Enhancing 80 million pages.

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Pensamientos al azar acerca de vBSEO y www.bmwfaq.com
Rate this Entry

Forum Stats Signature Generator

Posted 11-15-2007 at 06:30 AM by Danny Bembibre
I make a stupid script to generate forum stats in a image template with GD. This is based in a old plugin that come from the earling times of vBulletin2

What make this

Based in a template image


The script that is executed a scheduled task from the vB adminCP modify the template and put in it your forum stats.


You can modify this script for you own pourposes

Install Instructions
  1. Upload the script signature.php to forum-root/includes/cron
  2. Create a directory called signature in forum-root/images and make wright right (chmod 777 or chown apache:apache) and upload the image sig.jpg (modify as you want to have your own base image)
  3. Go to vB AdminCP->Scheduled Tasks->Add new Task
    • Task Name: Signature Generator
    • Includes: ./includes/cron/signature.php
    • Time choose what you want, mine is setter to be executed every 3 hours
The first time click in "Run now" and test if a image with name siggenerated.jpg exist (you can link this image in forums to work as signature).

Note: I test this in windows enviroment, i think in linux you need change the variable $Top=22 by $Top=10

The Code

PHP Code:
[left]<?php
/* Author: Danny Bembibre
* A PHP script to generate dynamic signature with your forum stats
* Put the file as a Task in the vBulletin Cron
* Based in old vbulletin hack 
* http://www.vbulletin.org/forum/showthread.php?t=50848
*/

error_reporting(E_ALL & ~E_NOTICE);

if (!
is_object($vbulletin->db)){
exit; 
}

//*************************
//Configure Image Variables
$TotalHeight=60;
$TotalWidth=260;
$LineSpacing=15;
$Top=22;
$Left=153;
//*************************

$TotalPosts $vbulletin->db->query_first("SELECT COUNT(postid) AS posts FROM " TABLE_PREFIX "post"); 
$TotalPosts number_format($TotalPosts['posts']); 

$TotalThreads $vbulletin->db->query_first("SELECT COUNT(threadid) AS threads FROM " TABLE_PREFIX "thread"); 
$TotalThreads number_format($TotalThreads['threads']); 

$TotalUsuarios $vbulletin->db->query_first("SELECT COUNT(userid) AS usuarios FROM " TABLE_PREFIX "user");
$TotalUsuarios number_format($TotalUsuarios['usuarios']); 

$ImgBase ImageCreateTrueColor($TotalWidth,$TotalHeight);

$Text "Members:" $TotalUsuarios "\nThreads:" $TotalThreads "\nPosts:" $TotalPosts "\n";

$BGcolor ImageColorAllocate ($ImgBase255255255); 
$TextColor ImageColorAllocate ($ImgBase000); 
ImageFilledRectangle ($ImgBase00$TotalWidth$TotalHeight$BGcolor);
ImageCopy ($ImgBase, @ImageCreateFromJPEG(DIR "/Images/signature/sig.jpg"), 0000$TotalWidth$TotalHeight);
ImageColorTransparent($ImgBase$BGcolor); 

$SplitedText split("\n"$Text);
$Idx 0;
while(
$Idx Count($SplitedText)){ 
ImageString($ImgBase2$Left, (($Idx $LineSpacing) - $LineSpacing $Top), $SplitedText[$Idx], $TextColor); 
$Idx++; }

@
ImageJPEG($ImgBaseDIR "/Images/signature/siggenerated.jpg"95); //Escribir la imagen al disco 
@ImageDestroy($ImgBase); //Limpiar la memoria

//log_cron_action('Signature Stats Generator', $nextitem);[/left]

?>

Attached Thumbnails
Click image for larger version

Name:	sig.jpg
Views:	1340
Size:	5.4 KB
ID:	24  Click image for larger version

Name:	siggenerated.jpg
Views:	1344
Size:	8.2 KB
ID:	25  Click image for larger version

Name:	sigtemplate.jpg
Views:	14
Size:	1.9 KB
ID:	26  
Attached Files
File Type: zip siggenerated.zip (16.1 KB, 40 views)
Total Comments 8

Comments

Old
BamaStangGuy's Avatar
Isn't a count(*) faster? It should return the same results no?

Either way, thanks for the code
permalink
Posted 11-15-2007 at 07:16 AM by BamaStangGuy BamaStangGuy is offline
Old
Danny Bembibre's Avatar
Is a habit, ever i make a count by the index column, in the backstage the database ever follow the more optimal way.
permalink
Posted 11-15-2007 at 07:21 AM by Danny Bembibre Danny Bembibre is offline
Old
Keith Cohen's Avatar
Actually, I think count(*) is slower since it hits all fields instead of just one. I always use the identity column when counting also.
permalink
Posted 11-15-2007 at 09:06 AM by Keith Cohen Keith Cohen is offline
Old
BamaStangGuy's Avatar
permalink
Posted 11-15-2007 at 07:10 PM by BamaStangGuy BamaStangGuy is offline
Old
Danny Bembibre's Avatar
Yes, i understand now, i totally shocked, im 12 years in the programming world and im involved during some years in RDBMS develop. My conclusion is that MyISAM dont work like any RDBMS, in any db always make a count by id or index column is much faster that make by count(*) independent if you has or not a where clausule in the expains you can see how InnoDB work faster make the count by column and how is much slower make count(*).
http://www.mysqlperformanceblog.com/...innodb-tables/
permalink
Posted 11-16-2007 at 05:24 AM by Danny Bembibre Danny Bembibre is offline
Old
Philipp Herbers's Avatar
Thanks for sharing, Danny!
permalink
Posted 11-16-2007 at 07:28 AM by Philipp Herbers Philipp Herbers is offline
Old
briansol's Avatar
select count(id) works too. no need for *
permalink
Posted 11-16-2007 at 01:41 PM by briansol briansol is offline
Old
Possible bug found:
PHP Code:
"/Images/signature/siggenerated.jpg"
Shouldn't the I in Images needs to be small case?!
permalink
Posted 05-22-2008 at 10:07 AM by Tammy Tammy is offline
 
Total Trackbacks 0

Trackbacks

Recent Blog Entries by Danny Bembibre

All times are GMT -4. The time now is 09:00 PM.


Powered by vBulletin Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 ©2008, Crawlability, Inc.