mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-08-05 16:17:28 +02:00
core: Add item uid (#1017)
'uid' represents the unique id for a feed item. This item is null by default and can be set to any string value. The provided string value is always hashed to sha1 to make it the same length in all cases. References #977, #1005
This commit is contained in:
@@ -55,6 +55,9 @@ class FeedItem {
|
||||
/** @var array List of category names or tags */
|
||||
protected $categories = array();
|
||||
|
||||
/** @var string Unique ID for the current item */
|
||||
protected $uid = null;
|
||||
|
||||
/** @var array Associative list of additional parameters */
|
||||
protected $misc = array(); // Custom parameters
|
||||
|
||||
@@ -391,6 +394,37 @@ class FeedItem {
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get unique id
|
||||
*
|
||||
* Use {@see FeedItem::setUid()} to set the unique id.
|
||||
*
|
||||
* @param string The unique id.
|
||||
*/
|
||||
public function getUid() {
|
||||
return $this->uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set unique id.
|
||||
*
|
||||
* Use {@see FeedItem::getUid()} to get the unique id.
|
||||
*
|
||||
* @param string $uid A string that uniquely identifies the current item
|
||||
* @return self
|
||||
*/
|
||||
public function setUid($uid) {
|
||||
$this->uid = null; // Clear previous data
|
||||
|
||||
if(!is_string($uid)) {
|
||||
Debug::log('Unique id must be a string!');
|
||||
} else {
|
||||
$this->uid = sha1($uid);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add miscellaneous elements to the item.
|
||||
*
|
||||
@@ -426,6 +460,7 @@ class FeedItem {
|
||||
'content' => $this->content,
|
||||
'enclosures' => $this->enclosures,
|
||||
'categories' => $this->categories,
|
||||
'uid' => $this->uid,
|
||||
), $this->misc
|
||||
);
|
||||
}
|
||||
@@ -454,6 +489,7 @@ class FeedItem {
|
||||
case 'content': $this->setContent($value); break;
|
||||
case 'enclosures': $this->setEnclosures($value); break;
|
||||
case 'categories': $this->setCategories($value); break;
|
||||
case 'uid': $this->setUid($value); break;
|
||||
default: $this->addMisc($name, $value);
|
||||
}
|
||||
}
|
||||
@@ -476,6 +512,7 @@ class FeedItem {
|
||||
case 'content': return $this->getContent();
|
||||
case 'enclosures': return $this->getEnclosures();
|
||||
case 'categories': return $this->getCategories();
|
||||
case 'uid': return $this->getUid();
|
||||
default:
|
||||
if(array_key_exists($name, $this->misc))
|
||||
return $this->misc[$name];
|
||||
|
Reference in New Issue
Block a user