Subs-Boards.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293
  1. <?php
  2. /**
  3. * This file is mainly concerned with minor tasks relating to boards, such as
  4. * marking them read, collapsing categories, or quick moderation.
  5. *
  6. * Simple Machines Forum (SMF)
  7. *
  8. * @package SMF
  9. * @author Simple Machines http://www.simplemachines.org
  10. * @copyright 2014 Simple Machines and individual contributors
  11. * @license http://www.simplemachines.org/about/smf/license.php BSD
  12. *
  13. * @version 2.1 Alpha 1
  14. */
  15. if (!defined('SMF'))
  16. die('No direct access...');
  17. /**
  18. * Mark a board or multiple boards read.
  19. *
  20. * @param array $boards
  21. * @param bool $unread
  22. */
  23. function markBoardsRead($boards, $unread = false)
  24. {
  25. global $user_info, $modSettings, $smcFunc;
  26. // Force $boards to be an array.
  27. if (!is_array($boards))
  28. $boards = array($boards);
  29. else
  30. $boards = array_unique($boards);
  31. // No boards, nothing to mark as read.
  32. if (empty($boards))
  33. return;
  34. // Allow the user to mark a board as unread.
  35. if ($unread)
  36. {
  37. // Clear out all the places where this lovely info is stored.
  38. // @todo Maybe not log_mark_read?
  39. $smcFunc['db_query']('', '
  40. DELETE FROM {db_prefix}log_mark_read
  41. WHERE id_board IN ({array_int:board_list})
  42. AND id_member = {int:current_member}',
  43. array(
  44. 'current_member' => $user_info['id'],
  45. 'board_list' => $boards,
  46. )
  47. );
  48. $smcFunc['db_query']('', '
  49. DELETE FROM {db_prefix}log_boards
  50. WHERE id_board IN ({array_int:board_list})
  51. AND id_member = {int:current_member}',
  52. array(
  53. 'current_member' => $user_info['id'],
  54. 'board_list' => $boards,
  55. )
  56. );
  57. }
  58. // Otherwise mark the board as read.
  59. else
  60. {
  61. $markRead = array();
  62. foreach ($boards as $board)
  63. $markRead[] = array($modSettings['maxMsgID'], $user_info['id'], $board);
  64. // Update log_mark_read and log_boards.
  65. $smcFunc['db_insert']('replace',
  66. '{db_prefix}log_mark_read',
  67. array('id_msg' => 'int', 'id_member' => 'int', 'id_board' => 'int'),
  68. $markRead,
  69. array('id_board', 'id_member')
  70. );
  71. $smcFunc['db_insert']('replace',
  72. '{db_prefix}log_boards',
  73. array('id_msg' => 'int', 'id_member' => 'int', 'id_board' => 'int'),
  74. $markRead,
  75. array('id_board', 'id_member')
  76. );
  77. }
  78. // Get rid of useless log_topics data, because log_mark_read is better for it - even if marking unread - I think so...
  79. // @todo look at this...
  80. // The call to markBoardsRead() in Display() used to be simply
  81. // marking log_boards (the previous query only)
  82. $result = $smcFunc['db_query']('', '
  83. SELECT MIN(id_topic)
  84. FROM {db_prefix}log_topics
  85. WHERE id_member = {int:current_member}',
  86. array(
  87. 'current_member' => $user_info['id'],
  88. )
  89. );
  90. list ($lowest_topic) = $smcFunc['db_fetch_row']($result);
  91. $smcFunc['db_free_result']($result);
  92. if (empty($lowest_topic))
  93. return;
  94. // @todo SLOW This query seems to eat it sometimes.
  95. $result = $smcFunc['db_query']('', '
  96. SELECT lt.id_topic
  97. FROM {db_prefix}log_topics AS lt
  98. INNER JOIN {db_prefix}topics AS t /*!40000 USE INDEX (PRIMARY) */ ON (t.id_topic = lt.id_topic
  99. AND t.id_board IN ({array_int:board_list}))
  100. WHERE lt.id_member = {int:current_member}
  101. AND lt.id_topic >= {int:lowest_topic}
  102. AND lt.unwatched != 1',
  103. array(
  104. 'current_member' => $user_info['id'],
  105. 'board_list' => $boards,
  106. 'lowest_topic' => $lowest_topic,
  107. )
  108. );
  109. $topics = array();
  110. while ($row = $smcFunc['db_fetch_assoc']($result))
  111. $topics[] = $row['id_topic'];
  112. $smcFunc['db_free_result']($result);
  113. if (!empty($topics))
  114. $smcFunc['db_query']('', '
  115. DELETE FROM {db_prefix}log_topics
  116. WHERE id_member = {int:current_member}
  117. AND id_topic IN ({array_int:topic_list})',
  118. array(
  119. 'current_member' => $user_info['id'],
  120. 'topic_list' => $topics,
  121. )
  122. );
  123. }
  124. /**
  125. * Mark one or more boards as read.
  126. */
  127. function MarkRead()
  128. {
  129. global $board, $topic, $user_info, $board_info, $modSettings, $smcFunc;
  130. // No Guests allowed!
  131. is_not_guest();
  132. checkSession('get');
  133. if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'all')
  134. {
  135. // Find all the boards this user can see.
  136. $result = $smcFunc['db_query']('', '
  137. SELECT b.id_board
  138. FROM {db_prefix}boards AS b
  139. WHERE {query_see_board}',
  140. array(
  141. )
  142. );
  143. $boards = array();
  144. while ($row = $smcFunc['db_fetch_assoc']($result))
  145. $boards[] = $row['id_board'];
  146. $smcFunc['db_free_result']($result);
  147. if (!empty($boards))
  148. markBoardsRead($boards, isset($_REQUEST['unread']));
  149. $_SESSION['id_msg_last_visit'] = $modSettings['maxMsgID'];
  150. if (!empty($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'action=unread') !== false)
  151. redirectexit('action=unread');
  152. if (isset($_SESSION['topicseen_cache']))
  153. $_SESSION['topicseen_cache'] = array();
  154. redirectexit();
  155. }
  156. elseif (isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'unreadreplies')
  157. {
  158. // Make sure all the topics are integers!
  159. $topics = array_map('intval', explode('-', $_REQUEST['topics']));
  160. $smcFunc['db_query']('', '
  161. SELECT id_topic, unwatched
  162. FROM {db_prefix}log_topics
  163. WHERE id_topic IN ({array_int:selected_topics})
  164. AND id_member = {int:current_user}',
  165. array(
  166. 'selected_topics' => $topics,
  167. 'current_user' => $user_info['id'],
  168. )
  169. );
  170. $logged_topics = array();
  171. while ($row = $smcFunc['db_fetch_assoc']($request))
  172. $logged_topics[$row['id_topic']] = $row['unwatched'];
  173. $smcFunc['db_free_result']($request);
  174. $markRead = array();
  175. foreach ($topics as $id_topic)
  176. $markRead[] = array($modSettings['maxMsgID'], $user_info['id'], $id_topic, (isset($logged_topics[$topic]) ? $logged_topics[$topic] : 0));
  177. $smcFunc['db_insert']('replace',
  178. '{db_prefix}log_topics',
  179. array('id_msg' => 'int', 'id_member' => 'int', 'id_topic' => 'int', 'unwatched' => 'int'),
  180. $markRead,
  181. array('id_member', 'id_topic')
  182. );
  183. if (isset($_SESSION['topicseen_cache']))
  184. $_SESSION['topicseen_cache'] = array();
  185. redirectexit('action=unreadreplies');
  186. }
  187. // Special case: mark a topic unread!
  188. elseif (isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'topic')
  189. {
  190. // First, let's figure out what the latest message is.
  191. $result = $smcFunc['db_query']('', '
  192. SELECT t.id_first_msg, t.id_last_msg, IFNULL(lt.unwatched, 0) as unwatched
  193. FROM {db_prefix}topics as t
  194. LEFT JOIN {db_prefix}log_topics as lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member})
  195. WHERE t.id_topic = {int:current_topic}',
  196. array(
  197. 'current_topic' => $topic,
  198. 'current_member' => $user_info['id'],
  199. )
  200. );
  201. $topicinfo = $smcFunc['db_fetch_assoc']($result);
  202. $smcFunc['db_free_result']($result);
  203. if (!empty($_GET['t']))
  204. {
  205. // If they read the whole topic, go back to the beginning.
  206. if ($_GET['t'] >= $topicinfo['id_last_msg'])
  207. $earlyMsg = 0;
  208. // If they want to mark the whole thing read, same.
  209. elseif ($_GET['t'] <= $topicinfo['id_first_msg'])
  210. $earlyMsg = 0;
  211. // Otherwise, get the latest message before the named one.
  212. else
  213. {
  214. $result = $smcFunc['db_query']('', '
  215. SELECT MAX(id_msg)
  216. FROM {db_prefix}messages
  217. WHERE id_topic = {int:current_topic}
  218. AND id_msg >= {int:id_first_msg}
  219. AND id_msg < {int:topic_msg_id}',
  220. array(
  221. 'current_topic' => $topic,
  222. 'topic_msg_id' => (int) $_GET['t'],
  223. 'id_first_msg' => $topicinfo['id_first_msg'],
  224. )
  225. );
  226. list ($earlyMsg) = $smcFunc['db_fetch_row']($result);
  227. $smcFunc['db_free_result']($result);
  228. }
  229. }
  230. // Marking read from first page? That's the whole topic.
  231. elseif ($_REQUEST['start'] == 0)
  232. $earlyMsg = 0;
  233. else
  234. {
  235. $result = $smcFunc['db_query']('', '
  236. SELECT id_msg
  237. FROM {db_prefix}messages
  238. WHERE id_topic = {int:current_topic}
  239. ORDER BY id_msg
  240. LIMIT {int:start}, 1',
  241. array(
  242. 'current_topic' => $topic,
  243. 'start' => (int) $_REQUEST['start'],
  244. )
  245. );
  246. list ($earlyMsg) = $smcFunc['db_fetch_row']($result);
  247. $smcFunc['db_free_result']($result);
  248. $earlyMsg--;
  249. }
  250. // Blam, unread!
  251. $smcFunc['db_insert']('replace',
  252. '{db_prefix}log_topics',
  253. array('id_msg' => 'int', 'id_member' => 'int', 'id_topic' => 'int', 'unwatched' => 'int'),
  254. array($earlyMsg, $user_info['id'], $topic, $topicinfo['unwatched']),
  255. array('id_member', 'id_topic')
  256. );
  257. redirectexit('board=' . $board . '.0');
  258. }
  259. else
  260. {
  261. $categories = array();
  262. $boards = array();
  263. if (isset($_REQUEST['c']))
  264. {
  265. $_REQUEST['c'] = explode(',', $_REQUEST['c']);
  266. foreach ($_REQUEST['c'] as $c)
  267. $categories[] = (int) $c;
  268. }
  269. if (isset($_REQUEST['boards']))
  270. {
  271. $_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
  272. foreach ($_REQUEST['boards'] as $b)
  273. $boards[] = (int) $b;
  274. }
  275. if (!empty($board))
  276. $boards[] = (int) $board;
  277. if (isset($_REQUEST['children']) && !empty($boards))
  278. {
  279. // They want to mark the entire tree starting with the boards specified
  280. // The easist thing is to just get all the boards they can see, but since we've specified the top of tree we ignore some of them
  281. $request = $smcFunc['db_query']('', '
  282. SELECT b.id_board, b.id_parent
  283. FROM {db_prefix}boards AS b
  284. WHERE {query_see_board}
  285. AND b.child_level > {int:no_parents}
  286. AND b.id_board NOT IN ({array_int:board_list})
  287. ORDER BY child_level ASC
  288. ',
  289. array(
  290. 'no_parents' => 0,
  291. 'board_list' => $boards,
  292. )
  293. );
  294. while ($row = $smcFunc['db_fetch_assoc']($request))
  295. if (in_array($row['id_parent'], $boards))
  296. $boards[] = $row['id_board'];
  297. $smcFunc['db_free_result']($request);
  298. }
  299. $clauses = array();
  300. $clauseParameters = array();
  301. if (!empty($categories))
  302. {
  303. $clauses[] = 'id_cat IN ({array_int:category_list})';
  304. $clauseParameters['category_list'] = $categories;
  305. }
  306. if (!empty($boards))
  307. {
  308. $clauses[] = 'id_board IN ({array_int:board_list})';
  309. $clauseParameters['board_list'] = $boards;
  310. }
  311. if (empty($clauses))
  312. redirectexit();
  313. $request = $smcFunc['db_query']('', '
  314. SELECT b.id_board
  315. FROM {db_prefix}boards AS b
  316. WHERE {query_see_board}
  317. AND b.' . implode(' OR b.', $clauses),
  318. array_merge($clauseParameters, array(
  319. ))
  320. );
  321. $boards = array();
  322. while ($row = $smcFunc['db_fetch_assoc']($request))
  323. $boards[] = $row['id_board'];
  324. $smcFunc['db_free_result']($request);
  325. if (empty($boards))
  326. redirectexit();
  327. markBoardsRead($boards, isset($_REQUEST['unread']));
  328. foreach ($boards as $b)
  329. {
  330. if (isset($_SESSION['topicseen_cache'][$b]))
  331. $_SESSION['topicseen_cache'][$b] = array();
  332. }
  333. if (!isset($_REQUEST['unread']))
  334. {
  335. // Find all the boards this user can see.
  336. $result = $smcFunc['db_query']('', '
  337. SELECT b.id_board
  338. FROM {db_prefix}boards AS b
  339. WHERE b.id_parent IN ({array_int:parent_list})
  340. AND {query_see_board}',
  341. array(
  342. 'parent_list' => $boards,
  343. )
  344. );
  345. if ($smcFunc['db_num_rows']($result) > 0)
  346. {
  347. $logBoardInserts = '';
  348. while ($row = $smcFunc['db_fetch_assoc']($result))
  349. $logBoardInserts[] = array($modSettings['maxMsgID'], $user_info['id'], $row['id_board']);
  350. $smcFunc['db_insert']('replace',
  351. '{db_prefix}log_boards',
  352. array('id_msg' => 'int', 'id_member' => 'int', 'id_board' => 'int'),
  353. $logBoardInserts,
  354. array('id_member', 'id_board')
  355. );
  356. }
  357. $smcFunc['db_free_result']($result);
  358. if (empty($board))
  359. redirectexit();
  360. else
  361. redirectexit('board=' . $board . '.0');
  362. }
  363. else
  364. {
  365. if (empty($board_info['parent']))
  366. redirectexit();
  367. else
  368. redirectexit('board=' . $board_info['parent'] . '.0');
  369. }
  370. }
  371. }
  372. /**
  373. * Get the id_member associated with the specified message.
  374. * @param int $messageID
  375. * @return int the member id
  376. */
  377. function getMsgMemberID($messageID)
  378. {
  379. global $smcFunc;
  380. // Find the topic and make sure the member still exists.
  381. $result = $smcFunc['db_query']('', '
  382. SELECT IFNULL(mem.id_member, 0)
  383. FROM {db_prefix}messages AS m
  384. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  385. WHERE m.id_msg = {int:selected_message}
  386. LIMIT 1',
  387. array(
  388. 'selected_message' => (int) $messageID,
  389. )
  390. );
  391. if ($smcFunc['db_num_rows']($result) > 0)
  392. list ($memberID) = $smcFunc['db_fetch_row']($result);
  393. // The message doesn't even exist.
  394. else
  395. $memberID = 0;
  396. $smcFunc['db_free_result']($result);
  397. return (int) $memberID;
  398. }
  399. /**
  400. * Modify the settings and position of a board.
  401. * Used by ManageBoards.php to change the settings of a board.
  402. *
  403. * @param int $board_id
  404. * @param array &$boardOptions
  405. */
  406. function modifyBoard($board_id, &$boardOptions)
  407. {
  408. global $cat_tree, $boards, $smcFunc;
  409. // Get some basic information about all boards and categories.
  410. getBoardTree();
  411. // Make sure given boards and categories exist.
  412. if (!isset($boards[$board_id]) || (isset($boardOptions['target_board']) && !isset($boards[$boardOptions['target_board']])) || (isset($boardOptions['target_category']) && !isset($cat_tree[$boardOptions['target_category']])))
  413. fatal_lang_error('no_board');
  414. $id = $board_id;
  415. call_integration_hook('integrate_pre_modify_board', array($id, &$boardOptions));
  416. // All things that will be updated in the database will be in $boardUpdates.
  417. $boardUpdates = array();
  418. $boardUpdateParameters = array();
  419. // In case the board has to be moved
  420. if (isset($boardOptions['move_to']))
  421. {
  422. // Move the board to the top of a given category.
  423. if ($boardOptions['move_to'] == 'top')
  424. {
  425. $id_cat = $boardOptions['target_category'];
  426. $child_level = 0;
  427. $id_parent = 0;
  428. $after = $cat_tree[$id_cat]['last_board_order'];
  429. }
  430. // Move the board to the bottom of a given category.
  431. elseif ($boardOptions['move_to'] == 'bottom')
  432. {
  433. $id_cat = $boardOptions['target_category'];
  434. $child_level = 0;
  435. $id_parent = 0;
  436. $after = 0;
  437. foreach ($cat_tree[$id_cat]['children'] as $id_board => $dummy)
  438. $after = max($after, $boards[$id_board]['order']);
  439. }
  440. // Make the board a child of a given board.
  441. elseif ($boardOptions['move_to'] == 'child')
  442. {
  443. $id_cat = $boards[$boardOptions['target_board']]['category'];
  444. $child_level = $boards[$boardOptions['target_board']]['level'] + 1;
  445. $id_parent = $boardOptions['target_board'];
  446. // People can be creative, in many ways...
  447. if (isChildOf($id_parent, $board_id))
  448. fatal_lang_error('mboards_parent_own_child_error', false);
  449. elseif ($id_parent == $board_id)
  450. fatal_lang_error('mboards_board_own_child_error', false);
  451. $after = $boards[$boardOptions['target_board']]['order'];
  452. // Check if there are already children and (if so) get the max board order.
  453. if (!empty($boards[$id_parent]['tree']['children']) && empty($boardOptions['move_first_child']))
  454. foreach ($boards[$id_parent]['tree']['children'] as $childBoard_id => $dummy)
  455. $after = max($after, $boards[$childBoard_id]['order']);
  456. }
  457. // Place a board before or after another board, on the same child level.
  458. elseif (in_array($boardOptions['move_to'], array('before', 'after')))
  459. {
  460. $id_cat = $boards[$boardOptions['target_board']]['category'];
  461. $child_level = $boards[$boardOptions['target_board']]['level'];
  462. $id_parent = $boards[$boardOptions['target_board']]['parent'];
  463. $after = $boards[$boardOptions['target_board']]['order'] - ($boardOptions['move_to'] == 'before' ? 1 : 0);
  464. }
  465. // Oops...?
  466. else
  467. trigger_error('modifyBoard(): The move_to value \'' . $boardOptions['move_to'] . '\' is incorrect', E_USER_ERROR);
  468. // Get a list of children of this board.
  469. $childList = array();
  470. recursiveBoards($childList, $boards[$board_id]['tree']);
  471. // See if there are changes that affect children.
  472. $childUpdates = array();
  473. $levelDiff = $child_level - $boards[$board_id]['level'];
  474. if ($levelDiff != 0)
  475. $childUpdates[] = 'child_level = child_level ' . ($levelDiff > 0 ? '+ ' : '') . '{int:level_diff}';
  476. if ($id_cat != $boards[$board_id]['category'])
  477. $childUpdates[] = 'id_cat = {int:category}';
  478. // Fix the children of this board.
  479. if (!empty($childList) && !empty($childUpdates))
  480. $smcFunc['db_query']('', '
  481. UPDATE {db_prefix}boards
  482. SET ' . implode(',
  483. ', $childUpdates) . '
  484. WHERE id_board IN ({array_int:board_list})',
  485. array(
  486. 'board_list' => $childList,
  487. 'category' => $id_cat,
  488. 'level_diff' => $levelDiff,
  489. )
  490. );
  491. // Make some room for this spot.
  492. $smcFunc['db_query']('', '
  493. UPDATE {db_prefix}boards
  494. SET board_order = board_order + {int:new_order}
  495. WHERE board_order > {int:insert_after}
  496. AND id_board != {int:selected_board}',
  497. array(
  498. 'insert_after' => $after,
  499. 'selected_board' => $board_id,
  500. 'new_order' => 1 + count($childList),
  501. )
  502. );
  503. $boardUpdates[] = 'id_cat = {int:id_cat}';
  504. $boardUpdates[] = 'id_parent = {int:id_parent}';
  505. $boardUpdates[] = 'child_level = {int:child_level}';
  506. $boardUpdates[] = 'board_order = {int:board_order}';
  507. $boardUpdateParameters += array(
  508. 'id_cat' => $id_cat,
  509. 'id_parent' => $id_parent,
  510. 'child_level' => $child_level,
  511. 'board_order' => $after + 1,
  512. );
  513. }
  514. // This setting is a little twisted in the database...
  515. if (isset($boardOptions['posts_count']))
  516. {
  517. $boardUpdates[] = 'count_posts = {int:count_posts}';
  518. $boardUpdateParameters['count_posts'] = $boardOptions['posts_count'] ? 0 : 1;
  519. }
  520. // Set the theme for this board.
  521. if (isset($boardOptions['board_theme']))
  522. {
  523. $boardUpdates[] = 'id_theme = {int:id_theme}';
  524. $boardUpdateParameters['id_theme'] = (int) $boardOptions['board_theme'];
  525. }
  526. // Should the board theme override the user preferred theme?
  527. if (isset($boardOptions['override_theme']))
  528. {
  529. $boardUpdates[] = 'override_theme = {int:override_theme}';
  530. $boardUpdateParameters['override_theme'] = $boardOptions['override_theme'] ? 1 : 0;
  531. }
  532. // Who's allowed to access this board.
  533. if (isset($boardOptions['access_groups']))
  534. {
  535. $boardUpdates[] = 'member_groups = {string:member_groups}';
  536. $boardUpdateParameters['member_groups'] = implode(',', $boardOptions['access_groups']);
  537. }
  538. // And who isn't.
  539. if (isset($boardOptions['deny_groups']))
  540. {
  541. $boardUpdates[] = 'deny_member_groups = {string:deny_groups}';
  542. $boardUpdateParameters['deny_groups'] = implode(',', $boardOptions['deny_groups']);
  543. }
  544. if (isset($boardOptions['board_name']))
  545. {
  546. $boardUpdates[] = 'name = {string:board_name}';
  547. $boardUpdateParameters['board_name'] = $boardOptions['board_name'];
  548. }
  549. if (isset($boardOptions['board_description']))
  550. {
  551. $boardUpdates[] = 'description = {string:board_description}';
  552. $boardUpdateParameters['board_description'] = $boardOptions['board_description'];
  553. }
  554. if (isset($boardOptions['profile']))
  555. {
  556. $boardUpdates[] = 'id_profile = {int:profile}';
  557. $boardUpdateParameters['profile'] = (int) $boardOptions['profile'];
  558. }
  559. if (isset($boardOptions['redirect']))
  560. {
  561. $boardUpdates[] = 'redirect = {string:redirect}';
  562. $boardUpdateParameters['redirect'] = $boardOptions['redirect'];
  563. }
  564. if (isset($boardOptions['num_posts']))
  565. {
  566. $boardUpdates[] = 'num_posts = {int:num_posts}';
  567. $boardUpdateParameters['num_posts'] = (int) $boardOptions['num_posts'];
  568. }
  569. $id = $board_id;
  570. call_integration_hook('integrate_modify_board', array($id, &$boardUpdates, &$boardUpdateParameters));
  571. // Do the updates (if any).
  572. if (!empty($boardUpdates))
  573. $request = $smcFunc['db_query']('', '
  574. UPDATE {db_prefix}boards
  575. SET
  576. ' . implode(',
  577. ', $boardUpdates) . '
  578. WHERE id_board = {int:selected_board}',
  579. array_merge($boardUpdateParameters, array(
  580. 'selected_board' => $board_id,
  581. ))
  582. );
  583. // Set moderators of this board.
  584. if (isset($boardOptions['moderators']) || isset($boardOptions['moderator_string']) || isset($boardOptions['moderator_groups']) || isset($boardOptions['moderator_group_string']))
  585. {
  586. // Reset current moderators for this board - if there are any!
  587. $smcFunc['db_query']('', '
  588. DELETE FROM {db_prefix}moderators
  589. WHERE id_board = {int:board_list}',
  590. array(
  591. 'board_list' => $board_id,
  592. )
  593. );
  594. // Validate and get the IDs of the new moderators.
  595. if (isset($boardOptions['moderator_string']) && trim($boardOptions['moderator_string']) != '')
  596. {
  597. // Divvy out the usernames, remove extra space.
  598. $moderator_string = strtr($smcFunc['htmlspecialchars']($boardOptions['moderator_string'], ENT_QUOTES), array('&quot;' => '"'));
  599. preg_match_all('~"([^"]+)"~', $moderator_string, $matches);
  600. $moderators = array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $moderator_string)));
  601. for ($k = 0, $n = count($moderators); $k < $n; $k++)
  602. {
  603. $moderators[$k] = trim($moderators[$k]);
  604. if (strlen($moderators[$k]) == 0)
  605. unset($moderators[$k]);
  606. }
  607. // Find all the id_member's for the member_name's in the list.
  608. if (empty($boardOptions['moderators']))
  609. $boardOptions['moderators'] = array();
  610. if (!empty($moderators))
  611. {
  612. $request = $smcFunc['db_query']('', '
  613. SELECT id_member
  614. FROM {db_prefix}members
  615. WHERE member_name IN ({array_string:moderator_list}) OR real_name IN ({array_string:moderator_list})
  616. LIMIT ' . count($moderators),
  617. array(
  618. 'moderator_list' => $moderators,
  619. )
  620. );
  621. while ($row = $smcFunc['db_fetch_assoc']($request))
  622. $boardOptions['moderators'][] = $row['id_member'];
  623. $smcFunc['db_free_result']($request);
  624. }
  625. }
  626. // Add the moderators to the board.
  627. if (!empty($boardOptions['moderators']))
  628. {
  629. $inserts = array();
  630. foreach ($boardOptions['moderators'] as $moderator)
  631. $inserts[] = array($board_id, $moderator);
  632. $smcFunc['db_insert']('insert',
  633. '{db_prefix}moderators',
  634. array('id_board' => 'int', 'id_member' => 'int'),
  635. $inserts,
  636. array('id_board', 'id_member')
  637. );
  638. }
  639. // Reset current moderator groups for this board - if there are any!
  640. $smcFunc['db_query']('', '
  641. DELETE FROM {db_prefix}moderator_groups
  642. WHERE id_board = {int:board_list}',
  643. array(
  644. 'board_list' => $board_id,
  645. )
  646. );
  647. // Validate and get the IDs of the new moderator groups.
  648. if (isset($boardOptions['moderator_group_string']) && trim($boardOptions['moderator_group_string']) != '')
  649. {
  650. // Divvy out the group names, remove extra space.
  651. $moderator_group_string = strtr($smcFunc['htmlspecialchars']($boardOptions['moderator_group_string'], ENT_QUOTES), array('&quot;' => '"'));
  652. preg_match_all('~"([^"]+)"~', $moderator_group_string, $matches);
  653. $moderator_groups = array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $moderator_group_string)));
  654. for ($k = 0, $n = count($moderator_groups); $k < $n; $k++)
  655. {
  656. $moderator_groups[$k] = trim($moderator_groups[$k]);
  657. if (strlen($moderator_groups[$k]) == 0)
  658. unset($moderator_groups[$k]);
  659. }
  660. /* Find all the id_group's for all the group names in the list
  661. But skip any invalid ones (invisible/post groups/Administrator/Moderator) */
  662. if (empty($boardOptions['moderator_groups']))
  663. $boardOptions['moderator_groups'] = array();
  664. if (!empty($moderator_groups))
  665. {
  666. $request = $smcFunc['db_query']('', '
  667. SELECT id_group
  668. FROM {db_prefix}membergroups
  669. WHERE group_name IN ({array_string:moderator_group_list})
  670. AND hidden = {int:visible}
  671. AND min_posts = {int:negative_one}
  672. AND id_group NOT IN ({array_int:invalid_groups})
  673. LIMIT ' . count($moderator_groups),
  674. array(
  675. 'visible' => 0,
  676. 'negative_one' => -1,
  677. 'invalid_groups' => array(1,3),
  678. 'moderator_group_list' => $moderator_groups,
  679. )
  680. );
  681. while ($row = $smcFunc['db_fetch_assoc']($request))
  682. {
  683. $boardOptions['moderator_groups'][] = $row['id_group'];
  684. }
  685. $smcFunc['db_free_result']($request);
  686. }
  687. }
  688. // Add the moderator groups to the board.
  689. if (!empty($boardOptions['moderator_groups']))
  690. {
  691. $inserts = array();
  692. foreach ($boardOptions['moderator_groups'] as $moderator_group)
  693. $inserts[] = array($board_id, $moderator_group);
  694. $smcFunc['db_insert']('insert',
  695. '{db_prefix}moderator_groups',
  696. array('id_board' => 'int', 'id_group' => 'int'),
  697. $inserts,
  698. array('id_board', 'id_group')
  699. );
  700. }
  701. // Note that caches can now be wrong!
  702. updateSettings(array('settings_updated' => time()));
  703. }
  704. if (isset($boardOptions['move_to']))
  705. reorderBoards();
  706. clean_cache('data');
  707. if (empty($boardOptions['dont_log']))
  708. logAction('edit_board', array('board' => $board_id), 'admin');
  709. }
  710. /**
  711. * Create a new board and set its properties and position.
  712. * Allows (almost) the same options as the modifyBoard() function.
  713. * With the option inherit_permissions set, the parent board permissions
  714. * will be inherited.
  715. *
  716. * @param array $boardOptions
  717. * @return int The new board id
  718. */
  719. function createBoard($boardOptions)
  720. {
  721. global $boards, $smcFunc;
  722. // Trigger an error if one of the required values is not set.
  723. if (!isset($boardOptions['board_name']) || trim($boardOptions['board_name']) == '' || !isset($boardOptions['move_to']) || !isset($boardOptions['target_category']))
  724. trigger_error('createBoard(): One or more of the required options is not set', E_USER_ERROR);
  725. if (in_array($boardOptions['move_to'], array('child', 'before', 'after')) && !isset($boardOptions['target_board']))
  726. trigger_error('createBoard(): Target board is not set', E_USER_ERROR);
  727. // Set every optional value to its default value.
  728. $boardOptions += array(
  729. 'posts_count' => true,
  730. 'override_theme' => false,
  731. 'board_theme' => 0,
  732. 'access_groups' => array(),
  733. 'board_description' => '',
  734. 'profile' => 1,
  735. 'moderators' => '',
  736. 'inherit_permissions' => true,
  737. 'dont_log' => true,
  738. );
  739. $board_columns = array(
  740. 'id_cat' => 'int', 'name' => 'string-255', 'description' => 'string', 'board_order' => 'int',
  741. 'member_groups' => 'string', 'redirect' => 'string',
  742. );
  743. $board_parameters = array(
  744. $boardOptions['target_category'], $boardOptions['board_name'] , '', 0,
  745. '-1,0', '',
  746. );
  747. call_integration_hook('integrate_create_board', array(&$boardOptions, &$board_columns, &$board_parameters));
  748. // Insert a board, the settings are dealt with later.
  749. $smcFunc['db_insert']('',
  750. '{db_prefix}boards',
  751. $board_columns,
  752. $board_parameters,
  753. array('id_board')
  754. );
  755. $board_id = $smcFunc['db_insert_id']('{db_prefix}boards', 'id_board');
  756. if (empty($board_id))
  757. return 0;
  758. // Change the board according to the given specifications.
  759. modifyBoard($board_id, $boardOptions);
  760. // Do we want the parent permissions to be inherited?
  761. if ($boardOptions['inherit_permissions'])
  762. {
  763. getBoardTree();
  764. if (!empty($boards[$board_id]['parent']))
  765. {
  766. $request = $smcFunc['db_query']('', '
  767. SELECT id_profile
  768. FROM {db_prefix}boards
  769. WHERE id_board = {int:board_parent}
  770. LIMIT 1',
  771. array(
  772. 'board_parent' => (int) $boards[$board_id]['parent'],
  773. )
  774. );
  775. list ($boardOptions['profile']) = $smcFunc['db_fetch_row']($request);
  776. $smcFunc['db_free_result']($request);
  777. $smcFunc['db_query']('', '
  778. UPDATE {db_prefix}boards
  779. SET id_profile = {int:new_profile}
  780. WHERE id_board = {int:current_board}',
  781. array(
  782. 'new_profile' => $boardOptions['profile'],
  783. 'current_board' => $board_id,
  784. )
  785. );
  786. }
  787. }
  788. // Clean the data cache.
  789. clean_cache('data');
  790. // Created it.
  791. logAction('add_board', array('board' => $board_id), 'admin');
  792. // Here you are, a new board, ready to be spammed.
  793. return $board_id;
  794. }
  795. /**
  796. * Remove one or more boards.
  797. * Allows to move the children of the board before deleting it
  798. * if moveChildrenTo is set to null, the child boards will be deleted.
  799. * Deletes:
  800. * - all topics that are on the given boards;
  801. * - all information that's associated with the given boards;
  802. * updates the statistics to reflect the new situation.
  803. *
  804. * @param array $boards_to_remove
  805. * @param array $moveChildrenTo = null
  806. */
  807. function deleteBoards($boards_to_remove, $moveChildrenTo = null)
  808. {
  809. global $sourcedir, $boards, $smcFunc;
  810. // No boards to delete? Return!
  811. if (empty($boards_to_remove))
  812. return;
  813. getBoardTree();
  814. call_integration_hook('integrate_delete_board', array($boards_to_remove, &$moveChildrenTo));
  815. // If $moveChildrenTo is set to null, include the children in the removal.
  816. if ($moveChildrenTo === null)
  817. {
  818. // Get a list of the child boards that will also be removed.
  819. $child_boards_to_remove = array();
  820. foreach ($boards_to_remove as $board_to_remove)
  821. recursiveBoards($child_boards_to_remove, $boards[$board_to_remove]['tree']);
  822. // Merge the children with their parents.
  823. if (!empty($child_boards_to_remove))
  824. $boards_to_remove = array_unique(array_merge($boards_to_remove, $child_boards_to_remove));
  825. }
  826. // Move the children to a safe home.
  827. else
  828. {
  829. foreach ($boards_to_remove as $id_board)
  830. {
  831. // @todo Separate category?
  832. if ($moveChildrenTo === 0)
  833. fixChildren($id_board, 0, 0);
  834. else
  835. fixChildren($id_board, $boards[$moveChildrenTo]['level'] + 1, $moveChildrenTo);
  836. }
  837. }
  838. // Delete ALL topics in the selected boards (done first so topics can't be marooned.)
  839. $request = $smcFunc['db_query']('', '
  840. SELECT id_topic
  841. FROM {db_prefix}topics
  842. WHERE id_board IN ({array_int:boards_to_remove})',
  843. array(
  844. 'boards_to_remove' => $boards_to_remove,
  845. )
  846. );
  847. $topics = array();
  848. while ($row = $smcFunc['db_fetch_assoc']($request))
  849. $topics[] = $row['id_topic'];
  850. $smcFunc['db_free_result']($request);
  851. require_once($sourcedir . '/RemoveTopic.php');
  852. removeTopics($topics, false);
  853. // Delete the board's logs.
  854. $smcFunc['db_query']('', '
  855. DELETE FROM {db_prefix}log_mark_read
  856. WHERE id_board IN ({array_int:boards_to_remove})',
  857. array(
  858. 'boards_to_remove' => $boards_to_remove,
  859. )
  860. );
  861. $smcFunc['db_query']('', '
  862. DELETE FROM {db_prefix}log_boards
  863. WHERE id_board IN ({array_int:boards_to_remove})',
  864. array(
  865. 'boards_to_remove' => $boards_to_remove,
  866. )
  867. );
  868. $smcFunc['db_query']('', '
  869. DELETE FROM {db_prefix}log_notify
  870. WHERE id_board IN ({array_int:boards_to_remove})',
  871. array(
  872. 'boards_to_remove' => $boards_to_remove,
  873. )
  874. );
  875. // Delete this board's moderators.
  876. $smcFunc['db_query']('', '
  877. DELETE FROM {db_prefix}moderators
  878. WHERE id_board IN ({array_int:boards_to_remove})',
  879. array(
  880. 'boards_to_remove' => $boards_to_remove,
  881. )
  882. );
  883. // Delete this board's moderator groups.
  884. $smcFunc['db_query']('', '
  885. DELETE FROM {db_prefix}moderator_groups
  886. WHERE id_board IN ({array_int:boards_to_remove})',
  887. array(
  888. 'boards_to_remove' => $boards_to_remove,
  889. )
  890. );
  891. // Delete any extra events in the calendar.
  892. $smcFunc['db_query']('', '
  893. DELETE FROM {db_prefix}calendar
  894. WHERE id_board IN ({array_int:boards_to_remove})',
  895. array(
  896. 'boards_to_remove' => $boards_to_remove,
  897. )
  898. );
  899. // Delete any message icons that only appear on these boards.
  900. $smcFunc['db_query']('', '
  901. DELETE FROM {db_prefix}message_icons
  902. WHERE id_board IN ({array_int:boards_to_remove})',
  903. array(
  904. 'boards_to_remove' => $boards_to_remove,
  905. )
  906. );
  907. // Delete the boards.
  908. $smcFunc['db_query']('', '
  909. DELETE FROM {db_prefix}boards
  910. WHERE id_board IN ({array_int:boards_to_remove})',
  911. array(
  912. 'boards_to_remove' => $boards_to_remove,
  913. )
  914. );
  915. // Latest message/topic might not be there anymore.
  916. updateStats('message');
  917. updateStats('topic');
  918. updateSettings(array(
  919. 'calendar_updated' => time(),
  920. ));
  921. // Plus reset the cache to stop people getting odd results.
  922. updateSettings(array('settings_updated' => time()));
  923. // Clean the cache as well.
  924. clean_cache('data');
  925. // Let's do some serious logging.
  926. foreach ($boards_to_remove as $id_board)
  927. logAction('delete_board', array('boardname' => $boards[$id_board]['name']), 'admin');
  928. reorderBoards();
  929. }
  930. /**
  931. * Put all boards in the right order and sorts the records of the boards table.
  932. * Used by modifyBoard(), deleteBoards(), modifyCategory(), and deleteCategories() functions
  933. */
  934. function reorderBoards()
  935. {
  936. global $cat_tree, $boardList, $boards, $smcFunc;
  937. getBoardTree();
  938. // Set the board order for each category.
  939. $board_order = 0;
  940. foreach ($cat_tree as $catID => $dummy)
  941. {
  942. foreach ($boardList[$catID] as $boardID)
  943. if ($boards[$boardID]['order'] != ++$board_order)
  944. $smcFunc['db_query']('', '
  945. UPDATE {db_prefix}boards
  946. SET board_order = {int:new_order}
  947. WHERE id_board = {int:selected_board}',
  948. array(
  949. 'new_order' => $board_order,
  950. 'selected_board' => $boardID,
  951. )
  952. );
  953. }
  954. // Sort the records of the boards table on the board_order value.
  955. $smcFunc['db_query']('alter_table_boards', '
  956. ALTER TABLE {db_prefix}boards
  957. ORDER BY board_order',
  958. array(
  959. 'db_error_skip' => true,
  960. )
  961. );
  962. }
  963. /**
  964. * Fixes the children of a board by setting their child_levels to new values.
  965. * Used when a board is deleted or moved, to affect its children.
  966. *
  967. * @param int $parent
  968. * @param int $newLevel
  969. * @param int $newParent
  970. */
  971. function fixChildren($parent, $newLevel, $newParent)
  972. {
  973. global $smcFunc;
  974. // Grab all children of $parent...
  975. $result = $smcFunc['db_query']('', '
  976. SELECT id_board
  977. FROM {db_prefix}boards
  978. WHERE id_parent = {int:parent_board}',
  979. array(
  980. 'parent_board' => $parent,
  981. )
  982. );
  983. $children = array();
  984. while ($row = $smcFunc['db_fetch_assoc']($result))
  985. $children[] = $row['id_board'];
  986. $smcFunc['db_free_result']($result);
  987. // ...and set it to a new parent and child_level.
  988. $smcFunc['db_query']('', '
  989. UPDATE {db_prefix}boards
  990. SET id_parent = {int:new_parent}, child_level = {int:new_child_level}
  991. WHERE id_parent = {int:parent_board}',
  992. array(
  993. 'new_parent' => $newParent,
  994. 'new_child_level' => $newLevel,
  995. 'parent_board' => $parent,
  996. )
  997. );
  998. // Recursively fix the children of the children.
  999. foreach ($children as $child)
  1000. fixChildren($child, $newLevel + 1, $child);
  1001. }
  1002. /**
  1003. * Load a lot of useful information regarding the boards and categories.
  1004. * The information retrieved is stored in globals:
  1005. * $boards properties of each board.
  1006. * $boardList a list of boards grouped by category ID.
  1007. * $cat_tree properties of each category.
  1008. */
  1009. function getBoardTree()
  1010. {
  1011. global $cat_tree, $boards, $boardList, $smcFunc;
  1012. // Getting all the board and category information you'd ever wanted.
  1013. $request = $smcFunc['db_query']('', '
  1014. SELECT
  1015. IFNULL(b.id_board, 0) AS id_board, b.id_parent, b.name AS board_name, b.description, b.child_level,
  1016. b.board_order, b.count_posts, b.member_groups, b.id_theme, b.override_theme, b.id_profile, b.redirect,
  1017. b.num_posts, b.num_topics, b.deny_member_groups, c.id_cat, c.name AS cat_name, c.description AS cat_desc, c.cat_order, c.can_collapse
  1018. FROM {db_prefix}categories AS c
  1019. LEFT JOIN {db_prefix}boards AS b ON (b.id_cat = c.id_cat)
  1020. ORDER BY c.cat_order, b.child_level, b.board_order',
  1021. array(
  1022. )
  1023. );
  1024. $cat_tree = array();
  1025. $boards = array();
  1026. $last_board_order = 0;
  1027. while ($row = $smcFunc['db_fetch_assoc']($request))
  1028. {
  1029. if (!isset($cat_tree[$row['id_cat']]))
  1030. {
  1031. $cat_tree[$row['id_cat']] = array(
  1032. 'node' => array(
  1033. 'id' => $row['id_cat'],
  1034. 'name' => $row['cat_name'],
  1035. 'description' => $row['cat_desc'],
  1036. 'order' => $row['cat_order'],
  1037. 'can_collapse' => $row['can_collapse']
  1038. ),
  1039. 'is_first' => empty($cat_tree),
  1040. 'last_board_order' => $last_board_order,
  1041. 'children' => array()
  1042. );
  1043. $prevBoard = 0;
  1044. $curLevel = 0;
  1045. }
  1046. if (!empty($row['id_board']))
  1047. {
  1048. if ($row['child_level'] != $curLevel)
  1049. $prevBoard = 0;
  1050. $boards[$row['id_board']] = array(
  1051. 'id' => $row['id_board'],
  1052. 'category' => $row['id_cat'],
  1053. 'parent' => $row['id_parent'],
  1054. 'level' => $row['child_level'],
  1055. 'order' => $row['board_order'],
  1056. 'name' => $row['board_name'],
  1057. 'member_groups' => explode(',', $row['member_groups']),
  1058. 'deny_groups' => explode(',', $row['deny_member_groups']),
  1059. 'description' => $row['description'],
  1060. 'count_posts' => empty($row['count_posts']),
  1061. 'posts' => $row['num_posts'],
  1062. 'topics' => $row['num_topics'],
  1063. 'theme' => $row['id_theme'],
  1064. 'override_theme' => $row['override_theme'],
  1065. 'profile' => $row['id_profile'],
  1066. 'redirect' => $row['redirect'],
  1067. 'prev_board' => $prevBoard
  1068. );
  1069. $prevBoard = $row['id_board'];
  1070. $last_board_order = $row['board_order'];
  1071. if (empty($row['child_level']))
  1072. {
  1073. $cat_tree[$row['id_cat']]['children'][$row['id_board']] = array(
  1074. 'node' => &$boards[$row['id_board']],
  1075. 'is_first' => empty($cat_tree[$row['id_cat']]['children']),
  1076. 'children' => array()
  1077. );
  1078. $boards[$row['id_board']]['tree'] = &$cat_tree[$row['id_cat']]['children'][$row['id_board']];
  1079. }
  1080. else
  1081. {
  1082. // Parent doesn't exist!
  1083. if (!isset($boards[$row['id_parent']]['tree']))
  1084. fatal_lang_error('no_valid_parent', false, array($row['board_name']));
  1085. // Wrong childlevel...we can silently fix this...
  1086. if ($boards[$row['id_parent']]['tree']['node']['level'] != $row['child_level'] - 1)
  1087. $smcFunc['db_query']('', '
  1088. UPDATE {db_prefix}boards
  1089. SET child_level = {int:new_child_level}
  1090. WHERE id_board = {int:selected_board}',
  1091. array(
  1092. 'new_child_level' => $boards[$row['id_parent']]['tree']['node']['level'] + 1,
  1093. 'selected_board' => $row['id_board'],
  1094. )
  1095. );
  1096. $boards[$row['id_parent']]['tree']['children'][$row['id_board']] = array(
  1097. 'node' => &$boards[$row['id_board']],
  1098. 'is_first' => empty($boards[$row['id_parent']]['tree']['children']),
  1099. 'children' => array()
  1100. );
  1101. $boards[$row['id_board']]['tree'] = &$boards[$row['id_parent']]['tree']['children'][$row['id_board']];
  1102. }
  1103. }
  1104. }
  1105. $smcFunc['db_free_result']($request);
  1106. // Get a list of all the boards in each category (using recursion).
  1107. $boardList = array();
  1108. foreach ($cat_tree as $catID => $node)
  1109. {
  1110. $boardList[$catID] = array();
  1111. recursiveBoards($boardList[$catID], $node);
  1112. }
  1113. }
  1114. /**
  1115. * Recursively get a list of boards.
  1116. * Used by getBoardTree
  1117. *
  1118. * @param array &$_boardList
  1119. * @param array &$_tree
  1120. */
  1121. function recursiveBoards(&$_boardList, &$_tree)
  1122. {
  1123. if (empty($_tree['children']))
  1124. return;
  1125. foreach ($_tree['children'] as $id => $node)
  1126. {
  1127. $_boardList[] = $id;
  1128. recursiveBoards($_boardList, $node);
  1129. }
  1130. }
  1131. /**
  1132. * Returns whether the child board id is actually a child of the parent (recursive).
  1133. * @param int $child
  1134. * @param int $parent
  1135. * @return boolean
  1136. */
  1137. function isChildOf($child, $parent)
  1138. {
  1139. global $boards;
  1140. if (empty($boards[$child]['parent']))
  1141. return false;
  1142. if ($boards[$child]['parent'] == $parent)
  1143. return true;
  1144. return isChildOf($boards[$child]['parent'], $parent);
  1145. }
  1146. ?>