Displaying posts to external page hiding my content

All web design discussion, including Ultimate Quiz MOD support.

Moderator: CricketMX Forum Moderators

Post Reply
junlee
Greenhorn
Greenhorn
Posts: 7
Joined: Tue Jan 04, 2011 1:36 am

Hello, I followed the tutorial on http://blog.phpbb.com/2009/11/09/how-to ... nal-pages/ to get my main page to display the latest 5 posts from a "News" section on my forums, and it is displaying correctly, however nothing else on the page is visible after the news feed. No text, images, tables, anything are able to be displayed while this code is active for some reason and I cannot figure it out. I noticed another user posted the same problem in a separate thread but it never seemed to have gotten resolved. Has anyone found out any other solutions to this since then?

Here is my code

Code: Select all

<?php
/*
* home.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 : './forums/';
$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(4, 4);
$forum_id_where = create_where_clauses($forum_id, 'forum');
 
$topic_id = array(20, 50);
$topic_id_where = create_where_clauses($topic_id, 'topic');


$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'    => 't.topic_first_post_id = p.post_id'
         ),
     ),
  
      'WHERE'     => str_replace( array('WHERE ', 'forum_id'), array('', 't.forum_id'), $forum_id_where) . '
                     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),
      ));
   }



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

page_footer();
?>
This code is inside of a table cell in my "news table", however taking it out of the table and just displaying it in the body does not resolve the issue. I am planning on adding quite a bit of content underneath this News table where the forum is being fed to. Is there some way replace the page_footer() call inside the php block with something else and still have the feed work?

I tried removing page_footer(); from the main php code and adding <?php page_footer(); ?> at the very bottom of my page, however all that did was display the forum feed on the very bottom of the page instead of in my News table.

Any help is appreciated, thanks!
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

If you don't mind, could you provide a link to the page in question so I can see the problem?

Also, if you are able to could you post the contents of newstemplate.html?

Thanks :)
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
junlee
Greenhorn
Greenhorn
Posts: 7
Joined: Tue Jan 04, 2011 1:36 am

yup.

here is the only page using the forum feed: http://locohq.com/index.php

it is supposed to have the same layout as this page: http://locohq.com/about

You can see the 'ad space' table that comes after the news content isn't showing up, causing the layout to be out of place too. Also there is a small bit of text at the bottom that is gone.

here is my newstemplate.html

Code: Select all

<!-- BEGIN announcements -->
<span style="font-size: 18px">  {announcements.TOPIC_TITLE} </span><br>
<span style="font-size: 10px">  Posted by: {announcements.POST_AUTHOR} on {announcements.POST_DATE}</span><br><br>
<span style="font-family: Arial, Helvetica, sans-serif" >{announcements.POST_TEXT}</span><br><br>
___________________________________________________________
<br><br>
<!-- END announcements -->
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

Try this, to the top of newstemplate.html add:

Code: Select all

<!-- INCLUDE overall_header.html -->
And at the bottom, add:

Code: Select all

<!-- INCLUDE overall_footer.html -->
Don't forget to purge the cache so the change takes effect :)
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
junlee
Greenhorn
Greenhorn
Posts: 7
Joined: Tue Jan 04, 2011 1:36 am

http://locohq.com/index.php

Well it just added a bunch of stuff to the news box, but still no luck on showing the content after the page_footer();
junlee
Greenhorn
Greenhorn
Posts: 7
Joined: Tue Jan 04, 2011 1:36 am

Ok just a quick update. I got it working by copying all of my html code from my index.php into my newstemplate.html file, and my index.php now just has your php forum code in it. Not sure if this is the best way but it seems to be working fine now.

Thanks for the help :)
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

You're welcome :)

That should be fine, by convention you are supposed to have most - if not all - of your HTML code inside the the template file (ie. newstemplate.html in your case). So it sounds like you've done it perfectly :)
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
junlee
Greenhorn
Greenhorn
Posts: 7
Joined: Tue Jan 04, 2011 1:36 am

Hello again!

My site has grown quite a bit since I first posted here, and I am sorta having some issues again with this script :(

Well let me explain that my site is a fansite for an online game (english version) and the korean version of the game gets updates ahead of the english version. So I have a new author that will post news from the korean version that I would like to display along side my regular site news, which I can accomplish easily by changing the $forum_id to read the korean section as well...but the issue is that his posts will be very long and have a lot of pictures and information, so his posts will dwarf the regular news posts that are around it and also make the main site page extremely long.

So I was trying to think of some solutions. Here were my thoughts:

1) I could make different News tabs to dynamically display the correct forum feed with javascript. I tried to duplicate your $posts_ary section but with different variable names so that I could use the script to load two different forum sections at once and display each separately in different <div> sections...but I completely broke the code trying that :p And since I cannot include anything after the page_footer(); call at the end of the script...all of my layout code is included in the template file. This means that I can't just simply call a php include to two separate pages and have them inside hidden <divs> that appear when someone clicks the corresponding link, as it will display my ENTIRE layout inside the div rather than just the forum topics.

2) Rather than displaying the full forum post, is there a way to only display like the first 400 characters or so as a preview, then just have a "Read More" link after it? This would be my favorite choice, I'd really like to do it but to be honest with you, I have no idea how to modify your code to accomplish such a thing!

3) Find a way to display the forum posts without using page_footer(), or modify it somehow to allow content to be displayed under it. This was the original goal when I first made the thread, and would still be nice so that I could include my page_footer.html rather than having to edit the hard coded template whenever my navbar on the side changes.

The best possible outcome would be choices 2 and 3, but we already discussed 3 before so I'm not sure if you figured out a way yet. But choice 2 would definitely be ideal if you knew how.

As always, any help is greatly appreciated.
Thanks!
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

Hi junlee. I have good news for you, number two is very easy to implement :)

Find:

Code: Select all

$post_text = nl2br($posts_row['post_text']);
And change it to:

Code: Select all

$post_text = nl2br(substr($posts_row['post_text'], 0, 400));
substr is a PHP function which returns a portion of a string. In this case, it starts at character 0 and displays the next 400.

To get a read more link, just implement $post_link which is used in the template variable POST_LINK :)
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
junlee
Greenhorn
Greenhorn
Posts: 7
Joined: Tue Jan 04, 2011 1:36 am

Ahh that works pretty well. The only issue I've found is that if the substring happens to be in the middle of a tag whenever it is cut off (I had a post in the middle of a <b></b> then the rest of the page was bolded). I could see potential problems if it cut off an image tag too, for example, but other than that it seems to be working fine.

I noticed phpbb3 has an option for "ATOM feed", which seems to just display posts in an xml format inside of a feed.php file. It doesn't give you a whole lot of options by default for how many feeds you want though. Have you looked into this at all? I'm not sure if it would be a viable alternative or not to your script. I'm guessing you would have to parse the XML tags in the feed.php file using something like AJAX...however that field is relatively new to me so I'm not too sure.

anyway, thanks again for the help :)
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

I think I might have a solution for the HTML tag not closing. Undo the changes in the previous post, and instead try this:

FIND

Code: Select all

$post_text = smiley_text($post_text);
AFTER ADD

Code: Select all

strip_bbcode($post_text, $posts_row['bbcode_uid']);
$post_text = substr($posts_row['post_text'], 0, 400);
How does that work?
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
junlee
Greenhorn
Greenhorn
Posts: 7
Joined: Tue Jan 04, 2011 1:36 am

Well, that makes the tags not do anything, but still shows every tag in the post. You can see the result in the "Second Impact Update" news post here http://test.locohq.com/
Post Reply