| @@ -325,15 +325,31 @@ | ||
| 325 | 325 | |
| 326 | 326 | return $file_paths; |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | + /** | |
| 330 | + * Get an asset version that changes when the local file changes. | |
| 331 | + * | |
| 332 | + * @param string $file Relative asset path. | |
| 333 | + * @return string Asset version. | |
| 334 | + */ | |
| 335 | + private function get_asset_version( $file ) { | |
| 336 | + $path = dirname( FRIENDS_PLUGIN_FILE ) . '/' . $file; | |
| 337 | + if ( file_exists( $path ) ) { | |
| 338 | + return Friends::VERSION . '-' . filemtime( $path ); | |
| 339 | + } | |
| 340 | + | |
| 341 | + return Friends::VERSION; | |
| 342 | + } | |
| 343 | + | |
| 329 | 344 | public function default_theme() { |
| 330 | 345 | $handle = 'friends'; |
| 331 | 346 | $file = 'friends.css'; |
| 332 | - $version = Friends::VERSION; | |
| 347 | + $version = $this->get_asset_version( $file ); | |
| 333 | 348 | wp_enqueue_style( $handle, plugins_url( $file, FRIENDS_PLUGIN_FILE ), array(), apply_filters( 'friends_debug_enqueue', $version, $handle, dirname( FRIENDS_PLUGIN_FILE ) . '/' . $file ) ); |
| 334 | 349 | |
| 335 | - wp_enqueue_script( 'friends-default-theme', plugins_url( 'friends-default-theme.js', FRIENDS_PLUGIN_FILE ), array( 'jquery', 'friends' ), $version, true ); | |
| 350 | + $file = 'friends-default-theme.js'; | |
| 351 | + wp_enqueue_script( 'friends-default-theme', plugins_url( $file, FRIENDS_PLUGIN_FILE ), array( 'jquery', 'friends' ), $this->get_asset_version( $file ), true ); | |
| 336 | 352 | } |
| 337 | 353 | |
| 338 | 354 | /** |
| 339 | 355 | * Reference our script for the /friends page |
| @@ -345,35 +361,36 @@ | ||
| 345 | 361 | global $wp_query; |
| 346 | 362 | |
| 347 | 363 | $handle = 'friends'; |
| 348 | 364 | $file = 'friends.js'; |
| 349 | - $version = Friends::VERSION; | |
| 365 | + $version = $this->get_asset_version( $file ); | |
| 350 | 366 | wp_enqueue_script( $handle, plugins_url( $file, FRIENDS_PLUGIN_FILE ), array( 'common', 'jquery', 'wp-util' ), apply_filters( 'friends_debug_enqueue', $version, $handle, dirname( FRIENDS_PLUGIN_FILE ) . '/' . $file ), true ); |
| 351 | 367 | |
| 352 | 368 | $query_vars = wp_json_encode( $this->get_minimal_query_vars( $wp_query->query_vars ) ); |
| 353 | 369 | |
| 354 | 370 | $variables = array( |
| 355 | - 'emojis_json' => plugins_url( 'emojis.json', FRIENDS_PLUGIN_FILE ), | |
| 356 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), | |
| 357 | - 'rest_base' => rest_url( 'friends/v1/' ), | |
| 358 | - 'rest_nonce' => wp_create_nonce( 'wp_rest' ), | |
| 359 | - 'text_link_expired' => __( 'The link has expired. A new link has been generated, please click it again.', 'friends' ), | |
| 360 | - 'text_undo' => __( 'Undo' ), // phpcs:ignore WordPress.WP.I18n.MissingArgDomain | |
| 361 | - 'text_trash_post' => __( 'Trash this post', 'friends' ), | |
| 362 | - 'text_del_convers' => __( 'Do you really want to delete this conversation?', 'friends' ), | |
| 363 | - 'text_no_more_posts' => __( 'No more posts available.', 'friends' ), | |
| 364 | - 'text_checking_url' => __( 'Checking URL.', 'friends' ), | |
| 365 | - 'text_refreshed' => __( 'Refreshed', 'friends' ), | |
| 366 | - 'text_refreshing' => __( 'Refreshing', 'friends' ), | |
| 367 | - 'text_compact_mode' => __( 'Compact mode', 'friends' ), | |
| 368 | - 'text_expanded_mode' => __( 'Expanded mode', 'friends' ), | |
| 369 | - 'text_loading_comments' => __( 'Loading comments...', 'friends' ), | |
| 370 | - 'text_still_loading' => __( 'Still loading...', 'friends' ), | |
| 371 | - 'refresh_now' => isset( $_GET['refresh'] ) ? 'true' : 'false', // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 372 | - 'query_vars' => $query_vars, | |
| 373 | - 'qv_sign' => sha1( wp_salt( 'nonce' ) . $query_vars ), | |
| 374 | - 'current_page' => get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1, | |
| 375 | - 'max_page' => $wp_query->max_num_pages, | |
| 371 | + 'emojis_json' => plugins_url( 'emojis.json', FRIENDS_PLUGIN_FILE ), | |
| 372 | + 'ajax_url' => admin_url( 'admin-ajax.php' ), | |
| 373 | + 'rest_base' => rest_url( 'friends/v1/' ), | |
| 374 | + 'rest_nonce' => wp_create_nonce( 'wp_rest' ), | |
| 375 | + 'text_link_expired' => __( 'The link has expired. A new link has been generated, please click it again.', 'friends' ), | |
| 376 | + 'text_undo' => __( 'Undo' ), // phpcs:ignore WordPress.WP.I18n.MissingArgDomain | |
| 377 | + 'text_trash_post' => __( 'Trash this post', 'friends' ), | |
| 378 | + 'text_del_convers' => __( 'Do you really want to delete this conversation?', 'friends' ), | |
| 379 | + 'text_no_more_posts' => __( 'No more posts available.', 'friends' ), | |
| 380 | + 'text_checking_url' => __( 'Checking URL.', 'friends' ), | |
| 381 | + 'text_refreshed' => __( 'Refreshed', 'friends' ), | |
| 382 | + 'text_refreshing' => __( 'Refreshing', 'friends' ), | |
| 383 | + 'text_compact_mode' => __( 'Compact mode', 'friends' ), | |
| 384 | + 'text_expanded_mode' => __( 'Expanded mode', 'friends' ), | |
| 385 | + 'text_loading_comments' => __( 'Loading comments...', 'friends' ), | |
| 386 | + 'text_still_loading' => __( 'Still loading...', 'friends' ), | |
| 387 | + 'message_delivery_nonce' => wp_create_nonce( 'friends-message-delivery-statuses' ), | |
| 388 | + 'refresh_now' => isset( $_GET['refresh'] ) ? 'true' : 'false', // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 389 | + 'query_vars' => $query_vars, | |
| 390 | + 'qv_sign' => sha1( wp_salt( 'nonce' ) . $query_vars ), | |
| 391 | + 'current_page' => get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1, | |
| 392 | + 'max_page' => $wp_query->max_num_pages, | |
| 376 | 393 | ); |
| 377 | 394 | |
| 378 | 395 | // translators: %s is a user handle. |
| 379 | 396 | $variables['text_confirm_delete_follower'] = __( 'Do you really want to delete the follower %s?', 'friends' ); |
| @@ -523,12 +540,13 @@ | ||
| 523 | 540 | |
| 524 | 541 | public function mastodon_theme() { |
| 525 | 542 | $handle = 'friends-mastodon'; |
| 526 | 543 | $file = 'templates/mastodon/mastodon.css'; |
| 527 | - $version = Friends::VERSION; | |
| 544 | + $version = $this->get_asset_version( $file ); | |
| 528 | 545 | wp_enqueue_style( $handle, plugins_url( $file, FRIENDS_PLUGIN_FILE ), array(), apply_filters( 'friends_debug_enqueue', $version, $handle, dirname( FRIENDS_PLUGIN_FILE ) . '/' . $file ) ); |
| 529 | 546 | |
| 530 | - wp_enqueue_script( 'friends-mastodon', plugins_url( 'templates/mastodon/mastodon.js', FRIENDS_PLUGIN_FILE ), array( 'jquery', 'friends' ), $version, true ); | |
| 547 | + $file = 'templates/mastodon/mastodon.js'; | |
| 548 | + wp_enqueue_script( 'friends-mastodon', plugins_url( $file, FRIENDS_PLUGIN_FILE ), array( 'jquery', 'friends' ), $this->get_asset_version( $file ), true ); | |
| 531 | 549 | wp_localize_script( |
| 532 | 550 | 'friends-mastodon', |
| 533 | 551 | 'friendsMastodon', |
| 534 | 552 | array( |
| @@ -559,12 +577,13 @@ | ||
| 559 | 577 | |
| 560 | 578 | public function twitter_theme() { |
| 561 | 579 | $handle = 'friends-twitter'; |
| 562 | 580 | $file = 'templates/twitter/twitter.css'; |
| 563 | - $version = Friends::VERSION; | |
| 581 | + $version = $this->get_asset_version( $file ); | |
| 564 | 582 | wp_enqueue_style( $handle, plugins_url( $file, FRIENDS_PLUGIN_FILE ), array(), apply_filters( 'friends_debug_enqueue', $version, $handle, dirname( FRIENDS_PLUGIN_FILE ) . '/' . $file ) ); |
| 565 | 583 | |
| 566 | - wp_enqueue_script( 'friends-twitter', plugins_url( 'templates/twitter/twitter.js', FRIENDS_PLUGIN_FILE ), array( 'jquery', 'friends' ), $version, true ); | |
| 584 | + $file = 'templates/twitter/twitter.js'; | |
| 585 | + wp_enqueue_script( 'friends-twitter', plugins_url( $file, FRIENDS_PLUGIN_FILE ), array( 'jquery', 'friends' ), $this->get_asset_version( $file ), true ); | |
| 567 | 586 | wp_localize_script( |
| 568 | 587 | 'friends-twitter', |
| 569 | 588 | 'friendsTwitter', |
| 570 | 589 | array( |
| @@ -583,12 +602,13 @@ | ||
| 583 | 602 | |
| 584 | 603 | public function google_reader_theme() { |
| 585 | 604 | $handle = 'friends-google-reader'; |
| 586 | 605 | $file = 'templates/google-reader/google-reader.css'; |
| 587 | - $version = Friends::VERSION; | |
| 606 | + $version = $this->get_asset_version( $file ); | |
| 588 | 607 | wp_enqueue_style( $handle, plugins_url( $file, FRIENDS_PLUGIN_FILE ), array(), apply_filters( 'friends_debug_enqueue', $version, $handle, dirname( FRIENDS_PLUGIN_FILE ) . '/' . $file ) ); |
| 589 | 608 | |
| 590 | - wp_enqueue_script( 'friends-google-reader', plugins_url( 'templates/google-reader/google-reader.js', FRIENDS_PLUGIN_FILE ), array( 'jquery' ), $version, true ); | |
| 609 | + $file = 'templates/google-reader/google-reader.js'; | |
| 610 | + wp_enqueue_script( 'friends-google-reader', plugins_url( $file, FRIENDS_PLUGIN_FILE ), array( 'jquery' ), $this->get_asset_version( $file ), true ); | |
| 591 | 611 | |
| 592 | 612 | add_filter( |
| 593 | 613 | 'friends_template_paths_theme_google-reader', |
| 594 | 614 | function ( $file_paths ) { |
| @@ -660,9 +680,9 @@ | ||
| 660 | 680 | // No theme swap needed; templates are registered as plugin templates |
| 661 | 681 | // and injected via template_override. |
| 662 | 682 | $handle = 'friends-blocks'; |
| 663 | 683 | $file = 'friends-blocks.css'; |
| 664 | - $version = Friends::VERSION; | |
| 684 | + $version = $this->get_asset_version( $file ); | |
| 665 | 685 | wp_enqueue_style( $handle, plugins_url( $file, FRIENDS_PLUGIN_FILE ), array(), apply_filters( 'friends_debug_enqueue', $version, $handle, dirname( FRIENDS_PLUGIN_FILE ) . '/' . $file ) ); |
| 666 | 686 | } |
| 667 | 687 | |
| 668 | 688 | /** |
| @@ -876,9 +896,9 @@ | ||
| 876 | 896 | return ''; |
| 877 | 897 | } |
| 878 | 898 | |
| 879 | 899 | $author_name = $author->display_name; |
| 880 | - $author_name_html = Feed_Parser_ActivityPub::replace_custom_emojis_for_user( $author_name, $author ); | |
| 900 | + $author_name_html = apply_filters( 'friends_author_display_name_html', esc_html( $author_name ), $author_name, $author ); | |
| 881 | 901 | $override_author_name = apply_filters( 'friends_override_author_name', '', $author_name, $block->context['postId'] ); |
| 882 | 902 | if ( isset( $attributes['isLink'] ) && $attributes['isLink'] ) { |
| 883 | 903 | $author_name_html = sprintf( '<a href="%1$s" target="%2$s" class="wp-block-post-author-name__link">%3$s</a>', esc_url( $author->get_local_friends_page_url() ), esc_attr( $attributes['linkTarget'] ), $author_name_html ); |
| 884 | 904 | } |
| @@ -901,9 +921,9 @@ | ||
| 901 | 921 | $wrapper_attributes, |
| 902 | 922 | wp_kses( |
| 903 | 923 | $author_name_html, |
| 904 | 924 | array_merge( |
| 905 | - Feed_Parser_ActivityPub::get_custom_emoji_allowed_html(), | |
| 925 | + wp_kses_allowed_html( 'post' ), | |
| 906 | 926 | array( |
| 907 | 927 | 'a' => array( |
| 908 | 928 | 'class' => true, |
| 909 | 929 | 'href' => true, |
| @@ -2198,8 +2218,13 @@ | ||
| 2198 | 2218 | $is_friends = array_shift( $pagename_parts ); |
| 2199 | 2219 | |
| 2200 | 2220 | if ( 'friends' !== $is_friends ) { |
| 2201 | 2221 | return $query; |
| 2222 | + } | |
| 2223 | + | |
| 2224 | + if ( isset( $pagename_parts[0] ) && 'settings' === $pagename_parts[0] ) { | |
| 2225 | + wp_safe_redirect( self_admin_url( 'admin.php?page=friends-settings' ) ); | |
| 2226 | + exit; | |
| 2202 | 2227 | } |
| 2203 | 2228 | |
| 2204 | 2229 | // Not available for the general public or friends. |
| 2205 | 2230 | $viewable = $this->has_required_priviledges() && Friends::on_frontend(); |