]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/invite.php
Merge branch '0.8.x' of git://gitorious.org/~brion/statusnet/brion-fixes into 0.8.x
[quix0rs-gnu-social.git] / actions / invite.php
index b0fc799589a5ae2f1ace55990cbccf2c6272ef68..9fa6a76f671f471a83b13b590db846401fd6b039 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
- * Laconica - a distributed open-source microblogging tool
- * Copyright (C) 2008, Controlez-Vous, Inc.
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2008, 2009, StatusNet, Inc.
  *
  * 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
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-if (!defined('LACONICA')) { exit(1); }
+if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
 
-class InviteAction extends Action {
+class InviteAction extends CurrentUserDesignAction
+{
+    var $mode = null;
+    var $error = null;
+    var $already = null;
+    var $subbed = null;
+    var $sent = null;
 
-    function is_readonly()
+    function isReadOnly($args)
     {
         return false;
     }
@@ -29,24 +35,25 @@ class InviteAction extends Action {
     function handle($args)
     {
         parent::handle($args);
-        if (!common_logged_in()) {
-            $this->client_error(sprintf(_('You must be logged in to invite other users to use %s'),
+        if (!common_config('invite', 'enabled')) {
+            $this->clientError(_('Invites have been disabled.'));
+        } else if (!common_logged_in()) {
+            $this->clientError(sprintf(_('You must be logged in to invite other users to use %s'),
                                         common_config('site', 'name')));
             return;
         } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
-            $this->send_invitations();
+            $this->sendInvitations();
         } else {
-            $this->show_form();
+            $this->showForm();
         }
     }
 
-    function send_invitations()
+    function sendInvitations()
     {
-
         # CSRF protection
         $token = $this->trimmed('token');
         if (!$token || $token != common_session_token()) {
-            $this->show_form(_('There was a problem with your session token. Try again, please.'));
+            $this->showForm(_('There was a problem with your session token. Try again, please.'));
             return;
         }
 
@@ -62,101 +69,138 @@ class InviteAction extends Action {
         foreach ($addresses as $email) {
             $email = trim($email);
             if (!Validate::email($email, true)) {
-                $this->show_form(sprintf(_('Invalid email address: %s'), $email));
+                $this->showForm(sprintf(_('Invalid email address: %s'), $email));
                 return;
             }
         }
 
-        $already = array();
-        $subbed = array();
+        $this->already = array();
+        $this->subbed = array();
 
         foreach ($addresses as $email) {
             $email = common_canonical_email($email);
             $other = User::staticGet('email', $email);
             if ($other) {
                 if ($user->isSubscribed($other)) {
-                    $already[] = $other;
+                    $this->already[] = $other;
                 } else {
                     subs_subscribe_to($user, $other);
-                    $subbed[] = $other;
+                    $this->subbed[] = $other;
                 }
             } else {
-                $sent[] = $email;
-                $this->send_invitation($email, $user, $personal);
+                $this->sent[] = $email;
+                $this->sendInvitation($email, $user, $personal);
             }
         }
 
-        common_show_header(_('Invitation(s) sent'));
-        if ($already) {
-            common_element('p', null, _('You are already subscribed to these users:'));
-            common_element_start('ul');
-            foreach ($already as $other) {
-                common_element('li', null, sprintf(_('%s (%s)'), $other->nickname, $other->email));
+        $this->mode = 'sent';
+
+        $this->showPage();
+    }
+
+    function showScripts()
+    {
+        parent::showScripts();
+        $this->autofocus('addresses');
+    }
+
+    function title()
+    {
+        if ($this->mode == 'sent') {
+            return _('Invitation(s) sent');
+        } else {
+            return _('Invite new users');
+        }
+    }
+
+    function showContent()
+    {
+        if ($this->mode == 'sent') {
+            $this->showInvitationSuccess();
+        } else {
+            $this->showInviteForm();
+        }
+    }
+
+    function showInvitationSuccess()
+    {
+        if ($this->already) {
+            $this->element('p', null, _('You are already subscribed to these users:'));
+            $this->elementStart('ul');
+            foreach ($this->already as $other) {
+                $this->element('li', null, sprintf(_('%s (%s)'), $other->nickname, $other->email));
             }
-            common_element_end('ul');
+            $this->elementEnd('ul');
         }
-        if ($subbed) {
-            common_element('p', null, _('These people are already users and you were automatically subscribed to them:'));
-            common_element_start('ul');
-            foreach ($subbed as $other) {
-                common_element('li', null, sprintf(_('%s (%s)'), $other->nickname, $other->email));
+        if ($this->subbed) {
+            $this->element('p', null, _('These people are already users and you were automatically subscribed to them:'));
+            $this->elementStart('ul');
+            foreach ($this->subbed as $other) {
+                $this->element('li', null, sprintf(_('%s (%s)'), $other->nickname, $other->email));
             }
-            common_element_end('ul');
+            $this->elementEnd('ul');
         }
-        if ($sent) {
-            common_element('p', null, _('Invitation(s) sent to the following people:'));
-            common_element_start('ul');
-            foreach ($sent as $other) {
-                common_element('li', null, $other);
+        if ($this->sent) {
+            $this->element('p', null, _('Invitation(s) sent to the following people:'));
+            $this->elementStart('ul');
+            foreach ($this->sent as $other) {
+                $this->element('li', null, $other);
             }
-            common_element_end('ul');
-            common_element('p', null, _('You will be notified when your invitees accept the invitation and register on the site. Thanks for growing the community!'));
+            $this->elementEnd('ul');
+            $this->element('p', null, _('You will be notified when your invitees accept the invitation and register on the site. Thanks for growing the community!'));
         }
-        common_show_footer();
     }
 
-    function show_top($error=null)
+    function showPageNotice()
     {
-        if ($error) {
-            common_element('p', 'error', $error);
-        } else {
-            common_element_start('div', 'instructions');
-            common_element('p', null,
-                           _('Use this form to invite your friends and colleagues to use this service.'));
-            common_element_end('div');
+        if ($this->mode != 'sent') {
+            if ($this->error) {
+                $this->element('p', 'error', $this->error);
+            } else {
+                $this->elementStart('div', 'instructions');
+                $this->element('p', null,
+                               _('Use this form to invite your friends and colleagues to use this service.'));
+                $this->elementEnd('div');
+            }
         }
     }
 
-    function show_form($error=null)
+    function showForm($error=null)
     {
+        $this->mode = 'form';
+        $this->error = $error;
+        $this->showPage();
+    }
 
-        global $config;
-
-        common_show_header(_('Invite new users'), null, $error, array($this, 'show_top'));
-
-        common_element_start('form', array('method' => 'post',
-                                           'id' => 'invite',
+    function showInviteForm()
+    {
+        $this->elementStart('form', array('method' => 'post',
+                                           'id' => 'form_invite',
+                                           'class' => 'form_settings',
                                            'action' => common_local_url('invite')));
-        common_hidden('token', common_session_token());
+        $this->elementStart('fieldset');
+        $this->element('legend', null, 'Send an invitation');
+        $this->hidden('token', common_session_token());
 
-        common_textarea('addresses', _('Email addresses'),
+        $this->elementStart('ul', 'form_data');
+        $this->elementStart('li');
+        $this->textarea('addresses', _('Email addresses'),
                         $this->trimmed('addresses'),
                         _('Addresses of friends to invite (one per line)'));
-
-        common_textarea('personal', _('Personal message'),
+        $this->elementEnd('li');
+        $this->elementStart('li');
+        $this->textarea('personal', _('Personal message'),
                         $this->trimmed('personal'),
                         _('Optionally add a personal message to the invitation.'));
-
-        common_submit('send', _('Send'));
-
-        common_element_end('form');
-
-        common_show_footer();
+        $this->elementEnd('li');
+        $this->elementEnd('ul');
+        $this->submit('send', _('Send'));
+        $this->elementEnd('fieldset');
+        $this->elementEnd('form');
     }
 
-    function send_invitation($email, $user, $personal)
+    function sendInvitation($email, $user, $personal)
     {
-
         $profile = $user->getProfile();
         $bestname = $profile->getBestName();
 
@@ -178,7 +222,7 @@ class InviteAction extends Action {
         $recipients = array($email);
 
         $headers['From'] = mail_notify_from();
-        $headers['To'] = $email;
+        $headers['To'] = trim($email);
         $headers['Subject'] = sprintf(_('%1$s has invited you to join them on %2$s'), $bestname, $sitename);
 
         $body = sprintf(_("%1\$s has invited you to join them on %2\$s (%3\$s).\n\n".
@@ -197,9 +241,14 @@ class InviteAction extends Action {
                         common_root_url(),
                         $personal,
                         common_local_url('showstream', array('nickname' => $user->nickname)),
-                        common_local_url('register', array('code' => $invite->code)));
+                        common_local_url((!common_config('site', 'openidonly')) ? 'register' : 'openidlogin', array('code' => $invite->code)));
 
         mail_send($recipients, $headers, $body);
     }
 
+    function showLocalNav()
+    {
+        $nav = new SubGroupNav($this, common_current_user());
+        $nav->show();
+    }
 }