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