I am trying to integrate Forum Feeds of a PHPBB3 Forum into an external Frontpage.
For this I'm using an example from the phpbbwiki : here is the code
My problem is that this only works if the user is authenticated on the forum allready, but I would like the user to see topics that are open to guest users, instead of a PHPBB default (blank-)page.
In this case I am using ajax to return topics in JSON, but this should not really matter for my problem here.
It would be good to know if this is achievable within the scope of what PHPBB is able to deliver and where to start looking if this is a more complicated problem.
If this is a simple matter for some of you I would be grateful for help.
Thank you!
update
The SQL Statement for retrieval of the posts is not created, because the user does not seem to have read permissions. The conditional that fails is (funnction: create_where_clauses) :
// 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) )
where id_check is the current forum_id.
Here is part of the user data object:
["user_id"] => string(1) "1"
["user_type"]=> string(1) "2"
["group_id"] => string(1) "1"
This User is in the GUESTS Group and its type is IGNORE by default. I'have tried setting user_type to 0=NORMAL - to no avail.
As a normal visitor on the PHPBB3 Forum I can read all open forums and I wonder why this generic guest user cannot access the forums.
update and sollution
I want to thank you for the answer that brought me on track again. I would have searchted endlessly for a sollution in the depths of PHPBBs user management when the original mistake I made was just a dumb copy/paste problem...
$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');
These two lines where taken from the tutorial and still in place when trying to retrieve data from "all" forums and topics. Incidentally those Forum Id's where open to registered users and closed to non-authenticated users. When lifiting the above content restrictions the script again performs as it should be.
So again - extra thanks goes to Andy.
The blank page is because you don't have a external_body.html
file in your style/prosilver/templates
directory.
A very basic external_body.html
will look something like this. Obviously, you'll have to integrate this into your home page's theme.
<!-- BEGIN announcements -->
Title: {announcements.TOPIC_TITLE}<br />
Post author: {announcements.POST_AUTHOR}<br />
Post date: {announcements.POST_DATE}<br />
Last post text: {announcements.POST_TEXT}<br />
Post link: {announcements.POST_LINK}
<!-- END announcements -->
Then, using the file provided by battye of the phpBB.com MOD team, and putting it in the root of your forum, you can show the most recent posts.
external_page.php
<?php
/*
* Description: example file for displaying latest posts and topics
* by battye (for phpBB.com MOD Team)
* September 29, 2009
* Modified for StackOverflow Question: http://stackoverflow.com/questions/14723578/phpbb3-forum-feed-on-external-page-for-non-authenticated-users
*/
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$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');
$search_limit = 5;
// ----- Change between HERE -----
$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", "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),
));
}
// --- and HERE ---
page_header('External page');
$template->set_filenames(array(
'body' => 'external_body.html'
));
page_footer();
?>
If you don't want this in the root of your forum, you need to modify this line to use the appropriate path to point to the root of your forum:
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
The two lines indicating where to change your block of code are the heart of what gets displayed. Above, I've posted Example 4 from your supplied link. Replacing the entire block of code from the other examples will work as well.
Finally, you may need to clear your cache from the ACP when you make template changes.
来源:https://stackoverflow.com/questions/14723578/phpbb3-forum-feed-on-external-page-for-non-authenticated-users