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,59 +11,77 @@
|
||||
namespace IPS\core\widgets;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Application\Module;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Member;
|
||||
use IPS\Member\Group;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
use IPS\Session\Store;
|
||||
use IPS\Settings;
|
||||
use IPS\Theme;
|
||||
use IPS\Widget\StaticCache;
|
||||
use function array_slice;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* activeUsers Widget
|
||||
*/
|
||||
class _activeUsers extends \IPS\Widget\PermissionCache
|
||||
class activeUsers extends StaticCache
|
||||
{
|
||||
/**
|
||||
* @brief Widget Key
|
||||
*/
|
||||
public $key = 'activeUsers';
|
||||
public string $key = 'activeUsers';
|
||||
|
||||
/**
|
||||
* @brief App
|
||||
*/
|
||||
public $app = 'core';
|
||||
public string $app = 'core';
|
||||
|
||||
/**
|
||||
* @brief Plugin
|
||||
*/
|
||||
public $plugin = '';
|
||||
|
||||
|
||||
/**
|
||||
* @brief Cache Expiration
|
||||
* @note We only let this cache be valid for up to 60 seconds
|
||||
*/
|
||||
public $cacheExpiration = 60;
|
||||
public int $cacheExpiration = 60;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected string $url = '';
|
||||
|
||||
/**
|
||||
* 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 );
|
||||
|
||||
$member = \IPS\Member::loggedIn() ?: new \IPS\Member;
|
||||
$member = Member::loggedIn() ?: new Member;
|
||||
|
||||
/* 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() )
|
||||
{
|
||||
$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 )
|
||||
{
|
||||
$this->url = $parts['scheme'] . "://" . $parts['host'] . ( isset( $parts['port'] ) ? ':' . $parts['port'] : '' ) . $parts['path'];
|
||||
}
|
||||
@@ -74,30 +92,14 @@ class _activeUsers extends \IPS\Widget\PermissionCache
|
||||
|
||||
if( $member->member_id AND !$member->isOnlineAnonymously() )
|
||||
{
|
||||
\IPS\Output::i()->jsVars['member_id'] = $member->member_id;
|
||||
\IPS\Output::i()->jsVars['member_url'] = (string) $member->url();
|
||||
\IPS\Output::i()->jsVars['member_hovercardUrl'] = (string) $member->url()->setQueryString( 'do', 'hovercard' );
|
||||
\IPS\Output::i()->jsVars['member_formattedName'] = str_replace( '"', '\\"', \IPS\Member\Group::load( $member->member_group_id )->formatName( $member->name ) );
|
||||
Output::i()->jsVars['member_id'] = $member->member_id;
|
||||
Output::i()->jsVars['member_url'] = (string) $member->url();
|
||||
Output::i()->jsVars['member_hovercardUrl'] = (string) $member->url()->setQueryString( 'do', 'hovercard' );
|
||||
Output::i()->jsVars['member_formattedName'] = str_replace( '"', '\\"', Group::load( $member->member_group_id )->formatName( $member->name ) );
|
||||
}
|
||||
|
||||
/* We want to use the user's permissions array which will validate social groups, clubs and groups. But, we need to remove the individual member entry */
|
||||
$member = \IPS\Member::loggedIn() ?: new \IPS\Member;
|
||||
$permissions = $member->permissionArray();
|
||||
|
||||
foreach( $permissions as $key => $entry )
|
||||
{
|
||||
if( mb_substr( $entry, 0, 1 ) === 'm' )
|
||||
{
|
||||
unset( $permissions[ $key ] );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* We sort to ensure the array is always in the same order */
|
||||
sort( $permissions );
|
||||
|
||||
$theme = $member->skin ?: \IPS\Theme::defaultTheme();
|
||||
$this->cacheKey = "widget_{$this->key}_" . $this->uniqueKey . '_' . md5( $this->url . '_' . json_encode( $configuration ) . "_" . $member->language()->id . "_" . $theme . "_" . json_encode( $permissions ) . $orientation . '-' . (int) \IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'core', 'members', 'front' ) ) );
|
||||
$theme = $member->skin ?: Theme::defaultTheme();
|
||||
$this->cacheKey = "widget_{$this->key}_" . $this->uniqueKey . '_' . md5( $this->url . '_' . json_encode( $configuration ) . "_" . $member->language()->id . "_" . $theme . "_" . $orientation . '-' . (int) Member::loggedIn()->canAccessModule( Module::get( 'core', 'members', 'front' ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,22 +108,22 @@ class _activeUsers extends \IPS\Widget\PermissionCache
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render()
|
||||
public function render(): string
|
||||
{
|
||||
/* Do we have permission? */
|
||||
if ( !\IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'core', 'online', 'front' ) ) )
|
||||
if ( !Member::loggedIn()->canAccessModule( Module::get( 'core', 'online', 'front' ) ) )
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
$members = \IPS\Session\Store::i()->getOnlineMembersByLocation( \IPS\Dispatcher::i()->application->directory, \IPS\Dispatcher::i()->module->key, \IPS\Dispatcher::i()->controller, \IPS\Request::i()->id, $this->url );
|
||||
$members = Store::i()->getOnlineMembersByLocation( Dispatcher::i()->application->directory, Dispatcher::i()->module->key, Dispatcher::i()->controller, Request::i()->id, $this->url );
|
||||
|
||||
$memberCount = \count( $members );
|
||||
$memberCount = count( $members );
|
||||
|
||||
/* If it's on the sidebar (rather than at the bottom), we want to limit it to 60 so we don't take too much space */
|
||||
if ( $this->orientation === 'vertical' and \count( $members ) >= 60 )
|
||||
if ( $this->orientation === 'vertical' and count( $members ) >= 60 )
|
||||
{
|
||||
$members = \array_slice( $members, 0, 60 );
|
||||
$members = array_slice( $members, 0, 60 );
|
||||
}
|
||||
|
||||
/* Display */
|
||||
|
||||
Reference in new issue
Block a user