The Articles Topic

All updates to the site will be posted here.

Moderator: CricketMX Forum Moderators

Re: Working example of displaying latest posts on external p

Postby battye » Tue Jul 19, 2011 3:09 pm

markoff wrote:
Articles Bot wrote:
This article is a follow-on from the blog post I made at phpBB.com not too long ago. I recommend reading that post first before reading this, as all of the information you need might be in that po...


Read more



Hello, I was wondering if you had any tips for adding a "View older entries" at the bottom of the blog posts, from the main page. So I could display 10 blog posts, and then click the link to view another 10 older posts.

Thanks. Using your blog code now and it helped me out a lot


Hi markoff, welcome to CMX :)

See this code here:

Code: Select all
$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);


See how sql_query_limit is used? Information about that can be found at http://wiki.phpbb.com/Dbal.sql_query_limit
So $db->sql_query_limit($topics, 10, 10); would select 10 results with an offset of 10 (ie. results 10 to 20).

Do you have any experience with PHP? Because you could do this dynamically by introducing another variable to put as the 3rd parameter (after $search_limit) which changes from 0 to 10 depending on whether the "display more" link has been clicked. If not, let me know and I can help you out with this :)
CricketMX.com.. home of bat's, rat's and other farmyard animals...
My articles: view all articles by battye

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
User avatar
battye
Site Admin
Site Admin
 
Posts: 14253
Joined: Sun Jan 11, 2004 8:26 am
Location: Victoria Falls, Zimbabwe

Re: The Articles Topic

Postby markoff » Wed Jul 20, 2011 12:53 pm

Thanks so much.. that is exactly what I needed to know. I am learning PHP as I go and have been modifying your code a bit to serve my needs. Its a lot of fun and this setup has added an entirely new dimension to my site.. I really appreciate it!
markoff
Greenhorn
Greenhorn
 
Posts: 2
Joined: Mon Jul 18, 2011 8:20 pm

Re: Working example of displaying latest posts on external p

Postby neljan » Wed Jul 20, 2011 11:19 pm

Articles Bot wrote:
This article is a follow-on from the blog post I made at phpBB.com not too long ago. I recommend reading that post first before reading this, as all of the information you need might be in that po...


Read more


Me again :)

I'm using the function to display the contents of posts on external pages, then :

Code: Select all
$search_limit = 1;

$forum_id = array(834);
$forum_id_where = create_where_clauses($forum_id, 'forum');

$topic_id = array(11497);
$topic_id_where = create_where_clauses($topic_id, 'topic');

$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'     =>  str_replace( array('WHERE ', 'topic_id'), array('', 't.topic_id'), $topic_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'];
         $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'] . '&amp;t=' . $posts_row['topic_id'] . '&amp;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),
         ));
      }


The problem is, if I choose to display posts from a forum that a user does not have permissions to, they get this error:

SQL ERROR [ mysql4 ]

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND t.topic_status <> 2 AND t.topic_approved = 1 ORDER ' at line 2 [1064]

Perhaps a bug?

anyway, since the forum I'm targetting is a hidden forum, intended for staff to post announcements to be displayed on external pages for everyone (regardless of whether they have access to the hidden forum or not) I would like to remove the part of the function that checks for permissions.

Should I delete (from functions)...
Code: Select all
$auth_f_read = array_keys($auth->acl_getf('f_read', true));


Then change...
Code: Select all
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);

Or is it something else?

Thanks very much.
neljan
Greenhorn
Greenhorn
 
Posts: 5
Joined: Tue Jun 28, 2011 4:18 pm

Re: The Articles Topic

Postby neljan » Wed Jul 20, 2011 11:30 pm

Ok I changed this:

$auth_f_read = array_keys($auth->acl_getf('f_read', true));

to

$auth_f_read = array_keys($auth->acl_getf('f_read', false);

to fix it.
neljan
Greenhorn
Greenhorn
 
Posts: 5
Joined: Tue Jun 28, 2011 4:18 pm

Re: Working example of displaying latest posts on external p

Postby frantic purple » Mon Oct 10, 2011 7:14 pm

Okay so I got the script to work perfectly, but now I'm having trouble with the page it's on. Here's the process I went through at phpBB.com: http://www.phpbb.com/community/posting.php?mode=edit&f=71&p=13061904. Anything I put after the script will not show up on the webpage. I think it has something to do with the script not finishing or something but I'm not entirely sure or how to fix it for that matter. Here's the script:

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 : './forum/';
$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(1, 4);
    $forum_id_where = create_where_clauses($forum_id, 'forum');

    $topic_id = array();
    $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'] . '&amp;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),
         ));
      }


page_header('External page');

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

    page_footer();


Thanks in advance. :)
frantic purple
Greenhorn
Greenhorn
 
Posts: 10
Joined: Mon Oct 10, 2011 7:06 pm

Re: The Articles Topic

Postby battye » Tue Oct 11, 2011 2:44 pm

Hi frantic purple, welcome to CMX :)

What do you mean by "anything you put after the script"?

The last line is page_footer(), so you won't be able to see anything that is done after that point because the footer has already been drawn to the screen :)
CricketMX.com.. home of bat's, rat's and other farmyard animals...
My articles: view all articles by battye

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
User avatar
battye
Site Admin
Site Admin
 
Posts: 14253
Joined: Sun Jan 11, 2004 8:26 am
Location: Victoria Falls, Zimbabwe

Re: The Articles Topic

Postby frantic purple » Tue Oct 11, 2011 6:13 pm

battye wrote:Hi frantic purple, welcome to CMX :)

What do you mean by "anything you put after the script"?

The last line is page_footer(), so you won't be able to see anything that is done after that point because the footer has already been drawn to the screen :)

Thanks for the quick response. What I mean by "anything you put after the script" is anything on the index page of my website after the script. For example I have my own footer I would like to place on the website separate from the script, but any HTML, PHP, etc, won't show on the index page after the script has been run. It will however show on the index page if I delete the page_footer(); line in the script. But when I delete the page_footer(); line then the script doesn't show on the index page and the website footer does. So I guess my question is what can I do to have the script and my website footer show on my website index page? Do I have to change something in page_footer(); file? Thank you so much this has been bugging me for weeks. :]
frantic purple
Greenhorn
Greenhorn
 
Posts: 10
Joined: Mon Oct 10, 2011 7:06 pm

Re: The Articles Topic

Postby battye » Fri Oct 14, 2011 1:34 pm

There are a number of ways you could do it. The one that springs to mind for me would be to actually edit overall_footer.html (in styles/prosilver/template) and add a conditional statement to display your desired website footer. ie.

Code: Select all
<!-- IF IN_WEBSITE --> html code here... <!-- ENDIF -->


And then modify a bit of the PHP so the templating variable IN_WEBSITE is set to true when this script is being run.

Another option is, if you don't want your script to look like phpBB, to remove all of the templating references and just echo the output. Then you can style it using HTML in any way you want :)
CricketMX.com.. home of bat's, rat's and other farmyard animals...
My articles: view all articles by battye

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
User avatar
battye
Site Admin
Site Admin
 
Posts: 14253
Joined: Sun Jan 11, 2004 8:26 am
Location: Victoria Falls, Zimbabwe

Re: The Articles Topic

Postby frantic purple » Fri Oct 14, 2011 8:46 pm

battye wrote:There are a number of ways you could do it. The one that springs to mind for me would be to actually edit overall_footer.html (in styles/prosilver/template) and add a conditional statement to display your desired website footer. ie.

Code: Select all
<!-- IF IN_WEBSITE --> html code here... <!-- ENDIF -->


And then modify a bit of the PHP so the templating variable IN_WEBSITE is set to true when this script is being run.

Another option is, if you don't want your script to look like phpBB, to remove all of the templating references and just echo the output. Then you can style it using HTML in any way you want :)

Okay so I think I'm going with option 2 because I would like to have my main website not look like phpBB. All I want is for the posts from one forum (http://meanvent.com/forum/index.php > News & Updates) to show on the website (http://meanvent.com/). Everything looks and works perfectly, except once the PHP script runs the rest of the code gets cut off. Looking at the source code from the index page it seems that the code after the PHP script is not even getting retrieved, which leads me to believe that the PHP script is somehow stopping at the end and not allowing for the rest of the page to do its thing. So, if I'm right, then what exactly do I need to change in the PHP script to make it so all the code after the script will get retrieved (and show up on the page)? Or is there a better way to retrieve the latest posts from a certain forum? Thank you so much. I apologize for the repeated questions, and for not quite getting it.

Website index code
Code: Select all
<?php include("site/template/config.php"); ?>

<head>

<meta http-equiv="content-type" content="text/html;charset=utf-8" />

<title>MeanVent Studios | Home</title>

</head>

<body>

<?php include("site/template/theupdater.php"); ?>

<b>Hello</b>

<?php include("site/template/footer.php"); ?>

<i>Testing Testing One Two...is this thing on?</i>

</body>


Internet source code
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<link rel="stylesheet" type="text/css" href="../styles/global.css" />

<html>
<head>

<meta http-equiv="content-type" content="text/html;charset=utf-8" />

<title>MeanVent Studios | Home</title>

</head>

<body>

<html>
<head>
<style type="text/css">
body
{
background-color:#FFFFFF;
}
h1
{
font-family:"Courier New";
font-size:20px;
font-weight:bold;
font-style:normal;
color:purple;
}
h2
{
font-family:"Arial";
font-size:14px;
font-weight:normal;
font-style:italic;
color:green;
}
</style>
</head>

<body>


<h1>MeanVent Has Begun</h1>
<h2>September 17th, 2011, 1:34 pm</h2>
Written by <a href="./forum/memberlist.php?mode=viewprofile&amp;u=2" style="color: #AA0000;" class="username-coloured">frantic purple</a><br /><br />

With Blinding Light signing on for the first time, MeanVent Studios has finally started to step towards its ultimate goal of becoming a game development studio, among other things. The first task we Meanies have is to build up our own fortress, our castle, our home: our website. After that we will begin to explore the many ideas we have for our first game. We will let you in on more details soon....<br />
<br />
Forum Registration has now been disabled due to the infinite amount of spammers creating an account. Registration will be back on when we post the first big update for our very first game. Thank you for understanding.<br /><br />
<a href="./forum/viewtopic.php?f=4&amp;t=20">Read more</a><hr /><br /><br />


</body>
</html>

As you can see, these lines are in the index code, but do not show on the internet source code:
Code: Select all
<b>Hello</b>

<?php include("site/template/footer.php"); ?>

<i>Testing Testing One Two...is this thing on?</i>


PHP script
Website directory: ("site/template/theupdater.php")
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 : './forum/';
$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(1, 4);
    $forum_id_where = create_where_clauses($forum_id, 'forum');

    $topic_id = array();
    $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'] . '&amp;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),
         ));
      }


page_header('External page');

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

    page_footer();
frantic purple
Greenhorn
Greenhorn
 
Posts: 10
Joined: Mon Oct 10, 2011 7:06 pm

Re: The Articles Topic

Postby battye » Sat Oct 15, 2011 5:29 am

You need to get rid of the templating references is theupdater.php. Like this:

Code: Select all
page_header('External page');

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

    page_footer();


And instead of having $template->assign_block_vars('announcements', array(.... replace each with an echo. Like:

Code: Select all
echo censor_text($topic_title);
echo $topic_author;
...
echo censor_text($post_text);


Then you can remove the echo's and add formatting to them (ie. echo '<br />'; for a new line) as necessary :)
CricketMX.com.. home of bat's, rat's and other farmyard animals...
My articles: view all articles by battye

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
User avatar
battye
Site Admin
Site Admin
 
Posts: 14253
Joined: Sun Jan 11, 2004 8:26 am
Location: Victoria Falls, Zimbabwe

Re: The Articles Topic

Postby frantic purple » Sat Oct 15, 2011 9:22 pm

Okay so what exactly do I delete from this code:
Code: Select all
page_header('External page');

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

        page_footer();

And what exactly do I replace the deleted part with? Also do I delete external_body.html? (forum/styles/prosilver/template/external_body.html). Or do I need to change or delete only part of it?

external_body.html:
Code: Select all
<html>
<head>
<style type="text/css">
body
{
background-color:#FFFFFF;
}
h1
{
font-family:"Courier New";
font-size:20px;
font-weight:bold;
font-style:normal;
color:purple;
}
h2
{
font-family:"Arial";
font-size:14px;
font-weight:normal;
font-style:italic;
color:green;
}
</style>
</head>

<body>

<!-- BEGIN announcements -->
<h1>{announcements.TOPIC_TITLE}</h1>
<h2>{announcements.TOPIC_DATE}</h2>
Written by {announcements.TOPIC_AUTHOR}<br /><br />
{announcements.POST_TEXT}<br /><br />
<a href="{announcements.TOPIC_LINK}">Read more</a><hr /><br /><br />
<!-- END announcements -->

</body>
</html>


Or do I need to change the page_footer(); file? Because when I delete this the rest of the index page shows, but the script doesn't work. Thank you so much, sorry for not understanding the previous post.
frantic purple
Greenhorn
Greenhorn
 
Posts: 10
Joined: Mon Oct 10, 2011 7:06 pm

Re: The Articles Topic

Postby battye » Sun Oct 16, 2011 4:11 pm

You can remove all of

Code: Select all
page_header('External page');

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

        page_footer();


And where you have

Code: Select all
$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),
         ));


