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 function getPreview($imgFile, $maxSize = THUMB_SIZE)
37 # example: data/myalbum/100.mypic.jpg
38 $newImgFile = DATA_DIR."/".dirname($imgFile)."/".$maxSize.".".basename($imgFile);
40 # if the preview is a symlink, image is already good sized
41 if (is_link($newImgFile)) return $imgFile;
43 if (! is_file($newImgFile))
45 # this tels the template to flush output after displaying previews
46 $GLOBALS["generating"] = true;
48 # reset script time limit to 20s (wont work in safe mode)
51 $ext = strtolower(substr($imgFile, -4));
53 $img = imagecreatefromjpeg($imgFile);
55 $img = imagecreatefrompng($imgFile);
59 # if the image is already small, make a symlink, and return it
60 if ($w <= $maxSize and $h <= $maxSize) {
62 symlink($imgFile, $newImgFile);
66 # config to allow group writable files
68 # create the thumbs directory recursively
69 if (! is_dir(dirname($newImgFile))) mkdir(dirname($newImgFile), 0777, true);
73 $newH = $h/($w/$maxSize);
75 $newW = $w/($h/$maxSize);
79 $newImg = imagecreatetruecolor($newW, $newH);
81 imagecopyresampled($newImg, $img, 0, 0, 0, 0, $newW, $newH, $w, $h);
84 imagejpeg($newImg, $newImgFile);
86 imagepng($newImg, $newImgFile);
89 imagedestroy($newImg);
95 function getAlbumPreview($dir)
97 $previewFile = DATA_DIR."/$dir/albumpreview";
99 if (is_file("$previewFile.jpg")) {
100 return "$previewFile.jpg";
101 } else if (is_file("$previewFile.empty")) {
103 } else if (is_file("$previewFile.png")) {
104 return "$previewFile.png";
106 # config to allow group writable files
108 # create the thumbs directory recursively
109 if (! is_dir(dirname($previewFile))) mkdir(dirname($previewFile), 0777, true);
111 // no preview: look for a preview in current dir, write it, return it
112 foreach (scandir($dir) as $file) if ($file != '.' and $file != '..') {
113 $ext = strtolower(substr($file, -4));
114 if ($ext == ".jpg" or $ext == ".png") {
115 $thumb = getPreview("$dir/$file");
116 copy($thumb, $previewFile.$ext);
117 return $previewFile.$ext;
118 } else if (is_dir("$dir/$file")) {
119 $subPreview = getAlbumPreview("$dir/$file");
121 $myPreview = dirname($previewFile)."/".basename($subPreview);
122 copy($subPreview, $myPreview);
128 // nothing found. create empty file
129 touch("$previewFile.empty");