]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/SubMirror/SubMirrorPlugin.php
SubMirror plugin initial checkin: allows setting up automatic mirroring of posts...
[quix0rs-gnu-social.git] / plugins / SubMirror / SubMirrorPlugin.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2009-2010, StatusNet, Inc.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 /**
21  * @package SubMirrorPlugin
22  * @maintainer Brion Vibber <brion@status.net>
23  */
24
25 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
26
27
28 class SubMirrorPlugin extends Plugin
29 {
30     /**
31      * Hook for RouterInitialized event.
32      *
33      * @param Net_URL_Mapper $m path-to-action mapper
34      * @return boolean hook return
35      */
36     function onRouterInitialized($m)
37     {
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'));
44         return true;
45     }
46
47     /**
48      * Automatically load the actions and libraries used by the plugin
49      *
50      * @param Class $cls the class
51      *
52      * @return boolean hook return
53      *
54      */
55     function onAutoload($cls)
56     {
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";
63         }
64         foreach ($files as $file) {
65             if (file_exists($file)) {
66                 include_once $file;
67                 return false;
68             }
69         }
70         return true;
71     }
72
73     function handle($notice)
74     {
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);
81             }
82         }
83     }
84
85     function onPluginVersion(&$versions)
86     {
87         $versions[] = array('name' => 'SubMirror',
88                             'version' => STATUSNET_VERSION,
89                             'author' => 'Brion Vibber',
90                             'homepage' => 'http://status.net/wiki/Plugin:SubMirror',
91                             'rawdescription' =>
92                             _m('Pull feeds into your timeline!'));
93
94         return true;
95     }
96
97     /**
98      * Menu item for settings
99      *
100      * @param Action &$action Action being executed
101      *
102      * @return boolean hook return
103      */
104
105     function onEndAccountSettingsNav(&$action)
106     {
107         $action_name = $action->trimmed('action');
108
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');
115
116         return true;
117     }
118
119     function onCheckSchema()
120     {
121         $schema = Schema::get();
122         $schema->ensureTable('submirror', SubMirror::schemaDef());
123         return true;
124     }
125
126     /**
127      * Set up queue handlers for outgoing hub pushes
128      * @param QueueManager $qm
129      * @return boolean hook return
130      */
131     function onEndInitializeQueueManager(QueueManager $qm)
132     {
133         // After each notice save, check if there's any repeat mirrors.
134         $qm->connect('mirror', 'MirrorQueueHandler');
135         return true;
136     }
137
138     function onStartEnqueueNotice($notice, &$transports)
139     {
140         $transports[] = 'mirror';
141     }
142
143     function onStartShowSubscriptionsContent($action)
144     {
145         $action->element('a',
146                          array('href' => common_local_url('mirrorsettings')),
147                          _m('Set up mirroring options...'));
148     }
149 }