+
| ' . __( 'Est. Moving Time', 'wp-strava' ) . ' |
diff --git a/src/WPStrava/StyleTranslations.php b/src/WPStrava/StyleTranslations.php
new file mode 100644
index 0000000..3bab331
--- /dev/null
+++ b/src/WPStrava/StyleTranslations.php
@@ -0,0 +1,50 @@
+
+ * @since 2.4
+ */
+ public function hook() {
+ add_action( 'wp_head', array( $this, 'print_style_translations' ) );
+ }
+
+ /**
+ * Add translation text to column header, identified by class.
+ *
+ * @param [type] $class CSS class for table data ().
+ * @param [type] $translation Text to add to column.
+ * @author Justin Foell
+ * @since 2.4
+ */
+ public function add_style_translation( $class, $translation ) {
+ $this->style_translations[ $class ] = $translation;
+ }
+ /**
+ * Print translatable strings as ";
+ }
+
+}
From aa9008822e5c5865dceb4078e676a11d64956a73 Mon Sep 17 00:00:00 2001
From: Justin Foell <630830+jrfoell@users.noreply.github.com>
Date: Mon, 2 Nov 2020 15:50:00 -0600
Subject: [PATCH 02/13] Responsive tables first pass
---
css/wp-strava.css | 41 ++++++
src/WPStrava.php | 2 -
src/WPStrava/ActivityRenderer.php | 80 +++++++----
src/WPStrava/ActivityShortcode.php | 4 +-
src/WPStrava/Blocks/Activity.php | 4 +
src/WPStrava/StyleTranslationRenderer.php | 158 ++++++++++++++++++++++
src/WPStrava/StyleTranslations.php | 50 -------
7 files changed, 258 insertions(+), 81 deletions(-)
create mode 100644 src/WPStrava/StyleTranslationRenderer.php
delete mode 100644 src/WPStrava/StyleTranslations.php
diff --git a/css/wp-strava.css b/css/wp-strava.css
index 7c1aea6..0b58c0d 100755
--- a/css/wp-strava.css
+++ b/css/wp-strava.css
@@ -32,3 +32,44 @@
.activity-details-table-units {
font-size: 0.8em;
}
+
+/* Responsive Tables */
+@media
+only screen and (max-width: 760px),
+(min-device-width: 768px) and (max-device-width: 1024px) {
+
+ /* Force table to not be like tables anymore */
+ table, thead, tbody, th, td, tr {
+ display: block;
+ }
+
+ /* Hide table headers (but not display: none;, for accessibility) */
+ thead tr {
+ position: absolute;
+ top: -9999px;
+ left: -9999px;
+ }
+
+ td {
+ /* Behave like a "row" */
+ border: none;
+ border-bottom: 1px solid #eee;
+ position: relative;
+ padding-left: 50%;
+ }
+
+ td:before {
+ /* Now like a table header */
+ position: absolute;
+ /* Top/left values mimic padding */
+ top: 5px;
+ left: 5px;
+ width: 45%;
+ padding-right: 10px;
+ white-space: nowrap;
+ }
+
+ .activity-details-table-info, .activity-details-table-units {
+ display: inline;
+ }
+}
diff --git a/src/WPStrava.php b/src/WPStrava.php
index c15be54..e3ceb17 100644
--- a/src/WPStrava.php
+++ b/src/WPStrava.php
@@ -85,8 +85,6 @@ class WPStrava {
if ( is_admin() ) {
$this->settings->hook();
} else { // Front-end.
- $this->style_translations = new WPStrava_StyleTranslations();
- $this->style_translations->hook();
add_action( 'init', array( $this, 'register_shortcodes' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'register_scripts' ) );
}
diff --git a/src/WPStrava/ActivityRenderer.php b/src/WPStrava/ActivityRenderer.php
index 6a94040..5322af6 100644
--- a/src/WPStrava/ActivityRenderer.php
+++ b/src/WPStrava/ActivityRenderer.php
@@ -2,7 +2,7 @@
/*
* ActivityRenderer has all the markup for the Activity Block & Shortcode.
*/
-class WPStrava_ActivityRenderer {
+class WPStrava_ActivityRenderer extends WPStrava_StyleTranslationRenderer {
/**
* Get the HTML for a single activity.
@@ -64,10 +64,19 @@ class WPStrava_ActivityRenderer {
return $activity_output;
}
+ public static function load_style_translations() {
+ self::add_style_translation( 'wp-strava-td-avg-speed', __( 'Average Speed', 'wp-strava' ) );
+ self::add_style_translation( 'wp-strava-td-max-speed', __( 'Max Speed', 'wp-strava' ) );
+ self::add_style_translation( 'wp-strava-td-elevation', __( 'Elevation Gain', 'wp-strava' ) );
+ self::add_style_translation( 'wp-strava-td-elapsed-time', __( 'Elapsed Time', 'wp-strava' ) );
+ self::add_style_translation( 'wp-strava-td-moving-time', __( 'Moving Time', 'wp-strava' ) );
+ self::add_style_translation( 'wp-strava-td-distance', __( 'Distance', 'wp-strava' ) );
+ }
+
/**
* The the activity details in in HTML table.
*
- * @param string $activity_details Activity details from the activity class.
+ * @param stdClass $activity_details Activity details from the activity class.
* @param string $som System of measure (english/metric).
* @return string HTML Table of activity details.
* @author Justin Foell
@@ -80,27 +89,42 @@ class WPStrava_ActivityRenderer {
$avg_title = '| ' . __( 'Average Speed', 'wp-strava' ) . ' | ';
$max_title = '' . __( 'Max Speed', 'wp-strava' ) . ' | ';
$elevation_title = '' . __( 'Elevation Gain', 'wp-strava' ) . ' | ';
+ $elevation = '
+ ' . $strava_som->elevation( $activity_details->total_elevation_gain ) . '
+ ' . $strava_som->get_elevation_label() . '
+ | ';
$avg_speed = '';
$max_speed = '';
- $elevation = '' . $strava_som->elevation( $activity_details->total_elevation_gain ) . ' | ';
- $speed_label = '';
- $elevation_label = '' . $strava_som->get_elevation_label() . ' | ';
switch ( $strava_activitytype ) {
case WPStrava_ActivityType::TYPE_GROUP_PACE:
- $avg_speed = '' . $strava_som->pace( $activity_details->average_speed ) . ' | ';
- $max_speed = '' . $strava_som->pace( $activity_details->max_speed ) . ' | ';
- $speed_label = '' . $strava_som->get_pace_label() . ' | ';
+ $avg_speed = '
+ ' . $strava_som->pace( $activity_details->average_speed ) . '
+ ' . $strava_som->get_pace_label() . '
+ | ';
+ $max_speed = '
+ ' . $strava_som->pace( $activity_details->max_speed ) . '
+ | ';
break;
case WPStrava_ActivityType::TYPE_GROUP_SPEED:
- $avg_speed = '' . $strava_som->speed( $activity_details->average_speed ) . ' | ';
- $max_speed = '' . $strava_som->speed( $activity_details->max_speed ) . ' | ';
- $speed_label = '' . $strava_som->get_speed_label() . ' | ';
+ $avg_speed = '
+ ' . $strava_som->speed( $activity_details->average_speed ) . '
+ ' . $strava_som->get_speed_label() . '
+ | ';
+ $max_speed = '
+ ' . $strava_som->speed( $activity_details->max_speed ) . '
+ ' . $strava_som->get_speed_label() . '
+ | ';
break;
case WPStrava_ActivityType::TYPE_GROUP_PACE:
- $avg_speed = '' . $strava_som->swimpace( $activity_details->average_speed ) . ' | ';
- $max_speed = '' . $strava_som->swimpace( $activity_details->max_speed ) . ' | ';
- $speed_label = '' . $strava_som->get_swimpace_label() . ' | ';
+ $avg_speed = '
+ ' . $strava_som->swimpace( $activity_details->average_speed ) . '
+ ' . $strava_som->get_swimpace_label() . '
+ | ';
+ $max_speed = '
+ ' . $strava_som->swimpace( $activity_details->max_speed ) . '
+ ' . $strava_som->get_swimpace_label() . '
+ | ';
break;
default:
$avg_title = '';
@@ -109,9 +133,8 @@ class WPStrava_ActivityRenderer {
}
if ( WPStrava::get_instance()->settings->hide_elevation ) {
- $elevation = '';
$elevation_title = '';
- $elevation_label = '';
+ $elevation = '';
}
return '
@@ -127,22 +150,23 @@ class WPStrava_ActivityRenderer {
|
-
- | ' . $strava_som->time( $activity_details->elapsed_time ) . ' |
- ' . $strava_som->time( $activity_details->moving_time ) . ' |
- ' . $strava_som->distance( $activity_details->distance ) . ' |
+
+ |
+ ' . $strava_som->time( $activity_details->elapsed_time ) . '
+ ' . $strava_som->get_time_label() . '
+ |
+
+ ' . $strava_som->time( $activity_details->moving_time ) . '
+ ' . $strava_som->get_time_label() . '
+ |
+
+ ' . $strava_som->distance( $activity_details->distance ) . '
+ ' . $strava_som->get_distance_label() . '
+ |
' . $avg_speed . '
' . $max_speed . '
' . $elevation . '
-
- | ' . $strava_som->get_time_label() . ' |
- ' . $strava_som->get_time_label() . ' |
- ' . $strava_som->get_distance_label() . ' |
- ' . $speed_label . '
- ' . $speed_label . '
- ' . $elevation_label . '
-
';
diff --git a/src/WPStrava/ActivityShortcode.php b/src/WPStrava/ActivityShortcode.php
index 8350294..ecce5f3 100644
--- a/src/WPStrava/ActivityShortcode.php
+++ b/src/WPStrava/ActivityShortcode.php
@@ -31,6 +31,8 @@ class WPStrava_ActivityShortcode {
add_shortcode( 'ride', array( $this, 'handler' ) ); // @deprecated 1.1
add_shortcode( 'activity', array( $this, 'handler' ) );
add_action( 'wp_footer', array( $this, 'print_scripts' ) );
+ WPStrava_ActivityRenderer::load_shortcode_style_translations( array( 'ride', 'activity' ) );
+ WPStrava_ActivityRenderer::load_style_translations();
}
/**
@@ -49,7 +51,7 @@ class WPStrava_ActivityShortcode {
return __( 'The athlete_token parameter is deprecated as of WP-Strava version 2 and should be replaced with client_id.', 'wp-strava' );
}
- $this->add_script = true;
+ $this->add_script = WPStrava_ActivityRenderer::has_shortcode( array( 'ride', 'activity' ) );
$renderer = new WPStrava_ActivityRenderer();
return $renderer->get_html( $atts );
diff --git a/src/WPStrava/Blocks/Activity.php b/src/WPStrava/Blocks/Activity.php
index 3baa5e3..982fa2d 100644
--- a/src/WPStrava/Blocks/Activity.php
+++ b/src/WPStrava/Blocks/Activity.php
@@ -5,6 +5,10 @@
class WPStrava_Blocks_Activity implements WPStrava_Blocks_Interface {
+ public function __construct() {
+ WPStrava_ActivityRenderer::load_style_translations( array( 'wp-strava/activity' ) );
+ }
+
/**
* Register the wp-strava/activity block.
*
diff --git a/src/WPStrava/StyleTranslationRenderer.php b/src/WPStrava/StyleTranslationRenderer.php
new file mode 100644
index 0000000..77b5df4
--- /dev/null
+++ b/src/WPStrava/StyleTranslationRenderer.php
@@ -0,0 +1,158 @@
+
+ * @since 2.4
+ */
+abstract class WPStrava_StyleTranslationRenderer {
+
+ /**
+ * Translations indexed by class.
+ * @var array
+ */
+ private static $style_translations = array();
+
+ private static $shortcodes = array();
+
+ private static $blocks = array();
+
+ private static $has_shortcodes = array();
+
+ private static $has_blocks = array();
+
+ abstract public static function load_style_translations();
+
+ public static function load_block_style_translations( $block ) {
+ $block = ! is_array( $block ) ? array( $block ) : $block;
+ self::$blocks = array_unique( array_merge( self::$blocks, $block ) );
+ self::add_filter();
+ }
+
+ public static function load_shortcode_style_translations( $shortcode ) {
+ $shortcode = ! is_array( $shortcode ) ? array( $shortcode ) : $shortcode;
+ self::$shortcodes = array_unique( array_merge( self::$shortcodes, $shortcode ) );
+ self::add_filter();
+ }
+
+ /**
+ * Add translation text to column header, identified by class.
+ *
+ * @param [type] $class CSS class for table data ().
+ * @param [type] $translation Text to add to column.
+ * @author Justin Foell
+ * @since 2.4
+ */
+ public static function add_style_translation( $class, $translation ) {
+ self::$style_translations[ $class ] = $translation;
+ }
+
+ public static function posts_results( $posts ) {
+ global $wp_query;
+
+ if ( ! $wp_query->is_main_query() || $wp_query->is_admin() ) {
+ return $posts;
+ }
+
+ if ( empty( $posts ) ) {
+ return $posts;
+ }
+
+ if ( empty( self::$shortcodes ) && empty( self::$blocks ) ) {
+ return $posts;
+ }
+
+ // This should only run once per request.
+ remove_filter( 'posts_results', array( __CLASS__, 'posts_results' ) );
+
+ foreach ( $posts as $post ) {
+ if ( self::has_shortcodes( $post ) || self::has_blocks( $post ) ) {
+ self::add_action();
+ }
+ }
+
+ return $posts;
+ }
+
+ public static function has_shortcode( $shortcode ) {
+ $shortcode = ! is_array( $shortcode ) ? array( $shortcode ) : $shortcode;
+ return ! empty( array_intersect( self::$has_shortcodes, $shortcode ) );
+ }
+
+ public static function has_block( $block ) {
+ $block = ! is_array( $block ) ? array( $block ) : $block;
+ return ! empty( array_intersect( self::$has_blocks, $block ) );
+ }
+
+
+ private static function add_filter() {
+ if ( ! has_filter( 'posts_results', array( __CLASS__, 'posts_results' ) ) ) {
+ add_filter( 'posts_results', array( __CLASS__, 'posts_results' ) );
+ }
+ }
+
+ private static function add_action() {
+ if ( ! has_action( 'wp_head', array( __CLASS__, 'print_style_translations' ) ) ) {
+ add_action( 'wp_head', array( __CLASS__, 'print_style_translations' ) );
+ }
+ }
+
+ private static function has_shortcodes( $post ) {
+ if ( empty( self::$shortcodes ) ) {
+ return false;
+ }
+
+ $has_shortcode = false;
+ foreach ( self::$shortcodes as $shortcode ) {
+ if ( has_shortcode( $post->post_content, $shortcode ) ) {
+ if ( ! in_array( $shortcode, self::$has_shortcodes, true ) ) {
+ self::$has_shortcodes[] = $shortcode;
+ }
+ $has_shortcode = true;
+ }
+ }
+
+ return $has_shortcode;
+ }
+
+ private static function has_blocks( $post ) {
+ if ( empty( self::$blocks ) ) {
+ return false;
+ }
+
+ $has_block = false;
+ foreach ( self::$blocks as $block ) {
+ if ( has_block( $block, $post ) ) {
+ if ( ! in_array( $block, self::$has_blocks, true ) ) {
+ self::$has_blocks[] = $block;
+ }
+ return true;
+ }
+ }
+
+ return $has_block;
+ }
+
+ /**
+ * Print translatable strings as ";
+ }
+}
diff --git a/src/WPStrava/StyleTranslations.php b/src/WPStrava/StyleTranslations.php
deleted file mode 100644
index 3bab331..0000000
--- a/src/WPStrava/StyleTranslations.php
+++ /dev/null
@@ -1,50 +0,0 @@
-
- * @since 2.4
- */
- public function hook() {
- add_action( 'wp_head', array( $this, 'print_style_translations' ) );
- }
-
- /**
- * Add translation text to column header, identified by class.
- *
- * @param [type] $class CSS class for table data ().
- * @param [type] $translation Text to add to column.
- * @author Justin Foell
- * @since 2.4
- */
- public function add_style_translation( $class, $translation ) {
- $this->style_translations[ $class ] = $translation;
- }
- /**
- * Print translatable strings as ";
- }
-
-}
From ab1d8f8515add0585462efa3cf4c75187049195f Mon Sep 17 00:00:00 2001
From: Justin Foell <630830+jrfoell@users.noreply.github.com>
Date: Mon, 2 Nov 2020 16:43:15 -0600
Subject: [PATCH 03/13] Documentation and formatting
---
css/wp-strava.css | 2 +-
src/WPStrava/ActivityShortcode.php | 2 +-
src/WPStrava/Blocks/Activity.php | 3 +-
src/WPStrava/RouteShortcode.php | 2 +-
src/WPStrava/SOM.php | 6 +-
src/WPStrava/StyleTranslationRenderer.php | 210 +++++++++++++++-------
6 files changed, 157 insertions(+), 68 deletions(-)
diff --git a/css/wp-strava.css b/css/wp-strava.css
index 0b58c0d..53cfc3e 100755
--- a/css/wp-strava.css
+++ b/css/wp-strava.css
@@ -53,7 +53,7 @@ only screen and (max-width: 760px),
td {
/* Behave like a "row" */
border: none;
- border-bottom: 1px solid #eee;
+ border-bottom: 1px solid #e7e7e7;
position: relative;
padding-left: 50%;
}
diff --git a/src/WPStrava/ActivityShortcode.php b/src/WPStrava/ActivityShortcode.php
index ecce5f3..571d894 100644
--- a/src/WPStrava/ActivityShortcode.php
+++ b/src/WPStrava/ActivityShortcode.php
@@ -31,7 +31,7 @@ class WPStrava_ActivityShortcode {
add_shortcode( 'ride', array( $this, 'handler' ) ); // @deprecated 1.1
add_shortcode( 'activity', array( $this, 'handler' ) );
add_action( 'wp_footer', array( $this, 'print_scripts' ) );
- WPStrava_ActivityRenderer::load_shortcode_style_translations( array( 'ride', 'activity' ) );
+ WPStrava_ActivityRenderer::register_shortcode_style_translations( array( 'ride', 'activity' ) );
WPStrava_ActivityRenderer::load_style_translations();
}
diff --git a/src/WPStrava/Blocks/Activity.php b/src/WPStrava/Blocks/Activity.php
index 982fa2d..f579e41 100644
--- a/src/WPStrava/Blocks/Activity.php
+++ b/src/WPStrava/Blocks/Activity.php
@@ -6,7 +6,8 @@
class WPStrava_Blocks_Activity implements WPStrava_Blocks_Interface {
public function __construct() {
- WPStrava_ActivityRenderer::load_style_translations( array( 'wp-strava/activity' ) );
+ WPStrava_ActivityRenderer::register_block_style_translations( 'wp-strava/activity' );
+ WPStrava_ActivityRenderer::load_style_translations();
}
/**
diff --git a/src/WPStrava/RouteShortcode.php b/src/WPStrava/RouteShortcode.php
index 1c62cfd..f56f6d3 100644
--- a/src/WPStrava/RouteShortcode.php
+++ b/src/WPStrava/RouteShortcode.php
@@ -102,7 +102,7 @@ class WPStrava_RouteShortcode {
/**
* The the route details in in HTML table.
*
- * @param string $route_details route details from the route class.
+ * @param stdClass $route_details route details from the route class.
* @param string $som System of measure (english/metric).
* @return string HTML Table of route details.
* @author Justin Foell
diff --git a/src/WPStrava/SOM.php b/src/WPStrava/SOM.php
index 11c4edb..0fc6e81 100644
--- a/src/WPStrava/SOM.php
+++ b/src/WPStrava/SOM.php
@@ -36,9 +36,9 @@ abstract class WPStrava_SOM {
* @see https://stackoverflow.com/a/20870843/2146022
*/
public function time( $seconds ) {
- $zero = new DateTime( '@0' );
- $offset = new DateTime( "@{$seconds}" );
- $diff = $zero->diff( $offset );
+ $zero = new DateTime( '@0' );
+ $offset = new DateTime( "@{$seconds}" );
+ $diff = $zero->diff( $offset );
return sprintf( '%02d:%02d:%02d', $diff->days * 24 + $diff->h, $diff->i, $diff->s );
}
diff --git a/src/WPStrava/StyleTranslationRenderer.php b/src/WPStrava/StyleTranslationRenderer.php
index 77b5df4..2a27d23 100644
--- a/src/WPStrava/StyleTranslationRenderer.php
+++ b/src/WPStrava/StyleTranslationRenderer.php
@@ -14,26 +14,62 @@ abstract class WPStrava_StyleTranslationRenderer {
*/
private static $style_translations = array();
+ /**
+ * Shortcodes registered with translatable style strings.
+ * @var array
+ */
private static $shortcodes = array();
+ /**
+ * Blocks registered with translatable style strings.
+ * @var array
+ */
private static $blocks = array();
+ /**
+ * Shortcodes found in content of current page.
+ * @var array
+ */
private static $has_shortcodes = array();
+ /**
+ * Blocks found in content of current page.
+ * @var array
+ */
private static $has_blocks = array();
+ /**
+ * Implemented by concrete renderers to load column headers by calling self::add_style_translation().
+ *
+ * @author Justin Foell
+ * @since 2.4
+ */
abstract public static function load_style_translations();
- public static function load_block_style_translations( $block ) {
- $block = ! is_array( $block ) ? array( $block ) : $block;
- self::$blocks = array_unique( array_merge( self::$blocks, $block ) );
- self::add_filter();
- }
-
- public static function load_shortcode_style_translations( $shortcode ) {
+ /**
+ * Register a shortcode that has translatable CSS strings.
+ *
+ * @param string|array $shortcode Shortcode (or array of shortcodes).
+ * @author Justin Foell
+ * @since 2.4
+ */
+ public static function register_shortcode_style_translations( $shortcode ) {
$shortcode = ! is_array( $shortcode ) ? array( $shortcode ) : $shortcode;
self::$shortcodes = array_unique( array_merge( self::$shortcodes, $shortcode ) );
- self::add_filter();
+ self::add_content_filter();
+ }
+
+ /**
+ * Register a block that has translatable CSS strings.
+ *
+ * @param string|array $block Block name (or array of block names).
+ * @author Justin Foell
+ * @since 2.4
+ */
+ public static function register_block_style_translations( $block ) {
+ $block = ! is_array( $block ) ? array( $block ) : $block;
+ self::$blocks = array_unique( array_merge( self::$blocks, $block ) );
+ self::add_content_filter();
}
/**
@@ -48,7 +84,15 @@ abstract class WPStrava_StyleTranslationRenderer {
self::$style_translations[ $class ] = $translation;
}
- public static function posts_results( $posts ) {
+ /**
+ * Go through posts from The Loop looking for our shortcodes and blocks.
+ *
+ * @param array $posts Posts from the current page loop.
+ * @return array Posts array, unharmed.
+ * @author Justin Foell
+ * @since 2.4
+ */
+ public static function search_content_for_shortcodes_and_blocks( $posts ) {
global $wp_query;
if ( ! $wp_query->is_main_query() || $wp_query->is_admin() ) {
@@ -64,76 +108,43 @@ abstract class WPStrava_StyleTranslationRenderer {
}
// This should only run once per request.
- remove_filter( 'posts_results', array( __CLASS__, 'posts_results' ) );
+ remove_filter( 'posts_results', array( __CLASS__, 'search_content_for_shortcodes_and_blocks' ) );
foreach ( $posts as $post ) {
if ( self::has_shortcodes( $post ) || self::has_blocks( $post ) ) {
- self::add_action();
+ self::add_print_style_action();
}
}
return $posts;
}
+ /**
+ * Current page has the shortcode specified.
+ *
+ * @param [type] $shortcode Shortcode.
+ * @return boolean True if shortcode was found in the_content.
+ * @author Justin Foell
+ * @since 2.4
+ */
public static function has_shortcode( $shortcode ) {
$shortcode = ! is_array( $shortcode ) ? array( $shortcode ) : $shortcode;
return ! empty( array_intersect( self::$has_shortcodes, $shortcode ) );
}
+ /**
+ * Current page has the block specified.
+ *
+ * @param [type] $block Block name.
+ * @return boolean True if block was found in the_content.
+ * @author Justin Foell
+ * @since 2.4
+ */
public static function has_block( $block ) {
$block = ! is_array( $block ) ? array( $block ) : $block;
return ! empty( array_intersect( self::$has_blocks, $block ) );
}
-
- private static function add_filter() {
- if ( ! has_filter( 'posts_results', array( __CLASS__, 'posts_results' ) ) ) {
- add_filter( 'posts_results', array( __CLASS__, 'posts_results' ) );
- }
- }
-
- private static function add_action() {
- if ( ! has_action( 'wp_head', array( __CLASS__, 'print_style_translations' ) ) ) {
- add_action( 'wp_head', array( __CLASS__, 'print_style_translations' ) );
- }
- }
-
- private static function has_shortcodes( $post ) {
- if ( empty( self::$shortcodes ) ) {
- return false;
- }
-
- $has_shortcode = false;
- foreach ( self::$shortcodes as $shortcode ) {
- if ( has_shortcode( $post->post_content, $shortcode ) ) {
- if ( ! in_array( $shortcode, self::$has_shortcodes, true ) ) {
- self::$has_shortcodes[] = $shortcode;
- }
- $has_shortcode = true;
- }
- }
-
- return $has_shortcode;
- }
-
- private static function has_blocks( $post ) {
- if ( empty( self::$blocks ) ) {
- return false;
- }
-
- $has_block = false;
- foreach ( self::$blocks as $block ) {
- if ( has_block( $block, $post ) ) {
- if ( ! in_array( $block, self::$has_blocks, true ) ) {
- self::$has_blocks[] = $block;
- }
- return true;
- }
- }
-
- return $has_block;
- }
-
/**
* Print translatable strings as ";
+ echo wp_kses( "", array( 'style' => array( 'id' => array() ) ) );
}
+
+ /**
+ * Add filter to post_results content.
+ *
+ * @author Justin Foell
+ * @since 2.4
+ */
+ private static function add_content_filter() {
+ if ( ! has_filter( 'posts_results', array( __CLASS__, 'search_content_for_shortcodes_and_blocks' ) ) ) {
+ add_filter( 'posts_results', array( __CLASS__, 'search_content_for_shortcodes_and_blocks' ) );
+ }
+ }
+
+ /**
+ * Undocumented function
+ *
+ * @author Justin Foell
+ * @since 2.4
+ */
+ private static function add_print_style_action() {
+ if ( ! has_action( 'wp_head', array( __CLASS__, 'print_style_translations' ) ) ) {
+ add_action( 'wp_head', array( __CLASS__, 'print_style_translations' ) );
+ }
+ }
+
+ /**
+ * Post contains one of the registered shortcodes.
+ *
+ * @param \WP_Post $post
+ * @return boolean
+ * @author Justin Foell
+ * @since 2.4
+ */
+ private static function has_shortcodes( $post ) {
+ if ( empty( self::$shortcodes ) ) {
+ return false;
+ }
+
+ $has_shortcode = false;
+ foreach ( self::$shortcodes as $shortcode ) {
+ if ( has_shortcode( $post->post_content, $shortcode ) ) {
+ if ( ! in_array( $shortcode, self::$has_shortcodes, true ) ) {
+ self::$has_shortcodes[] = $shortcode;
+ }
+ $has_shortcode = true;
+ }
+ }
+
+ return $has_shortcode;
+ }
+
+ /**
+ * Post contains one of the registered blocks.
+ *
+ * @param \WP_Post $post
+ * @return boolean
+ * @author Justin Foell
+ * @since 2.4
+ */
+ private static function has_blocks( $post ) {
+ if ( empty( self::$blocks ) ) {
+ return false;
+ }
+
+ $has_block = false;
+ foreach ( self::$blocks as $block ) {
+ if ( has_block( $block, $post ) ) {
+ if ( ! in_array( $block, self::$has_blocks, true ) ) {
+ self::$has_blocks[] = $block;
+ }
+ $has_block = true;
+ }
+ }
+
+ return $has_block;
+ }
+
}
From 580bc45ece9bc30dc5e4e27d871deb8281d808c0 Mon Sep 17 00:00:00 2001
From: Justin Foell <630830+jrfoell@users.noreply.github.com>
Date: Mon, 2 Nov 2020 16:44:47 -0600
Subject: [PATCH 04/13] Document function
---
src/WPStrava/StyleTranslationRenderer.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/WPStrava/StyleTranslationRenderer.php b/src/WPStrava/StyleTranslationRenderer.php
index 2a27d23..135939b 100644
--- a/src/WPStrava/StyleTranslationRenderer.php
+++ b/src/WPStrava/StyleTranslationRenderer.php
@@ -180,7 +180,7 @@ abstract class WPStrava_StyleTranslationRenderer {
}
/**
- * Undocumented function
+ * Hook into wp_head to print styles (only once).
*
* @author Justin Foell
* @since 2.4
From 05d93be713c6afcee585fe66801633e44069a320 Mon Sep 17 00:00:00 2001
From: Justin Foell <630830+jrfoell@users.noreply.github.com>
Date: Mon, 2 Nov 2020 16:49:43 -0600
Subject: [PATCH 05/13] Removed unused style translation
---
src/WPStrava.php | 6 ------
1 file changed, 6 deletions(-)
diff --git a/src/WPStrava.php b/src/WPStrava.php
index e3ceb17..68cc27e 100644
--- a/src/WPStrava.php
+++ b/src/WPStrava.php
@@ -41,12 +41,6 @@ class WPStrava {
*/
private $routes = null;
- /**
- * Style Translation object for responsive tables.
- * @var WPStrava_StyleTranslations
- */
- private $style_translations = null;
-
/**
* Private constructor (singleton).
*/
From 272705f9ef2f3a7e709164b22161b6e10a3c0e85 Mon Sep 17 00:00:00 2001
From: Justin Foell <630830+jrfoell@users.noreply.github.com>
Date: Tue, 3 Nov 2020 13:36:22 -0600
Subject: [PATCH 06/13] Move responsive column headings to data-label
---
css/wp-strava.css | 1 +
1 file changed, 1 insertion(+)
diff --git a/css/wp-strava.css b/css/wp-strava.css
index 53cfc3e..67bdb35 100755
--- a/css/wp-strava.css
+++ b/css/wp-strava.css
@@ -67,6 +67,7 @@ only screen and (max-width: 760px),
width: 45%;
padding-right: 10px;
white-space: nowrap;
+ content: attr(data-label);
}
.activity-details-table-info, .activity-details-table-units {
From e027a39bee35c3461c9e926267be8ab28b1bc767 Mon Sep 17 00:00:00 2001
From: Justin Foell <630830+jrfoell@users.noreply.github.com>
Date: Tue, 3 Nov 2020 13:37:12 -0600
Subject: [PATCH 07/13] Get rid of static calls
---
src/WPStrava/ActivityShortcode.php | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/src/WPStrava/ActivityShortcode.php b/src/WPStrava/ActivityShortcode.php
index 571d894..8350294 100644
--- a/src/WPStrava/ActivityShortcode.php
+++ b/src/WPStrava/ActivityShortcode.php
@@ -31,8 +31,6 @@ class WPStrava_ActivityShortcode {
add_shortcode( 'ride', array( $this, 'handler' ) ); // @deprecated 1.1
add_shortcode( 'activity', array( $this, 'handler' ) );
add_action( 'wp_footer', array( $this, 'print_scripts' ) );
- WPStrava_ActivityRenderer::register_shortcode_style_translations( array( 'ride', 'activity' ) );
- WPStrava_ActivityRenderer::load_style_translations();
}
/**
@@ -51,7 +49,7 @@ class WPStrava_ActivityShortcode {
return __( 'The athlete_token parameter is deprecated as of WP-Strava version 2 and should be replaced with client_id.', 'wp-strava' );
}
- $this->add_script = WPStrava_ActivityRenderer::has_shortcode( array( 'ride', 'activity' ) );
+ $this->add_script = true;
$renderer = new WPStrava_ActivityRenderer();
return $renderer->get_html( $atts );
From 07e02a19a927edc82ca3b6be05e75d36a184e22b Mon Sep 17 00:00:00 2001
From: Justin Foell <630830+jrfoell@users.noreply.github.com>
Date: Tue, 3 Nov 2020 13:37:49 -0600
Subject: [PATCH 08/13] Don't extend Style Renderer
---
src/WPStrava/ActivityRenderer.php | 31 +++++++++++--------------------
1 file changed, 11 insertions(+), 20 deletions(-)
diff --git a/src/WPStrava/ActivityRenderer.php b/src/WPStrava/ActivityRenderer.php
index 5322af6..3ee825c 100644
--- a/src/WPStrava/ActivityRenderer.php
+++ b/src/WPStrava/ActivityRenderer.php
@@ -2,7 +2,7 @@
/*
* ActivityRenderer has all the markup for the Activity Block & Shortcode.
*/
-class WPStrava_ActivityRenderer extends WPStrava_StyleTranslationRenderer {
+class WPStrava_ActivityRenderer {
/**
* Get the HTML for a single activity.
@@ -64,15 +64,6 @@ class WPStrava_ActivityRenderer extends WPStrava_StyleTranslationRenderer {
return $activity_output;
}
- public static function load_style_translations() {
- self::add_style_translation( 'wp-strava-td-avg-speed', __( 'Average Speed', 'wp-strava' ) );
- self::add_style_translation( 'wp-strava-td-max-speed', __( 'Max Speed', 'wp-strava' ) );
- self::add_style_translation( 'wp-strava-td-elevation', __( 'Elevation Gain', 'wp-strava' ) );
- self::add_style_translation( 'wp-strava-td-elapsed-time', __( 'Elapsed Time', 'wp-strava' ) );
- self::add_style_translation( 'wp-strava-td-moving-time', __( 'Moving Time', 'wp-strava' ) );
- self::add_style_translation( 'wp-strava-td-distance', __( 'Distance', 'wp-strava' ) );
- }
-
/**
* The the activity details in in HTML table.
*
@@ -89,7 +80,7 @@ class WPStrava_ActivityRenderer extends WPStrava_StyleTranslationRenderer {
$avg_title = '' . __( 'Average Speed', 'wp-strava' ) . ' | ';
$max_title = '' . __( 'Max Speed', 'wp-strava' ) . ' | ';
$elevation_title = '' . __( 'Elevation Gain', 'wp-strava' ) . ' | ';
- $elevation = '
+ $elevation = ' |
' . $strava_som->elevation( $activity_details->total_elevation_gain ) . '
' . $strava_som->get_elevation_label() . '
| ';
@@ -98,30 +89,30 @@ class WPStrava_ActivityRenderer extends WPStrava_StyleTranslationRenderer {
switch ( $strava_activitytype ) {
case WPStrava_ActivityType::TYPE_GROUP_PACE:
- $avg_speed = '
+ $avg_speed = ' |
' . $strava_som->pace( $activity_details->average_speed ) . '
' . $strava_som->get_pace_label() . '
| ';
- $max_speed = '
+ $max_speed = ' |
' . $strava_som->pace( $activity_details->max_speed ) . '
| ';
break;
case WPStrava_ActivityType::TYPE_GROUP_SPEED:
- $avg_speed = '
+ $avg_speed = ' |
' . $strava_som->speed( $activity_details->average_speed ) . '
' . $strava_som->get_speed_label() . '
| ';
- $max_speed = '
+ $max_speed = ' |
' . $strava_som->speed( $activity_details->max_speed ) . '
' . $strava_som->get_speed_label() . '
| ';
break;
case WPStrava_ActivityType::TYPE_GROUP_PACE:
- $avg_speed = '
+ $avg_speed = ' |
' . $strava_som->swimpace( $activity_details->average_speed ) . '
' . $strava_som->get_swimpace_label() . '
| ';
- $max_speed = '
+ $max_speed = ' |
' . $strava_som->swimpace( $activity_details->max_speed ) . '
' . $strava_som->get_swimpace_label() . '
| ';
@@ -151,15 +142,15 @@ class WPStrava_ActivityRenderer extends WPStrava_StyleTranslationRenderer {
- |
+ |
' . $strava_som->time( $activity_details->elapsed_time ) . '
' . $strava_som->get_time_label() . '
|
-
+ |
' . $strava_som->time( $activity_details->moving_time ) . '
' . $strava_som->get_time_label() . '
|
-
+ |
' . $strava_som->distance( $activity_details->distance ) . '
' . $strava_som->get_distance_label() . '
|
From 4a5f1c5c0e39d980729c02380269a454a92649ff Mon Sep 17 00:00:00 2001
From: Justin Foell <630830+jrfoell@users.noreply.github.com>
Date: Tue, 3 Nov 2020 13:38:21 -0600
Subject: [PATCH 09/13] Remove static calls from block
---
src/WPStrava/Blocks/Activity.php | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/src/WPStrava/Blocks/Activity.php b/src/WPStrava/Blocks/Activity.php
index f579e41..ceff6b0 100644
--- a/src/WPStrava/Blocks/Activity.php
+++ b/src/WPStrava/Blocks/Activity.php
@@ -5,11 +5,6 @@
class WPStrava_Blocks_Activity implements WPStrava_Blocks_Interface {
- public function __construct() {
- WPStrava_ActivityRenderer::register_block_style_translations( 'wp-strava/activity' );
- WPStrava_ActivityRenderer::load_style_translations();
- }
-
/**
* Register the wp-strava/activity block.
*
@@ -43,7 +38,7 @@ class WPStrava_Blocks_Activity implements WPStrava_Blocks_Interface {
}
$matches = [];
- preg_match( "/\/activities\/([0-9].*)$/", $attributes['url'], $matches );
+ preg_match( '/\/activities\/([0-9].*)$/', $attributes['url'], $matches );
if ( $matches[1] ) {
// Transform from block attributes to shortcode standard.
$attributes = array(
From 94c74d70ff726ea7b8581c7bab07ddd0a1d66933 Mon Sep 17 00:00:00 2001
From: Justin Foell <630830+jrfoell@users.noreply.github.com>
Date: Tue, 3 Nov 2020 13:38:39 -0600
Subject: [PATCH 10/13] Remove style renderer (use data-label instead)
---
src/WPStrava/StyleTranslationRenderer.php | 246 ----------------------
1 file changed, 246 deletions(-)
delete mode 100644 src/WPStrava/StyleTranslationRenderer.php
diff --git a/src/WPStrava/StyleTranslationRenderer.php b/src/WPStrava/StyleTranslationRenderer.php
deleted file mode 100644
index 135939b..0000000
--- a/src/WPStrava/StyleTranslationRenderer.php
+++ /dev/null
@@ -1,246 +0,0 @@
-
- * @since 2.4
- */
-abstract class WPStrava_StyleTranslationRenderer {
-
- /**
- * Translations indexed by class.
- * @var array
- */
- private static $style_translations = array();
-
- /**
- * Shortcodes registered with translatable style strings.
- * @var array
- */
- private static $shortcodes = array();
-
- /**
- * Blocks registered with translatable style strings.
- * @var array
- */
- private static $blocks = array();
-
- /**
- * Shortcodes found in content of current page.
- * @var array
- */
- private static $has_shortcodes = array();
-
- /**
- * Blocks found in content of current page.
- * @var array
- */
- private static $has_blocks = array();
-
- /**
- * Implemented by concrete renderers to load column headers by calling self::add_style_translation().
- *
- * @author Justin Foell
- * @since 2.4
- */
- abstract public static function load_style_translations();
-
- /**
- * Register a shortcode that has translatable CSS strings.
- *
- * @param string|array $shortcode Shortcode (or array of shortcodes).
- * @author Justin Foell
- * @since 2.4
- */
- public static function register_shortcode_style_translations( $shortcode ) {
- $shortcode = ! is_array( $shortcode ) ? array( $shortcode ) : $shortcode;
- self::$shortcodes = array_unique( array_merge( self::$shortcodes, $shortcode ) );
- self::add_content_filter();
- }
-
- /**
- * Register a block that has translatable CSS strings.
- *
- * @param string|array $block Block name (or array of block names).
- * @author Justin Foell
- * @since 2.4
- */
- public static function register_block_style_translations( $block ) {
- $block = ! is_array( $block ) ? array( $block ) : $block;
- self::$blocks = array_unique( array_merge( self::$blocks, $block ) );
- self::add_content_filter();
- }
-
- /**
- * Add translation text to column header, identified by class.
- *
- * @param [type] $class CSS class for table data ().
- * @param [type] $translation Text to add to column.
- * @author Justin Foell
- * @since 2.4
- */
- public static function add_style_translation( $class, $translation ) {
- self::$style_translations[ $class ] = $translation;
- }
-
- /**
- * Go through posts from The Loop looking for our shortcodes and blocks.
- *
- * @param array $posts Posts from the current page loop.
- * @return array Posts array, unharmed.
- * @author Justin Foell
- * @since 2.4
- */
- public static function search_content_for_shortcodes_and_blocks( $posts ) {
- global $wp_query;
-
- if ( ! $wp_query->is_main_query() || $wp_query->is_admin() ) {
- return $posts;
- }
-
- if ( empty( $posts ) ) {
- return $posts;
- }
-
- if ( empty( self::$shortcodes ) && empty( self::$blocks ) ) {
- return $posts;
- }
-
- // This should only run once per request.
- remove_filter( 'posts_results', array( __CLASS__, 'search_content_for_shortcodes_and_blocks' ) );
-
- foreach ( $posts as $post ) {
- if ( self::has_shortcodes( $post ) || self::has_blocks( $post ) ) {
- self::add_print_style_action();
- }
- }
-
- return $posts;
- }
-
- /**
- * Current page has the shortcode specified.
- *
- * @param [type] $shortcode Shortcode.
- * @return boolean True if shortcode was found in the_content.
- * @author Justin Foell
- * @since 2.4
- */
- public static function has_shortcode( $shortcode ) {
- $shortcode = ! is_array( $shortcode ) ? array( $shortcode ) : $shortcode;
- return ! empty( array_intersect( self::$has_shortcodes, $shortcode ) );
- }
-
- /**
- * Current page has the block specified.
- *
- * @param [type] $block Block name.
- * @return boolean True if block was found in the_content.
- * @author Justin Foell
- * @since 2.4
- */
- public static function has_block( $block ) {
- $block = ! is_array( $block ) ? array( $block ) : $block;
- return ! empty( array_intersect( self::$has_blocks, $block ) );
- }
-
- /**
- * Print translatable strings as ", array( 'style' => array( 'id' => array() ) ) );
- }
-
- /**
- * Add filter to post_results content.
- *
- * @author Justin Foell
- * @since 2.4
- */
- private static function add_content_filter() {
- if ( ! has_filter( 'posts_results', array( __CLASS__, 'search_content_for_shortcodes_and_blocks' ) ) ) {
- add_filter( 'posts_results', array( __CLASS__, 'search_content_for_shortcodes_and_blocks' ) );
- }
- }
-
- /**
- * Hook into wp_head to print styles (only once).
- *
- * @author Justin Foell
- * @since 2.4
- */
- private static function add_print_style_action() {
- if ( ! has_action( 'wp_head', array( __CLASS__, 'print_style_translations' ) ) ) {
- add_action( 'wp_head', array( __CLASS__, 'print_style_translations' ) );
- }
- }
-
- /**
- * Post contains one of the registered shortcodes.
- *
- * @param \WP_Post $post
- * @return boolean
- * @author Justin Foell
- * @since 2.4
- */
- private static function has_shortcodes( $post ) {
- if ( empty( self::$shortcodes ) ) {
- return false;
- }
-
- $has_shortcode = false;
- foreach ( self::$shortcodes as $shortcode ) {
- if ( has_shortcode( $post->post_content, $shortcode ) ) {
- if ( ! in_array( $shortcode, self::$has_shortcodes, true ) ) {
- self::$has_shortcodes[] = $shortcode;
- }
- $has_shortcode = true;
- }
- }
-
- return $has_shortcode;
- }
-
- /**
- * Post contains one of the registered blocks.
- *
- * @param \WP_Post $post
- * @return boolean
- * @author Justin Foell
- * @since 2.4
- */
- private static function has_blocks( $post ) {
- if ( empty( self::$blocks ) ) {
- return false;
- }
-
- $has_block = false;
- foreach ( self::$blocks as $block ) {
- if ( has_block( $block, $post ) ) {
- if ( ! in_array( $block, self::$has_blocks, true ) ) {
- self::$has_blocks[] = $block;
- }
- $has_block = true;
- }
- }
-
- return $has_block;
- }
-
-}
From 5b85c24405ffa7cbb70f5f487985889526558b90 Mon Sep 17 00:00:00 2001
From: Justin Foell <630830+jrfoell@users.noreply.github.com>
Date: Tue, 3 Nov 2020 13:41:11 -0600
Subject: [PATCH 11/13] Add default label, make sure settings is an array
---
src/WPStrava/Settings.php | 26 ++++++++++++++++++--------
1 file changed, 18 insertions(+), 8 deletions(-)
diff --git a/src/WPStrava/Settings.php b/src/WPStrava/Settings.php
index 4b5483f..54a6db0 100644
--- a/src/WPStrava/Settings.php
+++ b/src/WPStrava/Settings.php
@@ -236,10 +236,19 @@ class WPStrava_Settings {
* @since 2.0.0
*/
public function print_id_input() {
+ $first = true;
foreach ( $this->get_all_ids() as $id => $nickname ) {
?>
+
+
+
+
+
+
-
+
+
* @since 2.0.0
*/
@@ -644,7 +653,8 @@ class WPStrava_Settings {
* @since 2.0.0
*/
public function save_info( $id, $secret, $info ) {
- $infos = get_option( 'strava_info', array() );
+ $infos = get_option( 'strava_info' );
+ $infos = empty( $infos ) ? array() : $infos;
$infos = array_filter( $infos, array( $this, 'filter_by_id' ), ARRAY_FILTER_USE_KEY ); // Remove old IDs.
$info->client_secret = $secret;
@@ -661,7 +671,7 @@ class WPStrava_Settings {
* @since 2.0.0
*/
public function filter_by_id( $key ) {
- if ( in_array( $key, $this->ids ) ) {
+ if ( in_array( $key, $this->ids ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict -- Loose comparison OK.
return true;
}
return false;
From 65fa39e0d37a3567c6afe75eea5d1a84bb2d4a6d Mon Sep 17 00:00:00 2001
From: Justin Foell <630830+jrfoell@users.noreply.github.com>
Date: Tue, 3 Nov 2020 13:41:38 -0600
Subject: [PATCH 12/13] Coding standards
---
src/WPStrava/AuthRefresh.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/WPStrava/AuthRefresh.php b/src/WPStrava/AuthRefresh.php
index 3079eb3..1bdd6e3 100644
--- a/src/WPStrava/AuthRefresh.php
+++ b/src/WPStrava/AuthRefresh.php
@@ -107,7 +107,7 @@ class WPStrava_AuthRefresh extends WPStrava_Auth {
// Translators: Token refresh success message.
$this->feedback .= __( 'ID %s successfully re-authenticated.', 'wp-strava' );
- if ( $strava_info->access_token != $info->access_token ) {
+ if ( $strava_info->access_token !== $info->access_token ) {
// Translators: New token created message.
$this->feedback .= __( 'ID %s access extended.', 'wp-strava' );
From 73bf4e1c7ab5474449a858e5e04d05925bf2125a Mon Sep 17 00:00:00 2001
From: Justin Foell <630830+jrfoell@users.noreply.github.com>
Date: Tue, 3 Nov 2020 13:49:10 -0600
Subject: [PATCH 13/13] Updated readme
---
readme.txt | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/readme.txt b/readme.txt
index 0bd2efe..abb9bdf 100755
--- a/readme.txt
+++ b/readme.txt
@@ -3,7 +3,7 @@
Contributors: cmanon, jrfoell, lancewillett, dlintott, sebastianerb
Tags: strava, activity, bicycle, cycling, biking, running, run, swimming, swim, paddle, kayak, gps, shortcode, widget, plugin
Requires at least: 4.6
-Tested up to: 5.4
+Tested up to: 5.5
Stable tag: 2.3.2
Requires PHP: 5.3
License: GPLv2 or later
@@ -116,6 +116,10 @@ On the WP-Strava settings page you cannot currently remove and add another athle
== Changelog ==
+= 2.4.0 =
+Made activity table responsive https://wordpress.org/support/topic/responsive-strava-activity-table/
+Improve output escaping, documentation, and other coding standards
+
= 2.3.2 =
Added support to not link to activities https://wordpress.org/support/topic/feature-request-make-link-to-activity-optional
| | |