source: extensions/birthdate/main.inc.php @ 27153

Last change on this file since 27153 was 19773, checked in by plg, 11 years ago

new plugin birthdate to calculate age of people on each photo

File size: 3.0 KB
Line 
1<?php 
2/*
3Plugin Name: Birthdate
4Version: auto
5Description: Set a birthdate on a tag and Piwigo will display the age on any photo.
6Plugin URI: auto
7Author: plg
8Author URI: http://le-gall.net/pierrick
9*/
10
11defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
12
13global $prefixeTable;
14
15// +-----------------------------------------------------------------------+
16// | Define plugin constants                                               |
17// +-----------------------------------------------------------------------+
18
19defined('BIRTHDATE_ID') or define('BIRTHDATE_ID', basename(dirname(__FILE__)));
20define('BIRTHDATE_PATH' ,   PHPWG_PLUGINS_PATH . BIRTHDATE_ID . '/');
21define('BIRTHDATE_TABLE',   $prefixeTable . 'birthdate');
22define('BIRTHDATE_ADMIN',   get_root_url() . 'admin.php?page=plugin-' . BIRTHDATE_ID);
23define('BIRTHDATE_PUBLIC',  get_absolute_root_url() . make_index_url(array('section' => 'birthdate')) . '/');
24define('BIRTHDATE_DIR',     PWG_LOCAL_DIR . 'birthdate/');
25define('BIRTHDATE_VERSION', 'auto');
26
27
28// +-----------------------------------------------------------------------+
29// | Add event handlers                                                    |
30// +-----------------------------------------------------------------------+
31// init the plugin
32add_event_handler('init', 'birthdate_init');
33
34if (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}
42else
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
52include_once(BIRTHDATE_PATH . 'include/functions.inc.php');
53
54/**
55 * plugin initialization
56 *   - check for upgrades
57 *   - unserialize configuration
58 *   - load language
59 */
60function 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 = '
79UPDATE '. PLUGINS_TABLE .'
80SET version = "'. BIRTHDATE_VERSION .'"
81WHERE 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?>
Note: See TracBrowser for help on using the repository browser.