script.php 4.9 KB

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