• DONATE to NULLED!
    Форуму и его команде можно помочь, мотивировать модераторов разделов.
    Помогите модератору этого раздела killoff лично.

[хак] Вывод последних сообщений с форума IPB

Статус
В этой теме нельзя размещать новые ответы.

E-body

Мой дом здесь!
Регистрация
6 Сен 2007
Сообщения
992
Реакции
342
Еще одно решение вывода последних сообщений с форума IPB 2.3.x-2.2.x
DLE все версии. (на 6.7 точно)

Если ранее не включали возможность обработки PHP в шаблоне то:
Открыть index.php
Найти строку:
PHP:
echo $tpl->result['main'];
заменить на :
PHP:
eval (' ?' . '>' . $tpl->result['main'] . '<' . '?php ');

1. Создадим файл latest_post.php с содержанием:
PHP:
<?
// **************************************** //
// Original mod submitted by Miles Johnson. //
// Completely rewritten by Anthony Petito.. //
// V2.6:  15 January 2007.................. //
// V2.51: 13 June 2006..................... //
// V2.5:  03 June 2006..................... //
// V2.1:  10 April 2005.................... //
// V2.0:  04 April 2005.................... //
// **************************************** //

// This mod will pull the latest X posts from your forum and display them on your website.  
// This new version will also handle forums that you do not wish to show (excluded forums)

// Put this file where your FORUMS are located (e.g, http://domain.tld/forum).
// This should be in the same path as your conf_global.php file
// I've commented most of the code so that it's fairly understandable, however, 
// if you're unsure of what's going on here, stick to the comments on where to edit this file for your site.

// For this to work properly, copy the following code into your website.  Change it to match the link to THIS filename and path.
/* <?php include("http://domain.tld/forum/latest_posts.php");?> */

/////////////////////////////
// User Editable variables //
/////////////////////////////

// Change this to the number of posts you would like to show.
$posts = 10; 

// If you would like this mod to cut topics after a certain character length, leave this at 1.  Otherwise, change it to 0. 
$showtopiclength = 1; 

// Length of title to display before cutting off.  If topic title length exceeds this value, it is followed by ellipses (...)
// Only useful if the above varaible is set to 1.
$topiclength = 40; 

// Add forumid's to exclude from.  For example, you might want to exclude your private forums so that posts from it
// do not show up.  Seperate each forumid by a comma and ensure there's no spaces in between.  
$forumexclude = "38,37,71,73,69,44,75,108,74"; 

/*
TIME INTERVAL DISPLAY

0 = only days
1 = only hours
2 = only minutes
3 = only seconds  *** NOT WORKING *** 
4 = hours and minutes
5 = hours and seconds
6 = minutes and seconds
7 = hours, minutes, seconds

Please select which interval to use (besides option 3, which is not working correctly):
*/

$interval = 6;

/*
This will display the time interval between posts
Example: posted 3 minutes ago
Example: posted 2 hours and 3 minutes ago
Example: 1 day, 5 hours ago
*/
	
//OR display date only
// The following 2 lines can be changed to however you want the date and time to be displayed.  
// Default date: dd month year
// Default time: hh:mm ampm TIMEZONE (12 hour time)
// For more information on how the next 2 lines can be changed, please reference the README file.
// If you elect to show the date and time it was posted instead of the way shown above ONLY, change the $showtime variable to 1.
$showtime = 0;
$datedisplay = 'd F Y';
$timedisplay = 'h:i A T';

//////////////
// Required //
//////////////

require "conf_global.php";

//////////////
// Database //
//////////////

$mysql = mysql_connect( $INFO['sql_host'], $INFO['sql_user'], $INFO['sql_pass'] /*, $INFO['sql_driver'] */ );
if ( !$mysql ) {
    die( "<b>mysql_connect()</b>: ". mysql_error() );
}

$select_db = mysql_select_db( $INFO['sql_database'], $mysql );
if ( !$select_db ) {
    die( "<b>mysql_select_db()</b>: ". mysql_error() );
}


// Query the DB with the supplied user inputted variables.
if ($forumexclude <> "") {
	$getposts = mysql_query("SELECT posts, last_poster_name, last_poster_id, title, tid, forum_id, last_post FROM ibf_topics WHERE (forum_id NOT IN ($forumexclude)) ORDER BY last_post DESC LIMIT $posts");
	}
else {
	$getposts = mysql_query("SELECT posts, last_poster_name, last_poster_id, title, tid, forum_id, last_post FROM ibf_topics ORDER BY last_post DESC LIMIT $posts");
}

// Format and display the results.
while ( $post = mysql_fetch_array($getposts)) {

	$post[full_title] = $post[title];
	if ($showtopiclength == 1 AND strlen($post[full_title]) > $topiclength) {
		$post[short_title] = substr($post[full_title],0,$topiclength);
		$post[short_title] = $post[short_title]."...";
	}
	else {
		$post[short_title] = $post[full_title];	
	}
	
	$posted_on = date($datedisplay, $post[last_post]); // Need to change mySQL timestamp to something more human readable.
	$today_date = date($datedisplay, time()); // Grab today's date so we can compare it against the posted date
	
	if ($showtime == 0) {
		$showtimediff =  timediff($interval,time(),$post[last_post]); 
		$datefield = $showtimediff;
	}
	else {
	
		// If it was posted today, we want to display "Today, hh:mm AMPM"
		If ($posted_on == $today_date) {
			$datefield = "Today";
			$datefield = $datefield . ", " . date($timedisplay, $post[last_post]);
		}
		
		// If it was posted yesterday, we want to display "Yesterday, hh:mm AMPM"
		elseif (date('d F Y',strtotime("-1 day")) == $posted_on) {
			$datefield = "Yesterday";
			$datefield = $datefield . ", " . date($timedisplay, $post[last_post]);
		}
		
		else {
			$datefield = $posted_on;
		}
	}

	echo
	/////////////////
	// Post Format //
	/////////////////
	// Between the EOD markers you can put whatever you want in HTML format.  Just ensure that the link stays somewhat the same.
<<<EOD

<a href="$INFO[board_url]/index.php?showtopic=$post[tid]&view=getnewpost" class="last">$post[short_title]</a> by 
<a href="$INFO[board_url]/index.php?showuser=$post[last_poster_id]" class="last2">$post[last_poster_name]</a> <BR>
$datefield, в теме с $post[posts] ответами(ом).<P>

EOD;
}

function timediff($interval, $starttime, $endtime) {

	$timediff = $starttime - $endtime;
	$days=intval($timediff/86400);
	$remain=$timediff%86400;
	$hours=intval($remain/3600);
	$remain=$remain%3600;
	$mins=intval($remain/60);
	$secs=$remain%60;
	
	$pluraldays 	= ($days < 2) ? " день " : " дней ";
	$pluralhours 	= ($hours < 2) ? " час " : " часов ";
	$pluralmins 	= ($mins < 2) ? " минута " : " минут ";
	$pluralsecs 	= ($secs < 2) ? " секунда " : " секунд ";
	$hourcount	= ($hours == 0) ? 1 : 0;
	$minscount	= ($mins == 0) ? 1 : 0;
	$secscount	= ($secs == 0) ? 1 : 0;
	
	if ($days > 1) {
	// If a post is older than Yesterday we want to display the the date and time it was created rather than how long ago.
	// This makes it easier to display rather than having it say 3 days, 5 hours ago, for example.
		$timediff = $posted_on;
	}
	elseif ($days == 1) {
	// The post is within 1 day old.  In this case, I've decided it may be best to show only 1 day, 5 hours ago, for example.
		$timediff = "ответ оставлен ".$days." день и ".$hours.$pluralhours." назад";
	}
	else { 
	// Less than 1 day has passed and here we use the interval that was set above.
		if ($interval == 0) { 	$timediff = "ответ оставлен ".$days.$pluraldays." назад";}	// show only days
		elseif ($interval == 1) { $timediff = "ответ оставлен ".$hours.$pluralhours." назад";}	// show only hours
		elseif ($interval == 2) { $timediff = "ответ оставлен ".$mins.$pluralmins." назад";}	// show only minutes
		elseif ($interval == 3) { $timediff = "ответ оставлен ".$secs.$pluralsecs." назад";}	// show only seconds
		
		elseif ($interval == 4) { // show hours and minutes
			if ($hourcount) {	$timediff = "ответ оставлен ".$mins." ".$pluralmins." назад"; }
			else if ($minscount) {	$timediff = "ответ оставлен ".$hours." ".$pluralhours." назад"; }
			else {	$timediff = "ответ оставлен ".$hours.$pluralhours." и ".$mins." ".$pluralmins." назад"; }
		}
		elseif ($interval == 5) { // show hours and seconds
			if ($hourscount) {	$timediff = "ответ оставлен ".$secs." ".$pluralsecs." назад"; }
			else if ($secscount) {	$timediff = "ответ оставлен ".$hours." ".$pluralhours." назад"; }
			else {	$timediff = "ответ оставлен ".$hours.$pluralhours." и ".$sec." ".$pluralsecs." назад"; }
		}
		elseif ($interval == 6) { // show minutes and seconds	
			if ($minscount == 1) {	$timediff = "ответ оставлен ".$secs." ".$pluralsecs." назад"; }
			else if ($secscount == 1 ) {	$timediff = "ответ оставлен ".$mins." ".$pluralmins." назад"; }
			else {	$timediff = "ответ оставлен ".$mins.$pluralmins." и ".$secs." ".$pluralsecs." назад"; }
		}
		else {	// show hours, minutes and seconds 
			$timediff = "ответ оставлен ".$hours.$pluralhours.", ".$mins." ".$pluralmins." и".$secs." ".$pluralsecs." назад";
		}
	}
	
	return $timediff;

}	
?>

