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,78 +11,95 @@
|
||||
namespace IPS\core\widgets;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DateInterval;
|
||||
use IPS\Application;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Checkbox;
|
||||
use IPS\Helpers\Form\Number;
|
||||
use IPS\Helpers\Form\Radio;
|
||||
use IPS\Helpers\Form\Select;
|
||||
use IPS\Helpers\Form\Text;
|
||||
use IPS\Helpers\Form\YesNo;
|
||||
use IPS\Member;
|
||||
use IPS\Member\Group;
|
||||
use IPS\Patterns\ActiveRecordIterator;
|
||||
use IPS\Widget\Customizable;
|
||||
use IPS\Widget\StaticCache;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Members Widget
|
||||
*/
|
||||
class _members extends \IPS\Widget\StaticCache
|
||||
class members extends StaticCache implements Customizable
|
||||
{
|
||||
/**
|
||||
* @brief Widget Key
|
||||
*/
|
||||
public $key = 'members';
|
||||
public string $key = 'members';
|
||||
|
||||
/**
|
||||
* @brief App
|
||||
*/
|
||||
public $app = 'core';
|
||||
public string $app = 'core';
|
||||
|
||||
/**
|
||||
* @brief Plugin
|
||||
*/
|
||||
public $plugin = '';
|
||||
|
||||
|
||||
/**
|
||||
* Specify widget configuration
|
||||
*
|
||||
* @param \IPS\Helpers\Form|NULL $form Form helper
|
||||
* @return null|\IPS\Helpers\Form
|
||||
* @param Form|NULL $form Form helper
|
||||
* @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\Text( 'widget_member_title', isset( $this->configuration['widget_member_title'] ) ? $this->configuration['widget_member_title'] : \IPS\Member::loggedIn()->language()->addToStack( 'widget_member_title_default' ) ) );
|
||||
$form->add( new Text( 'widget_member_title', $this->configuration['widget_member_title'] ?? Member::loggedIn()->language()->addToStack( 'widget_member_title_default' ) ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Select(
|
||||
$form->add( new Select(
|
||||
'widget_member_groups',
|
||||
( isset( $this->configuration['widget_member_groups'] ) ) ? ( $this->configuration['widget_member_groups'] === '*' ? '*' : $this->configuration['widget_member_groups'] ) : '*',
|
||||
FALSE,
|
||||
array( 'options' => \IPS\Member\Group::groups(), 'multiple' => TRUE, 'parse' => 'normal', 'unlimited' => '*', 'unlimitedLang' => 'all' ),
|
||||
array( 'options' => Group::groups(), 'multiple' => TRUE, 'parse' => 'normal', 'unlimited' => '*', 'unlimitedLang' => 'all' ),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
'widget_member_groups'
|
||||
) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Checkbox( 'widget_member_secondary_groups', isset( $this->configuration['widget_member_secondary_groups'] ) ? $this->configuration['widget_member_secondary_groups'] : FALSE, FALSE ) );
|
||||
$form->add( new Checkbox( 'widget_member_secondary_groups', $this->configuration['widget_member_secondary_groups'] ?? FALSE, FALSE ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'widget_member_posts', isset( $this->configuration['widget_member_posts'] ) ? $this->configuration['widget_member_posts'] : 0, FALSE ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'widget_member_rep' , isset( $this->configuration['widget_member_rep'] ) ? $this->configuration['widget_member_rep'] : 0, FALSE ) );
|
||||
$form->add( new Number( 'widget_member_posts', $this->configuration['widget_member_posts'] ?? 0, FALSE ) );
|
||||
$form->add( new Number( 'widget_member_rep' , $this->configuration['widget_member_rep'] ?? 0, FALSE ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'widget_member_online', isset( $this->configuration['widget_member_online'] ) ? $this->configuration['widget_member_online'] : TRUE, FALSE ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'widget_member_born_today', isset( $this->configuration['widget_member_born_today'] ) ? $this->configuration['widget_member_born_today'] : FALSE, FALSE ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'widget_member_born_month', isset( $this->configuration['widget_member_born_month'] ) ? $this->configuration['widget_member_born_month'] : FALSE, FALSE ) );
|
||||
$form->add( new YesNo( 'widget_member_online', $this->configuration['widget_member_online'] ?? TRUE, FALSE ) );
|
||||
$form->add( new YesNo( 'widget_member_born_today', $this->configuration['widget_member_born_today'] ?? FALSE, FALSE ) );
|
||||
$form->add( new YesNo( 'widget_member_born_month', $this->configuration['widget_member_born_month'] ?? FALSE, FALSE ) );
|
||||
|
||||
if ( \IPS\Application::appIsEnabled('blog') )
|
||||
if ( Application::appIsEnabled('blog') )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'widget_member_has_blog', isset( $this->configuration['widget_member_has_blog'] ) ? $this->configuration['widget_member_has_blog'] : FALSE, FALSE ) );
|
||||
$form->add( new YesNo( 'widget_member_has_blog', $this->configuration['widget_member_has_blog'] ?? FALSE, FALSE ) );
|
||||
}
|
||||
|
||||
if ( \IPS\Application::appIsEnabled('gallery') )
|
||||
if ( Application::appIsEnabled('gallery') )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'widget_member_has_album', isset( $this->configuration['widget_member_has_album'] ) ? $this->configuration['widget_member_has_album'] : FALSE, FALSE ) );
|
||||
$form->add( new YesNo( 'widget_member_has_album', $this->configuration['widget_member_has_album'] ?? FALSE, FALSE ) );
|
||||
}
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'widget_member_show', ( isset( $this->configuration['widget_member_show'] ) and $this->configuration['widget_member_show'] != -1 ) ? $this->configuration['widget_member_show'] : 100, FALSE ) );
|
||||
$form->add( new Number( 'widget_member_show', ( isset( $this->configuration['widget_member_show'] ) and $this->configuration['widget_member_show'] != -1 ) ? $this->configuration['widget_member_show'] : 100, FALSE ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'widget_feed_sort_on', isset( $this->configuration['widget_feed_sort_on'] ) ? $this->configuration['widget_feed_sort_on'] : 'last_activity', FALSE, array( 'options' => array(
|
||||
$form->add( new Select( 'widget_feed_sort_on', $this->configuration['widget_feed_sort_on'] ?? 'last_activity', FALSE, array( 'options' => array(
|
||||
'name' => 'widget__sort_name',
|
||||
'member_posts' => 'widget__sort_posts',
|
||||
'joined' => 'widget__sort_joined',
|
||||
@@ -92,16 +109,16 @@ class _members extends \IPS\Widget\StaticCache
|
||||
'_age' => 'widget__sort_age',
|
||||
'pp_reputation_points' => 'widget__sort_points',
|
||||
'_random' => 'widget__sort_random'
|
||||
) ) ), NULL, NULL, NULL, 'widget_feed_sort_on' );
|
||||
) ), NULL, NULL, NULL, 'widget_feed_sort_on' ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'widget_feed_sort_dir', isset( $this->configuration['widget_feed_sort_dir'] ) ? $this->configuration['widget_feed_sort_dir'] : 'desc', FALSE, array(
|
||||
$form->add( new Select( 'widget_feed_sort_dir', $this->configuration['widget_feed_sort_dir'] ?? 'desc', FALSE, array(
|
||||
'options' => array(
|
||||
'desc' => 'descending',
|
||||
'asc' => 'ascending'
|
||||
)
|
||||
) ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'widget_member_display', isset( $this->configuration['widget_member_display'] ) ? $this->configuration['widget_member_display'] : 'csv', FALSE, array(
|
||||
$form->add( new Radio( 'widget_member_display', $this->configuration['widget_member_display'] ?? 'csv', FALSE, array(
|
||||
'options' => array(
|
||||
'csv' => 'widget__display_csv',
|
||||
'list' => 'widget__display_list'
|
||||
@@ -116,18 +133,18 @@ class _members extends \IPS\Widget\StaticCache
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render()
|
||||
public function render(): string
|
||||
{
|
||||
$where = array( array( 'completed=?', true ) );
|
||||
$joins = array();
|
||||
|
||||
if ( ! empty( $this->configuration['widget_member_groups'] ) AND $this->configuration['widget_member_groups'] !== '*' )
|
||||
{
|
||||
$groupWhere = \IPS\Db::i()->in( 'member_group_id', $this->configuration['widget_member_groups'] );
|
||||
$groupWhere = Db::i()->in( 'member_group_id', $this->configuration['widget_member_groups'] );
|
||||
|
||||
if ( ! empty( $this->configuration['widget_member_secondary_groups'] ) )
|
||||
{
|
||||
$groupWhere .= ' OR ' . \IPS\Db::i()->findInSet( 'mgroup_others', $this->configuration['widget_member_groups'] );
|
||||
$groupWhere .= ' OR ' . Db::i()->findInSet( 'mgroup_others', $this->configuration['widget_member_groups'] );
|
||||
}
|
||||
|
||||
$where[] = array( '(' . $groupWhere . ')' );
|
||||
@@ -145,12 +162,12 @@ class _members extends \IPS\Widget\StaticCache
|
||||
|
||||
if ( ! empty( $this->configuration['widget_member_online'] ) OR !isset( $this->configuration['widget_member_online'] ) )
|
||||
{
|
||||
$where[] = array( 'last_activity > ?', \IPS\DateTime::create()->sub( new \DateInterval( 'PT30M' ) )->getTimeStamp() );
|
||||
$where[] = array( 'last_activity > ?', DateTime::create()->sub( new DateInterval( 'PT30M' ) )->getTimeStamp() );
|
||||
}
|
||||
|
||||
if ( ! empty( $this->configuration['widget_member_born_today'] ) )
|
||||
{
|
||||
$time = \IPS\DateTime::ts( time(), TRUE );
|
||||
$time = DateTime::ts( time(), TRUE );
|
||||
$mon = $time->format('n');
|
||||
$mday = $time->format('j');
|
||||
$year = $time->format('Y');
|
||||
@@ -168,13 +185,13 @@ class _members extends \IPS\Widget\StaticCache
|
||||
|
||||
if ( ! empty( $this->configuration['widget_member_born_month'] ) )
|
||||
{
|
||||
$time = \IPS\DateTime::ts( time(), TRUE );
|
||||
$time = DateTime::ts( time(), TRUE );
|
||||
$mon = $time->format('n');
|
||||
|
||||
$where[] = array( 'bday_month=?', $mon );
|
||||
}
|
||||
|
||||
if ( \IPS\Application::appIsEnabled('blog') and ! empty( $this->configuration['widget_member_has_blog'] ) )
|
||||
if ( Application::appIsEnabled('blog') and ! empty( $this->configuration['widget_member_has_blog'] ) )
|
||||
{
|
||||
$joins['blog'] = array(
|
||||
'select' => 'blog.blog_id',
|
||||
@@ -183,7 +200,7 @@ class _members extends \IPS\Widget\StaticCache
|
||||
);
|
||||
}
|
||||
|
||||
if ( \IPS\Application::appIsEnabled('gallery') and ! empty( $this->configuration['widget_member_has_album'] ) )
|
||||
if ( Application::appIsEnabled('gallery') and ! empty( $this->configuration['widget_member_has_album'] ) )
|
||||
{
|
||||
$joins['gallery'] = array(
|
||||
'select' => 'gallery.album_id',
|
||||
@@ -214,10 +231,10 @@ class _members extends \IPS\Widget\StaticCache
|
||||
/* Exclude banned, validating and spammers */
|
||||
$where[] = array( "core_members.temp_ban=0" );
|
||||
$where[] = array( "core_members.email!=''" );
|
||||
$where[] = array( '( ! ' . \IPS\Db::i()->bitwiseWhere( \IPS\Member::$bitOptions['members_bitoptions'], 'bw_is_spammer' ) . ' )' );
|
||||
$where[] = array( '( ! ' . Db::i()->bitwiseWhere( Member::$bitOptions['members_bitoptions'], 'bw_is_spammer' ) . ' )' );
|
||||
$where[] = array( "( core_validating.vid IS NULL ) " );
|
||||
|
||||
$select = \IPS\Db::i()->select(
|
||||
$select = Db::i()->select(
|
||||
'core_members.*',
|
||||
'core_members',
|
||||
$where,
|
||||
@@ -227,20 +244,20 @@ class _members extends \IPS\Widget\StaticCache
|
||||
|
||||
$select->join( 'core_validating', 'core_validating.member_id=core_members.member_id AND core_validating.new_reg = 1' );
|
||||
|
||||
if ( \count( $joins ) )
|
||||
if ( count( $joins ) )
|
||||
{
|
||||
foreach( $joins as $join )
|
||||
{
|
||||
$select->join( $join['from'], ( isset( $join['where'] ) ? $join['where'] : null ), 'STRAIGHT_JOIN' );
|
||||
$select->join( $join['from'], ( $join['where'] ?? null ), 'STRAIGHT_JOIN' );
|
||||
}
|
||||
}
|
||||
|
||||
$members = new \IPS\Patterns\ActiveRecordIterator(
|
||||
$members = new ActiveRecordIterator(
|
||||
$select,
|
||||
'\IPS\Member'
|
||||
);
|
||||
|
||||
/* Display */
|
||||
return $this->output( $members, isset( $this->configuration['widget_member_title'] ) ? $this->configuration['widget_member_title'] : \IPS\Member::loggedIn()->language()->addToStack( 'widget_member_title_default' ), isset( $this->configuration['widget_member_display'] ) ? $this->configuration['widget_member_display'] : 'csv' );
|
||||
return $this->output( $members, $this->configuration['widget_member_title'] ?? Member::loggedIn()->language()->addToStack( 'widget_member_title_default' ), $this->configuration['widget_member_display'] ?? 'csv' );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user