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 function __construct($connection, Profile $owner, Action $out=null)
51 parent::__construct($out);
53 common_debug("ConnectedAppsList constructor");
55 $this->connection = $connection;
56 $this->owner = $owner;
59 /* Override this in subclasses. */
60 function showOwnerControls()
67 $this->out->elementStart('ul', 'applications');
71 while ($this->connection->fetch()) {
73 if($cnt > APPS_PER_PAGE) {
76 $this->showConnection();
79 $this->out->elementEnd('ul');
84 function showConnection()
86 $app = Oauth_application::getKV('id', $this->connection->application_id);
88 $this->out->elementStart('li', array('class' => 'application h-entry',
89 'id' => 'oauthclient-' . $app->id));
91 $this->out->elementStart('a', array('href' => $app->source_url,
92 'class' => 'h-card p-name'));
94 if (!empty($app->icon)) {
95 $this->out->element('img', array('src' => $app->icon,
96 'class' => 'avatar u-photo'));
98 if ($app->name != 'anonymous') {
99 $this->out->text($app->name);
101 // TRANS: Name for an anonymous application in application list.
102 $this->out->element('span', 'p-name', _('Unknown application'));
104 $this->out->elementEnd('a');
106 if ($app->name != 'anonymous') {
107 // @todo FIXME: i18n trouble.
108 // TRANS: Message has a leading space and a trailing space. Used in application list.
109 // TRANS: Before this message the application name is put, behind it the organisation that manages it.
110 $this->out->raw(_(' by '));
112 $this->out->element('a', array('href' => $app->homepage,
113 'class' => 'h-card'),
117 // TRANS: Application access type
118 $readWriteText = _('read-write');
119 // TRANS: Application access type
120 $readOnlyText = _('read-only');
122 $access = ($this->connection->access_type & Oauth_application::$writeAccess)
123 ? $readWriteText : $readOnlyText;
124 $modifiedDate = common_date_string($this->connection->modified);
125 // TRANS: Used in application list. %1$s is a modified date, %2$s is access type ("read-write" or "read-only")
126 $txt = sprintf(_('Approved %1$s - "%2$s" access.'), $modifiedDate, $access);
128 // @todo FIXME: i18n trouble.
129 $this->out->raw(" - $txt");
130 if (!empty($app->description)) {
132 'p', array('class' => 'application_description'),
138 'class' => 'access_token'),
139 // TRANS: Access token in the application list.
140 // TRANS: %s are the first 7 characters of the access token.
141 sprintf(_('Access token starting with: %s'), substr($this->connection->token, 0, 7))
144 $this->out->elementStart(
147 'id' => 'form_revoke_app',
148 'class' => 'form_revoke_app',
150 'action' => common_local_url('oauthconnectionssettings')
153 $this->out->elementStart('fieldset');
154 $this->out->hidden('oauth_token', $this->connection->token);
155 $this->out->hidden('token', common_session_token());
156 // TRANS: Button label in application list to revoke access to user data.
157 $this->out->submit('revoke', _m('BUTTON','Revoke'));
158 $this->out->elementEnd('fieldset');
159 $this->out->elementEnd('form');
161 $this->out->elementEnd('li');