phpfreechat icon indicating copy to clipboard operation
phpfreechat copied to clipboard

Fix in src/pfcurlprocessing.php for PHP7 compatibility

Open jhf2442 opened this issue 8 years ago • 5 comments

(sorry for not submitting a pull request, can't get it done - don't know what I'm doing wrong :-( ) pfcurlprocessing.php in PHP7 (Ubuntu 16.04) causes empty message content displayed

issue is caused by deprecated /e modifier in preg_replace. Fix is to go for preg_replace_callback

The 3 preg_replace statements must thus read : $ret = preg_replace_callback("#(^|[\n ]])([\w]+?://[\w#$%()&~/!.-;:=,?@+]*)#is", function($m) { return "$m[1]<a href="$m[2]"" . $target . ">" . pfc_shorten_url($m[2]) . "";}, $ret);

$ret = preg_replace_callback("#(^|[\n ]])((www|ftp).[\w#$%&~/.-;:=,?@+]*)#is",function($m) { return "$m[1]<a href="http://$m[2]"" . $target . ">" . pfc_shorten_url($m[2]) . "";}, $ret);

$ret = preg_replace_callback("#(^|[\n ]])([a-z0-9&-_.]+?)@([\w-]+.([\w-.]+.)*[\w]+)#i", function($m) { return "$m[1]<a href="mailto:$m[2]@$m[3]">" . pfc_shorten_url($m[2].'@'.$m[3]) . "";}, $ret);

jhf2442 avatar Jun 30 '16 21:06 jhf2442

attempted this change and still getting blank messages :-( Currently just removed the pfc_make_hyperlink call from the get message command and things all work except the auto hyperlinking.

EZWrighter avatar Sep 09 '16 21:09 EZWrighter

I solved it like this (for PHP 7):

$ret = preg_replace_callback("#(^|[\n \]])([\w]+?://[\w\#$%\(\)&~/!.\-;:=,?@+]*)#is", 'replace_callback_1', $ret);
$ret = preg_replace_callback("#(^|[\n \]])((www|ftp)\.[\w\#$%&~/.\-;:=,?@+]*)#is", 'replace_callback_2', $ret);  
$ret = preg_replace_callback("#(^|[\n \]])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", 'replace_callback_3', $ret); 

function replace_callback_1($matches) {
  $target = " onclick=\"window.open(this.href,'_blank');return false;\"";
  return $matches[1].'<a href="'.$matches[2].'"' . $target . '>' . pfc_shorten_url($matches[2]) . '</a>';
}  
function replace_callback_2($matches) {
  $target = " onclick=\"window.open(this.href,'_blank');return false;\"";
  return $matches[1].'<a href="http://'.$matches[2].'"' . $target . '>' . pfc_shorten_url($matches[2]) . '</a>';
}  
function replace_callback_3($matches) {
  return $matches[1].'<a href="mailto:'.$matches[2].'@'.$matches[3].'">' . pfc_shorten_url($matches[2].'@'.$matches[3]) . '</a>';
}

webprogrammierer avatar Apr 05 '17 23:04 webprogrammierer

@webprogrammierer Which file do I have to put this code into?

Torsten-K avatar Nov 13 '17 10:11 Torsten-K

@Torsten-K I have made this changes in the file src/pfcurlprocessing.php

webprogrammierer avatar Jan 03 '18 17:01 webprogrammierer

@webprogrammierer Danke schön / thank you!

Torsten-K avatar Jan 05 '18 10:01 Torsten-K