Esempio n. 1
0
 /**
  * Make a new placeholdr image using the PHP GD extension.
  *
  * @param  integer  $width
  * @param  integer $height
  * @param  string  $text
  * @return string|false
  */
 public function make($width, $height = 0, $text = '')
 {
     $width = (int) $width;
     $height = (int) $height;
     $text = trim($text);
     // The width is invalid, but lets fallback to width and height of 1px
     if ($width === 0) {
         $width = $height = 1;
     }
     // If the height is not specified or is too small, then default to the same
     // width size, thus making it a square.
     if ($height === 0) {
         $height = $width;
     }
     if ($width > Config::get('placeholdr::placeholdr.maximum_width')) {
         $width = Config::get('placeholdr::placeholdr.maximum_width');
     }
     if ($height > Config::get('placeholdr::placeholdr.maximum_height')) {
         $height = Config::get('placeholdr::placeholdr.maximum_height');
     }
     if ($text === '' or empty($text)) {
         $text = "{$width} X {$height}";
     }
     // Image otuput file name
     $image_output_name = md5($width . $height . $text) . '.png';
     // Output image file path
     $image_output_file = Config::get('placeholdr::placeholdr.placeholdrs_path') . $image_output_name;
     if (File::exists($image_output_file)) {
         return $image_output_file;
     } else {
         // Background color
         $bg_color = 'CCCCCC';
         // Text color
         $text_color = 'FFFFFF';
         // create the image resource
         $image = imagecreate($width, $height);
         // we are making two colors one for BackGround and one for ForeGround
         $bg_color = imagecolorallocate($image, base_convert(substr($bg_color, 0, 2), 16, 10), base_convert(substr($bg_color, 2, 2), 16, 10), base_convert(substr($bg_color, 4, 2), 16, 10));
         // Text color
         $text_color = imagecolorallocate($image, base_convert(substr($text_color, 0, 2), 16, 10), base_convert(substr($text_color, 2, 2), 16, 10), base_convert(substr($text_color, 4, 2), 16, 10));
         //Fill the background color
         imagefill($image, 0, 0, $bg_color);
         // Font face
         $font_face = Config::get('placeholdr::placeholdr.gd.font_face');
         // Calculate font size
         $font_size = $width > $height ? $height / 10 : $width / 10;
         // write the text .. with some alignment estimations
         imagettftext($image, $font_size, 0, $width / 2 - $font_size * 2.75, $height / 2 + $font_size * 0.2, $text_color, $font_face, $text);
         // Output buffer
         ob_start();
         // output the newly created image in png format
         imagepng($image);
         // Copy buffer
         $image_output = ob_get_clean();
         // free up resources
         imagedestroy($image);
         // Save buffer
         return File::put($image_output_file, $image_output) ? $image_output_file : false;
     }
 }
Esempio n. 2
0
 /**
  * Checks, if the cache has the given file
  * @param  string  $file     The filename
  * @param  int     $lifetime Lifetime of the file in cache
  * @return boolean false if not found
  */
 public static function has($file, $lifetime = 0)
 {
     static::loadConfig();
     $lifetime = $lifetime > 0 ? $lifetime : static::$cache_lifetime;
     $file = static::$cache_path . $file;
     if (File::exists($file)) {
         $filemtime = filemtime($file);
         if ($filemtime + $lifetime < time()) {
             File::delete($file);
             return false;
         }
         return true;
     }
 }
Esempio n. 3
0
 public function minify($group, $assets)
 {
     $combined_assets = array();
     foreach ($assets as $name => $data) {
         asort($data['attributes']);
         $attributes_string = json_encode($data['attributes']);
         $combined_assets[$attributes_string][$name] = $data;
     }
     $assets_html = '';
     $compile = false;
     foreach ($combined_assets as $attributes_string => $assets) {
         $files_to_compile = array();
         $output_files = array();
         foreach ($assets as $name => $data) {
             $file = path('public') . $data['source'];
             if (!File::exists($file)) {
                 throw new Exception('The Asset you are trying to compress does not exist (' . $file . ')');
             }
             $output_files[] = $name . '.' . ($group == 'script' ? 'js' : 'css');
             $files_to_compile[] = $data['source'];
         }
         $output_file = implode(',', $output_files);
         if (!count($output_files)) {
             return;
         }
         if (!file_exists($this->config['cache_dir_path'] . $output_file)) {
             $compile = true;
         } else {
             foreach ($files_to_compile as $file) {
                 if (File::modified($this->config['cache_dir_path'] . $output_file) < File::modified(path('public') . $file)) {
                     $compile = true;
                 }
             }
         }
         $method = 'minify_' . $group;
         $assets_html .= $this->{$method}($assets, $data['attributes'], $files_to_compile, $output_file, $compile);
     }
     return $assets_html;
 }
