| 1 |
<?php |
| 2 |
namespace Activitypub; |
| 3 |
|
| 4 |
/** |
| 5 |
* ActivityPub Admin Class |
| 6 |
* |
| 7 |
* @author Matthias Pfefferle |
| 8 |
*/ |
| 9 |
class Admin { |
| 10 |
/** |
| 11 |
* Initialize the class, registering WordPress hooks |
| 12 |
*/ |
| 13 |
public static function init() { |
| 14 |
\add_action( 'admin_menu', array( '\Activitypub\Admin', 'admin_menu' ) ); |
| 15 |
\add_action( 'admin_init', array( '\Activitypub\Admin', 'register_settings' ) ); |
| 16 |
\add_action( 'show_user_profile', array( '\Activitypub\Admin', 'add_fediverse_profile' ) ); |
| 17 |
\add_action( 'admin_enqueue_scripts', array( '\Activitypub\Admin', 'enqueue_scripts' ) ); |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* Add admin menu entry |
| 22 |
*/ |
| 23 |
public static function admin_menu() { |
| 24 |
$settings_page = \add_options_page( |
| 25 |
'Welcome', |
| 26 |
'ActivityPub', |
| 27 |
'manage_options', |
| 28 |
'activitypub', |
| 29 |
array( '\Activitypub\Admin', 'settings_page' ) |
| 30 |
); |
| 31 |
|
| 32 |
\add_action( 'load-' . $settings_page, array( '\Activitypub\Admin', 'add_settings_help_tab' ) ); |
| 33 |
|
| 34 |
$followers_list_page = \add_users_page( \__( 'Followers', 'activitypub' ), \__( 'Followers (Fediverse)', 'activitypub' ), 'read', 'activitypub-followers-list', array( '\Activitypub\Admin', 'followers_list_page' ) ); |
| 35 |
|
| 36 |
\add_action( 'load-' . $followers_list_page, array( '\Activitypub\Admin', 'add_followers_list_help_tab' ) ); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Load settings page |
| 41 |
*/ |
| 42 |
public static function settings_page() { |
| 43 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 44 |
if ( empty( $_GET['tab'] ) ) { |
| 45 |
$tab = 'welcome'; |
| 46 |
} else { |
| 47 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 48 |
$tab = sanitize_key( $_GET['tab'] ); |
| 49 |
} |
| 50 |
|
| 51 |
switch ( $tab ) { |
| 52 |
case 'settings': |
| 53 |
\Activitypub\Model\Post::upgrade_post_content_template(); |
| 54 |
|
| 55 |
\load_template( \dirname( __FILE__ ) . '/../templates/settings.php' ); |
| 56 |
break; |
| 57 |
case 'welcome': |
| 58 |
default: |
| 59 |
wp_enqueue_script( 'plugin-install' ); |
| 60 |
add_thickbox(); |
| 61 |
wp_enqueue_script( 'updates' ); |
| 62 |
|
| 63 |
\load_template( \dirname( __FILE__ ) . '/../templates/welcome.php' ); |
| 64 |
break; |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Load user settings page |
| 70 |
*/ |
| 71 |
public static function followers_list_page() { |
| 72 |
\load_template( \dirname( __FILE__ ) . '/../templates/followers-list.php' ); |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Register ActivityPub settings |
| 77 |
*/ |
| 78 |
public static function register_settings() { |
| 79 |
\register_setting( |
| 80 |
'activitypub', |
| 81 |
'activitypub_post_content_type', |
| 82 |
array( |
| 83 |
'type' => 'string', |
| 84 |
'description' => \__( 'Use title and link, summary, full or custom content', 'activitypub' ), |
| 85 |
'show_in_rest' => array( |
| 86 |
'schema' => array( |
| 87 |
'enum' => array( 'title', 'excerpt', 'content' ), |
| 88 |
), |
| 89 |
), |
| 90 |
'default' => 'content', |
| 91 |
) |
| 92 |
); |
| 93 |
\register_setting( |
| 94 |
'activitypub', |
| 95 |
'activitypub_custom_post_content', |
| 96 |
array( |
| 97 |
'type' => 'string', |
| 98 |
'description' => \__( 'Define your own custom post template', 'activitypub' ), |
| 99 |
'show_in_rest' => true, |
| 100 |
'default' => ACTIVITYPUB_CUSTOM_POST_CONTENT, |
| 101 |
) |
| 102 |
); |
| 103 |
\register_setting( |
| 104 |
'activitypub', |
| 105 |
'activitypub_max_image_attachments', |
| 106 |
array( |
| 107 |
'type' => 'integer', |
| 108 |
'description' => \__( 'Number of images to attach to posts.', 'activitypub' ), |
| 109 |
'default' => ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS, |
| 110 |
) |
| 111 |
); |
| 112 |
\register_setting( |
| 113 |
'activitypub', |
| 114 |
'activitypub_object_type', |
| 115 |
array( |
| 116 |
'type' => 'string', |
| 117 |
'description' => \__( 'The Activity-Object-Type', 'activitypub' ), |
| 118 |
'show_in_rest' => array( |
| 119 |
'schema' => array( |
| 120 |
'enum' => array( 'note', 'article', 'wordpress-post-format' ), |
| 121 |
), |
| 122 |
), |
| 123 |
'default' => 'note', |
| 124 |
) |
| 125 |
); |
| 126 |
\register_setting( |
| 127 |
'activitypub', |
| 128 |
'activitypub_use_hashtags', |
| 129 |
array( |
| 130 |
'type' => 'boolean', |
| 131 |
'description' => \__( 'Add hashtags in the content as native tags and replace the #tag with the tag-link', 'activitypub' ), |
| 132 |
'default' => 0, |
| 133 |
) |
| 134 |
); |
| 135 |
\register_setting( |
| 136 |
'activitypub', |
| 137 |
'activitypub_support_post_types', |
| 138 |
array( |
| 139 |
'type' => 'string', |
| 140 |
'description' => \esc_html__( 'Enable ActivityPub support for post types', 'activitypub' ), |
| 141 |
'show_in_rest' => true, |
| 142 |
'default' => array( 'post', 'pages' ), |
| 143 |
) |
| 144 |
); |
| 145 |
} |
| 146 |
|
| 147 |
public static function add_settings_help_tab() { |
| 148 |
require_once \dirname( __FILE__ ) . '/help.php'; |
| 149 |
} |
| 150 |
|
| 151 |
public static function add_followers_list_help_tab() { |
| 152 |
// todo |
| 153 |
} |
| 154 |
|
| 155 |
public static function add_fediverse_profile( $user ) { |
| 156 |
?> |
| 157 |
<h2 id="activitypub"><?php \esc_html_e( 'ActivityPub', 'activitypub' ); ?></h2> |
| 158 |
<?php |
| 159 |
\Activitypub\get_identifier_settings( $user->ID ); |
| 160 |
} |
| 161 |
|
| 162 |
public static function enqueue_scripts( $hook_suffix ) { |
| 163 |
if ( false !== strpos( $hook_suffix, 'activitypub' ) ) { |
| 164 |
wp_enqueue_style( 'activitypub-admin-styles', plugins_url( 'assets/css/activitypub-admin.css', ACTIVITYPUB_PLUGIN_FILE ), array(), '1.0.0' ); |
| 165 |
wp_enqueue_script( 'activitypub-admin-styles', plugins_url( 'assets/js/activitypub-admin.js', ACTIVITYPUB_PLUGIN_FILE ), array( 'jquery' ), '1.0.0', false ); |
| 166 |
} |
| 167 |
} |
| 168 |
} |
| 169 |
|