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('GNUSOCIAL')) { exit(1); }
33 * Widget to show a list of connected OAuth clients
35 * @category Application
37 * @author Zach Copley <zach@status.net>
38 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
39 * @link http://status.net/
41 class ConnectedAppsList extends Widget
43 /** Current connected application query */
44 var $connection = null;
46 /** Owner of this list */
49 /** Action object using us. */
52 function __construct($connection, $owner=null, $action=null)
54 parent::__construct($action);
56 common_debug("ConnectedAppsList constructor");
58 $this->connection = $connection;
59 $this->owner = $owner;
60 $this->action = $action;
63 /* Override this in subclasses. */
64 function showOwnerControls()
71 $this->out->elementStart('ul', 'applications');
75 while ($this->connection->fetch()) {
77 if($cnt > APPS_PER_PAGE) {
80 $this->showConnection();
83 $this->out->elementEnd('ul');
88 function showConnection()
90 $app = Oauth_application::getKV('id', $this->connection->application_id);
92 $this->out->elementStart('li', array('class' => 'application h-entry',
93 'id' => 'oauthclient-' . $app->id));
95 $this->out->elementStart('a', array('href' => $app->source_url,
96 'class' => 'h-card p-name'));
98 if (!empty($app->icon)) {
99 $this->out->element('img', array('src' => $app->icon,
100 'class' => 'avatar u-photo'));
102 if ($app->name != 'anonymous') {
103 $this->out->text($app->name);
105 // TRANS: Name for an anonymous application in application list.
106 $this->out->element('span', 'p-name', _('Unknown application'));
108 $this->out->elementEnd('a');
110 if ($app->name != 'anonymous') {
111 // @todo FIXME: i18n trouble.
112 // TRANS: Message has a leading space and a trailing space. Used in application list.
113 // TRANS: Before this message the application name is put, behind it the organisation that manages it.
114 $this->out->raw(_(' by '));
116 $this->out->element('a', array('href' => $app->homepage,
117 'class' => 'h-card'),
121 // TRANS: Application access type
122 $readWriteText = _('read-write');
123 // TRANS: Application access type
124 $readOnlyText = _('read-only');
126 $access = ($this->connection->access_type & Oauth_application::$writeAccess)
127 ? $readWriteText : $readOnlyText;
128 $modifiedDate = common_date_string($this->connection->modified);
129 // TRANS: Used in application list. %1$s is a modified date, %2$s is access type ("read-write" or "read-only")
130 $txt = sprintf(_('Approved %1$s - "%2$s" access.'), $modifiedDate, $access);
132 // @todo FIXME: i18n trouble.
133 $this->out->raw(" - $txt");
134 if (!empty($app->description)) {
136 'p', array('class' => 'application_description'),
142 'class' => 'access_token'),
143 // TRANS: Access token in the application list.
144 // TRANS: %s are the first 7 characters of the access token.
145 sprintf(_('Access token starting with: %s'), substr($this->connection->token, 0, 7))
148 $this->out->elementStart(
151 'id' => 'form_revoke_app',
152 'class' => 'form_revoke_app',
154 'action' => common_local_url('oauthconnectionssettings')
157 $this->out->elementStart('fieldset');
158 $this->out->hidden('oauth_token', $this->connection->token);
159 $this->out->hidden('token', common_session_token());
160 // TRANS: Button label in application list to revoke access to user data.
161 $this->out->submit('revoke', _m('BUTTON','Revoke'));
162 $this->out->elementEnd('fieldset');
163 $this->out->elementEnd('form');
165 $this->out->elementEnd('li');