コード例 #1
0
ファイル: PW_Alerts.php プロジェクト: rspindel/PW_Framework
 /**
  * Echos the list of alerts
  * @since 0.1
  */
 public static function render()
 {
     if (!self::get_alerts()) {
         return false;
     }
     // sort the alerts by priority
     usort(self::$_alerts, array('PW_Alerts', 'compare'));
     if (self::$_alerts) {
         foreach (self::$_alerts as $alert) {
             ZC::e('div.' . $alert['type'], $alert['message']);
         }
         self::$_alerts = array();
         delete_transient('PW_Alerts');
     }
 }
コード例 #2
0
ファイル: PW_Model.php プロジェクト: rspindel/PW_Framework
 /**
  * Validates the option against the validation rules returned by $this->rules()
  * @param array $option of option to be validated.
  * @return array The default properties and values
  * @since 0.1
  */
 public function validate($input = array(), $validate_all = true)
 {
     if ($is_ajax = defined('DOING_AJAX') && constant('DOING_AJAX') == true) {
         if (isset($_GET[$this->_name])) {
             $input = $_GET[$this->_name];
             $validate_all = false;
         } else {
             exit;
         }
     }
     $valid = true;
     $rules = $this->rules();
     foreach ($rules as $rule) {
         // remove spaces and then split up the comma delimited property string into an array
         $properties = str_replace(' ', '', $rule['properties']);
         $properties = strpos($properties, ',') === false ? array($properties) : explode(',', $properties);
         foreach ($properties as $property) {
             // set the field to null if no value was passed but a validation rules was set
             // this will allow for an error in a situation where someone used firebug to delete HTML dynamically
             $field = isset($input[$property]) ? $input[$property] : null;
             // if $validate_all is set to false, allow for empty properties
             if (!$validate_all && $field === null) {
                 continue;
             }
             // create an array of values from the rule definition to pass as method arguments to the callback function
             $args = $rule;
             array_unshift($args, $field);
             unset($args['properties']);
             unset($args['validator']);
             unset($args['message']);
             if ($error = call_user_func_array($rule['validator'], $args)) {
                 $message = isset($rule['message']) ? $rule['message'] : $error;
                 $message = str_replace("{property}", $this->get_label($property), $message);
                 $this->add_error($property, $message);
                 $valid = false;
             }
         }
     }
     // Add an alert for any errors
     if ($this->_errors && !$is_ajax) {
         PW_Alerts::add('error', '<p><strong>Please fix the following errors and trying submitting again.</strong></p>' . ZC::r('ul>li*' . count($this->errors), array_values($this->errors)), 0);
     }
     if ($is_ajax) {
         echo current($this->_errors);
         exit;
     } else {
         return $valid;
     }
 }
コード例 #3
0
 /**
  * Create the markup for the Create/Update and Delete buttons
  * @return string The rendered HTML markup
  * @since 0.1
  */
 protected function render_buttons()
 {
     $output = ZC::r('input.button-primary{%1}', array('type' => 'submit', 'value' => $this->_model->instance ? "Update" : "Create"), null);
     $instances = $this->_model->get_option();
     $instance = $instances[$this->_model->instance];
     if (0 != $this->_model->instance) {
         $delete_url = wp_nonce_url(add_query_arg('delete_instance', '1'), 'delete_instance');
         $output .= ZC::r('a.submitdelete[href="' . $delete_url . '"]', 'Delete ' . $instance['name']);
     }
     return $output;
 }