4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Requests & Discussions) => Topic started by: alekseyn1 on December 15, 2009, 10:50:37 AM

Title: [MOD] Last topics from phpBB3 forum to index page (php) version 2
Post by: alekseyn1 on December 15, 2009, 10:50:37 AM
Dear all,

this MOD is inspired by Joss in his mod

[MOD] Last topics from phpBB3 forum to index page (php)
http://www.4homepages.de/forum/index.php?topic=26170.0

here is my version: I took the PHPBB hack from one of the forums and made this...

Step 1.

make new file and call it for example recent_phpbb.php

this should be the content of this file:

Code: [Select]
<?php
/*-------------------------------------------------------------------------
|  PHPBB 3.x.x Last Posts Table with Permissions 0.1 (for center block) 10.12.2009 
|  for 4images 1.7.7 with bridge to PHPBB 3.x.x
|  by alekseyn1 <Aleksey Napolskih>
|  http://www.napolskih.com
|  Base on the following code by visiblesoul
/*-------------------------------------------------------------------------
|  MKPortal PHPBB 3.x.x Last Posts Table with Permissions 0.1 (for center block) 26.07.2008 
|  for MKP C 1.x with PHPBB 3.x.x
|  by mike16os <Khan-Cin Hau>
|  http://www.yamc.info/
|  Base on the following code by visiblesoul
/*-------------------------------------------------------------------------
|  MKPortal IPB 2.1.x Last Posts Table with Permissions 2.1 (for center block) 17.05.2006 
|  for MKP 1.1 x IPB 2.1.x
|  by visiblesoul <visiblesoul.net>
|  Support: http://www.visiblesoul.net/resources/forum/
+--------------------------------------------------------------------------*/

global $db$config;

/*---------------------------------------------------------------------------
Config:
--------------------------------------------------------------------------*/
$limit         10 // Number of forum posts to show in block 
$cutoff        60 // Number of characters to display in title
/*------------------------------------------------------------------------
Forum images Config:
--------------------------------------------------------------------------*/
$img_first_topic    ="";
$img_last_topic     ="";
//empty images canbe used by "" eg: $img_first_topic ="";
  
/*-------------------------------------------------------------------------
Language Setting:
--------------------------------------------------------------------------*/
$lang_topic_title        ="Topic Title";
$lang_last_post          ="Last Post";
$lang_last_post_date     ="posted on";
$lang_views              ="Views";
$lang_replies            ="Replies";
$lang_go_to_last_post    ="go to last post...";
$lang_topic_started_by   ="Topic started by";
$lang_on                 ="on";
$lang_by                 ="by";
$lang_last_poster        ="Last poster:";
/*------------------------------------------------------------------------*/

$content "
<tr>
  <td>

    <table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\">
      <tr>
<td valign=\"top\" class=\"head1\">
$lang_topic_title</td>
<td valign=\"top\" class=\"head1\" align=\"center\">
$lang_last_post</td>
<td valign=\"top\" class=\"head1\" align=\"center\">
$lang_last_post_date</td>
<td valign=\"top\" class=\"head1\" align=\"center\">
$lang_views</td>
<td valign=\"top\" class=\"head1\" align=\"center\">
$lang_replies</td>
      </tr>
"
;

$sql "SELECT forum_id, forum_password FROM ".FORUMS_TABLE."";
 
$result $db->sql_query($sql);

while($f $db->sql_fetchrow($result)) {
 
if ($f['forum_password'] != "" ) {
            
$bad[] = $f['forum_id'];
        
} else {
         
$good[] = $f['forum_id'];
        
}
    
}

 
if ( count($bad) > ) {
     
$qe " AND forum_id NOT IN(".implode(','$bad ).") ";
    
}

$sql1 "SELECT t.topic_last_post_id, t.topic_id, t.topic_title, t.topic_views, t.topic_replies, t.topic_time, t.topic_last_post_time, t.topic_first_poster_name, t.topic_last_poster_name, topic_poster, t.forum_id
    FROM "
.TOPICS_TABLE." t
    LEFT JOIN "
.FORUMS_TABLE." f ON (t.forum_id = f.forum_id)
    WHERE topic_approved != 0 AND topic_approved = 1 AND (topic_moved_id = 0 or topic_moved_id='') 
$qe
    GROUP BY t.topic_title
    ORDER BY t.topic_last_post_id DESC LIMIT 0,
$limit";

$result1 $db->sql_query($sql1);
while ( $post $db->sql_fetchrow($result1)) {
$post['title'] = strip_tags($post['title']);
$post['topic_title'] = str_replace"!" "!" $post['topic_title'] );
$post['topic_title'] = str_replace"&quot;""\""$post['topic_title'] );
if (strlen($post['topic_title']) > $cutoff) {
$post['topic_title'] = substr$post['topic_title'],0,($cutoff 3) ) . "...";
$post['topic_title'] = preg_replace'/&(#(\d+;?)?)?(\.\.\.)?$/''...',$post['topic_title'] );


$title utf8_to_cp1251($post['topic_title']);
 
$tid utf8_to_cp1251($post['topic_id']);
$tlastid utf8_to_cp1251($post['topic_last_post_id']);
                
$views $post['topic_views'];
$posts $post['topic_replies'];
$starter $post['topic_first_poster_name'];
$lastname $post['topic_last_poster_name'];
$lastid $post['topic_poster'];
$forum_id $post['forum_id'];
$startdate  $post['topic_time'];
$lastdate  $post['topic_last_post_time'];

$content .= "
<!-- topic begin -->
      <tr>
<td class=\"row1\" align=\"left\">
  
$img_first_topic <a href=\"./forum/viewtopic.php?f=$forum_id&t=$tid\" title=\"$lang_topic_started_by $starter $lang_on ".format_date($config['date_format']." ".$config['time_format'], $startdate)."\" target = \"_blank\">$title</a>
</td>
<td class=\"row2\" align=\"center\">
  <a href=\"./forum/viewtopic.php?f=
$forum_id&t=$tid&p=$tlastid#p$tlastid\" title=\"$lang_go_to_last_post\" target = \"_blank\">$img_last_topic $lang_last_post</a> $lang_by <a href=\"./forum/memberlist.php?mode=viewprofile&u=$lastid\" title=\"$lang_last_poster $lastname\" target = \"_blank\"><b>$lastname</b></a>
</td>
<td class=\"row1\" align=\"center\">"
.format_date($config['date_format']." ".$config['time_format'], $lastdate)."</td>
<td class=\"row2\" align=\"center\"> 
$views </td>
<td class=\"row1\" align=\"center\"> 
$posts </td>     
</td>
      </tr>
<!-- topic end -->   
"
;
}

$content .= "
    </table>

  </td>
</tr>
"
;  

        
          unset(
$limit);
          unset(
$cutoff);
          unset(
$perms);
          unset(
$good);
          unset(
$bad);
          unset(
$qe);
          unset(
$post);
          unset(
$tid);
          unset(
$title);
          unset(
$views);
          unset(
$posts);
          unset(
$startdate);
          unset(
$lastdate);
          unset(
$starter);
          unset(
$lastname);
          unset(
$lastid);
          unset(
$tlastid);
          unset(
$forum_id);
          unset(
$img_last_topic);
          unset(
$img_first_topic);
          unset(
$lang_topic_title);
          unset(
$lang_last_post);
          unset(
$lang_last_post_date);
          unset(
$lang_views);
          unset(
$lang_replies);
          unset(
$lang_go_to_last_post);
          unset(
$lang_topic_started_by);
          unset(
$lang_on);
          unset(
$lang_by);
          unset(
$lang_last_poster);
                     
echo 
$content;

