Ejemplo n.º 1
0
 public static function bbcodeHtmlSwitcher($post = '', $type = '', $isEditing = false)
 {
     $config = DiscussHelper::getConfig();
     if ($type == 'question') {
         $editor = $config->get('layout_editor');
     } else {
         if ($type == 'reply') {
             $editor = $config->get('layout_reply_editor');
         } else {
             if ($type == 'signature' || $type == 'description') {
                 $temp = $post;
                 $post = new stdClass();
                 $post->content_raw = $temp;
                 $post->content_type = 'bbcode';
                 $editor = 'bbcode';
             }
         }
     }
     if ($editor != 'bbcode') {
         $editor = 'html';
     }
     if ($post->content_type == 'bbcode') {
         if ($editor == 'bbcode') {
             //If content_type is bbcode and editor is bbcode
             if ($isEditing) {
                 $content = $post->content_raw;
             } else {
                 $content = $post->content_raw;
                 //$content = DiscussHelper::getHelper( 'String' )->escape( $content );
                 $content = EasyDiscussParser::bbcode($content);
                 $content = EasyDiscussParser::removeBrTag($content);
             }
         } else {
             //If content_type is bbcode and editor is html
             // Need content raw to work
             //$content = DiscussHelper::getHelper( 'String' )->escape( $post->content_raw );
             $content = EasyDiscussParser::bbcode($content);
             $content = EasyDiscussParser::removeBrTag($content);
         }
     } else {
         if ($editor == 'bbcode') {
             //If content_type is html and editor is bbcode
             if ($isEditing) {
                 $content = EasyDiscussParser::quoteBbcode($post->content_raw);
                 $content = EasyDiscussParser::smiley2bbcode($content);
                 // we need to parse smiley 1st before we parse htmltobbcode.
                 $content = EasyDiscussParser::html2bbcode($content);
             } else {
                 $content = $post->content_raw;
                 //Quote all bbcode here
                 $content = EasyDiscussParser::quoteBbcode($content);
             }
         } else {
             //If content_type is html and editor is html
             $content = $post->content_raw;
         }
     }
     // Apply censorship
     $content = DiscussHelper::wordFilter($content);
     return $content;
 }
Ejemplo n.º 2
0
 public function addActivityReply($post)
 {
     $core = JPATH_ROOT . '/components/com_community/libraries/core.php';
     $config = DiscussHelper::getConfig();
     if (!JFile::exists($core)) {
         return false;
     }
     require_once $core;
     // @rule: Insert points for user.
     if ($config->get('integration_jomsocial_points')) {
         CFactory::load('libraries', 'userpoints');
         CUserPoints::assignPoint('com_easydiscuss.reply.discussion', $post->user_id);
     }
     $lang = JFactory::getLanguage();
     $lang->load('com_easydiscuss', JPATH_ROOT);
     // We do not want to add activities if new blog activity is disabled.
     if (!$config->get('integration_jomsocial_activity_reply_question')) {
         return false;
     }
     $link = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=post&id=' . $post->parent_id, false, true);
     $replyLink = $link . '#' . JText::_('COM_EASYDISCUSS_REPLY_PERMALINK') . '-' . $post->id;
     $parent = DiscussHelper::getTable('Post');
     $parent->load($post->parent_id);
     $title = $this->getActivityTitle($parent->title);
     $content = '';
     if ($config->get('integration_jomsocial_activity_reply_question_content')) {
         $content = $post->content;
         $pattern = '#<img[^>]*>#i';
         preg_match_all($pattern, $content, $matches);
         $imgTag = '';
         if ($matches && count($matches[0]) > 0) {
             foreach ($matches[0] as $match) {
                 // exclude bbcodes from markitup
                 if (stristr($match, '/markitup/') === false) {
                     $imgTag = $match;
                     break;
                 }
             }
         }
         //Parse the bbcode first if using bbcode editor
         if ($config->get('layout_editor') == 'bbcode') {
             $content = EasyDiscussParser::bbcode($content);
         }
         $content = html_entity_decode(strip_tags($content));
         $content = JString::substr($content, 0, $config->get('integration_jomsocial_activity_content_length')) . '...';
         if ($imgTag) {
             $imgTag = JString::str_ireplace('img ', 'img style="margin: 0 5px 5px 0;float:left;height:auto;width: 120px !important;"', $imgTag);
             $content = $imgTag . $content . '<div style="clear:both;"></div>';
         }
         $content .= '<div style="text-align: right;"><a href="' . $link . '">' . JText::_('COM_EASYDISCUSS_JOMSOCIAL_ACTIVITY_REPLY_QUESTION_PARTICIPATE') . '</a></div>';
     }
     //get category privacy.
     $category_id = $post->category_id;
     if (!$post->category_id && $post->parent_id) {
         $postTable = DiscussHelper::getTable('Posts');
         $postTable->load($post->parent_id);
         $category_id = $postTable->category_id;
     }
     $category = DiscussHelper::getTable('Category');
     $category->load($category_id);
     $obj = new stdClass();
     $obj->access = $this->getActivityAccess();
     $obj->title = JText::sprintf('COM_EASYDISCUSS_JOMSOCIAL_ACTIVITY_REPLY_QUESTION', $replyLink, $link, $title);
     $obj->content = $content;
     $obj->cmd = 'easydiscuss.question.reply';
     $obj->actor = $post->user_id;
     $obj->target = 0;
     $obj->like_id = $post->id;
     $obj->like_type = 'com_easydiscuss';
     $obj->comment_id = $post->id;
     $obj->comment_type = 'com_easydiscuss';
     $obj->app = 'easydiscuss';
     $obj->cid = $post->id;
     // add JomSocial activities
     CFactory::load('libraries', 'activities');
     CActivityStream::add($obj);
 }
Ejemplo n.º 3
0
 public function getSignature($raw = false)
 {
     if (!array_key_exists('signature', $this->_data)) {
         if ($raw) {
             $this->_data['signature'] = trim($this->signature);
         } else {
             $this->_data['signature'] = nl2br(EasyDiscussParser::bbcode($this->signature));
         }
     }
     return $this->_data['signature'];
 }
Ejemplo n.º 4
0
 private function setPageHeaders($post)
 {
     // Set page title.
     DiscussHelper::setPageTitle($post->getTitle());
     $doc = JFactory::getDocument();
     $doc->setMetadata('keywords', $post->title);
     $doc->setMetadata('description', preg_replace('/\\s+/', ' ', substr(strip_tags(EasyDiscussParser::bbcode($post->content)), 0, 160)));
     // Set canonical link to avoid URL duplication.
     $doc->addHeadLink(DISCUSS_JURIROOT . DiscussRouter::getPostRoute($post->id), 'canonical', 'rel');
 }
Ejemplo n.º 5
0
 public function replyNotifyUsers($reply, $user, $senderName)
 {
     //send notification to all comment's subscribers that want to receive notification immediately
     $notify = DiscussHelper::getNotification();
     $emailData = array();
     $config = DiscussHelper::getConfig();
     $parent = DiscussHelper::getTable('Post');
     $parent->load($reply->parent_id);
     if ($reply->get('user_type') == DISCUSS_POSTER_GUEST) {
         $emailData['postAuthor'] = $senderName;
         $emailData['commentAuthor'] = $senderName;
         $emailData['replyAuthorAvatar'] = '';
     } else {
         $profile = DiscussHelper::getTable('Profile');
         $profile->load($user->id);
         $emailData['replyAuthor'] = $profile->getName();
         $emailData['commentAuthor'] = $profile->getName();
         $emailData['replyAuthorAvatar'] = $profile->getAvatar();
     }
     $emailContent = $reply->content;
     if ($reply->content_type != 'html') {
         // the content is bbcode. we need to parse it.
         $emailContent = EasyDiscussParser::bbcode($emailContent);
         $emailContent = EasyDiscussParser::removeBrTag($emailContent);
     }
     // If reply is html type we need to strip off html codes.
     if ($reply->content_type == 'html') {
         $emailContent = strip_tags($emailContent);
     }
     $emailContent = $parent->trimEmail($emailContent);
     $emailData['postTitle'] = $parent->title;
     $emailData['comment'] = $reply->content;
     $emailData['postLink'] = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=post&id=' . $parent->id, false, true);
     $emailData['replyContent'] = $reply->content;
     $attachments = $reply->getAttachments();
     $emailData['attachments'] = $attachments;
     $excludeEmails = array();
     $subscriberEmails = array();
     if (($config->get('main_sitesubscription') || $config->get('main_postsubscription')) && $config->get('notify_subscriber') && $reply->published == DISCUSS_ID_PUBLISHED) {
         $emailData['emailTemplate'] = 'email.subscription.reply.new.php';
         $emailData['emailSubject'] = JText::sprintf('COM_EASYDISCUSS_NEW_REPLY_ADDED', $parent->id, $parent->title);
         $emailData['post_id'] = $parent->id;
         $emailData['cat_id'] = $parent->category_id;
         //$subcribersEmails = DiscussHelper::getHelper( 'Mailer' )->notifyThreadSubscribers( $emailData );
         //$excludeEmails		= array_merge( $excludeEmails, $subcribersEmails);
         // Notify all subscriber about new replies
         DiscussHelper::getHelper('Mailer')->notifySubscribers($emailData, $excludeEmails);
     }
     //notify post owner.
     $postOwnerId = $parent->user_id;
     $postOwner = JFactory::getUser($postOwnerId);
     $ownerEmail = $postOwner->email;
     if ($parent->user_type != 'member') {
         $ownerEmail = $parent->poster_email;
     }
     if ($config->get('notify_owner') && $reply->published == DISCUSS_ID_PUBLISHED && $postOwnerId != $user->id && !in_array($ownerEmail, $subscriberEmails) && !empty($ownerEmail)) {
         $emailData['owner_email'] = $ownerEmail;
         $emailData['emailSubject'] = JText::sprintf('COM_EASYDISCUSS_NEW_REPLY_ADDED', $parent->id, $parent->title);
         $emailData['emailTemplate'] = 'email.post.reply.new.php';
         DiscussHelper::getHelper('Mailer')->notifyThreadOwner($emailData);
         $excludeEmails[] = $ownerEmail;
     }
     // Notify Participants
     if ($config->get('notify_participants') && $table->published == DISCUSS_ID_PUBLISHED) {
         $emailData['emailSubject'] = JText::sprintf('COM_EASYDISCUSS_NEW_REPLY_ADDED', $parent->id, $parent->title);
         $emailData['emailTemplate'] = 'email.post.reply.new.php';
         DiscussHelper::getHelper('Mailer')->notifyThreadParticipants($emailData, $excludeEmails);
     }
     //if reply under moderation, send owner a notification.
     if ($reply->published == DISCUSS_ID_PENDING) {
         // Generate hashkeys to map this current request
         $hashkey = DiscussHelper::getTable('Hashkeys');
         $hashkey->uid = $reply->id;
         $hashkey->type = DISCUSS_REPLY_TYPE;
         $hashkey->store();
         $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_REPLY') . '</a>';
         $emailData['moderation'] .= ' ' . JText::_('COM_EASYDISCUSS_OR') . ' <a href="' . $rejectURL . '" style="color:#477fda">' . JText::_('COM_EASYDISCUSS_REJECT') . '</a>';
         $emailData['moderation'] .= '</div>';
         $emailData['emailSubject'] = JText::sprintf('COM_EASYDISCUSS_NEW_REPLY_MODERATE', $parent->title);
         $emailData['emailTemplate'] = 'email.post.reply.moderation.php';
         DiscussHelper::getHelper('Mailer')->notifyAdministrators($emailData, array(), $config->get('notify_admin'), $config->get('notify_moderator'));
     } elseif ($table->published == DISCUSS_ID_PUBLISHED) {
         $emailData['emailTemplate'] = 'email.post.reply.new.php';
         $emailData['emailSubject'] = JText::sprintf('COM_EASYDISCUSS_NEW_REPLY_ADDED', $parent->id, $parent->title);
         $emailData['post_id'] = $parent->id;
         DiscussHelper::getHelper('Mailer')->notifyAdministrators($emailData, array(), $config->get('notify_admin_onreply'), $config->get('notify_moderator_onreply'));
     }
 }
Ejemplo n.º 6
0
 public static function getData($params)
 {
     $db = DiscussHelper::getDBO();
     $count = (int) $params->get('count', 10);
     $filter = (int) $params->get('filter_option', 0);
     $state = (int) $params->get('filter_state', 0);
     $includeSubcat = (bool) $params->get('include_subcategories', 0);
     $catId = intval($params->get('category', 0));
     $tagId = intval($params->get('tags', 0));
     $limitQuery = '';
     $catQuery = '';
     $exclusionQuery = '';
     if (!empty($count)) {
         $limitQuery = 'LIMIT 0,' . $count;
     }
     if ($state == 1) {
         // Unanswered
         $stateQuery = ' AND a.`isresolve`=' . $db->Quote(0);
         $stateQuery .= ' AND a.`answered`=' . $db->Quote(0);
         //Order query
         $orderBy = 'ORDER BY a.`replied` DESC ';
     } else {
         $stateQuery = '';
         $orderBy = 'ORDER BY a.`created` DESC ';
     }
     if ($filter == 0 || $filter == 1) {
         if ($filter == 1 && !empty($catId)) {
             if (!$includeSubcat) {
                 $catQuery = ' AND a.`category_id` = ' . $db->quote($catId) . ' ';
             } else {
                 $catIds = array($catId);
                 self::appendChildCategories($catId, $catIds);
                 JArrayHelper::toInteger($catIds);
                 $catQuery = ' AND a.`category_id` IN (' . implode(',', $catIds) . ') ';
             }
         }
         $excludedCategories = DiscussHelper::getPrivateCategories();
         if (!empty($excludedCategories)) {
             $exclusionQuery .= ' AND a.`category_id` NOT IN (' . implode(',', $excludedCategories) . ')';
         }
         $query = 'SELECT a.*, (SELECT COUNT(1) FROM `#__discuss_posts` WHERE `parent_id` = a.`id` AND `published`="1") AS `num_replies` FROM ' . $db->nameQuote('#__discuss_posts') . ' AS a ' . 'WHERE a.`published`=' . $db->Quote(1) . ' ' . 'AND a.`parent_id`=' . $db->Quote(0) . ' ' . $catQuery . $exclusionQuery . $stateQuery . $groupByQuery . $orderBy . $limitQuery;
     }
     if ($filter == 2) {
         $query = 'SELECT a.*, (SELECT COUNT(1) FROM `#__discuss_posts` WHERE `parent_id` = a.`id` AND `published`="1") AS `num_replies` ' . ' FROM ' . $db->nameQuote('#__discuss_posts') . ' AS a' . ' LEFT JOIN ' . $db->nameQuote('#__discuss_posts_tags') . ' AS c' . ' ON a.' . $db->nameQuote('id') . '= c.' . $db->nameQuote('post_id') . ' WHERE a.' . $db->nameQuote('published') . '=' . $db->Quote(1) . ' AND a.' . $db->nameQuote('parent_id') . '=' . $db->Quote(0) . ' AND b.' . $db->nameQuote('published') . '=' . $db->Quote(1) . ' AND c.' . $db->nameQuote('tag_id') . '=' . $db->Quote($tagId) . $stateQuery . $groupByQuery . $orderBy . $limitQuery;
     }
     if ($filter == 3) {
         // If featured post + unanswered settings in backend showing no post in the madule
         // is because featured post considered as answered
         // this behaviour is respecting to the component's "unanswered tab"
         $query = 'SELECT a.*, (SELECT COUNT(1) FROM `#__discuss_posts` WHERE `parent_id` = a.`id` AND `published`="1") AS `num_replies` ' . ' FROM ' . $db->nameQuote('#__discuss_posts') . ' AS a' . ' WHERE a.' . $db->nameQuote('published') . '=' . $db->Quote(1) . ' AND a.' . $db->nameQuote('parent_id') . '=' . $db->Quote(0) . ' AND a.' . $db->nameQuote('featured') . '=' . $db->Quote(1) . $stateQuery . $groupByQuery . $orderBy . $limitQuery;
     }
     $db->setQuery($query);
     if (!($result = $db->loadObjectList())) {
         return false;
     }
     $posts = array();
     require_once DISCUSS_HELPERS . '/parser.php';
     foreach ($result as $row) {
         $profile = DiscussHelper::getTable('Profile');
         $profile->load($row->user_id);
         $row->profile = $profile;
         $row->content = EasyDiscussParser::bbcode($row->content);
         $row->title = DiscussHelper::wordFilter($row->title);
         $row->content = DiscussHelper::wordFilter($row->content);
         // Process bbcode
         $row->content = EasyDiscussParser::bbcode($row->content);
         $posts[] = $row;
     }
     // Append profile objects to the result
     return $posts;
 }
Ejemplo n.º 7
0
 /**
  * Shares a new content on Facebook
  **/
 public function share($post)
 {
     $config = DiscussHelper::getConfig();
     $content = $post->content;
     $content = EasyDiscussParser::bbcode($content);
     JFactory::getLanguage()->load('com_easydiscuss', JPATH_ROOT);
     $editor = DiscussHelper::getEditorType('question');
     if ($editor == 'html') {
         // @rule: Match images from content
         $pattern = '/<\\s*img [^\\>]*src\\s*=\\s*[\\""\']?([^\\""\'\\s>]*)/i';
     } else {
         $pattern = '/\\[img\\](.*?)\\[\\/img\\]/ims';
     }
     preg_match($pattern, $content, $matches);
     $image = '';
     if ($matches) {
         $image = isset($matches[1]) ? $matches[1] : '';
         if (JString::stristr($matches[1], 'https://') === false && JString::stristr($matches[1], 'http://') === false && !empty($image)) {
             $image = DISCUSS_JURIROOT . '/' . ltrim($image, '/');
         }
     }
     $text = strip_tags($content);
     // @TODO: Configurable content length.
     $maxLength = 200;
     $text = JString::strlen($text) > $maxLength ? JString::substr($text, 0, $maxLength) . '...' : $text;
     $url = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=post&id=' . $post->id, false, true);
     $this->_access_token = preg_replace('/&expires=.*/i', '', $this->_access_token);
     $jConfig = DiscussHelper::getJConfig();
     $params = array('link' => $url, 'name' => $post->title, 'actions' => '{"name": "' . JText::_('COM_EASYDISCUSS_AUTOPOST_FB_VIEWON_BUTTON') . '", "link" : "' . $url . '"}', 'description' => $text, 'message' => JString::substr(strip_tags($text), 0, 30) . '...', 'access_token' => $this->_access_token);
     if (!empty($image)) {
         // Since Facebook does not allow https images we need to replace them here.
         $params['picture'] = str_ireplace('https://', 'http://', $image);
     } else {
         $params['picture'] = DISCUSS_JURIROOT . '/media/com_easydiscuss/images/default_facebook.png';
         $params['source'] = rtrim(JURI::root(), '/') . '/media/com_easydiscuss/images/default_facebook.png';
     }
     // @rule: See if we need to post this to a Facebook page instead.
     $pageId = $config->get('main_autopost_facebook_page_id');
     if (!empty($pageId)) {
         $pages = JString::trim($pageId);
         $pages = explode(',', $pages);
         $total = count($pages);
         // @rule: Test if there are any pages at all the user can access
         $accounts = parent::api('/me/accounts', array('access_token' => $this->_access_token));
         if (is_array($accounts) && isset($accounts['data'])) {
             for ($i = 0; $i < $total; $i++) {
                 foreach ($accounts['data'] as $page) {
                     if ($page['id'] == $pages[$i]) {
                         $params['access_token'] = $page['access_token'];
                         $query = parent::api('/' . $page['id'] . '/feed', 'post', $params);
                     }
                 }
             }
         }
     } else {
         // @rule: If this is just a normal posting, just post it on their page.
         $query = parent::api('/me/feed', 'post', $params);
     }
     $success = isset($query['id']) ? true : false;
     return $success;
 }
Ejemplo n.º 8
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);
 }