public function testExpireInvitation()
 {
     $inv = Api_Dao_FriendInvitation::createInvitation(100001, 3600);
     $inv_record = Api_Dao_FriendInvitation::getInvitation($inv);
     $inv_record->expires = time();
     $inv_record->save();
     Api_Dao_FriendInvitation::deleteAllExpired();
     $inv_record = Api_Dao_FriendInvitation::getInvitation($inv);
     $this->assertFalse($inv_record);
 }
Example #2
0
 public static function inviteFriendsByEmail($uid, $domain, $rsvp, $emails)
 {
     if (!is_array($emails)) {
         $emails = array($emails);
     }
     // Always collect the garbage whenever interacting with the FriendInvitation table
     Api_Dao_FriendInvitation::deleteAllExpired();
     $inv = Api_Dao_FriendInvitation::createInvitation($uid, self::FRIEND_INVITATION_MAX_AGE);
     // Make sure all the email addresses are well-formed and trimmed
     $fixed_emails = array();
     foreach ($emails as $email) {
         $email = trim($email);
         if (strchr($email, '@')) {
             $fixed_emails[] = trim($email);
         }
     }
     // Get user info for the sending user
     $ps = Api_Bo_UserProfileService::create();
     $uid_info = $ps->getProfiles(array($uid), array($domain), array('first_name', 'last_name'));
     $uid_info = $uid_info[0];
     // TODO: Replace with a queue
     // Send a bunch of emails
     $subject = 'Friend request from ' . $uid_info['first_name'] . ' ' . $uid_info['last_name'];
     // Just making sure...
     str_replace("\r\n", ' ', $subject);
     $base_message = "{$uid_info['first_name']} {$uid_info['last_name']} has invited you to be their friend. Click the link below to connect with them.\n\n";
     // TODO: Migrate to SMTPConfig.php?
     @(include 'LocalSettings.php');
     $headers = array('From' => str_replace("\r\n", ' ', '"' . $uid_info['first_name'] . ' ' . $uid_info['last_name'] . "\" <{$smtp_default_sender}>"), 'Subject' => str_replace("\r\n", ' ', 'Friend request from ' . $uid_info['first_name'] . ' ' . $uid_info['last_name']));
     $smtp = Mail::factory('smtp', array('host' => $smtp_server, 'auth' => $smtp_use_auth, 'username' => $smtp_username, 'password' => $smtp_password));
     //        $rsvp = 'http://' . $_SERVER['HTTP_HOST'] . RingsideWebConfig::$webRoot . '/friends.php?view=view_invites';
     foreach ($fixed_emails as $email) {
         // Append the inv=<inv_key> string to the end of the RSVP URL
         $my_rsvp = $rsvp . (strpos($rsvp, '?') !== false ? '&' : '?') . 'inv=' . $inv;
         $message = $base_message . '<' . $my_rsvp . '>';
         //            error_log("Sending to $email: $message");
         $headers['To'] = $email;
         $mail = $smtp->send($email, $headers, $message);
         if (PEAR::isError($mail)) {
             error_log("Failed to send email to {$email}: " . $mail->getMessage());
             return false;
         } else {
             error_log("Message sent");
         }
     }
     return $inv;
 }