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
@@ -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