Test Failed
Push — 1.0.0-dev ( c7a39c...6c2ad2 )
by nguereza
03:29
created
core/classes/cache/ApcCache.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  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
 	class ApcCache implements CacheInterface{
28 28
 
@@ -39,15 +39,15 @@  discard block
 block discarded – undo
39 39
 			}
40 40
 
41 41
 			/**
42
-	         * instance of the Log class
43
-	         */
44
-	        if(is_object($logger)){
45
-	          $this->logger = $logger;
46
-	        }
47
-	        else{
48
-	            $this->logger =& class_loader('Log', 'classes');
49
-	            $this->logger->setLogger('Library::ApcCache');
50
-	        }
42
+			 * instance of the Log class
43
+			 */
44
+			if(is_object($logger)){
45
+			  $this->logger = $logger;
46
+			}
47
+			else{
48
+				$this->logger =& class_loader('Log', 'classes');
49
+				$this->logger->setLogger('Library::ApcCache');
50
+			}
51 51
 		}
52 52
 
53 53
 		/**
@@ -87,13 +87,13 @@  discard block
 block discarded – undo
87 87
 			$this->logger->debug('Setting cache data for key ['. $key .'], time to live [' .$ttl. '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
88 88
 			$result = apc_store($key, $data, $ttl);
89 89
 			if($result === false){
90
-		    	$this->logger->error('Can not write cache data for the key ['. $key .'], return false');
91
-		    	return false;
92
-		    }
93
-		    else{
94
-		    	$this->logger->info('Cache data saved for the key ['. $key .']');
95
-		    	return true;
96
-		    }
90
+				$this->logger->error('Can not write cache data for the key ['. $key .'], return false');
91
+				return false;
92
+			}
93
+			else{
94
+				$this->logger->info('Cache data saved for the key ['. $key .']');
95
+				return true;
96
+			}
97 97
 		}
98 98
 
99 99
 
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 			}
113 113
 			else{
114 114
 				$this->logger->info('Found cache data for the key [' .$key. '] remove it');
115
-	      		return apc_delete($key) === true;
115
+		  		return apc_delete($key) === true;
116 116
 			}
117 117
 		}
118 118
 		
@@ -177,28 +177,28 @@  discard block
 block discarded – undo
177 177
 		}
178 178
 
179 179
 		/**
180
-	     * Return the Log instance
181
-	     * @return Log
182
-	     */
183
-	    public function getLogger(){
184
-	      return $this->logger;
185
-	    }
180
+		 * Return the Log instance
181
+		 * @return Log
182
+		 */
183
+		public function getLogger(){
184
+		  return $this->logger;
185
+		}
186 186
 
187
-	    /**
188
-	     * Set the log instance
189
-	     * @param Log $logger the log object
190
-	     */
191
-	    public function setLogger(Log $logger){
192
-	      $this->logger = $logger;
193
-	      return $this;
194
-	    }
187
+		/**
188
+		 * Set the log instance
189
+		 * @param Log $logger the log object
190
+		 */
191
+		public function setLogger(Log $logger){
192
+		  $this->logger = $logger;
193
+		  return $this;
194
+		}
195 195
 		
196 196
 		/**
197
-		* Return the array of cache information
198
-		*
199
-		* @param string $key the cache key to get the cache information 
200
-		* @return boolean|array
201
-		*/
197
+		 * Return the array of cache information
198
+		 *
199
+		 * @param string $key the cache key to get the cache information 
200
+		 * @return boolean|array
201
+		 */
202 202
 		private function _getCacheInfo($key){
203 203
 			$caches = apc_cache_info('user');
204 204
 			if(! empty($caches['cache_list'])){
Please login to merge, or discard this patch.
core/classes/cache/FileCache.php 1 patch
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  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
 	class FileCache implements CacheInterface{
28 28
 		
@@ -44,15 +44,15 @@  discard block
 block discarded – undo
44 44
 				show_error('The cache for file system is not available. Check the cache directory if is exists or is writable.');
45 45
 			}
46 46
 			/**
47
-	         * instance of the Log class
48
-	         */
49
-	        if(is_object($logger)){
50
-	          $this->logger = $logger;
51
-	        }
52
-	        else{
53
-	            $this->logger =& class_loader('Log', 'classes');
54
-	            $this->logger->setLogger('Library::FileCache');
55
-	        }
47
+			 * instance of the Log class
48
+			 */
49
+			if(is_object($logger)){
50
+			  $this->logger = $logger;
51
+			}
52
+			else{
53
+				$this->logger =& class_loader('Log', 'classes');
54
+				$this->logger->setLogger('Library::FileCache');
55
+			}
56 56
 			
57 57
 			//if Zlib extension is not loaded set compressCacheData to false
58 58
 			if(! extension_loaded('zlib')){
@@ -80,26 +80,26 @@  discard block
 block discarded – undo
80 80
 				return false;
81 81
 			}
82 82
 			// Getting a shared lock 
83
-		    flock($handle, LOCK_SH);
84
-		    $data = file_get_contents($filePath);
85
-      		fclose($handle);
86
-      		$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
87
-      		if (! $data) {
88
-      			$this->logger->error('Can not unserialize the cache data for the key ['. $key .'], return false');
89
-		         // If unserializing somehow didn't work out, we'll delete the file
90
-		         unlink($filePath);
91
-		         return false;
92
-	      	}
93
-	      	if (time() > $data['expire']) {
94
-	      		$this->logger->info('The cache data for the key ['. $key .'] already expired delete the cache file [' .$filePath. ']');
95
-		        // Unlinking when the file was expired
96
-		        unlink($filePath);
97
-		        return false;
98
-		     }
99
-		     else{
100
-		     	$this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']');
101
-		     	return $data['data'];
102
-		     }
83
+			flock($handle, LOCK_SH);
84
+			$data = file_get_contents($filePath);
85
+	  		fclose($handle);
86
+	  		$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
87
+	  		if (! $data) {
88
+	  			$this->logger->error('Can not unserialize the cache data for the key ['. $key .'], return false');
89
+				 // If unserializing somehow didn't work out, we'll delete the file
90
+				 unlink($filePath);
91
+				 return false;
92
+		  	}
93
+		  	if (time() > $data['expire']) {
94
+		  		$this->logger->info('The cache data for the key ['. $key .'] already expired delete the cache file [' .$filePath. ']');
95
+				// Unlinking when the file was expired
96
+				unlink($filePath);
97
+				return false;
98
+			 }
99
+			 else{
100
+			 	$this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']');
101
+			 	return $data['data'];
102
+			 }
103 103
 		}
104 104
 
105 105
 
@@ -121,25 +121,25 @@  discard block
 block discarded – undo
121 121
 			}
122 122
 			flock($handle, LOCK_EX); // exclusive lock, will get released when the file is closed
123 123
 			//Serializing along with the TTL
124
-		    $cacheData = serialize(array(
124
+			$cacheData = serialize(array(
125 125
 									'mtime' => time(),
126 126
 									'expire' => $expire,
127 127
 									'data' => $data,
128 128
 									'ttl' => $ttl
129 129
 									)
130 130
 								);		   
131
-		    $result = fwrite($handle, $this->compressCacheData ? gzdeflate($cacheData, 9) : $cacheData);
132
-		    if(! $result){
133
-		    	$this->logger->error('Can not write cache data into file [' .$filePath. '] for the key ['. $key .'], return false');
134
-		    	fclose($handle);
135
-		    	return false;
136
-		    }
137
-		    else{
138
-		    	$this->logger->info('Cache data saved into file [' .$filePath. '] for the key ['. $key .']');
139
-		    	fclose($handle);
131
+			$result = fwrite($handle, $this->compressCacheData ? gzdeflate($cacheData, 9) : $cacheData);
132
+			if(! $result){
133
+				$this->logger->error('Can not write cache data into file [' .$filePath. '] for the key ['. $key .'], return false');
134
+				fclose($handle);
135
+				return false;
136
+			}
137
+			else{
138
+				$this->logger->info('Cache data saved into file [' .$filePath. '] for the key ['. $key .']');
139
+				fclose($handle);
140 140
 				chmod($filePath, 0640);
141 141
 				return true;
142
-		    }
142
+			}
143 143
 		}	
144 144
 
145 145
 
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 			}
160 160
 			else{
161 161
 				$this->logger->info('Found cache file [' .$filePath. '] remove it');
162
-	      		unlink($filePath);
162
+		  		unlink($filePath);
163 163
 				return true;
164 164
 			}
165 165
 		}
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 			}
183 183
 			else{
184 184
 				$this->logger->info('Found cache file [' .$filePath. '] check the validity');
185
-	      		$data = file_get_contents($filePath);
185
+		  		$data = file_get_contents($filePath);
186 186
 				$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
187 187
 				if(! $data){
188 188
 					$this->logger->warning('Can not unserialize the cache data for file [' . $filePath . ']');
@@ -222,17 +222,17 @@  discard block
 block discarded – undo
222 222
 				foreach ($list as $file) {
223 223
 					$this->logger->debug('Processing the cache file [' . $file . ']');
224 224
 					$data = file_get_contents($file);
225
-		      		$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
226
-		      		if(! $data){
227
-		      			$this->logger->warning('Can not unserialize the cache data for file [' . $file . ']');
228
-		      		}
229
-		      		else if(time() > $data['expire']){
230
-		      			$this->logger->info('The cache data for file [' . $file . '] already expired remove it');
231
-		      			unlink($file);
232
-		      		}
233
-		      		else{
234
-		      			$this->logger->info('The cache data for file [' . $file . '] not yet expired skip it');
235
-		      		}
225
+			  		$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
226
+			  		if(! $data){
227
+			  			$this->logger->warning('Can not unserialize the cache data for file [' . $file . ']');
228
+			  		}
229
+			  		else if(time() > $data['expire']){
230
+			  			$this->logger->info('The cache data for file [' . $file . '] already expired remove it');
231
+			  			unlink($file);
232
+			  		}
233
+			  		else{
234
+			  			$this->logger->info('The cache data for file [' . $file . '] not yet expired skip it');
235
+			  		}
236 236
 				}
237 237
 			}
238 238
 		}	
@@ -255,19 +255,19 @@  discard block
 block discarded – undo
255 255
 			}
256 256
 		}
257 257
 	
258
-	    /**
259
-	     * @return boolean
260
-	     */
261
-	    public function isCompressCacheData(){
262
-	        return $this->compressCacheData;
263
-	    }
258
+		/**
259
+		 * @return boolean
260
+		 */
261
+		public function isCompressCacheData(){
262
+			return $this->compressCacheData;
263
+		}
264 264
 
265
-	    /**
266
-	     * @param boolean $compressCacheData
267
-	     *
268
-	     * @return self
269
-	     */
270
-	    public function setCompressCacheData($status = true){
265
+		/**
266
+		 * @param boolean $compressCacheData
267
+		 *
268
+		 * @return self
269
+		 */
270
+		public function setCompressCacheData($status = true){
271 271
 			//if Zlib extension is not loaded set compressCacheData to false
272 272
 			if($status === true && ! extension_loaded('zlib')){
273 273
 				
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
 				$this->compressCacheData = $status;
279 279
 			}
280 280
 			return $this;
281
-	    }
281
+		}
282 282
 		
283 283
 		/**
284 284
 		 * Check whether the cache feature for the handle is supported
@@ -290,28 +290,28 @@  discard block
 block discarded – undo
290 290
 		}
291 291
 
292 292
 		/**
293
-	     * Return the Log instance
294
-	     * @return Log
295
-	     */
296
-	    public function getLogger(){
297
-	      return $this->logger;
298
-	    }
293
+		 * Return the Log instance
294
+		 * @return Log
295
+		 */
296
+		public function getLogger(){
297
+		  return $this->logger;
298
+		}
299 299
 
300
-	    /**
301
-	     * Set the log instance
302
-	     * @param Log $logger the log object
303
-	     */
304
-	    public function setLogger(Log $logger){
305
-	      $this->logger = $logger;
306
-	      return $this;
307
-	    }
300
+		/**
301
+		 * Set the log instance
302
+		 * @param Log $logger the log object
303
+		 */
304
+		public function setLogger(Log $logger){
305
+		  $this->logger = $logger;
306
+		  return $this;
307
+		}
308 308
 		
309 309
 		/**
310
-		* Get the cache file full path for the given key
311
-		*
312
-		* @param $key the cache item key
313
-		* @return string the full cache file path for this key
314
-		*/
310
+		 * Get the cache file full path for the given key
311
+		 *
312
+		 * @param $key the cache item key
313
+		 * @return string the full cache file path for this key
314
+		 */
315 315
 		private function getFilePath($key){
316 316
 			return CACHE_PATH . md5($key) . '.cache';
317 317
 		}
Please login to merge, or discard this patch.
core/libraries/Browser.php 1 patch
Indentation   +1731 added lines, -1731 removed lines patch added patch discarded remove patch
@@ -1,1732 +1,1732 @@
 block discarded – undo
1 1
 <?php
2
-    defined('ROOT_PATH') || exit('Access denied');
3
-    /**
4
-     * File: Browser.php
5
-     * Author: Chris Schuld (http://chrisschuld.com/)
6
-     * Last Modified: July 22nd, 2016
7
-     * @version 2.0
8
-     * @package PegasusPHP
9
-     *
10
-     * Copyright (C) 2008-2010 Chris Schuld  ([email protected])
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 as
14
-     * published by the Free Software Foundation; either version 2 of
15
-     * 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 at:
21
-     * http://www.gnu.org/copyleft/gpl.html
22
-     *
23
-     *
24
-     * Typical Usage:
25
-     *
26
-     *   $browser = new Browser();
27
-     *   if( $browser->getBrowser() == Browser::BROWSER_FIREFOX && $browser->getVersion() >= 2 ) {
28
-     *    echo 'You have FireFox version 2 or greater';
29
-     *   }
30
-     *
31
-     * User Agents Sampled from: http://www.useragentstring.com/
32
-     *
33
-     * This implementation is based on the original work from Gary White
34
-     * http://apptools.com/phptools/browser/
35
-     *
36
-     */
37
-    class Browser
38
-    {
39
-        private $_agent = '';
40
-        private $_browser_name = '';
41
-        private $_version = '';
42
-        private $_platform = '';
43
-        private $_os = '';
44
-        private $_is_aol = false;
45
-        private $_is_mobile = false;
46
-        private $_is_tablet = false;
47
-        private $_is_robot = false;
48
-        private $_is_facebook = false;
49
-        private $_aol_version = '';
50
-
51
-        const BROWSER_UNKNOWN = 'unknown';
52
-        const VERSION_UNKNOWN = 'unknown';
53
-
54
-        const BROWSER_OPERA = 'Opera'; // http://www.opera.com/
55
-        const BROWSER_OPERA_MINI = 'Opera Mini'; // http://www.opera.com/mini/
56
-        const BROWSER_WEBTV = 'WebTV'; // http://www.webtv.net/pc/
57
-        const BROWSER_EDGE = 'Edge'; // https://www.microsoft.com/edge
58
-        const BROWSER_IE = 'Internet Explorer'; // http://www.microsoft.com/ie/
59
-        const BROWSER_POCKET_IE = 'Pocket Internet Explorer'; // http://en.wikipedia.org/wiki/Internet_Explorer_Mobile
60
-        const BROWSER_KONQUEROR = 'Konqueror'; // http://www.konqueror.org/
61
-        const BROWSER_ICAB = 'iCab'; // http://www.icab.de/
62
-        const BROWSER_OMNIWEB = 'OmniWeb'; // http://www.omnigroup.com/applications/omniweb/
63
-        const BROWSER_FIREBIRD = 'Firebird'; // http://www.ibphoenix.com/
64
-        const BROWSER_FIREFOX = 'Firefox'; // http://www.mozilla.com/en-US/firefox/firefox.html
65
-        const BROWSER_ICEWEASEL = 'Iceweasel'; // http://www.geticeweasel.org/
66
-        const BROWSER_SHIRETOKO = 'Shiretoko'; // http://wiki.mozilla.org/Projects/shiretoko
67
-        const BROWSER_MOZILLA = 'Mozilla'; // http://www.mozilla.com/en-US/
68
-        const BROWSER_AMAYA = 'Amaya'; // http://www.w3.org/Amaya/
69
-        const BROWSER_LYNX = 'Lynx'; // http://en.wikipedia.org/wiki/Lynx
70
-        const BROWSER_SAFARI = 'Safari'; // http://apple.com
71
-        const BROWSER_IPHONE = 'iPhone'; // http://apple.com
72
-        const BROWSER_IPOD = 'iPod'; // http://apple.com
73
-        const BROWSER_IPAD = 'iPad'; // http://apple.com
74
-        const BROWSER_CHROME = 'Chrome'; // http://www.google.com/chrome
75
-        const BROWSER_ANDROID = 'Android'; // http://www.android.com/
76
-        const BROWSER_GOOGLEBOT = 'GoogleBot'; // http://en.wikipedia.org/wiki/Googlebot
77
-
78
-        const BROWSER_YANDEXBOT = 'YandexBot'; // http://yandex.com/bots
79
-        const BROWSER_YANDEXIMAGERESIZER_BOT = 'YandexImageResizer'; // http://yandex.com/bots
80
-        const BROWSER_YANDEXIMAGES_BOT = 'YandexImages'; // http://yandex.com/bots
81
-        const BROWSER_YANDEXVIDEO_BOT = 'YandexVideo'; // http://yandex.com/bots
82
-        const BROWSER_YANDEXMEDIA_BOT = 'YandexMedia'; // http://yandex.com/bots
83
-        const BROWSER_YANDEXBLOGS_BOT = 'YandexBlogs'; // http://yandex.com/bots
84
-        const BROWSER_YANDEXFAVICONS_BOT = 'YandexFavicons'; // http://yandex.com/bots
85
-        const BROWSER_YANDEXWEBMASTER_BOT = 'YandexWebmaster'; // http://yandex.com/bots
86
-        const BROWSER_YANDEXDIRECT_BOT = 'YandexDirect'; // http://yandex.com/bots
87
-        const BROWSER_YANDEXMETRIKA_BOT = 'YandexMetrika'; // http://yandex.com/bots
88
-        const BROWSER_YANDEXNEWS_BOT = 'YandexNews'; // http://yandex.com/bots
89
-        const BROWSER_YANDEXCATALOG_BOT = 'YandexCatalog'; // http://yandex.com/bots
90
-
91
-        const BROWSER_SLURP = 'Yahoo! Slurp'; // http://en.wikipedia.org/wiki/Yahoo!_Slurp
92
-        const BROWSER_W3CVALIDATOR = 'W3C Validator'; // http://validator.w3.org/
93
-        const BROWSER_BLACKBERRY = 'BlackBerry'; // http://www.blackberry.com/
94
-        const BROWSER_ICECAT = 'IceCat'; // http://en.wikipedia.org/wiki/GNU_IceCat
95
-        const BROWSER_NOKIA_S60 = 'Nokia S60 OSS Browser'; // http://en.wikipedia.org/wiki/Web_Browser_for_S60
96
-        const BROWSER_NOKIA = 'Nokia Browser'; // * all other WAP-based browsers on the Nokia Platform
97
-        const BROWSER_MSN = 'MSN Browser'; // http://explorer.msn.com/
98
-        const BROWSER_MSNBOT = 'MSN Bot'; // http://search.msn.com/msnbot.htm
99
-        const BROWSER_BINGBOT = 'Bing Bot'; // http://en.wikipedia.org/wiki/Bingbot
100
-        const BROWSER_VIVALDI = 'Vivalidi'; // https://vivaldi.com/
101
-        const BROWSER_YANDEX = 'Yandex'; // https://browser.yandex.ua/
102
-
103
-        const BROWSER_NETSCAPE_NAVIGATOR = 'Netscape Navigator'; // http://browser.netscape.com/ (DEPRECATED)
104
-        const BROWSER_GALEON = 'Galeon'; // http://galeon.sourceforge.net/ (DEPRECATED)
105
-        const BROWSER_NETPOSITIVE = 'NetPositive'; // http://en.wikipedia.org/wiki/NetPositive (DEPRECATED)
106
-        const BROWSER_PHOENIX = 'Phoenix'; // http://en.wikipedia.org/wiki/History_of_Mozilla_Firefox (DEPRECATED)
107
-        const BROWSER_PLAYSTATION = "PlayStation";
108
-        const BROWSER_SAMSUNG = "SamsungBrowser";
109
-        const BROWSER_SILK = "Silk";
110
-        const BROWSER_I_FRAME = "Iframely";
111
-        const BROWSER_COCOA = "CocoaRestClient";
112
-
113
-        const PLATFORM_UNKNOWN = 'unknown';
114
-        const PLATFORM_WINDOWS = 'Windows';
115
-        const PLATFORM_WINDOWS_CE = 'Windows CE';
116
-        const PLATFORM_APPLE = 'Apple';
117
-        const PLATFORM_LINUX = 'Linux';
118
-        const PLATFORM_OS2 = 'OS/2';
119
-        const PLATFORM_BEOS = 'BeOS';
120
-        const PLATFORM_IPHONE = 'iPhone';
121
-        const PLATFORM_IPOD = 'iPod';
122
-        const PLATFORM_IPAD = 'iPad';
123
-        const PLATFORM_BLACKBERRY = 'BlackBerry';
124
-        const PLATFORM_NOKIA = 'Nokia';
125
-        const PLATFORM_FREEBSD = 'FreeBSD';
126
-        const PLATFORM_OPENBSD = 'OpenBSD';
127
-        const PLATFORM_NETBSD = 'NetBSD';
128
-        const PLATFORM_SUNOS = 'SunOS';
129
-        const PLATFORM_OPENSOLARIS = 'OpenSolaris';
130
-        const PLATFORM_ANDROID = 'Android';
131
-        const PLATFORM_PLAYSTATION = "Sony PlayStation";
132
-        const PLATFORM_ROKU = "Roku";
133
-        const PLATFORM_APPLE_TV = "Apple TV";
134
-        const PLATFORM_TERMINAL = "Terminal";
135
-        const PLATFORM_FIRE_OS = "Fire OS";
136
-        const PLATFORM_SMART_TV = "SMART-TV";
137
-        const PLATFORM_CHROME_OS = "Chrome OS";
138
-        const PLATFORM_JAVA_ANDROID = "Java/Android";
139
-        const PLATFORM_POSTMAN = "Postman";
140
-        const PLATFORM_I_FRAME = "Iframely";
141
-
142
-        const OPERATING_SYSTEM_UNKNOWN = 'unknown';
143
-
144
-        /**
145
-         * Class constructor
146
-         */
147
-        public function __construct($userAgent = "")
148
-        {
149
-            $this->reset();
150
-            if ($userAgent != "") {
151
-                $this->setUserAgent($userAgent);
152
-            } else {
153
-                $this->determine();
154
-            }
155
-        }
156
-
157
-        /**
158
-         * Reset all properties
159
-         */
160
-        public function reset()
161
-        {
162
-            $this->_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : "";
163
-            $this->_browser_name = self::BROWSER_UNKNOWN;
164
-            $this->_version = self::VERSION_UNKNOWN;
165
-            $this->_platform = self::PLATFORM_UNKNOWN;
166
-            $this->_os = self::OPERATING_SYSTEM_UNKNOWN;
167
-            $this->_is_aol = false;
168
-            $this->_is_mobile = false;
169
-            $this->_is_tablet = false;
170
-            $this->_is_robot = false;
171
-            $this->_is_facebook = false;
172
-            $this->_aol_version = self::VERSION_UNKNOWN;
173
-        }
174
-
175
-        /**
176
-         * Check to see if the specific browser is valid
177
-         * @param string $browserName
178
-         * @return bool True if the browser is the specified browser
179
-         */
180
-        public function isBrowser($browserName)
181
-        {
182
-            return (0 == strcasecmp($this->_browser_name, trim($browserName)));
183
-        }
184
-
185
-        /**
186
-         * The name of the browser.  All return types are from the class contants
187
-         * @return string Name of the browser
188
-         */
189
-        public function getBrowser()
190
-        {
191
-            return $this->_browser_name;
192
-        }
193
-
194
-        /**
195
-         * Set the name of the browser
196
-         * @param $browser string The name of the Browser
197
-         */
198
-        public function setBrowser($browser)
199
-        {
200
-            $this->_browser_name = $browser;
201
-        }
202
-
203
-        /**
204
-         * The name of the platform.  All return types are from the class contants
205
-         * @return string Name of the browser
206
-         */
207
-        public function getPlatform()
208
-        {
209
-            return $this->_platform;
210
-        }
211
-
212
-        /**
213
-         * Set the name of the platform
214
-         * @param string $platform The name of the Platform
215
-         */
216
-        public function setPlatform($platform)
217
-        {
218
-            $this->_platform = $platform;
219
-        }
220
-
221
-        /**
222
-         * The version of the browser.
223
-         * @return string Version of the browser (will only contain alpha-numeric characters and a period)
224
-         */
225
-        public function getVersion()
226
-        {
227
-            return $this->_version;
228
-        }
229
-
230
-        /**
231
-         * Set the version of the browser
232
-         * @param string $version The version of the Browser
233
-         */
234
-        public function setVersion($version)
235
-        {
236
-            $this->_version = preg_replace('/[^0-9,.,a-z,A-Z-]/', '', $version);
237
-        }
238
-
239
-        /**
240
-         * The version of AOL.
241
-         * @return string Version of AOL (will only contain alpha-numeric characters and a period)
242
-         */
243
-        public function getAolVersion()
244
-        {
245
-            return $this->_aol_version;
246
-        }
247
-
248
-        /**
249
-         * Set the version of AOL
250
-         * @param string $version The version of AOL
251
-         */
252
-        public function setAolVersion($version)
253
-        {
254
-            $this->_aol_version = preg_replace('/[^0-9,.,a-z,A-Z]/', '', $version);
255
-        }
256
-
257
-        /**
258
-         * Is the browser from AOL?
259
-         * @return boolean True if the browser is from AOL otherwise false
260
-         */
261
-        public function isAol()
262
-        {
263
-            return $this->_is_aol;
264
-        }
265
-
266
-        /**
267
-         * Is the browser from a mobile device?
268
-         * @return boolean True if the browser is from a mobile device otherwise false
269
-         */
270
-        public function isMobile()
271
-        {
272
-            return $this->_is_mobile;
273
-        }
274
-
275
-        /**
276
-         * Is the browser from a tablet device?
277
-         * @return boolean True if the browser is from a tablet device otherwise false
278
-         */
279
-        public function isTablet()
280
-        {
281
-            return $this->_is_tablet;
282
-        }
283
-
284
-        /**
285
-         * Is the browser from a robot (ex Slurp,GoogleBot)?
286
-         * @return boolean True if the browser is from a robot otherwise false
287
-         */
288
-        public function isRobot()
289
-        {
290
-            return $this->_is_robot;
291
-        }
292
-
293
-        /**
294
-         * Is the browser from facebook?
295
-         * @return boolean True if the browser is from facebook otherwise false
296
-         */
297
-        public function isFacebook()
298
-        {
299
-            return $this->_is_facebook;
300
-        }
301
-
302
-        /**
303
-         * Set the browser to be from AOL
304
-         * @param $isAol
305
-         */
306
-        public function setAol($isAol)
307
-        {
308
-            $this->_is_aol = $isAol;
309
-        }
310
-
311
-        /**
312
-         * Set the Browser to be mobile
313
-         * @param boolean $value is the browser a mobile browser or not
314
-         */
315
-        protected function setMobile($value = true)
316
-        {
317
-            $this->_is_mobile = $value;
318
-        }
319
-
320
-        /**
321
-         * Set the Browser to be tablet
322
-         * @param boolean $value is the browser a tablet browser or not
323
-         */
324
-        protected function setTablet($value = true)
325
-        {
326
-            $this->_is_tablet = $value;
327
-        }
328
-
329
-        /**
330
-         * Set the Browser to be a robot
331
-         * @param boolean $value is the browser a robot or not
332
-         */
333
-        protected function setRobot($value = true)
334
-        {
335
-            $this->_is_robot = $value;
336
-        }
337
-
338
-        /**
339
-         * Set the Browser to be a Facebook request
340
-         * @param boolean $value is the browser a robot or not
341
-         */
342
-        protected function setFacebook($value = true)
343
-        {
344
-            $this->_is_facebook = $value;
345
-        }
346
-
347
-        /**
348
-         * Get the user agent value in use to determine the browser
349
-         * @return string The user agent from the HTTP header
350
-         */
351
-        public function getUserAgent()
352
-        {
353
-            return $this->_agent;
354
-        }
355
-
356
-        /**
357
-         * Set the user agent value (the construction will use the HTTP header value - this will overwrite it)
358
-         * @param string $agent_string The value for the User Agent
359
-         */
360
-        public function setUserAgent($agent_string)
361
-        {
362
-            $this->reset();
363
-            $this->_agent = $agent_string;
364
-            $this->determine();
365
-        }
366
-
367
-        /**
368
-         * Used to determine if the browser is actually "chromeframe"
369
-         * @since 1.7
370
-         * @return boolean True if the browser is using chromeframe
371
-         */
372
-        public function isChromeFrame()
373
-        {
374
-            return (strpos($this->_agent, "chromeframe") !== false);
375
-        }
376
-
377
-        /**
378
-         * Returns a formatted string with a summary of the details of the browser.
379
-         * @return string formatted string with a summary of the browser
380
-         */
381
-        public function __toString()
382
-        {
383
-            return "<strong>Browser Name:</strong> {$this->getBrowser()}<br/>\n" .
384
-                "<strong>Browser Version:</strong> {$this->getVersion()}<br/>\n" .
385
-                "<strong>Browser User Agent String:</strong> {$this->getUserAgent()}<br/>\n" .
386
-                "<strong>Platform:</strong> {$this->getPlatform()}<br/>";
387
-        }
388
-
389
-        /**
390
-         * Protected routine to calculate and determine what the browser is in use (including platform)
391
-         */
392
-        protected function determine()
393
-        {
394
-            $this->checkPlatform();
395
-            $this->checkBrowsers();
396
-            $this->checkForAol();
397
-        }
398
-
399
-        /**
400
-         * Protected routine to determine the browser type
401
-         * @return boolean True if the browser was detected otherwise false
402
-         */
403
-        protected function checkBrowsers()
404
-        {
405
-            return (
406
-                // well-known, well-used
407
-                // Special Notes:
408
-                // (1) Opera must be checked before FireFox due to the odd
409
-                //     user agents used in some older versions of Opera
410
-                // (2) WebTV is strapped onto Internet Explorer so we must
411
-                //     check for WebTV before IE
412
-                // (3) (deprecated) Galeon is based on Firefox and needs to be
413
-                //     tested before Firefox is tested
414
-                // (4) OmniWeb is based on Safari so OmniWeb check must occur
415
-                //     before Safari
416
-                // (5) Netscape 9+ is based on Firefox so Netscape checks
417
-                //     before FireFox are necessary
418
-                // (6) Vivalid is UA contains both Firefox and Chrome so Vivalid checks
419
-                //     before Firefox and Chrome
420
-                $this->checkBrowserWebTv() ||
421
-                $this->checkBrowserEdge() ||
422
-                $this->checkBrowserInternetExplorer() ||
423
-                $this->checkBrowserOpera() ||
424
-                $this->checkBrowserGaleon() ||
425
-                $this->checkBrowserNetscapeNavigator9Plus() ||
426
-                $this->checkBrowserVivaldi() ||
427
-                $this->checkBrowserYandex() ||
428
-                $this->checkBrowserFirefox() ||
429
-                $this->checkBrowserChrome() ||
430
-                $this->checkBrowserOmniWeb() ||
431
-
432
-                // common mobile
433
-                $this->checkBrowserAndroid() ||
434
-                $this->checkBrowseriPad() ||
435
-                $this->checkBrowseriPod() ||
436
-                $this->checkBrowseriPhone() ||
437
-                $this->checkBrowserBlackBerry() ||
438
-                $this->checkBrowserNokia() ||
439
-
440
-                // common bots
441
-                $this->checkBrowserGoogleBot() ||
442
-                $this->checkBrowserMSNBot() ||
443
-                $this->checkBrowserBingBot() ||
444
-                $this->checkBrowserSlurp() ||
445
-
446
-                // Yandex bots
447
-                $this->checkBrowserYandexBot() ||
448
-                $this->checkBrowserYandexImageResizerBot() ||
449
-                $this->checkBrowserYandexBlogsBot() ||
450
-                $this->checkBrowserYandexCatalogBot() ||
451
-                $this->checkBrowserYandexDirectBot() ||
452
-                $this->checkBrowserYandexFaviconsBot() ||
453
-                $this->checkBrowserYandexImagesBot() ||
454
-                $this->checkBrowserYandexMediaBot() ||
455
-                $this->checkBrowserYandexMetrikaBot() ||
456
-                $this->checkBrowserYandexNewsBot() ||
457
-                $this->checkBrowserYandexVideoBot() ||
458
-                $this->checkBrowserYandexWebmasterBot() ||
459
-
460
-                // check for facebook external hit when loading URL
461
-                $this->checkFacebookExternalHit() ||
462
-
463
-                // WebKit base check (post mobile and others)
464
-                $this->checkBrowserSamsung() ||
465
-                $this->checkBrowserSilk() ||
466
-                $this->checkBrowserSafari() ||
467
-
468
-                // everyone else
469
-                $this->checkBrowserNetPositive() ||
470
-                $this->checkBrowserFirebird() ||
471
-                $this->checkBrowserKonqueror() ||
472
-                $this->checkBrowserIcab() ||
473
-                $this->checkBrowserPhoenix() ||
474
-                $this->checkBrowserAmaya() ||
475
-                $this->checkBrowserLynx() ||
476
-                $this->checkBrowserShiretoko() ||
477
-                $this->checkBrowserIceCat() ||
478
-                $this->checkBrowserIceweasel() ||
479
-                $this->checkBrowserW3CValidator() ||
480
-                $this->checkBrowserPlayStation() ||
481
-                $this->checkBrowserIframely() ||
482
-                $this->checkBrowserCocoa() ||
483
-                $this->checkBrowserMozilla() /* Mozilla is such an open standard that you must check it last */
484
-
485
-
486
-            );
487
-        }
488
-
489
-        /**
490
-         * Determine if the user is using a BlackBerry (last updated 1.7)
491
-         * @return boolean True if the browser is the BlackBerry browser otherwise false
492
-         */
493
-        protected function checkBrowserBlackBerry()
494
-        {
495
-            if (stripos($this->_agent, 'blackberry') !== false) {
496
-                $aresult = explode("/", stristr($this->_agent, "BlackBerry"));
497
-                if (isset($aresult[1])) {
498
-                    $aversion = explode(' ', $aresult[1]);
499
-                    $this->setVersion($aversion[0]);
500
-                    $this->_browser_name = self::BROWSER_BLACKBERRY;
501
-                    $this->setMobile(true);
502
-                    return true;
503
-                }
504
-            }
505
-            return false;
506
-        }
507
-
508
-        /**
509
-         * Determine if the user is using an AOL User Agent (last updated 1.7)
510
-         * @return boolean True if the browser is from AOL otherwise false
511
-         */
512
-        protected function checkForAol()
513
-        {
514
-            $this->setAol(false);
515
-            $this->setAolVersion(self::VERSION_UNKNOWN);
516
-
517
-            if (stripos($this->_agent, 'aol') !== false) {
518
-                $aversion = explode(' ', stristr($this->_agent, 'AOL'));
519
-                if (isset($aversion[1])) {
520
-                    $this->setAol(true);
521
-                    $this->setAolVersion(preg_replace('/[^0-9\.a-z]/i', '', $aversion[1]));
522
-                    return true;
523
-                }
524
-            }
525
-            return false;
526
-        }
527
-
528
-        /**
529
-         * Determine if the browser is the GoogleBot or not (last updated 1.7)
530
-         * @return boolean True if the browser is the GoogletBot otherwise false
531
-         */
532
-        protected function checkBrowserGoogleBot()
533
-        {
534
-            if (stripos($this->_agent, 'googlebot') !== false) {
535
-                $aresult = explode('/', stristr($this->_agent, 'googlebot'));
536
-                if (isset($aresult[1])) {
537
-                    $aversion = explode(' ', $aresult[1]);
538
-                    $this->setVersion(str_replace(';', '', $aversion[0]));
539
-                    $this->_browser_name = self::BROWSER_GOOGLEBOT;
540
-                    $this->setRobot(true);
541
-                    return true;
542
-                }
543
-            }
544
-            return false;
545
-        }
546
-
547
-        /**
548
-         * Determine if the browser is the YandexBot or not
549
-         * @return boolean True if the browser is the YandexBot otherwise false
550
-         */
551
-        protected function checkBrowserYandexBot()
552
-        {
553
-            if (stripos($this->_agent, 'YandexBot') !== false) {
554
-                $aresult = explode('/', stristr($this->_agent, 'YandexBot'));
555
-                if (isset($aresult[1])) {
556
-                    $aversion = explode(' ', $aresult[1]);
557
-                    $this->setVersion(str_replace(';', '', $aversion[0]));
558
-                    $this->_browser_name = self::BROWSER_YANDEXBOT;
559
-                    $this->setRobot(true);
560
-                    return true;
561
-                }
562
-            }
563
-            return false;
564
-        }
565
-
566
-        /**
567
-         * Determine if the browser is the YandexImageResizer or not
568
-         * @return boolean True if the browser is the YandexImageResizer otherwise false
569
-         */
570
-        protected function checkBrowserYandexImageResizerBot()
571
-        {
572
-            if (stripos($this->_agent, 'YandexImageResizer') !== false) {
573
-                $aresult = explode('/', stristr($this->_agent, 'YandexImageResizer'));
574
-                if (isset($aresult[1])) {
575
-                    $aversion = explode(' ', $aresult[1]);
576
-                    $this->setVersion(str_replace(';', '', $aversion[0]));
577
-                    $this->_browser_name = self::BROWSER_YANDEXIMAGERESIZER_BOT;
578
-                    $this->setRobot(true);
579
-                    return true;
580
-                }
581
-            }
582
-            return false;
583
-        }
584
-
585
-        /**
586
-         * Determine if the browser is the YandexCatalog or not
587
-         * @return boolean True if the browser is the YandexCatalog otherwise false
588
-         */
589
-        protected function checkBrowserYandexCatalogBot()
590
-        {
591
-            if (stripos($this->_agent, 'YandexCatalog') !== false) {
592
-                $aresult = explode('/', stristr($this->_agent, 'YandexCatalog'));
593
-                if (isset($aresult[1])) {
594
-                    $aversion = explode(' ', $aresult[1]);
595
-                    $this->setVersion(str_replace(';', '', $aversion[0]));
596
-                    $this->_browser_name = self::BROWSER_YANDEXCATALOG_BOT;
597
-                    $this->setRobot(true);
598
-                    return true;
599
-                }
600
-            }
601
-            return false;
602
-        }
603
-
604
-        /**
605
-         * Determine if the browser is the YandexNews or not
606
-         * @return boolean True if the browser is the YandexNews otherwise false
607
-         */
608
-        protected function checkBrowserYandexNewsBot()
609
-        {
610
-            if (stripos($this->_agent, 'YandexNews') !== false) {
611
-                $aresult = explode('/', stristr($this->_agent, 'YandexNews'));
612
-                if (isset($aresult[1])) {
613
-                    $aversion = explode(' ', $aresult[1]);
614
-                    $this->setVersion(str_replace(';', '', $aversion[0]));
615
-                    $this->_browser_name = self::BROWSER_YANDEXNEWS_BOT;
616
-                    $this->setRobot(true);
617
-                    return true;
618
-                }
619
-            }
620
-            return false;
621
-        }
622
-
623
-        /**
624
-         * Determine if the browser is the YandexMetrika or not
625
-         * @return boolean True if the browser is the YandexMetrika otherwise false
626
-         */
627
-        protected function checkBrowserYandexMetrikaBot()
628
-        {
629
-            if (stripos($this->_agent, 'YandexMetrika') !== false) {
630
-                $aresult = explode('/', stristr($this->_agent, 'YandexMetrika'));
631
-                if (isset($aresult[1])) {
632
-                    $aversion = explode(' ', $aresult[1]);
633
-                    $this->setVersion(str_replace(';', '', $aversion[0]));
634
-                    $this->_browser_name = self::BROWSER_YANDEXMETRIKA_BOT;
635
-                    $this->setRobot(true);
636
-                    return true;
637
-                }
638
-            }
639
-            return false;
640
-        }
641
-
642
-        /**
643
-         * Determine if the browser is the YandexDirect or not
644
-         * @return boolean True if the browser is the YandexDirect otherwise false
645
-         */
646
-        protected function checkBrowserYandexDirectBot()
647
-        {
648
-            if (stripos($this->_agent, 'YandexDirect') !== false) {
649
-                $aresult = explode('/', stristr($this->_agent, 'YandexDirect'));
650
-                if (isset($aresult[1])) {
651
-                    $aversion = explode(' ', $aresult[1]);
652
-                    $this->setVersion(str_replace(';', '', $aversion[0]));
653
-                    $this->_browser_name = self::BROWSER_YANDEXDIRECT_BOT;
654
-                    $this->setRobot(true);
655
-                    return true;
656
-                }
657
-            }
658
-            return false;
659
-        }
660
-
661
-        /**
662
-         * Determine if the browser is the YandexWebmaster or not
663
-         * @return boolean True if the browser is the YandexWebmaster otherwise false
664
-         */
665
-        protected function checkBrowserYandexWebmasterBot()
666
-        {
667
-            if (stripos($this->_agent, 'YandexWebmaster') !== false) {
668
-                $aresult = explode('/', stristr($this->_agent, 'YandexWebmaster'));
669
-                if (isset($aresult[1])) {
670
-                    $aversion = explode(' ', $aresult[1]);
671
-                    $this->setVersion(str_replace(';', '', $aversion[0]));
672
-                    $this->_browser_name = self::BROWSER_YANDEXWEBMASTER_BOT;
673
-                    $this->setRobot(true);
674
-                    return true;
675
-                }
676
-            }
677
-            return false;
678
-        }
679
-
680
-        /**
681
-         * Determine if the browser is the YandexFavicons or not
682
-         * @return boolean True if the browser is the YandexFavicons otherwise false
683
-         */
684
-        protected function checkBrowserYandexFaviconsBot()
685
-        {
686
-            if (stripos($this->_agent, 'YandexFavicons') !== false) {
687
-                $aresult = explode('/', stristr($this->_agent, 'YandexFavicons'));
688
-                if (isset($aresult[1])) {
689
-                    $aversion = explode(' ', $aresult[1]);
690
-                    $this->setVersion(str_replace(';', '', $aversion[0]));
691
-                    $this->_browser_name = self::BROWSER_YANDEXFAVICONS_BOT;
692
-                    $this->setRobot(true);
693
-                    return true;
694
-                }
695
-            }
696
-            return false;
697
-        }
698
-
699
-        /**
700
-         * Determine if the browser is the YandexBlogs or not
701
-         * @return boolean True if the browser is the YandexBlogs otherwise false
702
-         */
703
-        protected function checkBrowserYandexBlogsBot()
704
-        {
705
-            if (stripos($this->_agent, 'YandexBlogs') !== false) {
706
-                $aresult = explode('/', stristr($this->_agent, 'YandexBlogs'));
707
-                if (isset($aresult[1])) {
708
-                    $aversion = explode(' ', $aresult[1]);
709
-                    $this->setVersion(str_replace(';', '', $aversion[0]));
710
-                    $this->_browser_name = self::BROWSER_YANDEXBLOGS_BOT;
711
-                    $this->setRobot(true);
712
-                    return true;
713
-                }
714
-            }
715
-            return false;
716
-        }
717
-
718
-        /**
719
-         * Determine if the browser is the YandexMedia or not
720
-         * @return boolean True if the browser is the YandexMedia otherwise false
721
-         */
722
-        protected function checkBrowserYandexMediaBot()
723
-        {
724
-            if (stripos($this->_agent, 'YandexMedia') !== false) {
725
-                $aresult = explode('/', stristr($this->_agent, 'YandexMedia'));
726
-                if (isset($aresult[1])) {
727
-                    $aversion = explode(' ', $aresult[1]);
728
-                    $this->setVersion(str_replace(';', '', $aversion[0]));
729
-                    $this->_browser_name = self::BROWSER_YANDEXMEDIA_BOT;
730
-                    $this->setRobot(true);
731
-                    return true;
732
-                }
733
-            }
734
-            return false;
735
-        }
736
-
737
-        /**
738
-         * Determine if the browser is the YandexVideo or not
739
-         * @return boolean True if the browser is the YandexVideo otherwise false
740
-         */
741
-        protected function checkBrowserYandexVideoBot()
742
-        {
743
-            if (stripos($this->_agent, 'YandexVideo') !== false) {
744
-                $aresult = explode('/', stristr($this->_agent, 'YandexVideo'));
745
-                if (isset($aresult[1])) {
746
-                    $aversion = explode(' ', $aresult[1]);
747
-                    $this->setVersion(str_replace(';', '', $aversion[0]));
748
-                    $this->_browser_name = self::BROWSER_YANDEXVIDEO_BOT;
749
-                    $this->setRobot(true);
750
-                    return true;
751
-                }
752
-            }
753
-            return false;
754
-        }
755
-
756
-        /**
757
-         * Determine if the browser is the YandexImages or not
758
-         * @return boolean True if the browser is the YandexImages otherwise false
759
-         */
760
-        protected function checkBrowserYandexImagesBot()
761
-        {
762
-            if (stripos($this->_agent, 'YandexImages') !== false) {
763
-                $aresult = explode('/', stristr($this->_agent, 'YandexImages'));
764
-                if (isset($aresult[1])) {
765
-                    $aversion = explode(' ', $aresult[1]);
766
-                    $this->setVersion(str_replace(';', '', $aversion[0]));
767
-                    $this->_browser_name = self::BROWSER_YANDEXIMAGES_BOT;
768
-                    $this->setRobot(true);
769
-                    return true;
770
-                }
771
-            }
772
-            return false;
773
-        }
774
-
775
-        /**
776
-         * Determine if the browser is the MSNBot or not (last updated 1.9)
777
-         * @return boolean True if the browser is the MSNBot otherwise false
778
-         */
779
-        protected function checkBrowserMSNBot()
780
-        {
781
-            if (stripos($this->_agent, "msnbot") !== false) {
782
-                $aresult = explode("/", stristr($this->_agent, "msnbot"));
783
-                if (isset($aresult[1])) {
784
-                    $aversion = explode(" ", $aresult[1]);
785
-                    $this->setVersion(str_replace(";", "", $aversion[0]));
786
-                    $this->_browser_name = self::BROWSER_MSNBOT;
787
-                    $this->setRobot(true);
788
-                    return true;
789
-                }
790
-            }
791
-            return false;
792
-        }
793
-
794
-        /**
795
-         * Determine if the browser is the BingBot or not (last updated 1.9)
796
-         * @return boolean True if the browser is the BingBot otherwise false
797
-         */
798
-        protected function checkBrowserBingBot()
799
-        {
800
-            if (stripos($this->_agent, "bingbot") !== false) {
801
-                $aresult = explode("/", stristr($this->_agent, "bingbot"));
802
-                if (isset($aresult[1])) {
803
-                    $aversion = explode(" ", $aresult[1]);
804
-                    $this->setVersion(str_replace(";", "", $aversion[0]));
805
-                    $this->_browser_name = self::BROWSER_BINGBOT;
806
-                    $this->setRobot(true);
807
-                    return true;
808
-                }
809
-            }
810
-            return false;
811
-        }
812
-
813
-        /**
814
-         * Determine if the browser is the W3C Validator or not (last updated 1.7)
815
-         * @return boolean True if the browser is the W3C Validator otherwise false
816
-         */
817
-        protected function checkBrowserW3CValidator()
818
-        {
819
-            if (stripos($this->_agent, 'W3C-checklink') !== false) {
820
-                $aresult = explode('/', stristr($this->_agent, 'W3C-checklink'));
821
-                if (isset($aresult[1])) {
822
-                    $aversion = explode(' ', $aresult[1]);
823
-                    $this->setVersion($aversion[0]);
824
-                    $this->_browser_name = self::BROWSER_W3CVALIDATOR;
825
-                    return true;
826
-                }
827
-            } else if (stripos($this->_agent, 'W3C_Validator') !== false) {
828
-                // Some of the Validator versions do not delineate w/ a slash - add it back in
829
-                $ua = str_replace("W3C_Validator ", "W3C_Validator/", $this->_agent);
830
-                $aresult = explode('/', stristr($ua, 'W3C_Validator'));
831
-                if (isset($aresult[1])) {
832
-                    $aversion = explode(' ', $aresult[1]);
833
-                    $this->setVersion($aversion[0]);
834
-                    $this->_browser_name = self::BROWSER_W3CVALIDATOR;
835
-                    return true;
836
-                }
837
-            } else if (stripos($this->_agent, 'W3C-mobileOK') !== false) {
838
-                $this->_browser_name = self::BROWSER_W3CVALIDATOR;
839
-                $this->setMobile(true);
840
-                return true;
841
-            }
842
-            return false;
843
-        }
844
-
845
-        /**
846
-         * Determine if the browser is the Yahoo! Slurp Robot or not (last updated 1.7)
847
-         * @return boolean True if the browser is the Yahoo! Slurp Robot otherwise false
848
-         */
849
-        protected function checkBrowserSlurp()
850
-        {
851
-            if (stripos($this->_agent, 'slurp') !== false) {
852
-                $aresult = explode('/', stristr($this->_agent, 'Slurp'));
853
-                if (isset($aresult[1])) {
854
-                    $aversion = explode(' ', $aresult[1]);
855
-                    $this->setVersion($aversion[0]);
856
-                    $this->_browser_name = self::BROWSER_SLURP;
857
-                    $this->setRobot(true);
858
-                    $this->setMobile(false);
859
-                    return true;
860
-                }
861
-            }
862
-            return false;
863
-        }
864
-
865
-        /**
866
-         * Determine if the browser is Edge or not
867
-         * @return boolean True if the browser is Edge otherwise false
868
-         */
869
-        protected function checkBrowserEdge()
870
-        {
871
-            if (stripos($this->_agent, 'Edge/') !== false) {
872
-                $aresult = explode('/', stristr($this->_agent, 'Edge'));
873
-                if (isset($aresult[1])) {
874
-                    $aversion = explode(' ', $aresult[1]);
875
-                    $this->setVersion($aversion[0]);
876
-                    $this->setBrowser(self::BROWSER_EDGE);
877
-                    if (stripos($this->_agent, 'Windows Phone') !== false || stripos($this->_agent, 'Android') !== false) {
878
-                        $this->setMobile(true);
879
-                    }
880
-                    return true;
881
-                }
882
-            }
883
-            return false;
884
-        }
885
-
886
-        /**
887
-         * Determine if the browser is Internet Explorer or not (last updated 1.7)
888
-         * @return boolean True if the browser is Internet Explorer otherwise false
889
-         */
890
-        protected function checkBrowserInternetExplorer()
891
-        {
892
-            //  Test for IE11
893
-            if (stripos($this->_agent, 'Trident/7.0; rv:11.0') !== false) {
894
-                $this->setBrowser(self::BROWSER_IE);
895
-                $this->setVersion('11.0');
896
-                return true;
897
-            } // Test for v1 - v1.5 IE
898
-            else if (stripos($this->_agent, 'microsoft internet explorer') !== false) {
899
-                $this->setBrowser(self::BROWSER_IE);
900
-                $this->setVersion('1.0');
901
-                $aresult = stristr($this->_agent, '/');
902
-                if (preg_match('/308|425|426|474|0b1/i', $aresult)) {
903
-                    $this->setVersion('1.5');
904
-                }
905
-                return true;
906
-            } // Test for versions > 1.5
907
-            else if (stripos($this->_agent, 'msie') !== false && stripos($this->_agent, 'opera') === false) {
908
-                // See if the browser is the odd MSN Explorer
909
-                if (stripos($this->_agent, 'msnb') !== false) {
910
-                    $aresult = explode(' ', stristr(str_replace(';', '; ', $this->_agent), 'MSN'));
911
-                    if (isset($aresult[1])) {
912
-                        $this->setBrowser(self::BROWSER_MSN);
913
-                        $this->setVersion(str_replace(array('(', ')', ';'), '', $aresult[1]));
914
-                        return true;
915
-                    }
916
-                }
917
-                $aresult = explode(' ', stristr(str_replace(';', '; ', $this->_agent), 'msie'));
918
-                if (isset($aresult[1])) {
919
-                    $this->setBrowser(self::BROWSER_IE);
920
-                    $this->setVersion(str_replace(array('(', ')', ';'), '', $aresult[1]));
921
-                    if(preg_match('#trident/([0-9\.]+);#i', $this->_agent, $aresult)){
922
-                        if($aresult[1] == '3.1'){
923
-                            $this->setVersion('7.0');
924
-                        }
925
-                        else if($aresult[1] == '4.0'){
926
-                            $this->setVersion('8.0');
927
-                        }
928
-                        else if($aresult[1] == '5.0'){
929
-                            $this->setVersion('9.0');
930
-                        }
931
-                        else if($aresult[1] == '6.0'){
932
-                            $this->setVersion('10.0');
933
-                        }
934
-                        else if($aresult[1] == '7.0'){
935
-                            $this->setVersion('11.0');
936
-                        }
937
-                        else if($aresult[1] == '8.0'){
938
-                            $this->setVersion('11.0');
939
-                        }
940
-                    }
941
-                    if(stripos($this->_agent, 'IEMobile') !== false) {
942
-                        $this->setBrowser(self::BROWSER_POCKET_IE);
943
-                        $this->setMobile(true);
944
-                    }
945
-                    return true;
946
-                }
947
-            } // Test for versions > IE 10
948
-            else if (stripos($this->_agent, 'trident') !== false) {
949
-                $this->setBrowser(self::BROWSER_IE);
950
-                $result = explode('rv:', $this->_agent);
951
-                if (isset($result[1])) {
952
-                    $this->setVersion(preg_replace('/[^0-9.]+/', '', $result[1]));
953
-                    $this->_agent = str_replace(array("Mozilla", "Gecko"), "MSIE", $this->_agent);
954
-                }
955
-            } // Test for Pocket IE
956
-            else if (stripos($this->_agent, 'mspie') !== false || stripos($this->_agent, 'pocket') !== false) {
957
-                $aresult = explode(' ', stristr($this->_agent, 'mspie'));
958
-                if (isset($aresult[1])) {
959
-                    $this->setPlatform(self::PLATFORM_WINDOWS_CE);
960
-                    $this->setBrowser(self::BROWSER_POCKET_IE);
961
-                    $this->setMobile(true);
962
-
963
-                    if (stripos($this->_agent, 'mspie') !== false) {
964
-                        $this->setVersion($aresult[1]);
965
-                    } else {
966
-                        $aversion = explode('/', $this->_agent);
967
-                        if (isset($aversion[1])) {
968
-                            $this->setVersion($aversion[1]);
969
-                        }
970
-                    }
971
-                    return true;
972
-                }
973
-            }
974
-            return false;
975
-        }
976
-
977
-        /**
978
-         * Determine if the browser is Opera or not (last updated 1.7)
979
-         * @return boolean True if the browser is Opera otherwise false
980
-         */
981
-        protected function checkBrowserOpera()
982
-        {
983
-            if (stripos($this->_agent, 'opera mini') !== false) {
984
-                $resultant = stristr($this->_agent, 'opera mini');
985
-                if (preg_match('/\//', $resultant)) {
986
-                    $aresult = explode('/', $resultant);
987
-                    if (isset($aresult[1])) {
988
-                        $aversion = explode(' ', $aresult[1]);
989
-                        $this->setVersion($aversion[0]);
990
-                    }
991
-                } else {
992
-                    $aversion = explode(' ', stristr($resultant, 'opera mini'));
993
-                    if (isset($aversion[1])) {
994
-                        $this->setVersion($aversion[1]);
995
-                    }
996
-                }
997
-                $this->_browser_name = self::BROWSER_OPERA_MINI;
998
-                $this->setMobile(true);
999
-                return true;
1000
-            } else if (stripos($this->_agent, 'opera') !== false) {
1001
-                $resultant = stristr($this->_agent, 'opera');
1002
-                if (preg_match('/Version\/(1*.*)$/', $resultant, $matches)) {
1003
-                    $this->setVersion($matches[1]);
1004
-                } else if (preg_match('/\//', $resultant)) {
1005
-                    $aresult = explode('/', str_replace("(", " ", $resultant));
1006
-                    if (isset($aresult[1])) {
1007
-                        $aversion = explode(' ', $aresult[1]);
1008
-                        $this->setVersion($aversion[0]);
1009
-                    }
1010
-                } else {
1011
-                    $aversion = explode(' ', stristr($resultant, 'opera'));
1012
-                    $this->setVersion(isset($aversion[1]) ? $aversion[1] : "");
1013
-                }
1014
-                if (stripos($this->_agent, 'Opera Mobi') !== false) {
1015
-                    $this->setMobile(true);
1016
-                }
1017
-                $this->_browser_name = self::BROWSER_OPERA;
1018
-                return true;
1019
-            } else if (stripos($this->_agent, 'OPR') !== false) {
1020
-                $resultant = stristr($this->_agent, 'OPR');
1021
-                if (preg_match('/\//', $resultant)) {
1022
-                    $aresult = explode('/', str_replace("(", " ", $resultant));
1023
-                    if (isset($aresult[1])) {
1024
-                        $aversion = explode(' ', $aresult[1]);
1025
-                        $this->setVersion($aversion[0]);
1026
-                    }
1027
-                }
1028
-                if (stripos($this->_agent, 'Mobile') !== false) {
1029
-                    $this->setMobile(true);
1030
-                }
1031
-                $this->_browser_name = self::BROWSER_OPERA;
1032
-                return true;
1033
-            }
1034
-            return false;
1035
-        }
1036
-
1037
-        /**
1038
-         * Determine if the browser is Chrome or not (last updated 1.7)
1039
-         * @return boolean True if the browser is Chrome otherwise false
1040
-         */
1041
-        protected function checkBrowserChrome()
1042
-        {
1043
-            if (stripos($this->_agent, 'Chrome') !== false) {
1044
-                $aresult = explode('/', stristr($this->_agent, 'Chrome'));
1045
-                if (isset($aresult[1])) {
1046
-                    $aversion = explode(' ', $aresult[1]);
1047
-                    $this->setVersion($aversion[0]);
1048
-                    $this->setBrowser(self::BROWSER_CHROME);
1049
-                    //Chrome on Android
1050
-                    if (stripos($this->_agent, 'Android') !== false) {
1051
-                        if (stripos($this->_agent, 'Mobile') !== false) {
1052
-                            $this->setMobile(true);
1053
-                        } else {
1054
-                            $this->setTablet(true);
1055
-                        }
1056
-                    }
1057
-                    return true;
1058
-                }
1059
-            }
1060
-            return false;
1061
-        }
1062
-
1063
-
1064
-        /**
1065
-         * Determine if the browser is WebTv or not (last updated 1.7)
1066
-         * @return boolean True if the browser is WebTv otherwise false
1067
-         */
1068
-        protected function checkBrowserWebTv()
1069
-        {
1070
-            if (stripos($this->_agent, 'webtv') !== false) {
1071
-                $aresult = explode('/', stristr($this->_agent, 'webtv'));
1072
-                if (isset($aresult[1])) {
1073
-                    $aversion = explode(' ', $aresult[1]);
1074
-                    $this->setVersion($aversion[0]);
1075
-                    $this->setBrowser(self::BROWSER_WEBTV);
1076
-                    return true;
1077
-                }
1078
-            }
1079
-            return false;
1080
-        }
1081
-
1082
-        /**
1083
-         * Determine if the browser is NetPositive or not (last updated 1.7)
1084
-         * @return boolean True if the browser is NetPositive otherwise false
1085
-         */
1086
-        protected function checkBrowserNetPositive()
1087
-        {
1088
-            if (stripos($this->_agent, 'NetPositive') !== false) {
1089
-                $aresult = explode('/', stristr($this->_agent, 'NetPositive'));
1090
-                if (isset($aresult[1])) {
1091
-                    $aversion = explode(' ', $aresult[1]);
1092
-                    $this->setVersion(str_replace(array('(', ')', ';'), '', $aversion[0]));
1093
-                    $this->setBrowser(self::BROWSER_NETPOSITIVE);
1094
-                    return true;
1095
-                }
1096
-            }
1097
-            return false;
1098
-        }
1099
-
1100
-        /**
1101
-         * Determine if the browser is Galeon or not (last updated 1.7)
1102
-         * @return boolean True if the browser is Galeon otherwise false
1103
-         */
1104
-        protected function checkBrowserGaleon()
1105
-        {
1106
-            if (stripos($this->_agent, 'galeon') !== false) {
1107
-                $aresult = explode(' ', stristr($this->_agent, 'galeon'));
1108
-                $aversion = explode('/', $aresult[0]);
1109
-                if (isset($aversion[1])) {
1110
-                    $this->setVersion($aversion[1]);
1111
-                    $this->setBrowser(self::BROWSER_GALEON);
1112
-                    return true;
1113
-                }
1114
-            }
1115
-            return false;
1116
-        }
1117
-
1118
-        /**
1119
-         * Determine if the browser is Konqueror or not (last updated 1.7)
1120
-         * @return boolean True if the browser is Konqueror otherwise false
1121
-         */
1122
-        protected function checkBrowserKonqueror()
1123
-        {
1124
-            if (stripos($this->_agent, 'Konqueror') !== false) {
1125
-                $aresult = explode(' ', stristr($this->_agent, 'Konqueror'));
1126
-                $aversion = explode('/', $aresult[0]);
1127
-                if (isset($aversion[1])) {
1128
-                    $this->setVersion($aversion[1]);
1129
-                    $this->setBrowser(self::BROWSER_KONQUEROR);
1130
-                    return true;
1131
-                }
1132
-            }
1133
-            return false;
1134
-        }
1135
-
1136
-        /**
1137
-         * Determine if the browser is iCab or not (last updated 1.7)
1138
-         * @return boolean True if the browser is iCab otherwise false
1139
-         */
1140
-        protected function checkBrowserIcab()
1141
-        {
1142
-            if (stripos($this->_agent, 'icab') !== false) {
1143
-                $aversion = explode(' ', stristr(str_replace('/', ' ', $this->_agent), 'icab'));
1144
-                if (isset($aversion[1])) {
1145
-                    $this->setVersion($aversion[1]);
1146
-                    $this->setBrowser(self::BROWSER_ICAB);
1147
-                    return true;
1148
-                }
1149
-            }
1150
-            return false;
1151
-        }
1152
-
1153
-        /**
1154
-         * Determine if the browser is OmniWeb or not (last updated 1.7)
1155
-         * @return boolean True if the browser is OmniWeb otherwise false
1156
-         */
1157
-        protected function checkBrowserOmniWeb()
1158
-        {
1159
-            if (stripos($this->_agent, 'omniweb') !== false) {
1160
-                $aresult = explode('/', stristr($this->_agent, 'omniweb'));
1161
-                $aversion = explode(' ', isset($aresult[1]) ? $aresult[1] : "");
1162
-                $this->setVersion($aversion[0]);
1163
-                $this->setBrowser(self::BROWSER_OMNIWEB);
1164
-                return true;
1165
-            }
1166
-            return false;
1167
-        }
1168
-
1169
-        /**
1170
-         * Determine if the browser is Phoenix or not (last updated 1.7)
1171
-         * @return boolean True if the browser is Phoenix otherwise false
1172
-         */
1173
-        protected function checkBrowserPhoenix()
1174
-        {
1175
-            if (stripos($this->_agent, 'Phoenix') !== false) {
1176
-                $aversion = explode('/', stristr($this->_agent, 'Phoenix'));
1177
-                if (isset($aversion[1])) {
1178
-                    $this->setVersion($aversion[1]);
1179
-                    $this->setBrowser(self::BROWSER_PHOENIX);
1180
-                    return true;
1181
-                }
1182
-            }
1183
-            return false;
1184
-        }
1185
-
1186
-        /**
1187
-         * Determine if the browser is Firebird or not (last updated 1.7)
1188
-         * @return boolean True if the browser is Firebird otherwise false
1189
-         */
1190
-        protected function checkBrowserFirebird()
1191
-        {
1192
-            if (stripos($this->_agent, 'Firebird') !== false) {
1193
-                $aversion = explode('/', stristr($this->_agent, 'Firebird'));
1194
-                if (isset($aversion[1])) {
1195
-                    $this->setVersion($aversion[1]);
1196
-                    $this->setBrowser(self::BROWSER_FIREBIRD);
1197
-                    return true;
1198
-                }
1199
-            }
1200
-            return false;
1201
-        }
1202
-
1203
-        /**
1204
-         * Determine if the browser is Netscape Navigator 9+ or not (last updated 1.7)
1205
-         * NOTE: (http://browser.netscape.com/ - Official support ended on March 1st, 2008)
1206
-         * @return boolean True if the browser is Netscape Navigator 9+ otherwise false
1207
-         */
1208
-        protected function checkBrowserNetscapeNavigator9Plus()
1209
-        {
1210
-            if (stripos($this->_agent, 'Firefox') !== false && preg_match('/Navigator\/([^ ]*)/i', $this->_agent, $matches)) {
1211
-                $this->setVersion($matches[1]);
1212
-                $this->setBrowser(self::BROWSER_NETSCAPE_NAVIGATOR);
1213
-                return true;
1214
-            } else if (stripos($this->_agent, 'Firefox') === false && preg_match('/Netscape6?\/([^ ]*)/i', $this->_agent, $matches)) {
1215
-                $this->setVersion($matches[1]);
1216
-                $this->setBrowser(self::BROWSER_NETSCAPE_NAVIGATOR);
1217
-                return true;
1218
-            }
1219
-            return false;
1220
-        }
1221
-
1222
-        /**
1223
-         * Determine if the browser is Shiretoko or not (https://wiki.mozilla.org/Projects/shiretoko) (last updated 1.7)
1224
-         * @return boolean True if the browser is Shiretoko otherwise false
1225
-         */
1226
-        protected function checkBrowserShiretoko()
1227
-        {
1228
-            if (stripos($this->_agent, 'Mozilla') !== false && preg_match('/Shiretoko\/([^ ]*)/i', $this->_agent, $matches)) {
1229
-                $this->setVersion($matches[1]);
1230
-                $this->setBrowser(self::BROWSER_SHIRETOKO);
1231
-                return true;
1232
-            }
1233
-            return false;
1234
-        }
1235
-
1236
-        /**
1237
-         * Determine if the browser is Ice Cat or not (http://en.wikipedia.org/wiki/GNU_IceCat) (last updated 1.7)
1238
-         * @return boolean True if the browser is Ice Cat otherwise false
1239
-         */
1240
-        protected function checkBrowserIceCat()
1241
-        {
1242
-            if (stripos($this->_agent, 'Mozilla') !== false && preg_match('/IceCat\/([^ ]*)/i', $this->_agent, $matches)) {
1243
-                $this->setVersion($matches[1]);
1244
-                $this->setBrowser(self::BROWSER_ICECAT);
1245
-                return true;
1246
-            }
1247
-            return false;
1248
-        }
1249
-
1250
-        /**
1251
-         * Determine if the browser is Nokia or not (last updated 1.7)
1252
-         * @return boolean True if the browser is Nokia otherwise false
1253
-         */
1254
-        protected function checkBrowserNokia()
1255
-        {
1256
-            if (preg_match("/Nokia([^\/]+)\/([^ SP]+)/i", $this->_agent, $matches)) {
1257
-                $this->setVersion($matches[2]);
1258
-                if (stripos($this->_agent, 'Series60') !== false || strpos($this->_agent, 'S60') !== false) {
1259
-                    $this->setBrowser(self::BROWSER_NOKIA_S60);
1260
-                } else {
1261
-                    $this->setBrowser(self::BROWSER_NOKIA);
1262
-                }
1263
-                $this->setMobile(true);
1264
-                return true;
1265
-            }
1266
-            return false;
1267
-        }
1268
-
1269
-        /**
1270
-         * Determine if the browser is Firefox or not (last updated 1.7)
1271
-         * @return boolean True if the browser is Firefox otherwise false
1272
-         */
1273
-        protected function checkBrowserFirefox()
1274
-        {
1275
-            if (stripos($this->_agent, 'safari') === false) {
1276
-                if (preg_match("/Firefox[\/ \(]([^ ;\)]+)/i", $this->_agent, $matches)) {
1277
-                    $this->setVersion($matches[1]);
1278
-                    $this->setBrowser(self::BROWSER_FIREFOX);
1279
-                    //Firefox on Android
1280
-                    if (stripos($this->_agent, 'Android') !== false) {
1281
-                        if (stripos($this->_agent, 'Mobile') !== false) {
1282
-                            $this->setMobile(true);
1283
-                        } else {
1284
-                            $this->setTablet(true);
1285
-                        }
1286
-                    }
1287
-                    return true;
1288
-                } else if (preg_match("/Firefox$/i", $this->_agent, $matches)) {
1289
-                    $this->setVersion("");
1290
-                    $this->setBrowser(self::BROWSER_FIREFOX);
1291
-                    return true;
1292
-                }
1293
-            }
1294
-            return false;
1295
-        }
1296
-
1297
-        /**
1298
-         * Determine if the browser is Firefox or not (last updated 1.7)
1299
-         * @return boolean True if the browser is Firefox otherwise false
1300
-         */
1301
-        protected function checkBrowserIceweasel()
1302
-        {
1303
-            if (stripos($this->_agent, 'Iceweasel') !== false) {
1304
-                $aresult = explode('/', stristr($this->_agent, 'Iceweasel'));
1305
-                if (isset($aresult[1])) {
1306
-                    $aversion = explode(' ', $aresult[1]);
1307
-                    $this->setVersion($aversion[0]);
1308
-                    $this->setBrowser(self::BROWSER_ICEWEASEL);
1309
-                    return true;
1310
-                }
1311
-            }
1312
-            return false;
1313
-        }
1314
-
1315
-        /**
1316
-         * Determine if the browser is Mozilla or not (last updated 1.7)
1317
-         * @return boolean True if the browser is Mozilla otherwise false
1318
-         */
1319
-        protected function checkBrowserMozilla()
1320
-        {
1321
-            if (stripos($this->_agent, 'mozilla') !== false && preg_match('/rv:[0-9].[0-9][a-b]?/i', $this->_agent) && stripos($this->_agent, 'netscape') === false) {
1322
-                $aversion = explode(' ', stristr($this->_agent, 'rv:'));
1323
-                preg_match('/rv:[0-9].[0-9][a-b]?/i', $this->_agent, $aversion);
1324
-                $this->setVersion(str_replace('rv:', '', $aversion[0]));
1325
-                $this->setBrowser(self::BROWSER_MOZILLA);
1326
-                return true;
1327
-            } else if (stripos($this->_agent, 'mozilla') !== false && preg_match('/rv:[0-9]\.[0-9]/i', $this->_agent) && stripos($this->_agent, 'netscape') === false) {
1328
-                $aversion = explode('', stristr($this->_agent, 'rv:'));
1329
-                $this->setVersion(str_replace('rv:', '', $aversion[0]));
1330
-                $this->setBrowser(self::BROWSER_MOZILLA);
1331
-                return true;
1332
-            } else if (stripos($this->_agent, 'mozilla') !== false && preg_match('/mozilla\/([^ ]*)/i', $this->_agent, $matches) && stripos($this->_agent, 'netscape') === false) {
1333
-                $this->setVersion($matches[1]);
1334
-                $this->setBrowser(self::BROWSER_MOZILLA);
1335
-                return true;
1336
-            }
1337
-            return false;
1338
-        }
1339
-
1340
-        /**
1341
-         * Determine if the browser is Lynx or not (last updated 1.7)
1342
-         * @return boolean True if the browser is Lynx otherwise false
1343
-         */
1344
-        protected function checkBrowserLynx()
1345
-        {
1346
-            if (stripos($this->_agent, 'lynx') !== false) {
1347
-                $aresult = explode('/', stristr($this->_agent, 'Lynx'));
1348
-                $aversion = explode(' ', (isset($aresult[1]) ? $aresult[1] : ""));
1349
-                $this->setVersion($aversion[0]);
1350
-                $this->setBrowser(self::BROWSER_LYNX);
1351
-                return true;
1352
-            }
1353
-            return false;
1354
-        }
1355
-
1356
-        /**
1357
-         * Determine if the browser is Amaya or not (last updated 1.7)
1358
-         * @return boolean True if the browser is Amaya otherwise false
1359
-         */
1360
-        protected function checkBrowserAmaya()
1361
-        {
1362
-            if (stripos($this->_agent, 'amaya') !== false) {
1363
-                $aresult = explode('/', stristr($this->_agent, 'Amaya'));
1364
-                if (isset($aresult[1])) {
1365
-                    $aversion = explode(' ', $aresult[1]);
1366
-                    $this->setVersion($aversion[0]);
1367
-                    $this->setBrowser(self::BROWSER_AMAYA);
1368
-                    return true;
1369
-                }
1370
-            }
1371
-            return false;
1372
-        }
1373
-
1374
-        /**
1375
-         * Determine if the browser is Safari or not (last updated 1.7)
1376
-         * @return boolean True if the browser is Safari otherwise false
1377
-         */
1378
-        protected function checkBrowserSafari()
1379
-        {
1380
-            if (stripos($this->_agent, 'Safari') !== false
1381
-                && stripos($this->_agent, 'iPhone') === false
1382
-                && stripos($this->_agent, 'iPod') === false
1383
-            ) {
1384
-
1385
-                $aresult = explode('/', stristr($this->_agent, 'Version'));
1386
-                if (isset($aresult[1])) {
1387
-                    $aversion = explode(' ', $aresult[1]);
1388
-                    $this->setVersion($aversion[0]);
1389
-                } else {
1390
-                    $this->setVersion(self::VERSION_UNKNOWN);
1391
-                }
1392
-                $this->setBrowser(self::BROWSER_SAFARI);
1393
-                return true;
1394
-            }
1395
-            return false;
1396
-        }
1397
-
1398
-        protected function checkBrowserSamsung()
1399
-        {
1400
-            if (stripos($this->_agent, 'SamsungBrowser') !== false) {
1401
-
1402
-                $aresult = explode('/', stristr($this->_agent, 'SamsungBrowser'));
1403
-                if (isset($aresult[1])) {
1404
-                    $aversion = explode(' ', $aresult[1]);
1405
-                    $this->setVersion($aversion[0]);
1406
-                } else {
1407
-                    $this->setVersion(self::VERSION_UNKNOWN);
1408
-                }
1409
-                $this->setBrowser(self::BROWSER_SAMSUNG);
1410
-                return true;
1411
-            }
1412
-            return false;
1413
-        }
1414
-
1415
-        protected function checkBrowserSilk()
1416
-        {
1417
-            if (stripos($this->_agent, 'Silk') !== false) {
1418
-                $aresult = explode('/', stristr($this->_agent, 'Silk'));
1419
-                if (isset($aresult[1])) {
1420
-                    $aversion = explode(' ', $aresult[1]);
1421
-                    $this->setVersion($aversion[0]);
1422
-                } else {
1423
-                    $this->setVersion(self::VERSION_UNKNOWN);
1424
-                }
1425
-                $this->setBrowser(self::BROWSER_SILK);
1426
-                return true;
1427
-            }
1428
-            return false;
1429
-        }
1430
-
1431
-        protected function checkBrowserIframely()
1432
-        {
1433
-            if (stripos($this->_agent, 'Iframely') !== false) {
1434
-                $aresult = explode('/', stristr($this->_agent, 'Iframely'));
1435
-                if (isset($aresult[1])) {
1436
-                    $aversion = explode(' ', $aresult[1]);
1437
-                    $this->setVersion($aversion[0]);
1438
-                } else {
1439
-                    $this->setVersion(self::VERSION_UNKNOWN);
1440
-                }
1441
-                $this->setBrowser(self::BROWSER_I_FRAME);
1442
-                return true;
1443
-            }
1444
-            return false;
1445
-        }
1446
-
1447
-        protected function checkBrowserCocoa()
1448
-        {
1449
-            if (stripos($this->_agent, 'CocoaRestClient') !== false) {
1450
-                $aresult = explode('/', stristr($this->_agent, 'CocoaRestClient'));
1451
-                if (isset($aresult[1])) {
1452
-                    $aversion = explode(' ', $aresult[1]);
1453
-                    $this->setVersion($aversion[0]);
1454
-                } else {
1455
-                    $this->setVersion(self::VERSION_UNKNOWN);
1456
-                }
1457
-                $this->setBrowser(self::BROWSER_COCOA);
1458
-                return true;
1459
-            }
1460
-            return false;
1461
-        }
1462
-
1463
-        /**
1464
-         * Detect if URL is loaded from FacebookExternalHit
1465
-         * @return boolean True if it detects FacebookExternalHit otherwise false
1466
-         */
1467
-        protected function checkFacebookExternalHit()
1468
-        {
1469
-            if (stristr($this->_agent, 'FacebookExternalHit')) {
1470
-                $this->setRobot(true);
1471
-                $this->setFacebook(true);
1472
-                return true;
1473
-            }
1474
-            return false;
1475
-        }
1476
-
1477
-        /**
1478
-         * Detect if URL is being loaded from internal Facebook browser
1479
-         * @return boolean True if it detects internal Facebook browser otherwise false
1480
-         */
1481
-        protected function checkForFacebookIos()
1482
-        {
1483
-            if (stristr($this->_agent, 'FBIOS')) {
1484
-                $this->setFacebook(true);
1485
-                return true;
1486
-            }
1487
-            return false;
1488
-        }
1489
-
1490
-        /**
1491
-         * Detect Version for the Safari browser on iOS devices
1492
-         * @return boolean True if it detects the version correctly otherwise false
1493
-         */
1494
-        protected function getSafariVersionOnIos()
1495
-        {
1496
-            $aresult = explode('/', stristr($this->_agent, 'Version'));
1497
-            if (isset($aresult[1])) {
1498
-                $aversion = explode(' ', $aresult[1]);
1499
-                $this->setVersion($aversion[0]);
1500
-                return true;
1501
-            }
1502
-            return false;
1503
-        }
1504
-
1505
-        /**
1506
-         * Detect Version for the Chrome browser on iOS devices
1507
-         * @return boolean True if it detects the version correctly otherwise false
1508
-         */
1509
-        protected function getChromeVersionOnIos()
1510
-        {
1511
-            $aresult = explode('/', stristr($this->_agent, 'CriOS'));
1512
-            if (isset($aresult[1])) {
1513
-                $aversion = explode(' ', $aresult[1]);
1514
-                $this->setVersion($aversion[0]);
1515
-                $this->setBrowser(self::BROWSER_CHROME);
1516
-                return true;
1517
-            }
1518
-            return false;
1519
-        }
1520
-
1521
-        /**
1522
-         * Determine if the browser is iPhone or not (last updated 1.7)
1523
-         * @return boolean True if the browser is iPhone otherwise false
1524
-         */
1525
-        protected function checkBrowseriPhone()
1526
-        {
1527
-            if (stripos($this->_agent, 'iPhone') !== false) {
1528
-                $this->setVersion(self::VERSION_UNKNOWN);
1529
-                $this->setBrowser(self::BROWSER_IPHONE);
1530
-                $this->getSafariVersionOnIos();
1531
-                $this->getChromeVersionOnIos();
1532
-                $this->checkForFacebookIos();
1533
-                $this->setMobile(true);
1534
-                return true;
1535
-
1536
-            }
1537
-            return false;
1538
-        }
1539
-
1540
-        /**
1541
-         * Determine if the browser is iPad or not (last updated 1.7)
1542
-         * @return boolean True if the browser is iPad otherwise false
1543
-         */
1544
-        protected function checkBrowseriPad()
1545
-        {
1546
-            if (stripos($this->_agent, 'iPad') !== false) {
1547
-                $this->setVersion(self::VERSION_UNKNOWN);
1548
-                $this->setBrowser(self::BROWSER_IPAD);
1549
-                $this->getSafariVersionOnIos();
1550
-                $this->getChromeVersionOnIos();
1551
-                $this->checkForFacebookIos();
1552
-                $this->setTablet(true);
1553
-                return true;
1554
-            }
1555
-            return false;
1556
-        }
1557
-
1558
-        /**
1559
-         * Determine if the browser is iPod or not (last updated 1.7)
1560
-         * @return boolean True if the browser is iPod otherwise false
1561
-         */
1562
-        protected function checkBrowseriPod()
1563
-        {
1564
-            if (stripos($this->_agent, 'iPod') !== false) {
1565
-                $this->setVersion(self::VERSION_UNKNOWN);
1566
-                $this->setBrowser(self::BROWSER_IPOD);
1567
-                $this->getSafariVersionOnIos();
1568
-                $this->getChromeVersionOnIos();
1569
-                $this->checkForFacebookIos();
1570
-                $this->setMobile(true);
1571
-                return true;
1572
-            }
1573
-            return false;
1574
-        }
1575
-
1576
-        /**
1577
-         * Determine if the browser is Android or not (last updated 1.7)
1578
-         * @return boolean True if the browser is Android otherwise false
1579
-         */
1580
-        protected function checkBrowserAndroid()
1581
-        {
1582
-            if (stripos($this->_agent, 'Android') !== false) {
1583
-                $aresult = explode(' ', stristr($this->_agent, 'Android'));
1584
-                if (isset($aresult[1])) {
1585
-                    $aversion = explode(' ', $aresult[1]);
1586
-                    $this->setVersion($aversion[0]);
1587
-                } else {
1588
-                    $this->setVersion(self::VERSION_UNKNOWN);
1589
-                }
1590
-                if (stripos($this->_agent, 'Mobile') !== false) {
1591
-                    $this->setMobile(true);
1592
-                } else {
1593
-                    $this->setTablet(true);
1594
-                }
1595
-                $this->setBrowser(self::BROWSER_ANDROID);
1596
-                return true;
1597
-            }
1598
-            return false;
1599
-        }
1600
-
1601
-        /**
1602
-         * Determine if the browser is Vivaldi
1603
-         * @return boolean True if the browser is Vivaldi otherwise false
1604
-         */
1605
-        protected function checkBrowserVivaldi()
1606
-        {
1607
-            if (stripos($this->_agent, 'Vivaldi') !== false) {
1608
-                $aresult = explode('/', stristr($this->_agent, 'Vivaldi'));
1609
-                if (isset($aresult[1])) {
1610
-                    $aversion = explode(' ', $aresult[1]);
1611
-                    $this->setVersion($aversion[0]);
1612
-                    $this->setBrowser(self::BROWSER_VIVALDI);
1613
-                    return true;
1614
-                }
1615
-            }
1616
-            return false;
1617
-        }
1618
-
1619
-        /**
1620
-         * Determine if the browser is Yandex
1621
-         * @return boolean True if the browser is Yandex otherwise false
1622
-         */
1623
-        protected function checkBrowserYandex()
1624
-        {
1625
-            if (stripos($this->_agent, 'YaBrowser') !== false) {
1626
-                $aresult = explode('/', stristr($this->_agent, 'YaBrowser'));
1627
-                if (isset($aresult[1])) {
1628
-                    $aversion = explode(' ', $aresult[1]);
1629
-                    $this->setVersion($aversion[0]);
1630
-                    $this->setBrowser(self::BROWSER_YANDEX);
1631
-
1632
-                    if (stripos($this->_agent, 'iPad') !== false) {
1633
-                        $this->setTablet(true);
1634
-                    } elseif (stripos($this->_agent, 'Mobile') !== false) {
1635
-                        $this->setMobile(true);
1636
-                    } elseif (stripos($this->_agent, 'Android') !== false) {
1637
-                        $this->setTablet(true);
1638
-                    }
1639
-
1640
-                    return true;
1641
-                }
1642
-            }
1643
-
1644
-            return false;
1645
-        }
1646
-
1647
-        /**
1648
-         * Determine if the browser is a PlayStation
1649
-         * @return boolean True if the browser is PlayStation otherwise false
1650
-         */
1651
-        protected function checkBrowserPlayStation()
1652
-        {
1653
-            if (stripos($this->_agent, 'PlayStation ') !== false) {
1654
-                $aresult = explode(' ', stristr($this->_agent, 'PlayStation '));
1655
-                $this->setBrowser(self::BROWSER_PLAYSTATION);
1656
-                if (isset($aresult[0])) {
1657
-                    $aversion = explode(')', $aresult[2]);
1658
-                    $this->setVersion($aversion[0]);
1659
-                    if (stripos($this->_agent, 'Portable)') !== false || stripos($this->_agent, 'Vita') !== false) {
1660
-                        $this->setMobile(true);
1661
-                    }
1662
-                    return true;
1663
-                }
1664
-            }
1665
-            return false;
1666
-        }
1667
-
1668
-        /**
1669
-         * Determine the user's platform (last updated 2.0)
1670
-         */
1671
-        protected function checkPlatform()
1672
-        {
1673
-            if (stripos($this->_agent, 'windows') !== false) {
1674
-                $this->_platform = self::PLATFORM_WINDOWS;
1675
-            } else if (stripos($this->_agent, 'iPad') !== false) {
1676
-                $this->_platform = self::PLATFORM_IPAD;
1677
-            } else if (stripos($this->_agent, 'iPod') !== false) {
1678
-                $this->_platform = self::PLATFORM_IPOD;
1679
-            } else if (stripos($this->_agent, 'iPhone') !== false) {
1680
-                $this->_platform = self::PLATFORM_IPHONE;
1681
-            } elseif (stripos($this->_agent, 'mac') !== false) {
1682
-                $this->_platform = self::PLATFORM_APPLE;
1683
-            } elseif (stripos($this->_agent, 'android') !== false) {
1684
-                $this->_platform = self::PLATFORM_ANDROID;
1685
-            } elseif (stripos($this->_agent, 'Silk') !== false) {
1686
-                $this->_platform = self::PLATFORM_FIRE_OS;
1687
-            } elseif (stripos($this->_agent, 'linux') !== false && stripos($this->_agent, 'SMART-TV') !== false ) {
1688
-                $this->_platform = self::PLATFORM_LINUX .'/'.self::PLATFORM_SMART_TV;
1689
-            } elseif (stripos($this->_agent, 'linux') !== false) {
1690
-                $this->_platform = self::PLATFORM_LINUX;
1691
-            } else if (stripos($this->_agent, 'Nokia') !== false) {
1692
-                $this->_platform = self::PLATFORM_NOKIA;
1693
-            } else if (stripos($this->_agent, 'BlackBerry') !== false) {
1694
-                $this->_platform = self::PLATFORM_BLACKBERRY;
1695
-            } elseif (stripos($this->_agent, 'FreeBSD') !== false) {
1696
-                $this->_platform = self::PLATFORM_FREEBSD;
1697
-            } elseif (stripos($this->_agent, 'OpenBSD') !== false) {
1698
-                $this->_platform = self::PLATFORM_OPENBSD;
1699
-            } elseif (stripos($this->_agent, 'NetBSD') !== false) {
1700
-                $this->_platform = self::PLATFORM_NETBSD;
1701
-            } elseif (stripos($this->_agent, 'OpenSolaris') !== false) {
1702
-                $this->_platform = self::PLATFORM_OPENSOLARIS;
1703
-            } elseif (stripos($this->_agent, 'SunOS') !== false) {
1704
-                $this->_platform = self::PLATFORM_SUNOS;
1705
-            } elseif (stripos($this->_agent, 'OS\/2') !== false) {
1706
-                $this->_platform = self::PLATFORM_OS2;
1707
-            } elseif (stripos($this->_agent, 'BeOS') !== false) {
1708
-                $this->_platform = self::PLATFORM_BEOS;
1709
-            } elseif (stripos($this->_agent, 'win') !== false) {
1710
-                $this->_platform = self::PLATFORM_WINDOWS;
1711
-            } elseif (stripos($this->_agent, 'Playstation') !== false) {
1712
-                $this->_platform = self::PLATFORM_PLAYSTATION;
1713
-            } elseif (stripos($this->_agent, 'Roku') !== false) {
1714
-                $this->_platform = self::PLATFORM_ROKU;
1715
-            } elseif (stripos($this->_agent, 'iOS') !== false) {
1716
-                $this->_platform = self::PLATFORM_IPHONE . '/' . self::PLATFORM_IPAD;
1717
-            } elseif (stripos($this->_agent, 'tvOS') !== false) {
1718
-                $this->_platform = self::PLATFORM_APPLE_TV;
1719
-            } elseif (stripos($this->_agent, 'curl') !== false) {
1720
-                $this->_platform = self::PLATFORM_TERMINAL;
1721
-            } elseif (stripos($this->_agent, 'CrOS') !== false) {
1722
-                $this->_platform = self::PLATFORM_CHROME_OS;
1723
-            } elseif (stripos($this->_agent, 'okhttp') !== false) {
1724
-                $this->_platform = self::PLATFORM_JAVA_ANDROID;
1725
-            } elseif (stripos($this->_agent, 'PostmanRuntime') !== false) {
1726
-                $this->_platform = self::PLATFORM_POSTMAN;
1727
-            } elseif (stripos($this->_agent, 'Iframely') !== false) {
1728
-                $this->_platform = self::PLATFORM_I_FRAME;
1729
-            }
1730
-
1731
-        }
1732
-    }
2
+	defined('ROOT_PATH') || exit('Access denied');
3
+	/**
4
+	 * File: Browser.php
5
+	 * Author: Chris Schuld (http://chrisschuld.com/)
6
+	 * Last Modified: July 22nd, 2016
7
+	 * @version 2.0
8
+	 * @package PegasusPHP
9
+	 *
10
+	 * Copyright (C) 2008-2010 Chris Schuld  ([email protected])
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 as
14
+	 * published by the Free Software Foundation; either version 2 of
15
+	 * 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 at:
21
+	 * http://www.gnu.org/copyleft/gpl.html
22
+	 *
23
+	 *
24
+	 * Typical Usage:
25
+	 *
26
+	 *   $browser = new Browser();
27
+	 *   if( $browser->getBrowser() == Browser::BROWSER_FIREFOX && $browser->getVersion() >= 2 ) {
28
+	 *    echo 'You have FireFox version 2 or greater';
29
+	 *   }
30
+	 *
31
+	 * User Agents Sampled from: http://www.useragentstring.com/
32
+	 *
33
+	 * This implementation is based on the original work from Gary White
34
+	 * http://apptools.com/phptools/browser/
35
+	 *
36
+	 */
37
+	class Browser
38
+	{
39
+		private $_agent = '';
40
+		private $_browser_name = '';
41
+		private $_version = '';
42
+		private $_platform = '';
43
+		private $_os = '';
44
+		private $_is_aol = false;
45
+		private $_is_mobile = false;
46
+		private $_is_tablet = false;
47
+		private $_is_robot = false;
48
+		private $_is_facebook = false;
49
+		private $_aol_version = '';
50
+
51
+		const BROWSER_UNKNOWN = 'unknown';
52
+		const VERSION_UNKNOWN = 'unknown';
53
+
54
+		const BROWSER_OPERA = 'Opera'; // http://www.opera.com/
55
+		const BROWSER_OPERA_MINI = 'Opera Mini'; // http://www.opera.com/mini/
56
+		const BROWSER_WEBTV = 'WebTV'; // http://www.webtv.net/pc/
57
+		const BROWSER_EDGE = 'Edge'; // https://www.microsoft.com/edge
58
+		const BROWSER_IE = 'Internet Explorer'; // http://www.microsoft.com/ie/
59
+		const BROWSER_POCKET_IE = 'Pocket Internet Explorer'; // http://en.wikipedia.org/wiki/Internet_Explorer_Mobile
60
+		const BROWSER_KONQUEROR = 'Konqueror'; // http://www.konqueror.org/
61
+		const BROWSER_ICAB = 'iCab'; // http://www.icab.de/
62
+		const BROWSER_OMNIWEB = 'OmniWeb'; // http://www.omnigroup.com/applications/omniweb/
63
+		const BROWSER_FIREBIRD = 'Firebird'; // http://www.ibphoenix.com/
64
+		const BROWSER_FIREFOX = 'Firefox'; // http://www.mozilla.com/en-US/firefox/firefox.html
65
+		const BROWSER_ICEWEASEL = 'Iceweasel'; // http://www.geticeweasel.org/
66
+		const BROWSER_SHIRETOKO = 'Shiretoko'; // http://wiki.mozilla.org/Projects/shiretoko
67
+		const BROWSER_MOZILLA = 'Mozilla'; // http://www.mozilla.com/en-US/
68
+		const BROWSER_AMAYA = 'Amaya'; // http://www.w3.org/Amaya/
69
+		const BROWSER_LYNX = 'Lynx'; // http://en.wikipedia.org/wiki/Lynx
70
+		const BROWSER_SAFARI = 'Safari'; // http://apple.com
71
+		const BROWSER_IPHONE = 'iPhone'; // http://apple.com
72
+		const BROWSER_IPOD = 'iPod'; // http://apple.com
73
+		const BROWSER_IPAD = 'iPad'; // http://apple.com
74
+		const BROWSER_CHROME = 'Chrome'; // http://www.google.com/chrome
75
+		const BROWSER_ANDROID = 'Android'; // http://www.android.com/
76
+		const BROWSER_GOOGLEBOT = 'GoogleBot'; // http://en.wikipedia.org/wiki/Googlebot
77
+
78
+		const BROWSER_YANDEXBOT = 'YandexBot'; // http://yandex.com/bots
79
+		const BROWSER_YANDEXIMAGERESIZER_BOT = 'YandexImageResizer'; // http://yandex.com/bots
80
+		const BROWSER_YANDEXIMAGES_BOT = 'YandexImages'; // http://yandex.com/bots
81
+		const BROWSER_YANDEXVIDEO_BOT = 'YandexVideo'; // http://yandex.com/bots
82
+		const BROWSER_YANDEXMEDIA_BOT = 'YandexMedia'; // http://yandex.com/bots
83
+		const BROWSER_YANDEXBLOGS_BOT = 'YandexBlogs'; // http://yandex.com/bots
84
+		const BROWSER_YANDEXFAVICONS_BOT = 'YandexFavicons'; // http://yandex.com/bots
85
+		const BROWSER_YANDEXWEBMASTER_BOT = 'YandexWebmaster'; // http://yandex.com/bots
86
+		const BROWSER_YANDEXDIRECT_BOT = 'YandexDirect'; // http://yandex.com/bots
87
+		const BROWSER_YANDEXMETRIKA_BOT = 'YandexMetrika'; // http://yandex.com/bots
88
+		const BROWSER_YANDEXNEWS_BOT = 'YandexNews'; // http://yandex.com/bots
89
+		const BROWSER_YANDEXCATALOG_BOT = 'YandexCatalog'; // http://yandex.com/bots
90
+
91
+		const BROWSER_SLURP = 'Yahoo! Slurp'; // http://en.wikipedia.org/wiki/Yahoo!_Slurp
92
+		const BROWSER_W3CVALIDATOR = 'W3C Validator'; // http://validator.w3.org/
93
+		const BROWSER_BLACKBERRY = 'BlackBerry'; // http://www.blackberry.com/
94
+		const BROWSER_ICECAT = 'IceCat'; // http://en.wikipedia.org/wiki/GNU_IceCat
95
+		const BROWSER_NOKIA_S60 = 'Nokia S60 OSS Browser'; // http://en.wikipedia.org/wiki/Web_Browser_for_S60
96
+		const BROWSER_NOKIA = 'Nokia Browser'; // * all other WAP-based browsers on the Nokia Platform
97
+		const BROWSER_MSN = 'MSN Browser'; // http://explorer.msn.com/
98
+		const BROWSER_MSNBOT = 'MSN Bot'; // http://search.msn.com/msnbot.htm
99
+		const BROWSER_BINGBOT = 'Bing Bot'; // http://en.wikipedia.org/wiki/Bingbot
100
+		const BROWSER_VIVALDI = 'Vivalidi'; // https://vivaldi.com/
101
+		const BROWSER_YANDEX = 'Yandex'; // https://browser.yandex.ua/
102
+
103
+		const BROWSER_NETSCAPE_NAVIGATOR = 'Netscape Navigator'; // http://browser.netscape.com/ (DEPRECATED)
104
+		const BROWSER_GALEON = 'Galeon'; // http://galeon.sourceforge.net/ (DEPRECATED)
105
+		const BROWSER_NETPOSITIVE = 'NetPositive'; // http://en.wikipedia.org/wiki/NetPositive (DEPRECATED)
106
+		const BROWSER_PHOENIX = 'Phoenix'; // http://en.wikipedia.org/wiki/History_of_Mozilla_Firefox (DEPRECATED)
107
+		const BROWSER_PLAYSTATION = "PlayStation";
108
+		const BROWSER_SAMSUNG = "SamsungBrowser";
109
+		const BROWSER_SILK = "Silk";
110
+		const BROWSER_I_FRAME = "Iframely";
111
+		const BROWSER_COCOA = "CocoaRestClient";
112
+
113
+		const PLATFORM_UNKNOWN = 'unknown';
114
+		const PLATFORM_WINDOWS = 'Windows';
115
+		const PLATFORM_WINDOWS_CE = 'Windows CE';
116
+		const PLATFORM_APPLE = 'Apple';
117
+		const PLATFORM_LINUX = 'Linux';
118
+		const PLATFORM_OS2 = 'OS/2';
119
+		const PLATFORM_BEOS = 'BeOS';
120
+		const PLATFORM_IPHONE = 'iPhone';
121
+		const PLATFORM_IPOD = 'iPod';
122
+		const PLATFORM_IPAD = 'iPad';
123
+		const PLATFORM_BLACKBERRY = 'BlackBerry';
124
+		const PLATFORM_NOKIA = 'Nokia';
125
+		const PLATFORM_FREEBSD = 'FreeBSD';
126
+		const PLATFORM_OPENBSD = 'OpenBSD';
127
+		const PLATFORM_NETBSD = 'NetBSD';
128
+		const PLATFORM_SUNOS = 'SunOS';
129
+		const PLATFORM_OPENSOLARIS = 'OpenSolaris';
130
+		const PLATFORM_ANDROID = 'Android';
131
+		const PLATFORM_PLAYSTATION = "Sony PlayStation";
132
+		const PLATFORM_ROKU = "Roku";
133
+		const PLATFORM_APPLE_TV = "Apple TV";
134
+		const PLATFORM_TERMINAL = "Terminal";
135
+		const PLATFORM_FIRE_OS = "Fire OS";
136
+		const PLATFORM_SMART_TV = "SMART-TV";
137
+		const PLATFORM_CHROME_OS = "Chrome OS";
138
+		const PLATFORM_JAVA_ANDROID = "Java/Android";
139
+		const PLATFORM_POSTMAN = "Postman";
140
+		const PLATFORM_I_FRAME = "Iframely";
141
+
142
+		const OPERATING_SYSTEM_UNKNOWN = 'unknown';
143
+
144
+		/**
145
+		 * Class constructor
146
+		 */
147
+		public function __construct($userAgent = "")
148
+		{
149
+			$this->reset();
150
+			if ($userAgent != "") {
151
+				$this->setUserAgent($userAgent);
152
+			} else {
153
+				$this->determine();
154
+			}
155
+		}
156
+
157
+		/**
158
+		 * Reset all properties
159
+		 */
160
+		public function reset()
161
+		{
162
+			$this->_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : "";
163
+			$this->_browser_name = self::BROWSER_UNKNOWN;
164
+			$this->_version = self::VERSION_UNKNOWN;
165
+			$this->_platform = self::PLATFORM_UNKNOWN;
166
+			$this->_os = self::OPERATING_SYSTEM_UNKNOWN;
167
+			$this->_is_aol = false;
168
+			$this->_is_mobile = false;
169
+			$this->_is_tablet = false;
170
+			$this->_is_robot = false;
171
+			$this->_is_facebook = false;
172
+			$this->_aol_version = self::VERSION_UNKNOWN;
173
+		}
174
+
175
+		/**
176
+		 * Check to see if the specific browser is valid
177
+		 * @param string $browserName
178
+		 * @return bool True if the browser is the specified browser
179
+		 */
180
+		public function isBrowser($browserName)
181
+		{
182
+			return (0 == strcasecmp($this->_browser_name, trim($browserName)));
183
+		}
184
+
185
+		/**
186
+		 * The name of the browser.  All return types are from the class contants
187
+		 * @return string Name of the browser
188
+		 */
189
+		public function getBrowser()
190
+		{
191
+			return $this->_browser_name;
192
+		}
193
+
194
+		/**
195
+		 * Set the name of the browser
196
+		 * @param $browser string The name of the Browser
197
+		 */
198
+		public function setBrowser($browser)
199
+		{
200
+			$this->_browser_name = $browser;
201
+		}
202
+
203
+		/**
204
+		 * The name of the platform.  All return types are from the class contants
205
+		 * @return string Name of the browser
206
+		 */
207
+		public function getPlatform()
208
+		{
209
+			return $this->_platform;
210
+		}
211
+
212
+		/**
213
+		 * Set the name of the platform
214
+		 * @param string $platform The name of the Platform
215
+		 */
216
+		public function setPlatform($platform)
217
+		{
218
+			$this->_platform = $platform;
219
+		}
220
+
221
+		/**
222
+		 * The version of the browser.
223
+		 * @return string Version of the browser (will only contain alpha-numeric characters and a period)
224
+		 */
225
+		public function getVersion()
226
+		{
227
+			return $this->_version;
228
+		}
229
+
230
+		/**
231
+		 * Set the version of the browser
232
+		 * @param string $version The version of the Browser
233
+		 */
234
+		public function setVersion($version)
235
+		{
236
+			$this->_version = preg_replace('/[^0-9,.,a-z,A-Z-]/', '', $version);
237
+		}
238
+
239
+		/**
240
+		 * The version of AOL.
241
+		 * @return string Version of AOL (will only contain alpha-numeric characters and a period)
242
+		 */
243
+		public function getAolVersion()
244
+		{
245
+			return $this->_aol_version;
246
+		}
247
+
248
+		/**
249
+		 * Set the version of AOL
250
+		 * @param string $version The version of AOL
251
+		 */
252
+		public function setAolVersion($version)
253
+		{
254
+			$this->_aol_version = preg_replace('/[^0-9,.,a-z,A-Z]/', '', $version);
255
+		}
256
+
257
+		/**
258
+		 * Is the browser from AOL?
259
+		 * @return boolean True if the browser is from AOL otherwise false
260
+		 */
261
+		public function isAol()
262
+		{
263
+			return $this->_is_aol;
264
+		}
265
+
266
+		/**
267
+		 * Is the browser from a mobile device?
268
+		 * @return boolean True if the browser is from a mobile device otherwise false
269
+		 */
270
+		public function isMobile()
271
+		{
272
+			return $this->_is_mobile;
273
+		}
274
+
275
+		/**
276
+		 * Is the browser from a tablet device?
277
+		 * @return boolean True if the browser is from a tablet device otherwise false
278
+		 */
279
+		public function isTablet()
280
+		{
281
+			return $this->_is_tablet;
282
+		}
283
+
284
+		/**
285
+		 * Is the browser from a robot (ex Slurp,GoogleBot)?
286
+		 * @return boolean True if the browser is from a robot otherwise false
287
+		 */
288
+		public function isRobot()
289
+		{
290
+			return $this->_is_robot;
291
+		}
292
+
293
+		/**
294
+		 * Is the browser from facebook?
295
+		 * @return boolean True if the browser is from facebook otherwise false
296
+		 */
297
+		public function isFacebook()
298
+		{
299
+			return $this->_is_facebook;
300
+		}
301
+
302
+		/**
303
+		 * Set the browser to be from AOL
304
+		 * @param $isAol
305
+		 */
306
+		public function setAol($isAol)
307
+		{
308
+			$this->_is_aol = $isAol;
309
+		}
310
+
311
+		/**
312
+		 * Set the Browser to be mobile
313
+		 * @param boolean $value is the browser a mobile browser or not
314
+		 */
315
+		protected function setMobile($value = true)
316
+		{
317
+			$this->_is_mobile = $value;
318
+		}
319
+
320
+		/**
321
+		 * Set the Browser to be tablet
322
+		 * @param boolean $value is the browser a tablet browser or not
323
+		 */
324
+		protected function setTablet($value = true)
325
+		{
326
+			$this->_is_tablet = $value;
327
+		}
328
+
329
+		/**
330
+		 * Set the Browser to be a robot
331
+		 * @param boolean $value is the browser a robot or not
332
+		 */
333
+		protected function setRobot($value = true)
334
+		{
335
+			$this->_is_robot = $value;
336
+		}
337
+
338
+		/**
339
+		 * Set the Browser to be a Facebook request
340
+		 * @param boolean $value is the browser a robot or not
341
+		 */
342
+		protected function setFacebook($value = true)
343
+		{
344
+			$this->_is_facebook = $value;
345
+		}
346
+
347
+		/**
348
+		 * Get the user agent value in use to determine the browser
349
+		 * @return string The user agent from the HTTP header
350
+		 */
351
+		public function getUserAgent()
352
+		{
353
+			return $this->_agent;
354
+		}
355
+
356
+		/**
357
+		 * Set the user agent value (the construction will use the HTTP header value - this will overwrite it)
358
+		 * @param string $agent_string The value for the User Agent
359
+		 */
360
+		public function setUserAgent($agent_string)
361
+		{
362
+			$this->reset();
363
+			$this->_agent = $agent_string;
364
+			$this->determine();
365
+		}
366
+
367
+		/**
368
+		 * Used to determine if the browser is actually "chromeframe"
369
+		 * @since 1.7
370
+		 * @return boolean True if the browser is using chromeframe
371
+		 */
372
+		public function isChromeFrame()
373
+		{
374
+			return (strpos($this->_agent, "chromeframe") !== false);
375
+		}
376
+
377
+		/**
378
+		 * Returns a formatted string with a summary of the details of the browser.
379
+		 * @return string formatted string with a summary of the browser
380
+		 */
381
+		public function __toString()
382
+		{
383
+			return "<strong>Browser Name:</strong> {$this->getBrowser()}<br/>\n" .
384
+				"<strong>Browser Version:</strong> {$this->getVersion()}<br/>\n" .
385
+				"<strong>Browser User Agent String:</strong> {$this->getUserAgent()}<br/>\n" .
386
+				"<strong>Platform:</strong> {$this->getPlatform()}<br/>";
387
+		}
388
+
389
+		/**
390
+		 * Protected routine to calculate and determine what the browser is in use (including platform)
391
+		 */
392
+		protected function determine()
393
+		{
394
+			$this->checkPlatform();
395
+			$this->checkBrowsers();
396
+			$this->checkForAol();
397
+		}
398
+
399
+		/**
400
+		 * Protected routine to determine the browser type
401
+		 * @return boolean True if the browser was detected otherwise false
402
+		 */
403
+		protected function checkBrowsers()
404
+		{
405
+			return (
406
+				// well-known, well-used
407
+				// Special Notes:
408
+				// (1) Opera must be checked before FireFox due to the odd
409
+				//     user agents used in some older versions of Opera
410
+				// (2) WebTV is strapped onto Internet Explorer so we must
411
+				//     check for WebTV before IE
412
+				// (3) (deprecated) Galeon is based on Firefox and needs to be
413
+				//     tested before Firefox is tested
414
+				// (4) OmniWeb is based on Safari so OmniWeb check must occur
415
+				//     before Safari
416
+				// (5) Netscape 9+ is based on Firefox so Netscape checks
417
+				//     before FireFox are necessary
418
+				// (6) Vivalid is UA contains both Firefox and Chrome so Vivalid checks
419
+				//     before Firefox and Chrome
420
+				$this->checkBrowserWebTv() ||
421
+				$this->checkBrowserEdge() ||
422
+				$this->checkBrowserInternetExplorer() ||
423
+				$this->checkBrowserOpera() ||
424
+				$this->checkBrowserGaleon() ||
425
+				$this->checkBrowserNetscapeNavigator9Plus() ||
426
+				$this->checkBrowserVivaldi() ||
427
+				$this->checkBrowserYandex() ||
428
+				$this->checkBrowserFirefox() ||
429
+				$this->checkBrowserChrome() ||
430
+				$this->checkBrowserOmniWeb() ||
431
+
432
+				// common mobile
433
+				$this->checkBrowserAndroid() ||
434
+				$this->checkBrowseriPad() ||
435
+				$this->checkBrowseriPod() ||
436
+				$this->checkBrowseriPhone() ||
437
+				$this->checkBrowserBlackBerry() ||
438
+				$this->checkBrowserNokia() ||
439
+
440
+				// common bots
441
+				$this->checkBrowserGoogleBot() ||
442
+				$this->checkBrowserMSNBot() ||
443
+				$this->checkBrowserBingBot() ||
444
+				$this->checkBrowserSlurp() ||
445
+
446
+				// Yandex bots
447
+				$this->checkBrowserYandexBot() ||
448
+				$this->checkBrowserYandexImageResizerBot() ||
449
+				$this->checkBrowserYandexBlogsBot() ||
450
+				$this->checkBrowserYandexCatalogBot() ||
451
+				$this->checkBrowserYandexDirectBot() ||
452
+				$this->checkBrowserYandexFaviconsBot() ||
453
+				$this->checkBrowserYandexImagesBot() ||
454
+				$this->checkBrowserYandexMediaBot() ||
455
+				$this->checkBrowserYandexMetrikaBot() ||
456
+				$this->checkBrowserYandexNewsBot() ||
457
+				$this->checkBrowserYandexVideoBot() ||
458
+				$this->checkBrowserYandexWebmasterBot() ||
459
+
460
+				// check for facebook external hit when loading URL
461
+				$this->checkFacebookExternalHit() ||
462
+
463
+				// WebKit base check (post mobile and others)
464
+				$this->checkBrowserSamsung() ||
465
+				$this->checkBrowserSilk() ||
466
+				$this->checkBrowserSafari() ||
467
+
468
+				// everyone else
469
+				$this->checkBrowserNetPositive() ||
470
+				$this->checkBrowserFirebird() ||
471
+				$this->checkBrowserKonqueror() ||
472
+				$this->checkBrowserIcab() ||
473
+				$this->checkBrowserPhoenix() ||
474
+				$this->checkBrowserAmaya() ||
475
+				$this->checkBrowserLynx() ||
476
+				$this->checkBrowserShiretoko() ||
477
+				$this->checkBrowserIceCat() ||
478
+				$this->checkBrowserIceweasel() ||
479
+				$this->checkBrowserW3CValidator() ||
480
+				$this->checkBrowserPlayStation() ||
481
+				$this->checkBrowserIframely() ||
482
+				$this->checkBrowserCocoa() ||
483
+				$this->checkBrowserMozilla() /* Mozilla is such an open standard that you must check it last */
484
+
485
+
486
+			);
487
+		}
488
+
489
+		/**
490
+		 * Determine if the user is using a BlackBerry (last updated 1.7)
491
+		 * @return boolean True if the browser is the BlackBerry browser otherwise false
492
+		 */
493
+		protected function checkBrowserBlackBerry()
494
+		{
495
+			if (stripos($this->_agent, 'blackberry') !== false) {
496
+				$aresult = explode("/", stristr($this->_agent, "BlackBerry"));
497
+				if (isset($aresult[1])) {
498
+					$aversion = explode(' ', $aresult[1]);
499
+					$this->setVersion($aversion[0]);
500
+					$this->_browser_name = self::BROWSER_BLACKBERRY;
501
+					$this->setMobile(true);
502
+					return true;
503
+				}
504
+			}
505
+			return false;
506
+		}
507
+
508
+		/**
509
+		 * Determine if the user is using an AOL User Agent (last updated 1.7)
510
+		 * @return boolean True if the browser is from AOL otherwise false
511
+		 */
512
+		protected function checkForAol()
513
+		{
514
+			$this->setAol(false);
515
+			$this->setAolVersion(self::VERSION_UNKNOWN);
516
+
517
+			if (stripos($this->_agent, 'aol') !== false) {
518
+				$aversion = explode(' ', stristr($this->_agent, 'AOL'));
519
+				if (isset($aversion[1])) {
520
+					$this->setAol(true);
521
+					$this->setAolVersion(preg_replace('/[^0-9\.a-z]/i', '', $aversion[1]));
522
+					return true;
523
+				}
524
+			}
525
+			return false;
526
+		}
527
+
528
+		/**
529
+		 * Determine if the browser is the GoogleBot or not (last updated 1.7)
530
+		 * @return boolean True if the browser is the GoogletBot otherwise false
531
+		 */
532
+		protected function checkBrowserGoogleBot()
533
+		{
534
+			if (stripos($this->_agent, 'googlebot') !== false) {
535
+				$aresult = explode('/', stristr($this->_agent, 'googlebot'));
536
+				if (isset($aresult[1])) {
537
+					$aversion = explode(' ', $aresult[1]);
538
+					$this->setVersion(str_replace(';', '', $aversion[0]));
539
+					$this->_browser_name = self::BROWSER_GOOGLEBOT;
540
+					$this->setRobot(true);
541
+					return true;
542
+				}
543
+			}
544
+			return false;
545
+		}
546
+
547
+		/**
548
+		 * Determine if the browser is the YandexBot or not
549
+		 * @return boolean True if the browser is the YandexBot otherwise false
550
+		 */
551
+		protected function checkBrowserYandexBot()
552
+		{
553
+			if (stripos($this->_agent, 'YandexBot') !== false) {
554
+				$aresult = explode('/', stristr($this->_agent, 'YandexBot'));
555
+				if (isset($aresult[1])) {
556
+					$aversion = explode(' ', $aresult[1]);
557
+					$this->setVersion(str_replace(';', '', $aversion[0]));
558
+					$this->_browser_name = self::BROWSER_YANDEXBOT;
559
+					$this->setRobot(true);
560
+					return true;
561
+				}
562
+			}
563
+			return false;
564
+		}
565
+
566
+		/**
567
+		 * Determine if the browser is the YandexImageResizer or not
568
+		 * @return boolean True if the browser is the YandexImageResizer otherwise false
569
+		 */
570
+		protected function checkBrowserYandexImageResizerBot()
571
+		{
572
+			if (stripos($this->_agent, 'YandexImageResizer') !== false) {
573
+				$aresult = explode('/', stristr($this->_agent, 'YandexImageResizer'));
574
+				if (isset($aresult[1])) {
575
+					$aversion = explode(' ', $aresult[1]);
576
+					$this->setVersion(str_replace(';', '', $aversion[0]));
577
+					$this->_browser_name = self::BROWSER_YANDEXIMAGERESIZER_BOT;
578
+					$this->setRobot(true);
579
+					return true;
580
+				}
581
+			}
582
+			return false;
583
+		}
584
+
585
+		/**
586
+		 * Determine if the browser is the YandexCatalog or not
587
+		 * @return boolean True if the browser is the YandexCatalog otherwise false
588
+		 */
589
+		protected function checkBrowserYandexCatalogBot()
590
+		{
591
+			if (stripos($this->_agent, 'YandexCatalog') !== false) {
592
+				$aresult = explode('/', stristr($this->_agent, 'YandexCatalog'));
593
+				if (isset($aresult[1])) {
594
+					$aversion = explode(' ', $aresult[1]);
595
+					$this->setVersion(str_replace(';', '', $aversion[0]));
596
+					$this->_browser_name = self::BROWSER_YANDEXCATALOG_BOT;
597
+					$this->setRobot(true);
598
+					return true;
599
+				}
600
+			}
601
+			return false;
602
+		}
603
+
604
+		/**
605
+		 * Determine if the browser is the YandexNews or not
606
+		 * @return boolean True if the browser is the YandexNews otherwise false
607
+		 */
608
+		protected function checkBrowserYandexNewsBot()
609
+		{
610
+			if (stripos($this->_agent, 'YandexNews') !== false) {
611
+				$aresult = explode('/', stristr($this->_agent, 'YandexNews'));
612
+				if (isset($aresult[1])) {
613
+					$aversion = explode(' ', $aresult[1]);
614
+					$this->setVersion(str_replace(';', '', $aversion[0]));
615
+					$this->_browser_name = self::BROWSER_YANDEXNEWS_BOT;
616
+					$this->setRobot(true);
617
+					return true;
618
+				}
619
+			}
620
+			return false;
621
+		}
622
+
623
+		/**
624
+		 * Determine if the browser is the YandexMetrika or not
625
+		 * @return boolean True if the browser is the YandexMetrika otherwise false
626
+		 */
627
+		protected function checkBrowserYandexMetrikaBot()
628
+		{
629
+			if (stripos($this->_agent, 'YandexMetrika') !== false) {
630
+				$aresult = explode('/', stristr($this->_agent, 'YandexMetrika'));
631
+				if (isset($aresult[1])) {
632
+					$aversion = explode(' ', $aresult[1]);
633
+					$this->setVersion(str_replace(';', '', $aversion[0]));
634
+					$this->_browser_name = self::BROWSER_YANDEXMETRIKA_BOT;
635
+					$this->setRobot(true);
636
+					return true;
637
+				}
638
+			}
639
+			return false;
640
+		}
641
+
642
+		/**
643
+		 * Determine if the browser is the YandexDirect or not
644
+		 * @return boolean True if the browser is the YandexDirect otherwise false
645
+		 */
646
+		protected function checkBrowserYandexDirectBot()
647
+		{
648
+			if (stripos($this->_agent, 'YandexDirect') !== false) {
649
+				$aresult = explode('/', stristr($this->_agent, 'YandexDirect'));
650
+				if (isset($aresult[1])) {
651
+					$aversion = explode(' ', $aresult[1]);
652
+					$this->setVersion(str_replace(';', '', $aversion[0]));
653
+					$this->_browser_name = self::BROWSER_YANDEXDIRECT_BOT;
654
+					$this->setRobot(true);
655
+					return true;
656
+				}
657
+			}
658
+			return false;
659
+		}
660
+
661
+		/**
662
+		 * Determine if the browser is the YandexWebmaster or not
663
+		 * @return boolean True if the browser is the YandexWebmaster otherwise false
664
+		 */
665
+		protected function checkBrowserYandexWebmasterBot()
666
+		{
667
+			if (stripos($this->_agent, 'YandexWebmaster') !== false) {
668
+				$aresult = explode('/', stristr($this->_agent, 'YandexWebmaster'));
669
+				if (isset($aresult[1])) {
670
+					$aversion = explode(' ', $aresult[1]);
671
+					$this->setVersion(str_replace(';', '', $aversion[0]));
672
+					$this->_browser_name = self::BROWSER_YANDEXWEBMASTER_BOT;
673
+					$this->setRobot(true);
674
+					return true;
675
+				}
676
+			}
677
+			return false;
678
+		}
679
+
680
+		/**
681
+		 * Determine if the browser is the YandexFavicons or not
682
+		 * @return boolean True if the browser is the YandexFavicons otherwise false
683
+		 */
684
+		protected function checkBrowserYandexFaviconsBot()
685
+		{
686
+			if (stripos($this->_agent, 'YandexFavicons') !== false) {
687
+				$aresult = explode('/', stristr($this->_agent, 'YandexFavicons'));
688
+				if (isset($aresult[1])) {
689
+					$aversion = explode(' ', $aresult[1]);
690
+					$this->setVersion(str_replace(';', '', $aversion[0]));
691
+					$this->_browser_name = self::BROWSER_YANDEXFAVICONS_BOT;
692
+					$this->setRobot(true);
693
+					return true;
694
+				}
695
+			}
696
+			return false;
697
+		}
698
+
699
+		/**
700
+		 * Determine if the browser is the YandexBlogs or not
701
+		 * @return boolean True if the browser is the YandexBlogs otherwise false
702
+		 */
703
+		protected function checkBrowserYandexBlogsBot()
704
+		{
705
+			if (stripos($this->_agent, 'YandexBlogs') !== false) {
706
+				$aresult = explode('/', stristr($this->_agent, 'YandexBlogs'));
707
+				if (isset($aresult[1])) {
708
+					$aversion = explode(' ', $aresult[1]);
709
+					$this->setVersion(str_replace(';', '', $aversion[0]));
710
+					$this->_browser_name = self::BROWSER_YANDEXBLOGS_BOT;
711
+					$this->setRobot(true);
712
+					return true;
713
+				}
714
+			}
715
+			return false;
716
+		}
717
+
718
+		/**
719
+		 * Determine if the browser is the YandexMedia or not
720
+		 * @return boolean True if the browser is the YandexMedia otherwise false
721
+		 */
722
+		protected function checkBrowserYandexMediaBot()
723
+		{
724
+			if (stripos($this->_agent, 'YandexMedia') !== false) {
725
+				$aresult = explode('/', stristr($this->_agent, 'YandexMedia'));
726
+				if (isset($aresult[1])) {
727
+					$aversion = explode(' ', $aresult[1]);
728
+					$this->setVersion(str_replace(';', '', $aversion[0]));
729
+					$this->_browser_name = self::BROWSER_YANDEXMEDIA_BOT;
730
+					$this->setRobot(true);
731
+					return true;
732
+				}
733
+			}
734
+			return false;
735
+		}
736
+
737
+		/**
738
+		 * Determine if the browser is the YandexVideo or not
739
+		 * @return boolean True if the browser is the YandexVideo otherwise false
740
+		 */
741
+		protected function checkBrowserYandexVideoBot()
742
+		{
743
+			if (stripos($this->_agent, 'YandexVideo') !== false) {
744
+				$aresult = explode('/', stristr($this->_agent, 'YandexVideo'));
745
+				if (isset($aresult[1])) {
746
+					$aversion = explode(' ', $aresult[1]);
747
+					$this->setVersion(str_replace(';', '', $aversion[0]));
748
+					$this->_browser_name = self::BROWSER_YANDEXVIDEO_BOT;
749
+					$this->setRobot(true);
750
+					return true;
751
+				}
752
+			}
753
+			return false;
754
+		}
755
+
756
+		/**
757
+		 * Determine if the browser is the YandexImages or not
758
+		 * @return boolean True if the browser is the YandexImages otherwise false
759
+		 */
760
+		protected function checkBrowserYandexImagesBot()
761
+		{
762
+			if (stripos($this->_agent, 'YandexImages') !== false) {
763
+				$aresult = explode('/', stristr($this->_agent, 'YandexImages'));
764
+				if (isset($aresult[1])) {
765
+					$aversion = explode(' ', $aresult[1]);
766
+					$this->setVersion(str_replace(';', '', $aversion[0]));
767
+					$this->_browser_name = self::BROWSER_YANDEXIMAGES_BOT;
768
+					$this->setRobot(true);
769
+					return true;
770
+				}
771
+			}
772
+			return false;
773
+		}
774
+
775
+		/**
776
+		 * Determine if the browser is the MSNBot or not (last updated 1.9)
777
+		 * @return boolean True if the browser is the MSNBot otherwise false
778
+		 */
779
+		protected function checkBrowserMSNBot()
780
+		{
781
+			if (stripos($this->_agent, "msnbot") !== false) {
782
+				$aresult = explode("/", stristr($this->_agent, "msnbot"));
783
+				if (isset($aresult[1])) {
784
+					$aversion = explode(" ", $aresult[1]);
785
+					$this->setVersion(str_replace(";", "", $aversion[0]));
786
+					$this->_browser_name = self::BROWSER_MSNBOT;
787
+					$this->setRobot(true);
788
+					return true;
789
+				}
790
+			}
791
+			return false;
792
+		}
793
+
794
+		/**
795
+		 * Determine if the browser is the BingBot or not (last updated 1.9)
796
+		 * @return boolean True if the browser is the BingBot otherwise false
797
+		 */
798
+		protected function checkBrowserBingBot()
799
+		{
800
+			if (stripos($this->_agent, "bingbot") !== false) {
801
+				$aresult = explode("/", stristr($this->_agent, "bingbot"));
802
+				if (isset($aresult[1])) {
803
+					$aversion = explode(" ", $aresult[1]);
804
+					$this->setVersion(str_replace(";", "", $aversion[0]));
805
+					$this->_browser_name = self::BROWSER_BINGBOT;
806
+					$this->setRobot(true);
807
+					return true;
808
+				}
809
+			}
810
+			return false;
811
+		}
812
+
813
+		/**
814
+		 * Determine if the browser is the W3C Validator or not (last updated 1.7)
815
+		 * @return boolean True if the browser is the W3C Validator otherwise false
816
+		 */
817
+		protected function checkBrowserW3CValidator()
818
+		{
819
+			if (stripos($this->_agent, 'W3C-checklink') !== false) {
820
+				$aresult = explode('/', stristr($this->_agent, 'W3C-checklink'));
821
+				if (isset($aresult[1])) {
822
+					$aversion = explode(' ', $aresult[1]);
823
+					$this->setVersion($aversion[0]);
824
+					$this->_browser_name = self::BROWSER_W3CVALIDATOR;
825
+					return true;
826
+				}
827
+			} else if (stripos($this->_agent, 'W3C_Validator') !== false) {
828
+				// Some of the Validator versions do not delineate w/ a slash - add it back in
829
+				$ua = str_replace("W3C_Validator ", "W3C_Validator/", $this->_agent);
830
+				$aresult = explode('/', stristr($ua, 'W3C_Validator'));
831
+				if (isset($aresult[1])) {
832
+					$aversion = explode(' ', $aresult[1]);
833
+					$this->setVersion($aversion[0]);
834
+					$this->_browser_name = self::BROWSER_W3CVALIDATOR;
835
+					return true;
836
+				}
837
+			} else if (stripos($this->_agent, 'W3C-mobileOK') !== false) {
838
+				$this->_browser_name = self::BROWSER_W3CVALIDATOR;
839
+				$this->setMobile(true);
840
+				return true;
841
+			}
842
+			return false;
843
+		}
844
+
845
+		/**
846
+		 * Determine if the browser is the Yahoo! Slurp Robot or not (last updated 1.7)
847
+		 * @return boolean True if the browser is the Yahoo! Slurp Robot otherwise false
848
+		 */
849
+		protected function checkBrowserSlurp()
850
+		{
851
+			if (stripos($this->_agent, 'slurp') !== false) {
852
+				$aresult = explode('/', stristr($this->_agent, 'Slurp'));
853
+				if (isset($aresult[1])) {
854
+					$aversion = explode(' ', $aresult[1]);
855
+					$this->setVersion($aversion[0]);
856
+					$this->_browser_name = self::BROWSER_SLURP;
857
+					$this->setRobot(true);
858
+					$this->setMobile(false);
859
+					return true;
860
+				}
861
+			}
862
+			return false;
863
+		}
864
+
865
+		/**
866
+		 * Determine if the browser is Edge or not
867
+		 * @return boolean True if the browser is Edge otherwise false
868
+		 */
869
+		protected function checkBrowserEdge()
870
+		{
871
+			if (stripos($this->_agent, 'Edge/') !== false) {
872
+				$aresult = explode('/', stristr($this->_agent, 'Edge'));
873
+				if (isset($aresult[1])) {
874
+					$aversion = explode(' ', $aresult[1]);
875
+					$this->setVersion($aversion[0]);
876
+					$this->setBrowser(self::BROWSER_EDGE);
877
+					if (stripos($this->_agent, 'Windows Phone') !== false || stripos($this->_agent, 'Android') !== false) {
878
+						$this->setMobile(true);
879
+					}
880
+					return true;
881
+				}
882
+			}
883
+			return false;
884
+		}
885
+
886
+		/**
887
+		 * Determine if the browser is Internet Explorer or not (last updated 1.7)
888
+		 * @return boolean True if the browser is Internet Explorer otherwise false
889
+		 */
890
+		protected function checkBrowserInternetExplorer()
891
+		{
892
+			//  Test for IE11
893
+			if (stripos($this->_agent, 'Trident/7.0; rv:11.0') !== false) {
894
+				$this->setBrowser(self::BROWSER_IE);
895
+				$this->setVersion('11.0');
896
+				return true;
897
+			} // Test for v1 - v1.5 IE
898
+			else if (stripos($this->_agent, 'microsoft internet explorer') !== false) {
899
+				$this->setBrowser(self::BROWSER_IE);
900
+				$this->setVersion('1.0');
901
+				$aresult = stristr($this->_agent, '/');
902
+				if (preg_match('/308|425|426|474|0b1/i', $aresult)) {
903
+					$this->setVersion('1.5');
904
+				}
905
+				return true;
906
+			} // Test for versions > 1.5
907
+			else if (stripos($this->_agent, 'msie') !== false && stripos($this->_agent, 'opera') === false) {
908
+				// See if the browser is the odd MSN Explorer
909
+				if (stripos($this->_agent, 'msnb') !== false) {
910
+					$aresult = explode(' ', stristr(str_replace(';', '; ', $this->_agent), 'MSN'));
911
+					if (isset($aresult[1])) {
912
+						$this->setBrowser(self::BROWSER_MSN);
913
+						$this->setVersion(str_replace(array('(', ')', ';'), '', $aresult[1]));
914
+						return true;
915
+					}
916
+				}
917
+				$aresult = explode(' ', stristr(str_replace(';', '; ', $this->_agent), 'msie'));
918
+				if (isset($aresult[1])) {
919
+					$this->setBrowser(self::BROWSER_IE);
920
+					$this->setVersion(str_replace(array('(', ')', ';'), '', $aresult[1]));
921
+					if(preg_match('#trident/([0-9\.]+);#i', $this->_agent, $aresult)){
922
+						if($aresult[1] == '3.1'){
923
+							$this->setVersion('7.0');
924
+						}
925
+						else if($aresult[1] == '4.0'){
926
+							$this->setVersion('8.0');
927
+						}
928
+						else if($aresult[1] == '5.0'){
929
+							$this->setVersion('9.0');
930
+						}
931
+						else if($aresult[1] == '6.0'){
932
+							$this->setVersion('10.0');
933
+						}
934
+						else if($aresult[1] == '7.0'){
935
+							$this->setVersion('11.0');
936
+						}
937
+						else if($aresult[1] == '8.0'){
938
+							$this->setVersion('11.0');
939
+						}
940
+					}
941
+					if(stripos($this->_agent, 'IEMobile') !== false) {
942
+						$this->setBrowser(self::BROWSER_POCKET_IE);
943
+						$this->setMobile(true);
944
+					}
945
+					return true;
946
+				}
947
+			} // Test for versions > IE 10
948
+			else if (stripos($this->_agent, 'trident') !== false) {
949
+				$this->setBrowser(self::BROWSER_IE);
950
+				$result = explode('rv:', $this->_agent);
951
+				if (isset($result[1])) {
952
+					$this->setVersion(preg_replace('/[^0-9.]+/', '', $result[1]));
953
+					$this->_agent = str_replace(array("Mozilla", "Gecko"), "MSIE", $this->_agent);
954
+				}
955
+			} // Test for Pocket IE
956
+			else if (stripos($this->_agent, 'mspie') !== false || stripos($this->_agent, 'pocket') !== false) {
957
+				$aresult = explode(' ', stristr($this->_agent, 'mspie'));
958
+				if (isset($aresult[1])) {
959
+					$this->setPlatform(self::PLATFORM_WINDOWS_CE);
960
+					$this->setBrowser(self::BROWSER_POCKET_IE);
961
+					$this->setMobile(true);
962
+
963
+					if (stripos($this->_agent, 'mspie') !== false) {
964
+						$this->setVersion($aresult[1]);
965
+					} else {
966
+						$aversion = explode('/', $this->_agent);
967
+						if (isset($aversion[1])) {
968
+							$this->setVersion($aversion[1]);
969
+						}
970
+					}
971
+					return true;
972
+				}
973
+			}
974
+			return false;
975
+		}
976
+
977
+		/**
978
+		 * Determine if the browser is Opera or not (last updated 1.7)
979
+		 * @return boolean True if the browser is Opera otherwise false
980
+		 */
981
+		protected function checkBrowserOpera()
982
+		{
983
+			if (stripos($this->_agent, 'opera mini') !== false) {
984
+				$resultant = stristr($this->_agent, 'opera mini');
985
+				if (preg_match('/\//', $resultant)) {
986
+					$aresult = explode('/', $resultant);
987
+					if (isset($aresult[1])) {
988
+						$aversion = explode(' ', $aresult[1]);
989
+						$this->setVersion($aversion[0]);
990
+					}
991
+				} else {
992
+					$aversion = explode(' ', stristr($resultant, 'opera mini'));
993
+					if (isset($aversion[1])) {
994
+						$this->setVersion($aversion[1]);
995
+					}
996
+				}
997
+				$this->_browser_name = self::BROWSER_OPERA_MINI;
998
+				$this->setMobile(true);
999
+				return true;
1000
+			} else if (stripos($this->_agent, 'opera') !== false) {
1001
+				$resultant = stristr($this->_agent, 'opera');
1002
+				if (preg_match('/Version\/(1*.*)$/', $resultant, $matches)) {
1003
+					$this->setVersion($matches[1]);
1004
+				} else if (preg_match('/\//', $resultant)) {
1005
+					$aresult = explode('/', str_replace("(", " ", $resultant));
1006
+					if (isset($aresult[1])) {
1007
+						$aversion = explode(' ', $aresult[1]);
1008
+						$this->setVersion($aversion[0]);
1009
+					}
1010
+				} else {
1011
+					$aversion = explode(' ', stristr($resultant, 'opera'));
1012
+					$this->setVersion(isset($aversion[1]) ? $aversion[1] : "");
1013
+				}
1014
+				if (stripos($this->_agent, 'Opera Mobi') !== false) {
1015
+					$this->setMobile(true);
1016
+				}
1017
+				$this->_browser_name = self::BROWSER_OPERA;
1018
+				return true;
1019
+			} else if (stripos($this->_agent, 'OPR') !== false) {
1020
+				$resultant = stristr($this->_agent, 'OPR');
1021
+				if (preg_match('/\//', $resultant)) {
1022
+					$aresult = explode('/', str_replace("(", " ", $resultant));
1023
+					if (isset($aresult[1])) {
1024
+						$aversion = explode(' ', $aresult[1]);
1025
+						$this->setVersion($aversion[0]);
1026
+					}
1027
+				}
1028
+				if (stripos($this->_agent, 'Mobile') !== false) {
1029
+					$this->setMobile(true);
1030
+				}
1031
+				$this->_browser_name = self::BROWSER_OPERA;
1032
+				return true;
1033
+			}
1034
+			return false;
1035
+		}
1036
+
1037
+		/**
1038
+		 * Determine if the browser is Chrome or not (last updated 1.7)
1039
+		 * @return boolean True if the browser is Chrome otherwise false
1040
+		 */
1041
+		protected function checkBrowserChrome()
1042
+		{
1043
+			if (stripos($this->_agent, 'Chrome') !== false) {
1044
+				$aresult = explode('/', stristr($this->_agent, 'Chrome'));
1045
+				if (isset($aresult[1])) {
1046
+					$aversion = explode(' ', $aresult[1]);
1047
+					$this->setVersion($aversion[0]);
1048
+					$this->setBrowser(self::BROWSER_CHROME);
1049
+					//Chrome on Android
1050
+					if (stripos($this->_agent, 'Android') !== false) {
1051
+						if (stripos($this->_agent, 'Mobile') !== false) {
1052
+							$this->setMobile(true);
1053
+						} else {
1054
+							$this->setTablet(true);
1055
+						}
1056
+					}
1057
+					return true;
1058
+				}
1059
+			}
1060
+			return false;
1061
+		}
1062
+
1063
+
1064
+		/**
1065
+		 * Determine if the browser is WebTv or not (last updated 1.7)
1066
+		 * @return boolean True if the browser is WebTv otherwise false
1067
+		 */
1068
+		protected function checkBrowserWebTv()
1069
+		{
1070
+			if (stripos($this->_agent, 'webtv') !== false) {
1071
+				$aresult = explode('/', stristr($this->_agent, 'webtv'));
1072
+				if (isset($aresult[1])) {
1073
+					$aversion = explode(' ', $aresult[1]);
1074
+					$this->setVersion($aversion[0]);
1075
+					$this->setBrowser(self::BROWSER_WEBTV);
1076
+					return true;
1077
+				}
1078
+			}
1079
+			return false;
1080
+		}
1081
+
1082
+		/**
1083
+		 * Determine if the browser is NetPositive or not (last updated 1.7)
1084
+		 * @return boolean True if the browser is NetPositive otherwise false
1085
+		 */
1086
+		protected function checkBrowserNetPositive()
1087
+		{
1088
+			if (stripos($this->_agent, 'NetPositive') !== false) {
1089
+				$aresult = explode('/', stristr($this->_agent, 'NetPositive'));
1090
+				if (isset($aresult[1])) {
1091
+					$aversion = explode(' ', $aresult[1]);
1092
+					$this->setVersion(str_replace(array('(', ')', ';'), '', $aversion[0]));
1093
+					$this->setBrowser(self::BROWSER_NETPOSITIVE);
1094
+					return true;
1095
+				}
1096
+			}
1097
+			return false;
1098
+		}
1099
+
1100
+		/**
1101
+		 * Determine if the browser is Galeon or not (last updated 1.7)
1102
+		 * @return boolean True if the browser is Galeon otherwise false
1103
+		 */
1104
+		protected function checkBrowserGaleon()
1105
+		{
1106
+			if (stripos($this->_agent, 'galeon') !== false) {
1107
+				$aresult = explode(' ', stristr($this->_agent, 'galeon'));
1108
+				$aversion = explode('/', $aresult[0]);
1109
+				if (isset($aversion[1])) {
1110
+					$this->setVersion($aversion[1]);
1111
+					$this->setBrowser(self::BROWSER_GALEON);
1112
+					return true;
1113
+				}
1114
+			}
1115
+			return false;
1116
+		}
1117
+
1118
+		/**
1119
+		 * Determine if the browser is Konqueror or not (last updated 1.7)
1120
+		 * @return boolean True if the browser is Konqueror otherwise false
1121
+		 */
1122
+		protected function checkBrowserKonqueror()
1123
+		{
1124
+			if (stripos($this->_agent, 'Konqueror') !== false) {
1125
+				$aresult = explode(' ', stristr($this->_agent, 'Konqueror'));
1126
+				$aversion = explode('/', $aresult[0]);
1127
+				if (isset($aversion[1])) {
1128
+					$this->setVersion($aversion[1]);
1129
+					$this->setBrowser(self::BROWSER_KONQUEROR);
1130
+					return true;
1131
+				}
1132
+			}
1133
+			return false;
1134
+		}
1135
+
1136
+		/**
1137
+		 * Determine if the browser is iCab or not (last updated 1.7)
1138
+		 * @return boolean True if the browser is iCab otherwise false
1139
+		 */
1140
+		protected function checkBrowserIcab()
1141
+		{
1142
+			if (stripos($this->_agent, 'icab') !== false) {
1143
+				$aversion = explode(' ', stristr(str_replace('/', ' ', $this->_agent), 'icab'));
1144
+				if (isset($aversion[1])) {
1145
+					$this->setVersion($aversion[1]);
1146
+					$this->setBrowser(self::BROWSER_ICAB);
1147
+					return true;
1148
+				}
1149
+			}
1150
+			return false;
1151
+		}
1152
+
1153
+		/**
1154
+		 * Determine if the browser is OmniWeb or not (last updated 1.7)
1155
+		 * @return boolean True if the browser is OmniWeb otherwise false
1156
+		 */
1157
+		protected function checkBrowserOmniWeb()
1158
+		{
1159
+			if (stripos($this->_agent, 'omniweb') !== false) {
1160
+				$aresult = explode('/', stristr($this->_agent, 'omniweb'));
1161
+				$aversion = explode(' ', isset($aresult[1]) ? $aresult[1] : "");
1162
+				$this->setVersion($aversion[0]);
1163
+				$this->setBrowser(self::BROWSER_OMNIWEB);
1164
+				return true;
1165
+			}
1166
+			return false;
1167
+		}
1168
+
1169
+		/**
1170
+		 * Determine if the browser is Phoenix or not (last updated 1.7)
1171
+		 * @return boolean True if the browser is Phoenix otherwise false
1172
+		 */
1173
+		protected function checkBrowserPhoenix()
1174
+		{
1175
+			if (stripos($this->_agent, 'Phoenix') !== false) {
1176
+				$aversion = explode('/', stristr($this->_agent, 'Phoenix'));
1177
+				if (isset($aversion[1])) {
1178
+					$this->setVersion($aversion[1]);
1179
+					$this->setBrowser(self::BROWSER_PHOENIX);
1180
+					return true;
1181
+				}
1182
+			}
1183
+			return false;
1184
+		}
1185
+
1186
+		/**
1187
+		 * Determine if the browser is Firebird or not (last updated 1.7)
1188
+		 * @return boolean True if the browser is Firebird otherwise false
1189
+		 */
1190
+		protected function checkBrowserFirebird()
1191
+		{
1192
+			if (stripos($this->_agent, 'Firebird') !== false) {
1193
+				$aversion = explode('/', stristr($this->_agent, 'Firebird'));
1194
+				if (isset($aversion[1])) {
1195
+					$this->setVersion($aversion[1]);
1196
+					$this->setBrowser(self::BROWSER_FIREBIRD);
1197
+					return true;
1198
+				}
1199
+			}
1200
+			return false;
1201
+		}
1202
+
1203
+		/**
1204
+		 * Determine if the browser is Netscape Navigator 9+ or not (last updated 1.7)
1205
+		 * NOTE: (http://browser.netscape.com/ - Official support ended on March 1st, 2008)
1206
+		 * @return boolean True if the browser is Netscape Navigator 9+ otherwise false
1207
+		 */
1208
+		protected function checkBrowserNetscapeNavigator9Plus()
1209
+		{
1210
+			if (stripos($this->_agent, 'Firefox') !== false && preg_match('/Navigator\/([^ ]*)/i', $this->_agent, $matches)) {
1211
+				$this->setVersion($matches[1]);
1212
+				$this->setBrowser(self::BROWSER_NETSCAPE_NAVIGATOR);
1213
+				return true;
1214
+			} else if (stripos($this->_agent, 'Firefox') === false && preg_match('/Netscape6?\/([^ ]*)/i', $this->_agent, $matches)) {
1215
+				$this->setVersion($matches[1]);
1216
+				$this->setBrowser(self::BROWSER_NETSCAPE_NAVIGATOR);
1217
+				return true;
1218
+			}
1219
+			return false;
1220
+		}
1221
+
1222
+		/**
1223
+		 * Determine if the browser is Shiretoko or not (https://wiki.mozilla.org/Projects/shiretoko) (last updated 1.7)
1224
+		 * @return boolean True if the browser is Shiretoko otherwise false
1225
+		 */
1226
+		protected function checkBrowserShiretoko()
1227
+		{
1228
+			if (stripos($this->_agent, 'Mozilla') !== false && preg_match('/Shiretoko\/([^ ]*)/i', $this->_agent, $matches)) {
1229
+				$this->setVersion($matches[1]);
1230
+				$this->setBrowser(self::BROWSER_SHIRETOKO);
1231
+				return true;
1232
+			}
1233
+			return false;
1234
+		}
1235
+
1236
+		/**
1237
+		 * Determine if the browser is Ice Cat or not (http://en.wikipedia.org/wiki/GNU_IceCat) (last updated 1.7)
1238
+		 * @return boolean True if the browser is Ice Cat otherwise false
1239
+		 */
1240
+		protected function checkBrowserIceCat()
1241
+		{
1242
+			if (stripos($this->_agent, 'Mozilla') !== false && preg_match('/IceCat\/([^ ]*)/i', $this->_agent, $matches)) {
1243
+				$this->setVersion($matches[1]);
1244
+				$this->setBrowser(self::BROWSER_ICECAT);
1245
+				return true;
1246
+			}
1247
+			return false;
1248
+		}
1249
+
1250
+		/**
1251
+		 * Determine if the browser is Nokia or not (last updated 1.7)
1252
+		 * @return boolean True if the browser is Nokia otherwise false
1253
+		 */
1254
+		protected function checkBrowserNokia()
1255
+		{
1256
+			if (preg_match("/Nokia([^\/]+)\/([^ SP]+)/i", $this->_agent, $matches)) {
1257
+				$this->setVersion($matches[2]);
1258
+				if (stripos($this->_agent, 'Series60') !== false || strpos($this->_agent, 'S60') !== false) {
1259
+					$this->setBrowser(self::BROWSER_NOKIA_S60);
1260
+				} else {
1261
+					$this->setBrowser(self::BROWSER_NOKIA);
1262
+				}
1263
+				$this->setMobile(true);
1264
+				return true;
1265
+			}
1266
+			return false;
1267
+		}
1268
+
1269
+		/**
1270
+		 * Determine if the browser is Firefox or not (last updated 1.7)
1271
+		 * @return boolean True if the browser is Firefox otherwise false
1272
+		 */
1273
+		protected function checkBrowserFirefox()
1274
+		{
1275
+			if (stripos($this->_agent, 'safari') === false) {
1276
+				if (preg_match("/Firefox[\/ \(]([^ ;\)]+)/i", $this->_agent, $matches)) {
1277
+					$this->setVersion($matches[1]);
1278
+					$this->setBrowser(self::BROWSER_FIREFOX);
1279
+					//Firefox on Android
1280
+					if (stripos($this->_agent, 'Android') !== false) {
1281
+						if (stripos($this->_agent, 'Mobile') !== false) {
1282
+							$this->setMobile(true);
1283
+						} else {
1284
+							$this->setTablet(true);
1285
+						}
1286
+					}
1287
+					return true;
1288
+				} else if (preg_match("/Firefox$/i", $this->_agent, $matches)) {
1289
+					$this->setVersion("");
1290
+					$this->setBrowser(self::BROWSER_FIREFOX);
1291
+					return true;
1292
+				}
1293
+			}
1294
+			return false;
1295
+		}
1296
+
1297
+		/**
1298
+		 * Determine if the browser is Firefox or not (last updated 1.7)
1299
+		 * @return boolean True if the browser is Firefox otherwise false
1300
+		 */
1301
+		protected function checkBrowserIceweasel()
1302
+		{
1303
+			if (stripos($this->_agent, 'Iceweasel') !== false) {
1304
+				$aresult = explode('/', stristr($this->_agent, 'Iceweasel'));
1305
+				if (isset($aresult[1])) {
1306
+					$aversion = explode(' ', $aresult[1]);
1307
+					$this->setVersion($aversion[0]);
1308
+					$this->setBrowser(self::BROWSER_ICEWEASEL);
1309
+					return true;
1310
+				}
1311
+			}
1312
+			return false;
1313
+		}
1314
+
1315
+		/**
1316
+		 * Determine if the browser is Mozilla or not (last updated 1.7)
1317
+		 * @return boolean True if the browser is Mozilla otherwise false
1318
+		 */
1319
+		protected function checkBrowserMozilla()
1320
+		{
1321
+			if (stripos($this->_agent, 'mozilla') !== false && preg_match('/rv:[0-9].[0-9][a-b]?/i', $this->_agent) && stripos($this->_agent, 'netscape') === false) {
1322
+				$aversion = explode(' ', stristr($this->_agent, 'rv:'));
1323
+				preg_match('/rv:[0-9].[0-9][a-b]?/i', $this->_agent, $aversion);
1324
+				$this->setVersion(str_replace('rv:', '', $aversion[0]));
1325
+				$this->setBrowser(self::BROWSER_MOZILLA);
1326
+				return true;
1327
+			} else if (stripos($this->_agent, 'mozilla') !== false && preg_match('/rv:[0-9]\.[0-9]/i', $this->_agent) && stripos($this->_agent, 'netscape') === false) {
1328
+				$aversion = explode('', stristr($this->_agent, 'rv:'));
1329
+				$this->setVersion(str_replace('rv:', '', $aversion[0]));
1330
+				$this->setBrowser(self::BROWSER_MOZILLA);
1331
+				return true;
1332
+			} else if (stripos($this->_agent, 'mozilla') !== false && preg_match('/mozilla\/([^ ]*)/i', $this->_agent, $matches) && stripos($this->_agent, 'netscape') === false) {
1333
+				$this->setVersion($matches[1]);
1334
+				$this->setBrowser(self::BROWSER_MOZILLA);
1335
+				return true;
1336
+			}
1337
+			return false;
1338
+		}
1339
+
1340
+		/**
1341
+		 * Determine if the browser is Lynx or not (last updated 1.7)
1342
+		 * @return boolean True if the browser is Lynx otherwise false
1343
+		 */
1344
+		protected function checkBrowserLynx()
1345
+		{
1346
+			if (stripos($this->_agent, 'lynx') !== false) {
1347
+				$aresult = explode('/', stristr($this->_agent, 'Lynx'));
1348
+				$aversion = explode(' ', (isset($aresult[1]) ? $aresult[1] : ""));
1349
+				$this->setVersion($aversion[0]);
1350
+				$this->setBrowser(self::BROWSER_LYNX);
1351
+				return true;
1352
+			}
1353
+			return false;
1354
+		}
1355
+
1356
+		/**
1357
+		 * Determine if the browser is Amaya or not (last updated 1.7)
1358
+		 * @return boolean True if the browser is Amaya otherwise false
1359
+		 */
1360
+		protected function checkBrowserAmaya()
1361
+		{
1362
+			if (stripos($this->_agent, 'amaya') !== false) {
1363
+				$aresult = explode('/', stristr($this->_agent, 'Amaya'));
1364
+				if (isset($aresult[1])) {
1365
+					$aversion = explode(' ', $aresult[1]);
1366
+					$this->setVersion($aversion[0]);
1367
+					$this->setBrowser(self::BROWSER_AMAYA);
1368
+					return true;
1369
+				}
1370
+			}
1371
+			return false;
1372
+		}
1373
+
1374
+		/**
1375
+		 * Determine if the browser is Safari or not (last updated 1.7)
1376
+		 * @return boolean True if the browser is Safari otherwise false
1377
+		 */
1378
+		protected function checkBrowserSafari()
1379
+		{
1380
+			if (stripos($this->_agent, 'Safari') !== false
1381
+				&& stripos($this->_agent, 'iPhone') === false
1382
+				&& stripos($this->_agent, 'iPod') === false
1383
+			) {
1384
+
1385
+				$aresult = explode('/', stristr($this->_agent, 'Version'));
1386
+				if (isset($aresult[1])) {
1387
+					$aversion = explode(' ', $aresult[1]);
1388
+					$this->setVersion($aversion[0]);
1389
+				} else {
1390
+					$this->setVersion(self::VERSION_UNKNOWN);
1391
+				}
1392
+				$this->setBrowser(self::BROWSER_SAFARI);
1393
+				return true;
1394
+			}
1395
+			return false;
1396
+		}
1397
+
1398
+		protected function checkBrowserSamsung()
1399
+		{
1400
+			if (stripos($this->_agent, 'SamsungBrowser') !== false) {
1401
+
1402
+				$aresult = explode('/', stristr($this->_agent, 'SamsungBrowser'));
1403
+				if (isset($aresult[1])) {
1404
+					$aversion = explode(' ', $aresult[1]);
1405
+					$this->setVersion($aversion[0]);
1406
+				} else {
1407
+					$this->setVersion(self::VERSION_UNKNOWN);
1408
+				}
1409
+				$this->setBrowser(self::BROWSER_SAMSUNG);
1410
+				return true;
1411
+			}
1412
+			return false;
1413
+		}
1414
+
1415
+		protected function checkBrowserSilk()
1416
+		{
1417
+			if (stripos($this->_agent, 'Silk') !== false) {
1418
+				$aresult = explode('/', stristr($this->_agent, 'Silk'));
1419
+				if (isset($aresult[1])) {
1420
+					$aversion = explode(' ', $aresult[1]);
1421
+					$this->setVersion($aversion[0]);
1422
+				} else {
1423
+					$this->setVersion(self::VERSION_UNKNOWN);
1424
+				}
1425
+				$this->setBrowser(self::BROWSER_SILK);
1426
+				return true;
1427
+			}
1428
+			return false;
1429
+		}
1430
+
1431
+		protected function checkBrowserIframely()
1432
+		{
1433
+			if (stripos($this->_agent, 'Iframely') !== false) {
1434
+				$aresult = explode('/', stristr($this->_agent, 'Iframely'));
1435
+				if (isset($aresult[1])) {
1436
+					$aversion = explode(' ', $aresult[1]);
1437
+					$this->setVersion($aversion[0]);
1438
+				} else {
1439
+					$this->setVersion(self::VERSION_UNKNOWN);
1440
+				}
1441
+				$this->setBrowser(self::BROWSER_I_FRAME);
1442
+				return true;
1443
+			}
1444
+			return false;
1445
+		}
1446
+
1447
+		protected function checkBrowserCocoa()
1448
+		{
1449
+			if (stripos($this->_agent, 'CocoaRestClient') !== false) {
1450
+				$aresult = explode('/', stristr($this->_agent, 'CocoaRestClient'));
1451
+				if (isset($aresult[1])) {
1452
+					$aversion = explode(' ', $aresult[1]);
1453
+					$this->setVersion($aversion[0]);
1454
+				} else {
1455
+					$this->setVersion(self::VERSION_UNKNOWN);
1456
+				}
1457
+				$this->setBrowser(self::BROWSER_COCOA);
1458
+				return true;
1459
+			}
1460
+			return false;
1461
+		}
1462
+
1463
+		/**
1464
+		 * Detect if URL is loaded from FacebookExternalHit
1465
+		 * @return boolean True if it detects FacebookExternalHit otherwise false
1466
+		 */
1467
+		protected function checkFacebookExternalHit()
1468
+		{
1469
+			if (stristr($this->_agent, 'FacebookExternalHit')) {
1470
+				$this->setRobot(true);
1471
+				$this->setFacebook(true);
1472
+				return true;
1473
+			}
1474
+			return false;
1475
+		}
1476
+
1477
+		/**
1478
+		 * Detect if URL is being loaded from internal Facebook browser
1479
+		 * @return boolean True if it detects internal Facebook browser otherwise false
1480
+		 */
1481
+		protected function checkForFacebookIos()
1482
+		{
1483
+			if (stristr($this->_agent, 'FBIOS')) {
1484
+				$this->setFacebook(true);
1485
+				return true;
1486
+			}
1487
+			return false;
1488
+		}
1489
+
1490
+		/**
1491
+		 * Detect Version for the Safari browser on iOS devices
1492
+		 * @return boolean True if it detects the version correctly otherwise false
1493
+		 */
1494
+		protected function getSafariVersionOnIos()
1495
+		{
1496
+			$aresult = explode('/', stristr($this->_agent, 'Version'));
1497
+			if (isset($aresult[1])) {
1498
+				$aversion = explode(' ', $aresult[1]);
1499
+				$this->setVersion($aversion[0]);
1500
+				return true;
1501
+			}
1502
+			return false;
1503
+		}
1504
+
1505
+		/**
1506
+		 * Detect Version for the Chrome browser on iOS devices
1507
+		 * @return boolean True if it detects the version correctly otherwise false
1508
+		 */
1509
+		protected function getChromeVersionOnIos()
1510
+		{
1511
+			$aresult = explode('/', stristr($this->_agent, 'CriOS'));
1512
+			if (isset($aresult[1])) {
1513
+				$aversion = explode(' ', $aresult[1]);
1514
+				$this->setVersion($aversion[0]);
1515
+				$this->setBrowser(self::BROWSER_CHROME);
1516
+				return true;
1517
+			}
1518
+			return false;
1519
+		}
1520
+
1521
+		/**
1522
+		 * Determine if the browser is iPhone or not (last updated 1.7)
1523
+		 * @return boolean True if the browser is iPhone otherwise false
1524
+		 */
1525
+		protected function checkBrowseriPhone()
1526
+		{
1527
+			if (stripos($this->_agent, 'iPhone') !== false) {
1528
+				$this->setVersion(self::VERSION_UNKNOWN);
1529
+				$this->setBrowser(self::BROWSER_IPHONE);
1530
+				$this->getSafariVersionOnIos();
1531
+				$this->getChromeVersionOnIos();
1532
+				$this->checkForFacebookIos();
1533
+				$this->setMobile(true);
1534
+				return true;
1535
+
1536
+			}
1537
+			return false;
1538
+		}
1539
+
1540
+		/**
1541
+		 * Determine if the browser is iPad or not (last updated 1.7)
1542
+		 * @return boolean True if the browser is iPad otherwise false
1543
+		 */
1544
+		protected function checkBrowseriPad()
1545
+		{
1546
+			if (stripos($this->_agent, 'iPad') !== false) {
1547
+				$this->setVersion(self::VERSION_UNKNOWN);
1548
+				$this->setBrowser(self::BROWSER_IPAD);
1549
+				$this->getSafariVersionOnIos();
1550
+				$this->getChromeVersionOnIos();
1551
+				$this->checkForFacebookIos();
1552
+				$this->setTablet(true);
1553
+				return true;
1554
+			}
1555
+			return false;
1556
+		}
1557
+
1558
+		/**
1559
+		 * Determine if the browser is iPod or not (last updated 1.7)
1560
+		 * @return boolean True if the browser is iPod otherwise false
1561
+		 */
1562
+		protected function checkBrowseriPod()
1563
+		{
1564
+			if (stripos($this->_agent, 'iPod') !== false) {
1565
+				$this->setVersion(self::VERSION_UNKNOWN);
1566
+				$this->setBrowser(self::BROWSER_IPOD);
1567
+				$this->getSafariVersionOnIos();
1568
+				$this->getChromeVersionOnIos();
1569
+				$this->checkForFacebookIos();
1570
+				$this->setMobile(true);
1571
+				return true;
1572
+			}
1573
+			return false;
1574
+		}
1575
+
1576
+		/**
1577
+		 * Determine if the browser is Android or not (last updated 1.7)
1578
+		 * @return boolean True if the browser is Android otherwise false
1579
+		 */
1580
+		protected function checkBrowserAndroid()
1581
+		{
1582
+			if (stripos($this->_agent, 'Android') !== false) {
1583
+				$aresult = explode(' ', stristr($this->_agent, 'Android'));
1584
+				if (isset($aresult[1])) {
1585
+					$aversion = explode(' ', $aresult[1]);
1586
+					$this->setVersion($aversion[0]);
1587
+				} else {
1588
+					$this->setVersion(self::VERSION_UNKNOWN);
1589
+				}
1590
+				if (stripos($this->_agent, 'Mobile') !== false) {
1591
+					$this->setMobile(true);
1592
+				} else {
1593
+					$this->setTablet(true);
1594
+				}
1595
+				$this->setBrowser(self::BROWSER_ANDROID);
1596
+				return true;
1597
+			}
1598
+			return false;
1599
+		}
1600
+
1601
+		/**
1602
+		 * Determine if the browser is Vivaldi
1603
+		 * @return boolean True if the browser is Vivaldi otherwise false
1604
+		 */
1605
+		protected function checkBrowserVivaldi()
1606
+		{
1607
+			if (stripos($this->_agent, 'Vivaldi') !== false) {
1608
+				$aresult = explode('/', stristr($this->_agent, 'Vivaldi'));
1609
+				if (isset($aresult[1])) {
1610
+					$aversion = explode(' ', $aresult[1]);
1611
+					$this->setVersion($aversion[0]);
1612
+					$this->setBrowser(self::BROWSER_VIVALDI);
1613
+					return true;
1614
+				}
1615
+			}
1616
+			return false;
1617
+		}
1618
+
1619
+		/**
1620
+		 * Determine if the browser is Yandex
1621
+		 * @return boolean True if the browser is Yandex otherwise false
1622
+		 */
1623
+		protected function checkBrowserYandex()
1624
+		{
1625
+			if (stripos($this->_agent, 'YaBrowser') !== false) {
1626
+				$aresult = explode('/', stristr($this->_agent, 'YaBrowser'));
1627
+				if (isset($aresult[1])) {
1628
+					$aversion = explode(' ', $aresult[1]);
1629
+					$this->setVersion($aversion[0]);
1630
+					$this->setBrowser(self::BROWSER_YANDEX);
1631
+
1632
+					if (stripos($this->_agent, 'iPad') !== false) {
1633
+						$this->setTablet(true);
1634
+					} elseif (stripos($this->_agent, 'Mobile') !== false) {
1635
+						$this->setMobile(true);
1636
+					} elseif (stripos($this->_agent, 'Android') !== false) {
1637
+						$this->setTablet(true);
1638
+					}
1639
+
1640
+					return true;
1641
+				}
1642
+			}
1643
+
1644
+			return false;
1645
+		}
1646
+
1647
+		/**
1648
+		 * Determine if the browser is a PlayStation
1649
+		 * @return boolean True if the browser is PlayStation otherwise false
1650
+		 */
1651
+		protected function checkBrowserPlayStation()
1652
+		{
1653
+			if (stripos($this->_agent, 'PlayStation ') !== false) {
1654
+				$aresult = explode(' ', stristr($this->_agent, 'PlayStation '));
1655
+				$this->setBrowser(self::BROWSER_PLAYSTATION);
1656
+				if (isset($aresult[0])) {
1657
+					$aversion = explode(')', $aresult[2]);
1658
+					$this->setVersion($aversion[0]);
1659
+					if (stripos($this->_agent, 'Portable)') !== false || stripos($this->_agent, 'Vita') !== false) {
1660
+						$this->setMobile(true);
1661
+					}
1662
+					return true;
1663
+				}
1664
+			}
1665
+			return false;
1666
+		}
1667
+
1668
+		/**
1669
+		 * Determine the user's platform (last updated 2.0)
1670
+		 */
1671
+		protected function checkPlatform()
1672
+		{
1673
+			if (stripos($this->_agent, 'windows') !== false) {
1674
+				$this->_platform = self::PLATFORM_WINDOWS;
1675
+			} else if (stripos($this->_agent, 'iPad') !== false) {
1676
+				$this->_platform = self::PLATFORM_IPAD;
1677
+			} else if (stripos($this->_agent, 'iPod') !== false) {
1678
+				$this->_platform = self::PLATFORM_IPOD;
1679
+			} else if (stripos($this->_agent, 'iPhone') !== false) {
1680
+				$this->_platform = self::PLATFORM_IPHONE;
1681
+			} elseif (stripos($this->_agent, 'mac') !== false) {
1682
+				$this->_platform = self::PLATFORM_APPLE;
1683
+			} elseif (stripos($this->_agent, 'android') !== false) {
1684
+				$this->_platform = self::PLATFORM_ANDROID;
1685
+			} elseif (stripos($this->_agent, 'Silk') !== false) {
1686
+				$this->_platform = self::PLATFORM_FIRE_OS;
1687
+			} elseif (stripos($this->_agent, 'linux') !== false && stripos($this->_agent, 'SMART-TV') !== false ) {
1688
+				$this->_platform = self::PLATFORM_LINUX .'/'.self::PLATFORM_SMART_TV;
1689
+			} elseif (stripos($this->_agent, 'linux') !== false) {
1690
+				$this->_platform = self::PLATFORM_LINUX;
1691
+			} else if (stripos($this->_agent, 'Nokia') !== false) {
1692
+				$this->_platform = self::PLATFORM_NOKIA;
1693
+			} else if (stripos($this->_agent, 'BlackBerry') !== false) {
1694
+				$this->_platform = self::PLATFORM_BLACKBERRY;
1695
+			} elseif (stripos($this->_agent, 'FreeBSD') !== false) {
1696
+				$this->_platform = self::PLATFORM_FREEBSD;
1697
+			} elseif (stripos($this->_agent, 'OpenBSD') !== false) {
1698
+				$this->_platform = self::PLATFORM_OPENBSD;
1699
+			} elseif (stripos($this->_agent, 'NetBSD') !== false) {
1700
+				$this->_platform = self::PLATFORM_NETBSD;
1701
+			} elseif (stripos($this->_agent, 'OpenSolaris') !== false) {
1702
+				$this->_platform = self::PLATFORM_OPENSOLARIS;
1703
+			} elseif (stripos($this->_agent, 'SunOS') !== false) {
1704
+				$this->_platform = self::PLATFORM_SUNOS;
1705
+			} elseif (stripos($this->_agent, 'OS\/2') !== false) {
1706
+				$this->_platform = self::PLATFORM_OS2;
1707
+			} elseif (stripos($this->_agent, 'BeOS') !== false) {
1708
+				$this->_platform = self::PLATFORM_BEOS;
1709
+			} elseif (stripos($this->_agent, 'win') !== false) {
1710
+				$this->_platform = self::PLATFORM_WINDOWS;
1711
+			} elseif (stripos($this->_agent, 'Playstation') !== false) {
1712
+				$this->_platform = self::PLATFORM_PLAYSTATION;
1713
+			} elseif (stripos($this->_agent, 'Roku') !== false) {
1714
+				$this->_platform = self::PLATFORM_ROKU;
1715
+			} elseif (stripos($this->_agent, 'iOS') !== false) {
1716
+				$this->_platform = self::PLATFORM_IPHONE . '/' . self::PLATFORM_IPAD;
1717
+			} elseif (stripos($this->_agent, 'tvOS') !== false) {
1718
+				$this->_platform = self::PLATFORM_APPLE_TV;
1719
+			} elseif (stripos($this->_agent, 'curl') !== false) {
1720
+				$this->_platform = self::PLATFORM_TERMINAL;
1721
+			} elseif (stripos($this->_agent, 'CrOS') !== false) {
1722
+				$this->_platform = self::PLATFORM_CHROME_OS;
1723
+			} elseif (stripos($this->_agent, 'okhttp') !== false) {
1724
+				$this->_platform = self::PLATFORM_JAVA_ANDROID;
1725
+			} elseif (stripos($this->_agent, 'PostmanRuntime') !== false) {
1726
+				$this->_platform = self::PLATFORM_POSTMAN;
1727
+			} elseif (stripos($this->_agent, 'Iframely') !== false) {
1728
+				$this->_platform = self::PLATFORM_I_FRAME;
1729
+			}
1730
+
1731
+		}
1732
+	}
Please login to merge, or discard this patch.
core/libraries/Pagination.php 1 patch
Indentation   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-    defined('ROOT_PATH') || exit('Access denied');
2
+	defined('ROOT_PATH') || exit('Access denied');
3 3
 	/**
4 4
 	 * TNH Framework
5 5
 	 *
@@ -22,154 +22,154 @@  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 Pagination{
27
+	class Pagination{
28 28
         
29 29
 		/**
30
-         * The list of loaded config
31
-         * @var array
32
-         */
33
-        private $config = array();
30
+		 * The list of loaded config
31
+		 * @var array
32
+		 */
33
+		private $config = array();
34 34
 
35
-        /**
36
-         * Create an instance of pagination
37
-         * @param array $overwriteConfig the list of configuration to overwrite the defined configuration in config_pagination.php
38
-         */
39
-        public function __construct($overwriteConfig = array()){
40
-            if(file_exists(CONFIG_PATH . 'config_pagination.php')){
41
-                require_once CONFIG_PATH . 'config_pagination.php';
42
-                if(empty($config) || ! is_array($config)){
43
-                    show_error('No configuration found in ' . CONFIG_PATH . 'config_pagination.php');
44
-                }
35
+		/**
36
+		 * Create an instance of pagination
37
+		 * @param array $overwriteConfig the list of configuration to overwrite the defined configuration in config_pagination.php
38
+		 */
39
+		public function __construct($overwriteConfig = array()){
40
+			if(file_exists(CONFIG_PATH . 'config_pagination.php')){
41
+				require_once CONFIG_PATH . 'config_pagination.php';
42
+				if(empty($config) || ! is_array($config)){
43
+					show_error('No configuration found in ' . CONFIG_PATH . 'config_pagination.php');
44
+				}
45 45
 				else{
46 46
 					if(! empty($overwriteConfig)){
47 47
 						$config = array_merge($config, $overwriteConfig);
48 48
 					}
49 49
 					$this->config = $config;
50
-                    //put it gobally
50
+					//put it gobally
51 51
 					Config::setAll($config);
52 52
 					unset($config);
53 53
 				}
54
-            }
55
-            else{
56
-                show_error('Unable to find the pagination configuration file');
57
-            }
58
-        }
54
+			}
55
+			else{
56
+				show_error('Unable to find the pagination configuration file');
57
+			}
58
+		}
59 59
 
60 60
 
61
-        /**
62
-         * Set the pagination custom configuration to overwrite the default configuration in
63
-         * config_pagination.php
64
-         * @param array $config the configuration to set
65
-         */
66
-        public function setConfig(array $config = array()){
67
-            if(! empty($config)){
68
-                $this->config = array_merge($this->config, $config);
69
-                Config::setAll($config);
70
-            }
71
-        }
61
+		/**
62
+		 * Set the pagination custom configuration to overwrite the default configuration in
63
+		 * config_pagination.php
64
+		 * @param array $config the configuration to set
65
+		 */
66
+		public function setConfig(array $config = array()){
67
+			if(! empty($config)){
68
+				$this->config = array_merge($this->config, $config);
69
+				Config::setAll($config);
70
+			}
71
+		}
72 72
 
73
-        /**
74
-         * Generate the pagination link
75
-         * @param  int $totalRows the total number of data
76
-         * @param  int $currentPageNumber the current page number
77
-         * @return string the pagination link
78
-         */
79
-        public function getLink($totalRows, $currentPageNumber){
80
-            $pageQueryName = $this->config['page_query_string_name'];
81
-            $numberOfLink = $this->config['nb_link'];
73
+		/**
74
+		 * Generate the pagination link
75
+		 * @param  int $totalRows the total number of data
76
+		 * @param  int $currentPageNumber the current page number
77
+		 * @return string the pagination link
78
+		 */
79
+		public function getLink($totalRows, $currentPageNumber){
80
+			$pageQueryName = $this->config['page_query_string_name'];
81
+			$numberOfLink = $this->config['nb_link'];
82 82
 			$numberOfRowPerPage = $this->config['pagination_per_page'];
83
-            $queryString = Url::queryString();
84
-            $currentUrl = Url::current();
85
-            if($queryString == ''){
86
-                $query = '?' . $pageQueryName . '=';
87
-            }
88
-            else{
89
-                $tab = explode($pageQueryName . '=', $queryString);
90
-                $nb = count($tab);
91
-                if($nb == 1){
92
-                    $query = '?' . $queryString . '&' . $pageQueryName . '=';
93
-                }
94
-                else{
95
-                    if($tab[0] == ''){
96
-                        $query = '?' . $pageQueryName . '=';
97
-                    }
98
-                    else{
99
-                        $query = '?' . $tab[0] . '' . $pageQueryName . '=';
100
-                    }
101
-                }
102
-            }
103
-            $temp = explode('?', $currentUrl);
104
-            $query = $temp[0] . $query;
105
-            $navbar = '';
106
-            $numberOfPage = ceil($totalRows / $numberOfRowPerPage);
83
+			$queryString = Url::queryString();
84
+			$currentUrl = Url::current();
85
+			if($queryString == ''){
86
+				$query = '?' . $pageQueryName . '=';
87
+			}
88
+			else{
89
+				$tab = explode($pageQueryName . '=', $queryString);
90
+				$nb = count($tab);
91
+				if($nb == 1){
92
+					$query = '?' . $queryString . '&' . $pageQueryName . '=';
93
+				}
94
+				else{
95
+					if($tab[0] == ''){
96
+						$query = '?' . $pageQueryName . '=';
97
+					}
98
+					else{
99
+						$query = '?' . $tab[0] . '' . $pageQueryName . '=';
100
+					}
101
+				}
102
+			}
103
+			$temp = explode('?', $currentUrl);
104
+			$query = $temp[0] . $query;
105
+			$navbar = '';
106
+			$numberOfPage = ceil($totalRows / $numberOfRowPerPage);
107 107
 			if(! is_numeric ($currentPageNumber) || $currentPageNumber <= 0){
108 108
 				$currentPageNumber = 1;
109 109
 			}
110
-            if($numberOfPage <= 1 || $numberOfLink <= 0 || $numberOfRowPerPage <= 0 || !is_numeric($numberOfLink) || !is_numeric($numberOfRowPerPage)
111
-            ){
112
-                return $navbar;
113
-            }
114
-            if($numberOfLink % 2 == 0){
115
-                $start = $currentPageNumber - ($numberOfLink / 2) + 1;
116
-                $end = $currentPageNumber + ($numberOfLink / 2);
117
-            }
118
-            else{
119
-                $start = $currentPageNumber - floor($numberOfLink / 2);
120
-                $end = $currentPageNumber + floor($numberOfLink / 2);
121
-            }
122
-            if($start <= 1){
123
-                $begin = 1;
124
-                $end = $numberOfLink;
125
-            }
126
-            else if($start > 1 && $end < $numberOfPage){
127
-                $begin = $start;
128
-                $end = $end;
129
-            }
130
-            else{
131
-                $begin = ($numberOfPage - $numberOfLink) + 1;
132
-                $end = $numberOfPage;
133
-            }
134
-            if($numberOfPage <= $numberOfLink){
135
-                $begin = 1;
136
-                $end = $numberOfPage;
137
-            }
138
-            if($currentPageNumber == 1){
139
-                for($i = $begin; $i <= $end; $i++){
140
-                    if($i == $currentPageNumber){
141
-                        $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close'];
142
-                    }
143
-                    else{
144
-                        $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '" ' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' . $this->config['digit_close'];
145
-                    }
146
-                }
147
-                $navbar .= $this->config['next_open'] . '<a href="' . $query . ($currentPageNumber + 1) . '">' . $this->config['next_text'] . '</a>' . $this->config['next_close'];
148
-            }
149
-            else if($currentPageNumber > 1 && $currentPageNumber < $numberOfPage){
150
-                $navbar .= $this->config['previous_open'] . '<a href="' . $query . ($currentPageNumber - 1) . '">' . $this->config['previous_text'] . '</a>' . $this->config['previous_close'];
151
-                for($i = $begin; $i <= $end; $i++){
152
-                    if($i == $currentPageNumber){
153
-                        $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close'];
154
-                    }
155
-                    else{
156
-                        $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i .'</a>' . $this->config['digit_close'];
157
-                    }
158
-                }
159
-                $navbar .= $this->config['next_open']."<a href='$query".($currentPageNumber + 1)."'>".$this->config['next_text']."</a>".$this->config['next_close'];
160
-            }
161
-            else if($currentPageNumber == $numberOfPage){
162
-                $navbar .= $this->config['previous_open'] . '<a href="' . $query . ($currentPageNumber - 1) . '">' . $this->config['previous_text'] . '</a>' . $this->config['previous_close'];
163
-                for($i = $begin; $i <= $end; $i++){
164
-                    if($i == $currentPageNumber){
165
-                        $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close'];
166
-                    }
167
-                    else{
168
-                        $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' . $this->config['digit_close'];
169
-                    }
170
-                }
171
-            }
172
-            $navbar = $this->config['pagination_open'] . $navbar . $this->config['pagination_close'];
173
-            return $navbar;
174
-        }
175
-    }
110
+			if($numberOfPage <= 1 || $numberOfLink <= 0 || $numberOfRowPerPage <= 0 || !is_numeric($numberOfLink) || !is_numeric($numberOfRowPerPage)
111
+			){
112
+				return $navbar;
113
+			}
114
+			if($numberOfLink % 2 == 0){
115
+				$start = $currentPageNumber - ($numberOfLink / 2) + 1;
116
+				$end = $currentPageNumber + ($numberOfLink / 2);
117
+			}
118
+			else{
119
+				$start = $currentPageNumber - floor($numberOfLink / 2);
120
+				$end = $currentPageNumber + floor($numberOfLink / 2);
121
+			}
122
+			if($start <= 1){
123
+				$begin = 1;
124
+				$end = $numberOfLink;
125
+			}
126
+			else if($start > 1 && $end < $numberOfPage){
127
+				$begin = $start;
128
+				$end = $end;
129
+			}
130
+			else{
131
+				$begin = ($numberOfPage - $numberOfLink) + 1;
132
+				$end = $numberOfPage;
133
+			}
134
+			if($numberOfPage <= $numberOfLink){
135
+				$begin = 1;
136
+				$end = $numberOfPage;
137
+			}
138
+			if($currentPageNumber == 1){
139
+				for($i = $begin; $i <= $end; $i++){
140
+					if($i == $currentPageNumber){
141
+						$navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close'];
142
+					}
143
+					else{
144
+						$navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '" ' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' . $this->config['digit_close'];
145
+					}
146
+				}
147
+				$navbar .= $this->config['next_open'] . '<a href="' . $query . ($currentPageNumber + 1) . '">' . $this->config['next_text'] . '</a>' . $this->config['next_close'];
148
+			}
149
+			else if($currentPageNumber > 1 && $currentPageNumber < $numberOfPage){
150
+				$navbar .= $this->config['previous_open'] . '<a href="' . $query . ($currentPageNumber - 1) . '">' . $this->config['previous_text'] . '</a>' . $this->config['previous_close'];
151
+				for($i = $begin; $i <= $end; $i++){
152
+					if($i == $currentPageNumber){
153
+						$navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close'];
154
+					}
155
+					else{
156
+						$navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i .'</a>' . $this->config['digit_close'];
157
+					}
158
+				}
159
+				$navbar .= $this->config['next_open']."<a href='$query".($currentPageNumber + 1)."'>".$this->config['next_text']."</a>".$this->config['next_close'];
160
+			}
161
+			else if($currentPageNumber == $numberOfPage){
162
+				$navbar .= $this->config['previous_open'] . '<a href="' . $query . ($currentPageNumber - 1) . '">' . $this->config['previous_text'] . '</a>' . $this->config['previous_close'];
163
+				for($i = $begin; $i <= $end; $i++){
164
+					if($i == $currentPageNumber){
165
+						$navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close'];
166
+					}
167
+					else{
168
+						$navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' . $this->config['digit_close'];
169
+					}
170
+				}
171
+			}
172
+			$navbar = $this->config['pagination_open'] . $navbar . $this->config['pagination_close'];
173
+			return $navbar;
174
+		}
175
+	}
Please login to merge, or discard this patch.
core/libraries/Upload.php 1 patch
Indentation   +791 added lines, -791 removed lines patch added patch discarded remove patch
@@ -1,797 +1,797 @@
 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
-    */
26
-
27
-
28
-
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
-    */
40
-    class Upload{
41
-
42
-        /**
43
-        *   Version
44
-        *
45
-        *   @since      1.5
46
-        *   @version    1.0
47
-        */
48
-        const VERSION = '1.5';
49
-
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
-        */
62
-        private $upload_function = 'move_uploaded_file';
63
-
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
-        */
72
-        private $file_array    = array();
73
-
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
-        */
82
-        private $overwrite_file = false;
83
-
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
-        */
95
-        private $input;
96
-
97
-        /**
98
-        *    Path output
99
-        *
100
-        *    @since        1.0
101
-        *    @version    1.0
102
-        *    @var        string
103
-        */
104
-        private $destination_directory;
105
-
106
-        /**
107
-        *    Output filename
108
-        *
109
-        *    @since        1.0
110
-        *    @version    1.0
111
-        *    @var        string
112
-        */
113
-        private $filename;
114
-
115
-        /**
116
-        *    Max file size
117
-        *
118
-        *    @since        1.0
119
-        *    @version    1.0
120
-        *    @var        float
121
-        */
122
-        private $max_file_size= 0.0;
123
-
124
-        /**
125
-        *    List of allowed mime types
126
-        *
127
-        *    @since        1.0
128
-        *    @version    1.0
129
-        *    @var        array
130
-        */
131
-        private $allowed_mime_types = array();
132
-
133
-        /**
134
-        *    Callbacks
135
-        *
136
-        *    @since        1.0
137
-        *    @version    1.0
138
-        *    @var        array
139
-        */
140
-        private $callbacks = array('before' => null, 'after' => null);
141
-
142
-        /**
143
-        *    File object
144
-        *
145
-        *    @since        1.0
146
-        *    @version    1.0
147
-        *    @var        object
148
-        */
149
-        private $file;
150
-
151
-        /**
152
-        *    Helping mime types
153
-        *
154
-        *    @since        1.0
155
-        *    @version    1.0
156
-        *    @var        array
157
-        */
158
-        private $mime_helping = array(
159
-            'text'      =>    array('text/plain',),
160
-            'image'     =>    array(
161
-                'image/jpeg',
162
-                'image/jpg',
163
-                'image/pjpeg',
164
-                'image/png',
165
-                'image/gif',
166
-            ),
167
-            'document'  =>    array(
168
-                'application/pdf',
169
-                'application/msword',
170
-                'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
171
-                'application/vnd.openxmlformats-officedocument.presentationml.presentation',
172
-                'application/vnd.ms-powerpoint',
173
-                'application/vnd.ms-excel',
174
-                'application/vnd.oasis.opendocument.spreadsheet',
175
-                'application/vnd.oasis.opendocument.presentation',
176
-            ),
177
-            'video'    =>    array(
178
-                'video/3gpp',
179
-                'video/3gpp',
180
-                'video/x-msvideo',
181
-                'video/avi',
182
-                'video/mpeg4',
183
-                'video/mp4',
184
-                'video/mpeg',
185
-                'video/mpg',
186
-                'video/quicktime',
187
-                'video/x-sgi-movie',
188
-                'video/x-ms-wmv',
189
-                'video/x-flv',
190
-            ),
191
-        );
192
-
193
-        /**
194
-         * The upload error message
195
-         * @var array
196
-         */
197
-        public $error_messages = array();
198
-
199
-        /**
200
-         * The upload error message
201
-         * @var string
202
-         */
203
-        protected $error = null;
204
-
205
-        /**
206
-         * The logger instance
207
-         * @var Log
208
-         */
209
-        private $logger;
210
-
211
-
212
-        /**
213
-        *    Construct
214
-        *
215
-        *    @since     0.1
216
-        *    @version   1.0.1
217
-        *    @return    object
218
-        *    @method    object    __construct
219
-        */
220
-        public function __construct(){
221
-            $this->logger =& class_loader('Log', 'classes');
222
-            $this->logger->setLogger('Library::Upload');
223
-
224
-            Loader::lang('file_upload');
225
-            $obj =& get_instance();
226
-
227
-            $this->error_messages = array(
228
-                'upload_err_ini_size' => $obj->lang->get('fu_upload_err_ini_size'),
229
-                'upload_err_form_size' => $obj->lang->get('fu_upload_err_form_size'),
230
-                'upload_err_partial' => $obj->lang->get('fu_upload_err_partial'),
231
-                'upload_err_no_file' => $obj->lang->get('fu_upload_err_no_file'),
232
-                'upload_err_no_tmp_dir' => $obj->lang->get('fu_upload_err_no_tmp_dir'),
233
-                'upload_err_cant_write' => $obj->lang->get('fu_upload_err_cant_write'),
234
-                'upload_err_extension' => $obj->lang->get('fu_upload_err_extension'),
235
-                'accept_file_types' => $obj->lang->get('fu_accept_file_types'),
236
-                'file_uploads' => $obj->lang->get('fu_file_uploads_disabled'),
237
-                'max_file_size' => $obj->lang->get('fu_max_file_size'),
238
-                'overwritten_not_allowed' => $obj->lang->get('fu_overwritten_not_allowed'),
239
-            );
240
-
241
-            $this->file = array(
242
-                'status'                =>    false,    // True: success upload
243
-                'mime'                  =>    '',       // Empty string
244
-                'filename'              =>    '',       // Empty string
245
-                'original'              =>    '',       // Empty string
246
-                'size'                  =>    0,        // 0 Bytes
247
-                'sizeFormated'          =>    '0B',     // 0 Bytes
248
-                'destination'           =>    './',     // Default: ./
249
-                'allowed_mime_types'    =>    array(),  // Allowed mime types
250
-                'error'                 =>    null,        // File error
251
-            );
252
-
253
-            // Change dir to current dir
254
-            $this->destination_directory = dirname(__FILE__) . DIRECTORY_SEPARATOR;
255
-
256
-            // Set file array
257
-            if (isset($_FILES) && is_array($_FILES)) {
258
-                $this->file_array = $_FILES;
259
-            } elseif (isset($HTTP_POST_FILES) && is_array($HTTP_POST_FILES)) {
260
-                $this->file_array = $HTTP_POST_FILES;
261
-            }
262
-            $this->logger->info('The upload file information are : ' .stringfy_vars($this->file_array));
263
-        }
264
-        /**
265
-        *    Set input.
266
-        *    If you have $_FILES["file"], you must use the key "file"
267
-        *    Example:
268
-        *        $object->setInput("file");
269
-        *
270
-        *    @since     1.0
271
-        *    @version   1.0
272
-        *    @param     string      $input
273
-        *    @return    object
274
-        *    @method    boolean     setInput
275
-        */
276
-        public function setInput($input)
277
-        {
278
-            if (!empty($input) && (is_string($input) || is_numeric($input) )) {
279
-                $this->input = $input;
280
-            }
281
-            return $this;
282
-        }
283
-        /**
284
-        *    Set new filename
285
-        *    Example:
286
-        *        FileUpload::setFilename("new file.txt")
287
-        *    Remember:
288
-        *        Use %s to retrive file extension
289
-        *
290
-        *    @since     1.0
291
-        *    @version   1.0
292
-        *    @param     string      $filename
293
-        *    @return    object
294
-        *    @method    boolean     setFilename
295
-        */
296
-        public function setFilename($filename)
297
-        {
298
-            if ($this->isFilename($filename)) {
299
-                $this->filename = $filename;
300
-            }
301
-            return $this;
302
-        }
303
-        /**
304
-        *    Set automatic filename
305
-        *
306
-        *    @since     1.0
307
-        *    @version   1.5
308
-        *    @param     string      $extension
309
-        *    @return    object
310
-        *    @method    boolean     setAutoFilename
311
-        */
312
-        public function setAutoFilename()
313
-        {
314
-            $this->filename = sha1(mt_rand(1, 9999).uniqid());
315
-            $this->filename .= time();
316
-            return $this;
317
-        }
318
-        /**
319
-        *    Set file size limit
320
-        *
321
-        *    @since     1.0
322
-        *    @version   1.0
323
-        *    @param     double     $file_size
324
-        *    @return    object
325
-        *    @method    boolean     setMaxFileSize
326
-        */
327
-        public function setMaxFileSize($file_size)
328
-        {
329
-            $file_size = $this->sizeInBytes($file_size);
330
-            if (is_numeric($file_size) && $file_size > -1) {
331
-                // Get php config
332
-                $php_size = $this->sizeInBytes((int) ini_get('upload_max_filesize'));
333
-                // Calculate difference
334
-                if ($php_size < $file_size) {
335
-                    $this->logger->warning('The upload max file size you set [' .$file_size. '] is greather than the PHP configuration for upload max file size [' .$php_size. ']');
336
-                }
337
-                $this->max_file_size = $file_size;
338
-            }
339
-            return $this;
340
-        }
341
-        /**
342
-        *    Set array mime types
343
-        *
344
-        *    @since     1.0
345
-        *    @version   1.0
346
-        *    @param     array       $mimes
347
-        *    @return    object
348
-        *    @method    boolean     setAllowedMimeTypes
349
-        */
350
-        public function setAllowedMimeTypes(array $mimes)
351
-        {
352
-            if (count($mimes) > 0) {
353
-                array_map(array($this , 'setAllowMimeType'), $mimes);
354
-            }
355
-            return $this;
356
-        }
357
-        /**
358
-        *    Set input callback
359
-        *
360
-        *    @since     1.0
361
-        *    @version   1.0
362
-        *    @param     mixed       $callback
363
-        *    @return    object
364
-        *    @method    boolean     setCallbackInput
365
-        */
366
-        public function setCallbackInput($callback)
367
-        {
368
-            if (is_callable($callback, false)) {
369
-                $this->callbacks['input'] = $callback;
370
-            }
371
-            return $this;
372
-        }
373
-        /**
374
-        *    Set output callback
375
-        *
376
-        *    @since     1.0
377
-        *    @version   1.0
378
-        *    @param     mixed       $callback
379
-        *    @return    object
380
-        *    @method    boolean     setCallbackOutput
381
-        */
382
-        public function setCallbackOutput($callback)
383
-        {
384
-            if (is_callable($callback, false)) {
385
-                $this->callbacks['output'] = $callback;
386
-            }
387
-            return $this;
388
-        }
389
-        /**
390
-        *    Append a mime type to allowed mime types
391
-        *
392
-        *    @since     1.0
393
-        *    @version   1.0.1
394
-        *    @param     string      $mime
395
-        *    @return    object
396
-        *    @method    boolean     setAllowMimeType
397
-        */
398
-        public function setAllowMimeType($mime)
399
-        {
400
-            if (!empty($mime) && is_string($mime)) {
401
-                $this->allowed_mime_types[] = strtolower($mime);
402
-                $this->file['allowed_mime_types'][] = strtolower($mime);
403
-            } 
404
-            return $this;
405
-        }
406
-        /**
407
-        *    Set allowed mime types from mime helping
408
-        *
409
-        *    @since     1.0.1
410
-        *    @version   1.0.1
411
-        *    @return    object
412
-        *    @method    boolean    setMimeHelping
413
-        */
414
-        public function setMimeHelping($name)
415
-        {
416
-            if (!empty($name) && is_string($name)) {
417
-                if (array_key_exists($name, $this->mime_helping)) {
418
-                    return $this->setAllowedMimeTypes($this->mime_helping[ $name ]);
419
-                }
420
-            }
421
-            return $this;
422
-        }
423
-        /**
424
-        *    Set function to upload file
425
-        *    Examples:
426
-        *        1.- FileUpload::setUploadFunction("move_uploaded_file");
427
-        *        2.- FileUpload::setUploadFunction("copy");
428
-        *
429
-        *    @since     1.0
430
-        *    @version   1.0
431
-        *    @param     string      $function
432
-        *    @return    object
433
-        *    @method    boolean     setUploadFunction
434
-        */
435
-        public function setUploadFunction($function)
436
-        {
437
-            if (!empty($function) && (is_array($function) || is_string($function) )) {
438
-                if (is_callable( $function)) {
439
-                    $this->upload_function = $function;
440
-                }
441
-            }
442
-            return $this;
443
-        }
444
-        /**
445
-        *    Clear allowed mime types cache
446
-        *
447
-        *    @since     1.0
448
-        *    @version   1.0
449
-        *    @return    object
450
-        *    @method    boolean    clearAllowedMimeTypes
451
-        */
452
-        public function clearAllowedMimeTypes()
453
-        {
454
-            $this->allowed_mime_types = array();
455
-            $this->file['allowed_mime_types'] = array();
456
-            return $this;
457
-        }
458
-        /**
459
-        *    Set destination output
460
-        *
461
-        *    @since     1.0
462
-        *    @version   1.0
463
-        *    @param     string      $destination_directory      Destination path
464
-        *    @param     boolean     $create_if_not_exist
465
-        *    @return    object
466
-        *    @method    boolean     setDestinationDirectory
467
-        */
468
-        public function setDestinationDirectory($destination_directory, $create_if_not_exist = false) {
469
-            $destination_directory = realpath($destination_directory);
470
-            if (substr($destination_directory, -1) != DIRECTORY_SEPARATOR) {
471
-                $destination_directory .= DIRECTORY_SEPARATOR;
472
-            }
473
-
474
-            if ($this->isDirpath($destination_directory)) {
475
-                if ($this->dirExists($destination_directory)) {
476
-                    $this->destination_directory = $destination_directory;
477
-                    if (substr($this->destination_directory, -1) != DIRECTORY_SEPARATOR) {
478
-                        $this->destination_directory .= DIRECTORY_SEPARATOR;
479
-                    }
480
-                    chdir($destination_directory);
481
-                } elseif ($create_if_not_exist === true) {
482
-                    if (mkdir($destination_directory, 0775, true)) {
483
-                        if ($this->dirExists($destination_directory)) {
484
-                            $this->destination_directory = $destination_directory;
485
-                            if (substr($this->destination_directory, -1) != DIRECTORY_SEPARATOR) {
486
-                                $this->destination_directory .= DIRECTORY_SEPARATOR;
487
-                            }
488
-                            chdir($destination_directory);
489
-                        }
490
-                    }
491
-                    else{
492
-                        $this->logger->warning('Can not create the upload directory [' .$destination_directory. ']');
493
-                    }
494
-                }
495
-            }
496
-            return $this;
497
-        }
498
-        /**
499
-        *    Check file exists
500
-        *
501
-        *    @since      1.0
502
-        *    @version    1.0.1
503
-        *    @param      string     $file_destination
504
-        *    @return     boolean
505
-        *    @method     boolean    fileExists
506
-        */
507
-        public function fileExists($file_destination)
508
-        {
509
-            if ($this->isFilename($file_destination)) {
510
-                return (file_exists($file_destination) && is_file($file_destination));
511
-            }
512
-            return false;
513
-        }
514
-        /**
515
-        *    Check dir exists
516
-        *
517
-        *    @since        1.0
518
-        *    @version    1.0.1
519
-        *    @param      string     $path
520
-        *    @return     boolean
521
-        *    @method     boolean    dirExists
522
-        */
523
-        public function dirExists($path)
524
-        {
525
-            if ($this->isDirpath($path)) {
526
-                return (file_exists($path) && is_dir($path));
527
-            }
528
-            return false;
529
-        }
530
-        /**
531
-        *    Check valid filename
532
-        *
533
-        *    @since     1.0
534
-        *    @version   1.0.1
535
-        *    @param     string      $filename
536
-        *    @return    boolean
537
-        *    @method    boolean     isFilename
538
-        */
539
-        public function isFilename($filename)
540
-        {
541
-            $filename = basename($filename);
542
-            return (!empty($filename) && (is_string( $filename) || is_numeric($filename)));
543
-        }
544
-        /**
545
-        *    Validate mime type with allowed mime types,
546
-        *    but if allowed mime types is empty, this method return true
547
-        *
548
-        *    @since     1.0
549
-        *    @version   1.0
550
-        *    @param     string      $mime
551
-        *    @return    boolean
552
-        *    @method    boolean     checkMimeType
553
-        */
554
-        public function checkMimeType($mime)
555
-        {
556
-            if (count($this->allowed_mime_types) == 0) {
557
-                return true;
558
-            }
559
-            return in_array(strtolower($mime), $this->allowed_mime_types);
560
-        }
561
-        /**
562
-        *    Retrive status of upload
563
-        *
564
-        *    @since     1.0
565
-        *    @version   1.0
566
-        *    @return    boolean
567
-        *    @method    boolean    getStatus
568
-        */
569
-        public function getStatus()
570
-        {
571
-            return $this->file['status'];
572
-        }
573
-        /**
574
-        *    Check valid path
575
-        *
576
-        *    @since        1.0
577
-        *    @version    1.0.1
578
-        *    @param        string    $filename
579
-        *    @return     boolean
580
-        *    @method     boolean    isDirpath
581
-        */
582
-        public function isDirpath($path)
583
-        {
584
-            if (!empty( $path) && (is_string( $path) || is_numeric($path) )) {
585
-                if (DIRECTORY_SEPARATOR == '/') {
586
-                    return (preg_match( '/^[^*?"<>|:]*$/' , $path) == 1 );
587
-                } else {
588
-                    return (preg_match( "/^[^*?\"<>|:]*$/" , substr($path,2) ) == 1);
589
-                }
590
-            }
591
-            return false;
592
-        }
593
-        /**
594
-        *    Allow overwriting files
595
-        *
596
-        *    @since      1.0
597
-        *    @version    1.0
598
-        *    @return     object
599
-        *    @method     boolean    allowOverwriting
600
-        */
601
-        public function allowOverwriting()
602
-        {
603
-            $this->overwrite_file = true;
604
-            return $this;
605
-        }
606
-        /**
607
-        *    File info
608
-        *
609
-        *    @since      1.0
610
-        *    @version    1.0
611
-        *    @return     object
612
-        *    @method     object    getInfo
613
-        */
614
-        public function getInfo()
615
-        {
616
-            return (object)$this->file;
617
-        }
618
-
619
-        public function isUploaded(){
620
-            return isset($this->file_array[$this->input])
621
-            &&
622
-            is_uploaded_file($this->file_array[$this->input]['tmp_name']);
623
-        }
624
-        /**
625
-        *    Upload file
626
-        *
627
-        *    @since     1.0
628
-        *    @version   1.0.1
629
-        *    @return    boolean
630
-        *    @method    boolean    save
631
-        */
632
-        public function save(){
633
-            //check if file upload is  allowed in the configuration
634
-            if(! ini_get('file_uploads')){
635
-                $this->setError($this->error_messages['file_uploads']);
636
-                return false;
637
-            }
638
-            if (count($this->file_array) > 0) {
639
-                if (array_key_exists($this->input, $this->file_array)) {
640
-                    // set original filename if not have a new name
641
-                    if (empty($this->filename)) {
642
-                        $this->filename = $this->file_array[$this->input]['name'];
643
-                    }
644
-                    else{
645
-                        // Replace %s for extension in filename
646
-                        // Before: /[\w\d]*(.[\d\w]+)$/i
647
-                        // After: /^[\s[:alnum:]\-\_\.]*\.([\d\w]+)$/iu
648
-                        // Support unicode(utf-8) characters
649
-                        // Example: "русские.jpeg" is valid; "Zhōngguó.jpeg" is valid; "Tønsberg.jpeg" is valid
650
-                        $extension = preg_replace(
651
-                            '/^[\p{L}\d\s\-\_\.\(\)]*\.([\d\w]+)$/iu',
652
-                            '$1',
653
-                            $this->file_array[$this->input]['name']
654
-                        );
655
-                        $this->filename = $this->filename.'.'.$extension;
656
-                    }
657
-
658
-                    // set file info
659
-                    $this->file['mime']         = $this->file_array[$this->input]['type'];
660
-                    $this->file['tmp']          = $this->file_array[$this->input]['tmp_name'];
661
-                    $this->file['original']     = $this->file_array[$this->input]['name'];
662
-                    $this->file['size']         = $this->file_array[$this->input]['size'];
663
-                    $this->file['sizeFormated'] = $this->sizeFormat($this->file['size']);
664
-                    $this->file['destination']  = $this->destination_directory . $this->filename;
665
-                    $this->file['filename']     = $this->filename;
666
-                    $this->file['error']        = $this->file_array[$this->input]['error'];
667
-
668
-                    $this->logger->info('The upload file information to process is : ' .stringfy_vars($this->file));
669
-
670
-                    //check for php upload error
671
-                    if(is_numeric($this->file['error']) && $this->file['error'] > 0){
672
-                        $this->setError($this->getPhpUploadErrorMessageByCode($this->file['error']));
673
-                        return false;
674
-                    }
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
+
27
+
28
+
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
+	 */
40
+	class Upload{
41
+
42
+		/**
43
+		 *   Version
44
+		 *
45
+		 *   @since      1.5
46
+		 *   @version    1.0
47
+		 */
48
+		const VERSION = '1.5';
49
+
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
+		 */
62
+		private $upload_function = 'move_uploaded_file';
63
+
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
+		 */
72
+		private $file_array    = array();
73
+
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
+		 */
82
+		private $overwrite_file = false;
83
+
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
+		 */
95
+		private $input;
96
+
97
+		/**
98
+		 *    Path output
99
+		 *
100
+		 *    @since        1.0
101
+		 *    @version    1.0
102
+		 *    @var        string
103
+		 */
104
+		private $destination_directory;
105
+
106
+		/**
107
+		 *    Output filename
108
+		 *
109
+		 *    @since        1.0
110
+		 *    @version    1.0
111
+		 *    @var        string
112
+		 */
113
+		private $filename;
114
+
115
+		/**
116
+		 *    Max file size
117
+		 *
118
+		 *    @since        1.0
119
+		 *    @version    1.0
120
+		 *    @var        float
121
+		 */
122
+		private $max_file_size= 0.0;
123
+
124
+		/**
125
+		 *    List of allowed mime types
126
+		 *
127
+		 *    @since        1.0
128
+		 *    @version    1.0
129
+		 *    @var        array
130
+		 */
131
+		private $allowed_mime_types = array();
132
+
133
+		/**
134
+		 *    Callbacks
135
+		 *
136
+		 *    @since        1.0
137
+		 *    @version    1.0
138
+		 *    @var        array
139
+		 */
140
+		private $callbacks = array('before' => null, 'after' => null);
141
+
142
+		/**
143
+		 *    File object
144
+		 *
145
+		 *    @since        1.0
146
+		 *    @version    1.0
147
+		 *    @var        object
148
+		 */
149
+		private $file;
150
+
151
+		/**
152
+		 *    Helping mime types
153
+		 *
154
+		 *    @since        1.0
155
+		 *    @version    1.0
156
+		 *    @var        array
157
+		 */
158
+		private $mime_helping = array(
159
+			'text'      =>    array('text/plain',),
160
+			'image'     =>    array(
161
+				'image/jpeg',
162
+				'image/jpg',
163
+				'image/pjpeg',
164
+				'image/png',
165
+				'image/gif',
166
+			),
167
+			'document'  =>    array(
168
+				'application/pdf',
169
+				'application/msword',
170
+				'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
171
+				'application/vnd.openxmlformats-officedocument.presentationml.presentation',
172
+				'application/vnd.ms-powerpoint',
173
+				'application/vnd.ms-excel',
174
+				'application/vnd.oasis.opendocument.spreadsheet',
175
+				'application/vnd.oasis.opendocument.presentation',
176
+			),
177
+			'video'    =>    array(
178
+				'video/3gpp',
179
+				'video/3gpp',
180
+				'video/x-msvideo',
181
+				'video/avi',
182
+				'video/mpeg4',
183
+				'video/mp4',
184
+				'video/mpeg',
185
+				'video/mpg',
186
+				'video/quicktime',
187
+				'video/x-sgi-movie',
188
+				'video/x-ms-wmv',
189
+				'video/x-flv',
190
+			),
191
+		);
192
+
193
+		/**
194
+		 * The upload error message
195
+		 * @var array
196
+		 */
197
+		public $error_messages = array();
198
+
199
+		/**
200
+		 * The upload error message
201
+		 * @var string
202
+		 */
203
+		protected $error = null;
204
+
205
+		/**
206
+		 * The logger instance
207
+		 * @var Log
208
+		 */
209
+		private $logger;
210
+
211
+
212
+		/**
213
+		 *    Construct
214
+		 *
215
+		 *    @since     0.1
216
+		 *    @version   1.0.1
217
+		 *    @return    object
218
+		 *    @method    object    __construct
219
+		 */
220
+		public function __construct(){
221
+			$this->logger =& class_loader('Log', 'classes');
222
+			$this->logger->setLogger('Library::Upload');
223
+
224
+			Loader::lang('file_upload');
225
+			$obj =& get_instance();
226
+
227
+			$this->error_messages = array(
228
+				'upload_err_ini_size' => $obj->lang->get('fu_upload_err_ini_size'),
229
+				'upload_err_form_size' => $obj->lang->get('fu_upload_err_form_size'),
230
+				'upload_err_partial' => $obj->lang->get('fu_upload_err_partial'),
231
+				'upload_err_no_file' => $obj->lang->get('fu_upload_err_no_file'),
232
+				'upload_err_no_tmp_dir' => $obj->lang->get('fu_upload_err_no_tmp_dir'),
233
+				'upload_err_cant_write' => $obj->lang->get('fu_upload_err_cant_write'),
234
+				'upload_err_extension' => $obj->lang->get('fu_upload_err_extension'),
235
+				'accept_file_types' => $obj->lang->get('fu_accept_file_types'),
236
+				'file_uploads' => $obj->lang->get('fu_file_uploads_disabled'),
237
+				'max_file_size' => $obj->lang->get('fu_max_file_size'),
238
+				'overwritten_not_allowed' => $obj->lang->get('fu_overwritten_not_allowed'),
239
+			);
240
+
241
+			$this->file = array(
242
+				'status'                =>    false,    // True: success upload
243
+				'mime'                  =>    '',       // Empty string
244
+				'filename'              =>    '',       // Empty string
245
+				'original'              =>    '',       // Empty string
246
+				'size'                  =>    0,        // 0 Bytes
247
+				'sizeFormated'          =>    '0B',     // 0 Bytes
248
+				'destination'           =>    './',     // Default: ./
249
+				'allowed_mime_types'    =>    array(),  // Allowed mime types
250
+				'error'                 =>    null,        // File error
251
+			);
252
+
253
+			// Change dir to current dir
254
+			$this->destination_directory = dirname(__FILE__) . DIRECTORY_SEPARATOR;
255
+
256
+			// Set file array
257
+			if (isset($_FILES) && is_array($_FILES)) {
258
+				$this->file_array = $_FILES;
259
+			} elseif (isset($HTTP_POST_FILES) && is_array($HTTP_POST_FILES)) {
260
+				$this->file_array = $HTTP_POST_FILES;
261
+			}
262
+			$this->logger->info('The upload file information are : ' .stringfy_vars($this->file_array));
263
+		}
264
+		/**
265
+		 *    Set input.
266
+		 *    If you have $_FILES["file"], you must use the key "file"
267
+		 *    Example:
268
+		 *        $object->setInput("file");
269
+		 *
270
+		 *    @since     1.0
271
+		 *    @version   1.0
272
+		 *    @param     string      $input
273
+		 *    @return    object
274
+		 *    @method    boolean     setInput
275
+		 */
276
+		public function setInput($input)
277
+		{
278
+			if (!empty($input) && (is_string($input) || is_numeric($input) )) {
279
+				$this->input = $input;
280
+			}
281
+			return $this;
282
+		}
283
+		/**
284
+		 *    Set new filename
285
+		 *    Example:
286
+		 *        FileUpload::setFilename("new file.txt")
287
+		 *    Remember:
288
+		 *        Use %s to retrive file extension
289
+		 *
290
+		 *    @since     1.0
291
+		 *    @version   1.0
292
+		 *    @param     string      $filename
293
+		 *    @return    object
294
+		 *    @method    boolean     setFilename
295
+		 */
296
+		public function setFilename($filename)
297
+		{
298
+			if ($this->isFilename($filename)) {
299
+				$this->filename = $filename;
300
+			}
301
+			return $this;
302
+		}
303
+		/**
304
+		 *    Set automatic filename
305
+		 *
306
+		 *    @since     1.0
307
+		 *    @version   1.5
308
+		 *    @param     string      $extension
309
+		 *    @return    object
310
+		 *    @method    boolean     setAutoFilename
311
+		 */
312
+		public function setAutoFilename()
313
+		{
314
+			$this->filename = sha1(mt_rand(1, 9999).uniqid());
315
+			$this->filename .= time();
316
+			return $this;
317
+		}
318
+		/**
319
+		 *    Set file size limit
320
+		 *
321
+		 *    @since     1.0
322
+		 *    @version   1.0
323
+		 *    @param     double     $file_size
324
+		 *    @return    object
325
+		 *    @method    boolean     setMaxFileSize
326
+		 */
327
+		public function setMaxFileSize($file_size)
328
+		{
329
+			$file_size = $this->sizeInBytes($file_size);
330
+			if (is_numeric($file_size) && $file_size > -1) {
331
+				// Get php config
332
+				$php_size = $this->sizeInBytes((int) ini_get('upload_max_filesize'));
333
+				// Calculate difference
334
+				if ($php_size < $file_size) {
335
+					$this->logger->warning('The upload max file size you set [' .$file_size. '] is greather than the PHP configuration for upload max file size [' .$php_size. ']');
336
+				}
337
+				$this->max_file_size = $file_size;
338
+			}
339
+			return $this;
340
+		}
341
+		/**
342
+		 *    Set array mime types
343
+		 *
344
+		 *    @since     1.0
345
+		 *    @version   1.0
346
+		 *    @param     array       $mimes
347
+		 *    @return    object
348
+		 *    @method    boolean     setAllowedMimeTypes
349
+		 */
350
+		public function setAllowedMimeTypes(array $mimes)
351
+		{
352
+			if (count($mimes) > 0) {
353
+				array_map(array($this , 'setAllowMimeType'), $mimes);
354
+			}
355
+			return $this;
356
+		}
357
+		/**
358
+		 *    Set input callback
359
+		 *
360
+		 *    @since     1.0
361
+		 *    @version   1.0
362
+		 *    @param     mixed       $callback
363
+		 *    @return    object
364
+		 *    @method    boolean     setCallbackInput
365
+		 */
366
+		public function setCallbackInput($callback)
367
+		{
368
+			if (is_callable($callback, false)) {
369
+				$this->callbacks['input'] = $callback;
370
+			}
371
+			return $this;
372
+		}
373
+		/**
374
+		 *    Set output callback
375
+		 *
376
+		 *    @since     1.0
377
+		 *    @version   1.0
378
+		 *    @param     mixed       $callback
379
+		 *    @return    object
380
+		 *    @method    boolean     setCallbackOutput
381
+		 */
382
+		public function setCallbackOutput($callback)
383
+		{
384
+			if (is_callable($callback, false)) {
385
+				$this->callbacks['output'] = $callback;
386
+			}
387
+			return $this;
388
+		}
389
+		/**
390
+		 *    Append a mime type to allowed mime types
391
+		 *
392
+		 *    @since     1.0
393
+		 *    @version   1.0.1
394
+		 *    @param     string      $mime
395
+		 *    @return    object
396
+		 *    @method    boolean     setAllowMimeType
397
+		 */
398
+		public function setAllowMimeType($mime)
399
+		{
400
+			if (!empty($mime) && is_string($mime)) {
401
+				$this->allowed_mime_types[] = strtolower($mime);
402
+				$this->file['allowed_mime_types'][] = strtolower($mime);
403
+			} 
404
+			return $this;
405
+		}
406
+		/**
407
+		 *    Set allowed mime types from mime helping
408
+		 *
409
+		 *    @since     1.0.1
410
+		 *    @version   1.0.1
411
+		 *    @return    object
412
+		 *    @method    boolean    setMimeHelping
413
+		 */
414
+		public function setMimeHelping($name)
415
+		{
416
+			if (!empty($name) && is_string($name)) {
417
+				if (array_key_exists($name, $this->mime_helping)) {
418
+					return $this->setAllowedMimeTypes($this->mime_helping[ $name ]);
419
+				}
420
+			}
421
+			return $this;
422
+		}
423
+		/**
424
+		 *    Set function to upload file
425
+		 *    Examples:
426
+		 *        1.- FileUpload::setUploadFunction("move_uploaded_file");
427
+		 *        2.- FileUpload::setUploadFunction("copy");
428
+		 *
429
+		 *    @since     1.0
430
+		 *    @version   1.0
431
+		 *    @param     string      $function
432
+		 *    @return    object
433
+		 *    @method    boolean     setUploadFunction
434
+		 */
435
+		public function setUploadFunction($function)
436
+		{
437
+			if (!empty($function) && (is_array($function) || is_string($function) )) {
438
+				if (is_callable( $function)) {
439
+					$this->upload_function = $function;
440
+				}
441
+			}
442
+			return $this;
443
+		}
444
+		/**
445
+		 *    Clear allowed mime types cache
446
+		 *
447
+		 *    @since     1.0
448
+		 *    @version   1.0
449
+		 *    @return    object
450
+		 *    @method    boolean    clearAllowedMimeTypes
451
+		 */
452
+		public function clearAllowedMimeTypes()
453
+		{
454
+			$this->allowed_mime_types = array();
455
+			$this->file['allowed_mime_types'] = array();
456
+			return $this;
457
+		}
458
+		/**
459
+		 *    Set destination output
460
+		 *
461
+		 *    @since     1.0
462
+		 *    @version   1.0
463
+		 *    @param     string      $destination_directory      Destination path
464
+		 *    @param     boolean     $create_if_not_exist
465
+		 *    @return    object
466
+		 *    @method    boolean     setDestinationDirectory
467
+		 */
468
+		public function setDestinationDirectory($destination_directory, $create_if_not_exist = false) {
469
+			$destination_directory = realpath($destination_directory);
470
+			if (substr($destination_directory, -1) != DIRECTORY_SEPARATOR) {
471
+				$destination_directory .= DIRECTORY_SEPARATOR;
472
+			}
473
+
474
+			if ($this->isDirpath($destination_directory)) {
475
+				if ($this->dirExists($destination_directory)) {
476
+					$this->destination_directory = $destination_directory;
477
+					if (substr($this->destination_directory, -1) != DIRECTORY_SEPARATOR) {
478
+						$this->destination_directory .= DIRECTORY_SEPARATOR;
479
+					}
480
+					chdir($destination_directory);
481
+				} elseif ($create_if_not_exist === true) {
482
+					if (mkdir($destination_directory, 0775, true)) {
483
+						if ($this->dirExists($destination_directory)) {
484
+							$this->destination_directory = $destination_directory;
485
+							if (substr($this->destination_directory, -1) != DIRECTORY_SEPARATOR) {
486
+								$this->destination_directory .= DIRECTORY_SEPARATOR;
487
+							}
488
+							chdir($destination_directory);
489
+						}
490
+					}
491
+					else{
492
+						$this->logger->warning('Can not create the upload directory [' .$destination_directory. ']');
493
+					}
494
+				}
495
+			}
496
+			return $this;
497
+		}
498
+		/**
499
+		 *    Check file exists
500
+		 *
501
+		 *    @since      1.0
502
+		 *    @version    1.0.1
503
+		 *    @param      string     $file_destination
504
+		 *    @return     boolean
505
+		 *    @method     boolean    fileExists
506
+		 */
507
+		public function fileExists($file_destination)
508
+		{
509
+			if ($this->isFilename($file_destination)) {
510
+				return (file_exists($file_destination) && is_file($file_destination));
511
+			}
512
+			return false;
513
+		}
514
+		/**
515
+		 *    Check dir exists
516
+		 *
517
+		 *    @since        1.0
518
+		 *    @version    1.0.1
519
+		 *    @param      string     $path
520
+		 *    @return     boolean
521
+		 *    @method     boolean    dirExists
522
+		 */
523
+		public function dirExists($path)
524
+		{
525
+			if ($this->isDirpath($path)) {
526
+				return (file_exists($path) && is_dir($path));
527
+			}
528
+			return false;
529
+		}
530
+		/**
531
+		 *    Check valid filename
532
+		 *
533
+		 *    @since     1.0
534
+		 *    @version   1.0.1
535
+		 *    @param     string      $filename
536
+		 *    @return    boolean
537
+		 *    @method    boolean     isFilename
538
+		 */
539
+		public function isFilename($filename)
540
+		{
541
+			$filename = basename($filename);
542
+			return (!empty($filename) && (is_string( $filename) || is_numeric($filename)));
543
+		}
544
+		/**
545
+		 *    Validate mime type with allowed mime types,
546
+		 *    but if allowed mime types is empty, this method return true
547
+		 *
548
+		 *    @since     1.0
549
+		 *    @version   1.0
550
+		 *    @param     string      $mime
551
+		 *    @return    boolean
552
+		 *    @method    boolean     checkMimeType
553
+		 */
554
+		public function checkMimeType($mime)
555
+		{
556
+			if (count($this->allowed_mime_types) == 0) {
557
+				return true;
558
+			}
559
+			return in_array(strtolower($mime), $this->allowed_mime_types);
560
+		}
561
+		/**
562
+		 *    Retrive status of upload
563
+		 *
564
+		 *    @since     1.0
565
+		 *    @version   1.0
566
+		 *    @return    boolean
567
+		 *    @method    boolean    getStatus
568
+		 */
569
+		public function getStatus()
570
+		{
571
+			return $this->file['status'];
572
+		}
573
+		/**
574
+		 *    Check valid path
575
+		 *
576
+		 *    @since        1.0
577
+		 *    @version    1.0.1
578
+		 *    @param        string    $filename
579
+		 *    @return     boolean
580
+		 *    @method     boolean    isDirpath
581
+		 */
582
+		public function isDirpath($path)
583
+		{
584
+			if (!empty( $path) && (is_string( $path) || is_numeric($path) )) {
585
+				if (DIRECTORY_SEPARATOR == '/') {
586
+					return (preg_match( '/^[^*?"<>|:]*$/' , $path) == 1 );
587
+				} else {
588
+					return (preg_match( "/^[^*?\"<>|:]*$/" , substr($path,2) ) == 1);
589
+				}
590
+			}
591
+			return false;
592
+		}
593
+		/**
594
+		 *    Allow overwriting files
595
+		 *
596
+		 *    @since      1.0
597
+		 *    @version    1.0
598
+		 *    @return     object
599
+		 *    @method     boolean    allowOverwriting
600
+		 */
601
+		public function allowOverwriting()
602
+		{
603
+			$this->overwrite_file = true;
604
+			return $this;
605
+		}
606
+		/**
607
+		 *    File info
608
+		 *
609
+		 *    @since      1.0
610
+		 *    @version    1.0
611
+		 *    @return     object
612
+		 *    @method     object    getInfo
613
+		 */
614
+		public function getInfo()
615
+		{
616
+			return (object)$this->file;
617
+		}
618
+
619
+		public function isUploaded(){
620
+			return isset($this->file_array[$this->input])
621
+			&&
622
+			is_uploaded_file($this->file_array[$this->input]['tmp_name']);
623
+		}
624
+		/**
625
+		 *    Upload file
626
+		 *
627
+		 *    @since     1.0
628
+		 *    @version   1.0.1
629
+		 *    @return    boolean
630
+		 *    @method    boolean    save
631
+		 */
632
+		public function save(){
633
+			//check if file upload is  allowed in the configuration
634
+			if(! ini_get('file_uploads')){
635
+				$this->setError($this->error_messages['file_uploads']);
636
+				return false;
637
+			}
638
+			if (count($this->file_array) > 0) {
639
+				if (array_key_exists($this->input, $this->file_array)) {
640
+					// set original filename if not have a new name
641
+					if (empty($this->filename)) {
642
+						$this->filename = $this->file_array[$this->input]['name'];
643
+					}
644
+					else{
645
+						// Replace %s for extension in filename
646
+						// Before: /[\w\d]*(.[\d\w]+)$/i
647
+						// After: /^[\s[:alnum:]\-\_\.]*\.([\d\w]+)$/iu
648
+						// Support unicode(utf-8) characters
649
+						// Example: "русские.jpeg" is valid; "Zhōngguó.jpeg" is valid; "Tønsberg.jpeg" is valid
650
+						$extension = preg_replace(
651
+							'/^[\p{L}\d\s\-\_\.\(\)]*\.([\d\w]+)$/iu',
652
+							'$1',
653
+							$this->file_array[$this->input]['name']
654
+						);
655
+						$this->filename = $this->filename.'.'.$extension;
656
+					}
657
+
658
+					// set file info
659
+					$this->file['mime']         = $this->file_array[$this->input]['type'];
660
+					$this->file['tmp']          = $this->file_array[$this->input]['tmp_name'];
661
+					$this->file['original']     = $this->file_array[$this->input]['name'];
662
+					$this->file['size']         = $this->file_array[$this->input]['size'];
663
+					$this->file['sizeFormated'] = $this->sizeFormat($this->file['size']);
664
+					$this->file['destination']  = $this->destination_directory . $this->filename;
665
+					$this->file['filename']     = $this->filename;
666
+					$this->file['error']        = $this->file_array[$this->input]['error'];
667
+
668
+					$this->logger->info('The upload file information to process is : ' .stringfy_vars($this->file));
669
+
670
+					//check for php upload error
671
+					if(is_numeric($this->file['error']) && $this->file['error'] > 0){
672
+						$this->setError($this->getPhpUploadErrorMessageByCode($this->file['error']));
673
+						return false;
674
+					}
675 675
                     
676
-                    //check for mime type
677
-                    if (!$this->checkMimeType($this->file['mime'])) {
678
-                        $this->setError($this->error_messages['accept_file_types']);
679
-                        return false;
680
-                    }
681
-
682
-                     // Check file size
683
-                    if ($this->max_file_size > 0) {
684
-                        if ($this->max_file_size < $this->file['size']) {
685
-                            $this->setError(sprintf($this->error_messages['max_file_size'], $this->sizeFormat($this->max_file_size)));
686
-                            return false;
687
-                        }
688
-                    }
689
-
690
-                    // Check if exists file
691
-                    if ($this->fileExists($this->destination_directory . $this->filename)) {
692
-                        // Check if overwrite file
693
-                        if ($this->overwrite_file === false) {
694
-                            $this->setError($this->error_messages['overwritten_not_allowed']);
695
-                            return false;
696
-                        }
697
-                    }
698
-
699
-                    // Execute input callback
700
-                    if (!empty( $this->callbacks['input'])) {
701
-                        call_user_func($this->callbacks['input'], (object)$this->file);
702
-                    }
676
+					//check for mime type
677
+					if (!$this->checkMimeType($this->file['mime'])) {
678
+						$this->setError($this->error_messages['accept_file_types']);
679
+						return false;
680
+					}
681
+
682
+					 // Check file size
683
+					if ($this->max_file_size > 0) {
684
+						if ($this->max_file_size < $this->file['size']) {
685
+							$this->setError(sprintf($this->error_messages['max_file_size'], $this->sizeFormat($this->max_file_size)));
686
+							return false;
687
+						}
688
+					}
689
+
690
+					// Check if exists file
691
+					if ($this->fileExists($this->destination_directory . $this->filename)) {
692
+						// Check if overwrite file
693
+						if ($this->overwrite_file === false) {
694
+							$this->setError($this->error_messages['overwritten_not_allowed']);
695
+							return false;
696
+						}
697
+					}
698
+
699
+					// Execute input callback
700
+					if (!empty( $this->callbacks['input'])) {
701
+						call_user_func($this->callbacks['input'], (object)$this->file);
702
+					}
703 703
                    
704 704
 
705
-                    $this->file['status'] = call_user_func_array(
706
-                        $this->upload_function, array(
707
-                            $this->file_array[$this->input]['tmp_name'],
708
-                            $this->destination_directory . $this->filename
709
-                        )
710
-                    );
711
-
712
-                    // Execute output callback
713
-                    if (!empty( $this->callbacks['output'])) {
714
-                        call_user_func($this->callbacks['output'], (object)$this->file);
715
-                    }
716
-                    return $this->file['status'];
717
-                }
718
-            }
719
-        }
720
-
721
-        /**
722
-        *    File size for humans.
723
-        *
724
-        *    @since      1.0
725
-        *    @version    1.0
726
-        *    @param      integer    $bytes
727
-        *    @param      integer    $precision
728
-        *    @return     string
729
-        *    @method     string     sizeFormat
730
-        */
731
-        public function sizeFormat($size, $precision = 2)
732
-        {
733
-            if($size > 0){
734
-                $base       = log($size) / log(1024);
735
-                $suffixes   = array('B', 'K', 'M', 'G', 'T');
736
-                return round(pow(1024, $base - floor($base)), $precision) . ( isset($suffixes[floor($base)]) ? $suffixes[floor($base)] : '');
737
-            }
738
-            return null;
739
-        }
705
+					$this->file['status'] = call_user_func_array(
706
+						$this->upload_function, array(
707
+							$this->file_array[$this->input]['tmp_name'],
708
+							$this->destination_directory . $this->filename
709
+						)
710
+					);
711
+
712
+					// Execute output callback
713
+					if (!empty( $this->callbacks['output'])) {
714
+						call_user_func($this->callbacks['output'], (object)$this->file);
715
+					}
716
+					return $this->file['status'];
717
+				}
718
+			}
719
+		}
720
+
721
+		/**
722
+		 *    File size for humans.
723
+		 *
724
+		 *    @since      1.0
725
+		 *    @version    1.0
726
+		 *    @param      integer    $bytes
727
+		 *    @param      integer    $precision
728
+		 *    @return     string
729
+		 *    @method     string     sizeFormat
730
+		 */
731
+		public function sizeFormat($size, $precision = 2)
732
+		{
733
+			if($size > 0){
734
+				$base       = log($size) / log(1024);
735
+				$suffixes   = array('B', 'K', 'M', 'G', 'T');
736
+				return round(pow(1024, $base - floor($base)), $precision) . ( isset($suffixes[floor($base)]) ? $suffixes[floor($base)] : '');
737
+			}
738
+			return null;
739
+		}
740 740
 
741 741
         
742
-        /**
743
-        *    Convert human file size to bytes
744
-        *
745
-        *    @since      1.0
746
-        *    @version    1.0.1
747
-        *    @param      integer    $size
748
-        *    @return     string
749
-        *    @method     string     sizeInBytes
750
-        */
751
-        public function sizeInBytes($size)
752
-        {
753
-            $unit = 'B';
754
-            $units = array('B' => 0, 'K' => 1, 'M' => 2, 'G' => 3, 'T' => 4);
755
-            $matches = array();
756
-            preg_match('/(?<size>[\d\.]+)\s*(?<unit>b|k|m|g|t)?/i', $size, $matches);
757
-            if (array_key_exists('unit', $matches)) {
758
-                $unit = strtoupper($matches['unit']);
759
-            }
760
-            return (floatval($matches['size']) * pow(1024, $units[$unit]) ) ;
761
-        }
762
-
763
-        /**
764
-         * Get the upload error message
765
-         * @return string
766
-         */
767
-        public function getError(){
768
-            return $this->error;
769
-        }
770
-
771
-        /**
772
-         * Set the upload error message
773
-         * @param string $message the upload error message to set
774
-         */
775
-        public function setError($message){
776
-            $this->logger->info('The upload got error : ' . $message);
777
-            $this->error = $message;
778
-        }
779
-
780
-        /**
781
-         * Get the PHP upload error message for the given code
782
-         * @param  int $code the error code
783
-         * @return string the error message
784
-         */
785
-        private function getPhpUploadErrorMessageByCode($code){
786
-            $codeMessageMaps = array(
787
-                1 => $this->error_messages['upload_err_ini_size'],
788
-                2 => $this->error_messages['upload_err_form_size'],
789
-                3 => $this->error_messages['upload_err_partial'],
790
-                4 => $this->error_messages['upload_err_no_file'],
791
-                6 => $this->error_messages['upload_err_no_tmp_dir'],
792
-                7 => $this->error_messages['upload_err_cant_write'],
793
-                8 => $this->error_messages['upload_err_extension'],
794
-            );
795
-            return isset($codeMessageMaps[$code]) ? $codeMessageMaps[$code] : null;
796
-        }
797
-    }
742
+		/**
743
+		 *    Convert human file size to bytes
744
+		 *
745
+		 *    @since      1.0
746
+		 *    @version    1.0.1
747
+		 *    @param      integer    $size
748
+		 *    @return     string
749
+		 *    @method     string     sizeInBytes
750
+		 */
751
+		public function sizeInBytes($size)
752
+		{
753
+			$unit = 'B';
754
+			$units = array('B' => 0, 'K' => 1, 'M' => 2, 'G' => 3, 'T' => 4);
755
+			$matches = array();
756
+			preg_match('/(?<size>[\d\.]+)\s*(?<unit>b|k|m|g|t)?/i', $size, $matches);
757
+			if (array_key_exists('unit', $matches)) {
758
+				$unit = strtoupper($matches['unit']);
759
+			}
760
+			return (floatval($matches['size']) * pow(1024, $units[$unit]) ) ;
761
+		}
762
+
763
+		/**
764
+		 * Get the upload error message
765
+		 * @return string
766
+		 */
767
+		public function getError(){
768
+			return $this->error;
769
+		}
770
+
771
+		/**
772
+		 * Set the upload error message
773
+		 * @param string $message the upload error message to set
774
+		 */
775
+		public function setError($message){
776
+			$this->logger->info('The upload got error : ' . $message);
777
+			$this->error = $message;
778
+		}
779
+
780
+		/**
781
+		 * Get the PHP upload error message for the given code
782
+		 * @param  int $code the error code
783
+		 * @return string the error message
784
+		 */
785
+		private function getPhpUploadErrorMessageByCode($code){
786
+			$codeMessageMaps = array(
787
+				1 => $this->error_messages['upload_err_ini_size'],
788
+				2 => $this->error_messages['upload_err_form_size'],
789
+				3 => $this->error_messages['upload_err_partial'],
790
+				4 => $this->error_messages['upload_err_no_file'],
791
+				6 => $this->error_messages['upload_err_no_tmp_dir'],
792
+				7 => $this->error_messages['upload_err_cant_write'],
793
+				8 => $this->error_messages['upload_err_extension'],
794
+			);
795
+			return isset($codeMessageMaps[$code]) ? $codeMessageMaps[$code] : null;
796
+		}
797
+	}
Please login to merge, or discard this patch.
core/classes/model/Model.php 1 patch
Indentation   +928 added lines, -928 removed lines patch added patch discarded remove patch
@@ -1,595 +1,595 @@  discard block
 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
-    /**
29
-     * A base model with a series of CRUD functions (powered by CI's query builder),
30
-     * validation-in-model support, event callbacks and more.
31
-     *
32
-     * @link http://github.com/jamierumbelow/codeigniter-base-model
33
-     * @copyright Copyright (c) 2012, Jamie Rumbelow <http://jamierumbelow.net>
34
-     */
35
-
36
-    class Model{
37
-
38
-        /* --------------------------------------------------------------
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
+	/**
29
+	 * A base model with a series of CRUD functions (powered by CI's query builder),
30
+	 * validation-in-model support, event callbacks and more.
31
+	 *
32
+	 * @link http://github.com/jamierumbelow/codeigniter-base-model
33
+	 * @copyright Copyright (c) 2012, Jamie Rumbelow <http://jamierumbelow.net>
34
+	 */
35
+
36
+	class Model{
37
+
38
+		/* --------------------------------------------------------------
39 39
          * VARIABLES
40 40
          * ------------------------------------------------------------ */
41 41
 
42
-        /**
43
-         * This model's default database table. Automatically
44
-         * guessed by pluralising the model name.
45
-         */
46
-        protected $_table;
47
-
48
-        /**
49
-         * The database connection object. Will be set to the default
50
-         * connection. This allows individual models to use different DBs
51
-         * without overwriting the global database connection.
52
-         */
53
-        protected $_database;
54
-
55
-        /**
56
-         * This model's default primary key or unique identifier.
57
-         * Used by the get(), update() and delete() functions.
58
-         */
59
-        protected $primary_key = 'id';
60
-
61
-        /**
62
-         * Support for soft deletes and this model's 'deleted' key
63
-         */
64
-        protected $soft_delete = false;
65
-        protected $soft_delete_key = 'is_deleted';
66
-        protected $_temporary_with_deleted = FALSE;
67
-        protected $_temporary_only_deleted = FALSE;
68
-
69
-        /**
70
-         * The various callbacks available to the model. Each are
71
-         * simple lists of method names (methods will be run on $this).
72
-         */
73
-        protected $before_create = array();
74
-        protected $after_create = array();
75
-        protected $before_update = array();
76
-        protected $after_update = array();
77
-        protected $before_get = array();
78
-        protected $after_get = array();
79
-        protected $before_delete = array();
80
-        protected $after_delete = array();
81
-
82
-        protected $callback_parameters = array();
83
-
84
-        /**
85
-         * Protected, non-modifiable attributes
86
-         */
87
-        protected $protected_attributes = array();
88
-
89
-        /**
90
-         * Relationship arrays. Use flat strings for defaults or string
91
-         * => array to customise the class name and primary key
92
-         */
93
-        protected $belongs_to = array();
94
-        protected $has_many = array();
95
-
96
-        protected $_with = array();
97
-
98
-        /**
99
-         * An array of validation rules. This needs to be the same format
100
-         * as validation rules passed to the FormValidation library.
101
-         */
102
-        protected $validate = array();
103
-
104
-        /**
105
-         * Optionally skip the validation. Used in conjunction with
106
-         * skip_validation() to skip data validation for any future calls.
107
-         */
108
-        protected $skip_validation = FALSE;
109
-
110
-        /**
111
-         * By default we return our results as objects. If we need to override
112
-         * this, we can, or, we could use the `as_array()` and `as_object()` scopes.
113
-         */
114
-        protected $return_type = 'object';
115
-        protected $_temporary_return_type = NULL;
42
+		/**
43
+		 * This model's default database table. Automatically
44
+		 * guessed by pluralising the model name.
45
+		 */
46
+		protected $_table;
47
+
48
+		/**
49
+		 * The database connection object. Will be set to the default
50
+		 * connection. This allows individual models to use different DBs
51
+		 * without overwriting the global database connection.
52
+		 */
53
+		protected $_database;
54
+
55
+		/**
56
+		 * This model's default primary key or unique identifier.
57
+		 * Used by the get(), update() and delete() functions.
58
+		 */
59
+		protected $primary_key = 'id';
60
+
61
+		/**
62
+		 * Support for soft deletes and this model's 'deleted' key
63
+		 */
64
+		protected $soft_delete = false;
65
+		protected $soft_delete_key = 'is_deleted';
66
+		protected $_temporary_with_deleted = FALSE;
67
+		protected $_temporary_only_deleted = FALSE;
68
+
69
+		/**
70
+		 * The various callbacks available to the model. Each are
71
+		 * simple lists of method names (methods will be run on $this).
72
+		 */
73
+		protected $before_create = array();
74
+		protected $after_create = array();
75
+		protected $before_update = array();
76
+		protected $after_update = array();
77
+		protected $before_get = array();
78
+		protected $after_get = array();
79
+		protected $before_delete = array();
80
+		protected $after_delete = array();
81
+
82
+		protected $callback_parameters = array();
83
+
84
+		/**
85
+		 * Protected, non-modifiable attributes
86
+		 */
87
+		protected $protected_attributes = array();
88
+
89
+		/**
90
+		 * Relationship arrays. Use flat strings for defaults or string
91
+		 * => array to customise the class name and primary key
92
+		 */
93
+		protected $belongs_to = array();
94
+		protected $has_many = array();
95
+
96
+		protected $_with = array();
97
+
98
+		/**
99
+		 * An array of validation rules. This needs to be the same format
100
+		 * as validation rules passed to the FormValidation library.
101
+		 */
102
+		protected $validate = array();
103
+
104
+		/**
105
+		 * Optionally skip the validation. Used in conjunction with
106
+		 * skip_validation() to skip data validation for any future calls.
107
+		 */
108
+		protected $skip_validation = FALSE;
109
+
110
+		/**
111
+		 * By default we return our results as objects. If we need to override
112
+		 * this, we can, or, we could use the `as_array()` and `as_object()` scopes.
113
+		 */
114
+		protected $return_type = 'object';
115
+		protected $_temporary_return_type = NULL;
116 116
     	
117 117
     	
118
-    	/**
118
+		/**
119 119
     		The database cache time 
120
-    	*/
121
-    	protected $dbCacheTime = 0;
122
-
123
-        /**
124
-         * Instance of the Loader class
125
-         * @var Loader
126
-         */
127
-        protected $loaderInstance = null;
128
-
129
-        /**
130
-         * Instance of the FormValidation library
131
-         * @var FormValidation
132
-         */
133
-        protected $formValidationInstance = null;
134
-
135
-        /* --------------------------------------------------------------
120
+		 */
121
+		protected $dbCacheTime = 0;
122
+
123
+		/**
124
+		 * Instance of the Loader class
125
+		 * @var Loader
126
+		 */
127
+		protected $loaderInstance = null;
128
+
129
+		/**
130
+		 * Instance of the FormValidation library
131
+		 * @var FormValidation
132
+		 */
133
+		protected $formValidationInstance = null;
134
+
135
+		/* --------------------------------------------------------------
136 136
          * GENERIC METHODS
137 137
          * ------------------------------------------------------------ */
138 138
 
139
-        /**
140
-         * Initialise the model, tie into the CodeIgniter superobject and
141
-         * try our best to guess the table name.
142
-         */
143
-        public function __construct(Database $db = null){
144
-            if(is_object($db)){
145
-                $this->setDatabaseInstance($db);
146
-            }
147
-            else{
148
-                $obj = & get_instance();
149
-        		if(isset($obj->database) && is_object($obj->database)){
150
-                    /**
151
-                    * NOTE: Need use "clone" because some Model need have the personal instance of the database library
152
-                    * to prevent duplication
153
-                    */
154
-        			$this->setDatabaseInstance(clone $obj->database);
155
-                }
156
-            }
157
-
158
-            array_unshift($this->before_create, 'protect_attributes');
159
-            array_unshift($this->before_update, 'protect_attributes');
160
-            $this->_temporary_return_type = $this->return_type;
161
-        }
162
-
163
-        /* --------------------------------------------------------------
139
+		/**
140
+		 * Initialise the model, tie into the CodeIgniter superobject and
141
+		 * try our best to guess the table name.
142
+		 */
143
+		public function __construct(Database $db = null){
144
+			if(is_object($db)){
145
+				$this->setDatabaseInstance($db);
146
+			}
147
+			else{
148
+				$obj = & get_instance();
149
+				if(isset($obj->database) && is_object($obj->database)){
150
+					/**
151
+					 * NOTE: Need use "clone" because some Model need have the personal instance of the database library
152
+					 * to prevent duplication
153
+					 */
154
+					$this->setDatabaseInstance(clone $obj->database);
155
+				}
156
+			}
157
+
158
+			array_unshift($this->before_create, 'protect_attributes');
159
+			array_unshift($this->before_update, 'protect_attributes');
160
+			$this->_temporary_return_type = $this->return_type;
161
+		}
162
+
163
+		/* --------------------------------------------------------------
164 164
          * CRUD INTERFACE
165 165
          * ------------------------------------------------------------ */
166 166
 
167
-        /**
168
-         * Fetch a single record based on the primary key. Returns an object.
169
-         */
170
-        public function get($primary_value)
171
-        {
172
-    		return $this->get_by($this->primary_key, $primary_value);
173
-        }
174
-
175
-        /**
176
-         * Fetch a single record based on an arbitrary WHERE call. Can be
177
-         * any valid value to $this->_database->where().
178
-         */
179
-        public function get_by()
180
-        {
181
-            $where = func_get_args();
182
-
183
-            if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
184
-            {
185
-                $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
186
-            }
187
-
188
-    		$this->_set_where($where);
189
-
190
-            $this->trigger('before_get');
167
+		/**
168
+		 * Fetch a single record based on the primary key. Returns an object.
169
+		 */
170
+		public function get($primary_value)
171
+		{
172
+			return $this->get_by($this->primary_key, $primary_value);
173
+		}
174
+
175
+		/**
176
+		 * Fetch a single record based on an arbitrary WHERE call. Can be
177
+		 * any valid value to $this->_database->where().
178
+		 */
179
+		public function get_by()
180
+		{
181
+			$where = func_get_args();
182
+
183
+			if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
184
+			{
185
+				$this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
186
+			}
187
+
188
+			$this->_set_where($where);
189
+
190
+			$this->trigger('before_get');
191 191
 			$type = $this->_temporary_return_type == 'array' ? 'array' : false;
192
-            $row = $this->_database->from($this->_table)->get($type);
193
-            $this->_temporary_return_type = $this->return_type;
194
-            $row = $this->trigger('after_get', $row);
195
-            $this->_with = array();
196
-            return $row;
197
-        }
198
-
199
-        /**
200
-         * Fetch an array of records based on an array of primary values.
201
-         */
202
-        public function get_many($values)
203
-        {
204
-            $this->_database->in($this->primary_key, $values);
205
-            return $this->get_all();
206
-        }
207
-
208
-        /**
209
-         * Fetch an array of records based on an arbitrary WHERE call.
210
-         */
211
-        public function get_many_by()
212
-        {
213
-            $where = func_get_args();
214
-            $this->_set_where($where);
215
-            return $this->get_all();
216
-        }
217
-
218
-        /**
219
-         * Fetch all the records in the table. Can be used as a generic call
220
-         * to $this->_database->get() with scoped methods.
221
-         */
222
-        public function get_all()
223
-        {
224
-            $this->trigger('before_get');
225
-            if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
226
-            {
227
-                $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
228
-            }
192
+			$row = $this->_database->from($this->_table)->get($type);
193
+			$this->_temporary_return_type = $this->return_type;
194
+			$row = $this->trigger('after_get', $row);
195
+			$this->_with = array();
196
+			return $row;
197
+		}
198
+
199
+		/**
200
+		 * Fetch an array of records based on an array of primary values.
201
+		 */
202
+		public function get_many($values)
203
+		{
204
+			$this->_database->in($this->primary_key, $values);
205
+			return $this->get_all();
206
+		}
207
+
208
+		/**
209
+		 * Fetch an array of records based on an arbitrary WHERE call.
210
+		 */
211
+		public function get_many_by()
212
+		{
213
+			$where = func_get_args();
214
+			$this->_set_where($where);
215
+			return $this->get_all();
216
+		}
217
+
218
+		/**
219
+		 * Fetch all the records in the table. Can be used as a generic call
220
+		 * to $this->_database->get() with scoped methods.
221
+		 */
222
+		public function get_all()
223
+		{
224
+			$this->trigger('before_get');
225
+			if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
226
+			{
227
+				$this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
228
+			}
229 229
 			$type = $this->_temporary_return_type == 'array' ? 'array':false;
230
-            $result = $this->_database->from($this->_table)->getAll($type);
231
-            $this->_temporary_return_type = $this->return_type;
232
-
233
-            foreach ($result as $key => &$row)
234
-            {
235
-                $row = $this->trigger('after_get', $row, ($key == count($result) - 1));
236
-            }
237
-            $this->_with = array();
238
-            return $result;
239
-        }
240
-
241
-        /**
242
-         * Insert a new row into the table. $data should be an associative array
243
-         * of data to be inserted. Returns newly created ID.
244
-         */
245
-        public function insert($data = array(), $skip_validation = FALSE, $escape = true)
246
-        {
247
-            if ($skip_validation === FALSE)
248
-            {
249
-                $data = $this->validate($data);
250
-            }
251
-
252
-            if ($data !== FALSE)
253
-            {
254
-                $data = $this->trigger('before_create', $data);
255
-                $this->_database->from($this->_table)->insert($data, $escape);
256
-                $insert_id = $this->_database->insertId();
257
-                $this->trigger('after_create', $insert_id);
258
-                return $insert_id;
259
-            }
260
-            else
261
-            {
262
-                return FALSE;
263
-            }
264
-        }
265
-
266
-        /**
267
-         * Insert multiple rows into the table. Returns an array of multiple IDs.
268
-         */
269
-        public function insert_many($data = array(), $skip_validation = FALSE, $escape = true)
270
-        {
271
-            $ids = array();
272
-            foreach ($data as $key => $row)
273
-            {
274
-                $ids[] = $this->insert($row, $skip_validation, $escape);
275
-            }
276
-            return $ids;
277
-        }
278
-
279
-        /**
280
-         * Updated a record based on the primary value.
281
-         */
282
-        public function update($primary_value, $data = array(), $skip_validation = FALSE, $escape = true)
283
-        {
284
-            $data = $this->trigger('before_update', $data);
285
-            if ($skip_validation === FALSE)
286
-            {
287
-                $data = $this->validate($data);
288
-            }
289
-
290
-            if ($data !== FALSE)
291
-            {
292
-                $result = $this->_database->where($this->primary_key, $primary_value)
293
-                                   ->from($this->_table)
294
-                                   ->update($data, $escape);
295
-                $this->trigger('after_update', array($data, $result));
296
-                return $result;
297
-            }
298
-            else
299
-            {
300
-                return FALSE;
301
-            }
302
-        }
303
-
304
-        /**
305
-         * Update many records, based on an array of primary values.
306
-         */
307
-        public function update_many($primary_values, $data = array(), $skip_validation = FALSE, $escape = true)
308
-        {
309
-            $data = $this->trigger('before_update', $data);
310
-            if ($skip_validation === FALSE)
311
-            {
312
-                $data = $this->validate($data);
313
-            }
314
-            if ($data !== FALSE)
315
-            {
316
-                $result = $this->_database->in($this->primary_key, $primary_values)
317
-                                   ->from($this->_table)
318
-                                   ->update($data, $escape);
319
-                $this->trigger('after_update', array($data, $result));
320
-                return $result;
321
-            }
322
-            else
323
-            {
324
-                return FALSE;
325
-            }
326
-        }
327
-
328
-        /**
329
-         * Updated a record based on an arbitrary WHERE clause.
330
-         */
331
-        public function update_by()
332
-        {
333
-            $args = func_get_args();
334
-            $data = array();
335
-            if(count($args) == 2){
336
-                if(is_array($args[1])){
337
-                    $data = array_pop($args);
338
-                }
339
-            }
340
-            else if(count($args) == 3){
341
-                if(is_array($args[2])){
342
-                    $data = array_pop($args);
343
-                }
344
-            }
345
-            $data = $this->trigger('before_update', $data);
346
-            if ($this->validate($data) !== FALSE)
347
-            {
348
-                $this->_set_where($args);
349
-                $result = $this->_database->from($this->_table)->update($data);
350
-                $this->trigger('after_update', array($data, $result));
351
-                return $result;
352
-            }
353
-            else
354
-            {
355
-                return FALSE;
356
-            }
357
-        }
358
-
359
-        /**
360
-         * Update all records
361
-         */
362
-        public function update_all($data = array(), $escape = true)
363
-        {
364
-            $data = $this->trigger('before_update', $data);
365
-            $result = $this->_database->from($this->_table)->update($data, $escape);
366
-            $this->trigger('after_update', array($data, $result));
367
-            return $result;
368
-        }
369
-
370
-        /**
371
-         * Delete a row from the table by the primary value
372
-         */
373
-        public function delete($id)
374
-        {
375
-            $this->trigger('before_delete', $id);
376
-            $this->_database->where($this->primary_key, $id);
377
-            if ($this->soft_delete)
378
-            {
379
-                $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE ));
380
-            }
381
-            else
382
-            {
383
-                $result = $this->_database->from($this->_table)->delete();
384
-            }
385
-
386
-            $this->trigger('after_delete', $result);
387
-            return $result;
388
-        }
389
-
390
-        /**
391
-         * Delete a row from the database table by an arbitrary WHERE clause
392
-         */
393
-        public function delete_by()
394
-        {
395
-            $where = func_get_args();
396
-    	    $where = $this->trigger('before_delete', $where);
397
-            $this->_set_where($where);
398
-            if ($this->soft_delete)
399
-            {
400
-                $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE ));
401
-            }
402
-            else
403
-            {
404
-                $result = $this->_database->from($this->_table)->delete();
405
-            }
406
-            $this->trigger('after_delete', $result);
407
-            return $result;
408
-        }
409
-
410
-        /**
411
-         * Delete many rows from the database table by multiple primary values
412
-         */
413
-        public function delete_many($primary_values)
414
-        {
415
-            $primary_values = $this->trigger('before_delete', $primary_values);
416
-            $this->_database->in($this->primary_key, $primary_values);
417
-            if ($this->soft_delete)
418
-            {
419
-                $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE ));
420
-            }
421
-            else
422
-            {
423
-                $result = $this->_database->from($this->_table)->delete();
424
-            }
425
-            $this->trigger('after_delete', $result);
426
-            return $result;
427
-        }
428
-
429
-
430
-        /**
431
-         * Truncates the table
432
-         */
433
-        public function truncate()
434
-        {
435
-            $result = $this->_database->from($this->_table)->delete();
436
-            return $result;
437
-        }
438
-
439
-        /* --------------------------------------------------------------
230
+			$result = $this->_database->from($this->_table)->getAll($type);
231
+			$this->_temporary_return_type = $this->return_type;
232
+
233
+			foreach ($result as $key => &$row)
234
+			{
235
+				$row = $this->trigger('after_get', $row, ($key == count($result) - 1));
236
+			}
237
+			$this->_with = array();
238
+			return $result;
239
+		}
240
+
241
+		/**
242
+		 * Insert a new row into the table. $data should be an associative array
243
+		 * of data to be inserted. Returns newly created ID.
244
+		 */
245
+		public function insert($data = array(), $skip_validation = FALSE, $escape = true)
246
+		{
247
+			if ($skip_validation === FALSE)
248
+			{
249
+				$data = $this->validate($data);
250
+			}
251
+
252
+			if ($data !== FALSE)
253
+			{
254
+				$data = $this->trigger('before_create', $data);
255
+				$this->_database->from($this->_table)->insert($data, $escape);
256
+				$insert_id = $this->_database->insertId();
257
+				$this->trigger('after_create', $insert_id);
258
+				return $insert_id;
259
+			}
260
+			else
261
+			{
262
+				return FALSE;
263
+			}
264
+		}
265
+
266
+		/**
267
+		 * Insert multiple rows into the table. Returns an array of multiple IDs.
268
+		 */
269
+		public function insert_many($data = array(), $skip_validation = FALSE, $escape = true)
270
+		{
271
+			$ids = array();
272
+			foreach ($data as $key => $row)
273
+			{
274
+				$ids[] = $this->insert($row, $skip_validation, $escape);
275
+			}
276
+			return $ids;
277
+		}
278
+
279
+		/**
280
+		 * Updated a record based on the primary value.
281
+		 */
282
+		public function update($primary_value, $data = array(), $skip_validation = FALSE, $escape = true)
283
+		{
284
+			$data = $this->trigger('before_update', $data);
285
+			if ($skip_validation === FALSE)
286
+			{
287
+				$data = $this->validate($data);
288
+			}
289
+
290
+			if ($data !== FALSE)
291
+			{
292
+				$result = $this->_database->where($this->primary_key, $primary_value)
293
+								   ->from($this->_table)
294
+								   ->update($data, $escape);
295
+				$this->trigger('after_update', array($data, $result));
296
+				return $result;
297
+			}
298
+			else
299
+			{
300
+				return FALSE;
301
+			}
302
+		}
303
+
304
+		/**
305
+		 * Update many records, based on an array of primary values.
306
+		 */
307
+		public function update_many($primary_values, $data = array(), $skip_validation = FALSE, $escape = true)
308
+		{
309
+			$data = $this->trigger('before_update', $data);
310
+			if ($skip_validation === FALSE)
311
+			{
312
+				$data = $this->validate($data);
313
+			}
314
+			if ($data !== FALSE)
315
+			{
316
+				$result = $this->_database->in($this->primary_key, $primary_values)
317
+								   ->from($this->_table)
318
+								   ->update($data, $escape);
319
+				$this->trigger('after_update', array($data, $result));
320
+				return $result;
321
+			}
322
+			else
323
+			{
324
+				return FALSE;
325
+			}
326
+		}
327
+
328
+		/**
329
+		 * Updated a record based on an arbitrary WHERE clause.
330
+		 */
331
+		public function update_by()
332
+		{
333
+			$args = func_get_args();
334
+			$data = array();
335
+			if(count($args) == 2){
336
+				if(is_array($args[1])){
337
+					$data = array_pop($args);
338
+				}
339
+			}
340
+			else if(count($args) == 3){
341
+				if(is_array($args[2])){
342
+					$data = array_pop($args);
343
+				}
344
+			}
345
+			$data = $this->trigger('before_update', $data);
346
+			if ($this->validate($data) !== FALSE)
347
+			{
348
+				$this->_set_where($args);
349
+				$result = $this->_database->from($this->_table)->update($data);
350
+				$this->trigger('after_update', array($data, $result));
351
+				return $result;
352
+			}
353
+			else
354
+			{
355
+				return FALSE;
356
+			}
357
+		}
358
+
359
+		/**
360
+		 * Update all records
361
+		 */
362
+		public function update_all($data = array(), $escape = true)
363
+		{
364
+			$data = $this->trigger('before_update', $data);
365
+			$result = $this->_database->from($this->_table)->update($data, $escape);
366
+			$this->trigger('after_update', array($data, $result));
367
+			return $result;
368
+		}
369
+
370
+		/**
371
+		 * Delete a row from the table by the primary value
372
+		 */
373
+		public function delete($id)
374
+		{
375
+			$this->trigger('before_delete', $id);
376
+			$this->_database->where($this->primary_key, $id);
377
+			if ($this->soft_delete)
378
+			{
379
+				$result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE ));
380
+			}
381
+			else
382
+			{
383
+				$result = $this->_database->from($this->_table)->delete();
384
+			}
385
+
386
+			$this->trigger('after_delete', $result);
387
+			return $result;
388
+		}
389
+
390
+		/**
391
+		 * Delete a row from the database table by an arbitrary WHERE clause
392
+		 */
393
+		public function delete_by()
394
+		{
395
+			$where = func_get_args();
396
+			$where = $this->trigger('before_delete', $where);
397
+			$this->_set_where($where);
398
+			if ($this->soft_delete)
399
+			{
400
+				$result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE ));
401
+			}
402
+			else
403
+			{
404
+				$result = $this->_database->from($this->_table)->delete();
405
+			}
406
+			$this->trigger('after_delete', $result);
407
+			return $result;
408
+		}
409
+
410
+		/**
411
+		 * Delete many rows from the database table by multiple primary values
412
+		 */
413
+		public function delete_many($primary_values)
414
+		{
415
+			$primary_values = $this->trigger('before_delete', $primary_values);
416
+			$this->_database->in($this->primary_key, $primary_values);
417
+			if ($this->soft_delete)
418
+			{
419
+				$result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE ));
420
+			}
421
+			else
422
+			{
423
+				$result = $this->_database->from($this->_table)->delete();
424
+			}
425
+			$this->trigger('after_delete', $result);
426
+			return $result;
427
+		}
428
+
429
+
430
+		/**
431
+		 * Truncates the table
432
+		 */
433
+		public function truncate()
434
+		{
435
+			$result = $this->_database->from($this->_table)->delete();
436
+			return $result;
437
+		}
438
+
439
+		/* --------------------------------------------------------------
440 440
          * RELATIONSHIPS
441 441
          * ------------------------------------------------------------ */
442 442
 
443
-        public function with($relationship)
444
-        {
445
-            $this->_with[] = $relationship;
446
-            if (!in_array('relate', $this->after_get))
447
-            {
448
-                $this->after_get[] = 'relate';
449
-            }
450
-            return $this;
451
-        }
452
-
453
-        public function relate($row)
454
-        {
455
-    		if (empty($row))
456
-            {
457
-    		    return $row;
458
-            }
459
-
460
-            foreach ($this->belongs_to as $key => $value)
461
-            {
462
-                if (is_string($value))
463
-                {
464
-                    $relationship = $value;
465
-                    $options = array( 'primary_key' => $value . '_id', 'model' => $value . '_model' );
466
-                }
467
-                else
468
-                {
469
-                    $relationship = $key;
470
-                    $options = $value;
471
-                }
472
-
473
-                if (in_array($relationship, $this->_with))
474
-                {
475
-                    if(is_object($this->loaderInstance)){
476
-                        $this->loaderInstance->model($options['model'], $relationship . '_model');
477
-                    }
478
-                    else{
479
-                        Loader::model($options['model'], $relationship . '_model');    
480
-                    }
481
-                    if (is_object($row))
482
-                    {
483
-                        $row->{$relationship} = $this->{$relationship . '_model'}->get($row->{$options['primary_key']});
484
-                    }
485
-                    else
486
-                    {
487
-                        $row[$relationship] = $this->{$relationship . '_model'}->get($row[$options['primary_key']]);
488
-                    }
489
-                }
490
-            }
491
-
492
-            foreach ($this->has_many as $key => $value)
493
-            {
494
-                if (is_string($value))
495
-                {
496
-                    $relationship = $value;
497
-                    $options = array( 'primary_key' => $this->_table . '_id', 'model' => $value . '_model' );
498
-                }
499
-                else
500
-                {
501
-                    $relationship = $key;
502
-                    $options = $value;
503
-                }
504
-
505
-                if (in_array($relationship, $this->_with))
506
-                {
507
-                    if(is_object($this->loaderInstance)){
508
-                        $this->loaderInstance->model($options['model'], $relationship . '_model');
509
-                    }
510
-                    else{
511
-                        Loader::model($options['model'], $relationship . '_model');    
512
-                    }
513
-                    if (is_object($row))
514
-                    {
515
-                        $row->{$relationship} = $this->{$relationship . '_model'}->get_many_by($options['primary_key'], $row->{$this->primary_key});
516
-                    }
517
-                    else
518
-                    {
519
-                        $row[$relationship] = $this->{$relationship . '_model'}->get_many_by($options['primary_key'], $row[$this->primary_key]);
520
-                    }
521
-                }
522
-            }
523
-            return $row;
524
-        }
525
-
526
-        /* --------------------------------------------------------------
443
+		public function with($relationship)
444
+		{
445
+			$this->_with[] = $relationship;
446
+			if (!in_array('relate', $this->after_get))
447
+			{
448
+				$this->after_get[] = 'relate';
449
+			}
450
+			return $this;
451
+		}
452
+
453
+		public function relate($row)
454
+		{
455
+			if (empty($row))
456
+			{
457
+				return $row;
458
+			}
459
+
460
+			foreach ($this->belongs_to as $key => $value)
461
+			{
462
+				if (is_string($value))
463
+				{
464
+					$relationship = $value;
465
+					$options = array( 'primary_key' => $value . '_id', 'model' => $value . '_model' );
466
+				}
467
+				else
468
+				{
469
+					$relationship = $key;
470
+					$options = $value;
471
+				}
472
+
473
+				if (in_array($relationship, $this->_with))
474
+				{
475
+					if(is_object($this->loaderInstance)){
476
+						$this->loaderInstance->model($options['model'], $relationship . '_model');
477
+					}
478
+					else{
479
+						Loader::model($options['model'], $relationship . '_model');    
480
+					}
481
+					if (is_object($row))
482
+					{
483
+						$row->{$relationship} = $this->{$relationship . '_model'}->get($row->{$options['primary_key']});
484
+					}
485
+					else
486
+					{
487
+						$row[$relationship] = $this->{$relationship . '_model'}->get($row[$options['primary_key']]);
488
+					}
489
+				}
490
+			}
491
+
492
+			foreach ($this->has_many as $key => $value)
493
+			{
494
+				if (is_string($value))
495
+				{
496
+					$relationship = $value;
497
+					$options = array( 'primary_key' => $this->_table . '_id', 'model' => $value . '_model' );
498
+				}
499
+				else
500
+				{
501
+					$relationship = $key;
502
+					$options = $value;
503
+				}
504
+
505
+				if (in_array($relationship, $this->_with))
506
+				{
507
+					if(is_object($this->loaderInstance)){
508
+						$this->loaderInstance->model($options['model'], $relationship . '_model');
509
+					}
510
+					else{
511
+						Loader::model($options['model'], $relationship . '_model');    
512
+					}
513
+					if (is_object($row))
514
+					{
515
+						$row->{$relationship} = $this->{$relationship . '_model'}->get_many_by($options['primary_key'], $row->{$this->primary_key});
516
+					}
517
+					else
518
+					{
519
+						$row[$relationship] = $this->{$relationship . '_model'}->get_many_by($options['primary_key'], $row[$this->primary_key]);
520
+					}
521
+				}
522
+			}
523
+			return $row;
524
+		}
525
+
526
+		/* --------------------------------------------------------------
527 527
          * UTILITY METHODS
528 528
          * ------------------------------------------------------------ */
529 529
 
530
-        /**
531
-         * Retrieve and generate a form_dropdown friendly array
532
-         */
533
-        public function dropdown()
534
-        {
535
-            $args = func_get_args();
536
-            if(count($args) == 2)
537
-            {
538
-                list($key, $value) = $args;
539
-            }
540
-            else
541
-            {
542
-                $key = $this->primary_key;
543
-                $value = $args[0];
544
-            }
545
-            $this->trigger('before_dropdown', array( $key, $value ));
546
-            if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
547
-            {
548
-                $this->_database->where($this->soft_delete_key, FALSE);
549
-            }
550
-            $result = $this->_database->select(array($key, $value))
551
-                               ->from($this->_table)
552
-                               ->getAll();
553
-            $options = array();
554
-            foreach ($result as $row)
555
-            {
556
-                $options[$row->{$key}] = $row->{$value};
557
-            }
558
-            $options = $this->trigger('after_dropdown', $options);
559
-            return $options;
560
-        }
561
-
562
-        /**
563
-         * Fetch a count of rows based on an arbitrary WHERE call.
564
-         */
565
-        public function count_by()
566
-        {
567
-            if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
568
-            {
569
-                $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
570
-            }
571
-            $where = func_get_args();
572
-            $this->_set_where($where);
573
-            $this->_database->from($this->_table)->getAll();
574
-            return $this->_database->numRows();
575
-        }
576
-
577
-        /**
578
-         * Fetch a total count of rows, disregarding any previous conditions
579
-         */
580
-        public function count_all()
581
-        {
582
-            if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
583
-            {
584
-                $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
585
-            }
586
-            $this->_database->from($this->_table)->getAll();
587
-            return $this->_database->numRows();
588
-        }
530
+		/**
531
+		 * Retrieve and generate a form_dropdown friendly array
532
+		 */
533
+		public function dropdown()
534
+		{
535
+			$args = func_get_args();
536
+			if(count($args) == 2)
537
+			{
538
+				list($key, $value) = $args;
539
+			}
540
+			else
541
+			{
542
+				$key = $this->primary_key;
543
+				$value = $args[0];
544
+			}
545
+			$this->trigger('before_dropdown', array( $key, $value ));
546
+			if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
547
+			{
548
+				$this->_database->where($this->soft_delete_key, FALSE);
549
+			}
550
+			$result = $this->_database->select(array($key, $value))
551
+							   ->from($this->_table)
552
+							   ->getAll();
553
+			$options = array();
554
+			foreach ($result as $row)
555
+			{
556
+				$options[$row->{$key}] = $row->{$value};
557
+			}
558
+			$options = $this->trigger('after_dropdown', $options);
559
+			return $options;
560
+		}
561
+
562
+		/**
563
+		 * Fetch a count of rows based on an arbitrary WHERE call.
564
+		 */
565
+		public function count_by()
566
+		{
567
+			if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
568
+			{
569
+				$this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
570
+			}
571
+			$where = func_get_args();
572
+			$this->_set_where($where);
573
+			$this->_database->from($this->_table)->getAll();
574
+			return $this->_database->numRows();
575
+		}
576
+
577
+		/**
578
+		 * Fetch a total count of rows, disregarding any previous conditions
579
+		 */
580
+		public function count_all()
581
+		{
582
+			if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
583
+			{
584
+				$this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
585
+			}
586
+			$this->_database->from($this->_table)->getAll();
587
+			return $this->_database->numRows();
588
+		}
589 589
 		
590 590
 		/**
591
-		* Enabled cache temporary
592
-		*/
591
+		 * Enabled cache temporary
592
+		 */
593 593
 		public function cached($ttl = 0){
594 594
 		  if($ttl > 0){
595 595
 			$this->_database = $this->_database->cached($ttl);
@@ -597,385 +597,385 @@  discard block
 block discarded – undo
597 597
 		  return $this;
598 598
 		}
599 599
 
600
-        /**
601
-         * Tell the class to skip the insert validation
602
-         */
603
-        public function skip_validation()
604
-        {
605
-            $this->skip_validation = TRUE;
606
-            return $this;
607
-        }
608
-
609
-        /**
610
-         * Get the skip validation status
611
-         */
612
-        public function get_skip_validation()
613
-        {
614
-            return $this->skip_validation;
615
-        }
616
-
617
-        /**
618
-         * Return the next auto increment of the table. Only tested on MySQL.
619
-         */
620
-        public function get_next_id()
621
-        {
622
-            return (int) $this->_database->select('AUTO_INCREMENT')
623
-                ->from('information_schema.TABLES')
624
-                ->where('TABLE_NAME', $this->_table)
625
-                ->where('TABLE_SCHEMA', $this->_database->getDatabaseName())->get()->AUTO_INCREMENT;
626
-        }
627
-
628
-        /**
629
-         * Getter for the table name
630
-         */
631
-        public function table()
632
-        {
633
-            return $this->_table;
634
-        }
635
-
636
-        /* --------------------------------------------------------------
600
+		/**
601
+		 * Tell the class to skip the insert validation
602
+		 */
603
+		public function skip_validation()
604
+		{
605
+			$this->skip_validation = TRUE;
606
+			return $this;
607
+		}
608
+
609
+		/**
610
+		 * Get the skip validation status
611
+		 */
612
+		public function get_skip_validation()
613
+		{
614
+			return $this->skip_validation;
615
+		}
616
+
617
+		/**
618
+		 * Return the next auto increment of the table. Only tested on MySQL.
619
+		 */
620
+		public function get_next_id()
621
+		{
622
+			return (int) $this->_database->select('AUTO_INCREMENT')
623
+				->from('information_schema.TABLES')
624
+				->where('TABLE_NAME', $this->_table)
625
+				->where('TABLE_SCHEMA', $this->_database->getDatabaseName())->get()->AUTO_INCREMENT;
626
+		}
627
+
628
+		/**
629
+		 * Getter for the table name
630
+		 */
631
+		public function table()
632
+		{
633
+			return $this->_table;
634
+		}
635
+
636
+		/* --------------------------------------------------------------
637 637
          * GLOBAL SCOPES
638 638
          * ------------------------------------------------------------ */
639 639
 
640
-        /**
641
-         * Return the next call as an array rather than an object
642
-         */
643
-        public function as_array()
644
-        {
645
-            $this->_temporary_return_type = 'array';
646
-            return $this;
647
-        }
648
-
649
-        /**
650
-         * Return the next call as an object rather than an array
651
-         */
652
-        public function as_object()
653
-        {
654
-            $this->_temporary_return_type = 'object';
655
-            return $this;
656
-        }
657
-
658
-        /**
659
-         * Don't care about soft deleted rows on the next call
660
-         */
661
-        public function with_deleted()
662
-        {
663
-            $this->_temporary_with_deleted = TRUE;
664
-            return $this;
665
-        }
666
-
667
-        /**
668
-         * Only get deleted rows on the next call
669
-         */
670
-        public function only_deleted()
671
-        {
672
-            $this->_temporary_only_deleted = TRUE;
673
-            return $this;
674
-        }
675
-
676
-        /* --------------------------------------------------------------
640
+		/**
641
+		 * Return the next call as an array rather than an object
642
+		 */
643
+		public function as_array()
644
+		{
645
+			$this->_temporary_return_type = 'array';
646
+			return $this;
647
+		}
648
+
649
+		/**
650
+		 * Return the next call as an object rather than an array
651
+		 */
652
+		public function as_object()
653
+		{
654
+			$this->_temporary_return_type = 'object';
655
+			return $this;
656
+		}
657
+
658
+		/**
659
+		 * Don't care about soft deleted rows on the next call
660
+		 */
661
+		public function with_deleted()
662
+		{
663
+			$this->_temporary_with_deleted = TRUE;
664
+			return $this;
665
+		}
666
+
667
+		/**
668
+		 * Only get deleted rows on the next call
669
+		 */
670
+		public function only_deleted()
671
+		{
672
+			$this->_temporary_only_deleted = TRUE;
673
+			return $this;
674
+		}
675
+
676
+		/* --------------------------------------------------------------
677 677
          * OBSERVERS
678 678
          * ------------------------------------------------------------ */
679 679
 
680
-        /**
681
-         * MySQL DATETIME created_at and updated_at
682
-         */
683
-        public function created_at($row)
684
-        {
685
-            if (is_object($row))
686
-            {
687
-                $row->created_at = date('Y-m-d H:i:s');
688
-            }
689
-            else
690
-            {
691
-                $row['created_at'] = date('Y-m-d H:i:s');
692
-            }
693
-
694
-            return $row;
695
-        }
696
-
697
-        public function updated_at($row)
698
-        {
699
-            if (is_object($row))
700
-            {
701
-                $row->updated_at = date('Y-m-d H:i:s');
702
-            }
703
-            else
704
-            {
705
-                $row['updated_at'] = date('Y-m-d H:i:s');
706
-            }
707
-            return $row;
708
-        }
709
-
710
-        /**
711
-         * Serialises data for you automatically, allowing you to pass
712
-         * through objects and let it handle the serialisation in the background
713
-         */
714
-        public function serialize($row)
715
-        {
716
-            foreach ($this->callback_parameters as $column)
717
-            {
718
-                $row[$column] = serialize($row[$column]);
719
-            }
720
-            return $row;
721
-        }
722
-
723
-        public function unserialize($row)
724
-        {
725
-            foreach ($this->callback_parameters as $column)
726
-            {
727
-                if (is_array($row))
728
-                {
729
-                    $row[$column] = unserialize($row[$column]);
730
-                }
731
-                else
732
-                {
733
-                    $row->$column = unserialize($row->$column);
734
-                }
735
-            }
736
-            return $row;
737
-        }
738
-
739
-        /**
740
-         * Protect attributes by removing them from $row array
741
-         */
742
-        public function protect_attributes($row)
743
-        {
744
-            foreach ($this->protected_attributes as $attr)
745
-            {
746
-                if (is_object($row))
747
-                {
680
+		/**
681
+		 * MySQL DATETIME created_at and updated_at
682
+		 */
683
+		public function created_at($row)
684
+		{
685
+			if (is_object($row))
686
+			{
687
+				$row->created_at = date('Y-m-d H:i:s');
688
+			}
689
+			else
690
+			{
691
+				$row['created_at'] = date('Y-m-d H:i:s');
692
+			}
693
+
694
+			return $row;
695
+		}
696
+
697
+		public function updated_at($row)
698
+		{
699
+			if (is_object($row))
700
+			{
701
+				$row->updated_at = date('Y-m-d H:i:s');
702
+			}
703
+			else
704
+			{
705
+				$row['updated_at'] = date('Y-m-d H:i:s');
706
+			}
707
+			return $row;
708
+		}
709
+
710
+		/**
711
+		 * Serialises data for you automatically, allowing you to pass
712
+		 * through objects and let it handle the serialisation in the background
713
+		 */
714
+		public function serialize($row)
715
+		{
716
+			foreach ($this->callback_parameters as $column)
717
+			{
718
+				$row[$column] = serialize($row[$column]);
719
+			}
720
+			return $row;
721
+		}
722
+
723
+		public function unserialize($row)
724
+		{
725
+			foreach ($this->callback_parameters as $column)
726
+			{
727
+				if (is_array($row))
728
+				{
729
+					$row[$column] = unserialize($row[$column]);
730
+				}
731
+				else
732
+				{
733
+					$row->$column = unserialize($row->$column);
734
+				}
735
+			}
736
+			return $row;
737
+		}
738
+
739
+		/**
740
+		 * Protect attributes by removing them from $row array
741
+		 */
742
+		public function protect_attributes($row)
743
+		{
744
+			foreach ($this->protected_attributes as $attr)
745
+			{
746
+				if (is_object($row))
747
+				{
748 748
 					if(isset($row->$attr)){
749 749
 						unset($row->$attr);
750 750
 					}
751
-                }
752
-                else
753
-                {
751
+				}
752
+				else
753
+				{
754 754
 					if(isset($row[$attr])){
755 755
 						unset($row[$attr]);
756 756
 					}
757
-                }
758
-            }
759
-            return $row;
760
-        }
757
+				}
758
+			}
759
+			return $row;
760
+		}
761 761
 		
762 762
 		 /**
763
-         * Return the database instance
764
-         * @return Database the database instance
765
-         */
766
-        public function getDatabaseInstance(){
767
-            return $this->_database;
768
-        }
769
-
770
-        /**
771
-         * set the Database instance for future use
772
-         * @param Database $db the database object
773
-         */
774
-         public function setDatabaseInstance($db){
775
-            $this->_database = $db;
776
-            if($this->dbCacheTime > 0){
777
-                $this->_database->setCache($this->dbCacheTime);
778
-            }
779
-            return $this;
780
-        }
781
-
782
-        /**
783
-         * Return the loader instance
784
-         * @return Loader the loader instance
785
-         */
786
-        public function getLoader(){
787
-            return $this->loaderInstance;
788
-        }
789
-
790
-        /**
791
-         * set the loader instance for future use
792
-         * @param Loader $loader the loader object
793
-         */
794
-         public function setLoader($loader){
795
-            $this->loaderInstance = $loader;
796
-            return $this;
797
-        }
798
-
799
-        /**
800
-         * Return the FormValidation instance
801
-         * @return FormValidation the form validation instance
802
-         */
803
-        public function getFormValidation(){
804
-            return $this->formValidationInstance;
805
-        }
806
-
807
-        /**
808
-         * set the form validation instance for future use
809
-         * @param FormValidation $fv the form validation object
810
-         */
811
-         public function setFormValidation($fv){
812
-            $this->formValidationInstance = $fv;
813
-            return $this;
814
-        }
815
-
816
-        /* --------------------------------------------------------------
763
+		  * Return the database instance
764
+		  * @return Database the database instance
765
+		  */
766
+		public function getDatabaseInstance(){
767
+			return $this->_database;
768
+		}
769
+
770
+		/**
771
+		 * set the Database instance for future use
772
+		 * @param Database $db the database object
773
+		 */
774
+		 public function setDatabaseInstance($db){
775
+			$this->_database = $db;
776
+			if($this->dbCacheTime > 0){
777
+				$this->_database->setCache($this->dbCacheTime);
778
+			}
779
+			return $this;
780
+		}
781
+
782
+		/**
783
+		 * Return the loader instance
784
+		 * @return Loader the loader instance
785
+		 */
786
+		public function getLoader(){
787
+			return $this->loaderInstance;
788
+		}
789
+
790
+		/**
791
+		 * set the loader instance for future use
792
+		 * @param Loader $loader the loader object
793
+		 */
794
+		 public function setLoader($loader){
795
+			$this->loaderInstance = $loader;
796
+			return $this;
797
+		}
798
+
799
+		/**
800
+		 * Return the FormValidation instance
801
+		 * @return FormValidation the form validation instance
802
+		 */
803
+		public function getFormValidation(){
804
+			return $this->formValidationInstance;
805
+		}
806
+
807
+		/**
808
+		 * set the form validation instance for future use
809
+		 * @param FormValidation $fv the form validation object
810
+		 */
811
+		 public function setFormValidation($fv){
812
+			$this->formValidationInstance = $fv;
813
+			return $this;
814
+		}
815
+
816
+		/* --------------------------------------------------------------
817 817
          * QUERY BUILDER DIRECT ACCESS METHODS
818 818
          * ------------------------------------------------------------ */
819 819
 
820
-        /**
821
-         * A wrapper to $this->_database->orderBy()
822
-         */
823
-        public function order_by($criteria, $order = 'ASC')
824
-        {
825
-            if ( is_array($criteria) )
826
-            {
827
-                foreach ($criteria as $key => $value)
828
-                {
829
-                    $this->_database->orderBy($key, $value);
830
-                }
831
-            }
832
-            else
833
-            {
834
-                $this->_database->orderBy($criteria, $order);
835
-            }
836
-            return $this;
837
-        }
838
-
839
-        /**
840
-         * A wrapper to $this->_database->limit()
841
-         */
842
-        public function limit($offset = 0, $limit = 10)
843
-        {
844
-            $this->_database->limit($offset, $limit);
845
-            return $this;
846
-        }
847
-
848
-        /* --------------------------------------------------------------
820
+		/**
821
+		 * A wrapper to $this->_database->orderBy()
822
+		 */
823
+		public function order_by($criteria, $order = 'ASC')
824
+		{
825
+			if ( is_array($criteria) )
826
+			{
827
+				foreach ($criteria as $key => $value)
828
+				{
829
+					$this->_database->orderBy($key, $value);
830
+				}
831
+			}
832
+			else
833
+			{
834
+				$this->_database->orderBy($criteria, $order);
835
+			}
836
+			return $this;
837
+		}
838
+
839
+		/**
840
+		 * A wrapper to $this->_database->limit()
841
+		 */
842
+		public function limit($offset = 0, $limit = 10)
843
+		{
844
+			$this->_database->limit($offset, $limit);
845
+			return $this;
846
+		}
847
+
848
+		/* --------------------------------------------------------------
849 849
          * INTERNAL METHODS
850 850
          * ------------------------------------------------------------ */
851 851
 
852
-        /**
853
-         * Trigger an event and call its observers. Pass through the event name
854
-         * (which looks for an instance variable $this->event_name), an array of
855
-         * parameters to pass through and an optional 'last in interation' boolean
856
-         */
857
-        protected function trigger($event, $data = FALSE, $last = TRUE)
858
-        {
859
-            if (isset($this->$event) && is_array($this->$event))
860
-            {
861
-                foreach ($this->$event as $method)
862
-                {
863
-                    if (strpos($method, '('))
864
-                    {
865
-                        preg_match('/([a-zA-Z0-9\_\-]+)(\(([a-zA-Z0-9\_\-\., ]+)\))?/', $method, $matches);
866
-
867
-                        $method = $matches[1];
868
-                        $this->callback_parameters = explode(',', $matches[3]);
869
-                    }
870
-                    $data = call_user_func_array(array($this, $method), array($data, $last));
871
-                }
872
-            }
873
-            return $data;
874
-        }
875
-
876
-        /**
877
-         * Run validation on the passed data
878
-         */
879
-        protected function validate(array $data)
880
-        {
881
-            if($this->skip_validation)
882
-            {
883
-                return $data;
884
-            }
885
-            if(!empty($this->validate))
886
-            {
887
-                $fv = null;
888
-                if(is_object($this->formValidationInstance)){
889
-                    $fv = $this->formValidationInstance;
890
-                }
891
-                else{
892
-                    Loader::library('FormValidation');
893
-                    $fv = $this->formvalidation;
894
-                    $this->setFormValidation($fv);
895
-                }
852
+		/**
853
+		 * Trigger an event and call its observers. Pass through the event name
854
+		 * (which looks for an instance variable $this->event_name), an array of
855
+		 * parameters to pass through and an optional 'last in interation' boolean
856
+		 */
857
+		protected function trigger($event, $data = FALSE, $last = TRUE)
858
+		{
859
+			if (isset($this->$event) && is_array($this->$event))
860
+			{
861
+				foreach ($this->$event as $method)
862
+				{
863
+					if (strpos($method, '('))
864
+					{
865
+						preg_match('/([a-zA-Z0-9\_\-]+)(\(([a-zA-Z0-9\_\-\., ]+)\))?/', $method, $matches);
866
+
867
+						$method = $matches[1];
868
+						$this->callback_parameters = explode(',', $matches[3]);
869
+					}
870
+					$data = call_user_func_array(array($this, $method), array($data, $last));
871
+				}
872
+			}
873
+			return $data;
874
+		}
875
+
876
+		/**
877
+		 * Run validation on the passed data
878
+		 */
879
+		protected function validate(array $data)
880
+		{
881
+			if($this->skip_validation)
882
+			{
883
+				return $data;
884
+			}
885
+			if(!empty($this->validate))
886
+			{
887
+				$fv = null;
888
+				if(is_object($this->formValidationInstance)){
889
+					$fv = $this->formValidationInstance;
890
+				}
891
+				else{
892
+					Loader::library('FormValidation');
893
+					$fv = $this->formvalidation;
894
+					$this->setFormValidation($fv);
895
+				}
896 896
                
897
-                $fv->setData($data);
898
-                $fv->setRules($this->validate);
899
-
900
-                if ($fv->run())
901
-                {
902
-                    return $data;
903
-                }
904
-                else
905
-                {
906
-                    return FALSE;
907
-                }
908
-            }
909
-            else
910
-            {
911
-                return $data;
912
-            }
913
-        }
914
-
915
-
916
-        /**
917
-         * Set WHERE parameters, cleverly
918
-         */
919
-        protected function _set_where($params)
920
-        {
921
-            if (count($params) == 1 && is_array($params[0]))
922
-            {
923
-                foreach ($params[0] as $field => $filter)
924
-                {
925
-                    if (is_array($filter))
926
-                    {
927
-                        $this->_database->in($field, $filter);
928
-                    }
929
-                    else
930
-                    {
931
-                        if (is_int($field))
932
-                        {
933
-                            $this->_database->where($filter);
934
-                        }
935
-                        else
936
-                        {
937
-                            $this->_database->where($field, $filter);
938
-                        }
939
-                    }
940
-                }
941
-            }
942
-            else if (count($params) == 1)
943
-            {
944
-                $this->_database->where($params[0]);
945
-            }
946
-        	else if(count($params) == 2)
947
-    		{
948
-                if (is_array($params[1]))
949
-                {
950
-                    $this->_database->in($params[0], $params[1]);
951
-                }
952
-                else
953
-                {
954
-                    $this->_database->where($params[0], $params[1]);
955
-                }
956
-    		}
957
-    		else if(count($params) == 3)
958
-    		{
959
-    			$this->_database->where($params[0], $params[1], $params[2]);
960
-    		}
961
-            else
962
-            {
963
-                if (is_array($params[1]))
964
-                {
965
-                    $this->_database->in($params[0], $params[1]);
966
-                }
967
-                else
968
-                {
969
-                    $this->_database->where($params[0], $params[1]);
970
-                }
971
-            }
972
-        }
973
-
974
-        /**
897
+				$fv->setData($data);
898
+				$fv->setRules($this->validate);
899
+
900
+				if ($fv->run())
901
+				{
902
+					return $data;
903
+				}
904
+				else
905
+				{
906
+					return FALSE;
907
+				}
908
+			}
909
+			else
910
+			{
911
+				return $data;
912
+			}
913
+		}
914
+
915
+
916
+		/**
917
+		 * Set WHERE parameters, cleverly
918
+		 */
919
+		protected function _set_where($params)
920
+		{
921
+			if (count($params) == 1 && is_array($params[0]))
922
+			{
923
+				foreach ($params[0] as $field => $filter)
924
+				{
925
+					if (is_array($filter))
926
+					{
927
+						$this->_database->in($field, $filter);
928
+					}
929
+					else
930
+					{
931
+						if (is_int($field))
932
+						{
933
+							$this->_database->where($filter);
934
+						}
935
+						else
936
+						{
937
+							$this->_database->where($field, $filter);
938
+						}
939
+					}
940
+				}
941
+			}
942
+			else if (count($params) == 1)
943
+			{
944
+				$this->_database->where($params[0]);
945
+			}
946
+			else if(count($params) == 2)
947
+			{
948
+				if (is_array($params[1]))
949
+				{
950
+					$this->_database->in($params[0], $params[1]);
951
+				}
952
+				else
953
+				{
954
+					$this->_database->where($params[0], $params[1]);
955
+				}
956
+			}
957
+			else if(count($params) == 3)
958
+			{
959
+				$this->_database->where($params[0], $params[1], $params[2]);
960
+			}
961
+			else
962
+			{
963
+				if (is_array($params[1]))
964
+				{
965
+					$this->_database->in($params[0], $params[1]);
966
+				}
967
+				else
968
+				{
969
+					$this->_database->where($params[0], $params[1]);
970
+				}
971
+			}
972
+		}
973
+
974
+		/**
975 975
             Shortcut to controller
976
-        */
977
-        public function __get($key){
978
-            return get_instance()->{$key};
979
-        }
976
+		 */
977
+		public function __get($key){
978
+			return get_instance()->{$key};
979
+		}
980 980
 
981
-    }
981
+	}
Please login to merge, or discard this patch.
core/classes/Response.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  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
 	class Response{
28 28
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 		private $_currentUrlCacheKey = null;
58 58
 		
59 59
 		/**
60
-		* Whether we can compress the output using Gzip
61
-		* @var boolean
62
-		*/
60
+		 * Whether we can compress the output using Gzip
61
+		 * @var boolean
62
+		 */
63 63
 		private static $_canCompressOutput = false;
64 64
 		
65 65
 		/**
@@ -236,8 +236,8 @@  discard block
 block discarded – undo
236 236
 		}
237 237
 		
238 238
 		/**
239
-		* Send the final page output to user
240
-		*/
239
+		 * Send the final page output to user
240
+		 */
241 241
 		public function renderFinalPage(){
242 242
 			$logger = self::getLogger();
243 243
 			$obj = & get_instance();
@@ -301,8 +301,8 @@  discard block
 block discarded – undo
301 301
 		}
302 302
 		
303 303
 		/**
304
-		* Send the final page output to user if is cached
305
-		*/
304
+		 * Send the final page output to user if is cached
305
+		 */
306 306
 		public function renderFinalPageFromCache(&$cache){
307 307
 			$logger = self::getLogger();
308 308
 			$url = $this->_currentUrl;					
@@ -362,9 +362,9 @@  discard block
 block discarded – undo
362 362
 		}
363 363
 		
364 364
 		/**
365
-		* Get the final page to be rendered
366
-		* @return string
367
-		*/
365
+		 * Get the final page to be rendered
366
+		 * @return string
367
+		 */
368 368
 		public function getFinalPageRendered(){
369 369
 			return $this->_pageRender;
370 370
 		}
Please login to merge, or discard this patch.
core/classes/EventInfo.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@
 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
 	 * This class represent the event detail to dispatch to correspond listener
Please login to merge, or discard this patch.
core/classes/Database.php 1 patch
Indentation   +1289 added lines, -1289 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-    defined('ROOT_PATH') || exit('Access denied');
2
+	defined('ROOT_PATH') || exit('Access denied');
3 3
   /**
4 4
    * TNH Framework
5 5
    *
@@ -22,1198 +22,1198 @@  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
   class Database{
27 27
 	
28 28
 	/**
29 29
 	 * The PDO instance
30 30
 	 * @var object
31
-	*/
32
-    private $pdo                 = null;
31
+	 */
32
+	private $pdo                 = null;
33 33
     
34 34
 	/**
35 35
 	 * The database name used for the application
36 36
 	 * @var string
37
-	*/
37
+	 */
38 38
 	private $databaseName        = null;
39 39
     
40 40
 	/**
41 41
 	 * The SQL SELECT statment
42 42
 	 * @var string
43
-	*/
43
+	 */
44 44
 	private $select              = '*';
45 45
 	
46 46
 	/**
47 47
 	 * The SQL FROM statment
48 48
 	 * @var string
49
-	*/
50
-    private $from                = null;
49
+	 */
50
+	private $from                = null;
51 51
 	
52 52
 	/**
53 53
 	 * The SQL WHERE statment
54 54
 	 * @var string
55
-	*/
56
-    private $where               = null;
55
+	 */
56
+	private $where               = null;
57 57
 	
58 58
 	/**
59 59
 	 * The SQL LIMIT statment
60 60
 	 * @var string
61
-	*/
62
-    private $limit               = null;
61
+	 */
62
+	private $limit               = null;
63 63
 	
64 64
 	/**
65 65
 	 * The SQL JOIN statment
66 66
 	 * @var string
67
-	*/
68
-    private $join                = null;
67
+	 */
68
+	private $join                = null;
69 69
 	
70 70
 	/**
71 71
 	 * The SQL ORDER BY statment
72 72
 	 * @var string
73
-	*/
74
-    private $orderBy             = null;
73
+	 */
74
+	private $orderBy             = null;
75 75
 	
76 76
 	/**
77 77
 	 * The SQL GROUP BY statment
78 78
 	 * @var string
79
-	*/
80
-    private $groupBy             = null;
79
+	 */
80
+	private $groupBy             = null;
81 81
 	
82 82
 	/**
83 83
 	 * The SQL HAVING statment
84 84
 	 * @var string
85
-	*/
86
-    private $having              = null;
85
+	 */
86
+	private $having              = null;
87 87
 	
88 88
 	/**
89 89
 	 * The number of rows returned by the last query
90 90
 	 * @var int
91
-	*/
92
-    private $numRows             = 0;
91
+	 */
92
+	private $numRows             = 0;
93 93
 	
94 94
 	/**
95 95
 	 * The last insert id for the primary key column that have auto increment or sequence
96 96
 	 * @var mixed
97
-	*/
98
-    private $insertId            = null;
97
+	 */
98
+	private $insertId            = null;
99 99
 	
100 100
 	/**
101 101
 	 * The full SQL query statment after build for each command
102 102
 	 * @var string
103
-	*/
104
-    private $query               = null;
103
+	 */
104
+	private $query               = null;
105 105
 	
106 106
 	/**
107 107
 	 * The error returned for the last query
108 108
 	 * @var string
109
-	*/
110
-    private $error               = null;
109
+	 */
110
+	private $error               = null;
111 111
 	
112 112
 	/**
113 113
 	 * The result returned for the last query
114 114
 	 * @var mixed
115
-	*/
116
-    private $result              = array();
115
+	 */
116
+	private $result              = array();
117 117
 	
118 118
 	/**
119 119
 	 * The prefix used in each database table
120 120
 	 * @var string
121
-	*/
122
-    private $prefix              = null;
121
+	 */
122
+	private $prefix              = null;
123 123
 	
124 124
 	/**
125 125
 	 * The list of SQL valid operators
126 126
 	 * @var array
127
-	*/
128
-    private $operatorList        = array('=','!=','<','>','<=','>=','<>');
127
+	 */
128
+	private $operatorList        = array('=','!=','<','>','<=','>=','<>');
129 129
     
130 130
 	/**
131 131
 	 * The cache default time to live in second. 0 means no need to use the cache feature
132 132
 	 * @var int
133
-	*/
133
+	 */
134 134
 	private $cacheTtl              = 0;
135 135
 	
136 136
 	/**
137 137
 	 * The cache current time to live. 0 means no need to use the cache feature
138 138
 	 * @var int
139
-	*/
140
-    private $temporaryCacheTtl   = 0;
139
+	 */
140
+	private $temporaryCacheTtl   = 0;
141 141
 	
142 142
 	/**
143 143
 	 * The number of executed query for the current request
144 144
 	 * @var int
145
-	*/
146
-    private $queryCount          = 0;
145
+	 */
146
+	private $queryCount          = 0;
147 147
 	
148 148
 	/**
149 149
 	 * The default data to be used in the statments query INSERT, UPDATE
150 150
 	 * @var array
151
-	*/
152
-    private $data                = array();
151
+	 */
152
+	private $data                = array();
153 153
 	
154 154
 	/**
155 155
 	 * The database configuration
156 156
 	 * @var array
157
-	*/
158
-    private $config              = array();
157
+	 */
158
+	private $config              = array();
159 159
 	
160 160
 	/**
161 161
 	 * The logger instance
162 162
 	 * @var Log
163 163
 	 */
164
-    private $logger              = null;
164
+	private $logger              = null;
165 165
 
166 166
 
167
-    /**
168
-    * The cache instance
169
-    * @var CacheInterface
170
-    */
171
-    private $cacheInstance       = null;
167
+	/**
168
+	 * The cache instance
169
+	 * @var CacheInterface
170
+	 */
171
+	private $cacheInstance       = null;
172 172
 
173
-     /**
174
-    * The benchmark instance
175
-    * @var Benchmark
176
-    */
177
-    private $benchmarkInstance   = null;
173
+	 /**
174
+	  * The benchmark instance
175
+	  * @var Benchmark
176
+	  */
177
+	private $benchmarkInstance   = null;
178 178
 
179 179
 
180
-    /**
181
-     * Construct new database
182
-     * @param array $overwriteConfig the config to overwrite with the config set in database.php
183
-     */
184
-    public function __construct($overwriteConfig = array()){
185
-        //Set Log instance to use
186
-        $this->setLoggerFromParamOrCreateNewInstance(null);
180
+	/**
181
+	 * Construct new database
182
+	 * @param array $overwriteConfig the config to overwrite with the config set in database.php
183
+	 */
184
+	public function __construct($overwriteConfig = array()){
185
+		//Set Log instance to use
186
+		$this->setLoggerFromParamOrCreateNewInstance(null);
187 187
 
188
-        //Set global configuration using the config file
189
-        $this->setDatabaseConfigurationFromConfigFile($overwriteConfig);
188
+		//Set global configuration using the config file
189
+		$this->setDatabaseConfigurationFromConfigFile($overwriteConfig);
190 190
         
191
-    		$this->temporaryCacheTtl = $this->cacheTtl;
192
-    }
193
-
194
-    /**
195
-     * This is used to connect to database
196
-     * @return bool 
197
-     */
198
-    public function connect(){
199
-      $config = $this->getDatabaseConfiguration();
200
-      if(! empty($config)){
201
-        try{
202
-            $this->pdo = new PDO($this->getDsnFromDriver(), $config['username'], $config['password']);
203
-            $this->pdo->exec("SET NAMES '" . $config['charset'] . "' COLLATE '" . $config['collation'] . "'");
204
-            $this->pdo->exec("SET CHARACTER SET '" . $config['charset'] . "'");
205
-            $this->pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
206
-            return true;
207
-          }
208
-          catch (PDOException $e){
209
-            $this->logger->fatal($e->getMessage());
210
-            show_error('Cannot connect to Database.');
211
-            return false;
212
-          }
213
-      }
214
-      else{
215
-        show_error('Database configuration is not set.');
216
-        return false;
217
-      }
218
-    }
219
-
220
-    /**
221
-     * Set the SQL FROM statment
222
-     * @param  string|array $table the table name or array of table list
223
-     * @return object        the current Database instance
224
-     */
225
-    public function from($table){
226
-      if(is_array($table)){
227
-        $froms = '';
228
-        foreach($table as $key){
229
-          $froms .= $this->prefix . $key . ', ';
230
-        }
231
-        $this->from = rtrim($froms, ', ');
232
-      }
233
-      else{
234
-        $this->from = $this->prefix . $table;
235
-      }
236
-      return $this;
237
-    }
238
-
239
-    /**
240
-     * Set the SQL SELECT statment
241
-     * @param  string|array $fields the field name or array of field list
242
-     * @return object        the current Database instance
243
-     */
244
-    public function select($fields){
245
-      $select = (is_array($fields) ? implode(', ', $fields) : $fields);
246
-      $this->select = ($this->select == '*' ? $select : $this->select . ', ' . $select);
247
-      return $this;
248
-    }
249
-
250
-    /**
251
-     * Set the SQL SELECT DISTINCT statment
252
-     * @param  string $field the field name to distinct
253
-     * @return object        the current Database instance
254
-     */
255
-    public function distinct($field){
256
-      $distinct = ' DISTINCT ' . $field;
257
-      $this->select = ($this->select == '*' ? $distinct : $this->select . ', ' . $distinct);
258
-
259
-      return $this;
260
-    }
261
-
262
-    /**
263
-     * Set the SQL function MAX in SELECT statment
264
-     * @param  string $field the field name
265
-     * @param  string $name  if is not null represent the alias used for this field in the result
266
-     * @return object        the current Database instance
267
-     */
268
-    public function max($field, $name = null){
269
-      $func = 'MAX(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
270
-      $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
271
-      return $this;
272
-    }
273
-
274
-    /**
275
-     * Set the SQL function MIN in SELECT statment
276
-     * @param  string $field the field name
277
-     * @param  string $name  if is not null represent the alias used for this field in the result
278
-     * @return object        the current Database instance
279
-     */
280
-    public function min($field, $name = null){
281
-      $func = 'MIN(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
282
-      $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
283
-      return $this;
284
-    }
285
-
286
-    /**
287
-     * Set the SQL function SUM in SELECT statment
288
-     * @param  string $field the field name
289
-     * @param  string $name  if is not null represent the alias used for this field in the result
290
-     * @return object        the current Database instance
291
-     */
292
-    public function sum($field, $name = null){
293
-      $func = 'SUM(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
294
-      $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
295
-      return $this;
296
-    }
297
-
298
-    /**
299
-     * Set the SQL function COUNT in SELECT statment
300
-     * @param  string $field the field name
301
-     * @param  string $name  if is not null represent the alias used for this field in the result
302
-     * @return object        the current Database instance
303
-     */
304
-    public function count($field = '*', $name = null){
305
-      $func = 'COUNT(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
306
-      $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
307
-      return $this;
308
-    }
309
-
310
-    /**
311
-     * Set the SQL function AVG in SELECT statment
312
-     * @param  string $field the field name
313
-     * @param  string $name  if is not null represent the alias used for this field in the result
314
-     * @return object        the current Database instance
315
-     */
316
-    public function avg($field, $name = null){
317
-      $func = 'AVG(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
318
-      $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
319
-      return $this;
320
-    }
321
-
322
-    /**
323
-     * Set the SQL JOIN statment
324
-     * @param  string $table  the join table name
325
-     * @param  string $field1 the first field for join conditions	
326
-     * @param  string $op     the join condition operator. If is null the default will be "="
327
-     * @param  string $field2 the second field for join conditions
328
-     * @param  string $type   the type of join (INNER, LEFT, RIGHT)
329
-     * @return object        the current Database instance
330
-     */
331
-    public function join($table, $field1 = null, $op = null, $field2 = null, $type = ''){
332
-      $on = $field1;
333
-      $table = $this->prefix . $table;
334
-      if(! is_null($op)){
335
-        $on = (! in_array($op, $this->operatorList) ? $this->prefix . $field1 . ' = ' . $this->prefix . $op : $this->prefix . $field1 . ' ' . $op . ' ' . $this->prefix . $field2);
336
-      }
337
-      if (empty($this->join)){
338
-        $this->join = ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
339
-      }
340
-      else{
341
-        $this->join = $this->join . ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
342
-      }
343
-      return $this;
344
-    }
345
-
346
-    /**
347
-     * Set the SQL INNER JOIN statment
348
-     * @see  Database::join()
349
-     * @return object        the current Database instance
350
-     */
351
-    public function innerJoin($table, $field1, $op = null, $field2 = ''){
352
-      return $this->join($table, $field1, $op, $field2, 'INNER ');
353
-    }
354
-
355
-    /**
356
-     * Set the SQL LEFT JOIN statment
357
-     * @see  Database::join()
358
-     * @return object        the current Database instance
359
-     */
360
-    public function leftJoin($table, $field1, $op = null, $field2 = ''){
361
-      return $this->join($table, $field1, $op, $field2, 'LEFT ');
362
-	}
363
-
364
-	/**
365
-     * Set the SQL RIGHT JOIN statment
366
-     * @see  Database::join()
367
-     * @return object        the current Database instance
368
-     */
369
-    public function rightJoin($table, $field1, $op = null, $field2 = ''){
370
-      return $this->join($table, $field1, $op, $field2, 'RIGHT ');
371
-    }
372
-
373
-    /**
374
-     * Set the SQL FULL OUTER JOIN statment
375
-     * @see  Database::join()
376
-     * @return object        the current Database instance
377
-     */
378
-    public function fullOuterJoin($table, $field1, $op = null, $field2 = ''){
379
-    	return $this->join($table, $field1, $op, $field2, 'FULL OUTER ');
380
-    }
381
-
382
-    /**
383
-     * Set the SQL LEFT OUTER JOIN statment
384
-     * @see  Database::join()
385
-     * @return object        the current Database instance
386
-     */
387
-    public function leftOuterJoin($table, $field1, $op = null, $field2 = ''){
388
-      return $this->join($table, $field1, $op, $field2, 'LEFT OUTER ');
389
-    }
390
-
391
-    /**
392
-     * Set the SQL RIGHT OUTER JOIN statment
393
-     * @see  Database::join()
394
-     * @return object        the current Database instance
395
-     */
396
-    public function rightOuterJoin($table, $field1, $op = null, $field2 = ''){
397
-      return $this->join($table, $field1, $op, $field2, 'RIGHT OUTER ');
398
-    }
399
-
400
-    /**
401
-     * Set the SQL WHERE CLAUSE for IS NULL
402
-     * @param  string|array $field  the field name or array of field list
403
-     * @param  string $andOr the separator type used 'AND', 'OR', etc.
404
-     * @return object        the current Database instance
405
-     */
406
-    public function whereIsNull($field, $andOr = 'AND'){
407
-      if(is_array($field)){
408
-        foreach($field as $f){
409
-        	$this->whereIsNull($f, $andOr);
410
-        }
411
-      }
412
-      else{
413
-        if (! $this->where){
414
-          $this->where = $field.' IS NULL ';
415
-        }
416
-        else{
417
-            $this->where = $this->where . ' '.$andOr.' ' . $field.' IS NULL ';
418
-          }
419
-      }
420
-      return $this;
421
-    }
422
-
423
-    /**
424
-     * Set the SQL WHERE CLAUSE for IS NOT NULL
425
-     * @param  string|array $field  the field name or array of field list
426
-     * @param  string $andOr the separator type used 'AND', 'OR', etc.
427
-     * @return object        the current Database instance
428
-     */
429
-    public function whereIsNotNull($field, $andOr = 'AND'){
430
-      if(is_array($field)){
431
-        foreach($field as $f){
432
-          $this->whereIsNotNull($f, $andOr);
433
-        }
434
-      }
435
-      else{
436
-        if (! $this->where){
437
-          $this->where = $field.' IS NOT NULL ';
438
-        }
439
-        else{
440
-            $this->where = $this->where . ' '.$andOr.' ' . $field.' IS NOT NULL ';
441
-          }
442
-      }
443
-      return $this;
444
-    }
445
-
446
-    /**
447
-     * Get the SQL WHERE clause using array column => value
448
-     * @see Database::where
449
-     *
450
-     * @return string
451
-     */
452
-    protected function getWhereStrIfIsArray(array $where, $type = '', $andOr = 'AND', $escape = true){
453
-        $_where = array();
454
-        foreach ($where as $column => $data){
455
-          if(is_null($data)){
456
-            $data = '';
457
-          }
458
-          $_where[] = $type . $column . ' = ' . ($escape ? $this->escape($data) : $data);
459
-        }
460
-        $where = implode(' '.$andOr.' ', $_where);
461
-        return $where;
462
-    }
463
-
464
-     /**
465
-     * Get the SQL WHERE clause when operator argument is an array
466
-     * @see Database::where
467
-     *
468
-     * @return string
469
-     */
470
-    protected function getWhereStrIfOperatorIsArray($where, array $op, $type = '', $escape = true){
471
-       $x = explode('?', $where);
472
-       $w = '';
473
-        foreach($x as $k => $v){
474
-          if(! empty($v)){
475
-              if(isset($op[$k]) && is_null($op[$k])){
476
-                $op[$k] = '';
477
-              }
478
-              $w .= $type . $v . (isset($op[$k]) ? ($escape ? $this->escape($op[$k]) : $op[$k]) : '');
479
-          }
480
-        }
481
-        return $w;
482
-    }
483
-
484
-    /**
485
-     * Get the default SQL WHERE clause using operator = or the operator argument
486
-     * @see Database::where
487
-     *
488
-     * @return string
489
-     */
490
-    protected function getWhereStrForOperator($where, $op = null, $val = null, $type = '', $escape = true){
491
-       $w = '';
492
-       if (! in_array((string)$op, $this->operatorList)){
493
-          if(is_null($op)){
494
-            $op = '';
495
-          }
496
-          $w = $type . $where . ' = ' . ($escape ? $this->escape($op) : $op);
497
-        }
498
-        else{
499
-          if(is_null($val)){
500
-            $val = '';
501
-          }
502
-          $w = $type . $where . $op . ($escape ? $this->escape($val) : $val);
503
-        }
504
-        return $w;
505
-      }
506
-
507
-      /**
508
-       * Set the $this->where property 
509
-       * @param string $whereStr the WHERE clause string
510
-       * @param  string  $andOr the separator type used 'AND', 'OR', etc.
511
-       */
512
-      protected function setWhereStr($whereStr, $andOr = 'AND'){
513
-        if (empty($this->where)){
514
-          $this->where = $whereStr;
515
-        }
516
-        else{
517
-          if(substr($this->where, -1) == '('){
518
-            $this->where = $this->where . ' ' . $whereStr;
519
-          }
520
-          else{
521
-            $this->where = $this->where . ' '.$andOr.' ' . $whereStr;
522
-          }
523
-        }
524
-      }
191
+			$this->temporaryCacheTtl = $this->cacheTtl;
192
+	}
193
+
194
+	/**
195
+	 * This is used to connect to database
196
+	 * @return bool 
197
+	 */
198
+	public function connect(){
199
+	  $config = $this->getDatabaseConfiguration();
200
+	  if(! empty($config)){
201
+		try{
202
+			$this->pdo = new PDO($this->getDsnFromDriver(), $config['username'], $config['password']);
203
+			$this->pdo->exec("SET NAMES '" . $config['charset'] . "' COLLATE '" . $config['collation'] . "'");
204
+			$this->pdo->exec("SET CHARACTER SET '" . $config['charset'] . "'");
205
+			$this->pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
206
+			return true;
207
+		  }
208
+		  catch (PDOException $e){
209
+			$this->logger->fatal($e->getMessage());
210
+			show_error('Cannot connect to Database.');
211
+			return false;
212
+		  }
213
+	  }
214
+	  else{
215
+		show_error('Database configuration is not set.');
216
+		return false;
217
+	  }
218
+	}
219
+
220
+	/**
221
+	 * Set the SQL FROM statment
222
+	 * @param  string|array $table the table name or array of table list
223
+	 * @return object        the current Database instance
224
+	 */
225
+	public function from($table){
226
+	  if(is_array($table)){
227
+		$froms = '';
228
+		foreach($table as $key){
229
+		  $froms .= $this->prefix . $key . ', ';
230
+		}
231
+		$this->from = rtrim($froms, ', ');
232
+	  }
233
+	  else{
234
+		$this->from = $this->prefix . $table;
235
+	  }
236
+	  return $this;
237
+	}
238
+
239
+	/**
240
+	 * Set the SQL SELECT statment
241
+	 * @param  string|array $fields the field name or array of field list
242
+	 * @return object        the current Database instance
243
+	 */
244
+	public function select($fields){
245
+	  $select = (is_array($fields) ? implode(', ', $fields) : $fields);
246
+	  $this->select = ($this->select == '*' ? $select : $this->select . ', ' . $select);
247
+	  return $this;
248
+	}
249
+
250
+	/**
251
+	 * Set the SQL SELECT DISTINCT statment
252
+	 * @param  string $field the field name to distinct
253
+	 * @return object        the current Database instance
254
+	 */
255
+	public function distinct($field){
256
+	  $distinct = ' DISTINCT ' . $field;
257
+	  $this->select = ($this->select == '*' ? $distinct : $this->select . ', ' . $distinct);
258
+
259
+	  return $this;
260
+	}
261
+
262
+	/**
263
+	 * Set the SQL function MAX in SELECT statment
264
+	 * @param  string $field the field name
265
+	 * @param  string $name  if is not null represent the alias used for this field in the result
266
+	 * @return object        the current Database instance
267
+	 */
268
+	public function max($field, $name = null){
269
+	  $func = 'MAX(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
270
+	  $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
271
+	  return $this;
272
+	}
273
+
274
+	/**
275
+	 * Set the SQL function MIN in SELECT statment
276
+	 * @param  string $field the field name
277
+	 * @param  string $name  if is not null represent the alias used for this field in the result
278
+	 * @return object        the current Database instance
279
+	 */
280
+	public function min($field, $name = null){
281
+	  $func = 'MIN(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
282
+	  $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
283
+	  return $this;
284
+	}
285
+
286
+	/**
287
+	 * Set the SQL function SUM in SELECT statment
288
+	 * @param  string $field the field name
289
+	 * @param  string $name  if is not null represent the alias used for this field in the result
290
+	 * @return object        the current Database instance
291
+	 */
292
+	public function sum($field, $name = null){
293
+	  $func = 'SUM(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
294
+	  $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
295
+	  return $this;
296
+	}
297
+
298
+	/**
299
+	 * Set the SQL function COUNT in SELECT statment
300
+	 * @param  string $field the field name
301
+	 * @param  string $name  if is not null represent the alias used for this field in the result
302
+	 * @return object        the current Database instance
303
+	 */
304
+	public function count($field = '*', $name = null){
305
+	  $func = 'COUNT(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
306
+	  $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
307
+	  return $this;
308
+	}
309
+
310
+	/**
311
+	 * Set the SQL function AVG in SELECT statment
312
+	 * @param  string $field the field name
313
+	 * @param  string $name  if is not null represent the alias used for this field in the result
314
+	 * @return object        the current Database instance
315
+	 */
316
+	public function avg($field, $name = null){
317
+	  $func = 'AVG(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
318
+	  $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
319
+	  return $this;
320
+	}
321
+
322
+	/**
323
+	 * Set the SQL JOIN statment
324
+	 * @param  string $table  the join table name
325
+	 * @param  string $field1 the first field for join conditions	
326
+	 * @param  string $op     the join condition operator. If is null the default will be "="
327
+	 * @param  string $field2 the second field for join conditions
328
+	 * @param  string $type   the type of join (INNER, LEFT, RIGHT)
329
+	 * @return object        the current Database instance
330
+	 */
331
+	public function join($table, $field1 = null, $op = null, $field2 = null, $type = ''){
332
+	  $on = $field1;
333
+	  $table = $this->prefix . $table;
334
+	  if(! is_null($op)){
335
+		$on = (! in_array($op, $this->operatorList) ? $this->prefix . $field1 . ' = ' . $this->prefix . $op : $this->prefix . $field1 . ' ' . $op . ' ' . $this->prefix . $field2);
336
+	  }
337
+	  if (empty($this->join)){
338
+		$this->join = ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
339
+	  }
340
+	  else{
341
+		$this->join = $this->join . ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
342
+	  }
343
+	  return $this;
344
+	}
345
+
346
+	/**
347
+	 * Set the SQL INNER JOIN statment
348
+	 * @see  Database::join()
349
+	 * @return object        the current Database instance
350
+	 */
351
+	public function innerJoin($table, $field1, $op = null, $field2 = ''){
352
+	  return $this->join($table, $field1, $op, $field2, 'INNER ');
353
+	}
354
+
355
+	/**
356
+	 * Set the SQL LEFT JOIN statment
357
+	 * @see  Database::join()
358
+	 * @return object        the current Database instance
359
+	 */
360
+	public function leftJoin($table, $field1, $op = null, $field2 = ''){
361
+	  return $this->join($table, $field1, $op, $field2, 'LEFT ');
362
+	}
363
+
364
+	/**
365
+	 * Set the SQL RIGHT JOIN statment
366
+	 * @see  Database::join()
367
+	 * @return object        the current Database instance
368
+	 */
369
+	public function rightJoin($table, $field1, $op = null, $field2 = ''){
370
+	  return $this->join($table, $field1, $op, $field2, 'RIGHT ');
371
+	}
372
+
373
+	/**
374
+	 * Set the SQL FULL OUTER JOIN statment
375
+	 * @see  Database::join()
376
+	 * @return object        the current Database instance
377
+	 */
378
+	public function fullOuterJoin($table, $field1, $op = null, $field2 = ''){
379
+		return $this->join($table, $field1, $op, $field2, 'FULL OUTER ');
380
+	}
381
+
382
+	/**
383
+	 * Set the SQL LEFT OUTER JOIN statment
384
+	 * @see  Database::join()
385
+	 * @return object        the current Database instance
386
+	 */
387
+	public function leftOuterJoin($table, $field1, $op = null, $field2 = ''){
388
+	  return $this->join($table, $field1, $op, $field2, 'LEFT OUTER ');
389
+	}
390
+
391
+	/**
392
+	 * Set the SQL RIGHT OUTER JOIN statment
393
+	 * @see  Database::join()
394
+	 * @return object        the current Database instance
395
+	 */
396
+	public function rightOuterJoin($table, $field1, $op = null, $field2 = ''){
397
+	  return $this->join($table, $field1, $op, $field2, 'RIGHT OUTER ');
398
+	}
399
+
400
+	/**
401
+	 * Set the SQL WHERE CLAUSE for IS NULL
402
+	 * @param  string|array $field  the field name or array of field list
403
+	 * @param  string $andOr the separator type used 'AND', 'OR', etc.
404
+	 * @return object        the current Database instance
405
+	 */
406
+	public function whereIsNull($field, $andOr = 'AND'){
407
+	  if(is_array($field)){
408
+		foreach($field as $f){
409
+			$this->whereIsNull($f, $andOr);
410
+		}
411
+	  }
412
+	  else{
413
+		if (! $this->where){
414
+		  $this->where = $field.' IS NULL ';
415
+		}
416
+		else{
417
+			$this->where = $this->where . ' '.$andOr.' ' . $field.' IS NULL ';
418
+		  }
419
+	  }
420
+	  return $this;
421
+	}
422
+
423
+	/**
424
+	 * Set the SQL WHERE CLAUSE for IS NOT NULL
425
+	 * @param  string|array $field  the field name or array of field list
426
+	 * @param  string $andOr the separator type used 'AND', 'OR', etc.
427
+	 * @return object        the current Database instance
428
+	 */
429
+	public function whereIsNotNull($field, $andOr = 'AND'){
430
+	  if(is_array($field)){
431
+		foreach($field as $f){
432
+		  $this->whereIsNotNull($f, $andOr);
433
+		}
434
+	  }
435
+	  else{
436
+		if (! $this->where){
437
+		  $this->where = $field.' IS NOT NULL ';
438
+		}
439
+		else{
440
+			$this->where = $this->where . ' '.$andOr.' ' . $field.' IS NOT NULL ';
441
+		  }
442
+	  }
443
+	  return $this;
444
+	}
445
+
446
+	/**
447
+	 * Get the SQL WHERE clause using array column => value
448
+	 * @see Database::where
449
+	 *
450
+	 * @return string
451
+	 */
452
+	protected function getWhereStrIfIsArray(array $where, $type = '', $andOr = 'AND', $escape = true){
453
+		$_where = array();
454
+		foreach ($where as $column => $data){
455
+		  if(is_null($data)){
456
+			$data = '';
457
+		  }
458
+		  $_where[] = $type . $column . ' = ' . ($escape ? $this->escape($data) : $data);
459
+		}
460
+		$where = implode(' '.$andOr.' ', $_where);
461
+		return $where;
462
+	}
463
+
464
+	 /**
465
+	  * Get the SQL WHERE clause when operator argument is an array
466
+	  * @see Database::where
467
+	  *
468
+	  * @return string
469
+	  */
470
+	protected function getWhereStrIfOperatorIsArray($where, array $op, $type = '', $escape = true){
471
+	   $x = explode('?', $where);
472
+	   $w = '';
473
+		foreach($x as $k => $v){
474
+		  if(! empty($v)){
475
+			  if(isset($op[$k]) && is_null($op[$k])){
476
+				$op[$k] = '';
477
+			  }
478
+			  $w .= $type . $v . (isset($op[$k]) ? ($escape ? $this->escape($op[$k]) : $op[$k]) : '');
479
+		  }
480
+		}
481
+		return $w;
482
+	}
483
+
484
+	/**
485
+	 * Get the default SQL WHERE clause using operator = or the operator argument
486
+	 * @see Database::where
487
+	 *
488
+	 * @return string
489
+	 */
490
+	protected function getWhereStrForOperator($where, $op = null, $val = null, $type = '', $escape = true){
491
+	   $w = '';
492
+	   if (! in_array((string)$op, $this->operatorList)){
493
+		  if(is_null($op)){
494
+			$op = '';
495
+		  }
496
+		  $w = $type . $where . ' = ' . ($escape ? $this->escape($op) : $op);
497
+		}
498
+		else{
499
+		  if(is_null($val)){
500
+			$val = '';
501
+		  }
502
+		  $w = $type . $where . $op . ($escape ? $this->escape($val) : $val);
503
+		}
504
+		return $w;
505
+	  }
506
+
507
+	  /**
508
+	   * Set the $this->where property 
509
+	   * @param string $whereStr the WHERE clause string
510
+	   * @param  string  $andOr the separator type used 'AND', 'OR', etc.
511
+	   */
512
+	  protected function setWhereStr($whereStr, $andOr = 'AND'){
513
+		if (empty($this->where)){
514
+		  $this->where = $whereStr;
515
+		}
516
+		else{
517
+		  if(substr($this->where, -1) == '('){
518
+			$this->where = $this->where . ' ' . $whereStr;
519
+		  }
520
+		  else{
521
+			$this->where = $this->where . ' '.$andOr.' ' . $whereStr;
522
+		  }
523
+		}
524
+	  }
525 525
     
526
-    /**
527
-     * Set the SQL WHERE CLAUSE statment
528
-     * @param  string|array  $where the where field or array of field list
529
-     * @param  array|string  $op     the condition operator. If is null the default will be "="
530
-     * @param  mixed  $val    the where value
531
-     * @param  string  $type   the type used for this where clause (NOT, etc.)
532
-     * @param  string  $andOr the separator type used 'AND', 'OR', etc.
533
-     * @param  boolean $escape whether to escape or not the $val
534
-     * @return object        the current Database instance
535
-     */
536
-    public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true){
537
-      $whereStr = '';
538
-      if (is_array($where)){
539
-        $whereStr = $this->getWhereStrIfIsArray($where, $type, $andOr, $escape);
540
-      }
541
-      else{
542
-        if(is_array($op)){
543
-          $whereStr = $this->getWhereStrIfOperatorIsArray($where, $op, $type, $escape);
544
-        } else {
545
-          $whereStr = $this->getWhereStrForOperator($where, $op, $val, $type, $escape = true);
546
-        }
547
-      }
548
-      $this->setWhereStr($whereStr, $andOr);
549
-      return $this;
550
-    }
551
-
552
-    /**
553
-     * Set the SQL WHERE CLAUSE statment using OR
554
-     * @see  Database::where()
555
-     * @return object        the current Database instance
556
-     */
557
-    public function orWhere($where, $op = null, $val = null, $escape = true){
558
-      return $this->where($where, $op, $val, '', 'OR', $escape);
559
-    }
560
-
561
-
562
-    /**
563
-     * Set the SQL WHERE CLAUSE statment using AND and NOT
564
-     * @see  Database::where()
565
-     * @return object        the current Database instance
566
-     */
567
-    public function notWhere($where, $op = null, $val = null, $escape = true){
568
-      return $this->where($where, $op, $val, 'NOT ', 'AND', $escape);
569
-    }
570
-
571
-    /**
572
-     * Set the SQL WHERE CLAUSE statment using OR and NOT
573
-     * @see  Database::where()
574
-     * @return object        the current Database instance
575
-     */
576
-    public function orNotWhere($where, $op = null, $val = null, $escape = true){
577
-    	return $this->where($where, $op, $val, 'NOT ', 'OR', $escape);
578
-    }
579
-
580
-    /**
581
-     * Set the opened parenthesis for the complex SQL query
582
-     * @param  string $type   the type of this grouped (NOT, etc.)
583
-     * @param  string $andOr the multiple conditions separator (AND, OR, etc.)
584
-     * @return object        the current Database instance
585
-     */
586
-    public function groupStart($type = '', $andOr = ' AND'){
587
-      if (empty($this->where)){
588
-        $this->where = $type . ' (';
589
-      }
590
-      else{
591
-          if(substr($this->where, -1) == '('){
592
-            $this->where .= $type . ' (';
593
-          }
594
-          else{
595
-          	$this->where .= $andOr . ' ' . $type . ' (';
596
-          }
597
-      }
598
-      return $this;
599
-    }
600
-
601
-    /**
602
-     * Set the opened parenthesis for the complex SQL query using NOT type
603
-     * @see  Database::groupStart()
604
-     * @return object        the current Database instance
605
-     */
606
-    public function notGroupStart(){
607
-      return $this->groupStart('NOT');
608
-    }
609
-
610
-    /**
611
-     * Set the opened parenthesis for the complex SQL query using OR for separator
612
-     * @see  Database::groupStart()
613
-     * @return object        the current Database instance
614
-     */
615
-    public function orGroupStart(){
616
-      return $this->groupStart('', ' OR');
617
-    }
618
-
619
-     /**
620
-     * Set the opened parenthesis for the complex SQL query using OR for separator and NOT for type
621
-     * @see  Database::groupStart()
622
-     * @return object        the current Database instance
623
-     */
624
-    public function orNotGroupStart(){
625
-      return $this->groupStart('NOT', ' OR');
626
-    }
627
-
628
-    /**
629
-     * Close the parenthesis for the grouped SQL
630
-     * @return object        the current Database instance
631
-     */
632
-    public function groupEnd(){
633
-      $this->where .= ')';
634
-      return $this;
635
-    }
636
-
637
-    /**
638
-     * Set the SQL WHERE CLAUSE statment for IN
639
-     * @param  string  $field  the field name for IN statment
640
-     * @param  array   $keys   the list of values used
641
-     * @param  string  $type   the condition separator type (NOT)
642
-     * @param  string  $andOr the multiple conditions separator (OR, AND)
643
-     * @param  boolean $escape whether to escape or not the values
644
-     * @return object        the current Database instance
645
-     */
646
-    public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true){
647
-      $_keys = array();
648
-      foreach ($keys as $k => $v){
649
-        if(is_null($v)){
650
-          $v = '';
651
-        }
652
-        $_keys[] = (is_numeric($v) ? $v : ($escape ? $this->escape($v) : $v));
653
-      }
654
-      $keys = implode(', ', $_keys);
655
-      $whereStr = $field . ' ' . $type . ' IN (' . $keys . ')';
656
-      $this->setWhereStr($whereStr, $andOr);
657
-      return $this;
658
-    }
659
-
660
-    /**
661
-     * Set the SQL WHERE CLAUSE statment for NOT IN with AND separator
662
-     * @see  Database::in()
663
-     * @return object        the current Database instance
664
-     */
665
-    public function notIn($field, array $keys, $escape = true){
666
-      return $this->in($field, $keys, 'NOT ', 'AND', $escape);
667
-    }
668
-
669
-    /**
670
-     * Set the SQL WHERE CLAUSE statment for IN with OR separator
671
-     * @see  Database::in()
672
-     * @return object        the current Database instance
673
-     */
674
-    public function orIn($field, array $keys, $escape = true){
675
-      return $this->in($field, $keys, '', 'OR', $escape);
676
-    }
677
-
678
-    /**
679
-     * Set the SQL WHERE CLAUSE statment for NOT IN with OR separator
680
-     * @see  Database::in()
681
-     * @return object        the current Database instance
682
-     */
683
-    public function orNotIn($field, array $keys, $escape = true){
684
-      return $this->in($field, $keys, 'NOT ', 'OR', $escape);
685
-    }
686
-
687
-    /**
688
-     * Set the SQL WHERE CLAUSE statment for BETWEEN
689
-     * @param  string  $field  the field used for the BETWEEN statment
690
-     * @param  mixed  $value1 the BETWEEN begin value
691
-     * @param  mixed  $value2 the BETWEEN end value
692
-     * @param  string  $type   the condition separator type (NOT)
693
-     * @param  string  $andOr the multiple conditions separator (OR, AND)
694
-     * @param  boolean $escape whether to escape or not the values
695
-     * @return object        the current Database instance
696
-     */
697
-    public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true){
698
-      if(is_null($value1)){
699
-        $value1 = '';
700
-      }
701
-      if(is_null($value2)){
702
-        $value2 = '';
703
-      }
704
-      $whereStr = $field . ' ' . $type . ' BETWEEN ' . ($escape ? $this->escape($value1) : $value1) . ' AND ' . ($escape ? $this->escape($value2) : $value2);
705
-      $this->setWhereStr($whereStr, $andOr);
706
-      return $this;
707
-    }
708
-
709
-    /**
710
-     * Set the SQL WHERE CLAUSE statment for BETWEEN with NOT type and AND separator
711
-     * @see  Database::between()
712
-     * @return object        the current Database instance
713
-     */
714
-    public function notBetween($field, $value1, $value2, $escape = true){
715
-      return $this->between($field, $value1, $value2, 'NOT ', 'AND', $escape);
716
-    }
717
-
718
-    /**
719
-     * Set the SQL WHERE CLAUSE statment for BETWEEN with OR separator
720
-     * @see  Database::between()
721
-     * @return object        the current Database instance
722
-     */
723
-    public function orBetween($field, $value1, $value2, $escape = true){
724
-      return $this->between($field, $value1, $value2, '', 'OR', $escape);
725
-    }
726
-
727
-    /**
728
-     * Set the SQL WHERE CLAUSE statment for BETWEEN with NOT type and OR separator
729
-     * @see  Database::between()
730
-     * @return object        the current Database instance
731
-     */
732
-    public function orNotBetween($field, $value1, $value2, $escape = true){
733
-      return $this->between($field, $value1, $value2, 'NOT ', 'OR', $escape);
734
-    }
735
-
736
-    /**
737
-     * Set the SQL WHERE CLAUSE statment for LIKE
738
-     * @param  string  $field  the field name used in LIKE statment
739
-     * @param  string  $data   the LIKE value for this field including the '%', and '_' part
740
-     * @param  string  $type   the condition separator type (NOT)
741
-     * @param  string  $andOr the multiple conditions separator (OR, AND)
742
-     * @param  boolean $escape whether to escape or not the values
743
-     * @return object        the current Database instance
744
-     */
745
-    public function like($field, $data, $type = '', $andOr = 'AND', $escape = true){
746
-      if(empty($data)){
747
-        $data = '';
748
-      }
749
-      $like = $escape ? $this->escape($data) : $data;
750
-      if (empty($this->where)){
751
-        $this->where = $field . ' ' . $type . 'LIKE ' . $like;
752
-      }
753
-      else{
754
-        if(substr($this->where, -1) == '('){
755
-          $this->where = $this->where . ' ' . $field . ' ' . $type . 'LIKE ' . $like;
756
-        }
757
-        else{
758
-          $this->where = $this->where . ' '.$andOr.' ' . $field . ' ' . $type . 'LIKE ' . $like;
759
-        }
760
-      }
761
-      return $this;
762
-    }
763
-
764
-    /**
765
-     * Set the SQL WHERE CLAUSE statment for LIKE with OR separator
766
-     * @see  Database::like()
767
-     * @return object        the current Database instance
768
-     */
769
-    public function orLike($field, $data, $escape = true){
770
-      return $this->like($field, $data, '', 'OR', $escape);
771
-    }
772
-
773
-    /**
774
-     * Set the SQL WHERE CLAUSE statment for LIKE with NOT type and AND separator
775
-     * @see  Database::like()
776
-     * @return object        the current Database instance
777
-     */
778
-    public function notLike($field, $data, $escape = true){
779
-      return $this->like($field, $data, 'NOT ', 'AND', $escape);
780
-    }
781
-
782
-    /**
783
-     * Set the SQL WHERE CLAUSE statment for LIKE with NOT type and OR separator
784
-     * @see  Database::like()
785
-     * @return object        the current Database instance
786
-     */
787
-    public function orNotLike($field, $data, $escape = true){
788
-      return $this->like($field, $data, 'NOT ', 'OR', $escape);
789
-    }
790
-
791
-    /**
792
-     * Set the SQL LIMIT statment
793
-     * @param  int $limit    the limit offset. If $limitEnd is null this will be the limit count
794
-     * like LIMIT n;
795
-     * @param  int $limitEnd the limit count
796
-     * @return object        the current Database instance
797
-     */
798
-    public function limit($limit, $limitEnd = null){
799
-      if(empty($limit)){
800
-        return;
801
-      }
802
-      if (! is_null($limitEnd)){
803
-        $this->limit = $limit . ', ' . $limitEnd;
804
-      }
805
-      else{
806
-        $this->limit = $limit;
807
-      }
808
-      return $this;
809
-    }
810
-
811
-    /**
812
-     * Set the SQL ORDER BY CLAUSE statment
813
-     * @param  string $orderBy   the field name used for order
814
-     * @param  string $orderDir the order direction (ASC or DESC)
815
-     * @return object        the current Database instance
816
-     */
817
-    public function orderBy($orderBy, $orderDir = ' ASC'){
818
-      if (! empty($orderDir)){
819
-        $this->orderBy = ! $this->orderBy ? ($orderBy . ' ' . strtoupper($orderDir)) : $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir);
820
-      }
821
-      else{
822
-        if(stristr($orderBy, ' ') || $orderBy == 'rand()'){
823
-          $this->orderBy = ! $this->orderBy ? $orderBy : $this->orderBy . ', ' . $orderBy;
824
-        }
825
-        else{
826
-          $this->orderBy = ! $this->orderBy ? ($orderBy . ' ASC') : $this->orderBy . ', ' . ($orderBy . ' ASC');
827
-        }
828
-      }
829
-      return $this;
830
-    }
831
-
832
-    /**
833
-     * Set the SQL GROUP BY CLAUSE statment
834
-     * @param  string|array $field the field name used or array of field list
835
-     * @return object        the current Database instance
836
-     */
837
-    public function groupBy($field){
838
-      if(is_array($field)){
839
-        $this->groupBy = implode(', ', $field);
840
-      }
841
-      else{
842
-        $this->groupBy = $field;
843
-      }
844
-      return $this;
845
-    }
846
-
847
-    /**
848
-     * Set the SQL HAVING CLAUSE statment
849
-     * @param  string  $field  the field name used for HAVING statment
850
-     * @param  string|array  $op     the operator used or array
851
-     * @param  mixed  $val    the value for HAVING comparaison
852
-     * @param  boolean $escape whether to escape or not the values
853
-     * @return object        the current Database instance
854
-     */
855
-    public function having($field, $op = null, $val = null, $escape = true){
856
-      if(is_array($op)){
857
-        $x = explode('?', $field);
858
-        $w = '';
859
-        foreach($x as $k => $v){
860
-  	      if(!empty($v)){
861
-            if(isset($op[$k]) && is_null($op[$k])){
862
-              $op[$k] = '';
863
-            }
864
-  	      	$w .= $v . (isset($op[$k]) ? ($escape ? $this->escape($op[$k]) : $op[$k]) : '');
865
-  	      }
866
-      	}
867
-        $this->having = $w;
868
-      }
869
-      else if (! in_array($op, $this->operatorList)){
870
-        if(is_null($op)){
871
-          $op = '';
872
-        }
873
-        $this->having = $field . ' > ' . ($escape ? $this->escape($op) : $op);
874
-      }
875
-      else{
876
-        if(is_null($val)){
877
-          $val = '';
878
-        }
879
-        $this->having = $field . ' ' . $op . ' ' . ($escape ? $this->escape($val) : $val);
880
-      }
881
-      return $this;
882
-    }
883
-
884
-    /**
885
-     * Return the number of rows returned by the current query
886
-     * @return int
887
-     */
888
-    public function numRows(){
889
-      return $this->numRows;
890
-    }
891
-
892
-    /**
893
-     * Return the last insert id value
894
-     * @return mixed
895
-     */
896
-    public function insertId(){
897
-      return $this->insertId;
898
-    }
899
-
900
-    /**
901
-     * Show an error got from the current query (SQL command synthax error, database driver returned error, etc.)
902
-     */
903
-    public function error(){
526
+	/**
527
+	 * Set the SQL WHERE CLAUSE statment
528
+	 * @param  string|array  $where the where field or array of field list
529
+	 * @param  array|string  $op     the condition operator. If is null the default will be "="
530
+	 * @param  mixed  $val    the where value
531
+	 * @param  string  $type   the type used for this where clause (NOT, etc.)
532
+	 * @param  string  $andOr the separator type used 'AND', 'OR', etc.
533
+	 * @param  boolean $escape whether to escape or not the $val
534
+	 * @return object        the current Database instance
535
+	 */
536
+	public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true){
537
+	  $whereStr = '';
538
+	  if (is_array($where)){
539
+		$whereStr = $this->getWhereStrIfIsArray($where, $type, $andOr, $escape);
540
+	  }
541
+	  else{
542
+		if(is_array($op)){
543
+		  $whereStr = $this->getWhereStrIfOperatorIsArray($where, $op, $type, $escape);
544
+		} else {
545
+		  $whereStr = $this->getWhereStrForOperator($where, $op, $val, $type, $escape = true);
546
+		}
547
+	  }
548
+	  $this->setWhereStr($whereStr, $andOr);
549
+	  return $this;
550
+	}
551
+
552
+	/**
553
+	 * Set the SQL WHERE CLAUSE statment using OR
554
+	 * @see  Database::where()
555
+	 * @return object        the current Database instance
556
+	 */
557
+	public function orWhere($where, $op = null, $val = null, $escape = true){
558
+	  return $this->where($where, $op, $val, '', 'OR', $escape);
559
+	}
560
+
561
+
562
+	/**
563
+	 * Set the SQL WHERE CLAUSE statment using AND and NOT
564
+	 * @see  Database::where()
565
+	 * @return object        the current Database instance
566
+	 */
567
+	public function notWhere($where, $op = null, $val = null, $escape = true){
568
+	  return $this->where($where, $op, $val, 'NOT ', 'AND', $escape);
569
+	}
570
+
571
+	/**
572
+	 * Set the SQL WHERE CLAUSE statment using OR and NOT
573
+	 * @see  Database::where()
574
+	 * @return object        the current Database instance
575
+	 */
576
+	public function orNotWhere($where, $op = null, $val = null, $escape = true){
577
+		return $this->where($where, $op, $val, 'NOT ', 'OR', $escape);
578
+	}
579
+
580
+	/**
581
+	 * Set the opened parenthesis for the complex SQL query
582
+	 * @param  string $type   the type of this grouped (NOT, etc.)
583
+	 * @param  string $andOr the multiple conditions separator (AND, OR, etc.)
584
+	 * @return object        the current Database instance
585
+	 */
586
+	public function groupStart($type = '', $andOr = ' AND'){
587
+	  if (empty($this->where)){
588
+		$this->where = $type . ' (';
589
+	  }
590
+	  else{
591
+		  if(substr($this->where, -1) == '('){
592
+			$this->where .= $type . ' (';
593
+		  }
594
+		  else{
595
+		  	$this->where .= $andOr . ' ' . $type . ' (';
596
+		  }
597
+	  }
598
+	  return $this;
599
+	}
600
+
601
+	/**
602
+	 * Set the opened parenthesis for the complex SQL query using NOT type
603
+	 * @see  Database::groupStart()
604
+	 * @return object        the current Database instance
605
+	 */
606
+	public function notGroupStart(){
607
+	  return $this->groupStart('NOT');
608
+	}
609
+
610
+	/**
611
+	 * Set the opened parenthesis for the complex SQL query using OR for separator
612
+	 * @see  Database::groupStart()
613
+	 * @return object        the current Database instance
614
+	 */
615
+	public function orGroupStart(){
616
+	  return $this->groupStart('', ' OR');
617
+	}
618
+
619
+	 /**
620
+	  * Set the opened parenthesis for the complex SQL query using OR for separator and NOT for type
621
+	  * @see  Database::groupStart()
622
+	  * @return object        the current Database instance
623
+	  */
624
+	public function orNotGroupStart(){
625
+	  return $this->groupStart('NOT', ' OR');
626
+	}
627
+
628
+	/**
629
+	 * Close the parenthesis for the grouped SQL
630
+	 * @return object        the current Database instance
631
+	 */
632
+	public function groupEnd(){
633
+	  $this->where .= ')';
634
+	  return $this;
635
+	}
636
+
637
+	/**
638
+	 * Set the SQL WHERE CLAUSE statment for IN
639
+	 * @param  string  $field  the field name for IN statment
640
+	 * @param  array   $keys   the list of values used
641
+	 * @param  string  $type   the condition separator type (NOT)
642
+	 * @param  string  $andOr the multiple conditions separator (OR, AND)
643
+	 * @param  boolean $escape whether to escape or not the values
644
+	 * @return object        the current Database instance
645
+	 */
646
+	public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true){
647
+	  $_keys = array();
648
+	  foreach ($keys as $k => $v){
649
+		if(is_null($v)){
650
+		  $v = '';
651
+		}
652
+		$_keys[] = (is_numeric($v) ? $v : ($escape ? $this->escape($v) : $v));
653
+	  }
654
+	  $keys = implode(', ', $_keys);
655
+	  $whereStr = $field . ' ' . $type . ' IN (' . $keys . ')';
656
+	  $this->setWhereStr($whereStr, $andOr);
657
+	  return $this;
658
+	}
659
+
660
+	/**
661
+	 * Set the SQL WHERE CLAUSE statment for NOT IN with AND separator
662
+	 * @see  Database::in()
663
+	 * @return object        the current Database instance
664
+	 */
665
+	public function notIn($field, array $keys, $escape = true){
666
+	  return $this->in($field, $keys, 'NOT ', 'AND', $escape);
667
+	}
668
+
669
+	/**
670
+	 * Set the SQL WHERE CLAUSE statment for IN with OR separator
671
+	 * @see  Database::in()
672
+	 * @return object        the current Database instance
673
+	 */
674
+	public function orIn($field, array $keys, $escape = true){
675
+	  return $this->in($field, $keys, '', 'OR', $escape);
676
+	}
677
+
678
+	/**
679
+	 * Set the SQL WHERE CLAUSE statment for NOT IN with OR separator
680
+	 * @see  Database::in()
681
+	 * @return object        the current Database instance
682
+	 */
683
+	public function orNotIn($field, array $keys, $escape = true){
684
+	  return $this->in($field, $keys, 'NOT ', 'OR', $escape);
685
+	}
686
+
687
+	/**
688
+	 * Set the SQL WHERE CLAUSE statment for BETWEEN
689
+	 * @param  string  $field  the field used for the BETWEEN statment
690
+	 * @param  mixed  $value1 the BETWEEN begin value
691
+	 * @param  mixed  $value2 the BETWEEN end value
692
+	 * @param  string  $type   the condition separator type (NOT)
693
+	 * @param  string  $andOr the multiple conditions separator (OR, AND)
694
+	 * @param  boolean $escape whether to escape or not the values
695
+	 * @return object        the current Database instance
696
+	 */
697
+	public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true){
698
+	  if(is_null($value1)){
699
+		$value1 = '';
700
+	  }
701
+	  if(is_null($value2)){
702
+		$value2 = '';
703
+	  }
704
+	  $whereStr = $field . ' ' . $type . ' BETWEEN ' . ($escape ? $this->escape($value1) : $value1) . ' AND ' . ($escape ? $this->escape($value2) : $value2);
705
+	  $this->setWhereStr($whereStr, $andOr);
706
+	  return $this;
707
+	}
708
+
709
+	/**
710
+	 * Set the SQL WHERE CLAUSE statment for BETWEEN with NOT type and AND separator
711
+	 * @see  Database::between()
712
+	 * @return object        the current Database instance
713
+	 */
714
+	public function notBetween($field, $value1, $value2, $escape = true){
715
+	  return $this->between($field, $value1, $value2, 'NOT ', 'AND', $escape);
716
+	}
717
+
718
+	/**
719
+	 * Set the SQL WHERE CLAUSE statment for BETWEEN with OR separator
720
+	 * @see  Database::between()
721
+	 * @return object        the current Database instance
722
+	 */
723
+	public function orBetween($field, $value1, $value2, $escape = true){
724
+	  return $this->between($field, $value1, $value2, '', 'OR', $escape);
725
+	}
726
+
727
+	/**
728
+	 * Set the SQL WHERE CLAUSE statment for BETWEEN with NOT type and OR separator
729
+	 * @see  Database::between()
730
+	 * @return object        the current Database instance
731
+	 */
732
+	public function orNotBetween($field, $value1, $value2, $escape = true){
733
+	  return $this->between($field, $value1, $value2, 'NOT ', 'OR', $escape);
734
+	}
735
+
736
+	/**
737
+	 * Set the SQL WHERE CLAUSE statment for LIKE
738
+	 * @param  string  $field  the field name used in LIKE statment
739
+	 * @param  string  $data   the LIKE value for this field including the '%', and '_' part
740
+	 * @param  string  $type   the condition separator type (NOT)
741
+	 * @param  string  $andOr the multiple conditions separator (OR, AND)
742
+	 * @param  boolean $escape whether to escape or not the values
743
+	 * @return object        the current Database instance
744
+	 */
745
+	public function like($field, $data, $type = '', $andOr = 'AND', $escape = true){
746
+	  if(empty($data)){
747
+		$data = '';
748
+	  }
749
+	  $like = $escape ? $this->escape($data) : $data;
750
+	  if (empty($this->where)){
751
+		$this->where = $field . ' ' . $type . 'LIKE ' . $like;
752
+	  }
753
+	  else{
754
+		if(substr($this->where, -1) == '('){
755
+		  $this->where = $this->where . ' ' . $field . ' ' . $type . 'LIKE ' . $like;
756
+		}
757
+		else{
758
+		  $this->where = $this->where . ' '.$andOr.' ' . $field . ' ' . $type . 'LIKE ' . $like;
759
+		}
760
+	  }
761
+	  return $this;
762
+	}
763
+
764
+	/**
765
+	 * Set the SQL WHERE CLAUSE statment for LIKE with OR separator
766
+	 * @see  Database::like()
767
+	 * @return object        the current Database instance
768
+	 */
769
+	public function orLike($field, $data, $escape = true){
770
+	  return $this->like($field, $data, '', 'OR', $escape);
771
+	}
772
+
773
+	/**
774
+	 * Set the SQL WHERE CLAUSE statment for LIKE with NOT type and AND separator
775
+	 * @see  Database::like()
776
+	 * @return object        the current Database instance
777
+	 */
778
+	public function notLike($field, $data, $escape = true){
779
+	  return $this->like($field, $data, 'NOT ', 'AND', $escape);
780
+	}
781
+
782
+	/**
783
+	 * Set the SQL WHERE CLAUSE statment for LIKE with NOT type and OR separator
784
+	 * @see  Database::like()
785
+	 * @return object        the current Database instance
786
+	 */
787
+	public function orNotLike($field, $data, $escape = true){
788
+	  return $this->like($field, $data, 'NOT ', 'OR', $escape);
789
+	}
790
+
791
+	/**
792
+	 * Set the SQL LIMIT statment
793
+	 * @param  int $limit    the limit offset. If $limitEnd is null this will be the limit count
794
+	 * like LIMIT n;
795
+	 * @param  int $limitEnd the limit count
796
+	 * @return object        the current Database instance
797
+	 */
798
+	public function limit($limit, $limitEnd = null){
799
+	  if(empty($limit)){
800
+		return;
801
+	  }
802
+	  if (! is_null($limitEnd)){
803
+		$this->limit = $limit . ', ' . $limitEnd;
804
+	  }
805
+	  else{
806
+		$this->limit = $limit;
807
+	  }
808
+	  return $this;
809
+	}
810
+
811
+	/**
812
+	 * Set the SQL ORDER BY CLAUSE statment
813
+	 * @param  string $orderBy   the field name used for order
814
+	 * @param  string $orderDir the order direction (ASC or DESC)
815
+	 * @return object        the current Database instance
816
+	 */
817
+	public function orderBy($orderBy, $orderDir = ' ASC'){
818
+	  if (! empty($orderDir)){
819
+		$this->orderBy = ! $this->orderBy ? ($orderBy . ' ' . strtoupper($orderDir)) : $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir);
820
+	  }
821
+	  else{
822
+		if(stristr($orderBy, ' ') || $orderBy == 'rand()'){
823
+		  $this->orderBy = ! $this->orderBy ? $orderBy : $this->orderBy . ', ' . $orderBy;
824
+		}
825
+		else{
826
+		  $this->orderBy = ! $this->orderBy ? ($orderBy . ' ASC') : $this->orderBy . ', ' . ($orderBy . ' ASC');
827
+		}
828
+	  }
829
+	  return $this;
830
+	}
831
+
832
+	/**
833
+	 * Set the SQL GROUP BY CLAUSE statment
834
+	 * @param  string|array $field the field name used or array of field list
835
+	 * @return object        the current Database instance
836
+	 */
837
+	public function groupBy($field){
838
+	  if(is_array($field)){
839
+		$this->groupBy = implode(', ', $field);
840
+	  }
841
+	  else{
842
+		$this->groupBy = $field;
843
+	  }
844
+	  return $this;
845
+	}
846
+
847
+	/**
848
+	 * Set the SQL HAVING CLAUSE statment
849
+	 * @param  string  $field  the field name used for HAVING statment
850
+	 * @param  string|array  $op     the operator used or array
851
+	 * @param  mixed  $val    the value for HAVING comparaison
852
+	 * @param  boolean $escape whether to escape or not the values
853
+	 * @return object        the current Database instance
854
+	 */
855
+	public function having($field, $op = null, $val = null, $escape = true){
856
+	  if(is_array($op)){
857
+		$x = explode('?', $field);
858
+		$w = '';
859
+		foreach($x as $k => $v){
860
+  		  if(!empty($v)){
861
+			if(isset($op[$k]) && is_null($op[$k])){
862
+			  $op[$k] = '';
863
+			}
864
+  		  	$w .= $v . (isset($op[$k]) ? ($escape ? $this->escape($op[$k]) : $op[$k]) : '');
865
+  		  }
866
+	  	}
867
+		$this->having = $w;
868
+	  }
869
+	  else if (! in_array($op, $this->operatorList)){
870
+		if(is_null($op)){
871
+		  $op = '';
872
+		}
873
+		$this->having = $field . ' > ' . ($escape ? $this->escape($op) : $op);
874
+	  }
875
+	  else{
876
+		if(is_null($val)){
877
+		  $val = '';
878
+		}
879
+		$this->having = $field . ' ' . $op . ' ' . ($escape ? $this->escape($val) : $val);
880
+	  }
881
+	  return $this;
882
+	}
883
+
884
+	/**
885
+	 * Return the number of rows returned by the current query
886
+	 * @return int
887
+	 */
888
+	public function numRows(){
889
+	  return $this->numRows;
890
+	}
891
+
892
+	/**
893
+	 * Return the last insert id value
894
+	 * @return mixed
895
+	 */
896
+	public function insertId(){
897
+	  return $this->insertId;
898
+	}
899
+
900
+	/**
901
+	 * Show an error got from the current query (SQL command synthax error, database driver returned error, etc.)
902
+	 */
903
+	public function error(){
904 904
   		if($this->error){
905 905
   			show_error('Query: "' . $this->query . '" Error: ' . $this->error, 'Database Error');
906 906
   		}
907
-    }
908
-
909
-    /**
910
-     * Get the result of one record rows returned by the current query
911
-     * @param  boolean $returnSQLQueryOrResultType if is boolean and true will return the SQL query string.
912
-     * If is string will determine the result type "array" or "object"
913
-     * @return mixed       the query SQL string or the record result
914
-     */
915
-    public function get($returnSQLQueryOrResultType = false){
916
-      $this->limit = 1;
917
-      $query = $this->getAll(true);
918
-      if($returnSQLQueryOrResultType === true){
919
-        return $query;
920
-      }
921
-      else{
922
-        return $this->query( $query, false, (($returnSQLQueryOrResultType == 'array') ? true : false) );
923
-      }
924
-    }
925
-
926
-    /**
927
-     * Get the result of record rows list returned by the current query
928
-     * @param  boolean $returnSQLQueryOrResultType if is boolean and true will return the SQL query string.
929
-     * If is string will determine the result type "array" or "object"
930
-     * @return mixed       the query SQL string or the record result
931
-     */
932
-    public function getAll($returnSQLQueryOrResultType = false){
933
-      $query = 'SELECT ' . $this->select . ' FROM ' . $this->from;
934
-      if (! empty($this->join)){
935
-        $query .= $this->join;
936
-      }
907
+	}
908
+
909
+	/**
910
+	 * Get the result of one record rows returned by the current query
911
+	 * @param  boolean $returnSQLQueryOrResultType if is boolean and true will return the SQL query string.
912
+	 * If is string will determine the result type "array" or "object"
913
+	 * @return mixed       the query SQL string or the record result
914
+	 */
915
+	public function get($returnSQLQueryOrResultType = false){
916
+	  $this->limit = 1;
917
+	  $query = $this->getAll(true);
918
+	  if($returnSQLQueryOrResultType === true){
919
+		return $query;
920
+	  }
921
+	  else{
922
+		return $this->query( $query, false, (($returnSQLQueryOrResultType == 'array') ? true : false) );
923
+	  }
924
+	}
925
+
926
+	/**
927
+	 * Get the result of record rows list returned by the current query
928
+	 * @param  boolean $returnSQLQueryOrResultType if is boolean and true will return the SQL query string.
929
+	 * If is string will determine the result type "array" or "object"
930
+	 * @return mixed       the query SQL string or the record result
931
+	 */
932
+	public function getAll($returnSQLQueryOrResultType = false){
933
+	  $query = 'SELECT ' . $this->select . ' FROM ' . $this->from;
934
+	  if (! empty($this->join)){
935
+		$query .= $this->join;
936
+	  }
937 937
 	  
938
-      if (! empty($this->where)){
939
-        $query .= ' WHERE ' . $this->where;
940
-      }
938
+	  if (! empty($this->where)){
939
+		$query .= ' WHERE ' . $this->where;
940
+	  }
941 941
 
942
-      if (! empty($this->groupBy)){
943
-        $query .= ' GROUP BY ' . $this->groupBy;
944
-      }
942
+	  if (! empty($this->groupBy)){
943
+		$query .= ' GROUP BY ' . $this->groupBy;
944
+	  }
945 945
 
946
-      if (! empty($this->having)){
947
-        $query .= ' HAVING ' . $this->having;
948
-      }
946
+	  if (! empty($this->having)){
947
+		$query .= ' HAVING ' . $this->having;
948
+	  }
949 949
 
950
-      if (! empty($this->orderBy)){
951
-          $query .= ' ORDER BY ' . $this->orderBy;
952
-      }
950
+	  if (! empty($this->orderBy)){
951
+		  $query .= ' ORDER BY ' . $this->orderBy;
952
+	  }
953 953
 
954
-      if(! empty($this->limit)){
955
-      	$query .= ' LIMIT ' . $this->limit;
956
-      }
954
+	  if(! empty($this->limit)){
955
+	  	$query .= ' LIMIT ' . $this->limit;
956
+	  }
957 957
 	  
958 958
 	   if($returnSQLQueryOrResultType === true){
959
-      	return $query;
960
-      }
961
-      else{
962
-    	   return $this->query($query, true, (($returnSQLQueryOrResultType == 'array') ? true : false) );
963
-      }
964
-    }
965
-
966
-    /**
967
-     * Insert new record in the database
968
-     * @param  array   $data   the record data if is empty will use the $this->data array.
969
-     * @param  boolean $escape  whether to escape or not the values
970
-     * @return mixed          the insert id of the new record or null
971
-     */
972
-    public function insert($data = array(), $escape = true){
973
-      $column = array();
974
-      $val = array();
975
-      if(empty($data) && $this->getData()){
976
-        $columns = array_keys($this->getData());
977
-        $column = implode(',', $columns);
978
-        $val = implode(', ', $this->getData());
979
-      }
980
-      else{
981
-        $columns = array_keys($data);
982
-        $column = implode(',', $columns);
983
-        $val = implode(', ', ($escape ? array_map(array($this, 'escape'), $data) : $data));
984
-      }
985
-
986
-      $query = 'INSERT INTO ' . $this->from . ' (' . $column . ') VALUES (' . $val . ')';
987
-      $query = $this->query($query);
988
-
989
-      if ($query){
990
-        if(! $this->pdo){
991
-          $this->connect();
992
-        }
993
-        $this->insertId = $this->pdo->lastInsertId();
994
-        return $this->insertId();
995
-      }
996
-      else{
959
+	  	return $query;
960
+	  }
961
+	  else{
962
+		   return $this->query($query, true, (($returnSQLQueryOrResultType == 'array') ? true : false) );
963
+	  }
964
+	}
965
+
966
+	/**
967
+	 * Insert new record in the database
968
+	 * @param  array   $data   the record data if is empty will use the $this->data array.
969
+	 * @param  boolean $escape  whether to escape or not the values
970
+	 * @return mixed          the insert id of the new record or null
971
+	 */
972
+	public function insert($data = array(), $escape = true){
973
+	  $column = array();
974
+	  $val = array();
975
+	  if(empty($data) && $this->getData()){
976
+		$columns = array_keys($this->getData());
977
+		$column = implode(',', $columns);
978
+		$val = implode(', ', $this->getData());
979
+	  }
980
+	  else{
981
+		$columns = array_keys($data);
982
+		$column = implode(',', $columns);
983
+		$val = implode(', ', ($escape ? array_map(array($this, 'escape'), $data) : $data));
984
+	  }
985
+
986
+	  $query = 'INSERT INTO ' . $this->from . ' (' . $column . ') VALUES (' . $val . ')';
987
+	  $query = $this->query($query);
988
+
989
+	  if ($query){
990
+		if(! $this->pdo){
991
+		  $this->connect();
992
+		}
993
+		$this->insertId = $this->pdo->lastInsertId();
994
+		return $this->insertId();
995
+	  }
996
+	  else{
997 997
 		  return false;
998
-      }
999
-    }
1000
-
1001
-    /**
1002
-     * Update record in the database
1003
-     * @param  array   $data   the record data if is empty will use the $this->data array.
1004
-     * @param  boolean $escape  whether to escape or not the values
1005
-     * @return mixed          the update status
1006
-     */
1007
-    public function update($data = array(), $escape = true){
1008
-      $query = 'UPDATE ' . $this->from . ' SET ';
1009
-      $values = array();
1010
-      if(empty($data) && $this->getData()){
1011
-        foreach ($this->getData() as $column => $val){
1012
-          $values[] = $column . ' = ' . $val;
1013
-        }
1014
-      }
1015
-      else{
1016
-        foreach ($data as $column => $val){
1017
-          $values[] = $column . '=' . ($escape ? $this->escape($val) : $val);
1018
-        }
1019
-      }
1020
-      $query .= implode(', ', $values);
1021
-      if (! empty($this->where)){
1022
-        $query .= ' WHERE ' . $this->where;
1023
-      }
1024
-
1025
-      if (! empty($this->orderBy)){
1026
-        $query .= ' ORDER BY ' . $this->orderBy;
1027
-      }
1028
-
1029
-      if (! empty($this->limit)){
1030
-        $query .= ' LIMIT ' . $this->limit;
1031
-      }
1032
-      return $this->query($query);
1033
-    }
1034
-
1035
-    /**
1036
-     * Delete the record in database
1037
-     * @return mixed the delete status
1038
-     */
1039
-    public function delete(){
1040
-    	$query = 'DELETE FROM ' . $this->from;
1041
-
1042
-    	if (! empty($this->where)){
1043
-    		$query .= ' WHERE ' . $this->where;
1044
-      	}
1045
-
1046
-    	if (! empty($this->orderBy)){
1047
-    	  $query .= ' ORDER BY ' . $this->orderBy;
1048
-      	}
1049
-
1050
-    	if (! empty($this->limit)){
1051
-    		$query .= ' LIMIT ' . $this->limit;
1052
-      	}
1053
-
1054
-    	if($query == 'DELETE FROM ' . $this->from && $this->config['driver'] != 'sqlite'){  
1055
-    		$query = 'TRUNCATE TABLE ' . $this->from;
1056
-      }
1057
-    	return $this->query($query);
1058
-    }
1059
-
1060
-    /**
1061
-     * Execute an SQL query
1062
-     * @param  string  $query the query SQL string
1063
-     * @param  boolean $all   whether to return all record or not
1064
-     * @param  boolean $array return the result as array
1065
-     * @return mixed         the query result
1066
-     */
1067
-    public function query($query, $all = true, $array = false){
1068
-      $this->reset();
1069
-      if(is_array($all)){
1070
-        $x = explode('?', $query);
1071
-        $q = '';
1072
-        foreach($x as $k => $v){
1073
-          if(! empty($v)){
1074
-            $q .= $v . (isset($all[$k]) ? $this->escape($all[$k]) : '');
1075
-          }
1076
-        }
1077
-        $query = $q;
1078
-      }
1079
-
1080
-      $this->query = preg_replace('/\s\s+|\t\t+/', ' ', trim($query));
1081
-      $sqlSELECTQuery = stristr($this->query, 'SELECT');
1082
-      $this->logger->info('Execute SQL query ['.$this->query.'], return type: ' . ($array?'ARRAY':'OBJECT') .', return as list: ' . ($all ? 'YES':'NO'));
1083
-      //cache expire time
998
+	  }
999
+	}
1000
+
1001
+	/**
1002
+	 * Update record in the database
1003
+	 * @param  array   $data   the record data if is empty will use the $this->data array.
1004
+	 * @param  boolean $escape  whether to escape or not the values
1005
+	 * @return mixed          the update status
1006
+	 */
1007
+	public function update($data = array(), $escape = true){
1008
+	  $query = 'UPDATE ' . $this->from . ' SET ';
1009
+	  $values = array();
1010
+	  if(empty($data) && $this->getData()){
1011
+		foreach ($this->getData() as $column => $val){
1012
+		  $values[] = $column . ' = ' . $val;
1013
+		}
1014
+	  }
1015
+	  else{
1016
+		foreach ($data as $column => $val){
1017
+		  $values[] = $column . '=' . ($escape ? $this->escape($val) : $val);
1018
+		}
1019
+	  }
1020
+	  $query .= implode(', ', $values);
1021
+	  if (! empty($this->where)){
1022
+		$query .= ' WHERE ' . $this->where;
1023
+	  }
1024
+
1025
+	  if (! empty($this->orderBy)){
1026
+		$query .= ' ORDER BY ' . $this->orderBy;
1027
+	  }
1028
+
1029
+	  if (! empty($this->limit)){
1030
+		$query .= ' LIMIT ' . $this->limit;
1031
+	  }
1032
+	  return $this->query($query);
1033
+	}
1034
+
1035
+	/**
1036
+	 * Delete the record in database
1037
+	 * @return mixed the delete status
1038
+	 */
1039
+	public function delete(){
1040
+		$query = 'DELETE FROM ' . $this->from;
1041
+
1042
+		if (! empty($this->where)){
1043
+			$query .= ' WHERE ' . $this->where;
1044
+	  	}
1045
+
1046
+		if (! empty($this->orderBy)){
1047
+		  $query .= ' ORDER BY ' . $this->orderBy;
1048
+	  	}
1049
+
1050
+		if (! empty($this->limit)){
1051
+			$query .= ' LIMIT ' . $this->limit;
1052
+	  	}
1053
+
1054
+		if($query == 'DELETE FROM ' . $this->from && $this->config['driver'] != 'sqlite'){  
1055
+			$query = 'TRUNCATE TABLE ' . $this->from;
1056
+	  }
1057
+		return $this->query($query);
1058
+	}
1059
+
1060
+	/**
1061
+	 * Execute an SQL query
1062
+	 * @param  string  $query the query SQL string
1063
+	 * @param  boolean $all   whether to return all record or not
1064
+	 * @param  boolean $array return the result as array
1065
+	 * @return mixed         the query result
1066
+	 */
1067
+	public function query($query, $all = true, $array = false){
1068
+	  $this->reset();
1069
+	  if(is_array($all)){
1070
+		$x = explode('?', $query);
1071
+		$q = '';
1072
+		foreach($x as $k => $v){
1073
+		  if(! empty($v)){
1074
+			$q .= $v . (isset($all[$k]) ? $this->escape($all[$k]) : '');
1075
+		  }
1076
+		}
1077
+		$query = $q;
1078
+	  }
1079
+
1080
+	  $this->query = preg_replace('/\s\s+|\t\t+/', ' ', trim($query));
1081
+	  $sqlSELECTQuery = stristr($this->query, 'SELECT');
1082
+	  $this->logger->info('Execute SQL query ['.$this->query.'], return type: ' . ($array?'ARRAY':'OBJECT') .', return as list: ' . ($all ? 'YES':'NO'));
1083
+	  //cache expire time
1084 1084
   	  $cacheExpire = $this->temporaryCacheTtl;
1085 1085
   	  
1086 1086
   	  //return to the initial cache time
1087 1087
   	  $this->temporaryCacheTtl = $this->cacheTtl;
1088 1088
   	  
1089 1089
   	  //config for cache
1090
-        $cacheEnable = get_config('cache_enable');
1090
+		$cacheEnable = get_config('cache_enable');
1091 1091
   	  
1092 1092
   	  //the database cache content
1093
-        $cacheContent = null;
1093
+		$cacheContent = null;
1094 1094
   	  
1095 1095
   	  //this database query cache key
1096
-        $cacheKey = null;
1096
+		$cacheKey = null;
1097 1097
   	  
1098 1098
   	  //the cache manager instance
1099
-      $cacheInstance = null;
1099
+	  $cacheInstance = null;
1100 1100
   	  
1101 1101
   	  //if can use cache feature for this query
1102 1102
   	  $dbCacheStatus = $cacheEnable && $cacheExpire > 0;
1103 1103
 	  
1104
-      if ($dbCacheStatus && $sqlSELECTQuery){
1105
-        $this->logger->info('The cache is enabled for this query, try to get result from cache'); 
1106
-        $cacheKey = md5($query . $all . $array);
1107
-        if(is_object($this->cacheInstance)){
1108
-          $cacheInstance = $this->cacheInstance;
1109
-        }
1110
-        else{
1111
-          $obj = & get_instance();
1112
-          $cacheInstance = $obj->cache;  
1113
-        }
1114
-        $cacheContent = $cacheInstance->get($cacheKey);        
1115
-      }
1116
-      else{
1104
+	  if ($dbCacheStatus && $sqlSELECTQuery){
1105
+		$this->logger->info('The cache is enabled for this query, try to get result from cache'); 
1106
+		$cacheKey = md5($query . $all . $array);
1107
+		if(is_object($this->cacheInstance)){
1108
+		  $cacheInstance = $this->cacheInstance;
1109
+		}
1110
+		else{
1111
+		  $obj = & get_instance();
1112
+		  $cacheInstance = $obj->cache;  
1113
+		}
1114
+		$cacheContent = $cacheInstance->get($cacheKey);        
1115
+	  }
1116
+	  else{
1117 1117
 		  $this->logger->info('The cache is not enabled for this query or is not the SELECT query, get the result directly from real database');
1118
-      }
1118
+	  }
1119 1119
 
1120
-      if(! $this->pdo){
1121
-        $this->connect();
1122
-      }
1120
+	  if(! $this->pdo){
1121
+		$this->connect();
1122
+	  }
1123 1123
       
1124
-      if (! $cacheContent && $sqlSELECTQuery){
1125
-		    //for database query execution time
1126
-        $benchmarkMarkerKey = md5($query . $all . $array);
1127
-        $bench = null;
1128
-        if(is_object($this->benchmarkInstance)){
1129
-          $bench = $this->benchmarkInstance;
1130
-        }
1131
-        else{
1132
-          $obj = & get_instance();
1133
-          $bench = $obj->benchmark;  
1134
-        }
1135
-        $bench->mark('DATABASE_QUERY_START(' . $benchmarkMarkerKey . ')');
1136
-        //Now execute the query
1137
-		    $sqlQuery = $this->pdo->query($this->query);
1124
+	  if (! $cacheContent && $sqlSELECTQuery){
1125
+			//for database query execution time
1126
+		$benchmarkMarkerKey = md5($query . $all . $array);
1127
+		$bench = null;
1128
+		if(is_object($this->benchmarkInstance)){
1129
+		  $bench = $this->benchmarkInstance;
1130
+		}
1131
+		else{
1132
+		  $obj = & get_instance();
1133
+		  $bench = $obj->benchmark;  
1134
+		}
1135
+		$bench->mark('DATABASE_QUERY_START(' . $benchmarkMarkerKey . ')');
1136
+		//Now execute the query
1137
+			$sqlQuery = $this->pdo->query($this->query);
1138 1138
         
1139
-    		//get response time for this query
1140
-        $responseTime = $bench->elapsedTime('DATABASE_QUERY_START(' . $benchmarkMarkerKey . ')', 'DATABASE_QUERY_END(' . $benchmarkMarkerKey . ')');
1141
-	     	//TODO use the configuration value for the high response time currently is 1 second
1142
-        if($responseTime >= 1 ){
1143
-            $this->logger->warning('High response time while processing database query [' .$query. ']. The response time is [' .$responseTime. '] sec.');
1144
-        }
1145
-        if ($sqlQuery){
1146
-            //if need return all result like list of record
1147
-            if ($all){
1148
-    				    $this->result = ($array === false) ? $sqlQuery->fetchAll(PDO::FETCH_OBJ) : $sqlQuery->fetchAll(PDO::FETCH_ASSOC);
1149
-    		    }
1150
-            else{
1151
-				        $this->result = ($array === false) ? $sqlQuery->fetch(PDO::FETCH_OBJ) : $sqlQuery->fetch(PDO::FETCH_ASSOC);
1152
-            }
1153
-            //Sqlite and pgsql always return 0 when using rowCount()
1154
-            if(in_array($this->config['driver'], array('sqlite', 'pgsql'))){
1155
-              $this->numRows = count($this->result);  
1156
-            }
1157
-            else{
1158
-              $this->numRows = $sqlQuery->rowCount(); 
1159
-            }
1160
-
1161
-          if ($dbCacheStatus && $sqlSELECTQuery){
1162
-              $this->logger->info('Save the result for query [' .$this->query. '] into cache for future use');
1163
-              $cacheInstance->set($cacheKey, $this->result, $cacheExpire);
1164
-          }
1165
-        }
1166
-        else{
1167
-          $error = $this->pdo->errorInfo();
1168
-          $this->error = isset($error[2]) ? $error[2] : '';
1169
-          $this->logger->fatal('The database query execution got error: ' . stringfy_vars($error));
1170
-          $this->error();
1171
-        }
1172
-      }
1173
-      else if ((! $cacheContent && !$sqlSELECTQuery) || ($cacheContent && !$sqlSELECTQuery)){
1174
-    		$queryStr = $this->pdo->query($this->query);
1175
-    		if($queryStr){
1176
-          //Sqlite and pgsql always return 0 when using rowCount()
1177
-          if(in_array($this->config['driver'], array('sqlite', 'pgsql'))){
1178
-            $this->result = 1; //to test the result for the query like UPDATE, INSERT, DELETE
1179
-            $this->numRows = 1;  
1180
-          }
1181
-          else{
1182
-              $this->result = $queryStr->rowCount() >= 0; //to test the result for the query like UPDATE, INSERT, DELETE
1183
-              $this->numRows = $queryStr->rowCount(); 
1184
-          }
1185
-    		}
1186
-        if (! $this->result){
1187
-          $error = $this->pdo->errorInfo();
1188
-          $this->error = isset($error[2]) ? $error[2] : '';
1189
-          $this->logger->fatal('The database query execution got error: ' . stringfy_vars($error));
1190
-          $this->error();
1191
-        }
1192
-      }
1193
-      else{
1194
-        $this->logger->info('The result for query [' .$this->query. '] already cached use it');
1195
-        $this->result = $cacheContent;
1196
-	     	$this->numRows = count($this->result);
1197
-      }
1198
-      $this->queryCount++;
1199
-      if(! $this->result){
1200
-        $this->logger->info('No result where found for the query [' . $query . ']');
1201
-      }
1202
-      return $this->result;
1203
-    }
1204
-
1205
-    /**
1206
-     * Set database cache time to live
1207
-     * @param integer $ttl the cache time to live in second
1208
-     * @return object        the current Database instance
1209
-     */
1210
-    public function setCache($ttl = 0){
1211
-      if($ttl > 0){
1212
-        $this->cacheTtl = $ttl;
1213
-		    $this->temporaryCacheTtl = $ttl;
1214
-      }
1215
-      return $this;
1216
-    }
1139
+			//get response time for this query
1140
+		$responseTime = $bench->elapsedTime('DATABASE_QUERY_START(' . $benchmarkMarkerKey . ')', 'DATABASE_QUERY_END(' . $benchmarkMarkerKey . ')');
1141
+		 	//TODO use the configuration value for the high response time currently is 1 second
1142
+		if($responseTime >= 1 ){
1143
+			$this->logger->warning('High response time while processing database query [' .$query. ']. The response time is [' .$responseTime. '] sec.');
1144
+		}
1145
+		if ($sqlQuery){
1146
+			//if need return all result like list of record
1147
+			if ($all){
1148
+						$this->result = ($array === false) ? $sqlQuery->fetchAll(PDO::FETCH_OBJ) : $sqlQuery->fetchAll(PDO::FETCH_ASSOC);
1149
+				}
1150
+			else{
1151
+						$this->result = ($array === false) ? $sqlQuery->fetch(PDO::FETCH_OBJ) : $sqlQuery->fetch(PDO::FETCH_ASSOC);
1152
+			}
1153
+			//Sqlite and pgsql always return 0 when using rowCount()
1154
+			if(in_array($this->config['driver'], array('sqlite', 'pgsql'))){
1155
+			  $this->numRows = count($this->result);  
1156
+			}
1157
+			else{
1158
+			  $this->numRows = $sqlQuery->rowCount(); 
1159
+			}
1160
+
1161
+		  if ($dbCacheStatus && $sqlSELECTQuery){
1162
+			  $this->logger->info('Save the result for query [' .$this->query. '] into cache for future use');
1163
+			  $cacheInstance->set($cacheKey, $this->result, $cacheExpire);
1164
+		  }
1165
+		}
1166
+		else{
1167
+		  $error = $this->pdo->errorInfo();
1168
+		  $this->error = isset($error[2]) ? $error[2] : '';
1169
+		  $this->logger->fatal('The database query execution got error: ' . stringfy_vars($error));
1170
+		  $this->error();
1171
+		}
1172
+	  }
1173
+	  else if ((! $cacheContent && !$sqlSELECTQuery) || ($cacheContent && !$sqlSELECTQuery)){
1174
+			$queryStr = $this->pdo->query($this->query);
1175
+			if($queryStr){
1176
+		  //Sqlite and pgsql always return 0 when using rowCount()
1177
+		  if(in_array($this->config['driver'], array('sqlite', 'pgsql'))){
1178
+			$this->result = 1; //to test the result for the query like UPDATE, INSERT, DELETE
1179
+			$this->numRows = 1;  
1180
+		  }
1181
+		  else{
1182
+			  $this->result = $queryStr->rowCount() >= 0; //to test the result for the query like UPDATE, INSERT, DELETE
1183
+			  $this->numRows = $queryStr->rowCount(); 
1184
+		  }
1185
+			}
1186
+		if (! $this->result){
1187
+		  $error = $this->pdo->errorInfo();
1188
+		  $this->error = isset($error[2]) ? $error[2] : '';
1189
+		  $this->logger->fatal('The database query execution got error: ' . stringfy_vars($error));
1190
+		  $this->error();
1191
+		}
1192
+	  }
1193
+	  else{
1194
+		$this->logger->info('The result for query [' .$this->query. '] already cached use it');
1195
+		$this->result = $cacheContent;
1196
+		 	$this->numRows = count($this->result);
1197
+	  }
1198
+	  $this->queryCount++;
1199
+	  if(! $this->result){
1200
+		$this->logger->info('No result where found for the query [' . $query . ']');
1201
+	  }
1202
+	  return $this->result;
1203
+	}
1204
+
1205
+	/**
1206
+	 * Set database cache time to live
1207
+	 * @param integer $ttl the cache time to live in second
1208
+	 * @return object        the current Database instance
1209
+	 */
1210
+	public function setCache($ttl = 0){
1211
+	  if($ttl > 0){
1212
+		$this->cacheTtl = $ttl;
1213
+			$this->temporaryCacheTtl = $ttl;
1214
+	  }
1215
+	  return $this;
1216
+	}
1217 1217
 	
1218 1218
 	/**
1219 1219
 	 * Enabled cache temporary for the current query not globally	
@@ -1221,258 +1221,258 @@  discard block
 block discarded – undo
1221 1221
 	 * @return object        the current Database instance
1222 1222
 	 */
1223 1223
 	public function cached($ttl = 0){
1224
-      if($ttl > 0){
1225
-        $this->temporaryCacheTtl = $ttl;
1226
-      }
1224
+	  if($ttl > 0){
1225
+		$this->temporaryCacheTtl = $ttl;
1226
+	  }
1227
+	  return $this;
1228
+	}
1229
+
1230
+	/**
1231
+	 * Escape the data before execute query useful for security.
1232
+	 * @param  mixed $data the data to be escaped
1233
+	 * @return mixed       the data after escaped
1234
+	 */
1235
+	public function escape($data){
1236
+	  if(is_null($data)){
1237
+		return null;
1238
+	  }
1239
+	  if(! $this->pdo){
1240
+		$this->connect();
1241
+	  }
1242
+	  return $this->pdo->quote(trim($data));
1243
+	}
1244
+
1245
+	/**
1246
+	 * Return the number query executed count for the current request
1247
+	 * @return int
1248
+	 */
1249
+	public function queryCount(){
1250
+	  return $this->queryCount;
1251
+	}
1252
+
1253
+	/**
1254
+	 * Return the current query SQL string
1255
+	 * @return string
1256
+	 */
1257
+	public function getQuery(){
1258
+	  return $this->query;
1259
+	}
1260
+
1261
+	/**
1262
+	 * Return the application database name
1263
+	 * @return string
1264
+	 */
1265
+	public function getDatabaseName(){
1266
+	  return $this->databaseName;
1267
+	}
1268
+
1269
+	 /**
1270
+	  * Return the database configuration
1271
+	  * @return array
1272
+	  */
1273
+	public  function getDatabaseConfiguration(){
1274
+	  return $this->config;
1275
+	}
1276
+
1277
+	/**
1278
+	 * set the database configuration
1279
+	 * @param array $config the configuration
1280
+	 */
1281
+	public function setDatabaseConfiguration(array $config){
1282
+	  $this->config = array_merge($this->config, $config);
1283
+	  $this->prefix = $this->config['prefix'];
1284
+	  $this->databaseName = $this->config['database'];
1285
+	  $this->logger->info('The database configuration are listed below: ' . stringfy_vars(array_merge($this->config, array('password' => string_hidden($this->config['password'])))));
1227 1286
 	  return $this;
1228
-    }
1229
-
1230
-    /**
1231
-     * Escape the data before execute query useful for security.
1232
-     * @param  mixed $data the data to be escaped
1233
-     * @return mixed       the data after escaped
1234
-     */
1235
-    public function escape($data){
1236
-      if(is_null($data)){
1237
-        return null;
1238
-      }
1239
-      if(! $this->pdo){
1240
-        $this->connect();
1241
-      }
1242
-      return $this->pdo->quote(trim($data));
1243
-    }
1244
-
1245
-    /**
1246
-     * Return the number query executed count for the current request
1247
-     * @return int
1248
-     */
1249
-    public function queryCount(){
1250
-      return $this->queryCount;
1251
-    }
1252
-
1253
-    /**
1254
-     * Return the current query SQL string
1255
-     * @return string
1256
-     */
1257
-    public function getQuery(){
1258
-      return $this->query;
1259
-    }
1260
-
1261
-    /**
1262
-     * Return the application database name
1263
-     * @return string
1264
-     */
1265
-    public function getDatabaseName(){
1266
-      return $this->databaseName;
1267
-    }
1268
-
1269
-     /**
1270
-     * Return the database configuration
1271
-     * @return array
1272
-     */
1273
-    public  function getDatabaseConfiguration(){
1274
-      return $this->config;
1275
-    }
1276
-
1277
-    /**
1278
-     * set the database configuration
1279
-     * @param array $config the configuration
1280
-     */
1281
-    public function setDatabaseConfiguration(array $config){
1282
-      $this->config = array_merge($this->config, $config);
1283
-      $this->prefix = $this->config['prefix'];
1284
-      $this->databaseName = $this->config['database'];
1285
-      $this->logger->info('The database configuration are listed below: ' . stringfy_vars(array_merge($this->config, array('password' => string_hidden($this->config['password'])))));
1286
-      return $this;
1287
-    }
1288
-
1289
-    /**
1290
-     * Return the PDO instance
1291
-     * @return PDO
1292
-     */
1293
-    public function getPdo(){
1294
-      return $this->pdo;
1295
-    }
1296
-
1297
-    /**
1298
-     * Set the PDO instance
1299
-     * @param PDO $pdo the pdo object
1300
-     */
1301
-    public function setPdo(PDO $pdo){
1302
-      $this->pdo = $pdo;
1303
-      return $this;
1304
-    }
1305
-
1306
-
1307
-    /**
1308
-     * Return the Log instance
1309
-     * @return Log
1310
-     */
1311
-    public function getLogger(){
1312
-      return $this->logger;
1313
-    }
1314
-
1315
-    /**
1316
-     * Set the log instance
1317
-     * @param Log $logger the log object
1318
-     */
1319
-    public function setLogger($logger){
1320
-      $this->logger = $logger;
1321
-      return $this;
1322
-    }
1323
-
1324
-     /**
1325
-     * Return the cache instance
1326
-     * @return CacheInterface
1327
-     */
1328
-    public function getCacheInstance(){
1329
-      return $this->cacheInstance;
1330
-    }
1331
-
1332
-    /**
1333
-     * Set the cache instance
1334
-     * @param CacheInterface $cache the cache object
1335
-     */
1336
-    public function setCacheInstance($cache){
1337
-      $this->cacheInstance = $cache;
1338
-      return $this;
1339
-    }
1340
-
1341
-    /**
1342
-     * Return the benchmark instance
1343
-     * @return Benchmark
1344
-     */
1345
-    public function getBenchmark(){
1346
-      return $this->benchmarkInstance;
1347
-    }
1348
-
1349
-    /**
1350
-     * Set the benchmark instance
1351
-     * @param Benchmark $cache the cache object
1352
-     */
1353
-    public function setBenchmark($benchmark){
1354
-      $this->benchmarkInstance = $benchmark;
1355
-      return $this;
1356
-    }
1357
-
1358
-    /**
1359
-     * Return the data to be used for insert, update, etc.
1360
-     * @return array
1361
-     */
1362
-    public function getData(){
1363
-      return $this->data;
1364
-    }
1365
-
1366
-    /**
1367
-     * Set the data to be used for insert, update, etc.
1368
-     * @param string $key the data key identified
1369
-     * @param mixed $value the data value
1370
-     * @param boolean $escape whether to escape or not the $value
1371
-     * @return object        the current Database instance
1372
-     */
1373
-    public function setData($key, $value, $escape = true){
1374
-      $this->data[$key] = $escape ? $this->escape($value) : $value;
1375
-      return $this;
1376
-    }
1377
-
1378
-    /**
1379
-     * Set the Log instance using argument or create new instance
1380
-     * @param object $logger the Log instance if not null
1381
-     */
1382
-    protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
1383
-      if($logger !== null){
1384
-        $this->logger = $logger;
1385
-      }
1386
-      else{
1387
-          $this->logger =& class_loader('Log', 'classes');
1388
-          $this->logger->setLogger('Library::Database');
1389
-      }
1390
-    }
1287
+	}
1288
+
1289
+	/**
1290
+	 * Return the PDO instance
1291
+	 * @return PDO
1292
+	 */
1293
+	public function getPdo(){
1294
+	  return $this->pdo;
1295
+	}
1296
+
1297
+	/**
1298
+	 * Set the PDO instance
1299
+	 * @param PDO $pdo the pdo object
1300
+	 */
1301
+	public function setPdo(PDO $pdo){
1302
+	  $this->pdo = $pdo;
1303
+	  return $this;
1304
+	}
1305
+
1306
+
1307
+	/**
1308
+	 * Return the Log instance
1309
+	 * @return Log
1310
+	 */
1311
+	public function getLogger(){
1312
+	  return $this->logger;
1313
+	}
1314
+
1315
+	/**
1316
+	 * Set the log instance
1317
+	 * @param Log $logger the log object
1318
+	 */
1319
+	public function setLogger($logger){
1320
+	  $this->logger = $logger;
1321
+	  return $this;
1322
+	}
1323
+
1324
+	 /**
1325
+	  * Return the cache instance
1326
+	  * @return CacheInterface
1327
+	  */
1328
+	public function getCacheInstance(){
1329
+	  return $this->cacheInstance;
1330
+	}
1331
+
1332
+	/**
1333
+	 * Set the cache instance
1334
+	 * @param CacheInterface $cache the cache object
1335
+	 */
1336
+	public function setCacheInstance($cache){
1337
+	  $this->cacheInstance = $cache;
1338
+	  return $this;
1339
+	}
1340
+
1341
+	/**
1342
+	 * Return the benchmark instance
1343
+	 * @return Benchmark
1344
+	 */
1345
+	public function getBenchmark(){
1346
+	  return $this->benchmarkInstance;
1347
+	}
1348
+
1349
+	/**
1350
+	 * Set the benchmark instance
1351
+	 * @param Benchmark $cache the cache object
1352
+	 */
1353
+	public function setBenchmark($benchmark){
1354
+	  $this->benchmarkInstance = $benchmark;
1355
+	  return $this;
1356
+	}
1357
+
1358
+	/**
1359
+	 * Return the data to be used for insert, update, etc.
1360
+	 * @return array
1361
+	 */
1362
+	public function getData(){
1363
+	  return $this->data;
1364
+	}
1365
+
1366
+	/**
1367
+	 * Set the data to be used for insert, update, etc.
1368
+	 * @param string $key the data key identified
1369
+	 * @param mixed $value the data value
1370
+	 * @param boolean $escape whether to escape or not the $value
1371
+	 * @return object        the current Database instance
1372
+	 */
1373
+	public function setData($key, $value, $escape = true){
1374
+	  $this->data[$key] = $escape ? $this->escape($value) : $value;
1375
+	  return $this;
1376
+	}
1377
+
1378
+	/**
1379
+	 * Set the Log instance using argument or create new instance
1380
+	 * @param object $logger the Log instance if not null
1381
+	 */
1382
+	protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
1383
+	  if($logger !== null){
1384
+		$this->logger = $logger;
1385
+	  }
1386
+	  else{
1387
+		  $this->logger =& class_loader('Log', 'classes');
1388
+		  $this->logger->setLogger('Library::Database');
1389
+	  }
1390
+	}
1391 1391
 
1392 1392
    /**
1393 1393
     * Setting the database configuration using the configuration file
1394 1394
     * @param array $overwriteConfig the additional configuration to overwrite with the existing one
1395 1395
     */
1396
-    protected function setDatabaseConfigurationFromConfigFile(array $overwriteConfig = array()){
1397
-        $db = array();
1398
-        if(file_exists(CONFIG_PATH . 'database.php')){
1399
-            //here don't use require_once because somewhere user can create database instance directly
1400
-            require CONFIG_PATH . 'database.php';
1401
-        }
1396
+	protected function setDatabaseConfigurationFromConfigFile(array $overwriteConfig = array()){
1397
+		$db = array();
1398
+		if(file_exists(CONFIG_PATH . 'database.php')){
1399
+			//here don't use require_once because somewhere user can create database instance directly
1400
+			require CONFIG_PATH . 'database.php';
1401
+		}
1402 1402
           
1403
-        if(! empty($overwriteConfig)){
1404
-          $db = array_merge($db, $overwriteConfig);
1405
-        }
1406
-        $config = array();
1407
-        $config['driver']    = isset($db['driver']) ? $db['driver'] : 'mysql';
1408
-        $config['username']  = isset($db['username']) ? $db['username'] : 'root';
1409
-        $config['password']  = isset($db['password']) ? $db['password'] : '';
1410
-        $config['database']  = isset($db['database']) ? $db['database'] : '';
1411
-        $config['hostname']  = isset($db['hostname']) ? $db['hostname'] : 'localhost';
1412
-        $config['charset']   = isset($db['charset']) ? $db['charset'] : 'utf8';
1413
-        $config['collation'] = isset($db['collation']) ? $db['collation'] : 'utf8_general_ci';
1414
-        $config['prefix']    = isset($db['prefix']) ? $db['prefix'] : '';
1415
-        $port = '';
1416
-        if(strstr($config['hostname'], ':')){
1417
-          $p = explode(':', $config['hostname']);
1418
-          $port = isset($p[1]) ? $p[1] : '';
1419
-          $config['hostname'] = isset($p[0]) ? $p[0] : '';
1420
-        }
1421
-        $config['port']      = $port;
1422
-        $this->setDatabaseConfiguration($config);  
1423
-    }
1424
-
1425
-    /**
1426
-     * This method is used to get the PDO DSN string using th configured driver
1427
-     * @return string the DSN string
1428
-     */
1429
-    protected function getDsnFromDriver(){
1430
-      $config = $this->getDatabaseConfiguration();
1431
-      if(! empty($config)){
1432
-            $driverDsnMap = array(
1433
-                                    'mysql' => 'mysql:host=' . $config['hostname'] . ';' 
1434
-                                                . (($config['port']) != '' ? 'port=' . $config['port'] . ';' : '') 
1435
-                                                . 'dbname=' . $config['database'],
1436
-                                    'pgsql' => 'pgsql:host=' . $config['hostname'] . ';' 
1437
-                                                . (($config['port']) != '' ? 'port=' . $config['port'] . ';' : '')
1438
-                                                . 'dbname=' . $config['database'],
1439
-                                    'sqlite' => 'sqlite:' . $config['database'],
1440
-                                    'oracle' => 'oci:dbname=' . $config['hostname'] 
1441
-                                                . (($config['port']) != '' ? ':' . $config['port'] : '')
1442
-                                                . '/' . $config['database']
1443
-                                  );
1444
-            return isset($driverDsnMap[$config['driver']]) ? $driverDsnMap[$config['driver']] : '';
1445
-      } 
1403
+		if(! empty($overwriteConfig)){
1404
+		  $db = array_merge($db, $overwriteConfig);
1405
+		}
1406
+		$config = array();
1407
+		$config['driver']    = isset($db['driver']) ? $db['driver'] : 'mysql';
1408
+		$config['username']  = isset($db['username']) ? $db['username'] : 'root';
1409
+		$config['password']  = isset($db['password']) ? $db['password'] : '';
1410
+		$config['database']  = isset($db['database']) ? $db['database'] : '';
1411
+		$config['hostname']  = isset($db['hostname']) ? $db['hostname'] : 'localhost';
1412
+		$config['charset']   = isset($db['charset']) ? $db['charset'] : 'utf8';
1413
+		$config['collation'] = isset($db['collation']) ? $db['collation'] : 'utf8_general_ci';
1414
+		$config['prefix']    = isset($db['prefix']) ? $db['prefix'] : '';
1415
+		$port = '';
1416
+		if(strstr($config['hostname'], ':')){
1417
+		  $p = explode(':', $config['hostname']);
1418
+		  $port = isset($p[1]) ? $p[1] : '';
1419
+		  $config['hostname'] = isset($p[0]) ? $p[0] : '';
1420
+		}
1421
+		$config['port']      = $port;
1422
+		$this->setDatabaseConfiguration($config);  
1423
+	}
1424
+
1425
+	/**
1426
+	 * This method is used to get the PDO DSN string using th configured driver
1427
+	 * @return string the DSN string
1428
+	 */
1429
+	protected function getDsnFromDriver(){
1430
+	  $config = $this->getDatabaseConfiguration();
1431
+	  if(! empty($config)){
1432
+			$driverDsnMap = array(
1433
+									'mysql' => 'mysql:host=' . $config['hostname'] . ';' 
1434
+												. (($config['port']) != '' ? 'port=' . $config['port'] . ';' : '') 
1435
+												. 'dbname=' . $config['database'],
1436
+									'pgsql' => 'pgsql:host=' . $config['hostname'] . ';' 
1437
+												. (($config['port']) != '' ? 'port=' . $config['port'] . ';' : '')
1438
+												. 'dbname=' . $config['database'],
1439
+									'sqlite' => 'sqlite:' . $config['database'],
1440
+									'oracle' => 'oci:dbname=' . $config['hostname'] 
1441
+												. (($config['port']) != '' ? ':' . $config['port'] : '')
1442
+												. '/' . $config['database']
1443
+								  );
1444
+			return isset($driverDsnMap[$config['driver']]) ? $driverDsnMap[$config['driver']] : '';
1445
+	  } 
1446 1446
                             
1447
-      return null;
1448
-    }
1447
+	  return null;
1448
+	}
1449 1449
 
1450 1450
 
1451 1451
   /**
1452 1452
    * Reset the database class attributs to the initail values before each query.
1453 1453
    */
1454 1454
   private function reset(){
1455
-    $this->select   = '*';
1456
-    $this->from     = null;
1457
-    $this->where    = null;
1458
-    $this->limit    = null;
1459
-    $this->orderBy  = null;
1460
-    $this->groupBy  = null;
1461
-    $this->having   = null;
1462
-    $this->join     = null;
1463
-    $this->numRows  = 0;
1464
-    $this->insertId = null;
1465
-    $this->query    = null;
1466
-    $this->error    = null;
1467
-    $this->result   = array();
1468
-    $this->data     = array();
1455
+	$this->select   = '*';
1456
+	$this->from     = null;
1457
+	$this->where    = null;
1458
+	$this->limit    = null;
1459
+	$this->orderBy  = null;
1460
+	$this->groupBy  = null;
1461
+	$this->having   = null;
1462
+	$this->join     = null;
1463
+	$this->numRows  = 0;
1464
+	$this->insertId = null;
1465
+	$this->query    = null;
1466
+	$this->error    = null;
1467
+	$this->result   = array();
1468
+	$this->data     = array();
1469 1469
   }
1470 1470
 
1471 1471
   /**
1472 1472
    * The class destructor
1473 1473
    */
1474 1474
   public function __destruct(){
1475
-    $this->pdo = null;
1475
+	$this->pdo = null;
1476 1476
   }
1477 1477
 
1478 1478
 }
Please login to merge, or discard this patch.