Example #1
0
 /**
  * Remove a location from a post.
  *
  * @since	3.0
  * @access	public
  */
 public function removeLocation($id)
 {
     $ajax = new Disjax();
     $post = DiscussHelper::getTable('Post');
     $state = $post->load($id);
     $my = JFactory::getUser();
     if (!$id || !$state) {
         echo JText::_('COM_EASYDISCUSS_INVALID_ID');
         return $ajax->send();
     }
     if ($post->user_id != $my->id && !DiscussHelper::isModerator($post->category_id)) {
         echo JText::_('COM_EASYDISCUSS_NOT_ALLOWED_TO_REMOVE_LOCATION_FOR_POST');
         return $ajax->send();
     }
     // Update the address, latitude and longitude of the post.
     $post->address = '';
     $post->latitude = '';
     $post->longitude = '';
     $post->store();
     $content = JText::_('COM_EASYDISCUSS_LOCATION_IS_REMOVED');
     $options = new stdClass();
     $options->content = $content;
     $options->title = JText::_('COM_EASYDISCUSS_DELETE_LOCATION_TITLE');
     $buttons = array();
     $button = new stdClass();
     $button->title = JText::_('COM_EASYDISCUSS_BUTTON_CLOSE');
     $button->action = 'disjax.closedlg();';
     $buttons[] = $button;
     $options->buttons = $buttons;
     $ajax->script('discuss.location.removeHTML("' . $id . '");');
     $ajax->dialog($options);
     return $ajax->send();
 }
Example #2
0
 public function deleteAttachment($id)
 {
     require_once JPATH_ROOT . '/components/com_easydiscuss/controllers/attachment.php';
     $disjax = new Disjax();
     $controller = new EasyDiscussControllerAttachment();
     $msg = JText::_('COM_EASYDISCUSS_ATTACHMENT_DELETE_FAILED');
     $msgClass = 'dc_error';
     if ($controller->deleteFile($id)) {
         $msg = JText::_('COM_EASYDISCUSS_ATTACHMENT_DELETE_SUCCESS');
         $msgClass = 'dc_success';
         $disjax->script('EasyDiscuss.$( "#dc-attachments-' . $id . '" ).remove();');
     }
     $disjax->assign('dc_post_notification .msg_in', $msg);
     $disjax->script('EasyDiscuss.$( "#dc_post_notification .msg_in" ).addClass( "' . $msgClass . '" );');
     $disjax->script('EasyDiscuss.$( "#button-delete-att-' . $id . '" ).prop("disabled", false);');
     $disjax->send();
 }
Example #3
0
 public function ajaxSubmitEmail($data)
 {
     $my = JFactory::getUser();
     $djax = new Disjax();
     $post = DiscussStringHelper::ajaxPostToArray($data);
     if ($my->id == 0) {
         $djax->alert(JText::_('COM_EASYDISCUSS_YOU_DO_NOT_HAVE_PERMISION_TO_SUBMIT_REPORT'), JText::_('ERROR'), '450', 'auto');
         $djax->send();
         return;
     }
     // Load language files from front end.
     JFactory::getLanguage()->load('com_easydiscuss', JPATH_ROOT);
     if (empty($post['post_id'])) {
         $djax->alert(JText::_('COM_EASYDISCUSS_INVALID_POST_ID'), JText::_('ERROR'), '450', 'auto');
         $djax->send();
         return;
     }
     $postId = (int) $post['post_id'];
     $emailContent = $post['content'];
     // Prepare email data
     $postTbl = JTable::getInstance('posts', 'Discuss');
     $postTbl->load($postId);
     $moderator = DiscussHelper::getTable('Profile');
     $moderator->load($my->id);
     $creator = JFactory::getUser($postTbl->user_id);
     $date = DiscussHelper::getDate($postTbl->created);
     $emailData = array();
     $emailData['postAuthor'] = $moderator->getName();
     $emailData['postAuthorAvatar'] = $moderator->getAvatar();
     $emailData['postDate'] = $date->toFormat();
     $emailData['postLink'] = JURI::root() . 'index.php?option=com_easydiscuss&view=post&id=' . $postTbl->id;
     $emailData['postTitle'] = $postTbl->title;
     $emailData['messages'] = $emailContent;
     if (!empty($postTbl->parent_id)) {
         $parentTbl = JTable::getInstance('posts', 'Discuss');
         $parentTbl->load($postTbl->parent_id);
         $emailData['postTitle'] = $parentTbl->title;
         $emailData['postLink'] = JURI::root() . 'index.php?option=com_easydiscuss&view=post&id=' . $parentTbl->id;
     }
     $noti = DiscussHelper::getNotification();
     $noti->addQueue($creator->email, JText::sprintf('COM_EASYDISCUSS_REQUIRED_YOUR_ATTENTION', $emailData['postTitle']), '', 'email.report.attention.php', $emailData);
     $djax->assign('report-entry-msg-' . $postId, JText::_('COM_EASYDISCUSS_EMAIL_SENT_TO_AUTHOR'));
     $djax->script('admin.reports.revertEmailForm("' . $postId . '");');
     $djax->send();
     return;
 }
