예제 #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 = CSScaffold::config('core.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], '');
     }
 }
예제 #2
0
 public static function output()
 {
     if (CSScaffold::config('core.options.output') == "typography") {
         # Make sure we're sending HTML
         header('Content-Type: text/html');
         # Load the test suite markup
         $type = CSScaffold::load_view('TS_typography');
         # Echo and out!
         echo $type;
         exit;
     }
 }
예제 #3
0
 /**
  * Imports css via @import statements
  * 
  * @author Anthony Short
  * @param $css
  */
 public static function server_import($css, $previous = "")
 {
     # If they want to override the CSS syntax
     if (CSScaffold::config('core.override_import') === true) {
         $import = 'import';
     } else {
         $import = 'include';
     }
     if (preg_match_all('/\\@' . $import . '\\s+(?:\'|\\")([^\'\\"]+)(?:\'|\\")\\;/', $css, $matches)) {
         $unique = array_unique($matches[1]);
         $include = str_replace("\\", "/", unquote($unique[0]));
         # If they're getting an absolute file
         if ($include[0] == "/") {
             $include = DOCROOT . ltrim($include, "/");
         }
         # Make sure recursion isn't happening
         if ($include == $previous) {
             throw new Scaffold_Exception("Recursion occurring with CSS @includes in {$include}");
         }
         # If they haven't supplied an extension, we'll assume its a css file
         if (pathinfo($include, PATHINFO_EXTENSION) == "") {
             $include .= '.css';
         }
         # Make sure it's a CSS file
         if (!is_css($include)) {
             throw new Scaffold_Exception("Included file isn't a CSS file ({$include})");
         }
         # If the url starts with ~, we'll assume it's from the root of the css directory
         if ($include[0] == "~") {
             $include = ltrim($include, '~/');
             $include = CSScaffold::config('core.path.css') . $include;
         }
         if (file_exists($include)) {
             # Make sure it hasn't already been included
             if (!in_array($include, self::$loaded)) {
                 self::$loaded[] = $include;
                 $css = str_replace($matches[0][0], file_get_contents($include), $css);
             } else {
                 $css = str_replace($matches[0][0], '', $css);
             }
             # Compress it which removes any commented out @imports
             CSS::compress($css);
             # Check the file again for more imports
             $css = self::server_import($css, $include);
         } else {
             throw new Scaffold_Exception("Included CSS file doesn't exist ({$include})");
         }
     }
     return $css;
 }
예제 #4
0
 /**
  * Gets the XML and sets each of the nodes as constants
  *
  * @author Anthony Short
  * @return Void
  */
 public static function pre_process()
 {
     $file = CSScaffold::config('XML_constants.xml_path');
     # If the xml file doesn't exist
     if (!file_exists($file)) {
         throw new Scaffold_Exception('XML_constants.doesnt_exist', $file);
     }
     # Load the xml
     $xml = simplexml_load_file($file);
     # Loop through them and set them as constants
     foreach ($xml->constant as $key => $value) {
         Constants::set((string) $value->name, (string) $value->value);
     }
 }
예제 #5
0
 public static function check()
 {
     if (!IN_PRODUCTION) {
         # Clean it up so we can use the line numbers
         CSS::pretty();
         # Get the validator options from the config
         $validator_options = CSScaffold::config('Validate');
         # Add our options
         $validator_options['text'] = CSS::$css;
         $validator_options['output'] = 'soap12';
         # Encode them
         $validator_options = http_build_query($validator_options);
         $url = "http://jigsaw.w3.org/css-validator/validator?{$validator_options}";
         # The Curl options
         $options = array(CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => 1);
         # Start CURL
         $handle = curl_init();
         # Set the CURL options
         curl_setopt_array($handle, $options);
         # Store the response in a buffer
         $buffer = curl_exec($handle);
         # Close it
         curl_close($handle);
         # If something was returned
         if (!empty($buffer)) {
             # Simplexml doesn't like colons
             $buffer = preg_replace("/(<\\/?)(\\w+):([^>]*>)/", "\$1\$2\$3", $buffer);
             # Let it be xml!
             $results = simplexml_load_string($buffer);
             # Is it valid?
             $is_valid = (string) $results->envBody->mcssvalidationresponse->mvalidity;
             # Oh noes! Display the errors
             if ($is_valid == "false") {
                 # Lets get the errors into a nice array
                 $errors = $results->envBody->mcssvalidationresponse->mresult->merrors;
                 # Number of errors
                 $count = (int) $errors->merrorcount;
                 # Start creating the output message
                 $message = "<ol>";
                 foreach ($errors->merrorlist->merror as $key => $error) {
                     $message .= "<li><strong>" . trim((string) $error->mmessage) . "</strong> line " . (string) $error->mline . " near " . (string) $error->mcontext . "</li>";
                 }
                 $message .= "</ol>";
                 # Throw an error
                 throw new Scaffold_User_Exception("CSS is not valid - {$count} errors", $message);
             }
         }
     }
 }
예제 #6
0
 public static function output()
 {
     if (CSScaffold::config('core.options.output') == "grid" && isset(self::$column_width)) {
         # Make sure we're sending HTML
         header('Content-Type: text/html');
         # Load the test suite markup
         $page = CSScaffold::load_view('Layout_grid');
         # Echo and out!
         echo $page;
         exit;
     }
 }
예제 #7
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);
             }
         }
     }
 }
예제 #8
0
파일: CSS.php 프로젝트: pdclark/csscaffold
 /**
  * Finds all url()'s that start with ~/ and replaces it
  * with the CSS url.
  *
  * @return void
  */
 public static function replace_css_urls()
 {
     if ($found = CSS::find_functions('url')) {
         foreach ($found[1] as $url) {
             $url = unquote($url);
             if ($url[0] == "~") {
                 self::replace($url, str_replace('~/', CSScaffold::config('core.url.css'), $url));
             }
         }
     }
 }
예제 #9
0
 /**
  * Resolves a path used in the CSS so that the user can use
  * paths like normal css rather than PHP
  *
  * @author Anthony Short
  * @param $path
  * @return string
  */
 public static function resolve_path($path)
 {
     if ($path[0] == "/") {
         $path = DOCROOT . $path;
     } else {
         # Join the CSS directory with the requested directory
         $path = join_path(CSSPATH, CSScaffold::config('core.request.relative_dir'), $path);
         # Get the full server path to the file
         $path = realpath($path);
     }
     return $path;
 }