]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/invite.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / actions / invite.php
index 0e3a878f2eb49792bfd198e1db7e9e72b6304a81..0deb7a76ee2d997a5dd66236fc5fc1774e31e1cc 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
+if (!defined('GNUSOCIAL')) { exit(1); }
 
 // @todo XXX: Add documentation.
-class InviteAction extends CurrentUserDesignAction
+class InviteAction extends Action
 {
     var $mode = null;
     var $error = null;
@@ -33,12 +33,12 @@ class InviteAction extends CurrentUserDesignAction
         return;
     }
 
-    function isReadOnly($args)
+    function isReadOnly(array $args=array())
     {
         return false;
     }
 
-    function handle($args)
+    function handle(array $args=array())
     {
         parent::handle($args);
         if (!common_config('invite', 'enabled')) {
@@ -60,7 +60,6 @@ class InviteAction extends CurrentUserDesignAction
     function sendInvitations()
     {
         if (Event::handle('StartSendInvitations', array(&$this))) {
-
             // CSRF protection
             $token = $this->trimmed('token');
             if (!$token || $token != common_session_token()) {
@@ -75,6 +74,7 @@ class InviteAction extends CurrentUserDesignAction
             $bestname = $profile->getBestName();
             $sitename = common_config('site', 'name');
             $personal = $this->trimmed('personal');
+            $language = $this->trimmed('language');
 
             $addresses = explode("\n", $this->trimmed('addresses'));
             foreach ($addresses as $email) {
@@ -112,17 +112,24 @@ class InviteAction extends CurrentUserDesignAction
 
             foreach ($addresses as $email) {
                 $email = common_canonical_email($email);
-                $other = User::staticGet('email', $email);
-                if ($other) {
+                try {
+                    // If this user is already registered, subscribe to it!
+                    $other = Profile::getByEmail($email);
                     if ($user->isSubscribed($other)) {
                         $this->already[] = $other;
                     } else {
-                        subs_subscribe_to($user, $other);
-                        $this->subbed[] = $other;
+                        try {
+                            Subscription::ensureStart($profile, $other);
+                            $this->subbed[] = $other;
+                        } catch (Exception $e) {
+                            // subscription failed, but keep working
+                            common_debug('Invitation-based subscription failed: '.$e->getMessage());
+                        }
                     }
-                } else {
+                } catch (NoSuchUserException $e) {
+                    // If email was not known, let's send an invite!
                     $this->sent[] = $email;
-                    $this->sendInvitation($email, $user, $personal);
+                    $this->sendInvitation($email, $user, $personal, $language);
                 }
             }
 
@@ -162,7 +169,6 @@ class InviteAction extends CurrentUserDesignAction
     function showInvitationSuccess()
     {
         if (Event::handle('StartShowInvitationSuccess', array($this))) {
-
             if ($this->already) {
                 // TRANS: Message displayed inviting users to use a StatusNet site while the inviting user
                 // TRANS: is already subscribed to one or more users with the given e-mail address(es).
@@ -243,7 +249,7 @@ class InviteAction extends CurrentUserDesignAction
         }
     }
 
-    function sendInvitation($email, $user, $personal)
+    function sendInvitation($email, $user, $personal, $language)
     {
         $profile = $user->getProfile();
         $bestname = $profile->getBestName();
@@ -279,7 +285,7 @@ class InviteAction extends CurrentUserDesignAction
         $title = (empty($personal)) ? 'invite' : 'invitepersonal';
 
         // @todo FIXME: i18n issue.
-        $inviteTemplate = DocFile::forTitle($title, DocFile::mailPaths());
+        $inviteTemplate = DocFile::forTitle($title, DocFile::mailPaths(), $language);
 
         $body = $inviteTemplate->toHTML(array('inviter' => $bestname,
                                               'inviterurl' => $profile->profileurl,