]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/connectedappslist.php
OAuth widgets separated into their own files
[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     /** Action object using us. */
50     var $action = null;
51
52     function __construct($connection, $owner=null, $action=null)
53     {
54         parent::__construct($action);
55
56         common_debug("ConnectedAppsList constructor");
57
58         $this->connection = $connection;
59         $this->owner       = $owner;
60         $this->action      = $action;
61     }
62
63     /* Override this in subclasses. */
64     function showOwnerControls()
65     {
66         return;
67     }
68
69     function show()
70     {
71         $this->out->elementStart('ul', 'applications');
72
73         $cnt = 0;
74
75         while ($this->connection->fetch()) {
76             $cnt++;
77             if($cnt > APPS_PER_PAGE) {
78                 break;
79             }
80             $this->showConnection();
81         }
82
83         $this->out->elementEnd('ul');
84
85         return $cnt;
86     }
87
88     function showConnection()
89     {
90         $app = Oauth_application::getKV('id', $this->connection->application_id);
91
92         $this->out->elementStart('li', array('class' => 'application h-entry',
93                                              'id'    => 'oauthclient-' . $app->id));
94
95         $this->out->elementStart('a', array('href' => $app->source_url,
96                                             'class' => 'h-card p-name'));
97
98         if (!empty($app->icon)) {
99             $this->out->element('img', array('src' => $app->icon,
100                                              'class' => 'avatar u-photo'));
101         }
102         if ($app->name != 'anonymous') {
103             $this->out->text($app->name);
104         } else {
105             // TRANS: Name for an anonymous application in application list.
106             $this->out->element('span', 'p-name', _('Unknown application'));
107         }
108         $this->out->elementEnd('a');
109
110         if ($app->name != 'anonymous') {
111             // @todo FIXME: i18n trouble.
112             // TRANS: Message has a leading space and a trailing space. Used in application list.
113             // TRANS: Before this message the application name is put, behind it the organisation that manages it.
114             $this->out->raw(_(' by '));
115
116             $this->out->element('a', array('href' => $app->homepage,
117                                            'class' => 'h-card'),
118                                 $app->organization);
119         }
120
121         // TRANS: Application access type
122         $readWriteText = _('read-write');
123         // TRANS: Application access type
124         $readOnlyText = _('read-only');
125
126         $access = ($this->connection->access_type & Oauth_application::$writeAccess)
127             ? $readWriteText : $readOnlyText;
128         $modifiedDate = common_date_string($this->connection->modified);
129         // TRANS: Used in application list. %1$s is a modified date, %2$s is access type ("read-write" or "read-only")
130         $txt = sprintf(_('Approved %1$s - "%2$s" access.'), $modifiedDate, $access);
131
132         // @todo FIXME: i18n trouble.
133         $this->out->raw(" - $txt");
134         if (!empty($app->description)) {
135             $this->out->element(
136                 'p', array('class' => 'application_description'),
137                 $app->description
138             );
139         }
140         $this->out->element(
141             'p', array(
142             'class' => 'access_token'),
143             // TRANS: Access token in the application list.
144             // TRANS: %s are the first 7 characters of the access token.
145             sprintf(_('Access token starting with: %s'), substr($this->connection->token, 0, 7))
146         );
147
148         $this->out->elementStart(
149             'form',
150             array(
151                 'id' => 'form_revoke_app',
152                 'class' => 'form_revoke_app',
153                 'method' => 'POST',
154                 'action' => common_local_url('oauthconnectionssettings')
155             )
156         );
157         $this->out->elementStart('fieldset');
158         $this->out->hidden('oauth_token', $this->connection->token);
159         $this->out->hidden('token', common_session_token());
160         // TRANS: Button label in application list to revoke access to user data.
161         $this->out->submit('revoke', _m('BUTTON','Revoke'));
162         $this->out->elementEnd('fieldset');
163         $this->out->elementEnd('form');
164
165         $this->out->elementEnd('li');
166     }
167 }