You are here

function ARC_rdfxml_parser::calc_abs_path in Taxonomy import/export via XML 6.2

Same name and namespace in other branches
  1. 5.2 arc/ARC_rdfxml_parser.php \ARC_rdfxml_parser::calc_abs_path()
  2. 5 arc/ARC_rdfxml_parser.php \ARC_rdfxml_parser::calc_abs_path()
  3. 6 arc/ARC_rdfxml_parser.php \ARC_rdfxml_parser::calc_abs_path()
2 calls to ARC_rdfxml_parser::calc_abs_path()
ARC_rdfxml_parser::calc_base in arc/ARC_rdfxml_parser.php
ARC_rdfxml_parser::calc_uri in arc/ARC_rdfxml_parser.php

File

arc/ARC_rdfxml_parser.php, line 216

Class

ARC_rdfxml_parser

Code

function calc_abs_path($path = "", $base = "") {
  if (strpos($path, "/") === 0) {

    /* leading slash */
    if (preg_match("/([^\\/]*[\\/]{1,2}[^\\/]+)\\//", $base, $matches)) {
      return $matches[1] . $path;
    }
  }
  elseif ($path == "") {
    return $base;
  }
  else {

    /* rel path (../ or  path) */

    /* remove stuff after last slash */
    $base = substr($base, 0, strrpos($base, "/")) . "/";
    if (strpos($path, "../") === 0) {
      if (preg_match("/([^\\/]*[\\/]{1,2}[^\\/]+\\/)(.*)\\//", $base, $matches)) {
        $server_part = $matches[1];
        $path_part = $matches[2];
      }
      else {
        $server_part = $base;
        $path_part = "";
      }
      while (strpos($path, "../") === 0) {
        $path = substr($path, 3);
        $path_part = strlen($path_part) ? substr($path_part, 0, -1) : "";

        /* remove / */
        if (strpos($path_part, "/")) {
          $path_part = substr($path_part, 0, strrpos($path_part, "/")) . "/";

          /* remove stuff after (new) last slash */
        }
        else {
          $path_part = "";
        }
      }
      return $server_part . $path_part . $path;
    }
    else {
      return $base . $path;
    }
  }
  return $path;
}