| @@ -37,9 +37,9 @@ | ||
| 37 | 37 | * |
| 38 | 38 | * @return string The converted string. |
| 39 | 39 | */ |
| 40 | 40 | function camel_to_snake_case( $input ) { |
| 41 | - return strtolower( preg_replace( '/(?<!^)[A-Z]/', '_$0', $input ) ); | |
| 41 | + return \strtolower( \preg_replace( '/(?<!^)[A-Z]/', '_$0', $input ) ); | |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
| 45 | 45 | * Convert a string from snake_case to camelCase. |
| @@ -48,9 +48,9 @@ | ||
| 48 | 48 | * |
| 49 | 49 | * @return string The converted string. |
| 50 | 50 | */ |
| 51 | 51 | function snake_to_camel_case( $input ) { |
| 52 | - return lcfirst( str_replace( '_', '', ucwords( $input, '_' ) ) ); | |
| 52 | + return \lcfirst( \str_replace( '_', '', \ucwords( $input, '_' ) ) ); | |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | 56 | * Convert seconds to ISO 8601 duration format. |
| @@ -65,10 +65,10 @@ | ||
| 65 | 65 | if ( $seconds <= 0 ) { |
| 66 | 66 | return 'PT0S'; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - $hours = floor( $seconds / 3600 ); | |
| 70 | - $minutes = floor( ( $seconds % 3600 ) / 60 ); | |
| 69 | + $hours = \floor( $seconds / 3600 ); | |
| 70 | + $minutes = \floor( ( $seconds % 3600 ) / 60 ); | |
| 71 | 71 | $secs = $seconds % 60; |
| 72 | 72 | |
| 73 | 73 | $duration = 'PT'; |
| 74 | 74 | |
| @@ -98,24 +98,48 @@ | ||
| 98 | 98 | * thus disabling blocks registered by the ActivityPub plugin. |
| 99 | 99 | * |
| 100 | 100 | * @param boolean $supports_blocks True if the site supports the block editor, false otherwise. |
| 101 | 101 | */ |
| 102 | - return apply_filters( 'activitypub_site_supports_blocks', true ); | |
| 102 | + return \apply_filters( 'activitypub_site_supports_blocks', true ); | |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
| 106 | - * Check if data is valid JSON. | |
| 106 | + * Get the icon Image object for site-wide ActivityPub actors. | |
| 107 | 107 | * |
| 108 | - * @deprecated 7.1.0 Use {@see \json_decode}. | |
| 108 | + * Tries the site icon first, then the custom logo, and falls back to the | |
| 109 | + * bundled WordPress logo. | |
| 109 | 110 | * |
| 110 | - * @param string $data The data to check. | |
| 111 | + * @since 9.1.0 | |
| 111 | 112 | * |
| 112 | - * @return boolean True if the data is JSON, false otherwise. | |
| 113 | + * @return array The icon array with 'type' and 'url'. | |
| 113 | 114 | */ |
| 114 | -function is_json( $data ) { | |
| 115 | - \_deprecated_function( __FUNCTION__, '7.1.0', 'json_decode' ); | |
| 115 | +function site_icon() { | |
| 116 | + // Try site icon first. | |
| 117 | + $icon_id = \get_option( 'site_icon' ); | |
| 116 | 118 | |
| 117 | - return \is_array( \json_decode( $data, true ) ); | |
| 119 | + // Try custom logo second. | |
| 120 | + if ( ! $icon_id ) { | |
| 121 | + $icon_id = \get_theme_mod( 'custom_logo' ); | |
| 122 | + } | |
| 123 | + | |
| 124 | + $icon_url = false; | |
| 125 | + | |
| 126 | + if ( $icon_id ) { | |
| 127 | + $icon = \wp_get_attachment_image_src( $icon_id, 'full' ); | |
| 128 | + if ( $icon ) { | |
| 129 | + $icon_url = $icon[0]; | |
| 130 | + } | |
| 131 | + } | |
| 132 | + | |
| 133 | + if ( ! $icon_url ) { | |
| 134 | + // Fallback to default icon. | |
| 135 | + $icon_url = \plugins_url( '/assets/img/wp-logo.png', ACTIVITYPUB_PLUGIN_FILE ); | |
| 136 | + } | |
| 137 | + | |
| 138 | + return array( | |
| 139 | + 'type' => 'Image', | |
| 140 | + 'url' => \esc_url_raw( $icon_url ), | |
| 141 | + ); | |
| 118 | 142 | } |
| 119 | 143 | |
| 120 | 144 | /** |
| 121 | 145 | * Check whether a blog is public based on the `blog_public` option. |
| @@ -127,9 +151,9 @@ | ||
| 127 | 151 | * Filter whether the blog is public. |
| 128 | 152 | * |
| 129 | 153 | * @param bool $public Whether the blog is public. |
| 130 | 154 | */ |
| 131 | - return (bool) apply_filters( 'activitypub_is_blog_public', \get_option( 'blog_public', 1 ) ); | |
| 155 | + return (bool) \apply_filters( 'activitypub_is_blog_public', \get_option( 'blog_public', 1 ) ); | |
| 132 | 156 | } |
| 133 | 157 | |
| 134 | 158 | /** |
| 135 | 159 | * Get the masked WordPress version to only show the major and minor version. |
| @@ -137,15 +161,15 @@ | ||
| 137 | 161 | * @return string The masked version. |
| 138 | 162 | */ |
| 139 | 163 | function get_masked_wp_version() { |
| 140 | 164 | // Only show the major and minor version. |
| 141 | - $version = get_bloginfo( 'version' ); | |
| 165 | + $version = \get_bloginfo( 'version' ); | |
| 142 | 166 | // Strip the RC or beta part. |
| 143 | - $version = preg_replace( '/-.*$/', '', $version ); | |
| 144 | - $version = explode( '.', $version ); | |
| 145 | - $version = array_slice( $version, 0, 2 ); | |
| 167 | + $version = \preg_replace( '/-.*$/', '', $version ); | |
| 168 | + $version = \explode( '.', $version ); | |
| 169 | + $version = \array_slice( $version, 0, 2 ); | |
| 146 | 170 | |
| 147 | - return implode( '.', $version ); | |
| 171 | + return \implode( '.', $version ); | |
| 148 | 172 | } |
| 149 | 173 | |
| 150 | 174 | /** |
| 151 | 175 | * Check if a plugin is active, loading plugin.php if necessary. |
| @@ -177,9 +201,9 @@ | ||
| 177 | 201 | return null; |
| 178 | 202 | } |
| 179 | 203 | |
| 180 | 204 | $domains = \get_option( 'activitypub_attribution_domains', home_host() ); |
| 181 | - $domains = explode( PHP_EOL, $domains ); | |
| 205 | + $domains = \explode( PHP_EOL, $domains ); | |
| 182 | 206 | |
| 183 | 207 | if ( ! $domains ) { |
| 184 | 208 | $domains = null; |
| 185 | 209 | } |
| @@ -235,19 +259,19 @@ | ||
| 235 | 259 | // Remove all characters that are not letters, numbers, or hyphens. |
| 236 | 260 | $hashtag = \preg_replace( '/[^\p{L}\p{Nd}-]+/u', '-', $hashtag ); |
| 237 | 261 | |
| 238 | 262 | // Capitalize every letter that is preceded by a hyphen. |
| 239 | - $hashtag = preg_replace_callback( | |
| 263 | + $hashtag = \preg_replace_callback( | |
| 240 | 264 | '/-+(.)/', |
| 241 | 265 | static function ( $matches ) { |
| 242 | - return strtoupper( $matches[1] ); | |
| 266 | + return \strtoupper( $matches[1] ); | |
| 243 | 267 | }, |
| 244 | 268 | $hashtag |
| 245 | 269 | ); |
| 246 | 270 | |
| 247 | 271 | // Add a hashtag to the beginning of the string. |
| 248 | - $hashtag = ltrim( $hashtag, '#' ); | |
| 249 | - $hashtag = trim( $hashtag, '-' ); | |
| 272 | + $hashtag = \ltrim( $hashtag, '#' ); | |
| 273 | + $hashtag = \trim( $hashtag, '-' ); | |
| 250 | 274 | $hashtag = '#' . $hashtag; |
| 251 | 275 | |
| 252 | 276 | /** |
| 253 | 277 | * Allow defining your own custom hashtag generation rules. |
| @@ -254,11 +278,11 @@ | ||
| 254 | 278 | * |
| 255 | 279 | * @param string $hashtag The hashtag to be returned. |
| 256 | 280 | * @param string $input The original string. |
| 257 | 281 | */ |
| 258 | - $hashtag = apply_filters( 'activitypub_esc_hashtag', $hashtag, $input ); | |
| 282 | + $hashtag = \apply_filters( 'activitypub_esc_hashtag', $hashtag, $input ); | |
| 259 | 283 | |
| 260 | - return esc_html( $hashtag ); | |
| 284 | + return \esc_html( $hashtag ); | |
| 261 | 285 | } |
| 262 | 286 | |
| 263 | 287 | /** |
| 264 | 288 | * Replace content with links, mentions or hashtags by Regex callback and not affect protected tags. |
| @@ -270,9 +294,9 @@ | ||
| 270 | 294 | * @return string The content with links, mentions, hashtags, etc. |
| 271 | 295 | */ |
| 272 | 296 | function enrich_content_data( $content, $regex, $regex_callback ) { |
| 273 | 297 | // Small protection against execution timeouts: limit to 1 MB. |
| 274 | - if ( mb_strlen( $content ) > MB_IN_BYTES ) { | |
| 298 | + if ( \mb_strlen( $content ) > MB_IN_BYTES ) { | |
| 275 | 299 | return $content; |
| 276 | 300 | } |
| 277 | 301 | $tag_stack = array(); |
| 278 | 302 | $protected_tags = array( |
| @@ -283,22 +307,22 @@ | ||
| 283 | 307 | 'a', |
| 284 | 308 | ); |
| 285 | 309 | $content_with_links = ''; |
| 286 | 310 | $in_protected_tag = false; |
| 287 | - foreach ( wp_html_split( $content ) as $chunk ) { | |
| 288 | - if ( preg_match( '#^<!--[\s\S]*-->$#i', $chunk, $m ) ) { | |
| 311 | + foreach ( \wp_html_split( $content ) as $chunk ) { | |
| 312 | + if ( \preg_match( '#^<!--[\s\S]*-->$#i', $chunk, $m ) ) { | |
| 289 | 313 | $content_with_links .= $chunk; |
| 290 | 314 | continue; |
| 291 | 315 | } |
| 292 | 316 | |
| 293 | - if ( preg_match( '#^<(/)?([a-z-]+)\b[^>]*>$#i', $chunk, $m ) ) { | |
| 294 | - $tag = strtolower( $m[2] ); | |
| 317 | + if ( \preg_match( '#^<(/)?([a-z-]+)\b[^>]*>$#i', $chunk, $m ) ) { | |
| 318 | + $tag = \strtolower( $m[2] ); | |
| 295 | 319 | if ( '/' === $m[1] ) { |
| 296 | 320 | // Closing tag. |
| 297 | - $i = array_search( $tag, $tag_stack, true ); | |
| 321 | + $i = \array_search( $tag, $tag_stack, true ); | |
| 298 | 322 | // We can only remove the tag from the stack if it is in the stack. |
| 299 | 323 | if ( false !== $i ) { |
| 300 | - $tag_stack = array_slice( $tag_stack, 0, $i ); | |
| 324 | + $tag_stack = \array_slice( $tag_stack, 0, $i ); | |
| 301 | 325 | } |
| 302 | 326 | } else { |
| 303 | 327 | // Opening tag, add it to the stack. |
| 304 | 328 | $tag_stack[] = $tag; |
| @@ -305,9 +329,9 @@ | ||
| 305 | 329 | } |
| 306 | 330 | |
| 307 | 331 | // If we're in a protected tag, the tag_stack contains at least one protected tag string. |
| 308 | 332 | // The protected tag state can only change when we encounter a start or end tag. |
| 309 | - $in_protected_tag = array_intersect( $tag_stack, $protected_tags ); | |
| 333 | + $in_protected_tag = \array_intersect( $tag_stack, $protected_tags ); | |
| 310 | 334 | |
| 311 | 335 | // Never inspect tags. |
| 312 | 336 | $content_with_links .= $chunk; |
| 313 | 337 | continue; |