예제 #1
0
 function saveComment($values = array())
 {
     if (JCommentsSecurity::badRequest() == 1) {
         JCommentsSecurity::notAuth();
     }
     $db =& JCommentsFactory::getDBO();
     $config =& JCommentsFactory::getConfig();
     $response =& JCommentsFactory::getAjaxResponse();
     $values = JCommentsAJAX::prepareValues($_POST);
     $comment = new JCommentsDB($db);
     $id = (int) $values['id'];
     if ($comment->load($id)) {
         $acl =& JCommentsFactory::getACL();
         if ($acl->canEdit($comment)) {
             if ($values['comment'] == '') {
                 JCommentsAJAX::showErrorMessage(JText::_('ERROR_EMPTY_COMMENT'), 'comment');
             } else {
                 if ($config->getInt('comment_maxlength') != 0 && $acl->check('enable_comment_length_check') == 1 && JCommentsText::strlen($values['comment']) > $config->getInt('comment_maxlength')) {
                     JCommentsAJAX::showErrorMessage(JText::_('ERROR_TOO_LONG_COMMENT'), 'comment');
                 } else {
                     if ($config->getInt('comment_minlength') != 0 && $acl->check('enable_comment_length_check') == 1 && JCommentsText::strlen($values['comment']) < $config->getInt('comment_minlength')) {
                         JCommentsAJAX::showErrorMessage(JText::_('Your comment is too short'), 'comment');
                     } else {
                         $bbcode =& JCommentsFactory::getBBCode();
                         $comment->comment = $values['comment'];
                         $comment->comment = $bbcode->filter($comment->comment);
                         $comment->published = $acl->check('autopublish');
                         if ($config->getInt('comment_title') != 0 && isset($values['title'])) {
                             $comment->title = stripslashes((string) $values['title']);
                         }
                         if ($config->getInt('author_homepage') == 1 && isset($values['homepage'])) {
                             $comment->homepage = JCommentsText::url($values['homepage']);
                         } else {
                             $comment->homepage = '';
                         }
                         $allowed = true;
                         if ($config->getInt('enable_mambots') == 1) {
                             require_once JCOMMENTS_HELPERS . DS . 'plugin.php';
                             JCommentsPluginHelper::importPlugin('jcomments');
                             JCommentsPluginHelper::trigger('onBeforeCommentChanged', array(&$comment, &$response, &$allowed));
                         }
                         if ($allowed == false) {
                             return $response;
                         }
                         $comment->store();
                         $comment->checkin();
                         $comment->datetime = $comment->date;
                         if ($config->getInt('enable_mambots') == 1) {
                             JCommentsPluginHelper::importPlugin('jcomments');
                             JCommentsPluginHelper::trigger('onAfterCommentChanged', array(&$comment, &$response));
                         }
                         if ($config->getInt('enable_notification') == 1) {
                             if ($config->check('notification_type', 1) == true) {
                                 JComments::sendNotification($comment, false);
                             }
                         }
                         JComments::prepareComment($comment);
                         $tmpl =& JCommentsFactory::getTemplate();
                         $tmpl->load('tpl_comment');
                         $tmpl->addVar('tpl_comment', 'get_comment_body', 1);
                         $tmpl->addObject('tpl_comment', 'comment', $comment);
                         $html = $tmpl->renderTemplate('tpl_comment');
                         $html = JCommentsText::jsEscape($html);
                         $response->addScript("jcomments.updateComment(" . $comment->id . ", '{$html}');");
                     }
                 }
             }
         } else {
             $response->addAlert(JText::_('ERROR_CANT_EDIT'));
         }
     }
     unset($comment);
     return $response;
 }
예제 #2
0
 function getCommentsTree($object_id, $object_group = 'com_content', $search_text = '')
 {
     global $my;
     $object_id = (int) $object_id;
     $object_group = trim($object_group);
     $acl =& JCommentsFactory::getACL();
     $dbo =& JCommentsFactory::getDBO();
     $config =& JCommentsFactory::getConfig();
     $canPublish = $acl->canPublish();
     $canComment = $acl->canComment();
     $where = '';
     if ($search_text) {
         $words = explode(' ', $search_text);
         $wheres = array();
         foreach ($words as $word) {
             $wheres2 = array();
             $wheres2[] = "LOWER(name) LIKE '%{$word}%'";
             $wheres2[] = "LOWER(comment) LIKE '%{$word}%'";
         }
         if (isset($wheres2) && count($wheres2)) {
             $where .= ' AND (';
             $where .= implode(' OR ', $wheres2);
             $where .= ' )';
         }
     }
     if ($canComment == 0) {
         $total = JLMS_JComments::getCommentsCount($object_id, $object_group, $where);
         if ($total == 0) {
             return '';
         }
     }
     $query = "SELECT c.id, c.parent, c.object_id, c.object_group, c.userid, c.name, c.username, c.title, c.comment" . "\n , c.email, c.homepage, c.date as datetime, c.ip, c.published, c.checked_out, c.checked_out_time" . "\n , c.isgood, c.ispoor" . "\n , v.value as voted" . "\n FROM #__jcomments AS c" . "\n LEFT JOIN #__jcomments_votes AS v ON c.id = v.commentid " . ($my->id ? " AND  v.userid = " . $my->id : " AND  v.ip = '" . $acl->getUserIP() . "'") . "\n WHERE c.object_id = " . $object_id . "\n AND c.object_group = '" . $object_group . "'" . (JCommentsMultilingual::isEnabled() ? "\nAND c.lang = '" . JCommentsMultilingual::getLanguage() . "'" : "") . ($canPublish == 0 ? "\nAND c.published = 1" : "") . $where . "\n ORDER BY c.parent, c.date ASC";
     $dbo->setQuery($query);
     $rows = $dbo->loadObjectList();
     $tmpl =& JCommentsFactory::getTemplate($object_id, $object_group);
     $tmpl->load('tpl_tree');
     $tmpl->load('tpl_comment');
     if (count($rows)) {
         $isLocked = $config->getInt('object_locked', 0) == 1;
         $tmpl->addVar('tpl_tree', 'comments-refresh', intval(!$isLocked));
         $tmpl->addVar('tpl_tree', 'comments-rss', intval($config->getInt('enable_rss') && !$isLocked));
         $tmpl->addVar('tpl_tree', 'comments-can-subscribe', intval($my->id && $acl->check('enable_subscribe') && !$isLocked));
         if ($my->id && $acl->check('enable_subscribe')) {
             require_once JCOMMENTS_BASE . DS . 'jcomments.subscription.php';
             $manager =& JCommentsSubscriptionManager::getInstance();
             $isSubscribed = $manager->isSubscribed($object_id, $object_group, $my->id);
             $tmpl->addVar('tpl_tree', 'comments-user-subscribed', $isSubscribed);
         }
         $i = 1;
         if ($config->getInt('enable_mambots') == 1) {
             require_once JCOMMENTS_HELPERS . DS . 'plugin.php';
             JCommentsPluginHelper::importPlugin('jcomments');
             JCommentsPluginHelper::trigger('onBeforeDisplayCommentsList', array(&$rows));
             if ($acl->check('enable_gravatar')) {
                 JCommentsPluginHelper::trigger('onPrepareAvatars', array(&$rows));
             }
         }
         require_once JCOMMENTS_LIBRARIES . DS . 'joomlatune' . DS . 'tree.php';
         $tree = new JoomlaTuneTree($rows);
         $items = $tree->get();
         foreach ($rows as $row) {
             if ($config->getInt('enable_mambots') == 1) {
                 JCommentsPluginHelper::trigger('onBeforeDisplayComment', array(&$row));
             }
             // run autocensor, replace quotes, smiles and other pre-view processing
             JComments::prepareComment($row);
             // setup toolbar
             if (!$acl->canModerate($row)) {
                 $tmpl->addVar('tpl_comment', 'comments-panel-visible', 0);
             } else {
                 $tmpl->addVar('tpl_comment', 'comments-panel-visible', 1);
                 $tmpl->addVar('tpl_comment', 'button-edit', $acl->canEdit($row));
                 $tmpl->addVar('tpl_comment', 'button-delete', $acl->canDelete($row));
                 $tmpl->addVar('tpl_comment', 'button-publish', $acl->canPublish($row));
                 $tmpl->addVar('tpl_comment', 'button-ip', $acl->canViewIP($row));
             }
             $tmpl->addVar('tpl_comment', 'comment-show-vote', $config->getInt('enable_voting'));
             $tmpl->addVar('tpl_comment', 'comment-show-email', $acl->canViewEmail($row));
             $tmpl->addVar('tpl_comment', 'comment-show-homepage', $acl->canViewHomepage($row));
             $tmpl->addVar('tpl_comment', 'comment-show-title', $config->getInt('comment_title'));
             $tmpl->addVar('tpl_comment', 'button-vote', $acl->canVote($row));
             $tmpl->addVar('tpl_comment', 'button-quote', $acl->canQuote($row));
             $tmpl->addVar('tpl_comment', 'button-reply', $acl->canReply($row));
             $tmpl->addVar('tpl_comment', 'avatar', $acl->check('enable_gravatar'));
             if (isset($items[$row->id])) {
                 $tmpl->addVar('tpl_comment', 'comment-number', '');
                 $tmpl->addObject('tpl_comment', 'comment', $row);
                 $items[$row->id]->html = $tmpl->renderTemplate('tpl_comment');
                 $i++;
             }
         }
         $tmpl->addObject('tpl_tree', 'comments-items', $items);
         unset($rows);
     }
     return $tmpl->renderTemplate('tpl_tree');
 }
