]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/applicationlist.php
Merge branch '1.0.x' into schema-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  * Widget to show a list of connected OAuth clients
149  *
150  * @category Application
151  * @package  StatusNet
152  * @author   Zach Copley <zach@status.net>
153  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
154  * @link     http://status.net/
155  */
156 class ConnectedAppsList extends Widget
157 {
158     /** Current connected application query */
159     var $connection = null;
160
161     /** Owner of this list */
162     var $owner = null;
163
164     /** Action object using us. */
165     var $action = null;
166
167     function __construct($connection, $owner=null, $action=null)
168     {
169         parent::__construct($action);
170
171         common_debug("ConnectedAppsList constructor");
172
173         $this->connection = $connection;
174         $this->owner       = $owner;
175         $this->action      = $action;
176     }
177
178     /* Override this in subclasses. */
179     function showOwnerControls()
180     {
181         return;
182     }
183
184     function show()
185     {
186         $this->out->elementStart('ul', 'applications');
187
188         $cnt = 0;
189
190         while ($this->connection->fetch()) {
191             $cnt++;
192             if($cnt > APPS_PER_PAGE) {
193                 break;
194             }
195             $this->showConnection();
196         }
197
198         $this->out->elementEnd('ul');
199
200         return $cnt;
201     }
202
203     function showConnection()
204     {
205         $app = Oauth_application::staticGet('id', $this->connection->application_id);
206
207         $this->out->elementStart(
208             'li',
209             array(
210                 'class' => 'application',
211                 'id'    => 'oauthclient-' . $app->id
212             )
213         );
214
215         $this->out->elementStart('span', 'vcard author');
216
217         $this->out->elementStart(
218             'a',
219             array(
220                 'href' => $app->source_url,
221                 'class' => 'url'
222             )
223         );
224
225         if (!empty($app->icon)) {
226             $this->out->element(
227                 'img',
228                 array(
229                     'src' => $app->icon,
230                     'class' => 'photo avatar'
231                 )
232             );
233         }
234         if ($app->name != 'anonymous') {
235             $this->out->element('span', 'fn', $app->name);
236         }
237         $this->out->elementEnd('a');
238
239         if ($app->name == 'anonymous') {
240             $this->out->element('span', 'fn', "Unknown application");
241         }
242
243         $this->out->elementEnd('span');
244
245         if ($app->name != 'anonymous') {
246             // @todo FIXME: i18n trouble.
247             $this->out->raw(_(' by '));
248
249             $this->out->element(
250                 'a',
251                 array(
252                     'href' => $app->homepage,
253                     'class' => 'url'
254                 ),
255                 $app->organization
256             );
257         }
258
259         // TRANS: Application access type
260         $readWriteText = _('read-write');
261         // TRANS: Application access type
262         $readOnlyText = _('read-only');
263
264         $access = ($this->connection->access_type & Oauth_application::$writeAccess)
265             ? $readWriteText : $readOnlyText;
266         $modifiedDate = common_date_string($this->connection->modified);
267         // TRANS: Used in application list. %1$s is a modified date, %2$s is access type ("read-write" or "read-only")
268         $txt = sprintf(_('Approved %1$s - "%2$s" access.'), $modifiedDate, $access);
269
270         $this->out->raw(" - $txt");
271         if (!empty($app->description)) {
272             $this->out->element(
273                 'p', array('class' => 'application_description'),
274                 $app->description
275             );
276         }
277         $this->out->element(
278             'p', array(
279             'class' => 'access_token'),
280             // TRANS: Access token in the application list.
281             // TRANS: %s are the first 7 characters of the access token.
282             sprintf(_('Access token starting with: %s'), 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', _m('BUTTON','Revoke'));
299         $this->out->elementEnd('fieldset');
300         $this->out->elementEnd('form');
301
302         $this->out->elementEnd('li');
303     }
304 }