aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authormistic100 <mistic@piwigo.org>2014-01-26 00:38:37 +0000
committermistic100 <mistic@piwigo.org>2014-01-26 00:38:37 +0000
commitfae05b2743c514db2c345b2cf53c317af9d5ac5f (patch)
tree342df4daca0751692a2a45091901a1f7418cbf0b /include
parent948adde84006257791e5e7239c2c159eeac0d872 (diff)
replace more preg_replace callback
git-svn-id: http://piwigo.org/svn/trunk@26972 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include')
-rw-r--r--include/emogrifier.class.php20
1 files changed, 14 insertions, 6 deletions
diff --git a/include/emogrifier.class.php b/include/emogrifier.class.php
index ef2c49730..744dd45f8 100644
--- a/include/emogrifier.class.php
+++ b/include/emogrifier.class.php
@@ -35,6 +35,7 @@ UPDATES
Fixed some recent code introductions to make it cleaner to read.
2012-05-01 Made removal of invisible nodes operate in a case-insensitive manner... Thanks Juha P.!
2013-10-10 Add preserveStyleTag option
+ 2014-01-26 PHP 5.5 compatibility (/e modifier is deprecated in preg_replace)
*/
define('CACHE_CSS', 0);
@@ -124,7 +125,7 @@ class Emogrifier {
$vistedNodes = $vistedNodeRef = array();
$nodes = @$xpath->query('//*[@style]');
foreach ($nodes as $node) {
- $normalizedOrigStyle = preg_replace('/[A-z\-]+(?=\:)/Se',"strtolower('\\0')", $node->getAttribute('style'));
+ $normalizedOrigStyle = preg_replace_callback('/[A-z\-]+(?=\:)/S',create_function('$m', 'return strtolower($m[0]);'),$node->getAttribute('style'));
// in order to not overwrite existing style attributes in the HTML, we have to save the original HTML styles
$nodeKey = md5($node->getNodePath());
@@ -299,9 +300,6 @@ class Emogrifier {
'/([^\/]+):last-child/i', // last-child pseudo-selector
'/(\w)\[(\w+)\]/', // Matches element with attribute
'/(\w)\[(\w+)\=[\'"]?(\w+)[\'"]?\]/', // Matches element with EXACT attribute
- '/(\w+)?\#([\w\-]+)/e', // Matches id attributes
- '/(\w+|[\*\]])?((\.[\w\-]+)+)/e', // Matches class attributes
-
);
$replace = array(
'/',
@@ -311,12 +309,14 @@ class Emogrifier {
'*[last()]/self::\\1',
'\\1[@\\2]',
'\\1[@\\2="\\3"]',
- "(strlen('\\1') ? '\\1' : '*').'[@id=\"\\2\"]'",
- "(strlen('\\1') ? '\\1' : '*').'[contains(concat(\" \",@class,\" \"),concat(\" \",\"'.implode('\",\" \"))][contains(concat(\" \",@class,\" \"),concat(\" \",\"',explode('.',substr('\\2',1))).'\",\" \"))]'",
);
$css_selector = '//'.preg_replace($search, $replace, $css_selector);
+ // matches ids and classes
+ $css_selector = preg_replace_callback('/(\w+)?\#([\w\-]+)/', array($this, 'matchIdAttributes'), $css_selector);
+ $css_selector = preg_replace_callback('/(\w+|[\*\]])?((\.[\w\-]+)+)/', array($this, 'matchClassAttributes'), $css_selector);
+
// advanced selectors are going to require a bit more advanced emogrification
// if we required PHP 5.3 we could do this with closures
$css_selector = preg_replace_callback('/([^\/]+):nth-child\(\s*(odd|even|[+\-]?\d|[+\-]?\d?n(\s*[+\-]\s*\d)?)\s*\)/i', array($this, 'translateNthChild'), $css_selector);
@@ -327,6 +327,14 @@ class Emogrifier {
return $this->caches[CACHE_SELECTOR][$xpathkey];
}
+ private function matchIdAttributes($m) {
+ return (strlen($m[1]) ? $m[1] : '*').'[@id="'.$m[2].'"]';
+ }
+
+ private function matchClassAttributes($m) {
+ return (strlen($m[1]) ? $m[1] : '*').'[contains(concat(" ",@class," "),concat(" ","'.implode('"," "))][contains(concat(" ",@class," "),concat(" ","',explode('.',substr($m[2],1))).'"," "))]';
+ }
+
private function translateNthChild($match) {
$result = $this->parseNth($match);