source: extensions/skeleton/main.inc.php @ 20461

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

some little fixes

File size: 5.0 KB
RevLine 
[17899]1<?php 
2/*
3Plugin Name: skeleton
4Version: auto
5Description: This is not a plugin. It's a skeleton for future plugins.
[18408]6Plugin URI: auto
[17899]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// +-----------------------------------------------------------------------+
[17924]24defined('SKELETON_ID') or define('SKELETON_ID', basename(dirname(__FILE__)));
25define('SKELETON_PATH' ,   PHPWG_PLUGINS_PATH . SKELETON_ID . '/');
[17899]26define('SKELETON_TABLE',   $prefixeTable . 'skeleton');
[17924]27define('SKELETON_ADMIN',   get_root_url() . 'admin.php?page=plugin-' . SKELETON_ID);
[17899]28define('SKELETON_PUBLIC',  get_absolute_root_url() . make_index_url(array('section' => 'skeleton')) . '/');
[19842]29define('SKELETON_DIR',     PHPWG_ROOT_PATH . PWG_LOCAL_DIR . 'skeleton/');
[17924]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
[17899]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
[17924]46  add_event_handler('tabsheet_before_select', 'skeleton_tabsheet_before_select', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
[17899]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 
[17924]73  // prefilter on photo page
74  add_event_handler('loc_end_picture', 'skeleton_loc_end_picture');
75 
[17899]76  // file containing all previous handlers functions
77  include_once(SKELETON_PATH . 'include/public_events.inc.php');
78}
79
[17933]80// add API function
81add_event_handler('ws_add_methods', 'skeleton_ws_add_methods');
[17899]82
[17933]83
84// files containing specific plugin functions
[17899]85include_once(SKELETON_PATH . 'include/functions.inc.php');
[17933]86include_once(SKELETON_PATH . 'include/ws_functions.inc.php');
[17899]87
88
89
90
91/**
92 * plugin initialization
93 *   - check for upgrades
94 *   - unserialize configuration
95 *   - load language
96 */
97function skeleton_init()
98{
99  global $conf, $pwg_loaded_plugins;
100 
101  // apply upgrade if needed
102  if (
[18650]103    SKELETON_VERSION == 'auto' or
[17924]104    $pwg_loaded_plugins[SKELETON_ID]['version'] == 'auto' or
105    version_compare($pwg_loaded_plugins[SKELETON_ID]['version'], SKELETON_VERSION, '<')
[17899]106  )
107  {
108    // call install function
109    include_once(SKELETON_PATH . 'include/install.inc.php');
110    skeleton_install();
111   
112    // update plugin version in database
[18650]113    if ( $pwg_loaded_plugins[SKELETON_ID]['version'] != 'auto' and SKELETON_VERSION != 'auto' )
[17899]114    {
115      $query = '
116UPDATE '. PLUGINS_TABLE .'
117SET version = "'. SKELETON_VERSION .'"
[17924]118WHERE id = "'. SKELETON_ID .'"';
[17899]119      pwg_query($query);
120     
[17924]121      $pwg_loaded_plugins[SKELETON_ID]['version'] = SKELETON_VERSION;
[17899]122     
123      if (defined('IN_ADMIN'))
124      {
125        $_SESSION['page_infos'][] = 'Skeleton updated to version '. SKELETON_VERSION;
126      }
127    }
128  }
129 
130  // load plugin language file
131  load_language('plugin.lang', SKELETON_PATH);
132 
133  // prepare plugin configuration
134  $conf['skeleton'] = unserialize($conf['skeleton']);
135}
136
137?>
Note: See TracBrowser for help on using the repository browser.