예제 #1
0
 public function itShouldUnzipAllFiles()
 {
     $tmp_dir = dirname(__FILE__) . "/tmp";
     Ra_DirectoryHelper::mkdir($tmp_dir);
     $zip = new Ra_Zip($this->zip_path);
     $zip->extract_all($tmp_dir);
     foreach ($this->expected_data as $item) {
         $this->spec(file_exists($tmp_dir . '/' . $item))->should->beTrue();
     }
     Ra_DirectoryHelper::rmdir($tmp_dir);
 }
예제 #2
0
 public static function cache($route, $data)
 {
     $file = self::normalize_path($route) . '.html';
     Ra_DirectoryHelper::mkdir($file, true);
     file_put_contents($file, $data);
 }
예제 #3
0
 public function image_cache($model, $field, $id = null, $configuration = array(), $user_vars = array())
 {
     $configuration = array_merge(array('width' => 100, 'height' => 100, 'mode' => 1, 'format' => 'jpg', 'path_format' => '#cache/#model/#field/#id.#width.#height.#mode.#format', 'default' => ''), $configuration);
     $vars = array_merge(array('cache' => RA_CACHE_PATH, 'model' => $model, 'field' => $field, 'id' => $id, 'width' => $configuration['width'], 'height' => $configuration['height'], 'mode' => $configuration['mode'], 'format' => $configuration['format']), $user_vars);
     $path = Ra_StringHelper::simple_template($configuration['path_format'], $vars);
     $object = is_a($model, 'ActiveRecord') ? $model : ActiveRecord::model($model)->find($id);
     if ($object->{$field}) {
         if (file_exists($path) && file_exists($object->{$field}) && filemtime($object->{$field}) > filemtime($path)) {
             unlink($path);
         }
         if (!file_exists($path)) {
             if ($object->{$field}) {
                 Ra_DirectoryHelper::mkdir($path, true);
                 $image = new Ra_Image($object->{$field});
                 $image->resize($configuration['width'], $configuration['height'], $configuration['mode']);
                 $image->save($path);
             }
         }
     } else {
         $this->redirect_to('public/' . $configuration['default']);
     }
     return file_get_contents($path);
 }