function testCSSContentEmptyWithOtherProperties()
 {
     $null = null;
     $collection =& parse_css_properties("-html2ps-html-content: ''; content: ''; width: auto; height: auto; margin: 0; border: none; padding: 0; font: auto;", $null);
     $this->assertTrue($collection->contains(CSS_CONTENT));
     $this->assertTrue($collection->contains(CSS_HTML2PS_HTML_CONTENT));
     $counters =& new CSSCounterCollection();
     $content =& $collection->getPropertyValue(CSS_CONTENT);
     $this->assertEqual($content->render($counters), "");
     $content =& $collection->getPropertyValue(CSS_HTML2PS_HTML_CONTENT);
     $this->assertEqual($content->render($counters), "");
 }
function parse_style_attr($root, &$state, &$pipeline)
{
    $style = $root->get_attribute("style");
    // Some "designers" (obviously lacking the brain and ability to read ) use such constructs:
    //
    // <input maxLength=256 size=45 name=searchfor value="" style="{width:350px}">
    //
    // It is out of standard, as HTML 4.01 says:
    //
    // The syntax of the value of the style attribute is determined by the default style sheet language.
    // For example, for [[CSS2]] inline style, use the declaration block syntax described in section 4.1.8
    // *(without curly brace delimiters)*
    //
    // but still parsed by many browsers; let's be compatible with these idiots - remove curly braces
    //
    $style = preg_replace("/^\\s*{/", "", $style);
    $style = preg_replace("/}\\s*\$/", "", $style);
    $properties = parse_css_properties($style, $pipeline);
    $rule = new CSSRule(array(array(SELECTOR_ANY), $properties, $pipeline->get_base_url(), $root), $pipeline);
    $rule->apply($root, $state, $pipeline);
}
function parse_css_media($css, &$pipeline, $baseindex = 0)
{
    // Remove comments
    $css = preg_replace("#/\\*.*?\\*/#is", "", $css);
    // Extract @page rules
    $css = parse_css_atpage_rules($css, $pipeline);
    // Extract @import rules
    if ($num = preg_match_all("/@import[^;]+;/", $css, $matches, PREG_PATTERN_ORDER)) {
        for ($i = 0; $i < $num; $i++) {
            $this->parse_css_import($matches[0][$i], $pipeline);
        }
    }
    // Remove @import rules so they will not break further processing
    $css = preg_replace("/@import[^;]+;/", "", $css);
    while (preg_match("/([^{}]*){(.*?)}(.*)/is", $css, $matches)) {
        // Drop extracted part
        $css = $matches[3];
        // Save extracted part
        $raw_selectors = $matches[1];
        $raw_properties = $matches[2];
        $selectors = parse_css_selectors($raw_selectors);
        $properties = parse_css_properties($raw_properties, $pipeline);
        foreach ($selectors as $selector) {
            $this->_lastId++;
            $rule = array($selector, $properties, $pipeline->get_base_url(), $this->_lastId + $baseindex);
            $this->add_rule($rule, $pipeline);
        }
    }
}
 /**
  * TODO: CSS_TEXT_ALIGN should get  top/bottom values by default for
  * left-top, left-bottom, right-top and right-bottom boxes
  */
 function CSSAtRuleMarginBox($selector, &$pipeline)
 {
     $this->selector = $selector;
     $css = "-html2ps-html-content: ''; content: ''; width: auto; height: auto; margin: 0; border: none; padding: 0; font: auto;";
     $css = $css . $this->_getCSSDefaults($selector);
     $this->css = new CSSRule(array(array(SELECTOR_ANY), parse_css_properties($css, $null), '', null), $pipeline);
 }
