first commit

master
campi 2 years ago
commit 36bda5c22e

@ -0,0 +1,174 @@
<?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));
}
}
}

@ -0,0 +1,184 @@
<?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,
'show_in_rest' => 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);
$text_start = array();
$text_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);
?>
<input type="hidden" name="taxonomy_id" value="<?php echo $old_term['term_id'] ?>" />
<?php
for ($x=0;$x<7;$x++) :
$onair_day[$x] = isset($values['on_air_day_'.$x]) ? esc_attr($values['on_air_day_'.$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]) : '';
$broadcast[$x] = term_exists('Podcast', 'category', 0);
$old_term[$x] = term_exists($post->post_title, 'category', $broadcast); ?>
<div style='width:33%;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>
<option <?php echo ($onair_day[$x]==2) ? 'selected="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]==4) ? 'selected="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]==6) ? 'selected="selected"' : ''; ?> value="6">Sabato</option>
<option <?php echo ($onair_day[$x]==7) ? 'selected="selected"' : ''; ?> value="7">Domenica</option>
</select>
</div>
<div style='width:33%;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%;" />
</div>
<div style='width:33%;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%;" />
</div>
<div style="clear:both;"></div>
<?php
endfor;
}
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_0'])) {
$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));
for ($x=0;$x<7;$x++) {
update_post_meta($post_id, 'on_air_day_'.$x, wp_kses($_POST['on_air_day_'.$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, '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));
}
}
}

@ -0,0 +1,258 @@
<?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));
}
}
}

@ -0,0 +1,33 @@
<?php
/*
Template Name: Trasmissione
Template Post Type: post, page, broadcast
*/
get_header(); ?>
<div class="wrap">
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
while (have_posts()) :
the_post();
get_template_part('template-parts/page/content', 'page');
// If comments are open or we have at least one comment, load up the comment template.
if (comments_open() || get_comments_number()) :
comments_template();
endif;
endwhile; // End of the loop.
?>
</main><!-- #main -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
</div><!-- .wrap -->
<?php
get_footer();

@ -0,0 +1,162 @@
<?php
class PageTemplater
{
/**
* A reference to an instance of this class.
*/
private static $instance;
/**
* The array of templates that this plugin tracks.
*/
protected $templates;
/**
* Returns an instance of this class.
*/
public static function get_instance()
{
if (null == self::$instance) {
self::$instance = new PageTemplater();
}
return self::$instance;
}
/**
* Initializes the plugin by setting filters and administration functions.
*/
private function __construct()
{
$this->templates = array();
// Add a filter to the attributes metabox to inject template into the cache.
if (version_compare(floatval(get_bloginfo('version')), '4.7', '<')) {
// 4.6 and older
add_filter(
'single_template',
array( $this, 'register_project_templates' )
);
} else {
// Add a filter to the wp 4.7 version attributes metabox
add_filter(
'theme_page_templates',
array( $this, 'add_new_template' )
);
}
// Add a filter to the save post to inject out template into the page cache
add_filter(
'wp_insert_post_data',
array( $this, 'register_project_templates' )
);
// Add a filter to the template include to determine if the page has our
// template assigned and return it's path
add_filter(
'template_include',
array( $this, 'view_project_template')
);
// Add your templates to this array.
$this->templates = array(
'broadcast-template.php' => 'Broadcast',
);
}
/**
* Adds our template to the page dropdown for v4.7+
*
*/
public function add_new_template($posts_templates)
{
$posts_templates = array_merge($posts_templates, $this->templates);
return $posts_templates;
}
/**
* Adds our template to the pages cache in order to trick WordPress
* into thinking the template file exists where it doens't really exist.
*/
public function register_project_templates($atts)
{
// Create the key used for the themes cache
$cache_key = 'page_templates-' . md5(get_theme_root() . '/' . get_stylesheet());
// Retrieve the cache list.
// If it doesn't exist, or it's empty prepare an array
$templates = wp_get_theme()->get_page_templates();
if (empty($templates)) {
$templates = array();
}
// New cache, therefore remove the old one
wp_cache_delete($cache_key, 'themes');
// Now add our template to the list of templates by merging our templates
// with the existing templates array from the cache.
$templates = array_merge($templates, $this->templates);
// Add the modified cache to allow WordPress to pick it up for listing
// available templates
wp_cache_add($cache_key, $templates, 'themes', 1800);
return $atts;
}
/**
* Checks if the template is assigned to the page
*/
public function view_project_template($template)
{
// Return the search template if we're searching (instead of the template for the first result)
if (is_search()) {
return $template;
}
// Get global post
global $post;
// Return template if post is empty
if (! $post) {
return $template;
}
// Return default template if we don't have a custom one defined
if (! isset($this->templates[get_post_meta(
$post->ID,
'_wp_page_template',
true
)])) {
return $template;
}
// Allows filtering of file path
$filepath = apply_filters('page_templater_plugin_dir_path', plugin_dir_path(__FILE__));
$file = $filepath . get_post_meta(
$post->ID,
'_wp_page_template',
true
);
// Just to be safe, we check if the file exist first
if (file_exists($file)) {
return $file;
} else {
echo $file;
}
// Return template
return $template;
}
}
add_action('plugins_loaded', array( 'PageTemplater', 'get_instance' ));

