3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2010, StatusNet, Inc.
6 * Shows social activities in the output feed
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Affero General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Affero General Public License for more details.
20 * You should have received a copy of the GNU Affero General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 * @author Evan Prodromou <evan@status.net>
26 * @copyright 2010 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28 * @link http://status.net/
31 if (!defined('STATUSNET')) {
32 // This check helps protect against security problems;
33 // your code file can't be executed directly from the web.
38 * Activity plugin main class
42 * @author Evan Prodromou <evan@status.net>
43 * @copyright 2010 StatusNet, Inc.
44 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
45 * @link http://status.net/
48 class ActivityPlugin extends Plugin
50 const VERSION = '0.1';
52 // Flags to switch off certain activity notices
53 public $StartFollowUser = true;
54 public $StopFollowUser = true;
55 public $JoinGroup = true;
56 public $LeaveGroup = true;
57 public $StartLike = true;
58 public $StopLike = true;
60 function onAutoload($cls)
62 $dir = dirname(__FILE__);
71 function onEndSubscribe($subscriber, $other)
73 // Only do this if config is enabled
74 if(!$this->StartFollowUser) return true;
75 $user = $subscriber->getUser();
77 $sub = Subscription::pkeyGet(array('subscriber' => $subscriber->id,
78 'subscribed' => $other->id));
79 $rendered = sprintf(_m('<em><a href="%s">%s</a> started following <a href="%s">%s</a></em>.'),
80 $subscriber->profileurl,
81 $subscriber->getBestName(),
83 $other->getBestName());
84 $content = sprintf(_m('%s (%s) started following %s (%s).'),
85 $subscriber->getBestName(),
86 $subscriber->profileurl,
87 $other->getBestName(),
90 $notice = Notice::saveNew($user->id,
93 array('rendered' => $rendered,
94 'verb' => ActivityVerb::FOLLOW,
95 'object_type' => ActivityObject::PERSON,
101 function onEndUnsubscribe($subscriber, $other)
103 // Only do this if config is enabled
104 if(!$this->StopFollowUser) return true;
105 $user = $subscriber->getUser();
107 $rendered = sprintf(_m('<em><a href="%s">%s</a> stopped following <a href="%s">%s</a></em>.'),
108 $subscriber->profileurl,
109 $subscriber->getBestName(),
111 $other->getBestName());
112 $content = sprintf(_m('%s (%s) stopped following %s (%s).'),
113 $subscriber->getBestName(),
114 $subscriber->profileurl,
115 $other->getBestName(),
118 $uri = TagURI::mint('stop-following:%d:%d:%s',
121 common_date_iso8601(common_sql_now()));
123 $notice = Notice::saveNew($user->id,
126 array('rendered' => $rendered,
128 'verb' => ActivityVerb::UNFOLLOW,
129 'object_type' => ActivityObject::PERSON));
134 function onEndFavorNotice($profile, $notice)
136 // Only do this if config is enabled
137 if(!$this->StartLike) return true;
139 $user = $profile->getUser();
143 $author = $notice->getProfile();
144 $fave = Fave::pkeyGet(array('user_id' => $user->id,
145 'notice_id' => $notice->id));
147 $rendered = sprintf(_m('<em><a href="%s">%s</a> liked <a href="%s">%s\'s update</a></em>.'),
148 $profile->profileurl,
149 $profile->getBestName(),
151 $author->getBestName());
152 $content = sprintf(_m('%s (%s) liked %s\'s status (%s)'),
153 $profile->getBestName(),
154 $profile->profileurl,
155 $author->getBestName(),
158 $notice = Notice::saveNew($user->id,
161 array('rendered' => $rendered,
162 'uri' => $fave->getURI(),
163 'verb' => ActivityVerb::FAVORITE,
164 'object_type' => (($notice->verb == ActivityVerb::POST) ?
165 $notice->object_type : ActivityObject::ACTIVITY)));
170 function onEndDisfavorNotice($profile, $notice)
172 // Only do this if config is enabled
173 if(!$this->StopLike) return true;
174 $user = User::staticGet('id', $profile->id);
177 $author = Profile::staticGet('id', $notice->profile_id);
178 $rendered = sprintf(_m('<em><a href="%s">%s</a> stopped liking <a href="%s">%s\'s update</a></em>.'),
179 $profile->profileurl,
180 $profile->getBestName(),
182 $author->getBestName());
183 $content = sprintf(_m('%s (%s) stopped liking %s\'s status (%s)'),
184 $profile->getBestName(),
185 $profile->profileurl,
186 $author->getBestName(),
189 $uri = TagURI::mint('unlike:%d:%d:%s',
192 common_date_iso8601(common_sql_now()));
194 $notice = Notice::saveNew($user->id,
197 array('rendered' => $rendered,
199 'verb' => ActivityVerb::UNFAVORITE,
200 'object_type' => (($notice->verb == ActivityVerb::POST) ?
201 $notice->object_type : ActivityObject::ACTIVITY)));
206 function onEndJoinGroup($group, $user)
208 // Only do this if config is enabled
209 if(!$this->JoinGroup) return true;
211 $profile = $user->getProfile();
213 $rendered = sprintf(_m('<em><a href="%s">%s</a> joined the group "<a href="%s">%s</a>"</em>.'),
214 $profile->profileurl,
215 $profile->getBestName(),
217 $group->getBestName());
218 $content = sprintf(_m('%s (%s) joined the group %s (%s).'),
219 $profile->getBestName(),
220 $profile->profileurl,
221 $group->getBestName(),
224 $mem = Group_member::staticGet(array('group_id' => $group->id,
225 'profile_id' => $profile->id));
227 $notice = Notice::saveNew($user->id,
230 array('rendered' => $rendered,
231 'uri' => $mem->getURI(),
232 'verb' => ActivityVerb::JOIN,
233 'object_type' => ActivityObject::GROUP));
237 function onEndLeaveGroup($group, $user)
239 // Only do this if config is enabled
240 if(!$this->LeaveGroup) return true;
242 $profile = $user->getProfile();
244 $rendered = sprintf(_m('<em><a href="%s">%s</a> left the group "<a href="%s">%s</a>"</em>.'),
245 $profile->profileurl,
246 $profile->getBestName(),
248 $group->getBestName());
249 $content = sprintf(_m('%s (%s) left the group %s (%s)'),
250 $profile->getBestName(),
251 $profile->profileurl,
252 $group->getBestName(),
255 $uri = TagURI::mint('leave:%d:%d:%s',
258 common_date_iso8601(common_sql_now()));
260 $notice = Notice::saveNew($user->id,
263 array('rendered' => $rendered,
265 'verb' => ActivityVerb::LEAVE,
266 'object_type' => ActivityObject::GROUP));
270 function onEndNoticeAsActivity($notice, &$activity)
276 function onPluginVersion(&$versions)
278 $versions[] = array('name' => 'Activity',
279 'version' => self::VERSION,
280 'author' => 'Evan Prodromou',
281 'homepage' => 'http://status.net/wiki/Plugin:Activity',
283 _m('Emits notices when social activities happen.'));