PageRenderTime 55ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 1ms

/root/blocks/block_recent_topics.php

https://github.com/dravekx/stargate-portal
PHP | 218 lines | 148 code | 41 blank | 29 comment | 20 complexity | 98a3d0402184e84ba4bffb8f893c5a97 MD5 | raw file
  1. <?php
  2. /**
  3. *
  4. * @package Stargate Portal
  5. * @author Michael O'Toole - aka Michaelo
  6. * @begin Sunday, 20th May, 2007
  7. * @copyright (c) 2005-2008 phpbbireland
  8. * @home http://www.phpbbireland.com
  9. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10. * @note: Do not remove this copyright. Just append yours if you have modified it,
  11. * this is part of the Stargate Portal copyright agreement...
  12. *
  13. * @version $Id: block_recent_topics.php 297 2008-12-30 18:40:30Z JohnnyTheOne $
  14. * Updated: 21 February 2008
  15. *
  16. */
  17. /**
  18. * @ignore
  19. */
  20. if ( !defined('IN_PHPBB') )
  21. {
  22. exit;
  23. }
  24. // for bots test //
  25. $page_title = $user->lang['BLOCK_RECENT_TOPICS'];
  26. $phpEx = substr(strrchr(__FILE__, '.'), 1);
  27. $auth->acl($user->data);
  28. // URL PARAMETERS
  29. define('POST_TOPIC_URL', 't');
  30. define('POST_CAT_URL', 'c');
  31. define('POST_FORUM_URL', 'f');
  32. define('POST_USERS_URL', 'u');
  33. define('POST_POST_URL', 'p');
  34. define('POST_GROUPS_URL', 'g');
  35. $queries = 0;
  36. $cached_queries = 0;
  37. global $user, $forum_id, $phpbb_root_path, $phpEx, $SID, $config , $template, $portal_config, $userdata, $config, $db, $phpEx;
  38. // set up variables used //
  39. $display_this_many = $k_config['number_of_recent_topics_to_display'];
  40. $forum_count = $row_count = 0;
  41. $except_forum_id = $k_config['recent_topics_search_exclude'];
  42. $forum_data = array();
  43. $recent_topic_row = array();
  44. // get all forums //
  45. $sql = "SELECT * FROM ". FORUMS_TABLE . " ORDER BY forum_id";
  46. if (!$result = $db->sql_query($sql))
  47. {
  48. trigger_error('Error! Could not query forums information: ' . basename(dirname(__FILE__)) . '/' . basename(__FILE__) . ', line ' . __LINE__);
  49. }
  50. while( $row = $db->sql_fetchrow($result) )
  51. {
  52. $forum_data[] = $row;
  53. $forum_count++;
  54. }
  55. $db->sql_freeresult($result);
  56. for ($i = 1; $i < $forum_count; $i++)
  57. {
  58. if (!$auth->acl_gets('f_list', 'f_read', $forum_data[$i]['forum_id']))
  59. {
  60. $except_forum_id .= "'" . $forum_data[$i]['forum_id'] . "'";
  61. $except_forum_id .= ",";
  62. }
  63. }
  64. $except_forum_id = rtrim($except_forum_id,",");
  65. if($except_forum_id == '')
  66. $except_forum_id = '0';
  67. $sql = "SELECT t.topic_id, t.topic_title, t.topic_last_post_id, t.forum_id, p.post_id, p.poster_id, p.post_time, u.user_id, u.username, u.user_colour
  68. FROM " . TOPICS_TABLE . " AS t, " . POSTS_TABLE . " AS p, " . USERS_TABLE . " AS u
  69. WHERE t.forum_id NOT IN (" . $except_forum_id . ")
  70. AND t.topic_status <> 2
  71. AND p.post_id = t.topic_last_post_id
  72. AND p.poster_id = u.user_id
  73. ORDER BY p.post_id DESC
  74. LIMIT " . $display_this_many;
  75. if (!$result = $db->sql_query($sql, 300))
  76. {
  77. trigger_error("Could not query recent topics data");
  78. }
  79. while ($row = $db->sql_fetchrow($result))
  80. {
  81. $recent_topic_row[] = $row;
  82. if( $row['forum_id'] > 0)
  83. {
  84. // Get forum name for this postid
  85. $sql2 = "SELECT forum_name
  86. FROM " . FORUMS_TABLE . "
  87. WHERE forum_id = " . $row['forum_id'] . "
  88. LIMIT " . 1;
  89. $my_result = $db->sql_query($sql2);
  90. $my_row = $db->sql_fetchrow($my_result);
  91. $db->sql_freeresult($my_result);
  92. $recent_topic_row['forum_name'][$row_count] = $my_row['forum_name'];
  93. $row_count++;
  94. }
  95. }
  96. $db->sql_freeresult($result);
  97. $sql = "SELECT scroll, position
  98. FROM " . K_BLOCKS_TABLE . "
  99. WHERE title = 'Recent Topics' ";
  100. if( $result = $db->sql_query($sql, 300) )
  101. {
  102. $rowx = $db->sql_fetchrow($result);
  103. $scroll = $rowx['scroll'];
  104. $display_center = $rowx['position'];
  105. }
  106. else
  107. trigger_error("Could not query <strong>" . $recent_topics . "</strong> information");
  108. $db->sql_freeresult($result);
  109. ($scroll) ? $style_row = 'scroll' : $style_row = 'static';
  110. //$template->assign_block_vars($style_row, array());
  111. // change topics to display count if there are less topics that set in ACP
  112. if($display_this_many > $row_count)
  113. $display_this_many = $row_count;
  114. if($scroll)
  115. {
  116. $display_this_many = $row_count;
  117. if($row_count <= 6)
  118. {
  119. $style_row = 'static';
  120. $template->assign_vars(array(
  121. 'PROCESS' => false,
  122. ));
  123. }
  124. else
  125. {
  126. $template->assign_vars(array(
  127. 'PROCESS' => true,
  128. ));
  129. }
  130. }
  131. for ( $i = 0; $i < $display_this_many; $i++ )
  132. {
  133. if ($recent_topic_row[$i]['user_id'] != -1)
  134. {
  135. // this is a left or right block ? //
  136. if($display_center != 'C')
  137. {
  138. $my_title_long = $recent_topic_row[$i]['topic_title'];
  139. $recent_topic_row[$i]['topic_title'] = sgp_checksize ($recent_topic_row[$i]['topic_title'],20); // Michaelo's function to stop page from stretching due to long names in form select options... Names are truncated//
  140. }
  141. $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . (($recent_topic_row[$i]['forum_id']) ? $recent_topic_row[$i]['forum_id'] : $forum_id) );
  142. // add spaces for nice scrolling
  143. $my_title = smilies_pass($recent_topic_row[$i]['topic_title']);
  144. $length = strlen($my_title);
  145. // Truncate title and padd with ... if too long
  146. if($length > 25)
  147. {
  148. sgp_checksize ($my_title, 25);
  149. }
  150. $my_forum = smilies_pass($recent_topic_row['forum_name'][$i]);
  151. $length = strlen($my_forum);
  152. // do same for the forum name
  153. if($length > 25)
  154. sgp_checksize ($my_forum, 25);
  155. $template->assign_block_vars($style_row . '_recent_topic_row', array(
  156. 'U_FORUM' => append_sid("viewforum.$phpEx?" . POST_FORUM_URL . '=' . $recent_topic_row[$i]['forum_id']),
  157. 'U_LAST_POST' => $view_topic_url . '&amp;p=' . $recent_topic_row[$i]['topic_last_post_id'] . '#p' . $recent_topic_row[$i]['topic_last_post_id'],
  158. 'U_TITLE' => append_sid("viewtopic.$phpEx?" . POST_POST_URL . '=' . $recent_topic_row[$i]['post_id']),
  159. 'S_POSTER' => get_username_string('full', $recent_topic_row[$i]['user_id'], $recent_topic_row[$i]['username'], $recent_topic_row[$i]['user_colour']),
  160. 'S_POSTTIME' => $user->format_date($recent_topic_row[$i]['post_time']),
  161. 'S_ROW_COUNT' => $i,
  162. 'S_FORUM' => $my_forum,
  163. 'S_TITLE' => $my_title,
  164. 'S_TITLE_LONG' => $my_title_long,
  165. 'LAST_POST_IMG' => $user->img('icon_topic_newest', 'VIEW_LATEST_POST'),
  166. ));
  167. }
  168. }
  169. $template->assign_vars(array(
  170. 'S_RECENT_TOPICS_COUNT_ASKED' => $display_this_many,
  171. 'S_RECENT_TOPICS_COUNT_RETURNED' => $row_count,
  172. 'S_ALIGN_IT' => 'center',
  173. 'S_DISPLAY_CENTRE' => $display_center,
  174. 'S_COUNT' => $display_this_many,
  175. 'RT1_PORTAL_DEBUG' => sprintf($user->lang['PORTAL_DEBUG_QUERIES'], ($queries) ? $queries : '0', ($cached_queries) ? $cached_queries : '0'),
  176. ));
  177. ?>