Differences

This shows you the differences between two versions of the page.

Link to this comparison view

dev:changes_in_2.7 [2014/02/18 16:05]
mistic100 [add_event_handler() 4th parameter]
dev:changes_in_2.7 [2014/09/22 15:25] (current)
plg info about batch manager and filters + search.tpl
Line 1: Line 1:
 ====== Technical changes in Piwigo 2.7 ====== ====== Technical changes in Piwigo 2.7 ======
  
-===== add_event_handler() 4th parameter =====+===== About Plugins / PHP ===== 
 + 
 +==== trigger_change / trigger_notify ==== 
 +<WRAP important>Following what was [[http://piwigo.org/doc/doku.php?id=dev:changes_in_2.6#triggers_functions|announced for Piwigo 2.6]], the functions **trigger_event** and **trigger_action** were deleted. You must use **trigger_change** and **trigger_notify** instead.</WRAP> 
 + 
 + 
 +==== add_event_handler() 4th parameter ====
 The fourth parameter of **add_event_handler** function was used to tell the number of parameters which will be transmitted to the callback. This is no longer used: all parameters given to **trigger_change** or **trigger_notify** are always transmitted to all callback. The fourth parameter of **add_event_handler** function was used to tell the number of parameters which will be transmitted to the callback. This is no longer used: all parameters given to **trigger_change** or **trigger_notify** are always transmitted to all callback.
  
Line 20: Line 26:
  
 If the 4th parameter is anything else than a string it is ignored. If the 4th parameter is anything else than a string it is ignored.
 +
 +
 +==== Plugin maintenance class ====
 +We introduced a new pattern for maintenance of plugins, this uses a PHP class named after your plugin and define in a **maintain.class.php** file with the following methods:
 +
 +<code php>
 +/**
 + * PLUGINID must be replaced by the directory name of your plugin
 + */
 +class PLUGINID_maintain extends PluginMaintain
 +{
 +  function install($plugin_version, &$errors=array()) { ... }
 +  function activate($plugin_version, &$errors=array()) { ... }
 +  function update($old_version, $new_version, &$errors=array()) { ... }
 +  function deactivate() { ... }
 +  function uninstall() { ... }
 +}
 +</code>
 +
 +The **update** method can be called outside the automatic update process, for example if plugin files are manually replaced with a newer version, this ensure full support on hosts which block auto-update.
 +
 +The old file **maintain.inc.php** is still supported and will never be removed.
 +
 +==== conf_update_param ====
 +**conf_update_param** function has been enhanced:
 +  * if an array or object is provided as a value, it will be serialized and escaped before database insertion
 +  * provide **true** as third parameter to update the **$conf** global as well (with unserialized value)
 +  * if you prefer JSON over PHP serial you can provide a custom serializer as fourth parameter
 +
 +<code php>
 +conf_update_param('my_key', $my_array, true,
 +  create_function('$v', 'return addslashes(json_encode($v));'));
 +
 +// here, $conf['my_key'] == $my_array;
 +</code>
 +
 +Two utility functions was added: **safe_unserialize** and **safe_json_decode** which can be used if you are not sure if the value has already been unserialized or not.
 +
 +==== Selectize ====
 +
 +The plugins TokenInput and Chosen have been removed in favor to [[http://brianreavis.github.io/selectize.js/|Selectize]].
 +
 +Use this to load the script:
 +<code>
 +{combine_script id='jquery.selectize' load='footer' path='themes/default/js/plugins/selectize.min.js'}
 +</code>
 +
 +The old plugins sources will be removed in further version, your are advised to migrate now.
 +
 +== Theming ==
 +
 +Selectize comes with two colorschemes, dark and clear loaded conditionally with help of [[#themeconf_colorscheme|$themeconf['colorscheme']]].
 +
 +Use this to load the CSS:
 +<code>
 +{combine_css id='jquery.selectize' path="themes/default/js/plugins/selectize.{$themeconf.colorscheme}.css"}
 +</code>
 +
 +== Cache ==
 +
 +We added a LocalStorage cache for the lists of tags/albums/users/groups. It is used on every core Selectize box and considerably speeds-up loading time of admin pages. Here is how to use it.
 +
 +**Include the script (before or after Selectize):**
 +<code>
 +{combine_script id='LocalStorageCache' load='footer' path='admin/themes/default/js/LocalStorageCache.js'}
 +</code>
 +
 +**Add the HTML element:**
 +<code html>
 +<select data-selectize="categories" data-value="{$associated_albums|@json_encode|escape:html}"
 +        data-default="{$STORAGE_ALBUM}" name="associate[]" multiple>
 +</select>
 +</code>
 +''$associated_albums'' must be an array of identifiers for the preselect items.  
 +''data-default'' represents a item which can't be removed.
 +
 +**Init the cache:**
 +<code javascript>
 +var categoriesCache = new CategoriesCache({
 +  serverKey: '{$CACHE_KEYS.categories}',
 +  serverId: '{$CACHE_KEYS._hash}',
 +  rootUrl: '{$ROOT_URL}'
 +});
 +</code>
 +''$CACHE_KEYS'' array is used to sync the cache with the server, it contains state keys for ''categories'', ''tags'', ''users'' and ''groups''.
 +
 +**Init Selectize with the cache:**
 +<code javascript>
 +categoriesCache.selectize(jQuery('[data-selectize=categories]'));
 +</code>
 +
 +== Add album popin ==
 +
 +The reusable "add new album" popin (using Colorbox) has obviously been rewritten to use (exclusively) Selectize and the cache.
 +
 +**As before, include the template:**
 +<code>
 +{include file='include/add_album.inc.tpl'}
 +</code>
 +
 +**Add the receiving select and add button:**
 +<code html>
 +<select data-selectize="categories" data-value="{$selected_category|@json_encode|escape:html}"
 +  data-default="first" name="category" style="width:400px"></select>
 +
 +<br>{'... or '|@translate}
 +<a href="#" data-add-album="category" title="{'create a new album'|translate}">
 +  {'create a new album'|@translate}</a>
 +</code>
 +''data-add-album'' value refers to the ''name'' of the select.
 +
 +**Apply pwgAddAlbum micro-plugin by providing the cache:**
 +<code javascript>
 +jQuery('[data-add-album]').pwgAddAlbum({ cache: categoriesCache });
 +</code>
 +
 +==== Batch Manager, add filters ====
 +
 +We have added 2 trigger_change to add filters in the Batch Manager. The first on batch_manager_register_filters let you register a filter:
 +
 +<code php>add_event_handler('batch_manager_register_filters', 'bmab_register_filter');
 +function bmab_register_filter($filters)
 +{
 +  if (isset($_POST['filter_added_by_use']))
 +  {
 +    check_input_parameter('filter_added_by', $_POST, false, PATTERN_ID);
 +    
 +    $filters['added_by'] = $_POST['filter_added_by'];
 +  }
 +
 +  return $filters;
 +}</code>
 +
 +The second trigger_change batch_manager_perform_filters let you define the list of photos that match the filter, and add the set of photos to $filter_sets.
 +
 +<code php>add_event_handler('batch_manager_perform_filters', 'bmab_perform_filter');
 +function bmab_perform_filter($filter_sets)
 +{
 +  if (isset($_SESSION['bulk_manager_filter']['added_by']))
 +  {
 +    $query = '
 +SELECT
 +    id
 +  FROM '.IMAGES_TABLE.'
 +  WHERE added_by = '.$_SESSION['bulk_manager_filter']['added_by'].'
 +;';
 +    $filter_sets[] = array_from_query($query, 'id');
 +  }
 +
 +  return $filter_sets;
 +}</code>
 +
 +See a full example on http://piwigo.org/dev/browser/extensions/batch_manager_added_by/main.inc.php
 +
 +====Take A Tour plugin ====
 +
 +The plugin allow external sources like plugins to start their own tour. Check admin.tpl and the files tour.tpl and config.inc.php of the existing tours to get familiar with the system, but here some explanations:
 +  * the launch of a tour is made throught $_GET or $POST_ and require a pwg_token
 +  * $_REQUEST['submited_tour_path'] contains the path to the config.inc.php file, and is relative to  root_of_piwigo/plugins/TakeATour/ (e.g. $_GET['submited_tour_path']=../MyPlugin/tour/introduction )
 +  * config.inc.php contains AT LEAST the value of $TOUR_PATH which is the path to the tpl file and which is relativ eto the root of Piwigo (e.g. $TOUR_PATH = PHPWG_PLUGINS_PATH.'MyPlugin/tours/introduction/mytour.tpl';). config.inc.php is loaded before the parsing of the tpl of the tour and in the init event: so it will contains direct code to assign vars to your tpl, and can also contains additionnal add_event_handler. These add_event_handler are currently used as prefilter to add css id as anchors for steps. 
 +  * and so the tpl file should be made using the existing tours as examples: the script used is http://bootstraptour.com/ where you can found a doc
 +
 +Take A Tour loads the js and css needed, you just have to provide a config.inc.php and a tpl file and to load the language (it's recommended using the new option force_fallback like load_language('plugin.lang', PHPWG_PLUGINS_PATH .'MyPlugin/', array('force_fallback'=>'en_UK')); because empty text means that the step will be skiped)
 +
 +The plugin allows also the customization of the content of existing tours:
 +  * $conf['enable_synchronization'] is taken into account, no need to worry about that
 +  * but anything else can be changed by simply adding custom language files (see LocalFiles Editor)
 +  * steps in a tour can be skipped by simply emptying the content and title of that step, in the lang file
 +  * tours can be hidden in the admin of Take A Tour with the array $conf['TakeATour_tour_ignored']
 +
 +
 +
 +===== About Themes / tpl and CSS =====
 +
 +==== $themeconf['colorscheme'] ====
 +
 +With Selectize on search.tpl, we need to know if the theme is rather clear or dark, to load the appropriate CSS file (clear background or dark background). In your themeconf.inc.php, add the "colorscheme". It can be "dark" or "clear" only. This parameter will be used for other things like colorbox background or guestbook colors... (very useful for plugins)
 +
 +<code php>$themeconf = array(
 +  'name'  => 'clear',
 +  'parent' => 'default',
 +  'colorscheme' => 'clear',
 +);</code>
 +
 +==== picture.tpl - disable website field ====
 +We added an option to disable or enable the website field on comment add form. You must wrap the field in a IF block:
 +<code>{if $comment_add.SHOW_WEBSITE} ... {/if}</code>
 +
 +{$THUMB_SRC} template variable is not assigned anymore. Use instead {$current.derivatives.thumb->get_url()}
 +==== search.tpl - major changes ====
 +
 +The template search.tpl has deeply modified, so if you have a custom one in your theme, you'd better restart your customization from the new themes/default/template/search.tpl
 
Back to top
dev/changes_in_2.7.1392735945.txt.gz · Last modified: 2014/02/18 16:05 (external edit)
 
 
github twitter facebook google+ newsletter Donate Piwigo.org © 2002-2019 · Contact