Beispiel #1
1
 /**
  * Send the current message to the current list of users.
  */
 protected function sendToList()
 {
     $this->sentCount = 0;
     foreach ($this->users as $user) {
         if ($this->verbose && $this->sentCount % 100 == 0) {
             set_time_limit(60);
             echo '. ';
         }
         // Send message.
         $this->to($user['email'], $user['first'] . ' ' . $user['last']);
         $from = !empty($user['from']) ? $user['from'] : $this->from;
         $from_name = !empty($user['from_name']) ? $user['from_name'] : $this->fromName;
         $this->from($from, $from_name);
         $this->message->setUser(new User($user));
         $this->message->setDefaultVars();
         $this->subject($this->message->getSubject());
         $this->message($this->message->getMessage());
         if ($this->sendMessage()) {
             $this->sentCount++;
         }
         $this->mailer->ClearAddresses();
         Tracker::trackEvent('Email Sent', $this->message->id, !empty($user['user_id']) ? $user['user_id'] : 0);
     }
     echo "\n\n";
 }
Beispiel #2
0
 public function getTrackerStats()
 {
     $data = array('datasets' => array());
     $start = Request::get('start', 'int') ?: -30;
     $end = Request::get('end', 'int') ?: 0;
     $sub_id = -1;
     $user_id = -1;
     $tracker = NULL;
     foreach ($_GET['sets'] as $set) {
         $tracker = isset($set['tracker']) ? intval($set['tracker']) : $tracker;
         $sub_id = isset($set['sub_id']) ? intval($set['sub_id']) : $sub_id;
         $user_id = isset($set['user_id']) ? intval($set['user_id']) : $user_id;
         if (empty($tracker)) {
             throw new \Exception('Invalid tracker');
         }
         $data['datasets'][] = array('data' => array_values(Tracker::getHistory($tracker, $start, $end, $sub_id, $user_id)), 'label' => Tracker::getName($tracker));
     }
     $data['labels'] = array();
     $start += Time::today();
     $end += Time::today();
     for ($i = $start; $i <= $end; $i++) {
         $data['labels'][] = jdtogregorian($i);
     }
     Output::json($data);
 }
Beispiel #3
0
 public function getGetData()
 {
     $start = Request::get('start', 'int', null, -30);
     $end = Request::get('end', 'int', null, 0);
     $message_id = Request::get('message_id', 'int');
     $tracker = new Tracker();
     $email_sent = $tracker->getHistory(Tracker::getTrackerId('Email Sent'), $start, $end, $message_id);
     $email_bounced = $tracker->getHistory(Tracker::getTrackerId('Email Bounced'), $start, $end, $message_id);
     $email_opened = $tracker->getHistory(Tracker::getTrackerId('Email Opened'), $start, $end, $message_id);
     $data = new ChartData(Time::today() + $start, Time::today() + $end);
     $data->addDataSet($email_sent, 'Sent');
     $data->addDataSet($email_bounced, 'Bounced');
     $data->addDataSet($email_opened, 'Opened');
     $data->setXLabels(array_map('jdtogregorian', range(Time::today() + $start, Time::today() + $end)));
     $data->output();
 }
Beispiel #4
0
 /**
  * Does not require encryption, uses token.
  */
 public function post()
 {
     $user = ClientUser::getInstance()->id;
     // TODO: These can be spoofed.
     // A verification method is needed.
     $tracker = Request::post('tracker');
     $sub = Request::post('id', 'int');
     // Track.
     Tracker::trackEvent($tracker, $sub, $user);
     Output::json(Output::SUCCESS);
 }
Beispiel #5
0
 public function execute()
 {
     // Load the bounce handler.
     require_once HOME_PATH . '/Lightning/Vendor/BounceHandler/src/BounceHandler.php';
     $bounce_handler = new \cfortune\PHPBounceHandler\BounceHandler();
     // Parse the message.
     $bounce_info = $bounce_handler->get_the_facts(file_get_contents('php://stdin'));
     // If this was a message failure.
     if (!empty($bounce_info[0]['recipient']) && preg_match('/5\\.\\d\\.\\d/', $bounce_info[0]['status'])) {
         $email = $bounce_info[0]['recipient'];
         $user = User::loadByEmail($email);
         if (!$user) {
             // Bounced from an unknown recipient, ignore this.
             Tracker::trackEvent('Email Bounced', 0, 0);
             return;
         }
         // Track the bounced event.
         // TODO: we can scan the email for a link to see if we know the message id.
         Tracker::trackEvent('Email Bounced', 0, $user->user_id);
         // Get the last 6 send/bounce events.
         // TODO: Also check for a reactivation email.
         $mail_history = Database::getInstance()->select('tracker_event', array('user_id' => $user->user_id, 'tracker_id' => array('IN', array(Tracker::getTrackerId('Email Sent'), Tracker::getTrackerId('Email Bounced')))), array(), 'ORDER BY date DESC LIMIT 6');
         $bounce_count = 0;
         $bounce_id = Tracker::getTrackerId('Email Bounced');
         foreach ($mail_history as $history) {
             if ($history['tracker_id'] == $bounce_id) {
                 $bounce_count++;
             }
         }
         // If there are two bounced messages, deactivate the user.
         if ($bounce_count >= 2) {
             // TODO: Instead of '1' here, we should have a table like `tracker`
             // that tracks tracker sub_ids by name.
             Tracker::trackEvent('Deactivate User', 1, $user->user_id);
             $user->unsubscribeAll();
         }
     }
 }
Beispiel #6
0
 /**
  * Add the user to the mailing list.
  *
  * @param $list_id
  *   The ID of the mailing list.
  *
  * @return boolean
  *   Whether they were actually inserted.
  */
 public function subscribe($list_id)
 {
     if (Database::getInstance()->insert('message_list_user', array('message_list_id' => $list_id, 'user_id' => $this->id, 'time' => time()), true)) {
         // If a result was returned, they were added to the list.
         Tracker::trackEvent('Subscribe', $list_id, $this->id);
         return true;
     } else {
         // They were already in the list.
         return false;
     }
 }
Beispiel #7
0
 /**
  * Sets default variables for db and chainable messages
  * 
  * @param array $vars
  *   Variables to set for chainable messages
  */
 public function setDefaultVars($vars = null)
 {
     /*
      * If there's no 'message' variable set, it's a custom message, 
      * so we don't replace any variables except custom ones.
      */
     if (!empty($this->message_id)) {
         $tracking_image = Tracker::getTrackerImage('Email Opened', $this->message_id, $this->user->id);
         // Replace standard variables.
         $this->defaultVariables = ['USER_ID' => $this->user->id, 'MESSAGE_ID' => $this->message_id, 'FULL_NAME' => !empty($this->user->first) ? $this->user->fullName() : $this->default_name, 'URL_KEY' => !empty($this->user->id) ? User::urlKey($this->user->id, $this->user->salt) : '', 'EMAIL' => $this->user->email, 'UNSUBSCRIBE' => $this->unsubscribe && !empty($this->user->user_id) ? $this->getUnsubscribeString() : '', 'TRACKING_IMAGE' => $tracking_image];
     } else {
         $this->defaultVariables = ['UNSUBSCRIBE' => $this->unsubscribe && !empty($this->user->user_id) ? $this->getUnsubscribeString() : '', 'TRACKING_IMAGE' => ''];
         if (!empty($vars)) {
             $this->defaultVariables += $vars;
         }
     }
 }