From 6fcc5f10df0fbd02877e49aec7b662c64c60acc7 Mon Sep 17 00:00:00 2001 From: mistic100 Date: Mon, 27 Jan 2014 18:05:04 +0000 Subject: 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) git-svn-id: http://piwigo.org/svn/branches/2.6@26999 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin/history.php | 10 +++++++--- admin/include/functions.php | 16 +++++++++++----- admin/include/languages.class.php | 10 ---------- admin/include/plugins.class.php | 19 ------------------- admin/include/themes.class.php | 10 ---------- include/emogrifier.class.php | 20 ++++++++++++++------ 6 files changed, 32 insertions(+), 53 deletions(-) diff --git a/admin/history.php b/admin/history.php index 8307d5e32..8a2e07926 100644 --- a/admin/history.php +++ b/admin/history.php @@ -339,6 +339,8 @@ SELECT id, name, url_name FROM '.TAGS_TABLE; + + global $name_of_tag; // used for preg_replace $name_of_tag = array(); $result = pwg_query($query); while ($row=pwg_db_fetch_assoc($result)) @@ -399,9 +401,9 @@ SELECT $tags_string = ''; if (isset($line['tag_ids'])) { - $tags_string = preg_replace( - '/(\d+)/e', - 'isset($name_of_tag["$1"]) ? $name_of_tag["$1"] : "$1"', + $tags_string = preg_replace_callback( + '/(\d+)/', + create_function('$m', 'return isset($name_of_tag[$m[1]]) ? $name_of_tag[$m[1]] : $m[1];'), str_replace( ',', ', ', @@ -541,6 +543,8 @@ SELECT ), ) ); + + unset($name_of_tag); } // +-----------------------------------------------------------------------+ diff --git a/admin/include/functions.php b/admin/include/functions.php index 1df6e4f45..bdeab47e7 100644 --- a/admin/include/functions.php +++ b/admin/include/functions.php @@ -576,6 +576,7 @@ SELECT id, id_uppercat, uppercats, rank, global_rank FROM '.CATEGORIES_TABLE.' ORDER BY id_uppercat,rank,name'; + global $cat_map; // used in preg_replace callback $cat_map = array(); $current_rank = 0; @@ -602,13 +603,16 @@ SELECT id, id_uppercat, uppercats, rank, global_rank $datas = array(); + $cat_map_callback = create_function('$m', 'global $cat_map; return $cat_map[$m[1]]["rank"];'); + foreach( $cat_map as $id=>$cat ) { - $new_global_rank = preg_replace( - '/(\d+)/e', - "\$cat_map['$1']['rank']", - str_replace(',', '.', $cat['uppercats'] ) - ); + $new_global_rank = preg_replace_callback( + '/(\d+)/', + $cat_map_callback, + str_replace(',', '.', $cat['uppercats'] ) + ); + if ( $cat['rank_changed'] or $new_global_rank!=$cat['global_rank'] ) @@ -621,6 +625,8 @@ SELECT id, id_uppercat, uppercats, rank, global_rank } } + unset($cat_map); + mass_updates( CATEGORIES_TABLE, array( diff --git a/admin/include/languages.class.php b/admin/include/languages.class.php index bb9487bec..c4caa2dc9 100644 --- a/admin/include/languages.class.php +++ b/admin/include/languages.class.php @@ -402,16 +402,6 @@ UPDATE '.USER_INFOS_TABLE.' /** * Sort functions */ - function language_version_compare($a, $b) - { - $pattern = array('/([a-z])/ei', '/\.+/', '/\.\Z|\A\./'); - $replacement = array( "'.'.intval('\\1', 36).'.'", '.', ''); - - $array = preg_replace($pattern, $replacement, array($a, $b)); - - return version_compare($array[0], $array[1], '>='); - } - function extension_name_compare($a, $b) { return strcmp(strtolower($a['extension_name']), strtolower($b['extension_name'])); diff --git a/admin/include/plugins.class.php b/admin/include/plugins.class.php index 0ddc85b50..9862bccd4 100644 --- a/admin/include/plugins.class.php +++ b/admin/include/plugins.class.php @@ -614,25 +614,6 @@ DELETE FROM '. PLUGINS_TABLE .' /** * Sort functions */ - function plugin_version_compare($a, $b) - { - if (strtolower($a) == 'auto') return false; - - $array = preg_replace( - array('/\.+/', '/\.\Z|\A\./'), - array('.', ''), - array($a, $b) - ); - - $array = preg_replace_callback( - '/([a-z])/i', - create_function('$m', 'return intval($m[1], 36);'), - $array - ); - - return version_compare($array[0], $array[1], '>='); - } - function extension_revision_compare($a, $b) { if ($a['revision_date'] < $b['revision_date']) return 1; diff --git a/admin/include/themes.class.php b/admin/include/themes.class.php index 7832c42e0..824ccf4b9 100644 --- a/admin/include/themes.class.php +++ b/admin/include/themes.class.php @@ -689,16 +689,6 @@ SELECT /** * Sort functions */ - function theme_version_compare($a, $b) - { - $pattern = array('/([a-z])/ei', '/\.+/', '/\.\Z|\A\./'); - $replacement = array( "'.'.intval('\\1', 36).'.'", '.', ''); - - $array = preg_replace($pattern, $replacement, array($a, $b)); - - return version_compare($array[0], $array[1], '>='); - } - function extension_revision_compare($a, $b) { if ($a['revision_date'] < $b['revision_date']) return 1; 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); -- cgit v1.2.3