Esempio n. 1
0
 /** ************************************************
  * This function tries to travers the given url's path
  * but will not work if the realtive path is not traversable
  * with the given url.
  * @param: $url string; a url
  * @param: $relPath string; a relative path 
  * @return: string; the url after it was traversed by
  * relPath. Or false if there was some error/problem
  * TODO: Do a better job of adding / in the return string
  ***************************************************/
 public static function traversRelPath($sUrl, $relPath)
 {
     if (!WebUtils::isValidURL($sUrl)) {
         return false;
     }
     $baseP = WebUtils::getCurrentPathURL($sUrl);
     $baseU = WebUtils::getBaseURL($sUrl);
     $path = WebUtils::getPathOnly($sUrl);
     $path = explode('/', $path);
     $relPath = explode('/', $relPath);
     //echo '<pre>Path '. var_export($path, true) . '</pre><br/>';
     //echo '<pre>rel '. var_export($relPath, true) . '</pre><br/>';
     foreach ($relPath as $r) {
         if ($r != '.' && $r != '..') {
             array_push($path, array_shift($relPath));
             continue;
         } else {
             if ($r == '.') {
                 array_shift($relPath);
                 continue;
             } else {
                 if ($r == '..') {
                     array_shift($relPath);
                     if (array_pop($path) == null) {
                         return false;
                     }
                 }
             }
         }
     }
     return rtrim($baseU . implode('/', $path) . implode('/', $relPath), '/');
 }