Skip to content

Commit

Permalink
v1.9.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
tamw-wnet committed Jan 2, 2024
1 parent 0228c9f commit f9d74c0
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 23 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# NPR Story API

A collection of tools for publishing from and to NPR's Story API. [Find this plugin on the Wordpress.org Plugin Repository](https://wordpress.org/plugins/npr-story-api/).
A collection of tools for publishing from and to NPR's Story API. [Find this plugin on the WordPress.org Plugin Repository](https://wordpress.org/plugins/npr-story-api/).

- Contributors: jwcounts, tamw-wnet, bdivver
- Original developers: NPRDS, INN Labs
- Requires at least: 3.8.14
- Tested up to: 6.0
- Stable tag: 1.9.4.1
- Tested up to: 6.4.1
- Stable tag: 1.9.5.2
- License: GPLv2
- License URI: https://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -70,6 +70,14 @@ NPR Stories having got gotten
## Changelog

<!-- copy from readme.txt to here -->
### V1.9.5.1
* Adding `'no_found_posts' => false` to the query in `update_posts_from_stories()` for greater MySQL 8 compatability. Will also help on sites with large archives of posts
* Adding support for admin messaging regarding the sunsetting of the NPR Story API and this plugin. Will actually roll the messaging out once the successor plugin (NPR CDS) is available in the plugin directory

