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
@@ -11,21 +11,39 @@
|
||||
namespace IPS\core\ProfileFields;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\CustomField;
|
||||
use IPS\Data\Store;
|
||||
use IPS\Db;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Radio;
|
||||
use IPS\Helpers\Form\Select;
|
||||
use IPS\Helpers\Form\TextArea;
|
||||
use IPS\Helpers\Form\YesNo;
|
||||
use IPS\Log;
|
||||
use IPS\Login;
|
||||
use IPS\Member;
|
||||
use IPS\Member\ProfileStep;
|
||||
use IPS\Theme;
|
||||
use ParseError;
|
||||
use function defined;
|
||||
use function get_called_class;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom Profile Field Node
|
||||
*/
|
||||
class _Field extends \IPS\CustomField
|
||||
class Field extends CustomField
|
||||
{
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
protected static array $multitons;
|
||||
|
||||
/**
|
||||
* @brief Access level constants
|
||||
@@ -37,48 +55,47 @@ class _Field extends \IPS\CustomField
|
||||
const SEARCH = 4;
|
||||
const EDIT = 5;
|
||||
const PROFILE_COMPLETION = 6;
|
||||
|
||||
const PII_DATA_EXPORT = 7;
|
||||
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Table
|
||||
*/
|
||||
public static $databaseTable = 'core_pfields_data';
|
||||
public static ?string $databaseTable = 'core_pfields_data';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'pf_';
|
||||
public static string $databasePrefix = 'pf_';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] ID Database Column
|
||||
*/
|
||||
public static $databaseColumnId = 'id';
|
||||
public static string $databaseColumnId = 'id';
|
||||
|
||||
/**
|
||||
* @brief [Node] Parent Node ID Database Column
|
||||
*/
|
||||
public static $parentNodeColumnId = 'group_id';
|
||||
public static string $parentNodeColumnId = 'group_id';
|
||||
|
||||
/**
|
||||
* @brief [Node] Parent Node Class
|
||||
*/
|
||||
public static $parentNodeClass = 'IPS\core\ProfileFields\Group';
|
||||
public static string $parentNodeClass = 'IPS\core\ProfileFields\Group';
|
||||
|
||||
/**
|
||||
* @brief [Node] Order Database Column
|
||||
*/
|
||||
public static $databaseColumnOrder = 'position';
|
||||
public static ?string $databaseColumnOrder = 'position';
|
||||
|
||||
/**
|
||||
* @brief [CustomField] Title/Description lang prefix
|
||||
*/
|
||||
protected static $langKey = 'core_pfield';
|
||||
protected static string $langKey = 'core_pfield';
|
||||
|
||||
/**
|
||||
* @brief [Node] ACP Restrictions
|
||||
*/
|
||||
protected static $restrictions = array(
|
||||
protected static ?array $restrictions = array(
|
||||
'app' => 'core',
|
||||
'module' => 'membersettings',
|
||||
'prefix' => 'profilefields_',
|
||||
@@ -87,36 +104,43 @@ class _Field extends \IPS\CustomField
|
||||
/**
|
||||
* @brief [Node] Node Title
|
||||
*/
|
||||
public static $nodeTitle = 'profile_field';
|
||||
public static string $nodeTitle = 'profile_field';
|
||||
|
||||
/**
|
||||
* @brief [CustomField] Editor Options
|
||||
*/
|
||||
public static $editorOptions = array( 'app' => 'core', 'key' => 'CustomField' );
|
||||
public static array $editorOptions = array( 'app' => 'core', 'key' => 'CustomField' );
|
||||
|
||||
/**
|
||||
* @brief [Node] Title prefix. If specified, will look for a language key with "{$key}_title" as the key
|
||||
*/
|
||||
public static $titleLangPrefix = 'core_pfield_';
|
||||
public static ?string $titleLangPrefix = 'core_pfield_';
|
||||
|
||||
/**
|
||||
* @brief [CustomField] Database table
|
||||
*/
|
||||
protected static string $contentDatabaseTable = 'core_pfields_content';
|
||||
|
||||
/**
|
||||
* @brief [CustomField] FileStorage Extension for Upload fields
|
||||
*/
|
||||
public static $uploadStorageExtension = 'core_ProfileField';
|
||||
|
||||
public static string $uploadStorageExtension = 'core_ProfileField';
|
||||
|
||||
/**
|
||||
* Display Value
|
||||
*
|
||||
* @param mixed $value The value
|
||||
* @param bool $showSensitiveInformation If TRUE, potentially sensitive data (like passwords) will be displayed - otherwise will be blanked out
|
||||
* @param int $location \IPS\core\ProfileFields\Field::PROFILE for profile, \IPS\core\ProfileFields\Field::REG for registration screen, \IPS\core\ProfileFields\Field::STAFF for ModCP/ACP or \IPS\core\ProfileFields\Field::CONTENT for content areas (post bit)
|
||||
* @param \IPS\Member|NULL $member Member who completed the profile field
|
||||
* @return string
|
||||
* @param mixed|null $value The value
|
||||
* @param bool $showSensitiveInformation If TRUE, potentially sensitive data (like passwords) will be displayed - otherwise will be blanked out
|
||||
* @param null $separator
|
||||
* @param int $location \IPS\core\ProfileFields\Field::PROFILE for profile, \IPS\core\ProfileFields\Field::REG for registration screen, \IPS\core\ProfileFields\Field::STAFF for ModCP/ACP or \IPS\core\ProfileFields\Field::CONTENT for content areas (post bit)
|
||||
* @param Member|NULL $member Member who completed the profile field
|
||||
* @param bool $bypassCustomFormatting
|
||||
* @return string
|
||||
*/
|
||||
public function displayValue( $value=NULL, $showSensitiveInformation=FALSE, $location=0, \IPS\Member $member = null, $bypassCustomFormatting=FALSE, $separator=NULL )
|
||||
public function displayValue( mixed $value=NULL, bool $showSensitiveInformation=FALSE, $separator=NULL, int $location=0, Member $member = null, bool $bypassCustomFormatting=FALSE ): string
|
||||
{
|
||||
$formattedValue = parent::displayValue( $value, $showSensitiveInformation, $separator );
|
||||
$member = $member ?: new \IPS\Member;
|
||||
$member = $member ?: new Member;
|
||||
|
||||
switch( $location )
|
||||
{
|
||||
@@ -128,10 +152,9 @@ class _Field extends \IPS\CustomField
|
||||
}
|
||||
|
||||
/* If we are using the "default" formatting, set that up now */
|
||||
$format = $this->format ?: "<strong>{\$title}:</strong> {\$processedContent}";
|
||||
$format = $this->format ?: "<strong data-i-el='title'>{\$title}:</strong><div data-i-el='value'>{\$processedContent}</div>";
|
||||
|
||||
return $this->parseHtmlLogic( $format, $value, $formattedValue, $member );
|
||||
break;
|
||||
|
||||
case ( static::PROFILE ):
|
||||
case ( static::PROFILE_COMPLETION ):
|
||||
@@ -141,14 +164,12 @@ class _Field extends \IPS\CustomField
|
||||
}
|
||||
else
|
||||
{
|
||||
return $formattedValue;
|
||||
return (string) $formattedValue;
|
||||
}
|
||||
break;
|
||||
|
||||
case ( static::STAFF ) :
|
||||
default:
|
||||
return ( $this->type == 'Editor' ) ? \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->richText( $formattedValue ) : $formattedValue;
|
||||
break;
|
||||
return ( $this->type == 'Editor' ) ? Theme::i()->getTemplate( 'global', 'core', 'global' )->richText( $formattedValue ) : (string) $formattedValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,17 +178,17 @@ class _Field extends \IPS\CustomField
|
||||
*
|
||||
* @param string $template Format (which may include HTML logic)
|
||||
* @param string $rawValue Raw value
|
||||
* @param string $value Formatted value
|
||||
* @param \IPS\Member $member Member who completed the profile field
|
||||
* @param mixed $value Formatted value
|
||||
* @param Member $member Member who completed the profile field
|
||||
* @return string
|
||||
*/
|
||||
protected function parseHtmlLogic( $template, $rawValue, $value, \IPS\Member $member )
|
||||
protected function parseHtmlLogic( string $template, string $rawValue, mixed $value, Member $member ) : string
|
||||
{
|
||||
try
|
||||
{
|
||||
$functionName = 'profilefields_t_' . md5( $template );
|
||||
|
||||
if ( ! isset( \IPS\Data\Store::i()->$functionName ) )
|
||||
if ( ! isset( Store::i()->$functionName ) )
|
||||
{
|
||||
/* We need the "raw" content because HTML is typically used to format the value */
|
||||
$template = str_replace( '{$processedContent}', '{$processedContent|raw}', $template );
|
||||
@@ -176,25 +197,23 @@ class _Field extends \IPS\CustomField
|
||||
if ( $this->type == 'Editor' )
|
||||
{
|
||||
$template = str_replace( '{$content}', '{$content|raw}', $template );
|
||||
$template = \IPS\Theme::i()->getTemplate('global', 'core', 'global')->richText( $template );
|
||||
$template = Theme::i()->getTemplate('global', 'core', 'global')->richText( $template );
|
||||
}
|
||||
|
||||
/* $content is the raw content from the database, $processedContent is the parsed content ready for display */
|
||||
\IPS\Data\Store::i()->$functionName = \IPS\Theme::compileTemplate( $template, $functionName, '$title, $content, $processedContent, $member, $member_id', true );
|
||||
Store::i()->$functionName = Theme::compileTemplate( $template, $functionName, '$title, $content, $processedContent, $member, $member_id' );
|
||||
}
|
||||
|
||||
\IPS\Theme::runProcessFunction( \IPS\Data\Store::i()->$functionName, $functionName );
|
||||
Theme::runProcessFunction( Store::i()->$functionName, $functionName );
|
||||
|
||||
$themeFunction = 'IPS\\Theme\\'. $functionName;
|
||||
$html = $themeFunction( \IPS\Member::loggedIn()->language()->addToStack( static::$langKey . '_' . $this->id ), $rawValue, $value, $member, $member->member_id );
|
||||
|
||||
return $html;
|
||||
return $themeFunction( Member::loggedIn()->language()->addToStack( static::$langKey . '_' . $this->id ), $rawValue, $value, $member, $member->member_id );
|
||||
}
|
||||
catch ( \ParseError $e )
|
||||
catch ( ParseError $e )
|
||||
{
|
||||
@ob_end_clean();
|
||||
\IPS\Log::log( $e, 'pfield_error' );
|
||||
return $value;
|
||||
Log::log( $e, 'pfield_error' );
|
||||
return (string) $value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,19 +222,19 @@ class _Field extends \IPS\CustomField
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function fieldData()
|
||||
public static function fieldData() : array
|
||||
{
|
||||
if ( !isset( \IPS\Data\Store::i()->profileFields ) )
|
||||
if ( !isset( Store::i()->profileFields ) )
|
||||
{
|
||||
$fields = array();
|
||||
$display = FALSE;
|
||||
|
||||
foreach ( \IPS\Db::i()->select( '*', 'core_pfields_groups', NULL, 'pf_group_order' ) as $row )
|
||||
foreach ( Db::i()->select( '*', 'core_pfields_groups', NULL, 'pf_group_order' ) as $row )
|
||||
{
|
||||
$fields[ $row['pf_group_id'] ] = array();
|
||||
}
|
||||
|
||||
foreach ( \IPS\Db::i()->select( '*', 'core_pfields_data', NULL, 'pf_position' ) as $row )
|
||||
foreach ( Db::i()->select( '*', 'core_pfields_data', NULL, 'pf_position' ) as $row )
|
||||
{
|
||||
$fields[ $row['pf_group_id'] ][ $row['pf_id'] ] = $row;
|
||||
|
||||
@@ -225,10 +244,10 @@ class _Field extends \IPS\CustomField
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Data\Store::i()->profileFields = array( 'fields' => $fields, 'display' => $display );
|
||||
Store::i()->profileFields = array( 'fields' => $fields, 'display' => $display );
|
||||
}
|
||||
|
||||
return \IPS\Data\Store::i()->profileFields['fields'];
|
||||
return Store::i()->profileFields['fields'];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -236,13 +255,13 @@ class _Field extends \IPS\CustomField
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function fieldsForContentView()
|
||||
public static function fieldsForContentView() : bool
|
||||
{
|
||||
if ( !isset( \IPS\Data\Store::i()->profileFields ) )
|
||||
if ( !isset( Store::i()->profileFields ) )
|
||||
{
|
||||
static::fieldData();
|
||||
}
|
||||
return \IPS\Data\Store::i()->profileFields['display'];
|
||||
return Store::i()->profileFields['display'];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -250,10 +269,10 @@ class _Field extends \IPS\CustomField
|
||||
*
|
||||
* @param array $values Current values
|
||||
* @param int $location \IPS\core\ProfileFields\Field::PROFILE for profile, \IPS\core\ProfileFields\Field::REG for registration screen, \IPS\core\ProfileFields\Field::STAFF for ModCP/ACP, \IPS\core\ProfileFields\Field::EDIT for member editing
|
||||
* @param \IPS\Member|NULL $member IPS Member Object
|
||||
* @param Member|NULL $member IPS Member Object
|
||||
* @return array
|
||||
*/
|
||||
public static function fields( $values=array(), $location=0, ?\IPS\Member $member = null ): array
|
||||
public static function fields( array $values=array(), int $location=0, ?Member $member = null ): array
|
||||
{
|
||||
if( !$values )
|
||||
{
|
||||
@@ -282,7 +301,7 @@ class _Field extends \IPS\CustomField
|
||||
$values['field_' . $row['pf_id'] ] = NULL;
|
||||
}
|
||||
|
||||
static::$editorOptions['autoSaveKey'] = md5( \get_called_class() . '-' . $row['pf_id'] ) . ( $member ? '-' . $member->member_id : '' );
|
||||
static::$editorOptions['autoSaveKey'] = md5( get_called_class() . '-' . $row['pf_id'] ) . ( $member ? '-' . $member->member_id : '' );
|
||||
|
||||
if( $row['pf_type'] == 'Editor' AND $member )
|
||||
{
|
||||
@@ -304,20 +323,18 @@ class _Field extends \IPS\CustomField
|
||||
/**
|
||||
* Load Record with Member
|
||||
*
|
||||
* @see \IPS\Db::build
|
||||
* @param int|string $id ID
|
||||
* @param string $idField The database column that the $id parameter pertains to (NULL will use static::$databaseColumnId)
|
||||
* @param mixed $extraWhereClause Additional where clause(s) (see \IPS\Db::build for details)
|
||||
* @param \IPS\Member|NULL $member IPS Member Object
|
||||
* @return static
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \OutOfRangeException
|
||||
* @param int|string $id ID
|
||||
* @param string|null $idField The database column that the $id parameter pertains to (NULL will use static::$databaseColumnId)
|
||||
* @param mixed $extraWhereClause Additional where clause(s) (see \IPS\Db::build for details)
|
||||
* @param Member|NULL $member IPS Member Object
|
||||
* @return static
|
||||
* @see Db::build
|
||||
*/
|
||||
public static function loadWithMember( $id, $idField=NULL, $extraWhereClause=NULL, \IPS\Member $member = NULL ): self
|
||||
public static function loadWithMember( int|string $id, ?string $idField=NULL, mixed $extraWhereClause=NULL, ?Member $member = NULL ): self
|
||||
{
|
||||
$result = parent::load( $id, $idField, $extraWhereClause );
|
||||
|
||||
static::$editorOptions['autoSaveKey'] = md5( \get_called_class() . '-' . $result->id ) . ( $member ? '-' . $member->member_id : '' );
|
||||
static::$editorOptions['autoSaveKey'] = md5( get_called_class() . '-' . $result->id ) . ( $member ? '-' . $member->member_id : '' );
|
||||
|
||||
if( $result->type == 'Editor' AND $member )
|
||||
{
|
||||
@@ -335,7 +352,7 @@ class _Field extends \IPS\CustomField
|
||||
* @param bool $raw Returns the raw value if true or the display value if false. Useful for comparisons for field types like Yes/NO to see if a value is set.
|
||||
* @return array
|
||||
*/
|
||||
public static function values( $values, $location=0, $raw=FALSE )
|
||||
public static function values( array $values, int $location=0, bool $raw=FALSE ) : array
|
||||
{
|
||||
$return = array();
|
||||
foreach ( static::fieldData() as $groupId => $fields )
|
||||
@@ -346,18 +363,19 @@ class _Field extends \IPS\CustomField
|
||||
switch( $location )
|
||||
{
|
||||
case ( static::CONTENT ):
|
||||
if( $row['pf_topic_hide'] == 'hide' OR ( $row['pf_topic_hide'] == 'staff' AND !\IPS\Member::loggedIn()->isAdmin() AND !\IPS\Member::loggedIn()->modPermissions() ) )
|
||||
if( $row['pf_topic_hide'] == 'hide' OR ( $row['pf_topic_hide'] == 'staff' AND !Member::loggedIn()->isAdmin() AND !Member::loggedIn()->modPermissions() ) )
|
||||
{
|
||||
continue 2;
|
||||
}
|
||||
break;
|
||||
|
||||
case ( static::PROFILE ):
|
||||
if( $row['pf_member_hide'] == 'hide' OR ( $row['pf_member_hide'] == 'staff' AND !\IPS\Member::loggedIn()->isAdmin() AND !\IPS\Member::loggedIn()->modPermissions() ) OR ( $row['pf_member_hide'] == 'owner' AND !\IPS\Member::loggedIn()->isAdmin() AND !\IPS\Member::loggedIn()->modPermissions() AND \IPS\Member::loggedIn()->member_id != $values['member_id'] ) )
|
||||
if( $row['pf_member_hide'] == 'hide' OR ( $row['pf_member_hide'] == 'staff' AND !Member::loggedIn()->isAdmin() AND !Member::loggedIn()->modPermissions() ) OR ( $row['pf_member_hide'] == 'owner' AND !Member::loggedIn()->isAdmin() AND !Member::loggedIn()->modPermissions() AND Member::loggedIn()->member_id != $values['member_id'] ) )
|
||||
{
|
||||
continue 2;
|
||||
}
|
||||
break;
|
||||
|
||||
case ( static::PII_DATA_EXPORT ):
|
||||
if( !$row['pf_contains_pii'] )
|
||||
{
|
||||
@@ -371,7 +389,7 @@ class _Field extends \IPS\CustomField
|
||||
continue;
|
||||
}
|
||||
|
||||
$return[ $groupId ][ static::$langKey . '_' . $row['pf_id'] ] = !( $raw ) ? static::constructFromData( $row )->displayValue( $values[ 'field_' . $row['pf_id'] ], FALSE, $location, \IPS\Member::load( $values['member_id'] ) ) : $values[ 'field_' . $row['pf_id'] ];
|
||||
$return[ $groupId ][ static::$langKey . '_' . $row['pf_id'] ] = !( $raw ) ? static::constructFromData( $row )->displayValue( $values[ 'field_' . $row['pf_id'] ], FALSE, NULL, $location, Member::load( $values['member_id'] ) ) : $values[ 'field_' . $row['pf_id'] ];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -381,15 +399,15 @@ class _Field extends \IPS\CustomField
|
||||
/**
|
||||
* @brief Field ID controlling formatting that we should show/hide depending upon field type selection
|
||||
*/
|
||||
protected $fieldFormattingId = 'pf_topic_hide';
|
||||
protected string $fieldFormattingId = 'pf_topic_hide';
|
||||
|
||||
/**
|
||||
* [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 );
|
||||
|
||||
@@ -399,7 +417,7 @@ class _Field extends \IPS\CustomField
|
||||
|
||||
$form->addHeader( 'pfield_permissions' );
|
||||
|
||||
if ( \IPS\Login::registrationType() != 'full' )
|
||||
if ( Login::registrationType() != 'full' )
|
||||
{
|
||||
/* Quick register is enabled, so do not allow required to be set */
|
||||
if ( isset( $form->elements['']['pf_not_null'] ) )
|
||||
@@ -410,25 +428,24 @@ class _Field extends \IPS\CustomField
|
||||
else
|
||||
{
|
||||
/* Quick register is off, so show normal 'reg' field */
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'pf_show_on_reg', $this->id ? $this->show_on_reg : TRUE, FALSE, array(), NULL, NULL, NULL, 'pf_show_on_reg' ) );
|
||||
$form->add( new YesNo( 'pf_show_on_reg', $this->id ? $this->show_on_reg : TRUE, FALSE, array(), NULL, NULL, NULL, 'pf_show_on_reg' ) );
|
||||
}
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'pf_member_edit', $this->id ? $this->member_edit : TRUE, FALSE, array(), NULL, NULL, NULL, 'pf_member_edit' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'pf_member_hide', $this->id ? $this->member_hide : 'all', TRUE, array( 'options' => array( 'hide' => 'custom_fields_hide', 'staff' => 'custom_fields_staff', 'owner' => 'custom_fields_staff_owner', 'all' => 'custom_fields_all' ), 'toggles' => array( 'staff' => array( 'pf_profile_format' ), 'all' => array( 'pf_profile_format' ), 'owner' => array( 'pf_profile_format' ) ) ), NULL, NULL, NULL, 'pf_member_hide' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'pf_topic_hide', $this->id ? $this->topic_hide : 'hide', TRUE, array( 'options' => array( 'hide' => 'custom_fields_hide', 'staff' => 'custom_fields_staff', 'all' => 'custom_fields_all' ), 'toggles' => array( 'staff' => array( 'pf_format' ), 'all' => array( 'pf_format' ) ) ), NULL, NULL, NULL, 'pf_topic_hide' ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'pf_contains_pii', $this->id ? $this->contains_pii : FALSE, FALSE ) );
|
||||
|
||||
$form->add( new YesNo( 'pf_member_edit', $this->id ? $this->member_edit : TRUE, FALSE, array(), NULL, NULL, NULL, 'pf_member_edit' ) );
|
||||
$form->add( new Radio( 'pf_member_hide', $this->id ? $this->member_hide : 'all', TRUE, array( 'options' => array( 'hide' => 'custom_fields_hide', 'staff' => 'custom_fields_staff', 'owner' => 'custom_fields_staff_owner', 'all' => 'custom_fields_all' ), 'toggles' => array( 'staff' => array( 'pf_profile_format' ), 'all' => array( 'pf_profile_format' ), 'owner' => array( 'pf_profile_format' ) ) ), NULL, NULL, NULL, 'pf_member_hide' ) );
|
||||
$form->add( new Radio( 'pf_topic_hide', $this->id ? $this->topic_hide : 'hide', TRUE, array( 'options' => array( 'hide' => 'custom_fields_hide', 'staff' => 'custom_fields_staff', 'all' => 'custom_fields_all' ), 'toggles' => array( 'staff' => array( 'pf_format' ), 'all' => array( 'pf_format' ) ) ), NULL, NULL, NULL, 'pf_topic_hide' ) );
|
||||
|
||||
$form->addHeader( 'pfield_displayoptions' );
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'pf_search_type', $this->id ? $this->search_type : 'loose', FALSE, array( 'options' => array( 'exact' => 'pf_search_type_exact', 'loose' => 'pf_search_type_loose', '' => 'pf_search_type_none' ) ), NULL, NULL, NULL, 'pf_search_type' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'pf_search_type_on_off', $this->id ? $this->search_type : 'exact', FALSE, array( 'options' => array( 'exact' => 'pf_search_type_exact', '' => 'pf_search_type_none' ) ), NULL, NULL, NULL, 'pf_search_type_on_off' ) );
|
||||
$form->add( new Select( 'pf_search_type', $this->id ? $this->search_type : 'loose', FALSE, array( 'options' => array( 'exact' => 'pf_search_type_exact', 'loose' => 'pf_search_type_loose', '' => 'pf_search_type_none' ) ), NULL, NULL, NULL, 'pf_search_type' ) );
|
||||
$form->add( new Select( 'pf_search_type_on_off', $this->id ? $this->search_type : 'exact', FALSE, array( 'options' => array( 'exact' => 'pf_search_type_exact', '' => 'pf_search_type_none' ) ), NULL, NULL, NULL, 'pf_search_type_on_off' ) );
|
||||
|
||||
$formatOptions = array( 'default' => 'custom_field_format_default', 'custom' => 'custom_field_format_custom' );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'pf_profile_format', $this->profile_format ? 'custom' : 'default', TRUE, array( 'options' => $formatOptions, 'toggles' => array( 'custom' => array( 'pf_profile_format_custom' ) ) ), NULL, NULL, NULL, 'pf_profile_format' ) );
|
||||
$form->add( new Radio( 'pf_profile_format', $this->profile_format ? 'custom' : 'default', TRUE, array( 'options' => $formatOptions, 'toggles' => array( 'custom' => array( 'pf_profile_format_custom' ) ) ), NULL, NULL, NULL, 'pf_profile_format' ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\TextArea( 'pf_profile_format_custom', $this->profile_format, FALSE, array( 'placeholder' => "<strong>{\$title}:</strong> {\$content}" ), NULL, NULL, NULL, 'pf_profile_format_custom' ) );
|
||||
$form->add( new TextArea( 'pf_profile_format_custom', $this->profile_format, FALSE, array( 'placeholder' => "<strong>{\$title}:</strong> {\$content}" ), NULL, NULL, NULL, 'pf_profile_format_custom' ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'pf_format', $this->format ? 'custom' : 'default', TRUE, array( 'options' => $formatOptions, 'toggles' => array( 'custom' => array( 'pf_format_custom' ) ) ), NULL, NULL, NULL, 'pf_format' ) );
|
||||
$form->add( new \IPS\Helpers\Form\TextArea( 'pf_format_custom', $this->format, FALSE, array( 'placeholder' => "<strong>{\$title}:</strong> {\$content}" ), NULL, NULL, NULL, 'pf_format_custom' ) );
|
||||
$form->add( new Radio( 'pf_format', $this->format ? 'custom' : 'default', TRUE, array( 'options' => $formatOptions, 'toggles' => array( 'custom' => array( 'pf_format_custom' ) ) ), NULL, NULL, NULL, 'pf_format' ) );
|
||||
$form->add( new TextArea( 'pf_format_custom', $this->format, FALSE, array( 'placeholder' => "<strong>{\$title}:</strong> {\$content}" ), NULL, NULL, NULL, 'pf_format_custom' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -437,7 +454,7 @@ class _Field extends \IPS\CustomField
|
||||
* @param array $values Values from the form
|
||||
* @return array
|
||||
*/
|
||||
public function formatFormValues( $values )
|
||||
public function formatFormValues( array $values ): array
|
||||
{
|
||||
if( array_key_exists( 'pf_search_type', $values ) )
|
||||
{
|
||||
@@ -480,59 +497,31 @@ class _Field extends \IPS\CustomField
|
||||
return parent::formatFormValues( $values );
|
||||
}
|
||||
|
||||
/**
|
||||
* [ActiveRecord] Save Record
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
if( $this->_new )
|
||||
{
|
||||
$return = parent::save();
|
||||
\IPS\Db::i()->addColumn( 'core_pfields_content', array( 'name' => "field_{$this->id}", 'type' => 'MEDIUMTEXT' ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$return = parent::save();
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Caches
|
||||
* @note Defined cache keys will be cleared automatically as needed
|
||||
*/
|
||||
protected $caches = array( 'profileFields' );
|
||||
|
||||
/**
|
||||
* @brief [CustomField] Database table
|
||||
*/
|
||||
protected static $contentDatabaseTable;
|
||||
protected array $caches = array( 'profileFields' );
|
||||
|
||||
/**
|
||||
* [ActiveRecord] Delete Record
|
||||
*
|
||||
* @return void
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
public function delete(): void
|
||||
{
|
||||
static::$contentDatabaseTable = 'core_pfields_content';
|
||||
|
||||
parent::delete();
|
||||
|
||||
/* Do we need to do stuff with profile steps? */
|
||||
\IPS\Member\ProfileStep::resync();
|
||||
ProfileStep::resync();
|
||||
}
|
||||
}
|
||||
|
||||
/* This is only here for backwards compatibility */
|
||||
const PROFILE = _Field::PROFILE;
|
||||
const REG = _Field::REG;
|
||||
const STAFF = _Field::STAFF;
|
||||
const CONTENT = _Field::CONTENT;
|
||||
const SEARCH = _Field::SEARCH;
|
||||
const EDIT = _Field::EDIT;
|
||||
|
||||
const PROFILE_COMPLETION = _Field::PROFILE_COMPLETION;
|
||||
const PROFILE = Field::PROFILE;
|
||||
const REG = Field::REG;
|
||||
const STAFF = Field::STAFF;
|
||||
const CONTENT = Field::CONTENT;
|
||||
const SEARCH = Field::SEARCH;
|
||||
const EDIT = Field::EDIT;
|
||||
const PROFILE_COMPLETION = Field::PROFILE_COMPLETION;
|
||||
Reference in new issue
Block a user