]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/applicationlist.php
Misses this file to merge. I like the comments.
[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('li', array('class' => 'application h-entry',
91                                              'id'    => 'oauthclient-' . $this->application->id));
92
93         $this->out->elementStart('a', array('href' => common_local_url('showapplication',
94                                                                        array('id' => $this->application->id)),
95                                             'class' => 'h-card'));
96
97         if (!empty($this->application->icon)) {
98             $this->out->element('img', array('src' => $this->application->icon,
99                                              'class' => 'avatar u-photo'));
100         }
101
102         $this->out->text($this->application->name);
103         $this->out->elementEnd('a');
104
105         $this->out->raw(' by ');
106
107         $this->out->element('a', array('href' => $this->application->homepage,
108                                        'class' => 'u-url'),
109                             $this->application->organization);
110
111         $this->out->element('p', 'note', $this->application->description);
112         $this->out->elementEnd('li');
113
114     }
115
116     /* Override this in subclasses. */
117     function showOwnerControls()
118     {
119         return;
120     }
121 }
122
123 /**
124  * Widget to show a list of connected OAuth clients
125  *
126  * @category Application
127  * @package  StatusNet
128  * @author   Zach Copley <zach@status.net>
129  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
130  * @link     http://status.net/
131  */
132 class ConnectedAppsList extends Widget
133 {
134     /** Current connected application query */
135     var $connection = null;
136
137     /** Owner of this list */
138     var $owner = null;
139
140     /** Action object using us. */
141     var $action = null;
142
143     function __construct($connection, $owner=null, $action=null)
144     {
145         parent::__construct($action);
146
147         common_debug("ConnectedAppsList constructor");
148
149         $this->connection = $connection;
150         $this->owner       = $owner;
151         $this->action      = $action;
152     }
153
154     /* Override this in subclasses. */
155     function showOwnerControls()
156     {
157         return;
158     }
159
160     function show()
161     {
162         $this->out->elementStart('ul', 'applications');
163
164         $cnt = 0;
165
166         while ($this->connection->fetch()) {
167             $cnt++;
168             if($cnt > APPS_PER_PAGE) {
169                 break;
170             }
171             $this->showConnection();
172         }
173
174         $this->out->elementEnd('ul');
175
176         return $cnt;
177     }
178
179     function showConnection()
180     {
181         $app = Oauth_application::getKV('id', $this->connection->application_id);
182
183         $this->out->elementStart('li', array('class' => 'application h-entry',
184                                              'id'    => 'oauthclient-' . $app->id));
185
186         $this->out->elementStart('a', array('href' => $app->source_url,
187                                             'class' => 'h-card p-name'));
188
189         if (!empty($app->icon)) {
190             $this->out->element('img', array('src' => $app->icon,
191                                              'class' => 'avatar u-photo'));
192         }
193         if ($app->name != 'anonymous') {
194             $this->out->text($app->name);
195         } else {
196             // TRANS: Name for an anonymous application in application list.
197             $this->out->element('span', 'p-name', _('Unknown application'));
198         }
199         $this->out->elementEnd('a');
200
201         if ($app->name != 'anonymous') {
202             // @todo FIXME: i18n trouble.
203             // TRANS: Message has a leading space and a trailing space. Used in application list.
204             // TRANS: Before this message the application name is put, behind it the organisation that manages it.
205             $this->out->raw(_(' by '));
206
207             $this->out->element('a', array('href' => $app->homepage,
208                                            'class' => 'h-card'),
209                                 $app->organization);
210         }
211
212         // TRANS: Application access type
213         $readWriteText = _('read-write');
214         // TRANS: Application access type
215         $readOnlyText = _('read-only');
216
217         $access = ($this->connection->access_type & Oauth_application::$writeAccess)
218             ? $readWriteText : $readOnlyText;
219         $modifiedDate = common_date_string($this->connection->modified);
220         // TRANS: Used in application list. %1$s is a modified date, %2$s is access type ("read-write" or "read-only")
221         $txt = sprintf(_('Approved %1$s - "%2$s" access.'), $modifiedDate, $access);
222
223         // @todo FIXME: i18n trouble.
224         $this->out->raw(" - $txt");
225         if (!empty($app->description)) {
226             $this->out->element(
227                 'p', array('class' => 'application_description'),
228                 $app->description
229             );
230         }
231         $this->out->element(
232             'p', array(
233             'class' => 'access_token'),
234             // TRANS: Access token in the application list.
235             // TRANS: %s are the first 7 characters of the access token.
236             sprintf(_('Access token starting with: %s'), substr($this->connection->token, 0, 7))
237         );
238
239         $this->out->elementStart(
240             'form',
241             array(
242                 'id' => 'form_revoke_app',
243                 'class' => 'form_revoke_app',
244                 'method' => 'POST',
245                 'action' => common_local_url('oauthconnectionssettings')
246             )
247         );
248         $this->out->elementStart('fieldset');
249         $this->out->hidden('oauth_token', $this->connection->token);
250         $this->out->hidden('token', common_session_token());
251         // TRANS: Button label in application list to revoke access to user data.
252         $this->out->submit('revoke', _m('BUTTON','Revoke'));
253         $this->out->elementEnd('fieldset');
254         $this->out->elementEnd('form');
255
256         $this->out->elementEnd('li');
257     }
258 }