Version 4.1.19
This commit is contained in:
1 parent
28bd025b35
commit
2bd5025018
2674 files changed
+233518
-77766
No files matched your search
+2
-2
@@ -2,9 +2,9 @@
|
||||
/**
|
||||
* @brief Class for managing Atom documents
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @package IPS Community Suite
|
||||
* @since 5 Feb 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Wrapper class for managing DOMDocument objects
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Community Suite
|
||||
* @since 5 July 2016
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\Xml;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper class for managing DOMDocument objects
|
||||
*/
|
||||
class _DOMDocument extends \DOMDocument
|
||||
{
|
||||
/**
|
||||
* Load XML from a file
|
||||
*
|
||||
* @param string $filename The filename
|
||||
* @param int $options Bitmask of LIBXML_* constants
|
||||
* @return bool
|
||||
* @note We are disabling the entity loader after opening the content to prevent XXE
|
||||
*/
|
||||
public function load( $filename, $options=0 )
|
||||
{
|
||||
libxml_use_internal_errors(TRUE);
|
||||
$entityLoaderValue = libxml_disable_entity_loader( false );
|
||||
$opened = parent::load( $filename, $options );
|
||||
libxml_disable_entity_loader( $entityLoaderValue );
|
||||
|
||||
return $opened;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load HTML from a string
|
||||
*
|
||||
* @param string $source The HTML to open
|
||||
* @param int $options Bitmask of LIBXML_* constants
|
||||
* @return bool
|
||||
* @note We are disabling the entity loader after opening the content to prevent XXE
|
||||
*/
|
||||
public function loadHTML( $source, $options=0 )
|
||||
{
|
||||
libxml_use_internal_errors(TRUE);
|
||||
$entityLoaderValue = libxml_disable_entity_loader( false );
|
||||
$opened = parent::loadHTML( $source, $options );
|
||||
libxml_disable_entity_loader( $entityLoaderValue );
|
||||
|
||||
return $opened;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load HTML from a file
|
||||
*
|
||||
* @param string $filename The filename
|
||||
* @param int $options Bitmask of LIBXML_* constants
|
||||
* @return bool
|
||||
* @note We are disabling the entity loader after opening the content to prevent XXE
|
||||
*/
|
||||
public function loadHTMLFile( $filename, $options=0 )
|
||||
{
|
||||
libxml_use_internal_errors(TRUE);
|
||||
$entityLoaderValue = libxml_disable_entity_loader( false );
|
||||
$opened = parent::loadHTMLFile( $filename, $options );
|
||||
libxml_disable_entity_loader( $entityLoaderValue );
|
||||
|
||||
return $opened;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load XML from a string
|
||||
*
|
||||
* @param string $source The HTML to open
|
||||
* @param int $options Bitmask of LIBXML_* constants
|
||||
* @return bool
|
||||
* @note We are disabling the entity loader after opening the content to prevent XXE
|
||||
*/
|
||||
public function loadXML( $source, $options=0 )
|
||||
{
|
||||
libxml_use_internal_errors(TRUE);
|
||||
$entityLoaderValue = libxml_disable_entity_loader( false );
|
||||
$opened = parent::loadXML( $source, $options );
|
||||
libxml_disable_entity_loader( $entityLoaderValue );
|
||||
|
||||
return $opened;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prefix HTML content with certain HTML to force DOMDocument to treat the content as UTF-8-encoded HTML
|
||||
*
|
||||
* @param string $content HTML content to prefix
|
||||
* @return string
|
||||
*/
|
||||
static public function wrapHtml( $content )
|
||||
{
|
||||
return "<!DOCTYPE html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'/></head>" . $content;
|
||||
}
|
||||
}
|
||||
+36
-12
@@ -2,9 +2,9 @@
|
||||
/**
|
||||
* @brief Class for managing RSS documents
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @package IPS Community Suite
|
||||
* @since 18 Feb 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
@@ -75,7 +75,7 @@ class _Rss extends SimpleXML
|
||||
$item->addChild( 'title', $title );
|
||||
}
|
||||
|
||||
$item->addChild( 'link', $link->rfc3986() );
|
||||
$item->addChild( 'link', (string) $link );
|
||||
|
||||
if ( $description !== NULL )
|
||||
{
|
||||
@@ -127,15 +127,16 @@ class _Rss extends SimpleXML
|
||||
*/
|
||||
public function articles( $guidKey=NULL )
|
||||
{
|
||||
$articles = array();
|
||||
foreach ( $this->channel->item as $item )
|
||||
$articles = array();
|
||||
$items = $this->getItems();
|
||||
foreach ( $items as $item )
|
||||
{
|
||||
$link = NULL;
|
||||
if ( isset( $item->link ) AND $item->link )
|
||||
{
|
||||
try
|
||||
{
|
||||
$link = \IPS\Http\Url::external( $item->link );
|
||||
$link = \IPS\Http\Url::external( (string) $item->link );
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
}
|
||||
@@ -158,7 +159,7 @@ class _Rss extends SimpleXML
|
||||
}
|
||||
$guid = md5( $guidKey . $guid );
|
||||
|
||||
$text = (string) $item->description;
|
||||
$text = isset( $item->description ) ? (string) $item->description : (string) $item->title;
|
||||
|
||||
/* 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 ) )
|
||||
@@ -167,11 +168,7 @@ class _Rss extends SimpleXML
|
||||
}
|
||||
|
||||
/* 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 );
|
||||
}
|
||||
$pubDate = $this->getDate( $item );
|
||||
|
||||
if ( $pubDate === NULL AND $this->channel->pubDate )
|
||||
{
|
||||
@@ -187,4 +184,31 @@ class _Rss extends SimpleXML
|
||||
}
|
||||
return $articles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the date
|
||||
*
|
||||
* @param object $item RSS item
|
||||
* @return NULL|\IPS\DateTime
|
||||
*/
|
||||
protected function getDate( $item )
|
||||
{
|
||||
$pubDate = NULL;
|
||||
if ( $item->pubDate )
|
||||
{
|
||||
$pubDate = \IPS\DateTime::ts( strtotime( $item->pubDate ), TRUE );
|
||||
}
|
||||
|
||||
return $pubDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the items
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getItems()
|
||||
{
|
||||
return $this->channel->item;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Class for reading an RSS 1.0 document
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Community Suite
|
||||
* @since 18 Dec 2015
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\Xml;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class for reading an RSS 1.0 document
|
||||
*/
|
||||
class _Rss1 extends Rss
|
||||
{
|
||||
/**
|
||||
* Fetch the date
|
||||
*
|
||||
* @param object $item RSS item
|
||||
* @return NULL|\IPS\DateTime
|
||||
*/
|
||||
protected function getDate( $item )
|
||||
{
|
||||
$pubDate = NULL;
|
||||
|
||||
/* If we use the Dublin Core (dc) namespace, we will probably have dc:date */
|
||||
$namespaces = $this->getNamespaces( TRUE );
|
||||
|
||||
if( in_array( 'http://purl.org/dc/elements/1.1/', $namespaces ) AND $item->children( $namespaces['dc'] )->date )
|
||||
{
|
||||
$pubDate = \IPS\DateTime::ts( strtotime( $item->children( $namespaces['dc'] )->date ) );
|
||||
}
|
||||
|
||||
return $pubDate ?: parent::getDate( $item );
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the items
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getItems()
|
||||
{
|
||||
return $this->item;
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,9 @@
|
||||
/**
|
||||
* @brief Class for managing small XML files
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @package IPS Community Suite
|
||||
* @since 18 Feb 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
@@ -22,18 +22,22 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
* Class for managing small XML files
|
||||
*/
|
||||
class _SimpleXML extends \SimpleXMLElement
|
||||
{
|
||||
{
|
||||
/**
|
||||
* Create New XML Document
|
||||
*
|
||||
* @param string $rootElement Name of Root Element
|
||||
* @param string|NULL $xmlns Namespace
|
||||
* @return \IPS\Xml\SimpleXML
|
||||
* @note We are disabling the entity loader after opening the content to prevent XXE
|
||||
*/
|
||||
public static function create( $rootElement, $xmlns=NULL )
|
||||
{
|
||||
$entityLoaderValue = libxml_disable_entity_loader( false );
|
||||
|
||||
$string = $xmlns ? "<?xml version='1.0' encoding='UTF-8'?><{$rootElement} xmlns='{$xmlns}'></{$rootElement}>" : "<?xml version='1.0' encoding='UTF-8'?><{$rootElement}></{$rootElement}>";
|
||||
$class = @simplexml_load_string( $string, get_called_class() );
|
||||
libxml_disable_entity_loader( $entityLoaderValue );
|
||||
return $class->subtype();
|
||||
}
|
||||
|
||||
@@ -43,14 +47,18 @@ class _SimpleXML extends \SimpleXMLElement
|
||||
* @param string $filename Filename of XML file
|
||||
* @return \IPS\Xml\SimpleXML
|
||||
* @throws \InvalidArgumentException
|
||||
* @note We are disabling the entity loader after opening the content to prevent XXE
|
||||
*/
|
||||
public static function loadFile( $filename )
|
||||
{
|
||||
$entityLoaderValue = libxml_disable_entity_loader( false );
|
||||
|
||||
$class = @simplexml_load_file( $filename, get_called_class() );
|
||||
if ( $class === FALSE )
|
||||
{
|
||||
throw new \InvalidArgumentException;
|
||||
}
|
||||
libxml_disable_entity_loader( $entityLoaderValue );
|
||||
return $class->subtype();
|
||||
}
|
||||
|
||||
@@ -60,14 +68,18 @@ class _SimpleXML extends \SimpleXMLElement
|
||||
* @param string $xml XML
|
||||
* @return \IPS\Xml\SimpleXML
|
||||
* @throws \InvalidArgumentException
|
||||
* @note We are disabling the entity loader after opening the content to prevent XXE
|
||||
*/
|
||||
public static function loadString( $xml )
|
||||
{
|
||||
$entityLoaderValue = libxml_disable_entity_loader( false );
|
||||
|
||||
$class = @simplexml_load_string( $xml, get_called_class() );
|
||||
if ( $class === FALSE )
|
||||
{
|
||||
throw new \InvalidArgumentException;
|
||||
}
|
||||
libxml_disable_entity_loader( $entityLoaderValue );
|
||||
return $class->subtype();
|
||||
}
|
||||
|
||||
@@ -88,8 +100,16 @@ class _SimpleXML extends \SimpleXMLElement
|
||||
{
|
||||
return \IPS\Xml\Atom::loadString( $this->asXml() );
|
||||
}
|
||||
if ( mb_strtolower( $this->getName() ) === 'rdf' )
|
||||
{
|
||||
/* Verify this is an RSS 1.0 document */
|
||||
if( in_array( 'http://purl.org/rss/1.0/', $this->getNamespaces( true ) ) )
|
||||
{
|
||||
return \IPS\Xml\Rss1::loadString( $this->asXml() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Wrapper class for managing XMLReader objects
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Community Suite
|
||||
* @since 5 July 2016
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\Xml;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper class for managing XMLReader objects
|
||||
*/
|
||||
class _XMLReader extends \XMLReader
|
||||
{
|
||||
/**
|
||||
* Open a file or URL with XMLReader to read it
|
||||
*
|
||||
* @param string $uri The URI/path to open
|
||||
* @param string $encoding The encoding to use, or NULL
|
||||
* @param int $options Bitmask of LIBXML_* constants
|
||||
* @return bool
|
||||
* @note We are disabling the entity loader after opening the content to prevent XXE
|
||||
*/
|
||||
public function open( $uri, $encoding=NULL, $options=0 )
|
||||
{
|
||||
$entityLoaderValue = libxml_disable_entity_loader( false );
|
||||
$opened = parent::open( $uri, $encoding, $options );
|
||||
libxml_disable_entity_loader( $entityLoaderValue );
|
||||
|
||||
return $opened;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user