Имя пользователя:
Пароль:  
Помощь | Регистрация | Забыли пароль?  | Правила  

Компьютерный форум OSzone.net » Компьютеры + Интернет » Вебмастеру » PHP открытие fictionbook(fb2)

Ответить
Настройки темы
PHP открытие fictionbook(fb2)

Аватара для leonid.poydolov@fb

Новый участник


Сообщения: 43
Благодарности: 0

Профиль | Отправить PM | Цитировать


Хочу организовать в локалке чтение книг на fb2 (fictionbook2), но файлы открываются в браузере
HTML код: Выделить весь код
<?xml version="1.0"

и т.д..
Ниже нашел скрипт который открывает файлы это формата, но в строке 157 (
PHP код: Выделить весь код

$book ->book_load("cuda_kniga.fb2"); 


) надо писать название

Как сделать что бы при обращении к любой книге fb2 открытие(подхват) проходило через этот скрипт?

PHP код: Выделить весь код

<?php

/**
 * @author            Diz A Torr
 * @copyright        Copyright (c) 2010, CodeMotion
 * @license            GPL
 * @link            http:/conferdigit.ru
 * @since            Version 1.0
 * @filesource
 */
// ------------------------------------------------------------------------

  
class   fictionbook {
     var  
$book ;
    var 
$table_of_content = array();
    var 
$book_info = array();
    
    function 
book_load ($file){
        
$this->book simplexml_load_file ($file);
        
$this->title_info();
    }
    
    function 
title_info (){
        
$title_info 'title-info';
//        include ('ru-ru.php');
        
foreach ($this->book->description->$title_info->children() as $key=>$children){
            switch (
$key){
                case 
'genre':
                    
$this->book_info['genre'][] = $genre_table_ru[(string) $children]; break;
                case 
'book-title':
                    
$this->book_info['book-title'] = $children; break;
                case 
'author'//Автор(ы) произведения
                    
$last_name 'last-name';
                    
$first_name 'first-name';
                    
$middle_name 'middle-name';
                    
$home_page 'home-page';
                    
$this->book_info['author'][] = array (   'first-name'=>$children->$first_name
                                                            
'middle-name'=>$children->$middle_name
                                                            
'last-name'=>$children->$last_name
                                                            
'home-page'=>$children->$home_page
                                                            
'email'=>$children->email);
                break;
                case 
'annotation':
                    
$this->book_info['annotation'] = $children->asXML(); break;
                case 
'coverpage':
                    
$this->book_info['coverpage'] = $children->image; break;
                case 
'date'// хранит дату создания документа.
                    
$this->book_info['date'] = $children; break;
                case 
'translator'//Переводчик(и)
                    
$last_name 'last-name';
                    
$first_name 'first-name';
                    
$middle_name 'middle-name';
                    
$home_page 'home-page';
                    
$this->book_info['translator'][] = array (   'first-name'=>$children->$first_name
                                                            
'middle-name'=>$children->$middle_name
                                                            
'last-name'=>$children->$last_name
                                                            
'home-page'=>$children->$home_page
                                                            
'email'=>$children->email);
                break;
                case 
'lang'//Язык книги
                    
$this->book_info['lang'] = $children; break;
                case 
'year'// год издания книги.
                    
$this->book_info['year'] = $children; break;                    
                
            }
        }
        
$this->table_of_content $this->table_of_content();
    }
    
    function 
print_image ($image){
        
//print_r($image);
        
$image =  $image->asXML();
        
preg_match("/[\"|\']\#([\S]+\.[\S]+)[\"|\']/i"$image$image_name);
        
$image_name $image_name[1];
           foreach (
$this->book->binary as $binary){
               if (
$binary[id] == $image_name){
                   
$image base64_decode($binary);
                   
$file fopen($image_name'w');
                   
fwrite($file$image);
                   
fclose($file);
                   echo 
'';
               }
        }        
    }
    
    function 
table_of_content($book='false'){ //Надо было как-то отметить, что в начале читать с самого начала , при этом не задавая это явно в методе.
        
if (!empty($this->table_of_content)){return $this->table_of_content;}         //Проверка на наличие
        
if ($book == 'false'){$book $this->book->body;}
        foreach (
$book as $key=>$body){
            if (isset(
$body->title)){
                
$title $this->__clear_string($body->title->asXML());
                if (!empty(
$title)){
                    
//echo $title.' ';
                    
$title_array[] = $title;                    
                }
            }
            
$title_array_temp $this->table_of_content($body->section);
            if (!empty(
$title_array_temp)){$title_array[] = $title_array_temp;}
        }
        return 
$title_array;
    }

