script.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. if (!defined('DP'))
  3. die('Hacking Attempt...');
  4. /*
  5. (c) Site News 1.0 2011 Dream Portal Team
  6. */
  7. function module_news($params)
  8. {
  9. global $context, $txt, $settings, $modSettings;
  10. // Grab the parameters, if they exist.
  11. if (is_array($params))
  12. {
  13. $board = empty($params['board']) ? 1 : $params['board'];
  14. $limit = empty($params['limit']) ? 5 : $params['limit'];
  15. // Store the board news
  16. $input = dp_boardNews($board, $limit);
  17. // Default - Any content?
  18. if (empty($input))
  19. {
  20. module_error('empty');
  21. return;
  22. }
  23. foreach ($input as $news)
  24. {
  25. echo '
  26. <div class="dp_news">
  27. <div class="dp_news_head">
  28. <img src="', $settings['images_url'], '/on.png" alt="" />
  29. <p>
  30. <a href="', $news['href'], '"><strong>', $news['subject'], '</strong></a> ', $txt['by'], ' ', (!empty($modSettings['dp_color_members']) ? $news['color_poster'] : $news['poster']), '<br />
  31. <span class="smalltext">', $news['time'], '</span>
  32. </p>
  33. </div>';
  34. echo parse_bbc($news['body']);
  35. if(!$news['is_last']){
  36. echo '
  37. <div class="dp_dashed clear"><!-- // --></div>';
  38. }else{
  39. echo '
  40. <div class="clear"><!-- // --></div>';
  41. }
  42. echo '
  43. </div>';
  44. }
  45. }
  46. // Throw an error.
  47. else
  48. module_error();
  49. }
  50. function dp_boardNews($board, $limit)
  51. {
  52. global $scripturl, $smcFunc, $modSettings;
  53. if (!loadLanguage('Stats'))
  54. loadLanguage('Stats');
  55. $request = $smcFunc['db_query']('', '
  56. SELECT b.id_board
  57. FROM {db_prefix}boards AS b
  58. WHERE b.id_board = {int:current_board}
  59. AND {query_see_board}
  60. LIMIT 1',
  61. array(
  62. 'current_board' => $board,
  63. )
  64. );
  65. if ($smcFunc['db_num_rows']($request) == 0)
  66. return array();
  67. list ($board) = $smcFunc['db_fetch_row']($request);
  68. $smcFunc['db_free_result']($request);
  69. $request = $smcFunc['db_query']('', '
  70. SELECT id_first_msg
  71. FROM {db_prefix}topics
  72. WHERE id_board = {int:current_board}' . ($modSettings['postmod_active'] ? '
  73. AND approved = {int:is_approved}' : '') . '
  74. ORDER BY id_first_msg DESC
  75. LIMIT ' . $limit,
  76. array(
  77. 'current_board' => $board,
  78. 'is_approved' => 1,
  79. )
  80. );
  81. $posts = array();
  82. while ($row = $smcFunc['db_fetch_assoc']($request))
  83. $posts[] = $row['id_first_msg'];
  84. $smcFunc['db_free_result']($request);
  85. if (empty($posts))
  86. return array();
  87. $request = $smcFunc['db_query']('', '
  88. SELECT
  89. m.body,m.subject, IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time,
  90. t.id_topic, m.id_member, mg.online_color
  91. FROM {db_prefix}topics AS t
  92. INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
  93. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  94. LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = mem.id_group)
  95. WHERE t.id_first_msg IN ({array_int:post_list})
  96. ORDER BY t.id_first_msg DESC
  97. LIMIT ' . count($posts),
  98. array(
  99. 'post_list' => $posts,
  100. )
  101. );
  102. $return = array();
  103. while ($row = $smcFunc['db_fetch_assoc']($request))
  104. {
  105. $return[] = array(
  106. 'body'=>$row['body'],
  107. 'subject' => $row['subject'],
  108. 'time' => timeformat($row['poster_time']),
  109. 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
  110. 'poster' => !empty($row['id_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>' : $row['poster_name'],
  111. 'color_poster' => !empty($row['id_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '"><span style="color: ' . $row['online_color'] . ';">' . $row['poster_name'] . '</span></a>' : $row['poster_name'],
  112. 'is_last' => false
  113. );
  114. }
  115. $smcFunc['db_free_result']($request);
  116. if(empty($return)){
  117. return $return;
  118. }
  119. $return[count($return) - 1]['is_last'] = true;
  120. return $return;
  121. }
  122. ?>