PluginProbe
ActivityPub / 9.0.1
ActivityPub v9.0.1
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 9.0.1, at templates/post-preview.php

175 lines 5.3 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 /*
9 * The Fediverse Preview is an authoring tool, not a public view. Refuse to render
10 * it for logged-out visitors as a backstop, independent of how the request routed
11 * here — so a soft-deleted draft's preview can never be served to the public.
12 */
13 if ( ! \is_user_logged_in() ) {
14 \wp_die(
15 \esc_html__( 'You need to be logged in to preview this post.', 'activitypub' ),
16 403
17 );
18 }
19
20 $post = \get_post(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
21 $transformer = \Activitypub\Transformer\Factory::get_transformer( $post );
22
23 if ( \is_wp_error( $transformer ) ) {
24 \wp_die(
25 esc_html( $transformer->get_error_message() ),
26 404
27 );
28 }
29
30 \wp_register_style( 'activitypub-post-preview', ACTIVITYPUB_PLUGIN_URL . '/assets/css/activitypub-post-preview.css', array(), ACTIVITYPUB_PLUGIN_VERSION );
31
32 $object = $transformer->to_object();
33 $user = $transformer->get_actor_object();
34
35 $has_images = false;
36 $video = false;
37 $audio = false;
38 $layout = 'layout-1';
39
40 foreach ( $object->get_attachment() as $attachment ) {
41 if ( isset( $attachment['mediaType'] ) ) {
42 $media_type = strtok( $attachment['mediaType'], '/' );
43
44 switch ( $media_type ) {
45 case 'image':
46 $has_images = true;
47 $layout = 'layout-' . count( wp_list_filter( $object->get_attachment(), array( 'type' => 'Image' ) ) );
48 break 2;
49 case 'video':
50 $video = $attachment;
51 break 2;
52 case 'audio':
53 $audio = $attachment;
54 break 2;
55 }
56 }
57 }
58
59 ?>
60 <DOCTYPE html>
61 <html>
62 <head>
63 <meta charset="utf-8">
64 <title><?php echo esc_html( $object->get_name() ); ?></title>
65 <?php wp_print_styles( 'activitypub-post-preview' ); ?>
66 </head>
67 <body>
68 <div class="columns">
69 <aside class="sidebar">
70 <input type="search" disabled="disabled" placeholder="<?php esc_html_e( 'Search', 'activitypub' ); ?>" />
71 <div>
72 <div class="fake-image"></div>
73 <div>
74 <div class="name">
75 ████ ██████
76 </div>
77 <div class="webfinger">
78 @█████@██████
79 </div>
80 </div>
81 </div>
82 <textarea rows="10" cols="50" disabled="disabled" placeholder="<?php esc_html_e( 'What\'s up', 'activitypub' ); ?>"></textarea>
83 </aside>
84 <main>
85 <h1 class="column-header">
86 Home
87 </h1>
88 <article>
89 <address>
90 <img src="<?php echo esc_url( $user->get_icon()['url'] ); ?>" alt="<?php echo esc_attr( $user->get_name() ); ?>" />
91 <div>
92 <div class="name">
93 <?php echo esc_html( $user->get_name() ); ?>
94 </div>
95 <div class="webfinger">
96 <?php echo esc_html( '@' . $user->get_webfinger() ); ?>
97 </div>
98 </div>
99 </address>
100 <div class="content">
101 <?php if ( 'Article' === $object->get_type() && $object->get_name() ) : ?>
102 <h2><?php echo esc_html( $object->get_name() ); ?></h2>
103 <?php endif; ?>
104 <?php
105 $content_to_display = 'Article' === $object->get_type() ? $object->get_summary() : $object->get_content();
106
107 // Avoid captions making it through wp_kses.
108 $content_to_display = preg_replace( '/<figure.*?>.*?<\/figure>/s', '', $content_to_display );
109
110 echo wp_kses( $content_to_display, ACTIVITYPUB_MASTODON_HTML_SANITIZER );
111 ?>
112 </div>
113 <?php if ( $object->get_attachment() ) : ?>
114 <div class="attachments <?php echo \esc_attr( $layout ); ?>">
115 <?php
116 if ( $has_images ) :
117 foreach ( $object->get_attachment() as $attachment ) :
118 if ( 'Image' === $attachment['type'] ) :
119 ?>
120 <img src="<?php echo esc_url( $attachment['url'] ); ?>" alt="<?php echo esc_attr( $attachment['name'] ?? '' ); ?>" />
121 <?php
122 endif;
123 endforeach;
124 elseif ( $video ) :
125 ?>
126 <video controls src="<?php echo esc_url( $video['url'] ); ?>" title="<?php echo esc_attr( $video['name'] ?? '' ); ?>"></video>
127 <?php
128 elseif ( $audio ) :
129 ?>
130 <audio controls src="<?php echo esc_url( $audio['url'] ); ?>" title="<?php echo esc_attr( $audio['name'] ?? '' ); ?>"></audio>
131 <?php
132 endif;
133 ?>
134 </div>
135 <?php endif; ?>
136 <?php if ( $object->get_tag() ) : ?>
137 <div class="tags">
138 <?php foreach ( $object->get_tag() as $hashtag ) : ?>
139 <?php if ( 'Hashtag' === $hashtag['type'] ) : ?>
140 <a href="<?php echo esc_url( $hashtag['href'] ); ?>"><?php echo esc_html( $hashtag['name'] ); ?></a>
141 <?php endif; ?>
142 <?php endforeach; ?>
143 </div>
144 <?php endif; ?>
145 </article>
146 </main>
147 <aside class="sidebar">
148 <h1> Fediverse</h1>
149 <ul>
150 <li>████████</li>
151 <li>███████████</li>
152 <li>██████████</li>
153 <li>█████████</li>
154 <li>███████</li>
155 <li>████████</li>
156 <li>████████████</li>
157 <li>████████████</li>
158 <li>██████████</li>
159 <li>████████████</li>
160 </ul>
161 <hr />
162 <ul>
163 <li>███████████</li>
164 <li>██████████████</li>
165 <li>█████████</li>
166 </ul>
167 <hr />
168 <ul>
169 <li>██████████</li>
170 </ul>
171 </aside>
172 </div>
173 </body>
174 </html>
175