и поместите его в корень форума.

2. Открыть главный шаблон main.tpl и в подходящем месте вставить
PHP:
<? include "/home/bleble/public_html/forum/latest_posts.php"; ?>

Данное решение подойдет также и к другим cms, этим способом было прикручено вывод последних постов к сайту дле 6.7 с форума ipb 2.3.1 ../forum/ !
насчет удаленного инклюда наверно не прокатит, большинство хостеров отключают.

####################################################

Тема была создана после того как не получилось прикрутить другой хак см. ниже
1. Первое: Создаем файл с названием latest_posts.php и вставляем туда это:

PHP:
<?

// ******************************************* //
// Создатель оригинального мода Charli007.              //        
// ******************************************* //


$posts = 10;
$showtopiclength = 1;
$topiclength = 40;
$forumexclude = "10,13,15";
$datedisplay = 'd F Y';
$timedisplay = 'h:i A T';

require "ips_kernel/class_db_mysql.php";
require "conf_global.php";

$db = new db_driver;
$db->obj['sql_database']     = $INFO['sql_database'];
$db->obj['sql_user']         = $INFO['sql_user'];
$db->obj['sql_pass']         = $INFO['sql_pass'];
$db->obj['sql_host']         = $INFO['sql_host'];
$db->obj['sql_tbl_prefix']   = $INFO['sql_tbl_prefix'];

$db->connect();

$getposts = $db->query("SELECT posts, last_poster_name, last_poster_id, title, tid, forum_id, last_post FROM ibf_topics WHERE (forum_id NOT IN ($forumexclude)) ORDER BY last_post DESC LIMIT $posts");

while ($post = $db->fetch_row($getposts)) {
$post[full_title] = $post[title];
if ($showtopiclength == 1 AND strlen($post[full_title]) > $topiclength) {
        $post[short_title] = substr($post[full_title],0,$topiclength);
        $post[short_title] = $post[short_title]."...";
}
else {
        $post[short_title] = $post[full_title];
}

$posted_on = date($datedisplay, $post[last_post]);
$today_date = date($datedisplay, time());

If ($posted_on == $today_date) {
        $datefield = "Сегодня";
        $datefield = $datefield . ", " . date($timedisplay, $post[last_post]);
}

elseif (date('d F Y',strtotime("-1 day")) == $posted_on) {
        $datefield = "Вчера";
        $datefield = $datefield . ", " . date($timedisplay, $post[last_post]);
}

else {
        $datefield = $today_date;
}

echo

<<<EOD

<a href="$INFO[board_url]/index.php?showtopic=$post[tid]&view=getnewpost">$post[short_title]</a> by
<a href="$INFO[board_url]/index.php?showuser=$post[last_poster_id]">$post[last_poster_name]</a> <BR>
$datefield, и $post[posts] ответов.<P>

EOD;
}

?>


Кидаем данный файлик в директорию форума!

2. Создаем ещё один файлик с наименованием latestposts.php вкладываем в него это:

<? if (!eregi("index.php", $PHP_SELF)) { die ("<center><font face="Tahoma" color="red" size="9pt"><b>ACCESS DENIED!</b></font></center>"); } ?>

<table id="BLOCK_RIGHT" width="202" height="69" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td>
            <img src="images/bl2_01.gif" width="3" height="1"></td>
        <td>
            <img src="images/bl2_02.gif" width="196" height="1"></td>
        <td>
            <img src="images/bl2_03.gif" width="3" height="1"></td>
    </tr>
    <tr>
        <td>
            <img src="images/bl2_04.gif" width="3" height="14"></td>
        <td background="images/bl2_05.gif" class="b_text" align="center">
        <!-- START TITLE -->
        Форум пишет
        <!-- END TITLE -->
        </td>
        <td>
            <img src="images/bl2_06.gif" width="3" height="14"></td>
    </tr>
    <tr>
        <td>
            <img src="images/bl2_07.gif" width="3" height="4"></td>
        <td>
            <img src="images/bl2_08.gif" width="196" height="4"></td>
        <td>
            <img src="images/bl2_09.gif" width="3" height="4"></td>
    </tr>
    <tr>
        <td background="images/bl2_10.gif">
            <img src="images/bl2_10.gif" width="3" height="47"></td>
        <td valign="top" background="images/bl2_11.gif">
        <!-- START MSG -->
        <table width="100%"  border="0" cellspacing="2" cellpadding="2" align="top" class="text">
          <tr>
            <td>          
                <?

                    include "http://ссылка где в дерикторию форума/latest_posts.php";
    
                ?>
                   </td>
          </tr>
        </table>
        <!-- END MSG --></td>
        <td background="images/bl2_12.gif">
            <img src="images/bl2_12.gif" width="3" height="47"></td>
    </tr>
    <tr>
        <td>
            <img src="images/bl2_13.gif" width="3" height="3"></td>
        <td>
            <img src="images/bl2_14.gif" width="196" height="3"></td>
        <td>
            <img src="images/bl2_15.gif" width="3" height="3"></td>
    </tr>
</table>
 
Nu poskolku my eto vpisyvajem v dvizok DLE, to mozno prikrutit i Cache, i sekonomim na zaprose k DB
;]

v main.tpl neobizatelno prikrucivat php mozno prosto includit fail v engine.php ili v init.php ili daze v samom index.php

i zdelat zamena tega {latest_from_forum} v index.php na to cto vydajot latest_posts.php, tagze nelozyt latest_posts.php v koren, a kudanit gde drugije jego ne vozmut ;]
 
Nu poskolku my eto vpisyvajem v dvizok DLE, to mozno prikrutit i Cache, i sekonomim na zaprose k DB
;]

v main.tpl neobizatelno prikrucivat php mozno prosto includit fail v engine.php ili v init.php ili daze v samom index.php

i zdelat zamena tega {latest_from_forum} v index.php na to cto vydajot latest_posts.php, tagze nelozyt latest_posts.php v koren, a kudanit gde drugije jego ne vozmut ;]

Насчет кеш, можешь описать подробнее? Моих знаний php не хватает для такого релиза. Давно видел и читал от тебя такое высказывания насче кеша, в 4дле если помнишь в коментах к похожему хаку.
 
hmm nepomniu, no napishu popozhe
 
{fm_last_forum_msg} не парсится, где копать?
 
v indexe vsio propisal?
PHP:
$tpl->set('{fm_last_forum_msg}',$fm_last_forum_msg);

mozesh pered etim napisat
PHP:
echo $fm_last_forum_msg;
i smotri v samom verhu stranicy dolzen pojavitca text...


jesli net, to smotri kakije error kidajet. moz v mysql ne podrubajetca..
</span>

Добавлено через 3 минуты
ctob proverit ili zameniajetca kod, mozesh napisat

pered


PHP:
$tpl->set('{fm_last_forum_msg}',$fm_last_forum_msg);

$fm_last_forum_msg = "Zdes budit Text iz foruma";

tagze mozesh posmotret ili v engine/cache/ sozdajotca fail

fm_forum_msg.tmp

i posmotret cto v niom jest,
za odno potri cache cerez adminku..
 
v indexe vsio propisal?
PHP:
$tpl->set('{fm_last_forum_msg}',$fm_last_forum_msg);

mozesh pered etim napisat
PHP:
echo $fm_last_forum_msg;
i smotri v samom verhu stranicy dolzen pojavitca text...


jesli net, to smotri kakije error kidajet. moz v mysql ne podrubajetca..
</span>

Добавлено через 3 минуты
ctob proverit ili zameniajetca kod, mozesh napisat

pered


PHP:
$tpl->set('{fm_last_forum_msg}',$fm_last_forum_msg);

$fm_last_forum_msg = "Zdes budit Text iz foruma";

tagze mozesh posmotret ili v engine/cache/ sozdajotca fail

fm_forum_msg.tmp

i posmotret cto v niom jest,
za odno potri cache cerez adminku..

Это не делая, почистил кеш через админку.
Теперь заработало, но {fm_last_forum_msg} ставил в блок меню, а он отображается вверху страницы (в самом начале кода страницы)
-
Спасибо Роман, теперь хак работает с кеш, уверен это поможет облегчить работу сайта. :yahoo:
fm_forum_msg.tmp - наполнен выводом последних сообщений с ипб.

вот мой шаблон вывода сообщений
 
cashe obnovliajetca s kazdym ciasom. jesli jest vozmoznost k cronu, to prosto propishy v cron (na linuxe) ctob kazdyje 20 min steralsia fail cache vot dopustim tak

0-59/20 * * * * "rm -rf /put_k_cahe_diru/fm_forum_msg.tmp" 1> /dev/null &

vot i vsio

a tvoi shotimediff prosto pokazyvajet v slovah kogda eto bylo - takto on i ne nuznyi =)
 
При разрешении исполнения сторонних ПХП на сайте - 90% взлома сайта.
+ Есть совсем неплохой модуль от Калиотсро, обєдинение DLE и IPB в нём есть подобная вещь. (это не реклама, но как по мне зачем усложнять жизнь).
 
Статус
В этой теме нельзя размещать новые ответы.
Назад
Сверху