4 * StatusNet, the distributed open-source microblogging tool
6 * Widget to show a list of OAuth applications
10 * LICENCE: This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Affero General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Affero General Public License for more details.
20 * You should have received a copy of the GNU Affero General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 * @category Application
25 * @author Zach Copley <zach@status.net>
26 * @copyright 2008-2009 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28 * @link http://status.net/
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
35 require_once INSTALLDIR . '/lib/widget.php';
37 define('APPS_PER_PAGE', 20);
40 * Widget to show a list of OAuth applications
42 * @category Application
44 * @author Zach Copley <zach@status.net>
45 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
46 * @link http://status.net/
49 class ApplicationList extends Widget
51 /** Current application, application query */
52 var $application = null;
54 /** Owner of this list */
57 /** Action object using us. */
60 function __construct($application, $owner=null, $action=null, $connections = false)
62 parent::__construct($action);
64 $this->application = $application;
65 $this->owner = $owner;
66 $this->action = $action;
67 $this->connections = $connections;
72 $this->out->elementStart('ul', 'applications');
76 while ($this->application->fetch()) {
78 if($cnt > APPS_PER_PAGE) {
81 $this->showapplication();
84 $this->out->elementEnd('ul');
89 function showApplication()
91 $user = common_current_user();
93 $this->out->elementStart('li', array('class' => 'application',
94 'id' => 'oauthclient-' . $this->application->id));
96 $this->out->elementStart('span', 'vcard author');
97 if (!$this->connections) {
98 $this->out->elementStart('a',
99 array('href' => common_local_url('showapplication',
100 array('id' => $this->application->id)),
104 $this->out->elementStart('a', array('href' => $this->application->source_url,
108 if (!empty($this->application->icon)) {
109 $this->out->element('img', array('src' => $this->application->icon,
110 'class' => 'photo avatar'));
113 $this->out->element('span', 'fn', $this->application->name);
114 $this->out->elementEnd('a');
115 $this->out->elementEnd('span');
117 $this->out->raw(' by ');
119 $this->out->element('a', array('href' => $this->application->homepage,
121 $this->application->organization);
123 $this->out->element('p', 'note', $this->application->description);
124 $this->out->elementEnd('li');
126 if ($this->connections) {
127 $appUser = Oauth_application_user::getByKeys($this->owner, $this->application);
129 if (empty($appUser)) {
130 common_debug("empty appUser!");
133 $this->out->elementStart('li');
135 // TRANS: Application access type
136 $readWriteText = _('read-write');
137 // TRANS: Application access type
138 $readOnlyText = _('read-only');
140 $access = ($this->application->access_type & Oauth_application::$writeAccess)
141 ? $readWriteText : $readOnlyText;
142 $modifiedDate = common_date_string($appUser->modified);
143 // TRANS: Used in application list. %1$s is a modified date, %2$s is access type (read-write or read-only)
144 $txt = sprintf(_('Approved %1$s - "%2$s" access.'),$modifiedDate,$access);
146 $this->out->raw($txt);
147 $this->out->elementEnd('li');
149 $this->out->elementStart('li', 'entity_revoke');
150 $this->out->elementStart('form', array('id' => 'form_revoke_app',
151 'class' => 'form_revoke_app',
154 common_local_url('oauthconnectionssettings')));
155 $this->out->elementStart('fieldset');
156 $this->out->hidden('id', $this->application->id);
157 $this->out->hidden('token', common_session_token());
158 // TRANS: Button label
159 $this->out->submit('revoke', _m('BUTTON','Revoke'));
160 $this->out->elementEnd('fieldset');
161 $this->out->elementEnd('form');
162 $this->out->elementEnd('li');
166 /* Override this in subclasses. */
168 function showOwnerControls()