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-2009 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, $connections = false)
60 parent::__construct($action);
62 $this->application = $application;
63 $this->owner = $owner;
64 $this->action = $action;
65 $this->connections = $connections;
70 $this->out->elementStart('ul', 'applications');
74 while ($this->application->fetch()) {
76 if($cnt > APPS_PER_PAGE) {
79 $this->showapplication();
82 $this->out->elementEnd('ul');
87 function showApplication()
89 $user = common_current_user();
91 $this->out->elementStart('li', array('class' => 'application',
92 'id' => 'oauthclient-' . $this->application->id));
94 $this->out->elementStart('span', 'vcard author');
95 if (!$this->connections) {
96 $this->out->elementStart('a',
97 array('href' => common_local_url('showapplication',
98 array('id' => $this->application->id)),
102 $this->out->elementStart('a', array('href' => $this->application->source_url,
106 if (!empty($this->application->icon)) {
107 $this->out->element('img', array('src' => $this->application->icon,
108 'class' => 'photo avatar'));
111 $this->out->element('span', 'fn', $this->application->name);
112 $this->out->elementEnd('a');
113 $this->out->elementEnd('span');
115 $this->out->raw(' by ');
117 $this->out->element('a', array('href' => $this->application->homepage,
119 $this->application->organization);
121 $this->out->element('p', 'note', $this->application->description);
122 $this->out->elementEnd('li');
124 if ($this->connections) {
125 $appUser = Oauth_application_user::getByKeys($this->owner, $this->application);
127 if (empty($appUser)) {
128 common_debug("empty appUser!");
131 $this->out->elementStart('li');
133 // TRANS: Application access type
134 $readWriteText = _('read-write');
135 // TRANS: Application access type
136 $readOnlyText = _('read-only');
138 $access = ($this->application->access_type & Oauth_application::$writeAccess)
139 ? $readWriteText : $readOnlyText;
140 $modifiedDate = common_date_string($appUser->modified);
141 // TRANS: Used in application list. %1$s is a modified date, %2$s is access type ("read-write" or "read-only")
142 $txt = sprintf(_('Approved %1$s - "%2$s" access.'),$modifiedDate,$access);
144 $this->out->raw($txt);
145 $this->out->elementEnd('li');
147 $this->out->elementStart('li', 'entity_revoke');
148 $this->out->elementStart('form', array('id' => 'form_revoke_app',
149 'class' => 'form_revoke_app',
152 common_local_url('oauthconnectionssettings')));
153 $this->out->elementStart('fieldset');
154 $this->out->hidden('id', $this->application->id);
155 $this->out->hidden('token', common_session_token());
156 // TRANS: Button label
157 $this->out->submit('revoke', _m('BUTTON','Revoke'));
158 $this->out->elementEnd('fieldset');
159 $this->out->elementEnd('form');
160 $this->out->elementEnd('li');
164 /* Override this in subclasses. */
165 function showOwnerControls()