Skip to content

Technical changes in Piwigo 12

Pierrick Le Gall edited this page Sep 20, 2021 · 3 revisions

Has Settings

The “Has Settings” properties on plugins, introduced for Piwigo 11, see technical changes in version 11 is now mandatory with the new plugin manager.

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.

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);
}

With the new version of Smarty, an new error appears in the template :

Warning: Parameter 2 to wm_add_link_prefilter() expected to be a reference, value given

We would prefer not to modify Smarty (to keep it as "vanilla" as possible). To fix the issue, just remove the &$smarty in prefilter functions unless you know exactly what you are doing with it.

Php sort functions

PHP 8 introduced the Stable Sorting RFC, which means that all sorting functions in PHP are now "stable". More details about this in the link.

Smarty template variables

In previous versions of smarty, uninitialized template variable were considered as "not existing" or "false". In the version we are using now, theses uninitialized variales are causing errors. To prevent these you need to test if the variable exists in the template as it follows:

In previous version this would work but now it causes errors when $my_variable is not initialized.

  {if $my_variable}
    {$my_variable} exists !
  {/if}

And this does not causes any errors as you test if $my_variable exists.

  {if isset($my_variable) and $my_variable}
    {$my_variable} exists !
  {/if}

Of course, if your variable always have a value, it doesn't need to be tested.

End of upload

At the end of an upload, call the new pwg.images.uploadCompleted method. It will force Piwigo to empty the lounge immediately and plugins will use the appropriate new trigger ws_images_uploadCompleted (with the provided list of image_ids) to know if they have something to do with it. Think about a plugin like Smart Albums, that needs to check if new photos must be added to a smart album...

MySQL and reserved keywords

With new versions, MySQL adds some reserved keywords. For example the word groups became a reserved keyword with MySQL 8. The problem is that Piwigo has a table piwigo_groups but the prefix piwigo_ can be empty... We have to protect the reserved words with backticks`` in SQL queries.

In Piwigo 2.10 we automatically escaped rank. In Piwigo 11 we automatically escaped groups in all SQL queries. The idea seemed good but it had many collateral damages with unwanted escapes in the middle on word or configuration settings.

In Piwigo 11, we remove this automatic escape. Each SQL query using rank or groups will have to deal with escaping it.