TinyPortal

Development => Resources => Topic started by: janilxx on December 14, 2007, 12:23:10 AM

Title: Updating Most Online
Post by: janilxx on December 14, 2007, 12:23:10 AM
I have a site
http://www.beyonwizsoftware.net
which should not look much like a forum (forum was easiest to implement and it helps me to get users to update softwares in my site rather than I would do all updates by myself (as I do in another site: www.tapworld.net (luckily there is two other updaters as well)).

This site has TinyPortal in use and it shows posts from one board (Software) in front page. From there users usually go to Boards using "Software list" icon from the top of site or using links from "Links" box (right side of the front page).

Users of this forum are usually never supposed to open forum or board index ( http://www.beyonwizsoftware.net/index.php?action=forum ).

TinyPortal's Stats box shows most online stats. Here is code from TPortalBlocks.template.php:
Code: [Select]
            echo '
                  <hr /><img src="'.$settings['images_url'].'/icons/info.gif" style="margin: 0;" align="bottom" alt="" />
                 <a href="'.$scripturl.'?action=stats"><b>'.$txt['tp-stats'].'</b></a>
                 <br />'.$bullet.$txt[489].': '.$modSettings['totalMessages']. '
  <br />'.$bullet. $txt[490].': '.$modSettings['totalTopics']. '
  <br />'.$bullet.$txt['tp-mostonline-today'].': '.$modSettings['mostOnlineToday'].'
  <br />'.$bullet.$txt['tp-mostonline'].': '.$modSettings['mostOnline'].'<br />
  ('.timeformat($modSettings['mostDate']).')
  ';

I tried to find out when and where most online is updated and it seems to happen in BoardIndex.php:
Code: [Select]
// Track most online statistics?
if (!empty($modSettings['trackStats']))
{
// Determine the most users online - both all time and per day.
$total_users = $context['num_guests'] + $context['num_users_online'];

// More members on now than ever were?  Update it!
if (!isset($modSettings['mostOnline']) || $total_users >= $modSettings['mostOnline'])
updateSettings(array('mostOnline' => $total_users, 'mostDate' => time()));

$date = strftime('%Y-%m-%d', forum_time(false));

// One or more stats are not up-to-date?
if (!isset($modSettings['mostOnlineUpdated']) || $modSettings['mostOnlineUpdated'] != $date)
{
$request = db_query("
SELECT mostOn
FROM {$db_prefix}log_activity
WHERE date = '$date'
LIMIT 1", __FILE__, __LINE__);

// The log_activity hasn't got an entry for today?
if (mysql_num_rows($request) == 0)
{
db_query("
INSERT IGNORE INTO {$db_prefix}log_activity
(date, mostOn)
VALUES ('$date', $total_users)", __FILE__, __LINE__);
}
// There's an entry in log_activity on today...
else
{
list ($modSettings['mostOnlineToday']) = mysql_fetch_row($request);

if ($total_users > $modSettings['mostOnlineToday'])
trackStats(array('mostOn' => $total_users));

$total_users = max($total_users, $modSettings['mostOnlineToday']);
}
mysql_free_result($request);

updateSettings(array('mostOnlineUpdated' => $date, 'mostOnlineToday' => $total_users));
}
// Highest number of users online today?
elseif ($total_users > $modSettings['mostOnlineToday'])
{
trackStats(array('mostOn' => $total_users));
updateSettings(array('mostOnlineUpdated' => $date, 'mostOnlineToday' => $total_users));
}
}

It also seems to be so that this code is run only when http://www.beyonwizsoftware.net/index.php?action=forum is opened. This code is not run when TinyPortal fronpage is shown. And in my site this board index is rarely used, it means most online stats won't update often.

Could anyone help me to add code that updates most online stats from BoardIndex.php to TinyPortal (TPortal.php I suppose) or to somewhere else where it would be run regulary.

Thanks