Example #1
0
 /**
  * Create Exif class
  *
  * @param string $file 
  * @author Thibaud Rohmer
  */
 public function __construct($file = null)
 {
     /// No file given
     if (!isset($file)) {
         return;
     }
     /// File isn't an image
     if (is_array($file) || !File::Type($file) || File::Type($file) != "Image") {
         return;
     }
     /// No right to view
     if (!Judge::view($file)) {
         return;
     }
     /// No exif extension installed
     if (!in_array("exif", get_loaded_extensions())) {
         $infos[''] = "Exif extension is not installed on the server";
         return;
     }
     /// Create wanted table
     $this->init_wanted();
     /// Read exif
     $raw_exif = @exif_read_data($file);
     /// Parse exif
     foreach ($this->wanted as $name => $data) {
         foreach ($data as $d) {
             if (isset($raw_exif[$d])) {
                 $this->exif[$name] = $this->parse_exif($d, $raw_exif);
             }
         }
     }
     $this->filename = basename($file);
 }
Example #2
0
 /**
  * Create Video
  *
  * @param string $file 
  * @author Cédric Levasseur
  */
 public function __construct($file = NULL, $forcebig = false)
 {
     if (!Judge::view($file)) {
         return;
     }
     /// Check file type
     if (!isset($file) || !File::Type($file) || File::Type($file) != "Video") {
         return;
     }
     /// File object
     $this->file = $file;
     /// Set relative path (url encoded)
     $this->fileweb = urlencode(File::a2r($file));
 }
Example #3
0
 /**
  * Create Menu
  *
  * @param string $dir 
  * @param int $level
  * @author Thibaud Rohmer
  */
 public function __construct($dir = null, $level = 0)
 {
     /// Init Menu
     if ($dir == null) {
         $dir = Settings::$photos_dir;
     }
     /// Check rights
     if (!Judge::view($dir) || Judge::searchDir($dir) == NULL) {
         return;
     }
     if (!CurrentUser::$admin && !CurrentUser::$uploader && sizeof($this->list_files($dir, true, false, true)) == 0) {
         return;
     }
     /// Set variables
     $this->title = end(explode('/', $dir));
     $this->webdir = urlencode(File::a2r($dir));
     $this->path = File::a2r($dir);
     try {
         /// Check if selected dir is in $dir
         File::a2r(CurrentUser::$path, $dir);
         $this->selected = true;
         $this->class = "level-{$level} selected";
     } catch (Exception $e) {
         /// Selected dir not in $dir, or nothing is selected
         $this->selected = false;
         $this->class = "level-{$level}";
     }
     /// Create Menu for each directory
     $subdirs = $this->list_dirs($dir);
     if (Settings::$reverse_menu) {
         $subdirs = array_reverse($subdirs);
     }
     foreach ($subdirs as $d) {
         $this->items[] = new Menu($d, $level + 1);
     }
 }
Example #4
0
 public static function Zip($dir)
 {
     /// Check that user is allowed to acces this content
     if (!Judge::view($dir)) {
         return;
     }
     /// Prepare file
     $tmpfile = tempnam("tmp", "zip");
     $zip = new ZipArchive();
     $zip->open($tmpfile, ZipArchive::OVERWRITE);
     /// Staff with content
     $items = Menu::list_files($dir, true);
     foreach ($items as $item) {
         if (Judge::view($item)) {
             $zip->addFile($item, basename(dirname($item)) . "/" . basename($item));
         }
     }
     // Close and send to user
     $fname = basename($dir);
     $zip->close();
     header('Content-Type: application/zip');
     header('Content-Length: ' . filesize($tmpfile));
     header("Content-Disposition: attachment; filename=\"" . htmlentities($fname, ENT_QUOTES, 'UTF-8') . ".zip\"");
     readfile($tmpfile);
     unlink($tmpfile);
 }
Example #5
0
 /**
  * Generates a zip.
  *
  * @param string $dir  
  * @return void
  * @author Thibaud Rohmer
  */
 public static function Zip($dir)
 {
     /// Check that user is allowed to acces this content
     if (!Judge::view($dir)) {
         return;
     }
     // Get the relative path of the files
     $delimPosition = strrpos($dir, '/');
     if (strlen($dir) == $delimPosition) {
         echo "Error: Directory has a slash at the end";
         return;
     }
     // Create list with all filenames
     $items = Menu::list_files($dir, true);
     $itemsString = '';
     foreach ($items as $item) {
         if (Judge::view($item)) {
             // Use only the relative path of the filename
             $item = str_replace('//', '/', $item);
             $itemsString .= " '" . substr($item, $delimPosition + 1) . "'";
         }
     }
     // Close and send to user
     header('Content-Type: application/zip');
     header("Content-Disposition: attachment; filename=\"" . htmlentities(basename($dir), ENT_QUOTES, 'UTF-8') . ".zip\"");
     // Store the current working directory and change to the albums directory
     $cwd = getcwd();
     chdir(substr($dir, 0, $delimPosition));
     // ZIP-on-the-fly method copied from http://stackoverflow.com/questions/4357073
     //
     // use popen to execute a unix command pipeline
     // and grab the stdout as a php stream
     $fp = popen('zip -n .jpg:.JPG:.jpeg:.JPEG -0 - ' . $itemsString, 'r');
     // pick a bufsize that makes you happy (8192 has been suggested).
     $bufsize = 8192;
     $buff = '';
     while (!feof($fp)) {
         $buff = fread($fp, $bufsize);
         echo $buff;
         /// flush();
     }
     pclose($fp);
     // Chang to the previous working directory
     chdir($cwd);
 }
Example #6
0
 /**
  * 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;
 }
Example #7
0
 /**
  * Generate a foldergrid
  *
  * @return void
  * @author Thibaud Rohmer
  */
 private function foldergrid()
 {
     foreach ($this->dirs as $d) {
         $firstImg = Judge::searchDir($d);
         if (!(Judge::view($d) || $firstImg)) {
             continue;
         }
         $f = Menu::list_files($d, true);
         if (CurrentUser::$admin || CurrentUser::$uploader || sizeof($f) > 0) {
             if ($firstImg) {
                 $f[0] = $firstImg;
             }
             $item = new BoardDir($d, $f);
             $this->boardfolders[] = $item;
         }
     }
 }
Example #8
0
 /**
  * Check recursively if a file is viewable in a folder, and returns path to that file.
  */
 public static function searchDir($dir, $public_search = false)
 {
     foreach (Menu::list_files($dir) as $f) {
         if (Judge::view($f)) {
             return $f;
         }
     }
     foreach (Menu::list_dirs($dir) as $d) {
         if (($f = Judge::searchDir($d, $public_search)) != NULL) {
             return $f;
         }
     }
     return NULL;
 }
Example #9
0
 public static function Video($file, $width = '100%', $height = '100%', $control = false)
 {
     if (!Judge::view($file)) {
         return;
     }
     if (function_exists("error_reporting")) {
         error_reporting(0);
     }
     /// Check item
     if (!File::Type($file) || File::Type($file) != "Video") {
         return;
     }
     $basefile = new File($file);
     $basepath = File::a2r($file);
     $path_webm = Settings::$thumbs_dir . dirname($basepath) . "/" . $basefile->name . '.webm';
     $c = null;
     Video::FastEncodeVideo($file);
     $wh = ' height="' . $height . '" width="' . $width . '"';
     if ($control) {
         $c = ' controls="controls"';
     }
     echo '<video' . $wh . $c . '><source src="' . $path_webm . '" type="video/webm" /></video>';
     //echo 'Webm Video Codec not found.Plaese up to date the brower or Download the codec <a href="http://tools.google.com/dlpage/webmmf">Download</a>';
 }
Example #10
0
 /**
  * Generate a foldergrid
  *
  * @return void
  * @author Thibaud Rohmer
  */
 private function foldergrid()
 {
     foreach ($this->dirs as $d) {
         if (!Judge::view($d)) {
             //Dir is not accessible (rights) - ignore it for better performance
             continue;
         }
         $firstImg = Judge::searchDir($d);
         if (!$firstImg) {
             if (CurrentUser::$admin) {
                 $firstImg = NULL;
             } else {
                 continue;
             }
         }
         $item = new BoardDir($d, $firstImg);
         $this->boardfolders[] = $item;
     }
     if (Settings::$reverse_menu) {
         $this->boardfolders = array_reverse($this->boardfolders);
     }
 }
Example #11
0
 /**
  * Return image(s) $img
  */
 public static function get_img($key, $img, $t = 'large')
 {
     if (is_array($img)) {
         $res = array();
         foreach ($img as $i) {
             $p = get_img($key, $i, $t);
             if (isset($p)) {
                 $res[] = $p;
             }
         }
         return $res;
     } else {
         $i = File::r2a($img);
         if (Judge::view($i)) {
             switch ($t) {
                 case "thumb":
                     return file_get_contents(Provider::thumb($i));
                 case "small":
                     return file_get_contents(Provider::small($i));
                 case "large":
                 default:
                     return file_get_contents($i);
             }
         }
     }
 }
Example #12
0
 /**
  * Display BoardItem on Website
  *
  * @return void
  * @author Thibaud Rohmer
  */
 public function toHTML()
 {
     if (sizeof($this->images) > 0) {
         $getfile = "t=Thb&f=" . urlencode(File::a2r($this->images[0]));
     } else {
         $getfile = "";
     }
     /// We display the image as a background
     echo "<div class='directory'>";
     echo "<span class='name hidden'>" . htmlentities(basename($this->path), ENT_QUOTES, 'UTF-8') . "</span>";
     echo "<span class='path hidden'>" . htmlentities(File::a2r($this->path), ENT_QUOTES, 'UTF-8') . "</span>";
     echo "<div class='dir_img'";
     echo " style='";
     echo " background: \t\turl(\"?{$getfile}\") no-repeat center center;";
     echo " -webkit-background-size: cover;";
     echo " -moz-background-size: cover;";
     echo " -o-background-size: cover;";
     echo " background-size: \tcover;";
     echo "'>\n";
     echo "<span class='img_bg hidden'></span>";
     /// Images in the directory
     if (sizeof($this->images) > Settings::$max_img_dir) {
         for ($i = 0; $i < Settings::$max_img_dir; $i++) {
             $pos = floor(sizeof($this->images) * $i / Settings::$max_img_dir);
             if (Judge::view($this->images[$pos])) {
                 echo "<div class='alt_dir_img hidden'>" . urlencode(File::a2r($this->images[$pos])) . "</div>";
             }
         }
     } else {
         foreach ($this->images as $img) {
             if (Judge::view($img)) {
                 echo "<div class='alt_dir_img hidden'>" . urlencode(File::a2r($img)) . "</div>";
             }
         }
     }
     echo "<a href='?f={$this->url}'>";
     echo "<img src='./inc/img.png' width='100%' height='100%'>";
     echo "</a>\n";
     echo "</div>\n";
     echo "<div class='dirname'>";
     echo htmlentities(basename($this->path), ENT_QUOTES, 'UTF-8');
     echo "</div>\n";
     echo "</div>\n";
 }