-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview.php
200 lines (173 loc) · 5.6 KB
/
view.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<script>
var outd_i_media;
var outd_start_timer = false;
var outd_interval;
function outd_open_fullscreen() {
var elem = document.getElementById("outd_media");
if (elem.requestFullscreen) {
elem.requestFullscreen();
} else if (elem.webkitRequestFullscreen) { /* Safari */
elem.webkitRequestFullscreen();
} else if (elem.msRequestFullscreen) { /* IE11 */
elem.msRequestFullscreen();
}
}
function outd_start_media(){
outd_open_fullscreen();
if (!outd_start_timer){
outd_start_timer = true;
outd_interval = setInterval(outd_processa_media, 1000);
}
}
function outd_end_media(){
clearInterval(outd_interval);
outd_start_timer = false;
}
function outd_processa_media(){
if (!document.getElementById("outd_list_media").getElementsByTagName('figure')[0]){
alert('Nenhuma mídia para exibição');
outd_end_media();
return false;
}
let indx = document.getElementById("outd_list_media").getAttribute('indx') || 0;
if (!document.getElementById("outd_list_media").getElementsByTagName('figure')[indx]){
indx = 0;
}
let item = document.getElementById("outd_list_media").getElementsByTagName('figure')[indx];
if (item.classList.contains('start')){
return false;
}
if (item.classList.contains('end')){
document.getElementById("outd_list_media").setAttribute('indx',parseInt(indx)+1)
item.classList.remove('active');
item.classList.remove('start');
item.classList.remove('end');
return false;
}
item.classList.add('active');
item.classList.add('start');
let url = item.getAttribute("data-url");
let duration = item.getAttribute("data-duration");
let fit = item.getAttribute("data-fit");
let mime = item.getAttribute("data-mime");
let type = mime.split('/')[0];
if (type == "image"){
document.getElementById('outd_media').innerHTML=`
<img src='${url}' style='object-fit: ${fit};'>`;
setTimeout(function(){
item.classList.add("end");
item.classList.remove("start");
}, duration * 1000);
}else if ((type == "video") && (mime != "video/x-ms-wmv")){
document.getElementById('outd_media').innerHTML=`
<video c_ontrols autoplay muted>
<source src='${url}' type='${mime}'>
Navegador não suporta vídeos...`;
document.getElementById('outd_media')
.getElementsByTagName('video')[0]
.onended = function(){
item.classList.add('end');
item.classList.remove('start');
};
}else{
item.classList.add('end');
item.classList.remove('start');
}
}
</script>
<style>
#outd_media img,#outd_media video{
width:100%;
height:100%;
border:0;
margin:0;
padding:0;
}
#outd_media img{
object-fit: contain;
}
#outd_list_media figure.active{
border: 2px solid #ffd100;
}
</style>
<div class="is-content-justification-center is-layout-flex wp-container-6 wp-block-buttons">
<div class="wp-block-button">
<a id="outd_btn_start" class="wp-block-button__link wp-element-button" onclick='outd_start_media()'>
Iniciar Outdoor
</a>
</div>
</div>
<div id="outd_media" style="margin:10px;"></div>
<?php
$outd_options = get_option('outdoor_options');
$outd_order = 'outdoor.outdoor_order';
if (isset($outd_options["random"]) && $outd_options["random"] == 1) {
$outd_order = 'RAND()';
}
$sql = "
SELECT
outdoor.outdoor_id,
posts.post_title,
posts.post_name,
posts.post_mime_type,
posts.guid,
outdoor.outdoor_status,
outdoor.outdoor_order,
outdoor.outdoor_start_date,
outdoor.outdoor_end_date,
outdoor.outdoor_object_fit,
outdoor.outdoor_duration
FROM " . $wpdb->prefix . "outdoor outdoor
INNER JOIN " . $wpdb->prefix . "posts posts ON posts.id = outdoor.post_id
WHERE 1=1
AND outdoor.outdoor_status='active'
AND (outdoor.outdoor_start_date IS NULL OR outdoor.outdoor_start_date = '0000-00-00' OR outdoor.outdoor_start_date <= DATE(NOW()))
AND (outdoor.outdoor_end_date IS NULL OR outdoor.outdoor_end_date = '0000-00-00' OR outdoor.outdoor_end_date >= DATE(NOW()))
ORDER BY $outd_order
";
$result = $wpdb->get_results($sql);
$i = 0;
?>
<figure id="outd_list_media" class="is-layout-flex wp-block-gallery has-nested-images columns-default is-cropped" style="align-items: center;justify-content: center;padding-top:10px;">
<?php
foreach ($result as $linha) {
$max_w = 100;
$max_h = 70;
$mime = explode('/', $linha->post_mime_type);
$embed = '';
$url = $linha->guid;
$fit = $linha->outdoor_object_fit;
switch ($mime[0]) {
case 'image':
$embed = "<img src='{$url}' style='width:{$max_w}px;height:{$max_h}px;object-fit: {$fit};'>";
break;
default:
$embed = "<img src='" . OUTD_URL_IMG . "video.png' style='width:{$max_w}px;height:{$max_h}px;object-fit: contain;background:#F0F0F1;padding:5px;'>";
//$embed = "
//<video muted style='max-width:{$max_w}px;max-height:{$max_h}px;'>
//<source src='{$url}' type='{$item['post_mime_type']}'>
//";
break;
}
echo "
<figure
style='width:calc({$max_w}px + 10px);padding:3px;'
data-name='" . @$linha->post_title . "'
data-url='" . @$linha->guid . "'
data-duration='" . @$linha->outdoor_duration . "'
data-mime='" . @$linha->post_mime_type . "'
data-fit='" . @$linha->outdoor_object_fit . "'
>
<div>$embed</div>
<div style='
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-size:12px;
'>$linha->post_title</div>
</figure>
";
$i++;
}
?>
</figure>