aboutsummaryrefslogtreecommitdiff
path: root/h-source/Library/Call.php
diff options
context:
space:
mode:
authorAntonio Gallo <tonicucoz@gmail.com>2014-09-16 08:03:29 +0000
committerAntonio Gallo <tonicucoz@gmail.com>2014-09-16 08:03:29 +0000
commit11972639df8315753123ebccdadee1f596807ad0 (patch)
tree7c932d7e2f0d66afa55e603960f86cef7b00c5ff /h-source/Library/Call.php
parent6209923d6cfb2418ee926cccdc62a9383e14bd97 (diff)
Integrated new EasyGiant Library
Diffstat (limited to 'h-source/Library/Call.php')
-rwxr-xr-xh-source/Library/Call.php208
1 files changed, 177 insertions, 31 deletions
diff --git a/h-source/Library/Call.php b/h-source/Library/Call.php
index c75508b..7f80841 100755
--- a/h-source/Library/Call.php
+++ b/h-source/Library/Call.php
@@ -2,7 +2,7 @@
// EasyGiant is a PHP framework for creating and managing dynamic content
//
-// Copyright (C) 2009 - 2011 Antonio Gallo
+// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com)
// See COPYRIGHT.txt and LICENSE.txt.
//
// This file is part of EasyGiant
@@ -35,19 +35,40 @@ function sanitizeSuperGlobal()
$_SERVER = stripslashesDeep($_SERVER);
}
-
-
-function checkPostLength()
+function checkPostLength($checkArray = null)
{
+ $a = isset($checkArray) ? $checkArray : $_POST;
+
if (MAX_POST_LENGTH !== 0)
{
- foreach ($_POST as $key => $value)
+ foreach ($a as $key => $value)
{
- if (strlen($value) > MAX_POST_LENGTH) die('the length of some of the $_POST values is too large');
+ if (is_array($value))
+ {
+ checkPostLength($value);
+ }
+ else
+ {
+ if (strlen($value) > MAX_POST_LENGTH) die('the length of some of the $_POST values is too large');
+ }
}
}
}
+//remove elements that are arrays
+//applied to $_POST and $_GET
+function fixArray($array)
+{
+ $temp = array();
+
+ foreach ($array as $key => $value)
+ {
+ $temp[$key] = is_array($value) ? "" : $value;
+ }
+
+ return $temp;
+}
+
function checkRequestUriLength()
{
if (MAX_REQUEST_URI_LENGTH !== 0)
@@ -61,20 +82,108 @@ function checkRegisterGlobals()
if (ini_get('register_globals')) die('register globals is on: easyGiant works only with register globals off');
}
-function callHook()
+//geth the name of the current application used
+function getApplicationName()
+{
+ if (isset(Params::$currentApplication))
+ {
+ return Params::$currentApplication;
+ }
+ return null;
+}
+
+//geth the path of the current application used
+//add the trailing slash to the application name
+function getApplicationPath()
+{
+ if (isset(Params::$currentApplication))
+ {
+ return "Apps".DS.ucfirst(Params::$currentApplication).DS;
+ }
+ return null;
+}
+
+function languageInUrl($url)
{
+ $url = trim($url,"/");
+
+ if (in_array($url,Params::$frontEndLanguages))
+ {
+ return $url."/";
+ }
+ return false;
+}
+function callHook()
+{
+
$currentUrl = null;
if (MOD_REWRITE_MODULE === true)
{
- $url = isset($_GET['url']) ? $_GET['url'] : DEFAULT_CONTROLLER . '/' . DEFAULT_ACTION;
+ if (isset($_GET['url']))
+ {
+ if (!languageInUrl($_GET['url']))
+ {
+ $url = $_GET['url'];
+ }
+ else
+ {
+ $url = languageInUrl($_GET['url']) . DEFAULT_CONTROLLER . '/' . DEFAULT_ACTION;
+ }
+ }
+ else
+ {
+ $url = DEFAULT_CONTROLLER . '/' . DEFAULT_ACTION;
+ }
}
else
{
- $url = (strcmp(getQueryString(),"") !== 0) ? getQueryString() : DEFAULT_CONTROLLER . '/' . DEFAULT_ACTION;
+ if (strcmp(getQueryString(),"") !== 0)
+ {
+ if (!languageInUrl(getQueryString()))
+ {
+ $url = getQueryString();
+ }
+ else
+ {
+ $url = languageInUrl(getQueryString()) . DEFAULT_CONTROLLER . '/' . DEFAULT_ACTION;
+ }
+ }
+ else
+ {
+ $url = DEFAULT_CONTROLLER . '/' . DEFAULT_ACTION;
+ }
}
+ $arriveUrl = $url;
+
+ $urlArray = array();
+ $urlArray = explode("/",$url);
+
+ //get the language
+ if (count(Params::$frontEndLanguages) > 0)
+ {
+ if (in_array($urlArray[0],Params::$frontEndLanguages))
+ {
+ Params::$lang = sanitizeAll($urlArray[0]);
+ array_shift($urlArray);
+ }
+ else
+ {
+ Params::$lang = Params::$defaultFrontEndLanguage;
+/*
+ if (isset($_GET['url']) and Params::$redirectToDefaultLanguage)
+ {
+ $h = new HeaderObj(DOMAIN_NAME);
+
+ $h->redirect($arriveUrl);
+ }*/
+ }
+ }
+
+ $url = implode("/",$urlArray);
+
// rewrite the URL
if (Route::$rewrite === 'yes')
{
@@ -85,12 +194,19 @@ function callHook()
// echo $url;
- $urlArray = array();
$urlArray = explode("/",$url);
-
$controller = DEFAULT_CONTROLLER;
$action = DEFAULT_ACTION;
+
+ //check if an application name is found in the URL
+ if (isset(Params::$installed) and isset($urlArray[0]) and strcmp($urlArray[0],'') !== 0 and in_array($urlArray[0],Params::$installed))
+ {
+ Params::$currentApplication = strtolower(trim($urlArray[0]));
+
+ array_shift($urlArray);
+ }
+
if (isset($urlArray[0]))
{
$controller = (strcmp($urlArray[0],'') !== 0) ? strtolower(trim($urlArray[0])) : DEFAULT_CONTROLLER;
@@ -108,10 +224,30 @@ function callHook()
$errorAction = ERROR_ACTION !== false ? ERROR_ACTION : DEFAULT_ACTION;
/*
- VERIFY THE ACTION NAME
+ CHECK COUPLES CONTROLLER,ACTION
*/
+ if (!in_array('all',Route::$allowed))
+ {
+ $couple = "$controller,$action";
+ if (getApplicationName() !== null)
+ {
+ $couple = getApplicationName().",".$couple;
+ }
+ if (!in_array($couple,Route::$allowed))
+ {
+ Params::$currentApplication = null;
+ $controller = $errorController;
+ $action = $errorAction;
+ $urlArray = array();
+ }
+ }
+
+ /*
+ VERIFY THE ACTION NAME
+ */
if (method_exists('Controller', $action) or !ctype_alnum($action) or (strcmp($action,'') === 0))
{
+ Params::$currentApplication = null;
$controller = $errorController;
$action = $errorAction;
$urlArray = array();
@@ -122,6 +258,7 @@ function callHook()
*/
if (!ctype_alnum($controller) or (strcmp($controller,'') === 0))
{
+ Params::$currentApplication = null;
$controller = $errorController;
$action = $errorAction;
$urlArray = array();
@@ -129,8 +266,10 @@ function callHook()
//check that the controller class belongs to the application/controllers folder
//otherwise set the controller to the default controller
- if (!file_exists(ROOT.DS.APPLICATION_PATH.DS.'Controllers'.DS.ucwords($controller).'Controller.php'))
+ // if (!file_exists(ROOT.DS.APPLICATION_PATH.DS.'Controllers'.DS.ucwords($controller).'Controller.php') and !file_exists(ROOT.DS.APPLICATION_PATH.DS.getApplicationPath().'Controllers'.DS.ucwords($controller).'Controller.php'))
+ if (!file_exists(ROOT.DS.APPLICATION_PATH.DS.getApplicationPath().'Controllers'.DS.ucwords($controller).'Controller.php'))
{
+ Params::$currentApplication = null;
$controller = $errorController;
$action = $errorAction;
$urlArray = array();
@@ -139,6 +278,7 @@ function callHook()
//set the controller class to DEFAULT_CONTROLLER if it doesn't exists
if (!class_exists(ucwords($controller).'Controller'))
{
+ Params::$currentApplication = null;
$controller = $errorController;
$action = $errorAction;
$urlArray = array();
@@ -147,40 +287,28 @@ function callHook()
//set the action to DEFAULT_ACTION if it doesn't exists
if (!method_exists(ucwords($controller).'Controller', $action))
{
+ Params::$currentApplication = null;
$controller = $errorController;
$action = $errorAction;
$urlArray = array();
}
-
- /*
- CHECK COUPLES CONTROLLER,ACTION
- */
- if (!in_array('all',Route::$allowed))
- {
- $couple = "$controller,$action";
- if (!in_array($couple,Route::$allowed))
- {
- $controller = $errorController;
- $action = $errorAction;
- $urlArray = array();
- }
- }
array_shift($urlArray);
$queryString = $urlArray;
//set the name of the application
- $application = $controller;
+ $controllerName = $controller;
$controller = ucwords($controller);
$model = $controller;
$controller .= 'Controller';
$model .= 'Model';
+// echo $controller."-".$action;
//include the file containing the set of actions to carry out before the initialization of the controller class
Hooks::load(ROOT . DS . APPLICATION_PATH . DS . 'Hooks' . DS . 'BeforeInitialization.php');
if (class_exists($controller))
{
- $dispatch = new $controller($model,$application,$queryString);
+ $dispatch = new $controller($model,$controllerName,$queryString, getApplicationName());
//pass the action to the controller object
$dispatch->action = $action;
@@ -196,7 +324,7 @@ function callHook()
$templateFlag= true;
- if (method_exists($controller, $action))
+ if (method_exists($dispatch, $action))
{
//pass the action to the theme object
$dispatch->theme->action = $action;
@@ -235,7 +363,10 @@ function rewrite($url)
$oldKey = $key;
$key = str_replace('\/','/',$key);
$key = str_replace('/','\/',$key);
- if (preg_match('/^'.$key.'/',$url))
+
+ $regExpr = Params::$exactUrlMatchRewrite ? '/^'.$key.'$/' : '/^'.$key.'/';
+
+ if (preg_match($regExpr,$url))
{
$nurl = preg_replace('/^'.$key.'/',$address,$url);
return array($nurl,$oldKey);
@@ -272,10 +403,18 @@ function __autoload($className)
{
require_once(ROOT . DS . 'Library' . DS . $className . '.php');
}
+ else if (getApplicationName() and file_exists(ROOT . DS . APPLICATION_PATH . DS . getApplicationPath() . 'Controllers' . DS . $backupName . '.php'))
+ {
+ require_once(ROOT . DS . APPLICATION_PATH . DS . getApplicationPath() . 'Controllers' . DS . $backupName . '.php');
+ }
else if (file_exists(ROOT . DS . APPLICATION_PATH . DS . 'Controllers' . DS . $backupName . '.php'))
{
require_once(ROOT . DS . APPLICATION_PATH . DS . 'Controllers' . DS . $backupName . '.php');
}
+ else if (getApplicationName() and file_exists(ROOT . DS . APPLICATION_PATH . DS . getApplicationPath() . 'Models' . DS . $backupName . '.php'))
+ {
+ require_once(ROOT . DS . APPLICATION_PATH . DS . getApplicationPath() . 'Models' . DS . $backupName . '.php');
+ }
else if (file_exists(ROOT . DS . APPLICATION_PATH . DS . 'Models' . DS . $backupName . '.php'))
{
require_once(ROOT . DS . APPLICATION_PATH . DS . 'Models' . DS . $backupName . '.php');
@@ -284,6 +423,10 @@ function __autoload($className)
{
require_once(ROOT . DS . APPLICATION_PATH . DS . 'Modules' . DS . $backupName . '.php');
}
+ else if (getApplicationName() and file_exists(ROOT . DS . APPLICATION_PATH . DS . getApplicationPath() . 'Strings' . DS . $backupName . '.php'))
+ {
+ require_once(ROOT . DS . APPLICATION_PATH . DS . getApplicationPath() . 'Strings' . DS . $backupName . '.php');
+ }
else if (file_exists(ROOT . DS . APPLICATION_PATH . DS . 'Strings' . DS . $className . '.php'))
{
require_once(ROOT . DS . APPLICATION_PATH . DS . 'Strings' . DS . $className . '.php');
@@ -293,6 +436,9 @@ function __autoload($className)
try {
+ $_POST = fixArray($_POST);
+ $_GET = fixArray($_GET);
+
//check the length of the $_POST values
checkPostLength();