Firefox PHP

User status based on number of posts

Posted by Mandingo 
User status based on number of posts
July 30, 2004 10:50AM
Hi,
I got this idea from a message board I saw.

At the moment, I have this in read.tpl to show the number of posts by a user in their messages -

{IF MESSAGES->user_id true}{LANG->Posts}: {MESSAGES->user->posts}{/IF}

What I'd like to do is have it so that anyone with less than say 50 posts has the word 'new poster' next to their total or someone with say 5000 posts has 'legendary poster' or something like that. :-D

i suppose I'd have to edit read.php to achieve that?
Re: User status based on number of posts
July 30, 2004 01:06PM
You'd be better off doing this as as module then as a hack. You can create a module that runs when somebody is reading a post, and sets a variable in each message being read based on the number of posts that the poster has.

Your template can simply then print out that variable.
Re: User status based on number of posts
July 30, 2004 03:43PM
Right. That makes sense. I simply don't have a clue where to start though. :-(
Re: User status based on number of posts
July 30, 2004 03:59PM
Just off the top of my head quickly (I can look at it more later when I'm at home), but my Avatar module does something similar. I believe down at the bottom in the last function is when it works with reading posts.

Its using the "read" hook, which gets called when somebody is reading a message (or a series of messages in flat mode). For each message if an avatar is set, it adds a variable to that messages data saying so.

In your case, you could use very similar code. Something like this should do the trick:

foreach ($messages as $message) {
$user = phorum_user_get($user_id, false);
$posts = $user["posts"]; (I think that is the variable name anyway)
if ($posts > 100) {
 $message["postlabel"] = "You've posted a lot!";
}
else {
 $message["postlabel"] = "You newbie!";
}

}

Your template would then simply have to print out {MESSAGE->postlabel} in the appropriate place.
Re: User status based on number of posts
July 30, 2004 06:02PM
O.K. I get the concept, just can't quite get my head around how to make it into a mod...grrr...think...think...think...:-)
Re: User status based on number of posts
July 30, 2004 06:40PM
Take a look at some of the other modules that have already been made for examples. Thats what I do. :)
Re: User status based on number of posts
July 30, 2004 11:03PM
O.K. so if I do a file called 'info.txt' and put in it -

hook: read|mod_status

title: Status Module

desc: List the status of user depending on volume of posts.


and a 'status.php' with -

<?php


if(!defined("PHORUM_ADMIN")) return;


foreach ($messages as $message) {
$user = phorum_user_get($user_id, false);
$posts = $user["posts"];
if ($posts > 100) {
$message["postlabel"] = "You've posted a lot!";
}
else {
$message["postlabel"] = "You newbie!";
}

}

?>

am I going in the right direction?
It's showing up in admin and I can turn it on there, but nothing shows in the message body.

Sorry I'm a TOTAL newbie to mods.

I THINK I need something like -

function phorum_mod_status ($messages)

in there somewhere?




Edited 2 time(s). Last edit at 07/30/2004 11:15PM by Mandingo.
Re: User status based on number of posts
July 30, 2004 11:23PM
you need to run a function yeah. you should really look at the previous modules.

also this is bogus in the module-file:
if(!defined("PHORUM_ADMIN")) return;


Thomas Seifert
Phorum Development Team / Mysnip-Solutions.de
Custom Phorum and general software development
worry-free Phorum Hosting
Re: User status based on number of posts
July 30, 2004 11:28PM
Yep I'm looking at the previous modules. SO I have more or less everything there once I run a function?

Hmm..I'll give it another go. Thanks.
Re: User status based on number of posts
July 30, 2004 11:51PM
O.k. here's what I have -

<b>info.txt</b>

hook: read|phorum_mod_status

title: Status Module

desc: List the status of user depending on volume of posts.

==================================================

<b>status.php</b>

<?php

function phorum_mod_status($message)
{
$PHORUM = $GLOBALS["PHORUM"];


foreach ($messages as $message) {
$user = phorum_user_get($user_id, false);
$posts = $user["posts"];
if ($posts > 100) {
$message["postlabel"] = "You've posted a lot!";
}
else {
$message["postlabel"] = "You newbie!";
}
}

return $message;

}

?>

==================================================

Then I edit 'read.tpl' to include this -

{IF MESSAGES->user_id true}{LANG->Status}:&nbsp;{MESSAGES->mod_status}{/IF}


And....nothing happens :-(
Sorry, only registered users may post in this forum.

Click here to login