The D’ni counter
November 28th, 2005
Back in 2004 Kah’teh of MC requested information about hit counters, and mentioned it would be interesting to have one using D’ni numerals - A Base25 system.
This PHP code is waht I came up with in responce. It’s a little crowded.
if (defined(images) == 0) $images="counter/";
if (defined(imagesext) == 0) $imagesext="_b.png";
// _w for white, _b for black, & png file extension
if (defined(counterfile) == 0) $counterfile="counterfile.count";
// File that will be used to count
/* Do Not edit below this point unless you know what you are doing */
$file = '$images$counterfile';
if (!file_exists($file)) { // create count file if it doesn't exist
$fp = fopen($file,"w");
fputs ($fp,"0" );
}
else {
$fp = fopen($file,"r+"); // open file read-only
};
$numcount= fread($fp,filesize($file));
fclose($fp);
$numcount++;
$fp = fopen($file,"w");
fputs ($fp,$numcount);
$dnicount = base_convert($numcount, 10, 25);
echo "<img src='" . $images . "left$imagesext' alt='' />" ;
for ($x=0; $x < strlen($dnicount); $x++){
echo "<img src='" . $images . substr($dnicount,$x,1) . $imagesext;
echo "' title='You are linker $numcount' ";
echo " alt='You are linker $numcount' />";
}
echo "<img src='" . $images . "right$imagesext' alt='' <br>" ;
//print_r(parse_url($_SERVER['QUERY_STRING']));
… and here is the code updated for GR[ae]YSCALE. It depends on the statistics collected by the WP-Advanced-Stats-Recorder.
global $Stats;
$Stat = $Stats->getStats();
$images = "/wp-content/images/counter/";
$imagesext="_b.png";
$dnicount = base_convert($Stat->vistors, 10, 25);
echo "<img src='" . $images . "left$imagesext' alt=\"\" />" ;
for ($x=0; $x < strlen($dnicount); $x++){
echo "<img src=\"" . $images . substr($dnicount,$x,1) . $imagesext . "\" ";
echo "title=\"This site is " . $Stat-/>vistors . " visitors old\" ";
echo "alt=\"This site is " . $Stat->vistors . " visitors old\" />";
}
echo "<img src='" . $images . "right$imagesext' alt=\"\" />" ;
One issue with this method is that there are a possible 27 images to load, with a minimum of three. Converting the images into CSS Sprites could help. I hope to get to this eventually.
-Sud.
Posted in PHP |