Sindbad~EG File Manager
<?php
/*
* Security : blocking direct access
* Source : http://codex.wordpress.org/Theme_Development#Template_Files
*/
defined('ABSPATH') or die("Access Restricted");
/*
* Post Content : Remove Twitter widgets.js from oEmbed
* check this post if have problem with oEmbed : https://siteorigin.com/clearing-oembed-cache/
*/
add_filter('embed_handler_html', 'mwp_twitter_script', 10, 3);
add_filter('oembed_fetch_url', 'mwp_twitter_script', 10, 3);
function mwp_twitter_script($provider, $url, $args) {
$host = parse_url($provider, PHP_URL_HOST);
if (strpos($host, 'twitter.com') !== false) {
$provider = add_query_arg('omit_script', 'true', $provider);
}
return $provider;
}
/**
* HTML5 Validation
* Post Content : Remove twitter blockquote width
* check this post if have problem with oEmbed : https://siteorigin.com/clearing-oembed-cache/
*/
add_filter('embed_handler_html', 'mwp_twitter_settings', 10, 4);
add_filter('embed_oembed_html', 'mwp_twitter_settings', 10, 4);
function mwp_twitter_settings($html, $url, $attr, $post_ID=false){
if (function_exists( 'is_amp_endpoint' ) && is_amp_endpoint()) {
// Nothing to do
} elseif (!is_admin() ) {
if (strpos($url, 'twitter.com')!==false) {
$html = preg_replace('/width=".+?"/', "", $html);
$html = preg_replace('/data-\s+/i', " ", $html);
}
}
return $html;
}
/*
* Remove Instagram embed.js script on each embed
* https://snippets.khromov.se/fix-broken-overlapping-instagram-embed-for-wordpress/
*/
add_filter('embed_oembed_html', 'mwp_instgram_script', 5, 4);
function mwp_instgram_script($html, $url, $attr, $post_id) {
if (function_exists( 'is_amp_endpoint' ) && is_amp_endpoint()) {
// Nothing to do
} elseif (!is_admin()) {
$regex = '/<script.*instagram\.com\/embed.js.*\s?script>/U';
$regex_2 = '/<script.*platform\.instagram\.com\/.*\/embeds\.js.*script>/U';
if(preg_match($regex, $html) || preg_match($regex_2, $html)) {
$html = preg_replace($regex, '', $html);
$html = preg_replace($regex_2, '', $html);
return $html;
}
}
return $html;
}
/*
* Post Content : Remove Facebook script inlined
* check this post if have problem with oEmbed : https://siteorigin.com/clearing-oembed-cache/
*/
add_filter( 'embed_oembed_html', 'mwp_reformat_facebook_embed', 5, 4 );
function mwp_reformat_facebook_embed( $html, $url, $attr, $post_id ) {
if (function_exists( 'is_amp_endpoint' ) && is_amp_endpoint()) {
// Nothing to do
} elseif (!is_admin()) {
if (strpos($url, 'facebook.com')!==false) {
$html = sprintf('<div class="block-div"><div class="fb-post centered" data-href="%s"></div><div class="clearfix"></div></div>', esc_url( $url ));
}
}
return $html;
}
/**
* Extract Dailymotion url from iframe
*
*/
function mwp_dmurl($iframeCode) {
preg_match('/<iframe.*src=\"(.*)\".*><\/iframe>/isU', $iframeCode, $match);
$url = $match[1];
return $url;
}
/**
* Extract Dailymotion id from url
*
*/
function mwp_dmid($url) {
preg_match_all('/^.+dailymotion.com\/(?:video|swf\/video|embed\/video|hub|swf)\/([^&?]+)/',$url,$matches);
$id = $matches[1][0];
return $id;
}
/**
* Extract Vimeo id from iframe
*
*/
function mwp_viid($iframeCode) {
$regex = '~
# Match Vimeo link and embed code
(?:<iframe [^>]*src=")? # If iframe match up to first quote of src
(?: # Group vimeo url
https?:\/\/ # Either http or https
(?:[\w]+\.)* # Optional subdomains
vimeo\.com # Match vimeo.com
(?:[\/\w]*\/?)? # Optional video sub directory this handles groups links also
\/ # Slash before Id
([0-9]+) # $1: VIDEO_ID is numeric
[^\s]* # Not a space
) # End group
"? # Match end quote if part of src
(?:[^>]*></iframe>)? # Match the end of the iframe
(?:<p>.*</p>)? # Match any title information stuff
~ix';
if (preg_match($regex, $iframeCode, $matches)) {
return $matches[1];
} else {
return null;
}
}
/**
* Extract youtube id from iframe
*
*/
function mwp_ytid($iframeCode) {
return preg_replace_callback('/<iframe\s+.*?\s+src=(".*?").*?<\/iframe>/', function ($matches) {
$youtubeUrl = $matches[1];
$youtubeUrl = trim($youtubeUrl, '"');
$youtubeUrl = trim($youtubeUrl, "'");
preg_match("/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:m\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\"'>]+)/", $youtubeUrl, $videoId);
return $youtubeVideoId = isset($videoId[1]) ? $videoId[1] : "";
}, $iframeCode);
}
/**
* Rewrite embed iframe and use shortcode
*
*/
add_filter('embed_handler_html', 'mwp_filter_embed');
add_filter('embed_oembed_html', 'mwp_filter_embed');
function mwp_filter_embed($code){
if (!is_admin()) {
if (function_exists( 'is_amp_endpoint' ) && is_amp_endpoint()) {
// nothing to do
} else {
// Youtube
if(strpos($code, 'youtu.be') !== false || strpos($code, 'youtube.com') !== false){
$youtube_id = mwp_ytid($code);
$code = '';
$code = do_shortcode('[vid id="'.$youtube_id.'" source="youtube"]');
}
// Dailymotion
if(strpos($code, 'dailymotion.com') !== false){
$dailymotion_id = mwp_dmid(mwp_dmurl($code));
$code = '';
$code = do_shortcode('[vid id="'.$dailymotion_id.'" source="dailymotion"]');
}
// Vimeo
if(strpos($code, 'vimeo.com') !== false){
$vimeo_id = mwp_viid($code);
$code = '';
$code = do_shortcode('[vid id="'.$vimeo_id.'" source="vimeo"]');
}
}
return $code;
} else {
return $code;
}
}
function mwp_responsive_wp_video_shortcode( $html, $atts, $video, $post_id, $library ) {
$replace_value = array(
'width: ' . $atts['width'] . 'px'
);
$replace_with = array(
'width:inherit !important;overflow:hidden;'
);
return str_ireplace( $replace_value, $replace_with, $html );
}
//add_filter( 'wp_video_shortcode', 'mwp_responsive_wp_video_shortcode', 10, 5 );
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists