From 9410f6bd317e64fae8d461b121d3a5c9d2c0a160 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Mon, 27 May 2013 04:37:16 +0200 Subject: [PATCH] Add post flagging --- public_html/classes/forumflag.php | 47 ++++++++++ public_html/classes/forumpost.php | 10 +++ public_html/modules/forums/flag.php | 36 ++++++++ public_html/rewrite.php | 9 ++ public_html/static/css/flag.css | 120 +++++++++++++++++++++++++ public_html/static/js/script.js | 5 +- public_html/templates/forum/flag.tpl | 40 +++++++-- public_html/templates/forum/thread.tpl | 6 +- 8 files changed, 261 insertions(+), 12 deletions(-) create mode 100644 public_html/classes/forumflag.php create mode 100644 public_html/modules/forums/flag.php create mode 100644 public_html/static/css/flag.css diff --git a/public_html/classes/forumflag.php b/public_html/classes/forumflag.php new file mode 100644 index 0000000..b642562 --- /dev/null +++ b/public_html/classes/forumflag.php @@ -0,0 +1,47 @@ + array( + 'Reason' => "Reason" + ), + 'numeric' => array( + "UserId" => "UserId", + "PostId" => "PostId", + "ModeratorId" => "ModeratorId" + ), + 'boolean' => array( + "IsReviewed" => "Reviewed", + "IsValid" => "Valid" + ), + 'timestamp' => array( + "FlagDate" => "FlagDate", + "ReviewDate" => "ReviewDate" + ), + 'user' => array( + "User" => "UserId", + "Moderator" => "ModeratorId" + ), + 'forumpost' => array( + "Post" => "PostId" + ) + ); +} diff --git a/public_html/classes/forumpost.php b/public_html/classes/forumpost.php index ff76f10..c1f89a7 100644 --- a/public_html/classes/forumpost.php +++ b/public_html/classes/forumpost.php @@ -83,4 +83,14 @@ class ForumPost extends CPHPDatabaseRecordClass $sThanks->InsertIntoDatabase(); } } + + public function Flag($user_id, $reason) + { + $sFlag = new ForumFlag(0); + $sFlag->uPostId = $this->sId; + $sFlag->uUserId = $user_id; + $sFlag->uFlagDate = time(); + $sFlag->uReason = $reason; + $sFlag->InsertIntoDatabase(); + } } diff --git a/public_html/modules/forums/flag.php b/public_html/modules/forums/flag.php new file mode 100644 index 0000000..1a0d9c0 --- /dev/null +++ b/public_html/modules/forums/flag.php @@ -0,0 +1,36 @@ +uParameters[1]); +} +catch (NotFoundException $e) +{ + die("No such post exists."); +} + +$done = false; + +if(strtolower($_SERVER['REQUEST_METHOD']) == "post") +{ + $sForumPost->Flag($sCurrentUser->sId, $_POST['reason']); + $done = true; +} + +echo(NewTemplater::Render("forum/flag", $locale->strings, array( + "snippet" => purify_html(Markdown(cut_text($sForumPost->uBody, 500))), + "done" => $done +))); diff --git a/public_html/rewrite.php b/public_html/rewrite.php index 7f9447c..c4bfacf 100644 --- a/public_html/rewrite.php +++ b/public_html/rewrite.php @@ -88,6 +88,15 @@ $router->routes = array( "^/forums/thank/([0-9]+)$" => array( "methods" => "post", "target" => "modules/forums/thank.php", + "authenticator" => "authenticators/user.php", + "auth_error" => "modules/account/login.php", + "_section" => "None" + ), + "^/forums/flag/([0-9]+)$" => array( + "methods" => array("get", "post"), + "target" => "modules/forums/flag.php", + "authenticator" => "authenticators/user.php", + "auth_error" => "modules/account/login.php", "_section" => "None" ), "^/forums/discussion/([0-9]+)/[a-z0-9-]+(/p([0-9]))?$" => array( diff --git a/public_html/static/css/flag.css b/public_html/static/css/flag.css new file mode 100644 index 0000000..2b5a161 --- /dev/null +++ b/public_html/static/css/flag.css @@ -0,0 +1,120 @@ +body +{ + background-color: #E6FFE6; + font-family: sans-serif; + font-size: 14px; +} + +h1 +{ + background-color: #24431F; + color: white; + font-size: 19px; + padding: 7px 9px; +} + +p +{ + padding: 0px 5px; +} + +blockquote +{ + border: 1px solid #609657; + padding: 5px 6px; + margin: 5px 0px; + font-size: 12px; + color: #585858; + max-height: 80px; + overflow: auto; +} + +blockquote p +{ + margin: 6px 0px; +} + +blockquote blockquote +{ + border: 0px; + padding: 5px 0px 5px 5px; + margin: 5px 0px 5px 4px; + border-left: 3px solid #80B380; +} + +blockquote blockquote p +{ + margin: 0px; +} + +form .field +{ + margin-bottom: 7px; + padding-left: 6px; +} + +label, input, textarea, button +{ + display: block; + box-sizing: border-box; + -moz-box-sizing: border-box; +} + +label, input, select +{ + float: left; +} + +label +{ + width: 15%; + font-size: 15px; + color: #397739; + font-weight: bold; + margin-top: 6px; +} + +input, textarea, select +{ + border: 1px solid #397739; + background-color: white; + border-radius: 1px; + margin-top: 5px; +} + +input, select +{ + width: 66%; + font-size: 15px; + padding: 1px 3px; +} + +button +{ + font-size: 14px; + font-weight: bold; + background: #f5fff2; /* Old browsers */ + background: -moz-linear-gradient(top, #f5fff2 34%, #e9f7d7 74%, #ddefc9 100%); /* FF3.6+ */ + background: -webkit-gradient(linear, left top, left bottom, color-stop(34%,#f5fff2), color-stop(74%,#e9f7d7), color-stop(100%,#ddefc9)); /* Chrome,Safari4+ */ + background: -webkit-linear-gradient(top, #f5fff2 34%,#e9f7d7 74%,#ddefc9 100%); /* Chrome10+,Safari5.1+ */ + background: -o-linear-gradient(top, #f5fff2 34%,#e9f7d7 74%,#ddefc9 100%); /* Opera 11.10+ */ + background: -ms-linear-gradient(top, #f5fff2 34%,#e9f7d7 74%,#ddefc9 100%); /* IE10+ */ + background: linear-gradient(to bottom, #f5fff2 34%,#e9f7d7 74%,#ddefc9 100%); /* W3C */ + filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f5fff2', endColorstr='#ddefc9',GradientType=0 ); /* IE6-9 */ + color: #2E4F2B; + border: 1px solid silver; + border-radius: 4px; + padding: 4px 6px; + box-shadow: 0px 0px 4px 0px #c0dbba; + -webkit-box-shadow: 0px 0px 4px 0px #c0dbba; + -moz-box-shadow: 0px 0px 4px 0px #c0dbba; + -o-box-shadow: 0px 0px 4px 0px #c0dbba; + -ms-box-shadow: 0px 0px 4px 0px #c0dbba; + text-shadow: 1px 1px 0px #bbe6a6; + -webkit-text-shadow: 1px 1px 0px #bbe6a6; + -moz-text-shadow: 1px 1px 0px #bbe6a6; + -o-text-shadow: 1px 1px 0px #bbe6a6; + -ms-text-shadow: 1px 1px 0px #bbe6a6; + width: 15%; + float: right; +} diff --git a/public_html/static/js/script.js b/public_html/static/js/script.js index f5d083e..2bfae14 100644 --- a/public_html/static/js/script.js +++ b/public_html/static/js/script.js @@ -43,11 +43,10 @@ $(function(){ $('a.flag').click(function(event){ $.fancybox.open([{ - href: "/forums/flag/" + $(this).data("id"), - title: "Report a post" + href: "/forums/flag/" + $(this).data("id") }], { - padding: 24, + padding: 4, autoSize: false, width: 550, height: 400, diff --git a/public_html/templates/forum/flag.tpl b/public_html/templates/forum/flag.tpl index 3316309..02278d9 100644 --- a/public_html/templates/forum/flag.tpl +++ b/public_html/templates/forum/flag.tpl @@ -1,15 +1,41 @@ Flag post - +

Flag abusive post

-

- If you believe this post violates the community - rules or should otherwise be removed, please fill - in a reason or explanation below and hit the Flag - button. -

+ + {%if done == false} +
+ {%?snippet} +
+ +

+ If you believe this post violates the community + rules or should otherwise be removed, please fill + in a reason or explanation below and hit the Flag + button. +

+ +

+ We ask that you only flag posts that genuinely + break the community rules or are problematic + otherwise; we will not solve your personal conflicts, + and false reports will be ignored. +

+ +
+
+ + + +
+
+ {%else} +

+ Thanks for your report! A moderator will review it soon. +

+ {%/if} diff --git a/public_html/templates/forum/thread.tpl b/public_html/templates/forum/thread.tpl index ef8ac25..229abde 100644 --- a/public_html/templates/forum/thread.tpl +++ b/public_html/templates/forum/thread.tpl @@ -16,8 +16,10 @@ {%?post[author]} {%?post[date]} - Thanks - Flag + {%if logged-in == true} + Thanks + Flag + {%/if}
{%?post[author-status]}