Advertisement
Guest User

Untitled

a guest
Aug 28th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.81 KB | None | 0 0
  1. <?php
  2. /*
  3. * home.php
  4. * Description: example file for displaying latest posts and topics
  5. * by battye (for phpBB.com MOD Team)
  6. * September 29, 2009
  7. */
  8.  
  9. $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './forums/';
  10.  
  11. define('IN_PHPBB', true);
  12.  
  13. // Start session management
  14. $user->session_begin();
  15. $auth->acl($user->data);
  16. $user->setup('viewforum');
  17.  
  18. /* create_where_clauses( int[] gen_id, String type )
  19. * This function outputs an SQL WHERE statement for use when grabbing
  20. * posts and topics */
  21.  
  22. function create_where_clauses($gen_id, $type)
  23. {
  24. global $db, $auth;
  25.  
  26. $size_gen_id = sizeof($gen_id);
  27.  
  28. switch($type)
  29. {
  30. case 'forum':
  31. $type = 'forum_id';
  32. break;
  33. case 'topic':
  34. $type = 'topic_id';
  35. break;
  36. default:
  37. trigger_error('No type defined');
  38. }
  39.  
  40. // Set $out_where to nothing, this will be used of the gen_id
  41. // size is empty, in other words "grab from anywhere" with
  42. // no restrictions
  43. $out_where = '';
  44.  
  45. if( $size_gen_id > 0 )
  46. {
  47. // Get a list of all forums the user has permissions to read
  48. $auth_f_read = array_keys($auth->acl_getf('f_read', true));
  49.  
  50. if( $type == 'topic_id' )
  51. {
  52. $sql = 'SELECT topic_id FROM ' . TOPICS_TABLE . '
  53. WHERE ' . $db->sql_in_set('topic_id', $gen_id) . '
  54. AND ' . $db->sql_in_set('forum_id', $auth_f_read);
  55.  
  56. $result = $db->sql_query($sql);
  57.  
  58. while( $row = $db->sql_fetchrow($result) )
  59. {
  60. // Create an array with all acceptable topic ids
  61. $topic_id_list[] = $row['topic_id'];
  62. }
  63.  
  64. unset($gen_id);
  65.  
  66. $gen_id = $topic_id_list;
  67. $size_gen_id = sizeof($gen_id);
  68. }
  69.  
  70. $j = 0;
  71.  
  72. for( $i = 0; $i < $size_gen_id; $i++ )
  73. {
  74. $id_check = (int) $gen_id[$i];
  75.  
  76. // If the type is topic, all checks have been made and the query can start to be built
  77. if( $type == 'topic_id' )
  78. {
  79. $out_where .= ($j == 0) ? 'WHERE ' . $type . ' = ' . $id_check . ' ' : 'OR ' . $type . ' = ' . $id_check . ' ';
  80. }
  81.  
  82. // If the type is forum, do the check to make sure the user has read permissions
  83. else if( $type == 'forum_id' && $auth->acl_get('f_read', $id_check) )
  84. {
  85. $out_where .= ($j == 0) ? 'WHERE ' . $type . ' = ' . $id_check . ' ' : 'OR ' . $type . ' = ' . $id_check . ' ';
  86. }
  87.  
  88. $j++;
  89. }
  90. }
  91.  
  92. if( $out_where == '' && $size_gen_id > 0 )
  93. {
  94. trigger_error('A list of topics/forums has not been created');
  95. }
  96.  
  97. return $out_where;
  98. }
  99.  
  100. $search_limit = 5;
  101.  
  102. $forum_id = array(2, 5);
  103. $forum_id_where = create_where_clauses($forum_id, 'forum');
  104.  
  105. $topic_id = array(20, 50);
  106. $topic_id_where = create_where_clauses($topic_id, 'topic');
  107.  
  108. $topics = 'SELECT * FROM ' . TOPICS_TABLE . '
  109. ' . $forum_id_where . '
  110. AND topic_status <> ' . ITEM_MOVED . '
  111. AND topic_visibility = 1
  112. ORDER BY topic_id DESC';
  113.  
  114. $topics_result = $db->sql_query_limit($topics, $search_limit);
  115.  
  116. while( $topics_row = $db->sql_fetchrow($topics_result) )
  117. {
  118. $topic_title = $topics_row['topic_title'];
  119. $topic_author = get_username_string('full', $topics_row['topic_poster'], $topics_row['topic_first_poster_name'], $topics_row['topic_first_poster_colour']);
  120. $topic_date = $user->format_date($topics_row['topic_time']);
  121. $topic_last_post = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $topics_row['forum_id'] . '&amp;t=' . $topics_row['topic_id'] . '&amp;p=' . $topics_row['topic_last_post_id']) . '#p' . $topics_row['topic_last_post_id'];
  122. $topic_last_author = get_username_string('full', $topics_row['topic_last_poster_id'], $topics_row['topic_last_poster_name'], $topics_row['topic_last_poster_colour']);
  123. $topic_link = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $topics_row['forum_id'] . '&amp;t=' . $topics_row['topic_id']);
  124.  
  125. $template->assign_block_vars('announcements', array(
  126. 'TOPIC_TITLE' => censor_text($topic_title),
  127. 'TOPIC_AUTHOR' => $topic_author,
  128. 'TOPIC_DATE' => $topic_date,
  129. 'TOPIC_LAST_POST' => $topic_last_post,
  130. 'TOPIC_LAST_AUTHOR' => $topic_last_author,
  131. 'TOPIC_LINK' => $topic_link,
  132. ));
  133. }
  134.  
  135.  
  136. page_header('External page');
  137.  
  138. $template->set_filenames(array(
  139. 'body' => 'external_body.html'
  140. ));
  141.  
  142. page_footer();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement