Example #1
0
 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');
 }
Example #2
0
 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' : ''));
 }
Example #3
0
 protected function _saveAlbum($albumID, $album, $fields)
 {
     // Extra rules
     $rules = array('comments' => array('rules' => 'intval'), 'privacy' => array('rules' => 'intval'), 'public' => array('rules' => 'intval'));
     // Validate form values
     if (!$this->fields_model->validateValues($fields, $rules)) {
         return false;
     }
     // Extra fields
     $extra = array();
     $extra['comments'] = config::item('picture_comments', 'pictures') && config::item('picture_privacy_comments', 'pictures') ? (int) input::post('comments') : 1;
     $extra['privacy'] = config::item('album_privacy_view', 'pictures') ? (int) input::post('privacy') : 1;
     $extra['public'] = config::item('album_privacy_public', 'pictures') ? (int) input::post('public') : 1;
     // Save album
     if (!($albumID = $this->pictures_albums_model->saveAlbumData($albumID, session::item('user_id'), $album, $fields, $extra))) {
         if (!validate::getTotalErrors()) {
             view::setError(__('save_error', 'system'));
         }
         return false;
     }
     // Success
     view::setInfo(__('album_saved', 'pictures'));
     router::redirect('pictures/albums/edit/' . $albumID);
 }
Example #4
0
 protected function _savePage($pageID, $parentID, $page, $fields, $options, $trail)
 {
     // Check if demo mode is enabled
     if (input::demo()) {
         return false;
     }
     // Extra rules
     $rules = array();
     foreach ($options as $option) {
         if (isset($option['rules'])) {
             $rules[$option['keyword']] = array('label' => $option['name'], 'rules' => $option['rules']);
         }
     }
     $rules['keyword'] = array('label' => __('keyword', 'system'), 'rules' => array('trim', 'required', 'max_length' => 128, 'callback__is_valid_keyword' => array($parentID, $pageID)));
     // Validate form values
     if (!$this->fields_model->validateValues($fields, $rules)) {
         return false;
     }
     // Did keyword change?
     if ($pageID && $page['system'] && strcmp($page['keyword'], input::post('keyword'))) {
         validate::setFieldError('keyword', __('page_system_rename', 'pages'));
         return false;
     }
     // Extras
     $extra = array();
     $extra['parent_id'] = $parentID;
     $extra['location'] = ($trail ? implode('/', $trail) . '/' : '') . input::post('keyword');
     $extra['keyword'] = input::post('keyword');
     $extra['file_name'] = input::post('file_name');
     $extra['comments'] = config::item('page_comments', 'pages') ? (int) input::post('comments') : 1;
     $extra['likes'] = config::item('page_rating', 'pages') == 'likes' ? (int) input::post('likes') : 1;
     $extra['votes'] = config::item('page_rating', 'pages') == 'stars' ? (int) input::post('votes') : 1;
     $extra['trail'] = (int) input::post('trail');
     $extra['active'] = (int) input::post('active');
     // Save page
     if (!($pageID = $this->pages_model->savePageData($pageID, $parentID, $page, $fields, $extra))) {
         if (!validate::getTotalErrors()) {
             view::setError(__('save_error', 'system'));
         }
         return false;
     }
     // Success
     view::setInfo(__('page_saved', 'pages'));
     router::redirect('cp/content/pages/edit/' . $parentID . '/' . $pageID);
 }
Example #5
0
 protected function _saveAlbum($albumID, $album, $fields)
 {
     // Check if demo mode is enabled
     if (input::demo()) {
         return false;
     }
     // Extra rules
     $rules = array('comments' => array('rules' => 'intval'), 'privacy' => array('rules' => 'intval'), 'public' => array('rules' => 'intval'));
     // Validate form values
     if (!$this->fields_model->validateValues($fields, $rules)) {
         return false;
     }
     // Extras
     $extra = array();
     $extra['comments'] = config::item('picture_comments', 'pictures') && config::item('picture_privacy_comments', 'pictures') ? (int) input::post('comments') : 1;
     $extra['privacy'] = config::item('album_privacy_view', 'pictures') ? (int) input::post('privacy') : 1;
     $extra['public'] = config::item('album_privacy_public', 'pictures') ? (int) input::post('public') : 1;
     // Save album
     if (!($albumID = $this->pictures_albums_model->saveAlbumData($albumID, 0, $album, $fields, $extra))) {
         if (!validate::getTotalErrors()) {
             view::setError(__('save_error', 'system'));
         }
         return false;
     }
     // Success
     view::setInfo(__('album_saved', 'pictures', array(), array('%1' => html_helper::anchor('cp/plugins/pictures/albums/edit/' . $albumID, '\\1'), '%2' => html_helper::anchor('cp/plugins/pictures/browse/' . $albumID, '\\1'))));
     router::redirect('cp/plugins/pictures/albums/edit/' . $albumID);
 }
