Differences

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

Link to this comparison view

dev:extensions:plugin_tutorial2 [2011/07/11 07:16]
j.commelin
— (current)
Line 1: Line 1:
-====== Tutorial: Several tricks from the Copyrights plugin ====== 
-In this tutorial you will learn more about the basics of plugin development for Piwigo. This tutorial is a follow up on [[tutorial1|Tutorial: Hello World!]]. The entire plugin can be  
-installed from the extension gallery under the name [[http://piwigo.org/ext/extension_view.php?eid=537|'Copyrights']]. 
-Note that this tutorial follows the v1.0 revision of this plugin. 
  
-Since the plugin is relatively large to put all the code on this page, we only explicitly put that code here that is important and clarifies the ideas explained. The reader should read the rest of the code from the sources pointed to above. 
- 
-===== Introduction ===== 
-First of all, download the source code of the [[http://piwigo.org/ext/extension_view.php?eid=543|Skeleton plugin]]. We will use that as basis for this plugin. 
- 
-==== Outline ==== 
-With this plugin we want to achieve the following: 
-  - Somewhere we want to manage our copyrights. 
-  - Somehow copyrights must be added to photos. 
-  - Somehow the copyright must be displayed when visitors view a photo. 
-Therefore, we will write code for: 
-  - An administration panel, where the admin can create and edit plugins 
-  - An extension to the Batch manager (using events) so that copyrights can be added to photos. 
-  - Another event-hook that will display the copyright when a photo is viewed. 
- 
-===== The admin panel ===== 
- 
-For the admin panel we need to do two things. First add a link to the plugins menu, second create an admin page. 
- 
-==== The link in the menu ==== 
- 
-To add a link to the menu of plugins we put the following code in main.inc.php. This is our first serious encounter with event handlers. To see what events are available we refer to the [[http://piwigo.org/ext/extension_view.php?eid=288|Event tracer plugin]]. 
-<code> 
-/* +-----------------------------------------------------------------------+ 
- * | Plugin admin                                                          | 
- * +-----------------------------------------------------------------------+ */ 
- 
-// Add an entry to the plugins menu 
-add_event_handler('get_admin_plugin_menu_links', 'copyrights_admin_menu'); 
-function copyrights_admin_menu($menu) { 
-  array_push( 
-    $menu, 
-    array( 
-      'NAME'  => 'Copyrights', 
-      'URL'   => get_admin_plugin_menu_link(dirname(__FILE__)).'/admin.php' 
-    ) 
-  ); 
-  return $menu; 
-} 
-</code> 
-This adds an event handler to the event 'get_admin_plugin_menu_links'. The added handler is the function 'copyrights_admin_menu' that we define right below it. It consists of a simple array_push() to add our link to the plugins menu. 
- 
-Lets move on to the content of admin.php, since that is what we are linking to. 
- 
-==== The admin page ==== 
-We would like to do several things on the admin page. First of all, we want to be able to create plugins. Next we should be able to view them, and lastly, we want to be able to edit existing copyrights. 
- 
-Firstly, however, we load the language file and perform a security check. 
-<code> 
-load_language('plugin.lang', COPYRIGHTS_PATH); 
- 
-// Check access and exit when user status is not ok 
-check_status(ACCESS_ADMINISTRATOR); 
-</code> 
- 
-The rest of the code of the admin page does not add much to the learning of plugin writing for Piwigo. It is best read from source directly. The code is commented farely well. 
- 
-It is, however, good to mention the special use of the '$tab' variable. This is a variable that is used by Piwigo to create the tabbed layout they use. The Copyrights plugin makes use of this variable for deleting and updating Copyrights as if those are 'unvisible' tabs. 
- 
-===== Extending the Batch manager ===== 
-The Batch manager comes with two modes, so we will have to write extensions to both. 
- 
-==== Batch Mode ==== 
- 
-==== Single Mode ==== 
- 
-===== Modifying copyrights via picture_modify.php ===== 
-This part of the plugin works in the same way as the single mode of the Batch Manager. 
-  - It attaches an event handler, to set a prefilter. 
-  - The prefilter adds some Smarty code to the template. 
-  - Another event handler assigns the variables in the Smarty code. 
-  - Yet another event handler catches the 'Submit' button and updates the database. 
-The reader should try to understand how this is done by looking at the source code of the plugin. 
- 
-===== Showing the copyrights to visitors ===== 
-To show the copyrights to people visiting the gallery, we again make use of a prefilter. Just like the ways mentioned above. It should by now be pretty straight forward to learn this from the source code. 
- 
-===== Using maintain.inc.php ===== 
-In the file maintain.inc.php one can put code that should be executed at install, activation or deletion of a plugin. The reader can see from the source code of the plugin that the Copyrights plugin inserts several default copyrights into the database by using this file. 
 
Back to top
dev/extensions/plugin_tutorial2.1310368560.txt.gz · Last modified: 2011/07/11 07:16 by j.commelin
 
 
github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact