/** * 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; } if (!Judge::view($d)) { //Dir is not accessible (rights) - ignore it for better performance continue; } $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++; } } } $this->foldergrid(); }
public function Calculate() { /// Calculate number of users, etc... $this->stats['Users'] = sizeof(Account::findAll()); $this->stats['Groups'] = sizeof(Group::findAll()); $this->stats['Items'] = sizeof(Menu::list_files(Settings::$photos_dir, true)); $this->stats['Generated items'] = sizeof(Menu::list_files(Settings::$thumbs_dir, true)); $this->stats['Albums'] = sizeof(Menu::list_dirs(Settings::$photos_dir, true)); $this->accounts = array_reverse(Account::findAll()); $commentsfile = Settings::$conf_dir . "/comments.xml"; if (is_file($commentsfile)) { $xml = simplexml_load_file($commentsfile); $this->comments = $xml->children(); } }
/** * Create upload page * * @author Thibaud Rohmer */ public function __construct() { /// Get all subdirs $list_dirs = Menu::list_dirs(Settings::$photos_dir, true); /// Get all subfiles $list_files = Menu::list_files(Settings::$photos_dir, true); foreach ($list_dirs as $dir) { $d = File::a2r($dir); $this->dirs[] = $d; $this->files[] = $d; } foreach ($list_files as $file) { $this->files[] = File::a2r($file); } if (isset(CurrentUser::$path)) { $this->selected = File::a2r(CurrentUser::$path); } }
public function infodirtoHTML($dir) { $w = File::a2r($dir); $ret = ""; /// Folder name if (strlen($w) > 1) { $ret .= "<form class='rename'>\n\t\t\t\t<fieldset class='" . addslashes(htmlentities(File::a2r(dirname($dir)), ENT_QUOTES, 'UTF-8')) . "'>\n\t\t\t\t\t<input id='foldername' class='" . addslashes(htmlentities($w, ENT_QUOTES, 'UTF-8')) . "' type='text' value='" . addslashes(htmlentities(basename($w), ENT_QUOTES, 'UTF-8')) . "'>\n\t\t\t\t\t<input type='submit' value='Rename'>\n\t\t\t\t</fieldset>\n\t\t\t\t</form>"; } $ret .= "<form class='create'>\n\t\t\t\t<fieldset>\n\t\t\t\t\t<input type='hidden' name='path' value='" . addslashes(htmlentities($w, ENT_QUOTES, 'UTF-8')) . "'>\n\t\t\t\t\t<input id='foldername' name='newdir' type='text' value='New Folder'>\n\t\t\t\t\t<input type='submit' value='Create'>\n\t\t\t\t</fieldset>\n\t\t\t\t</form>"; /// Upload Images form $ret .= "<form class='dropzone' id='" . addslashes(htmlentities($w, ENT_QUOTES, 'UTF-8')) . "/' \n\t\t\taction='?t=Adm&a=Upl&j=Pan' method='POST' enctype='multipart/form-data'>\n\t\t\t<input type='hidden' name='path' value='" . addslashes(htmlentities($w, ENT_QUOTES, 'UTF-8')) . "'>\n\t\t\t<input type='file' name='images[]' multiple >\n\t\t\t<button>Upload</button>\n\t\t\t<div>Upload Images Here</div>\n\t\t\t</form>"; /// List images $ret .= "<table id='files'></table>"; $ret .= "<div class='images'>"; foreach (Menu::list_files($dir) as $img) { $ret .= "<div class='thmb'><img src='?t=Thb&f=" . urlencode(File::a2r($img)) . "'><span class='" . addslashes(htmlentities(File::a2r($img), ENT_QUOTES, 'UTF-8')) . "'>" . htmlentities(basename($img), ENT_QUOTES, 'UTF-8') . "</span></div>"; } $ret .= "</div>"; return $ret; }
/** * List files in $dir, omit hidden files * * @param string $dir * @return void * @author Thibaud Rohmer */ public static function list_files($dir, $rec = false, $hidden = false, $stopatfirst = false) { /// Directories list $list = array(); /// Check that $dir is a directory, or throw exception if (!is_dir($dir)) { throw new Exception("'" . $dir . "' is not a directory"); } /// Directory content $dir_content = scandir($dir); if (empty($dir_content)) { // Directory is empty or no right to read return $list; } /// Check each content foreach ($dir_content as $content) { /// Content isn't hidden and is a file if ($content[0] != '.' || $hidden) { if (is_file($path = $dir . "/" . $content)) { if (File::Type($path) && (File::Type($path) == "Image" || File::Type($path) == "Video")) { /// Add content to list $list[] = $path; /// We found the first one if ($stopatfirst) { return $list; } } } else { if ($rec) { $list = array_merge($list, Menu::list_files($dir . "/" . $content, true)); } } } } /// Return files list return $list; }
/** * 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); }
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); }
/** * 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; } } }
/** * 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; }
/** * 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; }
/** * Reccursively delete all files in $dir * * @param string $dir * @author Thibaud Rohmer */ public function rec_del($dir) { if (is_file($dir)) { return unlink($dir); } $dirs = Menu::list_dirs($dir); $files = Menu::list_files($dir, false, true); foreach ($dirs as $d) { AdminDelete::rec_del($d); } foreach ($files as $f) { unlink($f); } return rmdir($dir); }
/** * Reccursively delete all files in $dir * * @param string $dir * @author Thibaud Rohmer */ public function rec_del($dir) { if ($dir == Settings::$photos_dir) { return; } if (is_file($dir)) { return unlink($dir); } $dirs = Menu::list_dirs($dir); $files = Menu::list_files($dir, false, true); foreach ($dirs as $d) { Admin::rec_del($d); } foreach ($files as $f) { unlink($f); } return rmdir($dir); }
/** * Returns absolute path to previous item * * @param string $path * @return $prev * @author Thibaud Rohmer */ public static function prev($path) { $files = Menu::list_files(dirname($path)); $pos = array_search($path, $files); if (isset($pos) && $pos > 0) { /// Found $path return $files[$pos - 1]; } return $path; }
/** * Generate thumbs and webimages reccursively inside a folder * * @return void * @author Thibaud Rohmer */ public static function gener_all($folder) { $files = Menu::list_files($folder, true); if (!ini_get('safe_mode')) { set_time_limit(1200); } foreach ($files as $file) { /// Generate thumb Provider::image($file, true, false, false); /// Generate webimg Provider::image($file, false, false, false); } }
/** * List files contained in $dir */ public static function list_files($key, $dir) { CurrentUser::keyin($key); $res = array(); $m = Menu::list_files(File::r2a($dir)); if (sizeof($m) == 0) { return $res; } foreach ($m as $i) { if (Judge::view($i)) { $res[] = File::a2r($i); } } return $res; }