1 | <?php |
---|
2 | if (!defined('SUBSCRIBE_TO_PATH')) die('Hacking attempt!'); |
---|
3 | |
---|
4 | global $template, $conf, $page, $user; |
---|
5 | |
---|
6 | // check input parameters |
---|
7 | if ( empty($_GET['action']) or empty($_GET['email']) or empty($_GET['key']) ) |
---|
8 | { |
---|
9 | $_GET['action'] = null; |
---|
10 | } |
---|
11 | else |
---|
12 | { |
---|
13 | $_GET['verif_key'] = $_GET['action'].$_GET['email'].(isset($_GET['id'])?$_GET['id']:null); |
---|
14 | |
---|
15 | if ( decrypt_value($_GET['key'], $conf['secret_key']) !== $_GET['verif_key'] ) |
---|
16 | { |
---|
17 | $_GET['action'] = null; |
---|
18 | } |
---|
19 | } |
---|
20 | |
---|
21 | |
---|
22 | |
---|
23 | if ( !empty($_GET['action']) ) |
---|
24 | { |
---|
25 | // unsubscribe all |
---|
26 | if ( isset($_POST['unsubscribe_all']) and isset($_POST['unsubscribe_all_check']) ) |
---|
27 | { |
---|
28 | $query = ' |
---|
29 | DELETE FROM '.SUBSCRIBE_TO_TABLE.' |
---|
30 | WHERE email = "'.$_GET['email'].'" |
---|
31 | ;'; |
---|
32 | pwg_query($query); |
---|
33 | } |
---|
34 | |
---|
35 | // bulk action |
---|
36 | else if (isset($_POST['apply_bulk']) and !empty($_POST['selected'])) |
---|
37 | { |
---|
38 | foreach ($_POST['selected'] as $id) |
---|
39 | { |
---|
40 | switch ($_POST['action']) |
---|
41 | { |
---|
42 | case 'unsubscribe': |
---|
43 | un_subscribe_to_comments($_GET['email'], $id); |
---|
44 | break; |
---|
45 | case 'validate': |
---|
46 | validate_subscriptions($_GET['email'], $id); |
---|
47 | break; |
---|
48 | } |
---|
49 | } |
---|
50 | } |
---|
51 | |
---|
52 | // unsubscribe from manage page |
---|
53 | else if (isset($_GET['unsubscribe'])) |
---|
54 | { |
---|
55 | if (un_subscribe_to_comments($_GET['email'], $_GET['unsubscribe'])) |
---|
56 | { |
---|
57 | array_push($page['infos'], l10n('Successfully unsubscribed your email address from receiving notifications.')); |
---|
58 | } |
---|
59 | else |
---|
60 | { |
---|
61 | array_push($page['errors'], l10n('Not found.')); |
---|
62 | } |
---|
63 | } |
---|
64 | |
---|
65 | // validate from manage page |
---|
66 | else if (isset($_GET['validate'])) |
---|
67 | { |
---|
68 | if (validate_subscriptions($_GET['email'], $_GET['validate'])) |
---|
69 | { |
---|
70 | array_push($page['infos'], l10n('Your subscribtion has been validated, thanks you.')); |
---|
71 | } |
---|
72 | else |
---|
73 | { |
---|
74 | array_push($page['infos'], l10n('Already validated.')); |
---|
75 | } |
---|
76 | } |
---|
77 | |
---|
78 | $template->assign('MANAGE_LINK', make_stc_url('manage', $_GET['email'])); |
---|
79 | } |
---|
80 | |
---|
81 | |
---|
82 | switch ($_GET['action']) |
---|
83 | { |
---|
84 | /* validate */ |
---|
85 | case 'validate': |
---|
86 | { |
---|
87 | // don't need to sanitize inputs, already checked with the unique key |
---|
88 | $query = ' |
---|
89 | SELECT type, element_id |
---|
90 | FROM '.SUBSCRIBE_TO_TABLE.' |
---|
91 | WHERE |
---|
92 | email = "'.$_GET['email'].'" |
---|
93 | AND id = '.$_GET['id'].' |
---|
94 | ;'; |
---|
95 | $result = pwg_query($query); |
---|
96 | |
---|
97 | if (!pwg_db_num_rows($result)) |
---|
98 | { |
---|
99 | array_push($page['errors'], l10n('Not found.')); |
---|
100 | } |
---|
101 | else |
---|
102 | { |
---|
103 | if (validate_subscriptions($_GET['email'], $_GET['id'])) |
---|
104 | { |
---|
105 | array_push($page['infos'], l10n('Your subscribtion has been validated, thanks you.')); |
---|
106 | } |
---|
107 | else |
---|
108 | { |
---|
109 | array_push($page['infos'], l10n('Already validated.')); |
---|
110 | } |
---|
111 | |
---|
112 | list($type, $element_id) = pwg_db_fetch_row($result); |
---|
113 | |
---|
114 | switch ($type) |
---|
115 | { |
---|
116 | case 'image': |
---|
117 | $element = get_picture_infos($element_id, false); |
---|
118 | break; |
---|
119 | case 'album-images': |
---|
120 | case 'album': |
---|
121 | $element = get_category_infos($element_id, false); |
---|
122 | break; |
---|
123 | default: |
---|
124 | $element = null; |
---|
125 | } |
---|
126 | |
---|
127 | $template->assign(array( |
---|
128 | 'type' => $type, |
---|
129 | 'element' => $element, |
---|
130 | )); |
---|
131 | } |
---|
132 | |
---|
133 | $template->assign('IN_VALIDATE', true); |
---|
134 | break; |
---|
135 | } |
---|
136 | |
---|
137 | /* unsubscribe */ |
---|
138 | case 'unsubscribe': |
---|
139 | { |
---|
140 | $query = ' |
---|
141 | SELECT |
---|
142 | type, |
---|
143 | element_id |
---|
144 | FROM '.SUBSCRIBE_TO_TABLE.' |
---|
145 | WHERE |
---|
146 | email = "'.$_GET['email'].'" |
---|
147 | AND id = '.$_GET['id'].' |
---|
148 | ;'; |
---|
149 | $result = pwg_query($query); |
---|
150 | |
---|
151 | if (!pwg_db_num_rows($result)) |
---|
152 | { |
---|
153 | array_push($page['errors'], l10n('Not found.')); |
---|
154 | } |
---|
155 | else |
---|
156 | { |
---|
157 | if (un_subscribe_to_comments($_GET['email'], $_GET['id'])) |
---|
158 | { |
---|
159 | array_push($page['infos'], l10n('Successfully unsubscribed your email address from receiving notifications.')); |
---|
160 | } |
---|
161 | else |
---|
162 | { |
---|
163 | array_push($page['errors'], l10n('Not found.')); |
---|
164 | } |
---|
165 | |
---|
166 | list($type, $element_id) = pwg_db_fetch_row($result); |
---|
167 | |
---|
168 | switch ($type) |
---|
169 | { |
---|
170 | case 'image': |
---|
171 | $element = get_picture_infos($element_id); |
---|
172 | break; |
---|
173 | case 'album-images': |
---|
174 | case 'album': |
---|
175 | $element = get_category_infos($element_id); |
---|
176 | break; |
---|
177 | default: |
---|
178 | $element = null; |
---|
179 | } |
---|
180 | |
---|
181 | $template->assign(array( |
---|
182 | 'type' => $type, |
---|
183 | 'element' => $element, |
---|
184 | )); |
---|
185 | } |
---|
186 | |
---|
187 | $template->assign('IN_UNSUBSCRIBE', true); |
---|
188 | break; |
---|
189 | } |
---|
190 | |
---|
191 | /* manage */ |
---|
192 | case 'manage': |
---|
193 | { |
---|
194 | $query = ' |
---|
195 | SELECT * |
---|
196 | FROM '.SUBSCRIBE_TO_TABLE.' |
---|
197 | WHERE email = "'.$_GET['email'].'" |
---|
198 | ORDER BY registration_date DESC |
---|
199 | ;'; |
---|
200 | $result = pwg_query($query); |
---|
201 | |
---|
202 | if (pwg_db_num_rows($result)) |
---|
203 | { |
---|
204 | while ($subscription = pwg_db_fetch_assoc($result)) |
---|
205 | { |
---|
206 | $subscription['registration_date'] = format_date($subscription['registration_date'], true); |
---|
207 | |
---|
208 | switch ($subscription['type']) |
---|
209 | { |
---|
210 | case 'image': |
---|
211 | $subscription['infos'] = get_picture_infos($subscription['element_id']); |
---|
212 | break; |
---|
213 | case 'album-images': |
---|
214 | case 'album': |
---|
215 | $subscription['infos'] = get_category_infos($subscription['element_id'], true, $user['id']); |
---|
216 | break; |
---|
217 | default: |
---|
218 | $subscription['infos'] = null; |
---|
219 | $template->append('global_subscriptions', $subscription); |
---|
220 | continue(2); |
---|
221 | } |
---|
222 | |
---|
223 | $template->append('subscriptions', $subscription); |
---|
224 | } |
---|
225 | } |
---|
226 | else |
---|
227 | { |
---|
228 | array_push($page['infos'], l10n('You are not subscribed to any comment.')); |
---|
229 | } |
---|
230 | break; |
---|
231 | } |
---|
232 | |
---|
233 | default: |
---|
234 | { |
---|
235 | set_status_header(403); |
---|
236 | array_push($page['errors'], l10n('Bad query')); |
---|
237 | } |
---|
238 | } |
---|
239 | |
---|
240 | |
---|
241 | $template->assign(array( |
---|
242 | 'SUBSCRIBE_TO_PATH' => SUBSCRIBE_TO_PATH, |
---|
243 | 'SUBSCRIBE_TO_ABS_PATH' => realpath(SUBSCRIBE_TO_PATH).'/', |
---|
244 | 'COA_ACTIVATED' => defined('COA_ID'), |
---|
245 | )); |
---|
246 | |
---|
247 | if (!empty($_GET['email'])) |
---|
248 | { |
---|
249 | $template->assign('TITLE', '<a href="'.get_absolute_root_url().'">'.l10n('Home').'</a>'.$conf['level_separator']. |
---|
250 | sprintf(l10n('Subscriptions of %s'), '<i>'.$_GET['email'].'</i>')); |
---|
251 | } |
---|
252 | |
---|
253 | $template->set_filename('index', realpath(SUBSCRIBE_TO_PATH . 'template/subscribtions_page.tpl')); |
---|
254 | |
---|
255 | ?> |
---|