collapse collapse

* User Info

 
 
Welcome, Guest. Please login or register.
Did you miss your activation email?

* Who's Online

  • Dot Guests: 188
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

* Shoutbox

Refresh History
  • Shoutbox is not for support!
  • {OCS}MasterSeal: Yup, Still adore SP
    April 21, 2019, 07:08:06 PM
  • {OCS}MasterSeal: STILL love SP :)
    November 24, 2018, 05:05:50 AM
  • ♦ Ninja ZX-10RR ♦: <3 aegersz
    September 13, 2018, 03:36:09 PM
  • aegersz: I STILL <3 LOVE SimplePortal
    September 13, 2018, 07:11:39 AM
  • aegersz: o LOVE you guys - Simple Portal rocks !
    May 09, 2018, 05:18:59 AM
  • Chen Zhen: our apologies for the site being down.. please read server issues topic
    March 22, 2018, 05:32:38 AM
  • {OCS}MasterSeal: LOL PLEASE forget I just posted that. I found the answer in my own dang post back in 2015. lol sorry!
    July 04, 2017, 10:47:55 PM
  • {OCS}MasterSeal: I know this SB isnt' for support, but I just have a general question. Who would I contact to find out where SP stores its block info? Is it DB driven or files? I searched the site but came up with nothing. probably my fault any insight is appreciated.
    July 04, 2017, 10:43:36 PM
  • ♦ Ninja ZX-10RR ♦: Excuse me but what does Simpleportal have to deal with that?
    February 05, 2017, 08:21:14 PM
  • WhiteEagle: of course IMHO that site appears to be dead :(
    February 04, 2017, 01:08:05 PM
  • WhiteEagle: If I can get that, then I'll use it for that site...
    February 04, 2017, 01:07:35 PM
  • WhiteEagle: decided to not use SMF for any projects, unless I can get a copy of the premium version of the fanfiction archive plugin
    February 04, 2017, 01:06:54 PM
  • expertdecisions: cloudflare
    January 28, 2017, 08:01:47 AM
  • aegersz: SM release 2.0.13 !
    January 12, 2017, 06:00:13 AM
  • raffo: Tks Emanuele, even if I didn't understand the fix :D
    November 07, 2016, 02:01:20 AM
  • emanuele: [link]
    November 01, 2016, 12:43:50 PM
  • emanuele: raffo: the English support board is a good place. ;)
    November 01, 2016, 12:43:38 PM
  • raffo: Where can I find the fix for the shoutbox?
    November 01, 2016, 05:06:09 AM
  • {OCS}MasterSeal: To the SP team, I make a point to come here and thank you as much as possible for your work.  so again, THANK YOU!
    October 28, 2016, 10:38:05 AM
  • emanuele: That's indeed funny, the limit is present only in the patch and not the full install.
    October 22, 2016, 06:14:58 PM
Installation errors? Mod incompatibilities? Upgrade problems? Make your way over to the Install and Upgrade Support board for all your solutions!

Author Topic: [Block] Display Frequent Posters for SMF 2.0x using horizontal js pages  (Read 3988 times)

0 Members and 1 Guest are viewing this topic.

Offline Chen Zhen

  • The Underdog
  • Operations Manager
  • *
  • Posts: 1350
  • Gender: Male
  • Kinesis
    • WebDev
  • SMF Version: 2.1
  • EhPortal Version: 1.22
Custom PHP block:
Display Frequent Posters for SMF 2.0x using horizontal javascript pages
Submitted upon request.

Adjustable variables/integers are at the top of the block code.

Code: [Select]
/* Display Frequent Posters for SMF 2.0x by Underdog @http://askusaquestion.net */
/* Format: Horizontal javascript pages */
/* v1.1 */

global $smcFunc, $scripturl, $boardurl;

/* Adjust these */
$number_users = 24;
$lang = ' Posts';
$show_posts = 'Show posts from this user';
$show_profile = 'Show the user profile of ';
$none = 'No users selected';
$show_name = true;
$avatar_width = 50;
$avatar_height = 50;
$row_height = 100; /* <-- adjust depending on amount of text shown under avatar */
$user_name_max = 35; /* <-- max chars for user name display */
$per_row = 4;
$rows = 1;
$prev = 'Prev';
$next = 'Next';

