-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.php
141 lines (133 loc) · 6.88 KB
/
main.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<script type="text/javascript" src="https://www.youtube.com/iframe_api"></script>
<link rel='stylesheet' href='<?php echo site_url(); ?>/wp-admin/load-styles.php?load%5B%5D=dashicons' type='text/css' media='all' />
<style type="text/css">
<?php
echo file_get_contents(dirname(__FILE__).'/js/vendor/owl_carousel/assets/owl.carousel.css').
file_get_contents(dirname(__FILE__).'/css/bootstrap.min.css').
file_get_contents(dirname(__FILE__).'/css/style.css');
?>
</style>
<script type="text/javascript">
if(document.getElementById('<?php echo get_field('slider_id', 'option'); ?>')){
<?php
echo file_get_contents(dirname(__FILE__).'/js/vendor/gs/TweenMax.min.js').
file_get_contents(dirname(__FILE__).'/js/vendor/gs/TimelineMax.min.js').
file_get_contents(dirname(__FILE__).'/js/vendor/gs/plugins/EndArrayPlugin.min.js').
file_get_contents(dirname(__FILE__).'/js/vendor/owl_carousel/owl.carousel.min.js').
file_get_contents(dirname(__FILE__).'/js/vendor/gs/plugins/EndArrayPlugin.min.js').
file_get_contents(dirname(__FILE__).'/js/vendor/fit.min.js').
file_get_contents(dirname(__FILE__).'/js/vendor/jquery.fitvids.js').
file_get_contents(dirname(__FILE__).'/js/slider.js');
?>
window.zSlider.__proto__.id = '<?php echo get_field('slider_id', 'option'); ?>';
window.zSlider.var.siteurl = '<?php echo get_option('siteurl'); ?>';
window.zSlider.var.template_directory_uri = '<?php echo get_template_directory_uri(); ?>';
window.zSlider.var.slider_autoplay = <?php echo get_field('slider_autoplay', 'option'); ?>;
window.zSlider.var.slides = [<?php
$slides = get_field('slide', 'option');
$i = 0;
$len = 0;
$background_video_embed_script = '';
$onYouTubeIframeAPIReady = '';
if ( $slides ) {
foreach( $slides as $slide):
if( $slide['enabled'] == 'true' ) {
$len++;
}
endforeach;
foreach( $slides as $slide ):
if( $slide['enabled'] == 'true' ) {
$i++;
if ( $slide['background_video_embed'] != '' ){
$characters = 'abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randstring = '';
for ($i2 = 0; $i2 < 12; $i2++) {
$randstring .= $characters[rand(0, strlen($characters) - 1)];
}
$slide['background_video_embed_id'] = $randstring;
$iframe = $slide['background_video_embed'];
preg_match('/src="(.+?)"/', $iframe, $matches);
$src = $matches[1];
$pos = strrpos($src, '/') + 1;
if ($pos){
$id = substr($src, $pos);
$posEnd = strpos($id, '?');
$ytid = substr($id, 0, $posEnd);
$slide['background_video_embed_ytid'] = $ytid;
$onYouTubeIframeAPIReady .= '
window.player_' . $randstring . ' = new YT.Player("' . $randstring . '", {
playerVars: {
"rel": 0,
"controls": 0,
"showinfo": 0,
"autohide": 1,
"loop": 1,
"fs": 0,
"html5": 1,
"modestbranding": 1,
"enablejsapi": 1,
"playlist": "'.$ytid.'"
},
events: {
"onReady": window.onPlayerReady_' . $randstring .'
}
});
';
$background_video_embed_script .= '
window.playVideo_' . $randstring . ' = function() {
window.player_' . $randstring . '.playVideo();
}
window.stopVideo_' . $randstring . ' = function() {
window.player_' . $randstring . '.pauseVideo();
}
window.onPlayerReady_' . $randstring .' = function(){
window.player_' . $randstring . '.setVolume(' . $slide['background_video_volume'] . ');
window.player_' . $randstring . '.playVideo();
setTimeout(function(){
window.player_' . $randstring . '.pauseVideo();
window.player_' . $randstring . '.seekTo(0, false);
}, 500);
}
';
}
$params = array();
if ( stripos(strtolower($src), 'youtube.com') ) {
$params = array(
'rel' => 0,
'controls' => 0,
'showinfo' => 0,
'autohide' => 1,
'loop' => 1,
'fs' => 0,
'html5' => 1,
'modestbranding' => 1,
'enablejsapi' => 1,
'playlist' => $ytid
);
}
$new_src = add_query_arg($params, $src);
$attributes = 'frameborder="0"';
$iframe = '<iframe class="yt" id="' . $randstring . '" height="360" width="640" src="' . $new_src . '" '. $attributes .' allowfullscreen></iframe>';
$slide['background_video_embed'] = $iframe;
}
echo json_encode($slide);
}
if ( $i < $len && $i != 0 ) {
echo ',';
}
endforeach;
}
?>];
window.onYouTubeIframeAPIReady = function() {
setTimeout(function(){
jQuery("iframe.yt").parent().fitVids();
<?php echo $onYouTubeIframeAPIReady; ?>
window.zSlider.var.onYouTubeIframeAPIReadyFired = true;
setTimeout(function(){
window.zSlider.triggerYoutube('play');
}, 2000);
}, 1000);
}
<?php echo $background_video_embed_script; ?>
}
</script>