source: extensions/NBM_Subscriber/main.inc.php @ 13741

Last change on this file since 13741 was 12291, checked in by Eric, 13 years ago

New version 2.3.0 hard coded for publication

  • Property svn:eol-style set to LF
File size: 3.7 KB
Line 
1<?php
2/*
3Plugin Name: NBM Subscriber
4Version: 2.3.0
5Description: Permet aux visiteurs inscrits de gérer eux-même leur abonnement à la notification par mail (NBM) - Allows registered visitors to manage their own subscription to the notification by mail (NBM)
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=397
7Author: Eric
8Author URI: http://www.infernoweb.net
9*/
10
11if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
12if (!defined('NBMS_PATH')) define('NBMS_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
13
14include_once (NBMS_PATH.'include/functions.inc.php');
15
16load_language('plugin.lang', NBMS_PATH);
17
18
19/* Plugin admin */
20add_event_handler('get_admin_plugin_menu_links', 'NBMS_admin_menu');
21
22function NBMS_admin_menu($menu)
23{
24// +-----------------------------------------------------------------------+
25// |                      Getting plugin name                              |
26// +-----------------------------------------------------------------------+
27  $plugin =  NBMSInfos(NBMS_PATH);
28  $name = $plugin['name'];
29 
30  array_push($menu,
31    array(
32      'NAME' => $name,
33      'URL' => get_root_url().'admin.php?page=plugin-'.basename(NBMS_PATH)
34    )
35  );
36
37  return $menu;
38}
39
40
41/* Saving from profile with added data */
42add_event_handler('save_profile_from_post', 'NBMS_Save_Profile');
43
44function NBMS_Save_Profile()
45{
46  global $conf, $user;
47 
48  include_once(PHPWG_ROOT_PATH.'admin/include/functions_notification_by_mail.inc.php');
49 
50  $query = '
51SELECT *
52FROM '.USER_MAIL_NOTIFICATION_TABLE.'
53WHERE user_id = \''.$user['id'].'\'
54';
55 
56  $count = pwg_db_num_rows(pwg_query($query));
57 
58  if ($count == 0)
59  {
60    $inserts = array();
61    $check_key_list = array();
62   
63    // Calculate key
64    $nbm_user['check_key'] = find_available_check_key();
65
66    // Save key
67    array_push($check_key_list, $nbm_user['check_key']);
68   
69    // Insert new nbm_users
70    array_push
71    (
72      $inserts,
73        array
74        (
75          'user_id' => $user['id'],
76          'check_key' => $nbm_user['check_key'],
77          'enabled' => 'false' // By default if false, set to true with specific functions
78        )
79    );
80
81    mass_inserts(USER_MAIL_NOTIFICATION_TABLE, array('user_id', 'check_key', 'enabled'), $inserts); 
82  }
83  elseif ($count != 0 and !empty($_POST['NBM_Subscription']) && in_array($_POST['NBM_Subscription'], array('true', 'false')))
84  {
85    $query = '
86UPDATE '.USER_MAIL_NOTIFICATION_TABLE.'
87  SET enabled = \''.$_POST['NBM_Subscription'].'\'
88  WHERE user_id = \''.$user['id'].'\';';
89
90    pwg_query($query); 
91  }
92}
93
94/* Adding NBMS in profile page */
95add_event_handler('load_profile_in_template', 'NBMS_Load_Profile');
96
97function NBMS_Load_Profile()
98{
99  global $conf, $user, $template, $lang;
100
101  $query = '
102  SELECT enabled
103    FROM '.USER_MAIL_NOTIFICATION_TABLE.'
104    WHERE user_id = \''.$user['id'].'\'
105  ;';
106 
107  $data = pwg_db_fetch_assoc(pwg_query($query));
108 
109  $values = $data['enabled'];
110
111  $template->assign('radio_options',
112    array(
113      'true' => l10n('Yes'),
114      'false'=> l10n('No')));
115
116  $template->assign(
117    array(
118      'NBMS'=>$values
119    ));
120     
121  $template->set_prefilter('profile_content', 'NBMS_prefilter');
122}
123
124/* Original template modification */
125function NBMS_prefilter($content, &$smarty)
126{
127  global $template, $lang;
128 
129  load_language('plugin.lang', NBMS_PATH);
130 
131  $search = '<p class="bottomButtons">';
132     
133  $addon = '{if $ALLOW_USER_CUSTOMIZATION}
134  <fieldset>
135    <legend>{\'NBMS_Section\'|@translate}</legend>
136      <ul>
137        <li>
138          <span class="property">{\'NBMS_Text\'|@translate}</span>
139          {html_radios name=\'NBM_Subscription\' options=$radio_options selected=$NBMS}
140        </li>
141      </ul>
142  </fieldset>
143{/if}';
144 
145  $replacement = $addon.$search;
146
147  return str_replace($search, $replacement, $content);
148}
149?>
Note: See TracBrowser for help on using the repository browser.