1
0
mirror of https://github.com/php/web-php.git synced 2026-04-26 08:28:07 +02:00
Files
archived-web-php/bin/get-user-notes
T
jim winstead 930b62b1ad duh.
2001-08-28 07:26:29 +00:00

42 lines
1.1 KiB
PHP
Executable File

#!/usr/local/bin/php -q
<?
if ($argc != 2 && $argc != 3) die("usage: $argv[0] documentroot [since]");
$token = getenv("TOKEN");
if (!$token) die("you have to set the TOKEN environment variable");
$root = $argv[1];
if (!ereg("/\$",$root)) $root = "$root/";
$since = $argv[2];
$fp = fopen("http://www.php.net/bin/user-notes.php?token=".rawurlencode($token).($since?"&since=$since":""),"r");
while (!feof($fp)) {
$line = chop(fgets($fp,8096));
if (!strstr($line,"|")) continue; # skip invalid lines
list($id,$sect,$rate,$ts,$user,$note) = explode("|",$line);
$hash = substr(md5($sect),0,16);
@mkdir($root.substr($hash,0,2),0755);
$file = $root.substr($hash,0,2)."/$hash";
if ($since && !$restarted[$file]++) {
unlink($file);
}
$mtime = filemtime($file);
if (!($file = @fopen($file,"a"))) {
echo "unable to open $notes file $hash\n";
continue;
}
$note = gzuncompress(base64_decode($note));
fputs($file,"$id|$sect|$rate|$ts|$user|".base64_encode($note)."\n");
fclose($file);
touch($file, $mtime < $ts ? $ts : $mtime);
}
// vim: set ft=php3 : :