PageRenderTime 64ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/posting.php

https://github.com/MightyGorgon/icy_phoenix
PHP | 2564 lines | 2071 code | 260 blank | 233 comment | 672 complexity | 68a1ad9e1d79eb77c6463c3fac58861f MD5 | raw file
Possible License(s): AGPL-1.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. *
  4. * @package Icy Phoenix
  5. * @version $Id$
  6. * @copyright (c) 2008 Icy Phoenix
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. *
  12. * @Icy Phoenix is based on phpBB
  13. * @copyright (c) 2008 phpBB Group
  14. *
  15. */
  16. define('IN_POSTING', true);
  17. // MG Cash MOD For IP - BEGIN
  18. define('IN_CASHMOD', true);
  19. define('CM_POSTING', true);
  20. // MG Cash MOD For IP - END
  21. // Added to optimize memory for attachments
  22. define('ATTACH_DISPLAY', true);
  23. define('ATTACH_POSTING', true);
  24. define('CT_SECLEVEL', 'MEDIUM');
  25. $ct_ignorepvar = array('helpbox');
  26. define('IN_ICYPHOENIX', true);
  27. if (!defined('IP_ROOT_PATH')) define('IP_ROOT_PATH', './');
  28. if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
  29. include(IP_ROOT_PATH . 'common.' . PHP_EXT);
  30. include_once(IP_ROOT_PATH . 'includes/bbcode.' . PHP_EXT);
  31. include_once(IP_ROOT_PATH . 'includes/functions_post.' . PHP_EXT);
  32. include_once(IP_ROOT_PATH . 'includes/functions_topics.' . PHP_EXT);
  33. include_once(IP_ROOT_PATH . 'includes/functions_calendar.' . PHP_EXT);
  34. // Event Registration - BEGIN
  35. include_once(IP_ROOT_PATH . 'includes/functions_events_reg.' . PHP_EXT);
  36. // Event Registration - END
  37. @include_once(IP_ROOT_PATH . 'includes/class_topics.' . PHP_EXT);
  38. $class_topics = new class_topics();
  39. $use_jquery_tags = (!empty($config['use_jquery_tags']) && empty($user->data['mobile_style'])) ? true : false;
  40. //$use_jquery_tags = false;
  41. $config['jquery_ui'] = true;
  42. if (!empty($use_jquery_tags))
  43. {
  44. $config['jquery_tags'] = true;
  45. }
  46. // Init common vars: forum_id, topic_id, post_id, etc.
  47. $class_topics->var_init(true);
  48. // Check and set various parameters
  49. $sid = request_var('sid', '');
  50. $mode = request_var('mode', '');
  51. $submit = request_var('post', '');
  52. $news_category = request_var('news_category', '');
  53. $preview = request_var('preview', '');
  54. $draft = request_var('draft', '');
  55. $draft_mode = request_var('draft_mode', '');
  56. $delete = request_var('delete', '');
  57. $poll_delete = request_var('poll_delete', '');
  58. $poll_add = request_var('add_poll_option', '');
  59. $poll_edit = request_var('edit_poll_option', '');
  60. // UPI2DB - BEGIN
  61. $mark_edit = request_var('mark_edit', '');
  62. // UPI2DB - END
  63. $start = request_var('start', 0);
  64. $start = ($start < 0) ? 0 : $start;
  65. $confirm = isset($_POST['confirm']) ? true : false;
  66. $draft_confirm = !empty($_POST['draft_confirm']) ? true : false;
  67. $draft = (!empty($draft) || $draft_confirm) ? true : false;
  68. $lock_subject = request_var('lock_subject', 0);
  69. $draft_subject = '';
  70. $draft_message = '';
  71. if ($config['allow_drafts'] && ($draft_mode == 'draft_load') && ($draft_id > 0))
  72. {
  73. $sql = "SELECT d.*
  74. FROM " . DRAFTS_TABLE . " d
  75. WHERE d.draft_id = " . $draft_id . "
  76. LIMIT 1";
  77. $result = $db->sql_query($sql);
  78. if ($draft_row = $db->sql_fetchrow($result))
  79. {
  80. $db->sql_freeresult($result);
  81. if ($draft_row['forum_id'] > 0)
  82. {
  83. $forum_id = $draft_row['forum_id'];
  84. if ($draft_row['topic_id'] > 0)
  85. {
  86. $topic_id = $draft_row['topic_id'];
  87. }
  88. else
  89. {
  90. $topic_id = '';
  91. }
  92. $draft_subject = $draft_row['draft_subject'];
  93. $draft_message = htmlspecialchars_decode($draft_row['draft_message'], ENT_COMPAT);
  94. $preview = true;
  95. }
  96. else
  97. {
  98. $draft_subject = $draft_row['draft_subject'];
  99. $draft_message = $draft_row['draft_message'];
  100. $preview = true;
  101. }
  102. }
  103. }
  104. $forum_id_append = (!empty($forum_id) ? (POST_FORUM_URL . '=' . $forum_id) : '');
  105. $topic_id_append = (!empty($topic_id) ? (POST_TOPIC_URL . '=' . $topic_id) : '');
  106. $post_id_append = (!empty($post_id) ? (POST_POST_URL . '=' . $post_id) : '');
  107. // . (!empty($forum_id_append) ? ($forum_id_append . '&amp;') : '') . (!empty($topic_id_append) ? ($topic_id_append . '&amp;') : '') . $post_id_append
  108. $s_hidden_fields = '';
  109. $hidden_form_fields = '';
  110. $refresh = !empty($preview) || $poll_add || $poll_edit || $poll_delete || ($draft && !$draft_confirm);
  111. // Set topic type
  112. //echo $topic_type;
  113. //$topic_type = (in_array($topic_type, array(0, 1, 2, 3, 4))) ? $topic_type : POST_NORMAL;
  114. $topic_show_portal = (!empty($_POST['topic_show_portal'])) ? true : false;
  115. $topic_type = request_var('topictype', POST_NORMAL);
  116. if (!$topic_type)
  117. {
  118. $topic_type = POST_NORMAL;
  119. }
  120. // Maybe better do not replace these $_POST with request_var, or we may have further problems later
  121. $year = request_post_var('topic_calendar_year', 0);
  122. $month = request_post_var('topic_calendar_month', 0);
  123. $day = request_post_var('topic_calendar_day', 0);
  124. $hour = request_post_var('topic_calendar_hour', 0);
  125. $min = request_post_var('topic_calendar_min', 0);
  126. $d_day = request_post_var('topic_calendar_duration_day', 0);
  127. $d_hour = request_post_var('topic_calendar_duration_hour', 0);
  128. $d_min = request_post_var('topic_calendar_duration_min', 0);
  129. // this array will hold the plugin-specific variables
  130. $extra_vars = array();
  131. /**
  132. * @event posting.post_vars.
  133. * @description Allows to read POST data to be used later.
  134. * @since 3.0
  135. * @var int topic_type The topic type.
  136. * @var array extra_vars The extra variables that'll be carried throughout this file.
  137. */
  138. $vars = array(
  139. 'topic_type',
  140. 'extra_vars',
  141. );
  142. extract($class_plugins->trigger('posting.post_vars', compact($vars)));
  143. if (empty($year) || empty($month) || empty($day))
  144. {
  145. $year = '';
  146. $month = '';
  147. $day = '';
  148. $hour = '';
  149. $min = '';
  150. $d_day = '';
  151. $d_hour = '';
  152. $d_min = '';
  153. }
  154. if (empty($hour) && empty($min))
  155. {
  156. $hour = '';
  157. $min = '';
  158. $d_hour = '';
  159. $d_min = '';
  160. }
  161. // start event
  162. $topic_calendar_time = 0;
  163. if (!empty($year))
  164. {
  165. $topic_calendar_time = gmmktime(intval($hour), intval($min), 0, intval($month), intval($day), intval($year));
  166. }
  167. // duration
  168. $topic_calendar_duration = 0;
  169. $d_dur = $d_day . $d_hour . $d_min;
  170. if (!empty($topic_calendar_time) && !empty($d_dur))
  171. {
  172. $topic_calendar_duration = intval($d_day) * 86400 + intval($d_hour) * 3600 + intval($d_min) * 60;
  173. if ($topic_calendar_duration < 0)
  174. {
  175. $topic_calendar_duration = 0;
  176. }
  177. }
  178. // If the mode is set to topic review then output that review...
  179. if ($mode == 'topicreview')
  180. {
  181. require(IP_ROOT_PATH . 'includes/topic_review.' . PHP_EXT);
  182. topic_review($forum_id, $topic_id, false);
  183. exit;
  184. }
  185. elseif ($mode == 'smilies')
  186. {
  187. generate_smilies('window');
  188. exit;
  189. }
  190. // Start session management
  191. $user->session_begin();
  192. $auth->acl($user->data);
  193. $user->setup();
  194. // End session management
  195. // DNSBL CHECK - BEGIN
  196. if (!empty($config['check_dnsbl_posting']) && in_array($mode, array('newtopic', 'reply', 'editpost')) && !empty($submit))
  197. {
  198. if (($dnsbl = $user->check_dnsbl('post')) !== false)
  199. {
  200. $error[] = sprintf($lang['IP_BLACKLISTED'], $user->ip, $dnsbl[1], $dnsbl[1]);
  201. }
  202. if (!empty($error))
  203. {
  204. $message = implode('<br />', $error);
  205. message_die(GENERAL_MESSAGE, $message);
  206. }
  207. }
  208. // DNSBL CHECK - END
  209. // Was cancel pressed? If so then redirect to the appropriate page, no point in continuing with any further checks
  210. if (isset($_POST['cancel']))
  211. {
  212. if ($postreport)
  213. {
  214. $redirect = CMS_PAGE_VIEWTOPIC . '?' . (!empty($forum_id_append) ? ($forum_id_append . '&') : '') . (!empty($topic_id_append) ? ($topic_id_append . '&') : '') . POST_POST_URL . '=' . $postreport;
  215. $post_append = '';
  216. }
  217. elseif ($post_id)
  218. {
  219. $redirect = CMS_PAGE_VIEWTOPIC . '?' . (!empty($forum_id_append) ? ($forum_id_append . '&') : '') . (!empty($topic_id_append) ? ($topic_id_append . '&') : '') . $post_id_append;
  220. $post_append = '#p' . $post_id;
  221. }
  222. elseif ($topic_id)
  223. {
  224. $redirect = CMS_PAGE_VIEWTOPIC . '?' . (!empty($forum_id_append) ? ($forum_id_append . '&') : '') . $topic_id_append;
  225. $post_append = '';
  226. }
  227. elseif ($forum_id)
  228. {
  229. $redirect = CMS_PAGE_VIEWFORUM . '?' . $forum_id_append;
  230. $post_append = '';
  231. }
  232. else
  233. {
  234. $redirect = CMS_PAGE_FORUM;
  235. $post_append = '';
  236. }
  237. redirect(append_sid($redirect, true) . $post_append);
  238. }
  239. // What auth type do we need to check?
  240. $is_auth = array();
  241. $is_auth_type = '';
  242. $is_auth_type_cal = '';
  243. $read_only_write_auth_required = false;
  244. switch($mode)
  245. {
  246. case 'newtopic':
  247. // TODO: these also need to be checked if ($mode == 'editpost' && $post_data['first_post'])
  248. $read_only_write_auth_required = true;
  249. if ($topic_type == POST_GLOBAL_ANNOUNCE)
  250. {
  251. $is_auth_type = 'auth_globalannounce';
  252. }
  253. elseif ($topic_type == POST_ANNOUNCE)
  254. {
  255. $is_auth_type = 'auth_announce';
  256. }
  257. elseif ($topic_type == POST_STICKY)
  258. {
  259. $is_auth_type = 'auth_sticky';
  260. }
  261. else
  262. {
  263. $is_auth_type = 'auth_post';
  264. }
  265. if (!empty($topic_calendar_time))
  266. {
  267. $is_auth_type_cal = 'auth_cal';
  268. }
  269. break;
  270. case 'reply':
  271. case 'quote':
  272. $read_only_write_auth_required = true;
  273. $is_auth_type = 'auth_reply';
  274. break;
  275. case 'editpost':
  276. $read_only_write_auth_required = true;
  277. $is_auth_type = 'auth_edit';
  278. break;
  279. case 'delete':
  280. case 'poll_delete':
  281. $read_only_write_auth_required = true;
  282. $is_auth_type = 'auth_delete';
  283. break;
  284. case 'vote':
  285. $is_auth_type = 'auth_vote';
  286. break;
  287. // Event Registration - BEGIN
  288. case 'register':
  289. $is_auth_type = 'auth_vote';
  290. break;
  291. // Event Registration - END
  292. case 'topicreview':
  293. $is_auth_type = 'auth_read';
  294. break;
  295. default:
  296. message_die(GENERAL_MESSAGE, $lang['No_post_mode']);
  297. break;
  298. }
  299. //if ($read_only_write_auth_required && $config['read_only_forum'])
  300. if ($read_only_write_auth_required && $config['read_only_forum'] && ($user->data['user_level'] != ADMIN))
  301. {
  302. message_die(GENERAL_MESSAGE, $lang['READ_ONLY_FORUM']);
  303. }
  304. //
  305. // Here we do various lookups to find topic_id, forum_id, post_id etc.
  306. // Doing it here prevents spoofing (eg. faking forum_id, topic_id or post_id
  307. //
  308. $error_msg = '';
  309. $post_data = array();
  310. switch ($mode)
  311. {
  312. case 'newtopic':
  313. if (empty($forum_id))
  314. {
  315. if (!defined('STATUS_404')) define('STATUS_404', true);
  316. message_die(GENERAL_MESSAGE, 'NO_FORUM');
  317. }
  318. $sql = "SELECT f.*
  319. FROM " . FORUMS_TABLE . " f
  320. WHERE f.forum_id = " . $forum_id . "
  321. LIMIT 1";
  322. break;
  323. case 'reply':
  324. case 'vote':
  325. // Event Registration - BEGIN
  326. case 'register':
  327. // Event Registration - END
  328. if (empty($topic_id))
  329. {
  330. message_die(GENERAL_MESSAGE, $lang['No_topic_id']);
  331. }
  332. $sql = "SELECT f.*, t.*
  333. FROM " . FORUMS_TABLE . " f, " . TOPICS_TABLE . " t
  334. WHERE t.topic_id = " . $topic_id . "
  335. AND f.forum_id = t.forum_id
  336. LIMIT 1";
  337. break;
  338. case 'quote':
  339. case 'editpost':
  340. case 'delete':
  341. case 'poll_delete':
  342. if (empty($post_id))
  343. {
  344. message_die(GENERAL_MESSAGE, $lang['No_post_id']);
  345. }
  346. // MG Cash MOD For IP - BEGIN
  347. if (!empty($config['plugins']['cash']['enabled']))
  348. {
  349. $temp = $submit;
  350. $submit = !(!$submit || (isset($config['cash_disable']) && !$config['cash_disable'] && (($mode == 'editpost') || ($mode == 'delete'))));
  351. }
  352. // MG Cash MOD For IP - END
  353. $query = array(
  354. 'SELECT' => array('f.*', 't.*', 'p.*'),
  355. 'FROM' => array(
  356. POSTS_TABLE => 'p',
  357. TOPICS_TABLE => 't',
  358. FORUMS_TABLE => 'f',
  359. ),
  360. 'WHERE' => array(
  361. 'p.post_id = ' . $post_id,
  362. 't.topic_id = p.topic_id',
  363. 'f.forum_id = p.forum_id',
  364. ),
  365. 'LIMIT' => 1,
  366. );
  367. if (!$submit)
  368. {
  369. $query['SELECT'] = array_merge($query['SELECT'], array('u.username', 'u.user_id', 'u.user_sig', 'u.user_level', 'u.user_active', 'u.user_color'));
  370. $query['FROM'][USERS_TABLE] = 'u';
  371. $query['WHERE'][] = 'u.user_id = p.poster_id';
  372. }
  373. /**
  374. * @event posting.before_select.
  375. * @description Allows to edit the query to look up the forum / topic / post data.
  376. * @since 3.0
  377. * @var array query The SQL query parts.
  378. */
  379. extract($class_plugins->trigger('posting.before_select', compact('query')));
  380. $sql = $db->sql_build_query('SELECT', $query);
  381. // MG Cash MOD For IP - BEGIN
  382. if (!empty($config['plugins']['cash']['enabled']))
  383. {
  384. $submit = $temp;
  385. unset($temp);
  386. }
  387. // MG Cash MOD For IP - END
  388. break;
  389. default:
  390. message_die(GENERAL_MESSAGE, $lang['No_valid_mode']);
  391. }
  392. $result = $db->sql_query($sql);
  393. $post_info = $db->sql_fetchrow($result);
  394. if ($result && $post_info)
  395. {
  396. $db->sql_freeresult($result);
  397. $forum_id = $post_info['forum_id'];
  398. if (!empty($post_info['topic_calendar_duration']))
  399. {
  400. $post_info['topic_calendar_duration']++;
  401. }
  402. $forum_name = get_object_lang(POST_FORUM_URL . $post_info['forum_id'], 'name');
  403. $is_auth = auth(AUTH_ALL, $forum_id, $user->data, $post_info);
  404. // Topic Lock/Unlock
  405. $lock = (isset($_POST['lock'])) ? true : false;
  406. $unlock = (isset($_POST['unlock'])) ? true : false;
  407. if (($submit || $confirm) && ($lock || $unlock) && $is_auth['auth_mod'] && ($mode != 'newtopic') && (!$refresh))
  408. {
  409. $t_id = (!isset($post_info['topic_id'])) ? $topic_id : $post_info['topic_id'];
  410. if ($lock || $unlock)
  411. {
  412. $sql = "UPDATE " . TOPICS_TABLE . "
  413. SET topic_status = " . ($lock ? TOPIC_LOCKED : TOPIC_UNLOCKED) . "
  414. WHERE topic_id = " . $t_id . "
  415. AND topic_moved_id = 0";
  416. $result = $db->sql_query($sql);
  417. }
  418. }
  419. if (($post_info['forum_status'] == FORUM_LOCKED) && !$is_auth['auth_mod'])
  420. {
  421. message_die(GENERAL_MESSAGE, $lang['Forum_locked']);
  422. }
  423. elseif (($mode != 'newtopic') && ($post_info['topic_status'] == TOPIC_LOCKED) && !$is_auth['auth_mod'])
  424. {
  425. message_die(GENERAL_MESSAGE, $lang['Topic_locked']);
  426. }
  427. // LIMIT POST EDIT TIME - BEGIN
  428. $is_global_limit_edit_enabled = ($post_info['forum_limit_edit_time'] && (intval($config['forum_limit_edit_time_interval']) > 0)) ? true : false;
  429. $is_spam_limit_edit_enabled = ((intval($config['spam_posts_number']) > 0) && ($user->data['user_posts'] < (int) $config['spam_posts_number']) && (intval($config['spam_post_edit_interval']) > 0)) ? true : false;
  430. if (($mode == 'editpost') && ($user->data['user_level'] != ADMIN) && !$is_auth['auth_mod'] && !$submit && ($is_global_limit_edit_enabled || $is_spam_limit_edit_enabled))
  431. {
  432. if (($is_global_limit_edit_enabled && (intval($config['forum_limit_edit_time_interval']) < ((time() - $post_info['post_time']) / 60))) || ($is_spam_limit_edit_enabled && (intval($config['spam_post_edit_interval']) < ((time() - $post_info['post_time']) / 60))))
  433. {
  434. $message = sprintf($lang['LIMIT_EDIT_TIME_WARN'], intval($config['forum_limit_edit_time_interval'])) . '<br /><br />' . sprintf($lang['Click_view_message'], '<a href="' . append_sid(CMS_PAGE_VIEWTOPIC . '?' . POST_POST_URL . '=' . $post_id) . '#' . $post_id . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_forum'], '<a href="' . append_sid(CMS_PAGE_VIEWFORUM . '?' . POST_FORUM_URL . '=' . $forum_id) . '">', '</a>');
  435. message_die(GENERAL_MESSAGE, $message);
  436. }
  437. }
  438. // LIMIT POST EDIT TIME - END
  439. if ($mode == 'editpost')
  440. {
  441. if ($is_auth['auth_mod'] || ($user->data['user_level'] == ADMIN))
  442. {
  443. $template->assign_block_vars('switch_lock_post', array());
  444. $template->assign_var('S_POST_LOCKED', $post_info['post_locked'] ? ' checked="checked"' : '');
  445. }
  446. elseif ($post_info['post_locked'])
  447. {
  448. message_die(GENERAL_MESSAGE, 'POST_LOCKED');
  449. }
  450. }
  451. if (($mode == 'editpost') || ($mode == 'delete') || ($mode == 'poll_delete'))
  452. {
  453. $topic_id = $post_info['topic_id'];
  454. $topic_id_append = (!empty($topic_id) ? (POST_TOPIC_URL . '=' . $topic_id) : '');
  455. // MG Cash MOD For IP - BEGIN
  456. if (!empty($config['plugins']['cash']['enabled']))
  457. {
  458. $post_data['post_text'] = (($mode == 'editpost') || ($mode == 'delete')) ? $post_info['post_text'] : '';
  459. }
  460. // MG Cash MOD For IP - END
  461. $post_data['poster_post'] = ($post_info['poster_id'] == $user->data['user_id']) ? true : false;
  462. $post_data['first_post'] = ($post_info['topic_first_post_id'] == $post_id) ? true : false;
  463. $post_data['last_post'] = ($post_info['topic_last_post_id'] == $post_id) ? true : false;
  464. $post_data['last_topic'] = ($post_info['forum_last_post_id'] == $post_id) ? true : false;
  465. $post_data['has_poll'] = (!empty($post_info['poll_start']) ? true : false);
  466. $post_data['poll_start'] = !empty($post_info['poll_start']) ? $post_info['poll_start'] : 0;
  467. // Event Registration - BEGIN
  468. $post_data['has_reg'] = ($post_info['topic_reg']) ? true : false;
  469. // Event Registration - END
  470. $post_data['topic_type'] = $post_info['topic_type'];
  471. $topic_show_portal = ($topic_show_portal || $post_info['topic_show_portal']) ? true : false;
  472. $post_data['topic_show_portal'] = $topic_show_portal;
  473. $post_data['topic_calendar_time'] = $post_info['topic_calendar_time'];
  474. $post_data['topic_calendar_duration'] = $post_info['topic_calendar_duration'];
  475. $post_data['poster_id'] = $post_info['poster_id'];
  476. $post_data['post_images'] = $post_info['post_images'];
  477. /**
  478. * @event posting.post_data.
  479. * @description Sets up the post_data from the post_info.
  480. * @since 3.0
  481. * @var array query The SQL query parts
  482. */
  483. $vars = array(
  484. 'post_data',
  485. 'post_info',
  486. );
  487. extract($class_plugins->trigger('posting.post_data', compact($vars)));
  488. if (($config['allow_mods_edit_admin_posts'] == false) && ($post_info['user_level'] == ADMIN) && ($user->data['user_level'] != ADMIN))
  489. {
  490. message_die(GENERAL_ERROR, $lang['CannotEditAdminsPosts']);
  491. }
  492. if ($post_data['first_post'] && $post_data['has_poll'])
  493. {
  494. $sql = "SELECT *
  495. FROM " . POLL_OPTIONS_TABLE . " o
  496. WHERE o.topic_id = " . $topic_id . "
  497. ORDER BY o.poll_option_id";
  498. $result = $db->sql_query($sql);
  499. $poll_options = array();
  500. $poll_results_sum = 0;
  501. if ($row = $db->sql_fetchrow($result))
  502. {
  503. $poll_title = $post_info['poll_title'];
  504. $poll_start = $post_info['poll_start'];
  505. $poll_length = $post_info['poll_length'] / 86400;
  506. $poll_max_options = $post_info['poll_max_options'];
  507. $poll_change = $post_info['poll_change'];
  508. $poll_data = array(
  509. 'title' => $poll_title,
  510. 'start' => $poll_start,
  511. 'length' => $poll_length,
  512. 'max_options' => $poll_max_options,
  513. 'change' => $poll_change
  514. );
  515. do
  516. {
  517. $poll_options[$row['poll_option_id']] = $row['poll_option_text'];
  518. $poll_results_sum += $row['poll_option_total'];
  519. }
  520. while ($row = $db->sql_fetchrow($result));
  521. }
  522. $db->sql_freeresult($result);
  523. $post_data['edit_poll'] = ((!$poll_results_sum || $is_auth['auth_mod']) && $post_data['first_post']) ? true : 0;
  524. }
  525. else
  526. {
  527. $post_data['edit_poll'] = ($post_data['first_post'] && $is_auth['auth_pollcreate']) ? true : false;
  528. }
  529. // Can this user edit/delete the post/poll?
  530. if (($post_info['poster_id'] != $user->data['user_id']) && !$is_auth['auth_mod'])
  531. {
  532. $message = ($delete || ($mode == 'delete')) ? $lang['Delete_own_posts'] : $lang['Edit_own_posts'];
  533. $message .= '<br /><br />' . sprintf($lang['Click_return_topic'], '<a href="' . append_sid(CMS_PAGE_VIEWTOPIC . '?' . (!empty($forum_id_append) ? ($forum_id_append . '&amp;') : '') . $topic_id_append) . '">', '</a>');
  534. message_die(GENERAL_MESSAGE, $message);
  535. }
  536. elseif (!$post_data['last_post'] && !$is_auth['auth_mod'] && (($mode == 'delete') || $delete))
  537. {
  538. message_die(GENERAL_MESSAGE, $lang['Cannot_delete_replied']);
  539. }
  540. elseif (!$post_data['edit_poll'] && !$is_auth['auth_mod'] && (($mode == 'poll_delete') || $poll_delete))
  541. {
  542. message_die(GENERAL_MESSAGE, $lang['Cannot_delete_poll']);
  543. }
  544. // Event Registration - BEGIN
  545. if ($post_data['first_post'] && $post_data['has_reg'])
  546. {
  547. $sql = "SELECT *
  548. FROM " . REGISTRATION_DESC_TABLE . " rd
  549. WHERE rd.topic_id = $topic_id";
  550. $result = $db->sql_query($sql);
  551. if ($row = $db->sql_fetchrow($result))
  552. {
  553. $reg_active = ($row['reg_active'] == 1) ? 'checked="checked"' : '';
  554. $reg_max_option1 = (!empty($row['reg_max_option1'])) ? $row['reg_max_option1'] : '';
  555. $reg_max_option2 = (!empty($row['reg_max_option2'])) ? $row['reg_max_option2'] : '';
  556. $reg_max_option3 = (!empty($row['reg_max_option3'])) ? $row['reg_max_option3'] : '';
  557. $reg_length = (!empty($row['reg_length'])) ? ($row['reg_length']/86400) : '';
  558. }
  559. $db->sql_freeresult($result);
  560. }
  561. // Event Registration - END
  562. }
  563. else
  564. {
  565. if ($mode == 'quote')
  566. {
  567. $topic_id = $post_info['topic_id'];
  568. $topic_id_append = (!empty($topic_id) ? (POST_TOPIC_URL . '=' . $topic_id) : '');
  569. }
  570. if ($mode == 'newtopic')
  571. {
  572. $post_data['topic_type'] = POST_NORMAL;
  573. }
  574. elseif ($mode == 'reply')
  575. {
  576. $post_data['topic_type'] = $post_info['topic_type'];
  577. }
  578. // MG Cash MOD For IP - BEGIN
  579. if (!empty($config['plugins']['cash']['enabled']))
  580. {
  581. $post_data['topic_poster'] = ($mode == 'reply') ? $post_info['topic_poster'] : 0;
  582. }
  583. // MG Cash MOD For IP - END
  584. $post_data['first_post'] = ($mode == 'newtopic') ? true : 0;
  585. $post_data['last_post'] = false;
  586. $post_data['has_poll'] = false;
  587. $post_data['poll_start'] = 0;
  588. $post_data['edit_poll'] = false;
  589. }
  590. if ($mode == 'poll_delete')
  591. {
  592. $meta = '';
  593. $message = '';
  594. if (!class_exists('class_mcp')) include(IP_ROOT_PATH . 'includes/class_mcp.' . PHP_EXT);
  595. if (empty($class_mcp)) $class_mcp = new class_mcp();
  596. $class_mcp->post_delete($mode, $post_data, $message, $meta, $forum_id, $topic_id, $post_id);
  597. $redirect_url = append_sid(CMS_PAGE_VIEWTOPIC . '?' . POST_TOPIC_URL . '=' . $topic_id);
  598. meta_refresh(3, $redirect_url);
  599. message_die(GENERAL_MESSAGE, $message);
  600. }
  601. // BEGIN cmx_slash_news_mod
  602. // If you want to allow moderators to change news category when editing post you can decomment this...
  603. //if($config['allow_news'] && $post_data['first_post'] && $is_auth['auth_post'] && ($is_auth['auth_news'] || ($is_auth['auth_mod'] && ($mode == 'editpost'))))
  604. if($config['allow_news'] && $post_data['first_post'] && $is_auth['auth_post'] && $is_auth['auth_news'])
  605. {
  606. if($mode == 'editpost')
  607. {
  608. $post_data['news_id'] = $post_info['news_id'];
  609. }
  610. else
  611. {
  612. $post_data['news_id'] = 0;
  613. }
  614. $post_data['disp_news'] = true;
  615. }
  616. else
  617. {
  618. if($config['allow_news'] && $post_data['first_post'] && $is_auth['auth_post'] && !$is_auth['auth_news'] && ($mode == 'editpost'))
  619. {
  620. $post_data['news_id'] = $post_info['news_id'];
  621. }
  622. else
  623. {
  624. $post_data['news_id'] = 0;
  625. }
  626. $post_data['news_id'] = !empty($_POST['news_category']) ? intval($_POST['news_category']) : (!empty($post_data['news_id']) ? intval($post_data['news_id']) : 0);
  627. $hidden_form_fields .= '<input type="hidden" name="news_category" value="' . $post_data['news_id'] . '" />';
  628. $post_data['disp_news'] = false;
  629. }
  630. // END cmx_slash_news_mod
  631. }
  632. else
  633. {
  634. message_die(GENERAL_MESSAGE, $lang['No_such_post']);
  635. }
  636. // The user is not authed, if they're not logged in then redirect them, else show them an error message
  637. if (!$is_auth[$is_auth_type] || (!empty($is_auth_type_cal) && !$is_auth[$is_auth_type_cal]))
  638. {
  639. // Event Registration - BEGIN
  640. $reg_number_clicked = request_var('register', 0);
  641. $reg_user_id = request_var(POST_USERS_URL, 0);
  642. $reg_user_id = ($reg_user_id < 2) ? ANONYMOUS : $reg_user_id;
  643. // Event Registration - END
  644. if ($user->data['session_logged_in'])
  645. {
  646. if (!empty($is_auth_type_cal) && !$is_auth[$is_auth_type_cal])
  647. {
  648. message_die(GENERAL_MESSAGE, sprintf($lang['Sorry_' . $is_auth_type_cal], $is_auth[$is_auth_type_cal . '_type']));
  649. }
  650. message_die(GENERAL_MESSAGE, sprintf($lang['Sorry_' . $is_auth_type], $is_auth[$is_auth_type . '_type']));
  651. }
  652. switch($mode)
  653. {
  654. case 'newtopic':
  655. $redirect = 'mode=newtopic&' . $forum_id_append;
  656. break;
  657. case 'reply':
  658. case 'topicreview':
  659. $redirect = 'mode=reply&' . (!empty($forum_id_append) ? ($forum_id_append . '&') : '') . $topic_id_append;
  660. break;
  661. case 'quote':
  662. case 'editpost':
  663. $redirect = 'mode=quote&' . (!empty($forum_id_append) ? ($forum_id_append . '&') : '') . (!empty($topic_id_append) ? ($topic_id_append . '&') : '') . $post_id_append;
  664. break;
  665. // Event Registration - BEGIN
  666. case 'register':
  667. $redirect = 'mode=register&register=' . $reg_number_clicked . '&' . POST_USERS_URL . '=' . $reg_user_id . '&' . (!empty($forum_id_append) ? ($forum_id_append . '&') : '') . $topic_id_append;
  668. break;
  669. // Event Registration - END
  670. }
  671. $redirect .= ($post_reportid) ? '&post_reportid=' . $post_reportid : '';
  672. redirect(append_sid(CMS_PAGE_LOGIN . '?redirect=posting.' . PHP_EXT . '?' . $redirect, true));
  673. }
  674. // Self AUTH - BEGIN
  675. elseif (intval($is_auth[$is_auth_type]) == AUTH_SELF)
  676. {
  677. //self auth mod
  678. switch($mode)
  679. {
  680. case 'quote':
  681. case 'reply':
  682. $sql = "SELECT t.topic_id
  683. FROM " . TOPICS_TABLE . " t, " . USERS_TABLE. " u
  684. WHERE t.topic_id = " . $topic_id . "
  685. AND t.topic_poster = u.user_id
  686. AND u.user_id = " . $user->data['user_id'];
  687. break;
  688. }
  689. $result = $db->sql_query($sql);
  690. $self_auth = $db->sql_fetchrow($result);
  691. if (empty($self_auth))
  692. {
  693. message_die(GENERAL_MESSAGE, sprintf($lang['Sorry_' . $is_auth_type], $is_auth[$is_auth_type . '_type']));
  694. }
  695. }
  696. // Self AUTH - END
  697. // Set toggles for various options
  698. if (!$config['allow_html'])
  699. {
  700. $html_on = 0;
  701. }
  702. else
  703. {
  704. $html_on = ($submit || $refresh) ? ((!empty($_POST['disable_html'])) ? 0 : 1) : (($user->data['user_id'] == ANONYMOUS) ? $config['allow_html'] : $user->data['user_allowhtml']);
  705. }
  706. $html_on = (!empty($_POST['disable_html']) ? 0 : ((($user->data['user_level'] == ADMIN) && $config['allow_html_only_for_admins']) ? 1 : $html_on));
  707. $acro_auto_on = ($submit || $refresh) ? ((!empty($_POST['disable_acro_auto'])) ? 0 : 1) : 1;
  708. if (!$config['allow_bbcode'])
  709. {
  710. $bbcode_on = 0;
  711. }
  712. else
  713. {
  714. $bbcode_on = ($submit || $refresh) ? ((!empty($_POST['disable_bbcode'])) ? 0 : 1) : (($user->data['user_id'] == ANONYMOUS) ? $config['allow_bbcode'] : $user->data['user_allowbbcode']);
  715. }
  716. if (!$config['allow_smilies'])
  717. {
  718. $smilies_on = 0;
  719. }
  720. else
  721. {
  722. $smilies_on = ($submit || $refresh) ? ((!empty($_POST['disable_smilies'])) ? 0 : 1) : (($user->data['user_id'] == ANONYMOUS) ? $config['allow_smilies'] : $user->data['user_allowsmile']);
  723. }
  724. if($is_auth['auth_news'])
  725. {
  726. $topic_show_portal = ($submit || $refresh) ? (!empty($_POST['topic_show_portal']) ? 1 : 0) : 0;
  727. }
  728. else
  729. {
  730. $topic_show_portal = ($submit || $refresh || ($mode == 'editpost')) ? (!empty($post_data['topic_show_portal']) ? 1 : 0) : 0;
  731. }
  732. if (($submit || $refresh) && $is_auth['auth_read'])
  733. {
  734. $notify_user = (!empty($_POST['notify'])) ? 1 : 0;
  735. }
  736. else
  737. {
  738. if (($mode != 'newtopic') && $user->data['session_logged_in'] && $is_auth['auth_read'])
  739. {
  740. $sql = "SELECT topic_id
  741. FROM " . TOPICS_WATCH_TABLE . "
  742. WHERE topic_id = " . $topic_id . "
  743. AND user_id = " . $user->data['user_id'];
  744. $result = $db->sql_query($sql);
  745. $notify_user = ($db->sql_fetchrow($result)) ? true : $user->data['user_notify'];
  746. $db->sql_freeresult($result);
  747. }
  748. else
  749. {
  750. $notify_user = ($user->data['session_logged_in'] && $is_auth['auth_read']) ? $user->data['user_notify'] : 0;
  751. }
  752. }
  753. $attach_sig = ($submit || $refresh) ? ((!empty($_POST['attach_sig'])) ? 1 : 0) : (($user->data['user_id'] == ANONYMOUS) ? 0 : $user->data['user_attachsig']);
  754. $setbm = ($submit || $refresh) ? ((!empty($_POST['setbm'])) ? 1 : 0) : (($user->data['user_id'] == ANONYMOUS) ? 0 : $user->data['user_setbm']);
  755. execute_posting_attachment_handling();
  756. // What shall we do?
  757. // BEGIN cmx_slash_news_mod
  758. // Get News Categories.
  759. if($user->data['session_logged_in'] && $post_data['disp_news'])
  760. {
  761. if (($mode == 'editpost') && empty($post_id))
  762. {
  763. message_die(GENERAL_MESSAGE, $lang['No_post_id']);
  764. }
  765. $sql = 'SELECT * FROM ' . NEWS_TABLE . ' ORDER BY news_category';
  766. $result = $db->sql_query($sql, 0, 'news_cats_');
  767. $news_sel = array();
  768. $news_cat = array();
  769. while ($row = $db->sql_fetchrow($result))
  770. {
  771. if((($news_category > 0) && ($news_category == $row['news_id'])) || (($post_data['news_id'] > 0) && ($post_data['news_id'] == $row['news_id'])))
  772. {
  773. $news_sel = $row;
  774. }
  775. if($post_data['news_id'] != 0 && $post_data['news_id'] == $row['news_id'])
  776. {
  777. $news_sel = $row;
  778. }
  779. $news_cat[] = $row;
  780. }
  781. if(($post_data['news_id'] == 0) && ($news_category == 0))
  782. {
  783. $boxstring = '<option value="0">' . $lang['Regular_Post'] . '</option>';
  784. }
  785. else
  786. {
  787. $boxstring = '<option value="' . $news_sel['news_id'] . '">' . $news_sel['news_category'] . ' (' . $lang['Current_Selection'] . ')</option>';
  788. $boxstring .= '<option value="0">' . $lang['Regular_Post'] . '</option>';
  789. }
  790. if(sizeof($news_cat) > 0)
  791. {
  792. for($i = 0; $i < sizeof($news_cat); $i++)
  793. {
  794. if($news_cat[$i]['news_id'] != $post_data['news_id'])
  795. {
  796. $boxstring .= '<option value="' . $news_cat[$i]['news_id'] . '">' . $news_cat[$i]['news_category'] . '</option>';
  797. }
  798. }
  799. $template->assign_block_vars('switch_news_cat', array(
  800. 'L_NEWS_CATEGORY' => $lang['Select_News_Category'],
  801. 'S_NAME' => 'news_category',
  802. 'S_CATEGORY_BOX' => $boxstring
  803. )
  804. );
  805. }
  806. }
  807. // END cmx_slash_news_mod
  808. if (($delete || $poll_delete || ($mode == 'delete')) && !$confirm)
  809. {
  810. // Confirm deletion
  811. $s_hidden_fields .= '<input type="hidden" name="' . POST_POST_URL . '" value="' . $post_id . '" />';
  812. $s_hidden_fields .= ($delete || $mode == 'delete') ? '<input type="hidden" name="mode" value="delete" />' : '<input type="hidden" name="mode" value="poll_delete" />';
  813. $s_hidden_fields .= '<input type="hidden" name="sid" value="' . $user->data['session_id'] . '" />';
  814. $l_confirm = ($delete || ($mode == 'delete')) ? $lang['Confirm_delete'] : $lang['Confirm_delete_poll'];
  815. $template->assign_vars(array(
  816. 'MESSAGE_TITLE' => $lang['Information'],
  817. 'MESSAGE_TEXT' => $l_confirm,
  818. 'L_YES' => $lang['Yes'],
  819. 'L_NO' => $lang['No'],
  820. 'S_CONFIRM_ACTION' => append_sid('posting.' . PHP_EXT),
  821. 'S_HIDDEN_FIELDS' => $s_hidden_fields
  822. )
  823. );
  824. full_page_generation('confirm_body.tpl', $lang['Confirm'], '', '');
  825. }
  826. elseif ($mode == 'vote')
  827. {
  828. // Vote in a poll
  829. $voted_id = request_var('vote_id', array('' => 0));
  830. $voted_id = (sizeof($voted_id) > 1) ? array_unique($voted_id) : $voted_id;
  831. // Does this topic contain a poll?
  832. if (!empty($post_info['poll_start']))
  833. {
  834. $sql = "SELECT o.*
  835. FROM " . POLL_OPTIONS_TABLE . " o
  836. WHERE o.topic_id = " . $topic_id . "
  837. ORDER BY o.poll_option_id";
  838. $result = $db->sql_query($sql);
  839. $poll_info = array();
  840. while ($row = $db->sql_fetchrow($result))
  841. {
  842. $poll_info[] = $row;
  843. }
  844. $db->sql_freeresult($result);
  845. $cur_voted_id = array();
  846. if ($user->data['session_logged_in'] && ($user->data['bot_id'] === false))
  847. {
  848. $sql = "SELECT poll_option_id
  849. FROM " . POLL_VOTES_TABLE . "
  850. WHERE topic_id = " . $topic_id . "
  851. AND vote_user_id = " . $user->data['user_id'];
  852. $result = $db->sql_query($sql);
  853. while ($row = $db->sql_fetchrow($result))
  854. {
  855. $cur_voted_id[] = $row['poll_option_id'];
  856. }
  857. $db->sql_freeresult($result);
  858. }
  859. else
  860. {
  861. // Currently disable guests posting...
  862. $message = $lang['POLL_NO_GUESTS'] . '<br /><br />' . sprintf($lang['Click_return_topic'], '<a href="' . $redirect_url . '">', '</a>');
  863. message_die(GENERAL_MESSAGE, $message);
  864. // Cookie based guest tracking... I don't like this but hum ho... it's oft requested. This relies on "nice" users who don't feel the need to delete cookies to mess with results.
  865. if (isset($_COOKIE[$config['cookie_name'] . '_poll_' . $topic_id]))
  866. {
  867. $cur_voted_id = explode(',', $_COOKIE[$config['cookie_name'] . '_poll_' . $topic_id]);
  868. $cur_voted_id = array_map('intval', $cur_voted_id);
  869. }
  870. }
  871. if (!sizeof($voted_id) || (sizeof($voted_id) > $post_info['poll_max_options']) || in_array(VOTE_CONVERTED, $cur_voted_id))
  872. {
  873. if (!sizeof($voted_id))
  874. {
  875. $message = $lang['NO_VOTE_OPTION'];
  876. }
  877. elseif (sizeof($voted_id) > $post_info['poll_max_options'])
  878. {
  879. $message = $lang['TOO_MANY_VOTE_OPTIONS'];
  880. }
  881. elseif (in_array(VOTE_CONVERTED, $cur_voted_id))
  882. {
  883. $message = $lang['VOTE_CONVERTED'];
  884. }
  885. else
  886. {
  887. $message = $lang['FORM_INVALID'];
  888. }
  889. $redirect_url = append_sid(CMS_PAGE_VIEWTOPIC . '?' . (!empty($forum_id_append) ? ($forum_id_append . '&amp;') : '') . $topic_id_append . '&amp;start=' . $start);
  890. meta_refresh(3, $redirect_url);
  891. $message .= '<br /><br />' . sprintf($lang['Click_return_topic'], '<a href="' . $redirect_url . '">', '</a>');
  892. message_die(GENERAL_MESSAGE, $message);
  893. }
  894. foreach ($voted_id as $option)
  895. {
  896. if (in_array($option, $cur_voted_id))
  897. {
  898. continue;
  899. }
  900. $sql = "UPDATE " . POLL_OPTIONS_TABLE . "
  901. SET poll_option_total = poll_option_total + 1
  902. WHERE poll_option_id = " . (int) $option . "
  903. AND topic_id = " . (int) $topic_id;
  904. $db->sql_query($sql);
  905. if ($user->data['session_logged_in'] && ($user->data['bot_id'] === false))
  906. {
  907. $sql_ary = array(
  908. 'topic_id' => (int) $topic_id,
  909. 'poll_option_id' => (int) $option,
  910. 'vote_user_id' => (int) $user->data['user_id'],
  911. 'vote_user_ip' => (string) $user->data['session_ip'],
  912. );
  913. $sql = "INSERT INTO " . POLL_VOTES_TABLE . " " . $db->sql_build_array('INSERT', $sql_ary);
  914. $db->sql_query($sql);
  915. }
  916. }
  917. foreach ($cur_voted_id as $option)
  918. {
  919. if (!in_array($option, $voted_id))
  920. {
  921. $sql = "UPDATE " . POLL_OPTIONS_TABLE . "
  922. SET poll_option_total = poll_option_total - 1
  923. WHERE poll_option_id = " . (int) $option . "
  924. AND topic_id = " . (int) $topic_id;
  925. $db->sql_query($sql);
  926. if ($user->data['session_logged_in'] && ($user->data['bot_id'] === false))
  927. {
  928. $sql = "DELETE FROM " . POLL_VOTES_TABLE . "
  929. WHERE topic_id = " . (int) $topic_id . "
  930. AND poll_option_id = " . (int) $option . "
  931. AND vote_user_id = " . (int) $user->data['user_id'];
  932. $db->sql_query($sql);
  933. }
  934. }
  935. }
  936. if ($user->data['session_logged_in'] && ($user->data['bot_id'] === false))
  937. {
  938. if (function_exists('set_cookie'))
  939. {
  940. set_cookie('poll_' . $topic_id, implode(',', $voted_id), time() + 31536000);
  941. }
  942. }
  943. $sql = "UPDATE " . TOPICS_TABLE . "
  944. SET poll_last_vote = " . time() . "
  945. WHERE topic_id = " . $topic_id;
  946. $db->sql_query($sql);
  947. $redirect_url = append_sid(CMS_PAGE_VIEWTOPIC . '?' . (!empty($forum_id_append) ? ($forum_id_append . '&amp;') : '') . $topic_id_append . '&amp;start=' . $start);
  948. meta_refresh(3, $redirect_url);
  949. $message = $lang['VOTE_SUBMITTED'] . '<br /><br />' . sprintf($lang['Click_return_topic'], '<a href="' . $redirect_url . '">', '</a>');
  950. message_die(GENERAL_MESSAGE, $message);
  951. }
  952. else
  953. {
  954. redirect(append_sid(CMS_PAGE_VIEWTOPIC . '?' . (!empty($forum_id_append) ? ($forum_id_append . '&') : '') . $topic_id_append, true));
  955. }
  956. }
  957. // Event Registration - BEGIN
  958. elseif ($mode == 'register')
  959. {
  960. // Register for an event
  961. $register_value = request_var('register', 0);
  962. $register_value = in_array($register_value, array(REG_OPTION1, REG_OPTION2, REG_OPTION3, REG_UNREGISTER)) ? $register_value : 0;
  963. if (!empty($register_value))
  964. {
  965. $user_id = $user->data['user_id'];
  966. if ($user->data['user_level'] == ADMIN)
  967. {
  968. $target_user_id = request_var(POST_USERS_URL, 0);
  969. $target_user_id = ($target_user_id < 2) ? ANONYMOUS : $target_user_id;
  970. $target_username = request_var('username', '', true);
  971. if (!empty($target_user_id) && ($target_user_id != ANONYMOUS))
  972. {
  973. $target_userdata = get_userdata($target_user_id);
  974. }
  975. else
  976. {
  977. $target_userdata = get_userdata($target_username, true);
  978. }
  979. if (!empty($target_userdata))
  980. {
  981. $user_id = $target_userdata['user_id'];
  982. }
  983. }
  984. $zeit = time();
  985. $sql = "SELECT registration_status FROM " . REGISTRATION_TABLE . "
  986. WHERE topic_id = $topic_id AND registration_user_id = $user_id";
  987. $result = $db->sql_query($sql);
  988. if ($reg_info = $db->sql_fetchrow($result))
  989. {
  990. if ($register_value == REG_UNREGISTER) // cancel registration
  991. {
  992. $sql = "DELETE FROM " . REGISTRATION_TABLE . "
  993. WHERE topic_id = $topic_id
  994. AND registration_user_id = $user_id";
  995. $db->sql_query($sql);
  996. $message = $lang['Reg_Unregister'];
  997. }
  998. else
  999. {
  1000. $old_regstate = $reg_info['registration_status'];
  1001. if (($user->data['user_level'] != ADMIN) && (check_max_registration($topic_id, $register_value) === false))
  1002. {
  1003. $message = $lang['Reg_Max_Registrations'];
  1004. }
  1005. else
  1006. {
  1007. $sql = "UPDATE " . REGISTRATION_TABLE . "
  1008. SET registration_user_ip = '$user_ip', registration_time = $zeit, registration_status = $register_value
  1009. WHERE topic_id = $topic_id
  1010. AND registration_user_id = $user_id";
  1011. $db->sql_query($sql);
  1012. $message = $lang['Reg_Change'];
  1013. }
  1014. }
  1015. }
  1016. else
  1017. {
  1018. if (($user->data['user_level'] != ADMIN) && (check_max_registration($topic_id, $register_value) === false))
  1019. {
  1020. $message = sprintf($lang['Reg_Max_Registrations'], $num_max_reg);
  1021. }
  1022. else
  1023. {
  1024. $sql = "INSERT INTO " . REGISTRATION_TABLE . " (topic_id, registration_user_id, registration_user_ip, registration_time, registration_status)
  1025. VALUES ($topic_id, $user_id, '$user_ip', $zeit, $register_value)";
  1026. $db->sql_query($sql);
  1027. $message = $lang['Reg_Insert'];
  1028. }
  1029. }
  1030. $redirect_url = append_sid(CMS_PAGE_VIEWTOPIC . '?' . (!empty($forum_id_append) ? ($forum_id_append . '&amp;') : '') . $topic_id_append);
  1031. meta_refresh(3, $redirect_url);
  1032. $message .= '<br /><br />' . sprintf($lang['Click_return_topic'], '<a href="' . $redirect_url . '">', '</a>');
  1033. message_die(GENERAL_MESSAGE, $message);
  1034. }
  1035. else
  1036. {
  1037. message_die(GENERAL_ERROR, 'Missing information for registration', '', __LINE__, __FILE__);
  1038. }
  1039. }
  1040. // Event Registration - END
  1041. elseif ($submit || $confirm || ($draft && $draft_confirm))
  1042. {
  1043. // Submit post/vote (newtopic, edit, reply, etc.)
  1044. $return_message = '';
  1045. $return_meta = '';
  1046. // session id check
  1047. if (($sid == '') || ($sid != $user->data['session_id']))
  1048. {
  1049. $error_msg .= (!empty($error_msg)) ? '<br />' . $lang['Session_invalid'] : $lang['Session_invalid'];
  1050. }
  1051. switch ($mode)
  1052. {
  1053. case 'editpost':
  1054. case 'newtopic':
  1055. case 'reply':
  1056. // CrackerTracker v5.x
  1057. if (($config['ctracker_vconfirm_guest'] == 1) && !$user->data['session_logged_in'])
  1058. {
  1059. define('CRACKER_TRACKER_VCONFIRM', true);
  1060. define('POST_CONFIRM_CHECK', true);
  1061. include_once(IP_ROOT_PATH . 'includes/ctracker/engines/ct_visual_confirm.' . PHP_EXT);
  1062. }
  1063. // CrackerTracker v5.x
  1064. $username = htmlspecialchars_decode(request_post_var('username', '', true), ENT_COMPAT);
  1065. $subject = !empty($draft_subject) ? $draft_subject : request_post_var('subject', '', true);
  1066. $topic_desc = request_post_var('topic_desc', '', true);
  1067. $message = !empty($draft_message) ? $draft_message : htmlspecialchars_decode(request_post_var('message', '', true), ENT_COMPAT);
  1068. $notes = htmlspecialchars_decode(request_post_var('notes', '', true), ENT_COMPAT);
  1069. $notes_mod = '';
  1070. if (($user->data['user_level'] == ADMIN) || $is_auth['auth_mod'])
  1071. {
  1072. $notes_mod = htmlspecialchars_decode(request_post_var('notes_mod', '', true), ENT_COMPAT);
  1073. }
  1074. $post_images = request_post_var('post_images', '', true);
  1075. if (!empty($post_images) && (substr($post_images, 0, 4) == 'http'))
  1076. {
  1077. if (!function_exists('get_full_image_info'))
  1078. {
  1079. require(IP_ROOT_PATH . 'includes/class_image.' . PHP_EXT);
  1080. }
  1081. $pic_size = get_full_image_info($post_images);
  1082. if(empty($pic_size))
  1083. {
  1084. $post_images = '';
  1085. }
  1086. }
  1087. else
  1088. {
  1089. $post_images = '';
  1090. }
  1091. $post_data['post_images'] = $post_images;
  1092. $poll_title = (isset($_POST['poll_title']) && $is_auth['auth_pollcreate']) ? request_post_var('poll_title', '', true) : '';
  1093. $poll_options = (isset($_POST['poll_option_text']) && $is_auth['auth_pollcreate']) ? request_post_var('poll_option_text', array(0 => ''), true) : array();
  1094. $poll_start = time();
  1095. $poll_length = (isset($_POST['poll_length']) && $is_auth['auth_pollcreate']) ? request_post_var('poll_length', 0) : 0;
  1096. $poll_length = max(0, $poll_length * 86400);
  1097. $poll_max_options = (isset($_POST['poll_max_options']) && $is_auth['auth_pollcreate']) ? request_post_var('poll_max_options', 1) : 1;
  1098. $poll_max_options = max(1, $poll_max_options);
  1099. $poll_change = (isset($_POST['poll_change']) && $is_auth['auth_pollcreate']) ? 1 : 0;
  1100. $poll_data = array(
  1101. 'title' => $poll_title,
  1102. 'start' => $poll_start,
  1103. 'length' => $poll_length,
  1104. 'max_options' => $poll_max_options,
  1105. 'change' => $poll_change
  1106. );
  1107. $topic_calendar_time = ($topic_calendar_time != $post_data['topic_calendar_time'] && !$is_auth['auth_cal']) ? $post_data['topic_calendar_time'] : $topic_calendar_time;
  1108. if (empty($topic_calendar_time)) $topic_calendar_time = 0;
  1109. $topic_calendar_duration = ($topic_calendar_duration != $post_data['topic_calendar_duration'] && !$is_auth['auth_cal']) ? $post_data['topic_calendar_duration'] : $topic_calendar_duration;
  1110. if (!empty($topic_calendar_duration))
  1111. {
  1112. $topic_calendar_duration--;
  1113. }
  1114. if (empty($topic_calendar_time) || empty($topic_calendar_duration))
  1115. {
  1116. $topic_calendar_duration = 0;
  1117. }
  1118. // Event Registration - BEGIN
  1119. $reg_active = (isset($_POST['start_registration']) && $is_auth['auth_vote'] && $user->data['session_logged_in']) ? $_POST['start_registration'] : '';
  1120. $reg_reset = (isset($_POST['reset_registration']) && $is_auth['auth_vote'] && $user->data['session_logged_in']) ? $_POST['reset_registration'] : '';
  1121. $reg_max_option1 = (!empty($_POST['reg_max_option1']) && $is_auth['auth_vote'] && $user->data['session_logged_in']) ? $_POST['reg_max_option1'] : '';
  1122. $reg_max_option2 = (!empty($_POST['reg_max_option2']) && $is_auth['auth_vote'] && $user->data['session_logged_in']) ? $_POST['reg_max_option2'] : '';
  1123. $reg_max_option3 = (!empty($_POST['reg_max_option3']) && $is_auth['auth_vote'] && $user->data['session_logged_in']) ? $_POST['reg_max_option3'] : '';
  1124. $reg_length = (isset($_POST['reg_length']) && $is_auth['auth_vote'] && $user->data['session_logged_in']) ? $_POST['reg_length'] : '';
  1125. // Event Registration - END
  1126. prepare_post($mode, $post_data, $bbcode_on, $html_on, $smilies_on, $error_msg, $username, $subject, $message, $poll_title, $poll_options, $poll_data, $reg_active, $reg_reset, $reg_max_option1, $reg_max_option2, $reg_max_option3, $reg_length, $topic_desc, $topic_calendar_time, $topic_calendar_duration);
  1127. // MG Drafts - BEGIN
  1128. if (($config['allow_drafts'] == true) && $draft && $draft_confirm && $user->data['session_logged_in'] && (($mode == 'reply') || ($mode == 'newtopic')))
  1129. {
  1130. save_draft($draft_id, $user->data['user_id'], $forum_id, $topic_id, strip_tags($subject), $message);
  1131. //save_draft($draft_id, $user->data['user_id'], $forum_id, $topic_id, $db->sql_escape(strip_tags($subject)), $db->sql_escape($message));
  1132. $output_message = $lang['Drafts_Saved'];
  1133. $output_message .= '<br /><br />' . sprintf($lang['Click_return_drafts'], '<a href="' . append_sid(CMS_PAGE_DRAFTS) . '">', '</a>');
  1134. $output_message .= '<br /><br />' . sprintf($lang['Click_return_forum'], '<a href="' . append_sid(CMS_PAGE_VIEWFORUM . '?' . POST_FORUM_URL . '=' . $forum_id) . '">', '</a>');
  1135. $redirect_url = append_sid(CMS_PAGE_VIEWFORUM . '?' . POST_FORUM_URL . '=' . $forum_id);
  1136. meta_refresh(3, $redirect_url);
  1137. message_die(GENERAL_MESSAGE, $output_message);
  1138. }
  1139. // MG Drafts - END
  1140. if ($error_msg == '')
  1141. {
  1142. if ($mode == 'reply')
  1143. {
  1144. $topic_type = $post_data['topic_type'];
  1145. }
  1146. else
  1147. {
  1148. $topic_type = (($topic_type != $post_data['topic_type']) && !$is_auth['auth_sticky'] && !$is_auth['auth_announce'] && !$is_auth['auth_globalannounce']) ? $post_data['topic_type'] : $topic_type;
  1149. }
  1150. if(($mode == 'editpost') && $config['edit_notes'] && ((strlen($notes) > 2) || (strlen($notes_mod) > 2)))
  1151. {
  1152. $sql = "SELECT edit_notes FROM " . POSTS_TABLE . " WHERE post_id='" . $post_id . "'";
  1153. $result = $db->sql_query($sql);
  1154. $row = $db->sql_fetchrow($result);
  1155. $db->sql_freeresult($result);
  1156. $notes_list = strlen($row['edit_notes']) ? unserialize($row['edit_notes']) : array();
  1157. // Check limit and eventually delete notes
  1158. if(!empty($notes) && (sizeof($notes_list) >= intval($config['edit_notes_n'])))
  1159. {
  1160. $first_edit_note = 0;
  1161. $edit_notes_counter = 0;
  1162. for($i = 0; $i < sizeof($notes_list); $i++)
  1163. {
  1164. if (empty($notes_list[$i]['reserved']))
  1165. {
  1166. $edit_notes_counter++;
  1167. if (empty($first_edit_note))
  1168. {
  1169. $first_edit_note = $i;
  1170. }
  1171. }
  1172. }
  1173. if ($edit_notes_counter > intval($config['edit_notes_n']))
  1174. {
  1175. unset($notes_list[$first_edit_note]);
  1176. }
  1177. }
  1178. if (!empty($notes))
  1179. {
  1180. $notes_list[] = array(
  1181. 'poster' => $user->data['user_id'],
  1182. 'time' => time(),
  1183. //'text' => htmlspecialchars($notes)
  1184. 'text' => $notes,
  1185. 'reserved' => false
  1186. );
  1187. }
  1188. if (!empty($notes_mod))
  1189. {
  1190. $notes_list[] = array(
  1191. 'poster' => $user->data['user_id'],
  1192. 'time' => time(),
  1193. //'text' => htmlspecialchars($notes_mod)
  1194. 'text' => $notes_mod,
  1195. 'reserved' => true
  1196. );
  1197. }
  1198. empty_cache_folders(POSTS_CACHE_FOLDER);
  1199. $sql = "UPDATE " . POSTS_TABLE . " SET edit_notes = '" . $db->sql_escape(serialize($notes_list)) . "' WHERE post_id = '" . $post_id . "'";
  1200. $db->sql_query($sql);
  1201. if (!empty($notes))
  1202. {
  1203. $edit_count_sql = '';
  1204. // We need this, otherwise editing for normal users will be accounted twice... because the same edit will be updated in functions_post.php
  1205. if($user->data['user_level'] == ADMIN)
  1206. {
  1207. $edit_count_sql = ", post_edit_count = (post_edit_count + 1)";
  1208. }
  1209. $edited_sql = "post_edit_time = '" . time() . "'" . $edit_count_sql . ", post_edit_id = '" . $user->data['user_id'] . "'";
  1210. $sql = "UPDATE " . POSTS_TABLE . " SET " . $edited_sql . " WHERE post_id='" . $post_id . "'";
  1211. $db->sql_query($sql);
  1212. }
  1213. }
  1214. if ($lock_subject)
  1215. {
  1216. $url = '[url="' . CMS_PAGE_VIEWTOPIC . '?' . (!empty($forum_id_append) ? ($forum_id_append . '&amp;') : '') . (!empty($topic_id_append) ? ($topic_id_append . '&amp;') : '') . POST_POST_URL . '=' . $lock_subject . '#p' . $lock_subject . '"]';
  1217. $message = sprintf($lang['Link_to_post'], $url, '[/url]') . $message;
  1218. }
  1219. $topic_title_clean = '';
  1220. $topic_tags = '';
  1221. if ($post_data['first_post'])
  1222. {
  1223. $topic_title_clean = request_var('topic_title_clean', $subject, true);
  1224. $topic_title_clean = substr(ip_clean_string($topic_title_clean, $lang['ENCODING']), 0, 254);
  1225. @include_once(IP_ROOT_PATH . 'includes/class_topics_tags.' . PHP_EXT);
  1226. $class_topics_tags = new class_topics_tags();
  1227. if (!empty($use_jquery_tags))
  1228. {
  1229. if(array_key_exists('ttag', $_POST))
  1230. {
  1231. $all_topic_tags = request_var('ttag', array(0 => ''), true);
  1232. $topic_tags = implode(', ', array_filter(array_unique($all_topic_tags)));
  1233. }
  1234. }
  1235. else
  1236. {
  1237. $topic_tags = request_var('topic_tags', '', true);
  1238. }
  1239. if (!empty($topic_tags))
  1240. {
  1241. $topic_tags = trim($topic_tags);
  1242. while(substr($topic_tags, -1) == ',')
  1243. {
  1244. $topic_tags = trim(substr($topic_tags, 0, -1));
  1245. }
  1246. $topic_tags_array = $class_topics_tags->create_tags_array($topic_tags);
  1247. $topic_tags = implode(', ', array_filter(array_unique($topic_tags_array)));
  1248. $topic_tags = substr($topic_tags, 0, 254);
  1249. //die($topic_tags);
  1250. }
  1251. unset($class_topics_tags);
  1252. }
  1253. submit_post($mode, $post_data, $return_message, $return_meta, $forum_id, $topic_id, $post_id, $topic_type, $bbcode_on, $html_on, $acro_auto_on, $smilies_on, $attach_sig, $username, $subject, $topic_title_clean, $topic_tags, $message, $poll_title, $poll_options, $poll_data, $reg_active, $reg_reset, $reg_max_option1, $reg_max_option2, $reg_max_option3, $reg_length, $news_category, $topic_show_portal, $mark_edit, $topic_desc, $topic_calendar_time, $topic_calendar_duration, $extra_vars);
  1254. }
  1255. break;
  1256. case 'delete':
  1257. case 'poll_delete':
  1258. if ($error_msg != '')
  1259. {
  1260. message_die(GENERAL_MESSAGE, $error_msg);
  1261. }
  1262. if (!class_exists('class_mcp')) include(IP_ROOT_PATH . 'includes/class_mcp.' . PHP_EXT);
  1263. if (empty($class_mcp)) $class_mcp = new class_mcp();
  1264. $class_mcp->post_delete($mode, $post_data, $return_message, $return_meta, $forum_id, $topic_id, $post_id);
  1265. break;
  1266. }
  1267. if ($error_msg == '')
  1268. {
  1269. if ($mode != 'editpost')
  1270. {
  1271. $user_id = (($mode == 'reply') || ($mode == 'newtopic')) ? $user->data['user_id'] : $post_data['poster_id'];
  1272. if (!class_exists('class_mcp')) include(IP_ROOT_PATH . 'includes/class_mcp.' . PHP_EXT);
  1273. if (empty($class_mcp)) $class_mcp = new class_mcp();
  1274. $class_mcp->sync_post_stats($mode, $post_data, $forum_id, $topic_id, $post_id, $user_id);
  1275. }
  1276. $attachment_mod['posting']->insert_attachment($post_id);
  1277. if (($error_msg == '') && ($mode != 'poll_delete'))
  1278. {
  1279. // Forum Notification - BEGIN
  1280. if (!class_exists('class_notifications'))
  1281. {
  1282. include(IP_ROOT_PATH . 'includes/class_notifications.' . PHP_EXT);
  1283. $class_notifications = new class_notifications();
  1284. }
  1285. $post_data['subject'] = $subject;
  1286. $post_data['username'] = ($user->data['user_id'] == ANONYMOUS) ? $username : $user->data['username'];
  1287. $post_data['message'] = $message;
  1288. if ($post_data['first_post'])
  1289. {
  1290. // fetch topic title
  1291. $sql = "SELECT topic_title, topic_id
  1292. FROM " . TOPICS_TABLE . "
  1293. WHERE topic_id = " . $topic_id;
  1294. $result = $db->sql_query($sql);
  1295. if ($topic_info = $db->sql_fetchrow($result))
  1296. {
  1297. $class_notifications->send_notifications('newtopic', $post_data, $topic_info['topic_title'], $forum_id, $topic_id, $post_id, $notify_user);
  1298. }
  1299. }
  1300. else
  1301. {
  1302. if ($setbm)
  1303. {
  1304. set_bookmark($topic_id);
  1305. }
  1306. $class_notifications->send_notifications($mode, $post_data, $post_info['topic_title'], $forum_id, $topic_id, $post_id, $notify_user);
  1307. }
  1308. // Forum Notification - END
  1309. }
  1310. if ($lock_subject)
  1311. {
  1312. $url = '<a href="' . append_sid(CMS_PAGE_VIEWTOPIC . '?' . (!empty($forum_id_append) ? ($forum_id_append . '&amp;') : '') . (!empty($topic_id_append) ? ($topic_id_append . '&amp;') : '') . POST_POST_URL . '=' . $lock_subject . '#p' . $lock_subject) . '">';
  1313. $return_message = $lang['Report_stored'] . '<br /><br />' . sprintf($lang['Send_report'], $url, '</a>');
  1314. $return_meta = str_replace($post_id, $lock_subject, $return_meta);
  1315. }
  1316. if (($error_msg == '') && ($lock) && ($mode == 'newtopic'))
  1317. {
  1318. empty_cache_folders(POSTS_CACHE_FOLDER);
  1319. empty_cache_folders(FORUMS_CACHE_FOLDER);
  1320. $sql = "UPDATE " . TOPICS_TABLE . "
  1321. SET topic_status = " . TOPIC_LOCKED . "
  1322. WHERE topic_id = " . $topic_id . "
  1323. AND topic_mo

Large files files are truncated, but you can click here to view the full file