Example #1
1
 /**
  * parseBBcode
  * @return void
  */
 public function parseBBcode()
 {
     $dom = new \DomDocument();
     $dom->loadHTML($this->html);
     $finder = new \DomXPath($dom);
     $nodes = $finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' cacheLogText ')]");
     $parser = new JBBCode\Parser();
     $parser->addCodeDefinitionSet(new JBBCode\DefaultCodeDefinitionSet());
     foreach ($this->bbcode_colors as $color) {
         $builder = new JBBCode\CodeDefinitionBuilder($color, '<span style="color: ' . $color . ';">{param}</span>');
         $parser->addCodeDefinition($builder->build());
     }
     foreach ($nodes as $node) {
         $raw_log = $node->ownerDocument->saveHTML($node);
         $raw_log = trim(str_replace(array('<td class="cacheLogText" colspan="2">', '</td>'), '', $raw_log));
         $log = preg_replace('/<br>$/', '', $raw_log);
         $parser->parse($log);
         $node->nodeValue = $parser->getAsHtml();
     }
     //$smileyVisitor = new JBBCode\visitors\SmileyVisitor();
     //$parser->accept($smileyVisitor);
     $this->html = htmlspecialchars_decode($dom->saveHtml());
     $bbcodes = array_keys($this->bbcode_smileys);
     $images = array_values($this->bbcode_smileys);
     foreach ($images as $k => &$image) {
         $image = '<img src="../images/icons/' . $image . '" alt="' . $bbcodes[$k] . '" />';
     }
     foreach ($bbcodes as &$bbcode) {
         $bbcode = '[' . $bbcode . ']';
     }
     $this->html = str_replace($bbcodes, $images, $this->html);
 }
Example #2
0
 /**
  * Traverse a string of HTML and proxy out to convert markdownable tags
  *
  * @param  string $html
  * @return string
  */
 public function convert($html = null)
 {
     if (!is_null($html)) {
         $this->html = $html;
     }
     $this->html = preg_replace('~>\\s+<~', '><', $this->html);
     if (is_null($this->html)) {
         throw new Exception\NotTraversableException('No HTML was provided to traverse');
     }
     $this->doc->loadHTML('<?xml encoding="UTF-8">' . $this->html);
     $this->doc->encoding = 'UTF-8';
     $body = $this->doc->getElementsByTagName("body")->item(0);
     $this->convertRecursive($body);
     $markdown = $this->doc->saveHtml();
     $markdown = html_entity_decode($markdown, ENT_QUOTES, 'UTF-8');
     $markdown = preg_replace('/<!DOCTYPE [^>]+>/', null, $markdown);
     $unwanted = ['<html>', '</html>', '<body>', '</body>', '<?xml encoding="UTF-8">', '&#xD;'];
     $markdown = str_replace($unwanted, null, $markdown);
     $markdown = trim($markdown, "\n\r\v") . PHP_EOL;
     $markdown = preg_replace('/(?:(?:\\r\\n|\\r|\\n)\\s*){2}/s', "\n\n", $markdown);
     return $markdown;
 }
 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;
 }
