| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
-*/
+ */
/**
*
*
* @return bool
*/
- static function title($str, $maxLength = 127) {
+ public static function title($str, $maxLength = 127) {
// check length etc
if (empty($str) || strlen($str) > $maxLength) {
*
* @return bool
*/
- static function longTitle($str) {
+ public static function longTitle($str) {
return self::title($str, 255);
}
*
* @return bool
*/
- static function variable($str) {
+ public static function variable($str) {
// check length etc
if (empty($str) || strlen($str) > 31) {
return FALSE;
*
* @return bool
*/
- static function qfVariable($str) {
+ public static function qfVariable($str) {
// check length etc
//if ( empty( $str ) || strlen( $str ) > 31 ) {
if (strlen(trim($str)) == 0 || strlen($str) > 31) {
*
* @return bool
*/
- static function phone($phone) {
+ public static function phone($phone) {
// check length etc
if (empty($phone) || strlen($phone) > 16) {
return FALSE;
*
* @return bool
*/
- static function query($query) {
+ public static function query($query) {
// check length etc
if (empty($query) || strlen($query) < 3 || strlen($query) > 127) {
return FALSE;
*
* @return bool
*/
- static function url($url) {
+ public static function url($url) {
if (preg_match('/^\//', $url)) {
// allow relative URL's (CRM-15598)
$url = 'http://' . $_SERVER['HTTP_HOST'] . $url;
*
* @return bool
*/
- static function wikiURL($string) {
+ public static function wikiURL($string) {
$items = explode(' ', trim($string), 2);
return self::url($items[0]);
}
*
* @return bool
*/
- static function domain($domain) {
+ public static function domain($domain) {
// not perfect, but better than the previous one; see CRM-1502
if (!preg_match('/^[A-Za-z0-9]([A-Za-z0-9\.\-]*[A-Za-z0-9])?$/', $domain)) {
return FALSE;
*
* @return null
*/
- static function date($value, $default = NULL) {
+ public static function date($value, $default = NULL) {
if (is_string($value) &&
preg_match('/^\d\d\d\d-?\d\d-?\d\d$/', $value)
) {
*
* @return null|string
*/
- static function dateTime($value, $default = NULL) {
+ public static function dateTime($value, $default = NULL) {
$result = $default;
if (is_string($value) &&
preg_match('/^\d\d\d\d-?\d\d-?\d\d(\s\d\d:\d\d(:\d\d)?|\d\d\d\d(\d\d)?)?$/', $value)
* specified has to be beyond today. (i.e today or later)
*
* @param array $date
- * @param bool $monthRequired check whether month is mandatory
+ * @param bool $monthRequired
+ * Check whether month is mandatory.
*
- * @return bool true if valid date
- * @static
- * @access public
+ * @return bool
+ * true if valid date
*/
- static function currentDate($date, $monthRequired = TRUE) {
+ public static function currentDate($date, $monthRequired = TRUE) {
$config = CRM_Core_Config::singleton();
$d = CRM_Utils_Array::value('d', $date);
*
* @param string $date
*
- * @return bool true if valid date
- * @static
- * @access public
+ * @return bool
+ * true if valid date
*/
- static function mysqlDate($date) {
+ public static function mysqlDate($date) {
// allow date to be null
if ($date == NULL) {
return TRUE;
*
* @return bool
*/
- static function integer($value) {
+ public static function integer($value) {
if (is_int($value)) {
return TRUE;
}
*
* @return bool
*/
- static function positiveInteger($value) {
+ public static function positiveInteger($value) {
if (is_int($value)) {
return ($value < 0) ? FALSE : TRUE;
}
*
* @return bool
*/
- static function numeric($value) {
+ public static function numeric($value) {
// lets use a php gatekeeper to ensure this is numeric
if (!is_numeric($value)) {
return FALSE;
*
* @return bool
*/
- static function numberOfDigit($value, $noOfDigit) {
+ public static function numberOfDigit($value, $noOfDigit) {
return preg_match('/^\d{' . $noOfDigit . '}$/', $value) ? TRUE : FALSE;
}
*
* @return mixed
*/
- static function cleanMoney($value) {
+ public static function cleanMoney($value) {
// first remove all white space
$value = str_replace(array(' ', "\t", "\n"), '', $value);
$config = CRM_Core_Config::singleton();
- //CRM-14868
+ //CRM-14868
$currencySymbols = CRM_Core_PseudoConstant::get(
- 'CRM_Contribute_DAO_Contribution',
- 'currency', array(
- 'keyColumn' => 'name',
- 'labelColumn' => 'symbol'
- ));
- $value = str_replace($currencySymbols,'',$value);
+ 'CRM_Contribute_DAO_Contribution',
+ 'currency', array(
+ 'keyColumn' => 'name',
+ 'labelColumn' => 'symbol',
+ )
+ );
+ $value = str_replace($currencySymbols, '', $value);
if ($config->monetaryThousandSeparator) {
$mon_thousands_sep = $config->monetaryThousandSeparator;
// ugly fix for CRM-6391: do not drop the thousand separator if
// it looks like it’s separating decimal part (because a given
// value undergoes a second cleanMoney() call, for example)
- if ($mon_thousands_sep != '.' or substr($value, -3, 1) != '.') {
+ // CRM-15835 - in case the amount/value contains 0 after decimal
+ // eg 150.5 the following if condition will pass
+ if ($mon_thousands_sep != '.' or (substr($value, -3, 1) != '.' && substr($value, -2, 1) != '.')) {
$value = str_replace($mon_thousands_sep, '', $value);
}
*
* @return bool
*/
- static function money($value) {
+ public static function money($value) {
$config = CRM_Core_Config::singleton();
//only edge case when we have a decimal point in the input money
*
* @return bool
*/
- static function string($value, $maxLength = 0) {
+ public static function string($value, $maxLength = 0) {
if (is_string($value) &&
($maxLength === 0 || strlen($value) <= $maxLength)
) {
*
* @return bool
*/
- static function boolean($value) {
+ public static function boolean($value) {
return preg_match(
'/(^(1|0)$)|(^(Y(es)?|N(o)?)$)|(^(T(rue)?|F(alse)?)$)/i', $value
) ? TRUE : FALSE;
*
* @return bool
*/
- static function email($value) {
+ public static function email($value) {
return (bool) filter_var($value, FILTER_VALIDATE_EMAIL);
}
*
* @return bool
*/
- static function emailList($list) {
+ public static function emailList($list) {
$emails = explode(',', $list);
foreach ($emails as $email) {
$email = trim($email);
return TRUE;
}
- // allow between 4-6 digits as postal code since india needs 6 and US needs 5 (or
- // if u disregard the first 0, 4 (thanx excel!)
- // FIXME: we need to figure out how to localize such rules
/**
+ * allow between 4-6 digits as postal code since india needs 6 and US needs 5 (or
+ * if u disregard the first 0, 4 (thanx excel!)
+ * FIXME: we need to figure out how to localize such rules
* @param $value
*
* @return bool
*/
- static function postalCode($value) {
+ public static function postalCode($value) {
if (preg_match('/^\d{4,6}(-\d{4})?$/', $value)) {
return TRUE;
}
* See how file rules are written in HTML/QuickForm/file.php
* Checks to make sure the uploaded file is ascii
*
- * @param array Uploaded file info (from $_FILES)
- * @access private
- *
- * @return bool true if file has been uploaded, false otherwise
+ * @return bool
+ * true if file has been uploaded, false otherwise
*/
- static function asciiFile($elementValue) {
+ public static function asciiFile($elementValue) {
if ((isset($elementValue['error']) && $elementValue['error'] == 0) ||
(!empty($elementValue['tmp_name']) && $elementValue['tmp_name'] != 'none')
) {
/**
* Checks to make sure the uploaded file is in UTF-8, recodes if it's not
*
- * @param array Uploaded file info (from $_FILES)
- * @access private
- *
- * @return bool whether file has been uploaded properly and is now in UTF-8
+ * @return bool
+ * whether file has been uploaded properly and is now in UTF-8
*/
- static function utf8File($elementValue) {
+ public static function utf8File($elementValue) {
$success = FALSE;
if ((isset($elementValue['error']) && $elementValue['error'] == 0) ||
* See how file rules are written in HTML/QuickForm/file.php
* Checks to make sure the uploaded file is html
*
- * @param array Uploaded file info (from $_FILES)
- * @access private
- *
- * @return bool true if file has been uploaded, false otherwise
+ * @return bool
+ * true if file has been uploaded, false otherwise
*/
- static function htmlFile($elementValue) {
+ public static function htmlFile($elementValue) {
if ((isset($elementValue['error']) && $elementValue['error'] == 0) ||
(!empty($elementValue['tmp_name']) && $elementValue['tmp_name'] != 'none')
) {
}
/**
- * Check if there is a record with the same name in the db
+ * Check if there is a record with the same name in the db.
*
- * @param string $value the value of the field we are checking
- * @param array $options the daoName and fieldName (optional )
+ * @param string $value
+ * The value of the field we are checking.
+ * @param array $options
+ * The daoName and fieldName (optional ).
*
- * @return boolean true if object exists
- * @access public
- * @static
+ * @return bool
+ * true if object exists
*/
- static function objectExists($value, $options) {
+ public static function objectExists($value, $options) {
$name = 'name';
if (isset($options[2])) {
$name = $options[2];
*
* @return bool
*/
- static function optionExists($value, $options) {
+ public static function optionExists($value, $options) {
return CRM_Core_OptionValue::optionExists($value, $options[0], $options[1], $options[2], CRM_Utils_Array::value(3, $options, 'name'));
}
*
* @return bool
*/
- static function creditCardNumber($value, $type) {
+ public static function creditCardNumber($value, $type) {
require_once 'Validate/Finance/CreditCard.php';
return Validate_Finance_CreditCard::number($value, $type);
}
*
* @return bool
*/
- static function cvv($value, $type) {
+ public static function cvv($value, $type) {
require_once 'Validate/Finance/CreditCard.php';
return Validate_Finance_CreditCard::cvv($value, $type);
*
* @return bool
*/
- static function currencyCode($value) {
+ public static function currencyCode($value) {
static $currencyCodes = NULL;
if (!$currencyCodes) {
$currencyCodes = CRM_Core_PseudoConstant::currencyCode();
*
* @return bool
*/
- static function xssString($value) {
+ public static function xssString($value) {
if (is_string($value)) {
return preg_match('!<(vb)?script[^>]*>.*</(vb)?script.*>!ims',
$value
*
* @return bool
*/
- static function fileExists($path) {
+ public static function fileExists($path) {
return file_exists($path);
}
*
* @return bool
*/
- static function autocomplete($value, $options) {
+ public static function autocomplete($value, $options) {
if ($value) {
$selectOption = CRM_Core_BAO_CustomOption::valuesByID($options['fieldID'], $options['optionGroupID']);
*
* @return bool
*/
- static function validContact($value, $actualElementValue = NULL) {
+ public static function validContact($value, $actualElementValue = NULL) {
if ($actualElementValue) {
$value = $actualElementValue;
}
*
* @param array $date
*
- * @return bool true if valid date
- * @static
- * @access public
+ * @return bool
+ * true if valid date
*/
- static function qfDate($date) {
+ public static function qfDate($date) {
$config = CRM_Core_Config::singleton();
$d = CRM_Utils_Array::value('d', $date);
*
* @return bool
*/
- static function qfKey($key) {
+ public static function qfKey($key) {
return ($key) ? CRM_Core_Key::valid($key) : FALSE;
}
-}
+}