Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
+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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user