Subs-Boards.php 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289
  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 2013 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.disregarded != 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 boards are integers!
  159. $topics = array_map('intval', explode('-', $_REQUEST['topics']));
  160. $smcFunc['db_query']('', '
  161. SELECT id_topic, disregarded
  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['disregarded'];
  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', 'disregarded' => '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.disregarded, 0) as disregarded
  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', 'disregarded' => 'int'),
  254. array($earlyMsg, $user_info['id'], $topic, $topicinfo['disregarded']),
  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 $sourcedir, $cat_tree, $boards, $boardList, $modSettings, $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. if (empty($boardOptions['moderator_groups']))
  662. $boardOptions['moderator_groups'] = array();
  663. if (!empty($moderator_groups))
  664. {
  665. $request = $smcFunc['db_query']('', '
  666. SELECT id_group, min_posts
  667. FROM {db_prefix}membergroups
  668. WHERE group_name IN ({array_string:moderator_group_list})
  669. LIMIT ' . count($moderator_groups),
  670. array(
  671. 'moderator_group_list' => $moderator_groups,
  672. )
  673. );
  674. while ($row = $smcFunc['db_fetch_assoc']($request))
  675. {
  676. // Don't allow post groups, "Administrator" or "Moderator"
  677. if ($row['min_posts'] != -1 || in_array($row['id_group'], array(1,3)))
  678. continue;
  679. $boardOptions['moderator_groups'][] = $row['id_group'];
  680. }
  681. $smcFunc['db_free_result']($request);
  682. }
  683. }
  684. // Add the moderator groups to the board.
  685. if (!empty($boardOptions['moderator_groups']))
  686. {
  687. $inserts = array();
  688. foreach ($boardOptions['moderator_groups'] as $moderator_group)
  689. $inserts[] = array($board_id, $moderator_group);
  690. $smcFunc['db_insert']('insert',
  691. '{db_prefix}moderator_groups',
  692. array('id_board' => 'int', 'id_group' => 'int'),
  693. $inserts,
  694. array('id_board', 'id_group')
  695. );
  696. }
  697. // Note that caches can now be wrong!
  698. updateSettings(array('settings_updated' => time()));
  699. }
  700. if (isset($boardOptions['move_to']))
  701. reorderBoards();
  702. clean_cache('data');
  703. if (empty($boardOptions['dont_log']))
  704. logAction('edit_board', array('board' => $board_id), 'admin');
  705. }
  706. /**
  707. * Create a new board and set its properties and position.
  708. * Allows (almost) the same options as the modifyBoard() function.
  709. * With the option inherit_permissions set, the parent board permissions
  710. * will be inherited.
  711. *
  712. * @param array $boardOptions
  713. * @return int The new board id
  714. */
  715. function createBoard($boardOptions)
  716. {
  717. global $boards, $modSettings, $smcFunc;
  718. // Trigger an error if one of the required values is not set.
  719. if (!isset($boardOptions['board_name']) || trim($boardOptions['board_name']) == '' || !isset($boardOptions['move_to']) || !isset($boardOptions['target_category']))
  720. trigger_error('createBoard(): One or more of the required options is not set', E_USER_ERROR);
  721. if (in_array($boardOptions['move_to'], array('child', 'before', 'after')) && !isset($boardOptions['target_board']))
  722. trigger_error('createBoard(): Target board is not set', E_USER_ERROR);
  723. // Set every optional value to its default value.
  724. $boardOptions += array(
  725. 'posts_count' => true,
  726. 'override_theme' => false,
  727. 'board_theme' => 0,
  728. 'access_groups' => array(),
  729. 'board_description' => '',
  730. 'profile' => 1,
  731. 'moderators' => '',
  732. 'inherit_permissions' => true,
  733. 'dont_log' => true,
  734. );
  735. $board_columns = array(
  736. 'id_cat' => 'int', 'name' => 'string-255', 'description' => 'string', 'board_order' => 'int',
  737. 'member_groups' => 'string', 'redirect' => 'string',
  738. );
  739. $board_parameters = array(
  740. $boardOptions['target_category'], $boardOptions['board_name'] , '', 0,
  741. '-1,0', '',
  742. );
  743. call_integration_hook('integrate_create_board', array(&$boardOptions, &$board_columns, &$board_parameters));
  744. // Insert a board, the settings are dealt with later.
  745. $smcFunc['db_insert']('',
  746. '{db_prefix}boards',
  747. $board_columns,
  748. $board_parameters,
  749. array('id_board')
  750. );
  751. $board_id = $smcFunc['db_insert_id']('{db_prefix}boards', 'id_board');
  752. if (empty($board_id))
  753. return 0;
  754. // Change the board according to the given specifications.
  755. modifyBoard($board_id, $boardOptions);
  756. // Do we want the parent permissions to be inherited?
  757. if ($boardOptions['inherit_permissions'])
  758. {
  759. getBoardTree();
  760. if (!empty($boards[$board_id]['parent']))
  761. {
  762. $request = $smcFunc['db_query']('', '
  763. SELECT id_profile
  764. FROM {db_prefix}boards
  765. WHERE id_board = {int:board_parent}
  766. LIMIT 1',
  767. array(
  768. 'board_parent' => (int) $boards[$board_id]['parent'],
  769. )
  770. );
  771. list ($boardOptions['profile']) = $smcFunc['db_fetch_row']($request);
  772. $smcFunc['db_free_result']($request);
  773. $smcFunc['db_query']('', '
  774. UPDATE {db_prefix}boards
  775. SET id_profile = {int:new_profile}
  776. WHERE id_board = {int:current_board}',
  777. array(
  778. 'new_profile' => $boardOptions['profile'],
  779. 'current_board' => $board_id,
  780. )
  781. );
  782. }
  783. }
  784. // Clean the data cache.
  785. clean_cache('data');
  786. // Created it.
  787. logAction('add_board', array('board' => $board_id), 'admin');
  788. // Here you are, a new board, ready to be spammed.
  789. return $board_id;
  790. }
  791. /**
  792. * Remove one or more boards.
  793. * Allows to move the children of the board before deleting it
  794. * if moveChildrenTo is set to null, the child boards will be deleted.
  795. * Deletes:
  796. * - all topics that are on the given boards;
  797. * - all information that's associated with the given boards;
  798. * updates the statistics to reflect the new situation.
  799. *
  800. * @param array $boards_to_remove
  801. * @param array $moveChildrenTo = null
  802. */
  803. function deleteBoards($boards_to_remove, $moveChildrenTo = null)
  804. {
  805. global $sourcedir, $boards, $smcFunc;
  806. // No boards to delete? Return!
  807. if (empty($boards_to_remove))
  808. return;
  809. getBoardTree();
  810. call_integration_hook('integrate_delete_board', array($boards_to_remove, &$moveChildrenTo));
  811. // If $moveChildrenTo is set to null, include the children in the removal.
  812. if ($moveChildrenTo === null)
  813. {
  814. // Get a list of the child boards that will also be removed.
  815. $child_boards_to_remove = array();
  816. foreach ($boards_to_remove as $board_to_remove)
  817. recursiveBoards($child_boards_to_remove, $boards[$board_to_remove]['tree']);
  818. // Merge the children with their parents.
  819. if (!empty($child_boards_to_remove))
  820. $boards_to_remove = array_unique(array_merge($boards_to_remove, $child_boards_to_remove));
  821. }
  822. // Move the children to a safe home.
  823. else
  824. {
  825. foreach ($boards_to_remove as $id_board)
  826. {
  827. // @todo Separate category?
  828. if ($moveChildrenTo === 0)
  829. fixChildren($id_board, 0, 0);
  830. else
  831. fixChildren($id_board, $boards[$moveChildrenTo]['level'] + 1, $moveChildrenTo);
  832. }
  833. }
  834. // Delete ALL topics in the selected boards (done first so topics can't be marooned.)
  835. $request = $smcFunc['db_query']('', '
  836. SELECT id_topic
  837. FROM {db_prefix}topics
  838. WHERE id_board IN ({array_int:boards_to_remove})',
  839. array(
  840. 'boards_to_remove' => $boards_to_remove,
  841. )
  842. );
  843. $topics = array();
  844. while ($row = $smcFunc['db_fetch_assoc']($request))
  845. $topics[] = $row['id_topic'];
  846. $smcFunc['db_free_result']($request);
  847. require_once($sourcedir . '/RemoveTopic.php');
  848. removeTopics($topics, false);
  849. // Delete the board's logs.
  850. $smcFunc['db_query']('', '
  851. DELETE FROM {db_prefix}log_mark_read
  852. WHERE id_board IN ({array_int:boards_to_remove})',
  853. array(
  854. 'boards_to_remove' => $boards_to_remove,
  855. )
  856. );
  857. $smcFunc['db_query']('', '
  858. DELETE FROM {db_prefix}log_boards
  859. WHERE id_board IN ({array_int:boards_to_remove})',
  860. array(
  861. 'boards_to_remove' => $boards_to_remove,
  862. )
  863. );
  864. $smcFunc['db_query']('', '
  865. DELETE FROM {db_prefix}log_notify
  866. WHERE id_board IN ({array_int:boards_to_remove})',
  867. array(
  868. 'boards_to_remove' => $boards_to_remove,
  869. )
  870. );
  871. // Delete this board's moderators.
  872. $smcFunc['db_query']('', '
  873. DELETE FROM {db_prefix}moderators
  874. WHERE id_board IN ({array_int:boards_to_remove})',
  875. array(
  876. 'boards_to_remove' => $boards_to_remove,
  877. )
  878. );
  879. // Delete this board's moderator groups.
  880. $smcFunc['db_query']('', '
  881. DELETE FROM {db_prefix}moderator_groups
  882. WHERE id_board IN ({array_int:boards_to_remove})',
  883. array(
  884. 'boards_to_remove' => $boards_to_remove,
  885. )
  886. );
  887. // Delete any extra events in the calendar.
  888. $smcFunc['db_query']('', '
  889. DELETE FROM {db_prefix}calendar
  890. WHERE id_board IN ({array_int:boards_to_remove})',
  891. array(
  892. 'boards_to_remove' => $boards_to_remove,
  893. )
  894. );
  895. // Delete any message icons that only appear on these boards.
  896. $smcFunc['db_query']('', '
  897. DELETE FROM {db_prefix}message_icons
  898. WHERE id_board IN ({array_int:boards_to_remove})',
  899. array(
  900. 'boards_to_remove' => $boards_to_remove,
  901. )
  902. );
  903. // Delete the boards.
  904. $smcFunc['db_query']('', '
  905. DELETE FROM {db_prefix}boards
  906. WHERE id_board IN ({array_int:boards_to_remove})',
  907. array(
  908. 'boards_to_remove' => $boards_to_remove,
  909. )
  910. );
  911. // Latest message/topic might not be there anymore.
  912. updateStats('message');
  913. updateStats('topic');
  914. updateSettings(array(
  915. 'calendar_updated' => time(),
  916. ));
  917. // Plus reset the cache to stop people getting odd results.
  918. updateSettings(array('settings_updated' => time()));
  919. // Clean the cache as well.
  920. clean_cache('data');
  921. // Let's do some serious logging.
  922. foreach ($boards_to_remove as $id_board)
  923. logAction('delete_board', array('boardname' => $boards[$id_board]['name']), 'admin');
  924. reorderBoards();
  925. }
  926. /**
  927. * Put all boards in the right order and sorts the records of the boards table.
  928. * Used by modifyBoard(), deleteBoards(), modifyCategory(), and deleteCategories() functions
  929. */
  930. function reorderBoards()
  931. {
  932. global $cat_tree, $boardList, $boards, $smcFunc;
  933. getBoardTree();
  934. // Set the board order for each category.
  935. $board_order = 0;
  936. foreach ($cat_tree as $catID => $dummy)
  937. {
  938. foreach ($boardList[$catID] as $boardID)
  939. if ($boards[$boardID]['order'] != ++$board_order)
  940. $smcFunc['db_query']('', '
  941. UPDATE {db_prefix}boards
  942. SET board_order = {int:new_order}
  943. WHERE id_board = {int:selected_board}',
  944. array(
  945. 'new_order' => $board_order,
  946. 'selected_board' => $boardID,
  947. )
  948. );
  949. }
  950. // Sort the records of the boards table on the board_order value.
  951. $smcFunc['db_query']('alter_table_boards', '
  952. ALTER TABLE {db_prefix}boards
  953. ORDER BY board_order',
  954. array(
  955. 'db_error_skip' => true,
  956. )
  957. );
  958. }
  959. /**
  960. * Fixes the children of a board by setting their child_levels to new values.
  961. * Used when a board is deleted or moved, to affect its children.
  962. *
  963. * @param int $parent
  964. * @param int $newLevel
  965. * @param int $newParent
  966. */
  967. function fixChildren($parent, $newLevel, $newParent)
  968. {
  969. global $smcFunc;
  970. // Grab all children of $parent...
  971. $result = $smcFunc['db_query']('', '
  972. SELECT id_board
  973. FROM {db_prefix}boards
  974. WHERE id_parent = {int:parent_board}',
  975. array(
  976. 'parent_board' => $parent,
  977. )
  978. );
  979. $children = array();
  980. while ($row = $smcFunc['db_fetch_assoc']($result))
  981. $children[] = $row['id_board'];
  982. $smcFunc['db_free_result']($result);
  983. // ...and set it to a new parent and child_level.
  984. $smcFunc['db_query']('', '
  985. UPDATE {db_prefix}boards
  986. SET id_parent = {int:new_parent}, child_level = {int:new_child_level}
  987. WHERE id_parent = {int:parent_board}',
  988. array(
  989. 'new_parent' => $newParent,
  990. 'new_child_level' => $newLevel,
  991. 'parent_board' => $parent,
  992. )
  993. );
  994. // Recursively fix the children of the children.
  995. foreach ($children as $child)
  996. fixChildren($child, $newLevel + 1, $child);
  997. }
  998. /**
  999. * Load a lot of useful information regarding the boards and categories.
  1000. * The information retrieved is stored in globals:
  1001. * $boards properties of each board.
  1002. * $boardList a list of boards grouped by category ID.
  1003. * $cat_tree properties of each category.
  1004. */
  1005. function getBoardTree()
  1006. {
  1007. global $cat_tree, $boards, $boardList, $txt, $modSettings, $smcFunc;
  1008. // Getting all the board and category information you'd ever wanted.
  1009. $request = $smcFunc['db_query']('', '
  1010. SELECT
  1011. IFNULL(b.id_board, 0) AS id_board, b.id_parent, b.name AS board_name, b.description, b.child_level,
  1012. b.board_order, b.count_posts, b.member_groups, b.id_theme, b.override_theme, b.id_profile, b.redirect,
  1013. b.num_posts, b.num_topics, b.deny_member_groups, c.id_cat, c.name AS cat_name, c.cat_order, c.can_collapse
  1014. FROM {db_prefix}categories AS c
  1015. LEFT JOIN {db_prefix}boards AS b ON (b.id_cat = c.id_cat)
  1016. ORDER BY c.cat_order, b.child_level, b.board_order',
  1017. array(
  1018. )
  1019. );
  1020. $cat_tree = array();
  1021. $boards = array();
  1022. $last_board_order = 0;
  1023. while ($row = $smcFunc['db_fetch_assoc']($request))
  1024. {
  1025. if (!isset($cat_tree[$row['id_cat']]))
  1026. {
  1027. $cat_tree[$row['id_cat']] = array(
  1028. 'node' => array(
  1029. 'id' => $row['id_cat'],
  1030. 'name' => $row['cat_name'],
  1031. 'order' => $row['cat_order'],
  1032. 'can_collapse' => $row['can_collapse']
  1033. ),
  1034. 'is_first' => empty($cat_tree),
  1035. 'last_board_order' => $last_board_order,
  1036. 'children' => array()
  1037. );
  1038. $prevBoard = 0;
  1039. $curLevel = 0;
  1040. }
  1041. if (!empty($row['id_board']))
  1042. {
  1043. if ($row['child_level'] != $curLevel)
  1044. $prevBoard = 0;
  1045. $boards[$row['id_board']] = array(
  1046. 'id' => $row['id_board'],
  1047. 'category' => $row['id_cat'],
  1048. 'parent' => $row['id_parent'],
  1049. 'level' => $row['child_level'],
  1050. 'order' => $row['board_order'],
  1051. 'name' => $row['board_name'],
  1052. 'member_groups' => explode(',', $row['member_groups']),
  1053. 'deny_groups' => explode(',', $row['deny_member_groups']),
  1054. 'description' => $row['description'],
  1055. 'count_posts' => empty($row['count_posts']),
  1056. 'posts' => $row['num_posts'],
  1057. 'topics' => $row['num_topics'],
  1058. 'theme' => $row['id_theme'],
  1059. 'override_theme' => $row['override_theme'],
  1060. 'profile' => $row['id_profile'],
  1061. 'redirect' => $row['redirect'],
  1062. 'prev_board' => $prevBoard
  1063. );
  1064. $prevBoard = $row['id_board'];
  1065. $last_board_order = $row['board_order'];
  1066. if (empty($row['child_level']))
  1067. {
  1068. $cat_tree[$row['id_cat']]['children'][$row['id_board']] = array(
  1069. 'node' => &$boards[$row['id_board']],
  1070. 'is_first' => empty($cat_tree[$row['id_cat']]['children']),
  1071. 'children' => array()
  1072. );
  1073. $boards[$row['id_board']]['tree'] = &$cat_tree[$row['id_cat']]['children'][$row['id_board']];
  1074. }
  1075. else
  1076. {
  1077. // Parent doesn't exist!
  1078. if (!isset($boards[$row['id_parent']]['tree']))
  1079. fatal_lang_error('no_valid_parent', false, array($row['board_name']));
  1080. // Wrong childlevel...we can silently fix this...
  1081. if ($boards[$row['id_parent']]['tree']['node']['level'] != $row['child_level'] - 1)
  1082. $smcFunc['db_query']('', '
  1083. UPDATE {db_prefix}boards
  1084. SET child_level = {int:new_child_level}
  1085. WHERE id_board = {int:selected_board}',
  1086. array(
  1087. 'new_child_level' => $boards[$row['id_parent']]['tree']['node']['level'] + 1,
  1088. 'selected_board' => $row['id_board'],
  1089. )
  1090. );
  1091. $boards[$row['id_parent']]['tree']['children'][$row['id_board']] = array(
  1092. 'node' => &$boards[$row['id_board']],
  1093. 'is_first' => empty($boards[$row['id_parent']]['tree']['children']),
  1094. 'children' => array()
  1095. );
  1096. $boards[$row['id_board']]['tree'] = &$boards[$row['id_parent']]['tree']['children'][$row['id_board']];
  1097. }
  1098. }
  1099. }
  1100. $smcFunc['db_free_result']($request);
  1101. // Get a list of all the boards in each category (using recursion).
  1102. $boardList = array();
  1103. foreach ($cat_tree as $catID => $node)
  1104. {
  1105. $boardList[$catID] = array();
  1106. recursiveBoards($boardList[$catID], $node);
  1107. }
  1108. }
  1109. /**
  1110. * Recursively get a list of boards.
  1111. * Used by getBoardTree
  1112. *
  1113. * @param array &$_boardList
  1114. * @param array &$_tree
  1115. */
  1116. function recursiveBoards(&$_boardList, &$_tree)
  1117. {
  1118. if (empty($_tree['children']))
  1119. return;
  1120. foreach ($_tree['children'] as $id => $node)
  1121. {
  1122. $_boardList[] = $id;
  1123. recursiveBoards($_boardList, $node);
  1124. }
  1125. }
  1126. /**
  1127. * Returns whether the child board id is actually a child of the parent (recursive).
  1128. * @param int $child
  1129. * @param int $parent
  1130. * @return boolean
  1131. */
  1132. function isChildOf($child, $parent)
  1133. {
  1134. global $boards;
  1135. if (empty($boards[$child]['parent']))
  1136. return false;
  1137. if ($boards[$child]['parent'] == $parent)
  1138. return true;
  1139. return isChildOf($boards[$child]['parent'], $parent);
  1140. }
  1141. ?>