/* Do not edit below this line */

$query = '(users.posts > 0 AND is_activated = 1)';
$datum = array( 'id_member', 'posts', 'real_name', 'avatar', 'filename', 'id_attach');
$x = 0;
$count = 0;
$users = array();
$limit = !empty($number_users) ? (int)$number_users : 20;
$cell_width = 100 / (int)$per_row;

$pages = '<script type="text/javascript"><!--
        var pager = new frequentPager("new", '.(int)$rows.');
        pager.init();
        pager.showPageNav("pager", "l8stPagePosition");
        pager.showPage(1);
    //--></script>';

/* Some js to control the pages */
echo '<script type="text/javascript">
function frequentPager(tableName, itemsPerPage) {
    this.tableName = tableName;
    this.itemsPerPage = itemsPerPage;
    this.currentPage = 1;
    this.pages = 0;
    this.initiated = false;
   
    this.showRecords = function(from, to) {       
        var rows = document.getElementById(tableName).rows;
        // i starts from 1 to skip table header row';
echo "
        for (var i = 1; i < rows.length; i++) {
            if (i < from || i > to) 
                rows[i].style.display = 'none';
            else
                rows[i].style.display = '';
        }";
echo '
    }
   
    this.showPage = function(pageNumberFrequent) {
    if (! this.initiated) {
    alert("not initiated");
    return;
    }';
echo "
        var oldPageAnchor = document.getElementById('pg'+this.currentPage);
        oldPageAnchor.className = 'smalltext pg-normal';
       
        this.currentPage = pageNumberFrequent;
        var newPageAnchor = document.getElementById('pg'+this.currentPage);
        newPageAnchor.className = 'largetext pg-selected';
       
        var from = (pageNumberFrequent - 1) * itemsPerPage + 1;
        var to = from + itemsPerPage - 1;
        this.showRecords(from, to);
    }   
   
    this.prev = function() {
        if (this.currentPage > 1)
            this.showPage(this.currentPage - 1);
    }
   
    this.next = function() {
        if (this.currentPage < this.pages) {
            this.showPage(this.currentPage + 1);
        }
    }                       
   
    this.init = function() {
        var rows = document.getElementById(tableName).rows;
        var records = (rows.length - 1);
        this.pages = Math.ceil(records / itemsPerPage);
        this.initiated = true;
    }";
echo '
    this.showPageNav = function(pagerName, positionId) {
    if (! this.initiated) {
    alert("not initiated");
    return;
    }
    var element = document.getElementById(positionId);';
echo "
    var pagerHtml = '<span onclick=";
echo '"';
echo "' + pagerName + '.prev();";
echo '" class="smalltext pg-normal"> « ', $prev, ' </span> | ';
echo "';
        for (var page = 1; page <= this.pages; page++)
            pagerHtml += '<span id=";
echo '"';
echo "pg' + page + '";
echo '" class="smalltext pg-normal" onclick="';
echo "' + pagerName + '.showPage(' + page + ');";
echo '">';
echo "' + page + '</span> | ';
        pagerHtml += '<span onclick=";
echo '"';
echo "'+pagerName+'.next();";
echo '" class="smalltext pg-normal"> ', $next,' »</span>';
echo "';           
       
        element.innerHTML = pagerHtml;
    }
}
function regenerateFrequent()
{
window.location.reload()
}

