Author Topic: [Mod] More Statistics for your visitors  (Read 175373 times)

0 Members and 1 Guest are viewing this topic.

Offline Vraxor

  • Full Member
  • ***
  • Posts: 134
    • View Profile
    • http://tc-revolution.net
[Mod] More Statistics for your visitors
« on: December 29, 2002, 01:02:55 PM »
Hi all,

I did already forgot about this little modification I did. I was in fact the first little mod I did ever in PHP.

The idea is to show more statistics then the number of images and categories (which are shown by default).
This MOD will show:
- Number of Members
- Number of Image Votes
- Number of Image Hits
- Number of Image Comments
- Number of Image Downloads

All these are shown on totals, so it shows the total number of image hits over all images. You can see an example of it here: http://haunter.student.utwente.nl/Terrarevolution/galleries/index.php

// Ok, now lets get started

Creating the stats.php file
Make a new file called: stats.php
Save this empty file in the includes folder of 4images
Open stats.php with any code editor you like.

and copy past the following to your stats.php:
Code: [Select]
<?PHP

//-----------------------------------------------------
//--- Show number of Users ----------------------------
//-----------------------------------------------------
   $sql = "SELECT COUNT(*) as users
          FROM ".USERS_TABLE."
          WHERE user_id <> ".GUEST;
  $row = $site_db->query_firstrow($sql);

  $total_users = "".$lang['users']."<B> ".$row['users']."</B>\n";
 
  $site_template->register_vars("total_users", $total_users);
unset($total_users);

//-----------------------------------------------------
//--- Hits --------------------------------------------
//-----------------------------------------------------
$sql = "SELECT SUM(image_hits) AS sum
          FROM ".IMAGES_TABLE;
  $row = $site_db->query_firstrow($sql);

  $sum = (isset($row['sum'])) ? $row['sum'] : 0;
  $total_hits = "".$lang['total_hits']."<B> ".$row['sum']."</B>\n";
 
  $site_template->register_vars("total_hits", $total_hits);
unset($total_hits);

//-----------------------------------------------------
//--- Votes -------------------------------------------
//-----------------------------------------------------
$sql = "SELECT SUM(image_votes) AS sum
          FROM ".IMAGES_TABLE;
  $row = $site_db->query_firstrow($sql);

  $sum = (isset($row['sum'])) ? $row['sum'] : 0;
  $total_votes = "".$lang['total_votes']."<B> ".$row['sum']."</B>\n";
 
  $site_template->register_vars("total_votes", $total_votes);
unset($total_votes);

//-----------------------------------------------------
//--- Downloads ---------------------------------------
//-----------------------------------------------------
$sql = "SELECT SUM(image_downloads) AS sum
          FROM ".IMAGES_TABLE;
  $row = $site_db->query_firstrow($sql);

  $sum = (isset($row['sum'])) ? $row['sum'] : 0;
  $total_downloads = "".$lang['total_downloads']."<B> ".$row['sum']."</B>\n";
 
  $site_template->register_vars("total_downloads", $total_downloads);
unset($total_downloads);

//-----------------------------------------------------
//--- Comments ----------------------------------------
//-----------------------------------------------------
$sql = "SELECT SUM(image_comments) AS sum
          FROM ".IMAGES_TABLE;
  $row = $site_db->query_firstrow($sql);

  $sum = (isset($row['sum'])) ? $row['sum'] : 0;
  $total_comments = "".$lang['total_comments']."<B> ".$row['sum']."</B>\n";
 
  $site_template->register_vars("total_comments", $total_comments);
unset($total_comments);
?>


Now save the stats.php file.

ALWAYS BACKUP: any file you start editing as you might not be able to restore it when the mod doesn't work

Adding the statistics to the language files:

*NOTE* I only edited this in English, but you will have to copy this to any language you use and maybe translate the english.

Open the main.php file from the lang/[your language] folder of 4images.

Go all the way to the bottom of the file.

Find:
Code: [Select]
//-----------------------------------------------------
//--- Admin Links -------------------------------------
//-----------------------------------------------------
$lang['edit'] = "[Edit]";
$lang['delete'] = "[Delete]";


Add Before:
Code: [Select]
//-----------------------------------------------------
//--- Statistics --------------------------------------
//-----------------------------------------------------
$lang['users'] = "Total Members:";
$lang['total_hits'] = "Total Image Hits:";
$lang['total_votes'] = "Total Image Votes:";
$lang['total_downloads'] = "Total Image Downloads:";
$lang['total_comments'] = "Total Image Comments:";


Including the statistics in Index.php:

Open index.php in the root folder of 4images with any code editor you like.

Find:
Code: [Select]
require(ROOT_PATH.'includes/sessions.php');

Add after:
Code: [Select]
include(ROOT_PATH.'includes/stats.php');

Do the same for catergories.php, lightbox.php, top.php
(it might also work in memberlist.php, search.php, register.php etc. but I did not test them yet)

Now edit the template files that correspond with the php files you added the include to.

index.php = home.html
categories.php = categories.html
lightbox.php = lightbox.html
top.php = top.html

you can find the templates inside the templates/default folder of 4images.

In the templates you can now use the following tags:

{total_users} - This will show the total number of members
{total_votes} - This will show the total number of image votes
{total_comments} - This will show the total number of image comments
{total_hits} - This will show the total number of image hits
{total_downloads} - This will show the total number of image downloads

Uploading all the edited files:

Now upload all files you editted to the right folder at your webserver.

This is a list of files you need to upload:
./index.php
./categories.php
./lightbox.php
./top.php
./includes/stats.php
./lang/ (any language you editted) /main.php
./templates/ (any templates you editted) /home.html
./templates/ (any templates you editted) /categories.html
./templates/ (any templates you editted) /lightbox.html
./templates/ (any templates you editted) /top.html

