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/>.
21 * @package SubMirrorPlugin
22 * @maintainer Brion Vibber <brion@status.net>
25 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
28 class SubMirrorPlugin extends Plugin
31 * Hook for RouterInitialized event.
33 * @param Net_URL_Mapper $m path-to-action mapper
34 * @return boolean hook return
36 function onRouterInitialized($m)
38 $m->connect('settings/mirror',
39 array('action' => 'mirrorsettings'));
40 $m->connect('settings/mirror/add',
41 array('action' => 'addmirror'));
42 $m->connect('settings/mirror/edit',
43 array('action' => 'editmirror'));
48 * Automatically load the actions and libraries used by the plugin
50 * @param Class $cls the class
52 * @return boolean hook return
55 function onAutoload($cls)
57 $base = dirname(__FILE__);
58 $lower = strtolower($cls);
59 $files = array("$base/lib/$lower.php",
60 "$base/classes/$cls.php");
61 if (substr($lower, -6) == 'action') {
62 $files[] = "$base/actions/" . substr($lower, 0, -6) . ".php";
64 foreach ($files as $file) {
65 if (file_exists($file)) {
73 function handle($notice)
75 // Is anybody mirroring?
76 $mirror = new SubMirror();
77 $mirror->subscribed = $notice->profile_id;
78 if ($mirror->find()) {
79 while ($mirror->fetch()) {
80 $mirror->repeat($notice);
85 function onPluginVersion(&$versions)
87 $versions[] = array('name' => 'SubMirror',
88 'version' => STATUSNET_VERSION,
89 'author' => 'Brion Vibber',
90 'homepage' => 'http://status.net/wiki/Plugin:SubMirror',
92 _m('Pull feeds into your timeline!'));
98 * Menu item for settings
100 * @param Action &$action Action being executed
102 * @return boolean hook return
105 function onEndAccountSettingsNav(&$action)
107 $action_name = $action->trimmed('action');
109 $action->menuItem(common_local_url('mirrorsettings'),
110 // TRANS: SubMirror plugin menu item on user settings page.
111 _m('MENU', 'Mirroring'),
112 // TRANS: SubMirror plugin tooltip for user settings menu item.
113 _m('Configure mirroring of posts from other feeds'),
114 $action_name === 'mirrorsettings');
119 function onCheckSchema()
121 $schema = Schema::get();
122 $schema->ensureTable('submirror', SubMirror::schemaDef());
124 // @hack until key definition support is merged
125 SubMirror::fixIndexes($schema);
130 * Set up queue handlers for outgoing hub pushes
131 * @param QueueManager $qm
132 * @return boolean hook return
134 function onEndInitializeQueueManager(QueueManager $qm)
136 // After each notice save, check if there's any repeat mirrors.
137 $qm->connect('mirror', 'MirrorQueueHandler');
141 function onStartEnqueueNotice($notice, &$transports)
143 $transports[] = 'mirror';
147 * Let the OStatus subscription garbage collection know if we're
148 * making use of a remote feed, so it doesn't get dropped out
151 * @param Ostatus_profile $oprofile
152 * @param int $count in/out
153 * @return mixed hook return value
155 function onOstatus_profileSubscriberCount($oprofile, &$count)
157 if ($oprofile->profile_id) {
158 $mirror = new SubMirror();
159 $mirror->subscribed = $oprofile->profile_id;
160 if ($mirror->find()) {
161 while ($mirror->fetch()) {