Did some vars renaming to clarify

This commit is contained in:
Marc MAURICE 2010-12-30 19:10:44 +01:00
parent 2dda0f27a6
commit ad9d78f8d7

View file

@ -17,24 +17,24 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
require '../../config.php'; $bizouRootFromHere = '../..';
require "$bizouRootFromHere/config.php";
$simplePath = $_SERVER["PATH_INFO"]; $simpleImagePath = $_SERVER["PATH_INFO"];
if ($simplePath == '/') $simplePath = ''; if ($simpleImagePath == '/') $simpleImagePath = '';
// extra security check to avoid /photos/index/../.. like urls, maybe useless but.. // extra security check to avoid /photos/index/../.. like urls, maybe useless but..
if (strpos($simplePath, '..') !== false) die(".. found in url"); if (strpos($simpleImagePath, '..') !== false) die(".. found in url");
if (! is_file('../../'.IMAGES_DIR.$simplePath)) {
if (! is_file("$bizouRootFromHere/".IMAGES_DIR.$simpleImagePath)) {
header("HTTP/1.1 404 Not Found"); header("HTTP/1.1 404 Not Found");
die("File Not Found"); die("File Not Found");
} }
$scriptPath = $_SERVER["SCRIPT_NAME"];
// get all images in an array // get all images in an array
$images = array(); $images = array();
$files = scandir('../../'.IMAGES_DIR.dirname($simplePath)); $files = scandir("$bizouRootFromHere/".IMAGES_DIR.dirname($simpleImagePath));
foreach ($files as $file) { foreach ($files as $file) {
$ext = strtolower(substr($file, -4)); $ext = strtolower(substr($file, -4));
if ($ext == ".jpg" or $ext == ".png") if ($ext == ".jpg" or $ext == ".png")
@ -42,7 +42,7 @@ foreach ($files as $file) {
} }
// find the image position // find the image position
$pos = array_search(basename($simplePath), $images); $pos = array_search(basename($simpleImagePath), $images);
if ($pos === false) die("Image not found"); if ($pos === false) die("Image not found");
// get prev and next images // get prev and next images
@ -53,20 +53,25 @@ if ($pos > 0)
if ($pos < sizeof($images)-1) if ($pos < sizeof($images)-1)
$nextImage = $images[$pos+1]; $nextImage = $images[$pos+1];
$scriptUrl = $_SERVER["SCRIPT_NAME"];
$bizouRootUrl = dirname(dirname(dirname($scriptUrl)));
// scriptUrl = /path/to/bizou/plugins/viewer/view.php
// bizouRootUrl = /path/to/bizou
// template variables // template variables
$imageUrl = dirname($scriptPath)."/../../".IMAGES_DIR.$simplePath; $imageUrl = "$bizouRootUrl/".IMAGES_DIR.$simpleImagePath;
if ($nextImage === '') { if ($nextImage === '') {
$nextImageUrl = ''; $nextImageUrl = '';
$nextPageUrl = ''; $nextPageUrl = '';
} else { } else {
$nextImageUrl = dirname($scriptPath)."/".IMAGES_DIR.dirname($simplePath)."/$nextImage"; $nextImageUrl = "$bizouRootUrl/".IMAGES_DIR.dirname($simpleImagePath)."/$nextImage";
$nextPageUrl = dirname($_SERVER["REQUEST_URI"])."/$nextImage"; $nextPageUrl = dirname($_SERVER["REQUEST_URI"])."/$nextImage";
} }
if ($prevImage === '') $prevPageUrl = ''; if ($prevImage === '') $prevPageUrl = '';
else $prevPageUrl = dirname($_SERVER["REQUEST_URI"])."/$prevImage"; else $prevPageUrl = dirname($_SERVER["REQUEST_URI"])."/$prevImage";
$directoryUrl = dirname($scriptPath)."/../../index.php".dirname($simplePath); $directoryUrl = "$bizouRootUrl/index.php".dirname($simpleImagePath);
header('Content-Type: text/html; charset=utf-8'); header('Content-Type: text/html; charset=utf-8');
header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 3600)); header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 3600));