]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/TagSub/TagSubPlugin.php
Stub TagSubPlugin: plugin guts with no UI to setup subs
[quix0rs-gnu-social.git] / plugins / TagSub / TagSubPlugin.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2011, StatusNet, Inc.
5  *
6  * A plugin to enable local tab subscription
7  *
8  * PHP version 5
9  *
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.
14  *
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.
19  *
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/>.
22  *
23  * @category  TagSubPlugin
24  * @package   StatusNet
25  * @author    Brion Vibber <brion@status.net>
26  * @copyright 2011 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('STATUSNET')) {
32     exit(1);
33 }
34
35 /**
36  * TagSub plugin main class
37  *
38  * @category  TagSubPlugin
39  * @package   StatusNet
40  * @author    Brion Vibber <brionv@status.net>
41  * @copyright 2011 StatusNet, Inc.
42  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
43  * @link      http://status.net/
44  */
45 class TagSubPlugin extends Plugin
46 {
47     const VERSION         = '0.1';
48
49     /**
50      * Database schema setup
51      *
52      * @see Schema
53      *
54      * @return boolean hook value; true means continue processing, false means stop.
55      */
56     function onCheckSchema()
57     {
58         $schema = Schema::get();
59         $schema->ensureTable('tagsub', TagSub::schemaDef());
60         return true;
61     }
62
63     /**
64      * Load related modules when needed
65      *
66      * @param string $cls Name of the class to be loaded
67      *
68      * @return boolean hook value; true means continue processing, false means stop.
69      */
70     function onAutoload($cls)
71     {
72         $dir = dirname(__FILE__);
73
74         switch ($cls)
75         {
76         case 'TagsubAction':
77         case 'TagunsubAction':
78             include_once $dir . '/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
79             return false;
80         case 'TagSub':
81             include_once $dir.'/'.$cls.'.php';
82             return false;
83         case 'TagSubForm':
84         case 'TagUnsubForm':
85             include_once $dir.'/'.strtolower($cls).'.php';
86             return false;
87         default:
88             return true;
89         }
90     }
91
92     /**
93      * Map URLs to actions
94      *
95      * @param Net_URL_Mapper $m path-to-action mapper
96      *
97      * @return boolean hook value; true means continue processing, false means stop.
98      */
99     function onRouterInitialized($m)
100     {
101         $m->connect('tag/:tag/subscribe',
102                     array('action' => 'tagsub'),
103                     array('tag' => Router::REGEX_TAG));
104         $m->connect('tag/:tag/unsubscribe',
105                     array('action' => 'tagunsub'),
106                     array('tag' => Router::REGEX_TAG));
107
108         return true;
109     }
110
111     /**
112      * Plugin version data
113      *
114      * @param array &$versions array of version data
115      *
116      * @return value
117      */
118     function onPluginVersion(&$versions)
119     {
120         $versions[] = array('name' => 'TagSub',
121                             'version' => self::VERSION,
122                             'author' => 'Brion Vibber',
123                             'homepage' => 'http://status.net/wiki/Plugin:TagSub',
124                             'rawdescription' =>
125                             // TRANS: Plugin description.
126                             _m('Plugin to allow following all messages with a given tag.'));
127         return true;
128     }
129
130     /**
131      * Hook inbox delivery setup so tag subscribers receive all
132      * notices with that tag in their inbox.
133      *
134      * Currently makes no distinction between local messages and
135      * remote ones which happen to come in to the system. Remote
136      * notices that don't come in at all won't ever reach this.
137      *
138      * @param Notice $notice
139      * @param array $ni in/out map of profile IDs to inbox constants
140      * @return boolean hook result
141      */
142     function onStartNoticeWhoGets(Notice $notice, array &$ni)
143     {
144         foreach ($notice->getTags() as $tag) {
145             $tagsub = new TagSub();
146             $tagsub->tag = $tag;
147             $tagsub->find();
148
149             while ($tagsub->fetch()) {
150                 // These constants are currently not actually used, iirc
151                 $ni[$tagsub->profile_id] = NOTICE_INBOX_SOURCE_SUB;
152             }
153         }
154         return true;
155     }
156 }