File size: 3.56Kb
<?php
/**
* Free Wallpaper Script
*
* Free Wallpaper Script by Vepa Halliyev is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
*
* @package Free Wallpaper Script
* @author Vepa Halliyev
* @copyright Copyright (c) 2009, Vepa Halliyev, veppa.com.
* @license http://www.veppa.com/free-wallpaper-script/
* @link http://www.veppa.com/free-wallpaper-script/
* @since Version 1.0
* @filesource
*/
/**
* class Config
*
* @author Vepa Halliyev <veppa.com>
* @since 0.1
*/
class Config extends Record
{
const TABLE_NAME = 'config';
static $conf = false;
private static $loaded = false;
private static $themes;
private static $cols = array(
'name' => 1,
'val' => 1,
'is_editable' => 1
);
public function __construct($data = false, $locale_db = false)
{
$this->setColumns(self::$cols);
parent::__construct($data,$locale_db);
}
static public function option($name)
{
self::load();
return self::$conf->{$name};
}
public function optionSet($name,$value,$editible=0)
{
// read from db
$opt = self::findOneFrom('Config','name=?',array($name));
//print_r($opt);
if($opt)
{
// update record
$opt->val = $value;
$opt->save('name');
}
else
{
// save as new record
$opt = new Config();
$opt->val = $value;
$opt->name = $name;
$opt->is_editable = intval($editible);
$opt->save('no_id');
}
self::$conf->{$name} = $value;
}
public function load()
{
if(!self::$loaded)
{
$c = self::findAllFrom('Config');
self::$conf = new stdClass();
foreach($c as $c_)
{
self::$conf->{$c_->name} = $c_->val;
}
self::$loaded = true;
}
return self::$conf;
}
static function urlAssets()
{
// check if template set then load template location
return self::urlTemplate().'public/';
}
static function urlTemplate()
{
$template = self::option('template');
return BASE_URL.'user-content/templates/'.$template.'/';
}
/**
* Retrieve list of themes with theme data in theme directory.
*
* The theme is broken, if it doesn't have a parent theme and is missing either
* style.css and, or index.php. If the theme has a parent theme then it is
* broken, if it is missing style.css; index.php is optional. The broken theme
* list is saved in the {@link $wp_broken_themes} global, which is displayed on
* the theme list in the administration panels.
*
* @since 1.5.0
* @global array $wp_broken_themes Stores the broken themes.
* @global array $wp_themes Stores the working themes.
*
* @return array Theme list with theme data.
*/
function getThemes()
{
if(is_null(self::$themes))
{
// get themes from directory
self::$themes = array();
$theme_root = CORE_ROOT.'/../user-content/templates/';
// Files in wp-content/themes directory and one subdir down
$themes_dir = @ opendir($theme_root);
if ( !$themes_dir )
return false;
while ( ($theme_dir = readdir($themes_dir)) !== false ) {
if ( is_dir($theme_root . '/' . $theme_dir) && is_readable($theme_root . '/' . $theme_dir) ) {
if ( $theme_dir{0} == '.' || $theme_dir == '..' || $theme_dir == 'CVS' )
continue;
self::$themes[] = $theme_dir;
}
}
if ( is_dir( $theme_dir ) )
@closedir( $theme_dir );
if ( !$themes_dir || !self::$themes )
return self::$themes;
sort(self::$themes);
}
return self::$themes;
}
} // end User class