Tags improves

This commit is contained in:
dignajar 2015-09-18 00:24:10 -03:00
parent 696fd4475b
commit f7a1fde3fc
6 changed files with 111 additions and 48 deletions

View File

@ -226,7 +226,7 @@ function install($adminPassword, $email)
'error'=>array(
'description'=>'Error page',
'username'=>'admin',
'tags'=>'',
'tags'=>array(),
'status'=>'published',
'date'=>$currentDate,
'position'=>0
@ -241,7 +241,7 @@ function install($adminPassword, $email)
'description'=>'Welcome to Bludit',
'username'=>'admin',
'status'=>'published',
'tags'=>'bludit,cms,flat-file',
'tags'=>array('bludit'=>'Bludit','cms'=>'CMS','flat-files'=>'Flat files'),
'allowComments'=>false,
'date'=>$currentDate
)
@ -305,7 +305,8 @@ function install($adminPassword, $email)
array(
'postsIndex'=>array(
'bludit'=>array('name'=>'Bludit', 'posts'=>array('first-post')),
'cms'=>array('name'=>'cms', 'posts'=>array('first-post'))
'cms'=>array('name'=>'CMS', 'posts'=>array('first-post')),
'flat-files'=>array('name'=>'Flat files', 'posts'=>array('first-post'))
),
'pagesIndex'=>array()
),

View File

@ -9,7 +9,7 @@ class dbPages extends dbJSON
'content'=> array('inFile'=>true, 'value'=>''),
'description'=> array('inFile'=>false, 'value'=>''),
'username'=> array('inFile'=>false, 'value'=>''),
'tags'=> array('inFile'=>false, 'value'=>''),
'tags'=> array('inFile'=>false, 'value'=>array()),
'status'=> array('inFile'=>false, 'value'=>'draft'),
'date'=> array('inFile'=>false, 'value'=>0),
'position'=> array('inFile'=>false, 'value'=>0)
@ -43,6 +43,10 @@ class dbPages extends dbJSON
{
if( isset($args[$field]) )
{
if($field=='tags') {
$tmpValue = $this->generateTags($args['tags']);
}
else {
// Sanitize if will be saved on database.
if( !$options['inFile'] ) {
$tmpValue = Sanitize::html($args[$field]);
@ -51,6 +55,7 @@ class dbPages extends dbJSON
$tmpValue = $args[$field];
}
}
}
// Default value for the field.
else
{
@ -120,6 +125,10 @@ class dbPages extends dbJSON
{
if( isset($args[$field]) )
{
if($field=='tags') {
$tmpValue = $this->generateTags($args['tags']);
}
else {
// Sanitize if will be saved on database.
if( !$options['inFile'] ) {
$tmpValue = Sanitize::html($args[$field]);
@ -128,6 +137,7 @@ class dbPages extends dbJSON
$tmpValue = $args[$field];
}
}
}
// Default value for the field.
else
{
@ -285,6 +295,31 @@ class dbPages extends dbJSON
return $this->db;
}
// Returns an Array, array('tagSlug'=>'tagName')
// (string) $tags, tag list separeted by comma.
public function generateTags($tags)
{
$tmp = array();
$tags = trim($tags);
if(empty($tags)) {
return $tmp;
}
// Make array
$tags = explode(',', $tags);
foreach($tags as $tag)
{
$tag = trim($tag);
$tagKey = Text::cleanUrl($tag);
$tmp[$tagKey] = $tag;
}
return $tmp;
}
public function regenerateCli()
{
$db = $this->db;

View File

@ -8,7 +8,7 @@ class dbPosts extends dbJSON
'description'=> array('inFile'=>false, 'value'=>''),
'username'=> array('inFile'=>false, 'value'=>''),
'status'=> array('inFile'=>false, 'value'=>'draft'), // published, draft, scheduled
'tags'=> array('inFile'=>false, 'value'=>''),
'tags'=> array('inFile'=>false, 'value'=>array()),
'allowComments'=> array('inFile'=>false, 'value'=>false),
'date'=> array('inFile'=>false, 'value'=>'')
);
@ -112,17 +112,16 @@ class dbPosts extends dbJSON
$args['status'] = 'scheduled';
}
// Tags
if(Text::isNotEmpty($args['tags'])) {
$cleanTags = array_map('trim', explode(',', $args['tags']));
$args['tags'] = implode(',', $cleanTags);
}
// Verify arguments with the database fields.
foreach($this->dbFields as $field=>$options)
{
// If the field is in the arguments.
if( isset($args[$field]) )
{
if($field=='tags') {
$tmpValue = $this->generateTags($args['tags']);
}
else {
// Sanitize if will be saved on database.
if( !$options['inFile'] ) {
$tmpValue = Sanitize::html($args[$field]);
@ -131,7 +130,8 @@ class dbPosts extends dbJSON
$tmpValue = $args[$field];
}
}
// Default value for the field.
}
// Default value if not in the arguments.
else
{
$tmpValue = $options['value'];
@ -332,6 +332,31 @@ class dbPosts extends dbJSON
return false;
}
// Returns an Array, array('tagSlug'=>'tagName')
// (string) $tags, tag list separeted by comma.
public function generateTags($tags)
{
$tmp = array();
$tags = trim($tags);
if(empty($tags)) {
return $tmp;
}
// Make array
$tags = explode(',', $tags);
foreach($tags as $tag)
{
$tag = trim($tag);
$tagKey = Text::cleanUrl($tag);
$tmp[$tagKey] = $tag;
}
return $tmp;
}
// Sort posts by date.
public function sortByDate($HighToLow=true)
{

View File

@ -59,17 +59,10 @@ class dbTags extends dbJSON
// Foreach post
foreach($db as $postKey=>$values)
{
$explode = explode(',', $values['tags']);
$tags = $values['tags'];
// Foreach tag from post
foreach($explode as $tagName)
{
$tagName = trim($tagName);
$tagKey = $tagName;
//$tagKey = Text::cleanUrl($tagName);
// If the tag is not empty.
if(Text::isNotEmpty($tagName))
foreach($tags as $tagKey=>$tagName)
{
if( isset($tagsIndex[$tagKey]) ) {
array_push($tagsIndex[$tagKey]['posts'], $postKey);
@ -80,7 +73,6 @@ class dbTags extends dbJSON
}
}
}
}
$this->db['postsIndex'] = $tagsIndex;

View File

@ -49,15 +49,24 @@ class Page extends fileContent
return $this->getField('description');
}
public function tags()
public function tags($returnsArray=false)
{
return $this->getField('tags');
global $Url;
$tags = $this->getField('tags');
if($returnsArray) {
if($tags==false) {
return array();
}
public function tagsArray()
{
$tags = $this->getField('tags');
return explode(',', $tags);
return $tags;
}
else {
// Return string with tags separeted by comma.
return implode(', ', $tags);
}
}
public function position()

View File

@ -123,10 +123,11 @@ class Post extends fileContent
return array();
}
return explode(',', $tags);
return $tags;
}
else {
return $tags;
// Return string with tags separeted by comma.
return implode(', ', $tags);
}
}