/** * 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); } }
public function approvePost() { $mainframe = JFactory::getApplication(); $key = JRequest::getVar('key', ''); $redirect = DiscussRouter::_('index.php?option=com_easydiscuss&view=index', false); if (empty($key)) { $mainframe->redirect($redirect, JText::_('COM_EASYDISCUSS_NOT_ALLOWED_HERE'), 'error'); $mainframe->close(); } $hashkey = DiscussHelper::getTable('HashKeys'); if (!$hashkey->loadByKey($key)) { $mainframe->redirect($redirect, JText::_('COM_EASYDISCUSS_NOT_ALLOWED_HERE'), 'error'); $mainframe->close(); } $post = DiscussHelper::getTable('Post'); $post->load($hashkey->uid); $post->published = DISCUSS_ID_PUBLISHED; // @trigger: onBeforeSave $isNew = (bool) $post->id; DiscussEventsHelper::importPlugin('content'); DiscussEventsHelper::onContentBeforeSave('post', $post, $isNew); if (!$post->store()) { JError::raiseError(500, $post->getError()); } // @rule: Send out notifications when the pending moderation items are being published. DiscussHelper::sendNotification($post, $post->parent_id, true, $post->user_id, DISCUSS_ID_PENDING); // @trigger: onAfterSave DiscussEventsHelper::onContentAfterSave('post', $post, $isNew); // Add to jomsocial stream if (!empty($post->parent_id)) { DiscussHelper::getHelper('jomsocial')->addActivityReply($post); DiscussHelper::getHelper('easysocial')->replyDiscussionStream($post); } else { DiscussHelper::getHelper('jomsocial')->addActivityQuestion($post); DiscussHelper::getHelper('easysocial')->createDiscussionStream($post); } // Delete the unused hashkey now. $hashkey->delete(); $message = $hashkey->type == DISCUSS_REPLY_TYPE ? JText::_('COM_EASYDISCUSS_MODERATE_REPLY_PUBLISHED') : JText::_('COM_EASYDISCUSS_MODERATE_POST_PUBLISHED'); $pid = $hashkey->type == DISCUSS_REPLY_TYPE ? $post->parent_id : $post->id; $mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=post&id=' . $pid, false), $message, 'success'); }