diff --git a/classes/ModuleGrid.php b/classes/ModuleGrid.php index 90046f3ed..6b4d608e7 100644 --- a/classes/ModuleGrid.php +++ b/classes/ModuleGrid.php @@ -117,17 +117,17 @@ abstract class ModuleGridCore extends Module $grider .= '&width='.$params['width']; $grider .= '&height='.$params['height']; - if (isset($params['start']) AND Validate::IsUnsignedInt($params['start'])) + if (isset($params['start']) && Validate::IsUnsignedInt($params['start'])) $grider .= '&start='.$params['start']; - if (isset($params['limit']) AND Validate::IsUnsignedInt($params['limit'])) + if (isset($params['limit']) && Validate::IsUnsignedInt($params['limit'])) $grider .= '&limit='.$params['limit']; - if (isset($params['type']) AND Validate::IsName($params['type'])) + if (isset($params['type']) && Validate::IsName($params['type'])) $grider .= '&type='.$params['type']; - if (isset($params['option']) AND Validate::IsGenericName($params['option'])) + if (isset($params['option']) && Validate::IsGenericName($params['option'])) $grider .= '&option='.$params['option']; - if (isset($params['sort']) AND Validate::IsName($params['sort'])) + if (isset($params['sort']) && Validate::IsName($params['sort'])) $grider .= '&sort='.$params['sort']; - if (isset($params['dir']) AND Validate::IsSortDirection($params['dir'])) + if (isset($params['dir']) && Validate::isSortDirection($params['dir'])) $grider .= '&dir='.$params['dir']; require_once(dirname(__FILE__).'/../modules/'.$render.'/'.$render.'.php'); diff --git a/classes/Validate.php b/classes/Validate.php index ac6af45d4..0ef434497 100644 --- a/classes/Validate.php +++ b/classes/Validate.php @@ -32,32 +32,32 @@ class ValidateCore return preg_match('#^-?[0-9]+$#', (string)$ip); } - public static function isAnything($data) + public static function isAnything() { return true; } /** - * Check for e-mail validity - * - * @param string $email e-mail address to validate - * @return boolean Validity is ok or not - */ - public static function isEmail($email, $required = true) - { - return !empty($email) && preg_match('/^[a-z0-9!#$%&\'*+\/=?^`{}|~_-]+[.a-z0-9!#$%&\'*+\/=?^`{}|~_-]*@[a-z0-9]+[._a-z0-9-]*\.[a-z0-9]+$/ui', $email); - } + * Check for e-mail validity + * + * @param string $email e-mail address to validate + * @return boolean Validity is ok or not + */ + public static function isEmail($email) + { + return !empty($email) && preg_match('/^[a-z0-9!#$%&\'*+\/=?^`{}|~_-]+[.a-z0-9!#$%&\'*+\/=?^`{}|~_-]*@[a-z0-9]+[._a-z0-9-]*\.[a-z0-9]+$/ui', $email); + } - /** - * Check for module URL validity - * - * @param string $url module URL to validate - * @param array $errors Reference array for catching errors - * @return boolean Validity is ok or not - */ + /** + * Check for module URL validity + * + * @param string $url module URL to validate + * @param array $errors Reference array for catching errors + * @return boolean Validity is ok or not + */ public static function isModuleUrl($url, &$errors) { - if (!$url OR $url == 'http://') + if (!$url || $url == 'http://') $errors[] = Tools::displayError('Please specify module URL'); elseif (substr($url, -4) != '.tar' && substr($url, -4) != '.zip' && substr($url, -4) != '.tgz' && substr($url, -7) != '.tar.gz') $errors[] = Tools::displayError('Unknown archive type'); @@ -68,180 +68,180 @@ class ValidateCore if (!is_array(@get_headers($url))) $errors[] = Tools::displayError('Invalid URL'); } - if (!sizeof($errors)) + if (!count($errors)) return true; return false; } /** - * Check for MD5 string validity - * - * @param string $md5 MD5 string to validate - * @return boolean Validity is ok or not - */ + * Check for MD5 string validity + * + * @param string $md5 MD5 string to validate + * @return boolean Validity is ok or not + */ public static function isMd5($md5) { return preg_match('/^[a-f0-9A-F]{32}$/', $md5); } /** - * Check for SHA1 string validity - * - * @param string $sha1 SHA1 string to validate - * @return boolean Validity is ok or not - */ + * Check for SHA1 string validity + * + * @param string $sha1 SHA1 string to validate + * @return boolean Validity is ok or not + */ public static function isSha1($sha1) { return preg_match('/^[a-fA-F0-9]{40}$/', $sha1); } /** - * Check for a float number validity - * - * @param float $float Float number to validate - * @return boolean Validity is ok or not - */ - public static function isFloat($float) - { - return strval((float)($float)) == strval($float); + * Check for a float number validity + * + * @param float $float Float number to validate + * @return boolean Validity is ok or not + */ + public static function isFloat($float) + { + return strval((float)$float) == strval($float); } - public static function isUnsignedFloat($float) - { - return strval((float)$float) == strval($float) && $float >= 0; + public static function isUnsignedFloat($float) + { + return strval((float)$float) == strval($float) && $float >= 0; } /** - * Check for a float number validity - * - * @param float $float Float number to validate - * @return boolean Validity is ok or not - */ - public static function isOptFloat($float) - { + * Check for a float number validity + * + * @param float $float Float number to validate + * @return boolean Validity is ok or not + */ + public static function isOptFloat($float) + { return empty($float) || Validate::isFloat($float); } /** - * Check for a carrier name validity - * - * @param string $name Carrier name to validate - * @return boolean Validity is ok or not - */ + * Check for a carrier name validity + * + * @param string $name Carrier name to validate + * @return boolean Validity is ok or not + */ public static function isCarrierName($name) { - return empty($name) OR preg_match('/^[^<>;=#{}]*$/u', $name); + return empty($name) || preg_match('/^[^<>;=#{}]*$/u', $name); } /** - * Check for an image size validity - * - * @param string $size Image size to validate - * @return boolean Validity is ok or not - */ + * Check for an image size validity + * + * @param string $size Image size to validate + * @return boolean Validity is ok or not + */ public static function isImageSize($size) { return preg_match('/^[0-9]{1,4}$/', $size); } /** - * Check for name validity - * - * @param string $name Name to validate - * @return boolean Validity is ok or not - */ + * Check for name validity + * + * @param string $name Name to validate + * @return boolean Validity is ok or not + */ public static function isName($name) { return preg_match('/^[^0-9!<>,;?=+()@#"°{}_$%:]*$/u', stripslashes($name)); } /** - * Check for hook name validity - * - * @param string $hook Hook name to validate - * @return boolean Validity is ok or not - */ + * Check for hook name validity + * + * @param string $hook Hook name to validate + * @return boolean Validity is ok or not + */ public static function isHookName($hook) { return preg_match('/^[a-zA-Z0-9_-]+$/', $hook); } /** - * Check for sender name validity - * - * @param string $mailName Sender name to validate - * @return boolean Validity is ok or not - */ - public static function isMailName($mailName) + * Check for sender name validity + * + * @param string $mail_name Sender name to validate + * @return boolean Validity is ok or not + */ + public static function isMailName($mail_name) { - return preg_match('/^[^<>;=#{}]*$/u', $mailName); + return preg_match('/^[^<>;=#{}]*$/u', $mail_name); } /** - * Check for e-mail subject validity - * - * @param string $mailSubject e-mail subject to validate - * @return boolean Validity is ok or not - */ - public static function isMailSubject($mailSubject) + * Check for e-mail subject validity + * + * @param string $mail_subject e-mail subject to validate + * @return boolean Validity is ok or not + */ + public static function isMailSubject($mail_subject) { - return preg_match('/^[^<>]*$/u', $mailSubject); + return preg_match('/^[^<>]*$/u', $mail_subject); } /** - * Check for module name validity - * - * @param string $moduleName Module name to validate - * @return boolean Validity is ok or not - */ - public static function isModuleName($moduleName) + * Check for module name validity + * + * @param string $module_name Module name to validate + * @return boolean Validity is ok or not + */ + public static function isModuleName($module_name) { - return preg_match('/^[a-zA-Z0-9_-]+$/', $moduleName); + return preg_match('/^[a-zA-Z0-9_-]+$/', $module_name); } /** - * Check for template name validity - * - * @param string $tplName Template name to validate - * @return boolean Validity is ok or not - */ - public static function isTplName($tplName) + * Check for template name validity + * + * @param string $tpl_name Template name to validate + * @return boolean Validity is ok or not + */ + public static function isTplName($tpl_name) { - return preg_match('/^[a-zA-Z0-9_-]+$/', $tplName); + return preg_match('/^[a-zA-Z0-9_-]+$/', $tpl_name); } /** - * Check for image type name validity - * - * @param string $type Image type name to validate - * @return boolean Validity is ok or not - */ + * Check for image type name validity + * + * @param string $type Image type name to validate + * @return boolean Validity is ok or not + */ public static function isImageTypeName($type) { return preg_match('/^[a-zA-Z0-9_ -]+$/', $type); } /** - * Check for price validity - * - * @param string $price Price to validate - * @return boolean Validity is ok or not - */ + * Check for price validity + * + * @param string $price Price to validate + * @return boolean Validity is ok or not + */ public static function isPrice($price) { return preg_match('/^[0-9]{1,10}(\.[0-9]{1,9})?$/', $price); } /** - * Check for language code (ISO) validity - * - * @param string $isoCode Language code (ISO) to validate - * @return boolean Validity is ok or not - */ - public static function isLanguageIsoCode($isoCode) + * Check for language code (ISO) validity + * + * @param string $iso_code Language code (ISO) to validate + * @return boolean Validity is ok or not + */ + public static function isLanguageIsoCode($iso_code) { - return preg_match('/^[a-zA-Z]{2,3}$/', $isoCode); + return preg_match('/^[a-zA-Z]{2,3}$/', $iso_code); } public static function isLanguageCode($s) @@ -249,144 +249,146 @@ class ValidateCore return preg_match('/^[a-zA-Z]{2}(-[a-zA-Z]{2})?$/', $s); } - public static function isStateIsoCode($isoCode) + public static function isStateIsoCode($iso_code) { - return preg_match('/^[a-zA-Z0-9]{1,3}((-)[a-zA-Z0-9]{1,3})?$/', $isoCode); + return preg_match('/^[a-zA-Z0-9]{1,3}((-)[a-zA-Z0-9]{1,3})?$/', $iso_code); } - public static function isNumericIsoCode($isoCode) + public static function isNumericIsoCode($iso_code) { - return preg_match('/^[0-9]{2,3}$/', $isoCode); + return preg_match('/^[0-9]{2,3}$/', $iso_code); } /** - * Check for voucher name validity - * - * @param string $voucher voucher to validate - * @return boolean Validity is ok or not - */ + * Check for voucher name validity + * + * @param string $voucher voucher to validate + * @return boolean Validity is ok or not + */ public static function isDiscountName($voucher) { return preg_match('/^[^!<>,;?=+()@"°{}_$%:]{3,32}$/u', $voucher); } /** - * Check for product or category name validity - * - * @param string $name Product or category name to validate - * @return boolean Validity is ok or not - */ + * Check for product or category name validity + * + * @param string $name Product or category name to validate + * @return boolean Validity is ok or not + */ public static function isCatalogName($name) { return preg_match('/^[^<>;=#{}]*$/u', $name); } /** - * Check for a message validity - * - * @param string $message Message to validate - * @return boolean Validity is ok or not - */ + * Check for a message validity + * + * @param string $message Message to validate + * @return boolean Validity is ok or not + */ public static function isMessage($message) { return !preg_match('/[<>{}]/i', $message); } /** - * Check for a country name validity - * - * @param string $name Country name to validate - * @return boolean Validity is ok or not - */ + * Check for a country name validity + * + * @param string $name Country name to validate + * @return boolean Validity is ok or not + */ public static function isCountryName($name) { return preg_match('/^[a-zA-Z -]+$/', $name); } /** - * Check for a link (url-rewriting only) validity - * - * @param string $link Link to validate - * @return boolean Validity is ok or not - */ + * Check for a link (url-rewriting only) validity + * + * @param string $link Link to validate + * @return boolean Validity is ok or not + */ public static function isLinkRewrite($link) { return preg_match('/^[_a-zA-Z0-9\-\pL]+$/u', $link); } /** - * Check for a postal address validity - * - * @param string $address Address to validate - * @return boolean Validity is ok or not - */ + * Check for a postal address validity + * + * @param string $address Address to validate + * @return boolean Validity is ok or not + */ public static function isAddress($address) { return empty($address) || preg_match('/^[^!<>?=+@{}_$%]*$/u', $address); } /** - * Check for city name validity - * - * @param string $city City name to validate - * @return boolean Validity is ok or not - */ + * Check for city name validity + * + * @param string $city City name to validate + * @return boolean Validity is ok or not + */ public static function isCityName($city) { return preg_match('/^[^!<>;?=+@#"°{}_$%]*$/u', $city); } /** - * Check for search query validity - * - * @param string $search Query to validate - * @return boolean Validity is ok or not - */ + * Check for search query validity + * + * @param string $search Query to validate + * @return boolean Validity is ok or not + */ public static function isValidSearch($search) { return preg_match('/^[^<>;=#{}]{0,64}$/u', $search); } /** - * Check for standard name validity - * - * @param string $name Name to validate - * @return boolean Validity is ok or not - */ + * Check for standard name validity + * + * @param string $name Name to validate + * @return boolean Validity is ok or not + */ public static function isGenericName($name) { - return empty($name) OR preg_match('/^[^<>;=#{}]*$/u', $name); + return empty($name) || preg_match('/^[^<>;=#{}]*$/u', $name); } /** - * Check for HTML field validity (no XSS please !) - * - * @param string $html HTML field to validate - * @return boolean Validity is ok or not - */ + * Check for HTML field validity (no XSS please !) + * + * @param string $html HTML field to validate + * @return boolean Validity is ok or not + */ public static function isCleanHtml($html) { - $jsEvent = 'onmousedown|onmousemove|onmmouseup|onmouseover|onmouseout|onload|onunload|onfocus|onblur|onchange|onsubmit|ondblclick|onclick|onkeydown|onkeyup|onkeypress|onmouseenter|onmouseleave|onerror'; - return (!preg_match('/<[ \t\n]*script/i', $html) && !preg_match('/;={}]*$/u', $reference); } /** - * Check for password validity - * - * @param string $passwd Password to validate - * @return boolean Validity is ok or not - */ + * Check for password validity + * + * @param string $passwd Password to validate + * @param int $size + * @return boolean Validity is ok or not + */ public static function isPasswd($passwd, $size = 5) { return preg_match('/^[.a-zA-Z_0-9-!@#$%\^&*()]{'.(int)$size.',32}$/', $passwd); @@ -398,45 +400,46 @@ class ValidateCore } /** - * Check for configuration key validity - * - * @param string $configName Configuration key to validate - * @return boolean Validity is ok or not - */ - public static function isConfigName($configName) + * Check for configuration key validity + * + * @param string $config_name Configuration key to validate + * @return boolean Validity is ok or not + */ + public static function isConfigName($config_name) { - return preg_match('/^[a-zA-Z_0-9-]+$/', $configName); + return preg_match('/^[a-zA-Z_0-9-]+$/', $config_name); } /** - * Check date formats like http://php.net/manual/en/function.date.php - * - * @param string $date_format date format to check - * @return boolean Validity is ok or not - */ + * Check date formats like http://php.net/manual/en/function.date.php + * + * @param string $date_format date format to check + * @return boolean Validity is ok or not + */ public static function isPhpDateFormat($date_format) { - // We can't really check if this is valid or not, because this is a string and you can write whatever you want in it. That's why only < et > are forbidden (HTML) + // We can't really check if this is valid or not, because this is a string and you can write whatever you want in it. + // That's why only < et > are forbidden (HTML) return preg_match('/^[^<>]+$/', $date_format); } /** - * Check for date format - * - * @param string $date Date to validate - * @return boolean Validity is ok or not - */ + * Check for date format + * + * @param string $date Date to validate + * @return boolean Validity is ok or not + */ public static function isDateFormat($date) { return (bool)preg_match('/^([0-9]{4})-((0?[0-9])|(1[0-2]))-((0?[0-9])|([1-2][0-9])|(3[01]))( [0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $date); } /** - * Check for date validity - * - * @param string $date Date to validate - * @return boolean Validity is ok or not - */ + * Check for date validity + * + * @param string $date Date to validate + * @return boolean Validity is ok or not + */ public static function isDate($date) { if (!preg_match('/^([0-9]{4})-((0?[0-9])|(1[0-2]))-((0?[0-9])|([1-2][0-9])|(3[01]))( [0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $date, $matches)) @@ -445,84 +448,85 @@ class ValidateCore } /** - * Check for birthDate validity - * - * @param string $date birthdate to validate - * @return boolean Validity is ok or not - */ + * Check for birthDate validity + * + * @param string $date birthdate to validate + * @return boolean Validity is ok or not + */ public static function isBirthDate($date) { - if (empty($date) || $date == '0000-00-00') - return true; - if (preg_match('/^([0-9]{4})-((0?[1-9])|(1[0-2]))-((0?[1-9])|([1-2][0-9])|(3[01]))( [0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $date, $birthDate)) { - if ($birthDate[1] >= date('Y') - 9) - return false; - return true; - } + if (empty($date) || $date == '0000-00-00') + return true; + if (preg_match('/^([0-9]{4})-((0?[1-9])|(1[0-2]))-((0?[1-9])|([1-2][0-9])|(3[01]))( [0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $date, $birth_date)) + { + if ($birth_date[1] >= date('Y') - 9) + return false; + return true; + } return false; } /** - * Check for boolean validity - * - * @param boolean $bool Boolean to validate - * @return boolean Validity is ok or not - */ + * Check for boolean validity + * + * @param boolean $bool Boolean to validate + * @return boolean Validity is ok or not + */ public static function isBool($bool) { - return is_null($bool) OR is_bool($bool) OR preg_match('/^0|1$/', $bool); + return is_null($bool) || is_bool($bool) || preg_match('/^0|1$/', $bool); } /** - * Check for phone number validity - * - * @param string $phoneNumber Phone number to validate - * @return boolean Validity is ok or not - */ - public static function isPhoneNumber($phoneNumber) + * Check for phone number validity + * + * @param string $number Phone number to validate + * @return boolean Validity is ok or not + */ + public static function isPhoneNumber($number) { - return preg_match('/^[+0-9. ()-]*$/', $phoneNumber); + return preg_match('/^[+0-9. ()-]*$/', $number); } /** - * Check for barcode validity (EAN-13) - * - * @param string $ean13 Barcode to validate - * @return boolean Validity is ok or not - */ + * Check for barcode validity (EAN-13) + * + * @param string $ean13 Barcode to validate + * @return boolean Validity is ok or not + */ public static function isEan13($ean13) { - return !$ean13 OR preg_match('/^[0-9]{0,13}$/', $ean13); + return !$ean13 || preg_match('/^[0-9]{0,13}$/', $ean13); } /** - * Check for barcode validity (UPC) - * - * @param string $upc Barcode to validate - * @return boolean Validity is ok or not - */ + * Check for barcode validity (UPC) + * + * @param string $upc Barcode to validate + * @return boolean Validity is ok or not + */ public static function isUpc($upc) { - return !$upc OR preg_match('/^[0-9]{0,12}$/', $upc); + return !$upc || preg_match('/^[0-9]{0,12}$/', $upc); } /** - * Check for postal code validity - * - * @param string $postcode Postal code to validate - * @return boolean Validity is ok or not - */ + * Check for postal code validity + * + * @param string $postcode Postal code to validate + * @return boolean Validity is ok or not + */ public static function isPostCode($postcode) { - return empty($postcode) OR preg_match('/^[a-zA-Z 0-9-]+$/', $postcode); + return empty($postcode) || preg_match('/^[a-zA-Z 0-9-]+$/', $postcode); } /** - * Check for zip code format validity - * - * @param string $zip_code zip code format to validate - * @return boolean Validity is ok or not - */ + * Check for zip code format validity + * + * @param string $zip_code zip code format to validate + * @return boolean Validity is ok or not + */ public static function isZipCodeFormat($zip_code) { if (!empty($zip_code)) @@ -531,95 +535,96 @@ class ValidateCore } /** - * Check for table or identifier validity - * Mostly used in database for ordering : ASC / DESC - * - * @param string $orderWay Keyword to validate - * @return boolean Validity is ok or not - */ - public static function isOrderWay($orderWay) + * Check for table or identifier validity + * Mostly used in database for ordering : ASC / DESC + * + * @param string $way Keyword to validate + * @return boolean Validity is ok or not + */ + public static function isOrderWay($way) { - return ($orderWay === 'ASC' | $orderWay === 'DESC' | $orderWay === 'asc' | $orderWay === 'desc'); + return ($way === 'ASC' | $way === 'DESC' | $way === 'asc' | $way === 'desc'); } /** - * Check for table or identifier validity - * Mostly used in database for ordering : ORDER BY field - * - * @param string $orderBy Field to validate - * @return boolean Validity is ok or not - */ - public static function isOrderBy($orderBy) + * Check for table or identifier validity + * Mostly used in database for ordering : ORDER BY field + * + * @param string $order Field to validate + * @return boolean Validity is ok or not + */ + public static function isOrderBy($order) { - return preg_match('/^[a-zA-Z0-9_-]+$/', $orderBy); + return preg_match('/^[a-zA-Z0-9_-]+$/', $order); } /** - * Check for table or identifier validity - * Mostly used in database for table names and id_table - * - * @param string $table Table/identifier to validate - * @return boolean Validity is ok or not - */ + * Check for table or identifier validity + * Mostly used in database for table names and id_table + * + * @param string $table Table/identifier to validate + * @return boolean Validity is ok or not + */ public static function isTableOrIdentifier($table) { return preg_match('/^[a-zA-Z0-9_-]+$/', $table); } /** - * Check for values list validity - * Mostly used in database for insertions (A,B,C),(A,B,C)... - * - * @param string $list List to validate - * @return boolean Validity is ok or not - */ - public static function isValuesList($list) + * Check for values list validity + * Mostly used in database for insertions (A,B,C),(A,B,C)... + * + * @deprecated + * @return boolean Validity is ok or not + */ + public static function isValuesList() { + Tools::displayAsDeprecated(); return true; /* For history reason, we keep this line */ // return preg_match('/^[0-9,\'(). NULL]+$/', $list); } /** - * Check for tags list validity - * - * @param string $list List to validate - * @return boolean Validity is ok or not - */ + * Check for tags list validity + * + * @param string $list List to validate + * @return boolean Validity is ok or not + */ public static function isTagsList($list) { return preg_match('/^[^!<>;?=+#"°{}_$%]*$/u', $list); } /** - * Check for an integer validity - * - * @param integer $id Integer to validate - * @return boolean Validity is ok or not - */ + * Check for an integer validity + * + * @param integer $id Integer to validate + * @return boolean Validity is ok or not + */ public static function isInt($value) { return ((string)(int)$value === (string)$value || $value === false); } /** - * Check for an integer validity (unsigned) - * - * @param integer $id Integer to validate - * @return boolean Validity is ok or not - */ + * Check for an integer validity (unsigned) + * + * @param integer $id Integer to validate + * @return boolean Validity is ok or not + */ public static function isUnsignedInt($value) { return (preg_match('#^[0-9]+$#', (string)$value) && $value < 4294967296 && $value >= 0); } /** - * Check for an integer validity (unsigned) - * Mostly used in database for auto-increment - * - * @param integer $id Integer to validate - * @return boolean Validity is ok or not - */ + * Check for an integer validity (unsigned) + * Mostly used in database for auto-increment + * + * @param integer $id Integer to validate + * @return boolean Validity is ok or not + */ public static function isUnsignedId($id) { return Validate::isUnsignedInt($id); /* Because an id could be equal to zero when there is no association */ @@ -631,55 +636,55 @@ class ValidateCore } /** - * Check object validity - * - * @param object $object Object to validate - * @return boolean Validity is ok or not - */ + * Check object validity + * + * @param object $object Object to validate + * @return boolean Validity is ok or not + */ public static function isLoadedObject($object) { return is_object($object) && $object->id; } /** - * Check object validity - * - * @param integer $object Object to validate - * @return boolean Validity is ok or not - */ + * Check object validity + * + * @param integer $object Object to validate + * @return boolean Validity is ok or not + */ public static function isColor($color) { return preg_match('/^(#[0-9a-fA-F]{6}|[a-zA-Z0-9-]*)$/', $color); } /** - * Check url valdity (disallowed empty string) - * - * @param string $url Url to validate - * @return boolean Validity is ok or not - */ + * Check url valdity (disallowed empty string) + * + * @param string $url Url to validate + * @return boolean Validity is ok or not + */ public static function isUrl($url) { return preg_match('/^[~:#,%&_=\(\)\.\? \+\-@\/a-zA-Z0-9]+$/', $url); } /** - * Check url validity (allowed empty string) - * - * @param string $url Url to validate - * @return boolean Validity is ok or not - */ + * Check url validity (allowed empty string) + * + * @param string $url Url to validate + * @return boolean Validity is ok or not + */ public static function isUrlOrEmpty($url) { return empty($url) || Validate::isUrl($url); } /** - * Check object validity - * - * @param integer $object Object to validate - * @return boolean Validity is ok or not - */ + * Check if URL is absolute + * + * @param string $url URL to validate + * @return boolean Validity is ok or not + */ public static function isAbsoluteUrl($url) { if (!empty($url)) @@ -704,21 +709,21 @@ class ValidateCore } /** - * Check for standard name file validity - * - * @param string $name Name to validate - * @return boolean Validity is ok or not - */ + * Check for standard name file validity + * + * @param string $name Name to validate + * @return boolean Validity is ok or not + */ public static function isFileName($name) { return preg_match('/^[a-zA-Z0-9_.-]*$/', $name); } - + /** * Check for standard name directory validity * - * @param string $name Name to validate - * @return boolean Validity is ok or not + * @param string $dir Directory to validate + * @return boolean Validity is ok or not */ public static function isDirName($dir) { @@ -726,11 +731,11 @@ class ValidateCore } /** - * Check for admin panel tab name validity - * - * @param string $name Name to validate - * @return boolean Validity is ok or not - */ + * Check for admin panel tab name validity + * + * @param string $name Name to validate + * @return boolean Validity is ok or not + */ public static function isTabName($name) { return preg_match('/^[a-zA-Z0-9_-]*$/', $name); @@ -746,9 +751,9 @@ class ValidateCore return preg_match('/^[a-zA-Z]{1,2}$/', $unit); } - public static function isSubDomainName($subDomainName) + public static function isSubDomainName($domain) { - return preg_match('/^[a-zA-Z0-9-_]*$/', $subDomainName); + return preg_match('/^[a-zA-Z0-9-_]*$/', $domain); } public static function isVoucherDescription($text) @@ -757,33 +762,33 @@ class ValidateCore } /** - * Check if the value is a sort direction value (DESC/ASC) - * - * @param char $value - * @return boolean Validity is ok or not - */ - public static function IsSortDirection($value) + * Check if the value is a sort direction value (DESC/ASC) + * + * @param char $value + * @return boolean Validity is ok or not + */ + public static function isSortDirection($value) { return (!is_null($value) && ($value === 'ASC' || $value === 'DESC')); } /** - * Customization fields' label validity - * - * @param integer $object Object to validate - * @return boolean Validity is ok or not - */ + * Customization fields' label validity + * + * @param string $label + * @return boolean Validity is ok or not + */ public static function isLabel($label) { return (preg_match('/^[^{}<>]*$/u', $label)); } /** - * Price display method validity - * - * @param integer $data Data to validate - * @return boolean Validity is ok or not - */ + * Price display method validity + * + * @param integer $data Data to validate + * @return boolean Validity is ok or not + */ public static function isPriceDisplayMethod($data) { return ($data == PS_TAX_EXC || $data == PS_TAX_INC); @@ -810,88 +815,97 @@ class ValidateCore } /** - * Price display method validity - * - * @param string $data Data to validate - * @return boolean Validity is ok or not - */ + * Price display method validity + * + * @param string $data Data to validate + * @return boolean Validity is ok or not + */ public static function isString($data) { return is_string($data); } /** - * Check if the data is a reduction type (amout or percentage) - * - * @param string $data Data to validate - * @return boolean Validity is ok or not - */ + * Check if the data is a reduction type (amout or percentage) + * + * @param string $data Data to validate + * @return boolean Validity is ok or not + */ public static function isReductionType($data) { return ($data === 'amount' || $data === 'percentage'); } /** - * Check for bool_id - * - * @param string $ids - * @return boolean Validity is ok or not - */ - public static function isBool_Id($ids) + * Check for bool_id + * + * @param string $ids + * @return boolean Validity is ok or not + */ + public static function isBoolId($ids) { return (bool)preg_match('#^[01]_[0-9]+$#', $ids); } /** - * Check the localization pack part selected - * - * @param string $data Localization pack to check - * @return boolean Validity is ok or not - */ - public static function isLocalizationPackSelection($data) + * @deprecated 1.5.0 + */ + public static function isBool_Id($ids) { - return ($data === 'states' OR $data === 'taxes' OR $data === 'currencies' OR $data === 'languages' OR $data === 'units'); + Tools::displayAsDeprecated(); + return Validate::isBoolId($ids); } /** - * Check for PHP serialized data - * - * @param string $data Serialized data to validate - * @return boolean Validity is ok or not - */ + * Check the localization pack part selected + * + * @param string $data Localization pack to check + * @return boolean Validity is ok or not + */ + public static function isLocalizationPackSelection($data) + { + return ($data === 'states' || $data === 'taxes' || $data === 'currencies' || $data === 'languages' || $data === 'units'); + } + + /** + * Check for PHP serialized data + * + * @param string $data Serialized data to validate + * @return boolean Validity is ok or not + */ public static function isSerializedArray($data) { return is_null($data) || (is_string($data) && preg_match('/^a:[0-9]+:{.*;}$/s', $data)); } /** - * Check for Latitude/Longitude - * - * @param string $data Coordinate to validate - * @return boolean Validity is ok or not - */ + * Check for Latitude/Longitude + * + * @param string $data Coordinate to validate + * @return boolean Validity is ok or not + */ public static function isCoordinate($data) { return is_null($data) || preg_match('/^\-?[0-9]{1,8}\.[0-9]{1,8}$/s', $data); } /** - * Check for Language Iso Code - * - * @param string $iso_code - * @return boolean Validity is ok or not - */ + * Check for Language Iso Code + * + * @param string $iso_code + * @return boolean Validity is ok or not + */ public static function isLangIsoCode($iso_code) { return (bool)preg_match('/^[a-zA-Z]{2,3}$/s', $iso_code); } /** - * Check for Language File Name - * - * @param string $file_name - * @return boolean Validity is ok or not - */ + * Check for Language File Name + * + * @param string $file_name + * @return boolean Validity is ok or not + */ public static function isLanguageFileName($file_name) { return (bool)preg_match('/^[a-zA-Z]{2,3}\.gzip$/s', $file_name); @@ -957,7 +971,8 @@ class ValidateCore if (Tools::strlen($siret) != 14) return false; $sum = 0; - for($i=0; $i != 14; $i++) { + for ($i = 0; $i != 14; $i++) + { $tmp = ((($i + 1) % 2) + 1) * intval($siret[$i]); if ($tmp >= 10) $tmp -= 9; diff --git a/modules/statsbestcategories/statsbestcategories.php b/modules/statsbestcategories/statsbestcategories.php index 10fd2b799..d92c762f0 100644 --- a/modules/statsbestcategories/statsbestcategories.php +++ b/modules/statsbestcategories/statsbestcategories.php @@ -194,7 +194,7 @@ class StatsBestCategories extends ModuleGrid if (Validate::IsName($this->_sort)) { $this->_query .= ' ORDER BY `'.$this->_sort.'`'; - if (isset($this->_direction) && Validate::IsSortDirection($this->_direction)) + if (isset($this->_direction) && Validate::isSortDirection($this->_direction)) $this->_query .= ' '.$this->_direction; } if (($this->_start === 0 || Validate::IsUnsignedInt($this->_start)) && Validate::IsUnsignedInt($this->_limit)) diff --git a/modules/statsbestcustomers/statsbestcustomers.php b/modules/statsbestcustomers/statsbestcustomers.php index fb2ad269a..c3971e0fa 100644 --- a/modules/statsbestcustomers/statsbestcustomers.php +++ b/modules/statsbestcustomers/statsbestcustomers.php @@ -153,7 +153,7 @@ class StatsBestCustomers extends ModuleGrid if (Validate::IsName($this->_sort)) { $this->_query .= ' ORDER BY `'.$this->_sort.'`'; - if (isset($this->_direction) && Validate::IsSortDirection($this->_direction)) + if (isset($this->_direction) && Validate::isSortDirection($this->_direction)) $this->_query .= ' '.$this->_direction; } if (($this->_start === 0 || Validate::IsUnsignedInt($this->_start)) && Validate::IsUnsignedInt($this->_limit)) diff --git a/modules/statsbestmanufacturers/statsbestmanufacturers.php b/modules/statsbestmanufacturers/statsbestmanufacturers.php index 771df0f89..47877b789 100755 --- a/modules/statsbestmanufacturers/statsbestmanufacturers.php +++ b/modules/statsbestmanufacturers/statsbestmanufacturers.php @@ -141,7 +141,7 @@ class StatsBestManufacturers extends ModuleGrid if (Validate::IsName($this->_sort)) { $this->_query .= ' ORDER BY `'.$this->_sort.'`'; - if (isset($this->_direction) && Validate::IsSortDirection($this->_direction)) + if (isset($this->_direction) && Validate::isSortDirection($this->_direction)) $this->_query .= ' '.$this->_direction; } if (($this->_start === 0 || Validate::IsUnsignedInt($this->_start)) && Validate::IsUnsignedInt($this->_limit)) diff --git a/modules/statsbestproducts/statsbestproducts.php b/modules/statsbestproducts/statsbestproducts.php index cd12f8c0f..ef1844c97 100644 --- a/modules/statsbestproducts/statsbestproducts.php +++ b/modules/statsbestproducts/statsbestproducts.php @@ -178,7 +178,7 @@ class StatsBestProducts extends ModuleGrid if (Validate::IsName($this->_sort)) { $this->_query .= ' ORDER BY `'.$this->_sort.'`'; - if (isset($this->_direction) && Validate::IsSortDirection($this->_direction)) + if (isset($this->_direction) && Validate::isSortDirection($this->_direction)) $this->_query .= ' '.$this->_direction; } diff --git a/modules/statsbestsuppliers/statsbestsuppliers.php b/modules/statsbestsuppliers/statsbestsuppliers.php index a8b6bc10e..383b5b0f4 100644 --- a/modules/statsbestsuppliers/statsbestsuppliers.php +++ b/modules/statsbestsuppliers/statsbestsuppliers.php @@ -142,7 +142,7 @@ class StatsBestSuppliers extends ModuleGrid if (Validate::IsName($this->_sort)) { $this->_query .= ' ORDER BY `'.$this->_sort.'`'; - if (isset($this->_direction) && Validate::IsSortDirection($this->_direction)) + if (isset($this->_direction) && Validate::isSortDirection($this->_direction)) $this->_query .= ' '.$this->_direction; }