bludit/kernel/dbsite.class.php

224 lines
4.7 KiB
PHP
Raw Permalink Normal View History

2015-05-05 03:00:01 +02:00
<?php defined('BLUDIT') or die('Bludit CMS.');
class dbSite extends dbJSON
{
public $dbFields = array(
2015-08-26 05:42:32 +02:00
'title'=> array('inFile'=>false, 'value'=>'I am Guybrush Threepwood, mighty developer'),
2015-05-19 01:22:05 +02:00
'slogan'=> array('inFile'=>false, 'value'=>''),
2015-08-26 05:42:32 +02:00
'description'=> array('inFile'=>false, 'value'=>''),
'footer'=> array('inFile'=>false, 'value'=>'I wanna be a pirate!'),
'postsperpage'=> array('inFile'=>false, 'value'=>''),
'language'=> array('inFile'=>false, 'value'=>'en'),
2015-06-26 06:31:53 +02:00
'locale'=> array('inFile'=>false, 'value'=>'en_US'),
2015-08-26 05:42:32 +02:00
'timezone'=> array('inFile'=>false, 'value'=>'America/Argentina/Buenos_Aires'),
2015-05-05 03:00:01 +02:00
'theme'=> array('inFile'=>false, 'value'=>'pure'),
2015-08-26 05:42:32 +02:00
'adminTheme'=> array('inFile'=>false, 'value'=>'default'),
'homepage'=> array('inFile'=>false, 'value'=>''),
2015-05-05 03:00:01 +02:00
'uriPage'=> array('inFile'=>false, 'value'=>'/'),
'uriPost'=> array('inFile'=>false, 'value'=>'/post/'),
'uriTag'=> array('inFile'=>false, 'value'=>'/tag/'),
2015-09-10 04:33:31 +02:00
'url'=> array('inFile'=>false, 'value'=>''),
2015-10-20 05:14:28 +02:00
'cliMode'=> array('inFile'=>false, 'value'=>true),
'emailFrom'=> array('inFile'=>false, 'value'=>''),
'dateFormat'=> array('inFile'=>false, 'value'=>'F j, Y'),
'timeFormat'=> array('inFile'=>false, 'value'=>'g:i a')
2015-05-05 03:00:01 +02:00
);
function __construct()
{
parent::__construct(PATH_DATABASES.'site.php');
// Set timezone
$this->setTimezone( $this->timezone() );
// Set locale
$this->setLocale( $this->locale() );
}
// Returns an array with site configuration.
function get()
{
return $this->db;
}
public function set($args)
{
foreach($args as $field=>$value)
{
if( isset($this->dbFields[$field]) )
{
$this->db[$field] = Sanitize::html($value);
}
}
if( $this->save() === false ) {
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.');
return false;
}
return true;
}
// Returns an array with the filters for the url.
public function uriFilters($filter='')
{
$filters['admin'] = '/admin/';
$filters['post'] = $this->getField('uriPost');
$filters['page'] = $this->getField('uriPage');
$filters['tag'] = $this->getField('uriTag');
2015-05-05 03:00:01 +02:00
2015-09-18 02:37:14 +02:00
if(empty($filter)) {
2015-05-05 03:00:01 +02:00
return $filters;
2015-09-18 02:37:14 +02:00
}
2015-05-05 03:00:01 +02:00
return $filters[$filter];
}
public function urlPost()
{
$filter = $this->getField('uriPost');
return $this->url().ltrim($filter, '/');
2015-05-05 03:00:01 +02:00
}
public function urlPage()
{
$filter = $this->getField('uriPage');
return $this->url().ltrim($filter, '/');
2015-05-05 03:00:01 +02:00
}
public function urlTag()
{
$filter = $this->getField('uriTag');
return $this->url().ltrim($filter, '/');
2015-05-05 03:00:01 +02:00
}
// Returns the site title.
public function title()
{
return $this->getField('title');
2015-05-05 03:00:01 +02:00
}
2015-10-20 05:14:28 +02:00
public function emailFrom()
{
return $this->getField('emailFrom');
}
public function dateFormat()
{
return $this->getField('dateFormat');
}
public function timeFormat()
{
return $this->getField('timeFormat');
2015-10-20 05:14:28 +02:00
}
2015-05-19 01:22:05 +02:00
// Returns the site slogan.
public function slogan()
{
return $this->getField('slogan');
2015-05-19 01:22:05 +02:00
}
2015-05-05 03:00:01 +02:00
// Returns the site description.
public function description()
{
return $this->getField('description');
2015-05-05 03:00:01 +02:00
}
// Returns the site theme name.
public function theme()
{
return $this->getField('theme');
2015-05-05 03:00:01 +02:00
}
// Returns the admin theme name.
public function adminTheme()
{
return $this->getField('adminTheme');
2015-05-05 03:00:01 +02:00
}
// Returns the footer text.
public function footer()
{
return $this->getField('footer');
2015-05-05 03:00:01 +02:00
}
// Returns the url site.
public function url()
{
return $this->getField('url');
2015-05-05 03:00:01 +02:00
}
2015-09-10 04:33:31 +02:00
// Returns TRUE if the cli mode is enabled, otherwise FALSE.
public function cliMode()
{
return $this->getField('cliMode');
2015-09-10 04:33:31 +02:00
}
2015-07-10 02:25:53 +02:00
// Returns the relative home link
public function homeLink()
{
2015-09-08 02:51:48 +02:00
return HTML_PATH_ROOT;
2015-07-10 02:25:53 +02:00
}
2015-05-05 03:00:01 +02:00
// Returns the timezone.
public function timezone()
{
return $this->getField('timezone');
2015-05-05 03:00:01 +02:00
}
// Returns posts per page.
public function postsPerPage()
{
return $this->getField('postsperpage');
2015-05-05 03:00:01 +02:00
}
// Returns the current language.
public function language()
{
return $this->getField('language');
2015-05-05 03:00:01 +02:00
}
// Returns the current locale.
public function locale()
{
return $this->getField('locale');
2015-05-05 03:00:01 +02:00
}
2015-07-29 04:30:41 +02:00
// Returns the current language in short format.
public function shortLanguage()
{
$locale = $this->locale();
$explode = explode('_', $locale);
$short = array_shift($explode);
return $short;
}
2015-05-05 03:00:01 +02:00
// Returns the current homepage.
public function homepage()
{
return $this->getField('homepage');
2015-05-05 03:00:01 +02:00
}
// Set the locale.
public function setLocale($locale)
{
2015-10-24 01:23:33 +02:00
if(setlocale(LC_ALL, $locale.'.UTF-8')!==false) {
2015-05-05 03:00:01 +02:00
return true;
2015-10-24 01:23:33 +02:00
}
2015-05-05 03:00:01 +02:00
2015-10-24 01:23:33 +02:00
if(setlocale(LC_ALL, $locale.'.UTF8')!==false) {
2015-05-05 03:00:01 +02:00
return true;
2015-10-24 01:23:33 +02:00
}
2015-05-05 03:00:01 +02:00
return setlocale(LC_ALL, $locale);
}
// Set the timezone.
public function setTimezone($timezone)
{
return date_default_timezone_set($timezone);
}
2015-10-24 01:23:33 +02:00
}