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(); }
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(); } } }
/** * Loads a message either from the database or create it from scratch for * custom messages. * * @param integer $message_id * The ID of the message to load. * @param boolean $unsubscribe * Whether to include the ubsubscribe link when sending. * @param boolean $auto * Whether this is called as an automatic mailer. */ public function __construct($message_id = null, $unsubscribe = true, $auto = true) { $this->auto = $auto; $this->__data = Database::getInstance()->selectRow('message', array('message_id' => $message_id)); $this->loadTemplate(); $this->unsubscribe = $unsubscribe; if (empty(self::$message_sent_id)) { self::$message_sent_id = Tracker::getTrackerId('Email Sent'); } if ($default_name_settings = Configuration::get('mailer.default_name')) { $this->default_name = $default_name_settings; } $this->setCombinedMessageTemplate(); $this->loadVariablesFromTemplate(); }