]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/applicationlist.php
Merge branch 'anon-consumer' into 0.9.x
[quix0rs-gnu-social.git] / lib / applicationlist.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Widget to show a list of OAuth applications
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Application
23  * @package   StatusNet
24  * @author    Zach Copley <zach@status.net>
25  * @copyright 2008-2010 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
31     exit(1);
32 }
33
34 require_once INSTALLDIR . '/lib/widget.php';
35
36 define('APPS_PER_PAGE', 20);
37
38 /**
39  * Widget to show a list of OAuth applications
40  *
41  * @category Application
42  * @package  StatusNet
43  * @author   Zach Copley <zach@status.net>
44  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45  * @link     http://status.net/
46  */
47 class ApplicationList extends Widget
48 {
49     /** Current application, application query */
50     var $application = null;
51
52     /** Owner of this list */
53     var $owner = null;
54
55     /** Action object using us. */
56     var $action = null;
57
58     function __construct($application, $owner=null, $action=null)
59     {
60         parent::__construct($action);
61
62         $this->application = $application;
63         $this->owner       = $owner;
64         $this->action      = $action;
65     }
66
67     function show()
68     {
69         $this->out->elementStart('ul', 'applications');
70
71         $cnt = 0;
72
73         while ($this->application->fetch()) {
74             $cnt++;
75             if($cnt > APPS_PER_PAGE) {
76                 break;
77             }
78             $this->showapplication();
79         }
80
81         $this->out->elementEnd('ul');
82
83         return $cnt;
84     }
85
86     function showApplication()
87     {
88         $user = common_current_user();
89
90         $this->out->elementStart(
91             'li',
92             array(
93                 'class' => 'application',
94                 'id'    => 'oauthclient-' . $this->application->id
95             )
96         );
97
98         $this->out->elementStart('span', 'vcard author');
99
100         $this->out->elementStart(
101             'a',
102             array(
103                 'href' => common_local_url(
104                     'showapplication',
105                     array('id' => $this->application->id)),
106                     'class' => 'url'
107             )
108         );
109
110         if (!empty($this->application->icon)) {
111             $this->out->element(
112                 'img',
113                 array(
114                     'src' => $this->application->icon,
115                     'class' => 'photo avatar'
116                 )
117             );
118         }
119
120         $this->out->element('span', 'fn', $this->application->name);
121         $this->out->elementEnd('a');
122         $this->out->elementEnd('span');
123
124         $this->out->raw(' by ');
125
126         $this->out->element(
127             'a',
128             array(
129                 'href' => $this->application->homepage,
130                 'class' => 'url'
131             ),
132             $this->application->organization
133         );
134
135         $this->out->element('p', 'note', $this->application->description);
136         $this->out->elementEnd('li');
137
138     }
139
140     /* Override this in subclasses. */
141     function showOwnerControls()
142     {
143         return;
144     }
145
146 }
147
148
149 /**
150  * Widget to show a list of connected OAuth clients
151  *
152  * @category Application
153  * @package  StatusNet
154  * @author   Zach Copley <zach@status.net>
155  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
156  * @link     http://status.net/
157  */
158 class ConnectedAppsList extends Widget
159 {
160     /** Current connected application query */
161     var $connection = null;
162
163     /** Owner of this list */
164     var $owner = null;
165
166     /** Action object using us. */
167     var $action = null;
168
169     function __construct($connection, $owner=null, $action=null)
170     {
171         parent::__construct($action);
172
173         common_debug("ConnectedAppsList constructor");
174
175         $this->connection = $connection;
176         $this->owner       = $owner;
177         $this->action      = $action;
178     }
179
180     /* Override this in subclasses. */
181     function showOwnerControls()
182     {
183         return;
184     }
185
186     function show()
187     {
188         $this->out->elementStart('ul', 'applications');
189
190         $cnt = 0;
191
192         while ($this->connection->fetch()) {
193             $cnt++;
194             if($cnt > APPS_PER_PAGE) {
195                 break;
196             }
197             $this->showConnection();
198         }
199
200         $this->out->elementEnd('ul');
201
202         return $cnt;
203     }
204
205     function showConnection()
206     {
207         $app = Oauth_application::staticGet('id', $this->connection->application_id);
208
209         $this->out->elementStart(
210             'li',
211             array(
212                 'class' => 'application',
213                 'id'    => 'oauthclient-' . $app->id
214             )
215         );
216
217         $this->out->elementStart('span', 'vcard author');
218
219         $this->out->elementStart(
220             'a',
221             array(
222                 'href' => $app->source_url,
223                 'class' => 'url'
224             )
225         );
226
227         if (!empty($app->icon)) {
228             $this->out->element(
229                 'img',
230                 array(
231                     'src' => $app->icon,
232                     'class' => 'photo avatar'
233                 )
234             );
235         }
236         if ($app->name != 'anonymous') {
237             $this->out->element('span', 'fn', $app->name);
238         }
239         $this->out->elementEnd('a');
240
241         if ($app->name == 'anonymous') {
242             $this->out->element('span', 'fn', "Unknown application");
243         }
244
245         $this->out->elementEnd('span');
246
247         if ($app->name != 'anonymous') {
248
249             $this->out->raw(_(' by '));
250
251             $this->out->element(
252                 'a',
253                 array(
254                     'href' => $app->homepage,
255                     'class' => 'url'
256                 ),
257                 $app->organization
258             );
259         }
260
261         // TRANS: Application access type
262         $readWriteText = _('read-write');
263         // TRANS: Application access type
264         $readOnlyText = _('read-only');
265
266         $access = ($this->connection->access_type & Oauth_application::$writeAccess)
267             ? $readWriteText : $readOnlyText;
268         $modifiedDate = common_date_string($this->connection->modified);
269         // TRANS: Used in application list. %1$s is a modified date, %2$s is access type ("read-write" or "read-only")
270         $txt = sprintf(_('Approved %1$s - "%2$s" access.'), $modifiedDate, $access);
271
272         $this->out->raw(" - $txt");
273         if (!empty($app->description)) {
274             $this->out->element(
275                 'p', array('class' => 'application_description'),
276                 $app->description
277             );
278         }
279         $this->out->element(
280             'p', array(
281             'class' => 'access_token'),
282             _('Access token starting with: ') . substr($this->connection->token, 0, 7)
283         );
284
285         $this->out->elementStart(
286             'form',
287             array(
288                 'id' => 'form_revoke_app',
289                 'class' => 'form_revoke_app',
290                 'method' => 'POST',
291                 'action' => common_local_url('oauthconnectionssettings')
292             )
293         );
294         $this->out->elementStart('fieldset');
295         $this->out->hidden('oauth_token', $this->connection->token);
296         $this->out->hidden('token', common_session_token());
297         // TRANS: Button label
298         $this->out->submit('revoke', _('Revoke'));
299         $this->out->elementEnd('fieldset');
300         $this->out->elementEnd('form');
301
302         $this->out->elementEnd('li');
303
304     }
305 }