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.

115 lines
4.8 KiB
PHP

<?php
function show_palinsesto($args)
{
$week_days = ['Luned&igrave;','Marted&igrave;','Mercoled&igrave;','Gioved&igrave;','Venerd&igrave;','Sabato','Domenica'];
$tabs = $content = "";
$broadcast_post = array(
'post_type' => 'broadcast',
'numberposts' => -1
);
//$broadcast = new WP_Query($broadcast_post);
$broadcast = get_posts($broadcast_post);
$palinsesto = [];
//foreach ($broadcast->posts as $post) {
foreach ($broadcast as $post) {
$on_air_day = $on_air_start = $on_air_end = [];
for ($d=0;$d<7;$d++) {
$on_air_day[] = get_post_meta($post->ID, 'on_air_day_'.$d, false);
$on_air_start[] = get_post_meta($post->ID, 'on_air_start_'.$d, false);
$on_air_end[] = get_post_meta($post->ID, 'on_air_end_'.$d, false);
if (!empty($on_air_day[$d][0])&&!empty($on_air_start[$d][0])&&!empty($on_air_end[$d][0])) {
$palinsesto[$on_air_day[$d][0]][(string) $on_air_start[$d][0]] =
array(
'ID' => $post->ID,
'start' => $on_air_start[$d][0],
'end' => $on_air_end[$d][0],
'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 = [];
for ($d=0;$d<7;$d++) {
$rerun_day[] = get_post_meta($post->ID, 'rerun_day_'.$d, false);
$rerun_start[] = get_post_meta($post->ID, 'rerun_start_'.$d, false);
$rerun_end[] = get_post_meta($post->ID, 'rerun_end_'.$d, false);
if (!empty($rerun_day[$d][0])&&!empty($rerun_start[$d][0])&&!empty($rerun_end[$d][0])) {
$palinsesto[$rerun_day[$d][0]][(string) $rerun_start[$d][0]] =
array(
'ID' => $post->ID,
'start' => $rerun_start[$d][0],
'end' => $rerun_end[$d][0],
'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);
/*echo '<pre>';
print_r($palinsesto);
echo '</pre>';*/
$today = date("N");
for ($x=1;$x<=7;$x++) {
/*echo '<pre>';
echo("$today,$x");
echo '</pre>';*/
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 $key => $broadcast) {
$content .= '<div class="single-broadcast ';
$content .= (!$broadcast['on_air']) ? "rerun" : "onair";
$content .= '">';
//$content .= '" style="background:url(\''.$broadcast['thumb_url'].'\') no-repeat center center;background-size:cover;">';
//$content .= '<p class="img-url">'.$broadcast['thumb_url'].'</p>';
$content .= '<a href="'.$broadcast['the_permalink'].'" title="'.$broadcast['title'].'">';
/* $content .= '<img class="img-broadcast" src="'.$broadcast['thumb_url'].'" alt="'.$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 .= '<p>'.$broadcast['the_permalink'].'</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');