コード例 #1
0
ファイル: PushNotify.php プロジェクト: railpage/railpagecore
 /**
  * Send a push notification to all image screeners when a photo has been submitted to a competition
  * @since Version 3.10.0
  * @param \Railpage\Images\Competition $compObject
  * @param \Railpage\Images\Image $imageObject
  * @param \Railpage\Users\User $userObject
  * @return void
  * @todo finish it!
  */
 public static function photoAwaitingApproval(Competition $compObject, Image $imageObject, User $userObject)
 {
     $Push = new Notification();
     $Push->subject = sprintf("%s photo comp - new submission", $compObject->title);
     $Push->body = sprintf("A photo has been submitted to the %s photo competition by %s. Please review this photo!", $compObject->title, $userObject->username);
     $Push->setActionUrl($compObject->url->pending);
     $Push->transport = Notifications::TRANSPORT_PUSH;
     return;
     // add screeners in here. somehow
     $Push->commit()->dispatch();
 }
コード例 #2
0
ファイル: CompNotify.php プロジェクト: railpage/railpagecore
 /**
  * Notify the winner
  * @since Version 3.9.1
  * @return \Railpage\Gallery\Competition
  * @param \Railpage\Images\Competition
  * @todo Check recipient preferences for email notifications
  */
 public static function notifyWinner(Competition $compObject)
 {
     if (isset($compObject->meta['winnernotified']) && $compObject->meta['winnernotified'] === true) {
         return $this;
     }
     if ($Photo = $compObject->getWinningPhoto()) {
         /**
          * Create a news article
          */
         CompetitionUtility::createNewsArticle_Winner($compObject);
         /**
          * Create a site message
          */
         CompetitionUtility::createSiteNotificationForWinner($compObject);
         /**
          * Create an email
          */
         $Notification = new Notification();
         $Notification->AddRecipient($Photo->Author->id, $Photo->Author->username, $Photo->Author->contact_email);
         $Notification->subject = sprintf("Photo competition: %s", $compObject->title);
         /**
          * Set our email body
          */
         $body = sprintf("Hi %s,\n\nCongratulations! You won the <a href='%s'>%s</a> photo competition!\n\nAs the winner of this competition, you get to <a href='%s'>select a theme</a> for the next competition. You have seven days to do so, before we automatically select one.\n\nThanks\nThe Railpage team.", $Photo->Author->username, $compObject->url->canonical, $compObject->title, "https://www.railpage.com.au" . $compObject->url->suggestsubject);
         if (function_exists("wpautop") && function_exists("format_post")) {
             $body = wpautop(format_post($body));
         }
         /**
          * Assemble some template vars for our email
          */
         foreach ($Photo->Image->sizes as $size) {
             $hero = $size['source'];
             if ($size['width'] >= 600) {
                 break;
             }
         }
         $Smarty = AppCore::getSmarty();
         $Smarty->Assign("email", array("subject" => $Notification->subject, "hero" => array("image" => $hero, "title" => sprintf("Winning photo: Yours! <em>%s</em>", $Photo->Image->title), "link" => $compObject->url->url, "author" => $Photo->Author->username), "body" => $body));
         $Notification->body = $Smarty->Fetch($Smarty->ResolveTemplate("template.generic"));
         $Notification->commit();
         /**
          * Update the winnernotified flag
          */
         $compObject->meta['winnernotified'] = true;
         $compObject->commit();
     }
     return $compObject;
 }
コード例 #3
0
 /**
  * @depends test_createUser
  */
 public function testCreateNotification($User)
 {
     $Notification = new Notification();
     $Notification->subject = "test";
     $Notification->body = "such test, many wow";
     $Notification->Author = $User;
     $Notification->setActionUrl("https://www.google.com.au");
     $Notification->addRecipient($User->id, $User->username, $User->contact_email);
     $Notification->addHeader("blah", "thing");
     $Notification->commit();
     $Notification->dispatch();
     $Notification->getRecipients();
     return $Notification;
 }
