removing posts
This commit is contained in:
parent
16daff6abd
commit
22898c5c6c
@ -52,6 +52,10 @@ define('DEBUG_FILE', PATH_CONTENT.'debug.txt');
|
||||
|
||||
// PAGES DATABASE
|
||||
define('DB_PAGES', PATH_DATABASES.'pages.php');
|
||||
define('DB_SITE', PATH_DATABASES.'site.php');
|
||||
|
||||
// ADMIN URI FILTER
|
||||
define('ADMIN_URI_FILTER', '/admin/');
|
||||
|
||||
// Log separator
|
||||
define('LOG_SEP', ' | ');
|
||||
|
60
bl-kernel/boot/rules/69.pages.php
Normal file
60
bl-kernel/boot/rules/69.pages.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
||||
|
||||
// ============================================================================
|
||||
// Variables
|
||||
// ============================================================================
|
||||
|
||||
// Array with all published pages
|
||||
$pages = array();
|
||||
|
||||
// Array with all pages (published, draft, scheduled)
|
||||
$allPages = array();
|
||||
|
||||
// Object Page for the page filtered bye the user
|
||||
$page = false;
|
||||
|
||||
// ============================================================================
|
||||
// Main
|
||||
// ============================================================================
|
||||
|
||||
// Execute the scheduler
|
||||
if( $dbPages->scheduler() ) {
|
||||
// Reindex tags
|
||||
reindexTags();
|
||||
|
||||
// Reindex categories
|
||||
reindexCategories();
|
||||
}
|
||||
|
||||
// Build specific page
|
||||
if( $Url->whereAmI()==='page' ) {
|
||||
|
||||
// Build the page
|
||||
$page = buildPage( $Url->slug() );
|
||||
|
||||
// The page doesn't exist
|
||||
if($page===false) {
|
||||
$Url->setNotFound(true);
|
||||
}
|
||||
// The page is not published
|
||||
elseif( !$page->published() ) {
|
||||
$Url->setNotFound(true);
|
||||
}
|
||||
}
|
||||
elseif( $Url->whereAmI()==='tag' ) {
|
||||
$pages = buildPagesByTag( $Url->slug() );
|
||||
}
|
||||
elseif( $Url->whereAmI()==='category' ) {
|
||||
$pages = buildPagesByCategory( $Url->slug() );
|
||||
}
|
||||
elseif( $Url->whereAmI()==='home' ) {
|
||||
$pages = buildPagesForHome( $Url->slug() );
|
||||
}
|
||||
elseif( $Url->whereAmI()==='admin' ) {
|
||||
$pages = buildPagesForAdmin( $Url->slug() );
|
||||
}
|
||||
|
||||
if( $Url->notFound() ) {
|
||||
$Url->setWhereAmI('page');
|
||||
$page = new Page('error');
|
||||
}
|
@ -360,14 +360,15 @@ class dbPages extends dbJSON
|
||||
$currentDate = Date::current(DB_DATE_FORMAT);
|
||||
$saveDatabase = false;
|
||||
|
||||
foreach($this->db as $postKey=>$values) {
|
||||
if($values['status']=='scheduled') {
|
||||
if($values['date']<=$currentDate) {
|
||||
$this->db[$postKey]['status'] = 'published';
|
||||
// The database need to be sorted by date
|
||||
foreach($this->db as $pageKey=>$fields) {
|
||||
if($fields['status']=='scheduled') {
|
||||
if($fields['date']<=$currentDate) {
|
||||
$this->db[$pageKey]['status'] = 'published';
|
||||
$saveDatabase = true;
|
||||
}
|
||||
}
|
||||
elseif($values['status']=='published') {
|
||||
elseif($fields['status']=='published') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -378,7 +379,7 @@ class dbPages extends dbJSON
|
||||
return false;
|
||||
}
|
||||
|
||||
Log::set(__METHOD__.LOG_SEP.'New posts published from the scheduler.');
|
||||
Log::set(__METHOD__.LOG_SEP.'New pages published from the scheduler.');
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ class dbSite extends dbJSON
|
||||
'slogan'=> array('inFile'=>false, 'value'=>''),
|
||||
'description'=> array('inFile'=>false, 'value'=>''),
|
||||
'footer'=> array('inFile'=>false, 'value'=>'I wanna be a pirate!'),
|
||||
'postsperpage'=> array('inFile'=>false, 'value'=>''),
|
||||
'itemsPerPage'=> array('inFile'=>false, 'value'=>''),
|
||||
'language'=> array('inFile'=>false, 'value'=>'en'),
|
||||
'locale'=> array('inFile'=>false, 'value'=>'en_US'),
|
||||
'timezone'=> array('inFile'=>false, 'value'=>'America/Argentina/Buenos_Aires'),
|
||||
@ -15,9 +15,7 @@ class dbSite extends dbJSON
|
||||
'adminTheme'=> array('inFile'=>false, 'value'=>'default'),
|
||||
'homepage'=> array('inFile'=>false, 'value'=>''),
|
||||
'uriPage'=> array('inFile'=>false, 'value'=>'/'),
|
||||
'uriPost'=> array('inFile'=>false, 'value'=>'/post/'),
|
||||
'uriTag'=> array('inFile'=>false, 'value'=>'/tag/'),
|
||||
'uriBlog'=> array('inFile'=>false, 'value'=>'/blog/'),
|
||||
'uriCategory'=> array('inFile'=>false, 'value'=>'/category/'),
|
||||
'url'=> array('inFile'=>false, 'value'=>''),
|
||||
'emailFrom'=> array('inFile'=>false, 'value'=>''),
|
||||
@ -33,7 +31,7 @@ class dbSite extends dbJSON
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct(PATH_DATABASES.'site.php');
|
||||
parent::__construct(DB_SITE);
|
||||
|
||||
// Set timezone
|
||||
$this->setTimezone( $this->timezone() );
|
||||
@ -66,14 +64,13 @@ class dbSite extends dbJSON
|
||||
return true;
|
||||
}
|
||||
|
||||
// Returns an array with the filters for the url.
|
||||
// Returns an array with the filters for the url
|
||||
// or returns a string with the filter defined on $filter
|
||||
public function uriFilters($filter='')
|
||||
{
|
||||
$filters['admin'] = '/admin/';
|
||||
$filters['post'] = $this->getField('uriPost');
|
||||
$filters['admin'] = ADMIN_URI_FILTER;
|
||||
$filters['page'] = $this->getField('uriPage');
|
||||
$filters['tag'] = $this->getField('uriTag');
|
||||
$filters['blog'] = $this->getField('uriBlog');
|
||||
$filters['category'] = $this->getField('uriCategory');
|
||||
|
||||
if(empty($filter)) {
|
||||
@ -83,12 +80,6 @@ class dbSite extends dbJSON
|
||||
return $filters[$filter];
|
||||
}
|
||||
|
||||
public function urlPost()
|
||||
{
|
||||
$filter = $this->getField('uriPost');
|
||||
return $this->url().ltrim($filter, '/');
|
||||
}
|
||||
|
||||
public function urlPage()
|
||||
{
|
||||
$filter = $this->getField('uriPage');
|
||||
@ -101,12 +92,6 @@ class dbSite extends dbJSON
|
||||
return $this->url().ltrim($filter, '/');
|
||||
}
|
||||
|
||||
public function urlBlog()
|
||||
{
|
||||
$filter = $this->getField('uriBlog');
|
||||
return $this->url().ltrim($filter, '/');
|
||||
}
|
||||
|
||||
public function urlCategory()
|
||||
{
|
||||
$filter = $this->getField('uriCategory');
|
||||
@ -138,19 +123,19 @@ class dbSite extends dbJSON
|
||||
return $this->getField('googlePlus');
|
||||
}
|
||||
|
||||
// Returns the site title.
|
||||
// Returns the site title
|
||||
public function title()
|
||||
{
|
||||
return $this->getField('title');
|
||||
}
|
||||
|
||||
// Returns the site slogan.
|
||||
// Returns the site slogan
|
||||
public function slogan()
|
||||
{
|
||||
return $this->getField('slogan');
|
||||
}
|
||||
|
||||
// Returns the site description.
|
||||
// Returns the site description
|
||||
public function description()
|
||||
{
|
||||
return $this->getField('description');
|
||||
@ -171,38 +156,37 @@ class dbSite extends dbJSON
|
||||
return $this->getField('timeFormat');
|
||||
}
|
||||
|
||||
// Returns the site theme name.
|
||||
// Returns the site theme name
|
||||
public function theme()
|
||||
{
|
||||
return $this->getField('theme');
|
||||
}
|
||||
|
||||
// Returns the admin theme name.
|
||||
// Returns the admin theme name
|
||||
public function adminTheme()
|
||||
{
|
||||
return $this->getField('adminTheme');
|
||||
}
|
||||
|
||||
// Returns the footer text.
|
||||
// Returns the footer text
|
||||
public function footer()
|
||||
{
|
||||
return $this->getField('footer');
|
||||
}
|
||||
|
||||
// Returns the full domain and base url.
|
||||
// For example, http://www.domain.com/bludit/
|
||||
// Returns the full domain and base url
|
||||
// For example, https://www.domain.com/bludit/
|
||||
public function url()
|
||||
{
|
||||
return $this->getField('url');
|
||||
}
|
||||
|
||||
// Returns the protocol and the domain, without the base url.
|
||||
// Returns the protocol and the domain, without the base url
|
||||
// For example, http://www.domain.com
|
||||
public function domain()
|
||||
{
|
||||
// If the URL field is not set, try detect the domain.
|
||||
if(Text::isEmpty( $this->url() ))
|
||||
{
|
||||
if(Text::isEmpty( $this->url() )) {
|
||||
if(!empty($_SERVER['HTTPS'])) {
|
||||
$protocol = 'https://';
|
||||
}
|
||||
@ -211,13 +195,11 @@ class dbSite extends dbJSON
|
||||
}
|
||||
|
||||
$domain = trim($_SERVER['HTTP_HOST'], '/');
|
||||
|
||||
return $protocol.$domain;
|
||||
}
|
||||
|
||||
// Parse the domain from the field URL.
|
||||
$parse = parse_url($this->url());
|
||||
|
||||
$domain = trim($parse['host'], '/');
|
||||
|
||||
return $parse['scheme'].'://'.$domain;
|
||||
@ -241,10 +223,10 @@ class dbSite extends dbJSON
|
||||
return $this->getField('currentBuild');
|
||||
}
|
||||
|
||||
// Returns posts per page.
|
||||
public function postsPerPage()
|
||||
// Returns the amount of pages per page
|
||||
public function itemsPerPage()
|
||||
{
|
||||
return $this->getField('postsperpage');
|
||||
return $this->getField('itemsPerPage');
|
||||
}
|
||||
|
||||
// Returns the current language.
|
||||
|
@ -1,5 +1,62 @@
|
||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
||||
|
||||
function buildPage($key)
|
||||
{
|
||||
global $dbPages;
|
||||
global $dbUsers;
|
||||
global $Parsedown;
|
||||
global $Site;
|
||||
|
||||
// Page object, content from FILE
|
||||
$Page = new Page($key);
|
||||
if( !$Page->isValid() ) {
|
||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying build the page from file with key: '.$key);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Page database, content from DATABASE JSON.
|
||||
$db = $dbPages->getPageDB($key);
|
||||
if( !$db ) {
|
||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying build the page from database with key: '.$key);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Foreach field from DATABASE.
|
||||
foreach($db as $field=>$value) {
|
||||
$Page->setField($field, $value);
|
||||
}
|
||||
|
||||
// Content in raw format
|
||||
$contentRaw = $Page->content();
|
||||
$Page->setField('contentRaw', $Page->content(), true);
|
||||
|
||||
// Parse markdown content.
|
||||
$content = Text::pre2htmlentities($contentRaw); // Parse pre code with htmlentities
|
||||
$content = $Parsedown->text($content); // Parse Markdown.
|
||||
$content = Text::imgRel2Abs($content, HTML_PATH_UPLOADS); // Parse img src relative to absolute.
|
||||
$Page->setField('content', $content, true);
|
||||
|
||||
// Pagebrake
|
||||
$explode = explode(PAGE_BREAK, $content);
|
||||
$Page->setField('breakContent', $explode[0], true);
|
||||
$Page->setField('readMore', !empty($explode[1]), true);
|
||||
|
||||
// Date format
|
||||
$pageDate = $Page->date();
|
||||
$Page->setField('dateRaw', $pageDate, true);
|
||||
|
||||
$pageDateFormated = $Page->dateRaw( $Site->dateFormat() );
|
||||
$Page->setField('date', $pageDateFormated, true);
|
||||
|
||||
// User object
|
||||
$username = $Page->username();
|
||||
$Page->setField('user', $dbUsers->getUser($username));
|
||||
|
||||
return $Page;
|
||||
}
|
||||
|
||||
// ---- OLD
|
||||
|
||||
// POST FUNCTIONS
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@ -153,60 +210,7 @@ function reIndexCategoriesPages()
|
||||
return true;
|
||||
}
|
||||
|
||||
function buildPage($key)
|
||||
{
|
||||
global $dbPages;
|
||||
global $dbUsers;
|
||||
global $Parsedown;
|
||||
global $Site;
|
||||
|
||||
// Page object, content from FILE.
|
||||
$Page = new Page($key);
|
||||
if( !$Page->isValid() ) {
|
||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying build the page from file with key: '.$key);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Page database, content from DATABASE JSON.
|
||||
$db = $dbPages->getPageDB($key);
|
||||
if( !$db ) {
|
||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying build the page from database with key: '.$key);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Foreach field from DATABASE.
|
||||
foreach($db as $field=>$value) {
|
||||
$Page->setField($field, $value);
|
||||
}
|
||||
|
||||
// Content in raw format
|
||||
$contentRaw = $Page->content();
|
||||
$Page->setField('contentRaw', $Page->content(), true);
|
||||
|
||||
// Parse markdown content.
|
||||
$content = Text::pre2htmlentities($contentRaw); // Parse pre code with htmlentities
|
||||
$content = $Parsedown->text($content); // Parse Markdown.
|
||||
$content = Text::imgRel2Abs($content, HTML_PATH_UPLOADS); // Parse img src relative to absolute.
|
||||
$Page->setField('content', $content, true);
|
||||
|
||||
// Pagebrake
|
||||
$explode = explode(PAGE_BREAK, $content);
|
||||
$Page->setField('breakContent', $explode[0], true);
|
||||
$Page->setField('readMore', !empty($explode[1]), true);
|
||||
|
||||
// Date format
|
||||
$pageDate = $Page->date();
|
||||
$Page->setField('dateRaw', $pageDate, true);
|
||||
|
||||
$pageDateFormated = $Page->dateRaw( $Site->dateFormat() );
|
||||
$Page->setField('date', $pageDateFormated, true);
|
||||
|
||||
// User object
|
||||
$username = $Page->username();
|
||||
$Page->setField('user', $dbUsers->getUser($username));
|
||||
|
||||
return $Page;
|
||||
}
|
||||
|
||||
function buildAllPages()
|
||||
{
|
||||
|
@ -16,22 +16,15 @@ class Url
|
||||
// Decodes any %## encoding in the given string. Plus symbols ('+') are decoded to a space character.
|
||||
$decode = urldecode($_SERVER['REQUEST_URI']);
|
||||
|
||||
// remove parameters GET, do not use parse_url because has problem with utf-8.
|
||||
// Remove parameters GET, I don't use parse_url because has problem with utf-8
|
||||
$explode = explode('?', $decode);
|
||||
$this->uri = $explode[0];
|
||||
|
||||
$this->parameters = $_GET;
|
||||
|
||||
$this->uriStrlen = Text::length($this->uri);
|
||||
|
||||
$this->whereAmI = 'home';
|
||||
|
||||
$this->notFound = false;
|
||||
|
||||
$this->slug = '';
|
||||
|
||||
$this->filters = array();
|
||||
|
||||
$this->activeFilter = '';
|
||||
}
|
||||
|
||||
@ -40,7 +33,7 @@ class Url
|
||||
// Ex (English): Array('post'=>'/post/', 'tag'=>'/tag/', ....)
|
||||
public function checkFilters($filters)
|
||||
{
|
||||
// Get the admin filter
|
||||
// Store the admin filter and remove
|
||||
$adminFilter['admin'] = $filters['admin'];
|
||||
unset($filters['admin']);
|
||||
|
||||
@ -51,34 +44,25 @@ class Url
|
||||
$filters = $adminFilter + $filters;
|
||||
$this->filters = $filters;
|
||||
|
||||
foreach($filters as $filterName=>$filterURI)
|
||||
{
|
||||
// $slug will be FALSE if the filter is not included in the URI.
|
||||
foreach($filters as $filterName=>$filterURI) {
|
||||
|
||||
// $slug will be FALSE if the filter is not included in the URI
|
||||
$slug = $this->getSlugAfterFilter($filterURI);
|
||||
|
||||
if($slug!==false)
|
||||
{
|
||||
if($slug!==false) {
|
||||
$this->slug = $slug;
|
||||
$this->whereAmI = $filterName;
|
||||
$this->activeFilter = $filterURI;
|
||||
|
||||
// If the slug is empty
|
||||
if(Text::isEmpty($slug))
|
||||
{
|
||||
if($filterURI==='/')
|
||||
{
|
||||
if( Text::isEmpty($slug) ) {
|
||||
|
||||
if($filterURI==='/') {
|
||||
$this->whereAmI = 'home';
|
||||
break;
|
||||
}
|
||||
|
||||
if($filterURI===$filters['blog'])
|
||||
{
|
||||
$this->whereAmI = 'blog';
|
||||
break;
|
||||
}
|
||||
|
||||
if($filterURI===$adminFilter['admin'])
|
||||
{
|
||||
if($filterURI===$adminFilter['admin']) {
|
||||
$this->whereAmI = 'admin';
|
||||
$this->slug = 'dashboard';
|
||||
break;
|
||||
@ -124,7 +108,7 @@ class Url
|
||||
return $filter;
|
||||
}
|
||||
|
||||
// Return: home, tag, post
|
||||
// Returns where is the user, home, pages, categories, tags..
|
||||
public function whereAmI()
|
||||
{
|
||||
return $this->whereAmI;
|
||||
@ -148,7 +132,7 @@ class Url
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function setNotFound($error = true)
|
||||
public function setNotFound($error=true)
|
||||
{
|
||||
$this->notFound = $error;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user