Add a unique identifier for blog posts and pages
The unique identifier is permanently attached to the post or page and doesn't change during its lifetime. It can be used for many purposes that require identification, such as Disqus comment threads (to avoid thread duplication), redirection of old URLs, etc. Signed-off-by: ADTC <send2adtc@gmail.com>
This commit is contained in:
parent
d1c88a6fdb
commit
c5dde14783
@ -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
|
||||
|
@ -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();
|
||||
|
@ -273,3 +273,9 @@ $Url->checkFilters( $Site->uriFilters() );
|
||||
|
||||
// --- Objects shortcuts ---
|
||||
$L = $Language;
|
||||
|
||||
// Function for generating unique identifiers
|
||||
function generateUniqueId()
|
||||
{
|
||||
return md5(uniqid('', true));
|
||||
}
|
||||
|
@ -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()),
|
||||
@ -29,6 +30,11 @@ class dbPages extends dbJSON
|
||||
|
||||
$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');
|
||||
if( Text::isEmpty($args['username']) ) {
|
||||
@ -106,6 +112,11 @@ class dbPages extends dbJSON
|
||||
|
||||
$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');
|
||||
if( Text::isEmpty($args['username']) ) {
|
||||
|
@ -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
|
||||
@ -114,6 +115,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');
|
||||
if( Text::isEmpty($args['username']) ) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user