/**
  * 
  */
 public function index()
 {
     global $wpdb;
     $schedule = new Bbpp_ThankMeLater_Schedule();
     // get the total number of messages which are sent
     $total_num_sent = $schedule->findNum(1);
     $total_num_opened = $wpdb->get_var("SELECT COUNT(*) FROM `{$wpdb->prefix}bbpp_thankmelater_opens`");
     $total_num_scheduled = $schedule->findNum(0);
     $day_stats = array("data" => array(), "labels" => array());
     $ind = 0;
     $day_start = mktime(0, 0, 0, date("m"), date("d") - 30, date("Y"));
     $day_start_last = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
     while ($day_start <= $day_start_last) {
         $day_start_gmt = gmdate("Y-m-d H:i:s", $day_start);
         $day_end_gmt = gmdate("Y-m-d H:i:s", $day_start + 86400 - 1);
         $day_stats["data"][] = array($ind, $schedule->findSentBetween($day_start_gmt, $day_end_gmt));
         $day_stats["labels"][] = array($ind, date_i18n("d", $day_start, false));
         $day_start += 86400;
         $ind++;
     }
     $open_stats = array("data" => array(), "labels" => array());
     $ind = 0;
     $day_start = mktime(0, 0, 0, date("m"), date("d") - 30, date("Y"));
     $day_start_last = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
     while ($day_start <= $day_start_last) {
         $day_start_gmt = gmdate("Y-m-d H:i:s", $day_start);
         $day_end_gmt = gmdate("Y-m-d H:i:s", $day_start + 86400 - 1);
         $open_stats["data"][] = array($ind, (int) $wpdb->get_var($wpdb->prepare("\r\n\t\t\t\tSELECT COUNT(*) FROM `{$wpdb->prefix}bbpp_thankmelater_opens`\r\n\t\t\t\tWHERE `date_gmt` >= %s\r\n\t\t\t\tAND `date_gmt` <= %s\r\n\t\t\t", $day_start_gmt, $day_end_gmt)));
         $open_stats["labels"][] = array($ind, date_i18n("d", $day_start, false));
         $day_start += 86400;
         $ind++;
     }
     require_once BBPP_THANKMELATER_PLUGIN_PATH . "admin/statistics/index.php";
 }
Exemple #2
0
 /**
  * Process the loaded schedule events. i.e. sent the emails to the commenters.
  */
 public function process()
 {
     // mark the processing messages as sent *before* we try to send them.
     // this helps prevent race condition, since time is not tied up in trying
     // to send e-mail before marking it as sent
     foreach ($this->data as $pid => $data) {
         $this->selectSchedule($pid);
         $this->setSchedule(array("sent" => 1));
     }
     $this->save();
     // go through each schedule event...
     foreach ($this->data as $pid => $data) {
         $this->selectSchedule($pid);
         $message_id = $data["message_id"];
         $comment_id = $data["comment_id"];
         $comment = get_comment($comment_id);
         $message = new Bbpp_ThankMeLater_Message($message_id);
         // try to send email
         if ($comment && $message->send($comment)) {
         } else {
             // email counldn't be sent... mark as such...
             $this->setSchedule(array("sent" => 0));
             // we've tried for at least 3 hours, this mail is not going to
             // be sent, get rid of it.
             // (otherwise, we'll keep trying at the regular calls to process --
             // hourly if WP-Cron works, every 15 minutes in legacy mode).
             if ($this->getSendTime() < time() - 3600 * 3) {
                 $sched = new Bbpp_ThankMeLater_Schedule($data["id"]);
                 $sched->delete();
             }
         }
     }
     $this->save();
 }
Exemple #3
0
 /**
  * Hook called after comment is posted.
  */
 public function comment_post($id, $status = NULL)
 {
     global $wpdb;
     $comment = get_comment($id);
     $status = $status ? (string) $status : $comment->comment_approved;
     $is_live = TRUE;
     // comment deleted?
     if (!$comment) {
         $is_live = FALSE;
     } else {
         // don't process pingbacks and other non-comments...
         if ($comment->comment_type !== "") {
             $is_live = FALSE;
         }
         // make sure comment is approved (i.e. not deleted & not spam):
         //if ($comment->comment_approved !== "1") {
         //	$is_live = FALSE;
         //}
         if ($status !== "approve" && $status !== "1") {
             $is_live = FALSE;
         }
         $post = get_post($comment->comment_post_ID);
         if (!$post) {
             // post deleted
             $is_live = FALSE;
         } else {
             if ($post->post_status == "bbpp-thankmelater-pv") {
                 // not a real post -- used for previews
                 $is_live = FALSE;
             }
         }
         // check whether user has opted out of emails
         $opt_out_row = $wpdb->get_row($wpdb->prepare("\r\n\t\t\t\tSELECT `email` FROM `{$wpdb->prefix}bbpp_thankmelater_opt_outs`\r\n\t\t\t\tWHERE `email` = %s\r\n\t\t\t", $comment->comment_author_email));
         if ($opt_out_row !== NULL) {
             $is_live = FALSE;
         }
     }
     if ($is_live) {
         // schedule the messages to be sent for this comment.
         $message = new Bbpp_ThankMeLater_Message();
         $message->scheduleMessages($comment);
     } else {
         // remove any scheduled mails, this comment has been spammed or trashed
         $schedule = new Bbpp_ThankMeLater_Schedule();
         $schedule->readUnsent($id);
         $schedule->delete();
     }
 }
Exemple #4
0
 /**
  * Delete the message(s)
  * 
  * @global type $wpdb
  */
 public function delete()
 {
     global $wpdb;
     foreach ($this->data as $data) {
         $wpdb->query($wpdb->prepare("\r\n\t\t\t\tDELETE FROM `{$wpdb->prefix}bbpp_thankmelater_messages`\r\n\t\t\t\tWHERE `id` = %d\r\n\t\t\t", $data["id"]));
         // remove unsent messages from the schedule
         $schedule = new Bbpp_ThankMeLater_Schedule();
         $schedule->deleteUnsentByMessageId($data["id"]);
     }
 }