We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

ostatuspeopletag.php 5.3 KB
Newer Older
Shashi Gowda's avatar
Shashi Gowda committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
<?php
/*
 * StatusNet - the distributed open-source microblogging tool
 * Copyright (C) 2009-2010, StatusNet, Inc.
 *
 * 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/>.
 */

/**
 * @package OStatusPlugin
 * @maintainer Brion Vibber <brion@status.net>
 */

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

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

/**
 * Key UI methods:
 *
 *  showInputForm() - form asking for a remote profile account or URL
 *                    We end up back here on errors
 *
 *  showPreviewForm() - surrounding form for preview-and-confirm
 *    preview() - display profile for a remote group
 *
 *  success() - redirects to groups page on join
 */
class OStatusPeopletagAction extends OStatusSubAction
{
    protected $profile_uri; // provided acct: or URI of remote entity
    protected $oprofile; // Ostatus_profile of remote entity, if valid


    function validateRemoteProfile()
    {
        if (!$this->oprofile->isPeopletag()) {
            // Send us to the user subscription form for conf
            $target = common_local_url('ostatussub', array(), array('profile' => $this->profile_uri));
            common_redirect($target, 303);
        }
    }

    /**
     * Show the initial form, when we haven't yet been given a valid
     * remote profile.
     */
    function showInputForm()
    {
        $this->elementStart('form', array('method' => 'post',
                                          'id' => 'form_ostatus_sub',
                                          'class' => 'form_settings',
                                          'action' => $this->selfLink()));

        $this->hidden('token', common_session_token());

        $this->elementStart('fieldset', array('id' => 'settings_feeds'));

        $this->elementStart('ul', 'form_data');
        $this->elementStart('li');
        $this->input('profile',
                     _m('Subscribe to people tag'),
                     $this->profile_uri,
                     _m("Address of the OStatus people tag, like http://example.net/user/all/tag"));
        $this->elementEnd('li');
        $this->elementEnd('ul');

        $this->submit('validate', _m('Continue'));

        $this->elementEnd('fieldset');

        $this->elementEnd('form');
    }

    /**
     * Show a preview for a remote peopletag's profile
     * @return boolean true if we're ok to try joining
     */
    function preview()
    {
        $oprofile = $this->oprofile;
        $ptag = $oprofile->localPeopletag();

        $cur = common_current_user();
        if ($ptag->hasSubscriber($cur->id)) {
            $this->element('div', array('class' => 'error'),
98
                           _m('You are already subscribed to this people tag.'));
Shashi Gowda's avatar
Shashi Gowda committed
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
            $ok = false;
        } else {
            $ok = true;
        }

        $this->showEntity($ptag);
        return $ok;
    }

    function showEntity($ptag)
    {
        $this->elementStart('div', 'peopletag');
        $widget = new PeopletagListItem($ptag, common_current_user(), $this);
        $widget->showCreator();
        $widget->showTag();
        $widget->showDescription();
        $this->elementEnd('div');
    }

    /**
     * Redirect on successful remote people tag subscription
     */
    function success()
    {
        $cur = common_current_user();
        $url = common_local_url('peopletagsubscriptions', array('nickname' => $cur->nickname));
        common_redirect($url, 303);
    }

    /**
     * Attempt to finalize subscription.
     * validateFeed must have been run first.
     *
     * Calls showForm on failure or success on success.
     */
    function saveFeed()
    {
        $user = common_current_user();
        $ptag = $this->oprofile->localPeopletag();
        if ($ptag->hasSubscriber($user->id)) {
            // TRANS: OStatus remote group subscription dialog error.
            $this->showForm(_m('Already subscribed!'));
            return;
        }

        try {
            Profile_tag_subscription::add($ptag, $user);
            $this->success();
        } catch (Exception $e) {
            $this->showForm($e->getMessage());
        }
    }

    /**
     * Title of the page
     *
     * @return string Title of the page
     */

    function title()
    {
        // TRANS: Page title for OStatus remote people tag subscription form
        return _m('Confirm subscription to remote people tag');
    }

    /**
     * Instructions for use
     *
     * @return instructions for use
     */

    function getInstructions()
    {
172
        // TRANS: Instructions for OStatus list subscription form.
173
        return _m('You can subscribe to lists from other supported sites. Paste the lists\'s URI below:');
Shashi Gowda's avatar
Shashi Gowda committed
174 175 176 177 178 179 180
    }

    function selfLink()
    {
        return common_local_url('ostatuspeopletag');
    }
}