/** * method: expandPath * * todo: write documentation */ public static function expandPath($path) { // NOTE: this doesn't happen anymore, I think I got rid of this idea because it was never used // Loop through all the paths given in the htaccess file and attempt to replace them foreach (Amslib_Router::listPaths() as $key) { $path = str_replace($key, Amslib_Router::getPath($key), $path); } return Amslib_Website::expandPath($path); }
/** * method: importRouter * * todo: write documentation */ public static function importRouter($import) { $params = self::encodeURLPairs($import, "/", array("output", "url", "name")); // acquire the latest route for the export url and construct the url to call the external remote service $route = self::getRoute("service:framework:router:export:" . $import["output"]); $import["url"] = Amslib_File::resolvePath(Amslib_Website::expandPath($import["url"])); $import["url_full"] = rtrim($import["url"], "/") . rtrim($route["src"]["default"], "/") . "/{$params}/"; if ($import["output"] == "json") { // We are going to install a router using json as a data transfer medium // Acquire the json, decode it and obtain the domain $data = Amslib_File::getContents($import["url_full"], $error); if (strlen($error)) { Amslib_Debug::log("FAILED TO IMPORT ROUTER IN JSON FORMAT, OR OTHER PROBLEM DETECTED", $error, error_get_last()); } $data = json_decode($data, true); $domain = $data["domain"]; // For each route in the cache, create a new route in the local router, giving the name, group, domain and route data // You are not supposed to update the url cache, imported routes are not accessible through url // The reason for this is because it doesnt make sense a url from a remote system will be processed by the local system // All url requests for imported services should goto the remote server directly foreach (Amslib_Array::valid($data["cache"]) as $route) { // We cannot use the service inheritance when importing a remote router unset($route["extend"]); self::setRoute($route["name"], $route["group"], $domain, $route, false); } // Record that we imported something so we can possibly use this information self::setImportData($import["name"], $import); } else { if ($import["output"] == "xml") { $data = Amslib_File::getContents($import["url_full"], $error); if (strlen($error)) { Amslib_Debug::log("FAILED TO IMPORT ROUTER IN XML FORMAT, OR OTHER PROBLEM DETECTED", $error, error_get_last()); } // TODO: implement the logic to import from XML } } }
/** * method: getImage * * todo: write documentation * * NOTE: this function is being abused to be a generic "make relative url for a file" method for pretty much everything */ public function getImage($id, $relative = true) { if (!is_string($id)) { return false; } // Step 1: Expand any recognised tokens in the path $path = Amslib_Website::expandPath($id); // Step 2: Is the image absolute, beginning with http? if (strpos($id, "http") === 0) { return $id; } // Step 3: find the image inside the plugin if (isset($this->image[$id])) { return $this->image[$id]; } // Step 4: find the image relative to the website base (perhaps it's a path) $path = Amslib_Website::absolute($this->location . "/" . $id); if (file_exists($path)) { return $relative ? Amslib_Website::relative($path) : $path; } Amslib_Debug::log("stack_trace", "failed to find image", $id, $relative, $path, $this->location); // Step 4: return false, image was not found return false; }