Version 4.7.6

This commit is contained in:
Neo committed 2025-12-19 16:05:19 -08:00
1 parent 8ba7d43898
commit 7b7404e741
1085 files changed
+30590 -7837

No files matched your search

+72 -44
View File
@@ -166,7 +166,11 @@ trait Reactable
$itemIdColumn = $item::$databaseColumnId;
$itemId = $item->$itemIdColumn;
\IPS\Redis::i()->zIncrBy( 'trending', time() * 0.4, \get_class( $item ) .'__' . $itemId );
try
{
\IPS\Redis::i()->zIncrBy( 'trending', time() * 0.4, \get_class( $item ) .'__' . $itemId );
}
catch( \RedisException $e ) {}
}
}
@@ -519,65 +523,89 @@ trait Reactable
/**
* React Blurb
*
* @return string
* @return array
*/
public function reactBlurb()
public function reactBlurb(): array
{
if ( $this->reactBlurb === NULL )
{
$this->reactBlurb = array();
if ( \count( $this->reactions() ) )
/*
If we have lots of rows, then use a more efficient way of getting the data (but does increase query count and uses a group by).
I know this is an artibrary number, but it should mean that most communities never need to run this code, and just those with topics with more than 4,000 pages
*/
if ( ( $this instanceof \IPS\Content\Item ) and isset( $this::$databaseColumnMap['num_comments'] ) and $this->mapped( 'num_comments' ) >= 100000 )
{
$idColumn = static::$databaseColumnId;
if ( \is_array( $this->_reactions ) )
$enabledReactions = [];
foreach( \IPS\Content\Reaction::enabledReactions() as $reaction )
{
foreach( $this->_reactions AS $memberId => $reactions )
{
foreach( $reactions as $reaction )
{
if ( !isset( $this->reactBlurb[ $reaction ] ) )
{
$this->reactBlurb[ $reaction ] = 0;
}
$this->reactBlurb[ $reaction ]++;
}
}
}
else
{
foreach( \IPS\Db::i()->select( 'reaction', 'core_reputation_index', $this->getReactionWhereClause() )->join( 'core_reactions', 'reaction=reaction_id' ) AS $rep )
{
if ( !isset( $this->reactBlurb[ $rep ] ) )
{
$this->reactBlurb[ $rep ] = 0;
}
$this->reactBlurb[ $rep ]++;
}
$enabledReactions[] = $reaction->id;
}
/* Error suppressor for https://bugs.php.net/bug.php?id=50688 */
$enabledReactions = \IPS\Content\Reaction::enabledReactions();
@uksort( $this->reactBlurb, function( $a, $b ) use( $enabledReactions ) {
$positionA = $enabledReactions[ $a ]->position;
$positionB = $enabledReactions[ $b ]->position;
if ( $positionA == $positionB )
foreach( \IPS\Db::i()->select( 'COUNT(*) as count, reaction', 'core_reputation_index', $this->getReactionWhereClause( NULL , FALSE ), 'count DESC', NULL, 'reaction' ) as $row )
{
if( in_array( needle: $row['reaction'], haystack: $enabledReactions ) )
{
return 0;
$this->reactBlurb[ $row['reaction'] ] = $row['count'];
}
return ( $positionA < $positionB ) ? -1 : 1;
} );
}
}
else
{
$this->reactBlurb = array();
if ( \count( $this->reactions() ) )
{
$idColumn = static::$databaseColumnId;
if ( \is_array( $this->_reactions ) )
{
foreach ( $this->_reactions as $memberId => $reactions )
{
foreach ( $reactions as $reaction )
{
if ( !isset( $this->reactBlurb[$reaction] ) )
{
$this->reactBlurb[$reaction] = 0;
}
$this->reactBlurb[$reaction]++;
}
}
}
else
{
foreach ( \IPS\Db::i()->select( 'reaction', 'core_reputation_index', $this->getReactionWhereClause() )->join( 'core_reactions', 'reaction=reaction_id' ) as $rep )
{
if ( !isset( $this->reactBlurb[$rep] ) )
{
$this->reactBlurb[$rep] = 0;
}
$this->reactBlurb[$rep]++;
}
}
/* Error suppressor for https://bugs.php.net/bug.php?id=50688 */
$enabledReactions = \IPS\Content\Reaction::enabledReactions();
@uksort( $this->reactBlurb, function ( $a, $b ) use ( $enabledReactions ) {
$positionA = $enabledReactions[$a]->position;
$positionB = $enabledReactions[$b]->position;
if ( $positionA == $positionB )
{
return 0;
}
return ( $positionA < $positionB ) ? -1 : 1;
} );
}
else
{
$this->reactBlurb = array();
}
}
}
return $this->reactBlurb;
}