of course if you editted any more files then the once I mentioned above, you will need to upload them too.

I think this is it. Please note that it could be that I made an error somewhere in the directions above. As soon as you notice any error, please let me know and I will correct it as soon as possible.

Enjoy this little mod!!!

Cheers,
Vraxor

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[Mod] More Statistics for your visitors
« Reply #1 on: December 29, 2002, 07:58:12 PM »
Wow! works great, very nice!
just one little misspell I found
it supposed to be
Quote
{total_users}
not
Quote
{total_user}

and another thing, I think some host wont accept " <? " then need full tag " <?php "

P.S. do u have something else cool hided from us?  :D  :wink:
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Vraxor

  • Full Member
  • ***
  • Posts: 134
    • View Profile
    • http://tc-revolution.net
[Mod] More Statistics for your visitors
« Reply #2 on: December 29, 2002, 08:36:37 PM »
ok, fixed.

Good to hear you like it.

Offline X-Fan

  • Full Member
  • ***
  • Posts: 117
    • View Profile
    • http://www.comixfan.com/xfan/
[Mod] More Statistics for your visitors
« Reply #3 on: December 31, 2002, 03:28:09 AM »
Cool mod Vraxor, thanks!

Just a quick note for those using the vBulletin integration mod, in stats.php find:

Code: [Select]

          WHERE user_id <> ".GUEST;


and change to:

Code: [Select]

          WHERE userid <> ".GUEST;


For it to work with vBulletin's users table rather than 4images.
Eric J. Moreels
ComiX-Fan Editor-in-Chief
e-mail: webmaster@comixfan.cjb.net
Web: http://www.comixfan.com/xfan
AIM: XFan2k

Offline deviator

  • Newbie
  • *
  • Posts: 28
    • View Profile
[Mod] More Statistics for your visitors
« Reply #4 on: January 04, 2003, 03:27:53 PM »
This is real cool, and it works, no errors!

test here:

[link removed]

Greets.
« Last Edit: May 31, 2005, 12:54:23 AM by V@no »

Offline intuitiv

  • Pre-Newbie
  • Posts: 9
    • View Profile
    • http://www.intuitivmedia.net/
Parse error in stats.php -> need help !
« Reply #5 on: January 04, 2003, 05:58:04 PM »
Hallo !

Habe alle hier beschriebenen Schritte durchgeführt und erhalte nun folgende Fehlermeldung in home.html:

-------------------
Parse error: parse error in
/home/intuitiv/public_html/vision/includes/stats.php on line 5
-------------------

kann da jemand helfen ?
Die Site ist:

http://www.intuitivmedia.net/vision/index.php

thank you !

Offline Vraxor

  • Full Member
  • ***
  • Posts: 134
    • View Profile
    • http://tc-revolution.net
[Mod] More Statistics for your visitors
« Reply #6 on: January 04, 2003, 09:54:53 PM »
Hi intuitiv,

did you fix the error already as I do not see one?

Cheers,
Vraxor

Offline intuitiv

  • Pre-Newbie
  • Posts: 9
    • View Profile
    • http://www.intuitivmedia.net/
parse error fixed
« Reply #7 on: January 04, 2003, 10:29:50 PM »
Thank you, it was a problem related to my editor BBEdit 6.5. Everything is working fine.

Offline wrestlingwiredotnet

  • Newbie
  • *
  • Posts: 22
    • View Profile
    • http://www.wrestlingwire.net
thanks!
« Reply #8 on: January 11, 2003, 02:51:23 PM »
Love the stats mod, great mod, thanks!!!!
visit WWW.WRESTLINGWIRE.NET if your a wrestling fan!!!

Offline jdk

  • Pre-Newbie
  • Posts: 6
    • View Profile
[Mod] More Statistics for your visitors
« Reply #9 on: January 11, 2003, 07:44:55 PM »
i need help please here is link http://www.jtimberlake.net/gallery/index.php you can see  whats problem :/

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [MOD] More Statistics for your visitors
« Reply #10 on: January 11, 2003, 08:26:22 PM »
Quote from: Vraxor

Creating the stats.php file
Make a new file called: stats.php
Save this empty file in the includes folder of 4images
Open stats.php with any code editor you like.

and copy past the following to your stats.php:

did u do exactly this part?
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline jdk

  • Pre-Newbie
  • Posts: 6
    • View Profile
[Mod] More Statistics for your visitors
« Reply #11 on: January 11, 2003, 08:35:52 PM »
thank you soo much i forget to put stats.php in includes folder  again thank you  :oops:

Offline wrestlingwiredotnet

  • Newbie
  • *
  • Posts: 22
    • View Profile
    • http://www.wrestlingwire.net
same thing happened to me!
« Reply #12 on: January 11, 2003, 11:57:43 PM »
haha! same thing happened to me jdk, lol
visit WWW.WRESTLINGWIRE.NET if your a wrestling fan!!!

Offline criola

  • Pre-Newbie
  • Posts: 4
    • View Profile
Add new text section
« Reply #13 on: January 12, 2003, 01:12:36 PM »
Quote from: Vraxor


http://haunter.student.utwente.nl/Terrarevolution/galleries/index.php

I saw this image gallery! can u tell me how ca I add the section "Gallery News /Webmaster Comment" ?

thanksssssssssss

Offline Chris

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.487
  • Did u ever stop to think and then forget to start?
    • View Profile
[Mod] More Statistics for your visitors
« Reply #14 on: January 13, 2003, 04:39:57 AM »
Just edit the home.html template