0) //strpos can return boolean false or non boolen 0 which evaulates to false { $illegal = true; } if ($request[0] == "/") { $illegal = true; } if ($illegal) { echo "

This request has been denied to prevent potential abuse of FsPHPGallery (providing listing of arbitrary directories under the file system). If you are attempting to set up FsPHPGallery for the first time, please do not set \$imagePath (in config.php) to a value starting with \"/\" or containing \"..\" -- it is advisable to use symbolic links to get around this.

"; echo "\n"; global $abuseReports; global $email; if ($abuseReports) { mail($email, "Script abuse", $_SERVER["REMOTE_ADDR"] . " tried to abuse " . $_SERVER['REQUEST_URI']); } exit(); } } /* This function returns true if the image is portrait, otherwise returns false */ function isLandscape($path) { list($width, $height, $type, $attr) = getimagesize($path); if ($width > $height) { return true; } else { return false; } } /* Removes the trailing or preceeding slash from a string */ function removeSlashes($string) { if ($string[0] == "/") { $string = substr($string, 1); //return all but first char } if ($string[strlen($string) - 1] == "/") { $string = substr($string, 0, strlen($string) - 1); //return all but last char } return $string; } /* Recursive creates directories (e.g. mkdir -p) */ function recursiveMkdir($directory) { $dir = split("/", $directory); $create = ""; for ($i = 0; $i < count($dir); $i++) { $final = ($i == count($dir) - 1) ? true : false; $create = $create . $dir[$i] . "/"; if (file_exists($create)) { if ($final) { return true; } } else if (file_exists($create) && !is_dir($create)) { return false; } else { if (mkdir($create)) { if ($i == (count($dir) - 1)) { return true; } } else { return false; } } } } /* This takes a path and filename and returns just the path (not the filename) */ function returnPath($string) { $string = removeSlashes($string); $split = split("/", $string); $return = ""; for ($i = 0; $i < count($split) - 1; $i++) { $return = $return . $split[$i] . "/"; } return removeSlashes($return); } /* Takes a path and filename and returns just the file name (not the path) */ function returnName($string) { $string = removeSlashes($string); $split = split("/", $string); return $split[count($split) - 1]; } /* Checks whether the PHP has gd support */ function checkPHP() { if (!function_exists("imagejpeg")) { echo "

Your version of PHP does not appear to be compiled with gd support and therefore needs to be re-compiled with gd support before FsPHPGallery will work.

"; exit(); } } /* This function returns the extension of a file name */ function returnExtension($string) { return(strtolower(substr($string, strlen($string) - 3))); } function readCacheFile($file) { $fp = fopen($file,'r'); // dunno if this is a PHP bug or what but fgets() reads in the terminating new line // character as well so we have to manually cast it to an int due to PHP's // type looseness // actually i think it's because George used \n as the terminating character on each line $width = (int)fgets($fp); $height = (int)fgets($fp); $widthT = (int)fgets($fp); $heightT = (int)fgets($fp); $width_size1 = (int)fgets($fp); $height_size1 = (int)fgets($fp); $width_size2 = (int)fgets($fp); $height_size2 = (int)fgets($fp); $full_width = (int)fgets($fp); $full_height = (int)fgets($fp); fclose($fp); return ("$width $height $widthT $heightT $width_size1 $height_size1 $width_size2 $height_size2 $full_width $full_height"); } function writeCacheFile($item, $size_cache) { // Grab images for dimensions $extension = returnExtension($item); if ($extension == "jpg") { $source = imagecreatefromjpeg($item); } else if ($extension == "png") { $source = imagecreatefrompng($item); } $real_height = imagesy($source); $real_width = imagesx($source); imagedestroy($source); $ratio = ($real_width / $real_height); $ratio2 = ($real_height / $real_width); if (isLandscape($item)) { $width = round(600 * $ratio); $height = 600; $widthT = round(120 * $ratio); $heightT = 120; } else { $height = 600; $width = round(600 * $ratio); $heightT = 120; $widthT = round(120 * $ratio); } if (($real_height < 960) || ($real_width < 960)) { // For images with height < 960 // So that they don't scale UP $height_size1 = round($real_height * 0.5); $width_size1 = round($height_size1 * $ratio); $height_size2 = round($real_height * 0.75); $width_size2 = round($height_size2 * $ratio); } else { if (isLandscape($item)) { // For all landscape images (ie - with height > 960) $width_size1 = round(768 * $ratio); $height_size1 = 768; $width_size2 = round(960 * $ratio); $height_size2 = 960; } else { // For all portrait images (ie - with width > 960) $width_size1 = 768; $height_size1 = round(768 * $ratio2); $width_size2 = 960; $height_size2 = round(960 * $ratio2); } } recursiveMkdir(returnPath($size_cache)); $fp = fopen($size_cache,'w'); fwrite($fp, $width . "\n"); fwrite($fp, $height . "\n"); fwrite($fp, $widthT . "\n"); fwrite($fp, $heightT . "\n"); fwrite($fp, $width_size1 . "\n"); fwrite($fp, $height_size1 . "\n"); fwrite($fp, $width_size2 . "\n"); fwrite($fp, $height_size2 . "\n"); fwrite($fp, $real_width . "\n"); fwrite($fp, $real_height . "\n"); fclose($fp); clearstatcache(); }