bludit/bl-kernel/dbsite.class.php

304 lines
6.9 KiB
PHP
Raw 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!'),
2017-05-31 20:17:21 +02:00
'itemsPerPage'=> array('inFile'=>false, 'value'=>6),
2015-08-26 05:42:32 +02:00
'language'=> array('inFile'=>false, 'value'=>'en'),
'locale'=> array('inFile'=>false, 'value'=>'en, en_US, en_AU, en_CA, en_GB, en_IE, en_NZ'),
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'=>''),
'pageNotFound'=> array('inFile'=>false, 'value'=>''),
2015-05-05 03:00:01 +02:00
'uriPage'=> array('inFile'=>false, 'value'=>'/'),
'uriTag'=> array('inFile'=>false, 'value'=>'/tag/'),
2017-05-03 21:10:03 +02:00
'uriCategory'=> array('inFile'=>false, 'value'=>'/category/'),
'uriBlog'=> array('inFile'=>false, 'value'=>'/blog/'),
2015-09-10 04:33:31 +02:00
'url'=> array('inFile'=>false, 'value'=>''),
'emailFrom'=> array('inFile'=>false, 'value'=>''),
'dateFormat'=> array('inFile'=>false, 'value'=>'F j, Y'),
'timeFormat'=> array('inFile'=>false, 'value'=>'g:i a'),
2016-02-14 01:15:19 +01:00
'currentBuild'=> array('inFile'=>false, 'value'=>0),
'twitter'=> array('inFile'=>false, 'value'=>''),
'facebook'=> array('inFile'=>false, 'value'=>''),
2017-09-29 23:02:05 +02:00
'codepen'=> array('inFile'=>false, 'value'=>''),
2016-02-14 01:15:19 +01:00
'googlePlus'=> array('inFile'=>false, 'value'=>''),
2016-02-14 22:53:37 +01:00
'instagram'=> array('inFile'=>false, 'value'=>''),
2017-05-17 00:04:53 +02:00
'github'=> array('inFile'=>false, 'value'=>''),
2017-06-20 23:56:22 +02:00
'orderBy'=> array('inFile'=>false, 'value'=>'date') // date or position
2015-05-05 03:00:01 +02:00
);
function __construct()
{
2017-05-09 00:24:15 +02:00
parent::__construct(DB_SITE);
2015-05-05 03:00:01 +02:00
// 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])) {
2015-05-05 03:00:01 +02:00
$this->db[$field] = Sanitize::html($value);
}
}
return $this->save();
2015-05-05 03:00:01 +02:00
}
2017-05-09 00:24:15 +02:00
// Returns an array with the filters for the url
// or returns a string with the filter defined on $filter
2016-01-29 17:10:53 +01:00
public function uriFilters($filter='')
2015-05-05 03:00:01 +02:00
{
$filters['admin'] = '/'.ADMIN_URI_FILTER;
$filters['page'] = $this->getField('uriPage');
$filters['tag'] = $this->getField('uriTag');
2017-05-03 21:10:03 +02:00
$filters['category'] = $this->getField('uriCategory');
$filters['blog'] = $this->getField('uriBlog');
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];
}
// Returns the URL of the rss.xml file
// You need to have enabled the plugin RSS
public function rss()
{
return DOMAIN_BASE.'rss.xml';
}
// Returns the URL of the sitemap.xml file
// You need to have enabled the plugin Sitemap
public function sitemap()
{
return DOMAIN_BASE.'sitemap.xml';
2017-05-03 21:10:03 +02:00
}
2016-02-14 01:15:19 +01:00
public function twitter()
{
return $this->getField('twitter');
}
public function facebook()
{
return $this->getField('facebook');
}
2017-09-29 23:02:05 +02:00
public function codepen()
{
return $this->getField('codepen');
}
2016-02-14 22:53:37 +01:00
public function instagram()
{
return $this->getField('instagram');
}
2016-02-14 01:15:19 +01:00
public function github()
{
return $this->getField('github');
}
public function googlePlus()
{
return $this->getField('googlePlus');
}
2017-05-17 00:04:53 +02:00
public function orderBy()
{
return $this->getField('orderBy');
}
2017-05-09 00:24:15 +02:00
// Returns the site title
2015-05-05 03:00:01 +02:00
public function title()
{
return $this->getField('title');
2015-05-05 03:00:01 +02:00
}
2017-05-09 00:24:15 +02:00
// Returns the site slogan
2016-01-29 17:07:29 +01:00
public function slogan()
2015-10-20 05:14:28 +02:00
{
2016-01-29 17:07:29 +01:00
return $this->getField('slogan');
}
2017-05-09 00:24:15 +02:00
// Returns the site description
2016-01-29 17:07:29 +01:00
public function description()
{
2016-01-29 17:07:29 +01:00
return $this->getField('description');
}
2016-01-29 17:07:29 +01:00
public function emailFrom()
{
2016-01-29 17:07:29 +01:00
return $this->getField('emailFrom');
2015-10-20 05:14:28 +02:00
}
2016-01-29 17:07:29 +01:00
public function dateFormat()
2015-05-19 01:22:05 +02:00
{
2016-01-29 17:07:29 +01:00
return $this->getField('dateFormat');
2015-05-19 01:22:05 +02:00
}
2016-01-29 17:07:29 +01:00
public function timeFormat()
2015-05-05 03:00:01 +02:00
{
2016-01-29 17:07:29 +01:00
return $this->getField('timeFormat');
2015-05-05 03:00:01 +02:00
}
2017-05-09 00:24:15 +02:00
// Returns the site theme name
2015-05-05 03:00:01 +02:00
public function theme()
{
return $this->getField('theme');
2015-05-05 03:00:01 +02:00
}
2017-05-09 00:24:15 +02:00
// Returns the admin theme name
2015-05-05 03:00:01 +02:00
public function adminTheme()
{
return $this->getField('adminTheme');
2015-05-05 03:00:01 +02:00
}
2017-05-09 00:24:15 +02:00
// Returns the footer text
2015-05-05 03:00:01 +02:00
public function footer()
{
return $this->getField('footer');
2015-05-05 03:00:01 +02:00
}
2017-05-09 00:24:15 +02:00
// Returns the full domain and base url
// For example, https://www.domain.com/bludit
2015-05-05 03:00:01 +02:00
public function url()
{
return $this->getField('url');
2015-05-05 03:00:01 +02:00
}
2017-05-09 00:24:15 +02:00
// Returns the protocol and the domain, without the base url
2016-01-21 01:29:01 +01:00
// For example, http://www.domain.com
public function domain()
{
2015-11-30 01:45:30 +01:00
// If the URL field is not set, try detect the domain.
2017-05-09 00:24:15 +02:00
if(Text::isEmpty( $this->url() )) {
2015-11-30 01:45:30 +01:00
if(!empty($_SERVER['HTTPS'])) {
$protocol = 'https://';
}
else {
$protocol = 'http://';
}
2016-01-11 23:51:00 +01:00
$domain = trim($_SERVER['HTTP_HOST'], '/');
return $protocol.$domain;
2015-11-30 01:45:30 +01:00
}
// Parse the domain from the field URL.
$parse = parse_url($this->url());
2016-01-11 23:51:00 +01:00
$domain = trim($parse['host'], '/');
return $parse['scheme'].'://'.$domain;
}
2017-09-15 21:26:06 +02:00
/* DEPRECATED
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
}
2017-09-15 21:26:06 +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 the current build / version of Bludit.
public function currentBuild()
{
return $this->getField('currentBuild');
}
2017-05-09 00:24:15 +02:00
// Returns the amount of pages per page
public function itemsPerPage()
2015-05-05 03:00:01 +02:00
{
2017-05-09 00:24:15 +02:00
return $this->getField('itemsPerPage');
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
}
2017-09-15 21:26:06 +02:00
/* DEPRECATED
// Returns the current language in short format
2015-07-29 04:30:41 +02:00
public function shortLanguage()
{
$locale = $this->locale();
$explode = explode('_', $locale);
$short = array_shift($explode);
return $short;
}
2017-09-15 21:26:06 +02:00
*/
2017-07-11 23:53:53 +02:00
// Returns the current homepage, FALSE if not defined homepage
2015-05-05 03:00:01 +02:00
public function homepage()
{
2017-07-11 23:53:53 +02:00
$homepage = $this->getField('homepage');
if( empty($homepage) ) {
return false;
}
return $homepage;
2015-05-05 03:00:01 +02:00
}
// Returns the page defined for "Page not found", FALSE if not defined
public function pageNotFound()
{
$pageNotFound = $this->getField('pageNotFound');
if( empty($pageNotFound) ) {
return false;
}
return $pageNotFound;
}
// Set the locale, returns TRUE is success, FALSE otherwise
2015-05-05 03:00:01 +02:00
public function setLocale($locale)
{
$localeList = explode(',', $locale);
foreach ($localeList as $locale) {
$locale = trim($locale);
if (setlocale(LC_ALL, $locale.'.UTF-8')!==false) {
return true;
}
elseif (setlocale(LC_ALL, $locale)!==false) {
return true;
}
2015-10-24 01:23:33 +02:00
}
2015-05-05 03:00:01 +02:00
// Not was possible to set a locale, using default locale
return false;
2015-05-05 03:00:01 +02:00
}
// Set the timezone.
public function setTimezone($timezone)
{
return date_default_timezone_set($timezone);
}
2016-01-21 01:29:01 +01:00
}