Version 5.0.6
This commit is contained in:
1 parent
a3a4a9ccbd
commit
b89858b2ff
1214 files changed
+92828
-14859
No files matched your search
@@ -16,8 +16,11 @@ namespace IPS\downloads\modules\front\downloads;
|
||||
use DateTimeInterface;
|
||||
use DomainException;
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
use IPS\Application;
|
||||
use IPS\Content\Controller;
|
||||
use IPS\Content\Search\Index;
|
||||
use IPS\Content\Search\SearchContent;
|
||||
use IPS\core\DataLayer;
|
||||
use IPS\core\FrontNavigation;
|
||||
use IPS\DateTime;
|
||||
@@ -25,6 +28,7 @@ use IPS\Db;
|
||||
use IPS\downloads\File as FileClass;
|
||||
use IPS\downloads\File\PendingVersion;
|
||||
use IPS\downloads\Form\LinkedScreenshots;
|
||||
use IPS\Events\Event;
|
||||
use IPS\File;
|
||||
use IPS\File\Iterator;
|
||||
use IPS\Helpers\Form;
|
||||
@@ -55,6 +59,8 @@ use IPS\Session;
|
||||
use IPS\Settings;
|
||||
use IPS\Theme;
|
||||
use IPS\Widget;
|
||||
use LengthException;
|
||||
use LogicException;
|
||||
use OutOfRangeException;
|
||||
use RuntimeException;
|
||||
use UnderflowException;
|
||||
@@ -65,6 +71,7 @@ use function floatval;
|
||||
use function function_exists;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
use function trim;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
@@ -170,6 +177,12 @@ class view extends Controller
|
||||
|
||||
foreach ( new ActiveRecordIterator( Db::i()->select( 'pfd.*', array( 'downloads_cfields', 'pfd' ), NULL, 'pfd.cf_position' ), 'IPS\downloads\Field' ) as $field )
|
||||
{
|
||||
/* Check if the user can view this field */
|
||||
if( !$field->can( 'view' ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if( array_key_exists( 'field_' . $field->id, $this->file->customFields() ) )
|
||||
{
|
||||
if ( $fields[ 'field_' . $field->id ] !== null AND $fields[ 'field_' . $field->id ] !== '' )
|
||||
@@ -700,6 +713,9 @@ class view extends Controller
|
||||
Output::i()->error( 'generic_error', '3D161/M', 500, '' );
|
||||
}
|
||||
|
||||
/* Trigger an event listener */
|
||||
Event::fire( 'onDownload', $file, [ $this->file ] );
|
||||
|
||||
/* Print the file, honoring ranges */
|
||||
try
|
||||
{
|
||||
@@ -1246,6 +1262,7 @@ class view extends Controller
|
||||
else
|
||||
{
|
||||
$noWatermark = NULL;
|
||||
$watermarked = FALSE;
|
||||
if ( Settings::i()->idm_watermarkpath )
|
||||
{
|
||||
try
|
||||
@@ -1255,15 +1272,32 @@ class view extends Controller
|
||||
$image = Image::create( $file->contents() );
|
||||
$image->watermark( $watermark );
|
||||
$file = File::create( 'downloads_Screenshots', $file->originalFilename, $image );
|
||||
$watermarked = TRUE;
|
||||
}
|
||||
catch ( Exception $e ) { }
|
||||
}
|
||||
|
||||
/**
|
||||
* We only need to generate a new thumbnail if we are using watermarking.
|
||||
* If we are not, then we can simply use the previous thumbnail, if this existed previously, rather than generating a new one every time we upload a new version, which is unnecessary extra processing as well as disk usage.
|
||||
* If we are, then it is impossible to know if the watermark has since changed, so we need to go ahead and do it anyway.
|
||||
*/
|
||||
$existing = NULL;
|
||||
if ( $watermarked !== TRUE )
|
||||
{
|
||||
try
|
||||
{
|
||||
/* @note SELECT_FROM_WRITE_SERVER added in c96a0b88e7386e01a6eed39427f2312bc746874f */
|
||||
$existing = Db::i()->select( '*', 'downloads_files_records', array( "record_location=? AND record_file_id=?", (string) $file, $this->file->id ), NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->first();
|
||||
}
|
||||
catch( \UnderflowException $e ) {}
|
||||
}
|
||||
|
||||
Db::i()->insert( 'downloads_files_records', array(
|
||||
'record_file_id' => $this->file->id,
|
||||
'record_type' => 'ssupload',
|
||||
'record_location' => (string) $file,
|
||||
'record_thumb' => (string) $file->thumbnail( 'downloads_Screenshots' ),
|
||||
'record_thumb' => ( $watermarked OR !$existing ) ? (string) $file->thumbnail( 'downloads_Screenshots' ) : $existing['record_thumb'],
|
||||
'record_realname' => $file->originalFilename,
|
||||
'record_size' => $file->filesize(),
|
||||
'record_time' => time(),
|
||||
@@ -1464,6 +1498,78 @@ class view extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Quick edit the record's real name
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function ajaxEditLinkRecordRealName(): void
|
||||
{
|
||||
try
|
||||
{
|
||||
Session::i()->csrfCheck();
|
||||
|
||||
if ( ! $this->file->canEdit() )
|
||||
{
|
||||
throw new RuntimeException;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$record = Db::i()->select( '*', 'downloads_files_records', array( 'record_type=? and record_id=?', 'link', Request::i()->record_id ) )->first();
|
||||
}
|
||||
catch ( UnderflowException $e )
|
||||
{
|
||||
throw new RuntimeException;
|
||||
}
|
||||
|
||||
if ( ! $record['record_file_id'] == $this->file->id )
|
||||
{
|
||||
throw new RuntimeException;
|
||||
}
|
||||
|
||||
$oldTitle = $record['record_realname'];
|
||||
$maxLength = Settings::i()->max_title_length ?: 255;
|
||||
|
||||
if( mb_strlen( Request::i()->newTitle ) > $maxLength )
|
||||
{
|
||||
throw new LengthException( Member::loggedIn()->language()->addToStack( 'form_maxlength', FALSE, array( 'pluralize' => array( $maxLength ) ) ) );
|
||||
}
|
||||
elseif( !trim( Request::i()->newTitle ) )
|
||||
{
|
||||
throw new InvalidArgumentException('form_required');
|
||||
}
|
||||
|
||||
$newTitle = new Text( 'newTitle', Request::i()->newTitle );
|
||||
|
||||
if( $newTitle->validate() !== TRUE )
|
||||
{
|
||||
throw new InvalidArgumentException( Member::loggedIn()->language()->addToStack( 'form_tags_not_allowed', FALSE, array( 'sprintf' => array( Request::i()->newTitle ) ) ) );
|
||||
}
|
||||
|
||||
/* Stop doing anything if the title wasn't changed */
|
||||
if( $oldTitle == $newTitle->value )
|
||||
{
|
||||
Output::i()->json( $oldTitle );
|
||||
}
|
||||
|
||||
/* Update */
|
||||
Db::i()->update( 'downloads_files_records', array( 'record_realname' => $newTitle->value ), array( 'record_id=?', Request::i()->record_id ) );
|
||||
|
||||
Session::i()->modLog( 'modlog__linkedfile_edit_title', array( (string) $this->file->url() => FALSE, $newTitle->value => FALSE, $oldTitle => FALSE ), $this->file );
|
||||
|
||||
Output::i()->json( $newTitle->value );
|
||||
}
|
||||
catch( LogicException $e )
|
||||
{
|
||||
Output::i()->error( $e->getMessage(), '2D161/N', 403, '' );
|
||||
}
|
||||
catch ( Exception $e )
|
||||
{
|
||||
Output::i()->error( 'node_error', '2D161/2', 404, '' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribe Hover
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user