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

@@ -11,16 +11,24 @@
namespace IPS\core\Achievements\Actions;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Application;
use IPS\core\Achievements\Rule;
use IPS\Http\Url;
use IPS\Member;
use function defined;
use function get_called_class;
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;
}
/**
* Base class for AchievementAction extensions
*/
abstract class _AbstractAchievementAction
abstract class AchievementActionAbstract
{
/**
* Can use this rule?
@@ -29,19 +37,19 @@ abstract class _AbstractAchievementAction
*/
public function canUse(): bool
{
$exploded = explode( '\\', \get_called_class() );
$exploded = explode( '\\', get_called_class() );
return \IPS\Application::appIsEnabled( $exploded[1] );
return Application::appIsEnabled( $exploded[1] );
}
/**
* Get filter form elements
*
* @param array|NULL $filters Current filter values (if editing)
* @param \IPS\Http\Url $url The URL the form is being shown on
* @param Url $url The URL the form is being shown on
* @return array
*/
public function filters( ?array $filters, \IPS\Http\Url $url ): array
public function filters( ?array $filters, Url $url ): array
{
return [];
}
@@ -64,12 +72,12 @@ abstract class _AbstractAchievementAction
* calls that BEFORE making its change in the database (or there is read/write separation), you will need to add
* 1 to the value being considered for milestones
*
* @param \IPS\Member $subject The subject member
* @param Member $subject The subject member
* @param array $filters The value returned by formatFilterValues()
* @param mixed $extra Any additional information about what is happening (e.g. if a post is being made: the post object)
* @return bool
*/
public function filtersMatch( \IPS\Member $subject, array $filters, $extra = NULL ): bool
public function filtersMatch( Member $subject, array $filters, mixed $extra = NULL ): bool
{
return TRUE;
}
@@ -95,7 +103,7 @@ abstract class _AbstractAchievementAction
* @param array|NULL $filters Current filter values
* @return array
*/
public function awardOther( $extra = NULL, ?array $filters = NULL ): array
public function awardOther( mixed $extra = NULL, ?array $filters = NULL ): array
{
return [];
}
@@ -104,11 +112,11 @@ abstract class _AbstractAchievementAction
* Get identifier to prevent the member being awarded points for the same action twice
* Must be unique within within of this domain, must not exceed 32 chars.
*
* @param \IPS\Member $subject The subject member
* @param Member $subject The subject member
* @param mixed $extra Any additional information about what is happening (e.g. if a post is being made: the post object)
* @return string
*/
abstract public function identifier( \IPS\Member $subject, $extra = NULL ): string;
abstract public function identifier( Member $subject, mixed $extra = NULL ): string;
/**
* Return a description for this action to show in the log
@@ -122,8 +130,24 @@ abstract class _AbstractAchievementAction
/**
* Get "description" for rule
*
* @param \IPS\core\Achievements\Rule $rule The rule
* @param Rule $rule The rule
* @return string|null
*/
abstract public function ruleDescription( \IPS\core\Achievements\Rule $rule ): ?string;
abstract public function ruleDescription( Rule $rule ): ?string;
/**
* Process the rebuild row
*
* @param array $row Row from database
* @param array $data Data collected when starting rebuild [table, pkey...]
* @return void
*/
abstract public static function rebuildRow( array $row, array $data ) : void;
/**
* Get rebuild data
*
* @return array
*/
abstract public static function rebuildData(): array;
}
@@ -10,43 +10,63 @@
namespace IPS\core\Achievements\Actions;
/* 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\Achievements\Rule;
use IPS\DateTime;
use IPS\Db;
use IPS\Helpers\Form\Node;
use IPS\Helpers\Form\Number;
use IPS\Helpers\Form\Select;
use IPS\Http\Url;
use IPS\Member;
use IPS\Theme;
use OutOfRangeException;
use UnderflowException;
use function count;
use function defined;
use function get_called_class;
use function get_class;
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;
}
/**
* Abstract Achievement Action Extension for content-related things
*/
abstract class _AbstractContentAchievementAction extends AbstractAchievementAction
abstract class ContentAchievementActionAbstract extends AchievementActionAbstract
{
protected static $includeItems = TRUE;
protected static $includeComments = TRUE;
protected static $includeReviews = TRUE;
protected static bool $includeItems = TRUE;
protected static bool $includeComments = TRUE;
protected static bool $includeReviews = TRUE;
/**
* @var bool Exclude content items that require a first comment
*/
protected static $excludeItemsWithRequiredComment = FALSE;
protected static bool $excludeItemsWithRequiredComment = false;
/**
* Get filter form elements
*
* @param array|NULL $filters Current filter values (if editing)
* @param \IPS\Http\Url $url The URL the form is being shown on
* @param Url $url The URL the form is being shown on
* @return array
*/
public function filters( ?array $filters, \IPS\Http\Url $url ): array
public function filters( ?array $filters, Url $url ): array
{
$classKey = explode( '\\', \get_called_class() )[5];
$classKey = explode( '\\', get_called_class() )[5];
$contentTypeOptions = [];
$contentTypeToggles = [];
$_return = [];
$defaultApp = NULL;
foreach( \IPS\Application::applications() as $directory => $application )
foreach( Application::applications() as $directory => $application )
{
if( $application->default )
{
@@ -54,7 +74,7 @@ abstract class _AbstractContentAchievementAction extends AbstractAchievementActi
break;
}
}
foreach ( \IPS\Application::allExtensions( 'core', 'ContentRouter', FALSE, $defaultApp ) as $extension )
foreach ( Application::allExtensions( 'core', 'ContentRouter', FALSE, $defaultApp ) as $extension )
{
foreach ( $extension->classes as $class )
{
@@ -92,34 +112,34 @@ abstract class _AbstractContentAchievementAction extends AbstractAchievementActi
{
try
{
$nodeTitle = \IPS\Member::loggedIn()->language()->get( ($class::$containerNodeClass)::$nodeTitle . '_sg_lc' );
$nodeTitle = Member::loggedIn()->language()->get( ($class::$containerNodeClass)::$nodeTitle . '_sg_lc' );
}
catch( \UnderflowException $e )
catch( UnderflowException $e )
{
$nodeTitle = ($class::$containerNodeClass)::$nodeTitle . '_sg';
}
$nodeFilter = new \IPS\Helpers\Form\Node( $nodeFilterKey, ( $filters and isset( $filters[ 'nodes_' . str_replace( '\\', '-', $class ) ] ) and $filters[ 'nodes_' . str_replace( '\\', '-', $class ) ] ) ? $filters[ 'nodes_' . str_replace( '\\', '-', $class ) ] : 0, FALSE, [
$nodeFilter = new Node( $nodeFilterKey, ( $filters and isset( $filters[ 'nodes_' . str_replace( '\\', '-', $class ) ] ) and $filters[ 'nodes_' . str_replace( '\\', '-', $class ) ] ) ? $filters[ 'nodes_' . str_replace( '\\', '-', $class ) ] : 0, FALSE, [
'url' => $url,
'class' => $class::$containerNodeClass,
'showAllNodes' => TRUE,
'multiple' => TRUE,
], NULL, \IPS\Member::loggedIn()->language()->addToStack( 'achievement_filter_NewContentItem_node_prefix', FALSE, [ 'sprintf' => [
\IPS\Member::loggedIn()->language()->addToStack( $class::_definiteArticle(), FALSE ),
\IPS\Member::loggedIn()->language()->addToStack( $nodeTitle, FALSE )
], NULL, Member::loggedIn()->language()->addToStack( 'achievement_filter_NewContentItem_node_prefix', FALSE, [ 'sprintf' => [
Member::loggedIn()->language()->addToStack( $class::_definiteArticle(), FALSE ),
Member::loggedIn()->language()->addToStack( $nodeTitle, FALSE )
] ] ) );
$nodeFilter->label = \IPS\Member::loggedIn()->language()->addToStack( 'achievement_filter_NewContentItem_node', FALSE, [ 'sprintf' => [ \IPS\Member::loggedIn()->language()->addToStack( $nodeTitle, FALSE ) ] ] );
$nodeFilter->label = Member::loggedIn()->language()->addToStack( 'achievement_filter_NewContentItem_node', FALSE, [ 'sprintf' => [ Member::loggedIn()->language()->addToStack( $nodeTitle, FALSE ) ] ] );
$_return[ "nodes_" . str_replace( '\\', '-', $class ) ] = $nodeFilter;
}
}
}
}
$typeFilter = new \IPS\Helpers\Form\Select( 'achievement_filter_' . $classKey . '_type', ( $filters and isset( $filters['type'] ) and $filters['type'] ) ? $filters['type'] : NULL, FALSE, [ 'options' => $contentTypeOptions, 'toggles' => $contentTypeToggles ], NULL, \IPS\Member::loggedIn()->language()->addToStack('achievement_filter_NewContentItem_type_prefix') );
$typeFilter->label = \IPS\Member::loggedIn()->language()->addToStack('achievement_filter_NewContentItem_type');
$typeFilter = new Select( 'achievement_filter_' . $classKey . '_type', ( $filters and isset( $filters['type'] ) and $filters['type'] ) ? $filters['type'] : NULL, FALSE, [ 'options' => $contentTypeOptions, 'toggles' => $contentTypeToggles ], NULL, Member::loggedIn()->language()->addToStack('achievement_filter_NewContentItem_type_prefix') );
$typeFilter->label = Member::loggedIn()->language()->addToStack('achievement_filter_NewContentItem_type');
$nthFilter = new \IPS\Helpers\Form\Number( 'achievement_filter_' . $classKey . '_nth', ( $filters and isset( $filters['milestone'] ) and $filters['milestone'] ) ? $filters['milestone'] : 0, FALSE, [], NULL, \IPS\Member::loggedIn()->language()->addToStack('achievement_filter_nth_their'), \IPS\Member::loggedIn()->language()->addToStack('achievement_filter_' . $classKey . '_nth_suffix') );
$nthFilter->label = \IPS\Member::loggedIn()->language()->addToStack('achievement_filter_NewContentItem_nth');
$nthFilter = new Number( 'achievement_filter_' . $classKey . '_nth', ( $filters and isset( $filters['milestone'] ) and $filters['milestone'] ) ? $filters['milestone'] : 0, FALSE, [], NULL, Member::loggedIn()->language()->addToStack('achievement_filter_nth_their'), Member::loggedIn()->language()->addToStack('achievement_filter_' . $classKey . '_nth_suffix') );
$nthFilter->label = Member::loggedIn()->language()->addToStack('achievement_filter_NewContentItem_nth');
$return = [ 'type' => $typeFilter ];
foreach ( $_return as $k => $v )
@@ -139,7 +159,7 @@ abstract class _AbstractContentAchievementAction extends AbstractAchievementActi
*/
public function formatFilterValues( array $values ): array
{
$classKey = explode( '\\', \get_called_class() )[5];
$classKey = explode( '\\', get_called_class() )[5];
$return = [];
if ( isset( $values['achievement_filter_' . $classKey . '_type'] ) )
@@ -147,7 +167,7 @@ abstract class _AbstractContentAchievementAction extends AbstractAchievementActi
$return['type'] = $values['achievement_filter_' . $classKey . '_type'];
$itemClass = $return['type'];
if ( \in_array( 'IPS\Content\Comment', class_parents( $return['type'] ) ) )
if ( in_array( 'IPS\Content\Comment', class_parents( $return['type'] ) ) )
{
$itemClass = $return['type']::$itemClass;
}
@@ -171,12 +191,12 @@ abstract class _AbstractContentAchievementAction extends AbstractAchievementActi
* calls that BEFORE making its change in the database (or there is read/write separation), you will need to add
* 1 to the value being considered for milestones
*
* @param \IPS\Member $subject The subject member
* @param Member $subject The subject member
* @param array $filters The value returned by formatFilterValues()
* @param mixed $extra Any additional information about what is happening (e.g. if a post is being made: the post object)
* @return bool
*/
public function filtersMatch( \IPS\Member $subject, array $filters, $extra = NULL ): bool
public function filtersMatch( Member $subject, array $filters, mixed $extra = NULL ): bool
{
if ( isset( $filters['type'] ) )
{
@@ -186,14 +206,14 @@ abstract class _AbstractContentAchievementAction extends AbstractAchievementActi
}
$item = $extra;
if ( \in_array( 'IPS\Content\Comment', class_parents( $filters['type'] ) ) )
if ( in_array( 'IPS\Content\Comment', class_parents( $filters['type'] ) ) )
{
$item = $extra->item();
}
if ( isset( $filters[ 'nodes_' . str_replace( '\\', '-', \get_class( $item ) ) ] ) )
if ( isset( $filters[ 'nodes_' . str_replace( '\\', '-', get_class( $item ) ) ] ) )
{
if ( !\in_array( $item->container()->_id, $filters[ 'nodes_' . str_replace( '\\', '-', \get_class( $item ) ) ] ) )
if ( !in_array( $item->container()->_id, $filters[ 'nodes_' . str_replace( '\\', '-', get_class( $item ) ) ] ) )
{
return FALSE;
}
@@ -204,19 +224,19 @@ abstract class _AbstractContentAchievementAction extends AbstractAchievementActi
else
{
/* Make sure the class is a contentRouter approved class, mostly to stop private messages being awarded points */
foreach ( \IPS\Application::allExtensions( 'core', 'ContentRouter', FALSE ) as $extension )
foreach ( Application::allExtensions( 'core', 'ContentRouter', FALSE ) as $extension )
{
foreach ( $extension->classes as $class )
{
if ( \get_class( $extra ) == $class )
if ( get_class( $extra ) == $class )
{
return TRUE;
}
elseif ( isset( $class::$commentClass ) and \get_class( $extra ) == $class::$commentClass )
elseif ( isset( $class::$commentClass ) and get_class( $extra ) == $class::$commentClass )
{
return TRUE;
}
elseif ( isset( $class::$reviewClass ) and \get_class( $extra ) == $class::$reviewClass )
elseif ( isset( $class::$reviewClass ) and get_class( $extra ) == $class::$reviewClass )
{
return TRUE;
}
@@ -225,36 +245,33 @@ abstract class _AbstractContentAchievementAction extends AbstractAchievementActi
return FALSE;
}
/* Stop PHPStorm from complaining about incorrect return types >_> */
return FALSE;
}
/**
* Get identifier to prevent the member being awarded points for the same action twice
* Must be unique within within of this domain, must not exceed 32 chars.
*
* @param \IPS\Member $subject The subject member
* @param Member $subject The subject member
* @param mixed $extra Any additional information about what is happening (e.g. if a post is being made: the post object)
* @return string
*/
public function identifier( \IPS\Member $subject, $extra = NULL ): string
public function identifier( Member $subject, mixed $extra = NULL ): string
{
return \get_class( $extra ) . ':' . $extra->{$extra::$databaseColumnId};
return get_class( $extra ) . ':' . $extra->{$extra::$databaseColumnId};
}
/**
* Get "description" for rule (usually a description of the rule's filters)
*
* @param \IPS\core\Achievements\Rule $rule The rule
* @param Rule $rule The rule
* @return string|NULL
*/
protected function _nodeFilterDescription( \IPS\core\Achievements\Rule $rule ): ?string
protected function _nodeFilterDescription( Rule $rule ): ?string
{
if ( isset( $rule->filters['type'] ) )
{
$itemClass = $rule->filters['type'];
if ( \in_array( 'IPS\Content\Comment', class_parents( $rule->filters['type'] ) ) )
if ( in_array( 'IPS\Content\Comment', class_parents( $rule->filters['type'] ) ) )
{
$itemClass = $itemClass::$itemClass;
}
@@ -270,18 +287,18 @@ abstract class _AbstractContentAchievementAction extends AbstractAchievementActi
{
$nodeNames[] = $nodeClass::load( $id )->_title;
}
catch ( \OutOfRangeException $e ) {}
catch ( OutOfRangeException $e ) {}
}
if ( $nodeNames )
{
return \IPS\Member::loggedIn()->language()->addToStack( 'achievements_title_filter_location', FALSE, [
return Member::loggedIn()->language()->addToStack( 'achievements_title_filter_location', FALSE, [
'htmlsprintf' => [
\IPS\Theme::i()->getTemplate( 'achievements' )->ruleDescriptionBadge( 'location',
\count( $nodeNames ) === 1 ? $nodeNames[0] : \IPS\Member::loggedIn()->language()->addToStack( 'achievements_title_filter_location_val', FALSE, [ 'sprintf' => [
\count( $nodeNames ),
\IPS\Member::loggedIn()->language()->addToStack( $nodeClass::$nodeTitle, FALSE )
Theme::i()->getTemplate( 'achievements' )->ruleDescriptionBadge( 'location',
count( $nodeNames ) === 1 ? $nodeNames[0] : Member::loggedIn()->language()->addToStack( 'achievements_title_filter_location_val', FALSE, [ 'sprintf' => [
count( $nodeNames ),
Member::loggedIn()->language()->addToStack( $nodeClass::$nodeTitle, FALSE )
] ] ),
\count( $nodeNames ) === 1 ? NULL : $nodeNames
count( $nodeNames ) === 1 ? NULL : $nodeNames
)
],
] );
@@ -296,10 +313,10 @@ abstract class _AbstractContentAchievementAction extends AbstractAchievementActi
*
* @return array
*/
static public function rebuildData()
static public function rebuildData() : array
{
$return = [];
foreach ( \IPS\Application::allExtensions( 'core', 'ContentRouter', FALSE ) as $extension )
foreach ( Application::allExtensions( 'core', 'ContentRouter', FALSE ) as $extension )
{
foreach ( $extension->classes as $class )
{
@@ -349,30 +366,32 @@ abstract class _AbstractContentAchievementAction extends AbstractAchievementActi
*
* @param array $filters The value returned by formatFilterValues()
* @param string $class Class we are working with
* @param \IPS\DateTime|null $time Any time limit to add
* @param DateTime|null $time Any time limit to add
* @return array
*/
protected function getWherePerType( $filters, $class, $time=NULL ): array
protected function getWherePerType( array $filters, string $class, ?DateTime $time=NULL ): array
{
/* @var Content $class */
/* @var array $databaseColumnMap */
$where = ( $time ? [ [ $class::$databasePrefix . $class::$databaseColumnMap['date'] . ' >= ?', $time->getTimestamp() ] ] : [] );
$itemClass = $class;
if ( \in_array( 'IPS\Content\Comment', class_parents( $class ) ) )
if ( in_array( 'IPS\Content\Comment', class_parents( $class ) ) )
{
$itemClass = $class::$itemClass;
}
if ( isset( $filters[ 'nodes_' . str_replace( '\\', '-', $itemClass ) ] ) )
{
if ( \in_array( 'IPS\Content\Comment', class_parents( $class ) ) )
if ( in_array( 'IPS\Content\Comment', class_parents( $class ) ) )
{
$itemClass = $class::$itemClass;
$where[] = [ $class::$databasePrefix . $class::$databaseColumnMap['item'] . ' IN(?)',
\IPS\Db::i()->select( $itemClass::$databasePrefix . $itemClass::$databaseColumnId, $itemClass::$databaseTable, [ \IPS\Db::i()->in( $itemClass::$databasePrefix . $itemClass::$databaseColumnMap['container'], $filters[ 'nodes_' . str_replace( '\\', '-', $itemClass ) ] ) ] ) ];
Db::i()->select( $itemClass::$databasePrefix . $itemClass::$databaseColumnId, $itemClass::$databaseTable, [ Db::i()->in( $itemClass::$databasePrefix . $itemClass::$databaseColumnMap['container'], $filters[ 'nodes_' . str_replace( '\\', '-', $itemClass ) ] ) ] ) ];
}
else
{
$where[] = [ \IPS\Db::i()->in( $class::$databasePrefix . $class::$databaseColumnMap['container'], $filters[ 'nodes_' . str_replace( '\\', '-', $class ) ] ) ];
$where[] = [ Db::i()->in( $class::$databasePrefix . $class::$databaseColumnMap['container'], $filters[ 'nodes_' . str_replace( '\\', '-', $class ) ] ) ];
}
}
@@ -386,9 +405,9 @@ abstract class _AbstractContentAchievementAction extends AbstractAchievementActi
* @param array $data Data collected when starting rebuild [table, pkey...]
* @return void
*/
public static function rebuildRow( $row, $data )
public static function rebuildRow( array $row, array $data ) : void
{
$classCalled = explode( '\\', \get_called_class() );
$classCalled = explode( '\\', get_called_class() );
$class = $data['class'];
$item = $class::constructFromData( $row );
$item->author()->achievementAction( 'core', array_pop( $classCalled ), $item );
@@ -10,32 +10,47 @@
namespace IPS\core\Achievements\Actions;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Application;
use IPS\core\Achievements\Rule;
use IPS\Helpers\Form\Node;
use IPS\Helpers\Form\Number;
use IPS\Helpers\Form\Select;
use IPS\Http\Url;
use IPS\Member;
use IPS\Theme;
use OutOfRangeException;
use function count;
use function defined;
use function get_class;
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;
}
/**
* Abstract Achievement Action Extension for content-related things
*/
abstract class _AbstractNodeAchievementAction extends AbstractAchievementAction
abstract class NodeAchievementActionAbstract extends AchievementActionAbstract
{
/**
* Get filter form elements
*
* @param array|NULL $filters Current filter values (if editing)
* @param \IPS\Http\Url $url The URL the form is being shown on
* @param Url $url The URL the form is being shown on
* @return array
*/
public function filters( ?array $filters, \IPS\Http\Url $url ): array
public function filters( ?array $filters, Url $url ): array
{
$contentTypeOptions = [];
$contentTypeToggles = [];
$_return = [];
$defaultApp = NULL;
foreach( \IPS\Application::applications() as $directory => $application )
foreach( Application::applications() as $directory => $application )
{
if( $application->default )
{
@@ -43,7 +58,7 @@ abstract class _AbstractNodeAchievementAction extends AbstractAchievementAction
break;
}
}
foreach ( \IPS\Application::allExtensions( 'core', 'ContentRouter', FALSE, $defaultApp ) as $extension )
foreach ( Application::allExtensions( 'core', 'ContentRouter', FALSE, $defaultApp ) as $extension )
{
foreach ( $extension->classes as $class )
{
@@ -51,27 +66,26 @@ abstract class _AbstractNodeAchievementAction extends AbstractAchievementAction
{
$nodeClass = $class::$containerNodeClass;
$nodeFilterKey = 'achievement_subfilter_Node_type_' . str_replace( '\\', '-', $nodeClass );
$contentTypeToggles[ $nodeClass ][] = $nodeFilterKey;
$contentTypeToggles[ $nodeClass ] = [ $nodeFilterKey ];
$contentTypeOptions[ $nodeClass ] = $nodeClass::fullyQualifiedType();
$nodeFilter = new \IPS\Helpers\Form\Node( $nodeFilterKey, ( $filters and isset( $filters[ 'nodes_' . str_replace( '\\', '-', $nodeClass ) ] ) and $filters[ 'nodes_' . str_replace( '\\', '-', $nodeClass ) ] ) ? $filters[ 'nodes_' . str_replace( '\\', '-', $nodeClass ) ] : 0, FALSE, [
$nodeFilter = new Node( $nodeFilterKey, ( $filters and isset( $filters[ 'nodes_' . str_replace( '\\', '-', $nodeClass ) ] ) and $filters[ 'nodes_' . str_replace( '\\', '-', $nodeClass ) ] ) ? $filters[ 'nodes_' . str_replace( '\\', '-', $nodeClass ) ] : 0, FALSE, [
'url' => $url,
'class' => $class::$containerNodeClass,
'showAllNodes' => TRUE,
'multiple' => TRUE,
], NULL, \IPS\Member::loggedIn()->language()->addToStack( 'achievement_filter_Node_node_prefix') );
$nodeFilter->label = \IPS\Member::loggedIn()->language()->addToStack( 'achievement_filter_Node_node', FALSE, [ 'sprintf' => [ \IPS\Member::loggedIn()->language()->addToStack( ($class::$containerNodeClass)::$nodeTitle . '_sg', FALSE, [ 'strtolower' => TRUE ] ) ] ] );
], NULL, Member::loggedIn()->language()->addToStack( 'achievement_filter_Node_node_prefix') );
$nodeFilter->label = Member::loggedIn()->language()->addToStack( 'achievement_filter_Node_node', FALSE, [ 'sprintf' => [ Member::loggedIn()->language()->addToStack( ($class::$containerNodeClass)::$nodeTitle . '_sg', FALSE, [ 'strtolower' => TRUE ] ) ] ] );
$_return[ "nodes_" . str_replace( '\\', '-', $nodeClass ) ] = $nodeFilter;
}
}
}
$typeFilter = new \IPS\Helpers\Form\Select( 'achievement_filter_Node_type', ( $filters and isset( $filters['type'] ) and $filters['type'] ) ? $filters['type'] : NULL, FALSE, [ 'options' => $contentTypeOptions, 'toggles' => $contentTypeToggles ], NULL, \IPS\Member::loggedIn()->language()->addToStack('achievement_filter_NewContentItem_type_prefix') );
$typeFilter->label = \IPS\Member::loggedIn()->language()->addToStack('achievement_filter_NewContentItem_type');
$typeFilter = new Select( 'achievement_filter_Node_type', ( $filters and isset( $filters['type'] ) and $filters['type'] ) ? $filters['type'] : NULL, FALSE, [ 'options' => $contentTypeOptions, 'toggles' => $contentTypeToggles ], NULL, Member::loggedIn()->language()->addToStack('achievement_filter_NewContentItem_type_prefix') );
$typeFilter->label = Member::loggedIn()->language()->addToStack('achievement_filter_NewContentItem_type');
$nthFilter = new \IPS\Helpers\Form\Number( 'achievement_filter_Node_nth', ( $filters and isset( $filters['milestone'] ) and $filters['milestone'] ) ? $filters['milestone'] : 0, FALSE, [], NULL, \IPS\Member::loggedIn()->language()->addToStack('achievement_filter_nth_their'), \IPS\Member::loggedIn()->language()->addToStack('achievement_filter_Node_nth_suffix') );
$nthFilter->label = \IPS\Member::loggedIn()->language()->addToStack('achievement_filter_Node_nth');
$nthFilter = new Number( 'achievement_filter_Node_nth', ( $filters and isset( $filters['milestone'] ) and $filters['milestone'] ) ? $filters['milestone'] : 0, FALSE, [], NULL, Member::loggedIn()->language()->addToStack('achievement_filter_nth_their'), Member::loggedIn()->language()->addToStack('achievement_filter_Node_nth_suffix') );
$nthFilter->label = Member::loggedIn()->language()->addToStack('achievement_filter_Node_nth');
$return = [ 'type' => $typeFilter ];
foreach ( $_return as $k => $v )
@@ -117,12 +131,12 @@ abstract class _AbstractNodeAchievementAction extends AbstractAchievementAction
* calls that BEFORE making its change in the database (or there is read/write separation), you will need to add
* 1 to the value being considered for milestones
*
* @param \IPS\Member $subject The subject member
* @param Member $subject The subject member
* @param array $filters The value returned by formatFilterValues()
* @param mixed $extra Any additional information about what is happening (e.g. if a post is being made: the post object)
* @return bool
*/
public function filtersMatch( \IPS\Member $subject, array $filters, $extra = NULL ): bool
public function filtersMatch( Member $subject, array $filters, mixed $extra = NULL ): bool
{
if ( isset( $filters['type'] ) )
{
@@ -131,9 +145,9 @@ abstract class _AbstractNodeAchievementAction extends AbstractAchievementAction
return FALSE;
}
if ( isset( $filters[ 'nodes_' . str_replace( '\\', '-', \get_class( $extra ) ) ] ) )
if ( isset( $filters[ 'nodes_' . str_replace( '\\', '-', get_class( $extra ) ) ] ) )
{
if ( !\in_array( $extra->_id, $filters[ 'nodes_' . str_replace( '\\', '-', \get_class( $extra ) ) ] ) )
if ( !in_array( $extra->_id, $filters[ 'nodes_' . str_replace( '\\', '-', get_class( $extra ) ) ] ) )
{
return FALSE;
}
@@ -147,22 +161,22 @@ abstract class _AbstractNodeAchievementAction extends AbstractAchievementAction
* Get identifier to prevent the member being awarded points for the same action twice
* Must be unique within within of this domain, must not exceed 32 chars.
*
* @param \IPS\Member $subject The subject member
* @param Member $subject The subject member
* @param mixed $extra Any additional information about what is happening (e.g. if a post is being made: the post object)
* @return string
*/
public function identifier( \IPS\Member $subject, $extra = NULL ): string
public function identifier( Member $subject, mixed $extra = NULL ): string
{
return \get_class( $extra ) . ':' . $extra->{$extra::$databaseColumnId} . ':' . $subject->member_id;
return get_class( $extra ) . ':' . $extra->{$extra::$databaseColumnId} . ':' . $subject->member_id;
}
/**
* Get "description" for rule (usually a description of the rule's filters)
*
* @param \IPS\core\Achievements\Rule $rule The rule
* @param Rule $rule The rule
* @return string|NULL
*/
protected function _nodeFilterDescription( \IPS\core\Achievements\Rule $rule ): ?string
protected function _nodeFilterDescription( Rule $rule ): ?string
{
if ( isset( $rule->filters['type'] ) )
{
@@ -177,18 +191,18 @@ abstract class _AbstractNodeAchievementAction extends AbstractAchievementAction
{
$nodeNames[] = $nodeClass::load( $id )->_title;
}
catch ( \OutOfRangeException $e ) {}
catch ( OutOfRangeException $e ) {}
}
if ( $nodeNames )
{
return \IPS\Member::loggedIn()->language()->addToStack( 'achievements_title_filter_location', FALSE, [
return Member::loggedIn()->language()->addToStack( 'achievements_title_filter_location', FALSE, [
'htmlsprintf' => [
\IPS\Theme::i()->getTemplate( 'achievements' )->ruleDescriptionBadge( 'location',
\count( $nodeNames ) === 1 ? $nodeNames[0] : \IPS\Member::loggedIn()->language()->addToStack( 'achievements_title_filter_location_val', FALSE, [ 'sprintf' => [
\count( $nodeNames ),
\IPS\Member::loggedIn()->language()->addToStack( $nodeClass::$nodeTitle, FALSE, [ 'strtolower' => TRUE ] )
Theme::i()->getTemplate( 'achievements' )->ruleDescriptionBadge( 'location',
count( $nodeNames ) === 1 ? $nodeNames[0] : Member::loggedIn()->language()->addToStack( 'achievements_title_filter_location_val', FALSE, [ 'sprintf' => [
count( $nodeNames ),
Member::loggedIn()->language()->addToStack( $nodeClass::$nodeTitle, FALSE, [ 'strtolower' => TRUE ] )
] ] ),
\count( $nodeNames ) === 1 ? NULL : $nodeNames
count( $nodeNames ) === 1 ? NULL : $nodeNames
)
],
] );