From 1f65d1eb65268ea646ea77dcb0774d041dd6489a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Fri, 30 Aug 2013 21:27:55 +0200 Subject: [PATCH] Code refactoring --HG-- extra : rebase_source : d997be9abf119ab4a654dc25f25afa8cb5963357 --- resources/php-epub-meta/epub.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/resources/php-epub-meta/epub.php b/resources/php-epub-meta/epub.php index 998dc19..fa3147f 100644 --- a/resources/php-epub-meta/epub.php +++ b/resources/php-epub-meta/epub.php @@ -182,6 +182,13 @@ class EPub { return $this->xpath->query("//opf:manifest/opf:item[@href='$comp']")->item(0)->getAttribute('media-type'); } + private function getNavPointDetail ($node) { + $title = $this->toc_xpath->query('x:navLabel/x:text', $node)->item(0)->nodeValue; + $src = $this->toc_xpath->query('x:content', $node)->item(0)->attr('src'); + $src = str_replace ("/", "-SLASH-", $src); + return array("title" => $title, "src" => $src); + } + /** * Get the Epub content (TOC) as an array * @@ -191,17 +198,11 @@ class EPub { $contents = array(); $nodes = $this->toc_xpath->query('//x:ncx/x:navMap/x:navPoint'); foreach($nodes as $node){ - $title = $this->toc_xpath->query('x:navLabel/x:text', $node)->item(0)->nodeValue; - $src = $this->toc_xpath->query('x:content', $node)->item(0)->attr('src'); - $src = str_replace ("/", "-SLASH-", $src); - $contents[] = array("title" => $title, "src" => $src); + $contents[] = $this->getNavPointDetail ($node); $insidenodes = $this->toc_xpath->query('x:navPoint', $node); foreach($insidenodes as $insidenode){ - $title = $this->toc_xpath->query('x:navLabel/x:text', $insidenode)->item(0)->nodeValue; - $src = $this->toc_xpath->query('x:content', $insidenode)->item(0)->attr('src'); - $src = str_replace ("/", "-SLASH-", $src); - $contents[] = array("title" => $title, "src" => $src); + $contents[] = $this->getNavPointDetail ($insidenode); } } return $contents;