facebookinvite.php 4.63 KB
Newer Older
1 2
<?php
/*
3
 * StatusNet - the distributed open-source microblogging tool
4
 * Copyright (C) 2008, 2009, StatusNet, Inc.
5 6 7 8 9 10 11 12
 *
 * 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
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the
14 15 16
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
17
 * along with this program.     If not, see <http://www.gnu.org/licenses/>.
18 19
 */

20
if (!defined('STATUSNET') && !defined('LACONICA')) {
21 22
    exit(1);
}
23 24 25

require_once(INSTALLDIR.'/lib/facebookaction.php');

26 27
class FacebookinviteAction extends FacebookAction
{
28

29 30
    function handle($args)
    {
31
        parent::handle($args);
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
        $this->showForm();
    }

    /**
     * Wrapper for showing a page
     *
     * Stores an error and shows the page
     *
     * @param string $error Error, if any
     *
     * @return void
     */

    function showForm($error=null)
    {
        $this->error = $error;
        $this->showPage();
    }
50

51 52 53 54 55 56 57 58 59 60 61
    /**
     * Show the page content
     *
     * Either shows the registration form or, if registration was successful,
     * instructions for using the site.
     *
     * @return void
     */

    function showContent()
    {
62
        if ($this->arg('ids')) {
63
            $this->showSuccessContent();
64
        } else {
65
            $this->showFormContent();
66
        }
67
    }
68

69
    function showSuccessContent()
70
    {
71

72
        $this->element('h2', null, sprintf(_('Thanks for inviting your friends to use %s'),
73
            common_config('site', 'name')));
74
        $this->element('p', null, _('Invitations have been sent to the following users:'));
75

76
        $friend_ids = $_POST['ids']; // XXX: Hmm... is this the best way to access the list?
77

78
        $this->elementStart('ul', array('id' => 'facebook-friends'));
79 80

        foreach ($friend_ids as $friend) {
81
            $this->elementStart('li');
82
            $this->element('fb:profile-pic', array('uid' => $friend, 'size' => 'square'));
83
            $this->element('fb:name', array('uid' => $friend,
84
                                            'capitalize' => 'true'));
85
            $this->elementEnd('li');
86 87
        }

88
        $this->elementEnd("ul");
89 90 91

    }

92
    function showFormContent()
93
    {
94 95
        $content = sprintf(_('You have been invited to %s'), common_config('site', 'name')) .
            htmlentities('<fb:req-choice url="' . $this->app_uri . '" label="Add"/>');
96

97
        $this->elementStart('fb:request-form', array('action' => 'invite.php',
98
                                                      'method' => 'post',
99
                                                      'invite' => 'true',
100
                                                      'type' => common_config('site', 'name'),
101
                                                      'content' => $content));
102
        $this->hidden('invite', 'true');
103
        $actiontext = sprintf(_('Invite your friends to use %s'), common_config('site', 'name'));
104 105

        $multi_params = array('showborder' => 'false');
106
        $multi_params['actiontext'] = $actiontext;
107 108 109 110 111 112 113 114 115
        $multi_params['bypass'] = 'cancel';

        // Get a list of users who are already using the app for exclusion
        $exclude_ids = $this->facebook->api_client->friends_getAppUsers();
        $exclude_ids_csv = null;

        // fbml needs these as a csv string, not an array
        if ($exclude_ids) {
            $exclude_ids_csv = implode(',', $exclude_ids);
116 117 118 119
            $multi_params['exclude_ids'] = $exclude_ids_csv;
        }

        $this->element('fb:multi-friend-selector', $multi_params);
120
        $this->elementEnd('fb:request-form');
121

122
        if ($exclude_ids) {
123

124 125 126 127 128 129 130 131 132 133 134 135 136 137
            $this->element('h2', null, sprintf(_('Friends already using %s:'),
                common_config('site', 'name')));
            $this->elementStart('ul', array('id' => 'facebook-friends'));

            foreach ($exclude_ids as $friend) {
                $this->elementStart('li');
                $this->element('fb:profile-pic', array('uid' => $friend, 'size' => 'square'));
                $this->element('fb:name', array('uid' => $friend,
                                                'capitalize' => 'true'));
                $this->elementEnd('li');
            }

            $this->elementEnd("ul");
        }
138
    }
139 140

    function title()
141 142
    {
        return sprintf(_('Send invitations'));
143
    }
144 145

}