Beispiel #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;
     }
 }
 /**
  * Install a bundle from by downloading a Zip.
  *
  * @param  string  $url
  * @param  array   $bundle
  * @param  string  $path
  * @return void
  */
 protected function zipball($url, $bundle, $path)
 {
     $work = path('storage') . 'work/';
     // When installing a bundle from a Zip archive, we'll first clone
     // down the bundle zip into the bundles "working" directory so
     // we have a spot to do all of our bundle extration work.
     $target = $work . 'laravel-bundle.zip';
     File::put($target, $this->download($url));
     $zip = new \ZipArchive();
     $zip->open($target);
     // Once we have the Zip archive, we can open it and extract it
     // into the working directory. By convention, we expect the
     // archive to contain one root directory with the bundle.
     mkdir($work . 'zip');
     $zip->extractTo($work . 'zip');
     $latest = File::latest($work . 'zip')->getRealPath();
     @chmod($latest, 0777);
     // Once we have the latest modified directory, we should be
     // able to move its contents over into the bundles folder
     // so the bundle will be usable by the develoepr.
     File::mvdir($latest, $path);
     File::rmdir($work . 'zip');
     $zip->close();
     @unlink($target);
 }
 /**
  * Create a new Doctrine migration.
  *
  * @param  array  $arguments
  * @return void
  */
 public function make($arguments)
 {
     if (count($arguments) == 0) {
         throw new \Exception("I need to know what to name the migration.");
     }
     list($bundle, $migration) = Bundle::parse($arguments[0]);
     // The migration path is prefixed with the date timestamp, which
     // is a better way of ordering migrations than a simple integer
     // incrementation, since developers may start working on the
     // next migration at the same time unknowingly.
     $prefix = date('Y_m_d_His');
     $path = Bundle::path($bundle) . 'migrations' . DS;
     // If the migration directory does not exist for the bundle,
     // we will create the directory so there aren't errors when
     // when we try to write the migration file.
     if (!is_dir($path)) {
         mkdir($path);
     }
     $file = $path . $prefix . '_' . $migration . EXT;
     File::put($file, $this->stub($bundle, $migration));
     echo "Great! New migration created!";
     // Once the migration has been created, we'll return the
     // migration file name so it can be used by the task
     // consumer if necessary for futher work.
     return $file;
 }
Beispiel #4
0
 /**
  * Set the session driver to a given value.
  *
  * @param  string  $driver
  * @return void
  */
 protected function driver($driver)
 {
     // By default no session driver is set within the configuration.
     // This method will replace the empty driver option with the
     // driver specified in the arguments.
     $config = File::get(path('app') . 'config/session' . EXT);
     $config = str_replace("'driver' => '',", "'driver' => 'database',", $config);
     File::put(path('app') . 'config/session' . EXT, $config);
 }
Beispiel #5
0
 /**
  * Create an empty language file if it doesn't exist.
  *
  * @param string $path
  * @return bool
  */
 public static function create($full_path)
 {
     $dir = str_replace(basename($full_path), '', $full_path);
     if (!is_dir($dir)) {
         static::make($dir);
     }
     if (!file_exists($full_path)) {
         $data = '<?php return array();';
         \Laravel\File::put($full_path, $data);
     }
     return true;
 }
Beispiel #6
0
 public static function set_app_installed()
 {
     // Set application config file index.php
     $config_path = path('app') . 'config' . DS . 'application' . EXT;
     $config = File::get($config_path);
     $newConfig = str_replace("'installed' => false,", "'installed' => true,", $config, $count);
     if (isset($newConfig) and $newConfig != '') {
         if ($count > 0) {
             File::put($config_path, $newConfig);
             Log::info('App flag installed set');
         }
     } else {
         Log::error('App flag installed failed.');
     }
 }
Beispiel #7
0
 /**
  * Generate a random key for the application.
  *
  * @param  array  $arguments
  * @return void
  */
 public function generate($arguments = array())
 {
     // By default the Crypter class uses AES-256 encryption which uses
     // a 32 byte input vector, so that is the length of string we will
     // generate for the application token unless another length is
     // specified through the CLI.
     $key = Str::random(array_get($arguments, 0, 32));
     $config = File::get($this->path);
     $config = str_replace("'key' => '',", "'key' => '{$key}',", $config, $count);
     File::put($this->path, $config);
     if ($count > 0) {
         echo "Configuration updated with secure key!";
     } else {
         echo "An application key already exists!";
     }
     echo PHP_EOL;
 }
Beispiel #8
0
 /**
  * Write a stub phpunit.xml file to the base directory.
  *
  * @param  string  $directory
  * @return void
  */
 protected function stub($directory)
 {
     $path = path('sys') . 'cli/tasks/test/';
     $stub = File::get($path . 'stub.xml');
     // The PHPUnit bootstrap file contains several items that are swapped
     // at test time. This allows us to point PHPUnit at a few different
     // locations depending on what the developer wants to test.
     foreach (array('bootstrap', 'directory') as $item) {
         $stub = $this->{"swap_{$item}"}($stub, $path, $directory);
     }
     File::put(path('base') . 'phpunit.xml', $stub);
 }
Beispiel #9
0
 protected function minify_style($assets, $attributes, $files_to_compile, $output_file, $compile)
 {
     if ($compile) {
         $output_file_contents = '';
         foreach ($files_to_compile as $file) {
             $asset_content = File::get(path('public') . $file);
             $output_file_contents .= Compressor::process($asset_content);
         }
         File::put($this->config['cache_dir_path'] . $output_file, $output_file_contents);
     }
     return HTML::style($this->config['cache_dir'] . $output_file . '?t=' . File::modified($this->config['cache_dir_path'] . $output_file), $attributes);
 }
Beispiel #10
0
 /**
  * Saves activated bundle list to filesystem.
  *
  * @return boolean
  */
 protected function save()
 {
     return (bool) Laravel_File::put(ibundle_config('file'), $this->_data);
 }