-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.hideactivities.plugin.php
executable file
·128 lines (112 loc) · 4.2 KB
/
class.hideactivities.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
<?php if (!defined('APPLICATION')) exit();
/*
Copyright 2013 Alessandro Miliucci <[email protected]>
This file is part of HideActivities <https://github.com/lifeisfoo/HideActivities>
HideActivities is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
HideActivities is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with HideActivities. If not, see <http://www.gnu.org/licenses/>.
*/
// Define the plugin:
$PluginInfo['HideActivities'] = array(
'Name' => 'Hide Activities',
'Description' => 'Shows user activities (profile page) only to friends (from Friendships plugin)',
'Version' => '0.2.2',
'RequiredApplications' => array('Vanilla' => '2.0.18.4'),
'RequiredTheme' => FALSE,
'RequiredPlugins' => array('Friendships' => '0.1'),
'HasLocale' => FALSE,
'SettingsUrl' => FALSE,
'SettingsPermission' => 'Garden.AdminUser.Only',
'Author' => "Alessandro Miliucci",
'AuthorEmail' => '[email protected]',
'AuthorUrl' => 'http://forkwait.net'
);
class HideActivitiesPlugin extends Gdn_Plugin {
private $_FriendshipModel;
public function __construct() {
$this->_FriendshipModel = new FriendshipModel();
}
private function _SessionUserID(){
if(!Gdn::Session()->IsValid()){
return false;
}else{
return Gdn::Session()->UserID;
}
}
private function _ProfilePageID($ProfileController){
if($ProfileController instanceof ProfileController){
return $ProfileController->User->UserID;
}else{
return false;
}
}
private function _EmptyActivities(){
return Gdn::SQL()->Select('*')
->From('Activity a')
->Limit(0, 0)
->Get();
}
private function _FriendsActivities(){
if(!Gdn::Session()->IsValid()){ //if guest
return $this->_EmptyActivities();
}else{ //friends activities
$FriendsIDs = $this->_FriendshipModel->FriendsIDs(Gdn::Session()->UserID);
array_push($FriendsIDs, Gdn::Session()->UserID);
return Gdn::SQL()
//from ActivityModel->ActivityQuery()
->Select('a.*')
->Select('t.FullHeadline, t.ProfileHeadline, t.AllowComments, t.ShowIcon, t.RouteCode')
->Select('t.Name', '', 'ActivityType')
->Select('au.Name', '', 'ActivityName')
->Select('au.Gender', '', 'ActivityGender')
->Select('au.Photo', '', 'ActivityPhoto')
->Select('au.Email', '', 'ActivityEmail')
->Select('ru.Name', '', 'RegardingName')
->Select('ru.Gender', '', 'RegardingGender')
->Select('ru.Email', '', 'RegardingEmail')
->Select('ru.Photo', '', 'RegardingPhoto')
->From('Activity a')
->Join('ActivityType t', 'a.ActivityTypeID = t.ActivityTypeID')
->Join('User au', 'a.ActivityUserID = au.UserID')
->Join('User ru', 'a.RegardingUserID = ru.UserID', 'left')
//from ActivityModel->Get()
->OrderBy('a.DateInserted', 'desc')
//includes only activity from friends
->WhereIn('a.ActivityUserID', $FriendsIDs)
->OrWhereIn('a.InsertUserID', $FriendsIDs)
->Where('t.Public', '1')
->Where('a.CommentActivityID is null')
->Limit(50)
->Get();
}
}
public function ProfileController_BeforeActivitiesList_Handler($Sender) {
if($this->_SessionUserID() && $this->_ProfilePageID($Sender)){
if($this->_SessionUserID() != $this->_ProfilePageID($Sender)){ //not in himself profile page
if(!$this->_FriendshipModel->FriendsFrom($this->_SessionUserID(), $this->_ProfilePageID($Sender))){
//they are not friends
$Sender->ActivityData = $this->_EmptyActivities();
$Sender->NotFriends = true;
}else{ //they are good friends
//do nothing
}
}else{ //user is on himself profile page
//do nothing
}
}else{//guest
$Sender->ActivityData = $this->_EmptyActivities();
}
}
public function ActivityController_BeforeStatusForm_Handler($Sender) {
$Sender->ActivityData = $this->_FriendsActivities();
}
public function Setup() {}
public function OnDisable() {}
}