';
+ // without the hidden field it doesn't send any post value when the checkbox is not checked
+ $html .= "";
+ $html .= '';
+
+ if(!empty($args['tip'])) {
+ $html .= '
'.$args['tip'].'
';
+ }
+
+ $html .= '
';
+ $html .= '
';
+
+ echo $html;
+ }
public static function formTextarea($args)
{
diff --git a/bl-kernel/admin/views/settings-advanced.php b/bl-kernel/admin/views/settings-advanced.php
index 9c12461c..a3dc6b4e 100644
--- a/bl-kernel/admin/views/settings-advanced.php
+++ b/bl-kernel/admin/views/settings-advanced.php
@@ -19,6 +19,13 @@ HTML::formOpen(array('class'=>'uk-form-horizontal'));
'class'=>'uk-width-1-3 uk-form-medium',
'tip'=>$L->g('number-of-posts-to-show-per-page')
));
+
+ HTML::formCheckbox(array(
+ 'name'=>'shuffleIdeticalTags',
+ 'label'=>$L->g('Shufle posts with identical tags'),
+ 'checked'=>$Site->shuffleIdeticalTags(),
+ 'class'=>'uk-width-1-3 uk-form-medium',
+ ));
HTML::formSelect(array(
'name'=>'homepage',
diff --git a/bl-kernel/boot/rules/70.posts.php b/bl-kernel/boot/rules/70.posts.php
index d446f4da..67f8135c 100644
--- a/bl-kernel/boot/rules/70.posts.php
+++ b/bl-kernel/boot/rules/70.posts.php
@@ -51,7 +51,7 @@ 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());
}
// Build posts for homepage or admin area.
else
diff --git a/bl-kernel/dbposts.class.php b/bl-kernel/dbposts.class.php
index 4306d481..02298fbf 100644
--- a/bl-kernel/dbposts.class.php
+++ b/bl-kernel/dbposts.class.php
@@ -19,7 +19,7 @@ class dbPosts extends dbJSON
function __construct()
{
parent::__construct(PATH_DATABASES.'posts.php');
- }
+ }
// Return the amount of posts
// $total = TRUE, returns the total of posts
@@ -103,9 +103,10 @@ class dbPosts extends dbJSON
public function add($args)
{
+ global $Site;
$dataForDb = array(); // This data will be saved in the database
$dataForFile = array(); // This data will be saved in the file
-
+
// Current date, format of DB_DATE_FORMAT
$currentDate = Date::current(DB_DATE_FORMAT);
@@ -189,6 +190,10 @@ class dbPosts extends dbJSON
// Sort posts before save
$this->sortByDate();
+
+ if($Site->shuffleIdeticalTags()){
+ $this->mixTags();
+ }
if( $this->save() === false ) {
@@ -398,11 +403,63 @@ class dbPosts extends dbJSON
else {
uasort($this->db, array($this, 'sortLowToHigh'));
}
-
+
return true;
}
+
+ // Mix the posts so that neighbour posts have different Tags -
+ // helpfull if you want to show diverse content. Case studies for example
+ public function mixTags()
+ {
+ $previousValue = null;
+ $finalArray=array();
+ $buffeArray=array();
- private function sortLowToHigh($a, $b) {
+ // Get array keys
+ $arrayKeys = array_keys($this->db);
+ // Fetch last array key
+ $lastArrayKey = array_pop($arrayKeys);
+
+ foreach($this->db as $key=>$row){
+ foreach($buffeArray as $bufferKey=>$bufferRow){
+ // Get buffer array keys
+ $finalArrayKeys = array_keys($finalArray);
+ // Fetch last array key
+ $finalArraylastArrayKey = array_pop($finalArrayKeys);
+
+ if($bufferRow['tags']!=$finalArray[$finalArraylastArrayKey]['tags']){
+ $finalArray[$bufferKey]=$bufferRow;
+ unset($buffeArray[$bufferKey]);
+ }
+ }
+
+ $finalArrayKeys = array_keys($finalArray);
+ // Fetch last array key
+ $finalArraylastArrayKey = array_pop($finalArrayKeys);
+
+ if(empty($finalArray)){
+ $finalArray[$key]=$row;
+ }
+ elseif($row['tags']==$finalArray[$finalArraylastArrayKey]['tags']){
+ $buffeArray[$key]=$row;
+ }
+ else{
+ $finalArray[$key]=$row;
+ }
+
+ //reached the end so no other choice but to add the remaining buffer
+ if($key == $lastArrayKey) {
+ $finalArray=array_merge($finalArray,$buffeArray);
+ }
+
+ $previousValue = $row;
+ }
+
+ $this->db=$finalArray;
+ return true;
+ }
+
+ private function sortLowToHigh($a, $b) {
return $a['date']>$b['date'];
}
diff --git a/bl-kernel/dbsite.class.php b/bl-kernel/dbsite.class.php
index 26138464..a5932c19 100644
--- a/bl-kernel/dbsite.class.php
+++ b/bl-kernel/dbsite.class.php
@@ -8,6 +8,7 @@ class dbSite extends dbJSON
'description'=> array('inFile'=>false, 'value'=>''),
'footer'=> array('inFile'=>false, 'value'=>'I wanna be a pirate!'),
'postsperpage'=> array('inFile'=>false, 'value'=>''),
+ 'shuffleIdeticalTags'=> array('inFile'=>false, 'value'=>''),
'language'=> array('inFile'=>false, 'value'=>'en'),
'locale'=> array('inFile'=>false, 'value'=>'en_US'),
'timezone'=> array('inFile'=>false, 'value'=>'America/Argentina/Buenos_Aires'),
@@ -51,13 +52,13 @@ class dbSite extends dbJSON
{
foreach($args as $field=>$value)
{
- if( isset($this->dbFields[$field]) )
+ if( isset($this->dbFields[$field]) )
{
$this->db[$field] = Sanitize::html($value);
- }
- }
-
- if( $this->save() === false ) {
+ }
+ }
+
+ if( $this->save() === false ) {
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.');
return false;
}
@@ -238,6 +239,12 @@ class dbSite extends dbJSON
{
return $this->getField('postsperpage');
}
+
+ // Returns if tags mix is enabled.
+ public function shuffleIdeticalTags()
+ {
+ return $this->getField('shuffleIdeticalTags');
+ }
// Returns the current language.
public function language()
diff --git a/bl-kernel/functions.php b/bl-kernel/functions.php
index f8e486a1..564ed678 100644
--- a/bl-kernel/functions.php
+++ b/bl-kernel/functions.php
@@ -27,16 +27,16 @@ function buildPost($key)
global $Parsedown;
global $Site;
- // Post object, content from FILE.
+ // Post object, content from FILE.
$Post = new Post($key);
- if( !$Post->isValid() ) {
+ if( !$Post->isValid() ) {
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying build the post from file with key: '.$key);
return false;
}
// Post database, content from DATABASE JSON.
$db = $dbPosts->getPostDB($key);
- if( !$db ) {
+ if( !$db ) {
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying build the post from database with key: '.$key);
return false;
}
@@ -45,8 +45,8 @@ function buildPost($key)
foreach($db as $field=>$value) {
$Post->setField($field, $value);
}
-
- // Content in raw format
+
+ // Content in raw format
$contentRaw = $Post->content();
$Post->setField('contentRaw', $contentRaw, true);
@@ -72,7 +72,7 @@ function buildPost($key)
$username = $Post->username();
$Post->setField('user', $dbUsers->getUser($username));
- return $Post;
+ return $Post;
}
function buildPostsForPage($pageNumber=0, $amount=POSTS_PER_PAGE_ADMIN, $removeUnpublished=true, $tagKey=false)
@@ -105,8 +105,29 @@ function buildPostsForPage($pageNumber=0, $amount=POSTS_PER_PAGE_ADMIN, $removeU
array_push($posts, $Post);
}
}
+ return $posts;
+}
- return $posts;
+function buildTagPosts($tag,$amount=3, $pageNumber=0){
+ global $dbTags;
+ $posts=array();
+ $tag=str_replace(" ", "-",$tag);
+
+ $keys= $dbTags->getList($pageNumber, $amount, $tag);
+ foreach($keys as $key=>$value) {
+ $Post = buildPost($key);
+
+ if($Post==false){
+ break;
+ }
+ $posts['itms'][$key]=$Post->vars;
+ $posts['itms'][$key]['permalink']=$Post->permalink();
+ }
+
+ $posts['count']=$dbTags->countPostsByTag($tag);
+ $posts['page']=$pageNumber;
+
+ return $posts;
}
// PAGE FUNCTIONS
@@ -193,7 +214,7 @@ function buildAllPages()
// Remove the error page
unset($list['error']);
- // Sorte pages
+ // Sort pages
uasort($list, 'sortPages');
foreach($list as $key=>$db)
diff --git a/bl-kernel/url.class.php b/bl-kernel/url.class.php
index daf55f26..4ac3af4f 100644
--- a/bl-kernel/url.class.php
+++ b/bl-kernel/url.class.php
@@ -18,11 +18,17 @@ class Url
// remove parameters GET, do not use parse_url because has problem with utf-8.
$explode = explode('?', $decode);
- $this->uri = $explode[0];
+ $this->uri = $explode[0];
- $this->parameters = $_GET;
+ // deal with server config when missing the get params
+ if(empty($_GET)){
+ isset($explode[1]) ? parse_str($explode[1], $this->parameters):"";
+ }
+ else{
+ $this->parameters=$_GET;
+ }
- $this->uriStrlen = Text::length($this->uri);
+ $this->uriStrlen = Text::length($this->uri);
$this->whereAmI = 'home';
@@ -142,12 +148,12 @@ class Url
public function pageNumber()
{
- if(isset($this->parameters['page'])) {
+ if(isset($this->parameters['page'])) {
return $this->parameters['page'];
}
return 0;
}
-
+
public function setNotFound($error = true)
{
$this->notFound = $error;
@@ -170,7 +176,7 @@ class Url
// Check if the filter is in the uri.
$position = Text::stringPosition($this->uri, $filter);
- // If the position is FALSE, the filter isn't in the URI.
+ // If the position is FALSE, the filter isn't in the URI.
if($position===false) {
return false;
}
diff --git a/bl-plugins/api/plugin.php b/bl-plugins/api/plugin.php
index 393d35ce..39cefa83 100644
--- a/bl-plugins/api/plugin.php
+++ b/bl-plugins/api/plugin.php
@@ -33,24 +33,29 @@ class pluginAPI extends Plugin {
$html .= '';
$html .= '