| 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 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* Add admin menu entry |
| 21 |
*/ |
| 22 |
public static function admin_menu() { |
| 23 |
$settings_page = \add_options_page( |
| 24 |
'ActivityPub', |
| 25 |
'ActivityPub', |
| 26 |
'manage_options', |
| 27 |
'activitypub', |
| 28 |
array( '\Activitypub\Admin', 'settings_page' ) |
| 29 |
); |
| 30 |
|
| 31 |
\add_action( 'load-' . $settings_page, array( '\Activitypub\Admin', 'add_settings_help_tab' ) ); |
| 32 |
|
| 33 |
$followers_list_page = \add_users_page( \__( 'Followers', 'activitypub' ), \__( 'Followers (Fediverse)', 'activitypub' ), 'read', 'activitypub-followers-list', array( '\Activitypub\Admin', 'followers_list_page' ) ); |
| 34 |
|
| 35 |
\add_action( 'load-' . $followers_list_page, array( '\Activitypub\Admin', 'add_followers_list_help_tab' ) ); |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Load settings page |
| 40 |
*/ |
| 41 |
public static function settings_page() { |
| 42 |
\load_template( \dirname( __FILE__ ) . '/../templates/settings.php' ); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Load user settings page |
| 47 |
*/ |
| 48 |
public static function followers_list_page() { |
| 49 |
\load_template( \dirname( __FILE__ ) . '/../templates/followers-list.php' ); |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Register ActivityPub settings |
| 54 |
*/ |
| 55 |
public static function register_settings() { |
| 56 |
\register_setting( |
| 57 |
'activitypub', 'activitypub_post_content_type', array( |
| 58 |
'type' => 'string', |
| 59 |
'description' => \__( 'Use title and link, summary, full or custom content', 'activitypub' ), |
| 60 |
'show_in_rest' => array( |
| 61 |
'schema' => array( |
| 62 |
'enum' => array( 'title', 'excerpt', 'content' ), |
| 63 |
), |
| 64 |
), |
| 65 |
'default' => 'content', |
| 66 |
) |
| 67 |
); |
| 68 |
\register_setting( |
| 69 |
'activitypub', 'activitypub_custom_post_content', array( |
| 70 |
'type' => 'string', |
| 71 |
'description' => \__( 'Define your own custom post template', 'activitypub' ), |
| 72 |
'show_in_rest' => true, |
| 73 |
'default' => ACTIVITYPUB_CUSTOM_POST_CONTENT, |
| 74 |
) |
| 75 |
); |
| 76 |
\register_setting( |
| 77 |
'activitypub', 'activitypub_object_type', array( |
| 78 |
'type' => 'string', |
| 79 |
'description' => \__( 'The Activity-Object-Type', 'activitypub' ), |
| 80 |
'show_in_rest' => array( |
| 81 |
'schema' => array( |
| 82 |
'enum' => array( 'note', 'article', 'wordpress-post-format' ), |
| 83 |
), |
| 84 |
), |
| 85 |
'default' => 'note', |
| 86 |
) |
| 87 |
); |
| 88 |
\register_setting( |
| 89 |
'activitypub', 'activitypub_use_hashtags', array( |
| 90 |
'type' => 'boolean', |
| 91 |
'description' => \__( 'Add hashtags in the content as native tags and replace the #tag with the tag-link', 'activitypub' ), |
| 92 |
'default' => 0, |
| 93 |
) |
| 94 |
); |
| 95 |
\register_setting( |
| 96 |
'activitypub', 'activitypub_allowed_html', array( |
| 97 |
'type' => 'string', |
| 98 |
'description' => \__( 'List of HTML elements that are allowed in activities.', 'activitypub' ), |
| 99 |
'default' => ACTIVITYPUB_ALLOWED_HTML, |
| 100 |
) |
| 101 |
); |
| 102 |
\register_setting( |
| 103 |
'activitypub', 'activitypub_support_post_types', array( |
| 104 |
'type' => 'string', |
| 105 |
'description' => \esc_html__( 'Enable ActivityPub support for post types', 'activitypub' ), |
| 106 |
'show_in_rest' => true, |
| 107 |
'default' => array( 'post', 'pages' ), |
| 108 |
) |
| 109 |
); |
| 110 |
} |
| 111 |
|
| 112 |
public static function add_settings_help_tab() { |
| 113 |
\get_current_screen()->add_help_tab( |
| 114 |
array( |
| 115 |
'id' => 'overview', |
| 116 |
'title' => \__( 'Overview', 'activitypub' ), |
| 117 |
'content' => |
| 118 |
'<p>' . \__( 'ActivityPub is a decentralized social networking protocol based on the ActivityStreams 2.0 data format. ActivityPub is an official W3C recommended standard published by the W3C Social Web Working Group. It provides a client to server API for creating, updating and deleting content, as well as a federated server to server API for delivering notifications and subscribing to content.', 'activitypub' ) . '</p>', |
| 119 |
) |
| 120 |
); |
| 121 |
|
| 122 |
\get_current_screen()->set_help_sidebar( |
| 123 |
'<p><strong>' . \__( 'For more information:', 'activitypub' ) . '</strong></p>' . |
| 124 |
'<p>' . \__( '<a href="https://activitypub.rocks/">Test Suite</a>', 'activitypub' ) . '</p>' . |
| 125 |
'<p>' . \__( '<a href="https://www.w3.org/TR/activitypub/">W3C Spec</a>', 'activitypub' ) . '</p>' . |
| 126 |
'<p>' . \__( '<a href="https://github.com/pfefferle/wordpress-activitypub/issues">Give us feedback</a>', 'activitypub' ) . '</p>' . |
| 127 |
'<hr />' . |
| 128 |
'<p>' . \__( '<a href="https://notiz.blog/donate">Donate</a>', 'activitypub' ) . '</p>' |
| 129 |
); |
| 130 |
} |
| 131 |
|
| 132 |
public static function add_followers_list_help_tab() { |
| 133 |
// todo |
| 134 |
} |
| 135 |
|
| 136 |
public static function add_fediverse_profile( $user ) { |
| 137 |
?> |
| 138 |
<h2><?php \esc_html_e( 'Fediverse', 'activitypub' ); ?></h2> |
| 139 |
<?php |
| 140 |
\Activitypub\get_identifier_settings( $user->ID ); |
| 141 |
} |
| 142 |
} |
| 143 |
|