function parse($value, &$pipeline)
 {
     global $g_config;
     if (!$g_config['renderimages']) {
         return CSSListStyleImage::default_value();
     }
     if (preg_match('/url\\(([^)]+)\\)/', $value, $matches)) {
         $url = $matches[1];
         $full_url = $pipeline->guess_url(css_remove_value_quotes($url));
         return new ListStyleImage($full_url, Image::get($full_url, $pipeline));
     }
     return CSSListStyleImage::default_value();
 }
 function parse($value, &$pipeline)
 {
     global $g_config;
     if (!$g_config['renderimages']) {
         return CSSBackgroundImage::default_value();
     }
     // 'url' value
     if (preg_match("/url\\((.*[^\\\\]?)\\)/is", $value, $matches)) {
         $url = $matches[1];
         $full_url = $pipeline->guess_url(css_remove_value_quotes($url));
         return new BackgroundImage($full_url, Image::get($full_url, $pipeline));
     }
     // 'none' and unrecognzed values
     return CSSBackgroundImage::default_value();
 }
 function parse($value, &$pipeline)
 {
     if ($value === 'inherit') {
         return CSS_PROPERTY_INHERIT;
     }
     global $g_config;
     if (!$g_config['renderimages']) {
         return CSSListStyleImage::default_value();
     }
     if (preg_match('/url\\(([^)]+)\\)/', $value, $matches)) {
         $url = $matches[1];
         $full_url = $pipeline->guess_url(css_remove_value_quotes($url));
         return new ListStyleImage($full_url, ImageFactory::get($full_url, $pipeline));
     }
     /**
      * 'none' value and all unrecognized values
      */
     return CSSListStyleImage::default_value();
 }
