' . __('privacy policies of google', 'video-embed-privacy') . ''; $vimeoLink = '' . __('privacy policies of vimeo', 'video-embed-privacy') . ''; return [ 'show' => __('Show Content', 'video-embed-privacy'), 'yt_show' => __('Play Video', 'video-embed-privacy'), 'vimeo_show' => __('Play Video', 'video-embed-privacy'), 'generic_hint' => __('This content is referring to %s and will be loaded from an external source.', 'video-embed-privacy'), 'yt_hint' => sprintf(__('This video will be embedded from Youtube. The %s apply.', 'video-embed-privacy'), $ytLink), 'vimeo_hint' => sprintf(__('This video will be embedded from Vimeo. The %s apply.', 'video-embed-privacy'), $vimeoLink), 'cache' => 'false', 'replace_unknown' => 'true', 'key' => '' ]; } function video_embed_privacy_option($name) { $defaults = video_embed_privacy_defaults(); if (!isset($defaults[$name])) { die("Unknown option: $name"); } return get_option("video-embed-privacy-$name", $defaults[$name]); } function video_embed_privacy_option_ne($name) { return video_embed_privacy_option($name) ?: video_embed_privacy_defaults()[$name]; } function video_embed_privacy_available() { return [ 'yt' => [ 'name' => __('Youtube', 'video-embed-privacy'), 'videoIdMatch' => "=youtube.*embed/([\\w-]+)=i", 'textFixer' => function($in) { return preg_replace('~https?\://www\.youtube\.com~', 'https://www.youtube-nocookie.com', $in); } ], 'vimeo' => [ 'name' => __('Vimeo', 'video-embed-privacy'), 'videoIdMatch' => '=://player.vimeo.com/video/(\\d+)=i', ] ]; } function video_embed_privacy_translate($text, $url, $atts) { wp_enqueue_script('video-embed-privacy'); $noJsText = esc_html__('Please activate JavaScript to view this video.', 'video-embed-privacy') . '
' . esc_html__('Video-Link', 'video-embed-privacy') . ': ' . $url . ''; $playText = '' . video_embed_privacy_option_ne('show') . '
' . sprintf(video_embed_privacy_option_ne('generic_hint'), preg_replace("~\\w+://(.*?)/.*~", "$1", $url)) . '
'; $embedText = $text; $w = $atts ['width']; if (preg_match("/width=\"(\\d+)/", $text, $widthMatches)) { $w = $widthMatches [1] * 1; } $h = $atts ['height']; if (preg_match("/height=\"(\\d+)/", $text, $heightMatches)) { $h = $heightMatches [1] * 1; } $style = 'width: ' . $w . 'px; min-height: ' . $h . 'px;'; $class = 'video-wrapped'; $doReplacement = video_embed_privacy_option('replace_unknown') === 'true'; $supported = video_embed_privacy_available(); foreach ($supported as $id => $settings) { if (preg_match($settings['videoIdMatch'], $text, $matches)) { $playText = '' . video_embed_privacy_option_ne($id . '_show') . '
' . video_embed_privacy_option_ne($id . '_hint') . '
'; $v = $matches [1]; if (isset($settings['textFixer'])) { $embedText = $settings['textFixer']($embedText); } $s = hash('sha256', video_embed_privacy_option('key') . $id . '/' . $v); $preview = plugins_url("preview/$id/$v.jpg?s=$s", __FILE__); $class .= ' video-wrapped-video video-wrapped-' . $id; $style .= ' background-image: url(\'' . $preview . '\')'; $doReplacement = true; break; } } if ($doReplacement) { return '
' . $noJsText . '
'; } else { return $text; } } function video_embed_privacy_styles() { wp_register_style('video-embed-privacy', plugins_url('video-embed-privacy.css', __FILE__)); wp_register_script('video-embed-privacy', plugins_url('video-embed-privacy.js', __FILE__), array(), '1.0', true); wp_enqueue_style('video-embed-privacy'); } function video_embed_privacy_settings() { add_editor_style(plugins_url('video-embed-privacy.css', __FILE__)); register_setting('video-embed-privacy', 'notice'); } function video_embed_privacy_write_settings() { update_option('video-embed-privacy-key', wp_generate_password(48)); $settings = [ 'cache' => video_embed_privacy_option('cache') === 'true', 'key' => video_embed_privacy_option('key') ]; $file = dirname(__FILE__) . '/preview/settings.php'; file_put_contents($file, "' . esc_html__('Settings', 'video-embed-privacy') . '', ); return array_merge( $links, $mylinks ); } function video_embed_privacy_load_textdomain() { load_plugin_textdomain('video-embed-privacy', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); } add_filter('embed_oembed_html', 'video_embed_privacy_translate', 11, 3); add_action('wp_enqueue_scripts', 'video_embed_privacy_styles'); add_action('plugins_loaded', 'video_embed_privacy_load_textdomain'); register_activation_hook(__FILE__, 'video_embed_privacy_write_settings'); if (is_admin()) { add_action('admin_init', 'video_embed_privacy_settings'); add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'video_embed_privacy_add_action_links'); include dirname(__FILE__) . '/options.php'; } if (is_dir(dirname(__FILE__) . '/plugin-update-checker')) { // Download updates from github for github snapshots - this code will only execute if the gradle script is used for building. require dirname(__FILE__) . '/plugin-update-checker/plugin-update-checker.php'; $myUpdateChecker = Puc_v4_Factory::buildUpdateChecker( 'https://github.com/michaelzangl/wp-video-embed-privacy/', __FILE__, 'video-embed-privacy' ); }