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);
55 $exif = exif_read_data($imgFile);
57 $img = imagecreatefrompng($imgFile);
59 if ($img === false) return ""; #read error (wrong permission...)
63 # if the image is already small, make a symlink, and return it
64 if ($w <= $maxSize and $h <= $maxSize) {
66 symlink($imgFile, $newImgFile);
70 # config to allow group writable files
72 # create the thumbs directory recursively
73 if (! is_dir(dirname($newImgFile))) @mkdir(dirname($newImgFile), 0777, true)
74 or die("Could not write in data dir. Please fix permissions.");
78 $newH = $h/($w/$maxSize);
80 $newW = $w/($h/$maxSize);
84 $newImg = imagecreatetruecolor($newW, $newH);
86 imagecopyresampled($newImg, $img, 0, 0, 0, 0, $newW, $newH, $w, $h);
89 if (!empty($exif['Orientation'])) {
90 $orientation = $exif['Orientation'];
91 if ($orientation === 3) $newImg = imagerotate($newImg, 180, 0);
92 elseif ($orientation === 6) $newImg = imagerotate($newImg, -90, 0);
93 elseif ($orientation === 8) $newImg = imagerotate($newImg, 90, 0);
95 imagejpeg($newImg, $newImgFile, JPEG_QUALITY);
97 imagepng($newImg, $newImgFile);
101 imagedestroy($newImg);
108 function getAlbumPreview($dir)
110 $previewFile = DATA_DIR."/$dir/albumpreview";
112 if (is_file("$previewFile.jpg")) {
113 return "$previewFile.jpg";
114 } else if (is_file("$previewFile.empty")) {
116 } else if (is_file("$previewFile.png")) {
117 return "$previewFile.png";
119 # config to allow group writable files
121 # create the thumbs directory recursively
122 if (! is_dir(dirname($previewFile))) @mkdir(dirname($previewFile), 0777, true)
123 or die("Could not write in data dir. Please fix permissions.");
125 // no preview: look for a preview in current dir, write it, return it
126 foreach (scandir($dir) as $file) if ($file[0] != '.') {
127 $ext = strtolower(substr($file, -4));
128 if ($ext == ".jpg" or $ext == ".png") {
129 $thumb = getPreview("$dir/$file");
130 copy($thumb, $previewFile.$ext);
131 return $previewFile.$ext;
132 } else if (is_dir("$dir/$file")) {
133 $subPreview = getAlbumPreview("$dir/$file");
135 $myPreview = dirname($previewFile)."/".basename($subPreview);
136 copy($subPreview, $myPreview);
142 // nothing found. create empty file
143 touch("$previewFile.empty");