A simple Firefox download counter example

Posted by smargroth on Tue, 04/19/2005 - 20:02Syndicated Download Counter

I put a Firefox-download counter on my web page, at the "Links" section, by the link to Firefox.

It is nothing special, just a simple special idea to make page more attractive. It does update every 10 seconds (please wait some seconds for counter to show up at the beginning).

It is written in PHP and embedded as an inline frame. If anyone is interested in the PHP code for it, I can post it.

http://www.marsnjak.com/sergej/index.php?menu=5

Bye,

Sergej


Submitted by walterkai on Wed, 03/22/2006 - 14:18.


Submitted by SecondV on Sat, 03/04/2006 - 07:36.

<?php

$data = implode('', file('http://feeds.spreadfirefox.com/downloads/firefox.xml'));
preg_match_all("/<description>(.*?)<\/description>/i", $data, $num_downloads, PREG_SET_ORDER);
echo trim(strip_tags($num_downloads[1][1]));

?>

-SecondV

Submitted by nimd4 on Wed, 11/16/2005 - 16:07.

http://bgd.host.sk/firefox.html

Submitted by orebla on Sat, 08/06/2005 - 14:49.

For a simple img counter like this

Take this url: http://www.orebla.it/sig/ffxcount1.png

More info: http://www.orebla.it/forum/viewtopic.php?t=113

Submitted by kimharding on Tue, 08/02/2005 - 17:06.

It looks good, can you post up the code so that I can use it with out linking through you web site?

Kim

Submitted by Paeniteo on Wed, 08/03/2005 - 05:43.

The sourcecode is already posted in a comment below.

Submitted by chiieddy on Wed, 05/18/2005 - 15:06.

Dreamhost, a popular web host, has disabled fopen() on its site, which breaks this script. I've rewritten it with the CURL libraries and it's available here.

Additionally, I've removed the HTML, so it no longer refreshes automatically, but I've made it possible to wrap it directly into other PHP so you can just call the PHP file as an include and then wrap your own text and formatting around it. You can see that on the left side bar of my site (linked above) under the Get Firefox image. I've also removed the localization, since the return is a numeric value as text.

-
chiieddy

Submitted by pchere on Sun, 05/15/2005 - 03:32.
Submitted by osurocks on Thu, 04/21/2005 - 01:03.

Please post source code!

Submitted by smargroth on Sun, 04/24/2005 - 17:14.

Here is the code in PHP. I cannot make this post to preserve spaces and indentation, but anyway...
It is in PHP, and it uses simple XML parser (I would use DOM, but the server with my site doesn't have the module).
Write a file with this content and embed it as a frame into some other page. A number will appear shortly (but you must specify frame size that is large enough)

/********************************/
<?php

$CharSet = "windows-1250";
$CssFile = "/css/style.css";

$Lang = array_key_exists("lang", $_GET) ? $_GET["lang"] : "";
if (($Lang == NULL) || ($Lang == "")) {
if (array_key_exists("HTTP_ACCEPT_LANGUAGE", $_SERVER)) $Lang = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"], 0, 2);
else $Lang = "en";
}
if (($Lang != "en") && ($Lang != "sl")) $Lang = "en";

$StringList = array(
"downloads" => array("en" => "downloads until now", "sl" => "prenosov do sedaj"),
);

function GetNumFirefoxDownloads($Url, $Port, $Timeout) {
global $Lang;

$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);

if ($Lang == "sl") $ReturnValue = str_replace(",", ".", $ReturnValue);

return $ReturnValue;
}

$NumDownloads = GetNumFirefoxDownloads("http://feeds.spreadfirefox.com/downloads/firefox", 80, 25);

echo
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n".
"<html>\n".
"<head>\n".
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=".$CharSet."\" />\n".
"<meta http-equiv=\"refresh\" content=\"10; url=firefoxcounter.php?lang=".$Lang."\" />\n".
"<title></title>\n".
"<link rel=\"stylesheet\" href=\"".$CssFile."\" type=\"text/css\" />\n".
"</head>\n".
"<body style=\"margin:0px;\">\n".
"<font color=\"#A0A0A0\">(".$NumDownloads." ".$StringList["downloads"][$Lang].")</font>\n".
"</body>\n".
"</html>\n";

?>

Submitted by kpow on Tue, 07/25/2006 - 01:07.

 Take the code posted above, and paste it in the title="" att. of your referral button

<a href="?q=affiliates&id=121923&t=85"><img border="0" alt="Get Firefox!" title="

<?php
$data = implode('', file('http://feeds.spreadfirefox.com/downloads/firefox.xml'));
preg_match_all("/<description>(.*?)<\/description>/i", $data, $num_downloads, PREG_SET_ORDER);
echo trim(strip_tags($num_downloads[1][1]));
?> converted."
src="http://sfx-images.mozilla.org/affiliates/Buttons/80x15/firefox_80x15.png"/></a>

--
kpow