Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
@@ -12,7 +12,7 @@
|
||||
namespace IPS\downloads;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -215,6 +215,8 @@ class _Category extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
{
|
||||
\IPS\Content\Search\Index::i()->massUpdate( static::$contentItemClass, $node->_id, NULL, ( $enabled ) ? $node->searchIndexPermissions() : '' );
|
||||
|
||||
\IPS\Db::i()->update( 'core_tags_perms', array( 'tag_perm_text' => ( $enabled ) ? $node->searchIndexPermissions() : '' ), array( 'tag_perm_aap_lookup=?', md5( static::$permApp . ';' . static::$permType . ';' . $node->_id ) ) );
|
||||
|
||||
if ( $node->hasChildren( NULL ) )
|
||||
{
|
||||
foreach( $node->children( NULL ) AS $child )
|
||||
@@ -252,7 +254,7 @@ class _Category extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
)
|
||||
) ) );
|
||||
|
||||
$class = get_called_class();
|
||||
$class = \get_called_class();
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'cparent', $this->parent ?: 0, FALSE, array(
|
||||
'class' => '\IPS\downloads\Category',
|
||||
@@ -281,12 +283,13 @@ class _Category extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
$form->addHeader( 'category_display' );
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'csortorder', $this->sortorder ?: 'updated', FALSE, array( 'options' => array( 'updated' => 'sort_updated', 'last_comment' => 'last_reply', 'title' => 'file_title', 'rating' => 'sort_rating', 'date' => 'sort_date', 'num_comments' => 'sort_num_comments', 'num_reviews' => 'sort_num_reviews', 'views' => 'sort_num_views' ) ), NULL, NULL, NULL, 'csortorder' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Translatable( 'cdisclaimer', NULL, FALSE, array( 'app' => 'downloads', 'key' => ( $this->id ? "downloads_category_{$this->id}_disclaimer" : NULL ), 'editor' => array( 'app' => 'downloads', 'key' => 'Categories', 'autoSaveKey' => ( $this->id ? "downloads-cat-{$this->id}-disc" : "downloads-new-cat-disc" ), 'attachIds' => $this->id ? array( $this->id, NULL, 'disclaimer' ) : NULL, 'minimize' => 'cdisclaimer_placeholder' ) ), NULL, NULL, NULL, 'cdisclaimer-editor' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'cdisclaimer_location', $this->id ? $this->disclaimer_location : 'download', FALSE, array( 'options' => array( 'purchase' => 'cdisclaimer_purchase', 'download' => 'cdisclaimer_download', 'both' => 'cdisclaimer_both' ) ) ) );
|
||||
$form->addHeader( 'category_logs' );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'clog_on', $this->log !== 0, FALSE, array( 'togglesOn' => array( 'clog', 'submitter_log' ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'clog', $this->log === NULL ? -1 : $this->log, FALSE, array( 'unlimited' => -1 ), NULL, NULL, array(
|
||||
'preUnlimited' => \IPS\Member::loggedIn()->language()->addToStack('days'),
|
||||
'postUnlimited' => ( $this->id and \IPS\Member::loggedIn()->hasAcpRestriction( 'downloads', 'downloads', 'categories_recount_downloads' ) ) ? '<a data-confirm data-confirmSubMessage="' . \IPS\Member::loggedIn()->language()->addToStack('clog_recount_desc') . '" href="' . \IPS\Http\Url::internal( "app=downloads&module=downloads&controller=categories&do=recountDownloads&id={$this->id}") . '">' . \IPS\Member::loggedIn()->language()->addToStack('clog_recount') . '</a>' : ''
|
||||
), 'clog' ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'clog_on', $this->log !== 0, FALSE, array( 'disableCopy' => TRUE, 'togglesOn' => array( 'clog', 'submitter_log' ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Interval( 'clog', $this->log === NULL ? -1 : $this->log, FALSE, array(
|
||||
'valueAs' => \IPS\Helpers\Form\Interval::DAYS, 'unlimited' => -1,
|
||||
'endSuffix' => ( $this->id and \IPS\Member::loggedIn()->hasAcpRestriction( 'downloads', 'downloads', 'categories_recount_downloads' ) ) ? '<a data-confirm data-confirmSubMessage="' . \IPS\Member::loggedIn()->language()->addToStack('clog_recount_desc') . '" href="' . \IPS\Http\Url::internal( "app=downloads&module=downloads&controller=categories&do=recountDownloads&id={$this->id}")->csrf() . '">' . \IPS\Member::loggedIn()->language()->addToStack('clog_recount') . '</a>' : ''
|
||||
), NULL, NULL, NULL, 'clog' ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'cbitoptions_submitter_log', $this->bitoptions['submitter_log'], FALSE, array(), NULL, NULL, NULL, 'submitter_log' ) );
|
||||
|
||||
$form->addTab( 'category_submissions' );
|
||||
@@ -298,8 +301,10 @@ class _Category extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
throw new \InvalidArgumentException('form_required');
|
||||
}
|
||||
}, NULL, \IPS\Member::loggedIn()->language()->addToStack('filesize_raw_k'), 'cmaxfile' ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'cmultiple_files', $this->id ? $this->multiple_files : TRUE ) );
|
||||
$form->add( new \IPS\Helpers\Form\Translatable( 'csubmissionterms', $this->submissionterms, FALSE, array( 'app' => 'downloads', 'key' => ( $this->id ? "downloads_category_{$this->id}_subterms" : NULL ), 'editor' => array( 'app' => 'downloads', 'key' => 'Categories', 'autoSaveKey' => ( $this->id ? "downloads-cat-{$this->id}-subt" : "downloads-new-cat-subt" ), 'attachIds' => $this->id ? array( $this->id, NULL, 'subt' ) : NULL, 'minimize' => 'csubmissionterms_placeholder' ) ) ) );
|
||||
$form->addHeader( 'category_versioning' );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'cversion_numbers', $this->id ? $this->version_numbers : 1, TRUE, array( 'options' => array( 0 => 'version_numbers_disabled', 1 => 'version_numbers_enabled', 2 => 'version_numbers_required' ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'cversioning_on', $this->versioning !== 0, FALSE, array( 'togglesOn' => array( 'cversioning' ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'cversioning', $this->versioning === NULL ? -1 : $this->versioning, FALSE, array( 'unlimited' => -1 ), NULL, NULL, NULL, 'cversioning' ) );
|
||||
$form->addHeader( 'category_moderation' );
|
||||
@@ -316,11 +321,7 @@ class _Category extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
$form->addHeader( 'category_tags' );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'ctags_disabled', !$this->tags_disabled, FALSE, array( 'togglesOn' => array( 'ctags_noprefixes', 'ctags_predefined' ) ), NULL, NULL, NULL, 'ctags_disabled' ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'ctags_noprefixes', !$this->tags_noprefixes, FALSE, array(), NULL, NULL, NULL, 'ctags_noprefixes' ) );
|
||||
|
||||
if ( !\IPS\Settings::i()->tags_open_system )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'ctags_predefined', $this->tags_predefined, FALSE, array( 'autocomplete' => array( 'unique' => 'true' ), 'nullLang' => 'ctags_predefined_unlimited' ), NULL, NULL, NULL, 'ctags_predefined' ) );
|
||||
}
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'ctags_predefined', $this->tags_predefined, FALSE, array( 'autocomplete' => array( 'unique' => 'true' ), 'nullLang' => 'ctags_predefined_unlimited' ), NULL, NULL, NULL, 'ctags_predefined' ) );
|
||||
}
|
||||
|
||||
$form->addTab( 'category_errors', NULL, 'category_errors_blurb' );
|
||||
@@ -329,6 +330,13 @@ class _Category extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
|
||||
if ( \IPS\Application::appIsEnabled( 'forums' ) )
|
||||
{
|
||||
if ( $this->id )
|
||||
{
|
||||
$rebuildUrl = \IPS\Http\Url::internal( 'app=downloads&module=downloads&controller=categories&id=' . $this->id . '&do=rebuildTopicContent' )->csrf();
|
||||
|
||||
\IPS\Member::loggedIn()->language()->words['cforum_on_desc'] = \IPS\Member::loggedIn()->language()->addToStack( 'database_forum_record__desc' );
|
||||
}
|
||||
|
||||
$form->addTab( 'category_forums_integration' );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'cforum_on', $this->forum_id, FALSE, array( 'disableCopy' => TRUE, 'togglesOn' => array(
|
||||
'cforum_id',
|
||||
@@ -336,8 +344,13 @@ class _Category extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
'ctopic_suffix',
|
||||
'cbitoptions_topic_delete',
|
||||
'cbitoptions_topic_screenshot'
|
||||
) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'cforum_id', $this->forum_id ? $this->forum_id : NULL, FALSE, array( 'class' => 'IPS\forums\Forum', 'permissionCheck' => function ( $forum ) { return $forum->sub_can_post and !$forum->redirect_url; } ), NULL, NULL, NULL, 'cforum_id' ) );
|
||||
) ), NULL, NULL, $this->id ? \IPS\Member::loggedIn()->language()->addToStack( 'downloadcategory_topic_rebuild', NULL, array( 'sprintf' => array( $rebuildUrl ) ) ) : NULL ) );
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'cforum_id', $this->forum_id ? $this->forum_id : NULL, FALSE, array( 'class' => 'IPS\forums\Forum', 'permissionCheck' => function ( $forum ) { return $forum->sub_can_post and !$forum->redirect_url; } ), function( $val ) {
|
||||
if( \IPS\Request::i()->cforum_on_checkbox AND !$val )
|
||||
{
|
||||
throw new \DomainException( 'form_required' );
|
||||
}
|
||||
}, NULL, NULL, 'cforum_id' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'ctopic_prefix', $this->topic_prefix, FALSE, array( 'trim' => FALSE ), NULL, NULL, NULL, 'ctopic_prefix' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'ctopic_suffix', $this->topic_suffix, FALSE, array( 'trim' => FALSE ), NULL, NULL, NULL, 'ctopic_suffix' ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'cbitoptions_topic_delete', $this->id ? $this->bitoptions['topic_delete'] : NULL, FALSE, array(), NULL, NULL, NULL, 'cbitoptions_topic_delete' ) );
|
||||
@@ -441,7 +454,7 @@ class _Category extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
if ( isset( $values['cparent'] ) )
|
||||
{
|
||||
/* Avoid "cparent cannot be null" error if no parent selected. */
|
||||
$values['cparent'] = $values['cparent'] ? intval( $values['cparent']->id ) : 0;
|
||||
$values['cparent'] = $values['cparent'] ? \intval( $values['cparent']->id ) : 0;
|
||||
}
|
||||
|
||||
if ( isset( $values['cforum_on'] ) and !$values['cforum_on'] )
|
||||
@@ -451,7 +464,7 @@ class _Category extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
|
||||
if( isset( $values['cforum_id'] ) AND $values['cforum_id'] )
|
||||
{
|
||||
$values['cforum_id'] = ( $values['cforum_id'] instanceof \IPS\Node\Model ) ? intval( $values['cforum_id']->id ) : intval( $values['cforum_id'] );
|
||||
$values['cforum_id'] = ( $values['cforum_id'] instanceof \IPS\Node\Model ) ? \intval( $values['cforum_id']->id ) : \intval( $values['cforum_id'] );
|
||||
}
|
||||
|
||||
if( array_key_exists( 'cforum_on', $values ) )
|
||||
@@ -499,7 +512,7 @@ class _Category extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
$this->_customFields = array();
|
||||
if ( $this->_data['cfields'] )
|
||||
{
|
||||
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'downloads_cfields', array( \IPS\Db::i()->in( 'cf_id', explode( ',', $this->_data['cfields'] ) ) ) ), 'IPS\downloads\Field' ) AS $field )
|
||||
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'downloads_cfields', array( \IPS\Db::i()->in( 'cf_id', explode( ',', $this->_data['cfields'] ) ) ), 'cf_position ASC' ), 'IPS\downloads\Field' ) AS $field )
|
||||
{
|
||||
$this->_customFields[ $field->id ] = $field;
|
||||
}
|
||||
@@ -576,13 +589,14 @@ class _Category extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
* permission to create content in any node to determine
|
||||
* if there should be a "Submit" button
|
||||
*
|
||||
* @param mixed $permission A key which has a value in static::$permissionMap['view'] matching a column ID in core_permission_index
|
||||
* @param \IPS\Member|\IPS\Member\Group|NULL $member The member or group to check (NULL for currently logged in member)
|
||||
* @param array $where Additional WHERE clause
|
||||
* @param mixed $permission A key which has a value in static::$permissionMap['view'] matching a column ID in core_permission_index
|
||||
* @param \IPS\Member|\IPS\Member\Group|NULL $member The member or group to check (NULL for currently logged in member)
|
||||
* @param array $where Additional WHERE clause
|
||||
* @param bool $considerPostBeforeRegistering If TRUE, and $member is a guest, will return TRUE if "Post Before Registering" feature is enabled
|
||||
* @return bool
|
||||
* @throws \OutOfBoundsException If $permission does not exist in static::$permissionMap
|
||||
*/
|
||||
public static function canOnAny( $permission, $member=NULL, $where = array() )
|
||||
public static function canOnAny( $permission, $member=NULL, $where = array(), $considerPostBeforeRegistering = TRUE )
|
||||
{
|
||||
$member = ( $member === NULL ) ? \IPS\Member::loggedIn() : $member;
|
||||
|
||||
@@ -591,7 +605,7 @@ class _Category extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return parent::canOnAny( $permission, $member, $where );
|
||||
return parent::canOnAny( $permission, $member, $where, $considerPostBeforeRegistering );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -768,7 +782,7 @@ class _Category extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'cbitoptions_reviews', $this->id ? $this->bitoptions['reviews'] : TRUE, FALSE, array( 'togglesOn' => array( 'cbitoptions_reviews_download' ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'cbitoptions_allowss', $this->id ? $this->bitoptions['allowss'] : TRUE, FALSE, array( 'togglesOn' => array( 'cbitoptions_reqss', 'cmaxss', 'cmaxdims' ) ), NULL, NULL, NULL, 'cbitoptions_allowss' ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'cbitoptions_reqss', $this->bitoptions['reqss'], FALSE, array(), NULL, NULL, NULL, 'cbitoptions_reqss' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'ctypes', $this->id ? $this->_data['types'] : NULL, FALSE, array( 'autocomplete' => array( 'unique' => 'true' ), 'nullLang' => 'any_extensions' ), NULL, NULL, NULL, 'ctypes' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'ctypes', $this->id ? $this->_data['types'] : NULL, FALSE, array( 'autocomplete' => array( 'unique' => 'true', 'lang' => 'files_optional' ), 'nullLang' => 'any_extensions' ), NULL, NULL, NULL, 'ctypes' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\downloads;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -92,7 +92,6 @@ class _Field extends \IPS\CustomField
|
||||
/**
|
||||
* Get topic format
|
||||
*
|
||||
* @param \IPS\Helpers\Form $form The form
|
||||
* @return void
|
||||
*/
|
||||
public function get_topic_format()
|
||||
@@ -109,12 +108,21 @@ class _Field extends \IPS\CustomField
|
||||
public function form( &$form )
|
||||
{
|
||||
parent::form( $form );
|
||||
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'downloads_field_location', $this->id ? $this->display_location : 'below', FALSE, array( 'options' => array( 'sidebar' => 'idm_cfield_sidebar', 'below' => 'idm_cfield_below', 'tab' => 'idm_cfield_tab' ) ), NULL, NULL, NULL, 'idm_field_location' ) );
|
||||
|
||||
if ( \IPS\Application::appIsEnabled( 'nexus' ) and \IPS\Settings::i()->idm_nexus_on )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'downloads_field_paid', $this->id ? $this->paid_field : FALSE, FALSE, array( 'togglesOff' => array( 'idm_cf_topic', 'idm_pf_format', 'form_' . ( $this->id ?? 'new' ) . '_header_category_forums_integration' ) ) ) );
|
||||
}
|
||||
|
||||
if ( \IPS\Application::appIsEnabled( 'forums' ) )
|
||||
{
|
||||
$form->addHeader('category_forums_integration');
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'cf_topic', $this->topic ) );
|
||||
$form->add( new \IPS\Helpers\Form\TextArea( 'pf_format', $this->id ? $this->topic_format : '', FALSE, array( 'placeholder' => "<strong>{title}:</strong> {content}" ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'cf_topic', $this->topic, FALSE, array(), NULL, NULL, NULL, 'idm_cf_topic' ) );
|
||||
$form->add( new \IPS\Helpers\Form\TextArea( 'pf_format', $this->id ? $this->topic_format : '', FALSE, array(), NULL, NULL, NULL, 'idm_pf_format' ) );
|
||||
|
||||
\IPS\Member::loggedIn()->language()->words['pf_format_desc'] = \IPS\Member::loggedIn()->language()->addToStack('cf_format_desc');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +136,8 @@ class _Field extends \IPS\CustomField
|
||||
{
|
||||
if ( \IPS\Application::appIsEnabled( 'forums' ) AND isset( $values['cf_topic'] ) )
|
||||
{
|
||||
$values['topic'] = $values['cf_topic'];
|
||||
/* Forcibly disable include in topic option if it is a paid field */
|
||||
$values['topic'] = ( isset( $values['downloads_field_paid'] ) AND $values['downloads_field_paid'] ) ? $values['cf_topic'] : 0;
|
||||
unset( $values['cf_topic'] );
|
||||
}
|
||||
|
||||
@@ -137,6 +146,10 @@ class _Field extends \IPS\CustomField
|
||||
unset( $values['pf_search_type'] );
|
||||
unset( $values['pf_allow_attachments'] );
|
||||
|
||||
$values['display_location'] = $values['downloads_field_location'];
|
||||
$values['paid_field'] = $values['downloads_field_paid'];
|
||||
unset( $values['downloads_field_location'], $values['downloads_field_paid'] );
|
||||
|
||||
return parent::formatFormValues( $values );
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\downloads\File;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,386 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Pending Version Model
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @package Invision Community
|
||||
* @subpackage Downloads
|
||||
* @since 6 Apr 2020
|
||||
*/
|
||||
|
||||
namespace IPS\downloads\File;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* PendingVersion Model
|
||||
*/
|
||||
class _PendingVersion extends \IPS\Content\Item implements \IPS\Content\Hideable
|
||||
{
|
||||
/**
|
||||
* @brief Application
|
||||
*/
|
||||
public static $application = 'downloads';
|
||||
|
||||
/**
|
||||
* @brief Module
|
||||
*/
|
||||
public static $module = 'downloads';
|
||||
|
||||
/**
|
||||
* @brief Database Table
|
||||
*/
|
||||
public static $databaseTable = 'downloads_files_pending';
|
||||
|
||||
/**
|
||||
* @brief Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'pending_';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] ID Database Column
|
||||
*/
|
||||
public static $databaseColumnId = 'id';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database ID Fields
|
||||
*/
|
||||
protected static $databaseIdFields = array('pending_file_id');
|
||||
|
||||
/**
|
||||
* @brief Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
|
||||
/**
|
||||
* @brief Database Column Map
|
||||
*/
|
||||
public static $databaseColumnMap = array(
|
||||
'author' => 'member_id',
|
||||
'title' => 'name',
|
||||
'date' => 'date',
|
||||
'approved' => 'approved',
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief Title
|
||||
*/
|
||||
public static $title = 'downloads_file_pending';
|
||||
|
||||
/**
|
||||
* @brief Icon
|
||||
*/
|
||||
public static $icon = 'download';
|
||||
|
||||
/**
|
||||
* @brief [Content] Key for hide reasons
|
||||
*/
|
||||
public static $hideLogKey = 'downloads-file-pending';
|
||||
|
||||
/**
|
||||
* Can unhide?
|
||||
*
|
||||
* @param \IPS\Member|NULL $member The member to check for (NULL for currently logged in member)
|
||||
* @return boolean
|
||||
*/
|
||||
public function canUnhide( $member=NULL )
|
||||
{
|
||||
return \IPS\downloads\File::modPermission( 'unhide', $member, $this->file()->containerWrapper() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Can hide?
|
||||
*
|
||||
* @param \IPS\Member|NULL $member The member to check for (NULL for currently logged in member)
|
||||
* @return bool
|
||||
*/
|
||||
public function canHide( $member=NULL )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function content()
|
||||
{
|
||||
return $this->form_values['file_changelog'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Cached URLs
|
||||
*/
|
||||
protected $_url = array();
|
||||
|
||||
/**
|
||||
* Pending URL
|
||||
*
|
||||
* @param null|string $action 'do' action
|
||||
* @return \IPS\Http\Url
|
||||
*/
|
||||
public function url( $action=NULL ): \IPS\Http\Url
|
||||
{
|
||||
$url = \IPS\Http\Url::internal( "app=downloads&module=downloads&controller=pending&file_id={$this->file()->id}&id={$this->id}", 'front', 'downloads_file_pending', $this->file()->name_furl );
|
||||
|
||||
if( $action )
|
||||
{
|
||||
$url = $url->setQueryString( 'do', $action );
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief store decoded form values
|
||||
*/
|
||||
protected $_formValues = NULL;
|
||||
|
||||
/**
|
||||
* Get form values decoded
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_form_values(): array
|
||||
{
|
||||
if( $this->_formValues !== NULL )
|
||||
{
|
||||
return $this->_formValues;
|
||||
}
|
||||
|
||||
return json_decode( $this->_data['form_values'], TRUE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for file name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_name(): string
|
||||
{
|
||||
return $this->file()->mapped('title');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get decoded record deletions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_record_deletions(): array
|
||||
{
|
||||
return json_decode( $this->_data['record_deletions'], TRUE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Default Values
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultValues()
|
||||
{
|
||||
$this->approved = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for download save version
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function saveVersion(): void
|
||||
{
|
||||
$this->save_version = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set form values
|
||||
*
|
||||
* @param array $values
|
||||
*/
|
||||
public function set_form_values( array $values ): void
|
||||
{
|
||||
$this->_formValues = $values;
|
||||
$this->_data['form_values'] = json_encode( $values );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set record deletion IDs
|
||||
*
|
||||
* @param array $ids
|
||||
*/
|
||||
public function set_record_deletions( array $ids ): void
|
||||
{
|
||||
$this->_data['record_deletions'] = json_encode( $ids );
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for download updated date
|
||||
*
|
||||
* @param $value New date
|
||||
*/
|
||||
public function set_updated( $value ): void
|
||||
{
|
||||
$this->date = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do Moderator Action
|
||||
*
|
||||
* @param string $action The action
|
||||
* @param \IPS\Member|NULL $member The member doing the action (NULL for currently logged in member)
|
||||
* @param string|NULL $reason Reason (for hides)
|
||||
* @param bool $immediately Delete immediately
|
||||
* @return void
|
||||
* @throws \OutOfRangeException|\InvalidArgumentException|\RuntimeException
|
||||
*/
|
||||
public function modAction( $action, \IPS\Member $member = NULL, $reason = NULL, $immediately = FALSE )
|
||||
{
|
||||
/* We always want to immediately delete these records instead of leaving them soft deleted */
|
||||
if( $action === 'delete' )
|
||||
{
|
||||
$file = $this->file();
|
||||
$this->delete();
|
||||
|
||||
/* Moderator log */
|
||||
\IPS\Session::i()->modLog( 'modlog__action_newversion_reject', array( (string) $file->url() => FALSE, $file->name => FALSE ), $file );
|
||||
|
||||
if( \IPS\Dispatcher::hasInstance() AND !\IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->redirect( $file->url() );
|
||||
}
|
||||
elseif( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->json( 'OK' );
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
elseif( $action == 'approve' OR $action == 'unhide' )
|
||||
{
|
||||
/* Moderator log */
|
||||
\IPS\Session::i()->modLog( 'modlog__action_newversion_approved', array( (string) $this->file()->url() => FALSE, $this->file()->name => FALSE ), $this->file() );
|
||||
}
|
||||
|
||||
return parent::modAction( $action, $member, $reason, $immediately );
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Record
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$ids = [];
|
||||
foreach( \IPS\Db::i()->select( '*', 'downloads_files_records', array( 'record_file_id=? AND record_hidden=1', $this->file_id ) ) as $record )
|
||||
{
|
||||
switch( $record['record_type'] )
|
||||
{
|
||||
case 'upload':
|
||||
case 'ssupload':
|
||||
$this->file()->deleteRecords( $record['record_id'], $record['record_location'], ( $record['record_location'] == 'ssupload' ) ? 'downloads_Screenshots' : 'downloads_Files' );
|
||||
break;
|
||||
case 'link':
|
||||
case 'sslink':
|
||||
$ids[] = $record['record_id'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( \count( $ids ) )
|
||||
{
|
||||
$this->file()->deleteRecords( $ids );
|
||||
}
|
||||
|
||||
parent::delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get related file object
|
||||
*
|
||||
* @return \IPS\downloads\File
|
||||
*/
|
||||
public function file()
|
||||
{
|
||||
return \IPS\downloads\File::load( $this->file_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Unhide
|
||||
*
|
||||
* @param \IPS\Member|NULL $member The member doing the action (NULL for currently logged in member)
|
||||
* @return void
|
||||
*/
|
||||
public function unhide( $member )
|
||||
{
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
|
||||
if( $this->save_version )
|
||||
{
|
||||
$this->file()->saveVersion();
|
||||
}
|
||||
|
||||
/* Remove hidden flag */
|
||||
\IPS\Db::i()->update( 'downloads_files_records', array( 'record_hidden' => 0 ), array( 'record_file_id=?', $this->file_id ) );
|
||||
|
||||
$deletions = $this->record_deletions;
|
||||
$file = $this->file();
|
||||
array_walk( $deletions['records'], function( $arr, $key ) use ( $file ) {
|
||||
$file->deleteRecords( $key, $arr['url'], $arr['handler'] );
|
||||
});
|
||||
$file->deleteRecords( $deletions['links'] );
|
||||
|
||||
$file->size = \floatval( \IPS\Db::i()->select( 'SUM(record_size)', 'downloads_files_records', array( 'record_file_id=? AND record_type=? AND record_backup=0', $file->id, 'upload' ), NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->first() );
|
||||
|
||||
/* Work out the new primary screenshot */
|
||||
try
|
||||
{
|
||||
$file->primary_screenshot = \IPS\Db::i()->select( 'record_id', 'downloads_files_records', array( 'record_file_id=? AND ( record_type=? OR record_type=? ) AND record_backup=0 AND record_hidden=0', $file->id, 'ssupload', 'sslink' ), 'record_default DESC, record_id ASC', NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->first();
|
||||
}
|
||||
catch ( \UnderflowException $e ) { }
|
||||
|
||||
/* The container may not have versions enabled */
|
||||
if( !empty( $this->form_values['file_version'] ) )
|
||||
{
|
||||
$file->version = $this->form_values['file_version'];
|
||||
}
|
||||
|
||||
$file->changelog = $this->content();
|
||||
$file->updated = time();
|
||||
$file->approver = $member->member_id;
|
||||
$file->approvedon = time();
|
||||
$file->save();
|
||||
|
||||
/* Saved form values for after new version processing */
|
||||
$formValues = $this->form_values;
|
||||
|
||||
/* Delete pending record */
|
||||
$this->delete();
|
||||
|
||||
/* Send notifications */
|
||||
if ( $file->open )
|
||||
{
|
||||
$file->sendUpdateNotifications();
|
||||
}
|
||||
|
||||
$file->processAfterNewVersion( $formValues );
|
||||
}
|
||||
|
||||
/**
|
||||
* Save Changed Columns
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
parent::save();
|
||||
|
||||
\IPS\File::claimAttachments( "downloads-{$this->file_id}-changelog", $this->file_id, $this->id, 'changelogpending' );
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\downloads\File;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\downloads\File;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -91,8 +91,10 @@ class _Review extends \IPS\Content\Review implements \IPS\Content\EditHistory, \
|
||||
*
|
||||
* @param string|NULL $action Action
|
||||
* @return \IPS\Http\Url
|
||||
* @throws \BadMethodCallException
|
||||
* @throws \IPS\Http\Url\Exception
|
||||
*/
|
||||
public function url( $action=NULL )
|
||||
public function url( $action='find' )
|
||||
{
|
||||
return parent::url( $action )->setQueryString( 'tab', 'reviews' );
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\downloads\Form;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -69,7 +69,7 @@ class _LinkedScreenshots extends \IPS\Helpers\Form\FormAbstract
|
||||
*/
|
||||
public function html()
|
||||
{
|
||||
if ( is_array( $this->value ) and !isset( $this->value['values'] ) )
|
||||
if ( \is_array( $this->value ) and !isset( $this->value['values'] ) )
|
||||
{
|
||||
$value = array( 'values' => $this->value, 'default' => \IPS\Request::i()->screenshots_primary_screenshot );
|
||||
}
|
||||
|
||||
Whitespace-only changes.
Reference in new issue
Block a user