예제 #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
            }
        }
    }
예제 #2
0
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;
}
예제 #3
0
 /**
  * Imports css via @import statements
  * 
  * @author Anthony Short
  * @param $css
  */
 public static function server_import($css, $base)
 {
     if (preg_match_all('/\\@include\\s+(?:\'|\\")([^\'\\"]+)(?:\'|\\")\\;/', $css, $matches)) {
         $unique = array_unique($matches[1]);
         $include = str_replace("\\", "/", Scaffold_Utils::unquote($unique[0]));
         # 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 (pathinfo($include, PATHINFO_EXTENSION) != 'css') {
             $css = str_replace($matches[0][0], '', $css);
             Scaffold::log('Invalid @include file - ' . $include);
             self::server_import($css, $base);
         }
         # Find the file
         if ($path = Scaffold::find_file($include, $base)) {
             # Make sure it hasn't already been included
             if (!in_array($path, self::$loaded)) {
                 self::$loaded[] = $path;
                 $contents = file_get_contents($path);
                 # Check the file again for more imports
                 $contents = self::server_import($contents, realpath(dirname($path)) . '/');
                 $css = str_replace($matches[0][0], $contents, $css);
             } else {
                 $css = str_replace($matches[0][0], '', $css);
             }
         } else {
             Scaffold::error('Can\'t find the @include file - <strong>' . $unique[0] . '</strong>');
         }
         $css = self::server_import($css, $base);
     }
     return $css;
 }
예제 #4
0
/**
 * Embeds a file in the CSS using Base64
 *
 * @param $file
 * @return string
 */
function Scaffold_embed($file)
{
    $path = Scaffold::find_file(Scaffold_Utils::unquote($file));
    # Couldn't find it
    if ($path === false) {
        return false;
    }
    $data = 'data:image/' . pathinfo($path, PATHINFO_EXTENSION) . ';base64,' . base64_encode(file_get_contents($path));
    return "url(" . $data . ")";
}
예제 #5
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);
            }
        }
    }
예제 #6
0
/**
 * Adds the image-width property that allows you to automatically
 * obtain the width of a image
 *
 * Because functions can't have - in their name, it is replaced
 * with an underscore. The property name is still image-width
 *
 * @author Kirk Bentley
 * @param $url
 * @return string
 */
function Scaffold_image_width($url, $w = false)
{
    $url = preg_replace('/\\s+/', '', $url);
    $url = preg_replace('/url\\([\'\\"]?|[\'\\"]?\\)$/', '', $url);
    $path = Scaffold::find_file($url);
    if ($path === false) {
        return false;
    }
    // Get the width of the image file
    $size = GetImageSize($path);
    $width = $size[0];
    if ($w == '50%') {
        $width = $width * 0.5;
    }
    // Make sure theres a value so it doesn't break the css
    if (!$width) {
        $width = 0;
    }
    return $width;
}
/**
 * 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;
}
예제 #8
0
/**
 * Adds the image-width property that allows you to automatically
 * obtain the height of a image
 *
 * Because functions can't have - in their name, it is replaced
 * with an underscore. The property name is still image-height
 *
 * @author Kirk Bentley
 * @param $url
 * @return string
 */
function Scaffold_image_height($url, $h = false)
{
    $url = preg_replace('/\\s+/', '', $url);
    $url = preg_replace('/url\\([\'\\"]?|[\'\\"]?\\)$/', '', $url);
    $h = trim($h);
    $path = Scaffold::find_file($url);
    if ($path === false) {
        return false;
    }
    // Get the width of the image file
    $size = GetImageSize($path);
    $height = $size[1];
    if ($h == '50%') {
        $height = $height * 0.5;
    }
    // Make sure theres a value so it doesn't break the css
    if (!$height) {
        $height = 0;
    }
    return $height;
}
예제 #9
0
/**
 * 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-holder-position
 *
 * @author Kirk Bentley
 * @param $url
 * @param $x - x position
 * @param $y - y position
 * @return string
 */
