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__);
68 case 'FollowListItem':
69 case 'UnfollowListItem':
70 case 'SystemListItem':
71 include_once $dir . '/'.strtolower($cls).'.php';
78 function onEndSubscribe($subscriber, $other)
80 // Only do this if config is enabled
81 if(!$this->StartFollowUser) return true;
82 $user = $subscriber->getUser();
84 $sub = Subscription::pkeyGet(array('subscriber' => $subscriber->id,
85 'subscribed' => $other->id));
86 $rendered = sprintf(_m('<em><a href="%s">%s</a> started following <a href="%s">%s</a></em>.'),
87 $subscriber->profileurl,
88 $subscriber->getBestName(),
90 $other->getBestName());
91 $content = sprintf(_m('%s (%s) started following %s (%s).'),
92 $subscriber->getBestName(),
93 $subscriber->profileurl,
94 $other->getBestName(),
97 $notice = Notice::saveNew($user->id,
100 array('rendered' => $rendered,
101 'verb' => ActivityVerb::FOLLOW,
102 'object_type' => ActivityObject::PERSON,
103 'uri' => $sub->uri));
108 function onEndUnsubscribe($subscriber, $other)
110 // Only do this if config is enabled
111 if(!$this->StopFollowUser) return true;
112 $user = $subscriber->getUser();
114 $rendered = sprintf(_m('<em><a href="%s">%s</a> stopped following <a href="%s">%s</a></em>.'),
115 $subscriber->profileurl,
116 $subscriber->getBestName(),
118 $other->getBestName());
119 $content = sprintf(_m('%s (%s) stopped following %s (%s).'),
120 $subscriber->getBestName(),
121 $subscriber->profileurl,
122 $other->getBestName(),
125 $uri = TagURI::mint('stop-following:%d:%d:%s',
128 common_date_iso8601(common_sql_now()));
130 $notice = Notice::saveNew($user->id,
133 array('rendered' => $rendered,
135 'verb' => ActivityVerb::UNFOLLOW,
136 'object_type' => ActivityObject::PERSON));
141 function onEndFavorNotice($profile, $notice)
143 // Only do this if config is enabled
144 if(!$this->StartLike) return true;
146 $user = $profile->getUser();
150 $author = $notice->getProfile();
151 $fave = Fave::pkeyGet(array('user_id' => $user->id,
152 'notice_id' => $notice->id));
154 $rendered = sprintf(_m('<em><a href="%s">%s</a> liked <a href="%s">%s\'s update</a></em>.'),
155 $profile->profileurl,
156 $profile->getBestName(),
158 $author->getBestName());
159 $content = sprintf(_m('%s (%s) liked %s\'s status (%s)'),
160 $profile->getBestName(),
161 $profile->profileurl,
162 $author->getBestName(),
165 $notice = Notice::saveNew($user->id,
168 array('rendered' => $rendered,
169 'uri' => $fave->getURI(),
170 'verb' => ActivityVerb::FAVORITE,
171 'object_type' => (($notice->verb == ActivityVerb::POST) ?
172 $notice->object_type : ActivityObject::ACTIVITY)));
177 function onEndDisfavorNotice($profile, $notice)
179 // Only do this if config is enabled
180 if(!$this->StopLike) return true;
181 $user = User::staticGet('id', $profile->id);
184 $author = Profile::staticGet('id', $notice->profile_id);
185 $rendered = sprintf(_m('<em><a href="%s">%s</a> stopped liking <a href="%s">%s\'s update</a></em>.'),
186 $profile->profileurl,
187 $profile->getBestName(),
189 $author->getBestName());
190 $content = sprintf(_m('%s (%s) stopped liking %s\'s status (%s)'),
191 $profile->getBestName(),
192 $profile->profileurl,
193 $author->getBestName(),
196 $uri = TagURI::mint('unlike:%d:%d:%s',
199 common_date_iso8601(common_sql_now()));
201 $notice = Notice::saveNew($user->id,
204 array('rendered' => $rendered,
206 'verb' => ActivityVerb::UNFAVORITE,
207 'object_type' => (($notice->verb == ActivityVerb::POST) ?
208 $notice->object_type : ActivityObject::ACTIVITY)));
213 function onEndJoinGroup($group, $profile)
215 // Only do this if config is enabled
216 if(!$this->JoinGroup) return true;
218 $user = $profile->getUser();
224 $rendered = sprintf(_m('<em><a href="%s">%s</a> joined the group <a href="%s">%s</a></em>.'),
225 $profile->profileurl,
226 $profile->getBestName(),
228 $group->getBestName());
229 $content = sprintf(_m('%s (%s) joined the group %s (%s).'),
230 $profile->getBestName(),
231 $profile->profileurl,
232 $group->getBestName(),
235 $mem = Group_member::pkeyGet(array('group_id' => $group->id,
236 'profile_id' => $profile->id));
238 $notice = Notice::saveNew($user->id,
241 array('rendered' => $rendered,
242 'uri' => $mem->getURI(),
243 'verb' => ActivityVerb::JOIN,
244 'object_type' => ActivityObject::GROUP));
248 function onEndLeaveGroup($group, $profile)
250 // Only do this if config is enabled
251 if(!$this->LeaveGroup) return true;
253 $user = $profile->getUser();
259 $rendered = sprintf(_m('<em><a href="%s">%s</a> left the group <a href="%s">%s</a></em>.'),
260 $profile->profileurl,
261 $profile->getBestName(),
263 $group->getBestName());
264 $content = sprintf(_m('%s (%s) left the group %s (%s)'),
265 $profile->getBestName(),
266 $profile->profileurl,
267 $group->getBestName(),
270 $uri = TagURI::mint('leave:%d:%d:%s',
273 common_date_iso8601(common_sql_now()));
275 $notice = Notice::saveNew($user->id,
278 array('rendered' => $rendered,
280 'verb' => ActivityVerb::LEAVE,
281 'object_type' => ActivityObject::GROUP));
285 function onStartShowNoticeItem($nli)
287 $notice = $nli->notice;
291 switch ($notice->verb) {
292 case ActivityVerb::JOIN:
293 $adapter = new JoinListItem($nli);
295 case ActivityVerb::LEAVE:
296 $adapter = new JoinListItem($nli);
298 case ActivityVerb::FOLLOW:
299 $adapter = new FollowListItem($nli);
301 case ActivityVerb::UNFOLLOW:
302 $adapter = new UnfollowListItem($nli);
306 if (!empty($adapter)) {
307 $adapter->showNotice();
308 $adapter->showNoticeAttachments();
309 $adapter->showNoticeInfo();
310 $adapter->showNoticeOptions();
317 function onEndNoticeAsActivity($notice, &$activity)
322 function onPluginVersion(&$versions)
324 $versions[] = array('name' => 'Activity',
325 'version' => self::VERSION,
326 'author' => 'Evan Prodromou',
327 'homepage' => 'http://status.net/wiki/Plugin:Activity',
329 _m('Emits notices when social activities happen.'));