script.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. echo '<hr/> <div = class="TA_Discuss smalltext"><a href="?topic=',$news['id_about'] , ' ">Discuss this article ( ', $news['posts_about'] ,' )</a></div>';
  36. if(!$news['is_last']){
  37. echo '
  38. <div class="dp_dashed clear"><!-- // --></div>';
  39. }else{
  40. echo '
  41. <div class="clear"><!-- // --></div>';
  42. }
  43. echo '
  44. </div>';
  45. }
  46. }
  47. // Throw an error.
  48. else
  49. module_error();
  50. }
  51. function dp_boardNews($board, $limit)
  52. {
  53. global $scripturl, $smcFunc, $modSettings,$smf_eeems,$boarddir,$db_prefix;
  54. require_once($boarddir . '/SSI_eeems.php');
  55. if(!($smf_eeems instanceof SMF))
  56. $smf_eeems = new SMF();
  57. if (!loadLanguage('Stats'))
  58. loadLanguage('Stats');
  59. $request = $smcFunc['db_query']('', '
  60. SELECT b.id_board
  61. FROM {db_prefix}boards AS b
  62. WHERE b.id_board = {int:current_board}
  63. AND {query_see_board}
  64. LIMIT 1',
  65. array(
  66. 'current_board' => $board,
  67. )
  68. );
  69. if ($smcFunc['db_num_rows']($request) == 0)
  70. return array();
  71. list ($board) = $smcFunc['db_fetch_row']($request);
  72. $smcFunc['db_free_result']($request);
  73. $request = $smcFunc['db_query']('', '
  74. SELECT id_first_msg
  75. FROM {db_prefix}topics
  76. WHERE id_board = {int:current_board}' . ($modSettings['postmod_active'] ? '
  77. AND approved = {int:is_approved}' : '') . '
  78. ORDER BY id_first_msg DESC
  79. LIMIT ' . $limit,
  80. array(
  81. 'current_board' => $board,
  82. 'is_approved' => 1,
  83. )
  84. );
  85. $posts = array();
  86. while ($row = $smcFunc['db_fetch_assoc']($request))
  87. $posts[] = $row['id_first_msg'];
  88. $smcFunc['db_free_result']($request);
  89. if (empty($posts))
  90. return array();
  91. $request = $smcFunc['db_query']('', '
  92. SELECT
  93. m.body,m.subject, IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time,
  94. t.id_topic, m.id_member, mg.online_color
  95. FROM {db_prefix}topics AS t
  96. INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
  97. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  98. LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = mem.id_group)
  99. WHERE t.id_first_msg IN ({array_int:post_list})
  100. ORDER BY t.id_first_msg DESC
  101. LIMIT ' . count($posts),
  102. array(
  103. 'post_list' => $posts,
  104. )
  105. );
  106. $return = array();
  107. while ($row = $smcFunc['db_fetch_assoc']($request))
  108. {
  109. $res = $smf_eeems->sql->query("
  110. SELECT topic_about_id
  111. FROM {$db_prefix}topic_articles
  112. WHERE topic_article_id = ?
  113. ",'i',$row['id_topic'])->assoc_result;
  114. if(!empty($res)){
  115. $posts=$smf_eeems->topic($res['topic_about_id'])->post_count;
  116. $return[] = array(
  117. 'body'=>$row['body'],
  118. 'subject' => $row['subject'],
  119. 'time' => timeformat($row['poster_time']),
  120. 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
  121. 'poster' => !empty($row['id_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>' : $row['poster_name'],
  122. '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'],
  123. 'id_about'=>$res['topic_about_id'],
  124. 'posts_about'=>$posts,
  125. 'is_last' => false
  126. );}
  127. else {
  128. $posts=$smf_eeems->topic($row['id_topic'])->post_count;
  129. $return[] = array(
  130. 'body'=>$row['body'],
  131. 'subject' => $row['subject'],
  132. 'time' => timeformat($row['poster_time']),
  133. 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
  134. 'poster' => !empty($row['id_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>' : $row['poster_name'],
  135. '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'],
  136. 'id_about'=>$row['id_topic'],
  137. 'posts_about'=>$posts,
  138. 'is_last' => false
  139. );}
  140. }
  141. $smcFunc['db_free_result']($request);
  142. if(empty($return)){
  143. return $return;
  144. }
  145. $return[count($return) - 1]['is_last'] = true;
  146. return $return;
  147. }
  148. ?>