Skip to content

Commit

Permalink
[+]: use "LIBXML*" for PHP >= 5.4 (revert)
Browse files Browse the repository at this point in the history
  • Loading branch information
voku committed Oct 23, 2016
1 parent 2a5e10c commit e093d70
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 101 deletions.
6 changes: 2 additions & 4 deletions src/voku/helper/HtmlDomParser.php
Expand Up @@ -313,16 +313,14 @@ private function createDOMDocument($html, $libXMLExtraOptions = null)
libxml_clear_errors();

$optionsSimpleXml = LIBXML_DTDLOAD | LIBXML_DTDATTR | LIBXML_NONET;
$optionsXml = LIBXML_DTDATTR | LIBXML_NONET;
$optionsXml = 0;

if (defined('LIBXML_BIGLINES')) {
$optionsSimpleXml |= LIBXML_BIGLINES;
$optionsXml |= LIBXML_BIGLINES;
}

if (defined('LIBXML_COMPACT')) {
$optionsSimpleXml |= LIBXML_COMPACT;
$optionsXml |= LIBXML_COMPACT;
}

if (defined('LIBXML_HTML_NOIMPLIED')) {
Expand Down Expand Up @@ -353,7 +351,7 @@ private function createDOMDocument($html, $libXMLExtraOptions = null)

$html = self::replaceToPreserveHtmlEntities($html);

if (Bootup::is_php('5.4')) {
if ($optionsXml && Bootup::is_php('5.4')) {
$this->document->loadHTML($html, $optionsXml);
} else {
$this->document->loadHTML($html);
Expand Down
26 changes: 5 additions & 21 deletions tests/HtmlDomParserTest.php
Expand Up @@ -221,19 +221,10 @@ public function findTests()
array($html, 'input[id=in]', 1),
array($html, '#in', 1),
array($html, '*[id]', 52),
array($html, 'text', 462),
array($html, 'comment', 3),
);

if (Bootup::is_php('5.4')) {
$tests = array_merge_recursive($tests, array(
array($html, 'text', 640),
));
} else {
$tests = array_merge_recursive($tests, array(
array($html, 'text', 462),
));
}

return $tests;
}

Expand Down Expand Up @@ -360,17 +351,10 @@ public function testMail2()
$htmlExpected = str_replace(array("\r\n", "\r", "\n"), "\n", file_get_contents($filenameExpected));

// object to sting
if (Bootup::is_php('5.4')) {
self::assertSame(
$htmlExpected,
str_replace(array("\r\n", "\r", "\n"), "\n", (string)$html)
);
} else {
self::assertSame(
str_replace(array("\r\n", "\r", "\n", " "), "", $htmlExpected),
str_replace(array("\r\n", "\r", "\n", " "), "", (string)$html)
);
}
self::assertSame(
$htmlExpected,
str_replace(array("\r\n", "\r", "\n"), "\n", (string)$html)
);

$preHeaderContentArray = $html->find('.preheaderContent');

Expand Down
11 changes: 1 addition & 10 deletions tests/SimpleHtmlDomNodeTest.php
Expand Up @@ -62,19 +62,10 @@ public function findTests()
array($html, 'input[id]', 23),
array($html, 'input[id=in]', 1),
array($html, '#in', 1),
array($html, 'text', 390),
array($html, '*[id]', 51),
);

if (Bootup::is_php('5.4')) {
$tests = array_merge_recursive($tests, array(
array($html, 'text', 539),
));
} else {
$tests = array_merge_recursive($tests, array(
array($html, 'text', 390),
));
}

return $tests;
}

Expand Down
11 changes: 1 addition & 10 deletions tests/SimpleHtmlDomTest.php
Expand Up @@ -137,19 +137,10 @@ public function findTests()
array($html, 'input[id=in]', 1),
array($html, '#in', 1),
array($html, '*[id]', 52),
array($html, 'text', 462),
array($html, 'comment', 3),
);

if (Bootup::is_php('5.4')) {
$tests = array_merge_recursive($tests, array(
array($html, 'text', 640),
));
} else {
$tests = array_merge_recursive($tests, array(
array($html, 'text', 462),
));
}

return $tests;
}