You can also remove that too, but replace it with things like

Code: Select all
echo censor_text($topic_title);
echo $topic_author;
... (etc)
echo censor_text($post_text);


To output the various bits you want shown.

You don't need to change page_footer(). Don't delete external_body.html just yet. By the end of this it won't serve a purpose, but I wouldn't get rid of it just yet.
CricketMX.com.. home of bat's, rat's and other farmyard animals...
My articles: view all articles by battye

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
User avatar
battye
Site Admin
Site Admin
 
Posts: 14253
Joined: Sun Jan 11, 2004 8:26 am
Location: Victoria Falls, Zimbabwe

Re: The Articles Topic

Postby frantic purple » Sat Oct 22, 2011 2:55 am

Okay so now the script "theupdater" looks like 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 : './forum/';
$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(1, 4);
    $forum_id_where = create_where_clauses($forum_id, 'forum');

    $topic_id = array();
    $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'] . '&amp;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);


    echo censor_text($topic_title);
    echo $topic_author;
    ... (etc)
    echo censor_text($post_text);
}

Here's the webpage code that I wrote:
Code: Select all
<?php include("site/template/config.php"); ?>

<meta http-equiv="content-type" content="text/html;charset=utf-8" />

<head>

<title>MeanVent Studios | Home</title>

<meta name="description" content="Changing the rules of video game development. And being mean while doing it." />

</head>

<body>

<?php include("site/template/theupdater.php"); ?>

<b>Hello</b>

<?php include("site/template/footer.php"); ?>

<i>Testing Testing One Two...is this thing on?</i>

</body>

However the webpage http://www.meanvent.com is blank. Here's the webpage source code:
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<link rel="stylesheet" type="text/css" href="../styles/global.css" />

<html>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />

<head>

<title>MeanVent Studios | Home</title>

<meta name="description" content="Changing the rules of video game development. And being mean while doing it." />

</head>

<body>

As you can see the script "theupdater" and all of the code underneath does not show in the source code. The other problem of course being the script "theupdater" no longer working.
frantic purple
Greenhorn
Greenhorn
 
Posts: 10
Joined: Mon Oct 10, 2011 7:06 pm

Re: The Articles Topic

Postby battye » Sun Oct 23, 2011 4:45 pm

I'm surprised it didn't return an error message! I actually think it is but the error is being suppressed (due to the level of error reporting on your site), hence there is a blank page.

I didn't actually mean to put ... (etc) in the code, I meant "et cetera" for the "output the various bits you want shown". So if you want to output the topic date for example, you would include echo $topic_date; but if you didn't want to include the topic date then you wouldn't include that part. Please read the bottom viewtopic.php?p=106839#p106839 (the post above) very carefully. Notice how what is one the right hand side of the => is being used in the echo lines.
CricketMX.com.. home of bat's, rat's and other farmyard animals...
My articles: view all articles by battye

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
User avatar
battye
Site Admin
Site Admin
 
Posts: 14253
Joined: Sun Jan 11, 2004 8:26 am
Location: Victoria Falls, Zimbabwe

Re: The Articles Topic

Postby frantic purple » Sun Oct 23, 2011 7:59 pm

It works now, I just don't know how to format it. I tried adding some tags like <h1>, etc. but I couldn't get any to work, so I guess I just need to know where to put them to format the output of the script. Here's the script "theupdater" as is:
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 : './forum/';
$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(1, 4);
    $forum_id_where = create_where_clauses($forum_id, 'forum');

    $topic_id = array();
    $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'] . '&amp;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);


    echo $topic_title;
    echo $topic_date;
    echo $topic_author;
    echo $post_text;
    echo $topic_link;
}

Here's the webpage the script is on: http://www.meanvent.com/. As you can see everything is there, it just needs to be formatted to look nice and pretty. So where do I add the formatting tags <>, like <b>, etc. in the script to format it? Or do I do something else to format it? Thank you so much! Oh and I didn't add the "censor" part after the "echo". Should I add "censor" or is there any point to it? Also the "echo $topic_link" shows but not as a link. It's probably pretty simple but what do I do to make it show as a link on the webpage? Thank you so much, sorry for the question overload.
frantic purple
Greenhorn
Greenhorn
 
Posts: 10
Joined: Mon Oct 10, 2011 7:06 pm

PreviousNext

Return to Updates

Who is online

Users browsing this forum: No registered users and 1 guest

cron