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' )
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user