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,65 +11,66 @@
|
||||
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\Db;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Number;
|
||||
use IPS\Helpers\Form\Select;
|
||||
use IPS\Helpers\Form\Translatable;
|
||||
use IPS\Lang;
|
||||
use IPS\Member;
|
||||
use IPS\Patterns\ActiveRecordIterator;
|
||||
use IPS\Widget\Customizable;
|
||||
use IPS\Widget\StaticCache;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function in_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;
|
||||
}
|
||||
|
||||
/**
|
||||
* mostContributions Widget
|
||||
*/
|
||||
class _mostContributions extends \IPS\Widget\StaticCache
|
||||
class mostContributions extends StaticCache implements Customizable
|
||||
{
|
||||
/**
|
||||
* @brief Widget Key
|
||||
*/
|
||||
public $key = 'mostContributions';
|
||||
public string $key = 'mostContributions';
|
||||
|
||||
/**
|
||||
* @brief App
|
||||
*/
|
||||
public $app = 'core';
|
||||
|
||||
/**
|
||||
* @brief Plugin
|
||||
*/
|
||||
public $plugin = '';
|
||||
|
||||
/**
|
||||
* Initialise this widget
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
}
|
||||
public string $app = 'core';
|
||||
|
||||
/**
|
||||
* 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 );
|
||||
|
||||
/* Block title */
|
||||
$form->add( new \IPS\Helpers\Form\Translatable( 'widget_feed_title', isset( $this->configuration['language_key'] ) ? NULL : \IPS\Member::loggedIn()->language()->addToStack( 'block_mostContributions' ), FALSE, array( 'app' => 'core', 'key' => ( isset( $this->configuration['language_key'] ) ? $this->configuration['language_key'] : NULL ) ) ) );
|
||||
$form->add( new Translatable( 'widget_feed_title', isset( $this->configuration['language_key'] ) ? NULL : Member::loggedIn()->language()->addToStack( 'block_mostContributions' ), FALSE, array( 'app' => 'core', 'key' => ( $this->configuration['language_key'] ?? NULL ) ) ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'number_to_show', isset( $this->configuration['number_to_show'] ) ? $this->configuration['number_to_show'] : 5, TRUE, array( 'max' => 25 ) ) );
|
||||
$form->add( new Number( 'number_to_show', $this->configuration['number_to_show'] ?? 5, TRUE, array( 'max' => 25 ) ) );
|
||||
|
||||
/* What are we showing? */
|
||||
$classes = array();
|
||||
foreach ( \IPS\Application::allExtensions( 'core', 'ContentRouter' ) as $contentRouter )
|
||||
foreach ( Application::allExtensions( 'core', 'ContentRouter' ) as $contentRouter )
|
||||
{
|
||||
foreach ( $contentRouter->classes as $class )
|
||||
{
|
||||
$exploded = explode( '\\', $class );
|
||||
if ( \in_array( 'IPS\Content\Item', class_parents( $class ) ) )
|
||||
if ( in_array( 'IPS\Content\Item', class_parents( $class ) ) )
|
||||
{
|
||||
if ( $class::incrementPostCount() )
|
||||
{
|
||||
@@ -92,7 +93,7 @@ class _mostContributions extends \IPS\Widget\StaticCache
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif ( \in_array( 'IPS\Content\Comment', class_parents( $class ) ) )
|
||||
elseif ( in_array( 'IPS\Content\Comment', class_parents( $class ) ) )
|
||||
{
|
||||
if ( $class::incrementPostCount() )
|
||||
{
|
||||
@@ -120,7 +121,7 @@ class _mostContributions extends \IPS\Widget\StaticCache
|
||||
}
|
||||
}
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'most_contributions_area', isset( $this->configuration['most_contributions_area'] ) ? $this->configuration['most_contributions_area'] : "0", FALSE, array( 'options' => $options, 'multiple' => FALSE, 'unlimited' => '0', 'unlimitedLang' => "everything" ), NULL, NULL, NULL, 'most_contributions_area' ) );
|
||||
$form->add( new Select( 'most_contributions_area', $this->configuration['most_contributions_area'] ?? "0", FALSE, array( 'options' => $options, 'multiple' => FALSE, 'unlimited' => '0', 'unlimitedLang' => "everything" ), NULL, NULL, NULL, 'most_contributions_area' ) );
|
||||
return $form;
|
||||
}
|
||||
|
||||
@@ -130,7 +131,7 @@ class _mostContributions extends \IPS\Widget\StaticCache
|
||||
* @param array $values Values from form
|
||||
* @return array
|
||||
*/
|
||||
public function preConfig( $values )
|
||||
public function preConfig( array $values ): array
|
||||
{
|
||||
if ( !isset( $this->configuration['language_key'] ) )
|
||||
{
|
||||
@@ -138,7 +139,7 @@ class _mostContributions extends \IPS\Widget\StaticCache
|
||||
}
|
||||
$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;
|
||||
@@ -149,15 +150,15 @@ class _mostContributions extends \IPS\Widget\StaticCache
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render()
|
||||
public function render(): string
|
||||
{
|
||||
$members = array();
|
||||
$area = isset( $this->configuration['most_contributions_area'] ) ? $this->configuration['most_contributions_area'] : NULL;
|
||||
$area = $this->configuration['most_contributions_area'] ?? NULL;
|
||||
|
||||
/* If we're showing everything that's easy just show the content count */
|
||||
if( !$area )
|
||||
{
|
||||
$contributions = array( 'members' => new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_members', array( "member_posts > ?", 0 ), "member_posts DESC", array( 0,5 ) ), 'IPS\Member' ) );
|
||||
$contributions = array( 'members' => new ActiveRecordIterator( Db::i()->select( '*', 'core_members', array( "member_posts > ?", 0 ), "member_posts DESC", array( 0,5 ) ), 'IPS\Member' ) );
|
||||
}
|
||||
/* A specific content type? That's more work */
|
||||
else
|
||||
@@ -165,14 +166,14 @@ class _mostContributions extends \IPS\Widget\StaticCache
|
||||
$contributions = $area::mostContributions( $this->configuration['number_to_show'] );
|
||||
}
|
||||
|
||||
if( !\count( $contributions['members'] ) )
|
||||
if( !count( $contributions['members'] ) )
|
||||
{
|
||||
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 ) );
|
||||
}
|
||||
elseif ( isset( $this->configuration['widget_feed_title'] ) )
|
||||
{
|
||||
@@ -180,7 +181,7 @@ class _mostContributions extends \IPS\Widget\StaticCache
|
||||
}
|
||||
else
|
||||
{
|
||||
$title = \IPS\Member::loggedIn()->language()->addToStack( 'block_mostContributions' );
|
||||
$title = Member::loggedIn()->language()->addToStack( 'block_mostContributions' );
|
||||
}
|
||||
|
||||
return $this->output( $contributions, $area, $title );
|
||||
@@ -191,8 +192,8 @@ class _mostContributions extends \IPS\Widget\StaticCache
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
public function delete() : void
|
||||
{
|
||||
\IPS\Lang::deleteCustom( 'core', $this->configuration['language_key'] );
|
||||
Lang::deleteCustom( 'core', $this->configuration['language_key'] );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user