Example #4
0
 /**
  *
  * create directory tree html
  */
 public function getDirectoryTree($path, $skip_files = false, $link_prefix = '')
 {
     $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
     $dom = new DomDocument("1.0");
     $li = $dom;
     $ul = $dom->createElement('ul');
     $li->appendChild($ul);
     $el = $dom->createElement('li', 'Home');
     $at = $dom->createAttribute('clink');
     $at->value = $link_prefix;
     $el->appendChild($at);
     $ul->appendChild($el);
     $node = $ul;
     $depth = -1;
     foreach ($objects as $object) {
         $name = $object->getFilename();
         // skip unwanted files
         if ($name == '.' || $name == '..' || in_array($name, gatorconf::get('restricted_files'))) {
             continue;
         }
         $path = str_replace('\\', '/', $object->getPathname());
         $isDir = is_dir($path);
         $link = str_replace(gatorconf::get('repository'), '', $path);
         $link = gator::encodeurl(ltrim($link, '/\\'));
         $skip = false;
         if ($isDir == false && $skip_files == true) {
             // skip unwanted files
             $skip = true;
         } elseif ($isDir == false) {
             // this is regural file, no links here
             $link = '';
         } else {
             // this is dir
             $link = $link;
         }
         if ($objects->getDepth() == $depth) {
             //the depth hasnt changed so just add another li
             if (!$skip) {
                 $el = $dom->createElement('li', $name);
                 $at = $dom->createAttribute('clink');
                 $at->value = $link_prefix . $this->encrypt($link);
                 $el->appendChild($at);
                 if (!$isDir) {
                     $el->appendChild($dom->createAttribute('isfile'));
                 }
                 $node->appendChild($el);
             }
         } elseif ($objects->getDepth() > $depth) {
             //the depth increased, the last li is a non-empty folder
             $li = $node->lastChild;
             $ul = $dom->createElement('ul');
             $li->appendChild($ul);
             if (!$skip) {
                 $el = $dom->createElement('li', $name);
                 $at = $dom->createAttribute('clink');
                 $at->value = $link_prefix . $this->encrypt($link);
                 $el->appendChild($at);
                 if (!$isDir) {
                     $el->appendChild($dom->createAttribute('isfile'));
                 }
                 $ul->appendChild($el);
             }
             $node = $ul;
         } else {
             //the depth decreased, going up $difference directories
             $difference = $depth - $objects->getDepth();
             for ($i = 0; $i < $difference; $difference--) {
                 $node = $node->parentNode->parentNode;
             }
             if (!$skip) {
                 $el = $dom->createElement('li', $name);
                 $at = $dom->createAttribute('clink');
                 $at->value = $link_prefix . $this->encrypt($link);
                 $el->appendChild($at);
                 if (!$isDir) {
                     $el->appendChild($dom->createAttribute('isfile'));
                 }
                 $node->appendChild($el);
             }
         }
         $depth = $objects->getDepth();
     }
     return $dom->saveHtml();
 }
 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 render($post_id = false, $render = true, $inline = false, $no_links = false)
 {
     global $post;
     $saved = false;
     if ($post_id !== false) {
         $post = get_post($post_id);
         $saved = $post;
     }
     $saved = $post;
     if (!isset($post)) {
         //echo __('Sorry we could not find your email.','sendpress');
         return;
     }
     $selected_template = $this->get_template($post_id);
     $template_list = $this->info();
     if (isset($template_list[$selected_template])) {
         ob_start();
         require_once $template_list[$selected_template]['file'];
         $HtmlCode = ob_get_clean();
         $post = $saved;
         $HtmlCode = str_replace("*|SP:SUBJECT|*", $post->post_title, $HtmlCode);
         $body_bg = get_post_meta($post->ID, 'body_bg', true);
         $body_text = get_post_meta($post->ID, 'body_text', true);
         $body_link = get_post_meta($post->ID, 'body_link', true);
         $header_bg = get_post_meta($post->ID, 'header_bg', true);
         $active_header = get_post_meta($post->ID, 'active_header', true);
         $upload_image = get_post_meta($post->ID, 'upload_image', true);
         $header_text_color = get_post_meta($post->ID, 'header_text_color', true);
         $header_text = get_post_meta($post->ID, 'header_text', true);
         //needs adding to the template
         $header_link = get_post_meta($post->ID, 'header_link', true);
         //needs adding to the template
         $sub_header_text = get_post_meta($post->ID, 'sub_header_text', true);
         //needs adding to the template
         $image_header_url = get_post_meta($post->ID, 'image_header_url', true);
         //needs adding to the template
         $content_bg = get_post_meta($post->ID, 'content_bg', true);
         $content_text = get_post_meta($post->ID, 'content_text', true);
         $content_link = get_post_meta($post->ID, 'sp_content_link_color', true);
         $content_border = get_post_meta($post->ID, 'content_border', true);
         $header_link_open = '';
         $header_link_close = '';
         if ($active_header == 'image') {
             if (!empty($image_header_url)) {
                 $header_link_open = "<a style='color:" . $header_text_color . "' href='" . $image_header_url . "'>";
                 $header_link_close = "</a>";
             }
             $headercontent = $header_link_open . "<img style='display:block;' src='" . $upload_image . "' border='0' />" . $header_link_close;
             $HtmlCode = str_replace("*|SP:HEADERCONTENT|*", $headercontent, $HtmlCode);
         } else {
             if (!empty($header_link)) {
                 $header_link_open = "<a style='color:" . $header_text_color . "' href='" . $header_link . "'>";
                 $header_link_close = "</a>";
             }
             $headercontent = "<div style='padding: 10px; text-align:center;'><h1 style='text-align:center; color: " . $header_text_color . " !important;'>" . $header_link_open . $header_text . $header_link_close . "</h1>" . $sub_header_text . "</div>";
             $HtmlCode = str_replace("*|SP:HEADERCONTENT|*", $headercontent, $HtmlCode);
         }
         $HtmlCode = str_replace("*|SP:HEADERBG|*", $header_bg, $HtmlCode);
         $HtmlCode = str_replace("*|SP:HEADERTEXT|*", $header_text_color, $HtmlCode);
         $HtmlCode = str_replace("*|SP:BODYBG|*", $body_bg, $HtmlCode);
         $HtmlCode = str_replace("*|SP:BODYTEXT|*", $body_text, $HtmlCode);
         $HtmlCode = str_replace("*|SP:BODYLINK|*", $body_link, $HtmlCode);
         $HtmlCode = str_replace("*|SP:CONTENTBG|*", $content_bg, $HtmlCode);
         $HtmlCode = str_replace("*|SP:CONTENTTEXT|*", $content_text, $HtmlCode);
         $HtmlCode = str_replace("*|SP:CONTENTLINK|*", $content_link, $HtmlCode);
         $HtmlCode = str_replace("*|SP:CONTENTBORDER|*", $content_border, $HtmlCode);
         $HtmlCode = $this->tag_replace($HtmlCode);
         // Date processing
         $canspam = wpautop(SendPress_Option::get('canspam'));
         $HtmlCode = str_replace("*|SP:CANSPAM|*", $canspam, $HtmlCode);
         $social = '';
         if ($twit = SendPress_Option::get('twitter')) {
             $social .= "<a href='{$twit}' style='color: {$body_link};'>Twitter</a>";
         }
         if ($fb = SendPress_Option::get('facebook')) {
             if ($social != '') {
                 $social .= " | ";
             }
             $social .= "<a href='{$fb}'  style='color: {$body_link};'>Facebook</a>";
         }
         if ($ld = SendPress_Option::get('linkedin')) {
             if ($social != '') {
                 $social .= " | ";
             }
             $social .= "<a href='{$ld}'  style='color: {$body_link};'>LinkedIn</a>";
         }
         $social = SendPress_Data::build_social($body_link);
         $HtmlCode = str_replace("*|SP:SOCIAL|*", $social, $HtmlCode);
         $dom = new DomDocument();
         $dom->strictErrorChecking = false;
         @$dom->loadHtml($HtmlCode);
         $iTags = $dom->getElementsByTagName('img');
         foreach ($iTags as $iElement) {
             $class = $iElement->getAttribute('class');
         }
         $body_html = $dom->saveHtml();
         /*
         			$simplecss = file_get_contents(SENDPRESS_PATH.'/templates/simple.css');
         				
         			// create instance
         			$cssToInlineStyles = new CSSToInlineStyles($HtmlCode, $simplecss);
         // grab the processed HTML
         			$HtmlCode = $cssToInlineStyles->convert();
         */
         $display_correct = __("Is this email not displaying correctly?", "sendpress");
         $view = __("View it in your browser", "sendpress");
         $start_text = __("Not interested anymore?", "sendpress");
         $unsubscribe = __("Unsubscribe", "sendpress");
         $instantly = __("Instantly", "sendpress");
         $manage = __("Manage Subscription", "sendpress");
         if ($render) {
             //RENDER IN BROWSER
             if ($inline) {
                 $link = get_permalink($post->ID);
                 $browser = $display_correct . ' <a style="color: ' . $body_link . ';" href="' . $link . '">' . $view . '</a>.';
                 $HtmlCode = str_replace("*|SP:BROWSER|*", $browser, $HtmlCode);
                 $remove_me = ' <a href="#"  style="color: ' . $body_link . ';" >' . $unsubscribe . '</a> | ';
                 $manage = ' <a href="#"  style="color: ' . $body_link . ';" >' . $manage . '</a> ';
                 $HtmlCode = str_replace("*|SP:MANAGE|*", $manage, $HtmlCode);
                 $HtmlCode = str_replace("*|SP:UNSUBSCRIBE|*", $remove_me, $HtmlCode);
             } else {
                 $HtmlCode = str_replace("*|SP:BROWSER|*", '', $HtmlCode);
                 $HtmlCode = str_replace("*|SP:UNSUBSCRIBE|*", '', $HtmlCode);
                 $HtmlCode = str_replace("*|SP:MANAGE|*", '', $HtmlCode);
                 $HtmlCode = str_replace("*|ID|*", '', $HtmlCode);
                 $HtmlCode = str_replace("*|FNAME|*", '', $HtmlCode);
                 $HtmlCode = str_replace("*|LNAME|*", '', $HtmlCode);
                 $HtmlCode = str_replace("*|EMAIL|*", '', $HtmlCode);
             }
             echo $HtmlCode;
         } else {
             //PREP FOR SENDING
             if ($no_links == false) {
                 $link = get_permalink($post->ID);
                 $open_info = array("id" => $post->ID, "view" => "email");
                 $code = SendPress_Data::encrypt($open_info);
                 $xlink = SendPress_Manager::public_url($code);
                 $browser = $display_correct . ' <a style="color: ' . $body_link . ';" href="' . $xlink . '">' . $view . '</a>.';
                 $HtmlCode = str_replace("*|SP:BROWSER|*", $browser, $HtmlCode);
             } else {
                 $HtmlCode = str_replace("*|SP:BROWSER|*", '', $HtmlCode);
                 $HtmlCode = str_replace("*|SP:UNSUBSCRIBE|*", '', $HtmlCode);
                 $HtmlCode = str_replace("*|SP:MANAGE|*", '', $HtmlCode);
             }
             return $HtmlCode;
         }
     } else {
         //echo __('Sorry we could not find your email template.','sendpress');
         return;
     }
 }