diff --git a/bl-kernel/abstract/content.class.php b/bl-kernel/abstract/content.class.php index c0eaf294..35eae21d 100644 --- a/bl-kernel/abstract/content.class.php +++ b/bl-kernel/abstract/content.class.php @@ -136,6 +136,12 @@ class Content { return $this->getField('readMore'); } + // Returns the unique identifier + public function uniqueId() + { + return $this->getField('uniqueId'); + } + // Returns the field key public function key() { @@ -291,6 +297,7 @@ class Content { public function json($returnsArray=false) { $tmp['key'] = $this->key(); + $tmp['uniqueId'] = $this->uniqueId(); $tmp['title'] = $this->title(); $tmp['content'] = $this->content(); // Markdown parsed $tmp['contentRaw'] = $this->contentRaw(); // No Markdown parsed diff --git a/bl-kernel/admin/controllers/dashboard.php b/bl-kernel/admin/controllers/dashboard.php index f08de032..e49d503a 100644 --- a/bl-kernel/admin/controllers/dashboard.php +++ b/bl-kernel/admin/controllers/dashboard.php @@ -32,6 +32,12 @@ function updateBludit() $checksum = md5_file(PATH_POSTS.$key.DS.FILENAME); $dbPosts->setPostDb($key, 'md5file', $checksum); } + + // Unique identifier + if( empty($post['uniqueId']) ) { + $uniqueId = generateUniqueId(); + $dbPosts->setPostDb($key, 'uniqueId', $uniqueId); + } } $dbPosts->save(); @@ -52,6 +58,12 @@ function updateBludit() $checksum = md5_file(PATH_PAGES.$key.DS.FILENAME); $dbPages->setPageDb($key, 'md5file', $checksum); } + + // Unique identifier + if( empty($page['uniqueId']) ) { + $uniqueId = generateUniqueId(); + $dbPages->setPageDb($key, 'uniqueId', $uniqueId); + } } $dbPages->save(); diff --git a/bl-kernel/boot/init.php b/bl-kernel/boot/init.php index 34fd3e5c..2e43734b 100644 --- a/bl-kernel/boot/init.php +++ b/bl-kernel/boot/init.php @@ -273,3 +273,9 @@ $Url->checkFilters( $Site->uriFilters() ); // --- Objects shortcuts --- $L = $Language; + +// Function for generating unique identifiers +function generateUniqueId() +{ + return md5(uniqid('', true)); +} diff --git a/bl-kernel/dbpages.class.php b/bl-kernel/dbpages.class.php index 0a52ce7e..8c827d0f 100644 --- a/bl-kernel/dbpages.class.php +++ b/bl-kernel/dbpages.class.php @@ -7,6 +7,7 @@ class dbPages extends dbJSON private $dbFields = array( 'title'=> array('inFile'=>true, 'value'=>''), 'content'=> array('inFile'=>true, 'value'=>''), + 'uniqueId'=> array('inFile'=>false, 'value'=>''), 'description'=> array('inFile'=>false, 'value'=>''), 'username'=> array('inFile'=>false, 'value'=>''), 'tags'=> array('inFile'=>false, 'value'=>array()), @@ -28,6 +29,11 @@ class dbPages extends dbJSON $dataForFile = array(); // This data will be saved in the file $key = $this->generateKey($args['slug'], $args['parent']); + + // Generate unique identifier + if( empty($args['uniqueId']) ) { + $args['uniqueId'] = generateUniqueId(); + } // The user is always the one loggued. $args['username'] = Session::get('username'); @@ -105,6 +111,11 @@ class dbPages extends dbJSON $dataForFile = array(); $newKey = $this->generateKey($args['slug'], $args['parent'], false, $args['key']); + + // Generate unique identifier + if( empty($args['uniqueId']) ) { + $args['uniqueId'] = generateUniqueId(); + } // The user is always the one loggued. $args['username'] = Session::get('username'); diff --git a/bl-kernel/dbposts.class.php b/bl-kernel/dbposts.class.php index 72bac5cf..40a6dbd9 100644 --- a/bl-kernel/dbposts.class.php +++ b/bl-kernel/dbposts.class.php @@ -5,6 +5,7 @@ class dbPosts extends dbJSON private $dbFields = array( 'title'=> array('inFile'=>true, 'value'=>''), 'content'=> array('inFile'=>true, 'value'=>''), + 'uniqueId'=> array('inFile'=>false, 'value'=>''), 'description'=> array('inFile'=>false, 'value'=>''), 'username'=> array('inFile'=>false, 'value'=>''), 'status'=> array('inFile'=>false, 'value'=>'draft'), // published, draft, scheduled @@ -113,6 +114,11 @@ class dbPosts extends dbJSON // Generate the database key / index $key = $this->generateKey($args['slug']); + + // Generate unique identifier + if( empty($args['uniqueId']) ) { + $args['uniqueId'] = generateUniqueId(); + } // The user is always who is loggued $args['username'] = Session::get('username');