protected function makeThumb($file, $overwrite = true)
 {
     $img = image::factory($this->imageDriver, $file);
     // Drop files which are not images
     if ($img->initError) {
         return true;
     }
     $fimg = new fastImage($file);
     $type = $fimg->getType();
     $fimg->close();
     if ($type === false) {
         return true;
     }
     $thumb = substr($file, strlen($this->config['uploadDir']));
     $thumb = $this->config['uploadDir'] . "/" . $this->config['thumbsDir'] . "/" . $thumb;
     $thumb = path::normalize($thumb);
     $thumbDir = dirname($thumb);
     if (!is_dir($thumbDir) && !@mkdir($thumbDir, $this->config['dirPerms'], true)) {
         return false;
     }
     if (!$overwrite && is_file($thumb)) {
         return true;
     }
     // Images with smaller resolutions than thumbnails
     if ($img->width <= $this->config['thumbWidth'] && $img->height <= $this->config['thumbHeight']) {
         // Drop only browsable types
         if (in_array($type, array("gif", "jpeg", "png"))) {
             return true;
         }
         // Resize image
     } elseif (!$img->resizeFit($this->config['thumbWidth'], $this->config['thumbHeight'])) {
         return false;
     }
     // Save thumbnail
     $options = array('file' => $thumb);
     if ($type == "gif") {
         $type = "jpeg";
     }
     if ($type == "jpeg") {
         $options['quality'] = $this->config['jpegQuality'];
     }
     return $img->output($type, $options);
 }
 protected function act_thumb()
 {
     if (!isset($_GET['file']) || !isset($_GET['dir']) || !$this->checkFilename($_GET['file'])) {
         $this->sendDefaultThumb();
     }
     $dir = $this->getDir();
     $file = "{$this->thumbsTypeDir}/{$_GET['dir']}/{$_GET['file']}";
     // Create thumbnail
     if (!is_file($file) || !is_readable($file)) {
         $file = "{$dir}/{$_GET['file']}";
         if (!is_file($file) || !is_readable($file)) {
             $this->sendDefaultThumb($file);
         }
         $image = image::factory($this->imageDriver, $file);
         if ($image->initError) {
             $this->sendDefaultThumb($file);
         }
         $img = new fastImage($file);
         $type = $img->getType();
         $img->close();
         if (in_array($type, array("gif", "jpeg", "png")) && $image->width <= $this->config['thumbWidth'] && $image->height <= $this->config['thumbHeight']) {
             $mime = "image/{$type}";
             httpCache::file($file, $mime);
         } else {
             $this->sendDefaultThumb($file);
         }
         // Get type from already-existing thumbnail
     } else {
         $img = new fastImage($file);
         $type = $img->getType();
         $img->close();
     }
     httpCache::file($file, "image/{$type}");
 }
Exemple #3
0
 protected function getFiles($dir)
 {
     $thumbDir = "{$this->config['uploadDir']}/{$this->config['thumbsDir']}/{$dir}";
     $dir = "{$this->config['uploadDir']}/{$dir}";
     $return = array();
     $files = dir::content($dir, array('types' => "file"));
     if ($files === false) {
         return $return;
     }
     foreach ($files as $file) {
         $img = new fastImage($file);
         $type = $img->getType();
         if ($type !== false) {
             $size = $img->getSize($file);
             if (is_array($size) && count($size)) {
                 $thumb_file = "{$thumbDir}/" . basename($file);
                 if (!is_file($thumb_file)) {
                     $this->makeThumb($file, false);
                 }
                 $smallThumb = $size[0] <= $this->config['thumbWidth'] && $size[1] <= $this->config['thumbHeight'] && in_array($type, array("gif", "jpeg", "png"));
             } else {
                 $smallThumb = false;
             }
         } else {
             $smallThumb = false;
         }
         $img->close();
         $stat = stat($file);
         if ($stat === false) {
             continue;
         }
         $name = basename($file);
         $ext = file::getExtension($file);
         $types = $this->config['types'];
         $types = explode(' ', $types['images'] . ' ' . $types['image']);
         if (substr($name, 0, 1) == '.' && !$this->config['showHiddenFiles']) {
             continue;
         }
         if ($this->type == 'images' && !in_array(strtolower($ext), $types)) {
             continue;
         }
         $bigIcon = file_exists("themes/{$this->config['theme']}/img/files/big/{$ext}.png");
         $smallIcon = file_exists("themes/{$this->config['theme']}/img/files/small/{$ext}.png");
         $thumb = file_exists("{$thumbDir}/{$name}");
         $return[] = array('name' => stripcslashes($name), 'size' => $stat['size'], 'mtime' => $stat['mtime'], 'date' => @strftime($this->dateTimeSmall, $stat['mtime']), 'readable' => is_readable($file), 'writable' => file::isWritable($file), 'bigIcon' => $bigIcon, 'smallIcon' => $smallIcon, 'thumb' => $thumb, 'smallThumb' => $smallThumb);
     }
     return $return;
 }
Exemple #4
0
 protected function getFiles($dir)
 {
     $thumbDir = "{$this->config['uploadDir']}/{$this->config['thumbsDir']}/{$dir}";
     $dir = "{$this->config['uploadDir']}/{$dir}";
     $return = array();
     $files = dir::content($dir, array('types' => "file", 'not_pattern' => "/.*(?:-\\d{1,}x\\d{1,})\\..*/"));
     if ($files === false) {
         return $return;
     }
     foreach ($files as $file) {
         $img = new fastImage($file);
         $type = $img->getType();
         if ($type !== false) {
             $size = $img->getSize($file);
             if (is_array($size) && count($size)) {
                 $thumb_file = "{$thumbDir}/" . basename($file);
                 if (!is_file($thumb_file)) {
                     $this->makeThumb($file, false);
                 }
                 $smallThumb = $size[0] <= $this->config['thumbWidth'] && $size[1] <= $this->config['thumbHeight'] && in_array($size[2], array(IMAGETYPE_GIF, IMAGETYPE_PNG, IMAGETYPE_JPEG));
             } else {
                 $smallThumb = false;
             }
         } else {
             $smallThumb = false;
         }
         $img->close();
         $stat = stat($file);
         if ($stat === false) {
             continue;
         }
         $name = basename($file);
         $ext = file::getExtension($file);
         $bigIcon = file_exists("themes/{$this->config['theme']}/img/files/big/{$ext}.png");
         $smallIcon = file_exists("themes/{$this->config['theme']}/img/files/small/{$ext}.png");
         $thumb = file_exists("{$thumbDir}/{$name}");
         $return[] = array('name' => stripcslashes($name), 'size' => $stat['size'], 'mtime' => $stat['mtime'], 'date' => @strftime($this->dateTimeSmall, $stat['mtime']), 'readable' => is_readable($file), 'writable' => file::isWritable($file), 'bigIcon' => $bigIcon, 'smallIcon' => $smallIcon, 'thumb' => $thumb, 'smallThumb' => $smallThumb);
     }
     return $return;
 }