Mercurial > hg > vamp-website
comparison forum/Sources/ManageNews.php @ 76:e3e11437ecea website
Add forum code
author | Chris Cannam |
---|---|
date | Sun, 07 Jul 2013 11:25:48 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
75:72f59aa7e503 | 76:e3e11437ecea |
---|---|
1 <?php | |
2 | |
3 /** | |
4 * Simple Machines Forum (SMF) | |
5 * | |
6 * @package SMF | |
7 * @author Simple Machines http://www.simplemachines.org | |
8 * @copyright 2011 Simple Machines | |
9 * @license http://www.simplemachines.org/about/smf/license.php BSD | |
10 * | |
11 * @version 2.0 | |
12 */ | |
13 | |
14 if (!defined('SMF')) | |
15 die('Hacking attempt...'); | |
16 | |
17 /* | |
18 void ManageNews() | |
19 - the entrance point for all News and Newsletter screens. | |
20 - called by ?action=admin;area=news. | |
21 - does the permission checks. | |
22 - calls the appropriate function based on the requested sub-action. | |
23 | |
24 void EditNews() | |
25 - changes the current news items for the forum. | |
26 - uses the ManageNews template and edit_news sub template. | |
27 - called by ?action=admin;area=news. | |
28 - requires the edit_news permission. | |
29 - writes an entry into the moderation log. | |
30 - uses the edit_news administration area. | |
31 - can be accessed with ?action=admin;sa=editnews. | |
32 | |
33 void SelectMailingMembers() | |
34 - allows a user to select the membergroups to send their mailing to. | |
35 - uses the ManageNews template and email_members sub template. | |
36 - called by ?action=admin;area=news;sa=mailingmembers. | |
37 - requires the send_mail permission. | |
38 - form is submitted to ?action=admin;area=news;mailingcompose. | |
39 | |
40 void ComposeMailing() | |
41 - shows a form to edit a forum mailing and its recipients. | |
42 - uses the ManageNews template and email_members_compose sub template. | |
43 - called by ?action=admin;area=news;sa=mailingcompose. | |
44 - requires the send_mail permission. | |
45 - form is submitted to ?action=admin;area=news;sa=mailingsend. | |
46 | |
47 void SendMailing(bool clean_only = false) | |
48 - handles the sending of the forum mailing in batches. | |
49 - uses the ManageNews template and email_members_send sub template. | |
50 - called by ?action=admin;area=news;sa=mailingsend | |
51 - requires the send_mail permission. | |
52 - redirects to itself when more batches need to be sent. | |
53 - redirects to ?action=admin after everything has been sent. | |
54 - if clean_only is set will only clean the variables, put them in context, then return. | |
55 | |
56 void NewsSettings() | |
57 - set general news and newsletter settings and permissions. | |
58 - uses the ManageNews template and news_settings sub template. | |
59 - called by ?action=admin;area=news;sa=settings. | |
60 - requires the forum_admin permission. | |
61 */ | |
62 | |
63 // The controller; doesn't do anything, just delegates. | |
64 function ManageNews() | |
65 { | |
66 global $context, $txt, $scripturl; | |
67 | |
68 // First, let's do a quick permissions check for the best error message possible. | |
69 isAllowedTo(array('edit_news', 'send_mail', 'admin_forum')); | |
70 | |
71 loadTemplate('ManageNews'); | |
72 | |
73 // Format: 'sub-action' => array('function', 'permission') | |
74 $subActions = array( | |
75 'editnews' => array('EditNews', 'edit_news'), | |
76 'mailingmembers' => array('SelectMailingMembers', 'send_mail'), | |
77 'mailingcompose' => array('ComposeMailing', 'send_mail'), | |
78 'mailingsend' => array('SendMailing', 'send_mail'), | |
79 'settings' => array('ModifyNewsSettings', 'admin_forum'), | |
80 ); | |
81 | |
82 // Default to sub action 'main' or 'settings' depending on permissions. | |
83 $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : (allowedTo('edit_news') ? 'editnews' : (allowedTo('send_mail') ? 'mailingmembers' : 'settings')); | |
84 | |
85 // Have you got the proper permissions? | |
86 isAllowedTo($subActions[$_REQUEST['sa']][1]); | |
87 | |
88 // Create the tabs for the template. | |
89 $context[$context['admin_menu_name']]['tab_data'] = array( | |
90 'title' => $txt['news_title'], | |
91 'help' => 'edit_news', | |
92 'description' => $txt['admin_news_desc'], | |
93 'tabs' => array( | |
94 'editnews' => array( | |
95 ), | |
96 'mailingmembers' => array( | |
97 'description' => $txt['news_mailing_desc'], | |
98 ), | |
99 'settings' => array( | |
100 'description' => $txt['news_settings_desc'], | |
101 ), | |
102 ), | |
103 ); | |
104 | |
105 // Force the right area... | |
106 if (substr($_REQUEST['sa'], 0, 7) == 'mailing') | |
107 $context[$context['admin_menu_name']]['current_subsection'] = 'mailingmembers'; | |
108 | |
109 $subActions[$_REQUEST['sa']][0](); | |
110 } | |
111 | |
112 // Let the administrator(s) edit the news. | |
113 function EditNews() | |
114 { | |
115 global $txt, $modSettings, $context, $sourcedir, $user_info; | |
116 global $smcFunc; | |
117 | |
118 require_once($sourcedir . '/Subs-Post.php'); | |
119 | |
120 // The 'remove selected' button was pressed. | |
121 if (!empty($_POST['delete_selection']) && !empty($_POST['remove'])) | |
122 { | |
123 checkSession(); | |
124 | |
125 // Store the news temporarily in this array. | |
126 $temp_news = explode("\n", $modSettings['news']); | |
127 | |
128 // Remove the items that were selected. | |
129 foreach ($temp_news as $i => $news) | |
130 if (in_array($i, $_POST['remove'])) | |
131 unset($temp_news[$i]); | |
132 | |
133 // Update the database. | |
134 updateSettings(array('news' => implode("\n", $temp_news))); | |
135 | |
136 logAction('news'); | |
137 } | |
138 // The 'Save' button was pressed. | |
139 elseif (!empty($_POST['save_items'])) | |
140 { | |
141 checkSession(); | |
142 | |
143 foreach ($_POST['news'] as $i => $news) | |
144 { | |
145 if (trim($news) == '') | |
146 unset($_POST['news'][$i]); | |
147 else | |
148 { | |
149 $_POST['news'][$i] = $smcFunc['htmlspecialchars']($_POST['news'][$i], ENT_QUOTES); | |
150 preparsecode($_POST['news'][$i]); | |
151 } | |
152 } | |
153 | |
154 // Send the new news to the database. | |
155 updateSettings(array('news' => implode("\n", $_POST['news']))); | |
156 | |
157 // Log this into the moderation log. | |
158 logAction('news'); | |
159 } | |
160 | |
161 // Ready the current news. | |
162 foreach (explode("\n", $modSettings['news']) as $id => $line) | |
163 $context['admin_current_news'][$id] = array( | |
164 'id' => $id, | |
165 'unparsed' => un_preparsecode($line), | |
166 'parsed' => preg_replace('~<([/]?)form[^>]*?[>]*>~i', '<em class="smalltext"><$1form></em>', parse_bbc($line)), | |
167 ); | |
168 | |
169 $context['sub_template'] = 'edit_news'; | |
170 $context['page_title'] = $txt['admin_edit_news']; | |
171 } | |
172 | |
173 function SelectMailingMembers() | |
174 { | |
175 global $txt, $context, $modSettings, $smcFunc; | |
176 | |
177 $context['page_title'] = $txt['admin_newsletters']; | |
178 | |
179 $context['sub_template'] = 'email_members'; | |
180 | |
181 $context['groups'] = array(); | |
182 $postGroups = array(); | |
183 $normalGroups = array(); | |
184 | |
185 // If we have post groups disabled then we need to give a "ungrouped members" option. | |
186 if (empty($modSettings['permission_enable_postgroups'])) | |
187 { | |
188 $context['groups'][0] = array( | |
189 'id' => 0, | |
190 'name' => $txt['membergroups_members'], | |
191 'member_count' => 0, | |
192 ); | |
193 $normalGroups[0] = 0; | |
194 } | |
195 | |
196 // Get all the extra groups as well as Administrator and Global Moderator. | |
197 $request = $smcFunc['db_query']('', ' | |
198 SELECT mg.id_group, mg.group_name, mg.min_posts | |
199 FROM {db_prefix}membergroups AS mg' . (empty($modSettings['permission_enable_postgroups']) ? ' | |
200 WHERE mg.min_posts = {int:min_posts}' : '') . ' | |
201 GROUP BY mg.id_group, mg.min_posts, mg.group_name | |
202 ORDER BY mg.min_posts, CASE WHEN mg.id_group < {int:newbie_group} THEN mg.id_group ELSE 4 END, mg.group_name', | |
203 array( | |
204 'min_posts' => -1, | |
205 'newbie_group' => 4, | |
206 ) | |
207 ); | |
208 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
209 { | |
210 $context['groups'][$row['id_group']] = array( | |
211 'id' => $row['id_group'], | |
212 'name' => $row['group_name'], | |
213 'member_count' => 0, | |
214 ); | |
215 | |
216 if ($row['min_posts'] == -1) | |
217 $normalGroups[$row['id_group']] = $row['id_group']; | |
218 else | |
219 $postGroups[$row['id_group']] = $row['id_group']; | |
220 } | |
221 $smcFunc['db_free_result']($request); | |
222 | |
223 // If we have post groups, let's count the number of members... | |
224 if (!empty($postGroups)) | |
225 { | |
226 $query = $smcFunc['db_query']('', ' | |
227 SELECT mem.id_post_group AS id_group, COUNT(*) AS member_count | |
228 FROM {db_prefix}members AS mem | |
229 WHERE mem.id_post_group IN ({array_int:post_group_list}) | |
230 GROUP BY mem.id_post_group', | |
231 array( | |
232 'post_group_list' => $postGroups, | |
233 ) | |
234 ); | |
235 while ($row = $smcFunc['db_fetch_assoc']($query)) | |
236 $context['groups'][$row['id_group']]['member_count'] += $row['member_count']; | |
237 $smcFunc['db_free_result']($query); | |
238 } | |
239 | |
240 if (!empty($normalGroups)) | |
241 { | |
242 // Find people who are members of this group... | |
243 $query = $smcFunc['db_query']('', ' | |
244 SELECT id_group, COUNT(*) AS member_count | |
245 FROM {db_prefix}members | |
246 WHERE id_group IN ({array_int:normal_group_list}) | |
247 GROUP BY id_group', | |
248 array( | |
249 'normal_group_list' => $normalGroups, | |
250 ) | |
251 ); | |
252 while ($row = $smcFunc['db_fetch_assoc']($query)) | |
253 $context['groups'][$row['id_group']]['member_count'] += $row['member_count']; | |
254 $smcFunc['db_free_result']($query); | |
255 | |
256 // Also do those who have it as an additional membergroup - this ones more yucky... | |
257 $query = $smcFunc['db_query']('', ' | |
258 SELECT mg.id_group, COUNT(*) AS member_count | |
259 FROM {db_prefix}membergroups AS mg | |
260 INNER JOIN {db_prefix}members AS mem ON (mem.additional_groups != {string:blank_string} | |
261 AND mem.id_group != mg.id_group | |
262 AND FIND_IN_SET(mg.id_group, mem.additional_groups) != 0) | |
263 WHERE mg.id_group IN ({array_int:normal_group_list}) | |
264 GROUP BY mg.id_group', | |
265 array( | |
266 'normal_group_list' => $normalGroups, | |
267 'blank_string' => '', | |
268 ) | |
269 ); | |
270 while ($row = $smcFunc['db_fetch_assoc']($query)) | |
271 $context['groups'][$row['id_group']]['member_count'] += $row['member_count']; | |
272 $smcFunc['db_free_result']($query); | |
273 } | |
274 | |
275 // Any moderators? | |
276 $request = $smcFunc['db_query']('', ' | |
277 SELECT COUNT(DISTINCT id_member) AS num_distinct_mods | |
278 FROM {db_prefix}moderators | |
279 LIMIT 1', | |
280 array( | |
281 ) | |
282 ); | |
283 list ($context['groups'][3]['member_count']) = $smcFunc['db_fetch_row']($request); | |
284 $smcFunc['db_free_result']($request); | |
285 | |
286 $context['can_send_pm'] = allowedTo('pm_send'); | |
287 } | |
288 | |
289 // Email your members... | |
290 function ComposeMailing() | |
291 { | |
292 global $txt, $sourcedir, $context, $smcFunc; | |
293 | |
294 // Start by finding any members! | |
295 $toClean = array(); | |
296 if (!empty($_POST['members'])) | |
297 $toClean[] = 'members'; | |
298 if (!empty($_POST['exclude_members'])) | |
299 $toClean[] = 'exclude_members'; | |
300 if (!empty($toClean)) | |
301 { | |
302 require_once($sourcedir . '/Subs-Auth.php'); | |
303 foreach ($toClean as $type) | |
304 { | |
305 // Remove the quotes. | |
306 $_POST[$type] = strtr($_POST[$type], array('\\"' => '"')); | |
307 | |
308 preg_match_all('~"([^"]+)"~', $_POST[$type], $matches); | |
309 $_POST[$type] = array_unique(array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $_POST[$type])))); | |
310 | |
311 foreach ($_POST[$type] as $index => $member) | |
312 if (strlen(trim($member)) > 0) | |
313 $_POST[$type][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($member))); | |
314 else | |
315 unset($_POST[$type][$index]); | |
316 | |
317 // Find the members | |
318 $_POST[$type] = implode(',', array_keys(findMembers($_POST[$type]))); | |
319 } | |
320 } | |
321 | |
322 if (isset($_POST['member_list']) && is_array($_POST['member_list'])) | |
323 { | |
324 $members = array(); | |
325 foreach ($_POST['member_list'] as $member_id) | |
326 $members[] = (int) $member_id; | |
327 $_POST['members'] = implode(',', $members); | |
328 } | |
329 | |
330 if (isset($_POST['exclude_member_list']) && is_array($_POST['exclude_member_list'])) | |
331 { | |
332 $members = array(); | |
333 foreach ($_POST['exclude_member_list'] as $member_id) | |
334 $members[] = (int) $member_id; | |
335 $_POST['exclude_members'] = implode(',', $members); | |
336 } | |
337 | |
338 // Clean the other vars. | |
339 SendMailing(true); | |
340 | |
341 // We need a couple strings from the email template file | |
342 loadLanguage('EmailTemplates'); | |
343 | |
344 // Get a list of all full banned users. Use their Username and email to find them. Only get the ones that can't login to turn off notification. | |
345 $request = $smcFunc['db_query']('', ' | |
346 SELECT DISTINCT mem.id_member | |
347 FROM {db_prefix}ban_groups AS bg | |
348 INNER JOIN {db_prefix}ban_items AS bi ON (bg.id_ban_group = bi.id_ban_group) | |
349 INNER JOIN {db_prefix}members AS mem ON (bi.id_member = mem.id_member) | |
350 WHERE (bg.cannot_access = {int:cannot_access} OR bg.cannot_login = {int:cannot_login}) | |
351 AND (bg.expire_time IS NULL OR bg.expire_time > {int:current_time})', | |
352 array( | |
353 'cannot_access' => 1, | |
354 'cannot_login' => 1, | |
355 'current_time' => time(), | |
356 ) | |
357 ); | |
358 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
359 $context['recipients']['exclude_members'][] = $row['id_member']; | |
360 $smcFunc['db_free_result']($request); | |
361 | |
362 $request = $smcFunc['db_query']('', ' | |
363 SELECT DISTINCT bi.email_address | |
364 FROM {db_prefix}ban_items AS bi | |
365 INNER JOIN {db_prefix}ban_groups AS bg ON (bg.id_ban_group = bi.id_ban_group) | |
366 WHERE (bg.cannot_access = {int:cannot_access} OR bg.cannot_login = {int:cannot_login}) | |
367 AND (COALESCE(bg.expire_time, 1=1) OR bg.expire_time > {int:current_time}) | |
368 AND bi.email_address != {string:blank_string}', | |
369 array( | |
370 'cannot_access' => 1, | |
371 'cannot_login' => 1, | |
372 'current_time' => time(), | |
373 'blank_string' => '', | |
374 ) | |
375 ); | |
376 $condition_array = array(); | |
377 $condition_array_params = array(); | |
378 $count = 0; | |
379 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
380 { | |
381 $condition_array[] = '{string:email_' . $count . '}'; | |
382 $condition_array_params['email_' . $count++] = $row['email_address']; | |
383 } | |
384 | |
385 if (!empty($condition_array)) | |
386 { | |
387 $request = $smcFunc['db_query']('', ' | |
388 SELECT id_member | |
389 FROM {db_prefix}members | |
390 WHERE email_address IN(' . implode(', ', $condition_array) .')', | |
391 $condition_array_params | |
392 ); | |
393 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
394 $context['recipients']['exclude_members'][] = $row['id_member']; | |
395 } | |
396 | |
397 // Did they select moderators - if so add them as specific members... | |
398 if ((!empty($context['recipients']['groups']) && in_array(3, $context['recipients']['groups'])) || (!empty($context['recipients']['exclude_groups']) && in_array(3, $context['recipients']['exclude_groups']))) | |
399 { | |
400 $request = $smcFunc['db_query']('', ' | |
401 SELECT DISTINCT mem.id_member AS identifier | |
402 FROM {db_prefix}members AS mem | |
403 INNER JOIN {db_prefix}moderators AS mods ON (mods.id_member = mem.id_member) | |
404 WHERE mem.is_activated = {int:is_activated}', | |
405 array( | |
406 'is_activated' => 1, | |
407 ) | |
408 ); | |
409 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
410 { | |
411 if (in_array(3, $context['recipients'])) | |
412 $context['recipients']['exclude_members'][] = $row['identifier']; | |
413 else | |
414 $context['recipients']['members'][] = $row['identifier']; | |
415 } | |
416 $smcFunc['db_free_result']($request); | |
417 } | |
418 | |
419 // For progress bar! | |
420 $context['total_emails'] = count($context['recipients']['emails']); | |
421 $request = $smcFunc['db_query']('', ' | |
422 SELECT MAX(id_member) | |
423 FROM {db_prefix}members', | |
424 array( | |
425 ) | |
426 ); | |
427 list ($context['max_id_member']) = $smcFunc['db_fetch_row']($request); | |
428 $smcFunc['db_free_result']($request); | |
429 | |
430 // Clean up the arrays. | |
431 $context['recipients']['members'] = array_unique($context['recipients']['members']); | |
432 $context['recipients']['exclude_members'] = array_unique($context['recipients']['exclude_members']); | |
433 | |
434 // Setup the template! | |
435 $context['page_title'] = $txt['admin_newsletters']; | |
436 $context['sub_template'] = 'email_members_compose'; | |
437 | |
438 $context['default_subject'] = htmlspecialchars($context['forum_name'] . ': ' . $txt['subject']); | |
439 $context['default_message'] = htmlspecialchars($txt['message'] . "\n\n" . $txt['regards_team'] . "\n\n" . '{$board_url}'); | |
440 } | |
441 | |
442 // Send out the mailing! | |
443 function SendMailing($clean_only = false) | |
444 { | |
445 global $txt, $sourcedir, $context, $smcFunc; | |
446 global $scripturl, $modSettings, $user_info; | |
447 | |
448 // How many to send at once? Quantity depends on whether we are queueing or not. | |
449 $num_at_once = empty($modSettings['mail_queue']) ? 60 : 1000; | |
450 | |
451 // If by PM's I suggest we half the above number. | |
452 if (!empty($_POST['send_pm'])) | |
453 $num_at_once /= 2; | |
454 | |
455 checkSession(); | |
456 | |
457 // Where are we actually to? | |
458 $context['start'] = isset($_REQUEST['start']) ? $_REQUEST['start'] : 0; | |
459 $context['email_force'] = !empty($_POST['email_force']) ? 1 : 0; | |
460 $context['send_pm'] = !empty($_POST['send_pm']) ? 1 : 0; | |
461 $context['total_emails'] = !empty($_POST['total_emails']) ? (int) $_POST['total_emails'] : 0; | |
462 $context['max_id_member'] = !empty($_POST['max_id_member']) ? (int) $_POST['max_id_member'] : 0; | |
463 $context['send_html'] = !empty($_POST['send_html']) ? '1' : '0'; | |
464 $context['parse_html'] = !empty($_POST['parse_html']) ? '1' : '0'; | |
465 | |
466 // Create our main context. | |
467 $context['recipients'] = array( | |
468 'groups' => array(), | |
469 'exclude_groups' => array(), | |
470 'members' => array(), | |
471 'exclude_members' => array(), | |
472 'emails' => array(), | |
473 ); | |
474 | |
475 // Have we any excluded members? | |
476 if (!empty($_POST['exclude_members'])) | |
477 { | |
478 $members = explode(',', $_POST['exclude_members']); | |
479 foreach ($members as $member) | |
480 if ($member >= $context['start']) | |
481 $context['recipients']['exclude_members'][] = (int) $member; | |
482 } | |
483 | |
484 // What about members we *must* do? | |
485 if (!empty($_POST['members'])) | |
486 { | |
487 $members = explode(',', $_POST['members']); | |
488 foreach ($members as $member) | |
489 if ($member >= $context['start']) | |
490 $context['recipients']['members'][] = (int) $member; | |
491 } | |
492 // Cleaning groups is simple - although deal with both checkbox and commas. | |
493 if (!empty($_POST['groups'])) | |
494 { | |
495 if (is_array($_POST['groups'])) | |
496 { | |
497 foreach ($_POST['groups'] as $group => $dummy) | |
498 $context['recipients']['groups'][] = (int) $group; | |
499 } | |
500 else | |
501 { | |
502 $groups = explode(',', $_POST['groups']); | |
503 foreach ($groups as $group) | |
504 $context['recipients']['groups'][] = (int) $group; | |
505 } | |
506 } | |
507 // Same for excluded groups | |
508 if (!empty($_POST['exclude_groups'])) | |
509 { | |
510 if (is_array($_POST['exclude_groups'])) | |
511 { | |
512 foreach ($_POST['exclude_groups'] as $group => $dummy) | |
513 $context['recipients']['exclude_groups'][] = (int) $group; | |
514 } | |
515 else | |
516 { | |
517 $groups = explode(',', $_POST['exclude_groups']); | |
518 foreach ($groups as $group) | |
519 $context['recipients']['exclude_groups'][] = (int) $group; | |
520 } | |
521 } | |
522 // Finally - emails! | |
523 if (!empty($_POST['emails'])) | |
524 { | |
525 $addressed = array_unique(explode(';', strtr($_POST['emails'], array("\n" => ';', "\r" => ';', ',' => ';')))); | |
526 foreach ($addressed as $curmem) | |
527 { | |
528 $curmem = trim($curmem); | |
529 if ($curmem != '') | |
530 $context['recipients']['emails'][$curmem] = $curmem; | |
531 } | |
532 } | |
533 | |
534 // If we're only cleaning drop out here. | |
535 if ($clean_only) | |
536 return; | |
537 | |
538 require_once($sourcedir . '/Subs-Post.php'); | |
539 | |
540 // Save the message and its subject in $context | |
541 $context['subject'] = htmlspecialchars($_POST['subject']); | |
542 $context['message'] = htmlspecialchars($_POST['message']); | |
543 | |
544 // Prepare the message for sending it as HTML | |
545 if (!$context['send_pm'] && !empty($_POST['send_html'])) | |
546 { | |
547 // Prepare the message for HTML. | |
548 if (!empty($_POST['parse_html'])) | |
549 $_POST['message'] = str_replace(array("\n", ' '), array('<br />' . "\n", ' '), $_POST['message']); | |
550 | |
551 // This is here to prevent spam filters from tagging this as spam. | |
552 if (preg_match('~\<html~i', $_POST['message']) == 0) | |
553 { | |
554 if (preg_match('~\<body~i', $_POST['message']) == 0) | |
555 $_POST['message'] = '<html><head><title>' . $_POST['subject'] . '</title></head>' . "\n" . '<body>' . $_POST['message'] . '</body></html>'; | |
556 else | |
557 $_POST['message'] = '<html>' . $_POST['message'] . '</html>'; | |
558 } | |
559 } | |
560 | |
561 // Use the default time format. | |
562 $user_info['time_format'] = $modSettings['time_format']; | |
563 | |
564 $variables = array( | |
565 '{$board_url}', | |
566 '{$current_time}', | |
567 '{$latest_member.link}', | |
568 '{$latest_member.id}', | |
569 '{$latest_member.name}' | |
570 ); | |
571 | |
572 // We might need this in a bit | |
573 $cleanLatestMember = empty($_POST['send_html']) || $context['send_pm'] ? un_htmlspecialchars($modSettings['latestRealName']) : $modSettings['latestRealName']; | |
574 | |
575 // Replace in all the standard things. | |
576 $_POST['message'] = str_replace($variables, | |
577 array( | |
578 !empty($_POST['send_html']) ? '<a href="' . $scripturl . '">' . $scripturl . '</a>' : $scripturl, | |
579 timeformat(forum_time(), false), | |
580 !empty($_POST['send_html']) ? '<a href="' . $scripturl . '?action=profile;u=' . $modSettings['latestMember'] . '">' . $cleanLatestMember . '</a>' : ($context['send_pm'] ? '[url=' . $scripturl . '?action=profile;u=' . $modSettings['latestMember'] . ']' . $cleanLatestMember . '[/url]' : $cleanLatestMember), | |
581 $modSettings['latestMember'], | |
582 $cleanLatestMember | |
583 ), $_POST['message']); | |
584 $_POST['subject'] = str_replace($variables, | |
585 array( | |
586 $scripturl, | |
587 timeformat(forum_time(), false), | |
588 $modSettings['latestRealName'], | |
589 $modSettings['latestMember'], | |
590 $modSettings['latestRealName'] | |
591 ), $_POST['subject']); | |
592 | |
593 $from_member = array( | |
594 '{$member.email}', | |
595 '{$member.link}', | |
596 '{$member.id}', | |
597 '{$member.name}' | |
598 ); | |
599 | |
600 // If we still have emails, do them first! | |
601 $i = 0; | |
602 foreach ($context['recipients']['emails'] as $k => $email) | |
603 { | |
604 // Done as many as we can? | |
605 if ($i >= $num_at_once) | |
606 break; | |
607 | |
608 // Don't sent it twice! | |
609 unset($context['recipients']['emails'][$k]); | |
610 | |
611 // Dammit - can't PM emails! | |
612 if ($context['send_pm']) | |
613 continue; | |
614 | |
615 $to_member = array( | |
616 $email, | |
617 !empty($_POST['send_html']) ? '<a href="mailto:' . $email . '">' . $email . '</a>' : $email, | |
618 '??', | |
619 $email | |
620 ); | |
621 | |
622 sendmail($email, str_replace($from_member, $to_member, $_POST['subject']), str_replace($from_member, $to_member, $_POST['message']), null, null, !empty($_POST['send_html']), 5); | |
623 | |
624 // Done another... | |
625 $i++; | |
626 } | |
627 | |
628 // Got some more to send this batch? | |
629 $last_id_member = 0; | |
630 if ($i < $num_at_once) | |
631 { | |
632 // Need to build quite a query! | |
633 $sendQuery = '('; | |
634 $sendParams = array(); | |
635 if (!empty($context['recipients']['groups'])) | |
636 { | |
637 // Take the long route... | |
638 $queryBuild = array(); | |
639 foreach ($context['recipients']['groups'] as $group) | |
640 { | |
641 $sendParams['group_' . $group] = $group; | |
642 $queryBuild[] = 'mem.id_group = {int:group_' . $group . '}'; | |
643 if (!empty($group)) | |
644 { | |
645 $queryBuild[] = 'FIND_IN_SET({int:group_' . $group . '}, mem.additional_groups) != 0'; | |
646 $queryBuild[] = 'mem.id_post_group = {int:group_' . $group . '}'; | |
647 } | |
648 } | |
649 if (!empty($queryBuild)) | |
650 $sendQuery .= implode(' OR ', $queryBuild); | |
651 } | |
652 if (!empty($context['recipients']['members'])) | |
653 { | |
654 $sendQuery .= ($sendQuery == '(' ? '' : ' OR ') . 'mem.id_member IN ({array_int:members})'; | |
655 $sendParams['members'] = $context['recipients']['members']; | |
656 } | |
657 | |
658 $sendQuery .= ')'; | |
659 | |
660 // If we've not got a query then we must be done! | |
661 if ($sendQuery == '()') | |
662 redirectexit('action=admin'); | |
663 | |
664 // Anything to exclude? | |
665 if (!empty($context['recipients']['exclude_groups']) && in_array(0, $context['recipients']['exclude_groups'])) | |
666 $sendQuery .= ' AND mem.id_group != {int:regular_group}'; | |
667 if (!empty($context['recipients']['exclude_members'])) | |
668 { | |
669 $sendQuery .= ' AND mem.id_member NOT IN ({array_int:exclude_members})'; | |
670 $sendParams['exclude_members'] = $context['recipients']['exclude_members']; | |
671 } | |
672 | |
673 // Force them to have it? | |
674 if (empty($context['email_force'])) | |
675 $sendQuery .= ' AND mem.notify_announcements = {int:notify_announcements}'; | |
676 | |
677 // Get the smelly people - note we respect the id_member range as it gives us a quicker query. | |
678 $result = $smcFunc['db_query']('', ' | |
679 SELECT mem.id_member, mem.email_address, mem.real_name, mem.id_group, mem.additional_groups, mem.id_post_group | |
680 FROM {db_prefix}members AS mem | |
681 WHERE mem.id_member > {int:min_id_member} | |
682 AND mem.id_member < {int:max_id_member} | |
683 AND ' . $sendQuery . ' | |
684 AND mem.is_activated = {int:is_activated} | |
685 ORDER BY mem.id_member ASC | |
686 LIMIT {int:atonce}', | |
687 array_merge($sendParams, array( | |
688 'min_id_member' => $context['start'], | |
689 'max_id_member' => $context['start'] + $num_at_once - $i, | |
690 'atonce' => $num_at_once - $i, | |
691 'regular_group' => 0, | |
692 'notify_announcements' => 1, | |
693 'is_activated' => 1, | |
694 )) | |
695 ); | |
696 | |
697 while ($row = $smcFunc['db_fetch_assoc']($result)) | |
698 { | |
699 $last_id_member = $row['id_member']; | |
700 | |
701 // What groups are we looking at here? | |
702 if (empty($row['additional_groups'])) | |
703 $groups = array($row['id_group'], $row['id_post_group']); | |
704 else | |
705 $groups = array_merge( | |
706 array($row['id_group'], $row['id_post_group']), | |
707 explode(',', $row['additional_groups']) | |
708 ); | |
709 | |
710 // Excluded groups? | |
711 if (array_intersect($groups, $context['recipients']['exclude_groups'])) | |
712 continue; | |
713 | |
714 // We might need this | |
715 $cleanMemberName = empty($_POST['send_html']) || $context['send_pm'] ? un_htmlspecialchars($row['real_name']) : $row['real_name']; | |
716 | |
717 // Replace the member-dependant variables | |
718 $message = str_replace($from_member, | |
719 array( | |
720 $row['email_address'], | |
721 !empty($_POST['send_html']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $cleanMemberName . '</a>' : ($context['send_pm'] ? '[url=' . $scripturl . '?action=profile;u=' . $row['id_member'] . ']' . $cleanMemberName . '[/url]' : $cleanMemberName), | |
722 $row['id_member'], | |
723 $cleanMemberName, | |
724 ), $_POST['message']); | |
725 | |
726 $subject = str_replace($from_member, | |
727 array( | |
728 $row['email_address'], | |
729 $row['real_name'], | |
730 $row['id_member'], | |
731 $row['real_name'], | |
732 ), $_POST['subject']); | |
733 | |
734 // Send the actual email - or a PM! | |
735 if (!$context['send_pm']) | |
736 sendmail($row['email_address'], $subject, $message, null, null, !empty($_POST['send_html']), 5); | |
737 else | |
738 sendpm(array('to' => array($row['id_member']), 'bcc' => array()), $subject, $message); | |
739 } | |
740 $smcFunc['db_free_result']($result); | |
741 } | |
742 | |
743 // If used our batch assume we still have a member. | |
744 if ($i >= $num_at_once) | |
745 $last_id_member = $context['start']; | |
746 // Or we didn't have one in range? | |
747 elseif (empty($last_id_member) && $context['start'] + $num_at_once < $context['max_id_member']) | |
748 $last_id_member = $context['start'] + $num_at_once; | |
749 // If we have no id_member then we're done. | |
750 elseif (empty($last_id_member) && empty($context['recipients']['emails'])) | |
751 { | |
752 // Log this into the admin log. | |
753 logAction('newsletter', array(), 'admin'); | |
754 | |
755 redirectexit('action=admin'); | |
756 } | |
757 | |
758 $context['start'] = $last_id_member; | |
759 | |
760 // Working out progress is a black art of sorts. | |
761 $percentEmails = $context['total_emails'] == 0 ? 0 : ((count($context['recipients']['emails']) / $context['total_emails']) * ($context['total_emails'] / ($context['total_emails'] + $context['max_id_member']))); | |
762 $percentMembers = ($context['start'] / $context['max_id_member']) * ($context['max_id_member'] / ($context['total_emails'] + $context['max_id_member'])); | |
763 $context['percentage_done'] = round(($percentEmails + $percentMembers) * 100, 2); | |
764 | |
765 $context['page_title'] = $txt['admin_newsletters']; | |
766 $context['sub_template'] = 'email_members_send'; | |
767 } | |
768 | |
769 function ModifyNewsSettings($return_config = false) | |
770 { | |
771 global $context, $sourcedir, $modSettings, $txt, $scripturl; | |
772 | |
773 $config_vars = array( | |
774 array('title', 'settings'), | |
775 // Inline permissions. | |
776 array('permissions', 'edit_news', 'help' => ''), | |
777 array('permissions', 'send_mail'), | |
778 '', | |
779 // Just the remaining settings. | |
780 array('check', 'xmlnews_enable', 'onclick' => 'document.getElementById(\'xmlnews_maxlen\').disabled = !this.checked;'), | |
781 array('text', 'xmlnews_maxlen', 10), | |
782 ); | |
783 | |
784 if ($return_config) | |
785 return $config_vars; | |
786 | |
787 $context['page_title'] = $txt['admin_edit_news'] . ' - ' . $txt['settings']; | |
788 $context['sub_template'] = 'show_settings'; | |
789 | |
790 // Needed for the inline permission functions, and the settings template. | |
791 require_once($sourcedir . '/ManagePermissions.php'); | |
792 require_once($sourcedir . '/ManageServer.php'); | |
793 | |
794 // Wrap it all up nice and warm... | |
795 $context['post_url'] = $scripturl . '?action=admin;area=news;save;sa=settings'; | |
796 $context['permissions_excluded'] = array(-1); | |
797 | |
798 // Add some javascript at the bottom... | |
799 $context['settings_insert_below'] = ' | |
800 <script type="text/javascript"><!-- // --><![CDATA[ | |
801 document.getElementById("xmlnews_maxlen").disabled = !document.getElementById("xmlnews_enable").checked; | |
802 // ]]></script>'; | |
803 | |
804 // Saving the settings? | |
805 if (isset($_GET['save'])) | |
806 { | |
807 checkSession(); | |
808 | |
809 saveDBSettings($config_vars); | |
810 redirectexit('action=admin;area=news;sa=settings'); | |
811 } | |
812 | |
813 prepareDBSettingContext($config_vars); | |
814 } | |
815 | |
816 ?> |