Ignore:
Timestamp:
Jan 27, 2014, 7:05:04 PM (10 years ago)
Author:
mistic100
Message:

Merged revision(s) 26972, 26998 from trunk:
replace more preg_replace callback
........
remove *_version_compare methods in languages & plugins & themes classes, unused and outdated (preg_replace /e modifier)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.6/include/emogrifier.class.php

    r25344 r26999  
    3636    2012-05-01  Made removal of invisible nodes operate in a case-insensitive manner... Thanks Juha P.!
    3737    2013-10-10  Add preserveStyleTag option
     38    2014-01-26  PHP 5.5 compatibility (/e modifier is deprecated in preg_replace)
    3839*/
    3940
     
    125126        $nodes = @$xpath->query('//*[@style]');
    126127        foreach ($nodes as $node) {
    127             $normalizedOrigStyle = preg_replace('/[A-z\-]+(?=\:)/Se',"strtolower('\\0')", $node->getAttribute('style'));
     128            $normalizedOrigStyle = preg_replace_callback('/[A-z\-]+(?=\:)/S',create_function('$m', 'return strtolower($m[0]);'),$node->getAttribute('style'));
    128129
    129130            // in order to not overwrite existing style attributes in the HTML, we have to save the original HTML styles
     
    300301                               '/(\w)\[(\w+)\]/', // Matches element with attribute
    301302                               '/(\w)\[(\w+)\=[\'"]?(\w+)[\'"]?\]/', // Matches element with EXACT attribute
    302                                '/(\w+)?\#([\w\-]+)/e', // Matches id attributes
    303                                '/(\w+|[\*\]])?((\.[\w\-]+)+)/e', // Matches class attributes
    304 
    305303            );
    306304            $replace = array(
     
    312310                               '\\1[@\\2]',
    313311                               '\\1[@\\2="\\3"]',
    314                                "(strlen('\\1') ? '\\1' : '*').'[@id=\"\\2\"]'",
    315                                "(strlen('\\1') ? '\\1' : '*').'[contains(concat(\" \",@class,\" \"),concat(\" \",\"'.implode('\",\" \"))][contains(concat(\" \",@class,\" \"),concat(\" \",\"',explode('.',substr('\\2',1))).'\",\" \"))]'",
    316312            );
    317313
    318314            $css_selector = '//'.preg_replace($search, $replace, $css_selector);
     315
     316            // matches ids and classes
     317            $css_selector = preg_replace_callback('/(\w+)?\#([\w\-]+)/', array($this, 'matchIdAttributes'), $css_selector);
     318            $css_selector = preg_replace_callback('/(\w+|[\*\]])?((\.[\w\-]+)+)/', array($this, 'matchClassAttributes'), $css_selector);
    319319
    320320            // advanced selectors are going to require a bit more advanced emogrification
     
    326326        }
    327327        return $this->caches[CACHE_SELECTOR][$xpathkey];
     328    }
     329
     330    private function matchIdAttributes($m) {
     331      return (strlen($m[1]) ? $m[1] : '*').'[@id="'.$m[2].'"]';
     332    }
     333
     334    private function matchClassAttributes($m) {
     335      return (strlen($m[1]) ? $m[1] : '*').'[contains(concat(" ",@class," "),concat(" ","'.implode('"," "))][contains(concat(" ",@class," "),concat(" ","',explode('.',substr($m[2],1))).'"," "))]';
    328336    }
    329337
Note: See TracChangeset for help on using the changeset viewer.