diff --git a/README.md b/README.md index b140fb3..be20b7a 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,8 @@ A collection of tools for publishing from and to NPR's Story API. [Find this plu - Original developers: NPRDS, INN Labs - Requires at least: 3.8.14 - Tested up to: 6.4.1 -- Stable tag: 1.9.6 +- Version: 1.9.7 +- Stable tag: 1.9.7 - License: GPLv2 - License URI: https://www.gnu.org/licenses/gpl-2.0.html @@ -70,6 +71,15 @@ NPR Stories having got gotten ## Changelog +### V1.9.7 +* Updated ID pattern matching on get_stories.php to accommodate NPR's new alphanumeric IDs + +### V1.9.6.2 +* Fixed a potentially fatal error when trying to pull a Story API ID from a blank URL + +### V1.9.6.1 +* Added messaging about the eventual retirement of the Story API with links to the newly launched CDS plugin + ### V1.9.6 * Articles imported from the API will now show the original article URL as the canonical URL in the header diff --git a/composer.json b/composer.json index 06455a8..82cc731 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "license" : "GPL-2.0+", "require": {}, "dist": { - "url": "https://github.com/OpenPublicMedia/nprapi-wordpress/archive/refs/tags/v1.9.6.zip", + "url": "https://github.com/OpenPublicMedia/nprapi-wordpress/archive/refs/tags/v1.9.7.zip", "type": "zip" }, "authors": [ diff --git a/ds-npr-api.php b/ds-npr-api.php index e9b2bb0..3791028 100644 --- a/ds-npr-api.php +++ b/ds-npr-api.php @@ -2,7 +2,7 @@ /** * Plugin Name: NPR Story API * Description: A collection of tools for reusing content from NPR.org, now maintained and updated by NPR member station developers - * Version: 1.9.6 + * Version: 1.9.7 * Author: Open Public Media * License: GPLv2 */ @@ -264,7 +264,7 @@ function nprstory_add_header_meta() { } add_action( 'wp_head', 'nprstory_add_header_meta', 9 ); -// add_action('admin_notices', 'nprstory_cds_plugin_admin_notice'); +add_action('admin_notices', 'nprstory_cds_plugin_admin_notice'); function nprstory_cds_plugin_admin_notice() { global $pagenow; @@ -282,10 +282,10 @@ function nprstory_cds_plugin_admin_notice() { } } if ( $display ) { ?> -
+

-

-

+

NPR Content Distribution Service (CDS). The same great content, but with greater flexibility, a more modern architecture, and richer media support.', 'ds_npr_api' ); ?>

+

new NPR CDS Plugin. Be sure to file a ticket in NPR Studio to get your authorization token and station information.', 'ds_npr_api' ); ?>

= 8 ) { - $story_id = $story_id; - } - } elseif ( strpos( $story_id, 'npr.org' ) !== false ) { + if ( is_numeric( $story_id ) && strlen( $story_id ) >= 8 ) { + $valid = true; + } elseif ( preg_match( '/^[a-z0-9\-]+$/', $story_id ) ) { + $valid = true; + } elseif ( wp_http_validate_url( $story_id ) ) { $story_id = sanitize_url( $story_id ); // url format: /yyyy/mm/dd/id // url format: /blogs/name/yyyy/mm/dd/id - $story_id = preg_replace( '/https?\:\/\/[^\s\/]*npr\.org\/((([^\/]*\/){3,5})([0-9]{8,12}))\/.*/', '$4', $story_id ); - if ( !is_numeric( $story_id ) ) { - // url format: /templates/story/story.php?storyId=id - $story_id = preg_replace( '/https?\:\/\/[^\s\/]*npr\.org\/([^&\s\<]*storyId\=([0-9]+)).*/', '$2', $story_id ); - } - } else { - $story_id = sanitize_url( $story_id ); - $meta = get_meta_tags( $story_id ); - if ( !empty( $meta['brightspot-datalayer'] ) ) { - $json = json_decode( html_entity_decode( $meta['brightspot-datalayer'] ), TRUE ); - if ( !empty( $json['nprStoryId'] ) ) { - $story_id = $json['nprStoryId']; + if ( str_contains( $story_id, 'npr.org' ) ) { + preg_match( '/https?:\/\/[^\s\/]*npr\.org\/((([^\/]*\/){3,5})([a-z\-0-9]+))\/.*/', $story_id, $matches ); + if ( !empty( $matches[4] ) ) { + $story_id = $matches[4]; + $valid = true; + } else { + preg_match( '/https?\:\/\/[^\s\/]*npr\.org\/([^&\s\<]*storyId\=([0-9]+)).*/', $story_id, $matches ); + if ( !empty( $matches[2] ) ) { + $story_id = $matches[2]; + $valid = true; + } } - } elseif ( !empty( $meta['story_id'] ) ) { - $story_id = $meta['story_id']; } else { - nprstory_show_message( "The referenced URL (" . $story_id . ") does not contain a valid NPR Story API ID. Please try again.", TRUE ); - error_log( "The referenced URL (" . $story_id . ") does not contain a valid NPR Story API ID. Please try again." ); // debug use + $meta = get_meta_tags( $story_id ); + if ( ! empty( $meta['brightspot-datalayer'] ) ) { + $json = json_decode( html_entity_decode( $meta['brightspot-datalayer'] ), true ); + if ( ! empty( $json['nprStoryId'] ) ) { + $story_id = $json['nprStoryId']; + $valid = true; + } + } elseif ( ! empty( $meta['story_id'] ) ) { + $story_id = $meta['story_id']; + $valid = true; + } else { + nprstory_show_message( "The referenced URL (" . $story_id . ") does not contain a valid NPR CDS ID. Please try again.", true ); + error_log( "The referenced URL (" . $story_id . ") does not contain a valid NPR CDS ID. Please try again." ); // debug use + } } } } // Don't do anything if $story_id isn't an ID - if ( isset( $story_id ) && is_numeric( $story_id ) ) { + if ( !empty( $story_id ) && $valid ) { // start the API class // todo: check that the API key is actually set $api = new NPRAPIWordpress(); @@ -175,7 +185,6 @@ public function load_page_hook() { $xml = simplexml_load_string( $api->xml ); nprstory_show_message( 'Error retrieving story for id = ' . $story_id . '
API error =' . $api->message->id . '
API Message =' . $xml->message->text, TRUE ); error_log( 'Not going to save the return from query for story_id=' . $story_id .', we got an error=' . $api->message->id . ' from the NPR Story API' ); // debug use - return; } } } diff --git a/readme.txt b/readme.txt index cbadb61..90949b9 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,8 @@ Donate link: https://www.npr.org/series/750002/support-public-radio Tags: npr, news, public radio, api Requires at least: 3.8.14 Tested up to: 6.0 -Stable tag: 1.9.6 +Version: 1.9.7 +Stable tag: 1.9.7 License: GPLv2 License URI: http://www.gnu.org/licenses/gpl-2.0.html Text Domain: nprapi @@ -70,6 +71,15 @@ NPR Stories having got gotten == Changelog == += V1.9.7 = +* Updated ID pattern matching on get_stories.php to accommodate NPR's new alphanumeric IDs + += V1.9.6.2 = +* Fixed a potentially fatal error when trying to pull a Story API ID from a blank URL + += V1.9.6.1 = +* Added messaging about the eventual retirement of the Story API with links to the newly launched CDS plugin + = V1.9.6 = * Articles imported from the API will now show the original article URL as the canonical URL in the header