Improves for categories
This commit is contained in:
parent
5a3c217cca
commit
ce438a8e02
|
@ -81,6 +81,14 @@ HTML::formOpen(array('class'=>'uk-form-horizontal'));
|
||||||
'tip'=>''
|
'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">
|
echo '<div class="uk-form-row">
|
||||||
<div class="uk-form-controls">
|
<div class="uk-form-controls">
|
||||||
<button type="submit" class="uk-button uk-button-primary">'.$L->g('Save').'</button>
|
<button type="submit" class="uk-button uk-button-primary">'.$L->g('Save').'</button>
|
||||||
|
|
|
@ -48,6 +48,8 @@ define('PATH_ADMIN_THEMES', PATH_ADMIN.'themes'.DS);
|
||||||
define('PATH_ADMIN_CONTROLLERS', PATH_ADMIN.'controllers'.DS);
|
define('PATH_ADMIN_CONTROLLERS', PATH_ADMIN.'controllers'.DS);
|
||||||
define('PATH_ADMIN_VIEWS', PATH_ADMIN.'views'.DS);
|
define('PATH_ADMIN_VIEWS', PATH_ADMIN.'views'.DS);
|
||||||
|
|
||||||
|
define('DEBUG_FILE', PATH_CONTENT.'debug.txt');
|
||||||
|
|
||||||
// Log separator
|
// Log separator
|
||||||
define('LOG_SEP', ' | ');
|
define('LOG_SEP', ' | ');
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,12 @@ if( ($Url->whereAmI()==='post') && ($Url->notFound()===false) )
|
||||||
// Build posts by specific tag.
|
// Build posts by specific tag.
|
||||||
elseif( ($Url->whereAmI()==='tag') && ($Url->notFound()===false) )
|
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.
|
// Build posts for homepage or admin area.
|
||||||
else
|
else
|
||||||
|
|
|
@ -139,7 +139,7 @@ class dbCategories extends dbJSON
|
||||||
|
|
||||||
$this->save();
|
$this->save();
|
||||||
|
|
||||||
return $newCategoryKey;
|
return $newCategoryKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Re-generate posts index
|
// Re-generate posts index
|
||||||
|
@ -201,4 +201,25 @@ class dbCategories extends dbJSON
|
||||||
return Text::cleanUrl($category);
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -44,6 +44,8 @@ class dbLanguage extends dbJSON
|
||||||
$key = Text::lowercase($string);
|
$key = Text::lowercase($string);
|
||||||
$key = Text::replace(' ', '-', $key);
|
$key = Text::replace(' ', '-', $key);
|
||||||
|
|
||||||
|
#file_put_contents(DEBUG_FILE, $key.PHP_EOL, FILE_APPEND);
|
||||||
|
|
||||||
if(isset($this->db[$key])) {
|
if(isset($this->db[$key])) {
|
||||||
return $this->db[$key];
|
return $this->db[$key];
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,7 +117,7 @@ class dbPosts extends dbJSON
|
||||||
|
|
||||||
// Generate UUID
|
// Generate UUID
|
||||||
if( empty($args['uuid']) ) {
|
if( empty($args['uuid']) ) {
|
||||||
$args['uuid'] = md5(time().DOMAIN);
|
$args['uuid'] = md5(uniqid());
|
||||||
}
|
}
|
||||||
|
|
||||||
// The user is always who is loggued
|
// The user is always who is loggued
|
||||||
|
|
|
@ -18,6 +18,7 @@ class dbSite extends dbJSON
|
||||||
'uriPost'=> array('inFile'=>false, 'value'=>'/post/'),
|
'uriPost'=> array('inFile'=>false, 'value'=>'/post/'),
|
||||||
'uriTag'=> array('inFile'=>false, 'value'=>'/tag/'),
|
'uriTag'=> array('inFile'=>false, 'value'=>'/tag/'),
|
||||||
'uriBlog'=> array('inFile'=>false, 'value'=>'/blog/'),
|
'uriBlog'=> array('inFile'=>false, 'value'=>'/blog/'),
|
||||||
|
'uriCategory'=> array('inFile'=>false, 'value'=>'/category/'),
|
||||||
'url'=> array('inFile'=>false, 'value'=>''),
|
'url'=> array('inFile'=>false, 'value'=>''),
|
||||||
'emailFrom'=> array('inFile'=>false, 'value'=>''),
|
'emailFrom'=> array('inFile'=>false, 'value'=>''),
|
||||||
'dateFormat'=> array('inFile'=>false, 'value'=>'F j, Y'),
|
'dateFormat'=> array('inFile'=>false, 'value'=>'F j, Y'),
|
||||||
|
@ -73,6 +74,7 @@ class dbSite extends dbJSON
|
||||||
$filters['page'] = $this->getField('uriPage');
|
$filters['page'] = $this->getField('uriPage');
|
||||||
$filters['tag'] = $this->getField('uriTag');
|
$filters['tag'] = $this->getField('uriTag');
|
||||||
$filters['blog'] = $this->getField('uriBlog');
|
$filters['blog'] = $this->getField('uriBlog');
|
||||||
|
$filters['category'] = $this->getField('uriCategory');
|
||||||
|
|
||||||
if(empty($filter)) {
|
if(empty($filter)) {
|
||||||
return $filters;
|
return $filters;
|
||||||
|
@ -105,6 +107,12 @@ class dbSite extends dbJSON
|
||||||
return $this->url().ltrim($filter, '/');
|
return $this->url().ltrim($filter, '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function urlCategory()
|
||||||
|
{
|
||||||
|
$filter = $this->getField('uriCategory');
|
||||||
|
return $this->url().ltrim($filter, '/');
|
||||||
|
}
|
||||||
|
|
||||||
public function twitter()
|
public function twitter()
|
||||||
{
|
{
|
||||||
return $this->getField('twitter');
|
return $this->getField('twitter');
|
||||||
|
|
|
@ -92,7 +92,7 @@ function buildPost($key)
|
||||||
return $Post;
|
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 $dbPosts;
|
||||||
global $dbTags;
|
global $dbTags;
|
||||||
|
@ -100,9 +100,12 @@ function buildPostsForPage($pageNumber=0, $amount=POSTS_PER_PAGE_ADMIN, $removeU
|
||||||
|
|
||||||
$posts = array();
|
$posts = array();
|
||||||
|
|
||||||
if($tagKey) {
|
if($type=='tag') {
|
||||||
// Get the keys list from tags database, this database is optimized for this case.
|
// 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 {
|
else {
|
||||||
// Get the keys list from posts database.
|
// Get the keys list from posts database.
|
||||||
|
|
22
install.php
22
install.php
|
@ -331,7 +331,11 @@ function install($adminPassword, $email, $timezone)
|
||||||
'tags'=>array(),
|
'tags'=>array(),
|
||||||
'status'=>'published',
|
'status'=>'published',
|
||||||
'date'=>$currentDate,
|
'date'=>$currentDate,
|
||||||
'position'=>0
|
'position'=>0,
|
||||||
|
'coverImage'=>'',
|
||||||
|
'md5file'=>'',
|
||||||
|
'category'=>'',
|
||||||
|
'uuid'=>md5(uniqid())
|
||||||
),
|
),
|
||||||
'about'=>array(
|
'about'=>array(
|
||||||
'description'=>$Language->get('About your site or yourself'),
|
'description'=>$Language->get('About your site or yourself'),
|
||||||
|
@ -339,7 +343,11 @@ function install($adminPassword, $email, $timezone)
|
||||||
'tags'=>array(),
|
'tags'=>array(),
|
||||||
'status'=>'published',
|
'status'=>'published',
|
||||||
'date'=>$currentDate,
|
'date'=>$currentDate,
|
||||||
'position'=>1
|
'position'=>1,
|
||||||
|
'coverImage'=>'',
|
||||||
|
'md5file'=>'',
|
||||||
|
'category'=>'',
|
||||||
|
'uuid'=>md5(uniqid())
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -353,7 +361,11 @@ function install($adminPassword, $email, $timezone)
|
||||||
'status'=>'published',
|
'status'=>'published',
|
||||||
'tags'=>array('bludit'=>'Bludit','cms'=>'CMS','flat-files'=>'Flat files'),
|
'tags'=>array('bludit'=>'Bludit','cms'=>'CMS','flat-files'=>'Flat files'),
|
||||||
'allowComments'=>'false',
|
'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);
|
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/',
|
'uriPost'=>'/post/',
|
||||||
'uriPage'=>'/',
|
'uriPage'=>'/',
|
||||||
'uriTag'=>'/tag/',
|
'uriTag'=>'/tag/',
|
||||||
|
'uriBlog'=>'/blog/',
|
||||||
|
'uriCategory'=>'/category/',
|
||||||
'url'=>PROTOCOL.DOMAIN.HTML_PATH_ROOT,
|
'url'=>PROTOCOL.DOMAIN.HTML_PATH_ROOT,
|
||||||
'emailFrom'=>'no-reply@'.DOMAIN
|
'emailFrom'=>'no-reply@'.DOMAIN
|
||||||
);
|
);
|
||||||
|
@ -731,4 +745,4 @@ $(document).ready(function()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Loading…
Reference in New Issue