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 include_once $dir . '/'.strtolower($cls).'.php';
77 function onEndSubscribe($subscriber, $other)
79 // Only do this if config is enabled
80 if(!$this->StartFollowUser) return true;
81 $user = $subscriber->getUser();
83 $sub = Subscription::pkeyGet(array('subscriber' => $subscriber->id,
84 'subscribed' => $other->id));
85 $rendered = sprintf(_m('<em><a href="%s">%s</a> started following <a href="%s">%s</a></em>.'),
86 $subscriber->profileurl,
87 $subscriber->getBestName(),
89 $other->getBestName());
90 $content = sprintf(_m('%s (%s) started following %s (%s).'),
91 $subscriber->getBestName(),
92 $subscriber->profileurl,
93 $other->getBestName(),
96 $notice = Notice::saveNew($user->id,
99 array('rendered' => $rendered,
100 'verb' => ActivityVerb::FOLLOW,
101 'object_type' => ActivityObject::PERSON,
102 'uri' => $sub->uri));
107 function onEndUnsubscribe($subscriber, $other)
109 // Only do this if config is enabled
110 if(!$this->StopFollowUser) return true;
111 $user = $subscriber->getUser();
113 $rendered = sprintf(_m('<em><a href="%s">%s</a> stopped following <a href="%s">%s</a></em>.'),
114 $subscriber->profileurl,
115 $subscriber->getBestName(),
117 $other->getBestName());
118 $content = sprintf(_m('%s (%s) stopped following %s (%s).'),
119 $subscriber->getBestName(),
120 $subscriber->profileurl,
121 $other->getBestName(),
124 $uri = TagURI::mint('stop-following:%d:%d:%s',
127 common_date_iso8601(common_sql_now()));
129 $notice = Notice::saveNew($user->id,
132 array('rendered' => $rendered,
134 'verb' => ActivityVerb::UNFOLLOW,
135 'object_type' => ActivityObject::PERSON));
140 function onEndFavorNotice($profile, $notice)
142 // Only do this if config is enabled
143 if(!$this->StartLike) return true;
145 $user = $profile->getUser();
149 $author = $notice->getProfile();
150 $fave = Fave::pkeyGet(array('user_id' => $user->id,
151 'notice_id' => $notice->id));
153 $rendered = sprintf(_m('<em><a href="%s">%s</a> liked <a href="%s">%s\'s update</a></em>.'),
154 $profile->profileurl,
155 $profile->getBestName(),
157 $author->getBestName());
158 $content = sprintf(_m('%s (%s) liked %s\'s status (%s)'),
159 $profile->getBestName(),
160 $profile->profileurl,
161 $author->getBestName(),
164 $notice = Notice::saveNew($user->id,
167 array('rendered' => $rendered,
168 'uri' => $fave->getURI(),
169 'verb' => ActivityVerb::FAVORITE,
170 'object_type' => (($notice->verb == ActivityVerb::POST) ?
171 $notice->object_type : ActivityObject::ACTIVITY)));
176 function onEndDisfavorNotice($profile, $notice)
178 // Only do this if config is enabled
179 if(!$this->StopLike) return true;
180 $user = User::staticGet('id', $profile->id);
183 $author = Profile::staticGet('id', $notice->profile_id);
184 $rendered = sprintf(_m('<em><a href="%s">%s</a> stopped liking <a href="%s">%s\'s update</a></em>.'),
185 $profile->profileurl,
186 $profile->getBestName(),
188 $author->getBestName());
189 $content = sprintf(_m('%s (%s) stopped liking %s\'s status (%s)'),
190 $profile->getBestName(),
191 $profile->profileurl,
192 $author->getBestName(),
195 $uri = TagURI::mint('unlike:%d:%d:%s',
198 common_date_iso8601(common_sql_now()));
200 $notice = Notice::saveNew($user->id,
203 array('rendered' => $rendered,
205 'verb' => ActivityVerb::UNFAVORITE,
206 'object_type' => (($notice->verb == ActivityVerb::POST) ?
207 $notice->object_type : ActivityObject::ACTIVITY)));
212 function onEndJoinGroup($group, $profile)
214 // Only do this if config is enabled
215 if(!$this->JoinGroup) return true;
217 $user = $profile->getUser();
223 $rendered = sprintf(_m('<em><a href="%s">%s</a> joined the group <a href="%s">%s</a></em>.'),
224 $profile->profileurl,
225 $profile->getBestName(),
227 $group->getBestName());
228 $content = sprintf(_m('%s (%s) joined the group %s (%s).'),
229 $profile->getBestName(),
230 $profile->profileurl,
231 $group->getBestName(),
234 $mem = Group_member::pkeyGet(array('group_id' => $group->id,
235 'profile_id' => $profile->id));
237 $notice = Notice::saveNew($user->id,
240 array('rendered' => $rendered,
241 'uri' => $mem->getURI(),
242 'verb' => ActivityVerb::JOIN,
243 'object_type' => ActivityObject::GROUP));
247 function onEndLeaveGroup($group, $profile)
249 // Only do this if config is enabled
250 if(!$this->LeaveGroup) return true;
252 $user = $profile->getUser();
258 $rendered = sprintf(_m('<em><a href="%s">%s</a> left the group <a href="%s">%s</a></em>.'),
259 $profile->profileurl,
260 $profile->getBestName(),
262 $group->getBestName());
263 $content = sprintf(_m('%s (%s) left the group %s (%s)'),
264 $profile->getBestName(),
265 $profile->profileurl,
266 $group->getBestName(),
269 $uri = TagURI::mint('leave:%d:%d:%s',
272 common_date_iso8601(common_sql_now()));
274 $notice = Notice::saveNew($user->id,
277 array('rendered' => $rendered,
279 'verb' => ActivityVerb::LEAVE,
280 'object_type' => ActivityObject::GROUP));
284 function onStartShowNoticeItem($nli)
286 $notice = $nli->notice;
290 switch ($notice->verb) {
291 case ActivityVerb::JOIN:
292 $adapter = new JoinListItem($nli);
294 case ActivityVerb::LEAVE:
295 $adapter = new JoinListItem($nli);
297 case ActivityVerb::FOLLOW:
298 $adapter = new FollowListItem($nli);
300 case ActivityVerb::UNFOLLOW:
301 $adapter = new UnfollowListItem($nli);
305 if (!empty($adapter)) {
306 $adapter->showNotice();
307 $adapter->showNoticeAttachments();
308 $adapter->showNoticeInfo();
309 $adapter->showNoticeOptions();
316 function onEndNoticeAsActivity($notice, &$activity)
321 function onPluginVersion(&$versions)
323 $versions[] = array('name' => 'Activity',
324 'version' => self::VERSION,
325 'author' => 'Evan Prodromou',
326 'homepage' => 'http://status.net/wiki/Plugin:Activity',
328 _m('Emits notices when social activities happen.'));