function pageNameToFileNameImpl($basePath, $pageName)
 {
     global $WikiGallery_PathDelimiter;
     // empty pageName?
     if ($pageName == "") {
         return "";
     }
     //echo "Will try to find filename for $pageName<br/>";
     $lastComponent = WikiGalleryLastComponent($pageName, $WikiGallery_PathDelimiter);
     $head = WikiGalleryLeadingComponents($pageName, $WikiGallery_PathDelimiter);
     if (!$head) {
         $path = "";
         $pathslash = "";
     } else {
         $path = $this->pageNameToFileNameImpl($basePath, $head);
         if ($path == -1) {
             return -1;
         }
         $pathslash = "{$path}/";
     }
     if (!is_dir($basePath . "/" . $path)) {
         return -1;
     }
     $pwd = opendir($basePath . "/" . $path);
     $found = "";
     while (($file = readdir($pwd)) != false) {
         $filePageName = fileNameToPageName($file);
         if (ucfirst($lastComponent) == $filePageName) {
             //echo "Found $file==$lastComponent<br/>";
             $found = $file;
             break;
         } else {
             //echo "$file => $filePageName!=$lastComponent<br/>";
         }
     }
     closedir($pwd);
     if ($found == "") {
         return -1;
     } else {
         return $pathslash . $found;
     }
 }
Beispiel #2
0
 function thumb($path, $width, $height, $resizeMode = "")
 {
     // exists?
     $pagename = fileNameToPageName($path);
     $original = $this->picturesBasePath . "/" . $path;
     if (!is_file($original)) {
         Abort('image doesn\'t exist');
     }
     // resize?
     if ($width == 0 && $height == 0) {
         $filename = $original;
     } else {
         // resize
         $filename = $this->cacheBasePath . "/" . $this->cacheFileName($path, $width, $height, $resizeMode);
         $exists = WikiGalleryIsFileAndNonZero($filename);
         if (!$exists || filemtime($filename) < filemtime($original)) {
             if (is_file($filename)) {
                 // if it already there, it must be updated. So remove it to avoid trouble overwriting it
                 unlink($filename);
             } else {
                 // make directory
                 $dir = dirname($filename);
                 mkdirp($dir);
             }
             // call ImageMagick or GD to scale
             $this->scale($original, $filename, $width, $height, $resizeMode);
         } else {
             // touch it so that it is not purged during cleanup
             touch($filename);
         }
     }
     // Checking if the client is validating his cache and if it is current.
     $etag = md5($original . filemtime($original) . filesize($original));
     header('ETag: ' . $etag);
     if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == filemtime($original) || isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag) {
         // Client's cache IS current, so we just respond '304 Not Modified'.
         header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($original)) . ' GMT', true, 304);
     } else {
         // Image not cached or cache outdated, we respond '200 OK' and output the image.
         header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($original)) . ' GMT', true, 200);
         header('Content-Length: ' . filesize($filename));
         header("Content-type: " . WikiGalleryMimeType($original));
         header("Pragma: ");
         header('Expires: ' . gmdate('D, j M Y H:i:s T', time() + 600));
         header("Cache-Control: max-age=600, must-revalidate");
         print file_get_contents($filename);
     }
 }
 function neighbourPicturePage($name, $delta, $count = -1)
 {
     $pics = $this->neighbourPicture($name, $delta, $count);
     if (!$pics) {
         return false;
     }
     if ($count != -1) {
         $ret = array();
         foreach ($pics as $pic) {
             $ret[] = fileNameToPageName($pic);
         }
         return $ret;
     } else {
         if ($pics == "") {
             return "";
         } else {
             return fileNameToPageName($pics);
         }
     }
 }