Showing topics on outside (html) pages

Discussion forum for MOD Writers regarding MOD Development.
Locked
User avatar
PlanetMelb
Registered User
Posts: 135
Joined: Sat May 10, 2003 5:19 am

Showing topics on outside (html) pages

Post by PlanetMelb » Wed Jan 12, 2011 6:08 am

Hey guys, I hope I am posting in the correct place.

I am trying to show latest topics of the forum on my home (html) page. I followed the tutorial in this wiki article: http://wiki.phpbb.com/display/MODDOCS/P ... rnal+pages

I would like to use "Example 1: Display latest topics from specified forums" but am getting this error message:
Parse error: syntax error, unexpected '=' in /home/6-web/64/1f/mydomain.com.au/public/www/forum/home.php on line 27
The code I have used based on the tutorial is as follows:

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 : './';
$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 = 3; 
$forum_id = array(1, 3); 
$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", 'f=' . $topics_row['forum_id'] . '&t=' . $topics_row['topic_id'] . '&p=' . $topics_row['topic_last_post_id']) . '#p' . $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", 'f=' . $topics_row['forum_id'] . '&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('External page');

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

    page_footer();
?>
I would appreciate any help with this error message

User avatar
_Vinny_
Style Customisations
Style Customisations
Posts: 8363
Joined: Tue Aug 11, 2009 12:45 am
Location: Brazil
Name: Marcus Vinicius
Contact:

Re: Showing topics on outside (html) pages

Post by _Vinny_ » Wed Jan 12, 2011 8:39 pm

You need to put function described in the article.

Try 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 : './';
$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(1, 3);
$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", 'f=' . $topics_row['forum_id'] . '&t=' . $topics_row['topic_id'] . '&p=' . $topics_row['topic_last_post_id']) . '#p' . $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", 'f=' . $topics_row['forum_id'] . '&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('External page');

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

make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
page_footer();
?>
In your template, use this:

Code: Select all

<!-- INCLUDE overall_header.html -->
<!-- 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 -->
<!-- INCLUDE overall_footer.html --> 
You need only customize ;)

User avatar
PlanetMelb
Registered User
Posts: 135
Joined: Sat May 10, 2003 5:19 am

Re: Showing topics on outside (html) pages

Post by PlanetMelb » Wed Jan 12, 2011 11:01 pm

Thanks Vinny

U da man!

I will give it a crack from here :D

User avatar
_Vinny_
Style Customisations
Style Customisations
Posts: 8363
Joined: Tue Aug 11, 2009 12:45 am
Location: Brazil
Name: Marcus Vinicius
Contact:

Re: Showing topics on outside (html) pages

Post by _Vinny_ » Wed Jan 12, 2011 11:30 pm

You're welcome.

If you need any help with HTML, you may ask.

Locked

Return to “[3.0.x] MOD Writers Discussion”