Esempio n. 1
0
 /**
  * Validation will only be performed on input keys not on all field keys to
  * allow for partial input validation.
  *
  * @param array input
  * @return array errors (empty if no errors)
  */
 function validate($input)
 {
     $errors = array();
     $defaults = pixreviews::defaults();
     $plugin_checks = $this->meta->get('checks', array());
     foreach ($input as $key => $value) {
         $field = $this->fields->get($key);
         // Calculate validation rules
         // --------------------------
         $rules = array();
         // check pixreviews defaults
         if (isset($defaults['checks'][$field['type']])) {
             $rules = $defaults['checks'][$field['type']];
         }
         // check theme defaults
         if (isset($plugin_checks[$field['type']])) {
             $rules = array_merge($rules, $plugin_checks[$field['type']]);
         }
         // check field presets
         if (isset($field['checks'])) {
             $rules = array_merge($rules, $field['checks']);
         }
         // Perform validation
         // ------------------
         foreach ($rules as $rule) {
             $callback = pixreviews::callback($rule, $this->meta);
             $valid = call_user_func($callback, $input[$key], $field, $this);
             if (!$valid) {
                 isset($errors[$key]) or $errors[$key] = array();
                 $errors[$key][$rule] = $this->error_message($rule);
             }
         }
     }
     return $errors;
 }
Esempio n. 2
0
 /**
  * Execute postupdate hooks on input.
  */
 protected function postupdate($input)
 {
     $defaults = pixreviews::defaults();
     $plugin_hooks = $this->meta->get('processor', array('preupdate' => array(), 'postupdate' => array()));
     // Calculate hooks
     // ---------------
     $hooks = array();
     // check pixreviews defaults
     if (isset($defaults['processor']['postupdate'])) {
         $hooks = $defaults['processor']['postupdate'];
     }
     // check plugin defaults
     if (isset($plugin_hooks['postupdate'])) {
         $hooks = array_merge($hooks, $plugin_hooks['postupdate']);
     }
     // Execute hooks
     // -------------
     foreach ($hooks as $rule) {
         $callback = pixreviews::callback($rule, $this->meta);
         call_user_func($callback, $input, $this);
     }
 }