source: extensions/Subscribe_to_comments/main.inc.php @ 21533

Last change on this file since 21533 was 21441, checked in by mistic100, 11 years ago

some code corrections

File size: 3.0 KB
Line 
1<?php 
2/*
3Plugin Name: Subscribe To Comments
4Version: auto
5Description: This plugin allows to subscribe to comments by email.
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=587
7Author: Mistic
8Author URI: http://www.strangeplanet.fr
9*/
10
11/*
12 * potential problem : if the permissions of a user change, he receives notifications
13 * about photos and albums he can't see anymore
14 */
15
16if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
17
18global $prefixeTable;
19
20defined('SUBSCRIBE_TO_ID') or define('SUBSCRIBE_TO_ID', basename(dirname(__FILE__)));
21define('SUBSCRIBE_TO_PATH' ,   PHPWG_PLUGINS_PATH . SUBSCRIBE_TO_ID . '/');
22define('SUBSCRIBE_TO_TABLE',   $prefixeTable . 'subscribe_to_comments');
23define('SUBSCRIBE_TO_VERSION', 'auto');
24
25
26add_event_handler('init', 'stc_init');
27
28
29function stc_init()
30{
31  global $conf, $user, $pwg_loaded_plugins;
32 
33  // no comments on luciano
34  if ($user['theme'] == 'luciano') return;
35 
36  // apply upgrade if needed
37  if (
38    SUBSCRIBE_TO_VERSION == 'auto' or
39    $pwg_loaded_plugins[SUBSCRIBE_TO_ID]['version'] == 'auto' or
40    version_compare($pwg_loaded_plugins[SUBSCRIBE_TO_ID]['version'], SUBSCRIBE_TO_VERSION, '<')
41  )
42  {
43    include_once(SUBSCRIBE_TO_PATH . 'include/install.inc.php');
44    stc_install();
45   
46    if ( $pwg_loaded_plugins[SUBSCRIBE_TO_ID]['version'] != 'auto' and SUBSCRIBE_TO_VERSION != 'auto' )
47    {
48      $query = '
49UPDATE '. PLUGINS_TABLE .'
50SET version = "'. SUBSCRIBE_TO_VERSION .'"
51WHERE id = "'. SUBSCRIBE_TO_ID .'"';
52      pwg_query($query);
53     
54      $pwg_loaded_plugins[SUBSCRIBE_TO_ID]['version'] = SUBSCRIBE_TO_VERSION;
55     
56      if (defined('IN_ADMIN'))
57      {
58        $_SESSION['page_infos'][] = 'Subscribe to comments updated to version '. SUBSCRIBE_TO_VERSION;
59      }
60    }
61  }
62 
63  // load language and conf
64  load_language('plugin.lang', SUBSCRIBE_TO_PATH);
65  $conf['Subscribe_to_Comments'] = unserialize($conf['Subscribe_to_Comments']);
66 
67 
68  include_once(SUBSCRIBE_TO_PATH.'include/functions.inc.php');
69  include_once(SUBSCRIBE_TO_PATH.'include/subscribe_to_comments.inc.php');
70
71 
72  // send mails
73  add_event_handler('user_comment_insertion', 'stc_comment_insertion');
74  add_event_handler('user_comment_validation', 'stc_comment_validation', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
75
76  // subscribe
77  add_event_handler('loc_end_picture', 'stc_on_picture');
78  add_event_handler('loc_begin_coa', 'stc_on_album');
79
80  // management
81  add_event_handler('loc_end_section_init', 'stc_detect_section');
82  add_event_handler('loc_begin_page_header', 'stc_load_section');
83 
84  // items deletion
85  add_event_handler('begin_delete_elements', 'stc_delete_elements');
86  add_event_handler('delete_categories', 'stc_delete_categories');
87
88  // profile link
89  add_event_handler('loc_begin_profile', 'stc_profile_link');
90 
91  // config page
92  add_event_handler('get_admin_plugin_menu_links', 'stc_admin_menu');
93}
94
95
96function stc_admin_menu($menu) 
97{
98  array_push($menu, array(
99    'NAME' => 'Subscribe to Comments',
100    'URL' => get_root_url().'admin.php?page=plugin-' . SUBSCRIBE_TO_ID,
101  ));
102  return $menu;
103}
104
105?>
Note: See TracBrowser for help on using the repository browser.