| @@ -53,13 +53,8 @@ | ||
| 53 | 53 | |
| 54 | 54 | $hash_tags = array(); |
| 55 | 55 | |
| 56 | 56 | foreach ( $tags as $tag ) { |
| 57 | - // Tag can be empty. | |
| 58 | - if ( ! $tag ) { | |
| 59 | - continue; | |
| 60 | - } | |
| 61 | - | |
| 62 | 57 | $hash_tags[] = \sprintf( |
| 63 | 58 | '<a rel="tag" class="hashtag u-tag u-category" href="%s">%s</a>', |
| 64 | 59 | \esc_url( \get_tag_link( $tag ) ), |
| 65 | 60 | esc_hashtag( $tag->name ) |
| @@ -71,15 +66,15 @@ | ||
| 71 | 66 | |
| 72 | 67 | /** |
| 73 | 68 | * Generates output for the 'ap_title' Shortcode |
| 74 | 69 | * |
| 75 | - * @param array $attributes The Shortcode attributes. | |
| 76 | - * @param string $content The ActivityPub post-content. | |
| 77 | - * @param string $tag The tag/name of the Shortcode. | |
| 70 | + * @param array $atts The Shortcode attributes. | |
| 71 | + * @param string $content The ActivityPub post-content. | |
| 72 | + * @param string $tag The tag/name of the Shortcode. | |
| 78 | 73 | * |
| 79 | 74 | * @return string The post title. |
| 80 | 75 | */ |
| 81 | - public static function title( $attributes, $content, $tag ) { | |
| 76 | + public static function title( $atts, $content, $tag ) { | |
| 82 | 77 | $item = self::get_item(); |
| 83 | 78 | |
| 84 | 79 | if ( ! $item ) { |
| 85 | 80 | return ''; |
| @@ -90,15 +85,15 @@ | ||
| 90 | 85 | if ( ! $title ) { |
| 91 | 86 | return ''; |
| 92 | 87 | } |
| 93 | 88 | |
| 94 | - $attributes = shortcode_atts( | |
| 89 | + $atts = shortcode_atts( | |
| 95 | 90 | array( 'type' => 'plain' ), |
| 96 | - $attributes, | |
| 91 | + $atts, | |
| 97 | 92 | $tag |
| 98 | 93 | ); |
| 99 | 94 | |
| 100 | - if ( 'html' !== $attributes['type'] ) { | |
| 95 | + if ( 'html' !== $atts['type'] ) { | |
| 101 | 96 | return $title; |
| 102 | 97 | } |
| 103 | 98 | |
| 104 | 99 | return sprintf( '<h2>%s</h2>', $title ); |
| @@ -106,15 +101,15 @@ | ||
| 106 | 101 | |
| 107 | 102 | /** |
| 108 | 103 | * Generates output for the 'ap_excerpt' Shortcode |
| 109 | 104 | * |
| 110 | - * @param array $attributes The Shortcode attributes. | |
| 111 | - * @param string $content The ActivityPub post-content. | |
| 112 | - * @param string $tag The tag/name of the Shortcode. | |
| 105 | + * @param array $atts The Shortcode attributes. | |
| 106 | + * @param string $content The ActivityPub post-content. | |
| 107 | + * @param string $tag The tag/name of the Shortcode. | |
| 113 | 108 | * |
| 114 | 109 | * @return string The post excerpt. |
| 115 | 110 | */ |
| 116 | - public static function excerpt( $attributes, $content, $tag ) { | |
| 111 | + public static function excerpt( $atts, $content, $tag ) { | |
| 117 | 112 | $item = self::get_item(); |
| 118 | 113 | |
| 119 | 114 | if ( ! $item ) { |
| 120 | 115 | return ''; |
| @@ -119,15 +114,15 @@ | ||
| 119 | 114 | if ( ! $item ) { |
| 120 | 115 | return ''; |
| 121 | 116 | } |
| 122 | 117 | |
| 123 | - $attributes = shortcode_atts( | |
| 118 | + $atts = shortcode_atts( | |
| 124 | 119 | array( 'length' => ACTIVITYPUB_EXCERPT_LENGTH ), |
| 125 | - $attributes, | |
| 120 | + $atts, | |
| 126 | 121 | $tag |
| 127 | 122 | ); |
| 128 | 123 | |
| 129 | - $excerpt_length = intval( $attributes['length'] ); | |
| 124 | + $excerpt_length = intval( $atts['length'] ); | |
| 130 | 125 | |
| 131 | 126 | if ( 0 === $excerpt_length ) { |
| 132 | 127 | $excerpt_length = ACTIVITYPUB_EXCERPT_LENGTH; |
| 133 | 128 | } |
| @@ -140,15 +135,15 @@ | ||
| 140 | 135 | |
| 141 | 136 | /** |
| 142 | 137 | * Generates output for the 'ap_content' Shortcode. |
| 143 | 138 | * |
| 144 | - * @param array $attributes The Shortcode attributes. | |
| 145 | - * @param string $content The ActivityPub post-content. | |
| 146 | - * @param string $tag The tag/name of the Shortcode. | |
| 139 | + * @param array $atts The Shortcode attributes. | |
| 140 | + * @param string $content The ActivityPub post-content. | |
| 141 | + * @param string $tag The tag/name of the Shortcode. | |
| 147 | 142 | * |
| 148 | 143 | * @return string The post content. |
| 149 | 144 | */ |
| 150 | - public static function content( $attributes, $content, $tag ) { | |
| 145 | + public static function content( $atts, $content, $tag ) { | |
| 151 | 146 | $item = self::get_item(); |
| 152 | 147 | |
| 153 | 148 | if ( ! $item ) { |
| 154 | 149 | return ''; |
| @@ -156,11 +151,11 @@ | ||
| 156 | 151 | |
| 157 | 152 | // Prevent inception. |
| 158 | 153 | remove_shortcode( 'ap_content' ); |
| 159 | 154 | |
| 160 | - $attributes = shortcode_atts( | |
| 155 | + $atts = shortcode_atts( | |
| 161 | 156 | array( 'apply_filters' => 'yes' ), |
| 162 | - $attributes, | |
| 157 | + $atts, | |
| 163 | 158 | $tag |
| 164 | 159 | ); |
| 165 | 160 | |
| 166 | 161 | $content = ''; |
| @@ -176,9 +171,9 @@ | ||
| 176 | 171 | if ( empty( $content ) ) { |
| 177 | 172 | $content = \get_post_field( 'post_content', $item ); |
| 178 | 173 | } |
| 179 | 174 | |
| 180 | - if ( 'yes' === $attributes['apply_filters'] ) { | |
| 175 | + if ( 'yes' === $atts['apply_filters'] ) { | |
| 181 | 176 | /** This filter is documented in wp-includes/post-template.php */ |
| 182 | 177 | $content = \apply_filters( 'the_content', $content ); |
| 183 | 178 | } else { |
| 184 | 179 | if ( site_supports_blocks() ) { |
| @@ -187,11 +182,12 @@ | ||
| 187 | 182 | $content = \wptexturize( $content ); |
| 188 | 183 | $content = \wp_filter_content_tags( $content ); |
| 189 | 184 | } |
| 190 | 185 | |
| 186 | + // Replace script and style elements. | |
| 187 | + $content = \preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $content ); | |
| 191 | 188 | $content = \strip_shortcodes( $content ); |
| 192 | - $content = Sanitize::clean_html( $content ); | |
| 193 | - $content = Sanitize::strip_whitespace( $content ); | |
| 189 | + $content = \trim( \preg_replace( '/[\n\r\t]/', '', $content ) ); | |
| 194 | 190 | |
| 195 | 191 | add_shortcode( 'ap_content', array( 'Activitypub\Shortcodes', 'content' ) ); |
| 196 | 192 | |
| 197 | 193 | return $content; |
| @@ -199,15 +195,15 @@ | ||
| 199 | 195 | |
| 200 | 196 | /** |
| 201 | 197 | * Generates output for the 'ap_permalink' Shortcode. |
| 202 | 198 | * |
| 203 | - * @param array $attributes The Shortcode attributes. | |
| 204 | - * @param string $content The ActivityPub post-content. | |
| 205 | - * @param string $tag The tag/name of the Shortcode. | |
| 199 | + * @param array $atts The Shortcode attributes. | |
| 200 | + * @param string $content The ActivityPub post-content. | |
| 201 | + * @param string $tag The tag/name of the Shortcode. | |
| 206 | 202 | * |
| 207 | 203 | * @return string The post permalink. |
| 208 | 204 | */ |
| 209 | - public static function permalink( $attributes, $content, $tag ) { | |
| 205 | + public static function permalink( $atts, $content, $tag ) { | |
| 210 | 206 | $item = self::get_item(); |
| 211 | 207 | |
| 212 | 208 | if ( ! $item ) { |
| 213 | 209 | return ''; |
| @@ -212,17 +208,17 @@ | ||
| 212 | 208 | if ( ! $item ) { |
| 213 | 209 | return ''; |
| 214 | 210 | } |
| 215 | 211 | |
| 216 | - $attributes = shortcode_atts( | |
| 212 | + $atts = shortcode_atts( | |
| 217 | 213 | array( |
| 218 | 214 | 'type' => 'url', |
| 219 | 215 | ), |
| 220 | - $attributes, | |
| 216 | + $atts, | |
| 221 | 217 | $tag |
| 222 | 218 | ); |
| 223 | 219 | |
| 224 | - if ( 'html' !== $attributes['type'] ) { | |
| 220 | + if ( 'html' !== $atts['type'] ) { | |
| 225 | 221 | return \esc_url( \get_permalink( $item->ID ) ); |
| 226 | 222 | } |
| 227 | 223 | |
| 228 | 224 | return \sprintf( |
| @@ -233,15 +229,15 @@ | ||
| 233 | 229 | |
| 234 | 230 | /** |
| 235 | 231 | * Generates output for the 'ap_shortlink' Shortcode. |
| 236 | 232 | * |
| 237 | - * @param array $attributes The Shortcode attributes. | |
| 238 | - * @param string $content The ActivityPub post-content. | |
| 239 | - * @param string $tag The tag/name of the Shortcode. | |
| 233 | + * @param array $atts The Shortcode attributes. | |
| 234 | + * @param string $content The ActivityPub post-content. | |
| 235 | + * @param string $tag The tag/name of the Shortcode. | |
| 240 | 236 | * |
| 241 | 237 | * @return string The post shortlink. |
| 242 | 238 | */ |
| 243 | - public static function shortlink( $attributes, $content, $tag ) { | |
| 239 | + public static function shortlink( $atts, $content, $tag ) { | |
| 244 | 240 | $item = self::get_item(); |
| 245 | 241 | |
| 246 | 242 | if ( ! $item ) { |
| 247 | 243 | return ''; |
| @@ -246,17 +242,17 @@ | ||
| 246 | 242 | if ( ! $item ) { |
| 247 | 243 | return ''; |
| 248 | 244 | } |
| 249 | 245 | |
| 250 | - $attributes = shortcode_atts( | |
| 246 | + $atts = shortcode_atts( | |
| 251 | 247 | array( |
| 252 | 248 | 'type' => 'url', |
| 253 | 249 | ), |
| 254 | - $attributes, | |
| 250 | + $atts, | |
| 255 | 251 | $tag |
| 256 | 252 | ); |
| 257 | 253 | |
| 258 | - if ( 'html' !== $attributes['type'] ) { | |
| 254 | + if ( 'html' !== $atts['type'] ) { | |
| 259 | 255 | return \esc_url( \wp_get_shortlink( $item->ID ) ); |
| 260 | 256 | } |
| 261 | 257 | |
| 262 | 258 | return \sprintf( |
| @@ -267,15 +263,15 @@ | ||
| 267 | 263 | |
| 268 | 264 | /** |
| 269 | 265 | * Generates output for the 'ap_image' Shortcode. |
| 270 | 266 | * |
| 271 | - * @param array $attributes The Shortcode attributes. | |
| 272 | - * @param string $content The ActivityPub post-content. | |
| 273 | - * @param string $tag The tag/name of the Shortcode. | |
| 267 | + * @param array $atts The Shortcode attributes. | |
| 268 | + * @param string $content The ActivityPub post-content. | |
| 269 | + * @param string $tag The tag/name of the Shortcode. | |
| 274 | 270 | * |
| 275 | 271 | * @return string |
| 276 | 272 | */ |
| 277 | - public static function image( $attributes, $content, $tag ) { | |
| 273 | + public static function image( $atts, $content, $tag ) { | |
| 278 | 274 | $item = self::get_item(); |
| 279 | 275 | |
| 280 | 276 | if ( ! $item ) { |
| 281 | 277 | return ''; |
| @@ -280,13 +276,13 @@ | ||
| 280 | 276 | if ( ! $item ) { |
| 281 | 277 | return ''; |
| 282 | 278 | } |
| 283 | 279 | |
| 284 | - $attributes = shortcode_atts( | |
| 280 | + $atts = shortcode_atts( | |
| 285 | 281 | array( |
| 286 | 282 | 'type' => 'full', |
| 287 | 283 | ), |
| 288 | - $attributes, | |
| 284 | + $atts, | |
| 289 | 285 | $tag |
| 290 | 286 | ); |
| 291 | 287 | |
| 292 | 288 | $size = 'full'; |
| @@ -291,13 +287,13 @@ | ||
| 291 | 287 | |
| 292 | 288 | $size = 'full'; |
| 293 | 289 | |
| 294 | 290 | if ( in_array( |
| 295 | - $attributes['type'], | |
| 291 | + $atts['type'], | |
| 296 | 292 | array( 'thumbnail', 'medium', 'large', 'full' ), |
| 297 | 293 | true |
| 298 | 294 | ) ) { |
| 299 | - $size = $attributes['type']; | |
| 295 | + $size = $atts['type']; | |
| 300 | 296 | } |
| 301 | 297 | |
| 302 | 298 | $image = \get_the_post_thumbnail_url( $item->ID, $size ); |
| 303 | 299 | |
| @@ -310,14 +306,34 @@ | ||
| 310 | 306 | |
| 311 | 307 | /** |
| 312 | 308 | * Generates output for the 'ap_hashcats' Shortcode. |
| 313 | 309 | * |
| 314 | - * @deprecated 7.0.0 | |
| 315 | - * | |
| 316 | 310 | * @return string The post categories as hashtags. |
| 317 | 311 | */ |
| 318 | 312 | public static function hashcats() { |
| 319 | - return ''; | |
| 313 | + $item = self::get_item(); | |
| 314 | + | |
| 315 | + if ( ! $item ) { | |
| 316 | + return ''; | |
| 317 | + } | |
| 318 | + | |
| 319 | + $categories = \get_the_category( $item->ID ); | |
| 320 | + | |
| 321 | + if ( ! $categories ) { | |
| 322 | + return ''; | |
| 323 | + } | |
| 324 | + | |
| 325 | + $hash_tags = array(); | |
| 326 | + | |
| 327 | + foreach ( $categories as $category ) { | |
| 328 | + $hash_tags[] = \sprintf( | |
| 329 | + '<a rel="tag" class="hashtag u-tag u-category" href="%s">%s</a>', | |
| 330 | + \esc_url( \get_category_link( $category ) ), | |
| 331 | + esc_hashtag( $category->name ) | |
| 332 | + ); | |
| 333 | + } | |
| 334 | + | |
| 335 | + return \implode( ' ', $hash_tags ); | |
| 320 | 336 | } |
| 321 | 337 | |
| 322 | 338 | /** |
| 323 | 339 | * Generates output for the 'ap_author' Shortcode. |
| @@ -425,11 +441,13 @@ | ||
| 425 | 441 | if ( ! $item ) { |
| 426 | 442 | return ''; |
| 427 | 443 | } |
| 428 | 444 | |
| 429 | - $datetime = \get_post_datetime( $item ); | |
| 430 | - $date = $datetime->format( \get_option( 'time_format' ) ); | |
| 445 | + $datetime = \get_post_datetime( $item ); | |
| 446 | + $timeformat = \get_option( 'time_format' ); | |
| 431 | 447 | |
| 448 | + $date = $datetime->format( $timeformat ); | |
| 449 | + | |
| 432 | 450 | if ( ! $date ) { |
| 433 | 451 | return ''; |
| 434 | 452 | } |
| 435 | 453 | |
| @@ -447,13 +465,13 @@ | ||
| 447 | 465 | if ( ! $item ) { |
| 448 | 466 | return ''; |
| 449 | 467 | } |
| 450 | 468 | |
| 451 | - $datetime = \get_post_datetime( $item ); | |
| 452 | - $date_format = \get_option( 'date_format' ); | |
| 453 | - $time_format = \get_option( 'time_format' ); | |
| 469 | + $datetime = \get_post_datetime( $item ); | |
| 470 | + $dateformat = \get_option( 'date_format' ); | |
| 471 | + $timeformat = \get_option( 'time_format' ); | |
| 454 | 472 | |
| 455 | - $date = $datetime->format( $date_format . ' @ ' . $time_format ); | |
| 473 | + $date = $datetime->format( $dateformat . ' @ ' . $timeformat ); | |
| 456 | 474 | |
| 457 | 475 | if ( ! $date ) { |
| 458 | 476 | return ''; |
| 459 | 477 | } |