[19773] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: Birthdate |
---|
| 4 | Version: auto |
---|
| 5 | Description: Set a birthdate on a tag and Piwigo will display the age on any photo. |
---|
| 6 | Plugin URI: auto |
---|
| 7 | Author: plg |
---|
| 8 | Author URI: http://le-gall.net/pierrick |
---|
| 9 | */ |
---|
| 10 | |
---|
| 11 | defined('PHPWG_ROOT_PATH') or die('Hacking attempt!'); |
---|
| 12 | |
---|
| 13 | global $prefixeTable; |
---|
| 14 | |
---|
| 15 | // +-----------------------------------------------------------------------+ |
---|
| 16 | // | Define plugin constants | |
---|
| 17 | // +-----------------------------------------------------------------------+ |
---|
| 18 | |
---|
| 19 | defined('BIRTHDATE_ID') or define('BIRTHDATE_ID', basename(dirname(__FILE__))); |
---|
| 20 | define('BIRTHDATE_PATH' , PHPWG_PLUGINS_PATH . BIRTHDATE_ID . '/'); |
---|
| 21 | define('BIRTHDATE_TABLE', $prefixeTable . 'birthdate'); |
---|
| 22 | define('BIRTHDATE_ADMIN', get_root_url() . 'admin.php?page=plugin-' . BIRTHDATE_ID); |
---|
| 23 | define('BIRTHDATE_PUBLIC', get_absolute_root_url() . make_index_url(array('section' => 'birthdate')) . '/'); |
---|
| 24 | define('BIRTHDATE_DIR', PWG_LOCAL_DIR . 'birthdate/'); |
---|
| 25 | define('BIRTHDATE_VERSION', 'auto'); |
---|
| 26 | |
---|
| 27 | |
---|
| 28 | // +-----------------------------------------------------------------------+ |
---|
| 29 | // | Add event handlers | |
---|
| 30 | // +-----------------------------------------------------------------------+ |
---|
| 31 | // init the plugin |
---|
| 32 | add_event_handler('init', 'birthdate_init'); |
---|
| 33 | |
---|
| 34 | if (defined('IN_ADMIN')) |
---|
| 35 | { |
---|
| 36 | // admin plugins menu link |
---|
| 37 | add_event_handler('get_admin_plugin_menu_links', 'birthdate_admin_plugin_menu_links'); |
---|
| 38 | |
---|
| 39 | // file containing all previous handlers functions |
---|
| 40 | include_once(BIRTHDATE_PATH . 'include/admin_events.inc.php'); |
---|
| 41 | } |
---|
| 42 | else |
---|
| 43 | { |
---|
| 44 | // add age on tags |
---|
| 45 | add_event_handler('loc_end_picture', 'birthdate_loc_end_picture'); |
---|
| 46 | |
---|
| 47 | // file containing all previous handlers functions |
---|
| 48 | include_once(BIRTHDATE_PATH . 'include/public_events.inc.php'); |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | // files containing specific plugin functions |
---|
| 52 | include_once(BIRTHDATE_PATH . 'include/functions.inc.php'); |
---|
| 53 | |
---|
| 54 | /** |
---|
| 55 | * plugin initialization |
---|
| 56 | * - check for upgrades |
---|
| 57 | * - unserialize configuration |
---|
| 58 | * - load language |
---|
| 59 | */ |
---|
| 60 | function birthdate_init() |
---|
| 61 | { |
---|
| 62 | global $conf, $pwg_loaded_plugins; |
---|
| 63 | |
---|
| 64 | // apply upgrade if needed |
---|
| 65 | if ( |
---|
| 66 | BIRTHDATE_VERSION == 'auto' or |
---|
| 67 | $pwg_loaded_plugins[BIRTHDATE_ID]['version'] == 'auto' or |
---|
| 68 | version_compare($pwg_loaded_plugins[BIRTHDATE_ID]['version'], BIRTHDATE_VERSION, '<') |
---|
| 69 | ) |
---|
| 70 | { |
---|
| 71 | // call install function |
---|
| 72 | include_once(BIRTHDATE_PATH . 'include/install.inc.php'); |
---|
| 73 | birthdate_install(); |
---|
| 74 | |
---|
| 75 | // update plugin version in database |
---|
| 76 | if ( $pwg_loaded_plugins[BIRTHDATE_ID]['version'] != 'auto' and BIRTHDATE_VERSION != 'auto' ) |
---|
| 77 | { |
---|
| 78 | $query = ' |
---|
| 79 | UPDATE '. PLUGINS_TABLE .' |
---|
| 80 | SET version = "'. BIRTHDATE_VERSION .'" |
---|
| 81 | WHERE id = "'. BIRTHDATE_ID .'"'; |
---|
| 82 | pwg_query($query); |
---|
| 83 | |
---|
| 84 | $pwg_loaded_plugins[BIRTHDATE_ID]['version'] = BIRTHDATE_VERSION; |
---|
| 85 | |
---|
| 86 | if (defined('IN_ADMIN')) |
---|
| 87 | { |
---|
| 88 | $_SESSION['page_infos'][] = 'Birthdate updated to version '. BIRTHDATE_VERSION; |
---|
| 89 | } |
---|
| 90 | } |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | // load plugin language file |
---|
| 94 | load_language('plugin.lang', BIRTHDATE_PATH); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | ?> |
---|