Page 1 of 1

Dynamic PHPNuke Stat Signature Rate Topic: ***** 1 Votes

#1 Mikhail  Icon User is offline

  • Bastard Operator From Hell
  • member icon

Reputation: 58
  • View blog
  • Posts: 1,378
  • Joined: 26-October 07

Post icon  Posted 20 January 2008 - 01:52 PM

Today I am going to show you how to create Dynamic Signature which displays your PHPNuke stats and other information, it's simple to do when you understand queries, But in this tutorial I will show you how to create more common queries.

What you need:
  • Notepad or any text editor, it can be commercial software like Dreamweaver
  • Intermediate knowledge of PHP
  • Some Experience in MySQL


1. Lets start by creating a new php file. The first thing you need to do is to include PHPNuke main functions and variables in the new php file. Mainfile.php already has our database connection and variables, so your first part of the code should look like the following:
<?php
include ("mainfile.php"); //includes mainfile.php with all our functions and main variables
global $prefix, $user_prefix, $db; //defines your required variables


2. Now we run a few queries, these are the stats that you want extracted from your PHPNuke 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 MySql then you should know what these queries do:
<?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

?> 


3. 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 function does.
<?
$image = "signature.png";
$im = imagecreatefrompng($image);
$wc = ImageColorAllocate ($im, 255, 255, 255);
$red = ImageColorAllocate ($im, 255, 0, 0);
ImageString($im, 3, 48, 2, "Statistics for $sitename", $wc);
ImageString($im, 2, 48, 15, "$pageview ", $wc);
ImageString($im, 2, 48, 25, "$who_online", $red);
ImageString($im, 2, 48, 35, "Total User: $userCount", $wc);
header("Content-Type: image/png");
Imagepng($im,'',100);
ImageDestroy ($im);
?>



4. $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
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 ($im, 255, 255, 255);
$red = ImageColorAllocate ($im, 255, 0, 0);
ImageString($im, 3, 48, 2, "Statistics for $sitename", $wc);
ImageString($im, 2, 48, 15, "$pageview ", $wc);
ImageString($im, 2, 48, 25, "$who_online", $red);
ImageString($im, 2, 48, 35, "Total User: $userCount", $wc);
header("Content-Type: image/png");
Imagepng($im,'',100);
ImageDestroy ($im);
?>


5. Save your php file and upload to your PHPNuke 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.examplesi...e/signature.php .To use this signature in a forum you would add the following to your signature:
[url=http://www.examplesite.com][img]http://www.yoursite.com/nuke/signature.php[/img][/url]


Anyone who reads this tutorial, please try to comment. I've spent load of time to create this tutorial, of Course except me I'd like to give credit to my friend Andreas Baban, who helped me to retrieve stats from PHPNuke database, and Also taught me how to use PHP a few years back, sadly he is not member of </DIC>.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1