Version 5.0.13

This commit is contained in:
Neo committed 2025-12-19 19:04:57 -08:00
1 parent b89858b2ff
commit 5efe744c5f
1407 files changed
+69690 -30177

No files matched your search

@@ -49,8 +49,8 @@ class AnswerMarkedBest extends AchievementActionAbstract
*/
public function filters( ?array $filters, Url $url ): array
{
return [
'nodes' => new Node( 'achievement_filter_AnswerMarkedBest_forum', ( $filters and isset( $filters['nodes'] ) and $filters['nodes'] ) ? $filters['nodes'] : NULL, FALSE, [
$return = parent::filters( $filters, $url );
$return['nodes'] = new Node( 'achievement_filter_AnswerMarkedBest_forum', ( $filters and isset( $filters['nodes'] ) and $filters['nodes'] ) ? $filters['nodes'] : NULL, FALSE, [
'url' => $url,
'class' => 'IPS\forums\Forum',
'showAllNodes' => TRUE,
@@ -58,15 +58,16 @@ class AnswerMarkedBest extends AchievementActionAbstract
'permissionCheck' => function( $forum ) {
return $forum->forums_bitoptions['bw_enable_answers'];
}
], NULL, Member::loggedIn()->language()->addToStack('achievement_filter_AnswerMarkedBest_forum_prefix') ),
'helpful_or_solved' => new Select( 'achievement_filter_AnswerMarkedBest_helpful_or_solved', ( $filters and isset( $filters['helpful_or_solved'] ) and $filters['helpful_or_solved'] ) ? $filters['helpful_or_solved'] : NULL, NULL, [
], NULL, Member::loggedIn()->language()->addToStack('achievement_filter_AnswerMarkedBest_forum_prefix') );
$return['helpful_or_solved'] = new Select( 'achievement_filter_AnswerMarkedBest_helpful_or_solved', ( $filters and isset( $filters['helpful_or_solved'] ) and $filters['helpful_or_solved'] ) ? $filters['helpful_or_solved'] : NULL, NULL, [
'options' => [
'helpful' => Member::loggedIn()->language()->addToStack('achievement_filter_AnswerMarkedBest_helpful_or_solved_helpful'),
'solved' => Member::loggedIn()->language()->addToStack('achievement_filter_AnswerMarkedBest_helpful_or_solved_solved')
]
] ),
'milestone' => new Number( 'achievement_filter_AnswerMarkedBest_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_AnswerMarkedBest_nth_suffix') )
];
] );
$return['milestone'] = new Number( 'achievement_filter_AnswerMarkedBest_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_AnswerMarkedBest_nth_suffix') );
return $return;
}
/**
@@ -77,7 +78,7 @@ class AnswerMarkedBest extends AchievementActionAbstract
*/
public function formatFilterValues( array $values ): array
{
$return = [];
$return = parent::formatFilterValues( $values );
if ( isset( $values['achievement_filter_AnswerMarkedBest_forum'] ) )
{
$return['nodes'] = array_keys( $values['achievement_filter_AnswerMarkedBest_forum'] );
@@ -163,6 +164,39 @@ class AnswerMarkedBest extends AchievementActionAbstract
{
return [ $extra['post']->item()->author() ];
}
/**
* Determines if the member has already completed this rule.
* Used for retroactive rule completion.
* So far, this is only used in Quests, but may be used elsewhere at a later point.
*
* @param Member $member
* @param array $filters
* @return bool
*/
public function isRuleCompleted( Member $member, array $filters ) : bool
{
$where = [
[' member_id=?', $member->member_id ],
[ 'app=?', 'forums' ]
];
if( !empty( $filters['nodes'] ) )
{
$where[] = [ Db::i()->in( 'forum_id', $filters['nodes'] ) ];
}
$total = Db::i()->select( 'count(*)', 'core_solved_index', $where )
->join( 'forums_topics', 'item_id=tid' )
->first();
if( !empty( $filters['milestone'] ) )
{
return $total >= $filters['milestone'];
}
return $total > 0;
}
/**
* Get identifier to prevent the member being awarded points for the same action twice
@@ -238,7 +272,7 @@ class AnswerMarkedBest extends AchievementActionAbstract
{
$conditions[] = Member::loggedIn()->language()->addToStack( 'achievements_title_filter_milestone', FALSE, [
'htmlsprintf' => [
Theme::i()->getTemplate( 'achievements' )->ruleDescriptionBadge( 'milestone', Member::loggedIn()->language()->addToStack( 'achievements_title_filter_milestone_nth', FALSE, [ 'pluralize' => [ $rule->filters['milestone'] ] ] ) )
Theme::i()->getTemplate( 'achievements', 'core' )->ruleDescriptionBadge( 'milestone', Member::loggedIn()->language()->addToStack( 'achievements_title_filter_milestone_nth', FALSE, [ 'pluralize' => [ $rule->filters['milestone'] ] ] ) )
],
'sprintf' => Member::loggedIn()->language()->addToStack( 'best_answer_post', FALSE, [ 'strtolower' => TRUE ] )
] );
@@ -258,7 +292,7 @@ class AnswerMarkedBest extends AchievementActionAbstract
{
$conditions[] = Member::loggedIn()->language()->addToStack( 'achievements_title_filter_location', FALSE, [
'htmlsprintf' => [
Theme::i()->getTemplate( 'achievements' )->ruleDescriptionBadge( 'location',
Theme::i()->getTemplate( 'achievements', 'core' )->ruleDescriptionBadge( 'location',
count( $forumNames ) === 1 ? $forumNames[0] : Member::loggedIn()->language()->addToStack( 'achievements_title_filter_location_val', FALSE, [ 'sprintf' => [
count( $forumNames ),
Member::loggedIn()->language()->addToStack( Forum::$nodeTitle, FALSE, [ 'strtolower' => TRUE ] )
@@ -269,13 +303,19 @@ class AnswerMarkedBest extends AchievementActionAbstract
] );
}
}
if( $questCondition = $this->_questFilterDescription( $rule ) )
{
$conditions[] = $questCondition;
}
$title = Member::loggedIn()->language()->addToStack( 'AchievementAction__AnswerMarkedBest_title' );
if ( isset( $rule->filters['helpful_or_solved'] ) and $rule->filters['helpful_or_solved'] == 'helpful' )
{
$title = Member::loggedIn()->language()->addToStack( 'AchievementAction__AnswerMarkedHelpful_title' );
}
return Theme::i()->getTemplate( 'achievements' )->ruleDescription( $title, $conditions );
return Theme::i()->getTemplate( 'achievements', 'core' )->ruleDescription( $title, $conditions );
}
/**
@@ -13,7 +13,9 @@ namespace IPS\forums\extensions\core\AdvertisementLocations;
/* To prevent PHP errors (extending class does not exist) revealing path */
use IPS\core\Advertisement;
use IPS\Extensions\AdvertisementLocationsAbstract;
use IPS\Request;
use function defined;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
@@ -43,7 +45,7 @@ class ForumListing extends AdvertisementLocationsAbstract
*/
public function getSettings( array $settings ): array
{
return array( 'locations' => array( 'ad_forum_listing' => array() ), 'settings' => array() );
return array( 'locations' => array( 'ad_forum_listing' => array( 'IPS_forums_Forum' ) ), 'settings' => array() );
}
/**
@@ -56,4 +58,21 @@ class ForumListing extends AdvertisementLocationsAbstract
{
return array();
}
/**
* Check if the advertisement can be displayed, based on settings
*
* @param Advertisement $advertisement
* @param string $location
* @return bool
*/
public function canShow( Advertisement $advertisement, string $location ) : bool
{
if( isset( $advertisement->_additional_settings['IPS_forums_Forum'] ) and !in_array( Request::i()->id, $advertisement->_additional_settings['IPS_forums_Forum'] ) )
{
return false;
}
return TRUE;
}
}
@@ -13,7 +13,11 @@ namespace IPS\forums\extensions\core\AdvertisementLocations;
/* To prevent PHP errors (extending class does not exist) revealing path */
use IPS\core\Advertisement;
use IPS\Extensions\AdvertisementLocationsAbstract;
use IPS\forums\Topic;
use IPS\Request;
use OutOfRangeException;
use function defined;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
@@ -43,7 +47,7 @@ class TopicView extends AdvertisementLocationsAbstract
*/
public function getSettings( array $settings ): array
{
return array( 'locations' => array( 'ad_topic_view' => array() ), 'settings' => array() );
return array( 'locations' => array( 'ad_topic_view' => array( 'IPS_forums_Forum' ) ), 'settings' => array() );
}
/**
@@ -56,4 +60,28 @@ class TopicView extends AdvertisementLocationsAbstract
{
return array();
}
/**
* Check if the advertisement can be displayed, based on settings
*
* @param Advertisement $advertisement
* @param string $location
* @return bool
*/
public function canShow( Advertisement $advertisement, string $location ) : bool
{
if( isset( $advertisement->_additional_settings['IPS_forums_Forum'] ) )
{
try
{
return in_array( Topic::load( Request::i()->id )->forum_id, $advertisement->_additional_settings['IPS_forums_Forum'] );
}
catch( OutOfRangeException )
{
return false;
}
}
return TRUE;
}
}
@@ -15,8 +15,11 @@ namespace IPS\forums\extensions\core\Announcements;
use IPS\core\Announcements\Announcement;
use IPS\Extensions\AnnouncementsAbstract;
use IPS\forums\Forum;
use IPS\Helpers\Form\FormAbstract;
use IPS\Helpers\Form\Node;
use IPS\Node\NodeGroup;
use OutOfRangeException;
use function defined;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
@@ -55,6 +58,35 @@ class Forums extends AnnouncementsAbstract
return new Node( 'announce_forums', ( $announcement AND $announcement->ids ) ? explode( ",", $announcement->ids ) : 0, FALSE, array( 'class' => 'IPS\forums\Forum', 'zeroVal' => 'any', 'multiple' => TRUE, 'permissionCheck' => function ( $forum )
{
return $forum->sub_can_post and !$forum->redirect_url;
} ), NULL, NULL, NULL, 'announce_forums' );
}, 'nodeGroups' => true ), NULL, NULL, NULL, 'announce_forums' );
}
/**
* Parse the stored IDs into something that makes sense for the Announcement
* Default is a comma-separated string, but some locations may override
*
* @see Announcement::loadAllByLocation()
* @param string $ids
* @return array
*/
public function getAnnouncementIds( string $ids ) : array
{
$return = [];
foreach( parent::getAnnouncementIds( $ids ) as $id )
{
if( mb_substr( $id, 0, 1 ) == 'g' )
{
$group = Forum::availableNodeGroups()[ mb_substr( $id, 1 ) ] ?? null;
if( $group )
{
$return = array_merge( $return, $group->nodeIds() );
}
}
else
{
$return[] = $id;
}
}
return $return;
}
}
@@ -13,6 +13,7 @@ namespace IPS\forums\extensions\core\EditorLocations;
/* To prevent PHP errors (extending class does not exist) revealing path */
use Exception;
use InvalidArgumentException;
use IPS\Content;
use IPS\Db;
@@ -159,26 +160,30 @@ class Forums extends EditorLocationsAbstract
*/
public function attachmentLookup( int $id1=NULL, int $id2=NULL, string $id3=NULL ): Model|Content|Url|Member|null
{
if ( $id3 )
try
{
return Forum::load( $id1 );
}
elseif ( $id2 )
{
$topic = Topic::load( $id1 );
if( $id3 )
{
return Forum::load( $id1 );
}elseif( $id2 )
{
$topic = Topic::load( $id1 );
if( $topic->isArchived() )
if( $topic->isArchived() )
{
return ArchivedPost::load( $id2 );
}else
{
return Post::load( $id2 );
}
}else
{
return ArchivedPost::load( $id2 );
}
else
{
return Post::load( $id2 );
return Topic::load( $id1 );
}
}
else
catch( Exception $e )
{
return Topic::load( $id1 );
throw new LogicException;
}
}
@@ -252,7 +257,7 @@ class Forums extends EditorLocationsAbstract
}
catch( InvalidArgumentException $e )
{
if( $callback[1] == 'parseStatic' AND $e->getcode() == 103014 )
if( is_array( $callback ) and $callback[1] == 'parseStatic' AND $e->getcode() == 103014 )
{
$rebuilt = preg_replace( "#\[/?([^\]]+?)\]#", '', $word['word_custom'] );
}
@@ -26,9 +26,13 @@ use IPS\Helpers\Form\Node;
use IPS\Member;
use IPS\Request;
use IPS\Theme;
use function array_merge;
use function defined;
use function explode;
use function in_array;
use function is_array;
use function iterator_to_array;
use function round;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
@@ -178,6 +182,106 @@ class Solved extends OverviewStatisticsAbstract
return Theme::i()->getTemplate( 'stats', 'forums' )->solvedPercentage( $value, $previousValue, $nodeNames );
}
/**
* Generate numbers for the CSV export. Yes, there's lots of duplicated code from getBlock().
*
* @param array|string|null $dateRange
* @param string|null $subBlock
* @return (null|int)[]
*/
public function getBlockNumbers( array|string $dateRange = null, string $subBlock = null ) : array
{
/* Make sure someone isn't trying to manipulate the request or do something weird */
if( !in_array( $subBlock, $this->getBlocks() ) )
{
return [];
}
$value = 0;
$previousValue = 0;
/* Build where clause in the event we are filtering */
$where = array();
$previousWhere = NULL;
if( $dateRange !== NULL )
{
if( is_array( $dateRange ) )
{
$where = array(
array( 'start_date > ?', $dateRange['start']->getTimestamp() ),
array( 'start_date < ?', $dateRange['end']->getTimestamp() ),
);
}
else
{
$currentDate = new DateTime;
$interval = static::getInterval( $dateRange );
$initialTimestamp = $currentDate->sub( $interval )->getTimestamp();
$where = array( array( 'start_date > ?', $initialTimestamp ) );
$previousWhere = array( array( 'start_date BETWEEN ? AND ?', $currentDate->sub( $interval )->getTimestamp(), $initialTimestamp ) );
}
}
else if ( isset( Request::i()->nodes ) and Request::i()->nodes )
{
$where = array( array( Db::i()->in( 'forum_id', explode( ',', Request::i()->nodes ) ) ) );
}
//$where[] = array( 'type=?', 'solved' );
$where[] = array( Db::i()->in( 'forum_id', iterator_to_array( Db::i()->select( 'id', 'forums_forums', '(' . Db::i()->bitwiseWhere( Forum::$bitOptions['forums_bitoptions'], 'bw_enable_answers' ) . ') OR ( ' . Db::i()->bitwiseWhere( Forum::$bitOptions['forums_bitoptions'], 'bw_solved_set_by_moderator' ) . ' )' ) ) ) );
/* Get the current and previous values */
switch( $subBlock )
{
case 'percentagesolved':
$total = Db::i()->select( 'COUNT(*)', 'forums_topics', $this->_modifyWhereClause( $where ) )->first();
$solvedWhere = $this->_modifyWhereClause( $where );
$solvedWhere[] = [ 'core_solved_index.id is not null' ];
$solvedWhere[] = [ 'type=?', 'solved' ];
$solved = Db::i()->select( 'COUNT(*)', 'forums_topics', $solvedWhere )->join( 'core_solved_index', "core_solved_index.app='forums' AND core_solved_index.item_id=forums_topics.tid")->first();
$value = $total ? round( $solved / $total * 100, 2 ) : 0;
if( $previousWhere !== NULL )
{
$previousTotal = Db::i()->select( 'COUNT(*)', 'forums_topics', $this->_modifyWhereClause( $previousWhere ) )->first();
$previousSolved = Db::i()->select( 'COUNT(*)', 'forums_topics', array_merge( $this->_modifyWhereClause( $previousWhere ), array( array( 'core_solved_index.id IS NOT NULL' ) ) ) )->join( 'core_solved_index', "core_solved_index.app='forums' AND core_solved_index.item_id=forums_topics.tid")->first();
$previousValue = $previousTotal ? round( $previousSolved / $previousTotal * 100, 2 ) : 0;
}
return [
'statsreports_current_count' => $value,
'statsreports_previous_count' => $previousValue,
];
case 'averagetimesolved':
$value = Db::i()->select( 'AVG(CAST(core_solved_index.solved_date AS SIGNED)-forums_topics.start_date)', 'forums_topics', array_merge( $this->_modifyWhereClause( $where ), array( array( 'core_solved_index.id IS NOT NULL' ) ) ) )->join( 'core_solved_index', "core_solved_index.app='forums' AND core_solved_index.item_id=forums_topics.tid")->first();
if( $previousWhere !== NULL )
{
$previousValue = Db::i()->select( 'AVG(CAST(core_solved_index.solved_date AS SIGNED)-forums_topics.start_date)', 'forums_topics', array_merge( $this->_modifyWhereClause( $previousWhere ), array( array( 'core_solved_index.id IS NOT NULL' ) ) ) )->join( 'core_solved_index', "core_solved_index.app='forums' AND core_solved_index.item_id=forums_topics.tid")->first();
}
return [
'statsreports_current_count' => $value,
'statsreports_previous_count' => $previousValue
];
}
return [
'statsreports_current_count' => $value,
'statsreports_previous_count' => $previousValue
];
}
/**
* Modify the where clause to apply other filters
*
@@ -213,7 +317,7 @@ class Solved extends OverviewStatisticsAbstract
}
$form = new Form;
$form->attributes['data-controller'] = 'core.admin.stats.nodeFilters';
$form->class = "ipsForm--vertical";
$form->attributes['data-block'] = Request::i()->blockKey;
$form->attributes['data-subblock'] = $subBlock;
$form->add( new Node( Forum::$nodeTitle, NULL, TRUE, array( 'class' => '\IPS\forums\Forum', 'multiple' => TRUE, 'clubs' => FALSE ) ) );
@@ -0,0 +1,97 @@
<?php
/**
* @brief Background Task
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage Forums
* @since 22 Sep 2025
*/
namespace IPS\forums\extensions\core\Queue;
use IPS\Db;
use IPS\Extensions\QueueAbstract;
use IPS\Member;
use IPS\Task\Queue\OutOfRangeException as QueueOutOfRangeException;
use OutOfRangeException;
use function defined;
use const IPS\REBUILD_NORMAL;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Background Task
*/
class RebuildHelpfulCount extends QueueAbstract
{
/**
* Parse data before queuing
*
* @param array $data
* @return array|null
*/
public function preQueueData( array $data ): ?array
{
$data['count'] = (int) Db::i()->select( 'count(*)', 'forums_topics' )->first();
$data['lastId'] = 0;
return $data;
}
/**
* Run Background Task
*
* @param array $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return int New offset
* @throws QueueOutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function run( array &$data, int $offset ): int
{
$limit = REBUILD_NORMAL;
$currentId = $data['lastId'] ?? 0;
$rows = Db::i()->select( 'tid, count(id) as helpful', 'forums_topics', [ 'tid>?', $currentId ], 'tid', $limit, 'tid' )
->join( 'core_solved_index', [ 'core_solved_index.app=? and core_solved_index.type=? and forums_topics.tid=core_solved_index.item_id', 'forums', 'helpful'] );
foreach( $rows as $row )
{
if( $row['helpful'] )
{
Db::i()->update( 'forums_topics', [ 'helpful_count' => $row['helpful'] ], [ 'tid=?', $row['tid'] ] );
}
$data['lastId'] = $row['tid'];
$offset++;
}
if( $currentId === $data['lastId'] )
{
throw new QueueOutOfRangeException;
}
return $offset;
}
/**
* Get Progress
*
* @param array $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return array( 'text' => 'Doing something...', 'complete' => 50 ) Text explaining task and percentage complete
* @throws OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function getProgress( array $data, int $offset ): array
{
return array(
'text' => Member::loggedIn()->language()->addToStack('queue_rebuilding_helpful_counts'),
'complete' => $offset ? ( round( 100 / $data['count'] * $offset, 2 ) ) : 100
);
}
}
@@ -58,16 +58,6 @@ class RssImport extends RssImportAbstract
return array( 'IPS\\forums\\Topic' => Member::loggedIn()->language()->addToStack('__app_forums') );
}
/**
* Show in the Admin CP?
*
* @return boolean
*/
public function showInAdminCp(): bool
{
return true;
}
/**
* Node selector options
*