Improvements on tags
This commit is contained in:
parent
22c75b9d09
commit
25633d0dbc
|
@ -22,6 +22,8 @@ function editPost($args)
|
||||||
if( $dbPosts->edit($args) )
|
if( $dbPosts->edit($args) )
|
||||||
{
|
{
|
||||||
// Regenerate the database tags
|
// Regenerate the database tags
|
||||||
|
$dbPosts->removeUnpublished();
|
||||||
|
$dbPosts->sortByDate();
|
||||||
$dbTags->reindexPosts( $dbPosts->db );
|
$dbTags->reindexPosts( $dbPosts->db );
|
||||||
|
|
||||||
Alert::set($Language->g('The changes have been saved'));
|
Alert::set($Language->g('The changes have been saved'));
|
||||||
|
|
|
@ -26,6 +26,8 @@ function addPost($args)
|
||||||
if( $dbPosts->add($args) )
|
if( $dbPosts->add($args) )
|
||||||
{
|
{
|
||||||
// Regenerate the database tags
|
// Regenerate the database tags
|
||||||
|
$dbPosts->removeUnpublished();
|
||||||
|
$dbPosts->sortByDate();
|
||||||
$dbTags->reindexPosts( $dbPosts->db );
|
$dbTags->reindexPosts( $dbPosts->db );
|
||||||
|
|
||||||
Alert::set($Language->g('Post added successfully'));
|
Alert::set($Language->g('Post added successfully'));
|
||||||
|
|
|
@ -66,22 +66,28 @@ function buildPost($key)
|
||||||
return $Post;
|
return $Post;
|
||||||
}
|
}
|
||||||
|
|
||||||
function build_posts_per_page($pageNumber=0, $amount=5, $draftPosts=false)
|
function buildPostForPage($pageNumber=0, $amount=5, $removeUnpublished=false, $tagKey=false)
|
||||||
{
|
{
|
||||||
global $dbPosts;
|
global $dbPosts;
|
||||||
|
global $dbTags;
|
||||||
global $posts;
|
global $posts;
|
||||||
global $Url;
|
global $Url;
|
||||||
|
|
||||||
$list = $dbPosts->getPage($pageNumber, $amount, $draftPosts);
|
if($tagKey) {
|
||||||
|
$list = $dbTags->getList($pageNumber, $amount, $tagKey);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$list = $dbPosts->getList($pageNumber, $amount, $removeUnpublished);
|
||||||
|
}
|
||||||
|
|
||||||
// There are not post for the pageNumber then true Not found page
|
// There are not post for the pageNumber then set the page notfound
|
||||||
if(empty($list) && $pageNumber>0) {
|
if(empty($list) && $pageNumber>0) {
|
||||||
$Url->setNotFound(true);
|
$Url->setNotFound(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($list as $slug=>$db)
|
foreach($list as $postKey=>$values)
|
||||||
{
|
{
|
||||||
$Post = buildPost($slug);
|
$Post = buildPost($postKey);
|
||||||
|
|
||||||
if($Post!==false) {
|
if($Post!==false) {
|
||||||
array_push($posts, $Post);
|
array_push($posts, $Post);
|
||||||
|
@ -118,18 +124,18 @@ if( ($Url->whereAmI()==='post') && ($Url->notFound()===false) )
|
||||||
}
|
}
|
||||||
elseif( ($Url->whereAmI()==='tag') && ($Url->notFound()===false) )
|
elseif( ($Url->whereAmI()==='tag') && ($Url->notFound()===false) )
|
||||||
{
|
{
|
||||||
|
buildPostForPage($Url->pageNumber(), $Site->postsPerPage(), true, $Url->slug());
|
||||||
}
|
}
|
||||||
// Build post per page
|
// Build post per page
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if($Url->whereAmI()==='admin') {
|
if($Url->whereAmI()==='admin') {
|
||||||
// Build post for admin area with drafts
|
// Build post for admin area with drafts+schedulers
|
||||||
build_posts_per_page($Url->pageNumber(), POSTS_PER_PAGE_ADMIN, true);
|
buildPostForPage($Url->pageNumber(), POSTS_PER_PAGE_ADMIN, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Build post for the site, without the drafts posts
|
// Build post for the site, without the drafts and scheduleres posts
|
||||||
build_posts_per_page($Url->pageNumber(), $Site->postsPerPage(), false);
|
buildPostForPage($Url->pageNumber(), $Site->postsPerPage(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -320,7 +320,7 @@ class dbPosts extends dbJSON
|
||||||
return $this->db!=$db;
|
return $this->db!=$db;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
public function getPage($pageNumber, $postPerPage, $draftPosts=false)
|
public function getList($pageNumber, $postPerPage, $draftPosts=false)
|
||||||
{
|
{
|
||||||
// DEBUG: Ver una mejor manera de eliminar draft post antes de ordenarlos
|
// 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.
|
// DEBUG: Se eliminan antes de ordenarlos porque sino los draft cuentan como publicados en el PostPerPage.
|
||||||
|
@ -331,12 +331,13 @@ class dbPosts extends dbJSON
|
||||||
|
|
||||||
$init = (int) $postPerPage * $pageNumber;
|
$init = (int) $postPerPage * $pageNumber;
|
||||||
$end = (int) min( ($init + $postPerPage - 1), count($this->db) - 1 );
|
$end = (int) min( ($init + $postPerPage - 1), count($this->db) - 1 );
|
||||||
$outrange = $init<0 ? true : $init > $end;
|
$outrange = $init<0 ? true : $init>$end;
|
||||||
|
|
||||||
// Sort posts
|
// Sort posts
|
||||||
$tmp = $this->sortByDate();
|
$this->sortByDate();
|
||||||
|
|
||||||
if(!$outrange) {
|
if(!$outrange) {
|
||||||
|
$tmp = $this->db;
|
||||||
return array_slice($tmp, $init, $postPerPage, true);
|
return array_slice($tmp, $init, $postPerPage, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -417,7 +418,7 @@ class dbPosts extends dbJSON
|
||||||
else
|
else
|
||||||
uasort($tmp, 'high_to_low');
|
uasort($tmp, 'high_to_low');
|
||||||
|
|
||||||
return $tmp;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,13 +18,28 @@ class dbTags extends dbJSON
|
||||||
parent::__construct(PATH_DATABASES.'tags.php');
|
parent::__construct(PATH_DATABASES.'tags.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getList($pageNumber, $postPerPage, $tagKey)
|
||||||
|
{
|
||||||
|
$init = (int) $postPerPage * $pageNumber;
|
||||||
|
$end = (int) min( ($init + $postPerPage - 1), $this->countPostsByTag($tagKey) - 1 );
|
||||||
|
$outrange = $init<0 ? true : $init > $end;
|
||||||
|
|
||||||
|
if(!$outrange) {
|
||||||
|
$list = $this->db['postsIndex'][$tagKey]['posts'];
|
||||||
|
$tmp = array_flip($list);
|
||||||
|
return array_slice($tmp, $init, $postPerPage, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
public function countPostsByTag($tagKey)
|
public function countPostsByTag($tagKey)
|
||||||
{
|
{
|
||||||
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 {
|
else {
|
||||||
return false;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,8 +50,6 @@ class dbTags extends dbJSON
|
||||||
|
|
||||||
// Foreach post
|
// Foreach post
|
||||||
foreach($db as $postKey=>$values)
|
foreach($db as $postKey=>$values)
|
||||||
{
|
|
||||||
if( ($values['status']==='published') && ($values['date']<=$currentDate) )
|
|
||||||
{
|
{
|
||||||
$explode = explode(',', $values['tags']);
|
$explode = explode(',', $values['tags']);
|
||||||
|
|
||||||
|
@ -55,7 +68,6 @@ class dbTags extends dbJSON
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$this->db['postsIndex'] = $tagsIndex;
|
$this->db['postsIndex'] = $tagsIndex;
|
||||||
if( $this->save() === false ) {
|
if( $this->save() === false ) {
|
||||||
|
|
|
@ -27,12 +27,12 @@ class pluginTags extends Plugin {
|
||||||
global $dbTags;
|
global $dbTags;
|
||||||
global $Url;
|
global $Url;
|
||||||
|
|
||||||
|
$db = $dbTags->db['postsIndex'];
|
||||||
|
$filter = trim($Url->filters('tag'), '/');
|
||||||
|
|
||||||
$html = '<div class="plugin plugin-tags">';
|
$html = '<div class="plugin plugin-tags">';
|
||||||
$html .= '<h2>'.$this->getDbField('label').'</h2>';
|
$html .= '<h2>'.$this->getDbField('label').'</h2>';
|
||||||
$html .= '<div class="plugin-content">';
|
$html .= '<div class="plugin-content">';
|
||||||
|
|
||||||
$db = $dbTags->db['postsIndex'];
|
|
||||||
|
|
||||||
$html .= '<ul>';
|
$html .= '<ul>';
|
||||||
|
|
||||||
foreach($db as $tagKey=>$fields)
|
foreach($db as $tagKey=>$fields)
|
||||||
|
@ -40,7 +40,7 @@ class pluginTags extends Plugin {
|
||||||
$count = $dbTags->countPostsByTag($tagKey);
|
$count = $dbTags->countPostsByTag($tagKey);
|
||||||
|
|
||||||
// Print the parent
|
// Print the parent
|
||||||
$html .= '<li><a href="'.HTML_PATH_ROOT.$Url->filters('tag').$tagKey.'">'.$fields['name'].' ('.$count.')</a></li>';
|
$html .= '<li><a href="'.HTML_PATH_ROOT.$filter.'/'.$tagKey.'">'.$fields['name'].' ('.$count.')</a></li>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$html .= '</ul>';
|
$html .= '</ul>';
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
<!-- Content -->
|
<!-- Content -->
|
||||||
<?php
|
<?php
|
||||||
if($Url->whereAmI()=='home')
|
if( ($Url->whereAmI()=='home') || ($Url->whereAmI()=='tag') )
|
||||||
{
|
{
|
||||||
include('php/home.php');
|
include('php/home.php');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue