2015-05-05 03:00:01 +02:00
|
|
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
|
|
|
|
2018-08-03 18:59:23 +02:00
|
|
|
class Site extends dbJSON {
|
2015-11-14 17:47:26 +01:00
|
|
|
public $dbFields = array(
|
2018-07-28 21:00:12 +02:00
|
|
|
'title'=> 'I am Guybrush Threepwood, mighty developer',
|
|
|
|
'slogan'=> '',
|
|
|
|
'description'=> '',
|
|
|
|
'footer'=> 'I wanna be a pirate!',
|
|
|
|
'itemsPerPage'=> 6,
|
|
|
|
'language'=> 'en',
|
|
|
|
'locale'=> 'en, en_US, en_AU, en_CA, en_GB, en_IE, en_NZ',
|
|
|
|
'timezone'=> 'America/Argentina/Buenos_Aires',
|
|
|
|
'theme'=> 'pure',
|
|
|
|
'adminTheme'=> 'default',
|
|
|
|
'homepage'=> '',
|
|
|
|
'pageNotFound'=> '',
|
|
|
|
'uriPage'=> '/',
|
|
|
|
'uriTag'=> '/tag/',
|
|
|
|
'uriCategory'=> '/category/',
|
|
|
|
'uriBlog'=> '/blog/',
|
|
|
|
'url'=> '',
|
|
|
|
'emailFrom'=> '',
|
|
|
|
'dateFormat'=> 'F j, Y',
|
|
|
|
'timeFormat'=> 'g:i a',
|
|
|
|
'currentBuild'=> 0,
|
|
|
|
'twitter'=> '',
|
|
|
|
'facebook'=> '',
|
|
|
|
'codepen'=> '',
|
|
|
|
'googlePlus'=> '',
|
|
|
|
'instagram'=> '',
|
|
|
|
'github'=> '',
|
|
|
|
'gitlab'=> '',
|
|
|
|
'linkedin'=> '',
|
|
|
|
'orderBy'=> 'date', // date or position
|
|
|
|
'extremeFriendly'=> true,
|
|
|
|
'autosaveInterval'=> 2, // minutes
|
|
|
|
'titleFormatHomepage'=> '{{site-slogan}} | {{site-title}}',
|
|
|
|
'titleFormatPages'=> '{{page-title}} | {{site-title}}',
|
|
|
|
'titleFormatCategory'=> '{{category-name}} | {{site-title}}',
|
|
|
|
'titleFormatTag'=> '{{tag-name}} | {{site-title}}'
|
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)
|
|
|
|
{
|
2018-07-28 21:00:12 +02:00
|
|
|
// Check values on args or set default values
|
|
|
|
foreach ($this->dbFields as $field=>$value) {
|
|
|
|
if (isset($args[$field])) {
|
|
|
|
// Sanitize if will be stored on database
|
|
|
|
$finalValue = Sanitize::html($args[$field]);
|
|
|
|
settype($finalValue, gettype($value));
|
|
|
|
$this->db[$field] = $finalValue;
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
|
|
|
}
|
2017-05-21 22:01:44 +02:00
|
|
|
return $this->save();
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
|
|
|
|
2018-03-06 16:35:28 +01:00
|
|
|
// Returns an array with the URL filters
|
|
|
|
// Also, you can get the a particular filter
|
2016-01-29 17:10:53 +01:00
|
|
|
public function uriFilters($filter='')
|
2015-05-05 03:00:01 +02:00
|
|
|
{
|
2017-07-30 14:25:16 +02:00
|
|
|
$filters['admin'] = '/'.ADMIN_URI_FILTER;
|
2018-03-06 19:42:18 +01:00
|
|
|
$filters['page'] = $this->getField('uriPage');
|
|
|
|
$filters['tag'] = $this->getField('uriTag');
|
|
|
|
$filters['category'] = $this->getField('uriCategory');
|
2015-05-05 03:00:01 +02:00
|
|
|
|
2018-03-06 16:35:28 +01:00
|
|
|
if ($this->getField('uriBlog')) {
|
|
|
|
$filters['blog'] = $this->getField('uriBlog');
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2018-03-06 19:42:18 +01:00
|
|
|
if (isset($filters[$filter])) {
|
|
|
|
return $filters[$filter];
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
|
|
|
|
2017-06-04 22:08:20 +02:00
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2018-07-07 12:04:34 +02:00
|
|
|
public function autosaveInterval()
|
|
|
|
{
|
|
|
|
return $this->getField('autosaveInterval');
|
|
|
|
}
|
|
|
|
|
2018-04-22 17:45:31 +02:00
|
|
|
public function extremeFriendly()
|
|
|
|
{
|
|
|
|
return $this->getField('extremeFriendly');
|
|
|
|
}
|
|
|
|
|
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');
|
|
|
|
}
|
2018-07-07 12:04:34 +02:00
|
|
|
|
2018-06-24 13:37:45 +02:00
|
|
|
public function gitlab()
|
|
|
|
{
|
|
|
|
return $this->getField('gitlab');
|
|
|
|
}
|
2016-02-14 01:15:19 +01:00
|
|
|
|
|
|
|
public function googlePlus()
|
|
|
|
{
|
|
|
|
return $this->getField('googlePlus');
|
|
|
|
}
|
|
|
|
|
2018-03-05 10:57:02 +01:00
|
|
|
public function linkedin()
|
|
|
|
{
|
|
|
|
return $this->getField('linkedin');
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
2015-11-14 17:47:26 +01:00
|
|
|
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');
|
2015-11-14 17:47:26 +01:00
|
|
|
}
|
|
|
|
|
2017-05-09 00:24:15 +02:00
|
|
|
// Returns the site description
|
2016-01-29 17:07:29 +01:00
|
|
|
public function description()
|
2015-11-14 17:47:26 +01:00
|
|
|
{
|
2016-01-29 17:07:29 +01:00
|
|
|
return $this->getField('description');
|
2015-11-14 17:47:26 +01:00
|
|
|
}
|
|
|
|
|
2016-01-29 17:07:29 +01:00
|
|
|
public function emailFrom()
|
2015-11-14 17:47:26 +01:00
|
|
|
{
|
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()
|
|
|
|
{
|
2015-11-14 17:47:26 +01:00
|
|
|
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()
|
|
|
|
{
|
2015-11-14 17:47:26 +01:00
|
|
|
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()
|
|
|
|
{
|
2015-11-14 17:47:26 +01:00
|
|
|
return $this->getField('footer');
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
|
|
|
|
2018-07-13 18:30:42 +02:00
|
|
|
public function titleFormatPages()
|
|
|
|
{
|
|
|
|
return $this->getField('titleFormatPages');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function titleFormatHomepage()
|
|
|
|
{
|
|
|
|
return $this->getField('titleFormatHomepage');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function titleFormatCategory()
|
|
|
|
{
|
|
|
|
return $this->getField('titleFormatCategory');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function titleFormatTag()
|
|
|
|
{
|
|
|
|
return $this->getField('titleFormatTag');
|
|
|
|
}
|
|
|
|
|
2017-05-09 00:24:15 +02:00
|
|
|
// Returns the full domain and base url
|
2017-05-29 23:56:07 +02:00
|
|
|
// For example, https://www.domain.com/bludit
|
2015-05-05 03:00:01 +02:00
|
|
|
public function url()
|
|
|
|
{
|
2015-11-14 17:47:26 +01:00
|
|
|
return $this->getField('url');
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
|
|
|
|
2018-07-13 18:30:42 +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
|
2015-11-28 15:47:03 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-10-18 18:21:44 +02:00
|
|
|
// Parse the domain from the field url (Settings->Advanced)
|
2015-11-28 15:47:03 +01:00
|
|
|
$parse = parse_url($this->url());
|
2017-10-18 18:21:44 +02:00
|
|
|
$domain = rtrim($parse['host'], '/');
|
|
|
|
$port = !empty($parse['port']) ? ':'.$parse['port'] : '';
|
|
|
|
$scheme = !empty($parse['scheme']) ? $parse['scheme'].'://' : 'http://';
|
2016-01-11 23:51:00 +01:00
|
|
|
|
2017-10-18 18:21:44 +02:00
|
|
|
return $scheme.$domain.$port;
|
2015-11-28 15:47:03 +01:00
|
|
|
}
|
|
|
|
|
2015-05-05 03:00:01 +02:00
|
|
|
// Returns the timezone.
|
|
|
|
public function timezone()
|
|
|
|
{
|
2015-11-14 17:47:26 +01:00
|
|
|
return $this->getField('timezone');
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
|
|
|
|
2015-11-20 04:21:39 +01: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()
|
|
|
|
{
|
2015-11-14 17:47:26 +01:00
|
|
|
return $this->getField('language');
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the current locale.
|
|
|
|
public function locale()
|
|
|
|
{
|
2015-11-14 17:47:26 +01:00
|
|
|
return $this->getField('locale');
|
2015-05-05 03:00:01 +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
|
|
|
}
|
|
|
|
|
2018-07-17 19:13:01 +02:00
|
|
|
// Returns the page key for the page not found
|
2017-09-04 19:09:37 +02:00
|
|
|
public function pageNotFound()
|
|
|
|
{
|
|
|
|
$pageNotFound = $this->getField('pageNotFound');
|
|
|
|
return $pageNotFound;
|
|
|
|
}
|
|
|
|
|
2017-09-03 23:29:09 +02:00
|
|
|
// Set the locale, returns TRUE is success, FALSE otherwise
|
2015-05-05 03:00:01 +02:00
|
|
|
public function setLocale($locale)
|
|
|
|
{
|
2017-09-03 23:29:09 +02:00
|
|
|
$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
|
|
|
|
2017-09-03 23:29:09 +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);
|
|
|
|
}
|
|
|
|
|
2018-06-24 13:37:45 +02:00
|
|
|
}
|