Jump to content

User:Arnaud.ramey/GlamFiltered/Source

From Wikipedia, the free encyclopedia
<?php
function debug($msg) { echo "$msg<br>\n"; }

function refresh() {
	$max_hits_to_display = 300;
	$url = "http://toolserver.org/~magnus/glamorous.php?doit=1&category=Images+that+should+use+vector+graphics&use_globalusage=1&ns0=1&show_details=1&format=xml";
	//$url="file:///home/arnaud/Wiki/2010-09-07_php_glamorous/glamorous.php";
	//$url = "http://toolserver.org/~magnus/glamorous.php?doit=1&category=Altes+Rathaus+%28Bamberg%29+viewed+from+south&use_globalusage=1&ns0=1&show_details=1&format=xml";
	$content = "";

	debug("*** Retrieving content of Glamorous...");
	$nb_try = 0;
	while (strlen($content) < 500) {
	    $nb_try++;
	    $content = file_get_contents($url);
	}
	debug("*** Content retrieved in $nb_try tries.");
	debug("Lenght of the content : " . strlen($content) );
	//echo "<pre>"; 	foreach (str_split($content, 100) as $val) echo htmlentities($val) . "\n"; echo "</pre>";
	//echo "<pre>"; foreach (explode('>', $content) as $val) echo htmlentities($val . ">") . "\n"; echo "</pre>";

	debug("*** Parsing...");
	$tag_regexp = "'([^']*)'[^>]*"; // a value between quotes followed by anything
	$pattern = "|<image name=$tag_regexp url_page=$tag_regexp url_thumbnail=$tag_regexp usage=$tag_regexp>|siU";
	$nb_hits = preg_match_all($pattern, $content, $matches);

	debug("Nb hits:$nb_hits");
	//echo '<pre>'; print_r($matches); echo '</pre>';

	echo "<pre>" . htmlentities("<gallery>\n");
	for ($i = 0; $i < min($nb_hits, $max_hits_to_display); ++$i) {
	    $filename = $matches[1][$i];
	    $url_page = $matches[2][$i];
	    $url_thumbnail = $matches[3][$i];
	    $usage = $matches[4][$i];
	    //debug("Match: '$filename', usage:$usage");
	    //debug("<li><img src='$url_thumbnail' size=36/> <a href='$url_page'>$filename</a>, used $usage times.");
	    echo "File:" . $filename . " | " . $filename . " ($usage times)\n";
	}
	echo htmlentities("</gallery>\n") . "</pre>";
}
?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Title</title>
</head>
<body>
<? refresh() ?>
</body>
</html>