1

Topic: Phpbb3 latest posts on your homepage. Customizable.

Hello.

This modification shows phpbb3 latest post on your homepage.

It's working very fine on my site since I added it in september 2010.

(Another modification you may be interested in is here: >>> MODIFICATION TO PERFECTLY INTEGRATE A PHPBB3 FORUM INTO VLDPERSONALS <<<).

This modification allows you to set:
a) how many latest posts to display
b) how many characters of each post to display
c) the forums you want to exlude from showing in home page using forum IDs (useful for private/hidden/moderators sections of your forum)

NOTE: This has been created for vldpersonals 2.5.6 and for template REDLOVE. It worked on phpBB 3.0.7 PL1 and it's working on 3.0.8.
I don't know if it works on newest vldp versions and maybe you have to customize it to fit your own template.

IMPORTANT: I don't want to be responsible for any damage to your website and database.
So, REMEMBER TO BACKUP BEFORE YOU TRY.

After you try, please post your feedback to say if it works with vldpersonal versions after 2.5.6 and other templates than RedLove.
This will help other people to use and customize it.

1) Create a new file and name it latest_posts.php

2) Copy and paste into it the following code:

<?php
//    error_reporting(0);
    define('IN_PHPBB', true);

include_once ('');            //Path to phpBB Config File. Due to some restrictions by PHP, you have to provide complete physical path
$urlPath = "";                //phpBB URL with respect to root
$topicnumber = ;            //Total Post Count to Display
$posttext = ;                //Number of Characters to display in Post Text
$excludedforums = "";        //Forum ids to exclude. Each forum id should be seprated with Comma
$completeurl = "";

    $table_topics = $table_prefix. "topics";    //Usually you don't have to change below 4 variables
    $table_forums = $table_prefix. "forums";
    $table_posts = $table_prefix. "posts";
    $table_users = $table_prefix. "users";

function stripBBCode($text_to_search) {
     $pattern = '|[[\/\!]*?[^\[\]]*?]|si';
     $replace = '';
     return preg_replace($pattern, $replace, $text_to_search);
}



    $link = mysql_connect("$dbhost", "$dbuser", "$dbpasswd") or die("Could not connect");
    mysql_select_db("$dbname") or die("Could not select database");
    $sub_query = '';
    if(strlen($excludedforums) > 0) {
        $pieces = explode(",", $excludedforums);
        foreach ($pieces as $exforumid) {
            $sub_query .= " t.forum_id != " . $exforumid . ' AND ';
            }
    }

    $query = "SELECT t.topic_id, t.topic_title, t.topic_last_post_id, t.forum_id, p.post_id, p.poster_id, p.post_time, u.user_id, u.username, f.forum_name, p.post_text, p.bbcode_uid, p.bbcode_bitfield, f.forum_desc_options
    FROM $table_topics t, $table_forums f, $table_posts p, $table_users u
    WHERE t.topic_id = p.topic_id AND
    f.forum_id = t.forum_id AND ";

    if(strlen($sub_query) > 0) {
        $query .=  $sub_query ;
    }

    $query .= " t.topic_status <> 2 AND
    p.post_id = t.topic_last_post_id AND
    p.poster_id = u.user_id
    ORDER BY p.post_id DESC LIMIT $topicnumber";
    //echo $query;
    $result = mysql_query($query) or die("Query failed" . mysql_error($link));

    print "<div class=\"typecontent\">";
    if($topicnumber % 2) {
        $x="even";
    } else {
        $x="odd";
    }
    $y=0;
 while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    ++$y;
    if ($y==$topicnumber) {
        $x= $x .  " dataitemlast";
    }
    print "<div class=\"dataitem $x \">
                <table class=\"plain\">
                    <tr>
                        <td class=\"data\">
                                <div class=\"itemheader\">
                                    <h2 class=\"inner\">" .  $row["topic_title"] . "</h2>
                                        <ul class=\"itemheader\">
                                            <li>Posted at: " . date('F j, Y, g:i a', $row["post_time"])  . "</li>
                                            <li>By: <a href=\"$completeurl/$row[username]\">" .
                                            $row["username"]  . "</a></li> <li>In Forum: " . $row["forum_name"] . " </li>
                                        </ul>
                                </div>
                            <div class=\"entry\">" .
                                substr(stripBBCode($row["post_text"]),0,$posttext) . "<a href=\"$urlPath/viewtopic.php?f=$row[forum_id]&t=$row[topic_id]&p=$row[post_id]#p$row[post_id]\" style=\"text-decoration:none;font-weight:bold\"> Read more...</a>
                            </div>
                        </td>
                    </tr>
                </table>
                </div>";

                if ($x=="odd") {
                    $x="even";
                } else {
                    $x="odd";
                }

}
print "<div class=\"clear\"></div></div>";
    mysql_free_result($result);
//  mysql_close($link);
?>

3) Customize the file latest_posts.php this way:

>>> Set the following rows (from #5 to #10)

include_once ('');            //Path to phpBB Config File. Due to some restrictions by PHP, you have to provide complete physical path.
$urlPath = "";                //phpBB URL with respect to root
$topicnumber = ;            //Total Post Count to Display
$posttext = ;                //Number of Characters to display in Post Text
$excludedforums = "";            //Forum ids to exclude. Each forum id should be separated with Comma
$completeurl = "";


>>> EXAMPLE
include_once ('/home/mysite.com/public/phpbb3/config.php');            //Path to phpBB Config File. Due to some restrictions by PHP, you have to provide complete physical path
$urlPath = "/phpbb3";            //phpBB URL with respect to root
$topicnumber = 5;            //Total Post Count to Display
$posttext = 200;            //Number of Characters to display in Post Text
$excludedforums = "1,3,8,14";        //Forum ids to exclude. Each forum id should be separated with Comma
$completeurl = "http://www.mysite.com";

>>> NOTE: For the correct fisical path to phpBB config file, check to your web host.

4) upload the file latest_posts.php into your template folder (e.g.: /templates/webby2/)

5) open templates/YOURTEMPLATE/homepage.tpl (e.g.: /templates/webby2/homepage.tpl)

6) add the following script where you want to add latest forum posts

<h3 class="blogs">Latest Forum Posts</h3>
<div class="block blogs">
    <!-- INCLUDE latest_posts.php -->
</div>

7) ENJOY!

8) Remember to add your feedback into this forum. (Does this modification work on your vldpersonals version and within your template?)

Last edited by orange_slice (2011-02-14 02:31:11)

2

Re: Phpbb3 latest posts on your homepage. Customizable.

The part saying :var/www/virtual
can be different. Check your webhoster for the exact path

Good luck

Vld comercial version 2.6

3

Re: Phpbb3 latest posts on your homepage. Customizable.

Richard1969 wrote:

The part saying :var/www/virtual
can be different. Check your webhoster for the exact path

Good luck

thanks I did it and now it is working great smile
include_once ('/home/mysite/public_html/forum/config.php');

I ask my host and they tell me it should be this path !

(mysite=the name of your account on your host)

Give the world the best you have, and the best will come to you.
Tutorials and Mods for VldPersonals  Add CometChat to your vldPersonals site

4

Re: Phpbb3 latest posts on your homepage. Customizable.

gugu wrote:
Richard1969 wrote:

The part saying :var/www/virtual
can be different. Check your webhoster for the exact path

Good luck

thanks I did it and now it is working great smile
include_once ('/home/mysite/public_html/forum/config.php');

I ask my host and they tell me it should be this path !

(mysite=the name of your account on your host)

I modified installation instructions.
I don't remember anymore if
include_once ('/home/mysite/public_html/forum/config.php');
has to include the domain.
Example:
include_once ('/home/mysite.com/public_html/forum/config.php');

P.S. Which vldpersonal version an template are you using?

PP.SS. Read my signature for another modification for PhpBB3. It's working great.

Last edited by orange_slice (2011-02-12 14:01:19)

5

Re: Phpbb3 latest posts on your homepage. Customizable.

Your domain is not relevant its your account name with your webhost that counts.
Im using 2.5.7 vld and a modified template based on the nightlife template.
I didnt use your integration of phpbb3 but i will test it later this week. I will let you know how it turns out.

Vld comercial version 2.6

6

Re: Phpbb3 latest posts on your homepage. Customizable.

Richard1969 wrote:

Your domain is not relevant its your account name with your webhost that counts.

I know it.
I asked just to modify the installation instructions to be more helpful for people that could have problems during installation.

I suppose both modifications shoud work with new vldpersonals versions.
About templates, I think customization needs just a little work.

I hope modifications help all people using phpBB3 into vldpersonals.

7

Re: Phpbb3 latest posts on your homepage. Customizable.

I have a weir behaviour and I get no error whatsoever with the following: your tutorial works great, but we want smilies to show properly se we added a simple search and replace usin str_replace function. Now weird thing is - if I run the latest_post.php as standalone script it returns correct format, smileys are showing etc. but when I include the script in the template it breaks at the point of inclusion. Any idea why? there are no errors or warnings on php side, strange.

so:


$search = "{SMILIES_PATH}";
$replace = "/forum/images/smilies";
$post =  str_replace($search,$replace,stripBBCode($row["post_text"]));

works superb in standalon, but halts when included. if I remove the str_replace and do

$post =  $row["post_text"];

it works ok.

any ideas why this would break the script?

8

Re: Phpbb3 latest posts on your homepage. Customizable.

ok I solved it doing the it the proper way, instead of including it like suggested, I created standard extension and template and added new forumbox extension so now it can be used generally with different designs anywhere. works like  charm.

9

Re: Phpbb3 latest posts on your homepage. Customizable.

hocustranicu wrote:

ok I solved it doing the it the proper way, instead of including it like suggested, I created standard extension and template and added new forumbox extension so now it can be used generally with different designs anywhere. works like  charm.

Why don't you share it?

10

Re: Phpbb3 latest posts on your homepage. Customizable.

hocustranicu wrote:

ok I solved it doing the it the proper way, instead of including it like suggested, I created standard extension and template and added new forumbox extension so now it can be used generally with different designs anywhere. works like  charm.

yes please share it wink

Give the world the best you have, and the best will come to you.
Tutorials and Mods for VldPersonals  Add CometChat to your vldPersonals site

11

Re: Phpbb3 latest posts on your homepage. Customizable.

hocustranicu wrote:

I have a weir behaviour and I get no error whatsoever with the following: your tutorial works great, but we want smilies to show properly se we added a simple search and replace usin str_replace function. Now weird thing is - if I run the latest_post.php as standalone script it returns correct format, smileys are showing etc. but when I include the script in the template it breaks at the point of inclusion. Any idea why? there are no errors or warnings on php side, strange.

so:


$search = "{SMILIES_PATH}";
$replace = "/forum/images/smilies";
$post =  str_replace($search,$replace,stripBBCode($row["post_text"]));

works superb in standalon, but halts when included. if I remove the str_replace and do

$post =  $row["post_text"];

it works ok.

any ideas why this would break the script?

do you find a solution how to get this to work ? please share it wink

Give the world the best you have, and the best will come to you.
Tutorials and Mods for VldPersonals  Add CometChat to your vldPersonals site

12

Re: Phpbb3 latest posts on your homepage. Customizable.

Orange

Thank you so much for the tutorial, I was able to follow along and feel like I have followed the directions as close as possible but I'm missing something.  I contacted my host provider and they gave me this information

"Checking your website, it looks like it should be /home/cplcplco/public_html/phpBB3/config.php - please note UNIX filenames are case sensitive, so it must be phpBB3 and not phpbb3, in addition to the difference in your username and public_html instead of public. Please let us know if we can be of any further assistance."

So I fixed the problems and it is still showing up with "could not connect".   I'm using vld 2.7 and phpBB3 v3.0.8 Here is the code that I pasted into latest_post.php

<?php
//    error_reporting(0);
    define('IN_PHPBB3', true);

include_once ('home/cplcplco/public_html/phpBB3/config.php');            //Path to phpBB Config File. Due to some restrictions by PHP, you have to provide complete physical path
$urlPath = "/phpBB3";                //phpBB URL with respect to root
$topicnumber = 5;            //Total Post Count to Display
$posttext = 200;                //Number of Characters to display in Post Text
$excludedforums = "0";        //Forum ids to exclude. Each forum id should be seprated with Comma
$completeurl = "http://www.cpl2cpl.com";

    $table_topics = $table_prefix. "topics";    //Usually you don't have to change below 4 variables
    $table_forums = $table_prefix. "forums";
    $table_posts = $table_prefix. "posts";
    $table_users = $table_prefix. "users";

function stripBBCode($text_to_search) {
     $pattern = '|[[\/\!]*?[^\[\]]*?]|si';
     $replace = '';
     return preg_replace($pattern, $replace, $text_to_search);
}



    $link = mysql_connect("$dbhost", "$dbuser", "$dbpasswd") or die("Could not connect");
    mysql_select_db("$dbname") or die("Could not select database");
    $sub_query = '';
    if(strlen($excludedforums) > 0) {
        $pieces = explode(",", $excludedforums);
        foreach ($pieces as $exforumid) {
            $sub_query .= " t.forum_id != " . $exforumid . ' AND ';
            }
    }

    $query = "SELECT t.topic_id, t.topic_title, t.topic_last_post_id, t.forum_id, p.post_id, p.poster_id, p.post_time, u.user_id, u.username, f.forum_name, p.post_text, p.bbcode_uid, p.bbcode_bitfield, f.forum_desc_options
    FROM $table_topics t, $table_forums f, $table_posts p, $table_users u
    WHERE t.topic_id = p.topic_id AND
    f.forum_id = t.forum_id AND ";

    if(strlen($sub_query) > 0) {
        $query .=  $sub_query ;
    }

    $query .= " t.topic_status <> 2 AND
    p.post_id = t.topic_last_post_id AND
    p.poster_id = u.user_id
    ORDER BY p.post_id DESC LIMIT $topicnumber";
    //echo $query;
    $result = mysql_query($query) or die("Query failed" . mysql_error($link));

    print "<div class=\"typecontent\">";
    if($topicnumber % 2) {
        $x="even";
    } else {
        $x="odd";
    }
    $y=0;
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    ++$y;
    if ($y==$topicnumber) {
        $x= $x .  " dataitemlast";
    }
    print "<div class=\"dataitem $x \">
                <table class=\"plain\">
                    <tr>
                        <td class=\"data\">
                                <div class=\"itemheader\">
                                    <h2 class=\"inner\">" .  $row["topic_title"] . "</h2>
                                        <ul class=\"itemheader\">
                                            <li>Posted at: " . date('F j, Y, g:i a', $row["post_time"])  . "</li>
                                            <li>By: <a href=\"$completeurl/$row[username]\">" .
                                            $row["username"]  . "</a></li> <li>In Forum: " . $row["forum_name"] . " </li>
                                        </ul>
                                </div>
                            <div class=\"entry\">" .
                                substr(stripBBCode($row["post_text"]),0,$posttext) . "<a href=\"$urlPath/viewtopic.php?f=$row[forum_id]&t=$row[topic_id]&p=$row[post_id]#p$row[post_id]\" style=\"text-decoration:none;font-weight:bold\"> Read more...</a>
                            </div>
                        </td>
                    </tr>
                </table>
                </div>";

                if ($x=="odd") {
                    $x="even";
                } else {
                    $x="odd";
                }

}
print "<div class=\"clear\"></div></div>";
    mysql_free_result($result);
//  mysql_close($link);
?>




Thanks for the help in advance,

13

Re: Phpbb3 latest posts on your homepage. Customizable.

The modification I sherd into this topic doesn't work with vldpersonals 2.7
I am searching a coder to fix it and I am waiting to know if vldp team could help.
In the meanwhile, any help will be appreciated.

14

Re: Phpbb3 latest posts on your homepage. Customizable.

Chudson wrote:

"Checking your website, it looks like it should be /home/cplcplco/public_html/phpBB3/config.php - please note UNIX filenames are case sensitive, so it must be phpBB3 and not phpbb3

Chudson, by default, it should be phpBB3, but you can change it to be "phpbb3"or "forum" whatever you want under your site root, you also need change in forum PC > General > server settings > script path. keep same.

15

Re: Phpbb3 latest posts on your homepage. Customizable.

I would like say "thank you!" orange_slice for share your function with us, now my forum posts can show up in vld homepage,  It works, even though not perfect, I use phpBB3.08 and vld 2.7, nightlife style,

has 2 problem, one is in latest_posts.php line 9,
$excludedforums = "2";        //Forum ids to exclude. Each forum id should be seprated with Comma

I have total 6 forums, IDs are 2.4.5.7.8.9
first time by mistake,  I fill this:  $excludedforums = "4, 5,7,8,9"; then it only show up the posts from forum 2,
then I change to be $excludedforums = "2,4,5,7,8,9"; then get nothing,
then I just try put"2", then get posts from all forums, ha ha, magical.

Another problems is after I integrate phpBB3 into Vld2.7, others all work good, the only thing not work is when click the member "profile" button from forum, it goes to forum profile, but not goes to vld member profile.(this maybe I should reply in your another post.)

I am not a programmer, I just follow your steps did it, and don't know how to solve these problems :-)
just return back the solution. thanks!

Last edited by nvwokman (2011-08-19 23:39:41)

16

Re: Phpbb3 latest posts on your homepage. Customizable.

nvwokman wrote:

I have total 6 forums, IDs are 2.4.5.7.8.9
first time by mistake,  I fill this:  $excludedforums = "4, 5,7,8,9"; then it only show up the posts from forum 2

I don0t understand the problem. With these settings it has to show only forum 2, because 4.5.7.8.9 have been excluded.

nvwokman wrote:

then I change to be $excludedforums = "2,4,5,7,8,9"; then get nothing

It's right. You excluded all forums.

nvwokman wrote:

then I just try put"2", then get posts from all forums, ha ha, magical.

I don't understand... If you want to show the posts of all forums, just leave that field empty.

Did you try if it works with new registrations and members deletion?

17

Re: Phpbb3 latest posts on your homepage. Customizable.

Sorry, Orange,  I didn't back take look for a while.

Did you try if it works with new registrations and members deletion?

Yes, I did try to added new members from vld site, and the total members was added in forum. but the new register will not be showed up as the latest joined member,the latest joined member always is the last one that register from forum, so I have to hide it.

I tried to delete a member from vld site, and it didn't show up any error, but the forum total members was not reduce 1.

Orange, if you have anything new, please post here, we will be appreciate.

18

Re: Phpbb3 latest posts on your homepage. Customizable.

Great mod! Thank you for this orange_slice!

I have a question: Instead of "Read more..." in the code, is there a way to use a language variable? For example {L_READMORE} or {lang:"custom","readmore"} ??

PS regarding the problem with smilies not showing properly, you get fix it by editing /phpBB3/includes/message_parser.php

In line 1333 it says <img src="{SMILIES_PATH}/ 
replace {SMILIES_PATH} with images/smilies  (if that's your smilies directory, I'm using phpBB3 3.0.10)
Then create the directores images/smilies in the root of your vldPersonals installation and copy the smiley files from phpbb3 to that directory.

It's maybe not the best way but it works fine...