1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: skeleton |
---|
4 | Version: auto |
---|
5 | Description: This is not a plugin. It's a skeleton for future plugins. |
---|
6 | Plugin URI: auto |
---|
7 | Author: Mistic |
---|
8 | Author 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 | |
---|
17 | defined('PHPWG_ROOT_PATH') or die('Hacking attempt!'); |
---|
18 | |
---|
19 | global $prefixeTable; |
---|
20 | |
---|
21 | // +-----------------------------------------------------------------------+ |
---|
22 | // | Define plugin constants | |
---|
23 | // +-----------------------------------------------------------------------+ |
---|
24 | defined('SKELETON_ID') or define('SKELETON_ID', basename(dirname(__FILE__))); |
---|
25 | define('SKELETON_PATH' , PHPWG_PLUGINS_PATH . SKELETON_ID . '/'); |
---|
26 | define('SKELETON_TABLE', $prefixeTable . 'skeleton'); |
---|
27 | define('SKELETON_ADMIN', get_root_url() . 'admin.php?page=plugin-' . SKELETON_ID); |
---|
28 | define('SKELETON_PUBLIC', get_absolute_root_url() . make_index_url(array('section' => 'skeleton')) . '/'); |
---|
29 | define('SKELETON_DIR', PWG_LOCAL_DIR . 'skeleton/'); |
---|
30 | define('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 |
---|
38 | add_event_handler('init', 'skeleton_init'); |
---|
39 | |
---|
40 | if (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 | } |
---|
59 | else |
---|
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 |
---|
81 | add_event_handler('ws_add_methods', 'skeleton_ws_add_methods'); |
---|
82 | |
---|
83 | |
---|
84 | // files containing specific plugin functions |
---|
85 | include_once(SKELETON_PATH . 'include/functions.inc.php'); |
---|
86 | include_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 | */ |
---|
97 | function skeleton_init() |
---|
98 | { |
---|
99 | global $conf, $pwg_loaded_plugins; |
---|
100 | |
---|
101 | // apply upgrade if needed |
---|
102 | if ( |
---|
103 | $pwg_loaded_plugins[SKELETON_ID]['version'] == 'auto' or |
---|
104 | version_compare($pwg_loaded_plugins[SKELETON_ID]['version'], SKELETON_VERSION, '<') |
---|
105 | ) |
---|
106 | { |
---|
107 | // call install function |
---|
108 | include_once(SKELETON_PATH . 'include/install.inc.php'); |
---|
109 | skeleton_install(); |
---|
110 | |
---|
111 | // update plugin version in database |
---|
112 | if ($pwg_loaded_plugins[SKELETON_ID]['version'] != 'auto') |
---|
113 | { |
---|
114 | $query = ' |
---|
115 | UPDATE '. PLUGINS_TABLE .' |
---|
116 | SET version = "'. SKELETON_VERSION .'" |
---|
117 | WHERE id = "'. SKELETON_ID .'"'; |
---|
118 | pwg_query($query); |
---|
119 | |
---|
120 | $pwg_loaded_plugins[SKELETON_ID]['version'] = SKELETON_VERSION; |
---|
121 | |
---|
122 | if (defined('IN_ADMIN')) |
---|
123 | { |
---|
124 | $_SESSION['page_infos'][] = 'Skeleton updated to version '. SKELETON_VERSION; |
---|
125 | } |
---|
126 | } |
---|
127 | } |
---|
128 | |
---|
129 | // load plugin language file |
---|
130 | load_language('plugin.lang', SKELETON_PATH); |
---|
131 | |
---|
132 | // prepare plugin configuration |
---|
133 | $conf['skeleton'] = unserialize($conf['skeleton']); |
---|
134 | } |
---|
135 | |
---|
136 | ?> |
---|