Example #6
0
 protected function _saveMessage($messageID, $message)
 {
     // Check if demo mode is enabled
     if (input::demo()) {
         return false;
     }
     // Create rules
     $rules = array('message' => array('label' => __('message', 'messages'), 'rules' => array('trim', 'required')));
     // Assign rules
     validate::setRules($rules);
     // Validate fields
     if (!validate::run()) {
         return false;
     }
     // Get input data
     $body = input::post('message');
     // Save message
     if (!($messageID = $this->messages_model->saveMessage($messageID, $message['conversation_id'], $body))) {
         if (!validate::getTotalErrors()) {
             view::setError(__('save_error', 'system'));
         }
         return false;
     }
     // Success
     view::setInfo(__('message_saved', 'messages'));
     router::redirect('cp/plugins/messages/edit/' . $messageID);
 }
Example #7
0
 protected function _savePicture($pictureID, $adID, $picture, $ad, $fields)
 {
     // Check if demo mode is enabled
     if (input::demo()) {
         return false;
     }
     // Validate form values
     if (!$this->fields_model->validateValues($fields)) {
         return false;
     }
     // Extras
     $extra = array();
     $extra['active'] = (int) input::post('active');
     // Save picture
     if (!($pictureID = $this->classifieds_pictures_model->savePictureData($pictureID, $adID, $picture, $ad, $fields, $extra))) {
         if (!validate::getTotalErrors()) {
             view::setError(__('save_error', 'system'));
         }
         return false;
     }
     // Success
     view::setInfo(__('picture_saved', 'classifieds'));
     router::redirect('cp/plugins/classifieds/pictures/edit/' . $adID . '/' . $pictureID);
 }
Example #8
0
 public function vote()
 {
     // Is user logged in?
     if (!users_helper::isLoggedin()) {
         view::ajaxError(__('no_login', 'system_info'), 403);
     }
     // Get vars
     $resource = input::post_get('resource');
     $itemID = (int) input::post_get('item_id');
     $score = (int) input::post_get('score');
     // Get resource ID
     $resourceID = config::item('resources', 'core', $resource, 'resource_id');
     if (!$resourceID || !$itemID || $score < 1 || $score > 5) {
         return false;
     }
     // Load votes model
     loader::model('comments/votes');
     // Get resource item and vote if exists
     $item = $this->votes_model->getResourceVote($resource, $itemID);
     // Do resource or vote exist?
     if (!$item || $item['post_date']) {
         return false;
     }
     // Save vote
     if (!$this->votes_model->saveVote($resource, isset($item['user_id']) ? $item['user_id'] : 0, $itemID, $score)) {
         if (!validate::getTotalErrors()) {
             view::setError(__('save_error', 'system'));
         }
         return false;
     }
     $rating = number_format(($item['total_score'] + $score) / ($item['total_votes'] + 1), 2);
     $params = array('resource' => $resource, 'itemID' => $itemID, 'votes' => $item['total_votes'] + 1, 'score' => $item['total_score'], 'rating' => $rating, 'voted' => $score, 'date' => date_helper::now());
     $output = view::load('comments/rating', $params, true);
     view::ajaxResponse($output);
 }
Example #9
0
 protected function _saveBanner($groupID, $bannerID, $bannerOld)
 {
     // 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' => array($groupID, $bannerID))), 'code' => array('label' => __('banner_code', 'banners'), 'rules' => array('trim', 'required')), 'count_views' => array('label' => __('banner_count_views', 'banners'), 'rules' => array('trim', 'intval')), 'total_views' => array('label' => __('banner_views', 'banners'), 'rules' => array('trim', 'intval')), 'count_clicks' => array('label' => __('banner_count_clicks', 'banners'), 'rules' => array('trim', 'intval')), 'total_clicks' => array('label' => __('banner_clicks', 'banners'), 'rules' => array('trim', 'intval')), 'secure_mode' => array('label' => __('banner_secure_mode', 'banners'), 'rules' => array('trim', 'intval')), 'active' => array('label' => __('active', 'system'), 'rules' => array('trim', 'intval')));
     // Assign rules
     validate::setRules($rules);
     // Validate fields
     if (!validate::run()) {
         return false;
     }
     // Banner data
     $bannerData = input::post(array('name', 'keyword', 'code', 'count_views', 'total_views', 'count_clicks', 'total_clicks', 'secure_mode', 'active'));
     $bannerData['group_id'] = $groupID;
     // Save banner
     if (!($bannerID = $this->banners_model->saveBanner($groupID, $bannerID, $bannerData))) {
         if (!validate::getTotalErrors()) {
             view::setError(__('save_error', 'system'));
         }
         return false;
     }
     // Success
     view::setInfo(__('banner_saved', 'banners'));
     router::redirect('cp/content/banners/edit/' . $groupID . '/' . $bannerID);
 }
Example #10
0
 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);
 }
Example #11
0
 protected function _saveMessage($userID)
 {
     // Is user logged in?
     if (!users_helper::isLoggedin()) {
         return false;
     }
     if ($userID) {
         // Get user
         if (!($user = $this->users_model->getUser($userID)) || !$user['active'] || !$user['verified']) {
             return false;
         }
         // Does user have permission to view this user group/type?
         if (!in_array($user['group_id'], session::permission('users_groups_browse', 'users')) || !in_array($user['type_id'], session::permission('users_types_browse', 'users'))) {
             return false;
         } elseif (!$this->users_model->getPrivacyAccess($user['user_id'], isset($user['config']['privacy_profile']) ? $user['config']['privacy_profile'] : 1)) {
             return false;
         } elseif (!session::permission('messages_post', 'timeline') || !$this->users_model->getPrivacyAccess($user['user_id'], isset($user['config']['privacy_timeline_messages']) ? $user['config']['privacy_timeline_messages'] : 1, false)) {
             return false;
         }
     } else {
         $userID = session::item('user_id');
     }
     // Load messages model
     loader::model('timeline/messages', array(), 'timeline_messages_model');
     // Create rules
     $rules = array('message' => array('label' => __('message', 'timeline'), 'rules' => array('trim', 'required', 'min_length' => config::item('message_min_length', 'timeline'), 'max_length' => config::item('message_max_length', 'timeline'), 'callback__is_messages_delay')));
     // Assign rules
     validate::setRules($rules);
     // Validate fields
     if (!validate::run()) {
         $output = view::load('timeline/post', array('user' => $user), true);
         view::ajaxError($output);
     }
     // Get message
     $message = input::post('message');
     // Save message
     if (!($messageID = $this->timeline_messages_model->saveMessage(0, $message, $userID))) {
         if (!validate::getTotalErrors()) {
             view::setError(__('save_error', 'system'));
         }
         return false;
     }
     $actions = $this->timeline_model->getActions($userID, 0, 0, 1);
     $output = view::load('timeline/actions', array('actions' => $actions), true);
     view::ajaxResponse($output);
 }
Example #12
0
 protected function _savePicture($pictureID, $adID, $picture, $ad, $fields)
 {
     // Create rules
     $rules = array();
     // Validate form values
     if (!$this->fields_model->validateValues($fields, $rules)) {
         return false;
     }
     // Extras
     $extra = array();
     // Save picture
     if (!($pictureID = $this->classifieds_pictures_model->savePictureData($pictureID, $adID, $picture, $ad, $fields, $extra))) {
         if (!validate::getTotalErrors()) {
             view::setError(__('save_error', 'system'));
         }
         return false;
     }
     // Success
     view::setInfo(__('picture_saved', 'classifieds'));
     router::redirect('classifieds/pictures/edit/' . $adID . '/' . $pictureID);
 }
Example #13
0
 protected function _saveEntry($newsID, $news, $fields)
 {
     // Check if demo mode is enabled
     if (input::demo()) {
         return false;
     }
     // Extra rules
     $rules = array('comments' => array('rules' => 'intval'), 'likes' => array('rules' => 'intval'), 'votes' => array('rules' => 'intval'), 'active' => array('rules' => 'intval'));
     // Validate form values
     if (!$this->fields_model->validateValues($fields, $rules)) {
         return false;
     }
     // Extras
     $extra = array();
     $extra['comments'] = config::item('news_comments', 'news') ? (int) input::post('comments') : 1;
     $extra['likes'] = config::item('news_rating', 'news') == 'likes' ? (int) input::post('likes') : 1;
     $extra['votes'] = config::item('news_rating', 'news') == 'stars' ? (int) input::post('votes') : 1;
     $extra['active'] = (int) input::post('active');
     // Save news
     if (!($newsID = $this->news_model->saveEntryData($newsID, $news, $fields, $extra))) {
         if (!validate::getTotalErrors()) {
             view::setError(__('save_error', 'system'));
         }
         return false;
     }
     // Success
     view::setInfo(__('entry_saved', 'news'));
     router::redirect('cp/content/news/edit/' . $newsID);
 }
Example #14
0
 protected function _saveAd($adID, $ad, $fields)
 {
     // Extra rules
     $rules = array('comments' => array('rules' => 'intval'));
     // Validate form values
     if (!$this->fields_model->validateValues($fields, $rules)) {
         return false;
     }
     // Extra fields
     $extra = array();
     $extra['comments'] = config::item('ad_comments', 'classifieds') && config::item('ad_privacy_comments', 'classifieds') ? (int) input::post('comments') : 1;
     // Save ad
     if (!($adID = $this->classifieds_model->saveAdData($adID, session::item('user_id'), $ad, $fields, $extra))) {
         if (!validate::getTotalErrors()) {
             view::setError(__('save_error', 'system'));
         }
         return false;
     }
     // Success
     view::setInfo(__('ad_saved', 'classifieds'));
     router::redirect('classifieds/edit/' . $adID);
 }
Example #15
0
 protected function _saveBlog($blogID, $blog, $fields)
 {
     // Check if demo mode is enabled
     if (input::demo()) {
         return false;
     }
     // Extra rules
     $rules = array('comments' => array('rules' => 'intval'), 'privacy' => array('rules' => 'intval'), 'public' => array('rules' => 'intval'), 'active' => array('rules' => 'intval'));
     // Validate form values
     if (!$this->fields_model->validateValues($fields, $rules)) {
         return false;
     }
     // Extras
     $extra = array();
     $extra['comments'] = config::item('blog_comments', 'blogs') && config::item('blog_privacy_comments', 'blogs') ? (int) input::post('comments') : 1;
     $extra['privacy'] = config::item('blog_privacy_view', 'blogs') ? (int) input::post('privacy') : 1;
     $extra['public'] = config::item('blog_privacy_public', 'blogs') ? (int) input::post('public') : 1;
     $extra['active'] = (int) input::post('active');
     // Save blog
     if (!($blogID = $this->blogs_model->saveBlogData($blogID, 0, $blog, $fields, $extra))) {
         if (!validate::getTotalErrors()) {
             view::setError(__('save_error', 'system'));
         }
         return false;
     }
     // Success
     view::setInfo(__('blog_saved', 'blogs'));
     router::redirect('cp/plugins/blogs/edit/' . $blogID);
 }
Example #16
0
 protected function _saveComment($commentID, $comment, $fields)
 {
     // Check if demo mode is enabled
     if (input::demo()) {
         return false;
     }
     // Create rules
     $rules = array();
     foreach ($fields as $field) {
         if (isset($field['rules'])) {
             $rules[$field['keyword']] = array('label' => $field['name'], 'rules' => $field['rules']);
         }
     }
     // Assign rules
     validate::setRules($rules);
     // Validate fields
     if (!validate::run()) {
         return false;
     }
     // Get input data
     $data = array();
     foreach ($fields as $field) {
         $data[$field['keyword']] = input::post($field['keyword']);
     }
     // Save comment
     if (!($commentID = $this->comments_model->saveComment($commentID, $data))) {
         if (!validate::getTotalErrors()) {
             view::setError(__('save_error', 'system'));
         }
         return false;
     }
     // Success
     view::setInfo(__('comment_saved', 'comments'));
     router::redirect('cp/plugins/comments/edit/' . $commentID);
 }