Example #1
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();
     }
 }
Example #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();
 }
Example #3
0
 /**
  * 
  * @global type $wpdb
  */
 public function prepare_items()
 {
     if (!class_exists("Bbpp_ThankMeLater_Message")) {
         require_once BBPP_THANKMELATER_PLUGIN_PATH . "Message.php";
     }
     // we'll store the messages in this object:
     $message = new Bbpp_ThankMeLater_Message();
     // set the table headers
     $this->_column_headers = array($this->get_columns(), array(), $this->get_sortable_columns());
     // do the bulk actions, if any
     $this->process_bulk_action();
     // get the number of results
     $current_page = $this->get_pagenum();
     $total_items = $message->countMessages();
     $this->set_pagination_args(array("total_items" => $total_items, "per_page" => $this->per_page, "total_pages" => ceil($total_items / $this->per_page)));
     $orderby = NULL;
     $order = NULL;
     $sortable_vals = array_keys($this->get_sortable_columns());
     if (!empty($_REQUEST["orderby"]) && in_array(stripslashes($_REQUEST["orderby"]), $sortable_vals)) {
         $orderby = stripslashes($_REQUEST["orderby"]);
         if (!empty($_REQUEST["order"]) && in_array(stripslashes($_REQUEST["order"]), array("asc", "desc"))) {
             $order = stripslashes($_REQUEST["order"]);
         }
     }
     // get the results
     $this->items = $message->readMessages($this->per_page, ($current_page - 1) * $this->per_page, $orderby, $order);
 }
Example #4
0
 /**
  * Get a full list of all posts targeted by a message
  * 
  * @param type $id
  */
 public function targets($id)
 {
     // create a virtual Thank Me Later message
     $message = new Bbpp_ThankMeLater_Message($id);
     $posts = $message->getTargets();
     $count = count($posts);
     require_once BBPP_THANKMELATER_PLUGIN_PATH . "admin/messages/targets.php";
 }