コード例 #1
0
ファイル: box.input.img.php プロジェクト: isantiago/foswiki
 function &create(&$root, &$pipeline)
 {
     $name = $root->get_attribute('name');
     $value = $root->get_attribute('value');
     $url_autofix = new AutofixUrl();
     $src = $url_autofix->apply(trim($root->get_attribute("src")));
     $src_img = ImageFactory::get($pipeline->guess_url($src), $pipeline);
     if (is_null($src_img)) {
         error_log(sprintf("Cannot open image at '%s'", $src));
         if ($root->has_attribute('width')) {
             $width = px2pt($root->get_attribute('width'));
         } else {
             $width = px2pt(BROKEN_IMAGE_DEFAULT_SIZE_PX);
         }
         if ($root->has_attribute('height')) {
             $height = px2pt($root->get_attribute('height'));
         } else {
             $height = px2pt(BROKEN_IMAGE_DEFAULT_SIZE_PX);
         }
         $alt = $root->get_attribute('alt');
         $css_state =& $pipeline->get_current_css_state();
         $box =& new ButtonBrokenImagebox($width, $height, $alt, $name, $value, $css_state->get_property(CSS_HTML2PS_FORM_ACTION));
         $box->readCSS($css_state);
         return $box;
     }
     $css_state =& $pipeline->get_current_css_state();
     $box =& new ButtonImageBox($src_img, $name, $value, $css_state->get_property(CSS_HTML2PS_FORM_ACTION));
     $box->readCSS($css_state);
     $box->_setupSize();
     return $box;
 }
コード例 #2
0
 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;
     }
 }
コード例 #3
0
 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;
     }
 }
コード例 #4
0
 function &create(&$root, &$pipeline)
 {
     // Open image referenced by HTML tag
     // Some crazy HTML writers add leading and trailing spaces to SRC attribute value - we need to remove them
     //
     $url_autofix = new AutofixUrl();
     $src = $url_autofix->apply(trim($root->get_attribute("src")));
     $image_url = $pipeline->guess_url($src);
     $src_img = ImageFactory::get($image_url, $pipeline);
     if (is_null($src_img)) {
         // image could not be opened, use ALT attribute
         if ($root->has_attribute('width')) {
             $width = px2pt($root->get_attribute('width'));
         } else {
             $width = px2pt(BROKEN_IMAGE_DEFAULT_SIZE_PX);
         }
         if ($root->has_attribute('height')) {
             $height = px2pt($root->get_attribute('height'));
         } else {
             $height = px2pt(BROKEN_IMAGE_DEFAULT_SIZE_PX);
         }
         $alt = $root->get_attribute('alt');
         $box =& new BrokenImgBox($width, $height, $alt);
         $box->readCSS($pipeline->getCurrentCSSState());
         $box->put_width($width);
         $box->put_height($height);
         $box->default_baseline = $box->get_full_height();
         $box->src_height = $box->get_height();
         $box->src_width = $box->get_width();
         return $box;
     } else {
         $box =& new ImgBox($src_img);
         $box->readCSS($pipeline->getCurrentCSSState());
         $box->_setupSize();
         return $box;
     }
 }
コード例 #5
0
ファイル: processor.php プロジェクト: isantiago/foswiki
 function process_link_node(&$node)
 {
     $ruleset =& new CSSRuleset();
     $rel = strtolower($node->get_attribute('rel'));
     $type = strtolower($node->get_attribute('type'));
     // See HTML 4.01 p.14.2.3: This attribute (read: 'media') 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".
     if ($node->has_attribute('media')) {
         $media = explode(',', strtolower($node->get_attribute('media')));
     } else {
         $media = array('screen');
     }
     // Subconditions for the large condition below
     // 1. This is a stylesheet
     $is_stylesheet = $rel == 'stylesheet';
     // 2. This is a CSS stylesheet
     // Though HTML 4.01 standard says in p.14.2.3 "Authors must supply a value for this attribute; there is no default value for this attribute",
     // a lot of coders do not obey the standard; let's assume that if 'type' is omitted, we're dealing with CSS
     $is_css = $type == 'text/css' || $type == '';
     // 3. This stylesheet should be processed with current media
     // 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".
     // Yet again, let's be tolerant: if coder did not specify anything in the 'media' attribute value,
     // we assume that this stylesheet should be processed.
     // Note that if 'media' is omitted, we're using its default value - 'screent' (see above)
     $is_media_to_be_processed = count($media) == 0 || $this->is_allowed_media($media);
     if ($is_stylesheet && $is_css && $is_media_to_be_processed) {
         // Attempt to escape URL automaticaly
         $url_autofix = new AutofixUrl();
         $src = $url_autofix->apply(trim($node->get_attribute('href')));
         if ($src) {
             $ruleset = $this->import($src);
         }
     }
     return $ruleset;
 }
コード例 #6
0
 function TestAutofixUrlDirty8()
 {
     $url_autofix = new AutofixUrl();
     $source_url = 'test%z1test';
     $expected_url = 'test%25z1test';
     $fixed_url = $url_autofix->apply($source_url);
     $this->assertEqual($expected_url, $fixed_url);
 }