Pagina 1 van 1

berichten extern tonen

Geplaatst: 10 mar 2011, 13:03
door michaelbrouwer
Hallo,

Ik wil graag forumberichten op een extern website weergeven, nu heb ik de wiki handleiding berichten 'Laatste berichten tonen op site' doorgelezen. Ik loop alleen nog tegen een probleem aan, moet ik de onderstaande gegevens allemaal op 1 pagina plaatsen?

Header

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 : './';
$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);
$
Functies

Code: Selecteer alles

<?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;
}
Forum en topic info

Code: Selecteer alles

<?php
$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'
4e optie

Code: Selecteer alles

<?php
     $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", '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),
         ));
      }
footer

Code: Selecteer alles

<?php
    page_header('External page');
 
    $template->set_filenames(array(
        'body' => 'external_body.html'
    ));
 
    page_footer();

Re: berichten extern tonen

Geplaatst: 10 mar 2011, 13:12
door Ger
Je moet er inderdaad 1 totaal PHP bestand van maken.

Re: berichten extern tonen

Geplaatst: 10 mar 2011, 13:28
door michaelbrouwer
Thanks voor de snelle reactie :D, ik neem aan de alleen bovenaan de pagina een <?php en onderaan de footer een ?> voldoende is

Re: berichten extern tonen

Geplaatst: 10 mar 2011, 14:12
door Ger
Jep.
Verplaatst naar 3.0 modificaties
- Ger

Re: berichten extern tonen

Geplaatst: 10 mar 2011, 14:42
door michaelbrouwer
Thanks, ik ga er vanavond mee aan de gang :D

Re: berichten extern tonen

Geplaatst: 11 mar 2011, 19:07
door michaelbrouwer
Ik heb alles op 1 pagina gezet, maar ik krijg nu de volgende melding.

Code: Selecteer alles

template->_tpl_load_file(): File ./forum/styles/prosilver/template/external_body.html does not exist or is empt

Re: berichten extern tonen

Geplaatst: 11 mar 2011, 20:52
door Ger
Ik zie dat dit niet helemaal juist uitgelegd is op de Wiki. Je probleem is, dat je nog een template moet maken. Dat is een HTML bestand wat je in die template map zet, en in dit geval external_body.html noemt. De inhoud daarvan is zoiets:

Code: Selecteer alles

<!-- BEGIN announcements -->
    Title: {announcements.TOPIC_TITLE}
    Author: {announcements.TOPIC_AUTHOR}
    Date: {announcements.TOPIC_DATE}
    Last post: {announcements.TOPIC_LAST_POST}
    Topic link: {announcements.TOPIC_LINK}
    <!-- END announcements -->
Plus eventuele extra HTML.