Version 5.0.6

This commit is contained in:
Neo committed 2025-12-19 18:55:49 -08:00
1 parent a3a4a9ccbd
commit b89858b2ff
1214 files changed
+92828 -14859

No files matched your search

+75 -36
View File
@@ -276,11 +276,8 @@ abstract class Item extends Content
}
}
/* Now loop through and add all the elements to the form */
foreach( UiExtension::i()->run( $item ?: get_called_class(), 'formElements', array( $container ) ) as $element )
{
$form->add( $element );
}
/* Extensions */
static::extendForm( $form, $item, $container );
return $form;
}
@@ -296,6 +293,24 @@ abstract class Item extends Content
return static::buildCreateForm( $this->containerWrapper(), $this );
}
/**
* Extracting this to a separate method so that we can make sure we
* call all extensions everywhere it's necessary
*
* @param Form $form
* @param Item|null $item
* @param Model|null $container
* @return void
*/
public static function extendForm( Form $form, ?Item $item=null, ?Model $container=null ) : void
{
/* Now loop through and add all the elements to the form */
foreach( UiExtension::i()->run( $item ?: get_called_class(), 'formElements', array( $container ) ) as $element )
{
$form->add( $element );
}
}
/**
* Create generic object
*
@@ -1101,6 +1116,15 @@ abstract class Item extends Content
}
}
/* Rebuild club stats, but only if we don't enforce a comment as Comment::postCreate() will update */
if( ! static::$firstCommentRequired and $container = $this->containerWrapper() )
{
if ( IPS::classUsesTrait( $container, 'IPS\Content\ClubContainer' ) and $club = $container->club() )
{
$club->updateLastActivityAndItemCount();
}
}
Event::fire( 'onCreateOrEdit', $this, array( $values, TRUE ) );
$this->ui( 'formPostSave', array( $values ) );
@@ -1230,6 +1254,8 @@ abstract class Item extends Content
Event::fire( 'onCreateOrEdit', $this, array( $values ) );
$this->ui( 'formPostSave', array( $values ) );
Webhook::fire( str_replace( '\\', '', substr( get_called_class(), 3 ) ) . '_edit', $this, $this->webhookFilters() );
}
/* Holds the old content for edit logging */
@@ -2790,7 +2816,7 @@ abstract class Item extends Content
* @param array $where Where clause
* @param string|null $order MySQL ORDER BY clause (NULL to order by date)
* @param int|array|null $limit Limit clause
* @param string $permissionKey A key which has a value in the permission map (either of the container or of this class) matching a column ID in core_permission_index or NULL to ignore permissions
* @param string|null $permissionKey A key which has a value in the permission map (either of the container or of this class) matching a column ID in core_permission_index or NULL to ignore permissions
* @param int|bool|null $includeHiddenItems Include hidden items? NULL to detect if currently logged in member has permission, -1 to return public content only, TRUE to return unapproved content and FALSE to only return unapproved content the viewing member submitted
* @param int $queryFlags Select bitwise flags
* @param Member|null $member The member (NULL to use currently logged in member)
@@ -2807,7 +2833,7 @@ abstract class Item extends Content
* @param array|null $location Array of item lat and long
* @return ActiveRecordIterator|int
*/
public static function getItemsWithPermission( array $where=array(), string $order=NULL, int|array|null $limit=10, string $permissionKey='read', int|bool|null $includeHiddenItems= Filter::FILTER_AUTOMATIC, int $queryFlags=0, ?Member $member=null, bool $joinContainer=FALSE, bool $joinComments=FALSE, bool $joinReviews=FALSE, bool $countOnly=FALSE, ?array $joins=null, bool|Model $skipPermission=FALSE, bool $joinTags=TRUE, bool $joinAuthor=TRUE, bool $joinLastCommenter=TRUE, bool $showMovedLinks=FALSE, ?array $location=null ): ActiveRecordIterator|int
public static function getItemsWithPermission( array $where=array(), string $order=NULL, int|array|null $limit=10, ?string $permissionKey='read', int|bool|null $includeHiddenItems= Filter::FILTER_AUTOMATIC, int $queryFlags=0, ?Member $member=null, bool $joinContainer=FALSE, bool $joinComments=FALSE, bool $joinReviews=FALSE, bool $countOnly=FALSE, ?array $joins=null, bool|Model $skipPermission=FALSE, bool $joinTags=TRUE, bool $joinAuthor=TRUE, bool $joinLastCommenter=TRUE, bool $showMovedLinks=FALSE, ?array $location=null ): ActiveRecordIterator|int
{
/* Are we trying to improve count performance? */
$countShortcut = FALSE;
@@ -2819,7 +2845,7 @@ abstract class Item extends Content
$location['lat'] = number_format( $location['lat'], 6, '.', '' );
$location['lon'] = number_format( $location['lon'], 6, '.', '' );
$where[] = array( static::$databasePrefix . 'latitude' . ' IS NOT NULL AND ' . static::$databasePrefix . 'longitude' . ' IS NOT NULL' );
$where[] = array( static::$databaseTable . '.' . static::$databasePrefix . 'latitude' . ' IS NOT NULL AND ' . static::$databaseTable . '.' . static::$databasePrefix . 'longitude' . ' IS NOT NULL' );
$having = array( 'distance < 500' );
$order = 'distance ASC';
}
@@ -3079,7 +3105,7 @@ abstract class Item extends Content
}
}
$groupBy = ( $joinComments ? static::$databasePrefix . static::$databaseColumnId : NULL );
$groupBy = ( $joinComments ? static::$databaseTable . '.' . static::$databasePrefix . static::$databaseColumnId : NULL );
/* @var $databaseColumnMap array */
/* Build the select clause */
if( $countOnly )
@@ -3213,7 +3239,7 @@ abstract class Item extends Content
if ( isset( $location['lat'] ) and isset( $location['lon'] ) and is_numeric( $location['lat'] ) and is_numeric( $location['lon'] ) )
{
$selectClause .= ', ( 3959 * acos( cos( radians(' . $location['lat'] . ') ) * cos( radians( ' . static::$databasePrefix . 'latitude' . ' ) ) * cos( radians( ' . static::$databasePrefix . 'longitude' . ' ) - radians( ' . $location['lon'] . ' ) ) + sin( radians( ' . $location['lat'] . ' ) ) * sin( radians( ' . static::$databasePrefix . 'latitude' . ') ) ) ) AS distance';
$selectClause .= ', ( 3959 * acos( cos( radians(' . $location['lat'] . ') ) * cos( radians( ' . static::$databaseTable . '.' . static::$databasePrefix . 'latitude' . ' ) ) * cos( radians( ' . static::$databaseTable . '.' . static::$databasePrefix . 'longitude' . ' ) - radians( ' . $location['lon'] . ' ) ) + sin( radians( ' . $location['lat'] . ' ) ) * sin( radians( ' . static::$databaseTable . '.' . static::$databasePrefix . 'latitude' . ') ) ) ) AS distance';
}
if( $joinAuthor and isset( static::$databaseColumnMap['author'] ) )
@@ -5938,7 +5964,7 @@ abstract class Item extends Content
{
if ( !isset( static::$itemCounts[ $_key ] ) )
{
$_count = static::getItemsWithPermission( array( array( static::$databasePrefix . static::$databaseColumnMap['container'] . '=?', $container->_id ) ), NULL, 1, 'read', Filter::FILTER_AUTOMATIC, 0, NULL, FALSE, FALSE, FALSE, TRUE );
$_count = static::getItemsWithPermission( array( array( static::$databaseTable . '.' . static::$databasePrefix . static::$databaseColumnMap['container'] . '=?', $container->_id ) ), NULL, 1, 'read', Filter::FILTER_AUTOMATIC, 0, NULL, FALSE, FALSE, FALSE, TRUE );
$_key = md5( get_class( $container ) . $container->_id );
static::$itemCounts[ $_key ][ $container->_id ] = $_count;
@@ -5966,14 +5992,14 @@ abstract class Item extends Content
$commentClass = static::$commentClass;
/* @var $databaseColumnMap array */
static::$commentCounts[ $_key ] = iterator_to_array( Db::i()->select(
'COUNT(*) AS count, ' . static::$databasePrefix . static::$databaseColumnMap['container'],
'COUNT(*) AS count, ' . static::$databaseTable . '.' . static::$databasePrefix . static::$databaseColumnMap['container'],
$commentClass::$databaseTable,
NULL,
NULL,
NULL,
static::$databasePrefix . static::$databaseColumnMap['container']
)->join( static::$databaseTable, $commentClass::$databasePrefix . $commentClass::$databaseColumnMap['item'] . '=' . static::$databasePrefix . static::$databaseColumnId )
->setKeyField( static::$databasePrefix . static::$databaseColumnMap['container'] )
static::$databaseTable . '.' . static::$databasePrefix . static::$databaseColumnMap['container']
)->join( static::$databaseTable, $commentClass::$databasePrefix . $commentClass::$databaseColumnMap['item'] . '=' . static::$databaseTable . '.' . static::$databasePrefix . static::$databaseColumnId )
->setKeyField( static::$databaseTable . '.' . static::$databasePrefix . static::$databaseColumnMap['container'] )
->setValueField('count') );
}
@@ -5999,14 +6025,14 @@ abstract class Item extends Content
/* @var array $databaseColumnMap */
$reviewClass = static::$commentClass;
static::$reviewCounts[ $_key ] = iterator_to_array( Db::i()->select(
'COUNT(*) AS count, ' . static::$databasePrefix . static::$databaseColumnMap['container'],
'COUNT(*) AS count, ' . static::$databaseTable . '.' . static::$databasePrefix . static::$databaseColumnMap['container'],
$reviewClass::$databaseTable,
NULL,
NULL,
NULL,
static::$databasePrefix . static::$databaseColumnMap['container']
)->join( static::$databaseTable, $reviewClass::$databasePrefix . $reviewClass::$databaseColumnMap['item'] . '=' . static::$databasePrefix . static::$databaseColumnId )
->setKeyField( static::$databasePrefix . static::$databaseColumnMap['container'] )
static::$databaseTable . '.' . static::$databasePrefix . static::$databaseColumnMap['container']
)->join( static::$databaseTable, $reviewClass::$databasePrefix . $reviewClass::$databaseColumnMap['item'] . '=' . static::$databaseTable . '.' . static::$databasePrefix . static::$databaseColumnId )
->setKeyField( static::$databaseTable . '.' . static::$databasePrefix . static::$databaseColumnMap['container'] )
->setValueField('count') );
}
@@ -7129,12 +7155,18 @@ abstract class Item extends Content
if( $member->modPermission('can_manage_deleted_content') AND $this->hidden() == -2 )
{
$restore = new ContentMenuLink( url: $this->url()->csrf()->setQueryString( array( 'do' => 'moderate', 'action' => 'restore' ) ), languageString: 'restore_as_visible', identifier: 'restore' );
$restore->requiresConfirm( 'restore_as_visible_desc' );
$menu->add( $restore );
if( IPS::classUsesTrait( $this, Hideable::class ) and $this->canRestore() )
{
$restore = new ContentMenuLink( url: $this->url()->csrf()->setQueryString( array( 'do' => 'moderate', 'action' => 'restore' ) ), languageString: 'restore_as_visible', identifier: 'restore' );
$restore->requiresConfirm( 'restore_as_visible_desc' );
$menu->add( $restore );
$menu->add( new ContentMenuLink( $this->url()->csrf()->setQueryString( array( 'do' => 'moderate', 'action' => 'restoreAsHidden' ) ), 'restore_as_hidden', identifier: 'restore_hidden' ) );
}
$menu->add( new ContentMenuLink( $this->url()->csrf()->setQueryString( array( 'do' => 'moderate', 'action' => 'restoreAsHidden' ) ), 'restore_as_hidden', identifier: 'restore_hidden' ) );
$menu->add( new ContentMenuLink( $this->url()->csrf()->setQueryString( array( 'do' => 'moderate', 'action' => 'delete', 'immediate' => 1 ) ), 'delete_immediately', identifier: 'delete_immediately' ) );
if( $this->canDelete() )
{
$menu->add( new ContentMenuLink( $this->url()->csrf()->setQueryString( array( 'do' => 'moderate', 'action' => 'delete', 'immediate' => 1 ) ), 'delete_immediately', identifier: 'delete_immediately' ) );
}
}
else
{
@@ -7273,22 +7305,29 @@ abstract class Item extends Content
{
$menu->addSeparator();
$analytics = new ContentMenuLink( url:$this->url()->setQueryString( array( 'do' => 'analytics' ) ), languageString: 'analytics_and_stats' );
$analytics->opensDialog( 'analytics_and_stats', 'large' );
$menu->add( $analytics );
if( IPS::classUsesTrait( $this, Statistics::class ) )
{
$analytics = new ContentMenuLink( url:$this->url()->setQueryString( array( 'do' => 'analytics' ) ), languageString: 'analytics_and_stats' );
$analytics->opensDialog( 'analytics_and_stats', 'large' );
$menu->add( $analytics );
}
$menu->add( new ContentMenuLink( url:$this->url()->setQueryString( array( 'do' => 'modlog' ) ), languageString: 'moderation_history' , opensDialog: true ) );
}
if( $this->canOnMessage( 'add', $member ) )
if( IPS::classUsesTrait( $this, MetaData::class ) )
{
$menu->add( new ContentMenuLink( url: $this->url()->setQueryString( array( 'do' => 'messageForm' ) ), languageString: 'add_message' , opensDialog: true ) );
}
if( $this->canOnMessage( 'add', $member ) )
{
$menu->add( new ContentMenuLink( url: $this->url()->setQueryString( array( 'do' => 'messageForm' ) ), languageString: 'add_message' , opensDialog: true ) );
}
if( $this->canToggleItemModeration( $member ) )
{
$toggle = new ContentMenuLink( url: $this->url()->csrf()->setQueryString( array( 'do' => 'toggleItemModeration' ) ), languageString: $this->itemModerationEnabled() ?'disable_topic_moderation' : 'enable_topic_moderation' );
$toggle->requiresConfirm( $this->itemModerationEnabled() ? 'disable_topic_moderation_confirm' : 'enable_topic_moderation_confirm' );
$menu->add( $toggle );
if( $this->canToggleItemModeration( $member ) )
{
$toggle = new ContentMenuLink( url: $this->url()->csrf()->setQueryString( array( 'do' => 'toggleItemModeration' ) ), languageString: $this->itemModerationEnabled() ?'disable_topic_moderation' : 'enable_topic_moderation' );
$toggle->requiresConfirm( $this->itemModerationEnabled() ? 'disable_topic_moderation_confirm' : 'enable_topic_moderation_confirm' );
$menu->add( $toggle );
}
}
if ( method_exists( $this,'availableSavedActions' )AND $actions = $this->availableSavedActions() )
@@ -7443,7 +7482,7 @@ abstract class Item extends Content
'title' => $this->title ? $this->title : NULL,
'container' => $this->containerWrapper()?->apiOutput( $authorizedMember ),
'author' => $this->author()->apiOutput( $authorizedMember ),
'date' => DateTime::ts( $this->date )->rfc3339(),
'date' => ( isset( static::$databaseColumnMap['date'] ) ? DateTime::ts( $this->mapped( 'date' ) )->rfc3339() : null ),
'content' => $this->content(),
'url' => (string) $this->url()
);