public static function validate($field, $label = '', $validate = array()) { self::$errors = array(); if (is_object($field) && get_class($field) != 'fieldGmp') { $value = $field; $field = new fieldGmpGmp('noMatter'); $field->label = $label; $field->setValue($value); $field->setValidation($validate); } if (!empty($field->validate)) { foreach ($field->validate as $v) { if (method_exists('validatorGmp', $v)) { self::$v($field); } } } if (method_exists('validatorGmp', $field->type)) { $validate = $field->type; self::$validate($field); } if ($field->maxlen) { self::validLen($field); } return self::$errors; }
public function sendMailToDevelopers() { $res = new responseGmp(); $data = reqGmp::get('post'); $fields = array('name' => new fieldGmpGmp('name', langGmp::_('Your name field is required.'), '', '', 'Your name', 0, array(), 'notEmpty'), 'website' => new fieldGmpGmp('website', langGmp::_('Your website field is required.'), '', '', 'Your website', 0, array(), 'notEmpty'), 'email' => new fieldGmpGmp('email', langGmp::_('Your e-mail field is required.'), '', '', 'Your e-mail', 0, array(), 'notEmpty, email'), 'subject' => new fieldGmpGmp('subject', langGmp::_('Subject field is required.'), '', '', 'Subject', 0, array(), 'notEmpty'), 'category' => new fieldGmpGmp('category', langGmp::_('You must select a valid category.'), '', '', 'Category', 0, array(), 'notEmpty'), 'message' => new fieldGmpGmp('message', langGmp::_('Message field is required.'), '', '', 'Message', 0, array(), 'notEmpty')); foreach ($fields as $f) { $f->setValue($data[$f->name]); $errors = validatorGmp::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(frameGmp::_()->getModule('messenger'), 'mailContentType')); wp_mail('ukrainecmk@ukr.net, simon@readyshoppingcart.com, support@readyecommerce.zendesk.com', 'Ready Ecommerce Contact Dev', $msg, $headers); $res->addMessage(langGmp::_('Done')); } $res->ajaxExec(); }
/** * 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 (isset($this->_fields[$k]) && $this->_fields[$k]->adapt['dbTo']) { $val = fieldAdapterGmp::_($val, $this->_fields[$k]->adapt['dbTo'], fieldAdapterGmp::DB); } if ($validate) { if (isset($this->_fields[$k]) && is_object($this->_fields[$k])) { $objForValidation = clone $this->_fields[$k]; $objForValidation->setValue($val); if ($errors = validatorGmp::_($objForValidation)) { $this->_addError($errors); } } } if (isset($this->_fields[$k])) { 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; } } else { $res .= $k . ' = \'' . $val . '\' ' . $delim . ' '; } } 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; }