Version 4.1.19

This commit is contained in:
Neo committed 2025-12-19 05:38:56 -08:00
1 parent 28bd025b35
commit 2bd5025018
2674 files changed
+233518 -77766

No files matched your search

@@ -2,9 +2,9 @@
/**
* @brief Browse Files Controller
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Downloads
* @since 08 Oct 2013
* @version SVN_VERSION_NUMBER
@@ -89,10 +89,17 @@ class _browse extends \IPS\Dispatcher\Controller
*/
protected function _category( $category )
{
$_count = \IPS\downloads\File::getItemsWithPermission( array( array( \IPS\downloads\File::$databasePrefix . \IPS\downloads\File::$databaseColumnMap['container'] . '=?', $category->_id ) ), NULL, 1, 'read', NULL, 0, NULL, FALSE, FALSE, FALSE, TRUE );
$_count = \IPS\downloads\File::getItemsWithPermission( array( array( \IPS\downloads\File::$databasePrefix . \IPS\downloads\File::$databaseColumnMap['container'] . '=?', $category->_id ) ), NULL, 1, 'read', \IPS\Content\Hideable::FILTER_AUTOMATIC, 0, NULL, FALSE, FALSE, FALSE, TRUE );
if( !$_count )
{
/* Set breadcrumb */
foreach ( $category->parents() as $parent )
{
\IPS\Output::i()->breadcrumb[] = array( $parent->url(), $parent->_title );
}
\IPS\Output::i()->breadcrumb[] = array( NULL, $category->_title );
/* Show a 'no files' template if there's nothing to display */
$table = \IPS\Theme::i()->getTemplate( 'browse' )->noFiles( $category );
}
@@ -101,6 +108,12 @@ class _browse extends \IPS\Dispatcher\Controller
/* Build table */
$table = new \IPS\Helpers\Table\Content( 'IPS\downloads\File', $category->url(), NULL, $category );
$table->classes = array( 'ipsDataList_large' );
$table->sortOptions = array_merge( $table->sortOptions, array( 'file_downloads' => 'file_downloads' ) );
if ( $table->sortBy === 'file_name' )
{
$table->sortDirection = 'asc';
}
if ( \IPS\Application::appIsEnabled( 'nexus' ) and \IPS\Settings::i()->idm_nexus_on )
{
@@ -119,7 +132,7 @@ class _browse extends \IPS\Dispatcher\Controller
/* Output */
\IPS\Output::i()->title = $category->_title;
\IPS\Output::i()->contextualSearchOptions[ \IPS\Member::loggedIn()->language()->addToStack( 'search_contextual_item', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack( 'category' ) ) ) ) ] = array( 'type' => 'downloads_file', 'nodes' => $category->_id );
\IPS\Output::i()->contextualSearchOptions[ \IPS\Member::loggedIn()->language()->addToStack( 'search_contextual_item_downloads_categories' ) ] = array( 'type' => 'downloads_file', 'nodes' => $category->_id );
\IPS\Output::i()->sidebar['contextual'] = \IPS\Theme::i()->getTemplate( 'browse' )->indexSidebar( \IPS\downloads\Category::canOnAny('add'), $category );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'browse' )->category( $category, (string) $table );
}
@@ -2,9 +2,9 @@
/**
* @brief Submit File Controller
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Downloads
* @since 08 Oct 2013
* @version SVN_VERSION_NUMBER
@@ -49,7 +49,7 @@ class _submit extends \IPS\Dispatcher\Controller
{
$form = new \IPS\Helpers\Form( 'select_category', 'continue' );
$form->class = 'ipsForm_vertical ipsForm_noLabels';
$form->add( new \IPS\Helpers\Form\Node( 'category', isset( $data['category'] ) ? $data['category'] : NULL, TRUE, array(
$form->add( new \IPS\Helpers\Form\Node( 'select_category', isset( \IPS\Request::i()->category ) ? \IPS\Request::i()->category : NULL, TRUE, array(
'url' => \IPS\Http\Url::internal( 'app=downloads&module=downloads&controller=submit', 'front', 'downloads_submit' ),
'class' => 'IPS\downloads\Category',
'permissionCheck' => 'add',
@@ -62,7 +62,7 @@ class _submit extends \IPS\Dispatcher\Controller
if ( $values = $form->values() )
{
$url = \IPS\Http\Url::internal( 'app=downloads&module=downloads&controller=submit&do=submit', 'front', 'downloads_submit' )->setQueryString( 'category', $values['category']->_id );
$url = \IPS\Http\Url::internal( 'app=downloads&module=downloads&controller=submit&do=submit', 'front', 'downloads_submit' )->setQueryString( 'category', $values['select_category']->_id );
if ( isset( $values['bulk'] ) AND $values['bulk'] )
{
$url = $url->setQueryString( 'bulk', '1' );
@@ -168,16 +168,22 @@ class _submit extends \IPS\Dispatcher\Controller
if ( $category->bitoptions['allowss'] )
{
$image = TRUE;
if ( $category->maxdims )
{
$maxDims = explode( 'x', $category->maxdims );
$image = array( 'maxWidth' => $maxDims[0], 'maxHeight' => $maxDims[1] );
}
$form->add( new \IPS\Helpers\Form\Upload( 'screenshots', $screenshots, ( $category->bitoptions['reqss'] and !\IPS\Member::loggedIn()->group['idm_linked_files'] ), array(
'storageExtension' => 'downloads_Screenshots',
'image' => $category->maxssdims ? explode( 'x', $category->maxssdims ) : TRUE,
'image' => $image,
'maxFileSize' => $category->maxss ? ( $category->maxss / 1024 ) : NULL,
'multiple' => TRUE,
'template' => "downloads.submit.screenshot",
) ) );
if ( \IPS\Member::loggedIn()->group['idm_linked_files'] )
{
$form->add( new \IPS\Helpers\Form\Stack( 'url_screenshots', isset( $data['url_screenshots'] ) ? $data['url_screenshots'] : array(), FALSE, array( 'stackFieldType' => 'Url' ), array( 'IPS\downloads\File', 'blacklistCheck' ) ) );
$form->add( new \IPS\downloads\Form\LinkedScreenshots( 'url_screenshots', isset( $data['url_screenshots'] ) ? array( 'values' => $data['url_screenshots'] ) : array(), FALSE, array( 'stackFieldType' => 'Url' ), array( 'IPS\downloads\File', 'blacklistCheck' ) ) );
}
}
@@ -192,7 +198,7 @@ class _submit extends \IPS\Dispatcher\Controller
}
if ( $values = $form->values() )
{
{
/* Check */
if ( empty( $values['files'] ) and empty( $values['url_files'] ) and empty( $values['import_files'] ) )
{
@@ -298,7 +304,7 @@ class _submit extends \IPS\Dispatcher\Controller
'record_location' => (string) $file,
'record_thumb' => (string) $file->thumbnail( 'downloads_Screenshots' ),
'record_realname' => $file->originalFilename,
'record_size' => \strlen( $file->contents() ),
'record_size' => $file->filesize(),
'record_time' => time(),
'record_no_watermark' => $noWatermark,
'record_default' => ( \IPS\Request::i()->screenshots_primary_screenshot AND \IPS\Request::i()->screenshots_primary_screenshot == $_key ) ? 1 : 0
@@ -309,7 +315,7 @@ class _submit extends \IPS\Dispatcher\Controller
}
if ( isset( $values['url_screenshots'] ) )
{
foreach ( $values['url_screenshots'] as $url )
foreach ( $values['url_screenshots'] as $_key => $url )
{
$linkedScreenshots[] = (string) $url;
if ( !isset( $existing[ (string) $url ] ) )
@@ -322,6 +328,7 @@ class _submit extends \IPS\Dispatcher\Controller
'record_realname' => NULL,
'record_size' => 0,
'record_time' => time(),
'record_default' => ( \IPS\Request::i()->screenshots_primary_screenshot AND \IPS\Request::i()->screenshots_primary_screenshot == $_key ) ? 1 : 0
) );
}
unset( $existing[ (string) $url ] );
@@ -486,7 +493,7 @@ class _submit extends \IPS\Dispatcher\Controller
'record_location' => (string) $file,
'record_thumb' => (string) $file->thumbnail( 'downloads_Screenshots' ),
'record_realname' => $file->originalFilename,
'record_size' => \strlen( $file->contents() ),
'record_size' => $file->filesize(),
'record_time' => time(),
'record_no_watermark' => $noWatermark
) );
@@ -2,9 +2,9 @@
/**
* @brief View File Controller
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Downloads
* @since 10 Oct 2013
* @version SVN_VERSION_NUMBER
@@ -40,6 +40,8 @@ class _view extends \IPS\Content\Controller
{
$this->file = \IPS\downloads\File::load( \IPS\Request::i()->id );
/* Downloading does not check 'view' permission, as there is a separate download permission already.
@see https://invisionpower.com/4bugtrack/archived-reports/4092-cant-download-files-when-files-disallowed-to-view-by-any-group-r6975/ */
if ( !$this->file->canView( \IPS\Member::loggedIn() ) and \IPS\Request::i()->do != 'download' )
{
\IPS\Output::i()->error( $this->file->container()->message('npv') ?: 'node_error', '2D161/2', 403, '' );
@@ -84,7 +86,12 @@ class _view extends \IPS\Content\Controller
/* Any previous versions? */
$versionData = array( 'b_version' => $this->file->version, 'b_changelog' => $this->file->changelog, 'b_backup' => $this->file->updated );
$previousVersions = iterator_to_array( \IPS\Db::i()->select( '*', 'downloads_filebackup', array( "b_fileid=?", $this->file->id ), 'b_backup DESC' )->setKeyField( 'b_id' ) );
$versionWhere = array( array( "b_fileid=?", $this->file->id ) );
if ( !\IPS\downloads\File::canViewHiddenItems( NULL, $this->file->container() ) )
{
$versionWhere[] = array( 'b_hidden=0' );
}
$previousVersions = iterator_to_array( \IPS\Db::i()->select( '*', 'downloads_filebackup', $versionWhere, 'b_backup DESC' )->setKeyField( 'b_id' ) );
if ( isset( \IPS\Request::i()->changelog ) and isset( $previousVersions[ \IPS\Request::i()->changelog ] ) )
{
$versionData = $previousVersions[ \IPS\Request::i()->changelog ];
@@ -172,6 +179,10 @@ class _view extends \IPS\Content\Controller
/* Create the item */
$price = $this->file->price();
if ( !$price )
{
\IPS\Output::i()->error( 'file_no_price_for_currency', '1D161/H', 403, '' );
}
$item = new \IPS\downloads\extensions\nexus\Item\File( $this->file->name, $price );
$item->id = $this->file->id;
try
@@ -186,13 +197,14 @@ class _view extends \IPS\Content\Controller
$item->renewalTerm = $this->file->renewalTerm();
$item->payTo = $this->file->author();
$item->commission = \IPS\Settings::i()->idm_nexus_percent;
if ( $fees = json_decode( \IPS\Settings::i()->idm_nexus_transfee, TRUE ) )
if ( $fees = json_decode( \IPS\Settings::i()->idm_nexus_transfee, TRUE ) and isset( $fees[ $price->currency ] ) )
{
$item->fee = new \IPS\nexus\Money( $fees[ $price->currency ]['amount'], $price->currency );
}
/* Generate the invoice */
$invoice = new \IPS\nexus\Invoice;
$invoice->currency = ( isset( $_SESSION['currency'] ) and in_array( $_SESSION['currency'], \IPS\nexus\Money::currencies() ) ) ? $_SESSION['currency'] : \IPS\nexus\Customer::loggedIn()->defaultCurrency();
$invoice->member = \IPS\nexus\Customer::loggedIn();
$invoice->addItem( $item );
$invoice->return_uri = "app=downloads&module=downloads&controller=view&id={$this->file->id}";
@@ -324,19 +336,17 @@ class _view extends \IPS\Content\Controller
}
/* Log */
if ( $category->log !== 0 )
$_log = true;
if( isset( $_SERVER['HTTP_RANGE'] ) )
{
$_log = true;
if( isset( $_SERVER['HTTP_RANGE'] ) )
if( !\IPS\Http\Ranges::isStartOfFile() )
{
if( !\IPS\Http\Ranges::isStartOfFile() )
{
$_log = false;
}
$_log = false;
}
if( $_log )
}
if( $_log )
{
if ( $category->log !== 0 )
{
\IPS\Db::i()->insert( 'downloads_downloads', array(
'dfid' => $this->file->id,
@@ -348,10 +358,10 @@ class _view extends \IPS\Content\Controller
'dbrowsers' => \IPS\Session::i()->userAgent->useragentKey,
'dos' => ''
) );
$this->file->downloads++;
$this->file->save();
}
$this->file->downloads++;
$this->file->save();
}
if ( \IPS\Application::appIsEnabled( 'nexus' ) and \IPS\Settings::i()->idm_nexus_on and ( $this->file->cost or $this->file->nexus ) )
{
@@ -391,7 +401,7 @@ class _view extends \IPS\Content\Controller
\IPS\Output::i()->error( 'downloads_no_file', '3D161/G', 404, '' );
}
/* Log session */
$downloadSessionId = md5( uniqid( microtime(), true ) );
$downloadSessionId = \IPS\Login::generateRandomString();
\IPS\Db::i()->insert( 'downloads_sessions', array(
'dsess_id' => $downloadSessionId,
'dsess_mid' => (int) \IPS\Member::loggedIn()->member_id,
@@ -402,6 +412,12 @@ class _view extends \IPS\Content\Controller
register_shutdown_function( function() use( $downloadSessionId ) {
\IPS\Db::i()->delete( 'downloads_sessions', array( 'dsess_id=?', $downloadSessionId ) );
} );
/* If it's an AWS file just redirect to it */
if ( $file instanceof \IPS\File\Amazon )
{
\IPS\Output::i()->redirect( $file->generateTemporaryDownloadUrl() );
}
/* Print the file, honoring ranges */
$ranges = new \IPS\Http\Ranges( $file, (int) \IPS\Member::loggedIn()->group['idm_throttling'] );
@@ -428,6 +444,8 @@ class _view extends \IPS\Content\Controller
{
\IPS\Output::i()->error( 'no_module_permission', '2D161/5', 403, '' );
}
\IPS\Session::i()->csrfCheck();
/* Load the desired version */
try
@@ -503,6 +521,8 @@ class _view extends \IPS\Content\Controller
{
\IPS\Output::i()->error( 'no_module_permission', '2D161/8', 403, '' );
}
\IPS\Session::i()->csrfCheck();
/* Load the desired version */
try
@@ -536,6 +556,11 @@ class _view extends \IPS\Content\Controller
{
\IPS\Output::i()->error( 'no_module_permission', '2D161/9', 403, '' );
}
\IPS\Session::i()->csrfCheck();
/* Make sure the user confirmed the deletion */
\IPS\Request::i()->confirmedDelete();
/* Load the desired version */
try
@@ -546,9 +571,26 @@ class _view extends \IPS\Content\Controller
{
\IPS\Output::i()->error( 'node_error', '2D161/A', 404, '' );
}
/* Base file iterator */
$fileIterator = function( $recordType, $storageExtension ) use( $version )
{
return new \IPS\File\Iterator(
\IPS\Db::i()->select(
'record_location', 'downloads_files_records', array(
array( 'record_type=?', $recordType ),
\IPS\Db::i()->in( 'record_id', explode( ',', $version['b_records'] ) ),
array( 'record_location NOT IN (?)', \IPS\Db::i()->select(
'record_location', 'downloads_files_records', array( 'record_type=?', $recordType ), NULL,
NULL, 'record_location', 'COUNT(*) > 1'
) )
)
), $storageExtension
);
};
/* Delete */
foreach ( new \IPS\File\Iterator( \IPS\Db::i()->select( 'record_location', 'downloads_files_records', array( array( 'record_type=?', 'upload' ), \IPS\Db::i()->in( 'record_id', explode( ',', $version['b_records'] ) ) ) ), 'downloads_Files' ) as $file )
foreach ( $fileIterator( 'upload', 'downloads_Files' ) as $file )
{
try
{
@@ -556,7 +598,8 @@ class _view extends \IPS\Content\Controller
}
catch ( \Exception $e ) { }
}
foreach ( new \IPS\File\Iterator( \IPS\Db::i()->select( 'record_location', 'downloads_files_records', array( array( 'record_type=?', 'ssupload' ), \IPS\Db::i()->in( 'record_id', explode( ',', $version['b_records'] ) ) ) ), 'downloads_Screenshots' ) as $file )
foreach ( $fileIterator( 'ssupload', 'downloads_Screenshots' ) as $file )
{
try
{
@@ -624,7 +667,7 @@ class _view extends \IPS\Content\Controller
}
$form->add( new \IPS\Helpers\Form\Text( 'file_version', $this->file->version, ( $category->versioning !== 0 ), array( 'maxLength' => 32 ) ) );
$form->add( new \IPS\Helpers\Form\Editor( 'file_changelog', $this->file->changelog, FALSE, array( 'app' => 'downloads', 'key' => 'Downloads', 'autoSaveKey' => "downloads-{$this->file->id}-changelog", 'attachIds' => array( $this->file->id ) ) ) );
$form->add( new \IPS\Helpers\Form\Editor( 'file_changelog', $this->file->changelog, FALSE, array( 'app' => 'downloads', 'key' => 'Downloads', 'autoSaveKey' => "downloads-{$this->file->id}-changelog") ) );
$form->addHeader( 'upload_files' );
$form->add( new \IPS\Helpers\Form\Upload( 'files', iterator_to_array( $this->file->files( NULL, FALSE ) ), ( !\IPS\Member::loggedIn()->group['idm_linked_files'] and !\IPS\Member::loggedIn()->group['idm_import_files'] ), array( 'storageExtension' => 'downloads_Files', 'allowedFileTypes' => $category->types, 'maxFileSize' => $category->maxfile ? ( $category->maxfile / 1024 ) : NULL, 'multiple' => TRUE, 'retainDeleted' => TRUE ) ) );
@@ -670,7 +713,12 @@ class _view extends \IPS\Content\Controller
if ( \IPS\Member::loggedIn()->group['idm_linked_files'] )
{
$form->add( new \IPS\Helpers\Form\Stack( 'url_screenshots', iterator_to_array( \IPS\Db::i()->select( 'record_location', 'downloads_files_records', array( 'record_file_id=? AND record_type=? AND record_backup=0', $this->file->id, 'sslink' ) ) ), FALSE, array( 'stackFieldType' => 'Url' ), array( 'IPS\downloads\File', 'blacklistCheck' ) ) );
//iterator_to_array( \IPS\Db::i()->select( 'record_location', 'downloads_files_records', array( 'record_file_id=? AND record_type=? AND record_backup=0', $this->file->id, 'sslink' ) ) )
//
$form->add( new \IPS\downloads\Form\LinkedScreenshots( 'url_screenshots', array(
'values' => iterator_to_array( \IPS\Db::i()->select( 'record_id, record_location', 'downloads_files_records', array( 'record_file_id=? AND record_type=? AND record_backup=0', $this->file->id, 'sslink' ) )->setKeyField('record_id')->setValueField('record_location') ),
'default' => $this->file->_primary_screenshot
), FALSE, array( 'IPS\downloads\File', 'blacklistCheck' ) ) );
}
}
@@ -679,7 +727,7 @@ class _view extends \IPS\Content\Controller
/* Handle submissions */
if ( $values = $form->values() )
{
{
/* Check */
if ( empty( $values['files'] ) and empty( $values['url_files'] ) and empty( $values['import_files'] ) )
{
@@ -701,51 +749,14 @@ class _view extends \IPS\Content\Controller
$existingScreenshotLinks = array();
if ( $category->versioning !== 0 and ( !\IPS\Member::loggedIn()->group['idm_bypass_revision'] or $values['file_save_revision'] ) )
{
/* Move the old details into a backup record */
\IPS\Db::i()->insert( 'downloads_filebackup', array(
'b_fileid' => $this->file->id,
'b_filetitle' => $this->file->name,
'b_filedesc' => $this->file->desc,
'b_hidden' => FALSE,
'b_backup' => $this->file->updated,
'b_updated' => time(),
'b_records' => implode( ',', iterator_to_array( \IPS\Db::i()->select( 'record_id', 'downloads_files_records', array( 'record_file_id=? AND record_backup=0', $this->file->id ) ) ) ),
'b_version' => $this->file->version,
'b_changelog' => $this->file->changelog,
) );
/* Set the old records to be backups */
\IPS\Db::i()->update( 'downloads_files_records', array( 'record_backup' => TRUE ), array( 'record_file_id=? AND record_backup=0', $this->file->id ) );
/* Delete any old versions we no longer keep */
if ( $category->versioning !== NULL )
{
$count = \IPS\Db::i()->select( 'COUNT(*)', 'downloads_filebackup', array( 'b_fileid=?', $this->file->id ) )->first();
if ( ( $count - $category->versioning + 1 ) > 0 )
{
foreach ( \IPS\Db::i()->select( '*', 'downloads_filebackup', array( 'b_fileid=?', $this->file->id ), 'b_backup ASC', $count - $category->versioning + 1 ) as $backUp )
{
foreach ( \IPS\Db::i()->select( '*', 'downloads_files_records', \IPS\Db::i()->in( 'record_id', explode( ',', $backUp['b_records'] ) ) ) as $k => $file )
{
try
{
$file = \IPS\File::get( $file['record_type'] == 'upload' ? 'downloads_Files' : 'downloads_Screenshots', $file['record_location'] )->delete();
}
catch ( \Exception $e ) { }
}
\IPS\Db::i()->delete( 'downloads_files_records', \IPS\Db::i()->in( 'record_id', explode( ',', $backUp['b_records'] ) ) );
\IPS\Db::i()->delete( 'downloads_filebackup', array( 'b_id=?', $backUp['b_id'] ) );
}
}
}
$this->file->saveVersion();
}
else
{
$existingRecords = array_unique( iterator_to_array( \IPS\Db::i()->select( 'record_location', 'downloads_files_records', array( 'record_file_id=? AND record_type=?', $this->file->id, 'upload' ) ) ) );
$existingScreenshots = array_unique( iterator_to_array( \IPS\Db::i()->select( 'record_location', 'downloads_files_records', array( 'record_file_id=? AND record_type=?', $this->file->id, 'ssupload' ) ) ) );
$existingLinks = array_unique( iterator_to_array( \IPS\Db::i()->select( 'record_id, record_location', 'downloads_files_records', array( 'record_file_id=? AND record_type=?', $this->file->id, 'link' ) )->setKeyField('record_id')->setValueField('record_location') ) );
$existingScreenshotLinks = array_unique( iterator_to_array( \IPS\Db::i()->select( 'record_id, record_location', 'downloads_files_records', array( 'record_file_id=? AND record_type=?', $this->file->id, 'sslink' ) )->setKeyField('record_id')->setValueField('record_location') ) );
$existingRecords = array_unique( iterator_to_array( \IPS\Db::i()->select( 'record_location', 'downloads_files_records', array( 'record_file_id=? AND record_type=? AND record_backup=?', $this->file->id, 'upload', 0 ) ) ) );
$existingScreenshots = array_unique( iterator_to_array( \IPS\Db::i()->select( 'record_location', 'downloads_files_records', array( 'record_file_id=? AND record_type=? AND record_backup=?', $this->file->id, 'ssupload', 0 ) ) ) );
$existingLinks = array_unique( iterator_to_array( \IPS\Db::i()->select( 'record_id, record_location', 'downloads_files_records', array( 'record_file_id=? AND record_type=? AND record_backup=?', $this->file->id, 'link', 0 ) )->setKeyField('record_id')->setValueField('record_location') ) );
$existingScreenshotLinks = array_unique( iterator_to_array( \IPS\Db::i()->select( 'record_id, record_location', 'downloads_files_records', array( 'record_file_id=? AND record_type=? AND record_backup=?', $this->file->id, 'sslink', 0 ) )->setKeyField('record_id')->setValueField('record_location') ) );
}
/* Insert the new records */
@@ -831,6 +842,10 @@ class _view extends \IPS\Content\Controller
$key = array_search( (string) $file, $existingScreenshots );
if ( $key !== FALSE )
{
\IPS\Db::i()->update( 'downloads_files_records', array(
'record_default' => ( \IPS\Request::i()->screenshots_primary_screenshot AND \IPS\Request::i()->screenshots_primary_screenshot == $_key ) ? 1 : 0
), array( 'record_id=?', $_key ) );
unset( $existingScreenshots[ $key ] );
}
else
@@ -866,11 +881,14 @@ class _view extends \IPS\Content\Controller
if ( isset( $values['url_screenshots'] ) )
{
foreach ( $values['url_screenshots'] as $url )
foreach ( $values['url_screenshots'] as $_key => $url )
{
$key = array_search( (string) $file, $existingScreenshotLinks );
if ( $key !== FALSE )
{
\IPS\Db::i()->update( 'downloads_files_records', array(
'record_default' => ( \IPS\Request::i()->screenshots_primary_screenshot AND \IPS\Request::i()->screenshots_primary_screenshot == $_key ) ? 1 : 0
), array( 'record_id=?', $_key ) );
unset( $existingScreenshotLinks[ $key ] );
}
else
@@ -882,6 +900,7 @@ class _view extends \IPS\Content\Controller
'record_realname' => NULL,
'record_size' => 0,
'record_time' => time(),
'record_default' => ( \IPS\Request::i()->screenshots_primary_screenshot AND \IPS\Request::i()->screenshots_primary_screenshot == $_key ) ? 1 : 0
) );
}
}
@@ -925,7 +944,7 @@ class _view extends \IPS\Content\Controller
/* Work out the new primary screenshot */
try
{
$this->file->primary_screenshot = \IPS\Db::i()->select( 'record_id', 'downloads_files_records', array( 'record_file_id=? AND record_type=? AND record_backup=0', $this->file->id, 'ssupload' ), 'record_default DESC, record_id ASC' )->first();
$this->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', $this->file->id, 'ssupload', 'sslink' ), 'record_default DESC, record_id ASC' )->first();
}
catch ( \UnderflowException $e ) { }
@@ -945,6 +964,8 @@ class _view extends \IPS\Content\Controller
$this->file->sendUpdateNotifications();
}
$this->file->processAfterNewVersion( $values );
/* Boink */
\IPS\Output::i()->redirect( $this->file->url() );
}