PluginProbe
ActivityPub / 7.8.2
ActivityPub v7.8.2
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
activitypub / templates / post-preview.php

post-preview.php in ActivityPub 7.8.2, at templates/post-preview.php

163 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ActivityPub Post Preview template.
4 *
5 * @package Activitypub
6 */
7
8 $post = \get_post(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
9 $transformer = \Activitypub\Transformer\Factory::get_transformer( $post );
10
11 if ( \is_wp_error( $transformer ) ) {
12 \wp_die(
13 esc_html( $transformer->get_error_message() ),
14 404
15 );
16 }
17
18 \wp_register_style( 'activitypub-post-preview', ACTIVITYPUB_PLUGIN_URL . '/assets/css/activitypub-post-preview.css', array(), ACTIVITYPUB_PLUGIN_VERSION );
19
20 $object = $transformer->to_object();
21 $user = $transformer->get_actor_object();
22
23 $has_images = false;
24 $video = false;
25 $audio = false;
26 $layout = 'layout-1';
27
28 foreach ( $object->get_attachment() as $attachment ) {
29 if ( isset( $attachment['mediaType'] ) ) {
30 $media_type = strtok( $attachment['mediaType'], '/' );
31
32 switch ( $media_type ) {
33 case 'image':
34 $has_images = true;
35 $layout = 'layout-' . count( wp_list_filter( $object->get_attachment(), array( 'type' => 'Image' ) ) );
36 break 2;
37 case 'video':
38 $video = $attachment;
39 break 2;
40 case 'audio':
41 $audio = $attachment;
42 break 2;
43 }
44 }
45 }
46
47 ?>
48 <DOCTYPE html>
49 <html>
50 <head>
51 <meta charset="utf-8">
52 <title><?php echo esc_html( $object->get_name() ); ?></title>
53 <?php wp_print_styles( 'activitypub-post-preview' ); ?>
54 </head>
55 <body>
56 <div class="columns">
57 <aside class="sidebar">
58 <input type="search" disabled="disabled" placeholder="<?php esc_html_e( 'Search', 'activitypub' ); ?>" />
59 <div>
60 <div class="fake-image"></div>
61 <div>
62 <div class="name">
63 ████ ██████
64 </div>
65 <div class="webfinger">
66 @█████@██████
67 </div>
68 </div>
69 </div>
70 <textarea rows="10" cols="50" disabled="disabled" placeholder="<?php esc_html_e( 'What\'s up', 'activitypub' ); ?>"></textarea>
71 </aside>
72 <main>
73 <h1 class="column-header">
74 Home
75 </h1>
76 <article>
77 <address>
78 <img src="<?php echo esc_url( $user->get_icon()['url'] ); ?>" alt="<?php echo esc_attr( $user->get_name() ); ?>" />
79 <div>
80 <div class="name">
81 <?php echo esc_html( $user->get_name() ); ?>
82 </div>
83 <div class="webfinger">
84 <?php echo esc_html( '@' . $user->get_webfinger() ); ?>
85 </div>
86 </div>
87 </address>
88 <div class="content">
89 <?php if ( 'Article' === $object->get_type() && $object->get_name() ) : ?>
90 <h2><?php echo esc_html( $object->get_name() ); ?></h2>
91 <?php endif; ?>
92 <?php
93 $content_to_display = 'Article' === $object->get_type() ? $object->get_summary() : $object->get_content();
94
95 // Avoid captions making it through wp_kses.
96 $content_to_display = preg_replace( '/<figure.*?>.*?<\/figure>/s', '', $content_to_display );
97
98 echo wp_kses( $content_to_display, ACTIVITYPUB_MASTODON_HTML_SANITIZER );
99 ?>
100 </div>
101 <?php if ( $object->get_attachment() ) : ?>
102 <div class="attachments <?php echo \esc_attr( $layout ); ?>">
103 <?php
104 if ( $has_images ) :
105 foreach ( $object->get_attachment() as $attachment ) :
106 if ( 'Image' === $attachment['type'] ) :
107 ?>
108 <img src="<?php echo esc_url( $attachment['url'] ); ?>" alt="<?php echo esc_attr( $attachment['name'] ?? '' ); ?>" />
109 <?php
110 endif;
111 endforeach;
112 elseif ( $video ) :
113 ?>
114 <video controls src="<?php echo esc_url( $video['url'] ); ?>" title="<?php echo esc_attr( $video['name'] ?? '' ); ?>"></video>
115 <?php
116 elseif ( $audio ) :
117 ?>
118 <audio controls src="<?php echo esc_url( $audio['url'] ); ?>" title="<?php echo esc_attr( $audio['name'] ?? '' ); ?>"></audio>
119 <?php
120 endif;
121 ?>
122 </div>
123 <?php endif; ?>
124 <?php if ( $object->get_tag() ) : ?>
125 <div class="tags">
126 <?php foreach ( $object->get_tag() as $hashtag ) : ?>
127 <?php if ( 'Hashtag' === $hashtag['type'] ) : ?>
128 <a href="<?php echo esc_url( $hashtag['href'] ); ?>"><?php echo esc_html( $hashtag['name'] ); ?></a>
129 <?php endif; ?>
130 <?php endforeach; ?>
131 </div>
132 <?php endif; ?>
133 </article>
134 </main>
135 <aside class="sidebar">
136 <h1> Fediverse</h1>
137 <ul>
138 <li>████████</li>
139 <li>███████████</li>
140 <li>██████████</li>
141 <li>█████████</li>
142 <li>███████</li>
143 <li>████████</li>
144 <li>████████████</li>
145 <li>████████████</li>
146 <li>██████████</li>
147 <li>████████████</li>
148 </ul>
149 <hr />
150 <ul>
151 <li>███████████</li>
152 <li>██████████████</li>
153 <li>█████████</li>
154 </ul>
155 <hr />
156 <ul>
157 <li>██████████</li>
158 </ul>
159 </aside>
160 </div>
161 </body>
162 </html>
163