clean up admin settings

This commit is contained in:
Matthias Pfefferle 2023-04-28 15:12:30 +02:00
parent 02e0acdf69
commit 7c47f9a07c
3 changed files with 46 additions and 40 deletions

View file

@ -1,6 +1,8 @@
<?php <?php
namespace Activitypub; namespace Activitypub;
use Activitypub\Model\Post;
/** /**
* ActivityPub Admin Class * ActivityPub Admin Class
* *
@ -51,9 +53,9 @@ class Admin {
switch ( $tab ) { switch ( $tab ) {
case 'settings': case 'settings':
\Activitypub\Model\Post::upgrade_post_content_template(); Post::upgrade_post_content_template();
\load_template( \dirname( __FILE__ ) . '/../templates/settings.php' ); \load_template( ACTIVITYPUB_PLUGIN_DIR . 'templates/settings.php' );
break; break;
case 'welcome': case 'welcome':
default: default:
@ -61,7 +63,7 @@ class Admin {
add_thickbox(); add_thickbox();
wp_enqueue_script( 'updates' ); wp_enqueue_script( 'updates' );
\load_template( \dirname( __FILE__ ) . '/../templates/welcome.php' ); \load_template( ACTIVITYPUB_PLUGIN_DIR . 'templates/welcome.php' );
break; break;
} }
} }
@ -70,7 +72,7 @@ class Admin {
* Load user settings page * Load user settings page
*/ */
public static function followers_list_page() { public static function followers_list_page() {
\load_template( \dirname( __FILE__ ) . '/../templates/followers-list.php' ); \load_template( ACTIVITYPUB_PLUGIN_DIR . 'templates/followers-list.php' );
} }
/** /**
@ -146,7 +148,7 @@ class Admin {
} }
public static function add_settings_help_tab() { public static function add_settings_help_tab() {
require_once \dirname( __FILE__ ) . '/help.php'; require_once ACTIVITYPUB_PLUGIN_DIR . 'includes/help.php';
} }
public static function add_followers_list_help_tab() { public static function add_followers_list_help_tab() {
@ -154,25 +156,19 @@ class Admin {
} }
public static function add_fediverse_profile( $user ) { public static function add_fediverse_profile( $user ) {
$ap_description = get_user_meta( $user->ID, ACTIVITYPUB_USER_DESCRIPTION_KEY, true ); $description = get_user_meta( $user->ID, ACTIVITYPUB_USER_DESCRIPTION_KEY, true );
?>
<h2 id="activitypub"><?php \esc_html_e( 'ActivityPub', 'activitypub' ); ?></h2> \load_template(
<?php ACTIVITYPUB_PLUGIN_DIR . 'templates/user-settings.php',
\Activitypub\get_identifier_settings( $user->ID ); true,
?> array(
<table class="form-table" role="presentation"> 'description' => $description,
<tr class="activitypub-user-description-wrap"> )
<th><label for="activitypub-user-description"><?php \esc_html_e( 'Fediverse Biography', 'activitypub' ); ?></label></th> );
<td><textarea name="activitypub-user-description" id="activitypub-user-description" rows="5" cols="30"><?php echo \esc_html( $ap_description ); ?></textarea>
<p><?php \esc_html_e( 'If you wish to use different biographical info for the fediverse, enter your alternate bio here.', 'activitypub' ); ?></p></td>
<?php wp_nonce_field( 'activitypub-user-description', '_apnonce' ); ?>
</tr>
</table>
<?php
} }
public static function save_user_description( $user_id ) { public static function save_user_description( $user_id ) {
if ( ! wp_verify_nonce( $_REQUEST['_apnonce'], 'activitypub-user-description' ) ) { if ( isset( $_REQUEST['_apnonce'] ) && ! wp_verify_nonce( $_REQUEST['_apnonce'], 'activitypub-user-description' ) ) {
return false; return false;
} }
if ( ! current_user_can( 'edit_user', $user_id ) ) { if ( ! current_user_can( 'edit_user', $user_id ) ) {

View file

@ -241,25 +241,6 @@ function get_follower_inboxes( $user_id, $cc = array() ) {
return $inboxes; return $inboxes;
} }
function get_identifier_settings( $user_id ) {
?>
<table class="form-table">
<tbody>
<tr>
<th scope="row">
<label><?php \esc_html_e( 'Profile identifier', 'activitypub' ); ?></label>
</th>
<td>
<p><code><?php echo \esc_html( \Activitypub\get_webfinger_resource( $user_id ) ); ?></code> or <code><?php echo \esc_url( \get_author_posts_url( $user_id ) ); ?></code></p>
<?php // translators: the webfinger resource ?>
<p class="description"><?php \printf( \esc_html__( 'Try to follow "@%s" by searching for it on Mastodon,Friendica & Co.', 'activitypub' ), \esc_html( \Activitypub\get_webfinger_resource( $user_id ) ) ); ?></p>
</td>
</tr>
</tbody>
</table>
<?php
}
function get_followers( $user_id ) { function get_followers( $user_id ) {
$followers = \Activitypub\Peer\Followers::get_followers( $user_id ); $followers = \Activitypub\Peer\Followers::get_followers( $user_id );

View file

@ -0,0 +1,29 @@
<h2 id="activitypub"><?php \esc_html_e( 'ActivityPub', 'activitypub' ); ?></h2>
<table class="form-table">
<tbody>
<tr>
<th scope="row">
<label><?php \esc_html_e( 'Profile identifier', 'activitypub' ); ?></label>
</th>
<td>
<p>
<code><?php echo \esc_html( \Activitypub\get_webfinger_resource( \get_current_user_id() ) ); ?></code> or
<code><?php echo \esc_url( \get_author_posts_url( \get_current_user_id() ) ); ?></code>
</p>
<?php // translators: the webfinger resource ?>
<p class="description"><?php \printf( \esc_html__( 'Try to follow "@%s" by searching for it on Mastodon,Friendica & Co.', 'activitypub' ), \esc_html( \Activitypub\get_webfinger_resource( \get_current_user_id() ) ) ); ?></p>
</td>
</tr>
<tr class="activitypub-user-description-wrap">
<th>
<label for="activitypub-user-description"><?php \esc_html_e( 'Biography', 'activitypub' ); ?></label>
</th>
<td>
<textarea name="activitypub-user-description" id="activitypub-user-description" rows="5" cols="30" placeholder="<?php echo \esc_html( get_user_meta( \get_current_user_id(), 'description', true ) ); ?>"><?php echo \esc_html( $args['description'] ); ?></textarea>
<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>
</td>
<?php wp_nonce_field( 'activitypub-user-description', '_apnonce' ); ?>
</tr>
</tbody>
</table>