5 if (is_dir("plugins")) {
6 $plugins = scandir("plugins");
7 array_shift($plugins); array_shift($plugins); // remove . and ..
8 foreach ($plugins as $p) if (is_file("plugins/$p/functions.php"))
9 require "plugins/$p/functions.php";
12 function plugins_include($phpFile)
14 foreach ($GLOBALS['plugins'] as $p) if (is_file("plugins/$p/$phpFile"))
15 require "plugins/$p/$phpFile";
18 function getPathInfo()
20 $simplePath = $_SERVER["PATH_INFO"];
21 if ($simplePath == '/') $simplePath = '';
22 // extra security check to avoid /photos/index/../.. like urls, maybe useless but..
23 if (strpos($simplePath, '..') !== false) die(".. found in url");
28 if (! function_exists('getImageLink')) {
29 function getImageLink($imageSimplePath)
31 return $GLOBALS['rootUrl'].IMAGES_DIR.$imageSimplePath;
35 if (! function_exists('getPreview')) {
36 function getPreview($imgFile, $maxSize = THUMB_SIZE)
38 # example: data/myalbum/100.mypic.jpg
39 $newImgFile = DATA_DIR."/".dirname($imgFile)."/".$maxSize.".".basename($imgFile);
41 # if the preview is a symlink, image is already good sized
42 if (is_link($newImgFile)) return $imgFile;
44 if (! is_file($newImgFile))
46 # this tels the template to flush output after displaying previews
47 $GLOBALS["generating"] = true;
49 # reset script time limit to 20s (wont work in safe mode)
52 $ext = strtolower(substr($imgFile, -4));
54 $img = imagecreatefromjpeg($imgFile);
56 $img = imagecreatefrompng($imgFile);
60 # if the image is already small, make a symlink, and return it
61 if ($w <= $maxSize and $h <= $maxSize) {
63 symlink($imgFile, $newImgFile);
67 # config to allow group writable files
69 # create the thumbs directory recursively
70 if (! is_dir(dirname($newImgFile))) @mkdir(dirname($newImgFile), 0777, true)
71 or die("Could not write in data dir. Please fix permissions.");
75 $newH = $h/($w/$maxSize);
77 $newW = $w/($h/$maxSize);
81 $newImg = imagecreatetruecolor($newW, $newH);
83 imagecopyresampled($newImg, $img, 0, 0, 0, 0, $newW, $newH, $w, $h);
86 imagejpeg($newImg, $newImgFile);
88 imagepng($newImg, $newImgFile);
91 imagedestroy($newImg);
98 function getAlbumPreview($dir)
100 $previewFile = DATA_DIR."/$dir/albumpreview";
102 if (is_file("$previewFile.jpg")) {
103 return "$previewFile.jpg";
104 } else if (is_file("$previewFile.empty")) {
106 } else if (is_file("$previewFile.png")) {
107 return "$previewFile.png";
109 # config to allow group writable files
111 # create the thumbs directory recursively
112 if (! is_dir(dirname($previewFile))) @mkdir(dirname($previewFile), 0777, true)
113 or die("Could not write in data dir. Please fix permissions.");
115 // no preview: look for a preview in current dir, write it, return it
116 foreach (scandir($dir) as $file) if ($file[0] != '.') {
117 $ext = strtolower(substr($file, -4));
118 if ($ext == ".jpg" or $ext == ".png") {
119 $thumb = getPreview("$dir/$file");
120 copy($thumb, $previewFile.$ext);
121 return $previewFile.$ext;
122 } else if (is_dir("$dir/$file")) {
123 $subPreview = getAlbumPreview("$dir/$file");
125 $myPreview = dirname($previewFile)."/".basename($subPreview);
126 copy($subPreview, $myPreview);
132 // nothing found. create empty file
133 touch("$previewFile.empty");