1
0
Fork 0
forked from lino/radar-wp

First alpha: working style, dynamic sidebars, part tested cron.

This commit is contained in:
ekes 2019-04-30 19:30:25 +02:00
parent a6f657092d
commit 2342ebb052
6 changed files with 81 additions and 77 deletions

View file

@ -16,6 +16,7 @@ class Squat_Radar_Formatter {
add_filter('squat_radar_field_html', [__CLASS__, 'field_date_html'], 5, 4);
add_filter('squat_radar_field_html', [__CLASS__, 'field_location_html'], 5, 4);
add_filter('squat_radar_field_html', [__CLASS__, 'field_link_html'], 5, 4);
add_filter('squat_radar_field_html', [__CLASS__, 'field_summary_html'], 5, 4);
// Field 'url' was already turned into a <a> link, by field_link_html.
// The field_image_html is an example of an override with more specificity.
add_filter('squat_radar_field_html', [__CLASS__, 'field_image_html'], 7, 4);
@ -76,26 +77,26 @@ class Squat_Radar_Formatter {
// There can only be one date. With repeat etc. but just one.
// Repeating events will appear as a new item for each repeat in the feed.
$value = $value[0];
$output = '<span class="squat-radar-event-start-end">';
$output = '<span class="squat-radar-event-start-end">';
$output .= self::field_date_format( $value['time_start'], 'start' );
if ($value['time_start'] != $value['time_end']) {
$time_only = ( substr($value['time_start'], 0, 10) == substr($value['time_end'], 0, 10) );
$output .= self::field_date_format( $value['time_end'], 'end', $time_only );
$output .= ' - ' . self::field_date_format( $value['time_end'], 'end', $time_only );
}
$output .= '</span>';
return $output;
case 'time_start':
$value = $value[0];
$output = '<span class="squat-radar-event-start">';
$output .= self::field_date_format($value, 'start');
$output .= '</span>';
return $output;
case 'time_end':
$output = '<span class="squat-radar-event-start">';
$output .= self::field_date_format($value, 'start');
$value = $value[0];
$output = '<span class="squat-radar-event-end">';
$output .= self::field_date_format($value, 'end');
$output .= '</span>';
return $output;
@ -150,16 +151,16 @@ class Squat_Radar_Formatter {
* }
* ]
*/
function field_location_html($value, $original, $field, $context) {
static public function field_location_html($value, $original, $field, $context) {
switch ($field[0]) {
case 'map':
$output = [];
foreach ($value as $map) {
if ( is_array($map) && $map['lat'] !== NULL && $map['lon'] !== NULL ) {
if ( is_array($map) && ! empty($map['lat']) && $map['lat'] !== NULL && $map['lon'] !== NULL ) {
$this_output = '<span class="squat-radar-location squat-radar-location-map-link">';
$lat = $map['lat'];
$lon = $map['lon'];
$this_output .= "<a href=\"https://www.openstreetmap.org/?mlat=$lat&mlon=$lon#map=14/$lat/$lon\">";
$this_output .= "<a href=\"https://www.openstreetmap.org/?mlat=$lat&mlon=$lon#map=14/$lat/$lon\" target=\"_blank\">";
$this_output .= __('[Map]', 'squat-radar');
$this_output .= '</a></span>';
$output[] = $this_output;
@ -196,7 +197,7 @@ class Squat_Radar_Formatter {
/**
* Item Radar links implementation of 'squat_radar_field_html' filter.
*/
function field_link_html($value, $original, $field, $context) {
static public function field_link_html($value, $original, $field, $context) {
if ( ($field[0] == 'title' || $field[0] == 'title_field') && ! empty($context['event']['url'])) {
return '<a href="' . esc_url($context['event']['url']) . '" class="squat-radar-url squat-radar-url-title">' . sanitize_text_field( $value ) . '</a>';
}
@ -230,13 +231,40 @@ class Squat_Radar_Formatter {
return $value;
}
/**
* Item Radar summary implementation of 'squat_radar_field_html' filter.
*/
static public function field_summary_html($value, $original, $field, $context) {
if ( $field[0] == 'summary' ) {
// Summary is only populated if there is an explict summary.
if ( empty( trim($value) ) ) {
array_shift($field);
if (is_array($field)) {
$field_tree = array_reverse($field);
$sibling_fields = self::getValue($context['event'], $field_tree);
$value = print_r($context['event'], true);
if (! empty( $sibling_fields['value'] ) ) {
$value = wp_trim_words( $sibling_fields['value'], 30 );
}
}
}
if ( ! empty($value) ) {
$value = '<span class="squat-radar-body-summary">' . wp_kses_post( $value ) . '</span>';
}
}
return $value;
}
/**
* Format image implementation of 'squat_radar_field_html' filter.
*
* Deliberatly run after field_link_html. Showing how to override an existing filter.
* image:file:url
*/
function field_image_html($value, $original, $field, $context) {
static public function field_image_html($value, $original, $field, $context) {
if ($field[0] == 'url' && $field[1] == 'file' && $field[2] == 'image') {
return '<img src="'. esc_url_raw($original) .'" class="squat-radar-image" \>';
}
@ -261,7 +289,7 @@ class Squat_Radar_Formatter {
* @return string
* Flattend array with additional default classes.
*/
function field_html($value, $original, $field, $context) {
static public function field_html($value, $original, $field, $context) {
if ($value != $original) {
return $value;
}
@ -306,7 +334,7 @@ class Squat_Radar_Formatter {
return $output;
}
else {
$value = '<span class="squat-radar-' . sanitize_html_class($field[0]) . '">' . $value . '</span>';
$value = '<span class="squat-radar-' . sanitize_html_class($field[0]) . '">' . wp_kses_post( $value ) . '</span>';
}
return $value;
@ -315,8 +343,8 @@ class Squat_Radar_Formatter {
/**
* Title field HTML implentation of 'squat_radar_field_html' filter.
*/
function field_title_html($value, $original, $field, $context) {
if ($field[0] == 'title' && count($field) == 1) {
static public function field_title_html($value, $original, $field, $context) {
if (($field[0] == 'title' || $field[0] == 'title_field') && count($field) == 1) {
$value = '<h3 class="squat-radar-title">' . $value . '</h3>';
}