diff --git a/includes/squat-radar-connector.php b/includes/squat-radar-connector.php index 5df59a6..8268f35 100644 --- a/includes/squat-radar-connector.php +++ b/includes/squat-radar-connector.php @@ -1,11 +1,35 @@ language code, 'facets' => [key => value] ]. + */ function decode_search_url( $url ) { $matches = []; $result = []; @@ -36,6 +69,21 @@ class Squat_Radar_Connector { return $result; } + /** + * Encode a query key value from facets, fields, language, limit. + * + * @param array $facets + * Optional. Facet key => filter value array. + * @param array $fields + * Optional. Index array of API field names to retrieve. + * @param string $language + * Optional. Language code. + * @param int $limit + * Optional. Maximum number to items to return. + * + * @return array + * Array for use in self::get_events(). + */ function encode_api_query( $facets = [], $fields = [], $language = '', $limit = 10 ) { $query = []; @@ -57,6 +105,25 @@ class Squat_Radar_Connector { return $query; } + /** + * Return events meeting argument criteria. Either from cache, or retrieved from API. + * + * @param array $facets + * Facet name key => filter value. + * @param array $fields + * Optional. Array of key names. + * @param string $language + * Optional. Language code. + * @param int $limit + * Maximum number of items to return. + * @param int $expiration + * Seconds to cache results. 0 never expires. + * @param bool $reset + * Force a cache reset. + * + * @return array + * Array of event arrays, values keyed by field name. + */ function events( $facets, $fields = [], $language = NULL, $limit = 10, $expiration = 10800, $reset = FALSE ) { // 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']); diff --git a/includes/squat-radar-formatter.php b/includes/squat-radar-formatter.php index 435fcfe..717d849 100644 --- a/includes/squat-radar-formatter.php +++ b/includes/squat-radar-formatter.php @@ -1,7 +1,27 @@ '; + foreach ($value as $row) { + $output .= '
  • ' . sanitize_text_field( $row ) . '
  • '; + } + $output .= ''; + + return $output; + } + else { + $value = '' . wp_kses_post( $value ) . ''; + } + + return $value; + } + /** * Date field formatting implementation of 'squat_radar_field_html' filter. */ @@ -257,11 +359,10 @@ class Squat_Radar_Formatter { return $value; } - /** * Format image implementation of 'squat_radar_field_html' filter. * - * Deliberatly run after field_link_html. Showing how to override an existing filter. + * Intentionally run after field_link_html. Showing how to override an existing filter. * image:file:url */ static public function field_image_html($value, $original, $field, $context) { @@ -272,76 +373,9 @@ class Squat_Radar_Formatter { return $value; } + /** - * Basic implementation of 'squat_radar_field_html' filter. - * - * Put the output into HTML. - * - * @param array|string $value - * The field value being manipulated to become HTML to be displayed. - * @param array|string $original - * The original value of the field before any changes by filters. - * @param array $field - * The field tree. $field[0] being the name of the present field. $field[1] - * being any parent etc. - * @param array $context - * - * @return string - * Flattend array with additional default classes. - */ - static public function field_html($value, $original, $field, $context) { - if ($value != $original) { - return $value; - } - - if (is_array($value)) { - if ( ! empty($value['value']) ) { - $value = $value['value']; - } - elseif ( ! empty($value['title']) ) { - $value = $value['title']; - } - elseif ( ! empty($value['name']) ) { - $value = $value['name']; - } - elseif ( ! empty($value[0]['value']) ) { - foreach ($value as $row) { - $values[] = $row['value']; - } - $value = $values; - } - elseif ( ! empty($value[0]['title']) ) { - foreach ($value as $row) { - $titles[] = $row['title']; - } - $value = $titles; - } - elseif ( ! empty($value[0]['name']) ) { - foreach ($value as $row) { - $names[] = $row['name']; - } - $value = $names; - } - } - - if (is_array($value)) { - $output = ''; - - return $output; - } - else { - $value = '' . wp_kses_post( $value ) . ''; - } - - return $value; - } - - /** - * Title field HTML implentation of 'squat_radar_field_html' filter. + * Title field HTML implementation of 'squat_radar_field_html' filter. */ static public function field_title_html($value, $original, $field, $context) { if (($field[0] == 'title' || $field[0] == 'title_field') && count($field) == 1) { diff --git a/includes/squat-radar-instance.php b/includes/squat-radar-instance.php index 14c542d..f37cc63 100644 --- a/includes/squat-radar-instance.php +++ b/includes/squat-radar-instance.php @@ -1,11 +1,12 @@ events($instance['url']['keys']['facets'], $instance['fields'], $language, $instance['limit'], 0, TRUE ); } catch ( Squat_Radar_Connector_Exception $e ) { @@ -68,7 +91,11 @@ class Squat_Radar_Widget extends WP_Widget { return TRUE; } - + /** + * Implementation of WP_Widget::widget(). + * + * Outputs the events for the correct instance of the widget. + */ public function widget( $args, $instance ) { $widget_id = 'squat_radar_widget_' . $this->number; @@ -104,6 +131,9 @@ class Squat_Radar_Widget extends WP_Widget { echo $args['after_widget']; } + /** + * Action callback for AJAX widget display. + */ public static function ajax_callback() { if ( ! array_key_exists('instance', $_POST) ) { wp_die(); @@ -138,6 +168,11 @@ class Squat_Radar_Widget extends WP_Widget { return $html; } + /** + * Implementation of WP_Widget::form(). + * + * Widget options. + */ public function form( $instance ) { // @@ -269,7 +304,11 @@ class Squat_Radar_Widget extends WP_Widget { } - + /** + * Implementation of WP_Widget::update(). + * + * Save widget options. + */ public function update( $new_instance, $old_instance ) { $options = [];