예제 #3
0
 public static function getCommentItem(&$comment)
 {
     $acl = JCommentsFactory::getACL();
     $config = JCommentsFactory::getConfig();
     if ($acl->check('enable_gravatar')) {
         JCommentsEventHelper::trigger('onPrepareAvatar', array(&$comment));
     }
     // run autocensor, replace quotes, smilies and other pre-view processing
     JComments::prepareComment($comment);
     $tmpl = JCommentsFactory::getTemplate($comment->object_id, $comment->object_group);
     $tmpl->load('tpl_comment');
     // setup toolbar
     if (!$acl->canModerate($comment)) {
         $tmpl->addVar('tpl_comment', 'comments-panel-visible', 'visibility', 0);
     } else {
         $tmpl->addVar('tpl_comment', 'comments-panel-visible', 1);
         $tmpl->addVar('tpl_comment', 'button-edit', $acl->canEdit($comment));
         $tmpl->addVar('tpl_comment', 'button-delete', $acl->canDelete($comment));
         $tmpl->addVar('tpl_comment', 'button-publish', $acl->canPublish($comment));
         $tmpl->addVar('tpl_comment', 'button-ip', $acl->canViewIP($comment));
         $tmpl->addVar('tpl_comment', 'button-ban', $acl->canBan($comment));
         $tmpl->addVar('tpl_comment', 'comment-show-email', $acl->canViewEmail());
         $tmpl->addVar('tpl_comment', 'comment-show-homepage', $acl->canViewHomepage());
     }
     $tmpl->addVar('tpl_comment', 'comment-show-vote', $config->getInt('enable_voting'));
     $tmpl->addVar('tpl_comment', 'comment-show-email', $acl->canViewEmail($comment));
     $tmpl->addVar('tpl_comment', 'comment-show-homepage', $acl->canViewHomepage($comment));
     $tmpl->addVar('tpl_comment', 'comment-show-title', $config->getInt('comment_title'));
     $tmpl->addVar('tpl_comment', 'button-vote', $acl->canVote($comment));
     $tmpl->addVar('tpl_comment', 'button-quote', $acl->canQuote($comment));
     $tmpl->addVar('tpl_comment', 'button-reply', $acl->canReply($comment));
     $tmpl->addVar('tpl_comment', 'button-report', $acl->canReport($comment));
     $tmpl->addVar('tpl_comment', 'comment-number', '');
     $tmpl->addVar('tpl_comment', 'avatar', $acl->check('enable_gravatar') && !$comment->deleted);
     $tmpl->addObject('tpl_comment', 'comment', $comment);
     return $tmpl->renderTemplate('tpl_comment');
 }
예제 #4
0
 function getCommentListItem(&$comment)
 {
     $acl =& JCommentsFactory::getACL();
     $config =& JCommentsFactory::getConfig();
     if ($config->getInt('enable_mambots') == 1) {
         require_once JCOMMENTS_HELPERS . DS . 'plugin.php';
         JCommentsPluginHelper::importPlugin('jcomments');
         JCommentsPluginHelper::trigger('onBeforeDisplayComment', array(&$comment));
         if ($acl->check('enable_gravatar')) {
             JCommentsPluginHelper::trigger('onPrepareAvatar', array(&$comment));
         }
     }
     // run autocensor, replace quotes, smiles and other pre-view processing
     JComments::prepareComment($comment);
     $total = JCommentsModel::getCommentsCount($comment->object_id, $comment->object_group, ' AND parent = ' . $comment->parent);
     $tmpl = JCommentsFactory::getTemplate($comment->object_id, $comment->object_group);
     $tmpl->load('tpl_list');
     $tmpl->load('tpl_comment');
     // setup toolbar
     if (!$acl->canModerate($comment)) {
         $tmpl->addVar('tpl_comment', 'comments-panel-visible', 'visibility', 0);
     } else {
         $tmpl->addVar('tpl_comment', 'comments-panel-visible', 1);
         $tmpl->addVar('tpl_comment', 'button-edit', $acl->canEdit($comment));
         $tmpl->addVar('tpl_comment', 'button-delete', $acl->canDelete($comment));
         $tmpl->addVar('tpl_comment', 'button-publish', $acl->canPublish($comment));
         $tmpl->addVar('tpl_comment', 'button-ip', $acl->canViewIP($comment));
         $tmpl->addVar('tpl_comment', 'comment-show-email', $acl->canViewEmail());
         $tmpl->addVar('tpl_comment', 'comment-show-homepage', $acl->canViewHomepage());
     }
     $tmpl->addVar('tpl_comment', 'comment-show-vote', $config->getInt('enable_voting'));
     $tmpl->addVar('tpl_comment', 'comment-show-email', $acl->canViewEmail($comment));
     $tmpl->addVar('tpl_comment', 'comment-show-homepage', $acl->canViewHomepage($comment));
     $tmpl->addVar('tpl_comment', 'comment-show-title', $config->getInt('comment_title'));
     $tmpl->addVar('tpl_comment', 'button-vote', $acl->canVote($comment));
     $tmpl->addVar('tpl_comment', 'button-quote', $acl->canQuote($comment));
     $tmpl->addVar('tpl_comment', 'button-reply', $acl->canReply($comment));
     $tmpl->addVar('tpl_comment', 'button-report', $acl->canReport($comment));
     $tmpl->addVar('tpl_comment', 'comment-number', '');
     $tmpl->addVar('tpl_comment', 'avatar', $acl->check('enable_gravatar'));
     $tmpl->addObject('tpl_comment', 'comment', $comment);
     $commentItem = $tmpl->renderTemplate('tpl_comment');
     $tmpl->addVar('tpl_list', 'comment-id', $comment->id);
     $tmpl->addVar('tpl_list', 'comment-item', $commentItem);
     $tmpl->addVar('tpl_list', 'comment-modulo', $total % 2 ? 1 : 0);
     return $tmpl->renderTemplate('tpl_list');
 }