Topic review

Get help with installation and running phpBB 3.0.x here. Please do not post bug reports, feature requests, or MOD-related questions here.
Suggested Hosts
Forum rules
END OF SUPPORT: 1 January 2017 (announcement)
d-fruit
Registered User
Posts: 167
Joined: Tue Apr 21, 2009 3:20 pm
Location: Estonia

Topic review

Post by d-fruit »

Hello!

I want make into my website with news from forum.

Image

Topic's from: viewforum.php?f=2

How? Thanks.
Last edited by ric323 on Mon Aug 02, 2010 10:19 pm, edited 1 time in total.
Reason: Topic icon changed
User avatar
_Vinny_
Style Customisations
Style Customisations
Posts: 10531
Joined: Tue Aug 11, 2009 12:45 am
Location: Brazil
Name: Marcus Vinicius

Re: Topic review

Post by _Vinny_ »

d-fruit
Registered User
Posts: 167
Joined: Tue Apr 21, 2009 3:20 pm
Location: Estonia

Re: Topic review

Post by d-fruit »

Thanks, but i have problem's.

viewforum.php?f=2

$forum_id = 2;

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 : '../board/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . '../board/common.' . $phpEx);
include($phpbb_root_path . '../board/includes/bbcode.' . $phpEx);
include($phpbb_root_path . '../board/includes/functions_display.' . $phpEx);

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

$search_limit = 5;

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

$topic_id = 2;
$topic_id_where = create_where_clauses($topic_id, 'topic');

/* 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;
}

$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),
));
}
?>
This contect shows only empty. What wrong i did? :?
Last edited by d-fruit on Mon Aug 02, 2010 8:04 am, edited 2 times in total.
d-fruit
Registered User
Posts: 167
Joined: Tue Apr 21, 2009 3:20 pm
Location: Estonia

Re: Topic review

Post by d-fruit »

Please help :( Contect still showing empty. What i did wrongly?
Last edited by d-fruit on Mon Aug 02, 2010 8:04 am, edited 1 time in total.
d-fruit
Registered User
Posts: 167
Joined: Tue Apr 21, 2009 3:20 pm
Location: Estonia

Re: Topic review

Post by d-fruit »

Please, i need help :?
User avatar
ric323
Former Team Member
Posts: 22910
Joined: Tue Feb 06, 2007 12:33 am
Location: Melbourne, Australia
Name: Ric

Re: Topic review

Post by ric323 »

Please be patient. We have a 6 hour bump limit rule on this forum. http://www.phpbb.com/rules/#rule4g
The Knowledge Base contains solutions to many common problems!
How to fix "Doesn't have a default value" and "Incorrect string value: xxx for column 'post_text' " errors.
How to do a clean re-install of the latest phpBB3 version.
Problems with permissions? Read phpBB3 Permissions
User avatar
Rahber
Former Team Member
Posts: 2720
Joined: Tue Feb 12, 2008 3:39 pm
Location: Pakistan
Name: Rahber

Re: Topic review

Post by Rahber »

the code you gave above is incomplete you didnt follow the exact instruction given in that article

you are missing the function that extract the posts

Code: Select all

/* 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;
}
beside you are not having a array of that forum its just the single id that you provided

here is complete working code that will extract 5 post from forum 2

Code: Select all

<?php

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './board/';
$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", "p=" . $topics_row['topic_last_post_id'] . "#" . $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", "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,
));
}
page_header('The title of your page goes here');

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

page_footer();
?>
and the rest is up to how you format home_body.html
d-fruit
Registered User
Posts: 167
Joined: Tue Apr 21, 2009 3:20 pm
Location: Estonia

Re: Topic review

Post by d-fruit »

Still doens't work. (Doens't showing topic's)

home_body.html

Code: Select all

<div class="post">
         <h1 class="title">{announcements.TOPIC_TITLE}</h1>
         <p class="byline"><small>By {announcements.TOPIC_AUTHOR} - {announcements.TOPIC_DATE}</small></p>
         <div class="entry">
                  {announcements.POST_TEXT}
         </div>
         <div class="meta">
            <p class="links"><a href="{announcements.TOPIC_LINK}" class="comments">Kommentaarid</a> &nbsp;&bull;&nbsp;&nbsp; <a href="{announcements.TOPIC_LINK}" class="more">Loe edasi &raquo;</a></p>
         </div>
      </div>
d-fruit
Registered User
Posts: 167
Joined: Tue Apr 21, 2009 3:20 pm
Location: Estonia

Re: Topic review

Post by d-fruit »

d-fruit wrote:Still doens't work. (Doens't showing topic's)

home_body.html

Code: Select all

<div class="post">
         <h1 class="title">{announcements.TOPIC_TITLE}</h1>
         <p class="byline"><small>By {announcements.TOPIC_AUTHOR} - {announcements.TOPIC_DATE}</small></p>
         <div class="entry">
                  {announcements.POST_TEXT}
         </div>
         <div class="meta">
            <p class="links"><a href="{announcements.TOPIC_LINK}" class="comments">Kommentaarid</a> &nbsp;&bull;&nbsp;&nbsp; <a href="{announcements.TOPIC_LINK}" class="more">Loe edasi &raquo;</a></p>
         </div>
      </div>
My time is messed up. ( I don't know, is over 6h or not. )

What i did wrong?

Need still help.
d-fruit
Registered User
Posts: 167
Joined: Tue Apr 21, 2009 3:20 pm
Location: Estonia

Re: Topic review

Post by d-fruit »

Image

It must be showing 5 topic's from forum. (forum id 2)

But doens't show it.

Domain is http://www.prica.eu/home/index.php
Forum is http://www.prica.eu/board/index.php

Topic's from is http://prica.eu/board/viewforum.php?f=2
User avatar
_Vinny_
Style Customisations
Style Customisations
Posts: 10531
Joined: Tue Aug 11, 2009 12:45 am
Location: Brazil
Name: Marcus Vinicius

Re: Topic review

Post by _Vinny_ »

d-fruit wrote:My time is messed up. ( I don't know, is over 6h or not. )

What i did wrong?

Need still help.
Post the code file and the template.
d-fruit
Registered User
Posts: 167
Joined: Tue Apr 21, 2009 3:20 pm
Location: Estonia

Re: Topic review

Post by d-fruit »

Case close.

PHP Programmer helped me this problem out.

Return to “[3.0.x] Support Forum”