-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.php
More file actions
128 lines (103 loc) · 4.04 KB
/
plugin.php
File metadata and controls
128 lines (103 loc) · 4.04 KB
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
<?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["Ignore"] = array(
"name" => "Ignore",
"description" => "Allows users to ignore other users and hide their posts.",
"version" => ESOTALK_VERSION,
"author" => "Toby Zerner",
"authorEmail" => "support@esotalk.org",
"authorURL" => "http://esotalk.org",
"license" => "GPLv2",
"dependencies" => array(
"esoTalk" => "1.0.0g4"
)
);
class ETPlugin_Ignore extends ETPlugin {
// Setup: add a follow column to the member_channel table.
public function setup($oldVersion = "")
{
$structure = ET::$database->structure();
$structure->table("member_member")
->column("ignored", "bool", 0)
->exec(false);
return true;
}
public function init()
{
ET::define("message.noIgnoredMembers", "You haven't ignored any members. To ignore a member, go to their profile and choose <strong>Controls → Ignore member</strong>.");
}
public function handler_memberController_initProfile($sender, &$member, $panes, $controls, $actions)
{
if (!ET::$session->user or $member["memberId"] == ET::$session->userId) return;
$controls->separator(0);
$controls->add("ignore", "<a href='".URL("member/ignore/".$member["memberId"]."?token=".ET::$session->token."&return=".urlencode(ET::$controller->selfURL))."' id='ignoreLink'><i class='icon-eye-close'></i>".T($member["ignored"] ? "Unignore member" : "Ignore member")."</a>", 0);
}
// Add an action to toggle the ignoring status of a member.
public function action_memberController_ignore($controller, $memberId = "")
{
if (!ET::$session->user or !$controller->validateToken()) return;
// Make sure the member that we're trying to ignore exists.
if (!ET::SQL()->select("memberId")->from("member")->where("memberId", (int)$memberId)->exec()->numRows()) return;
// Work out if we're already ignored or not, and switch to the opposite of that.
$ignored = !ET::SQL()
->select("ignored")
->from("member_member")
->where("memberId1", ET::$session->userId)
->where("memberId2", (int)$memberId)
->exec()
->result();
// Write to the database.
ET::memberModel()->setStatus(ET::$session->userId, $memberId, array("ignored" => $ignored));
// Redirect back to the member profile.
$controller->redirect(R("return", URL("member/".$memberId)));
}
protected function getIgnored()
{
// Get a list of all the members that the user has ignored.
$result = ET::SQL()
->select("memberId2")
->from("member_member")
->where("memberId1", ET::$session->userId)
->where("ignored", 1)
->exec();
$ignoredIds = array_keys($result->allRows("memberId2"));
return $ignoredIds;
}
public function handler_postModel_getPostsAfter($sender, &$posts)
{
$ignoredIds = $this->getIgnored();
foreach ($posts as $k => &$post) {
if (in_array($post["memberId"], $ignoredIds)) unset($posts[$k]);
}
}
public function handler_searchModel_afterGetResults($sender, &$results)
{
$ignoredIds = $this->getIgnored();
foreach ($results as &$result) {
if (in_array($result["lastPostMemberId"], $ignoredIds)) $result["unread"] = 0;
}
}
public function handler_settingsController_initProfile($controller, $panes)
{
$panes->add("ignored", "<a href='".URL("settings/ignored")."'>".T("Ignored")."</a>");
}
public function action_settingsController_ignored($controller)
{
// The profile method sets up the settings page and returns the member's details.
// The argument is the name of the currently-active pane.
if (!($member = $controller->profile("ignored"))) return;
$ignoredIds = $this->getIgnored();
if ($ignoredIds) {
$sql = ET::SQL();
$sql->where("m.memberId IN (:memberIds)")
->bind(":memberIds", $ignoredIds)
->orderBy("m.username ASC");
$members = ET::memberModel()->getWithSQL($sql);
$controller->data("ignored", $members);
}
$controller->addCSSFile($this->resource("ignore.css"));
$controller->renderProfile($this->view("ignored"));
}
}