Beispiel #1
0
    /**
     * Takes a CSS string, rewrites all URL's using Scaffold's built-in find_file method
     *
     * @author Anthony Short
     * @param $css
     * @return $css string
     */
    public static function formatting_process()
    {
        # The absolute url to the directory of the current CSS file
        $dirPath = SCAFFOLD_DOCROOT . Scaffold::url_path(Scaffold::$css->path);
        $dir = rtrim(SCAFFOLD_URLPATH, '\\/') . '/' . str_replace(rtrim(SCAFFOLD_DOCROOT, '\\/') . DIRECTORY_SEPARATOR, '', Scaffold::$css->path);
        //$dir = str_replace('\\', '/', SCAFFOLD_URLPATH . str_replace(SCAFFOLD_DOCROOT, '', Scaffold::$css->path));
        # @imports - Thanks to the guys from Minify for the regex :)
        if (preg_match_all('/
			        @import\\s+
			        (?:url\\(\\s*)?      # maybe url(
			        [\'"]?               # maybe quote
			        (.*?)                # 1 = URI
			        [\'"]?               # maybe end quote
			        (?:\\s*\\))?         # maybe )
			        ([a-zA-Z,\\s]*)?     # 2 = media list
			        ;                    # end token
			    /x', Scaffold::$css->string, $found)) {
            foreach ($found[1] as $key => $value) {
                # Should we skip it
                if (self::skip($value)) {
                    continue;
                }
                $media = $found[2][$key] == "" ? '' : ' ' . preg_replace('/\\s+/', '', $found[2][$key]);
                # Absolute path
                $absolute = self::up_directory($dir, substr_count($url, '..' . DIRECTORY_SEPARATOR, 0)) . str_replace('..' . DIRECTORY_SEPARATOR, '', $url);
                $absolute = str_replace('\\', '/', $absolute);
                # Rewrite it
                # Webligo - PHP5.1 compat
                Scaffold::$css->string = str_replace($found[0][$key], '@import \'' . $absolute . '\'' . $media . ';', Scaffold::$css->string);
            }
        }
        # Convert all url()'s to absolute paths if required
        if (preg_match_all('/url\\(\\s*([^\\)\\s]+)\\s*\\)/', Scaffold::$css->__toString(), $found)) {
            foreach ($found[1] as $key => $value) {
                // START - Webligo Developments
                $original = $found[0][$key];
                $url = Scaffold_Utils::unquote($value);
                # Absolute Path
                if (self::skip($url)) {
                    continue;
                }
                # home path
                if ($url[0] == '~' && $url[1] == '/') {
                    $absolute = str_replace('\\', '/', rtrim(SCAFFOLD_URLPATH, '/\\') . '/' . ltrim($url, '~/'));
                    $absolutePath = rtrim(SCAFFOLD_DOCROOT, '/\\') . DIRECTORY_SEPARATOR . ltrim($url, '~/');
                } else {
                    $absolute = str_replace('\\', '/', self::up_directory($dir, substr_count($url, '..' . DIRECTORY_SEPARATOR, 0)) . str_replace('..' . DIRECTORY_SEPARATOR, '', $url));
                    $absolutePath = self::up_directory($dirPath, substr_count($url, '..' . DIRECTORY_SEPARATOR, 0)) . str_replace('..' . DIRECTORY_SEPARATOR, '', $url);
                }
                # If the file doesn't exist
                if (!Scaffold::find_file($absolutePath)) {
                    Scaffold::log("Missing image - {$absolute} / {$absolutePath}", 1);
                }
                # Rewrite it
                Scaffold::$css->string = str_replace($original, 'url(' . $absolute . ')', Scaffold::$css->string);
                # Webligo - PHP5.1 compat
                // END - Webligo Developments
            }
        }
    }
function Scaffold_image_replace_matrix($params)
{
    if (preg_match_all('/\\([^)]*?,[^)]*?\\)/', $params, $matches)) {
        foreach ($matches as $key => $original) {
            $new = str_replace(',', '#COMMA#', $original);
            $params = str_replace($original, $new, $params);
        }
    }
    $params = explode(',', $params);
    foreach (array('url', 'width', 'height', 'x', 'y') as $key => $name) {
        ${$name} = trim(str_replace('#COMMA#', ',', array_shift($params)));
    }
    $url = preg_replace('/\\s+/', '', $url);
    $url = preg_replace('/url\\([\'\\"]?|[\'\\"]?\\)$/', '', $url);
    if (!$x) {
        $x = 0;
    }
    if (!$y) {
        $y = 0;
    }
    $path = Scaffold::find_file($url);
    if ($path === false) {
        return false;
    }
    // Make sure theres a value so it doesn't break the css
    if (!$width && !$height) {
        $width = $height = 0;
    }
    // Build the selector
    $properties = "background:url(" . Scaffold::url_path($path) . ") no-repeat {$x}px {$y}px;\n\t\theight:{$height}px;\n\t\twidth:{$width}px;\n\t\tdisplay:block;\n\t\ttext-indent:-9999px;\n\t\toverflow:hidden;";
    return $properties;
}
 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;
 }
Beispiel #4
0
    /**
     * Takes a CSS string, rewrites all URL's using Scaffold's built-in find_file method
     *
     * @author Anthony Short
     * @param $css
     * @return $css string
     */
    public static function formatting_process()
    {
        # The absolute url to the directory of the current CSS file
        $dir = Scaffold::url_path(Scaffold::$css->path);
        # @imports - Thanks to the guys from Minify for the regex :)
        if (preg_match_all('/
			        @import\\s+
			        (?:url\\(\\s*)?      # maybe url(
			        [\'"]?               # maybe quote
			        (.*?)                # 1 = URI
			        [\'"]?               # maybe end quote
			        (?:\\s*\\))?         # maybe )
			        ([a-zA-Z,\\s]*)?     # 2 = media list
			        ;                    # end token
			    /x', Scaffold::$css, $found)) {
            foreach ($found[1] as $key => $value) {
                # Should we skip it
                if (self::skip($value)) {
                    continue;
                }
                $media = $found[2][$key] == "" ? '' : ' ' . preg_replace('/\\s+/', '', $found[2][$key]);
                # Absolute path
                $absolute = self::up_directory($dir, substr_count($value, '..' . DIRECTORY_SEPARATOR, 0)) . str_replace('..' . DIRECTORY_SEPARATOR, '', $value);
                # Rewrite it
                Scaffold::$css->string = str_replace($found[0][$key], '@import \'' . $absolute . '\'' . $media . ';', Scaffold::$css);
            }
        }
        # Convert all url()'s to absolute paths if required
        if (preg_match_all('/url\\(\\s*([^\\)\\s]+)\\s*\\)/', Scaffold::$css, $found)) {
            foreach ($found[1] as $key => $value) {
                $url = Scaffold_Utils::unquote($value);
                # Absolute Path
                if (self::skip($url)) {
                    continue;
                }
                # Absolute path
                $absolute = self::up_directory($dir, substr_count($url, '..' . DIRECTORY_SEPARATOR, 0)) . str_replace('..' . DIRECTORY_SEPARATOR, '', $url);
                # If the file doesn't exist
                if (!Scaffold::find_file($absolute)) {
                    Scaffold::log("Missing image - {$absolute}", 1);
                }
                # Rewrite it
                Scaffold::$css->string = str_replace($found[0][$key], 'url(' . $absolute . ')', Scaffold::$css);
            }
        }
    }
Beispiel #5
0
 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;
 }
/**
 * Adds the image-replace property that allows you to automatically
 * replace text with an image on your server.
 *
 * Because functions can't have - in their name, it is replaced
 * with an underscore. The property name is still image-replace
 *
 * @author Anthony Short
 * @param $url
 * @return string
 */
function Scaffold_image_replace($url)
{
    $url = preg_replace('/\\s+/', '', $url);
    $url = preg_replace('/url\\([\'\\"]?|[\'\\"]?\\)$/', '', $url);
    $path = Scaffold::find_file($url);
    if ($path === false) {
        return false;
    }
    // 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 = "background:url(" . Scaffold::url_path($path) . ") no-repeat 0 0;\n\t\theight:{$height}px;\n\t\twidth:{$width}px;\n\t\tdisplay:block;\n\t\ttext-indent:-9999px;\n\t\toverflow:hidden;";
    return $properties;
}
 /**
  * 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)
 {
     # Path to the image
     $file = "{$lgw}_{$cw}_{$rgw}_{$bl}_grid.png";
     if (($cache = Scaffold_Cache::find('Layout/' . $file)) === false) {
         Scaffold_Cache::create('Layout');
         $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);
         $cache = Scaffold_Cache::find('Layout') . '/' . $file;
         ImagePNG($image, $cache);
         # Kill it
         ImageDestroy($image);
     }
     return Scaffold::url_path($cache);
 }