Version 4.1.2

This commit is contained in:
Neo committed 2025-12-19 05:32:19 -08:00
1 parent 3ba79295ee
commit 28bd025b35
1131 files changed
+63658 -20579

No files matched your search

+21 -5
View File
@@ -44,19 +44,35 @@ class _Atom extends SimpleXML
$articles = array();
foreach ( $this->entry as $item )
{
{
$link = NULL;
if ( isset( $item->link ) )
{
try
/* Links are object nodes with attributes we need to parse - try to find the right link */
$linkToCheck = NULL;
foreach( $item->link as $_link )
{
$link = \IPS\Http\Url::external( $item->link );
$attributes = $_link->attributes();
if( !isset( $attributes['rel'] ) OR ( isset( $attributes['rel'] ) AND $attributes['rel'] == 'alternate' ) )
{
$linkToCheck = $attributes['href'];
break;
}
}
if( $linkToCheck )
{
try
{
$link = \IPS\Http\Url::external( $linkToCheck );
}
catch ( \Exception $e ) { }
}
catch ( \Exception $e ) { }
}
$articles[ md5( $guidKey . ( (string) $item->id ) ) ] = array(
'title' => (string) $item->title,
'title' => ( (string) $item->title ) ?: ( mb_substr( strip_tags( $item->content ), 0, 47 ) . '...' ),
'content' => isset( $item->content ) ? (string) $item->content : (string) $item->title,
'date' => \IPS\DateTime::ts( strtotime( $item->updated ) ),
'link' => $link
+46 -14
View File
@@ -34,23 +34,19 @@ class _Rss extends SimpleXML
*/
public static function newDocument( \IPS\Http\Url $url, $title, $description )
{
$xml = new self( '<rss version="2.0" />' );
$xml = new static( '<rss version="2.0" />' );
$channel = $xml->addChild( 'channel' );
$channel->addChild( 'title', $title );
$channel->addChild( 'link', (string) $url );
$channel->addChild( 'description', $description );
/* Previously we were regexing and whitelisting language codes for some reason - we should just send the language code always.
@see https://community.invisionpower.com/4bugtrack/active-reports/4x-problems-with-the-right-alignment-system-rss-and-emails-r7792/ */
$locale = mb_strtolower( \IPS\Member::loggedIn()->language()->short );
foreach ( array( preg_replace( '/^(.+?)_(.+?)(\..+?)$/', '$1-$2', $locale ), preg_replace( '/^(.+?)_(.+?)(\..+?)$/', '$1', $locale ) ) as $langCodeToTry )
{
if ( in_array( $langCodeToTry, array( 'af', 'sq', 'eu', 'be', 'bg', 'ca', 'zh-cn', 'zh-tw', 'hr', 'cs', 'da', 'nl', 'nl-be', 'nl-nl', 'en', 'en-au', 'en-bz', 'en-ca', 'en-ie', 'en-jm', 'en-nz', 'en-ph', 'en-za', 'en-tt', 'en-gb', 'en-us', 'en-zw', 'et', 'fo', 'fi', 'fr', 'fr-be', 'fr-ca', 'fr-fr', 'fr-lu', 'fr-mc', 'fr-ch', 'gl', 'gd', 'de', 'de-at', 'de-de', 'de-li', 'de-lu', 'de-ch', 'el', 'haw', 'hu', 'is', 'in', 'ga', 'it', 'it-it', 'it-ch', 'ja', 'ko', 'mk', 'no', 'pl', 'pt', 'pt-br', 'pt-pt', 'ro', 'ro-mo', 'ro-ro', 'ru', 'ru-mo', 'ru-ru', 'sr', 'sk', 'sl', 'es', 'es-ar', 'es-bo', 'es-cl', 'es-co', 'es-cr', 'es-do', 'es-ec', 'es-sv', 'es-gt', 'es-hn', 'es-mx', 'es-ni', 'es-pa', 'es-py', 'es-pe', 'es-pr', 'es-es', 'es-uy', 'es-ve', 'sv', 'sv-fi', 'sv-se', 'tr', 'uk' ) ) )
{
$channel->addChild( 'language', $langCodeToTry );
break;
}
}
$locale = mb_substr( $locale, 0, mb_strpos( str_replace( '-', '_', $locale ), '_' ) );
$channel->addChild( 'language', $locale );
return $xml;
}
@@ -83,6 +79,22 @@ class _Rss extends SimpleXML
if ( $description !== NULL )
{
$description = preg_replace_callback( "/\s+?(srcset|src)=(['\"])\/\/([^'\"]+?)(['\"])/ims", function( $matches ){
$baseUrl = parse_url( \IPS\Settings::i()->base_url );
/* Try to preserve http vs https */
if( isset( $baseUrl['scheme'] ) )
{
$url = $baseUrl['scheme'] . '://' . $matches[3];
}
else
{
$url = 'http://' . $matches[3];
}
return " {$matches[1]}={$matches[2]}{$url}{$matches[2]}";
}, $description );
$item->addChild( 'description', $description );
}
@@ -119,7 +131,7 @@ class _Rss extends SimpleXML
foreach ( $this->channel->item as $item )
{
$link = NULL;
if ( $item->link )
if ( isset( $item->link ) AND $item->link )
{
try
{
@@ -146,10 +158,30 @@ class _Rss extends SimpleXML
}
$guid = md5( $guidKey . $guid );
$text = (string) $item->description;
/* If there is a <content:encoded> tag, get the contents of that instead of description */
if( count( $item->children( 'content', true ) ) AND count( $item->children( 'content', true )->encoded ) )
{
$text = (string) $item->children( 'content', true )->encoded[0];
}
/* Some feeds may not provide a pubDate for the Item or Channel in the feed. Work out which one exists and if neither do, use the current time */
$pubDate = NULL;
if ( $item->pubDate )
{
$pubDate = \IPS\DateTime::ts( strtotime( $item->pubDate ), TRUE );
}
if ( $pubDate === NULL AND $this->channel->pubDate )
{
$pubDate = \IPS\DateTime::ts( strtotime( $this->channel->pubDate ), TRUE );
}
$articles[ $guid ] = array(
'title' => ( (string) $item->title ) ?: ( mb_substr( $item->description, 0, 47 ) . '...' ),
'content' => (string) $item->description,
'date' => $item->pubDate ? \IPS\DateTime::ts( strtotime( $item->pubDate ), TRUE ) : \IPS\DateTime::ts( strtotime( $this->channel->pubDate ), TRUE ),
'title' => ( (string) $item->title ) ?: ( mb_substr( $text, 0, 47 ) . '...' ),
'content' => (string) $text,
'date' => $pubDate ?: \IPS\DateTime::create(),
'link' => $link
);
}