From d30d70afd95653bb356603612db6519d6e6ebead Mon Sep 17 00:00:00 2001 From: Antonio Gallo Date: Sat, 3 Dec 2011 12:30:25 +0000 Subject: improved i18n --- h-source/Library/Call.php | 3 ++- h-source/Library/Controller.php | 1 - h-source/Library/Form/Entry.php | 1 + h-source/Library/Form/Form.php | 2 ++ h-source/Library/Form/Select.php | 2 +- h-source/Library/Helper/List.php | 10 ++++++--- h-source/Library/Html/Form.php | 46 ++++++++++++++++++++++++---------------- h-source/Library/Model/Base.php | 25 +++++++++++++++++++--- h-source/Library/Params.php | 14 ++++++++---- h-source/Library/Theme.php | 15 +++++++------ 10 files changed, 82 insertions(+), 37 deletions(-) (limited to 'h-source/Library') diff --git a/h-source/Library/Call.php b/h-source/Library/Call.php index 29a3046..c75508b 100755 --- a/h-source/Library/Call.php +++ b/h-source/Library/Call.php @@ -232,12 +232,13 @@ function rewrite($url) { foreach (Route::$map as $key => $address) { + $oldKey = $key; $key = str_replace('\/','/',$key); $key = str_replace('/','\/',$key); if (preg_match('/^'.$key.'/',$url)) { $nurl = preg_replace('/^'.$key.'/',$address,$url); - return array($nurl,$key); + return array($nurl,$oldKey); // return preg_replace('/^'.$key.'/',$address,$url); } } diff --git a/h-source/Library/Controller.php b/h-source/Library/Controller.php index 742e89d..5a9ec79 100755 --- a/h-source/Library/Controller.php +++ b/h-source/Library/Controller.php @@ -55,7 +55,6 @@ class Controller { protected $scaffold = null; //the reference to the scaffold object function __construct($model, $controller, $queryString = array()) { - $this->controller = $controller; $this->modelName = $model; $this->_queryString = $queryString; diff --git a/h-source/Library/Form/Entry.php b/h-source/Library/Form/Entry.php index a17ac5e..8136dda 100755 --- a/h-source/Library/Form/Entry.php +++ b/h-source/Library/Form/Entry.php @@ -32,6 +32,7 @@ abstract class Form_Entry { public $labelString = null; //label of the form public $labelClass = null; //the class of the tag of the label public $options = array(); //options (if the entry is a \n"; + $returnString .= "\n"; + $returnString ="\n"; return $returnString; } @@ -95,12 +105,12 @@ class Html_Form { //$name: the name of the input //$className: the class name of the input //$idName: name of the id - static public function fileUpload($name, $value, $className = null, $idName = null) + static public function fileUpload($name, $value, $className = null, $idName = null, $attributes = null) { $strClass = isset($className) ? "class='".$className."'" : null; $idStr = isset($idName) ? "id='".$idName."'" : null; - $returnString ="\n"; + $returnString ="\n"; return $returnString; } @@ -110,13 +120,13 @@ class Html_Form { //$option: option of the checkBox (string or number) //$className: the class name of the checkBox (string) //$idName: name of the id - static public function checkbox($name, $value, $option, $className = null, $idName = null) + static public function checkbox($name, $value, $option, $className = null, $idName = null, $attributes = null) { $strClass = isset($className) ? "class='".$className."'" : null; $idStr = isset($idName) ? "id='".$idName."'" : null; $str = (strcmp($value,$option) === 0) ? "checked = 'checked'" : null; - return "\n"; + return "\n"; } //return the HTML of a hidden entry @@ -131,24 +141,24 @@ class Html_Form { //$name: name of the password entry (string) //$value: the value of the password entry (string or number) //$idName: name of the id - static public function password($name, $value, $className = null, $idName = null) + static public function password($name, $value, $className = null, $idName = null, $attributes = null) { $strClass = isset($className) ? "class='".$className."'" : null; $idStr = isset($idName) ? "id='".$idName."'" : null; - return "\n"; + return "\n"; } //return the HTML of a textarea //$name: name of the textarea (string) //$value: the value of the textarea (string or number) //$idName: name of the id - static public function textarea($name, $value, $className = null, $idName = null) + static public function textarea($name, $value, $className = null, $idName = null, $attributes = null) { $strClass = isset($className) ? "class='".$className."'" : null; $idStr = isset($idName) ? "id='".$idName."'" : null; - return "\n"; + return "\n"; } //return the HTML of a radio button @@ -158,7 +168,7 @@ class Html_Form { //$className: the class name of the radio button //$position: position of the strings of the radio with respect to the "circles". It can be before or after //$idName: name of the id - static public function radio($name, $value, $options, $className = null, $position = 'after', $idName = null) + static public function radio($name, $value, $options, $className = null, $position = 'after', $idName = null, $attributes = null) { $strClass = isset($className) ? "class='".$className."'" : null; $idStr = isset($idName) ? "id='".$idName."'" : null; @@ -189,7 +199,7 @@ class Html_Form { } $str= (strcmp($value,$optionValue) === 0) ? "checked='checked'" : null; - $returnString .= "$before$after\n"; + $returnString .= "$before$after\n"; } return $returnString; diff --git a/h-source/Library/Model/Base.php b/h-source/Library/Model/Base.php index c89abcd..57d769a 100755 --- a/h-source/Library/Model/Base.php +++ b/h-source/Library/Model/Base.php @@ -236,7 +236,7 @@ abstract class Model_Base //method to create the where clause of the select query from the $this->where array //$level: level of the ricorsion //$whereClauseLevel: array containing the field=>value statements of the where clause. If $whereClause = null than $this->where is considered - public function createWhereClause($level = 0, $whereClauseLevel = null) + public function createWhereClause($level = 0, $whereClauseLevel = null, $operator = null) { $whereClause = null; $whereClauseArray = array(); @@ -247,7 +247,19 @@ abstract class Model_Base { if (is_array($value)) { - $newValue = $this->createWhereClause($level+1, $value); + if (strstr($field,"OR")) + { + $op = " OR "; + } + else if (strstr($field,"AND")) + { + $op = " AND "; + } + else + { + $op = null; + } + $newValue = $this->createWhereClause($level+1, $value, $op); if (isset($newValue)) $whereClauseArray[] = $newValue; } else @@ -283,7 +295,14 @@ abstract class Model_Base } } //get the logic operator at the current level - $logicOper = isset($this->logicalOperators[$level]) ? ' '.$this->logicalOperators[$level].' ' : ' AND '; + if (isset($operator)) + { + $logicOper = $operator; + } + else + { + $logicOper = isset($this->logicalOperators[$level]) ? ' '.$this->logicalOperators[$level].' ' : ' AND '; + } $whereClause = !empty($whereClauseArray) ? implode($logicOper,$whereClauseArray) : null; $whereClause = (isset($whereClause) and $level>0) ? '('.$whereClause.')' : $whereClause; return $whereClause; diff --git a/h-source/Library/Params.php b/h-source/Library/Params.php index 001040e..488c8b2 100644 --- a/h-source/Library/Params.php +++ b/h-source/Library/Params.php @@ -26,11 +26,14 @@ if (!defined('EG')) die('Direct access not allowed!'); class Params { - public static $allowedDb = array('Mysql','Mysqli','None'); //allowed database type + //allowed database type + public static $allowedDb = array('Mysql','Mysqli','None'); - public static $allowedSanitizeFunc = 'sanitizeAll,sanitizeDb,sanitizeHtml,forceInt,forceNat,none,md5,sha1'; //allowed sanitize functions + //allowed sanitize functions + public static $allowedSanitizeFunc = 'sanitizeAll,sanitizeDb,sanitizeHtml,forceInt,forceNat,none,md5,sha1'; - public static $allowedHashFunc = array('md5','sha1'); //allowed hash functions + //allowed hash functions + public static $allowedHashFunc = array('md5','sha1'); //conventional null value for the value of the field in the createWhereClause method of the Model class public static $nullQueryValue = false; @@ -46,9 +49,12 @@ class Params public static $htmlentititiesCharset = DEFAULT_CHARSET; //list of symbols used in the statements of the where clause of the select queries - public static $whereClauseSymbolArray = array('<','>','!=','<=','>=','in(','not in('); + public static $whereClauseSymbolArray = array('<','>','!=','<=','>=','in(','not in(','like'); //is the mbstring extension enabled? public static $mbStringLoaded = false; + //subfolder of the View folder where to look for view files + public static $viewSubfolder = null; + } \ No newline at end of file diff --git a/h-source/Library/Theme.php b/h-source/Library/Theme.php index 45cace4..a001631 100755 --- a/h-source/Library/Theme.php +++ b/h-source/Library/Theme.php @@ -75,19 +75,22 @@ class Theme { public function render() { extract($this->_data); + //find the View subfolder where to look for view files + $subfolder = isset(Params::$viewSubfolder) ? Params::$viewSubfolder . DS : null; + foreach ($this->_viewFiles as $file) { - if (file_exists(ROOT . DS . APPLICATION_PATH . DS . 'Views' . DS . ucwords($this->controller) . DS . $file . '.php')) { - include (ROOT . DS . APPLICATION_PATH . DS . 'Views' . DS . ucwords($this->controller) . DS . $file . '.php'); + if (file_exists(ROOT . DS . APPLICATION_PATH . DS . 'Views' . DS .$subfolder. ucwords($this->controller) . DS . $file . '.php')) { + include (ROOT . DS . APPLICATION_PATH . DS . 'Views' . DS .$subfolder. ucwords($this->controller) . DS . $file . '.php'); } else { - include (ROOT . DS . APPLICATION_PATH . DS . 'Views' . DS . $file . '.php'); + include (ROOT . DS . APPLICATION_PATH . DS . 'Views' . DS .$subfolder. $file . '.php'); } } if (isset($this->_lastView)) { - if (file_exists(ROOT . DS . APPLICATION_PATH . DS . 'Views' . DS . ucwords($this->controller) . DS . $this->_lastView . '.php')) { - include (ROOT . DS . APPLICATION_PATH . DS . 'Views' . DS . ucwords($this->controller) . DS . $this->_lastView . '.php'); + if (file_exists(ROOT . DS . APPLICATION_PATH . DS . 'Views' . DS .$subfolder. ucwords($this->controller) . DS . $this->_lastView . '.php')) { + include (ROOT . DS . APPLICATION_PATH . DS . 'Views' . DS .$subfolder. ucwords($this->controller) . DS . $this->_lastView . '.php'); } else { - include (ROOT . DS . APPLICATION_PATH . DS . 'Views' . DS . $this->_lastView . '.php'); + include (ROOT . DS . APPLICATION_PATH . DS . 'Views' . DS .$subfolder. $this->_lastView . '.php'); } } -- cgit v1.2.3