applicationlist.php 5.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
<?php
/**
 * StatusNet, the distributed open-source microblogging tool
 *
 * Widget to show a list of OAuth applications
 *
 * PHP version 5
 *
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
22
 * @category  Application
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
 * @package   StatusNet
 * @author    Zach Copley <zach@status.net>
 * @copyright 2008-2009 StatusNet, Inc.
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 * @link      http://status.net/
 */

if (!defined('STATUSNET') && !defined('LACONICA')) {
    exit(1);
}

require_once INSTALLDIR . '/lib/widget.php';

define('APPS_PER_PAGE', 20);

/**
 * Widget to show a list of OAuth applications
 *
41
 * @category Application
42 43 44 45 46 47 48 49 50
 * @package  StatusNet
 * @author   Zach Copley <zach@status.net>
 * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 * @link     http://status.net/
 */
class ApplicationList extends Widget
{
    /** Current application, application query */
    var $application = null;
51

52 53
    /** Owner of this list */
    var $owner = null;
54

55 56 57
    /** Action object using us. */
    var $action = null;

58
    function __construct($application, $owner=null, $action=null, $connections = false)
59 60 61 62 63 64
    {
        parent::__construct($action);

        $this->application = $application;
        $this->owner       = $owner;
        $this->action      = $action;
65
        $this->connections = $connections;
66 67 68 69
    }

    function show()
    {
Sarven Capadisli's avatar
Sarven Capadisli committed
70
        $this->out->elementStart('ul', 'applications');
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90

        $cnt = 0;

        while ($this->application->fetch()) {
            $cnt++;
            if($cnt > APPS_PER_PAGE) {
                break;
            }
            $this->showapplication();
        }

        $this->out->elementEnd('ul');

        return $cnt;
    }

    function showApplication()
    {
        $user = common_current_user();

91 92 93
        $this->out->elementStart('li', array('class' => 'application',
                                             'id' => 'oauthclient-' . $this->application->id));

94
        $this->out->elementStart('span', 'vcard author');
Sarven Capadisli's avatar
Sarven Capadisli committed
95 96
        if (!$this->connections) {
            $this->out->elementStart('a',
97 98 99
                                     array('href' => common_local_url('showapplication',
                                                                      array('id' => $this->application->id)),
                                                                      'class' => 'url'));
Sarven Capadisli's avatar
Sarven Capadisli committed
100 101 102 103 104

        } else {
            $this->out->elementStart('a', array('href' =>  $this->application->source_url,
                                                'class' => 'url'));
        }
105

106
        if (!empty($this->application->icon)) {
107
            $this->out->element('img', array('src' => $this->application->icon,
Sarven Capadisli's avatar
Sarven Capadisli committed
108
                                             'class' => 'photo avatar'));
109 110
        }

Sarven Capadisli's avatar
Sarven Capadisli committed
111
        $this->out->element('span', 'fn', $this->application->name);
112
        $this->out->elementEnd('a');
113
        $this->out->elementEnd('span');
114

Sarven Capadisli's avatar
Sarven Capadisli committed
115
        $this->out->raw(' by ');
116

Sarven Capadisli's avatar
Sarven Capadisli committed
117 118 119
        $this->out->element('a', array('href' => $this->application->homepage,
                                       'class' => 'url'),
                                 $this->application->organization);
120

Sarven Capadisli's avatar
Sarven Capadisli committed
121
        $this->out->element('p', 'note', $this->application->description);
Sarven Capadisli's avatar
Sarven Capadisli committed
122
        $this->out->elementEnd('li');
123

Sarven Capadisli's avatar
Sarven Capadisli committed
124 125
        if ($this->connections) {
            $appUser = Oauth_application_user::getByKeys($this->owner, $this->application);
126

Sarven Capadisli's avatar
Sarven Capadisli committed
127 128 129
            if (empty($appUser)) {
                common_debug("empty appUser!");
            }
130

Sarven Capadisli's avatar
Sarven Capadisli committed
131
            $this->out->elementStart('li');
132

133 134 135 136
            // TRANS: Application access type
            $readWriteText = _('read-write');
            // TRANS: Application access type
            $readOnlyText = _('read-only');
137

138 139 140
            $access = ($this->application->access_type & Oauth_application::$writeAccess)
              ? $readWriteText : $readOnlyText;
            $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

Sarven Capadisli's avatar
Sarven Capadisli committed
144 145 146
            $this->out->raw($txt);
            $this->out->elementEnd('li');

Zach Copley's avatar
Zach Copley committed
147 148 149 150 151 152 153 154 155
            $this->out->elementStart('li', 'entity_revoke');
            $this->out->elementStart('form', array('id' => 'form_revoke_app',
                                                   'class' => 'form_revoke_app',
                                                   'method' => 'POST',
                                                   'action' =>
                                                   common_local_url('oauthconnectionssettings')));
            $this->out->elementStart('fieldset');
            $this->out->hidden('id', $this->application->id);
            $this->out->hidden('token', common_session_token());
156 157
            // TRANS: Button label
            $this->out->submit('revoke', _m('BUTTON','Revoke'));
Zach Copley's avatar
Zach Copley committed
158 159 160
            $this->out->elementEnd('fieldset');
            $this->out->elementEnd('form');
            $this->out->elementEnd('li');
Sarven Capadisli's avatar
Sarven Capadisli committed
161
        }
162 163 164 165 166 167 168 169
    }

    /* Override this in subclasses. */
    function showOwnerControls()
    {
        return;
    }
}