TinyPortal

Development => Block Codes => Topic started by: MeRcChRiS on October 06, 2006, 04:09:06 AM

Title: Active Posters
Post by: MeRcChRiS on October 06, 2006, 04:09:06 AM
ok i need a TP Block that will show who has posted in a 24hr format.
The posts are going to be how much they posted in that day.

Name | Posts

[name] | [posts]
[name] | [posts]
[name] | [posts]
[name] | [posts]

etc... from the person with the most posts to the person with the least posts of that day, and a way for me to change how many people to show.
Title: Re: Active Posters
Post by: JPDeni on October 06, 2006, 02:29:32 PM
With any luck, this should work. This is a slight alteration of the "Top Posters" block, but I changed the start and stop times.
global $db_prefix, $scripturl;

$starttime = time() - (24 * 60 * 60);
$endtime = time(); 
$number_to_list = 9; // (one less than you want to list)

$count= array();
$poster_number = array();
$query = db_query(
    "SELECT posterName, {$db_prefix}messages.ID_MEMBER, ID_GROUP
     FROM {$db_prefix}members
     JOIN {$db_prefix}messages
     ON {$db_prefix}members.ID_MEMBER = {$db_prefix}messages.ID_MEMBER
     WHERE posterTime > $starttime
     AND posterTime < $endtime", __FILE__, __LINE__);

while ($row = mysql_fetch_assoc($query))
{
  if (!isset($count[$row['posterName']]))
    $count[$row['posterName']] = 0;
  ++$count[$row['posterName']];
    $poster_number[$row['posterName']] = $row['ID_MEMBER'];
}

arsort($count);
$list_number = 0;
foreach ($count as $key => $value)
{
  echo '<a class="normaltext" href="' . $scripturl . '?action=profile;u=' . $poster_number[$key] . '">' . $key . '</a> | ' . $value . '<br />';
  ++$list_number;
  if ($list_number > $number_to_list) 
    break;
}


I think the problem last night was that I was putting in too many quotes. We'll see if this works.
Title: Re: Active Posters
Post by: MeRcChRiS on October 06, 2006, 03:37:55 PM
mm no, i get this error,

   
Parse error: syntax error, unexpected T_STRING in /home/sector/public_html/carnage/oforums/Sources/Load.php(1613) : eval()'d code(34) : eval()'d code on line 5

im going to be at school so ill be back later, but keep working and good luck ;D
Title: Re: Active Posters
Post by: JPDeni on October 06, 2006, 03:41:23 PM
Sorry. Somehow I used spaces instead of underlines. It should be

$number_to_list = 9
and
if ($list_number > $number_to_list)
Title: Re: Active Posters
Post by: jacortina on October 06, 2006, 04:55:41 PM
Any reason you don't just let the query count and sort and limit?

global $db_prefix, $scripturl, $memberContext, $txt, $modSettings;

$starttime = strtotime('24 hours ago');
$list_count = 10;

$poster = array();

$request = db_query("
SELECTÃ,  m.ID_MEMBER, COUNT(m.ID_MEMBER) as postCount
FROM ({$db_prefix}messages AS m, {$db_prefix}topics AS t, {$db_prefix}boards AS b)
WHERE m.posterTime > " . $starttime . "
AND t.ID_TOPIC = m.ID_TOPIC
AND b.ID_BOARD = t.ID_BOARD" . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? " AND b.ID_BOARD != $modSettings[recycle_board]" : '') . "
GROUP BY m.ID_MEMBER
ORDER BY postCount DESC LIMIT " . $list_count, __FILE__, __LINE__);

while ($row = mysql_fetch_assoc($request))
{
Ã,  Ã,  loadMemberData(array($row['ID_MEMBER']));
Ã,  Ã,  loadMemberContext($row['ID_MEMBER']);
$poster[$row['ID_MEMBER']] = array (
Ã,  'id' => $row['ID_MEMBER'],
Ã,  'count' => $row['postCount'],
Ã,  'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '" title="' . $txt[92] . ' ' . $memberContext[$row['ID_MEMBER']]['name'] . '">' . '<font color="' . $memberContext[$row['ID_MEMBER']]['group_color'] . '">' . $memberContext[$row['ID_MEMBER']]['name'] . '</font>' . '</a>' );
}
mysql_free_result($request);

echo '<table width=100%>';
foreach($poster as $top_user)
{
echo '<tr>
Ã,  Ã,  Ã,  <td align="right" width=75%>' . $top_user['link'] . '</td>
Ã,  Ã,  Ã,  <td align="left">| '. $top_user['count'] . '</td>
Ã,  Ã,  Ã,  </tr>';
}
echo '</table>';


This code should ignore recycle bin entries (but doesn't seem to right now) and includes membergroup colors.

Edit: OK, now it excludes recycle been correctly. Forgoet to global $modSettings.
Title: Re: Active Posters
Post by: JPDeni on October 06, 2006, 07:25:17 PM
QuoteAny reason you don't just let the query count and sort and limit?
Because I didn't think of it?  ;D

Title: Re: Active Posters
Post by: jacortina on October 06, 2006, 07:28:12 PM
Oh. OK. As long as there was a good reason for it.  ;)
Title: Re: Active Posters
Post by: MeRcChRiS on October 06, 2006, 11:56:40 PM
 i tried both codes, and the 2nd one is cool, but how do i center it?


Also on both codes it shows posts i did from yesterday and not just today, how do i change that?

Quote$number_to_list = 9

needs to be

Quote$number_to_list = 9;
Title: Re: Active Posters
Post by: jacortina on October 07, 2006, 12:43:57 AM
I gave the names 75% of the width as they'll generally be longer than the number of digits in a daily post count. But, you can change that in the line:

<td align="right" width=75%>' . $top_user['link'] . '</td>


And, sorry, interpreted day to mean last 24 hours (which would be a 'rolling', top poster).

Be aware that 'since midnight' will be 'since midnight according to server time'. Change:

$starttime = strtotime('24 hours ago');
to
$starttime = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
Title: Re: Active Posters
Post by: JPDeni on October 07, 2006, 12:54:21 AM
Quote$number_to_list = 9

needs to be

$number_to_list = 9;
Right. I didn't put the whole line in. I did, however, fix the line in the original code.
Title: Re: Active Posters
Post by: MeRcChRiS on October 07, 2006, 12:56:56 AM
So if i change it to

$starttime = mktime(0, 0, 0, date('m'), date('d'), date('Y'));

then what ever the server time is at then it uses that time?
Title: Re: Active Posters
Post by: jacortina on October 07, 2006, 01:00:41 AM
It will mean starting time is start of calendar day AT the server (hour 0, minute 0, sec 0 of current server date; all these are according to the server the script is on).
Title: Re: Active Posters
Post by: MeRcChRiS on October 07, 2006, 01:05:54 AM
how would i know what date my server is on? is it the thing that in the Features and Options>Overall time offset?
Title: Re: Active Posters
Post by: jacortina on October 07, 2006, 01:14:28 AM
How to  put this...

The date should be current (within a couple of hours). The time YOU see when logged on is your offset (in your profile) plue the Overall time offset. If you display time to guests, that will reflect the Overall time offset only.

[NOTE: Are you SURE you don't want a running 24 hour count? ;) ]
Title: Re: Active Posters
Post by: MeRcChRiS on October 07, 2006, 01:18:39 AM
yeah i switched it back, thought it would be easier.
Title: Re: Active Posters
Post by: MeRcChRiS on October 07, 2006, 01:37:51 AM
Can you make me a Gallery php block,
1.Stats

Total Pictures:
Total Views:
Total Gallery Filesize:
Total Comments:

2.
      Most Viewed Image
       [Image Thumbnail]

      Most Recent Picture
       [Image Thumbnail]

heres the mod im using:http://mods.simplemachines.org/index.php?mod=473 (http://mods.simplemachines.org/index.php?mod=473)
Title: Re: Active Posters
Post by: jacortina on October 07, 2006, 01:58:05 AM
I'll have to take a pass on that. Don't like trying to code blind and I don't use that mod.
Title: Re: Active Posters
Post by: MeRcChRiS on October 07, 2006, 02:01:07 AM
oh ok, thanks for everything to!
Title: Re: Active Posters
Post by: Alundra on February 03, 2008, 10:32:51 PM
How do I exclude admin from showing?
Title: Re: Active Posters
Post by: platinumUWE on February 04, 2008, 06:42:02 PM
what kind of block is this suitbale for pls...php........ script
Title: Re: Active Posters
Post by: wilsy on February 04, 2008, 06:51:47 PM
Its a PHP block.

Regards,

Wilsy.
Title: Re: Active Posters
Post by: Alundra on February 05, 2008, 04:10:04 AM
How do I exclude admin?
Title: Re: Active Posters
Post by: JPDeni on February 05, 2008, 04:53:05 AM
I'm assuming you're using J. A. Cortina's code.

Change

SELECT  m.ID_MEMBER, COUNT(m.ID_MEMBER) as postCount
FROM ({$db_prefix}messages AS m, {$db_prefix}topics AS t, {$db_prefix}boards AS b)
WHERE m.posterTime > " . $starttime . "
AND t.ID_TOPIC = m.ID_TOPIC
AND b.ID_BOARD = t.ID_BOARD" . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? " AND b.ID_BOARD != $modSettings[recycle_board]" : '') . "
GROUP BY m.ID_MEMBER
ORDER BY postCount DESC LIMIT " . $list_count, __FILE__, __LINE__);


to


SELECT  m.ID_MEMBER, COUNT(m.ID_MEMBER) as postCount
FROM ({$db_prefix}messages AS m, {$db_prefix}topics AS t, {$db_prefix}boards AS b, {$db_prefix}members AS mem)
WHERE m.posterTime > " . $starttime . "
                                                   AND mem.ID_GROUP != 1
AND t.ID_TOPIC = m.ID_TOPIC
                                                   AND m.ID_MEMBER = mem.ID_MEMBER
AND b.ID_BOARD = t.ID_BOARD" . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? " AND b.ID_BOARD != $modSettings[recycle_board]" : '') . "
GROUP BY m.ID_MEMBER
ORDER BY postCount DESC LIMIT " . $list_count, __FILE__, __LINE__);


I think. :-) I haven't tested this, but it should work.
Title: Re: Active Posters
Post by: Alundra on February 07, 2008, 02:16:15 AM
It's perfect :D thank you!
Title: Re: Active Posters
Post by: Clipper107 on February 11, 2008, 10:13:47 AM
I'm pasting the code in a PHP block but I get an error, could somebody give me the whole correct code to paste in a PHP block...... :-\
Title: Re: Active Posters
Post by: G6Cad on February 11, 2008, 10:26:48 AM
How about you read the topic from the start.
JP Denis clearly said her change was from JA Cortina code earlier in the topic.
Title: Re: Active Posters
Post by: JPDeni on February 11, 2008, 01:45:40 PM
Clipper, what code did you paste into a php block? What is the error?
Title: Re: Active Posters
Post by: warhonowicz on February 13, 2008, 04:23:49 PM
could this be changed to show all users logged on during the last 24 hrs (or ever) rather than users that posted together with the time they are logged on (like what the admin can see in the members list via the admin panel)?
Title: Re: Active Posters
Post by: JPDeni on February 13, 2008, 06:18:34 PM
This shows those logged in during the past 24 hours, in order by the most recent log in.


global $db_prefix, $scripturl;

$starttime = time() - (24 * 60 * 60);

$query = db_query(
    "SELECT memberName, lastLogin
     FROM {$db_prefix}members
     WHERE lastLogin > $starttime
     ORDER BY lastLogin DESC", __FILE__, __LINE__);

echo "<table>";
while ($row = mysql_fetch_assoc($query))
{
  echo "<tr><td>";
  echo $row['memberName'];
  echo "</td><td>";
  echo timeformat($row['lastLogin']);
  echo "</td></tr>";
}
echo "</table>";
Title: Re: Active Posters
Post by: warhonowicz on February 13, 2008, 08:04:40 PM
cheers, have added the post count to it, just in case anyone is interested


global $db_prefix, $scripturl;

$starttime = time() - (30 * 7 * 24 * 60 * 60);

$query = db_query(
    "SELECT memberName, lastLogin, posts
     FROM {$db_prefix}members
     WHERE lastLogin > $starttime
     ORDER BY lastLogin DESC", __FILE__, __LINE__);

echo "<table>";
while ($row = mysql_fetch_assoc($query))
{
  echo "<tr><td>";
  echo $row['memberName'];
  echo "</td><td>";
  echo " | last logged on: ";
  echo "</td><td>";
  echo timeformat($row['lastLogin']);
  echo "</td><td>"; 
  echo " | posts: ";
  echo "</td><td>";
   echo $row['posts'];
  echo "</td></tr>";
 
}
echo "</table>";
Title: Re: Active Posters
Post by: wilsy on February 13, 2008, 09:32:11 PM
Quote from: warhonowicz on February 13, 2008, 08:04:40 PM
cheers, have added the post count to it, just in case anyone is interested



Could this block be made to scroll?

Regards,

Wilsy.
global $db_prefix, $scripturl;

$starttime = time() - (30 * 7 * 24 * 60 * 60);

$query = db_query(
    "SELECT memberName, lastLogin, posts
     FROM {$db_prefix}members
     WHERE lastLogin > $starttime
     ORDER BY lastLogin DESC", __FILE__, __LINE__);

echo "<table>";
while ($row = mysql_fetch_assoc($query))
{
  echo "<tr><td>";
  echo $row['memberName'];
  echo "</td><td>";
  echo " | last logged on: ";
  echo "</td><td>";
  echo timeformat($row['lastLogin']);
  echo "</td><td>"; 
  echo " | posts: ";
  echo "</td><td>";
   echo $row['posts'];
  echo "</td></tr>";
 
}
echo "</table>";

Title: Re: Active Posters
Post by: limogal on March 23, 2008, 12:52:28 PM
Quote from: JPDeni on October 06, 2006, 02:29:32 PM
With any luck, this should work. This is a slight alteration of the "Top Posters" block, but I changed the start and stop times.
global $db_prefix, $scripturl;

$starttime = time() - (24 * 60 * 60);
$endtime = time(); 
$number_to_list = 9; // (one less than you want to list)

$count= array();
$poster_number = array();
$query = db_query(
    "SELECT posterName, {$db_prefix}messages.ID_MEMBER, ID_GROUP
     FROM {$db_prefix}members
     JOIN {$db_prefix}messages
     ON {$db_prefix}members.ID_MEMBER = {$db_prefix}messages.ID_MEMBER
     WHERE posterTime > $starttime
     AND posterTime < $endtime", __FILE__, __LINE__);

while ($row = mysql_fetch_assoc($query))
{
  if (!isset($count[$row['posterName']]))
    $count[$row['posterName']] = 0;
  ++$count[$row['posterName']];
    $poster_number[$row['posterName']] = $row['ID_MEMBER'];
}

arsort($count);
$list_number = 0;
foreach ($count as $key => $value)
{
  echo '<a class="normaltext" href="' . $scripturl . '?action=profile;u=' . $poster_number[$key] . '">' . $key . '</a> | ' . $value . '<br />';
  ++$list_number;
  if ($list_number > $number_to_list) 
    break;
}


I think the problem last night was that I was putting in too many quotes. We'll see if this works.
hello Im tryin to learn all this stuff and Im totally confused what the right code to add to block would be by all the well I forgot this and if you do that lol can you please post the code exactly the way it should be so I can just add it till i learn all this scripting alittle bit better.
Thanks  a bunch and happy easter !
Title: Re: Active Posters
Post by: JPDeni on March 23, 2008, 01:30:53 PM
I'm not sure I understand what you're trying to say. I had to insert my own punctuation. :)

But, from the look of the code you posted, it is complete. Have you tried it?
Title: Re: Active Posters
Post by: wyvern on March 26, 2008, 02:54:48 PM
This is a nice block.  But it displays the usernames of members - not the chosen 'Display Name'.

I'm hopeful its an easy change... but I am not up to the task today...
Title: Re: Active Posters
Post by: JPDeni on March 26, 2008, 03:16:02 PM
Change


"SELECT posterName,


to


"SELECT realName,
Title: Re: Active Posters
Post by: wyvern on March 26, 2008, 03:32:11 PM
Thank you.

edit:

For completeness, the entire code for the block using Display Names:

global $db_prefix, $scripturl;

$starttime = time() - (24 * 60 * 60);
$endtime = time(); 
$number_to_list = 9; // (one less than you want to list)

$count= array();
$poster_number = array();
$query = db_query(
    "SELECT realName, {$db_prefix}messages.ID_MEMBER, ID_GROUP
     FROM {$db_prefix}members
     JOIN {$db_prefix}messages
     ON {$db_prefix}members.ID_MEMBER = {$db_prefix}messages.ID_MEMBER
     WHERE posterTime > $starttime
     AND posterTime < $endtime", __FILE__, __LINE__);

while ($row = mysql_fetch_assoc($query))
{
  if (!isset($count[$row['realName']]))
    $count[$row['realName']] = 0;
  ++$count[$row['realName']];
    $poster_number[$row['realName']] = $row['ID_MEMBER'];
}

arsort($count);
$list_number = 0;
foreach ($count as $key => $value)
{
  echo '<span class="smalltext"><a href="' . $scripturl . '?action=profile;u=' . $poster_number[$key] . '">' . $key . '</a>    ' . $value . '</span><br />';
  ++$list_number;
  if ($list_number > $number_to_list) 
    break;
}
Title: Re: Active Posters
Post by: blouogies on June 20, 2008, 07:59:56 AM
Quote from: wyvern on March 26, 2008, 03:32:11 PM
Thank you.

edit:

For completeness, the entire code for the block using Display Names:

global $db_prefix, $scripturl;

$starttime = time() - (24 * 60 * 60);
$endtime = time(); 
$number_to_list = 9; // (one less than you want to list)

$count= array();
$poster_number = array();
$query = db_query(
    "SELECT realName, {$db_prefix}messages.ID_MEMBER, ID_GROUP
     FROM {$db_prefix}members
     JOIN {$db_prefix}messages
     ON {$db_prefix}members.ID_MEMBER = {$db_prefix}messages.ID_MEMBER
     WHERE posterTime > $starttime
     AND posterTime < $endtime", __FILE__, __LINE__);

while ($row = mysql_fetch_assoc($query))
{
  if (!isset($count[$row['realName']]))
    $count[$row['realName']] = 0;
  ++$count[$row['realName']];
    $poster_number[$row['realName']] = $row['ID_MEMBER'];
}

arsort($count);
$list_number = 0;
foreach ($count as $key => $value)
{
  echo '<span class="smalltext"><a href="' . $scripturl . '?action=profile;u=' . $poster_number[$key] . '">' . $key . '</a>    ' . $value . '</span><br />';
  ++$list_number;
  if ($list_number > $number_to_list) 
    break;
}

Thanks for displaying the total code!
This is a awesome block thanks guys!!!