Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
+1
-1
@@ -11,7 +11,7 @@
|
||||
namespace IPS\Xml;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
|
||||
+25
-21
@@ -11,7 +11,7 @@
|
||||
namespace IPS\Xml;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -28,16 +28,10 @@ class _DOMDocument extends \DOMDocument
|
||||
* @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;
|
||||
return static::loadXML( file_get_contents( $filename ), $options );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,11 +44,19 @@ class _DOMDocument extends \DOMDocument
|
||||
*/
|
||||
public function loadHTML( $source, $options=0 )
|
||||
{
|
||||
libxml_use_internal_errors(TRUE);
|
||||
$entityLoaderValue = libxml_disable_entity_loader( false );
|
||||
libxml_use_internal_errors( TRUE );
|
||||
|
||||
/* Turn off external entity loader to prevent XXE */
|
||||
$entityLoaderValue = libxml_disable_entity_loader( TRUE );
|
||||
|
||||
/* Load it */
|
||||
$opened = parent::loadHTML( $source, $options );
|
||||
|
||||
/* Turn external entity loader back to what it was before so we're not messing with other
|
||||
PHP scripts on this server */
|
||||
libxml_disable_entity_loader( $entityLoaderValue );
|
||||
|
||||
|
||||
/* Return */
|
||||
return $opened;
|
||||
}
|
||||
|
||||
@@ -67,13 +69,8 @@ class _DOMDocument extends \DOMDocument
|
||||
* @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;
|
||||
{
|
||||
return static::loadHTML( file_get_contents( $filename ), $options );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,15 +79,22 @@ class _DOMDocument extends \DOMDocument
|
||||
* @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 );
|
||||
libxml_use_internal_errors( TRUE );
|
||||
|
||||
/* Turn off external entity loader to prevent XXE */
|
||||
$entityLoaderValue = libxml_disable_entity_loader( TRUE );
|
||||
|
||||
/* Load it */
|
||||
$opened = parent::loadXML( $source, $options );
|
||||
|
||||
/* Turn external entity loader back to what it was before so we're not messing with other
|
||||
PHP scripts on this server */
|
||||
libxml_disable_entity_loader( $entityLoaderValue );
|
||||
|
||||
/* Return */
|
||||
return $opened;
|
||||
}
|
||||
|
||||
|
||||
+24
-3
@@ -11,7 +11,7 @@
|
||||
namespace IPS\Xml;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -56,10 +56,11 @@ class _Rss extends SimpleXML
|
||||
* @param string|NULL $description Item description/content
|
||||
* @param \IPS\DateTime|NULL $date Item date
|
||||
* @param string $guid Item ID
|
||||
* @param \IPS\File $enclosure Enclosure file object
|
||||
* @return void
|
||||
* @todo [Future] The feed will validate now, but unrecognized attribute values cause warnings when validating. Also, the validator recommends using an Atom feed with the atom:link attribute.
|
||||
*/
|
||||
public function addItem( $title = NULL, \IPS\Http\Url $link = NULL, $description = NULL, \IPS\DateTime $date = NULL, $guid = NULL )
|
||||
public function addItem( $title = NULL, \IPS\Http\Url $link = NULL, $description = NULL, \IPS\DateTime $date = NULL, $guid = NULL, $enclosure=NULL )
|
||||
{
|
||||
if ( $title === NULL and $description === NULL )
|
||||
{
|
||||
@@ -95,6 +96,14 @@ class _Rss extends SimpleXML
|
||||
|
||||
$item->addChild( 'description', $description );
|
||||
}
|
||||
|
||||
if ( $enclosure !== NULL and $enclosure instanceof \IPS\File and $enclosure->mediaType() == 'image' )
|
||||
{
|
||||
$child = $item->addChild( 'enclosure' );
|
||||
$child->addAttribute( 'url', (string) $enclosure->url );
|
||||
$child->addAttribute( 'length', (string) $enclosure->filesize() );
|
||||
$child->addAttribute( 'type', \IPS\File::getMimeType( (string) $enclosure->url ) );
|
||||
}
|
||||
|
||||
if ( $guid !== NULL )
|
||||
{
|
||||
@@ -105,6 +114,7 @@ class _Rss extends SimpleXML
|
||||
{
|
||||
$item->addChild( 'pubDate', $date->format('r') );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,7 +170,7 @@ class _Rss extends SimpleXML
|
||||
$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 ) )
|
||||
if( \count( $item->children( 'content', true ) ) AND \count( $item->children( 'content', true )->encoded ) )
|
||||
{
|
||||
$text = (string) $item->children( 'content', true )->encoded[0];
|
||||
}
|
||||
@@ -179,6 +189,17 @@ class _Rss extends SimpleXML
|
||||
'date' => $pubDate ?: \IPS\DateTime::create(),
|
||||
'link' => $link
|
||||
);
|
||||
|
||||
if ( isset( $item->enclosure ) )
|
||||
{
|
||||
$attr = array();
|
||||
foreach( $item->enclosure->attributes() as $k => $v )
|
||||
{
|
||||
$attr[ $k ] = (string) $v;
|
||||
}
|
||||
|
||||
$articles[ $guid ]['enclosure'] = $attr;
|
||||
}
|
||||
}
|
||||
return $articles;
|
||||
}
|
||||
|
||||
+2
-2
@@ -11,7 +11,7 @@
|
||||
namespace IPS\Xml;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -35,7 +35,7 @@ class _Rss1 extends Rss
|
||||
/* 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 )
|
||||
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 ) );
|
||||
}
|
||||
|
||||
+33
-35
@@ -11,7 +11,7 @@
|
||||
namespace IPS\Xml;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -26,70 +26,68 @@ 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
|
||||
* @param string|NULL $xmlns Namespace
|
||||
* @return static
|
||||
*/
|
||||
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();
|
||||
if ( $xmlns )
|
||||
{
|
||||
return static::loadString( "<?xml version='1.0' encoding='UTF-8'?><{$rootElement} xmlns='{$xmlns}'></{$rootElement}>" );
|
||||
}
|
||||
else
|
||||
{
|
||||
return static::loadString( "<?xml version='1.0' encoding='UTF-8'?><{$rootElement}></{$rootElement}>" );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load File
|
||||
*
|
||||
* @param string $filename Filename of XML file
|
||||
* @return \IPS\Xml\SimpleXML
|
||||
* @return static
|
||||
* @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();
|
||||
return static::loadString( file_get_contents( $filename ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Load String
|
||||
*
|
||||
* @param string $xml XML
|
||||
* @return \IPS\Xml\SimpleXML
|
||||
* @return static
|
||||
* @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 );
|
||||
/* Turn off external entity loader to prevent XXE */
|
||||
$entityLoaderValue = libxml_disable_entity_loader( TRUE );
|
||||
|
||||
$class = @simplexml_load_string( $xml, get_called_class() );
|
||||
/* Load it */
|
||||
$class = @simplexml_load_string( $xml, \get_called_class() );
|
||||
|
||||
/* Turn external entity loader back to what it was before so we're not messing with other
|
||||
PHP scripts on this server */
|
||||
libxml_disable_entity_loader( $entityLoaderValue );
|
||||
|
||||
/* Return */
|
||||
if ( $class === FALSE )
|
||||
{
|
||||
throw new \InvalidArgumentException;
|
||||
}
|
||||
libxml_disable_entity_loader( $entityLoaderValue );
|
||||
return $class->subtype();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get appropriate subtype
|
||||
*
|
||||
* @return \IPS\Xml\SimpleXML
|
||||
* @return static
|
||||
*/
|
||||
protected function subtype()
|
||||
{
|
||||
if ( get_called_class() === 'IPS\Xml\SimpleXML' )
|
||||
if ( \get_called_class() === 'IPS\Xml\SimpleXML' )
|
||||
{
|
||||
if ( $this->getName() === 'rss' )
|
||||
{
|
||||
@@ -102,7 +100,7 @@ class _SimpleXML extends \SimpleXMLElement
|
||||
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 ) ) )
|
||||
if( \in_array( 'http://purl.org/rss/1.0/', $this->getNamespaces( true ) ) )
|
||||
{
|
||||
return \IPS\Xml\Rss1::loadString( $this->asXml() );
|
||||
}
|
||||
@@ -117,7 +115,7 @@ class _SimpleXML extends \SimpleXMLElement
|
||||
*
|
||||
* @param mixed $guidKey In previous versions, we encoded a key with the GUID. For legacy purposes, this can be passed here.
|
||||
* @return array
|
||||
* @note Subtypes (ATOM and RSS) define this method
|
||||
* @note Subtypes (ATOM and RSS) define this method
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
public function articles( $guidKey=NULL )
|
||||
@@ -138,7 +136,7 @@ class _SimpleXML extends \SimpleXMLElement
|
||||
public function addChild( $name, $value=NULL, $ns=NULL )
|
||||
{
|
||||
/* Arrays are possibly numerically indexed, which XML won't have */
|
||||
if( gettype( $name ) === 'integer' )
|
||||
if( \gettype( $name ) === 'integer' )
|
||||
{
|
||||
$name = $this->getName();
|
||||
|
||||
@@ -154,12 +152,12 @@ class _SimpleXML extends \SimpleXMLElement
|
||||
}
|
||||
|
||||
/* If it's not an array, we can just let the default SimpleXML method handle this */
|
||||
if( !is_array( $value ) and !( $value instanceof \IPS\Xml\SimpleXML ) )
|
||||
if( !\is_array( $value ) and !( $value instanceof \IPS\Xml\SimpleXML ) )
|
||||
{
|
||||
/* Unless it's a boolean value, then we should cast that to an integer */
|
||||
if( gettype( $value ) === 'boolean' )
|
||||
if( \gettype( $value ) === 'boolean' )
|
||||
{
|
||||
$value = intval( $value );
|
||||
$value = \intval( $value );
|
||||
}
|
||||
|
||||
/* Needs CDATA? */
|
||||
@@ -190,7 +188,7 @@ class _SimpleXML extends \SimpleXMLElement
|
||||
foreach ( $value as $k => $v )
|
||||
{
|
||||
/* If the value is an XML text element, just get the value */
|
||||
if ( $v instanceof \IPS\Xml\SimpleXML and count( $v->children() ) === 0 )
|
||||
if ( $v instanceof \IPS\Xml\SimpleXML and \count( $v->children() ) === 0 )
|
||||
{
|
||||
$v = (string) $v;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
namespace IPS\Xml;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -29,14 +29,15 @@ class _XMLReader extends \XMLReader
|
||||
* @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
|
||||
* @note We are disabling network access while loading 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 );
|
||||
if( $options === 0 )
|
||||
{
|
||||
$options = LIBXML_NONET;
|
||||
}
|
||||
|
||||
return $opened;
|
||||
return parent::open( $uri, $encoding, $options );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user