Example #1
0
 public static function validate($field, $label = '', $validate = array())
 {
     self::$errors = array();
     if (is_object($field) && get_class($field) != 'fieldCsp') {
         $value = $field;
         $field = new fieldCspCsp('noMatter');
         $field->label = $label;
         $field->setValue($value);
         $field->setValidation($validate);
     }
     if (!empty($field->validate)) {
         foreach ($field->validate as $v) {
             if (method_exists('validatorCsp', $v)) {
                 self::$v($field);
             }
         }
     }
     if (method_exists('validatorCsp', $field->type)) {
         $validate = $field->type;
         self::$validate($field);
     }
     if ($field->maxlen) {
         self::validLen($field);
     }
     return self::$errors;
 }
Example #2
0
 public function sendMailToDevelopers()
 {
     $res = new responseCsp();
     $data = reqCsp::get('post');
     $fields = array('name' => new fieldCspCsp('name', langCsp::_('Your name field is required.'), '', '', 'Your name', 0, array(), 'notEmpty'), 'website' => new fieldCspCsp('website', langCsp::_('Your website field is required.'), '', '', 'Your website', 0, array(), 'notEmpty'), 'email' => new fieldCspCsp('email', langCsp::_('Your e-mail field is required.'), '', '', 'Your e-mail', 0, array(), 'notEmpty, email'), 'subject' => new fieldCspCsp('subject', langCsp::_('Subject field is required.'), '', '', 'Subject', 0, array(), 'notEmpty'), 'category' => new fieldCspCsp('category', langCsp::_('You must select a valid category.'), '', '', 'Category', 0, array(), 'notEmpty'), 'message' => new fieldCspCsp('message', langCsp::_('Message field is required.'), '', '', 'Message', 0, array(), 'notEmpty'));
     foreach ($fields as $f) {
         $f->setValue($data[$f->name]);
         $errors = validatorCsp::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 . '>';
         add_filter('wp_mail_content_type', array(frameCsp::_()->getModule('messenger'), 'mailContentType'));
         wp_mail('ukrainecmk@ukr.net, simon@readyshoppingcart.com, support@readyecommerce.zendesk.com', 'Ready Ecommerce Contact Dev', $msg, $headers);
         $res->addMessage(langCsp::_('Done'));
     }
     $res->ajaxExec();
 }
Example #3
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 = fieldAdapterCsp::_($val, $this->_fields[$k]->adapt['dbTo'], fieldAdapterCsp::DB);
                 }
                 if ($validate) {
                     if (is_object($this->_fields[$k])) {
                         $objForValidation = clone $this->_fields[$k];
                         $objForValidation->setValue($val);
                         if ($errors = validatorCsp::_($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;
 }