@@ -1,918 +1,918 @@ |
||
| 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 | - class FormValidation{ |
|
| 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 | + class FormValidation{ |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * The form validation status |
|
| 32 | - * @var boolean |
|
| 33 | - */ |
|
| 34 | - protected $_success = false; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * The list of errors messages |
|
| 38 | - * @var array |
|
| 39 | - */ |
|
| 40 | - protected $_errorsMessages = array(); |
|
| 30 | + /** |
|
| 31 | + * The form validation status |
|
| 32 | + * @var boolean |
|
| 33 | + */ |
|
| 34 | + protected $_success = false; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * The list of errors messages |
|
| 38 | + * @var array |
|
| 39 | + */ |
|
| 40 | + protected $_errorsMessages = array(); |
|
| 41 | 41 | |
| 42 | - // Array of rule sets, fieldName => PIPE seperated ruleString |
|
| 43 | - protected $_rules = array(); |
|
| 42 | + // Array of rule sets, fieldName => PIPE seperated ruleString |
|
| 43 | + protected $_rules = array(); |
|
| 44 | 44 | |
| 45 | - // Array of errors, niceName => Error Message |
|
| 46 | - protected $_errors = array(); |
|
| 45 | + // Array of errors, niceName => Error Message |
|
| 46 | + protected $_errors = array(); |
|
| 47 | 47 | |
| 48 | - // Array of post Key => Nice name labels |
|
| 49 | - protected $_labels = array(); |
|
| 48 | + // Array of post Key => Nice name labels |
|
| 49 | + protected $_labels = array(); |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * The errors delimiters |
|
| 53 | - * @var array |
|
| 54 | - */ |
|
| 55 | - protected $_allErrorsDelimiter = array('<div class="error">', '</div>'); |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * The each error delimiter |
|
| 59 | - * @var array |
|
| 60 | - */ |
|
| 61 | - protected $_eachErrorDelimiter = array('<p class="error">', '</p>'); |
|
| 51 | + /** |
|
| 52 | + * The errors delimiters |
|
| 53 | + * @var array |
|
| 54 | + */ |
|
| 55 | + protected $_allErrorsDelimiter = array('<div class="error">', '</div>'); |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * The each error delimiter |
|
| 59 | + * @var array |
|
| 60 | + */ |
|
| 61 | + protected $_eachErrorDelimiter = array('<p class="error">', '</p>'); |
|
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | - * Indicated if need force the validation to be failed |
|
| 65 | - * @var boolean |
|
| 66 | - */ |
|
| 67 | - protected $_forceFail = false; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * The list of the error messages overrides by the original |
|
| 71 | - * @var array |
|
| 72 | - */ |
|
| 73 | - protected $_errorPhraseOverrides = array(); |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * The logger instance |
|
| 77 | - * @var Log |
|
| 78 | - */ |
|
| 79 | - private $logger; |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * The data to be validated, the default is to use $_POST |
|
| 83 | - * @var array |
|
| 84 | - */ |
|
| 85 | - private $data = array(); |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Whether to check the CSRF. This attribute is just a way to allow custom change of the |
|
| 64 | + * Indicated if need force the validation to be failed |
|
| 65 | + * @var boolean |
|
| 66 | + */ |
|
| 67 | + protected $_forceFail = false; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * The list of the error messages overrides by the original |
|
| 71 | + * @var array |
|
| 72 | + */ |
|
| 73 | + protected $_errorPhraseOverrides = array(); |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * The logger instance |
|
| 77 | + * @var Log |
|
| 78 | + */ |
|
| 79 | + private $logger; |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * The data to be validated, the default is to use $_POST |
|
| 83 | + * @var array |
|
| 84 | + */ |
|
| 85 | + private $data = array(); |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Whether to check the CSRF. This attribute is just a way to allow custom change of the |
|
| 89 | 89 | * CSRF global configuration |
| 90 | 90 | * |
| 91 | - * @var boolean |
|
| 92 | - */ |
|
| 93 | - public $enableCsrfCheck = false; |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Set all errors and rule sets empty, and sets success to false. |
|
| 97 | - * |
|
| 98 | - * @return void |
|
| 99 | - */ |
|
| 100 | - public function __construct() { |
|
| 101 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 102 | - $this->logger->setLogger('Library::FormValidation'); |
|
| 91 | + * @var boolean |
|
| 92 | + */ |
|
| 93 | + public $enableCsrfCheck = false; |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Set all errors and rule sets empty, and sets success to false. |
|
| 97 | + * |
|
| 98 | + * @return void |
|
| 99 | + */ |
|
| 100 | + public function __construct() { |
|
| 101 | + $this->logger =& class_loader('Log', 'classes'); |
|
| 102 | + $this->logger->setLogger('Library::FormValidation'); |
|
| 103 | 103 | |
| 104 | 104 | //Load form validation language message |
| 105 | - Loader::lang('form_validation'); |
|
| 106 | - $obj = & get_instance(); |
|
| 107 | - $this->_errorsMessages = array( |
|
| 108 | - 'required' => $obj->lang->get('fv_required'), |
|
| 109 | - 'min_length' => $obj->lang->get('fv_min_length'), |
|
| 110 | - 'max_length' => $obj->lang->get('fv_max_length'), |
|
| 111 | - 'exact_length' => $obj->lang->get('fv_exact_length'), |
|
| 112 | - 'less_than' => $obj->lang->get('fv_less_than'), |
|
| 113 | - 'greater_than' => $obj->lang->get('fv_greater_than'), |
|
| 114 | - 'matches' => $obj->lang->get('fv_matches'), |
|
| 115 | - 'valid_email' => $obj->lang->get('fv_valid_email'), |
|
| 116 | - 'not_equal' => array( |
|
| 117 | - 'post:key' => $obj->lang->get('fv_not_equal_post_key'), |
|
| 118 | - 'string' => $obj->lang->get('fv_not_equal_string') |
|
| 119 | - ), |
|
| 120 | - 'depends' => $obj->lang->get('fv_depends'), |
|
| 121 | - 'is_unique' => $obj->lang->get('fv_is_unique'), |
|
| 122 | - 'is_unique_update' => $obj->lang->get('fv_is_unique_update'), |
|
| 123 | - 'exists' => $obj->lang->get('fv_exists'), |
|
| 124 | - 'regex' => $obj->lang->get('fv_regex'), |
|
| 125 | - 'in_list' => $obj->lang->get('fv_in_list'), |
|
| 126 | - 'numeric' => $obj->lang->get('fv_numeric'), |
|
| 127 | - 'callback' => $obj->lang->get('fv_callback'), |
|
| 128 | - ); |
|
| 129 | - $this->_resetValidation(); |
|
| 130 | - $this->setData($obj->request->post(null)); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Reset the form validation instance |
|
| 135 | - */ |
|
| 136 | - protected function _resetValidation() { |
|
| 137 | - $this->_rules = array(); |
|
| 138 | - $this->_labels = array(); |
|
| 139 | - $this->_errorPhraseOverrides = array(); |
|
| 140 | - $this->_errors = array(); |
|
| 141 | - $this->_success = false; |
|
| 142 | - $this->_forceFail = false; |
|
| 143 | - $this->data = array(); |
|
| 105 | + Loader::lang('form_validation'); |
|
| 106 | + $obj = & get_instance(); |
|
| 107 | + $this->_errorsMessages = array( |
|
| 108 | + 'required' => $obj->lang->get('fv_required'), |
|
| 109 | + 'min_length' => $obj->lang->get('fv_min_length'), |
|
| 110 | + 'max_length' => $obj->lang->get('fv_max_length'), |
|
| 111 | + 'exact_length' => $obj->lang->get('fv_exact_length'), |
|
| 112 | + 'less_than' => $obj->lang->get('fv_less_than'), |
|
| 113 | + 'greater_than' => $obj->lang->get('fv_greater_than'), |
|
| 114 | + 'matches' => $obj->lang->get('fv_matches'), |
|
| 115 | + 'valid_email' => $obj->lang->get('fv_valid_email'), |
|
| 116 | + 'not_equal' => array( |
|
| 117 | + 'post:key' => $obj->lang->get('fv_not_equal_post_key'), |
|
| 118 | + 'string' => $obj->lang->get('fv_not_equal_string') |
|
| 119 | + ), |
|
| 120 | + 'depends' => $obj->lang->get('fv_depends'), |
|
| 121 | + 'is_unique' => $obj->lang->get('fv_is_unique'), |
|
| 122 | + 'is_unique_update' => $obj->lang->get('fv_is_unique_update'), |
|
| 123 | + 'exists' => $obj->lang->get('fv_exists'), |
|
| 124 | + 'regex' => $obj->lang->get('fv_regex'), |
|
| 125 | + 'in_list' => $obj->lang->get('fv_in_list'), |
|
| 126 | + 'numeric' => $obj->lang->get('fv_numeric'), |
|
| 127 | + 'callback' => $obj->lang->get('fv_callback'), |
|
| 128 | + ); |
|
| 129 | + $this->_resetValidation(); |
|
| 130 | + $this->setData($obj->request->post(null)); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Reset the form validation instance |
|
| 135 | + */ |
|
| 136 | + protected function _resetValidation() { |
|
| 137 | + $this->_rules = array(); |
|
| 138 | + $this->_labels = array(); |
|
| 139 | + $this->_errorPhraseOverrides = array(); |
|
| 140 | + $this->_errors = array(); |
|
| 141 | + $this->_success = false; |
|
| 142 | + $this->_forceFail = false; |
|
| 143 | + $this->data = array(); |
|
| 144 | 144 | $this->enableCsrfCheck = false; |
| 145 | - } |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - /** |
|
| 148 | - * Set the form validation data |
|
| 149 | - * @param array $data the values to be validated |
|
| 147 | + /** |
|
| 148 | + * Set the form validation data |
|
| 149 | + * @param array $data the values to be validated |
|
| 150 | 150 | * |
| 151 | - * @return FormValidation Current instance of object. |
|
| 152 | - */ |
|
| 153 | - public function setData(array $data){ |
|
| 154 | - $this->logger->debug('Setting the form validation data, the values are: ' . stringfy_vars($data)); |
|
| 155 | - $this->data = $data; |
|
| 151 | + * @return FormValidation Current instance of object. |
|
| 152 | + */ |
|
| 153 | + public function setData(array $data){ |
|
| 154 | + $this->logger->debug('Setting the form validation data, the values are: ' . stringfy_vars($data)); |
|
| 155 | + $this->data = $data; |
|
| 156 | 156 | return $this; |
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Get the form validation data |
|
| 161 | - * @return array the form validation data to be validated |
|
| 162 | - */ |
|
| 163 | - public function getData(){ |
|
| 164 | - return $this->data; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Get the validation function name to validate a rule |
|
| 169 | - * |
|
| 170 | - * @return string the function name |
|
| 171 | - */ |
|
| 172 | - protected function _toCallCase($funcName, $prefix='_validate') { |
|
| 173 | - $funcName = strtolower($funcName); |
|
| 174 | - $finalFuncName = $prefix; |
|
| 175 | - foreach (explode('_', $funcName) as $funcNamePart) { |
|
| 176 | - $finalFuncName .= strtoupper($funcNamePart[0]) . substr($funcNamePart, 1); |
|
| 177 | - } |
|
| 178 | - return $finalFuncName; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Returns the boolean of the data status success. It goes by the simple |
|
| 183 | - * |
|
| 184 | - * @return boolean Whether or not the data validation has succeeded |
|
| 185 | - */ |
|
| 186 | - public function isSuccess() { |
|
| 187 | - return $this->_success; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * Checks if the request method is POST or the Data to be validated is set |
|
| 192 | - * |
|
| 193 | - * @return boolean Whether or not the form has been submitted or the data is available for validation. |
|
| 194 | - */ |
|
| 195 | - public function canDoValidation() { |
|
| 196 | - return get_instance()->request->method() === 'POST' || ! empty($this->data); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Runs _run once POST data has been submitted or data is set manually. |
|
| 201 | - * |
|
| 202 | - * @return boolean |
|
| 203 | - */ |
|
| 204 | - public function run() { |
|
| 205 | - if ($this->canDoValidation()) { |
|
| 206 | - $this->logger->info('The data to validate are listed below: ' . stringfy_vars($this->getData())); |
|
| 207 | - $this->_run(); |
|
| 208 | - } |
|
| 209 | - return $this->isSuccess(); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * Takes and trims each data, if it has any rules, we parse the rule string and run |
|
| 214 | - * each rule against the data value. Sets _success to true if there are no errors |
|
| 215 | - * afterwards. |
|
| 216 | - */ |
|
| 217 | - protected function _run() { |
|
| 218 | - if(get_instance()->request->method() == 'POST' || $this->enableCsrfCheck){ |
|
| 219 | - $this->logger->debug('Check if CSRF is enabled in configuration'); |
|
| 220 | - //first check for CSRF |
|
| 221 | - if( get_config('csrf_enable', false) || $this->enableCsrfCheck){ |
|
| 222 | - $this->logger->info('Check the CSRF value if is valid'); |
|
| 223 | - if(! Security::validateCSRF()){ |
|
| 224 | - show_error('Invalide data, Cross Site Request Forgery do his job, the data to validate is corrupted.'); |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - else{ |
|
| 228 | - $this->logger->info('CSRF is not enabled in configuration or not set manully, no need to check it'); |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - ///////////////////////////////////////////// |
|
| 232 | - $this->_forceFail = false; |
|
| 233 | - |
|
| 234 | - foreach ($this->getData() as $inputName => $inputVal) { |
|
| 235 | - if(is_array($this->data[$inputName])){ |
|
| 236 | - $this->data[$inputName] = array_map('trim', $this->data[$inputName]); |
|
| 237 | - } |
|
| 238 | - else{ |
|
| 239 | - $this->data[$inputName] = trim($this->data[$inputName]); |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - if (array_key_exists($inputName, $this->_rules)) { |
|
| 243 | - foreach ($this->_parseRuleString($this->_rules[$inputName]) as $eachRule) { |
|
| 244 | - $this->_validateRule($inputName, $this->data[$inputName], $eachRule); |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - if (empty($this->_errors) && $this->_forceFail === false) { |
|
| 250 | - $this->_success = true; |
|
| 251 | - } |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * Adds a rule to a form data validation field. |
|
| 256 | - * |
|
| 257 | - * @param string $inputField Name of the field or the data key to add a rule to |
|
| 258 | - * @param string $ruleSets PIPE seperated string of rules |
|
| 259 | - * |
|
| 260 | - * @return FormValidation Current instance of object. |
|
| 261 | - */ |
|
| 262 | - public function setRule($inputField, $inputLabel, $ruleSets) { |
|
| 263 | - $this->_rules[$inputField] = $ruleSets; |
|
| 264 | - $this->_labels[$inputField] = $inputLabel; |
|
| 265 | - $this->logger->info('Set the field rule: name [' .$inputField. '], label [' .$inputLabel. '], rules [' .$ruleSets. ']'); |
|
| 266 | - return $this; |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * Takes an array of rules and uses setRule() to set them, accepts an array |
|
| 271 | - * of rule names rather than a pipe-delimited string as well. |
|
| 272 | - * @param array $ruleSets |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Get the form validation data |
|
| 161 | + * @return array the form validation data to be validated |
|
| 162 | + */ |
|
| 163 | + public function getData(){ |
|
| 164 | + return $this->data; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Get the validation function name to validate a rule |
|
| 169 | + * |
|
| 170 | + * @return string the function name |
|
| 171 | + */ |
|
| 172 | + protected function _toCallCase($funcName, $prefix='_validate') { |
|
| 173 | + $funcName = strtolower($funcName); |
|
| 174 | + $finalFuncName = $prefix; |
|
| 175 | + foreach (explode('_', $funcName) as $funcNamePart) { |
|
| 176 | + $finalFuncName .= strtoupper($funcNamePart[0]) . substr($funcNamePart, 1); |
|
| 177 | + } |
|
| 178 | + return $finalFuncName; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Returns the boolean of the data status success. It goes by the simple |
|
| 183 | + * |
|
| 184 | + * @return boolean Whether or not the data validation has succeeded |
|
| 185 | + */ |
|
| 186 | + public function isSuccess() { |
|
| 187 | + return $this->_success; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * Checks if the request method is POST or the Data to be validated is set |
|
| 192 | + * |
|
| 193 | + * @return boolean Whether or not the form has been submitted or the data is available for validation. |
|
| 194 | + */ |
|
| 195 | + public function canDoValidation() { |
|
| 196 | + return get_instance()->request->method() === 'POST' || ! empty($this->data); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * Runs _run once POST data has been submitted or data is set manually. |
|
| 201 | + * |
|
| 202 | + * @return boolean |
|
| 203 | + */ |
|
| 204 | + public function run() { |
|
| 205 | + if ($this->canDoValidation()) { |
|
| 206 | + $this->logger->info('The data to validate are listed below: ' . stringfy_vars($this->getData())); |
|
| 207 | + $this->_run(); |
|
| 208 | + } |
|
| 209 | + return $this->isSuccess(); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * Takes and trims each data, if it has any rules, we parse the rule string and run |
|
| 214 | + * each rule against the data value. Sets _success to true if there are no errors |
|
| 215 | + * afterwards. |
|
| 216 | + */ |
|
| 217 | + protected function _run() { |
|
| 218 | + if(get_instance()->request->method() == 'POST' || $this->enableCsrfCheck){ |
|
| 219 | + $this->logger->debug('Check if CSRF is enabled in configuration'); |
|
| 220 | + //first check for CSRF |
|
| 221 | + if( get_config('csrf_enable', false) || $this->enableCsrfCheck){ |
|
| 222 | + $this->logger->info('Check the CSRF value if is valid'); |
|
| 223 | + if(! Security::validateCSRF()){ |
|
| 224 | + show_error('Invalide data, Cross Site Request Forgery do his job, the data to validate is corrupted.'); |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + else{ |
|
| 228 | + $this->logger->info('CSRF is not enabled in configuration or not set manully, no need to check it'); |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + ///////////////////////////////////////////// |
|
| 232 | + $this->_forceFail = false; |
|
| 233 | + |
|
| 234 | + foreach ($this->getData() as $inputName => $inputVal) { |
|
| 235 | + if(is_array($this->data[$inputName])){ |
|
| 236 | + $this->data[$inputName] = array_map('trim', $this->data[$inputName]); |
|
| 237 | + } |
|
| 238 | + else{ |
|
| 239 | + $this->data[$inputName] = trim($this->data[$inputName]); |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + if (array_key_exists($inputName, $this->_rules)) { |
|
| 243 | + foreach ($this->_parseRuleString($this->_rules[$inputName]) as $eachRule) { |
|
| 244 | + $this->_validateRule($inputName, $this->data[$inputName], $eachRule); |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + if (empty($this->_errors) && $this->_forceFail === false) { |
|
| 250 | + $this->_success = true; |
|
| 251 | + } |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * Adds a rule to a form data validation field. |
|
| 256 | + * |
|
| 257 | + * @param string $inputField Name of the field or the data key to add a rule to |
|
| 258 | + * @param string $ruleSets PIPE seperated string of rules |
|
| 273 | 259 | * |
| 274 | 260 | * @return FormValidation Current instance of object. |
| 275 | - */ |
|
| 276 | - public function setRules(array $ruleSets) { |
|
| 277 | - foreach ($ruleSets as $ruleSet) { |
|
| 278 | - $pipeDelimitedRules = null; |
|
| 279 | - if (is_array($ruleSet['rules'])) { |
|
| 280 | - $pipeDelimitedRules = implode('|', $ruleSet['rules']); |
|
| 281 | - } else { |
|
| 282 | - $pipeDelimitedRules = $ruleSet['rules']; |
|
| 283 | - } |
|
| 284 | - $this->setRule($ruleSet['name'], $ruleSet['label'], $pipeDelimitedRules); |
|
| 285 | - } |
|
| 286 | - return $this; |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * This method creates the global errors delimiter, each argument occurs once, at the beginning, and |
|
| 291 | - * end of the errors block respectively. |
|
| 292 | - * |
|
| 293 | - * @param string $start Before block of errors gets displayed, HTML allowed. |
|
| 294 | - * @param string $end After the block of errors gets displayed, HTML allowed. |
|
| 295 | - * |
|
| 261 | + */ |
|
| 262 | + public function setRule($inputField, $inputLabel, $ruleSets) { |
|
| 263 | + $this->_rules[$inputField] = $ruleSets; |
|
| 264 | + $this->_labels[$inputField] = $inputLabel; |
|
| 265 | + $this->logger->info('Set the field rule: name [' .$inputField. '], label [' .$inputLabel. '], rules [' .$ruleSets. ']'); |
|
| 266 | + return $this; |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * Takes an array of rules and uses setRule() to set them, accepts an array |
|
| 271 | + * of rule names rather than a pipe-delimited string as well. |
|
| 272 | + * @param array $ruleSets |
|
| 273 | + * |
|
| 296 | 274 | * @return FormValidation Current instance of object. |
| 297 | - */ |
|
| 298 | - public function setErrorsDelimiter($start, $end) { |
|
| 299 | - $this->_allErrorsDelimiter[0] = $start; |
|
| 300 | - $this->_allErrorsDelimiter[1] = $end; |
|
| 301 | - return $this; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * This is the individual error delimiter, each argument occurs once before and after |
|
| 306 | - * each individual error listed. |
|
| 307 | - * |
|
| 308 | - * @param string $start Displayed before each error. |
|
| 309 | - * @param string $end Displayed after each error. |
|
| 310 | - * |
|
| 275 | + */ |
|
| 276 | + public function setRules(array $ruleSets) { |
|
| 277 | + foreach ($ruleSets as $ruleSet) { |
|
| 278 | + $pipeDelimitedRules = null; |
|
| 279 | + if (is_array($ruleSet['rules'])) { |
|
| 280 | + $pipeDelimitedRules = implode('|', $ruleSet['rules']); |
|
| 281 | + } else { |
|
| 282 | + $pipeDelimitedRules = $ruleSet['rules']; |
|
| 283 | + } |
|
| 284 | + $this->setRule($ruleSet['name'], $ruleSet['label'], $pipeDelimitedRules); |
|
| 285 | + } |
|
| 286 | + return $this; |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * This method creates the global errors delimiter, each argument occurs once, at the beginning, and |
|
| 291 | + * end of the errors block respectively. |
|
| 292 | + * |
|
| 293 | + * @param string $start Before block of errors gets displayed, HTML allowed. |
|
| 294 | + * @param string $end After the block of errors gets displayed, HTML allowed. |
|
| 295 | + * |
|
| 311 | 296 | * @return FormValidation Current instance of object. |
| 312 | - */ |
|
| 313 | - public function setErrorDelimiter($start, $end) { |
|
| 314 | - $this->_eachErrorDelimiter[0] = $start; |
|
| 315 | - $this->_eachErrorDelimiter[1] = $end; |
|
| 316 | - return $this; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * Get the each errors delimiters |
|
| 321 | - * |
|
| 322 | - * @return array |
|
| 323 | - */ |
|
| 324 | - public function getErrorDelimiter() { |
|
| 325 | - return $this->_eachErrorDelimiter; |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * Get the all errors delimiters |
|
| 330 | - * |
|
| 331 | - * @return array |
|
| 332 | - */ |
|
| 333 | - public function getErrorsDelimiter() { |
|
| 334 | - return $this->_allErrorsDelimiter; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * This sets a custom error message that can override the default error phrase provided |
|
| 339 | - * by FormValidation, it can be used in the format of setMessage('rule', 'error phrase') |
|
| 340 | - * which will globally change the error phrase of that rule, or in the format of: |
|
| 341 | - * setMessage('rule', 'fieldname', 'error phrase') - which will only change the error phrase for |
|
| 342 | - * that rule, applied on that field. |
|
| 343 | - * |
|
| 344 | - * @return boolean True on success, false on failure. |
|
| 345 | - */ |
|
| 346 | - public function setMessage() { |
|
| 347 | - $numArgs = func_num_args(); |
|
| 348 | - switch ($numArgs) { |
|
| 349 | - default: |
|
| 350 | - return false; |
|
| 351 | - break; |
|
| 352 | - // A global rule error message |
|
| 353 | - case 2: |
|
| 354 | - foreach ($this->post(null) as $key => $val) { |
|
| 355 | - $this->_errorPhraseOverrides[$key][func_get_arg(0)] = func_get_arg(1); |
|
| 356 | - } |
|
| 357 | - break; |
|
| 358 | - // Field specific rule error message |
|
| 359 | - case 3: |
|
| 360 | - $this->_errorPhraseOverrides[func_get_arg(1)][func_get_arg(0)] = func_get_arg(2); |
|
| 361 | - break; |
|
| 362 | - } |
|
| 363 | - return true; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - /** |
|
| 367 | - * Adds a custom error message in the errorSet array, that will |
|
| 368 | - * forcibly display it. |
|
| 369 | - * |
|
| 370 | - * @param string $inputName The form input name or data key |
|
| 371 | - * @param string $errorMessage Error to display |
|
| 372 | - * |
|
| 373 | - * @return formValidation Current instance of the object |
|
| 374 | - */ |
|
| 375 | - public function setCustomError($inputName, $errorMessage) { |
|
| 376 | - $errorMessage = str_replace('%1', $this->_labels[$inputName], $errorMessage); |
|
| 377 | - $this->_errors[$inputName] = $errorMessage; |
|
| 378 | - return $this; |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - /** |
|
| 382 | - * Allows for an accesor to any/all post values, if a value of null is passed as the key, it |
|
| 383 | - * will recursively find all keys/values of the $_POST array or data array. It also automatically trims |
|
| 384 | - * all values. |
|
| 385 | - * |
|
| 386 | - * @param string $key Key of $this->data to be found, pass null for all Key => Val pairs. |
|
| 387 | - * @param boolean $trim Defaults to true, trims all $this->data values. |
|
| 388 | - * @return string/array Array of post or data values if null is passed as key, string if only one key is desired. |
|
| 389 | - */ |
|
| 390 | - public function post($key = null, $trim = true) { |
|
| 391 | - $returnValue = null; |
|
| 392 | - if (is_null($key)) { |
|
| 393 | - $returnValue = array(); |
|
| 394 | - foreach ($this->getData() as $key => $val) { |
|
| 395 | - $returnValue[$key] = $this->post($key, $trim); |
|
| 396 | - } |
|
| 397 | - } else { |
|
| 398 | - $returnValue = (array_key_exists($key, $this->getData())) ? (($trim) ? trim($this->data[$key]) : $this->data[$key]) : false; |
|
| 399 | - } |
|
| 400 | - return $returnValue; |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * Gets all errors from errorSet and displays them, can be echo out from the |
|
| 405 | - * function or just returned. |
|
| 406 | - * |
|
| 407 | - * @param boolean $limit number of error to display or return |
|
| 408 | - * @param boolean $echo Whether or not the values are to be returned or displayed |
|
| 409 | - * |
|
| 410 | - * @return string Errors formatted for output |
|
| 411 | - */ |
|
| 412 | - public function displayErrors($limit = null, $echo = true) { |
|
| 413 | - list($errorsStart, $errorsEnd) = $this->_allErrorsDelimiter; |
|
| 414 | - list($errorStart, $errorEnd) = $this->_eachErrorDelimiter; |
|
| 415 | - $errorOutput = $errorsStart; |
|
| 416 | - $i = 0; |
|
| 417 | - if (!empty($this->_errors)) { |
|
| 418 | - foreach ($this->_errors as $fieldName => $error) { |
|
| 419 | - if ($i === $limit) { |
|
| 420 | - break; |
|
| 421 | - } |
|
| 422 | - $errorOutput .= $errorStart; |
|
| 423 | - $errorOutput .= $error; |
|
| 424 | - $errorOutput .= $errorEnd; |
|
| 425 | - $i++; |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - $errorOutput .= $errorsEnd; |
|
| 429 | - echo ($echo) ? $errorOutput : ''; |
|
| 430 | - return (! $echo) ? $errorOutput : null; |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - /** |
|
| 434 | - * Returns raw array of errors in no format instead of displaying them |
|
| 435 | - * formatted. |
|
| 436 | - * |
|
| 437 | - * @return array |
|
| 438 | - */ |
|
| 439 | - public function returnErrors() { |
|
| 440 | - return $this->_errors; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - /** |
|
| 444 | - * Breaks up a PIPE seperated string of rules, and puts them into an array. |
|
| 445 | - * |
|
| 446 | - * @param string $ruleString String to be parsed. |
|
| 447 | - * |
|
| 448 | - * @return array Array of each value in original string. |
|
| 449 | - */ |
|
| 450 | - protected function _parseRuleString($ruleString) { |
|
| 451 | - $ruleSets = array(); |
|
| 452 | - /* |
|
| 297 | + */ |
|
| 298 | + public function setErrorsDelimiter($start, $end) { |
|
| 299 | + $this->_allErrorsDelimiter[0] = $start; |
|
| 300 | + $this->_allErrorsDelimiter[1] = $end; |
|
| 301 | + return $this; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * This is the individual error delimiter, each argument occurs once before and after |
|
| 306 | + * each individual error listed. |
|
| 307 | + * |
|
| 308 | + * @param string $start Displayed before each error. |
|
| 309 | + * @param string $end Displayed after each error. |
|
| 310 | + * |
|
| 311 | + * @return FormValidation Current instance of object. |
|
| 312 | + */ |
|
| 313 | + public function setErrorDelimiter($start, $end) { |
|
| 314 | + $this->_eachErrorDelimiter[0] = $start; |
|
| 315 | + $this->_eachErrorDelimiter[1] = $end; |
|
| 316 | + return $this; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * Get the each errors delimiters |
|
| 321 | + * |
|
| 322 | + * @return array |
|
| 323 | + */ |
|
| 324 | + public function getErrorDelimiter() { |
|
| 325 | + return $this->_eachErrorDelimiter; |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * Get the all errors delimiters |
|
| 330 | + * |
|
| 331 | + * @return array |
|
| 332 | + */ |
|
| 333 | + public function getErrorsDelimiter() { |
|
| 334 | + return $this->_allErrorsDelimiter; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * This sets a custom error message that can override the default error phrase provided |
|
| 339 | + * by FormValidation, it can be used in the format of setMessage('rule', 'error phrase') |
|
| 340 | + * which will globally change the error phrase of that rule, or in the format of: |
|
| 341 | + * setMessage('rule', 'fieldname', 'error phrase') - which will only change the error phrase for |
|
| 342 | + * that rule, applied on that field. |
|
| 343 | + * |
|
| 344 | + * @return boolean True on success, false on failure. |
|
| 345 | + */ |
|
| 346 | + public function setMessage() { |
|
| 347 | + $numArgs = func_num_args(); |
|
| 348 | + switch ($numArgs) { |
|
| 349 | + default: |
|
| 350 | + return false; |
|
| 351 | + break; |
|
| 352 | + // A global rule error message |
|
| 353 | + case 2: |
|
| 354 | + foreach ($this->post(null) as $key => $val) { |
|
| 355 | + $this->_errorPhraseOverrides[$key][func_get_arg(0)] = func_get_arg(1); |
|
| 356 | + } |
|
| 357 | + break; |
|
| 358 | + // Field specific rule error message |
|
| 359 | + case 3: |
|
| 360 | + $this->_errorPhraseOverrides[func_get_arg(1)][func_get_arg(0)] = func_get_arg(2); |
|
| 361 | + break; |
|
| 362 | + } |
|
| 363 | + return true; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + /** |
|
| 367 | + * Adds a custom error message in the errorSet array, that will |
|
| 368 | + * forcibly display it. |
|
| 369 | + * |
|
| 370 | + * @param string $inputName The form input name or data key |
|
| 371 | + * @param string $errorMessage Error to display |
|
| 372 | + * |
|
| 373 | + * @return formValidation Current instance of the object |
|
| 374 | + */ |
|
| 375 | + public function setCustomError($inputName, $errorMessage) { |
|
| 376 | + $errorMessage = str_replace('%1', $this->_labels[$inputName], $errorMessage); |
|
| 377 | + $this->_errors[$inputName] = $errorMessage; |
|
| 378 | + return $this; |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + /** |
|
| 382 | + * Allows for an accesor to any/all post values, if a value of null is passed as the key, it |
|
| 383 | + * will recursively find all keys/values of the $_POST array or data array. It also automatically trims |
|
| 384 | + * all values. |
|
| 385 | + * |
|
| 386 | + * @param string $key Key of $this->data to be found, pass null for all Key => Val pairs. |
|
| 387 | + * @param boolean $trim Defaults to true, trims all $this->data values. |
|
| 388 | + * @return string/array Array of post or data values if null is passed as key, string if only one key is desired. |
|
| 389 | + */ |
|
| 390 | + public function post($key = null, $trim = true) { |
|
| 391 | + $returnValue = null; |
|
| 392 | + if (is_null($key)) { |
|
| 393 | + $returnValue = array(); |
|
| 394 | + foreach ($this->getData() as $key => $val) { |
|
| 395 | + $returnValue[$key] = $this->post($key, $trim); |
|
| 396 | + } |
|
| 397 | + } else { |
|
| 398 | + $returnValue = (array_key_exists($key, $this->getData())) ? (($trim) ? trim($this->data[$key]) : $this->data[$key]) : false; |
|
| 399 | + } |
|
| 400 | + return $returnValue; |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * Gets all errors from errorSet and displays them, can be echo out from the |
|
| 405 | + * function or just returned. |
|
| 406 | + * |
|
| 407 | + * @param boolean $limit number of error to display or return |
|
| 408 | + * @param boolean $echo Whether or not the values are to be returned or displayed |
|
| 409 | + * |
|
| 410 | + * @return string Errors formatted for output |
|
| 411 | + */ |
|
| 412 | + public function displayErrors($limit = null, $echo = true) { |
|
| 413 | + list($errorsStart, $errorsEnd) = $this->_allErrorsDelimiter; |
|
| 414 | + list($errorStart, $errorEnd) = $this->_eachErrorDelimiter; |
|
| 415 | + $errorOutput = $errorsStart; |
|
| 416 | + $i = 0; |
|
| 417 | + if (!empty($this->_errors)) { |
|
| 418 | + foreach ($this->_errors as $fieldName => $error) { |
|
| 419 | + if ($i === $limit) { |
|
| 420 | + break; |
|
| 421 | + } |
|
| 422 | + $errorOutput .= $errorStart; |
|
| 423 | + $errorOutput .= $error; |
|
| 424 | + $errorOutput .= $errorEnd; |
|
| 425 | + $i++; |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + $errorOutput .= $errorsEnd; |
|
| 429 | + echo ($echo) ? $errorOutput : ''; |
|
| 430 | + return (! $echo) ? $errorOutput : null; |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + /** |
|
| 434 | + * Returns raw array of errors in no format instead of displaying them |
|
| 435 | + * formatted. |
|
| 436 | + * |
|
| 437 | + * @return array |
|
| 438 | + */ |
|
| 439 | + public function returnErrors() { |
|
| 440 | + return $this->_errors; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + /** |
|
| 444 | + * Breaks up a PIPE seperated string of rules, and puts them into an array. |
|
| 445 | + * |
|
| 446 | + * @param string $ruleString String to be parsed. |
|
| 447 | + * |
|
| 448 | + * @return array Array of each value in original string. |
|
| 449 | + */ |
|
| 450 | + protected function _parseRuleString($ruleString) { |
|
| 451 | + $ruleSets = array(); |
|
| 452 | + /* |
|
| 453 | 453 | //////////////// hack for regex rule that can contain "|" |
| 454 | 454 | */ |
| 455 | - if(strpos($ruleString, 'regex') !== false){ |
|
| 456 | - $regexRule = array(); |
|
| 457 | - $rule = '#regex\[\/(.*)\/([a-zA-Z0-9]?)\]#'; |
|
| 458 | - preg_match($rule, $ruleString, $regexRule); |
|
| 459 | - $ruleStringTemp = preg_replace($rule, '', $ruleString); |
|
| 460 | - if(isset($regexRule[0]) && !empty($regexRule[0])){ |
|
| 461 | - $ruleSets[] = $regexRule[0]; |
|
| 462 | - } |
|
| 463 | - $ruleStringRegex = explode('|', $ruleStringTemp); |
|
| 464 | - if(is_array($ruleStringRegex)){ |
|
| 465 | - foreach ($ruleStringRegex as $rule) { |
|
| 466 | - $rule = trim($rule); |
|
| 467 | - if($rule){ |
|
| 468 | - $ruleSets[] = $rule; |
|
| 469 | - } |
|
| 470 | - } |
|
| 471 | - } |
|
| 472 | - } |
|
| 473 | - /***********************************/ |
|
| 474 | - else{ |
|
| 475 | - if (strpos($ruleString, '|') !== FALSE) { |
|
| 476 | - $ruleSets = explode('|', $ruleString); |
|
| 477 | - } else { |
|
| 478 | - $ruleSets[] = $ruleString; |
|
| 479 | - } |
|
| 480 | - } |
|
| 481 | - return $ruleSets; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - /** |
|
| 485 | - * Returns whether or not a field obtains the rule "required". |
|
| 486 | - * |
|
| 487 | - * @param string $fieldName Field to check if required. |
|
| 488 | - * |
|
| 489 | - * @return boolean Whether or not the field is required. |
|
| 490 | - */ |
|
| 491 | - protected function _fieldIsRequired($fieldName) { |
|
| 492 | - $rules = $this->_parseRuleString($this->_rules[$fieldName]); |
|
| 493 | - return (in_array('required', $rules)); |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - /** |
|
| 497 | - * Takes a data input name, it's value, and the rule it's being validated against (ex: max_length[16]) |
|
| 498 | - * and adds an error to the errorSet if it fails validation of the rule. |
|
| 499 | - * |
|
| 500 | - * @param string $inputName Name or key of the validation data |
|
| 501 | - * @param string $inputVal Value of the validation data |
|
| 502 | - * @param string $ruleName Rule to be validated against, including args (exact_length[5]) |
|
| 503 | - * @return void |
|
| 504 | - */ |
|
| 505 | - protected function _validateRule($inputName, $inputVal, $ruleName) { |
|
| 506 | - $this->logger->debug('Rule validation of field [' .$inputName. '], value [' .$inputVal. '], rule [' .$ruleName. ']'); |
|
| 507 | - // Array to store args |
|
| 508 | - $ruleArgs = array(); |
|
| 509 | - |
|
| 510 | - // Get the rule arguments, realRule is just the base rule name |
|
| 511 | - // Like min_length instead of min_length[3] |
|
| 512 | - $realRule = preg_match('/\[(.*)\]/', $ruleName, $ruleArgs); |
|
| 513 | - $ruleName = preg_replace('/\[(.*)\]/', '', $ruleName); |
|
| 455 | + if(strpos($ruleString, 'regex') !== false){ |
|
| 456 | + $regexRule = array(); |
|
| 457 | + $rule = '#regex\[\/(.*)\/([a-zA-Z0-9]?)\]#'; |
|
| 458 | + preg_match($rule, $ruleString, $regexRule); |
|
| 459 | + $ruleStringTemp = preg_replace($rule, '', $ruleString); |
|
| 460 | + if(isset($regexRule[0]) && !empty($regexRule[0])){ |
|
| 461 | + $ruleSets[] = $regexRule[0]; |
|
| 462 | + } |
|
| 463 | + $ruleStringRegex = explode('|', $ruleStringTemp); |
|
| 464 | + if(is_array($ruleStringRegex)){ |
|
| 465 | + foreach ($ruleStringRegex as $rule) { |
|
| 466 | + $rule = trim($rule); |
|
| 467 | + if($rule){ |
|
| 468 | + $ruleSets[] = $rule; |
|
| 469 | + } |
|
| 470 | + } |
|
| 471 | + } |
|
| 472 | + } |
|
| 473 | + /***********************************/ |
|
| 474 | + else{ |
|
| 475 | + if (strpos($ruleString, '|') !== FALSE) { |
|
| 476 | + $ruleSets = explode('|', $ruleString); |
|
| 477 | + } else { |
|
| 478 | + $ruleSets[] = $ruleString; |
|
| 479 | + } |
|
| 480 | + } |
|
| 481 | + return $ruleSets; |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + /** |
|
| 485 | + * Returns whether or not a field obtains the rule "required". |
|
| 486 | + * |
|
| 487 | + * @param string $fieldName Field to check if required. |
|
| 488 | + * |
|
| 489 | + * @return boolean Whether or not the field is required. |
|
| 490 | + */ |
|
| 491 | + protected function _fieldIsRequired($fieldName) { |
|
| 492 | + $rules = $this->_parseRuleString($this->_rules[$fieldName]); |
|
| 493 | + return (in_array('required', $rules)); |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + /** |
|
| 497 | + * Takes a data input name, it's value, and the rule it's being validated against (ex: max_length[16]) |
|
| 498 | + * and adds an error to the errorSet if it fails validation of the rule. |
|
| 499 | + * |
|
| 500 | + * @param string $inputName Name or key of the validation data |
|
| 501 | + * @param string $inputVal Value of the validation data |
|
| 502 | + * @param string $ruleName Rule to be validated against, including args (exact_length[5]) |
|
| 503 | + * @return void |
|
| 504 | + */ |
|
| 505 | + protected function _validateRule($inputName, $inputVal, $ruleName) { |
|
| 506 | + $this->logger->debug('Rule validation of field [' .$inputName. '], value [' .$inputVal. '], rule [' .$ruleName. ']'); |
|
| 507 | + // Array to store args |
|
| 508 | + $ruleArgs = array(); |
|
| 509 | + |
|
| 510 | + // Get the rule arguments, realRule is just the base rule name |
|
| 511 | + // Like min_length instead of min_length[3] |
|
| 512 | + $realRule = preg_match('/\[(.*)\]/', $ruleName, $ruleArgs); |
|
| 513 | + $ruleName = preg_replace('/\[(.*)\]/', '', $ruleName); |
|
| 514 | 514 | |
| 515 | - if (method_exists($this, $this->_toCallCase($ruleName))) { |
|
| 516 | - $methodToCall = $this->_toCallCase($ruleName); |
|
| 517 | - @call_user_func(array($this, $methodToCall), $inputName, $ruleName, $ruleArgs); |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - return; |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - /** |
|
| 524 | - * Set error for the given field or key |
|
| 525 | - * |
|
| 526 | - * @param string $inputName the input or key name |
|
| 527 | - * @param string $ruleName the rule name |
|
| 528 | - * @param array $replacements |
|
| 529 | - */ |
|
| 530 | - protected function _setError($inputName, $ruleName, $replacements = array()) { |
|
| 531 | - $rulePhraseKeyParts = explode(',', $ruleName); |
|
| 532 | - foreach ($rulePhraseKeyParts as $rulePhraseKeyPart) { |
|
| 533 | - if (array_key_exists($rulePhraseKeyPart, $this->_errorsMessages)) { |
|
| 534 | - $rulePhrase = $this->_errorsMessages[$rulePhraseKeyPart]; |
|
| 535 | - } else { |
|
| 536 | - $rulePhrase = $rulePhrase[$rulePhraseKeyPart]; |
|
| 537 | - } |
|
| 538 | - } |
|
| 539 | - // Any overrides? |
|
| 540 | - if (array_key_exists($inputName, $this->_errorPhraseOverrides) && array_key_exists($ruleName, $this->_errorPhraseOverrides[$inputName])) { |
|
| 541 | - $rulePhrase = $this->_errorPhraseOverrides[$inputName][$ruleName]; |
|
| 542 | - } |
|
| 543 | - // Type cast to array in case it's a string |
|
| 544 | - $replacements = (array) $replacements; |
|
| 515 | + if (method_exists($this, $this->_toCallCase($ruleName))) { |
|
| 516 | + $methodToCall = $this->_toCallCase($ruleName); |
|
| 517 | + @call_user_func(array($this, $methodToCall), $inputName, $ruleName, $ruleArgs); |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + return; |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + /** |
|
| 524 | + * Set error for the given field or key |
|
| 525 | + * |
|
| 526 | + * @param string $inputName the input or key name |
|
| 527 | + * @param string $ruleName the rule name |
|
| 528 | + * @param array $replacements |
|
| 529 | + */ |
|
| 530 | + protected function _setError($inputName, $ruleName, $replacements = array()) { |
|
| 531 | + $rulePhraseKeyParts = explode(',', $ruleName); |
|
| 532 | + foreach ($rulePhraseKeyParts as $rulePhraseKeyPart) { |
|
| 533 | + if (array_key_exists($rulePhraseKeyPart, $this->_errorsMessages)) { |
|
| 534 | + $rulePhrase = $this->_errorsMessages[$rulePhraseKeyPart]; |
|
| 535 | + } else { |
|
| 536 | + $rulePhrase = $rulePhrase[$rulePhraseKeyPart]; |
|
| 537 | + } |
|
| 538 | + } |
|
| 539 | + // Any overrides? |
|
| 540 | + if (array_key_exists($inputName, $this->_errorPhraseOverrides) && array_key_exists($ruleName, $this->_errorPhraseOverrides[$inputName])) { |
|
| 541 | + $rulePhrase = $this->_errorPhraseOverrides[$inputName][$ruleName]; |
|
| 542 | + } |
|
| 543 | + // Type cast to array in case it's a string |
|
| 544 | + $replacements = (array) $replacements; |
|
| 545 | 545 | $replacementCount = count($replacements); |
| 546 | - for ($i = 1; $i <= $replacementCount; $i++) { |
|
| 547 | - $key = $i - 1; |
|
| 548 | - $rulePhrase = str_replace('%' . $i, $replacements[$key], $rulePhrase); |
|
| 549 | - } |
|
| 550 | - if (! array_key_exists($inputName, $this->_errors)) { |
|
| 551 | - $this->_errors[$inputName] = $rulePhrase; |
|
| 552 | - } |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - /** |
|
| 556 | - * Used to run a callback for the callback rule, as well as pass in a default |
|
| 557 | - * argument of the post value. For example the username field having a rule: |
|
| 558 | - * callback[userExists] will eval userExists(data[username]) - Note the use |
|
| 559 | - * of eval over call_user_func is in case the function is not user defined. |
|
| 560 | - * |
|
| 561 | - * @param type $inputArg |
|
| 562 | - * @param string $callbackFunc |
|
| 563 | - * |
|
| 564 | - * @return anything |
|
| 565 | - */ |
|
| 566 | - protected function _runCallback($inputArg, $callbackFunc) { |
|
| 546 | + for ($i = 1; $i <= $replacementCount; $i++) { |
|
| 547 | + $key = $i - 1; |
|
| 548 | + $rulePhrase = str_replace('%' . $i, $replacements[$key], $rulePhrase); |
|
| 549 | + } |
|
| 550 | + if (! array_key_exists($inputName, $this->_errors)) { |
|
| 551 | + $this->_errors[$inputName] = $rulePhrase; |
|
| 552 | + } |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + /** |
|
| 556 | + * Used to run a callback for the callback rule, as well as pass in a default |
|
| 557 | + * argument of the post value. For example the username field having a rule: |
|
| 558 | + * callback[userExists] will eval userExists(data[username]) - Note the use |
|
| 559 | + * of eval over call_user_func is in case the function is not user defined. |
|
| 560 | + * |
|
| 561 | + * @param type $inputArg |
|
| 562 | + * @param string $callbackFunc |
|
| 563 | + * |
|
| 564 | + * @return anything |
|
| 565 | + */ |
|
| 566 | + protected function _runCallback($inputArg, $callbackFunc) { |
|
| 567 | 567 | return eval('return ' . $callbackFunc . '("' . $inputArg . '");'); |
| 568 | - } |
|
| 569 | - |
|
| 570 | - /** |
|
| 571 | - * Used for applying a rule only if the empty callback evaluates to true, |
|
| 572 | - * for example required[funcName] - This runs funcName without passing any |
|
| 573 | - * arguments. |
|
| 574 | - * |
|
| 575 | - * @param string $callbackFunc |
|
| 576 | - * |
|
| 577 | - * @return anything |
|
| 578 | - */ |
|
| 579 | - protected function _runEmptyCallback($callbackFunc) { |
|
| 580 | - return eval('return ' . $callbackFunc . '();'); |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - /** |
|
| 584 | - * Gets a specific label of a specific field input name. |
|
| 585 | - * |
|
| 586 | - * @param string $inputName |
|
| 587 | - * |
|
| 588 | - * @return string |
|
| 589 | - */ |
|
| 590 | - protected function _getLabel($inputName) { |
|
| 591 | - return (array_key_exists($inputName, $this->_labels)) ? $this->_labels[$inputName] : $inputName; |
|
| 592 | - } |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + /** |
|
| 571 | + * Used for applying a rule only if the empty callback evaluates to true, |
|
| 572 | + * for example required[funcName] - This runs funcName without passing any |
|
| 573 | + * arguments. |
|
| 574 | + * |
|
| 575 | + * @param string $callbackFunc |
|
| 576 | + * |
|
| 577 | + * @return anything |
|
| 578 | + */ |
|
| 579 | + protected function _runEmptyCallback($callbackFunc) { |
|
| 580 | + return eval('return ' . $callbackFunc . '();'); |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + /** |
|
| 584 | + * Gets a specific label of a specific field input name. |
|
| 585 | + * |
|
| 586 | + * @param string $inputName |
|
| 587 | + * |
|
| 588 | + * @return string |
|
| 589 | + */ |
|
| 590 | + protected function _getLabel($inputName) { |
|
| 591 | + return (array_key_exists($inputName, $this->_labels)) ? $this->_labels[$inputName] : $inputName; |
|
| 592 | + } |
|
| 593 | 593 | |
| 594 | - /** |
|
| 595 | - * Peform validation for the rule "required" |
|
| 596 | - * @param string $inputName the form field or data key name used |
|
| 597 | - * @param string $ruleName the rule name for this validation ("required") |
|
| 598 | - * @param array $ruleArgs the rules argument |
|
| 599 | - */ |
|
| 594 | + /** |
|
| 595 | + * Peform validation for the rule "required" |
|
| 596 | + * @param string $inputName the form field or data key name used |
|
| 597 | + * @param string $ruleName the rule name for this validation ("required") |
|
| 598 | + * @param array $ruleArgs the rules argument |
|
| 599 | + */ |
|
| 600 | 600 | protected function _validateRequired($inputName, $ruleName, array $ruleArgs) { |
| 601 | - $inputVal = $this->post($inputName); |
|
| 602 | - if(array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) { |
|
| 603 | - $callbackReturn = $this->_runEmptyCallback($ruleArgs[1]); |
|
| 604 | - if ($inputVal == '' && $callbackReturn == true) { |
|
| 605 | - $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
|
| 606 | - } |
|
| 607 | - } |
|
| 601 | + $inputVal = $this->post($inputName); |
|
| 602 | + if(array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) { |
|
| 603 | + $callbackReturn = $this->_runEmptyCallback($ruleArgs[1]); |
|
| 604 | + if ($inputVal == '' && $callbackReturn == true) { |
|
| 605 | + $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
|
| 606 | + } |
|
| 607 | + } |
|
| 608 | 608 | else if($inputVal == '') { |
| 609 | 609 | $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
| 610 | - } |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - /** |
|
| 614 | - * Perform validation for the honey pot so means for the validation to be failed |
|
| 615 | - * @param string $inputName the form field or data key name used |
|
| 616 | - * @param string $ruleName the rule name for this validation |
|
| 617 | - * @param array $ruleArgs the rules argument |
|
| 618 | - */ |
|
| 619 | - protected function _validateHoneypot($inputName, $ruleName, array $ruleArgs) { |
|
| 620 | - if ($this->data[$inputName] != '') { |
|
| 621 | - $this->_forceFail = true; |
|
| 622 | - } |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - /** |
|
| 626 | - * Peform validation for the rule "callback" |
|
| 627 | - * @param string $inputName the form field or data key name used |
|
| 628 | - * @param string $ruleName the rule name for this validation ("callback") |
|
| 629 | - * @param array $ruleArgs the rules argument |
|
| 630 | - */ |
|
| 631 | - protected function _validateCallback($inputName, $ruleName, array $ruleArgs) { |
|
| 632 | - if (function_exists($ruleArgs[1]) && !empty($this->data[$inputName])) { |
|
| 610 | + } |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + /** |
|
| 614 | + * Perform validation for the honey pot so means for the validation to be failed |
|
| 615 | + * @param string $inputName the form field or data key name used |
|
| 616 | + * @param string $ruleName the rule name for this validation |
|
| 617 | + * @param array $ruleArgs the rules argument |
|
| 618 | + */ |
|
| 619 | + protected function _validateHoneypot($inputName, $ruleName, array $ruleArgs) { |
|
| 620 | + if ($this->data[$inputName] != '') { |
|
| 621 | + $this->_forceFail = true; |
|
| 622 | + } |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + /** |
|
| 626 | + * Peform validation for the rule "callback" |
|
| 627 | + * @param string $inputName the form field or data key name used |
|
| 628 | + * @param string $ruleName the rule name for this validation ("callback") |
|
| 629 | + * @param array $ruleArgs the rules argument |
|
| 630 | + */ |
|
| 631 | + protected function _validateCallback($inputName, $ruleName, array $ruleArgs) { |
|
| 632 | + if (function_exists($ruleArgs[1]) && !empty($this->data[$inputName])) { |
|
| 633 | 633 | $result = $this->_runCallback($this->data[$inputName], $ruleArgs[1]); |
| 634 | 634 | if(! $result){ |
| 635 | 635 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
| 636 | 636 | } |
| 637 | - } |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - /** |
|
| 641 | - * Peform validation for the rule "depends" |
|
| 642 | - * @param string $inputName the form field or data key name used |
|
| 643 | - * @param string $ruleName the rule name for this validation ("depends") |
|
| 644 | - * @param array $ruleArgs the rules argument |
|
| 645 | - */ |
|
| 646 | - protected function _validateDepends($inputName, $ruleName, array $ruleArgs) { |
|
| 647 | - if (array_key_exists($ruleArgs[1], $this->_errors)) { |
|
| 648 | - $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
|
| 649 | - } |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - /** |
|
| 653 | - * Peform validation for the rule "not_equal" |
|
| 654 | - * @param string $inputName the form field or data key name used |
|
| 655 | - * @param string $ruleName the rule name for this validation ("not_equal") |
|
| 656 | - * @param array $ruleArgs the rules argument |
|
| 657 | - */ |
|
| 658 | - protected function _validateNotEqual($inputName, $ruleName, array $ruleArgs) { |
|
| 659 | - $canNotEqual = explode(',', $ruleArgs[1]); |
|
| 660 | - foreach ($canNotEqual as $doNotEqual) { |
|
| 661 | - $inputVal = $this->post($inputName); |
|
| 662 | - if (preg_match('/post:(.*)/', $doNotEqual)) { |
|
| 663 | - if ($inputVal == $this->data[str_replace('post:', '', $doNotEqual)]) { |
|
| 664 | - $this->_setError($inputName, $ruleName . ',post:key', array($this->_getLabel($inputName), $this->_getLabel(str_replace('post:', '', $doNotEqual)))); |
|
| 665 | - continue; |
|
| 666 | - } |
|
| 667 | - } |
|
| 637 | + } |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + /** |
|
| 641 | + * Peform validation for the rule "depends" |
|
| 642 | + * @param string $inputName the form field or data key name used |
|
| 643 | + * @param string $ruleName the rule name for this validation ("depends") |
|
| 644 | + * @param array $ruleArgs the rules argument |
|
| 645 | + */ |
|
| 646 | + protected function _validateDepends($inputName, $ruleName, array $ruleArgs) { |
|
| 647 | + if (array_key_exists($ruleArgs[1], $this->_errors)) { |
|
| 648 | + $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
|
| 649 | + } |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + /** |
|
| 653 | + * Peform validation for the rule "not_equal" |
|
| 654 | + * @param string $inputName the form field or data key name used |
|
| 655 | + * @param string $ruleName the rule name for this validation ("not_equal") |
|
| 656 | + * @param array $ruleArgs the rules argument |
|
| 657 | + */ |
|
| 658 | + protected function _validateNotEqual($inputName, $ruleName, array $ruleArgs) { |
|
| 659 | + $canNotEqual = explode(',', $ruleArgs[1]); |
|
| 660 | + foreach ($canNotEqual as $doNotEqual) { |
|
| 661 | + $inputVal = $this->post($inputName); |
|
| 662 | + if (preg_match('/post:(.*)/', $doNotEqual)) { |
|
| 663 | + if ($inputVal == $this->data[str_replace('post:', '', $doNotEqual)]) { |
|
| 664 | + $this->_setError($inputName, $ruleName . ',post:key', array($this->_getLabel($inputName), $this->_getLabel(str_replace('post:', '', $doNotEqual)))); |
|
| 665 | + continue; |
|
| 666 | + } |
|
| 667 | + } |
|
| 668 | 668 | else{ |
| 669 | - if ($inputVal == $doNotEqual) { |
|
| 670 | - $this->_setError($inputName, $ruleName . ',string', array($this->_getLabel($inputName), $doNotEqual)); |
|
| 671 | - continue; |
|
| 672 | - } |
|
| 673 | - } |
|
| 674 | - } |
|
| 675 | - } |
|
| 676 | - |
|
| 677 | - /** |
|
| 678 | - * Peform validation for the rule "matches" |
|
| 679 | - * @param string $inputName the form field or data key name used |
|
| 680 | - * @param string $ruleName the rule name for this validation ("matches") |
|
| 681 | - * @param array $ruleArgs the rules argument |
|
| 682 | - */ |
|
| 683 | - protected function _validateMatches($inputName, $ruleName, array $ruleArgs) { |
|
| 684 | - $inputVal = $this->post($inputName); |
|
| 685 | - if ($inputVal != $this->data[$ruleArgs[1]]) { |
|
| 686 | - $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
|
| 687 | - } |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - /** |
|
| 691 | - * Peform validation for the rule "valid_email" |
|
| 692 | - * @param string $inputName the form field or data key name used |
|
| 693 | - * @param string $ruleName the rule name for this validation ("valid_email") |
|
| 694 | - * @param array $ruleArgs the rules argument |
|
| 695 | - */ |
|
| 696 | - protected function _validateValidEmail($inputName, $ruleName, array $ruleArgs) { |
|
| 697 | - $inputVal = $this->post($inputName); |
|
| 698 | - if (! preg_match("/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i", $inputVal)) { |
|
| 699 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 700 | - return; |
|
| 701 | - } |
|
| 702 | - $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
|
| 703 | - } |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - /** |
|
| 707 | - * Peform validation for the rule "exact_length" |
|
| 708 | - * @param string $inputName the form field or data key name used |
|
| 709 | - * @param string $ruleName the rule name for this validation ("exact_length") |
|
| 710 | - * @param array $ruleArgs the rules argument |
|
| 711 | - */ |
|
| 712 | - protected function _validateExactLength($inputName, $ruleName, array $ruleArgs) { |
|
| 713 | - $inputVal = $this->post($inputName); |
|
| 714 | - if (strlen($inputVal) != $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length |
|
| 715 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 716 | - return; |
|
| 717 | - } |
|
| 718 | - $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
|
| 719 | - } |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - /** |
|
| 723 | - * Peform validation for the rule "max_length" |
|
| 724 | - * @param string $inputName the form field or data key name used |
|
| 725 | - * @param string $ruleName the rule name for this validation ("max_length") |
|
| 726 | - * @param array $ruleArgs the rules argument |
|
| 727 | - */ |
|
| 728 | - protected function _validateMaxLength($inputName, $ruleName, array $ruleArgs) { |
|
| 729 | - $inputVal = $this->post($inputName); |
|
| 730 | - if (strlen($inputVal) > $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length |
|
| 731 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 732 | - return; |
|
| 733 | - } |
|
| 734 | - $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
|
| 735 | - } |
|
| 736 | - } |
|
| 737 | - |
|
| 738 | - /** |
|
| 739 | - * Peform validation for the rule "min_length" |
|
| 740 | - * @param string $inputName the form field or data key name used |
|
| 741 | - * @param string $ruleName the rule name for this validation ("min_length") |
|
| 742 | - * @param array $ruleArgs the rules argument |
|
| 743 | - */ |
|
| 744 | - protected function _validateMinLength($inputName, $ruleName, array $ruleArgs) { |
|
| 745 | - $inputVal = $this->post($inputName); |
|
| 746 | - if (strlen($inputVal) < $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length |
|
| 747 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 748 | - return; |
|
| 749 | - } |
|
| 750 | - $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
|
| 751 | - } |
|
| 752 | - } |
|
| 669 | + if ($inputVal == $doNotEqual) { |
|
| 670 | + $this->_setError($inputName, $ruleName . ',string', array($this->_getLabel($inputName), $doNotEqual)); |
|
| 671 | + continue; |
|
| 672 | + } |
|
| 673 | + } |
|
| 674 | + } |
|
| 675 | + } |
|
| 676 | + |
|
| 677 | + /** |
|
| 678 | + * Peform validation for the rule "matches" |
|
| 679 | + * @param string $inputName the form field or data key name used |
|
| 680 | + * @param string $ruleName the rule name for this validation ("matches") |
|
| 681 | + * @param array $ruleArgs the rules argument |
|
| 682 | + */ |
|
| 683 | + protected function _validateMatches($inputName, $ruleName, array $ruleArgs) { |
|
| 684 | + $inputVal = $this->post($inputName); |
|
| 685 | + if ($inputVal != $this->data[$ruleArgs[1]]) { |
|
| 686 | + $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
|
| 687 | + } |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + /** |
|
| 691 | + * Peform validation for the rule "valid_email" |
|
| 692 | + * @param string $inputName the form field or data key name used |
|
| 693 | + * @param string $ruleName the rule name for this validation ("valid_email") |
|
| 694 | + * @param array $ruleArgs the rules argument |
|
| 695 | + */ |
|
| 696 | + protected function _validateValidEmail($inputName, $ruleName, array $ruleArgs) { |
|
| 697 | + $inputVal = $this->post($inputName); |
|
| 698 | + if (! preg_match("/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i", $inputVal)) { |
|
| 699 | + if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 700 | + return; |
|
| 701 | + } |
|
| 702 | + $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
|
| 703 | + } |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + /** |
|
| 707 | + * Peform validation for the rule "exact_length" |
|
| 708 | + * @param string $inputName the form field or data key name used |
|
| 709 | + * @param string $ruleName the rule name for this validation ("exact_length") |
|
| 710 | + * @param array $ruleArgs the rules argument |
|
| 711 | + */ |
|
| 712 | + protected function _validateExactLength($inputName, $ruleName, array $ruleArgs) { |
|
| 713 | + $inputVal = $this->post($inputName); |
|
| 714 | + if (strlen($inputVal) != $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length |
|
| 715 | + if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 716 | + return; |
|
| 717 | + } |
|
| 718 | + $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
|
| 719 | + } |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + /** |
|
| 723 | + * Peform validation for the rule "max_length" |
|
| 724 | + * @param string $inputName the form field or data key name used |
|
| 725 | + * @param string $ruleName the rule name for this validation ("max_length") |
|
| 726 | + * @param array $ruleArgs the rules argument |
|
| 727 | + */ |
|
| 728 | + protected function _validateMaxLength($inputName, $ruleName, array $ruleArgs) { |
|
| 729 | + $inputVal = $this->post($inputName); |
|
| 730 | + if (strlen($inputVal) > $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length |
|
| 731 | + if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 732 | + return; |
|
| 733 | + } |
|
| 734 | + $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
|
| 735 | + } |
|
| 736 | + } |
|
| 737 | + |
|
| 738 | + /** |
|
| 739 | + * Peform validation for the rule "min_length" |
|
| 740 | + * @param string $inputName the form field or data key name used |
|
| 741 | + * @param string $ruleName the rule name for this validation ("min_length") |
|
| 742 | + * @param array $ruleArgs the rules argument |
|
| 743 | + */ |
|
| 744 | + protected function _validateMinLength($inputName, $ruleName, array $ruleArgs) { |
|
| 745 | + $inputVal = $this->post($inputName); |
|
| 746 | + if (strlen($inputVal) < $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length |
|
| 747 | + if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 748 | + return; |
|
| 749 | + } |
|
| 750 | + $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
|
| 751 | + } |
|
| 752 | + } |
|
| 753 | 753 | |
| 754 | - /** |
|
| 755 | - * Peform validation for the rule "less_than" |
|
| 756 | - * @param string $inputName the form field or data key name used |
|
| 757 | - * @param string $ruleName the rule name for this validation ("less_than") |
|
| 758 | - * @param array $ruleArgs the rules argument |
|
| 759 | - */ |
|
| 760 | - protected function _validateLessThan($inputName, $ruleName, array $ruleArgs) { |
|
| 761 | - $inputVal = $this->post($inputName); |
|
| 762 | - if ($inputVal >= $ruleArgs[1]) { |
|
| 763 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 764 | - return; |
|
| 765 | - } |
|
| 766 | - $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
|
| 767 | - } |
|
| 768 | - } |
|
| 754 | + /** |
|
| 755 | + * Peform validation for the rule "less_than" |
|
| 756 | + * @param string $inputName the form field or data key name used |
|
| 757 | + * @param string $ruleName the rule name for this validation ("less_than") |
|
| 758 | + * @param array $ruleArgs the rules argument |
|
| 759 | + */ |
|
| 760 | + protected function _validateLessThan($inputName, $ruleName, array $ruleArgs) { |
|
| 761 | + $inputVal = $this->post($inputName); |
|
| 762 | + if ($inputVal >= $ruleArgs[1]) { |
|
| 763 | + if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 764 | + return; |
|
| 765 | + } |
|
| 766 | + $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
|
| 767 | + } |
|
| 768 | + } |
|
| 769 | 769 | |
| 770 | - /** |
|
| 771 | - * Peform validation for the rule "greater_than" |
|
| 772 | - * @param string $inputName the form field or data key name used |
|
| 773 | - * @param string $ruleName the rule name for this validation ("greater_than") |
|
| 774 | - * @param array $ruleArgs the rules argument |
|
| 775 | - */ |
|
| 776 | - protected function _validateGreaterThan($inputName, $ruleName, array $ruleArgs) { |
|
| 777 | - $inputVal = $this->post($inputName); |
|
| 778 | - if ($inputVal <= $ruleArgs[1]) { |
|
| 779 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 780 | - return; |
|
| 781 | - } |
|
| 782 | - $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
|
| 783 | - } |
|
| 784 | - } |
|
| 770 | + /** |
|
| 771 | + * Peform validation for the rule "greater_than" |
|
| 772 | + * @param string $inputName the form field or data key name used |
|
| 773 | + * @param string $ruleName the rule name for this validation ("greater_than") |
|
| 774 | + * @param array $ruleArgs the rules argument |
|
| 775 | + */ |
|
| 776 | + protected function _validateGreaterThan($inputName, $ruleName, array $ruleArgs) { |
|
| 777 | + $inputVal = $this->post($inputName); |
|
| 778 | + if ($inputVal <= $ruleArgs[1]) { |
|
| 779 | + if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 780 | + return; |
|
| 781 | + } |
|
| 782 | + $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
|
| 783 | + } |
|
| 784 | + } |
|
| 785 | 785 | |
| 786 | - /** |
|
| 787 | - * Peform validation for the rule "numeric" |
|
| 788 | - * @param string $inputName the form field or data key name used |
|
| 789 | - * @param string $ruleName the rule name for this validation ("numeric") |
|
| 790 | - * @param array $ruleArgs the rules argument |
|
| 791 | - */ |
|
| 792 | - protected function _validateNumeric($inputName, $ruleName, array $ruleArgs) { |
|
| 793 | - $inputVal = $this->post($inputName); |
|
| 794 | - if (! is_numeric($inputVal)) { |
|
| 795 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 796 | - return; |
|
| 797 | - } |
|
| 798 | - $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
|
| 799 | - } |
|
| 800 | - } |
|
| 786 | + /** |
|
| 787 | + * Peform validation for the rule "numeric" |
|
| 788 | + * @param string $inputName the form field or data key name used |
|
| 789 | + * @param string $ruleName the rule name for this validation ("numeric") |
|
| 790 | + * @param array $ruleArgs the rules argument |
|
| 791 | + */ |
|
| 792 | + protected function _validateNumeric($inputName, $ruleName, array $ruleArgs) { |
|
| 793 | + $inputVal = $this->post($inputName); |
|
| 794 | + if (! is_numeric($inputVal)) { |
|
| 795 | + if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 796 | + return; |
|
| 797 | + } |
|
| 798 | + $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
|
| 799 | + } |
|
| 800 | + } |
|
| 801 | 801 | |
| 802 | - /** |
|
| 803 | - * Peform validation for the rule "exists" |
|
| 804 | - * @param string $inputName the form field or data key name used |
|
| 805 | - * @param string $ruleName the rule name for this validation ("exists") |
|
| 806 | - * @param array $ruleArgs the rules argument |
|
| 807 | - */ |
|
| 802 | + /** |
|
| 803 | + * Peform validation for the rule "exists" |
|
| 804 | + * @param string $inputName the form field or data key name used |
|
| 805 | + * @param string $ruleName the rule name for this validation ("exists") |
|
| 806 | + * @param array $ruleArgs the rules argument |
|
| 807 | + */ |
|
| 808 | 808 | protected function _validateExists($inputName, $ruleName, array $ruleArgs) { |
| 809 | - $inputVal = $this->post($inputName); |
|
| 810 | - $obj = & get_instance(); |
|
| 811 | - if(! isset($obj->database)){ |
|
| 812 | - return; |
|
| 813 | - } |
|
| 814 | - list($table, $column) = explode('.', $ruleArgs[1]); |
|
| 815 | - $obj->database->from($table) |
|
| 816 | - ->where($column, $inputVal) |
|
| 817 | - ->get(); |
|
| 818 | - $nb = $obj->database->numRows(); |
|
| 819 | - if ($nb == 0) { |
|
| 820 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 821 | - return; |
|
| 822 | - } |
|
| 823 | - $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
|
| 824 | - } |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - /** |
|
| 828 | - * Peform validation for the rule "is_unique" |
|
| 829 | - * @param string $inputName the form field or data key name used |
|
| 830 | - * @param string $ruleName the rule name for this validation ("is_unique") |
|
| 831 | - * @param array $ruleArgs the rules argument |
|
| 832 | - */ |
|
| 833 | - protected function _validateIsUnique($inputName, $ruleName, array $ruleArgs) { |
|
| 834 | - $inputVal = $this->post($inputName); |
|
| 835 | - $obj = & get_instance(); |
|
| 836 | - if(! isset($obj->database)){ |
|
| 837 | - return; |
|
| 838 | - } |
|
| 839 | - list($table, $column) = explode('.', $ruleArgs[1]); |
|
| 840 | - $obj->database->from($table) |
|
| 841 | - ->where($column, $inputVal) |
|
| 842 | - ->get(); |
|
| 843 | - $nb = $obj->database->numRows(); |
|
| 844 | - if ($nb != 0) { |
|
| 845 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 846 | - return; |
|
| 847 | - } |
|
| 848 | - $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
|
| 849 | - } |
|
| 850 | - } |
|
| 809 | + $inputVal = $this->post($inputName); |
|
| 810 | + $obj = & get_instance(); |
|
| 811 | + if(! isset($obj->database)){ |
|
| 812 | + return; |
|
| 813 | + } |
|
| 814 | + list($table, $column) = explode('.', $ruleArgs[1]); |
|
| 815 | + $obj->database->from($table) |
|
| 816 | + ->where($column, $inputVal) |
|
| 817 | + ->get(); |
|
| 818 | + $nb = $obj->database->numRows(); |
|
| 819 | + if ($nb == 0) { |
|
| 820 | + if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 821 | + return; |
|
| 822 | + } |
|
| 823 | + $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
|
| 824 | + } |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + /** |
|
| 828 | + * Peform validation for the rule "is_unique" |
|
| 829 | + * @param string $inputName the form field or data key name used |
|
| 830 | + * @param string $ruleName the rule name for this validation ("is_unique") |
|
| 831 | + * @param array $ruleArgs the rules argument |
|
| 832 | + */ |
|
| 833 | + protected function _validateIsUnique($inputName, $ruleName, array $ruleArgs) { |
|
| 834 | + $inputVal = $this->post($inputName); |
|
| 835 | + $obj = & get_instance(); |
|
| 836 | + if(! isset($obj->database)){ |
|
| 837 | + return; |
|
| 838 | + } |
|
| 839 | + list($table, $column) = explode('.', $ruleArgs[1]); |
|
| 840 | + $obj->database->from($table) |
|
| 841 | + ->where($column, $inputVal) |
|
| 842 | + ->get(); |
|
| 843 | + $nb = $obj->database->numRows(); |
|
| 844 | + if ($nb != 0) { |
|
| 845 | + if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 846 | + return; |
|
| 847 | + } |
|
| 848 | + $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
|
| 849 | + } |
|
| 850 | + } |
|
| 851 | 851 | |
| 852 | - /** |
|
| 853 | - * Peform validation for the rule "is_unique_update" |
|
| 854 | - * @param string $inputName the form field or data key name used |
|
| 855 | - * @param string $ruleName the rule name for this validation ("is_unique_update") |
|
| 856 | - * @param array $ruleArgs the rules argument |
|
| 857 | - */ |
|
| 858 | - protected function _validateIsUniqueUpdate($inputName, $ruleName, array $ruleArgs) { |
|
| 859 | - $inputVal = $this->post($inputName); |
|
| 860 | - $obj = & get_instance(); |
|
| 861 | - if(! isset($obj->database)){ |
|
| 862 | - return; |
|
| 863 | - } |
|
| 864 | - $data = explode(',', $ruleArgs[1]); |
|
| 865 | - if(count($data) < 2){ |
|
| 866 | - return; |
|
| 867 | - } |
|
| 868 | - list($table, $column) = explode('.', $data[0]); |
|
| 869 | - list($field, $val) = explode('=', $data[1]); |
|
| 870 | - $obj->database->from($table) |
|
| 871 | - ->where($column, $inputVal) |
|
| 872 | - ->where($field, '!=', trim($val)) |
|
| 873 | - ->get(); |
|
| 874 | - $nb = $obj->database->numRows(); |
|
| 875 | - if ($nb != 0) { |
|
| 876 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 877 | - return; |
|
| 878 | - } |
|
| 879 | - $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
|
| 880 | - } |
|
| 881 | - } |
|
| 882 | - |
|
| 883 | - /** |
|
| 884 | - * Peform validation for the rule "in_list" |
|
| 885 | - * @param string $inputName the form field or data key name used |
|
| 886 | - * @param string $ruleName the rule name for this validation ("in_list") |
|
| 887 | - * @param array $ruleArgs the rules argument |
|
| 888 | - */ |
|
| 889 | - protected function _validateInList($inputName, $ruleName, array $ruleArgs) { |
|
| 890 | - $inputVal = $this->post($inputName); |
|
| 891 | - $list = explode(',', $ruleArgs[1]); |
|
| 892 | - $list = array_map('trim', $list); |
|
| 893 | - if (! in_array($inputVal, $list)) { |
|
| 894 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 895 | - return; |
|
| 896 | - } |
|
| 897 | - $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
|
| 898 | - } |
|
| 899 | - } |
|
| 900 | - |
|
| 901 | - /** |
|
| 902 | - * Peform validation for the rule "regex" |
|
| 903 | - * @param string $inputName the form field or data key name used |
|
| 904 | - * @param string $ruleName the rule name for this validation ("regex") |
|
| 905 | - * @param array $ruleArgs the rules argument |
|
| 906 | - */ |
|
| 907 | - protected function _validateRegex($inputName, $ruleName, array $ruleArgs) { |
|
| 908 | - $inputVal = $this->post($inputName); |
|
| 909 | - $regex = $ruleArgs[1]; |
|
| 910 | - if (! preg_match($regex, $inputVal)) { |
|
| 911 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 912 | - return; |
|
| 913 | - } |
|
| 914 | - $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
|
| 915 | - } |
|
| 916 | - } |
|
| 852 | + /** |
|
| 853 | + * Peform validation for the rule "is_unique_update" |
|
| 854 | + * @param string $inputName the form field or data key name used |
|
| 855 | + * @param string $ruleName the rule name for this validation ("is_unique_update") |
|
| 856 | + * @param array $ruleArgs the rules argument |
|
| 857 | + */ |
|
| 858 | + protected function _validateIsUniqueUpdate($inputName, $ruleName, array $ruleArgs) { |
|
| 859 | + $inputVal = $this->post($inputName); |
|
| 860 | + $obj = & get_instance(); |
|
| 861 | + if(! isset($obj->database)){ |
|
| 862 | + return; |
|
| 863 | + } |
|
| 864 | + $data = explode(',', $ruleArgs[1]); |
|
| 865 | + if(count($data) < 2){ |
|
| 866 | + return; |
|
| 867 | + } |
|
| 868 | + list($table, $column) = explode('.', $data[0]); |
|
| 869 | + list($field, $val) = explode('=', $data[1]); |
|
| 870 | + $obj->database->from($table) |
|
| 871 | + ->where($column, $inputVal) |
|
| 872 | + ->where($field, '!=', trim($val)) |
|
| 873 | + ->get(); |
|
| 874 | + $nb = $obj->database->numRows(); |
|
| 875 | + if ($nb != 0) { |
|
| 876 | + if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 877 | + return; |
|
| 878 | + } |
|
| 879 | + $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
|
| 880 | + } |
|
| 881 | + } |
|
| 882 | + |
|
| 883 | + /** |
|
| 884 | + * Peform validation for the rule "in_list" |
|
| 885 | + * @param string $inputName the form field or data key name used |
|
| 886 | + * @param string $ruleName the rule name for this validation ("in_list") |
|
| 887 | + * @param array $ruleArgs the rules argument |
|
| 888 | + */ |
|
| 889 | + protected function _validateInList($inputName, $ruleName, array $ruleArgs) { |
|
| 890 | + $inputVal = $this->post($inputName); |
|
| 891 | + $list = explode(',', $ruleArgs[1]); |
|
| 892 | + $list = array_map('trim', $list); |
|
| 893 | + if (! in_array($inputVal, $list)) { |
|
| 894 | + if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 895 | + return; |
|
| 896 | + } |
|
| 897 | + $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
|
| 898 | + } |
|
| 899 | + } |
|
| 900 | + |
|
| 901 | + /** |
|
| 902 | + * Peform validation for the rule "regex" |
|
| 903 | + * @param string $inputName the form field or data key name used |
|
| 904 | + * @param string $ruleName the rule name for this validation ("regex") |
|
| 905 | + * @param array $ruleArgs the rules argument |
|
| 906 | + */ |
|
| 907 | + protected function _validateRegex($inputName, $ruleName, array $ruleArgs) { |
|
| 908 | + $inputVal = $this->post($inputName); |
|
| 909 | + $regex = $ruleArgs[1]; |
|
| 910 | + if (! preg_match($regex, $inputVal)) { |
|
| 911 | + if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 912 | + return; |
|
| 913 | + } |
|
| 914 | + $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
|
| 915 | + } |
|
| 916 | + } |
|
| 917 | 917 | |
| 918 | - } |
|
| 918 | + } |
|
@@ -25,13 +25,13 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | 27 | |
| 28 | - class FormValidation{ |
|
| 28 | + class FormValidation { |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * The form validation status |
| 32 | 32 | * @var boolean |
| 33 | 33 | */ |
| 34 | - protected $_success = false; |
|
| 34 | + protected $_success = false; |
|
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * The list of errors messages |
@@ -40,31 +40,31 @@ discard block |
||
| 40 | 40 | protected $_errorsMessages = array(); |
| 41 | 41 | |
| 42 | 42 | // Array of rule sets, fieldName => PIPE seperated ruleString |
| 43 | - protected $_rules = array(); |
|
| 43 | + protected $_rules = array(); |
|
| 44 | 44 | |
| 45 | 45 | // Array of errors, niceName => Error Message |
| 46 | - protected $_errors = array(); |
|
| 46 | + protected $_errors = array(); |
|
| 47 | 47 | |
| 48 | 48 | // Array of post Key => Nice name labels |
| 49 | - protected $_labels = array(); |
|
| 49 | + protected $_labels = array(); |
|
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | 52 | * The errors delimiters |
| 53 | 53 | * @var array |
| 54 | 54 | */ |
| 55 | - protected $_allErrorsDelimiter = array('<div class="error">', '</div>'); |
|
| 55 | + protected $_allErrorsDelimiter = array('<div class="error">', '</div>'); |
|
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | 58 | * The each error delimiter |
| 59 | 59 | * @var array |
| 60 | 60 | */ |
| 61 | - protected $_eachErrorDelimiter = array('<p class="error">', '</p>'); |
|
| 61 | + protected $_eachErrorDelimiter = array('<p class="error">', '</p>'); |
|
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * Indicated if need force the validation to be failed |
| 65 | 65 | * @var boolean |
| 66 | 66 | */ |
| 67 | - protected $_forceFail = false; |
|
| 67 | + protected $_forceFail = false; |
|
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | 70 | * The list of the error messages overrides by the original |
@@ -98,13 +98,13 @@ discard block |
||
| 98 | 98 | * @return void |
| 99 | 99 | */ |
| 100 | 100 | public function __construct() { |
| 101 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 101 | + $this->logger = & class_loader('Log', 'classes'); |
|
| 102 | 102 | $this->logger->setLogger('Library::FormValidation'); |
| 103 | 103 | |
| 104 | 104 | //Load form validation language message |
| 105 | 105 | Loader::lang('form_validation'); |
| 106 | 106 | $obj = & get_instance(); |
| 107 | - $this->_errorsMessages = array( |
|
| 107 | + $this->_errorsMessages = array( |
|
| 108 | 108 | 'required' => $obj->lang->get('fv_required'), |
| 109 | 109 | 'min_length' => $obj->lang->get('fv_min_length'), |
| 110 | 110 | 'max_length' => $obj->lang->get('fv_max_length'), |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | $this->_success = false; |
| 142 | 142 | $this->_forceFail = false; |
| 143 | 143 | $this->data = array(); |
| 144 | - $this->enableCsrfCheck = false; |
|
| 144 | + $this->enableCsrfCheck = false; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | /** |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | * |
| 151 | 151 | * @return FormValidation Current instance of object. |
| 152 | 152 | */ |
| 153 | - public function setData(array $data){ |
|
| 153 | + public function setData(array $data) { |
|
| 154 | 154 | $this->logger->debug('Setting the form validation data, the values are: ' . stringfy_vars($data)); |
| 155 | 155 | $this->data = $data; |
| 156 | 156 | return $this; |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | * Get the form validation data |
| 161 | 161 | * @return array the form validation data to be validated |
| 162 | 162 | */ |
| 163 | - public function getData(){ |
|
| 163 | + public function getData() { |
|
| 164 | 164 | return $this->data; |
| 165 | 165 | } |
| 166 | 166 | |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | * |
| 170 | 170 | * @return string the function name |
| 171 | 171 | */ |
| 172 | - protected function _toCallCase($funcName, $prefix='_validate') { |
|
| 172 | + protected function _toCallCase($funcName, $prefix = '_validate') { |
|
| 173 | 173 | $funcName = strtolower($funcName); |
| 174 | 174 | $finalFuncName = $prefix; |
| 175 | 175 | foreach (explode('_', $funcName) as $funcNamePart) { |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | * @return boolean Whether or not the form has been submitted or the data is available for validation. |
| 194 | 194 | */ |
| 195 | 195 | public function canDoValidation() { |
| 196 | - return get_instance()->request->method() === 'POST' || ! empty($this->data); |
|
| 196 | + return get_instance()->request->method() === 'POST' || !empty($this->data); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | /** |
@@ -215,16 +215,16 @@ discard block |
||
| 215 | 215 | * afterwards. |
| 216 | 216 | */ |
| 217 | 217 | protected function _run() { |
| 218 | - if(get_instance()->request->method() == 'POST' || $this->enableCsrfCheck){ |
|
| 218 | + if (get_instance()->request->method() == 'POST' || $this->enableCsrfCheck) { |
|
| 219 | 219 | $this->logger->debug('Check if CSRF is enabled in configuration'); |
| 220 | 220 | //first check for CSRF |
| 221 | - if( get_config('csrf_enable', false) || $this->enableCsrfCheck){ |
|
| 221 | + if (get_config('csrf_enable', false) || $this->enableCsrfCheck) { |
|
| 222 | 222 | $this->logger->info('Check the CSRF value if is valid'); |
| 223 | - if(! Security::validateCSRF()){ |
|
| 223 | + if (!Security::validateCSRF()) { |
|
| 224 | 224 | show_error('Invalide data, Cross Site Request Forgery do his job, the data to validate is corrupted.'); |
| 225 | 225 | } |
| 226 | 226 | } |
| 227 | - else{ |
|
| 227 | + else { |
|
| 228 | 228 | $this->logger->info('CSRF is not enabled in configuration or not set manully, no need to check it'); |
| 229 | 229 | } |
| 230 | 230 | } |
@@ -232,10 +232,10 @@ discard block |
||
| 232 | 232 | $this->_forceFail = false; |
| 233 | 233 | |
| 234 | 234 | foreach ($this->getData() as $inputName => $inputVal) { |
| 235 | - if(is_array($this->data[$inputName])){ |
|
| 235 | + if (is_array($this->data[$inputName])) { |
|
| 236 | 236 | $this->data[$inputName] = array_map('trim', $this->data[$inputName]); |
| 237 | 237 | } |
| 238 | - else{ |
|
| 238 | + else { |
|
| 239 | 239 | $this->data[$inputName] = trim($this->data[$inputName]); |
| 240 | 240 | } |
| 241 | 241 | |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | public function setRule($inputField, $inputLabel, $ruleSets) { |
| 263 | 263 | $this->_rules[$inputField] = $ruleSets; |
| 264 | 264 | $this->_labels[$inputField] = $inputLabel; |
| 265 | - $this->logger->info('Set the field rule: name [' .$inputField. '], label [' .$inputLabel. '], rules [' .$ruleSets. ']'); |
|
| 265 | + $this->logger->info('Set the field rule: name [' . $inputField . '], label [' . $inputLabel . '], rules [' . $ruleSets . ']'); |
|
| 266 | 266 | return $this; |
| 267 | 267 | } |
| 268 | 268 | |
@@ -427,7 +427,7 @@ discard block |
||
| 427 | 427 | } |
| 428 | 428 | $errorOutput .= $errorsEnd; |
| 429 | 429 | echo ($echo) ? $errorOutput : ''; |
| 430 | - return (! $echo) ? $errorOutput : null; |
|
| 430 | + return (!$echo) ? $errorOutput : null; |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | /** |
@@ -452,26 +452,26 @@ discard block |
||
| 452 | 452 | /* |
| 453 | 453 | //////////////// hack for regex rule that can contain "|" |
| 454 | 454 | */ |
| 455 | - if(strpos($ruleString, 'regex') !== false){ |
|
| 455 | + if (strpos($ruleString, 'regex') !== false) { |
|
| 456 | 456 | $regexRule = array(); |
| 457 | 457 | $rule = '#regex\[\/(.*)\/([a-zA-Z0-9]?)\]#'; |
| 458 | 458 | preg_match($rule, $ruleString, $regexRule); |
| 459 | 459 | $ruleStringTemp = preg_replace($rule, '', $ruleString); |
| 460 | - if(isset($regexRule[0]) && !empty($regexRule[0])){ |
|
| 460 | + if (isset($regexRule[0]) && !empty($regexRule[0])) { |
|
| 461 | 461 | $ruleSets[] = $regexRule[0]; |
| 462 | 462 | } |
| 463 | 463 | $ruleStringRegex = explode('|', $ruleStringTemp); |
| 464 | - if(is_array($ruleStringRegex)){ |
|
| 464 | + if (is_array($ruleStringRegex)) { |
|
| 465 | 465 | foreach ($ruleStringRegex as $rule) { |
| 466 | 466 | $rule = trim($rule); |
| 467 | - if($rule){ |
|
| 467 | + if ($rule) { |
|
| 468 | 468 | $ruleSets[] = $rule; |
| 469 | 469 | } |
| 470 | 470 | } |
| 471 | 471 | } |
| 472 | 472 | } |
| 473 | 473 | /***********************************/ |
| 474 | - else{ |
|
| 474 | + else { |
|
| 475 | 475 | if (strpos($ruleString, '|') !== FALSE) { |
| 476 | 476 | $ruleSets = explode('|', $ruleString); |
| 477 | 477 | } else { |
@@ -503,7 +503,7 @@ discard block |
||
| 503 | 503 | * @return void |
| 504 | 504 | */ |
| 505 | 505 | protected function _validateRule($inputName, $inputVal, $ruleName) { |
| 506 | - $this->logger->debug('Rule validation of field [' .$inputName. '], value [' .$inputVal. '], rule [' .$ruleName. ']'); |
|
| 506 | + $this->logger->debug('Rule validation of field [' . $inputName . '], value [' . $inputVal . '], rule [' . $ruleName . ']'); |
|
| 507 | 507 | // Array to store args |
| 508 | 508 | $ruleArgs = array(); |
| 509 | 509 | |
@@ -547,7 +547,7 @@ discard block |
||
| 547 | 547 | $key = $i - 1; |
| 548 | 548 | $rulePhrase = str_replace('%' . $i, $replacements[$key], $rulePhrase); |
| 549 | 549 | } |
| 550 | - if (! array_key_exists($inputName, $this->_errors)) { |
|
| 550 | + if (!array_key_exists($inputName, $this->_errors)) { |
|
| 551 | 551 | $this->_errors[$inputName] = $rulePhrase; |
| 552 | 552 | } |
| 553 | 553 | } |
@@ -599,13 +599,13 @@ discard block |
||
| 599 | 599 | */ |
| 600 | 600 | protected function _validateRequired($inputName, $ruleName, array $ruleArgs) { |
| 601 | 601 | $inputVal = $this->post($inputName); |
| 602 | - if(array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) { |
|
| 602 | + if (array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) { |
|
| 603 | 603 | $callbackReturn = $this->_runEmptyCallback($ruleArgs[1]); |
| 604 | 604 | if ($inputVal == '' && $callbackReturn == true) { |
| 605 | 605 | $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
| 606 | 606 | } |
| 607 | 607 | } |
| 608 | - else if($inputVal == '') { |
|
| 608 | + else if ($inputVal == '') { |
|
| 609 | 609 | $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
| 610 | 610 | } |
| 611 | 611 | } |
@@ -631,7 +631,7 @@ discard block |
||
| 631 | 631 | protected function _validateCallback($inputName, $ruleName, array $ruleArgs) { |
| 632 | 632 | if (function_exists($ruleArgs[1]) && !empty($this->data[$inputName])) { |
| 633 | 633 | $result = $this->_runCallback($this->data[$inputName], $ruleArgs[1]); |
| 634 | - if(! $result){ |
|
| 634 | + if (!$result) { |
|
| 635 | 635 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
| 636 | 636 | } |
| 637 | 637 | } |
@@ -665,7 +665,7 @@ discard block |
||
| 665 | 665 | continue; |
| 666 | 666 | } |
| 667 | 667 | } |
| 668 | - else{ |
|
| 668 | + else { |
|
| 669 | 669 | if ($inputVal == $doNotEqual) { |
| 670 | 670 | $this->_setError($inputName, $ruleName . ',string', array($this->_getLabel($inputName), $doNotEqual)); |
| 671 | 671 | continue; |
@@ -695,8 +695,8 @@ discard block |
||
| 695 | 695 | */ |
| 696 | 696 | protected function _validateValidEmail($inputName, $ruleName, array $ruleArgs) { |
| 697 | 697 | $inputVal = $this->post($inputName); |
| 698 | - if (! preg_match("/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i", $inputVal)) { |
|
| 699 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 698 | + if (!preg_match("/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i", $inputVal)) { |
|
| 699 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 700 | 700 | return; |
| 701 | 701 | } |
| 702 | 702 | $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
@@ -712,7 +712,7 @@ discard block |
||
| 712 | 712 | protected function _validateExactLength($inputName, $ruleName, array $ruleArgs) { |
| 713 | 713 | $inputVal = $this->post($inputName); |
| 714 | 714 | if (strlen($inputVal) != $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length |
| 715 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 715 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 716 | 716 | return; |
| 717 | 717 | } |
| 718 | 718 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -728,7 +728,7 @@ discard block |
||
| 728 | 728 | protected function _validateMaxLength($inputName, $ruleName, array $ruleArgs) { |
| 729 | 729 | $inputVal = $this->post($inputName); |
| 730 | 730 | if (strlen($inputVal) > $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length |
| 731 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 731 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 732 | 732 | return; |
| 733 | 733 | } |
| 734 | 734 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -744,7 +744,7 @@ discard block |
||
| 744 | 744 | protected function _validateMinLength($inputName, $ruleName, array $ruleArgs) { |
| 745 | 745 | $inputVal = $this->post($inputName); |
| 746 | 746 | if (strlen($inputVal) < $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length |
| 747 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 747 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 748 | 748 | return; |
| 749 | 749 | } |
| 750 | 750 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -760,7 +760,7 @@ discard block |
||
| 760 | 760 | protected function _validateLessThan($inputName, $ruleName, array $ruleArgs) { |
| 761 | 761 | $inputVal = $this->post($inputName); |
| 762 | 762 | if ($inputVal >= $ruleArgs[1]) { |
| 763 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 763 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 764 | 764 | return; |
| 765 | 765 | } |
| 766 | 766 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -776,7 +776,7 @@ discard block |
||
| 776 | 776 | protected function _validateGreaterThan($inputName, $ruleName, array $ruleArgs) { |
| 777 | 777 | $inputVal = $this->post($inputName); |
| 778 | 778 | if ($inputVal <= $ruleArgs[1]) { |
| 779 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 779 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 780 | 780 | return; |
| 781 | 781 | } |
| 782 | 782 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -791,8 +791,8 @@ discard block |
||
| 791 | 791 | */ |
| 792 | 792 | protected function _validateNumeric($inputName, $ruleName, array $ruleArgs) { |
| 793 | 793 | $inputVal = $this->post($inputName); |
| 794 | - if (! is_numeric($inputVal)) { |
|
| 795 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 794 | + if (!is_numeric($inputVal)) { |
|
| 795 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 796 | 796 | return; |
| 797 | 797 | } |
| 798 | 798 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
@@ -808,7 +808,7 @@ discard block |
||
| 808 | 808 | protected function _validateExists($inputName, $ruleName, array $ruleArgs) { |
| 809 | 809 | $inputVal = $this->post($inputName); |
| 810 | 810 | $obj = & get_instance(); |
| 811 | - if(! isset($obj->database)){ |
|
| 811 | + if (!isset($obj->database)) { |
|
| 812 | 812 | return; |
| 813 | 813 | } |
| 814 | 814 | list($table, $column) = explode('.', $ruleArgs[1]); |
@@ -817,7 +817,7 @@ discard block |
||
| 817 | 817 | ->get(); |
| 818 | 818 | $nb = $obj->database->numRows(); |
| 819 | 819 | if ($nb == 0) { |
| 820 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 820 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 821 | 821 | return; |
| 822 | 822 | } |
| 823 | 823 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
@@ -833,7 +833,7 @@ discard block |
||
| 833 | 833 | protected function _validateIsUnique($inputName, $ruleName, array $ruleArgs) { |
| 834 | 834 | $inputVal = $this->post($inputName); |
| 835 | 835 | $obj = & get_instance(); |
| 836 | - if(! isset($obj->database)){ |
|
| 836 | + if (!isset($obj->database)) { |
|
| 837 | 837 | return; |
| 838 | 838 | } |
| 839 | 839 | list($table, $column) = explode('.', $ruleArgs[1]); |
@@ -842,7 +842,7 @@ discard block |
||
| 842 | 842 | ->get(); |
| 843 | 843 | $nb = $obj->database->numRows(); |
| 844 | 844 | if ($nb != 0) { |
| 845 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 845 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 846 | 846 | return; |
| 847 | 847 | } |
| 848 | 848 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
@@ -858,11 +858,11 @@ discard block |
||
| 858 | 858 | protected function _validateIsUniqueUpdate($inputName, $ruleName, array $ruleArgs) { |
| 859 | 859 | $inputVal = $this->post($inputName); |
| 860 | 860 | $obj = & get_instance(); |
| 861 | - if(! isset($obj->database)){ |
|
| 861 | + if (!isset($obj->database)) { |
|
| 862 | 862 | return; |
| 863 | 863 | } |
| 864 | 864 | $data = explode(',', $ruleArgs[1]); |
| 865 | - if(count($data) < 2){ |
|
| 865 | + if (count($data) < 2) { |
|
| 866 | 866 | return; |
| 867 | 867 | } |
| 868 | 868 | list($table, $column) = explode('.', $data[0]); |
@@ -873,7 +873,7 @@ discard block |
||
| 873 | 873 | ->get(); |
| 874 | 874 | $nb = $obj->database->numRows(); |
| 875 | 875 | if ($nb != 0) { |
| 876 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 876 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 877 | 877 | return; |
| 878 | 878 | } |
| 879 | 879 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
@@ -890,8 +890,8 @@ discard block |
||
| 890 | 890 | $inputVal = $this->post($inputName); |
| 891 | 891 | $list = explode(',', $ruleArgs[1]); |
| 892 | 892 | $list = array_map('trim', $list); |
| 893 | - if (! in_array($inputVal, $list)) { |
|
| 894 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 893 | + if (!in_array($inputVal, $list)) { |
|
| 894 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 895 | 895 | return; |
| 896 | 896 | } |
| 897 | 897 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -907,8 +907,8 @@ discard block |
||
| 907 | 907 | protected function _validateRegex($inputName, $ruleName, array $ruleArgs) { |
| 908 | 908 | $inputVal = $this->post($inputName); |
| 909 | 909 | $regex = $ruleArgs[1]; |
| 910 | - if (! preg_match($regex, $inputVal)) { |
|
| 911 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 910 | + if (!preg_match($regex, $inputVal)) { |
|
| 911 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 912 | 912 | return; |
| 913 | 913 | } |
| 914 | 914 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
@@ -223,8 +223,7 @@ discard block |
||
| 223 | 223 | if(! Security::validateCSRF()){ |
| 224 | 224 | show_error('Invalide data, Cross Site Request Forgery do his job, the data to validate is corrupted.'); |
| 225 | 225 | } |
| 226 | - } |
|
| 227 | - else{ |
|
| 226 | + } else{ |
|
| 228 | 227 | $this->logger->info('CSRF is not enabled in configuration or not set manully, no need to check it'); |
| 229 | 228 | } |
| 230 | 229 | } |
@@ -234,8 +233,7 @@ discard block |
||
| 234 | 233 | foreach ($this->getData() as $inputName => $inputVal) { |
| 235 | 234 | if(is_array($this->data[$inputName])){ |
| 236 | 235 | $this->data[$inputName] = array_map('trim', $this->data[$inputName]); |
| 237 | - } |
|
| 238 | - else{ |
|
| 236 | + } else{ |
|
| 239 | 237 | $this->data[$inputName] = trim($this->data[$inputName]); |
| 240 | 238 | } |
| 241 | 239 | |
@@ -604,8 +602,7 @@ discard block |
||
| 604 | 602 | if ($inputVal == '' && $callbackReturn == true) { |
| 605 | 603 | $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
| 606 | 604 | } |
| 607 | - } |
|
| 608 | - else if($inputVal == '') { |
|
| 605 | + } else if($inputVal == '') { |
|
| 609 | 606 | $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
| 610 | 607 | } |
| 611 | 608 | } |
@@ -664,8 +661,7 @@ discard block |
||
| 664 | 661 | $this->_setError($inputName, $ruleName . ',post:key', array($this->_getLabel($inputName), $this->_getLabel(str_replace('post:', '', $doNotEqual)))); |
| 665 | 662 | continue; |
| 666 | 663 | } |
| 667 | - } |
|
| 668 | - else{ |
|
| 664 | + } else{ |
|
| 669 | 665 | if ($inputVal == $doNotEqual) { |
| 670 | 666 | $this->_setError($inputName, $ruleName . ',string', array($this->_getLabel($inputName), $doNotEqual)); |
| 671 | 667 | continue; |
@@ -22,7 +22,7 @@ |
||
| 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 StringHash{ |
| 28 | 28 | |
@@ -24,7 +24,7 @@ |
||
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | - class StringHash{ |
|
| 27 | + class StringHash { |
|
| 28 | 28 | |
| 29 | 29 | //blowfish |
| 30 | 30 | private static $algo = '$2a'; |
@@ -22,7 +22,7 @@ |
||
| 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 Html{ |
| 28 | 28 | |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | - class Html{ |
|
| 27 | + class Html { |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * Generate the html anchor link |
@@ -35,21 +35,21 @@ discard block |
||
| 35 | 35 | * |
| 36 | 36 | * @return string|void the anchor link generated html if $return is true or display it if not |
| 37 | 37 | */ |
| 38 | - public static function a($link = '', $anchor = null, array $attributes = array(), $return = true){ |
|
| 39 | - if(! is_url($link)){ |
|
| 38 | + public static function a($link = '', $anchor = null, array $attributes = array(), $return = true) { |
|
| 39 | + if (!is_url($link)) { |
|
| 40 | 40 | $link = Url::site_url($link); |
| 41 | 41 | } |
| 42 | - if(! $anchor){ |
|
| 42 | + if (!$anchor) { |
|
| 43 | 43 | $anchor = $link; |
| 44 | 44 | } |
| 45 | 45 | $str = null; |
| 46 | - $str .= '<a href = "'.$link.'"'; |
|
| 46 | + $str .= '<a href = "' . $link . '"'; |
|
| 47 | 47 | $str .= attributes_to_string($attributes); |
| 48 | 48 | $str .= '>'; |
| 49 | 49 | $str .= $anchor; |
| 50 | 50 | $str .= '</a>'; |
| 51 | 51 | |
| 52 | - if($return){ |
|
| 52 | + if ($return) { |
|
| 53 | 53 | return $str; |
| 54 | 54 | } |
| 55 | 55 | echo $str; |
@@ -64,18 +64,18 @@ discard block |
||
| 64 | 64 | * |
| 65 | 65 | * @return string|void the generated html for mailto link if $return is true or display it if not |
| 66 | 66 | */ |
| 67 | - public static function mailto($link, $anchor = null, array $attributes = array(), $return = true){ |
|
| 68 | - if(! $anchor){ |
|
| 67 | + public static function mailto($link, $anchor = null, array $attributes = array(), $return = true) { |
|
| 68 | + if (!$anchor) { |
|
| 69 | 69 | $anchor = $link; |
| 70 | 70 | } |
| 71 | 71 | $str = null; |
| 72 | - $str .= '<a href = "mailto:'.$link.'"'; |
|
| 72 | + $str .= '<a href = "mailto:' . $link . '"'; |
|
| 73 | 73 | $str .= attributes_to_string($attributes); |
| 74 | 74 | $str .= '>'; |
| 75 | 75 | $str .= $anchor; |
| 76 | 76 | $str .= '</a>'; |
| 77 | 77 | |
| 78 | - if($return){ |
|
| 78 | + if ($return) { |
|
| 79 | 79 | return $str; |
| 80 | 80 | } |
| 81 | 81 | echo $str; |
@@ -88,8 +88,8 @@ discard block |
||
| 88 | 88 | * |
| 89 | 89 | * @return string|void the generated "br" html if $return is true or display it if not |
| 90 | 90 | */ |
| 91 | - public static function br($nb = 1, $return = true){ |
|
| 92 | - if(! is_numeric($nb) || $nb <= 0){ |
|
| 91 | + public static function br($nb = 1, $return = true) { |
|
| 92 | + if (!is_numeric($nb) || $nb <= 0) { |
|
| 93 | 93 | $nb = 1; |
| 94 | 94 | } |
| 95 | 95 | $str = null; |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | $str .= '<br />'; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - if($return){ |
|
| 100 | + if ($return) { |
|
| 101 | 101 | return $str; |
| 102 | 102 | } |
| 103 | 103 | echo $str; |
@@ -111,15 +111,15 @@ discard block |
||
| 111 | 111 | * |
| 112 | 112 | * @return string|void the generated "hr" html if $return is true or display it if not. |
| 113 | 113 | */ |
| 114 | - public static function hr($nb = 1, array $attributes = array(), $return = true){ |
|
| 115 | - if(! is_numeric($nb) || $nb <= 0){ |
|
| 114 | + public static function hr($nb = 1, array $attributes = array(), $return = true) { |
|
| 115 | + if (!is_numeric($nb) || $nb <= 0) { |
|
| 116 | 116 | $nb = 1; |
| 117 | 117 | } |
| 118 | 118 | $str = null; |
| 119 | 119 | for ($i = 1; $i <= $nb; $i++) { |
| 120 | - $str .= '<hr' .attributes_to_string($attributes). ' />'; |
|
| 120 | + $str .= '<hr' . attributes_to_string($attributes) . ' />'; |
|
| 121 | 121 | } |
| 122 | - if($return){ |
|
| 122 | + if ($return) { |
|
| 123 | 123 | return $str; |
| 124 | 124 | } |
| 125 | 125 | echo $str; |
@@ -135,18 +135,18 @@ discard block |
||
| 135 | 135 | * |
| 136 | 136 | * @return string|void the generated header html if $return is true or display it if not. |
| 137 | 137 | */ |
| 138 | - public static function head($type = 1, $text = null, $nb = 1, array $attributes = array(), $return = true){ |
|
| 139 | - if(! is_numeric($nb) || $nb <= 0){ |
|
| 138 | + public static function head($type = 1, $text = null, $nb = 1, array $attributes = array(), $return = true) { |
|
| 139 | + if (!is_numeric($nb) || $nb <= 0) { |
|
| 140 | 140 | $nb = 1; |
| 141 | 141 | } |
| 142 | - if(! is_numeric($type) || $type <= 0 || $type > 6){ |
|
| 142 | + if (!is_numeric($type) || $type <= 0 || $type > 6) { |
|
| 143 | 143 | $type = 1; |
| 144 | 144 | } |
| 145 | 145 | $str = null; |
| 146 | 146 | for ($i = 1; $i <= $nb; $i++) { |
| 147 | - $str .= '<h' . $type . attributes_to_string($attributes). '>' .$text. '</h' . $type . '>'; |
|
| 147 | + $str .= '<h' . $type . attributes_to_string($attributes) . '>' . $text . '</h' . $type . '>'; |
|
| 148 | 148 | } |
| 149 | - if($return){ |
|
| 149 | + if ($return) { |
|
| 150 | 150 | return $str; |
| 151 | 151 | } |
| 152 | 152 | echo $str; |
@@ -161,15 +161,15 @@ discard block |
||
| 161 | 161 | * |
| 162 | 162 | * @return string|void the generated "ul" html if $return is true or display it if not. |
| 163 | 163 | */ |
| 164 | - public static function ul($data = array(), $attributes = array(), $return = true){ |
|
| 164 | + public static function ul($data = array(), $attributes = array(), $return = true) { |
|
| 165 | 165 | $data = (array) $data; |
| 166 | 166 | $str = null; |
| 167 | - $str .= '<ul' . (! empty($attributes['ul']) ? attributes_to_string($attributes['ul']):'') . '>'; |
|
| 167 | + $str .= '<ul' . (!empty($attributes['ul']) ? attributes_to_string($attributes['ul']) : '') . '>'; |
|
| 168 | 168 | foreach ($data as $row) { |
| 169 | - $str .= '<li' . (! empty($attributes['li']) ? attributes_to_string($attributes['li']):'') .'>' .$row. '</li>'; |
|
| 169 | + $str .= '<li' . (!empty($attributes['li']) ? attributes_to_string($attributes['li']) : '') . '>' . $row . '</li>'; |
|
| 170 | 170 | } |
| 171 | 171 | $str .= '</ul>'; |
| 172 | - if($return){ |
|
| 172 | + if ($return) { |
|
| 173 | 173 | return $str; |
| 174 | 174 | } |
| 175 | 175 | echo $str; |
@@ -183,15 +183,15 @@ discard block |
||
| 183 | 183 | * @param boolean $return whether need return the generated html or just display it directly |
| 184 | 184 | * @return string|void the generated "ol" html if $return is true or display it if not. |
| 185 | 185 | */ |
| 186 | - public static function ol($data = array(), $attributes = array(), $return = true){ |
|
| 186 | + public static function ol($data = array(), $attributes = array(), $return = true) { |
|
| 187 | 187 | $data = (array) $data; |
| 188 | 188 | $str = null; |
| 189 | - $str .= '<ol' . (!empty($attributes['ol']) ? attributes_to_string($attributes['ol']):'') . '>'; |
|
| 189 | + $str .= '<ol' . (!empty($attributes['ol']) ? attributes_to_string($attributes['ol']) : '') . '>'; |
|
| 190 | 190 | foreach ($data as $row) { |
| 191 | - $str .= '<li' . (!empty($attributes['li']) ? attributes_to_string($attributes['li']):'') .'>' .$row. '</li>'; |
|
| 191 | + $str .= '<li' . (!empty($attributes['li']) ? attributes_to_string($attributes['li']) : '') . '>' . $row . '</li>'; |
|
| 192 | 192 | } |
| 193 | 193 | $str .= '</ol>'; |
| 194 | - if($return){ |
|
| 194 | + if ($return) { |
|
| 195 | 195 | return $str; |
| 196 | 196 | } |
| 197 | 197 | echo $str; |
@@ -209,46 +209,46 @@ discard block |
||
| 209 | 209 | * @param boolean $return whether need return the generated html or just display it directly |
| 210 | 210 | * @return string|void the generated "table" html if $return is true or display it if not. |
| 211 | 211 | */ |
| 212 | - public static function table($headers = array(), $body = array(), $attributes = array(), $use_footer = false, $return = true){ |
|
| 212 | + public static function table($headers = array(), $body = array(), $attributes = array(), $use_footer = false, $return = true) { |
|
| 213 | 213 | $headers = (array) $headers; |
| 214 | 214 | $body = (array) $body; |
| 215 | 215 | $str = null; |
| 216 | - $str .= '<table' . (! empty($attributes['table']) ? attributes_to_string($attributes['table']):'') . '>'; |
|
| 217 | - if(! empty($headers)){ |
|
| 218 | - $str .= '<thead' . (! empty($attributes['thead']) ? attributes_to_string($attributes['thead']):'') .'>'; |
|
| 219 | - $str .= '<tr' . (! empty($attributes['thead_tr']) ? attributes_to_string($attributes['thead_tr']):'') .'>'; |
|
| 216 | + $str .= '<table' . (!empty($attributes['table']) ? attributes_to_string($attributes['table']) : '') . '>'; |
|
| 217 | + if (!empty($headers)) { |
|
| 218 | + $str .= '<thead' . (!empty($attributes['thead']) ? attributes_to_string($attributes['thead']) : '') . '>'; |
|
| 219 | + $str .= '<tr' . (!empty($attributes['thead_tr']) ? attributes_to_string($attributes['thead_tr']) : '') . '>'; |
|
| 220 | 220 | foreach ($headers as $value) { |
| 221 | - $str .= '<th' . (! empty($attributes['thead_th']) ? attributes_to_string($attributes['thead_th']):'') .'>' .$value. '</th>'; |
|
| 221 | + $str .= '<th' . (!empty($attributes['thead_th']) ? attributes_to_string($attributes['thead_th']) : '') . '>' . $value . '</th>'; |
|
| 222 | 222 | } |
| 223 | 223 | $str .= '</tr>'; |
| 224 | 224 | $str .= '</thead>'; |
| 225 | 225 | } |
| 226 | - else{ |
|
| 226 | + else { |
|
| 227 | 227 | //no need check for footer |
| 228 | 228 | $use_footer = false; |
| 229 | 229 | } |
| 230 | - $str .= '<tbody' . (! empty($attributes['tbody']) ? attributes_to_string($attributes['tbody']):'') .'>'; |
|
| 230 | + $str .= '<tbody' . (!empty($attributes['tbody']) ? attributes_to_string($attributes['tbody']) : '') . '>'; |
|
| 231 | 231 | foreach ($body as $row) { |
| 232 | - if(is_array($row)){ |
|
| 233 | - $str .= '<tr' . (! empty($attributes['tbody_tr']) ? attributes_to_string($attributes['tbody_tr']):'') .'>'; |
|
| 232 | + if (is_array($row)) { |
|
| 233 | + $str .= '<tr' . (!empty($attributes['tbody_tr']) ? attributes_to_string($attributes['tbody_tr']) : '') . '>'; |
|
| 234 | 234 | foreach ($row as $value) { |
| 235 | - $str .= '<td' . (! empty($attributes['tbody_td']) ? attributes_to_string($attributes['tbody_td']):'') .'>' .$value. '</td>'; |
|
| 235 | + $str .= '<td' . (!empty($attributes['tbody_td']) ? attributes_to_string($attributes['tbody_td']) : '') . '>' . $value . '</td>'; |
|
| 236 | 236 | } |
| 237 | 237 | $str .= '</tr>'; |
| 238 | 238 | } |
| 239 | 239 | } |
| 240 | 240 | $str .= '</tbody>'; |
| 241 | - if($use_footer){ |
|
| 242 | - $str .= '<tfoot' . (! empty($attributes['tfoot']) ? attributes_to_string($attributes['tfoot']):'') .'>'; |
|
| 243 | - $str .= '<tr' . (! empty($attributes['tfoot_tr']) ? attributes_to_string($attributes['tfoot_tr']):'') .'>'; |
|
| 241 | + if ($use_footer) { |
|
| 242 | + $str .= '<tfoot' . (!empty($attributes['tfoot']) ? attributes_to_string($attributes['tfoot']) : '') . '>'; |
|
| 243 | + $str .= '<tr' . (!empty($attributes['tfoot_tr']) ? attributes_to_string($attributes['tfoot_tr']) : '') . '>'; |
|
| 244 | 244 | foreach ($headers as $value) { |
| 245 | - $str .= '<th' . (! empty($attributes['tfoot_th']) ? attributes_to_string($attributes['tfoot_th']):'') .'>' .$value. '</th>'; |
|
| 245 | + $str .= '<th' . (!empty($attributes['tfoot_th']) ? attributes_to_string($attributes['tfoot_th']) : '') . '>' . $value . '</th>'; |
|
| 246 | 246 | } |
| 247 | 247 | $str .= '</tr>'; |
| 248 | 248 | $str .= '</tfoot>'; |
| 249 | 249 | } |
| 250 | 250 | $str .= '</table>'; |
| 251 | - if($return){ |
|
| 251 | + if ($return) { |
|
| 252 | 252 | return $str; |
| 253 | 253 | } |
| 254 | 254 | echo $str; |
@@ -222,8 +222,7 @@ |
||
| 222 | 222 | } |
| 223 | 223 | $str .= '</tr>'; |
| 224 | 224 | $str .= '</thead>'; |
| 225 | - } |
|
| 226 | - else{ |
|
| 225 | + } else{ |
|
| 227 | 226 | //no need check for footer |
| 228 | 227 | $use_footer = false; |
| 229 | 228 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 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,26 +22,26 @@ discard block |
||
| 22 | 22 | * You should have received a copy of the GNU General Public License |
| 23 | 23 | * along with this program; if not, write to the Free Software |
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | - */ |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | - 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); |
@@ -50,125 +50,125 @@ discard block |
||
| 50 | 50 | Config::setAll($config); |
| 51 | 51 | unset($config); |
| 52 | 52 | } |
| 53 | - } |
|
| 54 | - else{ |
|
| 55 | - show_error('Unable to find the pagination configuration file'); |
|
| 56 | - } |
|
| 57 | - } |
|
| 53 | + } |
|
| 54 | + else{ |
|
| 55 | + show_error('Unable to find the pagination configuration file'); |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Set the pagination custom configuration to overwrite the default configuration in |
|
| 62 | - * config_pagination.php |
|
| 63 | - * @param array $config the configuration to set |
|
| 64 | - */ |
|
| 65 | - public function setConfig(array $config = array()){ |
|
| 66 | - if(! empty($config)){ |
|
| 67 | - $this->config = array_merge($this->config, $config); |
|
| 68 | - Config::setAll($config); |
|
| 69 | - } |
|
| 70 | - } |
|
| 60 | + /** |
|
| 61 | + * Set the pagination custom configuration to overwrite the default configuration in |
|
| 62 | + * config_pagination.php |
|
| 63 | + * @param array $config the configuration to set |
|
| 64 | + */ |
|
| 65 | + public function setConfig(array $config = array()){ |
|
| 66 | + if(! empty($config)){ |
|
| 67 | + $this->config = array_merge($this->config, $config); |
|
| 68 | + Config::setAll($config); |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Generate the pagination link |
|
| 74 | - * @param int $totalRows the total number of data |
|
| 75 | - * @param int $currentPageNumber the current page number |
|
| 76 | - * @return string the pagination link |
|
| 77 | - */ |
|
| 78 | - public function getLink($totalRows, $currentPageNumber){ |
|
| 79 | - $pageQueryName = $this->config['page_query_string_name']; |
|
| 80 | - $numberOfLink = $this->config['nb_link']; |
|
| 72 | + /** |
|
| 73 | + * Generate the pagination link |
|
| 74 | + * @param int $totalRows the total number of data |
|
| 75 | + * @param int $currentPageNumber the current page number |
|
| 76 | + * @return string the pagination link |
|
| 77 | + */ |
|
| 78 | + public function getLink($totalRows, $currentPageNumber){ |
|
| 79 | + $pageQueryName = $this->config['page_query_string_name']; |
|
| 80 | + $numberOfLink = $this->config['nb_link']; |
|
| 81 | 81 | $numberOfRowPerPage = $this->config['pagination_per_page']; |
| 82 | - $queryString = Url::queryString(); |
|
| 83 | - $currentUrl = Url::current(); |
|
| 84 | - if($queryString == ''){ |
|
| 85 | - $query = '?' . $pageQueryName . '='; |
|
| 86 | - } |
|
| 87 | - else{ |
|
| 88 | - $tab = explode($pageQueryName . '=', $queryString); |
|
| 89 | - $nb = count($tab); |
|
| 90 | - if($nb == 1){ |
|
| 91 | - $query = '?' . $queryString . '&' . $pageQueryName . '='; |
|
| 92 | - } |
|
| 93 | - else{ |
|
| 94 | - if($tab[0] == ''){ |
|
| 95 | - $query = '?' . $pageQueryName . '='; |
|
| 96 | - } |
|
| 97 | - else{ |
|
| 98 | - $query = '?' . $tab[0] . '' . $pageQueryName . '='; |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - $temp = explode('?', $currentUrl); |
|
| 103 | - $query = $temp[0] . $query; |
|
| 104 | - $navbar = ''; |
|
| 105 | - $numberOfPage = ceil($totalRows / $numberOfRowPerPage); |
|
| 82 | + $queryString = Url::queryString(); |
|
| 83 | + $currentUrl = Url::current(); |
|
| 84 | + if($queryString == ''){ |
|
| 85 | + $query = '?' . $pageQueryName . '='; |
|
| 86 | + } |
|
| 87 | + else{ |
|
| 88 | + $tab = explode($pageQueryName . '=', $queryString); |
|
| 89 | + $nb = count($tab); |
|
| 90 | + if($nb == 1){ |
|
| 91 | + $query = '?' . $queryString . '&' . $pageQueryName . '='; |
|
| 92 | + } |
|
| 93 | + else{ |
|
| 94 | + if($tab[0] == ''){ |
|
| 95 | + $query = '?' . $pageQueryName . '='; |
|
| 96 | + } |
|
| 97 | + else{ |
|
| 98 | + $query = '?' . $tab[0] . '' . $pageQueryName . '='; |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + $temp = explode('?', $currentUrl); |
|
| 103 | + $query = $temp[0] . $query; |
|
| 104 | + $navbar = ''; |
|
| 105 | + $numberOfPage = ceil($totalRows / $numberOfRowPerPage); |
|
| 106 | 106 | if(! is_numeric ($currentPageNumber) || $currentPageNumber <= 0){ |
| 107 | 107 | $currentPageNumber = 1; |
| 108 | 108 | } |
| 109 | - if($numberOfPage <= 1 || $numberOfLink <= 0 || $numberOfRowPerPage <= 0 || !is_numeric($numberOfLink) || !is_numeric($numberOfRowPerPage) |
|
| 110 | - ){ |
|
| 111 | - return $navbar; |
|
| 112 | - } |
|
| 113 | - if($numberOfLink % 2 == 0){ |
|
| 114 | - $start = $currentPageNumber - ($numberOfLink / 2) + 1; |
|
| 115 | - $end = $currentPageNumber + ($numberOfLink / 2); |
|
| 116 | - } |
|
| 117 | - else{ |
|
| 118 | - $start = $currentPageNumber - floor($numberOfLink / 2); |
|
| 119 | - $end = $currentPageNumber + floor($numberOfLink / 2); |
|
| 120 | - } |
|
| 121 | - if($start <= 1){ |
|
| 122 | - $begin = 1; |
|
| 123 | - $end = $numberOfLink; |
|
| 124 | - } |
|
| 125 | - else if($start > 1 && $end < $numberOfPage){ |
|
| 126 | - $begin = $start; |
|
| 127 | - $end = $end; |
|
| 128 | - } |
|
| 129 | - else{ |
|
| 130 | - $begin = ($numberOfPage - $numberOfLink) + 1; |
|
| 131 | - $end = $numberOfPage; |
|
| 132 | - } |
|
| 133 | - if($numberOfPage <= $numberOfLink){ |
|
| 134 | - $begin = 1; |
|
| 135 | - $end = $numberOfPage; |
|
| 136 | - } |
|
| 137 | - if($currentPageNumber == 1){ |
|
| 138 | - for($i = $begin; $i <= $end; $i++){ |
|
| 139 | - if($i == $currentPageNumber){ |
|
| 140 | - $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close']; |
|
| 141 | - } |
|
| 142 | - else{ |
|
| 143 | - $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '" ' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' . $this->config['digit_close']; |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - $navbar .= $this->config['next_open'] . '<a href="' . $query . ($currentPageNumber + 1) . '">' . $this->config['next_text'] . '</a>' . $this->config['next_close']; |
|
| 147 | - } |
|
| 148 | - else if($currentPageNumber > 1 && $currentPageNumber < $numberOfPage){ |
|
| 149 | - $navbar .= $this->config['previous_open'] . '<a href="' . $query . ($currentPageNumber - 1) . '">' . $this->config['previous_text'] . '</a>' . $this->config['previous_close']; |
|
| 150 | - for($i = $begin; $i <= $end; $i++){ |
|
| 151 | - if($i == $currentPageNumber){ |
|
| 152 | - $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close']; |
|
| 153 | - } |
|
| 154 | - else{ |
|
| 155 | - $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i .'</a>' . $this->config['digit_close']; |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - $navbar .= $this->config['next_open']."<a href='$query".($currentPageNumber + 1)."'>".$this->config['next_text']."</a>".$this->config['next_close']; |
|
| 159 | - } |
|
| 160 | - else if($currentPageNumber == $numberOfPage){ |
|
| 161 | - $navbar .= $this->config['previous_open'] . '<a href="' . $query . ($currentPageNumber - 1) . '">' . $this->config['previous_text'] . '</a>' . $this->config['previous_close']; |
|
| 162 | - for($i = $begin; $i <= $end; $i++){ |
|
| 163 | - if($i == $currentPageNumber){ |
|
| 164 | - $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close']; |
|
| 165 | - } |
|
| 166 | - else{ |
|
| 167 | - $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' . $this->config['digit_close']; |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - $navbar = $this->config['pagination_open'] . $navbar . $this->config['pagination_close']; |
|
| 172 | - return $navbar; |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | 109 | \ No newline at end of file |
| 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 | + } |
|
| 176 | 176 | \ No newline at end of file |
@@ -24,7 +24,7 @@ discard block |
||
| 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 | 30 | * The list of loaded config |
@@ -36,14 +36,14 @@ discard block |
||
| 36 | 36 | * Create an instance of pagination |
| 37 | 37 | * @param array $overwriteConfig the list of configuration to overwrite the defined configuration in config_pagination.php |
| 38 | 38 | */ |
| 39 | - public function __construct($overwriteConfig = array()){ |
|
| 40 | - if(file_exists(CONFIG_PATH . 'config_pagination.php')){ |
|
| 39 | + public function __construct($overwriteConfig = array()) { |
|
| 40 | + if (file_exists(CONFIG_PATH . 'config_pagination.php')) { |
|
| 41 | 41 | require_once CONFIG_PATH . 'config_pagination.php'; |
| 42 | - if(empty($config) || ! is_array($config)){ |
|
| 42 | + if (empty($config) || !is_array($config)) { |
|
| 43 | 43 | show_error('No configuration found in ' . CONFIG_PATH . 'config_pagination.php'); |
| 44 | 44 | } |
| 45 | - else{ |
|
| 46 | - if(! empty($overwriteConfig)){ |
|
| 45 | + else { |
|
| 46 | + if (!empty($overwriteConfig)) { |
|
| 47 | 47 | $config = array_merge($config, $overwriteConfig); |
| 48 | 48 | } |
| 49 | 49 | $this->config = $config; |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | unset($config); |
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | - else{ |
|
| 54 | + else { |
|
| 55 | 55 | show_error('Unable to find the pagination configuration file'); |
| 56 | 56 | } |
| 57 | 57 | } |
@@ -62,8 +62,8 @@ discard block |
||
| 62 | 62 | * config_pagination.php |
| 63 | 63 | * @param array $config the configuration to set |
| 64 | 64 | */ |
| 65 | - public function setConfig(array $config = array()){ |
|
| 66 | - if(! empty($config)){ |
|
| 65 | + public function setConfig(array $config = array()) { |
|
| 66 | + if (!empty($config)) { |
|
| 67 | 67 | $this->config = array_merge($this->config, $config); |
| 68 | 68 | Config::setAll($config); |
| 69 | 69 | } |
@@ -75,26 +75,26 @@ discard block |
||
| 75 | 75 | * @param int $currentPageNumber the current page number |
| 76 | 76 | * @return string the pagination link |
| 77 | 77 | */ |
| 78 | - public function getLink($totalRows, $currentPageNumber){ |
|
| 78 | + public function getLink($totalRows, $currentPageNumber) { |
|
| 79 | 79 | $pageQueryName = $this->config['page_query_string_name']; |
| 80 | 80 | $numberOfLink = $this->config['nb_link']; |
| 81 | 81 | $numberOfRowPerPage = $this->config['pagination_per_page']; |
| 82 | 82 | $queryString = Url::queryString(); |
| 83 | 83 | $currentUrl = Url::current(); |
| 84 | - if($queryString == ''){ |
|
| 84 | + if ($queryString == '') { |
|
| 85 | 85 | $query = '?' . $pageQueryName . '='; |
| 86 | 86 | } |
| 87 | - else{ |
|
| 87 | + else { |
|
| 88 | 88 | $tab = explode($pageQueryName . '=', $queryString); |
| 89 | 89 | $nb = count($tab); |
| 90 | - if($nb == 1){ |
|
| 90 | + if ($nb == 1) { |
|
| 91 | 91 | $query = '?' . $queryString . '&' . $pageQueryName . '='; |
| 92 | 92 | } |
| 93 | - else{ |
|
| 94 | - if($tab[0] == ''){ |
|
| 93 | + else { |
|
| 94 | + if ($tab[0] == '') { |
|
| 95 | 95 | $query = '?' . $pageQueryName . '='; |
| 96 | 96 | } |
| 97 | - else{ |
|
| 97 | + else { |
|
| 98 | 98 | $query = '?' . $tab[0] . '' . $pageQueryName . '='; |
| 99 | 99 | } |
| 100 | 100 | } |
@@ -103,67 +103,67 @@ discard block |
||
| 103 | 103 | $query = $temp[0] . $query; |
| 104 | 104 | $navbar = ''; |
| 105 | 105 | $numberOfPage = ceil($totalRows / $numberOfRowPerPage); |
| 106 | - if(! is_numeric ($currentPageNumber) || $currentPageNumber <= 0){ |
|
| 106 | + if (!is_numeric($currentPageNumber) || $currentPageNumber <= 0) { |
|
| 107 | 107 | $currentPageNumber = 1; |
| 108 | 108 | } |
| 109 | - if($numberOfPage <= 1 || $numberOfLink <= 0 || $numberOfRowPerPage <= 0 || !is_numeric($numberOfLink) || !is_numeric($numberOfRowPerPage) |
|
| 110 | - ){ |
|
| 109 | + if ($numberOfPage <= 1 || $numberOfLink <= 0 || $numberOfRowPerPage <= 0 || !is_numeric($numberOfLink) || !is_numeric($numberOfRowPerPage) |
|
| 110 | + ) { |
|
| 111 | 111 | return $navbar; |
| 112 | 112 | } |
| 113 | - if($numberOfLink % 2 == 0){ |
|
| 113 | + if ($numberOfLink % 2 == 0) { |
|
| 114 | 114 | $start = $currentPageNumber - ($numberOfLink / 2) + 1; |
| 115 | 115 | $end = $currentPageNumber + ($numberOfLink / 2); |
| 116 | 116 | } |
| 117 | - else{ |
|
| 117 | + else { |
|
| 118 | 118 | $start = $currentPageNumber - floor($numberOfLink / 2); |
| 119 | 119 | $end = $currentPageNumber + floor($numberOfLink / 2); |
| 120 | 120 | } |
| 121 | - if($start <= 1){ |
|
| 121 | + if ($start <= 1) { |
|
| 122 | 122 | $begin = 1; |
| 123 | 123 | $end = $numberOfLink; |
| 124 | 124 | } |
| 125 | - else if($start > 1 && $end < $numberOfPage){ |
|
| 125 | + else if ($start > 1 && $end < $numberOfPage) { |
|
| 126 | 126 | $begin = $start; |
| 127 | 127 | $end = $end; |
| 128 | 128 | } |
| 129 | - else{ |
|
| 129 | + else { |
|
| 130 | 130 | $begin = ($numberOfPage - $numberOfLink) + 1; |
| 131 | 131 | $end = $numberOfPage; |
| 132 | 132 | } |
| 133 | - if($numberOfPage <= $numberOfLink){ |
|
| 133 | + if ($numberOfPage <= $numberOfLink) { |
|
| 134 | 134 | $begin = 1; |
| 135 | 135 | $end = $numberOfPage; |
| 136 | 136 | } |
| 137 | - if($currentPageNumber == 1){ |
|
| 138 | - for($i = $begin; $i <= $end; $i++){ |
|
| 139 | - if($i == $currentPageNumber){ |
|
| 137 | + if ($currentPageNumber == 1) { |
|
| 138 | + for ($i = $begin; $i <= $end; $i++) { |
|
| 139 | + if ($i == $currentPageNumber) { |
|
| 140 | 140 | $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close']; |
| 141 | 141 | } |
| 142 | - else{ |
|
| 142 | + else { |
|
| 143 | 143 | $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '" ' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' . $this->config['digit_close']; |
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | 146 | $navbar .= $this->config['next_open'] . '<a href="' . $query . ($currentPageNumber + 1) . '">' . $this->config['next_text'] . '</a>' . $this->config['next_close']; |
| 147 | 147 | } |
| 148 | - else if($currentPageNumber > 1 && $currentPageNumber < $numberOfPage){ |
|
| 148 | + else if ($currentPageNumber > 1 && $currentPageNumber < $numberOfPage) { |
|
| 149 | 149 | $navbar .= $this->config['previous_open'] . '<a href="' . $query . ($currentPageNumber - 1) . '">' . $this->config['previous_text'] . '</a>' . $this->config['previous_close']; |
| 150 | - for($i = $begin; $i <= $end; $i++){ |
|
| 151 | - if($i == $currentPageNumber){ |
|
| 150 | + for ($i = $begin; $i <= $end; $i++) { |
|
| 151 | + if ($i == $currentPageNumber) { |
|
| 152 | 152 | $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close']; |
| 153 | 153 | } |
| 154 | - else{ |
|
| 155 | - $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i .'</a>' . $this->config['digit_close']; |
|
| 154 | + else { |
|
| 155 | + $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' . $this->config['digit_close']; |
|
| 156 | 156 | } |
| 157 | 157 | } |
| 158 | - $navbar .= $this->config['next_open']."<a href='$query".($currentPageNumber + 1)."'>".$this->config['next_text']."</a>".$this->config['next_close']; |
|
| 158 | + $navbar .= $this->config['next_open'] . "<a href='$query" . ($currentPageNumber + 1) . "'>" . $this->config['next_text'] . "</a>" . $this->config['next_close']; |
|
| 159 | 159 | } |
| 160 | - else if($currentPageNumber == $numberOfPage){ |
|
| 160 | + else if ($currentPageNumber == $numberOfPage) { |
|
| 161 | 161 | $navbar .= $this->config['previous_open'] . '<a href="' . $query . ($currentPageNumber - 1) . '">' . $this->config['previous_text'] . '</a>' . $this->config['previous_close']; |
| 162 | - for($i = $begin; $i <= $end; $i++){ |
|
| 163 | - if($i == $currentPageNumber){ |
|
| 162 | + for ($i = $begin; $i <= $end; $i++) { |
|
| 163 | + if ($i == $currentPageNumber) { |
|
| 164 | 164 | $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close']; |
| 165 | 165 | } |
| 166 | - else{ |
|
| 166 | + else { |
|
| 167 | 167 | $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' . $this->config['digit_close']; |
| 168 | 168 | } |
| 169 | 169 | } |
@@ -41,8 +41,7 @@ discard block |
||
| 41 | 41 | require_once CONFIG_PATH . 'config_pagination.php'; |
| 42 | 42 | if(empty($config) || ! is_array($config)){ |
| 43 | 43 | show_error('No configuration found in ' . CONFIG_PATH . 'config_pagination.php'); |
| 44 | - } |
|
| 45 | - else{ |
|
| 44 | + } else{ |
|
| 46 | 45 | if(! empty($overwriteConfig)){ |
| 47 | 46 | $config = array_merge($config, $overwriteConfig); |
| 48 | 47 | } |
@@ -50,8 +49,7 @@ discard block |
||
| 50 | 49 | Config::setAll($config); |
| 51 | 50 | unset($config); |
| 52 | 51 | } |
| 53 | - } |
|
| 54 | - else{ |
|
| 52 | + } else{ |
|
| 55 | 53 | show_error('Unable to find the pagination configuration file'); |
| 56 | 54 | } |
| 57 | 55 | } |
@@ -83,18 +81,15 @@ discard block |
||
| 83 | 81 | $currentUrl = Url::current(); |
| 84 | 82 | if($queryString == ''){ |
| 85 | 83 | $query = '?' . $pageQueryName . '='; |
| 86 | - } |
|
| 87 | - else{ |
|
| 84 | + } else{ |
|
| 88 | 85 | $tab = explode($pageQueryName . '=', $queryString); |
| 89 | 86 | $nb = count($tab); |
| 90 | 87 | if($nb == 1){ |
| 91 | 88 | $query = '?' . $queryString . '&' . $pageQueryName . '='; |
| 92 | - } |
|
| 93 | - else{ |
|
| 89 | + } else{ |
|
| 94 | 90 | if($tab[0] == ''){ |
| 95 | 91 | $query = '?' . $pageQueryName . '='; |
| 96 | - } |
|
| 97 | - else{ |
|
| 92 | + } else{ |
|
| 98 | 93 | $query = '?' . $tab[0] . '' . $pageQueryName . '='; |
| 99 | 94 | } |
| 100 | 95 | } |
@@ -113,20 +108,17 @@ discard block |
||
| 113 | 108 | if($numberOfLink % 2 == 0){ |
| 114 | 109 | $start = $currentPageNumber - ($numberOfLink / 2) + 1; |
| 115 | 110 | $end = $currentPageNumber + ($numberOfLink / 2); |
| 116 | - } |
|
| 117 | - else{ |
|
| 111 | + } else{ |
|
| 118 | 112 | $start = $currentPageNumber - floor($numberOfLink / 2); |
| 119 | 113 | $end = $currentPageNumber + floor($numberOfLink / 2); |
| 120 | 114 | } |
| 121 | 115 | if($start <= 1){ |
| 122 | 116 | $begin = 1; |
| 123 | 117 | $end = $numberOfLink; |
| 124 | - } |
|
| 125 | - else if($start > 1 && $end < $numberOfPage){ |
|
| 118 | + } else if($start > 1 && $end < $numberOfPage){ |
|
| 126 | 119 | $begin = $start; |
| 127 | 120 | $end = $end; |
| 128 | - } |
|
| 129 | - else{ |
|
| 121 | + } else{ |
|
| 130 | 122 | $begin = ($numberOfPage - $numberOfLink) + 1; |
| 131 | 123 | $end = $numberOfPage; |
| 132 | 124 | } |
@@ -138,32 +130,27 @@ discard block |
||
| 138 | 130 | for($i = $begin; $i <= $end; $i++){ |
| 139 | 131 | if($i == $currentPageNumber){ |
| 140 | 132 | $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close']; |
| 141 | - } |
|
| 142 | - else{ |
|
| 133 | + } else{ |
|
| 143 | 134 | $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '" ' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' . $this->config['digit_close']; |
| 144 | 135 | } |
| 145 | 136 | } |
| 146 | 137 | $navbar .= $this->config['next_open'] . '<a href="' . $query . ($currentPageNumber + 1) . '">' . $this->config['next_text'] . '</a>' . $this->config['next_close']; |
| 147 | - } |
|
| 148 | - else if($currentPageNumber > 1 && $currentPageNumber < $numberOfPage){ |
|
| 138 | + } else if($currentPageNumber > 1 && $currentPageNumber < $numberOfPage){ |
|
| 149 | 139 | $navbar .= $this->config['previous_open'] . '<a href="' . $query . ($currentPageNumber - 1) . '">' . $this->config['previous_text'] . '</a>' . $this->config['previous_close']; |
| 150 | 140 | for($i = $begin; $i <= $end; $i++){ |
| 151 | 141 | if($i == $currentPageNumber){ |
| 152 | 142 | $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close']; |
| 153 | - } |
|
| 154 | - else{ |
|
| 143 | + } else{ |
|
| 155 | 144 | $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i .'</a>' . $this->config['digit_close']; |
| 156 | 145 | } |
| 157 | 146 | } |
| 158 | 147 | $navbar .= $this->config['next_open']."<a href='$query".($currentPageNumber + 1)."'>".$this->config['next_text']."</a>".$this->config['next_close']; |
| 159 | - } |
|
| 160 | - else if($currentPageNumber == $numberOfPage){ |
|
| 148 | + } else if($currentPageNumber == $numberOfPage){ |
|
| 161 | 149 | $navbar .= $this->config['previous_open'] . '<a href="' . $query . ($currentPageNumber - 1) . '">' . $this->config['previous_text'] . '</a>' . $this->config['previous_close']; |
| 162 | 150 | for($i = $begin; $i <= $end; $i++){ |
| 163 | 151 | if($i == $currentPageNumber){ |
| 164 | 152 | $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close']; |
| 165 | - } |
|
| 166 | - else{ |
|
| 153 | + } else{ |
|
| 167 | 154 | $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' . $this->config['digit_close']; |
| 168 | 155 | } |
| 169 | 156 | } |
@@ -22,7 +22,7 @@ |
||
| 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 | class Form{ |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | 27 | |
| 28 | - class Form{ |
|
| 28 | + class Form { |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * Generate the form opened tag |
@@ -35,33 +35,33 @@ discard block |
||
| 35 | 35 | * @param string $enctype the form enctype like "multipart/form-data" |
| 36 | 36 | * @return string the generated form html |
| 37 | 37 | */ |
| 38 | - public static function open($path = null, array $attributes = array(), $method = 'POST', $enctype = null){ |
|
| 39 | - if($path){ |
|
| 38 | + public static function open($path = null, array $attributes = array(), $method = 'POST', $enctype = null) { |
|
| 39 | + if ($path) { |
|
| 40 | 40 | $path = Url::site_url($path); |
| 41 | 41 | } |
| 42 | 42 | $method = strtoupper($method); |
| 43 | 43 | $str = null; |
| 44 | - $str .= '<form action = "'.$path.'" method = "'.$method.'"'; |
|
| 45 | - if(! empty($enctype)){ |
|
| 46 | - $str .= ' enctype = "'.$enctype.'" '; |
|
| 44 | + $str .= '<form action = "' . $path . '" method = "' . $method . '"'; |
|
| 45 | + if (!empty($enctype)) { |
|
| 46 | + $str .= ' enctype = "' . $enctype . '" '; |
|
| 47 | 47 | } |
| 48 | - if(! isset($attributes['accept-charset'])){ |
|
| 48 | + if (!isset($attributes['accept-charset'])) { |
|
| 49 | 49 | $attributes['accept-charset'] = get_config('charset', 'utf-8'); |
| 50 | 50 | } |
| 51 | 51 | $str .= attributes_to_string($attributes); |
| 52 | 52 | $str .= '>'; |
| 53 | 53 | $checkCsrf = false; |
| 54 | 54 | //check if the user set the checking of CSRF manually |
| 55 | - if($method != 'POST' && isset($attributes['csrf'])){ |
|
| 55 | + if ($method != 'POST' && isset($attributes['csrf'])) { |
|
| 56 | 56 | $obj = & get_instance(); |
| 57 | - if(! isset($obj->formvalidation)){ |
|
| 57 | + if (!isset($obj->formvalidation)) { |
|
| 58 | 58 | Loader::library('FormValidation'); |
| 59 | 59 | } |
| 60 | 60 | $obj->formvalidation->enableCsrfCheck = true; |
| 61 | 61 | $checkCsrf = true; |
| 62 | 62 | } |
| 63 | 63 | //if CSRF enable or is set manually |
| 64 | - if((get_config('csrf_enable', false) && $method == 'POST') || ($method != 'POST' && $checkCsrf)){ |
|
| 64 | + if ((get_config('csrf_enable', false) && $method == 'POST') || ($method != 'POST' && $checkCsrf)) { |
|
| 65 | 65 | $csrfValue = Security::generateCSRF(); |
| 66 | 66 | $csrfName = get_config('csrf_key', 'csrf_key'); |
| 67 | 67 | $str .= static::hidden($csrfName, $csrfValue); |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | * @see Form::open() for more details |
| 75 | 75 | * @return string the generated multipart form html |
| 76 | 76 | */ |
| 77 | - public static function openMultipart($path = null, array $attributes = array(), $method = 'POST'){ |
|
| 77 | + public static function openMultipart($path = null, array $attributes = array(), $method = 'POST') { |
|
| 78 | 78 | return self::open($path, $attributes, $method, 'multipart/form-data'); |
| 79 | 79 | } |
| 80 | 80 | |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | * Generate the form close |
| 83 | 83 | * @return string the form close html |
| 84 | 84 | */ |
| 85 | - public static function close(){ |
|
| 85 | + public static function close() { |
|
| 86 | 86 | return '</form>'; |
| 87 | 87 | } |
| 88 | 88 | |
@@ -93,10 +93,10 @@ discard block |
||
| 93 | 93 | * @param array $legendAttributes the legend additional HTML attributes. Is used only is $legend is not empty |
| 94 | 94 | * @return string the generated fieldset value |
| 95 | 95 | */ |
| 96 | - public static function fieldset($legend = '', array $fieldsetAttributes = array(), array $legendAttributes = array()){ |
|
| 96 | + public static function fieldset($legend = '', array $fieldsetAttributes = array(), array $legendAttributes = array()) { |
|
| 97 | 97 | $str = '<fieldset' . attributes_to_string($fieldsetAttributes) . '>'; |
| 98 | - if($legend){ |
|
| 99 | - $str .= '<legend' . attributes_to_string($legendAttributes) . '>'.$legend.'</legend>'; |
|
| 98 | + if ($legend) { |
|
| 99 | + $str .= '<legend' . attributes_to_string($legendAttributes) . '>' . $legend . '</legend>'; |
|
| 100 | 100 | } |
| 101 | 101 | return $str; |
| 102 | 102 | } |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | * Generate the fieldset close tag |
| 106 | 106 | * @return string the generated html for fieldset close |
| 107 | 107 | */ |
| 108 | - public static function fieldsetClose(){ |
|
| 108 | + public static function fieldsetClose() { |
|
| 109 | 109 | return '</fieldset>'; |
| 110 | 110 | } |
| 111 | 111 | |
@@ -115,13 +115,13 @@ discard block |
||
| 115 | 115 | * @param string $name the form field name |
| 116 | 116 | * @return string the error message if exists and null if not |
| 117 | 117 | */ |
| 118 | - public static function error($name){ |
|
| 118 | + public static function error($name) { |
|
| 119 | 119 | $return = null; |
| 120 | 120 | $obj = & get_instance(); |
| 121 | - if(isset($obj->formvalidation)){ |
|
| 121 | + if (isset($obj->formvalidation)) { |
|
| 122 | 122 | $errors = $obj->formvalidation->returnErrors(); |
| 123 | - $error = isset($errors[$name]) ? $errors[$name] : null; |
|
| 124 | - if($error){ |
|
| 123 | + $error = isset($errors[$name]) ? $errors[$name] : null; |
|
| 124 | + if ($error) { |
|
| 125 | 125 | list($errorStart, $errorEnd) = $obj->formvalidation->getErrorDelimiter(); |
| 126 | 126 | $return = $errorStart . $error . $errorEnd; |
| 127 | 127 | } |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | * @param mixed $default the default value if can not found the given form field name |
| 136 | 136 | * @return mixed the form field value if is set, otherwise return the default value. |
| 137 | 137 | */ |
| 138 | - public static function value($name, $default = null){ |
|
| 138 | + public static function value($name, $default = null) { |
|
| 139 | 139 | $value = get_instance()->request->query($name); |
| 140 | 140 | return $value ? $value : $default; |
| 141 | 141 | } |
@@ -147,14 +147,14 @@ discard block |
||
| 147 | 147 | * @param array $attributes the additional attributes to be added |
| 148 | 148 | * @return string the generated label html content |
| 149 | 149 | */ |
| 150 | - public static function label($label, $for = '', array $attributes = array()){ |
|
| 150 | + public static function label($label, $for = '', array $attributes = array()) { |
|
| 151 | 151 | $str = '<label'; |
| 152 | - if($for){ |
|
| 153 | - $str .= ' for = "'.$for.'"'; |
|
| 152 | + if ($for) { |
|
| 153 | + $str .= ' for = "' . $for . '"'; |
|
| 154 | 154 | } |
| 155 | 155 | $str .= attributes_to_string($attributes); |
| 156 | 156 | $str .= '>'; |
| 157 | - $str .= $label.'</label>'; |
|
| 157 | + $str .= $label . '</label>'; |
|
| 158 | 158 | return $str; |
| 159 | 159 | } |
| 160 | 160 | |
@@ -166,9 +166,9 @@ discard block |
||
| 166 | 166 | * @param string $type the type of the form field (password, text, submit, button, etc.) |
| 167 | 167 | * @return string the generated form field html content for the input |
| 168 | 168 | */ |
| 169 | - public static function input($name, $value = null, array $attributes = array(), $type = 'text'){ |
|
| 169 | + public static function input($name, $value = null, array $attributes = array(), $type = 'text') { |
|
| 170 | 170 | $str = null; |
| 171 | - $str .= '<input name = "'.$name.'" value = "'.$value.'" type = "'.$type.'"'; |
|
| 171 | + $str .= '<input name = "' . $name . '" value = "' . $value . '" type = "' . $type . '"'; |
|
| 172 | 172 | $str .= attributes_to_string($attributes); |
| 173 | 173 | $str .= '/>'; |
| 174 | 174 | return $str; |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | * Generate the form field for "text" |
| 179 | 179 | * @see Form::input() for more details |
| 180 | 180 | */ |
| 181 | - public static function text($name, $value = null, array $attributes = array()){ |
|
| 181 | + public static function text($name, $value = null, array $attributes = array()) { |
|
| 182 | 182 | return self::input($name, $value, $attributes, 'text'); |
| 183 | 183 | } |
| 184 | 184 | |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | * Generate the form field for "password" |
| 187 | 187 | * @see Form::input() for more details |
| 188 | 188 | */ |
| 189 | - public static function password($name, $value = null, array $attributes = array()){ |
|
| 189 | + public static function password($name, $value = null, array $attributes = array()) { |
|
| 190 | 190 | return self::input($name, $value, $attributes, 'password'); |
| 191 | 191 | } |
| 192 | 192 | |
@@ -194,8 +194,8 @@ discard block |
||
| 194 | 194 | * Generate the form field for "radio" |
| 195 | 195 | * @see Form::input() for more details |
| 196 | 196 | */ |
| 197 | - public static function radio($name, $value = null, $checked = false, array $attributes = array()){ |
|
| 198 | - if($checked){ |
|
| 197 | + public static function radio($name, $value = null, $checked = false, array $attributes = array()) { |
|
| 198 | + if ($checked) { |
|
| 199 | 199 | $attributes['checked'] = true; |
| 200 | 200 | } |
| 201 | 201 | return self::input($name, $value, $attributes, 'radio'); |
@@ -205,8 +205,8 @@ discard block |
||
| 205 | 205 | * Generate the form field for "checkbox" |
| 206 | 206 | * @see Form::input() for more details |
| 207 | 207 | */ |
| 208 | - public static function checkbox($name, $value = null, $checked = false, array $attributes = array()){ |
|
| 209 | - if($checked){ |
|
| 208 | + public static function checkbox($name, $value = null, $checked = false, array $attributes = array()) { |
|
| 209 | + if ($checked) { |
|
| 210 | 210 | $attributes['checked'] = true; |
| 211 | 211 | } |
| 212 | 212 | return self::input($name, $value, $attributes, 'checkbox'); |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | * Generate the form field for "number" |
| 217 | 217 | * @see Form::input() for more details |
| 218 | 218 | */ |
| 219 | - public static function number($name, $value = null, array $attributes = array()){ |
|
| 219 | + public static function number($name, $value = null, array $attributes = array()) { |
|
| 220 | 220 | return self::input($name, $value, $attributes, 'number'); |
| 221 | 221 | } |
| 222 | 222 | |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | * Generate the form field for "phone" |
| 225 | 225 | * @see Form::input() for more details |
| 226 | 226 | */ |
| 227 | - public static function phone($name, $value = null, array $attributes = array()){ |
|
| 227 | + public static function phone($name, $value = null, array $attributes = array()) { |
|
| 228 | 228 | return self::input($name, $value, $attributes, 'phone'); |
| 229 | 229 | } |
| 230 | 230 | |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | * Generate the form field for "email" |
| 233 | 233 | * @see Form::input() for more details |
| 234 | 234 | */ |
| 235 | - public static function email($name, $value = null, array $attributes = array()){ |
|
| 235 | + public static function email($name, $value = null, array $attributes = array()) { |
|
| 236 | 236 | return self::input($name, $value, $attributes, 'email'); |
| 237 | 237 | } |
| 238 | 238 | |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | * Generate the form field for "search" |
| 241 | 241 | * @see Form::input() for more details |
| 242 | 242 | */ |
| 243 | - public static function search($name, $value = null, array $attributes = array()){ |
|
| 243 | + public static function search($name, $value = null, array $attributes = array()) { |
|
| 244 | 244 | return self::input($name, $value, $attributes, 'search'); |
| 245 | 245 | } |
| 246 | 246 | |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | * Generate the form field for "hidden" |
| 249 | 249 | * @see Form::input() for more details |
| 250 | 250 | */ |
| 251 | - public static function hidden($name, $value = null, array $attributes = array()){ |
|
| 251 | + public static function hidden($name, $value = null, array $attributes = array()) { |
|
| 252 | 252 | return self::input($name, $value, $attributes, 'hidden'); |
| 253 | 253 | } |
| 254 | 254 | |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | * Generate the form field for "file" |
| 257 | 257 | * @see Form::input() for more details |
| 258 | 258 | */ |
| 259 | - public static function file($name, array $attributes = array()){ |
|
| 259 | + public static function file($name, array $attributes = array()) { |
|
| 260 | 260 | return self::input($name, null, $attributes, 'file'); |
| 261 | 261 | } |
| 262 | 262 | |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | * Generate the form field for "button" |
| 265 | 265 | * @see Form::input() for more details |
| 266 | 266 | */ |
| 267 | - public static function button($name, $value = null, array $attributes = array()){ |
|
| 267 | + public static function button($name, $value = null, array $attributes = array()) { |
|
| 268 | 268 | return self::input($name, $value, $attributes, 'button'); |
| 269 | 269 | } |
| 270 | 270 | |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | * Generate the form field for "reset" |
| 273 | 273 | * @see Form::input() for more details |
| 274 | 274 | */ |
| 275 | - public static function reset($name, $value = null, array $attributes = array()){ |
|
| 275 | + public static function reset($name, $value = null, array $attributes = array()) { |
|
| 276 | 276 | return self::input($name, $value, $attributes, 'reset'); |
| 277 | 277 | } |
| 278 | 278 | |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | * Generate the form field for "submit" |
| 281 | 281 | * @see Form::input() for more details |
| 282 | 282 | */ |
| 283 | - public static function submit($name, $value = null, array $attributes = array()){ |
|
| 283 | + public static function submit($name, $value = null, array $attributes = array()) { |
|
| 284 | 284 | return self::input($name, $value, $attributes, 'submit'); |
| 285 | 285 | } |
| 286 | 286 | |
@@ -291,12 +291,12 @@ discard block |
||
| 291 | 291 | * @param array $attributes the additional attributes to be added |
| 292 | 292 | * @return string the generated textarea form html content |
| 293 | 293 | */ |
| 294 | - public static function textarea($name, $value = '', array $attributes = array()){ |
|
| 294 | + public static function textarea($name, $value = '', array $attributes = array()) { |
|
| 295 | 295 | $str = null; |
| 296 | - $str .= '<textarea name = "'.$name.'"'; |
|
| 296 | + $str .= '<textarea name = "' . $name . '"'; |
|
| 297 | 297 | $str .= attributes_to_string($attributes); |
| 298 | 298 | $str .= '>'; |
| 299 | - $str .= $value.'</textarea>'; |
|
| 299 | + $str .= $value . '</textarea>'; |
|
| 300 | 300 | return $str; |
| 301 | 301 | } |
| 302 | 302 | |
@@ -308,20 +308,20 @@ discard block |
||
| 308 | 308 | * @param array $attributes the additional attribute to be added |
| 309 | 309 | * @return string the generated form field html content for select |
| 310 | 310 | */ |
| 311 | - public static function select($name, $values = null, $selected = null, array $attributes = array()){ |
|
| 312 | - if(! is_array($values)){ |
|
| 311 | + public static function select($name, $values = null, $selected = null, array $attributes = array()) { |
|
| 312 | + if (!is_array($values)) { |
|
| 313 | 313 | $values = array('' => $values); |
| 314 | 314 | } |
| 315 | 315 | $str = null; |
| 316 | - $str .= '<select name = "'.$name.'"'; |
|
| 316 | + $str .= '<select name = "' . $name . '"'; |
|
| 317 | 317 | $str .= attributes_to_string($attributes); |
| 318 | 318 | $str .= '>'; |
| 319 | - foreach($values as $key => $val){ |
|
| 319 | + foreach ($values as $key => $val) { |
|
| 320 | 320 | $select = ''; |
| 321 | - if($key == $selected){ |
|
| 321 | + if ($key == $selected) { |
|
| 322 | 322 | $select = 'selected'; |
| 323 | 323 | } |
| 324 | - $str .= '<option value = "'.$key.'" '.$select.'>'.$val.'</option>'; |
|
| 324 | + $str .= '<option value = "' . $key . '" ' . $select . '>' . $val . '</option>'; |
|
| 325 | 325 | } |
| 326 | 326 | $str .= '</select>'; |
| 327 | 327 | return $str; |
@@ -1,1732 +1,1732 @@ |
||
| 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 | - 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 | + 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 | + } |
|
@@ -918,27 +918,27 @@ discard block |
||
| 918 | 918 | if (isset($aresult[1])) { |
| 919 | 919 | $this->setBrowser(self::BROWSER_IE); |
| 920 | 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'){ |
|
| 921 | + if (preg_match('#trident/([0-9\.]+);#i', $this->_agent, $aresult)) { |
|
| 922 | + if ($aresult[1] == '3.1') { |
|
| 923 | 923 | $this->setVersion('7.0'); |
| 924 | 924 | } |
| 925 | - else if($aresult[1] == '4.0'){ |
|
| 925 | + else if ($aresult[1] == '4.0') { |
|
| 926 | 926 | $this->setVersion('8.0'); |
| 927 | 927 | } |
| 928 | - else if($aresult[1] == '5.0'){ |
|
| 928 | + else if ($aresult[1] == '5.0') { |
|
| 929 | 929 | $this->setVersion('9.0'); |
| 930 | 930 | } |
| 931 | - else if($aresult[1] == '6.0'){ |
|
| 931 | + else if ($aresult[1] == '6.0') { |
|
| 932 | 932 | $this->setVersion('10.0'); |
| 933 | 933 | } |
| 934 | - else if($aresult[1] == '7.0'){ |
|
| 934 | + else if ($aresult[1] == '7.0') { |
|
| 935 | 935 | $this->setVersion('11.0'); |
| 936 | 936 | } |
| 937 | - else if($aresult[1] == '8.0'){ |
|
| 937 | + else if ($aresult[1] == '8.0') { |
|
| 938 | 938 | $this->setVersion('11.0'); |
| 939 | 939 | } |
| 940 | 940 | } |
| 941 | - if(stripos($this->_agent, 'IEMobile') !== false) { |
|
| 941 | + if (stripos($this->_agent, 'IEMobile') !== false) { |
|
| 942 | 942 | $this->setBrowser(self::BROWSER_POCKET_IE); |
| 943 | 943 | $this->setMobile(true); |
| 944 | 944 | } |
@@ -1684,8 +1684,8 @@ discard block |
||
| 1684 | 1684 | $this->_platform = self::PLATFORM_ANDROID; |
| 1685 | 1685 | } elseif (stripos($this->_agent, 'Silk') !== false) { |
| 1686 | 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; |
|
| 1687 | + } elseif (stripos($this->_agent, 'linux') !== false && stripos($this->_agent, 'SMART-TV') !== false) { |
|
| 1688 | + $this->_platform = self::PLATFORM_LINUX . '/' . self::PLATFORM_SMART_TV; |
|
| 1689 | 1689 | } elseif (stripos($this->_agent, 'linux') !== false) { |
| 1690 | 1690 | $this->_platform = self::PLATFORM_LINUX; |
| 1691 | 1691 | } else if (stripos($this->_agent, 'Nokia') !== false) { |
@@ -921,20 +921,15 @@ |
||
| 921 | 921 | if(preg_match('#trident/([0-9\.]+);#i', $this->_agent, $aresult)){ |
| 922 | 922 | if($aresult[1] == '3.1'){ |
| 923 | 923 | $this->setVersion('7.0'); |
| 924 | - } |
|
| 925 | - else if($aresult[1] == '4.0'){ |
|
| 924 | + } else if($aresult[1] == '4.0'){ |
|
| 926 | 925 | $this->setVersion('8.0'); |
| 927 | - } |
|
| 928 | - else if($aresult[1] == '5.0'){ |
|
| 926 | + } else if($aresult[1] == '5.0'){ |
|
| 929 | 927 | $this->setVersion('9.0'); |
| 930 | - } |
|
| 931 | - else if($aresult[1] == '6.0'){ |
|
| 928 | + } else if($aresult[1] == '6.0'){ |
|
| 932 | 929 | $this->setVersion('10.0'); |
| 933 | - } |
|
| 934 | - else if($aresult[1] == '7.0'){ |
|
| 930 | + } else if($aresult[1] == '7.0'){ |
|
| 935 | 931 | $this->setVersion('11.0'); |
| 936 | - } |
|
| 937 | - else if($aresult[1] == '8.0'){ |
|
| 932 | + } else if($aresult[1] == '8.0'){ |
|
| 938 | 933 | $this->setVersion('11.0'); |
| 939 | 934 | } |
| 940 | 935 | } |
@@ -22,7 +22,7 @@ |
||
| 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 | if(! function_exists('__')){ |
| 28 | 28 | /** |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | - if(! function_exists('__')){ |
|
| 27 | + if (!function_exists('__')) { |
|
| 28 | 28 | /** |
| 29 | 29 | * function for the shortcut to Lang::get() |
| 30 | 30 | * @param string $key the language key to retrieve |
@@ -32,20 +32,20 @@ discard block |
||
| 32 | 32 | * for the given key |
| 33 | 33 | * @return string the language value |
| 34 | 34 | */ |
| 35 | - function __($key, $default = 'LANGUAGE_ERROR'){ |
|
| 35 | + function __($key, $default = 'LANGUAGE_ERROR') { |
|
| 36 | 36 | return get_instance()->lang->get($key, $default); |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | |
| 42 | - if(! function_exists('get_languages')){ |
|
| 42 | + if (!function_exists('get_languages')) { |
|
| 43 | 43 | /** |
| 44 | 44 | * function for the shortcut to Lang::getSupported() |
| 45 | 45 | * |
| 46 | 46 | * @return array all the supported languages |
| 47 | 47 | */ |
| 48 | - function get_languages(){ |
|
| 48 | + function get_languages() { |
|
| 49 | 49 | return get_instance()->lang->getSupported(); |
| 50 | 50 | } |
| 51 | 51 | |
@@ -22,7 +22,7 @@ |
||
| 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 | /** |
@@ -55,17 +55,13 @@ |
||
| 55 | 55 | |
| 56 | 56 | if (isset($_SERVER["HTTP_CLIENT_IP"])) { |
| 57 | 57 | $ip = $_SERVER["HTTP_CLIENT_IP"]; |
| 58 | - } |
|
| 59 | - else if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) { |
|
| 58 | + } else if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) { |
|
| 60 | 59 | $ip = $_SERVER["HTTP_X_FORWARDED_FOR"]; |
| 61 | - } |
|
| 62 | - else if (isset($_SERVER["HTTP_X_FORWARDED"])) { |
|
| 60 | + } else if (isset($_SERVER["HTTP_X_FORWARDED"])) { |
|
| 63 | 61 | $ip = $_SERVER["HTTP_X_FORWARDED"]; |
| 64 | - } |
|
| 65 | - else if (isset($_SERVER["HTTP_FORWARDED_FOR"])) { |
|
| 62 | + } else if (isset($_SERVER["HTTP_FORWARDED_FOR"])) { |
|
| 66 | 63 | $ip = $_SERVER["HTTP_FORWARDED_FOR"]; |
| 67 | - } |
|
| 68 | - else if (isset($_SERVER["HTTP_FORWARDED"])) { |
|
| 64 | + } else if (isset($_SERVER["HTTP_FORWARDED"])) { |
|
| 69 | 65 | $ip = $_SERVER["HTTP_FORWARDED"]; |
| 70 | 66 | } |
| 71 | 67 | |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | |
| 43 | 43 | |
| 44 | - if(! function_exists('get_ip')){ |
|
| 44 | + if (!function_exists('get_ip')) { |
|
| 45 | 45 | /** |
| 46 | 46 | * Retrieves the user's IP address |
| 47 | 47 | * |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | * |
| 51 | 51 | * @return string the IP address. |
| 52 | 52 | */ |
| 53 | - function get_ip(){ |
|
| 53 | + function get_ip() { |
|
| 54 | 54 | $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1'; |
| 55 | 55 | |
| 56 | 56 | if (isset($_SERVER["HTTP_CLIENT_IP"])) { |
@@ -22,7 +22,7 @@ |
||
| 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 | * @file function_string.php |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * @filesource |
| 40 | 40 | */ |
| 41 | 41 | |
| 42 | - if(! function_exists('get_random_string')){ |
|
| 42 | + if (!function_exists('get_random_string')) { |
|
| 43 | 43 | /** |
| 44 | 44 | * Generate a random string |
| 45 | 45 | * @param string $type the type of generation. It can take the values: "alpha" for alphabetic characters, |
@@ -49,9 +49,9 @@ discard block |
||
| 49 | 49 | * @param boolean $lower if we return the generated string in lowercase (true). By default it's false. |
| 50 | 50 | * @return string the generated string. |
| 51 | 51 | */ |
| 52 | - function get_random_string($type = 'alnum', $length = 10, $lower = false){ |
|
| 52 | + function get_random_string($type = 'alnum', $length = 10, $lower = false) { |
|
| 53 | 53 | $str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; |
| 54 | - switch($type){ |
|
| 54 | + switch ($type) { |
|
| 55 | 55 | case 'alpha': |
| 56 | 56 | $str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
| 57 | 57 | break; |
@@ -63,10 +63,10 @@ discard block |
||
| 63 | 63 | break; |
| 64 | 64 | } |
| 65 | 65 | $random = null; |
| 66 | - for($i = 0; $i < $length; $i++){ |
|
| 66 | + for ($i = 0; $i < $length; $i++) { |
|
| 67 | 67 | $random .= $str[mt_rand() % strlen($str)]; |
| 68 | 68 | } |
| 69 | - if($lower){ |
|
| 69 | + if ($lower) { |
|
| 70 | 70 | $random = strtolower($random); |
| 71 | 71 | } |
| 72 | 72 | return $random; |