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';
53 * Database schema setup
58 * @return boolean hook value; true means continue processing, false means stop.
61 function onCheckSchema()
63 $schema = Schema::get();
65 // For storing the activity part of a notice
67 $schema->ensureTable('notice_activity',
68 array(new ColumnDef('notice_id', 'integer', null,
70 new ColumnDef('verb', 'varchar', 255,
72 new ColumnDef('object', 'varchar', 255,
78 function onAutoload($cls)
80 $dir = dirname(__FILE__);
84 case 'Notice_activity':
85 include_once $dir . '/'.$cls.'.php';
92 function onEndSubscribe($subscriber, $other)
94 $user = User::staticGet('id', $subscriber->id);
96 $rendered = sprintf(_m('<em>Started following <a href="%s">%s</a></em>.'),
98 $other->getBestName());
99 $content = sprintf(_m('Started following %s.'),
100 $other->getBestName());
102 $notice = Notice::saveNew($user->id,
105 array('rendered' => $rendered));
107 Notice_activity::setActivity($notice->id,
108 ActivityVerb::FOLLOW,
114 function onEndUnsubscribe($subscriber, $other)
116 $user = User::staticGet('id', $subscriber->id);
118 $rendered = sprintf(_m('<em>Stopped following <a href="%s">%s</a></em>.'),
120 $other->getBestName());
121 $content = sprintf(_m('Stopped following %s.'),
122 $other->getBestName());
124 $notice = Notice::saveNew($user->id,
127 array('rendered' => $rendered));
129 Notice_activity::setActivity($notice->id,
130 ActivityVerb::UNFOLLOW,
136 function onEndFavorNotice($profile, $notice)
138 $user = User::staticGet('id', $profile->id);
141 $author = Profile::staticGet('id', $notice->profile_id);
142 $rendered = sprintf(_m('<em>Liked <a href="%s">%s\'s status</a></em>.'),
144 $author->getBestName());
145 $content = sprintf(_m('Liked %s\'s status.'),
146 $author->getBestName());
148 $notice = Notice::saveNew($user->id,
151 array('rendered' => $rendered));
153 Notice_activity::setActivity($notice->id,
154 ActivityVerb::FAVORITE,
160 function onEndDisfavorNotice($profile, $notice)
162 $user = User::staticGet('id', $profile->id);
165 $author = Profile::staticGet('id', $notice->profile_id);
166 $rendered = sprintf(_m('<em>Stopped liking <a href="%s">%s\'s status</a></em>.'),
168 $author->getBestName());
169 $content = sprintf(_m('Stopped liking %s\'s status.'),
170 $author->getBestName());
172 $notice = Notice::saveNew($user->id,
175 array('rendered' => $rendered));
177 Notice_activity::setActivity($notice->id,
178 ActivityVerb::UNFAVORITE,
184 function onEndJoinGroup($group, $user)
186 $rendered = sprintf(_m('<em>Joined the group "<a href="%s">%s</a>"</em>.'),
188 $group->getBestName());
189 $content = sprintf(_m('Joined the group %s.'),
190 $group->getBestName());
192 $notice = Notice::saveNew($user->id,
195 array('rendered' => $rendered));
197 Notice_activity::setActivity($notice->id,
203 function onEndLeaveGroup($group, $user)
205 $rendered = sprintf(_m('<em>Left the group "<a href="%s">%s</a>"</em>.'),
207 $group->getBestName());
208 $content = sprintf(_m('Left the group "%s".'),
209 $group->getBestName());
211 $notice = Notice::saveNew($user->id,
214 array('rendered' => $rendered));
216 Notice_activity::setActivity($notice->id,
222 function onStartActivityVerb(&$notice, &$xs, &$verb)
224 $act = Notice_activity::staticGet('notice_id', $notice->id);
233 function onStartActivityDefaultObjectType(&$notice, &$xs, &$type)
235 $act = Notice_activity::staticGet('notice_id', $notice->id);
245 function onStartActivityObjects(&$notice, &$xs, &$objects)
247 $act = Notice_activity::staticGet('notice_id', $notice->id);
252 case ActivityVerb::FOLLOW:
253 case ActivityVerb::UNFOLLOW:
254 $profile = Profile::fromURI($act->object);
255 if (!empty($profile)) {
256 $objects[] = ActivityObject::fromProfile($profile);
259 case ActivityVerb::FAVORITE:
260 case ActivityVerb::UNFAVORITE:
261 $notice = Notice::staticGet('uri', $act->object);
262 if (!empty($notice)) {
263 $objects[] = $notice->asActivity();
266 case ActivityVerb::JOIN:
267 case ActivityVerb::LEAVE:
268 $group = User_group::staticGet('uri', $act->object);
269 if (!empty($notice)) {
270 $objects[] = ActivityObject::fromGroup($group);
280 function onPluginVersion(&$versions)
282 $versions[] = array('name' => 'Activity',
283 'version' => self::VERSION,
284 'author' => 'Evan Prodromou',
285 'homepage' => 'http://status.net/wiki/Plugin:Activity',
287 _m('Emits notices when social activities happen.'));