Recent topics listing on homepage

Discussion forum for MOD Writers regarding MOD Development.
User avatar
MPG187
Registered User
Posts: 519
Joined: Sun Apr 12, 2009 7:39 pm
Location: Operation420.net
Name: Operation 420
Contact:

Recent topics listing on homepage

Post by MPG187 » Tue Dec 08, 2009 8:19 pm

http://www.phpbb.com/community/viewtopi ... &t=1402415

I want to have a recent topics list on my homepage of my site that's outside my phpbb install directory. What code do I put to make this happen?
phpBB 3.0.4, http://operation420.net/forum, download package from phpBB.com (fresh install), mods installed, British English, MySQL 4.1.14

User avatar
tumba25
Former Team Member
Posts: 4430
Joined: Wed Jun 06, 2007 6:42 am
Location: Kokkola, Finland.
Name: Jari Kanerva
Contact:

Re: Recent topics listing on homepage

Post by tumba25 » Wed Dec 09, 2009 6:16 am

Need a mod/extension created/installed, other custom-coded solution or a server admin? https://tumba25.net

User avatar
MPG187
Registered User
Posts: 519
Joined: Sun Apr 12, 2009 7:39 pm
Location: Operation420.net
Name: Operation 420
Contact:

Re: Recent topics listing on homepage

Post by MPG187 » Wed Dec 09, 2009 9:31 pm

EDIT: Delete
Last edited by MPG187 on Wed Dec 09, 2009 9:40 pm, edited 1 time in total.
phpBB 3.0.4, http://operation420.net/forum, download package from phpBB.com (fresh install), mods installed, British English, MySQL 4.1.14

User avatar
MPG187
Registered User
Posts: 519
Joined: Sun Apr 12, 2009 7:39 pm
Location: Operation420.net
Name: Operation 420
Contact:

Re: Recent topics listing on homepage

Post by MPG187 » Wed Dec 09, 2009 9:36 pm

Code: Select all

<?php
/*
* test.php 
* Description: example file for displaying latest posts and topics
* by battye (for phpBB.com MOD Team)
* September 29, 2009
*/

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './forum';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('viewforum');

/* create_where_clauses( int[] gen_id, String type )
* This function outputs an SQL WHERE statement for use when grabbing 
* posts and topics */

function create_where_clauses($gen_id, $type)
{
global $db, $auth;

    $size_gen_id = sizeof($gen_id);

        switch($type)
        {
            case 'forum':
                $type = 'forum_id';
                break;
            case 'topic':
                $type = 'topic_id';
                break;
            default:
                trigger_error('No type defined');
        }

    // Set $out_where to nothing, this will be used of the gen_id
    // size is empty, in other words "grab from anywhere" with
    // no restrictions
    $out_where = '';

    if( $size_gen_id > 0 )
    {
    // Get a list of all forums the user has permissions to read
    $auth_f_read = array_keys($auth->acl_getf('f_read', true));

        if( $type == 'topic_id' )
        {
            $sql     = 'SELECT topic_id FROM ' . TOPICS_TABLE . '
                        WHERE ' .  $db->sql_in_set('topic_id', $gen_id) . '
                        AND ' .  $db->sql_in_set('forum_id', $auth_f_read);

            $result     = $db->sql_query($sql);

                while( $row = $db->sql_fetchrow($result) )
                {
                        // Create an array with all acceptable topic ids
                        $topic_id_list[] = $row['topic_id'];
                }

            unset($gen_id);

            $gen_id = $topic_id_list;
            $size_gen_id = sizeof($gen_id);
        }

    $j = 0;    

        for( $i = 0; $i < $size_gen_id; $i++ )
        {
        $id_check = (int) $gen_id[$i];

            // If the type is topic, all checks have been made and the query can start to be built
            if( $type == 'topic_id' )
            {
                $out_where .= ($j == 0) ? 'WHERE ' . $type . ' = ' . $id_check . ' ' : 'OR ' . $type . ' = ' . $id_check . ' ';
            }

            // If the type is forum, do the check to make sure the user has read permissions
            else if( $type == 'forum_id' && $auth->acl_get('f_read', $id_check) )
            {
                $out_where .= ($j == 0) ? 'WHERE ' . $type . ' = ' . $id_check . ' ' : 'OR ' . $type . ' = ' . $id_check . ' ';
            }    

        $j++;
        }
    }

    if( $out_where == '' && $size_gen_id > 0 )
    {
        trigger_error('A list of topics/forums has not been created');
    }

    return $out_where;
}

