Sindbad~EG File Manager
<?php
/*
* Security : blocking direct access
* Source : http://codex.wordpress.org/Theme_Development#Template_Files
*/
defined('ABSPATH') or die("Access Restricted");
/*
* Images
* Caption Filter
*/
add_filter('img_caption_shortcode', 'dap_responsive_img_caption_filter', 10, 3 );
add_filter('img_caption_shortcode', 'dap_responsive_img_caption_filter', 1, 3 );
function dap_responsive_img_caption_filter( $val, $attr, $content = null ) {
extract(shortcode_atts( array(
'id' => '',
'align' => '',
'width' => '',
'caption' => ''
), $attr));
if ( 1 > (int) $width || empty($caption) )
return $val;
if ( $id ) $id = 'id="' . esc_attr($id) . '" ';
return '<figure class="wp-caption ' . esc_attr($align) . '" style="width: ' . (10 + (int) $width) . 'px">' . do_shortcode( $content ) . '<figcaption class="wp-caption-text">' . $caption . '</figcaption></figure>';
}
/*
* Disable responsive image support
* http://wordpress.stackexchange.com/a/211376/40961
*
*/
function mwp_responsive_img_support( $attr ){
if( isset( $attr['sizes'] ) )
unset( $attr['sizes'] );
if( isset( $attr['srcset'] ) )
unset( $attr['srcset'] );
return $attr;
}
remove_filter('the_content', 'wp_make_content_images_responsive' );
add_filter('wp_get_attachment_image_attributes', 'mwp_responsive_img_support', PHP_INT_MAX );
add_filter('wp_calculate_image_sizes', '__return_false', PHP_INT_MAX );
add_filter('wp_calculate_image_srcset', '__return_false', PHP_INT_MAX );
/*
* LightBox Filter
*
*/
add_filter('the_content', 'add_class_lightbox', 12);
function add_class_lightbox($content){
if ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'carousel' ) ) :
elseif (mwp_option('lightbox-enable') == 1) :
global $post;
$pattern = "/<a(.*?)href=('|\")([^>]*).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>(.*?)<\/a>/i";
if (mwp_option('lightbox-library') == 1) :
$replacement = '<a$1href=$2$3.$4$5 data-rel="gallery-1" class="swipebox">$7</a>';
elseif (mwp_option('lightbox-library') == 2) :
$replacement = '<a$1href=$2$3.$4$5 data-lightbox="roadtrip" data-group="group"$6>$7</a>';
elseif (mwp_option('lightbox-library') == 3) :
$replacement = '<a$1href=$2$3.$4$5 class="venobox" data-gall="myGallery">$7</a>';
endif;
$content = preg_replace($pattern, $replacement, $content);
return $content;
else :
return $content;
endif;
}
/**
* Images
* Lazy Load Filter
*/
if (mwp_option('lazyload-mobile') == 1) :
add_filter('the_content', 'mwp_lazyload', 999999);
function mwp_lazyload($content) {
if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) :
return $content;
else :
return preg_replace_callback('/(<\s*img[^>]+)(src\s*=\s*"[^"]+")([^>]+>)/i', 'mwp_preg_lazyload', $content);
endif;
}
function mwp_preg_lazyload($img_match) {
$img_blank = 'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==';
$img_replace = $img_match[1] . 'src="' .$img_blank. '" data-src' . substr($img_match[2], 3) . $img_match[3];
$img_replace = preg_replace('/class\s*=\s*"/i', 'class="lazy ', $img_replace);
return $img_replace;
}
endif;
/*
* Auto remove first image from posts
*
*/
add_filter('the_content', 'mwp_remove_first_image');
function mwp_remove_first_image($content) {
if (mwp_option('first-image-remove') == 1) :
$get_categories_ids = mwp_option('remove-post-thumbnail');
if (!is_singular('page') && !is_feed() && !is_home() && is_singular() && !in_category($get_categories_ids) ) {
$content = preg_replace("/<img[^>]+\>/i", "", $content, 1);
}
endif;
return $content;
}
/*
* Remove rel=attachment wp-att-XXx html5 Validation
*
*/
add_filter('the_content', 'mwp_remove_rel_attr');
function mwp_remove_rel_attr($content) {
return preg_replace('/\s+rel="attachment wp-att-[0-9]+"/i', '', $content);
}
/*
* wrap image inside div
*
*/
add_filter('the_content', 'mwp_img_unautop', 30 );
function mwp_img_unautop($content) {
$content = preg_replace('/<p>\\s*?(<a .*?><img.*?><\\/a>|<img.*?>)?\\s*<\\/p>/s', '<div>$1</div>', $content);
return $content;
}
/*
* repair alternative alt text for wordpress images
* source : https://www.mwordpress.net/repair-alternative-alt-text-for-wordpress-images/
*
*/
add_filter('the_content', 'mwp_fill_missing_alt_tags', 0);
function mwp_fill_missing_alt_tags($content){
global $post;
preg_match_all('/<img (.*?)\/>/', $content, $images);
$site_name = get_bloginfo('name');
$char_array = array();
$char_array[] = '-';
$char_array[] = '_';
if(!is_null($images)) {
foreach($images[1] as $index => $value) {
preg_match( '/src\s*=\s*([\'"])?((?(1).+?|[^\s>]+))(?(1)\1)/', $value, $source );
// ALT tag : Not Found
if(!preg_match('/alt=/', $value)) :
$file = preg_replace( '/\-*(\d+)x(\d+)\.(.*)$/', ' ', $source[2] );
$filename = pathinfo($file, PATHINFO_FILENAME);
$text = str_replace( '/\-*(\d+)x(\d+)\.(.*)$/', ' ', $filename );
$title = str_replace( $char_array, ' ', $text );
$new_img = str_replace('<img', '<img alt="'.$title.' - '.$site_name.'"', $images[0][$index]);
$content = str_replace($images[0][$index], $new_img, $content);
endif;
// ALT tag : Empty
if(preg_match('/alt=/', $value) and strpos($value, 'alt=""')) :
$file = preg_replace( '/\-*(\d+)x(\d+)\.(.*)$/', ' ', $source[2] );
$filename = pathinfo($file, PATHINFO_FILENAME);
$text = str_replace( '/\-*(\d+)x(\d+)\.(.*)$/', ' ', $filename );
$title = str_replace( $char_array, ' ', $text );
$new_img = str_replace('alt=""', 'alt="'.$title.' - '.$site_name.'"', $images[0][$index]);
$content = str_replace($images[0][$index], $new_img, $content);
endif;
}
return $content;
}
}
/*
* convert youtube iframe to shortcode
*
*/
add_filter('the_content', 'mwp_youtube_covert');
function mwp_youtube_covert($content) {
if (function_exists( 'is_amp_endpoint' ) && is_amp_endpoint()) {
} else {
$content = preg_replace('#<iframe.+?src="http://www.youtube.com/embed/([a-zA-Z0-9_-]{11})["?][^>]+?></iframe>#i', '[vid id="$1" source="youtube"]', $content);
$content = preg_replace('#<iframe.+?src="https://www.youtube.com/embed/([a-zA-Z0-9_-]{11})["?][^>]+?></iframe>#i', '[vid id="$1" source="youtube"]', $content);
}
return $content;
}
/*
* Remove empty p tag
*
*/
add_filter('the_content', 'mwp_remove_empty_p', 20, 1);
function mwp_remove_empty_p($content){
if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
return $content;
} else {
$content = force_balance_tags($content);
return preg_replace('#<p>(\s| )*+(<br\s*/*>)?(\s| )*</p>#i', '', $content);
}
}
/**
* password input for protected posts
*
*/
add_filter('the_password_form', 'mwp_password_form' );
function mwp_password_form() {
global $post;
$label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID );
$form_pwd = '
<div class="protected">
<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" method="post">
<p class="alert alert-warning">
<span>' . __( "To view this protected post, enter the password below : ", MWP_TEXT_DOMAIN ) . '</span>
<label for="' . esc_attr($label) . '">' . __( "Password : " , MWP_TEXT_DOMAIN) . ' </label>
<input class="input" name="post_password" id="' . esc_attr($label) . '" type="password" size="20" maxlength="20" />
<input class="btn" type="submit" name="Submit" value="' . esc_attr__( "Submit" ) . '" />
</p>
</form>
</div>';
return $form_pwd;
}
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists