Esempio n. 1
0
 /**
  * Validates a file value.
  * 
  * @param string $value The value to validate.
  * 
  * @return bool|string Returns boolean TRUE upon successfull validation, and an error message string upon failure.
  */
 public function validate(&$value)
 {
     $required = get::array_def($this->attributes, 'required', false) == 'required';
     $multiple = get::array_def($this->attributes, 'multiple', false) == 'multiple';
     $msglbl = get::array_def($this->attributes, 'msglbl', get::array_def($this->attributes, 'name', $this->getId()));
     if ($required && (!isset($value) || $value['error'] == 4)) {
         return sprintf('"%s" is a required field.', $msglbl);
     }
     if (isset($value)) {
         if ($multiple) {
             foreach ($value as &$file) {
                 $err = $this->checkFileForError($file);
                 if ($err !== true) {
                     return $err;
                 }
             }
         } else {
             $err = $this->checkFileForError($value);
             if ($err !== true) {
                 return $err;
             }
         }
     }
     return true;
 }
Esempio n. 2
0
 /**
  * Validates a number value.
  * 
  * @param string $value The value to validate.
  * 
  * @return bool|string Returns boolean TRUE upon successfull validation, and an error message string upon failure.
  */
 public function validate(&$value)
 {
     $required = get::array_def($this->attributes, 'required', false) == 'required';
     $integeronly = get::array_def($this->attributes, 'integeronly', false, array(true, false));
     $msglbl = get::array_def($this->attributes, 'msglbl', get::array_def($this->attributes, 'name', $this->getId()));
     if ($required && (!isset($value) || strlen(trim($value)) < 1)) {
         return sprintf('"%s" is a required field.', $msglbl);
     }
     if (isset($value) && strlen(trim($value)) > 0) {
         $value = trim($value);
         $valid = $integeronly ? preg_match('/^[+-]?\\d+$/', $value) ? (int) $value : false : is::float($value);
         $errorText = $integeronly ? 'integer' : 'number';
         $min = get::array_def($this->attributes, 'min', null);
         $max = get::array_def($this->attributes, 'max', null);
         if ($valid === false) {
             return sprintf('"%s" is not a valid %s.', $msglbl, $errorText);
         } elseif (isset($min) && $valid < $min) {
             return sprintf('"%s" is not allowed to be less than %s.', $msglbl, $min);
         } elseif (isset($max) && $valid > $max) {
             return sprintf('"%s" is not allowed to be greater than %s.', $msglbl, $max);
         }
         $value = $valid;
     }
     return true;
 }