@ -0,0 +1,50 @@
<?php
/**
* The plugin bootstrap file
*
* This file is read by WordPress to generate the plugin information in the
* plugin admin area. This file also defines a function that starts the plugin.
*
* @link https://radiowombat.net
* @since 1.0.0
* @package Radio Wombat Toolkit Plugin
*
* @wordpress-plugin
* Plugin Name: Radio Wombat Toolkit
* Plugin URI: https://radiowombat.net
* Description: Gestione del palinsesto, versione wombat friendly
* Version: 1.0.3
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
if (! defined('WPINC')) {
die;
}
date_default_timezone_set("Europe/Rome");
register_activation_hook(__FILE__, 'add_broadcast_taxonomy');
function add_broadcast_taxonomy($args)
{
$check = term_exists('trasmissioni', 'category', 0);
if (!$check) {
$args = array(
'parent' => 0,
'slug' => 'trasmissioni'
);
wp_insert_term('Trasmissioni', 'category', $args);
}
}
foreach (glob(plugin_dir_path(__FILE__) . 'admin/*.php') as $file) {
include_once $file;
}
foreach (glob(plugin_dir_path(__FILE__) . 'inc/*.php') as $file) {
include_once $file;
}
foreach (glob(plugin_dir_path(__FILE__) . 'shortcodes/*.php') as $file) {
include_once $file;
}

@ -0,0 +1,73 @@
<?php
function rwt_broadcast_list()
{
global $wpdb;
$broadcast_post = array(
'numberposts' => -1,
'post_type' => 'broadcast',
'orderby' => 'title',
'order' => 'asc',
/* 'exclude' => array(
'key'=> '_wp_page_template',
'value' => 'old_broadcast_template.php',
'compare' => '!='
)*/
);
$broadcast = get_posts($broadcast_post);
//'<pre>';
//var_dump($broadcast);
//echo '</pre>';
$attive = array();
$concluse = array();
foreach ($broadcast as $post) {
$on_air_day = get_post_meta($post->ID, 'on_air_day_0', false);
$on_air = empty($on_air_day[0]) ? false : true;
if ($on_air) {
array_push($attive,$post);
} else {
array_push($concluse,$post);
}
}
$content = '<div align="center">[ <a href="#attive">Attive</a> ] [ <a href="#concluse">Concluse</a> ]</div>';
echo $content;
$content = '<a style="color:Gold" name="attive"><h4 style="color:Gold">[[[ Attive ]]] </h4>';
$content .= "<div class='broadcast-list'>\n";
foreach ($attive as $post) {
$content .= '<div class="single-broadcast">';
//$content .= '" style="background:url(\''.$post['thumb_url'].'\') no-repeat center center;background-size:cover;">';
//$content .= '<p class="img-url">'.$post['thumb_url'].'</p>';
$content .= '<a href="'.get_permalink($post->ID).'" title="'.$post->post_title.'">';
$content .= '<img class="img-broadcast" src="'.get_the_post_thumbnail_url($post->ID, 'full').'" />';
$content .= '<h4 class="broadcast-title">'.$post->post_title.'</h4>';
$content .= '</a>';
//$content .= '<p>'.$post['the_permalink'].'</p>';
$content .= "</div>\n";
}
$content .= "</div>\n";
echo $content;
$content = '<hr style="background-color:Gold;border-color:Gold"><hr style="background-color:Gold;border-color:Gold"> <br \> <a style="color:Gold" name="concluse"><h4 style="color:Gold">[[[ CONCLUSE ]]] </h4>';
$content .= "<div class='broadcast-list'>\n";
foreach ($concluse as $post) {
$content .= '<div class="single-broadcast">';
//$content .= '" style="background:url(\''.$post['thumb_url'].'\') no-repeat center center;background-size:cover;">';
//$content .= '<p class="img-url">'.$post['thumb_url'].'</p>';
$content .= '<a href="'.get_permalink($post->ID).'" title="'.$post->post_title.'">';
$content .= '<img class="img-broadcast" src="'.get_the_post_thumbnail_url($post->ID, 'full').'" />';
$content .= '<h4 class="broadcast-title">'.$post->post_title.'</h4>';
$content .= '</a>';
//$content .= '<p>'.$post['the_permalink'].'</p>';
$content .= "</div>\n";
}
$content .= "</div>\n";
echo $content;
//wp_enqueue_style('palinsesto_style', plugin_dir_url(__FILE__).'css/palinsesto.css', array(), '1.0', 'screen');
wp_enqueue_style('trasmissioni_style', plugin_dir_url(__FILE__).'css/trasmissioni.css', array(), '1.0', 'screen');
}
add_shortcode('broadcast_list', 'rwt_broadcast_list');