function regenerateFrequentPosters()
{
if (document.layers)
{
appearFrequent()
setTimeout(";
echo '"window.onresize=regenerateFrequent",450)
}
}

function changeFrequentText(whichcontent)
{
if (document.all||document.getElementById)
{
cross_el=document.getElementById? document.getElementById("descriptions"):document.all.descriptions
cross_el.innerHTML=';
echo "'<div style=";
echo '"font-family:Arial Narrow Bold;font-size:small;">';
echo "'+whichcontent+'</div>'
}
else if (document.layers)
{
document.d1.document.d2.document.write('<div style=";
echo '"font-family:Arial Narrow Bold;font-size:small;">';
echo "'+whichcontent+'</div>')
document.d1.document.d2.document.close()
}

}

function appearFrequent()
{
document.d1.visibility='show'
}
</script>";
/* end of js controller */

$result = $smcFunc['db_query']('', "SELECT users.id_member, users.posts, users.real_name, users.avatar, users.is_activated, att.id_attach, att.filename FROM {db_prefix}members AS users
LEFT JOIN {db_prefix}attachments AS att ON (att.id_member = users.id_member)
WHERE {$query} ORDER BY users.posts DESC LIMIT {$limit}");
while ($val = $smcFunc['db_fetch_assoc']($result))
{                     
foreach ($datum as $data)
{
if (empty($val[$data]))
$val[$data] = false;

$users[$count][$data] = $val[$data];                                               
}
$count++;
}
$smcFunc['db_free_result']($result);
echo '
<script type="text/javascript">
<!--
window.onload=regenerateFrequentPosters
//-->
</script>';
if ($count == 0)
echo '
<div style="text-align:center">', $none, '</div>';
else
{
echo '
<table id ="new" style="width:100%;">
<tr>
<td>&nbsp;</td>
</tr>';
foreach ($users as $user)
{
if ((empty($user['posts'])) || !$user['posts'])
continue;
if ($x == 0)
echo '
<tr>';

$x++;
 
if (!$user['avatar'] && !$user['filename'])
$user['avatar'] = $boardurl . '/avatars/noavatar.gif';
elseif (!$user['avatar'])
$user['avatar'] = $scripturl . '?action=dlattach;attach='.$user['id_attach'].';type=avatar';
elseif (substr($user['avatar'], 0, 4) != 'http')
$user['avatar'] = $boardurl .'/avatars/' . $user['avatar'];

$name = strlen($user['real_name']) >= (int)$user_name_max ? $name = substr($user['real_name'],0,(int)$user_name_max).'...':$user['real_name'];
echo '
<td style="text-align:center;width:'.(int)$cell_width.'%;">
<div style="height:'.$row_height.'px;overflow:hidden;">
<a href="'.$scripturl.'?action=profile;u='.$user['id_member'].'" title="'.$show_profile,$user['real_name'].'">
<img src="'. $user['avatar'] . '" style="max-height:'.$avatar_height.'px;max-width:'.$avatar_width.'px;" alt="" />
</a>
<br />';
if ($show_name)
echo '
<a href="'.$scripturl.'?action=profile;u='.$user['id_member'].'" title="'.$user['real_name'].'">',$name,'</a>
<br />';

echo '
<a href="'.$scripturl.'?action=profile;area=showposts;u='.$user['id_member'].'" title="'.$show_posts.'">', $user['posts'], $lang, '</a>
</div>
</td>';
if ($x > ((int)$per_row -1))
{
$x=0;
echo '
</tr>';
}
}

echo '
</table>';

if (((int)$per_row * (int)$rows) != (int)$number_users)
echo '
<br />
<div id="l8stPagePosition" style="text-align:center;">&nbsp;</div>
<div style="text-align:center;">', $pages, '</div>';
}

Top, Bottom, Header or Footer display is suggested.
« Last Edit: January 07, 2013, 02:25:27 PM by Underdog »

Offline Kryzen

  • Localizer
  • Language
  • *
  • Posts: 826
  • Gender: Male
  • SMF Version: 2.0.11
  • SP Version: 2.3.6
Nice and thanks :)

Offline nontanun

  • Newbie
  • Posts: 3
  • SMF Version: 2.0
  • SP Version: 2.3.3
Thanks :thumbsup:

Offline pixeleyes

  • Jr. Member
  • **
  • Posts: 72
  • SMF Version: None
  • SP Version: 2.3.3
thanks Underdog

Can you add one more option for Monthly base top posters.


Offline pixeleyes

  • Jr. Member
  • **
  • Posts: 72
  • SMF Version: None
  • SP Version: 2.3.3
Again I need your help!

Like above User block I want Staff block.
« Last Edit: June 21, 2012, 08:13:37 AM by pixeleyes »