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

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

fix breadcrumb in 2.5 & add button with new template features

File size: 5.1 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// | Define plugin constants                                               |
23// +-----------------------------------------------------------------------+
24defined('SKELETON_ID') or define('SKELETON_ID', basename(dirname(__FILE__)));
25define('SKELETON_PATH' ,   PHPWG_PLUGINS_PATH . SKELETON_ID . '/');
26define('SKELETON_TABLE',   $prefixeTable . 'skeleton');
27define('SKELETON_ADMIN',   get_root_url() . 'admin.php?page=plugin-' . SKELETON_ID);
28define('SKELETON_PUBLIC',  get_absolute_root_url() . make_index_url(array('section' => 'skeleton')) . '/');
29define('SKELETON_DIR',     PHPWG_ROOT_PATH . PWG_LOCAL_DIR . 'skeleton/');
30define('SKELETON_VERSION', 'auto');
31// 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
32
33
34// +-----------------------------------------------------------------------+
35// | Add event handlers                                                    |
36// +-----------------------------------------------------------------------+
37// init the plugin
38add_event_handler('init', 'skeleton_init');
39
40if (defined('IN_ADMIN'))
41{
42  // admin plugins menu link
43  add_event_handler('get_admin_plugin_menu_links', 'skeleton_admin_plugin_menu_links');
44 
45  // new tab on photo page
46  add_event_handler('tabsheet_before_select', 'skeleton_tabsheet_before_select', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
47 
48  // new prefiler in Batch Manager
49  add_event_handler('get_batch_manager_prefilters', 'skeleton_add_batch_manager_prefilters');
50  add_event_handler('perform_batch_manager_prefilters', 'skeleton_perform_batch_manager_prefilters', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
51 
52  // new action in Batch Manager
53  add_event_handler('loc_end_element_set_global', 'skeleton_loc_end_element_set_global');
54  add_event_handler('element_set_global_action', 'skeleton_element_set_global_action', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
55 
56  // file containing all previous handlers functions
57  include_once(SKELETON_PATH . 'include/admin_events.inc.php');
58}
59else
60{
61  // add a public section
62  add_event_handler('loc_end_section_init', 'skeleton_loc_end_section_init');
63  add_event_handler('loc_end_index', 'skeleton_loc_end_page');
64 
65  // add item to existing menu (EVENT_HANDLER_PRIORITY_NEUTRAL+10 is for compatibility with Advanced Menu Manager)
66  add_event_handler('blockmanager_apply', 'skeleton_blockmanager_apply1', EVENT_HANDLER_PRIORITY_NEUTRAL+10);
67 
68  // add a new menu block
69  add_event_handler('blockmanager_register_blocks', 'skeleton_blockmanager_register_blocks');
70  add_event_handler('blockmanager_apply', 'skeleton_blockmanager_apply2');
71  // NOTE: skeleton_blockmanager_apply1() and skeleton_blockmanager_apply2() can (should) be merged
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  // file containing all previous handlers functions
81  include_once(SKELETON_PATH . 'include/public_events.inc.php');
82}
83
84// add API function
85add_event_handler('ws_add_methods', 'skeleton_ws_add_methods');
86
87
88// files containing specific plugin functions
89include_once(SKELETON_PATH . 'include/functions.inc.php');
90include_once(SKELETON_PATH . 'include/ws_functions.inc.php');
91
92
93
94
95/**
96 * plugin initialization
97 *   - check for upgrades
98 *   - unserialize configuration
99 *   - load language
100 */
101function skeleton_init()
102{
103  global $conf, $pwg_loaded_plugins;
104 
105  // apply upgrade if needed
106  if (
107    SKELETON_VERSION == 'auto' or
108    $pwg_loaded_plugins[SKELETON_ID]['version'] == 'auto' or
109    version_compare($pwg_loaded_plugins[SKELETON_ID]['version'], SKELETON_VERSION, '<')
110  )
111  {
112    // call install function
113    include_once(SKELETON_PATH . 'include/install.inc.php');
114    skeleton_install();
115   
116    // update plugin version in database
117    if ( $pwg_loaded_plugins[SKELETON_ID]['version'] != 'auto' and SKELETON_VERSION != 'auto' )
118    {
119      $query = '
120UPDATE '. PLUGINS_TABLE .'
121SET version = "'. SKELETON_VERSION .'"
122WHERE id = "'. SKELETON_ID .'"';
123      pwg_query($query);
124     
125      $pwg_loaded_plugins[SKELETON_ID]['version'] = SKELETON_VERSION;
126     
127      if (defined('IN_ADMIN'))
128      {
129        $_SESSION['page_infos'][] = 'Skeleton updated to version '. SKELETON_VERSION;
130      }
131    }
132  }
133 
134  // load plugin language file
135  load_language('plugin.lang', SKELETON_PATH);
136 
137  // prepare plugin configuration
138  $conf['skeleton'] = unserialize($conf['skeleton']);
139}
140
141?>
Note: See TracBrowser for help on using the repository browser.