@ -0,0 +1,67 @@
.gator-tabs-container{
display:flex;
flex-direction:column;
width:100%;
justify-content:center;
align-content:flex-start;
}
.gator-tabs-container ul {
list-style-type:none;
}
.gator-tabs-container ul li {
margin: 0;
}
ul.gator-tabs-header {
background-color:#BBB;
display:flex;
flex-wrap:wrap;
padding:.375rem;
text-align:center;
margin:0;
}
ul.gator-tabs-header > li {
color:#063844;
cursor:pointer;
flex-grow:1;
padding:.375rem;
font-size:2.125rem;
}
.gator-tabs, .broadcast-list {
display:flex;
margin:0 !important;
}
.gator-tab {
padding:1rem;
width:100%;
flex-flow:wrap;
}
.gator-tab .single-broadcast, .broadcast-list .single-broadcast {
width:33.3333%;
padding:10px 20px;
box-sizing:border-box;
flex-flow:wrap;
}
.img-broadcast {
max-height:50%;
max-width:100%;
object-fit: contain;
}
.onair {
background-color:black;
color:Gold;
}
.rerun {
background-color:black;
}

@ -0,0 +1,25 @@
.gator-tabs, .broadcast-list {
display:flex;
flex-direction:row;
margin:0 !important;
width:100%;
justify-content:center;
flex-wrap:wrap;
}
.gator-tab .single-broadcast, .single-broadcast {
width:200px;
height:100px
box-sizing:border-box;
flex-flow:wrap;
margin:auto;
padding:10px;
}
.img-broadcast {
max-height:50%;
max-width:70%;
margin:auto;
object-fit: contain;
}

@ -0,0 +1,30 @@
function tabify( element ){
const header = element.querySelector('.gator-tabs-header');
const content = element.querySelector('.gator-tabs');
const tab_headers = [...header.children];
const tab_contents = [...content.children];
tab_contents.forEach( x => x.style.display = 'none');
let current_tab_index = -1;
function setTab( index ){
if( current_tab_index > -1 ){
tab_headers[ current_tab_index ].style.fontWeight = 400;
tab_contents[ current_tab_index ].style.display = 'none';
}
tab_headers[ index ].style.fontWeight = 800;
tab_contents[ index ].style.display = 'flex';
current_tab_index = index;
}
default_tab_index = tab_headers.findIndex( x => {
return [...x.classList].indexOf('default-gator-tab') > -1;
});
default_tab_index = default_tab_index === -1 ? 0 : default_tab_index;
setTab( default_tab_index );
tab_headers.forEach((x,i) => x.onclick = event => setTab(i));
}
// this is where the magic happens!
[...document.querySelectorAll('.gator-tabs-container')]
.forEach(x => tabify(x));

@ -0,0 +1,114 @@
<?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');

@ -0,0 +1,126 @@
<?php
/*
La funzione what_play_now funzione da per scontato che non ci siano trasmissioni con piu' di una diretta
a settimana nello stesso giorno.
*/
function what_play_now($args)
{
global $wpdb;
/* Oggi espresso come $day (giorno della settimana 1-7 a partire da lunedì) e $now oggetto DateTime completo */
$day = date("N");
$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;
}
}
/* 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) {
$done = true;
//echo get_post($post_id)->post_title;
return get_post($t[1])->post_title;
break;
}
}
}
/* fine check repliche */
if (!$done) {
//echo "Selezione musicale";
return "Selezione musicale";
}
}
add_shortcode('whatplaynow', 'what_play_now');
?>
Loading…
Cancel
Save