added heve_to_run fun & modification

master
campi 2 years ago
parent 3bf7ef779c
commit 758d5113ed

@ -42,9 +42,7 @@ function live_meta_box_add()
function orari_dirette_input($post)
{
$values = get_post_custom($post->ID);
$onair_cadence = array();
$text_start = array();
$text_end = array();
$onair_cadence = $onair_start_date = $onair_start = $onair_end = array();
wp_nonce_field('on_air_nonce', 'onair_nonce');
$broadcast = term_exists('Podcast', 'category', 0);
$old_term = term_exists($post->post_title, 'category', $broadcast);
@ -53,13 +51,14 @@ function orari_dirette_input($post)
<?php
for ($x=0;$x<7;$x++) :
$onair_day[$x] = isset($values['on_air_day_'.$x]) ? esc_attr($values['on_air_day_'.$x][0]) : '';
$onair_cadence[$x] = isset($values['on_air_cadence'.$x]) ? esc_attr($values['on_air_cadence'.$x][0]) : '';
$text_start[$x] = isset($values['on_air_start_'.$x]) ? esc_attr($values['on_air_start_'.$x][0]) : '';
$text_end[$x] = isset($values['on_air_end_'.$x]) ? esc_attr($values['on_air_end_'.$x][0]) : '';
$onair_cadence[$x] = isset($values['on_air_cadence_'.$x]) ? esc_attr($values['on_air_cadence_'.$x][0]) : '';
$onair_start_date[$x] = isset($values['on_air_start_date_'.$x]) ? esc_attr($values['on_air_start_date_'.$x][0]) : '';
$onair_start[$x] = isset($values['on_air_start_'.$x]) ? esc_attr($values['on_air_start_'.$x][0]) : '';
$onair_end[$x] = isset($values['on_air_end_'.$x]) ? esc_attr($values['on_air_end_'.$x][0]) : '';
$broadcast[$x] = term_exists('Podcast', 'category', 0);
$old_term[$x] = term_exists($post->post_title, 'category', $broadcast); ?>
<div style='width:25%;float:left;'>
<div style='width:20%;float:left;'>
<select name="on_air_day_<?php echo $x; ?>" id="on_air_day_<?php echo $x; ?>">
<option <?php echo ($onair_day[$x]=='') ? 'selected="selected"' : ''; ?> value="">Seleziona un giorno</option>
<option <?php echo ($onair_day[$x]==1) ? 'selected="selected"' : ''; ?> value="1">Luned&igrave;</option>
@ -71,22 +70,25 @@ function orari_dirette_input($post)
<option <?php echo ($onair_day[$x]==7) ? 'selected="selected"' : ''; ?> value="7">Domenica</option>
</select>
</div>
<div style='width:25%;float:left;'>
<div style='width:20%;float:left;'>
<label for="onair_start_date_<?php echo $x; ?>">Data inizio</label>
<input type="date" name="on_air_start_date_<?php echo $x; ?>" id="on_air_start_date_<?php echo $x; ?>" value="<?php echo $onair_start_date[$x]; ?>" style="width: 40%;" />
</div>
<div style='width:20%;float:left;'>
<select name="on_air_cadence_<?php echo $x; ?>" id="on_air_cadence_<?php echo $x; ?>">
<label for="on_air_cadence_<?php echo $x; ?>">Cadenza</label>
<option <?php echo ($onair_cadence[$x]=='') ? 'selected="selected"' : ''; ?> value="">Seleziona una cadenza</option>
<option <?php echo ($onair_cadence[$x]==1) ? 'selected="selected"' : ''; ?> value="1">Una volta a settimana</option>
<option <?php echo ($onair_cadence[$x]==2) ? 'selected="selected"' : ''; ?> value="2">Due volte al mese</option>
<option <?php echo ($onair_cadence[$x]==3) ? 'selected="selected"' : ''; ?> value="3">Una volta al mese</option>
<option <?php echo ($onair_cadence[$x]==2) ? 'selected="selected"' : ''; ?> value="2">Una volta ogni 2 settimane</option>
<option <?php echo ($onair_cadence[$x]==4) ? 'selected="selected"' : ''; ?> value="4">Una volta ogni 4 settimane</option>
</select>
</div>
<div style='width:25%;float:left;'>
<div style='width:20%;float:left;'>
<label for="on_air_start_<?php echo $x; ?>">Ora inizio</label>
<input type="time" name="on_air_start_<?php echo $x; ?>" id="on_air_start_<?php echo $x; ?>" value="<?php echo $text_start[$x]; ?>" style="width: 30%;" />
<input type="time" name="on_air_start_<?php echo $x; ?>" id="on_air_start_<?php echo $x; ?>" value="<?php echo $onair_start[$x]; ?>" style="width: 40%;" />
</div>
<div style='width:25%;float:left;'>
<div style='width:20%;float:left;'>
<label for="on_air_end_<?php echo $x; ?>">Ora fine</label>
<input type="time" name="on_air_end_<?php echo $x; ?>" id="on_air_end_<?php echo $x; ?>" value="<?php echo $text_end[$x]; ?>" style="width: 30%;" />
<input type="time" name="on_air_end_<?php echo $x; ?>" id="on_air_end_<?php echo $x; ?>" value="<?php echo $onair_end[$x]; ?>" style="width: 40%;" />
</div>
<div style="clear:both;"></div>
<?php
@ -96,19 +98,19 @@ function orari_dirette_input($post)
function orari_repliche_input($post)
{
$values = get_post_custom($post->ID);
$rerun_cadence = array();
$text_start = array();
$text_end = array();
$rerun_day = $rerun_cadence = $rerun_start_date = $rerun_start = $rerun_end = array();
wp_nonce_field('rerun_nonce', 're_run_nonce');
for ($x=0;$x<7;$x++) :
$rerun_day[$x] = isset($values['rerun_day_'.$x]) ? esc_attr($values['rerun_day_'.$x][0]) : '';
$rerun_cadence[$x] = isset($values['on_air_cadence'.$x]) ? esc_attr($values['on_air_cadence'.$x][0]) : '';
$text_start[$x] = isset($values['rerun_start_'.$x]) ? esc_attr($values['rerun_start_'.$x][0]) : '';
$text_end[$x] = isset($values['rerun_end_'.$x]) ? esc_attr($values['rerun_end_'.$x][0]) : ''; ?>
$rerun_start[$x] = isset($values['rerun_start_'.$x]) ? esc_attr($values['rerun_start_'.$x][0]) : '';
$rerun_end[$x] = isset($values['rerun_end_'.$x]) ? esc_attr($values['rerun_end_'.$x][0]) : '';
$rerun_cadence[$x] = isset($values['rerun_cadence_'.$x]) ? esc_attr($values['rerun_cadence_'.$x][0]) : '';
$rerun_start_date[$x] = isset($values['rerun_start_date_'.$x]) ? esc_attr($values['rerun_start_date_'.$x][0]) : '';
?>
<div style='width:100%;float:left;'>
<h3>Replica n. <?php echo $x+1; ?></h3>
</div>
<div style='width:25%;float:left;'>
<div style='width:20%;float:left;'>
<select name="rerun_day_<?php echo $x; ?>" id="rerun_day_<?php echo $x; ?>">
<option <?php echo ($rerun_day[$x]=='') ? 'selected="selected"' : ''; ?> value="">Seleziona un giorno</option>
<option <?php echo ($rerun_day[$x]==1) ? 'selected="selected"' : ''; ?> value="1">Luned&igrave;</option>
@ -120,22 +122,25 @@ function orari_repliche_input($post)
<option <?php echo ($rerun_day[$x]==7) ? 'selected="selected"' : ''; ?> value="7">Domenica</option>
</select>
</div>
<div style='width:25%;float:left;'>
<select name="rerun_cadence_<?php echo $x; ?>" id="on_air_cadence_<?php echo $x; ?>">
<div style='width:20%;float:left;'>
<label for="rerun_start_date_<?php echo $x; ?>">Data inizio</label>
<input type="date" name="rerun_start_date_<?php echo $x; ?>" id="rerun_start_date_<?php echo $x; ?>" value="<?php echo $rerun_start_date[$x]; ?>" style="width: 40%;" />
</div>
<div style='width:20%;float:left;'>
<select name="rerun_cadence_<?php echo $x; ?>" id="rerun_cadence_<?php echo $x; ?>">
<label for="rerun_cadence_<?php echo $x; ?>">Cadenza</label>
<option <?php echo ($rerun_cadence[$x]=='') ? 'selected="selected"' : ''; ?> value="">Seleziona una cadenza</option>
<option <?php echo ($rerun_cadence[$x]==1) ? 'selected="selected"' : ''; ?> value="1">Una volta a settimana</option>
<option <?php echo ($rerun_cadence[$x]==2) ? 'selected="selected"' : ''; ?> value="2">Due volte al mese</option>
<option <?php echo ($rerun_cadence[$x]==3) ? 'selected="selected"' : ''; ?> value="3">Una volta al mese</option>
<option <?php echo ($rerun_cadence[$x]==2) ? 'selected="selected"' : ''; ?> value="2">Una volta ogni 2 settimane</option>
<option <?php echo ($rerun_cadence[$x]==4) ? 'selected="selected"' : ''; ?> value="4">Una volta ogni 4 settimane</option>
</select>
</div>
<div style='width:25%;float:left;'>
<div style='width:20%;float:left;'>
<label for="rerun_start_<?php echo $x; ?>">Ora inizio</label>
<input type="time" name="rerun_start_<?php echo $x; ?>" id="rerun_start_<?php echo $x; ?>" value="<?php echo $text_start[$x]; ?>" style="width: 30%;" />
<input type="time" name="rerun_start_<?php echo $x; ?>" id="rerun_start_<?php echo $x; ?>" value="<?php echo $rerun_start[$x]; ?>" style="width: 40%;" />
</div>
<div style='width:25%;float:left;'>
<div style='width:20%;float:left;'>
<label for="rerun_end_<?php echo $x; ?>">Ora fine</label>
<input type="time" name="rerun_end_<?php echo $x; ?>" id="rerun_end_<?php echo $x; ?>" value="<?php echo $text_end[$x]; ?>" style="width: 30%;" />
<input type="time" name="rerun_end_<?php echo $x; ?>" id="rerun_end_<?php echo $x; ?>" value="<?php echo $rerun_end[$x]; ?>" style="width: 40%;" />
</div>
<div style="clear:both;"></div>
<?php
@ -199,10 +204,12 @@ function orari_dirette_save($post_id)
update_post_meta($post_id, 'on_air_start_'.$x, wp_kses($_POST['on_air_start_'.$x], $allowed));
update_post_meta($post_id, 'on_air_end_'.$x, wp_kses($_POST['on_air_end_'.$x], $allowed));
update_post_meta($post_id, 'on_air_cadence_'.$x, wp_kses($_POST['on_air_cadence_'.$x], $allowed));
update_post_meta($post_id, 'on_air_start_date_'.$x, wp_kses($_POST['on_air_start_date_'.$x], $allowed));
update_post_meta($post_id, 'rerun_day_'.$x, wp_kses($_POST['rerun_day_'.$x], $allowed));
update_post_meta($post_id, 'rerun_start_'.$x, wp_kses($_POST['rerun_start_'.$x], $allowed));
update_post_meta($post_id, 'rerun_end_'.$x, wp_kses($_POST['rerun_end_'.$x], $allowed));
update_post_meta($post_id, 'rerun_cadence_'.$x, wp_kses($_POST['rerun_end_'.$x], $allowed));
update_post_meta($post_id, 'rerun_start_date_'.$x, wp_kses($_POST['rerun_start_date_'.$x], $allowed));
}
}
}

