Improvements on tags
This commit is contained in:
parent
1c1cc786ad
commit
0c70da532b
|
@ -16,8 +16,10 @@
|
||||||
// Main after POST
|
// Main after POST
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
$_newPosts = $dbPosts->regenerate();
|
//$_newPosts = $dbPosts->regenerateCli();
|
||||||
$_newPages = $dbPages->regenerate();
|
//$_newPages = $dbPages->regenerateCli();
|
||||||
|
|
||||||
|
$_newPages = $_newPosts = array();
|
||||||
|
|
||||||
$_draftPosts = array();
|
$_draftPosts = array();
|
||||||
foreach($posts as $Post)
|
foreach($posts as $Post)
|
||||||
|
|
|
@ -24,9 +24,7 @@ function editPage($args)
|
||||||
// Edit the page.
|
// Edit the page.
|
||||||
if( $dbPages->edit($args) )
|
if( $dbPages->edit($args) )
|
||||||
{
|
{
|
||||||
$dbPages->regenerate();
|
$dbPages->regenerateCli();
|
||||||
|
|
||||||
//$dbTags->reindexPages( $dbPages->db );
|
|
||||||
|
|
||||||
Alert::set($Language->g('The changes have been saved'));
|
Alert::set($Language->g('The changes have been saved'));
|
||||||
Redirect::page('admin', 'edit-page/'.$args['key']);
|
Redirect::page('admin', 'edit-page/'.$args['key']);
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// Check role
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Functions
|
// Functions
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
@ -7,7 +11,6 @@
|
||||||
function editPost($args)
|
function editPost($args)
|
||||||
{
|
{
|
||||||
global $dbPosts;
|
global $dbPosts;
|
||||||
global $dbTags;
|
|
||||||
global $Language;
|
global $Language;
|
||||||
|
|
||||||
// Post status, published or draft.
|
// Post status, published or draft.
|
||||||
|
@ -21,10 +24,8 @@ function editPost($args)
|
||||||
// Edit the post.
|
// Edit the post.
|
||||||
if( $dbPosts->edit($args) )
|
if( $dbPosts->edit($args) )
|
||||||
{
|
{
|
||||||
// Regenerate the database tags
|
// Reindex tags, this function is in 70.posts.php
|
||||||
$dbPosts->removeUnpublished();
|
reIndexTagsPosts();
|
||||||
$dbPosts->sortByDate();
|
|
||||||
$dbTags->reindexPosts( $dbPosts->db );
|
|
||||||
|
|
||||||
Alert::set($Language->g('The changes have been saved'));
|
Alert::set($Language->g('The changes have been saved'));
|
||||||
Redirect::page('admin', 'edit-post/'.$args['key']);
|
Redirect::page('admin', 'edit-post/'.$args['key']);
|
||||||
|
@ -33,18 +34,19 @@ function editPost($args)
|
||||||
{
|
{
|
||||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to edit the post.');
|
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to edit the post.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function deletePost($key)
|
function deletePost($key)
|
||||||
{
|
{
|
||||||
global $dbPosts;
|
global $dbPosts;
|
||||||
global $dbTags;
|
|
||||||
global $Language;
|
global $Language;
|
||||||
|
|
||||||
if( $dbPosts->delete($key) )
|
if( $dbPosts->delete($key) )
|
||||||
{
|
{
|
||||||
// Regenerate the database tags
|
// Reindex tags, this function is in 70.posts.php
|
||||||
$dbTags->reindexPosts( $dbPosts->db );
|
reIndexTagsPosts();
|
||||||
|
|
||||||
Alert::set($Language->g('The post has been deleted successfully'));
|
Alert::set($Language->g('The post has been deleted successfully'));
|
||||||
Redirect::page('admin', 'manage-posts');
|
Redirect::page('admin', 'manage-posts');
|
||||||
|
|
|
@ -24,8 +24,6 @@ function addPage($args)
|
||||||
// Add the page.
|
// Add the page.
|
||||||
if( $dbPages->add($args) )
|
if( $dbPages->add($args) )
|
||||||
{
|
{
|
||||||
//$dbTags->reindexPages( $dbPages->db );
|
|
||||||
|
|
||||||
Alert::set($Language->g('Page added successfully'));
|
Alert::set($Language->g('Page added successfully'));
|
||||||
Redirect::page('admin', 'manage-pages');
|
Redirect::page('admin', 'manage-pages');
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
function addPost($args)
|
function addPost($args)
|
||||||
{
|
{
|
||||||
global $dbPosts;
|
global $dbPosts;
|
||||||
global $dbTags;
|
|
||||||
global $Language;
|
global $Language;
|
||||||
|
|
||||||
// Page status, published or draft.
|
// Page status, published or draft.
|
||||||
|
@ -25,10 +24,8 @@ function addPost($args)
|
||||||
// Add the page.
|
// Add the page.
|
||||||
if( $dbPosts->add($args) )
|
if( $dbPosts->add($args) )
|
||||||
{
|
{
|
||||||
// Regenerate the database tags
|
// Reindex tags, this function is in 70.posts.php
|
||||||
$dbPosts->removeUnpublished();
|
reIndexTagsPosts();
|
||||||
$dbPosts->sortByDate();
|
|
||||||
$dbTags->reindexPosts( $dbPosts->db );
|
|
||||||
|
|
||||||
Alert::set($Language->g('Post added successfully'));
|
Alert::set($Language->g('Post added successfully'));
|
||||||
Redirect::page('admin', 'manage-posts');
|
Redirect::page('admin', 'manage-posts');
|
||||||
|
@ -37,6 +34,8 @@ function addPost($args)
|
||||||
{
|
{
|
||||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to create the post.');
|
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to create the post.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
13
features.txt
13
features.txt
|
@ -38,10 +38,23 @@ Si cambia el parent
|
||||||
verificar parent
|
verificar parent
|
||||||
mover directorio adentro del parent
|
mover directorio adentro del parent
|
||||||
|
|
||||||
|
—————————
|
||||||
|
Nuevo post
|
||||||
|
- Reindex dbtags
|
||||||
|
|
||||||
|
—————————
|
||||||
|
|
||||||
Editar usuario
|
Editar usuario
|
||||||
1- Usuario logueado
|
1- Usuario logueado
|
||||||
2- Ver si el usuario es administrador o si es el mismo usuario que se esta editando.
|
2- Ver si el usuario es administrador o si es el mismo usuario que se esta editando.
|
||||||
|
|
||||||
|
—————————
|
||||||
|
dbTags
|
||||||
|
Regenerate posts list
|
||||||
|
- Al momento de regenerarla deberia enviarle la lista de post ordenada por fecha.
|
||||||
|
- De esta forma la estructura esta ordenada para mostrarla.
|
||||||
|
- El que hace el trabajo es el administrador
|
||||||
|
|
||||||
—————————
|
—————————
|
||||||
New post->Publish->Manage posts
|
New post->Publish->Manage posts
|
||||||
New page->Publish->Manage pages
|
New page->Publish->Manage pages
|
||||||
|
|
62
install.php
62
install.php
|
@ -69,7 +69,7 @@ include(PATH_KERNEL.'dblanguage.class.php');
|
||||||
include(PATH_HELPERS.'log.class.php');
|
include(PATH_HELPERS.'log.class.php');
|
||||||
include(PATH_HELPERS.'date.class.php');
|
include(PATH_HELPERS.'date.class.php');
|
||||||
|
|
||||||
// Try detect locale/language from HTTP
|
// Try to detect language from HTTP
|
||||||
$explode = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
$explode = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
||||||
$localeFromHTTP = empty($explode[0])?'en_US':str_replace('-', '_', $explode[0]);
|
$localeFromHTTP = empty($explode[0])?'en_US':str_replace('-', '_', $explode[0]);
|
||||||
|
|
||||||
|
@ -193,13 +193,19 @@ function install($adminPassword, $email)
|
||||||
|
|
||||||
if(!mkdir(PATH_PLUGINS_DATABASES.'pages', $dirpermissions, true))
|
if(!mkdir(PATH_PLUGINS_DATABASES.'pages', $dirpermissions, true))
|
||||||
{
|
{
|
||||||
$errorText = 'Error when trying to created the directory=>'.PATH_PLUGINS_DATABASES;
|
$errorText = 'Error when trying to created the directory=>'.PATH_PLUGINS_DATABASES.'pages';
|
||||||
error_log($errorText, 0);
|
error_log($errorText, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!mkdir(PATH_PLUGINS_DATABASES.'simplemde', $dirpermissions, true))
|
if(!mkdir(PATH_PLUGINS_DATABASES.'simplemde', $dirpermissions, true))
|
||||||
{
|
{
|
||||||
$errorText = 'Error when trying to created the directory=>'.PATH_PLUGINS_DATABASES;
|
$errorText = 'Error when trying to created the directory=>'.PATH_PLUGINS_DATABASES.'simplemde';
|
||||||
|
error_log($errorText, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!mkdir(PATH_PLUGINS_DATABASES.'tags', $dirpermissions, true))
|
||||||
|
{
|
||||||
|
$errorText = 'Error when trying to created the directory=>'.PATH_PLUGINS_DATABASES.'tags';
|
||||||
error_log($errorText, 0);
|
error_log($errorText, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,14 +297,36 @@ function install($adminPassword, $email)
|
||||||
|
|
||||||
file_put_contents(PATH_DATABASES.'security.php', $dataHead.json_encode($data, JSON_PRETTY_PRINT), LOCK_EX);
|
file_put_contents(PATH_DATABASES.'security.php', $dataHead.json_encode($data, JSON_PRETTY_PRINT), LOCK_EX);
|
||||||
|
|
||||||
// File plugins/pages/db.php
|
// File tags.php
|
||||||
$data = array(
|
file_put_contents(
|
||||||
'homeLink'=>true,
|
PATH_DATABASES.'tags.php',
|
||||||
'label'=>$Language->get('Pages'),
|
$dataHead.json_encode(
|
||||||
'position'=>'0'
|
array(
|
||||||
|
'postsIndex'=>array(
|
||||||
|
'bludit'=>array('name'=>'Bludit', 'posts'=>array('first-post')),
|
||||||
|
'cms'=>array('name'=>'cms', 'posts'=>array('first-post'))
|
||||||
|
),
|
||||||
|
'pagesIndex'=>array()
|
||||||
|
),
|
||||||
|
JSON_PRETTY_PRINT),
|
||||||
|
LOCK_EX
|
||||||
);
|
);
|
||||||
|
|
||||||
file_put_contents(PATH_PLUGINS_DATABASES.'pages'.DS.'db.php', $dataHead.json_encode($data, JSON_PRETTY_PRINT), LOCK_EX);
|
|
||||||
|
// PLUGINS
|
||||||
|
|
||||||
|
// File plugins/pages/db.php
|
||||||
|
file_put_contents(
|
||||||
|
PATH_PLUGINS_DATABASES.'pages'.DS.'db.php',
|
||||||
|
$dataHead.json_encode(
|
||||||
|
array(
|
||||||
|
'position'=>0,
|
||||||
|
'homeLink'=>true,
|
||||||
|
'label'=>$Language->get('Pages')
|
||||||
|
),
|
||||||
|
JSON_PRETTY_PRINT),
|
||||||
|
LOCK_EX
|
||||||
|
);
|
||||||
|
|
||||||
// File plugins/simplemde/db.php
|
// File plugins/simplemde/db.php
|
||||||
file_put_contents(
|
file_put_contents(
|
||||||
|
@ -311,14 +339,18 @@ function install($adminPassword, $email)
|
||||||
LOCK_EX
|
LOCK_EX
|
||||||
);
|
);
|
||||||
|
|
||||||
// File tags.php
|
// File plugins/tags/db.php
|
||||||
$data = array(
|
file_put_contents(
|
||||||
'postsIndex'=>array(),
|
PATH_PLUGINS_DATABASES.'tags'.DS.'db.php',
|
||||||
'pagesIndex'=>array()
|
$dataHead.json_encode(
|
||||||
|
array(
|
||||||
|
'position'=>0,
|
||||||
|
'label'=>$Language->get('Tags')
|
||||||
|
),
|
||||||
|
JSON_PRETTY_PRINT),
|
||||||
|
LOCK_EX
|
||||||
);
|
);
|
||||||
|
|
||||||
file_put_contents(PATH_DATABASES.'tags.php', $dataHead.json_encode($data, JSON_PRETTY_PRINT), LOCK_EX);
|
|
||||||
|
|
||||||
// File index.txt for error page
|
// File index.txt for error page
|
||||||
$data = 'Title: '.$Language->get('Error').'
|
$data = 'Title: '.$Language->get('Error').'
|
||||||
Content: '.$Language->get('The page has not been found');
|
Content: '.$Language->get('The page has not been found');
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
class dbJSON
|
class dbJSON
|
||||||
{
|
{
|
||||||
public $db;
|
public $db;
|
||||||
|
public $dbBackup;
|
||||||
public $file;
|
public $file;
|
||||||
public $firstLine;
|
public $firstLine;
|
||||||
|
|
||||||
|
@ -12,6 +13,7 @@ class dbJSON
|
||||||
{
|
{
|
||||||
$this->file = $file;
|
$this->file = $file;
|
||||||
$this->db = array();
|
$this->db = array();
|
||||||
|
$this->dbBackup = array();
|
||||||
$this->firstLine = $firstLine;
|
$this->firstLine = $firstLine;
|
||||||
|
|
||||||
if(file_exists($file))
|
if(file_exists($file))
|
||||||
|
@ -35,6 +37,7 @@ class dbJSON
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$this->db = $array;
|
$this->db = $array;
|
||||||
|
$this->dbBackup = $array;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -43,6 +46,12 @@ class dbJSON
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function restoreDb()
|
||||||
|
{
|
||||||
|
$this->db = $this->dbBackup;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Returns the amount of database items.
|
// Returns the amount of database items.
|
||||||
public function count()
|
public function count()
|
||||||
{
|
{
|
||||||
|
|
|
@ -39,8 +39,8 @@ if( $layout['slug']==='ajax' )
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Boot rules
|
// Boot rules
|
||||||
include(PATH_RULES.'70.build_posts.php');
|
include(PATH_RULES.'70.posts.php');
|
||||||
include(PATH_RULES.'70.build_pages.php');
|
include(PATH_RULES.'70.pages.php');
|
||||||
include(PATH_RULES.'80.plugins.php');
|
include(PATH_RULES.'80.plugins.php');
|
||||||
include(PATH_RULES.'99.header.php');
|
include(PATH_RULES.'99.header.php');
|
||||||
include(PATH_RULES.'99.paginator.php');
|
include(PATH_RULES.'99.paginator.php');
|
||||||
|
|
|
@ -10,6 +10,26 @@ $posts = array();
|
||||||
// Functions
|
// Functions
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
|
function reIndexTagsPosts()
|
||||||
|
{
|
||||||
|
global $dbPosts;
|
||||||
|
global $dbTags;
|
||||||
|
|
||||||
|
// Remove unpublished, only drafts.
|
||||||
|
$dbPosts->removeUnpublished(false);
|
||||||
|
|
||||||
|
// Sort posts
|
||||||
|
$dbPosts->sortByDate();
|
||||||
|
|
||||||
|
// Regenerate the tags index for posts
|
||||||
|
$dbTags->reindexPosts( $dbPosts->db );
|
||||||
|
|
||||||
|
// Restore de db on dbPost
|
||||||
|
$dbPosts->restoreDb();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function buildPost($key)
|
function buildPost($key)
|
||||||
{
|
{
|
||||||
global $dbPosts;
|
global $dbPosts;
|
||||||
|
@ -59,14 +79,13 @@ function buildPost($key)
|
||||||
$user = $dbUsers->getDb( $Post->username() );
|
$user = $dbUsers->getDb( $Post->username() );
|
||||||
|
|
||||||
$Post->setField('authorFirstName', $user['firstName'], false);
|
$Post->setField('authorFirstName', $user['firstName'], false);
|
||||||
|
|
||||||
$Post->setField('authorLastName', $user['lastName'], false);
|
$Post->setField('authorLastName', $user['lastName'], false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $Post;
|
return $Post;
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildPostForPage($pageNumber=0, $amount=5, $removeUnpublished=false, $tagKey=false)
|
function buildPostsForPage($pageNumber=0, $amount=POSTS_PER_PAGE_ADMIN, $removeUnpublished=true, $tagKey=false)
|
||||||
{
|
{
|
||||||
global $dbPosts;
|
global $dbPosts;
|
||||||
global $dbTags;
|
global $dbTags;
|
||||||
|
@ -74,34 +93,34 @@ function buildPostForPage($pageNumber=0, $amount=5, $removeUnpublished=false, $t
|
||||||
global $Url;
|
global $Url;
|
||||||
|
|
||||||
if($tagKey) {
|
if($tagKey) {
|
||||||
|
// Get the keys list from tags database, this database is optimized for this case.
|
||||||
$list = $dbTags->getList($pageNumber, $amount, $tagKey);
|
$list = $dbTags->getList($pageNumber, $amount, $tagKey);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// Get the keys list from posts database.
|
||||||
$list = $dbPosts->getList($pageNumber, $amount, $removeUnpublished);
|
$list = $dbPosts->getList($pageNumber, $amount, $removeUnpublished);
|
||||||
}
|
}
|
||||||
|
|
||||||
// There are not post for the pageNumber then set the page notfound
|
// There are not posts for the page number then set the page notfound
|
||||||
if(empty($list) && $pageNumber>0) {
|
if(empty($list) && $pageNumber>0) {
|
||||||
$Url->setNotFound(true);
|
$Url->setNotFound(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Foreach post key, build the post.
|
||||||
foreach($list as $postKey=>$values)
|
foreach($list as $postKey=>$values)
|
||||||
{
|
{
|
||||||
$Post = buildPost($postKey);
|
$Post = buildPost($postKey);
|
||||||
|
|
||||||
if($Post!==false) {
|
if($Post!==false) {
|
||||||
array_push($posts, $Post);
|
array_push($posts, $Post);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Main
|
// Main
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
// Filter by post, then build it
|
// Build specific post.
|
||||||
if( ($Url->whereAmI()==='post') && ($Url->notFound()===false) )
|
if( ($Url->whereAmI()==='post') && ($Url->notFound()===false) )
|
||||||
{
|
{
|
||||||
$Post = buildPost( $Url->slug() );
|
$Post = buildPost( $Url->slug() );
|
||||||
|
@ -122,20 +141,20 @@ if( ($Url->whereAmI()==='post') && ($Url->notFound()===false) )
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// Build posts by specific tag.
|
||||||
elseif( ($Url->whereAmI()==='tag') && ($Url->notFound()===false) )
|
elseif( ($Url->whereAmI()==='tag') && ($Url->notFound()===false) )
|
||||||
{
|
{
|
||||||
buildPostForPage($Url->pageNumber(), $Site->postsPerPage(), true, $Url->slug());
|
buildPostsForPage($Url->pageNumber(), $Site->postsPerPage(), true, $Url->slug());
|
||||||
}
|
}
|
||||||
// Build post per page
|
// Build posts for homepage or admin area.
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// Posts for admin area.
|
||||||
if($Url->whereAmI()==='admin') {
|
if($Url->whereAmI()==='admin') {
|
||||||
// Build post for admin area with drafts+schedulers
|
buildPostsForPage($Url->pageNumber(), POSTS_PER_PAGE_ADMIN, false);
|
||||||
buildPostForPage($Url->pageNumber(), POSTS_PER_PAGE_ADMIN, true);
|
|
||||||
}
|
}
|
||||||
else
|
// Posts for homepage
|
||||||
{
|
else {
|
||||||
// Build post for the site, without the drafts and scheduleres posts
|
buildPostsForPage($Url->pageNumber(), $Site->postsPerPage(), true);
|
||||||
buildPostForPage($Url->pageNumber(), $Site->postsPerPage(), false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,8 +1,8 @@
|
||||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
||||||
|
|
||||||
// Boot rules
|
// Boot rules
|
||||||
include(PATH_RULES.'70.build_posts.php');
|
include(PATH_RULES.'70.posts.php');
|
||||||
include(PATH_RULES.'70.build_pages.php');
|
include(PATH_RULES.'70.pages.php');
|
||||||
include(PATH_RULES.'80.plugins.php');
|
include(PATH_RULES.'80.plugins.php');
|
||||||
include(PATH_RULES.'99.header.php');
|
include(PATH_RULES.'99.header.php');
|
||||||
include(PATH_RULES.'99.paginator.php');
|
include(PATH_RULES.'99.paginator.php');
|
||||||
|
|
|
@ -26,11 +26,7 @@ class dbPages extends dbJSON
|
||||||
$dataForFile = array(); // This data will be saved in the file
|
$dataForFile = array(); // This data will be saved in the file
|
||||||
|
|
||||||
$key = $this->generateKey($args['slug'], $args['parent']);
|
$key = $this->generateKey($args['slug'], $args['parent']);
|
||||||
/*
|
|
||||||
if($key===false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
// The user is always the one loggued.
|
// The user is always the one loggued.
|
||||||
$args['username'] = Session::get('username');
|
$args['username'] = Session::get('username');
|
||||||
if( Text::isEmpty($args['username']) ) {
|
if( Text::isEmpty($args['username']) ) {
|
||||||
|
@ -289,7 +285,7 @@ class dbPages extends dbJSON
|
||||||
return $this->db;
|
return $this->db;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function regenerate()
|
public function regenerateCli()
|
||||||
{
|
{
|
||||||
$db = $this->db;
|
$db = $this->db;
|
||||||
$newPaths = array();
|
$newPaths = array();
|
||||||
|
@ -361,73 +357,4 @@ class dbPages extends dbJSON
|
||||||
|
|
||||||
return $this->db!=$db;
|
return $this->db!=$db;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
public function regenerate()
|
|
||||||
{
|
|
||||||
$db = $this->db;
|
|
||||||
$paths = array();
|
|
||||||
$fields = array();
|
|
||||||
|
|
||||||
// Complete $fields with the default values.
|
|
||||||
foreach($this->dbFields as $field=>$options) {
|
|
||||||
if(!$options['inFile']) {
|
|
||||||
$fields[$field] = $options['value'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Foreach new page set the unix time stamp.
|
|
||||||
$fields['unixTimeCreated'] = Date::unixTime();
|
|
||||||
|
|
||||||
// Foreach new page set the owner admin.
|
|
||||||
$fields['username'] = 'admin';
|
|
||||||
|
|
||||||
// Foreach new page set the status.
|
|
||||||
if(HANDMADE_PUBLISHED) {
|
|
||||||
$fields['status']='published';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the pages from the first level of directories
|
|
||||||
$tmpPaths = glob(PATH_PAGES.'*', GLOB_ONLYDIR);
|
|
||||||
foreach($tmpPaths as $directory)
|
|
||||||
{
|
|
||||||
$key = basename($directory);
|
|
||||||
|
|
||||||
if(file_exists($directory.DS.'index.txt')){
|
|
||||||
// The key is the directory name
|
|
||||||
$paths[$key] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Recovery pages from subdirectories
|
|
||||||
$subPaths = glob($directory.DS.'*', GLOB_ONLYDIR);
|
|
||||||
foreach($subPaths as $subDirectory)
|
|
||||||
{
|
|
||||||
$subKey = basename($subDirectory);
|
|
||||||
|
|
||||||
if(file_exists($subDirectory.DS.'index.txt')) {
|
|
||||||
// The key is composed by the directory/subdirectory
|
|
||||||
$paths[$key.'/'.$subKey] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove old posts from db
|
|
||||||
foreach( array_diff_key($db, $paths) as $slug=>$data ) {
|
|
||||||
unset($this->db[$slug]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Insert new posts to db
|
|
||||||
foreach( array_diff_key($paths, $db) as $slug=>$data ) {
|
|
||||||
$this->db[$slug] = $fields;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save the database.
|
|
||||||
if( $this->save() === false ) {
|
|
||||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->db!=$db;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
|
@ -15,7 +15,7 @@ class dbPosts extends dbJSON
|
||||||
|
|
||||||
private $numberPosts = array(
|
private $numberPosts = array(
|
||||||
'total'=>0,
|
'total'=>0,
|
||||||
'withoutDrafts'=>0
|
'published'=>0
|
||||||
);
|
);
|
||||||
|
|
||||||
function __construct()
|
function __construct()
|
||||||
|
@ -31,7 +31,7 @@ class dbPosts extends dbJSON
|
||||||
return $this->numberPosts['total'];
|
return $this->numberPosts['total'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->numberPosts['withoutDrafts'];
|
return $this->numberPosts['published'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return an array with the post's database, FALSE otherwise.
|
// Return an array with the post's database, FALSE otherwise.
|
||||||
|
@ -163,10 +163,6 @@ class dbPosts extends dbJSON
|
||||||
|
|
||||||
public function edit($args)
|
public function edit($args)
|
||||||
{
|
{
|
||||||
if( !Valid::date($args['date'], DB_DATE_FORMAT) ) {
|
|
||||||
$args['date'] = Date::current(DB_DATE_FORMAT);
|
|
||||||
}
|
|
||||||
|
|
||||||
if( $this->delete($args['key']) ) {
|
if( $this->delete($args['key']) ) {
|
||||||
return $this->add($args);
|
return $this->add($args);
|
||||||
}
|
}
|
||||||
|
@ -203,7 +199,109 @@ class dbPosts extends dbJSON
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function regenerate()
|
// Returns an array with a list of posts keys, filtered by a page number.
|
||||||
|
public function getList($pageNumber, $postPerPage, $removeUnpublished=true)
|
||||||
|
{
|
||||||
|
$totalPosts = $this->numberPosts['total'];
|
||||||
|
|
||||||
|
// Remove the unpublished posts.
|
||||||
|
if($removeUnpublished) {
|
||||||
|
$this->removeUnpublished();
|
||||||
|
$totalPosts = $this->numberPosts['published'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$init = (int) $postPerPage * $pageNumber;
|
||||||
|
$end = (int) min( ($init + $postPerPage - 1), $totalPosts - 1 );
|
||||||
|
$outrange = $init<0 ? true : $init>$end;
|
||||||
|
|
||||||
|
if(!$outrange)
|
||||||
|
{
|
||||||
|
// Sort posts
|
||||||
|
$this->sortByDate();
|
||||||
|
|
||||||
|
return array_slice($this->db, $init, $postPerPage, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete all posts from an user.
|
||||||
|
public function deletePostsByUser($username)
|
||||||
|
{
|
||||||
|
foreach($this->db as $key=>$value)
|
||||||
|
{
|
||||||
|
if($value['username']==$username) {
|
||||||
|
unset($this->db[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save the database.
|
||||||
|
if( $this->save() === false ) {
|
||||||
|
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Link-up all posts from an user to another user.
|
||||||
|
public function linkPostsToUser($oldUsername, $newUsername)
|
||||||
|
{
|
||||||
|
foreach($this->db as $key=>$value)
|
||||||
|
{
|
||||||
|
if($value['username']==$oldUsername) {
|
||||||
|
$this->db[$key]['username'] = $newUsername;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save the database.
|
||||||
|
if( $this->save() === false ) {
|
||||||
|
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove the posts not published, status != published or date grater than current date.
|
||||||
|
public function removeUnpublished($scheduled=true)
|
||||||
|
{
|
||||||
|
$currentDate = Date::current(DB_DATE_FORMAT);
|
||||||
|
|
||||||
|
foreach($this->db as $key=>$values)
|
||||||
|
{
|
||||||
|
if( ($values['status']!='published') || ( ($values['date']>$currentDate) && $scheduled ) ) {
|
||||||
|
unset($this->db[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->numberPosts['published'] = count($this->db);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort posts by date.
|
||||||
|
public function sortByDate($HighToLow=true)
|
||||||
|
{
|
||||||
|
if($HighToLow) {
|
||||||
|
uasort($this->db, array($this, 'sortHighToLow'));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
uasort($this->db, array($this, 'sortLowToHigh'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function sortLowToHigh($a, $b) {
|
||||||
|
return $a['date']>$b['date'];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function sortHighToLow($a, $b) {
|
||||||
|
return $a['date']<$b['date'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function regenerateCli()
|
||||||
{
|
{
|
||||||
$db = $this->db;
|
$db = $this->db;
|
||||||
$newPaths = array();
|
$newPaths = array();
|
||||||
|
@ -265,160 +363,4 @@ class dbPosts extends dbJSON
|
||||||
return $this->db!=$db;
|
return $this->db!=$db;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
public function regenerate()
|
|
||||||
{
|
|
||||||
$db = $this->db;
|
|
||||||
$paths = array();
|
|
||||||
$fields = array();
|
|
||||||
|
|
||||||
// Default fields and value
|
|
||||||
foreach($this->dbFields as $field=>$options) {
|
|
||||||
if(!$options['inFile']) {
|
|
||||||
$fields[$field] = $options['value'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unix time stamp
|
|
||||||
$fields['date'] = Date::current(DB_DATE_FORMAT);
|
|
||||||
|
|
||||||
// Username
|
|
||||||
$fields['username'] = 'admin';
|
|
||||||
|
|
||||||
if(HANDMADE_PUBLISHED) {
|
|
||||||
$fields['status']='published';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Recovery pages from the first level of directories
|
|
||||||
$tmpPaths = glob(PATH_POSTS.'*', GLOB_ONLYDIR);
|
|
||||||
foreach($tmpPaths as $directory)
|
|
||||||
{
|
|
||||||
$key = basename($directory);
|
|
||||||
|
|
||||||
if(file_exists($directory.DS.'index.txt')) {
|
|
||||||
// The key is the directory name
|
|
||||||
$paths[$key] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove old posts from db
|
|
||||||
foreach( array_diff_key($db, $paths) as $slug=>$data ) {
|
|
||||||
unset($this->db[$slug]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Insert new posts to db
|
|
||||||
foreach( array_diff_key($paths, $db) as $slug=>$data ) {
|
|
||||||
$this->db[$slug] = $fields;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save the database.
|
|
||||||
if( $this->save() === false ) {
|
|
||||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->db!=$db;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
public function getList($pageNumber, $postPerPage, $draftPosts=false)
|
|
||||||
{
|
|
||||||
// DEBUG: Ver una mejor manera de eliminar draft post antes de ordenarlos
|
|
||||||
// DEBUG: Se eliminan antes de ordenarlos porque sino los draft cuentan como publicados en el PostPerPage.
|
|
||||||
if(!$draftPosts) {
|
|
||||||
$this->removeUnpublished();
|
|
||||||
$this->numberPosts['withoutDrafts'] = count($this->db);
|
|
||||||
}
|
|
||||||
|
|
||||||
$init = (int) $postPerPage * $pageNumber;
|
|
||||||
$end = (int) min( ($init + $postPerPage - 1), count($this->db) - 1 );
|
|
||||||
$outrange = $init<0 ? true : $init>$end;
|
|
||||||
|
|
||||||
// Sort posts
|
|
||||||
$this->sortByDate();
|
|
||||||
|
|
||||||
if(!$outrange) {
|
|
||||||
$tmp = $this->db;
|
|
||||||
return array_slice($tmp, $init, $postPerPage, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete all posts from an user.
|
|
||||||
public function deletePostsByUser($username)
|
|
||||||
{
|
|
||||||
foreach($this->db as $key=>$value)
|
|
||||||
{
|
|
||||||
if($value['username']==$username) {
|
|
||||||
unset($this->db[$key]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save the database.
|
|
||||||
if( $this->save() === false ) {
|
|
||||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Link-up all posts from an user to another user.
|
|
||||||
public function linkPostsToUser($oldUsername, $newUsername)
|
|
||||||
{
|
|
||||||
foreach($this->db as $key=>$value)
|
|
||||||
{
|
|
||||||
if($value['username']==$oldUsername) {
|
|
||||||
$this->db[$key]['username'] = $newUsername;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save the database.
|
|
||||||
if( $this->save() === false ) {
|
|
||||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove the posts not published, status != published and date grater than current date.
|
|
||||||
// DEBUG: Ver una mejor manera de eliminar draft post antes de ordenarlos
|
|
||||||
private function removeUnpublished()
|
|
||||||
{
|
|
||||||
$tmp = array();
|
|
||||||
$currentDate = Date::current(DB_DATE_FORMAT);
|
|
||||||
|
|
||||||
foreach($this->db as $key=>$values)
|
|
||||||
{
|
|
||||||
if( ($values['status']==='published') && ($values['date']<=$currentDate) ) {
|
|
||||||
$tmp[$key]=$values;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->db = $tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function sortByDate($low_to_high=false)
|
|
||||||
{
|
|
||||||
// high to low
|
|
||||||
function high_to_low($a, $b) {
|
|
||||||
return $a['date']<$b['date'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// low to high
|
|
||||||
function low_to_high($a, $b) {
|
|
||||||
return $a['date']>$b['date'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$tmp = $this->db;
|
|
||||||
|
|
||||||
if($low_to_high)
|
|
||||||
uasort($tmp, 'low_to_high');
|
|
||||||
else
|
|
||||||
uasort($tmp, 'high_to_low');
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -18,18 +18,25 @@ class dbTags extends dbJSON
|
||||||
parent::__construct(PATH_DATABASES.'tags.php');
|
parent::__construct(PATH_DATABASES.'tags.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns an array with a list of posts keys, filtered by a page number and a tag key.
|
||||||
public function getList($pageNumber, $postPerPage, $tagKey)
|
public function getList($pageNumber, $postPerPage, $tagKey)
|
||||||
{
|
{
|
||||||
|
if( !isset($this->db['postsIndex'][$tagKey]) ) {
|
||||||
|
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying get the posts list by the tag key: '.$tagKey);
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
$init = (int) $postPerPage * $pageNumber;
|
$init = (int) $postPerPage * $pageNumber;
|
||||||
$end = (int) min( ($init + $postPerPage - 1), $this->countPostsByTag($tagKey) - 1 );
|
$end = (int) min( ($init + $postPerPage - 1), $this->countPostsByTag($tagKey) - 1 );
|
||||||
$outrange = $init<0 ? true : $init > $end;
|
$outrange = $init<0 ? true : $init > $end;
|
||||||
|
|
||||||
if(!$outrange) {
|
if(!$outrange) {
|
||||||
$list = $this->db['postsIndex'][$tagKey]['posts'];
|
$list = $this->db['postsIndex'][$tagKey]['posts'];
|
||||||
$tmp = array_flip($list);
|
$tmp = array_flip($list); // Change the posts keys list in the array key.
|
||||||
return array_slice($tmp, $init, $postPerPage, true);
|
return array_slice($tmp, $init, $postPerPage, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying get the list of posts, out of range?. Pagenumber: '.$pageNumber);
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,11 +45,12 @@ class dbTags extends dbJSON
|
||||||
if( isset($this->db['postsIndex'][$tagKey]) ) {
|
if( isset($this->db['postsIndex'][$tagKey]) ) {
|
||||||
return count($this->db['postsIndex'][$tagKey]['posts']);
|
return count($this->db['postsIndex'][$tagKey]['posts']);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
// Regenerate the posts index for each tag.
|
||||||
|
// (array) $db, the $db must be sorted by date and the posts published only.
|
||||||
public function reindexPosts($db)
|
public function reindexPosts($db)
|
||||||
{
|
{
|
||||||
$tagsIndex = array();
|
$tagsIndex = array();
|
||||||
|
@ -74,6 +82,8 @@ class dbTags extends dbJSON
|
||||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.');
|
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -179,7 +179,6 @@ class Text {
|
||||||
return preg_replace_callback('/<pre.*?><code(.*?)>(.*?)<\/code><\/pre>/imsu',
|
return preg_replace_callback('/<pre.*?><code(.*?)>(.*?)<\/code><\/pre>/imsu',
|
||||||
create_function('$input', 'return "<pre><code $input[1]>".htmlentities($input[2])."</code></pre>";'),
|
create_function('$input', 'return "<pre><code $input[1]>".htmlentities($input[2])."</code></pre>";'),
|
||||||
$string);
|
$string);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue