diff --git a/code/controllers/CommentingController.php b/code/controllers/CommentingController.php index d8c3cbc..cbb1161 100644 --- a/code/controllers/CommentingController.php +++ b/code/controllers/CommentingController.php @@ -181,10 +181,13 @@ class CommentingController extends Controller { if($comment->NeedsModeration){ $this->sessionMessage($moderationMsg, 'good'); } - - $hash = ($comment->NeedsModeration) ? '#Comments_holder' : '#Comment_' . $comment->ID; + + // build up the return link. Ideally redirect to + $holder = Commenting::get_config_value($comment->BaseClass, 'comments_holder_id'); + + $hash = ($comment->NeedsModeration) ? $holder : $comment->Permalink(); $url = (isset($data['ReturnURL'])) ? $data['ReturnURL'] : false; - return ($url) ? $this->redirect($url . $hash) : $this->redirectBack(); + return ($url) ? $this->redirect($url .'#'. $hash) : $this->redirectBack(); } } \ No newline at end of file diff --git a/code/dataobjects/Comment.php b/code/dataobjects/Comment.php index a9b9bed..99a4255 100755 --- a/code/dataobjects/Comment.php +++ b/code/dataobjects/Comment.php @@ -30,19 +30,13 @@ class Comment extends DataObject { static $casting = array( "RSSTitle" => "Varchar", ); - - static $comments_per_page = 10; - static $moderate = false; - - static $bbcode = false; - /** * Return a link to this comment * * @return string link to this comment. */ - function Link($action = "") { + public function Link($action = "") { return $this->Parent()->Link($action) . '#' . $this->Permalink(); } @@ -52,96 +46,34 @@ class Comment extends DataObject { * * @return string */ - function Permalink() { - $prefix = Commenting::get_config_value($this->ownerBaseClass, 'comment_permalink_prefix'); + public function Permalink() { + $prefix = Commenting::get_config_value($this->BaseClass, 'comment_permalink_prefix'); - return $prefix . '-' . $id; - } - - function getRSSName() { - if($this->Name) { - return $this->Name; - } elseif($this->Author()) { - return $this->Author()->getName(); - } - } - - function ParsedBBCode(){ - $parser = new BBCodeParser($this->Comment); - return $parser->parse(); - } - - function DeleteLink() { - return ($this->canDelete()) ? "PageComment_Controller/deletecomment/$this->ID" : false; - } - - function CommentTextWithLinks() { - $pattern = '|([a-zA-Z]+://)([a-zA-Z0-9?&%.;:/=+_-]*)|is'; - $replace = '$1$2'; - return preg_replace($pattern, $replace, $this->Comment); - } - - function SpamLink() { - return ($this->canEdit() && !$this->IsSpam) ? "PageComment_Controller/reportspam/$this->ID" : false; - } - - function HamLink() { - return ($this->canEdit() && $this->IsSpam) ? "PageComment_Controller/reportham/$this->ID" : false; - } - - function ApproveLink() { - return ($this->canEdit() && $this->NeedsModeration) ? "PageComment_Controller/approve/$this->ID" : false; - } - - function SpamClass() { - if($this->getField('IsSpam')) { - return 'spam'; - } else if($this->getField('NeedsModeration')) { - return 'unmoderated'; - } else { - return 'notspam'; - } - } - - - function RSSTitle() { - return sprintf( - _t('PageComment.COMMENTBY', "Comment by '%s' on %s", PR_MEDIUM, 'Name, Page Title'), - Convert::raw2xml($this->getRSSName()), - $this->Parent()->Title - ); - } - - - - - function PageTitle() { - return $this->Parent()->Title; - } - - static function enableBBCode() { - self::$bbcode = true; - } - - static function bbCodeEnabled() { - return self::$bbcode; + return $prefix . $this->ID; } /** - * * @param boolean $includerelations a boolean value to indicate if the labels returned include relation fields - * */ function fieldLabels($includerelations = true) { $labels = parent::fieldLabels($includerelations); - $labels['Name'] = _t('PageComment.Name', 'Author Name'); - $labels['Comment'] = _t('PageComment.Comment', 'Comment'); - $labels['IsSpam'] = _t('PageComment.IsSpam', 'Spam?'); - $labels['NeedsModeration'] = _t('PageComment.NeedsModeration', 'Needs Moderation?'); + $labels['Name'] = _t('Comment.NAME', 'Author Name'); + $labels['Comment'] = _t('Comment.COMMENT', 'Comment'); + $labels['IsSpam'] = _t('Comment.ISSPAM', 'Spam?'); + $labels['NeedsModeration'] = _t('Comment.NEEDSMODERATION', 'Needs Moderation?'); return $labels; } + /** + * Returns the parent {@link DataObject} this comment is attached too + * + * @return DataObject + */ + public function getParent() { + return DataObject::get_by_id($this->BaseClass, $this->ParentID); + } + /** * This method is called just before this object is * written to the database. @@ -186,7 +118,7 @@ class Comment extends DataObject { $extended = $this->extendedCan('canView', $member); if($extended !== null) return $extended; - $page = $this->Parent(); + $page = $this->getParent(); return ( ($page && $page->ProvideComments) || (bool)Permission::checkMember($member, 'CMS_ACCESS_CommentAdmin') @@ -228,4 +160,55 @@ class Comment extends DataObject { return $this->canEdit($member); } + + + /************************************ Review the following */ + function getRSSName() { + if($this->Name) { + return $this->Name; + } elseif($this->Author()) { + return $this->Author()->getName(); + } + } + + function DeleteLink() { + return ($this->canDelete()) ? "PageComment_Controller/deletecomment/$this->ID" : false; + } + + function CommentTextWithLinks() { + $pattern = '|([a-zA-Z]+://)([a-zA-Z0-9?&%.;:/=+_-]*)|is'; + $replace = '$1$2'; + return preg_replace($pattern, $replace, $this->Comment); + } + + function SpamLink() { + return ($this->canEdit() && !$this->IsSpam) ? "PageComment_Controller/reportspam/$this->ID" : false; + } + + function HamLink() { + return ($this->canEdit() && $this->IsSpam) ? "PageComment_Controller/reportham/$this->ID" : false; + } + + function ApproveLink() { + return ($this->canEdit() && $this->NeedsModeration) ? "PageComment_Controller/approve/$this->ID" : false; + } + + function SpamClass() { + if($this->getField('IsSpam')) { + return 'spam'; + } else if($this->getField('NeedsModeration')) { + return 'unmoderated'; + } else { + return 'notspam'; + } + } + + + function RSSTitle() { + return sprintf( + _t('PageComment.COMMENTBY', "Comment by '%s' on %s", PR_MEDIUM, 'Name, Page Title'), + Convert::raw2xml($this->getRSSName()), + $this->Parent()->Title + ); + } } \ No newline at end of file diff --git a/code/extensions/CommentsExtension.php b/code/extensions/CommentsExtension.php index 5b97710..52b05d5 100644 --- a/code/extensions/CommentsExtension.php +++ b/code/extensions/CommentsExtension.php @@ -49,7 +49,11 @@ class CommentsExtension extends DataObjectDecorator { * @return DataObjectSet */ function Comments() { - return DataObject::get('Comment', "\"ParentID\" = '". $this->owner->ID ."' AND \"BaseClass\" = '". $this->ownerBaseClass ."'"); + return DataObject::get( + 'Comment', + "\"ParentID\" = '". $this->owner->ID ."' AND \"BaseClass\" = '". $this->ownerBaseClass ."'", + Commenting::get_config_value($this->ownerBaseClass, 'order_comments_by') + ); } diff --git a/templates/CommentsInterface_singlecomment.ss b/templates/CommentsInterface_singlecomment.ss index 46e8557..b32a193 100755 --- a/templates/CommentsInterface_singlecomment.ss +++ b/templates/CommentsInterface_singlecomment.ss @@ -1,4 +1,4 @@ -

+