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

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

first commit

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