@@ -1,89 +1,89 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') or exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 2 | + defined('ROOT_PATH') or exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Class for Benchmark |
|
| 29 | - */ |
|
| 30 | - class Benchmark{ |
|
| 31 | - /** |
|
| 32 | - * The markers for excution time |
|
| 33 | - * @var array |
|
| 34 | - */ |
|
| 35 | - private $markersTime = array(); |
|
| 27 | + /** |
|
| 28 | + * Class for Benchmark |
|
| 29 | + */ |
|
| 30 | + class Benchmark{ |
|
| 31 | + /** |
|
| 32 | + * The markers for excution time |
|
| 33 | + * @var array |
|
| 34 | + */ |
|
| 35 | + private $markersTime = array(); |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * The markers for memory usage |
|
| 39 | - * @var array |
|
| 40 | - */ |
|
| 41 | - private $markersMemory = array(); |
|
| 37 | + /** |
|
| 38 | + * The markers for memory usage |
|
| 39 | + * @var array |
|
| 40 | + */ |
|
| 41 | + private $markersMemory = array(); |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * This method is used to mark one point for benchmark (execution time and memory usage) |
|
| 45 | - * @param string $name the marker name |
|
| 46 | - */ |
|
| 47 | - public function mark($name){ |
|
| 48 | - //Marker for execution time |
|
| 49 | - $this->markersTime[$name] = microtime(true); |
|
| 50 | - //Marker for memory usage |
|
| 51 | - $this->markersMemory[$name] = memory_get_usage(true); |
|
| 52 | - } |
|
| 43 | + /** |
|
| 44 | + * This method is used to mark one point for benchmark (execution time and memory usage) |
|
| 45 | + * @param string $name the marker name |
|
| 46 | + */ |
|
| 47 | + public function mark($name){ |
|
| 48 | + //Marker for execution time |
|
| 49 | + $this->markersTime[$name] = microtime(true); |
|
| 50 | + //Marker for memory usage |
|
| 51 | + $this->markersMemory[$name] = memory_get_usage(true); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * This method is used to get the total excution time in second between two markers |
|
| 56 | - * @param string $startMarkerName the marker for start point |
|
| 57 | - * @param string $endMarkerName the marker for end point |
|
| 58 | - * @param integer $decimalCount the number of decimal |
|
| 59 | - * @return string the total execution time |
|
| 60 | - */ |
|
| 61 | - public function elapsedTime($startMarkerName = null, $endMarkerName = null, $decimalCount = 6){ |
|
| 62 | - if(! $startMarkerName || !isset($this->markersTime[$startMarkerName])){ |
|
| 63 | - return 0; |
|
| 64 | - } |
|
| 54 | + /** |
|
| 55 | + * This method is used to get the total excution time in second between two markers |
|
| 56 | + * @param string $startMarkerName the marker for start point |
|
| 57 | + * @param string $endMarkerName the marker for end point |
|
| 58 | + * @param integer $decimalCount the number of decimal |
|
| 59 | + * @return string the total execution time |
|
| 60 | + */ |
|
| 61 | + public function elapsedTime($startMarkerName = null, $endMarkerName = null, $decimalCount = 6){ |
|
| 62 | + if(! $startMarkerName || !isset($this->markersTime[$startMarkerName])){ |
|
| 63 | + return 0; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - if(! isset($this->markersTime[$endMarkerName])){ |
|
| 67 | - $this->markersTime[$endMarkerName] = microtime(true); |
|
| 68 | - } |
|
| 69 | - return number_format($this->markersTime[$endMarkerName] - $this->markersTime[$startMarkerName], $decimalCount); |
|
| 70 | - } |
|
| 66 | + if(! isset($this->markersTime[$endMarkerName])){ |
|
| 67 | + $this->markersTime[$endMarkerName] = microtime(true); |
|
| 68 | + } |
|
| 69 | + return number_format($this->markersTime[$endMarkerName] - $this->markersTime[$startMarkerName], $decimalCount); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * This method is used to get the total memory usage in byte between two markers |
|
| 74 | - * @param string $startMarkerName the marker for start point |
|
| 75 | - * @param string $endMarkerName the marker for end point |
|
| 76 | - * @param integer $decimalCount the number of decimal |
|
| 77 | - * @return string the total memory usage |
|
| 78 | - */ |
|
| 79 | - public function memoryUsage($startMarkerName = null, $endMarkerName = null, $decimalCount = 6){ |
|
| 80 | - if(! $startMarkerName || !isset($this->markersMemory[$startMarkerName])){ |
|
| 81 | - return 0; |
|
| 82 | - } |
|
| 72 | + /** |
|
| 73 | + * This method is used to get the total memory usage in byte between two markers |
|
| 74 | + * @param string $startMarkerName the marker for start point |
|
| 75 | + * @param string $endMarkerName the marker for end point |
|
| 76 | + * @param integer $decimalCount the number of decimal |
|
| 77 | + * @return string the total memory usage |
|
| 78 | + */ |
|
| 79 | + public function memoryUsage($startMarkerName = null, $endMarkerName = null, $decimalCount = 6){ |
|
| 80 | + if(! $startMarkerName || !isset($this->markersMemory[$startMarkerName])){ |
|
| 81 | + return 0; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - if(! isset($this->markersMemory[$endMarkerName])){ |
|
| 85 | - $this->markersMemory[$endMarkerName] = microtime(true); |
|
| 86 | - } |
|
| 87 | - return number_format($this->markersMemory[$endMarkerName] - $this->markersMemory[$startMarkerName], $decimalCount); |
|
| 88 | - } |
|
| 89 | - } |
|
| 84 | + if(! isset($this->markersMemory[$endMarkerName])){ |
|
| 85 | + $this->markersMemory[$endMarkerName] = microtime(true); |
|
| 86 | + } |
|
| 87 | + return number_format($this->markersMemory[$endMarkerName] - $this->markersMemory[$startMarkerName], $decimalCount); |
|
| 88 | + } |
|
| 89 | + } |
|
@@ -1,168 +1,168 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @file Assets.php |
|
| 29 | - * |
|
| 30 | - * This class contains static methods for generating static content links (images, Javascript, CSS, etc.). |
|
| 31 | - * |
|
| 32 | - * @package core |
|
| 33 | - * @author Tony NGUEREZA |
|
| 34 | - * @copyright Copyright (c) 2017 |
|
| 35 | - * @license https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL) |
|
| 36 | - * @link http://www.iacademy.cf |
|
| 37 | - * @version 1.0.0 |
|
| 38 | - * @since 1.0.0 |
|
| 39 | - * @filesource |
|
| 40 | - */ |
|
| 41 | - class Assets{ |
|
| 27 | + /** |
|
| 28 | + * @file Assets.php |
|
| 29 | + * |
|
| 30 | + * This class contains static methods for generating static content links (images, Javascript, CSS, etc.). |
|
| 31 | + * |
|
| 32 | + * @package core |
|
| 33 | + * @author Tony NGUEREZA |
|
| 34 | + * @copyright Copyright (c) 2017 |
|
| 35 | + * @license https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL) |
|
| 36 | + * @link http://www.iacademy.cf |
|
| 37 | + * @version 1.0.0 |
|
| 38 | + * @since 1.0.0 |
|
| 39 | + * @filesource |
|
| 40 | + */ |
|
| 41 | + class Assets{ |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * The logger instance |
|
| 45 | - * @var Log |
|
| 46 | - */ |
|
| 47 | - private static $logger; |
|
| 43 | + /** |
|
| 44 | + * The logger instance |
|
| 45 | + * @var Log |
|
| 46 | + */ |
|
| 47 | + private static $logger; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * The signleton of the logger |
|
| 51 | - * @return Object the Log instance |
|
| 52 | - */ |
|
| 53 | - private static function getLogger(){ |
|
| 54 | - if(self::$logger == null){ |
|
| 55 | - //can't assign reference to static variable |
|
| 56 | - self::$logger[0] =& class_loader('Log', 'classes'); |
|
| 57 | - self::$logger[0]->setLogger('Library::Assets'); |
|
| 58 | - } |
|
| 59 | - return self::$logger[0]; |
|
| 60 | - } |
|
| 49 | + /** |
|
| 50 | + * The signleton of the logger |
|
| 51 | + * @return Object the Log instance |
|
| 52 | + */ |
|
| 53 | + private static function getLogger(){ |
|
| 54 | + if(self::$logger == null){ |
|
| 55 | + //can't assign reference to static variable |
|
| 56 | + self::$logger[0] =& class_loader('Log', 'classes'); |
|
| 57 | + self::$logger[0]->setLogger('Library::Assets'); |
|
| 58 | + } |
|
| 59 | + return self::$logger[0]; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Generate the link of the assets file. |
|
| 65 | - * |
|
| 66 | - * Generates the absolute link of a file inside ASSETS_PATH folder. |
|
| 67 | - * For example : |
|
| 68 | - * echo Assets::path('foo/bar/css/style.css'); => http://mysite.com/assets/foo/bar/css/style.css |
|
| 69 | - * Note: |
|
| 70 | - * The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH. |
|
| 71 | - * |
|
| 72 | - * @param string $asset the name of the assets file path with the extension. |
|
| 73 | - * @return string|null the absolute path of the assets file, if it exists otherwise returns null if the file does not exist. |
|
| 74 | - */ |
|
| 75 | - public static function path($asset){ |
|
| 76 | - $logger = self::getLogger(); |
|
| 77 | - $path = ASSETS_PATH . $asset; |
|
| 63 | + /** |
|
| 64 | + * Generate the link of the assets file. |
|
| 65 | + * |
|
| 66 | + * Generates the absolute link of a file inside ASSETS_PATH folder. |
|
| 67 | + * For example : |
|
| 68 | + * echo Assets::path('foo/bar/css/style.css'); => http://mysite.com/assets/foo/bar/css/style.css |
|
| 69 | + * Note: |
|
| 70 | + * The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH. |
|
| 71 | + * |
|
| 72 | + * @param string $asset the name of the assets file path with the extension. |
|
| 73 | + * @return string|null the absolute path of the assets file, if it exists otherwise returns null if the file does not exist. |
|
| 74 | + */ |
|
| 75 | + public static function path($asset){ |
|
| 76 | + $logger = self::getLogger(); |
|
| 77 | + $path = ASSETS_PATH . $asset; |
|
| 78 | 78 | |
| 79 | - $logger->debug('Including the Assets file [' . $path . ']'); |
|
| 80 | - //Check if the file exists |
|
| 81 | - if(file_exists($path)){ |
|
| 82 | - $logger->info('Assets file [' . $path . '] included successfully'); |
|
| 83 | - return Url::base_url($path); |
|
| 84 | - } |
|
| 85 | - $logger->warning('Assets file [' . $path . '] does not exist'); |
|
| 86 | - return null; |
|
| 87 | - } |
|
| 79 | + $logger->debug('Including the Assets file [' . $path . ']'); |
|
| 80 | + //Check if the file exists |
|
| 81 | + if(file_exists($path)){ |
|
| 82 | + $logger->info('Assets file [' . $path . '] included successfully'); |
|
| 83 | + return Url::base_url($path); |
|
| 84 | + } |
|
| 85 | + $logger->warning('Assets file [' . $path . '] does not exist'); |
|
| 86 | + return null; |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Generate the link of the css file. |
|
| 91 | - * |
|
| 92 | - * Generates the absolute link of a file containing the CSS style. |
|
| 93 | - * For example : |
|
| 94 | - * echo Assets::css('mystyle'); => http://mysite.com/assets/css/mystyle.css |
|
| 95 | - * Note: |
|
| 96 | - * The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH. |
|
| 97 | - * |
|
| 98 | - * @param $path the name of the css file without the extension. |
|
| 99 | - * @return string|null the absolute path of the css file, if it exists otherwise returns null if the file does not exist. |
|
| 100 | - */ |
|
| 101 | - public static function css($path){ |
|
| 102 | - $logger = self::getLogger(); |
|
| 103 | - /* |
|
| 89 | + /** |
|
| 90 | + * Generate the link of the css file. |
|
| 91 | + * |
|
| 92 | + * Generates the absolute link of a file containing the CSS style. |
|
| 93 | + * For example : |
|
| 94 | + * echo Assets::css('mystyle'); => http://mysite.com/assets/css/mystyle.css |
|
| 95 | + * Note: |
|
| 96 | + * The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH. |
|
| 97 | + * |
|
| 98 | + * @param $path the name of the css file without the extension. |
|
| 99 | + * @return string|null the absolute path of the css file, if it exists otherwise returns null if the file does not exist. |
|
| 100 | + */ |
|
| 101 | + public static function css($path){ |
|
| 102 | + $logger = self::getLogger(); |
|
| 103 | + /* |
|
| 104 | 104 | * if the file name contains the ".css" extension, replace it with |
| 105 | 105 | * an empty string for better processing. |
| 106 | 106 | */ |
| 107 | - $path = str_ireplace('.css', '', $path); |
|
| 108 | - $path = ASSETS_PATH . 'css/' . $path . '.css'; |
|
| 107 | + $path = str_ireplace('.css', '', $path); |
|
| 108 | + $path = ASSETS_PATH . 'css/' . $path . '.css'; |
|
| 109 | 109 | |
| 110 | - $logger->debug('Including the Assets file [' . $path . '] for CSS'); |
|
| 111 | - //Check if the file exists |
|
| 112 | - if(file_exists($path)){ |
|
| 113 | - $logger->info('Assets file [' . $path . '] for CSS included successfully'); |
|
| 114 | - return Url::base_url($path); |
|
| 115 | - } |
|
| 116 | - $logger->warning('Assets file [' . $path . '] for CSS does not exist'); |
|
| 117 | - return null; |
|
| 118 | - } |
|
| 110 | + $logger->debug('Including the Assets file [' . $path . '] for CSS'); |
|
| 111 | + //Check if the file exists |
|
| 112 | + if(file_exists($path)){ |
|
| 113 | + $logger->info('Assets file [' . $path . '] for CSS included successfully'); |
|
| 114 | + return Url::base_url($path); |
|
| 115 | + } |
|
| 116 | + $logger->warning('Assets file [' . $path . '] for CSS does not exist'); |
|
| 117 | + return null; |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * Generate the link of the javascript file. |
|
| 122 | - * |
|
| 123 | - * Generates the absolute link of a file containing the javascript. |
|
| 124 | - * For example : |
|
| 125 | - * echo Assets::js('myscript'); => http://mysite.com/assets/js/myscript.js |
|
| 126 | - * Note: |
|
| 127 | - * The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH. |
|
| 128 | - * |
|
| 129 | - * @param $path the name of the javascript file without the extension. |
|
| 130 | - * @return string|null the absolute path of the javascript file, if it exists otherwise returns null if the file does not exist. |
|
| 131 | - */ |
|
| 132 | - public static function js($path){ |
|
| 133 | - $logger = self::getLogger(); |
|
| 134 | - $path = str_ireplace('.js', '', $path); |
|
| 135 | - $path = ASSETS_PATH . 'js/' . $path . '.js'; |
|
| 136 | - $logger->debug('Including the Assets file [' . $path . '] for javascript'); |
|
| 137 | - if(file_exists($path)){ |
|
| 138 | - $logger->info('Assets file [' . $path . '] for Javascript included successfully'); |
|
| 139 | - return Url::base_url($path); |
|
| 140 | - } |
|
| 141 | - $logger->warning('Assets file [' . $path . '] for Javascript does not exist'); |
|
| 142 | - return null; |
|
| 143 | - } |
|
| 120 | + /** |
|
| 121 | + * Generate the link of the javascript file. |
|
| 122 | + * |
|
| 123 | + * Generates the absolute link of a file containing the javascript. |
|
| 124 | + * For example : |
|
| 125 | + * echo Assets::js('myscript'); => http://mysite.com/assets/js/myscript.js |
|
| 126 | + * Note: |
|
| 127 | + * The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH. |
|
| 128 | + * |
|
| 129 | + * @param $path the name of the javascript file without the extension. |
|
| 130 | + * @return string|null the absolute path of the javascript file, if it exists otherwise returns null if the file does not exist. |
|
| 131 | + */ |
|
| 132 | + public static function js($path){ |
|
| 133 | + $logger = self::getLogger(); |
|
| 134 | + $path = str_ireplace('.js', '', $path); |
|
| 135 | + $path = ASSETS_PATH . 'js/' . $path . '.js'; |
|
| 136 | + $logger->debug('Including the Assets file [' . $path . '] for javascript'); |
|
| 137 | + if(file_exists($path)){ |
|
| 138 | + $logger->info('Assets file [' . $path . '] for Javascript included successfully'); |
|
| 139 | + return Url::base_url($path); |
|
| 140 | + } |
|
| 141 | + $logger->warning('Assets file [' . $path . '] for Javascript does not exist'); |
|
| 142 | + return null; |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - /** |
|
| 146 | - * Generate the link of the image file. |
|
| 147 | - * |
|
| 148 | - * Generates the absolute link of a file containing the image. |
|
| 149 | - * For example : |
|
| 150 | - * echo Assets::img('myimage.png'); => http://mysite.com/assets/images/myimage.png |
|
| 151 | - * Note: |
|
| 152 | - * The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH. |
|
| 153 | - * |
|
| 154 | - * @param $path the name of the image file with the extension. |
|
| 155 | - * @return string|null the absolute path of the image file, if it exists otherwise returns null if the file does not exist. |
|
| 156 | - */ |
|
| 157 | - public static function img($path){ |
|
| 158 | - $logger = self::getLogger(); |
|
| 159 | - $path = ASSETS_PATH . 'images/' . $path; |
|
| 160 | - $logger->debug('Including the Assets file [' . $path . '] for image'); |
|
| 161 | - if(file_exists($path)){ |
|
| 162 | - $logger->info('Assets file [' . $path . '] for image included successfully'); |
|
| 163 | - return Url::base_url($path); |
|
| 164 | - } |
|
| 165 | - $logger->warning('Assets file [' . $path . '] for image does not exist'); |
|
| 166 | - return null; |
|
| 167 | - } |
|
| 168 | - } |
|
| 145 | + /** |
|
| 146 | + * Generate the link of the image file. |
|
| 147 | + * |
|
| 148 | + * Generates the absolute link of a file containing the image. |
|
| 149 | + * For example : |
|
| 150 | + * echo Assets::img('myimage.png'); => http://mysite.com/assets/images/myimage.png |
|
| 151 | + * Note: |
|
| 152 | + * The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH. |
|
| 153 | + * |
|
| 154 | + * @param $path the name of the image file with the extension. |
|
| 155 | + * @return string|null the absolute path of the image file, if it exists otherwise returns null if the file does not exist. |
|
| 156 | + */ |
|
| 157 | + public static function img($path){ |
|
| 158 | + $logger = self::getLogger(); |
|
| 159 | + $path = ASSETS_PATH . 'images/' . $path; |
|
| 160 | + $logger->debug('Including the Assets file [' . $path . '] for image'); |
|
| 161 | + if(file_exists($path)){ |
|
| 162 | + $logger->info('Assets file [' . $path . '] for image included successfully'); |
|
| 163 | + return Url::base_url($path); |
|
| 164 | + } |
|
| 165 | + $logger->warning('Assets file [' . $path . '] for image does not exist'); |
|
| 166 | + return null; |
|
| 167 | + } |
|
| 168 | + } |
|
@@ -1,32 +1,32 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | defined('ROOT_PATH') || exit('Access denied'); |
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | 27 | class Pagination{ |
| 28 | 28 | |
| 29 | - /** |
|
| 29 | + /** |
|
| 30 | 30 | * The list of loaded config |
| 31 | 31 | * @var array |
| 32 | 32 | */ |
@@ -43,15 +43,15 @@ discard block |
||
| 43 | 43 | if(empty($config) || ! is_array($config)){ |
| 44 | 44 | show_error('No configuration found in ' . CONFIG_PATH . 'config_pagination.php'); |
| 45 | 45 | } |
| 46 | - else{ |
|
| 47 | - if(! empty($overwriteConfig)){ |
|
| 48 | - $config = array_merge($config, $overwriteConfig); |
|
| 49 | - } |
|
| 50 | - $this->config = $config; |
|
| 46 | + else{ |
|
| 47 | + if(! empty($overwriteConfig)){ |
|
| 48 | + $config = array_merge($config, $overwriteConfig); |
|
| 49 | + } |
|
| 50 | + $this->config = $config; |
|
| 51 | 51 | //put it gobally |
| 52 | - Config::setAll($config); |
|
| 53 | - unset($config); |
|
| 54 | - } |
|
| 52 | + Config::setAll($config); |
|
| 53 | + unset($config); |
|
| 54 | + } |
|
| 55 | 55 | } |
| 56 | 56 | else{ |
| 57 | 57 | show_error('Unable to find the pagination configuration file'); |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | public function getLink($totalRows, $currentPageNumber){ |
| 81 | 81 | $pageQueryName = $this->config['page_query_string_name']; |
| 82 | 82 | $numberOfLink = $this->config['nb_link']; |
| 83 | - $numberOfRowPerPage = $this->config['pagination_per_page']; |
|
| 83 | + $numberOfRowPerPage = $this->config['pagination_per_page']; |
|
| 84 | 84 | $queryString = Url::queryString(); |
| 85 | 85 | $currentUrl = Url::current(); |
| 86 | 86 | if($queryString == ''){ |
@@ -106,9 +106,9 @@ discard block |
||
| 106 | 106 | $navbar = ''; |
| 107 | 107 | $numberOfPage = ceil($totalRows / $numberOfRowPerPage); |
| 108 | 108 | $currentPageNumber = (int) $currentPageNumber; |
| 109 | - if($currentPageNumber <= 0){ |
|
| 110 | - $currentPageNumber = 1; |
|
| 111 | - } |
|
| 109 | + if($currentPageNumber <= 0){ |
|
| 110 | + $currentPageNumber = 1; |
|
| 111 | + } |
|
| 112 | 112 | if($numberOfPage <= 1 || $numberOfLink <= 0 || $numberOfRowPerPage <= 0 || !is_numeric($numberOfLink) || !is_numeric($numberOfRowPerPage) |
| 113 | 113 | ){ |
| 114 | 114 | return $navbar; |
@@ -22,10 +22,10 @@ discard block |
||
| 22 | 22 | * You should have received a copy of the GNU General Public License |
| 23 | 23 | * along with this program; if not, write to the Free Software |
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | - */ |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | - class FormValidation{ |
|
| 28 | + class FormValidation{ |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * The form validation status |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | */ |
| 61 | 61 | protected $_eachErrorDelimiter = array('<p class="error">', '</p>'); |
| 62 | 62 | |
| 63 | - /** |
|
| 63 | + /** |
|
| 64 | 64 | * Indicated if need force the validation to be failed |
| 65 | 65 | * @var boolean |
| 66 | 66 | */ |
@@ -86,8 +86,8 @@ discard block |
||
| 86 | 86 | |
| 87 | 87 | /** |
| 88 | 88 | * Whether to check the CSRF. This attribute is just a way to allow custom change of the |
| 89 | - * CSRF global configuration |
|
| 90 | - * |
|
| 89 | + * CSRF global configuration |
|
| 90 | + * |
|
| 91 | 91 | * @var boolean |
| 92 | 92 | */ |
| 93 | 93 | public $enableCsrfCheck = false; |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | $this->logger =& class_loader('Log', 'classes'); |
| 102 | 102 | $this->logger->setLogger('Library::FormValidation'); |
| 103 | 103 | |
| 104 | - //Load form validation language message |
|
| 104 | + //Load form validation language message |
|
| 105 | 105 | Loader::lang('form_validation'); |
| 106 | 106 | $obj = & get_instance(); |
| 107 | 107 | $this->_errorsMessages = array( |
@@ -141,19 +141,19 @@ discard block |
||
| 141 | 141 | $this->_success = false; |
| 142 | 142 | $this->_forceFail = false; |
| 143 | 143 | $this->data = array(); |
| 144 | - $this->enableCsrfCheck = false; |
|
| 144 | + $this->enableCsrfCheck = false; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | /** |
| 148 | 148 | * Set the form validation data |
| 149 | 149 | * @param array $data the values to be validated |
| 150 | - * |
|
| 150 | + * |
|
| 151 | 151 | * @return FormValidation Current instance of object. |
| 152 | 152 | */ |
| 153 | 153 | public function setData(array $data){ |
| 154 | 154 | $this->logger->debug('Setting the form validation data, the values are: ' . stringfy_vars($data)); |
| 155 | 155 | $this->data = $data; |
| 156 | - return $this; |
|
| 156 | + return $this; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -164,11 +164,11 @@ discard block |
||
| 164 | 164 | return $this->data; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * Get the validation function name to validate a rule |
|
| 169 | - * |
|
| 170 | - * @return string the function name |
|
| 171 | - */ |
|
| 167 | + /** |
|
| 168 | + * Get the validation function name to validate a rule |
|
| 169 | + * |
|
| 170 | + * @return string the function name |
|
| 171 | + */ |
|
| 172 | 172 | protected function _toCallCase($funcName, $prefix='_validate') { |
| 173 | 173 | $funcName = strtolower($funcName); |
| 174 | 174 | $finalFuncName = $prefix; |
@@ -238,12 +238,12 @@ discard block |
||
| 238 | 238 | $this->_forceFail = false; |
| 239 | 239 | |
| 240 | 240 | foreach ($this->getData() as $inputName => $inputVal) { |
| 241 | - if(is_array($this->data[$inputName])){ |
|
| 242 | - $this->data[$inputName] = array_map('trim', $this->data[$inputName]); |
|
| 243 | - } |
|
| 244 | - else{ |
|
| 245 | - $this->data[$inputName] = trim($this->data[$inputName]); |
|
| 246 | - } |
|
| 241 | + if(is_array($this->data[$inputName])){ |
|
| 242 | + $this->data[$inputName] = array_map('trim', $this->data[$inputName]); |
|
| 243 | + } |
|
| 244 | + else{ |
|
| 245 | + $this->data[$inputName] = trim($this->data[$inputName]); |
|
| 246 | + } |
|
| 247 | 247 | |
| 248 | 248 | if (array_key_exists($inputName, $this->_rules)) { |
| 249 | 249 | foreach ($this->_parseRuleString($this->_rules[$inputName]) as $eachRule) { |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | * |
| 263 | 263 | * @param string $inputField Name of the field or the data key to add a rule to |
| 264 | 264 | * @param string $ruleSets PIPE seperated string of rules |
| 265 | - * |
|
| 265 | + * |
|
| 266 | 266 | * @return FormValidation Current instance of object. |
| 267 | 267 | */ |
| 268 | 268 | public function setRule($inputField, $inputLabel, $ruleSets) { |
@@ -276,8 +276,8 @@ discard block |
||
| 276 | 276 | * Takes an array of rules and uses setRule() to set them, accepts an array |
| 277 | 277 | * of rule names rather than a pipe-delimited string as well. |
| 278 | 278 | * @param array $ruleSets |
| 279 | - * |
|
| 280 | - * @return FormValidation Current instance of object. |
|
| 279 | + * |
|
| 280 | + * @return FormValidation Current instance of object. |
|
| 281 | 281 | */ |
| 282 | 282 | public function setRules(array $ruleSets) { |
| 283 | 283 | foreach ($ruleSets as $ruleSet) { |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | * @param string $start Before block of errors gets displayed, HTML allowed. |
| 300 | 300 | * @param string $end After the block of errors gets displayed, HTML allowed. |
| 301 | 301 | * |
| 302 | - * @return FormValidation Current instance of object. |
|
| 302 | + * @return FormValidation Current instance of object. |
|
| 303 | 303 | */ |
| 304 | 304 | public function setErrorsDelimiter($start, $end) { |
| 305 | 305 | $this->_allErrorsDelimiter[0] = $start; |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | * @param string $start Displayed before each error. |
| 315 | 315 | * @param string $end Displayed after each error. |
| 316 | 316 | * |
| 317 | - * @return FormValidation Current instance of object. |
|
| 317 | + * @return FormValidation Current instance of object. |
|
| 318 | 318 | */ |
| 319 | 319 | public function setErrorDelimiter($start, $end) { |
| 320 | 320 | $this->_eachErrorDelimiter[0] = $start; |
@@ -322,21 +322,21 @@ discard block |
||
| 322 | 322 | return $this; |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | - /** |
|
| 326 | - * Get the each errors delimiters |
|
| 327 | - * |
|
| 328 | - * @return array |
|
| 329 | - */ |
|
| 330 | - public function getErrorDelimiter() { |
|
| 325 | + /** |
|
| 326 | + * Get the each errors delimiters |
|
| 327 | + * |
|
| 328 | + * @return array |
|
| 329 | + */ |
|
| 330 | + public function getErrorDelimiter() { |
|
| 331 | 331 | return $this->_eachErrorDelimiter; |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | - /** |
|
| 335 | - * Get the all errors delimiters |
|
| 336 | - * |
|
| 337 | - * @return array |
|
| 338 | - */ |
|
| 339 | - public function getErrorsDelimiter() { |
|
| 334 | + /** |
|
| 335 | + * Get the all errors delimiters |
|
| 336 | + * |
|
| 337 | + * @return array |
|
| 338 | + */ |
|
| 339 | + public function getErrorsDelimiter() { |
|
| 340 | 340 | return $this->_allErrorsDelimiter; |
| 341 | 341 | } |
| 342 | 342 | |
@@ -374,7 +374,7 @@ discard block |
||
| 374 | 374 | * |
| 375 | 375 | * @param string $inputName The form input name or data key |
| 376 | 376 | * @param string $errorMessage Error to display |
| 377 | - * |
|
| 377 | + * |
|
| 378 | 378 | * @return formValidation Current instance of the object |
| 379 | 379 | */ |
| 380 | 380 | public function setCustomError($inputName, $errorMessage) { |
@@ -411,17 +411,17 @@ discard block |
||
| 411 | 411 | * |
| 412 | 412 | * @param boolean $limit number of error to display or return |
| 413 | 413 | * @param boolean $echo Whether or not the values are to be returned or displayed |
| 414 | - * |
|
| 414 | + * |
|
| 415 | 415 | * @return string Errors formatted for output |
| 416 | 416 | */ |
| 417 | 417 | public function displayErrors($limit = null, $echo = true) { |
| 418 | 418 | list($errorsStart, $errorsEnd) = $this->_allErrorsDelimiter; |
| 419 | 419 | list($errorStart, $errorEnd) = $this->_eachErrorDelimiter; |
| 420 | 420 | $errorOutput = $errorsStart; |
| 421 | - $i = 0; |
|
| 421 | + $i = 0; |
|
| 422 | 422 | if (!empty($this->_errors)) { |
| 423 | 423 | foreach ($this->_errors as $fieldName => $error) { |
| 424 | - if ($i === $limit) { |
|
| 424 | + if ($i === $limit) { |
|
| 425 | 425 | break; |
| 426 | 426 | } |
| 427 | 427 | $errorOutput .= $errorStart; |
@@ -449,7 +449,7 @@ discard block |
||
| 449 | 449 | * Breaks up a PIPE seperated string of rules, and puts them into an array. |
| 450 | 450 | * |
| 451 | 451 | * @param string $ruleString String to be parsed. |
| 452 | - * |
|
| 452 | + * |
|
| 453 | 453 | * @return array Array of each value in original string. |
| 454 | 454 | */ |
| 455 | 455 | protected function _parseRuleString($ruleString) { |
@@ -462,10 +462,10 @@ discard block |
||
| 462 | 462 | $rule = '#regex\[\/(.*)\/([a-zA-Z0-9]?)\]#'; |
| 463 | 463 | preg_match($rule, $ruleString, $regexRule); |
| 464 | 464 | $ruleStringTemp = preg_replace($rule, '', $ruleString); |
| 465 | - if(!empty($regexRule[0])){ |
|
| 466 | - $ruleSets[] = $regexRule[0]; |
|
| 467 | - } |
|
| 468 | - $ruleStringRegex = explode('|', $ruleStringTemp); |
|
| 465 | + if(!empty($regexRule[0])){ |
|
| 466 | + $ruleSets[] = $regexRule[0]; |
|
| 467 | + } |
|
| 468 | + $ruleStringRegex = explode('|', $ruleStringTemp); |
|
| 469 | 469 | foreach ($ruleStringRegex as $rule) { |
| 470 | 470 | $rule = trim($rule); |
| 471 | 471 | if($rule){ |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | } else { |
| 482 | 482 | $ruleSets[] = $ruleString; |
| 483 | 483 | } |
| 484 | - } |
|
| 484 | + } |
|
| 485 | 485 | return $ruleSets; |
| 486 | 486 | } |
| 487 | 487 | |
@@ -489,7 +489,7 @@ discard block |
||
| 489 | 489 | * Returns whether or not a field obtains the rule "required". |
| 490 | 490 | * |
| 491 | 491 | * @param string $fieldName Field to check if required. |
| 492 | - * |
|
| 492 | + * |
|
| 493 | 493 | * @return boolean Whether or not the field is required. |
| 494 | 494 | */ |
| 495 | 495 | protected function _fieldIsRequired($fieldName) { |
@@ -524,13 +524,13 @@ discard block |
||
| 524 | 524 | return; |
| 525 | 525 | } |
| 526 | 526 | |
| 527 | - /** |
|
| 528 | - * Set error for the given field or key |
|
| 529 | - * |
|
| 530 | - * @param string $inputName the input or key name |
|
| 531 | - * @param string $ruleName the rule name |
|
| 532 | - * @param array|string $replacements |
|
| 533 | - */ |
|
| 527 | + /** |
|
| 528 | + * Set error for the given field or key |
|
| 529 | + * |
|
| 530 | + * @param string $inputName the input or key name |
|
| 531 | + * @param string $ruleName the rule name |
|
| 532 | + * @param array|string $replacements |
|
| 533 | + */ |
|
| 534 | 534 | protected function _setError($inputName, $ruleName, $replacements = array()) { |
| 535 | 535 | $rulePhraseKeyParts = explode(',', $ruleName); |
| 536 | 536 | $rulePhrase = null; |
@@ -547,7 +547,7 @@ discard block |
||
| 547 | 547 | } |
| 548 | 548 | // Type cast to array in case it's a string |
| 549 | 549 | $replacements = (array) $replacements; |
| 550 | - $replacementCount = count($replacements); |
|
| 550 | + $replacementCount = count($replacements); |
|
| 551 | 551 | for ($i = 1; $i <= $replacementCount; $i++) { |
| 552 | 552 | $key = $i - 1; |
| 553 | 553 | $rulePhrase = str_replace('%' . $i, $replacements[$key], $rulePhrase); |
@@ -565,11 +565,11 @@ discard block |
||
| 565 | 565 | * |
| 566 | 566 | * @param type $inputArg |
| 567 | 567 | * @param string $callbackFunc |
| 568 | - * |
|
| 568 | + * |
|
| 569 | 569 | * @return mixed |
| 570 | 570 | */ |
| 571 | 571 | protected function _runCallback($inputArg, $callbackFunc) { |
| 572 | - return eval('return ' . $callbackFunc . '("' . $inputArg . '");'); |
|
| 572 | + return eval('return ' . $callbackFunc . '("' . $inputArg . '");'); |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | /** |
@@ -578,7 +578,7 @@ discard block |
||
| 578 | 578 | * arguments. |
| 579 | 579 | * |
| 580 | 580 | * @param string $callbackFunc |
| 581 | - * |
|
| 581 | + * |
|
| 582 | 582 | * @return mixed |
| 583 | 583 | */ |
| 584 | 584 | protected function _runEmptyCallback($callbackFunc) { |
@@ -589,7 +589,7 @@ discard block |
||
| 589 | 589 | * Gets a specific label of a specific field input name. |
| 590 | 590 | * |
| 591 | 591 | * @param string $inputName |
| 592 | - * |
|
| 592 | + * |
|
| 593 | 593 | * @return string |
| 594 | 594 | */ |
| 595 | 595 | protected function _getLabel($inputName) { |
@@ -602,7 +602,7 @@ discard block |
||
| 602 | 602 | * @param string $ruleName the rule name for this validation ("required") |
| 603 | 603 | * @param array $ruleArgs the rules argument |
| 604 | 604 | */ |
| 605 | - protected function _validateRequired($inputName, $ruleName, array $ruleArgs) { |
|
| 605 | + protected function _validateRequired($inputName, $ruleName, array $ruleArgs) { |
|
| 606 | 606 | $inputVal = $this->post($inputName); |
| 607 | 607 | if(array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) { |
| 608 | 608 | $callbackReturn = $this->_runEmptyCallback($ruleArgs[1]); |
@@ -610,8 +610,8 @@ discard block |
||
| 610 | 610 | $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
| 611 | 611 | } |
| 612 | 612 | } |
| 613 | - else if($inputVal == '') { |
|
| 614 | - $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
|
| 613 | + else if($inputVal == '') { |
|
| 614 | + $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
|
| 615 | 615 | } |
| 616 | 616 | } |
| 617 | 617 | |
@@ -635,10 +635,10 @@ discard block |
||
| 635 | 635 | */ |
| 636 | 636 | protected function _validateCallback($inputName, $ruleName, array $ruleArgs) { |
| 637 | 637 | if (function_exists($ruleArgs[1]) && !empty($this->data[$inputName])) { |
| 638 | - $result = $this->_runCallback($this->data[$inputName], $ruleArgs[1]); |
|
| 639 | - if(! $result){ |
|
| 640 | - $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
|
| 641 | - } |
|
| 638 | + $result = $this->_runCallback($this->data[$inputName], $ruleArgs[1]); |
|
| 639 | + if(! $result){ |
|
| 640 | + $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
|
| 641 | + } |
|
| 642 | 642 | } |
| 643 | 643 | } |
| 644 | 644 | |
@@ -670,7 +670,7 @@ discard block |
||
| 670 | 670 | continue; |
| 671 | 671 | } |
| 672 | 672 | } |
| 673 | - else{ |
|
| 673 | + else{ |
|
| 674 | 674 | if ($inputVal == $doNotEqual) { |
| 675 | 675 | $this->_setError($inputName, $ruleName . ',string', array($this->_getLabel($inputName), $doNotEqual)); |
| 676 | 676 | continue; |
@@ -762,7 +762,7 @@ discard block |
||
| 762 | 762 | * @param string $ruleName the rule name for this validation ("less_than") |
| 763 | 763 | * @param array $ruleArgs the rules argument |
| 764 | 764 | */ |
| 765 | - protected function _validateLessThan($inputName, $ruleName, array $ruleArgs) { |
|
| 765 | + protected function _validateLessThan($inputName, $ruleName, array $ruleArgs) { |
|
| 766 | 766 | $inputVal = $this->post($inputName); |
| 767 | 767 | if ($inputVal >= $ruleArgs[1]) { |
| 768 | 768 | if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
@@ -778,7 +778,7 @@ discard block |
||
| 778 | 778 | * @param string $ruleName the rule name for this validation ("greater_than") |
| 779 | 779 | * @param array $ruleArgs the rules argument |
| 780 | 780 | */ |
| 781 | - protected function _validateGreaterThan($inputName, $ruleName, array $ruleArgs) { |
|
| 781 | + protected function _validateGreaterThan($inputName, $ruleName, array $ruleArgs) { |
|
| 782 | 782 | $inputVal = $this->post($inputName); |
| 783 | 783 | if ($inputVal <= $ruleArgs[1]) { |
| 784 | 784 | if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
@@ -794,7 +794,7 @@ discard block |
||
| 794 | 794 | * @param string $ruleName the rule name for this validation ("numeric") |
| 795 | 795 | * @param array $ruleArgs the rules argument |
| 796 | 796 | */ |
| 797 | - protected function _validateNumeric($inputName, $ruleName, array $ruleArgs) { |
|
| 797 | + protected function _validateNumeric($inputName, $ruleName, array $ruleArgs) { |
|
| 798 | 798 | $inputVal = $this->post($inputName); |
| 799 | 799 | if (! is_numeric($inputVal)) { |
| 800 | 800 | if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
@@ -810,17 +810,17 @@ discard block |
||
| 810 | 810 | * @param string $ruleName the rule name for this validation ("exists") |
| 811 | 811 | * @param array $ruleArgs the rules argument |
| 812 | 812 | */ |
| 813 | - protected function _validateExists($inputName, $ruleName, array $ruleArgs) { |
|
| 813 | + protected function _validateExists($inputName, $ruleName, array $ruleArgs) { |
|
| 814 | 814 | $inputVal = $this->post($inputName); |
| 815 | - $obj = & get_instance(); |
|
| 816 | - if(! isset($obj->database)){ |
|
| 817 | - return; |
|
| 818 | - } |
|
| 819 | - list($table, $column) = explode('.', $ruleArgs[1]); |
|
| 820 | - $obj->database->from($table) |
|
| 821 | - ->where($column, $inputVal) |
|
| 822 | - ->get(); |
|
| 823 | - $nb = $obj->database->numRows(); |
|
| 815 | + $obj = & get_instance(); |
|
| 816 | + if(! isset($obj->database)){ |
|
| 817 | + return; |
|
| 818 | + } |
|
| 819 | + list($table, $column) = explode('.', $ruleArgs[1]); |
|
| 820 | + $obj->database->from($table) |
|
| 821 | + ->where($column, $inputVal) |
|
| 822 | + ->get(); |
|
| 823 | + $nb = $obj->database->numRows(); |
|
| 824 | 824 | if ($nb == 0) { |
| 825 | 825 | if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
| 826 | 826 | return; |
@@ -835,17 +835,17 @@ discard block |
||
| 835 | 835 | * @param string $ruleName the rule name for this validation ("is_unique") |
| 836 | 836 | * @param array $ruleArgs the rules argument |
| 837 | 837 | */ |
| 838 | - protected function _validateIsUnique($inputName, $ruleName, array $ruleArgs) { |
|
| 838 | + protected function _validateIsUnique($inputName, $ruleName, array $ruleArgs) { |
|
| 839 | 839 | $inputVal = $this->post($inputName); |
| 840 | - $obj = & get_instance(); |
|
| 841 | - if(! isset($obj->database)){ |
|
| 842 | - return; |
|
| 843 | - } |
|
| 844 | - list($table, $column) = explode('.', $ruleArgs[1]); |
|
| 845 | - $obj->database->from($table) |
|
| 846 | - ->where($column, $inputVal) |
|
| 847 | - ->get(); |
|
| 848 | - $nb = $obj->database->numRows(); |
|
| 840 | + $obj = & get_instance(); |
|
| 841 | + if(! isset($obj->database)){ |
|
| 842 | + return; |
|
| 843 | + } |
|
| 844 | + list($table, $column) = explode('.', $ruleArgs[1]); |
|
| 845 | + $obj->database->from($table) |
|
| 846 | + ->where($column, $inputVal) |
|
| 847 | + ->get(); |
|
| 848 | + $nb = $obj->database->numRows(); |
|
| 849 | 849 | if ($nb != 0) { |
| 850 | 850 | if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
| 851 | 851 | return; |
@@ -860,23 +860,23 @@ discard block |
||
| 860 | 860 | * @param string $ruleName the rule name for this validation ("is_unique_update") |
| 861 | 861 | * @param array $ruleArgs the rules argument |
| 862 | 862 | */ |
| 863 | - protected function _validateIsUniqueUpdate($inputName, $ruleName, array $ruleArgs) { |
|
| 863 | + protected function _validateIsUniqueUpdate($inputName, $ruleName, array $ruleArgs) { |
|
| 864 | 864 | $inputVal = $this->post($inputName); |
| 865 | - $obj = & get_instance(); |
|
| 866 | - if(! isset($obj->database)){ |
|
| 867 | - return; |
|
| 868 | - } |
|
| 869 | - $data = explode(',', $ruleArgs[1]); |
|
| 870 | - if(count($data) < 2){ |
|
| 871 | - return; |
|
| 872 | - } |
|
| 873 | - list($table, $column) = explode('.', $data[0]); |
|
| 874 | - list($field, $val) = explode('=', $data[1]); |
|
| 875 | - $obj->database->from($table) |
|
| 876 | - ->where($column, $inputVal) |
|
| 877 | - ->where($field, '!=', trim($val)) |
|
| 878 | - ->get(); |
|
| 879 | - $nb = $obj->database->numRows(); |
|
| 865 | + $obj = & get_instance(); |
|
| 866 | + if(! isset($obj->database)){ |
|
| 867 | + return; |
|
| 868 | + } |
|
| 869 | + $data = explode(',', $ruleArgs[1]); |
|
| 870 | + if(count($data) < 2){ |
|
| 871 | + return; |
|
| 872 | + } |
|
| 873 | + list($table, $column) = explode('.', $data[0]); |
|
| 874 | + list($field, $val) = explode('=', $data[1]); |
|
| 875 | + $obj->database->from($table) |
|
| 876 | + ->where($column, $inputVal) |
|
| 877 | + ->where($field, '!=', trim($val)) |
|
| 878 | + ->get(); |
|
| 879 | + $nb = $obj->database->numRows(); |
|
| 880 | 880 | if ($nb != 0) { |
| 881 | 881 | if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
| 882 | 882 | return; |
@@ -893,7 +893,7 @@ discard block |
||
| 893 | 893 | */ |
| 894 | 894 | protected function _validateInList($inputName, $ruleName, array $ruleArgs) { |
| 895 | 895 | $inputVal = $this->post($inputName); |
| 896 | - $list = explode(',', $ruleArgs[1]); |
|
| 896 | + $list = explode(',', $ruleArgs[1]); |
|
| 897 | 897 | $list = array_map('trim', $list); |
| 898 | 898 | if (! in_array($inputVal, $list)) { |
| 899 | 899 | if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
@@ -911,7 +911,7 @@ discard block |
||
| 911 | 911 | */ |
| 912 | 912 | protected function _validateRegex($inputName, $ruleName, array $ruleArgs) { |
| 913 | 913 | $inputVal = $this->post($inputName); |
| 914 | - $regex = $ruleArgs[1]; |
|
| 914 | + $regex = $ruleArgs[1]; |
|
| 915 | 915 | if (! preg_match($regex, $inputVal)) { |
| 916 | 916 | if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
| 917 | 917 | return; |
@@ -1,87 +1,87 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') or exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 2 | + defined('ROOT_PATH') or exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * PDF library to generate PDF document using the library DOMPDF |
|
| 29 | - */ |
|
| 30 | - class PDF{ |
|
| 27 | + /** |
|
| 28 | + * PDF library to generate PDF document using the library DOMPDF |
|
| 29 | + */ |
|
| 30 | + class PDF{ |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * The dompdf instance |
|
| 34 | - * @var Dompdf |
|
| 35 | - */ |
|
| 36 | - private $dompdf = null; |
|
| 32 | + /** |
|
| 33 | + * The dompdf instance |
|
| 34 | + * @var Dompdf |
|
| 35 | + */ |
|
| 36 | + private $dompdf = null; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * The logger instance |
|
| 40 | - * @var Log |
|
| 41 | - */ |
|
| 42 | - private $logger; |
|
| 38 | + /** |
|
| 39 | + * The logger instance |
|
| 40 | + * @var Log |
|
| 41 | + */ |
|
| 42 | + private $logger; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Create PDF library instance |
|
| 46 | - */ |
|
| 47 | - public function __construct(){ |
|
| 48 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 49 | - $this->logger->setLogger('Library::PDF'); |
|
| 44 | + /** |
|
| 45 | + * Create PDF library instance |
|
| 46 | + */ |
|
| 47 | + public function __construct(){ |
|
| 48 | + $this->logger =& class_loader('Log', 'classes'); |
|
| 49 | + $this->logger->setLogger('Library::PDF'); |
|
| 50 | 50 | |
| 51 | - require_once VENDOR_PATH.'dompdf/dompdf_config.inc.php'; |
|
| 52 | - $this->dompdf = new Dompdf(); |
|
| 53 | - } |
|
| 51 | + require_once VENDOR_PATH.'dompdf/dompdf_config.inc.php'; |
|
| 52 | + $this->dompdf = new Dompdf(); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Generate PDF document |
|
| 57 | - * @param string $html the HTML content to use for generation |
|
| 58 | - * @param string $filename the generated PDF document filename |
|
| 59 | - * @param boolean $stream if need send the generated PDF to browser for download |
|
| 60 | - * @param string $paper the PDF document paper type like 'A4', 'A5', 'letter', etc. |
|
| 61 | - * @param string $orientation the PDF document orientation like 'portrait', 'landscape' |
|
| 62 | - * @return string|void if $stream is true send PDF document to browser for download, else return the generated PDF |
|
| 63 | - * content like to join in Email attachment of for other purpose use. |
|
| 64 | - */ |
|
| 65 | - public function generate($html, $filename = 'output.pdf', $stream = true, $paper = 'A4', $orientation = 'portrait'){ |
|
| 66 | - $this->logger->info('Generating of PDF document: filename [' .$filename. '], stream [' .($stream ? 'TRUE':'FALSE'). '], paper [' .$paper. '], orientation [' .$orientation. ']'); |
|
| 67 | - $this->dompdf->load_html($html); |
|
| 68 | - $this->dompdf->set_paper($paper, $orientation); |
|
| 69 | - $this->dompdf->render(); |
|
| 70 | - if($stream){ |
|
| 71 | - $this->dompdf->stream($filename); |
|
| 72 | - } |
|
| 73 | - else{ |
|
| 74 | - return $this->dompdf->output(); |
|
| 75 | - } |
|
| 76 | - } |
|
| 55 | + /** |
|
| 56 | + * Generate PDF document |
|
| 57 | + * @param string $html the HTML content to use for generation |
|
| 58 | + * @param string $filename the generated PDF document filename |
|
| 59 | + * @param boolean $stream if need send the generated PDF to browser for download |
|
| 60 | + * @param string $paper the PDF document paper type like 'A4', 'A5', 'letter', etc. |
|
| 61 | + * @param string $orientation the PDF document orientation like 'portrait', 'landscape' |
|
| 62 | + * @return string|void if $stream is true send PDF document to browser for download, else return the generated PDF |
|
| 63 | + * content like to join in Email attachment of for other purpose use. |
|
| 64 | + */ |
|
| 65 | + public function generate($html, $filename = 'output.pdf', $stream = true, $paper = 'A4', $orientation = 'portrait'){ |
|
| 66 | + $this->logger->info('Generating of PDF document: filename [' .$filename. '], stream [' .($stream ? 'TRUE':'FALSE'). '], paper [' .$paper. '], orientation [' .$orientation. ']'); |
|
| 67 | + $this->dompdf->load_html($html); |
|
| 68 | + $this->dompdf->set_paper($paper, $orientation); |
|
| 69 | + $this->dompdf->render(); |
|
| 70 | + if($stream){ |
|
| 71 | + $this->dompdf->stream($filename); |
|
| 72 | + } |
|
| 73 | + else{ |
|
| 74 | + return $this->dompdf->output(); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Return the instance of Dompdf |
|
| 80 | - * |
|
| 81 | - * @return object the dompdf instance |
|
| 82 | - */ |
|
| 83 | - public function getDompdf(){ |
|
| 84 | - return $this->dompdf; |
|
| 85 | - } |
|
| 78 | + /** |
|
| 79 | + * Return the instance of Dompdf |
|
| 80 | + * |
|
| 81 | + * @return object the dompdf instance |
|
| 82 | + */ |
|
| 83 | + public function getDompdf(){ |
|
| 84 | + return $this->dompdf; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - } |
|
| 87 | + } |
|
@@ -22,139 +22,139 @@ discard block |
||
| 22 | 22 | * You should have received a copy of the GNU General Public License |
| 23 | 23 | * along with this program; if not, write to the Free Software |
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | - */ |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | - * Upload |
|
| 31 | - * |
|
| 32 | - * A complete class to upload files with php 5 or higher, but the best: very simple to use. |
|
| 33 | - * |
|
| 34 | - * @author Olaf Erlandsen <[email protected]> |
|
| 35 | - * @author http://www.webdevfreelance.com/ |
|
| 36 | - * |
|
| 37 | - * @package FileUpload |
|
| 38 | - * @version 1.5 |
|
| 39 | - */ |
|
| 30 | + * Upload |
|
| 31 | + * |
|
| 32 | + * A complete class to upload files with php 5 or higher, but the best: very simple to use. |
|
| 33 | + * |
|
| 34 | + * @author Olaf Erlandsen <[email protected]> |
|
| 35 | + * @author http://www.webdevfreelance.com/ |
|
| 36 | + * |
|
| 37 | + * @package FileUpload |
|
| 38 | + * @version 1.5 |
|
| 39 | + */ |
|
| 40 | 40 | class Upload{ |
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | - * Version |
|
| 44 | - * |
|
| 45 | - * @since 1.5 |
|
| 46 | - * @version 1.0 |
|
| 47 | - */ |
|
| 43 | + * Version |
|
| 44 | + * |
|
| 45 | + * @since 1.5 |
|
| 46 | + * @version 1.0 |
|
| 47 | + */ |
|
| 48 | 48 | const VERSION = '1.5'; |
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | - * Upload function name |
|
| 52 | - * Remember: |
|
| 53 | - * Default function: move_uploaded_file |
|
| 54 | - * Native options: |
|
| 55 | - * - move_uploaded_file (Default and best option) |
|
| 56 | - * - copy |
|
| 57 | - * |
|
| 58 | - * @since 1.0 |
|
| 59 | - * @version 1.0 |
|
| 60 | - * @var string |
|
| 61 | - */ |
|
| 51 | + * Upload function name |
|
| 52 | + * Remember: |
|
| 53 | + * Default function: move_uploaded_file |
|
| 54 | + * Native options: |
|
| 55 | + * - move_uploaded_file (Default and best option) |
|
| 56 | + * - copy |
|
| 57 | + * |
|
| 58 | + * @since 1.0 |
|
| 59 | + * @version 1.0 |
|
| 60 | + * @var string |
|
| 61 | + */ |
|
| 62 | 62 | private $upload_function = 'move_uploaded_file'; |
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | - * Array with the information obtained from the |
|
| 66 | - * variable $_FILES or $HTTP_POST_FILES. |
|
| 67 | - * |
|
| 68 | - * @since 1.0 |
|
| 69 | - * @version 1.0 |
|
| 70 | - * @var array |
|
| 71 | - */ |
|
| 65 | + * Array with the information obtained from the |
|
| 66 | + * variable $_FILES or $HTTP_POST_FILES. |
|
| 67 | + * |
|
| 68 | + * @since 1.0 |
|
| 69 | + * @version 1.0 |
|
| 70 | + * @var array |
|
| 71 | + */ |
|
| 72 | 72 | private $file_array = array(); |
| 73 | 73 | |
| 74 | 74 | /** |
| 75 | - * If the file you are trying to upload already exists it will |
|
| 76 | - * be overwritten if you set the variable to true. |
|
| 77 | - * |
|
| 78 | - * @since 1.0 |
|
| 79 | - * @version 1.0 |
|
| 80 | - * @var boolean |
|
| 81 | - */ |
|
| 75 | + * If the file you are trying to upload already exists it will |
|
| 76 | + * be overwritten if you set the variable to true. |
|
| 77 | + * |
|
| 78 | + * @since 1.0 |
|
| 79 | + * @version 1.0 |
|
| 80 | + * @var boolean |
|
| 81 | + */ |
|
| 82 | 82 | private $overwrite_file = false; |
| 83 | 83 | |
| 84 | 84 | /** |
| 85 | - * Input element |
|
| 86 | - * Example: |
|
| 87 | - * <input type="file" name="file" /> |
|
| 88 | - * Result: |
|
| 89 | - * FileUpload::$input = file |
|
| 90 | - * |
|
| 91 | - * @since 1.0 |
|
| 92 | - * @version 1.0 |
|
| 93 | - * @var string |
|
| 94 | - */ |
|
| 85 | + * Input element |
|
| 86 | + * Example: |
|
| 87 | + * <input type="file" name="file" /> |
|
| 88 | + * Result: |
|
| 89 | + * FileUpload::$input = file |
|
| 90 | + * |
|
| 91 | + * @since 1.0 |
|
| 92 | + * @version 1.0 |
|
| 93 | + * @var string |
|
| 94 | + */ |
|
| 95 | 95 | private $input; |
| 96 | 96 | |
| 97 | 97 | /** |
| 98 | - * Path output |
|
| 99 | - * |
|
| 100 | - * @since 1.0 |
|
| 101 | - * @version 1.0 |
|
| 102 | - * @var string |
|
| 103 | - */ |
|
| 98 | + * Path output |
|
| 99 | + * |
|
| 100 | + * @since 1.0 |
|
| 101 | + * @version 1.0 |
|
| 102 | + * @var string |
|
| 103 | + */ |
|
| 104 | 104 | private $destination_directory; |
| 105 | 105 | |
| 106 | 106 | /** |
| 107 | - * Output filename |
|
| 108 | - * |
|
| 109 | - * @since 1.0 |
|
| 110 | - * @version 1.0 |
|
| 111 | - * @var string |
|
| 112 | - */ |
|
| 107 | + * Output filename |
|
| 108 | + * |
|
| 109 | + * @since 1.0 |
|
| 110 | + * @version 1.0 |
|
| 111 | + * @var string |
|
| 112 | + */ |
|
| 113 | 113 | private $filename; |
| 114 | 114 | |
| 115 | 115 | /** |
| 116 | - * Max file size |
|
| 117 | - * |
|
| 118 | - * @since 1.0 |
|
| 119 | - * @version 1.0 |
|
| 120 | - * @var float |
|
| 121 | - */ |
|
| 116 | + * Max file size |
|
| 117 | + * |
|
| 118 | + * @since 1.0 |
|
| 119 | + * @version 1.0 |
|
| 120 | + * @var float |
|
| 121 | + */ |
|
| 122 | 122 | private $max_file_size= 0.0; |
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | - * List of allowed mime types |
|
| 126 | - * |
|
| 127 | - * @since 1.0 |
|
| 128 | - * @version 1.0 |
|
| 129 | - * @var array |
|
| 130 | - */ |
|
| 125 | + * List of allowed mime types |
|
| 126 | + * |
|
| 127 | + * @since 1.0 |
|
| 128 | + * @version 1.0 |
|
| 129 | + * @var array |
|
| 130 | + */ |
|
| 131 | 131 | private $allowed_mime_types = array(); |
| 132 | 132 | |
| 133 | 133 | /** |
| 134 | - * Callbacks |
|
| 135 | - * |
|
| 136 | - * @since 1.0 |
|
| 137 | - * @version 1.0 |
|
| 138 | - * @var array |
|
| 139 | - */ |
|
| 134 | + * Callbacks |
|
| 135 | + * |
|
| 136 | + * @since 1.0 |
|
| 137 | + * @version 1.0 |
|
| 138 | + * @var array |
|
| 139 | + */ |
|
| 140 | 140 | private $callbacks = array('before' => null, 'after' => null); |
| 141 | 141 | |
| 142 | 142 | /** |
| 143 | - * File object |
|
| 144 | - * |
|
| 145 | - * @since 1.0 |
|
| 146 | - * @version 1.0 |
|
| 147 | - * @var object |
|
| 148 | - */ |
|
| 143 | + * File object |
|
| 144 | + * |
|
| 145 | + * @since 1.0 |
|
| 146 | + * @version 1.0 |
|
| 147 | + * @var object |
|
| 148 | + */ |
|
| 149 | 149 | private $file; |
| 150 | 150 | |
| 151 | 151 | /** |
| 152 | - * Helping mime types |
|
| 153 | - * |
|
| 154 | - * @since 1.0 |
|
| 155 | - * @version 1.0 |
|
| 156 | - * @var array |
|
| 157 | - */ |
|
| 152 | + * Helping mime types |
|
| 153 | + * |
|
| 154 | + * @since 1.0 |
|
| 155 | + * @version 1.0 |
|
| 156 | + * @var array |
|
| 157 | + */ |
|
| 158 | 158 | private $mime_helping = array( |
| 159 | 159 | 'text' => array('text/plain',), |
| 160 | 160 | 'image' => array( |
@@ -210,13 +210,13 @@ discard block |
||
| 210 | 210 | |
| 211 | 211 | |
| 212 | 212 | /** |
| 213 | - * Construct |
|
| 214 | - * |
|
| 215 | - * @since 0.1 |
|
| 216 | - * @version 1.0.1 |
|
| 217 | - * @return object |
|
| 218 | - * @method object __construct |
|
| 219 | - */ |
|
| 213 | + * Construct |
|
| 214 | + * |
|
| 215 | + * @since 0.1 |
|
| 216 | + * @version 1.0.1 |
|
| 217 | + * @return object |
|
| 218 | + * @method object __construct |
|
| 219 | + */ |
|
| 220 | 220 | public function __construct(){ |
| 221 | 221 | $this->logger =& class_loader('Log', 'classes'); |
| 222 | 222 | $this->logger->setLogger('Library::Upload'); |
@@ -260,17 +260,17 @@ discard block |
||
| 260 | 260 | $this->logger->info('The upload file information are : ' .stringfy_vars($this->file_array)); |
| 261 | 261 | } |
| 262 | 262 | /** |
| 263 | - * Set input. |
|
| 264 | - * If you have $_FILES["file"], you must use the key "file" |
|
| 265 | - * Example: |
|
| 266 | - * $object->setInput("file"); |
|
| 267 | - * |
|
| 268 | - * @since 1.0 |
|
| 269 | - * @version 1.0 |
|
| 270 | - * @param string $input |
|
| 271 | - * @return object |
|
| 272 | - * @method boolean setInput |
|
| 273 | - */ |
|
| 263 | + * Set input. |
|
| 264 | + * If you have $_FILES["file"], you must use the key "file" |
|
| 265 | + * Example: |
|
| 266 | + * $object->setInput("file"); |
|
| 267 | + * |
|
| 268 | + * @since 1.0 |
|
| 269 | + * @version 1.0 |
|
| 270 | + * @param string $input |
|
| 271 | + * @return object |
|
| 272 | + * @method boolean setInput |
|
| 273 | + */ |
|
| 274 | 274 | public function setInput($input) |
| 275 | 275 | { |
| 276 | 276 | if (!empty($input) && (is_string($input) || is_numeric($input) )) { |
@@ -279,18 +279,18 @@ discard block |
||
| 279 | 279 | return $this; |
| 280 | 280 | } |
| 281 | 281 | /** |
| 282 | - * Set new filename |
|
| 283 | - * Example: |
|
| 284 | - * FileUpload::setFilename("new file.txt") |
|
| 285 | - * Remember: |
|
| 286 | - * Use %s to retrive file extension |
|
| 287 | - * |
|
| 288 | - * @since 1.0 |
|
| 289 | - * @version 1.0 |
|
| 290 | - * @param string $filename |
|
| 291 | - * @return object |
|
| 292 | - * @method boolean setFilename |
|
| 293 | - */ |
|
| 282 | + * Set new filename |
|
| 283 | + * Example: |
|
| 284 | + * FileUpload::setFilename("new file.txt") |
|
| 285 | + * Remember: |
|
| 286 | + * Use %s to retrive file extension |
|
| 287 | + * |
|
| 288 | + * @since 1.0 |
|
| 289 | + * @version 1.0 |
|
| 290 | + * @param string $filename |
|
| 291 | + * @return object |
|
| 292 | + * @method boolean setFilename |
|
| 293 | + */ |
|
| 294 | 294 | public function setFilename($filename) |
| 295 | 295 | { |
| 296 | 296 | if ($this->isFilename($filename)) { |
@@ -299,14 +299,14 @@ discard block |
||
| 299 | 299 | return $this; |
| 300 | 300 | } |
| 301 | 301 | /** |
| 302 | - * Set automatic filename |
|
| 303 | - * |
|
| 304 | - * @since 1.0 |
|
| 305 | - * @version 1.5 |
|
| 306 | - * @param string $extension |
|
| 307 | - * @return object |
|
| 308 | - * @method boolean setAutoFilename |
|
| 309 | - */ |
|
| 302 | + * Set automatic filename |
|
| 303 | + * |
|
| 304 | + * @since 1.0 |
|
| 305 | + * @version 1.5 |
|
| 306 | + * @param string $extension |
|
| 307 | + * @return object |
|
| 308 | + * @method boolean setAutoFilename |
|
| 309 | + */ |
|
| 310 | 310 | public function setAutoFilename() |
| 311 | 311 | { |
| 312 | 312 | $this->filename = sha1(mt_rand(1, 9999).uniqid()); |
@@ -314,14 +314,14 @@ discard block |
||
| 314 | 314 | return $this; |
| 315 | 315 | } |
| 316 | 316 | /** |
| 317 | - * Set file size limit |
|
| 318 | - * |
|
| 319 | - * @since 1.0 |
|
| 320 | - * @version 1.0 |
|
| 321 | - * @param double $file_size |
|
| 322 | - * @return object |
|
| 323 | - * @method boolean setMaxFileSize |
|
| 324 | - */ |
|
| 317 | + * Set file size limit |
|
| 318 | + * |
|
| 319 | + * @since 1.0 |
|
| 320 | + * @version 1.0 |
|
| 321 | + * @param double $file_size |
|
| 322 | + * @return object |
|
| 323 | + * @method boolean setMaxFileSize |
|
| 324 | + */ |
|
| 325 | 325 | public function setMaxFileSize($file_size) |
| 326 | 326 | { |
| 327 | 327 | $file_size = $this->sizeInBytes($file_size); |
@@ -337,14 +337,14 @@ discard block |
||
| 337 | 337 | return $this; |
| 338 | 338 | } |
| 339 | 339 | /** |
| 340 | - * Set array mime types |
|
| 341 | - * |
|
| 342 | - * @since 1.0 |
|
| 343 | - * @version 1.0 |
|
| 344 | - * @param array $mimes |
|
| 345 | - * @return object |
|
| 346 | - * @method boolean setAllowedMimeTypes |
|
| 347 | - */ |
|
| 340 | + * Set array mime types |
|
| 341 | + * |
|
| 342 | + * @since 1.0 |
|
| 343 | + * @version 1.0 |
|
| 344 | + * @param array $mimes |
|
| 345 | + * @return object |
|
| 346 | + * @method boolean setAllowedMimeTypes |
|
| 347 | + */ |
|
| 348 | 348 | public function setAllowedMimeTypes(array $mimes) |
| 349 | 349 | { |
| 350 | 350 | if (count($mimes) > 0) { |
@@ -353,14 +353,14 @@ discard block |
||
| 353 | 353 | return $this; |
| 354 | 354 | } |
| 355 | 355 | /** |
| 356 | - * Set input callback |
|
| 357 | - * |
|
| 358 | - * @since 1.0 |
|
| 359 | - * @version 1.0 |
|
| 360 | - * @param mixed $callback |
|
| 361 | - * @return object |
|
| 362 | - * @method boolean setCallbackInput |
|
| 363 | - */ |
|
| 356 | + * Set input callback |
|
| 357 | + * |
|
| 358 | + * @since 1.0 |
|
| 359 | + * @version 1.0 |
|
| 360 | + * @param mixed $callback |
|
| 361 | + * @return object |
|
| 362 | + * @method boolean setCallbackInput |
|
| 363 | + */ |
|
| 364 | 364 | public function setCallbackInput($callback) |
| 365 | 365 | { |
| 366 | 366 | if (is_callable($callback, false)) { |
@@ -369,14 +369,14 @@ discard block |
||
| 369 | 369 | return $this; |
| 370 | 370 | } |
| 371 | 371 | /** |
| 372 | - * Set output callback |
|
| 373 | - * |
|
| 374 | - * @since 1.0 |
|
| 375 | - * @version 1.0 |
|
| 376 | - * @param mixed $callback |
|
| 377 | - * @return object |
|
| 378 | - * @method boolean setCallbackOutput |
|
| 379 | - */ |
|
| 372 | + * Set output callback |
|
| 373 | + * |
|
| 374 | + * @since 1.0 |
|
| 375 | + * @version 1.0 |
|
| 376 | + * @param mixed $callback |
|
| 377 | + * @return object |
|
| 378 | + * @method boolean setCallbackOutput |
|
| 379 | + */ |
|
| 380 | 380 | public function setCallbackOutput($callback) |
| 381 | 381 | { |
| 382 | 382 | if (is_callable($callback, false)) { |
@@ -385,14 +385,14 @@ discard block |
||
| 385 | 385 | return $this; |
| 386 | 386 | } |
| 387 | 387 | /** |
| 388 | - * Append a mime type to allowed mime types |
|
| 389 | - * |
|
| 390 | - * @since 1.0 |
|
| 391 | - * @version 1.0.1 |
|
| 392 | - * @param string $mime |
|
| 393 | - * @return object |
|
| 394 | - * @method boolean setAllowMimeType |
|
| 395 | - */ |
|
| 388 | + * Append a mime type to allowed mime types |
|
| 389 | + * |
|
| 390 | + * @since 1.0 |
|
| 391 | + * @version 1.0.1 |
|
| 392 | + * @param string $mime |
|
| 393 | + * @return object |
|
| 394 | + * @method boolean setAllowMimeType |
|
| 395 | + */ |
|
| 396 | 396 | public function setAllowMimeType($mime) |
| 397 | 397 | { |
| 398 | 398 | if (!empty($mime) && is_string($mime)) { |
@@ -402,13 +402,13 @@ discard block |
||
| 402 | 402 | return $this; |
| 403 | 403 | } |
| 404 | 404 | /** |
| 405 | - * Set allowed mime types from mime helping |
|
| 406 | - * |
|
| 407 | - * @since 1.0.1 |
|
| 408 | - * @version 1.0.1 |
|
| 409 | - * @return object |
|
| 410 | - * @method boolean setMimeHelping |
|
| 411 | - */ |
|
| 405 | + * Set allowed mime types from mime helping |
|
| 406 | + * |
|
| 407 | + * @since 1.0.1 |
|
| 408 | + * @version 1.0.1 |
|
| 409 | + * @return object |
|
| 410 | + * @method boolean setMimeHelping |
|
| 411 | + */ |
|
| 412 | 412 | public function setMimeHelping($name) |
| 413 | 413 | { |
| 414 | 414 | if (!empty($name) && is_string($name)) { |
@@ -419,17 +419,17 @@ discard block |
||
| 419 | 419 | return $this; |
| 420 | 420 | } |
| 421 | 421 | /** |
| 422 | - * Set function to upload file |
|
| 423 | - * Examples: |
|
| 424 | - * 1.- FileUpload::setUploadFunction("move_uploaded_file"); |
|
| 425 | - * 2.- FileUpload::setUploadFunction("copy"); |
|
| 426 | - * |
|
| 427 | - * @since 1.0 |
|
| 428 | - * @version 1.0 |
|
| 429 | - * @param string $function |
|
| 430 | - * @return object |
|
| 431 | - * @method boolean setUploadFunction |
|
| 432 | - */ |
|
| 422 | + * Set function to upload file |
|
| 423 | + * Examples: |
|
| 424 | + * 1.- FileUpload::setUploadFunction("move_uploaded_file"); |
|
| 425 | + * 2.- FileUpload::setUploadFunction("copy"); |
|
| 426 | + * |
|
| 427 | + * @since 1.0 |
|
| 428 | + * @version 1.0 |
|
| 429 | + * @param string $function |
|
| 430 | + * @return object |
|
| 431 | + * @method boolean setUploadFunction |
|
| 432 | + */ |
|
| 433 | 433 | public function setUploadFunction($function) |
| 434 | 434 | { |
| 435 | 435 | if (!empty($function) && (is_array($function) || is_string($function) )) { |
@@ -440,13 +440,13 @@ discard block |
||
| 440 | 440 | return $this; |
| 441 | 441 | } |
| 442 | 442 | /** |
| 443 | - * Clear allowed mime types cache |
|
| 444 | - * |
|
| 445 | - * @since 1.0 |
|
| 446 | - * @version 1.0 |
|
| 447 | - * @return object |
|
| 448 | - * @method boolean clearAllowedMimeTypes |
|
| 449 | - */ |
|
| 443 | + * Clear allowed mime types cache |
|
| 444 | + * |
|
| 445 | + * @since 1.0 |
|
| 446 | + * @version 1.0 |
|
| 447 | + * @return object |
|
| 448 | + * @method boolean clearAllowedMimeTypes |
|
| 449 | + */ |
|
| 450 | 450 | public function clearAllowedMimeTypes() |
| 451 | 451 | { |
| 452 | 452 | $this->allowed_mime_types = array(); |
@@ -454,15 +454,15 @@ discard block |
||
| 454 | 454 | return $this; |
| 455 | 455 | } |
| 456 | 456 | /** |
| 457 | - * Set destination output |
|
| 458 | - * |
|
| 459 | - * @since 1.0 |
|
| 460 | - * @version 1.0 |
|
| 461 | - * @param string $destination_directory Destination path |
|
| 462 | - * @param boolean $create_if_not_exist |
|
| 463 | - * @return object |
|
| 464 | - * @method boolean setDestinationDirectory |
|
| 465 | - */ |
|
| 457 | + * Set destination output |
|
| 458 | + * |
|
| 459 | + * @since 1.0 |
|
| 460 | + * @version 1.0 |
|
| 461 | + * @param string $destination_directory Destination path |
|
| 462 | + * @param boolean $create_if_not_exist |
|
| 463 | + * @return object |
|
| 464 | + * @method boolean setDestinationDirectory |
|
| 465 | + */ |
|
| 466 | 466 | public function setDestinationDirectory($destination_directory, $create_if_not_exist = false) { |
| 467 | 467 | $destination_directory = realpath($destination_directory); |
| 468 | 468 | if (substr($destination_directory, -1) != DIRECTORY_SEPARATOR) { |
@@ -486,14 +486,14 @@ discard block |
||
| 486 | 486 | return $this; |
| 487 | 487 | } |
| 488 | 488 | /** |
| 489 | - * Check file exists |
|
| 490 | - * |
|
| 491 | - * @since 1.0 |
|
| 492 | - * @version 1.0.1 |
|
| 493 | - * @param string $file_destination |
|
| 494 | - * @return boolean |
|
| 495 | - * @method boolean fileExists |
|
| 496 | - */ |
|
| 489 | + * Check file exists |
|
| 490 | + * |
|
| 491 | + * @since 1.0 |
|
| 492 | + * @version 1.0.1 |
|
| 493 | + * @param string $file_destination |
|
| 494 | + * @return boolean |
|
| 495 | + * @method boolean fileExists |
|
| 496 | + */ |
|
| 497 | 497 | public function fileExists($file_destination) |
| 498 | 498 | { |
| 499 | 499 | if ($this->isFilename($file_destination)) { |
@@ -502,14 +502,14 @@ discard block |
||
| 502 | 502 | return false; |
| 503 | 503 | } |
| 504 | 504 | /** |
| 505 | - * Check dir exists |
|
| 506 | - * |
|
| 507 | - * @since 1.0 |
|
| 508 | - * @version 1.0.1 |
|
| 509 | - * @param string $path |
|
| 510 | - * @return boolean |
|
| 511 | - * @method boolean dirExists |
|
| 512 | - */ |
|
| 505 | + * Check dir exists |
|
| 506 | + * |
|
| 507 | + * @since 1.0 |
|
| 508 | + * @version 1.0.1 |
|
| 509 | + * @param string $path |
|
| 510 | + * @return boolean |
|
| 511 | + * @method boolean dirExists |
|
| 512 | + */ |
|
| 513 | 513 | public function dirExists($path) |
| 514 | 514 | { |
| 515 | 515 | if ($this->isDirpath($path)) { |
@@ -518,29 +518,29 @@ discard block |
||
| 518 | 518 | return false; |
| 519 | 519 | } |
| 520 | 520 | /** |
| 521 | - * Check valid filename |
|
| 522 | - * |
|
| 523 | - * @since 1.0 |
|
| 524 | - * @version 1.0.1 |
|
| 525 | - * @param string $filename |
|
| 526 | - * @return boolean |
|
| 527 | - * @method boolean isFilename |
|
| 528 | - */ |
|
| 521 | + * Check valid filename |
|
| 522 | + * |
|
| 523 | + * @since 1.0 |
|
| 524 | + * @version 1.0.1 |
|
| 525 | + * @param string $filename |
|
| 526 | + * @return boolean |
|
| 527 | + * @method boolean isFilename |
|
| 528 | + */ |
|
| 529 | 529 | public function isFilename($filename) |
| 530 | 530 | { |
| 531 | 531 | $filename = basename($filename); |
| 532 | 532 | return (!empty($filename) && (is_string( $filename) || is_numeric($filename))); |
| 533 | 533 | } |
| 534 | 534 | /** |
| 535 | - * Validate mime type with allowed mime types, |
|
| 536 | - * but if allowed mime types is empty, this method return true |
|
| 537 | - * |
|
| 538 | - * @since 1.0 |
|
| 539 | - * @version 1.0 |
|
| 540 | - * @param string $mime |
|
| 541 | - * @return boolean |
|
| 542 | - * @method boolean checkMimeType |
|
| 543 | - */ |
|
| 535 | + * Validate mime type with allowed mime types, |
|
| 536 | + * but if allowed mime types is empty, this method return true |
|
| 537 | + * |
|
| 538 | + * @since 1.0 |
|
| 539 | + * @version 1.0 |
|
| 540 | + * @param string $mime |
|
| 541 | + * @return boolean |
|
| 542 | + * @method boolean checkMimeType |
|
| 543 | + */ |
|
| 544 | 544 | public function checkMimeType($mime) |
| 545 | 545 | { |
| 546 | 546 | if (count($this->allowed_mime_types) == 0) { |
@@ -549,26 +549,26 @@ discard block |
||
| 549 | 549 | return in_array(strtolower($mime), $this->allowed_mime_types); |
| 550 | 550 | } |
| 551 | 551 | /** |
| 552 | - * Retrive status of upload |
|
| 553 | - * |
|
| 554 | - * @since 1.0 |
|
| 555 | - * @version 1.0 |
|
| 556 | - * @return boolean |
|
| 557 | - * @method boolean getStatus |
|
| 558 | - */ |
|
| 552 | + * Retrive status of upload |
|
| 553 | + * |
|
| 554 | + * @since 1.0 |
|
| 555 | + * @version 1.0 |
|
| 556 | + * @return boolean |
|
| 557 | + * @method boolean getStatus |
|
| 558 | + */ |
|
| 559 | 559 | public function getStatus() |
| 560 | 560 | { |
| 561 | 561 | return $this->file['status']; |
| 562 | 562 | } |
| 563 | 563 | /** |
| 564 | - * Check valid path |
|
| 565 | - * |
|
| 566 | - * @since 1.0 |
|
| 567 | - * @version 1.0.1 |
|
| 568 | - * @param string $filename |
|
| 569 | - * @return boolean |
|
| 570 | - * @method boolean isDirpath |
|
| 571 | - */ |
|
| 564 | + * Check valid path |
|
| 565 | + * |
|
| 566 | + * @since 1.0 |
|
| 567 | + * @version 1.0.1 |
|
| 568 | + * @param string $filename |
|
| 569 | + * @return boolean |
|
| 570 | + * @method boolean isDirpath |
|
| 571 | + */ |
|
| 572 | 572 | public function isDirpath($path) |
| 573 | 573 | { |
| 574 | 574 | if (!empty( $path) && (is_string( $path) || is_numeric($path) )) { |
@@ -581,26 +581,26 @@ discard block |
||
| 581 | 581 | return false; |
| 582 | 582 | } |
| 583 | 583 | /** |
| 584 | - * Allow overwriting files |
|
| 585 | - * |
|
| 586 | - * @since 1.0 |
|
| 587 | - * @version 1.0 |
|
| 588 | - * @return object |
|
| 589 | - * @method boolean allowOverwriting |
|
| 590 | - */ |
|
| 584 | + * Allow overwriting files |
|
| 585 | + * |
|
| 586 | + * @since 1.0 |
|
| 587 | + * @version 1.0 |
|
| 588 | + * @return object |
|
| 589 | + * @method boolean allowOverwriting |
|
| 590 | + */ |
|
| 591 | 591 | public function allowOverwriting() |
| 592 | 592 | { |
| 593 | 593 | $this->overwrite_file = true; |
| 594 | 594 | return $this; |
| 595 | 595 | } |
| 596 | 596 | /** |
| 597 | - * File info |
|
| 598 | - * |
|
| 599 | - * @since 1.0 |
|
| 600 | - * @version 1.0 |
|
| 601 | - * @return object |
|
| 602 | - * @method object getInfo |
|
| 603 | - */ |
|
| 597 | + * File info |
|
| 598 | + * |
|
| 599 | + * @since 1.0 |
|
| 600 | + * @version 1.0 |
|
| 601 | + * @return object |
|
| 602 | + * @method object getInfo |
|
| 603 | + */ |
|
| 604 | 604 | public function getInfo() |
| 605 | 605 | { |
| 606 | 606 | return (object)$this->file; |
@@ -618,13 +618,13 @@ discard block |
||
| 618 | 618 | |
| 619 | 619 | |
| 620 | 620 | /** |
| 621 | - * Upload file |
|
| 622 | - * |
|
| 623 | - * @since 1.0 |
|
| 624 | - * @version 1.0.1 |
|
| 625 | - * @return boolean |
|
| 626 | - * @method boolean save |
|
| 627 | - */ |
|
| 621 | + * Upload file |
|
| 622 | + * |
|
| 623 | + * @since 1.0 |
|
| 624 | + * @version 1.0.1 |
|
| 625 | + * @return boolean |
|
| 626 | + * @method boolean save |
|
| 627 | + */ |
|
| 628 | 628 | public function save(){ |
| 629 | 629 | if (count($this->file_array) > 0 && array_key_exists($this->input, $this->file_array)) { |
| 630 | 630 | // set original filename if not have a new name |
@@ -681,15 +681,15 @@ discard block |
||
| 681 | 681 | |
| 682 | 682 | |
| 683 | 683 | /** |
| 684 | - * File size for humans. |
|
| 685 | - * |
|
| 686 | - * @since 1.0 |
|
| 687 | - * @version 1.0 |
|
| 688 | - * @param integer $bytes |
|
| 689 | - * @param integer $precision |
|
| 690 | - * @return string |
|
| 691 | - * @method string sizeFormat |
|
| 692 | - */ |
|
| 684 | + * File size for humans. |
|
| 685 | + * |
|
| 686 | + * @since 1.0 |
|
| 687 | + * @version 1.0 |
|
| 688 | + * @param integer $bytes |
|
| 689 | + * @param integer $precision |
|
| 690 | + * @return string |
|
| 691 | + * @method string sizeFormat |
|
| 692 | + */ |
|
| 693 | 693 | public function sizeFormat($size, $precision = 2) |
| 694 | 694 | { |
| 695 | 695 | if($size > 0){ |
@@ -702,14 +702,14 @@ discard block |
||
| 702 | 702 | |
| 703 | 703 | |
| 704 | 704 | /** |
| 705 | - * Convert human file size to bytes |
|
| 706 | - * |
|
| 707 | - * @since 1.0 |
|
| 708 | - * @version 1.0.1 |
|
| 709 | - * @param integer|double $size |
|
| 710 | - * @return integer|double |
|
| 711 | - * @method string sizeInBytes |
|
| 712 | - */ |
|
| 705 | + * Convert human file size to bytes |
|
| 706 | + * |
|
| 707 | + * @since 1.0 |
|
| 708 | + * @version 1.0.1 |
|
| 709 | + * @param integer|double $size |
|
| 710 | + * @return integer|double |
|
| 711 | + * @method string sizeInBytes |
|
| 712 | + */ |
|
| 713 | 713 | public function sizeInBytes($size) |
| 714 | 714 | { |
| 715 | 715 | $unit = 'B'; |
@@ -761,7 +761,7 @@ discard block |
||
| 761 | 761 | return true; |
| 762 | 762 | } |
| 763 | 763 | |
| 764 | - //check for php upload error |
|
| 764 | + //check for php upload error |
|
| 765 | 765 | if(is_numeric($this->file['error']) && $this->file['error'] > 0){ |
| 766 | 766 | $this->setError($this->getPhpUploadErrorMessageByCode($this->file['error'])); |
| 767 | 767 | return true; |
@@ -773,7 +773,7 @@ discard block |
||
| 773 | 773 | return true; |
| 774 | 774 | } |
| 775 | 775 | |
| 776 | - // Check file size |
|
| 776 | + // Check file size |
|
| 777 | 777 | if ($this->max_file_size > 0 && $this->max_file_size < $this->file['size']) { |
| 778 | 778 | $this->setError(sprintf($this->error_messages['max_file_size'], $this->sizeFormat($this->max_file_size))); |
| 779 | 779 | return true; |
@@ -1,251 +1,251 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | - class Html{ |
|
| 27 | + class Html{ |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Generate the html anchor link |
|
| 31 | - * @param string $link the href attribute value |
|
| 32 | - * @param string $anchor the displayed anchor |
|
| 33 | - * @param array $attributes the additional attributes to be added |
|
| 34 | - * @param boolean $return whether need return the generated html or just display it directly |
|
| 35 | - * |
|
| 36 | - * @return string|void the anchor link generated html if $return is true or display it if not |
|
| 37 | - */ |
|
| 38 | - public static function a($link = '', $anchor = null, array $attributes = array(), $return = true){ |
|
| 39 | - if(! is_url($link)){ |
|
| 40 | - $link = Url::site_url($link); |
|
| 41 | - } |
|
| 42 | - if(! $anchor){ |
|
| 43 | - $anchor = $link; |
|
| 44 | - } |
|
| 45 | - $str = null; |
|
| 46 | - $str .= '<a href = "'.$link.'"'; |
|
| 47 | - $str .= attributes_to_string($attributes); |
|
| 48 | - $str .= '>'; |
|
| 49 | - $str .= $anchor; |
|
| 50 | - $str .= '</a>'; |
|
| 29 | + /** |
|
| 30 | + * Generate the html anchor link |
|
| 31 | + * @param string $link the href attribute value |
|
| 32 | + * @param string $anchor the displayed anchor |
|
| 33 | + * @param array $attributes the additional attributes to be added |
|
| 34 | + * @param boolean $return whether need return the generated html or just display it directly |
|
| 35 | + * |
|
| 36 | + * @return string|void the anchor link generated html if $return is true or display it if not |
|
| 37 | + */ |
|
| 38 | + public static function a($link = '', $anchor = null, array $attributes = array(), $return = true){ |
|
| 39 | + if(! is_url($link)){ |
|
| 40 | + $link = Url::site_url($link); |
|
| 41 | + } |
|
| 42 | + if(! $anchor){ |
|
| 43 | + $anchor = $link; |
|
| 44 | + } |
|
| 45 | + $str = null; |
|
| 46 | + $str .= '<a href = "'.$link.'"'; |
|
| 47 | + $str .= attributes_to_string($attributes); |
|
| 48 | + $str .= '>'; |
|
| 49 | + $str .= $anchor; |
|
| 50 | + $str .= '</a>'; |
|
| 51 | 51 | |
| 52 | - if($return){ |
|
| 53 | - return $str; |
|
| 54 | - } |
|
| 55 | - echo $str; |
|
| 56 | - } |
|
| 52 | + if($return){ |
|
| 53 | + return $str; |
|
| 54 | + } |
|
| 55 | + echo $str; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Generate an mailto anchor link |
|
| 60 | - * @param string $link the email address |
|
| 61 | - * @param string $anchor the displayed value of the link |
|
| 62 | - * @param array $attributes the additional attributes to be added |
|
| 63 | - * @param boolean $return whether need return the generated html or just display it directly |
|
| 64 | - * |
|
| 65 | - * @return string|void the generated html for mailto link if $return is true or display it if not |
|
| 66 | - */ |
|
| 67 | - public static function mailto($link, $anchor = null, array $attributes = array(), $return = true){ |
|
| 68 | - if(! $anchor){ |
|
| 69 | - $anchor = $link; |
|
| 70 | - } |
|
| 71 | - $str = null; |
|
| 72 | - $str .= '<a href = "mailto:'.$link.'"'; |
|
| 73 | - $str .= attributes_to_string($attributes); |
|
| 74 | - $str .= '>'; |
|
| 75 | - $str .= $anchor; |
|
| 76 | - $str .= '</a>'; |
|
| 58 | + /** |
|
| 59 | + * Generate an mailto anchor link |
|
| 60 | + * @param string $link the email address |
|
| 61 | + * @param string $anchor the displayed value of the link |
|
| 62 | + * @param array $attributes the additional attributes to be added |
|
| 63 | + * @param boolean $return whether need return the generated html or just display it directly |
|
| 64 | + * |
|
| 65 | + * @return string|void the generated html for mailto link if $return is true or display it if not |
|
| 66 | + */ |
|
| 67 | + public static function mailto($link, $anchor = null, array $attributes = array(), $return = true){ |
|
| 68 | + if(! $anchor){ |
|
| 69 | + $anchor = $link; |
|
| 70 | + } |
|
| 71 | + $str = null; |
|
| 72 | + $str .= '<a href = "mailto:'.$link.'"'; |
|
| 73 | + $str .= attributes_to_string($attributes); |
|
| 74 | + $str .= '>'; |
|
| 75 | + $str .= $anchor; |
|
| 76 | + $str .= '</a>'; |
|
| 77 | 77 | |
| 78 | - if($return){ |
|
| 79 | - return $str; |
|
| 80 | - } |
|
| 81 | - echo $str; |
|
| 82 | - } |
|
| 78 | + if($return){ |
|
| 79 | + return $str; |
|
| 80 | + } |
|
| 81 | + echo $str; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Generate the html "br" tag |
|
| 86 | - * @param integer $nb the number of generated "<br />" tag |
|
| 87 | - * @param boolean $return whether need return the generated html or just display it directly |
|
| 88 | - * |
|
| 89 | - * @return string|void the generated "br" html if $return is true or display it if not |
|
| 90 | - */ |
|
| 91 | - public static function br($nb = 1, $return = true){ |
|
| 92 | - $nb = (int) $nb; |
|
| 93 | - $str = null; |
|
| 94 | - for ($i = 1; $i <= $nb; $i++) { |
|
| 95 | - $str .= '<br />'; |
|
| 96 | - } |
|
| 84 | + /** |
|
| 85 | + * Generate the html "br" tag |
|
| 86 | + * @param integer $nb the number of generated "<br />" tag |
|
| 87 | + * @param boolean $return whether need return the generated html or just display it directly |
|
| 88 | + * |
|
| 89 | + * @return string|void the generated "br" html if $return is true or display it if not |
|
| 90 | + */ |
|
| 91 | + public static function br($nb = 1, $return = true){ |
|
| 92 | + $nb = (int) $nb; |
|
| 93 | + $str = null; |
|
| 94 | + for ($i = 1; $i <= $nb; $i++) { |
|
| 95 | + $str .= '<br />'; |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - if($return){ |
|
| 99 | - return $str; |
|
| 100 | - } |
|
| 101 | - echo $str; |
|
| 102 | - } |
|
| 98 | + if($return){ |
|
| 99 | + return $str; |
|
| 100 | + } |
|
| 101 | + echo $str; |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * Generate the html content for tag "hr" |
|
| 106 | - * @param integer $nb the number of generated "<hr />" tag |
|
| 107 | - * @param array $attributes the tag attributes |
|
| 108 | - * @param boolean $return whether need return the generated html or just display it directly |
|
| 109 | - * |
|
| 110 | - * @return string|void the generated "hr" html if $return is true or display it if not. |
|
| 111 | - */ |
|
| 112 | - public static function hr($nb = 1, array $attributes = array(), $return = true){ |
|
| 113 | - $nb = (int) $nb; |
|
| 114 | - $str = null; |
|
| 115 | - for ($i = 1; $i <= $nb; $i++) { |
|
| 116 | - $str .= '<hr' .attributes_to_string($attributes). ' />'; |
|
| 117 | - } |
|
| 118 | - if($return){ |
|
| 119 | - return $str; |
|
| 120 | - } |
|
| 121 | - echo $str; |
|
| 122 | - } |
|
| 104 | + /** |
|
| 105 | + * Generate the html content for tag "hr" |
|
| 106 | + * @param integer $nb the number of generated "<hr />" tag |
|
| 107 | + * @param array $attributes the tag attributes |
|
| 108 | + * @param boolean $return whether need return the generated html or just display it directly |
|
| 109 | + * |
|
| 110 | + * @return string|void the generated "hr" html if $return is true or display it if not. |
|
| 111 | + */ |
|
| 112 | + public static function hr($nb = 1, array $attributes = array(), $return = true){ |
|
| 113 | + $nb = (int) $nb; |
|
| 114 | + $str = null; |
|
| 115 | + for ($i = 1; $i <= $nb; $i++) { |
|
| 116 | + $str .= '<hr' .attributes_to_string($attributes). ' />'; |
|
| 117 | + } |
|
| 118 | + if($return){ |
|
| 119 | + return $str; |
|
| 120 | + } |
|
| 121 | + echo $str; |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - /** |
|
| 125 | - * Generate the html content for tag like h1, h2, h3, h4, h5 and h6 |
|
| 126 | - * @param integer $type the tag type 1 mean h1, 2 h2, etc, |
|
| 127 | - * @param string $text the display text |
|
| 128 | - * @param integer $nb the number of generated "<h{1,2,3,4,5,6}>" |
|
| 129 | - * @param array $attributes the tag attributes |
|
| 130 | - * @param boolean $return whether need return the generated html or just display it directly |
|
| 131 | - * |
|
| 132 | - * @return string|void the generated header html if $return is true or display it if not. |
|
| 133 | - */ |
|
| 134 | - public static function head($type = 1, $text = null, $nb = 1, array $attributes = array(), $return = true){ |
|
| 135 | - $nb = (int) $nb; |
|
| 136 | - $type = (int) $type; |
|
| 137 | - if($type <= 0 || $type > 6){ |
|
| 138 | - $type = 1; |
|
| 139 | - } |
|
| 140 | - $str = null; |
|
| 141 | - for ($i = 1; $i <= $nb; $i++) { |
|
| 142 | - $str .= '<h' . $type . attributes_to_string($attributes). '>' .$text. '</h' . $type . '>'; |
|
| 143 | - } |
|
| 144 | - if($return){ |
|
| 145 | - return $str; |
|
| 146 | - } |
|
| 147 | - echo $str; |
|
| 148 | - } |
|
| 124 | + /** |
|
| 125 | + * Generate the html content for tag like h1, h2, h3, h4, h5 and h6 |
|
| 126 | + * @param integer $type the tag type 1 mean h1, 2 h2, etc, |
|
| 127 | + * @param string $text the display text |
|
| 128 | + * @param integer $nb the number of generated "<h{1,2,3,4,5,6}>" |
|
| 129 | + * @param array $attributes the tag attributes |
|
| 130 | + * @param boolean $return whether need return the generated html or just display it directly |
|
| 131 | + * |
|
| 132 | + * @return string|void the generated header html if $return is true or display it if not. |
|
| 133 | + */ |
|
| 134 | + public static function head($type = 1, $text = null, $nb = 1, array $attributes = array(), $return = true){ |
|
| 135 | + $nb = (int) $nb; |
|
| 136 | + $type = (int) $type; |
|
| 137 | + if($type <= 0 || $type > 6){ |
|
| 138 | + $type = 1; |
|
| 139 | + } |
|
| 140 | + $str = null; |
|
| 141 | + for ($i = 1; $i <= $nb; $i++) { |
|
| 142 | + $str .= '<h' . $type . attributes_to_string($attributes). '>' .$text. '</h' . $type . '>'; |
|
| 143 | + } |
|
| 144 | + if($return){ |
|
| 145 | + return $str; |
|
| 146 | + } |
|
| 147 | + echo $str; |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - /** |
|
| 151 | - * Generate the html "ul" tag |
|
| 152 | - * @param array $data the data to use for each "li" tag |
|
| 153 | - * @param array $attributes the "ul" properties attribute use the array index below for each tag: |
|
| 154 | - * for ul "ul", for li "li". |
|
| 155 | - * @param boolean $return whether need return the generated html or just display it directly |
|
| 156 | - * |
|
| 157 | - * @return string|void the generated "ul" html if $return is true or display it if not. |
|
| 158 | - */ |
|
| 159 | - public static function ul($data = array(), $attributes = array(), $return = true){ |
|
| 160 | - $data = (array) $data; |
|
| 161 | - $str = null; |
|
| 162 | - $str .= '<ul' . (! empty($attributes['ul']) ? attributes_to_string($attributes['ul']):'') . '>'; |
|
| 163 | - foreach ($data as $row) { |
|
| 164 | - $str .= '<li' . (! empty($attributes['li']) ? attributes_to_string($attributes['li']):'') .'>' .$row. '</li>'; |
|
| 165 | - } |
|
| 166 | - $str .= '</ul>'; |
|
| 167 | - if($return){ |
|
| 168 | - return $str; |
|
| 169 | - } |
|
| 170 | - echo $str; |
|
| 171 | - } |
|
| 150 | + /** |
|
| 151 | + * Generate the html "ul" tag |
|
| 152 | + * @param array $data the data to use for each "li" tag |
|
| 153 | + * @param array $attributes the "ul" properties attribute use the array index below for each tag: |
|
| 154 | + * for ul "ul", for li "li". |
|
| 155 | + * @param boolean $return whether need return the generated html or just display it directly |
|
| 156 | + * |
|
| 157 | + * @return string|void the generated "ul" html if $return is true or display it if not. |
|
| 158 | + */ |
|
| 159 | + public static function ul($data = array(), $attributes = array(), $return = true){ |
|
| 160 | + $data = (array) $data; |
|
| 161 | + $str = null; |
|
| 162 | + $str .= '<ul' . (! empty($attributes['ul']) ? attributes_to_string($attributes['ul']):'') . '>'; |
|
| 163 | + foreach ($data as $row) { |
|
| 164 | + $str .= '<li' . (! empty($attributes['li']) ? attributes_to_string($attributes['li']):'') .'>' .$row. '</li>'; |
|
| 165 | + } |
|
| 166 | + $str .= '</ul>'; |
|
| 167 | + if($return){ |
|
| 168 | + return $str; |
|
| 169 | + } |
|
| 170 | + echo $str; |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | - /** |
|
| 174 | - * Generate the html "ol" tag |
|
| 175 | - * @param array $data the data to use for each "li" tag |
|
| 176 | - * @param array $attributes the "ol" properties attribute use the array index below for each tag: |
|
| 177 | - * for ol "ol", for li "li". |
|
| 178 | - * @param boolean $return whether need return the generated html or just display it directly |
|
| 179 | - * @return string|void the generated "ol" html if $return is true or display it if not. |
|
| 180 | - */ |
|
| 181 | - public static function ol($data = array(), $attributes = array(), $return = true){ |
|
| 182 | - $data = (array) $data; |
|
| 183 | - $str = null; |
|
| 184 | - $str .= '<ol' . (!empty($attributes['ol']) ? attributes_to_string($attributes['ol']):'') . '>'; |
|
| 185 | - foreach ($data as $row) { |
|
| 186 | - $str .= '<li' . (!empty($attributes['li']) ? attributes_to_string($attributes['li']):'') .'>' .$row. '</li>'; |
|
| 187 | - } |
|
| 188 | - $str .= '</ol>'; |
|
| 189 | - if($return){ |
|
| 190 | - return $str; |
|
| 191 | - } |
|
| 192 | - echo $str; |
|
| 193 | - } |
|
| 173 | + /** |
|
| 174 | + * Generate the html "ol" tag |
|
| 175 | + * @param array $data the data to use for each "li" tag |
|
| 176 | + * @param array $attributes the "ol" properties attribute use the array index below for each tag: |
|
| 177 | + * for ol "ol", for li "li". |
|
| 178 | + * @param boolean $return whether need return the generated html or just display it directly |
|
| 179 | + * @return string|void the generated "ol" html if $return is true or display it if not. |
|
| 180 | + */ |
|
| 181 | + public static function ol($data = array(), $attributes = array(), $return = true){ |
|
| 182 | + $data = (array) $data; |
|
| 183 | + $str = null; |
|
| 184 | + $str .= '<ol' . (!empty($attributes['ol']) ? attributes_to_string($attributes['ol']):'') . '>'; |
|
| 185 | + foreach ($data as $row) { |
|
| 186 | + $str .= '<li' . (!empty($attributes['li']) ? attributes_to_string($attributes['li']):'') .'>' .$row. '</li>'; |
|
| 187 | + } |
|
| 188 | + $str .= '</ol>'; |
|
| 189 | + if($return){ |
|
| 190 | + return $str; |
|
| 191 | + } |
|
| 192 | + echo $str; |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - /** |
|
| 196 | - * Generate the html "table" tag |
|
| 197 | - * @param array $headers the table headers to use between (<thead>) |
|
| 198 | - * @param array $body the table body values between (<tbody>) |
|
| 199 | - * @param array $attributes the table properties attribute use the array index below for each tag: |
|
| 200 | - * for table "table", for thead "thead", for thead tr "thead_tr", |
|
| 201 | - * for thead th "thead_th", for tbody "tbody", for tbody tr "tbody_tr", for tbody td "tbody_td", for tfoot "tfoot", |
|
| 202 | - * for tfoot tr "tfoot_tr", for tfoot th "tfoot_th". |
|
| 203 | - * @param boolean $use_footer whether need to generate table footer (<tfoot>) use the $headers values |
|
| 204 | - * @param boolean $return whether need return the generated html or just display it directly |
|
| 205 | - * @return string|void the generated "table" html if $return is true or display it if not. |
|
| 206 | - */ |
|
| 207 | - public static function table($headers = array(), $body = array(), $attributes = array(), $use_footer = false, $return = true){ |
|
| 208 | - $headers = (array) $headers; |
|
| 209 | - $body = (array) $body; |
|
| 210 | - $str = null; |
|
| 211 | - $str .= '<table' . (! empty($attributes['table']) ? attributes_to_string($attributes['table']):'') . '>'; |
|
| 212 | - if(! empty($headers)){ |
|
| 213 | - $str .= '<thead' . (! empty($attributes['thead']) ? attributes_to_string($attributes['thead']):'') .'>'; |
|
| 214 | - $str .= '<tr' . (! empty($attributes['thead_tr']) ? attributes_to_string($attributes['thead_tr']):'') .'>'; |
|
| 215 | - foreach ($headers as $value) { |
|
| 216 | - $str .= '<th' . (! empty($attributes['thead_th']) ? attributes_to_string($attributes['thead_th']):'') .'>' .$value. '</th>'; |
|
| 217 | - } |
|
| 218 | - $str .= '</tr>'; |
|
| 219 | - $str .= '</thead>'; |
|
| 220 | - } |
|
| 221 | - else{ |
|
| 222 | - //no need check for footer |
|
| 223 | - $use_footer = false; |
|
| 224 | - } |
|
| 225 | - $str .= '<tbody' . (! empty($attributes['tbody']) ? attributes_to_string($attributes['tbody']):'') .'>'; |
|
| 226 | - foreach ($body as $row) { |
|
| 227 | - if(is_array($row)){ |
|
| 228 | - $str .= '<tr' . (! empty($attributes['tbody_tr']) ? attributes_to_string($attributes['tbody_tr']):'') .'>'; |
|
| 229 | - foreach ($row as $value) { |
|
| 230 | - $str .= '<td' . (! empty($attributes['tbody_td']) ? attributes_to_string($attributes['tbody_td']):'') .'>' .$value. '</td>'; |
|
| 231 | - } |
|
| 232 | - $str .= '</tr>'; |
|
| 233 | - } |
|
| 234 | - } |
|
| 235 | - $str .= '</tbody>'; |
|
| 236 | - if($use_footer){ |
|
| 237 | - $str .= '<tfoot' . (! empty($attributes['tfoot']) ? attributes_to_string($attributes['tfoot']):'') .'>'; |
|
| 238 | - $str .= '<tr' . (! empty($attributes['tfoot_tr']) ? attributes_to_string($attributes['tfoot_tr']):'') .'>'; |
|
| 239 | - foreach ($headers as $value) { |
|
| 240 | - $str .= '<th' . (! empty($attributes['tfoot_th']) ? attributes_to_string($attributes['tfoot_th']):'') .'>' .$value. '</th>'; |
|
| 241 | - } |
|
| 242 | - $str .= '</tr>'; |
|
| 243 | - $str .= '</tfoot>'; |
|
| 244 | - } |
|
| 245 | - $str .= '</table>'; |
|
| 246 | - if($return){ |
|
| 247 | - return $str; |
|
| 248 | - } |
|
| 249 | - echo $str; |
|
| 250 | - } |
|
| 251 | - } |
|
| 195 | + /** |
|
| 196 | + * Generate the html "table" tag |
|
| 197 | + * @param array $headers the table headers to use between (<thead>) |
|
| 198 | + * @param array $body the table body values between (<tbody>) |
|
| 199 | + * @param array $attributes the table properties attribute use the array index below for each tag: |
|
| 200 | + * for table "table", for thead "thead", for thead tr "thead_tr", |
|
| 201 | + * for thead th "thead_th", for tbody "tbody", for tbody tr "tbody_tr", for tbody td "tbody_td", for tfoot "tfoot", |
|
| 202 | + * for tfoot tr "tfoot_tr", for tfoot th "tfoot_th". |
|
| 203 | + * @param boolean $use_footer whether need to generate table footer (<tfoot>) use the $headers values |
|
| 204 | + * @param boolean $return whether need return the generated html or just display it directly |
|
| 205 | + * @return string|void the generated "table" html if $return is true or display it if not. |
|
| 206 | + */ |
|
| 207 | + public static function table($headers = array(), $body = array(), $attributes = array(), $use_footer = false, $return = true){ |
|
| 208 | + $headers = (array) $headers; |
|
| 209 | + $body = (array) $body; |
|
| 210 | + $str = null; |
|
| 211 | + $str .= '<table' . (! empty($attributes['table']) ? attributes_to_string($attributes['table']):'') . '>'; |
|
| 212 | + if(! empty($headers)){ |
|
| 213 | + $str .= '<thead' . (! empty($attributes['thead']) ? attributes_to_string($attributes['thead']):'') .'>'; |
|
| 214 | + $str .= '<tr' . (! empty($attributes['thead_tr']) ? attributes_to_string($attributes['thead_tr']):'') .'>'; |
|
| 215 | + foreach ($headers as $value) { |
|
| 216 | + $str .= '<th' . (! empty($attributes['thead_th']) ? attributes_to_string($attributes['thead_th']):'') .'>' .$value. '</th>'; |
|
| 217 | + } |
|
| 218 | + $str .= '</tr>'; |
|
| 219 | + $str .= '</thead>'; |
|
| 220 | + } |
|
| 221 | + else{ |
|
| 222 | + //no need check for footer |
|
| 223 | + $use_footer = false; |
|
| 224 | + } |
|
| 225 | + $str .= '<tbody' . (! empty($attributes['tbody']) ? attributes_to_string($attributes['tbody']):'') .'>'; |
|
| 226 | + foreach ($body as $row) { |
|
| 227 | + if(is_array($row)){ |
|
| 228 | + $str .= '<tr' . (! empty($attributes['tbody_tr']) ? attributes_to_string($attributes['tbody_tr']):'') .'>'; |
|
| 229 | + foreach ($row as $value) { |
|
| 230 | + $str .= '<td' . (! empty($attributes['tbody_td']) ? attributes_to_string($attributes['tbody_td']):'') .'>' .$value. '</td>'; |
|
| 231 | + } |
|
| 232 | + $str .= '</tr>'; |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | + $str .= '</tbody>'; |
|
| 236 | + if($use_footer){ |
|
| 237 | + $str .= '<tfoot' . (! empty($attributes['tfoot']) ? attributes_to_string($attributes['tfoot']):'') .'>'; |
|
| 238 | + $str .= '<tr' . (! empty($attributes['tfoot_tr']) ? attributes_to_string($attributes['tfoot_tr']):'') .'>'; |
|
| 239 | + foreach ($headers as $value) { |
|
| 240 | + $str .= '<th' . (! empty($attributes['tfoot_th']) ? attributes_to_string($attributes['tfoot_th']):'') .'>' .$value. '</th>'; |
|
| 241 | + } |
|
| 242 | + $str .= '</tr>'; |
|
| 243 | + $str .= '</tfoot>'; |
|
| 244 | + } |
|
| 245 | + $str .= '</table>'; |
|
| 246 | + if($return){ |
|
| 247 | + return $str; |
|
| 248 | + } |
|
| 249 | + echo $str; |
|
| 250 | + } |
|
| 251 | + } |
|
@@ -1,330 +1,330 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | - class Form{ |
|
| 28 | + class Form{ |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Generate the form opened tag |
|
| 32 | - * @param string $path the form action path |
|
| 33 | - * @param array $attributes the additional form attributes |
|
| 34 | - * @param string $method the form method like 'GET', 'POST' |
|
| 35 | - * @param string $enctype the form enctype like "multipart/form-data" |
|
| 36 | - * @return string the generated form html |
|
| 37 | - */ |
|
| 38 | - public static function open($path = null, array $attributes = array(), $method = 'POST', $enctype = null){ |
|
| 39 | - if($path){ |
|
| 40 | - $path = Url::site_url($path); |
|
| 41 | - } |
|
| 42 | - $method = strtoupper($method); |
|
| 43 | - $str = null; |
|
| 44 | - $str .= '<form action = "'.$path.'" method = "'.$method.'"'; |
|
| 45 | - if(! empty($enctype)){ |
|
| 46 | - $str .= ' enctype = "'.$enctype.'" '; |
|
| 47 | - } |
|
| 48 | - if(! isset($attributes['accept-charset'])){ |
|
| 49 | - $attributes['accept-charset'] = get_config('charset', 'utf-8'); |
|
| 50 | - } |
|
| 51 | - $str .= attributes_to_string($attributes); |
|
| 52 | - $str .= '>'; |
|
| 53 | - $checkCsrf = false; |
|
| 54 | - //check if the user set the checking of CSRF manually |
|
| 55 | - if($method != 'POST' && isset($attributes['csrf'])){ |
|
| 56 | - $obj = & get_instance(); |
|
| 57 | - if(! isset($obj->formvalidation)){ |
|
| 58 | - Loader::library('FormValidation'); |
|
| 59 | - } |
|
| 60 | - $obj->formvalidation->enableCsrfCheck = true; |
|
| 61 | - $checkCsrf = true; |
|
| 62 | - } |
|
| 63 | - //if CSRF enable or is set manually |
|
| 64 | - if((get_config('csrf_enable', false) && $method == 'POST') || ($method != 'POST' && $checkCsrf)){ |
|
| 65 | - $csrfValue = Security::generateCSRF(); |
|
| 66 | - $csrfName = get_config('csrf_key', 'csrf_key'); |
|
| 67 | - $str .= static::hidden($csrfName, $csrfValue); |
|
| 68 | - } |
|
| 69 | - return $str; |
|
| 70 | - } |
|
| 30 | + /** |
|
| 31 | + * Generate the form opened tag |
|
| 32 | + * @param string $path the form action path |
|
| 33 | + * @param array $attributes the additional form attributes |
|
| 34 | + * @param string $method the form method like 'GET', 'POST' |
|
| 35 | + * @param string $enctype the form enctype like "multipart/form-data" |
|
| 36 | + * @return string the generated form html |
|
| 37 | + */ |
|
| 38 | + public static function open($path = null, array $attributes = array(), $method = 'POST', $enctype = null){ |
|
| 39 | + if($path){ |
|
| 40 | + $path = Url::site_url($path); |
|
| 41 | + } |
|
| 42 | + $method = strtoupper($method); |
|
| 43 | + $str = null; |
|
| 44 | + $str .= '<form action = "'.$path.'" method = "'.$method.'"'; |
|
| 45 | + if(! empty($enctype)){ |
|
| 46 | + $str .= ' enctype = "'.$enctype.'" '; |
|
| 47 | + } |
|
| 48 | + if(! isset($attributes['accept-charset'])){ |
|
| 49 | + $attributes['accept-charset'] = get_config('charset', 'utf-8'); |
|
| 50 | + } |
|
| 51 | + $str .= attributes_to_string($attributes); |
|
| 52 | + $str .= '>'; |
|
| 53 | + $checkCsrf = false; |
|
| 54 | + //check if the user set the checking of CSRF manually |
|
| 55 | + if($method != 'POST' && isset($attributes['csrf'])){ |
|
| 56 | + $obj = & get_instance(); |
|
| 57 | + if(! isset($obj->formvalidation)){ |
|
| 58 | + Loader::library('FormValidation'); |
|
| 59 | + } |
|
| 60 | + $obj->formvalidation->enableCsrfCheck = true; |
|
| 61 | + $checkCsrf = true; |
|
| 62 | + } |
|
| 63 | + //if CSRF enable or is set manually |
|
| 64 | + if((get_config('csrf_enable', false) && $method == 'POST') || ($method != 'POST' && $checkCsrf)){ |
|
| 65 | + $csrfValue = Security::generateCSRF(); |
|
| 66 | + $csrfName = get_config('csrf_key', 'csrf_key'); |
|
| 67 | + $str .= static::hidden($csrfName, $csrfValue); |
|
| 68 | + } |
|
| 69 | + return $str; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Generate the form opened tag for multipart like to send a file |
|
| 74 | - * @see Form::open() for more details |
|
| 75 | - * @return string the generated multipart form html |
|
| 76 | - */ |
|
| 77 | - public static function openMultipart($path = null, array $attributes = array(), $method = 'POST'){ |
|
| 78 | - return self::open($path, $attributes, $method, 'multipart/form-data'); |
|
| 79 | - } |
|
| 72 | + /** |
|
| 73 | + * Generate the form opened tag for multipart like to send a file |
|
| 74 | + * @see Form::open() for more details |
|
| 75 | + * @return string the generated multipart form html |
|
| 76 | + */ |
|
| 77 | + public static function openMultipart($path = null, array $attributes = array(), $method = 'POST'){ |
|
| 78 | + return self::open($path, $attributes, $method, 'multipart/form-data'); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Generate the form close |
|
| 83 | - * @return string the form close html |
|
| 84 | - */ |
|
| 85 | - public static function close(){ |
|
| 86 | - return '</form>'; |
|
| 87 | - } |
|
| 81 | + /** |
|
| 82 | + * Generate the form close |
|
| 83 | + * @return string the form close html |
|
| 84 | + */ |
|
| 85 | + public static function close(){ |
|
| 86 | + return '</form>'; |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Generate the form fieldset & legend |
|
| 91 | - * @param string $legend the legend tag value |
|
| 92 | - * @param array $fieldsetAttributes the fieldset additional HTML attributes |
|
| 93 | - * @param array $legendAttributes the legend additional HTML attributes. Is used only is $legend is not empty |
|
| 94 | - * @return string the generated fieldset value |
|
| 95 | - */ |
|
| 96 | - public static function fieldset($legend = '', array $fieldsetAttributes = array(), array $legendAttributes = array()){ |
|
| 97 | - $str = '<fieldset' . attributes_to_string($fieldsetAttributes) . '>'; |
|
| 98 | - if($legend){ |
|
| 99 | - $str .= '<legend' . attributes_to_string($legendAttributes) . '>'.$legend.'</legend>'; |
|
| 100 | - } |
|
| 101 | - return $str; |
|
| 102 | - } |
|
| 89 | + /** |
|
| 90 | + * Generate the form fieldset & legend |
|
| 91 | + * @param string $legend the legend tag value |
|
| 92 | + * @param array $fieldsetAttributes the fieldset additional HTML attributes |
|
| 93 | + * @param array $legendAttributes the legend additional HTML attributes. Is used only is $legend is not empty |
|
| 94 | + * @return string the generated fieldset value |
|
| 95 | + */ |
|
| 96 | + public static function fieldset($legend = '', array $fieldsetAttributes = array(), array $legendAttributes = array()){ |
|
| 97 | + $str = '<fieldset' . attributes_to_string($fieldsetAttributes) . '>'; |
|
| 98 | + if($legend){ |
|
| 99 | + $str .= '<legend' . attributes_to_string($legendAttributes) . '>'.$legend.'</legend>'; |
|
| 100 | + } |
|
| 101 | + return $str; |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * Generate the fieldset close tag |
|
| 106 | - * @return string the generated html for fieldset close |
|
| 107 | - */ |
|
| 108 | - public static function fieldsetClose(){ |
|
| 109 | - return '</fieldset>'; |
|
| 110 | - } |
|
| 104 | + /** |
|
| 105 | + * Generate the fieldset close tag |
|
| 106 | + * @return string the generated html for fieldset close |
|
| 107 | + */ |
|
| 108 | + public static function fieldsetClose(){ |
|
| 109 | + return '</fieldset>'; |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * Get the error message for the given form field name. |
|
| 114 | - * This use the form validation information to get the error information. |
|
| 115 | - * @param string $name the form field name |
|
| 116 | - * @return string the error message if exists and null if not |
|
| 117 | - */ |
|
| 118 | - public static function error($name){ |
|
| 119 | - $return = null; |
|
| 120 | - $obj = & get_instance(); |
|
| 121 | - if(isset($obj->formvalidation)){ |
|
| 122 | - $errors = $obj->formvalidation->returnErrors(); |
|
| 123 | - $error = isset($errors[$name]) ? $errors[$name] : null; |
|
| 124 | - if($error){ |
|
| 125 | - list($errorStart, $errorEnd) = $obj->formvalidation->getErrorDelimiter(); |
|
| 126 | - $return = $errorStart . $error . $errorEnd; |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - return $return; |
|
| 130 | - } |
|
| 112 | + /** |
|
| 113 | + * Get the error message for the given form field name. |
|
| 114 | + * This use the form validation information to get the error information. |
|
| 115 | + * @param string $name the form field name |
|
| 116 | + * @return string the error message if exists and null if not |
|
| 117 | + */ |
|
| 118 | + public static function error($name){ |
|
| 119 | + $return = null; |
|
| 120 | + $obj = & get_instance(); |
|
| 121 | + if(isset($obj->formvalidation)){ |
|
| 122 | + $errors = $obj->formvalidation->returnErrors(); |
|
| 123 | + $error = isset($errors[$name]) ? $errors[$name] : null; |
|
| 124 | + if($error){ |
|
| 125 | + list($errorStart, $errorEnd) = $obj->formvalidation->getErrorDelimiter(); |
|
| 126 | + $return = $errorStart . $error . $errorEnd; |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + return $return; |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - /** |
|
| 133 | - * Get the form field value |
|
| 134 | - * @param string $name the form field name |
|
| 135 | - * @param mixed $default the default value if can not found the given form field name |
|
| 136 | - * @return mixed the form field value if is set, otherwise return the default value. |
|
| 137 | - */ |
|
| 138 | - public static function value($name, $default = null){ |
|
| 139 | - $value = get_instance()->request->query($name); |
|
| 140 | - return $value ? $value : $default; |
|
| 141 | - } |
|
| 132 | + /** |
|
| 133 | + * Get the form field value |
|
| 134 | + * @param string $name the form field name |
|
| 135 | + * @param mixed $default the default value if can not found the given form field name |
|
| 136 | + * @return mixed the form field value if is set, otherwise return the default value. |
|
| 137 | + */ |
|
| 138 | + public static function value($name, $default = null){ |
|
| 139 | + $value = get_instance()->request->query($name); |
|
| 140 | + return $value ? $value : $default; |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - /** |
|
| 144 | - * Generate the form label html content |
|
| 145 | - * @param string $label the title of the label |
|
| 146 | - * @param string $for the value of the label "for" attribute |
|
| 147 | - * @param array $attributes the additional attributes to be added |
|
| 148 | - * @return string the generated label html content |
|
| 149 | - */ |
|
| 150 | - public static function label($label, $for = '', array $attributes = array()){ |
|
| 151 | - $str = '<label'; |
|
| 152 | - if($for){ |
|
| 153 | - $str .= ' for = "'.$for.'"'; |
|
| 154 | - } |
|
| 155 | - $str .= attributes_to_string($attributes); |
|
| 156 | - $str .= '>'; |
|
| 157 | - $str .= $label.'</label>'; |
|
| 158 | - return $str; |
|
| 159 | - } |
|
| 143 | + /** |
|
| 144 | + * Generate the form label html content |
|
| 145 | + * @param string $label the title of the label |
|
| 146 | + * @param string $for the value of the label "for" attribute |
|
| 147 | + * @param array $attributes the additional attributes to be added |
|
| 148 | + * @return string the generated label html content |
|
| 149 | + */ |
|
| 150 | + public static function label($label, $for = '', array $attributes = array()){ |
|
| 151 | + $str = '<label'; |
|
| 152 | + if($for){ |
|
| 153 | + $str .= ' for = "'.$for.'"'; |
|
| 154 | + } |
|
| 155 | + $str .= attributes_to_string($attributes); |
|
| 156 | + $str .= '>'; |
|
| 157 | + $str .= $label.'</label>'; |
|
| 158 | + return $str; |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - /** |
|
| 162 | - * Generate the form field for input like "text", "email", "password", etc. |
|
| 163 | - * @param string $name the form field name |
|
| 164 | - * @param mixed $value the form field value to be set |
|
| 165 | - * @param array $attributes the additional attributes to be added in the form input |
|
| 166 | - * @param string $type the type of the form field (password, text, submit, button, etc.) |
|
| 167 | - * @return string the generated form field html content for the input |
|
| 168 | - */ |
|
| 169 | - public static function input($name, $value = null, array $attributes = array(), $type = 'text'){ |
|
| 170 | - $str = null; |
|
| 171 | - $str .= '<input name = "'.$name.'" value = "'.$value.'" type = "'.$type.'"'; |
|
| 172 | - $str .= attributes_to_string($attributes); |
|
| 173 | - $str .= '/>'; |
|
| 174 | - return $str; |
|
| 175 | - } |
|
| 161 | + /** |
|
| 162 | + * Generate the form field for input like "text", "email", "password", etc. |
|
| 163 | + * @param string $name the form field name |
|
| 164 | + * @param mixed $value the form field value to be set |
|
| 165 | + * @param array $attributes the additional attributes to be added in the form input |
|
| 166 | + * @param string $type the type of the form field (password, text, submit, button, etc.) |
|
| 167 | + * @return string the generated form field html content for the input |
|
| 168 | + */ |
|
| 169 | + public static function input($name, $value = null, array $attributes = array(), $type = 'text'){ |
|
| 170 | + $str = null; |
|
| 171 | + $str .= '<input name = "'.$name.'" value = "'.$value.'" type = "'.$type.'"'; |
|
| 172 | + $str .= attributes_to_string($attributes); |
|
| 173 | + $str .= '/>'; |
|
| 174 | + return $str; |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - /** |
|
| 178 | - * Generate the form field for "text" |
|
| 179 | - * @see Form::input() for more details |
|
| 180 | - */ |
|
| 181 | - public static function text($name, $value = null, array $attributes = array()){ |
|
| 182 | - return self::input($name, $value, $attributes, 'text'); |
|
| 183 | - } |
|
| 177 | + /** |
|
| 178 | + * Generate the form field for "text" |
|
| 179 | + * @see Form::input() for more details |
|
| 180 | + */ |
|
| 181 | + public static function text($name, $value = null, array $attributes = array()){ |
|
| 182 | + return self::input($name, $value, $attributes, 'text'); |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - /** |
|
| 186 | - * Generate the form field for "password" |
|
| 187 | - * @see Form::input() for more details |
|
| 188 | - */ |
|
| 189 | - public static function password($name, $value = null, array $attributes = array()){ |
|
| 190 | - return self::input($name, $value, $attributes, 'password'); |
|
| 191 | - } |
|
| 185 | + /** |
|
| 186 | + * Generate the form field for "password" |
|
| 187 | + * @see Form::input() for more details |
|
| 188 | + */ |
|
| 189 | + public static function password($name, $value = null, array $attributes = array()){ |
|
| 190 | + return self::input($name, $value, $attributes, 'password'); |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | - /** |
|
| 194 | - * Generate the form field for "radio" |
|
| 195 | - * @see Form::input() for more details |
|
| 196 | - */ |
|
| 197 | - public static function radio($name, $value = null, $checked = false, array $attributes = array()){ |
|
| 198 | - if($checked){ |
|
| 199 | - $attributes['checked'] = true; |
|
| 200 | - } |
|
| 201 | - return self::input($name, $value, $attributes, 'radio'); |
|
| 202 | - } |
|
| 193 | + /** |
|
| 194 | + * Generate the form field for "radio" |
|
| 195 | + * @see Form::input() for more details |
|
| 196 | + */ |
|
| 197 | + public static function radio($name, $value = null, $checked = false, array $attributes = array()){ |
|
| 198 | + if($checked){ |
|
| 199 | + $attributes['checked'] = true; |
|
| 200 | + } |
|
| 201 | + return self::input($name, $value, $attributes, 'radio'); |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - /** |
|
| 205 | - * Generate the form field for "checkbox" |
|
| 206 | - * @see Form::input() for more details |
|
| 207 | - */ |
|
| 208 | - public static function checkbox($name, $value = null, $checked = false, array $attributes = array()){ |
|
| 209 | - if($checked){ |
|
| 210 | - $attributes['checked'] = true; |
|
| 211 | - } |
|
| 212 | - return self::input($name, $value, $attributes, 'checkbox'); |
|
| 213 | - } |
|
| 204 | + /** |
|
| 205 | + * Generate the form field for "checkbox" |
|
| 206 | + * @see Form::input() for more details |
|
| 207 | + */ |
|
| 208 | + public static function checkbox($name, $value = null, $checked = false, array $attributes = array()){ |
|
| 209 | + if($checked){ |
|
| 210 | + $attributes['checked'] = true; |
|
| 211 | + } |
|
| 212 | + return self::input($name, $value, $attributes, 'checkbox'); |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - /** |
|
| 216 | - * Generate the form field for "number" |
|
| 217 | - * @see Form::input() for more details |
|
| 218 | - */ |
|
| 219 | - public static function number($name, $value = null, array $attributes = array()){ |
|
| 220 | - return self::input($name, $value, $attributes, 'number'); |
|
| 221 | - } |
|
| 215 | + /** |
|
| 216 | + * Generate the form field for "number" |
|
| 217 | + * @see Form::input() for more details |
|
| 218 | + */ |
|
| 219 | + public static function number($name, $value = null, array $attributes = array()){ |
|
| 220 | + return self::input($name, $value, $attributes, 'number'); |
|
| 221 | + } |
|
| 222 | 222 | |
| 223 | - /** |
|
| 224 | - * Generate the form field for "phone" |
|
| 225 | - * @see Form::input() for more details |
|
| 226 | - */ |
|
| 227 | - public static function phone($name, $value = null, array $attributes = array()){ |
|
| 228 | - return self::input($name, $value, $attributes, 'phone'); |
|
| 229 | - } |
|
| 223 | + /** |
|
| 224 | + * Generate the form field for "phone" |
|
| 225 | + * @see Form::input() for more details |
|
| 226 | + */ |
|
| 227 | + public static function phone($name, $value = null, array $attributes = array()){ |
|
| 228 | + return self::input($name, $value, $attributes, 'phone'); |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | - /** |
|
| 232 | - * Generate the form field for "email" |
|
| 233 | - * @see Form::input() for more details |
|
| 234 | - */ |
|
| 235 | - public static function email($name, $value = null, array $attributes = array()){ |
|
| 236 | - return self::input($name, $value, $attributes, 'email'); |
|
| 237 | - } |
|
| 231 | + /** |
|
| 232 | + * Generate the form field for "email" |
|
| 233 | + * @see Form::input() for more details |
|
| 234 | + */ |
|
| 235 | + public static function email($name, $value = null, array $attributes = array()){ |
|
| 236 | + return self::input($name, $value, $attributes, 'email'); |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | - /** |
|
| 240 | - * Generate the form field for "search" |
|
| 241 | - * @see Form::input() for more details |
|
| 242 | - */ |
|
| 243 | - public static function search($name, $value = null, array $attributes = array()){ |
|
| 244 | - return self::input($name, $value, $attributes, 'search'); |
|
| 245 | - } |
|
| 239 | + /** |
|
| 240 | + * Generate the form field for "search" |
|
| 241 | + * @see Form::input() for more details |
|
| 242 | + */ |
|
| 243 | + public static function search($name, $value = null, array $attributes = array()){ |
|
| 244 | + return self::input($name, $value, $attributes, 'search'); |
|
| 245 | + } |
|
| 246 | 246 | |
| 247 | - /** |
|
| 248 | - * Generate the form field for "hidden" |
|
| 249 | - * @see Form::input() for more details |
|
| 250 | - */ |
|
| 251 | - public static function hidden($name, $value = null, array $attributes = array()){ |
|
| 252 | - return self::input($name, $value, $attributes, 'hidden'); |
|
| 253 | - } |
|
| 247 | + /** |
|
| 248 | + * Generate the form field for "hidden" |
|
| 249 | + * @see Form::input() for more details |
|
| 250 | + */ |
|
| 251 | + public static function hidden($name, $value = null, array $attributes = array()){ |
|
| 252 | + return self::input($name, $value, $attributes, 'hidden'); |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - /** |
|
| 256 | - * Generate the form field for "file" |
|
| 257 | - * @see Form::input() for more details |
|
| 258 | - */ |
|
| 259 | - public static function file($name, array $attributes = array()){ |
|
| 260 | - return self::input($name, null, $attributes, 'file'); |
|
| 261 | - } |
|
| 255 | + /** |
|
| 256 | + * Generate the form field for "file" |
|
| 257 | + * @see Form::input() for more details |
|
| 258 | + */ |
|
| 259 | + public static function file($name, array $attributes = array()){ |
|
| 260 | + return self::input($name, null, $attributes, 'file'); |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | - /** |
|
| 264 | - * Generate the form field for "button" |
|
| 265 | - * @see Form::input() for more details |
|
| 266 | - */ |
|
| 267 | - public static function button($name, $value = null, array $attributes = array()){ |
|
| 268 | - return self::input($name, $value, $attributes, 'button'); |
|
| 269 | - } |
|
| 263 | + /** |
|
| 264 | + * Generate the form field for "button" |
|
| 265 | + * @see Form::input() for more details |
|
| 266 | + */ |
|
| 267 | + public static function button($name, $value = null, array $attributes = array()){ |
|
| 268 | + return self::input($name, $value, $attributes, 'button'); |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | - /** |
|
| 272 | - * Generate the form field for "reset" |
|
| 273 | - * @see Form::input() for more details |
|
| 274 | - */ |
|
| 275 | - public static function reset($name, $value = null, array $attributes = array()){ |
|
| 276 | - return self::input($name, $value, $attributes, 'reset'); |
|
| 277 | - } |
|
| 271 | + /** |
|
| 272 | + * Generate the form field for "reset" |
|
| 273 | + * @see Form::input() for more details |
|
| 274 | + */ |
|
| 275 | + public static function reset($name, $value = null, array $attributes = array()){ |
|
| 276 | + return self::input($name, $value, $attributes, 'reset'); |
|
| 277 | + } |
|
| 278 | 278 | |
| 279 | - /** |
|
| 280 | - * Generate the form field for "submit" |
|
| 281 | - * @see Form::input() for more details |
|
| 282 | - */ |
|
| 283 | - public static function submit($name, $value = null, array $attributes = array()){ |
|
| 284 | - return self::input($name, $value, $attributes, 'submit'); |
|
| 285 | - } |
|
| 279 | + /** |
|
| 280 | + * Generate the form field for "submit" |
|
| 281 | + * @see Form::input() for more details |
|
| 282 | + */ |
|
| 283 | + public static function submit($name, $value = null, array $attributes = array()){ |
|
| 284 | + return self::input($name, $value, $attributes, 'submit'); |
|
| 285 | + } |
|
| 286 | 286 | |
| 287 | - /** |
|
| 288 | - * Generate the form field for textarea |
|
| 289 | - * @param string $name the name of the textarea field |
|
| 290 | - * @param string $value the textarea field value |
|
| 291 | - * @param array $attributes the additional attributes to be added |
|
| 292 | - * @return string the generated textarea form html content |
|
| 293 | - */ |
|
| 294 | - public static function textarea($name, $value = '', array $attributes = array()){ |
|
| 295 | - $str = null; |
|
| 296 | - $str .= '<textarea name = "'.$name.'"'; |
|
| 297 | - $str .= attributes_to_string($attributes); |
|
| 298 | - $str .= '>'; |
|
| 299 | - $str .= $value.'</textarea>'; |
|
| 300 | - return $str; |
|
| 301 | - } |
|
| 287 | + /** |
|
| 288 | + * Generate the form field for textarea |
|
| 289 | + * @param string $name the name of the textarea field |
|
| 290 | + * @param string $value the textarea field value |
|
| 291 | + * @param array $attributes the additional attributes to be added |
|
| 292 | + * @return string the generated textarea form html content |
|
| 293 | + */ |
|
| 294 | + public static function textarea($name, $value = '', array $attributes = array()){ |
|
| 295 | + $str = null; |
|
| 296 | + $str .= '<textarea name = "'.$name.'"'; |
|
| 297 | + $str .= attributes_to_string($attributes); |
|
| 298 | + $str .= '>'; |
|
| 299 | + $str .= $value.'</textarea>'; |
|
| 300 | + return $str; |
|
| 301 | + } |
|
| 302 | 302 | |
| 303 | - /** |
|
| 304 | - * Generate the form field for select |
|
| 305 | - * @param string $name the name of the form field |
|
| 306 | - * @param mixed|array $values the values used to populate the "option" tags |
|
| 307 | - * @param mixed $selected the selected value in the option list |
|
| 308 | - * @param array $attributes the additional attribute to be added |
|
| 309 | - * @return string the generated form field html content for select |
|
| 310 | - */ |
|
| 311 | - public static function select($name, $values = null, $selected = null, array $attributes = array()){ |
|
| 312 | - if(! is_array($values)){ |
|
| 313 | - $values = array('' => $values); |
|
| 314 | - } |
|
| 315 | - $str = null; |
|
| 316 | - $str .= '<select name = "'.$name.'"'; |
|
| 317 | - $str .= attributes_to_string($attributes); |
|
| 318 | - $str .= '>'; |
|
| 319 | - foreach($values as $key => $val){ |
|
| 320 | - $select = ''; |
|
| 321 | - if($key == $selected){ |
|
| 322 | - $select = 'selected'; |
|
| 323 | - } |
|
| 324 | - $str .= '<option value = "'.$key.'" '.$select.'>'.$val.'</option>'; |
|
| 325 | - } |
|
| 326 | - $str .= '</select>'; |
|
| 327 | - return $str; |
|
| 328 | - } |
|
| 303 | + /** |
|
| 304 | + * Generate the form field for select |
|
| 305 | + * @param string $name the name of the form field |
|
| 306 | + * @param mixed|array $values the values used to populate the "option" tags |
|
| 307 | + * @param mixed $selected the selected value in the option list |
|
| 308 | + * @param array $attributes the additional attribute to be added |
|
| 309 | + * @return string the generated form field html content for select |
|
| 310 | + */ |
|
| 311 | + public static function select($name, $values = null, $selected = null, array $attributes = array()){ |
|
| 312 | + if(! is_array($values)){ |
|
| 313 | + $values = array('' => $values); |
|
| 314 | + } |
|
| 315 | + $str = null; |
|
| 316 | + $str .= '<select name = "'.$name.'"'; |
|
| 317 | + $str .= attributes_to_string($attributes); |
|
| 318 | + $str .= '>'; |
|
| 319 | + foreach($values as $key => $val){ |
|
| 320 | + $select = ''; |
|
| 321 | + if($key == $selected){ |
|
| 322 | + $select = 'selected'; |
|
| 323 | + } |
|
| 324 | + $str .= '<option value = "'.$key.'" '.$select.'>'.$val.'</option>'; |
|
| 325 | + } |
|
| 326 | + $str .= '</select>'; |
|
| 327 | + return $str; |
|
| 328 | + } |
|
| 329 | 329 | |
| 330 | - } |
|
| 330 | + } |
|
@@ -1,195 +1,195 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @file bootstrap.php |
|
| 29 | - * |
|
| 30 | - * Contains the loading process: loading of constants, common functions, libraries |
|
| 31 | - * configurations, etc |
|
| 32 | - * verification of the environment and the routing of the request. |
|
| 33 | - * |
|
| 34 | - * @package core |
|
| 35 | - * @author Tony NGUEREZA |
|
| 36 | - * @copyright Copyright (c) 2017 |
|
| 37 | - * @license https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL) |
|
| 38 | - * @link http://www.iacademy.cf |
|
| 39 | - * @version 1.0.0 |
|
| 40 | - * @filesource |
|
| 41 | - */ |
|
| 27 | + /** |
|
| 28 | + * @file bootstrap.php |
|
| 29 | + * |
|
| 30 | + * Contains the loading process: loading of constants, common functions, libraries |
|
| 31 | + * configurations, etc |
|
| 32 | + * verification of the environment and the routing of the request. |
|
| 33 | + * |
|
| 34 | + * @package core |
|
| 35 | + * @author Tony NGUEREZA |
|
| 36 | + * @copyright Copyright (c) 2017 |
|
| 37 | + * @license https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL) |
|
| 38 | + * @link http://www.iacademy.cf |
|
| 39 | + * @version 1.0.0 |
|
| 40 | + * @filesource |
|
| 41 | + */ |
|
| 42 | 42 | |
| 43 | - //if the application is running in CLI mode $_SESSION global variable is not available |
|
| 44 | - if(IS_CLI){ |
|
| 45 | - $_SESSION = array(); |
|
| 46 | - } |
|
| 43 | + //if the application is running in CLI mode $_SESSION global variable is not available |
|
| 44 | + if(IS_CLI){ |
|
| 45 | + $_SESSION = array(); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * inclusion of global constants of the environment that contain : name of the framework, |
|
| 50 | - * version, release date, version of PHP required, etc. |
|
| 51 | - */ |
|
| 52 | - require_once CORE_PATH . 'constants.php'; |
|
| 48 | + /** |
|
| 49 | + * inclusion of global constants of the environment that contain : name of the framework, |
|
| 50 | + * version, release date, version of PHP required, etc. |
|
| 51 | + */ |
|
| 52 | + require_once CORE_PATH . 'constants.php'; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * include file containing commons functions used in the framework such: show_error, |
|
| 56 | - * php_exception_handler, php_error_handler, get_instance, etc. |
|
| 57 | - */ |
|
| 58 | - require_once CORE_PATH . 'common.php'; |
|
| 54 | + /** |
|
| 55 | + * include file containing commons functions used in the framework such: show_error, |
|
| 56 | + * php_exception_handler, php_error_handler, get_instance, etc. |
|
| 57 | + */ |
|
| 58 | + require_once CORE_PATH . 'common.php'; |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * The Benchmark class |
|
| 62 | - */ |
|
| 63 | - $BENCHMARK =& class_loader('Benchmark'); |
|
| 60 | + /** |
|
| 61 | + * The Benchmark class |
|
| 62 | + */ |
|
| 63 | + $BENCHMARK =& class_loader('Benchmark'); |
|
| 64 | 64 | |
| 65 | - $BENCHMARK->mark('APP_EXECUTION_START'); |
|
| 65 | + $BENCHMARK->mark('APP_EXECUTION_START'); |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * instance of the Log class |
|
| 69 | - */ |
|
| 67 | + /** |
|
| 68 | + * instance of the Log class |
|
| 69 | + */ |
|
| 70 | 70 | $LOGGER =& class_loader('Log', 'classes'); |
| 71 | 71 | |
| 72 | 72 | $LOGGER->setLogger('ApplicationBootstrap'); |
| 73 | 73 | |
| 74 | 74 | $LOGGER->debug('Checking PHP version ...'); |
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * Verification of the PHP environment: minimum and maximum version |
|
| 78 | - */ |
|
| 79 | - if (version_compare(phpversion(), TNH_REQUIRED_PHP_MIN_VERSION, '<')){ |
|
| 80 | - show_error('Your PHP Version [' . phpversion() . '] is less than [' . TNH_REQUIRED_PHP_MIN_VERSION . '], please install a new version or update your PHP to the latest.', 'PHP Error environment'); |
|
| 81 | - } |
|
| 82 | - else if(version_compare(phpversion(), TNH_REQUIRED_PHP_MAX_VERSION, '>')){ |
|
| 83 | - show_error('Your PHP Version [' . phpversion() . '] is greather than [' . TNH_REQUIRED_PHP_MAX_VERSION . '] please install a PHP version that is compatible.', 'PHP Error environment'); |
|
| 84 | - } |
|
| 85 | - $LOGGER->info('PHP version [' . phpversion() . '] is OK [REQUIRED MINIMUM: ' . TNH_REQUIRED_PHP_MIN_VERSION . ', REQUIRED MAXIMUM: ' . TNH_REQUIRED_PHP_MAX_VERSION . '], application can work without any issue'); |
|
| 76 | + /** |
|
| 77 | + * Verification of the PHP environment: minimum and maximum version |
|
| 78 | + */ |
|
| 79 | + if (version_compare(phpversion(), TNH_REQUIRED_PHP_MIN_VERSION, '<')){ |
|
| 80 | + show_error('Your PHP Version [' . phpversion() . '] is less than [' . TNH_REQUIRED_PHP_MIN_VERSION . '], please install a new version or update your PHP to the latest.', 'PHP Error environment'); |
|
| 81 | + } |
|
| 82 | + else if(version_compare(phpversion(), TNH_REQUIRED_PHP_MAX_VERSION, '>')){ |
|
| 83 | + show_error('Your PHP Version [' . phpversion() . '] is greather than [' . TNH_REQUIRED_PHP_MAX_VERSION . '] please install a PHP version that is compatible.', 'PHP Error environment'); |
|
| 84 | + } |
|
| 85 | + $LOGGER->info('PHP version [' . phpversion() . '] is OK [REQUIRED MINIMUM: ' . TNH_REQUIRED_PHP_MIN_VERSION . ', REQUIRED MAXIMUM: ' . TNH_REQUIRED_PHP_MAX_VERSION . '], application can work without any issue'); |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Setting of the PHP error message handling function |
|
| 89 | - */ |
|
| 90 | - set_error_handler('php_error_handler'); |
|
| 87 | + /** |
|
| 88 | + * Setting of the PHP error message handling function |
|
| 89 | + */ |
|
| 90 | + set_error_handler('php_error_handler'); |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * Setting of the PHP error exception handling function |
|
| 94 | - */ |
|
| 95 | - set_exception_handler('php_exception_handler'); |
|
| 92 | + /** |
|
| 93 | + * Setting of the PHP error exception handling function |
|
| 94 | + */ |
|
| 95 | + set_exception_handler('php_exception_handler'); |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * Setting of the PHP shutdown handling function |
|
| 99 | - */ |
|
| 100 | - register_shutdown_function('php_shudown_handler'); |
|
| 97 | + /** |
|
| 98 | + * Setting of the PHP shutdown handling function |
|
| 99 | + */ |
|
| 100 | + register_shutdown_function('php_shudown_handler'); |
|
| 101 | 101 | |
| 102 | - //if user have some composer packages |
|
| 103 | - $LOGGER->debug('Check for composer autoload'); |
|
| 104 | - if(file_exists(VENDOR_PATH . 'autoload.php')){ |
|
| 105 | - $LOGGER->info('The composer autoload file exists include it'); |
|
| 106 | - require_once VENDOR_PATH . 'autoload.php'; |
|
| 107 | - } |
|
| 108 | - else{ |
|
| 109 | - $LOGGER->info('The composer autoload file does not exist skipping'); |
|
| 110 | - } |
|
| 102 | + //if user have some composer packages |
|
| 103 | + $LOGGER->debug('Check for composer autoload'); |
|
| 104 | + if(file_exists(VENDOR_PATH . 'autoload.php')){ |
|
| 105 | + $LOGGER->info('The composer autoload file exists include it'); |
|
| 106 | + require_once VENDOR_PATH . 'autoload.php'; |
|
| 107 | + } |
|
| 108 | + else{ |
|
| 109 | + $LOGGER->info('The composer autoload file does not exist skipping'); |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - $LOGGER->debug('Begin to load the required resources'); |
|
| 112 | + $LOGGER->debug('Begin to load the required resources'); |
|
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * Load the EventInfo class file |
|
| 116 | - */ |
|
| 117 | - require_once CORE_CLASSES_PATH . 'EventInfo.php'; |
|
| 114 | + /** |
|
| 115 | + * Load the EventInfo class file |
|
| 116 | + */ |
|
| 117 | + require_once CORE_CLASSES_PATH . 'EventInfo.php'; |
|
| 118 | 118 | |
| 119 | 119 | |
| 120 | - $BENCHMARK->mark('CONFIG_INIT_START'); |
|
| 121 | - /** |
|
| 122 | - * Load configurations and using the |
|
| 123 | - * static method "init()" to initialize the Config class . |
|
| 124 | - */ |
|
| 125 | - $CONFIG =& class_loader('Config', 'classes'); |
|
| 126 | - $CONFIG->init(); |
|
| 127 | - $BENCHMARK->mark('CONFIG_INIT_END'); |
|
| 120 | + $BENCHMARK->mark('CONFIG_INIT_START'); |
|
| 121 | + /** |
|
| 122 | + * Load configurations and using the |
|
| 123 | + * static method "init()" to initialize the Config class . |
|
| 124 | + */ |
|
| 125 | + $CONFIG =& class_loader('Config', 'classes'); |
|
| 126 | + $CONFIG->init(); |
|
| 127 | + $BENCHMARK->mark('CONFIG_INIT_END'); |
|
| 128 | 128 | |
| 129 | - $BENCHMARK->mark('MODULE_INIT_START'); |
|
| 130 | - /** |
|
| 131 | - * Load modules and using the |
|
| 132 | - * static method "init()" to initialize the Module class. |
|
| 133 | - */ |
|
| 134 | - $MODULE =& class_loader('Module', 'classes'); |
|
| 135 | - $MODULE->init(); |
|
| 136 | - $BENCHMARK->mark('MODULE_INIT_END'); |
|
| 129 | + $BENCHMARK->mark('MODULE_INIT_START'); |
|
| 130 | + /** |
|
| 131 | + * Load modules and using the |
|
| 132 | + * static method "init()" to initialize the Module class. |
|
| 133 | + */ |
|
| 134 | + $MODULE =& class_loader('Module', 'classes'); |
|
| 135 | + $MODULE->init(); |
|
| 136 | + $BENCHMARK->mark('MODULE_INIT_END'); |
|
| 137 | 137 | |
| 138 | - $LOGGER->debug('Loading Base Controller ...'); |
|
| 139 | - /** |
|
| 140 | - * Include of the file containing the Base Controller class |
|
| 141 | - */ |
|
| 142 | - require_once CORE_CLASSES_PATH . 'Controller.php'; |
|
| 143 | - $LOGGER->info('Base Controller loaded successfully'); |
|
| 138 | + $LOGGER->debug('Loading Base Controller ...'); |
|
| 139 | + /** |
|
| 140 | + * Include of the file containing the Base Controller class |
|
| 141 | + */ |
|
| 142 | + require_once CORE_CLASSES_PATH . 'Controller.php'; |
|
| 143 | + $LOGGER->info('Base Controller loaded successfully'); |
|
| 144 | 144 | |
| 145 | - /** |
|
| 146 | - * Register controllers autoload function |
|
| 147 | - */ |
|
| 148 | - spl_autoload_register('autoload_controller'); |
|
| 145 | + /** |
|
| 146 | + * Register controllers autoload function |
|
| 147 | + */ |
|
| 148 | + spl_autoload_register('autoload_controller'); |
|
| 149 | 149 | |
| 150 | - /** |
|
| 151 | - * Loading Security class |
|
| 152 | - */ |
|
| 153 | - $SECURITY =& class_loader('Security', 'classes'); |
|
| 154 | - $SECURITY->checkWhiteListIpAccess(); |
|
| 150 | + /** |
|
| 151 | + * Loading Security class |
|
| 152 | + */ |
|
| 153 | + $SECURITY =& class_loader('Security', 'classes'); |
|
| 154 | + $SECURITY->checkWhiteListIpAccess(); |
|
| 155 | 155 | |
| 156 | - /** |
|
| 157 | - * Loading Url class |
|
| 158 | - */ |
|
| 159 | - $URL =& class_loader('Url', 'classes'); |
|
| 156 | + /** |
|
| 157 | + * Loading Url class |
|
| 158 | + */ |
|
| 159 | + $URL =& class_loader('Url', 'classes'); |
|
| 160 | 160 | |
| 161 | - if(get_config('cache_enable', false)){ |
|
| 162 | - /** |
|
| 163 | - * Load Cache interface file |
|
| 164 | - */ |
|
| 165 | - require_once CORE_CLASSES_CACHE_PATH . 'CacheInterface.php'; |
|
| 166 | - $cacheHandler = get_config('cache_handler'); |
|
| 167 | - if(! $cacheHandler){ |
|
| 168 | - show_error('The cache feature is enabled in the configuration but the cache handler class is not set.'); |
|
| 169 | - } |
|
| 170 | - $CACHE = null; |
|
| 171 | - //first check if the cache handler is the system driver |
|
| 172 | - if(file_exists(CORE_CLASSES_CACHE_PATH . $cacheHandler . '.php')){ |
|
| 173 | - $CACHE =& class_loader($cacheHandler, 'classes/cache'); |
|
| 174 | - } |
|
| 175 | - else{ |
|
| 176 | - //it's not a system driver use user library |
|
| 177 | - $CACHE =& class_loader($cacheHandler); |
|
| 178 | - } |
|
| 179 | - //check if the page already cached |
|
| 180 | - if(! empty($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'get'){ |
|
| 181 | - $RESPONSE = & class_loader('Response', 'classes'); |
|
| 182 | - $RESPONSE->renderFinalPageFromCache($CACHE); |
|
| 183 | - } |
|
| 184 | - } |
|
| 161 | + if(get_config('cache_enable', false)){ |
|
| 162 | + /** |
|
| 163 | + * Load Cache interface file |
|
| 164 | + */ |
|
| 165 | + require_once CORE_CLASSES_CACHE_PATH . 'CacheInterface.php'; |
|
| 166 | + $cacheHandler = get_config('cache_handler'); |
|
| 167 | + if(! $cacheHandler){ |
|
| 168 | + show_error('The cache feature is enabled in the configuration but the cache handler class is not set.'); |
|
| 169 | + } |
|
| 170 | + $CACHE = null; |
|
| 171 | + //first check if the cache handler is the system driver |
|
| 172 | + if(file_exists(CORE_CLASSES_CACHE_PATH . $cacheHandler . '.php')){ |
|
| 173 | + $CACHE =& class_loader($cacheHandler, 'classes/cache'); |
|
| 174 | + } |
|
| 175 | + else{ |
|
| 176 | + //it's not a system driver use user library |
|
| 177 | + $CACHE =& class_loader($cacheHandler); |
|
| 178 | + } |
|
| 179 | + //check if the page already cached |
|
| 180 | + if(! empty($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'get'){ |
|
| 181 | + $RESPONSE = & class_loader('Response', 'classes'); |
|
| 182 | + $RESPONSE->renderFinalPageFromCache($CACHE); |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | 185 | |
| 186 | - //load model class |
|
| 187 | - require_once CORE_CLASSES_MODEL_PATH . 'Model.php'; |
|
| 186 | + //load model class |
|
| 187 | + require_once CORE_CLASSES_MODEL_PATH . 'Model.php'; |
|
| 188 | 188 | |
| 189 | - $LOGGER->info('Everything is OK load Router library and dispatch the request to the corresponding controller'); |
|
| 190 | - /** |
|
| 191 | - * Routing |
|
| 192 | - * instantiation of the "Router" class and user request routing processing. |
|
| 193 | - */ |
|
| 194 | - $ROUTER = & class_loader('Router', 'classes'); |
|
| 195 | - $ROUTER->run(); |
|
| 189 | + $LOGGER->info('Everything is OK load Router library and dispatch the request to the corresponding controller'); |
|
| 190 | + /** |
|
| 191 | + * Routing |
|
| 192 | + * instantiation of the "Router" class and user request routing processing. |
|
| 193 | + */ |
|
| 194 | + $ROUTER = & class_loader('Router', 'classes'); |
|
| 195 | + $ROUTER->run(); |
|