TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,917
  • Total Topics: 21,308
  • Online today: 629
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 509
  • Total: 509

Top Stats - 3 in 1 Block

Started by akulion, November 04, 2006, 03:53:42 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

brianjw

Introducing the 4 in 1 block!!! YAY! edited code by Aku and JPDeni and transformed with 4 columns and the 4th column has this months birthdays! My first php customizing!! WOOHOO!

Code (If you want to use it - feel free) Select

global $db_prefix, $memberContext;

$count = 2;
$users = array();

$request = db_query("
SELECT ID_MEMBER FROM {$db_prefix}members WHERE is_activated = 1 ORDER BY ID_MEMBER DESC LIMIT ".$count, __FILE__, __LINE__);

while ($row = mysql_fetch_assoc($request)) {
$users[] = intval($row['ID_MEMBER']);
}

loadMemberData($users);
echo'<table border="1" width="100%" id="table1" cellpadding="2" style="border-collapse: collapse">
<tr><td  bgcolor="#FF9900" width="150"><font color="#FFFFFF" face="Verdana" size="2"><b>Newest Members</b></font></td><td bgcolor="#660066" width="200"><font color="#FFFFFF" face="Verdana" size="2"><b>Top 10 Posters</b></font></td><td  bgcolor="#336699"><font color="#FFFFFF" face="Verdana" size="2"><b>This Weeks Top Posters</b></font></td><td  bgcolor="#00CC33"><font color="#FFFFFF" face="Verdana" size="2"><b>This Months Birthdays</b></font></td></tr><tr>
<td>';
$i = 0;
foreach($users as $user_id) {
if ($i > 0) echo '<hr>';
$i++;

loadMemberContext($user_id);

if (!empty($memberContext[$user_id]['avatar']['image']))
echo '<div align="center">'.$memberContext[$user_id]['avatar']['image'].'<BR>'.$memberContext[$user_id]['link'].'</div>';
else
echo '<div align="center"><img src="http://brianjwilson.com/forum/noava.gif" height=80 widh=80><BR><BR>'.$memberContext[$user_id]['link'].'</div>';
}

$numberofposters = 10; // You can change this to however many you want

require_once "SSI.php";
$top_posters = ssi_topPoster($numberofposters, "return");
echo'</td><td>';
foreach ($top_posters as $poster)
{
  echo $poster['link'] , ' (', $poster['posts'] , ')<br />';
}
echo'</td><td>';

global $db_prefix;
$count= array();

$query = db_query(
    "SELECT posterName
     FROM {$db_prefix}messages
     ORDER BY posterTime DESC
     LIMIT 100", __FILE__, __LINE__);

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

$random = array_rand($count, count($count));
echo '<div style="text-align: center">';
foreach ($random as $value)
{
  $fsize = $count[$value] + 7;
  $name = str_replace(" ",'Ã,·',$value);
  echo '<span style="font-size:' . $fsize . 'pt;">' . $name . '</span> ';
}
echo '</div></td><td>';
global $db_prefix, $scripturl;

echo '
  <div style="padding: 4px; font-weight: bold;">';
echo $title;
echo '
  </div>
  <div class="windowbg" style="padding: 4px; ">';
      $month = date('m');
      $month_number = '-' . $month . '-';
      $query = db_query(
    "SELECT ID_MEMBER, memberName, birthdate
     FROM {$db_prefix}members
     WHERE birthdate LIKE '%$month_number%'
     AND birthdate NOT LIKE '0001-01-01'
     ORDER BY memberName", __FILE__, __LINE__);
  if(db_affected_rows() != 0)
  {
    $birthdays = array();
    $member = array();
    while ($row = mysql_fetch_assoc($query))
    {
       $day = substr($row['birthdate'],8,2);
       $birthdays[$row['memberName']] =  $day;
       $member[$row['memberName']] = $row['ID_MEMBER'];
    }
    asort($birthdays);
    foreach ($birthdays as $key => $value)
    {
      echo '<a class="normaltext" href="' . $scripturl . '?action=profile;u=' . $member[$key] . '">' . $key . '</a> (' . $value . '.' . $month . ')<br />';
   }
}
else
  echo 'No birthdays this month';
echo'</div> ';
echo'</td></tr>
</table>';

put that code in a phpblock (CENTER BLOCK)

knat

Nice work Brian  ;) I also changed mine to a 4 in 1 block but my 4th block shows some forum stats  8)

brianjw

#62
I was thinking about making it with tabs but couldn't understand it so I moved to the stats like you.
I have 20 top posters and I have 3 newest members...

global $db_prefix, $memberContext;

$count = 3;
$users = array();

$request = db_query("
SELECT ID_MEMBER FROM {$db_prefix}members WHERE is_activated = 1 ORDER BY ID_MEMBER DESC LIMIT ".$count, __FILE__, __LINE__);

while ($row = mysql_fetch_assoc($request)) {
$users[] = intval($row['ID_MEMBER']);
}

loadMemberData($users);
echo'<table border="1" width="100%" id="table1" cellpadding="2" style="border-collapse: collapse">
<tr><tdÃ,  bgcolor="#FF9900" width="150"><font color="#FFFFFF" face="Verdana" size="2"><b>Newest Members</b></font></td><td bgcolor="#660066" width="200"><font color="#FFFFFF" face="Verdana" size="2"><b>Top 20 Posters</b></font></td><tdÃ,  bgcolor="#336699"><font color="#FFFFFF" face="Verdana" size="2"><b>This Weeks Top Posters</b></font></td><tdÃ,  bgcolor="#00CC33"><font color="#FFFFFF" face="Verdana" size="2"><b>Stats</b></font></td></tr><tr>
<td>';
$i = 0;
foreach($users as $user_id) {
if ($i > 0) echo '<hr>';
$i++;

loadMemberContext($user_id);

if (!empty($memberContext[$user_id]['avatar']['image']))
echo '<div align="center">'.$memberContext[$user_id]['avatar']['image'].'<BR>'.$memberContext[$user_id]['link'].'</div>';
else
echo '<div align="center"><img src="http://brianjwilson.com/forum/noava.gif" height=80 widh=80><BR><BR>'.$memberContext[$user_id]['link'].'</div>';
}

$numberofposters = 20; // You can change this to however many you want

require_once "SSI.php";
$top_posters = ssi_topPoster($numberofposters, "return");
echo'</td><td>';
foreach ($top_posters as $poster)
{
Ã,  echo $poster['link'] , ' (', $poster['posts'] , ')<br />';
}
echo'</td><td>';

global $db_prefix;
$count= array();

$query = db_query(
Ã,  Ã,  "SELECT posterName
Ã,  Ã,   FROM {$db_prefix}messages
Ã,  Ã,   ORDER BY posterTime DESC
Ã,  Ã,   LIMIT 100", __FILE__, __LINE__);

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

$random = array_rand($count, count($count));
echo '<div style="text-align: center">';
foreach ($random as $value)
{
Ã,  $fsize = $count[$value] + 7;
Ã,  $name = str_replace(" ",'Ã,·',$value);
Ã,  echo '<span style="font-size:' . $fsize . 'pt;">' . $name . '</span> ';
}
echo '</div></td><td>';
TPortal_statsbox();
echo'</td></tr>
</table>';

Does anyone have any idea on how to make the stats table wider? Click here to see

brianjw

knat

you can control the width of each td in your table..

here is my code.. but its unuseable to you because i use some css that you dont have.. but you can maybe see how i changed my code  :)

global $db_prefix, $memberContext, $modSettings;
$count = 1;
$users = array();

$request = db_query("
SELECT ID_MEMBER FROM {$db_prefix}members WHERE is_activated = 1 AND ID_GROUP <> 1 AND ID_GROUP <> 2 ORDER BY ID_MEMBER DESC LIMIT ".$count, __FILE__, __LINE__);

while ($row = mysql_fetch_assoc($request)) {
$users[] = intval($row['ID_MEMBER']);
}

loadMemberData($users);
echo'<table width="100%" id="table1">
<tr><td class="tborder6"><font color="#000000" face="Verdana" size="2"><b><center>Nyeste:</center></b></font></td><td class="tborder6" width="150"><font color="#000000" face="Verdana" size="2"><b><center>Top 5 Aktive</center></b></font></td><td class="tborder5"><font color="#000000" face="Verdana" size="2"><b><center>Sidste 7 dages mest aktive medlemmer:</center></b></font></td><td class="tborder4" align="center" width="10"><font color="#000000" face="Verdana" size="2"><b><center>Statistik:</center></b></font></td></tr><tr overflow="hidden">

<td class="tborder6" overflow="hidden" align="center" valign="middle" width="80" height="80">';
$i = 0;
foreach($users as $user_id) {
if ($i > 0) echo '<hr>';
$i++;

loadMemberContext($user_id);

if (!empty($memberContext[$user_id]['avatar']['image']))
echo '<div align="center" height="80" Width="80" overflow="auto">'.$memberContext[$user_id]['avatar']['image'].'<BR>'.$memberContext[$user_id]['link'].'</div>';
else
echo '<div align="center"><img src="http://gapeindex.dk/avatars/noava.gif" height=80 width=80><BR>'.$memberContext[$user_id]['link'].'</div>';
}

$numberofposters = 5; // You can change this to however many you want

$request = db_query("
SELECT ID_MEMBER, realName, posts
FROM {$db_prefix}members
                          WHERE ID_GROUP <> 1
                          AND ID_GROUP <> 2
ORDER BY posts DESC
LIMIT $numberofposters", __FILE__, __LINE__);
$top_posters= array();
while ($row = mysql_fetch_assoc($request))
$top_posters[] = array(
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['realName'] . '</a>',
'posts' => $row['posts']
);
mysql_free_result($request);


echo'</td><td class="tborder6" padding="2" width="150" align="middle" valign="middle"><center>';
foreach ($top_posters as $poster)
{
  echo $poster['link'] , ' (', $poster['posts'] , ')<br />';
}
echo'</td></center><td class="tborder5" overflow="hidden">';

global $db_prefix, $scripturl;
$nbsp = "&n"."bsp;";
$count= array();
$poster_number = array();
$query = db_query(
    "SELECT mes.posterName, mes.ID_MEMBER, mem.ID_GROUP, grp.onlineColor
     FROM smf_messages as mes
     LEFT JOIN smf_members as mem
     ON mem.ID_MEMBER = mes.ID_MEMBER
     LEFT JOIN smf_membergroups as grp
     ON grp.ID_GROUP = mem.ID_GROUP
     WHERE mem.ID_GROUP <> 1 AND mem.ID_GROUP <> 2
     ORDER BY posterTime DESC
     LIMIT 100", __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'];
    $poster_color[$row['posterName']] = $row['onlineColor'];
}

asort($count);
$low_count = reset($count);

$random = array_rand($count, count($count));
echo '<div style="text-align: center">';
foreach ($random as $value)
{
  $fsize = intval($count[$value]/$low_count) + 4;
  if ($fsize > 18)
    $fsize = 18;
  elseif ($fsize < 8)
    $fsize = 8;
  $name = str_replace(" ",$nbsp,$value);
  if (!empty($poster_color[$value]))
    echo '<a class="link" href="' . $scripturl . '?action=profile;u=' . $poster_number[$value] .
    '" style="font-size:' . $fsize . 'pt; color:' . $poster_color[$value] . '"> ' . $name . ' </a> ';
  else
    echo '<a class="link" href="' . $scripturl . '?action=profile;u=' . $poster_number[$value] .
    '" style="font-size:' . $fsize . 'pt; color:' . $poster_color[$value] . '"> ' . $name . ' </a> ';
}
echo '</div></td><td width="150" class="tborder4" valign="middle">';
$today = strtotime("24 hours ago");
date('j') == 1 ? $thismonth = $today : $thismonth = strtotime(date('F') . ' 1');
date('l') == 'Sunday' ? $thisweek = $today : $thisweek = strtotime('last Sunday');
date('M') == 'January' ? $thisyear = $thismonth : $thisyear = strtotime('January 1');

$query = db_query("SELECT
COUNT(dateRegistered > $thisyear OR NULL) as year,
COUNT(dateRegistered > $thismonth OR NULL) as month,
COUNT(dateRegistered > $thisweek OR NULL) as week,
COUNT(dateRegistered > $today OR NULL) as today
FROM {$db_prefix}members
WHERE is_activated = 1", __FILE__, __LINE__);
$row = mysql_fetch_assoc($query);

settype($row['today'], "integer");
settype($row['week'], "integer");
settype($row['month'], "integer");

echo '<center>Medlemmer: ', $modSettings['totalMembers'],'<br/>';
echo 'Denne måned: ', $row['month'],'<br/>';
echo 'Denne uge: ', $row['week'],'<br/>';
echo 'Sidste 24 timer: ', $row['today'];

echo '</center></td></tr></table>';

brianjw

How would I make: This Weeks Top Posters show up with Display Names and not usernames? ???

Code I am using:

global $db_prefix, $memberContext;

$count = 3;
$users = array();

$request = db_query("
SELECT ID_MEMBER FROM {$db_prefix}members WHERE is_activated = 1 ORDER BY ID_MEMBER DESC LIMIT ".$count, __FILE__, __LINE__);

while ($row = mysql_fetch_assoc($request)) {
$users[] = intval($row['ID_MEMBER']);
}

loadMemberData($users);
echo'<table border="1" width="100%" id="table1" cellpadding="2" style="border-collapse: collapse">
<tr><td  bgcolor="#FF9900" width="150"><font color="#FFFFFF" face="Verdana" size="2"><b>Newest Members</b></font></td><td bgcolor="#660066" width="200"><font color="#FFFFFF" face="Verdana" size="2"><b>Top 20 Posters</b></font></td><td  bgcolor="#336699"><font color="#FFFFFF" face="Verdana" size="2"><b>This Weeks Top Posters</b></font></td><td  bgcolor="#00CC33"><font color="#FFFFFF" face="Verdana" size="2"><b>Stats</b></font></td></tr><tr>
<td>';
$i = 0;
foreach($users as $user_id) {
if ($i > 0) echo '<hr>';
$i++;

loadMemberContext($user_id);

if (!empty($memberContext[$user_id]['avatar']['image']))
echo '<div align="center">'.$memberContext[$user_id]['avatar']['image'].'<BR>'.$memberContext[$user_id]['link'].'</div>';
else
echo '<div align="center"><img src="http://brianjwilson.com/forum/noava.gif" height=80 widh=80><BR><BR>'.$memberContext[$user_id]['link'].'</div>';
}

$numberofposters = 20; // You can change this to however many you want

require_once "SSI.php";
$top_posters = ssi_topPoster($numberofposters, "return");
echo'</td><td>';
foreach ($top_posters as $poster)
{
  echo $poster['link'] , ' (', $poster['posts'] , ')<br />';
}
echo'</td><td>';

global $db_prefix;
$count= array();

$query = db_query(
    "SELECT posterName
     FROM {$db_prefix}messages
     ORDER BY posterTime DESC
     LIMIT 100", __FILE__, __LINE__);

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

$random = array_rand($count, count($count));
echo '<div style="text-align: center">';
foreach ($random as $value)
{
  $fsize = $count[$value] + 7;
  $name = str_replace(" ",'Ã,·',$value);
  echo '<span style="font-size:' . $fsize . 'pt;">' . $name . '</span> ';
}
echo '</div></td><td>';
TPortal_statsbox();
echo'</td></tr>
</table>';

I think I have to modify the SSI.php but to make sure I am asking here and also am asking where. :)

Thanks,
Brianjw

JPDeni

#65
Rather than modifying SSI.php, it would be better just to put the code in your block.

Instead of


$numberofposters = 20; // You can change this to however many you want

require_once "SSI.php";
$top_posters = ssi_topPoster($numberofposters, "return");
echo'</td><td>';
foreach ($top_posters as $poster)
{
  echo $poster['link'] , ' (', $poster['posts'] , ')<br />';
}



use


global $scripturl;
echo'</td><td>';
$numberofposters = 20; // You can change this to however many you want

$request = db_query("
  SELECT ID_MEMBER, memberName, posts
  FROM {$db_prefix}members
  ORDER BY posts DESC
  LIMIT $numberofposters", __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($request))
  echo '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['memberName'] . '</a>' , ' (', $row['posts'] , ')<br />';
mysql_free_result($request);


It's only a little more code, but it makes it easier to alter if you decide you want to later on.

RoarinRow

Quote from: JPDeni on February 28, 2007, 04:13:12 PM
Rather than modifying SSI.php, it would be better just to put the code in your block.


global $scripturl;
echo'</td><td>';
$numberofposters = 20; // You can change this to however many you want

$request = db_query("
  SELECT ID_MEMBER, memberName, posts
  FROM {$db_prefix}members
  ORDER BY posts DESC
  LIMIT $numberofposters", __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($request))
  echo '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['memberName'] . '</a>' , ' (', $row['posts'] , ')<br />';
mysql_free_result($request);


It's only a little more code, but it makes it easier to alter if you decide you want to later on.

Seems to work for me, thank you!

SMF 2.0 RC3
TP 1.0 beta 5-1
Wordpress 3.0

knat

Frases like "This weeks top posters" and "new members this month" are actually wrong

It is more like "Last 7 days top posters" and "New members in the last 30 days"

Am i right ?

RoarinRow

Quote from: knat on February 28, 2007, 05:54:40 PM
Frases like "This weeks top posters" and "new members this month" are actually wrong

It is more like "Last 7 days top posters" and "New members in the last 30 days"

Am i right ?

Not sure, but I configured mine just to show the last two members, the top 10 posters and active members this week.

SMF 2.0 RC3
TP 1.0 beta 5-1
Wordpress 3.0

JPDeni

You mean with this:


$today = strtotime("24 hours ago");
date('j') == 1 ? $thismonth = $today : $thismonth = strtotime(date('F') . ' 1');
date('l') == 'Sunday' ? $thisweek = $today : $thisweek = strtotime('last Sunday');
date('M') == 'January' ? $thisyear = $thismonth : $thisyear = strtotime('January 1');


No. $thismonth is defined as the first day of the current month. $thisweek is defined as the most recent Sunday. $thisyear is defined as the first day of January. The "last day" one is within the past 24 hours, though, and not since midnight on the current day.

It really would be easier to have this discussion in the orginal topic where that code was posted, though.

This website is proudly hosted on Crocweb Cloud Website Hosting.