diff --git a/install.php b/install.php index af59ef8e..844cf5a4 100644 --- a/install.php +++ b/install.php @@ -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() ), diff --git a/kernel/dbpages.class.php b/kernel/dbpages.class.php index 9d0331ea..4be86e09 100644 --- a/kernel/dbpages.class.php +++ b/kernel/dbpages.class.php @@ -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; diff --git a/kernel/dbposts.class.php b/kernel/dbposts.class.php index 93d5cce1..57d23dd4 100644 --- a/kernel/dbposts.class.php +++ b/kernel/dbposts.class.php @@ -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) { diff --git a/kernel/dbtags.class.php b/kernel/dbtags.class.php index 92d7b824..8ab3b6bd 100644 --- a/kernel/dbtags.class.php +++ b/kernel/dbtags.class.php @@ -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); } } } diff --git a/kernel/page.class.php b/kernel/page.class.php index 9335b445..8b4431da 100644 --- a/kernel/page.class.php +++ b/kernel/page.class.php @@ -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() diff --git a/kernel/post.class.php b/kernel/post.class.php index 373d229f..0da32994 100644 --- a/kernel/post.class.php +++ b/kernel/post.class.php @@ -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); } }