3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, 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('LACONICA')) { exit(1); }
22 class InviteAction extends Action {
24 function is_readonly() {
28 function handle($args) {
29 parent::handle($args);
30 if (!common_logged_in()) {
31 $this->client_error(sprintf(_('You must be logged in to invite other users to use %s'),
32 common_config('site', 'name')));
34 } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
35 $this->send_invitation();
41 function send_invitation() {
43 $user = common_current_user();
44 $profile = $user->getProfile();
46 $bestname = $profile->getBestName();
47 $sitename = common_config('site', 'name');
48 $personal = $this->trimmed('personal');
50 $addresses = explode("\n", $this->trimmed('addresses'));
52 foreach ($addresses as $email) {
54 $email = trim($email);
56 if (!Validate::email($email, true)) {
57 $this->show_form(sprintf(_('Invalid email address: %s'), $email));
62 foreach ($addresses as $email) {
64 $email = trim($email);
66 $recipients = array($email);
68 $headers['From'] = mail_notify_from();
69 $headers['To'] = $email;
70 $headers['Subject'] = sprintf(_('%1s has invited you to join them on %2s'), $bestname, $sitename);
72 $body = sprintf(_("%1s has invited you to join them on %2s (%3s).\n\n".
73 "%4s is a micro-blogging service that lets you keep up-to-date with people you know and people who interest you.\n\n".
74 "You can also share news about yourself, your thoughts, or your life online with people who know about you.\n\n".
75 "%5s said:\n\n%6s\n\n".
76 "You can see %7s's profile page on %8s here:\n\n".
78 "If you'd like to try the service, click on the link below to accept the invitation.\n\n".
80 "If not, you can ignore this message. Thanks for your patience and your time.\n\n".
82 $bestname, $sitename, common_root_url(),
86 common_local_url('showstream', array('nickname' => $user->nickname)),
87 common_local_url('register', array('code' => $invite->code)),
90 mail_send($recipients, $headers, $body);
94 common_show_header(_('Invitation(s) sent'));
95 common_element('p', NULL, _('Invitation(s) sent. You will be notified when your invitees accept the invitation and register on the site. Thanks for growing the community!'));
99 function show_top($error=NULL) {
101 common_element('p', 'error', $error);
103 common_element_start('div', 'instructions');
104 common_element('p', NULL,
105 _('Use this form to invite your friends and colleagues to use this service.'));
106 common_element_end('div');
110 function show_form($error=NULL) {
114 common_show_header(_('Invite new users'), NULL, $error, array($this, 'show_top'));
116 common_element_start('form', array('method' => 'post',
118 'action' => common_local_url('invite')));
120 common_textarea('addresses', _('Email addresses'),
121 $this->trimmed('addresses'),
122 _('Addresses of friends to invite (one per line)'));
124 common_textarea('personal', _('Personal message'),
125 $this->trimmed('personal'),
126 _('Optionally add a personal message to the invitation.'));
128 common_submit('preview', _('Preview'));
130 common_element_end('form');
132 common_show_footer();