/** * comment save function used by cb.easyblog plugin. */ function saveCBcomment($post) { require_once JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_easyblog' . DIRECTORY_SEPARATOR . 'constants.php'; $mainframe = JFactory::getApplication(); $my = JFactory::getUser(); $config = EasyBlogHelper::getConfig(); $ajax = new Ejax(); if (JString::strlen($post['comment']) == 0) { $ajax->script('easyblogApp.comment.notify("' . $post['id'] . '","' . JText::_('Comment is empty') . '","' . 'error' . '")'); $ajax->script('easyblogApp.spinner.hide()'); $ajax->script('easyblogApp.element.focus("comment")'); return $ajax->send(); } // We don't require a title here. $post['title'] = ''; //real work start here. $isModerate = false; $parentId = "0"; $commentDepth = $post['comment_depth']; $blogId = $post['id']; //we need to rename the esname and esemail back to name and email. $post['url'] = ''; $post['name'] = $post['esname']; $post['email'] = $post['esemail']; unset($post['esname']); unset($post['esemail']); JTable::addIncludePath(EBLOG_TABLES); $db = EasyBlogHelper::db(); $comment = EasyBlogHelper::getTable('Comment', 'Table'); $comment->bindPost($post); $now = EasyBlogHelper::getDate(); $totalComment = empty($post['totalComment']) ? 1 : $post['totalComment']; $comment->created = $now->toMySql(); $comment->modified = $now->toMySql(); $comment->published = 1; $comment->parent_id = $parentId; $comment->created_by = $my->id; if ($my->id != 0 && $config->get('comment_moderatecomment') == 1 || $my->id == 0 && $config->get('comment_moderateguestcomment') == 1) { $comment->published = 0; $isModerate = true; } jimport('joomla.application.component.model'); JLoader::import('Comment', EBLOG_ROOT . DIRECTORY_SEPARATOR . 'models'); $model = JModel::getInstance('Comment', 'EasyBlogModel'); $latestComment = $model->getLatestComment($blogId, $parentId); $left = 1; $right = 2; if (!empty($latestComment)) { $left = $latestComment->rgt + 1; $right = $latestComment->rgt + 2; $model->updateCommentSibling($blogId, $latestComment->rgt); } $comment->lft = $left; $comment->rgt = $right; if (!$comment->store()) { $ajax->script('easyblogApp.comment.notify("' . $post['id'] . '","' . JText::_('Comment add failed') . '","' . 'error' . '")'); $ajax->script('easyblogApp.spinner.hide()'); $ajax->{$ajax}('easyblogApp.element.focus("comment")'); return $ajax->send(); } $profile = EasyBlogHelper::getTable('Profile', 'Table'); $profile->load($comment->created_by); $comment->creator = $profile; $date = EasyBlogDateHelper::dateWithOffSet($comment->created); $comment->formattedDate = $date->toFormat($config->get('layout_dateformat', '%A, %d %B %Y')); $text = JString::strlen($comment->comment) > 50 ? JString::substr(strip_tags($comment->comment), 0, 50) . '...' : strip_tags($comment->comment); $commentText = ' <li> <div class="blog-comment-avatar"> <a href="' . $comment->creator->getProfileLink() . '"><img src="' . $comment->creator->getAvatar() . '" width="32" /></a> </div> <div class="blog-comment-item eztc"> <div class="small"> <a href="' . $comment->creator->getProfileLink() . '">' . $comment->creator->getName() . '</a> ' . JText::_('on') . ' <span class="small">' . $comment->formattedDate . '</span> </div> ' . $text . ' </div> <div style="clear: both;"></div> </li>'; $ajax->prepend('comments-wrapper' . $blogId, $commentText); $ajax->script('easyblogApp.comment.cancel("' . $blogId . '")'); $ajax->script('easyblogApp.spinner.hide()'); $ajax->script('easyblogApp.comment.notify("' . $blogId . '","' . JText::_('Comment Added') . '","' . 'success' . '")'); return $ajax->send(); }