/** * Builds the {@link FrameTree}, loads any CSS and applies the styles to * the {@link FrameTree} */ private function processHtml() { $this->tree->build_tree(); $this->css->load_css_file(Stylesheet::getDefaultStylesheet(), Stylesheet::ORIG_UA); $acceptedmedia = Stylesheet::$ACCEPTED_GENERIC_MEDIA_TYPES; $acceptedmedia[] = $this->options->getDefaultMediaType(); // <base href="" /> $base_nodes = $this->dom->getElementsByTagName("base"); if ($base_nodes->length && ($href = $base_nodes->item(0)->getAttribute("href"))) { list($this->protocol, $this->baseHost, $this->basePath) = Helpers::explode_url($href); } // Set the base path of the Stylesheet to that of the file being processed $this->css->set_protocol($this->protocol); $this->css->set_host($this->baseHost); $this->css->set_base_path($this->basePath); // Get all the stylesheets so that they are processed in document order $xpath = new DOMXPath($this->dom); $stylesheets = $xpath->query("//*[name() = 'link' or name() = 'style']"); foreach ($stylesheets as $tag) { switch (strtolower($tag->nodeName)) { // load <link rel="STYLESHEET" ... /> tags case "link": if (mb_strtolower(stripos($tag->getAttribute("rel"), "stylesheet") !== false) || mb_strtolower($tag->getAttribute("type")) === "text/css") { //Check if the css file is for an accepted media type //media not given then always valid $formedialist = preg_split("/[\\s\n,]/", $tag->getAttribute("media"), -1, PREG_SPLIT_NO_EMPTY); if (count($formedialist) > 0) { $accept = false; foreach ($formedialist as $type) { if (in_array(mb_strtolower(trim($type)), $acceptedmedia)) { $accept = true; break; } } if (!$accept) { //found at least one mediatype, but none of the accepted ones //Skip this css file. continue; } } $url = $tag->getAttribute("href"); $url = Helpers::build_url($this->protocol, $this->baseHost, $this->basePath, $url); $this->css->load_css_file($url, Stylesheet::ORIG_AUTHOR); } break; // load <style> tags // load <style> tags case "style": // Accept all <style> tags by default (note this is contrary to W3C // HTML 4.0 spec: // http://www.w3.org/TR/REC-html40/present/styles.html#adef-media // which states that the default media type is 'screen' if ($tag->hasAttributes() && ($media = $tag->getAttribute("media")) && !in_array($media, $acceptedmedia)) { continue; } $css = ""; if ($tag->hasChildNodes()) { $child = $tag->firstChild; while ($child) { $css .= $child->nodeValue; // Handle <style><!-- blah --></style> $child = $child->nextSibling; } } else { $css = $tag->nodeValue; } $this->css->load_css($css); break; } } }
public function testSetters() { $option = new Options(); $option->set(array('tempDir' => 'test1', 'fontDir' => 'test2', 'fontCache' => 'test3', 'chroot' => 'test4', 'logOutputFile' => 'test5', 'defaultMediaType' => 'test6', 'defaultPaperSize' => 'test7', 'defaultFont' => 'test8', 'dpi' => 300, 'fontHeightRatio' => 1.2, 'isPhpEnabled' => true, 'isRemoteEnabled' => true, 'isJavascriptEnabled' => false, 'isHtml5ParserEnabled' => true, 'isFontSubsettingEnabled' => true, 'debugPng' => true, 'debugKeepTemp' => true, 'debugCss' => true, 'debugLayout' => true, 'debugLayoutLines' => false, 'debugLayoutBlocks' => false, 'debugLayoutInline' => false, 'debugLayoutPaddingBox' => false, 'adminUsername' => 'test9', 'adminPassword' => 'test10')); $this->assertEquals('test1', $option->getTempDir()); $this->assertEquals('test2', $option->getFontDir()); $this->assertEquals('test3', $option->getFontCache()); $this->assertEquals('test4', $option->getChroot()); $this->assertEquals('test5', $option->getLogOutputFile()); $this->assertEquals('test6', $option->getDefaultMediaType()); $this->assertEquals('test7', $option->getDefaultPaperSize()); $this->assertEquals('test8', $option->getDefaultFont()); $this->assertEquals(300, $option->getDpi()); $this->assertEquals(1.2, $option->getFontHeightRatio()); $this->assertTrue($option->getIsPhpEnabled()); $this->assertTrue($option->getIsRemoteEnabled()); $this->assertFalse($option->getIsJavascriptEnabled()); $this->assertTrue($option->getIsHtml5ParserEnabled()); $this->assertTrue($option->getIsFontSubsettingEnabled()); $this->assertTrue($option->getDebugPng()); $this->assertTrue($option->getDebugKeepTemp()); $this->assertTrue($option->getDebugCss()); $this->assertTrue($option->getDebugLayout()); $this->assertFalse($option->getDebugLayoutLines()); $this->assertFalse($option->getDebugLayoutBlocks()); $this->assertFalse($option->getDebugLayoutInline()); $this->assertFalse($option->getDebugLayoutPaddingBox()); $this->assertEquals('test9', $option->getAdminUsername()); $this->assertEquals('test10', $option->getAdminPassword()); }