コード例 #4
0
ファイル: Weekly.php プロジェクト: railpage/railpagecore
 /**
  * Queue the newsletter for dispatch
  * @since Version 3.10.0
  * @return \Railpage\Newsletters\Weekly
  */
 private function queue()
 {
     $this->Notification->subject = "[News] " . $this->Newsletter->subject;
     $this->Notification->body = $this->html;
     $this->Notification->meta['decoration'] = $this->replacements;
     $this->Notification->addHeader("List-Unsubscribe", "<http://railpage.com.au/unsubscribe?email=##email_encoded##&newsletter=weekly>");
     Debug::LogCLI("Queueing notification for dispatch");
     $this->Notification->commit();
     $this->Newsletter->status = Newsletter::STATUS_SENT;
     Debug::LogCLI("Commiting the newsletter to the database");
     $this->Newsletter->commit();
     /**
      * Update the last sent timestamp
      */
     foreach ($this->user_ids as $user_id) {
         $query = "INSERT INTO nuke_users_flags (user_id, newsletter_weekly_last) VALUES(" . $user_id . ", NOW()) ON DUPLICATE KEY UPDATE newsletter_weekly_last = NOW()";
         $ZendDB->query($query);
     }
     return $this;
 }
コード例 #5
0
ファイル: Message.php プロジェクト: railpage/railpagecore
 /** 
  * Send this message
  * @since Version 3.3
  * @version 3.3
  * @return boolean
  */
 public function send()
 {
     $this->validate();
     $data = array("privmsgs_type" => PRIVMSGS_UNREAD_MAIL, "privmsgs_subject" => $this->subject, "privmsgs_from_userid" => $this->from_user_id, "privmsgs_to_userid" => $this->to_user_id, "privmsgs_date" => time(), "privmsgs_ip" => encode_ip($_SERVER['REMOTE_ADDR']), "privmsgs_enable_bbcode" => $this->enable_bbcode, "privmsgs_enable_html" => $this->enable_html, "privmsgs_enable_smilies" => $this->enable_smilies, "privmsgs_attach_sig" => $this->enable_signature, "object_id" => $this->object_id);
     $this->db->insert("nuke_bbprivmsgs", $data);
     $pm_id = $this->db->lastInsertId();
     $this->id = $pm_id;
     $data = array("privmsgs_text_id" => $pm_id, "privmsgs_bbcode_uid" => $this->bbcode_uid, "privmsgs_text" => function_exists("prepare_submit") ? prepare_submit($this->body) : $this->body);
     $rs = $this->db->insert("nuke_bbprivmsgs_text", $data);
     /**
      * If the recipient doesn't want to be notified of a new message then return out
      */
     if ($this->Recipient->notify_privmsg != 1) {
         return;
     }
     /**
      * Send a push notification
      */
     $Push = new Notification();
     $Push->transport = Notifications::TRANSPORT_PUSH;
     $Push->subject = sprintf("[Private Messages] New message from %s", $this->Author->username);
     $Push->body = sprintf("%s has sent you a new private message in the conversation titled \"%s\"", $this->Author->username, $this->subject);
     $Push->setActionUrl(sprintf("/messages/conversation/%d", $this->id))->addRecipient($this->Recipient->id, $this->Recipient->username, $this->Recipient->username);
     $Push->commit()->dispatch();
     /**
      * Template settings
      */
     $Smarty = AppCore::getSmarty();
     $Smarty->assign("server_addr", "www.railpage.com.au");
     $Smarty->assign("message_id", $this->id);
     $Smarty->assign("pm_from_username", $this->Author->username);
     $Smarty->assign("userdata_username", $this->Recipient->username);
     /**
      * Create a user notification
      */
     $Notification = new Notification();
     $Notification->transport = Notifications::TRANSPORT_EMAIL;
     $Notification->status = Notifications::STATUS_QUEUED;
     $Notification->subject = sprintf("[Private Messages] New message from %s", $this->Author->username);
     $Notification->addRecipient($this->Recipient->id, $this->Recipient->username, $this->Recipient->contact_email);
     $tpl = $Smarty->ResolveTemplate("template.generic");
     $email = array("subject" => sprintf("New message from %s", $this->Author->username), "subtitle" => "Private Messages", "body" => nl2br(sprintf("Hi %s,\n\n<a href='http://www.railpage.com.au%s?utm_medium&email&utm_source=private-messages&utm_campain=user-%d'>%s</a> has sent you a new <a href='http://www.railpage.com.au/messages/conversation/%d?utm_medium=email&utm_source=private-messages&utm_campaign=user-%d#%d'>private message</a> in the conversation titled <em>%s</em>.", $this->Recipient->username, $this->Author->url->url, $this->Author->id, $this->Author->username, $this->id, $this->Author->id, $this->id, $this->subject)));
     $Smarty->Assign("email", $email);
     $Notification->body = $Smarty->fetch($tpl);
     $Notification->commit();
 }
