| Server IP : 213.186.33.4 / Your IP : 216.73.216.146 Web Server : Apache System : Linux webm005.cluster103.gra.hosting.ovh.net 6.18.39-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Tue Jul 21 12:03:15 CEST 2026 x86_64 User : karinebmkh ( 644538) PHP Version : 8.4.22 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/karinebmkh/www2/wp-content/plugins/glaza-core/includes/ |
Upload File : |
<?php
/**
* @param array $settings
*
* @return array|mixed|object
* get Instagram images with token
*/
if ( ! function_exists( 'glaza_data_instagram_token' ) ) {
function glaza_data_instagram_token( $settings = array() ) {
$cache_name = 'glaza_instagram_cache';
if ( ! empty( $settings['cache_id'] ) ) {
$cache_id = $settings['cache_id'];
} else {
$cache_id = 0;
}
$cache_data = get_transient( $cache_name );
if ( ! is_array( $cache_data ) ) {
$cache_data = array();
}
if ( ! empty( $cache_data[ $cache_id ] ) ) {
return $cache_data[ $cache_id ];
} else {
if ( empty( $settings['instagram_token'] ) ) {
return esc_html__( 'empty Instagram token', 'glaza-core' );
}
$token = trim( $settings['instagram_token'] );
if ( ! empty( $settings['total_images'] ) ) {
$total = intval( $settings['total_images'] );
} else {
$total = 6;
}
$user = explode( ".", $token );
if ( empty( $user[0] ) ) {
return esc_html__( 'token error.', 'glaza-core' );
} else {
$params = array(
'sslverify' => false,
'timeout' => 100
);
if ( ! empty( $settings['tag'] ) ) {
$response = wp_remote_get( 'https://api.instagram.com/v1/tags/' . trim( $settings['tag'] ) . '/media/recent/?access_token=' . $token . '&count=' . $total, $params );
} else {
$response = wp_remote_get( 'https://api.instagram.com/v1/users/' . $user[0] . '/media/recent/?access_token=' . $token . '&count=' . $total, $params );
}
if ( is_wp_error( $response ) || empty( $response['response']['code'] ) || 200 != $response['response']['code'] ) {
return esc_html__( 'Token expired or no pictures.', 'glaza-core' );
};
$data_images = json_decode( wp_remote_retrieve_body( $response ) );
$cache_data[ $cache_id ] = $data_images;
delete_transient( $cache_name );
set_transient( $cache_name, $cache_data, 12000 );
return $data_images;
}
}
}
}
/**
* @param array $settings
*
* @return mixed
* get instagram images without token
*/
if ( ! function_exists( 'glaza_data_instagram_no_token' ) ) {
function glaza_data_instagram_no_token( $settings = array() ) {
$cache_name = 'glaza_instagram_cache';
if ( ! empty( $settings['cache_id'] ) ) {
$cache_id = $settings['cache_id'];
} else {
$cache_id = 0;
}
$cache_data = get_transient( $cache_name );
if ( ! is_array( $cache_data ) ) {
$cache_data = array();
}
if ( ! empty( $cache_data[ $cache_id ] ) ) {
return $cache_data[ $cache_id ];
} else {
if ( empty( $settings['user_name'] ) ) {
return false;
}
$user_name = trim( strtolower( $settings['user_name'] ) );
switch ( substr( $user_name, 0, 1 ) ) {
case '#':
$url = 'https://instagram.com/explore/tags/' . str_replace( '#', '', $user_name );
break;
default:
$url = 'https://instagram.com/' . str_replace( '@', '', $user_name );
break;
}
$params = array(
'sslverify' => false,
'timeout' => 100
);
$response = wp_remote_get( $url, $params );
if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
return esc_html__( 'Unable to connect to Instagram.', 'glaza-core' );
}
$response = explode( 'window._sharedData = ', $response['body'] );
$response = explode( ';</script>', $response[1] );
$response = json_decode( $response[0], true );
if ( empty( $response ) ) {
return esc_html__( 'invalid data.', 'glaza-core' );
}
if ( isset( $response['entry_data']['ProfilePage'][0]['graphql']['user']['edge_owner_to_timeline_media']['edges'] ) ) {
$response = $response['entry_data']['ProfilePage'][0]['graphql']['user']['edge_owner_to_timeline_media']['edges'];
} elseif ( isset( $response['entry_data']['TagPage'][0]['graphql']['hashtag']['edge_hashtag_to_media']['edges'] ) ) {
$response = $response['entry_data']['TagPage'][0]['graphql']['hashtag']['edge_hashtag_to_media']['edges'];
} else {
return esc_html__( 'invalid data.', 'glaza-core' );
}
if ( ! is_array( $response ) ) {
return esc_html__( 'invalid data.', 'glaza-core' );
}
$data_images = array();
foreach ( $response as $image ) {
$image['thumbnail_src'] = '';
if ( ! empty( $image['node']['thumbnail_resources'][4]['src'] ) ) {
$image['thumbnail_src'] = preg_replace( '/^https?\:/i', '', $image['node']['thumbnail_resources'][4]['src'] );
} elseif ( ! empty( $image['node']['thumbnail_resources'][2]['src'] ) ) {
$image['thumbnail_src'] = preg_replace( '/^https?\:/i', '', $image['node']['thumbnail_resources'][2]['src'] );
} elseif ( ! empty( $image['node']['thumbnail_resources'][0]['src'] ) ) {
$image['thumbnail_src'] = preg_replace( '/^https?\:/i', '', $image['node']['thumbnail_resources'][0]['src'] );
}
if ( ! empty( $image['node']['shortcode'] ) ) {
$link = trailingslashit( '//instagram.com/p/' . $image['node']['shortcode'] );
} else {
$link = '#';
}
if ( ! empty( $image['node']['edge_media_to_caption']['edges'][0]['node']['text'] ) ) {
$caption = esc_attr( $image['node']['edge_media_to_caption']['edges'][0]['node']['text'] );
} else {
$caption = 'instagram image';
}
$data_images[] = array(
'thumbnail_src' => $image['thumbnail_src'],
'caption' => $caption,
'link' => $link,
);
}
$cache_data[ $cache_id ] = $data_images;
delete_transient( $cache_name );
set_transient( $cache_name, $cache_data, 12000 );
return $data_images;
}
}
}
/**
* @param array $settings
*
* @return array|mixed|object
* flickr data
*/
if ( ! function_exists( 'glaza_data_flickr' ) ) {
function glaza_data_flickr( $settings = array() ) {
if ( empty( $settings['flickr_id'] ) ) {
return false;
};
$cache_name = 'glaza_flickr_cache';
if ( ! empty( $settings['cache_id'] ) ) {
$cache_id = $settings['cache_id'];
} else {
$cache_id = 0;
}
$cache_data = get_transient( $cache_name );
if ( ! is_array( $cache_data ) ) {
$cache_data = array();
}
if ( ! empty( $cache_data[ $cache_id ] ) ) {
return $cache_data[ $cache_id ];
} else {
if ( empty( $settings['tag'] ) ) {
$settings['tag'] = '';
}
if ( empty( $settings['total_images'] ) ) {
$settings['total_images'] = 9;
}
$params = array( 'timeout' => 100, 'sslverify' => false );
$response = wp_remote_get( 'http://api.flickr.com/services/feeds/photos_public.gne?format=json&id=' . urlencode( $settings['flickr_id'] ) . '&nojsoncallback=1&tags=' . urlencode( $settings['tag'] ), $params );
if ( is_wp_error( $response ) || '200' != $response['response']['code'] ) {
return false;
}
$response = wp_remote_retrieve_body( $response );
$response = str_replace( "\\'", "'", $response );
$data_images = json_decode( $response, true );
if ( is_array( $data_images ) ) {
$data_images = array_slice( $data_images['items'], 0, $settings['total_images'] );
foreach ( $data_images as $i => $v ) {
$data_images[ $i ]['media'] = preg_replace( '/_m\.(jp?g|png|gif)$/', '_s.\\1', $v['media']['m'] );
}
$cache_data[ $cache_id ] = $data_images;
delete_transient( $cache_name );
set_transient( $cache_name, $cache_data, 12000 );
return $response;
} else {
return false;
}
}
}
}
/**
* @param $video_url
* @return bool|string
* check video host
*/
if ( ! function_exists( 'glaza_video_detect_url' ) ) {
function glaza_video_detect_url( $video_url ) {
$video_url = strtolower( $video_url );
if ( strpos( $video_url, 'youtube.com' ) !== false or strpos( $video_url, 'youtu.be' ) !== false ) {
return 'youtube';
}
if ( strpos( $video_url, 'dailymotion.com' ) !== false ) {
return 'dailymotion';
}
if ( strpos( $video_url, 'vimeo.com' ) !== false ) {
return 'vimeo';
}
return false;
}
}
/**
* @param $video_url
* @return mixed
* get youtube video ID
*/
if ( ! function_exists( 'glaza_video_id_youtube' ) ) {
function glaza_video_id_youtube( $video_url ) {
$s = array();
parse_str( parse_url( $video_url, PHP_URL_QUERY ), $s );
if ( empty( $s["v"] ) ) {
$youtube_sl_explode = explode( '?', $video_url );
$youtube_sl = explode( '/', $youtube_sl_explode[0] );
if ( ! empty( $youtube_sl[3] ) ) {
return $youtube_sl [3];
}
return $youtube_sl [0];
} else {
return $s["v"];
}
}
}
/**
* @param $video_url
* @return mixed
* get vimeo video ID
*/
if ( ! function_exists( 'glaza_video_id_vimeo' ) ) {
function glaza_video_id_vimeo( $video_url ) {
sscanf( parse_url( $video_url, PHP_URL_PATH ), '/%d', $video_id );
return $video_id;
}
}
if ( ! function_exists( 'glaza_video_id_dailymotion' ) ) {
function glaza_video_id_dailymotion( $video_url ) {
$video_id = strtok( basename( $video_url ), '_' );
if ( strpos( $video_id, '#video=' ) !== false ) {
$video_parts = explode( '#video=', $video_id );
if ( ! empty( $video_parts[1] ) ) {
return $video_parts[1];
}
};
return $video_id;
}
}
/**
* @param $image_url
* @return bool
* check response
*/
if ( ! function_exists( 'glaza_video_feat_response' ) ) {
function glaza_video_feat_response( $image_url ) {
$headers = @get_headers( $image_url );
if ( ! empty( $headers[0] ) and strpos( $headers[0], '404' ) !== false ) {
return true;
}
return false;
}
}
/**
* @param $video_url
* get video thumbnail youtube
*/
if ( ! function_exists( 'glaza_video_get_feat_youtube' ) ) {
function glaza_video_get_feat_youtube( $video_url ) {
//set http
$protocol = 'http';
if ( is_ssl() ) {
$protocol = 'https';
}
$video_id = glaza_video_id_youtube( $video_url );
$image_url_1920 = $protocol . '://img.youtube.com/vi/' . $video_id . '/maxresdefault.jpg';
$image_url_640 = $protocol . '://img.youtube.com/vi/' . $video_id . '/sddefault.jpg';
$image_url_480 = $protocol . '://img.youtube.com/vi/' . $video_id . '/hqdefault.jpg';
if ( ! glaza_video_feat_response( $image_url_1920 ) ) {
return $image_url_1920;
} elseif ( ! glaza_video_feat_response( $image_url_640 ) ) {
return $image_url_640;
} elseif ( ! glaza_video_feat_response( $image_url_480 ) ) {
return $image_url_480;
} else {
return false;
}
}
}
/**
* @param $video_url
* @return bool
* get vimeo featured image
*/
if ( ! function_exists( 'glaza_video_get_feat_vimeo' ) ) {
function glaza_video_get_feat_vimeo( $video_url ) {
$protocol = 'http';
if ( is_ssl() ) {
$protocol = 'https';
}
$video_id = glaza_video_id_vimeo( $video_url );
$api_url = $protocol . '://vimeo.com/api/oembed.json?url=https://vimeo.com/' . $video_id;
$data_response = wp_remote_get( $api_url, array(
'timeout' => 60,
'sslverify' => false,
'user-agent' => 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0'
)
);
if ( ! is_wp_error( $data_response ) ) {
$data_response = wp_remote_retrieve_body( $data_response );
$data_response = json_decode( $data_response );
$image_url = $data_response->thumbnail_url;
return $image_url;
} else {
return false;
}
}
}
/**
* @param $video_url
* @return bool
* get dailymotion featured image
*/
if ( ! function_exists( 'glaza_video_get_feat_dailymotion' ) ) {
function glaza_video_get_feat_dailymotion( $video_url ) {
$video_id = glaza_video_id_dailymotion( $video_url );
$protocol = 'http';
if ( is_ssl() ) {
$protocol = 'https';
}
$param = $protocol . '://api.dailymotion.com/video/' . $video_id . '?fields=thumbnail_url';
$data_response = wp_remote_get( $param );
if ( ! is_wp_error( $data_response ) ) {
$data_response = json_decode( $data_response['body'] );
$image_url = $data_response->thumbnail_url;
return $image_url;
} else {
return false;
}
}
}
/**
* @param $video_url
* @return bool|string
* get video featured image
*/
if ( ! function_exists( 'glaza_video_get_feat' ) ) {
function glaza_video_get_feat( $video_url ) {
if ( empty( $video_url ) ) {
return false;
}
$host_name = glaza_video_detect_url( $video_url );
switch ( $host_name ) {
case 'youtube' :
return glaza_video_get_feat_youtube( $video_url );
case 'vimeo' :
return glaza_video_get_feat_vimeo( $video_url );
case 'dailymotion' :
return glaza_video_get_feat_dailymotion( $video_url );
default :
return false;
}
}
}
/**
* @param $att_id
* set featured thumbnail
*/
if ( ! function_exists( 'glaza_video_set_featured' ) ) {
function glaza_video_set_featured( $att_id ) {
update_post_meta( get_the_ID(), '_thumbnail_id', $att_id );
}
}
/**
* @param $post_id
* @return bool
* get and save video featured image
*/
if ( ! function_exists( 'glaza_video_save_featured' ) ) {
function glaza_video_save_featured( $post_id ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return false;
}
if ( get_post_status( $post_id ) != 'publish' ) {
return false;
}
$post_type = get_post_type( $post_id );
$video_url = get_post_meta( $post_id, 'glaza_meta_video_url', true );
if ( 'post' != $post_type || empty( $video_url ) ) {
return false;
}
$image_url = glaza_video_get_feat( $video_url );
if ( ! empty( $image_url ) && ! has_post_thumbnail( $post_id ) ) {
add_action( 'add_attachment', 'glaza_video_set_featured' );
media_sideload_image( $image_url, $post_id, $post_id );
remove_action( 'add_attachment', 'glaza_video_set_featured' );
};
return false;
}
}
add_action( 'save_post', 'glaza_video_save_featured', 10, 1 );
/**
* @param $image
* @param $attachment_id
* @param $size
* @param $icon
* @return array|false
* gif support
*/
if ( ! function_exists( 'glaza_support_gif' ) ) {
function glaza_support_gif( $image, $attachment_id, $size, $icon ) {
$gif_support = glaza_get_option( 'gif_support' );
if ( ! empty( $gif_support ) ) {
$format = wp_check_filetype( $image[0] );
if ( ! empty( $format ) && 'gif' == $format['ext'] && 'full' != $size ) {
return wp_get_attachment_image_src( $attachment_id, $size = 'full', $icon );
}
}
return $image;
}
}
add_filter( 'wp_get_attachment_image_src', 'glaza_support_gif', 10, 4 );