]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/applicationlist.php
Merge branch 'testing'
[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
49 class ApplicationList extends Widget
50 {
51     /** Current application, application query */
52     var $application = null;
53
54     /** Owner of this list */
55     var $owner = null;
56
57     /** Action object using us. */
58     var $action = null;
59
60     function __construct($application, $owner=null, $action=null, $connections = false)
61     {
62         parent::__construct($action);
63
64         $this->application = $application;
65         $this->owner       = $owner;
66         $this->action      = $action;
67         $this->connections = $connections;
68     }
69
70     function show()
71     {
72         $this->out->elementStart('ul', 'applications');
73
74         $cnt = 0;
75
76         while ($this->application->fetch()) {
77             $cnt++;
78             if($cnt > APPS_PER_PAGE) {
79                 break;
80             }
81             $this->showapplication();
82         }
83
84         $this->out->elementEnd('ul');
85
86         return $cnt;
87     }
88
89     function showApplication()
90     {
91
92         $user = common_current_user();
93
94         $this->out->elementStart('li', array('class' => 'application',
95                                              'id' => 'oauthclient-' . $this->application->id));
96
97         $this->out->elementStart('span', 'vcard author');
98         if (!$this->connections) {
99             $this->out->elementStart('a',
100                                      array('href' => common_local_url('showapplication',
101                                                                       array('id' => $this->application->id)),
102                                                                       'class' => 'url'));
103
104         } else {
105             $this->out->elementStart('a', array('href' =>  $this->application->source_url,
106                                                 'class' => 'url'));
107         }
108
109         if (!empty($this->application->icon)) {
110             $this->out->element('img', array('src' => $this->application->icon,
111                                              'class' => 'photo avatar'));
112         }
113
114         $this->out->element('span', 'fn', $this->application->name);
115         $this->out->elementEnd('a');
116         $this->out->elementEnd('span');
117
118         $this->out->raw(' by ');
119
120         $this->out->element('a', array('href' => $this->application->homepage,
121                                        'class' => 'url'),
122                                  $this->application->organization);
123
124         $this->out->element('p', 'note', $this->application->description);
125         $this->out->elementEnd('li');
126
127         if ($this->connections) {
128             $appUser = Oauth_application_user::getByKeys($this->owner, $this->application);
129
130             if (empty($appUser)) {
131                 common_debug("empty appUser!");
132             }
133
134             $this->out->elementStart('li');
135
136             $access = ($this->application->access_type & Oauth_application::$writeAccess)
137               ? 'read-write' : 'read-only';
138
139             $txt = 'Approved ' . common_date_string($appUser->modified) .
140               " - $access access.";
141
142             $this->out->raw($txt);
143             $this->out->elementEnd('li');
144
145             $this->out->elementStart('li', 'entity_revoke');
146             $this->out->elementStart('form', array('id' => 'form_revoke_app',
147                                                    'class' => 'form_revoke_app',
148                                                    'method' => 'POST',
149                                                    'action' =>
150                                                    common_local_url('oauthconnectionssettings')));
151             $this->out->elementStart('fieldset');
152             $this->out->hidden('id', $this->application->id);
153             $this->out->hidden('token', common_session_token());
154             $this->out->submit('revoke', _('Revoke'));
155             $this->out->elementEnd('fieldset');
156             $this->out->elementEnd('form');
157             $this->out->elementEnd('li');
158         }
159     }
160
161     /* Override this in subclasses. */
162
163     function showOwnerControls()
164     {
165         return;
166     }
167
168 }