View Single Post
  #189  
Old 07-22-2019, 02:46 PM
ChiNa ChiNa is offline
 
Join Date: Jul 2012
Posts: 457
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

How to fix preg_replace() errors in PHP 5.6 + 7.x for DJ AME's 2.5/2.7 :

- This fix is for the preg_replace Errors (Error 1) in ame_bbcode.php reported by user Mandushi above.
- In my case I encountered the 2nd Error (Error 2) seen below after upgrading to vBulletin 3.8.1.1 and PHP 5.6+

Error 1: In vBulletin 3.8.x versions using PHP 5.6 +:
Code:
mod_fcgid: stderr: PHP Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /includes/ame_bbcode.php on line 712
Error 2: In vBulletin 3.8.1.1, when using PHP 5.6 +:
Code:
Deprecated: preg_replace(): The /e modifier is deprecated, use  preg_replace_callback instead in includes/ame_bbcode.php on line  331\n'
Here is the fix:

Thankfully I had some help to complete this fix long time a go on StackOverflow (Credits Barmar). So the methods below below will fix all of the preg_replace deprecated errors in ame_bbcode.php file.

1. Edit the > ame_bbcode.php and find this line in function named (&fetch_full_ameinfo):
Code:
if (!$findonly)
2. Then replace the COMPLETE section with this instead:
Code:
if (!$findonly)
        {

        $ameinfo['find'][] = "~($result[findcode])~ie";
        $ameinfo['replace'][] = 'ame_match_bbcode($param1, $param2, \'' . $result['ameid'] . '\', \'' . ame_slasher($result['title']) . '\', ' . $result['container'] . ', \'' . ame_slasher($result['replacecode']) . '\', \'$match[1]\', \'$match[2]\', \'$match[3]\', \'$match[4]\', \'$match[5]\', \'$match[6]\')';

        }
        else
        {

        $ameinfo['find'][] = "~(\[url\]$result[findcode]\[/url\])~ie";
        $ameinfo['find'][] = "~(\[url="?$result[findcode]"?\](.*?)\[/url\])~i";
        $ameinfo['replace'][] = 'ame_match("$match[1]", "", ' . intval($result['extraction']) .', "' . ($result['embedregexp'] ? "~" . ame_slasher($result['embedregexp']) . "~sim" : "") . '", "' . ($result['validation'] ? "~" . ame_slasher($result['validation']) . "~sim" : "") . '",$ameinfo)';
        $ameinfo['replace'][] = 'ame_match("$match[1]", "$match[2]", ' . intval($result['extraction']) .', "' . ($result['embedregexp'] ? "~" . ame_slasher($result['embedregexp']) . "~sim" : "") . '", "' . ($result['validation'] ? "~" . ame_slasher($result['validation']) . "~sim" : "") . '", $ameinfo)';

            }
3. Next find the line below in function named function ame_process_bbcode:
Code:
$text = preg_replace($ameinfo['find'], $ameinfo['replace'], ($param2 ? $param2 : $param1), 1);
4. And replace it with this instead:
Code:
$text = preg_replace_callback($ameinfo['find'], function($match) use (&$param1, &$param2, &$ameinfo) {
        return eval($ameinfo['replace']);
    }, ($param2 ? $param2 : $param1), 1);
And that's pretty much it. Now you should no longer experince the preg_replace errors in ame_bbcode.php

Additional Fix for line 324 in ame_bbcode.php

1. The line seen below at line 324 will also show up as a Deprecated Error:

Code:
$text = preg_replace($ameinfo['find'], $ameinfo['replace'], $text);
2. To fix it, just replace it with the line below as well:

Code:
      $text = preg_replace($substitutes, $subhandlers, $text);
      $text = preg_replace_callback($ameinfo['find'], function($match) use (&$text) {
        return eval($ameinfo['replace']);
       }, ($text), 1);

Please leave a feed back for others to know if you were able to make it work on your end. Thank you.

Regards China.
Reply With Quote
2 благодарности(ей) от:
Mandushi, z3r0
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01504 seconds
  • Memory Usage 1,789KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (8)bbcode_code
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (2)post_thanks_box_bit
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete