PluginProbe ʕ •ᴥ•ʔ
Presto Player / 4.3.2
Presto Player v4.3.2
4.3.2 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 / Integrations / BeaverBuilder / ReusableVideoModule / Module.php
presto-player / inc / Integrations / BeaverBuilder / ReusableVideoModule Last commit date
includes 1 month ago Module.php 1 month ago
Module.php
198 lines
1 <?php
2 /**
3 * Presto Player Reusable Video Beaver Builder module.
4 *
5 * @package PrestoPlayer
6 */
7
8 namespace PrestoPlayer\Integrations\BeaverBuilder\ReusableVideoModule;
9
10 use PrestoPlayer\Services\Scripts;
11 use PrestoPlayer\Models\ReusableVideo;
12
13 /**
14 * Beaver Builder module for embedding a Presto Player Media Hub item.
15 */
16 class Module extends \FLBuilderModule {
17
18
19 /**
20 * Register the module with Beaver Builder.
21 */
22 public function __construct() {
23 parent::__construct(
24 array(
25 'name' => __( 'Presto Player Media', 'presto-player' ),
26 'description' => __( 'Presto Player Media', 'presto-player' ),
27 'group' => __( 'Presto Player', 'presto-player' ),
28 'category' => __( 'Presto Player', 'presto-player' ),
29 'dir' => PRESTO_PLAYER_BB_DIR . 'ReusableVideoModule/',
30 'url' => PRESTO_PLAYER_BB_URL . 'ReusableVideoModule/',
31 'icon' => 'button.svg',
32 'editor_export' => true, // Defaults to true and can be omitted.
33 'enabled' => true, // Defaults to true and can be omitted.
34 'partial_refresh' => false, // Defaults to false and can be omitted.
35 )
36 );
37
38 $this->slug = 'presto-player';
39 }
40
41 /**
42 * Should be overridden by subclasses to enqueue
43 * additional css/js using the add_css and add_js methods.
44 *
45 * @since 1.0
46 * @return void
47 */
48 public function enqueue_scripts() {
49 // always enqueue the css.
50 $assets = include trailingslashit( PRESTO_PLAYER_PLUGIN_DIR ) . 'dist/beaver-builder.asset.php';
51 $this->add_css( 'surecart/beaver-builder/admin', trailingslashit( PRESTO_PLAYER_PLUGIN_URL ) . 'dist/beaver-builder.css', array(), $assets['version'] );
52
53 // Responsive iframe ui is enabled, enqueue the script for the parent window.
54 if ( class_exists( '\FLBuilderUIIFrame' ) && \FLBuilderUIIFrame::is_enabled() ) {
55 add_action( 'fl_builder_ui_enqueue_scripts', array( $this, 'enqueue_parent_window_script' ) );
56 } else {
57 $this->add_js(
58 'surecart/beaver-builder/admin',
59 trailingslashit( PRESTO_PLAYER_PLUGIN_URL ) . 'dist/beaver-builder.js',
60 array_merge( array( 'jquery' ), $assets['dependencies'] ),
61 $assets['version'],
62 true
63 );
64 }
65 }
66
67 /**
68 * Enqueue script for the parent window.
69 *
70 * @since 2.0.13
71 * @return void
72 */
73 public function enqueue_parent_window_script() {
74 $assets = include trailingslashit( PRESTO_PLAYER_PLUGIN_DIR ) . 'dist/beaver-builder.asset.php';
75 wp_enqueue_script(
76 'surecart/beaver-builder/admin',
77 trailingslashit( PRESTO_PLAYER_PLUGIN_URL ) . 'dist/beaver-builder.js',
78 array_merge( array( 'jquery', 'regenerator-runtime' ), $assets['dependencies'] ),
79 $assets['version'],
80 true
81 );
82 }
83
84 /**
85 * Get the module settings configuration.
86 *
87 * @return array Settings configuration array for Beaver Builder.
88 */
89 public static function getSettings() {
90 return array(
91 'settings' => array(
92 'title' => __( 'Settings', 'presto-player' ),
93 'sections' => array(
94 'video_select' => array(
95 'title' => 'Media',
96 'fields' => array(
97 'video_select_ajax' => array(
98 'type' => 'raw',
99 'label' => __( 'Select Media Hub Item', 'presto-player' ),
100 'content' => self::dynamic_dropdown(),
101 ),
102 'video_id' => array(
103 'type' => 'text',
104 ),
105 'video_name' => array(
106 'type' => 'text',
107 ),
108 'url_override' => array(
109 'type' => 'text',
110 'label' => 'URL Override',
111 'connections' => array( 'url' ),
112 ),
113 ),
114 ),
115 ),
116 ),
117 );
118 }
119
120 /**
121 * Build the markup for the Media Hub item selector dropdown.
122 *
123 * @return string The dropdown HTML markup.
124 */
125 public static function dynamic_dropdown() {
126 ob_start();
127 ?>
128 <div class="presto-builder--custom-video-controls">
129 <div class="fl-builder--category-select" x-data="window.prestoBBDropdown({nonce: '<?php echo esc_attr( wp_create_nonce( 'wp_rest' ) ); ?>'})" x-init="init">
130 <div class="fl-builder--selector-display" x-on:click="open">
131 <button class="fl-builder--selector-display-label">
132 <span class="fl-builder--group-label"><?php esc_html_e( 'Media', 'presto-player' ); ?></span>
133 <span class="fl-builder--current-view-name" x-text="video.name || 'Select media'"></span>
134 </button>
135 </div>
136
137 <div class="presto-builder--selector-menu">
138 <div class="presto-builder--menu" x-show="isOpen()" x-on:click.away="close">
139 <input class="presto-builder--dropdown-search" x-ref="searchbox" type="text" x-model="search" placeholder="<?php esc_attr_e( 'Search Media Hub', 'presto-player' ); ?>" />
140 <template x-if="loading">
141 <svg width='14px' height='14px' xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid" class="uil-ring">
142 <rect x="0" y="0" width="100" height="100" fill="none" class="bk"></rect>
143 <circle cx="50" cy="50" r="44" stroke-dasharray="179.69909978533616 96.7610537305656" stroke="#2ea2cc" fill="none" stroke-width="12">
144 <animateTransform attributeName="transform" type="rotate" values="0 50 50;180 50 50;360 50 50;" keyTimes="0;0.5;1" dur="1s" repeatCount="indefinite" begin="0s"></animateTransform>
145 </circle>
146 </svg>
147 </template>
148
149 <template x-if="!loading" x-for="item in items" :key="item.ID">
150 <button class="presto-builder--menu-item" x-text="item.post_title" x-on:click="setVideo(item)"></button>
151 </template>
152 </div>
153
154 </div>
155 <div class="presto-builder--video-edit-buttons">
156 <a href="/wp-admin/post-new.php?post_type=pp_video_block" class="fl-builder-button presto-create-bb-video" target="_blank">
157 <?php esc_html_e( 'Create', 'presto-player' ); ?>
158 </a> &nbsp;
159 <template x-if="video.id">
160 <a x-bind:href="video.editLink" class="fl-builder-button presto-create-bb-video" target="_blank">
161 <?php esc_html_e( 'Edit', 'presto-player' ); ?>
162 </a>
163 </template>
164 </div>
165 </div>
166 <?php
167 return ob_get_clean();
168 }
169
170 /**
171 * Display the block
172 *
173 * @return void
174 */
175 public function display() {
176 if ( ! $this->settings->video_id ) {
177 return;
178 }
179
180 // global is the most reliable between page builders.
181 global $load_presto_js;
182 $load_presto_js = true;
183 ( new Scripts() )->blockAssets(); // enqueue block assets.
184
185 $video = new ReusableVideo( $this->settings->video_id );
186 $overrides = array();
187 if ( $this->settings->url_override ) {
188 $overrides['src'] = $this->settings->url_override;
189 }
190 $render = $video->renderBlock( $overrides );
191 if ( $render ) {
192 echo $render; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- renderBlock() returns player markup escaped within the block renderer.
193 return;
194 }
195 return;
196 }
197 }
198