| 1 |
<?php |
| 2 |
/* |
| 3 |
* @link https://wpthemespace.com |
| 4 |
* @since 1.0.0 |
| 5 |
* @package Gallery box wordpress plugin |
| 6 |
* description Extra function for gallery box |
| 7 |
* |
| 8 |
* @ Gallery box |
| 9 |
*/ |
| 10 |
|
| 11 |
//function for youtube video id |
| 12 |
// Youtube video id filtring |
| 13 |
if ( ! function_exists( 'get_gbox_youtube_id' ) ) : |
| 14 |
function get_gbox_youtube_id($url) |
| 15 |
{ |
| 16 |
$video_id = false; |
| 17 |
|
| 18 |
$parsed_url = parse_url($url); |
| 19 |
if (!is_array($parsed_url) || !isset($parsed_url['host'])) { |
| 20 |
return false; |
| 21 |
} |
| 22 |
if (strcasecmp($parsed_url['host'], 'youtu.be') === 0) |
| 23 |
{ |
| 24 |
#### (dontcare)://youtu.be/<video id> |
| 25 |
$video_id = isset($parsed_url['path']) ? substr($parsed_url['path'], 1) : false; |
| 26 |
} |
| 27 |
elseif (strcasecmp($parsed_url['host'], 'www.youtube.com') === 0) |
| 28 |
{ |
| 29 |
if (isset($parsed_url['query'])) |
| 30 |
{ |
| 31 |
$query_params = array(); |
| 32 |
parse_str($parsed_url['query'], $query_params); |
| 33 |
if (isset($query_params['v'])) |
| 34 |
{ |
| 35 |
#### (dontcare)://www.youtube.com/(dontcare)?v=<video id> |
| 36 |
$video_id = $query_params['v']; |
| 37 |
} |
| 38 |
} |
| 39 |
if ($video_id == false && isset($parsed_url['path'])) |
| 40 |
{ |
| 41 |
$path_parts = explode('/', substr($parsed_url['path'], 1)); |
| 42 |
if (isset($path_parts[0]) && in_array($path_parts[0], array('e', 'embed', 'v')) && isset($path_parts[1])) |
| 43 |
{ |
| 44 |
#### (dontcare)://www.youtube.com/(whitelist)/<video id> |
| 45 |
$video_id = $path_parts[1]; |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
return $video_id; |
| 51 |
} |
| 52 |
endif; |
| 53 |
|
| 54 |
// Vimeo id filter by this function |
| 55 |
|
| 56 |
if ( ! function_exists( 'gbox_vimeo_url_id' ) ) : |
| 57 |
function gbox_vimeo_url_id($url = '') { |
| 58 |
$regs = array(); |
| 59 |
$id = ''; |
| 60 |
if (preg_match('%^https?:\/\/(?:www\.|player\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|video\/|)(\d+)(?:$|\/|\?)(?:[?]?.*)$%im', $url, $regs)) { |
| 61 |
$id = $regs[3]; |
| 62 |
} |
| 63 |
return $id; |
| 64 |
|
| 65 |
} |
| 66 |
|
| 67 |
endif; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
function isVimeoConnected() |
| 72 |
{ |
| 73 |
// use 80 for http or 443 for https protocol |
| 74 |
$connected = fsockopen("www.vimeo.com", 443, $errno, $errstr, 5); |
| 75 |
if ($connected){ |
| 76 |
fclose($connected); |
| 77 |
return true; |
| 78 |
} |
| 79 |
return false; |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* Get Post List |
| 84 |
* return array |
| 85 |
*/ |
| 86 |
function gbox_gallery_list( $post_type = 'gallery_box' ){ |
| 87 |
$options = array(); |
| 88 |
$gbox_untitle = esc_html__('Untitled gallery id','gallery-box'); |
| 89 |
$options['0'] = __('Select','gallery-box'); |
| 90 |
// $perpage = wooaddons_get_option( 'loadproductlimit', 'wooaddons_others_tabs', '20' ); |
| 91 |
$all_post = array( 'posts_per_page' => -1, 'post_type'=> $post_type ); |
| 92 |
$post_terms = get_posts( $all_post ); |
| 93 |
if ( ! empty( $post_terms ) && ! is_wp_error( $post_terms ) ){ |
| 94 |
foreach ( $post_terms as $term ) { |
| 95 |
if(empty($term->post_title)){ |
| 96 |
$options[ $term->ID ] = $gbox_untitle.'-'.$term->ID; |
| 97 |
}else{ |
| 98 |
$options[ $term->ID ] = $term->post_title; |
| 99 |
} |
| 100 |
} |
| 101 |
return $options; |
| 102 |
} |
| 103 |
} |
| 104 |
|