function 
utf8_to_cp1251($s)
        {
            for (
$c=0;$c<strlen($s);$c++)
            {
               
$i=ord($s[$c]);
               if (
$i<=127$out.=$s[$c];
                   if (
$byte2){
                       
$new_c2=($c1&3)*64+($i&63);
                       
$new_c1=($c1>>2)&5;
                       
$new_i=$new_c1*256+$new_c2;
                   if (
$new_i==1025){
                       
$out_i=168;
                   } else {
                       if (
$new_i==1105){
                           
$out_i=184;
                       } else {
                           
$out_i=$new_i-848;
                       }
                   }
                   
$out.=chr($out_i);
                   
$byte2=false;
                   }
               if ((
$i>>5)==6) {
                   
$c1=$i;
                   
$byte2=true;
               }
            }
            return 
$out;
}

?>

Step 2.


in your home.html file (in your template directory) include this string in the place where you want your table to show up:

Code: [Select]
 <!--last forum posts -->

 <table width="100%" border="0" cellspacing="0" cellpadding="1">
                    <tr>
                      <td class="head1">
                        <table width="100%" border="0" cellspacing="0" cellpadding="3">
                          <tr>
                            <td class="head1" valign="top" colspan="5">Last forum posts</td>
                          </tr>
 
 <tr>
                            <td class="row1" valign="top" colspan="5"><?php include(ROOT_PATH."/recent_phpbb.php"); ?></td>
                          </tr>

                        </table>
                      </td>
                    </tr>
                  </table>
                  <br />
<!--end last forum posts -->


Notes:

1. In include/constants.php you must set the value to "1" in this define:  define('EXEC_PHP_CODE', 1);
2. This particular version of the code is designed for the database in UTF8 and your 4images site in other encoding (cp1251 in my case). I have only included the function to recode utf8 into windows 1251 - russian encoding. I am sure you can find other functions to recode into your codepage if required
3. you need to modify all occurrences of this code
Code: [Select]
<a href=\"./forum/ to reflect the correct path of your phpBB3 installation
4. of course you are more than welcom to improve and modify this code. Please post your improvements here for everybody's benefit.

see attachment for demo...
Title: Re: [MOD] Last topics from phpBB3 forum to index page (php) version 2
Post by: V@no on December 15, 2009, 03:57:19 PM
As far as I can tell this addon will only work if your 4images is integrated with phpBB3, correct?
Title: Re: [MOD] Last topics from phpBB3 forum to index page (php) version 2
Post by: alekseyn1 on December 15, 2009, 04:01:14 PM
As far as I can tell this addon will only work if your 4images is integrated with phpBB3, correct?

correct. only with this MOD

http://www.4homepages.de/forum/index.php?topic=26013.0
Title: Re: [MOD] Last topics from phpBB3 forum to index page (php) version 2
Post by: bergblume on May 22, 2015, 05:44:17 PM
for last forum posts of phpbb2 forums this code works (just as addition)

create recent.php with

<?php
    // ############         Edit below         ########################################
    $topic_length = '20';   // length of topic title
    $topic_limit = '5';   // limit of displayed topics
    $special_forums = '0';   // specify forums ('0' = no; '1' = yes)
    $forum_ids = '3,5,6,7';      // IDs of forums; separate them with a comma

    $config_path = '/';   // path to config.php
    $root_path = 'INSERTYOURURLHERE';      // link path
    // ############         Edit above         #######################################

    $path = dirname(__FILE__);
    include_once($path.$config_path .'config.php');
    mysql_connect($dbhost, $dbuser, $dbpasswd) OR die('Unable to select server.');
    mysql_select_db($dbname) OR die('Unable to select database.');

    // ############## output ##############
    echo '<table border="0" cellpadding="0" cellspacing="0" style="width: 100%" id="Table_DSF-Top5">
    <body text="#000000" link="#000000" vlink="#333333" alink="#333333">
             <tr>
               <td colspan="4"><span class="small"><font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:11px">
               Die '. $topic_limit .' letzten Themen im Forum</font></span></td><br>
             </tr>
             <tr>

                <td style="width: 20%"><span class="small">
                <strong>
                <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:11px">Foren</font></strong>
                <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:9px"></font
                </strong></span></td>
                <td style="width: 20%"><span class="small">
                <strong>
                <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:11px">User</font>
                </strong>
                <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:9px"></font
                </strong></span></td>
                <td style="width: 20%"><span class="small">
                <strong>
                <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:11px">Datum</font>
                </strong></span></td>
                <td style="width: 20%"><span class="small"><strong>
                <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:11px">Thema</font>
                </strong>
                <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:9px"></font
                </strong></span></td>

             </tr>';
    // ############## output ##############

    $where_forums = ( $special_forums == '0' ) ? '' : 't.forum_id NOT IN ('. $forum_ids .') AND ';
    $sql = "SELECT t.*, f.forum_id, f.forum_name, u.username AS first_poster, u.user_id AS first_poster_id, u2.username AS last_poster, u2.user_id AS last_poster_id, p.post_username AS first_poster_name, p2.post_username AS last_poster_name, p2.post_time
       FROM ". $table_prefix ."topics t, ". $table_prefix ."forums f, ". $table_prefix ."users u, ". $table_prefix ."posts p, ". $table_prefix ."posts p2, ". $table_prefix ."users u2
       WHERE $where_forums t.topic_poster = u.user_id AND f.forum_id = t.forum_id AND p.post_id = t.topic_first_post_id AND p2.post_id = t.topic_last_post_id AND u2.user_id = p2.poster_id
       ORDER BY t.topic_last_post_id DESC LIMIT $topic_limit";
    $result = mysql_query($sql);
    if( !$result )
    {
       die('SQL Statement Error: '. mysql_error());
       exit();
    }

    $line = array();
    while( $row = mysql_fetch_array($result) )
    {
       $line[] = $row;
    }

    for( $i = 0; $i < count($line); $i++ )
    {
       $forum_id = $line[$i]['forum_id'];
       $forum_url = $root_path .'viewforum.php?f='. $forum_id;
       $topic_id = $line[$i]['topic_id'];
       $topic_url = $root_path .'viewtopic.php?t='. $topic_id;

       $topic_title = ( strlen($line[$i]['topic_title']) < $topic_length ) ? $line[$i]['topic_title'] : substr(stripslashes($line[$i]['topic_title']), 0, $topic_length) .'...';

       $topic_type =  ( $line[$i]['topic_type'] == '2' ) ? 'Announcement ': '';
       $topic_type .= ( $line[$i]['topic_type'] == '3' ) ? 'Global Announcement ': '';
       $topic_type .= ( $line[$i]['topic_type'] == '1' ) ? 'Sticky ': '';
       $topic_type .= ( $line[$i]['topic_vote'] ) ? 'Poll ': '';

       $views = $line[$i]['topic_views'];
       $replies = $line[$i]['topic_replies'];

       $first_time = date('d.m.Y', $line[$i]['topic_time']);
       $first_author = ( $line[$i]['first_poster_id'] != '-1' ) ? '<a href="'. $root_path .'profile.php?mode=viewprofile&amp;u='. $line[$i]['first_poster_id'] .'" target="_blank">'. $line[$i]['first_poster'] .'</a>' : ( ($line[$i]['first_poster_name'] != '' ) ? $line[$i]['first_poster_name'] : 'guest' );
       $last_time = date('d.m.Y', $line[$i]['post_time']);
       $last_author = ( $line[$i]['last_poster_id'] != '-1' ) ? $line[$i]['last_poster'] : ( ($line[$i]['last_poster_name'] != '' ) ? $line[$i]['last_poster_name'] : 'guest' );
       $last_url = '<a href="'. $root_path .'viewtopic.php?p='. $line[$i]['topic_last_post_id'] .'#'. $line[$i]['topic_last_post_id'] .'" target="_blank">'. $last_author .'</a>';

       // ############## output ##############
       echo '<tr>

               <td style="width: 20%"><a href="'. $forum_url .'" target="_blank">
                <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:11px">'. $line[$i]['forum_name'] .'</font></a></td>
                <td style="width: 20%">
                <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:11px">'. $last_url .'</font></td>
                <td style="width: 20%">
                <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:11px">'. $last_time .'</font></td>
                <td style="width: 20%"><a href="'. $topic_url .'" target="_blank">
                <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:11px">'. $topic_title .'</font></a></td>

            </tr>';

       // ############## output ##############
    }

    echo '</table>';
    mysql_close();
    ?>

save recent.php in your forum directory

and then embed with this line your latest posts somewhere within your 4images (best in the sidebar) with this code:

<?php include(ROOT_PATH."forum/recent.php"); ?>