示例#1
0
 /**
  * Parses embed() functions within the CSS.
  * @access public
  * @param $source
  * @param $scaffold
  * @return string
  */
 public function process($source, $scaffold)
 {
     // We can only embed for file sources
     if ($source->type != 'file') {
         return;
     }
     foreach (Scaffold_Helper_CSS::find_functions('embed', $source->contents) as $found) {
         // Get the full path to the file relative to the source
         $path = $source->find($url);
         // The file doesn't exist
         if ($path === false) {
             continue;
         }
         $id = 'embeds/' . md5($path);
         $ext = pathinfo($path, PATHINFO_EXTENSION);
         $mod_time = filemtime($path);
         $mime = $this->_get_mime($ext);
         // If it's a file we can actually use
         if ($mime === false) {
             continue;
         }
         // Try and load it from the cache
         $data = $scaffold->cache->get($id);
         // If the cached version has expired
         if ($data === false or $mod_time > $data->last_modified) {
             $data = base64_encode(file_get_contents($path));
             $scaffold->cache->set($id, $data, $mod_time, false);
         } else {
             $data = $data->contents;
         }
         $string = "url(data:{$mime};base64,{$data})";
         $source->contents = str_replace($found['string'], $string, $source->contents);
     }
 }
示例#2
0
 /**
  * Find css style functions
  * @author Anthony Short
  * @test
  */
 public function Find_css_style_functions()
 {
     $string = '#id {background:url( http://google.com );border-image:url("images/bullet.png")}';
     $expected = array(0 => array('string' => 'url( http://google.com )', 'params' => array('http://google.com ')), 1 => array('string' => 'url("images/bullet.png")', 'params' => array('"images/bullet.png"')));
     $output = Scaffold_Helper_CSS::find_functions('url', $string);
     $this->assertEquals($output, $expected);
 }
示例#3
0
 /**
  * @access public
  * @param $source
  * @return string
  */
 public function pre_process($source, $scaffold)
 {
     // Go through each custom function
     foreach ($this->functions as $name => $function) {
         $obj = $function[0];
         $method = $function[1];
         // Find them in the CSS
         foreach (Scaffold_Helper_CSS::find_functions($name, $source->contents) as $found) {
             // Call the hook method for this function
             $result = call_user_func_array(array($obj, $method), $found['params']);
             // Replace it in the CSS
             $source->contents = str_replace($found['string'], $result, $source->contents);
         }
     }
 }