Improvements on tags
This commit is contained in:
parent
22c75b9d09
commit
25633d0dbc
|
@ -22,6 +22,8 @@ function editPost($args)
|
|||
if( $dbPosts->edit($args) )
|
||||
{
|
||||
// Regenerate the database tags
|
||||
$dbPosts->removeUnpublished();
|
||||
$dbPosts->sortByDate();
|
||||
$dbTags->reindexPosts( $dbPosts->db );
|
||||
|
||||
Alert::set($Language->g('The changes have been saved'));
|
||||
|
|
|
@ -26,6 +26,8 @@ function addPost($args)
|
|||
if( $dbPosts->add($args) )
|
||||
{
|
||||
// Regenerate the database tags
|
||||
$dbPosts->removeUnpublished();
|
||||
$dbPosts->sortByDate();
|
||||
$dbTags->reindexPosts( $dbPosts->db );
|
||||
|
||||
Alert::set($Language->g('Post added successfully'));
|
||||
|
|
|
@ -66,22 +66,28 @@ function buildPost($key)
|
|||
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 $dbTags;
|
||||
global $posts;
|
||||
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) {
|
||||
$Url->setNotFound(true);
|
||||
}
|
||||
|
||||
foreach($list as $slug=>$db)
|
||||
foreach($list as $postKey=>$values)
|
||||
{
|
||||
$Post = buildPost($slug);
|
||||
$Post = buildPost($postKey);
|
||||
|
||||
if($Post!==false) {
|
||||
array_push($posts, $Post);
|
||||
|
@ -118,18 +124,18 @@ if( ($Url->whereAmI()==='post') && ($Url->notFound()===false) )
|
|||
}
|
||||
elseif( ($Url->whereAmI()==='tag') && ($Url->notFound()===false) )
|
||||
{
|
||||
|
||||
buildPostForPage($Url->pageNumber(), $Site->postsPerPage(), true, $Url->slug());
|
||||
}
|
||||
// Build post per page
|
||||
else
|
||||
{
|
||||
if($Url->whereAmI()==='admin') {
|
||||
// Build post for admin area with drafts
|
||||
build_posts_per_page($Url->pageNumber(), POSTS_PER_PAGE_ADMIN, true);
|
||||
// Build post for admin area with drafts+schedulers
|
||||
buildPostForPage($Url->pageNumber(), POSTS_PER_PAGE_ADMIN, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Build post for the site, without the drafts posts
|
||||
build_posts_per_page($Url->pageNumber(), $Site->postsPerPage(), false);
|
||||
// Build post for the site, without the drafts and scheduleres posts
|
||||
buildPostForPage($Url->pageNumber(), $Site->postsPerPage(), false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -320,7 +320,7 @@ class dbPosts extends dbJSON
|
|||
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: 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;
|
||||
$end = (int) min( ($init + $postPerPage - 1), count($this->db) - 1 );
|
||||
$outrange = $init<0 ? true : $init > $end;
|
||||
$outrange = $init<0 ? true : $init>$end;
|
||||
|
||||
// Sort posts
|
||||
$tmp = $this->sortByDate();
|
||||
$this->sortByDate();
|
||||
|
||||
if(!$outrange) {
|
||||
$tmp = $this->db;
|
||||
return array_slice($tmp, $init, $postPerPage, true);
|
||||
}
|
||||
|
||||
|
@ -417,7 +418,7 @@ class dbPosts extends dbJSON
|
|||
else
|
||||
uasort($tmp, 'high_to_low');
|
||||
|
||||
return $tmp;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,13 +18,28 @@ class dbTags extends dbJSON
|
|||
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)
|
||||
{
|
||||
if( isset($this->db['postsIndex'][$tagKey]) ) {
|
||||
return count($this->db['postsIndex'][$tagKey]['posts']);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,23 +51,20 @@ class dbTags extends dbJSON
|
|||
// Foreach post
|
||||
foreach($db as $postKey=>$values)
|
||||
{
|
||||
if( ($values['status']==='published') && ($values['date']<=$currentDate) )
|
||||
$explode = explode(',', $values['tags']);
|
||||
|
||||
// Foreach tag from post
|
||||
foreach($explode as $tagName)
|
||||
{
|
||||
$explode = explode(',', $values['tags']);
|
||||
$tagName = trim($tagName);
|
||||
$tagKey = Text::cleanUrl($tagName);
|
||||
|
||||
// Foreach tag from post
|
||||
foreach($explode as $tagName)
|
||||
{
|
||||
$tagName = trim($tagName);
|
||||
$tagKey = Text::cleanUrl($tagName);
|
||||
|
||||
if( isset($tagsIndex[$tagKey]) ) {
|
||||
array_push($tagsIndex[$tagKey]['posts'], $postKey);
|
||||
}
|
||||
else {
|
||||
$tagsIndex[$tagKey]['name'] = $tagName;
|
||||
$tagsIndex[$tagKey]['posts'] = array($postKey);
|
||||
}
|
||||
if( isset($tagsIndex[$tagKey]) ) {
|
||||
array_push($tagsIndex[$tagKey]['posts'], $postKey);
|
||||
}
|
||||
else {
|
||||
$tagsIndex[$tagKey]['name'] = $tagName;
|
||||
$tagsIndex[$tagKey]['posts'] = array($postKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,12 +27,12 @@ class pluginTags extends Plugin {
|
|||
global $dbTags;
|
||||
global $Url;
|
||||
|
||||
$db = $dbTags->db['postsIndex'];
|
||||
$filter = trim($Url->filters('tag'), '/');
|
||||
|
||||
$html = '<div class="plugin plugin-tags">';
|
||||
$html .= '<h2>'.$this->getDbField('label').'</h2>';
|
||||
$html .= '<div class="plugin-content">';
|
||||
|
||||
$db = $dbTags->db['postsIndex'];
|
||||
|
||||
$html .= '<ul>';
|
||||
|
||||
foreach($db as $tagKey=>$fields)
|
||||
|
@ -40,7 +40,7 @@ class pluginTags extends Plugin {
|
|||
$count = $dbTags->countPostsByTag($tagKey);
|
||||
|
||||
// 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>';
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
<!-- Content -->
|
||||
<?php
|
||||
if($Url->whereAmI()=='home')
|
||||
if( ($Url->whereAmI()=='home') || ($Url->whereAmI()=='tag') )
|
||||
{
|
||||
include('php/home.php');
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue