Improves for categories

This commit is contained in:
Diego 2017-05-03 21:10:03 +02:00
parent 5a3c217cca
commit ce438a8e02
9 changed files with 73 additions and 10 deletions

View File

@ -81,6 +81,14 @@ HTML::formOpen(array('class'=>'uk-form-horizontal'));
'tip'=>''
));
HTML::formInputText(array(
'name'=>'uriCategory',
'label'=>$L->g('Category'),
'value'=>$Site->uriFilters('category'),
'class'=>'uk-width-1-2 uk-form-medium',
'tip'=>''
));
echo '<div class="uk-form-row">
<div class="uk-form-controls">
<button type="submit" class="uk-button uk-button-primary">'.$L->g('Save').'</button>

View File

@ -48,6 +48,8 @@ define('PATH_ADMIN_THEMES', PATH_ADMIN.'themes'.DS);
define('PATH_ADMIN_CONTROLLERS', PATH_ADMIN.'controllers'.DS);
define('PATH_ADMIN_VIEWS', PATH_ADMIN.'views'.DS);
define('DEBUG_FILE', PATH_CONTENT.'debug.txt');
// Log separator
define('LOG_SEP', ' | ');

View File

@ -51,7 +51,12 @@ if( ($Url->whereAmI()==='post') && ($Url->notFound()===false) )
// Build posts by specific tag.
elseif( ($Url->whereAmI()==='tag') && ($Url->notFound()===false) )
{
$posts = buildPostsForPage($Url->pageNumber(), $Site->postsPerPage(), true, $Url->slug());
$posts = buildPostsForPage($Url->pageNumber(), $Site->postsPerPage(), true, $Url->slug(), 'tag');
}
// Build posts by specific category.
elseif( ($Url->whereAmI()==='category') && ($Url->notFound()===false) )
{
$posts = buildPostsForPage($Url->pageNumber(), $Site->postsPerPage(), true, $Url->slug(), 'category');
}
// Build posts for homepage or admin area.
else

View File

@ -139,7 +139,7 @@ class dbCategories extends dbJSON
$this->save();
return $newCategoryKey;
return $newCategoryKey;
}
// Re-generate posts index
@ -201,4 +201,25 @@ class dbCategories extends dbJSON
return Text::cleanUrl($category);
}
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;
$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); // Change the posts keys list in the array key.
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();
}
}

View File

@ -44,6 +44,8 @@ class dbLanguage extends dbJSON
$key = Text::lowercase($string);
$key = Text::replace(' ', '-', $key);
#file_put_contents(DEBUG_FILE, $key.PHP_EOL, FILE_APPEND);
if(isset($this->db[$key])) {
return $this->db[$key];
}

View File

@ -117,7 +117,7 @@ class dbPosts extends dbJSON
// Generate UUID
if( empty($args['uuid']) ) {
$args['uuid'] = md5(time().DOMAIN);
$args['uuid'] = md5(uniqid());
}
// The user is always who is loggued

View File

@ -18,6 +18,7 @@ class dbSite extends dbJSON
'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'=>''),
'dateFormat'=> array('inFile'=>false, 'value'=>'F j, Y'),
@ -73,6 +74,7 @@ class dbSite extends dbJSON
$filters['page'] = $this->getField('uriPage');
$filters['tag'] = $this->getField('uriTag');
$filters['blog'] = $this->getField('uriBlog');
$filters['category'] = $this->getField('uriCategory');
if(empty($filter)) {
return $filters;
@ -105,6 +107,12 @@ class dbSite extends dbJSON
return $this->url().ltrim($filter, '/');
}
public function urlCategory()
{
$filter = $this->getField('uriCategory');
return $this->url().ltrim($filter, '/');
}
public function twitter()
{
return $this->getField('twitter');

View File

@ -92,7 +92,7 @@ function buildPost($key)
return $Post;
}
function buildPostsForPage($pageNumber=0, $amount=POSTS_PER_PAGE_ADMIN, $removeUnpublished=true, $tagKey=false)
function buildPostsForPage($pageNumber=0, $amount=POSTS_PER_PAGE_ADMIN, $removeUnpublished=true, $key, $type='tag')
{
global $dbPosts;
global $dbTags;
@ -100,9 +100,12 @@ function buildPostsForPage($pageNumber=0, $amount=POSTS_PER_PAGE_ADMIN, $removeU
$posts = array();
if($tagKey) {
if($type=='tag') {
// 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, $key);
}
elseif($type=='category') {
$list = $dbCategories->getList($pageNumber, $amount, $key);
}
else {
// Get the keys list from posts database.

View File

@ -331,7 +331,11 @@ function install($adminPassword, $email, $timezone)
'tags'=>array(),
'status'=>'published',
'date'=>$currentDate,
'position'=>0
'position'=>0,
'coverImage'=>'',
'md5file'=>'',
'category'=>'',
'uuid'=>md5(uniqid())
),
'about'=>array(
'description'=>$Language->get('About your site or yourself'),
@ -339,7 +343,11 @@ function install($adminPassword, $email, $timezone)
'tags'=>array(),
'status'=>'published',
'date'=>$currentDate,
'position'=>1
'position'=>1,
'coverImage'=>'',
'md5file'=>'',
'category'=>'',
'uuid'=>md5(uniqid())
)
);
@ -353,7 +361,11 @@ function install($adminPassword, $email, $timezone)
'status'=>'published',
'tags'=>array('bludit'=>'Bludit','cms'=>'CMS','flat-files'=>'Flat files'),
'allowComments'=>'false',
'date'=>$currentDate
'date'=>$currentDate,
'coverImage'=>'',
'md5file'=>'',
'category'=>'',
'uuid'=>md5(uniqid())
)
);
file_put_contents(PATH_DATABASES.'posts.php', $dataHead.json_encode($data, JSON_PRETTY_PRINT), LOCK_EX);
@ -374,6 +386,8 @@ function install($adminPassword, $email, $timezone)
'uriPost'=>'/post/',
'uriPage'=>'/',
'uriTag'=>'/tag/',
'uriBlog'=>'/blog/',
'uriCategory'=>'/category/',
'url'=>PROTOCOL.DOMAIN.HTML_PATH_ROOT,
'emailFrom'=>'no-reply@'.DOMAIN
);
@ -731,4 +745,4 @@ $(document).ready(function()
</script>
</body>
</html>
</html>