PluginProbe ʕ •ᴥ•ʔ
Presto Player / 4.3.1
Presto Player v4.3.1
4.3.1 4.3.0 4.2.4 4.2.3 4.2.2 4.2.0 4.2.1 trunk 1.10.0 1.10.1 1.10.2 1.11.0 1.12.0 1.13.0 1.14.0 1.14.1 1.5.10 1.5.11 1.5.12 1.5.13 1.5.14 1.5.15 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.10 1.6.11 1.6.12 1.6.13 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.9.0 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.14 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.16 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.2.0 2.2.1 2.2.2 2.2.3 2.2.3-beta1 2.3.0 2.3.1 2.3.2 2.3.3 3.0.0 3.0.0-beta1 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.1.0 3.1.1 3.1.2 3.1.3 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4
presto-player / inc / Services / ReusableVideos.php
presto-player / inc / Services Last commit date
API 1 month ago Blocks 10 months ago License 1 month ago AdminNotice.php 3 weeks ago AdminNotices.php 3 weeks ago AjaxActions.php 3 weeks ago Blocks.php 1 year ago Compatibility.php 10 months ago Learn.php 1 month ago Menu.php 1 month ago Migrations.php 1 year ago NpsSurvey.php 5 months ago Onboarding.php 3 weeks ago Player.php 3 days ago PluginInstaller.php 1 month ago PreloadService.php 1 year ago ProCompatibility.php 1 month ago ReusableVideos.php 2 weeks ago RewriteRulesManager.php 1 year ago Scripts.php 2 weeks ago Settings.php 1 month ago Shortcodes.php 1 month ago Streamer.php 3 weeks ago Translation.php 3 weeks ago Usage.php 3 weeks ago VideoPostType.php 2 weeks ago
ReusableVideos.php
173 lines
1 <?php
2 /**
3 * Reusable video admin notice and block renderer.
4 *
5 * @package PrestoPlayer
6 * @subpackage Services
7 */
8
9 namespace PrestoPlayer\Services;
10
11 use PrestoPlayer\Services\Scripts;
12
13 /**
14 * Renders the Media Hub introduction notice and helpers for reusable video blocks.
15 */
16 class ReusableVideos {
17
18 /**
19 * Register shortcode.
20 *
21 * @return void
22 */
23 public function register() {
24 add_action( 'admin_notices', array( $this, 'notice' ) );
25 add_action( 'admin_init', array( $this, 'dismissNotice' ) );
26 }
27
28 /**
29 * Render the Media Hub admin notice on the reusable video list screen.
30 *
31 * @return void
32 */
33 public function notice() {
34 global $typenow, $current_screen;
35
36 if ( ! ( 'pp_video_block' === $typenow && 'edit' === $current_screen->base ) ) {
37 return;
38 }
39
40 $notice_name = 'presto_player_reusable_notice';
41 if ( AdminNotices::isDismissed( $notice_name ) ) {
42 return;
43 }
44 ?>
45 <div class="notice" style="border-left-color: #7c3aed;">
46 <p><strong><?php esc_html_e( 'What is the media hub?', 'presto-player' ); ?></strong></p>
47 <p><?php esc_html_e( 'The media hub is a more flexible way to add media to your site. It allows you to save audio and videos which you can later use in any post or page on your site - either through the Block Editor, a page builder, or by using a shortcode or php function.', 'presto-player' ); ?></p>
48 <p><a href="
49 <?php
50 echo esc_url(
51 add_query_arg(
52 array(
53 'presto_action' => 'dismiss_notices',
54 'presto_notice' => $notice_name,
55 '_wpnonce' => wp_create_nonce( AdminNotices::DISMISS_NONCE_ACTION ),
56 )
57 )
58 );
59 ?>
60 "><?php esc_html_e( 'Dismiss Notice', 'presto-player' ); ?></a></p>
61 </div>
62 <?php
63 }
64
65 /**
66 * Persist the dismissal of the Media Hub notice on admin_init.
67 *
68 * @return void
69 */
70 public function dismissNotice() {
71 // Permissions check.
72 if ( ! current_user_can( 'update_options' ) ) {
73 return;
74 }
75
76 // Not our notices, bail.
77 if ( ! isset( $_GET['presto_action'] ) || 'dismiss_notice' !== $_GET['presto_action'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only branch guard; nonce verified before update below.
78 return;
79 }
80
81 $notice = ! empty( $_GET['presto_notice'] ) ? sanitize_text_field( wp_unslash( $_GET['presto_notice'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce verified before update below.
82
83 if ( ! $notice ) {
84 return;
85 }
86
87 // Notice is dismissed.
88 update_option( 'presto_player_dismissed_notice_' . sanitize_text_field( $notice ), 1 );
89 }
90
91 /**
92 * Get reusable video block function.
93 *
94 * @param mixed $id The ID of the reusable block.
95 * @return string The content of the block.
96 */
97 public static function get( $id ) {
98 $content_post = get_post( $id );
99 $content = $content_post ? $content_post->post_content : '';
100 return $content;
101 }
102
103 /**
104 * Render a reusable block by id.
105 *
106 * @param int $id The ID of the reusable block.
107 * @return string Rendered HTML.
108 */
109 public static function getBlock( $id ) {
110 $blocks = parse_blocks( self::get( $id ) );
111 $out = '';
112 if ( is_feed() ) {
113 foreach ( $blocks as $block ) {
114 foreach ( $block['innerBlocks'] as $innerblock ) {
115 $out .= self::getFeedHtml( $innerblock );
116 }
117 }
118 return $out;
119 }
120
121 foreach ( $blocks as $block ) {
122 $out .= render_block( $block );
123 }
124
125 return $out;
126 }
127
128 /**
129 * Display block function.
130 *
131 * @param mixed $id The ID of the reusable block.
132 */
133 public static function display( $id ) {
134 echo self::getBlock( $id ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output is rendered block HTML from core's render_block().
135 }
136
137 /**
138 * Return fallback html for feeds.
139 *
140 * @param array $block array of block attributes.
141 */
142 public static function getFeedHtml( $block ) {
143
144 $html = '';
145 if ( 'presto-player/vimeo' === $block['blockName'] ) {
146 ob_start();
147 ?>
148 <div class="presto-iframe-fallback-container">
149 <iframe style="width: 100%" class="presto-fallback-iframe" id="presto-iframe-fallback-<?php echo (int) $block['attrs']['id']; ?>" src="<?php echo esc_attr( $block['attrs']['src'] ); ?>"></iframe>
150 </div>
151 <?php
152 $html = ob_get_clean();
153 } elseif ( 'presto-player/youtube' === $block['blockName'] ) {
154 ob_start();
155 ?>
156 <div class="presto-iframe-fallback-container">
157 <iframe style="width: 100%" class="presto-fallback-iframe" id="presto-iframe-fallback-<?php echo (int) $block['attrs']['id']; ?>" src="<?php echo esc_attr( $block['attrs']['src'] ); ?>"></iframe>
158 </div>
159 <?php
160 $html = ob_get_clean();
161 } else {
162 ob_start();
163 ?>
164 <video controls preload="none">
165 <source src="<?php echo esc_attr( $block['attrs']['src'] ); ?>" />
166 </video>
167 <?php
168 $html = ob_get_clean();
169 }
170 return $html;
171 }
172 }
173