diff --git a/bl-kernel/admin/views/settings-advanced.php b/bl-kernel/admin/views/settings-advanced.php
index 9c12461c..a3b8f7c3 100644
--- a/bl-kernel/admin/views/settings-advanced.php
+++ b/bl-kernel/admin/views/settings-advanced.php
@@ -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 '
diff --git a/bl-kernel/boot/init.php b/bl-kernel/boot/init.php
index 34fd3e5c..c386b406 100644
--- a/bl-kernel/boot/init.php
+++ b/bl-kernel/boot/init.php
@@ -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', ' | ');
diff --git a/bl-kernel/boot/rules/70.posts.php b/bl-kernel/boot/rules/70.posts.php
index d446f4da..f03c5c8b 100644
--- a/bl-kernel/boot/rules/70.posts.php
+++ b/bl-kernel/boot/rules/70.posts.php
@@ -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
diff --git a/bl-kernel/dbcategories.class.php b/bl-kernel/dbcategories.class.php
index b72e0947..fc42d4e7 100644
--- a/bl-kernel/dbcategories.class.php
+++ b/bl-kernel/dbcategories.class.php
@@ -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();
+ }
+
}
\ No newline at end of file
diff --git a/bl-kernel/dblanguage.class.php b/bl-kernel/dblanguage.class.php
index 2801391b..260de063 100644
--- a/bl-kernel/dblanguage.class.php
+++ b/bl-kernel/dblanguage.class.php
@@ -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];
}
diff --git a/bl-kernel/dbposts.class.php b/bl-kernel/dbposts.class.php
index 1dda02b6..d14f7945 100644
--- a/bl-kernel/dbposts.class.php
+++ b/bl-kernel/dbposts.class.php
@@ -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
diff --git a/bl-kernel/dbsite.class.php b/bl-kernel/dbsite.class.php
index 26138464..7d53ed08 100644
--- a/bl-kernel/dbsite.class.php
+++ b/bl-kernel/dbsite.class.php
@@ -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');
diff --git a/bl-kernel/functions.php b/bl-kernel/functions.php
index cbf8310d..bfd5c9ff 100644
--- a/bl-kernel/functions.php
+++ b/bl-kernel/functions.php
@@ -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.
diff --git a/install.php b/install.php
index e5d73e72..77d078de 100644
--- a/install.php
+++ b/install.php
@@ -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()