Esempio n. 3
0
 protected function run_query($sql, array $params = null)
 {
     $p = array('wt' => 'phps', 'q' => $sql);
     $p['start'] = get::array_def($params, 'start', 0);
     $p['rows'] = get::array_def($params, 'rows', 10);
     if (isset($params) && count($params) > 0) {
         $p = $p + $params;
     }
     $debug = false;
     if (isset($p['debug_query']) && $p['debug_query']) {
         unset($p['debug_query']);
         $debug = true;
     }
     $qs = http_build_query($p, null, '&');
     //$qs = preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', $qs); //kills arrays - solr doesn't handle arrays well, but does handle duplicate names
     $pat = array('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '/%5E/', '/%28/', '/%29/', '/%2A/', '/%3A/', '/%22/');
     $rep = array('=', '^', '(', ')', '*', ':', '"');
     $qs = preg_replace($pat, $rep, $qs);
     $url = $this->db . 'select?' . $qs;
     if ($debug) {
         log::debug($url);
     }
     $results = $this->runSolrQuery($url);
     return $results;
 }
Esempio n. 4
0
 /**
  * Validates a checkbox value.
  * 
  * @param string $value The value to validate.
  * 
  * @return bool|string Returns boolean TRUE upon successfull validation, and an error message string upon failure.
  */
 public function validate(&$value)
 {
     $required = get::array_def($this->attributes, 'required', false) == 'required';
     $msglbl = get::array_def($this->attributes, 'msglbl', get::array_def($this->attributes, 'name', $this->getId()));
     if ($required && !isset($value)) {
         return sprintf('"%s" is a required field.', $msglbl);
     }
     return true;
 }
Esempio n. 5
0
 /**
  * Generates the HTML for the form element.
  * 
  * @return string
  */
 public function __toString()
 {
     $this->attributes['id'] = $this->getId();
     $this->attributes['name'] = $this->getName();
     $this->attributes['value'] = get::array_def($this->attributes, 'value', '');
     $this->attributes['type'] = $this->type;
     $content = get::array_def($this->attributes, 'content', $this->attributes['value']);
     $html = sprintf('<button%s>%s</button>', get::formattedAttributes($this->getAttributes()), $content);
     if (is::existset($this->attributes, 'autofocus')) {
         $html .= $this->getAutoFocusScript($this->attributes['id']);
     }
     return $html;
 }
Esempio n. 6
0
 /**
  * Validates a text value.
  * 
  * @param string $value The value to validate.
  * 
  * @return bool|string Returns boolean TRUE upon successfull validation, and an error message string upon failure.
  */
 public function validate(&$value)
 {
     $required = get::array_def($this->attributes, 'required', false) == 'required';
     $maxlength = get::array_def($this->attributes, 'maxlength', 0);
     $msglbl = get::array_def($this->attributes, 'msglbl', get::array_def($this->attributes, 'name', $this->getId()));
     if ($required && (!isset($value) || strlen(trim($value)) < 1)) {
         return sprintf('"%s" is a required field.', $msglbl);
     }
     if ($maxlength > 0 && strlen(trim($value)) > $maxlength) {
         return sprintf('"%s" has to many characters - the max length is %s.', $msglbl, $maxlength);
     }
     return true;
 }
Esempio n. 7
0
 /**
  * Validates a text value.
  * 
  * @param string $value The value to validate.
  * 
  * @return bool|string Returns boolean TRUE upon successfull validation, and an error message string upon failure.
  */
 public function validate(&$value)
 {
     $required = get::array_def($this->attributes, 'required', false) == 'required';
     //$maxlength = get::array_def($this->attributes, 'maxlength', 0);
     //$pattern = get::array_def($this->attributes, 'pattern', null);
     $msglbl = get::array_def($this->attributes, 'msglbl', get::array_def($this->attributes, 'name', $this->getId()));
     if ($required && (!isset($value) || strlen(trim($value)) < 1)) {
         return sprintf('"%s" is a required field.', $msglbl);
     }
     //if( $maxlength > 0 && strlen(trim($value)) > $maxlength )
     //return sprintf('"%s" has to many characters - the max length is %s.', $msglbl, $maxlength);
     //if( $pattern != null && isset($value) && strlen(trim($value)) > 0 && !preg_match('/^(?:'.$pattern.')$/', $value) )
     //return sprintf('"%s" does not match the pattern defined for it.', $msglbl);
     return true;
 }
Esempio n. 8
0
File: url.php Progetto: Borvik/Munla
 /**
  * Validates a url value.
  * 
  * @param string $value The value to validate.
  * 
  * @return bool|string Returns boolean TRUE upon successfull validation, and an error message string upon failure.
  */
 public function validate(&$value)
 {
     $return = parent::validate($value);
     if ($return !== true) {
         return $return;
     }
     if (isset($value) && strlen(trim($value)) > 0) {
         $valid = is::url($value, true);
         if (!is_array($valid)) {
             $msglbl = get::array_def($this->attributes, 'msglbl', get::array_def($this->attributes, 'name', $this->getId()));
             return sprintf('"%s" has an invalid url. Urls start with http/https/ftp followed by "://" and then the domain and path.', $msglbl);
         }
         $value = $valid;
     }
     return true;
 }
Esempio n. 9
0
 /**
  * Validates a email value.
  * 
  * @param string $value The value to validate.
  * 
  * @return bool|string Returns boolean TRUE upon successfull validation, and an error message string upon failure.
  */
 public function validate(&$value)
 {
     $return = parent::validate($value);
     if ($return !== true) {
         return $return;
     }
     if (isset($value) && strlen(trim($value)) > 0) {
         $valid = is::email($value, get::array_def($this->attributes, 'multiple', false) == 'multiple');
         if (!is_object($valid) || !($valid instanceof emailAddressList || $valid instanceof emailAddress)) {
             $msglbl = get::array_def($this->attributes, 'msglbl', get::array_def($this->attributes, 'name', $this->getId()));
             return sprintf('"%s" has an invalid email address.', $msglbl);
         }
         $value = $valid;
     }
     return true;
 }
Esempio n. 10
0
 /**
  * Validates a text value.
  * 
  * @param string $value The value to validate.
  * 
  * @return bool|string Returns boolean TRUE upon successfull validation, and an error message string upon failure.
  */
 public function validate(&$value)
 {
     $return = parent::validate($value);
     if ($return !== true) {
         return $return;
     }
     $maxlength = get::array_def($this->attributes, 'maxlength', 0);
     $pattern = get::array_def($this->attributes, 'pattern', null);
     $msglbl = get::array_def($this->attributes, 'msglbl', get::array_def($this->attributes, 'name', $this->getId()));
     if ($maxlength > 0 && strlen(trim($value)) > $maxlength) {
         return sprintf('"%s" has to many characters - the max length is %s.', $msglbl, $maxlength);
     }
     if ($pattern != null && isset($value) && strlen(trim($value)) > 0 && !preg_match('/^(?:' . $pattern . ')$/', $value)) {
         return sprintf('"%s" does not match the pattern defined for it.', $msglbl);
     }
     return true;
 }
Esempio n. 11
0
File: tel.php Progetto: Borvik/Munla
 /**
  * Validates a telephone value.
  * 
  * @param string $value The value to validate.
  * 
  * @return bool|string Returns boolean TRUE upon successfull validation, and an error message string upon failure.
  */
 public function validate(&$value)
 {
     $return = parent::validate($value);
     if ($return !== true) {
         return $return;
     }
     $mode = get::array_def($this->attributes, 'validatemode', 'none');
     if (isset($value) && strlen(trim($value)) > 0 && $mode != 'none') {
         if (strtolower($mode) == 'us') {
             $return = false;
             if (preg_match('/^[\\(]?(\\d{0,3})[\\)]?[\\s]?[\\-]?(\\d{3})[\\s]?[\\-]?(\\d{4})([x\\s]{1,}(\\d*))?$/', trim($value), $matches)) {
                 $phoneNumber = '';
                 // we have a match, dump sub-patterns to $matches
                 $phone_number = $matches[0];
                 // original number
                 $area_code = $matches[1];
                 // 3-digit area code
                 $exchange = $matches[2];
                 // 3-digit exchange
                 $number = $matches[3];
                 // 4-digit number
                 $return = new phoneNumber();
                 $return->original = $matches[0];
                 if (isset($matches[1]) && strlen(trim($matches[1])) > 0) {
                     $return->areacode = trim($matches[1]);
                     $return->formatted .= '(' . $return->areacode . ') ';
                 }
                 $return->exchange = $matches[2];
                 $return->number = $matches[3];
                 $return->formatted .= $return->exchange . '-' . $return->number;
                 if (isset($matches[4]) && strlen(trim($matches[4])) > 0) {
                     $return->extension = trim($matches[5]);
                     $return->xformatted = $return->formatted . ' x' . $return->extension;
                 }
             }
             if ($return === false) {
                 $msglbl = get::array_def($this->attributes, 'msglbl', get::array_def($this->attributes, 'name', $this->getId()));
                 return sprintf('"%s" has an invalid phone format (###-#### with optional 3 digit area code, and/or extension).', $msglbl);
             }
             $value = $return;
         }
     }
     return true;
 }
Esempio n. 12
0
 /**
  * Validates a color value.  According to the W3C this field should ALWAYS have a value.
  * 
  * @param string $value The value to validate.
  * 
  * @return bool|string Returns boolean TRUE upon successfull validation, and an error message string upon failure.
  */
 public function validate(&$value)
 {
     $return = parent::validate($value);
     if ($return !== true) {
         return $return;
     }
     if (!isset($value) || strlen(trim($value)) < 1) {
         $value = '#000000';
     }
     if (isset($value) && strlen(trim($value)) > 0) {
         $valid = is::color($value);
         if ($valid === false) {
             $msglbl = get::array_def($this->attributes, 'msglbl', get::array_def($this->attributes, 'name', $this->getId()));
             return sprintf('"%s" has an invalid color (ex. #FFFFFF).', $msglbl);
         }
         $value = $valid;
     }
     return true;
 }
Esempio n. 13
0
 /**
  * Validates a datetime value.
  * 
  * @param string $value The value to validate.
  * 
  * @return bool|string Returns boolean TRUE upon successfull validation, and an error message string upon failure.
  */
 public function validate(&$value)
 {
     $return = parent::validate($value);
     if ($return !== true) {
         return $return;
     }
     if (isset($value) && strlen(trim($value)) > 0) {
         $msglbl = get::array_def($this->attributes, 'msglbl', get::array_def($this->attributes, 'name', $this->getId()));
         $valid = is::datetime($value);
         if ($valid === false) {
             return sprintf('"%s" does not have a valid date/time. The format is YYYY-mm-ddThh:mm:ss.fff. "T" is a literal separator.', $msglbl);
         }
         $mode = get::array_def($this->attributes, 'datemode', 'html');
         $min = get::array_def($this->attributes, 'min', false);
         if (is_object($min) && $min instanceof cDateTime) {
             if ($valid->lessThan($min)) {
                 switch ($mode) {
                     case 'html':
                         break;
                     case 'us':
                         $min = $min->format_us();
                         break;
                     default:
                         $min = $min->format($mode);
                         break;
                 }
                 return sprintf('"%s" cannot be before "%s".', $msglbl, $min);
             }
         }
         $max = get::array_def($this->attributes, 'max', false);
         if (is_object($max) && $max instanceof cDateTime) {
             if ($max->lessThan($valid)) {
                 switch ($mode) {
                     case 'html':
                         break;
                     case 'us':
                         $max = $max->format_us();
                         break;
                     default:
                         $max = $max->format($mode);
                         break;
                 }
                 return sprintf('"%s" cannot be after "%s".', $msglbl, $max);
             }
         }
         $value = $valid;
     }
     return true;
 }
Esempio n. 14
0
 /**
  * Validates a selected value.
  * 
  * @param string $value The value to validate.
  * 
  * @return bool|string Returns boolean TRUE upon successfull validation, and an error message string upon failure.
  */
 public function validate(&$value)
 {
     if (is_array($value)) {
         $value = array_filter($value, array($this, 'removeEmptyValues'));
     } elseif ($value == $this->emptyValue) {
         $value = null;
     }
     $allowchange = get::array_def($this->attributes, 'allowchange', false, array(true, false));
     $required = get::array_def($this->attributes, 'required', false) == 'required';
     $multiple = get::array_def($this->attributes, 'multiple', false) == 'multiple';
     $msglbl = get::array_def($this->attributes, 'msglbl', get::array_def($this->attributes, 'name', $this->getId()));
     if ($required && (!isset($value) || !is_array($value) && (strlen(trim($value)) < 1 || $value == $this->emptyValue) || is_array($value) && count($value) < 1)) {
         return sprintf('"%s" is a required field.', $msglbl);
     } elseif (!$allowchange) {
         if (!$multiple && isset($value) && is_array($value)) {
             return sprintf('Multiple values are not allowed for "%s" - please choose from the list.', $msglbl);
         }
         if (isset($value) && !is_array($value) && $multiple) {
             $value = array($value);
         }
         if (isset($value) && !is_array($value) && !in_array($value, $this->values)) {
             return sprintf('"%s" is not a valid value for "%s" - please choose from the list.', $value, $msglbl);
         }
         if (isset($value) && is_array($value)) {
             foreach ($value as $v) {
                 if (is_array($v)) {
                     return sprintf('"%s" - a select list selection may not itself be an array - please choose from the list.', $msglbl);
                 }
                 if (!in_array($v, $this->values)) {
                     return sprintf('"%s" is not a valid value for "%s" - please choose from the list.', $v, $msglbl);
                 }
             }
         }
     }
     return true;
 }
Esempio n. 15
0
 /**
  * Validates a radio button value.
  * 
  * @param string $value The value to validate.
  * 
  * @return bool|string Returns boolean TRUE upon successfull validation, and an error message string upon failure.
  */
 public function validate(&$value)
 {
     $args = func_get_args();
     array_shift($args);
     $fields = $args[0];
     $name = $this->getName();
     if (in_array($name, fe_radio::$validated)) {
         return true;
     }
     $msglbl = get::array_def($this->attributes, 'msglbl', get::array_def($this->attributes, 'name', $this->getId()));
     $required = false;
     $allowchange = false;
     $values = array();
     foreach ($fields as $field) {
         if (!$field instanceof fe_radio || $field->getName() != $name) {
             continue;
         }
         if (get::array_def($field->attributes, 'required', false) == 'required') {
             $required = true;
         }
         if (get::array_def($this->attributes, 'allowchange', false, array(true, false))) {
             $allowchange = true;
         }
         $values[] = get::array_def($field->attributes, 'value');
     }
     fe_radio::$validated[] = $name;
     if ($required && !isset($value)) {
         return sprintf('"%s" is a required field.', $msglbl);
     }
     if (!$allowchange && isset($value) && !in_array($value, $values)) {
         return sprintf('"%s" is not a valid value for "%s" - please choose from the list.', $value, $msglbl);
     }
     return true;
 }
Esempio n. 16
0
 /**
  * Get a specific attribute from this form element.
  * 
  * @param string $name The name of the attribute to get.
  * 
  * @return mixed
  */
 public function getAttibuteValue($name)
 {
     return get::array_def($this->attributes, $name);
 }