|
|
|
<?php
|
|
|
|
|
|
|
|
function have_to_run_this_week($startdate_s, $cadence_i)
|
|
|
|
{
|
|
|
|
$today = (new DateTime())->setTime(0,0,0);
|
|
|
|
if (!empty($startdate_s)) {
|
|
|
|
$startdate = new DateTime($startdate_s);
|
|
|
|
if ($startdate > $today)
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
$cadence_i = 1;
|
|
|
|
}
|
|
|
|
$return_value;
|
|
|
|
switch($cadence_i) {
|
|
|
|
case 1: //settimanale
|
|
|
|
$return_value = true;
|
|
|
|
break;
|
|
|
|
case 2: //ogni 2 settimane
|
|
|
|
case 3: //ogni 3 settimane
|
|
|
|
case 4: //ogni 4 settimane
|
|
|
|
$modulo = 7 * $cadence_i;
|
|
|
|
$today->modify("this week {$startdate->format('l')}");
|
|
|
|
$date_difference = date_diff($today, $startdate);
|
|
|
|
$days_difference = $date_difference->days;
|
|
|
|
if (($days_difference % $modulo) == 0) {
|
|
|
|
$return_value = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$return_value = false;
|
|
|
|
break;
|
|
|
|
case 5: //una volta al mese
|
|
|
|
print_r($startdate);
|
|
|
|
if (which_day_of_the_month($startdate) == which_day_of_the_month($today)) {
|
|
|
|
$return_value = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$return_value = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return $return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
function which_day_of_the_month($datetime)
|
|
|
|
{
|
|
|
|
$datetime->setTime(0,0,0);
|
|
|
|
$weekday_literal = $datetime->format("l");
|
|
|
|
$weekday_iterator = clone($datetime);
|
|
|
|
$weekday_iterator->modify("first $weekday_literal of this month");
|
|
|
|
$count = 1;
|
|
|
|
while($datetime != $weekday_iterator && $count < 5) {
|
|
|
|
$weekday_iterator->modify("next $weekday_literal");
|
|
|
|
$count++;
|
|
|
|
}
|
|
|
|
return $count;
|
|
|
|
}
|
|
|
|
|
|
|
|
function show_palinsesto($args)
|
|
|
|
{
|
|
|
|
$week_days = ['Lunedì','Martedì','Mercoledì','Giovedì','Venerdì','Sabato','Domenica'];
|
|
|
|
$tabs = $content = "";
|
|
|
|
|
|
|
|
$broadcast_post = array(
|
|
|
|
'post_type' => 'broadcast',
|
|
|
|
'numberposts' => -1
|
|
|
|
);
|
|
|
|
|
|
|
|
$broadcasts = get_posts($broadcast_post);
|
|
|
|
$palinsesto = [];
|
|
|
|
|
|
|
|
foreach ($broadcasts as $post) {
|
|
|
|
$on_air_day = $on_air_start = $on_air_end = $on_air_cadence = $on_air_startdate = "";
|
|
|
|
for ($d=0;$d<7;$d++) {
|
|
|
|
$on_air_day = get_post_meta($post->ID, 'on_air_day_'.$d, true);
|
|
|
|
$on_air_start = get_post_meta($post->ID, 'on_air_start_'.$d, true);
|
|
|
|
$on_air_end = get_post_meta($post->ID, 'on_air_end_'.$d, true);
|
|
|
|
$on_air_cadence = get_post_meta($post->ID, 'on_air_cadence_'.$d, true);
|
|
|
|
$on_air_startdate = get_post_meta($post->ID, 'on_air_startdate_'.$d, true);
|
|
|
|
|
|
|
|
if (empty($on_air_cadence) || empty($on_air_startdate)) {
|
|
|
|
$on_air_cadence = "1";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($on_air_day)&&!empty($on_air_start)&&!empty($on_air_end)) {
|
|
|
|
|
|
|
|
if (have_to_run_this_week($on_air_startdate, (int)$on_air_cadence)) {
|
|
|
|
$palinsesto[(int)$on_air_day][(string)$on_air_start] =
|
|
|
|
array(
|
|
|
|
'ID' => $post->ID,
|
|
|
|
'start' => $on_air_start,
|
|
|
|
'end' => $on_air_end,
|
|
|
|
'on_air' => true,
|
|
|
|
'title' => $post->post_title,
|
|
|
|
'excerpt' => $post->post_excerpt,
|
|
|
|
'thumb_url' => get_the_post_thumbnail_url($post->ID, 'full'),
|
|
|
|
'the_permalink' => get_permalink($post->ID),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$rerun_day = $rerun_start = $rerun_end = $rerun_cadence = $rerun_startdate = "";
|
|
|
|
for ($d=0;$d<7;$d++) {
|
|
|
|
$rerun_day = get_post_meta($post->ID, 'rerun_day_'.$d, true);
|
|
|
|
$rerun_start = get_post_meta($post->ID, 'rerun_start_'.$d, true);
|
|
|
|
$rerun_end = get_post_meta($post->ID, 'rerun_end_'.$d, true);
|
|
|
|
$rerun_cadence = get_post_meta($post->ID, 'rerun_cadence_'.$d, true);
|
|
|
|
$rerun_startdate = get_post_meta($post->ID, 'rerun_startdate_'.$d, true);
|
|
|
|
|
|
|
|
if (!empty($rerun_day)&&!empty($rerun_start)&&!empty($rerun_end)) {
|
|
|
|
|
|
|
|
if (empty($rerun_cadence) || empty($rerun_startdate)) {
|
|
|
|
$rerun_cadence = "1"; //default settimanale
|
|
|
|
}
|
|
|
|
|
|
|
|
if (have_to_run_this_week($rerun_startdate, (int)$rerun_cadence)) {
|
|
|
|
$palinsesto[(int)$rerun_day][(string)$rerun_start] =
|
|
|
|
array(
|
|
|
|
'ID' => $post->ID,
|
|
|
|
'start' => $rerun_start,
|
|
|
|
'end' => $rerun_end,
|
|
|
|
'on_air' => false,
|
|
|
|
'title' => $post->post_title,
|
|
|
|
'excerpt' => $post->post_excerpt,
|
|
|
|
'thumb_url' => get_the_post_thumbnail_url($post->ID, 'full'),
|
|
|
|
'the_permalink' => get_permalink($post->ID),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ksort($palinsesto);
|
|
|
|
$today = date("N");
|
|
|
|
|
|
|
|
for ($x=1;$x<=7;$x++) {
|
|
|
|
|
|
|
|
if ($x == $today)
|
|
|
|
$tabs .= "<li class='default-gator-tab'>".$week_days[$x-1]."</li>";
|
|
|
|
else
|
|
|
|
$tabs .= "<li>".$week_days[$x-1]."</li>";
|
|
|
|
$content .= '<li class="gator-tab">';
|
|
|
|
|
|
|
|
if (!empty($palinsesto[$x])) {
|
|
|
|
ksort($palinsesto[$x]);
|
|
|
|
foreach ($palinsesto[$x] as $hour => $broadcast) {
|
|
|
|
$content .= '<div class="single-broadcast ';
|
|
|
|
$content .= (!$broadcast['on_air']) ? "rerun" : "onair";
|
|
|
|
$content .= '">';
|
|
|
|
$content .= '<a href="'.$broadcast['the_permalink'].'" title="'.$broadcast['title'].'">';
|
|
|
|
$content .= '<h4 class="broadcast-title">'.$broadcast['title'].'</h4>';
|
|
|
|
$content .= '</a>';
|
|
|
|
/* Indico sotto al titolo se la trasmissione è una replica o una diretta */
|
|
|
|
$content .= (!$broadcast['on_air']) ? "[replica]" : "[diretta]";
|
|
|
|
$content .= '<p class="broadcast-time">'.$broadcast['start'].' - '.$broadcast['end'].'</p>';
|
|
|
|
$content .= '<p class="broadcast-excerpt">'.$broadcast['excerpt'].'</p>';
|
|
|
|
$content .= "</div>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$content .= '</li>';
|
|
|
|
} ?>
|
|
|
|
|
|
|
|
<div class="gator-tabs-container">
|
|
|
|
<ul class="gator-tabs-header">
|
|
|
|
<?php echo $tabs; ?>
|
|
|
|
</ul>
|
|
|
|
<ul class="gator-tabs">
|
|
|
|
<?php echo $content; ?>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
wp_enqueue_style('palinsesto_style', plugin_dir_url(__FILE__).'css/palinsesto.css', array(), '1.0', 'screen');
|
|
|
|
wp_enqueue_script('palinsesto_js', plugin_dir_url(__FILE__).'js/palinsesto.js', array(), '1.0', true);
|
|
|
|
}
|
|
|
|
add_shortcode('palinsesto', 'show_palinsesto');
|