Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -12,36 +12,74 @@
|
||||
namespace IPS\core\Rss;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DomainException;
|
||||
use ErrorException;
|
||||
use IPS\Application;
|
||||
use IPS\Content;
|
||||
use IPS\Content\Search\Index;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\File;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Member as FormMember;
|
||||
use IPS\Helpers\Form\Node;
|
||||
use IPS\Helpers\Form\Password;
|
||||
use IPS\Helpers\Form\Radio;
|
||||
use IPS\Helpers\Form\Text;
|
||||
use IPS\Helpers\Form\Url as FormUrl;
|
||||
use IPS\Helpers\Form\YesNo;
|
||||
use IPS\Http\Request\Exception;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Http\Url\Exception as UrlException;
|
||||
use IPS\Image;
|
||||
use IPS\Member;
|
||||
use IPS\Node\Model;
|
||||
use IPS\Settings;
|
||||
use IPS\Text\DOMParser;
|
||||
use IPS\Text\Parser;
|
||||
use IPS\Theme;
|
||||
use IPS\Xml\Atom;
|
||||
use IPS\Xml\DOMDocument;
|
||||
use IPS\Xml\Rss;
|
||||
use IPS\Xml\Rss1;
|
||||
use RuntimeException;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function get_class;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Feed Import Node
|
||||
*/
|
||||
class _Import extends \IPS\Node\Model
|
||||
class Import extends Model
|
||||
{
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
protected static array $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Table
|
||||
*/
|
||||
public static $databaseTable = 'core_rss_import';
|
||||
public static ?string $databaseTable = 'core_rss_import';
|
||||
|
||||
/**
|
||||
* @brief Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'rss_import_';
|
||||
public static string $databasePrefix = 'rss_import_';
|
||||
|
||||
/**
|
||||
* @brief [Node] Node Title
|
||||
*/
|
||||
public static $nodeTitle = 'rss_import';
|
||||
public static string $nodeTitle = 'rss_import';
|
||||
|
||||
/**
|
||||
* @brief [Node] ACP Restrictions
|
||||
@@ -59,7 +97,7 @@ class _Import extends \IPS\Node\Model
|
||||
'prefix' => 'foo_', // [Optional] Rather than specifying each key in the map, you can specify a prefix, and it will automatically look for restrictions with the key "[prefix]_add/edit/permissions/delete"
|
||||
* @endcode
|
||||
*/
|
||||
protected static $restrictions = array(
|
||||
protected static ?array $restrictions = array(
|
||||
'app' => 'core',
|
||||
'module' => 'applications',
|
||||
'prefix' => 'rss_'
|
||||
@@ -71,7 +109,7 @@ class _Import extends \IPS\Node\Model
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultValues()
|
||||
public function setDefaultValues() : void
|
||||
{
|
||||
$this->settings = array();
|
||||
}
|
||||
@@ -81,11 +119,11 @@ class _Import extends \IPS\Node\Model
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get__title()
|
||||
protected function get__title(): string
|
||||
{
|
||||
if ( $this->class == 'IPS\\blog\\Entry' )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'blogs_blog_' . $this->node_id );
|
||||
return Member::loggedIn()->language()->addToStack( 'blogs_blog_' . $this->node_id );
|
||||
}
|
||||
|
||||
return $this->title;
|
||||
@@ -94,9 +132,9 @@ class _Import extends \IPS\Node\Model
|
||||
/**
|
||||
* [Node] Get description
|
||||
*
|
||||
* @return string
|
||||
* @return string|null
|
||||
*/
|
||||
protected function get__description()
|
||||
protected function get__description(): ?string
|
||||
{
|
||||
return $this->url;
|
||||
}
|
||||
@@ -107,7 +145,7 @@ class _Import extends \IPS\Node\Model
|
||||
* @note Return value NULL indicates the node cannot be enabled/disabled
|
||||
* @return bool|null
|
||||
*/
|
||||
protected function get__enabled()
|
||||
protected function get__enabled(): ?bool
|
||||
{
|
||||
return $this->enabled;
|
||||
}
|
||||
@@ -118,11 +156,11 @@ class _Import extends \IPS\Node\Model
|
||||
* @param bool|int $enabled Whether to set it enabled or disabled
|
||||
* @return void
|
||||
*/
|
||||
protected function set__enabled( $enabled )
|
||||
protected function set__enabled( int|bool $enabled ) : void
|
||||
{
|
||||
if ( $enabled )
|
||||
{
|
||||
\IPS\Db::i()->update( 'core_tasks', array( 'enabled' => 1 ), array( '`key`=?', 'rssimport' ) );
|
||||
Db::i()->update( 'core_tasks', array( 'enabled' => 1 ), array( '`key`=?', 'rssimport' ) );
|
||||
}
|
||||
$this->enabled = $enabled;
|
||||
}
|
||||
@@ -132,7 +170,7 @@ class _Import extends \IPS\Node\Model
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get__icon()
|
||||
protected function get__icon(): mixed
|
||||
{
|
||||
return $this->_application->_icon;
|
||||
}
|
||||
@@ -140,9 +178,9 @@ class _Import extends \IPS\Node\Model
|
||||
/**
|
||||
* Get the class for this RSS entry
|
||||
*
|
||||
* @return \IPS\Content
|
||||
* @return Content
|
||||
*/
|
||||
public function get__class()
|
||||
public function get__class() : Content
|
||||
{
|
||||
$class = $this->class;
|
||||
return new $class;
|
||||
@@ -151,20 +189,20 @@ class _Import extends \IPS\Node\Model
|
||||
/**
|
||||
* Get the application for this RSS entry
|
||||
*
|
||||
* @return \IPS\Application
|
||||
* @return Application
|
||||
*/
|
||||
public function get__application()
|
||||
public function get__application() : Application
|
||||
{
|
||||
$class = $this->_class;
|
||||
return \IPS\Application::load( $class::$application );
|
||||
return Application::load( $class::$application );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL for where this imports into
|
||||
*
|
||||
* @return \IPS\Http\Url|Null
|
||||
* @return Url|Null
|
||||
*/
|
||||
public function get__importedIntoUrl()
|
||||
public function get__importedIntoUrl() : ?Url
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -181,9 +219,9 @@ class _Import extends \IPS\Node\Model
|
||||
/**
|
||||
* Get the extension for this RSS entry
|
||||
*
|
||||
* @return \IPS\Application
|
||||
* @return object
|
||||
*/
|
||||
public function get__extension()
|
||||
public function get__extension() : object
|
||||
{
|
||||
$classname = 'IPS\\' . $this->_application->directory . '\extensions\core\RssImport\RssImport';
|
||||
return new $classname;
|
||||
@@ -195,9 +233,9 @@ class _Import extends \IPS\Node\Model
|
||||
* @param string|array $value Value
|
||||
* @return void
|
||||
*/
|
||||
public function set_settings( $value )
|
||||
public function set_settings( array|string $value ) : void
|
||||
{
|
||||
$this->_data['settings'] = ( \is_array( $value ) ? json_encode( $value ) : $value );
|
||||
$this->_data['settings'] = ( is_array( $value ) ? json_encode( $value ) : $value );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -205,9 +243,9 @@ class _Import extends \IPS\Node\Model
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_settings()
|
||||
public function get_settings() : array
|
||||
{
|
||||
return ( \is_array( $this->_data['settings'] ) ) ? $this->_data['settings'] : json_decode( $this->_data['settings'], TRUE );
|
||||
return ( is_array( $this->_data['settings'] ) ) ? $this->_data['settings'] : json_decode( $this->_data['settings'], TRUE );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -215,25 +253,25 @@ class _Import extends \IPS\Node\Model
|
||||
* Example code explains return value
|
||||
*
|
||||
* @code
|
||||
array(
|
||||
array(
|
||||
'icon' => 'plus-circle', // Name of FontAwesome icon to use
|
||||
'title' => 'foo', // Language key to use for button's title parameter
|
||||
'link' => \IPS\Http\Url::internal( 'app=foo...' ) // URI to link to
|
||||
'class' => 'modalLink' // CSS Class to use on link (Optional)
|
||||
),
|
||||
... // Additional buttons
|
||||
);
|
||||
* array(
|
||||
* array(
|
||||
* 'icon' => 'plus-circle', // Name of FontAwesome icon to use
|
||||
* 'title' => 'foo', // Language key to use for button's title parameter
|
||||
* 'link' => \IPS\Http\Url::internal( 'app=foo...' ) // URI to link to
|
||||
* 'class' => 'modalLink' // CSS Class to use on link (Optional)
|
||||
* ),
|
||||
* ... // Additional buttons
|
||||
* );
|
||||
* @endcode
|
||||
* @param string $url Base URL
|
||||
* @param Url $url Base URL
|
||||
* @param bool $subnode Is this a subnode?
|
||||
* @return array
|
||||
*/
|
||||
public function getButtons( $url, $subnode=FALSE )
|
||||
public function getButtons( Url $url, bool $subnode=FALSE ):array
|
||||
{
|
||||
$buttons = parent::getButtons( $url, $subnode );
|
||||
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction('rss_run') )
|
||||
if ( Member::loggedIn()->hasAcpRestriction('rss_run') )
|
||||
{
|
||||
$buttons = array_merge( array( 'run' => array(
|
||||
'icon' => 'refresh',
|
||||
@@ -248,31 +286,31 @@ class _Import extends \IPS\Node\Model
|
||||
/**
|
||||
* [Node] Edit Form (add form is a Wizard in core/modules/admin/applications/rss.php)
|
||||
*
|
||||
* @param \IPS\Helpers\Form $form The form
|
||||
* @param Form $form The form
|
||||
* @return void
|
||||
*/
|
||||
public function form( &$form )
|
||||
public function form( Form &$form ) : void
|
||||
{
|
||||
$class = $this->_class;
|
||||
|
||||
$form->addHeader('rss_import_url');
|
||||
$form->add( new \IPS\Helpers\Form\Url( 'rss_import_url', $this->url, TRUE ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'rss_import_auth_user', $this->auth_user ) );
|
||||
$form->add( new \IPS\Helpers\Form\Password( 'rss_import_auth_pass', $this->auth_pass ) );
|
||||
$form->add( new FormUrl( 'rss_import_url', $this->url, TRUE ) );
|
||||
$form->add( new Text( 'rss_import_auth_user', $this->auth_user ) );
|
||||
$form->add( new Password( 'rss_import_auth_pass', $this->auth_pass ) );
|
||||
$form->addHeader('rss_import_details');
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'rss_import_node_id', $this->node_id, TRUE, $this->_extension->nodeSelectorOptions( $this ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Member( 'rss_import_member', \IPS\Member::load( $this->member ), TRUE ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'rss_import_showlink', $this->showlink ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'rss_import_enclosures', $this->enclosures, FALSE, array( 'options' => array(
|
||||
$form->add( new Node( 'rss_import_node_id', $this->node_id, TRUE, $this->_extension->nodeSelectorOptions( $this ) ) );
|
||||
$form->add( new FormMember( 'rss_import_member', Member::load( $this->member ), TRUE ) );
|
||||
$form->add( new Text( 'rss_import_showlink', $this->showlink ) );
|
||||
$form->add( new Radio( 'rss_import_enclosures', $this->enclosures, FALSE, array( 'options' => array(
|
||||
'import' => "rss_import_enclosures_import",
|
||||
'hotlink' => "rss_import_enclosures_hotlink",
|
||||
'ignore' => "rss_import_enclosures_ignore",
|
||||
) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'rss_import_topic_pre', $this->topic_pre, FALSE, array( 'trim' => FALSE ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'rss_import_auto_follow', $this->auto_follow, FALSE, array(), NULL, NULL, NULL, 'rss_import_auto_follow' ) );
|
||||
$form->add( new Text( 'rss_import_topic_pre', $this->topic_pre, FALSE, array( 'trim' => FALSE ) ) );
|
||||
$form->add( new YesNo( 'rss_import_auto_follow', $this->auto_follow, FALSE, array(), NULL, NULL, NULL, 'rss_import_auto_follow' ) );
|
||||
$this->_extension->form( $form, $this );
|
||||
|
||||
\IPS\Member::loggedIn()->language()->words['rss_import_auto_follow'] = \IPS\Member::loggedIn()->language()->addToStack( 'rss_import_auto_follow_lang', FALSE, array( 'sprintf' => array( $class::_definiteArticle() ) ) );
|
||||
Member::loggedIn()->language()->words['rss_import_auto_follow'] = Member::loggedIn()->language()->addToStack( 'rss_import_auto_follow_lang', FALSE, array( 'sprintf' => array( $class::_definiteArticle() ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -281,7 +319,7 @@ class _Import extends \IPS\Node\Model
|
||||
* @param array $values Values from the form
|
||||
* @return array
|
||||
*/
|
||||
public function formatFormValues( $values )
|
||||
public function formatFormValues( array $values ): array
|
||||
{
|
||||
if( isset( $values['rss_import_url'] ) )
|
||||
{
|
||||
@@ -298,26 +336,22 @@ class _Import extends \IPS\Node\Model
|
||||
|
||||
if ( $response->httpResponseCode == 401 )
|
||||
{
|
||||
throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack( 'rss_import_auth' ) );
|
||||
throw new DomainException( Member::loggedIn()->language()->addToStack( 'rss_import_auth' ) );
|
||||
}
|
||||
|
||||
$response = $response->decodeXml();
|
||||
if ( !( $response instanceof \IPS\Xml\Rss ) and !( $response instanceof \IPS\Xml\Atom ) )
|
||||
if ( !( $response instanceof Rss ) and !( $response instanceof Atom ) )
|
||||
{
|
||||
throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack( 'rss_import_invalid' ) );
|
||||
throw new DomainException( Member::loggedIn()->language()->addToStack( 'rss_import_invalid' ) );
|
||||
}
|
||||
}
|
||||
catch ( \IPS\Http\Request\Exception $e )
|
||||
catch ( Exception $e )
|
||||
{
|
||||
throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack( 'form_url_bad' ) );
|
||||
throw new DomainException( Member::loggedIn()->language()->addToStack( 'form_url_bad' ) );
|
||||
}
|
||||
catch( \RuntimeException $e )
|
||||
catch( RuntimeException | ErrorException $e )
|
||||
{
|
||||
throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack( 'rss_import_invalid' ) );
|
||||
}
|
||||
catch ( \ErrorException $e )
|
||||
{
|
||||
throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack( 'rss_import_invalid' ) );
|
||||
throw new DomainException( Member::loggedIn()->language()->addToStack( 'rss_import_invalid' ) );
|
||||
}
|
||||
|
||||
$values['title'] = (string) $response->channel->title;
|
||||
@@ -374,7 +408,7 @@ class _Import extends \IPS\Node\Model
|
||||
* @param array $values Values from the form
|
||||
* @return void
|
||||
*/
|
||||
public function postSaveForm( $values )
|
||||
public function postSaveForm( array $values ) : void
|
||||
{
|
||||
$this->run();
|
||||
}
|
||||
@@ -383,19 +417,19 @@ class _Import extends \IPS\Node\Model
|
||||
* Run Import
|
||||
*
|
||||
* @return void
|
||||
* @throws \IPS\Http\Url\Exception
|
||||
* @throws UrlException
|
||||
*/
|
||||
public function run()
|
||||
public function run() : void
|
||||
{
|
||||
/* Skip this if the member is restricted from posting */
|
||||
if( \IPS\Member::load( $this->member )->restrict_post or \IPS\Member::load( $this->member )->members_bitoptions['unacknowledged_warnings'] )
|
||||
if( Member::load( $this->member )->restrict_post or Member::load( $this->member )->members_bitoptions['unacknowledged_warnings'] )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$previouslyImportedGuids = iterator_to_array( \IPS\Db::i()->select( 'rss_imported_guid', 'core_rss_imported', array( 'rss_imported_import_id=?', $this->id ) ) );
|
||||
$previouslyImportedGuids = iterator_to_array( Db::i()->select( 'rss_imported_guid', 'core_rss_imported', array( 'rss_imported_import_id=?', $this->id ) ) );
|
||||
|
||||
$request = \IPS\Http\Url::external( $this->url )->request();
|
||||
$request = Url::external( $this->url )->request();
|
||||
if ( $this->auth_user or $this->auth_pass )
|
||||
{
|
||||
$request = $request->login( $this->auth_user, $this->auth_pass );
|
||||
@@ -405,7 +439,7 @@ class _Import extends \IPS\Node\Model
|
||||
$class = $this->_class;
|
||||
$containerClass = $class::$containerNodeClass;
|
||||
$container = $containerClass::load( $this->node_id );
|
||||
$member = \IPS\Member::load( $this->member );
|
||||
$member = Member::load( $this->member );
|
||||
|
||||
$i = 0;
|
||||
/* Enclosures can cause a lot more processing time so we need to import less */
|
||||
@@ -414,21 +448,21 @@ class _Import extends \IPS\Node\Model
|
||||
$inserts = array();
|
||||
$request = $request->decodeXml();
|
||||
|
||||
if( !( $request instanceof \IPS\Xml\Rss1 ) AND !( $request instanceof \IPS\Xml\Rss ) AND !( $request instanceof \IPS\Xml\Atom ) )
|
||||
if( !( $request instanceof Rss1 ) AND !( $request instanceof Rss ) AND !( $request instanceof Atom ) )
|
||||
{
|
||||
throw new \RuntimeException( 'rss_import_invalid' );
|
||||
throw new RuntimeException( 'rss_import_invalid' );
|
||||
}
|
||||
|
||||
$post = NULL;
|
||||
foreach ( $request->articles( $this->id ) as $guid => $article )
|
||||
{
|
||||
if ( !\in_array( $guid, $previouslyImportedGuids ) )
|
||||
if ( !in_array( $guid, $previouslyImportedGuids ) )
|
||||
{
|
||||
/* Don't post future date content - this breaks things like marking as read */
|
||||
$timeNow = \IPS\DateTime::create();
|
||||
$timeNow = DateTime::create();
|
||||
if( $article['date'] > $timeNow )
|
||||
{
|
||||
$article['date'] = \IPS\DateTime::create();
|
||||
$article['date'] = DateTime::create();
|
||||
}
|
||||
|
||||
$article['guid'] = $guid;
|
||||
@@ -438,18 +472,18 @@ class _Import extends \IPS\Node\Model
|
||||
{
|
||||
$rel = array();
|
||||
|
||||
if( \IPS\Settings::i()->posts_add_nofollow )
|
||||
if( Settings::i()->posts_add_nofollow )
|
||||
{
|
||||
$rel['nofollow'] = 'nofollow';
|
||||
}
|
||||
|
||||
if( \IPS\Settings::i()->links_external )
|
||||
if( Settings::i()->links_external )
|
||||
{
|
||||
$rel['external'] = 'external';
|
||||
}
|
||||
|
||||
$linkRelPart = '';
|
||||
if ( \count( $rel ) )
|
||||
if ( count( $rel ) )
|
||||
{
|
||||
$linkRelPart = 'rel="' . implode( ' ', $rel ) . '"';
|
||||
}
|
||||
@@ -458,31 +492,31 @@ class _Import extends \IPS\Node\Model
|
||||
}
|
||||
|
||||
/* Parse the article body now, in case we need to add attachments to it later */
|
||||
$articleContent = \IPS\Text\Parser::parseStatic( $article['content'] . $readMoreLink, TRUE, NULL, $member, $this->_extension->fileStorage, TRUE, !(bool) $member->group['g_dohtml'] );
|
||||
$articleContent = Parser::parseStatic( $article['content'] . $readMoreLink, NULL, $member, $this->_extension->fileStorage, TRUE );
|
||||
|
||||
$imageHtml = '';
|
||||
if ( $this->enclosures != 'ignore' and isset( $article['enclosure'] ) and isset( $article['enclosure']['url'] ) and isset( $article['enclosure']['length'] ) and isset( $article['enclosure']['type'] ) )
|
||||
{
|
||||
/* Limit imports to around 2mb otherwise timeouts and memory issues can occur when processing with GD */
|
||||
if ( mb_substr( $article['enclosure']['type'], 0, 6 ) == 'image/' and ( $this->enclosures == 'hotlink' or $article['enclosure']['length'] <= 1572864 or \IPS\Settings::i()->image_suite == 'imagemagick' ) )
|
||||
if ( mb_substr( $article['enclosure']['type'], 0, 6 ) == 'image/' and ( $this->enclosures == 'hotlink' or $article['enclosure']['length'] <= 1572864 or Settings::i()->image_suite == 'imagemagick' ) )
|
||||
{
|
||||
/* Are we remotely linking to the image? */
|
||||
if( $this->enclosures == 'hotlink' and !$this->_enclosureEmbedded( $article['enclosure']['url'], $articleContent ) )
|
||||
{
|
||||
$imageName = basename( parse_url( $article['enclosure']['url'], PHP_URL_PATH ) );
|
||||
$imageHtml = \IPS\Theme::i()->getTemplate( 'editor', 'core', 'global' )->linkedImage( $article['enclosure']['url'], $imageName ?: 'image' );
|
||||
$imageHtml = Theme::i()->getTemplate( 'editor', 'core', 'global' )->linkedImage( $article['enclosure']['url'], $imageName ?: 'image' );
|
||||
}
|
||||
elseif( $this->enclosures == 'import' )
|
||||
{
|
||||
try
|
||||
{
|
||||
$response = \IPS\Http\Url::external( $article['enclosure']['url'] )->request()->get();
|
||||
$response = Url::external( $article['enclosure']['url'] )->request()->get();
|
||||
|
||||
$match = FALSE;
|
||||
$contentType = ( isset( $response->httpHeaders['Content-Type'] ) ) ? $response->httpHeaders['Content-Type'] : ( ( isset( $response->httpHeaders['content-type'] ) ) ? $response->httpHeaders['content-type'] : NULL );
|
||||
if ( $contentType )
|
||||
{
|
||||
foreach ( \IPS\Image::$imageMimes as $mime )
|
||||
foreach ( Image::$imageMimes as $mime )
|
||||
{
|
||||
if ( preg_match( '/^' . str_replace( '~~', '.+', preg_quote( str_replace( '*', '~~', $mime ), '/' ) ) . '$/i', $contentType ) )
|
||||
{
|
||||
@@ -496,7 +530,7 @@ class _Import extends \IPS\Node\Model
|
||||
if ( $match )
|
||||
{
|
||||
$processAttachment = TRUE;
|
||||
\IPS\Image::$exifEnabled = FALSE;
|
||||
Image::$exifEnabled = FALSE;
|
||||
if ( method_exists( $this->_extension, 'processEnclosure' ) )
|
||||
{
|
||||
if ( $this->_extension->processEnclosure( $this, $response, $article ) !== FALSE )
|
||||
@@ -509,12 +543,12 @@ class _Import extends \IPS\Node\Model
|
||||
{
|
||||
try
|
||||
{
|
||||
$image = \IPS\Image::create( $response );
|
||||
$image = Image::create( $response );
|
||||
$maxImageSizes = NULL;
|
||||
|
||||
if ( \IPS\Settings::i()->attachment_resample_size )
|
||||
if ( Settings::i()->attachment_resample_size )
|
||||
{
|
||||
$maxImageSizes = explode( 'x', \IPS\Settings::i()->attachment_resample_size );
|
||||
$maxImageSizes = explode( 'x', Settings::i()->attachment_resample_size );
|
||||
|
||||
/* If the dimensions were 0x0 then correct... */
|
||||
if ( !$maxImageSizes[0] or !$maxImageSizes[1] )
|
||||
@@ -527,21 +561,28 @@ class _Import extends \IPS\Node\Model
|
||||
$image->resizeToMax( $maxImageSizes[0], $maxImageSizes[1] );
|
||||
}
|
||||
|
||||
$newFile = \IPS\File::create( 'core_Attachment', 'rssImage-' . $guid . '.' . $image->type, (string)$image );
|
||||
$newFile = File::create( 'core_Attachment', 'rssImage-' . $guid . '.' . $image->type, (string)$image );
|
||||
$attachment = $newFile->makeAttachment( md5( $guid . ':' . session_id() ), $member );
|
||||
$article['attachment'] = $attachment;
|
||||
|
||||
/* If the image is already in the body of the article, replace it with our embed instead */
|
||||
if( !$this->_enclosureReplace( $article['enclosure']['url'], $attachment, $articleContent ) )
|
||||
{
|
||||
$imageHtml = \IPS\Theme::i()->getTemplate( 'editor', 'core', 'global' )->attachedImage( $attachment['attach_location'], $attachment['attach_thumb_location'] ? $attachment['attach_thumb_location'] : $attachment['attach_location'], $attachment['attach_file'], $attachment['attach_id'], $attachment['attach_thumb_location'] ? $attachment['attach_img_width'] : $attachment['attach_location'] );
|
||||
$imageHtml = Theme::i()->getTemplate( 'editor', 'core', 'global' )->attachedImage(
|
||||
$attachment['attach_location'],
|
||||
$attachment['attach_thumb_location'] ?: $attachment['attach_location'],
|
||||
$attachment['attach_file'],
|
||||
$attachment['attach_id'],
|
||||
$attachment['attach_thumb_location'] ? $attachment['attach_thumb_width'] : $attachment['attach_img_width'],
|
||||
$attachment['attach_thumb_location'] ? $attachment['attach_thumb_height'] : $attachment['attach_img_height'],
|
||||
);
|
||||
}
|
||||
}
|
||||
catch ( \Exception $e ){}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( \IPS\Http\Request\Exception $e )
|
||||
catch ( Exception $e )
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -551,11 +592,11 @@ class _Import extends \IPS\Node\Model
|
||||
$content = $imageHtml . $articleContent;
|
||||
$item = $this->_extension->create( $this, $article, $container, $content );
|
||||
$idColumn = $class::$databaseColumnId;
|
||||
$followArea = mb_strtolower( mb_substr( \get_class( $class ), mb_strrpos( \get_class( $class ), '\\' ) + 1 ) );
|
||||
$followArea = mb_strtolower( mb_substr( get_class( $class ), mb_strrpos( get_class( $class ), '\\' ) + 1 ) );
|
||||
|
||||
if ( $item )
|
||||
{
|
||||
\IPS\Db::i()->insert( 'core_rss_imported', array(
|
||||
Db::i()->insert( 'core_rss_imported', array(
|
||||
'rss_imported_guid' => $guid,
|
||||
'rss_imported_content_id' => $item->$idColumn,
|
||||
'rss_imported_import_id' => $this->id
|
||||
@@ -563,7 +604,7 @@ class _Import extends \IPS\Node\Model
|
||||
|
||||
if ( $this->auto_follow )
|
||||
{
|
||||
\IPS\Db::i()->insert( 'core_follow', array(
|
||||
Db::i()->insert( 'core_follow', array(
|
||||
'follow_id' => md5( $class::$application . ';' . $followArea . ';' . $item->$idColumn . ';' . $member->member_id ),
|
||||
'follow_app' => $class::$application,
|
||||
'follow_area' => $followArea,
|
||||
@@ -578,15 +619,15 @@ class _Import extends \IPS\Node\Model
|
||||
}
|
||||
|
||||
/* Re-index to pick up any changes to hidden, etc */
|
||||
if ( $item instanceof \IPS\Content\Searchable )
|
||||
if( Content\Search\SearchContent::isSearchable( $item ) )
|
||||
{
|
||||
\IPS\Content\Search\Index::i()->index( $item );
|
||||
Index::i()->index( $item );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Something went wrong, but log the guid so it doesn't get stuck in a loop forever */
|
||||
\IPS\Db::i()->insert( 'core_rss_imported', array(
|
||||
Db::i()->insert( 'core_rss_imported', array(
|
||||
'rss_imported_guid' => $guid,
|
||||
'rss_imported_content_id' => 0,
|
||||
'rss_imported_import_id' => $this->id
|
||||
@@ -617,11 +658,11 @@ class _Import extends \IPS\Node\Model
|
||||
* @param string $content Body of article
|
||||
* @return bool
|
||||
*/
|
||||
protected function _enclosureReplace( $url, $attachment, &$content )
|
||||
protected function _enclosureReplace( string $url, array $attachment, string &$content ) : bool
|
||||
{
|
||||
/* Load source */
|
||||
$source = new \IPS\Xml\DOMDocument( '1.0', 'UTF-8' );
|
||||
$source->loadHTML( \IPS\Xml\DOMDocument::wrapHtml( $content ) );
|
||||
$source = new DOMDocument( '1.0', 'UTF-8' );
|
||||
$source->loadHTML( DOMDocument::wrapHtml( $content ) );
|
||||
|
||||
/* Look for the image URL and replace it with the attachment if found */
|
||||
$replaced = FALSE;
|
||||
@@ -635,26 +676,24 @@ class _Import extends \IPS\Node\Model
|
||||
$replaced = true;
|
||||
|
||||
$element->setAttribute( 'data-fileid', $attachment['attach_id'] );
|
||||
$element->setAttribute( $srcAttribute, '{fileStore.core_Attachment}/' . ( $attachment['attach_thumb_location'] ? $attachment['attach_thumb_location'] : $attachment['attach_location'] ) );
|
||||
$element->setAttribute( $srcAttribute, '{fileStore.core_Attachment}/' . ( $attachment['attach_thumb_location'] ?: $attachment['attach_location'] ) );
|
||||
}
|
||||
}
|
||||
|
||||
if( $replaced )
|
||||
{
|
||||
$content = \IPS\Text\DOMParser::getDocumentBodyContents( $source );
|
||||
$content = \IPS\Text\Parser::replaceFileStoreTags( $content );
|
||||
$content = DOMParser::getDocumentBodyContents( $source );
|
||||
$content = Parser::replaceFileStoreTags( $content );
|
||||
|
||||
/* Set lazy loading and wrapping link on the content */
|
||||
if( $rebuilt = \IPS\Text\Parser::rebuildAttachmentUrls( $content ) )
|
||||
if( $rebuilt = Parser::rebuildAttachmentUrls( $content ) )
|
||||
{
|
||||
$content = $rebuilt;
|
||||
}
|
||||
|
||||
$content = \IPS\Text\Parser::parseLazyLoad( $content, \IPS\Settings::i()->lazy_load_enabled );
|
||||
|
||||
/* And then finally, we need to reparse to make sure our replacement tags are in place */
|
||||
$source = new \IPS\Xml\DOMDocument( '1.0', 'UTF-8' );
|
||||
$source->loadHTML( \IPS\Xml\DOMDocument::wrapHtml( $content ) );
|
||||
$source = new DOMDocument( '1.0', 'UTF-8' );
|
||||
$source->loadHTML( DOMDocument::wrapHtml( $content ) );
|
||||
|
||||
$tags = array( 'a', 'img' );
|
||||
|
||||
@@ -668,7 +707,7 @@ class _Import extends \IPS\Node\Model
|
||||
{
|
||||
if ( $element->hasAttribute( $attribute ) )
|
||||
{
|
||||
if ( preg_match( '#^(https?:)?//(' . preg_quote( rtrim( str_replace( array( 'http://', 'https://' ), '', \IPS\Settings::i()->base_url ), '/' ), '#' ) . ')/(.+?)$#', $element->getAttribute( $attribute ), $matches ) )
|
||||
if ( preg_match( '#^(https?:)?//(' . preg_quote( rtrim( str_replace( array( 'http://', 'https://' ), '', Settings::i()->base_url ), '/' ), '#' ) . ')/(.+?)$#', $element->getAttribute( $attribute ), $matches ) )
|
||||
{
|
||||
$element->setAttribute( $attribute, '%7B___base_url___%7D/' . $matches[3] );
|
||||
}
|
||||
@@ -678,9 +717,9 @@ class _Import extends \IPS\Node\Model
|
||||
{
|
||||
if ( $element->hasAttribute( $attribute ) )
|
||||
{
|
||||
if ( mb_strpos( $element->getAttribute( $attribute ), \IPS\Settings::i()->base_url ) )
|
||||
if ( mb_strpos( $element->getAttribute( $attribute ), Settings::i()->base_url ) )
|
||||
{
|
||||
$element->setAttribute( $attribute, str_replace( \IPS\Settings::i()->base_url, '%7B___base_url___%7D/', $element->getAttribute( $attribute ) ) );
|
||||
$element->setAttribute( $attribute, str_replace( Settings::i()->base_url, '%7B___base_url___%7D/', $element->getAttribute( $attribute ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -688,7 +727,7 @@ class _Import extends \IPS\Node\Model
|
||||
}
|
||||
|
||||
|
||||
$content = \IPS\Text\DOMParser::getDocumentBodyContents( $source );
|
||||
$content = DOMParser::getDocumentBodyContents( $source );
|
||||
|
||||
/* Replace file storage tags */
|
||||
$content = preg_replace( '/<fileStore\.([\d\w\_]+?)>/i', '<fileStore.$1>', $content );
|
||||
@@ -705,11 +744,11 @@ class _Import extends \IPS\Node\Model
|
||||
* @param string $content Body of article
|
||||
* @return bool
|
||||
*/
|
||||
protected function _enclosureEmbedded( $url, $content )
|
||||
protected function _enclosureEmbedded( string $url, string $content ) : bool
|
||||
{
|
||||
/* Load source */
|
||||
$source = new \IPS\Xml\DOMDocument( '1.0', 'UTF-8' );
|
||||
$source->loadHTML( \IPS\Xml\DOMDocument::wrapHtml( $content ) );
|
||||
$source = new DOMDocument( '1.0', 'UTF-8' );
|
||||
$source->loadHTML( DOMDocument::wrapHtml( $content ) );
|
||||
|
||||
/* Look for the image URL */
|
||||
$contentImages = $source->getElementsByTagName( 'img' );
|
||||
@@ -727,12 +766,12 @@ class _Import extends \IPS\Node\Model
|
||||
/**
|
||||
* [ActiveRecord] Delete Record
|
||||
*
|
||||
* @return void
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
public function delete(): void
|
||||
{
|
||||
\IPS\Db::i()->delete( 'core_rss_imported', array( "rss_imported_import_id=?", $this->id ) );
|
||||
return parent::delete();
|
||||
Db::i()->delete( 'core_rss_imported', array( "rss_imported_import_id=?", $this->id ) );
|
||||
parent::delete();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -744,7 +783,7 @@ class _Import extends \IPS\Node\Model
|
||||
* @param mixed $where Where clause
|
||||
* @return array
|
||||
*/
|
||||
public static function search( $column, $query, $order=NULL, $where=array() )
|
||||
public static function search( string $column, string $query, string $order=NULL, mixed $where=array() ): array
|
||||
{
|
||||
if ( $column === '_title' )
|
||||
{
|
||||
|
||||
@@ -11,56 +11,81 @@
|
||||
namespace IPS\core;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Content;
|
||||
use IPS\Content\Search\ContentFilter;
|
||||
use IPS\Content\Search\Query;
|
||||
use IPS\Data\Store;
|
||||
use IPS\Db;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\CheckboxSet;
|
||||
use IPS\Helpers\Form\Member as FormMember;
|
||||
use IPS\Helpers\Form\Node;
|
||||
use IPS\Helpers\Form\Number;
|
||||
use IPS\Helpers\Form\Translatable;
|
||||
use IPS\Helpers\Form\YesNo;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Http\Url\Friendly;
|
||||
use IPS\Lang;
|
||||
use IPS\Member;
|
||||
use IPS\Member\Group;
|
||||
use IPS\Node\Model;
|
||||
use IPS\Xml\Rss as XmlRss;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* RSS Exports
|
||||
*/
|
||||
class _Rss extends \IPS\Node\Model
|
||||
class Rss extends Model
|
||||
{
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
protected static array $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Table
|
||||
*/
|
||||
public static $databaseTable = 'core_rss_export';
|
||||
public static ?string $databaseTable = 'core_rss_export';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'rss_';
|
||||
public static string $databasePrefix = 'rss_';
|
||||
|
||||
/**
|
||||
* @brief [Node] Order Database Column
|
||||
*/
|
||||
public static $databaseColumnOrder = 'position';
|
||||
public static ?string $databaseColumnOrder = 'position';
|
||||
|
||||
/**
|
||||
* @brief [Node] Node Title
|
||||
*/
|
||||
public static $nodeTitle = 'rss_exports';
|
||||
public static string $nodeTitle = 'rss_exports';
|
||||
|
||||
/**
|
||||
* @brief [Node] Title prefix. If specified, will look for a language key with "{$key}_title" as the key
|
||||
*/
|
||||
public static $titleLangPrefix = 'rss_export_title_';
|
||||
public static ?string $titleLangPrefix = 'rss_export_title_';
|
||||
|
||||
/**
|
||||
* @brief [Node] Description suffix. If specified, will look for a language key with "{$titleLangPrefix}_{$id}_{$descriptionLangSuffix}" as the key
|
||||
*/
|
||||
public static $descriptionLangSuffix = '_desc';
|
||||
public static ?string $descriptionLangSuffix = '_desc';
|
||||
|
||||
/**
|
||||
* @brief [Node] Enabled/Disabled Column
|
||||
*/
|
||||
public static $databaseColumnEnabledDisabled = 'enabled';
|
||||
public static ?string $databaseColumnEnabledDisabled = 'enabled';
|
||||
|
||||
/**
|
||||
* @brief [Node] ACP Restrictions
|
||||
@@ -78,7 +103,7 @@ class _Rss extends \IPS\Node\Model
|
||||
'prefix' => 'foo_', // [Optional] Rather than specifying each key in the map, you can specify a prefix, and it will automatically look for restrictions with the key "[prefix]_add/edit/permissions/delete"
|
||||
* @endcode
|
||||
*/
|
||||
protected static $restrictions = array(
|
||||
protected static ?array $restrictions = array(
|
||||
'app' => 'core',
|
||||
'module' => 'discovery',
|
||||
'all' => 'rss_export_manage',
|
||||
@@ -87,48 +112,48 @@ class _Rss extends \IPS\Node\Model
|
||||
/**
|
||||
* @brief [Node] URL Base
|
||||
*/
|
||||
public static $urlBase = 'app=core&module=discover&controller=rss&id=';
|
||||
public static string $urlBase = 'app=core&module=discover&controller=rss&id=';
|
||||
|
||||
/**
|
||||
* @brief [Node] SEO Template
|
||||
*/
|
||||
public static $urlTemplate = 'rss_feed';
|
||||
public static string $urlTemplate = 'rss_feed';
|
||||
|
||||
/**
|
||||
* @brief SEO Title Column
|
||||
*/
|
||||
public static $seoTitleColumn = 'seo_title';
|
||||
public static string $seoTitleColumn = 'seo_title';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Attempt to load from cache
|
||||
* @note If this is set to TRUE you MUST define a getStore() method to return the objects from cache
|
||||
*/
|
||||
protected static $loadFromCache = TRUE;
|
||||
protected static bool $loadFromCache = TRUE;
|
||||
|
||||
/**
|
||||
* [Node] Add/Edit Form
|
||||
*
|
||||
* @param \IPS\Helpers\Form $form The form
|
||||
* @param Form $form The form
|
||||
* @return void
|
||||
*/
|
||||
public function form( &$form )
|
||||
public function form( Form &$form ) : void
|
||||
{
|
||||
/* Main Settings Form */
|
||||
$form->addHeader( 'rss_settings' );
|
||||
$form->add( new \IPS\Helpers\Form\Translatable( 'rss_name', NULL, TRUE, array( 'app' => 'core', 'key' => ( $this->_id ) ? "rss_export_title_{$this->_id}" : NULL ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Translatable( 'rss_desc', NULL, TRUE, array( 'app' => 'core', 'key' => ( $this->_id ) ? "rss_export_title_{$this->_id}_desc" : NULL ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'rss_count', ( $this->_id ) ? $this->count : 25, TRUE, array( 'min' => 1, 'max' => 100 ) ) );
|
||||
$form->add( new Translatable( 'rss_name', NULL, TRUE, array( 'app' => 'core', 'key' => ( $this->_id ) ? "rss_export_title_{$this->_id}" : NULL ) ) );
|
||||
$form->add( new Translatable( 'rss_desc', NULL, TRUE, array( 'app' => 'core', 'key' => ( $this->_id ) ? "rss_export_title_{$this->_id}_desc" : NULL ) ) );
|
||||
$form->add( new Number( 'rss_count', ( $this->_id ) ? $this->count : 25, TRUE, array( 'min' => 1, 'max' => 100 ) ) );
|
||||
|
||||
$groups = array();
|
||||
foreach( \IPS\Member\Group::groups() AS $group_id => $group )
|
||||
foreach( Group::groups() AS $group_id => $group )
|
||||
{
|
||||
$groups[ $group_id ] = $group->name;
|
||||
}
|
||||
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'rss_groups', ( $this->_id ) ? $this->groups : '*', FALSE, array( 'options' => $groups, 'multiple' => TRUE, 'unlimited' => '*', 'impliedUnlimited' => TRUE ) ) );
|
||||
$form->add( new CheckboxSet( 'rss_groups', ( $this->_id ) ? $this->groups : '*', FALSE, array( 'options' => $groups, 'multiple' => TRUE, 'unlimited' => '*', 'impliedUnlimited' => TRUE ) ) );
|
||||
|
||||
/* Content Form */
|
||||
$form->addHeader( 'rss_content' );
|
||||
foreach( \IPS\Content::routedClasses( TRUE, FALSE, TRUE ) AS $class )
|
||||
foreach( Content::routedClasses( TRUE, FALSE, TRUE ) AS $class )
|
||||
{
|
||||
if ( isset( $class::$databaseColumnMap['author'] ) )
|
||||
{
|
||||
@@ -140,17 +165,17 @@ class _Rss extends \IPS\Node\Model
|
||||
$containerClass = $class::$containerNodeClass;
|
||||
}
|
||||
|
||||
\IPS\Member::loggedIn()->language()->words["rss_classes_{$class}"] = \IPS\Member::loggedIn()->language()->addToStack( $class::$title . '_pl' );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'rss_classes_' . $class, ( $this->_id ) ? \in_array( $class, $this->configuration['classes'] ) : FALSE, FALSE, $options ) );
|
||||
Member::loggedIn()->language()->words["rss_classes_{$class}"] = Member::loggedIn()->language()->addToStack( $class::$title . '_pl' );
|
||||
$form->add( new YesNo( 'rss_classes_' . $class, ( $this->_id ) ? in_array( $class, $this->configuration['classes'] ) : FALSE, FALSE, $options ) );
|
||||
|
||||
if ( $containerClass )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words["nodes_{$class}"] = \IPS\Member::loggedIn()->language()->addToStack( $containerClass::$nodeTitle );
|
||||
$form->add( new \IPS\Helpers\Form\Node( "nodes_{$class}", ( $this->_id AND isset( $this->configuration['containers'][$class] ) ) ? $this->configuration['containers'][$class] : 0, FALSE, array(
|
||||
Member::loggedIn()->language()->words["nodes_{$class}"] = Member::loggedIn()->language()->addToStack( $containerClass::$nodeTitle );
|
||||
$form->add( new Node( "nodes_{$class}", ( $this->_id AND isset( $this->configuration['containers'][$class] ) ) ? $this->configuration['containers'][$class] : 0, FALSE, array(
|
||||
'class' => $containerClass,
|
||||
'zeroVal' => 'all',
|
||||
'multiple' => TRUE,
|
||||
'permissionCheck' => function( $val ) { return $val->can( 'view', new \IPS\Member ); },
|
||||
'permissionCheck' => function( $val ) { return $val->can( 'view', new Member ); },
|
||||
'forceOwner' => FALSE,
|
||||
), NULL, NULL, NULL, "rss_nodes_{$class::$title}" ) );
|
||||
}
|
||||
@@ -160,17 +185,17 @@ class _Rss extends \IPS\Node\Model
|
||||
$members = NULL;
|
||||
if ( $this->_id AND isset( $this->configuration['members'] ) )
|
||||
{
|
||||
if ( \count( $this->configuration['members'] ) )
|
||||
if ( count( $this->configuration['members'] ) )
|
||||
{
|
||||
$members = array();
|
||||
foreach( $this->configuration['members'] AS $member )
|
||||
{
|
||||
$members[] = \IPS\Member::load( $member );
|
||||
$members[] = Member::load( $member );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Member( 'rss_members', $members, FALSE, array( 'multiple' => NULL, 'nullLang' => 'everyone' ) ) );
|
||||
$form->add( new FormMember( 'rss_members', $members, FALSE, array( 'multiple' => NULL, 'nullLang' => 'everyone' ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -179,7 +204,7 @@ class _Rss extends \IPS\Node\Model
|
||||
* @param array $values Values from the form
|
||||
* @return array
|
||||
*/
|
||||
public function formatFormValues( $values )
|
||||
public function formatFormValues( array $values ): array
|
||||
{
|
||||
/* Build our config */
|
||||
$config = array(
|
||||
@@ -193,7 +218,7 @@ class _Rss extends \IPS\Node\Model
|
||||
{
|
||||
if ( mb_substr( $k, 0, 12 ) == 'rss_classes_' )
|
||||
{
|
||||
if ( $values[$k] == TRUE )
|
||||
if ( $v )
|
||||
{
|
||||
$config['classes'][] = str_replace( 'rss_classes_', '', $k );
|
||||
}
|
||||
@@ -202,11 +227,11 @@ class _Rss extends \IPS\Node\Model
|
||||
}
|
||||
else if ( mb_substr( $k, 0, 6 ) == 'nodes_' )
|
||||
{
|
||||
if ( \is_array( $v ) )
|
||||
if ( is_array( $v ) )
|
||||
{
|
||||
foreach( $v AS $id => $node )
|
||||
{
|
||||
if ( $node instanceof \IPS\Node\Model )
|
||||
if ( $node instanceof Model )
|
||||
{
|
||||
$config['containers'][ str_replace( 'nodes_', '', $k ) ][] = $node->_id;
|
||||
}
|
||||
@@ -218,7 +243,7 @@ class _Rss extends \IPS\Node\Model
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $v instanceof \IPS\Node\Model )
|
||||
if ( $v instanceof Model )
|
||||
{
|
||||
$config['containers'][ str_replace( 'nodes_', '', $k ) ][] = $v->_id;
|
||||
}
|
||||
@@ -235,17 +260,17 @@ class _Rss extends \IPS\Node\Model
|
||||
/* Set the members */
|
||||
if ( array_key_exists( 'rss_members', $values ) )
|
||||
{
|
||||
if ( \is_array( $values['rss_members'] ) )
|
||||
if ( is_array( $values['rss_members'] ) )
|
||||
{
|
||||
foreach( $values['rss_members'] AS $member )
|
||||
{
|
||||
if ( $member instanceof \IPS\Member )
|
||||
if ( $member instanceof Member )
|
||||
{
|
||||
$config['members'][] = $member->member_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( $values['rss_members'] instanceof \IPS\Member )
|
||||
else if ( $values['rss_members'] instanceof Member )
|
||||
{
|
||||
$config['members'][] = $values['rss_members']->member_id;
|
||||
}
|
||||
@@ -263,16 +288,16 @@ class _Rss extends \IPS\Node\Model
|
||||
/* Custom Language Strings */
|
||||
if ( array_key_exists( 'rss_name', $values ) )
|
||||
{
|
||||
\IPS\Lang::saveCustom( 'core', "rss_export_title_{$this->_id}", $values['rss_name'] );
|
||||
Lang::saveCustom( 'core', "rss_export_title_{$this->_id}", $values['rss_name'] );
|
||||
|
||||
if ( \is_array( $values['rss_name'] ) )
|
||||
if ( is_array( $values['rss_name'] ) )
|
||||
{
|
||||
reset( $values['rss_name'] );
|
||||
$this->seo_title = \IPS\Http\Url\Friendly::seoTitle( $values['rss_name'][ key( $values['rss_name'] ) ] );
|
||||
$this->seo_title = Friendly::seoTitle( $values['rss_name'][ key( $values['rss_name'] ) ] );
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->seo_title = \IPS\Http\Url\Friendly::seoTitle( $values['rss_name'] );
|
||||
$this->seo_title = Friendly::seoTitle( $values['rss_name'] );
|
||||
}
|
||||
|
||||
unset( $values['rss_name'] );
|
||||
@@ -280,7 +305,7 @@ class _Rss extends \IPS\Node\Model
|
||||
|
||||
if ( array_key_exists( 'rss_desc', $values ) )
|
||||
{
|
||||
\IPS\Lang::saveCustom( 'core', "rss_export_title_{$this->_id}_desc", $values['rss_desc'] );
|
||||
Lang::saveCustom( 'core', "rss_export_title_{$this->_id}_desc", $values['rss_desc'] );
|
||||
|
||||
unset( $values['rss_desc'] );
|
||||
}
|
||||
@@ -293,14 +318,14 @@ class _Rss extends \IPS\Node\Model
|
||||
* @brief [ActiveRecord] Caches
|
||||
* @note Defined cache keys will be cleared automatically as needed
|
||||
*/
|
||||
protected $caches = array( 'rssFeeds' );
|
||||
protected array $caches = array( 'rssFeeds' );
|
||||
|
||||
/**
|
||||
* Get Configuration
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_configuration()
|
||||
public function get_configuration() : array
|
||||
{
|
||||
return json_decode( $this->_data['configuration'], TRUE );
|
||||
}
|
||||
@@ -311,7 +336,7 @@ class _Rss extends \IPS\Node\Model
|
||||
* @param array $values The configuration
|
||||
* @return void
|
||||
*/
|
||||
public function set_configuration( array $values )
|
||||
public function set_configuration( array $values ) : void
|
||||
{
|
||||
$this->_data['configuration'] = json_encode( $values );
|
||||
}
|
||||
@@ -322,9 +347,9 @@ class _Rss extends \IPS\Node\Model
|
||||
* @param array|string $values The groups, or an asterisk for all groups
|
||||
* @return void
|
||||
*/
|
||||
public function set_groups( $values )
|
||||
public function set_groups( array|string $values ) : void
|
||||
{
|
||||
if ( \is_array( $values ) )
|
||||
if ( is_array( $values ) )
|
||||
{
|
||||
$this->_data['groups'] = implode( ',', $values );
|
||||
}
|
||||
@@ -337,9 +362,9 @@ class _Rss extends \IPS\Node\Model
|
||||
/**
|
||||
* Get Groups
|
||||
*
|
||||
* @return array
|
||||
* @return array|string
|
||||
*/
|
||||
public function get_groups()
|
||||
public function get_groups() : array|string
|
||||
{
|
||||
if ( $this->_data['groups'] == '*' )
|
||||
{
|
||||
@@ -352,32 +377,32 @@ class _Rss extends \IPS\Node\Model
|
||||
/**
|
||||
* Generate the feed
|
||||
*
|
||||
* @param \IPS\Member|NULL $member The member, or NULL for a Guest
|
||||
* @param Member|NULL $member The member, or NULL for a Guest
|
||||
* @return string
|
||||
*/
|
||||
public function generate( $member=NULL )
|
||||
public function generate( ?Member $member=NULL ) : string
|
||||
{
|
||||
$member = $member ?: new \IPS\Member;
|
||||
$member = $member ?: new Member;
|
||||
|
||||
$search = \IPS\Content\Search\Query::init( $member );
|
||||
$search = Query::init( $member );
|
||||
$filterByClass = FALSE;
|
||||
|
||||
if ( \count( $this->configuration['classes'] ) )
|
||||
if ( count( $this->configuration['classes'] ) )
|
||||
{
|
||||
$filterByClass = TRUE;
|
||||
$filters = array();
|
||||
|
||||
foreach( $this->configuration['classes'] AS $class )
|
||||
{
|
||||
if( class_exists( $class, TRUE ) )
|
||||
if( class_exists( $class ) )
|
||||
{
|
||||
if ( isset( $class::$firstCommentRequired ) AND $class::$firstCommentRequired )
|
||||
{
|
||||
$filter = \IPS\Content\Search\ContentFilter::init( $class, TRUE, TRUE, FALSE )->onlyFirstComment();
|
||||
$filter = ContentFilter::init( $class, TRUE, TRUE, FALSE )->onlyFirstComment();
|
||||
}
|
||||
else
|
||||
{
|
||||
$filter = \IPS\Content\Search\ContentFilter::init( $class, TRUE, FALSE, FALSE );
|
||||
$filter = ContentFilter::init( $class, TRUE, FALSE, FALSE );
|
||||
}
|
||||
|
||||
if ( !empty( $this->configuration['containers'][$class] ) )
|
||||
@@ -392,15 +417,15 @@ class _Rss extends \IPS\Node\Model
|
||||
$search->filterByContent( $filters );
|
||||
}
|
||||
|
||||
if ( isset( $this->configuration['members'] ) AND \count( $this->configuration['members'] ) )
|
||||
if ( isset( $this->configuration['members'] ) AND count( $this->configuration['members'] ) )
|
||||
{
|
||||
$search->filterByAuthor( $this->configuration['members'] );
|
||||
}
|
||||
|
||||
$search->setLimit( $this->count );
|
||||
$search->setOrder( \IPS\Content\Search\Query::ORDER_NEWEST_CREATED );
|
||||
$search->setOrder( Query::ORDER_NEWEST_CREATED );
|
||||
|
||||
if( $filterByClass == TRUE AND !\count( $filters ) )
|
||||
if( $filterByClass AND !count( $filters ) )
|
||||
{
|
||||
$results = array();
|
||||
}
|
||||
@@ -410,10 +435,10 @@ class _Rss extends \IPS\Node\Model
|
||||
}
|
||||
|
||||
/* We have to use get() to ensure CDATA tags wrap the title properly */
|
||||
$title = \IPS\Member::loggedIn()->language()->get( "rss_export_title_{$this->_id}" );
|
||||
$description = \IPS\Member::loggedIn()->language()->get( "rss_export_title_{$this->_id}_desc" );
|
||||
$title = Member::loggedIn()->language()->get( "rss_export_title_{$this->_id}" );
|
||||
$description = Member::loggedIn()->language()->get( "rss_export_title_{$this->_id}_desc" );
|
||||
|
||||
$document = \IPS\Xml\Rss::newDocument( $this->url(), $title, $description );
|
||||
$document = XmlRss::newDocument( $this->url(), $title, $description );
|
||||
|
||||
foreach( $results AS $result )
|
||||
{
|
||||
@@ -428,28 +453,28 @@ class _Rss extends \IPS\Node\Model
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getStore()
|
||||
public static function getStore(): array
|
||||
{
|
||||
if ( !isset( \IPS\Data\Store::i()->rssFeeds ) )
|
||||
if ( !isset( Store::i()->rssFeeds ) )
|
||||
{
|
||||
\IPS\Data\Store::i()->rssFeeds = iterator_to_array( \IPS\Db::i()->select( '*', static::$databaseTable, NULL, "rss_position ASC" )->setKeyField( 'rss_id' ) );
|
||||
Store::i()->rssFeeds = iterator_to_array( Db::i()->select( '*', static::$databaseTable, NULL, "rss_position ASC" )->setKeyField( 'rss_id' ) );
|
||||
}
|
||||
|
||||
return \IPS\Data\Store::i()->rssFeeds;
|
||||
return Store::i()->rssFeeds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL
|
||||
*
|
||||
* @return \IPS\Http\Url
|
||||
* @return Url|string|null
|
||||
*/
|
||||
public function url()
|
||||
public function url(): Url|string|null
|
||||
{
|
||||
$url = parent::url();
|
||||
|
||||
if ( \IPS\Member::loggedIn()->member_id )
|
||||
if ( Member::loggedIn()->member_id )
|
||||
{
|
||||
$url = $url->setQueryString( array( 'member_id' => \IPS\Member::loggedIn()->member_id, 'key' => \IPS\Member::loggedIn()->getUniqueMemberHash() ) );
|
||||
$url = $url->setQueryString( array( 'member_id' => Member::loggedIn()->member_id, 'key' => Member::loggedIn()->getUniqueMemberHash() ) );
|
||||
}
|
||||
|
||||
return $url;
|
||||
|
||||
Reference in new issue
Block a user