From 161e5e91996c98cf3286bdbb107a47a72b513589 Mon Sep 17 00:00:00 2001
From: Kolier <kolier.li@gmail.com>
Date: Mon, 6 Oct 2014 16:31:36 +0800
Subject: [PATCH] Fix: #2103151, Reroll patch based on
 https://www.drupal.org/files/issues/deprecated_e-2103151-16.patch

---
 filefield_paths.module | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/filefield_paths.module b/filefield_paths.module
index 989a9d0..3dba703 100644
--- a/filefield_paths.module
+++ b/filefield_paths.module
@@ -298,24 +298,27 @@ function _filefield_paths_replace_path($old, $new, $entity) {
   // Build replacement.
   $info = parse_url(file_stream_wrapper_uri_normalize($new));
   $info['path'] = !empty($info['path']) ? $info['path'] : '';
-  $replacement = "_filefield_paths_replace_path_uri_scheme('\${1}', '{$old}', '{$new}') . '\${2}{$info['host']}{$info['path']}'";
+  $replacement = "_filefield_paths_replace_path_uri_scheme(\$matches[1], '{$old}', '{$new}') . \$matches[2] . '{$info['host']}{$info['path']}'";
 
   // Newer versions of the Image module add an 8 character token which is
   // required if the image style hasn't been generated yet. Look for this token
   // in the query string and replace it.
   if (defined('IMAGE_DERIVATIVE_TOKEN')) {
-    $regex .= '(\?(\S+?&|)' . IMAGE_DERIVATIVE_TOKEN . '=(\S{8})|)';
-    $replacement .= " . _filefield_paths_replace_image_derivative_token('{$old}', '{$new}', '\${5}', '\${7}', '\${3}')";
+    $regex .= '(\?(\S+?&|)' . IMAGE_DERIVATIVE_TOKEN . '=(\S{8})|())';
+    $replacement .= " . _filefield_paths_replace_image_derivative_token('{$old}', '{$new}', \$matches[5], \$matches[7], \$matches[3])";
   }
 
+  // Create an anonymous function for the replacement via preg_replace_callback.
+  $replacement_callback = create_function('$matches', "return {$replacement};");
+
   $fields = field_info_fields();
   foreach ($fields as $name => $field) {
     if ($field['module'] == 'text' && isset($entity->{$field['field_name']}) && is_array($entity->{$field['field_name']})) {
       foreach ($entity->{$field['field_name']} as &$language) {
         foreach ($language as &$item) {
-          $item['value'] = preg_replace("/$regex/e", $replacement, $item['value']);
+          $item['value'] = preg_replace_callback("/$regex/", $replacement_callback, $item['value']);
           if (isset($item['summary'])) {
-            $item['summary'] = preg_replace("/$regex/e", $replacement, $item['summary']);
+            $item['summary'] = preg_replace_callback("/$regex/", $replacement_callback, $item['summary']);
           }
         }
       }
-- 
1.9.4.msysgit.1

