]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Facebook/facebookinvite.php
Merge branch '0.9.x'
[quix0rs-gnu-social.git] / plugins / Facebook / facebookinvite.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2008, 2009, StatusNet, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the
14  * GNU Affero General Public License for more details.
15  *
16  * 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     exit(1);
22 }
23
24 require_once INSTALLDIR . '/plugins/Facebook/facebookaction.php';
25
26 class FacebookinviteAction extends FacebookAction
27 {
28     function handle($args)
29     {
30         parent::handle($args);
31         $this->showForm();
32     }
33
34     /**
35      * Wrapper for showing a page
36      *
37      * Stores an error and shows the page
38      *
39      * @param string $error Error, if any
40      *
41      * @return void
42      */
43     function showForm($error=null)
44     {
45         $this->error = $error;
46         $this->showPage();
47     }
48
49     /**
50      * Show the page content
51      *
52      * Either shows the registration form or, if registration was successful,
53      * instructions for using the site.
54      *
55      * @return void
56      */
57     function showContent()
58     {
59         if ($this->arg('ids')) {
60             $this->showSuccessContent();
61         } else {
62             $this->showFormContent();
63         }
64     }
65
66     function showSuccessContent()
67     {
68         // TRANS: %s is the name of the site.
69         $this->element('h2', null, sprintf(_m('Thanks for inviting your friends to use %s.'),
70             common_config('site', 'name')));
71         // TRANS: Followed by an unordered list with invited friends.
72         $this->element('p', null, _m('Invitations have been sent to the following users:'));
73
74         $friend_ids = $_POST['ids']; // XXX: Hmm... is this the best way to access the list?
75
76         $this->elementStart('ul', array('id' => 'facebook-friends'));
77
78         foreach ($friend_ids as $friend) {
79             $this->elementStart('li');
80             $this->element('fb:profile-pic', array('uid' => $friend, 'size' => 'square'));
81             $this->element('fb:name', array('uid' => $friend,
82                                             'capitalize' => 'true'));
83             $this->elementEnd('li');
84         }
85
86         $this->elementEnd('ul');
87     }
88
89     function showFormContent()
90     {
91         $content = sprintf(_m('You have been invited to %s'), common_config('site', 'name')) .
92             htmlentities('<fb:req-choice url="' . $this->app_uri . '" label="Add"/>');
93
94         $this->elementStart('fb:request-form', array('action' => 'invite.php',
95                                                       'method' => 'post',
96                                                       'invite' => 'true',
97                                                       'type' => common_config('site', 'name'),
98                                                       'content' => $content));
99         $this->hidden('invite', 'true');
100         // TRANS: %s is the name of the site.
101         $actiontext = sprintf(_m('Invite your friends to use %s'), common_config('site', 'name'));
102
103         $multi_params = array('showborder' => 'false');
104         $multi_params['actiontext'] = $actiontext;
105         $multi_params['bypass'] = 'cancel';
106         $multi_params['cols'] = 4;
107
108         // Get a list of users who are already using the app for exclusion
109         $exclude_ids = $this->facebook->api_client->friends_getAppUsers();
110         $exclude_ids_csv = null;
111
112         // fbml needs these as a csv string, not an array
113         if ($exclude_ids) {
114             $exclude_ids_csv = implode(',', $exclude_ids);
115             $multi_params['exclude_ids'] = $exclude_ids_csv;
116         }
117
118         $this->element('fb:multi-friend-selector', $multi_params);
119         $this->elementEnd('fb:request-form');
120
121         if ($exclude_ids) {
122
123             // TRANS: %s is the name of the site.
124             $this->element('h2', null, sprintf(_m('Friends already using %s:'),
125                 common_config('site', 'name')));
126             $this->elementStart('ul', array('id' => 'facebook-friends'));
127
128             foreach ($exclude_ids as $friend) {
129                 $this->elementStart('li');
130                 $this->element('fb:profile-pic', array('uid' => $friend, 'size' => 'square'));
131                 $this->element('fb:name', array('uid' => $friend,
132                                                 'capitalize' => 'true'));
133                 $this->elementEnd('li');
134             }
135
136             $this->elementEnd("ul");
137         }
138     }
139
140     function title()
141     {
142         // TRANS: Page title.
143         return sprintf(_m('Send invitations'));
144     }
145 }