Beispiel #1
0
 public function clear_thumbnails()
 {
     $stack = $this->stack ? $this->stack : $this->resultset->get_stack();
     $file_path = get_file_directory(str_replace('>', '/', $stack));
     if (!isset($this->thumbnails)) {
         $this->thumbnails = array();
     } else {
         if (is_string($this->thumbnails)) {
             $this->thumbnails = array_filter(explode(';', $this->thumbnails));
         }
     }
     $extension = strtolower(substr($this->filename, strrpos($this->filename, '.') + 1));
     foreach ($this->thumbnails as $thumbnail) {
         if (preg_match('/([a-z]+)([0-9]+)x([0-9]+)(c?)/is', $thumbnail, $match)) {
             $target = $file_path . $this->id . '-' . $match[2] . 'x' . $match[3];
             $slugfield = 'slug_' . $match[1];
             $slug = isset($this->{$slugfield}) ? $this->{$slugfield} : $this->slug;
             $file = $file_path . $slug . '-' . $this->id . '-' . $match[2] . '-' . $match[3];
             if ($match[4] == 'c') {
                 $file .= '-c';
                 $target .= '-c';
             }
             $file .= '.' . $extension;
             $target .= '.' . $extension;
             @unlink($file);
             @unlink($target);
         }
     }
     if (!$this->path) {
         $this->path = $stack;
     }
     if ($this->path && $this->id && $this->thumbnails_field) {
         where('id = %d', $this->id)->update($this->path, array($this->thumbnails_field => ''));
         $this->thumbnails = array();
     }
 }
Beispiel #2
0
function get_file_url($directory)
{
    get_file_directory($directory);
    return url('files/' . $directory, false);
}