function display($tmpl = null) { DiscussEventsHelper::importPlugin('content'); $mainframe = JFactory::getApplication(); $config = DiscussHelper::getConfig(); $my = JFactory::getUser(); $sortConfig = $config->get('layout_ordering_category', 'latest'); $sort = JRequest::getCmd('sort', $sortConfig); $this->setPathway(JText::_('COM_EASYDISCUSS_BREADCRUMBS_CATEGORIES')); DiscussHelper::setPageTitle(JText::_('COM_EASYDISCUSS_CATEGORIES_TITLE')); // Set the meta of the page. DiscussHelper::setMeta(); // @task: Add view $this->logView(); $modelP = DiscussHelper::getModel('Posts'); $categoryModel = DiscussHelper::getModel('Categories'); $hideEmptyPost = false; $categories = $categoryModel->getCategoryTree(); $theme = new DiscussThemes(); $theme->set('categories', $categories); echo $theme->fetch('categories.php'); }
/** * Triggers the content plugin * * @since 3.2 * @access public * @param string * @return */ public function triggerReply() { $config = DiscussHelper::getConfig(); if (!$config->get('main_content_trigger_replies')) { return; } // process content plugins DiscussEventsHelper::importPlugin('content'); DiscussEventsHelper::onContentPrepare('reply', $postTable); $event = new stdClass(); $args = array(&$this); $results = DiscussEventsHelper::onContentBeforeDisplay('reply', $args); $event->beforeDisplayContent = trim(implode("\n", $results)); $results = DiscussEventsHelper::onContentAfterDisplay('reply', $args); $event->afterDisplayContent = trim(implode("\n", $results)); $this->event = $event; }
/** * Triggers plugins. * * @since 3.0 * @access public */ public static function triggerPlugins($type, $eventName, &$data, $hasReturnValue = false) { DiscussEventsHelper::importPlugin($type); $args = array('post', &$data); $returnValue = call_user_func_array('DiscussEventsHelper::' . $eventName, $args); if ($hasReturnValue) { return trim(implode("\n", $returnValue)); } return; }
/** * update posts */ public function submit() { if (JRequest::getMethod() == 'POST') { JRequest::checkToken('request') or jexit('Invalid Token'); $user = JFactory::getUser(); // get all forms value $post = JRequest::get('post'); // get id if available $id = JRequest::getInt('id', 0); // get post parent id $parent = JRequest::getInt('parent_id', 0); // the source where page come from $source = JRequest::getVar('source', 'posts'); // Get raw content from request as we may need to respect the html codes. $content = JRequest::getVar('dc_reply_content', '', 'post', 'none', JREQUEST_ALLOWRAW); // Ensure that the posted content is respecting the correct values. $post['dc_reply_content'] = $content; // get config $config = DiscussHelper::getConfig(); $post['alias'] = empty($post['alias']) ? DiscussHelper::getAlias($post['title'], 'post', $id) : DiscussHelper::getAlias($post['alias'], 'post', $id); //clear tags if editing a post. $previousTags = array(); if (!empty($id)) { $postsTagsModel = $this->getModel('PostsTags'); $tmppreviousTags = $postsTagsModel->getPostTags($id); if (!empty($tmppreviousTags)) { foreach ($tmppreviousTags as $previoustag) { $previousTags[] = $previoustag->id; } } $postsTagsModel->deletePostTag($id); } // bind the table $postTable = JTable::getInstance('posts', 'Discuss'); $postTable->load($id); //get previous post status before binding. $prevPostStatus = $postTable->published; $postTable->bind($post, true); // hold last inserted ID in DB $lastId = null; // @rule: Bind parameters $postTable->bindParams($post); if ($config->get('main_private_post') && isset($post['private'])) { $postTable->private = $post['private']; } // @trigger: onBeforeSave $isNew = (bool) $postTable->id; DiscussEventsHelper::importPlugin('content'); DiscussEventsHelper::onContentBeforeSave('post', $post, $isNew); if (!$postTable->store()) { JError::raiseError(500, $postTable->getError()); } //Clear off previous records before storing $ruleModel = DiscussHelper::getModel('CustomFields'); $ruleModel->deleteCustomFieldsValue($postTable->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] = ''; } } $postTable->bindCustomFields($fields, $fieldId); } } // @trigger: onAfterSave DiscussEventsHelper::onContentAfterSave('post', $post, $isNew); // The category_id for the replies should change too $postTable->moveChilds($postTable->id, $postTable->category_id); $lastId = $postTable->id; // Bind file attachments $postTable->bindAttachments(); $message = JText::_('COM_EASYDISCUSS_POST_SAVED'); $date = DiscussHelper::getDate(); //@task: Save tags $tags = JRequest::getVar('tags', '', 'POST'); if (!empty($tags)) { $tagModel = $this->getModel('Tags'); foreach ($tags as $tag) { if (!empty($tag)) { $tagTable = JTable::getInstance('Tags', 'Discuss'); //@task: Only add tags if it doesn't exist. if (!$tagTable->exists($tag)) { $tagInfo['title'] = JString::trim($tag); $tagInfo['alias'] = DiscussHelper::getAlias($tag, 'tag'); $tagInfo['created'] = $date->toMySQL(); $tagInfo['published'] = 1; $tagInfo['user_id'] = $user->id; $tagTable->bind($tagInfo); $tagTable->store(); } else { $tagTable->load($tag, true); } $postTagInfo = array(); //@task: Store in the post tag $postTagTable = JTable::getInstance('PostsTags', 'Discuss'); $postTagInfo['post_id'] = $postTable->id; $postTagInfo['tag_id'] = $tagTable->id; $postTagTable->bind($postTagInfo); $postTagTable->store(); } } } $isNew = empty($id) ? true : false; if (($isNew || $prevPostStatus == DISCUSS_ID_PENDING) && $postTable->published == DISCUSS_ID_PUBLISHED) { $owner = $isNew ? $user->id : $postTable->user_id; DiscussHelper::sendNotification($postTable, $parent, $isNew, $owner, $prevPostStatus); // auto subscription if ($config->get('main_autopostsubscription') && $config->get('main_postsubscription') && $postTable->user_type != 'twitter' && !empty($postTable->parent_id)) { // process only if this is a reply //automatically subscribe this user into this reply $replier = JFactory::getUser($postTable->user_id); $subscription_info = array(); $subscription_info['type'] = 'post'; $subscription_info['userid'] = !empty($postTable->user_id) ? $postTable->user_id : '0'; $subscription_info['email'] = !empty($postTable->user_id) ? $replier->email : $postTable->poster_email; $subscription_info['cid'] = $postTable->parent_id; $subscription_info['member'] = !empty($postTable->user_id) ? '1' : '0'; $subscription_info['name'] = !empty($postTable->user_id) ? $replier->name : $postTable->poster_name; $subscription_info['interval'] = 'instant'; //get frontend subscribe table $susbcribeModel = DiscussHelper::getModel('Subscribe'); $sid = ''; if ($subscription_info['userid'] == 0) { $sid = $susbcribeModel->isPostSubscribedEmail($subscription_info); if (empty($sid)) { $susbcribeModel->addSubscription($subscription_info); } } else { $sid = $susbcribeModel->isPostSubscribedUser($subscription_info); if (empty($sid['id'])) { //add new subscription. $susbcribeModel->addSubscription($subscription_info); } } } // only if the post is a discussion if ($config->get('integration_pingomatic') && empty($postTable->parent_id)) { $pingo = DiscussHelper::getHelper('Pingomatic'); $urls = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=post&id=' . $postTable->id, true, true); $pingo->ping($postTable->title, $urls); } } $pid = ''; if (!empty($parent)) { $pid = '&pid=' . $parent; } $task = $this->getTask(); switch ($task) { case 'apply': $redirect = 'index.php?option=com_easydiscuss&view=post&id=' . $postTable->id; break; case 'save': $redirect = 'index.php?option=com_easydiscuss&view=posts'; break; case 'savePublishNew': default: $redirect = 'index.php?option=com_easydiscuss&view=post'; break; } DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_DISCUSSION_SAVED'), DISCUSS_QUEUE_SUCCESS); $this->setRedirect($redirect); } }
/** * Triggers when an edited reply is saved. * * @since 3.0 * @param null * @return null */ public function saveReply() { // Load ajax library $ajax = DiscussHelper::getHelper('Ajax'); $config = DiscussHelper::getConfig(); // Get the posted data $data = JRequest::get('post'); // Prepare the output data $output = array(); $output['id'] = $data['post_id']; $acl = DiscussHelper::getHelper('ACL'); $my = JFactory::getUser(); // Check for empty content $this->checkEmpty($data, $ajax); // Rebind the post data because it may contain HTML codes $data['content'] = JRequest::getVar('content', '', 'post', 'none', JREQUEST_ALLOWRAW); $data['content_type'] = DiscussHelper::getEditorType('reply'); // Load up the post table $post = DiscussHelper::getTable('Post'); $post->load($data['post_id']); // Bind the post table with the data $post->bind($data); // Check if the post data is valid if (!$post->id || !$data['post_id']) { $ajax->reject('error', JText::_('COM_EASYDISCUSS_SYSTEM_INVALID_ID')); return $ajax->send(); } // Only allow users with proper access $isModerator = DiscussHelper::getHelper('Moderator')->isModerator($post->category_id); // Do not allow unauthorized access if (!DiscussHelper::isSiteAdmin() && $post->user_id != $my->id && !$acl->allowed('edit_reply', 0) && !$isModerator) { $ajax->reject('error', JText::_('COM_EASYDISCUSS_SYSTEM_INSUFFICIENT_PERMISSIONS')); $ajax->send(); } // Get the new content from the post data $post->content = $data['content']; // Validate captcha $this->checkCaptcha($data); // @rule: Bind parameters if ($config->get('reply_field_references')) { $post->bindParams($data); } // Bind file attachments if ($acl->allowed('add_attachment', '0')) { $post->bindAttachments(); } // Determines if this is a new post. $isNew = false; // @trigger: onBeforeSave DiscussEventsHelper::importPlugin('content'); DiscussEventsHelper::onContentBeforeSave('post', $post, $isNew); // Try to store the post now if (!$post->store()) { $ajax->reject('error', JText::_('COM_EASYDISCUSS_ERROR')); $ajax->send(); } // Process polls $this->processPolls($post); // Process custom fields $this->saveCustomFieldsValue($post->id); // @trigger: onAfterSave DiscussEventsHelper::onContentAfterSave('post', $post, $isNew); // Filter for badwords $post->title = DiscussHelper::wordFilter($post->title); $post->content = DiscussHelper::wordFilter($post->content); // Determines if the user is allowed to delete this post $canDelete = false; if (DiscussHelper::isSiteAdmin() || $acl->allowed('delete_reply', '0') || $post->user_id == $my->id) { $canDelete = true; } // URL References $post->references = $post->getReferences(); // Get the voted state $voteModel = DiscussHelper::getModel('Votes'); $post->voted = $voteModel->hasVoted($post->id); // Get total votes for this post $post->totalVote = $post->sum_totalvote; // Load profile info $creator = DiscussHelper::getTable('Profile'); $creator->load($post->user_id); // Assign creator $post->user = $creator; // Format the content. $tmp = $post->content; $post->content_raw = $post->content; $post->content = DiscussHelper::formatContent($post); // Once the formatting is done, we need to escape the raw content $post->content_raw = DiscussHelper::getHelper('String')->escape($tmp); // Store the default values //default value $post->isVoted = 0; $post->total_vote_cnt = 0; $post->likesAuthor = ''; $post->minimize = 0; // Trigger reply $post->triggerReply(); // Load up parent's post $question = DiscussHelper::getTable('Post'); $question->load($post->parent_id); $recaptcha = ''; $enableRecaptcha = $config->get('antispam_recaptcha'); $publicKey = $config->get('antispam_recaptcha_public'); $skipRecaptcha = $config->get('antispam_skip_recaptcha'); $model = DiscussHelper::getModel('Posts'); $postCount = count($model->getPostsBy('user', $my->id)); if ($enableRecaptcha && !empty($publicKey) && $postCount < $skipRecaptcha) { require_once DISCUSS_CLASSES . '/recaptcha.php'; $recaptcha = getRecaptchaData($publicKey, $config->get('antispam_recaptcha_theme'), $config->get('antispam_recaptcha_lang'), null, $config->get('antispam_recaptcha_ssl'), 'edit-reply-recaptcha' . $post->id); } // Get the post access object here. $category = DiscussHelper::getTable('Category'); $category->load($post->category_id); $access = $post->getAccess($category); $post->access = $access; // Get comments for the post $commentLimit = $config->get('main_comment_pagination') ? $config->get('main_comment_pagination_count') : null; $comments = $post->getComments($commentLimit); $post->comments = DiscussHelper::formatComments($comments); $theme = new DiscussThemes(); $theme->set('question', $question); $theme->set('post', $post); $theme->set('category', $category); // Get theme file output $contents = $theme->fetch('post.reply.item.php'); $ajax->resolve($contents); return $ajax->send(); }
/** * Responsible to process a comment for saving. * * @since 3.0 * @access public */ public function save() { $id = JRequest::getInt('id', 0); $my = JFactory::getUser(); $acl = DiscussHelper::getHelper('ACL'); $ajax = DiscussHelper::getHelper('Ajax'); $config = DiscussHelper::getConfig(); // Load the post item. $post = DiscussHelper::getTable('Post'); $state = $post->load($id); // Test if a valid post id is provided. if (!$id || !$state) { $ajax->reject(JText::_('COM_EASYDISCUSS_COMMENTS_INVALID_POST_ID')); return $ajax->send(); } $category = DiscussHelper::getTable('Category'); $category->load($post->category_id); $access = $post->getAccess($category); // Test if the user is allowed to add comment or not. if (!$access->canComment()) { $ajax->reject(JText::_('COM_EASYDISCUSS_COMMENTS_NOT_ALLOWED')); return $ajax->send(); } // Test if the comment message exists. $message = JRequest::getVar('comment', ''); if (empty($message)) { $ajax->reject(JText::_('COM_EASYDISCUSS_COMMENT_IS_EMPTY')); } // Test if the user checked the terms and conditions box. if ($config->get('main_comment_tnc')) { $acceptedTerms = JRequest::getInt('tnc', 0); if (!$acceptedTerms) { $ajax->reject(JText::_('COM_EASYDISCUSS_TERMS_PLEASE_ACCEPT')); return $ajax->send(); } } // Load user profile's object. $profile = DiscussHelper::getTable('Profile'); $profile->load($my->id); // Build up comment object. $commentData = new stdClass(); $commentData->user_id = $my->id; $commentData->name = $profile->getName(); $commentData->email = $my->email; $commentData->comment = $message; $commentData->post_id = $post->id; // Run through akismet screening if necessary. if ($config->get('antispam_akismet') && $config->get('antispam_akismet_key')) { require_once DISCUSS_CLASSES . '/akismet.php'; $data = array('author' => $my->name, 'email' => $my->email, 'website' => DISCUSS_JURIROOT, 'body' => $commentData->comment, 'alias' => ''); $akismet = new Akismet(DISCUSS_JURIROOT, $config->get('antispam_akismet_key'), $data); if ($akismet->isSpam()) { $ajax->reject(JText::_('COM_EASYDISCUSS_AKISMET_SPAM_DETECTED')); return $ajax->send(); } } $comment = DiscussHelper::getTable('Comment'); $comment->bind($commentData, true); if (!$comment->store()) { $ajax->reject($comment->getError()); return $ajax->send(); } // Get post duration. $durationObj = new stdClass(); $durationObj->daydiff = 0; $durationObj->timediff = '00:00:01'; $comment->duration = DiscussHelper::getDurationString($durationObj); // Set the comment creator. $comment->creator = $profile; // Try to detect if the comment is posted to the main question or a reply. $liveNotificationText = ''; if ($post->parent_id) { $question = DiscussHelper::getTable('Post'); $question->load($post->parent_id); $liveNotificationText = 'COM_EASYDISCUSS_COMMENT_REPLY_NOTIFICATION_TITLE'; } else { $question = DiscussHelper::getTable('Post'); $question->load($id); $liveNotificationText = 'COM_EASYDISCUSS_COMMENT_QUESTION_NOTIFICATION_TITLE'; } // Create notification item in EasySocial DiscussHelper::getHelper('EasySocial')->notify('new.comment', $post, $question, $comment); if ($comment->published && !$question->private) { // AUP integrations DiscussHelper::getHelper('Aup')->assign(DISCUSS_POINTS_NEW_COMMENT, $comment->user_id, ''); // jomsocial activity stream DiscussHelper::getHelper('jomsocial')->addActivityComment($post, $question); DiscussHelper::getHelper('easysocial')->commentDiscussionStream($comment, $post, $question); } // Add notification to the post owner. if ($post->user_id != $my->id && $comment->published && $config->get('main_notifications_comments')) { $notification = DiscussHelper::getTable('Notifications'); $notification->bind(array('title' => JText::sprintf($liveNotificationText, $question->title), 'cid' => $question->id, 'type' => DISCUSS_NOTIFICATIONS_COMMENT, 'target' => $post->user_id, 'author' => $my->id, 'permalink' => 'index.php?option=com_easydiscuss&view=post&id=' . $question->id)); $notification->store(); } // Try to assign badge and points to the current user. // Only assign points and badge when they are commenting a post that are not posted by them // if( $my->id != $post->user_id ) // { // Add logging for user. DiscussHelper::getHelper('History')->log('easydiscuss.new.comment', $my->id, JText::_('COM_EASYDISCUSS_BADGES_HISTORY_NEW_COMMENT'), $post->id); // Assign badge for EasySocial DiscussHelper::getHelper('EasySocial')->assignBadge('create.comment', $my->id, JText::_('COM_EASYDISCUSS_BADGES_HISTORY_NEW_COMMENT')); DiscussHelper::getHelper('Badges')->assign('easydiscuss.new.comment', $my->id); DiscussHelper::getHelper('Points')->assign('easydiscuss.new.comment', $my->id, $comment); // } // Apply badword filtering for the comment. $comment->comment = DiscussHelper::wordFilter($comment->comment); $emailData = array(); $emailData['commentContent'] = $comment->comment; $emailData['commentAuthor'] = $profile->getName(); $emailData['commentAuthorAvatar'] = $profile->getAvatar(); $emailData['postTitle'] = $question->title; $emailData['postLink'] = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=post&id=' . $question->id, false, true); $emails = array(); // Send email to the post owner only if the commenter is not the post owner. if ($post->user_id != 0 && $post->id != $my->id) { $user = JFactory::getUser($post->user_id); $emails[] = $user->email; } // Retrieve the list of user emails from the list of comments made on the post. $existingComments = $post->getComments(); if ($existingComments) { foreach ($existingComments as $existingComment) { // Only add the email when the user id is not the current logged in user who is posting the comment. // It should not send email to the post owner as well since the post owner will already get a notification. if ($existingComment->user_id != 0 && $existingComment->user_id != $my->id && $existingComment->user_id != $post->user_id) { $user = JFactory::getUser($existingComment->user_id); $emails[] = $user->email; } } } // Ensure the emails are all unique. $emails = array_unique($emails); // Only send email when email is not empty. if (!empty($emails)) { $notify = DiscussHelper::getNotification(); $notify->addQueue($emails, JText::sprintf('COM_EASYDISCUSS_EMAIL_TITLE_NEW_COMMENT', JString::substr($question->content, 0, 15)) . '...', '', 'email.post.comment.new.php', $emailData); } //revert the comment form // $ajax->script('discuss.comment.cancel()'); // Process comment triggers. if ($config->get('main_content_trigger_comments')) { $comment->content = $comment->comment; // process content plugins DiscussEventsHelper::importPlugin('content'); DiscussEventsHelper::onContentPrepare('comment', $comment); $comment->event = new stdClass(); $results = DiscussEventsHelper::onContentBeforeDisplay('comment', $comment); $comment->event->beforeDisplayContent = trim(implode("\n", $results)); $results = DiscussEventsHelper::onContentAfterDisplay('comment', $comment); $comment->event->afterDisplayContent = trim(implode("\n", $results)); $comment->comment = $comment->content; } // Get the parent post post id $postId = $post->parent_id ? $post->parent_id : $post->id; // Get the result of the posted comment. $theme = new DiscussThemes(); $theme->set('comment', $comment); $theme->set('postId', $postId); $output = $theme->fetch('post.reply.comment.item.php'); $ajax->resolve($output); return $ajax->send(); }
/** * Saves an edited reply if the site is configured to use a WYSIWYG editor * * @since 3.2 * @access public * @param string * @return */ public function saveReply() { //JRequest::checkToken('request') or jexit( 'Invalid Token' ); $config = DiscussHelper::getConfig(); $acl = DiscussHelper::getHelper('ACL'); $my = JFactory::getUser(); $app = JFactory::getApplication(); $post = JRequest::get('POST'); $output = array(); $output['id'] = $post['post_id']; $postTable = DiscussHelper::getTable('Post'); $postTable->load($post['post_id']); $categoryTable = DiscussHelper::getTable('category'); $categoryTable->load($postTable->category_id); $postAccess = DiscussHelper::getPostAccess($postTable, $categoryTable); if (!$postAccess->canEdit()) { DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_SYSTEM_INSUFFICIENT_PERMISSIONS'), DISCUSS_QUEUE_ERROR); $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=ask&id=' . $post['post_id'], false)); return $app->close(); } // do checking here! if (empty($post['dc_reply_content'])) { DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_ERROR_REPLY_EMPTY'), DISCUSS_QUEUE_ERROR); $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=ask&id=' . $post['post_id'], false)); return $app->close(); } // Rebind the post data $post['dc_reply_content'] = JRequest::getVar('dc_reply_content', '', 'post', 'none', JREQUEST_ALLOWRAW); $post['content'] = $post['dc_reply_content']; $data['content_type'] = DiscussHelper::getEditorType('reply'); $postTable->bind($post); $recaptcha = $config->get('antispam_recaptcha'); $public = $config->get('antispam_recaptcha_public'); $private = $config->get('antispam_recaptcha_private'); if (!$config->get('antispam_recaptcha_registered_members') && $my->id > 0) { $recaptcha = false; } if ($recaptcha && $public && $private) { require_once DISCUSS_CLASSES . '/recaptcha.php'; $obj = DiscussRecaptcha::recaptcha_check_answer($private, $_SERVER['REMOTE_ADDR'], $post['recaptcha_challenge_field'], $post['recaptcha_response_field']); if (!$obj->is_valid) { $ajax->reloadCaptcha(); $ajax->reject('error', JText::_('COM_EASYDISCUSS_POST_INVALID_RECAPTCHA_RESPONSE')); $ajax->send(); } } else { if ($config->get('antispam_easydiscuss_captcha')) { $runCaptcha = DiscussHelper::getHelper('Captcha')->showCaptcha(); if ($runCaptcha) { $response = JRequest::getVar('captcha-response'); $captchaId = JRequest::getInt('captcha-id'); $discussCaptcha = new stdClass(); $discussCaptcha->captchaResponse = $response; $discussCaptcha->captchaId = $captchaId; $state = DiscussHelper::getHelper('Captcha')->verify($discussCaptcha); if (!$state) { DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_INVALID_CAPTCHA'), DISCUSS_QUEUE_ERROR); $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=post&layout=edit&id=' . $postTable->id, false)); return $app->close(); } } } } // @rule: Bind parameters if ($config->get('reply_field_references')) { $postTable->bindParams($post); } // Bind file attachments if ($acl->allowed('add_attachment', '0')) { $postTable->bindAttachments(); } $isNew = false; // @trigger: onBeforeSave DiscussEventsHelper::importPlugin('content'); DiscussEventsHelper::onContentBeforeSave('post', $postTable, $isNew); if (!$postTable->store()) { $ajax->reject('error', JText::_('COM_EASYDISCUSS_ERROR')); $ajax->send(); } // Process poll items $includePolls = JRequest::getBool('pollitems', false); // Process poll items here. if ($includePolls && $config->get('main_polls')) { $pollItems = JRequest::getVar('pollitems'); $pollItemsOri = JRequest::getVar('pollitemsOri'); // Delete polls if necessary since this post doesn't contain any polls. //if( !$isNew && !$includePolls ) if (count($pollItems) == 1 && empty($pollItems[0]) && !$isNew) { $postTable->removePoll(); } // Check if the multiple polls checkbox is it checked? $multiplePolls = JRequest::getVar('multiplePolls', '0'); if ($pollItems) { // As long as we need to create the poll answers, we need to create the main question. $pollTitle = JRequest::getVar('poll_question', ''); // Since poll question are entirely optional. $pollQuestion = DiscussHelper::getTable('PollQuestion'); $pollQuestion->loadByPost($postTable->id); $pollQuestion->post_id = $postTable->id; $pollQuestion->title = $pollTitle; $pollQuestion->multiple = $config->get('main_polls_multiple') ? $multiplePolls : false; $pollQuestion->store(); if (!$isNew) { // Try to detect which poll items needs to be removed. $remove = JRequest::getVar('pollsremove'); if (!empty($remove)) { $remove = explode(',', $remove); foreach ($remove as $id) { $id = (int) $id; $poll = DiscussHelper::getTable('Poll'); $poll->load($id); $poll->delete(); } } } for ($i = 0; $i < count($pollItems); $i++) { $item = $pollItems[$i]; $itemOri = isset($pollItemsOri[$i]) ? $pollItemsOri[$i] : ''; $value = (string) $item; $valueOri = (string) $itemOri; if (trim($value) == '') { continue; } $poll = DiscussHelper::getTable('Poll'); if (empty($valueOri) && !empty($value)) { // this is a new item. $poll->set('value', $value); $poll->set('post_id', $postTable->get('id')); $poll->store(); } else { if (!empty($valueOri) && !empty($value)) { // update existing value. if (!$poll->loadByValue($valueOri, $postTable->get('id'))) { $poll->set('value', $value); $poll->store(); } } } } } } if (!empty($postTable->id)) { //Clear off previous records before storing $ruleModel = DiscussHelper::getModel('CustomFields'); $ruleModel->deleteCustomFieldsValue($postTable->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] = ''; } } $postTable->bindCustomFields($fields, $fieldId); } } } // @trigger: onAfterSave DiscussEventsHelper::onContentAfterSave('post', $postTable, $isNew); //get parent post $parentId = $postTable->parent_id; $parentTable = DiscussHelper::getTable('Post'); $parentTable->load($parentId); // filtering badwords $postTable->title = DiscussHelper::wordFilter($postTable->title); $postTable->content = DiscussHelper::wordFilter($postTable->content); //all access control goes here. $canDelete = false; if (DiscussHelper::isSiteAdmin() || $acl->allowed('delete_reply', '0') || $postTable->user_id == $user->id) { $canDelete = true; } // @rule: URL References $postTable->references = $postTable->getReferences(); // set for vote status $voteModel = DiscussHelper::getModel('Votes'); $postTable->voted = $voteModel->hasVoted($postTable->id); // get total vote for this reply $postTable->totalVote = $postTable->sum_totalvote; //load porfile info and auto save into table if user is not already exist in discuss's user table. $creator = DiscussHelper::getTable('Profile'); $creator->load($postTable->user_id); $postTable->user = $creator; //default value $postTable->isVoted = 0; $postTable->total_vote_cnt = 0; $postTable->likesAuthor = ''; $postTable->minimize = 0; if ($config->get('main_content_trigger_replies')) { // process content plugins DiscussEventsHelper::importPlugin('content'); DiscussEventsHelper::onContentPrepare('reply', $postTable); $postTable->event = new stdClass(); $results = DiscussEventsHelper::onContentBeforeDisplay('reply', $postTable); $postTable->event->beforeDisplayContent = trim(implode("\n", $results)); $results = DiscussEventsHelper::onContentAfterDisplay('reply', $postTable); $postTable->event->afterDisplayContent = trim(implode("\n", $results)); } $theme = new DiscussThemes(); $question = DiscussHelper::getTable('Post'); $question->load($postTable->parent_id); $recaptcha = ''; $enableRecaptcha = $config->get('antispam_recaptcha'); $publicKey = $config->get('antispam_recaptcha_public'); $skipRecaptcha = $config->get('antispam_skip_recaptcha'); $model = DiscussHelper::getModel('Posts'); $postCount = count($model->getPostsBy('user', $my->id)); if ($enableRecaptcha && !empty($publicKey) && $postCount < $skipRecaptcha) { require_once DISCUSS_CLASSES . '/recaptcha.php'; $recaptcha = getRecaptchaData($publicKey, $config->get('antispam_recaptcha_theme'), $config->get('antispam_recaptcha_lang'), null, $config->get('antispam_recaptcha_ssl'), 'edit-reply-recaptcha' . $postTable->id); } // Get the post access object here. $category = DiscussHelper::getTable('Category'); $category->load($postTable->category_id); $access = $postTable->getAccess($category); $postTable->access = $access; // Get comments for the post $commentLimit = $config->get('main_comment_pagination') ? $config->get('main_comment_pagination_count') : null; $comments = $postTable->getComments($commentLimit); $postTable->comments = DiscussHelper::formatComments($comments); $theme->set('question', $question); $theme->set('post', $postTable); $theme->set('category', $category); $html = $theme->fetch('post.reply.item.php'); if ($recaptcha && $public && $private) { $output['type'] = 'success.captcha'; } if (!$parentTable->islock) { $output['type'] = 'locked'; } $message = $isNew ? JText::_('COM_EASYDISCUSS_POST_STORED') : JText::_('COM_EASYDISCUSS_EDIT_SUCCESS'); $state = 'success'; // Let's set our custom message here. DiscussHelper::setMessageQueue($message, $state); $redirect = JRequest::getVar('redirect', ''); if (!empty($redirect)) { $redirect = base64_decode($redirect); return $this->setRedirect($redirect); } $this->setRedirect(DiscussRouter::getPostRoute($post['parent_id'], false)); }