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;
     }
 }
Example #2
0
 function neighbourPicture($name, $delta, $count = -1)
 {
     // is it a file?
     $pagefile = $this->provider->pageNameToFileName($name);
     if ($pagefile == -1 || $this->provider->isAlbum("/" . $pagefile)) {
         return false;
     }
     // split pathes into filename and path
     $filename = WikiGalleryLastComponent($pagefile);
     $path = WikiGalleryLeadingComponents($pagefile);
     if (!$path) {
         $slashpath = "";
         $pathslash = "";
     } else {
         $slashpath = "/" . $path;
         $pathslash = $path . "/";
     }
     // find position in the album of the current picture
     $pictures = $this->provider->getFilenames($slashpath);
     $indexed = array();
     $i = 0;
     $thisIndex = -1;
     foreach ($pictures as $k) {
         $indexed[$i] = $k;
         if ($k == $filename) {
             $thisIndex = $i;
         }
         $i++;
     }
     $picturesNum = $i;
     // found?
     if ($thisIndex == -1) {
         return false;
     }
     // get $count many neighbours from $thisIndex-$delta
     if ($count == -1) {
         $i = $thisIndex + $delta;
         if ($i >= 0 && $i < $picturesNum) {
             return $pathslash . $indexed[$i];
         } else {
             return "";
         }
     } else {
         $i = max($thisIndex + $delta, 0);
         $ret = array();
         while ($i < $picturesNum && $i < $thisIndex + $delta + $count) {
             $ret[] = $pathslash . $indexed[$i];
             $i++;
         }
         return $ret;
     }
 }