|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * ActivityPub Blog Settings Fields Handler. |
| 4 | + * |
| 5 | + * @package ActivityPub |
| 6 | + */ |
| 7 | + |
| 8 | +namespace Activitypub; |
| 9 | + |
| 10 | +/** |
| 11 | + * Class to handle all blog settings fields and callbacks. |
| 12 | + */ |
| 13 | +class Blog_Settings_Fields { |
| 14 | + /** |
| 15 | + * Initialize the settings fields. |
| 16 | + */ |
| 17 | + public static function init() { |
| 18 | + add_action( 'settings_page_activitypub', array( self::class, 'register_settings' ) ); |
| 19 | + } |
| 20 | + |
| 21 | + /** |
| 22 | + * Register all settings fields. |
| 23 | + */ |
| 24 | + public static function register_settings() { |
| 25 | + add_settings_section( |
| 26 | + 'activitypub_blog_profile', |
| 27 | + __( 'Blog Profile', 'activitypub' ), |
| 28 | + '__return_empty_string', |
| 29 | + 'activitypub_blog_settings' |
| 30 | + ); |
| 31 | + |
| 32 | + add_settings_field( |
| 33 | + 'activitypub_blog_avatar', |
| 34 | + __( 'Manage Avatar', 'activitypub' ), |
| 35 | + array( self::class, 'avatar_callback' ), |
| 36 | + 'activitypub_blog_settings', |
| 37 | + 'activitypub_blog_profile' |
| 38 | + ); |
| 39 | + |
| 40 | + add_settings_field( |
| 41 | + 'activitypub_header_image', |
| 42 | + __( 'Manage Header Image', 'activitypub' ), |
| 43 | + array( self::class, 'header_image_callback' ), |
| 44 | + 'activitypub_blog_settings', |
| 45 | + 'activitypub_blog_profile' |
| 46 | + ); |
| 47 | + |
| 48 | + add_settings_field( |
| 49 | + 'activitypub_blog_identifier', |
| 50 | + __( 'Change Profile ID', 'activitypub' ), |
| 51 | + array( self::class, 'profile_id_callback' ), |
| 52 | + 'activitypub_blog_settings', |
| 53 | + 'activitypub_blog_profile', |
| 54 | + array( 'label_for' => 'activitypub_blog_identifier' ) |
| 55 | + ); |
| 56 | + |
| 57 | + add_settings_field( |
| 58 | + 'activitypub_blog_description', |
| 59 | + __( 'Change Description', 'activitypub' ), |
| 60 | + array( self::class, 'description_callback' ), |
| 61 | + 'activitypub_blog_settings', |
| 62 | + 'activitypub_blog_profile', |
| 63 | + array( 'label_for' => 'activitypub_blog_description' ) |
| 64 | + ); |
| 65 | + |
| 66 | + add_settings_field( |
| 67 | + 'activitypub_extra_fields', |
| 68 | + __( 'Extra Fields', 'activitypub' ), |
| 69 | + array( self::class, 'extra_fields_callback' ), |
| 70 | + 'activitypub_blog_settings', |
| 71 | + 'activitypub_blog_profile' |
| 72 | + ); |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * Avatar field callback. |
| 77 | + */ |
| 78 | + public static function avatar_callback() { |
| 79 | + ?> |
| 80 | + <?php if ( has_site_icon() ) : ?> |
| 81 | + <p><img src="<?php echo esc_url( get_site_icon_url( '50' ) ); ?>" alt="" /></p> |
| 82 | + <?php endif; ?> |
| 83 | + <p class="description"> |
| 84 | + <?php |
| 85 | + echo wp_kses( |
| 86 | + sprintf( |
| 87 | + // translators: %s is a URL. |
| 88 | + __( 'The ActivityPub plugin uses the WordPress Site Icon as Avatar for the Blog-Profile, you can change the Site Icon in the "<a href="%s">General Settings</a>" of WordPress.', 'activitypub' ), |
| 89 | + esc_url( admin_url( 'options-general.php' ) ) |
| 90 | + ), |
| 91 | + 'default' |
| 92 | + ); |
| 93 | + ?> |
| 94 | + </p> |
| 95 | + <?php |
| 96 | + } |
| 97 | + |
| 98 | + /** |
| 99 | + * Header image field callback. |
| 100 | + */ |
| 101 | + public static function header_image_callback() { |
| 102 | + $classes_for_button = 'button upload-button button-add-media button-add-header-image'; |
| 103 | + $classes_for_button_on_change = 'button'; |
| 104 | + $classes_for_wrapper = ' hidden'; |
| 105 | + |
| 106 | + if ( (int) get_option( 'activitypub_header_image', 0 ) ) { |
| 107 | + $classes_for_wrapper = ' has-header-image'; |
| 108 | + $classes_for_button_on_change = $classes_for_button; |
| 109 | + $classes_for_button = 'button'; |
| 110 | + } |
| 111 | + ?> |
| 112 | + <div id="activitypub-header-image-preview-wrapper" class="<?php echo esc_attr( $classes_for_wrapper ); ?>"> |
| 113 | + <img id="activitypub-header-image-preview" src="<?php echo esc_url( wp_get_attachment_url( get_option( 'activitypub_header_image' ) ) ); ?>" style="max-width: 100%;" alt="" /> |
| 114 | + </div> |
| 115 | + <button |
| 116 | + type="button" |
| 117 | + id="activitypub-choose-from-library-button" |
| 118 | + class="<?php echo esc_attr( $classes_for_button ); ?>" |
| 119 | + data-alt-classes="<?php echo esc_attr( $classes_for_button_on_change ); ?>" |
| 120 | + data-choose-text="<?php esc_attr_e( 'Choose a Header Image', 'activitypub' ); ?>" |
| 121 | + data-update-text="<?php esc_attr_e( 'Change Header Icon', 'activitypub' ); ?>" |
| 122 | + data-update="<?php esc_attr_e( 'Set as Header Image', 'activitypub' ); ?>" |
| 123 | + data-state="<?php echo esc_attr( (int) get_option( 'activitypub_header_image', 0 ) ); ?>"> |
| 124 | + <?php if ( (int) get_option( 'activitypub_header_image', 0 ) ) : ?> |
| 125 | + <?php esc_html_e( 'Change Header Image', 'activitypub' ); ?> |
| 126 | + <?php else : ?> |
| 127 | + <?php esc_html_e( 'Choose a Header Image', 'activitypub' ); ?> |
| 128 | + <?php endif; ?> |
| 129 | + </button> |
| 130 | + <button |
| 131 | + id="activitypub-remove-header-image" |
| 132 | + type="button" |
| 133 | + <?php echo (int) get_option( 'activitypub_header_image', 0 ) ? 'class="button button-secondary reset"' : 'class="button button-secondary reset hidden"'; ?>> |
| 134 | + <?php esc_html_e( 'Remove Header Image', 'activitypub' ); ?> |
| 135 | + </button> |
| 136 | + <input type="hidden" name="activitypub_header_image" id="activitypub_header_image" value="<?php echo esc_attr( get_option( 'activitypub_header_image' ) ); ?>"> |
| 137 | + <?php |
| 138 | + } |
| 139 | + |
| 140 | + /** |
| 141 | + * Profile ID field callback. |
| 142 | + */ |
| 143 | + public static function profile_id_callback() { |
| 144 | + ?> |
| 145 | + <label for="activitypub_blog_identifier"> |
| 146 | + <input id="activitypub_blog_identifier" class="blog-user-identifier" name="activitypub_blog_identifier" type="text" value="<?php echo esc_attr( get_option( 'activitypub_blog_identifier', Model\Blog::get_default_username() ) ); ?>" /> |
| 147 | + @<?php echo esc_html( wp_parse_url( home_url(), PHP_URL_HOST ) ); ?> |
| 148 | + </label> |
| 149 | + <p class="description"> |
| 150 | + <?php esc_html_e( 'This profile name will federate all posts written on your blog, regardless of the author who posted it.', 'activitypub' ); ?> |
| 151 | + </p> |
| 152 | + <p class="description"> |
| 153 | + <strong> |
| 154 | + <?php esc_html_e( 'Please avoid using an existing author’s name as the blog profile ID. Fediverse platforms might use caching and this could break the functionality completely.', 'activitypub' ); ?> |
| 155 | + </strong> |
| 156 | + </p> |
| 157 | + <?php |
| 158 | + } |
| 159 | + |
| 160 | + /** |
| 161 | + * Description field callback. |
| 162 | + */ |
| 163 | + public static function description_callback() { |
| 164 | + ?> |
| 165 | + <label for="activitypub_blog_description"> |
| 166 | + <textarea |
| 167 | + class="blog-user-description large-text" |
| 168 | + rows="5" |
| 169 | + name="activitypub_blog_description" |
| 170 | + id="activitypub_blog_description" |
| 171 | + placeholder="<?php echo esc_attr( get_bloginfo( 'description' ) ); ?>" |
| 172 | + ><?php echo esc_textarea( get_option( 'activitypub_blog_description' ) ); ?></textarea> |
| 173 | + </label> |
| 174 | + <p class="description"> |
| 175 | + <?php esc_html_e( 'By default the ActivityPub plugin uses the WordPress tagline as a description for the blog profile.', 'activitypub' ); ?> |
| 176 | + </p> |
| 177 | + <?php |
| 178 | + } |
| 179 | + |
| 180 | + /** |
| 181 | + * Extra fields callback. |
| 182 | + */ |
| 183 | + public static function extra_fields_callback() { |
| 184 | + ?> |
| 185 | + <p class="description"> |
| 186 | + <?php esc_html_e( 'Your homepage, social profiles, pronouns, age, anything you want.', 'activitypub' ); ?> |
| 187 | + </p> |
| 188 | + |
| 189 | + <table class="widefat striped activitypub-extra-fields" role="presentation" style="margin: 15px 0;"> |
| 190 | + <?php |
| 191 | + $extra_fields = Collection\Extra_Fields::get_actor_fields( Collection\Actors::BLOG_USER_ID ); |
| 192 | + |
| 193 | + if ( empty( $extra_fields ) ) : |
| 194 | + ?> |
| 195 | + <tr> |
| 196 | + <td colspan="3"> |
| 197 | + <?php esc_html_e( 'No extra fields found.', 'activitypub' ); ?> |
| 198 | + </td> |
| 199 | + </tr> |
| 200 | + <?php |
| 201 | + endif; |
| 202 | + |
| 203 | + foreach ( $extra_fields as $extra_field ) : |
| 204 | + ?> |
| 205 | + <tr> |
| 206 | + <td><?php echo esc_html( $extra_field->post_title ); ?></td> |
| 207 | + <td><?php echo wp_kses_post( get_the_excerpt( $extra_field ) ); ?></td> |
| 208 | + <td> |
| 209 | + <a href="<?php echo esc_url( get_edit_post_link( $extra_field->ID ) ); ?>" class="button"> |
| 210 | + <?php esc_html_e( 'Edit', 'activitypub' ); ?> |
| 211 | + </a> |
| 212 | + </td> |
| 213 | + </tr> |
| 214 | + <?php endforeach; ?> |
| 215 | + </table> |
| 216 | + |
| 217 | + <p> |
| 218 | + <a href="<?php echo esc_url( admin_url( '/post-new.php?post_type=ap_extrafield_blog' ) ); ?>" class="button"> |
| 219 | + <?php esc_html_e( 'Add new', 'activitypub' ); ?> |
| 220 | + </a> |
| 221 | + <a href="<?php echo esc_url( admin_url( '/edit.php?post_type=ap_extrafield_blog' ) ); ?>"> |
| 222 | + <?php esc_html_e( 'Manage all', 'activitypub' ); ?> |
| 223 | + </a> |
| 224 | + </p> |
| 225 | + <?php |
| 226 | + } |
| 227 | +} |
0 commit comments