master
campi 2 years ago
parent 437d5e1352
commit 4e97102c43

@ -30,8 +30,8 @@ function create_broadcast_post()
); );
} }
add_action('init', 'create_broadcast_post'); add_action('init', 'create_broadcast_post');
add_action('add_meta_boxes', 'live_meta_box_add'); add_action('add_meta_boxes', 'live_meta_box_add');
function live_meta_box_add() function live_meta_box_add()
{ {
//give name of your input field //give name of your input field
@ -60,14 +60,14 @@ function orari_dirette_input($post)
<div style='width:20%;float:left;'> <div style='width:20%;float:left;'>
<select name="on_air_day_<?php echo $x; ?>" id="on_air_day_<?php echo $x; ?>"> <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]=='') ? 'selected' : ''; ?> value="">Seleziona un giorno</option>
<option <?php echo ($onair_day[$x]==1) ? 'selected="selected"' : ''; ?> value="1">Luned&igrave;</option> <option <?php echo ($onair_day[$x]==1) ? 'selected' : ''; ?> value="1">Luned&igrave;</option>
<option <?php echo ($onair_day[$x]==2) ? 'selected="selected"' : ''; ?> value="2">Marted&igrave;</option> <option <?php echo ($onair_day[$x]==2) ? 'selected' : ''; ?> value="2">Marted&igrave;</option>
<option <?php echo ($onair_day[$x]==3) ? 'selected="selected"' : ''; ?> value="3">Mercoled&igrave;</option> <option <?php echo ($onair_day[$x]==3) ? 'selected' : ''; ?> value="3">Mercoled&igrave;</option>
<option <?php echo ($onair_day[$x]==4) ? 'selected="selected"' : ''; ?> value="4">Gioved&igrave;</option> <option <?php echo ($onair_day[$x]==4) ? 'selected' : ''; ?> value="4">Gioved&igrave;</option>
<option <?php echo ($onair_day[$x]==5) ? 'selected="selected"' : ''; ?> value="5">Venerd&igrave;</option> <option <?php echo ($onair_day[$x]==5) ? 'selected' : ''; ?> value="5">Venerd&igrave;</option>
<option <?php echo ($onair_day[$x]==6) ? 'selected="selected"' : ''; ?> value="6">Sabato</option> <option <?php echo ($onair_day[$x]==6) ? 'selected' : ''; ?> value="6">Sabato</option>
<option <?php echo ($onair_day[$x]==7) ? 'selected="selected"' : ''; ?> value="7">Domenica</option> <option <?php echo ($onair_day[$x]==7) ? 'selected' : ''; ?> value="7">Domenica</option>
</select> </select>
</div> </div>
<div style='width:20%;float:left;'> <div style='width:20%;float:left;'>
@ -77,9 +77,11 @@ function orari_dirette_input($post)
<div style='width:20%;float:left;'> <div style='width:20%;float:left;'>
<select name="on_air_cadence_<?php echo $x; ?>" id="on_air_cadence_<?php echo $x; ?>"> <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> <label for="on_air_cadence_<?php echo $x; ?>">Cadenza</label>
<option <?php echo ($onair_cadence[$x]==1) ? 'selected="selected"' : ''; ?> value="1">Una volta a settimana</option> <option <?php echo ($onair_cadence[$x]==1) ? 'selected' : ''; ?> value="1">Una volta a settimana</option>
<option <?php echo ($onair_cadence[$x]==2) ? 'selected="selected"' : ''; ?> value="2">Una volta ogni 2 settimane</option> <option <?php echo ($onair_cadence[$x]==2) ? '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> <option <?php echo ($onair_cadence[$x]==3) ? 'selected' : ''; ?> value="3" type="hidden">Una volta ogni 3 settimane</option>
<option <?php echo ($onair_cadence[$x]==4) ? 'selected' : ''; ?> value="4">Una volta ogni 4 settimane</option>
<option <?php echo ($onair_cadence[$x]==5) ? 'selected' : ''; ?> value="5">Una volta al mese</option>
</select> </select>
</div> </div>
<div style='width:20%;float:left;'> <div style='width:20%;float:left;'>
@ -93,6 +95,8 @@ function orari_dirette_input($post)
<div style="clear:both;"></div> <div style="clear:both;"></div>
<?php <?php
endfor; endfor;
wp_enqueue_script('add_onchange_listener', plugin_dir_url(__FILE__).'add_onchange_listener.js', array(), '1.0', true);
} }
function orari_repliche_input($post) function orari_repliche_input($post)
@ -112,14 +116,14 @@ function orari_repliche_input($post)
</div> </div>
<div style='width:20%;float:left;'> <div style='width:20%;float:left;'>
<select name="rerun_day_<?php echo $x; ?>" id="rerun_day_<?php echo $x; ?>"> <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]=='') ? 'selected' : ''; ?> value="">Seleziona un giorno</option>
<option <?php echo ($rerun_day[$x]==1) ? 'selected="selected"' : ''; ?> value="1">Luned&igrave;</option> <option <?php echo ($rerun_day[$x]==1) ? 'selected' : ''; ?> value="1">Luned&igrave;</option>
<option <?php echo ($rerun_day[$x]==2) ? 'selected="selected"' : ''; ?> value="2">Marted&igrave;</option> <option <?php echo ($rerun_day[$x]==2) ? 'selected' : ''; ?> value="2">Marted&igrave;</option>
<option <?php echo ($rerun_day[$x]==3) ? 'selected="selected"' : ''; ?> value="3">Mercoled&igrave;</option> <option <?php echo ($rerun_day[$x]==3) ? 'selected' : ''; ?> value="3">Mercoled&igrave;</option>
<option <?php echo ($rerun_day[$x]==4) ? 'selected="selected"' : ''; ?> value="4">Gioved&igrave;</option> <option <?php echo ($rerun_day[$x]==4) ? 'selected' : ''; ?> value="4">Gioved&igrave;</option>
<option <?php echo ($rerun_day[$x]==5) ? 'selected="selected"' : ''; ?> value="5">Venerd&igrave;</option> <option <?php echo ($rerun_day[$x]==5) ? 'selected' : ''; ?> value="5">Venerd&igrave;</option>
<option <?php echo ($rerun_day[$x]==6) ? 'selected="selected"' : ''; ?> value="6">Sabato</option> <option <?php echo ($rerun_day[$x]==6) ? 'selected' : ''; ?> value="6">Sabato</option>
<option <?php echo ($rerun_day[$x]==7) ? 'selected="selected"' : ''; ?> value="7">Domenica</option> <option <?php echo ($rerun_day[$x]==7) ? 'selected' : ''; ?> value="7">Domenica</option>
</select> </select>
</div> </div>
<div style='width:20%;float:left;'> <div style='width:20%;float:left;'>
@ -129,9 +133,9 @@ function orari_repliche_input($post)
<div style='width:20%;float:left;'> <div style='width:20%;float:left;'>
<select name="rerun_cadence_<?php echo $x; ?>" id="rerun_cadence_<?php echo $x; ?>"> <select name="rerun_cadence_<?php echo $x; ?>" id="rerun_cadence_<?php echo $x; ?>">
<label for="rerun_cadence_<?php echo $x; ?>">Cadenza</label> <label for="rerun_cadence_<?php echo $x; ?>">Cadenza</label>
<option <?php echo ($rerun_cadence[$x]==1) ? 'selected="selected"' : ''; ?> value="1">Una volta a settimana</option> <option <?php echo ($rerun_cadence[$x]==1) ? 'selected' : ''; ?> value="1">Una volta a settimana</option>
<option <?php echo ($rerun_cadence[$x]==2) ? 'selected="selected"' : ''; ?> value="2">Una volta ogni 2 settimane</option> <option <?php echo ($rerun_cadence[$x]==2) ? '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> <option <?php echo ($rerun_cadence[$x]==4) ? 'selected' : ''; ?> value="4">Una volta ogni 4 settimane</option>
</select> </select>
</div> </div>
<div style='width:20%;float:left;'> <div style='width:20%;float:left;'>
@ -166,12 +170,7 @@ function orari_dirette_save($post_id)
if (!current_user_can('edit_post', $post_id)) { if (!current_user_can('edit_post', $post_id)) {
return; return;
} }
/*
echo '<pre>';
print_r($_POST);
echo '</pre>';
exit();
*/
// now we can actually save the data // now we can actually save the data
$allowed = array( $allowed = array(
'a' => array( // on allow a tags 'a' => array( // on allow a tags
@ -199,17 +198,39 @@ function orari_dirette_save($post_id)
wp_insert_term($_POST['post_title'], 'category', $args); wp_insert_term($_POST['post_title'], 'category', $args);
} }
update_post_meta($post_id, 'taxonomy_id', wp_kses($_POST['taxonomy_id'], $allowed)); update_post_meta($post_id, 'taxonomy_id', wp_kses($_POST['taxonomy_id'], $allowed));
for ($x=0;$x<7;$x++) { for ($x=0;$x<7;$x++) {
update_post_meta($post_id, 'on_air_day_'.$x, wp_kses($_POST['on_air_day_'.$x], $allowed)); $onair_day_data = wp_kses($_POST['on_air_day_'.$x], $allowed);
$rerun_day_data = wp_kses($_POST['rerun_day_'.$x], $allowed);
$onair_start_date_data = wp_kses($_POST['on_air_start_date_'.$x], $allowed);
$rerun_start_date_data = wp_kses($_POST['rerun_start_date_'.$x], $allowed);
if (!empty($onair_day_data) && !empty($onair_start_date_data)) {
check_and_correct_start_date_flag($onair_start_date_data, $onair_day_data);
}
if (!empty($rerun_day_data) && !empty($rerun_start_date_data)) {
check_and_correct_start_date_flag($rerun_start_date_data, $rerun_day_data);
}
update_post_meta($post_id, 'on_air_day_'.$x, $onair_day_data);
update_post_meta($post_id, 'on_air_start_'.$x, wp_kses($_POST['on_air_start_'.$x], $allowed)); 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_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_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, $rerun_day_data);
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_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_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_cadence_'.$x, wp_kses($_POST['rerun_cadence_'.$x], $allowed));
update_post_meta($post_id, 'rerun_start_date_'.$x, wp_kses($_POST['rerun_start_date_'.$x], $allowed)); update_post_meta($post_id, 'on_air_start_date_'.$x, $onair_start_date_data);
update_post_meta($post_id, 'rerun_start_date_'.$x, $rerun_start_date_data);
} }
} }
} }
function check_and_correct_start_date_flag(&$start_date_ptr, $day) {
$start_date_dt = new DateTime($start_date_ptr);
$weekday_number = $start_date_dt->format("N");
if ($day != $weekday_number) {
$day_diff = $day - $weekday_number;
$start_date_dt->modify($day_diff." days");
$start_date_ptr = $start_date_dt->format("Y-m-d");
};
}

