<?php
/**
* Copyright (C) 2004 Tony Bierman
*
* This program 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.
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
/*
see README.html for complete documentation
*/
$COUNT_FILE = phpgiggle_clicksfile;
function error ($error_message) {
echo $error_message."<BR>";
exit;
}
function array_csort() {
$args = func_get_args();
$marray = array_shift($args);
$msortline = "return(array_multisort(";
foreach ($args as $arg) {
$i++;
if (is_string($arg)) {
foreach ($marray as $row) {
$sortarr[$i][] = $row[$arg];
}
} else {
$sortarr[$i] = $arg;
}
$msortline .= "\$sortarr[".$i."],";
}
$msortline .= "\$marray));";
eval($msortline);
return $marray;
}
// Begin Main
if (! file_exists($COUNT_FILE))
error("Can't find file, check '\$COUNT_FILE' var...");
$file_arry = file($COUNT_FILE) or error("Can not open \$COUNT_FILE");
$i=0;
while (list($key, $val) = each($file_arry)) {
if ($val != "") {
list($file_url, $nb) = preg_split("/\t|\n/", $val);
$array[$i][url] = $file_url;
$array[$i][hits] = $nb;
$i++;
}
}
$sorted = array_csort($array, "hits", SORT_DESC, SORT_NUMERIC);
for($x=0;$x<=$i;$x++) {
$output .= "<TR><TD>"."<A HREF=\"".$sorted[$x][url].
"\">".wordwrap($sorted[$x][url], 52, "<br />\n", 1)."</A></TD>".
sprintf("<TD>%05d</TD>",$sorted[$x][hits])."</TR>";
$total_hits+=$sorted[$x][hits];
}
?>
<div id="content" width="80%">
<h2>Summary for <?php echo $total_hits; ?> Clicks</h2><br />
<TABLE Border="1" width="100"><TR><TH>URL</TH><TH>Clicks</TH></TR>
<?php echo $output; ?>
</TABLE></DIV>