]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/connectedappslist.php
Avoid having to check for notices without rendered copies in upgrade.php
[quix0rs-gnu-social.git] / lib / connectedappslist.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-2010 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('GNUSOCIAL')) { exit(1); }
31
32 /**
33  * Widget to show a list of connected OAuth clients
34  *
35  * @category Application
36  * @package  StatusNet
37  * @author   Zach Copley <zach@status.net>
38  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
39  * @link     http://status.net/
40  */
41 class ConnectedAppsList extends Widget
42 {
43     /** Current connected application query */
44     var $connection = null;
45
46     /** Owner of this list */
47     var $owner = null;
48
49     function __construct($connection, Profile $owner, Action $out=null)
50     {
51         parent::__construct($out);
52
53         common_debug("ConnectedAppsList constructor");
54
55         $this->connection = $connection;
56         $this->owner      = $owner;
57     }
58
59     /* Override this in subclasses. */
60     function showOwnerControls()
61     {
62         return;
63     }
64
65     function show()
66     {
67         $this->out->elementStart('ul', 'applications');
68
69         $cnt = 0;
70
71         while ($this->connection->fetch()) {
72             $cnt++;
73             if($cnt > APPS_PER_PAGE) {
74                 break;
75             }
76             $this->showConnection();
77         }
78
79         $this->out->elementEnd('ul');
80
81         return $cnt;
82     }
83
84     function showConnection()
85     {
86         $app = Oauth_application::getKV('id', $this->connection->application_id);
87
88         $this->out->elementStart('li', array('class' => 'application h-entry',
89                                              'id'    => 'oauthclient-' . $app->id));
90
91         $this->out->elementStart('a', array('href' => $app->source_url,
92                                             'class' => 'h-card p-name'));
93
94         if (!empty($app->icon)) {
95             $this->out->element('img', array('src' => $app->icon,
96                                              'class' => 'avatar u-photo'));
97         }
98         if ($app->name != 'anonymous') {
99             $this->out->text($app->name);
100         } else {
101             // TRANS: Name for an anonymous application in application list.
102             $this->out->element('span', 'p-name', _('Unknown application'));
103         }
104         $this->out->elementEnd('a');
105
106         if ($app->name != 'anonymous') {
107             // @todo FIXME: i18n trouble.
108             // TRANS: Message has a leading space and a trailing space. Used in application list.
109             // TRANS: Before this message the application name is put, behind it the organisation that manages it.
110             $this->out->raw(_(' by '));
111
112             $this->out->element('a', array('href' => $app->homepage,
113                                            'class' => 'h-card'),
114                                 $app->organization);
115         }
116
117         // TRANS: Application access type
118         $readWriteText = _('read-write');
119         // TRANS: Application access type
120         $readOnlyText = _('read-only');
121
122         $access = ($this->connection->access_type & Oauth_application::$writeAccess)
123             ? $readWriteText : $readOnlyText;
124         $modifiedDate = common_date_string($this->connection->modified);
125         // TRANS: Used in application list. %1$s is a modified date, %2$s is access type ("read-write" or "read-only")
126         $txt = sprintf(_('Approved %1$s - "%2$s" access.'), $modifiedDate, $access);
127
128         // @todo FIXME: i18n trouble.
129         $this->out->raw(" - $txt");
130         if (!empty($app->description)) {
131             $this->out->element(
132                 'p', array('class' => 'application_description'),
133                 $app->description
134             );
135         }
136         $this->out->element(
137             'p', array(
138             'class' => 'access_token'),
139             // TRANS: Access token in the application list.
140             // TRANS: %s are the first 7 characters of the access token.
141             sprintf(_('Access token starting with: %s'), substr($this->connection->token, 0, 7))
142         );
143
144         $this->out->elementStart(
145             'form',
146             array(
147                 'id' => 'form_revoke_app',
148                 'class' => 'form_revoke_app',
149                 'method' => 'POST',
150                 'action' => common_local_url('oauthconnectionssettings')
151             )
152         );
153         $this->out->elementStart('fieldset');
154         $this->out->hidden('oauth_token', $this->connection->token);
155         $this->out->hidden('token', common_session_token());
156         // TRANS: Button label in application list to revoke access to user data.
157         $this->out->submit('revoke', _m('BUTTON','Revoke'));
158         $this->out->elementEnd('fieldset');
159         $this->out->elementEnd('form');
160
161         $this->out->elementEnd('li');
162     }
163 }