public function replaceCSS($context)
 {
     // Find all of the link tags
     preg_match_all('#<link\\s[^>]*href=\\"' . str_replace('/', '\\/', self::CSS_DIR) . '\\/([^\\"]*).css\\"[^>]*>#', $context['output'], $found);
     foreach ($found[1] as $i => $file) {
         // Construct the filenames for the css files
         $original_filename = DOCROOT . self::CSS_DIR . "/{$file}.css";
         $new_filename = DOCROOT . self::CSS_DIR . "/{$file}-processed.css";
         // Find when the files where last edited
         $original_time = filemtime($original_filename);
         $new_time = file_exists($new_filename) ? filemtime($new_filename) : 0;
         // If the unprocessed CSS has been edited since our processed one, reprocessed it
         if ($original_time > $new_time) {
             // Remove the old file
             if ($new_time) {
                 unlink($new_filename);
             }
             // Process the CSSP file
             $csspp = new CSSPP(basename($original_filename), dirname($original_filename) . '/');
             // See if the user wants the CSS to be minified
             if ($this->_Parent->Configuration->get('minify', 'csspp') != 'yes') {
                 $csspp->setOption('minify', FALSE);
             }
             // See if the user wants the comments stripped out of the CSS
             if ($this->_Parent->Configuration->get('strip_comments', 'csspp') != 'yes') {
                 $csspp->setOption('comments', TRUE);
             }
             file_put_contents($new_filename, $csspp->process());
         }
         // Change all of the link tags
         $new = str_replace("{$file}.css", "{$file}-processed.css?" . filemtime($new_filename), $found[0][$i]);
         $context['output'] = str_replace($found[0][$i], $new, $context['output']);
     }
 }
 public function css()
 {
     $file = $this->get('file');
     $csspp = new CSSPP($file, CSS_BASE_PATH);
     // Include CSS that was marked for inclusion in the session
     if (array_key_exists('stylesheets', $_SESSION)) {
         foreach (array_unique($_SESSION['stylesheets']) as $stylesheet) {
             $csspp->append("@include '{$stylesheet}';\n");
         }
         unset($_SESSION['stylesheets']);
     }
     header('Content-type: text/css');
     echo $csspp;
 }
Exemplo n.º 3
0
<?php

require 'csspp.php';
$csspp = new CSSPP($_GET['file'], realpath(dirname(__FILE__) . '/../') . '/');
$csspp->setOption('minify', FALSE);
header('Content-Type: text/css');
echo $csspp;