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,31 +12,46 @@
|
||||
namespace IPS\cms\extensions\core\RssImport;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use Exception;
|
||||
use IPS\cms\Databases;
|
||||
use IPS\cms\Fields;
|
||||
use IPS\Content;
|
||||
use IPS\core\Rss\Import;
|
||||
use IPS\Db;
|
||||
use IPS\Extensions\RssImportAbstract;
|
||||
use IPS\File;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Radio;
|
||||
use IPS\Http\Response;
|
||||
use IPS\Image;
|
||||
use IPS\Member;
|
||||
use IPS\Node\Model;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function get_class;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief RSS Import extension: RssImport
|
||||
*/
|
||||
class _RssImport
|
||||
class RssImport extends RssImportAbstract
|
||||
{
|
||||
/**
|
||||
* @brief RSSImport Classes
|
||||
*/
|
||||
public $classes = array();
|
||||
|
||||
/**
|
||||
* @brief Filestorage class
|
||||
*/
|
||||
public $fileStorage = 'cms_Records';
|
||||
public string $fileStorage = 'cms_Records';
|
||||
|
||||
/**
|
||||
* @brief Encosure images to process
|
||||
* @brief Enclosure images to process
|
||||
*/
|
||||
public static $enclosures = array();
|
||||
public static array $enclosures = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@@ -47,7 +62,7 @@ class _RssImport
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach ( \IPS\cms\Databases::databases() as $id => $database )
|
||||
foreach ( Databases::databases() as $id => $database )
|
||||
{
|
||||
if ( $database->canImportRss() )
|
||||
{
|
||||
@@ -55,7 +70,7 @@ class _RssImport
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
catch ( Exception $e )
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -63,10 +78,9 @@ class _RssImport
|
||||
/**
|
||||
* Show in the Admin CP?
|
||||
*
|
||||
* @param Object $class The class to check
|
||||
* @return boolean
|
||||
*/
|
||||
public function showInAdminCp( $class ): bool
|
||||
public function showInAdminCp(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -76,12 +90,12 @@ class _RssImport
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function availableOptions()
|
||||
public function availableOptions(): array
|
||||
{
|
||||
$options = array();
|
||||
try
|
||||
{
|
||||
foreach ( \IPS\cms\Databases::databases() as $id => $database )
|
||||
foreach ( Databases::databases() as $id => $database )
|
||||
{
|
||||
if ( $database->canImportRss() )
|
||||
{
|
||||
@@ -89,7 +103,7 @@ class _RssImport
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
catch ( Exception $e )
|
||||
{
|
||||
} // If you have not upgraded pages but it is installed, this throws an error
|
||||
|
||||
@@ -99,10 +113,10 @@ class _RssImport
|
||||
/**
|
||||
* Node selector options
|
||||
*
|
||||
* @param \IPS\core\Rss\Import|null $rss Existing RSS object if editing|NULL if not
|
||||
* @param Import|null $rss Existing RSS object if editing|null if not
|
||||
* @return array
|
||||
*/
|
||||
public function nodeSelectorOptions( $rss )
|
||||
public function nodeSelectorOptions( ?Import $rss ): array
|
||||
{
|
||||
/* Get the correct class */
|
||||
$class = $rss->_class;
|
||||
@@ -112,17 +126,19 @@ class _RssImport
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \IPS\core\Rss\Import $rss RSS object
|
||||
* @param Import $rss RSS object
|
||||
* @param array $article RSS feed article importing
|
||||
* @param \IPS\Node\Model $container Container object
|
||||
* @param Model $container Container object
|
||||
* @param string $content Post content with read more link if set
|
||||
* @return \IPS\Content
|
||||
* @return Content|null
|
||||
*/
|
||||
public function create( \IPS\core\Rss\Import $rss, $article, \IPS\Node\Model $container, $content )
|
||||
public function create( Import $rss, array $article, Model $container, string $content ): ?Content
|
||||
{
|
||||
$settings = $rss->settings;
|
||||
$recordClass = $rss->_class;
|
||||
$member = \IPS\Member::load( $rss->member );
|
||||
$member = Member::load( $rss->member );
|
||||
|
||||
/* @var Fields $fieldsClass */
|
||||
$fieldsClass = '\IPS\cms\Fields' . $recordClass::database()->id;
|
||||
$customFields = $fieldsClass::fields( $settings, 'add' );
|
||||
$fieldData = $fieldsClass::data();
|
||||
@@ -196,7 +212,7 @@ class _RssImport
|
||||
}
|
||||
else if ( isset( $article['attachment'] ) )
|
||||
{
|
||||
\IPS\Db::i()->insert( 'core_attachments_map', array(
|
||||
Db::i()->insert( 'core_attachments_map', array(
|
||||
'attachment_id' => $article['attachment']['attach_id'],
|
||||
'location_key' => 'cms_Records' . $recordClass::database()->id,
|
||||
'id1' => $record->primary_id_field,
|
||||
@@ -214,7 +230,7 @@ class _RssImport
|
||||
|
||||
return $record;
|
||||
}
|
||||
catch( \Exception $e )
|
||||
catch( Exception $e )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@@ -223,16 +239,15 @@ class _RssImport
|
||||
/**
|
||||
* Process the enclosure
|
||||
*
|
||||
* @param \IPS\core\Rss\Import $rss
|
||||
* @param \IPS\Http $response
|
||||
* @param Import $rss
|
||||
* @param Response $response
|
||||
* @param array $article
|
||||
* @return bool
|
||||
*/
|
||||
public function processEnclosure( \IPS\core\Rss\Import $rss, \IPS\Http\Response $response, $article )
|
||||
public function processEnclosure( Import $rss, Response $response, array $article ): bool
|
||||
{
|
||||
$settings = $rss->settings;
|
||||
$recordClass = $rss->_class;
|
||||
$fieldsClass = '\IPS\cms\Fields' . $recordClass::database()->id;
|
||||
|
||||
if ( empty( $settings['record_image'] ) )
|
||||
{
|
||||
@@ -241,7 +256,7 @@ class _RssImport
|
||||
|
||||
try
|
||||
{
|
||||
$image = \IPS\Image::create( $response );
|
||||
$image = Image::create( $response );
|
||||
$fixedFieldSettings = $recordClass::database()->fixed_field_settings;
|
||||
|
||||
$dims = NULL;
|
||||
@@ -255,11 +270,11 @@ class _RssImport
|
||||
$image->resizeToMax( $fixedFieldSettings['record_image']['image_dims'][0], $fixedFieldSettings['record_image']['image_dims'][1] );
|
||||
}
|
||||
|
||||
static::$enclosures[ $article['guid'] ] = \IPS\File::create( $this->fileStorage, 'rssImage-' . $article['guid'] . '.' . $image->type, (string)$image );
|
||||
static::$enclosures[ $article['guid'] ] = File::create( $this->fileStorage, 'rssImage-' . $article['guid'] . '.' . $image->type, (string)$image );
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
catch( \Exception $e )
|
||||
catch( Exception $e )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
@@ -268,27 +283,29 @@ class _RssImport
|
||||
/**
|
||||
* Addition Form elements
|
||||
*
|
||||
* @param \IPS\Helpers\Form $form The form
|
||||
* @param \IPS\core\Rss\Import $rss Existing RSS object
|
||||
* @param Form $form The form
|
||||
* @param Import|null $rss Existing RSS object
|
||||
* @return void
|
||||
*/
|
||||
public function form( &$form, \IPS\core\Rss\Import $rss )
|
||||
public function form( Form $form, ?Import $rss=null ) : void
|
||||
{
|
||||
$settings = $rss->settings;
|
||||
$recordClass = $rss->_class;
|
||||
$nodeClass = $recordClass::$containerNodeClass;
|
||||
|
||||
/* @var Fields $fieldsClass */
|
||||
$fieldsClass = '\IPS\cms\Fields' . $recordClass::database()->id;
|
||||
$customFields = $fieldsClass::fields( $settings, 'add', $rss->node_id ? $nodeClass::load( $rss->node_id ) : NULL );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'rss_import_record_open', ( $settings ? $settings['record_open'] : 1 ), FALSE, array( 'options' => array( 1 => 'unlocked', 0 => 'locked' ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'rss_import_record_hide', ( $settings ? $settings['record_hide'] : 0 ), FALSE, array( 'options' => array( 0 => 'unhidden', 1 => 'hidden' ) ) ) );
|
||||
$form->add( new Radio( 'rss_import_record_open', ( $settings ? $settings['record_open'] : 1 ), FALSE, array( 'options' => array( 1 => 'unlocked', 0 => 'locked' ) ) ) );
|
||||
$form->add( new Radio( 'rss_import_record_hide', ( $settings ? $settings['record_hide'] : 0 ), FALSE, array( 'options' => array( 0 => 'unhidden', 1 => 'hidden' ) ) ) );
|
||||
|
||||
if ( $rss->has_enclosures and $fieldsClass::fixedFieldFormShow( 'record_image' ) )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'rss_import_record_image', ( $settings ? $settings['record_image'] : 1 ), FALSE, array( 'options' => array( 1 => 'rss_import_record_image_header', 0 => 'rss_import_record_image_inline' ) ) ) );
|
||||
$form->add( new Radio( 'rss_import_record_image', ( $settings ? $settings['record_image'] : 1 ), FALSE, array( 'options' => array( 1 => 'rss_import_record_image_header', 0 => 'rss_import_record_image_inline' ) ) ) );
|
||||
}
|
||||
|
||||
if ( \count( $customFields ) )
|
||||
if ( count( $customFields ) )
|
||||
{
|
||||
$fields = array();
|
||||
foreach( $customFields as $id => $field )
|
||||
@@ -301,10 +318,10 @@ class _RssImport
|
||||
$fields[] = $field;
|
||||
}
|
||||
|
||||
if ( \count( $fields ) )
|
||||
if ( count( $fields ) )
|
||||
{
|
||||
$form->addHeader('rss_import_cms_defaults');
|
||||
$form->addMessage('rss_import_cms_defaults_desc', 'ipsType_light');
|
||||
$form->addMessage('rss_import_cms_defaults_desc', 'i-color_soft');
|
||||
|
||||
foreach( $fields as $f )
|
||||
{
|
||||
@@ -317,11 +334,11 @@ class _RssImport
|
||||
/**
|
||||
* Process additional fields unique to this extension
|
||||
*
|
||||
* @param array $values Values from form
|
||||
* @param \IPS\core\Rss\Import $rss Existing RSS object
|
||||
* @param array $values Values from form
|
||||
* @param Import $rss Existing RSS object
|
||||
* @return array
|
||||
*/
|
||||
public function saveForm( &$values, $rss )
|
||||
public function saveForm( array &$values, Import $rss ): array
|
||||
{
|
||||
$return = array(
|
||||
'record_open' => $values['rss_import_record_open'],
|
||||
@@ -350,7 +367,8 @@ class _RssImport
|
||||
}
|
||||
}
|
||||
|
||||
$customFields = $fieldsClass::fields( $customValues, 'add', NULL );
|
||||
/* @var Fields $fieldsClass */
|
||||
$customFields = $fieldsClass::fields( $customValues, 'add' );
|
||||
|
||||
foreach( $customFields as $key => $field )
|
||||
{
|
||||
@@ -361,9 +379,9 @@ class _RssImport
|
||||
|
||||
$key = 'field_' . $key;
|
||||
|
||||
if ( isset( $customValues[ $field->name ] ) and \get_class( $field ) == 'IPS\Helpers\Form\Upload' )
|
||||
if ( isset( $customValues[ $field->name ] ) and get_class( $field ) == 'IPS\Helpers\Form\Upload' )
|
||||
{
|
||||
if ( \is_array( $customValues[ $field->name ] ) )
|
||||
if ( is_array( $customValues[ $field->name ] ) )
|
||||
{
|
||||
$items = array();
|
||||
foreach( $customValues[ $field->name ] as $obj )
|
||||
@@ -378,13 +396,13 @@ class _RssImport
|
||||
}
|
||||
}
|
||||
/* If we're using decimals, then the database field is set to DECIMALS, so we cannot using stringValue() */
|
||||
else if ( isset( $customValues[ $field->name ] ) and \get_class( $field ) == 'IPS\Helpers\Form\Number' and ( isset( $field->options['decimals'] ) and $field->options['decimals'] > 0 ) )
|
||||
else if ( isset( $customValues[ $field->name ] ) and get_class( $field ) == 'IPS\Helpers\Form\Number' and ( isset( $field->options['decimals'] ) and $field->options['decimals'] > 0 ) )
|
||||
{
|
||||
$return[ $key ] = $field->value;
|
||||
}
|
||||
else
|
||||
{
|
||||
$return[ $key ] = $field::stringValue( isset( $customValues[ $field->name ] ) ? $customValues[ $field->name ] : NULL );
|
||||
$return[ $key ] = $field::stringValue($customValues[$field->name] ?? NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user