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,53 +11,63 @@
|
||||
namespace IPS\core\widgets;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Application;
|
||||
use IPS\Content;
|
||||
use IPS\core\Stream as StreamClass;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Number;
|
||||
use IPS\Helpers\Form\Select;
|
||||
use IPS\Helpers\Form\Text;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\Output;
|
||||
use IPS\Theme;
|
||||
use IPS\Widget\PermissionCache;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
use function strstr;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* stream Widget
|
||||
*/
|
||||
class _stream extends \IPS\Widget\PermissionCache
|
||||
class stream extends PermissionCache
|
||||
{
|
||||
/**
|
||||
* @brief Widget Key
|
||||
*/
|
||||
public $key = 'stream';
|
||||
public string $key = 'stream';
|
||||
|
||||
/**
|
||||
* @brief App
|
||||
*/
|
||||
public $app = 'core';
|
||||
public string $app = 'core';
|
||||
|
||||
/**
|
||||
* @brief Plugin
|
||||
*/
|
||||
public $plugin = '';
|
||||
|
||||
|
||||
/**
|
||||
* Initialise this widget
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init()
|
||||
public function init(): void
|
||||
{
|
||||
parent::init(); //outputCss
|
||||
|
||||
/* Necessary CSS/JS */
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js('front_streams.js', 'core' ) );
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'front_statuses.js', 'core' ) );
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'styles/streams.css' ) );
|
||||
|
||||
if ( \IPS\Theme::i()->settings['responsive'] )
|
||||
{
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'styles/streams_responsive.css', 'core', 'front' ) );
|
||||
}
|
||||
Output::i()->jsFiles = array_merge( Output::i()->jsFiles, Output::i()->js('front_streams.js', 'core' ) );
|
||||
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'styles/streams.css' ) );
|
||||
|
||||
$apps = array();
|
||||
if( isset( $this->configuration['content'] ) and \strstr( $this->configuration['content'], ',' ) )
|
||||
if( isset( $this->configuration['content'] ) and strstr( $this->configuration['content'], ',' ) )
|
||||
{
|
||||
foreach( explode( ',', $this->configuration['content'] ) as $content )
|
||||
{
|
||||
@@ -67,9 +77,9 @@ class _stream extends \IPS\Widget\PermissionCache
|
||||
}
|
||||
|
||||
/* We will need specific CSS */
|
||||
foreach( \IPS\Application::enabledApplications() as $appDir => $app )
|
||||
foreach( Application::enabledApplications() as $appDir => $app )
|
||||
{
|
||||
if ( isset( $this->configuration['content'] ) and $this->configuration['content'] === 0 or \in_array( $appDir, $apps ) )
|
||||
if ( isset( $this->configuration['content'] ) and $this->configuration['content'] === 0 or in_array( $appDir, $apps ) )
|
||||
{
|
||||
if ( method_exists( $app, 'outputCss' ) )
|
||||
{
|
||||
@@ -82,28 +92,25 @@ class _stream extends \IPS\Widget\PermissionCache
|
||||
/**
|
||||
* Specify widget configuration
|
||||
*
|
||||
* @param null|\IPS\Helpers\Form $form Form object
|
||||
* @return null|\IPS\Helpers\Form
|
||||
* @param null|Form $form Form object
|
||||
* @return Form
|
||||
*/
|
||||
public function configuration( &$form=null )
|
||||
public function configuration( Form &$form=null ): Form
|
||||
{
|
||||
$form = parent::configuration( $form );
|
||||
$options = array();
|
||||
foreach( \IPS\Content::routedClasses( FALSE, FALSE, TRUE ) AS $class )
|
||||
foreach( Content\Search\SearchContent::searchableClasses() as $class )
|
||||
{
|
||||
if ( \in_array( 'IPS\Content\Searchable', \class_implements( $class ) ) )
|
||||
{
|
||||
$options[ $class ] = \IPS\Member::loggedIn()->language()->addToStack( $class::$title . '_pl' );
|
||||
}
|
||||
$options[ $class ] = Member::loggedIn()->language()->addToStack( $class::$title . '_pl' );
|
||||
}
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'title', $this->configuration['title'] ?? NULL, TRUE ) );
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'content', ( isset( $this->configuration['content'] ) AND $this->configuration['content'] !== 0 ) ? explode( ',', $this->configuration['content'] ) : 0, FALSE, array(
|
||||
$form->add( new Text( 'title', $this->configuration['title'] ?? NULL, TRUE ) );
|
||||
$form->add( new Select( 'content', ( isset( $this->configuration['content'] ) AND $this->configuration['content'] !== 0 ) ? explode( ',', $this->configuration['content'] ) : 0, FALSE, array(
|
||||
'options' => $options,
|
||||
'multiple' => TRUE,
|
||||
'unlimited' => 0,
|
||||
) ) );
|
||||
|
||||
$dateField = new \IPS\Helpers\Form\Select( 'date', ( isset( $this->configuration['date'] ) ) ? $this->configuration['date'] : 'year', FALSE, array(
|
||||
$dateField = new Select( 'date', ( isset( $this->configuration['date'] ) ) ? $this->configuration['date'] : 'year', FALSE, array(
|
||||
'options' => array(
|
||||
'today' => 'search_day',
|
||||
'week' => 'search_week',
|
||||
@@ -111,10 +118,10 @@ class _stream extends \IPS\Widget\PermissionCache
|
||||
'year' => 'search_year'
|
||||
)
|
||||
) );
|
||||
$dateField->label = \IPS\Member::loggedIn()->language()->addToStack( 'stream_date_relative_days' );
|
||||
$dateField->label = Member::loggedIn()->language()->addToStack( 'stream_date_relative_days' );
|
||||
$form->add( $dateField );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'max_results', $this->configuration['max_results'] ?? 5, TRUE, array( 'max' => 20 ) ) );
|
||||
$form->add( new Number( 'max_results', $this->configuration['max_results'] ?? 5, TRUE, array( 'max' => 20 ) ) );
|
||||
return $form;
|
||||
}
|
||||
|
||||
@@ -124,9 +131,9 @@ class _stream extends \IPS\Widget\PermissionCache
|
||||
* @param array $values Values from form
|
||||
* @return array
|
||||
*/
|
||||
public function preConfig( $values )
|
||||
public function preConfig( array $values ): array
|
||||
{
|
||||
if ( \is_array( $values['content'] ) )
|
||||
if ( is_array( $values['content'] ) )
|
||||
{
|
||||
$save = [];
|
||||
foreach( $values['content'] AS $class )
|
||||
@@ -144,7 +151,7 @@ class _stream extends \IPS\Widget\PermissionCache
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render()
|
||||
public function render(): string
|
||||
{
|
||||
if ( !isset( $this->configuration['content'] ) )
|
||||
{
|
||||
@@ -154,11 +161,11 @@ class _stream extends \IPS\Widget\PermissionCache
|
||||
/* Set our content */
|
||||
if ( $this->configuration['content'] === 0 )
|
||||
{
|
||||
$stream = \IPS\core\Stream::allActivityStream();
|
||||
$stream = StreamClass::allActivityStream();
|
||||
}
|
||||
else
|
||||
{
|
||||
$stream = new \IPS\core\Stream;
|
||||
$stream = new StreamClass;
|
||||
$stream->classes = $this->configuration['content'];
|
||||
}
|
||||
|
||||
@@ -191,17 +198,17 @@ class _stream extends \IPS\Widget\PermissionCache
|
||||
/* Set some defaults */
|
||||
$stream->id = 0;
|
||||
$stream->include_comments = TRUE;
|
||||
$stream->baseUrl = \IPS\Http\Url::internal( "app=core&module=discover&controller=streams", 'front', 'discover_all' );
|
||||
$stream->baseUrl = Url::internal( "app=core&module=discover&controller=streams", 'front', 'discover_all' );
|
||||
|
||||
/* Query */
|
||||
$query = $stream->query()->setLimit( $this->configuration['max_results'] ?? 5 );
|
||||
$results = $query->search();
|
||||
|
||||
if ( !\count( $results ) )
|
||||
if ( !count( $results ) )
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->output( $stream, $results, $this->configuration['title'] ?? \IPS\Member::loggedIn()->language()->addToStack( 'block_stream' ), $this->orientation );
|
||||
return $this->output( $stream, $results, $this->configuration['title'] ?? Member::loggedIn()->language()->addToStack( 'block_stream' ), $this->orientation );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user