3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2009-2010, StatusNet, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
23 * @package SubMirrorPlugin
24 * @maintainer Brion Vibber <brion@status.net>
26 class SubMirrorPlugin extends Plugin
29 * Hook for RouterInitialized event.
31 * @param Net_URL_Mapper $m path-to-action mapper
32 * @return boolean hook return
34 function onRouterInitialized($m)
36 $m->connect('settings/mirror',
37 array('action' => 'mirrorsettings'));
38 $m->connect('settings/mirror/add/:provider',
39 array('action' => 'mirrorsettings'),
40 array('provider' => '[A-Za-z0-9_-]+'));
41 $m->connect('settings/mirror/add',
42 array('action' => 'addmirror'));
43 $m->connect('settings/mirror/edit',
44 array('action' => 'editmirror'));
49 * Automatically load the actions and libraries used by the plugin
51 * @param Class $cls the class
53 * @return boolean hook return
56 function onAutoload($cls)
58 $base = dirname(__FILE__);
59 $lower = strtolower($cls);
60 $files = array("$base/lib/$lower.php",
61 "$base/classes/$cls.php");
62 if (substr($lower, -6) == 'action') {
63 $files[] = "$base/actions/" . substr($lower, 0, -6) . ".php";
65 foreach ($files as $file) {
66 if (file_exists($file)) {
74 function handle($notice)
76 // Is anybody mirroring?
77 $mirror = new SubMirror();
78 $mirror->subscribed = $notice->profile_id;
79 if ($mirror->find()) {
80 while ($mirror->fetch()) {
81 $mirror->repeat($notice);
86 function onPluginVersion(&$versions)
88 $versions[] = array('name' => 'SubMirror',
89 'version' => STATUSNET_VERSION,
90 'author' => 'Brion Vibber',
91 'homepage' => 'http://status.net/wiki/Plugin:SubMirror',
93 // TRANS: Plugin description.
94 _m('Pull feeds into your timeline!'));
100 * Menu item for personal subscriptions/groups area
102 * @param Action $action action being executed
104 * @return boolean hook return
106 function onEndAccountSettingsNav($action)
108 $action_name = $action->trimmed('action');
110 common_debug("ACTION NAME = " . $action_name);
112 $action->menuItem(common_local_url('mirrorsettings'),
113 // TRANS: SubMirror plugin menu item on user settings page.
114 _m('MENU', 'Mirroring'),
115 // TRANS: SubMirror plugin tooltip for user settings menu item.
116 _m('Configure mirroring of posts from other feeds'),
117 $action_name === 'mirrorsettings');
122 function onCheckSchema()
124 $schema = Schema::get();
125 $schema->ensureTable('submirror', SubMirror::schemaDef());
127 // @hack until key definition support is merged
128 SubMirror::fixIndexes($schema);
133 * Set up queue handlers for outgoing hub pushes
134 * @param QueueManager $qm
135 * @return boolean hook return
137 function onEndInitializeQueueManager(QueueManager $qm)
139 // After each notice save, check if there's any repeat mirrors.
140 $qm->connect('mirror', 'MirrorQueueHandler');
144 function onStartEnqueueNotice($notice, &$transports)
146 $transports[] = 'mirror';
150 * Let the OStatus subscription garbage collection know if we're
151 * making use of a remote feed, so it doesn't get dropped out
154 * @param Ostatus_profile $oprofile
155 * @param int $count in/out
156 * @return mixed hook return value
158 function onOstatus_profileSubscriberCount($oprofile, &$count)
160 if (empty($oprofile) || !($oprofile instanceof Ostatus_profile)) {
164 if ($oprofile->profile_id) {
165 $mirror = new SubMirror();
166 $mirror->subscribed = $oprofile->profile_id;
167 if ($mirror->find()) {
168 while ($mirror->fetch()) {
178 * Add a count of mirrored feeds into a user's profile sidebar stats.
180 * @param Profile $profile
181 * @param array $stats
182 * @return boolean hook return value
184 function onProfileStats($profile, &$stats)
186 $cur = common_current_user();
187 if (!empty($cur) && $cur->id == $profile->id) {
188 $mirror = new SubMirror();
189 $mirror->subscriber = $profile->id;
192 // TRANS: Label in profile statistics section, followed by a count.
193 'label' => _m('Mirrored feeds'),
194 'link' => common_local_url('mirrorsettings'),
195 'value' => $mirror->count(),
198 $insertAt = count($stats);
199 foreach ($stats as $i => $row) {
200 if ($row['id'] == 'groups') {
201 // Slip us in after them.
206 array_splice($stats, $insertAt, 0, array($entry));