The ProgrammersTalk Community
Forum Register Search Today's Posts Mark Forums Read
Register

Go Back   The ProgrammersTalk Community > Web Programming > PHP


Welcome to the The ProgrammersTalk Community forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.
Reply
 
LinkBack (4) Thread Tools    Display Modes   
  4 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 07-08-2007, 03:04 PM
Blood08's Avatar
Blood08 Blood08 is offline
Jr. Programmer
Awards Showcase
Quality Tutorial Quality Tutorial 
Total Awards: 2
Join Date: Jun 2007
Location: Source Code
Posts: 98
iTrader: (0)
Blood08 is on a distinguished road
Icon1 [Tutorial] PHPNuke Stats Image


This tutorial will explain how to create those very cool signatures that show your phpnuke stats and other informations. It is quite simple once you understand how to create queries. But I will show you how to create a few of the more common queries.

Steps
Create a new php file with your tags <?php ?> . The first thing in our file is to include nuke main functions and variables.
Mainfile.php already has our database connection and variables, so your first part of the code should look like the following:


PHP Code:
<?php 
include ("mainfile.php"); //include mainfile.php with all our funtions and main variables
global $prefix$user_prefix$db//define your required variables
Next we run a few queries, these are the stats that you want extracted from your nuke database. You can get these or other queries by searching some of your nuke blocks for the ones you need. The ones I will show you are Total Hits, Who's Online and User Count. These are the queries I used, if you understand a little about MySql then you should know what these queries does.

PHP Code:
<?php

//Nuke Stats
$sql "SELECT count FROM ".$prefix."_counter WHERE type='total' AND var='hits'";
$result $db->sql_query($sql);
$row $db->sql_fetchrow($result);
$pageview "Receved $row[0] since $startdate";
//End Nuke Stats
//Who's online for Nuke
$g_online_num $db->sql_numrows($db->sql_query("SELECT * FROM ".$prefix."_session WHERE guest='1'"));
$m_online_num $db->sql_numrows($db->sql_query("SELECT * FROM ".$prefix."_session WHERE guest='0'"));
$w_online_num $gt_online_num $m_online_num;
$who_online "On Line: $g_online_num Guests & $m_online_num members"
//end Nuke stats
//User Count
$sql "SELECT COUNT(user_id) AS userCount FROM $user_prefix"._users."";
$result $db->sql_query($sql);
$row $db->sql_fetchrow($result);
$userCount $row[userCount];
//End Nuke stats

?>
Now we tell the signature what to display on it and what image to use. First I will show you the code then I will explain what each does.

PHP Code:
<?
$image 
"signature.png"
$im imagecreatefrompng($image);
$wc ImageColorAllocate ($im255255255); 
$red ImageColorAllocate ($im25500);
ImageString($im3482"Statistics for $sitename"$wc); 
ImageString($im24815"$pageview "$wc); 
ImageString($im24825"$who_online"$red); 
ImageString($im24835"Total User: $userCount"$wc);
header("Content-Type: image/png"); 
Imagepng($im,'',100); 
ImageDestroy ($im); 
?>
$image = "signature.png"; This part is used to define the png file that will be used in the signature, make sure it is wide and long enough to hold your stats. It is a good idea not to put too much graphics on it so the text can be shown. A nice gradient background will do.

$im = imagecreatefrompng($image); This is saying that the background should be created using the png file.

$wc = ImageColorAllocate ($im, 255, 255, 255); These are colors for your text, it should be written just like that, the only things than can be changed are $wc and 255, 255, 255. The numbers are RGB colors and the $wc is a variable to define the color. You must use a different one for each color.
ImageString($im, 2, 48, 15, "$pageview ", $wc); This part defines what's placed on the signature. The only things that should be changed are 2, 48, 15, "$pageview ", $wc . The first number ( 2 ) is the size of the text. The second and third numbers are the vertical and horizontal alignment (48, 15, ).
You will have to continually adjust these to get the text at the perfect spot on the image. This ( "$pageview " ) is the variable defined from the database query. The rest of the code is just to finish the imagecreate function and close php. So your entire php file should look like the following.




PHP Code:
<?php 
include ("mainfile.php"); //include mainfile.php with all our funtions and main variables
global $prefix$user_prefix$db//define your required variables
//Nuke Stats
$sql "SELECT count FROM ".$prefix."_counter WHERE type='total' AND var='hits'";
$result $db->sql_query($sql);
$row $db->sql_fetchrow($result);
$pageview "Receved $row[0] since $startdate";
//End Nuke Stats
//Who's online for Nuke
$g_online_num $db->sql_numrows($db->sql_query("SELECT * FROM ".$prefix."_session WHERE guest='1'"));
$m_online_num $db->sql_numrows($db->sql_query("SELECT * FROM ".$prefix."_session WHERE guest='0'"));
$who_online_num $g_online_num $m_online_num;
$who_online "On Line: $g_online_num Guests & $m_online_num members";
//end Nuke stats
//User Count
$sql "SELECT COUNT(user_id) AS userCount FROM $user_prefix"._users."";
$result $db->sql_query($sql);
$row $db->sql_fetchrow($result);
$userCount $row[userCount];
//End Nuke stats
$image "signature.png";
$im imagecreatefrompng($image);
$wc ImageColorAllocate ($im255255255);
$red ImageColorAllocate ($im25500);
ImageString($im3482"Statistics for $sitename"$wc); 
ImageString($im24815"$pageview "$wc); 
ImageString($im24825"$who_online"$red);
ImageString($im24835"Total User: $userCount"$wc); 
header("Content-Type: image/png");
Imagepng($im,'',100); 
ImageDestroy ($im); 
?>
Save your php file and upload to your nuke root directory, this is the same folder as config.php and mainfile.php. Create your png image and place inside that folder too. You can test it by linking to your php file. http://www.mysite.com/nuke/signature.php .To use this signature in a forum you would add the following to your signature.

[u rl=http://www.yoursite.com] [i mg]http://www.yoursite.com/nuke/signature.php[/ img][/ url]

With them together of course.

__________________
Fersk Webmasters' Forum
Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!

Last edited by Blood08 : 07-08-2007 at 03:07 PM.
Reply With Quote
Reply


Thread Tools
Display Modes

   Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.programmerstalk.net/thread862.html
Posted By For Type Date
Nuke-Evolution » Forums » Misc Help » Forum Stats Signature This thread Refback 09-23-2007 12:18 PM
Nuke-Evolution Forums » Post 96747 » Re: Forum Stats Signature This thread Refback 09-23-2007 09:26 AM
Nuke-Evolution Forums » Post 96730 » Forum Stats Signature This thread Refback 09-23-2007 08:49 AM
Nuke-Evolution Forums » Post 96738 » Re: Forum Stats Signature This thread Refback 09-23-2007 07:32 AM


All times are GMT -7. The time now is 11:43 AM. Powered by vBulletin
Copyright © 2000 - 2007, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO © 2007 ProgrammersTalk Sedo - Buy and Sell Domain Names and Websites project info: programmerstalk.net Statistics for project programmerstalk.net etracker® web controlling instead of log file analysis


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50