diff options
Diffstat (limited to 'formats')
-rw-r--r-- | formats/AtomFormat.php | 11 | ||||
-rw-r--r-- | formats/JsonFormat.php | 41 |
2 files changed, 31 insertions, 21 deletions
diff --git a/formats/AtomFormat.php b/formats/AtomFormat.php index 1e01a0ff..02d7d61a 100644 --- a/formats/AtomFormat.php +++ b/formats/AtomFormat.php @@ -40,10 +40,15 @@ class AtomFormat extends FormatAbstract{ $entryTitle = $this->xml_encode($item->getTitle()); $entryContent = $item->getContent(); $entryUri = $item->getURI(); + $entryID = ''; - // the item id must be a valid unique URI - $entryID = $this->xml_encode($entryUri); - if (empty($entryID)) + if (!empty($item->getUid())) + $entryID = 'urn:sha1:' . $item->getUid(); + + if (empty($entryID)) // Fallback to provided URI + $entryID = $this->xml_encode($entryUri); + + if (empty($entryID)) // Fallback to title and content $entryID = 'urn:sha1:' . hash('sha1', $entryTitle . $entryContent); if (empty($entryTimestamp)) diff --git a/formats/JsonFormat.php b/formats/JsonFormat.php index fafe7a5a..5d091628 100644 --- a/formats/JsonFormat.php +++ b/formats/JsonFormat.php @@ -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) ); } } |