In Piwigo 12, to get compatibility with PHP 8, we have updated Smarty from a "modified" version 3.1.29 to version 3.1.39. Templates need a small change (checking if variable is set before using it) but I'm more concerned about prefilters.
In many plugins, here is the way a prefilter is used:
add_event_handler('loc_begin_admin_page', 'wm_add_link', 60); function wm_add_link() { global $template; $template->set_prefilter('picture_modify', 'wm_add_link_prefilter'); $template->assign('TEMPLATE_VAR', 'abcd'); } } function wm_add_link_prefilter($content, &$smarty) { $search = '<h1>'; $replacement = '<h1><a href="https://piwigo.org">piwigo.org</a> '; return str_replace($search, $replacement, $content); }
I have no idea why we have "&$smarty" as second parameter in the prefilter function definition. I haven't found any example where it's actually used. What we see, is that it fails after update to Smarty 3.1.39 :
Warning: Parameter 2 to wm_add_link_prefilter() expected to be a reference, value given
Considering I would prefer not to modify Smarty (to keep it as "vanilla" as possible), I see 2 solutions:
1) replace &$smarty by $smarty
2) remove the second paramter completely (I see no difference when it's removed...)
The third solution could be to reapply [Github] Piwigo commit 968e9ff0
I would like to decide what we do, so that we can give a direction to plugin developers in our "technical changes for Piwigo 12" guide.
Offline
By the way, in Piwigo-Skeleton plugin:
/** * add a prefilter on photo page */ function skeleton_loc_end_picture() { global $template; $template->set_prefilter('picture', 'skeleton_picture_prefilter'); } function skeleton_picture_prefilter($content) { $search = '{if $display_info.author and isset($INFO_AUTHOR)}'; $replace = ' <div id="Skeleton" class="imageInfo"> <dt>{\'Skeleton\'|@translate}</dt> <dd style="color:orange;">{\'Piwigo rocks\'|@translate}</dd> </div> '; return str_replace($search, $replace.$search, $content); }
That's solution 2. So I guess mistic100 likes this solution best.
Offline
Hi Pierrick!
that's way too high end coding for me^^
Are solutions 1&2 backward compatible?
i'm just seeing those changes in their doc:
old
https://www.smarty.net/docsv2/en/advanc … prefilters
new
https://www.smarty.net/docs/en/advanced … ilters.tpl
and stackoverflow examples which don't use that second argument
https://stackoverflow.com/questions/661 … 1#66163511
that's my 2cents
Offline
Hi flop25,
flop25 wrote:
Are solutions 1&2 backward compatible?
These 2 solutions mean the prefilter functions in plugins using "&$smarty" have to be changed. So it's not "backward compatible". It implies plugins to be changed. But Piwigo 12 already asks some changes to plugins, so it's not that much a problem I think.
and stackoverflow examples which don't use that second argument
I don't understand why we have this "&$smarty" in the first place :-/ Removing this parameter would not have any impact, unless it's useful to something I don't see!
Offline
Backward compatibility in the way that those updated plug-ins will be compatible with smarty2?
Offline
plg wrote:
flop25 wrote:
Are solutions 1&2 backward compatible?
These 2 solutions mean the prefilter functions in plugins using "&$smarty" have to be changed. So it's not "backward compatible". It implies plugins to be changed. But Piwigo 12 already asks some changes to plugins, so it's not that much a problem I think.
As I understand it, it *is* backward compatible, but it is not forward compatible. Which means plugins updated to 12 will still work on older versions, but plugins not updated will emit the warning.
---
I guess this variable exists to be able to use Smarty internals where not prefilter, pipes, etc, exists. But I don't remember ever using it.
Offline
mistic100 wrote:
As I understand it, it *is* backward compatible, but it is not forward compatible. Which means plugins updated to 12 will still work on older versions, but plugins not updated will emit the warning.
---
I guess this variable exists to be able to use Smarty internals where not prefilter, pipes, etc, exists. But I don't remember ever using it.
Thx!
removing that second variable/ref seems fine to me
Offline
mistic100 wrote:
As I understand it, it *is* backward compatible, but it is not forward compatible. Which means plugins updated to 12 will still work on older versions, but plugins not updated will emit the warning.
That's right.
It's a bit more than a warning. It eventually breaks the page.
We're going to recommend removing completely the second parameter.
Offline
Moin (as we say in the north of Germany),
I just came across this warning when I activated the PersoFavicon plugin. I checked the main.inc.php and removed the second argument "&$smarty" from the Favicon function, and the warning is gone.
In my case it was not only the warning, but also that the favicon did not show up.
I found out that the source code is not on Github, but on Trac Page. How can we modify the code there?
By the way, thanks for your good work. Keep on going.
Best regards
Jens
Offline
Just like to note that the "TakeATour" plugin (which is bundled with piwigo 12.0.0) needs update in its *_prefilter functions.
Offline
And themes/modus/themeconf.inc.php (also bundled with piwigo 12.0.0) too.
Offline
alb wrote:
Just like to note that the "TakeATour" plugin (which is bundled with piwigo 12.0.0) needs update in its *_prefilter functions.
I created merge request https://github.com/Piwigo/TakeATour/pull/13 for that.
Offline
I've been biding my time to update as so many plugin's were marked as incompatible. The good news is, I can now update
BUT
After updating to 12.2 and updating all the plugins I'm getting this message
Warning: Parameter 2 to del_FaviconF() expected to be a reference, value given in /home/soft-focus-imagining/domains/serendipity.soft-focus-imagining.com/public_html/include/smarty/libs/sysplugins/smarty_internal_runtime_filterhandler.php on line 63
Should I attempt to follow the changes in this thread or wait for an official fix.
Many Thanks,
Nigel.
p.s. Still the best gallery software available!
Offline
You seem to have followed [Forum, post 180378 by ddtddt in topic 31160] Stop PIWIGO from using "favicon.ico. Remove the ,&$smarty second parameter from the del_FaviconF() function signature.
Offline