Passed
Push — 1.0.0-dev ( 93958a...e1c8ef )
by nguereza
02:26
created
core/bootstrap.php 1 patch
Indentation   +189 added lines, -189 removed lines patch added patch discarded remove patch
@@ -1,207 +1,207 @@
 block discarded – undo
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
-	*/
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
-	 */
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
+
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';
59
-
60
-	/**
61
-	 * Include of the file containing the BaseClass 
62
-	 */
63
-	require_once CORE_CLASSES_PATH . 'BaseClass.php';
64
-
65
-	/**
66
-	 * Include of the file containing the BaseClass 
67
-	 */
68
-	require_once CORE_CLASSES_PATH . 'BaseStaticClass.php';
69
-
70
-	/**
71
-	 * The Benchmark class
72
-	 */
73
-	$BENCHMARK =& class_loader('Benchmark');
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
+
60
+    /**
61
+     * Include of the file containing the BaseClass 
62
+     */
63
+    require_once CORE_CLASSES_PATH . 'BaseClass.php';
64
+
65
+    /**
66
+     * Include of the file containing the BaseClass 
67
+     */
68
+    require_once CORE_CLASSES_PATH . 'BaseStaticClass.php';
69
+
70
+    /**
71
+     * The Benchmark class
72
+     */
73
+    $BENCHMARK =& class_loader('Benchmark');
74 74
 	
75
-	$BENCHMARK->mark('APP_EXECUTION_START');
75
+    $BENCHMARK->mark('APP_EXECUTION_START');
76 76
 	
77
-	/**
78
-    * instance of the Log class
79
-    */
77
+    /**
78
+     * instance of the Log class
79
+     */
80 80
     $LOGGER =& class_loader('Log', 'classes');
81 81
 
82 82
     $LOGGER->setLogger('ApplicationBootstrap');
83 83
 
84 84
     $LOGGER->debug('Checking PHP version ...');	
85 85
 	
86
-	/**
87
-	* Verification of the PHP environment: minimum and maximum version
88
-	*/
89
-	if (version_compare(phpversion(), TNH_REQUIRED_PHP_MIN_VERSION, '<')){
90
-		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');	
91
-	}
92
-	else if(version_compare(phpversion(), TNH_REQUIRED_PHP_MAX_VERSION, '>')){
93
-		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');	
94
-	}
95
-	$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');
96
-
97
-	/**
98
-	* Setting of the PHP error message handling function
99
-	*/
100
-	set_error_handler('php_error_handler');
101
-
102
-	/**
103
-	* Setting of the PHP error exception handling function
104
-	*/
105
-	set_exception_handler('php_exception_handler');
106
-
107
-	/**
108
-	 * Setting of the PHP shutdown handling function
109
-	 */
110
-	register_shutdown_function('php_shudown_handler');
86
+    /**
87
+     * Verification of the PHP environment: minimum and maximum version
88
+     */
89
+    if (version_compare(phpversion(), TNH_REQUIRED_PHP_MIN_VERSION, '<')){
90
+        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');	
91
+    }
92
+    else if(version_compare(phpversion(), TNH_REQUIRED_PHP_MAX_VERSION, '>')){
93
+        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');	
94
+    }
95
+    $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');
96
+
97
+    /**
98
+     * Setting of the PHP error message handling function
99
+     */
100
+    set_error_handler('php_error_handler');
101
+
102
+    /**
103
+     * Setting of the PHP error exception handling function
104
+     */
105
+    set_exception_handler('php_exception_handler');
106
+
107
+    /**
108
+     * Setting of the PHP shutdown handling function
109
+     */
110
+    register_shutdown_function('php_shudown_handler');
111 111
 	
112
-	//if user have some composer packages
113
-	$LOGGER->debug('Check for composer autoload');
114
-	if(file_exists(VENDOR_PATH . 'autoload.php')){
115
-		$LOGGER->info('The composer autoload file exists include it');
116
-		require_once VENDOR_PATH . 'autoload.php';
117
-	}
118
-	else{
119
-		$LOGGER->info('The composer autoload file does not exist skipping');
120
-	}
112
+    //if user have some composer packages
113
+    $LOGGER->debug('Check for composer autoload');
114
+    if(file_exists(VENDOR_PATH . 'autoload.php')){
115
+        $LOGGER->info('The composer autoload file exists include it');
116
+        require_once VENDOR_PATH . 'autoload.php';
117
+    }
118
+    else{
119
+        $LOGGER->info('The composer autoload file does not exist skipping');
120
+    }
121 121
 	
122
-	$LOGGER->debug('Begin to load the required resources');
123
-
124
-	/**
125
-	 * Load the EventInfo class file
126
-	 */
127
-	require_once CORE_CLASSES_PATH . 'EventInfo.php';
128
-
129
-
130
-	$BENCHMARK->mark('CONFIG_INIT_START');
131
-	/**
132
-	* Load configurations and using the 
133
-	* static method "init()" to initialize the Config class .
134
-	*/
135
-	$CONFIG =& class_loader('Config', 'classes');	
136
-	$CONFIG->init();
137
-	$BENCHMARK->mark('CONFIG_INIT_END');
138
-
139
-	$BENCHMARK->mark('MODULE_INIT_START');
140
-	/**
141
-	* Load modules and using the 
142
-	* static method "init()" to initialize the Module class.
143
-	*/
144
-	$MODULE =& class_loader('Module', 'classes');
145
-	$MODULE->init();
146
-	$BENCHMARK->mark('MODULE_INIT_END');
147
-
148
-	$LOGGER->debug('Loading Base Controller ...');
149
-	/**
150
-	 * Include of the file containing the Base Controller class 
151
-	 */
152
-	require_once CORE_CLASSES_PATH . 'Controller.php';
153
-	$LOGGER->info('Base Controller loaded successfully');
154
-
155
-	/**
156
-	* Register controllers autoload function
157
-	*/
158
-	 spl_autoload_register('autoload_controller');
159
-
160
-	/**
161
-	* Loading Security class
162
-	*/
163
-	$SECURITY =& class_loader('Security', 'classes');
164
-	$SECURITY->checkWhiteListIpAccess();
122
+    $LOGGER->debug('Begin to load the required resources');
123
+
124
+    /**
125
+     * Load the EventInfo class file
126
+     */
127
+    require_once CORE_CLASSES_PATH . 'EventInfo.php';
128
+
129
+
130
+    $BENCHMARK->mark('CONFIG_INIT_START');
131
+    /**
132
+     * Load configurations and using the 
133
+     * static method "init()" to initialize the Config class .
134
+     */
135
+    $CONFIG =& class_loader('Config', 'classes');	
136
+    $CONFIG->init();
137
+    $BENCHMARK->mark('CONFIG_INIT_END');
138
+
139
+    $BENCHMARK->mark('MODULE_INIT_START');
140
+    /**
141
+     * Load modules and using the 
142
+     * static method "init()" to initialize the Module class.
143
+     */
144
+    $MODULE =& class_loader('Module', 'classes');
145
+    $MODULE->init();
146
+    $BENCHMARK->mark('MODULE_INIT_END');
147
+
148
+    $LOGGER->debug('Loading Base Controller ...');
149
+    /**
150
+     * Include of the file containing the Base Controller class 
151
+     */
152
+    require_once CORE_CLASSES_PATH . 'Controller.php';
153
+    $LOGGER->info('Base Controller loaded successfully');
154
+
155
+    /**
156
+     * Register controllers autoload function
157
+     */
158
+        spl_autoload_register('autoload_controller');
159
+
160
+    /**
161
+     * Loading Security class
162
+     */
163
+    $SECURITY =& class_loader('Security', 'classes');
164
+    $SECURITY->checkWhiteListIpAccess();
165 165
 	
166
-	/**
167
-	* Loading Url class
168
-	*/
169
-	$URL =& class_loader('Url', 'classes');
166
+    /**
167
+     * Loading Url class
168
+     */
169
+    $URL =& class_loader('Url', 'classes');
170 170
 	
171
-	if(get_config('cache_enable', false)){
172
-		/**
173
-		 * Load Cache interface file
174
-		 */
175
-		require_once CORE_CLASSES_CACHE_PATH . 'CacheInterface.php';
176
-		$cacheHandler = get_config('cache_handler');
177
-		if(! $cacheHandler){
178
-			show_error('The cache feature is enabled in the configuration but the cache handler class is not set.');
179
-		}
180
-		$CACHE = null;
181
-		//first check if the cache handler is the system driver
182
-		if(file_exists(CORE_CLASSES_CACHE_PATH . $cacheHandler . '.php')){
183
-			$CACHE =& class_loader($cacheHandler, 'classes/cache');
184
-		}
185
-		else{
186
-			//it's not a system driver use user library
187
-			$CACHE =& class_loader($cacheHandler);
188
-		}
189
-		//check if the page already cached
190
-		if(! empty($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'get'){
191
-			$RESPONSE = & class_loader('Response', 'classes');
192
-			if ($RESPONSE->renderFinalPageFromCache($CACHE)){
193
-				return;
194
-			}
195
-		}
196
-	}
171
+    if(get_config('cache_enable', false)){
172
+        /**
173
+         * Load Cache interface file
174
+         */
175
+        require_once CORE_CLASSES_CACHE_PATH . 'CacheInterface.php';
176
+        $cacheHandler = get_config('cache_handler');
177
+        if(! $cacheHandler){
178
+            show_error('The cache feature is enabled in the configuration but the cache handler class is not set.');
179
+        }
180
+        $CACHE = null;
181
+        //first check if the cache handler is the system driver
182
+        if(file_exists(CORE_CLASSES_CACHE_PATH . $cacheHandler . '.php')){
183
+            $CACHE =& class_loader($cacheHandler, 'classes/cache');
184
+        }
185
+        else{
186
+            //it's not a system driver use user library
187
+            $CACHE =& class_loader($cacheHandler);
188
+        }
189
+        //check if the page already cached
190
+        if(! empty($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'get'){
191
+            $RESPONSE = & class_loader('Response', 'classes');
192
+            if ($RESPONSE->renderFinalPageFromCache($CACHE)){
193
+                return;
194
+            }
195
+        }
196
+    }
197 197
 	
198
-	//load model class
199
-	require_once CORE_CLASSES_MODEL_PATH . 'Model.php';
198
+    //load model class
199
+    require_once CORE_CLASSES_MODEL_PATH . 'Model.php';
200 200
 	
201
-	$LOGGER->info('Everything is OK load Router library and dispatch the request to the corresponding controller');
202
-	/**
203
-	* Routing
204
-	* instantiation of the "Router" class and request processing.
205
-	*/
206
-	$ROUTER = & class_loader('Router', 'classes');
207
-	$ROUTER->processRequest();
201
+    $LOGGER->info('Everything is OK load Router library and dispatch the request to the corresponding controller');
202
+    /**
203
+     * Routing
204
+     * instantiation of the "Router" class and request processing.
205
+     */
206
+    $ROUTER = & class_loader('Router', 'classes');
207
+    $ROUTER->processRequest();
Please login to merge, or discard this patch.
core/libraries/Email.php 1 patch
Indentation   +728 added lines, -728 removed lines patch added patch discarded remove patch
@@ -1,733 +1,733 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * Simple Mail
5
-	 *
6
-	 * A simple PHP wrapper class for sending email using the mail() method.
7
-	 *
8
-	 * PHP version > 5.2
9
-	 *
10
-	 * LICENSE: This source file is subject to the MIT license, which is
11
-	 * available through the world-wide-web at the following URI:
12
-	 * http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt
13
-	 *
14
-	 * @category  SimpleMail
15
-	 * @package   SimpleMail
16
-	 * @author    Eoghan O'Brien <[email protected]>
17
-	 * @copyright 2009 - 2017 Eoghan O'Brien
18
-	 * @license   http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt MIT
19
-	 * @version   1.7.1
20
-	 * @link      http://github.com/eoghanobrien/php-simple-mail
21
-	 */
22
-
23
-	/**
24
-	 * Simple Mail class.
25
-	 *
26
-	 * @category  SimpleMail
27
-	 * @package   SimpleMail
28
-	 * @author    Eoghan O'Brien <[email protected]>
29
-	 * @copyright 2009 - 2017 Eoghan O'Brien
30
-	 * @license   http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt MIT
31
-	 * @version   1.7.1
32
-	 * @link      http://github.com/eoghanobrien/php-simple-mail
33
-	 */
34
-	class Email extends BaseClass
35
-	{
36
-		/**
37
-		 * @var int $_wrap
38
-		 */
39
-		protected $_wrap = 78;
40
-
41
-		/**
42
-		 * @var array $_to
43
-		 */
44
-		protected $_to = array();
45
-
46
-		/**
47
-		 * @var string $_subject
48
-		 */
49
-		protected $_subject;
50
-
51
-		/**
52
-		 * @var string $_message
53
-		 */
54
-		protected $_message;
55
-
56
-		/**
57
-		 * @var array $_headers
58
-		 */
59
-		protected $_headers = array();
60
-
61
-		/**
62
-		 * @var string $_parameters
63
-		 */
64
-		protected $_params;
65
-
66
-		/**
67
-		 * @var array $_attachments
68
-		 */
69
-		protected $_attachments = array();
70
-
71
-		/**
72
-		 * @var string $_uid
73
-		 */
74
-		protected $_uid;
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * Simple Mail
5
+     *
6
+     * A simple PHP wrapper class for sending email using the mail() method.
7
+     *
8
+     * PHP version > 5.2
9
+     *
10
+     * LICENSE: This source file is subject to the MIT license, which is
11
+     * available through the world-wide-web at the following URI:
12
+     * http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt
13
+     *
14
+     * @category  SimpleMail
15
+     * @package   SimpleMail
16
+     * @author    Eoghan O'Brien <[email protected]>
17
+     * @copyright 2009 - 2017 Eoghan O'Brien
18
+     * @license   http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt MIT
19
+     * @version   1.7.1
20
+     * @link      http://github.com/eoghanobrien/php-simple-mail
21
+     */
22
+
23
+    /**
24
+     * Simple Mail class.
25
+     *
26
+     * @category  SimpleMail
27
+     * @package   SimpleMail
28
+     * @author    Eoghan O'Brien <[email protected]>
29
+     * @copyright 2009 - 2017 Eoghan O'Brien
30
+     * @license   http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt MIT
31
+     * @version   1.7.1
32
+     * @link      http://github.com/eoghanobrien/php-simple-mail
33
+     */
34
+    class Email extends BaseClass
35
+    {
36
+        /**
37
+         * @var int $_wrap
38
+         */
39
+        protected $_wrap = 78;
40
+
41
+        /**
42
+         * @var array $_to
43
+         */
44
+        protected $_to = array();
45
+
46
+        /**
47
+         * @var string $_subject
48
+         */
49
+        protected $_subject;
50
+
51
+        /**
52
+         * @var string $_message
53
+         */
54
+        protected $_message;
55
+
56
+        /**
57
+         * @var array $_headers
58
+         */
59
+        protected $_headers = array();
60
+
61
+        /**
62
+         * @var string $_parameters
63
+         */
64
+        protected $_params;
65
+
66
+        /**
67
+         * @var array $_attachments
68
+         */
69
+        protected $_attachments = array();
70
+
71
+        /**
72
+         * @var string $_uid
73
+         */
74
+        protected $_uid;
75 75
 		
76 76
 
77
-		/**
78
-		 * __construct
79
-		 *
80
-		 * Resets the class properties.
81
-		 */
82
-		public function __construct()
83
-		{
84
-			parent::__construct();
85
-			$this->reset();
86
-		}
87
-
88
-		/**
89
-		 * reset
90
-		 *
91
-		 * Resets all properties to initial state.
92
-		 *
93
-		 * @return self
94
-		 */
95
-		public function reset()
96
-		{
97
-			$this->_to = array();
98
-			$this->_headers = array();
99
-			$this->_subject = null;
100
-			$this->_message = null;
101
-			$this->_wrap = 78;
102
-			$this->_params = null;
103
-			$this->_attachments = array();
104
-			$this->_uid = $this->getUniqueId();
105
-			return $this;
106
-		}
77
+        /**
78
+         * __construct
79
+         *
80
+         * Resets the class properties.
81
+         */
82
+        public function __construct()
83
+        {
84
+            parent::__construct();
85
+            $this->reset();
86
+        }
87
+
88
+        /**
89
+         * reset
90
+         *
91
+         * Resets all properties to initial state.
92
+         *
93
+         * @return self
94
+         */
95
+        public function reset()
96
+        {
97
+            $this->_to = array();
98
+            $this->_headers = array();
99
+            $this->_subject = null;
100
+            $this->_message = null;
101
+            $this->_wrap = 78;
102
+            $this->_params = null;
103
+            $this->_attachments = array();
104
+            $this->_uid = $this->getUniqueId();
105
+            return $this;
106
+        }
107 107
 		
108
-		 /**
109
-		 * setFrom
110
-		 *
111
-		 * @param string $email The email to send as from.
112
-		 * @param string $name  The name to send as from.
113
-		 *
114
-		 * @return self
115
-		 */
116
-		public function setFrom($email, $name = null)
117
-		{
118
-			$this->addMailHeader('From', (string) $email, (string) $name);
119
-			return $this;
120
-		}
121
-
122
-		/**
123
-		 * setTo
124
-		 *
125
-		 * @param string $email The email address to send to.
126
-		 * @param string $name  The name of the person to send to.
127
-		 *
128
-		 * @return self
129
-		 */
130
-		public function setTo($email, $name = null)
131
-		{
132
-			$this->_to[] = $this->formatHeader((string) $email, (string) $name);
133
-			return $this;
134
-		}
108
+            /**
109
+             * setFrom
110
+             *
111
+             * @param string $email The email to send as from.
112
+             * @param string $name  The name to send as from.
113
+             *
114
+             * @return self
115
+             */
116
+        public function setFrom($email, $name = null)
117
+        {
118
+            $this->addMailHeader('From', (string) $email, (string) $name);
119
+            return $this;
120
+        }
121
+
122
+        /**
123
+         * setTo
124
+         *
125
+         * @param string $email The email address to send to.
126
+         * @param string $name  The name of the person to send to.
127
+         *
128
+         * @return self
129
+         */
130
+        public function setTo($email, $name = null)
131
+        {
132
+            $this->_to[] = $this->formatHeader((string) $email, (string) $name);
133
+            return $this;
134
+        }
135 135
 		
136
-		/**
137
-		* Set destination using array
138
-		* @params array $emails the list of recipient. This is an associative array name => email
139
-		* @example array('John Doe' => '[email protected]')
140
-		* @return Object the current instance
141
-		*/
142
-		public function setTos(array $emails)
143
-		{
144
-			foreach ($emails as $name => $email) {
145
-				if(is_numeric($name)){
146
-					$this->setTo($email);
147
-				}
148
-				else{
149
-					$this->setTo($email, $name);
150
-				}
151
-			}
152
-			return $this;
153
-		}
154
-
155
-
156
-		/**
157
-		 * getTo
158
-		 *
159
-		 * Return an array of formatted To addresses.
160
-		 *
161
-		 * @return array
162
-		 */
163
-		public function getTo()
164
-		{
165
-			return $this->_to;
166
-		}
167
-
168
-
169
-		/**
170
-		 * setCc
171
-		 *
172
-		 * @param array  $pairs  An array of name => email pairs.
173
-		 *
174
-		 * @return self
175
-		 */
176
-		public function setCc(array $pairs)
177
-		{
178
-			return $this->addMailHeaders('Cc', $pairs);
179
-		}
180
-
181
-		/**
182
-		 * setBcc
183
-		 *
184
-		 * @param array  $pairs  An array of name => email pairs.
185
-		 *
186
-		 * @return self
187
-		 */
188
-		public function setBcc(array $pairs)
189
-		{
190
-			return $this->addMailHeaders('Bcc', $pairs);
191
-		}
192
-
193
-		/**
194
-		 * setReplyTo
195
-		 *
196
-		 * @param string $email
197
-		 * @param string $name
198
-		 *
199
-		 * @return self
200
-		 */
201
-		public function setReplyTo($email, $name = null)
202
-		{
203
-			return $this->addMailHeader('Reply-To', $email, $name);
204
-		}
205
-
206
-		/**
207
-		 * setHtml
208
-		 *
209
-		 * @return self
210
-		 */
211
-		public function setHtml()
212
-		{
213
-			$this->addGenericHeader(
214
-				'Content-Type', 'text/html; charset="utf-8"'
215
-			);
216
-			return $this;
217
-		}
218
-
219
-		/**
220
-		 * setSubject
221
-		 *
222
-		 * @param string $subject The email subject
223
-		 *
224
-		 * @return self
225
-		 */
226
-		public function setSubject($subject)
227
-		{
228
-			$this->_subject = $this->encodeUtf8(
229
-				$this->filterOther((string) $subject)
230
-			);
231
-			return $this;
232
-		}
233
-
234
-		/**
235
-		 * getSubject function.
236
-		 *
237
-		 * @return string
238
-		 */
239
-		public function getSubject()
240
-		{
241
-			return $this->_subject;
242
-		}
243
-
244
-		/**
245
-		 * setMessage
246
-		 *
247
-		 * @param string $message The message to send.
248
-		 *
249
-		 * @return self
250
-		 */
251
-		public function setMessage($message)
252
-		{
253
-			$this->_message = str_replace("\n.", "\n..", (string) $message);
254
-			return $this;
255
-		}
256
-
257
-		/**
258
-		 * getMessage
259
-		 *
260
-		 * @return string
261
-		 */
262
-		public function getMessage()
263
-		{
264
-			return $this->_message;
265
-		}
266
-
267
-		/**
268
-		 * addAttachment
269
-		 *
270
-		 * @param string $path The file path to the attachment.
271
-		 * @param string $filename The filename of the attachment when emailed.
272
-		 * @param string $data
273
-		 * 
274
-		 * @return self
275
-		 */
276
-		public function addAttachment($path, $filename = null, $data = null)
277
-		{
278
-			if(! file_exists($path)){
279
-				show_error('The file [' .$path. '] does not exists.');
280
-			}
281
-			$filename = empty($filename) ? basename($path) : $filename;
282
-			$filename = $this->encodeUtf8($this->filterOther((string) $filename));
283
-			$data = empty($data) ? $this->getAttachmentData($path) : $data;
284
-			$this->_attachments[] = array(
285
-				'path' => $path,
286
-				'file' => $filename,
287
-				'data' => chunk_split(base64_encode($data))
288
-			);
289
-			return $this;
290
-		}
291
-
292
-		/**
293
-		 * getAttachmentData
294
-		 *
295
-		 * @param string $path The path to the attachment file.
296
-		 *
297
-		 * @return string
298
-		 */
299
-		public function getAttachmentData($path)
300
-		{
301
-			if(! file_exists($path)){
302
-				show_error('The file [' .$path. '] does not exists.');
303
-			}
304
-			$filesize = filesize($path);
305
-			$handle = fopen($path, "r");
306
-			$attachment = null;
307
-			if(is_resource($handle)){
308
-				$attachment = fread($handle, $filesize);
309
-				fclose($handle);
310
-			}
311
-			return $attachment;
312
-		}
313
-
314
-		/**
315
-		 * addMailHeader
316
-		 *
317
-		 * @param string $header The header to add.
318
-		 * @param string $email  The email to add.
319
-		 * @param string $name   The name to add.
320
-		 *
321
-		 * @return self
322
-		 */
323
-		public function addMailHeader($header, $email, $name = null)
324
-		{
325
-			$address = $this->formatHeader((string) $email, (string) $name);
326
-			$this->_headers[] = sprintf('%s: %s', (string) $header, $address);
327
-			return $this;
328
-		}
329
-
330
-		/**
331
-		 * addMailHeaders
332
-		 *
333
-		 * @param string $header The header to add.
334
-		 * @param array  $pairs  An array of name => email pairs.
335
-		 *
336
-		 * @return self
337
-		 */
338
-		public function addMailHeaders($header, array $pairs)
339
-		{
340
-			if (count($pairs) === 0) {
341
-				show_error('You must pass at least one name => email pair.');
342
-			}
343
-			$addresses = array();
344
-			foreach ($pairs as $name => $email) {
345
-				$name = is_numeric($name) ? null : $name;
346
-				$addresses[] = $this->formatHeader($email, $name);
347
-			}
348
-			$this->addGenericHeader($header, implode(',', $addresses));
349
-			return $this;
350
-		}
351
-
352
-		/**
353
-		 * addGenericHeader
354
-		 *
355
-		 * @param string $name The generic header to add.
356
-		 * @param mixed  $value  The value of the header.
357
-		 *
358
-		 * @return self
359
-		 */
360
-		public function addGenericHeader($name, $value)
361
-		{
362
-			$this->_headers[] = sprintf(
363
-				'%s: %s',
364
-				(string) $name,
365
-				(string) $value
366
-			);
367
-			return $this;
368
-		}
369
-
370
-		/**
371
-		 * getHeaders
372
-		 *
373
-		 * Return the headers registered so far as an array.
374
-		 *
375
-		 * @return array
376
-		 */
377
-		public function getHeaders()
378
-		{
379
-			return $this->_headers;
380
-		}
381
-
382
-		/**
383
-		 * setAdditionalParameters
384
-		 *
385
-		 * Such as "[email protected]
386
-		 *
387
-		 * @param string $additionalParameters The addition mail parameter.
388
-		 *
389
-		 * @return self
390
-		 */
391
-		public function setParameters($additionalParameters)
392
-		{
393
-			$this->_params = (string) $additionalParameters;
394
-			return $this;
395
-		}
396
-
397
-		/**
398
-		 * getAdditionalParameters
399
-		 *
400
-		 * @return string
401
-		 */
402
-		public function getParameters()
403
-		{
404
-			return $this->_params;
405
-		}
406
-
407
-		/**
408
-		 * setWrap
409
-		 *
410
-		 * @param int $wrap The number of characters at which the message will wrap.
411
-		 *
412
-		 * @return self
413
-		 */
414
-		public function setWrap($wrap = 78)
415
-		{
416
-			$wrap = (int) $wrap;
417
-			if ($wrap < 1) {
418
-				$wrap = 78;
419
-			}
420
-			$this->_wrap = $wrap;
421
-			return $this;
422
-		}
423
-
424
-		/**
425
-		 * getWrap
426
-		 *
427
-		 * @return int
428
-		 */
429
-		public function getWrap()
430
-		{
431
-			return $this->_wrap;
432
-		}
433
-
434
-		/**
435
-		 * hasAttachments
436
-		 * 
437
-		 * Checks if the email has any registered attachments.
438
-		 *
439
-		 * @return bool
440
-		 */
441
-		public function hasAttachments()
442
-		{
443
-			return !empty($this->_attachments);
444
-		}
445
-
446
-		/**
447
-		 * assembleAttachment
448
-		 *
449
-		 * @return string
450
-		 */
451
-		public function assembleAttachmentHeaders()
452
-		{
453
-			$head = array();
454
-			$head[] = "MIME-Version: 1.0";
455
-			$head[] = "Content-Type: multipart/mixed; boundary=\"{$this->_uid}\"";
456
-
457
-			return join(PHP_EOL, $head);
458
-		}
459
-
460
-		/**
461
-		 * assembleAttachmentBody
462
-		 *
463
-		 * @return string
464
-		 */
465
-		public function assembleAttachmentBody()
466
-		{
467
-			$body = array();
468
-			$body[] = "This is a multi-part message in MIME format.";
469
-			$body[] = "--{$this->_uid}";
470
-			$body[] = "Content-Type: text/html; charset=\"utf-8\"";
471
-			$body[] = "Content-Transfer-Encoding: quoted-printable";
472
-			$body[] = "";
473
-			$body[] = quoted_printable_encode($this->_message);
474
-			$body[] = "";
475
-			$body[] = "--{$this->_uid}";
476
-
477
-			foreach ($this->_attachments as $attachment) {
478
-				$body[] = $this->getAttachmentMimeTemplate($attachment);
479
-			}
480
-
481
-			return implode(PHP_EOL, $body) . '--';
482
-		}
483
-
484
-		/**
485
-		 * getAttachmentMimeTemplate
486
-		 *
487
-		 * @param array  $attachment An array containing 'file' and 'data' keys.
488
-		 *
489
-		 * @return string
490
-		 */
491
-		public function getAttachmentMimeTemplate($attachment)
492
-		{
493
-			$file = $attachment['file'];
494
-			$data = $attachment['data'];
495
-
496
-			$head = array();
497
-			$head[] = "Content-Type: application/octet-stream; name=\"{$file}\"";
498
-			$head[] = "Content-Transfer-Encoding: base64";
499
-			$head[] = "Content-Disposition: attachment; filename=\"{$file}\"";
500
-			$head[] = "";
501
-			$head[] = $data;
502
-			$head[] = "";
503
-			$head[] = "--{$this->_uid}";
504
-
505
-			return implode(PHP_EOL, $head);
506
-		}
507
-
508
-		/**
509
-		 * send the email
510
-		 *
511
-		 * @return boolean
512
-		 */
513
-		public function send()
514
-		{
515
-			$to = $this->getToForSend();
516
-			$headers = $this->getHeadersForSend();
517
-
518
-			if (empty($to)) {
519
-				show_error('Unable to send, no To address has been set.');
520
-			}
521
-
522
-			if ($this->hasAttachments()) {
523
-				$message  = $this->assembleAttachmentBody();
524
-				$headers .= PHP_EOL . $this->assembleAttachmentHeaders();
525
-			} else {
526
-				$message = $this->getWrapMessage();
527
-			}
528
-			$this->logger->info('Sending new mail, the information are listed below: destination: ' . $to . ', headers: ' . $headers . ', message: ' . $message);
529
-			return mail($to, $this->_subject, $message, $headers, $this->_params);
530
-		}
531
-
532
-		/**
533
-		 * debug
534
-		 *
535
-		 * @return string
536
-		 */
537
-		public function debug()
538
-		{
539
-			return '<pre>' . print_r($this, true) . '</pre>';
540
-		}
541
-
542
-		/**
543
-		 * magic __toString function
544
-		 *
545
-		 * @return string
546
-		 */
547
-		public function __toString()
548
-		{
549
-			return print_r($this, true);
550
-		}
551
-
552
-		/**
553
-		 * formatHeader
554
-		 *
555
-		 * Formats a display address for emails according to RFC2822 e.g.
556
-		 * Name <[email protected]>
557
-		 *
558
-		 * @param string $email The email address.
559
-		 * @param string $name  The display name.
560
-		 *
561
-		 * @return string
562
-		 */
563
-		public function formatHeader($email, $name = null)
564
-		{
565
-			$email = $this->filterEmail((string) $email);
566
-			if (empty($name)) {
567
-				return $email;
568
-			}
569
-			$name = $this->encodeUtf8($this->filterName((string) $name));
570
-			return sprintf('"%s" <%s>', $name, $email);
571
-		}
572
-
573
-		/**
574
-		 * encodeUtf8
575
-		 *
576
-		 * @param string $value The value to encode.
577
-		 *
578
-		 * @return string
579
-		 */
580
-		public function encodeUtf8($value)
581
-		{
582
-			$value = trim($value);
583
-			if (preg_match('/(\s)/', $value)) {
584
-				return $this->encodeUtf8Words($value);
585
-			}
586
-			return $this->encodeUtf8Word($value);
587
-		}
588
-
589
-		/**
590
-		 * encodeUtf8Word
591
-		 *
592
-		 * @param string $value The word to encode.
593
-		 *
594
-		 * @return string
595
-		 */
596
-		public function encodeUtf8Word($value)
597
-		{
598
-			return sprintf('=?UTF-8?B?%s?=', base64_encode($value));
599
-		}
600
-
601
-		/**
602
-		 * encodeUtf8Words
603
-		 *
604
-		 * @param string $value The words to encode.
605
-		 *
606
-		 * @return string
607
-		 */
608
-		public function encodeUtf8Words($value)
609
-		{
610
-			$words = explode(' ', $value);
611
-			$encoded = array();
612
-			foreach ($words as $word) {
613
-				$encoded[] = $this->encodeUtf8Word($word);
614
-			}
615
-			return join($this->encodeUtf8Word(' '), $encoded);
616
-		}
617
-
618
-		/**
619
-		 * filterEmail
620
-		 *
621
-		 * Removes any carriage return, line feed, tab, double quote, comma
622
-		 * and angle bracket characters before sanitizing the email address.
623
-		 *
624
-		 * @param string $email The email to filter.
625
-		 *
626
-		 * @return string
627
-		 */
628
-		public function filterEmail($email)
629
-		{
630
-			$rule = array(
631
-				"\r" => '',
632
-				"\n" => '',
633
-				"\t" => '',
634
-				'"'  => '',
635
-				','  => '',
636
-				'<'  => '',
637
-				'>'  => ''
638
-			);
639
-			$email = strtr($email, $rule);
640
-			$email = filter_var($email, FILTER_SANITIZE_EMAIL);
641
-			return $email;
642
-		}
643
-
644
-		/**
645
-		 * filterName
646
-		 *
647
-		 * Removes any carriage return, line feed or tab characters. Replaces
648
-		 * double quotes with single quotes and angle brackets with square
649
-		 * brackets, before sanitizing the string and stripping out html tags.
650
-		 *
651
-		 * @param string $name The name to filter.
652
-		 *
653
-		 * @return string
654
-		 */
655
-		public function filterName($name)
656
-		{
657
-			$rule = array(
658
-				"\r" => '',
659
-				"\n" => '',
660
-				"\t" => '',
661
-				'"'  => "'",
662
-				'<'  => '[',
663
-				'>'  => ']',
664
-			);
665
-			$filtered = filter_var(
666
-				$name,
667
-				FILTER_SANITIZE_STRING,
668
-				FILTER_FLAG_NO_ENCODE_QUOTES
669
-			);
670
-			return trim(strtr($filtered, $rule));
671
-		}
672
-
673
-		/**
674
-		 * filterOther
675
-		 *
676
-		 * Removes ASCII control characters including any carriage return, line
677
-		 * feed or tab characters.
678
-		 *
679
-		 * @param string $data The data to filter.
680
-		 *
681
-		 * @return string
682
-		 */
683
-		public function filterOther($data)
684
-		{
685
-			return filter_var($data, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW);
686
-		}
687
-
688
-		/**
689
-		 * getHeadersForSend
690
-		 *
691
-		 * @return string
692
-		 */
693
-		public function getHeadersForSend()
694
-		{
695
-			if (empty($this->_headers)) {
696
-				return '';
697
-			}
698
-			return join(PHP_EOL, $this->_headers);
699
-		}
700
-
701
-		/**
702
-		 * getToForSend
703
-		 *
704
-		 * @return string
705
-		 */
706
-		public function getToForSend()
707
-		{
708
-			if (empty($this->_to)) {
709
-				return '';
710
-			}
711
-			return join(', ', $this->_to);
712
-		}
713
-
714
-		/**
715
-		 * getUniqueId
716
-		 *
717
-		 * @return string
718
-		 */
719
-		public function getUniqueId()
720
-		{
721
-			return md5(uniqid(time()));
722
-		}
723
-
724
-		/**
725
-		 * getWrapMessage
726
-		 *
727
-		 * @return string
728
-		 */
729
-		public function getWrapMessage()
730
-		{
731
-			return wordwrap($this->_message, $this->_wrap);
732
-		}
733
-	}
136
+        /**
137
+         * Set destination using array
138
+         * @params array $emails the list of recipient. This is an associative array name => email
139
+         * @example array('John Doe' => '[email protected]')
140
+         * @return Object the current instance
141
+         */
142
+        public function setTos(array $emails)
143
+        {
144
+            foreach ($emails as $name => $email) {
145
+                if(is_numeric($name)){
146
+                    $this->setTo($email);
147
+                }
148
+                else{
149
+                    $this->setTo($email, $name);
150
+                }
151
+            }
152
+            return $this;
153
+        }
154
+
155
+
156
+        /**
157
+         * getTo
158
+         *
159
+         * Return an array of formatted To addresses.
160
+         *
161
+         * @return array
162
+         */
163
+        public function getTo()
164
+        {
165
+            return $this->_to;
166
+        }
167
+
168
+
169
+        /**
170
+         * setCc
171
+         *
172
+         * @param array  $pairs  An array of name => email pairs.
173
+         *
174
+         * @return self
175
+         */
176
+        public function setCc(array $pairs)
177
+        {
178
+            return $this->addMailHeaders('Cc', $pairs);
179
+        }
180
+
181
+        /**
182
+         * setBcc
183
+         *
184
+         * @param array  $pairs  An array of name => email pairs.
185
+         *
186
+         * @return self
187
+         */
188
+        public function setBcc(array $pairs)
189
+        {
190
+            return $this->addMailHeaders('Bcc', $pairs);
191
+        }
192
+
193
+        /**
194
+         * setReplyTo
195
+         *
196
+         * @param string $email
197
+         * @param string $name
198
+         *
199
+         * @return self
200
+         */
201
+        public function setReplyTo($email, $name = null)
202
+        {
203
+            return $this->addMailHeader('Reply-To', $email, $name);
204
+        }
205
+
206
+        /**
207
+         * setHtml
208
+         *
209
+         * @return self
210
+         */
211
+        public function setHtml()
212
+        {
213
+            $this->addGenericHeader(
214
+                'Content-Type', 'text/html; charset="utf-8"'
215
+            );
216
+            return $this;
217
+        }
218
+
219
+        /**
220
+         * setSubject
221
+         *
222
+         * @param string $subject The email subject
223
+         *
224
+         * @return self
225
+         */
226
+        public function setSubject($subject)
227
+        {
228
+            $this->_subject = $this->encodeUtf8(
229
+                $this->filterOther((string) $subject)
230
+            );
231
+            return $this;
232
+        }
233
+
234
+        /**
235
+         * getSubject function.
236
+         *
237
+         * @return string
238
+         */
239
+        public function getSubject()
240
+        {
241
+            return $this->_subject;
242
+        }
243
+
244
+        /**
245
+         * setMessage
246
+         *
247
+         * @param string $message The message to send.
248
+         *
249
+         * @return self
250
+         */
251
+        public function setMessage($message)
252
+        {
253
+            $this->_message = str_replace("\n.", "\n..", (string) $message);
254
+            return $this;
255
+        }
256
+
257
+        /**
258
+         * getMessage
259
+         *
260
+         * @return string
261
+         */
262
+        public function getMessage()
263
+        {
264
+            return $this->_message;
265
+        }
266
+
267
+        /**
268
+         * addAttachment
269
+         *
270
+         * @param string $path The file path to the attachment.
271
+         * @param string $filename The filename of the attachment when emailed.
272
+         * @param string $data
273
+         * 
274
+         * @return self
275
+         */
276
+        public function addAttachment($path, $filename = null, $data = null)
277
+        {
278
+            if(! file_exists($path)){
279
+                show_error('The file [' .$path. '] does not exists.');
280
+            }
281
+            $filename = empty($filename) ? basename($path) : $filename;
282
+            $filename = $this->encodeUtf8($this->filterOther((string) $filename));
283
+            $data = empty($data) ? $this->getAttachmentData($path) : $data;
284
+            $this->_attachments[] = array(
285
+                'path' => $path,
286
+                'file' => $filename,
287
+                'data' => chunk_split(base64_encode($data))
288
+            );
289
+            return $this;
290
+        }
291
+
292
+        /**
293
+         * getAttachmentData
294
+         *
295
+         * @param string $path The path to the attachment file.
296
+         *
297
+         * @return string
298
+         */
299
+        public function getAttachmentData($path)
300
+        {
301
+            if(! file_exists($path)){
302
+                show_error('The file [' .$path. '] does not exists.');
303
+            }
304
+            $filesize = filesize($path);
305
+            $handle = fopen($path, "r");
306
+            $attachment = null;
307
+            if(is_resource($handle)){
308
+                $attachment = fread($handle, $filesize);
309
+                fclose($handle);
310
+            }
311
+            return $attachment;
312
+        }
313
+
314
+        /**
315
+         * addMailHeader
316
+         *
317
+         * @param string $header The header to add.
318
+         * @param string $email  The email to add.
319
+         * @param string $name   The name to add.
320
+         *
321
+         * @return self
322
+         */
323
+        public function addMailHeader($header, $email, $name = null)
324
+        {
325
+            $address = $this->formatHeader((string) $email, (string) $name);
326
+            $this->_headers[] = sprintf('%s: %s', (string) $header, $address);
327
+            return $this;
328
+        }
329
+
330
+        /**
331
+         * addMailHeaders
332
+         *
333
+         * @param string $header The header to add.
334
+         * @param array  $pairs  An array of name => email pairs.
335
+         *
336
+         * @return self
337
+         */
338
+        public function addMailHeaders($header, array $pairs)
339
+        {
340
+            if (count($pairs) === 0) {
341
+                show_error('You must pass at least one name => email pair.');
342
+            }
343
+            $addresses = array();
344
+            foreach ($pairs as $name => $email) {
345
+                $name = is_numeric($name) ? null : $name;
346
+                $addresses[] = $this->formatHeader($email, $name);
347
+            }
348
+            $this->addGenericHeader($header, implode(',', $addresses));
349
+            return $this;
350
+        }
351
+
352
+        /**
353
+         * addGenericHeader
354
+         *
355
+         * @param string $name The generic header to add.
356
+         * @param mixed  $value  The value of the header.
357
+         *
358
+         * @return self
359
+         */
360
+        public function addGenericHeader($name, $value)
361
+        {
362
+            $this->_headers[] = sprintf(
363
+                '%s: %s',
364
+                (string) $name,
365
+                (string) $value
366
+            );
367
+            return $this;
368
+        }
369
+
370
+        /**
371
+         * getHeaders
372
+         *
373
+         * Return the headers registered so far as an array.
374
+         *
375
+         * @return array
376
+         */
377
+        public function getHeaders()
378
+        {
379
+            return $this->_headers;
380
+        }
381
+
382
+        /**
383
+         * setAdditionalParameters
384
+         *
385
+         * Such as "[email protected]
386
+         *
387
+         * @param string $additionalParameters The addition mail parameter.
388
+         *
389
+         * @return self
390
+         */
391
+        public function setParameters($additionalParameters)
392
+        {
393
+            $this->_params = (string) $additionalParameters;
394
+            return $this;
395
+        }
396
+
397
+        /**
398
+         * getAdditionalParameters
399
+         *
400
+         * @return string
401
+         */
402
+        public function getParameters()
403
+        {
404
+            return $this->_params;
405
+        }
406
+
407
+        /**
408
+         * setWrap
409
+         *
410
+         * @param int $wrap The number of characters at which the message will wrap.
411
+         *
412
+         * @return self
413
+         */
414
+        public function setWrap($wrap = 78)
415
+        {
416
+            $wrap = (int) $wrap;
417
+            if ($wrap < 1) {
418
+                $wrap = 78;
419
+            }
420
+            $this->_wrap = $wrap;
421
+            return $this;
422
+        }
423
+
424
+        /**
425
+         * getWrap
426
+         *
427
+         * @return int
428
+         */
429
+        public function getWrap()
430
+        {
431
+            return $this->_wrap;
432
+        }
433
+
434
+        /**
435
+         * hasAttachments
436
+         * 
437
+         * Checks if the email has any registered attachments.
438
+         *
439
+         * @return bool
440
+         */
441
+        public function hasAttachments()
442
+        {
443
+            return !empty($this->_attachments);
444
+        }
445
+
446
+        /**
447
+         * assembleAttachment
448
+         *
449
+         * @return string
450
+         */
451
+        public function assembleAttachmentHeaders()
452
+        {
453
+            $head = array();
454
+            $head[] = "MIME-Version: 1.0";
455
+            $head[] = "Content-Type: multipart/mixed; boundary=\"{$this->_uid}\"";
456
+
457
+            return join(PHP_EOL, $head);
458
+        }
459
+
460
+        /**
461
+         * assembleAttachmentBody
462
+         *
463
+         * @return string
464
+         */
465
+        public function assembleAttachmentBody()
466
+        {
467
+            $body = array();
468
+            $body[] = "This is a multi-part message in MIME format.";
469
+            $body[] = "--{$this->_uid}";
470
+            $body[] = "Content-Type: text/html; charset=\"utf-8\"";
471
+            $body[] = "Content-Transfer-Encoding: quoted-printable";
472
+            $body[] = "";
473
+            $body[] = quoted_printable_encode($this->_message);
474
+            $body[] = "";
475
+            $body[] = "--{$this->_uid}";
476
+
477
+            foreach ($this->_attachments as $attachment) {
478
+                $body[] = $this->getAttachmentMimeTemplate($attachment);
479
+            }
480
+
481
+            return implode(PHP_EOL, $body) . '--';
482
+        }
483
+
484
+        /**
485
+         * getAttachmentMimeTemplate
486
+         *
487
+         * @param array  $attachment An array containing 'file' and 'data' keys.
488
+         *
489
+         * @return string
490
+         */
491
+        public function getAttachmentMimeTemplate($attachment)
492
+        {
493
+            $file = $attachment['file'];
494
+            $data = $attachment['data'];
495
+
496
+            $head = array();
497
+            $head[] = "Content-Type: application/octet-stream; name=\"{$file}\"";
498
+            $head[] = "Content-Transfer-Encoding: base64";
499
+            $head[] = "Content-Disposition: attachment; filename=\"{$file}\"";
500
+            $head[] = "";
501
+            $head[] = $data;
502
+            $head[] = "";
503
+            $head[] = "--{$this->_uid}";
504
+
505
+            return implode(PHP_EOL, $head);
506
+        }
507
+
508
+        /**
509
+         * send the email
510
+         *
511
+         * @return boolean
512
+         */
513
+        public function send()
514
+        {
515
+            $to = $this->getToForSend();
516
+            $headers = $this->getHeadersForSend();
517
+
518
+            if (empty($to)) {
519
+                show_error('Unable to send, no To address has been set.');
520
+            }
521
+
522
+            if ($this->hasAttachments()) {
523
+                $message  = $this->assembleAttachmentBody();
524
+                $headers .= PHP_EOL . $this->assembleAttachmentHeaders();
525
+            } else {
526
+                $message = $this->getWrapMessage();
527
+            }
528
+            $this->logger->info('Sending new mail, the information are listed below: destination: ' . $to . ', headers: ' . $headers . ', message: ' . $message);
529
+            return mail($to, $this->_subject, $message, $headers, $this->_params);
530
+        }
531
+
532
+        /**
533
+         * debug
534
+         *
535
+         * @return string
536
+         */
537
+        public function debug()
538
+        {
539
+            return '<pre>' . print_r($this, true) . '</pre>';
540
+        }
541
+
542
+        /**
543
+         * magic __toString function
544
+         *
545
+         * @return string
546
+         */
547
+        public function __toString()
548
+        {
549
+            return print_r($this, true);
550
+        }
551
+
552
+        /**
553
+         * formatHeader
554
+         *
555
+         * Formats a display address for emails according to RFC2822 e.g.
556
+         * Name <[email protected]>
557
+         *
558
+         * @param string $email The email address.
559
+         * @param string $name  The display name.
560
+         *
561
+         * @return string
562
+         */
563
+        public function formatHeader($email, $name = null)
564
+        {
565
+            $email = $this->filterEmail((string) $email);
566
+            if (empty($name)) {
567
+                return $email;
568
+            }
569
+            $name = $this->encodeUtf8($this->filterName((string) $name));
570
+            return sprintf('"%s" <%s>', $name, $email);
571
+        }
572
+
573
+        /**
574
+         * encodeUtf8
575
+         *
576
+         * @param string $value The value to encode.
577
+         *
578
+         * @return string
579
+         */
580
+        public function encodeUtf8($value)
581
+        {
582
+            $value = trim($value);
583
+            if (preg_match('/(\s)/', $value)) {
584
+                return $this->encodeUtf8Words($value);
585
+            }
586
+            return $this->encodeUtf8Word($value);
587
+        }
588
+
589
+        /**
590
+         * encodeUtf8Word
591
+         *
592
+         * @param string $value The word to encode.
593
+         *
594
+         * @return string
595
+         */
596
+        public function encodeUtf8Word($value)
597
+        {
598
+            return sprintf('=?UTF-8?B?%s?=', base64_encode($value));
599
+        }
600
+
601
+        /**
602
+         * encodeUtf8Words
603
+         *
604
+         * @param string $value The words to encode.
605
+         *
606
+         * @return string
607
+         */
608
+        public function encodeUtf8Words($value)
609
+        {
610
+            $words = explode(' ', $value);
611
+            $encoded = array();
612
+            foreach ($words as $word) {
613
+                $encoded[] = $this->encodeUtf8Word($word);
614
+            }
615
+            return join($this->encodeUtf8Word(' '), $encoded);
616
+        }
617
+
618
+        /**
619
+         * filterEmail
620
+         *
621
+         * Removes any carriage return, line feed, tab, double quote, comma
622
+         * and angle bracket characters before sanitizing the email address.
623
+         *
624
+         * @param string $email The email to filter.
625
+         *
626
+         * @return string
627
+         */
628
+        public function filterEmail($email)
629
+        {
630
+            $rule = array(
631
+                "\r" => '',
632
+                "\n" => '',
633
+                "\t" => '',
634
+                '"'  => '',
635
+                ','  => '',
636
+                '<'  => '',
637
+                '>'  => ''
638
+            );
639
+            $email = strtr($email, $rule);
640
+            $email = filter_var($email, FILTER_SANITIZE_EMAIL);
641
+            return $email;
642
+        }
643
+
644
+        /**
645
+         * filterName
646
+         *
647
+         * Removes any carriage return, line feed or tab characters. Replaces
648
+         * double quotes with single quotes and angle brackets with square
649
+         * brackets, before sanitizing the string and stripping out html tags.
650
+         *
651
+         * @param string $name The name to filter.
652
+         *
653
+         * @return string
654
+         */
655
+        public function filterName($name)
656
+        {
657
+            $rule = array(
658
+                "\r" => '',
659
+                "\n" => '',
660
+                "\t" => '',
661
+                '"'  => "'",
662
+                '<'  => '[',
663
+                '>'  => ']',
664
+            );
665
+            $filtered = filter_var(
666
+                $name,
667
+                FILTER_SANITIZE_STRING,
668
+                FILTER_FLAG_NO_ENCODE_QUOTES
669
+            );
670
+            return trim(strtr($filtered, $rule));
671
+        }
672
+
673
+        /**
674
+         * filterOther
675
+         *
676
+         * Removes ASCII control characters including any carriage return, line
677
+         * feed or tab characters.
678
+         *
679
+         * @param string $data The data to filter.
680
+         *
681
+         * @return string
682
+         */
683
+        public function filterOther($data)
684
+        {
685
+            return filter_var($data, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW);
686
+        }
687
+
688
+        /**
689
+         * getHeadersForSend
690
+         *
691
+         * @return string
692
+         */
693
+        public function getHeadersForSend()
694
+        {
695
+            if (empty($this->_headers)) {
696
+                return '';
697
+            }
698
+            return join(PHP_EOL, $this->_headers);
699
+        }
700
+
701
+        /**
702
+         * getToForSend
703
+         *
704
+         * @return string
705
+         */
706
+        public function getToForSend()
707
+        {
708
+            if (empty($this->_to)) {
709
+                return '';
710
+            }
711
+            return join(', ', $this->_to);
712
+        }
713
+
714
+        /**
715
+         * getUniqueId
716
+         *
717
+         * @return string
718
+         */
719
+        public function getUniqueId()
720
+        {
721
+            return md5(uniqid(time()));
722
+        }
723
+
724
+        /**
725
+         * getWrapMessage
726
+         *
727
+         * @return string
728
+         */
729
+        public function getWrapMessage()
730
+        {
731
+            return wordwrap($this->_message, $this->_wrap);
732
+        }
733
+    }
Please login to merge, or discard this patch.
core/libraries/PDF.php 1 patch
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -1,80 +1,80 @@
 block discarded – undo
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 extends BaseClass{
27
+    /**
28
+     * PDF library to generate PDF document using the library DOMPDF
29
+     */
30
+    class PDF extends BaseClass{
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
-		 * Create PDF library instance
40
-		 */
41
-		public function __construct(){
42
-			parent::__construct();
38
+        /**
39
+         * Create PDF library instance
40
+         */
41
+        public function __construct(){
42
+            parent::__construct();
43 43
 
44
-			require_once VENDOR_PATH.'dompdf/dompdf_config.inc.php';
45
-			$this->dompdf = new Dompdf();
46
-		}
44
+            require_once VENDOR_PATH.'dompdf/dompdf_config.inc.php';
45
+            $this->dompdf = new Dompdf();
46
+        }
47 47
 
48
-		/**
49
-		 * Generate PDF document
50
-		 * @param  string  $html        the HTML content to use for generation
51
-		 * @param  string  $filename    the generated PDF document filename
52
-		 * @param  boolean $stream      if need send the generated PDF to browser for download
53
-		 * @param  string  $paper       the PDF document paper type like 'A4', 'A5', 'letter', etc.
54
-		 * @param  string  $orientation the PDF document orientation like 'portrait', 'landscape'
55
-		 * @return string|void               if $stream is true send PDF document to browser for download, else return the generated PDF
56
-		 * content like to join in Email attachment of for other purpose use.
57
-		 */
58
-		public function generate($html, $filename = 'output.pdf', $stream = true, $paper = 'A4', $orientation = 'portrait'){
59
-			$this->logger->info('Generating of PDF document: filename [' .$filename. '], stream [' .($stream ? 'TRUE':'FALSE'). '], paper [' .$paper. '], orientation [' .$orientation. ']');
60
-			$this->dompdf->load_html($html);
61
-			$this->dompdf->set_paper($paper, $orientation);
62
-			$this->dompdf->render();
63
-			if($stream){
64
-				$this->dompdf->stream($filename);
65
-			}
66
-			else{
67
-				return $this->dompdf->output();
68
-			}
69
-		}
48
+        /**
49
+         * Generate PDF document
50
+         * @param  string  $html        the HTML content to use for generation
51
+         * @param  string  $filename    the generated PDF document filename
52
+         * @param  boolean $stream      if need send the generated PDF to browser for download
53
+         * @param  string  $paper       the PDF document paper type like 'A4', 'A5', 'letter', etc.
54
+         * @param  string  $orientation the PDF document orientation like 'portrait', 'landscape'
55
+         * @return string|void               if $stream is true send PDF document to browser for download, else return the generated PDF
56
+         * content like to join in Email attachment of for other purpose use.
57
+         */
58
+        public function generate($html, $filename = 'output.pdf', $stream = true, $paper = 'A4', $orientation = 'portrait'){
59
+            $this->logger->info('Generating of PDF document: filename [' .$filename. '], stream [' .($stream ? 'TRUE':'FALSE'). '], paper [' .$paper. '], orientation [' .$orientation. ']');
60
+            $this->dompdf->load_html($html);
61
+            $this->dompdf->set_paper($paper, $orientation);
62
+            $this->dompdf->render();
63
+            if($stream){
64
+                $this->dompdf->stream($filename);
65
+            }
66
+            else{
67
+                return $this->dompdf->output();
68
+            }
69
+        }
70 70
 		
71
-		/**
72
-		* Return the instance of Dompdf
73
-		*
74
-		* @return object the dompdf instance
75
-		*/
76
-		public function getDompdf(){
77
-			return $this->dompdf;
78
-		}
71
+        /**
72
+         * Return the instance of Dompdf
73
+         *
74
+         * @return object the dompdf instance
75
+         */
76
+        public function getDompdf(){
77
+            return $this->dompdf;
78
+        }
79 79
 		
80
-	}
80
+    }
Please login to merge, or discard this patch.
core/libraries/FormValidation.php 1 patch
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -22,10 +22,10 @@  discard block
 block discarded – undo
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 extends BaseClass{
28
+        class FormValidation extends BaseClass{
29 29
 		 
30 30
         /**
31 31
          * The form validation status
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
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
          */
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
         public function __construct() {
94 94
             parent::__construct();
95 95
            
96
-		   //Load form validation language message
96
+            //Load form validation language message
97 97
             Loader::lang('form_validation');
98 98
             $obj = & get_instance();
99 99
             $this->_errorsMessages  = array(
@@ -155,13 +155,13 @@  discard block
 block discarded – undo
155 155
         /**
156 156
          * Set the form validation data
157 157
          * @param array $data the values to be validated
158
-		 *
158
+         *
159 159
          * @return FormValidation Current instance of object.
160 160
          */
161 161
         public function setData(array $data){
162 162
             $this->logger->debug('Setting the form validation data, the values are: ' . stringfy_vars($data));
163 163
             $this->data = $data;
164
-			return $this;
164
+            return $this;
165 165
         }
166 166
 
167 167
         /**
@@ -172,11 +172,11 @@  discard block
 block discarded – undo
172 172
             return $this->data;
173 173
         }
174 174
 
175
-		/**
176
-		* Get the validation function name to validate a rule
177
-		*
178
-		* @return string the function name
179
-		*/
175
+        /**
176
+         * Get the validation function name to validate a rule
177
+         *
178
+         * @return string the function name
179
+         */
180 180
         protected function _toCallCase($funcName, $prefix='_validate') {
181 181
             $funcName = strtolower($funcName);
182 182
             $finalFuncName = $prefix;
@@ -246,12 +246,12 @@  discard block
 block discarded – undo
246 246
             $this->_forceFail = false;
247 247
 
248 248
             foreach ($this->getData() as $inputName => $inputVal) {
249
-    			if(is_array($this->data[$inputName])){
250
-    				$this->data[$inputName] = array_map('trim', $this->data[$inputName]);
251
-    			}
252
-    			else{
253
-    				$this->data[$inputName] = trim($this->data[$inputName]);
254
-    			}
249
+                if(is_array($this->data[$inputName])){
250
+                    $this->data[$inputName] = array_map('trim', $this->data[$inputName]);
251
+                }
252
+                else{
253
+                    $this->data[$inputName] = trim($this->data[$inputName]);
254
+                }
255 255
 
256 256
                 if (array_key_exists($inputName, $this->_rules)) {
257 257
                     foreach ($this->_parseRuleString($this->_rules[$inputName]) as $eachRule) {
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
          *
268 268
          * @param string $inputField Name of the field or the data key to add a rule to
269 269
          * @param string $ruleSets PIPE seperated string of rules
270
-		 *
270
+         *
271 271
          * @return FormValidation Current instance of object.
272 272
          */
273 273
         public function setRule($inputField, $inputLabel, $ruleSets) {
@@ -281,8 +281,8 @@  discard block
 block discarded – undo
281 281
          * Takes an array of rules and uses setRule() to set them, accepts an array
282 282
          * of rule names rather than a pipe-delimited string as well.
283 283
          * @param array $ruleSets
284
-		 *
285
-		 * @return FormValidation Current instance of object.
284
+         *
285
+         * @return FormValidation Current instance of object.
286 286
          */
287 287
         public function setRules(array $ruleSets) {
288 288
             foreach ($ruleSets as $ruleSet) {
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
          * @param string $start Before block of errors gets displayed, HTML allowed.
305 305
          * @param string $end After the block of errors gets displayed, HTML allowed.
306 306
          *
307
-		 * @return FormValidation Current instance of object.
307
+         * @return FormValidation Current instance of object.
308 308
          */
309 309
         public function setErrorsDelimiter($start, $end) {
310 310
             $this->_allErrorsDelimiter[0] = $start;
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
          * @param string $start Displayed before each error.
320 320
          * @param string $end Displayed after each error.
321 321
          * 
322
-		 * @return FormValidation Current instance of object.
322
+         * @return FormValidation Current instance of object.
323 323
          */
324 324
         public function setErrorDelimiter($start, $end) {
325 325
             $this->_eachErrorDelimiter[0] = $start;
@@ -327,21 +327,21 @@  discard block
 block discarded – undo
327 327
             return $this;
328 328
         }
329 329
 
330
-		/**
331
-		* Get the each errors delimiters
332
-		*
333
-		* @return array
334
-		*/
335
-    	public function getErrorDelimiter() {
330
+        /**
331
+         * Get the each errors delimiters
332
+         *
333
+         * @return array
334
+         */
335
+        public function getErrorDelimiter() {
336 336
             return $this->_eachErrorDelimiter;
337 337
         }
338 338
 
339
-		/**
340
-		* Get the all errors delimiters
341
-		*
342
-		* @return array
343
-		*/
344
-    	public function getErrorsDelimiter() {
339
+        /**
340
+         * Get the all errors delimiters
341
+         *
342
+         * @return array
343
+         */
344
+        public function getErrorsDelimiter() {
345 345
             return $this->_allErrorsDelimiter;
346 346
         }
347 347
 
@@ -379,7 +379,7 @@  discard block
 block discarded – undo
379 379
          *
380 380
          * @param string $inputName The form input name or data key
381 381
          * @param string $errorMessage Error to display
382
-		 *
382
+         *
383 383
          * @return formValidation Current instance of the object
384 384
          */
385 385
         public function setCustomError($inputName, $errorMessage) {
@@ -416,17 +416,17 @@  discard block
 block discarded – undo
416 416
          *
417 417
          * @param boolean $limit number of error to display or return
418 418
          * @param boolean $echo Whether or not the values are to be returned or displayed
419
-		 *
419
+         *
420 420
          * @return string Errors formatted for output
421 421
          */
422 422
         public function displayErrors($limit = null, $echo = true) {
423 423
             list($errorsStart, $errorsEnd) = $this->_allErrorsDelimiter;
424 424
             list($errorStart, $errorEnd) = $this->_eachErrorDelimiter;
425 425
             $errorOutput = $errorsStart;
426
-    		$i = 0;
426
+            $i = 0;
427 427
             if (!empty($this->_errors)) {
428 428
                 foreach ($this->_errors as $fieldName => $error) {
429
-        	    	if ($i === $limit) { 
429
+                    if ($i === $limit) { 
430 430
                         break; 
431 431
                     }
432 432
                     $errorOutput .= $errorStart;
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
          * Breaks up a PIPE seperated string of rules, and puts them into an array.
455 455
          *
456 456
          * @param string $ruleString String to be parsed.
457
-		 *
457
+         *
458 458
          * @return array Array of each value in original string.
459 459
          */
460 460
         protected function _parseRuleString($ruleString) {
@@ -467,10 +467,10 @@  discard block
 block discarded – undo
467 467
                 $rule = '#regex\[\/(.*)\/([a-zA-Z0-9]?)\]#';
468 468
                 preg_match($rule, $ruleString, $regexRule);
469 469
                 $ruleStringTemp = preg_replace($rule, '', $ruleString);
470
-                 if(!empty($regexRule[0])){
471
-                     $ruleSets[] = $regexRule[0];
472
-                 }
473
-                 $ruleStringRegex = explode('|', $ruleStringTemp);
470
+                    if(!empty($regexRule[0])){
471
+                        $ruleSets[] = $regexRule[0];
472
+                    }
473
+                    $ruleStringRegex = explode('|', $ruleStringTemp);
474 474
                 foreach ($ruleStringRegex as $rule) {
475 475
                     $rule = trim($rule);
476 476
                     if($rule){
@@ -486,7 +486,7 @@  discard block
 block discarded – undo
486 486
                 } else {
487 487
                     $ruleSets[] = $ruleString;
488 488
                 }
489
-             }
489
+                }
490 490
             return $ruleSets;
491 491
         }
492 492
 
@@ -494,7 +494,7 @@  discard block
 block discarded – undo
494 494
          * Returns whether or not a field obtains the rule "required".
495 495
          *
496 496
          * @param string $fieldName Field to check if required.
497
-		 *
497
+         *
498 498
          * @return boolean Whether or not the field is required.
499 499
          */
500 500
         protected function _fieldIsRequired($fieldName) {
@@ -529,13 +529,13 @@  discard block
 block discarded – undo
529 529
             return;
530 530
         }
531 531
 
532
-		/**
533
-		* Set error for the given field or key
534
-		*
535
-		* @param string $inputName the input or key name
536
-		* @param string $ruleName the rule name
537
-		* @param array|string $replacements
538
-		*/
532
+        /**
533
+         * Set error for the given field or key
534
+         *
535
+         * @param string $inputName the input or key name
536
+         * @param string $ruleName the rule name
537
+         * @param array|string $replacements
538
+         */
539 539
         protected function _setError($inputName, $ruleName, $replacements = array()) {
540 540
             $rulePhraseKeyParts = explode(',', $ruleName);
541 541
             $rulePhrase = null;
@@ -552,7 +552,7 @@  discard block
 block discarded – undo
552 552
             }
553 553
             // Type cast to array in case it's a string
554 554
             $replacements = (array) $replacements;
555
-			$replacementCount = count($replacements);
555
+            $replacementCount = count($replacements);
556 556
             for ($i = 1; $i <= $replacementCount; $i++) {
557 557
                 $key = $i - 1;
558 558
                 $rulePhrase = str_replace('%' . $i, $replacements[$key], $rulePhrase);
@@ -570,11 +570,11 @@  discard block
 block discarded – undo
570 570
          *
571 571
          * @param type $inputArg
572 572
          * @param string $callbackFunc
573
-		 *
573
+         *
574 574
          * @return mixed
575 575
          */
576 576
         protected function _runCallback($inputArg, $callbackFunc) {
577
-			return eval('return ' . $callbackFunc . '("' . $inputArg . '");');
577
+            return eval('return ' . $callbackFunc . '("' . $inputArg . '");');
578 578
         }
579 579
 
580 580
         /**
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
          * arguments.
584 584
          *
585 585
          * @param string $callbackFunc
586
-		 *
586
+         *
587 587
          * @return mixed
588 588
          */
589 589
         protected function _runEmptyCallback($callbackFunc) {
@@ -594,7 +594,7 @@  discard block
 block discarded – undo
594 594
          * Gets a specific label of a specific field input name.
595 595
          *
596 596
          * @param string $inputName
597
-		 *
597
+         *
598 598
          * @return string
599 599
          */
600 600
         protected function _getLabel($inputName) {
@@ -607,7 +607,7 @@  discard block
 block discarded – undo
607 607
          * @param  string $ruleName  the rule name for this validation ("required")
608 608
          * @param  array  $ruleArgs  the rules argument
609 609
          */
610
-		protected function _validateRequired($inputName, $ruleName, array $ruleArgs) {
610
+        protected function _validateRequired($inputName, $ruleName, array $ruleArgs) {
611 611
             $inputVal = $this->post($inputName);
612 612
             if(array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) {
613 613
                 $callbackReturn = $this->_runEmptyCallback($ruleArgs[1]);
@@ -615,8 +615,8 @@  discard block
 block discarded – undo
615 615
                     $this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
616 616
                 }
617 617
             } 
618
-			else if($inputVal == '') {
619
-				$this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
618
+            else if($inputVal == '') {
619
+                $this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
620 620
             }
621 621
         }
622 622
 
@@ -640,10 +640,10 @@  discard block
 block discarded – undo
640 640
          */
641 641
         protected function _validateCallback($inputName, $ruleName, array $ruleArgs) {
642 642
             if (function_exists($ruleArgs[1]) && !empty($this->data[$inputName])) {
643
-				$result = $this->_runCallback($this->data[$inputName], $ruleArgs[1]);
644
-				if(! $result){
645
-					$this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
646
-				}
643
+                $result = $this->_runCallback($this->data[$inputName], $ruleArgs[1]);
644
+                if(! $result){
645
+                    $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
646
+                }
647 647
             }
648 648
         }
649 649
 
@@ -675,7 +675,7 @@  discard block
 block discarded – undo
675 675
                         continue;
676 676
                     }
677 677
                 } 
678
-				else{
678
+                else{
679 679
                     if ($inputVal == $doNotEqual) {
680 680
                         $this->_setError($inputName, $ruleName . ',string', array($this->_getLabel($inputName), $doNotEqual));
681 681
                         continue;
@@ -767,7 +767,7 @@  discard block
 block discarded – undo
767 767
          * @param  string $ruleName  the rule name for this validation ("less_than")
768 768
          * @param  array  $ruleArgs  the rules argument
769 769
          */
770
-    	protected function _validateLessThan($inputName, $ruleName, array $ruleArgs) {
770
+        protected function _validateLessThan($inputName, $ruleName, array $ruleArgs) {
771 771
             $inputVal = $this->post($inputName);
772 772
             if ($inputVal >= $ruleArgs[1]) { 
773 773
                 if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
@@ -783,7 +783,7 @@  discard block
 block discarded – undo
783 783
          * @param  string $ruleName  the rule name for this validation ("greater_than")
784 784
          * @param  array  $ruleArgs  the rules argument
785 785
          */
786
-    	protected function _validateGreaterThan($inputName, $ruleName, array $ruleArgs) {
786
+        protected function _validateGreaterThan($inputName, $ruleName, array $ruleArgs) {
787 787
             $inputVal = $this->post($inputName);
788 788
             if ($inputVal <= $ruleArgs[1]) {
789 789
                 if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
@@ -799,7 +799,7 @@  discard block
 block discarded – undo
799 799
          * @param  string $ruleName  the rule name for this validation ("numeric")
800 800
          * @param  array  $ruleArgs  the rules argument
801 801
          */
802
-    	protected function _validateNumeric($inputName, $ruleName, array $ruleArgs) {
802
+        protected function _validateNumeric($inputName, $ruleName, array $ruleArgs) {
803 803
             $inputVal = $this->post($inputName);
804 804
             if (! is_numeric($inputVal)) {
805 805
                 if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
@@ -815,18 +815,18 @@  discard block
 block discarded – undo
815 815
          * @param  string $ruleName  the rule name for this validation ("exists")
816 816
          * @param  array  $ruleArgs  the rules argument
817 817
          */
818
-		protected function _validateExists($inputName, $ruleName, array $ruleArgs) {
818
+        protected function _validateExists($inputName, $ruleName, array $ruleArgs) {
819 819
             $inputVal = $this->post($inputName);
820
-    		if (! is_object($this->databaseInstance)){
820
+            if (! is_object($this->databaseInstance)){
821 821
                 $obj = & get_instance();
822 822
                 if(isset($obj->database)){
823 823
                     $this->databaseInstance = $obj->database;
824 824
                 } 
825 825
             }
826
-    		list($table, $column) = explode('.', $ruleArgs[1]);
827
-    		$this->databaseInstance->getQueryBuilder()->from($table)
828
-    			                                       ->where($column, $inputVal);
829
-    		$this->databaseInstance->get();
826
+            list($table, $column) = explode('.', $ruleArgs[1]);
827
+            $this->databaseInstance->getQueryBuilder()->from($table)
828
+                                                        ->where($column, $inputVal);
829
+            $this->databaseInstance->get();
830 830
             if ($this->databaseInstance->numRows() <= 0) {
831 831
                 if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
832 832
                     return;
@@ -841,7 +841,7 @@  discard block
 block discarded – undo
841 841
          * @param  string $ruleName  the rule name for this validation ("is_unique")
842 842
          * @param  array  $ruleArgs  the rules argument
843 843
          */
844
-    	protected function _validateIsUnique($inputName, $ruleName, array $ruleArgs) {
844
+        protected function _validateIsUnique($inputName, $ruleName, array $ruleArgs) {
845 845
             $inputVal = $this->post($inputName);
846 846
             if (! is_object($this->databaseInstance)){
847 847
                 $obj = & get_instance();
@@ -849,11 +849,11 @@  discard block
 block discarded – undo
849 849
                     $this->databaseInstance = $obj->database;
850 850
                 } 
851 851
             }
852
-    		list($table, $column) = explode('.', $ruleArgs[1]);
853
-    		$this->databaseInstance->getQueryBuilder()->from($table)
854
-    			                                      ->where($column, $inputVal);
855
-    		$this->databaseInstance->get();
856
-    		if ($this->databaseInstance->numRows() > 0) {
852
+            list($table, $column) = explode('.', $ruleArgs[1]);
853
+            $this->databaseInstance->getQueryBuilder()->from($table)
854
+                                                        ->where($column, $inputVal);
855
+            $this->databaseInstance->get();
856
+            if ($this->databaseInstance->numRows() > 0) {
857 857
                 if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
858 858
                     return;
859 859
                 }
@@ -867,25 +867,25 @@  discard block
 block discarded – undo
867 867
          * @param  string $ruleName  the rule name for this validation ("is_unique_update")
868 868
          * @param  array  $ruleArgs  the rules argument
869 869
          */
870
-    	protected function _validateIsUniqueUpdate($inputName, $ruleName, array $ruleArgs) {
870
+        protected function _validateIsUniqueUpdate($inputName, $ruleName, array $ruleArgs) {
871 871
             $inputVal = $this->post($inputName);
872
-    		if (! is_object($this->databaseInstance)){
872
+            if (! is_object($this->databaseInstance)){
873 873
                 $obj = & get_instance();
874 874
                 if(isset($obj->database)){
875 875
                     $this->databaseInstance = $obj->database;
876 876
                 } 
877 877
             }
878
-    		$data = explode(',', $ruleArgs[1]);
879
-    		if(count($data) < 2){
880
-    			return;
881
-    		}
882
-    		list($table, $column) = explode('.', $data[0]);
883
-    		list($field, $val)    = explode('=', $data[1]);
884
-    		$this->databaseInstance->getQueryBuilder()->from($table)
885
-                                			          ->where($column, $inputVal)
886
-                                            		  ->where($field, '!=', trim($val));
878
+            $data = explode(',', $ruleArgs[1]);
879
+            if(count($data) < 2){
880
+                return;
881
+            }
882
+            list($table, $column) = explode('.', $data[0]);
883
+            list($field, $val)    = explode('=', $data[1]);
884
+            $this->databaseInstance->getQueryBuilder()->from($table)
885
+                                                        ->where($column, $inputVal)
886
+                                                        ->where($field, '!=', trim($val));
887 887
             $this->databaseInstance->get();
888
-    		if ($this->databaseInstance->numRows() > 0) {
888
+            if ($this->databaseInstance->numRows() > 0) {
889 889
                 if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
890 890
                     return;
891 891
                 }
@@ -901,7 +901,7 @@  discard block
 block discarded – undo
901 901
          */
902 902
         protected function _validateInList($inputName, $ruleName, array $ruleArgs) {
903 903
             $inputVal = $this->post($inputName);
904
-    		$list = explode(',', $ruleArgs[1]);
904
+            $list = explode(',', $ruleArgs[1]);
905 905
             $list = array_map('trim', $list);
906 906
             if (! in_array($inputVal, $list)) {
907 907
                 if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
@@ -919,7 +919,7 @@  discard block
 block discarded – undo
919 919
          */
920 920
         protected function _validateRegex($inputName, $ruleName, array $ruleArgs) {
921 921
             $inputVal = $this->post($inputName);
922
-    		$regex = $ruleArgs[1];
922
+            $regex = $ruleArgs[1];
923 923
             if (! preg_match($regex, $inputVal)) {
924 924
                 if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
925 925
                     return;
Please login to merge, or discard this patch.
core/libraries/Upload.php 1 patch
Indentation   +293 added lines, -293 removed lines patch added patch discarded remove patch
@@ -22,139 +22,139 @@  discard block
 block discarded – undo
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 extends BaseClass{
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(
@@ -204,13 +204,13 @@  discard block
 block discarded – undo
204 204
 
205 205
 
206 206
         /**
207
-        *    Construct
208
-        *
209
-        *    @since     0.1
210
-        *    @version   1.0.1
211
-        *    @return    object
212
-        *    @method    object    __construct
213
-        */
207
+         *    Construct
208
+         *
209
+         *    @since     0.1
210
+         *    @version   1.0.1
211
+         *    @return    object
212
+         *    @method    object    __construct
213
+         */
214 214
         public function __construct(){
215 215
             parent::__construct();
216 216
 
@@ -253,17 +253,17 @@  discard block
 block discarded – undo
253 253
             $this->logger->info('The upload file information are : ' .stringfy_vars($this->file_array));
254 254
         }
255 255
         /**
256
-        *    Set input.
257
-        *    If you have $_FILES["file"], you must use the key "file"
258
-        *    Example:
259
-        *        $object->setInput("file");
260
-        *
261
-        *    @since     1.0
262
-        *    @version   1.0
263
-        *    @param     string      $input
264
-        *    @return    object
265
-        *    @method    boolean     setInput
266
-        */
256
+         *    Set input.
257
+         *    If you have $_FILES["file"], you must use the key "file"
258
+         *    Example:
259
+         *        $object->setInput("file");
260
+         *
261
+         *    @since     1.0
262
+         *    @version   1.0
263
+         *    @param     string      $input
264
+         *    @return    object
265
+         *    @method    boolean     setInput
266
+         */
267 267
         public function setInput($input)
268 268
         {
269 269
             if (!empty($input) && (is_string($input) || is_numeric($input) )) {
@@ -272,18 +272,18 @@  discard block
 block discarded – undo
272 272
             return $this;
273 273
         }
274 274
         /**
275
-        *    Set new filename
276
-        *    Example:
277
-        *        FileUpload::setFilename("new file.txt")
278
-        *    Remember:
279
-        *        Use %s to retrive file extension
280
-        *
281
-        *    @since     1.0
282
-        *    @version   1.0
283
-        *    @param     string      $filename
284
-        *    @return    object
285
-        *    @method    boolean     setFilename
286
-        */
275
+         *    Set new filename
276
+         *    Example:
277
+         *        FileUpload::setFilename("new file.txt")
278
+         *    Remember:
279
+         *        Use %s to retrive file extension
280
+         *
281
+         *    @since     1.0
282
+         *    @version   1.0
283
+         *    @param     string      $filename
284
+         *    @return    object
285
+         *    @method    boolean     setFilename
286
+         */
287 287
         public function setFilename($filename)
288 288
         {
289 289
             if ($this->isFilename($filename)) {
@@ -292,14 +292,14 @@  discard block
 block discarded – undo
292 292
             return $this;
293 293
         }
294 294
         /**
295
-        *    Set automatic filename
296
-        *
297
-        *    @since     1.0
298
-        *    @version   1.5
299
-        *    @param     string      $extension
300
-        *    @return    object
301
-        *    @method    boolean     setAutoFilename
302
-        */
295
+         *    Set automatic filename
296
+         *
297
+         *    @since     1.0
298
+         *    @version   1.5
299
+         *    @param     string      $extension
300
+         *    @return    object
301
+         *    @method    boolean     setAutoFilename
302
+         */
303 303
         public function setAutoFilename()
304 304
         {
305 305
             $this->filename = sha1(mt_rand(1, 9999).uniqid());
@@ -307,14 +307,14 @@  discard block
 block discarded – undo
307 307
             return $this;
308 308
         }
309 309
         /**
310
-        *    Set file size limit
311
-        *
312
-        *    @since     1.0
313
-        *    @version   1.0
314
-        *    @param     double     $file_size
315
-        *    @return    object
316
-        *    @method    boolean     setMaxFileSize
317
-        */
310
+         *    Set file size limit
311
+         *
312
+         *    @since     1.0
313
+         *    @version   1.0
314
+         *    @param     double     $file_size
315
+         *    @return    object
316
+         *    @method    boolean     setMaxFileSize
317
+         */
318 318
         public function setMaxFileSize($file_size)
319 319
         {
320 320
             $file_size = $this->sizeInBytes($file_size);
@@ -330,14 +330,14 @@  discard block
 block discarded – undo
330 330
             return $this;
331 331
         }
332 332
         /**
333
-        *    Set array mime types
334
-        *
335
-        *    @since     1.0
336
-        *    @version   1.0
337
-        *    @param     array       $mimes
338
-        *    @return    object
339
-        *    @method    boolean     setAllowedMimeTypes
340
-        */
333
+         *    Set array mime types
334
+         *
335
+         *    @since     1.0
336
+         *    @version   1.0
337
+         *    @param     array       $mimes
338
+         *    @return    object
339
+         *    @method    boolean     setAllowedMimeTypes
340
+         */
341 341
         public function setAllowedMimeTypes(array $mimes)
342 342
         {
343 343
             if (count($mimes) > 0) {
@@ -346,14 +346,14 @@  discard block
 block discarded – undo
346 346
             return $this;
347 347
         }
348 348
         /**
349
-        *    Set input callback
350
-        *
351
-        *    @since     1.0
352
-        *    @version   1.0
353
-        *    @param     mixed       $callback
354
-        *    @return    object
355
-        *    @method    boolean     setCallbackInput
356
-        */
349
+         *    Set input callback
350
+         *
351
+         *    @since     1.0
352
+         *    @version   1.0
353
+         *    @param     mixed       $callback
354
+         *    @return    object
355
+         *    @method    boolean     setCallbackInput
356
+         */
357 357
         public function setCallbackInput($callback)
358 358
         {
359 359
             if (is_callable($callback, false)) {
@@ -362,14 +362,14 @@  discard block
 block discarded – undo
362 362
             return $this;
363 363
         }
364 364
         /**
365
-        *    Set output callback
366
-        *
367
-        *    @since     1.0
368
-        *    @version   1.0
369
-        *    @param     mixed       $callback
370
-        *    @return    object
371
-        *    @method    boolean     setCallbackOutput
372
-        */
365
+         *    Set output callback
366
+         *
367
+         *    @since     1.0
368
+         *    @version   1.0
369
+         *    @param     mixed       $callback
370
+         *    @return    object
371
+         *    @method    boolean     setCallbackOutput
372
+         */
373 373
         public function setCallbackOutput($callback)
374 374
         {
375 375
             if (is_callable($callback, false)) {
@@ -378,14 +378,14 @@  discard block
 block discarded – undo
378 378
             return $this;
379 379
         }
380 380
         /**
381
-        *    Append a mime type to allowed mime types
382
-        *
383
-        *    @since     1.0
384
-        *    @version   1.0.1
385
-        *    @param     string      $mime
386
-        *    @return    object
387
-        *    @method    boolean     setAllowMimeType
388
-        */
381
+         *    Append a mime type to allowed mime types
382
+         *
383
+         *    @since     1.0
384
+         *    @version   1.0.1
385
+         *    @param     string      $mime
386
+         *    @return    object
387
+         *    @method    boolean     setAllowMimeType
388
+         */
389 389
         public function setAllowMimeType($mime)
390 390
         {
391 391
             if (!empty($mime) && is_string($mime)) {
@@ -395,13 +395,13 @@  discard block
 block discarded – undo
395 395
             return $this;
396 396
         }
397 397
         /**
398
-        *    Set allowed mime types from mime helping
399
-        *
400
-        *    @since     1.0.1
401
-        *    @version   1.0.1
402
-        *    @return    object
403
-        *    @method    boolean    setMimeHelping
404
-        */
398
+         *    Set allowed mime types from mime helping
399
+         *
400
+         *    @since     1.0.1
401
+         *    @version   1.0.1
402
+         *    @return    object
403
+         *    @method    boolean    setMimeHelping
404
+         */
405 405
         public function setMimeHelping($name)
406 406
         {
407 407
             if (!empty($name) && is_string($name)) {
@@ -412,17 +412,17 @@  discard block
 block discarded – undo
412 412
             return $this;
413 413
         }
414 414
         /**
415
-        *    Set function to upload file
416
-        *    Examples:
417
-        *        1.- FileUpload::setUploadFunction("move_uploaded_file");
418
-        *        2.- FileUpload::setUploadFunction("copy");
419
-        *
420
-        *    @since     1.0
421
-        *    @version   1.0
422
-        *    @param     string      $function
423
-        *    @return    object
424
-        *    @method    boolean     setUploadFunction
425
-        */
415
+         *    Set function to upload file
416
+         *    Examples:
417
+         *        1.- FileUpload::setUploadFunction("move_uploaded_file");
418
+         *        2.- FileUpload::setUploadFunction("copy");
419
+         *
420
+         *    @since     1.0
421
+         *    @version   1.0
422
+         *    @param     string      $function
423
+         *    @return    object
424
+         *    @method    boolean     setUploadFunction
425
+         */
426 426
         public function setUploadFunction($function)
427 427
         {
428 428
             if (!empty($function) && (is_array($function) || is_string($function) )) {
@@ -433,13 +433,13 @@  discard block
 block discarded – undo
433 433
             return $this;
434 434
         }
435 435
         /**
436
-        *    Clear allowed mime types cache
437
-        *
438
-        *    @since     1.0
439
-        *    @version   1.0
440
-        *    @return    object
441
-        *    @method    boolean    clearAllowedMimeTypes
442
-        */
436
+         *    Clear allowed mime types cache
437
+         *
438
+         *    @since     1.0
439
+         *    @version   1.0
440
+         *    @return    object
441
+         *    @method    boolean    clearAllowedMimeTypes
442
+         */
443 443
         public function clearAllowedMimeTypes()
444 444
         {
445 445
             $this->allowed_mime_types = array();
@@ -447,15 +447,15 @@  discard block
 block discarded – undo
447 447
             return $this;
448 448
         }
449 449
         /**
450
-        *    Set destination output
451
-        *
452
-        *    @since     1.0
453
-        *    @version   1.0
454
-        *    @param     string      $destination_directory      Destination path
455
-        *    @param     boolean     $create_if_not_exist
456
-        *    @return    object
457
-        *    @method    boolean     setDestinationDirectory
458
-        */
450
+         *    Set destination output
451
+         *
452
+         *    @since     1.0
453
+         *    @version   1.0
454
+         *    @param     string      $destination_directory      Destination path
455
+         *    @param     boolean     $create_if_not_exist
456
+         *    @return    object
457
+         *    @method    boolean     setDestinationDirectory
458
+         */
459 459
         public function setDestinationDirectory($destination_directory, $create_if_not_exist = false) {
460 460
             $destination_directory = realpath($destination_directory);
461 461
             if (substr($destination_directory, -1) != DIRECTORY_SEPARATOR) {
@@ -479,14 +479,14 @@  discard block
 block discarded – undo
479 479
             return $this;
480 480
         }
481 481
         /**
482
-        *    Check file exists
483
-        *
484
-        *    @since      1.0
485
-        *    @version    1.0.1
486
-        *    @param      string     $file_destination
487
-        *    @return     boolean
488
-        *    @method     boolean    fileExists
489
-        */
482
+         *    Check file exists
483
+         *
484
+         *    @since      1.0
485
+         *    @version    1.0.1
486
+         *    @param      string     $file_destination
487
+         *    @return     boolean
488
+         *    @method     boolean    fileExists
489
+         */
490 490
         public function fileExists($file_destination)
491 491
         {
492 492
             if ($this->isFilename($file_destination)) {
@@ -495,14 +495,14 @@  discard block
 block discarded – undo
495 495
             return false;
496 496
         }
497 497
         /**
498
-        *    Check dir exists
499
-        *
500
-        *    @since        1.0
501
-        *    @version    1.0.1
502
-        *    @param      string     $path
503
-        *    @return     boolean
504
-        *    @method     boolean    dirExists
505
-        */
498
+         *    Check dir exists
499
+         *
500
+         *    @since        1.0
501
+         *    @version    1.0.1
502
+         *    @param      string     $path
503
+         *    @return     boolean
504
+         *    @method     boolean    dirExists
505
+         */
506 506
         public function dirExists($path)
507 507
         {
508 508
             if ($this->isDirpath($path)) {
@@ -511,29 +511,29 @@  discard block
 block discarded – undo
511 511
             return false;
512 512
         }
513 513
         /**
514
-        *    Check valid filename
515
-        *
516
-        *    @since     1.0
517
-        *    @version   1.0.1
518
-        *    @param     string      $filename
519
-        *    @return    boolean
520
-        *    @method    boolean     isFilename
521
-        */
514
+         *    Check valid filename
515
+         *
516
+         *    @since     1.0
517
+         *    @version   1.0.1
518
+         *    @param     string      $filename
519
+         *    @return    boolean
520
+         *    @method    boolean     isFilename
521
+         */
522 522
         public function isFilename($filename)
523 523
         {
524 524
             $filename = basename($filename);
525 525
             return (!empty($filename) && (is_string( $filename) || is_numeric($filename)));
526 526
         }
527 527
         /**
528
-        *    Validate mime type with allowed mime types,
529
-        *    but if allowed mime types is empty, this method return true
530
-        *
531
-        *    @since     1.0
532
-        *    @version   1.0
533
-        *    @param     string      $mime
534
-        *    @return    boolean
535
-        *    @method    boolean     checkMimeType
536
-        */
528
+         *    Validate mime type with allowed mime types,
529
+         *    but if allowed mime types is empty, this method return true
530
+         *
531
+         *    @since     1.0
532
+         *    @version   1.0
533
+         *    @param     string      $mime
534
+         *    @return    boolean
535
+         *    @method    boolean     checkMimeType
536
+         */
537 537
         public function checkMimeType($mime)
538 538
         {
539 539
             if (count($this->allowed_mime_types) == 0) {
@@ -542,26 +542,26 @@  discard block
 block discarded – undo
542 542
             return in_array(strtolower($mime), $this->allowed_mime_types);
543 543
         }
544 544
         /**
545
-        *    Retrive status of upload
546
-        *
547
-        *    @since     1.0
548
-        *    @version   1.0
549
-        *    @return    boolean
550
-        *    @method    boolean    getStatus
551
-        */
545
+         *    Retrive status of upload
546
+         *
547
+         *    @since     1.0
548
+         *    @version   1.0
549
+         *    @return    boolean
550
+         *    @method    boolean    getStatus
551
+         */
552 552
         public function getStatus()
553 553
         {
554 554
             return $this->file['status'];
555 555
         }
556 556
         /**
557
-        *    Check valid path
558
-        *
559
-        *    @since        1.0
560
-        *    @version    1.0.1
561
-        *    @param        string    $filename
562
-        *    @return     boolean
563
-        *    @method     boolean    isDirpath
564
-        */
557
+         *    Check valid path
558
+         *
559
+         *    @since        1.0
560
+         *    @version    1.0.1
561
+         *    @param        string    $filename
562
+         *    @return     boolean
563
+         *    @method     boolean    isDirpath
564
+         */
565 565
         public function isDirpath($path)
566 566
         {
567 567
             if (!empty( $path) && (is_string( $path) || is_numeric($path) )) {
@@ -574,26 +574,26 @@  discard block
 block discarded – undo
574 574
             return false;
575 575
         }
576 576
         /**
577
-        *    Allow overwriting files
578
-        *
579
-        *    @since      1.0
580
-        *    @version    1.0
581
-        *    @return     object
582
-        *    @method     boolean    allowOverwriting
583
-        */
577
+         *    Allow overwriting files
578
+         *
579
+         *    @since      1.0
580
+         *    @version    1.0
581
+         *    @return     object
582
+         *    @method     boolean    allowOverwriting
583
+         */
584 584
         public function allowOverwriting()
585 585
         {
586 586
             $this->overwrite_file = true;
587 587
             return $this;
588 588
         }
589 589
         /**
590
-        *    File info
591
-        *
592
-        *    @since      1.0
593
-        *    @version    1.0
594
-        *    @return     object
595
-        *    @method     object    getInfo
596
-        */
590
+         *    File info
591
+         *
592
+         *    @since      1.0
593
+         *    @version    1.0
594
+         *    @return     object
595
+         *    @method     object    getInfo
596
+         */
597 597
         public function getInfo()
598 598
         {
599 599
             return (object)$this->file;
@@ -611,13 +611,13 @@  discard block
 block discarded – undo
611 611
 
612 612
         
613 613
         /**
614
-        *    Upload file
615
-        *
616
-        *    @since     1.0
617
-        *    @version   1.0.1
618
-        *    @return    boolean
619
-        *    @method    boolean    save
620
-        */
614
+         *    Upload file
615
+         *
616
+         *    @since     1.0
617
+         *    @version   1.0.1
618
+         *    @return    boolean
619
+         *    @method    boolean    save
620
+         */
621 621
         public function save(){
622 622
             if (count($this->file_array) > 0 && array_key_exists($this->input, $this->file_array)) {
623 623
                 // set original filename if not have a new name
@@ -674,15 +674,15 @@  discard block
 block discarded – undo
674 674
 
675 675
 
676 676
         /**
677
-        *    File size for humans.
678
-        *
679
-        *    @since      1.0
680
-        *    @version    1.0
681
-        *    @param      integer    $bytes
682
-        *    @param      integer    $precision
683
-        *    @return     string
684
-        *    @method     string     sizeFormat
685
-        */
677
+         *    File size for humans.
678
+         *
679
+         *    @since      1.0
680
+         *    @version    1.0
681
+         *    @param      integer    $bytes
682
+         *    @param      integer    $precision
683
+         *    @return     string
684
+         *    @method     string     sizeFormat
685
+         */
686 686
         public function sizeFormat($size, $precision = 2)
687 687
         {
688 688
             if($size > 0){
@@ -695,14 +695,14 @@  discard block
 block discarded – undo
695 695
 
696 696
         
697 697
         /**
698
-        *    Convert human file size to bytes
699
-        *
700
-        *    @since      1.0
701
-        *    @version    1.0.1
702
-        *    @param      integer|double    $size
703
-        *    @return     integer|double
704
-        *    @method     string     sizeInBytes
705
-        */
698
+         *    Convert human file size to bytes
699
+         *
700
+         *    @since      1.0
701
+         *    @version    1.0.1
702
+         *    @param      integer|double    $size
703
+         *    @return     integer|double
704
+         *    @method     string     sizeInBytes
705
+         */
706 706
         public function sizeInBytes($size)
707 707
         {
708 708
             $unit = 'B';
@@ -754,7 +754,7 @@  discard block
 block discarded – undo
754 754
                 return true;
755 755
             }
756 756
 
757
-             //check for php upload error
757
+                //check for php upload error
758 758
             if(is_numeric($this->file['error']) && $this->file['error'] > 0){
759 759
                 $this->setError($this->getPhpUploadErrorMessageByCode($this->file['error']));
760 760
                 return true;
@@ -766,7 +766,7 @@  discard block
 block discarded – undo
766 766
                 return true;
767 767
             }
768 768
 
769
-             // Check file size
769
+                // Check file size
770 770
             if ($this->max_file_size > 0 && $this->max_file_size < $this->file['size']) {
771 771
                 $this->setError(sprintf($this->error_messages['max_file_size'], $this->sizeFormat($this->max_file_size)));
772 772
                 return true;
Please login to merge, or discard this patch.
core/libraries/Assets.php 1 patch
Indentation   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -1,149 +1,149 @@
 block discarded – undo
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 extends BaseStaticClass{
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 extends BaseStaticClass{
42 42
 
43 43
 
44
-		/**
45
-		 *  Generate the link of the assets file.
46
-		 *  
47
-		 *  Generates the absolute link of a file inside ASSETS_PATH folder.
48
-		 *  For example :
49
-		 *  	echo Assets::path('foo/bar/css/style.css'); => http://mysite.com/assets/foo/bar/css/style.css
50
-		 *  Note:
51
-		 *  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.
52
-		 *  
53
-		 *  @param string $asset the name of the assets file path with the extension.
54
-		 *  @return string|null the absolute path of the assets file, if it exists otherwise returns null if the file does not exist.
55
-		 */
56
-		public static function path($asset){
57
-			$logger = self::getLogger();	
58
-			$path = ASSETS_PATH . $asset;
44
+        /**
45
+         *  Generate the link of the assets file.
46
+         *  
47
+         *  Generates the absolute link of a file inside ASSETS_PATH folder.
48
+         *  For example :
49
+         *  	echo Assets::path('foo/bar/css/style.css'); => http://mysite.com/assets/foo/bar/css/style.css
50
+         *  Note:
51
+         *  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.
52
+         *  
53
+         *  @param string $asset the name of the assets file path with the extension.
54
+         *  @return string|null the absolute path of the assets file, if it exists otherwise returns null if the file does not exist.
55
+         */
56
+        public static function path($asset){
57
+            $logger = self::getLogger();	
58
+            $path = ASSETS_PATH . $asset;
59 59
 			
60
-			$logger->debug('Including the Assets file [' . $path . ']');
61
-			//Check if the file exists
62
-			if(file_exists($path)){
63
-				$logger->info('Assets file [' . $path . '] included successfully');
64
-				return Url::base_url($path);
65
-			}
66
-			$logger->warning('Assets file [' . $path . '] does not exist');
67
-			return null;
68
-		}
60
+            $logger->debug('Including the Assets file [' . $path . ']');
61
+            //Check if the file exists
62
+            if(file_exists($path)){
63
+                $logger->info('Assets file [' . $path . '] included successfully');
64
+                return Url::base_url($path);
65
+            }
66
+            $logger->warning('Assets file [' . $path . '] does not exist');
67
+            return null;
68
+        }
69 69
 		
70
-		/**
71
-		 *  Generate the link of the css file.
72
-		 *  
73
-		 *  Generates the absolute link of a file containing the CSS style.
74
-		 *  For example :
75
-		 *  	echo Assets::css('mystyle'); => http://mysite.com/assets/css/mystyle.css
76
-		 *  Note:
77
-		 *  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.
78
-		 *  
79
-		 *  @param string $path the name of the css file without the extension.
80
-		 *  @return string|null the absolute path of the css file, if it exists otherwise returns null if the file does not exist.
81
-		 */
82
-		public static function css($path){
83
-			$logger = self::getLogger();
84
-			/*
70
+        /**
71
+         *  Generate the link of the css file.
72
+         *  
73
+         *  Generates the absolute link of a file containing the CSS style.
74
+         *  For example :
75
+         *  	echo Assets::css('mystyle'); => http://mysite.com/assets/css/mystyle.css
76
+         *  Note:
77
+         *  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.
78
+         *  
79
+         *  @param string $path the name of the css file without the extension.
80
+         *  @return string|null the absolute path of the css file, if it exists otherwise returns null if the file does not exist.
81
+         */
82
+        public static function css($path){
83
+            $logger = self::getLogger();
84
+            /*
85 85
 			* if the file name contains the ".css" extension, replace it with 
86 86
 			* an empty string for better processing.
87 87
 			*/
88
-			$path = str_ireplace('.css', '', $path);
89
-			$path = ASSETS_PATH . 'css/' . $path . '.css';
88
+            $path = str_ireplace('.css', '', $path);
89
+            $path = ASSETS_PATH . 'css/' . $path . '.css';
90 90
 			
91
-			$logger->debug('Including the Assets file [' . $path . '] for CSS');
92
-			//Check if the file exists
93
-			if(file_exists($path)){
94
-				$logger->info('Assets file [' . $path . '] for CSS included successfully');
95
-				return Url::base_url($path);
96
-			}
97
-			$logger->warning('Assets file [' . $path . '] for CSS does not exist');
98
-			return null;
99
-		}
91
+            $logger->debug('Including the Assets file [' . $path . '] for CSS');
92
+            //Check if the file exists
93
+            if(file_exists($path)){
94
+                $logger->info('Assets file [' . $path . '] for CSS included successfully');
95
+                return Url::base_url($path);
96
+            }
97
+            $logger->warning('Assets file [' . $path . '] for CSS does not exist');
98
+            return null;
99
+        }
100 100
 
101
-		/**
102
-		 *  Generate the link of the javascript file.
103
-		 *  
104
-		 *  Generates the absolute link of a file containing the javascript.
105
-		 *  For example :
106
-		 *  	echo Assets::js('myscript'); => http://mysite.com/assets/js/myscript.js
107
-		 *  Note:
108
-		 *  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.
109
-		 *  
110
-		 *  @param string $path the name of the javascript file without the extension.
111
-		 *  @return string|null the absolute path of the javascript file, if it exists otherwise returns null if the file does not exist.
112
-		 */
113
-		public static function js($path){
114
-			$logger = self::getLogger();
115
-			$path = str_ireplace('.js', '', $path);
116
-			$path = ASSETS_PATH . 'js/' . $path . '.js';
117
-			$logger->debug('Including the Assets file [' . $path . '] for javascript');
118
-			if(file_exists($path)){
119
-				$logger->info('Assets file [' . $path . '] for Javascript included successfully');
120
-				return Url::base_url($path);
121
-			}
122
-			$logger->warning('Assets file [' . $path . '] for Javascript does not exist');
123
-			return null;
124
-		}
101
+        /**
102
+         *  Generate the link of the javascript file.
103
+         *  
104
+         *  Generates the absolute link of a file containing the javascript.
105
+         *  For example :
106
+         *  	echo Assets::js('myscript'); => http://mysite.com/assets/js/myscript.js
107
+         *  Note:
108
+         *  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.
109
+         *  
110
+         *  @param string $path the name of the javascript file without the extension.
111
+         *  @return string|null the absolute path of the javascript file, if it exists otherwise returns null if the file does not exist.
112
+         */
113
+        public static function js($path){
114
+            $logger = self::getLogger();
115
+            $path = str_ireplace('.js', '', $path);
116
+            $path = ASSETS_PATH . 'js/' . $path . '.js';
117
+            $logger->debug('Including the Assets file [' . $path . '] for javascript');
118
+            if(file_exists($path)){
119
+                $logger->info('Assets file [' . $path . '] for Javascript included successfully');
120
+                return Url::base_url($path);
121
+            }
122
+            $logger->warning('Assets file [' . $path . '] for Javascript does not exist');
123
+            return null;
124
+        }
125 125
 
126
-		/**
127
-		 *  Generate the link of the image file.
128
-		 *  
129
-		 *  Generates the absolute link of a file containing the image.
130
-		 *  For example :
131
-		 *  	echo Assets::img('myimage.png'); => http://mysite.com/assets/images/myimage.png
132
-		 *  Note:
133
-		 *  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.
134
-		 *  
135
-		 *  @param string $path the name of the image file with the extension.
136
-		 *  @return string|null the absolute path of the image file, if it exists otherwise returns null if the file does not exist.
137
-		 */
138
-		public static function img($path){
139
-			$logger = self::getLogger();
140
-			$path = ASSETS_PATH . 'images/' . $path;
141
-			$logger->debug('Including the Assets file [' . $path . '] for image');
142
-			if(file_exists($path)){
143
-				$logger->info('Assets file [' . $path . '] for image included successfully');
144
-				return Url::base_url($path);
145
-			}
146
-			$logger->warning('Assets file [' . $path . '] for image does not exist');
147
-			return null;
148
-		}
149
-	}
126
+        /**
127
+         *  Generate the link of the image file.
128
+         *  
129
+         *  Generates the absolute link of a file containing the image.
130
+         *  For example :
131
+         *  	echo Assets::img('myimage.png'); => http://mysite.com/assets/images/myimage.png
132
+         *  Note:
133
+         *  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.
134
+         *  
135
+         *  @param string $path the name of the image file with the extension.
136
+         *  @return string|null the absolute path of the image file, if it exists otherwise returns null if the file does not exist.
137
+         */
138
+        public static function img($path){
139
+            $logger = self::getLogger();
140
+            $path = ASSETS_PATH . 'images/' . $path;
141
+            $logger->debug('Including the Assets file [' . $path . '] for image');
142
+            if(file_exists($path)){
143
+                $logger->info('Assets file [' . $path . '] for image included successfully');
144
+                return Url::base_url($path);
145
+            }
146
+            $logger->warning('Assets file [' . $path . '] for image does not exist');
147
+            return null;
148
+        }
149
+    }
Please login to merge, or discard this patch.
core/libraries/Cookie.php 1 patch
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -1,94 +1,94 @@
 block discarded – undo
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 Cookie extends BaseStaticClass{
27
+    class Cookie extends BaseStaticClass{
28 28
 
29
-		/**
30
-		 * Get the cookie item value
31
-		 * @param  string $item    the cookie item name to get
32
-		 * @param  mixed $default the default value to use if can not find the cokkie item in the list
33
-		 * @return mixed          the cookie value if exist or the default value
34
-		 */
35
-		public static function get($item, $default = null){
36
-			$logger = self::getLogger();
37
-			if(array_key_exists($item, $_COOKIE)){
38
-				return $_COOKIE[$item];
39
-			}
40
-			$logger->warning('Cannot find cookie item [' . $item . '], using the default value [' . $default . ']');
41
-			return $default;
42
-		}
29
+        /**
30
+         * Get the cookie item value
31
+         * @param  string $item    the cookie item name to get
32
+         * @param  mixed $default the default value to use if can not find the cokkie item in the list
33
+         * @return mixed          the cookie value if exist or the default value
34
+         */
35
+        public static function get($item, $default = null){
36
+            $logger = self::getLogger();
37
+            if(array_key_exists($item, $_COOKIE)){
38
+                return $_COOKIE[$item];
39
+            }
40
+            $logger->warning('Cannot find cookie item [' . $item . '], using the default value [' . $default . ']');
41
+            return $default;
42
+        }
43 43
 
44
-		/**
45
-		 * Set the cookie item value
46
-		 * @param string  $name     the cookie item name
47
-		 * @param string  $value    the cookie value to set
48
-		 * @param integer $expire   the time to live for this cookie
49
-		 * @param string  $path     the path that the cookie will be available
50
-		 * @param string  $domain   the domain that the cookie will be available
51
-		 * @param boolean $secure   if this cookie will be available on secure connection or not
52
-		 * @param boolean $httponly if this cookie will be available under HTTP protocol.
53
-		 */
54
-		public static function set($name, $value = '', $expire = 0, $path = '/', $domain = '', $secure = false, $httponly = false){
55
-			if(headers_sent()){
56
-				show_error('There exists a cookie that we wanted to create that we couldn\'t 
44
+        /**
45
+         * Set the cookie item value
46
+         * @param string  $name     the cookie item name
47
+         * @param string  $value    the cookie value to set
48
+         * @param integer $expire   the time to live for this cookie
49
+         * @param string  $path     the path that the cookie will be available
50
+         * @param string  $domain   the domain that the cookie will be available
51
+         * @param boolean $secure   if this cookie will be available on secure connection or not
52
+         * @param boolean $httponly if this cookie will be available under HTTP protocol.
53
+         */
54
+        public static function set($name, $value = '', $expire = 0, $path = '/', $domain = '', $secure = false, $httponly = false){
55
+            if(headers_sent()){
56
+                show_error('There exists a cookie that we wanted to create that we couldn\'t 
57 57
 						    because headers was already sent. Make sure to do this first 
58 58
 							before outputing anything.');
59
-			}
60
-			$timestamp = $expire;
61
-			if($expire){
62
-				$timestamp = time() + $expire;
63
-			}
64
-			setcookie($name, $value, $timestamp, $path, $domain, $secure, $httponly);
65
-		}
59
+            }
60
+            $timestamp = $expire;
61
+            if($expire){
62
+                $timestamp = time() + $expire;
63
+            }
64
+            setcookie($name, $value, $timestamp, $path, $domain, $secure, $httponly);
65
+        }
66 66
 
67
-		/**
68
-		 * Delete the cookie item in the list
69
-		 * @param  string $item the cookie item name to be cleared
70
-		 * @return boolean true if the item exists and is deleted successfully otherwise will return false.
71
-		 */
72
-		public static function delete($item){
73
-			$logger = self::getLogger();
74
-			if(array_key_exists($item, $_COOKIE)){
75
-				$logger->info('Delete cookie item ['.$item.']');
76
-				unset($_COOKIE[$item]);
77
-				return true;
78
-			}
79
-			else{
80
-				$logger->warning('Cookie item ['.$item.'] to be deleted does not exists');
81
-				return false;
82
-			}
83
-		}
67
+        /**
68
+         * Delete the cookie item in the list
69
+         * @param  string $item the cookie item name to be cleared
70
+         * @return boolean true if the item exists and is deleted successfully otherwise will return false.
71
+         */
72
+        public static function delete($item){
73
+            $logger = self::getLogger();
74
+            if(array_key_exists($item, $_COOKIE)){
75
+                $logger->info('Delete cookie item ['.$item.']');
76
+                unset($_COOKIE[$item]);
77
+                return true;
78
+            }
79
+            else{
80
+                $logger->warning('Cookie item ['.$item.'] to be deleted does not exists');
81
+                return false;
82
+            }
83
+        }
84 84
 
85
-		/**
86
-		 * Check if the given cookie item exists
87
-		 * @param  string $item the cookie item name
88
-		 * @return boolean       true if the cookie item is set, false or not
89
-		 */
90
-		public static function exists($item){
91
-			return array_key_exists($item, $_COOKIE);
92
-		}
85
+        /**
86
+         * Check if the given cookie item exists
87
+         * @param  string $item the cookie item name
88
+         * @return boolean       true if the cookie item is set, false or not
89
+         */
90
+        public static function exists($item){
91
+            return array_key_exists($item, $_COOKIE);
92
+        }
93 93
 
94
-	}
94
+    }
Please login to merge, or discard this patch.
core/classes/Module.php 1 patch
Indentation   +228 added lines, -228 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4 4
      * TNH Framework
5 5
      *
6 6
      * A simple PHP framework using HMVC architecture
@@ -22,252 +22,252 @@  discard block
 block discarded – undo
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
-	class Module extends BaseStaticClass{
27
+    class Module extends BaseStaticClass{
28 28
 		
29
-		/**
30
-		 * list of loaded module
31
-		 * @var array
32
-		 */
33
-		private static $list = array();
29
+        /**
30
+         * list of loaded module
31
+         * @var array
32
+         */
33
+        private static $list = array();
34 34
 
35
-		/**
36
-		 * Initialise the module list by scanning the directory MODULE_PATH
37
-		 */
38
-		public function init(){
39
-			$logger = self::getLogger();
40
-			$logger->debug('Check if the application contains the modules ...');
41
-			$moduleDir = opendir(MODULE_PATH);
42
-			if (is_resource($moduleDir)){
43
-				while(($module = readdir($moduleDir)) !== false){
44
-					if (preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)){
45
-						self::$list[] = $module;
46
-					}
47
-					else{
48
-						$logger->info('Skipping [' .$module. '], may be this is not a directory or does not exists or is invalid name');
49
-					}
50
-				}
51
-				closedir($moduleDir);
52
-			}
53
-			ksort(self::$list);
35
+        /**
36
+         * Initialise the module list by scanning the directory MODULE_PATH
37
+         */
38
+        public function init(){
39
+            $logger = self::getLogger();
40
+            $logger->debug('Check if the application contains the modules ...');
41
+            $moduleDir = opendir(MODULE_PATH);
42
+            if (is_resource($moduleDir)){
43
+                while(($module = readdir($moduleDir)) !== false){
44
+                    if (preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)){
45
+                        self::$list[] = $module;
46
+                    }
47
+                    else{
48
+                        $logger->info('Skipping [' .$module. '], may be this is not a directory or does not exists or is invalid name');
49
+                    }
50
+                }
51
+                closedir($moduleDir);
52
+            }
53
+            ksort(self::$list);
54 54
 			
55
-			if (! empty(self::$list)){
56
-				$logger->info('The application contains the module below [' . implode(', ', self::getModuleList()) . ']');
57
-			}
58
-		}
55
+            if (! empty(self::$list)){
56
+                $logger->info('The application contains the module below [' . implode(', ', self::getModuleList()) . ']');
57
+            }
58
+        }
59 59
 		
60 60
 
61
-		/**
62
-		 * Add new module in the list
63
-		 * @param string $name the name of the module
64
-		 *
65
-		 * @return object the current instance
66
-		 */
67
-		public function add($name){
68
-			self::$list[] = $name;
69
-			return $this;
70
-		}
61
+        /**
62
+         * Add new module in the list
63
+         * @param string $name the name of the module
64
+         *
65
+         * @return object the current instance
66
+         */
67
+        public function add($name){
68
+            self::$list[] = $name;
69
+            return $this;
70
+        }
71 71
 		
72
-		/**
73
-		 * Get the list of the custom autoload configuration from module if exists
74
-		 * @return array|boolean the autoload configurations list or false if no module contains the autoload configuration values
75
-		 */
76
-		public static function getModulesAutoloadConfig(){
77
-			$logger = self::getLogger();
78
-			if (empty(self::$list)){
79
-				$logger->info('No module was loaded skipping.');
80
-				return false;
81
-			}
82
-			$autoloads = array();
83
-			$autoloads['libraries'] = array();
84
-			$autoloads['config']    = array();
85
-			$autoloads['models']    = array();
86
-			$autoloads['functions'] = array();
87
-			$autoloads['languages'] = array();
72
+        /**
73
+         * Get the list of the custom autoload configuration from module if exists
74
+         * @return array|boolean the autoload configurations list or false if no module contains the autoload configuration values
75
+         */
76
+        public static function getModulesAutoloadConfig(){
77
+            $logger = self::getLogger();
78
+            if (empty(self::$list)){
79
+                $logger->info('No module was loaded skipping.');
80
+                return false;
81
+            }
82
+            $autoloads = array();
83
+            $autoloads['libraries'] = array();
84
+            $autoloads['config']    = array();
85
+            $autoloads['models']    = array();
86
+            $autoloads['functions'] = array();
87
+            $autoloads['languages'] = array();
88 88
 			
89
-			foreach (self::$list as $module) {
90
-				$file = MODULE_PATH . $module . DS . 'config' . DS . 'autoload.php';
91
-				if (file_exists($file)){
92
-					$autoload = array();
93
-					require_once $file;
94
-					if (! empty($autoload) && is_array($autoload)){
95
-						$autoloads = array_merge_recursive($autoloads, $autoload);
96
-						unset($autoload);
97
-					}
98
-				}
99
-			}
100
-			return $autoloads;
101
-		}
89
+            foreach (self::$list as $module) {
90
+                $file = MODULE_PATH . $module . DS . 'config' . DS . 'autoload.php';
91
+                if (file_exists($file)){
92
+                    $autoload = array();
93
+                    require_once $file;
94
+                    if (! empty($autoload) && is_array($autoload)){
95
+                        $autoloads = array_merge_recursive($autoloads, $autoload);
96
+                        unset($autoload);
97
+                    }
98
+                }
99
+            }
100
+            return $autoloads;
101
+        }
102 102
 
103
-		/**
104
-		 * Get the list of the custom routes configuration from module if exists
105
-		 * @return array|boolean the routes list or false if no module contains the routes configuration
106
-		 */
107
-		public static function getModulesRoutesConfig(){
108
-			$logger = self::getLogger();
109
-			if (empty(self::$list)){
110
-				$logger->info('No module was loaded skipping.');
111
-				return false;
112
-			}
113
-			$routes = array();
114
-			foreach (self::$list as $module) {
115
-				$file = MODULE_PATH . $module . DS . 'config' . DS . 'routes.php';
116
-				if (file_exists($file)){
117
-					$route = array();
118
-					require_once $file;
119
-					if (! empty($route) && is_array($route)){
120
-						$routes = array_merge($routes, $route);
121
-						unset($route);
122
-					}
123
-				}
124
-			}
125
-			return $routes;
126
-		}
103
+        /**
104
+         * Get the list of the custom routes configuration from module if exists
105
+         * @return array|boolean the routes list or false if no module contains the routes configuration
106
+         */
107
+        public static function getModulesRoutesConfig(){
108
+            $logger = self::getLogger();
109
+            if (empty(self::$list)){
110
+                $logger->info('No module was loaded skipping.');
111
+                return false;
112
+            }
113
+            $routes = array();
114
+            foreach (self::$list as $module) {
115
+                $file = MODULE_PATH . $module . DS . 'config' . DS . 'routes.php';
116
+                if (file_exists($file)){
117
+                    $route = array();
118
+                    require_once $file;
119
+                    if (! empty($route) && is_array($route)){
120
+                        $routes = array_merge($routes, $route);
121
+                        unset($route);
122
+                    }
123
+                }
124
+            }
125
+            return $routes;
126
+        }
127 127
 
128 128
 
129
-		/**
130
-		 * Check if in module list can have this controller
131
-		 * @see Module::findClassInModuleFullFilePath
132
-		 * @return boolean|string  false or null if no module have this controller, path the full path of the controller
133
-		 */
134
-		public static function findControllerFullPath($class, $module = null){
135
-			return self::findClassInModuleFullFilePath($class, $module, 'controllers');
136
-		}
129
+        /**
130
+         * Check if in module list can have this controller
131
+         * @see Module::findClassInModuleFullFilePath
132
+         * @return boolean|string  false or null if no module have this controller, path the full path of the controller
133
+         */
134
+        public static function findControllerFullPath($class, $module = null){
135
+            return self::findClassInModuleFullFilePath($class, $module, 'controllers');
136
+        }
137 137
 
138
-		/**
139
-		 * Check if in module list can have this model
140
-		 * @see Module::findClassInModuleFullFilePath
141
-		 * @return boolean|string  false or null if no module have this model, return the full path of this model
142
-		 */
143
-		public static function findModelFullPath($class, $module = null){
144
-			return self::findClassInModuleFullFilePath($class, $module, 'models');
145
-		}
138
+        /**
139
+         * Check if in module list can have this model
140
+         * @see Module::findClassInModuleFullFilePath
141
+         * @return boolean|string  false or null if no module have this model, return the full path of this model
142
+         */
143
+        public static function findModelFullPath($class, $module = null){
144
+            return self::findClassInModuleFullFilePath($class, $module, 'models');
145
+        }
146 146
 
147
-		/**
148
-		 * Check if in module list can have this library
149
-		 * @see Module::findClassInModuleFullFilePath
150
-		 * @return boolean|string  false or null if no module have this library,  return the full path of this library
151
-		 */
152
-		public static function findLibraryFullPath($class, $module = null){
153
-			return self::findClassInModuleFullFilePath($class, $module, 'libraries');
154
-		}
147
+        /**
148
+         * Check if in module list can have this library
149
+         * @see Module::findClassInModuleFullFilePath
150
+         * @return boolean|string  false or null if no module have this library,  return the full path of this library
151
+         */
152
+        public static function findLibraryFullPath($class, $module = null){
153
+            return self::findClassInModuleFullFilePath($class, $module, 'libraries');
154
+        }
155 155
 
156 156
 		
157
-		/**
158
-		 * Check if in module list can have this config
159
-		 * @see  Module::findNonClassInModuleFullFilePath
160
-		 * @return boolean|string  false or null if no module have this configuration,  return the full path of this configuration
161
-		 */
162
-		public static function findConfigFullPath($configuration, $module = null){
163
-			return self::findNonClassInModuleFullFilePath($configuration, $module, 'config');
164
-		}
157
+        /**
158
+         * Check if in module list can have this config
159
+         * @see  Module::findNonClassInModuleFullFilePath
160
+         * @return boolean|string  false or null if no module have this configuration,  return the full path of this configuration
161
+         */
162
+        public static function findConfigFullPath($configuration, $module = null){
163
+            return self::findNonClassInModuleFullFilePath($configuration, $module, 'config');
164
+        }
165 165
 
166
-		/**
167
-		 * Check if in module list can have this helper
168
-		 * @see  Module::findNonClassInModuleFullFilePath
169
-		 * @return boolean|string  false or null if no module have this helper,  return the full path of this helper
170
-		 */
171
-		public static function findFunctionFullPath($helper, $module = null){
172
-			return self::findNonClassInModuleFullFilePath($helper, $module, 'functions');
173
-		}
166
+        /**
167
+         * Check if in module list can have this helper
168
+         * @see  Module::findNonClassInModuleFullFilePath
169
+         * @return boolean|string  false or null if no module have this helper,  return the full path of this helper
170
+         */
171
+        public static function findFunctionFullPath($helper, $module = null){
172
+            return self::findNonClassInModuleFullFilePath($helper, $module, 'functions');
173
+        }
174 174
 
175
-		/**
176
-		 * Check if in module list can have this view
177
-		 * @see  Module::findNonClassInModuleFullFilePath
178
-		 * @return boolean|string  false or null if no module have this view, path the full path of the view
179
-		 */
180
-		public static function findViewFullPath($view, $module = null){
181
-			return self::findNonClassInModuleFullFilePath($view, $module, 'views');
182
-		}
175
+        /**
176
+         * Check if in module list can have this view
177
+         * @see  Module::findNonClassInModuleFullFilePath
178
+         * @return boolean|string  false or null if no module have this view, path the full path of the view
179
+         */
180
+        public static function findViewFullPath($view, $module = null){
181
+            return self::findNonClassInModuleFullFilePath($view, $module, 'views');
182
+        }
183 183
 
184
-		/**
185
-		 * Check if in module list can have this language
186
-		 * @see  Module::findNonClassInModuleFullFilePath
187
-		 * @return boolean|string  false or null if no module have this language,  return the full path of this language
188
-		 */
189
-		public static function findLanguageFullPath($language, $appLang, $module = null){
190
-			return self::findNonClassInModuleFullFilePath($language, $module, 'lang', $appLang);
191
-		}
184
+        /**
185
+         * Check if in module list can have this language
186
+         * @see  Module::findNonClassInModuleFullFilePath
187
+         * @return boolean|string  false or null if no module have this language,  return the full path of this language
188
+         */
189
+        public static function findLanguageFullPath($language, $appLang, $module = null){
190
+            return self::findNonClassInModuleFullFilePath($language, $module, 'lang', $appLang);
191
+        }
192 192
 
193
-		/**
194
-		 * Get the list of module loaded
195
-		 * @return array the module list
196
-		 */
197
-		public static function getModuleList(){
198
-			return self::$list;
199
-		}
193
+        /**
194
+         * Get the list of module loaded
195
+         * @return array the module list
196
+         */
197
+        public static function getModuleList(){
198
+            return self::$list;
199
+        }
200 200
 
201
-		/**
202
-		 * Check if the application has an module
203
-		 * @return boolean
204
-		 */
205
-		public static function hasModule(){
206
-			return !empty(self::$list);
207
-		}
201
+        /**
202
+         * Check if the application has an module
203
+         * @return boolean
204
+         */
205
+        public static function hasModule(){
206
+            return !empty(self::$list);
207
+        }
208 208
 
209
-		/**
210
-		 * Check if in module list can have the model, controller, library
211
-		 * @param  string $class the class name of library, model, controller
212
-		 * @param string $module the module name
213
-		 * @param string $type the name of the type "controllers", "libraries", "models"
214
-		 * @return boolean|string  false or null if no module 
215
-		 * have this class, return the full path of the class
216
-		 */
217
-		protected static function findClassInModuleFullFilePath($class, $module, $type){
218
-			$logger = self::getLogger();
219
-		    $class = str_ireplace('.php', '', $class);
220
-		    $class = ucfirst($class);
221
-		    $classFile = $class.'.php';
222
-		    $logger->debug('Checking the class [' . $class . '] in module [' . $module . '] for [' . $type . '] ...');
223
-		    $filePath = MODULE_PATH . $module . DS . $type . DS . $classFile;
224
-		    if (file_exists($filePath)){
225
-		        $logger->info('Found class [' . $class . '] in module [' . $module . '] for [' . $type . '] the file path is [' .$filePath. ']');
226
-		        return $filePath;
227
-		    }
228
-		    $logger->info('Class [' . $class . '] does not exist in the module [' .$module. '] for [' . $type . ']');
229
-		    return false;
230
-		}
209
+        /**
210
+         * Check if in module list can have the model, controller, library
211
+         * @param  string $class the class name of library, model, controller
212
+         * @param string $module the module name
213
+         * @param string $type the name of the type "controllers", "libraries", "models"
214
+         * @return boolean|string  false or null if no module 
215
+         * have this class, return the full path of the class
216
+         */
217
+        protected static function findClassInModuleFullFilePath($class, $module, $type){
218
+            $logger = self::getLogger();
219
+            $class = str_ireplace('.php', '', $class);
220
+            $class = ucfirst($class);
221
+            $classFile = $class.'.php';
222
+            $logger->debug('Checking the class [' . $class . '] in module [' . $module . '] for [' . $type . '] ...');
223
+            $filePath = MODULE_PATH . $module . DS . $type . DS . $classFile;
224
+            if (file_exists($filePath)){
225
+                $logger->info('Found class [' . $class . '] in module [' . $module . '] for [' . $type . '] the file path is [' .$filePath. ']');
226
+                return $filePath;
227
+            }
228
+            $logger->info('Class [' . $class . '] does not exist in the module [' .$module. '] for [' . $type . ']');
229
+            return false;
230
+        }
231 231
 
232
-		/**
233
-		 * Check if in module list can have the config, view, helper, language
234
-		 * @param string $name the name of config, view, helper, language
235
-		 * @param string $module the module name
236
-		 * @param string $type the name of the type "config", "functions", "views", "lang"
237
-		 * @param string|null $appLang the application language. This is use only when $type = "lang"
238
-		 * @return boolean|string  false or null if no module 
239
-		 * have this resource, return the full path of the resource
240
-		 */
241
-		protected static function findNonClassInModuleFullFilePath($name, $module, $type, $appLang = null){
242
-		    $logger = self::getLogger();
243
-		    $name = str_ireplace('.php', '', $name);
244
-		    $file = $name.'.php';
245
-		    $filePath = MODULE_PATH . $module . DS . $type . DS . $file;
246
-		    switch($type){
247
-		        case 'functions':
248
-		            $name = str_ireplace('function_', '', $name);
249
-		            $file = 'function_'.$name.'.php';
250
-		            $filePath = MODULE_PATH . $module . DS . $type . DS . $file;
251
-		        break;
252
-		        case 'views':
253
-		            $name = trim($name, '/\\');
254
-		            $name = str_ireplace('/', DS, $name);
255
-		            $file = $name . '.php';
256
-		            $filePath = MODULE_PATH . $module . DS . $type . DS . $file;
257
-		        break;
258
-		        case 'lang':
259
-		            $name = str_ireplace('lang_', '', $name);
260
-		            $file = 'lang_'.$name.'.php';
261
-		            $filePath = MODULE_PATH . $module . DS . $type . DS . $appLang . DS . $file;
262
-		        break;
263
-		    }
264
-		    $logger->debug('Checking resource [' . $name . '] in module [' .$module. '] for [' . $type . '] ...');
265
-		    if (file_exists($filePath)){
266
-		        $logger->info('Found resource [' . $name . '] in module [' .$module. '] for [' . $type . '] the file path is [' .$filePath. ']');
267
-		        return $filePath;
268
-		    }
269
-		    $logger->info('Resource [' . $name . '] does not exist in the module [' .$module. '] for [' . $type . ']');
270
-		    return false;
271
-		}
232
+        /**
233
+         * Check if in module list can have the config, view, helper, language
234
+         * @param string $name the name of config, view, helper, language
235
+         * @param string $module the module name
236
+         * @param string $type the name of the type "config", "functions", "views", "lang"
237
+         * @param string|null $appLang the application language. This is use only when $type = "lang"
238
+         * @return boolean|string  false or null if no module 
239
+         * have this resource, return the full path of the resource
240
+         */
241
+        protected static function findNonClassInModuleFullFilePath($name, $module, $type, $appLang = null){
242
+            $logger = self::getLogger();
243
+            $name = str_ireplace('.php', '', $name);
244
+            $file = $name.'.php';
245
+            $filePath = MODULE_PATH . $module . DS . $type . DS . $file;
246
+            switch($type){
247
+                case 'functions':
248
+                    $name = str_ireplace('function_', '', $name);
249
+                    $file = 'function_'.$name.'.php';
250
+                    $filePath = MODULE_PATH . $module . DS . $type . DS . $file;
251
+                break;
252
+                case 'views':
253
+                    $name = trim($name, '/\\');
254
+                    $name = str_ireplace('/', DS, $name);
255
+                    $file = $name . '.php';
256
+                    $filePath = MODULE_PATH . $module . DS . $type . DS . $file;
257
+                break;
258
+                case 'lang':
259
+                    $name = str_ireplace('lang_', '', $name);
260
+                    $file = 'lang_'.$name.'.php';
261
+                    $filePath = MODULE_PATH . $module . DS . $type . DS . $appLang . DS . $file;
262
+                break;
263
+            }
264
+            $logger->debug('Checking resource [' . $name . '] in module [' .$module. '] for [' . $type . '] ...');
265
+            if (file_exists($filePath)){
266
+                $logger->info('Found resource [' . $name . '] in module [' .$module. '] for [' . $type . '] the file path is [' .$filePath. ']');
267
+                return $filePath;
268
+            }
269
+            $logger->info('Resource [' . $name . '] does not exist in the module [' .$module. '] for [' . $type . ']');
270
+            return false;
271
+        }
272 272
 
273
-	}
273
+    }
Please login to merge, or discard this patch.
core/classes/Config.php 1 patch
Indentation   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -1,160 +1,160 @@
 block discarded – undo
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 Config extends BaseStaticClass{
27
+    class Config extends BaseStaticClass{
28 28
 		
29
-		/**
30
-		 * The list of loaded configuration
31
-		 * @var array
32
-		 */
33
-		private static $config = array();
29
+        /**
30
+         * The list of loaded configuration
31
+         * @var array
32
+         */
33
+        private static $config = array();
34 34
 
35
-		/**
36
-		 * Initialize the configuration by loading all the configuration from config file
37
-		 */
38
-		public static function init(){
39
-			$logger = self::getLogger();
40
-			$logger->debug('Initialization of the configuration');
41
-			self::$config = & load_configurations();
42
-			self::setBaseUrlUsingServerVar();
43
-			if(ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info','all'))){
44
-				$logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance');
45
-			}
46
-			$logger->info('Configuration initialized successfully');
47
-			$logger->info('The application configuration are listed below: ' . stringfy_vars(self::$config));
48
-		}
35
+        /**
36
+         * Initialize the configuration by loading all the configuration from config file
37
+         */
38
+        public static function init(){
39
+            $logger = self::getLogger();
40
+            $logger->debug('Initialization of the configuration');
41
+            self::$config = & load_configurations();
42
+            self::setBaseUrlUsingServerVar();
43
+            if(ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info','all'))){
44
+                $logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance');
45
+            }
46
+            $logger->info('Configuration initialized successfully');
47
+            $logger->info('The application configuration are listed below: ' . stringfy_vars(self::$config));
48
+        }
49 49
 
50
-		/**
51
-		 * Get the configuration item value
52
-		 * @param  string $item    the configuration item name to get
53
-		 * @param  mixed $default the default value to use if can not find the config item in the list
54
-		 * @return mixed          the config value if exist or the default value
55
-		 */
56
-		public static function get($item, $default = null){
57
-			$logger = self::getLogger();
58
-			if(array_key_exists($item, self::$config)){
59
-				return self::$config[$item];
60
-			}
61
-			$logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']');
62
-			return $default;
63
-		}
50
+        /**
51
+         * Get the configuration item value
52
+         * @param  string $item    the configuration item name to get
53
+         * @param  mixed $default the default value to use if can not find the config item in the list
54
+         * @return mixed          the config value if exist or the default value
55
+         */
56
+        public static function get($item, $default = null){
57
+            $logger = self::getLogger();
58
+            if(array_key_exists($item, self::$config)){
59
+                return self::$config[$item];
60
+            }
61
+            $logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']');
62
+            return $default;
63
+        }
64 64
 
65
-		/**
66
-		 * Set the configuration item value
67
-		 * @param string $item  the config item name to set
68
-		 * @param mixed $value the config item value
69
-		 */
70
-		public static function set($item, $value){
71
-			self::$config[$item] = $value;
72
-		}
65
+        /**
66
+         * Set the configuration item value
67
+         * @param string $item  the config item name to set
68
+         * @param mixed $value the config item value
69
+         */
70
+        public static function set($item, $value){
71
+            self::$config[$item] = $value;
72
+        }
73 73
 
74
-		/**
75
-		 * Get all the configuration values
76
-		 * @return array the config values
77
-		 */
78
-		public static function getAll(){
79
-			return self::$config;
80
-		}
74
+        /**
75
+         * Get all the configuration values
76
+         * @return array the config values
77
+         */
78
+        public static function getAll(){
79
+            return self::$config;
80
+        }
81 81
 
82
-		/**
83
-		 * Set the configuration values bu merged with the existing configuration
84
-		 * @param array $config the config values to add in the configuration list
85
-		 */
86
-		public static function setAll(array $config = array()){
87
-			self::$config = array_merge(self::$config, $config);
88
-		}
82
+        /**
83
+         * Set the configuration values bu merged with the existing configuration
84
+         * @param array $config the config values to add in the configuration list
85
+         */
86
+        public static function setAll(array $config = array()){
87
+            self::$config = array_merge(self::$config, $config);
88
+        }
89 89
 
90
-		/**
91
-		 * Delete the configuration item in the list
92
-		 * @param  string $item the config item name to be deleted
93
-		 * @return boolean true if the item exists and is deleted successfully otherwise will return false.
94
-		 */
95
-		public static function delete($item){
96
-			$logger = self::getLogger();
97
-			if(array_key_exists($item, self::$config)){
98
-				$logger->info('Delete config item ['.$item.']');
99
-				unset(self::$config[$item]);
100
-				return true;
101
-			}
102
-			else{
103
-				$logger->warning('Config item ['.$item.'] to be deleted does not exists');
104
-				return false;
105
-			}
106
-		}
90
+        /**
91
+         * Delete the configuration item in the list
92
+         * @param  string $item the config item name to be deleted
93
+         * @return boolean true if the item exists and is deleted successfully otherwise will return false.
94
+         */
95
+        public static function delete($item){
96
+            $logger = self::getLogger();
97
+            if(array_key_exists($item, self::$config)){
98
+                $logger->info('Delete config item ['.$item.']');
99
+                unset(self::$config[$item]);
100
+                return true;
101
+            }
102
+            else{
103
+                $logger->warning('Config item ['.$item.'] to be deleted does not exists');
104
+                return false;
105
+            }
106
+        }
107 107
 
108
-		/**
109
-		 * Load the configuration file. This an alias to Loader::config()
110
-		 * @param  string $config the config name to be loaded
111
-		 */
112
-		public static function load($config){
113
-			Loader::config($config);
114
-		}
108
+        /**
109
+         * Load the configuration file. This an alias to Loader::config()
110
+         * @param  string $config the config name to be loaded
111
+         */
112
+        public static function load($config){
113
+            Loader::config($config);
114
+        }
115 115
 
116
-		/**
117
-		 * Set the configuration for "base_url" if is not set in the configuration
118
-		 */
119
-		private static function setBaseUrlUsingServerVar(){
120
-			$logger = self::getLogger();
121
-			if (! isset(self::$config['base_url']) || ! is_url(self::$config['base_url'])){
122
-				if(ENVIRONMENT == 'production'){
123
-					$logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time');
124
-				}
125
-				$baseUrl = null;
126
-				$protocol = 'http';
127
-				if(is_https()){
128
-					$protocol = 'https';
129
-				}
130
-				$protocol .='://';
116
+        /**
117
+         * Set the configuration for "base_url" if is not set in the configuration
118
+         */
119
+        private static function setBaseUrlUsingServerVar(){
120
+            $logger = self::getLogger();
121
+            if (! isset(self::$config['base_url']) || ! is_url(self::$config['base_url'])){
122
+                if(ENVIRONMENT == 'production'){
123
+                    $logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time');
124
+                }
125
+                $baseUrl = null;
126
+                $protocol = 'http';
127
+                if(is_https()){
128
+                    $protocol = 'https';
129
+                }
130
+                $protocol .='://';
131 131
 
132
-				if (isset($_SERVER['SERVER_ADDR'])){
133
-					$baseUrl = $_SERVER['SERVER_ADDR'];
134
-					//check if the server is running under IPv6
135
-					if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){
136
-						$baseUrl = '['.$_SERVER['SERVER_ADDR'].']';
137
-					}
138
-					$serverPort = 80;
139
-					if (isset($_SERVER['SERVER_PORT'])) {
140
-						$serverPort = $_SERVER['SERVER_PORT'];
141
-					}
142
-					$port = '';
143
-					if($serverPort && ((is_https() && $serverPort != 443) || (!is_https() && $serverPort != 80))){
144
-						$port = ':'.$serverPort;
145
-					}
146
-					$baseUrl = $protocol . $baseUrl . $port . substr(
147
-																		$_SERVER['SCRIPT_NAME'], 
148
-																		0, 
149
-																		strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME']))
150
-																	);
151
-				}
152
-				else{
153
-					$logger->warning('Can not determine the application base URL automatically, use http://localhost as default');
154
-					$baseUrl = 'http://localhost/';
155
-				}
156
-				self::set('base_url', $baseUrl);
157
-			}
158
-			self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/';
159
-		}
160
-	}
132
+                if (isset($_SERVER['SERVER_ADDR'])){
133
+                    $baseUrl = $_SERVER['SERVER_ADDR'];
134
+                    //check if the server is running under IPv6
135
+                    if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){
136
+                        $baseUrl = '['.$_SERVER['SERVER_ADDR'].']';
137
+                    }
138
+                    $serverPort = 80;
139
+                    if (isset($_SERVER['SERVER_PORT'])) {
140
+                        $serverPort = $_SERVER['SERVER_PORT'];
141
+                    }
142
+                    $port = '';
143
+                    if($serverPort && ((is_https() && $serverPort != 443) || (!is_https() && $serverPort != 80))){
144
+                        $port = ':'.$serverPort;
145
+                    }
146
+                    $baseUrl = $protocol . $baseUrl . $port . substr(
147
+                                                                        $_SERVER['SCRIPT_NAME'], 
148
+                                                                        0, 
149
+                                                                        strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME']))
150
+                                                                    );
151
+                }
152
+                else{
153
+                    $logger->warning('Can not determine the application base URL automatically, use http://localhost as default');
154
+                    $baseUrl = 'http://localhost/';
155
+                }
156
+                self::set('base_url', $baseUrl);
157
+            }
158
+            self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/';
159
+        }
160
+    }
Please login to merge, or discard this patch.