aboutsummaryrefslogtreecommitdiff
path: root/cli/user-info.php
blob: 5b26ecb15e4ef9155d50d6eb3bb0d12079ec5f46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/php
<?php
require('_cli.php');

function formatSize($bytes)
{//http://www.php.net/manual/function.disk-free-space.php#103382
	$si_prefix = array('', 'k', 'M', 'G', 'T', 'P');
	$i = min((int)log($bytes, 1024), count($si_prefix) - 1);
	return ($i <= 0) ? $bytes.'B' :
		round($bytes / pow(1024, $i), 2).' '.$si_prefix[$i].'B';
}

$options = getopt('h', array(
		'user:',
	));

if (empty($options['user'])) {
	fail('Usage: ' . basename(__FILE__) . " -h --user username");
}

$users = $options['user'] === '*' ? listUsers() : array($options['user']);

foreach ($users as $username) {
	$username = cliInitUser($username);

	$entryDAO = FreshRSS_Factory::createEntryDao($username);

	echo $username === FreshRSS_Context::$system_conf->default_user ? '*' : ' ', "\t";

	if (isset($options['h'])) {	//Human format
		echo
			$username, "\t",
			date('c', FreshRSS_UserDAO::mtime($username)), "\t",
			formatSize($entryDAO->size()), "\t",
			"\n";
	} else {
		echo
			$username, "\t",
			FreshRSS_UserDAO::mtime($username), "\t",
			$entryDAO->size(), "\t",
			"\n";
	}
}