Reputation: 87
i have a problem with one 3rd party component for Joomla 3. Unfortunately i'm not an advanced php developer and the component owner does not support this for now, so i'm completely on my own =)
In advance - i have read all related topics there and was not able to make it ont he right way.
My problem is to convert this line:
return preg_replace('/\{([a-zA-Z_]+)\}/e', '$item->\\1', $this->rowtemplate);
with preg_replace_callback(), since in php 5.5 /e parameter is deprecated.
Thanks a lot in advance.
Edit:
There is the whole code part:
public function loadRowtemplate ($item)
{
$table = $this->params->get('table');
if(!$this->rowtemplate) {
$rowtemplate = $table['row'][0] ? "<td><p>" . nl2br($table['row'][0]) . "</p></td>" : "";
$rowtemplate .= $table['row'][1] ? "<td><p>" . nl2br($table['row'][1]) . "</p></td>" : "";
$rowtemplate .= $table['row'][2] ? "<td><p>" . nl2br($table['row'][2]) . "</p></td>" : "";
$rowtemplate .= $table['row'][3] ? "<td><p>" . nl2br($table['row'][3]) . "</p></td>" : "";
$rowtemplate .= $table['row'][4] ? "<td><p>" . nl2br($table['row'][4]) . "</p></td>" : "";
$this->rowtemplate = str_replace(",", "<br/>", $rowtemplate);
}
**return preg_replace('/\{([a-zA-Z_]+)\}/e', '$item->\\1', $this->rowtemplate);**
}
Edit 2:
There is correct working solution for Joomla 3 and Profiler by Harold Prins Extension (com_profiler) with PHP 5.5:
return preg_replace_callback(
'/\{([a-zA-Z_]+)\}/',
function ($match) use ($item) {
if (isset($item->{$match[1]})) {
return $item->{$match[1]};
}
return "";
},
$this->rowtemplate
);
Thanks a lot to Matteo Tassinari for solution.
Upvotes: 0
Views: 989
Reputation: 18584
What you want should look like:
return preg_replace_callback(
'/\{([a-zA-Z_]+)\}/',
function ($match) use ($item) {
if (isset($item->{$match[1]})) {
return $item->{$match[1]};
}
return "";
},
$this->rowtemplate
);
see also the docs for the function itself: http://php.net/manual/en/function.preg-replace-callback.php
Upvotes: 2