diff --git a/code/controllers/CommentingController.php b/code/controllers/CommentingController.php index ee1fb4c..5bb0278 100644 --- a/code/controllers/CommentingController.php +++ b/code/controllers/CommentingController.php @@ -79,38 +79,36 @@ class CommentingController extends Controller { $class = $request->param('ID'); $id = $request->param('OtherID'); - if(isset($_GET['pageid'])) { - $id = Convert::raw2sql($_GET['pageid']); + $comments = Comment::get()->filter(array( + 'Moderated' => 1, + 'IsSpam' => 0, + )); - $comments = Comment::get()->where(sprintf( - "BaseClass = 'SiteTree' AND ParentID = '%s' AND Moderated = 1 AND IsSpam = 0", $id + if($request->getVar('pageid')) { + $comments = $comments->filter(array( + 'BaseClass' => 'SiteTree', + 'ParentID' => $request->getVar('pageid'), )); $link = $this->Link('rss', 'SiteTree', $id); - } else if($class && $id) { + } elseif($class && $id) { if(Commenting::has_commenting($class)) { - $comments = Comment::get()->where(sprintf( - "BaseClass = '%s' AND ParentID = '%s' AND Moderated = 1 AND IsSpam = 0", - Convert::raw2sql($class), - Convert::raw2sql($id) + $comments = $comments->filter(array( + 'BaseClass' => $class, + 'ParentID' => $id, )); $link = $this->Link('rss', Convert::raw2xml($class), (int) $id); } else { return $this->httpError(404); } - } else if($class) { + } elseif($class) { if(Commenting::has_commenting($class)) { - $comments = Comment::get()->where(sprintf( - "BaseClass = '%s' AND Moderated = 1 AND IsSpam = 0", - Convert::raw2sql($class) - )); + $comments = $comments->filter('BaseClass', $class); } else { return $this->httpError(404); } - } else { - $comments = Comment::get()->where("Moderated = 1 AND IsSpam = 0"); } $title = _t('CommentingController.RSSTITLE', "Comments RSS Feed"); diff --git a/code/dataobjects/Comment.php b/code/dataobjects/Comment.php index d2cad8a..c5dfe1f 100755 --- a/code/dataobjects/Comment.php +++ b/code/dataobjects/Comment.php @@ -22,7 +22,7 @@ class Comment extends DataObject { "Author" => "Member" ); - public static $default_sort = "Created DESC"; + public static $default_sort = '"Created" DESC'; public static $has_many = array(); diff --git a/code/extensions/CommentsExtension.php b/code/extensions/CommentsExtension.php index 2a01c28..a34ecdc 100644 --- a/code/extensions/CommentsExtension.php +++ b/code/extensions/CommentsExtension.php @@ -56,19 +56,20 @@ class CommentsExtension extends DataExtension { $order = Commenting::get_config_value($this->ownerBaseClass, 'order_comments_by'); - // has moderation been turned on if it has amend the sql query - $moderation = ''; + $list = Comment::get()->filter(array( + 'ParentID' => $this->owner->ID, + 'BaseClass' => $this->ownerBaseClass + ))->sort($order); + + // has moderation been turned on if it has amend the DataList if (Commenting::get_config_value($this->ownerBaseClass, 'require_moderation')) { - $member = new Member(); - if ($member->currentUser() == false) { - $moderation = 'Moderated = 1 AND '; + if (Member::currentUser() == false) { + $list = $list->filter('Moderated', 1); } } - $list = new PaginatedList(Comment::get()->where(sprintf( - $moderation . "ParentID = '%s' AND BaseClass = '%s'", $this->owner->ID, $this->ownerBaseClass - ))->sort($order)); + $list = new PaginatedList($list); $list->setPageLength(Commenting::get_config_value( $this->ownerBaseClass, 'comments_per_page'