function Scaffold_image_holder_position($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', 'x', 'y') as $key => $name) {
        ${$name} = trim(str_replace('#COMMA#', ',', array_shift($params)));
    }
    $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;
    }
    $left = $x;
    if ($x == '50%') {
        $left = -$width * 0.5;
    }
    $top = $y;
    if ($y == '50%') {
        $top = -$height * 0.5;
    }
    // Build the selector
    $properties = "top:{$top}px;\n\t\tleft:{$left}px;";
    return $properties;
}
예제 #10
0
파일: Scaffold.php 프로젝트: robeendey/ce
 /**
  * Sets the initial variables, checks if we need to process the css
  * and then sends whichever file to the browser.
  *
  * @return void
  */
 public static function setup($config)
 {
     /**
      * Choose whether to show or hide errors
      */
     if (SCAFFOLD_PRODUCTION === false) {
         ini_set('display_errors', true);
         error_reporting(E_ALL & ~E_STRICT);
     } else {
         ini_set('display_errors', false);
         error_reporting(0);
     }
     /**
      * Define contstants for system paths for easier access.
      */
     if (!defined('SCAFFOLD_SYSPATH') && !defined('SCAFFOLD_DOCROOT')) {
         define('SCAFFOLD_SYSPATH', self::fix_path($config['system']));
         define('SCAFFOLD_DOCROOT', $config['document_root']);
         define('SCAFFOLD_URLPATH', str_replace(SCAFFOLD_DOCROOT, '', SCAFFOLD_SYSPATH));
     }
     /**
      * Add include paths for finding files
      */
     Scaffold::add_include_path(SCAFFOLD_SYSPATH, SCAFFOLD_DOCROOT);
     /**
      * Tell the cache where to save files and for how long to keep them for
      */
     Scaffold_Cache::setup(Scaffold::fix_path($config['cache']), $config['cache_lifetime']);
     /**
      * The level at which logged messages will halt processing and be thrown as errors
      */
     self::$error_threshold = $config['error_threshold'];
     /**
      * Disabling flags allows for quicker processing
      */
     if ($config['disable_flags'] === true) {
         self::$flags = false;
     }
     /**
      * Tell the log where to save it's files. Set it to automatically save the log on exit
      */
     if ($config['enable_log'] === true) {
         // START - Modified by Webligo Developments
         if ($config['log_path']) {
             Scaffold_Log::log_directory($config['log_path']);
         } else {
             Scaffold_Log::log_directory(SCAFFOLD_SYSPATH . 'logs');
         }
         // END - Modified by Webligo Developments
         //Scaffold_Log::log_directory(SCAFFOLD_SYSPATH.'logs');
         Scaffold_Event::add('system.shutdown', array('Scaffold_Log', 'save'));
     }
     /**
      * Load each of the modules
      */
     foreach (Scaffold::list_files(SCAFFOLD_SYSPATH . 'modules') as $module) {
         $name = basename($module);
         $module_config = SCAFFOLD_SYSPATH . 'config/' . $name . '.php';
         if (file_exists($module_config)) {
             unset($config);
             include $module_config;
             self::$config[$name] = $config;
         }
         self::add_include_path($module);
         if ($controller = Scaffold::find_file($name . '.php', false, true)) {
             require_once $controller;
             self::$modules[$name] = new $name();
         }
     }
     /**
      * Module Initialization Hook
      * This hook allows modules to load libraries and create events
      * before any processing is done at all. 
      */
     self::hook('initialize');
     /**
      * Create the shutdown event
      */
     Scaffold_Event::add('system.shutdown', array('Scaffold', 'shutdown'));
 }
예제 #11
0
 /**
  * Parse the @grid rule and calculate the grid.
  *
  * @author Anthony Short
  * @param $css
  */
 public static function import_process()
 {
     if ($settings = Scaffold::$css->find_at_group('grid')) {
         $groups = $settings['groups'];
         $settings = $settings['values'];
         # You really should only have one @grid
         if (count($groups) > 1) {
             Scaffold::error('Layout module can only use one @grid rule');
         }
         # Make sure the groups have all the right properties
         self::check_grid($groups[0], $settings);
         # The number of columns
         $cc = $settings['column-count'];
         # The tyopgraphic baseline
         $bl = $settings['baseline'];
         # The left gutter on grid columns
         $lgw = isset($settings['left-gutter-width']) ? $settings['left-gutter-width'] : 0;
         # The right gutter on grid columns
         $rgw = isset($settings['right-gutter-width']) ? $settings['right-gutter-width'] : 0;
         # The combined gutter widths
         $gw = $settings['gutter-width'] = $lgw + $rgw;
         # The total width of the grid
         $grid = $settings['grid-width'];
         # The grid width minus all the gutter widths
         $netgridwidth = $grid - $cc * $gw;
         # The width of a single column
         $cw = floor($netgridwidth / $cc);
         self::$grid_settings = array('column_width' => $cw, 'gutter_width' => $gw, 'left_gutter_width' => $lgw, 'right_gutter_width' => $rgw, 'grid_width' => $grid, 'baseline' => $bl);
         /**
          * Set each of the column widths as Constants. They 
          * can be accessed like this: $columns_1
          */
         if (class_exists('Constants')) {
             for ($i = 1; $i <= $cc; $i++) {
                 Constants::set('columns_' . $i, $i * $cw + ($i * $gw - $gw) . 'px');
             }
         }
         /**
          * Set them as constants we can use in the css. They can
          * be accessed like this: $column_count
          */
         foreach (self::$grid_settings as $key => $value) {
             Constants::set($key, $value . 'px');
         }
         # Set this seperately as it doesn't need px added to it
         self::$grid_settings['column_count'] = $cc;
         Constants::set('column_count', $cc);
         /**
          * Create the grid background image
          */
         $img = self::create_grid_image($cw, $bl, $lgw, $rgw);
         Scaffold::$css->string .= "=grid-overlay{background:url('" . $img . "');} .grid-overlay { +grid-overlay; }";
         /**
          * Include the mixin templates so you can access each of
          * the grid properties with mixins like this: +columns(4);
          */
         $mixins = Scaffold::find_file('templates/mixins.css');
         $classes = Scaffold::find_file('templates/classes.css');
         if ($mixins !== false and $classes !== false) {
             Scaffold::$css->string .= file_get_contents($mixins);
             Scaffold::$css->string .= file_get_contents($classes);
         }
     }
 }