PHPePub\Core\EPub::processChapterStyles PHP Method

processChapterStyles() protected method

Process style tags in a DOMDocument. Styles will be passed as CSS files and reinserted into the document.
protected processChapterStyles ( &$xmlDoc, integer $externalReferences = EPub::EXTERNAL_REF_ADD, string $baseDir = "", string $htmlDir = "" ) : boolean
$externalReferences integer How to handle external references, EPub::EXTERNAL_REF_IGNORE, EPub::EXTERNAL_REF_ADD or EPub::EXTERNAL_REF_REMOVE_IMAGES? Default is EPub::EXTERNAL_REF_ADD.
$baseDir string Default is "", meaning it is pointing to the document root.
$htmlDir string The path to the parent HTML file's directory from the root of the archive.
return boolean FALSE if uncuccessful (book is finalized or $externalReferences == EXTERNAL_REF_IGNORE).
    protected function processChapterStyles(&$xmlDoc, $externalReferences = EPub::EXTERNAL_REF_ADD, $baseDir = "", $htmlDir = "")
    {
        if ($this->isFinalized || $externalReferences === EPub::EXTERNAL_REF_IGNORE) {
            return false;
        }
        // process inlined CSS styles in style tags.
        $styles = $xmlDoc->getElementsByTagName("style");
        $styleCount = $styles->length;
        for ($styleIdx = 0; $styleIdx < $styleCount; $styleIdx++) {
            $style = $styles->item($styleIdx);
            $styleData = preg_replace('#[/\\*\\s]*\\<\\!\\[CDATA\\[[\\s\\*/]*#im', "", $style->nodeValue);
            $styleData = preg_replace('#[/\\*\\s]*\\]\\]\\>[\\s\\*/]*#im', "", $styleData);
            $this->processCSSExternalReferences($styleData, $externalReferences, $baseDir, $htmlDir);
            $style->nodeValue = "\n" . trim($styleData) . "\n";
        }
        return true;
    }