source: extensions/skeleton/trunk/main.inc.php @ 24349

Last change on this file since 24349 was 24182, checked in by mistic100, 11 years ago

remove php end tags, remove at symbol in template, add example of class handlers, remove useless files

File size: 4.9 KB
Line 
1<?php 
2/*
3Plugin Name: skeleton
4Version: auto
5Description: This is not a plugin. It's a skeleton for future plugins.
6Plugin URI: auto
7Author: Mistic
8Author URI: http://www.strangeplanet.fr
9*/
10
11/**
12 * This is te main file of the plugin, called by Piwigo in "include/common.inc.php" line 137.
13 * At this point of the code, Piwigo is not completely initialized, so nothing should be done directly
14 * except define constants and event handlers (see http://piwigo.org/doc/doku.php?id=dev:plugins)
15 */
16
17defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
18
19global $prefixeTable;
20
21
22// +-----------------------------------------------------------------------+
23// | Define plugin constants                                               |
24// +-----------------------------------------------------------------------+
25defined('SKELETON_ID') or define('SKELETON_ID', basename(dirname(__FILE__)));
26define('SKELETON_PATH' ,   PHPWG_PLUGINS_PATH . SKELETON_ID . '/');
27define('SKELETON_TABLE',   $prefixeTable . 'skeleton');
28define('SKELETON_ADMIN',   get_root_url() . 'admin.php?page=plugin-' . SKELETON_ID);
29define('SKELETON_PUBLIC',  get_absolute_root_url() . make_index_url(array('section' => 'skeleton')) . '/');
30define('SKELETON_DIR',     PHPWG_ROOT_PATH . PWG_LOCAL_DIR . 'skeleton/');
31define('SKELETON_VERSION', 'auto');
32// this is automatically updated by PEM if you publish your plugin with SVN, otherwise you musn't forget to change it, as well as "Version" in the plugin header
33
34
35
36// +-----------------------------------------------------------------------+
37// | Add event handlers                                                    |
38// +-----------------------------------------------------------------------+
39// init the plugin
40add_event_handler('init', 'skeleton_init');
41
42/*
43 * this is the common way to define event functions: create a new function for each event you want to handle
44 */
45if (defined('IN_ADMIN'))
46{
47  // file containing all admin handlers functions
48  include_once(SKELETON_PATH . 'include/admin_events.inc.php');
49 
50  // admin plugins menu link
51  add_event_handler('get_admin_plugin_menu_links', 'skeleton_admin_plugin_menu_links');
52 
53  // new tab on photo page
54  add_event_handler('tabsheet_before_select', 'skeleton_tabsheet_before_select', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
55 
56  // new prefiler in Batch Manager
57  add_event_handler('get_batch_manager_prefilters', 'skeleton_add_batch_manager_prefilters');
58  add_event_handler('perform_batch_manager_prefilters', 'skeleton_perform_batch_manager_prefilters', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
59 
60  // new action in Batch Manager
61  add_event_handler('loc_end_element_set_global', 'skeleton_loc_end_element_set_global');
62  add_event_handler('element_set_global_action', 'skeleton_element_set_global_action', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
63}
64else
65{
66  // file containing all public handlers functions
67  include_once(SKELETON_PATH . 'include/public_events.inc.php');
68 
69  // add a public section
70  add_event_handler('loc_end_section_init', 'skeleton_loc_end_section_init');
71  add_event_handler('loc_end_index', 'skeleton_loc_end_page');
72 
73  // add button on album and photos pages
74  add_event_handler('loc_end_index', 'skeleton_add_button');
75  add_event_handler('loc_end_picture', 'skeleton_add_button');
76 
77  // prefilter on photo page
78  add_event_handler('loc_end_picture', 'skeleton_loc_end_picture');
79}
80
81// add API function
82add_event_handler('ws_add_methods', 'skeleton_ws_add_methods');
83
84
85/*
86 * event functions can also be wrapped in a class
87 */
88
89// file containing the class for menu handlers functions
90include_once(SKELETON_PATH . 'include/menu_events.class.php');
91
92// add item to existing menu (EVENT_HANDLER_PRIORITY_NEUTRAL+10 is for compatibility with Advanced Menu Manager plugin)
93add_event_handler('blockmanager_apply', array('SkeletonMenu', 'blockmanager_apply1'), EVENT_HANDLER_PRIORITY_NEUTRAL+10);
94
95// add a new menu block (the declaration must be done every time, in order to be able to manage the menu block in "Menus" screen and Advanced Menu Manager)
96add_event_handler('blockmanager_register_blocks', array('SkeletonMenu', 'blockmanager_register_blocks'));
97add_event_handler('blockmanager_apply', array('SkeletonMenu', 'blockmanager_apply2'));
98// NOTE: blockmanager_apply1() and blockmanager_apply2() can (must) be merged
99
100
101
102// files containing specific plugin functions
103include_once(SKELETON_PATH . 'include/functions.inc.php');
104include_once(SKELETON_PATH . 'include/ws_functions.inc.php');
105
106
107
108
109/**
110 * plugin initialization
111 *   - check for upgrades
112 *   - unserialize configuration
113 *   - load language
114 */
115function skeleton_init()
116{
117  global $conf, $pwg_loaded_plugins;
118 
119  // apply upgrade if needed
120  include_once(SKELETON_PATH . 'include/install.inc.php');
121  request_plugin_update(SKELETON_ID, SKELETON_VERSION, 'skeleton_install');
122 
123  // load plugin language file
124  load_language('plugin.lang', SKELETON_PATH);
125 
126  // prepare plugin configuration
127  $conf['skeleton'] = unserialize($conf['skeleton']);
128}
Note: See TracBrowser for help on using the repository browser.