当前位置: 首页>>代码示例>>PHP>>正文


PHP validate::run方法代码示例

本文整理汇总了PHP中validate::run方法的典型用法代码示例。如果您正苦于以下问题:PHP validate::run方法的具体用法?PHP validate::run怎么用?PHP validate::run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在validate的用法示例。


在下文中一共展示了validate::run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _savePackage

 protected function _savePackage($packageID)
 {
     // Check if demo mode is enabled
     if (input::demo()) {
         return false;
     }
     // Create rules
     $rules = array('credits' => array('label' => __('credits', 'billing_credits'), 'rules' => array('trim', 'required', 'is_natural_no_zero')), 'price' => array('label' => __('price', 'billing'), 'rules' => array('trim', 'required', 'numeric')), 'active' => array('label' => __('active', 'system'), 'rules' => array('trim', 'required', 'intval')));
     // Assign rules
     validate::setRules($rules);
     // Validate fields
     if (!validate::run()) {
         return false;
     }
     // Get post data
     $package = input::post(array('credits', 'price', 'active'));
     // Save banner group
     if (!($packageID = $this->credits_model->savePackage($packageID, $package))) {
         view::setError(__('save_error', 'system'));
         return false;
     }
     // Success
     view::setInfo(__('package_saved', 'billing_credits'));
     router::redirect('cp/billing/credits/edit/' . $packageID);
 }
开发者ID:soremi,项目名称:tutornavi,代码行数:25,代码来源:credits.php

示例2: _saveGroup

 protected function _saveGroup($groupID)
 {
     // Check if demo mode is enabled
     if (input::demo()) {
         return false;
     }
     // Create rules
     $rules = array('name' => array('label' => __('name', 'system'), 'rules' => array('trim', 'required', 'max_length' => 255)), 'keyword' => array('label' => __('keyword', 'system'), 'rules' => array('trim', 'required', 'max_length' => 128, 'alpha_dash', 'strtolower', 'callback__is_unique_keyword' => $groupID)));
     // Assign rules
     validate::setRules($rules);
     // Validate fields
     if (!validate::run()) {
         return false;
     }
     // Get post data
     $groupData = input::post(array('name', 'keyword'));
     // Save banner group
     if (!($groupID = $this->banners_groups_model->saveGroup($groupID, $groupData))) {
         view::setError(__('save_error', 'system'));
         return false;
     }
     // Success
     view::setInfo(__('group_saved', 'banners'));
     router::redirect('cp/content/banners/groups/edit/' . $groupID);
 }
开发者ID:soremi,项目名称:tutornavi,代码行数:25,代码来源:groups.php

示例3: _sendFeedback

 protected function _sendFeedback()
 {
     // Check if demo mode is enabled
     if (input::demo()) {
         return false;
     }
     // Extra rules
     $rules = array('name' => array('rules' => array('required', 'is_string', 'trim', 'min_length' => 2, 'max_length' => 255)), 'email' => array('rules' => array('required', 'is_string', 'trim', 'valid_email', 'min_length' => 4, 'max_length' => 255)), 'subject' => array('rules' => array('required', 'is_string', 'trim', 'min_length' => 5, 'max_length' => 255)), 'message' => array('rules' => array('required', 'is_string', 'trim', 'min_length' => 10, 'max_length' => 10000)));
     if (config::item('feedback_captcha', 'feedback') == 1 || config::item('feedback_captcha', 'feedback') == 2 && !users_helper::isLoggedin()) {
         $rules['captcha'] = array('rules' => array('is_captcha'));
     }
     validate::setRules($rules);
     // Validate form values
     if (!validate::run($rules)) {
         return false;
     }
     // Get values
     $email = input::post('email');
     $subject = input::post('subject');
     $message = input::post('message') . "\n\n--\n" . input::post('name') . ' <' . input::post('email') . '>' . "\n" . input::ipaddress();
     // Send feedback
     if (!$this->feedback_model->sendFeedback($email, $subject, $message)) {
         if (!validate::getTotalErrors()) {
             view::setError(__('send_error', 'system'));
         }
         return false;
     }
     // Success
     view::setInfo(__('message_sent', 'feedback'));
     router::redirect('feedback');
 }
开发者ID:soremi,项目名称:tutornavi,代码行数:31,代码来源:feedback.php

示例4: _submitReport

 protected function _submitReport($resource, $resourceID, $userID, $itemID, $subjects)
 {
     // Extra rules
     $rules = array('subject' => array('rules' => $subjects ? array('required', 'callback__is_valid_subject' => array($subjects)) : array('callback__is_valid_subject' => array($subjects))), 'message' => array('rules' => array('is_string', 'trim', 'max_length' => 255)));
     validate::setRules($rules);
     // Validate form values
     if (!validate::run($rules)) {
         return false;
     }
     // Get values
     $subject = $subjects ? (int) input::post('subject') : 0;
     $message = input::post('message');
     // Send feedback
     if (!$this->reports_model->saveReport($resourceID, $userID, $itemID, $subject, $message)) {
         if (!validate::getTotalErrors()) {
             view::setError(__('save_error', 'system'));
         }
         return false;
     }
     // Success
     router::redirect('report/sent' . (input::get('modal') ? '?modal=1' : ''));
 }
开发者ID:soremi,项目名称:tutornavi,代码行数:22,代码来源:report.php

示例5: _saveComment

 protected function _saveComment($resource, $itemID)
 {
     // Is user logged in?
     if (!users_helper::isLoggedin()) {
         return false;
     }
     // Create rules
     $rules = array('comment' => array('label' => __('comment_body', 'comments'), 'rules' => array('trim', 'required', 'min_length' => config::item('min_length', 'comments'), 'max_length' => config::item('max_length', 'comments'), 'callback__is_comments_delay')));
     // Assign rules
     validate::setRules($rules);
     // Validate fields
     if (!validate::run()) {
         return false;
     }
     // Get comment
     $comment = array('comment' => input::post('comment'));
     // Get table and column names
     $table = config::item('resources', 'core', $resource, 'table');
     $column = config::item('resources', 'core', $resource, 'column');
     $user = config::item('resources', 'core', $resource, 'user');
     // Get resource item
     $item = $this->db->query("SELECT `" . $column . "` " . ($user ? ', `' . $user . '` AS `user_id`' : '') . "\n\t\t\tFROM `:prefix:" . $table . "`\n\t\t\tWHERE `" . $column . "`=? LIMIT 1", array($itemID))->row();
     // Does resource exist?
     if (!$item) {
         return false;
     }
     // Save comment
     if (!$this->comments_model->saveComment(0, $comment, $resource, isset($item['user_id']) ? $item['user_id'] : 0, $itemID)) {
         if (!validate::getTotalErrors()) {
             view::setError(__('save_error', 'system'));
         }
         return false;
     }
     // Reset post values
     $_POST['comment'] = '';
     validate::resetRules();
     return true;
 }
开发者ID:soremi,项目名称:tutornavi,代码行数:38,代码来源:comments.php

示例6: _saveField

 protected function _saveField($plugin, $table, $categoryID, $fieldID, $fieldOld, $configs, $hidden)
 {
     // Check if demo mode is enabled
     if (input::demo()) {
         return false;
     }
     // Rules array
     $rules = array();
     // Data array
     $inputData = array('keyword', 'type', 'style', 'class', 'required', 'system', 'multilang');
     // Name
     foreach (config::item('languages', 'core', 'keywords') as $languageID => $lang) {
         $rules['name_' . $lang] = array('label' => __('name', 'system_fields') . (count(config::item('languages', 'core', 'keywords')) > 1 ? ' [' . config::item('languages', 'core', 'names', $languageID) . ']' : ''), 'rules' => array('trim', 'required', 'max_length' => 255));
         $rules['vname_' . $lang] = array('label' => __('name_view', 'system_fields') . (count(config::item('languages', 'core', 'keywords')) > 1 ? ' [' . config::item('languages', 'core', 'names', $languageID) . ']' : ''), 'rules' => array('trim', 'max_length' => 255));
         $rules['sname_' . $lang] = array('label' => __('name_search', 'system_fields') . (count(config::item('languages', 'core', 'keywords')) > 1 ? ' [' . config::item('languages', 'core', 'names', $languageID) . ']' : ''), 'rules' => array('trim', 'max_length' => 255));
         $rules['validate_error_' . $lang] = array('label' => __('validate_error', 'system_fields') . (count(config::item('languages', 'core', 'keywords')) > 1 ? ' [' . config::item('languages', 'core', 'names', $languageID) . ']' : ''), 'rules' => array('trim', 'max_length' => 255));
         $inputData[] = 'name_' . $lang;
         $inputData[] = 'vname_' . $lang;
         $inputData[] = 'sname_' . $lang;
         $inputData[] = 'validate_error_' . $lang;
     }
     // Keyword
     $rules['keyword'] = array('label' => __('keyword', 'system'), 'rules' => array('trim', 'required', 'alpha_dash', 'max_length' => 128, 'callback__is_unique_keyword' => array($plugin, $categoryID, $fieldID), 'callback__is_system_field' => array($fieldID ? $fieldOld['keyword'] : '', $fieldID ? $fieldOld['system'] : '')));
     // Type
     $rules['type'] = array('label' => __('field_type', 'system_fields'), 'rules' => array('required', 'callback__is_system_field' => array($fieldID ? $fieldOld['type'] : '', $fieldID ? $fieldOld['system'] : '')));
     // Style value
     $rules['style'] = array('label' => __('style', 'system_fields'), 'rules' => array('trim'));
     // Class value
     $rules['class'] = array('label' => __('class', 'system_fields'), 'rules' => array('trim'));
     // Required
     $rules['required'] = array('label' => __('required', 'system_fields'), 'rules' => array('intval'));
     // Regular expression
     $rules['validate'] = array('label' => __('validate', 'system_fields'), 'rules' => array('trim'));
     $inputData[] = 'validate';
     // Configuration array
     $inputConfig = array();
     foreach (array('custom', input::post('type')) as $conf) {
         if (isset($configs[$conf])) {
             foreach ($configs[$conf] as $option) {
                 $rules['config_' . $conf . '_' . $option['keyword']] = array('label' => utf8::strtolower($option['label']), 'rules' => isset($option['rules']) ? $option['rules'] : array());
                 $inputConfig[$option['keyword']] = 'config_' . $conf . '_' . $option['keyword'];
             }
         }
     }
     // Add items rules
     $items = array();
     $oldItems = $fieldID ? $fieldOld['items'] : array();
     if ($this->fields_model->isMultiValue(input::post('type'))) {
         $itemsPost = input::post('items');
         $sitemsPost = input::post('sitems');
         foreach (config::item('languages', 'core', 'keywords') as $languageID => $lang) {
             $orderID = 1;
             if (isset($itemsPost[$lang]) && is_array($itemsPost[$lang])) {
                 foreach ($itemsPost[$lang] as $itemID => $itemName) {
                     // Trim name
                     $itemName = utf8::trim($itemName);
                     // Assign item data
                     $items[$itemID]['order_id'] = $orderID;
                     $items[$itemID]['name_' . $lang] = $itemName;
                     $items[$itemID]['sname_' . $lang] = $sitemsPost[$lang][$itemID];
                     $orderID++;
                     // Add rule
                     $rules['items[' . $lang . '][' . $itemID . ']'] = array();
                     if ($itemName == '') {
                         validate::setRule('items', '', '');
                         validate::setFieldError('items', __('empty_item', 'system_fields') . (count(config::item('languages', 'core', 'keywords')) > 1 ? ' [' . config::item('languages', 'core', 'names', $languageID) . ']' : ''));
                     }
                 }
             }
         }
         if (!$items) {
             validate::setRule('items', '', '');
             validate::setFieldError('items', __('no_items', 'system_fields'));
         }
         view::assign(array('field' => array('items' => $items)));
     }
     // Assign rules
     validate::setRules($rules);
     // Validate fields
     if (!validate::run()) {
         return false;
     }
     // Get post data
     $fieldData = input::post($inputData);
     // Default data
     $fieldData['system'] = isset($hidden['system']) ? $hidden['system'] : 0;
     $fieldData['multilang'] = isset($hidden['multilang']) ? $hidden['multilang'] : 0;
     // Get config data
     $fieldData['config'] = array();
     foreach ($inputConfig as $key => $val) {
         $fieldData['config'][$key] = input::post($val);
     }
     // Set additional config data
     $fieldData['config']['html'] = input::post('html') ? 1 : 0;
     $fieldData['config']['in_search'] = input::post('in_search') ? 1 : 0;
     $fieldData['config']['in_search_advanced'] = input::post('in_search_advanced') ? 1 : 0;
     if ($fieldData['config']['in_search'] || $fieldData['config']['in_search_advanced']) {
         $fieldData['config']['search_options'] = input::post('search_options') ? input::post('search_options') : '';
     }
     if (input::post('type') == 'checkbox' || input::post('search_options') == 'multiple') {
//.........这里部分代码省略.........
开发者ID:soremi,项目名称:tutornavi,代码行数:101,代码来源:system.php

示例7: _saveType

 protected function _saveType($typeID, $type, $fields)
 {
     // Check if demo mode is enabled
     if (input::demo()) {
         return false;
     }
     // Rules array
     $rules = array();
     // Input data array
     $input = array('keyword', 'field_name_1', 'field_name_2');
     // Name field
     foreach (config::item('languages', 'core', 'keywords') as $languageID => $language) {
         $rules['name_' . $language] = array('label' => __('name', 'system') . (count(config::item('languages', 'core', 'keywords')) > 1 ? ' [' . config::item('languages', 'core', 'names', $languageID) . ']' : ''), 'rules' => array('trim', 'required', 'max_length' => 128));
         $input[] = 'name_' . $language;
     }
     // Keyword field
     $rules['keyword'] = array('label' => __('keyword', 'system'), 'rules' => array('required', 'max_length' => 32, 'alpha_dash', 'strtolower', 'callback__is_unique_keyword' => $typeID));
     // Is this an existing type?
     if ($typeID) {
         $rules['field_name_1'] = array('label' => __('type_fields_name', 'users_types'), 'rules' => array('max_length' => 128, 'callback__is_valid_field_name' => array('field_name_1', $fields)));
         $rules['field_name_2'] = array('label' => __('type_fields_name', 'users_types'), 'rules' => array('max_length' => 128, 'callback__is_valid_field_name' => array('field_name_2', $fields)));
     }
     // Assign rules
     validate::setRules($rules);
     // Validate fields
     if (!validate::run()) {
         return false;
     }
     // Get post data
     $data = input::post($input);
     // Save user type
     if (!($newTypeID = $this->users_types_model->saveType($typeID, $data))) {
         if ($typeID) {
             view::setError(__('db_no_rename', 'system_fields'));
         } else {
             view::setError(__('db_no_create', 'system_fields'));
         }
         return false;
     }
     // Is this an existing type?
     if ($typeID) {
         $fields = config::item('usertypes', 'core', 'fields', $typeID);
         if (($data['field_name_1'] || $data['field_name_2']) && ($fields[1] != $data['field_name_1'] || $fields[2] != $data['field_name_2'])) {
             $this->users_types_model->updateNames($typeID, $data['field_name_1'], $data['field_name_2']);
         }
     }
     // Success
     view::setInfo(__('type_saved', 'users_types'));
     router::redirect('cp/users/types/edit/' . $newTypeID);
 }
开发者ID:soremi,项目名称:tutornavi,代码行数:50,代码来源:types.php

示例8: _saveLanguageData

 protected function _saveLanguageData($plugin, $language, $default)
 {
     // Check if demo mode is enabled
     if (input::demo()) {
         return false;
     }
     // Create rules
     $rules = array();
     foreach ($default as $section => $groups) {
         foreach ($groups as $group => $types) {
             foreach ($types as $type => $lang) {
                 foreach ($lang as $keyword => $name) {
                     $rules[$group . '_' . $keyword] = array('label' => '', 'rules' => array('trim', 'required'));
                 }
             }
         }
     }
     // Assign rules
     validate::setRules($rules);
     // Validate fields
     if (!validate::run()) {
         return false;
     }
     // Get language data
     $languageData = array();
     foreach ($default as $section => $groups) {
         foreach ($groups as $group => $types) {
             foreach ($types as $type => $lang) {
                 foreach ($lang as $keyword => $name) {
                     $cp = $type == 'cp' ? 1 : 0;
                     // Set language data
                     $data = array('value_' . $language => input::post($group . '_' . $keyword));
                     // Save language string
                     $this->languages_model->saveLanguageData($plugin, $section, $group, $keyword, $data);
                 }
             }
         }
     }
     // Recompile language pack
     $this->languages_model->compile($language);
     // Success
     view::setInfo(__('language_saved', 'system_languages'));
     router::redirect('cp/system/languages/translate/' . $plugin . '/' . $language);
 }
开发者ID:soremi,项目名称:tutornavi,代码行数:44,代码来源:languages.php

示例9: checkRules

 private function checkRules($modelAction)
 {
     if (method_exists($this, 'rules')) {
         $rules = $this->rules();
         if (!empty($rules)) {
             foreach ($rules as $val) {
                 validate::run($this->data, $val, $this->attributes, $modelAction, $this);
             }
         }
     }
 }
开发者ID:jeremywong1992,项目名称:companyBook,代码行数:11,代码来源:model.class.php

示例10: _saveNewsletter

 protected function _saveNewsletter($newsletterID)
 {
     // Check if demo mode is enabled
     if (input::demo()) {
         return false;
     }
     // Create rules
     $rules = array('category_id' => array('label' => __('gift_category', 'gifts'), 'rules' => array('intval')));
     // Get newsletter data
     $newsletterData = $input = array();
     $rules['subject'] = array('label' => __('newsletter_subject', 'newsletters'), 'rules' => array('trim', 'required', 'max_length' => 255));
     $rules['message_html'] = array('label' => __('newsletter_message_html', 'newsletters'), 'rules' => array('trim', 'required'));
     $rules['message_text'] = array('label' => __('newsletter_message_text', 'newsletters'), 'rules' => array('trim', 'required'));
     $input = array('subject', 'message_html', 'message_text');
     // Assign rules
     validate::setRules($rules);
     // Validate fields
     if (!validate::run()) {
         return false;
     }
     // Get newsletter data
     $newsletter = input::post($input);
     // Save newsletter
     if (!($newsletterID = $this->newsletters_model->saveNewsletter($newsletterID, $newsletter))) {
         view::setError(__('save_error', 'system'));
         return false;
     }
     router::redirect('cp/content/newsletters/' . (uri::segment(6) == 'review' ? 'review' : 'recipients') . '/' . $newsletterID);
 }
开发者ID:soremi,项目名称:tutornavi,代码行数:29,代码来源:newsletters.php

示例11: _saveTemplate

 protected function _saveTemplate($templateID, $keyword)
 {
     // Check if demo mode is enabled
     if (input::demo()) {
         return false;
     }
     // Rules and input arrays
     $rules = $input = array();
     // Build rules
     foreach (config::item('languages', 'core', 'keywords') as $languageID => $language) {
         // Make sure this is not a header/footer template
         if (!in_array($keyword, array('header', 'footer'))) {
             $rules['subject_' . $language] = array('label' => __('template_subject', 'system_email_templates') . (count(config::item('languages', 'core', 'keywords')) > 1 ? ' [' . config::item('languages', 'core', 'names', $languageID) . ']' : ''), 'rules' => array('trim', 'required'));
             $input[] = 'subject_' . $language;
         }
         $rules['message_html_' . $language] = array('label' => __('template_message_html', 'system_email_templates') . (count(config::item('languages', 'core', 'keywords')) > 1 ? ' [' . config::item('languages', 'core', 'names', $languageID) . ']' : ''), 'rules' => array('trim', 'required'));
         $rules['message_text_' . $language] = array('label' => __('template_message_text', 'system_email_templates') . (count(config::item('languages', 'core', 'keywords')) > 1 ? ' [' . config::item('languages', 'core', 'names', $languageID) . ']' : ''), 'rules' => array('trim', 'required'));
         $rules['active'] = array('label' => __('active', 'system'), 'rules' => array('required', 'intval'));
         $input[] = 'message_html_' . $language;
         $input[] = 'message_text_' . $language;
         $input[] = 'active';
     }
     // Assign rules
     validate::setRules($rules);
     // Validate fields
     if (!validate::run()) {
         return false;
     }
     // Get template data
     $template = input::post($input);
     // Save template data
     $this->emailtemplates_model->saveTemplate($templateID, $template);
     // Success
     view::setInfo(__('template_saved', 'system_email_templates'));
     router::redirect('cp/system/emailtemplates/edit/' . $templateID);
 }
开发者ID:soremi,项目名称:tutornavi,代码行数:36,代码来源:emailtemplates.php

示例12: _saveMetaTags

 protected function _saveMetaTags($plugin, $tags)
 {
     // Check if demo mode is enabled
     if (input::demo()) {
         return false;
     }
     $rules = array();
     foreach ($tags as $keyword => $group) {
         foreach (config::item('languages', 'core', 'keywords') as $language) {
             $rules[$keyword . '_title_' . $language] = $rules[$keyword . '_description_' . $language] = $rules[$keyword . '_keywords_' . $language] = array('label' => '', 'rules' => array('is_string', 'trim', 'max_length' => 255));
         }
     }
     validate::setRules($rules);
     if (!validate::run()) {
         return false;
     }
     foreach ($tags as $keyword => $group) {
         $data = array();
         foreach (config::item('languages', 'core', 'keywords') as $language) {
             $data['meta_title_' . $language] = input::post($keyword . '_title_' . $language);
             $data['meta_description_' . $language] = input::post($keyword . '_description_' . $language);
             $data['meta_keywords_' . $language] = input::post($keyword . '_keywords_' . $language);
         }
         $this->metatags_model->saveMetaTags($plugin, $keyword, $data);
     }
     view::setInfo(__('meta_tags_saved', 'system_metatags'));
     router::redirect('cp/system/metatags/edit/' . $plugin);
 }
开发者ID:soremi,项目名称:tutornavi,代码行数:28,代码来源:metatags.php

示例13: _savePlan

 protected function _savePlan($planID)
 {
     // Check if demo mode is enabled
     if (input::demo()) {
         return false;
     }
     // Rules array
     $rules = array();
     // Data array
     $input = array('duration', 'cycle', 'price', 'group_id', 'signup', 'active');
     // Name
     foreach (config::item('languages', 'core', 'keywords') as $languageID => $languageKey) {
         $rules['name_' . $languageKey] = array('label' => __('name', 'system') . (count(config::item('languages', 'core', 'keywords')) > 1 ? ' [' . config::item('languages', 'core', 'names', $languageID) . ']' : ''), 'rules' => array('trim', 'required', 'max_length' => 255));
         $input[] = 'name_' . $languageKey;
         $rules['description_' . $languageKey] = array('label' => __('description', 'system') . (count(config::item('languages', 'core', 'keywords')) > 1 ? ' [' . config::item('languages', 'core', 'names', $languageID) . ']' : ''), 'rules' => array('trim', 'required'));
         $input[] = 'description_' . $languageKey;
     }
     // Additional rules
     $rules['duration'] = array('label' => __('plan_cycle', 'billing_plans'), 'rules' => array('trim', 'required', 'is_natural_no_zero'));
     $rules['cycle'] = array('label' => __('plan_cycle', 'billing_plans'), 'rules' => array('trim', 'required', 'intval'));
     $rules['price'] = array('label' => __('price', 'billing'), 'rules' => array('trim', 'required', 'numeric'));
     $rules['group_id'] = array('label' => __('user_group', 'users'), 'rules' => array('trim', 'required', 'intval'));
     $rules['signup'] = array('label' => __('plan_show_signup', 'billing_plans'), 'rules' => array('trim', 'required', 'intval'));
     $rules['active'] = array('label' => __('active', 'system'), 'rules' => array('trim', 'required', 'intval'));
     // Assign rules
     validate::setRules($rules);
     // Validate fields
     if (!validate::run()) {
         return false;
     }
     // Get post data
     $plan = input::post($input);
     // Save banner group
     if (!($planID = $this->plans_model->savePlan($planID, $plan))) {
         view::setError(__('save_error', 'system'));
         return false;
     }
     // Success
     view::setInfo(__('plan_saved', 'billing_plans'));
     router::redirect('cp/billing/plans/edit/' . $planID);
 }
开发者ID:soremi,项目名称:tutornavi,代码行数:41,代码来源:plans.php

示例14: _saveMessage

 protected function _saveMessage($conversationID, $conversation)
 {
     // Are we allowed to reply?
     if ($conversation['user_id'] == session::item('user_id') && !session::permission('messages_reply', 'messages') || !in_array($conversation['users'][$conversation['user_id']]['group_id'], session::permission('messages_reply', 'messages'))) {
         view::setError(__('no_action', 'system'));
         return false;
     } elseif (config::item('credits_active', 'billing') && session::permission('messages_credits', 'messages') && session::permission('messages_credits', 'messages') > session::item('total_credits')) {
         view::setError(__('no_credits', 'system', array(), array('%' => html_helper::anchor('billing/credits', '\\1'))));
         return false;
     }
     // Create rules
     $rules = array('message' => array('label' => __('message', 'messages'), 'rules' => array('trim', 'required', 'callback__is_messages_delay')));
     // Do we have character limit?
     if (session::permission('messages_characters_limit', 'messages')) {
         $rules['message']['rules']['max_length'] = session::permission('messages_characters_limit', 'messages');
     }
     // Assign rules
     validate::setRules($rules);
     // Validate fields
     if (!validate::run()) {
         return false;
     }
     // Get input data
     $message = input::post('message');
     // Save message
     if (!($messageID = $this->messages_model->saveMessage(0, $conversationID, $message, $conversation['recipients']))) {
         if (!validate::getTotalErrors()) {
             view::setError(__('save_error', 'system'));
         }
         return false;
     }
     // Create email replacement tags
     $tags = array();
     foreach (session::section('session') as $key => $value) {
         $tags['from.' . $key] = $value;
     }
     $tags['conversation_link'] = config::siteURL('messages/view/' . $conversationID);
     // Send new private message email
     loader::library('email');
     foreach ($conversation['users'] as $user) {
         if ($user['user_id'] != session::item('user_id') && (!isset($user['config']['notify_messages']) || $user['config']['notify_messages'])) {
             $this->email->sendTemplate('messages_new', $user['email'], array_merge($tags, $user), $user['language_id']);
         }
     }
     // Success
     view::setInfo(__('message_sent', 'messages'));
     router::redirect('messages/view/' . $conversationID);
 }
开发者ID:soremi,项目名称:tutornavi,代码行数:48,代码来源:messages.php

示例15: validateValues

 public function validateValues($fields, $rules = array())
 {
     // Loop through fields
     foreach ($fields as $field) {
         // Is this a data field?
         if (isset($field['system'])) {
             // Is this a multi language field?
             if ($field['multilang']) {
                 $languages = array();
                 foreach (config::item('languages', 'core', 'keywords') as $languageID => $languageKey) {
                     $languages[] = array('keyword' => '_' . $languageKey, 'language' => config::item('languages', 'core', 'names', $languageID));
                 }
             } else {
                 $languages = array(array('keyword' => '', 'language' => ''));
             }
             // Loop through fields
             foreach ($languages as $param) {
                 // Is this a section divider?
                 if ($field['type'] != 'section') {
                     $keyword = 'data_' . $field['keyword'] . $param['keyword'];
                     // Create basic rule
                     $rules[$keyword] = array('label' => text_helper::entities($field['name']) . ($param['language'] ? count($languages) > 1 ? ' [' . $param['language'] . ']' : '' : ''), 'rules' => array());
                     // Required
                     if ($field['required']) {
                         if ($field['type'] == 'birthday') {
                             foreach (array('day', 'month', 'year') as $index) {
                                 $rules['data_' . $field['keyword'] . $param['keyword'] . '[' . $index . ']']['label'] = $field['name'];
                                 $rules['data_' . $field['keyword'] . $param['keyword'] . '[' . $index . ']']['rules'][] = 'required';
                             }
                             $value = input::post($keyword);
                         } elseif ($field['type'] == 'location') {
                             foreach (array('country', 'state', 'city') as $index) {
                                 $rules['data_' . $field['keyword'] . $param['keyword'] . '[' . $index . ']']['label'] = $field['name'];
                                 $rules['data_' . $field['keyword'] . $param['keyword'] . '[' . $index . ']']['rules'][] = 'required';
                             }
                             $value = input::post($keyword);
                         } else {
                             $rules[$keyword]['rules'][] = 'required';
                         }
                     }
                     // Field types
                     if ($this->getValueFormat($field['type']) == 'text') {
                         $rules[$keyword]['rules'][] = 'is_string';
                     } elseif ($this->getValueFormat($field['type']) == 'number') {
                         $rules[$keyword]['rules'][] = 'intval';
                         $rules[$keyword]['rules'][] = 'is_numeric';
                     } elseif ($this->getValueFormat($field['type']) == 'double') {
                         $rules[$keyword]['rules'][] = 'is_numeric';
                     }
                     if ($field['type'] == 'website') {
                         $rules[$keyword]['rules']['valid_url'] = array(array('http://', 'https://'));
                     }
                     // Min/max rules
                     foreach (array('min_length', 'max_length', 'min_value', 'max_value') as $rule) {
                         if (isset($field['config'][$rule]) && $field['config'][$rule]) {
                             $rules[$keyword]['rules'][$rule] = array($field['config'][$rule]);
                         }
                     }
                     // Validation
                     if (isset($field['validate']) && $field['validate']) {
                         $rules[$keyword]['rules']['regex'] = array($field['validate']);
                         validate::setError('data_' . $field['keyword'] . '_regex', $field['validate_error'], $field['keyword'] . $param['keyword']);
                     }
                 }
             }
         }
     }
     // Set rules
     validate::setRules($rules);
     // Validate fields
     if (!validate::run()) {
         return false;
     }
     return true;
 }
开发者ID:soremi,项目名称:tutornavi,代码行数:75,代码来源:fields.php


注:本文中的validate::run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。