public static function getButtonHTML($row, $position = 'vertical') { $config = DiscussHelper::getConfig(); if (!$config->get('integration_digg')) { return ''; } $dataURL = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=post&id=' . $row->id, false, true); $dataURL = urlencode($dataURL); $html = ''; if ($position == 'horizontal') { $class = 'DiggCompact'; } else { $class = 'DiggMedium'; } $html = '<script type="text/javascript">(function() { var s = document.createElement(\'SCRIPT\'), s1 = document.getElementsByTagName(\'SCRIPT\')[0]; s.type = \'text/javascript\'; s.async = true; s.src = \'http://widgets.digg.com/buttons.js\'; s1.parentNode.insertBefore(s, s1); })(); </script> <!-- Wide Button --> <div class="social-button digg-share"><a class="DiggThisButton ' . $class . '" href="https://digg.com/submit?url=' . $dataURL . '&title=' . $row->title . '"></a></div>'; return $html; }
function process() { $view = new EasyDiscussView(); $date = DiscussHelper::getDate(); $now = $date->toMySQL(); $modelSubscribe = $view->getModel('Subscribe'); $subscribers = $modelSubscribe->getSiteSubscribers($this->interval, $now); $total = count($subscribers); if (empty($total)) { return false; } foreach ($subscribers as $subscriber) { $notify = DiscussHelper::getNotification(); $data = array(); $rows = $modelSubscribe->getCreatedPostByInterval($subscriber->sent_out, $now); $posts = array(); if ($rows) { foreach ($rows as $row) { $row['categorylink'] = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=categorie&layout=listings&category_id=' . $row['category_id'], false, true); $row['link'] = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=post&id=' . $row['id'], false, true); $row['userlink'] = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=profile&id=' . $row['user_id'], false, true); $category = DiscussHelper::getTable('Category'); $creator = DiscussHelper::getTable('Profile'); $category->load($row['category_id']); $creator->load($row['user_id']); $row['category'] = $category->getTitle(); $row['avatar'] = $creator->getAvatar(); $row['name'] = $creator->getName(); $row['date'] = DiscussDateHelper::toFormat($row['created'], '%b %e, %Y'); $row['message'] = DiscussHelper::parseContent($row['content']); $posts[] = $row; } } $data['post'] = $posts; $data['total'] = count($data['post']); $data['unsubscribeLink'] = DiscussHelper::getUnsubscribeLink($subscriber, true, true); $subject = $date->toMySQL(); switch (strtoupper($this->interval)) { case 'DAILY': $subject = $date->toFormat('%F'); $data['interval'] = JText::_('today'); break; case 'WEEKLY': $subject = $date->toFormat('%V'); $data['interval'] = JText::_('this week'); break; case 'MONTHLY': $subject = $date->toFormat('%B'); $data['interval'] = JText::_('this month'); break; } if (!empty($data['post'])) { $notify->addQueue($subscriber->email, JText::sprintf('COM_EASYDISCUSS_YOUR_' . $this->interval . '_SUBSCRIPTION', $subject), '', 'email.subscription.site.interval.php', $data); } $subscribe = DiscussHelper::getTable('Subscribe'); $subscribe->load($subscriber->id); $subscribe->sent_out = $now; $subscribe->store(); } }
function requestAccess() { $session = JFactory::getSession(); if ($session->has('twitter_oauth_request_token', 'discuss')) { $session->clear('twitter_oauth_request_token', 'discuss'); } $config = DiscussHelper::getConfig(); $consumerKey = $config->get('integration_twitter_consumer_key'); $consumerSecretKey = $config->get('integration_twitter_consumer_secret_key'); $consumer = new DiscussTwitterOAuth($consumerKey, $consumerSecretKey); $callback = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&controller=twitter&task=authorizeAccess', false, true); $request_token = $consumer->getRequestToken($callback); $session->set('twitter_oauth_request_token', "oauth_token=" . $request_token['oauth_token'] . ",oauth_token_secret=" . $request_token['oauth_token_secret'], 'discuss'); $this->setRedirect($consumer->getAuthorizeURL($request_token['oauth_token'], FALSE)); }
public function addOpenGraph(DiscussPost $post) { // Use facebook developer tools to check the result // https://developers.facebook.com/tools/debug/og $doc = JFactory::getDocument(); $config = DiscussHelper::getConfig(); // Search for an image in the content $image = self::searchImage($post->content); if ($image) { $doc->addCustomTag('<meta property="og:image" content="' . $image . '" />'); } if ($config->get('integration_facebook_like')) { $appId = $config->get('integration_facebook_like_appid'); if ($appId) { $doc->addCustomTag('<meta property="fb:app_id" content="' . $appId . '" />'); } $adminId = $config->get('integration_facebook_like_admin'); if ($adminId) { $doc->addCustomTag('<meta property="fb:admins" content="' . $adminId . '" />'); } } // Add post title info here. $doc->addCustomTag('<meta property="og:title" content="' . $post->title . '" />'); // Add post content. $maxContent = 350; // Remove bbcode tags from the content. $content = EasyDiscussParser::removeCodes($post->content); $content = strip_tags($post->content); if (JString::strlen($content) > $maxContent) { $content = JString::substr($content, 0, $maxContent) . '...'; } // Add content to description $doc->addCustomTag('<meta property="og:description" content="' . $content . '" />'); // Add the type of the og tag. $doc->addCustomTag('<meta property="og:type" content="article" />'); // Add the URL for this page. $url = DiscussRouter::getRoutedURL(DiscussRouter::getPostRoute($post->id, false, true)); $doc->addCustomTag('<meta property="og:url" content="' . $url . '" />'); $doc->setTitle($post->title); $doc->setDescription($content); return true; }
public static function getButtonHTML($row, $position = 'vertical') { $config = DiscussHelper::getConfig(); if (!$config->get('integration_linkedin')) { return ''; } $button = $config->get('integration_linkedin_button'); $dataURL = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=post&id=' . $row->id, false, true); if ($position == 'horizontal') { $counter = ' data-counter="right"'; } else { $counter = ' data-counter="top"'; } $html = ''; $html = '<div class="social-button linkedin-share">'; $html .= '<script type="text/javascript" src="https://platform.linkedin.com/in.js"></script>'; $html .= '<script type="in/share" data-url="' . $dataURL . '"' . $counter . '></script>'; $html .= '</div>'; return $html; }
public static function getButtonHTML($row, $position = 'vertical') { $config = DiscussHelper::getConfig(); if (!$config->get('integration_twitter_button')) { return ''; } $html = ''; $style = $config->get('integration_twitter_button_style'); $dataURL = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=post&id=' . $row->id, false, true); $width = '80px'; if ($position == 'horizontal') { $style = 'horizontal'; $width = '80px'; } else { $width = '55px'; $style = 'vertical'; } $html = '<div class="social-button retweet" style="width: ' . $width . '"><a href="http://twitter.com/share" class="twitter-share-button" data-url="' . $dataURL . '" data-counturl="' . $dataURL . '" data-count="' . $style . '">Tweet</a><script type="text/javascript" src="https://platform.twitter.com/widgets.js"></script></div>'; return $html; }
public static function getButtonHTML($row, $position = 'vertical') { $config = DiscussHelper::getConfig(); if (!$config->get('integration_googleshare')) { return ''; } $size = $config->get('integration_googleshare_layout'); $dataURL = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=post&id=' . $row->id, false, true); $googleShare = ''; if ($position == 'horizontal') { $size = 'medium'; $width = '170px'; } else { $size = 'tall'; $width = '50px'; } $googleShare .= '<div class="social-button google-share" style="width:' . $width . '">'; $googleShare .= '<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>'; $googleShare .= '<g:plus action="share" size="' . $size . '" href="' . $dataURL . '"></g:plus>'; $googleShare .= '</div>'; return $googleShare; }
public static function getLikeHTML($row, $position = 'vertical') { $config = DiscussHelper::getConfig(); if (!$config->get('integration_facebook_like')) { return ''; } $document = JFactory::getDocument(); $language = $document->getLanguage(); $language = explode('-', $language); if (count($language) != 2) { $language = array('en', 'GB'); } $layout = $config->get('integration_facebook_like_layout'); $faces = $config->get('integration_facebook_like_faces') ? 'true' : 'false'; $width = $config->get('integration_facebook_like_width'); $verb = $config->get('integration_facebook_like_verb'); $theme = $config->get('integration_facebook_like_theme'); $send = $config->get('integration_facebook_like_send') ? 'true' : 'false'; $height = $faces == 'true' ? '70' : '30'; $locale = $language[0] . '_' . JString::strtoupper($language[1]); $fb = DiscussHelper::getHelper('Facebook'); $fb->addOpenGraph($row); $url = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=post&id=' . $row->id, true, true); $html = ''; if ($position == 'horizontal') { $layout = 'button_count'; } else { $layout = 'box_count'; } $html = '<div class="social-button facebook-like">'; if ($config->get('integration_facebook_scripts')) { $html .= '<div id="fb-root"></div><script src="https://connect.facebook.net/' . $locale . '/all.js#xfbml=1"></script>'; } $html .= '<fb:like href="' . $url . '" send="' . $send . '" layout="' . $layout . '" action="' . $verb . '" '; $html .= 'locale="' . $locale . '" colorscheme="' . $theme . '" show_faces="' . $faces . '" style="height: ' . $height . ';" height="' . $height . '"></fb:like>'; $html .= '</div>'; return $html; }
/** * Processes ajax request when a user likes an item. * * @since 1.0 * @access public * @param string * @return */ public function like() { $my = JFactory::getUser(); $ajax = DiscussHelper::getHelper('ajax'); $config = DiscussHelper::getConfig(); // Get the post. $postId = JRequest::getInt('postid'); $post = DiscussHelper::getTable('Post'); $post->load($postId); // Determine if the likes are enabled or not. if ($post->isReply() && !$config->get('main_likes_replies') || $post->isQuestion() && !$config->get('main_likes_discussions')) { return $ajax->reject(); } // Do not allow non logged in users to like an item. if (!$my->id) { return $ajax->reject(); } // Determine if the current user request is to like the post item or unlike. $isLike = !$post->isLikedBy($my->id); if ($isLike) { DiscussHelper::getHelper('Likes')->addLikes($post->id, 'post', $my->id); } else { // If this is an unlike request, we need to remove it. DiscussHelper::getHelper('Likes')->removeLikes($post->id, $my->id); } // Get the main question if this is a reply. if ($post->isReply()) { $question = DiscussHelper::getTable('Post'); $question->load($post->parent_id); } else { $question = $post; } // Add JomSocial activity item if the post for the main discussion item if it has been liked. if ($post->published && $isLike) { // EasySocial instegrations DiscussHelper::getHelper('EasySocial')->notify('new.likes', $post, $question); DiscussHelper::getHelper('jomsocial')->addActivityLikes($post, $question); DiscussHelper::getHelper('easysocial')->likesStream($post, $question); } // Add a badge record for the user when they like a discussion // The record should only be added when the user liked another user's post. if ($post->isQuestion() && $isLike && $my->id != $post->user_id) { // Add logging for user. DiscussHelper::getHelper('History')->log('easydiscuss.like.discussion', $my->id, JText::sprintf('COM_EASYDISCUSS_BADGES_HISTORY_LIKE_DISCUSSION', $question->title), $post->id); DiscussHelper::getHelper('Badges')->assign('easydiscuss.like.discussion', $my->id); DiscussHelper::getHelper('Points')->assign('easydiscuss.like.discussion', $my->id); // Assign badge for EasySocial DiscussHelper::getHelper('EasySocial')->assignBadge('like.question', $my->id, JText::sprintf('COM_EASYDISCUSS_BADGES_HISTORY_LIKE_DISCUSSION', $question->title)); } // Add a badge record for the user when they like a discussion // The record should only be added when the user liked another user's post. if ($post->isReply() && $isLike && $my->id != $post->user_id) { // Add logging for user. DiscussHelper::getHelper('History')->log('easydiscuss.like.reply', $my->id, JText::sprintf('COM_EASYDISCUSS_BADGES_HISTORY_LIKE_REPLY', $post->title), $post->id); DiscussHelper::getHelper('Badges')->assign('easydiscuss.like.reply', $my->id); DiscussHelper::getHelper('Points')->assign('easydiscuss.like.reply', $my->id); } // Remove history when a user unlikes a discussion. if ($post->isQuestion() && !$isLike && $my->id != $post->user_id) { // Remove unlike DiscussHelper::getHelper('History')->removeLog('easydiscuss.like.discussion', $my->id, $post->id); DiscussHelper::getHelper('Badges')->assign('easydiscuss.unlike.discussion', $my->id); DiscussHelper::getHelper('Points')->assign('easydiscuss.unlike.discussion', $my->id); } // Remove history when a user unlikes a reply. if ($post->isReply() && !$isLike && $my->id != $post->user_id) { // Remove unlike DiscussHelper::getHelper('History')->removeLog('easydiscuss.like.reply', $my->id, $post->id); DiscussHelper::getHelper('Badges')->assign('easydiscuss.unlike.reply', $my->id); DiscussHelper::getHelper('Points')->assign('easydiscuss.unlike.reply', $my->id); } // Add notifications to the post owner. if ($post->user_id != $my->id) { $notification = DiscussHelper::getTable('Notifications'); $text = $post->isQuestion() ? 'COM_EASYDISCUSS_LIKE_DISCUSSION_NOTIFICATION_TITLE' : 'COM_EASYDISCUSS_LIKE_REPLY_NOTIFICATION_TITLE'; $title = $question->title; $likeType = $post->isQuestion() ? DISCUSS_NOTIFICATIONS_LIKES_DISCUSSION : DISCUSS_NOTIFICATIONS_LIKES_REPLIES; $notification->bind(array('title' => JText::sprintf($text, $title), 'cid' => $question->id, 'type' => $likeType, 'target' => $post->user_id, 'author' => $my->id, 'permalink' => 'index.php?option=com_easydiscuss&view=post&id=' . $question->id)); $notification->store(); } // Only send notification email if the post owner is a registered user. // And, it would not send email if the user that is liking on his own item. if ($post->user_id && $my->id != $post->user_id && $isLike && $config->get('notify_owner_like')) { // Send email to post / reply author that someone liked their post. $notify = DiscussHelper::getNotification(); $profile = DiscussHelper::getTable('Profile'); $profile->load($my->id); $emailSubject = JText::sprintf('COM_EASYDISCUSS_USER_LIKED_YOUR_POST', $profile->getName()); $emailTemplate = 'email.like.post.php'; $emailData = array(); $emailData['authorName'] = $profile->getName(); $emailData['authorAvatar'] = $profile->getAvatar(); $emailData['replyContent'] = $post->content; $emailData['postLink'] = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=post&id=' . $question->id, false, true); $recipient = JFactory::getUser($post->user_id); $notify->addQueue($recipient->email, $emailSubject, '', $emailTemplate, $emailData); } // Get the like's text. $likeText = DiscussHelper::getHelper('Likes')->getLikesHTML($post->id, $my->id, 'post'); if (!$likeText) { $likeText = JText::_('COM_EASYDISCUSS_BE_THE_FIRST_TO_LIKE'); } $count = DiscussHelper::getModel('Likes')->getTotalLikes($postId); $ajax->resolve($likeText, $count); return $ajax->send(); }
/** * Notify the user when a new conversation is started or replied. * * @since 3.0 * @access public * @param DiscussConversationMessage The message object that is formatted * */ public function notify(DiscussConversationMessage $message) { $author = DiscussHelper::getTable('Profile'); $author->load($message->created_by); $model = DiscussHelper::getModel('Conversation'); $result = $model->getParticipants($this->id, $message->created_by); $recipient = DiscussHelper::getTable('Profile'); $recipient->load($result[0]); $emailData = array(); $emailData['conversationLink'] = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=conversation&layout=read&id=' . $this->id, false, true); $emailData['authorName'] = $author->getName(); $emailData['authorAvatar'] = $author->getAvatar(); $emailData['content'] = $message->message; $subject = JText::sprintf('COM_EASYDISCUSS_CONVERSATION_EMAIL_SUBJECT', $author->getName()); $notification = DiscussHelper::getNotification(); $notification->addQueue($recipient->user->email, $subject, '', 'email.conversation.reply.php', $emailData); }
public function addActivityBadges($badge) { $core = JPATH_ROOT . '/components/com_community/libraries/core.php'; $config = DiscussHelper::getConfig(); $my = JFactory::getUser(); if (!JFile::exists($core)) { return false; } require_once $core; $lang = JFactory::getLanguage(); $lang->load('com_easydiscuss', JPATH_ROOT); // We do not want to add activities if new badges activity is disabled. if (!$config->get('integration_jomsocial_activity_badges', 0)) { return false; } $link = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=badges&layout=listings&id=' . $badge->id); $content = '<img src="' . $badge->getAvatar() . '" />'; $title = $this->getActivityTitle($badge->title); $obj = new stdClass(); $obj->title = JText::sprintf('COM_EASYDISCUSS_JOMSOCIAL_ACTIVITY_BADGES_ITEM', $link, $title); $obj->content = $content; $obj->cmd = 'easydiscuss.badges.earned'; $obj->actor = $my->id; $obj->target = 0; $obj->like_id = $badge->uniqueId; $obj->like_type = 'com_easydiscuss_badge'; $obj->comment_id = $badge->uniqueId; $obj->comment_type = 'com_easydiscuss_badge'; $obj->app = 'easydiscuss'; $obj->cid = $badge->uniqueId; // add JomSocial activities CFactory::load('libraries', 'activities'); CActivityStream::add($obj); }
/** * 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 submit() { $config = DiscussHelper::getConfig(); $my = JFactory::getUser(); $id = JRequest::getInt('id'); $app = JFactory::getApplication(); $post = DiscussHelper::getTable('Post'); $state = $post->load($id); $acl = DiscussHelper::getHelper('ACL'); if (!$post->id || !$state) { DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_INVALID_POST_ID'), DISCUSS_QUEUE_ERROR); $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss', false)); $app->close(); } // Get the URL to the discussion. $url = DiscussRouter::getPostRoute($post->id, false); if ($post->isReply()) { $url = DiscussRouter::getPostRoute($post->parent_id, false); } if (!$acl->allowed('send_report')) { DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_YOU_DO_NOT_HAVE_PERMISION_TO_SUBMIT_REPORT'), DISCUSS_QUEUE_ERROR); $app->redirect($url); $app->close(); } if (!$config->get('main_report')) { DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_REPORT_HAS_BEEN_DISABLED_BY_ADMINISTRATOR'), DISCUSS_QUEUE_ERROR); $app->redirect($url); $app->close(); } $message = JRequest::getString('reporttext', ''); if (empty($message)) { DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_REPORT_EMPTY_TEXT'), DISCUSS_QUEUE_ERROR); $app->redirect($url); $app->close(); } $date = DiscussHelper::getDate(); $report = DiscussHelper::getTable('Report'); $report->created_by = $my->id; $report->post_id = $post->id; $report->reason = $message; $report->created = $date->toMySQL(); if (!$report->store()) { DiscussHelper::setMessageQueue($report->getError(), DISCUSS_QUEUE_ERROR); $app->redirect($url); $app->close(); } // Mark post as reported. $report->markPostReport(); $threshold = $config->get('main_reportthreshold', 15); $totalReports = $report->getReportCount(); $redirectMessage = JText::_('COM_EASYDISCUSS_REPORT_SUBMITTED'); // Check if the number of reports for this post exceeded the threshold. if ($totalReports > $reportThreshold) { $owner = $post->getOwner(); $date = DiscussHelper::getDate($post->created); $emailData = array(); $emailData['postContent'] = $post->content; $emailData['postAuthor'] = $owner->name; $emailData['postAuthorAvatar'] = $owner->avatar; $emailData['postDate'] = $date->toFormat(); $emailData['postLink'] = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=post&id=' . $post->id, false, true); $emailData['emailSubject'] = JText::sprintf('COM_EASYDISCUSS_REPORT_REQUIRED_YOUR_ATTENTION', JString::substr($postTbl->content, 0, 15)) . '...'; $emailData['emailTemplate'] = 'email.post.attention.php'; if ($post->isReply()) { $emailData['postLink'] = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=post&id=' . $post->parent_id, false, true); } DiscussHelper::getHelper('Mailer')->notifyAdministrators($emailData, array(), $config->get('notify_admin'), $config->get('notify_moderator')); $redirectMessage = JText::_('COM_EASYDISCUSS_REPORT_SUBMITTED_BUT_POST_MARKED_AS_REPORT'); } DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_REPORT_SUBMITTED'), DISCUSS_QUEUE_SUCCESS); $app->redirect($url); }
/** * 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; }
/** * 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); }
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')); } }
/** * Process message **/ public function processMessage($message, $post) { $search = array(); $replace = array(); //replace title if (preg_match_all("/.*?(\\{title\\})/is", $message, $matches)) { $search[] = '{title}'; $replace[] = $post->title; } //replace category if (preg_match_all("/.*?(\\{category\\})/is", $message, $matches)) { $category = DiscussHelper::getTable('Category'); $category->load($post->category_id); $search[] = '{category}'; $replace[] = $category->title; } $message = JString::str_ireplace($search, $replace, $message); //replace link if (preg_match_all("/.*?(\\{url\\})/is", $message, $matches)) { $link = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=post&id=' . $post->id, false, true); // @rule: Detect the length of the link $length = JString::strlen($link); $balance = 140 - $length; $parts = explode('{url}', $message); $message = JString::substr($parts[0], 0, 119); $message .= ' ' . $link; return $message; } return JString::substr($message, 0, 140); }
/** * 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(); }
public static function getSubscriptionsManagerLink() { static $link = null; if (!$link) { $link = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=profile#Subscriptions', false, true); } return $link; }
} else { ?> <a class="attachment-image-link" <?php echo $system->config->get('attachment_image_title') ? 'title="' . $this->escape($attachment->title) . '"' : ''; ?> href="<?php echo DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&controller=attachment&task=displayFile&tmpl=component&id=' . $attachment->id, false, true); ?> "><img src="<?php echo JRoute::_('index.php?option=com_easydiscuss&controller=attachment&task=displayFile&tmpl=component&size=thumb&id=' . $attachment->id); ?> " title="<?php echo $this->escape($attachment->title); ?> " /></a> <div class="caption" style="text-align:center;"> <a class="attachment-image-link" title="<?php echo $this->escape($attachment->title); ?> " href="<?php echo DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&controller=attachment&task=displayFile&tmpl=component&id=' . $attachment->id, false, true); ?> "><?php echo $attachment->title; ?> </a> </div> <?php }
public static function getUnsubscribeLink($subdata, $external = false, $html = false) { $unsubdata = base64_encode("type=" . $subdata->type . "\r\nsid=" . $subdata->id . "\r\nuid=" . $subdata->userid . "\r\ntoken=" . md5($subdata->id . $subdata->created)); $link = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&controller=subscription&task=unsubscribe&data=' . $unsubdata, false, $external); return $link; }
/** * Process new reply submission called via an iframe. * * @since 2.0 * @access public */ public function ajaxSubmitReply() { // Process when a new reply is made from bbcode / wysiwyg editor $my = JFactory::getUser(); $config = DiscussHelper::getConfig(); $ajax = new Disjax(); $acl = DiscussHelper::getHelper('ACL'); $post = JRequest::get('POST'); // @task: User needs to be logged in, in order to submit a new reply. if (!$acl->allowed('add_reply', '0') && $my->id == 0) { // Append result $output = array(); $output['message'] = JText::_('COM_EASYDISCUSS_PLEASE_KINDLY_LOGIN_INORDER_TO_REPLY'); $output['type'] = 'error'; echo $this->_outputJson($output); return false; } if (!$acl->allowed('add_reply', '0')) { // Append result $output = array(); $output['message'] = JText::_('COM_EASYDISCUSS_ENTRY_NO_PERMISSION_TO_REPLY'); $output['type'] = 'error'; echo $this->_outputJson($output); return false; } if (!isset($post['parent_id'])) { // Append result $output = array(); $output['message'] = JText::_('COM_EASYDISCUSS_SYSTEM_INVALID_ID'); $output['type'] = 'error'; echo $this->_outputJson($output); return false; } $question = DiscussHelper::getTable('Post'); $state = $question->load($post['parent_id']); if (!$state) { // Append result $output = array(); $output['message'] = JText::_('COM_EASYDISCUSS_SYSTEM_INVALID_ID'); $output['type'] = 'error'; echo $this->_outputJson($output); return false; } // Ensure that the user really has access to the discussion if ($question->private && $my->id != $question->user_id && !DiscussHelper::isSiteAdmin() && !DiscussHelper::isModerator($post->category_id, $my->id)) { // Append result $output = array(); $output['message'] = JText::_('COM_EASYDISCUSS_SYSTEM_INSUFFICIENT_PERMISSIONS'); $output['type'] = 'error'; echo $this->_outputJson($output); return false; } $questionCategory = DiscussHelper::getTable('Category'); $questionCategory->load($question->category_id); $questionAccess = $question->getAccess($questionCategory); if (!$questionAccess->canReply()) { // Append result $output = array(); $output['message'] = JText::_('COM_EASYDISCUSS_ENTRY_NO_PERMISSION_TO_REPLY'); $output['type'] = 'error'; echo $this->_outputJson($output); return false; } if (empty($post['dc_reply_content'])) { // Append result $output = array(); $output['message'] = JText::_('COM_EASYDISCUSS_ERROR_REPLY_EMPTY'); $output['type'] = 'error'; echo $this->_outputJson($output); return false; } if (empty($my->id)) { if (empty($post['user_type'])) { // Append result $output = array(); $output['message'] = JText::_('COM_EASYDISCUSS_INVALID_USER_TYPE'); $output['type'] = 'error'; echo $this->_outputJson($output); return false; } if (!DiscussUserHelper::validateUserType($post['user_type'])) { $output = array(); $output['message'] = JText::sprintf('COM_EASYDISCUSS_THIS_USERTYPE_HAD_BEEN_DISABLED', $post['user_type']); $output['type'] = 'error'; echo $this->_outputJson($output); return false; } if (empty($post['poster_name']) || empty($post['poster_email'])) { $output = array(); $output['message'] = JText::sprintf('COM_EASYDISCUSS_GUEST_SIGN_IN_DESC'); $output['type'] = 'error'; echo $this->_outputJson($output); return false; } } else { $post['user_type'] = 'member'; $post['poster_name'] = ''; $post['poster_email'] = ''; } // get id if available $id = 0; // set alias $post['alias'] = DiscussHelper::getAlias($post['title'], 'post'); // set post owner $post['user_id'] = $my->id; $content = JRequest::getVar('dc_reply_content', '', 'post', 'none', JREQUEST_ALLOWRAW); $content = DiscussHelper::getHelper('String ')->unhtmlentities($content); // Rebind the post data $post['dc_reply_content'] = $content; $post['content_type'] = DiscussHelper::getEditorType('reply'); // Set the ip address $post['ip'] = JRequest::getVar('REMOTE_ADDR', '', 'SERVER'); // bind the table $table = DiscussHelper::getTable('Post'); $table->bind($post, true); // Set the category id for the reply since we might need to use this for acl checks. $table->category_id = $question->category_id; if ($config->get('main_moderatepost', 0) && !DiscussHelper::isModerateThreshold($my->id) && !DiscussHelper::isSiteAdmin($post->user_id)) { $table->published = DISCUSS_ID_PENDING; } else { $table->published = DISCUSS_ID_PUBLISHED; } require_once DISCUSS_CLASSES . '/recaptcha.php'; if (DiscussRecaptcha::isRequired()) { $obj = DiscussRecaptcha::recaptcha_check_answer($config->get('antispam_recaptcha_private'), $_SERVER['REMOTE_ADDR'], $post['recaptcha_challenge_field'], $post['recaptcha_response_field']); if (!$obj->is_valid) { $output = array(); $output['message'] = JText::_('COM_EASYDISCUSS_POST_INVALID_RECAPTCHA_RESPONSE'); $output['type'] = 'error.captcha'; echo $this->_outputJson($output); return false; } } 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) { $output = array(); $output['message'] = JText::sprintf('COM_EASYDISCUSS_INVALID_CAPTCHA'); $output['type'] = 'error'; echo $this->_outputJson($output); return false; } } } } 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' => $post['dc_reply_content'], 'alias' => ''); $akismet = new Akismet(DISCUSS_JURIROOT, $config->get('antispam_akismet_key'), $data); if (!$akismet->errorsExist()) { if ($akismet->isSpam()) { $output = array(); $output['message'] = JText::_('COM_EASYDISCUSS_AKISMET_SPAM_DETECTED'); $output['type'] = 'error'; echo $this->_outputJson($output); return false; } } } // hold last inserted ID in DB $lastId = null; // @rule: Bind parameters $table->bindParams($post); $isNew = true; // @trigger: onBeforeSave DiscussEventsHelper::importPlugin('content'); DiscussEventsHelper::onContentBeforeSave('reply', $table, $isNew); if (!$table->store()) { $output = array(); $output['message'] = JText::_('COM_EASYDISCUSS_ERROR_SUBMIT_REPLY'); $output['type'] = 'error'; echo $this->_outputJson($output); return false; } // Process poll items. if ($config->get('main_polls_replies')) { $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 ) if (!$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) { $pollItems = JRequest::getVar('pollitems'); // 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($table->id); $pollQuestion->post_id = $table->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(); } } } foreach ($pollItems as $item) { $value = (string) $item; if (trim($value) == '') { continue; } $poll = DiscussHelper::getTable('Poll'); if (!$poll->loadByValue($value, $table->id, $multiplePolls)) { $poll->set('value', $value); $poll->set('post_id', $table->get('id')); $poll->store(); } } } } } } // Process custom fields $this->saveCustomFieldsValue($table->id); // @trigger: onAfterSave DiscussEventsHelper::onContentAfterSave('reply', $table, $isNew); // @rule: Add notifications for the thread starter if ($table->published && $config->get('main_notifications_reply')) { // Get all users that are subscribed to this post $model = $this->getModel('Posts'); $participants = $model->getParticipants($table->parent_id); // Add the thread starter into the list of participants. $participants[] = $question->get('user_id'); // Notify all subscribers foreach ($participants as $participant) { if ($participant != $my->id) { $notification = DiscussHelper::getTable('Notifications'); $notification->bind(array('title' => JText::sprintf('COM_EASYDISCUSS_REPLY_DISCUSSION_NOTIFICATION_TITLE', $question->get('title')), 'cid' => $question->get('id'), 'type' => DISCUSS_NOTIFICATIONS_REPLY, 'target' => $participant, 'author' => $table->get('user_id'), 'permalink' => 'index.php?option=com_easydiscuss&view=post&id=' . $question->get('id'))); $notification->store(); } } // @rule: Detect if any names are being mentioned in the post $names = DiscussHelper::getHelper('String')->detectNames($table->content); if ($names) { foreach ($names as $name) { $name = JString::str_ireplace('@', '', $name); $id = DiscussHelper::getUserId($name); if (!$id || $id == $table->get('user_id')) { continue; } $notification = DiscussHelper::getTable('Notifications'); $notification->bind(array('title' => JText::sprintf('COM_EASYDISCUSS_MENTIONED_REPLY_NOTIFICATION_TITLE', $question->get('title')), 'cid' => $question->get('id'), 'type' => DISCUSS_NOTIFICATIONS_MENTIONED, 'target' => $id, 'author' => $table->get('user_id'), 'permalink' => 'index.php?option=com_easydiscuss&view=post&id=' . $question->get('id'))); $notification->store(); } } } if ($table->published && !$question->private) { // Create notification item in EasySocial DiscussHelper::getHelper('EasySocial')->notify('new.reply', $table, $question); // @rule: Badges DiscussHelper::getHelper('History')->log('easydiscuss.new.reply', $table->user_id, JText::sprintf('COM_EASYDISCUSS_BADGES_HISTORY_NEW_REPLY', $question->title), $table->id); DiscussHelper::getHelper('Badges')->assign('easydiscuss.new.reply', $table->user_id); DiscussHelper::getHelper('Points')->assign('easydiscuss.new.reply', $table->user_id, $table); // Assign badge for EasySocial DiscussHelper::getHelper('EasySocial')->assignBadge('reply.question', $table->user_id, JText::sprintf('COM_EASYDISCUSS_BADGES_HISTORY_NEW_REPLY', $question->title)); // @rule: AUP integrations DiscussHelper::getHelper('Aup')->assign(DISCUSS_POINTS_NEW_REPLY, $table->user_id, $question->title); // @rule: ranking DiscussHelper::getHelper('ranks')->assignRank($table->user_id, $config->get('main_ranking_calc_type')); } // Bind file attachments if ($acl->allowed('add_attachment', '0')) { if (!$table->bindAttachments() && $table->getError()) { $output = array(); $output['message'] = $table->getError(); $output['type'] = 'error'; echo $this->_outputJson($output); return false; } } $replier = new stdClass(); if ($my->id > 0) { $replier->id = $my->id; $replier->name = $my->name; } else { $replier->id = 0; $replier->name = JText::_('COM_EASYDISCUSS_GUEST'); // TODO: user the poster_name } //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($replier->id); $table->user = $creator; $voteModel = $this->getModel('votes'); // clean up bad code $table->content_raw = $table->content; //$table->content = DiscussHelper::parseContent( $table->content ); // @rule: URL References $table->references = $table->getReferences(); // Since this is a new reply, it's impossible that it has been voted before. $table->voted = false; // get total vote for this reply $table->totalVote = $table->sum_totalvote; $result['status'] = 'success'; $result['title'] = JText::_('COM_EASYDISCUSS_SUCCESS_SUBMIT_REPLY'); $result['id'] = $table->id; $result['message'] = JText::_('COM_EASYDISCUSS_REPLY_SAVED'); $table->title = DiscussHelper::wordFilter($table->title); $table->content = DiscussHelper::wordFilter($table->content); // Legacy fix when switching from WYSIWYG editor to bbcode. $table->content = EasyDiscussParser::html2bbcode($table->content); $table->content = DiscussHelper::formatContent($table, true); //all access control goes here. $canDelete = false; $isMainLocked = false; if (DiscussHelper::isSiteAdmin() || $acl->allowed('delete_reply', '0') || $table->user_id == $my->id) { $canDelete = true; } $parent = DiscussHelper::getTable('Post'); $parent->load($table->parent_id); $isMainLocked = $parent->islock; //default value $table->isVoted = 0; $table->total_vote_cnt = 0; $table->likesAuthor = ''; $table->minimize = 0; if ($config->get('main_content_trigger_replies')) { $tempContent = $table->content; $table->content = str_replace('@', '@', $tempContent); // process content plugins DiscussEventsHelper::importPlugin('content'); DiscussEventsHelper::onContentPrepare('reply', $table); $table->event = new stdClass(); $results = DiscussEventsHelper::onContentBeforeDisplay('reply', $table); $table->event->beforeDisplayContent = trim(implode("\n", $results)); $results = DiscussEventsHelper::onContentAfterDisplay('reply', $table); $table->event->afterDisplayContent = trim(implode("\n", $results)); } $tpl = new DiscussThemes(); $category = DiscussHelper::getTable('Category'); $category->load($question->category_id); $table->access = $table->getAccess($category); // Since the reply dont have any comments yet. $table->comments = array(); $tpl->set('category', $category); $tpl->set('post', $table); $tpl->set('question', $parent); $tpl->set('isMine', DiscussHelper::isMine($parent->user_id)); $tpl->set('isAdmin', DiscussHelper::isSiteAdmin()); $tpl->set('isMainLocked', $isMainLocked); $recaptcha = ''; $enableRecaptcha = $config->get('antispam_recaptcha', 0); $publicKey = $config->get('antispam_recaptcha_public'); $html = $table->published == DISCUSS_ID_PENDING ? $tpl->fetch('post.reply.item.moderation.php') : $tpl->fetch('post.reply.item.php'); //send notification to all comment's subscribers that want to receive notification immediately $notify = DiscussHelper::getNotification(); $excludeEmails = array(); $attachments = $table->getAttachments(); $emailData['attachments'] = $attachments; $emailData['postTitle'] = $parent->title; $emailData['comment'] = DiscussHelper::parseContent($table->content); $emailData['commentAuthor'] = $my->id ? $creator->getName() : $table->poster_name; $emailData['postLink'] = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=post&id=' . $parent->id, false, true); $emailContent = $table->content; $isEditing = $isNew == true ? false : true; $emailContent = DiscussHelper::bbcodeHtmlSwitcher($table, 'reply', $isEditing); $emailContent = $question->trimEmail($emailContent); $emailData['replyContent'] = $emailContent; $emailData['replyAuthor'] = $my->id ? $creator->getName() : $table->poster_name; $emailData['replyAuthorAvatar'] = $creator->getAvatar(); $emailData['post_id'] = $parent->id; $emailData['cat_id'] = $parent->category_id; $subscriberEmails = array(); if (($config->get('main_sitesubscription') || $config->get('main_postsubscription')) && $config->get('notify_subscriber') && $table->published == DISCUSS_ID_PUBLISHED) { $emailData['emailTemplate'] = 'email.subscription.reply.new.php'; $emailData['emailSubject'] = JText::sprintf('COM_EASYDISCUSS_NEW_REPLY_ADDED', $parent->id, $parent->title); $posterEmail = $post['poster_email'] ? $post['poster_email'] : $my->email; // Get the emails of user who subscribe to this post only // This does not send to subscribers whom subscribe to site and category $subcribersEmails = DiscussHelper::getHelper('Mailer')->notifyThreadSubscribers($emailData, array($posterEmail, $my->email)); $excludeEmails[] = $posterEmail; $excludeEmails = array_merge($excludeEmails, $subcribersEmails); $excludeEmails = array_unique($excludeEmails); } //notify post owner. $postOwnerId = $parent->user_id; $postOwner = JFactory::getUser($postOwnerId); $ownerEmail = $postOwner->email; if ($parent->user_type != 'member') { $ownerEmail = $parent->poster_email; } // Notify Owner // if reply under moderation, send owner a notification. if ($config->get('notify_owner') && $table->published == DISCUSS_ID_PUBLISHED && $postOwnerId != $replier->id && !in_array($ownerEmail, $excludeEmails) && !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); // Notify Participants $excludeEmails[] = $ownerEmail; $excludeEmails = array_unique($excludeEmails); } 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 ($table->published == DISCUSS_ID_PENDING) { // Notify admins. // Generate hashkeys to map this current request $hashkey = DiscussHelper::getTable('Hashkeys'); $hashkey->uid = $table->id; $hashkey->type = DISCUSS_REPLY_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_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 && !$question->private) { $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, $excludeEmails, $config->get('notify_admin_onreply'), $config->get('notify_moderator_onreply')); } // @rule: Jomsocial activity integrations if ($table->published == DISCUSS_ID_PUBLISHED && !$question->private) { DiscussHelper::getHelper('jomsocial')->addActivityReply($table); DiscussHelper::getHelper('easysocial')->replyDiscussionStream($table); } $autoSubscribed = false; if ($config->get('main_autopostsubscription') && $config->get('main_postsubscription') && $table->user_type != 'twitter') { //automatically subscribe this user into this post. $subscription_info = array(); $subscription_info['type'] = 'post'; $subscription_info['userid'] = !empty($table->user_id) ? $table->user_id : '0'; $subscription_info['email'] = !empty($table->user_id) ? $my->email : $table->poster_email; $subscription_info['cid'] = $parent->id; $subscription_info['member'] = !empty($table->user_id) ? '1' : '0'; $subscription_info['name'] = !empty($table->user_id) ? $my->name : $table->poster_name; $subscription_info['interval'] = 'instant'; $model = $this->getModel('Subscribe'); $sid = ''; if ($subscription_info['userid'] == 0) { $sid = $model->isPostSubscribedEmail($subscription_info); if (empty($sid)) { if ($model->addSubscription($subscription_info)) { $autoSubscribed = true; } } } else { $sid = $model->isPostSubscribedUser($subscription_info); if (empty($sid['id'])) { //add new subscription. if ($model->addSubscription($subscription_info)) { $autoSubscribed = true; } } } } // Append result $output = array(); $output['message'] = $autoSubscribed ? JText::_('COM_EASYDISCUSS_SUCCESS_REPLY_POSTED_AND_SUBSCRIBED') : JText::_('COM_EASYDISCUSS_SUCCESS_REPLY_POSTED'); $output['type'] = 'success'; $output['html'] = $html; // Perhaps the viewer is unable to view the replies. if (!$questionCategory->canViewReplies()) { $output['message'] = JText::_('COM_EASYDISCUSS_REPLY_SUCCESS_BUT_UNABLE_TO_VIEW_REPLIES'); } if ($enableRecaptcha && !empty($publicKey) && $recaptcha) { $output['type'] = 'success.captcha'; } echo $this->_outputJson($output); }
/** * Sends a ping request to pingomatic servers. * * @since 3.0 * @access public * @param null * @return bool True if success, false otherwise. * */ public function ping() { if ($this->published != DISCUSS_ID_PUBLISHED) { return false; } $config = DiscussHelper::getConfig(); if (!$config->get('integration_pingomatic')) { return false; } $pingomatic = DiscussHelper::getHelper('Pingomatic'); return $pingomatic->ping($this->title, DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=post&id=' . $this->id, true, true)); }
public function twitter($tpl = null) { $step = JRequest::getVar('step'); $config = DiscussHelper::getConfig(); $callback = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=autoposting', false, true); $oauth = DiscussHelper::getHelper('OAuth')->getConsumer('twitter', $config->get('main_autopost_twitter_id'), $config->get('main_autopost_twitter_secret'), $callback); $oauth = DiscussHelper::getTable('OAuth'); $oauth->loadByType('twitter'); $associated = (bool) $oauth->id; if ($step == '3') { //this mean we completed the final steps. reset step to empty. $mainframe =& JFactory::getApplication(); $mainframe->redirect('index.php?option=com_easydiscuss&view=autoposting&layout=form&type=twitter'); $mainframe->close(); } $this->assignRef('associated', $associated); $this->assignRef('config', $config); $this->assignRef('step', $step); parent::display($tpl); }