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__);
67 include_once $dir . '/'.strtolower($cls).'.php';
74 function onEndSubscribe($subscriber, $other)
76 // Only do this if config is enabled
77 if(!$this->StartFollowUser) return true;
78 $user = $subscriber->getUser();
80 $sub = Subscription::pkeyGet(array('subscriber' => $subscriber->id,
81 'subscribed' => $other->id));
82 $rendered = sprintf(_m('<em><a href="%s">%s</a> started following <a href="%s">%s</a></em>.'),
83 $subscriber->profileurl,
84 $subscriber->getBestName(),
86 $other->getBestName());
87 $content = sprintf(_m('%s (%s) started following %s (%s).'),
88 $subscriber->getBestName(),
89 $subscriber->profileurl,
90 $other->getBestName(),
93 $notice = Notice::saveNew($user->id,
96 array('rendered' => $rendered,
97 'verb' => ActivityVerb::FOLLOW,
98 'object_type' => ActivityObject::PERSON,
104 function onEndUnsubscribe($subscriber, $other)
106 // Only do this if config is enabled
107 if(!$this->StopFollowUser) return true;
108 $user = $subscriber->getUser();
110 $rendered = sprintf(_m('<em><a href="%s">%s</a> stopped following <a href="%s">%s</a></em>.'),
111 $subscriber->profileurl,
112 $subscriber->getBestName(),
114 $other->getBestName());
115 $content = sprintf(_m('%s (%s) stopped following %s (%s).'),
116 $subscriber->getBestName(),
117 $subscriber->profileurl,
118 $other->getBestName(),
121 $uri = TagURI::mint('stop-following:%d:%d:%s',
124 common_date_iso8601(common_sql_now()));
126 $notice = Notice::saveNew($user->id,
129 array('rendered' => $rendered,
131 'verb' => ActivityVerb::UNFOLLOW,
132 'object_type' => ActivityObject::PERSON));
137 function onEndFavorNotice($profile, $notice)
139 // Only do this if config is enabled
140 if(!$this->StartLike) return true;
142 $user = $profile->getUser();
146 $author = $notice->getProfile();
147 $fave = Fave::pkeyGet(array('user_id' => $user->id,
148 'notice_id' => $notice->id));
150 $rendered = sprintf(_m('<em><a href="%s">%s</a> liked <a href="%s">%s\'s update</a></em>.'),
151 $profile->profileurl,
152 $profile->getBestName(),
154 $author->getBestName());
155 $content = sprintf(_m('%s (%s) liked %s\'s status (%s)'),
156 $profile->getBestName(),
157 $profile->profileurl,
158 $author->getBestName(),
161 $notice = Notice::saveNew($user->id,
164 array('rendered' => $rendered,
165 'uri' => $fave->getURI(),
166 'verb' => ActivityVerb::FAVORITE,
167 'object_type' => (($notice->verb == ActivityVerb::POST) ?
168 $notice->object_type : ActivityObject::ACTIVITY)));
173 function onEndDisfavorNotice($profile, $notice)
175 // Only do this if config is enabled
176 if(!$this->StopLike) return true;
177 $user = User::staticGet('id', $profile->id);
180 $author = Profile::staticGet('id', $notice->profile_id);
181 $rendered = sprintf(_m('<em><a href="%s">%s</a> stopped liking <a href="%s">%s\'s update</a></em>.'),
182 $profile->profileurl,
183 $profile->getBestName(),
185 $author->getBestName());
186 $content = sprintf(_m('%s (%s) stopped liking %s\'s status (%s)'),
187 $profile->getBestName(),
188 $profile->profileurl,
189 $author->getBestName(),
192 $uri = TagURI::mint('unlike:%d:%d:%s',
195 common_date_iso8601(common_sql_now()));
197 $notice = Notice::saveNew($user->id,
200 array('rendered' => $rendered,
202 'verb' => ActivityVerb::UNFAVORITE,
203 'object_type' => (($notice->verb == ActivityVerb::POST) ?
204 $notice->object_type : ActivityObject::ACTIVITY)));
209 function onEndJoinGroup($group, $profile)
211 // Only do this if config is enabled
212 if(!$this->JoinGroup) return true;
214 $user = $profile->getUser();
220 $rendered = sprintf(_m('<em><a href="%s">%s</a> joined the group <a href="%s">%s</a></em>.'),
221 $profile->profileurl,
222 $profile->getBestName(),
224 $group->getBestName());
225 $content = sprintf(_m('%s (%s) joined the group %s (%s).'),
226 $profile->getBestName(),
227 $profile->profileurl,
228 $group->getBestName(),
231 $mem = Group_member::pkeyGet(array('group_id' => $group->id,
232 'profile_id' => $profile->id));
234 $notice = Notice::saveNew($user->id,
237 array('rendered' => $rendered,
238 'uri' => $mem->getURI(),
239 'verb' => ActivityVerb::JOIN,
240 'object_type' => ActivityObject::GROUP));
244 function onEndLeaveGroup($group, $profile)
246 // Only do this if config is enabled
247 if(!$this->LeaveGroup) return true;
249 $user = $profile->getUser();
255 $rendered = sprintf(_m('<em><a href="%s">%s</a> left the group <a href="%s">%s</a></em>.'),
256 $profile->profileurl,
257 $profile->getBestName(),
259 $group->getBestName());
260 $content = sprintf(_m('%s (%s) left the group %s (%s)'),
261 $profile->getBestName(),
262 $profile->profileurl,
263 $group->getBestName(),
266 $uri = TagURI::mint('leave:%d:%d:%s',
269 common_date_iso8601(common_sql_now()));
271 $notice = Notice::saveNew($user->id,
274 array('rendered' => $rendered,
276 'verb' => ActivityVerb::LEAVE,
277 'object_type' => ActivityObject::GROUP));
281 function onStartShowNoticeItem($nli)
283 $notice = $nli->notice;
287 switch ($notice->verb) {
288 case ActivityVerb::JOIN:
289 $adapter = new JoinListItem($nli);
293 if (!empty($adapter)) {
294 $adapter->showNotice();
295 $adapter->showNoticeAttachments();
296 $adapter->showNoticeInfo();
297 $adapter->showNoticeOptions();
304 function onEndNoticeAsActivity($notice, &$activity)
309 function onPluginVersion(&$versions)
311 $versions[] = array('name' => 'Activity',
312 'version' => self::VERSION,
313 'author' => 'Evan Prodromou',
314 'homepage' => 'http://status.net/wiki/Plugin:Activity',
316 _m('Emits notices when social activities happen.'));