Esempio n. 1
0
 /**
  * method:	render
  *
  * This method will render this plugin using the default information,
  * unless you ignore that and do your own thing
  *
  * params:
  * 	$id		-	the id of the view to render, the "default" view is the first one to load
  * 	$params	-	an array of variables to make available to the view
  */
 public function render($id = "default", $params = array())
 {
     $params["resource"] = Amslib_Router::getResource();
     $params["body"] = strtolower($params["resource"]);
     $params["route"] = Amslib_Router::getName();
     $params["site_title"] = $this->getSiteTitle();
     $params["url_home"] = $this->getURL("home");
     $params["meta_description"] = $this->getValue("meta_description");
     $params["meta_author"] = $this->getValue("meta_author");
     if (strpos($params["route"], "error") !== false) {
         $params["data"] = $this->getErrorData();
     } else {
         $params["logo"] = $this->getFile("/resources/logo.png");
         $params["url_about"] = $this->getURL("about-framework");
         $params["url_gettingstarted"] = $this->getURL("getting-started");
         $params["url_examples"] = $this->getURL("examples");
         $params["url_plugins"] = $this->getURL("plugins");
         $params["url_webservices"] = $this->getURL("webservices");
         $params["url_api"] = $this->getURL("api");
         $params["url_documentation"] = $this->getURL("documentation");
         $params["url_testframework"] = $this->getURL("test-framework");
     }
     $params["content"] = $this->renderView($params["resource"], $params);
     return $this->renderView("Skeleton", $params);
 }
Esempio n. 2
0
 /**
  * method:	render
  * 
  * This method will render this plugin using the default information, 
  * unless you ignore that and do your own thing
  * 
  * params:
  * 	$id		-	the id of the view to render, the "default" view is the first one to load
  * 	$params	-	an array of variables to make available to the view
  */
 public function render($id = "default", $params = array())
 {
     $resource = Amslib_Router::getResource();
     $route = Amslib_Router::getName();
     switch ($route) {
         case "hello_world":
             //	Do you want to do something cusomised?
             $params["jabba_the_hut"] = "gimme a kiss beautiful";
             $params["luke_skywalker"] = "kissed his sister";
             $params["han_solo"] = "he shot first";
     }
     $params["content"] = $this->renderView($resource, $params);
     return $this->renderView("Skeleton", $params);
 }
Esempio n. 3
0
<?php

//	Change this to the correct path if required
require_once "amslib/Amslib.php";
Amslib_Debug::showErrors();
//	If you need language support, follow this pattern
Amslib_Router_Language::add("en_GB", "en", true);
Amslib_Router_Language::add("es_ES", "es");
Amslib_Router_Language::initialise("en");
//	Here we create a normal router object
$xml = Amslib_Router::getObject("source:xml");
$xml->load("amslib_router.xml");
Amslib_Router::setSource($xml);
Amslib_Router::execute();
//	This is how to obtain the language catalogue, using the language system linked ot the router
$locale = Amslib_Translator_XML::getInstance();
$locale->load("translations/" . Amslib_Router_Language::getCode() . ".xml", true);
//	Get the resource from the route detected
$resource = $router->getResource();
//	Here you should put what you need to do in order to complete the work
Esempio n. 4
0
 /**
  * 	method:	finalise
  *
  * 	todo: write documentation
  */
 public static function finalise()
 {
     if (!self::$path) {
         trigger_error("There was no __WEBSITE_ROOT__ definition found, check your .htaccess file", E_USER_ERROR);
         return false;
     }
     self::$route = false;
     //	TODO: document better what this code does
     $static = self::getRouteByURL(self::$path);
     //	Find all the matches and store all the route names here
     $matches = array($static["src_selected"] => $static);
     //	NOTE: so every route passes through the callback, even though it doesnt ask for it??
     foreach (self::$callback as $c) {
         $data = call_user_func($c, self::$path);
         $route = $data ? self::getRoute($data["name"]) : false;
         if ($route) {
             $matches[$data["src_selected"]] = array_merge($route, $data);
         }
     }
     $matches = array_filter($matches);
     if (count($matches) == 1) {
         //	set the only result
         self::$route = current($matches);
     } else {
         //	If there was more than one match, we need to search for the longest one and discard the rest
         $longest = "";
         //	search for the longest match in the array
         foreach (Amslib_Array::valid($matches) as $k => $r) {
             if (strlen($k) > strlen($longest)) {
                 $longest = $k;
             }
         }
         self::$route = isset($matches[$longest]) ? $matches[$longest] : self::$emptyRoute;
     }
 }
Esempio n. 5
0
 /**
  * 	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);
 }
Esempio n. 6
0
 /**
  * 	method:	decodeURLPairs
  *
  * 	todo: write documentation
  */
 public static function decodeURLPairs($offset = 0)
 {
     return Amslib_Router::decodeURLPairs($offset);
 }
Esempio n. 7
0
 /**
  * method:	render
  * 
  * This method will render this plugin using the default information, 
  * unless you ignore that and do your own thing
  * 
  * params:
  * 	$id		-	the id of the view to render, the "default" view is the first one to load
  * 	$params	-	an array of variables to make available to the view
  */
 public function render($id = "default", $params = array())
 {
     $resource = Amslib_Router::getResource();
     $params["content"] = $this->renderView($resource, $params);
     return $this->renderView("Skeleton", $params);
 }
Esempio n. 8
0
 /**
  * 	method:	__construct
  *
  * 	todo: write documentation
  *
  * 	notes:
  * 		-	The object is basically hard coded to ONLY use $_POST as an input source, but this might not be true
  * 		-	In situations where $_GET is used, you'd need to post some parameters through $_GET, others $_POST
  * 		-	So this should be made more flexible, so the webservice can define the input source and this accomodates
  */
 public function __construct()
 {
     //	Reset the service data and session structures
     $this->data = array();
     $this->session = array(self::HD => array());
     //	FIXME: we are hardcoding a route "home" which might not exist, this could be a bad idea
     $default_url = Amslib_Router::getURL("home");
     $url_return = Amslib_POST::get("url_return", Amslib_POST::get("return_url", $default_url));
     $url_return = Amslib_String::rchop($url_return, "?");
     $url_success = Amslib_POST::get("url_success", Amslib_POST::get("success_url", $url_return));
     $url_success = Amslib_String::rchop($url_success, "?");
     $url_failure = Amslib_POST::get("url_failure", Amslib_POST::get("failure_url", $url_return));
     $url_failure = Amslib_String::rchop($url_failure, "?");
     //	TODO:	I should remove all the url parameters from the source data so it doesn't pass through as data
     //	NOTE:	well then in this case perhaps I should have to namespace them too so they are in a separate
     //			part of the source data and not obvious "url_return" might be a bit generic
     //	NOTE:	but if I namespace them, I don't want to pass that complexity onto the programmer
     //	NOTE:	perhaps this means I need to add functions to build these parameters for the programmer
     //			instead of making them build them personally
     $this->setSuccessURL($url_success);
     $this->setFailureURL($url_failure);
     //	blank the appropriate session key to stop previous sessions overlapping
     //	NOTE:	what if you are using the json output? then there is no key to erase,
     //			so you're just creating session keys and not using them
     Amslib_SESSION::get(self::SR, false, true);
     //	Obtain the old return_ajax parameter, either as json or false
     $return_ajax = Amslib_POST::get("return_ajax", false) ? "json" : false;
     //	Obtain the new output_format parameter, or default to the return_ajax value if not found
     $format = Amslib_POST::get("output_format", $return_ajax);
     //	Sanitise the format to be one of three possible options, or default to false
     //	NOTE: we might want to use redirect, but we cannot store anything useful in the session
     //	NOTE: however this is valid reasoning: to do the job, redirect, but don't bother writing session data cause it cannot be used
     if (!in_array($format, array(false, "json", "session"))) {
         $format = false;
     }
     //	Now it should be safe to set the output format, false will of course reset
     $this->setOutputFormat($format);
     //	Initialise all the terminator groups that can exist
     $this->terminatorList = array_fill_keys(array("common", "success", "failure"), array());
 }
