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;
61 * Database schema setup
66 * @return boolean hook value; true means continue processing, false means stop.
69 function onCheckSchema()
71 $schema = Schema::get();
73 // For storing the activity part of a notice
75 $schema->ensureTable('notice_activity',
76 array(new ColumnDef('notice_id', 'integer', null,
78 new ColumnDef('verb', 'varchar', 255,
80 new ColumnDef('object', 'varchar', 255,
86 function onAutoload($cls)
88 $dir = dirname(__FILE__);
92 case 'Notice_activity':
93 include_once $dir . '/'.$cls.'.php';
100 function onEndSubscribe($subscriber, $other)
102 // Only do this if config is enabled
103 if(!$this->StartFollowUser) return true;
104 $user = User::staticGet('id', $subscriber->id);
106 $rendered = sprintf(_m('<em>Started following <a href="%s">%s</a></em>.'),
108 $other->getBestName());
109 $content = sprintf(_m('Started following %s : %s'),
110 $other->getBestName(),
113 $notice = Notice::saveNew($user->id,
116 array('rendered' => $rendered));
118 Notice_activity::setActivity($notice->id,
119 ActivityVerb::FOLLOW,
125 function onEndUnsubscribe($subscriber, $other)
127 // Only do this if config is enabled
128 if(!$this->StopFollowUser) return true;
129 $user = User::staticGet('id', $subscriber->id);
131 $rendered = sprintf(_m('<em>Stopped following <a href="%s">%s</a></em>.'),
133 $other->getBestName());
134 $content = sprintf(_m('Stopped following %s : %s'),
135 $other->getBestName(),
138 $notice = Notice::saveNew($user->id,
141 array('rendered' => $rendered));
143 Notice_activity::setActivity($notice->id,
144 ActivityVerb::UNFOLLOW,
150 function onEndFavorNotice($profile, $notice)
152 // Only do this if config is enabled
153 if(!$this->StartLike) return true;
154 $user = User::staticGet('id', $profile->id);
157 $author = Profile::staticGet('id', $notice->profile_id);
158 $rendered = sprintf(_m('<em>Liked <a href="%s">%s\'s status</a></em>.'),
160 $author->getBestName());
161 $content = sprintf(_m('Liked %s\'s status: %s'),
162 $author->getBestName(),
165 $notice = Notice::saveNew($user->id,
168 array('rendered' => $rendered));
170 Notice_activity::setActivity($notice->id,
171 ActivityVerb::FAVORITE,
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>Stopped liking <a href="%s">%s\'s status</a></em>.'),
187 $author->getBestName());
188 $content = sprintf(_m('Stopped liking %s\'s status: %s'),
189 $author->getBestName(),
192 $notice = Notice::saveNew($user->id,
195 array('rendered' => $rendered));
197 Notice_activity::setActivity($notice->id,
198 ActivityVerb::UNFAVORITE,
204 function onEndJoinGroup($group, $user)
206 // Only do this if config is enabled
207 if(!$this->JoinGroup) return true;
208 $rendered = sprintf(_m('<em>Joined the group "<a href="%s">%s</a>"</em>.'),
210 $group->getBestName());
211 $content = sprintf(_m('Joined the group %s : %s'),
212 $group->getBestName(),
215 $notice = Notice::saveNew($user->id,
218 array('rendered' => $rendered));
220 Notice_activity::setActivity($notice->id,
226 function onEndLeaveGroup($group, $user)
228 // Only do this if config is enabled
229 if(!$this->LeaveGroup) return true;
230 $rendered = sprintf(_m('<em>Left the group "<a href="%s">%s</a>"</em>.'),
232 $group->getBestName());
233 $content = sprintf(_m('Left the group "%s" : %s'),
234 $group->getBestName(),
237 $notice = Notice::saveNew($user->id,
240 array('rendered' => $rendered));
242 Notice_activity::setActivity($notice->id,
248 function onEndNoticeAsActivity($notice, &$activity)
250 $na = Notice_activity::staticGet('notice_id', $notice->id);
254 $activity->verb = $na->verb;
256 // wipe the old object!
258 $activity->objects = array();
262 case ActivityVerb::FOLLOW:
263 case ActivityVerb::UNFOLLOW:
264 $profile = Profile::fromURI($na->object);
265 if (!empty($profile)) {
266 $activity->objects[] = ActivityObject::fromProfile($profile);
269 case ActivityVerb::FAVORITE:
270 case ActivityVerb::UNFAVORITE:
271 $target = Notice::staticGet('uri', $na->object);
272 if (!empty($target)) {
273 $activity->objects[] = ActivityObject::fromNotice($target);
276 case ActivityVerb::JOIN:
277 case ActivityVerb::LEAVE:
278 $group = User_group::staticGet('uri', $na->object);
279 if (!empty($notice)) {
280 $activity->objects[] = ActivityObject::fromGroup($group);
292 function onPluginVersion(&$versions)
294 $versions[] = array('name' => 'Activity',
295 'version' => self::VERSION,
296 'author' => 'Evan Prodromou',
297 'homepage' => 'http://status.net/wiki/Plugin:Activity',
299 _m('Emits notices when social activities happen.'));