diff options
author | Mario Vavti <mario@mariovavti.com> | 2016-12-23 10:09:46 +0100 |
---|---|---|
committer | Mario Vavti <mario@mariovavti.com> | 2016-12-23 10:09:46 +0100 |
commit | 3b9b03cf86979b28e7fa249133176bed84b0105c (patch) | |
tree | 336dc8b8b9627e7f4a93e5c35fe3e98555274616 /Zotlabs/Web/Router.php | |
parent | 2e5a993f880d619aedf3693927e7b3e164fbfcc0 (diff) | |
parent | ef39c1e94b5149a3019d417d08dc7c16c8aef9c1 (diff) | |
download | volse-hubzilla-3b9b03cf86979b28e7fa249133176bed84b0105c.tar.gz volse-hubzilla-3b9b03cf86979b28e7fa249133176bed84b0105c.tar.bz2 volse-hubzilla-3b9b03cf86979b28e7fa249133176bed84b0105c.zip |
Merge branch '2.0RC'
Diffstat (limited to 'Zotlabs/Web/Router.php')
-rw-r--r-- | Zotlabs/Web/Router.php | 116 |
1 files changed, 64 insertions, 52 deletions
diff --git a/Zotlabs/Web/Router.php b/Zotlabs/Web/Router.php index 4ba2a450d..271836ba9 100644 --- a/Zotlabs/Web/Router.php +++ b/Zotlabs/Web/Router.php @@ -2,51 +2,53 @@ namespace Zotlabs\Web; - +/** + * + * We have already parsed the server path into App::$argc and App::$argv + * + * App::$argv[0] is our module name. Let's call it 'foo'. We will load the + * Zotlabs/Module/Foo.php (object) or file mod/foo.php (procedural) + * and use it for handling our URL request to 'https://ourgreatwebsite.something/foo' . + * The module file contains a few functions that we call in various circumstances + * and in the following order: + * @code{.php} + * Object: + * class Foo extends \Zotlabs\Web\Controller { + * function init() { init function } + * function post() { post function } + * function get() { normal page function } + * } + * + * Procedual interface: + * foo_init() + * foo_post() (only called if there are $_POST variables) + * foo_content() - the string return of this function contains our page body + * @endcode + * Modules which emit other serialisations besides HTML (XML,JSON, etc.) should do + * so within the module init and/or post functions and then invoke killme() to terminate + * further processing. + */ class Router { private $modname = ''; private $controller = null; + /** + * @brief Router constructor + * + * @param[in,out] App &$a + * @throws Exception module not found + */ function __construct(&$a) { - /** - * - * We have already parsed the server path into App::$argc and App::$argv - * - * App::$argv[0] is our module name. Let's call it 'foo'. We will load the - * Zotlabs/Module/Foo.php (object) or file mod/foo.php (procedural) - * and use it for handling our URL request to 'https://ourgreatwebsite.something/foo' . - * The module file contains a few functions that we call in various circumstances - * and in the following order: - * - * Object: - * class Foo extends Zotlabs\Web\Controller { - * function init() { init function } - * function post() { post function } - * function get() { normal page function } - * } - * - * Procedual interface: - * foo_init() - * foo_post() (only called if there are $_POST variables) - * foo_content() - the string return of this function contains our page body - * - * Modules which emit other serialisations besides HTML (XML,JSON, etc.) should do - * so within the module init and/or post functions and then invoke killme() to terminate - * further processing. - */ - $module = \App::$module; $modname = "Zotlabs\\Module\\" . ucfirst($module); if(strlen($module)) { - /** - * + /* * We will always have a module name. * First see if we have a plugin which is masquerading as a module. - * */ if(is_array(\App::$plugins) && in_array($module,\App::$plugins) && file_exists("addon/{$module}/{$module}.php")) { @@ -66,7 +68,7 @@ class Router { goaway(z_root()); } - /** + /* * If the site has a custom module to over-ride the standard module, use it. * Otherwise, look for the standard program module */ @@ -101,13 +103,13 @@ class Router { } } } - - /** - * This provides a place for plugins to register module handlers which don't otherwise exist - * on the system, or to completely over-ride an existing module. + + /* + * This provides a place for plugins to register module handlers which don't otherwise exist + * on the system, or to completely over-ride an existing module. * If the plugin sets 'installed' to true we won't throw a 404 error for the specified module even if * there is no specific module file or matching plugin name. - * The plugin should catch at least one of the module hooks for this URL. + * The plugin should catch at least one of the module hooks for this URL. */ $x = array('module' => $module, 'installed' => \App::$module_loaded, 'controller' => $this->controller); @@ -117,7 +119,7 @@ class Router { $this->controller = $x['controller']; } - /** + /* * The URL provided does not resolve to a valid module. * * On Dreamhost sites, quite often things go wrong for no apparent reason and they send us to '/internal_error.html'. @@ -135,15 +137,21 @@ class Router { killme(); } - logger("Module {$module} not found.", LOGGER_DEBUG, LOG_WARNING); - - if((x($_SERVER, 'QUERY_STRING')) && ($_SERVER['QUERY_STRING'] === 'q=internal_error.html') && \App::$config['system']['dreamhost_error_hack']) { - logger('index.php: dreamhost_error_hack invoked. Original URI =' . $_SERVER['REQUEST_URI']); + if((x($_SERVER, 'QUERY_STRING')) + && ($_SERVER['QUERY_STRING'] === 'q=internal_error.html') + && \App::$config['system']['dreamhost_error_hack']) { + logger('index.php: dreamhost_error_hack invoked. Original URI =' . $_SERVER['REQUEST_URI'],LOGGER_DEBUG); goaway(z_root() . $_SERVER['REQUEST_URI']); } - logger('index.php: page not found: ' . $_SERVER['REQUEST_URI'] . ' ADDRESS: ' . $_SERVER['REMOTE_ADDR'] . ' QUERY: ' . $_SERVER['QUERY_STRING'], LOGGER_DEBUG); - header($_SERVER['SERVER_PROTOCOL'] . ' 404 ' . t('Not Found')); + if(get_config('system','log_404',true)) { + logger("Module {$module} not found.", LOGGER_DEBUG, LOG_WARNING); + logger('index.php: page not found: ' . $_SERVER['REQUEST_URI'] + . ' ADDRESS: ' . $_SERVER['REMOTE_ADDR'] . ' QUERY: ' + . $_SERVER['QUERY_STRING'], LOGGER_DEBUG); + } + + header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found'); $tpl = get_markup_template('404.tpl'); \App::$page['content'] = replace_macros($tpl, array( '$message' => t('Page not found.') @@ -157,7 +165,11 @@ class Router { } } - + /** + * @brief + * + * @param[in,out] App &$a + */ function Dispatch(&$a) { /** @@ -168,14 +180,14 @@ class Router { \App::$page['page_title'] = \App::$module; $placeholder = ''; - /** + /* * No theme has been specified when calling the module_init functions * For this reason, please restrict the use of templates to those which * do not provide any presentation details - as themes will not be able * to over-ride them. */ - $arr = array('init' => true, 'replace' => false); + $arr = array('init' => true, 'replace' => false); call_hooks(\App::$module . '_mod_init', $arr); if(! $arr['replace']) { if($this->controller && method_exists($this->controller,'init')) { @@ -187,7 +199,7 @@ class Router { } } - /** + /* * Do all theme initialisation here before calling any additional module functions. * The module_init function may have changed the theme. * Additionally any page with a Comanche template may alter the theme. @@ -195,7 +207,7 @@ class Router { */ - /** + /* * In case a page has overloaded a module, see if we already have a layout defined * otherwise, if a PDL file exists for this module, use it * The member may have also created a customised PDL that's stored in the config @@ -203,7 +215,7 @@ class Router { load_pdl($a); - /** + /* * load current theme info */ @@ -226,7 +238,7 @@ class Router { } } - if(($_SERVER['REQUEST_METHOD'] === 'POST') && (! \App::$error) && (! x($_POST, 'auth-params'))) { + if(($_SERVER['REQUEST_METHOD'] === 'POST') && (! \App::$error) && (! x($_POST, 'auth-params'))) { call_hooks(\App::$module . '_mod_post', $_POST); if($this->controller && method_exists($this->controller,'post')) { @@ -238,7 +250,7 @@ class Router { } } - if(! \App::$error) { + if(! \App::$error) { $arr = array('content' => \App::$page['content'], 'replace' => false); call_hooks(\App::$module . '_mod_content', $arr); \App::$page['content'] = $arr['content']; |