Sindbad~EG File Manager
<?php
/*
* Security : blocking direct access
* Source : http://codex.wordpress.org/Theme_Development#Template_Files
*/
defined('ABSPATH') or die("Access Restricted");
/*
* Youtube Helpers
*
*/
function mwp_yt_get_thumb($id) {
$string = sanitize_text_field($id);
$imgUrl = "https://i1.ytimg.com/vi/$string/mqdefault.jpg";
return $imgUrl;
}
function mwp_yt_get_thumb_fly($id) {
$string = sanitize_text_field($id);
$imgUrl = "https://i1.ytimg.com/vi/$string/mqdefault.jpg";
return $imgUrl;
}
function mwp_yt_img($id, $width, $height) {
$img_blank = MWP_BlankImage;
if (!is_array($id)) {
$image_url = 'https://i1.ytimg.com/vi/'.$id.'/mqdefault.jpg';
} else {
$image_url = mwp_thumb_size_default_src();
}
if (mwp_option('lazyload-enable') == 1) {
echo '<div class="crop"><img src="'.$img_blank.'" data-src="'.$image_url.'" class="lazy img-responsive" alt="'.get_the_title().'" width="'.$width.'" height="'.$height.'" ></div>';
} else {
echo '<div class="crop"><img src="'.$image_url.'" alt="'.get_the_title().'" class="img-responsive" width="'.$width.'" height="'.$height.'" /></div>';
}
}
function mwp_yt_img_nolazy($id, $width, $height) {
if (!is_array($id)) {
echo '<div class="crop"><img src="https://i1.ytimg.com/vi/'.$id.'/mqdefault.jpg" class="img-responsive" alt="'.get_the_title().'" width="'.$width.'" height="'.$height.'"></div>';
} else {
echo '<div class="crop"><img src="' .mwp_thumb_size_default_src(). '" alt="'.get_the_title().'" class="img-responsive" width="'.$width.'" height="'.$height.'" /></div>';
}
}
/*
* Dilaymotion Helpers
*
*/
function mwp_dm_get_thumb($id) {
if (!is_array($id)) {
$url = sprintf( 'https://api.dailymotion.com/video/%s?fields=thumbnail_240_url', $id );
$response = wp_remote_get( $url, array( 'timeout' => 15 ) );
if( ! is_wp_error( $response ) && isset( $response['response']['code'] ) && 200 === $response['response']['code'] ) {
$body = wp_remote_retrieve_body( $response );
$object = json_decode( $body , TRUE );
$thumb = $object['thumbnail_240_url'];
return $thumb;
}
}
}
function mwp_dm_get_thumb_lg($id) {
if (!is_array($id)) {
$url = sprintf( 'https://api.dailymotion.com/video/%s?fields=thumbnail_480_url', $id );
$response = wp_remote_get( $url, array( 'timeout' => 15 ) );
if( ! is_wp_error( $response ) && isset( $response['response']['code'] ) && 200 === $response['response']['code'] ) {
$body = wp_remote_retrieve_body( $response );
$object = json_decode( $body , TRUE );
$thumb = $object['thumbnail_480_url'];
return $thumb;
}
}
}
function mwp_dm_img($link, $width, $height) {
$img_blank = MWP_BlankImage;
if (!empty($link)) {
$image_url = $link;
} else {
$image_url = mwp_thumb_size_default_src();
}
if (mwp_option('lazyload-enable') == 1) {
echo '<div class="crop"><img src="'.$img_blank.'" data-src="'.$image_url.'" class="lazy img-responsive" alt="'.get_the_title().'" width="'.$width.'" height="'.$height.'" ></div>';
} else {
echo '<div class="crop"><img src="'.$image_url.'" alt="'.get_the_title().'" class="img-responsive" width="'.$width.'" height="'.$height.'" /></div>';
}
}
function mwp_dm_img_nolazy($link, $width, $height) {
if (!empty($link)) {
echo '<div class="crop"><img src="'.$link.'" class="lazy img-responsive" alt="'.get_the_title().'" width="'.$width.'" height="'.$height.'" ></div>';
} else {
echo '<div class="crop"><img src="' .mwp_thumb_size_default_src(). '" alt="'.get_the_title().'" class="img-responsive" width="'.$width.'" height="'.$height.'" /></div>';
}
}
/*
* Vimeo Helpers
*
*/
function mwp_vi_get_thumb($id) {
if (!is_array($id)) :
$url = sprintf( 'https://vimeo.com/api/v2/video/%s.php', $id );
$response = wp_remote_get( $url, array( 'timeout' => 15 ) );
if( ! is_wp_error( $response ) && isset( $response['response']['code'] ) && 200 === $response['response']['code'] ) {
$body = unserialize(wp_remote_retrieve_body( $response ));
$thumb = $body[0]['thumbnail_large'];
return $thumb;
}
endif;
}
function mwp_vi_img($link, $width, $height) {
$img_blank = MWP_BlankImage;
if (!empty($link)) {
$image_url = $link;
} else {
$image_url = mwp_thumb_size_default_src();
}
if (mwp_option('lazyload-enable') == 1) {
echo '<div class="crop"><img src="'.$img_blank.'" data-src="'.$image_url.'" class="lazy img-responsive" alt="'.get_the_title().'" width="'.$width.'" height="'.$height.'" ></div>';
} else {
echo '<div class="crop"><img src="'.$image_url.'" alt="'.get_the_title().'" class="img-responsive" width="'.$width.'" height="'.$height.'" /></div>';
}
}
function mwp_vi_img_nolazy($link, $width, $height) {
if (!empty($link)) {
echo '<div class="crop"><img src="'.$link.'" class="lazy img-responsive" alt="'.get_the_title().'" width="'.$width.'" height="'.$height.'"></div>';
} else {
echo '<div class="crop"><img src="' .mwp_thumb_size_default_src(). '" alt="'.get_the_title().'" class="img-responsive" width="'.$width.'" height="'.$height.'" /></div>';
}
}
/*
* Facebook Helpers
*
*/
function mwp_fb_get_thumb($id) {
$fb_access_token = mwp_option('facebook-access-token');
if (!is_array($id) && !empty($fb_access_token)) {
$url = sprintf( 'https://graph.facebook.com/%s', $id );
$param = array(
'fields' => 'format,source,length',
'access_token' => $fb_access_token,
);
$response = wp_remote_get( add_query_arg( $param, $url ), array( 'timeout' => 15 ) );
if( ! is_wp_error( $response ) && isset( $response['response']['code'] ) && 200 === $response['response']['code'] ) {
$body = json_decode(wp_remote_retrieve_body( $response ));
$count = count($body->format)-1;
$thumbnail = $body->format[$count]->picture;
return $thumbnail;
} else {
$thumbnail = mwp_thumb_size_default_src();
return $thumbnail;
}
} else {
$thumbnail = mwp_thumb_size_default_src();
return $thumbnail;
}
}
function mwp_fb_img($id, $width, $height) {
$img_blank = MWP_BlankImage;
if (!is_array($id)) {
$image_url = mwp_fb_get_thumb($id);
if (mwp_option('lazyload-enable') == 1) {
echo '<div class="crop"><img src="'.$img_blank.'" data-src="'.$image_url.'" class="lazy img-responsive" alt="'.get_the_title().'" width="'.$width.'" height="'.$height.'" ></div>';
} else {
echo '<div class="crop"><img src="'.$image_url.'" alt="'.get_the_title().'" class="img-responsive" width="'.$width.'" height="'.$height.'" /></div>';
}
}
}
function mwp_fb_img_nolazy($id, $width, $height) {
if (!is_array($id)) {
echo '<div class="crop"><img src="'.mwp_fb_get_thumb($id).'" class="lazy img-responsive" alt="'.get_the_title().'" width="'.$width.'" height="'.$height.'"></div>';
} else {
echo '<div class="crop"><img src="' .mwp_thumb_size_default_src(). '" alt="'.get_the_title().'" class="img-responsive" width="'.$width.'" height="'.$height.'" /></div>';
}
}
/*
* Get Video Image and display it
*
*/
function mwp_smart_thumb($size, $postid, $width, $height, $crop=false) {
if (mwp_option('thumbnail-vyd') == 0 || has_post_thumbnail() ) {
mwp_thumb_size($size, $width, $height, 'img-responsive' , $crop);
} else {
// New custom field Youtube & Vimeo & Dailymotion
$key_exists_yt = metadata_exists( 'post', $postid, 'mwp_yt_id' );
$key_exists_vi = metadata_exists( 'post', $postid, 'mwp_vi_thumbnail' );
$key_exists_dm = metadata_exists( 'post', $postid, 'mwp_dm_thumbnail' );
$key_exists_fb = metadata_exists( 'post', $postid, 'mwp_fb_id' );
// Get New custom field value (Video ID)
$check_y = get_post_meta($postid, 'mwp_yt_id' , true);
$check_v = get_post_meta($postid, 'mwp_vi_thumbnail' , true);
$check_d = get_post_meta($postid, 'mwp_dm_thumbnail' , true);
$check_f = get_post_meta($postid, 'mwp_fb_id' , true);
if ($key_exists_yt == true && !empty($check_y)) {
mwp_yt_img($check_y, $width, $height);
} elseif ($key_exists_vi == true && !empty($check_v)) {
mwp_vi_img($check_v, $width, $height);
} elseif ($key_exists_dm == true && !empty($check_d)) {
mwp_dm_img($check_d, $width, $height);
} elseif ($key_exists_fb == true && !empty($check_f)) {
mwp_fb_img($check_f, $width, $height);
} else {
mwp_thumb_size_default('img-responsive', $width, $height);
}
}
}
/*
* Get Video Image and display it (NO Lazyload)
*
*/
function mwp_smart_thumb_nolazy($size, $postid, $width, $height) {
if (mwp_option('thumbnail-vyd') == 0 || has_post_thumbnail() ) {
mwp_thumb_size($size, $width, $height, 'img-responsive no-lazy' );
} else {
// New custom field Youtube & Vimeo & Dailymotion
$key_exists_yt = metadata_exists( 'post', $postid, 'mwp_yt_id' );
$key_exists_vi = metadata_exists( 'post', $postid, 'mwp_vi_thumbnail' );
$key_exists_dm = metadata_exists( 'post', $postid, 'mwp_dm_thumbnail' );
$key_exists_fb = metadata_exists( 'post', $postid, 'mwp_fb_id' );
// Get New custom field value (Video ID)
$check_y = get_post_meta($postid, 'mwp_yt_id' , true);
$check_v = get_post_meta($postid, 'mwp_vi_thumbnail' , true);
$check_d = get_post_meta($postid, 'mwp_dm_thumbnail' , true);
$check_f = get_post_meta($postid, 'mwp_fb_id' , true);
if ($key_exists_yt == true && !empty($check_y)) {
mwp_yt_img_nolazy($check_y, $width, $height);
} elseif ($key_exists_vi == true && !empty($check_v)) {
mwp_vi_img_nolazy($check_v, $width, $height);
} elseif ($key_exists_dm == true && !empty($check_d)) {
mwp_dm_img_nolazy($check_d, $width, $height);
} elseif ($key_exists_fb == true && !empty($check_f)) {
mwp_fb_img_nolazy($check_f, $width, $height);
} else {
mwp_thumb_size_default('img-responsive no-lazy', $width, $height);
}
}
}
/*
* Get Video Duration and display it
*
*/
function mwp_video_duration($postid) {
if (mwp_option('thumbnail-vyd') == 0) {
return false;
} else {
// Get time value from metabox
$time_vid = mwp_option('video_duration');
$time_vid_value = get_post_meta($postid, $time_vid , true);
$key_exists_yt = metadata_exists( 'post', $postid, 'mwp_yt_duration' );
$key_exists_vi = metadata_exists( 'post', $postid, 'mwp_vi_duration' );
$key_exists_dm = metadata_exists( 'post', $postid, 'mwp_dm_duration' );
$key_exists_sp = metadata_exists( 'post', $postid, $time_vid );
// Get New custom field value (Video ID)
$check_y = get_post_meta($postid, 'mwp_yt_duration' , true);
$check_v = get_post_meta($postid, 'mwp_vi_duration' , true);
$check_d = get_post_meta($postid, 'mwp_dm_duration' , true);
if ($key_exists_sp == true && !empty($time_vid_value) ) {
return $time_vid_value;
} elseif ($key_exists_yt == true && !empty($check_y)) {
return $check_y;
} elseif ($key_exists_vi == true && !empty($check_v)) {
return $check_v;
} elseif ($key_exists_dm == true && !empty($check_d)) {
return $check_d;
} else {
return '';
}
}
}
/*
* Display Video Embed in Posts endpoint /embed
*
*/
function mwp_check_video_embed($postid) {
// New custom field Youtube & Vimeo & Dailymotion
$key_exists_yt = metadata_exists( 'post', $postid, 'mwp_yt_id' );
$key_exists_vi = metadata_exists( 'post', $postid, 'mwp_vi_id' );
$key_exists_dm = metadata_exists( 'post', $postid, 'mwp_dm_id' );
$key_exists_fb = metadata_exists( 'post', $postid, 'mwp_fb_id' );
// Get New custom field value (Video ID)
$check_y = get_post_meta($postid, 'mwp_yt_id' , true);
$check_v = get_post_meta($postid, 'mwp_vi_id' , true);
$check_d = get_post_meta($postid, 'mwp_dm_id' , true);
$check_f = get_post_meta($postid, 'mwp_fb_id' , true);
if ($key_exists_yt == true && !empty($check_y)) {
mwp_yt_embed($check_y);
} elseif ($key_exists_vi == true && !empty($check_v)) {
mwp_vi_embed($check_v);
} elseif ($key_exists_dm == true && !empty($check_d)) {
mwp_dm_embed($check_d);
} elseif ($key_exists_fb == true && !empty($check_f)) {
mwp_fb_embed($check_f);
}
}
function mwp_yt_embed($id) {
if (!is_array($id)) {
echo '<iframe style="width:100%;height:100%;border:none!important;" src="//www.youtube.com/embed/'.$id.'?vq=hd720&rel=0&controls=1&iv_load_policy=3&disablekb=1&modestbranding=1"></iframe>';
}
}
function mwp_dm_embed($id) {
if (!is_array($id)) {
echo '<iframe style="width:100%;height:100%;border:none!important;" src="//www.dailymotion.com/embed/video/'.$id.'?info=0&logo=0&related=0"></iframe>';
}
}
function mwp_vi_embed($id) {
if (!is_array($id)) {
echo '<iframe style="width:100%;height:100%;border:none!important;" src="//player.vimeo.com/video/'.$id.'?portrait=0&title=0&badge=0"></iframe>';
}
}
function mwp_fb_embed($id) {
if (!is_array($id)) {
echo '<iframe style="width:100%;height:100%;border:none!important;" src="https://www.facebook.com/video/embed?video_id='.$id.'" allowfullscreen></iframe>';
}
}
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists