Move to sane directory structure. Don't make 'cms' the top level of the silverstripe...
[silverstripe-elijah.git] / silverstripe-gsoc / cms / code / sitefeatures / PageComment.php
blob02011322ed1cf59aa6b1edf04f4c48093fe76dc0
1 <?php
3 class PageComment extends DataObject {
4 static $db = array(
5 "Name" => "Varchar",
6 "Comment" => "Text",
7 "IsSpam" => "Boolean",
8 );
10 static $has_one = array(
11 "Parent" => "SiteTree",
14 static $casting = array(
15 "RSSTitle" => "Varchar",
18 // Number of comments to show before paginating
19 static $comments_per_page = 10;
21 /**
22 * Return a link to this comment
23 * @return string link to this comment.
25 function Link() {
26 return $this->Parent()->Link();
30 function DeleteLink() {
31 if(Permission::check('CMS_ACCESS_CMSMain')) {
32 return "PageComment/deletecomment/$this->ID";
35 function deletecomment() {
36 if(Permission::check('CMS_ACCESS_CMSMain')) {
37 $comment = DataObject::get_by_id("PageComment", $this->urlParams['ID']);
38 if($comment) {
39 $comment->delete();
43 if(Director::is_ajax()) {
44 echo "";
45 } else {
46 Director::redirectBack();
50 function SpamLink() {
51 $member = Member::currentUser();
52 if(SSAkismet::isEnabled() && Permission::check('CMS_ACCESS_CMSMain') && !$this->getField('IsSpam')) {
53 return "PageComment/reportspam/$this->ID";
57 function HamLink() {
58 $member = Member::currentUser();
59 if(SSAkismet::isEnabled() && Permission::check('CMS_ACCESS_CMSMain') && $this->getField('IsSpam')) {
60 return "PageComment/reportham/$this->ID";
64 function SpamClass() {
65 if($this->getField('IsSpam')) {
66 return 'spam';
67 } else {
68 return 'notspam';
72 function reportspam() {
73 if(SSAkismet::isEnabled() && Permission::check('CMS_ACCESS_CMSMain')) {
74 $comment = DataObject::get_by_id("PageComment", $this->urlParams['ID']);
76 if($comment) {
77 try {
78 $akismet = new SSAkismet();
79 $akismet->setCommentAuthor($comment->getField('Name'));
80 $akismet->setCommentContent($comment->getField('Comment'));
82 $akismet->submitSpam();
83 } catch (Exception $e) {
84 // Akismet didn't work, most likely the service is down.
87 if(SSAkismet::getSaveSpam()) {
88 $comment->setField('IsSpam', true);
89 $comment->write();
90 } else {
91 $comment->delete();
96 if(Director::is_ajax()) {
97 if(SSAkismet::getSaveSpam()) {
98 echo $comment->renderWith('PageCommentInterface_singlecomment');
99 } else {
100 echo '';
102 } else {
103 Director::redirectBack();
107 function reportham() {
108 if(SSAkismet::isEnabled() && Permission::check('CMS_ACCESS_CMSMain')) {
109 $comment = DataObject::get_by_id("PageComment", $this->urlParams['ID']);
111 if($comment) {
112 try {
113 $akismet = new SSAkismet();
114 $akismet->setCommentAuthor($comment->getField('Name'));
115 $akismet->setCommentContent($comment->getField('Comment'));
117 $akismet->submitHam();
118 } catch (Exception $e) {
119 // Akismet didn't work, most likely the service is down.
122 $comment->setField('IsSpam', false);
123 $comment->write();
127 if(Director::is_ajax()) {
128 echo $comment->renderWith('PageCommentInterface_singlecomment');
129 } else {
130 Director::redirectBack();
134 function RSSTitle() {
135 return "Comment by '$this->Name' on " . $this->Parent()->Title;
137 function rss() {
138 $rss = new RSSFeed(DataObject::get("PageComment", "ParentID > 0", "Created DESC", "", 10), "home/", "Page comments", "", "RSSTitle", "Comment", "Name");
139 $rss->outputToBrowser();