1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: NBM_Subscribe |
---|
4 | Version: 1.0.a |
---|
5 | Description: Permettre aux visiteurs inscrits de s'inscrire eux-même à la notification par mail (NBM) - To allow the registered users to subscribe themself to the notification by mail (NBM) |
---|
6 | Plugin URI: http://fr.piwigo.org/ext/extension_view.php?eid= |
---|
7 | Author: Eric |
---|
8 | Author URI: http://www.infernoweb.net |
---|
9 | */ |
---|
10 | |
---|
11 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
12 | if (!defined('NBMS_DIR')) define('NBMS_DIR' , basename(dirname(__FILE__))); |
---|
13 | if (!defined('NBMS_PATH')) define('NBMS_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
---|
14 | |
---|
15 | include_once (NBMS_PATH.'include/functions.inc.php'); |
---|
16 | |
---|
17 | load_language('plugin.lang', NBMS_PATH); |
---|
18 | |
---|
19 | |
---|
20 | /* Plugin admin */ |
---|
21 | add_event_handler('get_admin_plugin_menu_links', 'NBMS_admin_menu'); |
---|
22 | |
---|
23 | function 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 | /* Adding NBMS in profile page */ |
---|
43 | //add_event_handler('loc_begin_profile', 'NBMS_Profile'); |
---|
44 | add_event_handler('save_profile_from_post', 'NBMS_Save_Profile'); |
---|
45 | |
---|
46 | function NBMS_Save_Profile() |
---|
47 | { |
---|
48 | global $conf; |
---|
49 | |
---|
50 | if (!empty($_POST['NBM_Subscription']) && in_array( $_POST['NBM_Subscription'], array('true', 'false'))) |
---|
51 | { |
---|
52 | $fo=fopen (NBMS_PATH.'log.txt','a') ; |
---|
53 | fwrite($fo,"======================\n") ; |
---|
54 | fwrite($fo,'le ' . date('D, d M Y H:i:s') . "\r\n"); |
---|
55 | fwrite($fo,$to . "\n" . $_POST['NBM_Subscription'] . "\r\n") ; |
---|
56 | fclose($fo) ; |
---|
57 | |
---|
58 | $query = ' |
---|
59 | UPDATE '.USER_MAIL_NOTIFICATION_TABLE.' |
---|
60 | SET enabled = \''.$_POST['NBM_Subscription'].'\' |
---|
61 | WHERE user_id = \''.$user['id'].'\';'; |
---|
62 | |
---|
63 | pwg_query($query); |
---|
64 | } |
---|
65 | /*if (isset($_POST['NBM_Subscription']) and $_POST['NBM_Subscription'] == 'true') |
---|
66 | { |
---|
67 | $query = ' |
---|
68 | UPDATE '.USER_MAIL_NOTIFICATION_TABLE.' |
---|
69 | SET enabled = \'true\' |
---|
70 | WHERE user_id = \''.$user['id'].'\';'; |
---|
71 | |
---|
72 | pwg_query($query); |
---|
73 | } |
---|
74 | elseif (isset($_POST['NBM_Subscription']) and $_POST['NBM_Subscription'] == 'false') |
---|
75 | { |
---|
76 | $query = ' |
---|
77 | UPDATE '.USER_MAIL_NOTIFICATION_TABLE.' |
---|
78 | SET enabled = \'false\' |
---|
79 | WHERE user_id = \''.$user['id'].'\';'; |
---|
80 | |
---|
81 | pwg_query($query); |
---|
82 | }*/ |
---|
83 | } |
---|
84 | |
---|
85 | add_event_handler('load_profile_in_template', 'NBMS_Load_Profile'); |
---|
86 | |
---|
87 | function NBMS_Load_Profile() |
---|
88 | { |
---|
89 | global $conf, $user, $template, $lang; |
---|
90 | |
---|
91 | $query = ' |
---|
92 | SELECT enabled |
---|
93 | FROM '.USER_MAIL_NOTIFICATION_TABLE.' |
---|
94 | WHERE user_id = \''.$user['id'].'\' |
---|
95 | ;'; |
---|
96 | |
---|
97 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
98 | |
---|
99 | $values = $data['enabled']; |
---|
100 | |
---|
101 | $template->assign('radio_options', |
---|
102 | array( |
---|
103 | 'true' => l10n('Yes'), |
---|
104 | 'false'=> l10n('No'))); |
---|
105 | |
---|
106 | $template->assign( |
---|
107 | array( |
---|
108 | 'NBMS'=>$values |
---|
109 | )); |
---|
110 | |
---|
111 | $template->set_prefilter('profile_content', 'NBMS_prefilter'); |
---|
112 | } |
---|
113 | |
---|
114 | function NBMS_prefilter($content, &$smarty) |
---|
115 | { |
---|
116 | global $template; |
---|
117 | |
---|
118 | load_language('plugin.lang', NBMS_PATH); |
---|
119 | |
---|
120 | $search = '<p class="bottomButtons">'; |
---|
121 | |
---|
122 | $addon = '{if $ALLOW_USER_CUSTOMIZATION} |
---|
123 | <fieldset> |
---|
124 | <legend>{\'NBMS_Title\'|@translate}</legend> |
---|
125 | <ul> |
---|
126 | <li> |
---|
127 | <span class="property">{\'NBMS\'|@translate}</span> |
---|
128 | <span class="property">{$TEST}</span> |
---|
129 | {html_radios name=\'NBM_Subscription\' options=$radio_options selected=$NBMS} |
---|
130 | </li> |
---|
131 | </ul> |
---|
132 | </fieldset> |
---|
133 | {/if}'; |
---|
134 | |
---|
135 | $replacement = $addon.$search; |
---|
136 | |
---|
137 | return str_replace($search, $replacement, $content);; |
---|
138 | } |
---|
139 | |
---|
140 | ?> |
---|