Example #1
0
// Load fileroot info:
$FileRootCache =& get_FileRootCache();
$FileRoot =& $FileRootCache->get_by_ID($root);
// Load file object (not the file content):
$File = new File($FileRoot->type, $FileRoot->in_type_ID, $path);
// Check if the request has an If-Modified-Since date
if (array_key_exists('HTTP_IF_MODIFIED_SINCE', $_SERVER)) {
    $if_modified_since = strtotime(preg_replace('/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE']));
    $file_lastmode_ts = $File->get_lastmod_ts();
    if ($file_lastmode_ts <= $if_modified_since) {
        // file was not modified since if_modified_since ts
        header_http_response('304 Not Modified');
        exit(0);
    }
}
if (!empty($size) && $File->is_image()) {
    // We want a thumbnail:
    // fp> TODO: for more efficient caching, this should probably redirect to the static file right after creating it (when $public_access_to_media=true OF COURSE)
    global $thumbnail_sizes;
    load_funcs('/files/model/_image.funcs.php');
    $size_name = $size;
    if (!isset($thumbnail_sizes[$size])) {
        // this file size alias is not defined, use default:
        // TODO: dh> this causes links for e.g. "fit-50x50" to work also, but with the drawback of images not getting served from the
        //           .evocache directory directly. I think invalid $size params should bark out here.
        // fp> ok.
        $size_name = 'fit-80x80';
    }
    if (!isset($thumbnail_sizes[$size_name][4])) {
        // Set blur percent in 0 by default
        $thumbnail_sizes[$size_name][4] = 0;
Example #2
0
 protected function write_thumbs($id)
 {
     $original = $this->{$this->path_column} . $this->{$this->file_column};
     if (!$this->create_thumbs || !File::is_image($original)) {
         return false;
     }
     $thumb_dir = PUBLIC_DIR . $this->thumb_base . $id . "/";
     if (!is_dir($thumb_dir)) {
         mkdir($thumb_dir, 0777);
     }
     foreach ($this->create_thumbs as $thumb => $size) {
         if (!is_dir($thumb_dir . $thumb)) {
             mkdir($thumb_dir . $thumb, 0777);
         }
         $destination = $thumb_dir . $thumb . "/" . $this->{$this->file_column};
         if (File::is_image($original)) {
             File::resize_image($original, $destination, $size);
         }
     }
     return true;
 }
Example #3
0
 /**
  * show function - this is now moved from the contoller level so can differ for each model
  * NOTE: this function exits
  * @param string $size 
  */
 public function show($size = 110, $compress = false)
 {
     $source = PUBLIC_DIR . $this->rpath . "/" . $this->filename;
     $extension = File::get_extension($this->filename);
     $file = CACHE_DIR . $this->id . "_" . $size . "." . $extension;
     //slash any spaces
     $source = preg_replace("/[\\s]/", "\\ ", $source);
     if (!is_readable($source)) {
         error_log("FATAL IMAGE ERROR");
     }
     if (!File::is_image($source)) {
         if (!is_file($file) || !is_readable($file)) {
             $icon_type = $extension;
             $icon = PLUGIN_DIR . "cms/resources/public/images/cms/" . "cms-generic-icon-" . strtolower($icon_type) . ".gif";
             if (!is_readable($icon) || $icon_file != file_get_contents($icon)) {
                 $icon_file = PLUGIN_DIR . "cms/resources/public/images/cms/" . "cms-generic-icon.png";
                 $source = CACHE_DIR . "cms-generic-icon.gif";
             } else {
                 $source = CACHE_DIR . "cms-generic-icon-{$icon_type}.gif";
             }
             file_put_contents($source, $icon_file);
         }
     }
     if (!is_file($file) || !is_readable($file)) {
         File::resize_image($source, $file, $size, $compression);
     }
     if ($this->image = File::display_image($file)) {
         return true;
     }
     return false;
 }