You are here

function csstidy_print::_print in Advanced CSS/JS Aggregation 6

Same name and namespace in other branches
  1. 7 advagg_css_compress/csstidy/class.csstidy_print.inc \csstidy_print::_print()

Returns the formatted CSS Code and saves it into $this->output_css and $this->output_css_plain

@access private @version 2.0

Parameters

bool $plain plain text or not:

string $default_media default @media to add to selectors without any @media:

2 calls to csstidy_print::_print()
csstidy_print::formatted in advagg_css_compress/csstidy/class.csstidy_print.inc
Returns the formatted CSS code
csstidy_print::plain in advagg_css_compress/csstidy/class.csstidy_print.inc
Returns the CSS code as plain text

File

advagg_css_compress/csstidy/class.csstidy_print.inc, line 166

Class

csstidy_print
CSS Printing class

Code

function _print($plain = false, $default_media = '') {
  if ($this->output_css && $this->output_css_plain) {
    return;
  }
  $output = '';
  if (!$this->parser
    ->get_cfg('preserve_css')) {
    $this
      ->_convert_raw_css($default_media);
  }
  $template =& $this->template;
  if ($plain) {
    $template = array_map('strip_tags', $template);
  }
  if ($this->parser
    ->get_cfg('timestamp')) {
    array_unshift($this->tokens, array(
      COMMENT,
      ' CSSTidy ' . $this->parser->version . ': ' . date('r') . ' ',
    ));
  }
  if (!empty($this->charset)) {
    $output .= $template[0] . '@charset ' . $template[5] . $this->charset . $template[6];
  }
  if (!empty($this->import)) {
    for ($i = 0, $size = count($this->import); $i < $size; $i++) {
      if (substr($this->import[$i], 0, 4) === 'url(' && substr($this->import[$i], -1, 1) === ')') {
        $this->import[$i] = '\'' . substr($this->import[$i], 4, -1) . '\'';
        $this->parser
          ->log('Optimised @import : Removed "url("', 'Information');
      }
      $output .= $template[0] . '@import ' . $template[5] . $this->import[$i] . $template[6];
    }
  }
  if (!empty($this->namespace)) {
    if (substr($this->namespace, 0, 4) === 'url(' && substr($this->namespace, -1, 1) === ')') {
      $this->namespace = '\'' . substr($this->namespace, 4, -1) . '\'';
      $this->parser
        ->log('Optimised @namespace : Removed "url("', 'Information');
    }
    $output .= $template[0] . '@namespace ' . $template[5] . $this->namespace . $template[6];
  }
  $output .= $template[13];
  $in_at_out = '';
  $out =& $output;
  foreach ($this->tokens as $key => $token) {
    switch ($token[0]) {
      case AT_START:
        $out .= $template[0] . $this
          ->_htmlsp($token[1], $plain) . $template[1];
        $out =& $in_at_out;
        break;
      case SEL_START:
        if ($this->parser
          ->get_cfg('lowercase_s')) {
          $token[1] = strtolower($token[1]);
        }
        $out .= $token[1][0] !== '@' ? $template[2] . $this
          ->_htmlsp($token[1], $plain) : $template[0] . $this
          ->_htmlsp($token[1], $plain);
        $out .= $template[3];
        break;
      case PROPERTY:
        if ($this->parser
          ->get_cfg('case_properties') === 2) {
          $token[1] = strtoupper($token[1]);
        }
        elseif ($this->parser
          ->get_cfg('case_properties') === 1) {
          $token[1] = strtolower($token[1]);
        }
        $out .= $template[4] . $this
          ->_htmlsp($token[1], $plain) . ':' . $template[5];
        break;
      case VALUE:
        $out .= $this
          ->_htmlsp($token[1], $plain);
        if ($this
          ->_seeknocomment($key, 1) == SEL_END && $this->parser
          ->get_cfg('remove_last_;')) {
          $out .= str_replace(';', '', $template[6]);
        }
        else {
          $out .= $template[6];
        }
        break;
      case SEL_END:
        $out .= $template[7];
        if ($this
          ->_seeknocomment($key, 1) != AT_END) {
          $out .= $template[8];
        }
        break;
      case AT_END:
        $out =& $output;
        $out .= $template[10] . str_replace("\n", "\n" . $template[10], $in_at_out);
        $in_at_out = '';
        $out .= $template[9];
        break;
      case COMMENT:
        $out .= $template[11] . '/*' . $this
          ->_htmlsp($token[1], $plain) . '*/' . $template[12];
        break;
    }
  }
  $output = trim($output);
  if (!$plain) {
    $this->output_css = $output;
    $this
      ->_print(true);
  }
  else {

    // If using spaces in the template, don't want these to appear in the plain output
    $this->output_css_plain = str_replace('&#160;', '', $output);
  }
}