-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.php
163 lines (136 loc) · 5.62 KB
/
plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
// Copyright 2014 Toby Zerner, Simon Zerner
// This file is part of esoTalk. Please see the included license file for usage information.
if (!defined("IN_ESOTALK")) exit;
ET::$pluginInfo["ShadowBan"] = array(
"name" => "Shadow Ban",
"description" => "Hide one or all of a member's posts without them being aware.",
"version" => ESOTALK_VERSION,
"author" => "Toby Zerner",
"authorEmail" => "support@esotalk.org",
"authorURL" => "http://esotalk.org",
"license" => "GPLv2",
"dependencies" => array(
"esoTalk" => "1.0.0g4"
)
);
class ETPlugin_ShadowBan extends ETPlugin {
// Setup: add columns to the member and post tables.
public function setup($oldVersion = "")
{
$structure = ET::$database->structure();
$structure->table("member")
->column("shadowBanned", "bool", 0)
->exec(false);
$structure->table("post", "MyISAM")
->column("shadowDeleted", "bool", 0)
->exec(false);
return true;
}
public function handler_memberController_initProfile($sender, &$member, $panes, $controls, $actions)
{
$model = ET::memberModel();
// If we can suspend the member, then we can shadow-ban them too.
if ($model->canSuspend($member)) {
$controls->add("shadowBan", "<a href='".URL("member/shadowBan/".$member["memberId"]."?token=".ET::$session->token."&return=".urlencode(ET::$controller->selfURL))."' id='shadowBanLink'><i class='icon-adjust'></i>".T($member["shadowBanned"] ? "Un-shadow ban" : "Shadow ban")."</a>", array("before" => "suspend"));
}
}
public function action_memberController_shadowBan($controller, $memberId = "")
{
if (!($member = $controller->getMember($memberId))) return;
if (!ET::$session->user or !$controller->validateToken()) return;
// If we don't have permission to shadow-ban the member, throw an error.
if (!ET::memberModel()->canSuspend($member)) {
$this->renderMessage(T("Error"), T("message.noPermission"));
return;
}
// Write to the database.
ET::memberModel()->updateById($member["memberId"], array("shadowBanned" => !$member["shadowBanned"]));
// Redirect back to the member profile.
$controller->redirect(R("return", URL("member/".$memberId)));
}
public function handler_postModel_getPostsBefore($sender, $sql)
{
$sql->select("m.shadowBanned", "shadowBanned");
}
public function handler_conversationController_formatPostForTemplate($sender, &$formatted, $post, $conversation)
{
// If the post hasn't been deleted, but its author has been shadow-
// banned, then hide it from everyone but the author.
if (!$post["deleteTime"]) {
if ($conversation["startMemberId"] != ET::$session->userId && $post["shadowBanned"]) {
$post["deleteTime"] = $post["time"];
$formatted = $sender->formatPostForTemplate($post, $conversation);
if ($conversation["canModerate"]) {
$formatted["controls"] = array("<span>This member has been shadow-banned</span>");
}
}
}
// If the post has been deleted, then we have the ability to shadow-
// delete it.
else {
if ($conversation["canModerate"]) {
addToArray($formatted["controls"], "<a href='".URL("conversation/shadowDelete/".$post["postId"]."?token=".ET::$session->token)."' title='".T($post["shadowDeleted"] ? "Un-shadow Delete" : "Shadow Delete")."' class='control-shadowDelete'><i class='icon-".($post["shadowDeleted"] ? "circle" : "adjust")."'></i></a>");
}
// If it has been shadow-deleted or its author shadow-banned, then
// hide it from everyone but the author.
if ($conversation["startMemberId"] == ET::$session->userId && ($post["shadowDeleted"] || $post["shadowBanned"])) {
$post["deleteTime"] = null;
$formatted = $sender->formatPostForTemplate($post, $conversation);
}
}
}
public function action_conversationController_shadowDelete($sender, $postId)
{
$conversation = ET::conversationModel()->getByPostId($postId);
if (!$conversation or !$sender->validateToken()) return;
// Stop here with an error if the user isn't allowed to shadow delete the post.
if (!$conversation["canModerate"]) {
$sender->renderMessage(T("Error"), T("message.noPermission"));
return false;
}
$model = ET::postModel();
$post = $model->getById($postId);
$model->updateById($postId, array("shadowDeleted" => !$post["shadowDeleted"]));
redirect(URL(R("return", postURL($postId))));
}
public function handler_conversationModel_addReplyBeforeCreateActivity($sender, $conversation, $postId)
{
// Prevent notifications from being sent when a reply is made if the
// member is shadow-banned.
if (ET::$session->user["shadowBanned"]) {
return $postId;
}
}
public function handler_activityModel_getActivityBefore($sender, $member, $activity, $posts)
{
// If the member is shadow-banned, hide all of their posts from their
// activity stream.
if ($member["shadowBanned"] && $member["memberId"] != ET::$session->userId) {
$posts->where("0=1");
}
// Hide any shadow-deleted posts.
$posts->where("p.shadowDeleted=0");
}
// public function handler_postModel_getPostsAfter($sender, &$posts)
// {
// foreach ($posts as $k => &$post) {
// if ($post["shadowBanned"] or $post["shadowDeleted"]) {
// unset($posts[$k]);
// }
// }
// }
// public function handler_searchModel_beforeGetResults($controller, $sql)
// {
// $sql->select("lpm.shadowBanned OR lp.shadowDeleted", "shadowLastPost")
// ->from("post lp", "c.conversationId=lp.conversationId AND c.lastPostTime=lp.time AND c.lastPostMemberId=lp.memberId", "left");
// }
// public function handler_searchModel_afterGetResults($sender, &$results)
// {
// foreach ($results as &$result) {
// if ($result["shadowLastPost"]) {
// $result["unread"] = max(0, $result["unread"] - 1);
// }
// }
// }
}