Commit 91e8be66 authored by Ingo Leindecker's avatar Ingo Leindecker
Browse files

Added PHP Script for displaying the daily program on the website.

parent 6dea7df6
body {
font-family: 'Roboto', sans-serif;
margin: 0px;
}
#aura {
font-size: 15px;
}
/* Top navigation bar */
#aura header {
overflow: auto;
border-bottom: 1px solid #ccc;
background: #222;
color: white;
}
#aura header a {
text-decoration: none;
color: #fff;
}
/* The current day */
#aura .current-day {
width: calc(100% - 140px);
float: left;
padding: 10px 0 10px 0;
font-size: 1.4em;
text-align: center;
cursor: pointer;
}
/* Previous and next buttons */
#aura .prev, #aura .next {
width: 30px;
padding: 10px 20px;
font-size: 1.5em;
font-weight: bold;
}
#aura .prev {
float: left;
}
#aura .next {
float: right;
text-align: right;
}
/**
* Timeslot
*/
/* A timeslot row */
#aura .timeslot {
display: block;
clear: both;
overflow: auto;
border-bottom:1px solid #ccc;
margin-bottom: 1px;
padding: 10px 20px 9px 10px;
cursor: pointer;
background:#ededed;
color:#222;
}
/* Highlight the timeslot that's playing right now */
#aura .timeslot.now {
border-left: 10px solid #ff7474;
padding-left: 0px;
}
/* Time column */
#aura .time-col {
width: calc(40% - 150px); /* Replace 150px with your custom thumbnail width */
float: left;
min-width: 85px;
max-width: 200px;
text-align: center;
}
/* The timeslot's time */
#aura .time {
font-size: 1.3em;
font-weight: bold;
}
/* Show column */
#aura .show-col {
width: 60%;
float: left;
}
/* The timeslot's show name */
#aura .show {
font-size: 1.3em;
font-weight: bold;
}
/* Note title if present */
#aura .note .title {
display: block;
font-size: 1.1em;
margin-top: 5px;
}
/* Thumbnail column */
#aura .img-col {
width: auto; /* Replace 150px with your custom thumbnail width */
float: right;
text-align: right;
}
#aura .img-col img {
max-height: 65px;
width: auto;
}
@media (max-width: 460px) {
#aura .img-col {
display: none;
}
}
/* The show's metadata */
#aura .meta {
display: none;
margin-top: .5em;
}
#aura .meta .summary {
display:block;
margin-bottom:1em;
}
#aura hr {
width: 50px;
height: 1px;
border: none;
border-top: 1px solid #b6b6b6;
clear: both;
overflow: auto;
margin: 9px 0;
}
#aura .contact-website,
#aura .contact-email,
#aura .hosts,
#aura .languages,
#aura .categories,
#aura .topics,
#aura .types,
#aura .musicfocus {
display: block;
margin-top: 5px;
font-size: .8em;
}
/* Metadata captions */
#aura .website-caption,
#aura .email-caption,
#aura .hosts-caption,
#aura .languages-caption,
#aura .categories-caption,
#aura .topics-caption,
#aura .types-caption,
#aura .musicfocus-caption {
background: #ddd;
color: #333;
border-radius: 3px 0px;
padding: 1px 4px;
}
/* Calendar */
div.ui-datepicker {
position: absolute !important;
width: auto;
max-width: 17em;
min-width: 280px;
margin: 0 auto;
margin-left: calc(50% - 10.25em);
box-shadow: 0 0 7px #111;
border-radius: 5px;
}
/* Header */
.ui-widget-header {
background: #3c3c3b;
}
.ui-datepicker .ui-datepicker-header {
padding: 0;
}
/* Month name */
.ui-datepicker .ui-datepicker-title {
color: #fff;
}
/* Previous/next buttons */
.ui-datepicker .ui-datepicker-prev, .ui-datepicker .ui-datepicker-next {
top: 0;
filter: invert(100%);
}
.ui-datepicker .ui-datepicker-prev:hover, .ui-datepicker .ui-datepicker-next:hover {
background: none;
cursor: pointer;
border: none;
}
/* Calendar days */
.ui-state-default, .ui-widget-content .ui-state-default {
background: #3c3c3b;
border: none;
}
.ui-corner-all {
border-radius: 0px;
}
/* Day hover */
.ui-state-hover, .ui-widget-content .ui-state-hover {
background: #3c3c3b;
border: none;
color: #fff;
}
/* Today */
.ui-state-highlight, .ui-widget-content .ui-state-highlight {
background: #ddd;
border: none;
color: #333 !important;
}
/* Selected day */
.ui-state-active, .ui-widget-content .ui-state-active {
border: none;
border-top: 1px solid #777;
border-left: 1px solid #777;
background: #fff;
color: #333 !important;
}
\ No newline at end of file
<?php
/* URL to AURA API with trailing slash */
define( 'AURA_API_URL', 'http://localhost:8000/api/v1/' );
/* URL to the site's media directory (where images are stored) with trailing slash */
define( 'AURA_SITE_MEDIA_ROOT', 'http://localhost:8000/site_media/' );
/* Localization for strftime() */
setlocale( LC_ALL, 'de_DE.UTF-8', 'German_Germany', 'German' );
/* Localization for time() */
date_default_timezone_set( 'Europe/Berlin' );
/**** END OF CONFIGURATION ****/
header("Content-type:text/html; charset=UTF-8");
if( ! isset( $_GET["date"] ) || empty( $_GET["date"] ) ) {
$date = date("Y-m-d");
} else {
$date = $_GET["date"];
}
$prev = date( "Y-m-d", strtotime( $date ) - 86400 );
$next = date( "Y-m-d", strtotime( $date ) + 86400 );
?>
<!doctype html>
<html lang="de">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="https://fonts.googleapis.com/css?family=Roboto:400,100,300,700" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" />
<link rel="stylesheet" href="program.css" type="text/css" />
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
<div id="aura">
<header>
<div class="prev"><a href="?date=<?php echo $prev; ?>">&lt;</a></div>
<div class="current-day" id="datepicker"><?php echo strftime( "%A, %d. %B", strtotime( $date ) ); ?></div>
<div class="next"><a href="?date=<?php echo $next; ?>">&gt;</a></div>
</header>
<?php
$timeslots = json_decode( file_get_contents( AURA_API_URL . "timeslots/?start=". $date . "&end=" . $date ) );
$hosts = json_decode( file_get_contents( AURA_API_URL . "hosts" ) );
$hosts_names = aura_array_column( $hosts, 'name', 'id' );
$categories = json_decode( file_get_contents( AURA_API_URL . "categories" ) );
$categories_names = aura_array_column( $categories, 'category', 'id' );
$languages = json_decode( file_get_contents( AURA_API_URL . "languages" ) );
$languages_names = aura_array_column( $languages, 'name', 'id' );
$topics = json_decode( file_get_contents( AURA_API_URL . "topics" ) );
$topics_names = aura_array_column( $topics, 'topic', 'id' );
$musicfocus = json_decode( file_get_contents( AURA_API_URL . "musicfocus" ) );
$musicfocus_names = aura_array_column( $musicfocus, 'focus', 'id' );
$types = json_decode( file_get_contents( AURA_API_URL . "types" ) );
$types_names = aura_array_column( $types, 'type', 'id' );
foreach( $timeslots as $timeslot ) :
$show = json_decode( file_get_contents( AURA_API_URL . "shows/" . $timeslot->show ) );
$note = "";
if( is_numeric( $timeslot->note_id ) && $timeslot->note_id > 0 )
$note = json_decode( file_get_contents( AURA_API_URL . "notes/" . $timeslot->note_id ) );
$timeslot_start = aura_strip_leading_zero( strftime( "%H:%M", strtotime( $timeslot->start ) ) );
$now_class = ( strtotime( $timeslot->start ) <= time() && strtotime( $timeslot->end ) >= time() ) ? " now" : "";
$is_repetition = ( $timeslot->is_repetition ) ? " (WH)" : "";
// The show's image by default
$thumbnail = ( ! empty( $show->thumbnails[1] ) ) ? AURA_SITE_MEDIA_ROOT . "/" . $show->thumbnails[0] : "";
// Override it by the note's image if existing
$thumbnail = ( ! empty( $note->thumbnails[1] ) ) ? AURA_SITE_MEDIA_ROOT . "/" . $note->thumbnails[0] : $thumbnail;
?>
<!-- TIMESLOT TEMPLATE BEGIN -->
<div id="timeslot-<?php echo $timeslot->id; ?>" class="timeslot<?php echo $now_class; ?>">
<div class="time-col">
<span class="time"><?php echo $timeslot_start; ?></span>
<?php if( ! empty( $now_class ) ) : ?>
<div class="now-text">JETZT</div>
<?php endif; ?>
</div>
<div class="show-col">
<span class="show"><?php echo $show->name; ?><?php echo $is_repetition; ?></span>
<div class="note">
<?php if( ! empty( $note ) ) : ?>
<span class="title"><?php echo $note->title; ?></span>
<?php endif; ?>
</div>
<div class="meta">
<?php if( ! empty( $note ) ) : ?>
<span class="summary"><?php echo nl2br( trim( $note->summary ) ); ?></span>
<?php else : ?>
<span class="summary"><?php echo nl2br( trim( $show->short_description ) ); ?></span>
<?php endif; ?>
<?php if( ! empty( $show->website ) ) : ?>
<div class="contact-website">
<span class="website-caption">Website:</span>
<span class="website"><a href="<?php echo $show->website; ?>" target="_blank"><?php echo $show->website; ?></a></span>
</div>
<?php endif; ?>
<?php if( ! empty( $show->hosts ) ) : ?>
<div class="hosts">
<span class="hosts-caption">Hosts:</span>
<span class="hosts-names"><?php echo aura_gen_list( $show->hosts, $hosts_names ); ?></span>
</div>
<?php endif; ?>
<?php if( ! empty( $show->email ) ) : ?>
<div class="contact-email">
<span class="email-caption">E-Mail:</span>
<span class="email"><a href="mailto:<?php echo $show->email; ?>"><?php echo $show->email; ?></a></span>
</div>
<?php endif; ?>
<hr />
<?php if( ! empty( $show->language ) ) : ?>
<div class="languages">
<span class="languages-caption">Sprachen:</span>
<span class="languages-names"><?php echo aura_gen_list( $show->language, $languages_names ); ?></span>
</div>
<?php endif; ?>
<?php if( ! empty( $show->category ) ) : ?>
<div class="categories">
<span class="categories-caption">Kategorien:</span>
<span class="categories-names"><?php echo aura_gen_list( $show->category, $categories_names ); ?></span>
</div>
<?php endif; ?>
<?php if( ! empty( $show->topic ) ) : ?>
<div class="topics">
<span class="topics-caption">Themen:</span>
<span class="topics-names"><?php echo aura_gen_list( $show->topic, $topics_names ); ?></span>
</div>
<?php endif; ?>
<?php if( ! empty( $show->type ) ) : ?>
<div class="types">
<span class="types-caption">Format:</span>
<span class="types-names"><?php echo $types_names[$show->type]; ?></span>
</div>
<?php endif; ?>
<?php if( ! empty( $show->musicfocus ) ) : ?>
<div class="musicfocus">
<span class="musicfocus-caption">Musikschwerpunkt:</span>
<span class="musicfocus-names"><?php echo aura_gen_list( $show->musicfocus, $musicfocus_names ); ?></span>
</div>
<?php endif; ?>
</div>
</div>
<?php if( ! empty( $thumbnail ) ) : ?>
<div class="img-col">
<img src="<?php echo $thumbnail; ?>" />
</div>
<?php endif; ?>
</div>
<!-- TIMESLOT TEMPLATE END -->
<?php
endforeach; ?>
</div>
<script type="text/javascript">
var date_selected = new Date(<?php echo strtotime( $date ) * 1000; ?>); // Timestamp in milliseconds
jQuery(document).ready(function(jQuery){
jQuery.datepicker.setDefaults({"closeText":"Schlie\u00dfen","currentText":"Heute","monthNames":["Januar","Februar","M\u00e4rz","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"],"monthNamesShort":["Jan","Feb","Mrz","Apr","Mai","Jun","Jul","Aug","Sep","Okt","Nov","Dez"],"nextText":"Weiter","prevText":"Vorherige","dayNames":["Sonntag","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag"],"dayNamesShort":["So","Mo","Di","Mi","Do","Fr","Sa"],"dayNamesMin":["S","M","D","M","D","F","S"],"dateFormat":"d. MM yy","firstDay":1,"isRTL":false});
});
/* When clicked on date in datepicker, redirect to new calendar page */
jQuery(document).on("click", "#datepicker", function() {
if( jQuery(".ui-datepicker").css("display") == "none" )
jQuery(".ui-datepicker").show();
else
jQuery(".ui-datepicker").hide();
jQuery(this).datepicker({
dateFormat: 'D, d. MM yy',
defaultDate: date_selected,
onSelect: function(dateText, inst) {
inst.currentMonth++;
if( inst.currentMonth > 12 ) {
ints.currentMonth = 01;
ints.currentYear++;
}
window.location = '?date=' + inst.currentYear + '-' + inst.currentMonth + '-' + inst.currentDay;;
}
});
});
/*
jQuery(document).on("mouseleave", ".ui-datepicker", function() {
jQuery(".ui-datepicker").hide();
});
*/
/* Toggle visibility of shows' metadata */
jQuery(document).on("click", ".timeslot", function() {
// Prevent toggle if text was selected
if( document.getSelection().toString() != '' )
return;
var meta = jQuery(this).find(".meta");
if( meta.css("display") == "none" )
meta.slideDown();
else
meta.slideUp();
});
</script>
</body>
</html>
<?php
/**
* For PHP < 7 downward compatibility
* Replaces array_column()
*
* See https://github.com/ramsey/array_column/blob/master/src/array_column.php
*
* Returns the values from a single column of the input array, identified by
* the $columnKey.
*
* Optionally, you may provide an $indexKey to index the values in the returned
* array by the values from the $indexKey column in the input array.
*
* @param array $input A multi-dimensional array (record set) from which to pull
* a column of values.
* @param mixed $columnKey The column of values to return. This value may be the
* integer key of the column you wish to retrieve, or it
* may be the string key name for an associative array.
* @param mixed $indexKey (Optional.) The column to use as the index/keys for
* the returned array. This value may be the integer key
* of the column, or it may be the string key name.
* @return array
*/
function aura_array_column($input = null, $columnKey = null, $indexKey = null) {
// Using func_get_args() in order to check for proper number of
// parameters and trigger errors exactly as the built-in array_column()
// does in PHP 5.5.
$argc = func_num_args();
$params = func_get_args();
if( $argc < 2 ) {
trigger_error( "array_column() expects at least 2 parameters, {$argc} given", E_USER_WARNING );
return null;
}
if( ! is_array( $params[0] ) ) {
trigger_error(
'array_column() expects parameter 1 to be array, ' . gettype( $params[0] ) . ' given',
E_USER_WARNING
);
return null;
}
if( ! is_int( $params[1] )
&& ! is_float( $params[1] )
&& ! is_string( $params[1] )
&& $params[1] !== null
&& ! ( is_object( $params[1] ) && method_exists( $params[1], '__toString' ) )
) {
trigger_error( 'array_column(): The column key should be either a string or an integer', E_USER_WARNING );
return false;
}
if( isset( $params[2] )
&& ! is_int( $params[2] )
&& ! is_float( $params[2] )
&& ! is_string( $params[2] )
&& ! ( is_object( $params[2] ) && method_exists( $params[2], '__toString' ) )
) {
trigger_error( 'array_column(): The index key should be either a string or an integer', E_USER_WARNING );
return false;
}
$paramsInput = (array) $params[0];
$paramsColumnKey = ( $params[1] !== null ) ? (string) $params[1] : null;
$paramsIndexKey = null;
if( isset( $params[2] ) ) {
if( is_float($params[2] ) || is_int( $params[2] ) ) {
$paramsIndexKey = (int) $params[2];
} else {
$paramsIndexKey = (string) $params[2];
}
}
$resultArray = array();
foreach( $paramsInput as $row ) {
$row = (array) $row;
$key = $value = null;
$keySet = $valueSet = false;
if ( $paramsIndexKey !== null && array_key_exists( $paramsIndexKey, $row ) ) {
$keySet = true;
$key = (string) $row[$paramsIndexKey];
}
if( $paramsColumnKey === null ) {
$valueSet = true;
$value = $row;
} elseif( is_array( $row ) && array_key_exists( $paramsColumnKey, $row ) ) {
$valueSet = true;
$value = $row[$paramsColumnKey];
}
if( $valueSet ) {
if( $keySet ) {
$resultArray[$key] = $value;
} else {