Elementor_Enhancer.php
1 year ago
EmbedPress_Core_Installer.php
6 years ago
EmbedPress_Notice.php
2 years ago
EmbedPress_Plugin_Usage_Tracker.php
1 year ago
Extend_CustomPlayer_Controls.php
1 year ago
Extend_Elementor_Controls.php
1 year ago
Feature_Enhancer.php
1 year ago
Helper.php
1 year ago
Feature_Enhancer.php
1697 lines
| 1 | <?php |
| 2 | |
| 3 | namespace EmbedPress\Includes\Classes; |
| 4 | |
| 5 | use \EmbedPress\Providers\Youtube; |
| 6 | use EmbedPress\Shortcode; |
| 7 | use EmbedPress\Includes\Classes\Helper; |
| 8 | use \Elementor\Controls_Manager; |
| 9 | use EmbedPress\Providers\TemplateLayouts\YoutubeLayout; |
| 10 | use EmbedPress\Providers\TikTok; |
| 11 | use EmbedPress\Providers\Spreaker; |
| 12 | use EmbedPress\Providers\Wrapper; |
| 13 | use EmbedPress\Providers\GooglePhotos; |
| 14 | |
| 15 | class Feature_Enhancer |
| 16 | { |
| 17 | public static $attributes_data; |
| 18 | |
| 19 | public function __construct() |
| 20 | { |
| 21 | add_filter('embedpress:onAfterEmbed', [$this, 'enhance_youtube'], 90); |
| 22 | add_filter('embedpress:onAfterEmbed', [$this, 'enhance_vimeo'], 90); |
| 23 | add_filter('embedpress:onAfterEmbed', [$this, 'enhance_wistia'], 90); |
| 24 | add_filter('embedpress:onAfterEmbed', [$this, 'enhance_twitch'], 90); |
| 25 | add_filter('embedpress:onAfterEmbed', [$this, 'enhance_dailymotion'], 90); |
| 26 | add_filter('embedpress:onAfterEmbed', [$this, 'enhance_soundcloud'], 90); |
| 27 | add_filter('embedpress:onAfterEmbed', [$this, 'enhance_missing_title'], 90); |
| 28 | |
| 29 | add_filter( |
| 30 | 'embedpress_gutenberg_youtube_params', |
| 31 | [$this, 'embedpress_gutenberg_register_block_youtube'] |
| 32 | ); |
| 33 | |
| 34 | add_action('init', array($this, 'embedpress_gutenberg_register_block_vimeo')); |
| 35 | add_action('embedpress_gutenberg_wistia_block_after_embed', array($this, 'embedpress_wistia_block_after_embed')); |
| 36 | add_action('elementor/widget/embedpres_elementor/skins_init', [$this, 'elementor_setting_init']); |
| 37 | add_action('wp_ajax_youtube_rest_api', [$this, 'youtube_rest_api']); |
| 38 | add_action('wp_ajax_nopriv_youtube_rest_api', [$this, 'youtube_rest_api']); |
| 39 | add_action('embedpress_gutenberg_embed', [$this, 'gutenberg_embed'], 10, 2); |
| 40 | add_action('wp_ajax_save_source_data', [$this, 'save_source_data']); |
| 41 | add_action('save_post', [$this, 'save_source_data_on_post_update'], 10, 3); |
| 42 | add_action('wp_ajax_delete_source_data', [$this, 'delete_source_data']); |
| 43 | add_action('load-post.php', [$this, 'delete_source_temp_data_on_reload']); |
| 44 | add_action('embedpress:isEmbra', [$this, 'isEmbra'], 10, 3); |
| 45 | add_action('elementor/editor/after_save', [$this, 'save_el_source_data_on_post_update']); |
| 46 | |
| 47 | add_action('wp_head', [$this, 'embedpress_generate_social_share_meta']); |
| 48 | |
| 49 | add_action('wp_ajax_get_viewer', function () { |
| 50 | $pdf = EMBEDPRESS_PATH_BASE . 'assets/pdf/web/viewer.html'; |
| 51 | // header type html |
| 52 | header('Content-Type: text/html'); |
| 53 | $contents = file_get_contents($pdf); |
| 54 | echo str_replace('<head>', '<head><base href="' . EMBEDPRESS_URL_ASSETS . 'pdf/web/' . '">', $contents); |
| 55 | die; |
| 56 | }); |
| 57 | add_action('wp_ajax_nopriv_get_viewer', function () { |
| 58 | $pdf = EMBEDPRESS_PATH_BASE . 'assets/pdf/web/viewer.html'; |
| 59 | // header type html |
| 60 | header('Content-Type: text/html'); |
| 61 | $contents = file_get_contents($pdf); |
| 62 | echo str_replace('<head>', '<head><base href="' . EMBEDPRESS_URL_ASSETS . 'pdf/web/' . '">', $contents); |
| 63 | die; |
| 64 | }); |
| 65 | } |
| 66 | |
| 67 | public function save_source_data() |
| 68 | { |
| 69 | if (!isset($_POST['_source_nonce']) || !wp_verify_nonce($_POST['_source_nonce'], 'source_nonce_embedpress')) { |
| 70 | return; |
| 71 | } |
| 72 | |
| 73 | if (!current_user_can('manage_options')) { |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | $source_url = isset($_POST['source_url']) ? $_POST['source_url'] : null; |
| 78 | $blockid = isset($_POST['block_id']) ? $_POST['block_id'] : null; |
| 79 | |
| 80 | |
| 81 | Helper::get_source_data($blockid, $source_url, 'gutenberg_source_data', 'gutenberg_temp_source_data'); |
| 82 | } |
| 83 | |
| 84 | function save_el_source_data_on_post_update($post_id) |
| 85 | { |
| 86 | Helper::get_save_source_data_on_post_update('elementor_source_data', 'elementor_temp_source_data'); |
| 87 | } |
| 88 | |
| 89 | function save_source_data_on_post_update($post_id, $post, $update) |
| 90 | { |
| 91 | if (!empty(strpos($post->post_content, 'wp:embedpress'))) { |
| 92 | Helper::get_save_source_data_on_post_update('gutenberg_source_data', 'gutenberg_temp_source_data'); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | public function delete_source_data() |
| 97 | { |
| 98 | if (!isset($_POST['_source_nonce']) || !wp_verify_nonce($_POST['_source_nonce'], 'source_nonce_embedpress')) { |
| 99 | return; |
| 100 | } |
| 101 | if (!current_user_can('manage_options')) { |
| 102 | return; |
| 103 | } |
| 104 | |
| 105 | $blockid = isset($_POST['block_id']) ? $_POST['block_id'] : ''; |
| 106 | |
| 107 | Helper::get_delete_source_data($blockid, 'gutenberg_source_data', 'gutenberg_temp_source_data'); |
| 108 | } |
| 109 | |
| 110 | public function delete_source_temp_data_on_reload() |
| 111 | { |
| 112 | Helper::get_delete_source_temp_data_on_reload('gutenberg_temp_source_data'); |
| 113 | } |
| 114 | |
| 115 | public function isEmbra($isEmbra, $url, $atts) |
| 116 | { |
| 117 | |
| 118 | if (strpos($url, 'youtube.com') !== false) { |
| 119 | $youtube = new Youtube($url, $atts); |
| 120 | if ($youtube->validateUrl($youtube->getUrl(false))) { |
| 121 | return true; |
| 122 | } |
| 123 | } |
| 124 | if (strpos($url, 'tiktok.com') !== false) { |
| 125 | $tiktok = new TikTok($url, $atts); |
| 126 | if ($tiktok->validateUrl($tiktok->getUrl(false))) { |
| 127 | return true; |
| 128 | } |
| 129 | } |
| 130 | if (strpos($url, 'spreaker.com') !== false) { |
| 131 | $spreaker = new Spreaker($url, $atts); |
| 132 | if ($spreaker->validateUrl($spreaker->getUrl(false))) { |
| 133 | return true; |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | |
| 138 | if (strpos($url, 'photos.app.goo.gl') !== false) { |
| 139 | $google_photos = new GooglePhotos($url, $atts); |
| 140 | |
| 141 | if ($google_photos->validateUrl($google_photos->getUrl(false))) { |
| 142 | return true; |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | if (strpos($url, site_url()) !== false) { |
| 147 | $wrapper = new Wrapper($url, $atts); |
| 148 | if ($wrapper->validateUrl($wrapper->getUrl(false))) { |
| 149 | return true; |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | return $isEmbra; |
| 154 | } |
| 155 | |
| 156 | // public function youtube_rest_api() |
| 157 | // { |
| 158 | // // Instantiate the class |
| 159 | // $youtube = new Youtube($config = ''); |
| 160 | |
| 161 | |
| 162 | // // Call the non-static method |
| 163 | // // $result = $youtube->someMethod(); |
| 164 | |
| 165 | // $result = YoutubeLayout::create_youtube_layout([ |
| 166 | // 'playlistId' => isset($_POST['playlistid']) ? sanitize_text_field($_POST['playlistid']) : null, |
| 167 | // 'pageToken' => isset($_POST['pagetoken']) ? sanitize_text_field($_POST['pagetoken']) : null, |
| 168 | // 'ytChannelLayout' => isset($_POST['ytChannelLayout']) ? sanitize_text_field($_POST['ytChannelLayout']) : 'gallery', |
| 169 | // 'pagesize' => isset($_POST['pagesize']) ? sanitize_text_field($_POST['pagesize']) : null, |
| 170 | // 'currentpage' => isset($_POST['currentpage']) ? sanitize_text_field($_POST['currentpage']) : null, |
| 171 | // 'columns' => isset($_POST['epcolumns']) ? sanitize_text_field($_POST['epcolumns']) : null, |
| 172 | // 'showTitle' => isset($_POST['showtitle']) ? sanitize_text_field($_POST['showtitle']) : null, |
| 173 | // 'showPaging' => isset($_POST['showpaging']) ? sanitize_text_field($_POST['showpaging']) : null, |
| 174 | // 'autonext' => isset($_POST['autonext']) ? sanitize_text_field($_POST['autonext']) : null, |
| 175 | // 'thumbplay' => isset($_POST['thumbplay']) ? sanitize_text_field($_POST['thumbplay']) : null, |
| 176 | // 'thumbnail_quality' => isset($_POST['thumbnail_quality']) ? sanitize_text_field($_POST['thumbnail_quality']) : null, |
| 177 | // ], $youtube->layout_data(), $youtube->get_layout()); |
| 178 | |
| 179 | // // print_r($youtube->layout_data()); die; |
| 180 | |
| 181 | // wp_send_json($result); |
| 182 | // } |
| 183 | |
| 184 | public function youtube_rest_api() |
| 185 | { |
| 186 | // Instantiate the class |
| 187 | $youtube = new Youtube($config = ''); |
| 188 | |
| 189 | // echo '<pre>'; |
| 190 | |
| 191 | // print_r($_POST); |
| 192 | |
| 193 | $result = $youtube->get_gallery_page([ |
| 194 | 'playlistId' => isset($_POST['playlistid']) ? sanitize_text_field($_POST['playlistid']) : null, |
| 195 | 'pageToken' => isset($_POST['pagetoken']) ? sanitize_text_field($_POST['pagetoken']) : null, |
| 196 | 'pagesize' => isset($_POST['pagesize']) ? sanitize_text_field($_POST['pagesize']) : null, |
| 197 | 'currentpage' => isset($_POST['currentpage']) ? sanitize_text_field($_POST['currentpage']) : null, |
| 198 | 'columns' => isset($_POST['epcolumns']) ? sanitize_text_field($_POST['epcolumns']) : null, |
| 199 | 'showTitle' => isset($_POST['showtitle']) ? sanitize_text_field($_POST['showtitle']) : null, |
| 200 | 'showPaging' => isset($_POST['showpaging']) ? sanitize_text_field($_POST['showpaging']) : null, |
| 201 | 'autonext' => isset($_POST['autonext']) ? sanitize_text_field($_POST['autonext']) : null, |
| 202 | 'thumbplay' => isset($_POST['thumbplay']) ? sanitize_text_field($_POST['thumbplay']) : null, |
| 203 | 'thumbnail_quality' => isset($_POST['thumbnail_quality']) ? sanitize_text_field($_POST['thumbnail_quality']) : null, |
| 204 | 'channel_url' => isset($_POST['channelUrl']) ? sanitize_text_field($_POST['channelUrl']) : '' |
| 205 | ]); |
| 206 | |
| 207 | wp_send_json($result); |
| 208 | } |
| 209 | |
| 210 | |
| 211 | //Check is YouTube single video |
| 212 | public function ytValidateUrl($url) |
| 213 | { |
| 214 | return (bool) (preg_match('~v=(?:[a-z0-9_\-]+)~i', (string) $url)); |
| 215 | } |
| 216 | |
| 217 | //Check is YouTube live video |
| 218 | public function ytValidateLiveUrl($url) |
| 219 | { |
| 220 | return (bool) (preg_match('/^https?:\/\/(?:www\.)?youtube\.com\/(?:channel\/[\w-]+|@[\w-]+)\/live$/', (string) $url)); |
| 221 | } |
| 222 | |
| 223 | |
| 224 | //Check is Wistia validate url |
| 225 | public function wistiaValidateUrl($url) |
| 226 | { |
| 227 | return (bool) (preg_match('#\/medias\\\?\/([a-z0-9]+)\.?#i', (string) $url)); |
| 228 | } |
| 229 | |
| 230 | //Check is Wistia validate url |
| 231 | public function vimeoValidateUrl($url) |
| 232 | { |
| 233 | return (bool) preg_match('/https?:\/\/(www\.)?vimeo\.com\/\d+/', (string) $url); |
| 234 | } |
| 235 | |
| 236 | |
| 237 | |
| 238 | // Get wistia block attributes |
| 239 | public function get_wistia_block_attributes($attributes) |
| 240 | { |
| 241 | |
| 242 | // Embed Options |
| 243 | $embedOptions = new \stdClass; |
| 244 | $embedOptions->videoFoam = false; |
| 245 | $embedOptions->fullscreenButton = (isset($attributes['wfullscreen']) && (bool) $attributes['wfullscreen'] === true); |
| 246 | $embedOptions->playbar = (isset($attributes['playbar']) && (bool) $attributes['playbar'] === true); |
| 247 | |
| 248 | $embedOptions->playButton = (isset($attributes['playbutton']) && (bool) $attributes['playbutton'] === true); |
| 249 | $embedOptions->smallPlayButton = (isset($attributes['smallplaybutton']) && (bool) $attributes['smallplaybutton'] === true); |
| 250 | |
| 251 | $embedOptions->autoPlay = (isset($attributes['wautoplay']) && (bool) $attributes['wautoplay'] === true); |
| 252 | $embedOptions->resumable = (isset($attributes['resumable']) && (bool) $attributes['resumable'] === true); |
| 253 | |
| 254 | if (!empty($attributes['wstarttime'])) { |
| 255 | $embedOptions->time = isset($attributes['wstarttime']) ? $attributes['wstarttime'] : ''; |
| 256 | } |
| 257 | |
| 258 | $embedOptions = apply_filters('embedpress_wistia_block_attributes', $embedOptions, $attributes); |
| 259 | |
| 260 | $pluginList = []; |
| 261 | |
| 262 | if (isset($attributes['scheme'])) { |
| 263 | $color = $attributes['scheme']; |
| 264 | if (null !== $color) { |
| 265 | $embedOptions->playerColor = $color; |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | // Closed Captions plugin |
| 270 | if ($attributes['captions'] === true) { |
| 271 | $isCaptionsEnabled = ($attributes['captions'] === true); |
| 272 | $isCaptionsEnabledByDefault = ($attributes['captions'] === true); |
| 273 | if ($isCaptionsEnabled) { |
| 274 | $pluginList['captions-v1'] = [ |
| 275 | 'onByDefault' => $isCaptionsEnabledByDefault, |
| 276 | ]; |
| 277 | } |
| 278 | $embedOptions->captions = $isCaptionsEnabled; |
| 279 | $embedOptions->captionsDefault = $isCaptionsEnabledByDefault; |
| 280 | } |
| 281 | |
| 282 | $embedOptions->plugin = $pluginList; |
| 283 | |
| 284 | |
| 285 | |
| 286 | return json_encode($embedOptions); |
| 287 | } |
| 288 | |
| 289 | public function gutenberg_embed($embedHTML, $attributes) |
| 290 | { |
| 291 | $attributes = Helper::removeQuote($attributes); |
| 292 | |
| 293 | if (!empty($attributes['url'])) { |
| 294 | $youtube = new Youtube($attributes['url']); |
| 295 | |
| 296 | $is_youtube = $youtube->validateUrl($youtube->getUrl(false)); |
| 297 | if ($is_youtube && empty($this->ytValidateLiveUrl($attributes['url']))) { |
| 298 | $atts = [ |
| 299 | 'width' => intval($attributes['width']), |
| 300 | 'height' => intval($attributes['height']), |
| 301 | 'pagesize' => isset($attributes['pagesize']) ? intval($attributes['pagesize']) : 6, |
| 302 | 'ytChannelLayout' => isset($attributes['ytChannelLayout']) ? $attributes['ytChannelLayout'] : 'gallery', |
| 303 | 'columns' => isset($attributes['columns']) ? intval($attributes['columns']) : 3, |
| 304 | 'ispagination' => isset($attributes['ispagination']) ? $attributes['ispagination'] : 0, |
| 305 | 'gapbetweenvideos' => isset($attributes['gapbetweenvideos']) ? $attributes['gapbetweenvideos'] : 30, |
| 306 | ]; |
| 307 | |
| 308 | $atts = Helper::removeQuote($atts); |
| 309 | |
| 310 | $urlInfo = Shortcode::parseContent($attributes['url'], true, $atts); |
| 311 | |
| 312 | if (!empty($urlInfo->embed)) { |
| 313 | $embedHTML = $urlInfo->embed; |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | if (!empty($attributes['url']) && ($this->ytValidateUrl($attributes['url']) || $this->ytValidateLiveUrl($attributes['url']))) { |
| 318 | |
| 319 | $atts = [ |
| 320 | 'url' => $attributes['url'], |
| 321 | 'starttime' => !empty($attributes['starttime']) ? $attributes['starttime'] : '', |
| 322 | 'endtime' => !empty($attributes['endtime']) ? $attributes['endtime'] : '', |
| 323 | 'autoplay' => !empty($attributes['autoplay']) ? 1 : 0, |
| 324 | 'controls' => isset($attributes['controls']) ? $attributes['controls'] : '1', |
| 325 | 'fullscreen' => !empty($attributes['fullscreen']) ? 1 : 0, |
| 326 | 'videoannotations' => !empty($attributes['videoannotations']) ? 1 : 0, |
| 327 | 'progressbarcolor' => !empty($attributes['progressbarcolor']) ? $attributes['progressbarcolor'] : 'red', |
| 328 | 'closedcaptions' => !empty($attributes['closedcaptions']) ? 1 : 0, |
| 329 | 'modestbranding' => !empty($attributes['modestbranding']) ? $attributes['modestbranding'] : '', |
| 330 | 'relatedvideos' => !empty($attributes['relatedvideos']) ? 1 : 0, |
| 331 | 'muteVideo' => !empty($attributes['muteVideo']) ? 1 : 0, |
| 332 | 'customlogo' => !empty($attributes['customlogo']) ? $attributes['customlogo'] : '', |
| 333 | 'logoX' => !empty($attributes['logoX']) ? $attributes['logoX'] : 5, |
| 334 | 'logoY' => !empty($attributes['logoY']) ? $attributes['logoY'] : 10, |
| 335 | 'customlogoUrl' => !empty($attributes['customlogoUrl']) ? $attributes['customlogoUrl'] : '', |
| 336 | 'logoOpacity' => !empty($attributes['logoOpacity']) ? $attributes['logoOpacity'] : 0.6, |
| 337 | ]; |
| 338 | |
| 339 | $atts = Helper::removeQuote($atts); |
| 340 | |
| 341 | $urlInfo = Shortcode::parseContent($attributes['url'], true, $atts); |
| 342 | |
| 343 | if (!empty($urlInfo->embed)) { |
| 344 | $embedHTML = $urlInfo->embed; |
| 345 | } |
| 346 | |
| 347 | if (isset($urlInfo->embed) && preg_match('/src=\"(.+?)\"/', $urlInfo->embed, $match)) { |
| 348 | $url_full = $match[1]; |
| 349 | $query = parse_url($url_full, PHP_URL_QUERY); |
| 350 | |
| 351 | parse_str($query ?? '', $params); |
| 352 | |
| 353 | $params['controls'] = isset($attributes['controls']) ? $attributes['controls'] : '1'; |
| 354 | $params['iv_load_policy'] = !empty($attributes['videoannotations']) ? 1 : 0; |
| 355 | $params['fs'] = !empty($attributes['fullscreen']) ? 1 : 0; |
| 356 | $params['rel'] = !empty($attributes['relatedvideos']) ? 1 : 0; |
| 357 | $params['end'] = !empty($attributes['endtime']) ? $attributes['endtime'] : ''; |
| 358 | $params['autoplay'] = !empty($attributes['autoplay']) ? 1 : 0; |
| 359 | $params['mute'] = !empty($attributes['muteVideo']) ? 1 : 0; |
| 360 | $params['start'] = !empty($attributes['starttime']) ? $attributes['starttime'] : ''; |
| 361 | $params['color'] = !empty($attributes['progressbarcolor']) ? $attributes['progressbarcolor'] : 'red'; |
| 362 | $params['modestbranding'] = empty($attributes['modestbranding']) ? 0 : 1; // Reverse the condition value for modestbranding. 0 = display, 1 = do not display |
| 363 | $params['cc_load_policy'] = !empty($attributes['closedcaptions']) ? 0 : 1; |
| 364 | |
| 365 | preg_match('/(.+)?\?/', $url_full, $url); |
| 366 | |
| 367 | if (empty($url)) { |
| 368 | return $embedHTML; |
| 369 | } |
| 370 | |
| 371 | $url = $url[1]; |
| 372 | |
| 373 | // Reassemble the url with the new variables. |
| 374 | $url_modified = $url . '?'; |
| 375 | |
| 376 | foreach ($params as $paramName => $paramValue) { |
| 377 | |
| 378 | $and = '&'; |
| 379 | if (array_key_last($params) === $paramName) { |
| 380 | $and = ''; |
| 381 | } |
| 382 | |
| 383 | if (isset($paramValue) && $paramValue !== '') { |
| 384 | $url_modified .= $paramName . '=' . $paramValue . $and; |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | // Replaces the old url with the new one. |
| 389 | $embedHTML = str_replace($url_full, rtrim($url_modified, '&'), $urlInfo->embed); |
| 390 | } |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | if (!empty($attributes['url']) && $this->wistiaValidateUrl($attributes['url'])) { |
| 395 | |
| 396 | |
| 397 | $embedOptions = $this->get_wistia_block_attributes($attributes); |
| 398 | |
| 399 | // Get the video ID |
| 400 | $videoId = $this->getVideoIDFromURL($attributes['url']); |
| 401 | $shortVideoId = substr($videoId, 0, 3); |
| 402 | |
| 403 | // Responsive? |
| 404 | |
| 405 | $class = array( |
| 406 | 'wistia_embed', |
| 407 | 'wistia_async_' . $videoId |
| 408 | ); |
| 409 | |
| 410 | $attribs = array( |
| 411 | sprintf('id="wistia_%s"', $videoId), |
| 412 | sprintf('class="%s"', join(' ', $class)), |
| 413 | sprintf('style="width:%spx; height:%spx;"', $attributes['width'], $attributes['height']) |
| 414 | ); |
| 415 | |
| 416 | $labels = array( |
| 417 | 'watch_from_beginning' => __('Watch from the beginning', 'embedpress'), |
| 418 | 'skip_to_where_you_left_off' => __('Skip to where you left off', 'embedpress'), |
| 419 | 'you_have_watched_it_before' => __( |
| 420 | 'It looks like you\'ve watched<br />part of this video before!', |
| 421 | 'embedpress' |
| 422 | ), |
| 423 | ); |
| 424 | $labels = json_encode($labels); |
| 425 | |
| 426 | preg_match('/ose-uid-([a-z0-9]*)/', $attributes['embedHTML'], $matches); |
| 427 | $uid = $matches[1]; |
| 428 | |
| 429 | $html = "<div class=\"embedpress-wrapper ose-wistia ose-uid-{$uid} responsive\">"; |
| 430 | $html .= '<script src="https://fast.wistia.com/assets/external/E-v1.js" async></script>'; |
| 431 | $html .= "<script>window.pp_embed_wistia_labels = {$labels};</script>\n"; |
| 432 | $html .= "<script>window._wq = window._wq || []; _wq.push({\"{$shortVideoId}\": {$embedOptions}});</script>\n"; |
| 433 | $html .= '<div ' . join(' ', $attribs) . "></div>\n"; |
| 434 | $html .= '</div>'; |
| 435 | $embedHTML = $html; |
| 436 | } |
| 437 | |
| 438 | if (!empty($attributes['url']) && $this->vimeoValidateUrl($attributes['url'])) { |
| 439 | |
| 440 | $atts = [ |
| 441 | 'url' => $attributes['url'], |
| 442 | 'vstarttime' => !empty($attributes['vstarttime']) ? $attributes['vstarttime'] : '', |
| 443 | 'vscheme' => !empty($attributes['vscheme']) ? $attributes['vscheme'] : 'red', |
| 444 | 'vautoplay' => !empty($attributes['vautoplay']) ? 1 : 0, |
| 445 | 'vtitle' => !empty($attributes['vtitle']) ? 1 : 0, |
| 446 | 'vauthor' => !empty($attributes['vauthor']) ? 1 : 0, |
| 447 | 'vavatar' => !empty($attributes['vavatar']) ? 1 : 0, |
| 448 | 'vautopause' => !empty($attributes['vautopause']) ? 1 : 0, |
| 449 | 'vdnt' => !empty($attributes['vdnt']) ? 1 : 0, |
| 450 | 'customlogo' => !empty($attributes['customlogo']) ? $attributes['customlogo'] : '', |
| 451 | 'logoX' => !empty($attributes['logoX']) ? $attributes['logoX'] : 5, |
| 452 | 'logoY' => !empty($attributes['logoY']) ? $attributes['logoY'] : 10, |
| 453 | 'customlogoUrl' => !empty($attributes['customlogoUrl']) ? $attributes['customlogoUrl'] : '', |
| 454 | 'logoOpacity' => !empty($attributes['logoOpacity']) ? $attributes['logoOpacity'] : 0.6, |
| 455 | ]; |
| 456 | |
| 457 | $atts = Helper::removeQuote($atts); |
| 458 | |
| 459 | $urlInfo = Shortcode::parseContent($attributes['url'], true, $atts); |
| 460 | |
| 461 | if (!empty($urlInfo->embed)) { |
| 462 | $embedHTML = $urlInfo->embed; |
| 463 | } |
| 464 | |
| 465 | if (isset($urlInfo->embed) && preg_match('/src=\"(.+?)\"/', $urlInfo->embed, $match)) { |
| 466 | $url_full = $match[1]; |
| 467 | $query = parse_url($url_full, PHP_URL_QUERY); |
| 468 | parse_str($query, $params); |
| 469 | |
| 470 | |
| 471 | unset($params['amp;dnt']); |
| 472 | |
| 473 | $params['title'] = !empty($attributes['vtitle']) ? 1 : 0; |
| 474 | $params['byline'] = !empty($attributes['vauthor']) ? 1 : 0; |
| 475 | $params['portrait'] = !empty($attributes['vavatar']) ? 1 : 0; |
| 476 | $params['autoplay'] = !empty($attributes['vautoplay']) ? 1 : 0; |
| 477 | $params['loop'] = !empty($attributes['vloop']) ? 1 : 0; |
| 478 | $params['autopause'] = !empty($attributes['vautopause']) ? 1 : 0; |
| 479 | if (empty($attributes['vautopause'])) : |
| 480 | $params['dnt'] = !empty($attributes['vdnt']) ? 1 : 0; |
| 481 | endif; |
| 482 | $params['color'] = !empty($attributes['vscheme']) ? str_replace("#", "", $attributes['vscheme']) : '00ADEF'; |
| 483 | |
| 484 | if (!empty($attributes['vstarttime'])) : |
| 485 | $params['t'] = !empty($attributes['vstarttime']) ? $attributes['vstarttime'] : ''; |
| 486 | endif; |
| 487 | |
| 488 | preg_match('/(.+)?\?/', $url_full, $url); |
| 489 | |
| 490 | if (empty($url)) { |
| 491 | return $embedHTML; |
| 492 | } |
| 493 | |
| 494 | $url = $url[1]; |
| 495 | |
| 496 | // Reassemble the url with the new variables. |
| 497 | $url_modified = $url . '?'; |
| 498 | |
| 499 | // print_r($url_modified); |
| 500 | |
| 501 | |
| 502 | foreach ($params as $param => $value) { |
| 503 | $url_modified = add_query_arg($param, $value, $url_modified); |
| 504 | } |
| 505 | |
| 506 | $url_modified = str_replace("&t=", "#t=", $url_modified); |
| 507 | |
| 508 | // Replaces the old url with the new one. |
| 509 | $embedHTML = str_replace($url_full, rtrim($url_modified, '&'), $urlInfo->embed); |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | return $embedHTML; |
| 514 | } |
| 515 | |
| 516 | |
| 517 | public function elementor_setting_init() |
| 518 | { |
| 519 | $this->remove_classic_filters(); |
| 520 | add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'youtube'], 10, 2); |
| 521 | add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'wistia'], 10, 2); |
| 522 | add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'twitch'], 10, 2); |
| 523 | add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'soundcloud'], 10, 2); |
| 524 | add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'dailymotion'], 10, 2); |
| 525 | add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'spotify'], 10, 2); |
| 526 | add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'vimeo'], 10, 2); |
| 527 | } |
| 528 | public function remove_classic_filters() |
| 529 | { |
| 530 | remove_filter('embedpress:onAfterEmbed', [$this, 'enhance_youtube'], 90); |
| 531 | remove_filter('embedpress:onAfterEmbed', [$this, 'enhance_vimeo'], 90); |
| 532 | remove_filter('embedpress:onAfterEmbed', [$this, 'enhance_wistia'], 90); |
| 533 | remove_filter('embedpress:onAfterEmbed', [$this, 'enhance_twitch'], 90); |
| 534 | remove_filter('embedpress:onAfterEmbed', [$this, 'enhance_dailymotion'], 90); |
| 535 | remove_filter('embedpress:onAfterEmbed', [$this, 'enhance_soundcloud'], 90); |
| 536 | } |
| 537 | public function getOptions($provider = '', $schema = []) |
| 538 | { |
| 539 | $options = (array) get_option(EMBEDPRESS_PLG_NAME . ':' . $provider, []); |
| 540 | if (empty($options) || (count($options) === 1 && empty($options[0]))) { |
| 541 | $options = []; |
| 542 | |
| 543 | foreach ($schema as $fieldSlug => $field) { |
| 544 | $value = isset($field['default']) ? $field['default'] : ""; |
| 545 | |
| 546 | settype($value, isset($field['type']) && in_array( |
| 547 | strtolower($field['type']), |
| 548 | ['bool', 'boolean', 'int', 'integer', 'float', 'string'] |
| 549 | ) ? $field['type'] : 'string'); |
| 550 | |
| 551 | if ($fieldSlug === "license_key") { |
| 552 | $options['license'] = [ |
| 553 | 'key' => true, |
| 554 | 'status' => "missing", |
| 555 | ]; |
| 556 | } else { |
| 557 | $options[$fieldSlug] = $value; |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | $options['license'] = [ |
| 563 | 'key' => true, |
| 564 | 'status' => "missing", |
| 565 | ]; |
| 566 | return apply_filters('emebedpress_get_options', $options); |
| 567 | } |
| 568 | |
| 569 | public function get_youtube_params($options) |
| 570 | { |
| 571 | $params = []; |
| 572 | |
| 573 | // Handle `autoplay` option. |
| 574 | if (isset($options['autoplay']) && (bool) $options['autoplay'] === true) { |
| 575 | $params['autoplay'] = 1; |
| 576 | } else { |
| 577 | unset($params['autoplay']); |
| 578 | } |
| 579 | |
| 580 | // Handle `controls` option. |
| 581 | if (isset($options['controls']) && in_array((int) $options['controls'], [0, 1, 2])) { |
| 582 | $params['controls'] = (int) $options['controls']; |
| 583 | } else { |
| 584 | unset($params['controls']); |
| 585 | } |
| 586 | |
| 587 | // Handle `fs` option. |
| 588 | if (isset($options['fs']) && in_array((int) $options['fs'], [0, 1])) { |
| 589 | $params['fs'] = (int) $options['fs']; |
| 590 | } else { |
| 591 | unset($params['fs']); |
| 592 | } |
| 593 | |
| 594 | // Handle `iv_load_policy` option. |
| 595 | if (isset($options['iv_load_policy']) && in_array((int) $options['iv_load_policy'], [1, 3])) { |
| 596 | $params['iv_load_policy'] = (int) $options['iv_load_policy']; |
| 597 | } else { |
| 598 | unset($params['iv_load_policy']); |
| 599 | } |
| 600 | |
| 601 | return apply_filters('embedpress_youtube_params', $params); |
| 602 | } |
| 603 | |
| 604 | public function get_vimeo_params($options) |
| 605 | { |
| 606 | $params = []; |
| 607 | |
| 608 | // Handle `display_title` option. |
| 609 | if (isset($options['display_title']) && (bool) $options['display_title'] === true) { |
| 610 | $params['title'] = 1; |
| 611 | } else { |
| 612 | $params['title'] = 0; |
| 613 | } |
| 614 | |
| 615 | // Handle `autoplay` option. |
| 616 | if (!empty($options['autoplay'])) { |
| 617 | $params['autoplay'] = 1; |
| 618 | } else { |
| 619 | unset($params['autoplay']); |
| 620 | } |
| 621 | |
| 622 | // Handle `color` option. |
| 623 | if (!empty($options['color'])) { |
| 624 | $params['color'] = str_replace('#', '', $options['color']); |
| 625 | } else { |
| 626 | unset($params['color']); |
| 627 | } |
| 628 | return apply_filters('embedpress_vimeo_params', $params); |
| 629 | } |
| 630 | |
| 631 | //--- For CLASSIC AND BLOCK EDITOR |
| 632 | public function enhance_youtube($embed) |
| 633 | { |
| 634 | |
| 635 | |
| 636 | $isYoutube = (isset($embed->provider_name) && strtoupper($embed->provider_name) === 'YOUTUBE') || (isset($embed->url) && isset($embed->{$embed->url}) && isset($embed->{$embed->url}['provider_name']) && strtoupper($embed->{$embed->url}['provider_name']) === 'YOUTUBE'); |
| 637 | |
| 638 | if ( |
| 639 | $isYoutube && isset($embed->embed) |
| 640 | && preg_match('/<iframe[^>]+src=["\']([^"\']+)[^>]*>/', $embed->embed, $match) |
| 641 | ) { |
| 642 | |
| 643 | // for compatibility only, @TODO; remove later after deep testing. |
| 644 | $options = $this->getOptions('youtube', $this->get_youtube_settings_schema()); |
| 645 | |
| 646 | // Parse the url to retrieve all its info like variables etc. |
| 647 | $url_full = $match[1]; |
| 648 | $query = parse_url($url_full, PHP_URL_QUERY); |
| 649 | $query = $query ?? ''; // Ensure $query is a string |
| 650 | parse_str($query, $params); |
| 651 | // Handle `color` option. |
| 652 | if (!empty($options['color'])) { |
| 653 | $params['color'] = $options['color']; |
| 654 | } else { |
| 655 | unset($params['color']); |
| 656 | } |
| 657 | // Handle `rel` option. |
| 658 | if (isset($options['rel']) && in_array((int) $options['rel'], [0, 1])) { |
| 659 | $params['rel'] = (int) $options['rel']; |
| 660 | } else { |
| 661 | unset($params['rel']); |
| 662 | } |
| 663 | |
| 664 | // Handle `autoplay` option. |
| 665 | if (isset($options['autoplay']) && (bool) $options['autoplay'] === true) { |
| 666 | $params['autoplay'] = 1; |
| 667 | } else { |
| 668 | unset($params['autoplay']); |
| 669 | } |
| 670 | |
| 671 | // Handle `controls` option. |
| 672 | if (isset($options['controls']) && in_array((int) $options['controls'], [0, 1, 2])) { |
| 673 | $params['controls'] = (int) $options['controls']; |
| 674 | } else { |
| 675 | unset($params['controls']); |
| 676 | } |
| 677 | if (isset($options['start_time'])) { |
| 678 | $params['start'] = $options['start_time']; |
| 679 | } else { |
| 680 | unset($params['start']); |
| 681 | } |
| 682 | if (isset($options['end_time'])) { |
| 683 | $params['end'] = $options['end_time']; |
| 684 | } else { |
| 685 | unset($params['end']); |
| 686 | } |
| 687 | |
| 688 | // Handle `fs` option. |
| 689 | if (isset($options['fs']) && in_array((int) $options['fs'], [0, 1])) { |
| 690 | $params['fs'] = (int) $options['fs']; |
| 691 | } else { |
| 692 | unset($params['fs']); |
| 693 | } |
| 694 | |
| 695 | // Handle `iv_load_policy` option. |
| 696 | if (isset($options['iv_load_policy']) && in_array((int) $options['iv_load_policy'], [1, 3])) { |
| 697 | $params['iv_load_policy'] = (int) $options['iv_load_policy']; |
| 698 | } else { |
| 699 | unset($params['iv_load_policy']); |
| 700 | } |
| 701 | |
| 702 | // pro controls will be handled by the pro so remove it from the free. |
| 703 | $pro_controls = ['cc_load_policy', 'modestbranding']; |
| 704 | foreach ($pro_controls as $pro_control) { |
| 705 | if (isset($params[$pro_control])) { |
| 706 | unset($params[$pro_control]); |
| 707 | } |
| 708 | } |
| 709 | |
| 710 | |
| 711 | $url = explode('?', $url_full); |
| 712 | |
| 713 | if (isset($url[0])) { |
| 714 | $url = $url[0]; |
| 715 | } |
| 716 | |
| 717 | if (is_object($embed->attributes) && !empty($embed->attributes)) { |
| 718 | $attributes = (array) $embed->attributes; |
| 719 | |
| 720 | $params['controls'] = isset($attributes['data-controls']) ? $attributes['data-controls'] : '1'; |
| 721 | $params['iv_load_policy'] = !empty($attributes['data-videoannotations']) && ($attributes['data-videoannotations'] == 'true') ? 1 : 0; |
| 722 | $params['fs'] = !empty($attributes['data-fullscreen']) && ($attributes['data-fullscreen'] == 'true') ? 1 : 0; |
| 723 | $params['rel'] = !empty($attributes['data-relatedvideos']) && ($attributes['data-relatedvideos'] == 'true') ? 1 : 0; |
| 724 | $params['end'] = !empty($attributes['data-endtime']) ? $attributes['data-endtime'] : ''; |
| 725 | $params['autoplay'] = !empty($attributes['data-autoplay']) && ($attributes['data-autoplay'] == 'true') ? 1 : 0; |
| 726 | $params['mute'] = !empty($attributes['data-muteVideo']) && ($attributes['data-muteVideo'] == 'true') ? 1 : 0; |
| 727 | $params['start'] = !empty($attributes['data-starttime']) ? $attributes['data-starttime'] : ''; |
| 728 | $params['color'] = !empty($attributes['data-progressbarcolor']) ? $attributes['data-progressbarcolor'] : 'red'; |
| 729 | $params['modestbranding'] = empty($attributes['data-modestbranding']) ? 0 : 1; // Reverse the condition value for modestbranding. 0 = display, 1 = do not display |
| 730 | $params['cc_load_policy'] = !empty($attributes['data-closedcaptions']) && ($attributes['data-closedcaptions'] == 'true') ? 0 : 1; |
| 731 | $params['playsinline'] = '1'; |
| 732 | |
| 733 | } |
| 734 | |
| 735 | // Ensure $url is a string. If $url is an array, convert it to a string or use a specific element. |
| 736 | $url_string = is_array($url) ? (isset($url[0]) ? $url[0] : '') : $url; |
| 737 | |
| 738 | // Reassemble the URL with the new variables. |
| 739 | $url_modified = $url_string . '?'; |
| 740 | foreach ($params as $paramName => $paramValue) { |
| 741 | $url_modified .= urlencode($paramName) . '=' . urlencode($paramValue) . '&'; |
| 742 | } |
| 743 | |
| 744 | // Remove the trailing '&' or '?' if no parameters were added. |
| 745 | $url_modified = rtrim($url_modified, '&?'); |
| 746 | |
| 747 | |
| 748 | // Replaces the old url with the new one. |
| 749 | $embed->embed = str_replace($url_full, rtrim($url_modified, '&'), $embed->embed); |
| 750 | } |
| 751 | |
| 752 | return $embed; |
| 753 | } |
| 754 | |
| 755 | public function enhance_vimeo($embed) |
| 756 | { |
| 757 | |
| 758 | |
| 759 | if ( |
| 760 | isset($embed->provider_name) |
| 761 | && strtoupper($embed->provider_name) === 'VIMEO' |
| 762 | && isset($embed->embed) |
| 763 | && preg_match('/src=\"(.+?)\"/', $embed->embed, $match) |
| 764 | ) { |
| 765 | // old schema is for backward compatibility only @todo; remove it in the next version after deep test |
| 766 | $options = $this->getOptions('vimeo', $this->get_vimeo_settings_schema()); |
| 767 | |
| 768 | $url_full = $match[1]; |
| 769 | $params = []; |
| 770 | |
| 771 | // Handle `display_title` option. |
| 772 | if (isset($options['display_title']) && (bool) $options['display_title'] === true) { |
| 773 | $params['title'] = 1; |
| 774 | } else { |
| 775 | $params['title'] = 0; |
| 776 | } |
| 777 | |
| 778 | // Handle `autoplay` option. |
| 779 | if (isset($options['autoplay']) && (bool) $options['autoplay'] === true) { |
| 780 | $params['autoplay'] = 1; |
| 781 | } else { |
| 782 | unset($params['autoplay']); |
| 783 | } |
| 784 | |
| 785 | // Handle `color` option. |
| 786 | if (!empty($options['color'])) { |
| 787 | $params['color'] = str_replace('#', '', $options['color']); |
| 788 | } else { |
| 789 | unset($params['color']); |
| 790 | } |
| 791 | // Handle `display_author` option. |
| 792 | if (isset($options['display_author']) && (bool) $options['display_author'] === true) { |
| 793 | $params['byline'] = 1; |
| 794 | } else { |
| 795 | $params['byline'] = 0; |
| 796 | } |
| 797 | |
| 798 | // Handle `display_avatar` option. |
| 799 | if (isset($options['display_avatar']) && (bool) $options['display_avatar'] === true) { |
| 800 | $params['portrait'] = 1; |
| 801 | } else { |
| 802 | $params['portrait'] = 0; |
| 803 | } |
| 804 | |
| 805 | // NOTE: 'vimeo_dnt' is actually only 'dnt' in the params, so unset 'dnt' only |
| 806 | //@todo; maybe extract unsetting pro vars to a function later |
| 807 | $pro_controls = ['loop', 'autopause', 'dnt',]; |
| 808 | foreach ($pro_controls as $pro_control) { |
| 809 | if (isset($params[$pro_control])) { |
| 810 | unset($params[$pro_control]); |
| 811 | } |
| 812 | } |
| 813 | |
| 814 | if (!empty($params['autopause'])) { |
| 815 | unset($params['dnt']); |
| 816 | unset($params['amp;dnt']); |
| 817 | } |
| 818 | |
| 819 | // Reassemble the url with the new variables. |
| 820 | $url_modified = str_replace("&dnt=1", "", $url_full); |
| 821 | |
| 822 | if (is_object($embed->attributes) && !empty($embed->attributes)) { |
| 823 | $attributes = (array) $embed->attributes; |
| 824 | |
| 825 | $attributes = stringToBoolean($attributes); |
| 826 | |
| 827 | |
| 828 | $params['title'] = !empty($attributes['data-vtitle']) ? 1 : 0; |
| 829 | $params['byline'] = !empty($attributes['data-vauthor']) ? 1 : 0; |
| 830 | $params['portrait'] = !empty($attributes['data-vavatar']) ? 1 : 0; |
| 831 | $params['autoplay'] = !empty($attributes['data-vautoplay']) ? 1 : 0; |
| 832 | $params['loop'] = !empty($attributes['data-vloop']) ? 1 : 0; |
| 833 | $params['autopause'] = !empty($attributes['data-vautopause']) ? 1 : 0; |
| 834 | if (empty($attributes['data-vautopause'])) : |
| 835 | $params['dnt'] = !empty($attributes['data-vdnt']) ? 1 : 0; |
| 836 | endif; |
| 837 | $params['color'] = !empty($attributes['data-vscheme']) ? str_replace("#", "", $attributes['data-vscheme']) : '00ADEF'; |
| 838 | |
| 839 | if (!empty($attributes['data-vstarttime'])) : |
| 840 | $params['t'] = !empty($attributes['data-vstarttime']) ? $attributes['data-vstarttime'] : ''; |
| 841 | endif; |
| 842 | |
| 843 | foreach ($params as $param => $value) { |
| 844 | $url_modified = add_query_arg($param, $value, $url_modified); |
| 845 | } |
| 846 | |
| 847 | $url_modified = str_replace("&t=", "#t=", $url_modified); |
| 848 | } else { |
| 849 | foreach ($params as $param => $value) { |
| 850 | $url_modified = add_query_arg($param, $value, $url_modified); |
| 851 | } |
| 852 | |
| 853 | if (empty($attributes['data-vstarttime']) && isset($options['start_time'])) { |
| 854 | $start_time = sanitize_text_field($options['start_time']); |
| 855 | $url_modified .= '#t=' . $start_time; |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | do_action('embedpress_after_modified_url', $url_modified, $url_full, $params); |
| 860 | |
| 861 | // Replaces the old url with the new one. |
| 862 | $embed->embed = str_replace($url_full, $url_modified, $embed->embed); |
| 863 | } |
| 864 | |
| 865 | return $embed; |
| 866 | } |
| 867 | |
| 868 | public function enhance_wistia($embed) |
| 869 | { |
| 870 | |
| 871 | if ( |
| 872 | isset($embed->provider_name) |
| 873 | && strtoupper($embed->provider_name) === 'WISTIA, INC.' |
| 874 | && isset($embed->embed) |
| 875 | && preg_match('/src=\"(.+?)\"/', $embed->embed, $match) |
| 876 | ) { |
| 877 | $options = $this->getOptions('wistia', $this->get_wistia_settings_schema()); |
| 878 | |
| 879 | $url_full = $match[1]; |
| 880 | |
| 881 | // Parse the url to retrieve all its info like variables etc. |
| 882 | $query = parse_url($embed->url, PHP_URL_QUERY); |
| 883 | $url = str_replace('?' . $query, '', $url_full); |
| 884 | |
| 885 | if ($query !== null) { |
| 886 | parse_str($query, $params); |
| 887 | } |
| 888 | |
| 889 | // Set the class in the attributes |
| 890 | $embed->attributes->class = str_replace('{provider_alias}', 'wistia', $embed->attributes->class); |
| 891 | $embed->embed = str_replace('ose-wistia, inc.', 'ose-wistia', $embed->embed); |
| 892 | |
| 893 | |
| 894 | // Embed Options |
| 895 | $embedOptions = new \stdClass; |
| 896 | $embedOptions->videoFoam = false; |
| 897 | $embedOptions->fullscreenButton = (isset($options['display_fullscreen_button']) && (bool) $options['display_fullscreen_button'] === true); |
| 898 | $embedOptions->playbar = (isset($options['display_playbar']) && (bool) $options['display_playbar'] === true); |
| 899 | |
| 900 | $embedOptions->smallPlayButton = (isset($options['small_play_button']) && (bool) $options['small_play_button'] === true); |
| 901 | |
| 902 | $embedOptions->autoPlay = (isset($options['autoplay']) && (bool) $options['autoplay'] === true); |
| 903 | |
| 904 | if (!empty($options['start_time'])) { |
| 905 | // $embedOptions->time = isset($options['start_time']) ? $options['start_time'] : 0; |
| 906 | } |
| 907 | |
| 908 | if (isset($options['player_color'])) { |
| 909 | $color = $options['player_color']; |
| 910 | if (null !== $color) { |
| 911 | $embedOptions->playerColor = $color; |
| 912 | } |
| 913 | } |
| 914 | |
| 915 | // Plugins |
| 916 | $pluginsBaseURL = plugins_url('assets/js/wistia/min', dirname(__DIR__) . '/embedpress-Wistia.php'); |
| 917 | |
| 918 | $pluginList = array(); |
| 919 | |
| 920 | // Resumable |
| 921 | if (isset($options['plugin_resumable'])) { |
| 922 | $isResumableEnabled = $options['plugin_resumable']; |
| 923 | if ($isResumableEnabled) { |
| 924 | // Add the resumable plugin |
| 925 | $pluginList['resumable'] = array( |
| 926 | 'src' => $pluginsBaseURL . '/resumable.min.js', |
| 927 | 'async' => false |
| 928 | ); |
| 929 | } |
| 930 | } |
| 931 | |
| 932 | // Add a fix for the autoplay and resumable work better together |
| 933 | if (isset($options->autoPlay)) { |
| 934 | if ($isResumableEnabled) { |
| 935 | $pluginList['fixautoplayresumable'] = array( |
| 936 | 'src' => $pluginsBaseURL . '/fixautoplayresumable.min.js' |
| 937 | ); |
| 938 | } |
| 939 | } |
| 940 | |
| 941 | // Focus plugin |
| 942 | if (isset($options['plugin_focus'])) { |
| 943 | $isFocusEnabled = $options['plugin_focus']; |
| 944 | $pluginList['dimthelights'] = array( |
| 945 | 'src' => $pluginsBaseURL . '/dimthelights.min.js', |
| 946 | 'autoDim' => $isFocusEnabled |
| 947 | ); |
| 948 | $embedOptions->focus = $isFocusEnabled; |
| 949 | } |
| 950 | |
| 951 | // Rewind plugin |
| 952 | if (isset($options['plugin_rewind'])) { |
| 953 | if ($options['plugin_rewind']) { |
| 954 | $embedOptions->rewindTime = isset($options['plugin_rewind_time']) ? (int) $options['plugin_rewind_time'] : 10; |
| 955 | |
| 956 | $pluginList['rewind'] = array( |
| 957 | 'src' => $pluginsBaseURL . '/rewind.min.js' |
| 958 | ); |
| 959 | } |
| 960 | } |
| 961 | $embedOptions->plugin = $pluginList; |
| 962 | |
| 963 | $embedOptions = json_encode($embedOptions); |
| 964 | |
| 965 | // Get the video ID |
| 966 | $videoId = $this->getVideoIDFromURL($embed->url); |
| 967 | $shortVideoId = substr($videoId, 0, 3); |
| 968 | |
| 969 | // Responsive? |
| 970 | |
| 971 | $class = array( |
| 972 | 'wistia_embed', |
| 973 | 'wistia_async_' . $videoId |
| 974 | ); |
| 975 | |
| 976 | $attribs = array( |
| 977 | sprintf('id="wistia_%s"', $videoId), |
| 978 | sprintf('class="%s"', join(' ', $class)), |
| 979 | sprintf('style="width:%spx; height:%spx;"', $embed->width, $embed->height) |
| 980 | ); |
| 981 | |
| 982 | $labels = array( |
| 983 | 'watch_from_beginning' => __('Watch from the beginning', 'embedpress'), |
| 984 | 'skip_to_where_you_left_off' => __('Skip to where you left off', 'embedpress'), |
| 985 | 'you_have_watched_it_before' => __( |
| 986 | 'It looks like you\'ve watched<br />part of this video before!', |
| 987 | 'embedpress' |
| 988 | ), |
| 989 | ); |
| 990 | $labels = json_encode($labels); |
| 991 | |
| 992 | preg_match('/ose-uid-([a-z0-9]*)/', $embed->embed, $matches); |
| 993 | $uid = $matches[1]; |
| 994 | |
| 995 | $html = "<div class=\"embedpress-wrapper ose-wistia ose-uid-{$uid} responsive\">"; |
| 996 | $html .= '<script src="https://fast.wistia.com/assets/external/E-v1.js" async></script>'; |
| 997 | $html .= "<script>window.pp_embed_wistia_labels = {$labels};</script>\n"; |
| 998 | $html .= "<script>window._wq = window._wq || []; _wq.push({\"{$shortVideoId}\": {$embedOptions}});</script>\n"; |
| 999 | $html .= '<div ' . join(' ', $attribs) . "></div>\n"; |
| 1000 | $html .= '</div>'; |
| 1001 | $embed->embed = $html; |
| 1002 | } |
| 1003 | |
| 1004 | return $embed; |
| 1005 | } |
| 1006 | |
| 1007 | public function enhance_twitch($embed_content) |
| 1008 | { |
| 1009 | $e = isset($embed_content->url) && isset($embed_content->{$embed_content->url}) ? $embed_content->{$embed_content->url} : []; |
| 1010 | if (isset($e['provider_name']) && strtoupper($e['provider_name']) === 'TWITCH' && isset($embed_content->embed)) { |
| 1011 | $settings = $this->getOptions('twitch', $this->get_twitch_settings_schema()); |
| 1012 | |
| 1013 | $atts = isset($embed_content->attributes) ? $embed_content->attributes : []; |
| 1014 | $time = '0h0m0s'; |
| 1015 | $type = $e['type']; |
| 1016 | $content_id = $e['content_id']; |
| 1017 | $channel = 'channel' === $type ? $content_id : ''; |
| 1018 | $video = 'video' === $type ? $content_id : ''; |
| 1019 | $muted = isset($settings['embedpress_pro_twitch_mute']) && ('yes' === $settings['embedpress_pro_twitch_mute']) ? 'true' : 'false'; |
| 1020 | $full_screen = isset($settings['embedpress_pro_fs']) && ('yes' === $settings['embedpress_pro_fs']) ? 'true' : 'false'; |
| 1021 | $autoplay = isset($settings['embedpress_pro_twitch_autoplay']) && ('yes' === $settings['embedpress_pro_twitch_autoplay']) ? 'true' : 'false'; |
| 1022 | $theme = !empty($settings['embedpress_pro_twitch_theme']) ? esc_attr($settings['embedpress_pro_twitch_theme']) : 'dark'; |
| 1023 | |
| 1024 | $layout = 'video'; |
| 1025 | $width = !empty($atts->{'data-width'}) ? (int) $atts->{'data-width'} : 800; |
| 1026 | $height = !empty($atts->{'data-height'}) ? (int) $atts->{'data-height'} : 450; |
| 1027 | if (!empty($settings['start_time'])) { |
| 1028 | $ta = explode(':', gmdate("G:i:s", $settings['start_time'])); |
| 1029 | $h = $ta[0] . 'h'; |
| 1030 | $m = ($ta[1] * 1) . 'm'; |
| 1031 | $s = ($ta[2] * 1) . 's'; |
| 1032 | $time = $h . $m . $s; |
| 1033 | } |
| 1034 | $url = "https://embed.twitch.tv?autoplay={$autoplay}&channel={$channel}&height={$height}&layout={$layout}&migration=true&muted={$muted}&theme={$theme}&time={$time}&video={$video}&width={$width}&allowfullscreen={$full_screen}"; |
| 1035 | $pars_url = wp_parse_url(get_site_url()); |
| 1036 | $url = !empty($pars_url['host']) ? $url . '&parent=' . $pars_url['host'] : $url; |
| 1037 | ob_start(); |
| 1038 | ?> |
| 1039 | <div class="embedpress_wrapper" data-url="<?php echo esc_url($embed_content->url); ?>"> |
| 1040 | <iframe src="<?php echo esc_url($url); ?>" allowfullscreen="" scrolling="no" frameborder="0" allow="autoplay; fullscreen" title="Twitch" sandbox="allow-modals allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox" width="<?php echo esc_attr($width); ?>" height="<?php echo esc_attr($height); ?>" style="max-width: <?php echo esc_attr($width); ?>px; max-height:<?php echo esc_attr($height); ?>px;"></iframe> |
| 1041 | </div> |
| 1042 | <?php |
| 1043 | $c = ob_get_clean(); |
| 1044 | $embed_content->embed = $c; |
| 1045 | } |
| 1046 | |
| 1047 | return $embed_content; |
| 1048 | } |
| 1049 | public function enhance_dailymotion($embed) |
| 1050 | { |
| 1051 | $options = $this->getOptions('dailymotion', $this->get_dailymotion_settings_schema()); |
| 1052 | $isDailymotion = (isset($embed->provider_name) && strtoupper($embed->provider_name) === 'DAILYMOTION') || (isset($embed->url) && isset($embed->{$embed->url}) && isset($embed->{$embed->url}['provider_name']) && strtoupper($embed->{$embed->url}['provider_name']) === 'DAILYMOTION'); |
| 1053 | |
| 1054 | if ( |
| 1055 | $isDailymotion && isset($embed->embed) |
| 1056 | && preg_match('/src=\"(.+?)\"/', $embed->embed, $match) |
| 1057 | ) { |
| 1058 | // Parse the url to retrieve all its info like variables etc. |
| 1059 | $url_full = $match[1]; |
| 1060 | $params = [ |
| 1061 | 'ui-highlight' => str_replace('#', '', isset($options['color']) ? $options['color'] : null), |
| 1062 | 'mute' => (int) isset($options['mute']) ? $options['mute'] : null, |
| 1063 | 'autoplay' => (int) isset($options['autoplay']) ? $options['autoplay'] : null, |
| 1064 | 'controls' => (int) isset($options['controls']) ? $options['controls'] : null, |
| 1065 | 'ui-start-screen-info' => (int) isset($options['video_info']) ? $options['video_info'] : null, |
| 1066 | 'endscreen-enable' => 0, |
| 1067 | ]; |
| 1068 | |
| 1069 | if (isset($options['play_on_mobile']) && $options['play_on_mobile'] == '1') { |
| 1070 | $params['playsinline'] = 1; |
| 1071 | } |
| 1072 | $params['start'] = (int) isset($options['start_time']) ? $options['start_time'] : null; |
| 1073 | |
| 1074 | $params = apply_filters('embedpress_enhance_dailymotion', $params, $options); |
| 1075 | |
| 1076 | |
| 1077 | $url_modified = $url_full; |
| 1078 | foreach ($params as $param => $value) { |
| 1079 | $url_modified = add_query_arg($param, $value, $url_modified); |
| 1080 | } |
| 1081 | $embed->embed = str_replace($url_full, $url_modified, $embed->embed); |
| 1082 | } |
| 1083 | |
| 1084 | return $embed; |
| 1085 | } |
| 1086 | public function enhance_soundcloud($embed) |
| 1087 | { |
| 1088 | |
| 1089 | $isSoundcloud = (isset($embed->provider_name) && strtoupper($embed->provider_name) === 'SOUNDCLOUD') || (isset($embed->url) && isset($embed->{$embed->url}) && isset($embed->{$embed->url}['provider_name']) && strtoupper($embed->{$embed->url}['provider_name']) === 'SOUNDCLOUD'); |
| 1090 | |
| 1091 | if ( |
| 1092 | $isSoundcloud && isset($embed->embed) |
| 1093 | && preg_match('/src=\"(.+?)\"/', $embed->embed, $match) |
| 1094 | ) { |
| 1095 | $options = $this->getOptions('soundcloud', $this->get_soundcloud_settings_schema()); |
| 1096 | // Parse the url to retrieve all its info like variables etc. |
| 1097 | $url_full = $match[1]; |
| 1098 | $params = [ |
| 1099 | 'color' => str_replace('#', '', $options['color']), |
| 1100 | 'visual' => isset($options['visual']) && $options['visual'] == '1' ? 'true' : 'false', |
| 1101 | 'auto_play' => isset($options['autoplay']) && $options['autoplay'] == '1' ? 'true' : 'false', |
| 1102 | 'sharing' => isset($options['share_button']) && $options['share_button'] == '1' ? 'true' : 'false', |
| 1103 | 'show_comments' => isset($options['comments']) && $options['comments'] == '1' ? 'true' : 'false', |
| 1104 | 'buying' => 'false', |
| 1105 | 'download' => 'false', |
| 1106 | 'show_artwork' => isset($options['artwork']) && $options['artwork'] == '1' ? 'true' : 'false', |
| 1107 | 'show_playcount' => isset($options['play_count']) && $options['play_count'] == '1' ? 'true' : 'false', |
| 1108 | 'show_user' => isset($options['username']) && $options['username'] == '1' ? 'true' : 'false', |
| 1109 | ]; |
| 1110 | |
| 1111 | $params = apply_filters('embedpress_enhance_soundcloud', $params, $options); |
| 1112 | |
| 1113 | $url_modified = $url_full; |
| 1114 | foreach ($params as $param => $value) { |
| 1115 | $url_modified = add_query_arg($param, $value, $url_modified); |
| 1116 | } |
| 1117 | |
| 1118 | // Replaces the old url with the new one. |
| 1119 | $embed->embed = str_replace($url_full, $url_modified, $embed->embed); |
| 1120 | if ('false' === $params['visual']) { |
| 1121 | $embed->embed = str_replace('height="400"', 'height="200 !important"', $embed->embed); |
| 1122 | } |
| 1123 | } |
| 1124 | |
| 1125 | return $embed; |
| 1126 | } |
| 1127 | public function embedpress_gutenberg_register_block_youtube($youtube_params) |
| 1128 | { |
| 1129 | $youtube_options = $this->getOptions('youtube', $this->get_youtube_settings_schema()); |
| 1130 | return $this->get_youtube_params($youtube_options); |
| 1131 | } |
| 1132 | public function embedpress_gutenberg_register_block_vimeo() |
| 1133 | { |
| 1134 | if (function_exists('register_block_type')) : |
| 1135 | register_block_type('embedpress/vimeo-block', array( |
| 1136 | 'attributes' => array( |
| 1137 | 'url' => array( |
| 1138 | 'type' => 'string', |
| 1139 | 'default' => '' |
| 1140 | ), |
| 1141 | 'iframeSrc' => array( |
| 1142 | 'type' => 'string', |
| 1143 | 'default' => '' |
| 1144 | ), |
| 1145 | ), |
| 1146 | 'render_callback' => [$this, 'embedpress_gutenberg_render_block_vimeo'] |
| 1147 | )); |
| 1148 | endif; |
| 1149 | } |
| 1150 | public function embedpress_gutenberg_render_block_vimeo($attributes) |
| 1151 | { |
| 1152 | ob_start(); |
| 1153 | if (!empty($attributes) && !empty($attributes['iframeSrc'])) : |
| 1154 | $vimeo_options = $this->getOptions('vimeo', $this->get_vimeo_settings_schema()); |
| 1155 | $vimeo_params = $this->get_vimeo_params($vimeo_options); |
| 1156 | $iframeUrl = $attributes['iframeSrc']; |
| 1157 | $align = 'align' . (isset($attributes['align']) ? $attributes['align'] : 'center'); |
| 1158 | foreach ($vimeo_params as $param => $value) { |
| 1159 | $iframeUrl = add_query_arg($param, $value, $iframeUrl); |
| 1160 | } |
| 1161 | //@TODO; test responsive without static height width, keeping for now backward compatibility |
| 1162 | ?> |
| 1163 | <div class="ose-vimeo wp-block-embed-vimeo <?php echo esc_attr($align); ?>"> |
| 1164 | <iframe src="<?php echo esc_url($iframeUrl); ?>" allowtransparency="true" frameborder="0" width="640" height="360"> |
| 1165 | </iframe> |
| 1166 | </div> |
| 1167 | <?php |
| 1168 | endif; |
| 1169 | |
| 1170 | return apply_filters('embedpress_gutenberg_block_markup', ob_get_clean()); |
| 1171 | } |
| 1172 | public function get_youtube_settings_schema() |
| 1173 | { |
| 1174 | return [ |
| 1175 | 'autoplay' => [ |
| 1176 | 'type' => 'bool', |
| 1177 | 'default' => false |
| 1178 | ], |
| 1179 | 'color' => [ |
| 1180 | 'type' => 'string', |
| 1181 | 'default' => 'red' |
| 1182 | ], |
| 1183 | 'cc_load_policy' => [ |
| 1184 | 'type' => 'bool', |
| 1185 | 'default' => false |
| 1186 | ], |
| 1187 | 'controls' => [ |
| 1188 | 'type' => 'string', |
| 1189 | 'default' => '1' |
| 1190 | ], |
| 1191 | 'fs' => [ |
| 1192 | 'type' => 'bool', |
| 1193 | 'default' => true |
| 1194 | ], |
| 1195 | 'iv_load_policy' => [ |
| 1196 | 'type' => 'radio', |
| 1197 | 'default' => '1' |
| 1198 | ], |
| 1199 | 'rel' => [ |
| 1200 | 'type' => 'bool', |
| 1201 | 'default' => true |
| 1202 | ], |
| 1203 | 'modestbranding' => [ |
| 1204 | 'type' => 'string', |
| 1205 | 'default' => '0' |
| 1206 | ], |
| 1207 | 'logo_url' => [ |
| 1208 | 'type' => 'url', |
| 1209 | ], |
| 1210 | 'logo_xpos' => [ |
| 1211 | 'type' => 'number', |
| 1212 | 'default' => 10 |
| 1213 | ], |
| 1214 | 'logo_ypos' => [ |
| 1215 | 'type' => 'number', |
| 1216 | 'default' => 10 |
| 1217 | ], |
| 1218 | 'cta_url' => [ |
| 1219 | 'type' => 'url', |
| 1220 | ], |
| 1221 | 'start_time' => [ |
| 1222 | 'type' => 'number', |
| 1223 | 'default' => 10 |
| 1224 | ], |
| 1225 | 'end_time' => [ |
| 1226 | 'type' => 'number', |
| 1227 | 'default' => 10 |
| 1228 | ], |
| 1229 | ]; |
| 1230 | } |
| 1231 | public function get_vimeo_settings_schema() |
| 1232 | { |
| 1233 | return array( |
| 1234 | 'start_time' => [ |
| 1235 | 'type' => 'number', |
| 1236 | 'default' => 10 |
| 1237 | ], |
| 1238 | 'autoplay' => array( |
| 1239 | 'type' => 'bool', |
| 1240 | 'default' => false |
| 1241 | ), |
| 1242 | 'loop' => array( |
| 1243 | 'type' => 'bool', |
| 1244 | 'default' => false |
| 1245 | ), |
| 1246 | 'autopause' => array( |
| 1247 | 'type' => 'bool', |
| 1248 | 'default' => false |
| 1249 | ), |
| 1250 | 'vimeo_dnt' => array( |
| 1251 | 'type' => 'bool', |
| 1252 | 'default' => true, |
| 1253 | ), |
| 1254 | 'color' => array( |
| 1255 | 'type' => 'text', |
| 1256 | 'default' => '#00adef', |
| 1257 | 'classes' => 'color-field' |
| 1258 | ), |
| 1259 | 'display_title' => array( |
| 1260 | 'type' => 'bool', |
| 1261 | 'default' => true |
| 1262 | ), |
| 1263 | 'display_author' => array( |
| 1264 | 'type' => 'bool', |
| 1265 | 'default' => true |
| 1266 | ), |
| 1267 | 'display_avatar' => array( |
| 1268 | 'type' => 'bool', |
| 1269 | 'default' => true |
| 1270 | ) |
| 1271 | ); |
| 1272 | } |
| 1273 | public function get_wistia_settings_schema() |
| 1274 | { |
| 1275 | return array( |
| 1276 | 'start_time' => [ |
| 1277 | 'type' => 'number', |
| 1278 | 'default' => 0 |
| 1279 | ], |
| 1280 | 'display_fullscreen_button' => array( |
| 1281 | 'type' => 'bool', |
| 1282 | 'default' => true |
| 1283 | ), |
| 1284 | 'display_playbar' => array( |
| 1285 | 'type' => 'bool', |
| 1286 | 'default' => true |
| 1287 | ), |
| 1288 | 'small_play_button' => array( |
| 1289 | 'type' => 'bool', |
| 1290 | 'default' => true |
| 1291 | ), |
| 1292 | 'display_volume_control' => array( |
| 1293 | 'type' => 'bool', |
| 1294 | 'default' => true |
| 1295 | ), |
| 1296 | 'autoplay' => array( |
| 1297 | 'type' => 'bool', |
| 1298 | 'default' => false |
| 1299 | ), |
| 1300 | 'volume' => array( |
| 1301 | 'type' => 'text', |
| 1302 | 'default' => '100' |
| 1303 | ), |
| 1304 | 'player_color' => array( |
| 1305 | 'type' => 'text', |
| 1306 | 'default' => '#00adef', |
| 1307 | ), |
| 1308 | 'plugin_resumable' => array( |
| 1309 | 'type' => 'bool', |
| 1310 | 'default' => false |
| 1311 | ), |
| 1312 | 'plugin_captions' => array( |
| 1313 | 'type' => 'bool', |
| 1314 | 'default' => false |
| 1315 | ), |
| 1316 | 'plugin_captions_default' => array( |
| 1317 | 'type' => 'bool', |
| 1318 | 'default' => false |
| 1319 | ), |
| 1320 | 'plugin_focus' => array( |
| 1321 | 'type' => 'bool', |
| 1322 | 'default' => false |
| 1323 | ), |
| 1324 | 'plugin_rewind' => array( |
| 1325 | 'type' => 'bool', |
| 1326 | 'default' => false |
| 1327 | ), |
| 1328 | 'plugin_rewind_time' => array( |
| 1329 | 'type' => 'text', |
| 1330 | 'default' => '10' |
| 1331 | ), |
| 1332 | ); |
| 1333 | } |
| 1334 | |
| 1335 | |
| 1336 | public function getVideoIDFromURL($url) |
| 1337 | { |
| 1338 | // https://fast.wistia.com/embed/medias/xf1edjzn92.jsonp |
| 1339 | // https://ostraining-1.wistia.com/medias/xf1edjzn92 |
| 1340 | preg_match('#\/medias\\\?\/([a-z0-9]+)\.?#i', $url, $matches); |
| 1341 | |
| 1342 | $id = false; |
| 1343 | if (isset($matches[1])) { |
| 1344 | $id = $matches[1]; |
| 1345 | } |
| 1346 | |
| 1347 | return $id; |
| 1348 | } |
| 1349 | public function embedpress_wistia_block_after_embed($attributes) |
| 1350 | { |
| 1351 | $embedOptions = $this->embedpress_wistia_pro_get_options(); |
| 1352 | // Get the video ID |
| 1353 | $videoId = $this->getVideoIDFromURL($attributes['url']); |
| 1354 | $shortVideoId = $videoId; |
| 1355 | |
| 1356 | $labels = array( |
| 1357 | 'watch_from_beginning' => __('Watch from the beginning', 'embedpress'), |
| 1358 | 'skip_to_where_you_left_off' => __('Skip to where you left off', 'embedpress'), |
| 1359 | 'you_have_watched_it_before' => __('It looks like you\'ve watched<br />part of this video before!', 'embedpress'), |
| 1360 | ); |
| 1361 | $labels = json_encode($labels); |
| 1362 | |
| 1363 | |
| 1364 | $html = '<script src="https://fast.wistia.com/assets/external/E-v1.js"></script>'; |
| 1365 | $html .= "<script>window.pp_embed_wistia_labels = {$labels};</script>\n"; |
| 1366 | $html .= "<script>wistiaEmbed = Wistia.embed( \"{$shortVideoId}\", {$embedOptions} );</script>\n"; |
| 1367 | |
| 1368 | |
| 1369 | |
| 1370 | echo $html; |
| 1371 | } |
| 1372 | public function embedpress_wistia_pro_get_options() |
| 1373 | { |
| 1374 | $options = $this->getOptions('wistia', $this->get_wistia_settings_schema()); |
| 1375 | // Embed Options |
| 1376 | $embedOptions = new \stdClass; |
| 1377 | // $embedOptions->videoFoam = true; |
| 1378 | $embedOptions->fullscreenButton = (isset($options['display_fullscreen_button']) && (bool) $options['display_fullscreen_button'] === true); |
| 1379 | $embedOptions->smallPlayButton = (isset($options['small_play_button']) && (bool) $options['small_play_button'] === true); |
| 1380 | $embedOptions->autoPlay = (isset($options['autoplay']) && (bool) $options['autoplay'] === true); |
| 1381 | |
| 1382 | if (isset($options['player_color'])) { |
| 1383 | $color = $options['player_color']; |
| 1384 | if (null !== $color) { |
| 1385 | $embedOptions->playerColor = $color; |
| 1386 | } |
| 1387 | } |
| 1388 | |
| 1389 | // Plugins |
| 1390 | $pluginsBaseURL = plugins_url('assets/js/wistia/min', dirname(__DIR__) . '/embedpress-Wistia.php'); |
| 1391 | |
| 1392 | $pluginList = array(); |
| 1393 | |
| 1394 | // Resumable |
| 1395 | if (isset($options['plugin_resumable'])) { |
| 1396 | $isResumableEnabled = $options['plugin_resumable']; |
| 1397 | if ($isResumableEnabled) { |
| 1398 | // Add the resumable plugin |
| 1399 | $pluginList['resumable'] = array( |
| 1400 | 'src' => '//fast.wistia.com/labs/resumable/plugin.js', |
| 1401 | 'async' => false |
| 1402 | ); |
| 1403 | } |
| 1404 | } |
| 1405 | // Add a fix for the autoplay and resumable work better together |
| 1406 | //@TODO; check baseurl deeply, not looking good |
| 1407 | if ($options['autoplay']) { |
| 1408 | if ($isResumableEnabled) { |
| 1409 | $pluginList['fixautoplayresumable'] = array( |
| 1410 | 'src' => $pluginsBaseURL . '/fixautoplayresumable.min.js' |
| 1411 | ); |
| 1412 | } |
| 1413 | } |
| 1414 | |
| 1415 | |
| 1416 | // Focus plugin |
| 1417 | if (isset($options['plugin_focus'])) { |
| 1418 | $isFocusEnabled = $options['plugin_focus']; |
| 1419 | $pluginList['dimthelights'] = array( |
| 1420 | 'src' => '//fast.wistia.com/labs/dim-the-lights/plugin.js', |
| 1421 | 'autoDim' => $isFocusEnabled |
| 1422 | ); |
| 1423 | $embedOptions->focus = $isFocusEnabled; |
| 1424 | } |
| 1425 | |
| 1426 | $embedOptions->plugin = $pluginList; |
| 1427 | $embedOptions = apply_filters('embedpress_wistia_params', $embedOptions); |
| 1428 | $embedOptions = json_encode($embedOptions); |
| 1429 | return apply_filters('embedpress_wistia_params_after_encode', $embedOptions); |
| 1430 | } |
| 1431 | |
| 1432 | |
| 1433 | public function get_twitch_settings_schema() |
| 1434 | { |
| 1435 | return [ |
| 1436 | 'start_time' => [ |
| 1437 | 'type' => 'number', |
| 1438 | 'default' => 0, |
| 1439 | ], |
| 1440 | 'embedpress_pro_twitch_autoplay' => [ |
| 1441 | 'type' => 'string', |
| 1442 | 'default' => 'no', |
| 1443 | ], |
| 1444 | 'embedpress_pro_twitch_chat' => [ |
| 1445 | 'type' => 'string', |
| 1446 | 'default' => 'no', |
| 1447 | ], |
| 1448 | |
| 1449 | 'embedpress_pro_twitch_theme' => [ |
| 1450 | 'type' => 'string', |
| 1451 | 'default' => 'dark', |
| 1452 | ], |
| 1453 | 'embedpress_pro_fs' => [ |
| 1454 | 'type' => 'string', |
| 1455 | 'default' => 'yes', |
| 1456 | ], |
| 1457 | 'embedpress_pro_twitch_mute' => [ |
| 1458 | 'type' => 'string', |
| 1459 | 'default' => 'yes', |
| 1460 | ], |
| 1461 | |
| 1462 | ]; |
| 1463 | } |
| 1464 | public function get_dailymotion_settings_schema() |
| 1465 | { |
| 1466 | return [ |
| 1467 | 'autoplay' => [ |
| 1468 | 'type' => 'string', |
| 1469 | 'default' => '' |
| 1470 | ], |
| 1471 | 'play_on_mobile' => [ |
| 1472 | 'type' => 'string', |
| 1473 | 'default' => '' |
| 1474 | ], |
| 1475 | 'color' => [ |
| 1476 | 'type' => 'string', |
| 1477 | 'default' => '#dd3333' |
| 1478 | ], |
| 1479 | 'mute' => [ |
| 1480 | 'type' => 'string', |
| 1481 | 'default' => '' |
| 1482 | ], |
| 1483 | 'controls' => [ |
| 1484 | 'type' => 'string', |
| 1485 | 'default' => '1' |
| 1486 | ], |
| 1487 | 'video_info' => [ |
| 1488 | 'type' => 'string', |
| 1489 | 'default' => '1' |
| 1490 | ], |
| 1491 | 'show_logo' => [ |
| 1492 | 'type' => 'string', |
| 1493 | 'default' => '1' |
| 1494 | ], |
| 1495 | 'start_time' => [ |
| 1496 | 'type' => 'string', |
| 1497 | 'default' => '0' |
| 1498 | ], |
| 1499 | ]; |
| 1500 | } |
| 1501 | public function get_soundcloud_settings_schema() |
| 1502 | { |
| 1503 | return [ |
| 1504 | 'visual' => [ |
| 1505 | 'type' => 'string', |
| 1506 | 'default' => '' |
| 1507 | ], |
| 1508 | 'autoplay' => [ |
| 1509 | 'type' => 'string', |
| 1510 | 'default' => '' |
| 1511 | ], |
| 1512 | 'play_on_mobile' => [ |
| 1513 | 'type' => 'string', |
| 1514 | 'default' => '' |
| 1515 | ], |
| 1516 | 'color' => [ |
| 1517 | 'type' => 'string', |
| 1518 | 'default' => '#dd3333' |
| 1519 | ], |
| 1520 | |
| 1521 | 'share_button' => [ |
| 1522 | 'type' => 'string', |
| 1523 | 'default' => '' |
| 1524 | ], |
| 1525 | 'comments' => [ |
| 1526 | 'type' => 'string', |
| 1527 | 'default' => '1' |
| 1528 | ], |
| 1529 | 'artwork' => [ |
| 1530 | 'type' => 'string', |
| 1531 | 'default' => '' |
| 1532 | ], |
| 1533 | 'play_count' => [ |
| 1534 | 'type' => 'string', |
| 1535 | 'default' => '1' |
| 1536 | ], |
| 1537 | 'username' => [ |
| 1538 | 'type' => 'string', |
| 1539 | 'default' => '1' |
| 1540 | ], |
| 1541 | 'download_button' => [ |
| 1542 | 'type' => 'string', |
| 1543 | 'default' => '1' |
| 1544 | ], |
| 1545 | 'buy_button' => [ |
| 1546 | 'type' => 'string', |
| 1547 | 'default' => '1' |
| 1548 | ], |
| 1549 | ]; |
| 1550 | } |
| 1551 | |
| 1552 | public function enhance_missing_title($embed) |
| 1553 | { |
| 1554 | |
| 1555 | $embed_arr = get_object_vars($embed); |
| 1556 | |
| 1557 | $url = $embed->url; |
| 1558 | |
| 1559 | if (strpos($url, 'gettyimages') !== false) { |
| 1560 | $title = $embed_arr[$url]['title']; |
| 1561 | $embed->embed = $embed->embed . " |
| 1562 | <script> |
| 1563 | if (typeof gie === 'function') { |
| 1564 | gie(function(){ |
| 1565 | var iframe = document.querySelector('.ose-embedpress-responsive iframe'); |
| 1566 | if(iframe && !iframe.getAttribute('title')){ |
| 1567 | iframe.setAttribute('title', '$title') |
| 1568 | } |
| 1569 | }); |
| 1570 | } |
| 1571 | </script> |
| 1572 | "; |
| 1573 | } |
| 1574 | |
| 1575 | |
| 1576 | return $embed; |
| 1577 | } |
| 1578 | |
| 1579 | |
| 1580 | public function embedpress_generate_social_share_meta() |
| 1581 | { |
| 1582 | $post_id = get_the_ID(); |
| 1583 | $post = get_post($post_id); |
| 1584 | $tags = ''; |
| 1585 | |
| 1586 | $thumbnail_url = get_the_post_thumbnail_url($post_id); |
| 1587 | |
| 1588 | if (!empty($_GET['hash'])) { |
| 1589 | |
| 1590 | $id_value = sanitize_text_field($_GET['hash']); |
| 1591 | $unique_hash = !empty($_GET['unique']) ? sanitize_text_field($_GET['unique']) : ''; |
| 1592 | |
| 1593 | $url = get_the_permalink($post_id); |
| 1594 | |
| 1595 | if (class_exists('Elementor\Plugin') && \Elementor\Plugin::$instance->documents->get(get_the_ID())->is_built_with_elementor()) { |
| 1596 | |
| 1597 | $page_settings = get_post_meta($post_id, '_elementor_data', true); |
| 1598 | |
| 1599 | $ep_settings = Helper::ep_get_elementor_widget_settings($page_settings, $id_value, 'embedpres_elementor'); |
| 1600 | $pdf_settings = Helper::ep_get_elementor_widget_settings($page_settings, $id_value, 'embedpress_pdf'); |
| 1601 | $doc_settings = Helper::ep_get_elementor_widget_settings($page_settings, $id_value, 'embedpres_document'); |
| 1602 | |
| 1603 | if (is_array($ep_settings) && !empty($ep_settings)) { |
| 1604 | $title = !empty($ep_settings[0]['embedpress_content_title']) ? $ep_settings[0]['embedpress_content_title'] : ''; |
| 1605 | |
| 1606 | $description = !empty($ep_settings[0]['embedpress_content_descripiton']) ? $ep_settings[0]['embedpress_content_descripiton'] : ''; |
| 1607 | |
| 1608 | $image_url = !empty($ep_settings[0]['embedpress_content_share_custom_thumbnail']['url']) ? $ep_settings[0]['embedpress_content_share_custom_thumbnail']['url'] : ''; |
| 1609 | } else if (is_array($pdf_settings) && !empty($pdf_settings)) { |
| 1610 | $title = !empty($pdf_settings[0]['embedpress_pdf_content_title']) ? $pdf_settings[0]['embedpress_pdf_content_title'] : ''; |
| 1611 | |
| 1612 | $description = !empty($pdf_settings[0]['embedpress_pdf_content_descripiton']) ? $pdf_settings[0]['embedpress_pdf_content_descripiton'] : ''; |
| 1613 | |
| 1614 | $image_url = !empty($pdf_settings[0]['embedpress_pdf_content_share_custom_thumbnail']['url']) ? $pdf_settings[0]['embedpress_pdf_content_share_custom_thumbnail']['url'] : ''; |
| 1615 | } else if (is_array($doc_settings) && !empty($doc_settings)) { |
| 1616 | $title = !empty($doc_settings[0]['embedpress_doc_content_title']) ? $doc_settings[0]['embedpress_doc_content_title'] : ''; |
| 1617 | |
| 1618 | $description = !empty($doc_settings[0]['embedpress_doc_content_descripiton']) ? $doc_settings[0]['embedpress_doc_content_descripiton'] : ''; |
| 1619 | |
| 1620 | $image_url = !empty($doc_settings[0]['embedpress_doc_content_share_custom_thumbnail']['url']) ? $doc_settings[0]['embedpress_doc_content_share_custom_thumbnail']['url'] : ''; |
| 1621 | } |
| 1622 | |
| 1623 | if (!empty($image_url)) { |
| 1624 | $tags .= "<meta name='twitter:image' content='" . esc_url($image_url) . "'/>\n"; |
| 1625 | $tags .= "<meta property='og:image' content='" . esc_url($image_url) . "'/>\n"; |
| 1626 | } else if (!empty($thumbnail_url)) { |
| 1627 | $tags .= "<meta name='twitter:image' content='" . esc_url($thumbnail_url) . "'/>\n"; |
| 1628 | $tags .= "<meta property='og:image' content='" . esc_url($thumbnail_url) . "'/>\n"; |
| 1629 | } |
| 1630 | |
| 1631 | if (!empty($title)) { |
| 1632 | $title = json_decode('"' . $title . '"', JSON_UNESCAPED_UNICODE); |
| 1633 | $tags .= "<meta property='og:title' content='" . esc_attr($title) . "'/>\n"; |
| 1634 | $tags .= "<meta name='title' content='" . esc_attr($title) . "'>\n"; |
| 1635 | $tags .= "<meta name='twitter:title' content='" . esc_attr($title) . "'/>\n"; |
| 1636 | |
| 1637 | } |
| 1638 | |
| 1639 | if (!empty($description)) { |
| 1640 | $description = json_decode('"' . $description . '"', JSON_UNESCAPED_UNICODE); |
| 1641 | $tags .= "<meta property='og:description' content='" . esc_attr($description) . "'/>\n"; |
| 1642 | $tags .= "<meta name='description' content='" . esc_attr($description) . "'/>\n"; |
| 1643 | $tags .= "<meta name='twitter:description' content='" . esc_attr($description) . "'/>\n"; |
| 1644 | |
| 1645 | } |
| 1646 | |
| 1647 | } else { |
| 1648 | |
| 1649 | $block_content = $post->post_content; |
| 1650 | |
| 1651 | // Regular expression to match the id and href keys and their values |
| 1652 | $thumb = '/(?:"id":"' . $id_value . '"|"clientId":"' . $id_value . '").*?"customThumbnail":"(.*?)"/'; |
| 1653 | $title_regex = '/(?:"id":"' . $id_value . '"|"clientId":"' . $id_value . '").*?"customTitle":"(.*?)"/'; |
| 1654 | $description_regex = '/(?:"id":"' . $id_value . '"|"clientId":"' . $id_value . '").*?"customDescription":"(.*?)"/'; |
| 1655 | |
| 1656 | // Search for the regex pattern in the string and extract the href value |
| 1657 | if (preg_match($thumb, $block_content, $matches1)) { |
| 1658 | $image_url = esc_url($matches1[1]); |
| 1659 | $tags .= "\n<meta name='twitter:image' content='" . esc_attr($image_url) . "'/>\n"; |
| 1660 | $tags .= "<meta property='og:image' content='" . esc_attr($image_url) . "'/>\n"; |
| 1661 | |
| 1662 | } else if (!empty($thumbnail_url)) { |
| 1663 | $tags .= "\n<meta name='twitter:image' content='" . esc_attr($thumbnail_url) . "'/>\n"; |
| 1664 | $tags .= "<meta property='og:image' content='" . esc_attr($thumbnail_url) . "'/>\n"; |
| 1665 | } |
| 1666 | |
| 1667 | if (preg_match($title_regex, $block_content, $matches2)) { |
| 1668 | $title = json_decode('"' . $matches2[1] . '"', JSON_UNESCAPED_UNICODE); |
| 1669 | $tags .= "<meta property='og:title' content='" . esc_attr($title) . "'/>\n"; |
| 1670 | $tags .= "<meta name='title' content='" . esc_attr($title) . "'>\n"; |
| 1671 | $tags .= "<meta name='twitter:title' content='" . esc_attr($title) . "'/>\n"; |
| 1672 | |
| 1673 | } |
| 1674 | |
| 1675 | if (preg_match($description_regex, $block_content, $matches3)) { |
| 1676 | $description = json_decode('"' . $matches3[1] . '"', JSON_UNESCAPED_UNICODE); |
| 1677 | $tags .= "<meta property='og:description' content='" . esc_attr($description) . "'/>\n"; |
| 1678 | $tags .= "<meta name='description' content='" . esc_attr($description) . "'/>\n"; |
| 1679 | $tags .= "<meta name='twitter:description' content='" . esc_attr($description) . "'/>\n"; |
| 1680 | |
| 1681 | } |
| 1682 | } |
| 1683 | |
| 1684 | $share_url = !empty($unique_hash) ? "$url?hash=$id_value&unique=$unique_hash" : "$url?hash=$id_value"; |
| 1685 | $tags .= "<meta property='og:url' content='". $share_url . "'/>\n"; |
| 1686 | $tags .= "<meta name='twitter:card' content='summary_large_image'/>\n"; |
| 1687 | |
| 1688 | // Add Open Graph type for better LinkedIn compatibility |
| 1689 | $tags .= "<meta property='og:type' content='article'/>\n"; |
| 1690 | |
| 1691 | remove_action('wp_head', 'rel_canonical'); |
| 1692 | |
| 1693 | echo $tags; |
| 1694 | } |
| 1695 | } |
| 1696 | } |
| 1697 |