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

Revision 6750, 2.9 KB checked in by Eric, 10 years ago (diff)

[NBM_Subscriber]

  • Bug on language display in customization panel fixed
  • New 1.0.1 release for PEM publication
  • Property svn:eol-style set to LF
Line 
1<?php
2/*
3Plugin Name: NBM Subscriber
4Version: 1.0.1
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://fr.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_DIR')) define('NBMS_DIR' , basename(dirname(__FILE__)));
13if (!defined('NBMS_PATH')) define('NBMS_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
14
15include_once (NBMS_PATH.'include/functions.inc.php');
16
17load_language('plugin.lang', NBMS_PATH);
18
19
20/* Plugin admin */
21add_event_handler('get_admin_plugin_menu_links', 'NBMS_admin_menu');
22
23function NBMS_admin_menu($menu)
24{
25// +-----------------------------------------------------------------------+
26// |                      Getting plugin name                              |
27// +-----------------------------------------------------------------------+
28  $plugin =  NBMSInfos(NBMS_PATH);
29  $name = $plugin['name'];
30 
31  array_push($menu,
32    array(
33      'NAME' => $name,
34      'URL'  => get_admin_plugin_menu_link(NBMS_PATH.'/admin/NBMS_admin.php')
35    )
36  );
37
38  return $menu;
39}
40
41
42/* Saving from profile with added data */
43add_event_handler('save_profile_from_post', 'NBMS_Save_Profile');
44
45function NBMS_Save_Profile()
46{
47  global $conf, $user;
48 
49  if (!empty($_POST['NBM_Subscription']) && in_array( $_POST['NBM_Subscription'], array('true', 'false')))
50  {
51    $query = '
52UPDATE '.USER_MAIL_NOTIFICATION_TABLE.'
53  SET enabled = \''.$_POST['NBM_Subscription'].'\'
54  WHERE user_id = \''.$user['id'].'\';';
55
56    pwg_query($query); 
57  }
58}
59
60/* Adding NBMS in profile page */
61add_event_handler('load_profile_in_template', 'NBMS_Load_Profile');
62
63function NBMS_Load_Profile()
64{
65  global $conf, $user, $template, $lang;
66
67  $query = '
68  SELECT enabled
69    FROM '.USER_MAIL_NOTIFICATION_TABLE.'
70    WHERE user_id = \''.$user['id'].'\'
71  ;';
72 
73  $data = pwg_db_fetch_assoc(pwg_query($query));
74 
75  $values = $data['enabled'];
76
77  $template->assign('radio_options',
78    array(
79      'true' => l10n('Yes'),
80      'false'=> l10n('No')));
81
82  $template->assign(
83    array(
84      'NBMS'=>$values
85    ));
86     
87  $template->set_prefilter('profile_content', 'NBMS_prefilter');
88}
89
90/* Original template modification */
91function NBMS_prefilter($content, &$smarty)
92{
93  global $template, $lang;
94 
95  load_language('plugin.lang', NBMS_PATH);
96 
97  $search = '<p class="bottomButtons">';
98     
99  $addon = '{if $ALLOW_USER_CUSTOMIZATION}
100  <fieldset>
101    <legend>{\'NBMS_Section\'|@translate}</legend>
102      <ul>
103        <li>
104          <span class="property">{\'NBMS_Text\'|@translate}</span>
105          {html_radios name=\'NBM_Subscription\' options=$radio_options selected=$NBMS}
106        </li>
107      </ul>
108  </fieldset>
109{/if}';
110 
111  $replacement = $addon.$search;
112
113  return str_replace($search, $replacement, $content);
114}
115?>
Note: See TracBrowser for help on using the repository browser.