コード例 #6
0
 /**
  * Set push notification settings for a user
  * @since Version 3.10.0
  * @param \Railpage\Users\User $User
  * @param string $subscription
  * @return void
  */
 public static function setPushSubscription(User $User, $subscription, $enabled = null)
 {
     $endpoint = false;
     $registration_id = false;
     $provider = false;
     if (strpos($subscription, "https://android.googleapis.com/gcm/send/") !== false) {
         $endpoint = "https://android.googleapis.com/gcm/send/";
         $registration_id = str_replace("https://android.googleapis.com/gcm/send/", "", $subscription);
         $provider = "google";
     }
     if (!$endpoint || !$registration_id || !$provider) {
         return;
     }
     /**
      * Subscribe
      */
     if ($enabled) {
         // Check for an existing subscription
         $query = "SELECT endpoint, registration_id FROM nuke_user_push WHERE user_id = ? AND provider = ?";
         $params = [$User->id, $provider];
         $Database = AppCore::GetDatabase();
         $result = $Database->fetchAll($query, $params);
         foreach ($result as $row) {
             if ($row['endpoint'] == $endpoint && $row['registration_id'] == $registration_id) {
                 return;
             }
         }
         // No matching subscription on record - save it
         $data = ["user_id" => $User->id, "provider" => $provider, "endpoint" => $endpoint, "registration_id" => $registration_id];
         $Database->insert("nuke_user_push", $data);
         $id = $Database->lastInsertId();
         if ((!$result || count($result) === 0) && filter_var($id, FILTER_VALIDATE_INT)) {
             try {
                 $Push = new Notification();
                 $Push->transport = Notifications::TRANSPORT_PUSH;
                 $Push->subject = "Welcome to push notifications!";
                 $Push->body = "You'll start to receive immediate notifications here when there are new posts in your subscribed threads, or a new photo competition to enter, or anything else we think you might be interested in. This feature is in early development, so please feel free to provide feedback";
                 $Push->setActionUrl("/account")->addRecipient($User->id, $User->username, $User->username);
                 $Push->commit()->dispatch();
             } catch (Exception $e) {
                 // Throw it away
             }
         }
         return;
     }
     /**
      * Unsubscribe
      */
     if ($enabled == false) {
         $where = ["registration_id = ?" => $subscription];
         $Database->delete("nuke_user_push", $where);
     }
 }
