/** * method: load * * returns: * Boolean true or false depending on whether it succeeded, there are some codepaths which call setError() * this is because of serious errors which can't be handled at the moment * * NOTE: * - if language is false, you need to call setLanguage before you * call load otherwise the source can't load the correct file */ public function load() { if (!$this->language) { return false; } $dir = $this->getConfig("directory"); $source = Amslib_File::reduceSlashes("{$dir}/{$this->language}.xml"); $filename = false; try { // NOTE: This is ugly and I believe it's a failure of Amslib_File::find() to not do this automatically if (file_exists($source)) { $filename = $source; } else { if (file_exists($f = Amslib_File::find(Amslib_Website::relative($source), true))) { $filename = $f; } else { if (file_exists($f = Amslib_File::find(Amslib_Website::absolute($source), true))) { $filename = $f; } } } if (!$filename) { Amslib_Debug::log("stack_trace", "directory", $dir, "filename", $filename, "language", $this->language); } else { $this->qp = Amslib_QueryPath::qp($filename); return true; } } catch (Exception $e) { Amslib_Debug::log("Exception: ", $e->getMessage(), "file=", $filename, "source=", $source); Amslib_Debug::log("stack_trace"); } return false; }
public static function getCodeLocation($stack_offset = 2, $exception = NULL) { $stack = $exception ? self::getStackTrace("exception", $exception) : self::getStackTrace(); // eliminate this function from the stack $location = array_slice($stack, $stack_offset); $line = array_shift($location); $location = count($location) == 0 ? ltrim(Amslib_Website::web($line["file"]), "/") : array_shift($location); $line = isset($line["line"]) ? "@{$line["line"]}" : ""; $location = is_array($location) && Amslib_Array::hasKeys($location, array("class", "type", "function")) ? $location["class"] . $location["type"] . $location["function"] : $location; $location = is_array($location) && Amslib_Array::hasKeys($location, array("file", "function")) ? basename($location["file"]) . "({$location["function"]})" : $location; $location = is_array($location) && Amslib_Array::hasKeys($location, "function") ? "{$location["function"]}()" : $location; if (is_array($location)) { error_log("Debugging error, location of error not available: " . Amslib_Debug::vdump($location)); } $location = is_array($location) ? "__ERROR_unknown_location" : $location; return $location . $line; }
/** * method: serviceExportRouterJSON * * todo: write documentation */ public static function serviceExportRouterJSON($service, $source) { $data = self::exportRouterShared(); Amslib_Website::outputJSON($data); }
/** * method: writeCacheFromFile * * todo: write documentation */ public function writeCacheFromFile($filename) { $filename = Amslib_Website::absolute($filename); $cache = $this->getCacheFilename(); return copy($filename, $cache) && chmod($cache, 0755); }
protected static function setPath($name, $path) { Amslib_Website::setPath($name, $path); }
/** * note: * - I got the basics of this method from: http://stackoverflow.com/a/14883803/279147 */ public static function resolvePath($path) { if (strpos($path, "..") === false) { return $path; } list($protocol, $url) = explode("://", $path) + array(NULL, NULL); if ($url) { // protocol was valid, so domain is the first element $array = explode("/", $url); $domain = array_shift($array); $prefix = "{$protocol}://{$domain}/"; } else { $array = explode("/", $path); // If the path begins with a / then the final result path has to have one too $prefix = $path[0] == "/" ? "/" : ""; } $parents = array(); foreach ($array as $dir) { switch ($dir) { case '.': // Don't need to do anything here break; case '..': if (count($parents)) { array_pop($parents); } break; default: $parents[] = $dir; break; } } $url = $prefix . implode("/", $parents); return Amslib_Website::reduceSlashes($url); }
/** * method: redirect * * todo: write documentation */ public static function redirect($url, $permenant = 0) { $type = $permenant ? 301 : 0; return Amslib_Website::redirect($url, true, $type); }
/** * method: redirect * * todo: write documentation */ public function redirect($command = false) { if ($command != false) { $this->command = $command; } switch ($this->command) { case "SetExpressCheckout": $this->setExpressCheckout(true); $this->collapseParameters(); $this->url = "{$this->url}?{$this->queryString}"; Amslib_Website::redirect($this->url); } }
/** * method: glob * * todo: write documentation */ public static function glob($location, $relative = false) { $items = glob(Amslib_Website::absolute($location)); if ($relative) { foreach ($items as &$i) { $i = Amslib_Website::relative($i); } } return $items; }
/** * method: failureJSON * * todo: write documentation */ protected function failureJSON() { Amslib_Website::outputJSON($this->getResultData(), true); }
/** * method: set * * todo: write documentation */ public static function set($path = NULL) { if (self::$location !== NULL) { return self::$location; } $router_dir = NULL; if ($path == NULL) { self::$location = Amslib_Router::getBase(); } else { // Make sure the location has a slash at both front+back (ex: /location/, not /location or location/) self::$location = self::reduceSlashes("/" . Amslib_File::relative($path) . "/"); } // NOTE: Special case having a single slash as the location to being a blank string // the single slash causes lots of bugs and means you have to check everywhere // for it's presence, whilst it doesnt really do anything, so better if you // just eliminate it and put a blank string // NOTE: The reason is, if you str_replace($location,"",$something) and $location is / // then you will nuke every path separator in your url, which is useless.... if (self::$location == "/") { self::$location = ""; } return self::$location; }
/** * method: openFile * * todo: write documentation */ public function openFile($filename) { // NOTE: Added a call to Amslib_Website::abs to fix finding the file, because in some cases, // the file cannot be found. But I am not sure of the side-effects (if any) of doing this $this->filename = Amslib_File::find(Amslib_Website::absolute($filename), true); $document = new DOMDocument('1.0', 'UTF-8'); if (is_file($this->filename) && $document->load($this->filename)) { $this->xpath = new DOMXPath($document); return true; } Amslib_Keystore::add("error", "Amslib_XML::openFile[{$filename}], path[{$this->filename}] failed"); return false; }
/** * method: __construct * * todo: write documentation */ public function __construct($source) { $this->route = false; $this->import = false; $this->valid = false; $filename = false; try { // NOTE: This is ugly and I believe it's a failure of Amslib_File::find() to not do this automatically if (file_exists($source)) { $filename = $source; } else { if (file_exists($f = Amslib_File::find(Amslib_Website::relative($source), true))) { $filename = $f; } else { if (file_exists($f = Amslib_File::find(Amslib_Website::absolute($source), true))) { $filename = $f; } } } if (!$filename) { Amslib_Debug::log("The filename was not valid, we could not getRoutes from this XML Source"); } else { Amslib_QueryPath::qp($filename); Amslib_QueryPath::execCallback("router > path[name]", array($this, "configPath"), $this); Amslib_QueryPath::execCallback("router > service[name]", array($this, "configService"), $this); Amslib_QueryPath::execCallback("router > callback", array($this, "configCallback"), $this); Amslib_QueryPath::execCallback("router > import", array($this, "configImport"), $this); Amslib_QueryPath::execCallback("router > export", array($this, "configExport"), $this); $this->valid = true; } } catch (Exception $e) { Amslib_Debug::log("Exception: ", $e->getMessage(), "file=", $filename, "source=", $source); Amslib_Debug::log("stack_trace"); } }
/** * method: __construct * * todo: write documentation */ public function __construct($name, $location, $config = NULL) { parent::__construct(); // unless I think of a reason to not do this, always initialise sessions @session_start(); // This is needed so non-routed-services will work without modification // NOTE: probably I shouldn't need to do this, I need to find a way to make this redundant Amslib_Router::initialise(); // NOTE: I think that this method is redundant and the system should do it for me // NOTE: I'm not sure whether this method is actually useful anymore, I think it's out of date maybe Amslib_Website::set(); $base = Amslib_Router::getBase(); Amslib_Website::setPath("amslib", Amslib::locate()); Amslib_Website::setPath("website", $base); Amslib_Website::setPath("website_ext", Amslib_Router_URL::externalURL($base)); Amslib_Website::setPath("host", Amslib_Router_URL::externalURL()); // NOTE: I don't think I want this __ADMIN__ parameter anymore Amslib_Website::setPath("admin", "__ADMIN__"); Amslib_Website::setPath("plugin", "__PLUGIN__"); Amslib_Website::setPath("docroot", Amslib_File::documentRoot()); $this->completionCallback = array(); // Set the name, location and config of the plugin that was found in the hard disk $this->setName($name); $this->setLocation($location); $this->setConfigSource($config); }
public function redirectToURL($url) { Amslib_Website::redirect($url); }