Ejemplo n.º 1
0
 /**
  * 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;
 }
Ejemplo n.º 2
0
 /**
  * 	method:	writeCacheFromFile
  *
  * 	todo: write documentation
  */
 public function writeCacheFromFile($filename)
 {
     $filename = Amslib_Website::absolute($filename);
     $cache = $this->getCacheFilename();
     return copy($filename, $cache) && chmod($cache, 0755);
 }
Ejemplo n.º 3
0
 /**
  * 	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;
 }
Ejemplo n.º 4
0
 /**
  * 	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;
 }
Ejemplo n.º 5
0
 /**
  * 	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");
     }
 }
Ejemplo n.º 6
0
 /**
  * 	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;
 }