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 -205 1.3.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,16 +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 -
22 - if ( ! is_user_disabled( get_current_user_id() ) ) {
23 - \add_action( 'show_user_profile', array( self::class, 'add_profile' ) );
24 - }
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' ) );
25 17 }
26 18
27 19 /**
28 20 * Add admin menu entry
@@ -27,24 +19,17 @@
27 19 /**
28 20 * Add admin menu entry
29 21 */
30 22 public static function admin_menu() {
31 - $settings_page = \add_options_page(
32 - 'Welcome',
23 + $settings_page = add_options_page(
33 24 'ActivityPub',
25 + 'ActivityPub',
34 26 'manage_options',
35 27 'activitypub',
36 - array( self::class, 'settings_page' )
28 + array( '\Activitypub\Admin', 'settings_page' )
37 29 );
38 30
39 - \add_action( 'load-' . $settings_page, array( self::class, 'add_settings_help_tab' ) );
40 -
41 - // user has to be able to publish posts
42 - if ( ! is_user_disabled( get_current_user_id() ) ) {
43 - $followers_list_page = \add_users_page( \__( 'Followers', 'activitypub' ), \__( 'Followers', 'activitypub' ), 'read', 'activitypub-followers-list', array( self::class, 'followers_list_page' ) );
44 -
45 - \add_action( 'load-' . $followers_list_page, array( self::class, 'add_followers_list_help_tab' ) );
46 - }
31 + add_action( 'load-' . $settings_page, array( '\Activitypub\Admin', 'add_help_tab' ) );
47 32 }
48 33
49 34 /**
50 35 * Load settings page
@@ -49,227 +34,85 @@
49 34 /**
50 35 * Load settings page
51 36 */
52 37 public static function settings_page() {
53 - // phpcs:ignore WordPress.Security.NonceVerification.Recommended
54 - if ( empty( $_GET['tab'] ) ) {
55 - $tab = 'welcome';
56 - } else {
57 - // phpcs:ignore WordPress.Security.NonceVerification.Recommended
58 - $tab = sanitize_key( $_GET['tab'] );
59 - }
60 -
61 - switch ( $tab ) {
62 - case 'settings':
63 - \load_template( ACTIVITYPUB_PLUGIN_DIR . 'templates/settings.php' );
64 - break;
65 - case 'followers':
66 - \load_template( ACTIVITYPUB_PLUGIN_DIR . 'templates/blog-user-followers-list.php' );
67 - break;
68 - case 'welcome':
69 - default:
70 - wp_enqueue_script( 'plugin-install' );
71 - add_thickbox();
72 - wp_enqueue_script( 'updates' );
73 -
74 - \load_template( ACTIVITYPUB_PLUGIN_DIR . 'templates/welcome.php' );
75 - break;
76 - }
38 + load_template( dirname( __FILE__ ) . '/../templates/settings-page.php' );
77 39 }
78 40
79 41 /**
80 - * Load user settings page
42 + * Register PubSubHubbub settings
81 43 */
82 - public static function followers_list_page() {
83 - // user has to be able to publish posts
84 - if ( ! is_user_disabled( get_current_user_id() ) ) {
85 - \load_template( ACTIVITYPUB_PLUGIN_DIR . 'templates/user-followers-list.php' );
86 - }
87 - }
88 -
89 - /**
90 - * Register ActivityPub settings
91 - */
92 44 public static function register_settings() {
93 - \register_setting(
94 - 'activitypub',
95 - 'activitypub_post_content_type',
96 - array(
45 + register_setting(
46 + 'activitypub', 'activitypub_post_content_type', array(
97 47 'type' => 'string',
98 - 'description' => \__( 'Use title and link, summary, full or custom content', 'activitypub' ),
48 + 'description' => __( 'Use summary or full content', 'activitypub' ),
99 49 'show_in_rest' => array(
100 50 'schema' => array(
101 - 'enum' => array(
102 - 'title',
103 - 'excerpt',
104 - 'content',
105 - ),
51 + 'enum' => array( 'excerpt', 'content' ),
106 52 ),
107 53 ),
108 54 'default' => 'content',
109 55 )
110 56 );
111 - \register_setting(
112 - 'activitypub',
113 - 'activitypub_custom_post_content',
114 - array(
57 + register_setting(
58 + 'activitypub', 'activitypub_object_type', array(
115 59 'type' => 'string',
116 - 'description' => \__( 'Define your own custom post template', 'activitypub' ),
117 - 'show_in_rest' => true,
118 - 'default' => ACTIVITYPUB_CUSTOM_POST_CONTENT,
119 - )
120 - );
121 - \register_setting(
122 - 'activitypub',
123 - 'activitypub_max_image_attachments',
124 - array(
125 - 'type' => 'integer',
126 - 'description' => \__( 'Number of images to attach to posts.', 'activitypub' ),
127 - 'default' => ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS,
128 - )
129 - );
130 - \register_setting(
131 - 'activitypub',
132 - 'activitypub_object_type',
133 - array(
134 - 'type' => 'string',
135 - 'description' => \__( 'The Activity-Object-Type', 'activitypub' ),
60 + 'description' => __( 'The Activity-Object-Type', 'activitypub' ),
136 61 'show_in_rest' => array(
137 62 'schema' => array(
138 - 'enum' => array(
139 - 'note',
140 - 'article',
141 - 'wordpress-post-format',
142 - ),
63 + 'enum' => array( 'note', 'article', 'wordpress-post-format' ),
143 64 ),
144 65 ),
145 66 'default' => 'note',
146 67 )
147 68 );
148 - \register_setting(
149 - 'activitypub',
150 - 'activitypub_use_hashtags',
151 - array(
69 + register_setting(
70 + 'activitypub', 'activitypub_use_shortlink', array(
152 71 'type' => 'boolean',
153 - 'description' => \__( 'Add hashtags in the content as native tags and replace the #tag with the tag-link', 'activitypub' ),
154 - 'default' => '0',
72 + 'description' => __( 'Use the Shortlink instead of the permalink', 'activitypub' ),
73 + 'default' => 0,
155 74 )
156 75 );
157 - \register_setting(
158 - 'activitypub',
159 - 'activitypub_support_post_types',
160 - array(
161 - 'type' => 'string',
162 - 'description' => \esc_html__( 'Enable ActivityPub support for post types', 'activitypub' ),
163 - 'show_in_rest' => true,
164 - 'default' => array( 'post', 'pages' ),
165 - )
166 - );
167 - \register_setting(
168 - 'activitypub',
169 - 'activitypub_blog_user_identifier',
170 - array(
171 - 'type' => 'string',
172 - 'description' => \esc_html__( 'The Identifier of the Blog-User', 'activitypub' ),
173 - 'show_in_rest' => true,
174 - 'default' => Blog_User::get_default_username(),
175 - 'sanitize_callback' => function( $value ) {
176 - // hack to allow dots in the username
177 - $parts = explode( '.', $value );
178 - $sanitized = array();
179 -
180 - foreach ( $parts as $part ) {
181 - $sanitized[] = \sanitize_title( $part );
182 - }
183 -
184 - $sanitized = implode( '.', $sanitized );
185 -
186 - // check for login or nicename.
187 - $user = new WP_User_Query(
188 - array(
189 - 'search' => $sanitized,
190 - 'search_columns' => array( 'user_login', 'user_nicename' ),
191 - 'number' => 1,
192 - 'hide_empty' => true,
193 - 'fields' => 'ID',
194 - )
195 - );
196 -
197 - if ( $user->results ) {
198 - add_settings_error(
199 - 'activitypub_blog_user_identifier',
200 - 'activitypub_blog_user_identifier',
201 - \esc_html__( 'You cannot use an existing author\'s name for the blog profile ID.', 'activitypub' ),
202 - 'error'
203 - );
204 -
205 - return Blog_User::get_default_username();
206 - }
207 -
208 - return $sanitized;
209 - },
210 - )
211 - );
212 - \register_setting(
213 - 'activitypub',
214 - 'activitypub_enable_users',
215 - array(
76 + register_setting(
77 + 'activitypub', 'activitypub_use_hashtags', array(
216 78 'type' => 'boolean',
217 - 'description' => \__( 'Every Author on this Blog (with the publish_posts capability) gets his own ActivityPub enabled Profile.', 'activitypub' ),
218 - 'default' => '1',
79 + 'description' => __( 'Add hashtags in the content as native tags and replace the #tag with the tag-link', 'activitypub' ),
80 + 'default' => 0,
219 81 )
220 82 );
221 - \register_setting(
222 - 'activitypub',
223 - 'activitypub_enable_blog_user',
224 - array(
83 + register_setting(
84 + 'activitypub', 'activitypub_add_tags_as_hashtags', array(
225 85 'type' => 'boolean',
226 - 'description' => \__( 'Your Blog becomes an ActivityPub compatible Profile.', 'activitypub' ),
227 - 'default' => '0',
86 + 'description' => __( 'Add all tags as hashtags at the end of each activity', 'activitypub' ),
87 + 'default' => 0,
228 88 )
229 89 );
230 90 }
231 91
232 - public static function add_settings_help_tab() {
233 - require_once ACTIVITYPUB_PLUGIN_DIR . 'includes/help.php';
234 - }
235 -
236 - public static function add_followers_list_help_tab() {
237 - // todo
238 - }
239 -
240 - public static function add_profile( $user ) {
241 - $description = get_user_meta( $user->ID, 'activitypub_user_description', true );
242 -
243 - \load_template(
244 - ACTIVITYPUB_PLUGIN_DIR . 'templates/user-settings.php',
245 - true,
92 + public static function add_help_tab() {
93 + get_current_screen()->add_help_tab(
246 94 array(
247 - '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>',
248 99 )
249 100 );
250 - }
251 101
252 - public static function save_user_description( $user_id ) {
253 - if ( ! isset( $_REQUEST['_apnonce'] ) ) {
254 - return false;
255 - }
256 - $nonce = sanitize_text_field( wp_unslash( $_REQUEST['_apnonce'] ) );
257 - if (
258 - ! wp_verify_nonce( $nonce, 'activitypub-user-description' ) ||
259 - ! current_user_can( 'edit_user', $user_id )
260 - ) {
261 - return false;
262 - }
263 - $description = ! empty( $_POST['activitypub-user-description'] ) ? sanitize_text_field( wp_unslash( $_POST['activitypub-user-description'] ) ) : false;
264 - if ( $description ) {
265 - update_user_meta( $user_id, 'activitypub_user_description', $description );
266 - }
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 + );
267 110 }
268 111
269 - public static function enqueue_scripts( $hook_suffix ) {
270 - if ( false !== strpos( $hook_suffix, 'activitypub' ) ) {
271 - wp_enqueue_style( 'activitypub-admin-styles', plugins_url( 'assets/css/activitypub-admin.css', ACTIVITYPUB_PLUGIN_FILE ), array(), '1.0.0' );
272 - wp_enqueue_script( 'activitypub-admin-styles', plugins_url( 'assets/js/activitypub-admin.js', ACTIVITYPUB_PLUGIN_FILE ), array( 'jquery' ), '1.0.0', false );
273 - }
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 );
274 117 }
275 118 }