Changeset 26999 for branches/2.6


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)

Location:
branches/2.6
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/2.6/admin/history.php

    r26649 r26999  
    340340    name, url_name
    341341  FROM '.TAGS_TABLE;
     342
     343    global $name_of_tag; // used for preg_replace
    342344    $name_of_tag = array();
    343345    $result = pwg_query($query);
     
    400402    if (isset($line['tag_ids']))
    401403    {
    402       $tags_string = preg_replace(
    403         '/(\d+)/e',
    404         'isset($name_of_tag["$1"]) ? $name_of_tag["$1"] : "$1"',
     404      $tags_string = preg_replace_callback(
     405        '/(\d+)/',
     406        create_function('$m', 'return isset($name_of_tag[$m[1]]) ? $name_of_tag[$m[1]] : $m[1];'),
    405407        str_replace(
    406408          ',',
     
    542544      )
    543545    );
     546
     547  unset($name_of_tag);
    544548}
    545549
  • branches/2.6/admin/include/functions.php

    r26921 r26999  
    577577  ORDER BY id_uppercat,rank,name';
    578578
     579  global $cat_map; // used in preg_replace callback
    579580  $cat_map = array();
    580581
     
    603604  $datas = array();
    604605
     606  $cat_map_callback = create_function('$m', 'global $cat_map; return $cat_map[$m[1]]["rank"];');
     607
    605608  foreach( $cat_map as $id=>$cat )
    606609  {
    607     $new_global_rank = preg_replace(
    608           '/(\d+)/e',
    609           "\$cat_map['$1']['rank']",
    610           str_replace(',', '.', $cat['uppercats'] )
    611           );
     610    $new_global_rank = preg_replace_callback(
     611      '/(\d+)/',
     612      $cat_map_callback,
     613      str_replace(',', '.', $cat['uppercats'] )
     614      );
     615
    612616    if ( $cat['rank_changed']
    613617      or $new_global_rank!=$cat['global_rank']
     
    621625    }
    622626  }
     627
     628  unset($cat_map);
    623629
    624630  mass_updates(
  • branches/2.6/admin/include/languages.class.php

    r26461 r26999  
    403403   * Sort functions
    404404   */
    405   function language_version_compare($a, $b)
    406   {
    407     $pattern = array('/([a-z])/ei', '/\.+/', '/\.\Z|\A\./');
    408     $replacement = array( "'.'.intval('\\1', 36).'.'", '.', '');
    409 
    410     $array = preg_replace($pattern, $replacement, array($a, $b));
    411 
    412     return version_compare($array[0], $array[1], '>=');
    413   }
    414 
    415405  function extension_name_compare($a, $b)
    416406  {
  • branches/2.6/admin/include/plugins.class.php

    r26461 r26999  
    615615   * Sort functions
    616616   */
    617   function plugin_version_compare($a, $b)
    618   {
    619     if (strtolower($a) == 'auto') return false;
    620    
    621     $array = preg_replace(
    622       array('/\.+/', '/\.\Z|\A\./'),
    623       array('.', ''),
    624       array($a, $b)
    625       );
    626      
    627     $array = preg_replace_callback(
    628       '/([a-z])/i',
    629       create_function('$m', 'return intval($m[1], 36);'),
    630       $array
    631       );
    632    
    633     return version_compare($array[0], $array[1], '>=');
    634   }
    635 
    636617  function extension_revision_compare($a, $b)
    637618  {
  • branches/2.6/admin/include/themes.class.php

    r26461 r26999  
    690690   * Sort functions
    691691   */
    692   function theme_version_compare($a, $b)
    693   {
    694     $pattern = array('/([a-z])/ei', '/\.+/', '/\.\Z|\A\./');
    695     $replacement = array( "'.'.intval('\\1', 36).'.'", '.', '');
    696 
    697     $array = preg_replace($pattern, $replacement, array($a, $b));
    698 
    699     return version_compare($array[0], $array[1], '>=');
    700   }
    701 
    702692  function extension_revision_compare($a, $b)
    703693  {
  • 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.