all feature implemented

master
campi 2 years ago
parent 4e97102c43
commit 666b9a710f

@ -1,174 +0,0 @@
<?php
function create_broadcast_post()
{
register_post_type(
'broadcast',
array(
'labels' => array(
'name' => __('Trasmissioni'),
'add_new' => __('Aggiungi Trasmissione'),
'new_item' => __('Nuova Trasmissione')
),
'public' => true,
'hierarchical' => false,
'exclude_from_search' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 3,
'has_archive' => false,
'supports' => array(
'title',
'editor',
'excerpt',
'thumbnail',
'post-formats'
),
'menu_icon' => 'dashicons-microphone',
)
);
}
add_action('init', 'create_broadcast_post');
add_action('add_meta_boxes', 'live_meta_box_add');
function live_meta_box_add()
{
//give name of your input field
add_meta_box('orari-dirette', 'ORARI DELLA DIRETTA', 'orari_dirette_input', 'broadcast', 'normal', 'high');
add_meta_box('orari-repliche', 'ORARI DELLE REPLICHE', 'orari_repliche_input', 'broadcast', 'normal', 'high');
}
function orari_dirette_input($post)
{
$values = get_post_custom($post->ID);
$onair_day = isset($values['on_air_day']) ? esc_attr($values['on_air_day'][0]) : '';
$text_start = isset($values['on_air_start']) ? esc_attr($values['on_air_start'][0]) : '';
$text_end = isset($values['on_air_end']) ? esc_attr($values['on_air_end'][0]) : '';
$broadcast = term_exists('Podcast', 'category', 0);
$old_term = term_exists($post->post_title, 'category', $broadcast);
wp_nonce_field('on_air_nonce', 'onair_nonce'); ?>
<input type="hidden" name="taxonomy_id" value="<?php echo $old_term['term_id'] ?>" />
<div style='width:33%;float:left;'>
<select name="on_air_day" id="on_air_day">
<option <?php echo ($onair_day=='') ? 'selected="selected"' : ''; ?> value="">Seleziona un giorno</option>
<option <?php echo ($onair_day==1) ? 'selected="selected"' : ''; ?> value="1">Luned&igrave;</option>
<option <?php echo ($onair_day==2) ? 'selected="selected"' : ''; ?> value="2">Marted&igrave;</option>
<option <?php echo ($onair_day==3) ? 'selected="selected"' : ''; ?> value="3">Mercoled&igrave;</option>
<option <?php echo ($onair_day==4) ? 'selected="selected"' : ''; ?> value="4">Gioved&igrave;</option>
<option <?php echo ($onair_day==5) ? 'selected="selected"' : ''; ?> value="5">Venerd&igrave;</option>
<option <?php echo ($onair_day==6) ? 'selected="selected"' : ''; ?> value="6">Sabato</option>
<option <?php echo ($onair_day==7) ? 'selected="selected"' : ''; ?> value="7">Domenica</option>
</select>
</div>
<div style='width:33%;float:left;'>
<label for="on_air_start">Ora inizio</label>
<input type="time" name="on_air_start" id="on_air_start" value="<?php echo $text_start; ?>" style="width: 30%;" />
</div>
<div style='width:33%;float:left;'>
<label for="on_air_end">Ora fine</label>
<input type="time" name="on_air_end" id="on_air_end" value="<?php echo $text_end; ?>" style="width: 30%;" />
</div>
<div style="clear:both;"></div>
<?php
}
function orari_repliche_input($post)
{
$values = get_post_custom($post->ID);
$text_start = array();
$text_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]) : '';
$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]) : ''; ?>
<div style='width:100%;float:left;'>
<h3>Replica n. <?php echo $x+1; ?></h3>
</div>
<div style='width:33%;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>
<option <?php echo ($rerun_day[$x]==2) ? 'selected="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]==4) ? 'selected="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]==6) ? 'selected="selected"' : ''; ?> value="6">Sabato</option>
<option <?php echo ($rerun_day[$x]==7) ? 'selected="selected"' : ''; ?> value="7">Domenica</option>
</select>
</div>
<div style='width:33%;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%;" />
</div>
<div style='width:33%;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%;" />
</div>
<div style="clear:both;"></div>
<?php
endfor;
}
add_action('save_post', 'orari_dirette_save');
function orari_dirette_save($post_id)
{
// Bail if we're doing an auto save
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
// if our nonce isn't there, or we can't verify it, bail
if (!isset($_POST['onair_nonce']) || !wp_verify_nonce($_POST['onair_nonce'], 'on_air_nonce')) {
return;
}
if (!isset($_POST['re_run_nonce']) || !wp_verify_nonce($_POST['re_run_nonce'], 'rerun_nonce')) {
return;
}
// if our current user can't edit this post, bail
if (!current_user_can('edit_post', $post_id)) {
return;
}
/*
echo '<pre>';
print_r($_POST);
echo '</pre>';
exit();
*/
// now we can actually save the data
$allowed = array(
'a' => array( // on allow a tags
'href' => array() // and those anchords can only have href attribute
)
);
if (isset($_POST['on_air_start'])) {
$broadcast = term_exists('Podcast', 'category', 0);
$check = term_exists(intval($_POST['taxonomy_id']), 'category', $broadcast['term_id']);
if (intval($check['term_id']) > 0) {
$args = array(
'cat_ID' => intval($check['term_id']),
'taxonomy' => 'category',
'cat_name' => $_POST['post_title'],
'category_description' => '',
'category_nicename' => $_POST['post_name'],
'category_parent' => $broadcast['term_id']
);
$test = wp_insert_category($args);
} else {
$args = array(
'parent' => $broadcast['term_id'],
'slug' => strtolower(wp_specialchars(str_replace(" ", "-", $_POST['post_title']))),
);
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, 'on_air_day', wp_kses($_POST['on_air_day'], $allowed));
update_post_meta($post_id, 'on_air_start', wp_kses($_POST['on_air_start'], $allowed));
update_post_meta($post_id, 'on_air_end', wp_kses($_POST['on_air_end'], $allowed));
for ($x=0;$x<7;$x++) {
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));
}
}
}

