PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/mail_digests.php

http://github.com/MightyGorgon/icy_phoenix
PHP | 617 lines | 424 code | 70 blank | 123 comment | 84 complexity | 52f85831db1c1c0886a33628105811a0 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * @package Icy Phoenix
  5. * @version $Id$
  6. * @copyright (c) 2008 Icy Phoenix
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. *
  12. * @Extra credits for this file
  13. * Mark D. Hamill (mhamill@computer.org)
  14. *
  15. */
  16. // ----------------------------------------- WARNING ---------------------------------------------- //
  17. // THIS PROGRAM SHOULD BE INVOKED TO RUN AUTOMATICALLY EVERY HOUR BY THE OPERATING SYSTEM USING AN
  18. // OPERATING SYSTEM FEATURE LIKE CRONTAB. SEE BATCH_SCHEDULING.TXT!!!
  19. // ------------------------------------------ EDIT ------------------------------------------------ //
  20. // IN ACP THERE IS AN OPTION FOR TRYING TO EMULATE THE CRONTAB VIA PHP. NOT FULLY WORKING YET WITH
  21. // SOME CONFIGURATIONS.
  22. // ----------------------------------------- WARNING ---------------------------------------------- //
  23. // Warning: this was only tested with MySQL. I don't have access to other databases. Consequently,
  24. // the SQL may need tweaking for other relational databases.
  25. if (!defined('PHP_DIGESTS_CRON'))
  26. {
  27. // Comment this line to allow execution of mail_digests.php from address bar.
  28. // Decomment it to block the execution
  29. die('This file cannot be run directly...');
  30. define('IN_ICYPHOENIX', true);
  31. if (!defined('IP_ROOT_PATH')) define('IP_ROOT_PATH', './');
  32. if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
  33. include(IP_ROOT_PATH . 'common.' . PHP_EXT);
  34. // Start session management
  35. $user->session_begin();
  36. $auth->acl($user->data);
  37. $user->setup();
  38. // End session management
  39. if (empty($config['cron_digests_interval']) || ($config['cron_digests_interval'] == -1))
  40. {
  41. message_die(GENERAL_MESSAGE, $lang['Not_Auth_View']);
  42. }
  43. }
  44. if (!defined('IN_ICYPHOENIX'))
  45. {
  46. die('Hacking attempt');
  47. }
  48. // COMMON INCLUSIONS WHERE NEEDED - BEGIN
  49. // Comment at least the whole "IF" if you are going to run this file outside Icy Phoenix
  50. if (!defined('IN_CRON'))
  51. {
  52. if (!defined('IP_ROOT_PATH')) define('IP_ROOT_PATH', './');
  53. if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
  54. if (!defined('ICYPHOENIX_VERSION')) @include(IP_ROOT_PATH . 'includes/constants.' . PHP_EXT);
  55. if (!function_exists('append_sid')) @include(IP_ROOT_PATH . 'includes/functions.' . PHP_EXT);
  56. if (!function_exists('check_mem_limit')) @include(IP_ROOT_PATH . 'includes/functions_admin.' . PHP_EXT);
  57. if (!function_exists('auth')) @include(IP_ROOT_PATH . 'includes/auth.' . PHP_EXT);
  58. if (!defined('PHP_DIGESTS_FUNCTIONS_CRON')) @include(IP_ROOT_PATH . 'includes/functions_cron.' . PHP_EXT);
  59. if (empty($user->data))
  60. {
  61. // Start session management
  62. $user->session_begin();
  63. $auth->acl($user->data);
  64. $user->setup();
  65. // End session management
  66. }
  67. if (($config['url_rw'] || $config['url_rw_guests']) && !function_exists('make_url_friendly'))
  68. {
  69. @include_once(IP_ROOT_PATH . 'includes/functions_rewrite.' . PHP_EXT);
  70. }
  71. }
  72. if (!class_exists('bbcode') || empty($bbcode))
  73. {
  74. @include_once(IP_ROOT_PATH . 'includes/bbcode.' . PHP_EXT);
  75. }
  76. if (!class_exists('emailer')) @include(IP_ROOT_PATH . 'includes/emailer.' . PHP_EXT);
  77. if (!defined('DIGEST_VERSION')) @include(IP_ROOT_PATH . 'includes/digest_constants.' . PHP_EXT);
  78. setup_extra_lang(array('lang_digests'));
  79. // COMMON INCLUSIONS WHERE NEEDED - BEGIN
  80. @set_time_limit(0);
  81. $mem_limit = check_mem_limit();
  82. @ini_set('memory_limit', $mem_limit);
  83. ignore_user_abort();
  84. $link_tag = '';
  85. $link_tag_unset = true;
  86. //$break_type = (DIGEST_SHOW_SUMMARY_TYPE == 'html') ? "<br />\r\n" : "\r\n";
  87. $break_type = (DIGEST_SHOW_SUMMARY_TYPE == 'html') ? "<br />\n" : "\n";
  88. $line_break = "\n";
  89. $digest_log_entry = '';
  90. // Is today the day to run the weekly digest?
  91. $today = @getdate();
  92. $wday = $today['wday'];
  93. $current_hour = $today['hours'];
  94. $weekly_digest_text = ($wday == DIGEST_WEEKLY_DIGEST_DAY) ? " or (digest_type = 'WEEK' and send_hour = " . $current_hour . ")" : "";
  95. // Retrieve a list of forum_ids that all registered users can access. Since digests go only to registered users it's important to include those forums not accessible to the general public but accessible to users.
  96. $sql = 'SELECT forum_id FROM ' . FORUMS_TABLE . ' WHERE auth_read IN (' . AUTH_ALL . ', ' . AUTH_REG . ') AND forum_type = ' . FORUM_POST;
  97. $result = $db->sql_query($sql);
  98. $i = 0;
  99. while ($row = $db->sql_fetchrow($result))
  100. {
  101. $valid_forums[$i] = $row['forum_id'];
  102. $i++;
  103. }
  104. $db->sql_freeresult($result);
  105. // Send a user a weekly digest only if it is the correct day and hour of the week for a weekly digest, and any daily digest if the current hour of the day is the same as the hour wanted for the digest.
  106. /*
  107. $sql = "SELECT s.user_id, u.username, u.user_email, u.user_lastvisit, u.user_lang, s.digest_type, s.format, s.show_text, s.show_mine, s.new_only, s.send_on_no_messages, s.send_hour, s.text_length
  108. FROM " . DIGEST_SUBSCRIPTIONS_TABLE . ' s, ' . USERS_TABLE . " u
  109. WHERE s.user_id = u.user_id
  110. AND s.user_id = 2";
  111. */
  112. $sql = "SELECT s.user_id, u.username, u.user_email, u.user_lastvisit, u.user_lang, s.digest_type, s.format, s.show_text, s.show_mine, s.new_only, s.send_on_no_messages, s.send_hour, s.text_length
  113. FROM " . DIGEST_SUBSCRIPTIONS_TABLE . " s, " . USERS_TABLE . " u
  114. WHERE s.user_id = u.user_id AND ((digest_type = 'DAY' AND send_hour = " . $current_hour . ")" . $weekly_digest_text . ")";
  115. $result = $db->sql_query($sql);
  116. // With each pass through the loop one user will receive a customized digest.
  117. $digests_sent = 0;
  118. while ($row = $db->sql_fetchrow($result))
  119. {
  120. // This logic ensures the hour the user wanted to receive the digest is reported correctly in the digest.
  121. $user_timezone = (float) $row['user_timezone'];
  122. $offset = $board_timezone - $user_timezone;
  123. $send_hour = (float) $row['send_hour'] - $offset;
  124. if ($send_hour < 0)
  125. {
  126. $send_hour = $send_hour + 24;
  127. }
  128. elseif ($send_hour >= 24)
  129. {
  130. $send_hour = $send_hour - 24;
  131. }
  132. if ($row['new_only'] == 'TRUE')
  133. {
  134. // To filter out any possible messages a user may have seen we need to examine a number of
  135. // possibilities, including last user message date/time, date/time of last session, if it exists, and
  136. // of course, the last access date/time in the USERS table. Of these 3 possibilities, whichever is
  137. // the greatest value is the actual last accessed date, and we may need to filter out messages
  138. // prior to this date and time. My experience is phpBB doesn't always get it right.
  139. $sql3 = "SELECT max(post_time) AS last_post_date
  140. FROM " . POSTS_TABLE . "
  141. WHERE poster_id = " . $row['user_id'];
  142. $result3 = $db->sql_query($sql3);
  143. $row3 = $db->sql_fetchrow($result3);
  144. $last_post_date = ($row3['last_post_date'] <> '') ? $row3['last_post_date'] : 0;
  145. $db->sql_freeresult($result3);
  146. // When did the user's last session accessed?
  147. $sql3 = "SELECT max(session_time) AS last_session_date
  148. FROM " . SESSIONS_TABLE . "
  149. WHERE session_user_id = " . $row['user_id'];
  150. $result3 = $db->sql_query($sql3);
  151. $row3 = $db->sql_fetchrow($result3);
  152. $last_session_date = ($row3['last_session_date'] <> '') ? $row3['last_session_date'] : 0;
  153. $db->sql_freeresult($result3);
  154. $last_visited_date = $row['user_lastvisit'];
  155. if ($last_visited_date == '')
  156. {
  157. $last_visited_date = 0;
  158. }
  159. // The true last visit date is the greatest of: last_visited_date, last message posted, and last session date
  160. $last_visited_date = max($last_post_date, $last_session_date, $last_visited_date);
  161. }
  162. // Get a list of forums that can only be read if user has been granted explicit permission
  163. $i = 0;
  164. $elected_forums = array();
  165. $sql3 = "SELECT distinct a.forum_id
  166. FROM " . AUTH_ACCESS_TABLE . " a, " . USER_GROUP_TABLE . " ug
  167. WHERE ug.user_id = " . $row['user_id'] . "
  168. AND ug.user_pending = 0
  169. AND a.group_id = ug.group_id";
  170. $result3 = $db->sql_query($sql3);
  171. while ($row3 = $db->sql_fetchrow($result3))
  172. {
  173. $elected_forums [$i] = $row3['forum_id'];
  174. $i++;
  175. }
  176. $db->sql_freeresult($result3);
  177. // Get the union of the valid_forums array and the elected_formus array. The resulting elements are
  178. // the forums that could be queried. This is necessary because MySQL doesn't support SQL Unions (yet).
  179. $queried_forums = array_merge($valid_forums, $elected_forums);
  180. $queried_forums = array_unique($queried_forums);
  181. // Further filter the number of messages sent by including only forums from which the user
  182. // specifically wants to get emails. If there are none, assume all.
  183. $i = 0;
  184. $subscribed_forums = '';
  185. $sql3 = "SELECT forum_id
  186. FROM " . DIGEST_SUBSCRIBED_FORUMS_TABLE . "
  187. WHERE user_id = " . $row['user_id'];
  188. $result3 = $db->sql_query($sql3);
  189. while ($row3 = $db->sql_fetchrow($result3))
  190. {
  191. $subscribed_forums [$i] = $row3['forum_id'];
  192. $i++;
  193. }
  194. $db->sql_freeresult($result3);
  195. // If there are subscribed forums, we only want to see messages for these forums.
  196. if ($i <> 0)
  197. {
  198. $queried_forums = array_intersect($queried_forums, $subscribed_forums);
  199. }
  200. // Create a list of forums to be queried from the database. This is a comma delimited list of all forums
  201. // the user is allowed to read that can be used with the SQL IN operation.
  202. $forums_list = implode(',', $queried_forums);
  203. if (empty($forums_list))
  204. {
  205. continue;
  206. }
  207. // Format sender's email address (SMTP seems to have a problem with adding username)
  208. $to = ($config['smtp_delivery']) ? $row['user_email'] : $row['username'] . ' <' . $row['user_email'] . '>';
  209. // Show the text of the message?
  210. $show_text = ($row['show_text'] == 'YES') ? true: false;
  211. // Show messages written by this user?
  212. $show_mine = ($row['show_mine'] == 'YES') ? true: false;
  213. // Prepare to get digest type
  214. if($row['digest_type'] == 'DAY')
  215. {
  216. $msg_period = $lang['digest_period_24_hrs'];
  217. $period = time() - (24 * 60 * 60);
  218. }
  219. else
  220. {
  221. $msg_period = $lang['digest_period_1_week'];
  222. $period = time() - (7 * 24 * 60 * 60);
  223. }
  224. // Format differently if HTML requests
  225. if($row['format'] == 'HTML')
  226. {
  227. $html = true;
  228. $parastart = '<p>';
  229. $paraend = '</p>' . $line_break;
  230. }
  231. else
  232. {
  233. $html = false;
  234. $parastart = '';
  235. $paraend = $line_break . $line_break;
  236. }
  237. // Set part of SQL needed to retrieve new only, or messages through the selected period
  238. if ($row['new_only'] == 'TRUE')
  239. {
  240. $code = max($period, $last_visited_date);
  241. }
  242. else
  243. {
  244. $code = $period;
  245. }
  246. // Filter out user's own postings, if they so elected
  247. if ($show_mine == false)
  248. {
  249. $code .= ' and p.poster_id <> ' . $row['user_id'];
  250. }
  251. // The emailer class does not have the equivalent of the assign_block_vars operation, so the
  252. // entire digest must be placed inside a variable.
  253. $msg = '';
  254. // Create a list of messages for this user that presumably have not been seen.
  255. // Filter out unauthorized forums.
  256. $sql2 = "SELECT f.forum_name, t.topic_title, u.username AS 'Posted by', p.post_time, p.post_text, p.post_id, t.topic_id, f.forum_id
  257. FROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f, " . USERS_TABLE . " u
  258. WHERE p.topic_id = t.topic_id
  259. AND t.forum_id = f.forum_id
  260. AND p.poster_id = u.user_id
  261. AND f.forum_type = " . FORUM_POST . "
  262. AND p.post_time > " . $code . "
  263. AND f.forum_id IN (" . $forums_list . ")
  264. ORDER BY f.forum_order, t.topic_title, p.post_time";
  265. // Uncomment next line to see SQL used
  266. // $msg .= "**DEBUG**\r\n' . $sql2 . '\r\n**DEBUG**\r\n";
  267. $result2 = $db->sql_query($sql2);
  268. // Format all the mail for this user
  269. $last_forum = '';
  270. $last_topic = '';
  271. $msg_count = 0;
  272. while ($row2 = $db->sql_fetchrow($result2))
  273. {
  274. // Calculate Display Time
  275. $display_time = date(DIGEST_DATE_FORMAT, $row2['post_time']);
  276. // Format Post Text
  277. $post_text = (strlen($row2['post_text']) <= $row['text_length']) ? $row2['post_text'] : substr($row2['post_text'], 0, $row['text_length']) . '...';
  278. // Close table if topic is changed
  279. if (($row2['topic_title'] <> $last_topic) && $html && ($last_topic <> ''))
  280. {
  281. $msg .= '</table><br /><br />' . $line_break;
  282. }
  283. // Show name of forum only if it changes
  284. if ($row2['forum_name'] <> $last_forum)
  285. {
  286. if (!empty($config['url_rw']))
  287. {
  288. $forum_url = DIGEST_SITE_URL . str_replace ('--', '-', make_url_friendly($row2['forum_name']) . '-vf' . $row2['forum_id'] . '.html');
  289. }
  290. else
  291. {
  292. $forum_url = DIGEST_SITE_URL . CMS_PAGE_VIEWFORUM . '?' . POST_FORUM_URL . '=' . $row2['forum_id'];
  293. }
  294. if ($html)
  295. {
  296. if ($last_forum <> '')
  297. {
  298. //$msg .= '</table><br /><hr /><br />' . $line_break;
  299. $msg .= '<br /><hr /><br />' . $line_break;
  300. }
  301. $msg .= '<h2>' . $lang['digest_forum'] . '<a href="' . $forum_url . '">' . $row2['forum_name'] . '</a></h2>' . $line_break;
  302. }
  303. else
  304. {
  305. $msg .= $line_break . "<<<< " . $lang['digest_forum'] . ' ' . $row2['forum_name'] . ', ' . $forum_url . " >>>>" . $line_break;
  306. }
  307. }
  308. // Show name of topic only if it changes
  309. if ($row2['topic_title'] <> $last_topic)
  310. {
  311. if (!empty($config['url_rw']))
  312. {
  313. $topic_url = DIGEST_SITE_URL . str_replace ('--', '-', make_url_friendly($row2['topic_title']) . '-vt' . $row2['topic_id'] . '.html');
  314. }
  315. else
  316. {
  317. $topic_url = DIGEST_SITE_URL . CMS_PAGE_VIEWTOPIC . '?' . POST_TOPIC_URL . '=' . $row2['topic_id'];
  318. }
  319. if ($html)
  320. {
  321. $msg .= '<h3>' . $lang['digest_topic'] . '<a href="' . $topic_url . '">' . $row2['topic_title'] . '</a></h3>' . $line_break;
  322. $msg .= '<table class="forumline tw98pct">' . $line_break;
  323. }
  324. else
  325. {
  326. $msg .= $line_break . "<< " . $lang['digest_topic'] . ' ' . $row2['topic_title'] . ', ' . $topic_url . " >>" . $line_break . $line_break;
  327. }
  328. }
  329. // Show message information
  330. if (!empty($config['url_rw']))
  331. {
  332. $post_url = DIGEST_SITE_URL . str_replace ('--', '-', make_url_friendly($row2['topic_title']) . '-vp' . $row2['post_id'] . '.html#p' . $row2['post_id']);
  333. }
  334. else
  335. {
  336. $post_url = DIGEST_SITE_URL . CMS_PAGE_VIEWTOPIC . '?' . POST_POST_URL . '=' . $row2['post_id'] . '#p' . $row2['post_id'];
  337. }
  338. if ($html)
  339. {
  340. $msg .= '<tr>' . $line_break;
  341. $msg .= '<th style="text-align: left;">' . $lang['digest_link'] . ': <a href="' . $post_url . '">' . $row2['post_id'] . '</a> - ' . $lang['digest_post_time'] . ': ' . $display_time . ' ' . gmdate('T', $row2['post_time']) . ' - ' . $lang['digest_author'] . ': ' . $row2['Posted by'] . '</th>' . $line_break;
  342. $msg .= '</tr>' . $line_break;
  343. if ($show_text)
  344. {
  345. /*
  346. // Remove BBCode and replace \n with <br />, makes for nicer presentation
  347. $this_msg = '<td>' . preg_replace('/\[\S+\]/', '', $post_text) . '</td>';
  348. $this_msg = preg_replace('/\\n/', '<br />', $this_msg);
  349. $msg .= $this_msg . $line_break;
  350. */
  351. $bbcode->allow_html = (isset($config['allow_html']) ? $config['allow_html'] : false);
  352. $bbcode->allow_bbcode = (isset($config['allow_bbcode']) ? $config['allow_bbcode'] : true);
  353. $bbcode->allow_smilies = (isset($config['allow_smilies']) ? $config['allow_smilies'] : true);
  354. $post_text = $bbcode->parse($post_text);
  355. $this_msg = '<td class="row1"><div class="post-text">' . $post_text . '</div></td>';
  356. if (empty($bbcode->allow_bbcode))
  357. {
  358. $this_msg = str_replace("\n", "<br />", preg_replace("/\r\n/", "\n", $this_msg));
  359. }
  360. $msg .= '<tr>' . $line_break;
  361. $msg .= $this_msg . $line_break;
  362. $msg .= '</tr>' . $line_break;
  363. $msg .= '<tr>' . $line_break;
  364. $msg .= '<td class="row2"><div class="post-text">&nbsp;</div></td>' . $line_break;
  365. $msg .= '</tr>' . $line_break;
  366. }
  367. }
  368. else
  369. {
  370. $msg .= $lang['digest_posted_by'] . $row2['Posted by'] . $lang['digest_posted_at'] . $display_time . ' ' . gmdate('T', $row2['post_time']) .
  371. ', ' . $post_url . '' . $line_break;
  372. // If requested to show the message text
  373. if ($show_text)
  374. {
  375. if (strlen($post_text) < ($row['text_length'] + 3))
  376. {
  377. $msg .= $post_text . $line_break;
  378. }
  379. else
  380. {
  381. // Remove BBCode, makes for nicer presentation
  382. $msg .= $lang['digest_message_excerpt'] . ': ' . preg_replace('/\[\S+\]/', '', $post_text) . $line_break;
  383. }
  384. $msg .= $line_break . '------------------------------' . $line_break;
  385. }
  386. }
  387. // If the forum has changed, note the change
  388. if ($row2['forum_name'] <> $last_forum)
  389. {
  390. $last_forum = $row2['forum_name'];
  391. }
  392. if ($row2['topic_title'] <> $last_topic)
  393. {
  394. $last_topic = $row2['topic_title'];
  395. }
  396. $msg_count++;
  397. }
  398. $db->sql_freeresult($result2);
  399. if ($html && ($last_topic <> ''))
  400. {
  401. $msg .= '</table>' . $line_break;
  402. }
  403. if ($msg_count == 0)
  404. {
  405. $msg .= $parastart . $lang['digest_no_new_messages'] . $paraend;
  406. }
  407. // Send the email if there are messages or if user selected to send email anyhow
  408. if (($msg_count > 0) || ($row['send_on_no_messages'] == 'YES'))
  409. {
  410. if (!is_object($emailer))
  411. {
  412. $emailer = new emailer();
  413. }
  414. $emailer->use_template('mail_digests', $row['user_lang']);
  415. if ($html)
  416. {
  417. // Apply a style sheet if requested for HTML digest. If no style sheet is wanted then the
  418. // link tag pointing to the style sheet is not displayed. A custom style sheet gets first priority.
  419. /*
  420. if ($link_tag_unset)
  421. {
  422. $stylesheet = '';
  423. if (DIGEST_USE_CUSTOM_STYLESHEET)
  424. {
  425. $stylesheet = DIGEST_CUSTOM_STYLESHEET_PATH;
  426. }
  427. elseif (DIGEST_USE_DEFAULT_STYLESHEET)
  428. {
  429. // Get the default style sheet to apply to the HTML email
  430. $sql2 = 'SELECT style_name, head_stylesheet
  431. FROM ' . THEMES_TABLE . '
  432. WHERE themes_id = ' . $config['default_style'];
  433. $result2 = $db->sql_query($sql2);
  434. $row2 = $db->sql_fetchrow($result2);
  435. $stylesheet = 'templates/' . $row2['style_name'] . '/' . $row2['head_stylesheet'];
  436. $db->sql_freeresult($result2);
  437. }
  438. if ($stylesheet <> '')
  439. {
  440. $link_tag = '<link rel="stylesheet" type="text/css" href="' . DIGEST_SITE_URL . $stylesheet . '" />';
  441. }
  442. $link_tag_unset = false;
  443. }
  444. */
  445. }
  446. $encoding_charset = !empty($lang['ENCODING']) ? $lang['ENCODING'] : 'UTF-8';
  447. $config['html_email'] = $html;
  448. $emailer->from = $lang['digest_from_text_name'] . ' <' . $lang['digest_from_email_address'] . '>';
  449. $emailer->to($to);
  450. $emailer->set_subject($lang['digest_subject_line']);
  451. $emailer->assign_vars(array(
  452. 'BOARD_URL' => DIGEST_SITE_URL,
  453. 'LINK' => $link_tag,
  454. 'L_SITENAME' => $config['sitename'],
  455. 'L_SALUTATION' => $lang['digest_salutation'],
  456. 'SALUTATION' => $row['username'],
  457. 'L_DIGEST_OPTIONS' => $lang['digest_your_digest_options'],
  458. 'L_INTRODUCTION' => $lang['digest_introduction'],
  459. 'L_FORMAT' => $lang['digest_format_short'],
  460. 'FORMAT' => $row['format'],
  461. 'L_MESSAGE_TEXT' => $lang['digest_show_message_text'],
  462. 'MESSAGE_TEXT' => $row['show_text'],
  463. 'L_MY_MESSAGES' => $lang['digest_show_my_messages'],
  464. 'MY_MESSAGES' => $row['show_mine'],
  465. 'L_FREQUENCY' => $lang['digest_frequency'],
  466. 'FREQUENCY' => $row['digest_type'],
  467. 'L_NEW_MESSAGES' => $lang['digest_show_only_new_messages'],
  468. 'NEW_MESSAGES' => $row['new_only'],
  469. 'L_SEND_DIGEST' => $lang['digest_send_if_no_new_messages'],
  470. 'SEND_DIGEST' => $row['send_on_no_messages'],
  471. 'L_SEND_TIME' => $lang['digest_hour_to_send_short'],
  472. 'SEND_TIME' => gmdate('g A', gmmktime($send_hour)),
  473. 'DIGEST_CONTENT' => $msg,
  474. 'DISCLAIMER' => ($html) ? $lang['digest_disclaimer_html'] : $lang['digest_disclaimer_text'],
  475. 'L_TEXT_LENGTH' => $lang['digest_message_size'],
  476. 'TEXT_LENGTH' => $row['text_length'],
  477. 'L_VERSION' => $lang['digest_version_text'],
  478. 'VERSION' => DIGEST_VERSION
  479. )
  480. );
  481. $emailer->send($html);
  482. $emailer->reset();
  483. $digests_sent++;
  484. }
  485. // Normally this is run as a batch job, but it can be useful to get summary information of what was sent and to whom.
  486. if (DIGEST_SHOW_SUMMARY)
  487. {
  488. $digest_log_entry .= $lang['digest_a_digest_containing'] . ' ' . $msg_count . ' ' . $lang['digest_posts_was_sent_to'] . ' ' . $row['user_email'] . $break_type;
  489. }
  490. }
  491. $db->sql_freeresult($result);
  492. // Summary information normally not seen, but can be captured via command line to a file
  493. if (DIGEST_SHOW_SUMMARY)
  494. {
  495. $summary_content = '';
  496. if (DIGEST_SHOW_SUMMARY_TYPE == 'html')
  497. {
  498. $summary_content .= '<html>' . $line_break;
  499. $summary_content .= '<head>' . $line_break;
  500. $summary_content .= '<title>' . $lang['digest_summary'] . '</title>' . $line_break;
  501. $summary_content .= '</head>' . $line_break;
  502. $summary_content .= '<body>' . $line_break;
  503. $summary_content .= '<h1>' . $lang['digest_summary'] . '</h1>' . $line_break;
  504. }
  505. $summary_content .= $digest_log_entry;
  506. if (DIGEST_SHOW_SUMMARY_TYPE == 'html')
  507. {
  508. $summary_content .= '<hr />' . $line_break;
  509. }
  510. $summary_content .= $lang['digest_a_total_of'] . ' ' . $digests_sent . ' ' . $lang['digest_were_emailed'] . $break_type;
  511. $summary_content .= $lang['digest_server_date'] . ' ' . gmdate(DIGEST_SERVER_DATE_DISPLAY) . $break_type;
  512. $summary_content .= $lang['digest_server_hour'] . ' ' . gmdate('H') . $break_type;
  513. $summary_content .= $lang['digest_server_time_zone'] . ' ' . gmdate('Z') / 3600 . ' ' . $lang['digest_or'] . ' ' . gmdate('T') . $break_type;
  514. if (DIGEST_SHOW_SUMMARY_TYPE == 'html')
  515. {
  516. $summary_content .= '</body>' . $line_break;
  517. $summary_content .= '</html>' . $line_break;
  518. }
  519. if (!defined('PHP_DIGESTS_CRON'))
  520. {
  521. echo($summary_content);
  522. }
  523. else
  524. {
  525. // MG Digests LOG - BEGIN
  526. if (!empty($config['write_digests_log']))
  527. {
  528. //echo($summary_content);
  529. $datecode = gmdate('Ymd');
  530. $logs_path = !empty($config['logs_path']) ? $config['logs_path'] : 'logs';
  531. $logdigests = $logs_path . '/digests_' . $datecode . '.txt';
  532. $date = gmdate('Y/m/d - H:i:s');
  533. $log_message = '[' . $date . ']' . $line_break . $line_break;
  534. $log_message .= $summary_content;
  535. $log_message .= $line_break . $line_break;
  536. $log_message .= '________________________________________________';
  537. $log_message .= $line_break . $line_break;
  538. $fp = fopen($logdigests, "a+");
  539. fwrite($fp, $log_message);
  540. fclose($fp);
  541. }
  542. // MG Digests LOG - END
  543. }
  544. }
  545. set_config('cron_digests_last_run', time());
  546. set_config('cron_lock_hour', 0);
  547. ?>