Version 4.6.0

This commit is contained in:
Neo committed 2025-12-19 05:55:31 -08:00
1 parent f79dcf067a
commit 517a5e1f70
2036 files changed
+110041 -26162

No files matched your search

@@ -27,6 +27,11 @@ class _downloaders extends \IPS\Dispatcher\Controller
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
/**
* @brief Allow MySQL RW separation for efficiency
*/
public static $allowRWSeparation = TRUE;
/**
* @brief Number of results per page
@@ -103,7 +108,17 @@ class _downloaders extends \IPS\Dispatcher\Controller
$total = 0;
}
if( $total )
/* Add the date range button */
\IPS\Output::i()->sidebar['actions'] = array(
'settings' => array(
'title' => 'stats_date_range',
'icon' => 'calendar',
'link' => \IPS\Http\Url::internal( 'app=downloads&module=stats&controller=downloaders&form=1' )->setQueryString( $params ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('stats_date_range') )
)
);
if( $total > 0 )
{
$select = \IPS\Db::i()->select( 'dmid, count(*) as downloads', 'downloads_downloads', $where, 'downloads DESC', array( ( $page - 1 ) * static::PER_PAGE, static::PER_PAGE ), 'dmid' );
$mids = array();
@@ -128,15 +143,6 @@ class _downloaders extends \IPS\Dispatcher\Controller
FALSE
);
\IPS\Output::i()->sidebar['actions'] = array(
'settings' => array(
'title' => 'stats_date_range',
'icon' => 'calendar',
'link' => \IPS\Http\Url::internal( 'app=downloads&module=stats&controller=downloaders&form=1' )->setQueryString( $params ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('stats_date_range') )
)
);
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('stats')->downloadsTable( $select, $pagination, $members );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__downloads_stats_downloaders');
}
@@ -27,6 +27,11 @@ class _downloads extends \IPS\Dispatcher\Controller
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
/**
* @brief Allow MySQL RW separation for efficiency
*/
public static $allowRWSeparation = TRUE;
/**
* Execute
@@ -27,6 +27,11 @@ class _submitters extends \IPS\Dispatcher\Controller
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
/**
* @brief Allow MySQL RW separation for efficiency
*/
public static $allowRWSeparation = TRUE;
/**
* @brief Number of results per page
@@ -103,6 +108,16 @@ class _submitters extends \IPS\Dispatcher\Controller
$total = 0;
}
/* Add the date range button */
\IPS\Output::i()->sidebar['actions'] = array(
'settings' => array(
'title' => 'stats_date_range',
'icon' => 'calendar',
'link' => \IPS\Http\Url::internal( 'app=downloads&module=stats&controller=submitters&form=1' )->setQueryString( $params ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('stats_date_range') )
)
);
if( $total > 0 )
{
$select = \IPS\Db::i()->select( 'file_submitter, count(*) as files', 'downloads_files', $where, 'files DESC', array( ( $page - 1 ) * static::PER_PAGE, static::PER_PAGE ), 'file_submitter' )->join( 'core_members', 'core_members.member_id=downloads_files.file_submitter' );
@@ -127,15 +142,7 @@ class _submitters extends \IPS\Dispatcher\Controller
static::PER_PAGE,
FALSE
);
\IPS\Output::i()->sidebar['actions'] = array(
'settings' => array(
'title' => 'stats_date_range',
'icon' => 'calendar',
'link' => \IPS\Http\Url::internal( 'app=downloads&module=stats&controller=submitters&form=1' )->setQueryString( $params ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('stats_date_range') )
)
);
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global', 'core' )->message( \IPS\Member::loggedIn()->language()->addToStack( 'stats_include_hidden_content' ), 'info' );
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate('stats')->submittersTable( $select, $pagination, $members );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__downloads_stats_submitters');
@@ -0,0 +1,157 @@
<?php
/**
* @brief Top Downloads
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage Downloads
* @since 19 Apr 2021
*/
namespace IPS\downloads\modules\admin\stats;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* topdownloads
*/
class _topdownloads extends \IPS\Dispatcher\Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
/**
* @brief Allow MySQL RW separation for efficiency
*/
public static $allowRWSeparation = TRUE;
/**
* @brief Number of results per page
*/
const PER_PAGE = 25;
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'topdownloads_manage' );
parent::execute();
}
/**
* Manage
*
* @return void
*/
protected function manage()
{
$where = array();
if ( isset( \IPS\Request::i()->form ) )
{
$form = new \IPS\Helpers\Form( 'form', 'go' );
$default = array(
'start' => \IPS\Request::i()->start ? \IPS\DateTime::ts( \IPS\Request::i()->start ) : NULL,
'end' => \IPS\Request::i()->end ? \IPS\DateTime::ts( \IPS\Request::i()->end ) : NULL
);
$form->add( new \IPS\Helpers\Form\DateRange( 'stats_date_range', $default, FALSE, array( 'start' => array( 'max' => \IPS\DateTime::ts( time() )->setTime( 0, 0, 0 ), 'time' => FALSE ), 'end' => array( 'max' => \IPS\DateTime::ts( time() )->setTime( 23, 59, 59 ), 'time' => FALSE ) ) ) );
if ( !$values = $form->values() )
{
\IPS\Output::i()->output = $form;
return;
}
}
/* Figure out start and end parameters for links */
$params = array(
'start' => !empty( $values['stats_date_range']['start'] ) ? $values['stats_date_range']['start']->getTimestamp() : \IPS\Request::i()->start,
'end' => !empty( $values['stats_date_range']['end'] ) ? $values['stats_date_range']['end']->getTimestamp() : \IPS\Request::i()->end
);
if ( $params['start'] )
{
$where[] = array( 'dtime>?', $params['start'] );
}
if ( $params['end'] )
{
$where[] = array( 'dtime<?', $params['end'] );
}
$page = isset( \IPS\Request::i()->page ) ? \intval( \IPS\Request::i()->page ) : 1;
if ( $page < 1 )
{
$page = 1;
}
try
{
$total = \IPS\Db::i()->select( 'COUNT(DISTINCT(dfid))', 'downloads_downloads', $where )->first();
}
catch ( \UnderflowException $e )
{
$total = 0;
}
/* Add date range selector */
\IPS\Output::i()->sidebar['actions'] = array(
'settings' => array(
'title' => 'stats_date_range',
'icon' => 'calendar',
'link' => \IPS\Http\Url::internal( 'app=downloads&module=stats&controller=topdownloads&form=1' )->setQueryString( $params ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack( 'stats_date_range' ) )
)
);
if ( $total > 0 )
{
$select = iterator_to_array( \IPS\Db::i()->select( 'dfid, count(*) as downloads', 'downloads_downloads', $where, 'downloads DESC', array( ( $page - 1 ) * static::PER_PAGE, static::PER_PAGE ), 'dfid' )->join( 'downloads_files', 'downloads_files.file_id=downloads_downloads.dfid' ) );
$files = iterator_to_array( \IPS\Db::i()->select( '*', 'downloads_files', \IPS\Db::i()->in( 'file_id', array_column( $select, 'dfid' ) ) )->setKeyField( 'file_id' ) );
$downloads = array();
if ( \count( $select ) )
{
foreach ( $select as $row )
{
$file = \IPS\downloads\File::constructFromData( $files[ $row['dfid'] ] );
$downloads[] = array(
'dfid' => $row['dfid'],
'downloads' => $row['downloads'],
'file' => \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->basicUrl( $file->url(), TRUE, $file->name )
);
}
}
$pagination = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->pagination(
\IPS\Http\Url::internal( 'app=downloads&module=stats&controller=topdownloads' )->setQueryString( $params ),
ceil( $total / static::PER_PAGE ),
$page,
static::PER_PAGE,
FALSE
);
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global', 'core' )->message( \IPS\Member::loggedIn()->language()->addToStack( 'stats_include_hidden_content' ), 'info' );
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'stats' )->topDownloadsTable( $downloads, $pagination );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'menu__downloads_stats_topdownloads' );
}
else
{
/* Return the no results message */
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global', 'core' )->block( \IPS\Member::loggedIn()->language()->addToStack( 'menu__downloads_stats_topdownloads' ), \IPS\Member::loggedIn()->language()->addToStack( 'no_results' ), FALSE, 'ipsPad', NULL, TRUE );
}
}
}
@@ -100,7 +100,7 @@ class _submit extends \IPS\Dispatcher\Controller
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=downloads&module=downloads&controller=submit&_step=select_category', 'front', 'downloads_submit' ) );
}
if( !$category->can('add') )
if( !$category->can('add') OR !\IPS\Member::loggedIn()->group['idm_max_size'] )
{
\IPS\Output::i()->error( 'add_files_no_perm', '3D286/1', 403, '' );
}
@@ -177,7 +177,7 @@ class _submit extends \IPS\Dispatcher\Controller
if ( $category->bitoptions['allowss'] )
{
$image = TRUE;
if ( $category->maxdims )
if ( $category->maxdims and $category->maxdims != '0x0' )
{
$maxDims = explode( 'x', $category->maxdims );
$image = array( 'maxWidth' => $maxDims[0], 'maxHeight' => $maxDims[1] );
@@ -495,10 +495,17 @@ class _submit extends \IPS\Dispatcher\Controller
if ( $category->bitoptions['allowss'] )
{
$existing[ $key ] = iterator_to_array( new \IPS\File\Iterator( \IPS\Db::i()->select( '*', 'downloads_files_records', array( 'record_post_key=? AND record_type=?', md5( "{$data['postKey']}-{$key}" ), 'ssupload' ) )->setValueField( function( $row ) { return $row['record_no_watermark'] ?: $row['record_location']; } )->setKeyField( function( $row ) { return $row['record_no_watermark'] ?: $row['record_location']; } ), 'downloads_Screenshots' ) );
$image = TRUE;
if ( $category->maxdims and $category->maxdims != '0x0' )
{
$maxDims = explode( 'x', $category->maxdims );
$image = array( 'maxWidth' => $maxDims[0], 'maxHeight' => $maxDims[1] );
}
$form->add( new \IPS\Helpers\Form\Upload( "screenshots_{$key}", $existing[ $key ], ( $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
) ) );
@@ -148,7 +148,7 @@ class _view extends \IPS\Content\Controller
'author' => array(
'@type' => 'Person',
'name' => \IPS\Member::load( $this->file->submitter )->name,
'image' => \IPS\Member::load( $this->file->submitter )->get_photo()
'image' => \IPS\Member::load( $this->file->submitter )->get_photo( TRUE, TRUE )
),
'interactionStatistic' => array(
array(
@@ -314,7 +314,7 @@ class _view extends \IPS\Content\Controller
}
/* Have we accepted the terms? */
if ( $downloadTerms = $this->file->container()->message('disclaimer') and \in_array( $this->file->container()->disclaimer_location, [ 'purchase', 'both'] ) and !isset( \IPS\Request::i()->confirm ) )
if ( $downloadTerms = $this->file->container()->message('disclaimer') and \in_array( $this->file->container()->disclaimer_location, [ 'purchase', 'both' ] ) and !isset( \IPS\Request::i()->confirm ) )
{
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'view' )->purchaseTerms( $this->file, $downloadTerms, $this->file->url('buy')->csrf()->setQueryString( 'confirm', 1 ) );
return;
@@ -401,15 +401,16 @@ class _view extends \IPS\Content\Controller
*/
protected function download()
{
\IPS\Output::i()->metaTags['robots'] = 'noindex';
/* No direct linking check */
if ( \IPS\Settings::i()->idm_antileech )
if ( \IPS\Settings::i()->idm_antileech AND !$this->file->requiresDownloadConfirmation() )
{
if ( !isset( \IPS\Request::i()->csrfKey ) )
{
\IPS\Output::i()->redirect( $this->file->url() );
}
\IPS\Output::i()->metaTags['robots'] = 'noindex';
\IPS\Session::i()->csrfCheck();
}
@@ -453,7 +454,7 @@ class _view extends \IPS\Content\Controller
$files = $this->file->files( isset( \IPS\Request::i()->version ) ? \IPS\Request::i()->version : NULL );
/* Have we accepted the terms? */
if ( $downloadTerms = $category->message('disclaimer') and \in_array( $this->file->container()->disclaimer_location, [ 'download', 'both'] ) and !isset( \IPS\Request::i()->confirm ) )
if ( $downloadTerms = $category->message('disclaimer') and \in_array( $category->disclaimer_location, [ 'download', 'both' ] ) and !isset( \IPS\Request::i()->confirm ) )
{
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'view' )->download( $this->file, $downloadTerms, null, $confirmUrl, \count( $files ) > 1 );
return;
@@ -860,7 +861,7 @@ class _view extends \IPS\Content\Controller
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'front_submit.js', 'downloads', 'front' ) );
/* Permission check */
if ( !$this->file->canEdit() OR $this->file->hasPendingVersion() )
if ( !$this->file->canEdit() OR !$this->file->container()->can('add') OR $this->file->hasPendingVersion() )
{
\IPS\Output::i()->error( 'no_module_permission', '2D161/C', 403, '' );
}
@@ -903,7 +904,7 @@ class _view extends \IPS\Content\Controller
{
$form->add( new \IPS\Helpers\Form\Text( 'file_version', $this->file->version, ( $category->version_numbers == 2 ) ? TRUE : FALSE, array( 'maxLength' => 32 ) ) );
}
$form->add( new \IPS\Helpers\Form\Editor( 'file_changelog', NULL, FALSE, array( 'app' => 'downloads', 'key' => 'Downloads', 'autoSaveKey' => "downloads-{$this->file->id}-changelog", 'allowAttachments' => FALSE ) ) );
$form->add( new \IPS\Helpers\Form\Editor( 'file_changelog', NULL, $category->require_changelog, array( 'app' => 'downloads', 'key' => 'Downloads', 'autoSaveKey' => "downloads-{$this->file->id}-changelog", 'allowAttachments' => FALSE ) ) );
$defaultFiles = iterator_to_array( $this->file->files( NULL, FALSE ) );
if( !$category->multiple_files )
@@ -952,9 +953,16 @@ class _view extends \IPS\Content\Controller
$screenshots[ $this->file->_primary_screenshot ] = array( 'fileurl' => $screenshots[ $this->file->_primary_screenshot ], 'default' => true );
}
$image = TRUE;
if ( $category->maxdims and $category->maxdims != '0x0' )
{
$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,
'retainDeleted' => TRUE,
@@ -1023,6 +1031,7 @@ class _view extends \IPS\Content\Controller
{
$existingRecords = 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, 'upload', 0 ) )->setKeyField('record_id')->setValueField('record_location') ) );
$existingScreenshots = 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, 'ssupload', 0 ) )->setKeyField('record_id')->setValueField('record_location') ) );
$existingThumbnails = array_unique( iterator_to_array( \IPS\Db::i()->select( 'record_id, record_thumb', 'downloads_files_records', array( 'record_file_id=? AND record_type=? AND record_backup=?', $this->file->id, 'ssupload', 0 ) )->setKeyField('record_id')->setValueField('record_thumb') ) );
$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') ) );
}
@@ -1124,6 +1133,11 @@ class _view extends \IPS\Content\Controller
), array( 'record_id=?', $_key ) );
unset( $existingScreenshots[ $key ] );
if( isset( $existingThumbnails[ $key ] ) )
{
unset( $existingThumbnails[ $key ] );
}
}
else
{
@@ -1202,7 +1216,7 @@ class _view extends \IPS\Content\Controller
}
}
$deletions = array( 'records' => array(), 'links' => array() );
$deletions = array( 'records' => array(), 'links' => array(), 'thumbs' => array() );
/* Delete any we're not using anymore */
foreach ( $existingRecords as $recordId => $url )
@@ -1213,11 +1227,13 @@ class _view extends \IPS\Content\Controller
{
$deletions['records'][ $recordId ] = array( 'handler' => 'downloads_Screenshots', 'url' => $url );
}
foreach ( array_merge( $existingLinks, $existingScreenshotLinks ) as $id => $url )
foreach ( ( $existingLinks + $existingScreenshotLinks ) as $id => $url )
{
$deletions['links'][ $id ] = $id;
}
$deletions['thumbs'] = $existingThumbnails;
if( $requireApproval )
{
$fileObj->record_deletions = $deletions;
@@ -1229,6 +1245,15 @@ class _view extends \IPS\Content\Controller
});
$fileObj->deleteRecords( $deletions['links'] );
foreach( $deletions['thumbs'] as $url )
{
try
{
\IPS\File::get( 'downloads_Screenshots', $url )->delete();
}
catch( \Exception $e ){}
}
/* Set the new details */
$fileObj->version = ( isset( $values['file_version'] ) ) ? $values['file_version'] : NULL;
$fileObj->changelog = $values['file_changelog'];