/** * Board constructor * * @param string $path * @author Thibaud Rohmer */ public function __construct($path = NULL) { if (!isset($path)) { $path = CurrentUser::$path; } $this->analyzed = array(); $this->path = $path; // If $path is a file, list directory containing the file if (is_file($path)) { $this->path = dirname($path); } $this->title = basename($this->path); $this->header = new BoardHeader($this->title, $this->path); $this->files = Menu::list_files($this->path); $this->dirs = Menu::list_dirs($this->path); $pageURL = Settings::$site_address . "/?f=" . urlencode(File::a2r($this->path)); // generate the header - opengraph metatags for facebook $this->page_header = "<meta property=\"og:url\" content=\"" . $pageURL . "\"/>\n" . "<meta property=\"og:site_name\" content=\"" . Settings::$name . "\"/>\n" . "<meta property=\"og:type\" content=\"article\"/>\n" . "<meta property=\"og:title\" content=\"" . Settings::$name . ": " . File::a2r($this->path) . "\"/>\n"; if (Settings::$fbappid) { $this->page_header .= "<meta property=\"fb:app_id\" content=\"" . Settings::$fbappid . "\"/>\n"; } if (!empty($this->files)) { $i = 0; foreach ($this->files as $file) { if ($i > 9) { break; } if (Judge::is_public($file)) { $this->page_header .= "<meta property=\"og:image\" content=\"" . Settings::$site_address . "/?t=Thb&f=" . urlencode(File::a2r($file)) . "\"/>\n"; $i++; } } } else { // No files in the directory, getting thumbnails from sub-directories $i = 0; foreach ($this->dirs as $d) { if ($i > 9) { break; } $img = Judge::searchDir($d, true); if ($img) { $this->page_header .= "<meta property=\"og:image\" content=\"" . Settings::$site_address . "/?t=Thb&f=" . urlencode(File::a2r($img)) . "\"/>\n"; $i++; } } } // Generate the grid $this->grid(); $this->foldergrid(); }
public static function thumb($file) { require_once dirname(__FILE__) . '/../phpthumb/phpthumb.class.php'; $path = File::r2a(File::a2r($file), Settings::$thumbs_dir); // We check that the thumb already exists, was created after the image, at the right size $goodThumb = false; if (file_exists($path) && filectime($file) < filectime($path)) { $dim = getimagesize($path); $goodThumb = $dim[0] == Settings::$thumbs_size && $dim[1] == Settings::$thumbs_size; } /// If we need to create a thumb, then this is a new picture if (!$goodThumb) { if (Judge::is_public($file)) { $r = new RSS(Settings::$conf_dir . "/photos_feed.txt"); $webpath = Settings::$site_address . "?f=" . urlencode(File::a2r($file)); $r->add(basename($file), $webpath, "<img src='{$webpath}&t=Thb' />"); } /// Create directories if (!file_exists(dirname($path))) { @mkdir(dirname($path), 0750, true); } /// Create thumbnail $thumb = new phpthumb(); if (!empty(Settings::$imagemagick_path)) { $thumb->config_imagemagick_path = Settings::$imagemagick_path; } $thumb->setSourceData(file_get_contents($file)); $thumb->CalculateThumbnailDimensions(); $thumb->w = Settings::$thumbs_size; $thumb->h = Settings::$thumbs_size; $thumb->zc = Settings::$thumbs_size; $thumb->q = Settings::$quality_mini; if (File::Type($file) == 'Image' && Provider::get_orientation_degrees($file) != 0) { $thumb->SourceImageToGD(); //$thumb->ra = Provider::get_orientation_degrees($file); $thumb->Rotate(); } $thumb->GenerateThumbnail(); $thumb->RenderToFile($path); chmod($path, 0775); } /* Implementation of webp... for later. $webp = $path.".webp"; if(!file_exists($webp) || filectime($webp) < filectime($path) ){ imagewebp(imagecreatefromjpeg($path),$webp); } */ return $path; }
/** * Check if a file is viewable in a folder, and returns path to that file. */ public static function searchDir($dir, $public_search = false) { $rightsdir = File::r2a(File::a2r($dir), Settings::$thumbs_dir); $rightsfiles = glob($rightsdir . "/.*ights.xml"); // Check files foreach ($rightsfiles as $rf) { $f = Judge::associated_file($rf); if ($public_search and Judge::is_public($f) or !$public_search and Judge::view($f)) { if (is_file($f)) { return $f; } else { foreach (Menu::list_files($f, true) as $p) { if ($public_search and Judge::is_public($p) or !$public_search and Judge::view($p)) { return $p; } } } } } // Check subdirs foreach (Menu::list_dirs($dir) as $d) { if ($f = Judge::searchDir($d, $public_search)) { return $f; } } return false; }