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',
39 array('action' => 'addmirror'));
40 $m->connect('settings/mirror/edit',
41 array('action' => 'editmirror'));
46 * Automatically load the actions and libraries used by the plugin
48 * @param Class $cls the class
50 * @return boolean hook return
53 function onAutoload($cls)
55 $base = dirname(__FILE__);
56 $lower = strtolower($cls);
57 $files = array("$base/lib/$lower.php",
58 "$base/classes/$cls.php");
59 if (substr($lower, -6) == 'action') {
60 $files[] = "$base/actions/" . substr($lower, 0, -6) . ".php";
62 foreach ($files as $file) {
63 if (file_exists($file)) {
71 function handle($notice)
73 // Is anybody mirroring?
74 $mirror = new SubMirror();
75 $mirror->subscribed = $notice->profile_id;
76 if ($mirror->find()) {
77 while ($mirror->fetch()) {
78 $mirror->repeat($notice);
83 function onPluginVersion(&$versions)
85 $versions[] = array('name' => 'SubMirror',
86 'version' => STATUSNET_VERSION,
87 'author' => 'Brion Vibber',
88 'homepage' => 'http://status.net/wiki/Plugin:SubMirror',
90 _m('Pull feeds into your timeline!'));
96 * Menu item for settings
98 * @param Action &$action Action being executed
100 * @return boolean hook return
103 function onEndAccountSettingsNav(&$action)
105 $action_name = $action->trimmed('action');
107 $action->menuItem(common_local_url('mirrorsettings'),
108 // TRANS: SubMirror plugin menu item on user settings page.
109 _m('MENU', 'Mirroring'),
110 // TRANS: SubMirror plugin tooltip for user settings menu item.
111 _m('Configure mirroring of posts from other feeds'),
112 $action_name === 'mirrorsettings');
117 function onCheckSchema()
119 $schema = Schema::get();
120 $schema->ensureTable('submirror', SubMirror::schemaDef());
122 // @hack until key definition support is merged
123 SubMirror::fixIndexes($schema);
128 * Set up queue handlers for outgoing hub pushes
129 * @param QueueManager $qm
130 * @return boolean hook return
132 function onEndInitializeQueueManager(QueueManager $qm)
134 // After each notice save, check if there's any repeat mirrors.
135 $qm->connect('mirror', 'MirrorQueueHandler');
139 function onStartEnqueueNotice($notice, &$transports)
141 $transports[] = 'mirror';
145 * Let the OStatus subscription garbage collection know if we're
146 * making use of a remote feed, so it doesn't get dropped out
149 * @param Ostatus_profile $oprofile
150 * @param int $count in/out
151 * @return mixed hook return value
153 function onOstatus_profileSubscriberCount($oprofile, &$count)
155 if ($oprofile->profile_id) {
156 $mirror = new SubMirror();
157 $mirror->subscribed = $oprofile->profile_id;
158 if ($mirror->find()) {
159 while ($mirror->fetch()) {