Пример #1
0
 public function testParseStyleSheet()
 {
     $parsed = $this->object->parseStylesheet("p:not(.p2) { color: red }");
     $this->assertEquals($parsed, array(array("p:not(.p2)", "color: red")));
 }
 public function prepare_content($inline = true)
 {
     if (empty($this->content)) {
         return false;
     }
     //strip all unwanted stuff from the content
     $this->strip_stuff();
     //fix for Yahoo background color
     if (!strpos($this->content, 'body{background-image')) {
         $this->content = preg_replace('/body{background-color/', 'body,.bodytbl{background-color', $this->content, 1);
     }
     //Inline CSS
     if ($inline) {
         error_reporting(0);
         require_once MYMAIL_DIR . '/classes/libs/InlineStyle.php';
         $htmldoc = new InlineStyle($this->content);
         $stylesheet = $htmldoc->extractStylesheets();
         $originalstyle = $stylesheet[0];
         $mediaBlocks = $this->parseMediaBlocks($originalstyle);
         $stylesheet = str_replace($mediaBlocks, '', $originalstyle);
         $htmldoc->applyStylesheet($stylesheet);
         $html = $this->content;
         preg_match('#(<style ?[^<]+?>[^<]+<\\/style>)#', $this->content, $styles);
         $html = $htmldoc->getHTML();
         if ($styles[0]) {
             $html = preg_replace('#(<body ?[^<]+?>)#', "\$1\n" . $styles[0], $html);
         }
         //convert urlencode back
         $this->content = urldecode($html);
     }
     $this->content = str_replace(array('%7B', '%7D'), array('{', '}'), $this->content);
     //return false;
     return $this->content;
 }