@ -0,0 +1,43 @@
// change, consistently with day field, the date field
function add_change_day_handler(elem, day_field_id, date_field_id) {
elem.addEventListener('change', function(e) {
const setted_weekday = document.getElementById(day_field_id).value;
const date_input = document.getElementById(date_field_id);
if (date_input.value.length !== 0){
const date = new Date(date_input.value);
let weekday = date.getDay();
weekday = (weekday == 0) ? 7 : weekday;
if (weekday != setted_weekday ) {
let weekday_diff = setted_weekday - weekday;
date.setDate(date.getDate() + weekday_diff);
date_input.value = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
}
}
});
}
// change, consistently with date field, the day field
function add_change_date_handler(elem, day_field_id, date_field_id) {
elem.addEventListener('change', function(e) {
const setted_date = document.getElementById(date_field_id).value;
const day_input = document.getElementById(day_field_id);
let setted_weekday = day_input.value;
let date_weekday = new Date(setted_date).getDay();
date_weekday = (date_weekday == 0) ? 7 : date_weekday;
if (date_weekday != setted_weekday) {
day_input.value = date_weekday;
}
});
}
for (var i = 0; i < 7 ; i++) {
let onair_day_input = document.getElementById("on_air_day_" + i);
let rerun_day_input = document.getElementById("rerun_day_" + i);
let onair_date_input = document.getElementById("on_air_start_date_" + i);
let rerun_date_input = document.getElementById("rerun_start_date_" + i);
add_change_day_handler(onair_day_input, "on_air_day_" + i, "on_air_start_date_" + i);
add_change_day_handler(rerun_day_input, "rerun_day_" + i, "rerun_start_date_" + i);
add_change_date_handler(onair_date_input, "on_air_day_" + i, "on_air_start_date_" + i);
add_change_date_handler(rerun_date_input, "rerun_day_" + i, "rerun_start_date_" + i);
}

