]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/facebookinvite.php
ed59dda85f4bd7615ce241f2c2d06df083175e0b
[quix0rs-gnu-social.git] / actions / facebookinvite.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, 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('LACONICA')) { exit(1); }
21
22 require_once(INSTALLDIR.'/lib/facebookaction.php');
23
24 class FacebookinviteAction extends FacebookAction
25 {
26
27     function handle($args)
28     {
29         parent::handle($args);
30         $this->showForm();
31     }
32
33     /**
34      * Wrapper for showing a page
35      *
36      * Stores an error and shows the page
37      *
38      * @param string $error Error, if any
39      *
40      * @return void
41      */
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
58     function showContent()
59     {
60         if ($this->arg('ids')) {
61             $this->showSuccessContent();
62         } else {
63             $this->showFormContent();
64         }
65     }
66
67     function showSuccessContent()
68     {
69
70         $this->element('h2', null, sprintf(_('Thanks for inviting your friends to use %s'), 
71             common_config('site', 'name')));
72         $this->element('p', null, _('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
90     function showFormContent()
91     {
92
93         // Get a list of users who are already using the app for exclusion
94         $exclude_ids = $this->facebook->api_client->friends_getAppUsers();
95
96         $content = sprintf(_('You have been invited to %s'), common_config('site', 'name')) .
97             htmlentities('<fb:req-choice url="' . $this->app_uri . '" label="Add"/>');
98
99         $this->elementStart('fb:request-form', array('action' => 'invite.php',
100                                                       'method' => 'post',
101                                                       'invite' => 'true',
102                                                       'type' => common_config('site', 'name'),
103                                                       'content' => $content));
104         $this->hidden('invite', 'true');
105         $actiontext = sprintf(_('Invite your friends to use %s'), common_config('site', 'name'));
106         $this->element('fb:multi-friend-selector', array('showborder' => 'false',
107                                                                'actiontext' => $actiontext,
108                                                                'exclude_ids' => implode(',', $exclude_ids),
109                                                                'bypass' => 'cancel'));
110
111         $this->elementEnd('fb:request-form');
112
113         $this->element('h2', null, sprintf(_('Friends already using %s:'), 
114             common_config('site', 'name')));
115         $this->elementStart('ul', array('id' => 'facebook-friends'));
116         
117         foreach ($exclude_ids as $friend) {
118             $this->elementStart('li');
119             $this->element('fb:profile-pic', array('uid' => $friend, 'size' => 'square'));
120             $this->element('fb:name', array('uid' => $friend,
121                                             'capitalize' => 'true'));
122             $this->elementEnd('li');
123         }
124
125         $this->elementEnd("ul");
126     }
127     
128     function title() 
129     {
130         return sprintf(_('Send invitations'));
131     }
132
133 }