FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


phpBB Module for Hot, Random, and Recent Topics?





Aredon
Well after three to four hours of searching with google and phpBB's website I am still empty handed with the module that I would like to create. Basically I'm struggling with the SQL at this point, which is really kind of a shame. I already have a function that prints recent topics halfway reasonably, but I'll admit that the code is hardly my own.

Code:
define('IN_PHPBB', true);
function recent_posts(){
   global $phpbb_root_path, $phpEx, $user, $db, $config, $cache, $template;
   $path = $_SERVER['DOCUMENT_ROOT'];
   $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : $path.'/community/';
   $phpEx = substr(strrchr(__FILE__, '.'), 1);
   include($phpbb_root_path . 'common.' . $phpEx);
   // Start session management
    $user->session_begin();
    $auth->acl($user->data);
    $user->setup();
    // Number of posts and grabbing permissions
    $topic_limit = request_var('topic_limit', 10);
    $forums = array_unique(array_keys($auth->acl_getf('f_read', true)));

    // Select the last topics to which we have permissions
    $sql = 'SELECT p.post_id, p.topic_id, p.forum_id, p.post_subject, p.post_time, u.username
                    FROM ' . POSTS_TABLE . ' p , ' . USERS_TABLE . ' u
                    WHERE post_approved = 1
                        AND ' . $db->sql_in_set('forum_id', $forums) . '
                        AND u.user_id = p.poster_id
                    ORDER BY post_time DESC
                    LIMIT 0,' . $topic_limit;
    $result = $db->sql_query($sql);

    // Now let's output the content
    echo '<ul>';
    while ($row = $db->sql_fetchrow($result))
    {
        $url = generate_board_url() . "/viewtopic.{$phpEx}?f={$row['forum_id']}&amp;t={$row['topic_id']}&amp;p={$row['post_id']}#p{$row['post_id']}";
        echo '<li><a target="_top" href="' . $url . '">' . $row['post_subject'] . '</a><br /><font size="1" color="#728370" face="Verdana, Arial, Helvetica, sans-serif">from ' . $row['username'] . ' on ' . $user->format_date($row['post_time']) . '</font></li>';
    }
    echo '</ul>';
}


I would love to have something modular like this for Hot and Random topics as well (something I can include outside the phpBB root), but oddly enough I can't seem to find any documentation on it for a 3.0.x version, and I worry that additional functions of the same structure would cause repeat header issues or redeclaration of globals. I have already posted on the phpBB forums as well, but I feel it would be foolish to not try and get answers in as many places as possible! Very Happy So if anyone knows how I might find a module that will do the things I need, that would be awesome!
Aredon
Moved to this function for recent posts rather than topics.
Code:
function recent_posts(){
global $phpbb_root_path, $phpEx, $user, $db, $config, $cache, $template, $auth;
$search_limit = 5;
$forum_id = array();
$forum_id_where = create_where_clauses($forum_id, 'forum');
   $posts_ary = array(
     'SELECT'    => 'p.*, t.*, u.username, u.user_colour',
 
     'FROM'      => array(
         POSTS_TABLE     => 'p',
     ),
 
     'LEFT_JOIN' => array(
         array(
             'FROM'  => array(USERS_TABLE => 'u'),
             'ON'    => 'u.user_id = p.poster_id'
         ),
         array(
             'FROM'  => array(TOPICS_TABLE => 't'),
             'ON'    => 'p.topic_id = t.topic_id'
         ),
     ),
 
     'WHERE'     => $db->sql_in_set('t.forum_id', array_keys($auth->acl_getf('f_read', true))) . '
                     AND t.topic_status <> ' . ITEM_MOVED . '
                     AND t.topic_approved = 1',
 
     'ORDER_BY'  => 'p.post_id DESC',
);
 
$posts = $db->sql_build_query('SELECT', $posts_ary);

$posts_result = $db->sql_query_limit($posts, $search_limit);

   while( $posts_row = $db->sql_fetchrow($posts_result) )
   {
      $topic_title       = $posts_row['topic_title'];
      $post_author       = get_username_string('full', $posts_row['poster_id'], $posts_row['username'], $posts_row['user_colour']);
      $post_date          = $user->format_date($posts_row['post_time']);
      $post_link       = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $posts_row['forum_id'] . '&amp;t=' . $posts_row['topic_id'] . '&amp;p=' . $posts_row['post_id']) . '#p' . $posts_row['post_id'];

      $post_text = nl2br($posts_row['post_text']);

      $bbcode = new bbcode(base64_encode($bbcode_bitfield));       
      $bbcode->bbcode_second_pass($post_text, $posts_row['bbcode_uid'], $posts_row['bbcode_bitfield']);

      $post_text = smiley_text($post_text);

      $template->assign_block_vars('announcements', array(
      'TOPIC_TITLE'       => censor_text($topic_title),
      'POST_AUTHOR'       => $post_author,
      'POST_DATE'       => $post_date,
      'POST_LINK'       => $post_link,
      'POST_TEXT'         => censor_text($post_text),
      ));
   }
   return $template->_tpldata['announcements'];
}
Related topics
Me Thinks....
Referals
gratis forum ?
Feedback
Additional Features for the forum
Integrate Wordpress blog with SMF forum
John McCain will really keep taxes low
Americans want universal health care. Why can't we get it?
Outside phpBB Integration Functions
This months edition of Good News
Free Reliable Internet Hosting
Can we get a page where all the recent and hot topics are?
Do you feel that you are forced to put post everyday?
2nd site
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.