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

Last change on this file since 17924 was 17924, checked in by mistic100, 12 years ago
  • ENGINE=MyISAM for table creation
  • add simple prefilter example
  • don't hardcode plugin folder
  • define VERSION auto, implemented soon in PEM
File size: 4.8 KB
RevLine 
[17899]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// +-----------------------------------------------------------------------+
[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')) . '/');
29define('SKELETON_DIR',     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
80
81// file containing specific plugin functions
82include_once(SKELETON_PATH . 'include/functions.inc.php');
83
84
85
86
87/**
88 * plugin initialization
89 *   - check for upgrades
90 *   - unserialize configuration
91 *   - load language
92 */
93function skeleton_init()
94{
95  global $conf, $pwg_loaded_plugins;
96 
97  // apply upgrade if needed
98  if (
[17924]99    $pwg_loaded_plugins[SKELETON_ID]['version'] == 'auto' or
100    version_compare($pwg_loaded_plugins[SKELETON_ID]['version'], SKELETON_VERSION, '<')
[17899]101  )
102  {
103    // call install function
104    include_once(SKELETON_PATH . 'include/install.inc.php');
105    skeleton_install();
106   
107    // update plugin version in database
[17924]108    if ($pwg_loaded_plugins[SKELETON_ID]['version'] != 'auto')
[17899]109    {
110      $query = '
111UPDATE '. PLUGINS_TABLE .'
112SET version = "'. SKELETON_VERSION .'"
[17924]113WHERE id = "'. SKELETON_ID .'"';
[17899]114      pwg_query($query);
115     
[17924]116      $pwg_loaded_plugins[SKELETON_ID]['version'] = SKELETON_VERSION;
[17899]117     
118      if (defined('IN_ADMIN'))
119      {
120        $_SESSION['page_infos'][] = 'Skeleton updated to version '. SKELETON_VERSION;
121      }
122    }
123  }
124 
125  // load plugin language file
126  load_language('plugin.lang', SKELETON_PATH);
127 
128  // prepare plugin configuration
129  $conf['skeleton'] = unserialize($conf['skeleton']);
130}
131
132?>
Note: See TracBrowser for help on using the repository browser.