Ejemplo n.º 4
0
function parse_css_import($import, &$pipeline)
{
    if (preg_match("/@import\\s+[\"'](.*)[\"'];/", $import, $matches)) {
        // @import "<url>"
        $this->css_import(trim($matches[1]), $pipeline);
    } elseif (preg_match("/@import\\s+url\\((.*)\\);/", $import, $matches)) {
        // @import url()
        $this->css_import(trim(css_remove_value_quotes($matches[1])), $pipeline);
    } elseif (preg_match("/@import\\s+(.*);/", $import, $matches)) {
        // @import <url>
        $this->css_import(trim(css_remove_value_quotes($matches[1])), $pipeline);
    }
}
function parse_css_selector($raw_selector)
{
    // Note a 'trim' call. Is is required as there could be leading/trailing spaces in $raw_selector
    //
    $raw_selector = strtolower(trim($raw_selector));
    // Direct Parent/child selectors (for example 'table > tr')
    if (preg_match("/^(\\S.*)\\s*>\\s*([^\\s]+)\$/", $raw_selector, $matches)) {
        return array(SELECTOR_SEQUENCE, array(parse_css_selector($matches[2]), array(SELECTOR_DIRECT_PARENT, parse_css_selector($matches[1]))));
    }
    // Parent/child selectors (for example 'table td')
    if (preg_match("/^(\\S.*)\\s+([^\\s]+)\$/", $raw_selector, $matches)) {
        return array(SELECTOR_SEQUENCE, array(parse_css_selector($matches[2]), array(SELECTOR_PARENT, parse_css_selector($matches[1]))));
    }
    if (preg_match("/^(.+)\\[(" . SELECTOR_ATTR_REGEXP . ")\\]\$/", $raw_selector, $matches)) {
        return array(SELECTOR_SEQUENCE, array(parse_css_selector($matches[1]), array(SELECTOR_ATTR, $matches[2])));
    }
    if (preg_match("/^(.+)\\[" . SELECTOR_ATTR_VALUE_REGEXP . "\\]\$/", $raw_selector, $matches)) {
        return array(SELECTOR_SEQUENCE, array(parse_css_selector($matches[1]), array(SELECTOR_ATTR_VALUE, $matches[2], css_remove_value_quotes($matches[3]))));
    }
    if (preg_match("/^(.+)\\[" . SELECTOR_ATTR_VALUE_WORD_REGEXP . "\\]\$/", $raw_selector, $matches)) {
        return array(SELECTOR_SEQUENCE, array(parse_css_selector($matches[1]), array(SELECTOR_ATTR_VALUE_WORD, $matches[2], css_remove_value_quotes($matches[3]))));
    }
    // pseudoclasses & pseudoelements
    if (preg_match("/^([#\\.\\s\\w_-]*):(\\w+)\$/", $raw_selector, $matches)) {
        if ($matches[1] === "") {
            $matches[1] = "*";
        }
        switch ($matches[2]) {
            case "lowlink":
                return array(SELECTOR_SEQUENCE, array(parse_css_selector($matches[1]), array(SELECTOR_PSEUDOCLASS_LINK_LOW_PRIORITY)));
            case "link":
                return array(SELECTOR_SEQUENCE, array(parse_css_selector($matches[1]), array(SELECTOR_PSEUDOCLASS_LINK)));
            case "before":
                return array(SELECTOR_SEQUENCE, array(parse_css_selector($matches[1]), array(SELECTOR_PSEUDOELEMENT_BEFORE)));
            case "after":
                return array(SELECTOR_SEQUENCE, array(parse_css_selector($matches[1]), array(SELECTOR_PSEUDOELEMENT_AFTER)));
        }
    }
    // :lang() pseudoclass
    if (preg_match("/^([#\\.\\s\\w_-]+):lang\\((\\w+)\\)\$/", $raw_selector, $matches)) {
        return array(SELECTOR_SEQUENCE, array(parse_css_selector($matches[1]), array(SELECTOR_LANGUAGE, $matches[2])));
    }
    if (preg_match("/^(\\S+)(\\.\\S+)\$/", $raw_selector, $matches)) {
        return array(SELECTOR_SEQUENCE, array(parse_css_selector($matches[1]), parse_css_selector($matches[2])));
    }
    switch ($raw_selector[0]) {
        case '#':
            return array(SELECTOR_ID, substr($raw_selector, 1));
        case '.':
            return array(SELECTOR_CLASS, substr($raw_selector, 1));
    }
    if (preg_match("/^(\\w+)#(" . SELECTOR_ID_REGEXP . ")\$/", $raw_selector, $matches)) {
        return array(SELECTOR_SEQUENCE, array(array(SELECTOR_ID, $matches[2]), array(SELECTOR_TAG, $matches[1])));
    }
    if ($raw_selector === "*") {
        return array(SELECTOR_ANY);
    }
    return array(SELECTOR_TAG, $raw_selector);
}
Ejemplo n.º 6
0
 function import_ruleset_selector_simple($syntax_selector)
 {
     $selector = array(SELECTOR_ANY);
     if (!is_null($syntax_selector->get_element())) {
         $selector = array(SELECTOR_SEQUENCE, array(array(SELECTOR_TAG, $syntax_selector->get_element()), $selector));
     }
     $ids = $syntax_selector->get_ids();
     foreach ($ids as $id) {
         $selector = array(SELECTOR_SEQUENCE, array(array(SELECTOR_ID, substr($id, 1)), $selector));
     }
     $classes = $syntax_selector->get_classes();
     foreach ($classes as $class) {
         $selector = array(SELECTOR_SEQUENCE, array(array(SELECTOR_CLASS, $class), $selector));
     }
     $attribs = $syntax_selector->get_attribs();
     foreach ($attribs as $attrib) {
         switch ($attrib->get_op()) {
             case ATTRIB_OP_EQUAL:
                 $selector = array(SELECTOR_SEQUENCE, array(array(SELECTOR_ATTR_VALUE, $attrib->get_name(), css_remove_value_quotes($attrib->get_value())), $selector));
                 break;
             case ATTRIB_OP_DASHMATCH:
                 $selector = array(SELECTOR_SEQUENCE, array(array(SELECTOR_ATTR_VALUE_WORD_HYPHEN, $attrib->get_name(), css_remove_value_quotes($attrib->get_value())), $selector));
                 break;
             case ATTRIB_OP_INCLUDES:
                 $selector = array(SELECTOR_SEQUENCE, array(array(SELECTOR_ATTR_VALUE_WORD, $attrib->get_name(), css_remove_value_quotes($attrib->get_value())), $selector));
                 break;
             default:
                 $selector = array(SELECTOR_SEQUENCE, array(array(SELECTOR_ATTR, $attrib->get_name()), $selector));
                 break;
         }
     }
     $pseudo = $syntax_selector->get_pseudo();
     foreach ($pseudo as $pseudo_item) {
         switch ($pseudo_item->get_name()) {
             case 'link':
                 $selector = array(SELECTOR_SEQUENCE, array(array(SELECTOR_PSEUDOCLASS_LINK), $selector));
                 break;
             case 'before':
                 $selector = array(SELECTOR_SEQUENCE, array(array(SELECTOR_PSEUDOELEMENT_BEFORE), $selector));
                 break;
             case 'after':
                 $selector = array(SELECTOR_SEQUENCE, array(array(SELECTOR_PSEUDOELEMENT_AFTER), $selector));
                 break;
             case 'visited':
             case 'active':
             case 'hover':
                 // No nothing, as html2ps is not interactive user-agent
                 break;
             default:
                 error_log(sprintf('Unknown pseudo selector: "%s"', $pseudo_item->get_name()));
         }
     }
     return $selector;
 }
 function parse($value)
 {
     return css_remove_value_quotes($value);
 }