Email Email    Print Print   

Display Phorum 5.2 Recent Messages on Custom PHP Page.

Sunday, June 1st, 2008

I spent ages looking around for a simple solution to show a few recent messages posted by users on message boards powered by Phorum.

I couldn’t find anything concise and easy to follow apart from a few hints on the Phorum Support Forum (thanks to Maurice Makaay).

So here’s some code I’ve written with a few comments to help you understand how it works.

I got it to work on the Saathi Night home page. I hope it works for you.

<?php
// ADD THIS SECTION OF PHP TO THE TOP OF YOUR PHP PAGE.
// CHANGES FOCUS TO PHORUM DIRECTORY.
$current_dir = getcwd();
// EDIT THIS LINE AND ENTER THE FULL SERVER PATH TO YOUR PHORUM INSTALLATION
chdir("/path/to/phorum");
// DEFINE THIS PAGE AND INCLUDE COMMON.PHP FROM PHORUM INSTALLATION
define("phorum_page", "my_recent_messages");
include("./common.php");
// GET MESSAGES AS ARRAY.
// THIS GETS ALL THE RECENT POSTED AND UPDATED MESSAGES.
// —————————————————–
$msgs = phorum_db_get_recent_messages(10,0,0,0,"LIST_UPDATED_THREADS");
 
// DOCUMENTATION FOR THIS IS AS FOLLOWS (FROM PHORUM DB LAYER AS OF 01 JUNE 2008)
// array phorum_db_get_recent_messages (integer $length, [integer $offset = 0], [integer $forum_id = 0], [integer $thread = 0], [integer $list_type = LIST_RECENT_MESSAGES])
// integer $length: Limit the number of returned messages to this number.
// integer $offset: When using the $length parameter to limit the number of returned messages, this parameter can be used to specify the retrieval offset.
// integer $forum_id: A forum_id, an array of forum_ids or 0 (zero) to retrieve messages from any forum.
// integer $thread: A thread id or 0 (zero) to retrieve messages from any thread.
// integer $list_type: This parameter determines the type of list that has to be returned. Options for this parameter are:
// LIST_RECENT_MESSAGES: return a list of recent messages
// LIST_RECENT_THREADS: return a list of recent threads
// LIST_UPDATED_THREADS: return a list of recently updated threads
?>
 
<?php
// ADD THIS SECTION OF PHP WHERE YOU WANT YOUR MESSAGES TO APPEAR.
 
// CYCLE THROUGH EACH OF THE MESSAGES IN THE MESSAGE ARRAY
foreach ($msgs as $onemsg)
{
// YOU CAN COMMENT THIS OUT TO SEE ALL POSSIBLE VARIABLES THAT YOU CAN USE TO DISPLAY OR DO SOME PROCESSING FOR EACH MESSAGE print_r($onemsg);
if ($onemsg['subject'])
{
$datestamp = $onemsg['modifystamp'] ? $onemsg['modifystamp'] : $onemsg['datestamp'] ;
// EDIT THE HTTP ADDRESS TO YOUR PHORUM INSTALLATION
echo "<p><a href="http://yoursite.com/phoruminstallation/read.php?".$onemsg['forum_id'].",".$onemsg['thread'].",".$onemsg['message_id']."#msg-".$onemsg['message_id']."">".$onemsg['subject']."</a><br>By <b>".$onemsg['author']."</b> on ".date("D j M Y",$onemsg['datestamp'])."</p>";
}
}
 
// CHANGE FOCUS BACK TO ORIGINAL WORKING DIRECTORY.
chdir($current_dir);
?>

Email To A Friend Email To A Friend    Print This Post Print This Post    
1 Star2 Stars3 Stars4 Stars5 Stars (Rate this Post)
Loading ... Loading ...
Posted before Start of Transformation in: My Stuff & More , Saathi Night , Website Development

Post Your Comment:

Login or Register to Post a comment.