Hallo Community,
ich möchte eine ePub Datei php seitig zerlegen und diesen Inhalt auf eine html seite platzieren.
Ich bin dank einer Person aus diesem Forum auf eine Quelle gestoßen
Ich weiß noch nicht wie es funktioniert.
Muss ich vorher eine Quelle (epub) angeben und dann die php datei ausführen?
- Quelle :https://github.com/trizz/PHP-ePub-Reader
ich möchte eine ePub Datei php seitig zerlegen und diesen Inhalt auf eine html seite platzieren.
Ich bin dank einer Person aus diesem Forum auf eine Quelle gestoßen
Ich weiß noch nicht wie es funktioniert.
Muss ich vorher eine Quelle (epub) angeben und dann die php datei ausführen?
- Quelle :https://github.com/trizz/PHP-ePub-Reader
Code:
[COLOR=#BB2CA2][FONT=Menlo]<?php[/FONT][/COLOR][FONT=Menlo]
[/FONT]
[COLOR=#272AD8][FONT=Menlo][COLOR=#000000]defined([/COLOR]'BASEPATH'[COLOR=#000000]) or [/COLOR][COLOR=#bb2ca2]exit[/COLOR][COLOR=#000000]([/COLOR]'No direct script access allowed'[COLOR=#000000]);[/COLOR][/FONT][/COLOR]
[FONT=Menlo]
[/FONT]
[COLOR=#008400][FONT=Menlo]/**[/FONT][/COLOR]
[COLOR=#008400][FONT=Menlo] * ePub Reader class[/FONT][/COLOR]
[COLOR=#008400][FONT=Menlo] *[/FONT][/COLOR]
[COLOR=#008400][FONT=Menlo] * @package CodeIgniter[/FONT][/COLOR]
[COLOR=#008400][FONT=Menlo] * @subpackage Libraries[/FONT][/COLOR]
[COLOR=#008400][FONT=Menlo] * @author Tristan Siebers[/FONT][/COLOR]
[COLOR=#008400][FONT=Menlo] * @link n/a[/FONT][/COLOR]
[COLOR=#008400][FONT=Menlo] * @license LGPL[/FONT][/COLOR]
[COLOR=#008400][FONT=Menlo] * @version 0.1.0[/FONT][/COLOR]
[COLOR=#008400][FONT=Menlo] */[/FONT][/COLOR]
[FONT=Menlo][COLOR=#bb2ca2]class[/COLOR] Readepub {[/FONT]
[FONT=Menlo]
[/FONT]
[FONT=Menlo] [COLOR=#bb2ca2]var[/COLOR] $ebookDir;[/FONT]
[FONT=Menlo] [COLOR=#bb2ca2]var[/COLOR] $opfFile;[/FONT]
[FONT=Menlo] [COLOR=#bb2ca2]var[/COLOR] $opfDir;[/FONT]
[FONT=Menlo] [COLOR=#bb2ca2]var[/COLOR] $dcElements;[/FONT]
[FONT=Menlo] [COLOR=#bb2ca2]var[/COLOR] $manifest;[/FONT]
[FONT=Menlo] [/FONT]
[FONT=Menlo] [COLOR=#bb2ca2]var[/COLOR] $spine;[/FONT]
[FONT=Menlo] [COLOR=#bb2ca2]var[/COLOR] $toc;[/FONT]
[FONT=Menlo]
[/FONT]
[FONT=Menlo] public [COLOR=#bb2ca2]function[/COLOR] init($ebookDir) {[/FONT]
[FONT=Menlo] $this->ebookDir = $ebookDir;[/FONT]
[FONT=Menlo] $this->_getOPF();[/FONT]
[FONT=Menlo]
[/FONT]
[FONT=Menlo] $this->_getDcData();[/FONT]
[FONT=Menlo] $this->_getManifest();[/FONT]
[FONT=Menlo] $this->_getSpine();[/FONT]
[FONT=Menlo] $this->_getTOC();[/FONT]
[FONT=Menlo] }[/FONT]
[FONT=Menlo] public [COLOR=#bb2ca2]function[/COLOR] getDcItem($item) {[/FONT]
[FONT=Menlo] [COLOR=#bb2ca2]if[/COLOR](key_exists($item, $this->dcElements)) {[/FONT]
[FONT=Menlo] [COLOR=#bb2ca2]return[/COLOR] $this->dcElements[$item];[/FONT]
[FONT=Menlo] } [COLOR=#bb2ca2]else[/COLOR] {[/FONT]
[FONT=Menlo] [COLOR=#bb2ca2]return[/COLOR] false;[/FONT]
[FONT=Menlo] }[/FONT]
[FONT=Menlo] }[/FONT]
[FONT=Menlo] public [COLOR=#bb2ca2]function[/COLOR] getManifest($item) {[/FONT]
[FONT=Menlo] [COLOR=#bb2ca2]if[/COLOR](key_exists($item, $this->manifest)) {[/FONT]
[FONT=Menlo] [COLOR=#bb2ca2]return[/COLOR] $this->manifest[$item];[/FONT]
[FONT=Menlo] } [COLOR=#bb2ca2]else[/COLOR] {[/FONT]
[FONT=Menlo] [COLOR=#bb2ca2]return[/COLOR] false;[/FONT]
[FONT=Menlo] }[/FONT]
[FONT=Menlo] }[/FONT]
[FONT=Menlo] public [COLOR=#bb2ca2]function[/COLOR] getManifestByType($type) {[/FONT]
[FONT=Menlo] [COLOR=#bb2ca2]foreach[/COLOR]($this->manifest AS $manifestID => $manifest) {[/FONT]
[FONT=Menlo] [COLOR=#bb2ca2]if[/COLOR]($manifest[[COLOR=#272ad8]'media-type'[/COLOR]] == $type) {[/FONT]
[FONT=Menlo] $return[$manifestID][[COLOR=#272ad8]'href'[/COLOR]] = $manifest[[COLOR=#272ad8]'href'[/COLOR]];[/FONT]
[FONT=Menlo] $return[$manifestID][[COLOR=#272ad8]'media-type'[/COLOR]] = $manifest[[COLOR=#272ad8]'media-type'[/COLOR]];[/FONT]
[FONT=Menlo] }[/FONT]
[FONT=Menlo] }[/FONT]
[FONT=Menlo] [COLOR=#bb2ca2]return[/COLOR] (count($return) == [COLOR=#272ad8]0[/COLOR]) ? false : $return;[/FONT]
[FONT=Menlo] }[/FONT]
[FONT=Menlo] public [COLOR=#bb2ca2]function[/COLOR] getTOC() {[/FONT]
[FONT=Menlo] [COLOR=#bb2ca2]return[/COLOR] $this->toc;[/FONT]
[FONT=Menlo] }[/FONT]
[FONT=Menlo] public [COLOR=#bb2ca2]function[/COLOR] getOPFDir() {[/FONT]
[FONT=Menlo] [COLOR=#bb2ca2]return[/COLOR] $this->opfDir;[/FONT]
[FONT=Menlo] }[/FONT]
[FONT=Menlo]
[/FONT]
[FONT=Menlo] public [COLOR=#bb2ca2]function[/COLOR] debug() {[/FONT]
[FONT=Menlo] [COLOR=#bb2ca2]echo[/COLOR] sprintf([COLOR=#272ad8]'<pre>%s</pre>'[/COLOR], print_r($this, true));[/FONT]
[FONT=Menlo] }[/FONT]
[FONT=Menlo]
[/FONT]
[COLOR=#008400][FONT=Menlo]// Private functions[/FONT][/COLOR]
[FONT=Menlo]
[/FONT]
[FONT=Menlo] private [COLOR=#bb2ca2]function[/COLOR] _getOPF() {[/FONT]
[FONT=Menlo] $opfContents = simplexml_load_file($this->ebookDir [COLOR=#bb2ca2].[/COLOR] [COLOR=#272ad8]'/META-INF/container.xml'[/COLOR]);[/FONT]
[FONT=Menlo] $opfAttributes = $opfContents->rootfiles->rootfile->attributes();[/FONT]
[COLOR=#008400][FONT=Menlo][COLOR=#000000] $this->opfFile = ([/COLOR][COLOR=#bb2ca2]string[/COLOR][COLOR=#000000]) $opfAttributes[[/COLOR][COLOR=#272ad8]0[/COLOR][COLOR=#000000]]; [/COLOR]// Typecasting to string to get rid of the XML object[/FONT][/COLOR]
[FONT=Menlo] $opfDirParts = explode([COLOR=#272ad8]'/'[/COLOR],$this->opfFile);[/FONT]
[COLOR=#008400][FONT=Menlo][COLOR=#bb2ca2]unset[/COLOR][COLOR=#000000]($opfDirParts[(count($opfDirParts)-[/COLOR][COLOR=#272ad8]1[/COLOR][COLOR=#000000])]); [/COLOR]// remove the last part (it's the .opf file itself)[/FONT][/COLOR]
[FONT=Menlo] $this->opfDir = implode([COLOR=#272ad8]'/'[/COLOR],$opfDirParts);[/FONT]
[FONT=Menlo] [COLOR=#bb2ca2]return[/COLOR] $this->opfFile;[/FONT]
[FONT=Menlo] }[/FONT]
[FONT=Menlo] private [COLOR=#bb2ca2]function[/COLOR] _getDcData() {[/FONT]
[FONT=Menlo] $opfContents = simplexml_load_file($this->ebookDir [COLOR=#bb2ca2].[/COLOR] [COLOR=#272ad8]'/'[/COLOR] [COLOR=#bb2ca2].[/COLOR] $this->opfFile);[/FONT]
[FONT=Menlo] $this->dcElements = ([COLOR=#bb2ca2]array[/COLOR]) $opfContents->metadata->children([COLOR=#272ad8]'dc'[/COLOR], true);[/FONT]
[FONT=Menlo] }[/FONT]
[FONT=Menlo] private [COLOR=#bb2ca2]function[/COLOR] _getManifest() {[/FONT]
[FONT=Menlo] $opfContents = simplexml_load_file($this->ebookDir [COLOR=#bb2ca2].[/COLOR] [COLOR=#272ad8]'/'[/COLOR] [COLOR=#bb2ca2].[/COLOR] $this->opfFile);[/FONT]
[FONT=Menlo]
[/FONT]
[FONT=Menlo] $iManifest = [COLOR=#272ad8]0[/COLOR];[/FONT]
[FONT=Menlo] [COLOR=#bb2ca2]foreach[/COLOR] ($opfContents->manifest->item AS $item) {[/FONT]
[FONT=Menlo] $attr = $item->attributes();[/FONT]
[FONT=Menlo] $id = ([COLOR=#bb2ca2]string[/COLOR]) $attr->id;[/FONT]
[FONT=Menlo] $this->manifest[$id][[COLOR=#272ad8]'href'[/COLOR]] = ([COLOR=#bb2ca2]string[/COLOR]) $attr->href;[/FONT]
[FONT=Menlo] $this->manifest[$id][[COLOR=#272ad8]'media-type'[/COLOR]] = ([COLOR=#bb2ca2]string[/COLOR]) $attr->{[COLOR=#272ad8]'media-type'[/COLOR]};[/FONT]
[FONT=Menlo] $iManifest++;[/FONT]
[FONT=Menlo] }[/FONT]
[FONT=Menlo] }[/FONT]
[FONT=Menlo] private [COLOR=#bb2ca2]function[/COLOR] _getSpine() {[/FONT]
[FONT=Menlo] $opfContents = simplexml_load_file($this->ebookDir [COLOR=#bb2ca2].[/COLOR] [COLOR=#272ad8]'/'[/COLOR] [COLOR=#bb2ca2].[/COLOR] $this->opfFile);[/FONT]
[FONT=Menlo]
[/FONT]
[FONT=Menlo] [COLOR=#bb2ca2]foreach[/COLOR] ($opfContents->spine->itemref AS $item) {[/FONT]
[FONT=Menlo] $attr = $item->attributes();[/FONT]
[FONT=Menlo] $this->spine[] = ([COLOR=#bb2ca2]string[/COLOR]) $attr->idref;[/FONT]
[FONT=Menlo] }[/FONT]
[FONT=Menlo] }[/FONT]
[FONT=Menlo] private [COLOR=#bb2ca2]function[/COLOR] _getTOC() {[/FONT]
[FONT=Menlo] $tocFile = $this->getManifest([COLOR=#272ad8]'ncx'[/COLOR]);[/FONT]
[FONT=Menlo] $tocContents = simplexml_load_file($this->ebookDir[COLOR=#bb2ca2].[/COLOR][COLOR=#272ad8]'/'[/COLOR][COLOR=#bb2ca2].[/COLOR]$this->opfDir[COLOR=#bb2ca2].[/COLOR][COLOR=#272ad8]'/'[/COLOR][COLOR=#bb2ca2].[/COLOR]$tocFile[[COLOR=#272ad8]'href'[/COLOR]]);[/FONT]
[FONT=Menlo] $toc = [COLOR=#bb2ca2]array[/COLOR]();[/FONT]
[FONT=Menlo] [COLOR=#bb2ca2]foreach[/COLOR]($tocContents->navMap->navPoint AS $navPoint) {[/FONT]
[FONT=Menlo] $navPointData = $navPoint->attributes();[/FONT]
[FONT=Menlo] $toc[([COLOR=#bb2ca2]string[/COLOR])$navPointData[[COLOR=#272ad8]'playOrder'[/COLOR]]][[COLOR=#272ad8]'id'[/COLOR]] = ([COLOR=#bb2ca2]string[/COLOR])$navPointData[[COLOR=#272ad8]'id'[/COLOR]];[/FONT]
[FONT=Menlo] $toc[([COLOR=#bb2ca2]string[/COLOR])$navPointData[[COLOR=#272ad8]'playOrder'[/COLOR]]][[COLOR=#272ad8]'naam'[/COLOR]] = ([COLOR=#bb2ca2]string[/COLOR])$navPoint->navLabel->text;[/FONT]
[FONT=Menlo] $toc[([COLOR=#bb2ca2]string[/COLOR])$navPointData[[COLOR=#272ad8]'playOrder'[/COLOR]]][[COLOR=#272ad8]'src'[/COLOR]] = ([COLOR=#bb2ca2]string[/COLOR])$navPoint->content->attributes();[/FONT]
[FONT=Menlo] }[/FONT]
[FONT=Menlo] $this->toc = $toc;[/FONT]
[FONT=Menlo] }[/FONT]
[COLOR=#BB2CA2][FONT=Menlo]}[/FONT][/COLOR]