function &parse_css_property($string, &$pipeline)
{
    $collection =& parse_css_properties($string, $pipeline);
    return $collection;
}
Beispiel #6
0
 echo $form->generate_hidden_field("tid", $mybb->input['tid']) . "\n";
 echo $form->generate_hidden_field("file", htmlspecialchars_uni($mybb->input['file'])) . "\n";
 echo "{$lang->selector}: <select id=\"selector\" name=\"selector\">\n{$selector_list}</select> <span id=\"mini_spinner\">" . $form->generate_submit_button($lang->go) . "</span><br /><br />\n";
 $form->end();
 // Haven't chosen a selector to edit, show the first one from the stylesheet
 if (!$mybb->input['selector']) {
     reset($css_array);
     uasort($css_array, "css_selectors_sort_cmp");
     $selector = key($css_array);
     $editable_selector = $css_array[$selector];
 } else {
     $editable_selector = $css_array[$mybb->input['selector']];
     $selector = $mybb->input['selector'];
 }
 // Get the properties from this item
 $properties = parse_css_properties($editable_selector['values']);
 foreach (array('background', 'color', 'width', 'font-family', 'font-size', 'font-style', 'font-weight', 'text-decoration') as $_p) {
     if (!isset($properties[$_p])) {
         $properties[$_p] = '';
     }
 }
 $form = new Form("index.php?module=style-themes&amp;action=edit_stylesheet", "post");
 echo $form->generate_hidden_field("tid", $mybb->input['tid'], array('id' => "tid")) . "\n";
 echo $form->generate_hidden_field("file", htmlspecialchars_uni($mybb->input['file']), array('id' => "file")) . "\n";
 echo $form->generate_hidden_field("selector", htmlspecialchars_uni($selector), array('id' => 'hidden_selector')) . "\n";
 echo "<div id=\"stylesheet\">";
 $table = new Table();
 $table->construct_cell("<div style=\"float: right;\">" . $form->generate_text_box('css_bits[background]', $properties['background'], array('id' => 'css_bits[background]', 'style' => 'width: 260px;')) . "</div><div><strong>{$lang->background}</strong></div>", array('style' => 'width: 20%;'));
 $table->construct_cell("<strong>{$lang->extra_css_atribs}</strong><br /><div style=\"align: center;\">" . $form->generate_text_area('css_bits[extra]', $properties['extra'], array('id' => 'css_bits[extra]', 'style' => 'width: 98%;', 'rows' => '19')) . "</div>", array('rowspan' => 8));
 $table->construct_row();
 $table->construct_cell("<div style=\"float: right;\">" . $form->generate_text_box('css_bits[color]', $properties['color'], array('id' => 'css_bits[color]', 'style' => 'width: 260px;')) . "</div><div><strong>{$lang->color}</strong></div>", array('style' => 'width: 40%;'));
function parse_css_media($css, &$pipeline, $baseindex = 0)
{
    // Remove comments
    $css = preg_replace("#/\\*.*?\\*/#is", "", $css);
    // Extract @import rules
    if ($num = preg_match_all("/@import[^;]+;/", $css, $matches, PREG_PATTERN_ORDER)) {
        for ($i = 0; $i < $num; $i++) {
            parse_css_import($matches[0][$i], $pipeline);
        }
    }
    while (preg_match("/([^{}]*){(.*?)}(.*)/is", $css, $matches)) {
        // Drop extracted part
        $css = $matches[3];
        // Save extracted part
        $raw_selectors = $matches[1];
        $raw_properties = $matches[2];
        $selectors = parse_css_selectors($raw_selectors);
        $properties = parse_css_properties($raw_properties, $pipeline);
        foreach ($selectors as $selector) {
            // FIXME: this stuff definitely should be incapsulated
            global $g_css;
            global $g_css_index;
            $g_css_index++;
            array_push($g_css, array($selector, $properties, $pipeline->get_base_url(), $g_css_index + $baseindex));
        }
    }
}
Beispiel #8
0
function get_css_properties($css, $id)
{
    if (!is_array($css)) {
        $css = css_to_array($css);
    }
    if (!isset($css[$id])) {
        return false;
    }
    return parse_css_properties($css[$id]['values']);
}
    function testCSSParsePropertiesMultilineWithLinefeedsAround()
    {
        $null = null;
        $collection =& parse_css_properties('
font-weight: bold;
-html2ps-html-content: "Sample;Text"; 
color: red;
', $null);
        $properties = $collection->getPropertiesRaw();
        $this->assertTrue($collection->contains(CSS_HTML2PS_HTML_CONTENT));
        $this->assertTrue($collection->contains(CSS_COLOR));
        $this->assertTrue($collection->contains(CSS_FONT_WEIGHT));
        $this->assertEqual($collection->getPropertyValue(CSS_FONT_WEIGHT), WEIGHT_BOLD);
        $content =& $collection->getPropertyValue(CSS_HTML2PS_HTML_CONTENT);
        $counters =& new CSSCounterCollection();
        $this->assertEqual($content->render($counters), "Sample;Text");
        $color = $collection->getPropertyValue(CSS_COLOR);
        $this->assertEqual($color->r, 1);
        $this->assertEqual($color->g, 0);
        $this->assertEqual($color->b, 0);
    }