Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

+47 -34
View File
@@ -12,58 +12,71 @@
namespace IPS\core\widgets;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Content\Controller;
use IPS\Dispatcher;
use IPS\Helpers\Form;
use IPS\Helpers\Form\Number;
use IPS\Helpers\Form\Translatable;
use IPS\Lang;
use IPS\Member;
use IPS\Request;
use IPS\Settings;
use IPS\Widget\Customizable;
use IPS\Widget\PermissionCache;
use function count;
use function defined;
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;
}
/**
* Related Content Widget
*/
class _relatedContent extends \IPS\Widget\PermissionCache
class relatedContent extends PermissionCache implements Customizable
{
/**
* @brief Widget Key
*/
public $key = 'relatedContent';
public string $key = 'relatedContent';
/**
* @brief App
*/
public $app = 'core';
/**
* @brief Plugin
*/
public $plugin = '';
public string $app = 'core';
/**
* Constructor
*
* @param String $uniqueKey Unique key for this specific instance
* @param String $uniqueKey Unique key for this specific instance
* @param array $configuration Widget custom configuration
* @param null|string|array $access Array/JSON string of executable apps (core=sidebar only, content=IP.Content only, etc)
* @param null|string $orientation Orientation (top, bottom, right, left)
* @param array|string|null $access Array/JSON string of executable apps (core=sidebar only, content=IP.Content only, etc)
* @param string|null $orientation Orientation (top, bottom, right, left)
* @param string $layout
* @return void
*/
public function __construct( $uniqueKey, array $configuration, $access=null, $orientation=null )
public function __construct(string $uniqueKey, array $configuration, array|string $access=null, string $orientation=null, string $layout='table' )
{
parent::__construct( $uniqueKey, $configuration, $access, $orientation );
parent::__construct( $uniqueKey, $configuration, $access, $orientation, $layout );
/* We can't run the URL related logic if we have no dispatcher because this class could also be initialized by the CLI cron job */
if( \IPS\Dispatcher::hasInstance() )
if( Dispatcher::hasInstance() )
{
/* Cache per item, not per block */
$parts = parse_url( (string) \IPS\Request::i()->url()->setPage() );
$parts = parse_url( (string) Request::i()->url()->setPage() );
if ( \IPS\Settings::i()->htaccess_mod_rewrite )
if ( Settings::i()->htaccess_mod_rewrite )
{
$url = $parts['scheme'] . "://" . $parts['host'] . ( isset( $parts['port'] ) ? ':' . $parts['port'] : '' ) . $parts['path'];
$url = $parts['scheme'] . "://" . $parts['host'] . ( isset( $parts['port'] ) ? ':' . $parts['port'] : '' ) . ( $parts['path'] ?? '' );
}
else
{
$url = $parts['scheme'] . "://" . $parts['host'] . ( isset( $parts['port'] ) ? ':' . $parts['port'] : '' ) . $parts['path'] . ( isset( $parts['query'] ) ? '?' . $parts['query'] : '' );
$url = $parts['scheme'] . "://" . $parts['host'] . ( isset( $parts['port'] ) ? ':' . $parts['port'] : '' ) . ( $parts['path'] ?? '' ) . ( isset( $parts['query'] ) ? '?' . $parts['query'] : '' );
}
$this->cacheKey .= '_' . md5( $url );
@@ -76,7 +89,7 @@ class _relatedContent extends \IPS\Widget\PermissionCache
* @param array $values Values from form
* @return array
*/
public function preConfig( $values )
public function preConfig( array $values ): array
{
if ( !isset( $this->configuration['language_key'] ) )
{
@@ -84,7 +97,7 @@ class _relatedContent extends \IPS\Widget\PermissionCache
}
$values['language_key'] = $this->configuration['language_key'];
\IPS\Lang::saveCustom( 'core', $this->configuration['language_key'], $values['widget_feed_title'] );
Lang::saveCustom( 'core', $this->configuration['language_key'], $values['widget_feed_title'] );
unset( $values['widget_feed_title'] );
return $values;
@@ -93,16 +106,16 @@ class _relatedContent extends \IPS\Widget\PermissionCache
/**
* Specify widget configuration
*
* @param null|\IPS\Helpers\Form $form Form object
* @return \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 );
/* Block title */
$form->add( new \IPS\Helpers\Form\Translatable( 'widget_feed_title', isset( $this->configuration['language_key'] ) ? NULL : \IPS\Member::loggedIn()->language()->addToStack( 'block_relatedContent' ), FALSE, array( 'app' => 'core', 'key' => ( isset( $this->configuration['language_key'] ) ? $this->configuration['language_key'] : NULL ) ) ) );
$form->add( new \IPS\Helpers\Form\Number( 'toshow', isset( $this->configuration['toshow'] ) ? $this->configuration['toshow'] : 5, TRUE ) );
$form->add( new Translatable( 'widget_feed_title', isset( $this->configuration['language_key'] ) ? NULL : Member::loggedIn()->language()->addToStack( 'block_relatedContent' ), FALSE, array( 'app' => 'core', 'key' => ( $this->configuration['language_key'] ?? NULL ) ) ) );
$form->add( new Number( 'toshow', $this->configuration['toshow'] ?? 5, TRUE ) );
return $form;
}
@@ -112,29 +125,29 @@ class _relatedContent extends \IPS\Widget\PermissionCache
*
* @return string
*/
public function render()
public function render(): string
{
if( !( \IPS\Dispatcher::i()->dispatcherController instanceof \IPS\Content\Controller ) )
if( !( Dispatcher::i()->dispatcherController instanceof Controller ) )
{
return '';
}
$limit = isset ( $this->configuration['toshow'] ) ? $this->configuration['toshow'] : 5;
$limit = $this->configuration['toshow'] ?? 5;
$related = \IPS\Dispatcher::i()->dispatcherController->getSimilarContent( $limit );
$related = Dispatcher::i()->dispatcherController->getSimilarContent( $limit );
if( $related === NULL or !\count( $related ) )
if( $related === NULL or !count( $related ) )
{
return '';
}
if ( isset( $this->configuration['language_key'] ) )
{
$title = \IPS\Member::loggedIn()->language()->addToStack( $this->configuration['language_key'], FALSE, array( 'escape' => TRUE ) );
$title = Member::loggedIn()->language()->addToStack( $this->configuration['language_key'], FALSE, array( 'escape' => TRUE ) );
}
else
{
$title = \IPS\Member::loggedIn()->language()->addToStack( 'block_relatedContent' );
$title = Member::loggedIn()->language()->addToStack( 'block_relatedContent' );
}
return $this->output( $related, $title );