3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2008, 2009, StatusNet, Inc.
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.
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.
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/>.
20 if (!defined('STATUSNET') && !defined('LACONICA')) {
24 require_once INSTALLDIR . '/plugins/Facebook/facebookaction.php';
26 class FacebookinviteAction extends FacebookAction
29 function handle($args)
31 parent::handle($args);
36 * Wrapper for showing a page
38 * Stores an error and shows the page
40 * @param string $error Error, if any
45 function showForm($error=null)
47 $this->error = $error;
52 * Show the page content
54 * Either shows the registration form or, if registration was successful,
55 * instructions for using the site.
60 function showContent()
62 if ($this->arg('ids')) {
63 $this->showSuccessContent();
65 $this->showFormContent();
69 function showSuccessContent()
72 $this->element('h2', null, sprintf(_m('Thanks for inviting your friends to use %s'),
73 common_config('site', 'name')));
74 $this->element('p', null, _m('Invitations have been sent to the following users:'));
76 $friend_ids = $_POST['ids']; // XXX: Hmm... is this the best way to access the list?
78 $this->elementStart('ul', array('id' => 'facebook-friends'));
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');
88 $this->elementEnd("ul");
92 function showFormContent()
94 $content = sprintf(_m('You have been invited to %s'), common_config('site', 'name')) .
95 htmlentities('<fb:req-choice url="' . $this->app_uri . '" label="Add"/>');
97 $this->elementStart('fb:request-form', array('action' => 'invite.php',
100 'type' => common_config('site', 'name'),
101 'content' => $content));
102 $this->hidden('invite', 'true');
103 $actiontext = sprintf(_m('Invite your friends to use %s'), common_config('site', 'name'));
105 $multi_params = array('showborder' => 'false');
106 $multi_params['actiontext'] = $actiontext;
107 $multi_params['bypass'] = 'cancel';
108 $multi_params['cols'] = 4;
110 // Get a list of users who are already using the app for exclusion
111 $exclude_ids = $this->facebook->api_client->friends_getAppUsers();
112 $exclude_ids_csv = null;
114 // fbml needs these as a csv string, not an array
116 $exclude_ids_csv = implode(',', $exclude_ids);
117 $multi_params['exclude_ids'] = $exclude_ids_csv;
120 $this->element('fb:multi-friend-selector', $multi_params);
121 $this->elementEnd('fb:request-form');
125 $this->element('h2', null, sprintf(_m('Friends already using %s:'),
126 common_config('site', 'name')));
127 $this->elementStart('ul', array('id' => 'facebook-friends'));
129 foreach ($exclude_ids as $friend) {
130 $this->elementStart('li');
131 $this->element('fb:profile-pic', array('uid' => $friend, 'size' => 'square'));
132 $this->element('fb:name', array('uid' => $friend,
133 'capitalize' => 'true'));
134 $this->elementEnd('li');
137 $this->elementEnd("ul");
143 return sprintf(_m('Send invitations'));