@ -95,7 +95,7 @@ function orari_dirette_input($post)
<div style="clear:both;"></div>
<?php
endfor;
wp_enqueue_script('add_onchange_listener', plugin_dir_url(__FILE__).'add_onchange_listener.js', array(), '1.0', true);
wp_enqueue_script('add_onchange_listener', plugin_dir_url(__FILE__).'js/add_onchange_listener.js', array(), '1.0', true);
}

@ -1,258 +0,0 @@
<?php
function create_broadcast_post()
{
register_post_type(
'broadcast',
array(
'labels' => array(
'name' => __('Trasmissioni'),
'add_new' => __('Aggiungi Trasmissione'),
'new_item' => __('Nuova Trasmissione')
),
'public' => true,
'hierarchical' => false,
'exclude_from_search' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 3,
'has_archive' => false,
'supports' => array(
'title',
'editor',
'excerpt',
'thumbnail',
'post-formats'
),
'menu_icon' => 'dashicons-microphone',
)
);
}
add_action('init', 'create_broadcast_post');
add_action('add_meta_boxes', 'live_meta_box_add');
function live_meta_box_add()
{
//give name of your input field
add_meta_box('orari-dirette', 'ORARI DELLA DIRETTA', 'orari_dirette_input', 'broadcast', 'normal', 'high');
add_meta_box('orari-repliche', 'ORARI DELLE REPLICHE', 'orari_repliche_input', 'broadcast', 'normal', 'high');
}
function orari_dirette_input($post)
{
$values = get_post_custom($post->ID);
$onair_day = isset($values['on_air_day']) ? esc_attr($values['on_air_day'][0]) : '';
$text_start = isset($values['on_air_start']) ? esc_attr($values['on_air_start'][0]) : '';
$text_end = isset($values['on_air_end']) ? esc_attr($values['on_air_end'][0]) : '';
$broadcast = term_exists('Podcast', 'category', 0);
$old_term = term_exists($post->post_title, 'category', $broadcast);
wp_nonce_field('on_air_nonce', 'onair_nonce'); ?>
<input type="hidden" name="taxonomy_id" value="<?php echo $old_term['term_id'] ?>" />
<!-- Lunedì -->
<div style='width:33%;float:left;'>
<input type="hidden" name="on_air_day_1" id="on_air_day_1" value="1">
Lunedì
</div>
<div style='width:33%;float:left;'>
<label for="on_air_start_1">Ora inizio</label>
<input type="time" name="on_air_start_1" id="on_air_start_1" value="<?php echo $text_start; ?>" style="width: 30%;" />
</div>
<div style='width:33%;float:left;'>
<label for="on_air_end_1">Ora fine</label>
<input type="time" name="on_air_end_1" id="on_air_end_1" value="<?php echo $text_end; ?>" style="width: 30%;" />
</div>
<div style="clear:both;"></div>
<!-- Martedì -->
<br>
<div style='width:33%;float:left;'>
<input type="hidden" name="on_air_day_2" id="on_air_day_2" value="2">
Martedì
</div>
<div style='width:33%;float:left;'>
<label for="on_air_start_2">Ora inizio</label>
<input type="time" name="on_air_start_2" id="on_air_start_2" value="<?php echo $text_start; ?>" style="width: 30%;" />
</div>
<div style='width:33%;float:left;'>
<label for="on_air_end_2">Ora fine</label>
<input type="time" name="on_air_end_2" id="on_air_end_2" value="<?php echo $text_end; ?>" style="width: 30%;" />
</div>
<div style="clear:both;"></div>
<!-- Mercoledì -->
<br>
<div style='width:33%;float:left;'>
<input type="hidden" name="on_air_day_3" id="on_air_day_3" value="3">
Mercoledì
</div>
<div style='width:33%;float:left;'>
<label for="on_air_start_3">Ora inizio</label>
<input type="time" name="on_air_start_3" id="on_air_start_3" value="<?php echo $text_start; ?>" style="width: 30%;" />
</div>
<div style='width:33%;float:left;'>
<label for="on_air_end_3">Ora fine</label>
<input type="time" name="on_air_end_3" id="on_air_end_3" value="<?php echo $text_end; ?>" style="width: 30%;" />
</div>
<div style="clear:both;"></div>
<!-- Giovedì -->
<br>
<div style='width:33%;float:left;'>
<input type="hidden" name="on_air_day_4" id="on_air_day_4" value="4">
Giovedì
</div>
<div style='width:33%;float:left;'>
<label for="on_air_start_4">Ora inizio</label>
<input type="time" name="on_air_start_4" id="on_air_start_4" value="<?php echo $text_start; ?>" style="width: 30%;" />
</div>
<div style='width:33%;float:left;'>
<label for="on_air_end_4">Ora fine</label>
<input type="time" name="on_air_end_4" id="on_air_end_4" value="<?php echo $text_end; ?>" style="width: 30%;" />
</div>
<div style="clear:both;"></div>
<!-- Venerdì -->
<br>
<div style='width:33%;float:left;'>
<input type="hidden" name="on_air_day_5" id="on_air_day_5" value="5">
Venerdì
</div>
<div style='width:33%;float:left;'>
<label for="on_air_start_5">Ora inizio</label>
<input type="time" name="on_air_start_5" id="on_air_start_5" value="<?php echo $text_start; ?>" style="width: 30%;" />
</div>
<div style='width:33%;float:left;'>
<label for="on_air_end_5">Ora fine</label>
<input type="time" name="on_air_end_5" id="on_air_end_5" value="<?php echo $text_end; ?>" style="width: 30%;" />
</div>
<div style="clear:both;"></div>
<!-- Sabato -->
<br>
<div style='width:33%;float:left;'>
<input type="hidden" name="on_air_day_6" id="on_air_day_6" value="6">
Sabato
</div>
<div style='width:33%;float:left;'>
<label for="on_air_start_6">Ora inizio</label>
<input type="time" name="on_air_start_6" id="on_air_start_6" value="<?php echo $text_start; ?>" style="width: 30%;" />
</div>
<div style='width:33%;float:left;'>
<label for="on_air_end_6">Ora fine</label>
<input type="time" name="on_air_end_6" id="on_air_end_6" value="<?php echo $text_end; ?>" style="width: 30%;" />
</div>
<div style="clear:both;"></div>
<!-- Domenica -->
<br>
<div style='width:33%;float:left;'>
<input type="hidden" name="on_air_day_7" id="on_air_day_7" value="7">
Sabato
</div>
<div style='width:33%;float:left;'>
<label for="on_air_start_7">Ora inizio</label>
<input type="time" name="on_air_start_7" id="on_air_start_7" value="<?php echo $text_start; ?>" style="width: 30%;" />
</div>
<div style='width:33%;float:left;'>
<label for="on_air_end_7">Ora fine</label>
<input type="time" name="on_air_end_7" id="on_air_end_7" value="<?php echo $text_end; ?>" style="width: 30%;" />
</div>
<div style="clear:both;"></div>
<?php
}
function orari_repliche_input($post)
{
$values = get_post_custom($post->ID);
$text_start = array();
$text_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]) : '';
$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]) : ''; ?>
<div style='width:100%;float:left;'>
<h3>Replica n. <?php echo $x+1; ?></h3>
</div>
<div style='width:33%;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>
<option <?php echo ($rerun_day[$x]==2) ? 'selected="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]==4) ? 'selected="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]==6) ? 'selected="selected"' : ''; ?> value="6">Sabato</option>
<option <?php echo ($rerun_day[$x]==7) ? 'selected="selected"' : ''; ?> value="7">Domenica</option>
</select>
</div>
<div style='width:33%;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%;" />
</div>
<div style='width:33%;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%;" />
</div>
<div style="clear:both;"></div>
<?php
endfor;
}
add_action('save_post', 'orari_dirette_save');
function orari_dirette_save($post_id)
{
// Bail if we're doing an auto save
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
// if our nonce isn't there, or we can't verify it, bail
if (!isset($_POST['onair_nonce']) || !wp_verify_nonce($_POST['onair_nonce'], 'on_air_nonce')) {
return;
}
if (!isset($_POST['re_run_nonce']) || !wp_verify_nonce($_POST['re_run_nonce'], 'rerun_nonce')) {
return;
}
// if our current user can't edit this post, bail
if (!current_user_can('edit_post', $post_id)) {
return;
}
/*
echo '<pre>';
print_r($_POST);
echo '</pre>';
exit();
*/
// now we can actually save the data
$allowed = array(
'a' => array( // on allow a tags
'href' => array() // and those anchords can only have href attribute
)
);
if (isset($_POST['on_air_start'])) {
$broadcast = term_exists('Podcast', 'category', 0);
$check = term_exists(intval($_POST['taxonomy_id']), 'category', $broadcast['term_id']);
if (intval($check['term_id']) > 0) {
$args = array(
'cat_ID' => intval($check['term_id']),
'taxonomy' => 'category',
'cat_name' => $_POST['post_title'],
'category_description' => '',
'category_nicename' => $_POST['post_name'],
'category_parent' => $broadcast['term_id']
);
$test = wp_insert_category($args);
} else {
$args = array(
'parent' => $broadcast['term_id'],
'slug' => strtolower(wp_specialchars(str_replace(" ", "-", $_POST['post_title']))),
);
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, 'on_air_day', wp_kses($_POST['on_air_day'], $allowed));
update_post_meta($post_id, 'on_air_start', wp_kses($_POST['on_air_start'], $allowed));
update_post_meta($post_id, 'on_air_end', wp_kses($_POST['on_air_end'], $allowed));
for ($x=0;$x<7;$x++) {
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));
}
}
}

@ -1,25 +1,26 @@
// change, consistently with day field, the date field
// change the date field consistently with day 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){
if (date_input.value.length !== 0 && setted_weekday.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();
date_input.value = date.toISOString().split('T')[0];
}
}
});
}
// change, consistently with date field, the day field
// change the day field consistently with date 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;
if (setted_date.length !== 0) {
const day_input = document.getElementById(day_field_id);
let setted_weekday = day_input.value;
let date_weekday = new Date(setted_date).getDay();
@ -27,6 +28,7 @@ function add_change_date_handler(elem, day_field_id, date_field_id) {
if (date_weekday != setted_weekday) {
day_input.value = date_weekday;
}
}
});
}
@ -37,7 +39,10 @@ for (var i = 0; i < 7 ; 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);
add_change_day_handler(onair_date_input, "on_air_day_" + i, "on_air_start_date_" + i);
add_change_day_handler(rerun_date_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,19 +1,24 @@
<?php
//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);
if (!empty($start_date_s)) {
$start_date = new DateTime($start_date_s);
if ($start_date > $today){
return false;
}
}
$return_value;
switch($cadence_i) {
case 1: //settimanale
$return_value = true;
break;
case 2: //ogni 2 settimane
case 3:
case 3: //ogni 3 settimane
case 4: //ogni 4 settimane
$modulo = 7 * $cadence_i;
$today->modify("this week {$start_date->format('l')}");
$date_difference = date_diff($today, $start_date);
$days_difference = $date_difference->days;
if (($days_difference % $modulo) < 7) {
@ -30,12 +35,12 @@ function have_to_run_this_week($start_date_s, $cadence_i)
$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");

@ -15,106 +15,56 @@ function what_play_now($args)
$now = new DateTime("NOW");
$done = false;
/* Cerco nelle dirette */
/* Prendo dalla tabella wp_postmeta le tramissioni con diretta oggi */
$results = $wpdb->get_results("select post_id from wp_postmeta where meta_key = 'on_air_day' and meta_value = '$day'");
//print_r($results);
foreach ($results as $t) {
$post_id = $t->post_id;
/* Estraggo la fascia oraria e controllo ne $now è contenuto nel range */
$start = $wpdb->get_results("select meta_value from wp_postmeta where meta_key = 'on_air_start' and post_id = '$post_id'");
$end = $wpdb->get_results("select meta_value from wp_postmeta where meta_key = 'on_air_end' and post_id = '$post_id'");
$s = $start[0]->meta_value;
$e = $end[0]->meta_value;
/*
echo "<pre>";
echo "$s $e";
echo "</pre>";
*/
$begin = new DateTime("$s");
$end = new DateTime("$e");
if ($now >= $begin && $now <= $end) {
$done = true;
//echo get_post($post_id)->post_title;
return get_post($post_id)->post_title;
break;
/* 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 );
}
/* inizio check repliche */
if (!$done) {
/* Cerco nelle repliche */
$rerun_today = [];
$tocheck = [];
/* Prendo dalla tabella wp_postmeta le trasmissioni con una replica oggi */
for ($i=0; $i <=6; $i++) {
$rerun = "rerun_day_$i";
$results = $wpdb->get_results("select post_id from wp_postmeta where meta_key = '$rerun' and meta_value = '$day'");
/*
echo "<pre>";
print_r($results);
echo "</pre>";
*/
foreach ($results as $t) {
$tocheck[0] = $i;
$tocheck[1] = $t->post_id;
array_push($rerun_today,$tocheck);
}
}
foreach ($rerun_today as $t) {
$rerun_start = "rerun_start_$t[0]";
$rerun_end = "rerun_end_$t[0]";
$start = $wpdb->get_results("select meta_value from wp_postmeta where meta_key = '$rerun_start' and post_id = '$t[1]'");
$end = $wpdb->get_results("select meta_value from wp_postmeta where meta_key = '$rerun_end' and post_id = '$t[1]'");
$s = $start[0]->meta_value;
$e = $end[0]->meta_value;
/*
echo "<pre>";
print_r($s);
print_r($e);
echo "</pre>";
*/
$begin = new DateTime("$s");
$end = new DateTime("$e");
/*
echo "<pre>";
print_r($now);
echo "</pre>";
*/
if ($now >= $begin && $now <= $end) {
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;
//echo get_post($post_id)->post_title;
return get_post($t[1])->post_title;
return get_post($post_id)->post_title;
break;
}
}
}
/* fine check repliche */
if (!$done) {
//echo "Selezione musicale";
return "Selezione musicale";
}

Loading…
Cancel
Save