' . $html . ' '; return $template; } static function convertBlockquotesToTables($html) { $DOM_parser = new \pQuery(); $DOM = $DOM_parser->parseStr($html); $blockquotes = $DOM->query('blockquote'); if(!$blockquotes->count()) return $html; foreach($blockquotes as $blockquote) { $contents = array(); $paragraphs = $blockquote->query('p', 0); foreach($paragraphs as $index => $paragraph) { $contents[] = $paragraph->html(); if($index + 1 < $paragraphs->count()) $contents[] = '
'; $paragraph->remove(); } $paragraph->remove(); $blockquote->setTag('table'); $blockquote->addClass('mailpoet_blockquote'); $blockquote->width = '100%'; $blockquote->spacing = 0; $blockquote->border = 0; $blockquote->cellpadding = 0; $blockquote->html('
' . implode('', $contents) . '
' ); $blockquote = self::insertLineBreak($blockquote); } return $DOM->__toString(); } static function convertParagraphsToTables($html) { $DOM_parser = new \pQuery(); $DOM = $DOM_parser->parseStr($html); $paragraphs = $DOM->query('p'); if(!$paragraphs->count()) return $html; foreach($paragraphs as $paragraph) { // process empty paragraphs if(!trim($paragraph->html())) { $next_element = ($paragraph->getNextSibling()) ? trim($paragraph->getNextSibling()->text()) : false; $previous_element = ($paragraph->getPreviousSibling()) ? trim($paragraph->getPreviousSibling()->text()) : false; $previous_element_tag = ($previous_element) ? $paragraph->getPreviousSibling()->tag : false; // if previous or next paragraphs are empty OR previous paragraph // is a heading, insert a break line if(!$next_element || !$previous_element || (preg_match('/h\d+/', $previous_element_tag)) ) { $paragraph = self::insertLineBreak($paragraph); } $paragraph->remove(); continue; } $style = $paragraph->style; if(!preg_match('/text-align/i', $style)) { $style = 'text-align: left;' . $style; } $contents = $paragraph->html(); $paragraph->setTag('table'); $paragraph->style = 'border-spacing:0;mso-table-lspace:0;mso-table-rspace:0;'; $paragraph->width = '100%'; $paragraph->cellpadding = 0; $next_element = $paragraph->getNextSibling(); // unless this is the last element in column, add double line breaks $line_breaks = ($next_element && !trim($next_element->text())) ? '

' : ''; // if this element is followed by a list, add single line break $line_breaks = ($next_element && preg_match('/
  • /i', $next_element->text())) ? '
    ' : $line_breaks; $paragraph->html(' ' . $contents . $line_breaks . ' ' ); } return $DOM->__toString(); } static function styleLists($html) { $DOM_parser = new \pQuery(); $DOM = $DOM_parser->parseStr($html); $lists = $DOM->query('ol, ul, li'); if(!$lists->count()) return $html; foreach($lists as $list) { if($list->tag === 'li') { $list->setInnertext($list->html()); $list->class = 'mailpoet_paragraph'; } else { $list->class = 'mailpoet_paragraph'; $list->style .= 'padding-top:0;padding-bottom:0;margin-top:10px;'; } $list->style = StylesHelper::applyTextAlignment($list->style); $list->style .= 'margin-bottom:10px;'; } return $DOM->__toString(); } static function styleHeadings($html) { $DOM_parser = new \pQuery(); $DOM = $DOM_parser->parseStr($html); $headings = $DOM->query('h1, h2, h3, h4'); if(!$headings->count()) return $html; foreach($headings as $heading) { $heading->style = StylesHelper::applyTextAlignment($heading->style); $heading->style .= 'padding:0;font-style:normal;font-weight:normal;'; } return $DOM->__toString(); } static function removeLastLineBreak($html) { return preg_replace('/(^)?()+$/i', '', $html); } static function insertLineBreak($element) { $element->parent->insertChild( array( 'tag_name' => 'br', 'self_close' => true, 'attributes' => array() ), $element->index() + 1 ); return $element; } }