This is an old revision of the document!
In this tutorial you will learn more about the basics of plugin development for Piwigo. This tutorial is a follow up on Tutorial: Hello World!. The entire plugin can be installed from the extension gallery under the name 'Copyrights'. Note that this tutorial follows the v1.0 revision of this plugin.
First of all, download the source code of the Skeleton plugin. We will use that as basis for this plugin.
With this plugin we want to achieve the following:
Therefore, we will write code for:
For the admin panel we need to do two things. First add a link to the plugins menu, second create an admin page.
To add a link to the menu of plugins we put the following code in main.inc.php
// In main.inc.php /* +-----------------------------------------------------------------------+ * | 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; }
This add 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.
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.
load_language('plugin.lang', COPYRIGHTS_PATH); // Check access and exit when user status is not ok check_status(ACCESS_ADMINISTRATOR);
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.
The Batch manager comes with two modes, so we will have to write extensions to both.