Bladeren bron

Replaced list_getModLogEntries /e preg_replace with a callback.

Signed-off-by: Jeremy D <[email protected]>
Jeremy D 10 jaren geleden
bovenliggende
commit
26e21869df
2 gewijzigde bestanden met toevoegingen van 24 en 5 verwijderingen
  1. 20 1
      Sources/Modlog.php
  2. 4 4
      Sources/Subs.php

+ 20 - 1
Sources/Modlog.php

@@ -607,6 +607,7 @@ function list_getModLogEntries($start, $items_per_page, $sort, $query_string = '
 	}
 
 	// Do some formatting of the action string.
+	$callback = pregReplaceCurry('list_getModLogEntriesCallback', 3);
 	foreach ($entries as $k => $entry)
 	{
 		// Make any message info links so its easier to go find that message.
@@ -620,11 +621,29 @@ function list_getModLogEntries($start, $items_per_page, $sort, $query_string = '
 
 		if (empty($entries[$k]['action_text']))
 			$entries[$k]['action_text'] = isset($txt['modlog_ac_' . $entry['action']]) ? $txt['modlog_ac_' . $entry['action']] : $entry['action'];
-		$entries[$k]['action_text'] = preg_replace('~\{([A-Za-z\d_]+)\}~ie', 'isset($entries[$k][\'extra\'][\'$1\']) ? $entries[$k][\'extra\'][\'$1\'] : \'\'', $entries[$k]['action_text']);
+		$entries[$k]['action_text'] = preg_replace_callback('~\{([A-Za-z\d_]+)\}~i', $callback($entries, $k), $entries[$k]['action_text']);
+
 	}
 
 	// Back we go!
 	return $entries;
 }
 
+/**
+ * Smiely Replacment Callback.
+ *
+ * Our callback that does the actual smiley replacments.
+ *
+ * Original code from: http://php.net/manual/en/function.preg-replace-callback.php#88013
+ * This is needed until SMF only supports PHP 5.3+ and we change to "use"
+ *
+ * @param string $replacements
+ * @param string $matches
+ * @return string the replaced results.
+ */
+function list_getModLogEntriesCallback($entries, $key, $matches)
+{
+    return isset($entries[$key]['extra'][$matches[1]]) ? $entries[$key]['extra'][$matches[1]] : '';
+}
+
 ?>

+ 4 - 4
Sources/Subs.php

@@ -2470,15 +2470,15 @@ function parsesmileys(&$message)
 	/*
 	* TODO: When SMF supports only PHP 5.3+, we can change this to "uses" keyword and simpifly this.
 	*/
-	$callback = smielyPregReplaceCurry('smielyPregReplaceCallback', 2);
+	$callback = pregReplaceCurry('smielyPregReplaceCallback', 2);
 	$message = preg_replace_callback($smileyPregSearch, $callback($smileyPregReplacements), $message);
 }
 
 /**
- * Smiely Replacment Curry.
+ * Preg Replacment Curry.
  *
  * This allows use to do delayed argument binding and bring in
- * the replacement variables for smiley replacments.
+ * the replacement variables for some preg replacments.
  *
  * Original code from: http://php.net/manual/en/function.preg-replace-callback.php#88013
  * This is needed until SMF only supports PHP 5.3+ and we change to "use"
@@ -2487,7 +2487,7 @@ function parsesmileys(&$message)
  * @param string $arity
  * @return function a lambda function bound to $func.
  */
-function smielyPregReplaceCurry($func, $arity)
+function pregReplaceCurry($func, $arity)
 {
 	return create_function('', "
 		\$args = func_get_args();