Example #4
0
 public function filter($viewtype = 'user-post', $profileId = null)
 {
     $ajax = new Disjax();
     $mainframe = JFactory::getApplication();
     $config = DiscussHelper::getConfig();
     $acl = DiscussHelper::getHelper('ACL');
     $sort = 'latest';
     $data = null;
     $pagination = null;
     $model = $this->getModel('Posts');
     $tagsModel = $this->getModel('Tags');
     switch ($viewtype) {
         case 'user-achievements':
             $profile = DiscussHelper::getTable('Profile');
             $profile->load($profileId);
             $data = $profile->getBadges();
             break;
         case 'user-tags':
             $data = $tagsModel->getTagCloud('', '', '', $profileId);
             break;
         case 'user-replies':
             $data = $model->getRepliesFromUser($profileId);
             $pagination = $model->getPagination();
             DiscussHelper::formatPost($data);
             break;
         case 'user-unresolved':
             $data = $model->getUnresolvedFromUser($profileId);
             $pagination = $model->getPagination();
             DiscussHelper::formatPost($data);
             break;
         case 'user-post':
         default:
             if (is_null($profileId)) {
                 break;
             }
             $model = $this->getModel('Posts');
             $data = $model->getPostsBy('user', $profileId);
             $data = DiscussHelper::formatPost($data);
             $pagination = $model->getPagination();
             break;
     }
     // replace the content
     $content = '';
     $tpl = new DiscussThemes();
     $tpl->set('profileId', $profileId);
     if ($viewtype == 'user-post' || $viewtype == 'user-replies' || $viewtype == 'user-unresolved') {
         $nextLimit = DiscussHelper::getListLimit();
         if ($nextLimit >= $pagination->total) {
             // $ajax->remove( 'dc_pagination' );
             $ajax->assign($viewtype . ' #dc_pagination', '');
         }
         $tpl->set('posts', $data);
         $content = $tpl->fetch('main.item.php');
         $ajax->assign($viewtype . ' #dc_list', $content);
         //reset the next start limi
         $ajax->value('pagination-start', $nextLimit);
         if ($nextLimit < $pagination->total) {
             $filterArr = array();
             $filterArr['viewtype'] = $viewtype;
             $filterArr['id'] = $profileId;
             $ajax->assign($viewtype . ' #dc_pagination', $pagination->getPagesLinks('profile', $filterArr, true));
         }
     } else {
         if ($viewtype == 'user-tags') {
             $tpl->set('tagCloud', $data);
             $content = $tpl->fetch('tags.item.php');
             $ajax->assign('discuss-tag-list', $content);
         } else {
             if ($viewtype == 'user-achievements') {
                 $tpl->set('badges', $data);
                 $content = $tpl->fetch('users.achievements.list.php');
                 $ajax->assign('user-achievements', $content);
             }
         }
     }
     $ajax->script('discuss.spinner.hide( "profile-loading" );');
     //$ajax->assign( 'sort-wrapper' , $sort );
     //$ajax->script( 'EasyDiscuss.$("#pagination-filter").val("'.$viewtype.'");');
     $ajax->script('EasyDiscuss.$("#' . $viewtype . '").show();');
     $ajax->script('EasyDiscuss.$("#' . $viewtype . ' #dc_pagination").show();');
     $ajax->send();
 }
Example #5
0
 public function sort($sort = null, $filter = null, $categoryId = null)
 {
     $ajax = new Disjax();
     $mainframe = JFactory::getApplication();
     $user = JFactory::getUser();
     $config = DiscussHelper::getConfig();
     $acl = DiscussHelper::getHelper('ACL');
     $activeCategory = DiscussHelper::getTable('Category');
     $activeCategory->load($categoryId);
     //todo: check against the config
     $showAllPosts = 'all';
     $postModel = $this->getModel('Posts');
     $posts = $postModel->getData(true, $sort, null, $filter, $categoryId, null, $showAllPosts);
     $pagination = $postModel->getPagination('0', $sort, $filter, $categoryId, $showAllPosts);
     $posts = DiscussHelper::formatPost($posts);
     $nextLimit = DiscussHelper::getListLimit();
     if ($nextLimit >= $pagination->total) {
         $ajax->remove('dc_pagination .pagination-wrap');
     }
     $tpl = new DiscussThemes();
     $tpl->set('posts', $posts);
     $content = $tpl->fetch('main.item.php');
     //reset the next start limi
     $ajax->value('pagination-start', $nextLimit);
     if ($nextLimit < $pagination->total) {
         $filterArr = array();
         $filterArr['filter'] = $filter;
         $filterArr['category_id'] = $categoryId;
         $filterArr['sort'] = $sort;
         $ajax->assign('dc_pagination', $pagination->getPagesLinks('index', $filterArr, true));
     }
     $ajax->script('discuss.spinner.hide( "index-loading" );');
     $ajax->script('EasyDiscuss.$("#pagination-sorting").val("' . $sort . '");');
     $ajax->assign('dc_list', $content);
     $ajax->script('EasyDiscuss.$("#dc_list").show();');
     $ajax->script('EasyDiscuss.$("#dc_pagination").show();');
     $ajax->send();
 }
Example #6
0
 public function ajaxNoStatusPost($id = null)
 {
     $ajax = new Disjax();
     $config = DiscussHelper::getConfig();
     if (!$id) {
         $ajax->assign('dc_main_notifications', JText::_('COM_EASYDISCUSS_SYSTEM_INVALID_ID'));
         $ajax->script('EasyDiscuss.$( "#dc_main_notifications" ).addClass( "alert alert-error" );');
         $ajax->send();
         return;
     }
     $post = DiscussHelper::getTable('Post');
     $post->load($id);
     $isMine = DiscussHelper::isMine($post->user_id);
     $isAdmin = DiscussHelper::isSiteAdmin();
     $acl = DiscussHelper::getHelper('ACL');
     $isModerator = DiscussHelper::getHelper('Moderator')->isModerator($post->category_id);
     if (!$isMine && !$isAdmin && !$acl->allowed('mark_no_status', '0')) {
         if (!$isModerator) {
             $ajax->assign('dc_main_notifications', JText::_('COM_EASYDISCUSS_SYSTEM_INSUFFICIENT_PERMISSIONS'));
             $ajax->script('EasyDiscuss.$( "#dc_main_notifications" ).addClass( "alert alert-error" );');
             $ajax->send();
             return;
         }
     }
     // Turn on the on-hold status,
     // DISCUSS_POST_STATUS_OFF = 0
     $post->post_status = DISCUSS_POST_STATUS_OFF;
     if (!$post->store()) {
         $ajax->assign('dc_main_notifications', $post->getError());
         $ajax->script('EasyDiscuss.$( "#dc_main_notifications" ).addClass( "alert alert-error" );');
         $ajax->send();
         return;
     }
     // @rule: Add notifications for the thread starter
     $my = JFactory::getUser();
     if ($post->get('user_id') != $my->id) {
         $notification = DiscussHelper::getTable('Notifications');
         $notification->bind(array('title' => JText::sprintf('COM_EASYDISCUSS_NO_STATUS_DISCUSSION_NOTIFICATION_TITLE', $post->title), 'cid' => $post->get('id'), 'type' => 'unhold', 'target' => $post->get('user_id'), 'author' => $my->id, 'permalink' => 'index.php?option=com_easydiscuss&view=post&id=' . $post->get('id')));
         $notification->store();
     }
     // Remove other status
     $ajax->script('EasyDiscuss.$( ".discuss-item" ).removeClass( "is-resolved" );');
     $ajax->script('EasyDiscuss.$( ".postStatus" ).removeClass( "label-post_status" );');
     $ajax->script('EasyDiscuss.$( ".postStatus" ).removeClass( "label-post_status-on-hold" );');
     $ajax->script('EasyDiscuss.$( ".postStatus" ).removeClass( "label-post_status-accept" );');
     $ajax->script('EasyDiscuss.$( ".postStatus" ).removeClass( "label-post_status-working-on" );');
     $ajax->script('EasyDiscuss.$( ".postStatus" ).removeClass( "label-post_status-reject" );');
     $ajax->assign('dc_main_notifications', JText::_('COM_EASYDISCUSS_POST_NO_STATUS'));
     $ajax->script('EasyDiscuss.$( "#dc_main_notifications" ).addClass( "alert alert-success" );');
     $ajax->script('EasyDiscuss.$( ".postStatus" ).html("");');
     $ajax->send();
     return;
 }