Esempio n. 4
0
 public static function schema($action, $module_slug)
 {
     try {
         // Does the schema task file exists?
         $schema_path = path('bundle') . $module_slug . DS . 'tasks' . DS . 'schema' . EXT;
         if (\Laravel\File::exists($schema_path)) {
             include_once $schema_path;
             // Does the class exists?
             $class = Str::title($module_slug . '_Schema_Task');
             if (class_exists($class)) {
                 $schema_class = new $class();
                 // The action is callable?
                 if (is_callable(array($schema_class, $action))) {
                     $schema_class->{$action}();
                     return true;
                 } else {
                     Log::error('Failed to run data schema for module ' . $module_slug . '. Schema action [' . $action . '] not found.');
                 }
             } else {
                 Log::error('Failed to run data schema for module ' . $module_slug . '. Schema class [' . $class . '] not found.');
             }
         }
         // we dont have task schema to run
         return true;
     } catch (\Exception $e) {
         Log::error($e->getMessage());
         return false;
     }
 }
Esempio n. 5
0
 /**
  * Saves an Image
  * @param  string $file_name The new Filename
  * @param  bool   $override  True to override existing files
  * @param  bool   $destroy   True to destroy the Imwg instance
  * @return array  with infos about the image. example:<code>
  *    (
  *         [width] => 32
  *         [height] => 32
  *         [type] => GIF
  *         [attr] => width="32" height="32"
  *         [bits] => 4
  *         [channels] => 3
  *         [mime] => image/gif
  *     )
  * </code>
  */
 public function save($file_name, $override = true, $destroy = true)
 {
     if (static::$image_resource) {
         if (!File::exists($file_name) || $override) {
             // JPEG
             if (static::$file_info['type'] == "JPG") {
                 ImageJPEG(static::$image_resource, $file_name, static::$image_quality);
             } elseif (static::$file_info['type'] == "GIF") {
                 ImageGIF(static::$image_resource, $file_name);
             } elseif (static::$file_info['type'] == "PNG") {
                 ImagePNG(static::$image_resource, $file_name, static::$image_quality);
             }
         }
         // cache $file_info
         $file_info = static::$file_info;
         if ($destroy) {
             // destroy all resources
             $this->destroy();
         }
         // return the infos about the image
         return $file_info;
     }
 }
Esempio n. 6
0
<?php

Route::get('(:bundle)/rejigger.js', array('as' => 'rejigger_js', function () {
    return View::make('rejigger::js');
}));
Route::get('(:bundle)/version', array('as' => 'rejigger_version', function () {
    // Don't let the controller mistake this for a regular AJAX call
    unset($_SERVER['HTTP_X_REQUESTED_WITH']);
    $uri = \Rejigger\URI::resolve(Input::get('uri'));
    $route = \Laravel\Routing\Router::route('GET', $uri);
    $response = $route->call();
    $version = md5($response->content);
    // Parse out resources (css & script)
    preg_match_all('/\\<script[^\\>]+src=\\"(?P<src>[^\\"]+)\\"[^\\>]*\\>/i', $response->content, $scripts);
    preg_match_all('/\\<link[^\\>]+href=\\"(?P<href>[^\\"]+)\\"[^\\>]*\\>/i', $response->content, $styles);
    preg_match_all('/\\<img[^\\>]+src=\\"(?P<src>[^\\"]+)\\"[^\\>]*\\>/i', $response->content, $images);
    $resources = array_merge($scripts['src'], $styles['href'], $images['src']);
    $public = path('public');
    foreach ($resources as $resource) {
        $resource = $public . str_replace(\Laravel\URL::base(), '', $resource);
        if (\Laravel\File::exists($resource)) {
            $version .= File::modified($resource);
        }
    }
    return '{ "version": "' . md5($version) . '" }';
}));
Esempio n. 7
0
 /**
  * Starts the activated ibundles as bundles.
  *
  * @return array
  */
 public function register()
 {
     if (empty($this->registered)) {
         foreach ($this->activated() as $bundle => $config) {
             if (!Laravel_File::exists(ibundle_config('path') . $bundle)) {
                 // Remove it and skip registration
                 $this->deactivate($bundle);
                 continue;
             }
             if (!Bundle::exists($bundle)) {
                 // register the bundle using the ibundle.json data
                 Bundle::register($bundle, $config);
                 if (isset($config['auto']) and $config['auto'] === true) {
                     // Start the registered bundle
                     Bundle::start($bundle);
                     if (Bundle::started($bundle)) {
                         $this->registered[$bundle] = $config;
                     }
                 }
             }
         }
     }
     return (array) $this->registered;
 }