function parse_style_node($root, &$pipeline) { // Check if this style node have 'media' attribute // and if we're using this media; // // Note that, according to the HTML 4.01 p.14.2.3 // This attribute specifies the intended destination medium for style information. // It may be a single media descriptor or a comma-separated list. // The default value for this attribute is "screen". // $media_list = array("screen"); if ($root->has_attribute("media")) { // Note that there may be whitespace symbols around commas, so we should not just use 'explode' function $media_list = preg_split("/\\s*,\\s*/", trim($root->get_attribute("media"))); } if (!is_allowed_media($media_list)) { if (defined('DEBUG_MODE')) { error_log(sprintf('No allowed (%s) media types found in CSS stylesheet media types (%s). Stylesheet ignored.', join(',', config_get_allowed_media()), join(',', $media_list))); } return; } if (!isset($GLOBALS['g_stylesheet_title']) || $GLOBALS['g_stylesheet_title'] === "") { $GLOBALS['g_stylesheet_title'] = $root->get_attribute("title"); } if (!$root->has_attribute("title") || $root->get_attribute("title") === $GLOBALS['g_stylesheet_title']) { /** * Check if current node is empty (then, we don't need to parse its contents) */ $content = trim($root->get_content()); if ($content != "") { $this->parse_css($content, $pipeline); } } }
function parse_style_node($root, &$pipeline) { global $g_stylesheet_title; // Check if this style node have 'media' attribute // and if we're using this media; // // Note that, according to the HTML 4.01 p.14.2.3 // This attribute specifies the intended destination medium for style information. // It may be a single media descriptor or a comma-separated list. // The default value for this attribute is "screen". // $media_list = array("screen"); if ($root->has_attribute("media")) { // Note that there may be whitespace symbols around commas, so we should not just use 'explode' function // $media_list = preg_split("/\\s*,\\s*/", trim($root->get_attribute("media"))); } if (!is_allowed_media($media_list)) { return; } if ($g_stylesheet_title === "") { $g_stylesheet_title = $root->get_attribute("title"); } if (!$root->has_attribute("title") || $root->get_attribute("title") === $g_stylesheet_title) { /** * Check if current node is empty (then, we don't need to parse its contents) */ $content = trim($root->get_content()); if ($content != "") { parse_css($content, $pipeline); } } }
function scan_styles($root, &$pipeline) { switch ($root->node_type()) { case XML_ELEMENT_NODE: $tagname = strtolower($root->tagname()); if ($tagname === 'style') { // Parse <style ...> ... </style> nodes // $this->parse_style_node($root, $pipeline); } elseif ($tagname === 'link') { // Parse <link rel="stylesheet" ...> nodes // $rel = strtolower($root->get_attribute("rel")); $type = strtolower($root->get_attribute("type")); if ($root->has_attribute("media")) { $media = explode(",", $root->get_attribute("media")); } else { $media = array(); } if ($rel == "stylesheet" && ($type == "text/css" || $type == "") && (count($media) == 0 || is_allowed_media($media))) { // Attempt to escape URL automaticaly $url_autofix = new AutofixUrl(); $src = $url_autofix->apply(trim($root->get_attribute('href'))); if ($src) { $this->css_import($src, $pipeline); } } } // Note that we continue processing here! // Note that we continue processing here! case XML_DOCUMENT_NODE: // Scan all child nodes $child = $root->first_child(); while ($child) { $this->scan_styles($child, $pipeline); $child = $child->next_sibling(); } break; } }
function scan_styles($root, &$pipeline) { switch ($root->node_type()) { case XML_ELEMENT_NODE: # kornev, already in lower # $tagname = strtolower($root->tagname()); $tagname = $root->tagname(); if ($tagname === 'style') { $this->parse_style_node($root, $pipeline); } elseif ($tagname === 'link') { $rel = $root->get_attribute('rel'); $type = $root->get_attribute('type'); if ($root->has_attribute('media')) { $media = explode(',', $root->get_attribute('media')); } else { $media = array(); } if ($rel == 'stylesheet' && ($type == 'text/css' || $type == '') && (count($media) == 0 || is_allowed_media($media))) { // Attempt to escape URL automaticaly $url_autofix = new AutofixUrl(); $src = $url_autofix->apply(trim($root->get_attribute('href'))); if ($src) { $this->css_import($src, $pipeline); } } } // Note that we continue processing here! // Note that we continue processing here! case XML_DOCUMENT_NODE: // Scan all child nodes $child = $root->first_child(); while ($child) { $this->scan_styles($child, $pipeline); $child = $child->next_sibling(); } break; } }