Esempio n. 9
0
 /**
  * 	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;
 }
Esempio n. 10
0
 public function configExport($name, $array, $object)
 {
     foreach ($array["child"] as $c) {
         if ($c["tag"] == "restrict") {
             Amslib_Router::setExportRestriction($c["value"], false);
         }
     }
     return true;
 }
Esempio n. 11
0
 /**
  * method: execute
  *
  * execute the application, or process a web service, depending on the type of the route
  *
  * NOTE:
  * 	-	if the route has type='service' we are going to process a webservice
  * 	-	override this default behaviour by overriding this method with a customised version
  */
 public function execute($params = array())
 {
     //	If the url executed belonds to a web service, run the service code
     //	NOTE:	this isService() call, I think is a bit hacky, I would
     //			like to do away with it and have the framework do it
     if (Amslib_Router::isService()) {
         $this->runService();
     }
     //	Get the current route and acquire the api object for the current route and render it
     //	NOTE:	we do this so you can render pages from other plugins or the application based
     //			on what route has been opened, sometimes you want to define webpages in separate
     //			plugins and render them just based on the url and/or route
     $route = Amslib_Router::getRoute();
     if (!$route || !isset($route["group"])) {
         Amslib_Debug::log("ROUTE OR ROUTE/GROUP DOES NOT EXIST", $route);
         return;
     }
     $api = $this->getAPI($route["group"]);
     if (!$api || !method_exists($api, "render")) {
         Amslib_Debug::log("API OR ITS RENDER METHOD DOES NOT EXIST", get_class($api), $route);
         return;
     }
     //	If the url executed belongs to a page, render the default view of the application
     print $api->render("default", $params);
 }
Esempio n. 12
0
 /**
  * 	method:	getLanguage
  *
  * 	todo: write documentation
  */
 public function getLanguage($test = NULL, $success = true, $failure = false)
 {
     $lang = Amslib_Router::getLanguage();
     if ($test === NULL) {
         return $lang;
     }
     return $lang === $test ? $success : $failure;
 }
Esempio n. 13
0
 public static function processExport()
 {
     foreach (self::$export as $key => $list) {
         foreach ($list as $name => $value) {
             $src = is_string($value["src"]) ? self::getPlugin($value["src"]) : $value["src"];
             $dst = is_string($value["dst"]) ? self::getPlugin($value["dst"]) : $value["dst"];
             $data = false;
             if (!$src || !$dst) {
                 $sname = is_object($src) ? $src->getName() : "searched: {$value["src"]}";
                 $dname = is_object($dst) ? $dst->getName() : "searched: {$value["dst"]}";
                 Amslib_Debug::log("plugin list", Amslib_Plugin_Manager::listPlugin());
                 Amslib_Debug::log("plugin invalid", intval(is_object($src)) . ", " . intval(is_object($dst)), $sname, $dname, Amslib_Router::getPath());
                 continue;
             }
             switch ($value["key"]) {
                 case "stylesheet":
                 case "javascript":
                 case "font":
                     die("[DIE]EXPORT[{$key}] => " . Amslib_Debug::pdump(true, array($src->getName(), $dst->getName(), $value["key"], $value["val"])));
                     break;
                 case "view":
                 case "value":
                     //	NOTE:	if I could change getValue to this, I could refactor all of these branches
                     //			together maybe into something very generic
                     //	NOTE:	the new import/export system works slightly differently from the old one,
                     //			we push directly into the import/export queues the information that we
                     //			want to pass and it doesn't enter the host plugin, this way, we can skip
                     //			a lot of bullshit with regard to internal data and data which is destined
                     //			for other plugins, the getValue method should in this case, circumstantially
                     //			create objects or just parse the data out of the structure, but it's not
                     //			about "getting" the value from the pluing, the $value variable already has
                     //			it and in many cases we don't need to do anything except return a particular
                     //			key depending on the stucture or type of that data, but in the case of
                     //			translators, objects or models, we need to ask the host plugin to create
                     //			the object on our behalf and then return and use it, because it might be
                     //			that the host plugin is the only plugin which has the correct functionality
                     //			necessary to create that object, in these cases getValue will do more than
                     //			just return a particular key, but will actually process the input data into
                     //			an "output data" to use
                     //$data = $src->getValue($value);
                     $dst->setValue($value["key"], $value["val"]);
                     break;
                 case "service":
                     //Amslib_FirePHP::output("export",$item);
                     //	Hmmm, I need a test case cause otherwise I won't know if this works
                     break;
                 case "image":
                     $dst->setValue($value["key"], $value["val"]);
                     break;
                     //	We do nothing special with these entries, we simply pass them
                 //	We do nothing special with these entries, we simply pass them
                 case "model":
                 case "translator":
                 default:
                     //	NOTE: I should change $value["key"] here to $value and make "key" something getValue uses internally
                     $data = $src->getValue($value["key"]);
                     $dst->setValue($value["key"], $data);
                     break;
             }
         }
     }
     self::$export = NULL;
 }