Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -13,99 +13,83 @@ namespace IPS\downloads;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
|
||||
use IPS\Lang;
|
||||
use IPS\Application;
|
||||
use IPS\CustomField;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Radio;
|
||||
use IPS\Helpers\Form\TextArea;
|
||||
use IPS\Helpers\Form\YesNo;
|
||||
use IPS\Member;
|
||||
use IPS\Settings;
|
||||
use function defined;
|
||||
|
||||
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' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Field Node
|
||||
*/
|
||||
class _Field extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
class Field extends CustomField
|
||||
{
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
protected static array $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Table
|
||||
*/
|
||||
public static $databaseTable = 'downloads_cfields';
|
||||
public static ?string $databaseTable = 'downloads_cfields';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'cf_';
|
||||
public static string $databasePrefix = 'cf_';
|
||||
|
||||
/**
|
||||
* @brief [Node] Order Database Column
|
||||
*/
|
||||
public static $databaseColumnOrder = 'position';
|
||||
public static ?string $databaseColumnOrder = 'position';
|
||||
|
||||
/**
|
||||
* @brief [CustomField] Column Map
|
||||
*/
|
||||
public static $databaseColumnMap = array(
|
||||
public static array $databaseColumnMap = array(
|
||||
'not_null' => 'not_null'
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief [Node] Node Title
|
||||
*/
|
||||
public static $nodeTitle = 'ccfields';
|
||||
public static string $nodeTitle = 'ccfields';
|
||||
|
||||
/**
|
||||
* @brief [CustomField] Title/Description lang prefix
|
||||
*/
|
||||
protected static $langKey = 'downloads_field';
|
||||
protected static string $langKey = 'downloads_field';
|
||||
|
||||
/**
|
||||
* @brief [Node] Title prefix. If specified, will look for a language key with "{$key}_title" as the key
|
||||
*/
|
||||
public static $titleLangPrefix = 'downloads_field_';
|
||||
public static ?string $titleLangPrefix = 'downloads_field_';
|
||||
|
||||
/**
|
||||
* @brief [CustomField] Content Table
|
||||
*/
|
||||
public static $contentDatabaseTable = 'downloads_ccontent';
|
||||
public static string $contentDatabaseTable = 'downloads_ccontent';
|
||||
|
||||
/**
|
||||
* @brief [CustomField] Set to TRUE if uploads fields are capable of holding the submitted content for moderation
|
||||
*/
|
||||
public static $uploadsCanBeModerated = TRUE;
|
||||
|
||||
/**
|
||||
* @brief The map of permission columns
|
||||
*/
|
||||
public static $permissionMap = array(
|
||||
'view' => 'view',
|
||||
'edit' => 2,
|
||||
'add' => 3
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief [Node] App for permission index
|
||||
*/
|
||||
public static $permApp = 'downloads';
|
||||
|
||||
/**
|
||||
* @brief [Node] Type for permission index
|
||||
*/
|
||||
public static $permType = 'fields';
|
||||
|
||||
/**
|
||||
* @brief [Node] Prefix string that is automatically prepended to permission matrix language strings
|
||||
*/
|
||||
public static $permissionLangPrefix = 'perm_cfield_';
|
||||
public static bool $uploadsCanBeModerated = TRUE;
|
||||
|
||||
/**
|
||||
* @brief [Node] ACP Restrictions
|
||||
*/
|
||||
protected static $restrictions = array(
|
||||
protected static ?array $restrictions = array(
|
||||
'app' => 'downloads',
|
||||
'module' => 'downloads',
|
||||
'prefix' => 'fields_',
|
||||
@@ -114,69 +98,58 @@ class _Field extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
/**
|
||||
* @brief [CustomField] Editor Options
|
||||
*/
|
||||
public static $editorOptions = array( 'app' => 'downloads', 'key' => 'Downloads' );
|
||||
public static array $editorOptions = array( 'app' => 'downloads', 'key' => 'Downloads' );
|
||||
|
||||
/**
|
||||
* @brief [CustomField] FileStorage Extension for Upload fields
|
||||
*/
|
||||
public static $uploadStorageExtension = 'downloads_FileField';
|
||||
public static string $uploadStorageExtension = 'downloads_FileField';
|
||||
|
||||
/**
|
||||
* @brief [CustomField] An array of the 'keys' of the Field types toggles that shouldn't be an option. The main use is for excluding polls
|
||||
*/
|
||||
public static $disabledFieldTypes = array( 'Poll' );
|
||||
public static array $disabledFieldTypes = array( 'Poll' );
|
||||
|
||||
|
||||
/**
|
||||
* Get topic format
|
||||
*
|
||||
* @return void
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_topic_format()
|
||||
public function get_topic_format() : string|null
|
||||
{
|
||||
return $this->format;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* [Node] Does the currently logged in user have permission to edit permissions for this node?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function canManagePermissions()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Add/Edit Form
|
||||
*
|
||||
* @param \IPS\Helpers\Form $form The form
|
||||
* @param Form $form The form
|
||||
* @return void
|
||||
*/
|
||||
public function form( &$form )
|
||||
public function form( Form &$form ) : void
|
||||
{
|
||||
parent::form( $form );
|
||||
|
||||
|
||||
|
||||
unset( $form->elements['']['pf_search_type'] );
|
||||
unset( $form->elements['']['pf_search_type_on_off'] );
|
||||
\IPS\Member::loggedIn()->language()->words['field_displayoptions'] = \IPS\Member::loggedIn()->language()->addToStack('pfield_displayoptions');
|
||||
Member::loggedIn()->language()->words['field_displayoptions'] = Member::loggedIn()->language()->addToStack('pfield_displayoptions');
|
||||
|
||||
$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' ) );
|
||||
$form->add( new 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 )
|
||||
if ( Application::appIsEnabled( 'nexus' ) and 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' ) ) ) );
|
||||
$form->add( new 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' ) )
|
||||
if ( Application::appIsEnabled( 'forums' ) )
|
||||
{
|
||||
$form->addHeader('category_forums_integration');
|
||||
$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' ) );
|
||||
$form->add( new YesNo( 'cf_topic', $this->topic, FALSE, array(), NULL, NULL, NULL, 'idm_cf_topic' ) );
|
||||
$form->add( new 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');
|
||||
Member::loggedIn()->language()->words['pf_format_desc'] = Member::loggedIn()->language()->addToStack('cf_format_desc');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,9 +159,9 @@ class _Field extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
* @param array $values Values from the form
|
||||
* @return array
|
||||
*/
|
||||
public function formatFormValues( $values )
|
||||
public function formatFormValues( array $values ): array
|
||||
{
|
||||
if ( \IPS\Application::appIsEnabled( 'forums' ) AND isset( $values['cf_topic'] ) )
|
||||
if ( Application::appIsEnabled( 'forums' ) AND isset( $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'] ) ? 0 : $values['cf_topic'];
|
||||
@@ -205,28 +178,4 @@ class _Field extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
|
||||
return parent::formatFormValues( $values );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get output for API
|
||||
*
|
||||
* @param \IPS\Member|NULL $authorizedMember The member making the API request or NULL for API Key / client_credentials
|
||||
* @param array $fieldValues Current values for a specific file
|
||||
* @return array
|
||||
* @apiresponse int id ID number
|
||||
* @apiresponse string name Name
|
||||
* @apiresponse string description Description
|
||||
* @apiresponse string value Raw field value from the database
|
||||
* @apiresponse string|int|array|boolean displayValue Parsed Field value with all field data
|
||||
*/
|
||||
public function apiOutput( \IPS\Member $authorizedMember = NULL, $fieldValues=array() )
|
||||
{
|
||||
$lang = $authorizedMember ? $authorizedMember->language() : Lang::load( Lang::defaultLanguage() );
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $lang->addToStack( 'downloads_field_' . $this->id ),
|
||||
'description' => $lang->addToStack( 'downloads_field_' . $this->id . '_desc' ),
|
||||
'value' => $fieldValues[ 'field_' . $this->id ] ?? null,
|
||||
'displayValue' => $this->apiValue( $fieldValues[ 'field_' . $this->id ] )
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user