/** * 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"; }
/** * 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); }
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(); } } }
/** * 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; } }