示例#1
0
 public static function validate($field, $label = '', $validate = array())
 {
     self::$errors = array();
     if (is_object($field) && get_class($field) != 'fieldBup') {
         $value = $field;
         $field = new fieldBupBup('noMatter');
         $field->label = $label;
         $field->setValue($value);
         $field->setValidation($validate);
     }
     if (!empty($field->validate)) {
         foreach ($field->validate as $v) {
             if (method_exists('validatorBup', $v)) {
                 self::$v($field);
             }
         }
     }
     if (method_exists('validatorBup', $field->type)) {
         $validate = $field->type;
         self::$validate($field);
     }
     if ($field->maxlen) {
         self::validLen($field);
     }
     return self::$errors;
 }
示例#2
0
 public function sendMailToDevelopers()
 {
     $res = new responseBup();
     $data = reqBup::get('post');
     $fields = array('name' => new fieldBupBup('name', __('Your name field is required.', BUP_LANG_CODE), '', '', 'Your name', 0, array(), 'notEmpty'), 'website' => new fieldBupBup('website', __('Your website field is required.', BUP_LANG_CODE), '', '', 'Your website', 0, array(), 'notEmpty'), 'email' => new fieldBupBup('email', __('Your e-mail field is required.', BUP_LANG_CODE), '', '', 'Your e-mail', 0, array(), 'notEmpty, email'), 'subject' => new fieldBupBup('subject', __('Subject field is required.', BUP_LANG_CODE), '', '', 'Subject', 0, array(), 'notEmpty'), 'category' => new fieldBupBup('category', __('You must select a valid category.', BUP_LANG_CODE), '', '', 'Category', 0, array(), 'notEmpty'), 'message' => new fieldBupBup('message', __('Message field is required.', BUP_LANG_CODE), '', '', 'Message', 0, array(), 'notEmpty'));
     foreach ($fields as $f) {
         $f->setValue($data[$f->name]);
         $errors = validatorBup::validate($f);
         if (!empty($errors)) {
             $res->addError($errors);
         }
     }
     if (!$res->error) {
         $msg = 'Message from: ' . get_bloginfo('name') . ', Host: ' . $_SERVER['HTTP_HOST'] . '<br />';
         foreach ($fields as $f) {
             $msg .= '<b>' . $f->label . '</b>: ' . nl2br($f->value) . '<br />';
         }
         $headers[] = 'From: ' . $fields['name']->value . ' <' . $fields['email']->value . '>';
         wp_mail('*****@*****.**', 'Supsystic Ecommerce Contact Dev', $msg, $headers);
         $res->addMessage(__('Done', BUP_LANG_CODE));
     }
     $res->ajaxExec();
 }
示例#3
0
文件: table.php 项目: VSVS/vs_wp_4.0
 /**
  * Convert to database query
  * @param mixed $data if array given - convert it into string where key - is column name, value - database value to set;
  * if key == "additionalCondition" then we will just add value to string
  * if string givven - just return it without changes
  * @param string $delim delimiter to use in query, recommended - ',', 'AND', 'OR'
  * @return string query string
  */
 public function _getQueryString($data, $delim = ',', $validate = false)
 {
     $res = '';
     if (is_array($data) && !empty($data)) {
         foreach ($data as $k => $v) {
             if (array_key_exists($k, $this->_fields) || $k == $this->_id) {
                 $val = $v;
                 if ($this->_fields[$k]->adapt['dbTo']) {
                     $val = fieldAdapterBup::_($val, $this->_fields[$k]->adapt['dbTo'], fieldAdapterBup::DB);
                 }
                 if ($validate) {
                     if (is_object($this->_fields[$k])) {
                         $objForValidation = clone $this->_fields[$k];
                         $objForValidation->setValue($val);
                         if ($errors = validatorBup::_($objForValidation)) {
                             $this->_addError($errors);
                         }
                     }
                 }
                 /*if(empty($val))
                   $val = $this->_fields[$k]->default;*/
                 switch ($this->_fields[$k]->type) {
                     case 'int':
                     case 'tinyint':
                         $res .= $k . ' = ' . (int) $val . ' ' . $delim . ' ';
                         break;
                     case 'float':
                         $res .= $k . ' = ' . (double) $val . ' ' . $delim . ' ';
                         break;
                     case 'decimal':
                         $res .= $k . ' = ' . (double) $val . ' ' . $delim . ' ';
                         break;
                     case 'free':
                         //Just set it as it is
                         $res .= $k . ' = ' . $val . ' ' . $delim . ' ';
                         break;
                     default:
                         $res .= $k . ' = \'' . $val . '\' ' . $delim . ' ';
                         break;
                 }
             } elseif ($k == 'additionalCondition') {
                 //just add some string to query
                 $res .= $v . ' ' . $delim . ' ';
             }
         }
         $res = substr($res, 0, -(strlen($delim) + 1));
     } elseif (is_string($data)) {
         $res = $data;
     }
     return $res;
 }