/**
  * @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;
 }
示例#2
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();
 }
示例#3
0
 /**
  * Get and personalise the content for this newsletter
  * @since Version 3.10.0
  * @return \Railpage\Newsletters\Weekly
  */
 private function personaliseContent()
 {
     $replacements = array();
     Debug::LogCLI("Looping through " . count($this->recipients) . " users and preparing email decoration");
     $this->user_ids = array();
     $counter = 0;
     /**
      * Loop through our list of users and start to curate the contents
      */
     foreach ($this->recipients as $row) {
         // Flag this user ID so that we can update the "last sent" timestamp later
         $user_ids[] = $row['user_id'];
         // Sanity check : validate the email address first
         if (!filter_var($row['user_email'], FILTER_VALIDATE_EMAIL)) {
             Debug::LogCLI("Skipping user ID " . $row['user_id'] . " - \"" . $row['user_email'] . "\" is not a valid email address");
             continue;
         }
         // Add the recipient
         $this->Notification->addRecipient($row['user_id'], $row['username'], $row['user_email']);
         // Assign some decoration
         $replacements[$row['user_email']] = array("##username##" => $row['username'], "##email##" => $row['user_email'], "##email_encoded##" => urlencode($row['user_email']), "##unsubscribe##" => sprintf("http://railpage.com.au/unsubscribe?email=%s&newsletter=weekly", urlencode($row['user_email'])));
         /**
          * Get the custom news feed articles
          */
         Debug::LogCLI("Preparing personalised news for user ID " . $row['user_id']);
         // Try and create the user object. If it bombs out, we need to know about it but let the newsletter continue
         try {
             $User = UserFactory::CreateUser($row['user_id']);
         } catch (Exception $e) {
             Debug::LogCLI("Skipped user due to exception: " . $e->getMessage());
             continue;
         }
         // Create the custom news feed object
         $Feed = new Feed();
         $Feed->setUser($User);
         $articles = $Feed->addFilter(Feed::FILTER_UNREAD)->addFilter(Feed::FILTER_LAST_30_DAYS)->findArticles(0, 10, "story_hits");
         // If the number of personalised articles is less than ten, drop the filter and simply find ten recent and unread articles
         if (count($articles) < 10) {
             Debug::LogCLI("Found " . count($articles) . " articles for user ID " . $User->id . " - dropping keyword and topic filter from feed");
             $Feed->filter_words = null;
             $Feed->filter_topics = null;
             $articles = $Feed->findArticles(0, 10, "story_hits");
         }
         // If we have less than six articles skip this user altogether.
         if (count($articles) < 6) {
             Debug::LogCLI("Found " . count($articles) . " articles for user ID " . $User->id . " - skipping");
             continue;
         }
         Debug::LogCLI("Proceeding with newsletter for user ID " . $User->id);
         // Loop through each article and normalise the content
         foreach ($articles as $id => $article) {
             $article['sid'] = $article['story_id'];
             $article['catid'] = $article['topic_id'];
             $article['hometext'] = preg_replace("@(\\[b\\]|\\[\\/b\\])@", "", $article['story_blurb']);
             $article['informant'] = $article['username'];
             $article['informant_id'] = $article['user_id'];
             $article['ForumThreadId'] = $article['forum_topic_id'];
             $article['topictext'] = ContentUtility::FormatTitle($article['topic_title']);
             $article['topic'] = $article['topic_id'];
             $article['featured_image'] = ImageCache::cache($article['story_image']);
             $article['title'] = $article['story_title'];
             $article['url'] = NewsletterUtility::CreateUTMParametersForLink($this->Newsletter, $article['url']);
             $articles[$id] = $article;
         }
         $articles = array_values($articles);
         if (!isset($start)) {
             $start = 0;
         }
         // Loop through the prepended content and assign it to the blocks
         foreach ($this->prependedContent as $i => $block) {
             $tmp = ["##block" . $i . ".subtitle##" => $block['title'], "##block" . $i . ".featuredimage##" => $block['featuredimage'], "##block" . $i . ".text##" => strip_tags(wpautop(process_bbcode($block['text'])), "<br><br /><p>"), "##block" . $i . ".link##" => strpos($block['url'], "http") === false ? "http://www.railpage.com.au" . $block['url'] : $block['url'], "##block" . $i . ".alt_title##" => $block['subtitle'], "##block" . $i . ".link_text##" => isset($block['link_text']) && !empty($block['link_text']) ? $block['link_text'] : "Continue reading"];
             $replacements[$row['user_email']] = array_merge($replacements[$row['user_email']], $tmp);
         }
         // Loop through our content and assign to content blocks
         for ($i = count($this->prependedContent) + $start; $i < $start + $this->num_items; $i++) {
             $Date = new DateTime($articles[$i]['story_time']);
             $tmp = ["##block" . $i . ".subtitle##" => $articles[$i]['story_title'], "##block" . $i . ".featuredimage##" => $articles[$i]['story_image'], "##block" . $i . ".text##" => strip_tags(wpautop(process_bbcode($articles[$i]['story_lead'])), "<br><br /><p>"), "##block" . $i . ".link##" => strpos($articles[$i]['url'], "http") === false ? "http://www.railpage.com.au" . $articles[$i]['url'] : $articles[$i]['url'], "##block" . $i . ".alt_title##" => sprintf("Published %s", $Date->format("F j, Y, g:i a")), "##block" . $i . ".link_text##" => "Continue reading"];
             $replacements[$row['user_email']] = array_merge($replacements[$row['user_email']], $tmp);
         }
         Debug::LogCLI("Completed personalisation of newsletter for user ID " . $User->id);
         // Increment our personalised newsletter counter
         $counter++;
         /**
          * Break after 150 recipients. Don't want to be flagged as a spammer, or overload the MTA
          */
         if ($counter == 150) {
             break;
         }
     }
     $this->replacements = $replacements;
     return $this;
 }
 /**
  * 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;
 }
示例#5
0
 /**
  * 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;
 }
示例#6
0
 /**
  * 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;
 }