/** Main Call Function **/ function callHook() { global $url; global $default; $queryString = array(); if (!isset($url)) { $controller = $default['controller']; $action = $default['action']; } else { $url = routeURL($url); $urlArray = array(); $urlArray = explode("/", $url); $controller = $urlArray[0]; array_shift($urlArray); if (isset($urlArray[0])) { $action = $urlArray[0]; array_shift($urlArray); } else { $action = 'index'; // Default Action } $queryString = $urlArray; } $controllerName = ucfirst($controller) . 'Controller'; $dispatch = new $controllerName($controller, $action); if ((int) method_exists($controllerName, $action)) { call_user_func_array(array($dispatch, "beforeAction"), $queryString); call_user_func_array(array($dispatch, $action), $queryString); call_user_func_array(array($dispatch, "afterAction"), $queryString); } else { /* Error Generation Code Here */ } }
function processMVC() { global $url; global $default; if (!isset($url)) { $controller = $default['controller']; $action = $default['action']; } else { $url = routeURL($url); $urlArray = array(); $urlArray = explode("/", $url); $controller = $urlArray[0]; array_shift($urlArray); if (isset($urlArray[0])) { $action = $urlArray[0]; array_shift($urlArray); } else { $action = 'index'; // Default Action } $queryString = $urlArray; } $controllerName = $controller; $controller = ucwords($controller); $model = class_exists($controller) ? rtrim($controller, 's') : "Error"; $controller .= 'Controller'; $dispatch = class_exists($controller) ? new $controller($model, $controllerName, $action) : new ErrorController($model, $controllerName, $action); if ((int) method_exists($controller, $action)) { call_user_func_array(array($dispatch, $action), $queryString); } else { /* generate error code */ } }
function callHook() { global $url; global $default; global $controller; $queryString = array(); if (!isset($url)) { $controller = $default['controller']; $action = $default['action']; } else { $url = routeURL($url); $urlArray = array(); $urlArray = explode("/", $url); $urlArray = array_filter($urlArray); $controller = $urlArray[0]; array_shift($urlArray); if (isset($urlArray[0])) { $action = $urlArray[0]; array_shift($urlArray); } else { $action = 'index'; // Default Action } $queryString = $urlArray; } $controllerName = ucfirst($controller) . 'Controller'; // Check to see if the controller exists if (!file_exists('../application/controllers/' . $controllerName . '.php')) { if (isset($_SERVER['CONTENT_TYPE']) && $_SERVER['CONTENT_TYPE'] == 'application/json') { // Serve up some JSON $dispatch = new Api(); $dispatch->response('Endpoint not found', 404); } else { // Serve up some HTML $dispatch = new ErrorController(); call_user_func_array(array($dispatch, 'notFound'), []); exit; } } $dispatch = new $controllerName($controller, $action); if ((int) method_exists($controllerName, $action)) { call_user_func_array(array($dispatch, "beforeAction"), $queryString); call_user_func_array(array($dispatch, $action), $queryString); call_user_func_array(array($dispatch, "afterAction"), $queryString); } else { // We should check the Accept header type to server up the correct 404 if (isset($_SERVER['CONTENT_TYPE']) && $_SERVER['CONTENT_TYPE'] == 'application/json') { // Serve up some JSON $dispatch = new Api(); $dispatch->response('Endpoint not found', 404); } else { // Serve up some HTML $dispatch = new ErrorController(); call_user_func_array(array($dispatch, 'notFound'), []); exit; } } }
/** * Main Function for each http request. * The url pattern: controller/action/querystring */ function callHook() { global $url; global $default; $queryString = array(); if (!isset($url)) { $controller = $default['controller']; $action = $default['action']; } else { $url = routeURL($url); // if $url is null, return 404 error if (empty($url)) { $controller = $default['controller']; $action = 'error'; } else { //debug statement //echo "url->".$url; $urlArray = array(); $urlArray = explode("/", $url); //debug statement //print_r($urlArray); // fetch controller form array 0 $controller = $urlArray[0]; //shift out the first array element array_shift($urlArray); if (isset($urlArray[0])) { $action = $urlArray[0]; } else { $action = $default['action']; } //process controller parameters if (count($urlArray) > 1) { array_shift($urlArray); } else { $urlArray = array(); } $queryString = $urlArray; } //end else } $controllerName = ucfirst($controller) . 'Controller'; $dispatch = new $controllerName($controller, $action); //echo 'ctrl->'.$controller.' act->'.$action; if ((int) method_exists($controllerName, $action)) { call_user_func_array(array($dispatch, $action), $queryString); } else { /* Error Generation Code Here */ } }
/** Main Call Function **/ function despachar() { global $url; global $default; $queryString = array(); if (!isset($url)) { $controller = $default['controller']; $action = $default['action']; } else { $url = routeURL($url); $urlArray = array(); $urlArray = explode("/", $url); if (end($urlArray) == '') { array_pop($urlArray); } $controller = $urlArray[0]; array_shift($urlArray); if (isset($urlArray[0])) { $action = $urlArray[0]; array_shift($urlArray); } else { $action = 'index'; // Default Action } $queryString = $urlArray; } $controllerName = ucfirst($controller) . 'Controller'; if ((int) class_exists($controllerName) && (int) method_exists($controllerName, $action)) { $dispatch = new $controllerName($controller, $action); if (method_exists($dispatch, 'beforeAction')) { call_user_func_array(array($dispatch, 'beforeAction'), $queryString); } if (method_exists($dispatch, $action)) { call_user_func_array(array($dispatch, $action), $queryString); } if (method_exists($dispatch, 'afterAction')) { call_user_func_array(array($dispatch, 'afterAction'), $queryString); } } else { $controllerName = ucfirst($default['controller']) . 'Controller'; $dispatch = new $controllerName($default['controller'], $default['action'], true); //echo "No existe ese controlador o funcion"; } }
function DetermineRequest() { // declare variables global $url; global $default; $error_page = ROOT . DS . 'error404.php'; $queryString = array(); $url = routeURL($url); $url_page = ROOT . DS . 'pub' . DS . $url; if (!isset($url)) { $controller = $default['controller']; $action = $default['action']; $queryString = $default['queryString']; } elseif (file_exists($url_page)) { include $url_page; exit; } else { //$url = routeURL($url); $urlArray = array(); $urlArray = explode("/", $url); $controller = $urlArray[0]; array_shift($urlArray); if (isset($urlArray[0])) { $action = $urlArray[0]; array_shift($urlArray); $queryString = $urlArray; } else { $action = 'index'; // Default Action } } $controllerName = ucfirst($controller) . 'Controller'; $dispatch = new $controllerName($controller, $action); //echo $controller . ' is the controller, ' . $action . ' is the action, '; //print_r($queryString); //echo ' is the query string'; if ((int) method_exists($controllerName, $action)) { call_user_func(array($dispatch, $action), $queryString); } else { /* The controller does not have the action specified */ /* Here we decouple controller and action and look up the URL in the routing table */ /* look up the url in the routing table */ /* if it exists, use the controller and action specified */ } }
// You should have received a copy of the GNU General Public License // along with this program; see the file COPYING.txt. If not, see // <http://www.gnu.org/licenses/> // ----------------------------------------------------------------------- // CHECK INSTALLED if (is_readable("install/installer.php")) { header("Location: install/installer.php"); exit; } include_once "config/core.config.php"; include_once "inc/functions.inc.php"; // SESSION HANDLER -------------------------------------------------- session_name($core_config['php']['session_name']); session_start(); // SETUP URL ROUTING ------------------------------------------------ $uri_routing = routeURL(); if (isset($uri_routing[0]) && $uri_routing[0] == "disconnect") { session_unset(); session_destroy(); session_write_close(); header("Location: /"); exit; } // SET LOCALE ---------------------------------------------------------- define('LOCALE', $core_config['language']['server_locale']); if (isset($core_config['language']['standard_locale'])) { define('STND_LOCALE', $core_config['language']['standard_locale']); } else { define('STND_LOCALE', $core_config['language']['server_locale']); } putenv("LANGUAGE=" . LOCALE);
/** Main Call Function **/ function DetermineRequest() { global $url; global $default; $queryString = array(); if (!isset($url)) { // Go to the home page $controller = $default['controller']; $action = $default['action']; } else { $url = routeURL($url); $urlArray = array(); $urlArray = explode("/", $url); $controller = $urlArray[0]; // Save off the controller array_shift($urlArray); if (isset($urlArray[0])) { if (is_numeric($urlArray[0])) { $action = 'view'; } else { $action = $urlArray[0]; array_shift($urlArray); } $queryString = $urlArray; } else { $action = 'index'; // Default Action } } $controllerName = ucfirst($controller) . 'Controller'; /* __autoload() checks that $controllerName exists * If it doesn't exist, echoes error */ $dispatch = new $controllerName($controller, $action); if ((int) method_exists($controllerName, $action)) { if (method_exists($dispatch, "beforeAction")) { call_user_func_array(array($dispatch, "beforeAction"), $queryString); } call_user_func_array(array($dispatch, $action), $queryString); if (method_exists($dispatch, "afterAction")) { call_user_func_array(array($dispatch, "afterAction"), $queryString); } } else { /* The controller does not have the action specified */ /* Here we decouple controller and action and look up the URL in the routing table */ /* look up the url in the routing table */ /* if it exists, use the controller and action specified */ } /* if there's no controller/action or a routing table match, use default, or throw 404 error */ }