From eddba0e2c39a3cdddcdf7d1fcf0b50e97a794aab Mon Sep 17 00:00:00 2001 From: Justin Foell <630830+jrfoell@users.noreply.github.com> Date: Fri, 26 Mar 2021 14:05:48 -0500 Subject: [PATCH 1/3] Added package --- .../{ActivitiesList.php => ActivitiesListRenderer.php} | 0 src/WPStrava/RouteRenderer.php | 7 ++++++- 2 files changed, 6 insertions(+), 1 deletion(-) rename src/WPStrava/{ActivitiesList.php => ActivitiesListRenderer.php} (100%) diff --git a/src/WPStrava/ActivitiesList.php b/src/WPStrava/ActivitiesListRenderer.php similarity index 100% rename from src/WPStrava/ActivitiesList.php rename to src/WPStrava/ActivitiesListRenderer.php diff --git a/src/WPStrava/RouteRenderer.php b/src/WPStrava/RouteRenderer.php index 0d13a3a..524e8ff 100644 --- a/src/WPStrava/RouteRenderer.php +++ b/src/WPStrava/RouteRenderer.php @@ -1,5 +1,10 @@ Date: Fri, 26 Mar 2021 14:14:57 -0500 Subject: [PATCH 2/3] Added ActivitiesList block --- src/WPStrava.php | 1 + src/WPStrava/ActivitiesListRenderer.php | 29 ++++++---- src/WPStrava/ActivitiesListShortcode.php | 4 +- src/WPStrava/ActivitiesListWidget.php | 5 +- src/WPStrava/Blocks/ActivitiesList.php | 74 ++++++++++++++++++++++++ src/blocks/activitieslist/block.json | 18 ++++++ src/blocks/activitieslist/edit.js | 52 +++++++++++++++++ src/blocks/activitieslist/index.js | 9 +++ src/index.js | 1 + 9 files changed, 181 insertions(+), 12 deletions(-) create mode 100644 src/WPStrava/Blocks/ActivitiesList.php create mode 100644 src/blocks/activitieslist/block.json create mode 100644 src/blocks/activitieslist/edit.js create mode 100644 src/blocks/activitieslist/index.js diff --git a/src/WPStrava.php b/src/WPStrava.php index dddde35..2b7c25a 100644 --- a/src/WPStrava.php +++ b/src/WPStrava.php @@ -202,6 +202,7 @@ public function register_blocks() { static $blocks = array( 'WPStrava_Blocks_Activity', 'WPStrava_Blocks_Route', + 'WPStrava_Blocks_ActivitiesList', ); // automatically load dependencies and version diff --git a/src/WPStrava/ActivitiesListRenderer.php b/src/WPStrava/ActivitiesListRenderer.php index 0cdd42c..a67f1e1 100644 --- a/src/WPStrava/ActivitiesListRenderer.php +++ b/src/WPStrava/ActivitiesListRenderer.php @@ -1,6 +1,6 @@ * @since 2.3.0 */ -class WPStrava_ActivitiesList { - public static function get_activities_html( $args ) { - if ( isset( $args['athlete_token'] ) ) { +class WPStrava_ActivitiesListRenderer { + + /** + * Get the HTML for an Activities List. + * + * @param array $atts + * @return string HTML for an route. + * @author Justin Foell + * @since 2.8.0 + */ + public function get_html( $atts ) { + if ( isset( $atts['athlete_token'] ) ) { // Translators: Message shown when using deprecated athlete_token parameter. return __( 'The athlete_token parameter is deprecated as of WP-Strava version 2 and should be replaced with client_id.', 'wp-strava' ); } @@ -26,14 +35,14 @@ public static function get_activities_html( $args ) { 'date_end' => '', ); - $args = wp_parse_args( $args, $defaults ); + $atts = wp_parse_args( $atts, $defaults ); - $som = WPStrava_SOM::get_som( $args['som'] ); + $som = WPStrava_SOM::get_som( $atts['som'] ); $strava_activity = WPStrava::get_instance()->activity; $activities = array(); try { - $activities = $strava_activity->get_activities( $args ); + $activities = $strava_activity->get_activities( $atts ); } catch ( WPStrava_Exception $e ) { return $e->to_html(); } @@ -51,11 +60,11 @@ public static function get_activities_html( $args ) { // Translators: Shows something like "On <[went 10 miles] [during 2 hours] [climbing 100 feet]>." __( 'On %1$s %2$s', 'wp-strava' ), date_i18n( get_option( 'date_format' ), $unixtime ), - self::get_activity_time( $unixtime ) + $this->get_activity_time( $unixtime ) ); } - if ( is_numeric( $args['strava_club_id'] ) ) { + if ( is_numeric( $atts['strava_club_id'] ) ) { $name = $activity->athlete->firstname . ' ' . $activity->athlete->lastname; $response .= empty( $activity->athlete->id ) ? " {$name}" : @@ -86,7 +95,7 @@ public static function get_activities_html( $args ) { * @author Justin Foell * @since 1.7.1 */ - public static function get_activity_time( $unixtime ) { + private function get_activity_time( $unixtime ) { if ( WPStrava::get_instance()->settings->hide_time ) { return ''; } diff --git a/src/WPStrava/ActivitiesListShortcode.php b/src/WPStrava/ActivitiesListShortcode.php index 8749366..c1a6858 100644 --- a/src/WPStrava/ActivitiesListShortcode.php +++ b/src/WPStrava/ActivitiesListShortcode.php @@ -44,7 +44,9 @@ public function __construct() { */ public function handler( $atts ) { $this->add_script = true; - return WPStrava_ActivitiesList::get_activities_html( $atts ); + + $renderer = new WPStrava_ActivitiesListRenderer(); + return $renderer->get_html( $atts ); } /** diff --git a/src/WPStrava/ActivitiesListWidget.php b/src/WPStrava/ActivitiesListWidget.php index fea2fa9..c04db25 100644 --- a/src/WPStrava/ActivitiesListWidget.php +++ b/src/WPStrava/ActivitiesListWidget.php @@ -42,7 +42,10 @@ public function widget( $args, $instance ) { if ( $title ) { echo $args['before_title'] . $title . $args['after_title']; } - echo WPStrava_ActivitiesList::get_activities_html( $activities_args ); + + $renderer = new WPStrava_ActivitiesListRenderer(); + echo $renderer->get_html( $activities_args ); + echo $args['after_widget']; // phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped } diff --git a/src/WPStrava/Blocks/ActivitiesList.php b/src/WPStrava/Blocks/ActivitiesList.php new file mode 100644 index 0000000..856c9bc --- /dev/null +++ b/src/WPStrava/Blocks/ActivitiesList.php @@ -0,0 +1,74 @@ + + * @since 2.5.0 + */ + private $add_script = false; + + /** + * Register the wp-strava/activitieslist block. + * + * @author Justin Foell + * @since 2.2.0 + */ + public function register_block() { + register_block_type( + 'wp-strava/activitieslist', + array( + 'style' => 'wp-strava-block', + 'editor_style' => 'wp-strava-block-editor', + 'editor_script' => 'wp-strava-block', + 'render_callback' => array( $this, 'render_block' ), + 'attributes' => array( + 'som' => array( + 'type' => 'string', + 'default' => null, + ), + ), + ) + ); + add_action( 'wp_footer', array( $this, 'print_scripts' ) ); + } + + /** + * Render for this block. + * + * @param array $attributes JSON attributes saved in the HTML comment for this block. + * @param string $content The content from JS save() for this block. + * @return string HTML for this block. + * @author Justin Foell + * @since 2.2.0 + */ + public function render_block( $attributes, $content ) { + $this->add_script = true; + + // Transform from block attributes to shortcode standard. + $attributes = array( + 'som' => ! empty( $attributes['som'] ) ? $attributes['som'] : null, + ); + + $renderer = new WPStrava_ActivitiesListRenderer(); + return $renderer->get_html( $attributes ); + } + + /** + * Enqueue style if block is being used. + * + * @author Justin Foell + * @since 2.5.0 + */ + public function print_scripts() { + if ( $this->add_script ) { + wp_enqueue_style( 'wp-strava-style' ); + } + } +} diff --git a/src/blocks/activitieslist/block.json b/src/blocks/activitieslist/block.json new file mode 100644 index 0000000..c99cbd8 --- /dev/null +++ b/src/blocks/activitieslist/block.json @@ -0,0 +1,18 @@ +{ + "name": "wp-strava/activitieslist", + "title": "Strava Activities List", + "category": "embed", + "icon": "editor-ul", + "description": "List of Strava Activities", + "keywords": [ "activity", "ride" ], + "textdomain": "wp-strava", + "attributes": { + "som": { + "type": "string", + "default": null + } + }, + "editorScript": "file:../../../build/index.js", + "editorStyle": "file:../../../build/editor.css", + "style": "file:../../../build/style.css" +} diff --git a/src/blocks/activitieslist/edit.js b/src/blocks/activitieslist/edit.js new file mode 100644 index 0000000..ea5dcc2 --- /dev/null +++ b/src/blocks/activitieslist/edit.js @@ -0,0 +1,52 @@ +/* global wp, wpStrava */ +import SOMOverride from '../components/som-override'; + +const { __ } = wp.i18n; +const { Component } = wp.element; +const { InspectorControls } = wp.editor; +const { PanelBody, ToggleControl, ServerSideRender } = wp.components; + +class Edit extends Component { + + constructor() { + super( ...arguments ); + this.overrideSOM = this.overrideSOM.bind( this ); + + this.state = { + som: this.props.attributes.som, + }; + } + + overrideSOM( newSOM ) { + this.setState( { som: newSOM } ); + this.props.setAttributes( { som: newSOM } ); + } + + render() { + const { + som + } = this.state; + + return ( + <> + + + + + + + + ); + } +} + +export default Edit; diff --git a/src/blocks/activitieslist/index.js b/src/blocks/activitieslist/index.js new file mode 100644 index 0000000..70a50a1 --- /dev/null +++ b/src/blocks/activitieslist/index.js @@ -0,0 +1,9 @@ +/* global wp, wpStrava */ +import { registerBlockType } from '@wordpress/blocks'; +import edit from './edit'; +import metadata from './block.json'; + +metadata.edit = edit; +metadata.save = () => null; + +registerBlockType( metadata.name, metadata ); diff --git a/src/index.js b/src/index.js index ab46a48..056e447 100644 --- a/src/index.js +++ b/src/index.js @@ -1,2 +1,3 @@ import './blocks/activity'; import './blocks/route'; +import './blocks/activitieslist'; From 1a8249bf1980208d6adfd55ac9cfe5a574813fb6 Mon Sep 17 00:00:00 2001 From: Justin Foell <630830+jrfoell@users.noreply.github.com> Date: Fri, 26 Mar 2021 14:28:17 -0500 Subject: [PATCH 3/3] Bumped version --- readme.txt | 7 +++++-- wp-strava.php | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/readme.txt b/readme.txt index 837082e..ea2e355 100755 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Contributors: cmanon, jrfoell, lancewillett, dlintott, sebastianerb Tags: strava, activity, bicycle, cycling, biking, running, run, swimming, swim, paddle, kayak, gps, shortcode, widget, plugin, block, blocks Requires at least: 4.6 Tested up to: 5.7 -Stable tag: 2.7.0 +Stable tag: 2.8.0 Requires PHP: 5.3 License: GPLv2 or later @@ -32,6 +32,8 @@ Strava Route - embed a route in any page or post. Shows a summary of the route p Paste in the full route URL from Strava, such as https://www.strava.com/routes/2326567 and click "Embed." A preview map will be shown in the editor, similar to what will be displayed on the front-end. In the side-panel you can selection options to show the image only (without the details table), display markers at the start & finish points, and override the system of measure from your default selection under Settings -> Strava. +Strava Activities List - Shows your most recent activities in a bulleted list. + = Shortcodes = [activity id=NUMBER] - add to any page or post. Shows a summary of the activity plus a map if a google maps key has been added. @@ -119,9 +121,10 @@ On the WP-Strava settings page you cannot currently remove and add another athle == Changelog == -= Unreleased = += 2.8.0 = Revised `block.json` based on feedback from https://wordpress.org/plugins/developers/block-plugin-validator/ Add PHPCompatibility checks to coding standards (and fixes from recommendations) +Add Activities List Block = 2.7.0 = diff --git a/wp-strava.php b/wp-strava.php index 75f51bc..3ab2362 100755 --- a/wp-strava.php +++ b/wp-strava.php @@ -3,7 +3,7 @@ * Plugin Name: WP Strava * Plugin URI: https://wordpress.org/plugins/wp-strava/ * Description: Show your strava.com activity on your WordPress site. Some Icons are Copyright © Yusuke Kamiyamane. All rights reserved. Licensed under a Creative Commons Attribution 3.0 license. - * Version: 2.7.0 + * Version: 2.8.0 * Author: Carlos Santa Cruz, Justin Foell, Lance Willett, Daniel Lintott, Sebastian Erb * License: GPL2 * Text Domain: wp-strava @@ -27,7 +27,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -define( 'WPSTRAVA_PLUGIN_VERSION', '2.7.0' ); +define( 'WPSTRAVA_PLUGIN_VERSION', '2.8.0' ); define( 'WPSTRAVA_PLUGIN_FILE', __FILE__ ); define( 'WPSTRAVA_PLUGIN_DIR', trailingslashit( dirname( __FILE__ ) ) ); define( 'WPSTRAVA_PLUGIN_URL', plugins_url( '/', __FILE__ ) );