Browse Source

Attempt to fix multibyte padding in stats tool

pull/40/head
Benjamin Southall 5 years ago
parent
commit
adacad2338
  1. 16
      tools/stats.php

16
tools/stats.php

@ -1,5 +1,6 @@
#!/usr/bin/php
<?php
mb_internal_encoding('utf-8');
require dirname(__FILE__) . '/inc/cli.php';
$variants = array(array("hour", 3600), array("day", 3600*24), array("3 days", 3600*24*3),
@ -15,9 +16,22 @@ print(str_repeat('=', 13+11*count($variants)));
print("\n");
function mb_str_pad ($input, $pad_length, $pad_string, $pad_type, $encoding="UTF-8") {
if (!$encoding) {
$diff = strlen($input) - mb_strlen($input);
}
else {
$diff = strlen($input) - mb_strlen($input, $encoding);
}
return str_pad($input, $pad_length + $diff, $pad_string, $pad_type);
}
$q = query("SELECT uri FROM ``boards``");
while ($f = $q->fetch()) {
printf("%10s || ", $f['uri']);
$str = $f['uri'];
$str = mb_str_pad($str,10," ", STR_PAD_LEFT, "UTF-8");
printf("%s || ", $str);
foreach ($variants as $iter) {
list($term, $time) = $iter;
$qq = query(sprintf("SELECT COUNT(*) as count FROM ``posts_%s`` WHERE time > %d", $f['uri'], time()-$time));

Loading…
Cancel
Save