| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * |
|---|
| 4 | * @package phpBB3 |
|---|
| 5 | * @version $Id: mail_digests.php, v 2.0.0 Production 2008/07/06 mark@phpbbservices.com Exp $ |
|---|
| 6 | * @copyright (c) Mark D. Hamill (mhamill@computer.org, http://phpbbservices.com) |
|---|
| 7 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|---|
| 8 | * |
|---|
| 9 | */ |
|---|
| 10 | |
|---|
| 11 | /** |
|---|
| 12 | * @ignore |
|---|
| 13 | */ |
|---|
| 14 | |
|---|
| 15 | // Written by Mark D. Hamill, mhamill@computer.org, http://phpbbservices.com |
|---|
| 16 | // This software is designed to work with phpBB Version 3.0.4. |
|---|
| 17 | |
|---|
| 18 | // This is the e-mailing software for the Digests mod. It sends out daily or weekly |
|---|
| 19 | // digests based on settings created by users in the user control panel and stored in the |
|---|
| 20 | // phpbb_users table. It is typically called hourly by the operating system. |
|---|
| 21 | |
|---|
| 22 | define('IN_PHPBB', true); |
|---|
| 23 | $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './'; |
|---|
| 24 | $phpEx = substr(strrchr(__FILE__, '.'), 1); |
|---|
| 25 | include($phpbb_root_path . 'common.' . $phpEx); |
|---|
| 26 | include($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); // Used to send emails |
|---|
| 27 | |
|---|
| 28 | // Added by zhongzhen for ticket 263 to get wiki featured article on 2010-06-18 |
|---|
| 29 | require_once( dirname(__file__) . '/../common/omconfig.php' ); |
|---|
| 30 | require_once( FS_COMMON_DIRECTORY.'/utils.php'); |
|---|
| 31 | require_once (dirname(__file__) . '/../home/includes/classes/DB.php' ); |
|---|
| 32 | require_once(dirname(__file__) . '/../home/portlets/PortletsClass.php'); |
|---|
| 33 | //require_once('w/includes/templates/Userlogin.php'); |
|---|
| 34 | |
|---|
| 35 | $oDb = &newDb( 'wiki',true ); |
|---|
| 36 | $ArticlePortlet = new ArticlePortlet($oDb); |
|---|
| 37 | |
|---|
| 38 | // Start session management |
|---|
| 39 | $user->session_begin(); |
|---|
| 40 | $auth->acl($user->data); |
|---|
| 41 | $user->setup('mods/ucp_digests'); |
|---|
| 42 | |
|---|
| 43 | // Set the log file end of line delimiter |
|---|
| 44 | switch ($config['digests_log_eol']) |
|---|
| 45 | { |
|---|
| 46 | case DIGEST_HTML_VALUE: |
|---|
| 47 | $eol = "<br />\n"; |
|---|
| 48 | break; |
|---|
| 49 | case DIGEST_UNIX_VALUE: |
|---|
| 50 | $eol = "\n"; |
|---|
| 51 | break; |
|---|
| 52 | case DIGEST_WINDOWS_VALUE: |
|---|
| 53 | $eol = "\r\n"; |
|---|
| 54 | break; |
|---|
| 55 | case DIGEST_MAC_VALUE: |
|---|
| 56 | $eol = "\r"; |
|---|
| 57 | break; |
|---|
| 58 | default: |
|---|
| 59 | echo sprintf($user->lang['DIGEST_BAD_EOL'], $config['digests_log_eol']); |
|---|
| 60 | exit; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | // If the board is currently disabled, digests should also be disabled, don't ya think? |
|---|
| 64 | if ($config['board_disable']) |
|---|
| 65 | { |
|---|
| 66 | write_log_entry($user->lang['DIGEST_BOARD_DISABLED'], true); |
|---|
| 67 | exit; |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | // If the key parameter is enabled, validate the key parameter. If the parameter value does not match its required key, exit with an error. |
|---|
| 71 | if ($config['digests_require_key']) |
|---|
| 72 | { |
|---|
| 73 | $supplied_key = (isset($_GET['key'])) ? htmlspecialchars($_GET['key']) : ''; |
|---|
| 74 | if (trim($supplied_key) != trim($config['digests_key_value'])) |
|---|
| 75 | { |
|---|
| 76 | write_log_entry(sprintf($user->lang['DIGEST_BAD_KEY_VALUE'], $supplied_key, date($config['default_dateformat'], time())), true); |
|---|
| 77 | exit; |
|---|
| 78 | } |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | // Display a digest mail start processing message. It may get captured in a log |
|---|
| 82 | write_log_entry(sprintf($user->lang['DIGEST_START'],date($config['default_dateformat']))); |
|---|
| 83 | |
|---|
| 84 | // Need a board URL since URLs pointing to the board need to be absolute URLs |
|---|
| 85 | $board_url = generate_board_url() . '/'; |
|---|
| 86 | |
|---|
| 87 | // Is today the day to run the weekly digest? |
|---|
| 88 | $weekday_gmt = gmdate('w'); // 0 = Sunday, 6 = Saturday |
|---|
| 89 | $current_hour_gmt = gmdate('G'); // 0 thru 23 |
|---|
| 90 | $current_hour_gmt_plus_30 = gmdate('G') + .5; // 0 thru 23 |
|---|
| 91 | if ($current_hour_gmt_plus_30 == 24) |
|---|
| 92 | { |
|---|
| 93 | $current_hour_gmt_plus_30 = 0; // A very unlikely situation |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | $weekly_digest_sql = ($weekday_gmt == $config['digests_weekly_digest_day']) ? " OR (user_digest_type = '" . DIGEST_WEEKLY_VALUE . "' AND (user_digest_send_hour_gmt = $current_hour_gmt OR user_digest_send_hour_gmt = $current_hour_gmt_plus_30))" : ''; |
|---|
| 97 | |
|---|
| 98 | // We need to know which auth_option_id corresponds to the forum read privilege (f_read), so let's do it here just once. |
|---|
| 99 | $sql = 'SELECT auth_option_id |
|---|
| 100 | FROM ' . ACL_OPTIONS_TABLE . " |
|---|
| 101 | WHERE auth_option = 'f_read'"; |
|---|
| 102 | $result = $db->sql_query($sql); |
|---|
| 103 | $row = $db->sql_fetchrow($result); |
|---|
| 104 | $read_id = $row['auth_option_id']; |
|---|
| 105 | |
|---|
| 106 | // We also need to know which auth_option_id corresponds to the forum list privilege (f_list), so let's do it here just once. |
|---|
| 107 | $sql = 'SELECT auth_option_id |
|---|
| 108 | FROM ' . ACL_OPTIONS_TABLE . " |
|---|
| 109 | WHERE auth_option = 'f_list'"; |
|---|
| 110 | $result = $db->sql_query($sql); |
|---|
| 111 | $row = $db->sql_fetchrow($result); |
|---|
| 112 | $list_id = $row['auth_option_id']; |
|---|
| 113 | |
|---|
| 114 | // Get users requesting digests for the current hour |
|---|
| 115 | $sql = 'SELECT * FROM ' . USERS_TABLE . " WHERE ((user_digest_type = '" . DIGEST_DAILY_VALUE . "' AND (user_digest_send_hour_gmt = $current_hour_gmt OR user_digest_send_hour_gmt = $current_hour_gmt_plus_30))" . $weekly_digest_sql . ") AND user_inactive_reason = 0 AND user_digest_type <> '" . DIGEST_NONE_VALUE . "' ORDER BY user_lang"; |
|---|
| 116 | //$sql = 'SELECT * FROM ' . USERS_TABLE . " WHERE user_digest_type <> '" . DIGEST_NONE_VALUE . "' ORDER BY user_lang"; |
|---|
| 117 | //echo $sql; |
|---|
| 118 | $result = $db->sql_query($sql); |
|---|
| 119 | |
|---|
| 120 | $messenger = new messenger(false); // Send out digests one at a time, not in batch |
|---|
| 121 | |
|---|
| 122 | while ($row = $db->sql_fetchrow($result)) |
|---|
| 123 | { |
|---|
| 124 | // Each traverse through the loop sends out exactly one digest |
|---|
| 125 | |
|---|
| 126 | $digest_type = ($row['user_digest_type'] == DIGEST_DAILY_VALUE) ? $user->lang['DIGEST_DAILY'] : $user->lang['DIGEST_WEEKLY']; |
|---|
| 127 | $email_subject = sprintf($user->lang['DIGEST_SUBJECT_TITLE'], $config['sitename'], $digest_type); |
|---|
| 128 | |
|---|
| 129 | // Change the digest format into something human readable |
|---|
| 130 | switch($row['user_digest_format']) |
|---|
| 131 | { |
|---|
| 132 | case(DIGEST_TEXT_VALUE): |
|---|
| 133 | $format = $user->lang['DIGEST_FORMAT_TEXT']; |
|---|
| 134 | $messenger->template('digests_text'); // Change based on whether text, plain HTML or expanded HTML |
|---|
| 135 | $is_html = false; |
|---|
| 136 | $disclaimer = strip_tags(sprintf($user->lang['DIGEST_DISCLAIMER'], $board_url, $config['sitename'], $board_url, $phpEx, $config['board_contact'], $config['sitename'])); |
|---|
| 137 | $powered_by = $config['digests_digests_title']; |
|---|
| 138 | $use_classic_template = false; |
|---|
| 139 | break; |
|---|
| 140 | case(DIGEST_PLAIN_VALUE): |
|---|
| 141 | $format = $user->lang['DIGEST_FORMAT_PLAIN']; |
|---|
| 142 | $messenger->template('digests_plain_html'); // Change based on whether text, plain HTML or expanded HTML |
|---|
| 143 | $is_html = true; |
|---|
| 144 | $disclaimer = sprintf($user->lang['DIGEST_DISCLAIMER'], $board_url, $config['sitename'], $board_url, $phpEx, $config['board_contact'], $config['sitename']); |
|---|
| 145 | $powered_by = sprintf("<a href=\"%s\">%s</a>",$config['digests_page_url'],$config['digests_digests_title']); |
|---|
| 146 | $use_classic_template = false; |
|---|
| 147 | break; |
|---|
| 148 | case(DIGEST_PLAIN_CLASSIC_VALUE): |
|---|
| 149 | $format = $user->lang['DIGEST_FORMAT_PLAIN_CLASSIC']; |
|---|
| 150 | $messenger->template('digests_plain_html'); // Change based on whether text, plain HTML or expanded HTML |
|---|
| 151 | $is_html = true; |
|---|
| 152 | $disclaimer = sprintf($user->lang['DIGEST_DISCLAIMER'], $board_url, $config['sitename'], $board_url, $phpEx, $config['board_contact'], $config['sitename']); |
|---|
| 153 | $powered_by = sprintf("<a href=\"%s\">%s</a>",$config['digests_page_url'],$config['digests_digests_title']); |
|---|
| 154 | $use_classic_template = true; |
|---|
| 155 | break; |
|---|
| 156 | case(DIGEST_HTML_VALUE): |
|---|
| 157 | $format = $user->lang['DIGEST_FORMAT_HTML']; |
|---|
| 158 | $messenger->template('digests_html'); // Change based on whether text, plain HTML or expanded HTML |
|---|
| 159 | $is_html = true; |
|---|
| 160 | $disclaimer = sprintf($user->lang['DIGEST_DISCLAIMER'], $board_url, $config['sitename'], $config['board_contact'], $config['sitename']); // Changed by zhongzhen for ticket 263 on 2010-06-18 |
|---|
| 161 | $powered_by = sprintf("<a href=\"%s\" style=\"color: #0064B1;\">%s</a>",$board_url,'MIKE2.0 Forums'); // Changed by zhongzhen for ticket 263 on 2010-06-18 |
|---|
| 162 | $use_classic_template = false; |
|---|
| 163 | break; |
|---|
| 164 | case(DIGEST_HTML_CLASSIC_VALUE): |
|---|
| 165 | $format = $user->lang['DIGEST_FORMAT_HTML_CLASSIC']; |
|---|
| 166 | $messenger->template('digests_html'); // Change based on whether text, plain HTML or expanded HTML |
|---|
| 167 | $is_html = true; |
|---|
| 168 | $disclaimer = sprintf($user->lang['DIGEST_DISCLAIMER'], $board_url, $config['sitename'], $board_url, $phpEx, $config['board_contact'], $config['sitename']); |
|---|
| 169 | $powered_by = sprintf("<a href=\"%s\">%s</a>",$config['digests_page_url'],$config['digests_digests_title']); |
|---|
| 170 | $use_classic_template = true; |
|---|
| 171 | break; |
|---|
| 172 | default: |
|---|
| 173 | trigger_error(sprintf($user->lang['DIGEST_FORMAT_ERROR'], $row['user_digest_format'])); |
|---|
| 174 | break; |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | // Set email header information |
|---|
| 178 | $messenger->to($row['user_email']); |
|---|
| 179 | $messenger->from($config['sitename'] . ' ' . $user->lang['DIGEST_ROBOT'] . ' <' . $config['board_email'] . '>'); |
|---|
| 180 | $messenger->subject($email_subject); |
|---|
| 181 | |
|---|
| 182 | // Transform user_digest_send_hour_gmt to local time |
|---|
| 183 | $local_send_hour = $row['user_digest_send_hour_gmt'] + ($row['user_timezone'] + $row['user_dst']); |
|---|
| 184 | if ($local_send_hour >= 24) |
|---|
| 185 | { |
|---|
| 186 | $local_send_hour = $local_send_hour - 24; |
|---|
| 187 | } |
|---|
| 188 | else if ($local_send_hour < 0) |
|---|
| 189 | { |
|---|
| 190 | $local_send_hour = $local_send_hour + 24; |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | if (($local_send_hour >= 24) || ($local_send_hour < 0)) |
|---|
| 194 | { |
|---|
| 195 | trigger_error(sprintf($user->lang['DIGEST_TIME_ERROR'], $row['user_digest_filter_type'])); |
|---|
| 196 | exit; |
|---|
| 197 | } |
|---|
| 198 | |
|---|
| 199 | // Change the filter type into something human readable |
|---|
| 200 | switch($row['user_digest_filter_type']) |
|---|
| 201 | { |
|---|
| 202 | case(DIGEST_ALL): |
|---|
| 203 | $post_types = $user->lang['DIGEST_POSTS_TYPE_ANY']; |
|---|
| 204 | break; |
|---|
| 205 | case(DIGEST_FIRST): |
|---|
| 206 | $post_types = $user->lang['DIGEST_POSTS_TYPE_FIRST']; |
|---|
| 207 | break; |
|---|
| 208 | case(DIGEST_BOOKMARKS): |
|---|
| 209 | $post_types = $user->lang['DIGEST_USE_BOOKMARKS']; |
|---|
| 210 | break; |
|---|
| 211 | default: |
|---|
| 212 | trigger_error(sprintf($user->lang['DIGESTS_FILTER_ERROR'], $row['user_digest_filter_type'])); |
|---|
| 213 | exit; |
|---|
| 214 | } |
|---|
| 215 | |
|---|
| 216 | // Change the sort by into something human readable |
|---|
| 217 | switch ($row['user_digest_sortby']) |
|---|
| 218 | { |
|---|
| 219 | case(DIGEST_SORTBY_BOARD): |
|---|
| 220 | $sort_by = $user->lang['DIGEST_SORT_USER_ORDER']; |
|---|
| 221 | break; |
|---|
| 222 | case(DIGEST_SORTBY_STANDARD): |
|---|
| 223 | $sort_by = $user->lang['DIGEST_SORT_FORUM_TOPIC']; |
|---|
| 224 | break; |
|---|
| 225 | case(DIGEST_SORTBY_STANDARD_DESC): |
|---|
| 226 | $sort_by = $user->lang['DIGEST_SORT_FORUM_TOPIC_DESC']; |
|---|
| 227 | break; |
|---|
| 228 | case(DIGEST_SORTBY_POSTDATE): |
|---|
| 229 | $sort_by = $user->lang['DIGEST_SORT_POST_DATE']; |
|---|
| 230 | break; |
|---|
| 231 | case(DIGEST_SORTBY_POSTDATE_DESC): |
|---|
| 232 | $sort_by = $user->lang['DIGEST_SORT_POST_DATE_DESC']; |
|---|
| 233 | break; |
|---|
| 234 | default: |
|---|
| 235 | trigger_error(sprintf($user->lang['DIGESTS_SORT_BY_ERROR'], $row['user_digest_sortby'])); |
|---|
| 236 | exit; |
|---|
| 237 | } |
|---|
| 238 | |
|---|
| 239 | // Send a proper content-language to the output |
|---|
| 240 | $user_lang = $row['user_lang']; |
|---|
| 241 | if (strpos($user_lang, '-x-') !== false) |
|---|
| 242 | { |
|---|
| 243 | $user_lang = substr($user_lang, 0, strpos($user_lang, '-x-')); |
|---|
| 244 | } |
|---|
| 245 | |
|---|
| 246 | // Create proper message for indicating number of posts allowed in digest |
|---|
| 247 | if (($row['user_digest_max_posts'] == 0) || ($config['digests_max_items'] == 0)) |
|---|
| 248 | { |
|---|
| 249 | $max_posts_msg = $user->lang['DIGEST_NO_LIMIT']; |
|---|
| 250 | } |
|---|
| 251 | else if ($config['digests_max_items'] < $row['user_digest_max_posts']) |
|---|
| 252 | { |
|---|
| 253 | $max_posts_msg = sprintf($user->lang['DIGEST_BOARD_LIMIT'], $config['digests_max_items']); |
|---|
| 254 | } |
|---|
| 255 | else |
|---|
| 256 | { |
|---|
| 257 | $max_posts_msg = $row['user_digest_max_posts']; |
|---|
| 258 | } |
|---|
| 259 | |
|---|
| 260 | $server_timezone = floatval(date('O')/100); |
|---|
| 261 | // Convert server time into GMT time |
|---|
| 262 | $gmt_time = time() - ($server_timezone * 60 * 60); |
|---|
| 263 | // Now adjust GMT time to digest recipient's local time |
|---|
| 264 | $recipient_time = $gmt_time + (($row['user_timezone'] + $row['user_dst']) * 60 * 60); |
|---|
| 265 | |
|---|
| 266 | // Print the non-post information in the digest |
|---|
| 267 | $messenger->assign_vars(array( |
|---|
| 268 | 'DIGEST_DISCLAIMER' => $disclaimer, |
|---|
| 269 | 'DIGEST_FORMAT' => $format, |
|---|
| 270 | 'DIGEST_FREQUENCY' => $digest_type, |
|---|
| 271 | 'DIGEST_MAX_MSG_SIZE' => ($row['user_digest_max_display_words'] == 0) ? $user->lang['DIGEST_NO_LIMIT'] : $row['user_digest_max_display_words'], |
|---|
| 272 | 'DIGEST_MAX_POSTS_IN_DIGESTS' => $max_posts_msg, |
|---|
| 273 | 'DIGEST_MIN_WORDS_IN_DIGEST' => ($row['user_digest_min_words'] == 0) ? $user->lang['DIGEST_NO_CONSTRAINT'] : $row['user_digest_min_words'], |
|---|
| 274 | 'DIGEST_POST_TYPES' => $post_types, |
|---|
| 275 | 'DIGEST_POWERED_BY' => $powered_by, |
|---|
| 276 | 'DIGEST_REMOVE_FOES' => ($row['user_digest_remove_foes'] == 0) ? $user->lang['NO'] : $user->lang['YES'], |
|---|
| 277 | 'DIGEST_RESET_LAST_VISIT' => ($row['user_digest_reset_lastvisit'] == 0) ? $user->lang['NO'] : $user->lang['YES'], |
|---|
| 278 | 'DIGEST_SALUTATION' => $row['username'], |
|---|
| 279 | 'DIGEST_SEND_HOUR' => $user->lang['DIGEST_HOUR'][$local_send_hour], |
|---|
| 280 | 'DIGEST_SEND_IF_NO_NEW_MESSAGES'=> ($row['user_digest_send_on_no_posts'] == 0) ? $user->lang['NO'] : $user->lang['YES'], |
|---|
| 281 | 'DIGEST_SHOW_MY_MESSAGES' => ($row['user_digest_show_mine'] == 0) ? $user->lang['YES'] : $user->lang['NO'], |
|---|
| 282 | 'DIGEST_SHOW_NEW_POSTS_ONLY' => ($row['user_digest_new_posts_only'] == 1) ? $user->lang['YES'] : $user->lang['NO'], |
|---|
| 283 | 'DIGEST_SHOW_PMS' => ($row['user_digest_show_pms'] == 0) ? $user->lang['NO'] : $user->lang['YES'], |
|---|
| 284 | 'DIGEST_SORT_ORDER' => $sort_by, |
|---|
| 285 | 'DIGEST_VERSION' => $config['digests_version'], |
|---|
| 286 | 'L_DIGEST_FORMAT' => $user->lang['DIGEST_FORMAT_FOOTER'], |
|---|
| 287 | 'L_DIGEST_FREQUENCY' => $user->lang['DIGEST_MAIL_FREQUENCY'], |
|---|
| 288 | 'L_DIGEST_INTRODUCTION' => sprintf($user->lang['DIGEST_INTRODUCTION'],$config['sitename']), |
|---|
| 289 | 'L_DIGEST_MAX_MSG_SIZE' => $user->lang['DIGEST_MAX_SIZE'], |
|---|
| 290 | 'L_DIGEST_MAX_POSTS_IN_DIGESTS' => $user->lang['DIGEST_COUNT_LIMIT'], |
|---|
| 291 | 'L_DIGEST_MIN_WORDS_IN_DIGEST' => $user->lang['DIGEST_MIN_SIZE'], |
|---|
| 292 | 'L_DIGEST_OPTIONS' => $user->lang['DIGEST_YOUR_DIGEST_OPTIONS'], |
|---|
| 293 | 'L_DIGEST_POST_TYPES' => $user->lang['DIGEST_FILTER_TYPE'], |
|---|
| 294 | 'L_DIGEST_POWERED_BY' => $user->lang['DIGEST_POWERED_BY'], |
|---|
| 295 | 'L_DIGEST_PUBLISH_DATE' => sprintf($user->lang['DIGEST_PUBLISH_DATE'], date($row['user_dateformat'], $recipient_time)), |
|---|
| 296 | 'L_DIGEST_REMOVE_FOES' => $user->lang['DIGEST_FILTER_FOES'], |
|---|
| 297 | 'L_DIGEST_RESET_LAST_VISIT' => $user->lang['DIGEST_LASTVISIT_RESET'], |
|---|
| 298 | 'L_DIGEST_SALUTATION' => $user->lang['DIGEST_SALUTATION'], |
|---|
| 299 | 'L_DIGEST_SEND_HOUR' => $user->lang['DIGEST_SEND_HOUR'], |
|---|
| 300 | 'L_DIGEST_SEND_IF_NO_NEW_MESSAGES' => $user->lang['DIGEST_SEND_IF_NO_NEW_MESSAGES'], |
|---|
| 301 | 'L_DIGEST_SHOW_MY_MESSAGES' => $user->lang['DIGEST_REMOVE_YOURS'], |
|---|
| 302 | 'L_DIGEST_SHOW_NEW_POSTS_ONLY' => $user->lang['DIGEST_SHOW_NEW_POSTS_ONLY'], |
|---|
| 303 | 'L_DIGEST_SHOW_PMS' => $user->lang['DIGEST_SHOW_PMS'], |
|---|
| 304 | 'L_DIGEST_SORT_ORDER' => $user->lang['DIGEST_SORT_BY'], |
|---|
| 305 | 'L_DIGEST_TITLE' => $email_subject, |
|---|
| 306 | 'L_SITENAME' => $config['sitename'], |
|---|
| 307 | 'S_CONTENT_DIRECTION' => $user->lang['DIRECTION'], |
|---|
| 308 | 'S_USER_LANG' => $user_lang, |
|---|
| 309 | // Opportunity for improvement: use user's stylesheet, not board default, which is what will happen in this context |
|---|
| 310 | 'T_STYLESHEET_LINK' => ($config['digests_enable_custom_stylesheets']) ? "{$board_url}styles/" . $config['digests_custom_stylesheet_path'] : "{$board_url}styles/" . $user->theme['theme_path'] . '/theme/stylesheet.css', |
|---|
| 311 | 'T_THEME_PATH' => "{$board_url}styles/" . $user->theme['theme_path'] . '/theme', |
|---|
| 312 | 'T_FORUM_PATH' => $board_url, // added by zhongzhen for ticket 263 on 2010-06-18 |
|---|
| 313 | )); |
|---|
| 314 | |
|---|
| 315 | // Create SQL stubs |
|---|
| 316 | |
|---|
| 317 | $digest_exception = false; // Used to indicate if the SQL should not be called to fetch posts due to conditions like no bookmarked topics |
|---|
| 318 | |
|---|
| 319 | // Determine how far back one day or one week is from the current time. Beyond this time no posts will be fetched |
|---|
| 320 | if(trim($row['user_digest_type']) == DIGEST_DAILY_VALUE) |
|---|
| 321 | { |
|---|
| 322 | $date_limit = time() - (24 * 60 * 60); |
|---|
| 323 | } |
|---|
| 324 | else // Must be a weekly digest, since NONE has already been filtered out |
|---|
| 325 | { |
|---|
| 326 | $date_limit = time() - (7 * 24 * 60 * 60); |
|---|
| 327 | } |
|---|
| 328 | |
|---|
| 329 | // If requested to fetch new posts since the user's last visit, we need to examine the user_lastvisit date from the database. |
|---|
| 330 | // However, in no event do we want to go back more than either one week or day, depending on the type of digest requested. |
|---|
| 331 | if ($row['user_digest_new_posts_only']) |
|---|
| 332 | { |
|---|
| 333 | $date_limit = max($date_limit, $row['user_lastvisit']); |
|---|
| 334 | } |
|---|
| 335 | $date_limit_sql = ' AND p.post_time > ' . $date_limit; |
|---|
| 336 | |
|---|
| 337 | if ($row['user_digest_filter_type'] == DIGEST_BOOKMARKS) // Bookmarked topics only |
|---|
| 338 | { |
|---|
| 339 | |
|---|
| 340 | // When selecting bookmarked topics only, we can safely ignore the logic constraining the user to read only |
|---|
| 341 | // from certain forums. Instead we will create the SQL to get the bookmarked topics only. |
|---|
| 342 | |
|---|
| 343 | unset($bookmarked_topics); |
|---|
| 344 | $bookmarked_topics = array(); |
|---|
| 345 | $sql2 = 'SELECT t.topic_id |
|---|
| 346 | FROM ' . USERS_TABLE . ' u, ' . BOOKMARKS_TABLE . ' b, ' . TOPICS_TABLE . " t |
|---|
| 347 | WHERE u.user_id = b.user_id AND b.topic_id = t.topic_id |
|---|
| 348 | AND t.topic_last_post_time > $date_limit |
|---|
| 349 | AND b.user_id = " . $row['user_id']; |
|---|
| 350 | $result2 = $db->sql_query($sql2); |
|---|
| 351 | while ($row2 = $db->sql_fetchrow($result2)) |
|---|
| 352 | { |
|---|
| 353 | $bookmarked_topics[] = intval($row2['topic_id']); |
|---|
| 354 | } |
|---|
| 355 | $db->sql_freeresult($result2); |
|---|
| 356 | if (sizeof($bookmarked_topics) > 0) |
|---|
| 357 | { |
|---|
| 358 | $fetched_forums_sql = ' AND ' . $db->sql_in_set('t.topic_id', $bookmarked_topics); |
|---|
| 359 | } |
|---|
| 360 | else |
|---|
| 361 | { |
|---|
| 362 | // Logically, if there are no bookmarked topics for this user_id then there will be nothing in the digest. |
|---|
| 363 | $digest_exception = true; |
|---|
| 364 | $digest_exception_type = $user->lang['DIGEST_NO_BOOKMARKS']; |
|---|
| 365 | } |
|---|
| 366 | } |
|---|
| 367 | |
|---|
| 368 | else |
|---|
| 369 | |
|---|
| 370 | { |
|---|
| 371 | |
|---|
| 372 | // This logic creates some qualifying SQL to retrieve posts only from the correct forums |
|---|
| 373 | |
|---|
| 374 | // Get forum read permissions for this user. They are also usually stored in the user_permissions column, but sometimes the field is empty. This always works. |
|---|
| 375 | unset($allowed_forums); |
|---|
| 376 | $allowed_forums = array(); |
|---|
| 377 | |
|---|
| 378 | $forum_array = $auth->acl_raw_data_single_user($row['user_id']); |
|---|
| 379 | foreach ($forum_array as $key => $value) |
|---|
| 380 | { |
|---|
| 381 | foreach ($value as $auth_option_id => $auth_setting) |
|---|
| 382 | { |
|---|
| 383 | if ($auth_option_id == $read_id) |
|---|
| 384 | { |
|---|
| 385 | if (($auth_setting == 1) && check_all_parents($key)) |
|---|
| 386 | { |
|---|
| 387 | $allowed_forums[] = $key; |
|---|
| 388 | } |
|---|
| 389 | } |
|---|
| 390 | } |
|---|
| 391 | } |
|---|
| 392 | |
|---|
| 393 | if (sizeof($allowed_forums) == 0) |
|---|
| 394 | { |
|---|
| 395 | // If this user cannot retrieve ANY forums, no digest can be produced. |
|---|
| 396 | $digest_exception = true; |
|---|
| 397 | $digest_exception_type = $user->lang['DIGEST_NO_ALLOWED_FORUMS']; |
|---|
| 398 | } |
|---|
| 399 | else |
|---|
| 400 | { |
|---|
| 401 | $allowed_forums[] = 0; // Add in global announcements forum |
|---|
| 402 | } |
|---|
| 403 | |
|---|
| 404 | // Get the requested forums. If none are specified in the phpbb_digests_subscribed_forums table, then all allowed forums are assumed |
|---|
| 405 | unset($requested_forums); |
|---|
| 406 | $requested_forums = array(); |
|---|
| 407 | $sql2 = 'SELECT * FROM ' . DIGESTS_SUBSCRIBED_FORUMS_TABLE . ' |
|---|
| 408 | WHERE user_id = ' . $row['user_id']; |
|---|
| 409 | |
|---|
| 410 | $result2 = $db->sql_query($sql2); |
|---|
| 411 | while ($row2 = $db->sql_fetchrow($result2)) |
|---|
| 412 | { |
|---|
| 413 | $requested_forums[] = $row2['forum_id']; |
|---|
| 414 | } |
|---|
| 415 | $db->sql_freeresult($result2); |
|---|
| 416 | |
|---|
| 417 | // To capture global announcements when forums are specified, we have to add the pseudo-forum with a forum_id = 0. |
|---|
| 418 | if (sizeof($requested_forums) > 0) |
|---|
| 419 | { |
|---|
| 420 | $requested_forums[] = 0; |
|---|
| 421 | } |
|---|
| 422 | |
|---|
| 423 | // Ensure there are no duplicates |
|---|
| 424 | $requested_forums = array_unique($requested_forums); |
|---|
| 425 | |
|---|
| 426 | // The forums that will be fetched is the array intersection of the requested and allowed forums. |
|---|
| 427 | $fetched_forums = (sizeof($requested_forums) > 0) ? array_intersect($allowed_forums, $requested_forums): $allowed_forums; |
|---|
| 428 | asort($fetched_forums); |
|---|
| 429 | if (sizeof($fetched_forums) == 0) |
|---|
| 430 | { |
|---|
| 431 | $digest_exception = true; |
|---|
| 432 | $digest_exception_type = $user->lang['DIGEST_NO_ALLOWED_FORUMS']; |
|---|
| 433 | $fetched_forums_sql = ''; |
|---|
| 434 | } |
|---|
| 435 | else |
|---|
| 436 | { |
|---|
| 437 | $fetched_forums_sql = ' AND ' . $db->sql_in_set('p.forum_id', $fetched_forums); |
|---|
| 438 | } |
|---|
| 439 | |
|---|
| 440 | } |
|---|
| 441 | |
|---|
| 442 | // Create the SQL stub for the sort order |
|---|
| 443 | switch($row['user_digest_sortby']) |
|---|
| 444 | { |
|---|
| 445 | case DIGEST_SORTBY_BOARD: |
|---|
| 446 | $topic_asc_desc = ($row['user_topic_sortby_dir'] == 'd') ? 'DESC' : ''; |
|---|
| 447 | switch($row['user_topic_sortby_type']) |
|---|
| 448 | { |
|---|
| 449 | case 'a': |
|---|
| 450 | $order_by_sql = "f.left_id, f.right_id, t.topic_first_poster_name $topic_asc_desc, "; |
|---|
| 451 | break; |
|---|
| 452 | case 't': |
|---|
| 453 | $order_by_sql = "f.left_id, f.right_id, t.topic_last_post_time $topic_asc_desc, "; |
|---|
| 454 | break; |
|---|
| 455 | case 'r': |
|---|
| 456 | $order_by_sql = "f.left_id, f.right_id, t.topic_replies $topic_asc_desc, "; |
|---|
| 457 | break; |
|---|
| 458 | case 's': |
|---|
| 459 | $order_by_sql = "f.left_id, f.right_id, t.topic_title $topic_asc_desc, " ; |
|---|
| 460 | break; |
|---|
| 461 | case 'v': |
|---|
| 462 | $order_by_sql = "f.left_id, f.right_id, t.topic_views $topic_asc_desc, "; |
|---|
| 463 | break; |
|---|
| 464 | } |
|---|
| 465 | $post_asc_desc = ($row['user_post_sortby_dir'] == 'd') ? 'DESC' : ''; |
|---|
| 466 | switch($row['user_post_sortby_type']) |
|---|
| 467 | { |
|---|
| 468 | case 'a': |
|---|
| 469 | $order_by_sql .= "u.username_clean $post_asc_desc"; |
|---|
| 470 | break; |
|---|
| 471 | case 't': |
|---|
| 472 | $order_by_sql .= "p.post_time $post_asc_desc"; |
|---|
| 473 | break; |
|---|
| 474 | case 's': |
|---|
| 475 | $order_by_sql .= "p.post_subject $post_asc_desc" ; |
|---|
| 476 | break; |
|---|
| 477 | } |
|---|
| 478 | break; |
|---|
| 479 | case DIGEST_SORTBY_STANDARD: |
|---|
| 480 | $order_by_sql = 'f.left_id, f.right_id, t.topic_last_post_time, p.post_time'; |
|---|
| 481 | break; |
|---|
| 482 | case DIGEST_SORTBY_STANDARD_DESC: |
|---|
| 483 | $order_by_sql = 'f.left_id, f.right_id, t.topic_last_post_time, p.post_time DESC'; |
|---|
| 484 | break; |
|---|
| 485 | case DIGEST_SORTBY_POSTDATE: |
|---|
| 486 | $order_by_sql = 'f.left_id, f.right_id, p.post_time'; |
|---|
| 487 | break; |
|---|
| 488 | case DIGEST_SORTBY_POSTDATE_DESC: |
|---|
| 489 | $order_by_sql = 'f.left_id, f.right_id, p.post_time DESC'; |
|---|
| 490 | break; |
|---|
| 491 | } |
|---|
| 492 | |
|---|
| 493 | $new_topics_sql = ''; |
|---|
| 494 | $topics_posts_join_sql = 'f.forum_id = t.forum_id AND p.topic_id = t.topic_id '; |
|---|
| 495 | |
|---|
| 496 | // Create the first_post_only SQL stubs |
|---|
| 497 | if ($row['user_digest_filter_type'] == DIGEST_FIRST) |
|---|
| 498 | { |
|---|
| 499 | $new_topics_sql = " AND t.topic_time > $date_limit "; |
|---|
| 500 | $topics_posts_join_sql = ' t.topic_first_post_id = p.post_id AND t.forum_id = f.forum_id'; |
|---|
| 501 | } |
|---|
| 502 | |
|---|
| 503 | // Create SQL to remove your posts from the feed |
|---|
| 504 | $remove_mine_sql = ($row['user_digest_show_mine'] == 0) ? ' AND p.poster_id <> ' . $row['user_id'] : ''; |
|---|
| 505 | |
|---|
| 506 | // Create SQL to remove your foes from the feed |
|---|
| 507 | $filter_foes_sql = ''; |
|---|
| 508 | unset($foes); |
|---|
| 509 | $foes = array(); |
|---|
| 510 | if ($row['user_digest_remove_foes'] == 1) |
|---|
| 511 | { |
|---|
| 512 | |
|---|
| 513 | // Fetch your foes |
|---|
| 514 | $sql2 = 'SELECT zebra_id |
|---|
| 515 | FROM ' . ZEBRA_TABLE . ' |
|---|
| 516 | WHERE user_id = ' . $row['user_id'] . ' AND foe = 1'; |
|---|
| 517 | $result2 = $db->sql_query($sql2); |
|---|
| 518 | while ($row2 = $db->sql_fetchrow($result2)) |
|---|
| 519 | { |
|---|
| 520 | $foes[] = (int) $row2['zebra_id']; |
|---|
| 521 | } |
|---|
| 522 | $db->sql_freeresult($result2); |
|---|
| 523 | |
|---|
| 524 | if (sizeof($foes) > 0) |
|---|
| 525 | { |
|---|
| 526 | $filter_foes_sql = ' AND ' . $db->sql_in_set('p.poster_id', $foes, true); |
|---|
| 527 | } |
|---|
| 528 | |
|---|
| 529 | } |
|---|
| 530 | |
|---|
| 531 | // At last, construct the SQL to return the relevant posts |
|---|
| 532 | if (!$digest_exception) |
|---|
| 533 | { |
|---|
| 534 | |
|---|
| 535 | $sql_array = array( |
|---|
| 536 | 'SELECT' => 'f.*, t.*, p.*, u.*', |
|---|
| 537 | |
|---|
| 538 | 'FROM' => array( |
|---|
| 539 | POSTS_TABLE => 'p', |
|---|
| 540 | USERS_TABLE => 'u', |
|---|
| 541 | TOPICS_TABLE => 't' ), |
|---|
| 542 | |
|---|
| 543 | 'WHERE' => "$topics_posts_join_sql |
|---|
| 544 | AND p.poster_id = u.user_id |
|---|
| 545 | $date_limit_sql |
|---|
| 546 | $fetched_forums_sql |
|---|
| 547 | $new_topics_sql |
|---|
| 548 | $remove_mine_sql |
|---|
| 549 | $filter_foes_sql |
|---|
| 550 | AND p.post_approved = 1", |
|---|
| 551 | |
|---|
| 552 | 'ORDER_BY' => $order_by_sql |
|---|
| 553 | ); |
|---|
| 554 | |
|---|
| 555 | $sql_array['LEFT_JOIN'] = array( |
|---|
| 556 | array( |
|---|
| 557 | 'FROM' => array(FORUMS_TABLE => 'f', TOPICS_TABLE => 't'), |
|---|
| 558 | 'ON' => 't.forum_id = f.forum_id' |
|---|
| 559 | ) |
|---|
| 560 | ); |
|---|
| 561 | |
|---|
| 562 | $sql_posts = $db->sql_build_query('SELECT', $sql_array); |
|---|
| 563 | |
|---|
| 564 | if (defined(DEBUG)) |
|---|
| 565 | { |
|---|
| 566 | // In debug mode, write out the SQL used to retrieve posts |
|---|
| 567 | write_log_entry(sprintf($user->lang['DIGEST_SQL_POSTS'], $row['username'], $sql_posts)); |
|---|
| 568 | } |
|---|
| 569 | |
|---|
| 570 | // Execute the SQL to retrieve the relevant posts. Note, if $row['user_digest_max_posts'] == 0 and $config['digests_max_items'] == 0 then there is no limit on the rows returned |
|---|
| 571 | $result_posts = $db->sql_query_limit($sql_posts, min($row['user_digest_max_posts'],$config['digests_max_items'])); |
|---|
| 572 | $rowset_posts = $db->sql_fetchrowset($result_posts); // Get all the posts as a set |
|---|
| 573 | |
|---|
| 574 | } |
|---|
| 575 | else |
|---|
| 576 | { |
|---|
| 577 | $result_posts = NULL; |
|---|
| 578 | $rowset_posts = NULL; |
|---|
| 579 | } |
|---|
| 580 | |
|---|
| 581 | if (!$digest_exception) |
|---|
| 582 | { |
|---|
| 583 | if ($row['user_digest_show_pms']) |
|---|
| 584 | { |
|---|
| 585 | |
|---|
| 586 | // If there are any unread private messages, they are fetched separately and passed as a rowset to publish_feed. |
|---|
| 587 | $pm_sql = 'SELECT * |
|---|
| 588 | FROM ' . PRIVMSGS_TO_TABLE . ' pt, ' . PRIVMSGS_TABLE . ' pm, ' . USERS_TABLE . ' u |
|---|
| 589 | WHERE pt.msg_id = pm.msg_id |
|---|
| 590 | AND pt.author_id = u.user_id |
|---|
| 591 | AND pt.user_id = ' . $row['user_id'] . ' |
|---|
| 592 | AND (pm_unread = 1 OR pm_new = 1) |
|---|
| 593 | ORDER BY message_time'; |
|---|
| 594 | if (defined(DEBUG)) |
|---|
| 595 | { |
|---|
| 596 | // In debug mode, write out the SQL used to retrieve posts |
|---|
| 597 | write_log_entry(sprintf($user->lang['DIGEST_SQL_PMS'], $row['username'], $pm_sql)); |
|---|
| 598 | } |
|---|
| 599 | $pm_result = $db->sql_query($pm_sql); |
|---|
| 600 | $pm_rowset = $db->sql_fetchrowset($pm_result); |
|---|
| 601 | |
|---|
| 602 | } |
|---|
| 603 | else |
|---|
| 604 | { |
|---|
| 605 | $pm_result = NULL; |
|---|
| 606 | $pm_rowset = NULL; |
|---|
| 607 | if (defined(DEBUG)) |
|---|
| 608 | { |
|---|
| 609 | write_log_entry(sprintf($user->lang['DIGEST_SQL_PMS_NONE'], $row['username'])); |
|---|
| 610 | } |
|---|
| 611 | } |
|---|
| 612 | } |
|---|
| 613 | |
|---|
| 614 | // Construct the body of the digest. We use the templating system because of the advanced features missing in the |
|---|
| 615 | // email templating system, e.g. loops and switches |
|---|
| 616 | if (!$digest_exception) |
|---|
| 617 | { |
|---|
| 618 | $digest_content = create_content($rowset_posts, $pm_rowset, $row); |
|---|
| 619 | |
|---|
| 620 | $messenger->assign_vars(array( |
|---|
| 621 | 'DIGEST_CONTENT' => $digest_content, |
|---|
| 622 | )); |
|---|
| 623 | |
|---|
| 624 | // Mark private messages in the digest as read, if so instructed |
|---|
| 625 | if ((sizeof($pm_rowset) != 0) && ($row['user_digest_show_pms'] == 1) && ($row['user_digest_pm_mark_read'] == 1)) |
|---|
| 626 | { |
|---|
| 627 | $pm_read_sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . ' |
|---|
| 628 | SET pm_new = 0, pm_unread = 0 |
|---|
| 629 | WHERE user_id = ' . $row['user_id'] . ' |
|---|
| 630 | AND (pm_unread = 1 OR pm_new = 1)'; |
|---|
| 631 | $pm_read_sql_result = $db->sql_query($pm_read_sql); |
|---|
| 632 | $db->sql_freeresult($pm_read_sql_result); |
|---|
| 633 | } |
|---|
| 634 | } |
|---|
| 635 | else |
|---|
| 636 | { |
|---|
| 637 | write_log_entry(sprintf($digest_exception_type, $row['username'])); |
|---|
| 638 | } |
|---|
| 639 | |
|---|
| 640 | $db->sql_freeresult($result_posts); |
|---|
| 641 | $db->sql_freeresult($pm_result); |
|---|
| 642 | |
|---|
| 643 | // Send the digest out if there are new qualifying posts or the user requests a digest to be sent if there are no posts OR |
|---|
| 644 | // if there are unread private messages, the user wants to see private messages in the digest |
|---|
| 645 | if (!$digest_exception) |
|---|
| 646 | { |
|---|
| 647 | if ( $row['user_digest_send_on_no_posts'] || (sizeof($rowset_posts) > 0) || ((sizeof($pm_rowset) > 0) && $row['user_digest_show_pms'])) |
|---|
| 648 | { |
|---|
| 649 | $mail_sent = $messenger->send(NOTIFY_EMAIL, false, $is_html, true); |
|---|
| 650 | if (!$mail_sent) |
|---|
| 651 | { |
|---|
| 652 | write_log_entry(sprintf($user->lang['DIGEST_LOG_ENTRY_BAD'], $row['username'], $row['user_email'], date($config['default_dateformat']))); |
|---|
| 653 | } |
|---|
| 654 | else |
|---|
| 655 | { |
|---|
| 656 | write_log_entry(sprintf($user->lang['DIGEST_LOG_ENTRY_GOOD'], $row['username'], $row['user_email'], sizeof($rowset_posts), sizeof($pm_rowset), date($config['default_dateformat']))); |
|---|
| 657 | } |
|---|
| 658 | } |
|---|
| 659 | else |
|---|
| 660 | { |
|---|
| 661 | // log & reset messenger, bug fix provided by robdocmagic |
|---|
| 662 | write_log_entry(sprintf($user->lang['DIGEST_LOG_ENTRY_NONE'], $row['username'], $row['user_email'], date($config['default_dateformat']))); |
|---|
| 663 | $messenger->reset(); |
|---|
| 664 | } |
|---|
| 665 | } |
|---|
| 666 | |
|---|
| 667 | // Reset the user's last visit date on the forum, if so requested |
|---|
| 668 | if ($row['user_digest_reset_lastvisit']) |
|---|
| 669 | { |
|---|
| 670 | $sql2 = 'UPDATE ' . USERS_TABLE . ' |
|---|
| 671 | SET user_lastvisit = ' . time() . ' |
|---|
| 672 | WHERE user_id = ' . $row['user_id']; |
|---|
| 673 | $result2 = $db->sql_query($sql2); |
|---|
| 674 | } |
|---|
| 675 | |
|---|
| 676 | } |
|---|
| 677 | |
|---|
| 678 | // Kill the session we consumed. We don't want to use session_kill() because it updates user_lastvisit, |
|---|
| 679 | // which we don't necessarily want to do. |
|---|
| 680 | |
|---|
| 681 | $sql = 'DELETE FROM ' . SESSIONS_TABLE . " |
|---|
| 682 | WHERE session_id = '" . $db->sql_escape($user->session_id) . "' |
|---|
| 683 | AND session_user_id = " . (int) $user->data['user_id']; |
|---|
| 684 | $db->sql_query($sql); |
|---|
| 685 | |
|---|
| 686 | // Allow connecting logout with external auth method logout |
|---|
| 687 | $method = basename(trim($config['auth_method'])); |
|---|
| 688 | include_once($phpbb_root_path . 'includes/auth/auth_' . $method . '.' . $phpEx); |
|---|
| 689 | |
|---|
| 690 | $method = 'logout_' . $method; |
|---|
| 691 | if (function_exists($method)) |
|---|
| 692 | { |
|---|
| 693 | $method($user->data, $new_session); |
|---|
| 694 | } |
|---|
| 695 | |
|---|
| 696 | // Display a digest mail end processing message. It may get captured in a log |
|---|
| 697 | write_log_entry(sprintf($user->lang['DIGEST_END'],date($config['default_dateformat'])),true); |
|---|
| 698 | |
|---|
| 699 | exit; |
|---|
| 700 | |
|---|
| 701 | function create_content ($rowset, $pm_rowset, $user_row) |
|---|
| 702 | { |
|---|
| 703 | // This function creates the bulk of one digest, by marking up private messages and posts |
|---|
| 704 | // as appropriate and passing it back to the calling program. |
|---|
| 705 | |
|---|
| 706 | global $user, $template, $board_url, $phpEx, $config, $row, $is_html, $server_timezone, $use_classic_template, $ArticlePortlet; |
|---|
| 707 | $siteurl = generate_board_url(true); // added by zhongzhen for ticket 263 on 2010-06-18 |
|---|
| 708 | $featured_article = "<a href='" . $siteurl . "/wiki/" . $ArticlePortlet->getTitle() . "' style='color: #996600;'>" . $ArticlePortlet->getTitle() . "</a>"; |
|---|
| 709 | // Load the right template |
|---|
| 710 | $mail_template = ($is_html) ? 'mail_digests_html.html' : 'mail_digests_text.html'; |
|---|
| 711 | |
|---|
| 712 | $template->set_filenames(array( |
|---|
| 713 | 'mail_digests' => $mail_template, |
|---|
| 714 | )); |
|---|
| 715 | |
|---|
| 716 | // General template variables are set here |
|---|
| 717 | $template->assign_vars(array( |
|---|
| 718 | 'DIGEST_TOTAL_PMS' => sizeof($pm_rowset), |
|---|
| 719 | 'DIGEST_TOTAL_POSTS' => sizeof($rowset), |
|---|
| 720 | 'L_AUTHOR' => $user->lang['DIGEST_AUTHOR'], |
|---|
| 721 | 'L_DATE' => $user->lang['DIGEST_DATE'], |
|---|
| 722 | 'L_DIGEST_LINK' => $user->lang['DIGEST_DIGEST_LINK'], |
|---|
| 723 | 'L_DIGEST_POST_TEXT' => $user->lang['DIGEST_POST_TEXT'], |
|---|
| 724 | 'L_DIGEST_POST_TIME' => $user->lang['DIGEST_POST_TIME'], |
|---|
| 725 | 'L_DIGEST_TOTAL_POSTS' => $user->lang['DIGEST_TOTAL_POSTS'], |
|---|
| 726 | 'L_DIGEST_TOTAL_PMS' => $user->lang['DIGEST_TOTAL_UNREAD_PRIVATE_MESSAGES'], |
|---|
| 727 | 'L_FROM' => ucwords($user->lang['FROM']), |
|---|
| 728 | 'L_MESSAGE_SUBJECT' => $user->lang['DIGEST_SUBJECT_LABEL'], |
|---|
| 729 | 'L_NO_PMS' => $user->lang['DIGEST_NO_PRIVATE_MESSAGES'] . "\n", |
|---|
| 730 | 'L_NO_POSTS' => $user->lang['DIGEST_NO_POSTS'] . "\n", |
|---|
| 731 | 'L_ON' => $user->lang['DIGEST_ON'], |
|---|
| 732 | 'L_PRIVATE_MESSAGE' => strtolower($user->lang['PRIVATE_MESSAGE']) . "\n", |
|---|
| 733 | 'L_PRIVATE_MESSAGE_2' => ucwords($user->lang['PRIVATE_MESSAGE']) . "\n", |
|---|
| 734 | 'L_YOU_HAVE_PRIVATE_MESSAGES' => $user->lang['DIGEST_YOU_HAVE_PRIVATE_MESSAGES'] . "\n", |
|---|
| 735 | 'S_SHOW_TOTAL_PMS' => ($user_row['user_digest_show_pms'] == 1) ? 'Y' : 'N', |
|---|
| 736 | 'S_USE_CLASSIC_TEMPLATE' => ($use_classic_template) ? 'Y' : 'N', |
|---|
| 737 | 'SITEURL' => $siteurl, // added by zhongzhen for ticket 263 on 2010-06-18 |
|---|
| 738 | 'FEATURED_ARTICLE' => $featured_article, // added by zhongzhen for ticket 263 on 2010-06-18 |
|---|
| 739 | )); |
|---|
| 740 | |
|---|
| 741 | // Process private messages, if any, first |
|---|
| 742 | |
|---|
| 743 | if ((sizeof($pm_rowset) != 0) && ($row['user_digest_show_pms'] == 1)) |
|---|
| 744 | { |
|---|
| 745 | |
|---|
| 746 | $template->assign_vars(array( |
|---|
| 747 | 'S_SHOW_PMS' => 'Y', |
|---|
| 748 | )); |
|---|
| 749 | |
|---|
| 750 | foreach ($pm_rowset as $pm_row) |
|---|
| 751 | { |
|---|
| 752 | |
|---|
| 753 | // Now adjust post time to digest recipient's local time |
|---|
| 754 | $recipient_time = $pm_row['message_time'] - ($server_timezone * 60 * 60) + (($row['user_timezone'] + $row['user_dst']) * 60 * 60); |
|---|
| 755 | |
|---|
| 756 | $flags = (($pm_row['enable_bbcode']) ? OPTION_FLAG_BBCODE : 0) + |
|---|
| 757 | (($pm_row['enable_smilies']) ? OPTION_FLAG_SMILIES : 0) + |
|---|
| 758 | (($pm_row['enable_magic_url']) ? OPTION_FLAG_LINKS : 0); |
|---|
| 759 | |
|---|
| 760 | $pm_text = generate_text_for_display($pm_row['message_text'], $pm_row['bbcode_uid'], $pm_row['bbcode_bitfield'], $flags); |
|---|
| 761 | |
|---|
| 762 | // User signature wanted? |
|---|
| 763 | $user_sig = ( $pm_row['enable_sig'] && $pm_row['user_sig'] != '' && $config['allow_sig'] ) ? $pm_row['user_sig'] : ''; |
|---|
| 764 | if ($user_sig != '') |
|---|
| 765 | { |
|---|
| 766 | // Format the signature for display |
|---|
| 767 | $user_sig = generate_text_for_display($user_sig, $pm_row['user_sig_bbcode_uid'], $pm_row['user_sig_bbcode_bitfield'], $flags); |
|---|
| 768 | } |
|---|
| 769 | |
|---|
| 770 | // Add signature to bottom of post |
|---|
| 771 | $pm_text = ($user_sig != '') ? $pm_text . "\n" . $user->lang['DIGEST_POST_SIGNATURE_DELIMITER'] . "\n" . $user_sig : $pm_text . "\n"; |
|---|
| 772 | |
|---|
| 773 | // If a text digest is desired, this is a good point to strip tags, after first replacing <br /> with \n |
|---|
| 774 | if (!$is_html) |
|---|
| 775 | { |
|---|
| 776 | $pm_text = str_replace('<br />', "\n", $pm_text); |
|---|
| 777 | $pm_text = strip_tags($pm_text); |
|---|
| 778 | } |
|---|
| 779 | else |
|---|
| 780 | { |
|---|
| 781 | // Board URLs must be absolute in the digests, so substitute board URL for relative URL |
|---|
| 782 | $pm_text = str_replace('<img src="./', '<img src="' . $board_url, $pm_text); |
|---|
| 783 | } |
|---|
| 784 | |
|---|
| 785 | $template->assign_block_vars('pm', array( |
|---|
| 786 | 'NEW_UNREAD' => ($pm_row['pm_new'] == 1) ? $user->lang['DIGEST_NEW'] . ' ' : $user->lang['DIGEST_UNREAD'] . ' ', |
|---|
| 787 | 'PRIVATE_MESSAGE_LINK' => ($is_html) ? sprintf('<a href="%s?i=pm&mode=view&f=0&p=%s">%s</a>', $board_url . 'ucp.' . $phpEx, $pm_row['msg_id'], $pm_row['msg_id']) . "\n" : $pm_row['message_subject'] . "\n", |
|---|
| 788 | 'PRIVATE_MESSAGE_SUBJECT' => ($is_html) ? sprintf('<a href="%s?i=pm&mode=view&f=0&p=%s">%s</a>', $board_url . 'ucp.' . $phpEx, $pm_row['msg_id'], $pm_row['message_subject']) . "\n" : $pm_row['message_subject'] . "\n", |
|---|
| 789 | 'FROM' => ($is_html) ? sprintf('<a href="%s?mode=viewprofile&u=%s">%s</a>', $board_url . 'memberlist.' . $phpEx, $pm_row['author_id'], $pm_row['username']) : $pm_row['username'], |
|---|
| 790 | 'DATE' => date($pm_row['user_dateformat'], $recipient_time) . "\n", |
|---|
| 791 | 'CONTENT' => $pm_text . "\n", |
|---|
| 792 | )); |
|---|
| 793 | } |
|---|
| 794 | |
|---|
| 795 | } |
|---|
| 796 | else |
|---|
| 797 | { |
|---|
| 798 | // Turn off switch that would indicate there are private messages |
|---|
| 799 | $template->assign_vars(array( |
|---|
| 800 | 'S_SHOW_PMS' => 'N', |
|---|
| 801 | )); |
|---|
| 802 | } |
|---|
| 803 | |
|---|
| 804 | // Process posts next |
|---|
| 805 | |
|---|
| 806 | $last_forum_id = -1; |
|---|
| 807 | $last_topic_id = -1; |
|---|
| 808 | |
|---|
| 809 | if (sizeof($rowset) != 0) |
|---|
| 810 | { |
|---|
| 811 | |
|---|
| 812 | foreach ($rowset as $post_row) |
|---|
| 813 | { |
|---|
| 814 | |
|---|
| 815 | // Skip if post has less than minimum words wanted. |
|---|
| 816 | $show_in_digest = true; |
|---|
| 817 | if ($row['user_digest_min_words'] > 0) |
|---|
| 818 | { |
|---|
| 819 | $show_in_digest = (truncate_words($post_row['post_text'], $row['user_digest_min_words'], true) < $row['user_digest_min_words']) ? false : true; |
|---|
| 820 | } |
|---|
| 821 | |
|---|
| 822 | if ($show_in_digest) |
|---|
| 823 | { |
|---|
| 824 | |
|---|
| 825 | // Now adjust post time to digest recipient's local time |
|---|
| 826 | $recipient_time = $post_row['post_time'] - ($server_timezone * 60 * 60) + (($row['user_timezone'] + $row['user_dst']) * 60 * 60); |
|---|
| 827 | |
|---|
| 828 | // Need BBCode flags to translate BBCode |
|---|
| 829 | $flags = (($post_row['enable_bbcode']) ? OPTION_FLAG_BBCODE : 0) + |
|---|
| 830 | (($post_row['enable_smilies']) ? OPTION_FLAG_SMILIES : 0) + |
|---|
| 831 | (($post_row['enable_magic_url']) ? OPTION_FLAG_LINKS : 0); |
|---|
| 832 | |
|---|
| 833 | $post_text = generate_text_for_display($post_row['post_text'], $post_row['bbcode_uid'], $post_row['bbcode_bitfield'], $flags); |
|---|
| 834 | |
|---|
| 835 | // User signature wanted? |
|---|
| 836 | $user_sig = ( $post_row['enable_sig'] && $post_row['user_sig'] != '' && $config['allow_sig'] ) ? $post_row['user_sig'] : ''; |
|---|
| 837 | if ($user_sig != '') |
|---|
| 838 | { |
|---|
| 839 | // Format the signature for display |
|---|
| 840 | $user_sig = generate_text_for_display($user_sig, $post_row['user_sig_bbcode_uid'], $post_row['user_sig_bbcode_bitfield'], $flags); |
|---|
| 841 | } |
|---|
| 842 | |
|---|
| 843 | // Add signature to bottom of post |
|---|
| 844 | $post_text = ($user_sig != '') ? $post_text . "\n" . $user->lang['DIGEST_POST_SIGNATURE_DELIMITER'] . "\n" . $user_sig : $post_text . "\n"; |
|---|
| 845 | |
|---|
| 846 | // If a text digest is desired, this is a good point to strip tags |
|---|
| 847 | if (!$is_html) |
|---|
| 848 | { |
|---|
| 849 | $post_text = str_replace('<br />', "\n", $post_text); |
|---|
| 850 | $post_text = strip_tags($post_text); |
|---|
| 851 | } |
|---|
| 852 | else |
|---|
| 853 | { |
|---|
| 854 | // Board URLs must be absolute in the digests, so substitute board URL for relative URL |
|---|
| 855 | $post_text = str_replace('<img src="./', '<img src="' . $board_url, $post_text); |
|---|
| 856 | } |
|---|
| 857 | |
|---|
| 858 | if ($last_forum_id != (int) $post_row['forum_id']) |
|---|
| 859 | { |
|---|
| 860 | // Process a forum break |
|---|
| 861 | $template->assign_block_vars('forum', array( |
|---|
| 862 | 'FORUM' => ($is_html) ? sprintf('<a href="%sviewforum.%s?f=%s" style="color: #0064B1;">%s</a>', $board_url, $phpEx, $post_row['forum_id'], $post_row['forum_name']) : $post_row['forum_name'] . "\n", |
|---|
| 863 | )); |
|---|
| 864 | $last_forum_id = (int) $post_row['forum_id']; |
|---|
| 865 | } |
|---|
| 866 | |
|---|
| 867 | if ($last_topic_id != (int) $post_row['topic_id']) |
|---|
| 868 | { |
|---|
| 869 | // Process a topic break |
|---|
| 870 | $template->assign_block_vars('forum.topic', array( |
|---|
| 871 | 'TOPIC' => ($is_html) ? sprintf('<a href="%sviewtopic.%s?f=%s&t=%s" style="color: #996600;">%s</a>', $board_url, $phpEx, $post_row['forum_id'], $post_row['topic_id'], $post_row['topic_title']) : $post_row['topic_title'] . "\n", |
|---|
| 872 | )); |
|---|
| 873 | $last_topic_id = (int) $post_row['topic_id']; |
|---|
| 874 | } |
|---|
| 875 | |
|---|
| 876 | // Handle max display words logic |
|---|
| 877 | if ($row['user_digest_max_display_words'] > 0) |
|---|
| 878 | { |
|---|
| 879 | $post_text = truncate_words($post_text, $row['user_digest_max_display_words']); |
|---|
| 880 | } |
|---|
| 881 | |
|---|
| 882 | $template->assign_block_vars('forum.topic.post', array( |
|---|
| 883 | 'S_FIRST_POST' => ($post_row['topic_first_post_id'] == $post_row['post_id']) ? 'Y' : 'N', // Hide subject if first post, as it is the same as topic title |
|---|
| 884 | // added style by zhongzhen for ticket 263 on 2010-06-18 |
|---|
| 885 | 'SUBJECT' => ($is_html) ? sprintf('<a href="%sviewtopic.php?f=%s&t=%s#p%s" style="color: #0064B1;">%s</a>%s', $board_url, $post_row['forum_id'], $post_row['topic_id'], $post_row['post_id'], $post_row['post_subject'], "\n") : $post_row['post_subject'] . "\n" , |
|---|
| 886 | // added style by zhongzhen for ticket 263 on 2010-06-18 |
|---|
| 887 | 'POST_LINK' => ($is_html) ? sprintf('<a href="%sviewtopic.php?f=%s&t=%s#p%s" style="color: #0064B1;">%s</a>%s', $board_url, $post_row['forum_id'], $post_row['topic_id'], $post_row['post_id'], $post_row['post_id'], "\n") : $post_row['post_id'] . "\n" , |
|---|
| 888 | 'FROM' => ($is_html) ? sprintf('<a href="%s?mode=viewprofile&u=%s" style="color: #666666;">%s</a>%s', $board_url . 'memberlist.' . $phpEx, $post_row['user_id'], $post_row['username'], "\n") : $post_row['username'] . "\n", |
|---|
| 889 | 'DATE' => date($row['user_dateformat'], $recipient_time) . "\n", |
|---|
| 890 | 'CONTENT' => $post_text . "\n", |
|---|
| 891 | )); |
|---|
| 892 | |
|---|
| 893 | } |
|---|
| 894 | |
|---|
| 895 | } |
|---|
| 896 | |
|---|
| 897 | } |
|---|
| 898 | |
|---|
| 899 | $digest_body = $template->assign_display('mail_digests'); |
|---|
| 900 | $template->destroy(); // If you don't destroy the template subsequent users will receive duplicate posts |
|---|
| 901 | return $digest_body; |
|---|
| 902 | |
|---|
| 903 | } |
|---|
| 904 | |
|---|
| 905 | function truncate_words($text, $max_words, $just_count_words = false) |
|---|
| 906 | { |
|---|
| 907 | |
|---|
| 908 | // This function returns the first $max_words from the supplied $text. If $just_count_words === true, a word count is returned. Note: |
|---|
| 909 | // for consistency, HTML is stripped. This can be annoying, but otherwise HTML rendered in the digest may not be valid. |
|---|
| 910 | |
|---|
| 911 | global $user; |
|---|
| 912 | |
|---|
| 913 | if ($just_count_words) |
|---|
| 914 | { |
|---|
| 915 | return str_word_count(strip_tags($text)); |
|---|
| 916 | } |
|---|
| 917 | |
|---|
| 918 | $word_array = preg_split("/[\s]+/", $text); |
|---|
| 919 | |
|---|
| 920 | if (sizeof($word_array) <= $max_words) |
|---|
| 921 | { |
|---|
| 922 | return rtrim($text); |
|---|
| 923 | } |
|---|
| 924 | else |
|---|
| 925 | { |
|---|
| 926 | $truncated_text = ''; |
|---|
| 927 | for ($i=0; $i < $max_words; $i++) |
|---|
| 928 | { |
|---|
| 929 | $truncated_text .= $word_array[$i] . ' '; |
|---|
| 930 | } |
|---|
| 931 | return rtrim($truncated_text) . $user->lang['DIGEST_MAX_WORDS_NOTIFIER']; |
|---|
| 932 | } |
|---|
| 933 | } |
|---|
| 934 | |
|---|
| 935 | function write_log_entry ($log_entry, $close = false) |
|---|
| 936 | { |
|---|
| 937 | // This function writes a log entry. It could be to STDOUT, or it could be to a file, depending on value of $resource |
|---|
| 938 | |
|---|
| 939 | global $eol, $config, $phpbb_root_path, $phpEx; |
|---|
| 940 | |
|---|
| 941 | static $is_open = false; |
|---|
| 942 | static $resource = NULL; // If NULL, write to STDOUT |
|---|
| 943 | |
|---|
| 944 | if (!$config['digests_show_output']) |
|---|
| 945 | { |
|---|
| 946 | return; // Don't write any log entries if not requested |
|---|
| 947 | } |
|---|
| 948 | |
|---|
| 949 | if (!$is_open) |
|---|
| 950 | { |
|---|
| 951 | if (trim($config['digests_log_path']) != '') |
|---|
| 952 | { |
|---|
| 953 | // Attempt to open the file relative to the phpBB root directory shown in $config['digests_log_path'] write mode |
|---|
| 954 | $mode = ($config['digests_reset_log']) ? 'w+' : 'a+'; |
|---|
| 955 | if ($config['digests_reset_log']) |
|---|
| 956 | { |
|---|
| 957 | // If asked to reset the digest log, record the date and time the log was last truncated |
|---|
| 958 | set_config('digests_reset_log_date', time()); |
|---|
| 959 | // Then reset the digests_reset_log configuration variable to false |
|---|
| 960 | set_config('digests_reset_log', 0); |
|---|
| 961 | } |
|---|
| 962 | $path = $phpbb_root_path . trim($config['digests_log_path']); |
|---|
| 963 | $resource = fopen($path, $mode); |
|---|
| 964 | if (!$resource) |
|---|
| 965 | { |
|---|
| 966 | echo sprintf($user->lang['DIGEST_LOG_WRITE_ERROR'], $path) . $eol; |
|---|
| 967 | exit; |
|---|
| 968 | } |
|---|
| 969 | } |
|---|
| 970 | $is_open = true; |
|---|
| 971 | } |
|---|
| 972 | |
|---|
| 973 | if ($resource == NULL) |
|---|
| 974 | { |
|---|
| 975 | echo $log_entry . $eol; |
|---|
| 976 | } |
|---|
| 977 | else |
|---|
| 978 | { |
|---|
| 979 | fwrite ($resource, $log_entry . $eol); |
|---|
| 980 | if ($close) |
|---|
| 981 | { |
|---|
| 982 | fclose($resource); |
|---|
| 983 | } |
|---|
| 984 | } |
|---|
| 985 | |
|---|
| 986 | return; |
|---|
| 987 | } |
|---|
| 988 | |
|---|
| 989 | function check_all_parents($forum_id) |
|---|
| 990 | { |
|---|
| 991 | |
|---|
| 992 | // This function checks all parents for a given forum_id. If any of them do not have the f_list permission |
|---|
| 993 | // the function returns false, meaning the forum should not be displayed because it has a parent that should |
|---|
| 994 | // not be listed. Otherwise it returns true, indicating the forum can be listed. |
|---|
| 995 | |
|---|
| 996 | global $db, $forum_array, $list_id; |
|---|
| 997 | |
|---|
| 998 | $there_are_parents = true; |
|---|
| 999 | $current_forum_id = $forum_id; |
|---|
| 1000 | $include_this_forum = true; |
|---|
| 1001 | |
|---|
| 1002 | static $parents_loaded = false; |
|---|
| 1003 | static $parent_array = array(); |
|---|
| 1004 | |
|---|
| 1005 | if (!$parents_loaded) |
|---|
| 1006 | { |
|---|
| 1007 | // Get a list of parent_ids for each forum and put them in an array. |
|---|
| 1008 | $sql = 'SELECT forum_id, parent_id |
|---|
| 1009 | FROM ' . FORUMS_TABLE . ' |
|---|
| 1010 | ORDER BY 1'; |
|---|
| 1011 | $result = $db->sql_query($sql); |
|---|
| 1012 | while ($row = $db->sql_fetchrow($result)) |
|---|
| 1013 | { |
|---|
| 1014 | $parent_array[$row['forum_id']] = $row['parent_id']; |
|---|
| 1015 | } |
|---|
| 1016 | $parents_loaded = true; |
|---|
| 1017 | } |
|---|
| 1018 | |
|---|
| 1019 | while ($there_are_parents) |
|---|
| 1020 | { |
|---|
| 1021 | |
|---|
| 1022 | if ($parent_array[$current_forum_id] == 0) // No parent |
|---|
| 1023 | { |
|---|
| 1024 | $there_are_parents = false; |
|---|
| 1025 | } |
|---|
| 1026 | else |
|---|
| 1027 | { |
|---|
| 1028 | if ($forum_array[$parent_array[$current_forum_id]][$list_id] == 1) |
|---|
| 1029 | { |
|---|
| 1030 | // So far so good |
|---|
| 1031 | $current_forum_id = $parent_array[$current_forum_id]; |
|---|
| 1032 | } |
|---|
| 1033 | else |
|---|
| 1034 | { |
|---|
| 1035 | // Danger Will Robinson! No list permission exists for a parent of the requested forum, so this forum should not be shown |
|---|
| 1036 | $there_are_parents = false; |
|---|
| 1037 | $include_this_forum = false; |
|---|
| 1038 | } |
|---|
| 1039 | } |
|---|
| 1040 | |
|---|
| 1041 | } |
|---|
| 1042 | |
|---|
| 1043 | return $include_this_forum; |
|---|
| 1044 | |
|---|
| 1045 | } |
|---|
| 1046 | |
|---|
| 1047 | ?> |
|---|