]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/ModPlus/ModPlusPlugin.php
Merge commit 'refs/merge-requests/157' of git://gitorious.org/statusnet/mainline...
[quix0rs-gnu-social.git] / plugins / ModPlus / ModPlusPlugin.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 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 if (!defined('STATUSNET')) {
21     exit(1);
22 }
23
24 /**
25  * Some UI extras for now...
26  *
27  * @package ModPlusPlugin
28  * @maintainer Brion Vibber <brion@status.net>
29  */
30 class ModPlusPlugin extends Plugin
31 {
32     function onPluginVersion(&$versions)
33     {
34         $versions[] = array('name' => 'ModPlus',
35                             'version' => STATUSNET_VERSION,
36                             'author' => 'Brion Vibber',
37                             'homepage' => 'http://status.net/wiki/Plugin:ModPlus',
38                             'rawdescription' =>
39                             // TRANS: Plugin description.
40                             _m('UI extension for profile moderation actions.'));
41
42         return true;
43     }
44
45     /**
46      * Load JS at runtime if we're logged in.
47      *
48      * @param Action $action
49      * @return boolean hook result
50      */
51     function onEndShowScripts($action)
52     {
53         $user = common_current_user();
54         if ($user) {
55             $action->script($this->path('modplus.js'));
56         }
57         return true;
58     }
59
60     function onEndShowStatusNetStyles($action) {
61         $action->cssLink($this->path('modplus.css'));
62         return true;
63     }
64
65     /**
66      * Autoloader
67      *
68      * Loads our classes if they're requested.
69      *
70      * @param string $cls Class requested
71      *
72      * @return boolean hook return
73      */
74     function onAutoload($cls)
75     {
76         switch ($cls)
77         {
78         case 'RemoteprofileAction':
79         case 'RemoteProfileAction':
80             require_once dirname(__FILE__) . '/remoteprofileaction.php';
81             return false;
82         default:
83             return true;
84         }
85     }
86
87     /**
88      * Add ModPlus-related paths to the router table
89      *
90      * Hook for RouterInitialized event.
91      *
92      * @param Net_URL_Mapper $m URL mapper
93      *
94      * @return boolean hook return
95      */
96     function onStartInitializeRouter($m)
97     {
98         $m->connect('user/remote/:id',
99                 array('action' => 'remoteprofile'),
100                 array('id' => '[\d]+'));
101
102         return true;
103     }
104
105     /**
106      * Add per-profile info popup menu for author on notice lists.
107      *
108      * @param NoticeListItem $item
109      * @return boolean hook value
110      */
111     function onStartShowNoticeItem($item)
112     {
113         $this->showProfileOptions($item->out, $item->profile);
114         return true;
115     }
116
117     /**
118      * Add per-profile info popup menu on profile lists.
119      *
120      * @param ProfileListItem $item
121      */
122     function onStartProfileListItemProfile($item)
123     {
124         $this->showProfileOptions($item->out, $item->profile);
125         return true;
126     }
127
128     /**
129      * Build common remote-profile options structure.
130      * Currently only adds output for remote profiles, nothing for local users.
131      *
132      * @param HTMLOutputter $out
133      * @param Profile $profile (may also be an ArrayWrapper... sigh)
134      */
135     protected function showProfileOptions(HTMLOutputter $out, $profile)
136     {
137         $isRemote = !(User::staticGet('id', $profile->id));
138         if ($isRemote) {
139             $target = common_local_url('remoteprofile', array('id' => $profile->id));
140             // TRANS: Label for access to remote profile options.
141             $label = _m('Remote profile options...');
142             $out->elementStart('div', 'remote-profile-options');
143             $out->element('a', array('href' => $target), $label);
144             $out->elementEnd('div');
145         }
146     }
147 }