@ -1,18 +1,20 @@
<?php <?php
function have_to_run_this_week($start_date, $cadence) //l'update deve impostare correttamente il valore della data per evitare inconsistenza sui dati
function have_to_run_this_week($start_date_s, $cadence_i)
{ {
$today = (new DateTime())->setTime(0,0,0);
$start_date = new DateTime($start_date_s);
$return_value; $return_value;
switch($cadence) { switch($cadence_i) {
case 1: case 1: //settimanale
$return_value = true; $return_value = true;
break; break;
case 2: case 2: //ogni 2 settimane
case 4: case 3:
$today = new DateTime(); case 4: //ogni 4 settimane
$date = new DateTime($start_date); $modulo = 7 * $cadence_i;
$modulo = 7 * $cadence; $date_difference = date_diff($today, $start_date);
$date_difference = date_diff($today, $date);
$days_difference = $date_difference->days; $days_difference = $date_difference->days;
if (($days_difference % $modulo) < 7) { if (($days_difference % $modulo) < 7) {
$return_value = true; $return_value = true;
@ -20,11 +22,32 @@ function have_to_run_this_week($start_date, $cadence)
} }
$return_value = false; $return_value = false;
break; break;
case 5: //una volta al mese
if (which_day_of_the_month($start_date) == which_day_of_the_month($today)) {
$return_value = true;
break;
}
$return_value = false;
break;
} }
return $return_value; return $return_value;
} }
function which_day_of_the_month($datetime)
{
$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) function show_palinsesto($args)
{ {
$week_days = ['Luned&igrave;','Marted&igrave;','Mercoled&igrave;','Gioved&igrave;','Venerd&igrave;','Sabato','Domenica']; $week_days = ['Luned&igrave;','Marted&igrave;','Mercoled&igrave;','Gioved&igrave;','Venerd&igrave;','Sabato','Domenica'];
@ -77,12 +100,17 @@ function show_palinsesto($args)
$rerun_cadence = get_post_meta($post->ID, 'rerun_cadence_'.$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); $rerun_start_date = get_post_meta($post->ID, 'rerun_start_date_'.$d, true);
if (empty($rerun_cadence) || empty($rerun_start_date)) { /*
$rerun_cadence = "1"; //default settimanale echo '<pre>';
} print_r($post->ID . " - " . $rerun_day ." - " . $rerun_cadence);
echo '</pre>';
*/
if (!empty($rerun_day)&&!empty($rerun_start)&&!empty($rerun_end)) { if (!empty($rerun_day)&&!empty($rerun_start)&&!empty($rerun_end)) {
if (empty($rerun_cadence) || empty($rerun_start_date)) {
$rerun_cadence = "1"; //default settimanale
}
if (have_to_run_this_week($rerun_start_date, (int)$rerun_cadence)) { if (have_to_run_this_week($rerun_start_date, (int)$rerun_cadence)) {
$palinsesto[(int)$rerun_day][(string)$rerun_start] = $palinsesto[(int)$rerun_day][(string)$rerun_start] =
array( array(
@ -102,17 +130,19 @@ function show_palinsesto($args)
ksort($palinsesto); ksort($palinsesto);
// echo '<pre>'; // echo '<pre>';
// print_r($palinsesto); // print_r($palinsesto);
// echo '</pre>'; // echo '</pre>';
$today = date("N"); $today = date("N");
for ($x=1;$x<=7;$x++) { for ($x=1;$x<=7;$x++) {
/*echo '<pre>'; /*
echo '<pre>';
echo("$today,$x"); echo("$today,$x");
echo '</pre>';*/ echo '</pre>';
*/
if ($x == $today) if ($x == $today)
$tabs .= "<li class='default-gator-tab'>".$week_days[$x-1]."</li>"; $tabs .= "<li class='default-gator-tab'>".$week_days[$x-1]."</li>";
@ -139,6 +169,7 @@ function show_palinsesto($args)
$content .= '</li>'; $content .= '</li>';
} ?> } ?>
<div class="gator-tabs-container"> <div class="gator-tabs-container">
<ul class="gator-tabs-header"> <ul class="gator-tabs-header">
<?php echo $tabs; ?> <?php echo $tabs; ?>

@ -9,7 +9,7 @@ a settimana nello stesso giorno.
function what_play_now($args) function what_play_now($args)
{ {
global $wpdb; global $wpdb;
/* Oggi espresso come $day (giorno della settimana 1-7 a partire da lunedì) e $now oggetto DateTime completo */ /* Oggi espresso come $day (giorno della settimana 1-7 a partire da lunedì) e $now oggetto DateTime completo */
$day = date("N"); $day = date("N");
$now = new DateTime("NOW"); $now = new DateTime("NOW");
@ -69,7 +69,6 @@ function what_play_now($args)
echo "</pre>"; echo "</pre>";
*/ */
foreach ($results as $t) { foreach ($results as $t) {
$tocheck[0] = $i; $tocheck[0] = $i;
$tocheck[1] = $t->post_id; $tocheck[1] = $t->post_id;

Loading…
Cancel
Save