PluginProbe
ActivityPub / 0.7.3
ActivityPub v0.7.3
9.3.1 9.3.0 9.2.2 9.2.1 9.2.0 9.1.0 9.0.2 9.0.1 9.0.0 8.3.0 8.2.1 8.2.0 8.1.1 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.3.0 2.0.0 2.0.1 2.1.0 2.1.1 All 160 releases
← All changes | includes/class-admin.php +48 -237 2.0.00.7.3 View file →
@@ -1,10 +1,7 @@
1 1 <?php
2 2 namespace Activitypub;
3 3
4 -use WP_User_Query;
5 -use Activitypub\Model\Blog_User;
6 -
7 4 /**
8 5 * ActivityPub Admin Class
9 6 *
10 7 * @author Matthias Pfefferle
@@ -13,17 +10,11 @@
13 10 /**
14 11 * Initialize the class, registering WordPress hooks
15 12 */
16 13 public static function init() {
17 - \add_action( 'admin_menu', array( self::class, 'admin_menu' ) );
18 - \add_action( 'admin_init', array( self::class, 'register_settings' ) );
19 - \add_action( 'personal_options_update', array( self::class, 'save_user_description' ) );
20 - \add_action( 'admin_enqueue_scripts', array( self::class, 'enqueue_scripts' ) );
21 - \add_action( 'admin_notices', array( self::class, 'admin_notices' ) );
22 -
23 - if ( ! is_user_disabled( get_current_user_id() ) ) {
24 - \add_action( 'show_user_profile', array( self::class, 'add_profile' ) );
25 - }
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' ) );
26 17 }
27 18
28 19 /**
29 20 * Add admin menu entry
@@ -28,280 +19,100 @@
28 19 /**
29 20 * Add admin menu entry
30 21 */
31 22 public static function admin_menu() {
32 - $settings_page = \add_options_page(
33 - 'Welcome',
23 + $settings_page = add_options_page(
34 24 'ActivityPub',
25 + 'ActivityPub',
35 26 'manage_options',
36 27 'activitypub',
37 - array( self::class, 'settings_page' )
28 + array( '\Activitypub\Admin', 'settings_page' )
38 29 );
39 30
40 - \add_action( 'load-' . $settings_page, array( self::class, 'add_settings_help_tab' ) );
41 -
42 - // user has to be able to publish posts
43 - if ( ! is_user_disabled( get_current_user_id() ) ) {
44 - $followers_list_page = \add_users_page( \__( 'Followers', 'activitypub' ), \__( 'Followers', 'activitypub' ), 'read', 'activitypub-followers-list', array( self::class, 'followers_list_page' ) );
45 -
46 - \add_action( 'load-' . $followers_list_page, array( self::class, 'add_followers_list_help_tab' ) );
47 - }
31 + add_action( 'load-' . $settings_page, array( '\Activitypub\Admin', 'add_help_tab' ) );
48 32 }
49 33
50 34 /**
51 - * Display admin menu notices about configuration problems or conflicts.
52 - *
53 - * @return void
54 - */
55 - public static function admin_notices() {
56 - $permalink_structure = \get_option( 'permalink_structure' );
57 - if ( empty( $permalink_structure ) ) {
58 - $admin_notice = \__( 'You are using the ActivityPub plugin without setting a permalink structure. This will prevent ActivityPub from working. Please set a permalink structure.', 'activitypub' );
59 - self::show_admin_notice( $admin_notice, 'error' );
60 - }
61 - }
62 -
63 - /**
64 - * Display one admin menu notice about configuration problems or conflicts.
65 - *
66 - * @param string $admin_notice The notice to display.
67 - * @param string $level The level of the notice (error, warning, success, info).
68 - *
69 - * @return void
70 - */
71 - private static function show_admin_notice( $admin_notice, $level ) {
72 - ?>
73 -
74 - <div class="notice notice-<?php echo esc_attr( $level ); ?>">
75 - <p><?php echo wp_kses( $admin_notice, 'data' ); ?></p>
76 - </div>
77 -
78 - <?php
79 - }
80 -
81 - /**
82 35 * Load settings page
83 36 */
84 37 public static function settings_page() {
85 - // phpcs:ignore WordPress.Security.NonceVerification.Recommended
86 - if ( empty( $_GET['tab'] ) ) {
87 - $tab = 'welcome';
88 - } else {
89 - // phpcs:ignore WordPress.Security.NonceVerification.Recommended
90 - $tab = sanitize_key( $_GET['tab'] );
91 - }
92 -
93 - switch ( $tab ) {
94 - case 'settings':
95 - \load_template( ACTIVITYPUB_PLUGIN_DIR . 'templates/settings.php' );
96 - break;
97 - case 'followers':
98 - \load_template( ACTIVITYPUB_PLUGIN_DIR . 'templates/blog-user-followers-list.php' );
99 - break;
100 - case 'welcome':
101 - default:
102 - wp_enqueue_script( 'plugin-install' );
103 - add_thickbox();
104 - wp_enqueue_script( 'updates' );
105 -
106 - \load_template( ACTIVITYPUB_PLUGIN_DIR . 'templates/welcome.php' );
107 - break;
108 - }
38 + load_template( dirname( __FILE__ ) . '/../templates/settings-page.php' );
109 39 }
110 40
111 41 /**
112 - * Load user settings page
42 + * Register PubSubHubbub settings
113 43 */
114 - public static function followers_list_page() {
115 - // user has to be able to publish posts
116 - if ( ! is_user_disabled( get_current_user_id() ) ) {
117 - \load_template( ACTIVITYPUB_PLUGIN_DIR . 'templates/user-followers-list.php' );
118 - }
119 - }
120 -
121 - /**
122 - * Register ActivityPub settings
123 - */
124 44 public static function register_settings() {
125 - \register_setting(
126 - 'activitypub',
127 - 'activitypub_post_content_type',
128 - array(
45 + register_setting(
46 + 'activitypub', 'activitypub_post_content_type', array(
129 47 'type' => 'string',
130 - 'description' => \__( 'Use title and link, summary, full or custom content', 'activitypub' ),
48 + 'description' => __( 'Use summary or full content', 'activitypub' ),
131 49 'show_in_rest' => array(
132 50 'schema' => array(
133 - 'enum' => array(
134 - 'title',
135 - 'excerpt',
136 - 'content',
137 - ),
51 + 'enum' => array( 'excerpt', 'content' ),
138 52 ),
139 53 ),
140 54 'default' => 'content',
141 55 )
142 56 );
143 - \register_setting(
144 - 'activitypub',
145 - 'activitypub_custom_post_content',
146 - array(
57 + register_setting(
58 + 'activitypub', 'activitypub_object_type', array(
147 59 'type' => 'string',
148 - 'description' => \__( 'Define your own custom post template', 'activitypub' ),
149 - 'show_in_rest' => true,
150 - 'default' => ACTIVITYPUB_CUSTOM_POST_CONTENT,
151 - )
152 - );
153 - \register_setting(
154 - 'activitypub',
155 - 'activitypub_max_image_attachments',
156 - array(
157 - 'type' => 'integer',
158 - 'description' => \__( 'Number of images to attach to posts.', 'activitypub' ),
159 - 'default' => ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS,
160 - )
161 - );
162 - \register_setting(
163 - 'activitypub',
164 - 'activitypub_object_type',
165 - array(
166 - 'type' => 'string',
167 - 'description' => \__( 'The Activity-Object-Type', 'activitypub' ),
60 + 'description' => __( 'The Activity-Object-Type', 'activitypub' ),
168 61 'show_in_rest' => array(
169 62 'schema' => array(
170 - 'enum' => array(
171 - 'note',
172 - 'article',
173 - 'wordpress-post-format',
174 - ),
63 + 'enum' => array( 'note', 'article', 'wordpress-post-format' ),
175 64 ),
176 65 ),
177 66 'default' => 'note',
178 67 )
179 68 );
180 - \register_setting(
181 - 'activitypub',
182 - 'activitypub_use_hashtags',
183 - array(
69 + register_setting(
70 + 'activitypub', 'activitypub_use_shortlink', array(
184 71 'type' => 'boolean',
185 - 'description' => \__( 'Add hashtags in the content as native tags and replace the #tag with the tag-link', 'activitypub' ),
186 - 'default' => '0',
72 + 'description' => __( 'Use the Shortlink instead of the permalink', 'activitypub' ),
73 + 'default' => 0,
187 74 )
188 75 );
189 - \register_setting(
190 - 'activitypub',
191 - 'activitypub_support_post_types',
192 - array(
193 - 'type' => 'string',
194 - 'description' => \esc_html__( 'Enable ActivityPub support for post types', 'activitypub' ),
195 - 'show_in_rest' => true,
196 - 'default' => array( 'post', 'pages' ),
197 - )
198 - );
199 - \register_setting(
200 - 'activitypub',
201 - 'activitypub_blog_user_identifier',
202 - array(
203 - 'type' => 'string',
204 - 'description' => \esc_html__( 'The Identifier of the Blog-User', 'activitypub' ),
205 - 'show_in_rest' => true,
206 - 'default' => Blog_User::get_default_username(),
207 - 'sanitize_callback' => function ( $value ) {
208 - // hack to allow dots in the username
209 - $parts = explode( '.', $value );
210 - $sanitized = array();
211 -
212 - foreach ( $parts as $part ) {
213 - $sanitized[] = \sanitize_title( $part );
214 - }
215 -
216 - $sanitized = implode( '.', $sanitized );
217 -
218 - // check for login or nicename.
219 - $user = new WP_User_Query(
220 - array(
221 - 'search' => $sanitized,
222 - 'search_columns' => array( 'user_login', 'user_nicename' ),
223 - 'number' => 1,
224 - 'hide_empty' => true,
225 - 'fields' => 'ID',
226 - )
227 - );
228 -
229 - if ( $user->results ) {
230 - add_settings_error(
231 - 'activitypub_blog_user_identifier',
232 - 'activitypub_blog_user_identifier',
233 - \esc_html__( 'You cannot use an existing author\'s name for the blog profile ID.', 'activitypub' ),
234 - 'error'
235 - );
236 -
237 - return Blog_User::get_default_username();
238 - }
239 -
240 - return $sanitized;
241 - },
242 - )
243 - );
244 - \register_setting(
245 - 'activitypub',
246 - 'activitypub_enable_users',
247 - array(
76 + register_setting(
77 + 'activitypub', 'activitypub_use_hashtags', array(
248 78 'type' => 'boolean',
249 - 'description' => \__( 'Every Author on this Blog (with the publish_posts capability) gets his own ActivityPub enabled Profile.', 'activitypub' ),
250 - 'default' => '1',
79 + 'description' => __( 'Add hashtags in the content as native tags and replace the #tag with the tag-link', 'activitypub' ),
80 + 'default' => 0,
251 81 )
252 82 );
253 - \register_setting(
254 - 'activitypub',
255 - 'activitypub_enable_blog_user',
256 - array(
83 + register_setting(
84 + 'activitypub', 'activitypub_add_tags_as_hashtags', array(
257 85 'type' => 'boolean',
258 - 'description' => \__( 'Your Blog becomes an ActivityPub compatible Profile.', 'activitypub' ),
259 - 'default' => '0',
86 + 'description' => __( 'Add all tags as hashtags at the end of each activity', 'activitypub' ),
87 + 'default' => 0,
260 88 )
261 89 );
262 90 }
263 91
264 - public static function add_settings_help_tab() {
265 - require_once ACTIVITYPUB_PLUGIN_DIR . 'includes/help.php';
266 - }
267 -
268 - public static function add_followers_list_help_tab() {
269 - // todo
270 - }
271 -
272 - public static function add_profile( $user ) {
273 - $description = get_user_meta( $user->ID, 'activitypub_user_description', true );
274 -
275 - \load_template(
276 - ACTIVITYPUB_PLUGIN_DIR . 'templates/user-settings.php',
277 - true,
92 + public static function add_help_tab() {
93 + get_current_screen()->add_help_tab(
278 94 array(
279 - 'description' => $description,
95 + 'id' => 'overview',
96 + 'title' => __( 'Overview', 'activitypub' ),
97 + 'content' =>
98 + '<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>',
280 99 )
281 100 );
282 - }
283 101
284 - public static function save_user_description( $user_id ) {
285 - if ( ! isset( $_REQUEST['_apnonce'] ) ) {
286 - return false;
287 - }
288 - $nonce = sanitize_text_field( wp_unslash( $_REQUEST['_apnonce'] ) );
289 - if (
290 - ! wp_verify_nonce( $nonce, 'activitypub-user-description' ) ||
291 - ! current_user_can( 'edit_user', $user_id )
292 - ) {
293 - return false;
294 - }
295 - $description = ! empty( $_POST['activitypub-user-description'] ) ? sanitize_text_field( wp_unslash( $_POST['activitypub-user-description'] ) ) : false;
296 - if ( $description ) {
297 - update_user_meta( $user_id, 'activitypub_user_description', $description );
298 - }
102 + get_current_screen()->set_help_sidebar(
103 + '<p><strong>' . __( 'For more information:', 'activitypub' ) . '</strong></p>' .
104 + '<p>' . __( '<a href="https://activitypub.rocks/">Test Suite</a>', 'activitypub' ) . '</p>' .
105 + '<p>' . __( '<a href="https://www.w3.org/TR/activitypub/">W3C Spec</a>', 'activitypub' ) . '</p>' .
106 + '<p>' . __( '<a href="https://github.com/pfefferle/wordpress-activitypub/issues">Give us feedback</a>', 'activitypub' ) . '</p>' .
107 + '<hr />' .
108 + '<p>' . __( '<a href="https://notiz.blog/donate">Donate</a>', 'activitypub' ) . '</p>'
109 + );
299 110 }
300 111
301 - public static function enqueue_scripts( $hook_suffix ) {
302 - if ( false !== strpos( $hook_suffix, 'activitypub' ) ) {
303 - wp_enqueue_style( 'activitypub-admin-styles', plugins_url( 'assets/css/activitypub-admin.css', ACTIVITYPUB_PLUGIN_FILE ), array(), '1.0.0' );
304 - wp_enqueue_script( 'activitypub-admin-styles', plugins_url( 'assets/js/activitypub-admin.js', ACTIVITYPUB_PLUGIN_FILE ), array( 'jquery' ), '1.0.0', false );
305 - }
112 + public static function add_fediverse_profile( $user ) {
113 + ?>
114 + <h2><?php esc_html_e( 'Fediverse', 'activitypub' ); ?></h2>
115 + <?php
116 + \Activitypub\get_identifier_settings( $user->ID );
306 117 }
307 118 }