[Release] Display x Recent Topics on any page

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment! No new topics are allowed in this forum.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: MOD Development Forum rules

On February 1, 2009 this forum will be set to read only as part of retiring of phpBB2.
Eisi
Registered User
Posts: 67
Joined: Tue Apr 16, 2002 10:22 pm
Location: Germany, NRW
Contact:

[Release] Display x Recent Topics on any page

Post by Eisi »

I have released a MOD which displays the last x topics across all forums with date and time and name of the person who has replied last, or started the thread if no replies yet. Additionally the code uses the phpBB2 auth.php functions to check if the user is authorized to view the forum and therefore the topics. If no positive auth is returned for the topic, it is not displayed!

One current issue about this is, that the auth status isn't influencing the max_topics counter in any way, as of yet. That means, if you have set the script to display 10 topics, and all 10 of the latest topics are in a forum the current user cannot see, NONE are displayed for him. I will change that in a future version maybe. Or anyone else can post it here, and I will include it and give credits..

Please give me feedback if you encounter anything that shouldn't be.

[ UPDATE: 25. April 2002]
Current version is v1.2.0


Please download the ZIP from the link in my signature. It comes with a README.TXT file that explains how to install and use.
Basically, you copy the recent_topics.php into your phpBB directory, add one line and a table to your existing HTML page and, voilá.

Give me feedback on how it works...
Have fun!
Last edited by Eisi on Thu Apr 25, 2002 9:28 pm, edited 3 times in total.
Final Fantasy VII/ IX & Little Big Adventure 2: Eisi's Web-Welten (German)
Projects Under Development:
Event Management Community: VAMOS Online (German)

ivan
Registered User
Posts: 29
Joined: Sat Mar 23, 2002 9:13 pm
Location: fremont,ca
Contact:

