DateFormat
3 days ago
FieldTypeConfigurator
3 days ago
Media
3 days ago
Post
3 days ago
Pro
3 days ago
ActionIcons.php
3 days ago
AttachmentDisplay.php
3 days ago
BaseComponentFactory.php
3 days ago
BeforeAfter.php
3 days ago
BooleanValues.php
3 days ago
CharacterLimit.php
3 days ago
ColumnInfo.php
3 days ago
CommentDisplay.php
3 days ago
CommentLink.php
3 days ago
CommentStatus.php
3 days ago
CustomField.php
3 days ago
CustomFieldFactory.php
3 days ago
DateFormat.php
3 days ago
DateSaveFormat.php
3 days ago
ExifData.php
3 days ago
FieldType.php
3 days ago
FieldTypeFactory.php
3 days ago
FieldTypeFactoryBuilder.php
3 days ago
FileDisplay.php
3 days ago
FileLink.php
3 days ago
FilePreviewSize.php
3 days ago
HiddenInput.php
3 days ago
HiddenLabel.php
3 days ago
ImageSize.php
3 days ago
ImageSizeBase.php
3 days ago
IncludeMissingSizes.php
3 days ago
InputNameAware.php
3 days ago
IsLink.php
3 days ago
IsLinkable.php
3 days ago
IsMultiple.php
3 days ago
Label.php
3 days ago
LinkLabel.php
3 days ago
LinkToMenu.php
3 days ago
LinkablePostProperty.php
3 days ago
MediaLink.php
3 days ago
Message.php
3 days ago
ModalDisplay.php
3 days ago
Name.php
3 days ago
NumberFormat.php
3 days ago
NumberOfItems.php
3 days ago
Password.php
3 days ago
PathScope.php
3 days ago
PostExtendedProperty.php
3 days ago
PostLink.php
3 days ago
PostProperty.php
3 days ago
PostStatus.php
3 days ago
PostStatusIcon.php
3 days ago
PostType.php
3 days ago
PostTypeFactory.php
3 days ago
RelatedUserMetaField.php
3 days ago
SelectOptions.php
3 days ago
Separator.php
3 days ago
SerializedArrayKeys.php
3 days ago
SerializedDisplay.php
3 days ago
StringLimit.php
3 days ago
Taxonomy.php
3 days ago
TaxonomyFactory.php
3 days ago
TermLink.php
3 days ago
TermProperty.php
3 days ago
UseIcon.php
3 days ago
UserLink.php
3 days ago
UserLinkFactory.php
3 days ago
UserProperty.php
3 days ago
VideoDisplay.php
3 days ago
Width.php
3 days ago
WordLimit.php
3 days ago
WordsPerMinute.php
3 days ago
UserProperty.php
146 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Setting\ComponentFactory; |
| 6 | |
| 7 | use AC; |
| 8 | use AC\Expression\StringComparisonSpecification; |
| 9 | use AC\FormatterCollection; |
| 10 | use AC\Setting\AttributeCollection; |
| 11 | use AC\Setting\AttributeFactory; |
| 12 | use AC\Setting\Children; |
| 13 | use AC\Setting\Component; |
| 14 | use AC\Setting\ComponentCollection; |
| 15 | use AC\Setting\Config; |
| 16 | use AC\Setting\Control\Input; |
| 17 | use AC\Setting\Control\Input\Number; |
| 18 | use AC\Setting\Control\Input\OptionFactory; |
| 19 | use AC\Setting\Control\OptionCollection; |
| 20 | use AC\Setting\Control\Type\Option; |
| 21 | |
| 22 | class UserProperty extends BaseComponentFactory |
| 23 | { |
| 24 | public const KEY = 'display_author_as'; |
| 25 | public const PROPERTY_DISPLAY_NAME = 'display_name'; |
| 26 | public const PROPERTY_EMAIL = 'user_email'; |
| 27 | public const PROPERTY_FULL_NAME = 'first_last_name'; |
| 28 | public const PROPERTY_FIRST_NAME = 'first_name'; |
| 29 | public const PROPERTY_ID = 'ID'; |
| 30 | public const PROPERTY_LAST_NAME = 'last_name'; |
| 31 | public const PROPERTY_LOGIN = 'user_login'; |
| 32 | public const PROPERTY_NICENAME = 'user_nicename'; |
| 33 | public const PROPERTY_URL = 'user_url'; |
| 34 | public const PROPERTY_NICKNAME = 'nickname'; |
| 35 | public const PROPERTY_ROLES = 'roles'; |
| 36 | public const PROPERTY_GRAVATAR = 'gravatar'; |
| 37 | |
| 38 | protected function get_label(Config $config): ?string |
| 39 | { |
| 40 | return __('User Display', 'codepress-admin-columns'); |
| 41 | } |
| 42 | |
| 43 | protected function get_input(Config $config): ?Input |
| 44 | { |
| 45 | return OptionFactory::create_select( |
| 46 | 'display_author_as', |
| 47 | $this->get_input_options(), |
| 48 | $config->get('display_author_as') ?: 'display_name', |
| 49 | null, |
| 50 | false, |
| 51 | new AttributeCollection([ |
| 52 | AttributeFactory::create_refresh(), |
| 53 | ]) |
| 54 | ); |
| 55 | } |
| 56 | |
| 57 | protected function add_formatters(Config $config, FormatterCollection $formatters): void |
| 58 | { |
| 59 | $property = $config->get('display_author_as', self::PROPERTY_DISPLAY_NAME); |
| 60 | |
| 61 | switch ($property) { |
| 62 | case self::PROPERTY_GRAVATAR: |
| 63 | $formatters->add(new AC\Formatter\User\Property('user_email')); |
| 64 | $formatters->add(new AC\Formatter\Avatar((int)$config->get('gravatar_size', '60'))); |
| 65 | |
| 66 | break; |
| 67 | case self::PROPERTY_FULL_NAME: |
| 68 | $formatters->add(new AC\Formatter\User\FullName()); |
| 69 | break; |
| 70 | case self::PROPERTY_DISPLAY_NAME: |
| 71 | case self::PROPERTY_EMAIL: |
| 72 | case self::PROPERTY_FIRST_NAME: |
| 73 | case self::PROPERTY_ID: |
| 74 | case self::PROPERTY_LAST_NAME: |
| 75 | case self::PROPERTY_LOGIN: |
| 76 | case self::PROPERTY_NICENAME: |
| 77 | case self::PROPERTY_URL: |
| 78 | case self::PROPERTY_NICKNAME: |
| 79 | $formatters->add(new AC\Formatter\User\Property((string)$property)); |
| 80 | break; |
| 81 | case self::PROPERTY_ROLES: |
| 82 | $formatters->add(new AC\Formatter\User\TranslatedRoles()); |
| 83 | break; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | protected function get_children(Config $config): ?Children |
| 88 | { |
| 89 | return new Children( |
| 90 | $this->get_children_component_collection($config) |
| 91 | ); |
| 92 | } |
| 93 | |
| 94 | protected function get_children_component_collection(Config $config): ComponentCollection |
| 95 | { |
| 96 | return new ComponentCollection([ |
| 97 | new Component( |
| 98 | __('Image Size', 'codepress-admin-columns'), |
| 99 | null, |
| 100 | Number::create_single_step( |
| 101 | 'gravatar_size', |
| 102 | 0, |
| 103 | 100, |
| 104 | (int)$config->get('gravatar_size', 60), |
| 105 | null, |
| 106 | null, |
| 107 | 'px' |
| 108 | ), |
| 109 | StringComparisonSpecification::equal('gravatar') |
| 110 | ), |
| 111 | ]); |
| 112 | } |
| 113 | |
| 114 | protected function get_input_options(): OptionCollection |
| 115 | { |
| 116 | $options = new OptionCollection(); |
| 117 | |
| 118 | $default_options = [ |
| 119 | self::PROPERTY_DISPLAY_NAME => __('Display Name', 'codepress-admin-columns'), |
| 120 | self::PROPERTY_FIRST_NAME => __('First Name', 'codepress-admin-columns'), |
| 121 | self::PROPERTY_FULL_NAME => __('Full Name', 'codepress-admin-columns'), |
| 122 | self::PROPERTY_LAST_NAME => __('Last Name', 'codepress-admin-columns'), |
| 123 | self::PROPERTY_NICKNAME => __('Nickname', 'codepress-admin-columns'), |
| 124 | self::PROPERTY_LOGIN => __('User Login', 'codepress-admin-columns'), |
| 125 | self::PROPERTY_EMAIL => __('User Email', 'codepress-admin-columns'), |
| 126 | self::PROPERTY_ID => __('User ID', 'codepress-admin-columns'), |
| 127 | self::PROPERTY_NICENAME => __('User Nicename', 'codepress-admin-columns'), |
| 128 | self::PROPERTY_URL => __('User Website', 'codepress-admin-columns'), |
| 129 | ]; |
| 130 | |
| 131 | foreach ($default_options as $key => $label) { |
| 132 | $options->add( |
| 133 | new Option($label, $key, __('Default', 'codepress-admin-columns')) |
| 134 | ); |
| 135 | } |
| 136 | |
| 137 | $other_group = __('Other', 'codepress-admin-columns'); |
| 138 | |
| 139 | $options->add(new Option(__('Roles', 'codepress-admin-columns'), self::PROPERTY_ROLES, $other_group)); |
| 140 | $options->add(new Option(__('Gravatar', 'codepress-admin-columns'), self::PROPERTY_GRAVATAR, $other_group)); |
| 141 | |
| 142 | return $options; |
| 143 | } |
| 144 | |
| 145 | } |
| 146 |