2 /***************************************************************************
5 * begin : Saturday, Feb 13, 2001
6 * copyright : (C) 2001 The phpBB Group
7 * email : support@phpbb.com
9 * $Id: functions_post.php,v 1.9.2.37 2004/11/18 17:49:44 acydburn Exp $
12 ***************************************************************************/
14 /***************************************************************************
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 ***************************************************************************/
23 if (!defined('IN_PHPBB'))
25 die('Hacking attempt');
28 $html_entities_match = array('#&(?!(\#[0-9]+;))#', '#<#', '#>#');
29 $html_entities_replace = array('&', '<', '>');
31 $unhtml_specialchars_match = array('#>#', '#<#', '#"#', '#&#');
32 $unhtml_specialchars_replace = array('>', '<', '"', '&');
35 // This function will prepare a posted message for
36 // entry into the database.
38 function prepare_message($message, $html_on, $bbcode_on, $smile_on, $bbcode_uid = 0)
40 global $board_config, $html_entities_match, $html_entities_replace;
43 // Clean up the message
45 $message = trim($message);
49 $allowed_html_tags = split(',', $board_config['allow_html_tags']);
54 $message = ' ' . $message . ' ';
56 while ($start_html = strpos($message, '<', $start_html))
58 $tmp_message .= preg_replace($html_entities_match, $html_entities_replace, substr($message, $end_html + 1, ($start_html - $end_html - 1)));
60 if ($end_html = strpos($message, '>', $start_html))
62 $length = $end_html - $start_html + 1;
63 $hold_string = substr($message, $start_html, $length);
65 if (($unclosed_open = strrpos(' ' . $hold_string, '<')) != 1)
67 $tmp_message .= preg_replace($html_entities_match, $html_entities_replace, substr($hold_string, 0, $unclosed_open - 1));
68 $hold_string = substr($hold_string, $unclosed_open - 1);
72 for ($i = 0; $i < sizeof($allowed_html_tags); $i++)
74 $match_tag = trim($allowed_html_tags[$i]);
75 if (preg_match('#^<\/?' . $match_tag . '[> ]#i', $hold_string))
77 $tagallowed = (preg_match('#^<\/?' . $match_tag . ' .*?(style[\t ]*?=|on[\w]+[\t ]*?=)#i', $hold_string)) ? false : true;
81 $tmp_message .= ($length && !$tagallowed) ? preg_replace($html_entities_match, $html_entities_replace, $hold_string) : $hold_string;
83 $start_html += $length;
87 $tmp_message .= preg_replace($html_entities_match, $html_entities_replace, substr($message, $start_html, strlen($message)));
89 $start_html = strlen($message);
90 $end_html = $start_html;
94 if (!$end_html || ($end_html != strlen($message) && $tmp_message != ''))
96 $tmp_message .= preg_replace($html_entities_match, $html_entities_replace, substr($message, $end_html + 1));
99 $message = ($tmp_message != '') ? trim($tmp_message) : trim($message);
103 $message = preg_replace($html_entities_match, $html_entities_replace, $message);
106 if($bbcode_on && $bbcode_uid != '')
108 $message = bbencode_first_pass($message, $bbcode_uid);
114 function unprepare_message($message)
116 global $unhtml_specialchars_match, $unhtml_specialchars_replace;
118 return preg_replace($unhtml_specialchars_match, $unhtml_specialchars_replace, $message);
122 // Prepare a message for posting
124 function prepare_post(&$mode, &$post_data, &$bbcode_on, &$html_on, &$smilies_on, &$error_msg, &$username, &$bbcode_uid, &$subject, &$message, &$poll_title, &$poll_options, &$poll_length)
126 global $board_config, $userdata, $lang, $phpEx, $phpbb_root_path;
129 if (!empty($username))
131 $username = phpbb_clean_username($username);
133 if (!$userdata['session_logged_in'] || ($userdata['session_logged_in'] && $username != $userdata['username']))
135 include($phpbb_root_path . 'includes/functions_validate.'.$phpEx);
137 $result = validate_username($username);
138 if ($result['error'])
140 $error_msg .= (!empty($error_msg)) ? '<br />' . $result['error_msg'] : $result['error_msg'];
150 if (!empty($subject))
152 $subject = htmlspecialchars(trim($subject));
154 else if ($mode == 'newtopic' || ($mode == 'editpost' && $post_data['first_post']))
156 $error_msg .= (!empty($error_msg)) ? '<br />' . $lang['Empty_subject'] : $lang['Empty_subject'];
160 if (!empty($message))
162 $bbcode_uid = ($bbcode_on) ? make_bbcode_uid() : '';
163 $message = prepare_message(trim($message), $html_on, $bbcode_on, $smilies_on, $bbcode_uid);
165 else if ($mode != 'delete' && $mode != 'poll_delete')
167 $error_msg .= (!empty($error_msg)) ? '<br />' . $lang['Empty_message'] : $lang['Empty_message'];
173 if ($mode == 'newtopic' || ($mode == 'editpost' && $post_data['first_post']))
175 $poll_length = (isset($poll_length)) ? max(0, intval($poll_length)) : 0;
177 if (!empty($poll_title))
179 $poll_title = htmlspecialchars(trim($poll_title));
182 if(!empty($poll_options))
184 $temp_option_text = array();
185 while(list($option_id, $option_text) = @each($poll_options))
187 $option_text = trim($option_text);
188 if (!empty($option_text))
190 $temp_option_text[$option_id] = htmlspecialchars($option_text);
193 $option_text = $temp_option_text;
195 if (count($poll_options) < 2)
197 $error_msg .= (!empty($error_msg)) ? '<br />' . $lang['To_few_poll_options'] : $lang['To_few_poll_options'];
199 else if (count($poll_options) > $board_config['max_poll_options'])
201 $error_msg .= (!empty($error_msg)) ? '<br />' . $lang['To_many_poll_options'] : $lang['To_many_poll_options'];
203 else if ($poll_title == '')
205 $error_msg .= (!empty($error_msg)) ? '<br />' . $lang['Empty_poll_title'] : $lang['Empty_poll_title'];
214 // Post a new topic/reply/poll or edit existing post/poll
216 function submit_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_id, &$post_id, &$poll_id, &$topic_type, &$bbcode_on, &$html_on, &$smilies_on, &$attach_sig, &$bbcode_uid, &$post_username, &$post_subject, &$post_message, &$poll_title, &$poll_options, &$poll_length)
218 global $board_config, $lang, $db, $phpbb_root_path, $phpEx;
219 global $userdata, $user_ip;
221 include($phpbb_root_path . 'includes/functions_search.'.$phpEx);
223 $current_time = time();
225 if ($mode == 'newtopic' || $mode == 'reply' || $mode == 'editpost')
230 $where_sql = ($userdata['user_id'] == ANONYMOUS) ? "poster_ip = '$user_ip'" : 'poster_id = ' . $userdata['user_id'];
231 $sql = "SELECT MAX(post_time) AS last_post_time
232 FROM " . POSTS_TABLE . "
234 if ($result = $db->sql_query($sql))
236 if ($row = $db->sql_fetchrow($result))
238 if (intval($row['last_post_time']) > 0 && ($current_time - intval($row['last_post_time'])) < intval($board_config['flood_interval']))
240 message_die(GENERAL_MESSAGE, $lang['Flood_Error']);
246 if ($mode == 'editpost')
248 remove_search_post($post_id);
251 if ($mode == 'newtopic' || ($mode == 'editpost' && $post_data['first_post']))
253 $topic_vote = (!empty($poll_title) && count($poll_options) >= 2) ? 1 : 0;
255 $sql = ($mode != "editpost") ? "INSERT INTO " . TOPICS_TABLE . " (topic_title, topic_poster, topic_time, forum_id, topic_status, topic_type, topic_vote) VALUES ('$post_subject', " . $userdata['user_id'] . ", $current_time, $forum_id, " . TOPIC_UNLOCKED . ", $topic_type, $topic_vote)" : "UPDATE " . TOPICS_TABLE . " SET topic_title = '$post_subject', topic_type = $topic_type " . (($post_data['edit_vote'] || !empty($poll_title)) ? ", topic_vote = " . $topic_vote : "") . " WHERE topic_id = $topic_id";
256 if (!$db->sql_query($sql))
258 message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
261 if ($mode == 'newtopic')
263 $topic_id = $db->sql_nextid();
267 $edited_sql = ($mode == 'editpost' && !$post_data['last_post'] && $post_data['poster_post']) ? ", post_edit_time = $current_time, post_edit_count = post_edit_count + 1 " : "";
268 $sql = ($mode != "editpost") ? "INSERT INTO " . POSTS_TABLE . " (topic_id, forum_id, poster_id, post_username, post_time, poster_ip, enable_bbcode, enable_html, enable_smilies, enable_sig) VALUES ($topic_id, $forum_id, " . $userdata['user_id'] . ", '$post_username', $current_time, '$user_ip', $bbcode_on, $html_on, $smilies_on, $attach_sig)" : "UPDATE " . POSTS_TABLE . " SET post_username = '$post_username', enable_bbcode = $bbcode_on, enable_html = $html_on, enable_smilies = $smilies_on, enable_sig = $attach_sig" . $edited_sql . " WHERE post_id = $post_id";
269 if (!$db->sql_query($sql, BEGIN_TRANSACTION))
271 message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
274 if ($mode != 'editpost')
276 $post_id = $db->sql_nextid();
279 $sql = ($mode != 'editpost') ? "INSERT INTO " . POSTS_TEXT_TABLE . " (post_id, post_subject, bbcode_uid, post_text) VALUES ($post_id, '$post_subject', '$bbcode_uid', '$post_message')" : "UPDATE " . POSTS_TEXT_TABLE . " SET post_text = '$post_message', bbcode_uid = '$bbcode_uid', post_subject = '$post_subject' WHERE post_id = $post_id";
280 if (!$db->sql_query($sql))
282 message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
285 add_search_words('single', $post_id, stripslashes($post_message), stripslashes($post_subject));
290 if (($mode == 'newtopic' || ($mode == 'editpost' && $post_data['edit_poll'])) && !empty($poll_title) && count($poll_options) >= 2)
292 $sql = (!$post_data['has_poll']) ? "INSERT INTO " . VOTE_DESC_TABLE . " (topic_id, vote_text, vote_start, vote_length) VALUES ($topic_id, '$poll_title', $current_time, " . ($poll_length * 86400) . ")" : "UPDATE " . VOTE_DESC_TABLE . " SET vote_text = '$poll_title', vote_length = " . ($poll_length * 86400) . " WHERE topic_id = $topic_id";
293 if (!$db->sql_query($sql))
295 message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
298 $delete_option_sql = '';
299 $old_poll_result = array();
300 if ($mode == 'editpost' && $post_data['has_poll'])
302 $sql = "SELECT vote_option_id, vote_result
303 FROM " . VOTE_RESULTS_TABLE . "
304 WHERE vote_id = $poll_id
305 ORDER BY vote_option_id ASC";
306 if (!($result = $db->sql_query($sql)))
308 message_die(GENERAL_ERROR, 'Could not obtain vote data results for this topic', '', __LINE__, __FILE__, $sql);
311 while ($row = $db->sql_fetchrow($result))
313 $old_poll_result[$row['vote_option_id']] = $row['vote_result'];
315 if (!isset($poll_options[$row['vote_option_id']]))
317 $delete_option_sql .= ($delete_option_sql != '') ? ', ' . $row['vote_option_id'] : $row['vote_option_id'];
323 $poll_id = $db->sql_nextid();
326 @reset($poll_options);
329 while (list($option_id, $option_text) = each($poll_options))
331 if (!empty($option_text))
333 $option_text = str_replace("\'", "''", htmlspecialchars($option_text));
334 $poll_result = ($mode == "editpost" && isset($old_poll_result[$option_id])) ? $old_poll_result[$option_id] : 0;
336 $sql = ($mode != "editpost" || !isset($old_poll_result[$option_id])) ? "INSERT INTO " . VOTE_RESULTS_TABLE . " (vote_id, vote_option_id, vote_option_text, vote_result) VALUES ($poll_id, $poll_option_id, '$option_text', $poll_result)" : "UPDATE " . VOTE_RESULTS_TABLE . " SET vote_option_text = '$option_text', vote_result = $poll_result WHERE vote_option_id = $option_id AND vote_id = $poll_id";
337 if (!$db->sql_query($sql))
339 message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
345 if ($delete_option_sql != '')
347 $sql = "DELETE FROM " . VOTE_RESULTS_TABLE . "
348 WHERE vote_option_id IN ($delete_option_sql)
349 AND vote_id = $poll_id";
350 if (!$db->sql_query($sql))
352 message_die(GENERAL_ERROR, 'Error deleting pruned poll options', '', __LINE__, __FILE__, $sql);
357 $meta = '<meta http-equiv="refresh" content="3;url=' . append_sid("viewtopic.$phpEx?" . POST_POST_URL . "=" . $post_id) . '#' . $post_id . '">';
358 $message = $lang['Stored'] . '<br /><br />' . sprintf($lang['Click_view_message'], '<a href="' . append_sid("viewtopic.$phpEx?" . POST_POST_URL . "=" . $post_id) . '#' . $post_id . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_forum'], '<a href="' . append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id") . '">', '</a>');
364 // Update post stats and details
366 function update_post_stats(&$mode, &$post_data, &$forum_id, &$topic_id, &$post_id, &$user_id)
370 $sign = ($mode == 'delete') ? '- 1' : '+ 1';
371 $forum_update_sql = "forum_posts = forum_posts $sign";
372 $topic_update_sql = '';
374 if ($mode == 'delete')
376 if ($post_data['last_post'])
378 if ($post_data['first_post'])
380 $forum_update_sql .= ', forum_topics = forum_topics - 1';
385 $topic_update_sql .= 'topic_replies = topic_replies - 1';
387 $sql = "SELECT MAX(post_id) AS last_post_id
388 FROM " . POSTS_TABLE . "
389 WHERE topic_id = $topic_id";
390 if (!($result = $db->sql_query($sql)))
392 message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);
395 if ($row = $db->sql_fetchrow($result))
397 $topic_update_sql .= ', topic_last_post_id = ' . $row['last_post_id'];
401 if ($post_data['last_topic'])
403 $sql = "SELECT MAX(post_id) AS last_post_id
404 FROM " . POSTS_TABLE . "
405 WHERE forum_id = $forum_id";
406 if (!($result = $db->sql_query($sql)))
408 message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);
411 if ($row = $db->sql_fetchrow($result))
413 $forum_update_sql .= ($row['last_post_id']) ? ', forum_last_post_id = ' . $row['last_post_id'] : ', forum_last_post_id = 0';
417 else if ($post_data['first_post'])
419 $sql = "SELECT MIN(post_id) AS first_post_id
420 FROM " . POSTS_TABLE . "
421 WHERE topic_id = $topic_id";
422 if (!($result = $db->sql_query($sql)))
424 message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);
427 if ($row = $db->sql_fetchrow($result))
429 $topic_update_sql .= 'topic_replies = topic_replies - 1, topic_first_post_id = ' . $row['first_post_id'];
434 $topic_update_sql .= 'topic_replies = topic_replies - 1';
437 else if ($mode != 'poll_delete')
439 $forum_update_sql .= ", forum_last_post_id = $post_id" . (($mode == 'newtopic') ? ", forum_topics = forum_topics $sign" : "");
440 $topic_update_sql = "topic_last_post_id = $post_id" . (($mode == 'reply') ? ", topic_replies = topic_replies $sign" : ", topic_first_post_id = $post_id");
444 $topic_update_sql .= 'topic_vote = 0';
447 $sql = "UPDATE " . FORUMS_TABLE . " SET
449 WHERE forum_id = $forum_id";
450 if (!$db->sql_query($sql))
452 message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
455 if ($topic_update_sql != '')
457 $sql = "UPDATE " . TOPICS_TABLE . " SET
459 WHERE topic_id = $topic_id";
460 if (!$db->sql_query($sql))
462 message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
466 if ($mode != 'poll_delete')
468 $sql = "UPDATE " . USERS_TABLE . "
469 SET user_posts = user_posts $sign
470 WHERE user_id = $user_id";
471 if (!$db->sql_query($sql, END_TRANSACTION))
473 message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
481 // Delete a post/poll
483 function delete_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_id, &$post_id, &$poll_id)
485 global $board_config, $lang, $db, $phpbb_root_path, $phpEx;
486 global $userdata, $user_ip;
488 if ($mode != 'poll_delete')
490 include($phpbb_root_path . 'includes/functions_search.'.$phpEx);
492 $sql = "DELETE FROM " . POSTS_TABLE . "
493 WHERE post_id = $post_id";
494 if (!$db->sql_query($sql))
496 message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);
499 $sql = "DELETE FROM " . POSTS_TEXT_TABLE . "
500 WHERE post_id = $post_id";
501 if (!$db->sql_query($sql))
503 message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);
506 if ($post_data['last_post'])
508 if ($post_data['first_post'])
510 $forum_update_sql .= ', forum_topics = forum_topics - 1';
511 $sql = "DELETE FROM " . TOPICS_TABLE . "
512 WHERE topic_id = $topic_id
513 OR topic_moved_id = $topic_id";
514 if (!$db->sql_query($sql))
516 message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);
519 $sql = "DELETE FROM " . TOPICS_WATCH_TABLE . "
520 WHERE topic_id = $topic_id";
521 if (!$db->sql_query($sql))
523 message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);
528 remove_search_post($post_id);
531 if ($mode == 'poll_delete' || ($mode == 'delete' && $post_data['first_post'] && $post_data['last_post']) && $post_data['has_poll'] && $post_data['edit_poll'])
533 $sql = "DELETE FROM " . VOTE_DESC_TABLE . "
534 WHERE topic_id = $topic_id";
535 if (!$db->sql_query($sql))
537 message_die(GENERAL_ERROR, 'Error in deleting poll', '', __LINE__, __FILE__, $sql);
540 $sql = "DELETE FROM " . VOTE_RESULTS_TABLE . "
541 WHERE vote_id = $poll_id";
542 if (!$db->sql_query($sql))
544 message_die(GENERAL_ERROR, 'Error in deleting poll', '', __LINE__, __FILE__, $sql);
547 $sql = "DELETE FROM " . VOTE_USERS_TABLE . "
548 WHERE vote_id = $poll_id";
549 if (!$db->sql_query($sql))
551 message_die(GENERAL_ERROR, 'Error in deleting poll', '', __LINE__, __FILE__, $sql);
555 if ($mode == 'delete' && $post_data['first_post'] && $post_data['last_post'])
557 $meta = '<meta http-equiv="refresh" content="3;url=' . append_sid("viewforum.$phpEx?" . POST_FORUM_URL . '=' . $forum_id) . '">';
558 $message = $lang['Deleted'];
562 $meta = '<meta http-equiv="refresh" content="3;url=' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . '=' . $topic_id) . '">';
563 $message = (($mode == 'poll_delete') ? $lang['Poll_delete'] : $lang['Deleted']) . '<br /><br />' . sprintf($lang['Click_return_topic'], '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id") . '">', '</a>');
566 $message .= '<br /><br />' . sprintf($lang['Click_return_forum'], '<a href="' . append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id") . '">', '</a>');
572 // Handle user notification on new post
574 function user_notification($mode, &$post_data, &$topic_title, &$forum_id, &$topic_id, &$post_id, &$notify_user)
576 global $board_config, $lang, $db, $phpbb_root_path, $phpEx;
577 global $userdata, $user_ip;
579 $current_time = time();
581 if ($mode == 'delete')
583 $delete_sql = (!$post_data['first_post'] && !$post_data['last_post']) ? " AND user_id = " . $userdata['user_id'] : '';
584 $sql = "DELETE FROM " . TOPICS_WATCH_TABLE . " WHERE topic_id = $topic_id" . $delete_sql;
585 if (!$db->sql_query($sql))
587 message_die(GENERAL_ERROR, 'Could not change topic notify data', '', __LINE__, __FILE__, $sql);
592 if ($mode == 'reply')
594 $sql = "SELECT ban_userid
595 FROM " . BANLIST_TABLE;
596 if (!($result = $db->sql_query($sql)))
598 message_die(GENERAL_ERROR, 'Could not obtain banlist', '', __LINE__, __FILE__, $sql);
602 while ($row = $db->sql_fetchrow($result))
604 if (isset($row['ban_userid']) && !empty($row['ban_userid']))
606 $user_id_sql .= ', ' . $row['ban_userid'];
610 $sql = "SELECT u.user_id, u.user_email, u.user_lang
611 FROM " . TOPICS_WATCH_TABLE . " tw, " . USERS_TABLE . " u
612 WHERE tw.topic_id = $topic_id
613 AND tw.user_id NOT IN (" . $userdata['user_id'] . ", " . ANONYMOUS . $user_id_sql . ")
614 AND tw.notify_status = " . TOPIC_WATCH_UN_NOTIFIED . "
615 AND u.user_id = tw.user_id";
616 if (!($result = $db->sql_query($sql)))
618 message_die(GENERAL_ERROR, 'Could not obtain list of topic watchers', '', __LINE__, __FILE__, $sql);
621 $update_watched_sql = '';
622 $bcc_list_ary = array();
624 if ($row = $db->sql_fetchrow($result))
626 // Sixty second limit
631 if ($row['user_email'] != '')
633 $bcc_list_ary[$row['user_lang']][] = $row['user_email'];
635 $update_watched_sql .= ($update_watched_sql != '') ? ', ' . $row['user_id'] : $row['user_id'];
637 while ($row = $db->sql_fetchrow($result));
640 // Let's do some checking to make sure that mass mail functions
641 // are working in win32 versions of php.
643 if (preg_match('/[c-z]:\\\.*/i', getenv('PATH')) && !$board_config['smtp_delivery'])
645 $ini_val = (@phpversion() >= '4.0.0') ? 'ini_get' : 'get_cfg_var';
647 // We are running on windows, force delivery to use our smtp functions
648 // since php's are broken by default
649 $board_config['smtp_delivery'] = 1;
650 $board_config['smtp_host'] = @$ini_val('SMTP');
653 if (sizeof($bcc_list_ary))
655 include($phpbb_root_path . 'includes/emailer.'.$phpEx);
656 $emailer = new emailer($board_config['smtp_delivery']);
658 $script_name = preg_replace('/^\/?(.*?)\/?$/', '\1', trim($board_config['script_path']));
659 $script_name = ($script_name != '') ? $script_name . '/viewtopic.'.$phpEx : 'viewtopic.'.$phpEx;
660 $server_name = trim($board_config['server_name']);
661 $server_protocol = ($board_config['cookie_secure']) ? 'https://' : 'http://';
662 $server_port = ($board_config['server_port'] <> 80) ? ':' . trim($board_config['server_port']) . '/' : '/';
664 $orig_word = array();
665 $replacement_word = array();
666 obtain_word_list($orig_word, $replacement_word);
668 $emailer->from($board_config['board_email']);
669 $emailer->replyto($board_config['board_email']);
671 $topic_title = (count($orig_word)) ? preg_replace($orig_word, $replacement_word, unprepare_message($topic_title)) : unprepare_message($topic_title);
673 @reset($bcc_list_ary);
674 while (list($user_lang, $bcc_list) = each($bcc_list_ary))
676 $emailer->use_template('topic_notify', $user_lang);
678 for ($i = 0; $i < count($bcc_list); $i++)
680 $emailer->bcc($bcc_list[$i]);
683 // The Topic_reply_notification lang string below will be used
684 // if for some reason the mail template subject cannot be read
685 // ... note it will not necessarily be in the posters own language!
686 $emailer->set_subject($lang['Topic_reply_notification']);
688 // This is a nasty kludge to remove the username var ... till (if?)
689 // translators update their templates
690 $emailer->msg = preg_replace('#[ ]?{USERNAME}#', '', $emailer->msg);
692 $emailer->assign_vars(array(
693 'EMAIL_SIG' => (!empty($board_config['board_email_sig'])) ? str_replace('<br />', "\n", "-- \n" . $board_config['board_email_sig']) : '',
694 'SITENAME' => $board_config['sitename'],
695 'TOPIC_TITLE' => $topic_title,
697 'U_TOPIC' => $server_protocol . $server_name . $server_port . $script_name . '?' . POST_POST_URL . "=$post_id#$post_id",
698 'U_STOP_WATCHING_TOPIC' => $server_protocol . $server_name . $server_port . $script_name . '?' . POST_TOPIC_URL . "=$topic_id&unwatch=topic")
706 $db->sql_freeresult($result);
708 if ($update_watched_sql != '')
710 $sql = "UPDATE " . TOPICS_WATCH_TABLE . "
711 SET notify_status = " . TOPIC_WATCH_NOTIFIED . "
712 WHERE topic_id = $topic_id
713 AND user_id IN ($update_watched_sql)";
714 $db->sql_query($sql);
718 $sql = "SELECT topic_id
719 FROM " . TOPICS_WATCH_TABLE . "
720 WHERE topic_id = $topic_id
721 AND user_id = " . $userdata['user_id'];
722 if (!($result = $db->sql_query($sql)))
724 message_die(GENERAL_ERROR, 'Could not obtain topic watch information', '', __LINE__, __FILE__, $sql);
727 $row = $db->sql_fetchrow($result);
729 if (!$notify_user && !empty($row['topic_id']))
731 $sql = "DELETE FROM " . TOPICS_WATCH_TABLE . "
732 WHERE topic_id = $topic_id
733 AND user_id = " . $userdata['user_id'];
734 if (!$db->sql_query($sql))
736 message_die(GENERAL_ERROR, 'Could not delete topic watch information', '', __LINE__, __FILE__, $sql);
739 else if ($notify_user && empty($row['topic_id']))
741 $sql = "INSERT INTO " . TOPICS_WATCH_TABLE . " (user_id, topic_id, notify_status)
742 VALUES (" . $userdata['user_id'] . ", $topic_id, 0)";
743 if (!$db->sql_query($sql))
745 message_die(GENERAL_ERROR, 'Could not insert topic watch information', '', __LINE__, __FILE__, $sql);
752 // Fill smiley templates (or just the variables) with smileys
753 // Either in a window or inline
755 function generate_smilies($mode, $page_id)
757 global $db, $board_config, $template, $lang, $images, $theme, $phpEx, $phpbb_root_path;
758 global $user_ip, $session_length, $starttime;
765 if ($mode == 'window')
767 $userdata = session_pagestart($user_ip, $page_id);
768 init_userprefs($userdata);
770 $gen_simple_header = TRUE;
772 $page_title = $lang['Emoticons'] . " - $topic_title";
773 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
775 $template->set_filenames(array(
776 'smiliesbody' => 'posting_smilies.tpl')
780 $sql = "SELECT emoticon, code, smile_url
781 FROM " . SMILIES_TABLE . "
782 ORDER BY smilies_id";
783 if ($result = $db->sql_query($sql))
787 while ($row = $db->sql_fetchrow($result))
789 if (empty($rowset[$row['smile_url']]))
791 $rowset[$row['smile_url']]['code'] = str_replace("'", "\\'", str_replace('\\', '\\\\', $row['code']));
792 $rowset[$row['smile_url']]['emoticon'] = $row['emoticon'];
799 $smilies_count = ($mode == 'inline') ? min(19, $num_smilies) : $num_smilies;
800 $smilies_split_row = ($mode == 'inline') ? $inline_columns - 1 : $window_columns - 1;
806 while (list($smile_url, $data) = @each($rowset))
810 $template->assign_block_vars('smilies_row', array());
813 $template->assign_block_vars('smilies_row.smilies_col', array(
814 'SMILEY_CODE' => $data['code'],
815 'SMILEY_IMG' => $board_config['smilies_path'] . '/' . $smile_url,
816 'SMILEY_DESC' => $data['emoticon'])
819 $s_colspan = max($s_colspan, $col + 1);
821 if ($col == $smilies_split_row)
823 if ($mode == 'inline' && $row == $inline_rows - 1)
836 if ($mode == 'inline' && $num_smilies > $inline_rows * $inline_columns)
838 $template->assign_block_vars('switch_smilies_extra', array());
840 $template->assign_vars(array(
841 'L_MORE_SMILIES' => $lang['More_emoticons'],
842 'U_MORE_SMILIES' => append_sid("posting.$phpEx?mode=smilies"))
846 $template->assign_vars(array(
847 'L_EMOTICONS' => $lang['Emoticons'],
848 'L_CLOSE_WINDOW' => $lang['Close_window'],
849 'S_SMILIES_COLSPAN' => $s_colspan)
854 if ($mode == 'window')
856 $template->pparse('smiliesbody');
858 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);