Darkbyte Library

Nonstandard Web Browser

It appears that your browser does not comply with the W3C web standards which define how web pages are encoded, transmitted, and rendered. This site would look much better in a standards-compliant web browser, but its content is accessible to any browser or Internet device.

Firefox and Thunderbird download display. :: Show the world how much Firefox and Thunderbird count.

Download

License : GPL

Description :

A very simple PHP script to show how many times Firefox has been downloaded since v1.0 was launched on Nov 9th 2004.

Update : 20th June 2005
Updated the code so if the feed is unavailable it won't fill the error_log with messages.

Update : 3rd August 2005
Updated the code so you can display the Firefox or Thunderbird current download counts.

Source Code :


<?php
 
/******************************************************************************
 * mozilla.php
 * -----------
 * Author: Alan Doyle (alan.doyle@darkbyte.com)
 * Copyright: (c) 2005 Darkbyte Software
 * Release Version: 1.1
 * Date Started: 2005/05/09
 *
 * Display the number of Firefox downloads to date.
 *
 * 1.0 ... firefox_counter() ... Quick and Dirty Method.
 * 1.1 ... firefox_count()   ... XML Parsing Method.
 *
 ******************************************************************************
 *
 *   mozilla.php is free software; you can redistribute it and/or modify it
 *   under the terms of the GNU General Public License as published by the Free
 *   Software Foundation; either version 2 of the License, or (at your option)
 *   any later version.
 *
 *   mozilla.php is distributed in the hope that it will be useful, but WITHOUT
 *   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 *   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 *   more details.
 *
 *   You should have received a copy of the GNU General Public License along
 *   with mozilla.php; if not, write to the Free Software Foundation, Inc.,
 *   59 Temple Place, Suite 330, Boston, MA  02111-1307,  USA
 *
 *****************************************************************************/
 
define("FIREFOX_FEED",
			"http://www.spreadfirefox.com/download_counter.php?ff=1");
define("THUNDERBIRD_FEED",
			"http://www.spreadfirefox.com/download_counter.php?tb=1");
 
function GetNumDownloads($Url)
{
	$XmlData = file_get_contents($Url);
	if ($XmlData === NULL)
		return "?";
 
	global $ReturnValue;
	global $IsRightTag;
	$ReturnValue = "?";
	$IsRightTag = false;
 
	function XmlStartElement($Parser, $Name, $Attrs)
	{
		global $IsRightTag;
		if ($Name == "DESCRIPTION")
			$IsRightTag = true;
	}
 
	function XmlEndElement($Parser, $Name)
	{
		global $IsRightTag;
		if ($Name == "DESCRIPTION")
			$IsRightTag = false;
	}
 
	function XmlTextData($Parser, $Data)
	{
		global $ReturnValue;
		global $IsRightTag;
		if ($IsRightTag)
			$ReturnValue = $Data;
	}
 
	$XmlParser = xml_parser_create();
	xml_set_element_handler($XmlParser, "XmlStartElement", "XmlEndElement");
	xml_set_character_data_handler($XmlParser, "XmlTextData");
	xml_parse($XmlParser, $XmlData, true);
	xml_parser_free($XmlParser);
 
	return $ReturnValue;
}
 
/*
 * Get current download count of Mozilla Firefox.
 */
function firefox_count()
{
	echo GetNumDownloads(FIREFOX_FEED);
}
 
/*
 * Get current download count of Mozilla Thunderbird.
 */
function thunderbird_count()
{
	echo GetNumDownloads(THUNDERBIRD_FEED);
}
 
/*
 * Old Method ... Quick and dirty method
 */
function firefox_counter()
{
	$fp = @fopen('http://www.spreadfirefox.com/download_counter.php?ff=1', 'r');
	if( $fp == FALSE )
	{
		echo "!!! FIREFOX RSS FEED OFFLINE !!!";
		return;
	}
 
	while (!feof($fp))
		$f_contents .= fread($fp, 8192);
	fclose($fp);
 
	preg_match('/.*<description>(.*)<\/description>.*/is', $f_contents, $downloads);
	echo "$downloads[1]\n";
}
 
?>
Copyright © 2000-2008 Darkbyte Software, All Rights Reserved. 
Please direct your questions or comments to

CCBot/1.0 (+http://www.commoncrawl.org/bot.html) [38.103.63.57 ( )]