$search_limit = 5;

    $forum_id = array(2, 5);
    $forum_id_where = create_where_clauses($forum_id, 'forum');

    $topic_id = array(20, 50);
    $topic_id_where = create_where_clauses($topic_id, 'topic');

$topics = 'SELECT * FROM ' . TOPICS_TABLE . '
            ' . $forum_id_where . '
              AND topic_status <> ' . ITEM_MOVED . '
              AND topic_approved = 1
            ORDER BY topic_id DESC';

   $topics_result = $db->sql_query_limit($topics, $search_limit);

      while( $topics_row = $db->sql_fetchrow($topics_result) )
      {
         $topic_title       = $topics_row['topic_title'];
         $topic_author       = get_username_string('full', $topics_row['topic_poster'], $topics_row['topic_first_poster_name'], $topics_row['topic_first_poster_colour']);
         $topic_date       = $user->format_date($topics_row['topic_time']);
         $topic_last_post    = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $topics_row['forum_id'] . '&t=' . $topics_row['topic_id'] . '&p=' . $topics_row['topic_last_post_id']) . '#p' . $topics_row['topic_last_post_id'];
         $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']);
         $topic_link       = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $topics_row['forum_id'] . '&t=' . $topics_row['topic_id']);

         $template->assign_block_vars('announcements', array(
         'TOPIC_TITLE'       => censor_text($topic_title),
         'TOPIC_AUTHOR'       => $topic_author,
         'TOPIC_DATE'       => $topic_date,
         'TOPIC_LAST_POST'    => $topic_last_post,
         'TOPIC_LAST_AUTHOR' => $topic_last_author,
         'TOPIC_LINK'       => $topic_link,
         ));
      }

$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'] . '&t=' . $posts_row['topic_id'] . '&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),
         ));
      }

page_header('External page');

    $template->set_filenames(array(
        'body' => 'external_body.html'
    ));

    page_footer();
I get a blank page
phpBB 3.0.4, http://operation420.net/forum, download package from phpBB.com (fresh install), mods installed, British English, MySQL 4.1.14

User avatar
MPG187
Registered User
Posts: 519
Joined: Sun Apr 12, 2009 7:39 pm
Location: Operation420.net
Name: Operation 420
Contact:

Re: Recent topics listing on homepage

Post by MPG187 » Thu Dec 10, 2009 10:49 pm

bump
phpBB 3.0.4, http://operation420.net/forum, download package from phpBB.com (fresh install), mods installed, British English, MySQL 4.1.14

User avatar
tumba25
Former Team Member
Posts: 4430
Joined: Wed Jun 06, 2007 6:42 am
Location: Kokkola, Finland.
Name: Jari Kanerva
Contact:

Re: Recent topics listing on homepage

Post by tumba25 » Fri Dec 11, 2009 10:20 am

Activate debugging.

In config.php, remove the // in front of both debugging lines.
Need a mod/extension created/installed, other custom-coded solution or a server admin? https://tumba25.net

User avatar
MPG187
Registered User
Posts: 519
Joined: Sun Apr 12, 2009 7:39 pm
Location: Operation420.net
Name: Operation 420
Contact:

Re: Recent topics listing on homepage

Post by MPG187 » Fri Dec 11, 2009 10:05 pm

tumba25 wrote:Activate debugging.

In config.php, remove the // in front of both debugging lines.
It says not to edit the file and I don't see any debugging lines:

Code: Select all

<?php
// phpBB 3.0.x auto-generated configuration file
// Do not change anything in this file!
$dbms = 'mysql';
$dbhost = '';
$dbport = '';
$dbname = '';
$dbuser = '';
$dbpasswd = '';
$table_prefix = 'phpbb_';
$acm_type = 'file';
$load_extensions = '';

@define('PHPBB_INSTALLED', true);
// @define('DEBUG', true);
// @define('DEBUG_EXTRA', true);
?>
Last edited by tumba25 on Fri Dec 11, 2009 10:51 pm, edited 1 time in total.
Reason: Removed database info
phpBB 3.0.4, http://operation420.net/forum, download package from phpBB.com (fresh install), mods installed, British English, MySQL 4.1.14

