Version 4.0.13.1
This commit is contained in:
1 parent
f9e857d255
commit
c6a86f0d9b
7517 files changed
+597400
-668041
No files matched your search
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Categories
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Downloads
|
||||
* @since 27 Sep 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\downloads\modules\admin\downloads;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Categories
|
||||
*/
|
||||
class _categories extends \IPS\Node\Controller
|
||||
{
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = 'IPS\downloads\Category';
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'categories_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Recalculate Downloads
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function recountDownloads()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'categories_recount_downloads' );
|
||||
|
||||
try
|
||||
{
|
||||
$category = \IPS\downloads\Category::load( \IPS\Request::i()->id );
|
||||
|
||||
\IPS\Db::i()->update( 'downloads_files', array( 'file_downloads' => \IPS\Db::i()->select( 'COUNT(*)', 'downloads_downloads', array( 'dfid=file_id' ) ) ), array( 'file_cat=?', $category->id ) );
|
||||
\IPS\Session::i()->log( 'acplogs__downloads_recount_downloads', array( $category->_title => FALSE ) );
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=downloads&module=downloads&controller=categories&do=form&id=" . \IPS\Request::i()->id ), 'clog_recount_done' );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2D180/1', 404, '' );
|
||||
}
|
||||
}
|
||||
|
||||
protected function form()
|
||||
{
|
||||
parent::form();
|
||||
|
||||
if ( \IPS\Request::i()->id )
|
||||
{
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('edit_category') . ': ' . \IPS\Output::i()->title;
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('add_category');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief fields
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Downloads
|
||||
* @since 03 Oct 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\downloads\modules\admin\downloads;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* fields
|
||||
*/
|
||||
class _fields extends \IPS\Node\Controller
|
||||
{
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = 'IPS\downloads\Field';
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'fields_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Settings
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Downloads
|
||||
* @since 09 Oct 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\downloads\modules\admin\downloads;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings
|
||||
*/
|
||||
class _settings extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Manage Settings
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'settings_manage' );
|
||||
|
||||
$form = new \IPS\Helpers\Form;
|
||||
|
||||
$form->addTab('basic_settings');
|
||||
$form->add( new \IPS\Helpers\Form\Upload( 'idm_watermarkpath', \IPS\Settings::i()->idm_watermarkpath ? \IPS\File::get( 'core_Theme', \IPS\Settings::i()->idm_watermarkpath ) : NULL, FALSE, array( 'image' => TRUE, 'storageExtension' => 'core_Theme' ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Stack( 'idm_link_blacklist', explode( ',', \IPS\Settings::i()->idm_link_blacklist ), FALSE, array( 'placeholder' => 'example.com' ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'idm_antileech', \IPS\Settings::i()->idm_antileech ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'idm_rss', \IPS\Settings::i()->idm_rss ) );
|
||||
|
||||
if ( \IPS\Application::appIsEnabled( 'nexus' ) )
|
||||
{
|
||||
$form->addTab( 'paid_file_settings' );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'idm_nexus_on', \IPS\Settings::i()->idm_nexus_on, FALSE, array( 'togglesOn' => array( 'idm_nexus_tax', 'idm_nexus_percent', 'idm_nexus_transfee' ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'idm_nexus_tax', \IPS\Settings::i()->idm_nexus_tax, FALSE, array( 'class' => '\IPS\nexus\Tax', 'zeroVal' => 'do_not_tax' ), NULL, NULL, NULL, 'idm_nexus_tax' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'idm_nexus_percent', \IPS\Settings::i()->idm_nexus_percent, FALSE, array( 'min' => 0, 'max' => 100 ), NULL, NULL, '%', 'idm_nexus_percent' ) );
|
||||
$form->add( new \IPS\nexus\Form\Money( 'idm_nexus_transfee', json_decode( \IPS\Settings::i()->idm_nexus_transfee, TRUE ), FALSE, array(), NULL, NULL, NULL, 'idm_nexus_transfee' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'idm_nexus_gateways', explode( ',', \IPS\Settings::i()->idm_nexus_gateways ), FALSE, array( 'class' => '\IPS\nexus\Gateway', 'zeroVal' => 'no_restriction', 'multiple' => TRUE ), NULL, NULL, NULL, 'idm_nexus_gateways' ) );
|
||||
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'idm_nexus_display', explode( ',', \IPS\Settings::i()->idm_nexus_display ), FALSE, array( 'options' => array( 'purchases' => 'idm_purchases', 'downloads' => 'downloads' ) ) ) );
|
||||
}
|
||||
|
||||
if ( $values = $form->values( TRUE ) )
|
||||
{
|
||||
$form->saveAsSettings( $values );
|
||||
|
||||
/* Clear guest page caches */
|
||||
\IPS\Data\Cache::i()->clearAll();
|
||||
|
||||
\IPS\Session::i()->log( 'acplogs__downloads_settings' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('settings');
|
||||
\IPS\Output::i()->output = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuild Watermarks
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function rebuildWatermarks()
|
||||
{
|
||||
$perGo = 1;
|
||||
$watermark = \IPS\Settings::i()->idm_watermarkpath ? \IPS\Image::create( \IPS\File::get( 'core_Theme', \IPS\Settings::i()->idm_watermarkpath )->contents() ) : NULL;
|
||||
|
||||
\IPS\Output::i()->output = new \IPS\Helpers\MultipleRedirect( \IPS\Http\Url::internal( 'app=downloads&module=downloads&controller=settings&do=rebuildWatermarks' ), function( $doneSoFar ) use( $watermark, $perGo )
|
||||
{
|
||||
$where = array( array( 'record_type=?', 'ssupload' ) );
|
||||
if ( !$watermark )
|
||||
{
|
||||
$where[] = array( 'record_no_watermark<>?', '' );
|
||||
}
|
||||
|
||||
$select = \IPS\Db::i()->select( '*', 'downloads_files_records', $where, 'record_id', array( $doneSoFar, $perGo ), NULL, NULL, \IPS\Db::SELECT_SQL_CALC_FOUND_ROWS );
|
||||
if ( !$select->count() )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
foreach ( $select as $row )
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( $row['record_no_watermark'] )
|
||||
{
|
||||
$original = \IPS\File::get( 'downloads_Screenshots', $row['record_no_watermark'] );
|
||||
|
||||
try
|
||||
{
|
||||
\IPS\File::get( 'downloads_Screenshots', $row['record_location'] )->delete();
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
|
||||
if ( !$watermark )
|
||||
{
|
||||
\IPS\Db::i()->update( 'downloads_files_records', array(
|
||||
'record_location' => (string) $original,
|
||||
'record_thumb' => (string) $original->thumbnail( 'downloads_Screenshots' ),
|
||||
'record_no_watermark' => NULL
|
||||
), array( 'record_id=?', $row['record_id'] ) );
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$original = \IPS\File::get( 'downloads_Screenshots', $row['record_location'] );
|
||||
}
|
||||
|
||||
$image = \IPS\Image::create( $original->contents() );
|
||||
$image->watermark( $watermark );
|
||||
|
||||
$newFile = \IPS\File::create( 'downloads_Screenshots', $original->originalFilename, $image );
|
||||
|
||||
\IPS\Db::i()->update( 'downloads_files_records', array(
|
||||
'record_location' => (string) $newFile,
|
||||
'record_thumb' => (string) $newFile->thumbnail( 'downloads_Screenshots' ),
|
||||
'record_no_watermark' => (string) $original
|
||||
), array( 'record_id=?', $row['record_id'] ) );
|
||||
}
|
||||
catch ( \Exception $e ) {}
|
||||
}
|
||||
|
||||
$doneSoFar += $perGo;
|
||||
return array( $doneSoFar, \IPS\Member::loggedIn()->language()->addToStack('rebuilding'), 100 / $select->count( TRUE ) * $doneSoFar );
|
||||
|
||||
}, function()
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=downloads&module=downloads&controller=settings' ), 'completed' );
|
||||
} );
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Top Downloaders
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Downloads
|
||||
* @since 17 Dec 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Top Downloaders
|
||||
*/
|
||||
class _downloaders extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
const PER_PAGE = 25;
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'downloaders_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Top Downloaders
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
$values = NULL;
|
||||
$where = array( array( 'dmid>0' ) );
|
||||
|
||||
if ( isset( \IPS\Request::i()->form ) )
|
||||
{
|
||||
$form = new \IPS\Helpers\Form( 'form', 'go' );
|
||||
$form->add( new \IPS\Helpers\Form\DateRange( 'stats_date_range' ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
if ( $values['stats_date_range']['start'] )
|
||||
{
|
||||
$where[] = array( 'dtime>?', $values['stats_date_range']['start']->getTimestamp() );
|
||||
}
|
||||
if ( $values['stats_date_range']['end'] )
|
||||
{
|
||||
$where[] = array( 'dtime<?', $values['stats_date_range']['end']->getTimestamp() );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->output = $form;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$page = isset( \IPS\Request::i()->page ) ? intval( \IPS\Request::i()->page ) : 1;
|
||||
|
||||
if( $page < 1 )
|
||||
{
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$select = \IPS\Db::i()->select( 'dmid, COUNT(*) as downloads, core_members.*', 'downloads_downloads', $where, 'downloads DESC', array( ( $page - 1 ) * static::PER_PAGE, static::PER_PAGE ), 'dmid', NULL, \IPS\Db::SELECT_SQL_CALC_FOUND_ROWS )->join( 'core_members', 'core_members.member_id=downloads_downloads.dmid' );
|
||||
|
||||
$pagination = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->pagination(
|
||||
\IPS\Http\Url::internal( 'app=downloads&module=stats&controller=downloaders' )->setQueryString( $values ),
|
||||
ceil( $select->count( TRUE ) / static::PER_PAGE ),
|
||||
$page,
|
||||
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=downloaders&form=1' )->setQueryString( $values ),
|
||||
'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 );
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__downloads_stats_downloaders');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Downloads Statistics
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Downloads
|
||||
* @since 16 Dec 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* downloads
|
||||
*/
|
||||
class _downloads extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'downloads_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Downloads Statistics
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
$chart = new \IPS\Helpers\Chart\Dynamic( \IPS\Http\Url::internal( "app=downloads&module=stats&controller=downloads" ), 'downloads_downloads', 'dtime', '', array(), 'ColumnChart', 'monthly', array( 'start' => 0, 'end' => 0 ), array( 'dmid', 'dfid', 'dtime', 'dsize', 'dua', 'dip' ) );
|
||||
|
||||
$chart->addSeries( \IPS\Member::loggedIn()->language()->addToStack('downloads'), 'number', 'COUNT(*)', FALSE );
|
||||
$chart->availableTypes = array( 'LineChart', 'ColumnChart', 'BarChart' );
|
||||
|
||||
$chart->tableParsers = array(
|
||||
'dmid' => function( $val )
|
||||
{
|
||||
try
|
||||
{
|
||||
$member = \IPS\Member::load( $val );
|
||||
return "<a href='" . \IPS\Http\Url::internal( "app=downloads&module=stats&controller=member&do=downloads&id={$member->member_id}" ) . "'>{$member->name}</a>";
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack('deleted_member');
|
||||
}
|
||||
},
|
||||
'dfid' => function( $val )
|
||||
{
|
||||
try
|
||||
{
|
||||
$file = \IPS\downloads\File::load( $val );
|
||||
return "<a href='{$file->url()}' target='_blank'>{$file->name}</a>";
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack('deleted_file');
|
||||
}
|
||||
},
|
||||
'dtime' => function( $val )
|
||||
{
|
||||
return (string) \IPS\DateTime::ts( $val );
|
||||
},
|
||||
'dsize' => function( $val )
|
||||
{
|
||||
return \IPS\Output\Plugin\Filesize::humanReadableFilesize( $val );
|
||||
},
|
||||
'dua' => function( $val )
|
||||
{
|
||||
return (string) \IPS\Http\Useragent::parse( $val );
|
||||
},
|
||||
'dip' => function( $val )
|
||||
{
|
||||
$url = \IPS\Http\Url::internal( "app=core&module=members&controller=ip&ip={$val}&tab=downloads_DownloadLog" );
|
||||
return "<a href='{$url}'>{$val}</a>";
|
||||
}
|
||||
);
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('downloads_stats');
|
||||
\IPS\Output::i()->output = (string) $chart;
|
||||
}
|
||||
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Member Stats
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Downloads
|
||||
* @since 13 Dec 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Member Stats
|
||||
*/
|
||||
class _member extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Downloads
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function downloads()
|
||||
{
|
||||
/* Get member */
|
||||
try
|
||||
{
|
||||
$member = \IPS\Member::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2D170/1', 404, '' );
|
||||
}
|
||||
|
||||
/* Build chart */
|
||||
$tabs = array( 'information' => 'information', 'downloads' => 'downloads', 'bandwidth_use' => 'bandwidth_use' );
|
||||
$activeTab = \IPS\Request::i()->tab ?: 'information';
|
||||
switch ( $activeTab )
|
||||
{
|
||||
case 'information':
|
||||
$fileCount = \IPS\Db::i()->select( 'COUNT(*)', 'downloads_files', array( 'file_submitter=?', $member->member_id ) )->first();
|
||||
$diskspaceUsed = \IPS\Db::i()->select( 'SUM(file_size)', 'downloads_files', array( 'file_submitter=?', $member->member_id ) )->first();
|
||||
$numberOfDownloads = \IPS\Db::i()->select( 'COUNT(*)', 'downloads_downloads', array( 'dmid=?', $member->member_id ) )->first();
|
||||
$bandwidthUsed = \IPS\Db::i()->select( 'SUM(dsize)', 'downloads_downloads', array( 'dmid=?', $member->member_id ) )->first();
|
||||
|
||||
$allFiles = \IPS\Db::i()->select( 'COUNT(*)', 'downloads_files' )->first();
|
||||
$totalFileSize = \IPS\Db::i()->select( 'SUM(file_size)', 'downloads_files' )->first();
|
||||
$totalDownloadSize = \IPS\Db::i()->select( 'SUM(dsize)', 'downloads_downloads' )->first();
|
||||
|
||||
$activeTabContents = \IPS\Theme::i()->getTemplate( 'stats' )->information( \IPS\Theme::i()->getTemplate( 'global', 'core' )->definitionTable( array(
|
||||
'files_submitted' =>
|
||||
\IPS\Member::loggedIn()->language()->addToStack('downloads_stat_of_total', FALSE, array( 'sprintf' => array(
|
||||
\IPS\Member::loggedIn()->language()->formatNumber( $fileCount ),
|
||||
\IPS\Member::loggedIn()->language()->formatNumber( ( ( $allFiles ? ( 100 / $allFiles ) : 0 ) * $fileCount ), 2 ) ) )
|
||||
),
|
||||
'diskspace_used' =>
|
||||
\IPS\Member::loggedIn()->language()->addToStack('downloads_stat_of_total', FALSE, array( 'sprintf' => array(
|
||||
\IPS\Output\Plugin\Filesize::humanReadableFilesize( $diskspaceUsed ),
|
||||
\IPS\Member::loggedIn()->language()->formatNumber( ( ( $totalFileSize ? ( 100 / $totalFileSize ) : 0 ) * $diskspaceUsed ), 2 ) ) )
|
||||
),
|
||||
'average_filesize_downloads' =>
|
||||
\IPS\Member::loggedIn()->language()->addToStack('downloads_stat_average', FALSE, array( 'sprintf' => array(
|
||||
\IPS\Output\Plugin\Filesize::humanReadableFilesize( \IPS\Db::i()->select( 'AVG(file_size)', 'downloads_files', array( 'file_submitter=?', $member->member_id ) )->first() ),
|
||||
\IPS\Output\Plugin\Filesize::humanReadableFilesize( \IPS\Db::i()->select( 'AVG(file_size)', 'downloads_files' )->first() ) ))
|
||||
),
|
||||
'number_of_downloads' =>
|
||||
\IPS\Member::loggedIn()->language()->addToStack('downloads_stat_of_total', FALSE, array( 'sprintf' => array(
|
||||
\IPS\Member::loggedIn()->language()->formatNumber( $numberOfDownloads ),
|
||||
\IPS\Member::loggedIn()->language()->formatNumber( ( ( $allFiles ? ( 100 / $allFiles ) : 0 ) * $fileCount ), 2 ) ) )
|
||||
),
|
||||
'downloads_bandwidth_used' =>
|
||||
\IPS\Member::loggedIn()->language()->addToStack('downloads_stat_of_total', FALSE, array( 'sprintf' => array(
|
||||
\IPS\Output\Plugin\Filesize::humanReadableFilesize( $bandwidthUsed ),
|
||||
\IPS\Member::loggedIn()->language()->formatNumber( ( ( $totalDownloadSize ? ( 100 / $totalDownloadSize ) : 0 ) * $bandwidthUsed ), 2 ) ) )
|
||||
)
|
||||
) ) );
|
||||
break;
|
||||
|
||||
case 'downloads':
|
||||
$downloadsChart = new \IPS\Helpers\Chart\Dynamic( \IPS\Http\Url::internal( "app=downloads&module=stats&controller=member&do=downloads&id={$member->member_id}&tab=downloads&_graph=1" ), 'downloads_downloads', 'dtime', '', array(), 'ColumnChart', 'monthly', array( 'start' => 0, 'end' => 0 ), array( 'dfid', 'dtime', 'dsize', 'dua', 'dip' ) );
|
||||
$downloadsChart->where[] = array( 'dmid=?', $member->member_id );
|
||||
$downloadsChart->tableParsers = array(
|
||||
'dfid' => function( $val )
|
||||
{
|
||||
try
|
||||
{
|
||||
$file = \IPS\downloads\File::load( $val );
|
||||
return "<a href='{$file->url()}' target='_blank'>{$file->name}</a>";
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack('deleted_file');
|
||||
}
|
||||
},
|
||||
'dtime' => function( $val )
|
||||
{
|
||||
return (string) \IPS\DateTime::ts( $val );
|
||||
},
|
||||
'dsize' => function( $val )
|
||||
{
|
||||
return \IPS\Output\Plugin\Filesize::humanReadableFilesize( $val );
|
||||
},
|
||||
'dua' => function( $val )
|
||||
{
|
||||
return (string) \IPS\Http\Useragent::parse( $val );
|
||||
},
|
||||
'dip' => function( $val )
|
||||
{
|
||||
$url = \IPS\http\Url::internal( "app=core&module=members&controller=ip&ip={$val}&tab=downloads_DownloadLog" );
|
||||
return "<a href='{$url}'>{$val}</a>";
|
||||
}
|
||||
);
|
||||
$downloadsChart->addSeries( \IPS\Member::loggedIn()->language()->addToStack('downloads'), 'number', 'COUNT(*)', FALSE );
|
||||
$activeTabContents = ( \IPS\Request::i()->isAjax() and isset( \IPS\Request::i()->_graph ) ) ? (string) $downloadsChart : \IPS\Theme::i()->getTemplate( 'stats' )->graphs( (string) $downloadsChart );
|
||||
break;
|
||||
|
||||
case 'bandwidth_use':
|
||||
$bandwidthChart = new \IPS\Helpers\Chart\Dynamic( \IPS\Http\Url::internal( "app=downloads&module=stats&controller=member&do=downloads&id={$member->member_id}&tab=bandwidth_use&_graph=1" ), 'downloads_downloads', 'dtime', '', array( 'vAxis' => array( 'title' => '(kB)' ) ) );
|
||||
$bandwidthChart->where[] = array( 'dmid=?', $member->member_id );
|
||||
$bandwidthChart->addSeries( \IPS\Member::loggedIn()->language()->addToStack('bandwidth_use'), 'number', 'ROUND((SUM(dsize)/1024),2)', FALSE );
|
||||
$activeTabContents = ( \IPS\Request::i()->isAjax() and isset( \IPS\Request::i()->_graph ) ) ? (string) $bandwidthChart : \IPS\Theme::i()->getTemplate( 'stats' )->graphs( (string) $bandwidthChart );
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('member_downloads_chart', FALSE, array( 'sprintf' => array( $member->name ) ) );
|
||||
if( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->output = $activeTabContents;
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $activeTab, $activeTabContents, \IPS\Http\Url::internal( "app=downloads&module=stats&controller=member&do=downloads&id={$member->member_id}" ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Top Submitters
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Downloads
|
||||
* @since 17 Dec 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Top Submitters
|
||||
*/
|
||||
class _submitters extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
const PER_PAGE = 25;
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'submitters_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Top Submitters
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
$values = NULL;
|
||||
$where = array();
|
||||
|
||||
if ( isset( \IPS\Request::i()->form ) )
|
||||
{
|
||||
$form = new \IPS\Helpers\Form( 'form', 'go' );
|
||||
$form->add( new \IPS\Helpers\Form\DateRange( 'stats_date_range' ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
if ( $values['stats_date_range']['start'] )
|
||||
{
|
||||
$where[] = array( 'file_submitted>?', $values['stats_date_range']['start']->getTimestamp() );
|
||||
}
|
||||
if ( $values['stats_date_range']['end'] )
|
||||
{
|
||||
$where[] = array( 'file_submitted<?', $values['stats_date_range']['end']->getTimestamp() );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->output = $form;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$page = isset( \IPS\Request::i()->page ) ? intval( \IPS\Request::i()->page ) : 1;
|
||||
|
||||
if( $page < 1 )
|
||||
{
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$select = \IPS\Db::i()->select( 'file_submitter, COUNT(*) as files, core_members.*', 'downloads_files', $where, 'files DESC', array( ( $page - 1 ) * static::PER_PAGE, static::PER_PAGE ), 'file_submitter', NULL, \IPS\Db::SELECT_SQL_CALC_FOUND_ROWS )->join( 'core_members', 'core_members.member_id=downloads_files.file_submitter' );
|
||||
|
||||
$pagination = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->pagination(
|
||||
\IPS\Http\Url::internal( 'app=downloads&module=stats&controller=submitters' )->setQueryString( $values ),
|
||||
ceil( $select->count( TRUE ) / static::PER_PAGE ),
|
||||
$page,
|
||||
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( $values ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('stats_date_range') )
|
||||
)
|
||||
);
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('stats')->submittersTable( $select, $pagination );
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__downloads_stats_submitters');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
/**
|
||||
* @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.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Downloads
|
||||
* @since 08 Oct 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\downloads\modules\front\downloads;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Browse Files
|
||||
*/
|
||||
class _browse extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Route
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
if ( isset( \IPS\Request::i()->currency ) and in_array( \IPS\Request::i()->currency, \IPS\nexus\Money::currencies() ) and isset( \IPS\Request::i()->csrfKey ) and \IPS\Request::i()->csrfKey === \IPS\Session\Front::i()->csrfKey )
|
||||
{
|
||||
$_SESSION['currency'] = \IPS\Request::i()->currency;
|
||||
}
|
||||
|
||||
if ( isset( \IPS\Request::i()->id ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->_category( \IPS\downloads\Category::loadAndCheckPerms( \IPS\Request::i()->id, 'read' ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2D175/1', 404, '' );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->_index();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show Index
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _index()
|
||||
{
|
||||
/* Add RSS feed */
|
||||
if ( \IPS\Settings::i()->idm_rss )
|
||||
{
|
||||
\IPS\Output::i()->rssFeeds['idm_rss_title'] = \IPS\Http\Url::internal( 'app=downloads&module=downloads&controller=browse&do=rss', 'front', 'downloads_rss' );
|
||||
}
|
||||
|
||||
/* Get stuff */
|
||||
$featured = iterator_to_array( \IPS\downloads\File::featured( 4, '_rand' ) );
|
||||
$new = \IPS\downloads\File::getItemsWithPermission( array(), NULL, 14 );
|
||||
$highestRated = \IPS\downloads\File::getItemsWithPermission( array( array( 'file_rating > ?', 0 ) ), 'file_rating DESC', 14 );
|
||||
$mostDownloaded = \IPS\downloads\File::getItemsWithPermission( array( array( 'file_downloads > ?', 0 ) ), 'file_downloads DESC', 14 );
|
||||
|
||||
/* Online User Location */
|
||||
\IPS\Session::i()->setLocation( \IPS\Http\Url::internal( 'app=downloads', 'front', 'downloads' ), array(), 'loc_downloads_browsing' );
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->sidebar['contextual'] = \IPS\Theme::i()->getTemplate( 'browse' )->indexSidebar( \IPS\downloads\Category::canOnAny('add') );
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('downloads');
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'browse' )->index( $featured, $new, $highestRated, $mostDownloaded );
|
||||
}
|
||||
|
||||
/**
|
||||
* Show Category
|
||||
*
|
||||
* @param \IPS\downloads\Category $category The category to show
|
||||
* @return void
|
||||
*/
|
||||
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 );
|
||||
|
||||
if( !$_count['cnt'] )
|
||||
{
|
||||
/* Show a 'no files' template if there's nothing to display */
|
||||
$table = \IPS\Theme::i()->getTemplate( 'browse' )->noFiles( $category );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Build table */
|
||||
$table = new \IPS\Helpers\Table\Content( 'IPS\downloads\File', $category->url(), NULL, $category );
|
||||
$table->classes = array( 'ipsDataList_large' );
|
||||
|
||||
if ( \IPS\Application::appIsEnabled( 'nexus' ) and \IPS\Settings::i()->idm_nexus_on )
|
||||
{
|
||||
$table->filters = array(
|
||||
'file_free' => "( ( file_cost='' OR file_cost IS NULL ) AND ( file_nexus='' OR file_nexus IS NULL ) )",
|
||||
'file_paid' => "( file_cost<>'' OR file_nexus>0 )",
|
||||
);
|
||||
}
|
||||
$table->title = \IPS\Member::loggedIn()->language()->pluralize( \IPS\Member::loggedIn()->language()->get('download_file_count'), array( $_count['cnt'] ) );
|
||||
}
|
||||
|
||||
/* Online User Location */
|
||||
$permissions = $category->permissions();
|
||||
\IPS\Session::i()->setLocation( $category->url(), explode( ",", $permissions['perm_view'] ), 'loc_downloads_viewing_category', array( "downloads_category_{$category->id}" => TRUE ) );
|
||||
|
||||
/* 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()->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 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a category listing
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function categories()
|
||||
{
|
||||
/* Online User Location */
|
||||
\IPS\Session::i()->setLocation( \IPS\Http\Url::internal( 'app=downloads&module=downloads&controller=browse&do=categories', 'front', 'downloads_categories' ), array(), 'loc_downloads_browsing_categories' );
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('__app_downloads');
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'browse' )->categories();
|
||||
}
|
||||
|
||||
/**
|
||||
* Latest Files RSS
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function rss()
|
||||
{
|
||||
if( !\IPS\Settings::i()->idm_rss )
|
||||
{
|
||||
\IPS\Output::i()->error( 'rss_offline', '2D175/2', 403, 'rss_offline_admin' );
|
||||
}
|
||||
|
||||
$document = \IPS\Xml\Rss::newDocument( \IPS\Http\Url::internal( 'app=downloads&module=downloads&controller=browse', 'front', 'downloads' ), \IPS\Member::loggedIn()->language()->get('idm_rss_title'), \IPS\Member::loggedIn()->language()->get('idm_rss_title') );
|
||||
|
||||
foreach ( \IPS\downloads\File::getItemsWithPermission() as $file )
|
||||
{
|
||||
$document->addItem( $file->name, $file->url(), $file->desc, \IPS\DateTime::ts( $file->updated ), $file->id );
|
||||
}
|
||||
|
||||
/* @note application/rss+xml is not a registered IANA mime-type so we need to stick with text/xml for RSS */
|
||||
\IPS\Output::i()->sendOutput( $document->asXML(), 200, 'text/xml' );
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,572 @@
|
||||
<?php
|
||||
/**
|
||||
* @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.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Downloads
|
||||
* @since 08 Oct 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\downloads\modules\front\downloads;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit File Controller
|
||||
*/
|
||||
class _submit extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'front_submit.js', 'downloads', 'front' ) );
|
||||
|
||||
\IPS\downloads\File::canCreate( \IPS\Member::loggedIn(), NULL, TRUE );
|
||||
|
||||
\IPS\Output::i()->sidebar['enabled'] = FALSE;
|
||||
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Choose category
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
$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(
|
||||
'url' => \IPS\Http\Url::internal( 'app=downloads&module=downloads&controller=submit', 'front', 'downloads_submit' ),
|
||||
'class' => 'IPS\downloads\Category',
|
||||
'permissionCheck' => 'add',
|
||||
) ) );
|
||||
|
||||
if ( \IPS\Member::loggedIn()->group['idm_bulk_submit'] )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'bulk', NULL, FALSE, array( 'label' => "bulk_upload_button" ) ) );
|
||||
}
|
||||
|
||||
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 );
|
||||
if ( isset( $values['bulk'] ) AND $values['bulk'] )
|
||||
{
|
||||
$url = $url->setQueryString( 'bulk', '1' );
|
||||
}
|
||||
if( isset( \IPS\Request::i()->_new ) )
|
||||
{
|
||||
$url = $url->setQueryString(array( '_new' => '1' ) );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( $url );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'select_category' );
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'submit' )->categorySelector( $form );
|
||||
\IPS\Output::i()->breadcrumb[] = array( NULL, \IPS\Member::loggedIn()->language()->addToStack( 'select_category' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit files
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function submit()
|
||||
{
|
||||
$steps = array();
|
||||
|
||||
/**
|
||||
* Step 1: Upload files
|
||||
*/
|
||||
$steps['upload_files'] = function( $data )
|
||||
{
|
||||
/* Get category data */
|
||||
try
|
||||
{
|
||||
$category = \IPS\downloads\Category::loadAndCheckPerms( \IPS\Request::i()->category );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=downloads&module=downloads&controller=submit&_step=select_category', 'front', 'downloads_submit' ) );
|
||||
}
|
||||
|
||||
if( !$category->can('add') )
|
||||
{
|
||||
\IPS\Output::i()->error( 'add_files_no_perm', '3D286/1', 403, '' );
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form( 'upload_files', 'continue' );
|
||||
|
||||
$form->class = 'ipsForm_vertical';
|
||||
$form->hiddenValues['category'] = $category->_id;
|
||||
$form->hiddenValues['postKey'] = ( \IPS\Request::i()->postKey ) ? \IPS\Request::i()->postKey : md5( uniqid() );
|
||||
|
||||
/* Populate any existing records */
|
||||
$files = array();
|
||||
$screenshots = array();
|
||||
|
||||
if ( isset( $data['files'] ) )
|
||||
{
|
||||
foreach ( $data['files'] as $url )
|
||||
{
|
||||
$files[] = \IPS\File::get( 'downloads_Files', $url );
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $data['screenshots'] ) )
|
||||
{
|
||||
foreach ( $data['screenshots'] as $url )
|
||||
{
|
||||
$screenshots[] = \IPS\File::get( 'downloads_Screenshots', $url );
|
||||
}
|
||||
}
|
||||
|
||||
/* Add the fields */
|
||||
$form->add( new \IPS\Helpers\Form\Upload( 'files', $files, ( !\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 !== NULL ? ( $category->maxfile / 1024 ) : NULL, 'multiple' => TRUE, 'minimize' => FALSE ) ) );
|
||||
|
||||
if ( !isset( \IPS\Request::i()->bulk ) )
|
||||
{
|
||||
if ( \IPS\Member::loggedIn()->group['idm_linked_files'] )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Stack( 'url_files', isset( $data['url_files'] ) ? $data['url_files'] : array(), FALSE, array( 'stackFieldType' => 'Url' ), array( 'IPS\downloads\File', 'blacklistCheck' ) ) );
|
||||
}
|
||||
|
||||
if ( \IPS\Member::loggedIn()->group['idm_import_files'] )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Stack( 'import_files', array(), FALSE, array( 'placeholder' => \IPS\ROOT_PATH ), function( $val )
|
||||
{
|
||||
if( $val and is_array( $val ) )
|
||||
{
|
||||
foreach ( $val as $file )
|
||||
{
|
||||
if ( is_dir( $file ) )
|
||||
{
|
||||
throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack('err_import_files_dir', FALSE, array( 'sprintf' => array( $file ) ) ) );
|
||||
}
|
||||
elseif ( !is_file( $file ) )
|
||||
{
|
||||
throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack('err_import_files', FALSE, array( 'sprintf' => array( $file ) ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
} ) );
|
||||
}
|
||||
|
||||
if ( $category->bitoptions['allowss'] )
|
||||
{
|
||||
$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,
|
||||
'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 Elements */
|
||||
foreach ( \IPS\downloads\File::formElements( NULL, $category ) as $input )
|
||||
{
|
||||
$form->add( $input );
|
||||
}
|
||||
|
||||
/* Version field (we only show this on create */
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'file_version', '1.0.0', FALSE, array( 'maxLength' => 32 ) ) );
|
||||
}
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
/* Check */
|
||||
if ( empty( $values['files'] ) and empty( $values['url_files'] ) and empty( $values['import_files'] ) )
|
||||
{
|
||||
$form->error = \IPS\Member::loggedIn()->language()->addToStack('err_no_files');
|
||||
return \IPS\Theme::i()->getTemplate( 'submit' )->submitForm( $form, $category, $category->message('subterms'), ( \IPS\Member::loggedIn()->group['idm_bulk_submit'] && \IPS\Request::i()->bulk ) );
|
||||
}
|
||||
if ( !isset( \IPS\Request::i()->bulk ) && $category->bitoptions['reqss'] and empty( $values['screenshots'] ) and empty( $values['url_screenshots'] ) )
|
||||
{
|
||||
$form->error = \IPS\Member::loggedIn()->language()->addToStack('err_no_screenshots');
|
||||
return \IPS\Theme::i()->getTemplate( 'submit' )->submitForm( $form, $category, $category->message('subterms'), ( \IPS\Member::loggedIn()->group['idm_bulk_submit'] && \IPS\Request::i()->bulk ) );
|
||||
}
|
||||
|
||||
/* Get any records we had before in case we need to delete them */
|
||||
$existing = iterator_to_array( \IPS\Db::i()->select( '*', 'downloads_files_records', array( 'record_post_key=?', \IPS\Request::i()->postKey ) )->setKeyField( 'record_location' ) );
|
||||
|
||||
/* Loop through the values we have */
|
||||
$k = 0;
|
||||
$files = array();
|
||||
$linkedFiles = array();
|
||||
$screenshots = array();
|
||||
$linkedScreenshots = array();
|
||||
foreach ( $values['files'] as $file )
|
||||
{
|
||||
$files[ $k ] = (string) $file;
|
||||
if ( !isset( $existing[ (string) $file ] ) )
|
||||
{
|
||||
\IPS\Db::i()->insert( 'downloads_files_records', array(
|
||||
'record_post_key' => isset( \IPS\Request::i()->bulk ) ? md5( \IPS\Request::i()->postKey . "-{$k}" ) : \IPS\Request::i()->postKey,
|
||||
'record_type' => 'upload',
|
||||
'record_location' => (string) $file,
|
||||
'record_realname' => $file->originalFilename,
|
||||
'record_size' => $file->filesize(),
|
||||
'record_time' => time(),
|
||||
) );
|
||||
}
|
||||
$k++;
|
||||
unset( $existing[ (string) $file ] );
|
||||
}
|
||||
if ( isset( $values['import_files'] ) )
|
||||
{
|
||||
foreach ( $values['import_files'] as $path )
|
||||
{
|
||||
$file = \IPS\File::create( 'downloads_Files', mb_substr( $path, mb_strrpos( $path, DIRECTORY_SEPARATOR ) + 1 ), NULL, NULL, FALSE, $path );
|
||||
|
||||
$files[ $k ] = (string) $file;
|
||||
if ( !isset( $existing[ (string) $file ] ) )
|
||||
{
|
||||
\IPS\Db::i()->insert( 'downloads_files_records', array(
|
||||
'record_post_key' => isset( \IPS\Request::i()->bulk ) ? md5( \IPS\Request::i()->postKey . "-{$k}" ) : \IPS\Request::i()->postKey,
|
||||
'record_type' => 'upload',
|
||||
'record_location' => (string) $file,
|
||||
'record_realname' => $file->originalFilename,
|
||||
'record_size' => $file->filesize(),
|
||||
'record_time' => time(),
|
||||
) );
|
||||
}
|
||||
$k++;
|
||||
}
|
||||
}
|
||||
if ( isset( $values['url_files'] ) )
|
||||
{
|
||||
foreach ( $values['url_files'] as $url )
|
||||
{
|
||||
$linkedFiles[] = (string) $url;
|
||||
if ( !isset( $existing[ (string) $url ] ) )
|
||||
{
|
||||
\IPS\Db::i()->insert( 'downloads_files_records', array(
|
||||
'record_post_key' => \IPS\Request::i()->postKey,
|
||||
'record_type' => 'link',
|
||||
'record_location' => (string) $url,
|
||||
'record_realname' => NULL,
|
||||
'record_size' => 0,
|
||||
'record_time' => time(),
|
||||
) );
|
||||
}
|
||||
unset( $existing[ (string) $url ] );
|
||||
}
|
||||
}
|
||||
if ( isset( $values['screenshots'] ) )
|
||||
{
|
||||
foreach ( $values['screenshots'] as $_key => $file )
|
||||
{
|
||||
$screenshots[] = (string) $file;
|
||||
if ( !isset( $existing[ (string) $file ] ) )
|
||||
{
|
||||
$noWatermark = NULL;
|
||||
if ( \IPS\Settings::i()->idm_watermarkpath )
|
||||
{
|
||||
try
|
||||
{
|
||||
$noWatermark = (string) $file;
|
||||
$watermark = \IPS\Image::create( \IPS\File::get( 'core_Theme', \IPS\Settings::i()->idm_watermarkpath )->contents() );
|
||||
$image = \IPS\Image::create( $file->contents() );
|
||||
$image->watermark( $watermark );
|
||||
$file = \IPS\File::create( 'downloads_Screenshots', $file->originalFilename, $image );
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
}
|
||||
|
||||
\IPS\Db::i()->insert( 'downloads_files_records', array(
|
||||
'record_post_key' => \IPS\Request::i()->postKey,
|
||||
'record_type' => 'ssupload',
|
||||
'record_location' => (string) $file,
|
||||
'record_thumb' => (string) $file->thumbnail( 'downloads_Screenshots' ),
|
||||
'record_realname' => $file->originalFilename,
|
||||
'record_size' => \strlen( $file->contents() ),
|
||||
'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
|
||||
) );
|
||||
}
|
||||
unset( $existing[ (string) $file ] );
|
||||
}
|
||||
}
|
||||
if ( isset( $values['url_screenshots'] ) )
|
||||
{
|
||||
foreach ( $values['url_screenshots'] as $url )
|
||||
{
|
||||
$linkedScreenshots[] = (string) $url;
|
||||
if ( !isset( $existing[ (string) $url ] ) )
|
||||
{
|
||||
\IPS\Db::i()->insert( 'downloads_files_records', array(
|
||||
'record_post_key' => \IPS\Request::i()->postKey,
|
||||
'record_type' => 'sslink',
|
||||
'record_location' => (string) $url,
|
||||
'record_thumb' => NULL,
|
||||
'record_realname' => NULL,
|
||||
'record_size' => 0,
|
||||
'record_time' => time(),
|
||||
) );
|
||||
}
|
||||
unset( $existing[ (string) $url ] );
|
||||
}
|
||||
}
|
||||
|
||||
/* Delete any that we don't have any more */
|
||||
foreach ( $existing as $location => $file )
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\File::get( $file['record_type'] === 'upload' ? 'downloads_Files' : 'downloads_Screenshots', $location )->delete();
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
|
||||
\IPS\Db::i()->delete( 'downloads_files_records', array( 'record_id=?', $file['record_id'] ) );
|
||||
}
|
||||
|
||||
|
||||
if ( !isset( \IPS\Request::i()->bulk ) )
|
||||
{
|
||||
$file = \IPS\downloads\File::createFromForm( array_merge( $data, $values, array( 'postKey' => \IPS\Request::i()->postKey ) ), $category );
|
||||
|
||||
/* Redirect */
|
||||
if( $file->author()->member_id OR $file->canView() )
|
||||
{
|
||||
$url = $file->url();
|
||||
$message = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
$url = $category->url();
|
||||
$message = \IPS\Member::loggedIn()->language()->addToStack('file_requires_approval_g');
|
||||
}
|
||||
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->json( array( 'redirect' => (string) $url ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->redirect( $url, $message );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* This is a bulk file, so we want to go on to the next step */
|
||||
return array( 'category' => $category->_id, 'postKey' => \IPS\Request::i()->postKey, 'files' => $files, 'url_files' => $linkedFiles, 'screenshots' => $screenshots, 'url_screenshots' => $linkedScreenshots );
|
||||
}
|
||||
}
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'submit' )->submitForm( $form, $category, $category->message('subterms'), ( \IPS\Member::loggedIn()->group['idm_bulk_submit'] && \IPS\Request::i()->bulk ) );
|
||||
};
|
||||
|
||||
/**
|
||||
* Step 2: File information (for bulk uploads only)
|
||||
*/
|
||||
$steps['file_information'] = function ($data)
|
||||
{
|
||||
/* Get Category */
|
||||
try
|
||||
{
|
||||
$category = \IPS\downloads\Category::loadAndCheckPerms( $data['category'] );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=downloads&module=downloads&controller=submit', 'front', 'downloads_submit' ) );
|
||||
}
|
||||
/* Init Form */
|
||||
$form = new \IPS\Helpers\Form( 'file_information', 'continue' );
|
||||
$existing = array();
|
||||
|
||||
foreach ( $data['files'] as $key => $file )
|
||||
{
|
||||
/* Header */
|
||||
$file = \IPS\File::get( 'downloads_Files', $file );
|
||||
$form->addTab( $file->originalFilename );
|
||||
$form->addHeader( $file->originalFilename );
|
||||
|
||||
/* Form Elements */
|
||||
foreach ( \IPS\downloads\File::formElements( NULL, $category ) as $input )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words[ "filedata_{$key}_{$input->name}" ] = \IPS\Member::loggedIn()->language()->addToStack( $input->name, FALSE );
|
||||
|
||||
if ( !$input->value and in_array( $input->name, array( 'file_title', 'file_desc' ) ) )
|
||||
{
|
||||
$input->value = $file->originalFilename;
|
||||
}
|
||||
|
||||
$input->name = "filedata_{$key}_{$input->name}";
|
||||
if ( $input instanceof \IPS\Helpers\Form\Editor )
|
||||
{
|
||||
$input->options['autoSaveKey'] .= $key;
|
||||
}
|
||||
|
||||
$form->add( $input );
|
||||
}
|
||||
|
||||
/* Screenshots */
|
||||
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' ) );
|
||||
|
||||
$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,
|
||||
'maxFileSize' => $category->maxss ? ( $category->maxss / 1024 ) : NULL,
|
||||
'multiple' => TRUE
|
||||
) ) );
|
||||
\IPS\Member::loggedIn()->language()->words[ "screenshots_{$key}" ] = \IPS\Member::loggedIn()->language()->addToStack( 'screenshots', FALSE );
|
||||
}
|
||||
|
||||
|
||||
/* Version field (we only show this on create */
|
||||
$form->add( new \IPS\Helpers\Form\Text( "filedata_{$key}_file_version", '1.0.0', FALSE, array( 'maxLength' => 32 ) ) );
|
||||
\IPS\Member::loggedIn()->language()->words[ "filedata_{$key}_file_version" ] = \IPS\Member::loggedIn()->language()->addToStack( 'file_version', FALSE );
|
||||
}
|
||||
|
||||
|
||||
/* Handle Submissions */
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
if ( $category->bitoptions['allowss'] )
|
||||
{
|
||||
foreach ( $data['files'] as $key => $file )
|
||||
{
|
||||
/* Save Screenshots */
|
||||
foreach ( $values["screenshots_{$key}"] as $file )
|
||||
{
|
||||
$screenshots[] = (string) $file;
|
||||
if ( !isset( $existing[ $key ][ (string) $file ] ) )
|
||||
{
|
||||
$noWatermark = NULL;
|
||||
if ( \IPS\Settings::i()->idm_watermarkpath )
|
||||
{
|
||||
$noWatermark = (string) $file;
|
||||
$watermark = \IPS\Image::create( \IPS\File::get( 'core_Theme', \IPS\Settings::i()->idm_watermarkpath )->contents() );
|
||||
$image = \IPS\Image::create( $file->contents() );
|
||||
$image->watermark( $watermark );
|
||||
$file = \IPS\File::create( 'downloads_Screenshots', $file->originalFilename, $image );
|
||||
}
|
||||
|
||||
\IPS\Db::i()->insert( 'downloads_files_records', array(
|
||||
'record_post_key' => md5( "{$data['postKey']}-{$key}" ),
|
||||
'record_type' => 'ssupload',
|
||||
'record_location' => (string) $file,
|
||||
'record_thumb' => (string) $file->thumbnail( 'downloads_Screenshots' ),
|
||||
'record_realname' => $file->originalFilename,
|
||||
'record_size' => \strlen( $file->contents() ),
|
||||
'record_time' => time(),
|
||||
'record_no_watermark' => $noWatermark
|
||||
) );
|
||||
}
|
||||
else
|
||||
{
|
||||
unset( $existing[ $key ][ (string) $file ] );
|
||||
}
|
||||
}
|
||||
|
||||
unset( $values["screenshots_{$key}"] );
|
||||
|
||||
/* Delete any that we don't have any more */
|
||||
foreach ( $existing[ $key ] as $location => $file )
|
||||
{
|
||||
try
|
||||
{
|
||||
$file->delete();
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
|
||||
\IPS\Db::i()->delete( 'downloads_files_records', array( 'record_location=? OR record_no_watermark=?', (string) $file, (string) $file ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Create Files */
|
||||
foreach ( $data['files'] as $key => $fileUrl )
|
||||
{
|
||||
/* $values isn't going to work as is here */
|
||||
$save = array(
|
||||
'file_title' => $values["filedata_{$key}_file_title"],
|
||||
'file_desc' => $values["filedata_{$key}_file_desc"],
|
||||
'file_tags' => $values["filedata_{$key}_file_tags"],
|
||||
'file_version' => $values["filedata_{$key}_file_version"],
|
||||
'postKey' => md5( "{$data['postKey']}-{$key}" )
|
||||
);
|
||||
\IPS\downloads\File::createFromForm( $save, $category, FALSE );
|
||||
}
|
||||
|
||||
if ( \IPS\Member::loggedIn()->moderateNewContent() OR \IPS\downloads\File::moderateNewItems( \IPS\Member::loggedIn(), $category ) )
|
||||
{
|
||||
\IPS\downloads\File::_sendUnapprovedNotifications( $category );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\downloads\File::_sendNotifications( $category );
|
||||
}
|
||||
|
||||
/* Redirect */
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->json( array( 'redirect' => (string) $category->url() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->redirect( $category->url() );
|
||||
}
|
||||
}
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'submit' )->bulkForm( $form, $category );
|
||||
};
|
||||
|
||||
|
||||
/* Build Wizard */
|
||||
$url = \IPS\Http\Url::internal( 'app=downloads&module=downloads&controller=submit&do=submit', 'front', 'downloads_submit' );
|
||||
if ( isset( \IPS\Request::i()->category ) and \IPS\Request::i()->category )
|
||||
{
|
||||
$url = $url->setQueryString( 'category', \IPS\Request::i()->category );
|
||||
}
|
||||
if ( isset( \IPS\Request::i()->bulk ) and \IPS\Request::i()->bulk )
|
||||
{
|
||||
$url = $url->setQueryString( 'bulk', 1 );
|
||||
}
|
||||
$wizard = new \IPS\Helpers\Wizard( $steps, $url );
|
||||
$wizard->template = array( \IPS\Theme::i()->getTemplate( 'submit' ), 'wizardForm' );
|
||||
|
||||
/* Online User Location */
|
||||
\IPS\Session::i()->setLocation( \IPS\Http\Url::internal( 'app=downloads&module=downloads&controller=submit', 'front', 'downloads_submit' ), array(), 'loc_downloads_adding_file' );
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( isset( \IPS\Request::i()->bulk ) ? 'submit_multiple_files' : 'submit_a_file' );
|
||||
if ( \IPS\IN_DEV )
|
||||
{
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'plupload/moxie.js', 'core', 'interface' ) );
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'plupload/plupload.dev.js', 'core', 'interface' ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'plupload/plupload.full.min.js', 'core', 'interface' ) );
|
||||
}
|
||||
if ( \IPS\downloads\File::moderateNewItems( \IPS\Member::loggedIn() ) )
|
||||
{
|
||||
$wizard = \IPS\Theme::i()->getTemplate( 'forms', 'core' )->modQueueMessage( \IPS\Member::loggedIn()->warnings( 5, NULL, 'mq' ), \IPS\Member::loggedIn()->mod_posts ) . $wizard;
|
||||
}
|
||||
\IPS\Output::i()->output = $wizard;
|
||||
\IPS\Output::i()->breadcrumb[] = array( NULL, \IPS\Member::loggedIn()->language()->addToStack( 'submit_a_file' ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,988 @@
|
||||
<?php
|
||||
/**
|
||||
* @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.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Downloads
|
||||
* @since 10 Oct 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\downloads\modules\front\downloads;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* View File Controller
|
||||
*/
|
||||
class _view extends \IPS\Content\Controller
|
||||
{
|
||||
/**
|
||||
* [Content\Controller] Class
|
||||
*/
|
||||
protected static $contentModel = 'IPS\downloads\File';
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->file = \IPS\downloads\File::load( \IPS\Request::i()->id );
|
||||
|
||||
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, '' );
|
||||
}
|
||||
|
||||
if ( $this->file->primary_screenshot )
|
||||
{
|
||||
\IPS\Output::i()->metaTags['og:image'] = \IPS\File::get( 'downloads_Screenshots', $this->file->primary_screenshot_thumb )->url;
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2D161/1', 404, '' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'front_view.js', 'downloads', 'front' ) );
|
||||
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* View File
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
/* Init */
|
||||
parent::manage();
|
||||
|
||||
/* Sort out comments and reviews */
|
||||
$tabs = $this->file->commentReviewTabs();
|
||||
$_tabs = array_keys( $tabs );
|
||||
$tab = isset( \IPS\Request::i()->tab ) ? \IPS\Request::i()->tab : array_shift( $_tabs );
|
||||
$activeTabContents = $this->file->commentReviews( $tab );
|
||||
$commentsAndReviews = count( $tabs ) ? \IPS\Theme::i()->getTemplate( 'global', 'core' )->commentsAndReviewsTabs( \IPS\Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $tab, $activeTabContents, $this->file->url(), 'tab', FALSE, TRUE ), md5( $this->file->url() ) ) : NULL;
|
||||
if ( \IPS\Request::i()->isAjax() and !isset( \IPS\Request::i()->changelog ) )
|
||||
{
|
||||
\IPS\Output::i()->output = $activeTabContents;
|
||||
return;
|
||||
}
|
||||
|
||||
/* 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' ) );
|
||||
if ( isset( \IPS\Request::i()->changelog ) and isset( $previousVersions[ \IPS\Request::i()->changelog ] ) )
|
||||
{
|
||||
$versionData = $previousVersions[ \IPS\Request::i()->changelog ];
|
||||
}
|
||||
|
||||
if( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->json( \IPS\Theme::i()->getTemplate( 'view' )->changeLog( $this->file, $versionData ) );
|
||||
}
|
||||
|
||||
/* Online User Location */
|
||||
\IPS\Session::i()->setLocation( $this->file->url(), $this->file->onlineListPermissions(), 'loc_downloads_viewing_file', array( $this->file->name => FALSE ) );
|
||||
|
||||
/* Custom Field Formatting */
|
||||
$cfields = array();
|
||||
$fields = $this->file->customFields();
|
||||
|
||||
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( 'pfd.*', array( 'downloads_cfields', 'pfd' ), NULL, 'pfd.cf_position' ), 'IPS\downloads\Field' ) as $field )
|
||||
{
|
||||
if( array_key_exists( 'field_' . $field->id, $this->file->customFields() ) )
|
||||
{
|
||||
if ( $fields[ 'field_' . $field->id ] !== null AND $fields[ 'field_' . $field->id ] !== '' )
|
||||
{
|
||||
$cfields[ 'field_' . $field->id ] = $field->displayValue( $fields[ 'field_' . $field->id ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->sidebar['sticky'] = TRUE;
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'view' )->view( $this->file, $commentsAndReviews, $versionData, $previousVersions, $this->file->nextItem(), $this->file->prevItem(), $cfields );
|
||||
}
|
||||
|
||||
/**
|
||||
* Buy file
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function buy()
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
/* Can we buy? */
|
||||
if ( !$this->file->canBuy() )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission', '2D161/E', 403, '' );
|
||||
}
|
||||
|
||||
/* Is it associated with a Nexus product? */
|
||||
if ( $this->file->nexus )
|
||||
{
|
||||
$productIds = explode( ',', $this->file->nexus );
|
||||
|
||||
if ( count( $productIds ) === 1 )
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\nexus\Package::load( array_pop( $productIds ) )->url() );
|
||||
}
|
||||
catch ( \OutOfRangeExcpetion $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2D161/F', 404, '' );
|
||||
}
|
||||
}
|
||||
|
||||
$category = $this->file->container();
|
||||
try
|
||||
{
|
||||
foreach ( $category->parents() as $parent )
|
||||
{
|
||||
\IPS\Output::i()->breadcrumb[] = array( $parent->url(), $parent->_title );
|
||||
}
|
||||
\IPS\Output::i()->breadcrumb[] = array( $category->url(), $category->_title );
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'store.css', 'nexus' ) );
|
||||
\IPS\Output::i()->bodyClasses[] = 'ipsLayout_minimal';
|
||||
\IPS\Output::i()->sidebar['enabled'] = FALSE;
|
||||
\IPS\Output::i()->breadcrumb[] = array( $this->file->url(), $this->file->name );
|
||||
\IPS\Output::i()->title = $this->file->name;
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('nexus')->chooseProduct( \IPS\nexus\Package\Item::getItemsWithPermission( array( array( \IPS\Db::i()->in( 'p_id', $productIds ) ) ), 'p_position' ) );
|
||||
return;
|
||||
}
|
||||
|
||||
/* Create the item */
|
||||
$price = $this->file->price();
|
||||
$item = new \IPS\downloads\extensions\nexus\Item\File( $this->file->name, $price );
|
||||
$item->id = $this->file->id;
|
||||
try
|
||||
{
|
||||
$item->tax = \IPS\Settings::i()->idm_nexus_tax ? \IPS\nexus\Tax::load( \IPS\Settings::i()->idm_nexus_tax ) : NULL;
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) { }
|
||||
if ( \IPS\Settings::i()->idm_nexus_gateways )
|
||||
{
|
||||
$item->paymentMethodIds = explode( ',', \IPS\Settings::i()->idm_nexus_gateways );
|
||||
}
|
||||
$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 ) )
|
||||
{
|
||||
$item->fee = new \IPS\nexus\Money( $fees[ $price->currency ]['amount'], $price->currency );
|
||||
}
|
||||
|
||||
/* Generate the invoice */
|
||||
$invoice = new \IPS\nexus\Invoice;
|
||||
$invoice->member = \IPS\nexus\Customer::loggedIn();
|
||||
$invoice->addItem( $item );
|
||||
$invoice->return_uri = "app=downloads&module=downloads&controller=view&id={$this->file->id}";
|
||||
$invoice->save();
|
||||
|
||||
/* Take them to it */
|
||||
\IPS\Output::i()->redirect( $invoice->checkoutUrl() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Download file - Show terms and file selection
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function download()
|
||||
{
|
||||
/* No direct linking check */
|
||||
if ( \IPS\Settings::i()->idm_antileech )
|
||||
{
|
||||
if ( !isset( \IPS\Request::i()->csrfKey ) )
|
||||
{
|
||||
\IPS\Output::i()->redirect( $this->file->url() );
|
||||
}
|
||||
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
}
|
||||
|
||||
/* Can we download? */
|
||||
try
|
||||
{
|
||||
$this->file->downloadCheck();
|
||||
}
|
||||
catch ( \DomainException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( $e->getMessage(), '1D161/3', 403, '' );
|
||||
}
|
||||
|
||||
/* What's the URL to confirm? */
|
||||
$confirmUrl = $this->file->url()->setQueryString( array( 'do' => 'download', 'confirm' => 1 ) );
|
||||
if ( isset( \IPS\Request::i()->version ) )
|
||||
{
|
||||
$confirmUrl = $confirmUrl->setQueryString( 'version', \IPS\Request::i()->version );
|
||||
}
|
||||
if ( \IPS\Settings::i()->idm_antileech )
|
||||
{
|
||||
$confirmUrl = $confirmUrl->csrf();
|
||||
}
|
||||
|
||||
/* Set navigation */
|
||||
$category = $this->file->container();
|
||||
try
|
||||
{
|
||||
foreach ( $category->parents() as $parent )
|
||||
{
|
||||
\IPS\Output::i()->breadcrumb[] = array( $parent->url(), $parent->_title );
|
||||
}
|
||||
\IPS\Output::i()->breadcrumb[] = array( $category->url(), $category->_title );
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
|
||||
\IPS\Output::i()->breadcrumb[] = array( $this->file->url(), $this->file->name );
|
||||
\IPS\Output::i()->title = $this->file->name;
|
||||
|
||||
/* What files do we have? */
|
||||
$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 !isset( \IPS\Request::i()->confirm ) )
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'view' )->download( $this->file, $downloadTerms, null, $confirmUrl, count( $files ) > 1 );
|
||||
return;
|
||||
}
|
||||
|
||||
/* File Selected? */
|
||||
if ( count( $files ) === 1 or ( isset( \IPS\Request::i()->r ) ) )
|
||||
{
|
||||
/* Which file? */
|
||||
foreach ( $files as $k => $file )
|
||||
{
|
||||
$data = $files->data();
|
||||
if ( isset( \IPS\Request::i()->r ) and \IPS\Request::i()->r == $k )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check it */
|
||||
try
|
||||
{
|
||||
$this->file->downloadCheck( $data );
|
||||
}
|
||||
catch ( \DomainException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( $e->getMessage(), '1D161/4', 403, '' );
|
||||
}
|
||||
|
||||
/* Time Delay */
|
||||
if ( \IPS\Member::loggedIn()->group['idm_wait_period'] )
|
||||
{
|
||||
if ( isset( \IPS\Request::i()->t ) )
|
||||
{
|
||||
$timerKey = "downloads_delay_" . md5( (string) $file );
|
||||
|
||||
if ( !isset( $_SESSION[ $timerKey ] ) )
|
||||
{
|
||||
$_SESSION[ $timerKey ] = time();
|
||||
}
|
||||
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->json( array( 'download' => time() + \IPS\Member::loggedIn()->group['idm_wait_period'], 'currentTime' => time() ) );
|
||||
}
|
||||
|
||||
if ( $_SESSION[ $timerKey ] > ( time() - \IPS\Member::loggedIn()->group['idm_wait_period'] ) )
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'view' )->download( $this->file, null, $files, $confirmUrl, count( $files ) > 1, $data['record_id'], ( $_SESSION[ $timerKey ] + \IPS\Member::loggedIn()->group['idm_wait_period'] ) - time() );
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
unset( $_SESSION[ $timerKey ] );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'view' )->download( $this->file, null, $files, $confirmUrl, count( $files ) > 1 );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Log */
|
||||
if ( $category->log !== 0 )
|
||||
{
|
||||
$_log = true;
|
||||
|
||||
if( isset( $_SERVER['HTTP_RANGE'] ) )
|
||||
{
|
||||
if( !\IPS\Http\Ranges::isStartOfFile() )
|
||||
{
|
||||
$_log = false;
|
||||
}
|
||||
}
|
||||
|
||||
if( $_log )
|
||||
{
|
||||
\IPS\Db::i()->insert( 'downloads_downloads', array(
|
||||
'dfid' => $this->file->id,
|
||||
'dtime' => time(),
|
||||
'dip' => \IPS\Request::i()->ipAddress(),
|
||||
'dmid' => (int) \IPS\Member::loggedIn()->member_id,
|
||||
'dsize' => $data['record_size'],
|
||||
'dua' => \IPS\Session::i()->userAgent->useragent,
|
||||
'dbrowsers' => \IPS\Session::i()->userAgent->useragentKey,
|
||||
'dos' => ''
|
||||
) );
|
||||
|
||||
$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 ) )
|
||||
{
|
||||
\IPS\nexus\Customer::loggedIn()->log( 'download', array( 'type' => 'idm', 'id' => $this->file->id, 'name' => $this->file->name ) );
|
||||
}
|
||||
|
||||
/* Download */
|
||||
if ( $data['record_type'] === 'link' )
|
||||
{
|
||||
\IPS\Output::i()->redirect( $data['record_location'] );
|
||||
}
|
||||
else
|
||||
{
|
||||
$file = \IPS\File::get( 'downloads_Files', $data['record_location'] );
|
||||
$file->originalFilename = $data['record_realname'] ?: $file->originalFilename;
|
||||
$this->_download( $file );
|
||||
}
|
||||
}
|
||||
|
||||
/* Nope - choose one */
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'view' )->download( $this->file, null, $files, $confirmUrl, count( $files ) > 1 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Actually send the file for download
|
||||
*
|
||||
* @param \IPS\File $file The file to download
|
||||
* @return void
|
||||
*/
|
||||
protected function _download( \IPS\File $file )
|
||||
{
|
||||
if ( !$file->filesize() )
|
||||
{
|
||||
\IPS\Output::i()->error( 'downloads_no_file', '3D161/G', 404, '' );
|
||||
}
|
||||
/* Log session */
|
||||
$downloadSessionId = md5( uniqid( microtime(), true ) );
|
||||
\IPS\Db::i()->insert( 'downloads_sessions', array(
|
||||
'dsess_id' => $downloadSessionId,
|
||||
'dsess_mid' => (int) \IPS\Member::loggedIn()->member_id,
|
||||
'dsess_ip' => \IPS\Request::i()->ipAddress(),
|
||||
'dsess_file' => $this->file->id,
|
||||
'dsess_start' => time()
|
||||
) );
|
||||
register_shutdown_function( function() use( $downloadSessionId ) {
|
||||
\IPS\Db::i()->delete( 'downloads_sessions', array( 'dsess_id=?', $downloadSessionId ) );
|
||||
} );
|
||||
|
||||
/* Print the file, honoring ranges */
|
||||
$ranges = new \IPS\Http\Ranges( $file, (int) \IPS\Member::loggedIn()->group['idm_throttling'] );
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore a previous version
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function restorePreviousVersion()
|
||||
{
|
||||
/* Permission check */
|
||||
if ( !$this->file->canEdit() or !\IPS\Member::loggedIn()->group['idm_bypass_revision'] )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission', '2D161/5', 403, '' );
|
||||
}
|
||||
|
||||
/* Load the desired version */
|
||||
try
|
||||
{
|
||||
$version = \IPS\Db::i()->select( '*', 'downloads_filebackup', array( 'b_id=?', \IPS\Request::i()->version ) )->first();
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2D161/6', 404, '' );
|
||||
}
|
||||
|
||||
/* Delete the current versions and any versions in between */
|
||||
foreach ( new \IPS\File\Iterator( \IPS\Db::i()->select( 'record_location', 'downloads_files_records', array( 'record_file_id=? AND record_backup=0', $this->file->id ) ), 'downloads_Files' ) as $file )
|
||||
{
|
||||
try
|
||||
{
|
||||
$file->delete();
|
||||
}
|
||||
catch ( \Exception $e ) {}
|
||||
}
|
||||
\IPS\Db::i()->delete( 'downloads_files_records', array( 'record_file_id=? AND record_backup=0', $this->file->id ) );
|
||||
|
||||
/* Delete any versions in between */
|
||||
foreach ( \IPS\Db::i()->select( 'b_records', 'downloads_filebackup', array( 'b_fileid=? AND b_backup>?', $this->file->id, $version['b_backup'] ) ) as $backup )
|
||||
{
|
||||
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( ',', $backup ) ) ) ), 'downloads_Files' ) as $file )
|
||||
{
|
||||
try
|
||||
{
|
||||
$file->delete();
|
||||
}
|
||||
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( ',', $backup ) ) ) ), 'downloads_Files' ) as $file )
|
||||
{
|
||||
try
|
||||
{
|
||||
$file->delete();
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
}
|
||||
|
||||
\IPS\Db::i()->delete( 'downloads_files_records', \IPS\Db::i()->in( 'record_id', explode( ',', $backup ) ) );
|
||||
}
|
||||
\IPS\Db::i()->delete( 'downloads_filebackup', array( 'b_fileid=? AND b_backup>=?', $this->file->id, $version['b_backup'] ) );
|
||||
|
||||
/* Restore the records */
|
||||
\IPS\Db::i()->update( 'downloads_files_records', array( 'record_backup' => 0 ), array( 'record_file_id=?', $this->file->id ) );
|
||||
|
||||
/* Update the file information */
|
||||
$this->file->name = $version['b_filetitle'];
|
||||
$this->file->desc = $version['b_filedesc'];
|
||||
$this->file->version = $version['b_version'];
|
||||
$this->file->changelog = $version['b_changelog'];
|
||||
$this->file->save();
|
||||
|
||||
/* Moderator log */
|
||||
\IPS\Session::i()->modLog( 'modlog__action_restorebackup', array( (string) $this->file->url() => FALSE, $this->file->name => FALSE ), $this->file );
|
||||
|
||||
/* Redirect */
|
||||
\IPS\Output::i()->redirect( $this->file->url() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle Previous Version Visibility
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function previousVersionVisibility()
|
||||
{
|
||||
/* Permission check */
|
||||
if ( !$this->file->canEdit() or !\IPS\Member::loggedIn()->group['idm_bypass_revision'] )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission', '2D161/8', 403, '' );
|
||||
}
|
||||
|
||||
/* Load the desired version */
|
||||
try
|
||||
{
|
||||
$version = \IPS\Db::i()->select( '*', 'downloads_filebackup', array( 'b_id=?', \IPS\Request::i()->version ) )->first();
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2D161/7', 404, '' );
|
||||
}
|
||||
|
||||
/* Change visibility */
|
||||
\IPS\Db::i()->update( 'downloads_filebackup', array( 'b_hidden' => !$version['b_hidden'] ), array( 'b_id=?', $version['b_id'] ) );
|
||||
|
||||
/* Moderator log */
|
||||
\IPS\Session::i()->modLog( 'modlog__action_visibilitybackup', array( (string) $this->file->url() => FALSE, $this->file->name => FALSE ), $this->file );
|
||||
|
||||
/* Redirect */
|
||||
\IPS\Output::i()->redirect( $this->file->url()->setQueryString( 'changelog', $version['b_id'] ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Previous Version
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function deletePreviousVersion()
|
||||
{
|
||||
/* Permission check */
|
||||
if ( !$this->file->canEdit() or !\IPS\Member::loggedIn()->group['idm_bypass_revision'] )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission', '2D161/9', 403, '' );
|
||||
}
|
||||
|
||||
/* Load the desired version */
|
||||
try
|
||||
{
|
||||
$version = \IPS\Db::i()->select( '*', 'downloads_filebackup', array( 'b_id=?', \IPS\Request::i()->version ) )->first();
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2D161/A', 404, '' );
|
||||
}
|
||||
|
||||
/* 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 )
|
||||
{
|
||||
try
|
||||
{
|
||||
$file->delete();
|
||||
}
|
||||
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 )
|
||||
{
|
||||
try
|
||||
{
|
||||
$file->delete();
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
}
|
||||
|
||||
\IPS\Db::i()->delete( 'downloads_files_records', \IPS\Db::i()->in( 'record_id', explode( ',', $version['b_records'] ) ) );
|
||||
\IPS\Db::i()->delete( 'downloads_filebackup', array( 'b_id=?', $version['b_id'] ) );
|
||||
|
||||
/* Moderator log */
|
||||
\IPS\Session::i()->modLog( 'modlog__action_deletebackup', array( (string) $this->file->url() => FALSE, $this->file->name => FALSE ), $this->file );
|
||||
|
||||
/* Redirect */
|
||||
\IPS\Output::i()->redirect( $this->file->url()->setQueryString( 'changelog', $version['b_id'] ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* View download log
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function log()
|
||||
{
|
||||
/* Permission check */
|
||||
if ( !$this->file->canViewDownloaders() )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission', '2D161/B', 403, '' );
|
||||
}
|
||||
|
||||
$table = new \IPS\Helpers\Table\Db( 'downloads_downloads', $this->file->url()->setQueryString( 'do', 'log' ), array( 'dfid=?', $this->file->id ) );
|
||||
$table->tableTemplate = array( \IPS\Theme::i()->getTemplate( 'view' ), 'logTable' );
|
||||
$table->rowsTemplate = array( \IPS\Theme::i()->getTemplate( 'view' ), 'logRows' );
|
||||
$table->sortBy = 'dtime';
|
||||
$table->limit = 10;
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'view' )->log( $this->file, (string) $table );
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload a new version
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function newVersion()
|
||||
{
|
||||
\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() )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission', '2D161/C', 403, '' );
|
||||
}
|
||||
|
||||
$category = $this->file->container();
|
||||
|
||||
/* Build form */
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->addHeader( 'new_version_details' );
|
||||
|
||||
if ( $category->versioning !== 0 and \IPS\Member::loggedIn()->group['idm_bypass_revision'] )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'file_save_revision', TRUE ) );
|
||||
}
|
||||
|
||||
$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->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 ) ) );
|
||||
|
||||
if ( \IPS\Member::loggedIn()->group['idm_linked_files'] )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Stack( 'url_files', 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, 'link' ) ) ), FALSE, array( 'stackFieldType' => 'Url' ), array( 'IPS\downloads\File', 'blacklistCheck' ) ) );
|
||||
}
|
||||
|
||||
if ( \IPS\Member::loggedIn()->group['idm_import_files'] )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Stack( 'import_files', array(), FALSE, array( 'placeholder' => \IPS\ROOT_PATH ), function( $val )
|
||||
{
|
||||
if( is_array( $val ) )
|
||||
{
|
||||
foreach ( $val as $file )
|
||||
{
|
||||
if ( !is_file( $file ) )
|
||||
{
|
||||
throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack('err_import_files', FALSE, array( 'sprintf' => array( $file ) ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
} ) );
|
||||
}
|
||||
|
||||
if ( $category->bitoptions['allowss'] )
|
||||
{
|
||||
$screenshots = iterator_to_array( $this->file->screenshots( 2, FALSE ) );
|
||||
|
||||
if( $this->file->_primary_screenshot and isset( $screenshots[ $this->file->_primary_screenshot ] ) )
|
||||
{
|
||||
$screenshots[ $this->file->_primary_screenshot ] = array( 'fileurl' => $screenshots[ $this->file->_primary_screenshot ], 'default' => true );
|
||||
}
|
||||
|
||||
$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,
|
||||
'maxFileSize' => $category->maxss ? ( $category->maxss / 1024 ) : NULL,
|
||||
'multiple' => TRUE,
|
||||
'retainDeleted' => TRUE,
|
||||
'template' => "downloads.submit.screenshot",
|
||||
) ) );
|
||||
|
||||
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' ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
/* Output */
|
||||
\IPS\Output::i()->title = $this->file->name;
|
||||
\IPS\Output::i()->breadcrumb[] = array( $this->file->url(), $this->file->name );
|
||||
|
||||
/* Handle submissions */
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
/* Check */
|
||||
if ( empty( $values['files'] ) and empty( $values['url_files'] ) and empty( $values['import_files'] ) )
|
||||
{
|
||||
$form->error = \IPS\Member::loggedIn()->language()->addToStack('err_no_files');
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'submit' )->newVersion( $form, $category->versioning !== 0 );
|
||||
return (string) $form;
|
||||
}
|
||||
if ( $category->bitoptions['reqss'] and empty( $values['screenshots'] ) and empty( $values['url_screenshots'] ) )
|
||||
{
|
||||
$form->error = \IPS\Member::loggedIn()->language()->addToStack('err_no_screenshots');
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'submit' )->newVersion( $form, $category->versioning !== 0 );
|
||||
return (string) $form;
|
||||
}
|
||||
|
||||
/* Versioning */
|
||||
$existingRecords = array();
|
||||
$existingScreenshots = array();
|
||||
$existingLinks = array();
|
||||
$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'] ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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') ) );
|
||||
}
|
||||
|
||||
/* Insert the new records */
|
||||
foreach ( $values['files'] as $file )
|
||||
{
|
||||
$key = array_search( (string) $file, $existingRecords );
|
||||
|
||||
if ( $key !== FALSE )
|
||||
{
|
||||
unset( $existingRecords[ $key ] );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Db::i()->insert( 'downloads_files_records', array(
|
||||
'record_file_id' => $this->file->id,
|
||||
'record_type' => 'upload',
|
||||
'record_location' => (string) $file,
|
||||
'record_realname' => $file->originalFilename,
|
||||
'record_size' => $file->filesize(),
|
||||
'record_time' => time(),
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $values['import_files'] ) )
|
||||
{
|
||||
foreach ( $values['import_files'] as $path )
|
||||
{
|
||||
$file = \IPS\File::create( 'downloads_Files', mb_substr( $path, mb_strrpos( $path, DIRECTORY_SEPARATOR ) + 1 ), file_get_contents( $path ) );
|
||||
|
||||
$key = array_search( (string) $file, $existingRecords );
|
||||
if ( $key !== FALSE )
|
||||
{
|
||||
unset( $existingRecords[ $key ] );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Db::i()->insert( 'downloads_files_records', array(
|
||||
'record_file_id' => $this->file->id,
|
||||
'record_type' => 'upload',
|
||||
'record_location' => (string) $file,
|
||||
'record_realname' => $file->originalFilename,
|
||||
'record_size' => $file->filesize(),
|
||||
'record_time' => time(),
|
||||
) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $values['url_files'] ) )
|
||||
{
|
||||
foreach ( $values['url_files'] as $url )
|
||||
{
|
||||
$key = array_search( $url, $existingLinks );
|
||||
if ( $key !== FALSE )
|
||||
{
|
||||
unset( $existingLinks[ $key ] );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Db::i()->insert( 'downloads_files_records', array(
|
||||
'record_file_id' => $this->file->id,
|
||||
'record_type' => 'link',
|
||||
'record_location' => (string) $url,
|
||||
'record_realname' => NULL,
|
||||
'record_size' => 0,
|
||||
'record_time' => time(),
|
||||
) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $values['screenshots'] ) )
|
||||
{
|
||||
foreach ( $values['screenshots'] as $_key => $file )
|
||||
{
|
||||
/* If this was the primary screenshot, convert back */
|
||||
if( is_array( $file ) )
|
||||
{
|
||||
$file = $file['fileurl'];
|
||||
}
|
||||
|
||||
$key = array_search( (string) $file, $existingScreenshots );
|
||||
if ( $key !== FALSE )
|
||||
{
|
||||
unset( $existingScreenshots[ $key ] );
|
||||
}
|
||||
else
|
||||
{
|
||||
$noWatermark = NULL;
|
||||
if ( \IPS\Settings::i()->idm_watermarkpath )
|
||||
{
|
||||
try
|
||||
{
|
||||
$noWatermark = (string) $file;
|
||||
$watermark = \IPS\Image::create( \IPS\File::get( 'core_Theme', \IPS\Settings::i()->idm_watermarkpath )->contents() );
|
||||
$image = \IPS\Image::create( $file->contents() );
|
||||
$image->watermark( $watermark );
|
||||
$file = \IPS\File::create( 'downloads_Screenshots', $file->originalFilename, $image );
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
}
|
||||
|
||||
\IPS\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_realname' => $file->originalFilename,
|
||||
'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
|
||||
) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $values['url_screenshots'] ) )
|
||||
{
|
||||
foreach ( $values['url_screenshots'] as $url )
|
||||
{
|
||||
$key = array_search( (string) $file, $existingScreenshotLinks );
|
||||
if ( $key !== FALSE )
|
||||
{
|
||||
unset( $existingScreenshotLinks[ $key ] );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Db::i()->insert( 'downloads_files_records', array(
|
||||
'record_file_id' => $this->file->id,
|
||||
'record_type' => 'sslink',
|
||||
'record_location' => (string) $url,
|
||||
'record_realname' => NULL,
|
||||
'record_size' => 0,
|
||||
'record_time' => time(),
|
||||
) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Delete any we're not using anymore */
|
||||
foreach ( $existingRecords as $url )
|
||||
{
|
||||
try
|
||||
{
|
||||
$file = \IPS\File::get( 'downloads_Files', $url )->delete();
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
|
||||
\IPS\Db::i()->delete( 'downloads_files_records', array( 'record_location=?', $url ) );
|
||||
}
|
||||
foreach ( $existingScreenshots as $url )
|
||||
{
|
||||
try
|
||||
{
|
||||
$file = \IPS\File::get( 'downloads_Screenshots', $url )->delete();
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
|
||||
\IPS\Db::i()->delete( 'downloads_files_records', array( 'record_location=?', $url ) );
|
||||
}
|
||||
foreach ( $existingLinks as $id => $url )
|
||||
{
|
||||
\IPS\Db::i()->delete( 'downloads_files_records', array( 'record_id=?', $id ) );
|
||||
}
|
||||
foreach ( $existingScreenshotLinks as $id => $url )
|
||||
{
|
||||
\IPS\Db::i()->delete( 'downloads_files_records', array( 'record_id=?', $id ) );
|
||||
}
|
||||
|
||||
/* Set the new details */
|
||||
$this->file->version = $values['file_version'];
|
||||
$this->file->changelog = $values['file_changelog'];
|
||||
$this->file->size = floatval( \IPS\Db::i()->select( 'SUM(record_size)', 'downloads_files_records', array( 'record_file_id=? AND record_type=? AND record_backup=0', $this->file->id, 'upload' ) )->first() );
|
||||
|
||||
/* 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();
|
||||
}
|
||||
catch ( \UnderflowException $e ) { }
|
||||
|
||||
/* Does it have to be reapproved? */
|
||||
if ( $category->bitoptions['moderation'] and $category->bitoptions['moderation_edits'] and !$this->file->canUnhide() )
|
||||
{
|
||||
$this->file->open = 0;
|
||||
}
|
||||
|
||||
/* Save */
|
||||
$this->file->updated = time();
|
||||
$this->file->save();
|
||||
|
||||
/* Send notifications */
|
||||
if ( $this->file->open )
|
||||
{
|
||||
$this->file->sendUpdateNotifications();
|
||||
}
|
||||
|
||||
/* Boink */
|
||||
\IPS\Output::i()->redirect( $this->file->url() );
|
||||
}
|
||||
|
||||
/* Set navigation */
|
||||
try
|
||||
{
|
||||
foreach ( $category->parents() as $parent )
|
||||
{
|
||||
\IPS\Output::i()->breadcrumb[] = array( $parent->url(), $parent->_title );
|
||||
}
|
||||
\IPS\Output::i()->breadcrumb[] = array( $category->url(), $category->_title );
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'submit' )->newVersion( $form, $category->versioning !== 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Change Author
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function changeAuthor()
|
||||
{
|
||||
/* Permission check */
|
||||
if ( !$this->file->canChangeAuthor() )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission', '2D161/D', 403, '' );
|
||||
}
|
||||
|
||||
/* Build form */
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\Member( 'author', NULL, TRUE ) );
|
||||
$form->class .= 'ipsForm_vertical';
|
||||
|
||||
/* Handle submissions */
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$this->file->changeAuthor( $values['author'] );
|
||||
\IPS\Output::i()->redirect( $this->file->url() );
|
||||
}
|
||||
|
||||
/* Display form */
|
||||
\IPS\Output::i()->output = $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' ) );;
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
Whitespace-only changes.
Reference in new issue
Block a user