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

Last change on this file since 14225 was 14225, checked in by Eric, 12 years ago

New version 2.4.0 hard coded for compliance with Piwigo 2.4
Adding index.php in language/ru_RU/ directory

  • Property svn:eol-style set to LF
File size: 3.7 KB
RevLine 
[6436]1<?php
2/*
[6439]3Plugin Name: NBM Subscriber
[14225]4Version: 2.4.0
[6439]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)
[9535]6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=397
[6436]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,
[9888]33      'URL' => get_root_url().'admin.php?page=plugin-'.basename(NBMS_PATH)
[6436]34    )
35  );
36
37  return $menu;
38}
39
40
[6439]41/* Saving from profile with added data */
[6436]42add_event_handler('save_profile_from_post', 'NBMS_Save_Profile');
43
44function NBMS_Save_Profile()
45{
[6439]46  global $conf, $user;
[6436]47 
[6825]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)
[6439]59  {
[6825]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  {
[6439]85    $query = '
[6436]86UPDATE '.USER_MAIL_NOTIFICATION_TABLE.'
87  SET enabled = \''.$_POST['NBM_Subscription'].'\'
88  WHERE user_id = \''.$user['id'].'\';';
89
[6439]90    pwg_query($query); 
[6436]91  }
92}
93
[6439]94/* Adding NBMS in profile page */
[6436]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
[6439]124/* Original template modification */
[6436]125function NBMS_prefilter($content, &$smarty)
126{
[6750]127  global $template, $lang;
[6436]128 
129  load_language('plugin.lang', NBMS_PATH);
130 
131  $search = '<p class="bottomButtons">';
132     
133  $addon = '{if $ALLOW_USER_CUSTOMIZATION}
134  <fieldset>
[6439]135    <legend>{\'NBMS_Section\'|@translate}</legend>
[6436]136      <ul>
137        <li>
[6439]138          <span class="property">{\'NBMS_Text\'|@translate}</span>
[6436]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
[6750]147  return str_replace($search, $replacement, $content);
[6436]148}
149?>
Note: See TracBrowser for help on using the repository browser.