Пример #1
0
 public static function getCommentPage($object_id, $object_group, $comment_id)
 {
     $config = JCommentsFactory::getConfig();
     if ($config->getInt('comments_per_page') > 0) {
         require_once JCOMMENTS_HELPERS . '/pagination.php';
         $pagination = new JCommentsPagination($object_id, $object_group);
         $this_page = $pagination->getCommentPage($object_id, $object_group, $comment_id);
     } else {
         $this_page = 0;
     }
     return $this_page;
 }
Пример #2
0
 public static function deleteComment($id)
 {
     if (JCommentsSecurity::badRequest() == 1) {
         JCommentsSecurity::notAuth();
     }
     $acl = JCommentsFactory::getACL();
     $db = JCommentsFactory::getDBO();
     $config = JCommentsFactory::getConfig();
     $response = JCommentsFactory::getAjaxResponse();
     $comment = new JCommentsTableComment($db);
     if ($comment->load((int) $id)) {
         if ($acl->isLocked($comment)) {
             $response->addAlert(JText::_('ERROR_BEING_EDITTED'));
         } else {
             if ($acl->canDelete($comment)) {
                 $object_id = $comment->object_id;
                 $object_group = $comment->object_group;
                 $currentPage = 1;
                 if ($config->get('template_view') != 'tree' && $config->getInt('comments_per_page') > 0) {
                     require_once JCOMMENTS_HELPERS . DS . 'pagination.php';
                     $pagination = new JCommentsPagination($object_id, $object_group);
                     $currentPage = $pagination->getCommentPage($object_id, $object_group, $id);
                 }
                 $result = JCommentsEvent::trigger('onJCommentsCommentBeforeDelete', array(&$comment));
                 if (!in_array(false, $result, true)) {
                     if ($config->getInt('delete_mode') == 0) {
                         $comment->delete();
                         $count = JComments::getCommentsCount($object_id, $object_group, '', true);
                         if ($config->get('template_view') == 'tree') {
                             if ($count > 0) {
                                 $response->addScript("jcomments.updateComment('{$id}','');");
                             } else {
                                 $response->addScript("jcomments.updateTree('',null);");
                             }
                         } else {
                             if ($count > 0) {
                                 if ($config->getInt('comments_per_page') > 0) {
                                     $pagination->setCommentsCount($count);
                                     $currentPage = min($currentPage, $pagination->getTotalPages());
                                     $html = JComments::getCommentsList($object_id, $object_group, $currentPage);
                                     $html = JCommentsText::jsEscape($html);
                                     $response->addScript("jcomments.updateList('{$html}','r');");
                                 } else {
                                     $response->addScript("jcomments.updateComment('{$id}','');");
                                 }
                             } else {
                                 $response->addScript("jcomments.updateList('','r');");
                             }
                         }
                     } else {
                         $comment->markAsDeleted();
                         $html = JCommentsText::jsEscape(JComments::getCommentItem($comment));
                         $response->addScript("jcomments.updateComment(" . $comment->id . ", '{$html}');");
                     }
                     JCommentsEvent::trigger('onJCommentsCommentAfterDelete', array(&$comment));
                 }
             } else {
                 $response->addAlert(JText::_('ERROR_CANT_DELETE'));
             }
         }
     }
     return $response;
 }