Last ... days top readers statistics

master
vitalif 2010-01-28 12:03:50 +00:00
parent 76018b124b
commit cd35d028a6
4 changed files with 57 additions and 26 deletions

View File

@ -14,22 +14,23 @@
class FoF_Prefs
{
var $user_id;
var $user_id;
var $prefs;
var $admin_prefs;
function FoF_Prefs($user_id)
{
function FoF_Prefs($user_id)
{
global $FOF_USER_TABLE;
$this->user_id = $user_id;
$this->user_id = $user_id;
$result = fof_safe_query("select user_prefs from $FOF_USER_TABLE where user_id = %d", $user_id);
$row = mysql_fetch_array($result);
$prefs = unserialize($row['user_prefs']);
if(!is_array($prefs)) $prefs = array();
if(!is_array($prefs))
$prefs = array();
$this->prefs = $prefs;
if($user_id != 1)
{
$result = fof_safe_query("select user_prefs from $FOF_USER_TABLE where user_id = 1");
@ -42,23 +43,23 @@ class FoF_Prefs
{
$this->admin_prefs = $prefs;
}
$this->populate_defaults();
if($user_id == 1)
{
$this->prefs = array_merge($this->prefs, $this->admin_prefs);
}
}
function &instance()
{
static $instance;
if(!isset($instance)) $instance = new FoF_Prefs(fof_current_user());
return $instance;
}
function populate_defaults()
{
$defaults = array(
@ -70,36 +71,35 @@ class FoF_Prefs
"feed_order" => "feed_title",
"feed_direction" => "asc",
);
$admin_defaults = array(
"purge" => '',
"autotimeout" => 30,
"manualtimeout" => 15,
"logging" => true,
);
$this->stuff_array($this->prefs, $defaults);
$this->stuff_array($this->admin_prefs, $admin_defaults);
}
function stuff_array(&$array, $defaults)
{
foreach($defaults as $k => $v)
{
if(!isset($array[$k])) $array[$k] = $v;
}
if(!isset($array[$k]))
$array[$k] = $v;
}
function get($k)
{
return $this->prefs[$k];
}
function set($k, $v)
{
$this->prefs[$k] = $v;
}
function save()
{
fof_db_save_prefs($this->user_id, $this->prefs);

View File

@ -864,4 +864,22 @@ function fof_db_set_feed_custom_title($user_id, $feed_id, $feed_title, $custom_t
return $r;
}
function fof_db_get_top_readers($days, $count = NULL)
{
global $FOF_ITEM_TABLE, $FOF_USER_TABLE, $FOF_ITEM_TAG_TABLE, $FOF_SUBSCRIPTION_TABLE, $FOF_TAG_TABLE;
$result = fof_db_query(
"select u.*, count(i.item_id) posts from $FOF_USER_TABLE u
join $FOF_SUBSCRIPTION_TABLE s on s.user_id=u.user_id
join $FOF_ITEM_TABLE i on i.feed_id=s.feed_id
join $FOF_TAG_TABLE t on t.tag_name='unread'
left join $FOF_ITEM_TAG_TABLE ti on ti.tag_id=t.tag_id and ti.item_id=i.item_id
where i.item_published > ".(time()-intval($days*86400))." and ti.tag_id is null
group by u.user_id order by posts desc
".(!is_null($count) ? "limit $count" : ""));
$readers = array();
while ($row = mysql_fetch_assoc($result))
$readers[] = $row;
return $readers;
}
?>

View File

@ -47,6 +47,9 @@ $users = fof_db_get_value("SELECT COUNT(*) FROM fof_user");
$feeds = fof_db_get_value("SELECT COUNT(*) FROM fof_feed");
$items = fof_db_get_value("SELECT COUNT(*) FROM fof_item");
if ($fof_prefs_obj && ($days = intval($fof_prefs_obj->admin_prefs['topreaders_days'])) && ($count = intval($fof_prefs_obj->admin_prefs['topreaders_count'])))
$topreaders = fof_db_get_top_readers($days, $count);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
@ -54,8 +57,8 @@ $items = fof_db_get_value("SELECT COUNT(*) FROM fof_item");
<head>
<title>Feed on Feeds - Log on</title>
<style>
body { font-family: georgia; font-size: 16px; }
div { background: #eee; border: 1px solid black; width: 20em; margin: 5em auto; padding: 1.5em; }
body { font-family: georgia; font-size: 16px; text-align: center; }
div { background: #eee; border: 1px solid black; width: 20em; margin: 5em auto 2em; padding: 1.5em; }
form { margin: 0 0 0 -3px; }
</style>
</head>
@ -71,6 +74,13 @@ form { margin: 0 0 0 -3px; }
<center style="padding: 20px 0 0 0; font-size: 75%"><?= "As of ".date("Y-m-d").", $users&nbsp;our&nbsp;users subscribed to $feeds&nbsp;unique&nbsp;feeds with $items&nbsp;items." ?></center>
</form>
</div>
<?php if($topreaders) { ?>
<p><?=$days > 1 ? "Last $days days" : "Today's"?> top readers:<br />
<?php foreach($topreaders as $t) { ?>
<b><?=htmlspecialchars($t['user_name'])?></b>: <?=$t['posts']?> posts read<br />
<? } ?>
</p>
<? } ?>
</body>
</html>

View File

@ -16,12 +16,14 @@ include_once("fof-main.php");
$prefs =& FoF_Prefs::instance();
if(isset($_POST['adminprefs']))
if (fof_is_admin() && isset($_POST['adminprefs']))
{
$prefs->set('purge', $_POST['purge']);
$prefs->set('manualtimeout', $_POST['manualtimeout']);
$prefs->set('autotimeout', $_POST['autotimeout']);
$prefs->set('logging', $_POST['logging']);
$prefs->set('topreaders_days', $_POST['topreaders_days']);
$prefs->set('topreaders_count', $_POST['topreaders_count']);
$prefs->save();
@ -324,7 +326,7 @@ foreach($feeds as $row)
</tr>
<? } ?>
</table>
<input type="submit" value="Update tags and filters" />
<input type="submit" value="Save feed preferences" />
</form>
</div>
@ -336,6 +338,7 @@ Enable logging? <input type=checkbox name=logging <?php if($prefs->get('logging'
Purge read items after <input size=4 type=string name=purge value="<?php echo $prefs->get('purge')?>"> days (leave blank to never purge)<br><br>
Allow automatic feed updates every <input size=4 type=string name=autotimeout value="<?php echo $prefs->get('autotimeout')?>"> minutes<br><br>
Allow manual feed updates every <input size=4 type=string name=manualtimeout value="<?php echo $prefs->get('manualtimeout')?>"> minutes<br><br>
Show <b>Top <input size=3 type=string name=topreaders_count value="<?=intval($prefs->get('topreaders_count'))?>" /> readers in last <input size=3 type=string name=topreaders_days value="<?=intval($prefs->get('topreaders_days'))?>" /> days</b> statistics on the login page<br><br>
<input type=submit name=adminprefs value="Save Options">
</form>