Re: [Release] Display x Recent Topics on any page (auth-chec

Post by ivan »

Eisi wrote: I have released a MOD which displays the last x topics across all forums with date and time and name of the person who has replied last, or started the thread if no replies yet. Additionally the code checks if the user is authorized to view the forum and therefore the topics. If no positive auth is returned for the topic, it is not displayed. It works as an include, but as well if you put the code into any existing page.

I have tested it at home since I don't have any online boards atm. I can't find any problems. Please give me feedback if you encounter anything that shouldn't be.

Here you go: phpBB_Recent_Topics_v1.0.0

Code: Select all

<?php
/*############################################################### 
## Mod Title:	phpBB2 Recent Topics
## Mod Version:	1.0.0
## Author:	Matthias Eisenhardt < m.e@gmx.net > - www.zeitzumspielen.de
##
## Description:	Displays the last x topics, on any page
##		based on user auth level. Can only see topics from forums
##		the user is allowed to see. Next version will allow to chose
##		between topics and posts to display.
## 
## Installation Level: EASY
## Installation Time: 1 minute 
## Files to Edit: recent.php (this file)
## Included files: n/a
################################################################# 
## Security Disclaimer: This MOD Cannot Be Posted To Or Added At Any Non-Official phpBB Sites 
#################################################################
##
## Author Note: Inspired by the Hack "recent.php" by Acid (acid_junky@web.de)
##	          I have learned from it, however, this code is fresh!
##
#################################################################
## Installation Notes: Either copy the code into any page that you want to display
##		the topics on, or (recommended) save this as recent.php
##		and use the include command to call it from any other file.
##		The file has 3 (three) areas where you can set variables or
##		change the HTML for the output. Do not play with the rest
##		of the code, unless you know what you are doing!!
################################################################# 
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD 
#################################################################*/
define('IN_PHPBB', true);
$phpbb_root_path = "./"; 						//  Don't change this if unless you have a specific reason!
include_once($phpbb_root_path . 'extension.inc');
include_once($phpbb_root_path . 'common.'.$phpEx);
include_once($phpbb_root_path . '/includes/auth.php');

/**********************************************************************/
/***		START CONFIG VARIABLES	***/
//
$max_topics = "10"; 						//  How many topics do you want to display?
$display_topic_length = "40";					//  How many characters? Longer titles are shortened with "..."
//
/***		END CONFIG VARIABLES		***/
/**********************************************************************/
//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//
/**********************************************************************/
/***		START CONFIG HTML		***/
//
echo "<table border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td align=\"left\"><span class=\"gen\"><b>" . $lang['Topics'] . ":</b></span></td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td align=\"left\"><span class=\"gen\"><b>" . $lang['Last_Post'] . ":</b></span></td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td align=\"left\"><span class=\"gen\"><b>" . $lang['Poster'] . ":</b></span></td>
</tr>";
//
/***		END CONFIG HTML		***/
/*********************************************************************/

$sql = "SELECT topic_id, topic_title, topic_last_post_id, forum_id		/**/	
	FROM " . TOPICS_TABLE . "				/**  Query topic information **/
	ORDER BY topic_last_post_id DESC LIMIT $max_topics";	/**/

if( !($result = $db->sql_query($sql)) )
{
	message_die(GENERAL_ERROR, 'Could not obtain topic information', '', __LINE__, __FILE__, $sql);
}

$is_auth = array();
while ($row = $db->sql_fetchrow($result))
{ 
	$forum_id = $row['forum_id'];					// Auth check
	$is_auth = auth(AUTH_VIEW, $forum_id, $userdata);		//
	if($is_auth['auth_view'] == TRUE)				// If user can see topic (is allowed to see forum), then go ahead..
	{ 
		$lastreply_array = $db->sql_query("SELECT post_time, poster_id				/**/
						FROM " . POSTS_TABLE . "			/**  Query date and time of last reply  **/
						WHERE post_id =" . $row['topic_last_post_id']);		/**/
		$lastreply = mysql_fetch_array($lastreply_array); 
		$lastreply = $lastreply['post_time']; 
		$lastreply = create_date($board_config['default_dateformat'], $lastreply, $board_config['board_timezone']); 
		//
		// Get name of respective topic author
		//
		$author_array = $db -> sql_query("SELECT u.user_id, u.username AS username, p.poster_id, p.post_id
			FROM " . USERS_TABLE . " u, " . POSTS_TABLE . " p
			WHERE p.post_id =" . $row['topic_last_post_id'] . "
			AND p.poster_id = u.user_id");
		
		$author = mysql_fetch_array($author_array);
		$author = $author['username'];
	
		$j = stripslashes($row['topic_title']); 
		$k = substr($j, 0, $display_topic_length) . "...";

/**********************************************************************/
/***		START CONFIG HTML		***/
//
		echo "<tr><td align=\"left\"><span class=\"gensmall\">&raquo;&raquo; </span> <a href=\"" . append_sid("viewtopic.php?t=" . $row['topic_id']) . "\" class=\"genmed\">" . $k . "</a></td>
		<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
		<td align=\"left\"><span class=\"genmed\">$lastreply</span></td>
		<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
		<td><span class=\"genmed\">$author</span></td></tr>";
//
/***		END CONFIG HTML		***/
/*********************************************************************/

	}	// closing if $is_auth..
};	// closing while $row..

echo "</table>"; 

?>
Let me know what you think. You can download it .ZIPped from the link in my Signature.

Have fun!


here is where i edit right ?
define('IN_PHPBB', true);
$phpbb_root_path = "./"; // Don't change this if unless you have a specific reason!


and as sample of edit is
define(http://www.yoursite.com/phpBB2);
$phpbb_root_path = "./"; // Don't change this if unless you have a specific reason!


is this right ???

Bear_nG
Registered User
Posts: 125
Joined: Fri Apr 05, 2002 9:22 am
Location: Brisbane, Australia
Contact:

Post by Bear_nG »

dude - define is a script command
ivan wrote: /**********************************************************************/
/*** START CONFIG VARIABLES ***/
//
$max_topics = "10"; // How many topics do you want to display?
$display_topic_length = "40"; // How many characters? Longer titles are shortened with "..."
//
/*** END CONFIG VARIABLES ***/
/**********************************************************************/


that's the only bit you mess with, and it sets the number of posts, and the length of the preview...

set it back and go see if it works.

mikegoh
Registered User
Posts: 1
Joined: Mon Apr 22, 2002 7:42 am

Post by mikegoh »

Hi Eisi,

I have installed your mod but there is a problem. I get this error message:
Warning: Cannot add header information - headers already sent by (output started at /home/fishnati/public_html/index.php:5) in /home/fishnati/public_html/forum/includes/sessions.php on line 186

Warning: Cannot add header information - headers already sent by (output started at /home/fishnati/public_html/index.php:5) in /home/fishnati/public_html/forum/includes/sessions.php on line 187


however, this message will be gone once I had logged in to the site.
My homepage add is http://www.fishnatic.com

ivan
Registered User
Posts: 29
Joined: Sat Mar 23, 2002 9:13 pm
Location: fremont,ca
Contact:

Post by ivan »

mikegoh wrote: Hi Eisi,

I have installed your mod but there is a problem. I get this error message:
Warning: Cannot add header information - headers already sent by (output started at /home/fishnati/public_html/index.php:5) in /home/fishnati/public_html/forum/includes/sessions.php on line 186

Warning: Cannot add header information - headers already sent by (output started at /home/fishnati/public_html/index.php:5) in /home/fishnati/public_html/forum/includes/sessions.php on line 187


however, this message will be gone once I had logged in to the site.
My homepage add is http://www.fishnatic.com



i have the same problem ???
Ivan

Web Design At It's Best !!!
www.bayareastreetracing.com

ivan
Registered User
Posts: 29
Joined: Sat Mar 23, 2002 9:13 pm
Location: fremont,ca
Contact:

Post by ivan »

my error is


Warning: Failed opening './extension.inc' for inclusion (include_path='') in /home/sites/site22/web/New/test.php on line 35

Warning: Failed opening './common.' for inclusion (include_path='') in /home/sites/site22/web/New/test.php on line 36

Warning: Failed opening './/includes/auth.php' for inclusion (include_path='') in /home/sites/site22/web/New/test.php on line 37

Fatal error: Call to undefined function: session_pagestart() in /home/sites/site22/web/New/test.php on line 50
Ivan

Web Design At It's Best !!!
www.bayareastreetracing.com

Eisi
Registered User
Posts: 67
Joined: Tue Apr 16, 2002 10:22 pm
Location: Germany, NRW
Contact:

Post by Eisi »

Yep, I noticed. :)
I posted not the latest code. Sorry for that.

I will update it alittle later today. Gonna have lunch now. :)

No worries, it will work.
Final Fantasy VII/ IX & Little Big Adventure 2: Eisi's Web-Welten (German)
Projects Under Development:
Event Management Community: VAMOS Online (German)

Teach
Registered User
Posts: 305
Joined: Wed Nov 28, 2001 6:58 am
Location: Hopefully, soon to be somewhere else

Post by Teach »

I downloaded and installed it a few hours after you said you were going to have lunch. I got it to work, but right above the topics, I get the following error messages:

Code: Select all

Warning: Cannot add header information - headers already sent by (output started at /home/computer/public_html/index2.php:7) in /home/computer/public_html/forums/includes/sessions.php on line 280

Warning: Cannot add header information - headers already sent by (output started at /home/computer/public_html/index2.php:7) in /home/computer/public_html/forums/includes/sessions.php on line 281
[EDIT]Version 1.1.0 fixed the problem. Thank you![/EDIT]
Last edited by Teach on Wed Apr 24, 2002 1:17 pm, edited 2 times in total.

Alphajx
Registered User
Posts: 7
Joined: Sat Feb 16, 2002 11:21 am
Contact:

Pld Eisi

Post by Alphajx »

Nice code Eisi. The whole thing works fine! How about the ability to add a template like Acid's?
Later

Alphajx

Eisi
Registered User
Posts: 67
Joined: Tue Apr 16, 2002 10:22 pm
Location: Germany, NRW
Contact:

[UPDATED] Recent Topics MOD

Post by Eisi »

Ok, I just updated the code above and the downloadable archive. Everything should work now. I tested it back and forth the last hours, and at least for me, it works flawless.

Everyone should upgrade, since the old code definitely _will_ produce "Cannot add header" messages at some point sooner or later. It has to do with the way the session_pagestart() was called, and when the script was called. Everything worked fine, after the index.php had been opened once... weird. ;)


@Alphjx: I am actually a php n00b and had a hard time learning enough about phpBB2 and mySQL to get this code finished. I would like a template too, but I currently don't know how to write all the topics into one array, and parse it at a later point of time all at once into a template variable... :) Maybe someone who reads this can help me, or post some code for it...
Final Fantasy VII/ IX & Little Big Adventure 2: Eisi's Web-Welten (German)
Projects Under Development:
Event Management Community: VAMOS Online (German)

blulegend
Registered User
Posts: 83
Joined: Wed Jan 30, 2002 5:41 pm

Post by blulegend »

You can't have html output. You need to use a template based output. I had to change my version for this.

Eisi
Registered User
Posts: 67
Joined: Tue Apr 16, 2002 10:22 pm
Location: Germany, NRW
Contact:

Post by Eisi »

@Bluelegend: I PM'ed you

@Teach: You probably didn't get the latest version. Download again from my signature, or copy from the UPDATED code above. Make sure you have v1.1. It shouldnt be showing any error messages.

The echo commands were causing the errors, right? I suspected it, but dont know my way around yet. If you, or anyone else for that matter, could post a snippet which shows me how to
- put my sql queries into an array
- define the {template variables}. Would be best to have one each for the titles, date and names for easy customization of the template? what do you guys think?
- and parse it into the template, all at once

Currently the errors are supressed since they don't hinder the execution of the script or any other part of phpBB. The errors are gone after you have opened index.php once, anyway. But I would certainly like to recode it in a more correct way.

I am new to all this, so any kind of help would be much appreciated.


And thanks to www.computerbob.com for running the script publicly on his frontpage. Thanks :!:
Final Fantasy VII/ IX & Little Big Adventure 2: Eisi's Web-Welten (German)
Projects Under Development:
Event Management Community: VAMOS Online (German)

talia679
Registered User
Posts: 716
Joined: Tue Mar 12, 2002 4:07 pm
Location: PA
Contact:

Post by talia679 »

Very cool ... I'll have to give this one a try.
Thanks, Talia
Tag You're It Writing Community || TYI Forums
Taleria - Talia's Gallery of 2000+ Links & 140+ Books
GameCrafters Guild – Gaming info and resources

Eisi
Registered User
Posts: 67
Joined: Tue Apr 16, 2002 10:22 pm
Location: Germany, NRW
Contact:

Post by Eisi »

E U R E K A !!!

I tracked the "Warning: Cannot add header..." message down. You PHP-Wizards out there are allowed to laugh at this point, but I am learning by doing atm. :)

The error occurs (among other occurences), when there is HTML code before the <?php include('file'); ?> line and the file calls the session_pagestart() function. Weird about this is, that once the index.php has been opened the errors are gone for good. Can anyone explain that to me perhaps?

[Thinkingoutloud]
In the version 1.1 of my Mod, I have suppressed the error output by calling "@session_pagestart()". Basically, that means for me, that I HAVE to create a template output. Ok, that will be the next version. I am working on it. Gonna implement more features as well.
[/thinkingoutloud]
Final Fantasy VII/ IX & Little Big Adventure 2: Eisi's Web-Welten (German)
Projects Under Development:
Event Management Community: VAMOS Online (German)

Marginal
Registered User
Posts: 40
Joined: Fri Apr 05, 2002 9:23 am
Location: Bruxelles
Contact:

Post by Marginal »

Hi,

In fact, I would like to add this hack in a little bow a the right of my forum (www.lej.be) but I don't know the code I must enter in the template :(
Is anyone able to tell me the code I've to enter please ?
Thank you in advance !
Marginal

Locked

Return to “[2.0.x] MODs in Development”