\n";
foreach ($pages as $page)
{
// Process the current page
parse($page, "?0,0,0,0,1", true);
// Process pages in filtered subcategories
foreach ($categories as $cat)
{
parse($page, "?0,0,0,0,".$cat);
}
}
echo "\n";
if (sizeof($found) > 0)
{
echo "
New files:
";
}
foreach ($found as $row)
{
echo "".$row[0]."
\n";
}
echo "
\n";
function parse($page, $cat, $nocats = false)
{
GLOBAL $found;
$query = get_data($page.$cat);
// Everything before this is header and last updated files
$query = explode(" Browse | ", $query);
$query = $query[1];
// Everything after this is the most downloaded and footer
$query = explode("Downloads from this category", $query);
$query = $query[0];
// Now separate into category and download pages
$query = explode(" | Screenshot | ", $query);
$categories = $query[0];
$downloads = (isset($query[1]) ? $query[1] : "");
// Set found variables
$new = 0;
$old = 0;
// Get and parse all downloads on the page
preg_match_all("/HREF='\?0,0,0,0,(\d+),(\d+)'/", $downloads, $downloads);
$newdowns = array();
for ($index = 0; $index < sizeof($downloads[0]); $index++)
{
$newdowns[] = array($downloads[1][$index], $downloads[2][$index]);
}
$downloads = $newdowns;
unset($newdowns);
foreach ($downloads as $down)
{
$dquery = get_data($page.$cat.",".$down[1]);
// Get the name of the program
preg_match("/ (.*?)<\/B>/", $dquery, $name);
$name = $name[1];
// Download ID is always static
$dl_id = "?0,1,0.0,".$down[0].",".$down[1];
if (!isset($r_query[$dl_id]))
{
preg_match("/http:\/\/dl\.openhandhelds\.org\/cgi-bin\/(.*?)\.cgi/", $page, $system);
$system = $system[1];
$found[] = array("(".$system.") ".$name, $page.$dl_id);
$r_query[$dl_id] = true;
$new++;
}
else
{
$old++;
}
}
// Get and parse all new categories if we are told to
if (!$nocats)
{
preg_match_all("/onclick=\"window\.location\.href='\?0,0,0,0,(.*?)'/", $categories, $categories);
$categories = $categories[1];
foreach ($categories as $catb)
{
parse($page, "?0,0,0,0,".$catb);
}
}
// Output the newly found information
echo "| ".$page.$cat." | Found new: ".$new.", old: ".$old." | \n";
}
?> |