diff --git a/includes/squat-radar-connector.php b/includes/squat-radar-connector.php index 8268f35..50479d6 100644 --- a/includes/squat-radar-connector.php +++ b/includes/squat-radar-connector.php @@ -59,7 +59,7 @@ class Squat_Radar_Connector { $result = []; // Urldecode not required here because of the regex match. // Radar paramaters here are transcoded so will match. - if (preg_match('|//radar.squat.net/([a-z]{2})/events/([a-zA-Z0-9/]*)|', $url, $matches)) { + if (preg_match('|//radar.squat.net/([a-z]{2})/events/([a-zA-Z0-9\-/]*)|', $url, $matches)) { $result['language'] = $matches[1]; foreach (array_chunk(explode('/', $matches[2]), 2) as $key_value_pair) { $result['facets'][$key_value_pair[0]] = $key_value_pair[1]; @@ -90,7 +90,7 @@ class Squat_Radar_Connector { // Urlencode should do nothing here @see comment in decode_search_url. // If someone has snuck something in it will however help. foreach ( $facets as $key => $value ) { - $query[] = ['facets[' . urlencode($key) . '][]' => urlencode($value)]; + $query['facets[' . urlencode($key) . ']'][] = urlencode($value); } if ( ! empty($fields) ) { // {raw}urlencode is encoding : and , both of which are valid pchar. diff --git a/includes/squat-radar-formatter.php b/includes/squat-radar-formatter.php index 717d849..8481f49 100644 --- a/includes/squat-radar-formatter.php +++ b/includes/squat-radar-formatter.php @@ -339,12 +339,12 @@ class Squat_Radar_Formatter { 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) ) ) { + $value = trim($value); + if ( empty( $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 ); } @@ -366,7 +366,10 @@ class Squat_Radar_Formatter { * image:file:url */ static public function field_image_html($value, $original, $field, $context) { - if ($field[0] == 'url' && $field[1] == 'file' && $field[2] == 'image') { + if ( isset($field[0]) && $field[0] == 'url' && + isset($field[1]) && $field[1] == 'file' && + isset($field[2]) && $field[2] == 'image' + ) { return ''; } diff --git a/includes/squat-radar-widget.php b/includes/squat-radar-widget.php index 2aacb5a..c058824 100644 --- a/includes/squat-radar-widget.php +++ b/includes/squat-radar-widget.php @@ -40,7 +40,7 @@ class Squat_Radar_Widget extends WP_Widget { * Enqueue scripts callback, add CSS. */ static public function widget_style() { - wp_register_style( 'squat-radar-widget', SQUAT_RADAR_URL . '/assets/squat-radar.css' ); + wp_register_style( 'squat-radar-widget', SQUAT_RADAR_URL . 'assets/squat-radar.css' ); wp_enqueue_style( 'squat-radar-widget' ); } @@ -48,7 +48,7 @@ class Squat_Radar_Widget extends WP_Widget { * Enqueue scripts callback, add JS. */ static public function widget_script() { - wp_register_script( 'squat-radar-widget', SQUAT_RADAR_URL . '/assets/squat-radar.js', ['jquery'] ); + wp_register_script( 'squat-radar-widget', SQUAT_RADAR_URL . 'assets/squat-radar.js', ['jquery'] ); } /** @@ -121,7 +121,7 @@ class Squat_Radar_Widget extends WP_Widget { else { wp_enqueue_script( 'squat-radar-widget'); wp_localize_script( 'squat-radar-widget', 'squat_radar_widget', [ 'ajaxurl' => admin_url( 'admin-ajax.php' ) ] ); - wp_localize_script( 'squat-radar-widget', $widget_id, $instance ); + wp_localize_script( 'squat-radar-widget', $widget_id, ['number' => $this->number] ); echo '
' . esc_url( $instance['url']['value'] ) @@ -140,9 +140,16 @@ class Squat_Radar_Widget extends WP_Widget { } $data = []; - $instance = $_POST['instance']; + + // Load instance configuration from ID. + $instance_number = (int) $_POST['instance']['number']; + $widget_options_all = get_option('widget_squat_radar'); + if ( ! isset($widget_options_all[$instance_number]) ) { + wp_die(); + } + try { - $data['html'] = self::instance_events_html($instance); + $data['html'] = self::instance_events_html($widget_options_all[$instance_number]); } catch ( Squat_Radar_Connector_Exception $e ) { $data = ['is_error' => TRUE]; @@ -193,7 +200,7 @@ class Squat_Radar_Widget extends WP_Widget { // $field_id = esc_attr( $this->get_field_id( 'limit' ) ); $field_name = esc_attr( $this->get_field_name( 'limit' ) ); - $field_label = esc_attr( 'Number of events to display:', 'squat-radar' ); + $field_label = esc_attr( 'Max number of events to display:', 'squat-radar' ); $field_value = empty( $instance['limit'] ) ? '10' : (int) $instance['limit']; $field_class = 'tiny-text'; echo "

"; @@ -219,7 +226,7 @@ class Squat_Radar_Widget extends WP_Widget { echo '

' . __('The URL was not recognised as a Radar Events search result. It needs to include the domain and the rest of the /events/search/path like: https://radar.squat.net/en/events/city/City_Name/group/123 Start from https://radar.squat.net/en/events and use the filters in the right hand colunm there before copying the URL from your browser address bar.', 'squat-radar') . '
'; } else { - echo '
' . __('Go to https://radar.squat.net/en/events and filter for the events you want to show. Then copy the URL from your address bar into here. It will look similar to: https://radar.squat.net/en/events/city/City_Name/group/123', 'squat-radar') . '
'; + echo '
' . __('Go to https://radar.squat.net/en/events and filter for the events you want to show. Then copy the URL from your address bar into here. It will look similar to: https://radar.squat.net/en/events/city/City_Name/group/123 for example the URL to show all international callouts is https://radar.squat.net/en/events/callout/international-callout', 'squat-radar') . '
'; } if ( empty($instance['url']['error']) && ! empty( $instance['url']['keys'] ) ) { @@ -240,6 +247,18 @@ class Squat_Radar_Widget extends WP_Widget { echo '
'; echo '' . __('Fields', 'squat-radar') . ''; echo '

'; + // Some sensible checkbox defaults. + if ( empty($instance['fields']) ) { + $instance['fields'] = [ + 'title_field' => '', + 'date_time:time_start' => '', + 'body:summary' => '', + 'category' => '', + 'offline:address' => '', + 'offline:map' => '', + 'url' => '', + ]; + } foreach ($this->preset_fields() as $api_field_name => $field_label) { $field_id = esc_attr( $this->get_field_id( 'field-' . $api_field_name ) ); $field_name = esc_attr( $this->get_field_name( 'field-' . $api_field_name ) ); @@ -298,7 +317,7 @@ class Squat_Radar_Widget extends WP_Widget { $checked = checked( $use_cron, TRUE, FALSE ); echo ""; echo "
"; - echo '

' . __('Experimental. Do not use AJAX, but always display the cached version of the events. Update the cache after the expiry length using cron. Works best if you have a regular external cronjob running.') . '
'; + echo '
' . __('Do not use AJAX, but always display the cached version of the events. Update the cache after the expiry length using cron. Works best if you have a regular external cronjob running.') . '
'; echo '
'; diff --git a/readme.txt b/readme.txt index f8ccf89..1dffeab 100644 --- a/readme.txt +++ b/readme.txt @@ -1,9 +1,9 @@ === squat-radar === Tags: calendar,events -Requires at least: 4.8 -Tested up to: 5.1 +Requires at least: 4.0 +Tested up to: 5.4 Requires PHP: 5.4.0 -Stable tag: 2.0.0 +Stable tag: 2.0.6 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html @@ -13,11 +13,15 @@ Provides integration with https://radar.squat.net/ to display events on your Wor Enable the plugin as normal for your system. Once activated: -1. Visit the Widgets page. Here you will now see \'Squat Radar Events\' widget, and the \'Squat Radar Shortcode\' sidebar. -2. Add the widget to either the sidebar you want, or if you want to use the shortcode in content, the \'Squat Radar Shortcode\' sidebar. +1. Visit the Widgets page. Here you will now see 'Squat Radar Events' widget, and the 'Squat Radar Shortcode' sidebar. +2. Add the widget to either the sidebar you want, or if you want to use the shortcode in content, the 'Squat Radar Shortcode' sidebar. 3. To configure the sidebar go to https://radar.squat.net/events and filter for the events you want to show. Maybe your city and group, or a category etc. 4. Once you have the events filter you want copy the address from your address bar into the widget. 5. Select which fields you would like to show. -If you put the widget in a displayed sidebar that\'s it. The filtered list of upcoming events will now show up. +If you put the widget in a displayed sidebar that's it. The filtered list of upcoming events will now show up. If you used the Shortcode sidebar, add [squat_radar_sidebar] to the content where you want the events to display. +If you put the shortcode in a page called 'Events', make sure you've disabled any plugins which would suppress the contents of that page, for example 'The Events Calendar'. + +For extra-easy instructions with screenshots, look here: +https://network23.org/blog/2019/10/18/radar-events-plugin/ diff --git a/squat-radar.php b/squat-radar.php index 16e317c..50d07b5 100644 --- a/squat-radar.php +++ b/squat-radar.php @@ -11,9 +11,8 @@ * Plugin Name: Squat Radar calendar integration * Plugin URI: https://0xacab.org/radar/radar-wp * Description: Provides widget, and shortcode, integration for displaying events from https://radar.squat.net/ agenda. - * Version: 2.0.0 + * Version: 2.0.6 * Author: Radar contributors - * Author URI: https://0xacab.org/radar/radar-wp * License: GPL-2.0+ * License URI: http://www.gnu.org/licenses/gpl-2.0.txt * Text Domain: squat-radar