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