Version 4.6.0
This commit is contained in:
1 parent
f79dcf067a
commit
517a5e1f70
2036 files changed
+110041
-26162
No files matched your search
@@ -263,6 +263,11 @@ class _Import extends \IPS\Node\Model
|
||||
$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(
|
||||
'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' ) );
|
||||
$this->_extension->form( $form, $this );
|
||||
@@ -315,7 +320,17 @@ class _Import extends \IPS\Node\Model
|
||||
throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack( 'rss_import_invalid' ) );
|
||||
}
|
||||
|
||||
$values['title'] = (string) $request->get()->decodeXml()->channel->title;
|
||||
$values['title'] = (string) $response->channel->title;
|
||||
|
||||
/* Reset the has_enclosures flag */
|
||||
foreach( $response->articles() as $article )
|
||||
{
|
||||
if ( isset( $article['enclosure'] ) and isset( $article['enclosure']['url'] ) )
|
||||
{
|
||||
$this->has_enclosures = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( isset( $values['rss_import_node_id'] ) )
|
||||
@@ -336,6 +351,15 @@ class _Import extends \IPS\Node\Model
|
||||
unset( $values['rss_import_auto_follow'] );
|
||||
}
|
||||
|
||||
$this->enclosures = $values['rss_import_enclosures'];
|
||||
unset( $values['rss_import_enclosures'] );
|
||||
|
||||
/* If we are ignoring enclosures, reset the has_enclosures flag */
|
||||
if( $this->enclosures == 'ignore' )
|
||||
{
|
||||
$this->has_enclosures = false;
|
||||
}
|
||||
|
||||
if ( $settings = $this->_extension->saveForm( $values, $this ) )
|
||||
{
|
||||
$values['settings'] = $settings;
|
||||
@@ -433,78 +457,98 @@ class _Import extends \IPS\Node\Model
|
||||
$readMoreLink = "<p><a href='{$article['link']}' {$linkRelPart}>{$this->showlink}</a></p>";
|
||||
}
|
||||
|
||||
/* 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'] );
|
||||
|
||||
$imageHtml = '';
|
||||
if ( isset( $article['enclosure'] ) and isset( $article['enclosure']['url'] ) and isset( $article['enclosure']['length'] ) and isset( $article['enclosure']['type'] ) )
|
||||
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 ( $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 \IPS\Settings::i()->image_suite == 'imagemagick' ) )
|
||||
{
|
||||
try
|
||||
/* Are we remotely linking to the image? */
|
||||
if( $this->enclosures == 'hotlink' and !$this->_enclosureEmbedded( $article['enclosure']['url'], $articleContent ) )
|
||||
{
|
||||
$response = \IPS\Http\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 )
|
||||
{
|
||||
if ( preg_match( '/^' . str_replace( '~~', '.+', preg_quote( str_replace( '*', '~~', $mime ), '/' ) ) . '$/i', $contentType ) )
|
||||
{
|
||||
$match = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Does it match? */
|
||||
if ( $match )
|
||||
{
|
||||
$processAttachment = TRUE;
|
||||
\IPS\Image::$exifEnabled = FALSE;
|
||||
if ( method_exists( $this->_extension, 'processEnclosure' ) )
|
||||
{
|
||||
if ( $this->_extension->processEnclosure( $this, $response, $article ) !== FALSE )
|
||||
{
|
||||
$processAttachment = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $processAttachment )
|
||||
{
|
||||
try
|
||||
{
|
||||
$image = \IPS\Image::create( $response );
|
||||
$maxImageSizes = NULL;
|
||||
|
||||
if ( \IPS\Settings::i()->attachment_resample_size )
|
||||
{
|
||||
$maxImageSizes = explode( 'x', \IPS\Settings::i()->attachment_resample_size );
|
||||
}
|
||||
if ( $maxImageSizes !== NULL )
|
||||
{
|
||||
$image->resizeToMax( $maxImageSizes[0], $maxImageSizes[1] );
|
||||
}
|
||||
|
||||
$newFile = \IPS\File::create( 'core_Attachment', 'rssImage-' . $guid . '.' . $image->type, (string)$image );
|
||||
$attachment = $newFile->makeAttachment( md5( $guid . ':' . session_id() ), $member );
|
||||
$article['attachment'] = $attachment;
|
||||
|
||||
$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'] );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
$imageName = basename( parse_url( $article['enclosure']['url'], PHP_URL_PATH ) );
|
||||
$imageHtml = \IPS\Theme::i()->getTemplate( 'editor', 'core', 'global' )->linkedImage( $article['enclosure']['url'], $imageName ?: 'image' );
|
||||
}
|
||||
catch ( \IPS\Http\Request\Exception $e )
|
||||
elseif( $this->enclosures == 'import' )
|
||||
{
|
||||
try
|
||||
{
|
||||
$response = \IPS\Http\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 )
|
||||
{
|
||||
if ( preg_match( '/^' . str_replace( '~~', '.+', preg_quote( str_replace( '*', '~~', $mime ), '/' ) ) . '$/i', $contentType ) )
|
||||
{
|
||||
$match = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Does it match? */
|
||||
if ( $match )
|
||||
{
|
||||
$processAttachment = TRUE;
|
||||
\IPS\Image::$exifEnabled = FALSE;
|
||||
if ( method_exists( $this->_extension, 'processEnclosure' ) )
|
||||
{
|
||||
if ( $this->_extension->processEnclosure( $this, $response, $article ) !== FALSE )
|
||||
{
|
||||
$processAttachment = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $processAttachment )
|
||||
{
|
||||
try
|
||||
{
|
||||
$image = \IPS\Image::create( $response );
|
||||
$maxImageSizes = NULL;
|
||||
|
||||
if ( \IPS\Settings::i()->attachment_resample_size )
|
||||
{
|
||||
$maxImageSizes = explode( 'x', \IPS\Settings::i()->attachment_resample_size );
|
||||
|
||||
/* If the dimensions were 0x0 then correct... */
|
||||
if ( !$maxImageSizes[0] or !$maxImageSizes[1] )
|
||||
{
|
||||
$maxImageSizes = NULL;
|
||||
}
|
||||
}
|
||||
if ( $maxImageSizes !== NULL )
|
||||
{
|
||||
$image->resizeToMax( $maxImageSizes[0], $maxImageSizes[1] );
|
||||
}
|
||||
|
||||
$newFile = \IPS\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'] );
|
||||
}
|
||||
}
|
||||
catch ( \Exception $e ){}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( \IPS\Http\Request\Exception $e )
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$content = $imageHtml . \IPS\Text\Parser::parseStatic( $article['content'] . $readMoreLink, TRUE, NULL, $member, $this->_extension->fileStorage, TRUE, !(bool) $member->group['g_dohtml'] );
|
||||
$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 ) );
|
||||
@@ -515,7 +559,7 @@ class _Import extends \IPS\Node\Model
|
||||
'rss_imported_guid' => $guid,
|
||||
'rss_imported_content_id' => $item->$idColumn,
|
||||
'rss_imported_import_id' => $this->id
|
||||
) );
|
||||
), TRUE );
|
||||
|
||||
if ( $this->auto_follow )
|
||||
{
|
||||
@@ -540,7 +584,7 @@ class _Import extends \IPS\Node\Model
|
||||
'rss_imported_guid' => $guid,
|
||||
'rss_imported_content_id' => 0,
|
||||
'rss_imported_import_id' => $this->id
|
||||
) );
|
||||
), TRUE );
|
||||
}
|
||||
|
||||
$i++;
|
||||
@@ -558,6 +602,121 @@ class _Import extends \IPS\Node\Model
|
||||
$this->last_import = time();
|
||||
$this->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the enclosure URL is already embedded in the content we are parsing and if so, replace it
|
||||
*
|
||||
* @param string $url Enclosure URL
|
||||
* @param array $attachment Attachment details
|
||||
* @param string $content Body of article
|
||||
* @return bool
|
||||
*/
|
||||
protected function _enclosureReplace( $url, $attachment, &$content )
|
||||
{
|
||||
/* Load source */
|
||||
$source = new \IPS\Xml\DOMDocument( '1.0', 'UTF-8' );
|
||||
$source->loadHTML( \IPS\Xml\DOMDocument::wrapHtml( $content ) );
|
||||
|
||||
/* Look for the image URL and replace it with the attachment if found */
|
||||
$replaced = FALSE;
|
||||
|
||||
$contentImages = $source->getElementsByTagName( 'img' );
|
||||
foreach( $contentImages as $element )
|
||||
{
|
||||
$srcAttribute = $element->hasAttribute('data-src') ? 'data-src' : 'src';
|
||||
if ( $element->hasAttribute( $srcAttribute ) AND $element->getAttribute( $srcAttribute ) == $url )
|
||||
{
|
||||
$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'] ) );
|
||||
}
|
||||
}
|
||||
|
||||
if( $replaced )
|
||||
{
|
||||
$content = \IPS\Text\DOMParser::getDocumentBodyContents( $source );
|
||||
$content = \IPS\Text\Parser::replaceFileStoreTags( $content );
|
||||
|
||||
/* Set lazy loading and wrapping link on the content */
|
||||
if( $rebuilt = \IPS\Text\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 ) );
|
||||
|
||||
$tags = array( 'a', 'img' );
|
||||
|
||||
foreach( $tags as $tag )
|
||||
{
|
||||
$elements = $source->getElementsByTagName( $tag );
|
||||
foreach( $elements as $element )
|
||||
{
|
||||
/* Anything which has a URL may need swapping out */
|
||||
foreach ( array( 'href', 'src', 'data-src', 'data-video-src', 'data-embed-src', 'srcset', 'data-ipshover-target', 'data-fileid', 'cite', 'action', 'longdesc', 'usemap', 'poster' ) as $attribute )
|
||||
{
|
||||
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 ) )
|
||||
{
|
||||
$element->setAttribute( $attribute, '%7B___base_url___%7D/' . $matches[3] );
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ( array( 'srcset', 'style' ) as $attribute )
|
||||
{
|
||||
if ( $element->hasAttribute( $attribute ) )
|
||||
{
|
||||
if ( mb_strpos( $element->getAttribute( $attribute ), \IPS\Settings::i()->base_url ) )
|
||||
{
|
||||
$element->setAttribute( $attribute, str_replace( \IPS\Settings::i()->base_url, '%7B___base_url___%7D/', $element->getAttribute( $attribute ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$content = \IPS\Text\DOMParser::getDocumentBodyContents( $source );
|
||||
|
||||
/* Replace file storage tags */
|
||||
$content = preg_replace( '/<fileStore\.([\d\w\_]+?)>/i', '<fileStore.$1>', $content );
|
||||
$content = str_replace( array( '<___base_url___>', '%7B___base_url___%7D' ), '<___base_url___>', $content );
|
||||
}
|
||||
|
||||
return $replaced;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the enclosure URL is already embedded in the content we are parsing
|
||||
*
|
||||
* @param string $url Enclosure URL
|
||||
* @param string $content Body of article
|
||||
* @return bool
|
||||
*/
|
||||
protected function _enclosureEmbedded( $url, $content )
|
||||
{
|
||||
/* Load source */
|
||||
$source = new \IPS\Xml\DOMDocument( '1.0', 'UTF-8' );
|
||||
$source->loadHTML( \IPS\Xml\DOMDocument::wrapHtml( $content ) );
|
||||
|
||||
/* Look for the image URL */
|
||||
$contentImages = $source->getElementsByTagName( 'img' );
|
||||
foreach( $contentImages as $element )
|
||||
{
|
||||
if ( $element->hasAttribute('src') AND $element->getAttribute('src') == $url )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* [ActiveRecord] Delete Record
|
||||
|
||||
@@ -124,7 +124,7 @@ class _Rss extends \IPS\Node\Model
|
||||
{
|
||||
$groups[ $group_id ] = $group->name;
|
||||
}
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'rss_groups', ( $this->_id ) ? $this->groups : '*', FALSE, array( 'options' => $groups, 'multiple' => TRUE, 'unlimited' => '*' ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'rss_groups', ( $this->_id ) ? $this->groups : '*', FALSE, array( 'options' => $groups, 'multiple' => TRUE, 'unlimited' => '*', 'impliedUnlimited' => TRUE ) ) );
|
||||
|
||||
/* Content Form */
|
||||
$form->addHeader( 'rss_content' );
|
||||
@@ -422,17 +422,6 @@ class _Rss extends \IPS\Node\Model
|
||||
|
||||
return $document->asXML();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all saved RSS feeds (enabled status must be checked in userland code)
|
||||
*
|
||||
* @return array
|
||||
* @deprecated
|
||||
*/
|
||||
public static function getAllFeeds()
|
||||
{
|
||||
return static::getStore();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all saved RSS feeds (enabled status must be checked in userland code)
|
||||
|
||||
Reference in new issue
Block a user