3 * StatusNet, the distributed open-source microblogging tool
5 * Widget to show a list of OAuth applications
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.
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.
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/>.
22 * @category Application
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/
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
34 require_once INSTALLDIR . '/lib/widget.php';
36 define('APPS_PER_PAGE', 20);
39 * Widget to show a list of OAuth applications
41 * @category Application
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/
47 class ApplicationList extends Widget
49 /** Current application, application query */
50 var $application = null;
52 /** Owner of this list */
55 /** Action object using us. */
58 function __construct($application, $owner=null, $action=null)
60 parent::__construct($action);
62 $this->application = $application;
63 $this->owner = $owner;
64 $this->action = $action;
69 $this->out->elementStart('ul', 'applications');
73 while ($this->application->fetch()) {
75 if($cnt > APPS_PER_PAGE) {
78 $this->showapplication();
81 $this->out->elementEnd('ul');
86 function showApplication()
88 $user = common_current_user();
90 $this->out->elementStart('li', array('class' => 'application h-entry',
91 'id' => 'oauthclient-' . $this->application->id));
93 $this->out->elementStart('a', array('href' => common_local_url('showapplication',
94 array('id' => $this->application->id)),
95 'class' => 'h-card'));
97 if (!empty($this->application->icon)) {
98 $this->out->element('img', array('src' => $this->application->icon,
99 'class' => 'avatar u-photo'));
102 $this->out->text($this->application->name);
103 $this->out->elementEnd('a');
105 $this->out->raw(' by ');
107 $this->out->element('a', array('href' => $this->application->homepage,
109 $this->application->organization);
111 $this->out->element('p', 'note', $this->application->description);
112 $this->out->elementEnd('li');
116 /* Override this in subclasses. */
117 function showOwnerControls()
124 * Widget to show a list of connected OAuth clients
126 * @category Application
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/
132 class ConnectedAppsList extends Widget
134 /** Current connected application query */
135 var $connection = null;
137 /** Owner of this list */
140 /** Action object using us. */
143 function __construct($connection, $owner=null, $action=null)
145 parent::__construct($action);
147 common_debug("ConnectedAppsList constructor");
149 $this->connection = $connection;
150 $this->owner = $owner;
151 $this->action = $action;
154 /* Override this in subclasses. */
155 function showOwnerControls()
162 $this->out->elementStart('ul', 'applications');
166 while ($this->connection->fetch()) {
168 if($cnt > APPS_PER_PAGE) {
171 $this->showConnection();
174 $this->out->elementEnd('ul');
179 function showConnection()
181 $app = Oauth_application::getKV('id', $this->connection->application_id);
183 $this->out->elementStart('li', array('class' => 'application h-entry',
184 'id' => 'oauthclient-' . $app->id));
186 $this->out->elementStart('a', array('href' => $app->source_url,
187 'class' => 'h-card p-name'));
189 if (!empty($app->icon)) {
190 $this->out->element('img', array('src' => $app->icon,
191 'class' => 'avatar u-photo'));
193 if ($app->name != 'anonymous') {
194 $this->out->text($app->name);
196 // TRANS: Name for an anonymous application in application list.
197 $this->out->element('span', 'p-name', _('Unknown application'));
199 $this->out->elementEnd('a');
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 '));
207 $this->out->element('a', array('href' => $app->homepage,
208 'class' => 'h-card'),
212 // TRANS: Application access type
213 $readWriteText = _('read-write');
214 // TRANS: Application access type
215 $readOnlyText = _('read-only');
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);
223 // @todo FIXME: i18n trouble.
224 $this->out->raw(" - $txt");
225 if (!empty($app->description)) {
227 'p', array('class' => 'application_description'),
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))
239 $this->out->elementStart(
242 'id' => 'form_revoke_app',
243 'class' => 'form_revoke_app',
245 'action' => common_local_url('oauthconnectionssettings')
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');
256 $this->out->elementEnd('li');