Version 5.0.6
This commit is contained in:
1 parent
a3a4a9ccbd
commit
b89858b2ff
1214 files changed
+92828
-14859
No files matched your search
@@ -958,7 +958,7 @@ class Category extends Model implements Permissions
|
||||
* @param Club $club
|
||||
* @return void
|
||||
*/
|
||||
public function clubForm( Form $form, Club $club ) : void
|
||||
public function _clubForm( Form $form, Club $club ) : void
|
||||
{
|
||||
/* @var File $itemClass */
|
||||
$itemClass = static::$contentItemClass;
|
||||
|
||||
@@ -19,7 +19,9 @@ use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Radio;
|
||||
use IPS\Helpers\Form\TextArea;
|
||||
use IPS\Helpers\Form\YesNo;
|
||||
use IPS\Lang;
|
||||
use IPS\Member;
|
||||
use IPS\Node\Permissions;
|
||||
use IPS\Settings;
|
||||
use function defined;
|
||||
|
||||
@@ -32,7 +34,7 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
/**
|
||||
* Field Node
|
||||
*/
|
||||
class Field extends CustomField
|
||||
class Field extends CustomField implements Permissions
|
||||
{
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
@@ -85,6 +87,30 @@ class Field extends CustomField
|
||||
* @brief [CustomField] Set to TRUE if uploads fields are capable of holding the submitted content for moderation
|
||||
*/
|
||||
public static bool $uploadsCanBeModerated = TRUE;
|
||||
|
||||
/**
|
||||
* @brief The map of permission columns
|
||||
*/
|
||||
public static array $permissionMap = array(
|
||||
'view' => 'view',
|
||||
'edit' => 2,
|
||||
'add' => 3
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief [Node] App for permission index
|
||||
*/
|
||||
public static ?string $permApp = 'downloads';
|
||||
|
||||
/**
|
||||
* @brief [Node] Type for permission index
|
||||
*/
|
||||
public static ?string $permType = 'fields';
|
||||
|
||||
/**
|
||||
* @brief [Node] Prefix string that is automatically prepended to permission matrix language strings
|
||||
*/
|
||||
public static string $permissionLangPrefix = 'perm_cfield_';
|
||||
|
||||
/**
|
||||
* @brief [Node] ACP Restrictions
|
||||
@@ -121,6 +147,17 @@ class Field extends CustomField
|
||||
return $this->format;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* [Node] Does the currently logged-in user have permission to edit permissions for this node?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function canManagePermissions() : bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Add/Edit Form
|
||||
*
|
||||
@@ -178,4 +215,26 @@ class Field extends CustomField
|
||||
|
||||
return parent::formatFormValues( $values );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get output for API
|
||||
*
|
||||
* @param Member|NULL $authorizedMember The member making the API request or NULL for API Key / client_credentials
|
||||
* @param array $fieldValues Current values for a specific file
|
||||
* @return array
|
||||
* @apiresponse int id ID number
|
||||
* @apiresponse string name Name
|
||||
* @apiresponse string description Description
|
||||
* @apiresponse string value Current value for this file
|
||||
*/
|
||||
public function apiOutput( ?Member $authorizedMember = NULL, array $fieldValues=array() ): array
|
||||
{
|
||||
$lang = $authorizedMember ? $authorizedMember->language() : Lang::load( Lang::defaultLanguage() );
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $lang->addToStack( 'downloads_field_' . $this->id ),
|
||||
'description' => $lang->addToStack( 'downloads_field_' . $this->id . '_desc' ),
|
||||
'value' => $fieldValues[ 'field_' . $this->id ] ?? null
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1036,7 +1036,7 @@ Filter
|
||||
* @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)
|
||||
@@ -1053,7 +1053,7 @@ Filter
|
||||
* @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|null $joins=null, bool|Model $skipPermission=FALSE, bool $joinTags=TRUE, bool $joinAuthor=TRUE, bool $joinLastCommenter=TRUE, bool $showMovedLinks=FALSE, array|null $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|null $joins=null, bool|Model $skipPermission=FALSE, bool $joinTags=TRUE, bool $joinAuthor=TRUE, bool $joinLastCommenter=TRUE, bool $showMovedLinks=FALSE, array|null $location=null ): ActiveRecordIterator|int
|
||||
{
|
||||
$member = $member ?: Member::loggedIn();
|
||||
if ( !$member->isAdmin() )
|
||||
@@ -1625,7 +1625,7 @@ Filter
|
||||
|
||||
Member::loggedIn()->language()->words['file_cost_desc'] = $commissionBlurb;
|
||||
|
||||
$return['file_cost'] = new FormMoney( "{$bulkKey}file_cost", $item ? json_decode( $item->cost, TRUE ) : array(), NULL, array(), function( $val ) use ( $minimums, $bulkKey ) {
|
||||
$return['file_cost'] = new FormMoney( "{$bulkKey}file_cost", ( $item and $item->cost )? json_decode( $item->cost, TRUE ) : array(), NULL, array(), function( $val ) use ( $minimums, $bulkKey ) {
|
||||
foreach( $val as $currency => $money )
|
||||
{
|
||||
if( isset( $minimums[ $currency ]['amount'] ) AND $money->amount->compare( new Number( $minimums[ $currency ]['amount'] ) ) === -1 )
|
||||
@@ -1663,6 +1663,13 @@ Filter
|
||||
{
|
||||
foreach ( $container->cfields as $k => $field )
|
||||
{
|
||||
/* Does the user have permission to enter data into this field? */
|
||||
$perm = $item ? 'edit' : 'add';
|
||||
if( !$field->can( $perm ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$_id = $field->id;
|
||||
$field->id = "{$bulkKey}{$field->id}";
|
||||
if ( $field->type === 'Editor' )
|
||||
@@ -1724,6 +1731,11 @@ Filter
|
||||
}
|
||||
foreach ( $this->container()->cfields as $field )
|
||||
{
|
||||
if( !array_key_exists( "downloads_field_{$field->id}", $values ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$helper = $field->buildHelper( NULL, NULL, $new ? NULL : $this );
|
||||
if ( $helper instanceof Upload )
|
||||
{
|
||||
@@ -1797,6 +1809,11 @@ Filter
|
||||
$cfields = array();
|
||||
foreach ( $this->container()->cfields as $field )
|
||||
{
|
||||
if( !array_key_exists( "downloads_field_{$field->id}", $values ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$helper = $field->buildHelper( NULL, NULL, $new ? NULL : $this );
|
||||
if ( $helper instanceof Upload )
|
||||
{
|
||||
@@ -2136,7 +2153,7 @@ Filter
|
||||
{
|
||||
if ( !in_array( $file['record_location'], $locations ) )
|
||||
{
|
||||
$file = SystemFile::get( $file['record_type'] == 'upload' ? 'downloads_Files' : 'downloads_Screenshots', $file['record_location'] )->delete();
|
||||
SystemFile::get( $file['record_type'] == 'upload' ? 'downloads_Files' : 'downloads_Screenshots', $file['record_location'] )->delete();
|
||||
}
|
||||
}
|
||||
catch ( Exception $e ) { }
|
||||
@@ -2149,7 +2166,7 @@ Filter
|
||||
{
|
||||
if ( !in_array( $file['record_thumb'], $thumbs ) )
|
||||
{
|
||||
$file = SystemFile::get( 'downloads_Screenshots', $file['record_thumb'] )->delete();
|
||||
SystemFile::get( 'downloads_Screenshots', $file['record_thumb'] )->delete();
|
||||
}
|
||||
}
|
||||
catch ( Exception $e ) { }
|
||||
@@ -2161,7 +2178,7 @@ Filter
|
||||
{
|
||||
if ( !in_array( $file['record_no_watermark'], $watermarks ) )
|
||||
{
|
||||
$file = SystemFile::get( 'downloads_Screenshots', $file['record_no_watermark'] )->delete();
|
||||
SystemFile::get( 'downloads_Screenshots', $file['record_no_watermark'] )->delete();
|
||||
}
|
||||
}
|
||||
catch ( Exception $e ) { }
|
||||
@@ -2494,9 +2511,29 @@ Filter
|
||||
* @apiresponse int purchases Number of purchases
|
||||
* @apiresponse array renewalTerm File renewal term
|
||||
* @apiresponse bool hasPendingVersion Whether file has a new version pending. Will be NULL for client requests where the authorized member cannot upload new versions.
|
||||
* @apiresponse [\IPS\downloads\Field] customFields Custom field values for this file
|
||||
*/
|
||||
public function apiOutput( ?Member $authorizedMember = NULL, ?array $backup=NULL ) : array
|
||||
{
|
||||
/* Figure out custom fields if any */
|
||||
$fields = array();
|
||||
try
|
||||
{
|
||||
$fieldValues = Db::i()->select( '*', 'downloads_ccontent', [ 'file_id=?', $this->id ] )->first();
|
||||
|
||||
foreach( new ActiveRecordIterator(
|
||||
Db::i()->select( '*', 'downloads_cfields', null, 'cf_position' ),
|
||||
Field::class
|
||||
) as $field )
|
||||
{
|
||||
if( !$authorizedMember or $field->canView( $authorizedMember ) )
|
||||
{
|
||||
$fields[ $field->id ] = $field->apiOutput( $authorizedMember, $fieldValues );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( UnderflowException $e ) { }
|
||||
|
||||
return array(
|
||||
'id' => $this->id,
|
||||
'title' => $backup ? $backup['b_filetitle'] : $this->name,
|
||||
@@ -2536,7 +2573,8 @@ Filter
|
||||
'rating' => $this->averageReviewRating(),
|
||||
'purchases' => $this->purchaseCount(),
|
||||
'renewalTerm' => $this->isPaid() ? $this->renewalTerm() : NULL,
|
||||
'hasPendingVersion' => ( !$authorizedMember OR $this->canEdit( $authorizedMember ) ) ? $this->hasPendingVersion() : NULL
|
||||
'hasPendingVersion' => ( !$authorizedMember OR $this->canEdit( $authorizedMember ) ) ? $this->hasPendingVersion() : NULL,
|
||||
'customFields' => $fields
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2660,6 +2698,12 @@ Filter
|
||||
/* Run the parent so that we are sure everything is properly synched */
|
||||
$this->_syncTopic();
|
||||
|
||||
/* Stop here if we're not including screenshots */
|
||||
if( !$this->container()->bitoptions['topic_screenshot'] )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if( $screenshot = $this->primary_screenshot_thumb )
|
||||
{
|
||||
/* Now we need to copy the primary screenshot as an attachment to the first post */
|
||||
@@ -2676,9 +2720,24 @@ Filter
|
||||
{
|
||||
try
|
||||
{
|
||||
SystemFile::get( 'forums_Forums', $row['attach_location'] )->delete();
|
||||
/* Due to an older bug in 5.0.0 B9, attachment files can match the exact filename of a downloads record, so we won't want to delete if there's a match there */
|
||||
$existsAlready = Db::i()->select( '*', 'downloads_files_records', [ 'record_location=? or record_thumb=?', $row['attach_location'], $row['attach_location'] ] )->first();
|
||||
}
|
||||
catch( \UnderflowException )
|
||||
{
|
||||
$existsAlready = false;
|
||||
}
|
||||
|
||||
if ( $existsAlready === false )
|
||||
{
|
||||
/* Nothing found so proceed */
|
||||
try
|
||||
{
|
||||
|
||||
SystemFile::get( 'forums_Forums', $row['attach_location'] )->delete();
|
||||
}
|
||||
catch( Exception ){}
|
||||
}
|
||||
catch( Exception ){}
|
||||
|
||||
$delete[] = $row['attach_id'];
|
||||
}
|
||||
@@ -2695,9 +2754,7 @@ Filter
|
||||
{
|
||||
/* Copy the screenshot and generate an attachment */
|
||||
/* @var SystemFile $screenshot */
|
||||
$settings = json_decode( Settings::i()->upload_settings, true );
|
||||
$storageConfiguration = $settings['filestorage__core_Attachment'];
|
||||
$copy = $screenshot->copy( $storageConfiguration );
|
||||
$copy = $screenshot->duplicate();
|
||||
|
||||
$attachment = $copy->makeAttachment( md5( uniqid() ), $topic->author() );
|
||||
|
||||
|
||||
Reference in new issue
Block a user