2
0

Subs-MessageIndex.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * Simple Machines Forum (SMF)
  4. *
  5. * @package SMF
  6. * @author Simple Machines http://www.simplemachines.org
  7. * @copyright 2013 Simple Machines and individual 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('No direct access...');
  14. /**
  15. * Generates the query to determine the list of available boards for a user
  16. * Executes the query and returns the list
  17. *
  18. * @param type $boardListOptions
  19. * @return type
  20. */
  21. function getBoardList($boardListOptions = array())
  22. {
  23. global $smcFunc, $user_info;
  24. if (isset($boardListOptions['excluded_boards']) && isset($boardListOptions['included_boards']))
  25. trigger_error('getBoardList(): Setting both excluded_boards and included_boards is not allowed.', E_USER_ERROR);
  26. $where = array();
  27. $where_parameters = array();
  28. if (isset($boardListOptions['excluded_boards']))
  29. {
  30. $where[] = 'b.id_board NOT IN ({array_int:excluded_boards})';
  31. $where_parameters['excluded_boards'] = $boardListOptions['excluded_boards'];
  32. }
  33. if (isset($boardListOptions['included_boards']))
  34. {
  35. $where[] = 'b.id_board IN ({array_int:included_boards})';
  36. $where_parameters['included_boards'] = $boardListOptions['included_boards'];
  37. }
  38. if (!empty($boardListOptions['ignore_boards']))
  39. $where[] = '{query_wanna_see_board}';
  40. elseif (!empty($boardListOptions['use_permissions']))
  41. $where[] = '{query_see_board}';
  42. if (!empty($boardListOptions['not_redirection']))
  43. {
  44. $where[] = 'b.redirect = {string:blank_redirect}';
  45. $where_parameters['blank_redirect'] = '';
  46. }
  47. $request = $smcFunc['db_query']('messageindex_fetch_boards', '
  48. SELECT c.name AS cat_name, c.id_cat, b.id_board, b.name AS board_name, b.child_level
  49. FROM {db_prefix}boards AS b
  50. LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)' . (empty($where) ? '' : '
  51. WHERE ' . implode('
  52. AND ', $where)),
  53. $where_parameters
  54. );
  55. $return_value = array();
  56. if ($smcFunc['db_num_rows']($request) !== 0)
  57. {
  58. while ($row = $smcFunc['db_fetch_assoc']($request))
  59. {
  60. if (!isset($return_value[$row['id_cat']]))
  61. $return_value[$row['id_cat']] = array(
  62. 'id' => $row['id_cat'],
  63. 'name' => $row['cat_name'],
  64. 'boards' => array(),
  65. );
  66. $return_value[$row['id_cat']]['boards'][] = array(
  67. 'id' => $row['id_board'],
  68. 'name' => $row['board_name'],
  69. 'child_level' => $row['child_level'],
  70. 'selected' => isset($boardListOptions['selected_board']) && $boardListOptions['selected_board'] == $row['id_board'],
  71. );
  72. }
  73. }
  74. $smcFunc['db_free_result']($request);
  75. return $return_value;
  76. }
  77. ?>