コード例 #7
0
 /**
  * Send out a notification to site admins to cast a deciding vote in the event of a tied competition
  * @since Version 3.10.0
  * @param \Railpage\Images\Competition $photoComp
  * @return void
  */
 public static function NotifyTied(Competition $photoComp)
 {
     if (isset($photoComp->meta['notifytied']) && $photoComp->meta['notifytied'] >= strtotime("-1 day")) {
         return;
     }
     $photoComp->meta['notifytied'] = time();
     $photoComp->commit();
     $Smarty = AppCore::GetSmarty();
     // User who will cast the deciding vote
     $Decider = UserFactory::CreateUser(45);
     // Create the push notification
     $Push = new Notification();
     $Push->transport = Notifications::TRANSPORT_PUSH;
     $Push->subject = "Tied photo competition";
     $Push->body = sprintf("The %s photo competition is tied. Cast a deciding vote ASAP.", $photoComp->title);
     $Push->setActionUrl($photoComp->url->tied)->addRecipient($Decider->id, $Decider->username, $Decider->username);
     $Push->commit()->dispatch();
     // Create an email notification as a backup
     $Email = new Notification();
     $Email->subject = "Tied competition: " . $photoComp->title;
     $Email->addRecipient($Decider->id, $Decider->username, $Decider->username);
     $tpl = $Smarty->ResolveTemplate("template.generic");
     $email = array("subject" => $Email->subject, "subtitle" => "Photo competitions", "body" => sprintf("<p>The <a href='%s'>%s</a>photo competition is tied and requires a deciding vote. <a href='%s'>Cast it ASAP</a>.</p>", $photoComp->url->canonical, $photoComp->title, $photoComp->url->tied));
     $Smarty->Assign("email", $email);
     $Email->body = $Smarty->fetch($tpl);
     $Email->commit();
     return;
 }
コード例 #8
0
ファイル: BanControl.php プロジェクト: railpage/railpagecore
 /**
  * Unban user
  * @since Version 3.2
  * @version 3.2
  * @param int $banId
  * @param int|bool $userId
  * @return boolean
  */
 public function unBanUser($banId, $userId = null)
 {
     $success = false;
     /**
      * Empty the cache
      */
     try {
         $this->Memcached->delete("railpage:bancontrol.users");
         $this->Memcached->delete(self::CACHE_KEY_ALL);
     } catch (Exception $e) {
         // throw it away
     }
     try {
         $this->Redis->delete("railpage:bancontrol");
     } catch (Exception $e) {
         // throw it away
     }
     if ($banId instanceof User) {
         $userId = $banId->id;
     }
     if ($userId == null) {
         $query = "SELECT user_id FROM bancontrol WHERE id = ?";
         $userId = $this->db->fetchOne($query, $banId);
     }
     if ($userId > 0) {
         $data = array("ban_active" => 0);
         $where = array("user_id = " . $userId);
         $this->db->update("bancontrol", $data, $where);
         $success = true;
         $cachekey_user = sprintf(self::CACHE_KEY_USER, $userId);
         $this->Memcached->save($cachekey_user, false, strtotime("+5 weeks"));
     }
     if ($success) {
         // Tell the world that they've been unbanned
         $ThisUser = UserFactory::CreateUser($userId);
         $ThisUser->active = 1;
         $ThisUser->location = "";
         $ThisUser->signature = "";
         $ThisUser->avatar = "";
         $ThisUser->interests = "";
         $ThisUser->occupation = "";
         try {
             $ThisUser->commit();
             $Smarty = AppCore::getSmarty();
             // Send the ban email
             $Smarty->Assign("userdata_username", $ThisUser->username);
             // Send the confirmation email
             $Notification = new Notification();
             $Notification->addRecipient($ThisUser->id, $ThisUser->username, $ThisUser->contact_email);
             $Notification->body = $Smarty->Fetch($Smarty->ResolveTemplate("email_unban"));
             $Notification->subject = "Railpage account re-activation";
             $Notification->transport = Notifications::TRANSPORT_EMAIL;
             $Notification->commit()->dispatch();
             return true;
         } catch (Exception $e) {
             global $Error;
             if (isset($Error)) {
                 $Error->save($e, $_SESSION['user_id']);
             }
             Debug::logException($e);
         }
     }
     return false;
 }