@ -1,5 +1,30 @@
<?php
function have_to_run_this_week($start_date, $cadence)
{
$return_value;
switch($cadence) {
case 1:
$return_value = true;
break;
case 2:
case 4:
$date = getdate(strtotime($start_date));
$today = getdate(date("U"));
$modulo = 7 * $cadence;
$date_difference = date_diff($today, $date);
$days_difference = $date_difference["days"];
if (($days_difference % $modulo) < 7) {
$return_value = true;
break;
}
$return_value = false;
break;
}
return $return_value
}
function show_palinsesto($args)
{
$week_days = ['Luned&igrave;','Marted&igrave;','Mercoled&igrave;','Gioved&igrave;','Venerd&igrave;','Sabato','Domenica'];
@ -10,49 +35,60 @@ function show_palinsesto($args)
'numberposts' => -1
);
//$broadcast = new WP_Query($broadcast_post);
$broadcast = get_posts($broadcast_post);
$broadcasts = get_posts($broadcast_post);
$palinsesto = [];
//foreach ($broadcast->posts as $post) {
foreach ($broadcast as $post) {
$on_air_day = $on_air_start = $on_air_end = [];
foreach ($broadcasts as $post) {
$on_air_day = $on_air_start = $on_air_end = $on_air_cadence = $on_air_start_date = "";
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);
$on_air_cadence[] = get_post_meta($post->ID, 'on_air_cadence_'.$d, false); //added
if (!empty($on_air_day[$d][0])&&!empty($on_air_start[$d][0])&&!empty($on_air_end[$d][0])&&!empty($on_air_cadence[$d][0])) {
if (!isset($palinsesto[$on_air_day[$d][0]][(string) $on_air_start[$d][0]])){
$palinsesto[$on_air_day[$d][0]][(string) $on_air_start[$d][0]] = array();
$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_start_date = get_post_meta($post->ID, 'on_air_start_date_'.$d, true);
if (empty($on_air_cadence) || empty($on_air_start_date)) {
$on_air_cadence = "1";
}
array_push($palinsesto[$on_air_day[$d][0]] [(string)$on_air_start[$d][0]],
if (!empty($on_air_day)&&!empty($on_air_start)&&!empty($on_air_end)) {
if (have_to_run_this_week($on_air_start_date, (int)$on_air_cadence)) {
$palinsesto[(int)$on_air_day][(string)$on_air_start] =
array(
'ID' => $post->ID,
'start' => $on_air_start[$d][0],
'end' => $on_air_end[$d][0],
'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_day = $rerun_start = $rerun_end = $rerun_cadence = $rerun_start_date = "";
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]] =
$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_start_date = get_post_meta($post->ID, 'rerun_start_date_'.$d, true);
if (empty($rerun_cadence) || empty($rerun_start_date)) {
$rerun_cadence = "1";
}
if (!empty($rerun_day)&&!empty($rerun_start)&&!empty($rerun_end)) {
if (have_to_run_this_week($rerun_start_date, (int)$rerun_cadence)) {
$palinsesto[(int)$rerun_day][(string)$rerun_start] =
array(
'ID' => $post->ID,
'start' => $rerun_start[$d][0],
'end' => $rerun_end[$d][0],
'start' => $rerun_start,
'end' => $rerun_end,
'on_air' => false,
'title' => $post->post_title,
'excerpt' => $post->post_excerpt,
@ -62,11 +98,13 @@ function show_palinsesto($args)
}
}
}
}
ksort($palinsesto);
/*echo '<pre>';
print_r($palinsesto);
echo '</pre>';*/
// echo '<pre>';
// print_r($palinsesto);
// echo '</pre>';
$today = date("N");
@ -80,29 +118,25 @@ function show_palinsesto($args)
$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 $broadcast_list)
foreach ( $key => $broadcast) {
foreach ($palinsesto[$x] as $hour => $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">

Loading…
Cancel
Save