    function 
content($book='false',  $i=-1){
        if (
$book == 'false'){$book $this->book->body;}
        ++
$i;
        foreach (
$book->children() as $key=>$body){
            switch (
$key){
                case 
'image'
                    
$this->print_image ($body);
                break;
                case 
'title':
                    if (
$i == 0){$i=1;}
                    
$title $this->__clear_string($body->asXML());
                    echo 
''.$title.'';
                break;
                case 
'section'
                    
$this->content($body$i);
                break;
                case 
'epigraph':
                    echo 
'
'
.$this->__clear_string($body->asXML()).'
'
;
                break;
                default:
                echo 
$this->__clear_string($body->asXML(), false);
            }
        }
    }
    
    function 
print_table_of_content($table false){
        if (!
$table){$table $this->table_of_content;
        }
        echo 
'
'
;
        foreach (
$table as $row){
            if (
is_array($row)){
                
$this->print_table_of_content($row);
            }else{
                echo 
'
'
.$row.'
'
;
            }
        }
        echo 
'
'
;
    }
        
    
private function __clear_string ($string$p true){
        
$string preg_replace('/\|\<\/title\>/im'''$string); //|\|\<\/p\>
        
$string preg_replace('/\s+/m'" "$string);
        
$string preg_replace('/^\s+|\s+$/'''$string);
        if (
$p){$string preg_replace('/\|\<\/p\>/im'''$string);}
        return 
$string;
    }

}
$book  = new  fictionbook ;
$book ->book_load("cuda_kniga.fb2");
//echo '';
$book->print_table_of_content();
$book->content();
?>


Отправлено: 11:42, 22-06-2015

 

Аватара для leonid.poydolov@fb

Новый участник


Сообщения: 43
Благодарности: 0

Профиль | Отправить PM | Цитировать


нашел решение...
.htaccess
HTML код: Выделить весь код
RewriteEngine On RewriteRule ^(.*).fb2$ fb2reader.php?reader=$1 [L]

Создать наш файл под именем fb2reader.php и заменить строку 157

PHP код: Выделить весь код

$book ->book_load($_GET['reader'].".fb2"); 


полный код fb2reader.php

PHP код: Выделить весь код

<?php
/**
 * @author            Diz A Torr
 * @copyright        Copyright (c) 2010, CodeMotion
 * @license            GPL
 * @link            http:/conferdigit.ru
 * @since            Version 1.0
 * @filesource
 */
// ------------------------------------------------------------------------

  
class   fictionbook {
     var  
$book ;
    var 
$table_of_content = array();
    var 
$book_info = array();
    
    function 
book_load ($file){
        
$this->book simplexml_load_file ($file);
        
$this->title_info();
    }
    
    function 
title_info (){
        
$title_info 'title-info';
//        include ('ru-ru.php');
        
foreach ($this->book->description->$title_info->children() as $key=>$children){
            switch (
$key){
                case 
'genre':
                    
$this->book_info['genre'][] = $genre_table_ru[(string) $children]; break;
                case 
'book-title':
                    
$this->book_info['book-title'] = $children; break;
                case 
'author'//Автор(ы) произведения
                    
$last_name 'last-name';
                    
$first_name 'first-name';
                    
$middle_name 'middle-name';
                    
$home_page 'home-page';
                    
$this->book_info['author'][] = array (   'first-name'=>$children->$first_name
                                                            
'middle-name'=>$children->$middle_name
                                                            
'last-name'=>$children->$last_name
                                                            
'home-page'=>$children->$home_page
                                                            
'email'=>$children->email);
                break;
                case 
'annotation':
                    
$this->book_info['annotation'] = $children->asXML(); break;
                case 
'coverpage':
                    
$this->book_info['coverpage'] = $children->image; break;
                case 
'date'// хранит дату создания документа.
                    
$this->book_info['date'] = $children; break;
                case 
'translator'//Переводчик(и)
                    
$last_name 'last-name';
                    
$first_name 'first-name';
                    
$middle_name 'middle-name';
                    
$home_page 'home-page';
                    
$this->book_info['translator'][] = array (   'first-name'=>$children->$first_name
                                                            
'middle-name'=>$children->$middle_name
                                                            
'last-name'=>$children->$last_name
                                                            
'home-page'=>$children->$home_page
                                                            
'email'=>$children->email);
                break;
                case 
'lang'//Язык книги
                    
$this->book_info['lang'] = $children; break;
                case 
'year'// год издания книги.
                    
$this->book_info['year'] = $children; break;                    
                
            }
        }
        
$this->table_of_content $this->table_of_content();
    }
    
