/** * Hyperlink href attributes must be set before all the pages are named. * Go through the pages and replace the page UIDs in all hrefs with the actual page name. * Use Ganon to target only hyperlink href attributes * @param EpubManager $epubManager */ public function fixHyperlinkPageNames(EpubManager $epubManager) { $pages = $epubManager->pageList(); foreach ($pages as $pageFile) { $content = $epubManager->getPageContent($pageFile->relativePath); $dom = new HTML_Parser($content); $hyperlinks = $dom('a'); if (count($hyperlinks) > 0) { foreach ($hyperlinks as $hyperlink) { $href = $hyperlink->getAttribute('href'); $correctedHref = str_replace(array_keys($this->pageNameXref), array_values($this->pageNameXref), $href); $hyperlink->setAttribute('href', $correctedHref); } $epubManager->updatePageContent($pageFile->relativePath, (string) $dom); } unset($dom); } }