You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.0 KiB
PHP
76 lines
2.0 KiB
PHP
<?php
|
|
/*
|
|
|
|
La funzione what_play_now funzione da per scontato che non ci siano trasmissioni con piu' di una diretta
|
|
a settimana nello stesso giorno.
|
|
|
|
*/
|
|
|
|
function what_play_now($args)
|
|
{
|
|
|
|
global $wpdb;
|
|
/* Oggi espresso come $day (giorno della settimana 1-7 a partire da lunedì) e $now oggetto DateTime completo */
|
|
$day = date("N");
|
|
$now = new DateTime("NOW");
|
|
$done = false;
|
|
|
|
/* Cerco nelle dirette */
|
|
|
|
/* Prendo dalla tabella wp_postmeta le tramissioni con diretta oggi e le repliche */
|
|
$today_onair = $wpdb->get_results("
|
|
SELECT post_id, meta_key FROM wp_postmeta
|
|
WHERE meta_key BETWEEN 'on_air_day_0' AND 'on_air_day_6'
|
|
AND meta_value = '$day'
|
|
");
|
|
$today_rerun = $wpdb->get_results("
|
|
SELECT post_id, meta_key FROM wp_postmeta
|
|
WHERE meta_key BETWEEN 'rerun_day_0' AND 'rerun_day_6'
|
|
AND meta_value = '$day'
|
|
");
|
|
|
|
/* Inserisco in un array le trasmissioni */
|
|
$broadcast_to_check = [];
|
|
|
|
foreach ($today_onair as $t) {
|
|
array_push($broadcast_to_check, (array) $t );
|
|
}
|
|
foreach ($today_rerun as $t) {
|
|
array_push($broadcast_to_check, (array) $t );
|
|
}
|
|
|
|
foreach($broadcast_to_check as $broadcast) {
|
|
$post_id = $broadcast['post_id'];
|
|
$day_meta_key = $broadcast['meta_key'];
|
|
$meta_key_start = str_replace("day", "start", $day_meta_key);
|
|
$meta_key_end = str_replace("day", "end", $day_meta_key);
|
|
/* Estraggo la fascia oraria e controllo ne $now è contenuto nel range */
|
|
$start_timestring = ($wpdb->get_results("
|
|
SELECT meta_value FROM wp_postmeta
|
|
WHERE post_id = '$post_id' AND meta_key = '$meta_key_start'
|
|
"))[0]->meta_value;
|
|
$end_timestring = ($wpdb->get_results("
|
|
SELECT meta_value FROM wp_postmeta
|
|
WHERE post_id = '$post_id' AND meta_key = '$meta_key_end'
|
|
"))[0]->meta_value;
|
|
|
|
$start = new DateTime("$start_timestring");
|
|
$end = new DateTime("$end_timestring");
|
|
|
|
if ($now >= $start && $now <= $end) {
|
|
$done = true;
|
|
return get_post($post_id)->post_title;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!$done) {
|
|
return "Selezione musicale";
|
|
}
|
|
|
|
}
|
|
|
|
add_shortcode('whatplaynow', 'what_play_now');
|
|
|
|
?>
|