Difficulties displaying post on external pages!

All web design discussion, including Ultimate Quiz MOD support.

Moderator: CricketMX Forum Moderators

Post Reply
User avatar
XHunter
Greenhorn
Greenhorn
Posts: 2
Joined: Thu Jun 03, 2010 12:51 pm
Contact:

Hi, I am upgrading my forum from phpBB2 too phpBB3 and I was trying to find a way to display topics from a specific forum on my websites front page for phpBB3 since I am currently using a mod that allows me too do just that for phpBB2. I stumbled upon your tutorial guide which has been extremely helpful, but I'm running into a little problem.

Here is just a little information so you know how I have things setup. When you go too my websites homepage, the index.php files looks like this

Code: Select all

<?php
ob_start ("ob_gzhandler");

include($_SERVER['DOCUMENT_ROOT'] . "/templates/site_header.php"); 
include($_SERVER['DOCUMENT_ROOT'] . "/news.php"); 
include($_SERVER['DOCUMENT_ROOT'] . "/templates/site_footer.php"); 
?>
the news.php file is what is extracting the topics from my phpbb3 forum onto my website too display as news.

The news.php looks like this

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(16);
    $forum_id_where = create_where_clauses($forum_id, 'forum');

    $posts_ary = array(
    'SELECT' => 'p.*, t.*',

    'FROM' => array(
    POSTS_TABLE => 'p',
    ),

    'LEFT_JOIN' => array(
    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'];
    $topic_author = get_username_string('full', $posts_row['topic_poster'], $posts_row['topic_first_poster_name'], $posts_row['topic_first_poster_colour']);
    $topic_date = $user->format_date($posts_row['topic_time']);
    $topic_link = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "t=" . $posts_row['topic_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),
    'TOPIC_AUTHOR' => $topic_author,
    'TOPIC_DATE' => $topic_date,
    'TOPIC_LINK' => $topic_link,
    'POST_TEXT' => censor_text($post_text),
    ));
    }

    $template->set_filenames(array(
    'body' => 'site_news.html'
    ));
	
   	page_footer();
    ?>
The problem I am having is that anything placed after the "page_footer();" is not loaded. For example, placing the "page_footer();" code at the bottom before the "?>" prevents only the include($_SERVER['DOCUMENT_ROOT'] . "/templates/site_footer.php"); command from the index.php too not load while placing the "page_footer();" near the top of the news.php file prevents the entire news / topic extraction to not be displayed.

I have noticed a previous topic discussing this issue. I have tried your solution for the problem which you gave in that topic with no luck. I understand that your time is very precious and any help you can give me is very much appreciated. Thank you for taking the time and reading my issue, I hope to hear back from you soon. In the mean time, I will continue to try and solve this problem.
User avatar
battye
Site Admin
Site Admin
Posts: 14395
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

Hi, welcome to CMX.

I think your problem should be fairly easy to fix fortunately. Try removing "page_footer();" completely from news.php and moving it to the bottom of site_footer.php :)
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)
User avatar
XHunter
Greenhorn
Greenhorn
Posts: 2
Joined: Thu Jun 03, 2010 12:51 pm
Contact:

Got, I managed too get the script working. What I found out was that by adding in the "page_footer();" to the bottom or even after the site_footer.php resulted in the news information being displayed after the footer. I dug deep into the functions.php file and found that "page_footer" calls upon to more functions

Code: Select all

	garbage_collection();
	exit_handler();[code]
[/code]

Upon removing each function separately, I found out that the exit_handler(); was the cause of the problem.

Code: Select all

* Handler for exit calls in phpBB.
* This function supports hooks.
*
* Note: This function is called after the template has been outputted.
*/
function exit_handler()
{
	global $phpbb_hook, $config;

	if (!empty($phpbb_hook) && $phpbb_hook->call_hook(__FUNCTION__))
	{
		if ($phpbb_hook->hook_return(__FUNCTION__))
		{
			return $phpbb_hook->hook_return_result(__FUNCTION__);
		}
	}

	// As a pre-caution... some setups display a blank page if the flush() is not there.
	(empty($config['gzip_compress'])) ? @flush() : @ob_flush();

	exit;
}
What appears to be a quick fix for the problem by adding in "//" in front of the exit; actually causes a bunch of other problems. For example, when clicking submit when posting a comment, the are talking too the "This message has been edited successfully." page but with an error at the bottom of the page and no footer, the header just repeats itself.

How you fix this problem is by adding in an if else state for the exit command.

Code: Select all

function exit_handler()
{
	global $phpbb_hook, $config;

	if (!empty($phpbb_hook) && $phpbb_hook->call_hook(__FUNCTION__))
	{
		if ($phpbb_hook->hook_return(__FUNCTION__))
		{
			return $phpbb_hook->hook_return_result(__FUNCTION__);
		}
	}

	// As a pre-caution... some setups display a blank page if the flush() is not there.
	(empty($config['gzip_compress'])) ? @flush() : @ob_flush();

	$homepage = "/";
	$currentpage = $_SERVER['REQUEST_URI'];
	if($homepage==$currentpage) 
	{
	exit(include($_SERVER['DOCUMENT_ROOT'] . "/template/site-footer.php"));
	}
		else
		{
		exit;
		}

}
As you can see from the code above, I define the value for homepage and current page and I place and IF statement saying that if the URL equals the root url, than exit and include the site-footer.php file. Else, just exit.
User avatar
battye
Site Admin
Site Admin
Posts: 14395
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

I think there will be a better way to do this than editing exit_handler. If it works for you and you are happy with it, that's fine. But if you show me you site_footer.php file and site_header.php file (you can PM them to me if you would like) I can see if there is a better alternative.
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)
Post Reply