PageRenderTime 50ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/diendan/includes/functions_post.php

http://xoxoshop2010.googlecode.com/
PHP | 887 lines | 707 code | 107 blank | 73 comment | 185 complexity | d4fd4fca1ab76622079f9ed96bd2a380 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /***************************************************************************
  3. * functions_post.php
  4. * -------------------
  5. * begin : Saturday, Feb 13, 2001
  6. * copyright : (C) 2001 The phpBB Group
  7. * email : support@phpbb.com
  8. *
  9. * $Id: functions_post.php,v 1.9.2.52 2006/05/06 13:38:55 grahamje Exp $
  10. *
  11. *
  12. ***************************************************************************/
  13. /***************************************************************************
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 2 of the License, or
  18. * (at your option) any later version.
  19. *
  20. ***************************************************************************/
  21. if (!defined('IN_PHPBB'))
  22. {
  23. die('Hacking attempt');
  24. }
  25. $html_entities_match = array('#&(?!(\#[0-9]+;))#', '#<#', '#>#', '#"#');
  26. $html_entities_replace = array('&amp;', '&lt;', '&gt;', '&quot;');
  27. $unhtml_specialchars_match = array('#&gt;#', '#&lt;#', '#&quot;#', '#&amp;#');
  28. $unhtml_specialchars_replace = array('>', '<', '"', '&');
  29. //
  30. // This function will prepare a posted message for
  31. // entry into the database.
  32. //
  33. function prepare_message($message, $html_on, $bbcode_on, $smile_on, $bbcode_uid = 0)
  34. {
  35. global $board_config, $html_entities_match, $html_entities_replace;
  36. //
  37. // Clean up the message
  38. //
  39. $message = trim($message);
  40. if ($html_on)
  41. {
  42. // If HTML is on, we try to make it safe
  43. // This approach is quite agressive and anything that does not look like a valid tag
  44. // is going to get converted to HTML entities
  45. $message = stripslashes($message);
  46. $html_match = '#<[^\w<]*(\w+)((?:"[^"]*"|\'[^\']*\'|[^<>\'"])+)?>#';
  47. $matches = array();
  48. $message_split = preg_split($html_match, $message);
  49. preg_match_all($html_match, $message, $matches);
  50. $message = '';
  51. foreach ($message_split as $part)
  52. {
  53. $tag = array(array_shift($matches[0]), array_shift($matches[1]), array_shift($matches[2]));
  54. $message .= preg_replace($html_entities_match, $html_entities_replace, $part) . clean_html($tag);
  55. }
  56. $message = addslashes($message);
  57. $message = str_replace('&quot;', '\&quot;', $message);
  58. }
  59. else
  60. {
  61. $message = preg_replace($html_entities_match, $html_entities_replace, $message);
  62. }
  63. if($bbcode_on && $bbcode_uid != '')
  64. {
  65. $message = bbencode_first_pass($message, $bbcode_uid);
  66. }
  67. return $message;
  68. }
  69. function unprepare_message($message)
  70. {
  71. global $unhtml_specialchars_match, $unhtml_specialchars_replace;
  72. return preg_replace($unhtml_specialchars_match, $unhtml_specialchars_replace, $message);
  73. }
  74. //
  75. // Prepare a message for posting
  76. //
  77. 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)
  78. {
  79. global $board_config, $userdata, $lang, $phpEx, $phpbb_root_path;
  80. // Check username
  81. if (!empty($username))
  82. {
  83. $username = phpbb_clean_username($username);
  84. if (!$userdata['session_logged_in'] || ($userdata['session_logged_in'] && $username != $userdata['username']))
  85. {
  86. include($phpbb_root_path . 'includes/functions_validate.'.$phpEx);
  87. $result = validate_username($username);
  88. if ($result['error'])
  89. {
  90. $error_msg .= (!empty($error_msg)) ? '<br />' . $result['error_msg'] : $result['error_msg'];
  91. }
  92. }
  93. else
  94. {
  95. $username = '';
  96. }
  97. }
  98. // Check subject
  99. if (!empty($subject))
  100. {
  101. $subject = htmlspecialchars(trim($subject));
  102. }
  103. else if ($mode == 'newtopic' || ($mode == 'editpost' && $post_data['first_post']))
  104. {
  105. $error_msg .= (!empty($error_msg)) ? '<br />' . $lang['Empty_subject'] : $lang['Empty_subject'];
  106. }
  107. // Check message
  108. if (!empty($message))
  109. {
  110. $bbcode_uid = ($bbcode_on) ? make_bbcode_uid() : '';
  111. $message = prepare_message(trim($message), $html_on, $bbcode_on, $smilies_on, $bbcode_uid);
  112. }
  113. else if ($mode != 'delete' && $mode != 'poll_delete')
  114. {
  115. $error_msg .= (!empty($error_msg)) ? '<br />' . $lang['Empty_message'] : $lang['Empty_message'];
  116. }
  117. //
  118. // Handle poll stuff
  119. //
  120. if ($mode == 'newtopic' || ($mode == 'editpost' && $post_data['first_post']))
  121. {
  122. $poll_length = (isset($poll_length)) ? max(0, intval($poll_length)) : 0;
  123. if (!empty($poll_title))
  124. {
  125. $poll_title = htmlspecialchars(trim($poll_title));
  126. }
  127. if(!empty($poll_options))
  128. {
  129. $temp_option_text = array();
  130. while(list($option_id, $option_text) = @each($poll_options))
  131. {
  132. $option_text = trim($option_text);
  133. if (!empty($option_text))
  134. {
  135. $temp_option_text[intval($option_id)] = htmlspecialchars($option_text);
  136. }
  137. }
  138. $option_text = $temp_option_text;
  139. if (count($poll_options) < 2)
  140. {
  141. $error_msg .= (!empty($error_msg)) ? '<br />' . $lang['To_few_poll_options'] : $lang['To_few_poll_options'];
  142. }
  143. else if (count($poll_options) > $board_config['max_poll_options'])
  144. {
  145. $error_msg .= (!empty($error_msg)) ? '<br />' . $lang['To_many_poll_options'] : $lang['To_many_poll_options'];
  146. }
  147. else if ($poll_title == '')
  148. {
  149. $error_msg .= (!empty($error_msg)) ? '<br />' . $lang['Empty_poll_title'] : $lang['Empty_poll_title'];
  150. }
  151. }
  152. }
  153. return;
  154. }
  155. //
  156. // Post a new topic/reply/poll or edit existing post/poll
  157. //
  158. 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)
  159. {
  160. global $board_config, $lang, $db, $phpbb_root_path, $phpEx;
  161. global $userdata, $user_ip;
  162. include($phpbb_root_path . 'includes/functions_search.'.$phpEx);
  163. $current_time = time();
  164. if ($mode == 'newtopic' || $mode == 'reply' || $mode == 'editpost')
  165. {
  166. //
  167. // Flood control
  168. //
  169. $where_sql = ($userdata['user_id'] == ANONYMOUS) ? "poster_ip = '$user_ip'" : 'poster_id = ' . $userdata['user_id'];
  170. $sql = "SELECT MAX(post_time) AS last_post_time
  171. FROM " . POSTS_TABLE . "
  172. WHERE $where_sql";
  173. if ($result = $db->sql_query($sql))
  174. {
  175. if ($row = $db->sql_fetchrow($result))
  176. {
  177. if (intval($row['last_post_time']) > 0 && ($current_time - intval($row['last_post_time'])) < intval($board_config['flood_interval']))
  178. {
  179. message_die(GENERAL_MESSAGE, $lang['Flood_Error']);
  180. }
  181. }
  182. }
  183. }
  184. if ($mode == 'editpost')
  185. {
  186. remove_search_post($post_id);
  187. }
  188. if ($mode == 'newtopic' || ($mode == 'editpost' && $post_data['first_post']))
  189. {
  190. $topic_vote = (!empty($poll_title) && count($poll_options) >= 2) ? 1 : 0;
  191. $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";
  192. if (!$db->sql_query($sql))
  193. {
  194. message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
  195. }
  196. if ($mode == 'newtopic')
  197. {
  198. $topic_id = $db->sql_nextid();
  199. }
  200. }
  201. $edited_sql = ($mode == 'editpost' && !$post_data['last_post'] && $post_data['poster_post']) ? ", post_edit_time = $current_time, post_edit_count = post_edit_count + 1 " : "";
  202. $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";
  203. if (!$db->sql_query($sql, BEGIN_TRANSACTION))
  204. {
  205. message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
  206. }
  207. if ($mode != 'editpost')
  208. {
  209. $post_id = $db->sql_nextid();
  210. }
  211. $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";
  212. if (!$db->sql_query($sql))
  213. {
  214. message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
  215. }
  216. add_search_words('single', $post_id, stripslashes($post_message), stripslashes($post_subject));
  217. //
  218. // Add poll
  219. //
  220. if (($mode == 'newtopic' || ($mode == 'editpost' && $post_data['edit_poll'])) && !empty($poll_title) && count($poll_options) >= 2)
  221. {
  222. $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";
  223. if (!$db->sql_query($sql))
  224. {
  225. message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
  226. }
  227. $delete_option_sql = '';
  228. $old_poll_result = array();
  229. if ($mode == 'editpost' && $post_data['has_poll'])
  230. {
  231. $sql = "SELECT vote_option_id, vote_result
  232. FROM " . VOTE_RESULTS_TABLE . "
  233. WHERE vote_id = $poll_id
  234. ORDER BY vote_option_id ASC";
  235. if (!($result = $db->sql_query($sql)))
  236. {
  237. message_die(GENERAL_ERROR, 'Could not obtain vote data results for this topic', '', __LINE__, __FILE__, $sql);
  238. }
  239. while ($row = $db->sql_fetchrow($result))
  240. {
  241. $old_poll_result[$row['vote_option_id']] = $row['vote_result'];
  242. if (!isset($poll_options[$row['vote_option_id']]))
  243. {
  244. $delete_option_sql .= ($delete_option_sql != '') ? ', ' . $row['vote_option_id'] : $row['vote_option_id'];
  245. }
  246. }
  247. }
  248. else
  249. {
  250. $poll_id = $db->sql_nextid();
  251. }
  252. @reset($poll_options);
  253. $poll_option_id = 1;
  254. while (list($option_id, $option_text) = each($poll_options))
  255. {
  256. if (!empty($option_text))
  257. {
  258. $option_text = str_replace("\'", "''", htmlspecialchars($option_text));
  259. $poll_result = ($mode == "editpost" && isset($old_poll_result[$option_id])) ? $old_poll_result[$option_id] : 0;
  260. $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";
  261. if (!$db->sql_query($sql))
  262. {
  263. message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
  264. }
  265. $poll_option_id++;
  266. }
  267. }
  268. if ($delete_option_sql != '')
  269. {
  270. $sql = "DELETE FROM " . VOTE_RESULTS_TABLE . "
  271. WHERE vote_option_id IN ($delete_option_sql)
  272. AND vote_id = $poll_id";
  273. if (!$db->sql_query($sql))
  274. {
  275. message_die(GENERAL_ERROR, 'Error deleting pruned poll options', '', __LINE__, __FILE__, $sql);
  276. }
  277. }
  278. }
  279. $meta = '<meta http-equiv="refresh" content="3;url=' . append_sid("viewtopic.$phpEx?" . POST_POST_URL . "=" . $post_id) . '#' . $post_id . '">';
  280. $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>');
  281. return false;
  282. }
  283. //
  284. // Update post stats and details
  285. //
  286. function update_post_stats(&$mode, &$post_data, &$forum_id, &$topic_id, &$post_id, &$user_id)
  287. {
  288. global $db;
  289. $sign = ($mode == 'delete') ? '- 1' : '+ 1';
  290. $forum_update_sql = "forum_posts = forum_posts $sign";
  291. $topic_update_sql = '';
  292. if ($mode == 'delete')
  293. {
  294. if ($post_data['last_post'])
  295. {
  296. if ($post_data['first_post'])
  297. {
  298. $forum_update_sql .= ', forum_topics = forum_topics - 1';
  299. }
  300. else
  301. {
  302. $topic_update_sql .= 'topic_replies = topic_replies - 1';
  303. $sql = "SELECT MAX(post_id) AS last_post_id
  304. FROM " . POSTS_TABLE . "
  305. WHERE topic_id = $topic_id";
  306. if (!($result = $db->sql_query($sql)))
  307. {
  308. message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);
  309. }
  310. if ($row = $db->sql_fetchrow($result))
  311. {
  312. $topic_update_sql .= ', topic_last_post_id = ' . $row['last_post_id'];
  313. }
  314. }
  315. if ($post_data['last_topic'])
  316. {
  317. $sql = "SELECT MAX(post_id) AS last_post_id
  318. FROM " . POSTS_TABLE . "
  319. WHERE forum_id = $forum_id";
  320. if (!($result = $db->sql_query($sql)))
  321. {
  322. message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);
  323. }
  324. if ($row = $db->sql_fetchrow($result))
  325. {
  326. $forum_update_sql .= ($row['last_post_id']) ? ', forum_last_post_id = ' . $row['last_post_id'] : ', forum_last_post_id = 0';
  327. }
  328. }
  329. }
  330. else if ($post_data['first_post'])
  331. {
  332. $sql = "SELECT MIN(post_id) AS first_post_id
  333. FROM " . POSTS_TABLE . "
  334. WHERE topic_id = $topic_id";
  335. if (!($result = $db->sql_query($sql)))
  336. {
  337. message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);
  338. }
  339. if ($row = $db->sql_fetchrow($result))
  340. {
  341. $topic_update_sql .= 'topic_replies = topic_replies - 1, topic_first_post_id = ' . $row['first_post_id'];
  342. }
  343. }
  344. else
  345. {
  346. $topic_update_sql .= 'topic_replies = topic_replies - 1';
  347. }
  348. }
  349. else if ($mode != 'poll_delete')
  350. {
  351. $forum_update_sql .= ", forum_last_post_id = $post_id" . (($mode == 'newtopic') ? ", forum_topics = forum_topics $sign" : "");
  352. $topic_update_sql = "topic_last_post_id = $post_id" . (($mode == 'reply') ? ", topic_replies = topic_replies $sign" : ", topic_first_post_id = $post_id");
  353. }
  354. else
  355. {
  356. $topic_update_sql .= 'topic_vote = 0';
  357. }
  358. if ($mode != 'poll_delete')
  359. {
  360. $sql = "UPDATE " . FORUMS_TABLE . " SET
  361. $forum_update_sql
  362. WHERE forum_id = $forum_id";
  363. if (!$db->sql_query($sql))
  364. {
  365. message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
  366. }
  367. }
  368. if ($topic_update_sql != '')
  369. {
  370. $sql = "UPDATE " . TOPICS_TABLE . " SET
  371. $topic_update_sql
  372. WHERE topic_id = $topic_id";
  373. if (!$db->sql_query($sql))
  374. {
  375. message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
  376. }
  377. }
  378. if ($mode != 'poll_delete')
  379. {
  380. $sql = "UPDATE " . USERS_TABLE . "
  381. SET user_posts = user_posts $sign
  382. WHERE user_id = $user_id";
  383. if (!$db->sql_query($sql, END_TRANSACTION))
  384. {
  385. message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
  386. }
  387. }
  388. return;
  389. }
  390. //
  391. // Delete a post/poll
  392. //
  393. function delete_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_id, &$post_id, &$poll_id)
  394. {
  395. global $board_config, $lang, $db, $phpbb_root_path, $phpEx;
  396. global $userdata, $user_ip;
  397. if ($mode != 'poll_delete')
  398. {
  399. include($phpbb_root_path . 'includes/functions_search.'.$phpEx);
  400. $sql = "DELETE FROM " . POSTS_TABLE . "
  401. WHERE post_id = $post_id";
  402. if (!$db->sql_query($sql))
  403. {
  404. message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);
  405. }
  406. $sql = "DELETE FROM " . POSTS_TEXT_TABLE . "
  407. WHERE post_id = $post_id";
  408. if (!$db->sql_query($sql))
  409. {
  410. message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);
  411. }
  412. if ($post_data['last_post'])
  413. {
  414. if ($post_data['first_post'])
  415. {
  416. $forum_update_sql .= ', forum_topics = forum_topics - 1';
  417. $sql = "DELETE FROM " . TOPICS_TABLE . "
  418. WHERE topic_id = $topic_id
  419. OR topic_moved_id = $topic_id";
  420. if (!$db->sql_query($sql))
  421. {
  422. message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);
  423. }
  424. $sql = "DELETE FROM " . TOPICS_WATCH_TABLE . "
  425. WHERE topic_id = $topic_id";
  426. if (!$db->sql_query($sql))
  427. {
  428. message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);
  429. }
  430. }
  431. }
  432. remove_search_post($post_id);
  433. }
  434. if ($mode == 'poll_delete' || ($mode == 'delete' && $post_data['first_post'] && $post_data['last_post']) && $post_data['has_poll'] && $post_data['edit_poll'])
  435. {
  436. $sql = "DELETE FROM " . VOTE_DESC_TABLE . "
  437. WHERE topic_id = $topic_id";
  438. if (!$db->sql_query($sql))
  439. {
  440. message_die(GENERAL_ERROR, 'Error in deleting poll', '', __LINE__, __FILE__, $sql);
  441. }
  442. $sql = "DELETE FROM " . VOTE_RESULTS_TABLE . "
  443. WHERE vote_id = $poll_id";
  444. if (!$db->sql_query($sql))
  445. {
  446. message_die(GENERAL_ERROR, 'Error in deleting poll', '', __LINE__, __FILE__, $sql);
  447. }
  448. $sql = "DELETE FROM " . VOTE_USERS_TABLE . "
  449. WHERE vote_id = $poll_id";
  450. if (!$db->sql_query($sql))
  451. {
  452. message_die(GENERAL_ERROR, 'Error in deleting poll', '', __LINE__, __FILE__, $sql);
  453. }
  454. }
  455. if ($mode == 'delete' && $post_data['first_post'] && $post_data['last_post'])
  456. {
  457. $meta = '<meta http-equiv="refresh" content="3;url=' . append_sid("viewforum.$phpEx?" . POST_FORUM_URL . '=' . $forum_id) . '">';
  458. $message = $lang['Deleted'];
  459. }
  460. else
  461. {
  462. $meta = '<meta http-equiv="refresh" content="3;url=' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . '=' . $topic_id) . '">';
  463. $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>');
  464. }
  465. $message .= '<br /><br />' . sprintf($lang['Click_return_forum'], '<a href="' . append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id") . '">', '</a>');
  466. return;
  467. }
  468. //
  469. // Handle user notification on new post
  470. //
  471. function user_notification($mode, &$post_data, &$topic_title, &$forum_id, &$topic_id, &$post_id, &$notify_user)
  472. {
  473. global $board_config, $lang, $db, $phpbb_root_path, $phpEx;
  474. global $userdata, $user_ip;
  475. $current_time = time();
  476. if ($mode != 'delete')
  477. {
  478. if ($mode == 'reply')
  479. {
  480. $sql = "SELECT ban_userid
  481. FROM " . BANLIST_TABLE;
  482. if (!($result = $db->sql_query($sql)))
  483. {
  484. message_die(GENERAL_ERROR, 'Could not obtain banlist', '', __LINE__, __FILE__, $sql);
  485. }
  486. $user_id_sql = '';
  487. while ($row = $db->sql_fetchrow($result))
  488. {
  489. if (isset($row['ban_userid']) && !empty($row['ban_userid']))
  490. {
  491. $user_id_sql .= ', ' . $row['ban_userid'];
  492. }
  493. }
  494. $sql = "SELECT u.user_id, u.user_email, u.user_lang
  495. FROM " . TOPICS_WATCH_TABLE . " tw, " . USERS_TABLE . " u
  496. WHERE tw.topic_id = $topic_id
  497. AND tw.user_id NOT IN (" . $userdata['user_id'] . ", " . ANONYMOUS . $user_id_sql . ")
  498. AND tw.notify_status = " . TOPIC_WATCH_UN_NOTIFIED . "
  499. AND u.user_id = tw.user_id";
  500. if (!($result = $db->sql_query($sql)))
  501. {
  502. message_die(GENERAL_ERROR, 'Could not obtain list of topic watchers', '', __LINE__, __FILE__, $sql);
  503. }
  504. $update_watched_sql = '';
  505. $bcc_list_ary = array();
  506. if ($row = $db->sql_fetchrow($result))
  507. {
  508. // Sixty second limit
  509. @set_time_limit(60);
  510. do
  511. {
  512. if ($row['user_email'] != '')
  513. {
  514. $bcc_list_ary[$row['user_lang']][] = $row['user_email'];
  515. }
  516. $update_watched_sql .= ($update_watched_sql != '') ? ', ' . $row['user_id'] : $row['user_id'];
  517. }
  518. while ($row = $db->sql_fetchrow($result));
  519. //
  520. // Let's do some checking to make sure that mass mail functions
  521. // are working in win32 versions of php.
  522. //
  523. if (preg_match('/[c-z]:\\\.*/i', getenv('PATH')) && !$board_config['smtp_delivery'])
  524. {
  525. $ini_val = (@phpversion() >= '4.0.0') ? 'ini_get' : 'get_cfg_var';
  526. // We are running on windows, force delivery to use our smtp functions
  527. // since php's are broken by default
  528. $board_config['smtp_delivery'] = 1;
  529. $board_config['smtp_host'] = @$ini_val('SMTP');
  530. }
  531. if (sizeof($bcc_list_ary))
  532. {
  533. include($phpbb_root_path . 'includes/emailer.'.$phpEx);
  534. $emailer = new emailer($board_config['smtp_delivery']);
  535. $script_name = preg_replace('/^\/?(.*?)\/?$/', '\1', trim($board_config['script_path']));
  536. $script_name = ($script_name != '') ? $script_name . '/viewtopic.'.$phpEx : 'viewtopic.'.$phpEx;
  537. $server_name = trim($board_config['server_name']);
  538. $server_protocol = ($board_config['cookie_secure']) ? 'https://' : 'http://';
  539. $server_port = ($board_config['server_port'] <> 80) ? ':' . trim($board_config['server_port']) . '/' : '/';
  540. $orig_word = array();
  541. $replacement_word = array();
  542. obtain_word_list($orig_word, $replacement_word);
  543. $emailer->from($board_config['board_email']);
  544. $emailer->replyto($board_config['board_email']);
  545. $topic_title = (count($orig_word)) ? preg_replace($orig_word, $replacement_word, unprepare_message($topic_title)) : unprepare_message($topic_title);
  546. @reset($bcc_list_ary);
  547. while (list($user_lang, $bcc_list) = each($bcc_list_ary))
  548. {
  549. $emailer->use_template('topic_notify', $user_lang);
  550. for ($i = 0; $i < count($bcc_list); $i++)
  551. {
  552. $emailer->bcc($bcc_list[$i]);
  553. }
  554. // The Topic_reply_notification lang string below will be used
  555. // if for some reason the mail template subject cannot be read
  556. // ... note it will not necessarily be in the posters own language!
  557. $emailer->set_subject($lang['Topic_reply_notification']);
  558. // This is a nasty kludge to remove the username var ... till (if?)
  559. // translators update their templates
  560. $emailer->msg = preg_replace('#[ ]?{USERNAME}#', '', $emailer->msg);
  561. $emailer->assign_vars(array(
  562. 'EMAIL_SIG' => (!empty($board_config['board_email_sig'])) ? str_replace('<br />', "\n", "-- \n" . $board_config['board_email_sig']) : '',
  563. 'SITENAME' => $board_config['sitename'],
  564. 'TOPIC_TITLE' => $topic_title,
  565. 'U_TOPIC' => $server_protocol . $server_name . $server_port . $script_name . '?' . POST_POST_URL . "=$post_id#$post_id",
  566. 'U_STOP_WATCHING_TOPIC' => $server_protocol . $server_name . $server_port . $script_name . '?' . POST_TOPIC_URL . "=$topic_id&unwatch=topic")
  567. );
  568. $emailer->send();
  569. $emailer->reset();
  570. }
  571. }
  572. }
  573. $db->sql_freeresult($result);
  574. if ($update_watched_sql != '')
  575. {
  576. $sql = "UPDATE " . TOPICS_WATCH_TABLE . "
  577. SET notify_status = " . TOPIC_WATCH_NOTIFIED . "
  578. WHERE topic_id = $topic_id
  579. AND user_id IN ($update_watched_sql)";
  580. $db->sql_query($sql);
  581. }
  582. }
  583. $sql = "SELECT topic_id
  584. FROM " . TOPICS_WATCH_TABLE . "
  585. WHERE topic_id = $topic_id
  586. AND user_id = " . $userdata['user_id'];
  587. if (!($result = $db->sql_query($sql)))
  588. {
  589. message_die(GENERAL_ERROR, 'Could not obtain topic watch information', '', __LINE__, __FILE__, $sql);
  590. }
  591. $row = $db->sql_fetchrow($result);
  592. if (!$notify_user && !empty($row['topic_id']))
  593. {
  594. $sql = "DELETE FROM " . TOPICS_WATCH_TABLE . "
  595. WHERE topic_id = $topic_id
  596. AND user_id = " . $userdata['user_id'];
  597. if (!$db->sql_query($sql))
  598. {
  599. message_die(GENERAL_ERROR, 'Could not delete topic watch information', '', __LINE__, __FILE__, $sql);
  600. }
  601. }
  602. else if ($notify_user && empty($row['topic_id']))
  603. {
  604. $sql = "INSERT INTO " . TOPICS_WATCH_TABLE . " (user_id, topic_id, notify_status)
  605. VALUES (" . $userdata['user_id'] . ", $topic_id, 0)";
  606. if (!$db->sql_query($sql))
  607. {
  608. message_die(GENERAL_ERROR, 'Could not insert topic watch information', '', __LINE__, __FILE__, $sql);
  609. }
  610. }
  611. }
  612. }
  613. //
  614. // Fill smiley templates (or just the variables) with smileys
  615. // Either in a window or inline
  616. //
  617. function generate_smilies($mode, $page_id)
  618. {
  619. global $db, $board_config, $template, $lang, $images, $theme, $phpEx, $phpbb_root_path;
  620. global $user_ip, $session_length, $starttime;
  621. global $userdata;
  622. $inline_columns = 4;
  623. $inline_rows = 5;
  624. $window_columns = 8;
  625. if ($mode == 'window')
  626. {
  627. $userdata = session_pagestart($user_ip, $page_id);
  628. init_userprefs($userdata);
  629. $gen_simple_header = TRUE;
  630. $page_title = $lang['Emoticons'];
  631. include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  632. $template->set_filenames(array(
  633. 'smiliesbody' => 'posting_smilies.tpl')
  634. );
  635. }
  636. $sql = "SELECT emoticon, code, smile_url
  637. FROM " . SMILIES_TABLE . "
  638. ORDER BY smilies_id";
  639. if ($result = $db->sql_query($sql))
  640. {
  641. $num_smilies = 0;
  642. $rowset = array();
  643. while ($row = $db->sql_fetchrow($result))
  644. {
  645. if (empty($rowset[$row['smile_url']]))
  646. {
  647. $rowset[$row['smile_url']]['code'] = str_replace("'", "\\'", str_replace('\\', '\\\\', $row['code']));
  648. $rowset[$row['smile_url']]['emoticon'] = $row['emoticon'];
  649. $num_smilies++;
  650. }
  651. }
  652. if ($num_smilies)
  653. {
  654. $smilies_count = ($mode == 'inline') ? min(19, $num_smilies) : $num_smilies;
  655. $smilies_split_row = ($mode == 'inline') ? $inline_columns - 1 : $window_columns - 1;
  656. $s_colspan = 0;
  657. $row = 0;
  658. $col = 0;
  659. while (list($smile_url, $data) = @each($rowset))
  660. {
  661. if (!$col)
  662. {
  663. $template->assign_block_vars('smilies_row', array());
  664. }
  665. $template->assign_block_vars('smilies_row.smilies_col', array(
  666. 'SMILEY_CODE' => $data['code'],
  667. 'SMILEY_IMG' => $board_config['smilies_path'] . '/' . $smile_url,
  668. 'SMILEY_DESC' => $data['emoticon'])
  669. );
  670. $s_colspan = max($s_colspan, $col + 1);
  671. if ($col == $smilies_split_row)
  672. {
  673. if ($mode == 'inline' && $row == $inline_rows - 1)
  674. {
  675. break;
  676. }
  677. $col = 0;
  678. $row++;
  679. }
  680. else
  681. {
  682. $col++;
  683. }
  684. }
  685. if ($mode == 'inline' && $num_smilies > $inline_rows * $inline_columns)
  686. {
  687. $template->assign_block_vars('switch_smilies_extra', array());
  688. $template->assign_vars(array(
  689. 'L_MORE_SMILIES' => $lang['More_emoticons'],
  690. 'U_MORE_SMILIES' => append_sid("posting.$phpEx?mode=smilies"))
  691. );
  692. }
  693. $template->assign_vars(array(
  694. 'L_EMOTICONS' => $lang['Emoticons'],
  695. 'L_CLOSE_WINDOW' => $lang['Close_window'],
  696. 'S_SMILIES_COLSPAN' => $s_colspan)
  697. );
  698. }
  699. }
  700. if ($mode == 'window')
  701. {
  702. $template->pparse('smiliesbody');
  703. include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
  704. }
  705. }
  706. /**
  707. * Called from within prepare_message to clean included HTML tags if HTML is
  708. * turned on for that post
  709. * @param array $tag Matching text from the message to parse
  710. */
  711. function clean_html($tag)
  712. {
  713. global $board_config;
  714. if (empty($tag[0]))
  715. {
  716. return '';
  717. }
  718. $allowed_html_tags = preg_split('/, */', strtolower($board_config['allow_html_tags']));
  719. $disallowed_attributes = '/^(?:style|on)/i';
  720. // Check if this is an end tag
  721. preg_match('/<[^\w\/]*\/[\W]*(\w+)/', $tag[0], $matches);
  722. if (sizeof($matches))
  723. {
  724. if (in_array(strtolower($matches[1]), $allowed_html_tags))
  725. {
  726. return '</' . $matches[1] . '>';
  727. }
  728. else
  729. {
  730. return htmlspecialchars('</' . $matches[1] . '>');
  731. }
  732. }
  733. // Check if this is an allowed tag
  734. if (in_array(strtolower($tag[1]), $allowed_html_tags))
  735. {
  736. $attributes = '';
  737. if (!empty($tag[2]))
  738. {
  739. preg_match_all('/[\W]*?(\w+)[\W]*?=[\W]*?(["\'])((?:(?!\2).)*)\2/', $tag[2], $test);
  740. for ($i = 0; $i < sizeof($test[0]); $i++)
  741. {
  742. if (preg_match($disallowed_attributes, $test[1][$i]))
  743. {
  744. continue;
  745. }
  746. $attributes .= ' ' . $test[1][$i] . '=' . $test[2][$i] . str_replace(array('[', ']'), array('&#91;', '&#93;'), htmlspecialchars($test[3][$i])) . $test[2][$i];
  747. }
  748. }
  749. if (in_array(strtolower($tag[1]), $allowed_html_tags))
  750. {
  751. return '<' . $tag[1] . $attributes . '>';
  752. }
  753. else
  754. {
  755. return htmlspecialchars('<' . $tag[1] . $attributes . '>');
  756. }
  757. }
  758. // Finally, this is not an allowed tag so strip all the attibutes and escape it
  759. else
  760. {
  761. return htmlspecialchars('<' . $tag[1] . '>');
  762. }
  763. }
  764. ?>