Pagina 1 van 1

Probleempje met post op externe pagina

Geplaatst: 07 mei 2011, 20:37
door Blaatkip
  • Adres van je forum: http://forums.dutchforce.eu
    Mods?:Niet echt wat phpbb codes
    Wanneer ontstond het probleem?nvt
    phpBB versie:nieuwste? vorige week gedownload


    Heb je onlangs iets veranderd aan je forum?nvt
    Wat is het probleem?
Ben bezig met het ontwerp van een clanpage die als 'core' phpbb gebruikt.
Nou ben ik opzoek geweest naar manieren om content van het forum rechtstreeks in de site te plaatsen met behulp van de Wiki en de forums.

Stap 1 ging heel makkeljk, ik wou een 'recent topic' sectie op de site, waar de 'laatst geplaatste topics' in staan en vond deze code:

Code: Selecteer alles

<?
    define('IN_PHPBB', true);
    $phpbb_root_path = './forums/'; // Path to phpbb folder
    $phpEx = substr(strrchr(__FILE__, '.'), 1);
    include($phpbb_root_path . 'common.' . $phpEx);
    include($phpbb_root_path . 'includes/functions_display.' . $phpEx);

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

    // Grab user preferences
    $user->setup();
?>
 

				 <?  
    /*** phpBB3 - Last Active Topics System ***/
    //Show last x topics
    define('TOPICS_LIMIT',10);

    // Create arrays
    $topics = array();
    
    // Get forums that current user has read rights to.
    $forums = array_unique(array_keys($auth->acl_getf('f_read', true)));
    
    // Get active topics.
    $sql="SELECT *
    FROM " . TOPICS_TABLE . "
    WHERE topic_approved = '1' AND " . $db->sql_in_set('forum_id', $forums) . "
    ORDER BY topic_last_post_time DESC";
    $result = $db->sql_query_limit($sql,TOPICS_LIMIT);
    while ($r = $db->sql_fetchrow($result))
    {
        $topics[] = $r;
    }
   $db->sql_freeresult($result);
?>
<div>
<?
        
    foreach($topics as $t)
    {
        // Get folder img, topic status/type related information
        $topic_tracking_info = get_complete_topic_tracking($t['forum_id'], $t['topic_id']);
        $unread_topic = (isset($topic_tracking_info[$t['topic_id']]) && $t['topic_last_post_time'] > $topic_tracking_info[$t['topic_id']]) ? true : false;
        $folder_img = $folder_alt = $topic_type = '';
        topic_status($t, $t['topic_replies'], $unread_topic, $folder_img, $folder_alt, $topic_type);
        
        // output the link
        ?>
            <img style="vertical-align: text-bottom" src="<?=$user->img($folder_img, $folder_alt, false, '', 'src');?>" title="<?=$user->lang[$folder_alt];?>" alt="<?=$user->lang[$folder_alt];?>" />
            <a href="<?=$phpbb_root_path . 'viewtopic.php?f=' . $t['forum_id'] . '&t=' . $t['topic_id'] . '&p=' . $t['topic_last_post_id'] . '#p' . $t['topic_last_post_id'];?>"><?=html_entity_decode($t['topic_title']);?></a><br />
    <?
    }
    ?>
Deze werkte meteen perfect en kon deze meteen integreren in m'n site:
http://www.dutchforce.eu/test3.php
Dit functioneerd prima, al zou ik de achtergrond images nog willen toevoegen, maar dat is voor latere zorg.

Daarna ben ik begonnen om de laatste 3, 1st posts uit het nieuws forum te plaatsen op de site en vond dit:
http://blog.phpbb.com/2009/11/09/how-to ... nal-pages/

Example 3 is volgens mij precies wat ik nodig heb maar krijg het niet voor elkaar, krijg of vage errors of helemaal witte pagina die niets doet en vroeg me af wat ik verkeerd doe.

even duidelijk op een rij wat de bedoeling is:
de 3 laatste 1st posts uit dit forum:
http://forums.dutchforce.eu/viewforum.php?f=13
in z'n geheel op een externe pagina.

Wat moet ik precies veranderen en hoe kom ik achter het forum id?

Alvast bedankt

Re: Probleempje met post op externe pagina

Geplaatst: 08 mei 2011, 18:32
door Kevin
Het forum ID vind je terug in de url die je ziet staan als je in dat forum zit.
voorbeeld:

Code: Selecteer alles

http://forums.dutchforce.eu/viewforum.php?f=13
Forum ID is hier dus "13"

Re: Probleempje met post op externe pagina

Geplaatst: 09 mei 2011, 15:35
door Blaatkip
Ben vandaag weer even bezig geweest, maar het wil nog steeds niet werken.

Kom tot nu toe niet verder als dit:
http://www.dutchforce.eu/last-post3.php

met onderstaande code:

Code: Selecteer alles

<?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');
?>
 

				 <?  
    /*** phpBB3 - Last Active Topics System ***/
    //Show last x topics
    define('TOPICS_LIMIT',10);

    // Create arrays
    $topics = array();
    
    // Get forums that current user has read rights to.
    $forums = array_unique(array_keys($auth->acl_getf('f_read', true)));
    
    // Get active topics.
    $sql="SELECT *
    FROM " . TOPICS_TABLE . "
    WHERE topic_approved = '1' AND " . $db->sql_in_set('forum_id', $forums) . "
    ORDER BY topic_last_post_time DESC";
    $result = $db->sql_query_limit($sql,TOPICS_LIMIT);
    while ($r = $db->sql_fetchrow($result))
    {
        $topics[] = $r;
    }
   $db->sql_freeresult($result);
?>
<div>
<?
        
    foreach($topics as $t)
    {
        // Get folder img, topic status/type related information
        $topic_tracking_info = get_complete_topic_tracking($t['forum_id'], $t['topic_id']);
        $unread_topic = (isset($topic_tracking_info[$t['topic_id']]) && $t['topic_last_post_time'] > $topic_tracking_info[$t['topic_id']]) ? true : false;
        $folder_img = $folder_alt = $topic_type = '';
        topic_status($t, $t['topic_replies'], $unread_topic, $folder_img, $folder_alt, $topic_type);
        
        // output the link
        ?>
            <img style="vertical-align: text-bottom" src="<?=$user->img($folder_img, $folder_alt, false, '', 'src');?>" title="<?=$user->lang[$folder_alt];?>" alt="<?=$user->lang[$folder_alt];?>" />
            <a href="<?=$phpbb_root_path . 'viewtopic.php?f=' . $t['forum_id'] . '&t=' . $t['topic_id'] . '&p=' . $t['topic_last_post_id'] . '#p' . $t['topic_last_post_id'];?>"><?=html_entity_decode($t['topic_title']);?></a><br />
    <?
    }
    ?>
<?php
/* 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;
}
?>
<?php
$search_limit = 5;
 
    $forum_id = array(2, 5);
    $forum_id_where = create_where_clauses($forum_id, '13');
 
    $topic_id = array(20, 50);
    $topic_id_where = create_where_clauses($topic_id, 'topic');
?>
<?php
   $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", 'f=' . $posts_row['forum_id'] . '&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),
         ));
      }
?>

Wat doe ik hier fout? misschien maar een php editor gaan gebruiken want notepad geeft niet echt veel overzicht...

Re: Probleempje met post op externe pagina

Geplaatst: 09 mei 2011, 15:44
door Ger
Sowieso geen gewoon notepad (kladblok) gebruiken! Dat is vragen om problemen, ook al met de codering.
Download liever een gratis programma als Notepad++ of Crimson Editor.

Dat terzijde: je error komt waarschijnlijk doordat je op lijn 20-23 dit hebt staan:

Code: Selecteer alles

?>


             <?  
Dat is vragen om problemen, want die witregels gelden als output. Aangezien je er toch niets tussen hebt staan, kun je die vast weghalen. Alles wat ervoor en erachter staat is toch PHP.

Re: Probleempje met post op externe pagina

Geplaatst: 09 mei 2011, 16:43
door Blaatkip
Heb dit inmiddels aangepast, maar helaas geen resultaat.

Zou even kijken naar de editors die je hebt geadviseerd.
Maar de code is dus verder wel correct?

Re: Probleempje met post op externe pagina

Geplaatst: 09 mei 2011, 16:59
door Ger
Blaatkip schreef:Heb dit inmiddels aangepast, maar helaas geen resultaat.
Jawel. De error die je krijgt verwijst nu naar een andere regel, namelijk 45:

Code: Selecteer alles

?>
<div>
<?
Waarom die div?
Blijkbaar wil je opmaak en functies combineren in 1 bestand, maar dat is vragen om problemen. Waarom hanteer je niet gewoon de methodes zoals aangegeven op de pagina's die je zelf al gevonden had?
Blaatkip schreef:Maar de code is dus verder wel correct?
Ik heb verder nog niet gekeken.

Re: Probleempje met post op externe pagina

Geplaatst: 09 mei 2011, 18:26
door Blaatkip
Ja, die had ik ook al weggehaald heb inmiddels ook alle slordige en overbodige ruimte weggehaald ect, maar werkt nog steeds niet.

Ik hanteer de methodes die aangegeven staat op die blogpagina, maar het is natuurlijk de bedoeling dat ik deze posts plaats in een site, die <div> stond er nog tussen.

Aangezien 'recent topics' wel meteen werkte dacht ik deze code gelijk in m'n html pagina te stoppen en te renamen, toen dit niet werkte heb ik alle html code eruit gehaald om te kunnen debuggen en die is blijkbaar blijven staan.

Re: Probleempje met post op externe pagina

Geplaatst: 10 mei 2011, 08:51
door Ger
Ik zie toch nog het een en ander aan HTML staan, buiten PHP tags. Zorg er dus eerst even voor dat je NIETS meer buiten PHP tags hebt staan, en ga dan verder debuggen.

Re: Probleempje met post op externe pagina

Geplaatst: 10 mei 2011, 15:20
door Blaatkip
Werd er zo gek van dat ik ff een nieuwe file heb gemaakt en alle code opnieuw erin geplakt.

Ben een klein beetje vooruit gekomen krijg nu geen errors meer op de pagina, maar hij laat nog steeds geen topics zien.

Code: Selecteer alles

<?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 = 3;
 
    $forum_id = array(2, 5);
    $forum_id_where = create_where_clauses($forum_id, '');
 
    $topic_id = array(20, 50);
    $topic_id_where = create_where_clauses($topic_id, 'topic');
	$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", 'f=' . $posts_row['forum_id'] . '&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),
         ));
      }
Voorbeeld hier:
http://www.dutchforce.eu/last-post5.php

Hij zegt nu: No type defined]

Dus waarschijnlijk moet ik ergens nog iets aanpassen maar wat?