    function 
print_image ($image){
        
//print_r($image);
        
$image =  $image->asXML();
        
preg_match("/[\"|\']\#([\S]+\.[\S]+)[\"|\']/i"$image$image_name);
        
$image_name $image_name[1];
           foreach (
$this->book->binary as $binary){
               if (
$binary[id] == $image_name){
                   
$image base64_decode($binary);
                   
$file fopen($image_name'w');
                   
fwrite($file$image);
                   
fclose($file);
                   echo 
'';
               }
        }        
    }
    
    function 
table_of_content($book='false'){ //Надо было как-то отметить, что в начале читать с самого начала , при этом не задавая это явно в методе.
        
if (!empty($this->table_of_content)){return $this->table_of_content;}         //Проверка на наличие
        
if ($book == 'false'){$book $this->book->body;}
        foreach (
$book as $key=>$body){
            if (isset(
$body->title)){
                
$title $this->__clear_string($body->title->asXML());
                if (!empty(
$title)){
                    
//echo $title.' ';
                    
$title_array[] = $title;                    
                }
            }
            
$title_array_temp $this->table_of_content($body->section);
            if (!empty(
$title_array_temp)){$title_array[] = $title_array_temp;}
        }
        return 
$title_array;
    }

    function 
content($book='false',  $i=-1){
        if (
$book == 'false'){$book $this->book->body;}
        ++
$i;
        foreach (
$book->children() as $key=>$body){
            switch (
$key){
                case 
'image'
                    
$this->print_image ($body);
                break;
                case 
'title':
                    if (
$i == 0){$i=1;}
                    
$title $this->__clear_string($body->asXML());
                    echo 
''.$title.'';
                break;
                case 
'section'
                    
$this->content($body$i);
                break;
                case 
'epigraph':
                    echo 
'
'
.$this->__clear_string($body->asXML()).'
'
;
                break;
                default:
                echo 
$this->__clear_string($body->asXML(), false);
            }
        }
    }
    
    function 
print_table_of_content($table false){
        if (!
$table){$table $this->table_of_content;
        }
        echo 
'
'
;
        foreach (
$table as $row){
            if (
is_array($row)){
                
$this->print_table_of_content($row);
            }else{
                echo 
'
'
.$row.'
'
;
            }
        }
        echo 
'
'
;
    }
        
    
private function __clear_string ($string$p true){
        
$string preg_replace('/\|\<\/title\>/im'''$string); //|\|\<\/p\>
        
$string preg_replace('/\s+/m'" "$string);
        
$string preg_replace('/^\s+|\s+$/'''$string);
        if (
$p){$string preg_replace('/\|\<\/p\>/im'''$string);}
        return 
$string;
    }

}
$book  = new  fictionbook ;
$book ->book_load($_GET['reader'].".fb2");
//echo '';
$book->print_table_of_content();
$book->content();
?>


Отправлено: 12:15, 22-06-2015 | #2



Для отключения данного рекламного блока вам необходимо зарегистрироваться или войти с учетной записью социальной сети.

Если же вы забыли свой пароль на форуме, то воспользуйтесь данной ссылкой для восстановления пароля.



Компьютерный форум OSzone.net » Компьютеры + Интернет » Вебмастеру » PHP открытие fictionbook(fb2)

Участник сейчас на форуме Участник сейчас на форуме Участник вне форума Участник вне форума Автор темы Автор темы Шапка темы Сообщение прикреплено

Похожие темы
Название темы Автор Информация о форуме Ответов Последнее сообщение
2012 - Перезагрузка сервера при открытие диалогового окна "Открытие/сохранение файла" skullert Windows Server 2012/2012 R2 6 12-08-2014 08:12
fb2 Processor 1.0.2 OSZone Software Новости программного обеспечения 0 17-09-2012 14:30
Открытие файлов с прямым путем на Linux (PHP) ShadowPrince Общий по Linux 4 22-10-2011 19:56
кодировка файлов fb2 LEHA2008 Хочу все знать 1 11-04-2010 01:25
Проблема с PHP(не передаются переменные из формы в PHP- скрипт) Kirander Вебмастеру 21 03-08-2009 01:11




 
Переход