I’ve been at it again. This time I took
downloads and changed it to utilize the curl library rather than fopen (which is banned on
for security purposes).
<!-- /*
Original Code by: Smargroth
http://www.spreadfirefox.com/?q=user/view/70329
Code Modifications by: Chiieddy
http://www.spreadfirefox.com/?q=user/view/24336
Also Known As:
Elana Shenton
http://www.clampcampus.com/
Code information housed at http://www.clampcampus.com/wp-plugins/firefox (easier to copy/paste
from there!)
*/ -->
<?php
function GetNumFirefoxDownloads($Url, $Port, $Timeout) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, $Timeout);
curl_setopt($ch, CURLOPT_PORT, $Port);
$XmlData = curl_exec($ch);
curl_close($ch);
if ($XmlData === NULL) return "?";
global $ReturnValue;
global $IsRightTag;
$ReturnValue = "Error - Sorry no other data available.";
$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;
}
$NumDownloads = GetNumFirefoxDownloads("http://feeds.spreadfirefox.com/downloads/firefox", 80, 25);
echo $NumDownloads;
?>