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(
93 'class' => 'application',
94 'id' => 'oauthclient-' . $this->application->id
98 $this->out->elementStart('span', 'vcard author');
100 $this->out->elementStart(
103 'href' => common_local_url(
105 array('id' => $this->application->id)),
110 if (!empty($this->application->icon)) {
114 'src' => $this->application->icon,
115 'class' => 'photo avatar'
120 $this->out->element('span', 'fn', $this->application->name);
121 $this->out->elementEnd('a');
122 $this->out->elementEnd('span');
124 $this->out->raw(' by ');
129 'href' => $this->application->homepage,
132 $this->application->organization
135 $this->out->element('p', 'note', $this->application->description);
136 $this->out->elementEnd('li');
140 /* Override this in subclasses. */
141 function showOwnerControls()
150 * Widget to show a list of connected OAuth clients
152 * @category Application
154 * @author Zach Copley <zach@status.net>
155 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
156 * @link http://status.net/
158 class ConnectedAppsList extends Widget
160 /** Current connected application query */
161 var $connection = null;
163 /** Owner of this list */
166 /** Action object using us. */
169 function __construct($connection, $owner=null, $action=null)
171 parent::__construct($action);
173 common_debug("ConnectedAppsList constructor");
175 $this->connection = $connection;
176 $this->owner = $owner;
177 $this->action = $action;
180 /* Override this in subclasses. */
181 function showOwnerControls()
188 $this->out->elementStart('ul', 'applications');
192 while ($this->connection->fetch()) {
194 if($cnt > APPS_PER_PAGE) {
197 $this->showConnection();
200 $this->out->elementEnd('ul');
205 function showConnection()
207 $app = Oauth_application::staticGet('id', $this->connection->application_id);
209 $this->out->elementStart(
212 'class' => 'application',
213 'id' => 'oauthclient-' . $app->id
217 $this->out->elementStart('span', 'vcard author');
219 $this->out->elementStart(
222 'href' => $app->source_url,
227 if (!empty($app->icon)) {
232 'class' => 'photo avatar'
236 if ($app->name != 'anonymous') {
237 $this->out->element('span', 'fn', $app->name);
239 $this->out->elementEnd('a');
241 if ($app->name == 'anonymous') {
242 $this->out->element('span', 'fn', "Unknown application");
245 $this->out->elementEnd('span');
247 if ($app->name != 'anonymous') {
249 $this->out->raw(_(' by '));
254 'href' => $app->homepage,
261 // TRANS: Application access type
262 $readWriteText = _('read-write');
263 // TRANS: Application access type
264 $readOnlyText = _('read-only');
266 $access = ($this->connection->access_type & Oauth_application::$writeAccess)
267 ? $readWriteText : $readOnlyText;
268 $modifiedDate = common_date_string($this->connection->modified);
269 // TRANS: Used in application list. %1$s is a modified date, %2$s is access type ("read-write" or "read-only")
270 $txt = sprintf(_('Approved %1$s - "%2$s" access.'), $modifiedDate, $access);
272 $this->out->raw(" - $txt");
273 if (!empty($app->description)) {
275 'p', array('class' => 'application_description'),
281 'class' => 'access_token'),
282 _('Access token starting with: ') . substr($this->connection->token, 0, 7)
285 $this->out->elementStart(
288 'id' => 'form_revoke_app',
289 'class' => 'form_revoke_app',
291 'action' => common_local_url('oauthconnectionssettings')
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', _('Revoke'));
299 $this->out->elementEnd('fieldset');
300 $this->out->elementEnd('form');
302 $this->out->elementEnd('li');