Chris@76
|
1 <?php
|
Chris@76
|
2
|
Chris@76
|
3 /**
|
Chris@76
|
4 * Simple Machines Forum (SMF)
|
Chris@76
|
5 *
|
Chris@76
|
6 * @package SMF
|
Chris@76
|
7 * @author Simple Machines http://www.simplemachines.org
|
Chris@76
|
8 * @copyright 2011 Simple Machines
|
Chris@76
|
9 * @license http://www.simplemachines.org/about/smf/license.php BSD
|
Chris@76
|
10 *
|
Chris@76
|
11 * @version 2.0
|
Chris@76
|
12 */
|
Chris@76
|
13
|
Chris@76
|
14 if (!defined('SMF'))
|
Chris@76
|
15 die('Hacking attempt...');
|
Chris@76
|
16
|
Chris@76
|
17 /* This file is automatically called and handles all manner of scheduled things.
|
Chris@76
|
18
|
Chris@76
|
19 void AutoTask()
|
Chris@76
|
20 //!!!
|
Chris@76
|
21
|
Chris@76
|
22 void scheduled_approval_notification()
|
Chris@76
|
23 // !!!
|
Chris@76
|
24
|
Chris@76
|
25 void scheduled_daily_maintenance()
|
Chris@76
|
26 // !!!
|
Chris@76
|
27
|
Chris@76
|
28 void scheduled_auto_optimize()
|
Chris@76
|
29 // !!!
|
Chris@76
|
30
|
Chris@76
|
31 void scheduled_daily_digest()
|
Chris@76
|
32 // !!!
|
Chris@76
|
33
|
Chris@76
|
34 void scheduled_weekly_digest()
|
Chris@76
|
35 // !!!
|
Chris@76
|
36
|
Chris@76
|
37 void scheduled_paid_subscriptions()
|
Chris@76
|
38 // !!!
|
Chris@76
|
39
|
Chris@76
|
40 void ReduceMailQueue(int number, bool override)
|
Chris@76
|
41 // !!!
|
Chris@76
|
42
|
Chris@76
|
43 void CalculateNextTrigger(array tasks)
|
Chris@76
|
44 // !!!
|
Chris@76
|
45
|
Chris@76
|
46 int next_time(int regularity, char unit, int offset)
|
Chris@76
|
47 // !!!
|
Chris@76
|
48
|
Chris@76
|
49 void loadEssentialThemeData()
|
Chris@76
|
50 // !!!
|
Chris@76
|
51
|
Chris@76
|
52 void scheduled_fetchSMfiles()
|
Chris@76
|
53 // !!!
|
Chris@76
|
54
|
Chris@76
|
55 void scheduled_birthdayemails()
|
Chris@76
|
56 // !!!
|
Chris@76
|
57 */
|
Chris@76
|
58
|
Chris@76
|
59 // This function works out what to do!
|
Chris@76
|
60 function AutoTask()
|
Chris@76
|
61 {
|
Chris@76
|
62 global $time_start, $modSettings, $smcFunc;
|
Chris@76
|
63
|
Chris@76
|
64 // Special case for doing the mail queue.
|
Chris@76
|
65 if (isset($_GET['scheduled']) && $_GET['scheduled'] == 'mailq')
|
Chris@76
|
66 ReduceMailQueue();
|
Chris@76
|
67 else
|
Chris@76
|
68 {
|
Chris@76
|
69 // Select the next task to do.
|
Chris@76
|
70 $request = $smcFunc['db_query']('', '
|
Chris@76
|
71 SELECT id_task, task, next_time, time_offset, time_regularity, time_unit
|
Chris@76
|
72 FROM {db_prefix}scheduled_tasks
|
Chris@76
|
73 WHERE disabled = {int:not_disabled}
|
Chris@76
|
74 AND next_time <= {int:current_time}
|
Chris@76
|
75 ORDER BY next_time ASC
|
Chris@76
|
76 LIMIT 1',
|
Chris@76
|
77 array(
|
Chris@76
|
78 'not_disabled' => 0,
|
Chris@76
|
79 'current_time' => time(),
|
Chris@76
|
80 )
|
Chris@76
|
81 );
|
Chris@76
|
82 if ($smcFunc['db_num_rows']($request) != 0)
|
Chris@76
|
83 {
|
Chris@76
|
84 // The two important things really...
|
Chris@76
|
85 $row = $smcFunc['db_fetch_assoc']($request);
|
Chris@76
|
86
|
Chris@76
|
87 // When should this next be run?
|
Chris@76
|
88 $next_time = next_time($row['time_regularity'], $row['time_unit'], $row['time_offset']);
|
Chris@76
|
89
|
Chris@76
|
90 // How long in seconds it the gap?
|
Chris@76
|
91 $duration = $row['time_regularity'];
|
Chris@76
|
92 if ($row['time_unit'] == 'm')
|
Chris@76
|
93 $duration *= 60;
|
Chris@76
|
94 elseif ($row['time_unit'] == 'h')
|
Chris@76
|
95 $duration *= 3600;
|
Chris@76
|
96 elseif ($row['time_unit'] == 'd')
|
Chris@76
|
97 $duration *= 86400;
|
Chris@76
|
98 elseif ($row['time_unit'] == 'w')
|
Chris@76
|
99 $duration *= 604800;
|
Chris@76
|
100
|
Chris@76
|
101 // If we were really late running this task actually skip the next one.
|
Chris@76
|
102 if (time() + ($duration / 2) > $next_time)
|
Chris@76
|
103 $next_time += $duration;
|
Chris@76
|
104
|
Chris@76
|
105 // Update it now, so no others run this!
|
Chris@76
|
106 $smcFunc['db_query']('', '
|
Chris@76
|
107 UPDATE {db_prefix}scheduled_tasks
|
Chris@76
|
108 SET next_time = {int:next_time}
|
Chris@76
|
109 WHERE id_task = {int:id_task}
|
Chris@76
|
110 AND next_time = {int:current_next_time}',
|
Chris@76
|
111 array(
|
Chris@76
|
112 'next_time' => $next_time,
|
Chris@76
|
113 'id_task' => $row['id_task'],
|
Chris@76
|
114 'current_next_time' => $row['next_time'],
|
Chris@76
|
115 )
|
Chris@76
|
116 );
|
Chris@76
|
117 $affected_rows = $smcFunc['db_affected_rows']();
|
Chris@76
|
118
|
Chris@76
|
119 // The function must exist or we are wasting our time, plus do some timestamp checking, and database check!
|
Chris@76
|
120 if (function_exists('scheduled_' . $row['task']) && (!isset($_GET['ts']) || $_GET['ts'] == $row['next_time']) && $affected_rows)
|
Chris@76
|
121 {
|
Chris@76
|
122 ignore_user_abort(true);
|
Chris@76
|
123
|
Chris@76
|
124 // Do the task...
|
Chris@76
|
125 $completed = call_user_func('scheduled_' . $row['task']);
|
Chris@76
|
126
|
Chris@76
|
127 // Log that we did it ;)
|
Chris@76
|
128 if ($completed)
|
Chris@76
|
129 {
|
Chris@76
|
130 $total_time = round(array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)), 3);
|
Chris@76
|
131 $smcFunc['db_insert']('',
|
Chris@76
|
132 '{db_prefix}log_scheduled_tasks',
|
Chris@76
|
133 array(
|
Chris@76
|
134 'id_task' => 'int', 'time_run' => 'int', 'time_taken' => 'float',
|
Chris@76
|
135 ),
|
Chris@76
|
136 array(
|
Chris@76
|
137 $row['id_task'], time(), (int) $total_time,
|
Chris@76
|
138 ),
|
Chris@76
|
139 array()
|
Chris@76
|
140 );
|
Chris@76
|
141 }
|
Chris@76
|
142 }
|
Chris@76
|
143 }
|
Chris@76
|
144 $smcFunc['db_free_result']($request);
|
Chris@76
|
145
|
Chris@76
|
146 // Get the next timestamp right.
|
Chris@76
|
147 $request = $smcFunc['db_query']('', '
|
Chris@76
|
148 SELECT next_time
|
Chris@76
|
149 FROM {db_prefix}scheduled_tasks
|
Chris@76
|
150 WHERE disabled = {int:not_disabled}
|
Chris@76
|
151 ORDER BY next_time ASC
|
Chris@76
|
152 LIMIT 1',
|
Chris@76
|
153 array(
|
Chris@76
|
154 'not_disabled' => 0,
|
Chris@76
|
155 )
|
Chris@76
|
156 );
|
Chris@76
|
157 // No new task scheduled yet?
|
Chris@76
|
158 if ($smcFunc['db_num_rows']($request) === 0)
|
Chris@76
|
159 $nextEvent = time() + 86400;
|
Chris@76
|
160 else
|
Chris@76
|
161 list ($nextEvent) = $smcFunc['db_fetch_row']($request);
|
Chris@76
|
162 $smcFunc['db_free_result']($request);
|
Chris@76
|
163
|
Chris@76
|
164 updateSettings(array('next_task_time' => $nextEvent));
|
Chris@76
|
165 }
|
Chris@76
|
166
|
Chris@76
|
167 // Shall we return?
|
Chris@76
|
168 if (!isset($_GET['scheduled']))
|
Chris@76
|
169 return true;
|
Chris@76
|
170
|
Chris@76
|
171 // Finally, send some stuff...
|
Chris@76
|
172 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
Chris@76
|
173 header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
Chris@76
|
174 header('Content-Type: image/gif');
|
Chris@76
|
175 die("\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B");
|
Chris@76
|
176 }
|
Chris@76
|
177
|
Chris@76
|
178 // Function to sending out approval notices to moderators etc.
|
Chris@76
|
179 function scheduled_approval_notification()
|
Chris@76
|
180 {
|
Chris@76
|
181 global $scripturl, $modSettings, $mbname, $txt, $sourcedir, $smcFunc;
|
Chris@76
|
182
|
Chris@76
|
183 // Grab all the items awaiting approval and sort type then board - clear up any things that are no longer relevant.
|
Chris@76
|
184 $request = $smcFunc['db_query']('', '
|
Chris@76
|
185 SELECT aq.id_msg, aq.id_attach, aq.id_event, m.id_topic, m.id_board, m.subject, t.id_first_msg,
|
Chris@76
|
186 b.id_profile
|
Chris@76
|
187 FROM {db_prefix}approval_queue AS aq
|
Chris@76
|
188 INNER JOIN {db_prefix}messages AS m ON (m.id_msg = aq.id_msg)
|
Chris@76
|
189 INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
|
Chris@76
|
190 INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)',
|
Chris@76
|
191 array(
|
Chris@76
|
192 )
|
Chris@76
|
193 );
|
Chris@76
|
194 $notices = array();
|
Chris@76
|
195 $profiles = array();
|
Chris@76
|
196 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
197 {
|
Chris@76
|
198 // If this is no longer around we'll ignore it.
|
Chris@76
|
199 if (empty($row['id_topic']))
|
Chris@76
|
200 continue;
|
Chris@76
|
201
|
Chris@76
|
202 // What type is it?
|
Chris@76
|
203 if ($row['id_first_msg'] && $row['id_first_msg'] == $row['id_msg'])
|
Chris@76
|
204 $type = 'topic';
|
Chris@76
|
205 elseif ($row['id_attach'])
|
Chris@76
|
206 $type = 'attach';
|
Chris@76
|
207 else
|
Chris@76
|
208 $type = 'msg';
|
Chris@76
|
209
|
Chris@76
|
210 // Add it to the array otherwise.
|
Chris@76
|
211 $notices[$row['id_board']][$type][] = array(
|
Chris@76
|
212 'subject' => $row['subject'],
|
Chris@76
|
213 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'],
|
Chris@76
|
214 );
|
Chris@76
|
215
|
Chris@76
|
216 // Store the profile for a bit later.
|
Chris@76
|
217 $profiles[$row['id_board']] = $row['id_profile'];
|
Chris@76
|
218 }
|
Chris@76
|
219 $smcFunc['db_free_result']($request);
|
Chris@76
|
220
|
Chris@76
|
221 // Delete it all!
|
Chris@76
|
222 $smcFunc['db_query']('', '
|
Chris@76
|
223 DELETE FROM {db_prefix}approval_queue',
|
Chris@76
|
224 array(
|
Chris@76
|
225 )
|
Chris@76
|
226 );
|
Chris@76
|
227
|
Chris@76
|
228 // If nothing quit now.
|
Chris@76
|
229 if (empty($notices))
|
Chris@76
|
230 return true;
|
Chris@76
|
231
|
Chris@76
|
232 // Now we need to think about finding out *who* can approve - this is hard!
|
Chris@76
|
233
|
Chris@76
|
234 // First off, get all the groups with this permission and sort by board.
|
Chris@76
|
235 $request = $smcFunc['db_query']('', '
|
Chris@76
|
236 SELECT id_group, id_profile, add_deny
|
Chris@76
|
237 FROM {db_prefix}board_permissions
|
Chris@76
|
238 WHERE permission = {string:approve_posts}
|
Chris@76
|
239 AND id_profile IN ({array_int:profile_list})',
|
Chris@76
|
240 array(
|
Chris@76
|
241 'profile_list' => $profiles,
|
Chris@76
|
242 'approve_posts' => 'approve_posts',
|
Chris@76
|
243 )
|
Chris@76
|
244 );
|
Chris@76
|
245 $perms = array();
|
Chris@76
|
246 $addGroups = array(1);
|
Chris@76
|
247 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
248 {
|
Chris@76
|
249 // Sorry guys, but we have to ignore guests AND members - it would be too many otherwise.
|
Chris@76
|
250 if ($row['id_group'] < 2)
|
Chris@76
|
251 continue;
|
Chris@76
|
252
|
Chris@76
|
253 $perms[$row['id_profile']][$row['add_deny'] ? 'add' : 'deny'][] = $row['id_group'];
|
Chris@76
|
254
|
Chris@76
|
255 // Anyone who can access has to be considered.
|
Chris@76
|
256 if ($row['add_deny'])
|
Chris@76
|
257 $addGroups[] = $row['id_group'];
|
Chris@76
|
258 }
|
Chris@76
|
259 $smcFunc['db_free_result']($request);
|
Chris@76
|
260
|
Chris@76
|
261 // Grab the moderators if they have permission!
|
Chris@76
|
262 $mods = array();
|
Chris@76
|
263 $members = array();
|
Chris@76
|
264 if (in_array(2, $addGroups))
|
Chris@76
|
265 {
|
Chris@76
|
266 $request = $smcFunc['db_query']('', '
|
Chris@76
|
267 SELECT id_member, id_board
|
Chris@76
|
268 FROM {db_prefix}moderators',
|
Chris@76
|
269 array(
|
Chris@76
|
270 )
|
Chris@76
|
271 );
|
Chris@76
|
272 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
273 {
|
Chris@76
|
274 $mods[$row['id_member']][$row['id_board']] = true;
|
Chris@76
|
275 // Make sure they get included in the big loop.
|
Chris@76
|
276 $members[] = $row['id_member'];
|
Chris@76
|
277 }
|
Chris@76
|
278 $smcFunc['db_free_result']($request);
|
Chris@76
|
279 }
|
Chris@76
|
280
|
Chris@76
|
281 // Come along one and all... until we reject you ;)
|
Chris@76
|
282 $request = $smcFunc['db_query']('', '
|
Chris@76
|
283 SELECT id_member, real_name, email_address, lngfile, id_group, additional_groups, mod_prefs
|
Chris@76
|
284 FROM {db_prefix}members
|
Chris@76
|
285 WHERE id_group IN ({array_int:additional_group_list})
|
Chris@76
|
286 OR FIND_IN_SET({raw:additional_group_list_implode}, additional_groups) != 0' . (empty($members) ? '' : '
|
Chris@76
|
287 OR id_member IN ({array_int:member_list})') . '
|
Chris@76
|
288 ORDER BY lngfile',
|
Chris@76
|
289 array(
|
Chris@76
|
290 'additional_group_list' => $addGroups,
|
Chris@76
|
291 'member_list' => $members,
|
Chris@76
|
292 'additional_group_list_implode' => implode(', additional_groups) != 0 OR FIND_IN_SET(', $addGroups),
|
Chris@76
|
293 )
|
Chris@76
|
294 );
|
Chris@76
|
295 $members = array();
|
Chris@76
|
296 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
297 {
|
Chris@76
|
298 // Check whether they are interested.
|
Chris@76
|
299 if (!empty($row['mod_prefs']))
|
Chris@76
|
300 {
|
Chris@76
|
301 list(,, $pref_binary) = explode('|', $row['mod_prefs']);
|
Chris@76
|
302 if (!($pref_binary & 4))
|
Chris@76
|
303 continue;
|
Chris@76
|
304 }
|
Chris@76
|
305
|
Chris@76
|
306 $members[$row['id_member']] = array(
|
Chris@76
|
307 'id' => $row['id_member'],
|
Chris@76
|
308 'groups' => array_merge(explode(',', $row['additional_groups']), array($row['id_group'])),
|
Chris@76
|
309 'language' => $row['lngfile'],
|
Chris@76
|
310 'email' => $row['email_address'],
|
Chris@76
|
311 'name' => $row['real_name'],
|
Chris@76
|
312 );
|
Chris@76
|
313 }
|
Chris@76
|
314 $smcFunc['db_free_result']($request);
|
Chris@76
|
315
|
Chris@76
|
316 // Get the mailing stuff.
|
Chris@76
|
317 require_once($sourcedir . '/Subs-Post.php');
|
Chris@76
|
318 // Need the below for loadLanguage to work!
|
Chris@76
|
319 loadEssentialThemeData();
|
Chris@76
|
320
|
Chris@76
|
321 // Finally, loop through each member, work out what they can do, and send it.
|
Chris@76
|
322 foreach ($members as $id => $member)
|
Chris@76
|
323 {
|
Chris@76
|
324 $emailbody = '';
|
Chris@76
|
325
|
Chris@76
|
326 // Load the language file as required.
|
Chris@76
|
327 if (empty($current_language) || $current_language != $member['language'])
|
Chris@76
|
328 $current_language = loadLanguage('EmailTemplates', $member['language'], false);
|
Chris@76
|
329
|
Chris@76
|
330 // Loop through each notice...
|
Chris@76
|
331 foreach ($notices as $board => $notice)
|
Chris@76
|
332 {
|
Chris@76
|
333 $access = false;
|
Chris@76
|
334
|
Chris@76
|
335 // Can they mod in this board?
|
Chris@76
|
336 if (isset($mods[$id][$board]))
|
Chris@76
|
337 $access = true;
|
Chris@76
|
338
|
Chris@76
|
339 // Do the group check...
|
Chris@76
|
340 if (!$access && isset($perms[$profiles[$board]]['add']))
|
Chris@76
|
341 {
|
Chris@76
|
342 // They can access?!
|
Chris@76
|
343 if (array_intersect($perms[$profiles[$board]]['add'], $member['groups']))
|
Chris@76
|
344 $access = true;
|
Chris@76
|
345
|
Chris@76
|
346 // If they have deny rights don't consider them!
|
Chris@76
|
347 if (isset($perms[$profiles[$board]]['deny']))
|
Chris@76
|
348 if (array_intersect($perms[$profiles[$board]]['deny'], $member['groups']))
|
Chris@76
|
349 $access = false;
|
Chris@76
|
350 }
|
Chris@76
|
351
|
Chris@76
|
352 // Finally, fix it for admins!
|
Chris@76
|
353 if (in_array(1, $member['groups']))
|
Chris@76
|
354 $access = true;
|
Chris@76
|
355
|
Chris@76
|
356 // If they can't access it then give it a break!
|
Chris@76
|
357 if (!$access)
|
Chris@76
|
358 continue;
|
Chris@76
|
359
|
Chris@76
|
360 foreach ($notice as $type => $items)
|
Chris@76
|
361 {
|
Chris@76
|
362 // Build up the top of this section.
|
Chris@76
|
363 $emailbody .= $txt['scheduled_approval_email_' . $type] . "\n" .
|
Chris@76
|
364 '------------------------------------------------------' . "\n";
|
Chris@76
|
365
|
Chris@76
|
366 foreach ($items as $item)
|
Chris@76
|
367 $emailbody .= $item['subject'] . ' - ' . $item['href'] . "\n";
|
Chris@76
|
368
|
Chris@76
|
369 $emailbody .= "\n";
|
Chris@76
|
370 }
|
Chris@76
|
371 }
|
Chris@76
|
372
|
Chris@76
|
373 if ($emailbody == '')
|
Chris@76
|
374 continue;
|
Chris@76
|
375
|
Chris@76
|
376 $replacements = array(
|
Chris@76
|
377 'REALNAME' => $member['name'],
|
Chris@76
|
378 'BODY' => $emailbody,
|
Chris@76
|
379 );
|
Chris@76
|
380
|
Chris@76
|
381 $emaildata = loadEmailTemplate('scheduled_approval', $replacements, $current_language);
|
Chris@76
|
382
|
Chris@76
|
383 // Send the actual email.
|
Chris@76
|
384 sendmail($member['email'], $emaildata['subject'], $emaildata['body'], null, null, false, 2);
|
Chris@76
|
385 }
|
Chris@76
|
386
|
Chris@76
|
387 // All went well!
|
Chris@76
|
388 return true;
|
Chris@76
|
389 }
|
Chris@76
|
390
|
Chris@76
|
391 // Do some daily cleaning up.
|
Chris@76
|
392 function scheduled_daily_maintenance()
|
Chris@76
|
393 {
|
Chris@76
|
394 global $smcFunc, $modSettings, $sourcedir, $db_type;
|
Chris@76
|
395
|
Chris@76
|
396 // First clean out the cache.
|
Chris@76
|
397 clean_cache();
|
Chris@76
|
398
|
Chris@76
|
399 // If warning decrement is enabled and we have people who have not had a new warning in 24 hours, lower their warning level.
|
Chris@76
|
400 list (, , $modSettings['warning_decrement']) = explode(',', $modSettings['warning_settings']);
|
Chris@76
|
401 if ($modSettings['warning_decrement'])
|
Chris@76
|
402 {
|
Chris@76
|
403 // Find every member who has a warning level...
|
Chris@76
|
404 $request = $smcFunc['db_query']('', '
|
Chris@76
|
405 SELECT id_member, warning
|
Chris@76
|
406 FROM {db_prefix}members
|
Chris@76
|
407 WHERE warning > {int:no_warning}',
|
Chris@76
|
408 array(
|
Chris@76
|
409 'no_warning' => 0,
|
Chris@76
|
410 )
|
Chris@76
|
411 );
|
Chris@76
|
412 $members = array();
|
Chris@76
|
413 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
414 $members[$row['id_member']] = $row['warning'];
|
Chris@76
|
415 $smcFunc['db_free_result']($request);
|
Chris@76
|
416
|
Chris@76
|
417 // Have some members to check?
|
Chris@76
|
418 if (!empty($members))
|
Chris@76
|
419 {
|
Chris@76
|
420 // Find out when they were last warned.
|
Chris@76
|
421 $request = $smcFunc['db_query']('', '
|
Chris@76
|
422 SELECT id_recipient, MAX(log_time) AS last_warning
|
Chris@76
|
423 FROM {db_prefix}log_comments
|
Chris@76
|
424 WHERE id_recipient IN ({array_int:member_list})
|
Chris@76
|
425 AND comment_type = {string:warning}
|
Chris@76
|
426 GROUP BY id_recipient',
|
Chris@76
|
427 array(
|
Chris@76
|
428 'member_list' => array_keys($members),
|
Chris@76
|
429 'warning' => 'warning',
|
Chris@76
|
430 )
|
Chris@76
|
431 );
|
Chris@76
|
432 $member_changes = array();
|
Chris@76
|
433 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
434 {
|
Chris@76
|
435 // More than 24 hours ago?
|
Chris@76
|
436 if ($row['last_warning'] <= time() - 86400)
|
Chris@76
|
437 $member_changes[] = array(
|
Chris@76
|
438 'id' => $row['id_recipient'],
|
Chris@76
|
439 'warning' => $members[$row['id_recipient']] >= $modSettings['warning_decrement'] ? $members[$row['id_recipient']] - $modSettings['warning_decrement'] : 0,
|
Chris@76
|
440 );
|
Chris@76
|
441 }
|
Chris@76
|
442 $smcFunc['db_free_result']($request);
|
Chris@76
|
443
|
Chris@76
|
444 // Have some members to change?
|
Chris@76
|
445 if (!empty($member_changes))
|
Chris@76
|
446 foreach ($member_changes as $change)
|
Chris@76
|
447 $smcFunc['db_query']('', '
|
Chris@76
|
448 UPDATE {db_prefix}members
|
Chris@76
|
449 SET warning = {int:warning}
|
Chris@76
|
450 WHERE id_member = {int:id_member}',
|
Chris@76
|
451 array(
|
Chris@76
|
452 'warning' => $change['warning'],
|
Chris@76
|
453 'id_member' => $change['id'],
|
Chris@76
|
454 )
|
Chris@76
|
455 );
|
Chris@76
|
456 }
|
Chris@76
|
457 }
|
Chris@76
|
458
|
Chris@76
|
459 // Do any spider stuff.
|
Chris@76
|
460 if (!empty($modSettings['spider_mode']) && $modSettings['spider_mode'] > 1)
|
Chris@76
|
461 {
|
Chris@76
|
462 require_once($sourcedir . '/ManageSearchEngines.php');
|
Chris@76
|
463 consolidateSpiderStats();
|
Chris@76
|
464 }
|
Chris@76
|
465
|
Chris@76
|
466 // Check the database version - for some buggy MySQL version.
|
Chris@76
|
467 $server_version = $smcFunc['db_server_info']();
|
Chris@76
|
468 if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
|
Chris@76
|
469 updateSettings(array('db_mysql_group_by_fix' => '1'));
|
Chris@76
|
470 elseif (!empty($modSettings['db_mysql_group_by_fix']))
|
Chris@76
|
471 $smcFunc['db_query']('', '
|
Chris@76
|
472 DELETE FROM {db_prefix}settings
|
Chris@76
|
473 WHERE variable = {string:mysql_fix}',
|
Chris@76
|
474 array(
|
Chris@76
|
475 'mysql_fix' => 'db_mysql_group_by_fix',
|
Chris@76
|
476 )
|
Chris@76
|
477 );
|
Chris@76
|
478
|
Chris@76
|
479 // Regenerate the Diffie-Hellman keys if OpenID is enabled.
|
Chris@76
|
480 if (!empty($modSettings['enableOpenID']))
|
Chris@76
|
481 {
|
Chris@76
|
482 require_once($sourcedir . '/Subs-OpenID.php');
|
Chris@76
|
483 smf_openID_setup_DH(true);
|
Chris@76
|
484 }
|
Chris@76
|
485 elseif (!empty($modSettings['dh_keys']))
|
Chris@76
|
486 $smcFunc['db_query']('', '
|
Chris@76
|
487 DELETE FROM {db_prefix}settings
|
Chris@76
|
488 WHERE variable = {string:dh_keys}',
|
Chris@76
|
489 array(
|
Chris@76
|
490 'dh_keys' => 'dh_keys',
|
Chris@76
|
491 )
|
Chris@76
|
492 );
|
Chris@76
|
493
|
Chris@76
|
494 // Log we've done it...
|
Chris@76
|
495 return true;
|
Chris@76
|
496 }
|
Chris@76
|
497
|
Chris@76
|
498 // Auto optimize the database?
|
Chris@76
|
499 function scheduled_auto_optimize()
|
Chris@76
|
500 {
|
Chris@76
|
501 global $modSettings, $smcFunc, $db_prefix, $db_type;
|
Chris@76
|
502
|
Chris@76
|
503 // By default do it now!
|
Chris@76
|
504 $delay = false;
|
Chris@76
|
505
|
Chris@76
|
506 // As a kind of hack, if the server load is too great delay, but only by a bit!
|
Chris@76
|
507 if (!empty($modSettings['load_average']) && !empty($modSettings['loadavg_auto_opt']) && $modSettings['load_average'] >= $modSettings['loadavg_auto_opt'])
|
Chris@76
|
508 $delay = true;
|
Chris@76
|
509
|
Chris@76
|
510 // Otherwise are we restricting the number of people online for this?
|
Chris@76
|
511 if (!empty($modSettings['autoOptMaxOnline']))
|
Chris@76
|
512 {
|
Chris@76
|
513 $request = $smcFunc['db_query']('', '
|
Chris@76
|
514 SELECT COUNT(*)
|
Chris@76
|
515 FROM {db_prefix}log_online',
|
Chris@76
|
516 array(
|
Chris@76
|
517 )
|
Chris@76
|
518 );
|
Chris@76
|
519 list ($dont_do_it) = $smcFunc['db_fetch_row']($request);
|
Chris@76
|
520 $smcFunc['db_free_result']($request);
|
Chris@76
|
521
|
Chris@76
|
522 if ($dont_do_it > $modSettings['autoOptMaxOnline'])
|
Chris@76
|
523 $delay = true;
|
Chris@76
|
524 }
|
Chris@76
|
525
|
Chris@76
|
526 // If we are gonna delay, do so now!
|
Chris@76
|
527 if ($delay)
|
Chris@76
|
528 return false;
|
Chris@76
|
529
|
Chris@76
|
530 db_extend();
|
Chris@76
|
531
|
Chris@76
|
532 // Get all the tables.
|
Chris@76
|
533 $tables = $smcFunc['db_list_tables'](false, $db_prefix . '%');
|
Chris@76
|
534
|
Chris@76
|
535 // Actually do the optimisation.
|
Chris@76
|
536 if ($db_type == 'sqlite')
|
Chris@76
|
537 $smcFunc['db_optimize_table']($table[0]);
|
Chris@76
|
538 else
|
Chris@76
|
539 foreach ($tables as $table)
|
Chris@76
|
540 $smcFunc['db_optimize_table']($table);
|
Chris@76
|
541
|
Chris@76
|
542 // Return for the log...
|
Chris@76
|
543 return true;
|
Chris@76
|
544 }
|
Chris@76
|
545
|
Chris@76
|
546 // Send out a daily email of all subscribed topics.
|
Chris@76
|
547 function scheduled_daily_digest()
|
Chris@76
|
548 {
|
Chris@76
|
549 global $is_weekly, $txt, $mbname, $scripturl, $sourcedir, $smcFunc, $context, $modSettings;
|
Chris@76
|
550
|
Chris@76
|
551 // We'll want this...
|
Chris@76
|
552 require_once($sourcedir . '/Subs-Post.php');
|
Chris@76
|
553 loadEssentialThemeData();
|
Chris@76
|
554
|
Chris@76
|
555 $is_weekly = !empty($is_weekly) ? 1 : 0;
|
Chris@76
|
556
|
Chris@76
|
557 // Right - get all the notification data FIRST.
|
Chris@76
|
558 $request = $smcFunc['db_query']('', '
|
Chris@76
|
559 SELECT ln.id_topic, COALESCE(t.id_board, ln.id_board) AS id_board, mem.email_address, mem.member_name, mem.notify_types,
|
Chris@76
|
560 mem.lngfile, mem.id_member
|
Chris@76
|
561 FROM {db_prefix}log_notify AS ln
|
Chris@76
|
562 INNER JOIN {db_prefix}members AS mem ON (mem.id_member = ln.id_member)
|
Chris@76
|
563 LEFT JOIN {db_prefix}topics AS t ON (ln.id_topic != {int:empty_topic} AND t.id_topic = ln.id_topic)
|
Chris@76
|
564 WHERE mem.notify_regularity = {int:notify_regularity}
|
Chris@76
|
565 AND mem.is_activated = {int:is_activated}',
|
Chris@76
|
566 array(
|
Chris@76
|
567 'empty_topic' => 0,
|
Chris@76
|
568 'notify_regularity' => $is_weekly ? '3' : '2',
|
Chris@76
|
569 'is_activated' => 1,
|
Chris@76
|
570 )
|
Chris@76
|
571 );
|
Chris@76
|
572 $members = array();
|
Chris@76
|
573 $langs = array();
|
Chris@76
|
574 $notify = array();
|
Chris@76
|
575 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
576 {
|
Chris@76
|
577 if (!isset($members[$row['id_member']]))
|
Chris@76
|
578 {
|
Chris@76
|
579 $members[$row['id_member']] = array(
|
Chris@76
|
580 'email' => $row['email_address'],
|
Chris@76
|
581 'name' => $row['member_name'],
|
Chris@76
|
582 'id' => $row['id_member'],
|
Chris@76
|
583 'notifyMod' => $row['notify_types'] < 3 ? true : false,
|
Chris@76
|
584 'lang' => $row['lngfile'],
|
Chris@76
|
585 );
|
Chris@76
|
586 $langs[$row['lngfile']] = $row['lngfile'];
|
Chris@76
|
587 }
|
Chris@76
|
588
|
Chris@76
|
589 // Store this useful data!
|
Chris@76
|
590 $boards[$row['id_board']] = $row['id_board'];
|
Chris@76
|
591 if ($row['id_topic'])
|
Chris@76
|
592 $notify['topics'][$row['id_topic']][] = $row['id_member'];
|
Chris@76
|
593 else
|
Chris@76
|
594 $notify['boards'][$row['id_board']][] = $row['id_member'];
|
Chris@76
|
595 }
|
Chris@76
|
596 $smcFunc['db_free_result']($request);
|
Chris@76
|
597
|
Chris@76
|
598 if (empty($boards))
|
Chris@76
|
599 return true;
|
Chris@76
|
600
|
Chris@76
|
601 // Just get the board names.
|
Chris@76
|
602 $request = $smcFunc['db_query']('', '
|
Chris@76
|
603 SELECT id_board, name
|
Chris@76
|
604 FROM {db_prefix}boards
|
Chris@76
|
605 WHERE id_board IN ({array_int:board_list})',
|
Chris@76
|
606 array(
|
Chris@76
|
607 'board_list' => $boards,
|
Chris@76
|
608 )
|
Chris@76
|
609 );
|
Chris@76
|
610 $boards = array();
|
Chris@76
|
611 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
612 $boards[$row['id_board']] = $row['name'];
|
Chris@76
|
613 $smcFunc['db_free_result']($request);
|
Chris@76
|
614
|
Chris@76
|
615 if (empty($boards))
|
Chris@76
|
616 return true;
|
Chris@76
|
617
|
Chris@76
|
618 // Get the actual topics...
|
Chris@76
|
619 $request = $smcFunc['db_query']('', '
|
Chris@76
|
620 SELECT ld.note_type, t.id_topic, t.id_board, t.id_member_started, m.id_msg, m.subject,
|
Chris@76
|
621 b.name AS board_name
|
Chris@76
|
622 FROM {db_prefix}log_digest AS ld
|
Chris@76
|
623 INNER JOIN {db_prefix}topics AS t ON (t.id_topic = ld.id_topic
|
Chris@76
|
624 AND t.id_board IN ({array_int:board_list}))
|
Chris@76
|
625 INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
|
Chris@76
|
626 INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
|
Chris@76
|
627 WHERE ' . ($is_weekly ? 'ld.daily != {int:daily_value}' : 'ld.daily IN (0, 2)'),
|
Chris@76
|
628 array(
|
Chris@76
|
629 'board_list' => array_keys($boards),
|
Chris@76
|
630 'daily_value' => 2,
|
Chris@76
|
631 )
|
Chris@76
|
632 );
|
Chris@76
|
633 $types = array();
|
Chris@76
|
634 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
635 {
|
Chris@76
|
636 if (!isset($types[$row['note_type']][$row['id_board']]))
|
Chris@76
|
637 $types[$row['note_type']][$row['id_board']] = array(
|
Chris@76
|
638 'lines' => array(),
|
Chris@76
|
639 'name' => $row['board_name'],
|
Chris@76
|
640 'id' => $row['id_board'],
|
Chris@76
|
641 );
|
Chris@76
|
642
|
Chris@76
|
643 if ($row['note_type'] == 'reply')
|
Chris@76
|
644 {
|
Chris@76
|
645 if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
|
Chris@76
|
646 $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++;
|
Chris@76
|
647 else
|
Chris@76
|
648 $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
|
Chris@76
|
649 'id' => $row['id_topic'],
|
Chris@76
|
650 'subject' => un_htmlspecialchars($row['subject']),
|
Chris@76
|
651 'count' => 1,
|
Chris@76
|
652 );
|
Chris@76
|
653 }
|
Chris@76
|
654 elseif ($row['note_type'] == 'topic')
|
Chris@76
|
655 {
|
Chris@76
|
656 if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
|
Chris@76
|
657 $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
|
Chris@76
|
658 'id' => $row['id_topic'],
|
Chris@76
|
659 'subject' => un_htmlspecialchars($row['subject']),
|
Chris@76
|
660 );
|
Chris@76
|
661 }
|
Chris@76
|
662 else
|
Chris@76
|
663 {
|
Chris@76
|
664 if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
|
Chris@76
|
665 $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
|
Chris@76
|
666 'id' => $row['id_topic'],
|
Chris@76
|
667 'subject' => un_htmlspecialchars($row['subject']),
|
Chris@76
|
668 'starter' => $row['id_member_started'],
|
Chris@76
|
669 );
|
Chris@76
|
670 }
|
Chris@76
|
671
|
Chris@76
|
672 $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array();
|
Chris@76
|
673 if (!empty($notify['topics'][$row['id_topic']]))
|
Chris@76
|
674 $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['topics'][$row['id_topic']]);
|
Chris@76
|
675 if (!empty($notify['boards'][$row['id_board']]))
|
Chris@76
|
676 $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['boards'][$row['id_board']]);
|
Chris@76
|
677 }
|
Chris@76
|
678 $smcFunc['db_free_result']($request);
|
Chris@76
|
679
|
Chris@76
|
680 if (empty($types))
|
Chris@76
|
681 return true;
|
Chris@76
|
682
|
Chris@76
|
683 // Let's load all the languages into a cache thingy.
|
Chris@76
|
684 $langtxt = array();
|
Chris@76
|
685 foreach ($langs as $lang)
|
Chris@76
|
686 {
|
Chris@76
|
687 loadLanguage('Post', $lang);
|
Chris@76
|
688 loadLanguage('index', $lang);
|
Chris@76
|
689 loadLanguage('EmailTemplates', $lang);
|
Chris@76
|
690 $langtxt[$lang] = array(
|
Chris@76
|
691 'subject' => $txt['digest_subject_' . ($is_weekly ? 'weekly' : 'daily')],
|
Chris@76
|
692 'char_set' => $txt['lang_character_set'],
|
Chris@76
|
693 'intro' => sprintf($txt['digest_intro_' . ($is_weekly ? 'weekly' : 'daily')], $mbname),
|
Chris@76
|
694 'new_topics' => $txt['digest_new_topics'],
|
Chris@76
|
695 'topic_lines' => $txt['digest_new_topics_line'],
|
Chris@76
|
696 'new_replies' => $txt['digest_new_replies'],
|
Chris@76
|
697 'mod_actions' => $txt['digest_mod_actions'],
|
Chris@76
|
698 'replies_one' => $txt['digest_new_replies_one'],
|
Chris@76
|
699 'replies_many' => $txt['digest_new_replies_many'],
|
Chris@76
|
700 'sticky' => $txt['digest_mod_act_sticky'],
|
Chris@76
|
701 'lock' => $txt['digest_mod_act_lock'],
|
Chris@76
|
702 'unlock' => $txt['digest_mod_act_unlock'],
|
Chris@76
|
703 'remove' => $txt['digest_mod_act_remove'],
|
Chris@76
|
704 'move' => $txt['digest_mod_act_move'],
|
Chris@76
|
705 'merge' => $txt['digest_mod_act_merge'],
|
Chris@76
|
706 'split' => $txt['digest_mod_act_split'],
|
Chris@76
|
707 'bye' => $txt['regards_team'],
|
Chris@76
|
708 );
|
Chris@76
|
709 }
|
Chris@76
|
710
|
Chris@76
|
711 // Right - send out the silly things - this will take quite some space!
|
Chris@76
|
712 $emails = array();
|
Chris@76
|
713 foreach ($members as $mid => $member)
|
Chris@76
|
714 {
|
Chris@76
|
715 // Right character set!
|
Chris@76
|
716 $context['character_set'] = empty($modSettings['global_character_set']) ? $langtxt[$lang]['char_set'] : $modSettings['global_character_set'];
|
Chris@76
|
717
|
Chris@76
|
718 // Do the start stuff!
|
Chris@76
|
719 $email = array(
|
Chris@76
|
720 'subject' => $mbname . ' - ' . $langtxt[$lang]['subject'],
|
Chris@76
|
721 'body' => $member['name'] . ',' . "\n\n" . $langtxt[$lang]['intro'] . "\n" . $scripturl . '?action=profile;area=notification;u=' . $member['id'] . "\n",
|
Chris@76
|
722 'email' => $member['email'],
|
Chris@76
|
723 );
|
Chris@76
|
724
|
Chris@76
|
725 // All new topics?
|
Chris@76
|
726 if (isset($types['topic']))
|
Chris@76
|
727 {
|
Chris@76
|
728 $titled = false;
|
Chris@76
|
729 foreach ($types['topic'] as $id => $board)
|
Chris@76
|
730 foreach ($board['lines'] as $topic)
|
Chris@76
|
731 if (in_array($mid, $topic['members']))
|
Chris@76
|
732 {
|
Chris@76
|
733 if (!$titled)
|
Chris@76
|
734 {
|
Chris@76
|
735 $email['body'] .= "\n" . $langtxt[$lang]['new_topics'] . ':' . "\n" . '-----------------------------------------------';
|
Chris@76
|
736 $titled = true;
|
Chris@76
|
737 }
|
Chris@76
|
738 $email['body'] .= "\n" . sprintf($langtxt[$lang]['topic_lines'], $topic['subject'], $board['name']);
|
Chris@76
|
739 }
|
Chris@76
|
740 if ($titled)
|
Chris@76
|
741 $email['body'] .= "\n";
|
Chris@76
|
742 }
|
Chris@76
|
743
|
Chris@76
|
744 // What about replies?
|
Chris@76
|
745 if (isset($types['reply']))
|
Chris@76
|
746 {
|
Chris@76
|
747 $titled = false;
|
Chris@76
|
748 foreach ($types['reply'] as $id => $board)
|
Chris@76
|
749 foreach ($board['lines'] as $topic)
|
Chris@76
|
750 if (in_array($mid, $topic['members']))
|
Chris@76
|
751 {
|
Chris@76
|
752 if (!$titled)
|
Chris@76
|
753 {
|
Chris@76
|
754 $email['body'] .= "\n" . $langtxt[$lang]['new_replies'] . ':' . "\n" . '-----------------------------------------------';
|
Chris@76
|
755 $titled = true;
|
Chris@76
|
756 }
|
Chris@76
|
757 $email['body'] .= "\n" . ($topic['count'] == 1 ? sprintf($langtxt[$lang]['replies_one'], $topic['subject']) : sprintf($langtxt[$lang]['replies_many'], $topic['count'], $topic['subject']));
|
Chris@76
|
758 }
|
Chris@76
|
759
|
Chris@76
|
760 if ($titled)
|
Chris@76
|
761 $email['body'] .= "\n";
|
Chris@76
|
762 }
|
Chris@76
|
763
|
Chris@76
|
764 // Finally, moderation actions!
|
Chris@76
|
765 $titled = false;
|
Chris@76
|
766 foreach ($types as $note_type => $type)
|
Chris@76
|
767 {
|
Chris@76
|
768 if ($note_type == 'topic' || $note_type == 'reply')
|
Chris@76
|
769 continue;
|
Chris@76
|
770
|
Chris@76
|
771 foreach ($type as $id => $board)
|
Chris@76
|
772 foreach ($board['lines'] as $topic)
|
Chris@76
|
773 if (in_array($mid, $topic['members']))
|
Chris@76
|
774 {
|
Chris@76
|
775 if (!$titled)
|
Chris@76
|
776 {
|
Chris@76
|
777 $email['body'] .= "\n" . $langtxt[$lang]['mod_actions'] . ':' . "\n" . '-----------------------------------------------';
|
Chris@76
|
778 $titled = true;
|
Chris@76
|
779 }
|
Chris@76
|
780 $email['body'] .= "\n" . sprintf($langtxt[$lang][$note_type], $topic['subject']);
|
Chris@76
|
781 }
|
Chris@76
|
782
|
Chris@76
|
783 }
|
Chris@76
|
784 if ($titled)
|
Chris@76
|
785 $email['body'] .= "\n";
|
Chris@76
|
786
|
Chris@76
|
787 // Then just say our goodbyes!
|
Chris@76
|
788 $email['body'] .= "\n\n" . $txt['regards_team'];
|
Chris@76
|
789
|
Chris@76
|
790 // Send it - low priority!
|
Chris@76
|
791 sendmail($email['email'], $email['subject'], $email['body'], null, null, false, 4);
|
Chris@76
|
792 }
|
Chris@76
|
793
|
Chris@76
|
794 // Clean up...
|
Chris@76
|
795 if ($is_weekly)
|
Chris@76
|
796 {
|
Chris@76
|
797 $smcFunc['db_query']('', '
|
Chris@76
|
798 DELETE FROM {db_prefix}log_digest
|
Chris@76
|
799 WHERE daily != {int:not_daily}',
|
Chris@76
|
800 array(
|
Chris@76
|
801 'not_daily' => 0,
|
Chris@76
|
802 )
|
Chris@76
|
803 );
|
Chris@76
|
804 $smcFunc['db_query']('', '
|
Chris@76
|
805 UPDATE {db_prefix}log_digest
|
Chris@76
|
806 SET daily = {int:daily_value}
|
Chris@76
|
807 WHERE daily = {int:not_daily}',
|
Chris@76
|
808 array(
|
Chris@76
|
809 'daily_value' => 2,
|
Chris@76
|
810 'not_daily' => 0,
|
Chris@76
|
811 )
|
Chris@76
|
812 );
|
Chris@76
|
813 }
|
Chris@76
|
814 else
|
Chris@76
|
815 {
|
Chris@76
|
816 // Clear any only weekly ones, and stop us from sending daily again.
|
Chris@76
|
817 $smcFunc['db_query']('', '
|
Chris@76
|
818 DELETE FROM {db_prefix}log_digest
|
Chris@76
|
819 WHERE daily = {int:daily_value}',
|
Chris@76
|
820 array(
|
Chris@76
|
821 'daily_value' => 2,
|
Chris@76
|
822 )
|
Chris@76
|
823 );
|
Chris@76
|
824 $smcFunc['db_query']('', '
|
Chris@76
|
825 UPDATE {db_prefix}log_digest
|
Chris@76
|
826 SET daily = {int:both_value}
|
Chris@76
|
827 WHERE daily = {int:no_value}',
|
Chris@76
|
828 array(
|
Chris@76
|
829 'both_value' => 1,
|
Chris@76
|
830 'no_value' => 0,
|
Chris@76
|
831 )
|
Chris@76
|
832 );
|
Chris@76
|
833 }
|
Chris@76
|
834
|
Chris@76
|
835 // Just in case the member changes their settings mark this as sent.
|
Chris@76
|
836 $members = array_keys($members);
|
Chris@76
|
837 $smcFunc['db_query']('', '
|
Chris@76
|
838 UPDATE {db_prefix}log_notify
|
Chris@76
|
839 SET sent = {int:is_sent}
|
Chris@76
|
840 WHERE id_member IN ({array_int:member_list})',
|
Chris@76
|
841 array(
|
Chris@76
|
842 'member_list' => $members,
|
Chris@76
|
843 'is_sent' => 1,
|
Chris@76
|
844 )
|
Chris@76
|
845 );
|
Chris@76
|
846
|
Chris@76
|
847 // Log we've done it...
|
Chris@76
|
848 return true;
|
Chris@76
|
849 }
|
Chris@76
|
850
|
Chris@76
|
851 // Like the daily stuff - just seven times less regular ;)
|
Chris@76
|
852 function scheduled_weekly_digest()
|
Chris@76
|
853 {
|
Chris@76
|
854 global $is_weekly;
|
Chris@76
|
855
|
Chris@76
|
856 // We just pass through to the daily function - avoid duplication!
|
Chris@76
|
857 $is_weekly = true;
|
Chris@76
|
858 return scheduled_daily_digest();
|
Chris@76
|
859 }
|
Chris@76
|
860
|
Chris@76
|
861 // Send a bunch of emails from the mail queue.
|
Chris@76
|
862 function ReduceMailQueue($number = false, $override_limit = false, $force_send = false)
|
Chris@76
|
863 {
|
Chris@76
|
864 global $modSettings, $smcFunc, $sourcedir;
|
Chris@76
|
865
|
Chris@76
|
866 // Are we intending another script to be sending out the queue?
|
Chris@76
|
867 if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send))
|
Chris@76
|
868 return false;
|
Chris@76
|
869
|
Chris@76
|
870 // By default send 5 at once.
|
Chris@76
|
871 if (!$number)
|
Chris@76
|
872 $number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity'];
|
Chris@76
|
873
|
Chris@76
|
874 // If we came with a timestamp, and that doesn't match the next event, then someone else has beaten us.
|
Chris@76
|
875 if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send))
|
Chris@76
|
876 return false;
|
Chris@76
|
877
|
Chris@76
|
878 // By default move the next sending on by 10 seconds, and require an affected row.
|
Chris@76
|
879 if (!$override_limit)
|
Chris@76
|
880 {
|
Chris@76
|
881 $delay = !empty($modSettings['mail_queue_delay']) ? $modSettings['mail_queue_delay'] : (!empty($modSettings['mail_limit']) && $modSettings['mail_limit'] < 5 ? 10 : 5);
|
Chris@76
|
882
|
Chris@76
|
883 $smcFunc['db_query']('', '
|
Chris@76
|
884 UPDATE {db_prefix}settings
|
Chris@76
|
885 SET value = {string:next_mail_send}
|
Chris@76
|
886 WHERE variable = {string:mail_next_send}
|
Chris@76
|
887 AND value = {string:last_send}',
|
Chris@76
|
888 array(
|
Chris@76
|
889 'next_mail_send' => time() + $delay,
|
Chris@76
|
890 'mail_next_send' => 'mail_next_send',
|
Chris@76
|
891 'last_send' => $modSettings['mail_next_send'],
|
Chris@76
|
892 )
|
Chris@76
|
893 );
|
Chris@76
|
894 if ($smcFunc['db_affected_rows']() == 0)
|
Chris@76
|
895 return false;
|
Chris@76
|
896 $modSettings['mail_next_send'] = time() + $delay;
|
Chris@76
|
897 }
|
Chris@76
|
898
|
Chris@76
|
899 // If we're not overriding how many are we allow to send?
|
Chris@76
|
900 if (!$override_limit && !empty($modSettings['mail_limit']))
|
Chris@76
|
901 {
|
Chris@76
|
902 list ($mt, $mn) = @explode('|', $modSettings['mail_recent']);
|
Chris@76
|
903
|
Chris@76
|
904 // Nothing worth noting...
|
Chris@76
|
905 if (empty($mn) || $mt < time() - 60)
|
Chris@76
|
906 {
|
Chris@76
|
907 $mt = time();
|
Chris@76
|
908 $mn = $number;
|
Chris@76
|
909 }
|
Chris@76
|
910 // Otherwise we have a few more we can spend?
|
Chris@76
|
911 elseif ($mn < $modSettings['mail_limit'])
|
Chris@76
|
912 {
|
Chris@76
|
913 $mn += $number;
|
Chris@76
|
914 }
|
Chris@76
|
915 // No more I'm afraid, return!
|
Chris@76
|
916 else
|
Chris@76
|
917 return false;
|
Chris@76
|
918
|
Chris@76
|
919 // Reflect that we're about to send some, do it now to be safe.
|
Chris@76
|
920 updateSettings(array('mail_recent' => $mt . '|' . $mn));
|
Chris@76
|
921 }
|
Chris@76
|
922
|
Chris@76
|
923 // Now we know how many we're sending, let's send them.
|
Chris@76
|
924 $request = $smcFunc['db_query']('', '
|
Chris@76
|
925 SELECT /*!40001 SQL_NO_CACHE */ id_mail, recipient, body, subject, headers, send_html
|
Chris@76
|
926 FROM {db_prefix}mail_queue
|
Chris@76
|
927 ORDER BY priority ASC, id_mail ASC
|
Chris@76
|
928 LIMIT ' . $number,
|
Chris@76
|
929 array(
|
Chris@76
|
930 )
|
Chris@76
|
931 );
|
Chris@76
|
932 $ids = array();
|
Chris@76
|
933 $emails = array();
|
Chris@76
|
934 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
935 {
|
Chris@76
|
936 // We want to delete these from the database ASAP, so just get the data and go.
|
Chris@76
|
937 $ids[] = $row['id_mail'];
|
Chris@76
|
938 $emails[] = array(
|
Chris@76
|
939 'to' => $row['recipient'],
|
Chris@76
|
940 'body' => $row['body'],
|
Chris@76
|
941 'subject' => $row['subject'],
|
Chris@76
|
942 'headers' => $row['headers'],
|
Chris@76
|
943 'send_html' => $row['send_html'],
|
Chris@76
|
944 );
|
Chris@76
|
945 }
|
Chris@76
|
946 $smcFunc['db_free_result']($request);
|
Chris@76
|
947
|
Chris@76
|
948 // Delete, delete, delete!!!
|
Chris@76
|
949 if (!empty($ids))
|
Chris@76
|
950 $smcFunc['db_query']('', '
|
Chris@76
|
951 DELETE FROM {db_prefix}mail_queue
|
Chris@76
|
952 WHERE id_mail IN ({array_int:mail_list})',
|
Chris@76
|
953 array(
|
Chris@76
|
954 'mail_list' => $ids,
|
Chris@76
|
955 )
|
Chris@76
|
956 );
|
Chris@76
|
957
|
Chris@76
|
958 // Don't believe we have any left?
|
Chris@76
|
959 if (count($ids) < $number)
|
Chris@76
|
960 {
|
Chris@76
|
961 // Only update the setting if no-one else has beaten us to it.
|
Chris@76
|
962 $smcFunc['db_query']('', '
|
Chris@76
|
963 UPDATE {db_prefix}settings
|
Chris@76
|
964 SET value = {string:no_send}
|
Chris@76
|
965 WHERE variable = {string:mail_next_send}
|
Chris@76
|
966 AND value = {string:last_mail_send}',
|
Chris@76
|
967 array(
|
Chris@76
|
968 'no_send' => '0',
|
Chris@76
|
969 'mail_next_send' => 'mail_next_send',
|
Chris@76
|
970 'last_mail_send' => $modSettings['mail_next_send'],
|
Chris@76
|
971 )
|
Chris@76
|
972 );
|
Chris@76
|
973 }
|
Chris@76
|
974
|
Chris@76
|
975 if (empty($ids))
|
Chris@76
|
976 return false;
|
Chris@76
|
977
|
Chris@76
|
978 if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '')
|
Chris@76
|
979 require_once($sourcedir . '/Subs-Post.php');
|
Chris@76
|
980
|
Chris@76
|
981 // Send each email, yea!
|
Chris@76
|
982 $failed_emails = array();
|
Chris@76
|
983 foreach ($emails as $key => $email)
|
Chris@76
|
984 {
|
Chris@76
|
985 if (empty($modSettings['mail_type']) || $modSettings['smtp_host'] == '')
|
Chris@76
|
986 {
|
Chris@76
|
987 $email['subject'] = strtr($email['subject'], array("\r" => '', "\n" => ''));
|
Chris@76
|
988 if (!empty($modSettings['mail_strip_carriage']))
|
Chris@76
|
989 {
|
Chris@76
|
990 $email['body'] = strtr($email['body'], array("\r" => ''));
|
Chris@76
|
991 $email['headers'] = strtr($email['headers'], array("\r" => ''));
|
Chris@76
|
992 }
|
Chris@76
|
993
|
Chris@76
|
994 // No point logging a specific error here, as we have no language. PHP error is helpful anyway...
|
Chris@76
|
995 $result = mail(strtr($email['to'], array("\r" => '', "\n" => '')), $email['subject'], $email['body'], $email['headers']);
|
Chris@76
|
996
|
Chris@76
|
997 // Try to stop a timeout, this would be bad...
|
Chris@76
|
998 @set_time_limit(300);
|
Chris@76
|
999 if (function_exists('apache_reset_timeout'))
|
Chris@76
|
1000 @apache_reset_timeout();
|
Chris@76
|
1001 }
|
Chris@76
|
1002 else
|
Chris@76
|
1003 $result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['send_html'] ? $email['headers'] : 'Mime-Version: 1.0' . "\r\n" . $email['headers']);
|
Chris@76
|
1004
|
Chris@76
|
1005 // Hopefully it sent?
|
Chris@76
|
1006 if (!$result)
|
Chris@76
|
1007 $failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html']);
|
Chris@76
|
1008 }
|
Chris@76
|
1009
|
Chris@76
|
1010 // Any emails that didn't send?
|
Chris@76
|
1011 if (!empty($failed_emails))
|
Chris@76
|
1012 {
|
Chris@76
|
1013 // Update the failed attempts check.
|
Chris@76
|
1014 $smcFunc['db_insert']('replace',
|
Chris@76
|
1015 '{db_prefix}settings',
|
Chris@76
|
1016 array('variable' => 'string', 'value' => 'string'),
|
Chris@76
|
1017 array('mail_failed_attempts', empty($modSettings['mail_failed_attempts']) ? 1 : ++$modSettings['mail_failed_attempts']),
|
Chris@76
|
1018 array('variable')
|
Chris@76
|
1019 );
|
Chris@76
|
1020
|
Chris@76
|
1021 // If we have failed to many times, tell mail to wait a bit and try again.
|
Chris@76
|
1022 if ($modSettings['mail_failed_attempts'] > 5)
|
Chris@76
|
1023 $smcFunc['db_query']('', '
|
Chris@76
|
1024 UPDATE {db_prefix}settings
|
Chris@76
|
1025 SET value = {string:mail_next_send}
|
Chris@76
|
1026 WHERE variable = {string:next_mail_send}
|
Chris@76
|
1027 AND value = {string:last_send}',
|
Chris@76
|
1028 array(
|
Chris@76
|
1029 'next_mail_send' => time() + 60,
|
Chris@76
|
1030 'mail_next_send' => 'mail_next_send',
|
Chris@76
|
1031 'last_send' => $modSettings['mail_next_send'],
|
Chris@76
|
1032 ));
|
Chris@76
|
1033
|
Chris@76
|
1034 // Add our email back to the queue, manually.
|
Chris@76
|
1035 $smcFunc['db_insert']('insert',
|
Chris@76
|
1036 '{db_prefix}mail_queue',
|
Chris@76
|
1037 array('recipient' => 'string', 'body' => 'string', 'subject' => 'string', 'headers' => 'string', 'send_html' => 'string'),
|
Chris@76
|
1038 $failed_emails,
|
Chris@76
|
1039 array('id_mail')
|
Chris@76
|
1040 );
|
Chris@76
|
1041
|
Chris@76
|
1042 return false;
|
Chris@76
|
1043 }
|
Chris@76
|
1044 // We where unable to send the email, clear our failed attempts.
|
Chris@76
|
1045 elseif (!empty($modSettings['mail_failed_attempts']))
|
Chris@76
|
1046 $smcFunc['db_query']('', '
|
Chris@76
|
1047 UPDATE {db_prefix}settings
|
Chris@76
|
1048 SET value = {string:zero}
|
Chris@76
|
1049 WHERE variable = {string:mail_failed_attempts}',
|
Chris@76
|
1050 array(
|
Chris@76
|
1051 'zero' => '0',
|
Chris@76
|
1052 'mail_failed_attempts' => 'mail_failed_attempts',
|
Chris@76
|
1053 ));
|
Chris@76
|
1054
|
Chris@76
|
1055 // Had something to send...
|
Chris@76
|
1056 return true;
|
Chris@76
|
1057 }
|
Chris@76
|
1058
|
Chris@76
|
1059 // Calculate the next time the passed tasks should be triggered.
|
Chris@76
|
1060 function CalculateNextTrigger($tasks = array(), $forceUpdate = false)
|
Chris@76
|
1061 {
|
Chris@76
|
1062 global $modSettings, $smcFunc;
|
Chris@76
|
1063
|
Chris@76
|
1064 $task_query = '';
|
Chris@76
|
1065 if (!is_array($tasks))
|
Chris@76
|
1066 $tasks = array($tasks);
|
Chris@76
|
1067
|
Chris@76
|
1068 // Actually have something passed?
|
Chris@76
|
1069 if (!empty($tasks))
|
Chris@76
|
1070 {
|
Chris@76
|
1071 if (!isset($tasks[0]) || is_numeric($tasks[0]))
|
Chris@76
|
1072 $task_query = ' AND id_task IN ({array_int:tasks})';
|
Chris@76
|
1073 else
|
Chris@76
|
1074 $task_query = ' AND task IN ({array_string:tasks})';
|
Chris@76
|
1075 }
|
Chris@76
|
1076 $nextTaskTime = empty($tasks) ? time() + 86400 : $modSettings['next_task_time'];
|
Chris@76
|
1077
|
Chris@76
|
1078 // Get the critical info for the tasks.
|
Chris@76
|
1079 $request = $smcFunc['db_query']('', '
|
Chris@76
|
1080 SELECT id_task, next_time, time_offset, time_regularity, time_unit
|
Chris@76
|
1081 FROM {db_prefix}scheduled_tasks
|
Chris@76
|
1082 WHERE disabled = {int:no_disabled}
|
Chris@76
|
1083 ' . $task_query,
|
Chris@76
|
1084 array(
|
Chris@76
|
1085 'no_disabled' => 0,
|
Chris@76
|
1086 'tasks' => $tasks,
|
Chris@76
|
1087 )
|
Chris@76
|
1088 );
|
Chris@76
|
1089 $tasks = array();
|
Chris@76
|
1090 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
1091 {
|
Chris@76
|
1092 $next_time = next_time($row['time_regularity'], $row['time_unit'], $row['time_offset']);
|
Chris@76
|
1093
|
Chris@76
|
1094 // Only bother moving the task if it's out of place or we're forcing it!
|
Chris@76
|
1095 if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time())
|
Chris@76
|
1096 $tasks[$row['id_task']] = $next_time;
|
Chris@76
|
1097 else
|
Chris@76
|
1098 $next_time = $row['next_time'];
|
Chris@76
|
1099
|
Chris@76
|
1100 // If this is sooner than the current next task, make this the next task.
|
Chris@76
|
1101 if ($next_time < $nextTaskTime)
|
Chris@76
|
1102 $nextTaskTime = $next_time;
|
Chris@76
|
1103 }
|
Chris@76
|
1104 $smcFunc['db_free_result']($request);
|
Chris@76
|
1105
|
Chris@76
|
1106 // Now make the changes!
|
Chris@76
|
1107 foreach ($tasks as $id => $time)
|
Chris@76
|
1108 $smcFunc['db_query']('', '
|
Chris@76
|
1109 UPDATE {db_prefix}scheduled_tasks
|
Chris@76
|
1110 SET next_time = {int:next_time}
|
Chris@76
|
1111 WHERE id_task = {int:id_task}',
|
Chris@76
|
1112 array(
|
Chris@76
|
1113 'next_time' => $time,
|
Chris@76
|
1114 'id_task' => $id,
|
Chris@76
|
1115 )
|
Chris@76
|
1116 );
|
Chris@76
|
1117
|
Chris@76
|
1118 // If the next task is now different update.
|
Chris@76
|
1119 if ($modSettings['next_task_time'] != $nextTaskTime)
|
Chris@76
|
1120 updateSettings(array('next_task_time' => $nextTaskTime));
|
Chris@76
|
1121 }
|
Chris@76
|
1122
|
Chris@76
|
1123 // Simply returns a time stamp of the next instance of these time parameters.
|
Chris@76
|
1124 function next_time($regularity, $unit, $offset)
|
Chris@76
|
1125 {
|
Chris@76
|
1126 // Just in case!
|
Chris@76
|
1127 if ($regularity == 0)
|
Chris@76
|
1128 $regularity = 2;
|
Chris@76
|
1129
|
Chris@76
|
1130 $curHour = date('H', time());
|
Chris@76
|
1131 $curMin = date('i', time());
|
Chris@76
|
1132 $next_time = 9999999999;
|
Chris@76
|
1133
|
Chris@76
|
1134 // If the unit is minutes only check regularity in minutes.
|
Chris@76
|
1135 if ($unit == 'm')
|
Chris@76
|
1136 {
|
Chris@76
|
1137 $off = date('i', $offset);
|
Chris@76
|
1138
|
Chris@76
|
1139 // If it's now just pretend it ain't,
|
Chris@76
|
1140 if ($off == $curMin)
|
Chris@76
|
1141 $next_time = time() + $regularity;
|
Chris@76
|
1142 else
|
Chris@76
|
1143 {
|
Chris@76
|
1144 // Make sure that the offset is always in the past.
|
Chris@76
|
1145 $off = $off > $curMin ? $off - 60 : $off;
|
Chris@76
|
1146
|
Chris@76
|
1147 while ($off <= $curMin)
|
Chris@76
|
1148 $off += $regularity;
|
Chris@76
|
1149
|
Chris@76
|
1150 // Now we know when the time should be!
|
Chris@76
|
1151 $next_time = time() + 60 * ($off - $curMin);
|
Chris@76
|
1152 }
|
Chris@76
|
1153 }
|
Chris@76
|
1154 // Otherwise, work out what the offset would be with todays date.
|
Chris@76
|
1155 else
|
Chris@76
|
1156 {
|
Chris@76
|
1157 $next_time = mktime(date('H', $offset), date('i', $offset), 0, date('m'), date('d'), date('Y'));
|
Chris@76
|
1158
|
Chris@76
|
1159 // Make the time offset in the past!
|
Chris@76
|
1160 if ($next_time > time())
|
Chris@76
|
1161 {
|
Chris@76
|
1162 $next_time -= 86400;
|
Chris@76
|
1163 }
|
Chris@76
|
1164
|
Chris@76
|
1165 // Default we'll jump in hours.
|
Chris@76
|
1166 $applyOffset = 3600;
|
Chris@76
|
1167 // 24 hours = 1 day.
|
Chris@76
|
1168 if ($unit == 'd')
|
Chris@76
|
1169 $applyOffset = 86400;
|
Chris@76
|
1170 // Otherwise a week.
|
Chris@76
|
1171 if ($unit == 'w')
|
Chris@76
|
1172 $applyOffset = 604800;
|
Chris@76
|
1173
|
Chris@76
|
1174 $applyOffset *= $regularity;
|
Chris@76
|
1175
|
Chris@76
|
1176 // Just add on the offset.
|
Chris@76
|
1177 while ($next_time <= time())
|
Chris@76
|
1178 {
|
Chris@76
|
1179 $next_time += $applyOffset;
|
Chris@76
|
1180 }
|
Chris@76
|
1181 }
|
Chris@76
|
1182
|
Chris@76
|
1183 return $next_time;
|
Chris@76
|
1184 }
|
Chris@76
|
1185
|
Chris@76
|
1186 // This loads the bare minimum data to allow us to load language files!
|
Chris@76
|
1187 function loadEssentialThemeData()
|
Chris@76
|
1188 {
|
Chris@76
|
1189 global $settings, $modSettings, $smcFunc, $mbname, $context, $sourcedir;
|
Chris@76
|
1190
|
Chris@76
|
1191 // Get all the default theme variables.
|
Chris@76
|
1192 $result = $smcFunc['db_query']('', '
|
Chris@76
|
1193 SELECT id_theme, variable, value
|
Chris@76
|
1194 FROM {db_prefix}themes
|
Chris@76
|
1195 WHERE id_member = {int:no_member}
|
Chris@76
|
1196 AND id_theme IN (1, {int:theme_guests})',
|
Chris@76
|
1197 array(
|
Chris@76
|
1198 'no_member' => 0,
|
Chris@76
|
1199 'theme_guests' => $modSettings['theme_guests'],
|
Chris@76
|
1200 )
|
Chris@76
|
1201 );
|
Chris@76
|
1202 while ($row = $smcFunc['db_fetch_assoc']($result))
|
Chris@76
|
1203 {
|
Chris@76
|
1204 $settings[$row['variable']] = $row['value'];
|
Chris@76
|
1205
|
Chris@76
|
1206 // Is this the default theme?
|
Chris@76
|
1207 if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1')
|
Chris@76
|
1208 $settings['default_' . $row['variable']] = $row['value'];
|
Chris@76
|
1209 }
|
Chris@76
|
1210 $smcFunc['db_free_result']($result);
|
Chris@76
|
1211
|
Chris@76
|
1212 // Check we have some directories setup.
|
Chris@76
|
1213 if (empty($settings['template_dirs']))
|
Chris@76
|
1214 {
|
Chris@76
|
1215 $settings['template_dirs'] = array($settings['theme_dir']);
|
Chris@76
|
1216
|
Chris@76
|
1217 // Based on theme (if there is one).
|
Chris@76
|
1218 if (!empty($settings['base_theme_dir']))
|
Chris@76
|
1219 $settings['template_dirs'][] = $settings['base_theme_dir'];
|
Chris@76
|
1220
|
Chris@76
|
1221 // Lastly the default theme.
|
Chris@76
|
1222 if ($settings['theme_dir'] != $settings['default_theme_dir'])
|
Chris@76
|
1223 $settings['template_dirs'][] = $settings['default_theme_dir'];
|
Chris@76
|
1224 }
|
Chris@76
|
1225
|
Chris@76
|
1226 // Assume we want this.
|
Chris@76
|
1227 $context['forum_name'] = $mbname;
|
Chris@76
|
1228
|
Chris@76
|
1229 // Check loadLanguage actually exists!
|
Chris@76
|
1230 if (!function_exists('loadLanguage'))
|
Chris@76
|
1231 {
|
Chris@76
|
1232 require_once($sourcedir . '/Load.php');
|
Chris@76
|
1233 require_once($sourcedir . '/Subs.php');
|
Chris@76
|
1234 }
|
Chris@76
|
1235
|
Chris@76
|
1236 loadLanguage('index+Modifications');
|
Chris@76
|
1237 }
|
Chris@76
|
1238
|
Chris@76
|
1239 function scheduled_fetchSMfiles()
|
Chris@76
|
1240 {
|
Chris@76
|
1241 global $sourcedir, $txt, $language, $settings, $forum_version, $modSettings, $smcFunc;
|
Chris@76
|
1242
|
Chris@76
|
1243 // What files do we want to get
|
Chris@76
|
1244 $request = $smcFunc['db_query']('', '
|
Chris@76
|
1245 SELECT id_file, filename, path, parameters
|
Chris@76
|
1246 FROM {db_prefix}admin_info_files',
|
Chris@76
|
1247 array(
|
Chris@76
|
1248 )
|
Chris@76
|
1249 );
|
Chris@76
|
1250
|
Chris@76
|
1251 $js_files = array();
|
Chris@76
|
1252
|
Chris@76
|
1253 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
1254 {
|
Chris@76
|
1255 $js_files[$row['id_file']] = array(
|
Chris@76
|
1256 'filename' => $row['filename'],
|
Chris@76
|
1257 'path' => $row['path'],
|
Chris@76
|
1258 'parameters' => sprintf($row['parameters'], $language, urlencode($modSettings['time_format']), urlencode($forum_version)),
|
Chris@76
|
1259 );
|
Chris@76
|
1260 }
|
Chris@76
|
1261
|
Chris@76
|
1262 $smcFunc['db_free_result']($request);
|
Chris@76
|
1263
|
Chris@76
|
1264 // We're gonna need fetch_web_data() to pull this off.
|
Chris@76
|
1265 require_once($sourcedir . '/Subs-Package.php');
|
Chris@76
|
1266
|
Chris@76
|
1267 // Just in case we run into a problem.
|
Chris@76
|
1268 loadEssentialThemeData();
|
Chris@76
|
1269 loadLanguage('Errors', $language, false);
|
Chris@76
|
1270
|
Chris@76
|
1271 foreach ($js_files as $ID_FILE => $file)
|
Chris@76
|
1272 {
|
Chris@76
|
1273 // Create the url
|
Chris@76
|
1274 $server = empty($file['path']) || substr($file['path'], 0, 7) != 'http://' ? 'http://www.simplemachines.org' : '';
|
Chris@76
|
1275 $url = $server . (!empty($file['path']) ? $file['path'] : $file['path']) . $file['filename'] . (!empty($file['parameters']) ? '?' . $file['parameters'] : '');
|
Chris@76
|
1276
|
Chris@76
|
1277 // Get the file
|
Chris@76
|
1278 $file_data = fetch_web_data($url);
|
Chris@76
|
1279
|
Chris@76
|
1280 // If we got an error - give up - the site might be down.
|
Chris@76
|
1281 if ($file_data === false)
|
Chris@76
|
1282 {
|
Chris@76
|
1283 log_error(sprintf($txt['st_cannot_retrieve_file'], $url));
|
Chris@76
|
1284 return false;
|
Chris@76
|
1285 }
|
Chris@76
|
1286
|
Chris@76
|
1287 // Save the file to the database.
|
Chris@76
|
1288 $smcFunc['db_query']('substring', '
|
Chris@76
|
1289 UPDATE {db_prefix}admin_info_files
|
Chris@76
|
1290 SET data = SUBSTRING({string:file_data}, 1, 65534)
|
Chris@76
|
1291 WHERE id_file = {int:id_file}',
|
Chris@76
|
1292 array(
|
Chris@76
|
1293 'id_file' => $ID_FILE,
|
Chris@76
|
1294 'file_data' => $file_data,
|
Chris@76
|
1295 )
|
Chris@76
|
1296 );
|
Chris@76
|
1297 }
|
Chris@76
|
1298 return true;
|
Chris@76
|
1299 }
|
Chris@76
|
1300
|
Chris@76
|
1301 function scheduled_birthdayemails()
|
Chris@76
|
1302 {
|
Chris@76
|
1303 global $modSettings, $sourcedir, $mbname, $txt, $smcFunc, $birthdayEmails;
|
Chris@76
|
1304
|
Chris@76
|
1305 // Need this in order to load the language files.
|
Chris@76
|
1306 loadEssentialThemeData();
|
Chris@76
|
1307
|
Chris@76
|
1308 // Going to need this to send the emails.
|
Chris@76
|
1309 require_once($sourcedir . '/Subs-Post.php');
|
Chris@76
|
1310
|
Chris@76
|
1311 $greeting = isset($modSettings['birthday_email']) ? $modSettings['birthday_email'] : 'happy_birthday';
|
Chris@76
|
1312
|
Chris@76
|
1313 // Get the month and day of today.
|
Chris@76
|
1314 $month = date('n'); // Month without leading zeros.
|
Chris@76
|
1315 $day = date('j'); // Day without leading zeros.
|
Chris@76
|
1316
|
Chris@76
|
1317 // So who are the lucky ones? Don't include those who are banned and those who don't want them.
|
Chris@76
|
1318 $result = $smcFunc['db_query']('', '
|
Chris@76
|
1319 SELECT id_member, real_name, lngfile, email_address
|
Chris@76
|
1320 FROM {db_prefix}members
|
Chris@76
|
1321 WHERE is_activated < 10
|
Chris@76
|
1322 AND MONTH(birthdate) = {int:month}
|
Chris@76
|
1323 AND DAYOFMONTH(birthdate) = {int:day}
|
Chris@76
|
1324 AND notify_announcements = {int:notify_announcements}
|
Chris@76
|
1325 AND YEAR(birthdate) > {int:year}',
|
Chris@76
|
1326 array(
|
Chris@76
|
1327 'notify_announcements' => 1,
|
Chris@76
|
1328 'year' => 1,
|
Chris@76
|
1329 'month' => $month,
|
Chris@76
|
1330 'day' => $day,
|
Chris@76
|
1331 )
|
Chris@76
|
1332 );
|
Chris@76
|
1333
|
Chris@76
|
1334 // Group them by languages.
|
Chris@76
|
1335 $birthdays = array();
|
Chris@76
|
1336 while ($row = $smcFunc['db_fetch_assoc']($result))
|
Chris@76
|
1337 {
|
Chris@76
|
1338 if (!isset($birthdays[$row['lngfile']]))
|
Chris@76
|
1339 $birthdays[$row['lngfile']] = array();
|
Chris@76
|
1340 $birthdays[$row['lngfile']][$row['id_member']] = array(
|
Chris@76
|
1341 'name' => $row['real_name'],
|
Chris@76
|
1342 'email' => $row['email_address']
|
Chris@76
|
1343 );
|
Chris@76
|
1344 }
|
Chris@76
|
1345 $smcFunc['db_free_result']($result);
|
Chris@76
|
1346
|
Chris@76
|
1347 // Send out the greetings!
|
Chris@76
|
1348 foreach ($birthdays as $lang => $recps)
|
Chris@76
|
1349 {
|
Chris@76
|
1350 // We need to do some shuffling to make this work properly.
|
Chris@76
|
1351 loadLanguage('EmailTemplates', $lang);
|
Chris@76
|
1352 $txt['emails']['happy_birthday'] = $birthdayEmails[$greeting];
|
Chris@76
|
1353
|
Chris@76
|
1354 foreach ($recps as $recp)
|
Chris@76
|
1355 {
|
Chris@76
|
1356 $replacements = array(
|
Chris@76
|
1357 'REALNAME' => $recp['name'],
|
Chris@76
|
1358 );
|
Chris@76
|
1359
|
Chris@76
|
1360 $emaildata = loadEmailTemplate('happy_birthday', $replacements, $lang, false);
|
Chris@76
|
1361
|
Chris@76
|
1362 sendmail($recp['email'], $emaildata['subject'], $emaildata['body'], null, null, false, 4);
|
Chris@76
|
1363
|
Chris@76
|
1364 // Try to stop a timeout, this would be bad...
|
Chris@76
|
1365 @set_time_limit(300);
|
Chris@76
|
1366 if (function_exists('apache_reset_timeout'))
|
Chris@76
|
1367 @apache_reset_timeout();
|
Chris@76
|
1368
|
Chris@76
|
1369 }
|
Chris@76
|
1370 }
|
Chris@76
|
1371
|
Chris@76
|
1372 // Flush the mail queue, just in case.
|
Chris@76
|
1373 AddMailQueue(true);
|
Chris@76
|
1374
|
Chris@76
|
1375 return true;
|
Chris@76
|
1376 }
|
Chris@76
|
1377
|
Chris@76
|
1378 function scheduled_weekly_maintenance()
|
Chris@76
|
1379 {
|
Chris@76
|
1380 global $modSettings, $smcFunc;
|
Chris@76
|
1381
|
Chris@76
|
1382 // Delete some settings that needn't be set if they are otherwise empty.
|
Chris@76
|
1383 $emptySettings = array(
|
Chris@76
|
1384 'warning_mute', 'warning_moderate', 'warning_watch', 'warning_show', 'disableCustomPerPage', 'spider_mode', 'spider_group',
|
Chris@76
|
1385 'paid_currency_code', 'paid_currency_symbol', 'paid_email_to', 'paid_email', 'paid_enabled', 'paypal_email',
|
Chris@76
|
1386 'search_enable_captcha', 'search_floodcontrol_time', 'show_spider_online',
|
Chris@76
|
1387 );
|
Chris@76
|
1388
|
Chris@76
|
1389 $smcFunc['db_query']('', '
|
Chris@76
|
1390 DELETE FROM {db_prefix}settings
|
Chris@76
|
1391 WHERE variable IN ({array_string:setting_list})
|
Chris@76
|
1392 AND (value = {string:zero_value} OR value = {string:blank_value})',
|
Chris@76
|
1393 array(
|
Chris@76
|
1394 'zero_value' => '0',
|
Chris@76
|
1395 'blank_value' => '',
|
Chris@76
|
1396 'setting_list' => $emptySettings,
|
Chris@76
|
1397 )
|
Chris@76
|
1398 );
|
Chris@76
|
1399
|
Chris@76
|
1400 // Some settings we never want to keep - they are just there for temporary purposes.
|
Chris@76
|
1401 $deleteAnywaySettings = array(
|
Chris@76
|
1402 'attachment_full_notified',
|
Chris@76
|
1403 );
|
Chris@76
|
1404
|
Chris@76
|
1405 $smcFunc['db_query']('', '
|
Chris@76
|
1406 DELETE FROM {db_prefix}settings
|
Chris@76
|
1407 WHERE variable IN ({array_string:setting_list})',
|
Chris@76
|
1408 array(
|
Chris@76
|
1409 'setting_list' => $deleteAnywaySettings,
|
Chris@76
|
1410 )
|
Chris@76
|
1411 );
|
Chris@76
|
1412
|
Chris@76
|
1413 // Ok should we prune the logs?
|
Chris@76
|
1414 if (!empty($modSettings['pruningOptions']))
|
Chris@76
|
1415 {
|
Chris@76
|
1416 if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false)
|
Chris@76
|
1417 list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
|
Chris@76
|
1418
|
Chris@76
|
1419 if (!empty($modSettings['pruneErrorLog']))
|
Chris@76
|
1420 {
|
Chris@76
|
1421 // Figure out when our cutoff time is. 1 day = 86400 seconds.
|
Chris@76
|
1422 $t = time() - $modSettings['pruneErrorLog'] * 86400;
|
Chris@76
|
1423
|
Chris@76
|
1424 $smcFunc['db_query']('', '
|
Chris@76
|
1425 DELETE FROM {db_prefix}log_errors
|
Chris@76
|
1426 WHERE log_time < {int:log_time}',
|
Chris@76
|
1427 array(
|
Chris@76
|
1428 'log_time' => $t,
|
Chris@76
|
1429 )
|
Chris@76
|
1430 );
|
Chris@76
|
1431 }
|
Chris@76
|
1432
|
Chris@76
|
1433 if (!empty($modSettings['pruneModLog']))
|
Chris@76
|
1434 {
|
Chris@76
|
1435 // Figure out when our cutoff time is. 1 day = 86400 seconds.
|
Chris@76
|
1436 $t = time() - $modSettings['pruneModLog'] * 86400;
|
Chris@76
|
1437
|
Chris@76
|
1438 $smcFunc['db_query']('', '
|
Chris@76
|
1439 DELETE FROM {db_prefix}log_actions
|
Chris@76
|
1440 WHERE log_time < {int:log_time}
|
Chris@76
|
1441 AND id_log = {int:moderation_log}',
|
Chris@76
|
1442 array(
|
Chris@76
|
1443 'log_time' => $t,
|
Chris@76
|
1444 'moderation_log' => 1,
|
Chris@76
|
1445 )
|
Chris@76
|
1446 );
|
Chris@76
|
1447 }
|
Chris@76
|
1448
|
Chris@76
|
1449 if (!empty($modSettings['pruneBanLog']))
|
Chris@76
|
1450 {
|
Chris@76
|
1451 // Figure out when our cutoff time is. 1 day = 86400 seconds.
|
Chris@76
|
1452 $t = time() - $modSettings['pruneBanLog'] * 86400;
|
Chris@76
|
1453
|
Chris@76
|
1454 $smcFunc['db_query']('', '
|
Chris@76
|
1455 DELETE FROM {db_prefix}log_banned
|
Chris@76
|
1456 WHERE log_time < {int:log_time}',
|
Chris@76
|
1457 array(
|
Chris@76
|
1458 'log_time' => $t,
|
Chris@76
|
1459 )
|
Chris@76
|
1460 );
|
Chris@76
|
1461 }
|
Chris@76
|
1462
|
Chris@76
|
1463 if (!empty($modSettings['pruneReportLog']))
|
Chris@76
|
1464 {
|
Chris@76
|
1465 // Figure out when our cutoff time is. 1 day = 86400 seconds.
|
Chris@76
|
1466 $t = time() - $modSettings['pruneReportLog'] * 86400;
|
Chris@76
|
1467
|
Chris@76
|
1468 // This one is more complex then the other logs. First we need to figure out which reports are too old.
|
Chris@76
|
1469 $reports = array();
|
Chris@76
|
1470 $result = $smcFunc['db_query']('', '
|
Chris@76
|
1471 SELECT id_report
|
Chris@76
|
1472 FROM {db_prefix}log_reported
|
Chris@76
|
1473 WHERE time_started < {int:time_started}',
|
Chris@76
|
1474 array(
|
Chris@76
|
1475 'time_started' => $t,
|
Chris@76
|
1476 )
|
Chris@76
|
1477 );
|
Chris@76
|
1478
|
Chris@76
|
1479 while ($row = $smcFunc['db_fetch_row']($result))
|
Chris@76
|
1480 $reports[] = $row[0];
|
Chris@76
|
1481
|
Chris@76
|
1482 $smcFunc['db_free_result']($result);
|
Chris@76
|
1483
|
Chris@76
|
1484 if (!empty($reports))
|
Chris@76
|
1485 {
|
Chris@76
|
1486 // Now delete the reports...
|
Chris@76
|
1487 $smcFunc['db_query']('', '
|
Chris@76
|
1488 DELETE FROM {db_prefix}log_reported
|
Chris@76
|
1489 WHERE id_report IN ({array_int:report_list})',
|
Chris@76
|
1490 array(
|
Chris@76
|
1491 'report_list' => $reports,
|
Chris@76
|
1492 )
|
Chris@76
|
1493 );
|
Chris@76
|
1494 // And delete the comments for those reports...
|
Chris@76
|
1495 $smcFunc['db_query']('', '
|
Chris@76
|
1496 DELETE FROM {db_prefix}log_reported_comments
|
Chris@76
|
1497 WHERE id_report IN ({array_int:report_list})',
|
Chris@76
|
1498 array(
|
Chris@76
|
1499 'report_list' => $reports,
|
Chris@76
|
1500 )
|
Chris@76
|
1501 );
|
Chris@76
|
1502 }
|
Chris@76
|
1503 }
|
Chris@76
|
1504
|
Chris@76
|
1505 if (!empty($modSettings['pruneScheduledTaskLog']))
|
Chris@76
|
1506 {
|
Chris@76
|
1507 // Figure out when our cutoff time is. 1 day = 86400 seconds.
|
Chris@76
|
1508 $t = time() - $modSettings['pruneScheduledTaskLog'] * 86400;
|
Chris@76
|
1509
|
Chris@76
|
1510 $smcFunc['db_query']('', '
|
Chris@76
|
1511 DELETE FROM {db_prefix}log_scheduled_tasks
|
Chris@76
|
1512 WHERE time_run < {int:time_run}',
|
Chris@76
|
1513 array(
|
Chris@76
|
1514 'time_run' => $t,
|
Chris@76
|
1515 )
|
Chris@76
|
1516 );
|
Chris@76
|
1517 }
|
Chris@76
|
1518
|
Chris@76
|
1519 if (!empty($modSettings['pruneSpiderHitLog']))
|
Chris@76
|
1520 {
|
Chris@76
|
1521 // Figure out when our cutoff time is. 1 day = 86400 seconds.
|
Chris@76
|
1522 $t = time() - $modSettings['pruneSpiderHitLog'] * 86400;
|
Chris@76
|
1523
|
Chris@76
|
1524 $smcFunc['db_query']('', '
|
Chris@76
|
1525 DELETE FROM {db_prefix}log_spider_hits
|
Chris@76
|
1526 WHERE log_time < {int:log_time}',
|
Chris@76
|
1527 array(
|
Chris@76
|
1528 'log_time' => $t,
|
Chris@76
|
1529 )
|
Chris@76
|
1530 );
|
Chris@76
|
1531 }
|
Chris@76
|
1532 }
|
Chris@76
|
1533
|
Chris@76
|
1534 // Get rid of any paid subscriptions that were never actioned.
|
Chris@76
|
1535 $smcFunc['db_query']('', '
|
Chris@76
|
1536 DELETE FROM {db_prefix}log_subscribed
|
Chris@76
|
1537 WHERE end_time = {int:no_end_time}
|
Chris@76
|
1538 AND status = {int:not_active}
|
Chris@76
|
1539 AND start_time < {int:start_time}
|
Chris@76
|
1540 AND payments_pending < {int:payments_pending}',
|
Chris@76
|
1541 array(
|
Chris@76
|
1542 'no_end_time' => 0,
|
Chris@76
|
1543 'not_active' => 0,
|
Chris@76
|
1544 'start_time' => time() - 60,
|
Chris@76
|
1545 'payments_pending' => 1,
|
Chris@76
|
1546 )
|
Chris@76
|
1547 );
|
Chris@76
|
1548
|
Chris@76
|
1549 // Some OS's don't seem to clean out their sessions.
|
Chris@76
|
1550 $smcFunc['db_query']('', '
|
Chris@76
|
1551 DELETE FROM {db_prefix}sessions
|
Chris@76
|
1552 WHERE last_update < {int:last_update}',
|
Chris@76
|
1553 array(
|
Chris@76
|
1554 'last_update' => time() - 86400,
|
Chris@76
|
1555 )
|
Chris@76
|
1556 );
|
Chris@76
|
1557
|
Chris@76
|
1558 return true;
|
Chris@76
|
1559 }
|
Chris@76
|
1560
|
Chris@76
|
1561 // Perform the standard checks on expiring/near expiring subscriptions.
|
Chris@76
|
1562 function scheduled_paid_subscriptions()
|
Chris@76
|
1563 {
|
Chris@76
|
1564 global $txt, $sourcedir, $scripturl, $smcFunc, $modSettings, $language;
|
Chris@76
|
1565
|
Chris@76
|
1566 // Start off by checking for removed subscriptions.
|
Chris@76
|
1567 $request = $smcFunc['db_query']('', '
|
Chris@76
|
1568 SELECT id_subscribe, id_member
|
Chris@76
|
1569 FROM {db_prefix}log_subscribed
|
Chris@76
|
1570 WHERE status = {int:is_active}
|
Chris@76
|
1571 AND end_time < {int:time_now}',
|
Chris@76
|
1572 array(
|
Chris@76
|
1573 'is_active' => 1,
|
Chris@76
|
1574 'time_now' => time(),
|
Chris@76
|
1575 )
|
Chris@76
|
1576 );
|
Chris@76
|
1577 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
1578 {
|
Chris@76
|
1579 require_once($sourcedir . '/ManagePaid.php');
|
Chris@76
|
1580 removeSubscription($row['id_subscribe'], $row['id_member']);
|
Chris@76
|
1581 }
|
Chris@76
|
1582 $smcFunc['db_free_result']($request);
|
Chris@76
|
1583
|
Chris@76
|
1584 // Get all those about to expire that have not had a reminder sent.
|
Chris@76
|
1585 $request = $smcFunc['db_query']('', '
|
Chris@76
|
1586 SELECT ls.id_sublog, m.id_member, m.member_name, m.email_address, m.lngfile, s.name, ls.end_time
|
Chris@76
|
1587 FROM {db_prefix}log_subscribed AS ls
|
Chris@76
|
1588 INNER JOIN {db_prefix}subscriptions AS s ON (s.id_subscribe = ls.id_subscribe)
|
Chris@76
|
1589 INNER JOIN {db_prefix}members AS m ON (m.id_member = ls.id_member)
|
Chris@76
|
1590 WHERE ls.status = {int:is_active}
|
Chris@76
|
1591 AND ls.reminder_sent = {int:reminder_sent}
|
Chris@76
|
1592 AND s.reminder > {int:reminder_wanted}
|
Chris@76
|
1593 AND ls.end_time < ({int:time_now} + s.reminder * 86400)',
|
Chris@76
|
1594 array(
|
Chris@76
|
1595 'is_active' => 1,
|
Chris@76
|
1596 'reminder_sent' => 0,
|
Chris@76
|
1597 'reminder_wanted' => 0,
|
Chris@76
|
1598 'time_now' => time(),
|
Chris@76
|
1599 )
|
Chris@76
|
1600 );
|
Chris@76
|
1601 $subs_reminded = array();
|
Chris@76
|
1602 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
1603 {
|
Chris@76
|
1604 // If this is the first one load the important bits.
|
Chris@76
|
1605 if (empty($subs_reminded))
|
Chris@76
|
1606 {
|
Chris@76
|
1607 require_once($sourcedir . '/Subs-Post.php');
|
Chris@76
|
1608 // Need the below for loadLanguage to work!
|
Chris@76
|
1609 loadEssentialThemeData();
|
Chris@76
|
1610 }
|
Chris@76
|
1611
|
Chris@76
|
1612 $subs_reminded[] = $row['id_sublog'];
|
Chris@76
|
1613
|
Chris@76
|
1614 $replacements = array(
|
Chris@76
|
1615 'PROFILE_LINK' => $scripturl . '?action=profile;area=subscriptions;u=' . $row['id_member'],
|
Chris@76
|
1616 'REALNAME' => $row['member_name'],
|
Chris@76
|
1617 'SUBSCRIPTION' => $row['name'],
|
Chris@76
|
1618 'END_DATE' => strip_tags(timeformat($row['end_time'])),
|
Chris@76
|
1619 );
|
Chris@76
|
1620
|
Chris@76
|
1621 $emaildata = loadEmailTemplate('paid_subscription_reminder', $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']);
|
Chris@76
|
1622
|
Chris@76
|
1623 // Send the actual email.
|
Chris@76
|
1624 sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, null, false, 2);
|
Chris@76
|
1625 }
|
Chris@76
|
1626 $smcFunc['db_free_result']($request);
|
Chris@76
|
1627
|
Chris@76
|
1628 // Mark the reminder as sent.
|
Chris@76
|
1629 if (!empty($subs_reminded))
|
Chris@76
|
1630 $smcFunc['db_query']('', '
|
Chris@76
|
1631 UPDATE {db_prefix}log_subscribed
|
Chris@76
|
1632 SET reminder_sent = {int:reminder_sent}
|
Chris@76
|
1633 WHERE id_sublog IN ({array_int:subscription_list})',
|
Chris@76
|
1634 array(
|
Chris@76
|
1635 'subscription_list' => $subs_reminded,
|
Chris@76
|
1636 'reminder_sent' => 1,
|
Chris@76
|
1637 )
|
Chris@76
|
1638 );
|
Chris@76
|
1639
|
Chris@76
|
1640 return true;
|
Chris@76
|
1641 }
|
Chris@76
|
1642
|
Chris@76
|
1643 ?> |