FeedOnFeeds/classes/fof-prefs.php

111 lines
2.5 KiB
PHP
Raw Normal View History

2009-08-03 16:42:04 +04:00
<?php
/*
* This file is part of FEED ON FEEDS - http://feedonfeeds.com/
*
* fof-prefs.php - Preferences class
*
*
* Copyright (C) 2004-2007 Stephen Minutillo
* steve@minutillo.com - http://minutillo.com/steve/
*
* Distributed under the GPL - see LICENSE
*
*/
class FoF_Prefs
{
2010-01-28 15:03:50 +03:00
var $user_id;
2009-08-03 16:42:04 +04:00
var $prefs;
var $admin_prefs;
2010-01-28 15:03:50 +03:00
function __construct($user_id)
2010-01-28 15:03:50 +03:00
{
2009-08-03 16:42:04 +04:00
global $FOF_USER_TABLE;
2010-01-28 15:03:50 +03:00
$this->user_id = $user_id;
2009-08-03 16:42:04 +04:00
$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']);
2010-01-28 15:03:50 +03:00
if(!is_array($prefs))
$prefs = array();
2009-08-03 16:42:04 +04:00
$this->prefs = $prefs;
2010-01-28 15:03:50 +03:00
2009-08-03 16:42:04 +04:00
if($user_id != 1)
{
$result = fof_safe_query("select user_prefs from $FOF_USER_TABLE where user_id = 1");
$row = mysql_fetch_array($result);
$admin_prefs = unserialize($row['user_prefs']);
if(!is_array($admin_prefs)) $admin_prefs = array();
$this->admin_prefs = $admin_prefs;
}
else
{
$this->admin_prefs = $prefs;
}
2010-01-28 15:03:50 +03:00
2009-08-03 16:42:04 +04:00
$this->populate_defaults();
2010-01-28 15:03:50 +03:00
2009-08-03 16:42:04 +04:00
if($user_id == 1)
{
$this->prefs = array_merge($this->prefs, $this->admin_prefs);
}
}
2010-01-28 15:03:50 +03:00
static function instance()
2009-08-03 16:42:04 +04:00
{
static $instance;
if(!isset($instance))
{
$instance = new FoF_Prefs(fof_current_user());
}
2010-01-28 15:03:50 +03:00
2009-08-03 16:42:04 +04:00
return $instance;
}
2010-01-28 15:03:50 +03:00
2009-08-03 16:42:04 +04:00
function populate_defaults()
{
$defaults = array(
"favicons" => true,
"keyboard" => false,
"direction" => "desc",
"howmany" => 50,
"sharing" => "no",
"feed_order" => "feed_title",
"feed_direction" => "asc",
);
2010-01-28 15:03:50 +03:00
2009-08-03 16:42:04 +04:00
$admin_defaults = array(
2010-01-25 20:33:32 +03:00
"purge" => '',
2009-08-03 16:42:04 +04:00
"autotimeout" => 30,
"manualtimeout" => 15,
2010-01-25 20:33:32 +03:00
"logging" => true,
);
2010-01-28 15:03:50 +03:00
2009-08-03 16:42:04 +04:00
$this->stuff_array($this->prefs, $defaults);
$this->stuff_array($this->admin_prefs, $admin_defaults);
}
2010-01-28 15:03:50 +03:00
2009-08-03 16:42:04 +04:00
function stuff_array(&$array, $defaults)
{
foreach($defaults as $k => $v)
2010-01-28 15:03:50 +03:00
if(!isset($array[$k]))
$array[$k] = $v;
2009-08-03 16:42:04 +04:00
}
2010-01-28 15:03:50 +03:00
2009-08-03 16:42:04 +04:00
function get($k)
{
return $this->prefs[$k];
}
2010-01-28 15:03:50 +03:00
2009-08-03 16:42:04 +04:00
function set($k, $v)
{
$this->prefs[$k] = $v;
}
2010-01-28 15:03:50 +03:00
2009-08-03 16:42:04 +04:00
function save()
{
fof_db_save_prefs($this->user_id, $this->prefs);
}
}