I wanted an easy way for people to see if they had any new messages, so here is what I did
I have miniportal, so I decided to make it a block, but you could apply the code to anything
First I added a entry to the messages table to store whether or not they have viewed the message yet
ALTER TABLE `pun_messages` ADD `read` TINYINT( 1 ) DEFAULT '0' NOT NULL ;
Make sure you replace pun_messages with whatever your messages table is, if it is different
Second, I modified the template file so it would know I want a block there.
Open up include/functions.php and add the following at the very end of the file:
//
// Generate the messages block
//
function generate_messagesblock()
{
global $pun_config, $lang_common, $pun_user, $db;
$messages_return = "";
if (!$pun_user['is_guest']) {
$result = $db->query('SELECT count(*) FROM '.$db->prefix.'messages WHERE status=0 AND owner='.$pun_user['id']) or error('Unable to count messages', __FILE__, __LINE__, $db->error());
list($num_messages) = $db->fetch_row($result);
$result = $db->query('SELECT count(*) FROM '.$db->prefix.'messages WHERE `read`=0 AND status=0 AND owner='.$pun_user['id']) or error('Unable to count unread messages', __FILE__, __LINE__, $db->error());
list($num_messages_unread) = $db->fetch_row($result);
$messages_return .= "You currently have <b>".$num_messages."</b> messages, of which ";
if ($num_messages_unread>0) {
$messages_return .= "<font color=\"red\">";
}
$messages_return .= "<b>".$num_messages_unread."</b> are new";
if ($num_messages_unread>0) {
$messages_return .= "</font>";
}
$messages_return .= ".<br><a href=\"message_list.php\">Click here to view them</a>.";
} else {
$messages_return .= "Please log in to check your messaging status.";
}
return $messages_return;
}
Then open include/template/main.tpl, and find this:
<div class="block">
<h2><span>Menu</span></h2>
<div class="box">
<pun_sidelinks>
</div>
</div>
After it, add:
<div class="block">
<h2 class="block2"><span>Messages</span></h2>
<div class="box">
<div class="inbox">
<pun_messagesblock>
</div>
</div>
</div>
Then open header.php, and find this:
// START SUBST - <pun_sidelinks>
$tpl_main = str_replace('<pun_sidelinks>','<div class="inbox">'."\n\t\t\t". generate_navlinks()."\n\t\t".'</div>', $tpl_main);
// END SUBST - <pun_sidelinks>
After it, add:
// START SUBST - <pun_messagesblock>
$tpl_main = str_replace('<pun_messagesblock>','<div class="inbox">'."\n\t\t\t". generate_messagesblock()."\n\t\t".'</div>', $tpl_main);
// END SUBST - <pun_messagesblock>
Now open message_list.php, and find this:
// Do signature parsing/caching
if (isset($cur_post['signature']) && $pun_user['show_sig'] != '0')
{
$signature = parse_signature($cur_post['signature']);
}
After it, add:
//Mark it as read
$result = $db->query('UPDATE '.$db->prefix.'messages SET `read`=1 WHERE id='.$id) or error('UPDATE '.$db->prefix.'messages SET read=1 WHERE `id`='.$id.'Unable to set message as read', __FILE__, __LINE__, $db->error());
And that's it. Save and upload header.php, message_list.php, include/functions.php, and include/template/main.tpl
Right now message_list.php doesnt make the message title look any different if its unread, I just wanted to keep it simple
If this is completely useless to everyone, sorry :X