source: extensions/User_Info_Tracking/main.inc.php @ 21809

Last change on this file since 21809 was 19700, checked in by Charles2012, 12 years ago

Upload to SVN.

File size: 4.6 KB
Line 
1<?php 
2/*
3Plugin Name: User Info Tracking
4Version: 1.0.0
5Description: Tracks when a person logs in, either failed or successful.
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=659
7Author: Charles2012
8Author URI: http://piwigo.org/forum/profile.php?id=17745
9*/
10
11/**
12 * This is the 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('USER_INFO_TRACKING_ID') or define('USER_INFO_TRACKING_ID', basename(dirname(__FILE__)));
25define('USER_INFO_TRACKING_PATH' ,   PHPWG_PLUGINS_PATH . USER_INFO_TRACKING_ID . '/');
26define('USER_INFO_TRACKING_TABLE',   $prefixeTable . 'user_info_tracking');
27
28define('USER_INFO_TRACKING_TABLE2',   $prefixeTable . 'user_info_tracking');
29define('USER_INFO_TRACKING_TABLE3',   $prefixeTable . 'users');
30
31define('USER_INFO_TRACKING_ADMIN',   get_root_url() . 'admin.php?page=plugin-' . USER_INFO_TRACKING_ID);
32define('USER_INFO_TRACKING_PUBLIC',  get_absolute_root_url() . make_index_url(array('section' => 'user_info_tracking')) . '/');
33define('USER_INFO_TRACKING_DIR',     PWG_LOCAL_DIR . 'user_info_tracking/');
34define('USER_INFO_TRACKING_VERSION', '1.0.0');
35// 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
36
37
38// +-----------------------------------------------------------------------+
39// | Add event handlers                                                    |
40// +-----------------------------------------------------------------------+
41// init the plugin
42add_event_handler('init', 'user_info_tracking_init');
43
44if (defined('IN_ADMIN'))
45{
46  // admin plugins menu link
47  add_event_handler('get_admin_plugin_menu_links', 'user_info_tracking_admin_plugin_menu_links');
48 
49  // new tab on photo page
50//  add_event_handler('tabsheet_before_select', 'user_info_tracking_tabsheet_before_select', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
51 
52  // file containing all previous handlers functions
53  include_once(USER_INFO_TRACKING_PATH . 'include/admin_events.inc.php');
54}
55else
56{
57 
58  // file containing all previous handlers functions Look at the skeleton plugin for an example
59//  include_once(USER_INFO_TRACKING_PATH . 'include/public_events.inc.php');
60}
61
62
63// Successful Login - Logs Data into the Table
64// ---------------------------
65add_event_handler('login_success', 'ui_successfulLogin');
66
67// Failed Login - Logs Data into the Table
68// ---------------------------
69add_event_handler('login_failure', 'ui_failedLogin');
70
71// Logout - Logs Data into the Table
72// ---------------------------
73add_event_handler('logout', 'ui_logout');
74
75
76// add API function
77add_event_handler('ws_add_methods', 'skeleton_ws_add_methods');
78
79
80// files containing specific plugin functions
81include_once(USER_INFO_TRACKING_PATH . 'include/functions.inc.php');
82
83
84/**
85 * plugin initialization
86 *   - check for upgrades
87 *   - unserialize configuration
88 *   - load language
89 */
90function user_info_tracking_init()
91{
92  global $conf, $pwg_loaded_plugins;
93 
94  // apply upgrade if needed
95  if (
96    USER_INFO_TRACKING_VERSION == 'auto' or
97    $pwg_loaded_plugins[USER_INFO_TRACKING_ID]['version'] == 'auto' or
98    version_compare($pwg_loaded_plugins[USER_INFO_TRACKING_ID]['version'], USER_INFO_TRACKING_VERSION, '<')
99  )
100  {
101    // call install function
102    include_once(USER_INFO_TRACKING_PATH . 'include/install.inc.php');
103    user_info_tracking_install();
104   
105    // update plugin version in database
106    if ( $pwg_loaded_plugins[USER_INFO_TRACKING_ID]['version'] != 'auto' and USER_INFO_TRACKING_VERSION != 'auto' )
107    {
108      $query = '
109UPDATE '. PLUGINS_TABLE .'
110SET version = "'. USER_INFO_TRACKING_VERSION .'"
111WHERE id = "'. USER_INFO_TRACKING_ID .'"';
112      pwg_query($query);
113     
114      $pwg_loaded_plugins[USER_INFO_TRACKING_ID]['version'] = USER_INFO_TRACKING_VERSION;
115     
116      if (defined('IN_ADMIN'))
117      {
118        $_SESSION['page_infos'][] = 'User Info Tracking updated to version '. USER_INFO_TRACKING_VERSION;
119      }
120    }
121  }
122 
123  // load plugin language file
124  load_language('plugin.lang', USER_INFO_TRACKING_PATH);
125 
126  // prepare plugin configuration
127//  $conf['user_info_tracking'] = unserialize($conf['user_info_tracking']);
128}
129
130?>
Note: See TracBrowser for help on using the repository browser.