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,965
  • Latest: boruko
Stats
  • Total Posts: 195,982
  • Total Topics: 21,320
  • Online today: 431
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 95
  • Total: 95

Adding Total Views To Stats

Started by qtwre, March 24, 2008, 06:10:03 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

qtwre

Hey Guys,  I wanna add Total Views to the statsblock how do I do it?

Addtional: Page Views Today:

Stats
Total Views: xxxxxx
Page Views Today: xxx
Total Posts: 10269
Total Topics: 685
Online Today: 57
Online Ever: 183

p.s It's really hard to find this topic especially when I type stats in the searchbox.

And what is the meaning of $txt[95], $txt[64], etc?  where do I call the numbers?  I've looked around the .php files but don't really understand them.

IchBin

The $txt variables are the language strings in SMF. They are stored in the language files. I don't recall seeing SMF have anything for Total View or Page Views. Where are you seeing this information?

Ianedres

#2
Ich, I think he is referring to the number listed in the 'General Statistics' in the 'Stats' page...

I've been wondering this for a while and once tried to quickly get the number listed.

This works, but isn't pretty:
global $txt, $scripturl, $db_prefix, $modSettings, $user_info, $context;

$result = db_query("
SELECT
SUM(hits) AS hits
FROM {$db_prefix}log_activity", __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
mysql_free_result($result);

$context['num_hits'] = $row['hits'];

echo $context['num_hits'];


Place in a php block...   code is derived from stats.php but I removed some of the other calculations it performed...

qtwre

Quote from: IchBinâ,,¢ on March 24, 2008, 02:04:33 PM
The $txt variables are the language strings in SMF. They are stored in the language files.

Thanks!

Quote from: IchBinâ,,¢ on March 24, 2008, 02:04:33 PM
I don't recall seeing SMF have anything for Total View or Page Views. Where are you seeing this information?

I wanted to add the information to the block.  I can find the information at index?action=stats

Quote from: Ianedres on March 24, 2008, 04:37:39 PM
Ich, I think he is referring to the number listed in the 'General Statistics' in the 'Stats' page...

I've been wondering this for a while and once tried to quickly get the number listed.

This works, but isn't pretty:
global $txt, $scripturl, $db_prefix, $modSettings, $user_info, $context;

$result = db_query("
SELECT
SUM(hits) AS hits
FROM {$db_prefix}log_activity", __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
mysql_free_result($result);

$context['num_hits'] = $row['hits'];

echo $context['num_hits'];


Place in a php block...   code is derived from stats.php but I removed some of the other calculations it performed...

Thanks!  I wanted to add into the original stats itself, but I'll give it a try with ur code :)

qtwre

I've tried your code and it works great!  However do anyone know how to implement it into the orginal stats block?

I hope this is the file that I should edit: BoardIndex.template.php

// Show some statistics next to the link tree if SP1 info is off.
echo '
<table width="100%" cellpadding="3" cellspacing="0">
<tr>
<td valign="bottom">', theme_linktree(), '</td>
<td align="right">';
if (!$settings['show_sp1_info'])
echo '
', $txt[19], ': ', $context['common_stats']['total_members'], ' &nbsp;•&nbsp; ', $txt[95], ': ', $context['common_stats']['total_posts'], ' &nbsp;•&nbsp; ', $txt[64], ': ', $context['common_stats']['total_topics'], '
', ($settings['show_latest_member'] ? '<br />' . $txt[201] . ' <b>' . $context['common_stats']['latest_member']['link'] . '</b>' . $txt[581] : '');
echo '
</td>
</tr>
</table>';

qtwre

Anybody has a better knowledge to help pls? :smiley6600:

JPDeni

If you want to alter the statsbox, the file to edit is Themes/default/TPortalBlocks.template.php since that's where the statsbox is defined.

The query for the total number of hits is (as was posted before):

$result = db_query("
          SELECT SUM(hits) AS hits
          FROM {$db_prefix}log_activity", __FILE__, __LINE__);
          $row = mysql_fetch_assoc($result);
          mysql_free_result($result);

          $context['totalhits'] = $row['hits'];


The code for getting the number of hits for today is:

$today = date("Y-m-d");
$result = db_query("
          SELECT hits
          FROM {$db_prefix}log_activity
          WHERE date LIKE '$today'", __FILE__, __LINE__);
          $row = mysql_fetch_assoc($result);
          mysql_free_result($result);

          $context['todayhits'] = $row['hits'];


The stats are in $context['totalhits'] and $context['todayhits'].

This website is proudly hosted on Crocweb Cloud Website Hosting.