$suoptions['latest_threads'] = true; // تشغيل/تعطيل اخر المواضيع 
$suoptions['latest_posts'] = true; // تشغيل/تعطيل أخر المشاركات 
$suoptions['newest_members'] = true; // تشغيل/تعطيل اجدد الأعضاء 
$suoptions['online_today'] = true; // تشغيل/تعطيل المتواجدين اليوم 
$limits['top_posters'] = 5; // اختيار عدد أفضل المشاركين للظهور بالصفحة 
$limits['latest_threads'] = 5; // ختيار عدد اخر المواضيع للظهور بالصفحة 
$limits['latest_posts'] = 5; // ختيار عدد أخر المشاركات للظهور بالصفحة 
$limits['newest_members'] = 5; // ختيار عدد أجدد الأعضاء للظهور بالصفحة 
$exclusions['userperms'] = true; // Use user permissions when gathering threads/posts? 
$exclusions['posts'] = ''; // اختار رقم المنتدى لعدم ادخاله في الأحصائيات للمشاركات [overrides userperms] (ex: 1,2,3,4) 
$exclusions['threads'] = ''; // اختار رقم المنتدى لعدم ادخاله في الأحصائيات في المواضيع [overrides userperms] (ex: 1,2,3,4) 
$exclusions['posts_only'] = ''; // اختار رقم المنتدى لجعله في الأحصائيات فقط [overrides userperms and posts] (ex: 4,9,10) 
$exclusions['threads_only'] = ''; // اختار رقم المنتدى لجعله في الأحصائيات فقط [overrides userperms and threads] (ex: 19,51) 
//------------------------------------------------------------------------- 
// Init 
//------------------------------------------------------------------------- 
$su = array('top_posters' => '', 
'latest_posts' => '', 
'latest_threads' => '', 
'newest_members' => '', 
'online_today' => ''); 
$sql['post_fid'] = ''; 
$sql['post'] = ''; 
$sql['thread_fid'] = ''; 
$sql['thread'] = ''; 
$fids = ''; 
// Handle fids if we are to do latest_posts or latest_threads and userperms is true 
if(($suoptions['latest_posts'] || $suoptions['latest_threads']) && $exclusions['userperms']) 
{ 
$forumids = array(); 
foreach (
array_keys($forumcache) AS $forumid) 
{ 
$fp = &$bbuserinfo['forumpermissions']["$forumid"]; 
if (
$fp & CANVIEW AND $fp & CANVIEWOTHERS) 
{ 
$forumids[] = $forumid; 
} 
} 
$fids = implode(',', $forumids); 
unset(
$forumids, $fp); 
} 
// Handle post exclusions if we are to do latest_posts 
if($suoptions['latest_posts']) 
{ 
if(
$exclusions['posts_only'] != '') 
{ 
if(
strpos($exclusions['posts_only'], ',') === false) 
$sql['post'] = "AND thread.forumid = {$exclusions['posts_only']}"; 
else 
$sql['post'] = "AND thread.forumid IN({$exclusions['posts_only']}"; 
} 
elseif(
$exclusions['posts'] != '') 
{ 
if(
strpos($exclusions['posts'], ',') === false) 
$sql['post'] = "AND thread.forumid <> {$exclusions['posts']}"; 
else 
$sql['post'] = "AND thread.forumid NOT IN({$exclusions['posts']})"; 
} 
elseif(
$exclusions['useperms']) 
$sql['post_fid'] = "AND thread.forumid IN($fids)"; 
} 
// Handle thread exclusions if we are to do latest_threads 
if($suoptions['latest_threads']) 
{ 
if(
$exclusions['threads_only'] != '') 
{ 
if(
strpos($exclusions['threads_only'], ',') === false) 
$sql['thread'] = "AND thread.forumid = {$exclusions['threads_only']}"; 
else 
$sql['thread'] = "AND thread.forumid IN({$exclusions['threads_only']})"; 
} 
elseif(
$exclusions['threads'] != '') 
{ 
if(
strpos($exclusions['threads'], ',') === false) 
$sql['thread'] = "AND thread.forumid <> {$exclusions['threads']}"; 
else 
$sql['thread'] = "AND thread.forumid NOT IN({$exclusions['threads']})"; 
} 
elseif(
$exclusions['useperms']) 
$sql['thread_fid'] = "AND thread.forumid IN($fids)"; 
} 
//------------------------------------------------------------------------- 
// Top Posters 
//------------------------------------------------------------------------- 
if($suoptions['top_posters']) 
{ 
$q = $DB_site->query("SELECT user.*, usergroup.opentag, usergroup.closetag FROM ".TABLE_PREFIX."user AS user, ".TABLE_PREFIX."usergroup AS usergroup WHERE usergroup.usergroupid = user.usergroupid ORDER BY posts DESC LIMIT {$limits['top_posters']}"); 
$num = 0; 
while(
$user = $DB_site->fetch_array($q)) 
{ 
$num++; 
$user['place'] = $num; 
eval(
'$su[\'top_posters\'] .= "' . fetch_template('su-top_posters') . '";'); 
} 
$DB_site->free_result($q); 
unset(
$q, $user); 
} 
//------------------------------------------------------------------------- 
// Latest Posts 
//------------------------------------------------------------------------- 
if($suoptions['latest_posts']) 
{ 
$q = $DB_site->query("SELECT 
post.postid, post.title AS post_title, post.dateline AS post_dateline, 
thread.threadid, thread.title AS thread_title, thread.firstpostid, thread.replycount, thread.views, thread.votenum, thread.votetotal, thread.dateline AS thread_dateline, thread.lastpost, 
forum.forumid, forum.title AS forum_title, 
user.userid, user.username, 
tuser.userid AS tuserid, tuser.username AS tusername 
FROM 
"
.TABLE_PREFIX."post AS post, 
"
.TABLE_PREFIX."thread AS thread, 
"
.TABLE_PREFIX."forum AS forum, 
"
.TABLE_PREFIX."user AS user, 
"
.TABLE_PREFIX."user AS tuser 
LEFT JOIN " 
. TABLE_PREFIX . "deletionlog AS dlog_t ON (dlog_t.primaryid = thread.threadid AND dlog_t.type = 'thread') 
LEFT JOIN " 
. TABLE_PREFIX . "deletionlog AS dlog_p ON (dlog_p.primaryid = post.postid AND dlog_p.type = 'post') 
WHERE 
thread.threadid = post.threadid 
AND post.postid != thread.firstpostid 
AND forum.forumid = thread.forumid 
{$sql['post_fid']} 
{$sql['post']} 
AND thread.visible = 1 
AND dlog_t.primaryid IS NULL 
AND dlog_p.primaryid IS NULL 
AND post.visible = 1 
AND thread.open <> 10 
AND user.userid = post.userid 
AND tuser.userid = thread.postuserid 
ORDER BY post.postid DESC LIMIT {$limits['latest_posts']}"
); 
while(
$thread = $DB_site->fetch_array($q)) 
{ 
if(
$thread['post_title'] == '') 
$thread['post_title'] = 'Untitled'; 
$thread['lastpost'] = vbdate($vboptions['dateformat'], $thread['lastpost']); 
$thread['thread_date'] = vbdate($vboptions['dateformat'], $thread['thread_dateline']); 
$thread['post_date'] = vbdate($vboptions['dateformat'], $thread['post_dateline']); 
eval(
'$su[\'latest_posts\'] .= "' . fetch_template('su-latest_posts') . '";'); 
} 
$DB_site->free_result($q); 
unset(
$q, $thread); 
} 
//------------------------------------------------------------------------- 
// Latest Threads 
//------------------------------------------------------------------------- 
if($suoptions['latest_threads']) 
{ 
$q = $DB_site->query("SELECT 
thread.threadid, thread.title AS thread_title, thread.replycount, thread.views, thread.votenum, thread.votetotal, thread.lastpost, thread.dateline, thread.lastposter, 
forum.forumid, forum.title AS forum_title, 
user.userid, user.username 
FROM 
"
.TABLE_PREFIX."thread AS thread, 
"
.TABLE_PREFIX."forum AS forum, 
"
.TABLE_PREFIX."user AS user 
LEFT JOIN "
.TABLE_PREFIX."deletionlog AS deletionlog ON (deletionlog.primaryid = thread.threadid AND deletionlog.type = 'thread') 
WHERE 
forum.forumid = thread.forumid 
AND user.userid = thread.postuserid 
{$sql['thread_fid']} 
{$sql['thread']} 
AND thread.visible = 1 
AND open <> 10 
AND deletionlog.primaryid IS NULL 
ORDER BY thread.dateline DESC LIMIT {$limits['latest_threads']}"
); 
while(
$thread = $DB_site->fetch_array($q)) 
{ 
$thread['lastpost_date'] = vbdate($vboptions['dateformat'], $thread['lastpost']); 
$thread['thread_date'] = vbdate($vboptions['dateformat'], $thread['dateline']); 
eval(
'$su[\'latest_threads\'] .= "' . fetch_template('su-latest_threads') . '";'); 
} 
$DB_site->free_result($q); 
unset(
$q, $thread); 
} 
//------------------------------------------------------------------------- 
// Newest Members 
//------------------------------------------------------------------------- 
if($suoptions['newest_members']) 
{ 
$q = $DB_site->query("SELECT 
userid, username, usertitle, joindate, lastvisit, lastactivity, lastpost, posts, birthday 
FROM "
.TABLE_PREFIX."user 
ORDER BY userid DESC LIMIT {$limits['newest_members']}"
); 
while(
$user = $DB_site->fetch_array($q)) 
{ 
$user['join_date'] = vbdate($vboptions['dateformat'], $user['joindate']); 
eval(
'$su[\'newest_members\'] .= "' . fetch_template('su-newest_members') . '";'); 
} 
$DB_site->free_result($q); 
unset(
$q, $user); 
} 
//------------------------------------------------------------------------- 
// Users Online Today 
//------------------------------------------------------------------------- 
if($suoptions['online_today']) 
{ 
$time = mktime(0, 0, 0); 
$q = $DB_site->query("SELECT 
user.userid, user.username, (user.options & $_USEROPTIONS[invisible]) AS invisible, 
usergroup.opentag, usergroup.closetag 
FROM 
"
.TABLE_PREFIX."user AS user, 
"
.TABLE_PREFIX."usergroup AS usergroup 
WHERE 
user.lastactivity >= {$time} AND usergroup.usergroupid = user.usergroupid"
); 
$count = 0; 
$invis = 0; 
$changed = false; 
if(
$vboptions['addtemplatename']) 
{ 
$changed = true; 
$vboptions['addtemplatename'] = false; 
} 
while(
$user = $DB_site->fetch_array($q)) 
{ 
$count++; 
$user['lastactivity'] = TIMENOW; 
$status = fetch_online_status($user); 
if(
$status) 
{ 
if(
$status == 2) 
$invis++; 
eval(
'$su[\'online_today\'] .= "' . fetch_template('su-online_today') . ', ";'); 
} 
} 
if(
$changed) 
$vboptions['addtemplatename'] = true; 
$su['online_today'] = substr($su['online_today'], 0, (strlen($su['online_today'])-2)); 
$su['online_today_total'] = $count; 
$su['online_today_invisible'] = $invis; 
$DB_site->free_result($q); 
unset(
$time, $q, $user, $count, $invis, $status, $changed); 
} 
//------------------------------------------------------------------------- 
// Finish up 
//------------------------------------------------------------------------- 
unset($limits, $exclusions, $sql);