示例#1
0
        $permalink = '';
        if ($post->itemtype == 'posts') {
            $permalink = DiscussRouter::_('index.php?option=com_easydiscuss&view=post&id=' . $post->id);
        } else {
            if ($post->itemtype == 'replies') {
                $permalink = DiscussRouter::_('index.php?option=com_easydiscuss&view=post&id=' . $post->parent_id);
                $permalink = $permalink . '#' . JText::_('COM_EASYDISCUSS_REPLY_PERMALINK') . '-' . $post->id;
            } else {
                if ($post->itemtype == 'category') {
                    $permalink = DiscussRouter::_('index.php?option=com_easydiscuss&view=categories&layout=listings&category_id=' . $post->id);
                }
            }
        }
        ?>
<li class="<?php 
        echo DiscussHelper::isMine($post->user->id) ? 'mypost' : '';
        ?>
">

	<div class="discuss-item<?php 
        echo $post->islock ? ' is-locked' : '';
        echo $post->isresolve ? ' is-resolved' : '';
        echo $post->isFeatured ? ' is-featured' : '';
        ?>
">
		<div class="row-table">
			<div class="col-cell feed-head">
				<?php 
        if ($system->config->get('layout_avatar') && $system->config->get('layout_avatar_in_post')) {
            ?>
				<div class="discuss-avatar">
示例#2
0
 public function edit($tpl = null)
 {
     $app = JFactory::getApplication();
     $doc = JFactory::getDocument();
     $my = JFactory::getUser();
     $acl = DiscussHelper::getHelper('ACL');
     $config = DiscussHelper::getConfig();
     // Load post item
     $id = JRequest::getInt('id', 0);
     if (empty($id)) {
         DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_INVALID_POST_ID'));
         return;
     }
     $post = DiscussHelper::getTable('Post');
     $post->load($id);
     $post->content_raw = $post->content;
     $editing = (bool) $post->id;
     if (!$editing) {
         // try to get from session if there are any.
         $this->getSessionData($post);
     }
     $categoryId = JRequest::getInt('category', $post->category_id);
     // Load category item.
     $category = DiscussHelper::getTable('Category');
     $category->load($categoryId);
     // Check if user is allowed to post a discussion, we also need to check against the category acl
     if (empty($my->id) && !$acl->allowed('add_question', 0)) {
         DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_PLEASE_KINDLY_LOGIN_TO_CREATE_A_POST'));
         $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=index', false));
         $app->close();
         return;
     }
     if ($my->id != 0 && !$acl->allowed('add_question', '0') && !$category->canPost()) {
         $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=index', false), JText::_('COM_EASYDISCUSS_SYSTEM_INSUFFICIENT_PERMISSIONS'));
         $app->close();
         return;
     }
     // Set the breadcrumbs.
     $this->setPathway(JText::_('COM_EASYDISCUSS_BREADCRUMBS_ASK'));
     // Set the page title.
     $title = JText::_('COM_EASYDISCUSS_TITLE_ASK');
     if ($id && $post->id) {
         $title = JText::sprintf('COM_EASYDISCUSS_TITLE_EDIT_QUESTION', $post->getTitle());
     }
     // Set the page title
     DiscussHelper::setPageTitle($title);
     if ($editing) {
         $isModerator = DiscussHelper::getHelper('Moderator')->isModerator($post->category_id);
         if (!DiscussHelper::isMine($post->user_id) && !DiscussHelper::isSiteAdmin() && !$acl->allowed('edit_question') && !$isModerator) {
             $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=post&id=' . $postid, false), JText::_('COM_EASYDISCUSS_SYSTEM_INSUFFICIENT_PERMISSIONS'));
             $app->close();
         }
         $tagsModel = DiscussHelper::getModel('PostsTags');
         $post->tags = $tagsModel->getPostTags($post->id);
     } else {
         if ($categoryId) {
             // set the default category
             $post->category_id = $categoryId;
         }
     }
     $attachments = $post->getAttachments();
     if (isset($post->sessiondata)) {
         $attachments = '';
     }
     $model = DiscussHelper::getModel('Posts');
     $postCount = count($model->getPostsBy('user', $my->id));
     $onlyPublished = empty($post->id) ? true : false;
     // @rule: If there is a category id passed through the query, respect it first.
     $showPrivateCat = empty($post->id) && $my->id == 0 ? false : true;
     // [model:category]
     $categoryModel = $this->getModel('Category');
     $defaultCategory = $categoryModel->getDefaultCategory();
     if ($categoryId == 0 && $defaultCategory !== false) {
         $categoryId = $defaultCategory->id;
     }
     $nestedCategories = '';
     $categories = '';
     if ($config->get('layout_category_selection') == 'multitier') {
         $categoriesModel = $this->getModel('Categories');
         $categories = $categoriesModel->getCategories(array('acl_type' => DISCUSS_CATEGORY_ACL_ACTION_SELECT));
     } else {
         $nestedCategories = DiscussHelper::populateCategories('', '', 'select', 'category_id', $categoryId, true, $onlyPublished, $showPrivateCat, true);
     }
     if ($config->get('layout_reply_editor') == 'bbcode') {
         // Legacy fix when switching from WYSIWYG editor to bbcode.
         $post->content = EasyDiscussParser::html2bbcode($post->content);
     }
     $editor = '';
     if ($config->get('layout_editor') != 'bbcode') {
         $editor = JFactory::getEditor($config->get('layout_editor'));
     }
     // Get list of moderators from the site.
     $moderatorList = array();
     if ($config->get('main_assign_user')) {
         $moderatorList = DiscussHelper::getHelper('Moderator')->getSelectOptions($post->category_id);
     }
     $composer = new DiscussComposer("editing", $post);
     // Set the discussion object.
     $access = $post->getAccess($category);
     $theme = new DiscussThemes();
     // Test if reference is passed in query string.
     $reference = JRequest::getWord('reference');
     $referenceId = JRequest::getInt('reference_id', 0);
     $redirect = JRequest::getVar('redirect', '');
     $theme->set('redirect', $redirect);
     $theme->set('reference', $reference);
     $theme->set('referenceId', $referenceId);
     $theme->set('isEditMode', $editing);
     $theme->set('post', $post);
     $theme->set('composer', $composer);
     $theme->set('parent', $composer->parent);
     $theme->set('nestedCategories', $nestedCategories);
     $theme->set('attachments', $attachments);
     $theme->set('editor', $editor);
     $theme->set('moderatorList', $moderatorList);
     $theme->set('categories', $categories);
     $theme->set('access', $access);
     // Deprecated since 3.0. Will be removed in 4.0
     $theme->set('config', $config);
     echo $theme->fetch('form.reply.wysiwyg.php');
 }
示例#3
0
 function ajaxReadmoreReplies($limitstart = null, $sorting = null, $type = 'questions', $parentId = null, $filter = null, $category = null)
 {
     $ajax = new Disjax();
     $model = $this->getModel('Posts');
     $limitstart = (int) $limitstart;
     $mainframe = JFactory::getApplication();
     $config = DiscussHelper::getConfig();
     $posts = $model->getReplies($parentId, $sorting, $limitstart);
     $pagination = $model->getPagination($parentId, $sorting);
     $my = JFactory::getUser();
     $posts = DiscussHelper::formatPost($posts);
     $parent = DiscussHelper::getTable('Post');
     $parent->load($parentId);
     //check all the 'can' or 'canot' here.
     $acl = DiscussHelper::getHelper('ACL');
     $isMainLocked = $parent->islock ? true : false;
     $canDelete = false;
     $canTag = false;
     $canReply = $acl->allowed('add_reply', '0');
     if ($config->get('main_allowdelete', 2) == 2) {
         $canDelete = $isSiteAdmin ? true : false;
     } else {
         if ($config->get('main_allowdelete', 2) == 1) {
             $canDelete = $acl->allowed('delete_reply', '0');
         }
     }
     $category = DiscussHelper::getTable('Category');
     $category->load($category);
     $posts = DiscussHelper::formatReplies($posts, $category);
     $template = new DiscussThemes();
     $template->set('replies', $posts);
     $template->set('config', $config);
     $template->set('canReply', $canReply);
     $template->set('canDelete', $canDelete);
     $template->set('isMainLocked', $isMainLocked);
     //$template->set( 'isMine'		, false );
     //$template->set( 'isAdmin'		, false );
     $template->set('isMine', DiscussHelper::isMine($parent->user_id));
     $template->set('isAdmin', DiscussHelper::isSiteAdmin());
     $html = $template->fetch('reply.item.php');
     $nextLimit = $limitstart + DiscussHelper::getListLimit();
     if ($nextLimit >= $pagination->total) {
         $ajax->remove('dc_pagination a');
     }
     $ajax->value('pagination-start', $nextLimit);
     $ajax->script('EasyDiscuss.$("#dc_response").children().children( ":last").addClass( "separator" );');
     $ajax->append('dc_response tbody', $html);
     $ajax->send();
 }
示例#4
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;
 }
示例#5
0
 /**
  * Handles POST request for new discussions
  *
  * @since	3.0
  * @access	public
  */
 public function submit()
 {
     JRequest::checkToken('request') or jexit('Invalid Token');
     $config = DiscussHelper::getConfig();
     $my = JFactory::getUser();
     $app = JFactory::getApplication();
     $acl = DiscussHelper::getHelper('ACL');
     // If guest posting is disallowed in the settings, they shouldn't be able to create a discussion at all.
     if (!$my->id && !$acl->allowed('add_question', '0')) {
         DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_POST_PLEASE_LOGIN'), DISCUSS_QUEUE_ERROR);
         $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss', false));
         return $app->close();
     }
     // If user is disallowed in the acl, they shouldn't be able to create a discussion at all.
     if ($my->id && !$acl->allowed('add_question', '0')) {
         DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_SYSTEM_INSUFFICIENT_PERMISSIONS'), DISCUSS_QUEUE_ERROR);
         $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss', false));
         return $app->close();
     }
     // Get values from the posted form.
     $data = JRequest::get('post');
     if (isset($data['mod_post_topic_category_id'])) {
         $data['category_id'] = $data['mod_post_topic_category_id'];
         unset($data['mod_post_topic_category_id']);
     }
     // Run validation on the posted data.
     if (!$this->_fieldValidate($data)) {
         $files = JRequest::getVar('filedata', array(), 'FILES');
         $data['attachments'] = $files;
         DiscussHelper::storeSession($data, 'NEW_POST_TOKEN');
         $app->redirect(DiscussRouter::getAskRoute(null, false));
     }
     // get id if available
     $id = JRequest::getInt('id', 0);
     // bind the table
     $post = DiscussHelper::getTable('Post');
     $post->load($id);
     // set is new value
     $isNew = !$post->id ? true : false;
     // If the post is edited and it doesn't have private the user might be switching from private -> non private
     if (!$isNew && !isset($data['private'])) {
         $post->private = false;
     }
     // Perform captcha validation
     $state = EDC::validateCaptcha($data);
     if (!$state) {
         // Store the data into the session
         EDC::storeSession($data, 'NEW_POST_TOKEN');
         // Set error message
         EDC::setMessageQueue(JText::_('COM_EASYDISCUSS_INVALID_CAPTCHA'), DISCUSS_QUEUE_ERROR);
         if ($isNew) {
             $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=ask', false));
         } else {
             $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=ask&id=' . $post->id, false));
         }
     }
     $previousTags = array();
     if (!$isNew) {
         //check if admin or is owner before allowing edit.
         $isMine = DiscussHelper::isMine($post->user_id);
         $isAdmin = DiscussHelper::isSiteAdmin();
         $isEditor = $acl->allowed('edit_question');
         if (!$my->id && !$isMine && !$isAdmin && !$isEditor) {
             DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_NO_PERMISSION_TO_PERFORM_THE_REQUESTED_ACTION'), DISCUSS_QUEUE_ERROR);
             $this->setRedirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=post&id=' . $id, false));
             return;
         }
         // If this is an edited post, we need to remove existing tags and add them back again.
         $postsTagsModel = $this->getModel('PostsTags');
         $tmppreviousTags = $postsTagsModel->getPostTags($id);
         if (!empty($tmppreviousTags)) {
             foreach ($tmppreviousTags as $previoustag) {
                 $previousTags[] = $previoustag->id;
             }
         }
         if ($acl->allowed('add_tag', '0')) {
             $postsTagsModel->deletePostTag($id);
         }
     }
     // Get raw content from request as we may need to respect the html codes.
     $content = JRequest::getVar('dc_reply_content', '', 'post', 'none', JREQUEST_ALLOWRAW);
     if (empty($content)) {
         // if there is no content from component, get from module quick question
         $content = JRequest::getVar('quick_question_reply_content', '', 'post', 'none', JREQUEST_ALLOWRAW);
     }
     // some joomla editor htmlentity the content before it send to server. so we need
     // to do the god job to fix the content.
     $content = DiscussHelper::getHelper('String ')->unhtmlentities($content);
     // Ensure that the posted content is respecting the correct values.
     $data['dc_reply_content'] = $content;
     // Cleanup alias.
     $alias = DiscussHelper::wordFilter($data['title']);
     $data['alias'] = DiscussHelper::getAlias($alias, 'post', $post->id);
     // Detect the poster type.
     $data['user_type'] = empty($my->id) ? 'guest' : 'member';
     // Akismet configurations.
     if ($config->get('antispam_akismet') && $config->get('antispam_akismet_key')) {
         require_once DISCUSS_CLASSES . '/akismet.php';
         $params = array($data['title'], $data['dc_reply_content']);
         foreach ($params as $param) {
             $akismet = new Akismet(DISCUSS_JURIROOT, $config->get('antispam_akismet_key'), array('author' => $my->name, 'email' => $my->email, 'website' => DISCUSS_JURIROOT, 'body' => urlencode($param), 'alias' => ''));
             // Detect if there's any errors in Akismet.
             if (!$akismet->errorsExist() && $akismet->isSpam()) {
                 DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_AKISMET_SPAM_DETECTED'), DISCUSS_QUEUE_ERROR);
                 $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=ask', false));
                 return $app->close();
             }
         }
     }
     // Get previous status before binding.
     $prevPostStatus = $post->published;
     // If post is being edited, do not change the owner of the item.
     if (!$post->id) {
         $data['user_id'] = !$post->user_id ? $my->id : $post->user_id;
     }
     // Check permission to modify assignee
     $category = DiscussHelper::getTable('Category');
     $access = $post->getAccess($category);
     if ($access->canAssign()) {
         $assignment = DiscussHelper::getTable('PostAssignment');
         $assignment->load($post->id);
         // Add new record if assignee was changed
         if (array_key_exists('assignee_id', $data) && $assignment->assignee_id != $data['assignee_id']) {
             $newAssignment = DiscussHelper::getTable('PostAssignment');
             $newAssignment->post_id = $post->id;
             $newAssignment->assignee_id = (int) $data['assignee_id'];
             $newAssignment->assigner_id = (int) JFactory::getUser()->id;
             if (!$newAssignment->store()) {
                 $ajax->fail('Storing failed');
                 return $ajax->send();
             }
         }
     }
     $data['content_type'] = DiscussHelper::getEditorType('question');
     // Bind posted data against the table.
     $post->bind($data, true);
     // Set all post to be published by default.
     $post->published = DISCUSS_ID_PUBLISHED;
     // Detect if post should be moderated.
     if ($config->get('main_moderatepost') && !DiscussHelper::isSiteAdmin($post->user_id) && !DiscussHelper::isModerateThreshold($post->user_id)) {
         $post->published = DISCUSS_ID_PENDING;
     }
     // Bind posted parameters such as custom tab contents.
     $post->bindParams($data);
     // Check for maximum length of content if category has specific settings.
     $category = DiscussHelper::getTable('Category');
     $category->load($post->category_id);
     // If there's a maximum content length specified per category base, then we need to check against the content.
     if ($category->getParam('maxlength')) {
         $length = JString::strlen($post->content);
         if ($length > $category->getParam('maxlength_size', 1000)) {
             DiscussHelper::storeSession($data, 'NEW_POST_TOKEN');
             DiscussHelper::setMessageQueue(JText::sprintf('COM_EASYDISCUSS_MAXIMUM_LENGTH_EXCEEDED', $category->getParam('maxlength_size', 1000)), DISCUSS_QUEUE_ERROR);
             $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=ask', false));
             return $app->close();
         }
     }
     // If user tries to submit in a container, throw an error.
     if ($category->container) {
         DiscussHelper::storeSession($data, 'NEW_POST_TOKEN');
         DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_NOT_ALLOWED_TO_POST_INTO_CONTAINER'), DISCUSS_QUEUE_ERROR);
         $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=ask', false));
         return $app->close();
     }
     // @trigger: onBeforeSave
     DiscussEventsHelper::importPlugin('content');
     DiscussEventsHelper::onContentBeforeSave('post', $post, $isNew);
     // If password is disabled, do not allow users to set password.
     if (!$config->get('main_password_protection')) {
         $post->password = '';
     }
     // Detect user's ip address.
     $ip = JRequest::getVar('REMOTE_ADDR', '', 'SERVER');
     $post->ip = $ip;
     // Try to store the post object.
     if (!$post->store()) {
         DiscussHelper::setMessageQueue($post->getError(), DISCUSS_QUEUE_ERROR);
         $app->redirect(DiscussRouter::getAskRoute($category->id, false));
         return $app->close();
     }
     // API: References.
     $reference = JRequest::getWord('reference', '');
     $referenceId = JRequest::getInt('reference_id', 0);
     if (!empty($reference) && !empty($referenceId)) {
         $referenceTable = DiscussHelper::getTable('PostsReference');
         $referenceTable->extension = $reference;
         $referenceTable->post_id = $post->id;
         $referenceTable->reference_id = $referenceId;
         $referenceTable->store();
     }
     //Clear off previous records before storing
     $ruleModel = DiscussHelper::getModel('CustomFields');
     $ruleModel->deleteCustomFieldsValue($post->id, 'update');
     // Process custom fields.
     $fieldIds = JRequest::getVar('customFields');
     if (!empty($fieldIds)) {
         foreach ($fieldIds as $fieldId) {
             $fields = JRequest::getVar('customFieldValue_' . $fieldId);
             if (!empty($fields)) {
                 // Cater for custom fields select list
                 // To detect if there is no value selected for the select list custom fields
                 if (in_array('defaultList', $fields)) {
                     $tempKey = array_search('defaultList', $fields);
                     $fields[$tempKey] = '';
                 }
             }
             $post->bindCustomFields($fields, $fieldId);
         }
     }
     // @trigger: onAfterSave
     DiscussEventsHelper::onContentAfterSave('post', $post, $isNew);
     // The category_id for the replies should change too
     $post->moveChilds($post->id, $post->category_id);
     // Process poll items.
     if ($config->get('main_polls')) {
         $polls = JRequest::getVar('pollitems');
         if (!is_array($polls)) {
             $polls = array($polls);
         }
         // If the post is being edited and
         // there is only 1 poll item which is also empty,
         // we need to delete existing polls tied to this post.
         if (count($polls) == 1 && empty($polls[0]) && !$isNew) {
             $post->removePoll();
         }
         if (count($polls) > 0) {
             $hasPolls = false;
             foreach ($polls as $poll) {
                 // As long as there is 1 valid poll, we need to store them.
                 if (!empty($poll)) {
                     $hasPolls = true;
                     break;
                 }
             }
             if ($hasPolls) {
                 // Check if the multiple polls checkbox is it checked?
                 $multiplePolls = JRequest::getVar('multiplePolls', '0');
                 // Get the poll question here.
                 $pollQuestion = JRequest::getVar('poll_question', '');
                 // Try to detect which poll items needs to be removed.
                 $removePolls = JRequest::getVar('pollsremove');
                 // Get the poll items.
                 $pollItems = JRequest::getVar('pollitems');
                 $pollItemsOri = JRequest::getVar('pollitemsOri');
                 // Store the polls now.
                 $post->bindPolls($isNew, $pollItems, $removePolls, $multiplePolls, $pollQuestion, $pollItemsOri);
             }
         }
     }
     // Bind file attachments
     if ($acl->allowed('add_attachment') && $config->get('attachment_questions')) {
         $post->bindAttachments();
     }
     // Detect if the current post should be moderated or not.
     $isModerate = $post->published == DISCUSS_ID_PENDING ? true : false;
     // Process auto posting for posts that are really published and is in a public category.
     if ($post->published == DISCUSS_ID_PUBLISHED && $category->canPublicAccess()) {
         $post->autopost();
     }
     // Detect known names in the post.
     $names = DiscussHelper::getHelper('String')->detectNames($post->content);
     if ($names) {
         foreach ($names as $name) {
             $name = JString::str_ireplace('@', '', $name);
             $id = DiscussHelper::getUserId($name);
             if (!$id || $id == $post->get('user_id')) {
                 continue;
             }
             $notification = DiscussHelper::getTable('Notifications');
             $notification->bind(array('title' => JText::sprintf('COM_EASYDISCUSS_MENTIONED_QUESTION_NOTIFICATION_TITLE', $post->get('title')), 'cid' => $post->get('id'), 'type' => DISCUSS_NOTIFICATIONS_MENTIONED, 'target' => $id, 'author' => $post->get('user_id'), 'permalink' => 'index.php?option=com_easydiscuss&view=post&id=' . $post->get('id')));
             $notification->store();
         }
     }
     if (($isNew || $prevPostStatus == DISCUSS_ID_PENDING) && $post->published == DISCUSS_ID_PUBLISHED) {
         $post->ping();
     }
     $notify = DiscussHelper::getNotification();
     // badwords filtering for email data.
     $post->title = DiscussHelper::wordFilter($post->title);
     $post->content = DiscussHelper::wordFilter($post->content);
     if ($acl->allowed('add_tag', '0')) {
         //@task: Save tags
         $postTagModel = $this->getModel('PostsTags');
         $tags = JRequest::getVar('tags', '', 'POST');
         if (!empty($tags)) {
             $tagModel = $this->getModel('Tags');
             foreach ($tags as $tag) {
                 if (!empty($tag)) {
                     $tagTable = DiscussHelper::getTable('Tags');
                     //@task: Only add tags if it doesn't exist.
                     if (!$tagTable->exists($tag)) {
                         $tagTable->set('title', JString::trim($tag));
                         $tagTable->set('alias', DiscussHelper::getAlias($tag, 'tag'));
                         $tagTable->set('created', DiscussHelper::getDate()->toMySQL());
                         $tagTable->set('published', 1);
                         $tagTable->set('user_id', $my->id);
                         $tagTable->store();
                     } else {
                         $tagTable->load($tag, true);
                     }
                     $postTagInfo = array();
                     //@task: Store in the post tag
                     $postTagTable = DiscussHelper::getTable('PostsTags');
                     $postTagInfo['post_id'] = $post->id;
                     $postTagInfo['tag_id'] = $tagTable->id;
                     $postTagTable->bind($postTagInfo);
                     $postTagTable->store();
                 }
             }
         }
     }
     // prepare email content and information.
     $profile = DiscussHelper::getTable('Profile');
     $profile->load($my->id);
     // For use within the emails.
     $emailData = array();
     $emailData['postTitle'] = $post->title;
     $emailData['postAuthor'] = $profile->id ? $profile->getName() : $post->poster_name;
     $emailData['postAuthorAvatar'] = $profile->getAvatar();
     $emailData['postLink'] = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=post&id=' . $post->id, false, true);
     $emailContent = $post->content;
     if ($post->content_type != 'html') {
         // the content is bbcode. we need to parse it.
         $emailContent = EasyDiscussParser::bbcode($emailContent);
         $emailContent = EasyDiscussParser::removeBrTag($emailContent);
     }
     // If post is html type we need to strip off html codes.
     if ($post->content_type == 'html') {
         $emailContent = strip_tags($post->content);
     }
     $emailContent = $post->trimEmail($emailContent);
     $attachments = $post->getAttachments();
     $emailData['attachments'] = $attachments;
     $emailData['postContent'] = $emailContent;
     $emailData['post_id'] = $post->id;
     $emailData['cat_id'] = $post->category_id;
     $emailData['emailTemplate'] = 'email.subscription.site.new.php';
     $emailData['emailSubject'] = JText::sprintf('COM_EASYDISCUSS_NEW_QUESTION_ASKED', $post->id, $post->title);
     if ($isModerate) {
         // Generate hashkeys to map this current request
         $hashkey = DiscussHelper::getTable('HashKeys');
         $hashkey->uid = $post->id;
         $hashkey->type = DISCUSS_QUESTION_TYPE;
         $hashkey->store();
         require_once DISCUSS_HELPERS . '/router.php';
         $approveURL = DiscussHelper::getExternalLink('index.php?option=com_easydiscuss&controller=posts&task=approvePost&key=' . $hashkey->key);
         $rejectURL = DiscussHelper::getExternalLink('index.php?option=com_easydiscuss&controller=posts&task=rejectPost&key=' . $hashkey->key);
         $emailData['moderation'] = '<div style="display:inline-block;width:100%;padding:20px;border-top:1px solid #ccc;padding:20px 0 10px;margin-top:20px;line-height:19px;color:#555;font-family:\'Lucida Grande\',Tahoma,Arial;font-size:12px;text-align:left">';
         $emailData['moderation'] .= '<a href="' . $approveURL . '" style="display:inline-block;padding:5px 15px;background:#fc0;border:1px solid #caa200;border-bottom-color:#977900;color:#534200;text-shadow:0 1px 0 #ffe684;font-weight:bold;box-shadow:inset 0 1px 0 #ffe064;-moz-box-shadow:inset 0 1px 0 #ffe064;-webkit-box-shadow:inset 0 1px 0 #ffe064;border-radius:2px;moz-border-radius:2px;-webkit-border-radius:2px;text-decoration:none!important">' . JText::_('COM_EASYDISCUSS_EMAIL_APPROVE_POST') . '</a>';
         $emailData['moderation'] .= ' ' . JText::_('COM_EASYDISCUSS_OR') . ' <a href="' . $rejectURL . '" style="color:#477fda">' . JText::_('COM_EASYDISCUSS_REJECT') . '</a>';
         $emailData['moderation'] .= '</div>';
         $emailData['emailTemplate'] = 'email.subscription.site.moderate.php';
         $emailData['emailSubject'] = JText::sprintf('COM_EASYDISCUSS_NEW_QUESTION_MODERATE', $post->id, $post->title);
     } else {
         // If this is a private post, do not notify anyone
         if (!$post->private && $category->canPublicAccess()) {
             // Notify site subscribers
             if ($config->get('main_sitesubscription') && ($isNew || $prevPostStatus == DISCUSS_ID_PENDING) && $post->published == DISCUSS_ID_PUBLISHED && !$config->get('notify_all')) {
                 DiscussHelper::getHelper('Mailer')->notifySubscribers($emailData, array($my->email));
             }
             // Notify category subscribers
             if ($config->get('main_ed_categorysubscription') && ($isNew || $prevPostStatus == DISCUSS_ID_PENDING) && $post->published == DISCUSS_ID_PUBLISHED && !$config->get('notify_all')) {
                 DiscussHelper::getHelper('Mailer')->notifySubscribers($emailData, array($my->email));
             }
             // Notify EVERYBODY
             if ($config->get('notify_all') && !$isModerate) {
                 DiscussHelper::getHelper('Mailer')->notifyAllMembers($emailData, array($my->email));
             }
         }
     }
     // Notify admins and category moderators
     if ($isNew || $prevPostStatus == DISCUSS_ID_PENDING) {
         DiscussHelper::getHelper('Mailer')->notifyAdministrators($emailData, array($my->email), $config->get('notify_admin'), $config->get('notify_moderator'));
     }
     // @rule: Jomsocial activity integrations & points & ranking
     if (($isNew || $prevPostStatus == DISCUSS_ID_PENDING) && $post->published == DISCUSS_ID_PUBLISHED && !$post->private) {
         DiscussHelper::getHelper('jomsocial')->addActivityQuestion($post);
         DiscussHelper::getHelper('easysocial')->createDiscussionStream($post);
         // Add notification to subscribers
         DiscussHelper::getHelper('easysocial')->notify('new.discussion', $post);
         // Add logging for user.
         DiscussHelper::getHelper('History')->log('easydiscuss.new.discussion', $my->id, JText::sprintf('COM_EASYDISCUSS_BADGES_HISTORY_NEW_POST', $post->title), $post->id);
         DiscussHelper::getHelper('Badges')->assign('easydiscuss.new.discussion', $my->id);
         DiscussHelper::getHelper('Points')->assign('easydiscuss.new.discussion', $my->id);
         // Assign badge for EasySocial
         DiscussHelper::getHelper('EasySocial')->assignBadge('create.question', $my->id, JText::sprintf('COM_EASYDISCUSS_BADGES_HISTORY_NEW_POST', $post->title));
         // assign new ranks.
         DiscussHelper::getHelper('ranks')->assignRank($my->id, $config->get('main_ranking_calc_type'));
         // aup
         DiscussHelper::getHelper('Aup')->assign(DISCUSS_POINTS_NEW_DISCUSSION, $my->id, $post->title);
     }
     $message = $isNew ? JText::_('COM_EASYDISCUSS_POST_STORED') : JText::_('COM_EASYDISCUSS_EDIT_SUCCESS');
     $state = 'success';
     // Let's set our custom message here.
     if (!$post->isPending()) {
         DiscussHelper::setMessageQueue($message, $state);
     }
     $redirect = JRequest::getVar('redirect', '');
     if (!empty($redirect)) {
         $redirect = base64_decode($redirect);
         return $this->setRedirect($redirect);
     }
     $redirectionOption = $config->get('main_post_redirection');
     switch ($redirectionOption) {
         case 'default':
             $redirect = DiscussRouter::getPostRoute($post->id, false);
             break;
         case 'home':
             $redirect = DiscussRouter::_('index.php?option=com_easydiscuss&view=index', false);
             break;
         case 'mainCategory':
             $redirect = DiscussRouter::_('index.php?option=com_easydiscuss&view=categories', false);
             break;
         case 'currentCategory':
             $redirect = DiscussRouter::getCategoryRoute($post->category_id, false);
             break;
         default:
             $redirect = DiscussRouter::getPostRoute($post->id, false);
             break;
     }
     $this->setRedirect($redirect);
 }
示例#6
0
            echo $post->id;
            ?>
', 'reply' , '' );" class="btn btn-mini">
			<?php 
        }
        ?>
			<i class="icon-remove"></i> <?php 
        echo JText::_('COM_EASYDISCUSS_ENTRY_DELETE');
        ?>
</a>
		<?php 
    }
    ?>

		<?php 
    if ($access->canResolve() && $post->isQuestion() && !DiscussHelper::isSiteAdmin($my->id) && !DiscussHelper::isModerator($post->category_id, $my->id) && DiscussHelper::isMine($my->id)) {
        ?>
			<a class="admin-unresolve btn btn-mini" href="javascript:void(0);" onclick="discuss.post.unresolve('<?php 
        echo $post->id;
        ?>
');">
				<i class="icon-remove-sign"></i> <?php 
        echo JText::_('COM_EASYDISCUSS_ENTRY_MARK_UNRESOLVED');
        ?>
</a>

			<a class="admin-resolve btn btn-mini" href="javascript:void(0);" onclick="discuss.post.resolve('<?php 
        echo $post->id;
        ?>
');">
				<i class="icon-ok-sign"></i> <?php 
示例#7
0
 public function canUnmarkAnswered()
 {
     if (!$this->config->get('main_qna')) {
         return false;
     }
     if (!$this->post->answered) {
         return false;
     }
     if ($this->isSiteAdmin || $this->isModerator) {
         return true;
     }
     if (!is_null($this->parent)) {
         //check if the parent post is belong to current user or not.
         if (DiscussHelper::isMine($this->parent->user_id)) {
             return true;
         }
     }
     if ($this->acl->allowed('mark_answered')) {
         return true;
     }
     return false;
 }