| 1 |
<?php |
| 2 |
/** |
| 3 |
* ActivityPub User Settings Fields Handler. |
| 4 |
* |
| 5 |
* @package Activitypub |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Activitypub\WP_Admin; |
| 9 |
|
| 10 |
use Activitypub\Collection\Actors; |
| 11 |
use Activitypub\Collection\Extra_Fields; |
| 12 |
|
| 13 |
/** |
| 14 |
* Class to handle all user settings fields and callbacks. |
| 15 |
*/ |
| 16 |
class User_Settings_Fields { |
| 17 |
/** |
| 18 |
* Initialize the settings fields. |
| 19 |
*/ |
| 20 |
public static function init() { |
| 21 |
add_action( 'load-profile.php', array( self::class, 'register_settings' ) ); |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Register all settings fields. |
| 26 |
*/ |
| 27 |
public static function register_settings() { |
| 28 |
// Mark checklist item as done. |
| 29 |
\update_option( 'activitypub_checklist_profile_setup_visited', '1' ); |
| 30 |
|
| 31 |
\add_settings_section( |
| 32 |
'activitypub_user_profile', |
| 33 |
\esc_html__( 'ActivityPub', 'activitypub' ), |
| 34 |
array( self::class, 'section_description' ), |
| 35 |
'activitypub_user_settings', |
| 36 |
array( |
| 37 |
'before_section' => '<section id="activitypub">', |
| 38 |
'after_section' => '</section>', |
| 39 |
) |
| 40 |
); |
| 41 |
|
| 42 |
\add_settings_field( |
| 43 |
'activitypub_profile_url', |
| 44 |
\esc_html__( 'Profile URL', 'activitypub' ), |
| 45 |
array( self::class, 'profile_url_callback' ), |
| 46 |
'activitypub_user_settings', |
| 47 |
'activitypub_user_profile' |
| 48 |
); |
| 49 |
|
| 50 |
\add_settings_field( |
| 51 |
'activitypub_description', |
| 52 |
\esc_html__( 'Biography', 'activitypub' ), |
| 53 |
array( self::class, 'description_callback' ), |
| 54 |
'activitypub_user_settings', |
| 55 |
'activitypub_user_profile', |
| 56 |
array( 'label_for' => 'activitypub_description' ) |
| 57 |
); |
| 58 |
|
| 59 |
\add_settings_field( |
| 60 |
'activitypub_header_image', |
| 61 |
\esc_html__( 'Header Image', 'activitypub' ), |
| 62 |
array( self::class, 'header_image_callback' ), |
| 63 |
'activitypub_user_settings', |
| 64 |
'activitypub_user_profile', |
| 65 |
array( 'label_for' => 'activitypub_header_image' ) |
| 66 |
); |
| 67 |
|
| 68 |
\add_settings_field( |
| 69 |
'activitypub_notifications', |
| 70 |
\esc_html__( 'Email Notifications', 'activitypub' ), |
| 71 |
array( self::class, 'notifications_callback' ), |
| 72 |
'activitypub_user_settings', |
| 73 |
'activitypub_user_profile' |
| 74 |
); |
| 75 |
|
| 76 |
\add_settings_field( |
| 77 |
'activitypub_extra_fields', |
| 78 |
\esc_html__( 'Extra Fields', 'activitypub' ), |
| 79 |
array( self::class, 'extra_fields_callback' ), |
| 80 |
'activitypub_user_settings', |
| 81 |
'activitypub_user_profile' |
| 82 |
); |
| 83 |
|
| 84 |
\add_settings_field( |
| 85 |
'activitypub_also_known_as', |
| 86 |
\esc_html__( 'Account Aliases', 'activitypub' ), |
| 87 |
array( self::class, 'also_known_as_callback' ), |
| 88 |
'activitypub_user_settings', |
| 89 |
'activitypub_user_profile', |
| 90 |
array( 'label_for' => 'activitypub_also_known_as' ) |
| 91 |
); |
| 92 |
} |
| 93 |
|
| 94 |
/** |
| 95 |
* Section description callback. |
| 96 |
*/ |
| 97 |
public static function section_description() { |
| 98 |
echo '<p>' . \esc_html__( 'Define what others can see on your public Fediverse profile and next to your posts. With a profile picture and a fully completed profile, you are more likely to gain interactions and followers.', 'activitypub' ) . '</p>'; |
| 99 |
echo '<p>' . \esc_html__( 'The ActivityPub plugin tries to take as much information as possible from your profile settings. However, the following settings are not supported by WordPress or should be adjusted independently of the WordPress settings.', 'activitypub' ) . '</p>'; |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* Profile URL field callback. |
| 104 |
*/ |
| 105 |
public static function profile_url_callback() { |
| 106 |
$user = Actors::get_by_id( \get_current_user_id() ); |
| 107 |
?> |
| 108 |
<p> |
| 109 |
<?php |
| 110 |
\printf( |
| 111 |
// translators: 1: the webfinger resource, 2: the author URL. |
| 112 |
\esc_html__( '%1$s or %2$s', 'activitypub' ), |
| 113 |
'<code>' . \esc_html( $user->get_webfinger() ) . '</code>', |
| 114 |
'<code>' . \esc_url( $user->get_url() ) . '</code>' |
| 115 |
); |
| 116 |
?> |
| 117 |
</p> |
| 118 |
<p class="description"> |
| 119 |
<?php |
| 120 |
\printf( |
| 121 |
// translators: the webfinger resource. |
| 122 |
\esc_html__( 'Follow "@%s" by searching for it on Mastodon, Friendica, etc.', 'activitypub' ), |
| 123 |
\esc_html( $user->get_webfinger() ) |
| 124 |
); |
| 125 |
?> |
| 126 |
</p> |
| 127 |
<?php |
| 128 |
} |
| 129 |
|
| 130 |
/** |
| 131 |
* Description field callback. |
| 132 |
*/ |
| 133 |
public static function description_callback() { |
| 134 |
$description = \get_user_option( 'activitypub_description', \get_current_user_id() ); |
| 135 |
$placeholder = \get_user_meta( \get_current_user_id(), 'description', true ); |
| 136 |
?> |
| 137 |
<textarea name="activitypub_description" id="activitypub_description" rows="5" cols="30" placeholder="<?php echo \esc_attr( $placeholder ); ?>"><?php echo \esc_html( $description ); ?></textarea> |
| 138 |
<p class="description"><?php \esc_html_e( 'If you wish to use different biographical info for the fediverse, enter your alternate bio here.', 'activitypub' ); ?></p> |
| 139 |
<?php |
| 140 |
} |
| 141 |
|
| 142 |
/** |
| 143 |
* Header image field callback. |
| 144 |
*/ |
| 145 |
public static function header_image_callback() { |
| 146 |
$header_image = \get_user_option( 'activitypub_header_image', \get_current_user_id() ); |
| 147 |
$classes_for_upload_button = 'button upload-button button-add-media button-add-header-image'; |
| 148 |
$classes_for_update_button = 'button'; |
| 149 |
$classes_for_wrapper = ''; |
| 150 |
|
| 151 |
if ( (int) $header_image ) { |
| 152 |
$classes_for_wrapper .= ' has-header-image'; |
| 153 |
$classes_for_button = $classes_for_update_button; |
| 154 |
$classes_for_button_on_change = $classes_for_upload_button; |
| 155 |
} else { |
| 156 |
$classes_for_wrapper .= ' hidden'; |
| 157 |
$classes_for_button = $classes_for_upload_button; |
| 158 |
$classes_for_button_on_change = $classes_for_update_button; |
| 159 |
} |
| 160 |
?> |
| 161 |
<div id="activitypub-header-image-preview-wrapper" class="<?php echo \esc_attr( $classes_for_wrapper ); ?>"> |
| 162 |
<img id="activitypub-header-image-preview" src="<?php echo \esc_url( \wp_get_attachment_url( $header_image ) ); ?>" style="max-width: 100%;" alt="" /> |
| 163 |
</div> |
| 164 |
<button |
| 165 |
type="button" |
| 166 |
id="activitypub-choose-from-library-button" |
| 167 |
class="<?php echo \esc_attr( $classes_for_button ); ?>" |
| 168 |
data-alt-classes="<?php echo \esc_attr( $classes_for_button_on_change ); ?>" |
| 169 |
data-choose-text="<?php \esc_attr_e( 'Choose a Header Image', 'activitypub' ); ?>" |
| 170 |
data-update-text="<?php \esc_attr_e( 'Change Header Image', 'activitypub' ); ?>" |
| 171 |
data-update="<?php \esc_attr_e( 'Set as Header Image', 'activitypub' ); ?>" |
| 172 |
data-width="1500" |
| 173 |
data-height="500" |
| 174 |
<?php |
| 175 |
if ( ! \current_user_can( 'edit_others_posts' ) ) : |
| 176 |
\printf( 'data-user-id="%s"', \esc_attr( \get_current_user_id() ) ); |
| 177 |
endif; |
| 178 |
?> |
| 179 |
data-state="<?php echo \esc_attr( (int) $header_image ); ?>"> |
| 180 |
<?php echo (int) $header_image ? \esc_html__( 'Change Header Image', 'activitypub' ) : \esc_html__( 'Choose a Header Image', 'activitypub' ); ?> |
| 181 |
</button> |
| 182 |
<button |
| 183 |
id="activitypub-remove-header-image" |
| 184 |
type="button" |
| 185 |
<?php echo (int) $header_image ? 'class="button button-secondary reset"' : 'class="button button-secondary reset hidden"'; ?>> |
| 186 |
<?php \esc_html_e( 'Remove Header Image', 'activitypub' ); ?> |
| 187 |
</button> |
| 188 |
<input type="hidden" name="activitypub_header_image" id="activitypub_header_image" value="<?php echo \esc_attr( $header_image ); ?>"> |
| 189 |
<?php |
| 190 |
} |
| 191 |
|
| 192 |
/** |
| 193 |
* Notifications field callback. |
| 194 |
*/ |
| 195 |
public static function notifications_callback() { |
| 196 |
?> |
| 197 |
<fieldset id="activitypub-notifications"> |
| 198 |
<p> |
| 199 |
<label> |
| 200 |
<input type="checkbox" name="activitypub_mailer_new_follower" id="activitypub_mailer_new_follower" value="1" <?php \checked( 1, \get_user_option( 'activitypub_mailer_new_follower' ) ); ?> /> |
| 201 |
<?php \esc_html_e( 'New Followers', 'activitypub' ); ?> |
| 202 |
</label> |
| 203 |
</p> |
| 204 |
<p> |
| 205 |
<label> |
| 206 |
<input type="checkbox" name="activitypub_mailer_new_dm" id="activitypub_mailer_new_dm" value="1" <?php \checked( 1, \get_user_option( 'activitypub_mailer_new_dm' ) ); ?> /> |
| 207 |
<?php \esc_html_e( 'Direct Messages', 'activitypub' ); ?> |
| 208 |
</label> |
| 209 |
</p> |
| 210 |
<p> |
| 211 |
<label> |
| 212 |
<input type="checkbox" name="activitypub_mailer_new_mention" id="activitypub_mailer_new_mention" value="1" <?php \checked( 1, \get_user_option( 'activitypub_mailer_new_mention' ) ); ?> /> |
| 213 |
<?php \esc_html_e( 'New Mentions', 'activitypub' ); ?> |
| 214 |
</label> |
| 215 |
</p> |
| 216 |
</fieldset> |
| 217 |
<?php |
| 218 |
} |
| 219 |
|
| 220 |
/** |
| 221 |
* Extra fields callback. |
| 222 |
*/ |
| 223 |
public static function extra_fields_callback() { |
| 224 |
$extra_fields = Extra_Fields::get_actor_fields( \get_current_user_id() ); |
| 225 |
?> |
| 226 |
<p class="description"> |
| 227 |
<?php \esc_html_e( 'Your homepage, social profiles, pronouns, age, anything you want.', 'activitypub' ); ?> |
| 228 |
</p> |
| 229 |
|
| 230 |
<?php if ( ! empty( $extra_fields ) ) : ?> |
| 231 |
<table class="widefat striped activitypub-extra-fields" role="presentation" style="margin: 15px 0;"> |
| 232 |
<?php foreach ( $extra_fields as $extra_field ) : ?> |
| 233 |
<tr> |
| 234 |
<td><?php echo \esc_html( $extra_field->post_title ); ?></td> |
| 235 |
<td><?php echo \wp_kses_post( \get_the_excerpt( $extra_field ) ); ?></td> |
| 236 |
<td> |
| 237 |
<a href="<?php echo \esc_url( \get_edit_post_link( $extra_field->ID ) ); ?>" class="button"> |
| 238 |
<?php \esc_html_e( 'Edit', 'activitypub' ); ?> |
| 239 |
</a> |
| 240 |
</td> |
| 241 |
</tr> |
| 242 |
<?php endforeach; ?> |
| 243 |
</table> |
| 244 |
<?php endif; ?> |
| 245 |
|
| 246 |
<p class="extra-fields-nav"> |
| 247 |
<a href="<?php echo \esc_url( \admin_url( '/post-new.php?post_type=ap_extrafield' ) ); ?>" class="button"> |
| 248 |
<?php \esc_html_e( 'Add new', 'activitypub' ); ?> |
| 249 |
</a> |
| 250 |
<a href="<?php echo \esc_url( \admin_url( '/edit.php?post_type=ap_extrafield' ) ); ?>"> |
| 251 |
<?php \esc_html_e( 'Manage all', 'activitypub' ); ?> |
| 252 |
</a> |
| 253 |
</p> |
| 254 |
<?php |
| 255 |
} |
| 256 |
|
| 257 |
/** |
| 258 |
* Also Known As field callback. |
| 259 |
*/ |
| 260 |
public static function also_known_as_callback() { |
| 261 |
$also_known_as = \get_user_option( 'activitypub_also_known_as', \get_current_user_id() ); |
| 262 |
?> |
| 263 |
<textarea |
| 264 |
class="large-text" |
| 265 |
name="activitypub_also_known_as" |
| 266 |
id="activitypub_also_known_as" |
| 267 |
rows="5" |
| 268 |
><?php echo \esc_textarea( implode( PHP_EOL, (array) $also_known_as ) ); ?></textarea> |
| 269 |
<p class="description"> |
| 270 |
<?php \esc_html_e( 'If you’re moving from another account to this one, you’ll need to create an alias here first before transferring your followers. This step is safe, reversible, and doesn’t affect anything on its own. The migration itself is initiated from your old account.', 'activitypub' ); ?> |
| 271 |
</p> |
| 272 |
<p class="description"> |
| 273 |
<?php \esc_html_e( 'Enter one URL per line.', 'activitypub' ); ?> |
| 274 |
</p> |
| 275 |
<?php |
| 276 |
} |
| 277 |
} |
| 278 |
|