User avatar
tumba25
Former Team Member
Posts: 4430
Joined: Wed Jun 06, 2007 6:42 am
Location: Kokkola, Finland.
Name: Jari Kanerva
Contact:

Re: Recent topics listing on homepage

Post by tumba25 » Fri Dec 11, 2009 10:50 pm

MPG187 wrote:It says not to edit the file and I don't see any debugging lines:

Code: Select all

// @define('DEBUG', true);
// @define('DEBUG_EXTRA', true);
Those lines say debug.

And you should change your db password ASAP, like yesterday.
Need a mod/extension created/installed, other custom-coded solution or a server admin? https://tumba25.net

User avatar
MPG187
Registered User
Posts: 519
Joined: Sun Apr 12, 2009 7:39 pm
Location: Operation420.net
Name: Operation 420
Contact:

Re: Recent topics listing on homepage

Post by MPG187 » Fri Dec 11, 2009 10:52 pm

Oh I didn't notice, I'm too depressed lately....

What makes you say I should change my database password?

EDIT: It looked in there and it said my password in plain text!

When I change my password, so I just enter the new one in that file?
phpBB 3.0.4, http://operation420.net/forum, download package from phpBB.com (fresh install), mods installed, British English, MySQL 4.1.14

User avatar
tumba25
Former Team Member
Posts: 4430
Joined: Wed Jun 06, 2007 6:42 am
Location: Kokkola, Finland.
Name: Jari Kanerva
Contact:

Re: Recent topics listing on homepage

Post by tumba25 » Fri Dec 11, 2009 10:56 pm

You publicised your dbuser and dbpassword in a open forum for anyone to read. That info should be kept secret.
Need a mod/extension created/installed, other custom-coded solution or a server admin? https://tumba25.net

User avatar
tumba25
Former Team Member
Posts: 4430
Joined: Wed Jun 06, 2007 6:42 am
Location: Kokkola, Finland.
Name: Jari Kanerva
Contact:

Re: Recent topics listing on homepage

Post by tumba25 » Fri Dec 11, 2009 10:57 pm

MPG187 wrote:When I change my password, so I just enter the new one in that file?
Yes. Remember that the password differs between upper and lower case.
Need a mod/extension created/installed, other custom-coded solution or a server admin? https://tumba25.net

joebart72
Registered User
Posts: 743
Joined: Thu Feb 01, 2007 5:54 am

Re: Recent topics listing on homepage

Post by joebart72 » Mon Dec 14, 2009 3:39 am

Hello :)

I've a problem to access this page... :oops:
I learn English with phpbb.com :)

User avatar
MPG187
Registered User
Posts: 519
Joined: Sun Apr 12, 2009 7:39 pm
Location: Operation420.net
Name: Operation 420
Contact:

Re: Recent topics listing on homepage

Post by MPG187 » Mon Dec 14, 2009 9:42 pm

tumba25 wrote:You publicised your dbuser and dbpassword in a open forum for anyone to read. That info should be kept secret.
Ya I didn't know my username and password were in that file, I didn't look I just copied and pasted, I thought there would be an md5 or something like a Linux Shadow file.

But thanks to these things no one was able to access my database.
  • You removing the information swiftly
  • Only me knowing the url to the database administrator and me making it not something obvious
phpBB 3.0.4, http://operation420.net/forum, download package from phpBB.com (fresh install), mods installed, British English, MySQL 4.1.14

User avatar
MPG187
Registered User
Posts: 519
Joined: Sun Apr 12, 2009 7:39 pm
Location: Operation420.net
Name: Operation 420
Contact:

Re: Recent topics listing on homepage

Post by MPG187 » Tue Dec 15, 2009 11:28 pm

I removed the comments out of the debugging lines and it's still blank.
phpBB 3.0.4, http://operation420.net/forum, download package from phpBB.com (fresh install), mods installed, British English, MySQL 4.1.14

User avatar
MPG187
Registered User
Posts: 519
Joined: Sun Apr 12, 2009 7:39 pm
Location: Operation420.net
Name: Operation 420
Contact:

Re: Recent topics listing on homepage

Post by MPG187 » Wed Feb 03, 2010 3:15 am

I used the code Pony99ca posted herebut it just appears blank when I open the php page :(

Do I have to modify it for my forum?
phpBB 3.0.4, http://operation420.net/forum, download package from phpBB.com (fresh install), mods installed, British English, MySQL 4.1.14

Locked

Return to “[3.0.x] MOD Writers Discussion”