]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/applicationlist.php
* update/add translator documentation
[quix0rs-gnu-social.git] / lib / applicationlist.php
1 <?php
2
3 /**
4  * StatusNet, the distributed open-source microblogging tool
5  *
6  * Widget to show a list of OAuth applications
7  *
8  * PHP version 5
9  *
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.
14  *
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.
19  *
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/>.
22  *
23  * @category  Application
24  * @package   StatusNet
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/
29  */
30
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR . '/lib/widget.php';
36
37 define('APPS_PER_PAGE', 20);
38
39 /**
40  * Widget to show a list of OAuth applications
41  *
42  * @category Application
43  * @package  StatusNet
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/
47  */
48 class ApplicationList extends Widget
49 {
50     /** Current application, application query */
51     var $application = null;
52
53     /** Owner of this list */
54     var $owner = null;
55
56     /** Action object using us. */
57     var $action = null;
58
59     function __construct($application, $owner=null, $action=null, $connections = false)
60     {
61         parent::__construct($action);
62
63         $this->application = $application;
64         $this->owner       = $owner;
65         $this->action      = $action;
66         $this->connections = $connections;
67     }
68
69     function show()
70     {
71         $this->out->elementStart('ul', 'applications');
72
73         $cnt = 0;
74
75         while ($this->application->fetch()) {
76             $cnt++;
77             if($cnt > APPS_PER_PAGE) {
78                 break;
79             }
80             $this->showapplication();
81         }
82
83         $this->out->elementEnd('ul');
84
85         return $cnt;
86     }
87
88     function showApplication()
89     {
90         $user = common_current_user();
91
92         $this->out->elementStart('li', array('class' => 'application',
93                                              'id' => 'oauthclient-' . $this->application->id));
94
95         $this->out->elementStart('span', 'vcard author');
96         if (!$this->connections) {
97             $this->out->elementStart('a',
98                                      array('href' => common_local_url('showapplication',
99                                                                       array('id' => $this->application->id)),
100                                                                       'class' => 'url'));
101
102         } else {
103             $this->out->elementStart('a', array('href' =>  $this->application->source_url,
104                                                 'class' => 'url'));
105         }
106
107         if (!empty($this->application->icon)) {
108             $this->out->element('img', array('src' => $this->application->icon,
109                                              'class' => 'photo avatar'));
110         }
111
112         $this->out->element('span', 'fn', $this->application->name);
113         $this->out->elementEnd('a');
114         $this->out->elementEnd('span');
115
116         $this->out->raw(' by ');
117
118         $this->out->element('a', array('href' => $this->application->homepage,
119                                        'class' => 'url'),
120                                  $this->application->organization);
121
122         $this->out->element('p', 'note', $this->application->description);
123         $this->out->elementEnd('li');
124
125         if ($this->connections) {
126             $appUser = Oauth_application_user::getByKeys($this->owner, $this->application);
127
128             if (empty($appUser)) {
129                 common_debug("empty appUser!");
130             }
131
132             $this->out->elementStart('li');
133
134             // TRANS: Application access type
135             $readWriteText = _('read-write');
136             // TRANS: Application access type
137             $readOnlyText = _('read-only');
138
139             $access = ($this->application->access_type & Oauth_application::$writeAccess)
140               ? $readWriteText : $readOnlyText;
141             $modifiedDate = common_date_string($appUser->modified);
142             // TRANS: Used in application list. %1$s is a modified date, %2$s is access type (read-write or read-only)
143             $txt = sprintf(_('Approved %1$s - "%2$s" access.'),$modifiedDate,$access);
144
145             $this->out->raw($txt);
146             $this->out->elementEnd('li');
147
148             $this->out->elementStart('li', 'entity_revoke');
149             $this->out->elementStart('form', array('id' => 'form_revoke_app',
150                                                    'class' => 'form_revoke_app',
151                                                    'method' => 'POST',
152                                                    'action' =>
153                                                    common_local_url('oauthconnectionssettings')));
154             $this->out->elementStart('fieldset');
155             $this->out->hidden('id', $this->application->id);
156             $this->out->hidden('token', common_session_token());
157             // TRANS: Button label
158             $this->out->submit('revoke', _m('BUTTON','Revoke'));
159             $this->out->elementEnd('fieldset');
160             $this->out->elementEnd('form');
161             $this->out->elementEnd('li');
162         }
163     }
164
165     /* Override this in subclasses. */
166     function showOwnerControls()
167     {
168         return;
169     }
170 }