diff --git a/assets/squat-radar.css b/assets/squat-radar.css
index 699652c..bc17894 100644
--- a/assets/squat-radar.css
+++ b/assets/squat-radar.css
@@ -29,7 +29,15 @@
font-weight: bold;
}
-.squat-radar .squat-radar-datetime::before {
+.squat-radar .squat-radar-datetime.squat-radar-datetime-start::before {
+ content: '';
+ display: block;
+ float: none;
+ clear: both;
+}
+
+.squat-radar .squat-radar-event-start-end::after,
+.squat-radar .squat-radar-event-start {
content: '';
display: block;
float: none;
@@ -38,6 +46,15 @@
.squat-radar .squat-radar-list li {
display: inline;
+ list-style: none;
+}
+
+.squat-radar .squat-radar-list li:after {
+ content: ", ";
+}
+
+.squat-radar .squat-radar-list li:last-child:after {
+ content: "";
}
.squat-radar a.squat-radar-url-more {
diff --git a/assets/squat-radar.js b/assets/squat-radar.js
index 186b0b1..00394f9 100644
--- a/assets/squat-radar.js
+++ b/assets/squat-radar.js
@@ -18,6 +18,7 @@ jQuery(function($){
);
}
} else {
+ $(widget).empty();
$(widget).append(result.html);
// $(".squat-li a").on('click', function(e){
diff --git a/includes/squat-radar-connector.php b/includes/squat-radar-connector.php
index f8ff6bc..5df59a6 100644
--- a/includes/squat-radar-connector.php
+++ b/includes/squat-radar-connector.php
@@ -58,7 +58,8 @@ class Squat_Radar_Connector {
}
function events( $facets, $fields = [], $language = NULL, $limit = 10, $expiration = 10800, $reset = FALSE ) {
- $fields = array_merge($fields, ['uuid', 'title', 'url', 'event_status']);
+ // Fields we often want to get data out of but not necessarily are chosen to be shown.
+ $fields = array_merge($fields, ['uuid', 'title', 'body:value', 'url', 'event_status']);
$transient_key = 'squat_radar_events_' . sha1(implode($facets) . implode($fields) . $language . $limit);
if (! $reset && $data = get_transient( $transient_key )) {
return $data;
diff --git a/includes/squat-radar-formatter.php b/includes/squat-radar-formatter.php
index 055ea01..435fcfe 100644
--- a/includes/squat-radar-formatter.php
+++ b/includes/squat-radar-formatter.php
@@ -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 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 = '';
+ $output = '';
$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 .= '';
return $output;
case 'time_start':
-
+ $value = $value[0];
$output = '';
$output .= self::field_date_format($value, 'start');
$output .= '';
return $output;
case 'time_end':
-
- $output = '';
- $output .= self::field_date_format($value, 'start');
+ $value = $value[0];
+ $output = '';
+ $output .= self::field_date_format($value, 'end');
$output .= '';
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 = '';
$lat = $map['lat'];
$lon = $map['lon'];
- $this_output .= "";
+ $this_output .= "";
$this_output .= __('[Map]', 'squat-radar');
$this_output .= '';
$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 '' . sanitize_text_field( $value ) . '';
}
@@ -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 = '' . wp_kses_post( $value ) . '';
+ }
+ }
+
+ 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 '';
}
@@ -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 = '' . $value . '';
+ $value = '' . wp_kses_post( $value ) . '';
}
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 = ' ";
- echo __('If you want to display this single widget in a page or post use the Shortcode:') . ' ';
- if ( $this->number == '__i__' ) {
- echo '' . __( 'Shortcode will be available once you have saved this the first time') . '';
- }
- else {
- esc_attr_e( '[squat_radar_widget id="' . $this->number . '"]' );
- }
- echo "' . $value . '
';
}
diff --git a/includes/squat-radar-instance.php b/includes/squat-radar-instance.php
index db62124..14c542d 100644
--- a/includes/squat-radar-instance.php
+++ b/includes/squat-radar-instance.php
@@ -62,7 +62,7 @@ class Squat_Radar_Instance {
register_sidebar([
'name' => __( 'Squat Radar Shortcodes'),
- 'description'=> __( 'This widget area is not by default displayed on frontend. It can be displayed with all its widgets with the [squat_radar] shortcode; or used to hold active widgets displayed with their own [squat_radar_widget id="X"] shortcode, see instructions on widget configuration for the id.', 'squat-radar' ),
+ 'description'=> __( 'This widget area is not by default displayed on frontend. It can be displayed with all its widgets with the [squat_radar_sidebar] shortcode.', 'squat-radar' ),
'id' => 'squat_radar_widget_shortcode',
'before_widget' => ' ',
diff --git a/includes/squat-radar-widget.php b/includes/squat-radar-widget.php
index e41a8bc..c67f029 100644
--- a/includes/squat-radar-widget.php
+++ b/includes/squat-radar-widget.php
@@ -22,9 +22,7 @@ class Squat_Radar_Widget extends WP_Widget {
add_action( 'wp_ajax_squat_radar_events', [__CLASS__, 'ajax_callback'] );
add_action( 'wp_ajax_nopriv_squat_radar_events', [__CLASS__, 'ajax_callback'] );
add_action( 'wp_enqueue_scripts', [__CLASS__, 'widget_script'] );
- add_action( 'wp_enqueue_style', [__CLASS__, 'widget_style'] );
-
- add_shortcode( 'squat_radar_widget', [__CLASS__, 'shortcode' ] );
+ add_action( 'wp_enqueue_scripts', [__CLASS__, 'widget_style'] );
add_action( 'squat_radar_widget_cache_cron', [__CLASS__, 'cache_cron'] );
add_option( 'squat_radar_widget_cron_run', []);
@@ -32,44 +30,13 @@ class Squat_Radar_Widget extends WP_Widget {
static public function widget_style() {
wp_register_style( 'squat-radar-widget', SQUAT_RADAR_URL . '/assets/squat-radar.css' );
+ wp_enqueue_style( 'squat-radar-widget' );
}
static public function widget_script() {
wp_register_script( 'squat-radar-widget', SQUAT_RADAR_URL . '/assets/squat-radar.js', ['jquery'] );
}
- /**
- * Output a widget using 'squat_radar_widget' shortcode.
- *
- * Requires the widget ID.
- *
- * @example [squat_radar_widget id="1"]
- */
- static public function shortcode( $attributes, $content = '' ) {
- $defaults = [
- 'id' => '__i__',
- ];
- $attributes = shortcode_atts($defaults, $attributes, 'squat_radar_widget');
-
- // Return early if ID is unknown.
- $option = get_option( 'widget_squat_radar' );
- if (! isset( $option[$attributes['id']] )) {
- if ( current_user_can( 'administrator' ) ) {
- $content = '' . __('Squat Radar Widget shortcode ID not recognised. Check the suggestion at the top of the widget in the adminstration interface.', 'squat-radar') . '';
- }
- return $content;
- }
-
- $instance = $option[$attributes['id']];
- // render the widget
- ob_start();
- // To allow overriding the args here? For before after etc.
- the_widget( __CLASS__, $instance);
- $content = ob_get_clean();
-
- return $content;
- }
-
public static function cache_cron() {
$now = time();
$last_run = get_option('squat_radar_widget_cron_run', []);
@@ -86,12 +53,15 @@ class Squat_Radar_Widget extends WP_Widget {
protected static function cache_refresh($instance) {
$connector = new Squat_Radar_Connector();
- // @todo Languages...
- try {
- $data = $connector->events($instance['url']['keys']['facets'], $instance['fields'], $language, $instance['limit'], 0, TRUE );
- }
- catch ( Squat_Radar_Connector_Exception $e ) {
- return FALSE;
+ $languages = apply_filters( 'wpml_active_languages', NULL);
+ $languages = array_merge($instance['url']['keys']['language'], (array) $languages);
+ foreach ($languages as $language) {
+ try {
+ $data = $connector->events($instance['url']['keys']['facets'], $instance['fields'], $language, $instance['limit'], 0, TRUE );
+ }
+ catch ( Squat_Radar_Connector_Exception $e ) {
+ return FALSE;
+ }
}
return TRUE;
@@ -99,7 +69,6 @@ class Squat_Radar_Widget extends WP_Widget {
public function widget( $args, $instance ) {
- wp_enqueue_style( 'squat-radar-widget' );
$widget_id = 'squat_radar_widget_' . $this->number;
echo $args['before_widget'];
@@ -158,7 +127,7 @@ class Squat_Radar_Widget extends WP_Widget {
public static function instance_events_html($instance) {
$language = defined('ICL_LANGUAGE_CODE') ? ICL_LANGUAGE_CODE : $instance['url']['keys']['language'];
$connector = new Squat_Radar_Connector();
- $data = $connector->events($instance['url']['keys']['facets'], $instance['fields'], $language, $instance['limit'], $instance['cache_expire'], TRUE );
+ $data = $connector->events($instance['url']['keys']['facets'], $instance['fields'], $language, $instance['limit'], $instance['cache_expire']);
$html = '';
foreach ($data['result'] as $id => $event) {
$output = apply_filters( 'squat_radar_format_event', $event, $instance['fields'], ['instance' => $instance] );
@@ -170,19 +139,6 @@ class Squat_Radar_Widget extends WP_Widget {
public function form( $instance ) {
- //
- // Introduction.
- //
- echo "