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

Last change on this file since 20994 was 19842, checked in by mistic100, 12 years ago

some little fixes

File size: 5.0 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  // prefilter on photo page
74  add_event_handler('loc_end_picture', 'skeleton_loc_end_picture');
75 
76  // file containing all previous handlers functions
77  include_once(SKELETON_PATH . 'include/public_events.inc.php');
78}
79
80// add API function
81add_event_handler('ws_add_methods', 'skeleton_ws_add_methods');
82
83
84// files containing specific plugin functions
85include_once(SKELETON_PATH . 'include/functions.inc.php');
86include_once(SKELETON_PATH . 'include/ws_functions.inc.php');
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 (
103    SKELETON_VERSION == 'auto' or
104    $pwg_loaded_plugins[SKELETON_ID]['version'] == 'auto' or
105    version_compare($pwg_loaded_plugins[SKELETON_ID]['version'], SKELETON_VERSION, '<')
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
113    if ( $pwg_loaded_plugins[SKELETON_ID]['version'] != 'auto' and SKELETON_VERSION != 'auto' )
114    {
115      $query = '
116UPDATE '. PLUGINS_TABLE .'
117SET version = "'. SKELETON_VERSION .'"
118WHERE id = "'. SKELETON_ID .'"';
119      pwg_query($query);
120     
121      $pwg_loaded_plugins[SKELETON_ID]['version'] = SKELETON_VERSION;
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.