function save() { // Check for request forgeries JRequest::checkToken() or jexit('Invalid Token'); // @task: Check for acl rules. $this->checkAccess('comment'); $mainframe = JFactory::getApplication(); $message = ''; $type = 'message'; if (JRequest::getMethod() == 'POST') { $post = JRequest::get('post'); $user = JFactory::getUser(); $post['created_by'] = $user->id; $commentId = JRequest::getVar('commentid', ''); $comment = EasyBlogHelper::getTable('Comment', 'Table'); if (!empty($commentId)) { $comment->load($commentId); $post['created_by'] = $comment->created_by; } $comment->bind($post); //$comment->comment = EasyBlogStringHelper::url2link( $comment->comment ); if (!$comment->store()) { JError::raiseError(500, $comment->getError()); } else { if ($comment->published && !$comment->sent) { $comment->comment = EasyBlogCommentHelper::parseBBCode($comment->comment); $comment->comment = nl2br($comment->comment); $blog = EasyBlogHelper::getTable('Blog'); $blog->load($comment->post_id); $comment->processEmails(false, $blog); //update the sent flag to sent $comment->updateSent(); } $message = JText::_('COM_EASYBLOG_COMMENTS_SAVED'); } } else { $message = JText::_('Invalid request method. This form needs to be submitted through a "POST" request.'); $type = 'error'; } $mainframe->redirect('index.php?option=com_easyblog&view=comments', $message, $type); }
public static function parseBBCode($text) { //$text = htmlspecialchars($text , ENT_NOQUOTES ); $text = trim($text); //$text = nl2br( $text ); //$text = preg_replace_callback('/\[code\](.*?)\[\/code\]/ms', "escape", $text); $text = preg_replace_callback('/\\[code( type="(.*?)")?\\](.*?)\\[\\/code\\]/ms', 'escape', $text); // BBCode to find... $in = array('/\\[b\\](.*?)\\[\\/b\\]/ms', '/\\[i\\](.*?)\\[\\/i\\]/ms', '/\\[u\\](.*?)\\[\\/u\\]/ms', '/\\[img\\](.*?)\\[\\/img\\]/ms', '/\\[email\\](.*?)\\[\\/email\\]/ms', '/\\[url\\="?(.*?)"?\\](.*?)\\[\\/url\\]/ms', '/\\[size\\="?(.*?)"?\\](.*?)\\[\\/size\\]/ms', '/\\[color\\="?(.*?)"?\\](.*?)\\[\\/color\\]/ms', '/\\[quote](.*?)\\[\\/quote\\]/ms', '/\\[list\\=(.*?)\\](.*?)\\[\\/list\\]/ms', '/\\[list\\](.*?)\\[\\/list\\]/ms', '/\\[\\*\\]\\s?(.*?)\\n/ms'); // And replace them by... $out = array('<strong>\\1</strong>', '<em>\\1</em>', '<u>\\1</u>', '<img src="\\1" alt="\\1" />', '<a href="mailto:\\1">\\1</a>', '<a href="\\1">\\2</a>', '<span style="font-size:\\1%">\\2</span>', '<span style="color:\\1">\\2</span>', '<blockquote>\\1</blockquote>', '<ol start="\\1">\\2</ol>', '<ul>\\1</ul>', '<li>\\1</li>'); $tmp = preg_replace($in, '', $text); $config = EasyBlogHelper::getConfig(); if ($config->get('comment_autohyperlink')) { $text = EasyBlogCommentHelper::replaceURL($tmp, $text); } $text = preg_replace($in, $out, $text); // Smileys to find... $in = array(':D', ':)', ':o', ':p', ':(', ';)'); // And replace them by... $out = array('<img alt=":D" src="' . EBLOG_EMOTICONS_DIR . 'emoticon-happy.png" />', '<img alt=":)" src="' . EBLOG_EMOTICONS_DIR . 'emoticon-smile.png" />', '<img alt=":o" src="' . EBLOG_EMOTICONS_DIR . 'emoticon-surprised.png" />', '<img alt=":p" src="' . EBLOG_EMOTICONS_DIR . 'emoticon-tongue.png" />', '<img alt=":(" src="' . EBLOG_EMOTICONS_DIR . 'emoticon-unhappy.png" />', '<img alt=";)" src="' . EBLOG_EMOTICONS_DIR . 'emoticon-wink.png" />'); $text = str_replace($in, $out, $text); // paragraphs $text = str_replace("\r", "", $text); $text = "<p>" . preg_replace("/(\n){2,}/", "</p><p>", $text) . "</p>"; $text = preg_replace_callback('/<pre>(.*?)<\\/pre>/ms', "removeBr", $text); $text = preg_replace('/<p><pre>(.*?)<\\/pre><\\/p>/ms', "<pre>\\1</pre>", $text); $text = preg_replace_callback('/<ul>(.*?)<\\/ul>/ms', "removeBr", $text); $text = preg_replace('/<p><ul>(.*?)<\\/ul><\\/p>/ms', "<ul>\\1</ul>", $text); return $text; }
public static function formatBlogCommentsLite($comments) { for ($i = 0; $i < count($comments); $i++) { $row =& $comments[$i]; $creator = EasyBlogHelper::getTable('Profile', 'Table'); if ($row->created_by != 0) { $creator->load($row->created_by); $user = JFactory::getUser($row->created_by); $creator->setUser($user); } //get integrated avatar $row->poster = $creator; $row->comment = EasyBlogCommentHelper::parseBBCode($row->comment); } return $comments; }
/** * This method is invoked when a user submits a comment via ajax. * * @access public * @params Array $post An array of posted data. * @return null */ public function commentSave($post) { $ajax = new Ejax(); $app = JFactory::getApplication(); $my = JFactory::getUser(); $config = EasyBlogHelper::getConfig(); $acl = EasyBlogACLHelper::getRuleSet(); if (empty($acl->rules->allow_comment) && (empty($my->id) && !$config->get('main_allowguestcomment'))) { $ajax->script('eblog.spinner.hide()'); $ajax->script("eblog.loader.doneLoading();"); $ajax->script('eblog.comment.displayInlineMsg( "error" , "' . JText::_('COM_EASYBLOG_NO_PERMISSION_TO_POST_COMMENT') . '");'); $ajax->send(); } $isModerated = false; $parentId = $post['parent_id']; $commentDepth = $post['comment_depth']; $blogId = $post['id']; $subscribeBlog = isset($post['subscribe-to-blog']) ? true : false; // @task: Cleanup posted values. array_walk($post, array($this, '_trim')); array_walk($post, array($this, '_revertValue')); if (!$config->get('comment_require_email') && !isset($post['esemail'])) { $post['esemail'] = ''; } // @task: Run some validation tests on the posted values. if (!$this->_validateFields($post)) { // @task: Reload captcha if necessary EasyBlogHelper::getHelper('Captcha')->reload($ajax, $post); $ajax->script("eblog.loader.doneLoading();"); $ajax->script('eblog.spinner.hide()'); $ajax->script('$("#' . $this->err[1] . '").addClass("input-error");'); $ajax->script("eblog.element.focus('" . $this->err[1] . "');"); $ajax->script('eblog.comment.displayInlineMsg(\'error\', \'' . $this->err[0] . '\');'); $ajax->send(); return; } // @task: Akismet detection service. if ($config->get('comment_akismet')) { $data = array('author' => $post['esname'], 'email' => $post['esname'], 'website' => JURI::root(), 'body' => $post['comment'], 'permalink' => EasyBlogRouter::_('index.php?option=com_easyblog&view=entry&id=' . $post['id'])); if (EasyBlogHelper::getHelper('Akismet')->isSpam($data)) { $ajax->script('eblog.comment.displayInlineMsg(\'error\', \'' . JText::_('COM_EASYBLOG_SPAM_DETECTED_IN_COMMENT') . '\');'); $ajax->script("eblog.loader.doneLoading();"); $ajax->script('eblog.spinner.hide();'); $ajax->send(); return false; } } // @task: Retrieve the comments model $model = $this->getModel('Comment'); // @task: Retrieve the comment's table $comment = EasyBlogHelper::getTable('Comment'); // We need to rename the esname and esemail back to name and email. $post['name'] = $post['esname']; $post['email'] = $post['esemail']; unset($post['esname']); unset($post['esemail']); // @task: Bind posted values into the table. $comment->bindPost($post); if (!EasyBlogHelper::getHelper('Captcha')->verify($post)) { return EasyBlogHelper::getHelper('Captcha')->getError($ajax, $post); } // @task: Process registrations $registerUser = isset($post['esregister']) ? true : false; $fullname = isset($post['name']) ? $post['name'] : ''; $username = isset($post['esusername']) ? $post['esusername'] : ''; $email = $post['email']; $message = ''; $newUserId = 0; // @task: Process registrations if necessary if ($registerUser && $my->id <= 0) { $state = $this->processRegistrations($post, $username, $email, $ajax); if (!is_numeric($state)) { $ajax->script("eblog.loader.doneLoading();"); $ajax->script('eblog.comment.displayInlineMsg( "error" , "' . $state . '");'); EasyBlogHelper::getHelper('Captcha')->reload($ajax, $post); return $ajax->send(); } $newUserId = $state; } $totalComments = empty($post['totalComment']) ? 1 : $post['totalComment']; $date = EasyBlogHelper::getDate(); $comment->set('created', $date->toMySQL()); $comment->set('modified', $date->toMySQL()); $comment->set('published', 1); $comment->set('parent_id', $parentId); $comment->set('sent', 0); $comment->set('created_by', $my->id); // @rule: Update the user's id if they have just registered earlier. if ($newUserId != 0) { $comment->set('created_by', $newUserId); } // @rule: Update publish status if the comment requires moderation if ($config->get('comment_moderatecomment') == 1 || $my->id == 0 && $config->get('comment_moderateguestcomment') == 1) { $comment->set('published', EBLOG_COMMENT_STATUS_MODERATED); $isModerated = true; } $blog = EasyBlogHelper::getTable('Blog'); $blog->load($blogId); // If moderation for author is disabled, ensure that the comment is published. // If the author is the owner of the blog, it should never be moderated. if (!$config->get('comment_moderateauthorcomment') && $blog->created_by == $my->id) { $comment->set('published', 1); $isModerated = false; } if (!$comment->store()) { //$ejax->alert( JText::_('COM_EASYBLOG_COMMENT_FAILED_TO_SAVE'), JText::_('COM_EASYBLOG_ERROR') , '450', 'auto'); $ajax->script('eblog.comment.displayInlineMsg(\'error\', \'' . JText::_('COM_EASYBLOG_COMMENT_FAILED_TO_SAVE') . '\');'); return $ajax->send(); } // @task: Clean up the comment form $ajax->script('$(\'#title\').val(\'\');'); $ajax->script('$(\'#url\').val(\'\');'); $ajax->script('$(\'#comment\').val(\'\');'); $ajax->script('$(\'#esusername\').val(\'\');'); $ajax->script('$(\'#esregister\').attr(\'checked\',false);'); $message = JText::_('COM_EASYBLOG_COMMENTS_SUCCESS'); if ($newUserId != 0 && $registerUser) { $message = JText::_('COM_EASYBLOG_COMMENTS_SUCCESS_AND_REGISTERED'); } // @rule: Process subscription for blog automatically when the user submits a new comment and wants to subscribe to the blog. if ($subscribeBlog && $config->get('main_subscription') && $blog->subscription) { $isSubscribed = false; $userId = $my->id; $blogModel = EasyblogHelper::getModel('Blog'); if ($userId == 0) { $sid = $blogModel->isBlogSubscribedEmail($blog->id, $email); if (empty($sid)) { $isSubscribed = $blogModel->addBlogSubscription($blog->id, $email, '', $fullname); } } else { $sid = $blogModel->isBlogSubscribedUser($blog->id, $userId, $email); if (!empty($sid)) { // @task: User found, update the email address $blogModel->updateBlogSubscriptionEmail($sid, $userId, $email); } else { $isSubscribed = $blogModel->addBlogSubscription($blog->id, $email, $userId, $fullname); } } if ($isSubscribed) { $message .= ' ' . JText::_('COM_EASYBLOG_ENTRY_AUTO_SUBSCRIBED_SUCCESS'); $sid = $blogModel->isBlogSubscribedUser($blog->id, $userId, $email); $html = ''; $html .= '<div id="unsubscription-box" class="unsubscription-box">'; $html .= ' ' . JText::_('COM_EASYBLOG_ENTRY_AUTO_SUBSCRIBE_SUBSCRIBED_NOTE'); $html .= ' <a href="javascript:void(0);" title="" onclick="eblog.blog.unsubscribe( \'' . $sid . '\', \'' . $blog->id . '\' );">'; $html .= ' ' . JText::_('COM_EASYBLOG_UNSUBSCRIBE_BLOG'); $html .= ' </a>'; $html .= '</div>'; $ajax->append('subscription-box', $html); $ajax->script('$(\'#subscription-message\').remove();'); } } $row = $comment; $creator = EasyBlogHelper::getTable('Profile'); $creator->load($my->id); $row->poster = $creator; $row->comment = nl2br($row->comment); $row->comment = EasyBlogCommentHelper::parseBBCode($row->comment); $row->depth = is_null($commentDepth) ? '0' : $commentDepth; $row->likesAuthor = ''; // @rule: Process notifications $comment->processEmails($isModerated, $blog); if ($isModerated) { $tpl = new CodeThemes(); $tpl->set('comment', $row); $tpl->set('totalComment', $totalComments); $tpl->set('config', $config); $tpl->set('my', $my); $commentHtml = $tpl->fetch('blog.comment.moderate.php'); if ($parentId != 0) { $ajax->after('comment-' . $parentId, $commentHtml); $ajax->script('eblog.comment.cancel(\'' . $parentId . '\')'); } else { $ajax->append('blog-comment', $commentHtml); } // Reload recaptcha image once the comment is saved. EasyBlogHelper::getHelper('Captcha')->reload($ajax, $post); $ajax->script("eblog.loader.doneLoading();"); $ajax->script('eblog.comment.displayInlineMsg(\'info\', \'' . $message . '\');'); $ajax->send(); return; } $tpl = new CodeThemes(); $tpl->set('comment', $row); $tpl->set('totalComment', $totalComments); $tpl->set('config', $config); $tpl->set('my', $my); $tpl->set('acl', $acl); $commentHtml = $tpl->fetch('blog.comment.ejax.php'); if ($parentId != 0) { $ajax->after('comment-' . $parentId, $commentHtml); $ajax->script('eblog.comment.cancel(\'' . $parentId . '\')'); } else { $ajax->append('blog-comment', $commentHtml); } //update the sent flag to sent $comment->updateSent(); // Reload whichever captcha necessary for the next run EasyBlogHelper::getHelper('Captcha')->reload($ajax, $post); $ajax->script("eblog.loader.doneLoading();"); // update comment total count text on blog post if ($comment->published == 1) { $commentText = $tpl->getNouns('COM_EASYBLOG_COMMENT_COUNT', $totalComments, true); $ajax->script('$(\'.blog-comments a\').text(\'' . $commentText . '\');'); } //update the comment total count $ajax->script('$(\'#comment-total-count\').text(\'' . $totalComments . '\');'); //the next count. $ajax->script('$(\'#totalComment\').val(\'' . ($totalComments + 1) . '\');'); //$ejax->alert( $message, JText::_('COM_EASYBLOG_INFO') , '450', 'auto'); $ajax->script('eblog.comment.displayInlineMsg(\'info\', \'' . $message . '\');'); $ajax->send(); }
private function _htmlContent($userId, $contextString, $itemCount, $itemObj) { $db = EasyBlogHelper::db(); $verb = $itemObj->verb; $streamHTML = 'Failed retrieve content.'; $contextArr = explode('-', $contextString); $context = $contextArr[0]; switch ($context) { case 'comment': $item = $itemObj->target[0][1]; $actor = $itemObj->actor; $extra = ''; $obj = unserialize($item->uuid); if ($item->target_id == $userId) { $actor = $obj->commentauthor; $extra = '_TARGET'; } else { $actor = JText::_('COM_EASYBLOG_STREAM_YOU_AS_ACTOR'); } $commentId = $item->context_id; $blogId = $item->source_id; $comment = EasyBlogCommentHelper::parseBBCode($obj->comment); $blogLink = EasyBlogRouter::_('index.php?option=com_easyblog&view=entry&id=' . $blogId) . '#comment-' . $commentId; $title = JText::sprintf('COM_EASYBLOG_STREAM_COMMENT_ADD' . $extra, $actor, $blogLink, $obj->blogtitle, $obj->blogtitle); $commentDate = EasyBlogDateHelper::getDate($item->created); $filename = 'stream.comment.' . $verb . '.php'; $streamTheme = new CodeThemes(); $streamTheme->set('title', $title); $streamTheme->set('time', $itemObj->friendlyTS); $streamTheme->set('commentDate', $commentDate->toFormat()); $streamTheme->set('comment', $comment); $streamHTML = $streamTheme->fetch($filename); break; case 'profile': $filename = 'stream.profile.' . $verb . '.php'; $streamTheme = new CodeThemes(); // $actor = $itemObj->actor; $actor = JText::_('COM_EASYBLOG_STREAM_YOU_AS_ACTOR'); $streamTheme->set('actor', $actor); $streamTheme->set('time', $itemObj->friendlyTS); $streamHTML = $streamTheme->fetch($filename); break; case 'blogger': $streamTheme = new CodeThemes(); $extra = ''; $actor = $itemObj->actor; $targets = $itemObj->target; $actorArr = array(); $targetArr = array(); if (count($targets) > 1) { $stringTitle = array(); $cnt = 0; $swap = false; foreach ($targets as $target) { $item = $target[1]; $obj = unserialize($item->uuid); if ($item->target_id == $userId) { $actorArr[] = $obj->subscribername . '(' . $obj->subscriberemail . ')'; $targetArr[] = $obj->bloggername; // we knwo this userId is now target. Get the correct theme file. $extra = '.target'; } else { $bloggerLink = EasyBlogRouter::_('index.php?option=com_easyblog&view=blogger&layout=listings&id=' . $item->context_id); $tmpString = '<a href="' . $bloggerLink . '">' . $obj->bloggername . '</a>'; //$actorArr[] = $obj->subscribername; $actorArr[] = JText::_('COM_EASYBLOG_STREAM_YOU_AS_ACTOR'); $targetArr[] = $tmpString; } } } else { $item = $targets[0][1]; $obj = unserialize($item->uuid); if ($item->target_id == $userId) { $actorArr[] = $obj->subscribername . '(' . $obj->subscriberemail . ')'; $targetArr[] = $obj->bloggername; // we knwo this userId is now target. Get the correct theme file. $extra = '.target'; } else { $bloggerLink = EasyBlogRouter::_('index.php?option=com_easyblog&view=blogger&layout=listings&id=' . $item->context_id); $title = '<a href="' . $bloggerLink . '">' . $obj->bloggername . '</a>'; // $actorArr[] = $obj->subscribername; $actorArr[] = JText::_('COM_EASYBLOG_STREAM_YOU_AS_ACTOR'); $targetArr[] = $title; } } $targetArr = array_unique($targetArr); $actorArr = array_unique($actorArr); $stringActor = ''; $stringTarget = ''; // actors $cnt = 0; foreach ($actorArr as $item) { if (empty($stringActor)) { $stringActor = $item; } else { $stringActor .= $cnt + 1 == count($actorArr) ? ' and ' . $item : ', ' . $item; } $cnt++; } //targets $cnt = 0; foreach ($targetArr as $item) { if (empty($stringTarget)) { $stringTarget = $item; } else { $stringTarget .= $cnt + 1 == count($targetArr) ? ' and ' . $item : ', ' . $item; } $cnt++; } $streamTheme->set('actor', $stringActor); $streamTheme->set('target', $stringTarget); $streamTheme->set('actorCnt', count($actorArr)); $streamTheme->set('time', $itemObj->friendlyTS); $filename = 'stream.blogger.' . $verb . $extra . '.php'; $streamHTML = $streamTheme->fetch($filename); break; case 'post': $streamTheme = new CodeThemes(); $extra = ''; $actor = $itemObj->actor; $targets = $itemObj->target; /* old codes */ // if( count( $targets ) > 1 ) // { // $stringTitle = ''; // $cnt = 0; // foreach( $targets as $target ) // { // $item = $target[1]; // $blogLink = EasyBlogRouter::_( 'index.php?option=com_easyblog&view=entry&id=' . $item->context_id ); // $tmpString = '<a href="' . $blogLink. '">' . $item->uuid . '</a>'; // // if( empty( $stringTitle ) ) // { // $stringTitle = $tmpString; // } // else // { // $stringTitle .= ( ($cnt + 1) == count($targets) ) ? ' and ' . $tmpString : ', ' . $tmpString; // } // // $cnt++; // } // // $title = $stringTitle; // // } // else // { // $item = $targets[0][1]; // $blogLink = EasyBlogRouter::_( 'index.php?option=com_easyblog&view=entry&id=' . $item->context_id ); // $title = '<a href="' . $blogLink. '">' . $item->uuid . '</a>'; // } /* old codes ended */ $actorArr = array(); $targetArr = array(); if (count($targets) > 1) { $stringTitle = array(); $cnt = 0; $swap = false; foreach ($targets as $target) { $item = $target[1]; $obj = @unserialize($item->uuid); if ($obj === false) { $obj = new stdClass(); $obj->blogtitle = $item->uuid; } if ($item->target_id == $userId) { $actorArr[] = $obj->subscribername; // we knwo this userId is now target. Get the correct theme file. $extra = '.target'; } else { // $actorArr[] = $itemObj->actor; $actorArr[] = JText::_('COM_EASYBLOG_STREAM_YOU_AS_ACTOR'); } $blogLink = EasyBlogRouter::_('index.php?option=com_easyblog&view=entry&id=' . $item->context_id); $title = '<a href="' . $blogLink . '">' . $obj->blogtitle . '</a>'; $targetArr[] = $title; } } else { $item = $targets[0][1]; $obj = @unserialize($item->uuid); if ($obj === false) { $obj = new stdClass(); $obj->blogtitle = $item->uuid; } if ($item->target_id == $userId) { $actorArr[] = $obj->subscribername; // we knwo this userId is now target. Get the correct theme file. $extra = '.target'; } else { //$actorArr[] = $itemObj->actor; $actorArr[] = JText::_('COM_EASYBLOG_STREAM_YOU_AS_ACTOR'); } $blogLink = EasyBlogRouter::_('index.php?option=com_easyblog&view=entry&id=' . $item->context_id); $title = '<a href="' . $blogLink . '">' . $obj->blogtitle . '</a>'; $targetArr[] = $title; } $targetArr = array_unique($targetArr); $actorArr = array_unique($actorArr); $stringActor = ''; $stringTarget = ''; // actors $cnt = 0; foreach ($actorArr as $item) { if (empty($stringActor)) { $stringActor = $item; } else { $stringActor .= $cnt + 1 == count($actorArr) ? JText::_('COM_EASYBLOG_STREAM_AND') . $item : ', ' . $item; } $cnt++; } //targets $cnt = 0; foreach ($targetArr as $item) { if (empty($stringTarget)) { $stringTarget = $item; } else { $stringTarget .= $cnt + 1 == count($targetArr) ? JText::_('COM_EASYBLOG_STREAM_AND') . $item : ', ' . $item; } $cnt++; } $filename = 'stream.post.' . $verb . $extra . '.php'; $streamTheme->set('actor', $stringActor); $streamTheme->set('target', $stringTarget); $streamTheme->set('actorCnt', count($actorArr)); $streamTheme->set('time', $itemObj->friendlyTS); $streamHTML = $streamTheme->fetch($filename); break; case 'tag': case 'category': $jtext = $context == 'category' ? 'CATEGORY' : 'TAG'; $view = $context == 'category' ? 'categories' : 'tags'; $layout = $context == 'category' ? 'listings' : 'tag'; //$actor = $itemObj->actor; $actor = JText::_('COM_EASYBLOG_STREAM_YOU_AS_ACTOR'); $items = $itemObj->target; $categories = ''; if ($verb == 'delete') { $total = count($items); $i = 0; foreach ($items as $itemArr) { $item = $itemArr[1]; if (empty($categories)) { $categories = $item->uuid; } else { if ($i + 1 == $total) { $categories .= JText::_('COM_EASYBLOG_STREAM_AND') . $item->uuid; } else { $categories .= ', ' . $item->uuid; } } } } else { $total = count($items); $i = 0; foreach ($items as $itemArr) { $item = $itemArr[1]; $catLink = EasyBlogRouter::_('index.php?option=com_easyblog&view=' . $view . '&layout=' . $layout . '&id=' . $item->context_id); if (empty($categories)) { $categories = '<a href="' . $catLink . ' " title="' . EasyBlogHelper::getHelper('String')->escape($item->uuid) . '">' . $item->uuid . '</a>'; } else { if ($i + 1 == $total) { $categories .= JText::_('COM_EASYBLOG_STREAM_AND') . '<a href="' . $catLink . ' " title="' . EasyBlogHelper::getHelper('String')->escape($item->uuid) . '">' . $item->uuid . '</a>'; } else { $categories .= ', <a href="' . $catLink . ' " title="' . EasyBlogHelper::getHelper('String')->escape($item->uuid) . '">' . $item->uuid . '</a>'; } } $i++; } //end foreach } $title = JText::sprintf('COM_EASYBLOG_STREAM_' . $jtext . '_' . strtoupper($verb), $actor, $categories); $filename = 'stream.' . strtolower($jtext) . '.' . $verb . '.php'; $streamTheme = new CodeThemes(); $streamTheme->set('title', $title); $streamTheme->set('time', $itemObj->friendlyTS); $streamHTML = $streamTheme->fetch($filename); break; default: $streamHTML = $itemObj->story; break; } return $streamHTML; }
function display($tmpl = null) { JPluginHelper::importPlugin('easyblog'); $dispatcher = JDispatcher::getInstance(); $mainframe = JFactory::getApplication(); $document = JFactory::getDocument(); $config = EasyBlogHelper::getConfig(); $my = JFactory::getUser(); $notice = ''; //for trigger $params = $mainframe->getParams('com_easyblog'); $limitstart = JRequest::getInt('limitstart', 0, ''); $blogId = JRequest::getVar('id'); if (JRequest::getInt('print') == 1) { // Add noindex for print view by default. $document->setMetadata('robots', 'noindex,follow'); } if (empty($blogId)) { $mainframe->redirect(EasyBlogRouter::_('index.php?option=com_easyblog&view=latest', false), JText::_('COM_EASYBLOG_ENTRY_BLOG_NOT_FOUND')); $mainframe->close(); } if ($my->id <= 0 && $config->get('main_login_read')) { $mainframe->redirect(EasyBlogRouter::_('index.php?option=com_easyblog&view=entry&id=' . $blogId . '&layout=login', false)); $mainframe->close(); } $team = JRequest::getVar('team', ''); if (empty($team)) { //try get from session. $team = EasyBlogHelper::getSession('EASYBLOG_TEAMBLOG_ID'); } // set meta tags for post EasyBlogHelper::setMeta($blogId, META_TYPE_POST); $print = JRequest::getBool('print'); if ($print) { $document->setMetaData('robots', 'noindex, nofollow'); } $my = JFactory::getUser(); $blog = EasyBlogHelper::getTable('Blog', 'Table'); if (!$blog->load($blogId)) { $mainframe->redirect(EasyBlogRouter::_('index.php?option=com_easyblog&view=latest', false), JText::_('COM_EASYBLOG_ENTRY_BLOG_NOT_FOUND')); $mainframe->close(); } if (!empty($blog->robots)) { $document->setMetaData('robots', $blog->robots); } if (!empty($blog->copyrights)) { $document->setMetaData('rights', $blog->copyrights); } //assign the teamid here. $checkIsPrivate = false; //check if blog is password protected. if ($config->get('main_password_protect', true) && !empty($blog->blogpassword)) { if (!EasyBlogHelper::verifyBlogPassword($blog->blogpassword, $blog->id)) { $errmsg = ''; $jSession = JFactory::getSession(); if ($jSession->has('PROTECTEDBLOG_' . $blog->id, 'EASYBLOG')) { $errmsg = JText::_('COM_EASYBLOG_PASSWORD_PROTECTED_BLOG_INVALID_PASSWORD'); } $theme = new CodeThemes(); $theme->set('id', $blog->id); $theme->set('return', base64_encode(JURI::getInstance()->toString())); $theme->set('errmsg', $errmsg); echo $theme->fetch('blog.protected.php'); return false; } } //if team id provided, then we need to check if the user belong to the team or not. if ($blog->issitewide) { $checkIsPrivate = true; } else { if (empty($team)) { // blog post is not sitewide and teamid is empty? this is not so right. need to check this post contributed to which team one more time. $team = $blog->getTeamContributed(); } /* * if teamblog access set to 'member only' | 'registered user', team blog will supersede blog permision * if teamblog access set to 'everyone' then blog's permission will supersede teamblog access (logged user vs guest) */ if (!empty($team)) { $teamblog = EasyBlogHelper::getTable('TeamBlog', 'Table'); $teamblog->load($team); if ($teamblog->access == '1') { if (!EasyBlogHelper::isTeamBlogJoined($my->id, $team)) { //show error. EasyBlogHelper::showAccessDenied('teamblog', $teamblog->access); return; } } else { if ($teamblog->access == '2') { if (!EasyBlogHelper::isLoggedIn()) { EasyBlogHelper::showLogin(); return; } } else { // if teamblog the access set to 'everyone' then blog permission will supersede teamblog access $checkIsPrivate = true; } } } else { $checkIsPrivate = true; } } $blog->team_id = $team; //check if the blog permission set to private or public. if private, we //need to check if the user has login or not. if ($checkIsPrivate) { $privacy = $blog->isAccessible(); if (!$privacy->allowed) { echo $privacy->error; return; } } // added checking for other statuses switch ($blog->published) { case 0: case 2: case 3: // Unpublished post // Only Admin and blog owner can view this post if ($my->id == $blog->created_by) { $notice = JText::_('COM_EASYBLOG_ENTRY_BLOG_UNPUBLISHED_VISIBLE_TO_OWNER'); } elseif (EasyBlogHelper::isSiteAdmin()) { $notice = JText::_('COM_EASYBLOG_ENTRY_BLOG_UNPUBLISHED_VISIBLE_TO_ADMIN'); } else { EasyBlogHelper::setMessageQueue(JText::_('COM_EASYBLOG_ENTRY_BLOG_NOT_FOUND')); $mainframe->redirect(EasyBlogRouter::_('index.php?option=com_easyblog&view=latest', false)); } break; case 5: // Trashed posts. EasyBlogHelper::setMessageQueue(JText::_('COM_EASYBLOG_ENTRY_BLOG_NOT_FOUND')); $mainframe->redirect(EasyBlogRouter::_('index.php?option=com_easyblog&view=latest', false)); break; case 1: default: break; } //update the hits $blog->hit(); $acl = EasyBlogACLHelper::getRuleSet(); $pageTitle = EasyBlogHelper::getPageTitle($config->get('main_title')); if (empty($pageTitle)) { $document->setTitle($blog->title); } else { $document->setTitle($blog->title . ' - ' . $pageTitle); } // There is a possibility that the intro is hidden in the entry view, so we need to get this data. $rawIntroText = $blog->intro; // @rule: Process microblog post if ($blog->source) { EasyBlogHelper::formatMicroBlog($blog); } // process the video here if nessary $blog->intro = EasyBlogHelper::getHelper('Videos')->processVideos($blog->intro); $blog->content = EasyBlogHelper::getHelper('Videos')->processVideos($blog->content); // @rule: Process audio files. $blog->intro = EasyBlogHelper::getHelper('Audio')->process($blog->intro); $blog->content = EasyBlogHelper::getHelper('Audio')->process($blog->content); // @rule: Process adsense codes. $blog->intro = EasyBlogGoogleAdsense::processsAdsenseCode($blog->intro, $blog->created_by); $blog->content = EasyBlogGoogleAdsense::processsAdsenseCode($blog->content, $blog->created_by); // @trigger: onEasyBlogPrepareContent EasyBlogHelper::triggerEvent('easyblog.prepareContent', $blog, $params, $limitstart); // @rule: Hide introtext if necessary if ($config->get('main_hideintro_entryview') && !empty($blog->content)) { $blog->intro = ''; } //onPrepareContent trigger start $blog->introtext = $blog->intro; $blog->text = $blog->intro . $blog->content; // @trigger: onEasyBlogPrepareContent EasyBlogHelper::triggerEvent('prepareContent', $blog, $params, $limitstart); $blog->intro = $blog->introtext; $blog->content = $blog->text; // @legacy: since 3.5 has blog images, we can remove this in the future. // Remove first image for featured blogs if ($blog->isFeatured()) { $blog->content = EasyBlogHelper::removeFeaturedImage($blog->content); } $isFeatured = EasyBlogHelper::isFeatured('post', $blog->id); /* Post Tags */ $modelPT = $this->getModel('PostTag'); $tags = $modelPT->getBlogTags($blog->id); //page setup $blogHtml = ''; $commentHtml = ''; $blogHeader = ''; $blogFooter = ''; $adsenseHtml = ''; $trackbackHtml = ''; $blogger = null; if ($blog->created_by != 0) { $blogger = EasyBlogHelper::getTable('Profile', 'Table'); $blogger->load($blog->created_by); } // @rule: Set the author object into the table. $blog->author = $blogger; $blog->blogger = $blogger; // @rule: Before any trigger happens, try to replace the gallery first and append it at the bottom. $blog->intro = EasyBlogHelper::getHelper('Gallery')->process($blog->intro, $blog->created_by); $blog->content = EasyBlogHelper::getHelper('Gallery')->process($blog->content, $blog->created_by); $blog->intro = EasyBlogHelper::getHelper('Album')->process($blog->intro, $blog->created_by); $blog->content = EasyBlogHelper::getHelper('Album')->process($blog->content, $blog->created_by); //onAfterDisplayTitle, onBeforeDisplayContent, onAfterDisplayContent trigger start $blog->event = new stdClass(); $blog->introtext = $blog->intro; $blog->text = $blog->content; // @trigger: onAfterDisplayTitle / onContentAfterTitle $results = EasyBlogHelper::triggerEvent('afterDisplayTitle', $blog, $params, $limitstart); $blog->event->afterDisplayTitle = JString::trim(implode("\n", $results)); // @trigger: onBeforeDisplayContent / onContentBeforeDisplay $results = EasyBlogHelper::triggerEvent('beforeDisplayContent', $blog, $params, $limitstart); $blog->event->beforeDisplayContent = JString::trim(implode("\n", $results)); // @trigger: onAfterDisplayContent / onContentAfterDisplay $results = EasyBlogHelper::triggerEvent('afterDisplayContent', $blog, $params, $limitstart); $blog->event->afterDisplayContent = JString::trim(implode("\n", $results)); $blog->intro = $blog->introtext; $blog->content = $blog->text; unset($blog->introtext); unset($blog->text); if ($print) { $theme = new CodeThemes(); $theme->set('blog', $blog); $theme->set('tags', $tags); $theme->set('config', $config); $theme->set('blogger', $blogger); echo $theme->fetch('blog.read.print.php'); return; } if (!EasyBlogRouter::isCurrentActiveMenu('blogger', $blogger->id) && $config->get('layout_blogger_breadcrumb')) { $this->setPathway($blogger->getName(), $blogger->getLink()); } if (!EasyBlogRouter::isCurrentActiveMenu('entry', $blog->id)) { $this->setPathway($blog->title, ''); } $blogModel = $this->getModel('Blog'); $theme = new CodeThemes(); // add checking if comment system disabled by site owner if ($config->get('main_comment') && $blog->allowcomment) { // getting blog comments $commentModel = $this->getModel('Comment'); $blogComments = EasyBlogHelper::getHelper('Comment')->getBlogComment($blogId); $commtPagination = EasyBlogHelper::getHelper('Comment')->pagination; $comments = array(); if (!empty($blogComments)) { foreach ($blogComments as $comment) { $row = $comment; $row->comment = EasyBlogCommentHelper::parseBBCode($row->comment); if ($config->get('comment_likes')) { $row->likesAuthor = EasyBlogHelper::getLikesAuthors($row->id, 'comment', $my->id); $row->isLike = $commentModel->isLikeComment($row->id, $my->id); } else { $row->likesAuthor = ''; $row->isLike = 0; } $comments[] = $row; } } // compliant with the #comments at blog.item.comment.php $commentHtml = $config->get('comment_jcomments') ? '' : '<a id="comments"></a>'; $commentHtml .= EasyBlogCommentHelper::getCommentHTML($blog, $comments, $commtPagination); } $blog->totalComments = EasyBlogHelper::getHelper('Comment')->getCommentCount($blog); //get related blog post $blogRelatedPost = ''; if ($config->get('main_relatedpost', true)) { $blogRelatedPost = $blogModel->getRelatedBlog($blogId); } //get author's recent posts. $authorRecentPosts = ''; if ($config->get('main_showauthorinfo') && $config->get('main_showauthorposts')) { $authorPostLimit = $config->get('main_showauthorpostscount'); $authorRecentPosts = $blogModel->getBlogsBy('blogger', $blog->created_by, 'latest', $authorPostLimit); } // Facebook Like integrations require_once EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'facebook.php'; $facebookLike = EasyBlogFacebookLikes::getLikeHTML($blog, $rawIntroText); $url = EasyBlogRouter::getRoutedURL('index.php?option=com_easyblog&view=entry&id=' . $blog->id, false, true); // @rule: Add opengraph tags if required. if ($config->get('main_facebook_opengraph')) { EasyBlogFacebookLikes::addOpenGraphTags($blog, $rawIntroText); } // Add Twitter card details on page. EasyBlogHelper::getHelper('Twitter')->addCard($blog, $rawIntroText); // @task: Add canonical URLs. if ($config->get('main_canonical_entry')) { $canonicalUrl = EasyBlogRouter::getRoutedURL('index.php?option=com_easyblog&view=entry&id=' . $blog->id, false, true, true); $document->addCustomTag('<link rel="canonical" href="' . $canonicalUrl . '"/>'); } // @task: Add rel="nofollow" if necessary. if ($config->get('main_anchor_nofollow')) { $blog->content = EasyBlogHelper::addNoFollow($blog->content); } $prevLink = array(); $nextLink = array(); // construct prev & next link //get blog navigation object if ($config->get('layout_navigation')) { $blogNav = EasyBlogHelper::getBlogNavigation($blogId, $blog->created, $team, 'team'); //$team $prevLink = array(); if (!empty($blogNav['prev'])) { $prevLink['id'] = $blogNav['prev'][0]->id; $prevLink['title'] = JString::strlen($blogNav['prev'][0]->title) > 50 ? JString::substr($blogNav['prev'][0]->title, 0, 50) . '...' : $blogNav['prev'][0]->title; } $nextLink = array(); if (!empty($blogNav['next'])) { $nextLink['id'] = $blogNav['next'][0]->id; $nextLink['title'] = JString::strlen($blogNav['next'][0]->title) > 50 ? JString::substr($blogNav['next'][0]->title, 0, 50) . '...' : $blogNav['next'][0]->title; } } // @rule: Mark notifications item in EasyDiscuss when the blog entry is viewed if ($config->get('integrations_easydiscuss_notification_blog')) { EasyBlogHelper::getHelper('EasyDiscuss')->readNotification($blog->id, EBLOG_NOTIFICATIONS_TYPE_BLOG); } if ($config->get('integrations_easydiscuss_notification_comment')) { EasyBlogHelper::getHelper('EasyDiscuss')->readNotification($blog->id, EBLOG_NOTIFICATIONS_TYPE_COMMENT); } if ($config->get('integrations_easydiscuss_notification_rating')) { EasyBlogHelper::getHelper('EasyDiscuss')->readNotification($blog->id, EBLOG_NOTIFICATIONS_TYPE_RATING); } //get social bookmark provider. require_once EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'bookmark.php'; $bookmark = EasyBlogBookmark::getHTML(); // @task: As we are standardizing the admin tools, we fix the necessary properties here. $blog->isFeatured = $isFeatured; $theme->set('currentURL', EasyBlogRouter::_('index.php?option=com_easyblog&view=latest')); $theme->set('facebookLike', $facebookLike); $theme->set('notice', $notice); $theme->set('team', $team); $theme->set('blog', $blog); $theme->set('tags', $tags); $theme->set('blogger', $blogger); $theme->set('prevLink', $prevLink); $theme->set('nextLink', $nextLink); $theme->set('blogRelatedPost', $blogRelatedPost); $theme->set('authorRecentPosts', $authorRecentPosts); $theme->set('isFeatured', $isFeatured); $theme->set('isMineBlog', EasyBlogHelper::isMineBlog($blog->created_by, $my->id)); $theme->set('acl', $acl); $theme->set('url', $url); $theme->set('commentHTML', $commentHtml); $theme->set('bookmark', $bookmark); $theme->set('pdfLinkProperties', EasyBlogHelper::getPDFlinkProperties()); $theme->set('ispreview', false); // @task: trackbacks $trackbacks = $blogModel->getTrackback($blogId); $theme->set('trackbackURL', EasyBlogRouter::getRoutedURL('index.php?option=com_easyblog&view=trackback&post_id=' . $blog->id, true, true)); $theme->set('trackbacks', $trackbacks); //google adsense $adsense = EasyBlogGoogleAdsense::getHTML($blogger->id); $blogHeader = $adsense->header; $blogFooter = $adsense->footer; $theme->set('adsenseHTML', $adsense->beforecomments); $blogHtml = $theme->fetch('blog.read' . EasyBlogHelper::getHelper('Sources')->getTemplateFile($blog->source) . '.php'); echo $blogHeader; echo $blogHtml; echo $blogFooter; }
function comments() { $mainframe = JFactory::getApplication(); if (!EasyBlogHelper::isLoggedIn()) { EasyBlogHelper::showLogin(); return; } $config = EasyBlogHelper::getConfig(); $document = JFactory::getDocument(); $title = EasyBlogHelper::getPageTitle(JText::_('COM_EASYBLOG_DASHBOARD_COMMENTS_PAGE_TITLE')); // @task: Set the page title parent::setPageTitle($title, false, $config->get('main_pagetitle_autoappend')); $pathway = $mainframe->getPathway(); if (!EasyBlogRouter::isCurrentActiveMenu('dashboard')) { $pathway->addItem(JText::_('COM_EASYBLOG_DASHBOARD_BREADCRUMB'), EasyBlogRouter::_('index.php?option=com_easyblog&view=dashboard')); } $pathway->addItem(JText::_('COM_EASYBLOG_DASHBOARD_COMMENTS_BREADCRUMB'), ''); $my = JFactory::getUser(); $acl = EasyBlogACLHelper::getRuleSet(); $model = $this->getModel('Comment'); $user = EasyBlogHelper::getTable('Profile', 'Table'); $user->load($my->id); $search = JRequest::getVar('post-search', ''); $filter = JRequest::getWord('filter', 'all', 'REQUEST'); $sort = 'latest'; if ($acl->rules->manage_comment) { $comments = $model->getComments(0, '', $sort, '', $search, $filter); } else { $comments = $model->getComments(0, $my->id, $sort, '', $search, $filter); } $pagination = $model->getPagination(); JTable::addIncludePath(EBLOG_TABLES); for ($i = 0; $i < count($comments); $i++) { $row =& $comments[$i]; $row->comment = JString::strlen($row->comment) > 150 ? JString::substr($row->comment, 0, 150) . '...' : $row->comment; $row->comment = EasyBlogCommentHelper::parseBBCode($row->comment); $row->comment = strip_tags($row->comment, '<img>'); $row->isOwner = EasyBlogHelper::isMineBlog($my->id, $row->blog_owner); $profile = EasyBlogHelper::getTable('Profile', 'Table'); $profile->load($row->created_by); $row->author = $profile; } echo $this->showToolbar(__FUNCTION__, $user); // Add the breadcrumbs $breadcrumbs = array(JText::_('COM_EASYBLOG_DASHBOARD_BREADCRUMB_COMMENTS') => ''); $theme = new CodeThemes('dashboard'); $theme->set('breadcrumbs', $breadcrumbs); $theme->set('search', $search); $theme->set('filter', $filter); $theme->set('comments', $comments); $theme->set('pagination', $pagination); echo $theme->fetch('dashboard.comments.php'); }
private function addCommentStreamJomsocial($blog, $comment, $external) { $jsCoreFile = JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_community' . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'core.php'; $config = EasyBlogHelper::getConfig(); JFactory::getLanguage()->load('com_easyblog', JPATH_ROOT); // We do not want to add activities if new blog activity is disabled. if (!$config->get('integrations_jomsocial_comment_new_activity')) { return false; } if (!JFile::exists($jsCoreFile)) { return false; } require_once $jsCoreFile; JTable::addIncludePath(JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_community' . DIRECTORY_SEPARATOR . 'tables'); $event = JTable::getInstance('Group', 'CTable'); $event->load($external->uid); $config = EasyBlogHelper::getConfig(); $command = 'easyblog.comment.add'; $blogTitle = JString::substr($blog->title, 0, 30) . '...'; $blogLink = EasyBlogRouter::getRoutedURL('index.php?option=com_easyblog&view=entry&id=' . $comment->post_id, false, true); $content = ''; if ($config->get('integrations_jomsocial_submit_content')) { $content = $comment->comment; $content = EasyBlogCommentHelper::parseBBCode($content); $content = nl2br($content); $content = strip_tags($content); $content = JString::substr($content, 0, $config->get('integrations_jomsocial_comments_length')); } $obj = new stdClass(); $obj->title = JText::sprintf('COM_EASYBLOG_JS_ACTIVITY_COMMENT_ADDED', $blogLink, $blogTitle); $obj->content = $config->get('integrations_jomsocial_submit_content') ? $content : ''; $obj->cmd = $command; $obj->actor = $comment->created_by; $obj->target = 0; $obj->app = 'easyblog'; $obj->cid = $comment->id; $obj->eventid = $event->id; if ($config->get('integrations_jomsocial_activity_likes')) { $obj->like_id = $comment->id; $obj->like_type = 'com_easyblog.comments'; } if ($config->get('integrations_jomsocial_activity_comments')) { $obj->comment_id = $comment->id; $obj->comment_type = 'com_easyblog.comments'; } // add JomSocial activities CFactory::load('libraries', 'activities'); CActivityStream::add($obj); }
public function post() { $app = JFactory::getApplication(); $my = $this->plugin->getUser(); $config = EasyBlogHelper::getConfig(); $acl = EasyBlogACLHelper::getRuleSet(); $post = $app->input->post->getArray(); if (empty($acl->rules->allow_comment) && (empty($my->id) && !$config->get('main_allowguestcomment'))) { $this->plugin->setResponse($this->getErrorResponse(500, JText::_('COM_EASYBLOG_NO_PERMISSION_TO_POST_COMMENT'))); } $isModerated = false; $parentId = isset($post['parent_id']) ? $post['parent_id'] : 0; $commentDepth = isset($post['comment_depth']) ? $post['comment_depth'] : 0; $blogId = isset($post['id']) ? $post['id'] : 0; $subscribeBlog = isset($post['subscribe-to-blog']) ? true : false; if (!$blogId) { $this->plugin->setResponse($this->getErrorResponse(404, 'Invalid Blog')); } // @task: Cleanup posted values. array_walk($post, array($this, '_trim')); array_walk($post, array($this, '_revertValue')); if (!$config->get('comment_require_email') && !isset($post['esemail'])) { $post['esemail'] = ''; } // @task: Run some validation tests on the posted values. if (!$this->_validateFields($post)) { $this->plugin->setResponse($this->getErrorResponse(500, $this->err[0])); } // @task: Akismet detection service. if ($config->get('comment_akismet')) { $data = array('author' => $post['esname'], 'email' => $post['esname'], 'website' => JURI::root(), 'body' => $post['comment'], 'permalink' => EasyBlogRouter::_('index.php?option=com_easyblog&view=entry&id=' . $post['id'])); if (EasyBlogHelper::getHelper('Akismet')->isSpam($data)) { $this->plugin->setResponse($this->getErrorResponse(500, JText::_('COM_EASYBLOG_SPAM_DETECTED_IN_COMMENT'))); } } // @task: Retrieve the comments model $model = EasyBlogHelper::getModel('Comment'); // @task: Retrieve the comment's table $comment = EasyBlogHelper::getTable('Comment'); // We need to rename the esname and esemail back to name and email. $post['name'] = $post['esname']; $post['email'] = $post['esemail']; unset($post['esname']); unset($post['esemail']); // @task: Bind posted values into the table. $comment->bindPost($post); // @task: Process registrations $registerUser = isset($post['esregister']) ? true : false; $fullname = isset($post['name']) ? $post['name'] : ''; $username = isset($post['esusername']) ? $post['esusername'] : ''; $email = $post['email']; $message = ''; $newUserId = 0; // @task: Process registrations if necessary if ($registerUser && $my->id <= 0) { $state = $this->processRegistrations($post, $username, $email, $ajax); if (!is_numeric($state)) { $this->plugin->setResponse($this->getErrorResponse(500, $state)); } $newUserId = $state; } $totalComments = empty($post['totalComment']) ? 1 : $post['totalComment']; $date = EasyBlogHelper::getDate(); $comment->set('created', $date->toMySQL()); $comment->set('modified', $date->toMySQL()); $comment->set('published', 1); $comment->set('parent_id', $parentId); $comment->set('sent', 0); $comment->set('created_by', $my->id); // @rule: Update the user's id if they have just registered earlier. if ($newUserId != 0) { $comment->set('created_by', $newUserId); } // @rule: Update publish status if the comment requires moderation if ($config->get('comment_moderatecomment') == 1 || $my->id == 0 && $config->get('comment_moderateguestcomment') == 1) { $comment->set('published', EBLOG_COMMENT_STATUS_MODERATED); $isModerated = true; } $blog = EasyBlogHelper::getTable('Blog'); $blog->load($blogId); // If moderation for author is disabled, ensure that the comment is published. // If the author is the owner of the blog, it should never be moderated. if (!$config->get('comment_moderateauthorcomment') && $blog->created_by == $my->id) { $comment->set('published', 1); $isModerated = false; } if (!$comment->store()) { $this->plugin->setResponse($this->getErrorResponse(500, 'There was a problem saving the comment')); } // @rule: Process subscription for blog automatically when the user submits a new comment and wants to subscribe to the blog. if ($subscribeBlog && $config->get('main_subscription') && $blog->subscription) { $isSubscribed = false; $userId = $my->id; $blogModel = EasyblogHelper::getModel('Blog'); if ($userId == 0) { $sid = $blogModel->isBlogSubscribedEmail($blog->id, $email); if (empty($sid)) { $isSubscribed = $blogModel->addBlogSubscription($blog->id, $email, '', $fullname); } } else { $sid = $blogModel->isBlogSubscribedUser($blog->id, $userId, $email); if (!empty($sid)) { // @task: User found, update the email address $blogModel->updateBlogSubscriptionEmail($sid, $userId, $email); } else { $isSubscribed = $blogModel->addBlogSubscription($blog->id, $email, $userId, $fullname); } } } $row = $comment; $creator = EasyBlogHelper::getTable('Profile'); $creator->load($my->id); $row->poster = $creator; $row->comment = nl2br($row->comment); $row->comment = EasyBlogCommentHelper::parseBBCode($row->comment); $row->depth = is_null($commentDepth) ? '0' : $commentDepth; $row->likesAuthor = ''; // @rule: Process notifications $comment->processEmails($isModerated, $blog); //update the sent flag to sent $comment->updateSent(); // @TODO - Move this to a map comment function $item = new CommentSimpleSchema(); $item->commentid = $comment->id; $item->postid = $comment->post_id; $item->title = $comment->title; $item->text = EasyBlogCommentHelper::parseBBCode($comment->comment); $item->textplain = strip_tags(EasyBlogCommentHelper::parseBBCode($comment->comment)); $item->created_date = $comment->created; $item->created_date_elapsed = EasyBlogDateHelper::getLapsedTime($comment->created); $item->updated_date = $comment->modified; // Author $item->author->name = isset($comment->poster->nickname) ? $comment->poster->nickname : $comment->name; $item->author->photo = isset($comment->poster->avatar) ? $comment->poster->avatar : 'default_blogger.png'; $item->author->photo = JURI::root() . 'components/com_easyblog/assets/images/' . $item->author->photo; $item->author->email = $comment->email; $item->author->website = isset($comment->poster->url) ? $comment->poster->url : $comment->url; $this->plugin->setResponse($item); }
</b> <?php } ?> <div> <?php if (JString::strlen($item->comment) > 130) { ?> <?php echo JString::substr(strip_tags(EasyBlogCommentHelper::parseBBCode($item->comment)), 0, 130); ?> <?php } else { ?> <?php echo strip_tags(EasyBlogCommentHelper::parseBBCode($item->comment)); ?> <?php } ?> </div> </div> </div> </li> <?php } ?> </ul> </div> <?php }
function updateComment($post) { $ajax = new Ejax(); $mainframe = JFactory::getApplication(); $my = JFactory::getUser(); $acl = EasyBlogACLHelper::getRuleSet(); if (empty($acl->rules->manage_comment) || $my->id == 0) { $title = JText::_('COM_EASYBLOG_INFO'); $width = '450'; $height = 'auto'; $callback = JText::_('COM_EASYBLOG_NO_PERMISSION_TO_UPDATE_COMMENT'); $ajax->alert($callback, $title, $width, $height); $ajax->send(); return; } $commentId = $post['commentId']; array_walk($post, array($this, '_trim')); if (!$this->_validateFields($post)) { $callBack = 'ejax.load(\'dashboard\',\'viewComment\', \'' . $commentId . '\', \'edit\')'; //$ajax->assign('name' , 'hahaha'); //re open the comment edit pop up dialog $ajax->dialog($this->err[0], $callBack, JText::_('COM_EASYBLOG_ERROR'), '450', 'auto'); $ajax->send(); return; } //add here so that other component with the same comment.php jtable file will not get reference. JTable::addIncludePath(JPATH_ROOT . DIRECTORY_SEPARATOR . 'administrator' . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_easyblog' . DIRECTORY_SEPARATOR . 'tables'); $comment = EasyBlogHelper::getTable('Comment', 'Table'); $comment->bindPost($post); $blog = EasyBlogHelper::getTable('Blog', 'Table'); $blog->load($comment->post_id); // Test if the current browser is allowed to do this or not. if ($blog->created_by != $my->id) { echo JText::_('COM_EASYBLOG_NOT_ALLOWED'); exit; } $now = EasyBlogHelper::getDate(); $comment->modified = $now->toMySql(); if ($comment->store()) { //now we need to update the parent content. $title = '<a href="javascript: ejax.load(\'dashboard\',\'viewComment\', \'' . $comment->id . '\', \'readOnly\');">' . $comment->title . '</a>'; $commt->comment = JString::strlen($comment->comment) > 150 ? JString::substr($comment->comment, 0, 150) . '...' : $comment->comment; $commt->comment = EasyBlogCommentHelper::parseBBCode($comment->comment); $commt->comment = nl2br($comment->comment); $content = '<p id="comment-content-' . $comment->id . '">'; $content .= $comment->comment; $content .= '</p>'; $ajax->assign('comment-title-' . $comment->id, $title); $ajax->assign('comment-content-' . $comment->id, $content); $ajax->assign('comment-name-' . $comment->id, $comment->name); } else { $ajax->alert(JText::_('COM_EASYBLOG_COMMENT_FAILED_TO_SAVE'), JText::_('COM_EASYBLOG_ERROR'), '450', 'auto'); } $ajax->send(); return; }