Announcement

  •  » Engine
  •  » Piwigo 12, Smarty 3.1.39 and prefilters

#1 2021-08-11 15:53:21

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13791

Piwigo 12, Smarty 3.1.39 and prefilters

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:

Code:

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

 

#2 2021-08-11 16:29:43

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13791

Re: Piwigo 12, Smarty 3.1.39 and prefilters

By the way, in Piwigo-Skeleton plugin:

Code:

/**
 * 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

 

#3 2021-08-11 16:41:03

flop25
Piwigo Team
2006-07-06
7037

Re: Piwigo 12, Smarty 3.1.39 and prefilters

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


To get a better help : Politeness like Hello-A link-Your past actions precisely described
Check my extensions : more than 30 available
who I am and what I do : http://fr.gravatar.com/flop25
My gallery : an illustration of how to integrate Piwigo in your website

Offline

 

#4 2021-08-11 17:16:06

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13791

Re: Piwigo 12, Smarty 3.1.39 and prefilters

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

 

#5 2021-08-11 17:34:28

flop25
Piwigo Team
2006-07-06
7037

Re: Piwigo 12, Smarty 3.1.39 and prefilters

Backward compatibility in the way that those updated plug-ins will be compatible with smarty2?


To get a better help : Politeness like Hello-A link-Your past actions precisely described
Check my extensions : more than 30 available
who I am and what I do : http://fr.gravatar.com/flop25
My gallery : an illustration of how to integrate Piwigo in your website

Offline

 

#6 2021-08-12 18:06:47

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3277

Re: Piwigo 12, Smarty 3.1.39 and prefilters

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

 

#7 2021-08-12 19:30:42

flop25
Piwigo Team
2006-07-06
7037

Re: Piwigo 12, Smarty 3.1.39 and prefilters

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


To get a better help : Politeness like Hello-A link-Your past actions precisely described
Check my extensions : more than 30 available
who I am and what I do : http://fr.gravatar.com/flop25
My gallery : an illustration of how to integrate Piwigo in your website

Offline

 

#8 2021-08-16 15:53:22

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13791

Re: Piwigo 12, Smarty 3.1.39 and prefilters

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

 

#9 2021-10-21 22:51:42

jheinitz
Member
2015-02-16
21

Re: Piwigo 12, Smarty 3.1.39 and prefilters

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

 

#10 2021-11-06 20:10:56

alb
Member
2021-01-25
18

Re: Piwigo 12, Smarty 3.1.39 and prefilters

Just like to note that the "TakeATour" plugin (which is bundled with piwigo 12.0.0) needs update in its *_prefilter functions.

Offline

 

#11 2021-11-06 20:18:07

alb
Member
2021-01-25
18

Re: Piwigo 12, Smarty 3.1.39 and prefilters

And themes/modus/themeconf.inc.php (also bundled with piwigo 12.0.0) too.

Offline

 

#12 2021-11-06 20:32:40

erAck
Only trying to help
2015-09-06
2023

Re: Piwigo 12, Smarty 3.1.39 and prefilters

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.


Running Piwigo at https://erack.net/gallery/

Offline

 

#13 2022-01-05 05:02:08

Nigel-Aves
Member
2015-09-22
63

Re: Piwigo 12, Smarty 3.1.39 and prefilters

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

 

#14 2022-01-05 13:15:50

erAck
Only trying to help
2015-09-06
2023

Re: Piwigo 12, Smarty 3.1.39 and prefilters

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.


Running Piwigo at https://erack.net/gallery/

Offline

 
  •  » Engine
  •  » Piwigo 12, Smarty 3.1.39 and prefilters

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact