From a93461b231fb94f3a6a9df09a30557732201ddcc Mon Sep 17 00:00:00 2001 From: Antonio Gallo Date: Mon, 14 Oct 2013 16:06:56 +0000 Subject: added new EasyGiant Library --- h-source/Library/Array/Validate/Soft.php | 35 +++-------- h-source/Library/Array/Validate/Strong.php | 35 +++-------- h-source/Library/Db/Mysql.php | 3 +- h-source/Library/Db/Mysqli.php | 3 +- h-source/Library/Files/Upload.php | 22 ++++++- h-source/Library/Form/Form.php | 73 +++++++++++++++++++--- h-source/Library/Form/Hidden.php | 2 +- h-source/Library/Functions.php | 74 +++++++++++++++++++++- h-source/Library/Helper/List.php | 45 ++++++++------ h-source/Library/Helper/Popup.php | 4 +- h-source/Library/Html/Form.php | 25 ++++++++ h-source/Library/Image/Gd/Thumbnail.php | 19 +++++- h-source/Library/Lang/En/Generic.php | 1 + h-source/Library/Model/Base.php | 99 +++++++++++++++++++----------- h-source/Library/Params.php | 32 ++-------- h-source/Library/Scaffold.php | 4 +- h-source/Library/Url.php | 2 +- h-source/Library/Users/CheckAdmin.php | 5 ++ 18 files changed, 326 insertions(+), 157 deletions(-) (limited to 'h-source') diff --git a/h-source/Library/Array/Validate/Soft.php b/h-source/Library/Array/Validate/Soft.php index b348bdc..d0c7646 100644 --- a/h-source/Library/Array/Validate/Soft.php +++ b/h-source/Library/Array/Validate/Soft.php @@ -1,24 +1,7 @@ . if (!defined('EG')) die('Direct access not allowed!'); @@ -39,35 +22,35 @@ class Array_Validate_Soft extends Array_Validate_Base } //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) are alphabetic values - public function checkAlpha($associativeArray,$keyString) + public function checkAlpha($associativeArray,$keyString,$strength = 'soft') { return parent::checkAlpha($associativeArray,$keyString,'soft'); } //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) are alphanumeric values - public function checkAlphaNum($associativeArray,$keyString) + public function checkAlphaNum($associativeArray,$keyString,$strength = 'soft') { return parent::checkAlphaNum($associativeArray,$keyString,'soft'); } //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) are decimal digits - public function checkDigit($associativeArray,$keyString) + public function checkDigit($associativeArray,$keyString,$strength = 'soft') { return parent::checkDigit($associativeArray,$keyString,'soft'); } //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) have mail format - public function checkMail($associativeArray,$keyString) + public function checkMail($associativeArray,$keyString,$strength = 'soft') { return parent::checkMail($associativeArray,$keyString,'soft'); } //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) is a number (integer or number). It makes use of the is_numeric PHP built-in function - public function checkNumeric($associativeArray,$keyString) + public function checkNumeric($associativeArray,$keyString,$strength = 'soft') { return parent::checkNumeric($associativeArray,$keyString,'soft'); } @@ -88,15 +71,15 @@ class Array_Validate_Soft extends Array_Validate_Base //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) are one of the values indicated in the argument $strings (a comma-separated list of words) - public function checkIsStrings($associativeArray,$keyString,$strings = '') + public function checkIsStrings($associativeArray,$keyString,$strings = '',$strength = 'soft') { return parent::checkIsStrings($associativeArray,$keyString,$strings,'soft'); } //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) match the regular expression $regExp - public function checkMatch($associativeArray,$keyString,$regExp = '/./') + public function checkMatch($associativeArray,$keyString,$regExp = '/./',$strength = 'soft') { return parent::checkMatch($associativeArray,$keyString,$regExp,'soft'); } -} \ No newline at end of file +} diff --git a/h-source/Library/Array/Validate/Strong.php b/h-source/Library/Array/Validate/Strong.php index ccdce74..d105319 100644 --- a/h-source/Library/Array/Validate/Strong.php +++ b/h-source/Library/Array/Validate/Strong.php @@ -1,24 +1,7 @@ . if (!defined('EG')) die('Direct access not allowed!'); @@ -72,7 +55,7 @@ class Array_Validate_Strong extends Array_Validate_Base } //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) are alphabetic values - public function checkAlpha($associativeArray,$keyString) + public function checkAlpha($associativeArray,$keyString,$strength = 'strong') { if ($this->checkNotEmpty($associativeArray,$keyString)) { @@ -86,7 +69,7 @@ class Array_Validate_Strong extends Array_Validate_Base //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) are alphanumeric values - public function checkAlphaNum($associativeArray,$keyString) + public function checkAlphaNum($associativeArray,$keyString,$strength = 'strong') { if ($this->checkNotEmpty($associativeArray,$keyString)) { @@ -100,7 +83,7 @@ class Array_Validate_Strong extends Array_Validate_Base //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) are decimal digits - public function checkDigit($associativeArray,$keyString) + public function checkDigit($associativeArray,$keyString,$strength = 'strong') { if ($this->checkNotEmpty($associativeArray,$keyString)) { @@ -114,7 +97,7 @@ class Array_Validate_Strong extends Array_Validate_Base //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) have mail format - public function checkMail($associativeArray,$keyString) + public function checkMail($associativeArray,$keyString,$strength = 'strong') { if ($this->checkNotEmpty($associativeArray,$keyString)) { @@ -128,7 +111,7 @@ class Array_Validate_Strong extends Array_Validate_Base //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) is a number (integer or number). It makes use of the is_numeric PHP built-in function - public function checkNumeric($associativeArray,$keyString) + public function checkNumeric($associativeArray,$keyString,$strength = 'strong') { if ($this->checkNotEmpty($associativeArray,$keyString)) { @@ -170,7 +153,7 @@ class Array_Validate_Strong extends Array_Validate_Base //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) are one of the values indicated in the argument $strings (a comma-separated list of words) - public function checkIsStrings($associativeArray,$keyString,$strings = '') + public function checkIsStrings($associativeArray,$keyString,$strings = '',$strength = 'strong') { if ($this->checkNotEmpty($associativeArray,$keyString)) { @@ -183,7 +166,7 @@ class Array_Validate_Strong extends Array_Validate_Base } //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) match the regular expression $regExp - public function checkMatch($associativeArray,$keyString,$regExp = '/./') + public function checkMatch($associativeArray,$keyString,$regExp = '/./',$strength = 'strong') { if ($this->checkNotEmpty($associativeArray,$keyString)) { @@ -194,4 +177,4 @@ class Array_Validate_Strong extends Array_Validate_Base return false; } } -} \ No newline at end of file +} diff --git a/h-source/Library/Db/Mysql.php b/h-source/Library/Db/Mysql.php index 4561a1b..d19d24a 100755 --- a/h-source/Library/Db/Mysql.php +++ b/h-source/Library/Db/Mysql.php @@ -270,7 +270,8 @@ class Db_Mysql { $result = mysql_query($query); $temp = array(); while ($row = mysql_fetch_assoc($result)) { - $temp[$row['Field']] = reset(explode('(',$row['Type'])); + $e = explode('(',$row['Type']); + $temp[$row['Field']] = reset($e); } $types = array(); diff --git a/h-source/Library/Db/Mysqli.php b/h-source/Library/Db/Mysqli.php index df57a54..b65f470 100644 --- a/h-source/Library/Db/Mysqli.php +++ b/h-source/Library/Db/Mysqli.php @@ -273,7 +273,8 @@ class Db_Mysqli $result = $this->db->query($query); $temp = array(); while ($row = $result->fetch_assoc()) { - $temp[$row['Field']] = reset(explode('(',$row['Type'])); + $e = explode('(',$row['Type']); + $temp[$row['Field']] = reset($e); } $result->close(); diff --git a/h-source/Library/Files/Upload.php b/h-source/Library/Files/Upload.php index 7dbc7d1..00a0afe 100755 --- a/h-source/Library/Files/Upload.php +++ b/h-source/Library/Files/Upload.php @@ -230,7 +230,8 @@ class Files_Upload { if (strstr($file,'.')) { - return strtolower(end(explode('.', $file))); + $extArray = explode('.', $file); + return strtolower(end($extArray)); } return ''; } @@ -268,6 +269,23 @@ class Files_Upload } + //get a not existing folder name + public function getUniqueFolderName($folder,$int = 0) + { + $token = $int === 0 ? null : $this->params['fileUploadBeforeTokenChar'].$int; + + $newName = $folder.$token; + if (!is_dir($this->base.$this->directory.$newName)) + { + return $newName; + } + else + { + return $this->getUniqueFolderName($folder,$int+1); + } + + } + protected function parentDir() { #individuo la cartella madre $folders = explode(self::DS,$this->directory); @@ -333,7 +351,7 @@ class Files_Upload } //check if the $name folder is empty or not - protected function isEmpty($name) + public function isEmpty($name) { $items = scandir($name); foreach( $items as $this_file ) { diff --git a/h-source/Library/Form/Form.php b/h-source/Library/Form/Form.php index a1a9fda..d1899a4 100755 --- a/h-source/Library/Form/Form.php +++ b/h-source/Library/Form/Form.php @@ -97,7 +97,7 @@ class Form_Form { //function to create the HTML of the form //$values: an associative array ('entryName'=>'value') - //$subset: subset to print + //$subset: subset to print (comma seprated list of string or array) public function render($values = null, $subset = null) { @@ -116,23 +116,78 @@ class Form_Form { $fenctype = isset($this->enctype) ? " enctype=".$this->enctype." " : null; $htmlForm = "
\n"; - $subset = (isset($subset)) ? explode(',',$subset) : array_keys($values); + if (!isset($subset)) + { + $subset = array_keys($values); + } + else + { + $subset = !is_array($subset) ? explode(',',$subset) : $subset; + } +// $subset = (isset($subset)) ? explode(',',$subset) : array_keys($values); - foreach ($subset as $entry) + //first cicle: write the HTML of tabs if there are any + $tabsHtml = null; + $fCount = 0; + foreach ($subset as $key => $entry) { - - if (array_key_exists($entry,$this->entry)) + if (is_array($entry)) { - $value = array_key_exists($entry,$values) ? $values[$entry] : $this->entry[$entry]->defaultValue; - $htmlForm .= $this->entry[$entry]->render($value); + $currClass = $fCount === 0 ? "current_tab" : null; + $cleanKey = encode($key); + $tabsHtml .= "\t
  • $key
  • \n"; + $fCount++; + } + } + if (isset($tabsHtml)) + { + $htmlForm .= "\n"; + } + + $fCount = 0; + foreach ($subset as $k => $entry) + { + + $cleanK = encode($k); + if (!is_array($entry)) + { + if (array_key_exists($entry,$this->entry)) + { + $value = array_key_exists($entry,$values) ? $values[$entry] : $this->entry[$entry]->defaultValue; + $htmlForm .= $this->entry[$entry]->render($value); + } + } + else + { + $tHtml = null; + $displClass = $fCount === 0 ? null : "display_none"; + foreach ($entry as $e) + { + if (array_key_exists($e,$this->entry)) + { + $value = array_key_exists($e,$values) ? $values[$e] : $this->entry[$e]->defaultValue; + $tHtml .= $this->entry[$e]->render($value); + } + } + $htmlForm .= "
    $tHtml
    "; + $fCount++; } - } + $htmlForm .= "
    "; foreach ($this->submit as $name => $value) { - $htmlForm .= "
    \n\n
    \n"; + if (!is_array($value)) + { + $htmlForm .= "".Html_Form::submit($name, $value, null, $name).""; + } + else + { + array_unshift($value,$name); + $htmlForm .= call_user_func_array(array("Html_Form","submit"),$value); + } } + $htmlForm .= "
    "; $htmlForm .= "
    \n"; return $htmlForm; } diff --git a/h-source/Library/Form/Hidden.php b/h-source/Library/Form/Hidden.php index c589662..db86713 100755 --- a/h-source/Library/Form/Hidden.php +++ b/h-source/Library/Form/Hidden.php @@ -33,7 +33,7 @@ class Form_Hidden extends Form_Entry public function render($value = null) { - $returnString = Html_Form::hidden($this->entryName, $value); + $returnString = Html_Form::hidden($this->entryName, $value, $this->className, $this->idName); return $returnString; } diff --git a/h-source/Library/Functions.php b/h-source/Library/Functions.php index 1477680..62a1838 100755 --- a/h-source/Library/Functions.php +++ b/h-source/Library/Functions.php @@ -163,7 +163,9 @@ function sha1Deep($value) return array_map('sha1', $value); } - +function strip_tagsDeep($value) { + return array_map('strip_tags', $value); +} @@ -294,6 +296,76 @@ function getUserAgent() { } } +//encode a string to drop ugly characters +function encode($url) +{ + $url = utf8_decode(html_entity_decode($url,ENT_QUOTES,'UTF-8')); + + $temp = null; + + for ($i=0;$i"; + if (strcmp(substr($url,$i,1),' ') === 0) + { + $temp .= '_'; + } + else if (strcmp(substr($url,$i,1),"'") === 0) + { + $temp .= ''; + } + else + { + if (preg_match('/^[a-zA-Z\_0-9]$/',substr($url,$i,1))) + { + $temp .= substr($url,$i,1); + } + else + { + $temp .= '-'; + } + } + } + + $temp = urlencode($temp); + return $temp; +} + +function callFunction($function, $string, $caller = "CallFunction") +{ + if (strstr($function,'::')) //static method + { + $temp = explode('::',$function); + + if (!method_exists($temp[0],$temp[1])) + { + throw new Exception('Error in '.$caller.': method '.$temp[1].' of class '.$temp[0].' does not exists.'); + } + + return call_user_func(array($temp[0], $temp[1]),$string); + } + else if (strstr($function,'.')) //method + { + $temp = explode('.',$function); + + $obj = new $temp[0]; //new instance of the object + + if (!method_exists($obj,$temp[1])) + { + throw new Exception('Error in '.$caller.': method '.$temp[1].' of class '.$temp[0].' does not exists.'); + } + + return call_user_func(array($obj, $temp[1]),$string); + } + else //function + { + if (!function_exists($function)) { + throw new Exception('Error in '.$caller.': function '.$function.' does not exists.'); + } + //apply the function + return call_user_func($function,$string); + } +} function xml_encode($string) { diff --git a/h-source/Library/Helper/List.php b/h-source/Library/Helper/List.php index ba59643..7f8fb77 100755 --- a/h-source/Library/Helper/List.php +++ b/h-source/Library/Helper/List.php @@ -172,47 +172,48 @@ class Helper_List extends Helper_Html { public function replaceFields($string,$rowArray) { $this->__rowArray = $rowArray; //used by the replaceField method - $string = preg_replace_callback('/(\;)(.*?)(\;)/', 'Helper_List::replaceField' ,$string); + $string = preg_replace_callback('/(\;)(.*?)(\;)/', array($this, 'replaceField') ,$string); return $string; } + //get : or . as char used to separate table and field + public function getChar($string) + { + return strstr($string,':') ? ':' : '.'; + } + //replace a single string wrapped by ; with its correspondent value taken by the $recordArray associative array (a row of the select query) public function replaceField($match) { $string = $match[2]; - if (strstr($string,':') or strstr($string,'.')) { - if (strstr($string,':')) - { - $char = ':'; - } - else - { - $char = '.'; - } - //check if a function has been indicated - if (strstr($string,'|')) + //check if a function has been indicated + if (strstr($string,'|')) + { + //get the function + $firstArray = explode('|',$string); + if (strstr($firstArray[1],':') or strstr($firstArray[1],'.')) { - //get the function - $firstArray = explode('|',$string); $func = $firstArray[0]; //replace the fields + $char = $this->getChar($firstArray[1]); $temp = explode($char,$firstArray[1]); $string = $this->__rowArray[$temp[0]][$temp[1]]; - if (!function_exists($func)) { - throw new Exception('Error in '.__METHOD__.': function '.$func.' does not exists..'); - } - //apply the function - $string = call_user_func($func,$string); + $string = callFunction($func,$string,__METHOD__); } - else + } + else + { + if (strstr($string,':') or strstr($string,'.')) { + $char = $this->getChar($string); $temp = explode($char,$string); $string = $this->__rowArray[$temp[0]][$temp[1]]; } } + return $string; } @@ -477,6 +478,10 @@ class Helper_List extends Helper_Html { $viewStatus = Url::createUrl(array_values($this->viewArgs)); if (strcmp($value,Params::$nullQueryValue) === 0) $value = ''; } + else + { + $viewStatus = $this->viewStatus; + } $this->viewArgs[$viewArgsName] = $temp; $action = Url::getRoot($this->url).$viewStatus; diff --git a/h-source/Library/Helper/Popup.php b/h-source/Library/Helper/Popup.php index 18bb00d..4f67a5c 100755 --- a/h-source/Library/Helper/Popup.php +++ b/h-source/Library/Helper/Popup.php @@ -104,7 +104,7 @@ class Helper_Popup extends Helper_Html { $tempArg = $this->viewArgs[$field]; $this->legend[$field] = $tempArg; - $returnString .= "