public static function create_gradient($direction, $size, $from, $to, $stops = false) { if (!class_exists('GradientGD')) { include dirname(__FILE__) . '/libraries/gradientgd.php'; } $file = "{$direction}_{$size}_" . str_replace('#', '', $from) . "_" . str_replace('#', '', $to) . ".png"; if ($direction == 'horizontal') { $height = 50; $width = $size; $repeat = 'y'; } else { $height = $size; $width = 50; $repeat = 'x'; } if (!Scaffold_Cache::exists('gradients/' . $file)) { Scaffold_Cache::create('gradients'); $file = Scaffold_Cache::find('gradients') . '/' . $file; $gradient = new GradientGD($width, $height, $direction, $from, $to, $stops); $gradient->save($file); } $file = Scaffold_Cache::find('gradients') . '/' . $file; self::$gradients[] = array($direction, $size, $from, $to, $file); $properties = "\n\t\t\tbackground-position: top left;\n\t\t background-repeat: repeat-{$repeat};\n\t\t background-image: url(" . Scaffold::url_path($file) . ");\n\t\t"; return $properties; }
public static function create_rgba($r, $g, $b, $a) { if (!class_exists('RgbaGd')) { include dirname(__FILE__) . '/libraries/rgbagd.php'; } $file = "color_r{$r}_g{$g}_b{$b}_a{$a}.png"; $alpha = intval(127 - 127 * $a); if (!Scaffold_Cache::exists('rgba/' . $file)) { Scaffold_Cache::create('rgba'); $file = Scaffold_Cache::find('rgba') . '/' . $file; $rgba = new RgbaGd($r, $g, $b, $alpha); $rgba->save($file); } $file = Scaffold_Cache::find('rgba') . '/' . $file; self::$rgba[] = array($r, $g, $b, $alpha); $properties = "\n\t\t\tbackground-position: top left;\n\t\t background-repeat: repeat;\n\t\t background-image: url(" . Scaffold::url_path($file) . ") !important;\n\t\t background-image:none;\n\t\t background: rgba({$r},{$g},{$b},{$a});\n\t\t filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" . Scaffold::url_path($file) . ", sizingMethod=scale);\n\t\t"; return $properties; }
/** * Parse the CSS. This takes an array of files, options and configs * and parses the CSS, outputing the processed CSS string. * * @param array List of files * @param array Configuration options * @param string Options * @param boolean Return the CSS rather than displaying it * @return string The processed css file as a string */ public static function parse($files, $config, $options = array(), $display = false) { # Benchmark will do the entire run from start to finish Scaffold_Benchmark::start('system'); try { # Setup the cache and other variables/constants Scaffold::setup($config); self::$options = $options; $css = false; # Time it takes to get the flags Scaffold_Benchmark::start('system.flags'); # Get the flags from each of the loaded modules. $flags = self::$flags === false ? array() : self::flags(); # Time it takes to get the flags Scaffold_Benchmark::stop('system.flags'); # The final, combined CSS file in the cache $combined = md5(serialize(array($files, $flags))) . '.css'; /** * Check if we should use the combined cache right now and skip unneeded processing */ if (SCAFFOLD_PRODUCTION === true and Scaffold_Cache::exists($combined) and Scaffold_Cache::is_fresh($combined)) { Scaffold::$output = Scaffold_Cache::open($combined); } if (Scaffold::$output === null) { # We're processing the files Scaffold_Benchmark::start('system.check_files'); foreach ($files as $file) { # The time to process a single file Scaffold_Benchmark::start('system.file.' . basename($file)); # Make sure this file is allowed if (substr($file, 0, 4) == "http" or substr($file, -4, 4) != ".css") { Scaffold::error('Scaffold cannot the requested file - ' . $file); } /** * If there are flags, we'll include them in the filename */ if (!empty($flags)) { # Webligo PHP5.1 compat $cached_file = dirname($file) . DIRECTORY_SEPARATOR . substr(basename($file), 0, strrpos(basename($file), '.')) . '_' . implode('_', $flags) . '.css'; # $cached_file = dirname($file) . DIRECTORY_SEPARATOR . pathinfo($file, PATHINFO_FILENAME) . '_' . implode('_', $flags) . '.css'; } else { $cached_file = $file; } $request = Scaffold::find_file($file, false, true); /** * While not in production, we want to to always recache, so we'll fake the time */ $modified = SCAFFOLD_PRODUCTION ? Scaffold_Cache::modified($cached_file) : 0; /** * If the CSS file has been changed, or the cached version doesn't exist */ if (!Scaffold_Cache::exists($cached_file) or $modified < filemtime($request)) { Scaffold_Cache::write(Scaffold::process($request), $cached_file); Scaffold_Cache::remove($combined); } $css .= Scaffold_Cache::open($cached_file); # The time it's taken to process this file Scaffold_Benchmark::stop('system.file.' . basename($file)); } Scaffold::$output = $css; /** * If any of the files have changed we need to recache the combined */ if (!Scaffold_Cache::exists($combined)) { Scaffold_Cache::write(self::$output, $combined); } # The time it takes to process the files Scaffold_Benchmark::stop('system.check_files'); /** * Hook to modify what is sent to the browser */ if (SCAFFOLD_PRODUCTION === false) { Scaffold::hook('display'); } } /** * Set the HTTP headers for the request. Scaffold will set * all the headers required to score an A grade on YSlow. This * means your CSS will be sent as quickly as possible to the browser. */ $length = strlen(Scaffold::$output); $modified = Scaffold_Cache::modified($combined); $lifetime = SCAFFOLD_PRODUCTION === true ? $config['cache_lifetime'] : 0; Scaffold::set_headers($modified, $lifetime, $length); /** * If the user wants us to render the CSS to the browser, we run this event. * This will send the headers and output the processed CSS. */ if ($display === true) { Scaffold::render(Scaffold::$output, $config['gzip_compression']); } # Benchmark will do the entire run from start to finish Scaffold_Benchmark::stop('system'); } catch (Exception $e) { /** * The message returned by the error */ $message = $e->getMessage(); /** * Load in the error view */ if (SCAFFOLD_PRODUCTION === false && $display === true) { Scaffold::send_headers(); require Scaffold::find_file('scaffold_error.php', 'views'); } } # Log the final execution time #$benchmark = Scaffold_Benchmark::get('system'); #Scaffold_Log::log('Total Execution - ' . $benchmark['time']); # Save the logs and exit Scaffold_Event::run('system.shutdown'); return self::$output; }