function html() { $email_id = get_query_var('spemail'); global $post; if (is_object($this->data()) && $this->data()->id) { $email_id = $this->data()->id; } if (isset($_GET['eid'])) { $email_id = SPNL()->validate->int(base64_decode($_GET['eid'])); } // If there's a subscriber ID in the URL, we need to get the subscriber object from it to use for the str_replace below. if (isset($_GET['sid'])) { $subscriber_id = SPNL()->validate->int(base64_decode($_GET['sid'])); } else { $subscriber_id = 0; } //$post = get_post($email_id); $inline = false; if (isset($_GET['inline'])) { $inline = true; } SendPress_Email_Cache::build_cache_for_email($email_id); $message = new SendPress_Email(); $message->id($email_id); $message->subscriber_id($subscriber_id); $message->list_id(0); $body = $message->html(); //print_r( $body ); unset($message); echo $body; //echo SendPress_Template::get_instance()->render_html(false, true, $inline ); }
public static function getInstance() { if (!self::$instance) { self::$instance = new self(); } return self::$instance; }
static function send_mail_cron() { //@ini_set('max_execution_time',0); global $wpdb; $count = SendPress_Option::get('emails-per-hour'); $count = SendPress_Option::get('wpcron-per-call', 25); $email_count = 0; $attempts = 0; if (SendPress_Manager::limit_reached($count)) { return; } SendPress_Email_Cache::build_cache(); for ($i = 0; $i < $count; $i++) { $email = SendPress_Data::get_single_email_from_queue(); if ($email != null) { $attempts++; SendPress_Data::queue_email_process($email->id); $result = SendPress_Manager::send_email_from_queue($email); $email_count++; if ($result) { if ($result === true) { $wpdb->update(SendPress_Data::queue_table(), array('success' => 1, 'inprocess' => 3), array('id' => $email->id)); //( $sid, $rid, $lid=null, $uid=null, $ip=null, $device_type=null, $device=null, $type='confirm' ) //$wpdb->update( SendPress_Data::queue_table() , array('success'=>1,'inprocess'=>3 ) , array('id'=> $email->id )); //$wpdb->insert(SendPress_Data::subscriber_tracker_table() , array('subscriberID'=>$email->subscriberID,'emailID'=>$email->emailID,'sent_at' => get_gmt_from_date( date('Y-m-d H:i:s') )) ); SPNL()->db("Subscribers_Tracker")->add(array('subscriber_id' => intval($email->subscriberID), 'email_id' => intval($email->emailID))); SendPress_Data::add_subscriber_event($email->subscriberID, $email->emailID, $email->listID, null, null, null, null, 'send'); } else { $wpdb->update(SendPress_Data::queue_table(), array('success' => 2, 'inprocess' => 3), array('id' => $email->id)); SendPress_Data::add_subscriber_event($email->subscriberID, $email->emailID, $email->listID, null, null, null, null, 'bounce'); SendPress_Data::bounce_subscriber_by_id($email->subscriberID); } //$wpdb->insert( $this->subscriber_open_table(), $senddata); $count++; //SendPress_Data::update_report_sent_count( $email->emailID ); } else { $wpdb->update(SendPress_Data::queue_table(), array('attempts' => $email->attempts + 1, 'inprocess' => 0, 'last_attempt' => date('Y-m-d H:i:s')), array('id' => $email->id)); } } else { //We ran out of emails to process. break; } set_time_limit(30); } return; }
/** * Used to add Overwrite send info for testing. * * @return boolean true if mail sent successfully, false if an error */ static function send_test_email($email) { SendPress_Email_Cache::build_cache_for_email($email->emailID); $message = new SendPress_Email(); $message->id($email->emailID); $message->purge(true); $message->subscriber_id($email->subscriberID); $message->list_id($email->listID); $body = $message->html(); $subject = $message->subject(); $to = $email->to_email; $text = $message->text(); if (empty($text) || $text == '' || empty($body) || $body == '' || $body == " ") { SPNL()->log->add('Email Skiped', 'Email id #' . $email->emailID . ' to ' . $to . ' did not have any content. Was the email or template deleted?', 0, 'sending'); return false; } return SendPress_Manager::send($to, $subject, $body, $text, true, $email->subscriberID, $email->listID, $email->emailID); }
function html() { $post_template = $this->id(); global $wpdb; //$email = $this->email(); // Get any existing copy of our transient data if (SendPress_Email_Cache::get($this->id()) != null) { $body_html = SendPress_Email_Cache::get($this->id()); $post_template = get_post_meta($this->id(), '_sendpress_template', true); $body_html = spnl_do_email_tags($body_html, $post_template, $this->id(), $this->subscriber_id(), true); } else { if (false === ($body_html = get_transient('sendpress_report_body_html_' . $this->id())) || $this->purge() == true) { // It wasn't there, so regenerate the data and save the transient if (!$this->post_info) { $this->post_info = get_post($this->id()); } if ($this->cache() !== false) { $body_html = $this->cache(); } else { $body_html = SendPress_Template::get_instance()->render($this->id(), false, false, $this->remove_links()); $this->cache($body_html); } set_transient('sendpress_report_body_html_' . $this->id(), $body_html, 60 * 60 * 2); } } $subscriber = SendPress_Data::get_subscriber($this->subscriber_id()); if (!is_null($subscriber)) { $body_html = str_replace("*|FNAME|*", $subscriber->firstname, $body_html); $body_html = str_replace("*|LNAME|*", $subscriber->lastname, $body_html); $body_html = str_replace("*|EMAIL|*", $subscriber->email, $body_html); $body_html = str_replace("*|ID|*", $subscriber->subscriberID, $body_html); } $open_info = array("id" => $this->subscriber_id(), "report" => $this->id(), "view" => "open"); $code = SendPress_Data::encrypt($open_info); $link = SendPress_Manager::public_url($code); $tracker = "<img src='" . $link . "' width='1' height='1'/></body>"; $body_html = str_replace("</body>", $tracker, $body_html); $body_link = get_post_meta($this->id(), 'body_link', true); $body_html = spnl_do_subscriber_tags($body_html, $post_template, $this->id(), $this->subscriber_id(), true); //$pattern ="/(?<=href=(\"|'))[^\"']+(?=(\"|'))/"; //$body_html = preg_replace( $pattern , site_url() ."?sendpress=link&fxti=".$subscriber_key."&spreport=". $this->id ."&spurl=$0", $body_html ); if (class_exists("DomDocument")) { $dom = new DomDocument(); $dom->strictErrorChecking = false; @$dom->loadHtml($body_html); $pTags = $dom->getElementsByTagName('p'); foreach ($pTags as $pElement) { $px = $pElement->getAttribute('style'); $pElement->setAttribute('style', $px . ' margin-top:0;margin-bottom:10px;'); } if ($this->tracker()) { $aTags = $dom->getElementsByTagName('a'); foreach ($aTags as $aElement) { $href = $aElement->getAttribute('href'); /* $style = $aElement->getAttribute('style'); if($style == ""){ $aElement->setAttribute('style'); } */ //ADD TO DB? if (strrpos($href, "*|") === false && strrpos($href, "#") !== 0) { if (SendPress_Option::get('skip_mailto', false) == true && strrpos($href, "mailto") !== false) { continue; } /* $urlinDB = SendPress_Data::get_url_by_report_url( $this->id(), $href ); if(!isset($urlinDB[0])){ $urlData = array( 'url' => trim($href), 'reportID' => $this->id(), ); $urlID = SendPress_Data::insert_report_url( $urlData ); } else { $urlID = $urlinDB[0]->urlID; } $link = array( "id"=>$this->subscriber_id(), "report"=> $this->id(), "urlID"=> $urlID, "view"=>"link" ); */ $link = array("id" => $this->subscriber_id(), "report" => $this->id(), "view" => "tracker", "url" => $href); $code = SendPress_Data::encrypt($link); $link = SendPress_Manager::public_url($code); $href = $link; $aElement->setAttribute('href', $href); } } } $body_html = $dom->saveHtml(); } $link_data = array("id" => $this->subscriber_id(), "report" => $this->id(), "urlID" => '0', "view" => "manage", "listID" => $this->list_id(), "action" => "unsubscribe"); $code = SendPress_Data::encrypt($link_data); $link = SendPress_Manager::public_url($code); if (SendPress_Option::get('old_unsubscribe_link', false) === true) { $start_text = __("Not interested anymore?", "sendpress"); $unsubscribe = __("Unsubscribe", "sendpress"); $instantly = __("Instantly", "sendpress"); $remove_me_old = $start_text . ' <a href="' . $link . '" style="color: ' . $body_link . ';" >' . $unsubscribe . '</a> ' . $instantly . '.'; $body_html = str_replace("*|SP:UNSUBSCRIBE|*", $remove_me_old, $body_html); $body_html = str_replace("*|SP:MANAGE|*", '', $body_html); } else { $link_data = array("id" => $this->subscriber_id(), "report" => $this->id(), "urlID" => '0', "view" => "manage", "listID" => $this->list_id(), "action" => ""); $code = SendPress_Data::encrypt($link_data); $manage_link = SendPress_Manager::public_url($code); $unsubscribe = __("Unsubscribe", "sendpress"); $manage = __("Manage Subscription", "sendpress"); $remove_me = ' <a href="' . $link . '" style="color: ' . $body_link . ';" >' . $unsubscribe . '</a> | '; $manage = ' <a href="' . $manage_link . '" style="color: ' . $body_link . ';" >' . $manage . '</a> '; $body_html = str_replace("*|SP:UNSUBSCRIBE|*", $remove_me, $body_html); $body_html = str_replace("*|SP:MANAGE|*", $manage, $body_html); } if (!is_null($subscriber)) { $body_html = str_replace("*|FNAME|*", $subscriber->firstname, $body_html); $body_html = str_replace("*|LNAME|*", $subscriber->lastname, $body_html); $body_html = str_replace("*|EMAIL|*", $subscriber->email, $body_html); $body_html = str_replace("*|ID|*", $subscriber->subscriberID, $body_html); } //$body_html = apply_filters('sendpress_post_render_email', $body_html); //echo $body_html; //print_r($email); return $body_html; }
function template_include($template) { global $post; if (get_query_var('sendpress') || isset($_POST['sendpress'])) { $action = isset($_POST['sendpress']) ? $_POST['sendpress'] : get_query_var('sendpress'); //Look for encrypted data $data = SendPress_Data::decrypt($action); $view = false; if (is_object($data)) { $view = isset($data->view) ? $data->view : false; } else { $view = $action; } $view_class = SendPress_Data::get_public_view_class($view); if (class_exists($view_class)) { $view_class = new $view_class(); $view_class->data($data); if (isset($_POST['sp']) && wp_verify_nonce($_POST['sp'], 'sendpress-form-post') && method_exists($view_class, 'save')) { $view_class->save(); } $view_class->prerender(); $view_class->render(); } //$this->load_default_screen($action); die; } if (isset($post)) { if ($post->post_type == $this->_email_post_type || $post->post_type == $this->_report_post_type) { $inline = false; if (isset($_GET['inline'])) { $inline = true; } SendPress_Email_Cache::build_cache_for_email($post->ID); $message = new SendPress_Email(); $message->id($post->ID); $message->subscriber_id(0); $message->list_id(0); $body = $message->html(); //print_r( $body ); unset($message); echo $body; die; //SendPress_Template::get_instance()->render_html(false, true, $inline ); //return SENDPRESS_PATH. '/template-loader.php'; //return dirname(__FILE__) . '/my_special_template.php'; } /** * * if($post->post_type == 'sp-standard' ){ * return 'You Bet'; * } **/ } return $template; }