コード例 #9
0
ファイル: Reminder.php プロジェクト: railpage/railpagecore
 /**
  * Send this reminder
  * @since Version 3.8.7
  * @return \Railpage\Reminders\Reminder
  * @param boolean $markAsSent Flag to indicate if this is a test notification or not
  */
 public function send($markAsSent = false)
 {
     $this->validate();
     $Smarty = AppCore::getSmarty();
     /**
      * Set some vars
      */
     $email = array("subject" => $this->title, "body" => wpautop(format_post($this->text)));
     /**
      * Try and load the object to get some fancy stuff from it
      */
     try {
         $classname = sprintf("\\%s", $this->object);
         $Object = new $classname($this->object_id);
         $email['subtitle'] = "Railpage \\ " . $Object->Module->name;
         if (isset($Object->meta['coverphoto']) && !empty($Object->meta['coverphoto'])) {
             if ($CoverPhoto = (new Images())->getImageFromUrl($Object->meta['coverphoto'])) {
                 $email['hero'] = array("title" => isset($Object->name) ? $Object->name : $Object->title, "link" => isset($Object->url->canonical) ? $Object->url->canonical : sprintf("http://www.railpage.com.au%s", (string) $Object->url), "author" => isset($CoverPhoto->author->realname) && !empty($CoverPhoto->author->realname) ? $CoverPhoto->author->realname : $CoverPhoto->author->username);
                 if (strpos($email['hero']['link'], "http://") === false) {
                     $email['hero']['link'] = "http://www.railpage.com.au" . $email['hero']['link'];
                 }
                 if (strpos($email['hero']['link'], "railpage.com.au") === false) {
                     $email['hero']['link'] = sprintf("http://www.railpage.com.au%s", (string) $Object->url);
                 }
                 $utm = ["utm_source=reminder", "utm_medium=email", sprintf("utm_campaign=%s", ContentUtility::generateUrlSlug($this->title))];
                 $joiner = strpos($email['hero']['link'], "?") === false ? "?" : "&";
                 $email['hero']['link'] .= $joiner . implode("&", $utm);
                 foreach ($CoverPhoto->sizes as $size) {
                     if ($size >= 620) {
                         $email['hero']['image'] = $size['source'];
                     }
                 }
             }
         }
     } catch (Exception $e) {
     }
     /**
      * Process and fetch the email template
      */
     $tpl = $Smarty->ResolveTemplate("template.reminder");
     $Smarty->Assign("email", $email);
     $body = $Smarty->Fetch($tpl);
     $Notification = new Notification();
     $Notification->subject = $this->title;
     $Notification->body = $body;
     $Notification->addRecipient($this->User->id, $this->User->username, $this->User->contact_email);
     $Notification->commit();
     if ($markAsSent) {
         $this->sent = true;
         $this->Dispatched = new DateTime();
         $this->commit();
     }
     /**
      * Start composing and sending the email
      */
     /*
     $message = Swift_Message::newInstance()
         ->setSubject($this->title)
         ->setFrom(array(
             $this->Config->SMTP->username => $this->Config->SiteName
         ))
         ->setTo(array(
             $this->User->contact_email => !empty($this->User->realname) ? $this->User->realname : $this->User->username
         ))
         ->setBody($body, 'text/html');
     
     $transport = Swift_SmtpTransport::newInstance($this->Config->SMTP->host, $this->Config->SMTP->port, $this->Config->SMTP->TLS = true ? "tls" : NULL)
         ->setUsername($this->Config->SMTP->username)
         ->setPassword($this->Config->SMTP->password);
     
     $mailer = Swift_Mailer::newInstance($transport);
     
     if ($result = $mailer->send($message)) {
         if ($markAsSent) {
             $this->sent = true;
             $this->Dispatched = new DateTime;
             $this->commit();
         }
     }
     */
     return $this;
 }