Subs-MessageIndex.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * Simple Machines Forum (SMF)
  4. *
  5. * @package SMF
  6. * @author Simple Machines http://www.simplemachines.org
  7. * @copyright 2012 Simple Machines Forum contributors
  8. * @license http://www.simplemachines.org/about/smf/license.php BSD
  9. *
  10. * @version 2.1 Alpha 1
  11. */
  12. if (!defined('SMF'))
  13. die('Hacking attempt...');
  14. function getBoardList($boardListOptions = array())
  15. {
  16. global $smcFunc, $user_info;
  17. if (isset($boardListOptions['excluded_boards']) && isset($boardListOptions['included_boards']))
  18. trigger_error('getBoardList(): Setting both excluded_boards and included_boards is not allowed.', E_USER_ERROR);
  19. $where = array();
  20. $where_parameters = array();
  21. if (isset($boardListOptions['excluded_boards']))
  22. {
  23. $where[] = 'b.id_board NOT IN ({array_int:excluded_boards})';
  24. $where_parameters['excluded_boards'] = $boardListOptions['excluded_boards'];
  25. }
  26. if (isset($boardListOptions['included_boards']))
  27. {
  28. $where[] = 'b.id_board IN ({array_int:included_boards})';
  29. $where_parameters['included_boards'] = $boardListOptions['included_boards'];
  30. }
  31. if (!empty($boardListOptions['ignore_boards']))
  32. $where[] = '{query_wanna_see_board}';
  33. elseif (!empty($boardListOptions['use_permissions']))
  34. $where[] = '{query_see_board}';
  35. if (!empty($boardListOptions['not_redirection']))
  36. {
  37. $where[] = 'b.redirect = {string:blank_redirect}';
  38. $where_parameters['blank_redirect'] = '';
  39. }
  40. $request = $smcFunc['db_query']('messageindex_fetch_boards', '
  41. SELECT c.name AS cat_name, c.id_cat, b.id_board, b.name AS board_name, b.child_level
  42. FROM {db_prefix}boards AS b
  43. LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)' . (empty($where) ? '' : '
  44. WHERE ' . implode('
  45. AND ', $where)),
  46. $where_parameters
  47. );
  48. $return_value = array();
  49. if ($smcFunc['db_num_rows']($request) !== 0)
  50. {
  51. while ($row = $smcFunc['db_fetch_assoc']($request))
  52. {
  53. if (!isset($return_value[$row['id_cat']]))
  54. $return_value[$row['id_cat']] = array(
  55. 'id' => $row['id_cat'],
  56. 'name' => $row['cat_name'],
  57. 'boards' => array(),
  58. );
  59. $return_value[$row['id_cat']]['boards'][] = array(
  60. 'id' => $row['id_board'],
  61. 'name' => $row['board_name'],
  62. 'child_level' => $row['child_level'],
  63. 'selected' => isset($boardListOptions['selected_board']) && $boardListOptions['selected_board'] == $row['id_board'],
  64. );
  65. }
  66. }
  67. $smcFunc['db_free_result']($request);
  68. return $return_value;
  69. }
  70. ?>