Example #1
0
 /**
  * The second last process, should only be getting everything
  * syntaxically correct, rather than doing any heavy processing
  *
  * @author Anthony Short
  * @return $css string
  */
 public static function post_process()
 {
     if ($found = CSS::find_properties_with_value('image-replace', 'url\\([\'\\"]?([^)]+)[\'\\"]?\\)')) {
         foreach ($found[4] as $key => $value) {
             $path = $url = str_replace("\\", "/", unquote($value));
             # If they're getting an absolute file
             if ($path[0] == "/") {
                 $path = DOCROOT . ltrim($path, "/");
             }
             # Check if it exists
             if (!file_exists($path)) {
                 FB::log("ImageReplace - Image doesn't exist " . $path);
             }
             # Make sure it's an image
             if (!is_image($path)) {
                 FB::log("ImageReplace - File is not an image: {$path}");
             }
             // Get the size of the image file
             $size = GetImageSize($path);
             $width = $size[0];
             $height = $size[1];
             // Make sure theres a value so it doesn't break the css
             if (!$width && !$height) {
                 $width = $height = 0;
             }
             // Build the selector
             $properties = "\n\t\t\t\t\tbackground:url({$url}) no-repeat 0 0;\n\t\t\t\t\theight:{$height}px;\n\t\t\t\t\twidth:{$width}px;\n\t\t\t\t\tdisplay:block;\n\t\t\t\t\ttext-indent:-9999px;\n\t\t\t\t\toverflow:hidden;\n\t\t\t\t";
             CSS::replace($found[2][$key], $properties);
         }
         # Remove any left overs
         CSS::replace($found[1], '');
     }
 }
Example #2
0
 /**
  * Parses @fors within the css
  *
  * @author Anthony Short
  * @param $string
  * @return string
  */
 public static function parse_fors($string)
 {
     if ($found = self::find_fors($string)) {
         foreach ($found[0] as $key => $value) {
             $s = "";
             $from = $found[2][$key];
             $to = $found[3][$key];
             $var = $found[1][$key];
             for ($i = $from; $i <= $to; $i++) {
                 $s .= str_replace("!{$var}", $i, $found[5][$key]);
             }
             CSS::replace($found[0][$key], $s);
         }
     }
 }
Example #3
0
 /**
  * The main processing function called by Scaffold. MUST return $css!
  *
  * @author Anthony Short
  * @return $css string
  */
 public static function parse()
 {
     global $bases;
     # This will store our nicely formated bases array
     # This lets us loop through all the of +mixins and just
     # pull in the properties of that mixin and then parse it individually
     # based on the parameters
     $bases = array();
     # Finds any selectors starting with =mixin-name
     if ($found = CSS::find_selectors('\\=(?P<name>[0-9a-zA-Z_-]*)(\\((?P<args>.*?)\\))?', 5)) {
         # Just to make life a little easier
         $full_base = $found[0];
         $base_names = $found['name'];
         $base_args = $found['args'];
         $base_props = $found['properties'];
         # Clean up memory
         unset($found);
         # Puts the mixin bases into a more suitable array
         foreach ($base_names as $key => $value) {
             $bases[$value]['properties'] = $base_props[$key];
             # If there are mixin arguments, add them
             $bases[$value]['params'] = $base_args[$key] != "" ? explode(',', $base_args[$key]) : array();
         }
         # Store this away for debugging
         self::$mixins = $bases;
         # Remove all of the mixin bases
         CSS::remove($full_base);
         # Clean up memory
         unset($full_base, $base_names, $base_args, $base_props);
         # Find the mixins
         if ($mixins = self::find_mixins(CSS::$css)) {
             # Loop through each of the found +mixins
             foreach ($mixins[2] as $mixin_key => $mixin_name) {
                 CSS::replace($mixins[0][$mixin_key], self::build_mixins($mixin_key, $mixins));
             }
             # Remove all of the +mixins (if they still exist)
             CSS::replace($mixins[0], '');
         }
         # Clean up
         unset($bases, $mixins);
     }
 }
Example #4
0
 /**
  * Finds any round(n) and rounds the number 
  * to the nearest multiple of the baseline
  *
  * @author Anthony Short
  * @param $css
  */
 private static function round_to_baseline($baseline)
 {
     if ($found = CSS::find_functions('round')) {
         foreach ($found[0] as $key => $match) {
             CSS::replace($match, round($found[1][$key] / $baseline) * $baseline . "px");
         }
     }
 }
Example #5
0
 /**
  * Replace constants
  *
  * @author Anthony Short
  * @param $
  * @return return type
  */
 public static function replace()
 {
     if (!empty(self::$constants)) {
         foreach (self::$constants as $key => $value) {
             if ($value != "") {
                 if (CSScaffold::config('core.use_css_constants') === true) {
                     CSS::replace("const({$key})", unquote($value));
                 } else {
                     CSS::replace("!{$key}", unquote($value));
                 }
             }
         }
         self::$constants = array();
     } else {
         if (preg_match_all('/![a-zA-Z0-9-_]+/', CSS::$css, $matches)) {
             $missing = array_values(array_unique($matches[0]));
             # Remove !important
             unset($missing[array_search('!important', $missing)]);
             if (!empty($missing)) {
                 $missing = "<ul><li>" . implode("</li><li>", $missing) . "</li></ul>";
                 throw new Scaffold_Exception('Constants.missing_constants', $missing);
             }
         }
     }
 }