Version 4.0.13.1
This commit is contained in:
1 parent
f9e857d255
commit
c6a86f0d9b
7517 files changed
+597400
-668041
No files matched your search
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* @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.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @since 5 Feb 2014
|
||||
* @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 managing Atom documents
|
||||
*/
|
||||
class _Atom extends SimpleXML
|
||||
{
|
||||
/**
|
||||
* Get title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function title()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get articles
|
||||
*
|
||||
* @param mixed $guidKey In previous versions, we encoded a key with the GUID. For legacy purposes, this can be passed here.
|
||||
* @return array
|
||||
*/
|
||||
public function articles( $guidKey=NULL )
|
||||
{
|
||||
$articles = array();
|
||||
|
||||
foreach ( $this->entry as $item )
|
||||
{
|
||||
$link = NULL;
|
||||
if ( isset( $item->link ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$link = \IPS\Http\Url::external( $item->link );
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
}
|
||||
|
||||
$articles[ md5( $guidKey . ( (string) $item->id ) ) ] = array(
|
||||
'title' => (string) $item->title,
|
||||
'content' => isset( $item->content ) ? (string) $item->content : (string) $item->title,
|
||||
'date' => \IPS\DateTime::ts( strtotime( $item->updated ) ),
|
||||
'link' => $link
|
||||
);
|
||||
}
|
||||
return $articles;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
/**
|
||||
* @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.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @since 18 Feb 2013
|
||||
* @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 managing RSS documents
|
||||
*/
|
||||
class _Rss extends SimpleXML
|
||||
{
|
||||
/**
|
||||
* Create RSS document
|
||||
*
|
||||
* @param \IPS\Http\Url $url URL to document
|
||||
* @param string $title Channel Title
|
||||
* @param string $description Channel Description
|
||||
* @return void
|
||||
* @see <a href='http://cyber.law.harvard.edu/rss/languages.html'>Allowable values for language in RSS</a>
|
||||
*/
|
||||
public static function newDocument( \IPS\Http\Url $url, $title, $description )
|
||||
{
|
||||
$xml = new self( '<rss version="2.0" />' );
|
||||
|
||||
$channel = $xml->addChild( 'channel' );
|
||||
$channel->addChild( 'title', $title );
|
||||
$channel->addChild( 'link', (string) $url );
|
||||
$channel->addChild( 'description', $description );
|
||||
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
||||
return $xml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Item
|
||||
*
|
||||
* @param string $title Item title
|
||||
* @param \IPS\Http\Url|NULL $link Item link
|
||||
* @param string|NULL $description Item description/content
|
||||
* @param \IPS\DateTime|NULL $date Item date
|
||||
* @param string $guid Item ID
|
||||
* @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 )
|
||||
{
|
||||
if ( $title === NULL and $description === NULL )
|
||||
{
|
||||
throw new \InvalidArgumentException;
|
||||
}
|
||||
|
||||
$item = $this->channel->addChild( 'item' );
|
||||
|
||||
if ( $title !== NULL )
|
||||
{
|
||||
$item->addChild( 'title', $title );
|
||||
}
|
||||
|
||||
$item->addChild( 'link', $link->rfc3986() );
|
||||
|
||||
if ( $description !== NULL )
|
||||
{
|
||||
$item->addChild( 'description', $description );
|
||||
}
|
||||
|
||||
if ( $guid !== NULL )
|
||||
{
|
||||
$item->addChild( 'guid', $guid )->addAttribute( 'isPermaLink', 'false' );
|
||||
}
|
||||
|
||||
if ( $date !== NULL )
|
||||
{
|
||||
$item->addChild( 'pubDate', $date->format('r') );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function title()
|
||||
{
|
||||
return $this->channel->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get articles
|
||||
*
|
||||
* @param mixed $guidKey In previous versions, we encoded a key with the GUID. For legacy purposes, this can be passed here.
|
||||
* @return array
|
||||
*/
|
||||
public function articles( $guidKey=NULL )
|
||||
{
|
||||
$articles = array();
|
||||
foreach ( $this->channel->item as $item )
|
||||
{
|
||||
$link = NULL;
|
||||
if ( $item->link )
|
||||
{
|
||||
try
|
||||
{
|
||||
$link = \IPS\Http\Url::external( $item->link );
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
}
|
||||
|
||||
if ( isset( $item->guid ) )
|
||||
{
|
||||
$guid = $item->guid;
|
||||
}
|
||||
else
|
||||
{
|
||||
$guid = '';
|
||||
foreach ( array( 'title', 'link', 'description' ) as $k )
|
||||
{
|
||||
if ( isset( $item->$k ) )
|
||||
{
|
||||
$guid .= $item->$k;
|
||||
}
|
||||
}
|
||||
$guid = preg_replace( "#\s|\r|\n#is", "", $guid );
|
||||
}
|
||||
$guid = md5( $guidKey . $guid );
|
||||
|
||||
$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 ),
|
||||
'link' => $link
|
||||
);
|
||||
}
|
||||
return $articles;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
/**
|
||||
* @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.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @since 18 Feb 2013
|
||||
* @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 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
|
||||
*/
|
||||
public static function create( $rootElement, $xmlns=NULL )
|
||||
{
|
||||
$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() );
|
||||
return $class->subtype();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load File
|
||||
*
|
||||
* @param string $filename Filename of XML file
|
||||
* @return \IPS\Xml\SimpleXML
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public static function loadFile( $filename )
|
||||
{
|
||||
$class = @simplexml_load_file( $filename, get_called_class() );
|
||||
if ( $class === FALSE )
|
||||
{
|
||||
throw new \InvalidArgumentException;
|
||||
}
|
||||
return $class->subtype();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load String
|
||||
*
|
||||
* @param string $xml XML
|
||||
* @return \IPS\Xml\SimpleXML
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public static function loadString( $xml )
|
||||
{
|
||||
$class = @simplexml_load_string( $xml, get_called_class() );
|
||||
if ( $class === FALSE )
|
||||
{
|
||||
throw new \InvalidArgumentException;
|
||||
}
|
||||
return $class->subtype();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get appropriate subtype
|
||||
*
|
||||
* @return \IPS\Xml\SimpleXML
|
||||
*/
|
||||
protected function subtype()
|
||||
{
|
||||
if ( get_called_class() === 'IPS\Xml\SimpleXML' )
|
||||
{
|
||||
if ( $this->getName() === 'rss' )
|
||||
{
|
||||
return \IPS\Xml\Rss::loadString( $this->asXml() );
|
||||
}
|
||||
if ( $this->getName() === 'feed' )
|
||||
{
|
||||
return \IPS\Xml\Atom::loadString( $this->asXml() );
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Child
|
||||
* Modified to support passing other data types (including multi-dimensional arrays and other \IPS\XML\SimpleXML objects) as values
|
||||
*
|
||||
* @see <a href='http://www.php.net/manual/en/simplexmlelement.addchild.php'>SimpleXMLElement::addChild</a>
|
||||
* @param string $name Element Name
|
||||
* @param mixed $value Value
|
||||
* @param string|null $ns Namespace
|
||||
* @return void
|
||||
*/
|
||||
public function addChild( $name, $value=NULL, $ns=NULL )
|
||||
{
|
||||
/* Arrays are possibly numerically indexed, which XML won't have */
|
||||
if( gettype( $name ) === 'integer' )
|
||||
{
|
||||
$name = $this->getName();
|
||||
|
||||
/* If the name ends in s (e.g. <elements>) - we'll name it's children without the s (e.g. <element>) */
|
||||
if( mb_substr( $name, -2 ) === 'es' )
|
||||
{
|
||||
$name = mb_substr( $name, 0, mb_strlen( $name ) - 2 );
|
||||
}
|
||||
if( mb_substr( $name, -1 ) === 's' )
|
||||
{
|
||||
$name = mb_substr( $name, 0, mb_strlen( $name ) - 1 );
|
||||
}
|
||||
}
|
||||
|
||||
/* 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 ) )
|
||||
{
|
||||
/* Unless it's a boolean value, then we should cast that to an integer */
|
||||
if( gettype( $value ) === 'boolean' )
|
||||
{
|
||||
$value = intval( $value );
|
||||
}
|
||||
|
||||
/* Needs CDATA? */
|
||||
if ( preg_match( '/<|>|&/', $value ) )
|
||||
{
|
||||
$element = parent::addChild( $name, '', $ns );
|
||||
|
||||
$node = dom_import_simplexml( $element );
|
||||
$no = $node->ownerDocument;
|
||||
$node->appendChild( $no->createCDATASection( $value ) );
|
||||
|
||||
return $element;
|
||||
}
|
||||
else
|
||||
{
|
||||
return parent::addChild( $name, $value, $ns );
|
||||
}
|
||||
|
||||
/* Return */
|
||||
}
|
||||
/* If it is an array, we need to be a little clever */
|
||||
else
|
||||
{
|
||||
/* Create an element with a blank value */
|
||||
$element = parent::addChild( $name, '', $ns );
|
||||
|
||||
/* And loop through each value and rerun this method for each */
|
||||
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 )
|
||||
{
|
||||
$v = (string) $v;
|
||||
}
|
||||
|
||||
/* And add it */
|
||||
$element->addChild( $k, $v, $ns );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove Node
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function removeNode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Format XML in a readable way (normally only used for debugging purposes)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function format()
|
||||
{
|
||||
$dom = new \DOMDocument( '1.0', 'UTF-8' );
|
||||
$dom->preserveWhiteSpace = false;
|
||||
$dom->formatOutput = true;
|
||||
@$dom->loadXML( $this->asXML() );
|
||||
return $dom->saveXML();
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
Reference in new issue
Block a user