Version 4.7.23
This commit is contained in:
1 parent
7124a02564
commit
25ddeb65d6
1791 files changed
+76990
-44452
No files matched your search
@@ -12,6 +12,9 @@
|
||||
namespace IPS\downloads;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
|
||||
use IPS\Content\Comment;
|
||||
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
@@ -733,6 +736,7 @@ class _Category extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
{
|
||||
try
|
||||
{
|
||||
/* @note SELECT_FROM_WRITE_SERVER added in c96a0b88e7386e01a6eed39427f2312bc746874f */
|
||||
$file = \IPS\downloads\File::constructFromData( \IPS\Db::i()->select( '*', 'downloads_files', array( 'file_cat=? AND file_open=1', $this->id ), 'file_submitted DESC', 1, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->first() );
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
@@ -746,17 +750,17 @@ class _Category extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
$this->last_file_id = $file->id;
|
||||
$this->last_file_date = $file->submitted;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set last comment
|
||||
*
|
||||
* @param \IPS\Content\Comment|NULL $comment The latest comment or NULL to work it out
|
||||
* @return int
|
||||
* @note We actually want to set the last file info, not the last comment, so we ignore $comment
|
||||
* @param Comment|null $comment The latest comment or NULL to work it out
|
||||
* @param Item|null $updatedItem We sometimes run setLastComment() when an item has been edited, if so, that item will be here
|
||||
* @return void
|
||||
*/
|
||||
public function setLastComment( \IPS\Content\Comment $comment=NULL )
|
||||
public function _setLastComment( \IPS\Content\Comment $comment=NULL, \IPS\Content\Item $updatedItem=NULL )
|
||||
{
|
||||
$this->setLastFile();
|
||||
$this->setLastFile( $updatedItem );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,6 +12,9 @@
|
||||
namespace IPS\downloads;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
|
||||
use IPS\Lang;
|
||||
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
@@ -21,7 +24,7 @@ if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
/**
|
||||
* Field Node
|
||||
*/
|
||||
class _Field extends \IPS\CustomField
|
||||
class _Field extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
{
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
@@ -74,6 +77,30 @@ class _Field extends \IPS\CustomField
|
||||
* @brief [CustomField] Set to TRUE if uploads fields are capable of holding the submitted content for moderation
|
||||
*/
|
||||
public static $uploadsCanBeModerated = TRUE;
|
||||
|
||||
/**
|
||||
* @brief The map of permission columns
|
||||
*/
|
||||
public static $permissionMap = array(
|
||||
'view' => 'view',
|
||||
'edit' => 2,
|
||||
'add' => 3
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief [Node] App for permission index
|
||||
*/
|
||||
public static $permApp = 'downloads';
|
||||
|
||||
/**
|
||||
* @brief [Node] Type for permission index
|
||||
*/
|
||||
public static $permType = 'fields';
|
||||
|
||||
/**
|
||||
* @brief [Node] Prefix string that is automatically prepended to permission matrix language strings
|
||||
*/
|
||||
public static $permissionLangPrefix = 'perm_cfield_';
|
||||
|
||||
/**
|
||||
* @brief [Node] ACP Restrictions
|
||||
@@ -110,6 +137,17 @@ class _Field extends \IPS\CustomField
|
||||
return $this->format;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* [Node] Does the currently logged in user have permission to edit permissions for this node?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function canManagePermissions()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Add/Edit Form
|
||||
*
|
||||
@@ -120,8 +158,9 @@ class _Field extends \IPS\CustomField
|
||||
{
|
||||
parent::form( $form );
|
||||
|
||||
|
||||
|
||||
unset( $form->elements['']['pf_search_type'] );
|
||||
unset( $form->elements['']['pf_search_type_on_off'] );
|
||||
\IPS\Member::loggedIn()->language()->words['field_displayoptions'] = \IPS\Member::loggedIn()->language()->addToStack('pfield_displayoptions');
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'downloads_field_location', $this->id ? $this->display_location : 'below', FALSE, array( 'options' => array( 'sidebar' => 'idm_cfield_sidebar', 'below' => 'idm_cfield_below', 'tab' => 'idm_cfield_tab' ) ), NULL, NULL, NULL, 'idm_field_location' ) );
|
||||
@@ -166,4 +205,28 @@ class _Field extends \IPS\CustomField
|
||||
|
||||
return parent::formatFormValues( $values );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get output for API
|
||||
*
|
||||
* @param \IPS\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 Raw field value from the database
|
||||
* @apiresponse string|int|array|boolean displayValue Parsed Field value with all field data
|
||||
*/
|
||||
public function apiOutput( \IPS\Member $authorizedMember = NULL, $fieldValues=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,
|
||||
'displayValue' => $this->apiValue( $fieldValues[ 'field_' . $this->id ] )
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,10 @@
|
||||
namespace IPS\downloads;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
|
||||
use IPS\Db;
|
||||
use IPS\Patterns\ActiveRecordIterator;
|
||||
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
@@ -673,7 +677,7 @@ class _File extends \IPS\Content\Item implements
|
||||
/* Ignore future versions */
|
||||
$where[] = array( 'record_hidden=?', $pendingVersion );
|
||||
|
||||
$iterator = \IPS\Db::i()->select( 'record_id, record_location, record_thumb, record_no_watermark, record_default, record_type, record_realname, record_size', 'downloads_files_records', $where )->setKeyField( 'record_id' );
|
||||
$iterator = \IPS\Db::i()->select( 'record_id, record_location, record_thumb, record_no_watermark, record_default, record_type, record_realname, record_size', 'downloads_files_records', $where, 'record_time DESC' )->setKeyField( 'record_id' );
|
||||
$iterator = new \IPS\File\Iterator( $iterator, 'downloads_Screenshots', $valueField, FALSE, 'record_realname', $fileSizeField );
|
||||
$iterator = new \CachingIterator( $iterator, \CachingIterator::FULL_CACHE );
|
||||
|
||||
@@ -822,6 +826,7 @@ class _File extends \IPS\Content\Item implements
|
||||
{
|
||||
$return = array();
|
||||
$fields = $this->container()->cfields;
|
||||
$guest = new \IPS\Member;
|
||||
|
||||
if( $topic === TRUE AND $this->_fieldData === NULL )
|
||||
{
|
||||
@@ -1622,6 +1627,13 @@ class _File extends \IPS\Content\Item implements
|
||||
$customFieldValues = $item ? $item->customFields() : array();
|
||||
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' )
|
||||
@@ -1682,6 +1694,11 @@ class _File extends \IPS\Content\Item implements
|
||||
}
|
||||
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 \IPS\Helpers\Form\Upload )
|
||||
{
|
||||
@@ -1755,6 +1772,11 @@ class _File extends \IPS\Content\Item implements
|
||||
$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 \IPS\Helpers\Form\Upload )
|
||||
{
|
||||
@@ -2512,9 +2534,30 @@ class _File extends \IPS\Content\Item implements
|
||||
* @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( \IPS\Member $authorizedMember = NULL, $backup=NULL )
|
||||
{
|
||||
/* 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,
|
||||
@@ -2554,7 +2597,8 @@ class _File extends \IPS\Content\Item implements
|
||||
'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
|
||||
);
|
||||
|
||||
return $return;
|
||||
|
||||
@@ -325,6 +325,7 @@ class _PendingVersion extends \IPS\Content\Item implements \IPS\Content\Hideable
|
||||
public function delete()
|
||||
{
|
||||
$ids = [];
|
||||
/* @note SELECT_FROM_WRITE_SERVER added in pull #6913 "We update record_hidden=0 then delete record_hidden=1 pretty quickly afterwards before the change had propagated to the reader." */
|
||||
foreach( \IPS\Db::i()->select( '*', 'downloads_files_records', [ 'record_file_id=? AND record_hidden=1', $this->file_id ], NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER ) as $record )
|
||||
{
|
||||
switch( $record['record_type'] )
|
||||
@@ -402,11 +403,13 @@ class _PendingVersion extends \IPS\Content\Item implements \IPS\Content\Hideable
|
||||
catch( \Exception $e ){}
|
||||
}
|
||||
|
||||
/* @note SELECT_FROM_WRITE_SERVER race condition */
|
||||
$file->size = \floatval( \IPS\Db::i()->select( 'SUM(record_size)', 'downloads_files_records', array( 'record_file_id=? AND record_type=? AND record_backup=0', $file->id, 'upload' ), NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->first() );
|
||||
|
||||
/* Work out the new primary screenshot */
|
||||
try
|
||||
{
|
||||
/* @note SELECT_FROM_WRITE_SERVER race condition */
|
||||
$file->primary_screenshot = \IPS\Db::i()->select( 'record_id', 'downloads_files_records', array( 'record_file_id=? AND ( record_type=? OR record_type=? ) AND record_backup=0 AND record_hidden=0', $file->id, 'ssupload', 'sslink' ), 'record_default DESC, record_id ASC', NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->first();
|
||||
}
|
||||
catch ( \UnderflowException $e ) { }
|
||||
|
||||
Reference in new issue
Block a user