Expand Down
100 changes: 44 additions & 56 deletions tests/fixtures/test_mail_expected.html
@@ -1,9 +1,9 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>*|MC:SUBJECT|*</title>
<style type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>*|MC:SUBJECT|*</title>
<style type="text/css">
/* /\/\/\/\/\/\/\/\/ CLIENT-SPECIFIC STYLES /\/\/\/\/\/\/\/\/ */
#outlook a{padding:0;} /* Force Outlook to provide a "view in browser" message */
.ReadMsgBody{width:100%;} .ExternalClass{width:100%;} /* Force Hotmail to display emails at full width */
Expand Down Expand Up @@ -435,97 +435,85 @@
</head>
<body leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" offset="0">
<center>
<table align="center" border="0" cellpadding="0" cellspacing="0" height="100%" width="100%" id="bodyTable">
<tr>
<td align="center" valign="top" id="bodyCell">
<table align="center" border="0" cellpadding="0" cellspacing="0" height="100%" width="100%" id="bodyTable"><tr>
<td align="center" valign="top" id="bodyCell">
<!-- BEGIN TEMPLATE // -->
<table border="0" cellpadding="0" cellspacing="0" id="templateContainer">
<tr>
<td align="center" valign="top">
<tr>
<td align="center" valign="top">
<!-- BEGIN PREHEADER // -->
<table border="0" cellpadding="0" cellspacing="0" width="100%" id="templatePreheader">
<tr>
<td valign="top" class="preheaderContent" style="padding-top:10px; padding-right:20px; padding-bottom:10px; padding-left:20px;" mc:edit="preheader_content00">
<table border="0" cellpadding="0" cellspacing="0" width="100%" id="templatePreheader"><tr>
<td valign="top" class="preheaderContent" style="padding-top:10px; padding-right:20px; padding-bottom:10px; padding-left:20px;" mc:edit="preheader_content00">
Use this area to offer a short teaser of your email's content. Text here will show in the preview area of some email clients.
</td>
<!-- *|IFNOT:ARCHIVE_PAGE|* -->
<td valign="top" width="180" class="preheaderContent" style="padding-top:10px; padding-right:20px; padding-bottom:10px; padding-left:0;" mc:edit="preheader_content01">
Email not displaying correctly?<br><a href="*|ARCHIVE|*" target="_blank">View it in your browser</a>.
</td>
<!-- *|END:IF|* -->
</tr>
</table>
<!-- // END PREHEADER -->
</td>
</tr></table>
<!-- // END PREHEADER -->
</td>
</tr>
<tr>
<td align="center" valign="top">
<tr>
<td align="center" valign="top">
<!-- BEGIN HEADER // -->
<table border="0" cellpadding="0" cellspacing="0" width="100%" id="templateHeader">
<tr>
<td valign="top" class="headerContent">
<table border="0" cellpadding="0" cellspacing="0" width="100%" id="templateHeader"><tr>
<td valign="top" class="headerContent">
<img src="http://gallery.mailchimp.com/2425ea8ad3/images/header_placeholder_600px.png" style="max-width:600px;" id="headerImage" mc:label="header_image" mc:edit="header_image" mc:allowdesigner mc:allowtext>
</td>
</tr>
</table>
<!-- // END HEADER -->
</td>
</td>
</tr></table>
<!-- // END HEADER -->
</td>
</tr>
<tr>
<td align="center" valign="top">
<tr>
<td align="center" valign="top">
<!-- BEGIN BODY // -->
<table border="0" cellpadding="0" cellspacing="0" width="100%" id="templateBody">
<tr>
<td valign="top" class="bodyContent" mc:edit="body_content">
<table border="0" cellpadding="0" cellspacing="0" width="100%" id="templateBody"><tr>
<td valign="top" class="bodyContent" mc:edit="body_content">
<h1>Designing Your Template</h1>
<h3>Creating a good-looking email is simple</h3>
Customize your template by clicking on the style editor tabs above. Set your fonts, colors, and styles. After setting your styling is all done you can click here in this area, delete the text, and start adding your own awesome content.
<br>
<br>
<h2>Styling Your Content</h2>
<br><br><h2>Styling Your Content</h2>
<h4>Make your email easy to read</h4>
After you enter your content, highlight the text you want to style and select the options you set in the style editor in the "<em>styles</em>" drop down box. Want to <a href="http://www.mailchimp.com/kb/article/im-using-the-style-designer-and-i-cant-get-my-formatting-to-change" target="_blank">get rid of styling on a bit of text</a>, but having trouble doing it? Just use the "<em>remove formatting</em>" button to strip the text of any formatting and reset your style.
</td>
</tr>
</table>
<!-- // END BODY -->
</td>
</tr></table>
<!-- // END BODY -->
</td>
</tr>
<tr>
<td align="center" valign="top">
<tr>
<td align="center" valign="top">
<!-- BEGIN FOOTER // -->
<table border="0" cellpadding="0" cellspacing="0" width="100%" id="templateFooter">
<tr>
<td valign="top" class="footerContent" mc:edit="footer_content00">
<tr>
<td valign="top" class="footerContent" mc:edit="footer_content00">
<a href="*|TWITTER:PROFILEURL|*">Follow on Twitter</a>&nbsp;&nbsp;&nbsp;<a href="test/?email=test%40test.de">Friend on Facebook</a>&nbsp;&nbsp;&nbsp;<a href="*|FORWARD|*">Forward to Friend</a>&nbsp;
</td>
</tr>
<tr>
<td valign="top" class="footerContent" style="padding-top:0;" mc:edit="footer_content01">
<tr>
<td valign="top" class="footerContent" style="padding-top:0;" mc:edit="footer_content01">
<em>Copyright &copy; *|CURRENT_YEAR|* *|LIST:COMPANY|*, All rights reserved.</em>
<br>
*|IFNOT:ARCHIVE_PAGE|* *|LIST:DESCRIPTION|*
<br>
<br>
<strong>Our mailing address is:</strong>
<br><br><strong>Our mailing address is:</strong>
<br>
*|HTML:LIST_ADDRESS_HTML|* *|END:IF|*
</td>
</tr>
<tr>
<td valign="top" class="footerContent" style="padding-top:0; padding-bottom:40px;" mc:edit="footer_content02">
<tr>
<td valign="top" class="footerContent" style="padding-top:0; padding-bottom:40px;" mc:edit="footer_content02">
<a href="*|UNSUB|*">unsubscribe from this list</a>&nbsp;&nbsp;&nbsp;<a href="*|UPDATE_PROFILE|*">update subscription preferences</a>&nbsp;
</td>
</tr>
</table>
<!-- // END FOOTER -->
</td>
</table>
<!-- // END FOOTER -->
</td>
</tr>
</table>
<!-- // END TEMPLATE -->
</td>
</tr>
</table>
</table>
<!-- // END TEMPLATE -->
</td>
</tr></table>
</center>
</body>
</html>

0 comments on commit e093d70

Please sign in to comment.