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

View File

@ -9,7 +9,7 @@ class dbPages extends dbJSON
'content'=> array('inFile'=>true, 'value'=>''), 'content'=> array('inFile'=>true, 'value'=>''),
'description'=> array('inFile'=>false, 'value'=>''), 'description'=> array('inFile'=>false, 'value'=>''),
'username'=> 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'), 'status'=> array('inFile'=>false, 'value'=>'draft'),
'date'=> array('inFile'=>false, 'value'=>0), 'date'=> array('inFile'=>false, 'value'=>0),
'position'=> array('inFile'=>false, 'value'=>0) 'position'=> array('inFile'=>false, 'value'=>0)
@ -43,6 +43,10 @@ class dbPages extends dbJSON
{ {
if( isset($args[$field]) ) if( isset($args[$field]) )
{ {
if($field=='tags') {
$tmpValue = $this->generateTags($args['tags']);
}
else {
// Sanitize if will be saved on database. // Sanitize if will be saved on database.
if( !$options['inFile'] ) { if( !$options['inFile'] ) {
$tmpValue = Sanitize::html($args[$field]); $tmpValue = Sanitize::html($args[$field]);
@ -51,6 +55,7 @@ class dbPages extends dbJSON
$tmpValue = $args[$field]; $tmpValue = $args[$field];
} }
} }
}
// Default value for the field. // Default value for the field.
else else
{ {
@ -120,6 +125,10 @@ class dbPages extends dbJSON
{ {
if( isset($args[$field]) ) if( isset($args[$field]) )
{ {
if($field=='tags') {
$tmpValue = $this->generateTags($args['tags']);
}
else {
// Sanitize if will be saved on database. // Sanitize if will be saved on database.
if( !$options['inFile'] ) { if( !$options['inFile'] ) {
$tmpValue = Sanitize::html($args[$field]); $tmpValue = Sanitize::html($args[$field]);
@ -128,6 +137,7 @@ class dbPages extends dbJSON
$tmpValue = $args[$field]; $tmpValue = $args[$field];
} }
} }
}
// Default value for the field. // Default value for the field.
else else
{ {
@ -285,6 +295,31 @@ class dbPages extends dbJSON
return $this->db; 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() public function regenerateCli()
{ {
$db = $this->db; $db = $this->db;

View File

@ -8,7 +8,7 @@ class dbPosts extends dbJSON
'description'=> array('inFile'=>false, 'value'=>''), 'description'=> array('inFile'=>false, 'value'=>''),
'username'=> array('inFile'=>false, 'value'=>''), 'username'=> array('inFile'=>false, 'value'=>''),
'status'=> array('inFile'=>false, 'value'=>'draft'), // published, draft, scheduled '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), 'allowComments'=> array('inFile'=>false, 'value'=>false),
'date'=> array('inFile'=>false, 'value'=>'') 'date'=> array('inFile'=>false, 'value'=>'')
); );
@ -112,17 +112,16 @@ class dbPosts extends dbJSON
$args['status'] = 'scheduled'; $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. // Verify arguments with the database fields.
foreach($this->dbFields as $field=>$options) foreach($this->dbFields as $field=>$options)
{ {
// If the field is in the arguments.
if( isset($args[$field]) ) if( isset($args[$field]) )
{ {
if($field=='tags') {
$tmpValue = $this->generateTags($args['tags']);
}
else {
// Sanitize if will be saved on database. // Sanitize if will be saved on database.
if( !$options['inFile'] ) { if( !$options['inFile'] ) {
$tmpValue = Sanitize::html($args[$field]); $tmpValue = Sanitize::html($args[$field]);
@ -131,7 +130,8 @@ class dbPosts extends dbJSON
$tmpValue = $args[$field]; $tmpValue = $args[$field];
} }
} }
// Default value for the field. }
// Default value if not in the arguments.
else else
{ {
$tmpValue = $options['value']; $tmpValue = $options['value'];
@ -332,6 +332,31 @@ class dbPosts extends dbJSON
return false; 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. // Sort posts by date.
public function sortByDate($HighToLow=true) public function sortByDate($HighToLow=true)
{ {

View File

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

View File

@ -49,15 +49,24 @@ class Page extends fileContent
return $this->getField('description'); 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() return $tags;
{ }
$tags = $this->getField('tags'); else {
return explode(',', $tags); // Return string with tags separeted by comma.
return implode(', ', $tags);
}
} }
public function position() public function position()

View File

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