static function external($template_id, $email_id, $subscriber_id, $example)
 {
     //if( $example == false ){
     $content = get_post_meta($email_id, '_header_content', true);
     if (!$content) {
         if (self::template_post_exists($template_id)) {
             $content = get_post_meta($template_id, '_header_content', true);
         } else {
             $content = self::content();
         }
     }
     // get_post_meta($email_id);
     //$content = $content_post->post_content;
     //remove_filter('the_content','wpautop');
     add_filter('bj_lazy_load_run_filter', '__return_false');
     $content = apply_filters('the_content', $content);
     add_filter('the_content', 'wpautop');
     $content = str_replace(']]>', ']]>', $content);
     $content = spnl_do_email_tags($content, $template_id, $email_id, $subscriber_id, $example);
     /*
     } else {
     	$content = self::lipsum_format();
     }
     */
     if ($content != '') {
         return self::table_start($template_id) . $content . self::table_end($template_id);
     }
     return '';
 }
 static function external($template_id, $email_id, $subscriber_id, $example)
 {
     //if( $example == false ){
     if (self::template_post_exists($template_id)) {
         $content = get_post_meta($template_id, '_footer_page', true);
     } else {
         $content = '';
         //self::content();
     }
     //$content = $content_post->post_content;
     $link = get_post_meta($template_id, '_header_page_link_color', true);
     if ($link == false) {
         $link = '#2469a0';
     }
     //$content = SendPress_Template::link_style($link, $content);
     add_filter('bj_lazy_load_run_filter', '__return_false');
     remove_filter('the_content', 'wpautop');
     $content = apply_filters('the_content', $content);
     add_filter('the_content', 'wpautop');
     $content = nl2br(str_replace(']]>', ']]>', $content));
     $content = spnl_do_email_tags($content, $template_id, $email_id, $subscriber_id, $example);
     $content = SendPress_Template::link_style($link, $content);
     /*
     } else {
     	$content = self::lipsum_format();
     }
     */
     if ($content != '') {
         return self::table_start($template_id) . $content . self::table_end($template_id);
     }
     return '';
 }
 static function external($template_id, $email_id, $subscriber_id, $example, $x = false)
 {
     add_filter('bj_lazy_load_run_filter', '__return_false');
     if ($example == false) {
         do_action('sendpress_template_loaded');
         if ($x == false) {
             $content_post = get_post($email_id);
             $content = $content_post->post_content;
         } else {
             $content = $x;
         }
         $content = apply_filters('the_content', $content);
         $content = str_replace(']]>', ']]>', $content);
     } else {
         $content = self::lipsum_format();
     }
     $stat = get_post_status($template_id);
     $content = spnl_do_email_tags($content, $template_id, $email_id, $subscriber_id, $example);
     if ($stat == 'sp-standard') {
         $link = get_post_meta($template_id, '_content_link_color', true);
         if ($link == false) {
             $link = '#2469a0';
         }
         $content = SendPress_Template::link_style($link, $content);
     }
     return $content;
 }
 static function render_template_example($post)
 {
     $html = self::render_html_base_by_post($post);
     $return = spnl_do_content_tags($html, $post->ID, $post->ID, 0, true);
     $return = spnl_do_email_tags($return, $post->ID, $post->ID, 0, true);
     $return = spnl_do_subscriber_tags($return, $post->ID, $post->ID, 0, true);
     //$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($return);
         $pTags = $dom->getElementsByTagName('p');
         foreach ($pTags as $pElement) {
             $px = $pElement->getAttribute('style');
             $pElement->setAttribute('style', $px . ' margin-top:0;margin-bottom:10px;');
         }
         $return = $dom->saveHtml();
     }
     return $return;
 }
 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;
 }