Beispiel #1
0
 public function before()
 {
     parent::before();
     if (file_exists(CMSPATH . FileSystem::normalize_path('media/js/i18n/' . I18n::lang() . '-message.js'))) {
         Assets::js('i18n', ADMIN_RESOURCES . 'js/i18n/' . I18n::lang() . '-message.js', 'global');
     }
     if ($this->request->action() != 'logout' and Auth::is_logged_in()) {
         $this->go_home();
     }
 }
Beispiel #2
0
 /**
  * 
  * @param string $path
  */
 public function set_watermark_path($path)
 {
     $path = FileSystem::normalize_path($path);
     $image_path = DOCROOT . $path;
     if ($this->is_image($image_path)) {
         $this->watermark_path = $path;
     } else {
         $this->watermark = FALSE;
         $this->watermark_path = NULL;
     }
 }
Beispiel #3
0
 /**
  * 
  * @param string|SplFileInfo $file
  * @return \FileSystem|\FileSystem_File|\FileSystem_Directory
  * @throws Kohana_Exception
  */
 public static function factory($path)
 {
     if (!$path instanceof SplFileInfo) {
         $path = FileSystem::normalize_path($path);
         if (file_exists($path)) {
             if (!is_dir($path)) {
                 $path = new FileSystem_File($path);
             } else {
                 $path = new FileSystem_Directory($path);
             }
         } else {
             throw new Kohana_Exception('Directory or file :path not found', array(':path' => $path));
         }
     }
     return new FileSystem($path);
 }
Beispiel #4
0
 public function init_media()
 {
     parent::init_media();
     $this->template_js_params['ACE_THEME'] = Config::get('ace', 'theme', 'textmate');
     $this->template_js_params['DEFAULT_FILTER'] = Config::get('site', 'default_filter_id', '');
     Assets::package(array('jquery', 'bootstrap', 'notify', 'select2', 'dropzone', 'fancybox', 'datepicker', 'underscore', 'core'));
     foreach (array('.js', '-message.js') as $file_name) {
         $filename = Kohana::$cache_dir . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, array('i18n', NULL)) . I18n::lang() . $file_name;
         if (file_exists($filename)) {
             Assets::js('i18n', BASE_URL . 'cms/cache/i18n/' . I18n::lang() . $file_name, 'global', FALSE, 0);
         }
     }
     $file = $this->request->controller();
     $directory = $this->request->directory();
     if (!empty($directory)) {
         $file = $directory . '/' . $file;
     }
     $file = strtolower($file);
     if (Kohana::find_file('media', FileSystem::normalize_path('js/controller/' . $file), 'js')) {
         Assets::js('controller.' . $file, ADMIN_RESOURCES . 'js/controller/' . $file . '.js', 'global', FALSE, 999);
     }
     Assets::group('global', 'events', '<script type="text/javascript">' . Assets::merge_files('js/events', 'js') . '</script>', 'global');
 }
Beispiel #5
0
 /**
  * @param string $path
  * @param string $ext
  * @param string $cache_key
  * @param integer $lifetime
  * @return string
  */
 public static function mergeFiles($path, $ext, $cacheKey = NULL, $lifetime = Date::DAY)
 {
     $cache = Cache::instance();
     if ($cache_key === NULL) {
         $cache_key = 'assets::merge::' . URL::title($path, '::') . '::' . $ext;
     }
     $content = $cache->get($cache_key);
     if ($content === NULL) {
         $files = Kohana::find_file('media', FileSystem::normalize_path($path), $ext, TRUE);
         if (!empty($files)) {
             foreach ($files as $file) {
                 $content .= file_get_contents($file) . "\n";
             }
             if (Kohana::$caching === TRUE) {
                 $cache->set($cache_key, $content, $lifetime);
             }
         }
     }
     return $content;
 }
Beispiel #6
0
 /**
  * Создание уменьшенной копии изображения. 
  * Копия помещается в папку  PUBLICPATH . cache
  * 
  * @param string $filepath Путь до файла относительно PUBLICPATH
  * @param integer $width
  * @param integer $height
  * @param integer $master Мастер изменеия размера
  * @param bool $crop Обрезать?
  * 
  * return NULL | string Путь до кеша изображения
  */
 public static function cache($filepath, $width, $height, $master = Image::INVERSE, $crop = FALSE)
 {
     if ($master === NULL) {
         $master = Image::INVERSE;
     }
     $original_image = PUBLICPATH . $filepath;
     if (!is_file($original_image)) {
         return NULL;
     }
     $filename = pathinfo($filepath, PATHINFO_FILENAME);
     $directory = pathinfo($filepath, PATHINFO_DIRNAME);
     $extension = strtolower(pathinfo($filepath, PATHINFO_EXTENSION));
     if (!in_array($extension, array('jpg', 'gif', 'png', 'bmp', 'jpeg'))) {
         return NULL;
     }
     $cached_filename = $filename . '_' . $width . 'x' . $height . 'x' . $master;
     if ($crop === TRUE) {
         $cached_filename .= 'xCR';
     }
     $cached_image = 'cache/' . $directory . '/' . $cached_filename . '.' . $extension;
     $directory = FileSystem::normalize_path($directory);
     if (!is_file(PUBLICPATH . $cached_image) or filectime($original_image) > filectime(PUBLICPATH . $cached_image)) {
         $path = PUBLICPATH . 'cache';
         if (!is_dir($path) and is_writable(PUBLICPATH)) {
             mkdir($path, 0777);
         } else {
             if (!is_writable(PUBLICPATH)) {
                 throw new Kohana_Exception('Unable to write to the cache directory :resource', array(':resource' => $path));
             }
         }
         $directories = explode(DIRECTORY_SEPARATOR, $directory);
         foreach ($directories as $directory) {
             if (!is_writable($path)) {
                 throw new Kohana_Exception('Unable to write to the cache directory :resource', array(':resource' => $path));
             }
             $path = $path . DIRECTORY_SEPARATOR . $directory;
             if (!is_dir($path)) {
                 mkdir($path, 0777);
             }
         }
         list($width_orig, $height_orig) = getimagesize($original_image);
         if ($width_orig > $width or $height_orig > $height) {
             $iamge = Image::factory($original_image)->resize($width, $height, $master);
             if ($crop === TRUE) {
                 $iamge->crop($width, $height);
             }
             $iamge->save(PUBLICPATH . $cached_image);
         } else {
             copy($original_image, PUBLICPATH . $cached_image);
         }
     }
     return PUBLIC_URL . $cached_image;
 }