Tags improves
This commit is contained in:
parent
696fd4475b
commit
f7a1fde3fc
|
@ -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()
|
||||
),
|
||||
|
|
|
@ -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,12 +43,17 @@ class dbPages extends dbJSON
|
|||
{
|
||||
if( isset($args[$field]) )
|
||||
{
|
||||
// Sanitize if will be saved on database.
|
||||
if( !$options['inFile'] ) {
|
||||
$tmpValue = Sanitize::html($args[$field]);
|
||||
if($field=='tags') {
|
||||
$tmpValue = $this->generateTags($args['tags']);
|
||||
}
|
||||
else {
|
||||
$tmpValue = $args[$field];
|
||||
// Sanitize if will be saved on database.
|
||||
if( !$options['inFile'] ) {
|
||||
$tmpValue = Sanitize::html($args[$field]);
|
||||
}
|
||||
else {
|
||||
$tmpValue = $args[$field];
|
||||
}
|
||||
}
|
||||
}
|
||||
// Default value for the field.
|
||||
|
@ -120,12 +125,17 @@ class dbPages extends dbJSON
|
|||
{
|
||||
if( isset($args[$field]) )
|
||||
{
|
||||
// Sanitize if will be saved on database.
|
||||
if( !$options['inFile'] ) {
|
||||
$tmpValue = Sanitize::html($args[$field]);
|
||||
if($field=='tags') {
|
||||
$tmpValue = $this->generateTags($args['tags']);
|
||||
}
|
||||
else {
|
||||
$tmpValue = $args[$field];
|
||||
// Sanitize if will be saved on database.
|
||||
if( !$options['inFile'] ) {
|
||||
$tmpValue = Sanitize::html($args[$field]);
|
||||
}
|
||||
else {
|
||||
$tmpValue = $args[$field];
|
||||
}
|
||||
}
|
||||
}
|
||||
// Default value for the field.
|
||||
|
@ -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;
|
||||
|
|
|
@ -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,26 +112,26 @@ 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]) )
|
||||
{
|
||||
// Sanitize if will be saved on database.
|
||||
if( !$options['inFile'] ) {
|
||||
$tmpValue = Sanitize::html($args[$field]);
|
||||
if($field=='tags') {
|
||||
$tmpValue = $this->generateTags($args['tags']);
|
||||
}
|
||||
else {
|
||||
$tmpValue = $args[$field];
|
||||
// Sanitize if will be saved on database.
|
||||
if( !$options['inFile'] ) {
|
||||
$tmpValue = Sanitize::html($args[$field]);
|
||||
}
|
||||
else {
|
||||
$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)
|
||||
{
|
||||
|
|
|
@ -59,25 +59,17 @@ 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)
|
||||
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]) ) {
|
||||
array_push($tagsIndex[$tagKey]['posts'], $postKey);
|
||||
}
|
||||
else {
|
||||
$tagsIndex[$tagKey]['name'] = $tagName;
|
||||
$tagsIndex[$tagKey]['posts'] = array($postKey);
|
||||
}
|
||||
if( isset($tagsIndex[$tagKey]) ) {
|
||||
array_push($tagsIndex[$tagKey]['posts'], $postKey);
|
||||
}
|
||||
else {
|
||||
$tagsIndex[$tagKey]['name'] = $tagName;
|
||||
$tagsIndex[$tagKey]['posts'] = array($postKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
public function tagsArray()
|
||||
{
|
||||
$tags = $this->getField('tags');
|
||||
return explode(',', $tags);
|
||||
|
||||
if($returnsArray) {
|
||||
|
||||
if($tags==false) {
|
||||
return array();
|
||||
}
|
||||
|
||||
return $tags;
|
||||
}
|
||||
else {
|
||||
// Return string with tags separeted by comma.
|
||||
return implode(', ', $tags);
|
||||
}
|
||||
}
|
||||
|
||||
public function position()
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue