public static function build_cache() { self::getInstance(); $email_list = SendPress_Data::get_email_id_from_queue(); foreach ($email_list as $email) { $html = SendPress_Template::get_instance()->render_html($email->emailID, false, false, false); self::set($email->emailID, $html); } }
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; }
$aElement->setAttribute('style', $style); } //$content = $dom->saveHTML(); $content = preg_replace(array("/^\\<\\!DOCTYPE.*?<html><body>/si", "!</body></html>\$!si"), "", $dom->saveHTML()); $content = str_replace("%7B", "{", $content); $content = str_replace("%7D", "}", $content); return $content; } return $content; } static function tag_replace($HtmlCode) { $HtmlCode = str_replace('*|SITE:URL|*', get_option('home'), $HtmlCode); $HtmlCode = str_replace('*|SITE:TITLE|*', get_option('blogname'), $HtmlCode); $HtmlCode = str_replace('*|DATE|*', date_i18n(get_option('date_format')), $HtmlCode); $HtmlCode = str_replace('*|SITE:DESCRIPTION|*', get_option('blogdescription'), $HtmlCode); $x = 0; while (($x = strpos($HtmlCode, '*|DATE:', $x)) !== false) { $y = strpos($HtmlCode, '|*', $x); if ($y === false) { continue; } $f = substr($HtmlCode, $x + 7, $y - $x - 7); $HtmlCode = substr($HtmlCode, 0, $x) . date_i18n($f) . substr($HtmlCode, $y + 2); } return $HtmlCode; } } // Initialize! SendPress_Template::get_instance();
function get_templates() { _deprecated_function(__FUNCTION__, '0.8.7', 'SendPress_Template::get_instance()->info()'); return SendPress_Template::get_instance()->info(); }