PluginProbe
ActivityPub / 5.7.0
ActivityPub v5.7.0
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-shortcodes.php +88 -65 9.2.05.7.0 View file →
@@ -14,11 +14,11 @@
14 14 /**
15 15 * Register the shortcodes.
16 16 */
17 17 public static function register() {
18 - foreach ( \get_class_methods( self::class ) as $shortcode ) {
18 + foreach ( get_class_methods( self::class ) as $shortcode ) {
19 19 if ( 'init' !== $shortcode ) {
20 - \add_shortcode( 'ap_' . $shortcode, array( self::class, $shortcode ) );
20 + add_shortcode( 'ap_' . $shortcode, array( self::class, $shortcode ) );
21 21 }
22 22 }
23 23 }
24 24
@@ -25,11 +25,11 @@
25 25 /**
26 26 * Unregister the shortcodes.
27 27 */
28 28 public static function unregister() {
29 - foreach ( \get_class_methods( self::class ) as $shortcode ) {
29 + foreach ( get_class_methods( self::class ) as $shortcode ) {
30 30 if ( 'init' !== $shortcode ) {
31 - \remove_shortcode( 'ap_' . $shortcode );
31 + remove_shortcode( 'ap_' . $shortcode );
32 32 }
33 33 }
34 34 }
35 35
@@ -71,15 +71,15 @@
71 71
72 72 /**
73 73 * Generates output for the 'ap_title' Shortcode
74 74 *
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.
75 + * @param array $atts The Shortcode attributes.
76 + * @param string $content The ActivityPub post-content.
77 + * @param string $tag The tag/name of the Shortcode.
78 78 *
79 79 * @return string The post title.
80 80 */
81 - public static function title( $attributes, $content, $tag ) {
81 + public static function title( $atts, $content, $tag ) {
82 82 $item = self::get_item();
83 83
84 84 if ( ! $item ) {
85 85 return '';
@@ -90,31 +90,31 @@
90 90 if ( ! $title ) {
91 91 return '';
92 92 }
93 93
94 - $attributes = \shortcode_atts(
94 + $atts = shortcode_atts(
95 95 array( 'type' => 'plain' ),
96 - $attributes,
96 + $atts,
97 97 $tag
98 98 );
99 99
100 - if ( 'html' !== $attributes['type'] ) {
100 + if ( 'html' !== $atts['type'] ) {
101 101 return $title;
102 102 }
103 103
104 - return \sprintf( '<h2>%s</h2>', $title );
104 + return sprintf( '<h2>%s</h2>', $title );
105 105 }
106 106
107 107 /**
108 108 * Generates output for the 'ap_excerpt' Shortcode
109 109 *
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.
110 + * @param array $atts The Shortcode attributes.
111 + * @param string $content The ActivityPub post-content.
112 + * @param string $tag The tag/name of the Shortcode.
113 113 *
114 114 * @return string The post excerpt.
115 115 */
116 - public static function excerpt( $attributes, $content, $tag ) {
116 + public static function excerpt( $atts, $content, $tag ) {
117 117 $item = self::get_item();
118 118
119 119 if ( ! $item ) {
120 120 return '';
@@ -119,15 +119,15 @@
119 119 if ( ! $item ) {
120 120 return '';
121 121 }
122 122
123 - $attributes = \shortcode_atts(
123 + $atts = shortcode_atts(
124 124 array( 'length' => ACTIVITYPUB_EXCERPT_LENGTH ),
125 - $attributes,
125 + $atts,
126 126 $tag
127 127 );
128 128
129 - $excerpt_length = \intval( $attributes['length'] );
129 + $excerpt_length = intval( $atts['length'] );
130 130
131 131 if ( 0 === $excerpt_length ) {
132 132 $excerpt_length = ACTIVITYPUB_EXCERPT_LENGTH;
133 133 }
@@ -140,15 +140,15 @@
140 140
141 141 /**
142 142 * Generates output for the 'ap_content' Shortcode.
143 143 *
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.
144 + * @param array $atts The Shortcode attributes.
145 + * @param string $content The ActivityPub post-content.
146 + * @param string $tag The tag/name of the Shortcode.
147 147 *
148 148 * @return string The post content.
149 149 */
150 - public static function content( $attributes, $content, $tag ) {
150 + public static function content( $atts, $content, $tag ) {
151 151 $item = self::get_item();
152 152
153 153 if ( ! $item ) {
154 154 return '';
@@ -154,13 +154,13 @@
154 154 return '';
155 155 }
156 156
157 157 // Prevent inception.
158 - \remove_shortcode( 'ap_content' );
158 + remove_shortcode( 'ap_content' );
159 159
160 - $attributes = \shortcode_atts(
160 + $atts = shortcode_atts(
161 161 array( 'apply_filters' => 'yes' ),
162 - $attributes,
162 + $atts,
163 163 $tag
164 164 );
165 165
166 166 $content = '';
@@ -166,11 +166,11 @@
166 166 $content = '';
167 167
168 168 if ( 'attachment' === $item->post_type ) {
169 169 // Get title of attachment with fallback to alt text.
170 - $content = \wp_get_attachment_caption( $item->ID );
170 + $content = wp_get_attachment_caption( $item->ID );
171 171 if ( empty( $content ) ) {
172 - $content = \get_post_meta( $item->ID, '_wp_attachment_image_alt', true );
172 + $content = get_post_meta( $item->ID, '_wp_attachment_image_alt', true );
173 173 }
174 174 }
175 175
176 176 if ( empty( $content ) ) {
@@ -176,9 +176,9 @@
176 176 if ( empty( $content ) ) {
177 177 $content = \get_post_field( 'post_content', $item );
178 178 }
179 179
180 - if ( 'yes' === $attributes['apply_filters'] ) {
180 + if ( 'yes' === $atts['apply_filters'] ) {
181 181 /** This filter is documented in wp-includes/post-template.php */
182 182 $content = \apply_filters( 'the_content', $content );
183 183 } else {
184 184 if ( site_supports_blocks() ) {
@@ -187,13 +187,14 @@
187 187 $content = \wptexturize( $content );
188 188 $content = \wp_filter_content_tags( $content );
189 189 }
190 190
191 + // Replace script and style elements.
192 + $content = \preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $content );
191 193 $content = \strip_shortcodes( $content );
192 - $content = Sanitize::clean_html( $content );
193 - $content = Sanitize::strip_whitespace( $content );
194 + $content = \trim( \preg_replace( '/[\n\r\t]/', '', $content ) );
194 195
195 - \add_shortcode( 'ap_content', array( 'Activitypub\Shortcodes', 'content' ) );
196 + add_shortcode( 'ap_content', array( 'Activitypub\Shortcodes', 'content' ) );
196 197
197 198 return $content;
198 199 }
199 200
@@ -199,15 +200,15 @@
199 200
200 201 /**
201 202 * Generates output for the 'ap_permalink' Shortcode.
202 203 *
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.
204 + * @param array $atts The Shortcode attributes.
205 + * @param string $content The ActivityPub post-content.
206 + * @param string $tag The tag/name of the Shortcode.
206 207 *
207 208 * @return string The post permalink.
208 209 */
209 - public static function permalink( $attributes, $content, $tag ) {
210 + public static function permalink( $atts, $content, $tag ) {
210 211 $item = self::get_item();
211 212
212 213 if ( ! $item ) {
213 214 return '';
@@ -212,17 +213,17 @@
212 213 if ( ! $item ) {
213 214 return '';
214 215 }
215 216
216 - $attributes = \shortcode_atts(
217 + $atts = shortcode_atts(
217 218 array(
218 219 'type' => 'url',
219 220 ),
220 - $attributes,
221 + $atts,
221 222 $tag
222 223 );
223 224
224 - if ( 'html' !== $attributes['type'] ) {
225 + if ( 'html' !== $atts['type'] ) {
225 226 return \esc_url( \get_permalink( $item->ID ) );
226 227 }
227 228
228 229 return \sprintf(
@@ -233,15 +234,15 @@
233 234
234 235 /**
235 236 * Generates output for the 'ap_shortlink' Shortcode.
236 237 *
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.
238 + * @param array $atts The Shortcode attributes.
239 + * @param string $content The ActivityPub post-content.
240 + * @param string $tag The tag/name of the Shortcode.
240 241 *
241 242 * @return string The post shortlink.
242 243 */
243 - public static function shortlink( $attributes, $content, $tag ) {
244 + public static function shortlink( $atts, $content, $tag ) {
244 245 $item = self::get_item();
245 246
246 247 if ( ! $item ) {
247 248 return '';
@@ -246,17 +247,17 @@
246 247 if ( ! $item ) {
247 248 return '';
248 249 }
249 250
250 - $attributes = \shortcode_atts(
251 + $atts = shortcode_atts(
251 252 array(
252 253 'type' => 'url',
253 254 ),
254 - $attributes,
255 + $atts,
255 256 $tag
256 257 );
257 258
258 - if ( 'html' !== $attributes['type'] ) {
259 + if ( 'html' !== $atts['type'] ) {
259 260 return \esc_url( \wp_get_shortlink( $item->ID ) );
260 261 }
261 262
262 263 return \sprintf(
@@ -267,15 +268,15 @@
267 268
268 269 /**
269 270 * Generates output for the 'ap_image' Shortcode.
270 271 *
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.
272 + * @param array $atts The Shortcode attributes.
273 + * @param string $content The ActivityPub post-content.
274 + * @param string $tag The tag/name of the Shortcode.
274 275 *
275 276 * @return string
276 277 */
277 - public static function image( $attributes, $content, $tag ) {
278 + public static function image( $atts, $content, $tag ) {
278 279 $item = self::get_item();
279 280
280 281 if ( ! $item ) {
281 282 return '';
@@ -280,24 +281,24 @@
280 281 if ( ! $item ) {
281 282 return '';
282 283 }
283 284
284 - $attributes = \shortcode_atts(
285 + $atts = shortcode_atts(
285 286 array(
286 287 'type' => 'full',
287 288 ),
288 - $attributes,
289 + $atts,
289 290 $tag
290 291 );
291 292
292 293 $size = 'full';
293 294
294 - if ( \in_array(
295 - $attributes['type'],
295 + if ( in_array(
296 + $atts['type'],
296 297 array( 'thumbnail', 'medium', 'large', 'full' ),
297 298 true
298 299 ) ) {
299 - $size = $attributes['type'];
300 + $size = $atts['type'];
300 301 }
301 302
302 303 $image = \get_the_post_thumbnail_url( $item->ID, $size );
303 304
@@ -310,14 +311,34 @@
310 311
311 312 /**
312 313 * Generates output for the 'ap_hashcats' Shortcode.
313 314 *
314 - * @deprecated 7.0.0
315 - *
316 315 * @return string The post categories as hashtags.
317 316 */
318 317 public static function hashcats() {
319 - return '';
318 + $item = self::get_item();
319 +
320 + if ( ! $item ) {
321 + return '';
322 + }
323 +
324 + $categories = \get_the_category( $item->ID );
325 +
326 + if ( ! $categories ) {
327 + return '';
328 + }
329 +
330 + $hash_tags = array();
331 +
332 + foreach ( $categories as $category ) {
333 + $hash_tags[] = \sprintf(
334 + '<a rel="tag" class="hashtag u-tag u-category" href="%s">%s</a>',
335 + \esc_url( \get_category_link( $category ) ),
336 + esc_hashtag( $category->name )
337 + );
338 + }
339 +
340 + return \implode( ' ', $hash_tags );
320 341 }
321 342
322 343 /**
323 344 * Generates output for the 'ap_author' Shortcode.
@@ -337,9 +358,9 @@
337 358 if ( ! $name ) {
338 359 return '';
339 360 }
340 361
341 - return \wp_strip_all_tags( $name );
362 + return wp_strip_all_tags( $name );
342 363 }
343 364
344 365 /**
345 366 * Generates output for the 'ap_authorurl' Shortcode.
@@ -425,11 +446,13 @@
425 446 if ( ! $item ) {
426 447 return '';
427 448 }
428 449
429 - $datetime = \get_post_datetime( $item );
430 - $date = $datetime->format( \get_option( 'time_format' ) );
450 + $datetime = \get_post_datetime( $item );
451 + $timeformat = \get_option( 'time_format' );
431 452
453 + $date = $datetime->format( $timeformat );
454 +
432 455 if ( ! $date ) {
433 456 return '';
434 457 }
435 458
@@ -447,13 +470,13 @@
447 470 if ( ! $item ) {
448 471 return '';
449 472 }
450 473
451 - $datetime = \get_post_datetime( $item );
452 - $date_format = \get_option( 'date_format' );
453 - $time_format = \get_option( 'time_format' );
474 + $datetime = \get_post_datetime( $item );
475 + $dateformat = \get_option( 'date_format' );
476 + $timeformat = \get_option( 'time_format' );
454 477
455 - $date = $datetime->format( $date_format . ' @ ' . $time_format );
478 + $date = $datetime->format( $dateformat . ' @ ' . $timeformat );
456 479
457 480 if ( ! $date ) {
458 481 return '';
459 482 }