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

/zafenio/includes/acp/acp_forums.php

https://github.com/chrishildebrandt/zafenio
PHP | 1945 lines | 1467 code | 342 blank | 136 comment | 226 complexity | 96f4c1054e8b7aadb37c6a2049de3efc 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 acp
  5. * @version $Id$
  6. * @copyright (c) 2005 phpBB Group
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. * @ignore
  12. */
  13. if (!defined('IN_PHPBB'))
  14. {
  15. exit;
  16. }
  17. /**
  18. * @package acp
  19. */
  20. class acp_forums
  21. {
  22. var $u_action;
  23. var $parent_id = 0;
  24. function main($id, $mode)
  25. {
  26. global $db, $user, $auth, $template, $cache;
  27. global $config, $phpbb_admin_path, $phpbb_root_path, $phpEx;
  28. $user->add_lang('acp/forums');
  29. $this->tpl_name = 'acp_forums';
  30. $this->page_title = 'ACP_MANAGE_FORUMS';
  31. $form_key = 'acp_forums';
  32. add_form_key($form_key);
  33. $action = request_var('action', '');
  34. $update = (isset($_POST['update'])) ? true : false;
  35. $forum_id = request_var('f', 0);
  36. $this->parent_id = request_var('parent_id', 0);
  37. $forum_data = $errors = array();
  38. if ($update && !check_form_key($form_key))
  39. {
  40. $update = false;
  41. $errors[] = $user->lang['FORM_INVALID'];
  42. }
  43. // Check additional permissions
  44. switch ($action)
  45. {
  46. case 'progress_bar':
  47. $start = request_var('start', 0);
  48. $total = request_var('total', 0);
  49. $this->display_progress_bar($start, $total);
  50. exit;
  51. break;
  52. case 'delete':
  53. if (!$auth->acl_get('a_forumdel'))
  54. {
  55. trigger_error($user->lang['NO_PERMISSION_FORUM_DELETE'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
  56. }
  57. break;
  58. case 'add':
  59. if (!$auth->acl_get('a_forumadd'))
  60. {
  61. trigger_error($user->lang['NO_PERMISSION_FORUM_ADD'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
  62. }
  63. break;
  64. }
  65. // Major routines
  66. if ($update)
  67. {
  68. switch ($action)
  69. {
  70. case 'delete':
  71. $action_subforums = request_var('action_subforums', '');
  72. $subforums_to_id = request_var('subforums_to_id', 0);
  73. $action_posts = request_var('action_posts', '');
  74. $posts_to_id = request_var('posts_to_id', 0);
  75. $errors = $this->delete_forum($forum_id, $action_posts, $action_subforums, $posts_to_id, $subforums_to_id);
  76. if (sizeof($errors))
  77. {
  78. break;
  79. }
  80. $auth->acl_clear_prefetch();
  81. $cache->destroy('sql', FORUMS_TABLE);
  82. trigger_error($user->lang['FORUM_DELETED'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id));
  83. break;
  84. case 'edit':
  85. $forum_data = array(
  86. 'forum_id' => $forum_id
  87. );
  88. // No break here
  89. case 'add':
  90. $forum_data += array(
  91. 'parent_id' => request_var('forum_parent_id', $this->parent_id),
  92. 'forum_type' => request_var('forum_type', FORUM_POST),
  93. 'type_action' => request_var('type_action', ''),
  94. 'forum_status' => request_var('forum_status', ITEM_UNLOCKED),
  95. 'forum_parents' => '',
  96. 'forum_name' => utf8_normalize_nfc(request_var('forum_name', '', true)),
  97. 'forum_link' => request_var('forum_link', ''),
  98. 'forum_link_track' => request_var('forum_link_track', false),
  99. 'forum_desc' => utf8_normalize_nfc(request_var('forum_desc', '', true)),
  100. 'forum_desc_uid' => '',
  101. 'forum_desc_options' => 7,
  102. 'forum_desc_bitfield' => '',
  103. 'forum_rules' => utf8_normalize_nfc(request_var('forum_rules', '', true)),
  104. 'forum_rules_uid' => '',
  105. 'forum_rules_options' => 7,
  106. 'forum_rules_bitfield' => '',
  107. 'forum_rules_link' => request_var('forum_rules_link', ''),
  108. 'forum_image' => request_var('forum_image', ''),
  109. 'forum_style' => request_var('forum_style', 0),
  110. 'display_subforum_list' => request_var('display_subforum_list', false),
  111. 'display_on_index' => request_var('display_on_index', false),
  112. 'forum_topics_per_page' => request_var('topics_per_page', 0),
  113. 'enable_indexing' => request_var('enable_indexing', true),
  114. 'enable_icons' => request_var('enable_icons', false),
  115. 'enable_prune' => request_var('enable_prune', false),
  116. 'enable_post_review' => request_var('enable_post_review', true),
  117. 'enable_quick_reply' => request_var('enable_quick_reply', false),
  118. 'prune_days' => request_var('prune_days', 7),
  119. 'prune_viewed' => request_var('prune_viewed', 7),
  120. 'prune_freq' => request_var('prune_freq', 1),
  121. 'prune_old_polls' => request_var('prune_old_polls', false),
  122. 'prune_announce' => request_var('prune_announce', false),
  123. 'prune_sticky' => request_var('prune_sticky', false),
  124. 'forum_password' => request_var('forum_password', '', true),
  125. 'forum_password_confirm'=> request_var('forum_password_confirm', '', true),
  126. 'forum_password_unset' => request_var('forum_password_unset', false),
  127. );
  128. // On add, add empty forum_options... else do not consider it (not updating it)
  129. if ($action == 'add')
  130. {
  131. $forum_data['forum_options'] = 0;
  132. }
  133. // Use link_display_on_index setting if forum type is link
  134. if ($forum_data['forum_type'] == FORUM_LINK)
  135. {
  136. $forum_data['display_on_index'] = request_var('link_display_on_index', false);
  137. }
  138. // Linked forums and categories are not able to be locked...
  139. if ($forum_data['forum_type'] == FORUM_LINK || $forum_data['forum_type'] == FORUM_CAT)
  140. {
  141. $forum_data['forum_status'] = ITEM_UNLOCKED;
  142. }
  143. $forum_data['show_active'] = ($forum_data['forum_type'] == FORUM_POST) ? request_var('display_recent', true) : request_var('display_active', true);
  144. // Get data for forum rules if specified...
  145. if ($forum_data['forum_rules'])
  146. {
  147. generate_text_for_storage($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_bitfield'], $forum_data['forum_rules_options'], request_var('rules_parse_bbcode', false), request_var('rules_parse_urls', false), request_var('rules_parse_smilies', false));
  148. }
  149. // Get data for forum description if specified
  150. if ($forum_data['forum_desc'])
  151. {
  152. generate_text_for_storage($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_bitfield'], $forum_data['forum_desc_options'], request_var('desc_parse_bbcode', false), request_var('desc_parse_urls', false), request_var('desc_parse_smilies', false));
  153. }
  154. $errors = $this->update_forum_data($forum_data);
  155. if (!sizeof($errors))
  156. {
  157. $forum_perm_from = request_var('forum_perm_from', 0);
  158. $cache->destroy('sql', FORUMS_TABLE);
  159. // Copy permissions?
  160. if ($forum_perm_from && $forum_perm_from != $forum_data['forum_id'] &&
  161. ($action != 'edit' || empty($forum_id) || ($auth->acl_get('a_fauth') && $auth->acl_get('a_authusers') && $auth->acl_get('a_authgroups') && $auth->acl_get('a_mauth'))))
  162. {
  163. copy_forum_permissions($forum_perm_from, $forum_data['forum_id'], ($action == 'edit') ? true : false);
  164. cache_moderators();
  165. }
  166. /* Commented out because of questionable UI workflow - re-visit for 3.0.7
  167. else if (!$this->parent_id && $action != 'edit' && $auth->acl_get('a_fauth') && $auth->acl_get('a_authusers') && $auth->acl_get('a_authgroups') && $auth->acl_get('a_mauth'))
  168. {
  169. $this->copy_permission_page($forum_data);
  170. return;
  171. }
  172. */
  173. $auth->acl_clear_prefetch();
  174. $acl_url = '&amp;mode=setting_forum_local&amp;forum_id[]=' . $forum_data['forum_id'];
  175. $message = ($action == 'add') ? $user->lang['FORUM_CREATED'] : $user->lang['FORUM_UPDATED'];
  176. // Redirect to permissions
  177. if ($auth->acl_get('a_fauth'))
  178. {
  179. $message .= '<br /><br />' . sprintf($user->lang['REDIRECT_ACL'], '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url) . '">', '</a>');
  180. }
  181. // redirect directly to permission settings screen if authed
  182. if ($action == 'add' && !$forum_perm_from && $auth->acl_get('a_fauth'))
  183. {
  184. meta_refresh(4, append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url));
  185. }
  186. trigger_error($message . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id));
  187. }
  188. break;
  189. }
  190. }
  191. switch ($action)
  192. {
  193. case 'move_up':
  194. case 'move_down':
  195. if (!$forum_id)
  196. {
  197. trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
  198. }
  199. $sql = 'SELECT *
  200. FROM ' . FORUMS_TABLE . "
  201. WHERE forum_id = $forum_id";
  202. $result = $db->sql_query($sql);
  203. $row = $db->sql_fetchrow($result);
  204. $db->sql_freeresult($result);
  205. if (!$row)
  206. {
  207. trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
  208. }
  209. $move_forum_name = $this->move_forum_by($row, $action, 1);
  210. if ($move_forum_name !== false)
  211. {
  212. add_log('admin', 'LOG_FORUM_' . strtoupper($action), $row['forum_name'], $move_forum_name);
  213. $cache->destroy('sql', FORUMS_TABLE);
  214. }
  215. break;
  216. case 'sync':
  217. if (!$forum_id)
  218. {
  219. trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
  220. }
  221. @set_time_limit(0);
  222. $sql = 'SELECT forum_name, forum_topics_real
  223. FROM ' . FORUMS_TABLE . "
  224. WHERE forum_id = $forum_id";
  225. $result = $db->sql_query($sql);
  226. $row = $db->sql_fetchrow($result);
  227. $db->sql_freeresult($result);
  228. if (!$row)
  229. {
  230. trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
  231. }
  232. if ($row['forum_topics_real'])
  233. {
  234. $sql = 'SELECT MIN(topic_id) as min_topic_id, MAX(topic_id) as max_topic_id
  235. FROM ' . TOPICS_TABLE . '
  236. WHERE forum_id = ' . $forum_id;
  237. $result = $db->sql_query($sql);
  238. $row2 = $db->sql_fetchrow($result);
  239. $db->sql_freeresult($result);
  240. // Typecast to int if there is no data available
  241. $row2['min_topic_id'] = (int) $row2['min_topic_id'];
  242. $row2['max_topic_id'] = (int) $row2['max_topic_id'];
  243. $start = request_var('start', $row2['min_topic_id']);
  244. $batch_size = 2000;
  245. $end = $start + $batch_size;
  246. // Sync all topics in batch mode...
  247. sync('topic_approved', 'range', 'topic_id BETWEEN ' . $start . ' AND ' . $end, true, false);
  248. sync('topic', 'range', 'topic_id BETWEEN ' . $start . ' AND ' . $end, true, true);
  249. if ($end < $row2['max_topic_id'])
  250. {
  251. // We really need to find a way of showing statistics... no progress here
  252. $sql = 'SELECT COUNT(topic_id) as num_topics
  253. FROM ' . TOPICS_TABLE . '
  254. WHERE forum_id = ' . $forum_id . '
  255. AND topic_id BETWEEN ' . $start . ' AND ' . $end;
  256. $result = $db->sql_query($sql);
  257. $topics_done = request_var('topics_done', 0) + (int) $db->sql_fetchfield('num_topics');
  258. $db->sql_freeresult($result);
  259. $start += $batch_size;
  260. $url = $this->u_action . "&amp;parent_id={$this->parent_id}&amp;f=$forum_id&amp;action=sync&amp;start=$start&amp;topics_done=$topics_done&amp;total={$row['forum_topics_real']}";
  261. meta_refresh(0, $url);
  262. $template->assign_vars(array(
  263. 'U_PROGRESS_BAR' => $this->u_action . "&amp;action=progress_bar&amp;start=$topics_done&amp;total={$row['forum_topics_real']}",
  264. 'UA_PROGRESS_BAR' => addslashes($this->u_action . "&amp;action=progress_bar&amp;start=$topics_done&amp;total={$row['forum_topics_real']}"),
  265. 'S_CONTINUE_SYNC' => true,
  266. 'L_PROGRESS_EXPLAIN' => sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], $topics_done, $row['forum_topics_real']))
  267. );
  268. return;
  269. }
  270. }
  271. $url = $this->u_action . "&amp;parent_id={$this->parent_id}&amp;f=$forum_id&amp;action=sync_forum";
  272. meta_refresh(0, $url);
  273. $template->assign_vars(array(
  274. 'U_PROGRESS_BAR' => $this->u_action . '&amp;action=progress_bar',
  275. 'UA_PROGRESS_BAR' => addslashes($this->u_action . '&amp;action=progress_bar'),
  276. 'S_CONTINUE_SYNC' => true,
  277. 'L_PROGRESS_EXPLAIN' => sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], 0, $row['forum_topics_real']))
  278. );
  279. return;
  280. break;
  281. case 'sync_forum':
  282. $sql = 'SELECT forum_name, forum_type
  283. FROM ' . FORUMS_TABLE . "
  284. WHERE forum_id = $forum_id";
  285. $result = $db->sql_query($sql);
  286. $row = $db->sql_fetchrow($result);
  287. $db->sql_freeresult($result);
  288. if (!$row)
  289. {
  290. trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
  291. }
  292. sync('forum', 'forum_id', $forum_id, false, true);
  293. add_log('admin', 'LOG_FORUM_SYNC', $row['forum_name']);
  294. $cache->destroy('sql', FORUMS_TABLE);
  295. $template->assign_var('L_FORUM_RESYNCED', sprintf($user->lang['FORUM_RESYNCED'], $row['forum_name']));
  296. break;
  297. case 'add':
  298. case 'edit':
  299. if ($update)
  300. {
  301. $forum_data['forum_flags'] = 0;
  302. $forum_data['forum_flags'] += (request_var('forum_link_track', false)) ? FORUM_FLAG_LINK_TRACK : 0;
  303. $forum_data['forum_flags'] += (request_var('prune_old_polls', false)) ? FORUM_FLAG_PRUNE_POLL : 0;
  304. $forum_data['forum_flags'] += (request_var('prune_announce', false)) ? FORUM_FLAG_PRUNE_ANNOUNCE : 0;
  305. $forum_data['forum_flags'] += (request_var('prune_sticky', false)) ? FORUM_FLAG_PRUNE_STICKY : 0;
  306. $forum_data['forum_flags'] += ($forum_data['show_active']) ? FORUM_FLAG_ACTIVE_TOPICS : 0;
  307. $forum_data['forum_flags'] += (request_var('enable_post_review', true)) ? FORUM_FLAG_POST_REVIEW : 0;
  308. $forum_data['forum_flags'] += (request_var('enable_quick_reply', false)) ? FORUM_FLAG_QUICK_REPLY : 0;
  309. }
  310. // Show form to create/modify a forum
  311. if ($action == 'edit')
  312. {
  313. $this->page_title = 'EDIT_FORUM';
  314. $row = $this->get_forum_info($forum_id);
  315. $old_forum_type = $row['forum_type'];
  316. if (!$update)
  317. {
  318. $forum_data = $row;
  319. }
  320. else
  321. {
  322. $forum_data['left_id'] = $row['left_id'];
  323. $forum_data['right_id'] = $row['right_id'];
  324. }
  325. // Make sure no direct child forums are able to be selected as parents.
  326. $exclude_forums = array();
  327. foreach (get_forum_branch($forum_id, 'children') as $row)
  328. {
  329. $exclude_forums[] = $row['forum_id'];
  330. }
  331. $parents_list = make_forum_select($forum_data['parent_id'], $exclude_forums, false, false, false);
  332. $forum_data['forum_password_confirm'] = $forum_data['forum_password'];
  333. }
  334. else
  335. {
  336. $this->page_title = 'CREATE_FORUM';
  337. $forum_id = $this->parent_id;
  338. $parents_list = make_forum_select($this->parent_id, false, false, false, false);
  339. // Fill forum data with default values
  340. if (!$update)
  341. {
  342. $forum_data = array(
  343. 'parent_id' => $this->parent_id,
  344. 'forum_type' => FORUM_POST,
  345. 'forum_status' => ITEM_UNLOCKED,
  346. 'forum_name' => utf8_normalize_nfc(request_var('forum_name', '', true)),
  347. 'forum_link' => '',
  348. 'forum_link_track' => false,
  349. 'forum_desc' => '',
  350. 'forum_rules' => '',
  351. 'forum_rules_link' => '',
  352. 'forum_image' => '',
  353. 'forum_style' => 0,
  354. 'display_subforum_list' => true,
  355. 'display_on_index' => false,
  356. 'forum_topics_per_page' => 0,
  357. 'enable_indexing' => true,
  358. 'enable_icons' => false,
  359. 'enable_prune' => false,
  360. 'prune_days' => 7,
  361. 'prune_viewed' => 7,
  362. 'prune_freq' => 1,
  363. 'forum_flags' => FORUM_FLAG_POST_REVIEW + FORUM_FLAG_ACTIVE_TOPICS,
  364. 'forum_options' => 0,
  365. 'forum_password' => '',
  366. 'forum_password_confirm'=> '',
  367. );
  368. }
  369. }
  370. $forum_rules_data = array(
  371. 'text' => $forum_data['forum_rules'],
  372. 'allow_bbcode' => true,
  373. 'allow_smilies' => true,
  374. 'allow_urls' => true
  375. );
  376. $forum_desc_data = array(
  377. 'text' => $forum_data['forum_desc'],
  378. 'allow_bbcode' => true,
  379. 'allow_smilies' => true,
  380. 'allow_urls' => true
  381. );
  382. $forum_rules_preview = '';
  383. // Parse rules if specified
  384. if ($forum_data['forum_rules'])
  385. {
  386. if (!isset($forum_data['forum_rules_uid']))
  387. {
  388. // Before we are able to display the preview and plane text, we need to parse our request_var()'d value...
  389. $forum_data['forum_rules_uid'] = '';
  390. $forum_data['forum_rules_bitfield'] = '';
  391. $forum_data['forum_rules_options'] = 0;
  392. generate_text_for_storage($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_bitfield'], $forum_data['forum_rules_options'], request_var('rules_allow_bbcode', false), request_var('rules_allow_urls', false), request_var('rules_allow_smilies', false));
  393. }
  394. // Generate preview content
  395. $forum_rules_preview = generate_text_for_display($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_bitfield'], $forum_data['forum_rules_options']);
  396. // decode...
  397. $forum_rules_data = generate_text_for_edit($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_options']);
  398. }
  399. // Parse desciption if specified
  400. if ($forum_data['forum_desc'])
  401. {
  402. if (!isset($forum_data['forum_desc_uid']))
  403. {
  404. // Before we are able to display the preview and plane text, we need to parse our request_var()'d value...
  405. $forum_data['forum_desc_uid'] = '';
  406. $forum_data['forum_desc_bitfield'] = '';
  407. $forum_data['forum_desc_options'] = 0;
  408. generate_text_for_storage($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_bitfield'], $forum_data['forum_desc_options'], request_var('desc_allow_bbcode', false), request_var('desc_allow_urls', false), request_var('desc_allow_smilies', false));
  409. }
  410. // decode...
  411. $forum_desc_data = generate_text_for_edit($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_options']);
  412. }
  413. $forum_type_options = '';
  414. $forum_type_ary = array(FORUM_CAT => 'CAT', FORUM_POST => 'FORUM', FORUM_LINK => 'LINK');
  415. foreach ($forum_type_ary as $value => $lang)
  416. {
  417. $forum_type_options .= '<option value="' . $value . '"' . (($value == $forum_data['forum_type']) ? ' selected="selected"' : '') . '>' . $user->lang['TYPE_' . $lang] . '</option>';
  418. }
  419. $styles_list = style_select($forum_data['forum_style'], true);
  420. $statuslist = '<option value="' . ITEM_UNLOCKED . '"' . (($forum_data['forum_status'] == ITEM_UNLOCKED) ? ' selected="selected"' : '') . '>' . $user->lang['UNLOCKED'] . '</option><option value="' . ITEM_LOCKED . '"' . (($forum_data['forum_status'] == ITEM_LOCKED) ? ' selected="selected"' : '') . '>' . $user->lang['LOCKED'] . '</option>';
  421. $sql = 'SELECT forum_id
  422. FROM ' . FORUMS_TABLE . '
  423. WHERE forum_type = ' . FORUM_POST . "
  424. AND forum_id <> $forum_id";
  425. $result = $db->sql_query_limit($sql, 1);
  426. $postable_forum_exists = false;
  427. if ($db->sql_fetchrow($result))
  428. {
  429. $postable_forum_exists = true;
  430. }
  431. $db->sql_freeresult($result);
  432. // Subforum move options
  433. if ($action == 'edit' && $forum_data['forum_type'] == FORUM_CAT)
  434. {
  435. $subforums_id = array();
  436. $subforums = get_forum_branch($forum_id, 'children');
  437. foreach ($subforums as $row)
  438. {
  439. $subforums_id[] = $row['forum_id'];
  440. }
  441. $forums_list = make_forum_select($forum_data['parent_id'], $subforums_id);
  442. if ($postable_forum_exists)
  443. {
  444. $template->assign_vars(array(
  445. 'S_MOVE_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $subforums_id)) // , false, true, false???
  446. );
  447. }
  448. $template->assign_vars(array(
  449. 'S_HAS_SUBFORUMS' => ($forum_data['right_id'] - $forum_data['left_id'] > 1) ? true : false,
  450. 'S_FORUMS_LIST' => $forums_list)
  451. );
  452. }
  453. else if ($postable_forum_exists)
  454. {
  455. $template->assign_vars(array(
  456. 'S_MOVE_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $forum_id, false, true, false))
  457. );
  458. }
  459. $s_show_display_on_index = false;
  460. if ($forum_data['parent_id'] > 0)
  461. {
  462. // if this forum is a subforum put the "display on index" checkbox
  463. if ($parent_info = $this->get_forum_info($forum_data['parent_id']))
  464. {
  465. if ($parent_info['parent_id'] > 0 || $parent_info['forum_type'] == FORUM_CAT)
  466. {
  467. $s_show_display_on_index = true;
  468. }
  469. }
  470. }
  471. if (strlen($forum_data['forum_password']) == 32)
  472. {
  473. $errors[] = $user->lang['FORUM_PASSWORD_OLD'];
  474. }
  475. $template->assign_vars(array(
  476. 'S_EDIT_FORUM' => true,
  477. 'S_ERROR' => (sizeof($errors)) ? true : false,
  478. 'S_PARENT_ID' => $this->parent_id,
  479. 'S_FORUM_PARENT_ID' => $forum_data['parent_id'],
  480. 'S_ADD_ACTION' => ($action == 'add') ? true : false,
  481. 'U_BACK' => $this->u_action . '&amp;parent_id=' . $this->parent_id,
  482. 'U_EDIT_ACTION' => $this->u_action . "&amp;parent_id={$this->parent_id}&amp;action=$action&amp;f=$forum_id",
  483. 'L_COPY_PERMISSIONS_EXPLAIN' => $user->lang['COPY_PERMISSIONS_' . strtoupper($action) . '_EXPLAIN'],
  484. 'L_TITLE' => $user->lang[$this->page_title],
  485. 'ERROR_MSG' => (sizeof($errors)) ? implode('<br />', $errors) : '',
  486. 'FORUM_NAME' => $forum_data['forum_name'],
  487. 'FORUM_DATA_LINK' => $forum_data['forum_link'],
  488. 'FORUM_IMAGE' => $forum_data['forum_image'],
  489. 'FORUM_IMAGE_SRC' => ($forum_data['forum_image']) ? $phpbb_root_path . $forum_data['forum_image'] : '',
  490. 'FORUM_POST' => FORUM_POST,
  491. 'FORUM_LINK' => FORUM_LINK,
  492. 'FORUM_CAT' => FORUM_CAT,
  493. 'PRUNE_FREQ' => $forum_data['prune_freq'],
  494. 'PRUNE_DAYS' => $forum_data['prune_days'],
  495. 'PRUNE_VIEWED' => $forum_data['prune_viewed'],
  496. 'TOPICS_PER_PAGE' => $forum_data['forum_topics_per_page'],
  497. 'FORUM_RULES_LINK' => $forum_data['forum_rules_link'],
  498. 'FORUM_RULES' => $forum_data['forum_rules'],
  499. 'FORUM_RULES_PREVIEW' => $forum_rules_preview,
  500. 'FORUM_RULES_PLAIN' => $forum_rules_data['text'],
  501. 'S_BBCODE_CHECKED' => ($forum_rules_data['allow_bbcode']) ? true : false,
  502. 'S_SMILIES_CHECKED' => ($forum_rules_data['allow_smilies']) ? true : false,
  503. 'S_URLS_CHECKED' => ($forum_rules_data['allow_urls']) ? true : false,
  504. 'S_FORUM_PASSWORD_SET' => (empty($forum_data['forum_password'])) ? false : true,
  505. 'FORUM_DESC' => $forum_desc_data['text'],
  506. 'S_DESC_BBCODE_CHECKED' => ($forum_desc_data['allow_bbcode']) ? true : false,
  507. 'S_DESC_SMILIES_CHECKED' => ($forum_desc_data['allow_smilies']) ? true : false,
  508. 'S_DESC_URLS_CHECKED' => ($forum_desc_data['allow_urls']) ? true : false,
  509. 'S_FORUM_TYPE_OPTIONS' => $forum_type_options,
  510. 'S_STATUS_OPTIONS' => $statuslist,
  511. 'S_PARENT_OPTIONS' => $parents_list,
  512. 'S_STYLES_OPTIONS' => $styles_list,
  513. 'S_FORUM_OPTIONS' => make_forum_select(($action == 'add') ? $forum_data['parent_id'] : false, ($action == 'edit') ? $forum_data['forum_id'] : false, false, false, false),
  514. 'S_SHOW_DISPLAY_ON_INDEX' => $s_show_display_on_index,
  515. 'S_FORUM_POST' => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
  516. 'S_FORUM_ORIG_POST' => (isset($old_forum_type) && $old_forum_type == FORUM_POST) ? true : false,
  517. 'S_FORUM_ORIG_CAT' => (isset($old_forum_type) && $old_forum_type == FORUM_CAT) ? true : false,
  518. 'S_FORUM_ORIG_LINK' => (isset($old_forum_type) && $old_forum_type == FORUM_LINK) ? true : false,
  519. 'S_FORUM_LINK' => ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
  520. 'S_FORUM_CAT' => ($forum_data['forum_type'] == FORUM_CAT) ? true : false,
  521. 'S_ENABLE_INDEXING' => ($forum_data['enable_indexing']) ? true : false,
  522. 'S_TOPIC_ICONS' => ($forum_data['enable_icons']) ? true : false,
  523. 'S_DISPLAY_SUBFORUM_LIST' => ($forum_data['display_subforum_list']) ? true : false,
  524. 'S_DISPLAY_ON_INDEX' => ($forum_data['display_on_index']) ? true : false,
  525. 'S_PRUNE_ENABLE' => ($forum_data['enable_prune']) ? true : false,
  526. 'S_FORUM_LINK_TRACK' => ($forum_data['forum_flags'] & FORUM_FLAG_LINK_TRACK) ? true : false,
  527. 'S_PRUNE_OLD_POLLS' => ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_POLL) ? true : false,
  528. 'S_PRUNE_ANNOUNCE' => ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_ANNOUNCE) ? true : false,
  529. 'S_PRUNE_STICKY' => ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_STICKY) ? true : false,
  530. 'S_DISPLAY_ACTIVE_TOPICS' => ($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS) ? true : false,
  531. 'S_ENABLE_POST_REVIEW' => ($forum_data['forum_flags'] & FORUM_FLAG_POST_REVIEW) ? true : false,
  532. 'S_ENABLE_QUICK_REPLY' => ($forum_data['forum_flags'] & FORUM_FLAG_QUICK_REPLY) ? true : false,
  533. 'S_CAN_COPY_PERMISSIONS' => ($action != 'edit' || empty($forum_id) || ($auth->acl_get('a_fauth') && $auth->acl_get('a_authusers') && $auth->acl_get('a_authgroups') && $auth->acl_get('a_mauth'))) ? true : false,
  534. ));
  535. return;
  536. break;
  537. case 'delete':
  538. if (!$forum_id)
  539. {
  540. trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
  541. }
  542. $forum_data = $this->get_forum_info($forum_id);
  543. $subforums_id = array();
  544. $subforums = get_forum_branch($forum_id, 'children');
  545. foreach ($subforums as $row)
  546. {
  547. $subforums_id[] = $row['forum_id'];
  548. }
  549. $forums_list = make_forum_select($forum_data['parent_id'], $subforums_id);
  550. $sql = 'SELECT forum_id
  551. FROM ' . FORUMS_TABLE . '
  552. WHERE forum_type = ' . FORUM_POST . "
  553. AND forum_id <> $forum_id";
  554. $result = $db->sql_query_limit($sql, 1);
  555. if ($db->sql_fetchrow($result))
  556. {
  557. $template->assign_vars(array(
  558. 'S_MOVE_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $subforums_id, false, true)) // , false, true, false???
  559. );
  560. }
  561. $db->sql_freeresult($result);
  562. $parent_id = ($this->parent_id == $forum_id) ? 0 : $this->parent_id;
  563. $template->assign_vars(array(
  564. 'S_DELETE_FORUM' => true,
  565. 'U_ACTION' => $this->u_action . "&amp;parent_id={$parent_id}&amp;action=delete&amp;f=$forum_id",
  566. 'U_BACK' => $this->u_action . '&amp;parent_id=' . $this->parent_id,
  567. 'FORUM_NAME' => $forum_data['forum_name'],
  568. 'S_FORUM_POST' => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
  569. 'S_FORUM_LINK' => ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
  570. 'S_HAS_SUBFORUMS' => ($forum_data['right_id'] - $forum_data['left_id'] > 1) ? true : false,
  571. 'S_FORUMS_LIST' => $forums_list,
  572. 'S_ERROR' => (sizeof($errors)) ? true : false,
  573. 'ERROR_MSG' => (sizeof($errors)) ? implode('<br />', $errors) : '')
  574. );
  575. return;
  576. break;
  577. case 'copy_perm':
  578. $forum_perm_from = request_var('forum_perm_from', 0);
  579. // Copy permissions?
  580. if (!empty($forum_perm_from) && $forum_perm_from != $forum_id)
  581. {
  582. copy_forum_permissions($forum_perm_from, $forum_id, true);
  583. cache_moderators();
  584. $auth->acl_clear_prefetch();
  585. $cache->destroy('sql', FORUMS_TABLE);
  586. $acl_url = '&amp;mode=setting_forum_local&amp;forum_id[]=' . $forum_id;
  587. $message = $user->lang['FORUM_UPDATED'];
  588. // Redirect to permissions
  589. if ($auth->acl_get('a_fauth'))
  590. {
  591. $message .= '<br /><br />' . sprintf($user->lang['REDIRECT_ACL'], '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url) . '">', '</a>');
  592. }
  593. trigger_error($message . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id));
  594. }
  595. break;
  596. }
  597. // Default management page
  598. if (!$this->parent_id)
  599. {
  600. $navigation = $user->lang['FORUM_INDEX'];
  601. }
  602. else
  603. {
  604. $navigation = '<a href="' . $this->u_action . '">' . $user->lang['FORUM_INDEX'] . '</a>';
  605. $forums_nav = get_forum_branch($this->parent_id, 'parents', 'descending');
  606. foreach ($forums_nav as $row)
  607. {
  608. if ($row['forum_id'] == $this->parent_id)
  609. {
  610. $navigation .= ' -&gt; ' . $row['forum_name'];
  611. }
  612. else
  613. {
  614. $navigation .= ' -&gt; <a href="' . $this->u_action . '&amp;parent_id=' . $row['forum_id'] . '">' . $row['forum_name'] . '</a>';
  615. }
  616. }
  617. }
  618. // Jumpbox
  619. $forum_box = make_forum_select($this->parent_id, false, false, false, false); //make_forum_select($this->parent_id);
  620. if ($action == 'sync' || $action == 'sync_forum')
  621. {
  622. $template->assign_var('S_RESYNCED', true);
  623. }
  624. $sql = 'SELECT *
  625. FROM ' . FORUMS_TABLE . "
  626. WHERE parent_id = $this->parent_id
  627. ORDER BY left_id";
  628. $result = $db->sql_query($sql);
  629. if ($row = $db->sql_fetchrow($result))
  630. {
  631. do
  632. {
  633. $forum_type = $row['forum_type'];
  634. if ($row['forum_status'] == ITEM_LOCKED)
  635. {
  636. $folder_image = '<img src="images/icon_folder_lock.gif" alt="' . $user->lang['LOCKED'] . '" />';
  637. }
  638. else
  639. {
  640. switch ($forum_type)
  641. {
  642. case FORUM_LINK:
  643. $folder_image = '<img src="images/icon_folder_link.gif" alt="' . $user->lang['LINK'] . '" />';
  644. break;
  645. default:
  646. $folder_image = ($row['left_id'] + 1 != $row['right_id']) ? '<img src="images/icon_subfolder.gif" alt="' . $user->lang['SUBFORUM'] . '" />' : '<img src="images/icon_folder.gif" alt="' . $user->lang['FOLDER'] . '" />';
  647. break;
  648. }
  649. }
  650. $url = $this->u_action . "&amp;parent_id=$this->parent_id&amp;f={$row['forum_id']}";
  651. $template->assign_block_vars('forums', array(
  652. 'FOLDER_IMAGE' => $folder_image,
  653. 'FORUM_IMAGE' => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="" />' : '',
  654. 'FORUM_IMAGE_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
  655. 'FORUM_NAME' => $row['forum_name'],
  656. 'FORUM_DESCRIPTION' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
  657. 'FORUM_TOPICS' => $row['forum_topics'],
  658. 'FORUM_POSTS' => $row['forum_posts'],
  659. 'S_FORUM_LINK' => ($forum_type == FORUM_LINK) ? true : false,
  660. 'S_FORUM_POST' => ($forum_type == FORUM_POST) ? true : false,
  661. 'U_FORUM' => $this->u_action . '&amp;parent_id=' . $row['forum_id'],
  662. 'U_MOVE_UP' => $url . '&amp;action=move_up',
  663. 'U_MOVE_DOWN' => $url . '&amp;action=move_down',
  664. 'U_EDIT' => $url . '&amp;action=edit',
  665. 'U_DELETE' => $url . '&amp;action=delete',
  666. 'U_SYNC' => $url . '&amp;action=sync')
  667. );
  668. }
  669. while ($row = $db->sql_fetchrow($result));
  670. }
  671. else if ($this->parent_id)
  672. {
  673. $row = $this->get_forum_info($this->parent_id);
  674. $url = $this->u_action . '&amp;parent_id=' . $this->parent_id . '&amp;f=' . $row['forum_id'];
  675. $template->assign_vars(array(
  676. 'S_NO_FORUMS' => true,
  677. 'U_EDIT' => $url . '&amp;action=edit',
  678. 'U_DELETE' => $url . '&amp;action=delete',
  679. 'U_SYNC' => $url . '&amp;action=sync')
  680. );
  681. }
  682. $db->sql_freeresult($result);
  683. $template->assign_vars(array(
  684. 'ERROR_MSG' => (sizeof($errors)) ? implode('<br />', $errors) : '',
  685. 'NAVIGATION' => $navigation,
  686. 'FORUM_BOX' => $forum_box,
  687. 'U_SEL_ACTION' => $this->u_action,
  688. 'U_ACTION' => $this->u_action . '&amp;parent_id=' . $this->parent_id,
  689. 'U_PROGRESS_BAR' => $this->u_action . '&amp;action=progress_bar',
  690. 'UA_PROGRESS_BAR' => addslashes($this->u_action . '&amp;action=progress_bar'),
  691. ));
  692. }
  693. /**
  694. * Get forum details
  695. */
  696. function get_forum_info($forum_id)
  697. {
  698. global $db;
  699. $sql = 'SELECT *
  700. FROM ' . FORUMS_TABLE . "
  701. WHERE forum_id = $forum_id";
  702. $result = $db->sql_query($sql);
  703. $row = $db->sql_fetchrow($result);
  704. $db->sql_freeresult($result);
  705. if (!$row)
  706. {
  707. trigger_error("Forum #$forum_id does not exist", E_USER_ERROR);
  708. }
  709. return $row;
  710. }
  711. /**
  712. * Update forum data
  713. */
  714. function update_forum_data(&$forum_data)
  715. {
  716. global $db, $user, $cache, $phpbb_root_path;
  717. $errors = array();
  718. if (!$forum_data['forum_name'])
  719. {
  720. $errors[] = $user->lang['FORUM_NAME_EMPTY'];
  721. }
  722. if (utf8_strlen($forum_data['forum_desc']) > 4000)
  723. {
  724. $errors[] = $user->lang['FORUM_DESC_TOO_LONG'];
  725. }
  726. if (utf8_strlen($forum_data['forum_rules']) > 4000)
  727. {
  728. $errors[] = $user->lang['FORUM_RULES_TOO_LONG'];
  729. }
  730. if ($forum_data['forum_password'] || $forum_data['forum_password_confirm'])
  731. {
  732. if ($forum_data['forum_password'] != $forum_data['forum_password_confirm'])
  733. {
  734. $forum_data['forum_password'] = $forum_data['forum_password_confirm'] = '';
  735. $errors[] = $user->lang['FORUM_PASSWORD_MISMATCH'];
  736. }
  737. }
  738. if ($forum_data['prune_days'] < 0 || $forum_data['prune_viewed'] < 0 || $forum_data['prune_freq'] < 0)
  739. {
  740. $forum_data['prune_days'] = $forum_data['prune_viewed'] = $forum_data['prune_freq'] = 0;
  741. $errors[] = $user->lang['FORUM_DATA_NEGATIVE'];
  742. }
  743. $range_test_ary = array(
  744. array('lang' => 'FORUM_TOPICS_PAGE', 'value' => $forum_data['forum_topics_per_page'], 'column_type' => 'TINT:0'),
  745. );
  746. if (!empty($forum_data['forum_image']) && !file_exists($phpbb_root_path . $forum_data['forum_image']))
  747. {
  748. $errors[] = $user->lang['FORUM_IMAGE_NO_EXIST'];
  749. }
  750. validate_range($range_test_ary, $errors);
  751. // Set forum flags
  752. // 1 = link tracking
  753. // 2 = prune old polls
  754. // 4 = prune announcements
  755. // 8 = prune stickies
  756. // 16 = show active topics
  757. // 32 = enable post review
  758. $forum_data['forum_flags'] = 0;
  759. $forum_data['forum_flags'] += ($forum_data['forum_link_track']) ? FORUM_FLAG_LINK_TRACK : 0;
  760. $forum_data['forum_flags'] += ($forum_data['prune_old_polls']) ? FORUM_FLAG_PRUNE_POLL : 0;
  761. $forum_data['forum_flags'] += ($forum_data['prune_announce']) ? FORUM_FLAG_PRUNE_ANNOUNCE : 0;
  762. $forum_data['forum_flags'] += ($forum_data['prune_sticky']) ? FORUM_FLAG_PRUNE_STICKY : 0;
  763. $forum_data['forum_flags'] += ($forum_data['show_active']) ? FORUM_FLAG_ACTIVE_TOPICS : 0;
  764. $forum_data['forum_flags'] += ($forum_data['enable_post_review']) ? FORUM_FLAG_POST_REVIEW : 0;
  765. $forum_data['forum_flags'] += ($forum_data['enable_quick_reply']) ? FORUM_FLAG_QUICK_REPLY : 0;
  766. // Unset data that are not database fields
  767. $forum_data_sql = $forum_data;
  768. unset($forum_data_sql['forum_link_track']);
  769. unset($forum_data_sql['prune_old_polls']);
  770. unset($forum_data_sql['prune_announce']);
  771. unset($forum_data_sql['prune_sticky']);
  772. unset($forum_data_sql['show_active']);
  773. unset($forum_data_sql['enable_post_review']);
  774. unset($forum_data_sql['enable_quick_reply']);
  775. unset($forum_data_sql['forum_password_confirm']);
  776. // What are we going to do tonight Brain? The same thing we do everynight,
  777. // try to take over the world ... or decide whether to continue update
  778. // and if so, whether it's a new forum/cat/link or an existing one
  779. if (sizeof($errors))
  780. {
  781. return $errors;
  782. }
  783. // As we don't know the old password, it's kinda tricky to detect changes
  784. if ($forum_data_sql['forum_password_unset'])
  785. {
  786. $forum_data_sql['forum_password'] = '';
  787. }
  788. else if (empty($forum_data_sql['forum_password']))
  789. {
  790. unset($forum_data_sql['forum_password']);
  791. }
  792. else
  793. {
  794. $forum_data_sql['forum_password'] = phpbb_hash($forum_data_sql['forum_password']);
  795. }
  796. unset($forum_data_sql['forum_password_unset']);
  797. if (!isset($forum_data_sql['forum_id']))
  798. {
  799. // no forum_id means we're creating a new forum
  800. unset($forum_data_sql['type_action']);
  801. if ($forum_data_sql['parent_id'])
  802. {
  803. $sql = 'SELECT left_id, right_id, forum_type
  804. FROM ' . FORUMS_TABLE . '
  805. WHERE forum_id = ' . $forum_data_sql['parent_id'];
  806. $result = $db->sql_query($sql);
  807. $row = $db->sql_fetchrow($result);
  808. $db->sql_freeresult($result);
  809. if (!$row)
  810. {
  811. trigger_error($user->lang['PARENT_NOT_EXIST'] . adm_back_link($this->u_action . '&amp;' . $this->parent_id), E_USER_WARNING);
  812. }
  813. if ($row['forum_type'] == FORUM_LINK)
  814. {
  815. $errors[] = $user->lang['PARENT_IS_LINK_FORUM'];
  816. return $errors;
  817. }
  818. $sql = 'UPDATE ' . FORUMS_TABLE . '
  819. SET left_id = left_id + 2, right_id = right_id + 2
  820. WHERE left_id > ' . $row['right_id'];
  821. $db->sql_query($sql);
  822. $sql = 'UPDATE ' . FORUMS_TABLE . '
  823. SET right_id = right_id + 2
  824. WHERE ' . $row['left_id'] . ' BETWEEN left_id AND right_id';
  825. $db->sql_query($sql);
  826. $forum_data_sql['left_id'] = $row['right_id'];
  827. $forum_data_sql['right_id'] = $row['right_id'] + 1;
  828. }
  829. else
  830. {
  831. $sql = 'SELECT MAX(right_id) AS right_id
  832. FROM ' . FORUMS_TABLE;
  833. $result = $db->sql_query($sql);
  834. $row = $db->sql_fetchrow($result);
  835. $db->sql_freeresult($result);
  836. $forum_data_sql['left_id'] = $row['right_id'] + 1;
  837. $forum_data_sql['right_id'] = $row['right_id'] + 2;
  838. }
  839. $sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $forum_data_sql);
  840. $db->sql_query($sql);
  841. $forum_data['forum_id'] = $db->sql_nextid();
  842. add_log('admin', 'LOG_FORUM_ADD', $forum_data['forum_name']);
  843. }
  844. else
  845. {
  846. $row = $this->get_forum_info($forum_data_sql['forum_id']);
  847. if ($row['forum_type'] == FORUM_POST && $row['forum_type'] != $forum_data_sql['forum_type'])
  848. {
  849. // Has subforums and want to change into a link?
  850. if ($row['right_id'] - $row['left_id'] > 1 && $forum_data_sql['forum_type'] == FORUM_LINK)
  851. {
  852. $errors[] = $user->lang['FORUM_WITH_SUBFORUMS_NOT_TO_LINK'];
  853. return $errors;
  854. }
  855. // we're turning a postable forum into a non-postable forum
  856. if ($forum_data_sql['type_action'] == 'move')
  857. {
  858. $to_forum_id = request_var('to_forum_id', 0);
  859. if ($to_forum_id)
  860. {
  861. $errors = $this->move_forum_content($forum_data_sql['forum_id'], $to_forum_id);
  862. }
  863. else
  864. {
  865. return array($user->lang['NO_DESTINATION_FORUM']);
  866. }
  867. }
  868. else if ($forum_data_sql['type_action'] == 'delete')
  869. {
  870. $errors = $this->delete_forum_content($forum_data_sql['forum_id']);
  871. }
  872. else
  873. {
  874. return array($user->lang['NO_FORUM_ACTION']);
  875. }
  876. $forum_data_sql['forum_posts'] = $forum_data_sql['forum_topics'] = $forum_data_sql['forum_topics_real'] = $forum_data_sql['forum_last_post_id'] = $forum_data_sql['forum_last_poster_id'] = $forum_data_sql['forum_last_post_time'] = 0;
  877. $forum_data_sql['forum_last_poster_name'] = $forum_data_sql['forum_last_poster_colour'] = '';
  878. }
  879. else if ($row['forum_type'] == FORUM_CAT && $forum_data_sql['forum_type'] == FORUM_LINK)
  880. {
  881. // Has subforums?
  882. if ($row['right_id'] - $row['left_id'] > 1)
  883. {
  884. // We are turning a category into a link - but need to decide what to do with the subforums.
  885. $action_subforums = request_var('action_subforums', '');
  886. $subforums_to_id = request_var('subforums_to_id', 0);
  887. if ($action_subforums == 'delete')
  888. {
  889. $rows = get_forum_branch($row['forum_id'], 'children', 'descending', false);
  890. foreach ($rows as $_row)
  891. {
  892. // Do not remove the forum id we are about to change. ;)
  893. if ($_row['forum_id'] == $row['forum_id'])
  894. {
  895. continue;
  896. }
  897. $forum_ids[] = $_row['forum_id'];
  898. $errors = array_merge($errors, $this->delete_forum_content($_row['forum_id']));
  899. }
  900. if (sizeof($errors))
  901. {
  902. return $errors;
  903. }
  904. if (sizeof($forum_ids))
  905. {
  906. $sql = 'DELETE FROM ' . FORUMS_TABLE . '
  907. WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
  908. $db->sql_query($sql);
  909. $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . '
  910. WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
  911. $db->sql_query($sql);
  912. $sql = 'DELETE FROM ' . ACL_USERS_TABLE . '
  913. WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
  914. $db->sql_query($sql);
  915. // Delete forum ids from extension groups table
  916. $sql = 'SELECT group_id, allowed_forums
  917. FROM ' . EXTENSION_GROUPS_TABLE;
  918. $result = $db->sql_query($sql);
  919. while ($_row = $db->sql_fetchrow($result))
  920. {
  921. if (!$_row['allowed_forums'])
  922. {
  923. continue;
  924. }
  925. $allowed_forums = unserialize(trim($_row['allowed_forums']));
  926. $allowed_forums = array_diff($allowed_forums, $forum_ids);
  927. $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . "
  928. SET allowed_forums = '" . ((sizeof($allowed_forums)) ? serialize($allowed_forums) : '') . "'
  929. WHERE group_id = {$_row['group_id']}";
  930. $db->sql_query($sql);
  931. }
  932. $db->sql_freeresult($result);
  933. $cache->destroy('_extensions');
  934. }
  935. }
  936. else if ($action_subforums == 'move')
  937. {
  938. if (!$subforums_to_id)
  939. {
  940. return array($user->lang['NO_DESTINATION_FORUM']);
  941. }
  942. $sql = 'SELECT forum_name
  943. FROM ' . FORUMS_TABLE . '
  944. WHERE forum_id = ' . $subforums_to_id;
  945. $result = $db->sql_query($sql);
  946. $_row = $db->sql_fetchrow($result);
  947. $db->sql_freeresult($result);
  948. if (!$_row)
  949. {
  950. return array($user->lang['NO_FORUM']);
  951. }
  952. $subforums_to_name = $_row['forum_name'];
  953. $sql = 'SELECT forum_id
  954. FROM ' . FORUMS_TABLE . "
  955. WHERE parent_id = {$row['forum_id']}";
  956. $result = $db->sql_query($sql);
  957. while ($_row = $db->sql_fetchrow($result))
  958. {
  959. $this->move_forum($_row['forum_id'], $subforums_to_id);
  960. }
  961. $db->sql_freeresult($result);
  962. $sql = 'UPDATE ' . FORUMS_TABLE . "
  963. SET parent_id = $subforums_to_id
  964. WHERE parent_id = {$row['forum_id']}";
  965. $db->sql_query($sql);
  966. }
  967. // Adjust the left/right id
  968. $sql = 'UPDATE ' . FORUMS_TABLE . '
  969. SET right_id = left_id + 1
  970. WHERE forum_id = ' . $row['forum_id'];
  971. $db->sql_query($sql);
  972. }
  973. }
  974. else if ($row['forum_type'] == FORUM_CAT && $forum_data_sql['forum_type'] == FORUM_POST)
  975. {
  976. // Changing a category to a forum? Reset the data (you can't post directly in a cat, you must use a forum)
  977. $forum_data_sql['forum_posts'] = 0;
  978. $forum_data_sql['forum_topics'] = 0;
  979. $forum_data_sql['forum_topics_real'] = 0;
  980. $forum_data_sql['forum_last_post_id'] = 0;
  981. $forum_data_sql['forum_last_post_subject'] = '';
  982. $forum_data_sql['forum_last_post_time'] = 0;
  983. $forum_data_sql['forum_last_poster_id'] = 0;
  984. $forum_data_sql['forum_last_poster_name'] = '';
  985. $forum_data_sql['forum_last_poster_colour'] = '';
  986. }
  987. if (sizeof($errors))
  988. {
  989. return $errors;
  990. }
  991. if ($row['parent_id'] != $forum_data_sql['parent_id'])
  992. {
  993. if ($row['forum_id'] != $forum_data_sql['parent_id'])
  994. {
  995. $errors = $this->move_forum($forum_data_sql['forum_id'], $forum_data_sql['parent_id']);
  996. }
  997. else
  998. {
  999. $forum_data_sql['parent_id'] = $row['parent_id'];
  1000. }
  1001. }
  1002. if (sizeof($errors))
  1003. {
  1004. return $errors;
  1005. }
  1006. unset($forum_data_sql['type_action']);
  1007. if ($row['forum_name'] != $forum_data_sql['forum_name'])
  1008. {
  1009. // the forum name has changed, clear the parents list of all forums (for safety)
  1010. $sql = 'UPDATE ' . FORUMS_TABLE . "
  1011. SET forum_parents = ''";
  1012. $db->sql_query($sql);
  1013. }
  1014. // Setting the forum id to the forum id is not really received well by some dbs. ;)
  1015. $forum_id = $forum_data_sql['forum_id'];
  1016. unset($forum_data_sql['forum_id']);
  1017. $sql = 'UPDATE ' . FORUMS_TABLE . '
  1018. SET ' . $db->sql_build_array('UPDATE', $forum_data_sql) . '
  1019. WHERE forum_id = ' . $forum_id;
  1020. $db->sql_query($sql);
  1021. // Add it back
  1022. $forum_data['forum_id'] = $forum_id;
  1023. add_log('admin', 'LOG_FORUM_EDIT', $forum_data['forum_name']);
  1024. }
  1025. return $errors;
  1026. }
  1027. /**
  1028. * Move forum
  1029. */
  1030. function move_forum($from_id, $to_id)
  1031. {
  1032. global $db, $user;
  1033. $to_data = $moved_ids = $errors = array();
  1034. // Check if we want to move to a parent with link type
  1035. if ($to_id > 0)
  1036. {
  1037. $to_data = $this->get_forum_info($to_id);
  1038. if ($to_data['forum_type'] == FORUM_LINK)
  1039. {
  1040. $errors[] = $user->lang['PARENT_IS_LINK_FORUM'];
  1041. return $errors;
  1042. }
  1043. }
  1044. $moved_forums = get_forum_branch($from_id, 'children', 'descending');
  1045. $from_data = $moved_forums[0];
  1046. $diff = sizeof($moved_forums) * 2;
  1047. $moved_ids = array();
  1048. for ($i = 0; $i < sizeof($moved_forums); ++$i)
  1049. {
  1050. $moved_ids[] = $moved_forums[$i]['forum_id'];
  1051. }
  1052. // Resync parents
  1053. $sql = 'UPDATE ' . FORUMS_TABLE . "
  1054. SET right_id = right_id - $diff, forum_parents = ''
  1055. WHERE left_id < " . $from_data['right_id'] . "
  1056. AND right_id > " . $from_data['right_id'];
  1057. $db->sql_query($sql);
  1058. // Resync righthand side of tree
  1059. $sql = 'UPDATE ' . FORUMS_TABLE . "
  1060. SET left_id = left_id - $diff, right_id = right_id - $diff, forum_parents = ''
  1061. WHERE left_id > " . $from_data['right_id'];
  1062. $db->sql_query($sql);
  1063. if ($to_id > 0)
  1064. {
  1065. // Retrieve $to_data again, it may have been changed...
  1066. $to_data = $this->get_forum_info($to_id);
  1067. // Resync new parents
  1068. $sql = 'UPDATE ' . FORUMS_TABLE . "
  1069. SET right_id = right_id + $diff, forum_parents = ''
  1070. WHERE " . $to_data['right_id'] . ' BETWEEN left_id AND right_id
  1071. AND ' . $db->sql_in_set('forum_id', $moved_ids, true);
  1072. $db->sql_query($sql);
  1073. // Resync the righthand side of the tree
  1074. $sql = 'UPDATE ' . FORUMS_TABLE . "
  1075. SET left_id = left_id + $diff, right_id = right_id + $diff, forum_parents = ''
  1076. WHERE left_id > " . $to_data['right_id'] . '
  1077. AND ' . $db->sql_in_set('forum_id', $moved_ids, true);
  1078. $db->sql_query($sql);
  1079. // Resync moved branch
  1080. $to_data['right_id'] += $diff;
  1081. if ($to_data['right_id'] > $from_data['right_id'])
  1082. {
  1083. $diff = '+ ' . ($to_data['right_id'] - $from_data['right_id'] - 1);
  1084. }
  1085. else
  1086. {
  1087. $diff = '- ' . abs($to_data['right_id'] - $from_data['right_id'] - 1);
  1088. }
  1089. }
  1090. else
  1091. {
  1092. $sql = 'SELECT MAX(right_id) AS right_id
  1093. FROM ' . FORUMS_TABLE . '
  1094. WHERE ' . $db->sql_in_set('forum_id', $moved_ids, true);
  1095. $result = $db->sql_query($sql);
  1096. $row = $db->sql_fetchrow($result);
  1097. $db->sql_freeresult($result);
  1098. $diff = '+ ' . ($row['right_id'] - $from_data['left_id'] + 1);
  1099. }
  1100. $sql = 'UPDATE ' . FORUMS_TABLE . "
  1101. SET left_id = left_id $diff, right_id = right_id $diff, forum_parents = ''
  1102. WHERE " . $db->sql_in_set('forum_id', $moved_ids);
  1103. $db->sql_query($sql);
  1104. return $errors;
  1105. }
  1106. /**
  1107. * Move forum content from one to another forum
  1108. */
  1109. function move_forum_content($from_id, $to_id, $sync = true)
  1110. {
  1111. global $db;
  1112. $table_ary = array(LOG_TABLE, POSTS_TABLE, TOPICS_TABLE, DRAFTS_TABLE, TOPICS_TRACK_TABLE);
  1113. foreach ($table_ary as $table)
  1114. {
  1115. $sql = "UPDATE $table
  1116. SET forum_id = $to_id
  1117. WHERE forum_id = $from_id";
  1118. $db->sql_query($sql);
  1119. }
  1120. unset($table_ary);
  1121. $table_ary = array(FORUMS_ACCESS_TABLE, FORUMS_TRACK_TABLE, FORUMS_WATCH_TABLE, MODERATOR_CACHE_TABLE);
  1122. foreach ($table_ary as $table)
  1123. {
  1124. $sql = "DELETE FROM $table
  1125. WHERE forum_id = $from_id";
  1126. $db->sql_query($sql);
  1127. }
  1128. if ($sync)
  1129. {
  1130. // Delete ghost topics that link back to the same forum then resync counters
  1131. sync('topic_moved');
  1132. sync('forum', 'forum_id', $to_id, false, true);
  1133. }
  1134. return array();
  1135. }
  1136. /**
  1137. * Remove complete forum
  1138. */
  1139. function delete_forum($forum_id, $action_posts = 'delete', $action_subforums = 'delete', $posts_to_id = 0, $subforums_to_id = 0)
  1140. {
  1141. global $db, $user, $cache;
  1142. $forum_data = $this->get_forum_info($forum_id);
  1143. $errors = array();
  1144. $log_action_posts = $log_action_forums = $posts_to_name = $subforums_to_name = '';
  1145. $forum_ids = array($forum_id);
  1146. if ($action_posts == 'delete')
  1147. {
  1148. $log_action_posts = 'POSTS';
  1149. $errors = array_merge($errors, $this->delete_forum_content($forum_id));
  1150. }
  1151. else if ($action_posts == 'move')
  1152. {
  1153. if (!$posts_to_id)
  1154. {
  1155. $errors[] = $user->lang['NO_DESTINATION_FORUM'];
  1156. }
  1157. else
  1158. {
  1159. $log_action_posts = 'MOVE_POSTS';
  1160. $sql = 'SELECT forum_name
  1161. FROM ' . FORUMS_TABLE . '
  1162. WHERE forum_id = ' . $posts_to_id;
  1163. $result = $db->sql_query($sql);
  1164. $row = $db->sql_fetchrow($result);
  1165. $db->sql_freeresult($result);
  1166. if (!$row)
  1167. {
  1168. $errors[] = $user->lang['NO_FORUM'];
  1169. }
  1170. else
  1171. {
  1172. $posts_to_name = $row['forum_name'];
  1173. $errors = array_merge($errors, $this->move_forum_content($forum_id, $posts_to_id));
  1174. }
  1175. }
  1176. }
  1177. if (sizeof($errors))
  1178. {
  1179. return $errors;
  1180. }
  1181. if ($action_subforums == 'delete')
  1182. {
  1183. $log_action_forums = 'FORUMS';
  1184. $rows = get_forum_branch($forum_id, 'children', 'descending', false);
  1185. foreach ($rows as $row)
  1186. {
  1187. $forum_ids[] = $row['forum_id'];
  1188. $errors = array_merge($errors, $this->delete_forum_content($row['forum_id']));
  1189. }
  1190. if (sizeof($errors))
  1191. {
  1192. return $errors;
  1193. }
  1194. $diff = sizeof($forum_ids) * 2;
  1195. $sql = 'DELETE FROM ' . FORUMS_TABLE . '
  1196. WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
  1197. $db->sql_query($sql);
  1198. $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . '
  1199. WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
  1200. $db->sql_query($sql);
  1201. $sql = 'DELETE FROM ' . ACL_USERS_TABLE . '
  1202. WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
  1203. $db->sql_query($sql);
  1204. }
  1205. else if ($action_subforums == 'move')
  1206. {
  1207. if (!$subforums_to_id)
  1208. {
  1209. $errors[] = $user->lang['NO_DESTINATION_FORUM'];
  1210. }
  1211. else
  1212. {
  1213. $log_action_forums = 'MOVE_FORUMS';
  1214. $sql = 'SELECT forum_name
  1215. FROM ' . FORUMS_TABLE . '
  1216. WHERE forum_id = ' . $subforums_to_id;
  1217. $result = $db->sql_query($sql);
  1218. $row = $db->sql_fetchrow($result);
  1219. $db->sql_freeresult($result);
  1220. if (!$row)
  1221. {
  1222. $errors[] = $user->lang['NO_FORUM'];
  1223. }
  1224. else
  1225. {
  1226. $subforums_to_name = $row['forum_name'];
  1227. $sql = 'SELECT forum_id
  1228. FROM ' . FORUMS_TABLE . "
  1229. WHERE parent_id = $forum_id";
  1230. $result = $db->sql_query($sql);
  1231. while ($row = $db->sql_fetchrow($result))
  1232. {
  1233. $this->move_forum($row['forum_id'], $subforums_to_id);
  1234. }
  1235. $db->sql_freeresult($result);
  1236. // Grab new forum data for correct tree updating later
  1237. $forum_data = $this->get_forum_info($forum_id);
  1238. $sql = 'UPDATE ' . FORUMS_TABLE . "
  1239. SET parent_id = $subforums_to_id
  1240. WHERE parent_id = $forum_id";
  1241. $db->sql_query($sql);
  1242. $diff = 2;
  1243. $sql = 'DE…

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