Ejemplo n.º 1
0
 /**
  * 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();
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
0
 /** 
  * 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();
 }
Ejemplo n.º 4
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);
     }
 }
Ejemplo n.º 5
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;
 }