added phpzip and coordstat to distribution

.
This commit is contained in:
following
2013-02-07 12:16:15 +01:00
parent ac2b6bfc21
commit 1e7bb6493b
2 changed files with 186 additions and 0 deletions

88
bin/phpzip.php Normal file
View File

@@ -0,0 +1,88 @@
#!/usr/bin/php -q
<?php
/***************************************************************************
bin/phpzip.php
-------------------
begin : December 22 2005
For license information see doc/license.txt
***************************************************************************/
/***************************************************************************
Wrapper for unix-utilities zip, gzip and bz2
***************************************************************************/
$basedir = '/path/to/htdocs/download/zip/';
$zipper['zip'] = 'nice --adjustment=19 zip -j -q -1 {dst} {src}';
$zipper['gzip'] = 'nice --adjustment=19 gzip -1 -c {src} > {dst}';
$zipper['bzip2'] = 'nice --adjustment=19 bzip2 -1 -c {src} > {dst}';
if ($argv[1] == '--help')
{
echo $argv[0] . " --type=<ziptype> --src=<source> --dst=<destination>
--type can be zip, gzip or bzip2
--src relative* path to source file
--dst relative* path to destination file
*relative to $basedir
";
exit;
}
if ((substr($argv[1], 0, 7) != '--type=') || (substr($argv[2], 0, 6) != '--src=') || (substr($argv[3], 0, 6) != '--dst='))
die("wrong paramter\nuse " . $argv[0] . " --help\n");
if (isset($argv[4]))
die("wrong paramter\nuse " . $argv[0] . " --help\n");
$type = substr($argv[1], 7);
$src = substr($argv[2], 6);
$dst = substr($argv[3], 6);
if (!isset($zipper[$type]))
die("invaild zip type\nuse " . $argv[0] . " --help\n");
if (checkpath($src) == false)
die("invaild src\nuse " . $argv[0] . " --help\n");
if (checkpath($dst) == false)
die("invaild dst\nuse " . $argv[0] . " --help\n");
$src = $basedir . $src;
$dst = $basedir . $dst;
if (!file_exists($src))
die("error: source not exist\nuse " . $argv[0] . " --help\n");
if (file_exists($dst))
die("error: destination already exists\nuse " . $argv[0] . " --help\n");
$cmd = $zipper[$type];
$cmd = str_replace('{src}', escapeshellcmd($src), $cmd);
$cmd = str_replace('{dst}', escapeshellcmd($dst), $cmd);
system($cmd);
function checkpath($path)
{
$parts = explode('/', $path);
if ($parts[0] == '')
return false;
for ($i = 0; $i < count($parts); $i++)
{
if (($parts[$i] == '..') || ($parts[$i] == '.'))
return false;
if (!preg_match('/^[a-zA-Z0-9.-_]{1,}/', $parts[$i]))
return false;
}
return true;
}
?>

View File

@@ -0,0 +1,98 @@
<?php
/***************************************************************************
* For license information see doc/license.txt
*
* Unicode Reminder メモ
***************************************************************************/
// statistical data for cache and log activity map
chdir ("../..");
require('lib2/web.inc.php');
error_reporting(error_reporting() & ~E_NOTICE);
$grid = $_GET["grid"];
if ($grid <= 0) $grid = 0.2;
// caches created by year
$rs = sql("SELECT latitude, longitude, date_created FROM caches");
while ($cache = sql_fetch_assoc($rs))
{
$lat = floor($cache["latitude"] / $grid);
$long = floor($cache["longitude"] / $grid);
$year = substr($cache["date_created"],0,4);
if ($year >= 2005 && $year <= date("Y") && ($lat != 0 || $long != 0))
{
$years[$year] = true;
$liste[$lat][$long]["caches"][$year]++;
}
}
mysql_free_result($rs);
// logs per logdate by year
get_logs("cache_logs");
// get_logs("cache_logs_archived");
function get_logs($table)
{
global $grid, $liste, $years;
$rs = sql("SELECT latitude, longitude, date
FROM $table
INNER JOIN caches ON $table.cache_id=caches.cache_id");
while ($cache = sql_fetch_assoc($rs))
{
$lat = floor($cache["latitude"] / $grid);
$long = floor($cache["longitude"] / $grid);
$year = substr($cache["date"],0,4);
if ($year >= 2005 && $year <= date("Y") && ($lat != 0 || $long != 0))
{
$years[$year] = true;
$liste[$lat][$long]["logs"][$year]++;
}
}
mysql_free_result($rs);
}
ksort($years);
// active caches and logs
$rs = sql("SELECT latitude, longitude,
(SELECT COUNT(*) FROM cache_logs WHERE cache_logs.cache_id=caches.cache_id) AS logs
FROM caches WHERE status=1");
while ($cache = sql_fetch_assoc($rs))
{
$lat = floor($cache["latitude"] / $grid);
$long = floor($cache["longitude"] / $grid);
$liste[$lat][$long]["caches"]["all"]++;
$liste[$lat][$long]["logs"]["all"] += $cache["logs"];
}
mysql_free_result($rs);
ksort ($liste);
$lats = array_keys($liste);
foreach ($lats as $lat)
ksort($liste[$lat]);
// create output CSV data
header("Content-type: application/comma-separated-value");
header('Content-Disposition: attachment; filename="cachestat.csv"');
echo "latitude,longitude,caches,logs";
foreach ($years as $year => $dummy)
echo ",caches$year,logs$year";
echo "\r\n";
foreach ($liste as $lat => $liste2)
foreach ($liste2 as $long => $cachecounts)
{
echo ($lat*$grid + 0.5*$grid) . "," . ($long*$grid + 0.5*$grid) . "," .
$cachecounts["caches"]["all"] . "," .
$cachecounts["logs"]["all"];
foreach ($years as $year => $dummy)
echo "," . $cachecounts["caches"][$year] . "," . $cachecounts["logs"][$year];
echo "\r\n";
}
?>