Subs-Boards.php 37 KB

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