Subs-Boards.php 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292
  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.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 boards 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 $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. 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, $modSettings, $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, $txt, $modSettings, $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.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. 'order' => $row['cat_order'],
  1036. 'can_collapse' => $row['can_collapse']
  1037. ),
  1038. 'is_first' => empty($cat_tree),
  1039. 'last_board_order' => $last_board_order,
  1040. 'children' => array()
  1041. );
  1042. $prevBoard = 0;
  1043. $curLevel = 0;
  1044. }
  1045. if (!empty($row['id_board']))
  1046. {
  1047. if ($row['child_level'] != $curLevel)
  1048. $prevBoard = 0;
  1049. $boards[$row['id_board']] = array(
  1050. 'id' => $row['id_board'],
  1051. 'category' => $row['id_cat'],
  1052. 'parent' => $row['id_parent'],
  1053. 'level' => $row['child_level'],
  1054. 'order' => $row['board_order'],
  1055. 'name' => $row['board_name'],
  1056. 'member_groups' => explode(',', $row['member_groups']),
  1057. 'deny_groups' => explode(',', $row['deny_member_groups']),
  1058. 'description' => $row['description'],
  1059. 'count_posts' => empty($row['count_posts']),
  1060. 'posts' => $row['num_posts'],
  1061. 'topics' => $row['num_topics'],
  1062. 'theme' => $row['id_theme'],
  1063. 'override_theme' => $row['override_theme'],
  1064. 'profile' => $row['id_profile'],
  1065. 'redirect' => $row['redirect'],
  1066. 'prev_board' => $prevBoard
  1067. );
  1068. $prevBoard = $row['id_board'];
  1069. $last_board_order = $row['board_order'];
  1070. if (empty($row['child_level']))
  1071. {
  1072. $cat_tree[$row['id_cat']]['children'][$row['id_board']] = array(
  1073. 'node' => &$boards[$row['id_board']],
  1074. 'is_first' => empty($cat_tree[$row['id_cat']]['children']),
  1075. 'children' => array()
  1076. );
  1077. $boards[$row['id_board']]['tree'] = &$cat_tree[$row['id_cat']]['children'][$row['id_board']];
  1078. }
  1079. else
  1080. {
  1081. // Parent doesn't exist!
  1082. if (!isset($boards[$row['id_parent']]['tree']))
  1083. fatal_lang_error('no_valid_parent', false, array($row['board_name']));
  1084. // Wrong childlevel...we can silently fix this...
  1085. if ($boards[$row['id_parent']]['tree']['node']['level'] != $row['child_level'] - 1)
  1086. $smcFunc['db_query']('', '
  1087. UPDATE {db_prefix}boards
  1088. SET child_level = {int:new_child_level}
  1089. WHERE id_board = {int:selected_board}',
  1090. array(
  1091. 'new_child_level' => $boards[$row['id_parent']]['tree']['node']['level'] + 1,
  1092. 'selected_board' => $row['id_board'],
  1093. )
  1094. );
  1095. $boards[$row['id_parent']]['tree']['children'][$row['id_board']] = array(
  1096. 'node' => &$boards[$row['id_board']],
  1097. 'is_first' => empty($boards[$row['id_parent']]['tree']['children']),
  1098. 'children' => array()
  1099. );
  1100. $boards[$row['id_board']]['tree'] = &$boards[$row['id_parent']]['tree']['children'][$row['id_board']];
  1101. }
  1102. }
  1103. }
  1104. $smcFunc['db_free_result']($request);
  1105. // Get a list of all the boards in each category (using recursion).
  1106. $boardList = array();
  1107. foreach ($cat_tree as $catID => $node)
  1108. {
  1109. $boardList[$catID] = array();
  1110. recursiveBoards($boardList[$catID], $node);
  1111. }
  1112. }
  1113. /**
  1114. * Recursively get a list of boards.
  1115. * Used by getBoardTree
  1116. *
  1117. * @param array &$_boardList
  1118. * @param array &$_tree
  1119. */
  1120. function recursiveBoards(&$_boardList, &$_tree)
  1121. {
  1122. if (empty($_tree['children']))
  1123. return;
  1124. foreach ($_tree['children'] as $id => $node)
  1125. {
  1126. $_boardList[] = $id;
  1127. recursiveBoards($_boardList, $node);
  1128. }
  1129. }
  1130. /**
  1131. * Returns whether the child board id is actually a child of the parent (recursive).
  1132. * @param int $child
  1133. * @param int $parent
  1134. * @return boolean
  1135. */
  1136. function isChildOf($child, $parent)
  1137. {
  1138. global $boards;
  1139. if (empty($boards[$child]['parent']))
  1140. return false;
  1141. if ($boards[$child]['parent'] == $parent)
  1142. return true;
  1143. return isChildOf($boards[$child]['parent'], $parent);
  1144. }
  1145. ?>