/** * 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], ''); } }
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; } }
/** * 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; }
/** * 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); } }
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); } } } }
/** * Generates the background grid.png * * @author Anthony Short * @param $cl Column width * @param $bl Baseline * @param $gw Gutter Width * @return null */ private static function create_grid_image($cw, $bl, $lgw, $rgw, $file) { if (!file_exists($file)) { $image = ImageCreate($cw + $lgw + $rgw, $bl); $colorWhite = ImageColorAllocate($image, 255, 255, 255); $colorGrey = ImageColorAllocate($image, 200, 200, 200); $colorBlue = ImageColorAllocate($image, 240, 240, 255); # Draw left gutter Imagefilledrectangle($image, 0, 0, $lgw - 1, $bl, $colorWhite); # Draw column Imagefilledrectangle($image, $lgw, 0, $cw + $lgw - 1, $bl, $colorBlue); # Draw right gutter Imagefilledrectangle($image, $lgw + $cw + 1, 0, $lgw + $cw + $rgw, $bl, $colorWhite); # Draw baseline imageline($image, 0, $bl - 1, $lgw + $cw + $rgw, $bl - 1, $colorGrey); CSScaffold::cache_create(dirname($file)); ImagePNG($image, $file); # Kill it ImageDestroy($image); } }
/** * 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); } } } }
/** * 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)); } } } }
/** * Import mixins * * @author Anthony Short * @return string */ public static function import_mixins($dir) { if ($mixin_files = CSScaffold::list_files($dir, true)) { foreach ($mixin_files as $item) { if (!is_css($item)) { continue; } # Add it to our css CSS::append(file_get_contents($item)); } } else { throw new Scaffold_Exception('Cannot find the mixin directory - ' . $dir); } }
/** * Loads a library */ public static function load_library($library) { require_once CSScaffold::find_file('libraries', $library, TRUE); }
/** * Set exception message. * * @param string i18n language key for the message * @param array addition line parameters */ public function __construct($error) { $args = array_slice(func_get_args(), 1); # Fetch the error message $message = CSScaffold::lang($error, $args); if ($message === $error or empty($message)) { # Unable to locate the message for the error $message = 'Unknown Exception: ' . $error; } # Sets $this->message the proper way parent::__construct($message); }
* * If you're looking to do something unique, like moving files and folders * around, you'll probably need to change this file or create a custom * front controller for Scaffold. Just keep in mind that the run method * NEEDS those three parameters, the SYSPATH constant and all of the required * files. Apart from that, you should be able to drop it into anything. * * @package CSScaffold */ # Errors. This is overridden by the debug option later. ini_set('display_errors', TRUE); error_reporting(E_ALL & ~E_STRICT); # Include the config file include 'config.php'; # Path to the system directory define('SYSPATH', str_replace('\\', '/', realpath($path['system'])) . '/'); # Include the classes require SYSPATH . 'core/Utils.php'; require SYSPATH . 'core/Benchmark.php'; require SYSPATH . 'core/Module.php'; require SYSPATH . 'core/CSS.php'; require SYSPATH . 'core/Controller.php'; require SYSPATH . 'core/Exception.php'; require SYSPATH . 'vendor/FirePHPCore/fb.php'; require SYSPATH . 'vendor/FirePHPCore/FirePHP.class.php'; # And finally... the one that actually does the work require SYSPATH . 'controllers/CSScaffold.php'; # And we're off! if (isset($_GET['request'])) { CSScaffold::run($_GET, $config, $path); }
/** * 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; }
<?php defined('SYSPATH') or die('No direct access allowed.'); define('SCAFFOLD_VERSION', '1.5b3'); require SYSPATH . '/core/Common.php'; require SYSPATH . '/core/Benchmark.php'; require SYSPATH . '/core/Plugins.php'; require SYSPATH . '/core/CSScaffold.php'; require SYSPATH . '/core/CSS.php'; require SYSPATH . '/vendor/FirePHPCore/fb.php'; require SYSPATH . '/vendor/FirePHPCore/FirePHP.class.php'; # Send the request through to the main controller CSScaffold::setup($_GET); # Parse the css CSScaffold::parse_css(); # Send it to the browser CSScaffold::output_css();
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; } }