[19700] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: User Info Tracking |
---|
| 4 | Version: 1.0.0 |
---|
| 5 | Description: Tracks when a person logs in, either failed or successful. |
---|
| 6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=659 |
---|
| 7 | Author: Charles2012 |
---|
| 8 | Author 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 | |
---|
| 17 | defined('PHPWG_ROOT_PATH') or die('Hacking attempt!'); |
---|
| 18 | |
---|
| 19 | global $prefixeTable; |
---|
| 20 | |
---|
| 21 | // +-----------------------------------------------------------------------+ |
---|
| 22 | // | Define plugin constants | |
---|
| 23 | // +-----------------------------------------------------------------------+ |
---|
| 24 | defined('USER_INFO_TRACKING_ID') or define('USER_INFO_TRACKING_ID', basename(dirname(__FILE__))); |
---|
| 25 | define('USER_INFO_TRACKING_PATH' , PHPWG_PLUGINS_PATH . USER_INFO_TRACKING_ID . '/'); |
---|
| 26 | define('USER_INFO_TRACKING_TABLE', $prefixeTable . 'user_info_tracking'); |
---|
| 27 | |
---|
| 28 | define('USER_INFO_TRACKING_TABLE2', $prefixeTable . 'user_info_tracking'); |
---|
| 29 | define('USER_INFO_TRACKING_TABLE3', $prefixeTable . 'users'); |
---|
| 30 | |
---|
| 31 | define('USER_INFO_TRACKING_ADMIN', get_root_url() . 'admin.php?page=plugin-' . USER_INFO_TRACKING_ID); |
---|
| 32 | define('USER_INFO_TRACKING_PUBLIC', get_absolute_root_url() . make_index_url(array('section' => 'user_info_tracking')) . '/'); |
---|
| 33 | define('USER_INFO_TRACKING_DIR', PWG_LOCAL_DIR . 'user_info_tracking/'); |
---|
| 34 | define('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 |
---|
| 42 | add_event_handler('init', 'user_info_tracking_init'); |
---|
| 43 | |
---|
| 44 | if (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 | } |
---|
| 55 | else |
---|
| 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 | // --------------------------- |
---|
| 65 | add_event_handler('login_success', 'ui_successfulLogin'); |
---|
| 66 | |
---|
| 67 | // Failed Login - Logs Data into the Table |
---|
| 68 | // --------------------------- |
---|
| 69 | add_event_handler('login_failure', 'ui_failedLogin'); |
---|
| 70 | |
---|
| 71 | // Logout - Logs Data into the Table |
---|
| 72 | // --------------------------- |
---|
| 73 | add_event_handler('logout', 'ui_logout'); |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | // add API function |
---|
| 77 | add_event_handler('ws_add_methods', 'skeleton_ws_add_methods'); |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | // files containing specific plugin functions |
---|
| 81 | include_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 | */ |
---|
| 90 | function 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 = ' |
---|
| 109 | UPDATE '. PLUGINS_TABLE .' |
---|
| 110 | SET version = "'. USER_INFO_TRACKING_VERSION .'" |
---|
| 111 | WHERE 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 | ?> |
---|