PluginProbe ʕ •ᴥ•ʔ
Presto Player / 2.2.3-beta1
Presto Player v2.2.3-beta1
4.4.1 4.4.0 4.3.3 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 / Divi / Divi.php
presto-player / inc / Integrations / Divi Last commit date
includes 4 years ago Divi.php 2 years ago
Divi.php
135 lines
1 <?php
2
3 namespace PrestoPlayer\Integrations\Divi;
4
5 use PrestoPlayer\Plugin;
6 use PrestoPlayer\WPackio\Enqueue;
7 use PrestoPlayer\Models\ReusableVideo;
8 use PrestoPlayer\Models\Post;
9
10 /**
11 * Handles divi-related functionality
12 */
13 class Divi
14 {
15 public function register()
16 {
17 add_action('divi_extensions_init', [$this, 'init']);
18 add_action('wp_ajax_presto_get_media_attributes', [$this, 'getMediaItemAttributes']);
19 }
20
21 public function init()
22 {
23 // require our module
24 include_once 'includes/PrestoDiviExtension.php';
25
26 // enqueue the scripts
27 add_action('wp_enqueue_scripts', [$this, 'enqueueScripts']);
28
29 // fix rankmath conflict.
30 add_filter('script_loader_tag', [$this, 'rankMathFix'], 11, 3);
31
32 // parse the divi block to get the inner media hub block
33 add_filter('presto_player_get_block_from_content', [$this, 'getInnerBlockFromDiviBlock']);
34 }
35
36 /**
37 * Gets the inner media hub block from the divi block.
38 *
39 * @param array $block the Divi block array.
40 *
41 * @return array $block the filtered media hub inner block array.
42 */
43 public function getInnerBlockFromDiviBlock($block)
44 {
45 // bail if block is empty
46 if (empty($block)) {
47 return $block;
48 }
49
50 // bail if block is not a divi block
51 if ("divi/placeholder" !== $block['blockName']) {
52 return $block;
53 }
54
55 $pattern = get_shortcode_regex(['prpl_presto_player']);
56 $block_id = false;
57 if ($block['innerHTML'] && preg_match("/$pattern/", $block['innerHTML'], $matches)) {
58 $shortcode = $matches[0] ?? '';
59 if (!empty($shortcode)) {
60 $atts = shortcode_parse_atts($shortcode);
61 $block_id = isset($atts['video_id']) ? (int) $atts['video_id'] : false;
62 }
63 }
64 if (!empty($block_id)) {
65 $post_model = new Post(get_post($block_id));
66 $block = $post_model->getMediaHubBlockFromPost($block_id);
67 if (!empty($block)) {
68 return $block;
69 }
70 }
71 return $block;
72 }
73
74 /**
75 * Fixes rankmath excluding wp-i18n script from iframe.
76 *
77 * @param string $tag The <script> tag for the enqueued script.
78 * @param string $handle The script's registered handle.
79 * @param string $src The script's source URL.
80 *
81 * @return string
82 */
83 public function rankMathFix($tag, $handle, $src)
84 {
85 if ('wp-i18n' === $handle) {
86 return '<script type="text/javascript" src="' . $src . '"></script>' . "\n"; // phpcs:ignore
87 }
88 return $tag;
89 }
90
91 /**
92 * Get attributes to inject into JSX component
93 *
94 * @param integer $id
95 * @return void
96 */
97 public function getMediaItemAttributes($id)
98 {
99 \check_ajax_referer('et_admin_load_nonce');
100
101 $id = (int) $_POST['id'] ?? 0;
102
103 if (!$id) {
104 return new \WP_Error('invalid', 'You must provide an id', ['status' => 400]);
105 }
106
107 if (!$video = new ReusableVideo($id)) {
108 return false;
109 }
110
111 return wp_send_json_success($video->getAttributes());
112 }
113
114 public function enqueueScripts()
115 {
116 if (!et_core_is_fb_enabled()) {
117 return;
118 }
119
120 $assets = include trailingslashit(PRESTO_PLAYER_PLUGIN_DIR) . 'dist/divi.asset.php';
121 wp_enqueue_script(
122 'surecart/divi/admin',
123 trailingslashit(PRESTO_PLAYER_PLUGIN_URL) . 'dist/divi.js',
124 array_merge(['react-dom', 'jquery', 'hls.js'], $assets['dependencies']),
125 $assets['version'],
126 true
127 );
128 wp_enqueue_style('surecart/divi/admin', trailingslashit(PRESTO_PLAYER_PLUGIN_URL) . 'dist/divi.css', [], $assets['version']);
129
130 if (function_exists('wp_set_script_translations')) {
131 wp_set_script_translations('surecart/divi/admin', 'presto-player');
132 }
133 }
134 }
135