2015-03-02 22:22:02 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Mrss
|
|
|
|
* Documentation Source http://www.rssboard.org/media-rss
|
|
|
|
*/
|
2016-09-10 20:41:11 +02:00
|
|
|
class MrssFormat extends FormatAbstract {
|
|
|
|
public function stringify(){
|
|
|
|
$https = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 's' : '';
|
|
|
|
$httpHost = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '';
|
|
|
|
$httpInfo = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '';
|
2015-03-02 22:22:02 +01:00
|
|
|
|
2018-10-15 18:14:06 +02:00
|
|
|
$serverRequestUri = isset($_SERVER['REQUEST_URI']) ? $this->xml_encode($_SERVER['REQUEST_URI']) : '';
|
2015-03-02 22:22:02 +01:00
|
|
|
|
2016-09-10 20:41:11 +02:00
|
|
|
$extraInfos = $this->getExtraInfos();
|
|
|
|
$title = $this->xml_encode($extraInfos['name']);
|
2016-09-10 21:01:02 +02:00
|
|
|
|
2017-07-29 19:28:00 +02:00
|
|
|
if(!empty($extraInfos['uri'])) {
|
2016-09-10 21:01:02 +02:00
|
|
|
$uri = $this->xml_encode($extraInfos['uri']);
|
|
|
|
} else {
|
2018-11-05 19:05:59 +01:00
|
|
|
$uri = REPOSITORY;
|
2016-09-10 21:01:02 +02:00
|
|
|
}
|
|
|
|
|
2018-06-30 10:16:16 +02:00
|
|
|
$uriparts = parse_url($uri);
|
2018-11-05 12:55:58 +01:00
|
|
|
$icon = $this->xml_encode($uriparts['scheme'] . '://' . $uriparts['host'] . '/favicon.ico');
|
2015-03-02 22:22:02 +01:00
|
|
|
|
2016-09-10 20:41:11 +02:00
|
|
|
$items = '';
|
2017-07-29 19:28:00 +02:00
|
|
|
foreach($this->getItems() as $item) {
|
2016-09-10 20:41:11 +02:00
|
|
|
$itemAuthor = isset($item['author']) ? $this->xml_encode($item['author']) : '';
|
|
|
|
$itemTitle = strip_tags(isset($item['title']) ? $this->xml_encode($item['title']) : '');
|
|
|
|
$itemUri = isset($item['uri']) ? $this->xml_encode($item['uri']) : '';
|
|
|
|
$itemTimestamp = isset($item['timestamp']) ? $this->xml_encode(date(DATE_RFC2822, $item['timestamp'])) : '';
|
|
|
|
$itemContent = isset($item['content']) ? $this->xml_encode($this->sanitizeHtml($item['content'])) : '';
|
2016-11-09 18:59:17 +01:00
|
|
|
|
2016-11-12 22:04:42 +01:00
|
|
|
$entryEnclosuresWarning = '';
|
|
|
|
$entryEnclosures = '';
|
2017-07-29 19:28:00 +02:00
|
|
|
if(isset($item['enclosures'])) {
|
2016-11-12 22:04:42 +01:00
|
|
|
$entryEnclosures .= '<enclosure url="'
|
|
|
|
. $this->xml_encode($item['enclosures'][0])
|
Catching up | [Main] Debug mode, parse utils, MIME | [Bridges] Add/Improve 20 bridges (#802)
* Debug mode improvements
- Improve debug warning message
- Restore error reporting in debug mode
- Fix 'notice' messages for unset fields
* Add parsing utility functions
html.php
- extractFromDelimiters
- stripWithDelimiters
- stripRecursiveHTMLSection
- markdownToHtml (partial)
bridges
- remove now-duplicate functions
- call functions from html.php instead
* [Anidex] New bridge
Anime torrent tracker
* [Anime-Ultime] Restore thumbnail
* [CNET] Recreate bridge
Full rewrite as the previous one was broken
* [Dilbert] Minor URI fix
Use new self::URI property
* [EstCeQuonMetEnProd] Fix content extraction
Bridge was broken
* [Facebook] Fix "SpSonsSoriSsés" label
... which was taking space in item title
* [Futura-Sciences] Use HTTPS, More cleanup
Use HTTPS as FS now offer HTTPS
Clean additional useless HTML elements
* [GBATemp] Multiple fixes
- Fix categories: missing "break" statements
- Restore thumbnail as enclosure
- Fix date extraction
- Fix user blog post extraction
- Use getSimpleHTMLDOMCached
* [JapanExpo] Fix bridge, HTTPS, thumbnails
- Fix getSimpleHTMLDOMCached call
- Upgrade to HTTPS as JE now offers HTTPS
- Restore thumbnails as enclosures
* [LeMondeInformatique] Fix bridge, HTTPS
- Upgrade to HTTPS as LMI now offers HTTPS
- Restore thumbnails using small images
- Fix content extraction
- Fix text encoding issue
* [Nextgov] Fix content extraction
- Restore thumbnail and use small image
- Field extraction fixes
* [NextInpact] Add categories and filtering by type
- Offer all RSS feeds
- Allow filtering by article type
- Implement extraction for brief articles
- Remove article limit, many brief articles are publied all at once
* [NyaaTorrents] New bridge
Anime torrent tracker
* [Releases3DS] Cache content, restore thumbnail
- Use getSimpleHTMLDOMCached
- Restore thumbnail as enclosure
* [TheHackerNews] Fix bridge
- Fix content extraction including article body
- Restore thumbnail as enclosure
* [WeLiveSecurity] HTTPS, Fix content extraction
- Upgrade to HTTPS as WLS now offers HTTPS
- Fix content extraction including article body
* [WordPress] Reduce timeout, more content selectors
- Reduce timeout to use default one (1h)
- Add new content selector (articleBody)
- Find thumbnail and set as enclosure
- Fix <script> cleanup
* [YGGTorrent] Increase limit, use cache
- Increase item limit as uploads are very frequent
- Use getSimpleHTMLDOMCached
* [ZDNet] Rewrite with FeedExpander
- Upgrade to HTTPS as ZD now offers HTTPS
- Use FeedExpander for secondary fields
- Fix content extraction for article body
* [Main] Handle MIME type for enclosures
Many feed readers will ignore enclosures (e.g. thumbnails) with no MIME type. This commit adds automatic MIME type detection based on file extension (which may be inaccurate but is the only way without fetching the content).
One can force enclosure type using #.ext anchor (hacky, needs improving)
* [FeedExpander] Improve field extraction
- Add support for passing enclosures
- Improve author and uri extraction
- Fix 'notice' PHP error messages
* [Pull] Coding style fixes for #802
* [Pull] Implementing changes for #802
- Fix coding style issues with str append
- Remove useless CACHE_TIMEOUT
- Use count() instead of $limit
- Use defaultLinkTo() + handle strings
- Use http_build_query()
- Fix missing </em>
- Remove error_reporting(0)
- warning CSS (@LogMANOriginal)
- Fix typo in FeedExpander comment
* [Main] More documentation for markdownToHtml
See #802 for more details
2018-09-09 21:20:13 +02:00
|
|
|
. '" type="' . getMimeType($item['enclosures'][0]) . '" />';
|
2016-11-12 22:04:42 +01:00
|
|
|
|
2017-07-29 19:28:00 +02:00
|
|
|
if(count($item['enclosures']) > 1) {
|
2016-11-12 22:04:42 +01:00
|
|
|
$entryEnclosures .= PHP_EOL;
|
|
|
|
$entryEnclosuresWarning = '<br>Warning:
|
|
|
|
Some media files might not be shown to you. Consider using the ATOM format instead!';
|
2017-07-29 19:28:00 +02:00
|
|
|
foreach($item['enclosures'] as $enclosure) {
|
2016-11-12 22:04:42 +01:00
|
|
|
$entryEnclosures .= '<atom:link rel="enclosure" href="'
|
Catching up | [Main] Debug mode, parse utils, MIME | [Bridges] Add/Improve 20 bridges (#802)
* Debug mode improvements
- Improve debug warning message
- Restore error reporting in debug mode
- Fix 'notice' messages for unset fields
* Add parsing utility functions
html.php
- extractFromDelimiters
- stripWithDelimiters
- stripRecursiveHTMLSection
- markdownToHtml (partial)
bridges
- remove now-duplicate functions
- call functions from html.php instead
* [Anidex] New bridge
Anime torrent tracker
* [Anime-Ultime] Restore thumbnail
* [CNET] Recreate bridge
Full rewrite as the previous one was broken
* [Dilbert] Minor URI fix
Use new self::URI property
* [EstCeQuonMetEnProd] Fix content extraction
Bridge was broken
* [Facebook] Fix "SpSonsSoriSsés" label
... which was taking space in item title
* [Futura-Sciences] Use HTTPS, More cleanup
Use HTTPS as FS now offer HTTPS
Clean additional useless HTML elements
* [GBATemp] Multiple fixes
- Fix categories: missing "break" statements
- Restore thumbnail as enclosure
- Fix date extraction
- Fix user blog post extraction
- Use getSimpleHTMLDOMCached
* [JapanExpo] Fix bridge, HTTPS, thumbnails
- Fix getSimpleHTMLDOMCached call
- Upgrade to HTTPS as JE now offers HTTPS
- Restore thumbnails as enclosures
* [LeMondeInformatique] Fix bridge, HTTPS
- Upgrade to HTTPS as LMI now offers HTTPS
- Restore thumbnails using small images
- Fix content extraction
- Fix text encoding issue
* [Nextgov] Fix content extraction
- Restore thumbnail and use small image
- Field extraction fixes
* [NextInpact] Add categories and filtering by type
- Offer all RSS feeds
- Allow filtering by article type
- Implement extraction for brief articles
- Remove article limit, many brief articles are publied all at once
* [NyaaTorrents] New bridge
Anime torrent tracker
* [Releases3DS] Cache content, restore thumbnail
- Use getSimpleHTMLDOMCached
- Restore thumbnail as enclosure
* [TheHackerNews] Fix bridge
- Fix content extraction including article body
- Restore thumbnail as enclosure
* [WeLiveSecurity] HTTPS, Fix content extraction
- Upgrade to HTTPS as WLS now offers HTTPS
- Fix content extraction including article body
* [WordPress] Reduce timeout, more content selectors
- Reduce timeout to use default one (1h)
- Add new content selector (articleBody)
- Find thumbnail and set as enclosure
- Fix <script> cleanup
* [YGGTorrent] Increase limit, use cache
- Increase item limit as uploads are very frequent
- Use getSimpleHTMLDOMCached
* [ZDNet] Rewrite with FeedExpander
- Upgrade to HTTPS as ZD now offers HTTPS
- Use FeedExpander for secondary fields
- Fix content extraction for article body
* [Main] Handle MIME type for enclosures
Many feed readers will ignore enclosures (e.g. thumbnails) with no MIME type. This commit adds automatic MIME type detection based on file extension (which may be inaccurate but is the only way without fetching the content).
One can force enclosure type using #.ext anchor (hacky, needs improving)
* [FeedExpander] Improve field extraction
- Add support for passing enclosures
- Improve author and uri extraction
- Fix 'notice' PHP error messages
* [Pull] Coding style fixes for #802
* [Pull] Implementing changes for #802
- Fix coding style issues with str append
- Remove useless CACHE_TIMEOUT
- Use count() instead of $limit
- Use defaultLinkTo() + handle strings
- Use http_build_query()
- Fix missing </em>
- Remove error_reporting(0)
- warning CSS (@LogMANOriginal)
- Fix typo in FeedExpander comment
* [Main] More documentation for markdownToHtml
See #802 for more details
2018-09-09 21:20:13 +02:00
|
|
|
. $enclosure . '" type="' . getMimeType($enclosure) . '" />'
|
2016-11-12 22:04:42 +01:00
|
|
|
. PHP_EOL;
|
|
|
|
}
|
|
|
|
}
|
2016-11-09 18:59:17 +01:00
|
|
|
}
|
|
|
|
|
2018-07-16 12:32:24 +02:00
|
|
|
$entryCategories = '';
|
|
|
|
if(isset($item['categories'])) {
|
|
|
|
|
|
|
|
foreach($item['categories'] as $category) {
|
|
|
|
$entryCategories .= '<category>'
|
2018-11-05 12:55:58 +01:00
|
|
|
. $category . '</category>'
|
2018-07-16 12:32:24 +02:00
|
|
|
. PHP_EOL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-10 20:41:11 +02:00
|
|
|
$items .= <<<EOD
|
2015-03-02 22:22:02 +01:00
|
|
|
|
2016-09-10 20:41:11 +02:00
|
|
|
<item>
|
|
|
|
<title>{$itemTitle}</title>
|
|
|
|
<link>{$itemUri}</link>
|
|
|
|
<guid isPermaLink="true">{$itemUri}</guid>
|
|
|
|
<pubDate>{$itemTimestamp}</pubDate>
|
2016-11-12 22:04:42 +01:00
|
|
|
<description>{$itemContent}{$entryEnclosuresWarning}</description>
|
2016-09-10 20:41:11 +02:00
|
|
|
<author>{$itemAuthor}</author>
|
2016-11-12 22:04:42 +01:00
|
|
|
{$entryEnclosures}
|
2018-07-16 12:32:24 +02:00
|
|
|
{$entryCategories}
|
2016-09-10 20:41:11 +02:00
|
|
|
</item>
|
2015-03-02 22:22:02 +01:00
|
|
|
|
|
|
|
EOD;
|
2016-09-10 20:41:11 +02:00
|
|
|
}
|
2015-03-02 22:22:02 +01:00
|
|
|
|
2016-11-07 20:49:44 +01:00
|
|
|
$charset = $this->getCharset();
|
|
|
|
|
2018-09-15 14:13:05 +02:00
|
|
|
/* xml attributes need to have certain characters escaped to be w3c compliant */
|
|
|
|
$imageTitle = htmlspecialchars($title, ENT_COMPAT);
|
2016-09-10 20:41:11 +02:00
|
|
|
/* Data are prepared, now let's begin the "MAGIE !!!" */
|
2016-11-07 20:49:44 +01:00
|
|
|
$toReturn = <<<EOD
|
|
|
|
<?xml version="1.0" encoding="{$charset}"?>
|
|
|
|
<rss version="2.0"
|
|
|
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
|
|
|
xmlns:media="http://search.yahoo.com/mrss/"
|
2016-09-10 21:01:02 +02:00
|
|
|
xmlns:atom="http://www.w3.org/2005/Atom">
|
2016-09-10 20:41:11 +02:00
|
|
|
<channel>
|
|
|
|
<title>{$title}</title>
|
|
|
|
<link>http{$https}://{$httpHost}{$httpInfo}/</link>
|
|
|
|
<description>{$title}</description>
|
2018-09-15 14:13:05 +02:00
|
|
|
<image url="{$icon}" title="{$imageTitle}" link="{$uri}"/>
|
2016-09-10 20:41:11 +02:00
|
|
|
<atom:link rel="alternate" type="text/html" href="{$uri}" />
|
|
|
|
<atom:link rel="self" href="http{$https}://{$httpHost}{$serverRequestUri}" />
|
|
|
|
{$items}
|
|
|
|
</channel>
|
2015-03-02 22:22:02 +01:00
|
|
|
</rss>
|
|
|
|
EOD;
|
|
|
|
|
2016-09-10 20:41:11 +02:00
|
|
|
// Remove invalid non-UTF8 characters
|
|
|
|
ini_set('mbstring.substitute_character', 'none');
|
2016-11-07 20:49:44 +01:00
|
|
|
$toReturn = mb_convert_encoding($toReturn, $this->getCharset(), 'UTF-8');
|
2016-09-10 20:41:11 +02:00
|
|
|
return $toReturn;
|
|
|
|
}
|
2015-03-02 22:22:02 +01:00
|
|
|
|
2016-09-10 20:41:11 +02:00
|
|
|
public function display(){
|
|
|
|
$this
|
2016-11-07 20:49:44 +01:00
|
|
|
->setContentType('application/rss+xml; charset=' . $this->getCharset())
|
2016-09-10 20:41:11 +02:00
|
|
|
->callContentType();
|
2015-03-02 22:22:02 +01:00
|
|
|
|
2016-09-10 20:41:11 +02:00
|
|
|
return parent::display();
|
|
|
|
}
|
2016-08-09 17:05:29 +02:00
|
|
|
|
2016-09-10 20:41:11 +02:00
|
|
|
private function xml_encode($text){
|
|
|
|
return htmlspecialchars($text, ENT_XML1);
|
|
|
|
}
|
2015-03-02 22:22:02 +01:00
|
|
|
}
|