Example #7
0
 /**
  * Responsible to delete a comment.
  *
  * @since	3.0
  * @access	public
  */
 public function delete($id = null)
 {
     $ajax = new Disjax();
     $id = (int) $id;
     $comment = DiscussHelper::getTable('Comment');
     $comment->load($id);
     if (!$comment->canDelete()) {
         echo JText::_('COM_EASYDISCUSS_COMMENTS_NOT_ALLOWED');
         exit;
     }
     if (!$comment->delete()) {
         echo $comment->getError();
         exit;
     }
     // AUP Integrations
     DiscussHelper::getHelper('Aup')->assign(DISCUSS_POINTS_DELETE_COMMENT, $comment->user_id, '');
     $content = JText::_('COM_EASYDISCUSS_COMMENT_SUCESSFULLY_DELETED');
     $options = new stdClass();
     $options->content = $content;
     $options->title = JText::_('COM_EASYDISCUSS_DELETE_COMMENT');
     $buttons = array();
     $button = new stdClass();
     $button->title = JText::_('COM_EASYDISCUSS_BUTTON_CLOSE');
     $button->action = 'disjax.closedlg();';
     $button->className = 'btn-primary';
     $buttons[] = $button;
     $options->buttons = $buttons;
     $ajax->dialog($options);
     $ajax->script(' discuss.comment.removeEntry("' . $id . '");');
     return $ajax->send();
 }
Example #8
0
 function ajaxAddSubscription($type = 'tag', $email, $name, $interval, $cid = '0')
 {
     $disjax = new Disjax();
     $mainframe = JFactory::getApplication();
     $my = JFactory::getUser();
     $config = DiscussHelper::getConfig();
     $msg = '';
     $msgClass = 'dc_success';
     $subscription_info = array();
     $subscription_info['type'] = $type;
     $subscription_info['userid'] = $my->id;
     $subscription_info['email'] = $email;
     $subscription_info['cid'] = $cid;
     $subscription_info['member'] = $my->id ? '1' : '0';
     $subscription_info['name'] = $my->id ? $my->name : $name;
     $subscription_info['interval'] = $interval;
     //validation
     if (JString::trim($subscription_info['email']) == '') {
         $disjax->script('discuss.spinner.hide( "dialog_loading" );');
         $disjax->assign('dc_subscribe_notification .msg_in', JText::_('COM_EASYDISCUSS_EMAIL_IS_EMPTY'));
         $disjax->script('EasyDiscuss.$( "#dc_subscribe_notification .msg_in" ).addClass( "dc_error" );');
         $disjax->send();
         return;
     }
     if (JString::trim($subscription_info['name']) == '') {
         $disjax->script('discuss.spinner.hide( "dialog_loading" );');
         $disjax->assign('dc_subscribe_notification .msg_in', JText::_('COM_EASYDISCUSS_NAME_IS_EMPTY'));
         $disjax->script('EasyDiscuss.$( "#dc_subscribe_notification .msg_in" ).addClass( "dc_error" );');
         $disjax->send();
         return;
     }
     $model = $this->getModel('Subscribe');
     $sid = '';
     if ($my->id == 0) {
         $sid = $model->isTagSubscribedEmail($subscription_info);
         if ($sid != '') {
             //user found.
             // show message.
             $disjax->script('discuss.spinner.hide( "dialog_loading" );');
             $disjax->assign('dc_subscribe_notification .msg_in', JText::_('COM_EASYDISCUSS_ALREADY_SUBSCRIBED_TO_TAG'));
             $disjax->script('EasyDiscuss.$( "#dc_subscribe_notification .msg_in" ).addClass( "dc_success" );');
             $disjax->send();
             return;
         } else {
             if (!$model->addSubscription($subscription_info)) {
                 $msg = JText::sprintf('COM_EASYDISCUSS_SUBSCRIPTION_FAILED');
                 $msgClass = 'dc_error';
             }
         }
     } else {
         $sid = $model->isTagSubscribedUser($subscription_info);
         if ($sid['id'] != '') {
             // user found.
             // update the email address
             if (!$model->updatePostSubscription($sid['id'], $subscription_info)) {
                 $msg = JText::sprintf('COM_EASYDISCUSS_SUBSCRIPTION_FAILED');
                 $msgClass = 'dc_error';
             }
         } else {
             //add new subscription.
             if (!$model->addSubscription($subscription_info)) {
                 $msg = JText::sprintf('COM_EASYDISCUSS_SUBSCRIPTION_FAILED');
                 $msgClass = 'dc_error';
             }
         }
     }
     $msg = empty($msg) ? JText::_('COM_EASYDISCUSS_SUBSCRIPTION_SUCCESS') : $msg;
     $disjax->script('discuss.spinner.hide( "dialog_loading" );');
     $disjax->assign('dc_subscribe_notification .msg_in', $msg);
     $disjax->script('EasyDiscuss.$( "#dc_subscribe_notification .msg_in" ).addClass( "' . $msgClass . '" );');
     $disjax->send();
     return;
 }
Example #9
0
 public function delete($id)
 {
     $ajax = new Disjax();
     $user = JFactory::getUser();
     // @rule: Do not allow empty id or guests to delete files.
     if (empty($id) || empty($user->id)) {
         return false;
     }
     $attachment = DiscussHelper::getTable('Attachments');
     $attachment->load($id);
     // Ensure that only post owner or admin can delete it.
     if (!$attachment->deleteable()) {
         return false;
     }
     // Ensure that only post owner or admin can delete it.
     if (!$attachment->delete()) {
         return false;
     }
     $theme = new DiscussThemes();
     $content = JText::_('COM_EASYDISCUSS_ATTACHMENT_DELETED_SUCCESSFULLY');
     $options = new stdClass();
     $options->content = $content;
     $options->title = JText::_('COM_EASYDISCUSS_ATTACHMENT_DELETE_CONFIRMATION_TITLE');
     $buttons = array();
     $button = new stdClass();
     $button->title = JText::_('COM_EASYDISCUSS_BUTTON_CLOSE');
     $button->action = 'disjax.closedlg();';
     $buttons[] = $button;
     $options->buttons = $buttons;
     $ajax->script('EasyDiscuss.$("#attachment-' . $attachment->id . '" ).trigger("itemRemoved").remove();');
     $ajax->dialog($options);
     $ajax->send();
 }