Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -12,23 +12,33 @@
|
||||
namespace IPS\downloads\extensions\core\Dashboard;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DateInterval;
|
||||
use Exception;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\downloads\File;
|
||||
use IPS\Extensions\DashboardAbstract;
|
||||
use IPS\Theme;
|
||||
use function defined;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Dashboard extension: Overview
|
||||
*/
|
||||
class _Overview
|
||||
class Overview extends DashboardAbstract
|
||||
{
|
||||
/**
|
||||
* Can the current user view this dashboard item?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function canView()
|
||||
public function canView(): bool
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
@@ -38,30 +48,30 @@ class _Overview
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBlock()
|
||||
public function getBlock(): string
|
||||
{
|
||||
$oneMonthAgo = \IPS\DateTime::create()->sub( new \DateInterval( 'P1M' ) )->getTimestamp();
|
||||
$oneMonthAgo = DateTime::create()->sub( new DateInterval( 'P1M' ) )->getTimestamp();
|
||||
|
||||
/* Basic stats */
|
||||
$data = array(
|
||||
'total_disk_spaced' => (int) \IPS\Db::i()->select( 'SUM(record_size)', 'downloads_files_records' )->first(),
|
||||
'total_files' => (int) \IPS\Db::i()->select( 'COUNT(*)', 'downloads_files' )->first(),
|
||||
'total_views' => (int) \IPS\Db::i()->select( 'SUM(file_views)', 'downloads_files' )->first(),
|
||||
'total_downloads' => (int) \IPS\Db::i()->select( 'SUM(file_downloads)', 'downloads_files' )->first(),
|
||||
'total_bandwidth' => (int) \IPS\Db::i()->select( 'SUM(dsize)', 'downloads_downloads' )->first(),
|
||||
'current_month_bandwidth' => (int) \IPS\Db::i()->select( 'SUM(dsize)', 'downloads_downloads', array( 'dtime>?', $oneMonthAgo ) )->first(),
|
||||
'total_disk_spaced' => (int) Db::i()->select( 'SUM(record_size)', 'downloads_files_records' )->first(),
|
||||
'total_files' => (int) Db::i()->select( 'COUNT(*)', 'downloads_files' )->first(),
|
||||
'total_views' => (int) Db::i()->select( 'SUM(file_views)', 'downloads_files' )->first(),
|
||||
'total_downloads' => (int) Db::i()->select( 'SUM(file_downloads)', 'downloads_files' )->first(),
|
||||
'total_bandwidth' => (int) Db::i()->select( 'SUM(dsize)', 'downloads_downloads' )->first(),
|
||||
'current_month_bandwidth' => (int) Db::i()->select( 'SUM(dsize)', 'downloads_downloads', array( 'dtime>?', $oneMonthAgo ) )->first(),
|
||||
);
|
||||
|
||||
/* Specific files (will fail if no files yet) */
|
||||
try
|
||||
{
|
||||
$data['largest_file'] = \IPS\downloads\File::constructFromData( \IPS\Db::i()->select( '*', 'downloads_files', NULL, 'file_size DESC', 1 )->first() );
|
||||
$data['most_viewed_file'] = \IPS\downloads\File::constructFromData( \IPS\Db::i()->select( '*', 'downloads_files', NULL, 'file_views DESC', 1 )->first() );
|
||||
$data['most_downloaded_file'] = \IPS\downloads\File::constructFromData( \IPS\Db::i()->select( '*', 'downloads_files', NULL, 'file_downloads DESC', 1 )->first() );
|
||||
$data['largest_file'] = File::constructFromData( Db::i()->select( '*', 'downloads_files', NULL, 'file_size DESC', 1 )->first() );
|
||||
$data['most_viewed_file'] = File::constructFromData( Db::i()->select( '*', 'downloads_files', NULL, 'file_views DESC', 1 )->first() );
|
||||
$data['most_downloaded_file'] = File::constructFromData( Db::i()->select( '*', 'downloads_files', NULL, 'file_downloads DESC', 1 )->first() );
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
catch ( Exception $e ) { }
|
||||
|
||||
/* Display */
|
||||
return \IPS\Theme::i()->getTemplate( 'dashboard', 'downloads' )->overview( $data );
|
||||
return Theme::i()->getTemplate( 'dashboard', 'downloads' )->overview( $data );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user