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:
LogMANOriginal 2019-02-03 20:56:41 +01:00 committed by GitHub
parent a29512deee
commit 394149b114
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 71 additions and 23 deletions

View file

@ -16,21 +16,22 @@ class JsonFormat extends FormatAbstract {
'content',
'enclosures',
'categories',
'uid',
);
public function stringify(){
$urlScheme = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://';
$urlHost = (isset($_SERVER['HTTP_HOST'])) ? $_SERVER['HTTP_HOST'] : '';
$urlPath = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : '';
$urlRequest = (isset($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : '';
$urlPrefix = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://';
$urlHost = (isset($_SERVER['HTTP_HOST'])) ? $_SERVER['HTTP_HOST'] : '';
$urlPath = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : '';
$urlRequest = (isset($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : '';
$extraInfos = $this->getExtraInfos();
$data = array(
'version' => 'https://jsonfeed.org/version/1',
'title' => (!empty($extraInfos['name'])) ? $extraInfos['name'] : $urlHost,
'home_page_url' => (!empty($extraInfos['uri'])) ? $extraInfos['uri'] : REPOSITORY,
'feed_url' => $urlScheme . $urlHost . $urlRequest
'version' => 'https://jsonfeed.org/version/1',
'title' => (!empty($extraInfos['name'])) ? $extraInfos['name'] : $urlHost,
'home_page_url' => (!empty($extraInfos['uri'])) ? $extraInfos['uri'] : REPOSITORY,
'feed_url' => $urlPrefix . $urlHost . $urlRequest
);
if (!empty($extraInfos['icon'])) {
@ -42,20 +43,24 @@ class JsonFormat extends FormatAbstract {
foreach ($this->getItems() as $item) {
$entry = array();
$entryAuthor = $item->getAuthor();
$entryTitle = $item->getTitle();
$entryUri = $item->getURI();
$entryTimestamp = $item->getTimestamp();
$entryContent = $this->sanitizeHtml($item->getContent());
$entryEnclosures = $item->getEnclosures();
$entryCategories = $item->getCategories();
$entryAuthor = $item->getAuthor();
$entryTitle = $item->getTitle();
$entryUri = $item->getURI();
$entryTimestamp = $item->getTimestamp();
$entryContent = $this->sanitizeHtml($item->getContent());
$entryEnclosures = $item->getEnclosures();
$entryCategories = $item->getCategories();
$vendorFields = $item->toArray();
foreach (self::VENDOR_EXCLUDES as $key) {
unset($vendorFields[$key]);
}
$entry['id'] = $entryUri;
$entry['id'] = $item->getUid();
if (empty($entry['id'])) {
$entry['id'] = $entryUri;
}
if (!empty($entryTitle)) {
$entry['title'] = $entryTitle;
@ -82,8 +87,8 @@ class JsonFormat extends FormatAbstract {
$entry['attachments'] = array();
foreach ($entryEnclosures as $enclosure) {
$entry['attachments'][] = array(
'url' => $enclosure,
'mime_type' => getMimeType($enclosure)
'url' => $enclosure,
'mime_type' => getMimeType($enclosure)
);
}
}