### V1.9.5
* Added a check for image dimensions for imported article thumbnails, and use NPR resizer if necessary (credit to [@tamw-wnet](https://github.com/tamw-wnet) for the catch and PR) [PR #22](https://github.com/OpenPublicMedia/nprapi-wordpress/pull/22)
* Added filter `npr_pre_article_push` to allow for modifying the organization ID or API key before pushing an article. Example: if you run a site with more than one org ID in the Story API and you want certain categories to push to certain IDs, you can create a function to hook into that filter and modify the org ID and API key as needed

### V1.9.4.1
* Fixed an issue where updating imported articles was not also updating the post thumbnail (all credit to [@tamw-wnet](https://github.com/tamw-wnet) for the catch) [Issue #19](https://github.com/OpenPublicMedia/nprapi-wordpress/issues/19)

Expand Down
20 changes: 19 additions & 1 deletion classes/NPRAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ class NPRAPI {
const NPRML_NAMESPACE = 'xmlns:nprml=https://api.npr.org/nprml';
const NPRML_VERSION = '0.92.2';

public $request;
public $response;
public $xml;
public $notices;
public $message;
public $stories;

/**
* Initializes an NPRML object.
*/
Expand Down Expand Up @@ -289,13 +296,24 @@ function add_simplexml_attributes( $element, $object ) {
* Basic OOP container for NPR entity (story, author, etc.).
*/
class NPRMLEntity {

public $textWithHtml;
public $body;
public $layout;
public $image;
public $htmlAsset;
public $id;
public $correction;
public $audio;
}

/**
* Basic OOP container for NPRML element.
*/
class NPRMLElement {
public $value;
public $paragraphs;
public $mp3;
public $type;
function __toString() {
return $this->value;
}
Expand Down
30 changes: 16 additions & 14 deletions classes/NPRAPIWordpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function query_by_url( $url ) {
if ( $response['body'] ) {
$this->xml = $response['body'];
} else {
$this->notice[] = __( 'No data available.' );
$this->notices[] = __( 'No data available.' );
}
} else {
nprstory_show_message( 'An error occurred pulling your story from the NPR API. The API responded with message =' . $response['response']['message'], TRUE );
Expand Down Expand Up @@ -117,14 +117,13 @@ function update_posts_from_stories( $publish = TRUE, $qnum = false ) {
'meta_value' => $story->id,
'post_type' => $pull_post_type,
'post_status' => 'any',
'no_found_rows' => true
'no_found_rows' => true
]);

// set the mod_date and pub_date to now so that for a new story we will fail the test below and do the update
$post_mod_date = strtotime( date( 'Y-m-d H:i:s' ) );
$post_pub_date = $post_mod_date;
$cats = [];
// BS: no_found_rows doesnt return $exists->found_posts, so use $exists->posts.
if ( $exists->posts ) {
$existing = $exists->post;
$post_id = $existing->ID;
Expand Down Expand Up @@ -338,21 +337,21 @@ function update_posts_from_stories( $publish = TRUE, $qnum = false ) {
// check the <enlargement> and then the crops, in this order "enlargement", "standard" if they don't exist, just get the image->src
if ( !empty( $image->enlargement ) ) {
$image_url = $image->enlargement->src;
}
}
if ( !empty( $image->crop ) && is_array( $image->crop ) ) {
foreach ( $image->crop as $crop ) {
if ( empty( $crop->type ) ) {
continue;
}
if ( 'enlargement' === $crop->type ) {
$image_url = $crop->src;
// sometimes enlargements are much larger than needed
if ( ( 1500 < $crop->height ) || ( 2000 < $crop->width ) ){
// if there's no querystring already, add s=6 which media.npr.org resizes to a usable but large size
if ( strpos( $image_url, "?" ) === false ) {
$image_url .= "?s=6";
}
}
// sometimes enlargements are much larger than needed
if ( ( 1500 < $crop->height ) || ( 2000 < $crop->width ) ) {
// if there's no querystring already, add s=6 which media.npr.org resizes to a usable but large size
if ( strpos( $image_url, "?" ) === false ) {
$image_url .= "?s=6";
}
}
}
}
if ( empty( $image_url ) ) {
Expand All @@ -365,7 +364,7 @@ function update_posts_from_stories( $publish = TRUE, $qnum = false ) {
}
}
}
}
}

if ( empty( $image_url ) && !empty( $image->src ) ) {
$image_url = $image->src;
Expand Down Expand Up @@ -749,7 +748,7 @@ function get_transcript_from_link( $transcript ) {
* This function will check a story to see if there are transcripts that should go with it, if there are
* we'll return the transcript as one big string with Transcript at the top and each paragraph separated by <p>
*
* @param string $story
* @param object $story
* @return string
*/
function get_transcript_body( $story ) {
Expand Down Expand Up @@ -881,7 +880,10 @@ function get_body_with_layout( $story, $layout ) {
// simplify the arrangement of the storytext object
$layoutarry = [];
foreach( $story->layout->storytext as $type => $elements ) {
if ( !is_array( $elements ) ) {
if ( $elements === null ) {
continue;
}
if ( !is_array( $elements ) ) {
$elements = [ $elements ];
}
foreach ( $elements as $element ) {
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"license" : "GPL-2.0+",
"require": {},
"dist": {
"url": "https://github.com/OpenPublicMedia/nprapi-wordpress/archive/refs/tags/v1.9.4.1.zip",
"url": "https://github.com/OpenPublicMedia/nprapi-wordpress/archive/refs/tags/v1.9.5.2.zip",
"type": "zip"
},
"authors": [
Expand Down
31 changes: 29 additions & 2 deletions ds-npr-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.4.1
* Version: 1.9.5.2
* Author: Open Public Media
* License: GPLv2
*/
Expand Down Expand Up @@ -257,4 +257,31 @@ function nprstory_add_header_meta() {
}
}
}
add_action( 'wp_head', 'nprstory_add_header_meta', 100 );
add_action( 'wp_head', 'nprstory_add_header_meta', 100 );

// add_action('admin_notices', 'nprstory_cds_plugin_admin_notice');

function nprstory_cds_plugin_admin_notice() {
global $pagenow;
$display = false;
// Only show this message on the admin dashboard and if asked for
if ( $pagenow === 'index.php' ) {
$display = true;
} elseif ( !empty( $_GET['page'] ) ) {
if ( str_contains( $_GET['page'], 'npr-' ) || str_contains( $_GET['page'], 'npr_' ) ) {
$display = true;
}
} elseif ( !empty( $_GET['post_type'] ) ) {
if ( str_contains( $_GET['post_type'], 'npr-' ) || str_contains( $_GET['post_type'], 'npr_' ) ) {
$display = true;
}
}
if ( $display ) { ?>
<div class="notice notice-warning">
<h2><?php _e( 'The NPR Story API plugin is going away!', 'ds_npr_api' ); ?></h2>
<p><?php _e( 'In the coming months, the NPR Story API will be sunset in favor of the NPR Content Distribution System (CDS). The same great content, but with greater flexibility, a more modern architecture, and richer media support.', 'ds_npr_api' ); ?></p>
<p><?php _e( 'While the Story API will continue to function for some time, we encourage you to try out the new NPR CDS Plugin. Be sure to file a ticket in NPR Studio to get your authorization token and station information.', 'ds_npr_api' ); ?></p>
</div>
<?php
}
}
3 changes: 2 additions & 1 deletion push_story.php
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ function nprstory_save_datetime( $post_ID ) {
$time = ( isset( $_POST['nprone-expiry-time'] ) ) ? sanitize_text_field( $_POST['nprone-expiry-time'] ) : '00:00';

// If the post is not published and values are not set, save an empty post meta
if ( isset( $date ) && 'publish' === $post->status ) {
if ( !empty( $date ) && !empty( $post->status ) && 'publish' === $post->status ) {
$timezone = get_option( 'gmt_offset' );
$datetime = date_create( $date, nprstory_get_datetimezone() );
$time = explode( ':', $time );
Expand All @@ -643,6 +643,7 @@ function nprstory_save_datetime( $post_ID ) {
} else {
delete_post_meta( $post_ID, '_nprone_expiry_8601' );
}
return true;
}
add_action( 'save_post', 'nprstory_save_datetime');

Expand Down
10 changes: 9 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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.4.1
Stable tag: 1.9.5.2
License: GPLv2
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: nprapi
Expand Down Expand Up @@ -70,6 +70,14 @@ NPR Stories having got gotten


== Changelog ==
= V1.9.5.1 =
* Adding `'no_found_posts' => false` to the query in `update_posts_from_stories()` for greater MySQL 8 compatability. Will also help on sites with large archives of posts
* Adding support for admin messaging regarding the sunsetting of the NPR Story API and this plugin. Will actually roll the messaging out once the successor plugin (NPR CDS) is available in the plugin directory

= V1.9.5 =
* Added a check for image dimensions for imported article thumbnails, and use NPR resizer if necessary (credit to [@tamw-wnet](https://github.com/tamw-wnet) for the catch and PR) [PR #22](https://github.com/OpenPublicMedia/nprapi-wordpress/pull/22)
* Added filter `npr_pre_article_push` to allow for modifying the organization ID or API key before pushing an article. Example: if you run a site with more than one org ID in the Story API and you want certain categories to push to certain IDs, you can create a function to hook into that filter and modify the org ID and API key as needed

= V1.9.4.1 =
* Fixed an issue where updating imported articles was not also updating the post thumbnail (all credit to [@tamw-wnet](https://github.com/tamw-wnet) for the catch) [Issue #19](https://github.com/OpenPublicMedia/nprapi-wordpress/issues/19)

Expand Down

0 comments on commit f9d74c0

Please sign in to comment.