';
- }
- }
- }
-
- }
-
- return $transcript_body;
- }
+ /**
+ *
+ * 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 strang with Transcript at the top and each paragraph separated by
';
+ }
+ }
+ }
+
+ }
+ return $transcript_body;
+ }
}
diff --git a/classes/nprml.php b/classes/nprml.php
index 3ef3188..7942c06 100644
--- a/classes/nprml.php
+++ b/classes/nprml.php
@@ -4,14 +4,14 @@
* nprstory_to_nprml(): Translates a post to NPRML. Returns an XML string.
*/
function nprstory_to_nprml( $post ) {
- $story = nprstory_post_to_nprml_story( $post );
- $doc = array();
- $doc[] = array(
- 'tag' => 'list',
- 'children' => array( array( 'tag' => 'story', 'children' => $story ), ),
- );
- $ret_xml = nprstory_nprml_array_to_xml( 'nprml', array( 'version' => '0.93' ), $doc );
- return $ret_xml;
+ $story = nprstory_post_to_nprml_story( $post );
+ $doc = [];
+ $doc[] = [
+ 'tag' => 'list',
+ 'children' => [ [ 'tag' => 'story', 'children' => $story ] ],
+ ];
+ $ret_xml = nprstory_nprml_array_to_xml( 'nprml', [ 'version' => '0.93' ], $doc );
+ return $ret_xml;
}
/**
@@ -22,19 +22,19 @@ function nprstory_to_nprml( $post ) {
* @param $post
*/
function nprstory_post_to_nprml_story( $post ) {
- $story = array();
- $story[] = array(
+ $story = [];
+ $story[] = [
'tag' => 'link',
- 'attr' => array( 'type' => 'html' ),
+ 'attr' => [ 'type' => 'html' ],
'text' => get_permalink( $post ),
- );
+ ];
$use_custom = get_option( 'dp_npr_push_use_custom_map' );
//get the list of metas available for this post
$post_metas = get_post_custom_keys( $post->ID );
$teaser_text = '';
- if ( ! empty( $post->post_excerpt ) ){
+ if ( !empty( $post->post_excerpt ) ) {
$teaser_text = $post->post_excerpt;
}
@@ -44,14 +44,14 @@ function nprstory_post_to_nprml_story( $post ) {
$custom_content_meta = get_option( 'ds_npr_api_mapping_body' );
if (
$use_custom
- && ! empty( $custom_content_meta )
+ && !empty( $custom_content_meta )
&& $custom_content_meta != '#NONE#'
&& in_array( $custom_content_meta, $post_metas )
- ){
- $content = get_post_meta( $post->ID, $custom_content_meta, true);
+ ) {
+ $content = get_post_meta( $post->ID, $custom_content_meta, true );
$post_for_teaser = $post;
$post_for_teaser->post_content = $content;
- if ( empty( $teaser_text ) ){
+ if ( empty( $teaser_text ) ) {
$teaser_text = nprstory_nai_get_excerpt( $post_for_teaser );
}
} else {
@@ -72,14 +72,14 @@ function nprstory_post_to_nprml_story( $post ) {
// Let any plugin that has short codes try and replace those with HTML
$content = do_shortcode( $content );
- //for any remaining short codes, nuke 'em
+ // for any remaining short codes, nuke 'em
$content = strip_shortcodes( $content );
$content = apply_filters( 'the_content', $content );
- $story[] = array(
+ $story[] = [
'tag' => 'teaser',
'text' => $teaser_text,
- );
+ ];
/*
* Custom title
@@ -90,17 +90,17 @@ function nprstory_post_to_nprml_story( $post ) {
&& !empty( $custom_title_meta )
&& $custom_title_meta != '#NONE#'
&& in_array( $custom_content_meta, $post_metas )
- ){
+ ) {
$custom_title = get_post_meta( $post->ID, $custom_title_meta, true );
- $story[] = array(
+ $story[] = [
'tag' => 'title',
'text' => $custom_title,
- );
+ ];
} else {
- $story[] = array(
+ $story[] = [
'tag' => 'title',
'text' => $post->post_title,
- );
+ ];
}
/*
@@ -114,53 +114,53 @@ function nprstory_post_to_nprml_story( $post ) {
// Custom field mapping byline
if (
$use_custom
- && ! empty( $custom_byline_meta )
+ && !empty( $custom_byline_meta )
&& $custom_byline_meta != '#NONE#'
&& in_array( $custom_content_meta, $post_metas )
) {
$byline = TRUE;
- $story[] = array(
+ $story[] = [
'tag' => 'byline',
- 'children' => array(
- array(
+ 'children' => [
+ [
'tag' => 'name',
'text' => get_post_meta( $post->ID, $custom_byline_meta, true ),
- )
- ),
- );
+ ]
+ ]
+ ];
}
// Co-Authors Plus support overrides the NPR custom byline
if ( function_exists( 'get_coauthors' ) ) {
$coauthors = get_coauthors( $post->ID );
- if ( ! empty( $coauthors ) ) {
+ if ( !empty( $coauthors ) ) {
$byline = TRUE;
- foreach( $coauthors as $i=>$co ) {
- $story[] = array(
+ foreach( $coauthors as $i => $co ) {
+ $story[] = [
'tag' => 'byline',
- 'children' => array(
- array(
+ 'children' => [
+ [
'tag' => 'name',
'text' => $co->display_name,
- )
- )
- );
+ ]
+ ]
+ ];
}
} else {
nprstory_error_log( 'we do not have co authors' );
}
} else {
- nprstory_error_log('can not find get_coauthors');
+ nprstory_error_log( 'can not find get_coauthors' );
}
- if ( ! $byline ) {
- $story[] = array(
+ if ( !$byline ) {
+ $story[] = [
'tag' => 'byline',
- 'children' => array (
- array(
+ 'children' => [
+ [
'tag' => 'name',
- 'text' => get_the_author_meta( 'display_name', $post->post_author ),
- )
- ),
- );
+ 'text' => get_the_author_meta( 'display_name', $post->post_author )
+ ]
+ ]
+ ];
}
/*
@@ -171,10 +171,10 @@ function nprstory_post_to_nprml_story( $post ) {
*/
$nprapi = get_post_meta( $post->ID, '_send_to_one', true ); // 0 or 1
if ( ! empty( $nprapi ) && ( '1' === $nprapi || 1 === $nprapi ) ) {
- $story[] = array(
+ $story[] = [
'tag' => 'parent',
- 'attr' => array( 'id' => '319418027', 'type' => 'collection' ),
- );
+ 'attr' => [ 'id' => '319418027', 'type' => 'collection' ]
+ ];
}
/*
@@ -184,46 +184,46 @@ function nprstory_post_to_nprml_story( $post ) {
*/
$nprapi = get_post_meta( $post->ID, '_nprone_featured', true ); // 0 or 1
if ( ! empty( $nprapi ) && ( '1' === $nprapi || 1 === $nprapi ) ) {
- $story[] = array(
+ $story[] = [
'tag' => 'parent',
- 'attr' => array( 'id' => '500549367', 'type' => 'collection' ),
- );
+ 'attr' => [ 'id' => '500549367', 'type' => 'collection' ]
+ ];
}
/*
* Mini Teaser (not yet implemented)
* Slug (not yet implemented)
*/
- #'miniTeaser' => array( 'text' => '' ),
- #'slug' => array( 'text' => '' ),
+ // 'miniTeaser' => [ 'text' => '' ],
+ // 'slug' => [ 'text' => '' ],
/*
* Dates and times
*/
- $story[] = array(
+ $story[] = [
'tag' => 'storyDate',
- 'text' => mysql2date( 'D, d M Y H:i:s +0000', $post->post_date_gmt ),
- );
- $story[] = array(
+ 'text' => mysql2date( 'D, d M Y H:i:s +0000', $post->post_date_gmt )
+ ];
+ $story[] = [
'tag' => 'pubDate',
- 'text' => mysql2date( 'D, d M Y H:i:s +0000', $post->post_modified_gmt ),
- );
- $story[] = array(
+ 'text' => mysql2date( 'D, d M Y H:i:s +0000', $post->post_modified_gmt )
+ ];
+ $story[] = [
'tag' => 'lastModifiedDate',
- 'text' => mysql2date( 'D, d M Y H:i:s +0000', $post->post_modified_gmt ),
- );
- $story[] = array(
+ 'text' => mysql2date( 'D, d M Y H:i:s +0000', $post->post_modified_gmt )
+ ];
+ $story[] = [
'tag' => 'partnerId',
- 'text' => $post->guid,
- );
+ 'text' => $post->guid
+ ];
// NPR One audio run-by date
$datetime = nprstory_get_post_expiry_datetime( $post ); // if expiry date is not set, returns publication date plus 7 days
if ( $datetime instanceof DateTime ) {
- $story[] = array(
+ $story[] = [
'tag' => 'audioRunByDate',
'text' => date_format( $datetime, 'j M Y H:i:00 O' ) // 1 Oct 2017 01:00:00 -0400, 29 Feb 2020 23:59:00 -0500
- );
+ ];
}
@@ -235,42 +235,43 @@ function nprstory_post_to_nprml_story( $post ) {
* It would be nice to send text after we strip all html and shortcodes, but we need the html
* and sending both will duplicate the data in the API
*/
- $story[] = array(
+ $story[] = [
'tag' => 'textWithHtml',
- 'children' => nprstory_nprml_split_paragraphs( $content ),
- );
+ 'children' => nprstory_nprml_split_paragraphs( $content )
+ ];
$perms_group = get_option( 'ds_npr_story_default_permission' );
- if (!empty( $perms_group ) ) {
- $story[] = array(
+ if ( !empty( $perms_group ) ) {
+ $story[] = [
'tag' => 'permissions',
- 'children' => array (
- array(
+ 'children' => [
+ [
'tag' => 'permGroup',
- 'attr' => array( 'id' => $perms_group ),
- )
- ),
- );
+ 'attr' => [ 'id' => $perms_group ]
+ ]
+ ]
+ ];
}
$custom_media_credit = get_option( 'ds_npr_api_mapping_media_credit' );
$custom_media_agency = get_option( 'ds_npr_api_mapping_media_agency' );
- /* remove this for now until we decide if we're going to actually do this...km
- $dist_media_option = get_option('ds_npr_api_mapping_distribute_media');
- $dist_media_polarity = get_option('ds_npr_api_mapping_distribute_media_polarity');
+ /*
+ remove this for now until we decide if we're going to actually do this...km
+ $dist_media_option = get_option('ds_npr_api_mapping_distribute_media');
+ $dist_media_polarity = get_option('ds_npr_api_mapping_distribute_media_polarity');
*/
/*
* Attach images to the post
*/
- $args = array(
+ $args = [
'order'=> 'DESC',
'post_mime_type' => 'image',
'post_parent' => $post->ID,
'post_status' => null,
'post_type' => 'attachment'
- );
+ ];
$images = get_children( $args );
$primary_image = get_post_thumbnail_id( $post->ID );
@@ -282,7 +283,7 @@ function nprstory_post_to_nprml_story( $post ) {
if ( $use_custom && !empty( $custom_media_credit ) && $custom_media_credit != '#NONE#' && in_array( $custom_media_credit,$image_metas ) ) {
$custom_credit = get_post_meta( $image->ID, $custom_media_credit, true );
}
- if ( $use_custom && ! empty( $custom_media_agency ) && $custom_media_agency != '#NONE#' && in_array( $custom_media_agency,$image_metas ) ) {
+ if ( $use_custom && !empty( $custom_media_agency ) && $custom_media_agency != '#NONE#' && in_array( $custom_media_agency,$image_metas ) ) {
$custom_agency = get_post_meta( $image->ID, $custom_media_agency, true);
}
@@ -313,28 +314,28 @@ function nprstory_post_to_nprml_story( $post ) {
$in_body = "?origin=body";
}
}
- $story[] = array(
+ $story[] = [
'tag' => 'image',
- 'attr' => array( 'src' => $image_attach_url . $in_body, 'type' => $image_type ),
- 'children' => array(
- array(
+ 'attr' => [ 'src' => $image_attach_url . $in_body, 'type' => $image_type ],
+ 'children' => [
+ [
'tag' => 'title',
- 'text' => $image->post_title,
- ),
- array(
+ 'text' => $image->post_title
+ ],
+ [
'tag' => 'caption',
- 'text' => $image->post_excerpt,
- ),
- array(
+ 'text' => $image->post_excerpt
+ ],
+ [
'tag' => 'producer',
'text' => $custom_credit
- ),
- array(
+ ],
+ [
'tag' => 'provider',
'text' => $custom_agency
- )
- ),
- );
+ ]
+ ]
+ ];
}
/*
@@ -342,13 +343,13 @@ function nprstory_post_to_nprml_story( $post ) {
*
* Should be able to do the same as image for audio, with post_mime_type = 'audio' or something.
*/
- $args = array(
+ $args = [
'order'=> 'DESC',
'post_mime_type' => 'audio',
'post_parent' => $post->ID,
'post_status' => null,
'post_type' => 'attachment'
- );
+ ];
$audios = get_children( $args );
$audio_files = [];
@@ -362,28 +363,28 @@ function nprstory_post_to_nprml_story( $post ) {
$audio_guid = wp_get_attachment_url( $audio->ID );
$audio_files[] = $audio->ID;
- $story[] = array(
+ $story[] = [
'tag' => 'audio',
- 'children' => array(
- array(
+ 'children' => [
+ [
'tag' => 'format',
- 'children' => array (
- array(
+ 'children' => [
+ [
'tag' => 'mp3',
'text' => $audio_guid,
- )
- ),
- ),
- array(
+ ]
+ ]
+ ],
+ [
'tag' => 'description',
- 'text' => $caption,
- ),
- array(
+ 'text' => $caption
+ ],
+ [
'tag' => 'duration',
- 'text' => $audio_meta['length'],
- ),
- ),
- );
+ 'text' => $audio_meta['length']
+ ]
+ ]
+ ];
}
/*
@@ -399,7 +400,7 @@ function nprstory_post_to_nprml_story( $post ) {
$audio_guid = trim( $pieces[0] );
$attach_id = attachment_url_to_postid( $audio_guid );
- if ( !in_array( $attach_id, $audio_files ) ) :
+ if ( !in_array( $attach_id, $audio_files ) ) {
$audio_files[] = $attach_id;
$audio_meta = wp_get_attachment_metadata( $attach_id );
@@ -413,25 +414,25 @@ function nprstory_post_to_nprml_story( $post ) {
$duration = ( !empty($metadata['duration'] ) ) ? nprstory_convert_duration_to_seconds( $metadata['duration'] ) : 0;
endif;
- $story[] = array(
+ $story[] = [
'tag' => 'audio',
- 'children' => array(
- array(
+ 'children' => [
+ [
'tag' => 'duration',
- 'text' => $duration,
- ),
- array(
+ 'text' => $duration
+ ],
+ [
'tag' => 'format',
- 'children' => array(
- array(
- 'tag' => 'mp3',
- 'text' => wp_get_attachment_url( $attach_id ),
- ),
- ),
- ),
- ),
- );
- endif;
+ 'children' => [
+ [
+ 'tag' => 'mp3',
+ 'text' => wp_get_attachment_url( $attach_id )
+ ]
+ ]
+ ]
+ ]
+ ];
+ }
}
}
@@ -443,26 +444,26 @@ function nprstory_post_to_nprml_story( $post ) {
// Convert "HH:MM:SS" duration (not time) into seconds
function nprstory_convert_duration_to_seconds( $duration ) {
- $pieces = explode( ':', $duration );
- $duration_in_seconds = ( $pieces[0] * 60 * 60 + $pieces[1] * 60 + $pieces[2] );
- return $duration_in_seconds;
+ $pieces = explode( ':', $duration );
+ $duration_in_seconds = ( $pieces[0] * 60 * 60 + $pieces[1] * 60 + $pieces[2] );
+ return $duration_in_seconds;
}
function nprstory_nprml_split_paragraphs( $html ) {
- $parts = array_filter(
- array_map( 'trim', preg_split( "/<\/?p>/", $html ) )
- );
- $graphs = array();
- $num = 1;
- foreach ( $parts as $part ) {
- $graphs[] = array(
- 'tag' => 'paragraph',
- 'attr' => array( 'num' => $num ),
- 'cdata' => $part,
- );
- $num++;
- }
- return $graphs;
+ $parts = array_filter(
+ array_map( 'trim', preg_split( "/<\/?p>/", $html ) )
+ );
+ $graphs = [];
+ $num = 1;
+ foreach ( $parts as $part ) {
+ $graphs[] = [
+ 'tag' => 'paragraph',
+ 'attr' => [ 'num' => $num ],
+ 'cdata' => $part
+ ];
+ $num++;
+ }
+ return $graphs;
}
@@ -493,29 +494,29 @@ function nprstory_nprml_array_to_xml( $tag, $attrs, $data ) {
* @param DOMDocument $xml
*/
function nprstory_nprml_item_to_xml( $item, $xml ) {
- if ( ! array_key_exists( 'tag', $item ) ) {
+ if ( !array_key_exists( 'tag', $item ) ) {
error_log( "Unable to convert NPRML item to XML: no tag for: " . print_r( $item, true ) ); // debug use
// this should actually be a serious error
}
- $elem = $xml->createElement( $item[ 'tag' ] );
+ $elem = $xml->createElement( $item['tag'] );
if ( array_key_exists( 'children', $item ) ) {
- foreach ( $item[ 'children' ] as $child ) {
+ foreach ( $item['children'] as $child ) {
$childxml = nprstory_nprml_item_to_xml( $child, $xml );
$elem->appendChild( $childxml );
}
}
if ( array_key_exists( 'text', $item ) ) {
$elem->appendChild(
- $xml->createTextNode( $item[ 'text' ] )
+ $xml->createTextNode( $item['text'] )
);
}
if ( array_key_exists( 'cdata', $item ) ) {
$elem->appendChild(
- $xml->createCDATASection( $item[ 'cdata' ] )
+ $xml->createCDATASection( $item['cdata'] )
);
}
if ( array_key_exists( 'attr', $item ) ) {
- foreach ( $item[ 'attr' ] as $attr => $val ) {
+ foreach ( $item['attr'] as $attr => $val ) {
$elem->setAttribute( $attr, $val );
}
}
@@ -546,8 +547,7 @@ function nprstory_nai_get_excerpt( $post, $word_count = 30 ) {
$text = strip_tags( $text );
$excerpt_length = apply_filters( 'excerpt_length', $word_count );
//$excerpt_more = apply_filters( 'excerpt_more', ' ' . '[...]' );
- $words = preg_split( "/[\n\r\t ]+/", $text, $excerpt_length + 1,
- PREG_SPLIT_NO_EMPTY );
+ $words = preg_split( "/[\n\r\t ]+/", $text, $excerpt_length + 1, sPREG_SPLIT_NO_EMPTY );
if ( count( $words ) > $excerpt_length ) {
array_pop( $words );
$text = implode( ' ', $words );
diff --git a/ds-npr-api.php b/ds-npr-api.php
index 0843a2d..ca3202c 100644
--- a/ds-npr-api.php
+++ b/ds-npr-api.php
@@ -7,20 +7,20 @@
* License: GPLv2
*/
/*
- Copyright 2012 NPR Digital Services
+ Copyright 2012 NPR Digital Services
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License, version 2, as
- published by the Free Software Foundation.
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License, version 2, as
+ published by the Free Software Foundation.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
define( 'NPR_STORY_ID_META_KEY', 'npr_story_id' );
@@ -31,19 +31,19 @@
define( 'NPR_BYLINE_META_KEY', 'npr_byline' );
define( 'NPR_BYLINE_LINK_META_KEY', 'npr_byline_link' );
define( 'NPR_MULTI_BYLINE_META_KEY', 'npr_multi_byline' );
-define( 'NPR_IMAGE_GALLERY_META_KEY', 'npr_image_gallery');
-define( 'NPR_AUDIO_META_KEY', 'npr_audio');
-define( 'NPR_AUDIO_M3U_META_KEY', 'npr_audio_m3u');
-define( 'NPR_PUB_DATE_META_KEY', 'npr_pub_date');
-define( 'NPR_STORY_DATE_MEATA_KEY', 'npr_story_date');
-define( 'NPR_LAST_MODIFIED_DATE_KEY', 'npr_last_modified_date');
-define( 'NPR_RETRIEVED_STORY_META_KEY', 'npr_retrieved_story');
+define( 'NPR_IMAGE_GALLERY_META_KEY', 'npr_image_gallery' );
+define( 'NPR_AUDIO_META_KEY', 'npr_audio' );
+define( 'NPR_AUDIO_M3U_META_KEY', 'npr_audio_m3u' );
+define( 'NPR_PUB_DATE_META_KEY', 'npr_pub_date' );
+define( 'NPR_STORY_DATE_MEATA_KEY', 'npr_story_date' );
+define( 'NPR_LAST_MODIFIED_DATE_KEY', 'npr_last_modified_date' );
+define( 'NPR_RETRIEVED_STORY_META_KEY', 'npr_retrieved_story' );
-define( 'NPR_IMAGE_CREDIT_META_KEY', 'npr_image_credit');
-define( 'NPR_IMAGE_AGENCY_META_KEY', 'npr_image_agency');
-define( 'NPR_IMAGE_CAPTION_META_KEY', 'npr_image_caption');
+define( 'NPR_IMAGE_CREDIT_META_KEY', 'npr_image_credit' );
+define( 'NPR_IMAGE_AGENCY_META_KEY', 'npr_image_agency' );
+define( 'NPR_IMAGE_CAPTION_META_KEY', 'npr_image_caption' );
-define( 'NPR_PUSH_STORY_ERROR', 'npr_push_story_error');
+define( 'NPR_PUSH_STORY_ERROR', 'npr_push_story_error' );
define( 'NPR_MAX_QUERIES', 10 );
@@ -54,14 +54,14 @@
// Load files
define( 'NPRSTORY_PLUGIN_DIR', plugin_dir_path(__FILE__) );
require_once( NPRSTORY_PLUGIN_DIR . 'settings.php' );
-require_once( NPRSTORY_PLUGIN_DIR . 'classes/NPRAPIWordpress.php');
-require_once( NPRSTORY_PLUGIN_DIR . 'get_stories.php');
-require_once( NPRSTORY_PLUGIN_DIR . 'meta-boxes.php');
-require_once( NPRSTORY_PLUGIN_DIR . 'push_story.php');
+require_once( NPRSTORY_PLUGIN_DIR . 'classes/NPRAPIWordpress.php' );
+require_once( NPRSTORY_PLUGIN_DIR . 'get_stories.php' );
+require_once( NPRSTORY_PLUGIN_DIR . 'meta-boxes.php' );
+require_once( NPRSTORY_PLUGIN_DIR . 'push_story.php' );
//add the cron to get stories
register_activation_hook( NPRSTORY_PLUGIN_DIR . 'ds-npr-api.php', 'nprstory_activation' );
-add_action( 'npr_ds_hourly_cron', array ( 'DS_NPR_API','nprstory_cron_pull' ) );
+add_action( 'npr_ds_hourly_cron', [ 'DS_NPR_API','nprstory_cron_pull' ] );
register_deactivation_hook( NPRSTORY_PLUGIN_DIR . 'ds-npr-api.php', 'nprstory_deactivation' );
@@ -84,13 +84,13 @@ function nprstory_activation() {
function nprstory_activate() {
update_option( 'dp_npr_query_multi_cron_interval', 60 );
- if ( ! wp_next_scheduled( 'npr_ds_hourly_cron' ) ) {
+ if ( !wp_next_scheduled( 'npr_ds_hourly_cron' ) ) {
nprstory_error_log( 'turning on cron event for NPR Story API plugin' );
wp_schedule_event( time(), 'hourly', 'npr_ds_hourly_cron' );
}
- $num = get_option( 'ds_npr_num' );
- if ( empty($num) ) {
+ $num = get_option( 'ds_npr_num' );
+ if ( empty( $num ) ) {
update_option( 'ds_npr_num', 5 );
}
@@ -144,18 +144,16 @@ function nprstory_show_message( $message, $errormsg = false ) {
add_action( 'init', 'nprstory_create_post_type' );
function nprstory_create_post_type() {
- register_post_type( NPR_POST_TYPE,
- array(
- 'labels' => array(
- 'name' => __( 'NPR Stories' ),
- 'singular_name' => __( 'NPR Story' ),
- ),
- 'public' => true,
- 'has_archive' => true,
- 'menu_position' => 5,
- 'supports' => array( 'title', 'editor', 'thumbnail', 'custom-fields' ),
- )
- );
+ register_post_type( NPR_POST_TYPE, [
+ 'labels' => [
+ 'name' => __( 'NPR Stories' ),
+ 'singular_name' => __( 'NPR Story' ),
+ ],
+ 'public' => true,
+ 'has_archive' => true,
+ 'menu_position' => 5,
+ 'supports' => [ 'title', 'editor', 'thumbnail', 'custom-fields' ],
+ ]);
}
/**
@@ -170,7 +168,7 @@ function nprstory_add_meta_boxes() {
$push_post_type = get_option( 'ds_npr_push_post_type' ) ?: 'post';
$push_url = get_option( 'ds_npr_api_push_url' );
if ( $screen->id == $push_post_type ) {
- if ( ! empty( $push_url ) ) {
+ if ( !empty( $push_url ) ) {
global $post;
add_meta_box(
'ds_npr_document_meta',
diff --git a/get_stories.php b/get_stories.php
index 2e7deae..865c9ce 100644
--- a/get_stories.php
+++ b/get_stories.php
@@ -4,7 +4,7 @@
*/
require_once( NPRSTORY_PLUGIN_DIR . 'get_stories_ui.php' );
-require_once( NPRSTORY_PLUGIN_DIR . 'classes/NPRAPIWordpress.php');
+require_once( NPRSTORY_PLUGIN_DIR . 'classes/NPRAPIWordpress.php' );
class DS_NPR_API {
var $created_message = '';
@@ -28,22 +28,22 @@ public static function nprstory_get_pull_post_type() {
public static function nprstory_cron_pull() {
// here we should get the list of IDs/full urls that need to be checked hourly
//because this is run on cron, and may be fired off by an non-admin, we need to load a bunch of stuff
- require_once( ABSPATH . 'wp-admin/includes/file.php');
- require_once( ABSPATH . 'wp-admin/includes/media.php');
+ require_once( ABSPATH . 'wp-admin/includes/file.php' );
+ require_once( ABSPATH . 'wp-admin/includes/media.php' );
// This is debug code. It may be save future devs some time; please keep it around.
/*
- $now = gmDate("D, d M Y G:i:s O ");
- error_log("right now the time is -- ".$now); // debug use
+ $now = gmDate("D, d M Y G:i:s O ");
+ error_log("right now the time is -- ".$now); // debug use
*/
// here we go.
$num = get_option( 'ds_npr_num' );
- for ($i=0; $i<$num; $i++ ) {
+ for ( $i=0; $i < $num; $i++ ) {
$api = new NPRAPIWordpress();
$q = 'ds_npr_query_' . $i;
$query_string = get_option( $q );
- if ( ! empty( $query_string ) ) {
+ if ( !empty( $query_string ) ) {
nprstory_error_log( 'Cron '. $i . ' querying NPR API for ' . $query_string );
//if the query string contains the pull url and 'query', just make request from the API
if ( stristr( $query_string, get_option( 'ds_npr_api_pull_url' ) ) && stristr( $query_string,'query' ) ) {
@@ -60,29 +60,28 @@ public static function nprstory_cron_pull() {
var_export( get_option( 'ds_npr_api_pull_url' ), true )
) ); // debug use
} else {
- $params = array ('id' => $query_string, 'apiKey' => get_option( 'ds_npr_api_key' ));
+ $params = [ 'id' => $query_string, 'apiKey' => get_option( 'ds_npr_api_key' ) ];
$api->request( $params, 'query', get_option( 'ds_npr_api_pull_url' ) );
}
}
$api->parse();
- try {
- if ( empty( $api->message ) || $api->message->level != 'warning' ) {
- //check the publish flag and send that along.
- $pub_flag = FALSE;
- $pub_option = get_option('ds_npr_query_publish_'.$i);
- if ( $pub_option == 'Publish' ) {
- $pub_flag = TRUE;
- }
- $story = $api->update_posts_from_stories($pub_flag, $i);
- } else {
- if ( empty($story) ) {
- error_log('NPR Story API: not going to save story. Query '. $query_string .' returned an error '.$api->message->id. ' error'); // debug use
- }
- }
- }
- catch (Exception $e) {
- error_log('NPR Story API: error in ' . __FUNCTION__ . ' like this :'. $e); // debug use
- }
+ try {
+ if ( empty( $api->message ) || $api->message->level != 'warning' ) {
+ //check the publish flag and send that along.
+ $pub_flag = FALSE;
+ $pub_option = get_option( 'ds_npr_query_publish_' . $i );
+ if ( $pub_option == 'Publish' ) {
+ $pub_flag = TRUE;
+ }
+ $story = $api->update_posts_from_stories( $pub_flag, $i );
+ } else {
+ if ( empty( $story ) ) {
+ error_log( 'NPR Story API: not going to save story. Query ' . $query_string . ' returned an error ' . $api->message->id . ' error' ); // debug use
+ }
+ }
+ } catch( Exception $e ) {
+ error_log( 'NPR Story API: error in ' . __FUNCTION__ . ' like this :'. $e ); // debug use
+ }
}
}
}
@@ -90,101 +89,100 @@ public static function nprstory_cron_pull() {
/**
* Function to convert an alleged NPR story URL or ID into a story ID, then request it
*/
- public function load_page_hook() {
+ public function load_page_hook() {
// find the input that is allegedly a story id
// We validate these later
- if ( isset( $_POST ) && isset( $_POST[ 'story_id' ] ) ) {
- $story_id = $_POST[ 'story_id' ] ;
- if ( isset( $_POST['publishNow'] ) ){
- $publish = true;
- }
- if ( isset($_POST['createDaft'] ) ){
- $publish = false;
- }
- if ( ! check_admin_referer('nprstory_nonce_story_id', 'nprstory_nonce_story_id_field') ) {
+ if ( isset( $_POST ) && isset( $_POST[ 'story_id' ] ) ) {
+ $story_id = $_POST[ 'story_id' ] ;
+ if ( isset( $_POST['publishNow'] ) ) {
+ $publish = true;
+ }
+ if ( isset( $_POST['createDaft'] ) ) {
+ $publish = false;
+ }
+ if ( !check_admin_referer( 'nprstory_nonce_story_id', 'nprstory_nonce_story_id_field' ) ) {
wp_die(
- __('Nonce did not verify in DS_NPR_API::load_page_hook. Are you sure you should be doing this?'),
- __('NPR Story API Error'),
+ __( 'Nonce did not verify in DS_NPR_API::load_page_hook. Are you sure you should be doing this?' ),
+ __( 'NPR Story API Error' ),
403
);
}
- } else if ( isset( $_GET['story_id']) && isset( $_GET['create_draft'] ) ) {
- $story_id = $_GET['story_id'];
- }
+ } elseif ( isset( $_GET['story_id'] ) && isset( $_GET['create_draft'] ) ) {
+ $story_id = $_GET['story_id'];
+ }
// if the current user shouldn't be doing this, fail
- if ( ! current_user_can('edit_posts') ) {
+ if ( !current_user_can( 'edit_posts' ) ) {
wp_die(
- __('You do not have permission to edit posts, and therefore you do not have permission to pull posts from the NPR API'),
- __('NPR Story API Error'),
+ __( 'You do not have permission to edit posts, and therefore you do not have permission to pull posts from the NPR API' ),
+ __( 'NPR Story API Error' ),
403
);
}
// try to get the ID of the story from the URL
- if ( isset( $story_id ) ) {
- //check to see if we got an ID or a URL
- if ( is_numeric( $story_id ) ) {
- if (strlen($story_id) >= 8) {
- $story_id = $story_id;
+ if ( isset( $story_id ) ) {
+ //check to see if we got an ID or a URL
+ if ( is_numeric( $story_id ) ) {
+ if ( strlen( $story_id ) >= 8 ) {
+ $story_id = $story_id;
}
- } else {
- // url format: /yyyy/mm/dd/id
+ } else {
+ // 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
+ 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 );
}
- }
+ }
}
// Don't do anything if $story_id isn't an ID
if ( isset( $story_id ) && is_numeric( $story_id ) ) {
// start the API class
- // todo: check that the API key is actually set
- $api = new NPRAPIWordpress();
+ // todo: check that the API key is actually set
+ $api = new NPRAPIWordpress();
- $params = array( 'id' => $story_id, 'apiKey' => get_option( 'ds_npr_api_key' ) );
- $api->request( $params, 'query', get_option( 'ds_npr_api_pull_url' ) );
- $api->parse();
+ $params = [ 'id' => $story_id, 'apiKey' => get_option( 'ds_npr_api_key' ) ];
+ $api->request( $params, 'query', get_option( 'ds_npr_api_pull_url' ) );
+ $api->parse();
- if ( empty( $api->message ) || $api->message->level != 'warning') {
- $post_id = $api->update_posts_from_stories($publish);
- if ( ! empty( $post_id ) ) {
- //redirect to the edit page if we just updated one story
- $post_link = admin_url( 'post.php?action=edit&post=' . $post_id );
- wp_redirect( $post_link );
- }
- } else {
- if ( empty($story) ) {
- $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;
- }
- }
- }
- }
+ if ( empty( $api->message ) || $api->message->level != 'warning' ) {
+ $post_id = $api->update_posts_from_stories( $publish );
+ if ( !empty( $post_id ) ) {
+ //redirect to the edit page if we just updated one story
+ $post_link = admin_url( 'post.php?action=edit&post=' . $post_id );
+ wp_redirect( $post_link );
+ }
+ } else {
+ if ( empty( $story ) ) {
+ $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;
+ }
+ }
+ }
+ }
/**
* Class constructor that hooks up the menu and the "Get NPR Stories" page action.
*/
- public function __construct() {
- if ( ! is_admin() ) {
- return;
- }
- add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
- add_action( 'load-posts_page_get-npr-stories', array( $this, 'load_page_hook' ) );
- }
+ public function __construct() {
+ if ( !is_admin() ) {
+ return;
+ }
+ add_action( 'admin_menu', [ $this, 'admin_menu' ] );
+ add_action( 'load-posts_page_get-npr-stories', [ $this, 'load_page_hook' ] );
+ }
/**
* Register the admin menu for "Get NPR Stories"
*/
- public function admin_menu() {
- add_posts_page( 'Get NPR Stories', 'Get NPR Stories', 'edit_posts', 'get-npr-stories', 'nprstory_get_stories' );
- }
-
+ public function admin_menu() {
+ add_posts_page( 'Get NPR Stories', 'Get NPR Stories', 'edit_posts', 'get-npr-stories', 'nprstory_get_stories' );
+ }
}
-new DS_NPR_API;
+new DS_NPR_API;
\ No newline at end of file
diff --git a/get_stories_ui.php b/get_stories_ui.php
index f8f2c74..e863d7e 100644
--- a/get_stories_ui.php
+++ b/get_stories_ui.php
@@ -3,140 +3,143 @@
* Functions related to the user interface for fetching stories from the API
*/
-/**
+/*
* This will turn on the update story column for all posts
* yes, this is intentionally commented out
*
-add_filter('manage_posts_columns', 'nprstory_update_column');
+add_filter( 'manage_posts_columns', 'nprstory_update_column' );
-function nprstory_update_column($defaults){
+function nprstory_update_column( $defaults ) {
$pull_post_type = DS_NPR_API::nprstory_get_pull_post_type();
- global $post_type;
- if($post_type == $pull_post_type) {
+ global $post_type;
+ if ( $post_type == $pull_post_type ) {
$defaults['update_story'] = 'Update Story';
- }
+ }
return $defaults;
}
-/**/
+*/
// Add the update story column to the page listing the posts for the pull-type
-add_filter( 'manage_edit-' . DS_NPR_API::nprstory_get_pull_post_type() . '_columns', 'nprstory_add_new_story_columns');
+add_filter( 'manage_edit-' . DS_NPR_API::nprstory_get_pull_post_type() . '_columns', 'nprstory_add_new_story_columns' );
+
function nprstory_add_new_story_columns( $cols ) {
$cols['update_story'] = 'Update Story';
return $cols;
}
add_action( 'manage_posts_custom_column', 'nprstory_update_column_content', 10, 2 );
-function nprstory_update_column_content ( $column_name, $post_ID ) {
+
+function nprstory_update_column_content( $column_name, $post_ID ) {
if ( $column_name == 'update_story' ) {
$retrieved = get_post_meta( $post_ID, NPR_RETRIEVED_STORY_META_KEY, true );
- if ($retrieved) {
+ if ( $retrieved ) {
$api_id = get_post_meta( $post_ID, NPR_STORY_ID_META_KEY, TRUE );
- echo ( ' Update ' );
+ echo ' Update ';
}
}
}
//add the bulk action to the dropdown on the post admin page
add_action( 'admin_footer-edit.php', 'nprstory_bulk_action_update_dropdown' );
+
function nprstory_bulk_action_update_dropdown() {
$pull_post_type = DS_NPR_API::nprstory_get_pull_post_type();
- global $post_type;
- if( $post_type == $pull_post_type ) {
- ?>
-
-
+
+ current_action();
-
- switch( $action ) {
- // 3. Perform the action
- case 'updateNprStory':
-
- // make sure ids are submitted. depending on the resource type, this may be 'media' or 'ids'
- if ( isset( $_REQUEST['post'] ) ) {
- $post_ids = array_map( 'intval', $_REQUEST['post'] );
- }
-
- $exported = 0;
- foreach( $post_ids as $post_id ) {
- $api_id = get_post_meta( $post_id, NPR_STORY_ID_META_KEY, TRUE );
-
- // don't run API queries for posts that have no ID
- // @todo: why do some posts have no ID
- // @todo: oh, it's only imported drafts that don't have an ID
- if ( !empty( $api_id ) ) {
- $api = new NPRAPIWordpress();
- $params = array( 'id' => $api_id, 'apiKey' => get_option( 'ds_npr_api_key' ) );
- $api->request( $params, 'query', get_option( 'ds_npr_api_pull_url' ) );
- $api->parse();
- if ( empty( $api->message ) || $api->message->level != 'warning' ){
- nprstory_error_log( 'updating story for API ID='.$api_id );
- $story = $api->update_posts_from_stories();
+ // 1. get the action
+ $wp_list_table = _get_list_table( 'WP_Posts_List_Table' );
+ $action = $wp_list_table->current_action();
+
+ switch ( $action ) {
+ // 3. Perform the action
+ case 'updateNprStory':
+
+ // make sure ids are submitted. depending on the resource type, this may be 'media' or 'ids'
+ if ( isset( $_REQUEST['post'] ) ) {
+ $post_ids = array_map( 'intval', $_REQUEST['post'] );
+ }
+
+ $exported = 0;
+ foreach( $post_ids as $post_id ) {
+ $api_id = get_post_meta( $post_id, NPR_STORY_ID_META_KEY, TRUE );
+
+ // don't run API queries for posts that have no ID
+ // @todo: why do some posts have no ID
+ // @todo: oh, it's only imported drafts that don't have an ID
+ if ( !empty( $api_id ) ) {
+ $api = new NPRAPIWordpress();
+ $params = [ 'id' => $api_id, 'apiKey' => get_option( 'ds_npr_api_key' ) ];
+ $api->request( $params, 'query', get_option( 'ds_npr_api_pull_url' ) );
+ $api->parse();
+ if ( empty( $api->message ) || $api->message->level != 'warning' ) {
+ nprstory_error_log( 'updating story for API ID='.$api_id );
+ $story = $api->update_posts_from_stories();
+ }
}
- } else {
}
- }
- // build the redirect url
- //$sendback = add_query_arg( array('exported' => $exported, 'ids' => join(',', $post_ids) ), $sendback );
- break;
- default:
- return;
- }
+ // build the redirect url
+ //$sendback = add_query_arg( array('exported' => $exported, 'ids' => join(',', $post_ids) ), $sendback );
+ break;
+ default: return;
+ }
- // ...
+ // ...
- // 4. Redirect client
- //wp_redirect($sendback);
- //exit();
+ // 4. Redirect client
+ //wp_redirect($sendback);
+ //exit();
}
function nprstory_get_stories() {
- global $is_IE;
- $api_key = get_option( 'ds_npr_api_key' );
- $pull_url = get_option( 'ds_npr_api_pull_url' );
+ global $is_IE;
+ $api_key = get_option( 'ds_npr_api_key' );
+ $pull_url = get_option( 'ds_npr_api_pull_url' );
?>
-
-
Get NPR Stories
- Set your API Key here.', TRUE);?>
- Set your API Pull URL here.', TRUE);?>
-
+
Get NPR Stories
+ Set your API Key here.', TRUE );
+ }
+ if ( !$pull_url ) {
+ nprstory_show_message ('You do not currently have an API Pull URL set. Set your API Pull URL here.', TRUE );
+ }
+
+ // Get the story ID from the URL, then paste it into the input's value field with esc_attr
+ $story_id = '';
+ if ( ( isset( $_POST ) && isset( $_POST[ 'story_id' ] ) ) || ( isset( $_GET ) && isset( $_GET['story_id'] ) ) ) {
+ if ( !empty( $_POST['story_id'] ) ) {
+ $story_id = $_POST['story_id'];
+ }
+ if ( !empty($_GET['story_id'] ) ) {
+ $story_id = $_GET['story_id'];
+ }
+ }
?>
-
-
-
-
-
-
+
+
+ post_status );
- $attrs = array( 'id' => 'ds-npr-update-push' );
+ $attrs = [ 'id' => 'ds-npr-update-push' ];
- if ( $is_disabled ) {
+ if ( $is_disabled ) {
$attrs['disabled'] = 'disabled';
}
@@ -61,7 +61,6 @@ function nprstory_publish_meta_box( $post ) {
)
);
echo ''; // end the "Send to NPR API" list item
-
?>
@@ -70,12 +69,12 @@ function nprstory_publish_meta_box( $post ) {
* this section is only enabled if "include for listening in NPR One" is checked!
* This section does not use https://developer.wordpress.org/reference/functions/touch_time/ because there does not seem to be a way to pass it a custom element
*/
-
+
$datetime = nprstory_get_post_expiry_datetime( $post );
?>
- Expires on:
+ Expires on:
%1$s',
@@ -123,7 +122,7 @@ function nprstory_publish_meta_box_assets() {
wp_register_script(
'nprstory_publish_meta_box_script',
NPRSTORY_PLUGIN_URL . 'assets/js/meta-box.js',
- array( 'jquery', 'jquery-ui-datepicker' ),
+ [ 'jquery', 'jquery-ui-datepicker' ],
null,
true
);
@@ -158,4 +157,4 @@ function nprstory_publish_meta_box_prompt( $post ) {
wp_kses_post( __( 'Your site administrator must set the NPR Story API Push URL in the NPR Story API plugin\'s settings in order to push to the NPR API.', 'nprapi' ) )
);
}
-}
+}
\ No newline at end of file
diff --git a/push_story.php b/push_story.php
index a964698..3b38cf8 100644
--- a/push_story.php
+++ b/push_story.php
@@ -2,7 +2,6 @@
/**
* Functions relating to pushing content to the NPR API
*/
-
require_once ( NPRSTORY_PLUGIN_DIR . 'classes/NPRAPIWordpress.php' );
/**
@@ -13,8 +12,8 @@
* @param Int $post_ID
* @param WP_Post $post
*/
-function nprstory_api_push ( $post_ID, $post ) {
- if ( ! current_user_can( 'publish_posts' ) ) {
+function nprstory_api_push( $post_ID, $post ) {
+ if ( !current_user_can( 'publish_posts' ) ) {
wp_die(
__( 'You do not have permission to publish posts, and therefore you do not have permission to push posts to the NPR API.', 'nprapi' ),
__( 'NPR Story API Error', 'nprapi' ),
@@ -30,7 +29,7 @@ function nprstory_api_push ( $post_ID, $post ) {
//if the push url isn't set, don't even try to push.
$push_url = get_option( 'ds_npr_api_push_url' );
- if ( ! empty ( $push_url ) ) {
+ if ( !empty ( $push_url ) ) {
// For now, only submit the sort of post that is the push post type, and then only if published
if ( $post->post_type != $push_post_type || $post->post_status != 'publish' ) {
return;
@@ -49,7 +48,7 @@ function nprstory_api_push ( $post_ID, $post ) {
$custom_content_meta = get_option( 'ds_npr_api_mapping_body' );
$body_field = $custom_content_meta;
- if ( ! empty( $custom_content_meta ) && $custom_content_meta !== '#NONE#' && in_array( $custom_content_meta, $post_metas, true ) ) {
+ if ( !empty( $custom_content_meta ) && $custom_content_meta !== '#NONE#' && in_array( $custom_content_meta, $post_metas, true ) ) {
$content = get_post_meta( $post->ID, $custom_content_meta, true );
}
}
@@ -67,9 +66,9 @@ function nprstory_api_push ( $post_ID, $post ) {
// Don't push stories to the NPR story API if they were originally pulled from the NPR Story API
$retrieved = get_post_meta( $post_ID, NPR_RETRIEVED_STORY_META_KEY, true );
if ( empty( $retrieved ) || $retrieved == 0 ) {
- $api->send_request( $api->create_NPRML( $post ), $post_ID);
+ $api->send_request( $api->create_NPRML( $post ), $post_ID );
} else {
- nprstory_error_log('Not pushing the story with post_ID ' . $post_ID . ' to the NPR Story API because it came from the API');
+ nprstory_error_log( 'Not pushing the story with post_ID ' . $post_ID . ' to the NPR Story API because it came from the API' );
}
}
}
@@ -81,8 +80,8 @@ function nprstory_api_push ( $post_ID, $post ) {
*
* @param unknown_type $post_ID
*/
-function nprstory_api_delete ( $post_ID ) {
- if ( ! current_user_can( 'delete_others_posts' ) ) {
+function nprstory_api_delete( $post_ID ) {
+ if ( !current_user_can( 'delete_others_posts' ) ) {
wp_die(
__('You do not have permission to delete posts in the NPR API. Users that can delete other users\' posts have that ability: administrators and editors.'),
__('NPR Story API Error'),
@@ -105,7 +104,7 @@ function nprstory_api_delete ( $post_ID ) {
$post = get_post( $post_ID );
//if the push url isn't set, don't even try to delete.
$push_url = get_option( 'ds_npr_api_push_url' );
- if ( $post->post_type == $push_post_type && ! empty( $push_url ) && ! empty( $api_id ) ) {
+ if ( $post->post_type == $push_post_type && !empty( $push_url ) && !empty( $api_id ) ) {
// For now, only submit regular posts, and only on publish.
if ( $post->post_type != 'post' || $post->post_status != 'publish' ) {
return;
@@ -113,10 +112,10 @@ function nprstory_api_delete ( $post_ID ) {
$api = new NPRAPIWordpress();
$retrieved = get_post_meta( $post_ID, NPR_RETRIEVED_STORY_META_KEY, true );
- if ( empty( $retrieved ) || $retrieved == 0) {
- $api->send_request( $api->create_NPRML( $post ), $post_ID);
+ if ( empty( $retrieved ) || $retrieved == 0 ) {
+ $api->send_request( $api->create_NPRML( $post ), $post_ID );
} else {
- nprstory_error_log('Pushing delete action to the NPR Story API for the story with post_ID ' . $post_ID );
+ nprstory_error_log( 'Pushing delete action to the NPR Story API for the story with post_ID ' . $post_ID );
$api->send_delete( $api_id );
}
}
@@ -140,13 +139,13 @@ function nprstory_api_delete ( $post_ID ) {
* define the option page for mapping fields
*/
function nprstory_push_add_field_mapping_page() {
- add_options_page(
- 'NPR API Push Field Mapping',
- 'NPR API Field Mapping',
- 'manage_options',
- 'ds_npr_api_push_mapping',
- 'nprstory_add_field_mapping_page'
- );
+ add_options_page(
+ 'NPR API Push Field Mapping',
+ 'NPR API Field Mapping',
+ 'manage_options',
+ 'ds_npr_api_push_mapping',
+ 'nprstory_add_field_mapping_page'
+ );
}
add_action( 'admin_menu', 'nprstory_push_add_field_mapping_page' );
@@ -165,24 +164,24 @@ function nprstory_api_push_mapping_callback() { }
* @param $post_type
*/
function nprstory_push_meta_keys( $post_type = 'post' ) {
- global $wpdb;
- $limit = (int) apply_filters( 'postmeta_form_limit', 30 );
- $query = "
- SELECT DISTINCT( $wpdb->postmeta.meta_key )
- FROM $wpdb->posts
- LEFT JOIN $wpdb->postmeta
- ON $wpdb->posts.ID = $wpdb->postmeta.post_id
- WHERE $wpdb->posts.post_type = '%s'
- AND $wpdb->postmeta.meta_key != ''
- AND $wpdb->postmeta.meta_key NOT RegExp '(^[_0-9]wp_.+$)'
- AND $wpdb->postmeta.meta_key NOT RegExp '(^[0-9]+$)'
- ";
- //AND $wpdb->postmeta.meta_key NOT RegExp '(^[_0-9].+$)'
- $keys = $wpdb->get_col( $wpdb->prepare( $query, $post_type ) );
- if ( $keys ) natcasesort( $keys );
-
- //set_transient('ds_npr_' . $post_type .'_meta_keys', $keys, 60*60*24); # 1 Day Expiration
- return $keys;
+ global $wpdb;
+ $limit = (int) apply_filters( 'postmeta_form_limit', 30 );
+ $query = "
+ SELECT DISTINCT( $wpdb->postmeta.meta_key )
+ FROM $wpdb->posts
+ LEFT JOIN $wpdb->postmeta
+ ON $wpdb->posts.ID = $wpdb->postmeta.post_id
+ WHERE $wpdb->posts.post_type = '%s'
+ AND $wpdb->postmeta.meta_key != ''
+ AND $wpdb->postmeta.meta_key NOT RegExp '(^[_0-9]wp_.+$)'
+ AND $wpdb->postmeta.meta_key NOT RegExp '(^[0-9]+$)'
+ ";
+ //AND $wpdb->postmeta.meta_key NOT RegExp '(^[_0-9].+$)'
+ $keys = $wpdb->get_col( $wpdb->prepare( $query, $post_type ) );
+ if ( $keys ) natcasesort( $keys );
+
+ //set_transient('ds_npr_' . $post_type .'_meta_keys', $keys, 60*60*24); # 1 Day Expiration
+ return $keys;
}
/**
@@ -192,13 +191,13 @@ function nprstory_push_meta_keys( $post_type = 'post' ) {
* @param $post_type default is 'post'
*/
function nprstory_get_post_meta_keys( $post_type = 'post' ) {
- //$cache = get_transient('ds_npr_' . $post_type .'_meta_keys');
- if ( ! empty( $cache ) ) {
- $meta_keys = $cache;
- } else {
- $meta_keys = nprstory_push_meta_keys( $post_type );
- }
- return $meta_keys;
+ //$cache = get_transient('ds_npr_' . $post_type .'_meta_keys');
+ if ( !empty( $cache ) ) {
+ $meta_keys = $cache;
+ } else {
+ $meta_keys = nprstory_push_meta_keys( $post_type );
+ }
+ return $meta_keys;
}
/**
@@ -223,7 +222,7 @@ function nprstory_validation_callback_select( $value ) {
* @see nprstory_settings_init
*/
function nprstory_validation_callback_url( $value ) {
- // because of the generic nature of this callback , it's not going to log anything, just do some sanitization
+ // because of the generic nature of this callback, it's not going to log anything, just do some sanitization
// this value must be suitable for use as a form value
return esc_attr( $value );
}
@@ -294,37 +293,37 @@ function nprstory_validation_callback_debug( $value ) {
}
/**
- Set up the fields for mapping custom meta fields to NRPML fields that we push to the API
-*/
+ * Set up the fields for mapping custom meta fields to NRPML fields that we push to the API
+ */
function nprstory_push_settings_init() {
- add_settings_section( 'ds_npr_push_settings', 'NPR API PUSH settings', 'nprstory_api_push_settings_callback', 'ds_npr_api_push_mapping' );
+ add_settings_section( 'ds_npr_push_settings', 'NPR API PUSH settings', 'nprstory_api_push_settings_callback', 'ds_npr_api_push_mapping' );
- add_settings_field( 'dp_npr_push_use_custom_map', 'Use Custom Settings', 'nprstory_api_use_custom_mapping_callback', 'ds_npr_api_push_mapping', 'ds_npr_push_settings' );
- register_setting( 'ds_npr_api_push_mapping', 'dp_npr_push_use_custom_map', 'nprstory_validation_callback_checkbox' );
+ add_settings_field( 'dp_npr_push_use_custom_map', 'Use Custom Settings', 'nprstory_api_use_custom_mapping_callback', 'ds_npr_api_push_mapping', 'ds_npr_push_settings' );
+ register_setting( 'ds_npr_api_push_mapping', 'dp_npr_push_use_custom_map', 'nprstory_validation_callback_checkbox' );
- add_settings_field( 'ds_npr_api_mapping_title', 'Story Title', 'nprstory_api_mapping_title_callback', 'ds_npr_api_push_mapping', 'ds_npr_push_settings' );
- register_setting( 'ds_npr_api_push_mapping', 'ds_npr_api_mapping_title', 'nprstory_validation_callback_select');
+ add_settings_field( 'ds_npr_api_mapping_title', 'Story Title', 'nprstory_api_mapping_title_callback', 'ds_npr_api_push_mapping', 'ds_npr_push_settings' );
+ register_setting( 'ds_npr_api_push_mapping', 'ds_npr_api_mapping_title', 'nprstory_validation_callback_select');
- add_settings_field( 'ds_npr_api_mapping_body', 'Story Body', 'nprstory_api_mapping_body_callback', 'ds_npr_api_push_mapping', 'ds_npr_push_settings' );
- register_setting( 'ds_npr_api_push_mapping', 'ds_npr_api_mapping_body' , 'nprstory_validation_callback_select');
+ add_settings_field( 'ds_npr_api_mapping_body', 'Story Body', 'nprstory_api_mapping_body_callback', 'ds_npr_api_push_mapping', 'ds_npr_push_settings' );
+ register_setting( 'ds_npr_api_push_mapping', 'ds_npr_api_mapping_body' , 'nprstory_validation_callback_select');
- add_settings_field( 'ds_npr_api_mapping_byline', 'Story Byline', 'nprstory_api_mapping_byline_callback', 'ds_npr_api_push_mapping', 'ds_npr_push_settings' );
- register_setting( 'ds_npr_api_push_mapping', 'ds_npr_api_mapping_byline' , 'nprstory_validation_callback_select');
+ add_settings_field( 'ds_npr_api_mapping_byline', 'Story Byline', 'nprstory_api_mapping_byline_callback', 'ds_npr_api_push_mapping', 'ds_npr_push_settings' );
+ register_setting( 'ds_npr_api_push_mapping', 'ds_npr_api_mapping_byline' , 'nprstory_validation_callback_select');
- add_settings_field( 'ds_npr_api_mapping_media_credit', 'Media Credit Field', 'nprstory_api_mapping_media_credit_callback', 'ds_npr_api_push_mapping', 'ds_npr_push_settings' );
- register_setting( 'ds_npr_api_push_mapping', 'ds_npr_api_mapping_media_credit' , 'nprstory_validation_callback_select');
+ add_settings_field( 'ds_npr_api_mapping_media_credit', 'Media Credit Field', 'nprstory_api_mapping_media_credit_callback', 'ds_npr_api_push_mapping', 'ds_npr_push_settings' );
+ register_setting( 'ds_npr_api_push_mapping', 'ds_npr_api_mapping_media_credit' , 'nprstory_validation_callback_select');
- add_settings_field( 'ds_npr_api_mapping_media_agency', 'Media Agency Field', 'nprstory_api_mapping_media_agency_callback', 'ds_npr_api_push_mapping', 'ds_npr_push_settings' );
- register_setting( 'ds_npr_api_push_mapping', 'ds_npr_api_mapping_media_agency' , 'nprstory_validation_callback_select');
- /** This will add the mapping for media distribution. But for now, hold off.
- add_settings_field( 'ds_npr_api_mapping_distribute_media', 'Distribute Media Field', 'nprstory_api_mapping_distribute_media_callback', 'ds_npr_api_push_mapping', 'ds_npr_push_settings' );
- register_setting( 'ds_npr_api_push_mapping', 'ds_npr_api_mapping_distribute_media' , 'nprstory_validation_callback_select');
+ add_settings_field( 'ds_npr_api_mapping_media_agency', 'Media Agency Field', 'nprstory_api_mapping_media_agency_callback', 'ds_npr_api_push_mapping', 'ds_npr_push_settings' );
+ register_setting( 'ds_npr_api_push_mapping', 'ds_npr_api_mapping_media_agency' , 'nprstory_validation_callback_select');
+ /* This will add the mapping for media distribution. But for now, hold off.
+ add_settings_field( 'ds_npr_api_mapping_distribute_media', 'Distribute Media Field', 'nprstory_api_mapping_distribute_media_callback', 'ds_npr_api_push_mapping', 'ds_npr_push_settings' );
+ register_setting( 'ds_npr_api_push_mapping', 'ds_npr_api_mapping_distribute_media' , 'nprstory_validation_callback_select');
- add_settings_field( 'ds_npr_api_mapping_distribute_media_polarity', 'Distribute Media Field Polarity', 'nprstory_api_mapping_distribute_media_polarity_callback', 'ds_npr_api_push_mapping', 'ds_npr_push_settings' );
- register_setting( 'ds_npr_api_push_mapping', 'ds_npr_api_mapping_distribute_media_polarity' , 'nprstory_validation_callback_select');
- //nprstory_api_mapping_distribute_media_polarity_callback
- *
- */
+ add_settings_field( 'ds_npr_api_mapping_distribute_media_polarity', 'Distribute Media Field Polarity', 'nprstory_api_mapping_distribute_media_polarity_callback', 'ds_npr_api_push_mapping', 'ds_npr_push_settings' );
+ register_setting( 'ds_npr_api_push_mapping', 'ds_npr_api_mapping_distribute_media_polarity' , 'nprstory_validation_callback_select');
+ //nprstory_api_mapping_distribute_media_polarity_callback
+ *
+ */
}
add_action( 'admin_init', 'nprstory_push_settings_init' );
@@ -332,15 +331,14 @@ function nprstory_push_settings_init() {
/**
* call back for push settings
*/
-function nprstory_api_push_settings_callback() {
-}
+function nprstory_api_push_settings_callback() { }
/**
* callback for use custom mapping checkbox
*/
-function nprstory_api_use_custom_mapping_callback(){
+function nprstory_api_use_custom_mapping_callback() {
$use_custom = get_option( 'dp_npr_push_use_custom_map' );
- $check_box_string = "Do Distribute or Do Not Distribute?
- Use this page to map your custom WordPress Meta fields to fields sent the NPR API. Clicking the Use Custom Settings checkbox will enable these mappings. If you wish to use the default mapping for a field, select — default — and we will use the obvious WordPress field.
+
Select for the Meta fields for the post type
+
+
+
+
Date: Mon, 24 Jan 2022 13:54:54 -0500
Subject: [PATCH 07/10] Generate WP posts with rich layout including multimedia
etc (#4)
* If 'layout' is available in the NPR Story API output, generate complex HTML to render any images, YouTube videos, Tweets, iframes, or JavaScript-based widgets within the post in the order they appeared on the NPR website.
* if using the NPR "layout" only sideload primary story image into WordPress Media Library instead of all referenced images in the story
* Adding help text for layout option
Updating the text for the layout checkbox explaining that it may require a ticket with NPR to update their Story API key to get the layout section.
* Further tweaks to the help text for the
---
classes/NPRAPIWordpress.php | 313 +++++++++++++++++++++++++++++++++++-
ds-npr-api.php | 4 +
settings.php | 19 +++
3 files changed, 335 insertions(+), 1 deletion(-)
diff --git a/classes/NPRAPIWordpress.php b/classes/NPRAPIWordpress.php
index 3a0f328..f378342 100644
--- a/classes/NPRAPIWordpress.php
+++ b/classes/NPRAPIWordpress.php
@@ -102,6 +102,7 @@ function update_posts_from_stories( $publish = TRUE, $qnum = false ) {
if ( empty( $pull_post_type ) ) {
$pull_post_type = 'post';
}
+ $use_npr_layout = !empty(get_option( 'dp_npr_query_use_layout' )) ? TRUE : FALSE;
$post_id = null;
@@ -138,7 +139,18 @@ function update_posts_from_stories( $publish = TRUE, $qnum = false ) {
} else {
$existing = $existing_status = null;
}
-
+
+ $npr_has_layout = FALSE;
+ $npr_has_video = FALSE;
+ if ($use_npr_layout) {
+ // get the "NPR layout" version if available and the "use rich layout" option checked in settings
+ $npr_layout = $this->get_body_with_layout($story);
+ if (!empty($npr_layout['body'])) {
+ $story->body = $npr_layout['body'];
+ $npr_has_layout = TRUE;
+ $npr_has_video = $npr_layout['has_video'];
+ }
+ }
//add the transcript
$story->body .= $this->get_transcript_body($story);
@@ -226,6 +238,8 @@ function update_posts_from_stories( $publish = TRUE, $qnum = false ) {
NPR_PUB_DATE_META_KEY => $story->pubDate->value,
NPR_STORY_DATE_MEATA_KEY => $story->storyDate->value,
NPR_LAST_MODIFIED_DATE_KEY => $story->lastModifiedDate->value,
+ NPR_STORY_HAS_LAYOUT_META_KEY => $npr_has_layout,
+ NPR_STORY_HAS_VIDEO_META_KEY => $npr_has_video,
);
//get audio
if ( isset($story->audio) ) {
@@ -263,10 +277,21 @@ function update_posts_from_stories( $publish = TRUE, $qnum = false ) {
* @param NPRMLEntity $story Story object created during import
* @param bool $created true if not pre-existing, false otherwise
*/
+
+ if ($npr_has_layout) {
+ // keep WP from stripping content from NPR posts
+ kses_remove_filters();
+ }
+
$args = apply_filters( 'npr_pre_insert_post', $args, $post_id, $story, $created );
$post_id = wp_insert_post( $args );
+ if ($npr_has_layout) {
+ // re-enable the built-in content stripping
+ kses_init_filters();
+ }
+
//now that we have an id, we can add images
//this is the way WP seems to do it, but we couldn't call media_sideload_image or media_ because that returned only the URL
//for the attachment, and we want to be able to set the primary image, so we had to use this method to get the attachment ID.
@@ -285,6 +310,12 @@ function update_posts_from_stories( $publish = TRUE, $qnum = false ) {
$attached_images = get_children( $image_args );
}
foreach ( (array) $story->image as $image ) {
+
+ // only sideload the primary image if using the npr layout
+ if ( ($image->type != 'primary') && $npr_has_layout ) {
+ continue;
+ }
+
$image_url = '';
//check the and then the crops, in this order "enlargement", "standard" if they don't exist, just get the image->src
if ( ! empty( $image->enlargement ) ) {
@@ -440,9 +471,20 @@ function update_posts_from_stories( $publish = TRUE, $qnum = false ) {
* @param int $post_id Post ID or NULL if no post ID.
* @param NPRMLEntity $story Story object created during import
*/
+
+ if ($npr_has_layout) {
+ // keep WP from stripping content from NPR posts
+ kses_remove_filters();
+ }
+
$args = apply_filters( 'npr_pre_update_post', $args, $post_id, $story );
$post_id = wp_insert_post( $args );
+
+ if ($npr_has_layout) {
+ // re-enable content stripping
+ kses_init_filters();
+ }
}
//set categories for story
@@ -664,4 +706,273 @@ function get_transcript_body( $story ) {
return $transcript_body;
}
+
+
+ /**
+ *
+ * This function will check a story to see if it has a layout object, if there is
+ * we'll format the body with any images, externalAssets, or htmlAssets inserted in the order they are in the layout
+ * and return an array of the transformed body and flags for what sort of elements are returned
+ *
+ * @param NPRMLEntity $story Story object created during import
+ * @return array with reconstructed body and flags describing returned elements
+ */
+ function get_body_with_layout( $story ) {
+ $returnary = array('body' => FALSE, 'has_layout' => FALSE, 'has_image' => FALSE, 'has_video' => FALSE, 'has_external' => FALSE);
+ $body_with_layout = "";
+ if ( ! empty( $story->layout ) ) {
+ // simplify the arrangement of the storytext object
+ $layoutarry = array();
+ foreach($story->layout->storytext as $type => $elements) {
+ if (!is_array($elements)) {
+ $elements = array($elements);
+ }
+ foreach ($elements as $element) {
+ $num = $element->num;
+ $reference = $element->refId;
+ if ($type == 'text') {
+ // only paragraphs don't have a refId, they use num instead
+ $reference = $element->paragraphNum;
+ }
+ $layoutarry[(int)$num] = array('type'=>$type, 'reference' => $reference);
+ }
+ }
+ ksort($layoutarry);
+ $returnary['has_layout'] = TRUE;
+
+ $paragraphs = array();
+ $num = 1;
+ foreach ($story->textWithHtml->paragraphs as $paragraph) {
+ $partext = (string) $paragraph->value;
+ $paragraphs[$num] = $partext;
+ $num++;
+ }
+
+ $storyimages = array();
+ if (isset($story->image) ) {
+ $storyimages_array = array();
+ if (isset($story->image->id)) {
+ $storyimages_array[] = $story->image;
+ } else {
+ // sometimes there are multiple objects
+ foreach ( (array) $story->image as $stryimage ) {
+ if (isset($stryimage->id)) {
+ $storyimages_array[] = $stryimage;
+ }
+ }
+ }
+ foreach ($storyimages_array as $image) {
+ $image_url = FALSE;
+ $is_portrait = FALSE;
+ if ( ! empty( $image->enlargement ) ) {
+ $image_url = $image->enlargement->src;
+ }
+ if ( ! empty( $image->crop )) {
+ if (!is_array( $image->crop ) ) {
+ $cropobj = $image->crop;
+ unset($image->crop);
+ $image->crop = array($cropobj);
+ }
+ foreach ( $image->crop as $crop ) {
+ if (empty($crop->primary)) {
+ continue;
+ }
+ $image_url = $crop->src;
+ if ($crop->type == 'custom' && ((int)$crop->height > (int)$crop->width)) {
+ $is_portrait = TRUE;
+ }
+ break;
+ }
+ }
+ if ( empty( $image_url ) && ! empty( $image->src ) ) {
+ $image_url = $image->src;
+ }
+ // add resizing to any npr-hosted image
+ if (strpos($image_url, 'media.npr.org')) {
+ // remove any existing querystring
+ if (strpos($image_url, '?')) {
+ $image_url = substr($image_url, 0, strpos($image_url, '?'));
+ }
+ $image_url .= !$is_portrait ? '?s=6' : '?s=12';
+ }
+ $storyimages[$image->id] = (array) $image;
+ $storyimages[$image->id]['image_url'] = $image_url;
+ $storyimages[$image->id]['is_portrait'] = $is_portrait;
+ }
+ }
+
+
+
+ $externalAssets = array();
+ if (isset($story->externalAsset) ) {
+ $externals_array = array();
+ if (isset($story->externalAsset->type)) {
+ $externals_array[] = $story->externalAsset;
+ } else {
+ // sometimes there are multiple objects
+ foreach ( (array) $story->externalAsset as $extasset ) {
+ if (isset($extasset->type)) {
+ $externals_array[] = $extasset;
+ }
+ }
+ }
+ foreach ($externals_array as $embed) {
+ $externalAssets[$embed->id] = (array) $embed;
+ }
+ }
+ $htmlAssets = array();
+ if (isset($story->htmlAsset) ) {
+ if (isset($story->htmlAsset->id)) {
+ $htmlAssets[$story->htmlAsset->id] = $story->htmlAsset->value;
+ } else {
+ // sometimes there are multiple objects
+ foreach ( (array) $story->htmlAsset as $hasset ) {
+ if (isset($hasset->id)) {
+ $htmlAssets[$hasset->id] = $hasset->value;
+ }
+ }
+ }
+ }
+
+ $multimedia = array();
+ if (isset($story->multimedia) ) {
+ $multims_array = array();
+ if (isset($story->multimedia->id)) {
+ $multims_array[] = $story->multimedia;
+ } else {
+ // sometimes there are multiple objects
+ foreach ( (array) $story->multimedia as $multim ) {
+ if (isset($multim->id)) {
+ $multims_array[] = $multim;
+ }
+ }
+ }
+ foreach($multims_array as $multim) {
+ $multimedia[$multim->id] = (array)$multim;
+ }
+ }
+
+ foreach ($layoutarry as $ordernum => $element) {
+ $reference = $element['reference'];
+ switch ($element['type']) {
+ case 'text':
+ if (!empty($paragraphs[$reference])) {
+ $body_with_layout .= "
" . $paragraphs[$reference] . "
\n";
+ }
+ break;
+ case 'staticHtml':
+ if (!empty($htmlAssets[$reference])) {
+ $body_with_layout .= $htmlAssets[$reference] . "\n\n";
+ $returnary['has_external'] = TRUE;
+ if (strpos($htmlAssets[$reference], 'jwplayer.com')) {
+ $returnary['has_video'] = TRUE;
+ }
+ }
+ break;
+ case 'externalAsset':
+ if (!empty($externalAssets[$reference])) {
+ $figclass = "wp-block-embed";
+ if (!empty( (string)$externalAssets[$reference]['type']) && strtolower((string)$externalAssets[$reference]['type']) == 'youtube') {
+ $returnary['has_video'] = TRUE;
+ $figclass .= " is-type-video";
+ }
+ $fightml = "\n";
+ $body_with_layout .= $fightml;
+ }
+ break;
+ case 'multimedia':
+ if (!empty($multimedia[$reference])) {
+ // check permissions
+ $perms = $multimedia[$reference]['permissions'];
+ if (($perms->embed->allow != false)) {
+ $fightml = "\n";
+ $body_with_layout .= $fightml;
+ }
+ }
+ break;
+ default:
+ // handles both 'list' and 'image' since it will reset the type and then assign the reference
+ if ($element['type'] == 'list') {
+ foreach ($storyimages as $image) {
+ if ($image['type'] != 'primary') {
+ continue;
+ }
+ $reference = $image['id'];
+ $element['type'] = 'image';
+ break;
+ }
+ }
+ if ($element['type'] != 'image') {
+ break;
+ }
+ if (!empty($storyimages[$reference])) {
+ $figclass = "wp-block-image size-large";
+ $thisimg = $storyimages[$reference];
+ $fightml = !empty( (string)$thisimg['image_url']) ? '' : '';
+ $figcaption = (!empty($fightml) && !empty( $thiscaption)) ? $thiscaption : '';
+ $cites = '';
+ foreach (array('producer', 'provider', 'copyright') as $item) {
+ $thisitem = trim( (string)$thisimg[$item] );
+ if (!empty($thisitem)) {
+ $cites .= !empty($cites) ? ' | ' . $thisitem : $thisitem;
+ }
+ }
+ $cites = !empty($cites) ? "$cites" : '';
+ $thiscaption .= $cites;
+ $figcaption = (!empty($fightml) && !empty( $thiscaption)) ? "$thiscaption" : '';
+ $fightml .= (!empty($fightml) && !empty($figcaption)) ? $figcaption : '';
+ $body_with_layout .= (!empty($fightml)) ? "\n\n" : '';
+ // make sure it doesn't get reused;
+ unset($storyimages[$reference]);
+ }
+ break;
+ }
+ }
+
+ }
+ $returnary['body']= $body_with_layout;
+
+ return $returnary;
+ }
+
+
+
+
+
+
+
+
+
}
diff --git a/ds-npr-api.php b/ds-npr-api.php
index a2a4282..45053f8 100644
--- a/ds-npr-api.php
+++ b/ds-npr-api.php
@@ -32,6 +32,7 @@
define( 'NPR_BYLINE_LINK_META_KEY', 'npr_byline_link' );
define( 'NPR_MULTI_BYLINE_META_KEY', 'npr_multi_byline' );
define( 'NPR_IMAGE_GALLERY_META_KEY', 'npr_image_gallery');
+define( 'NPR_HTML_ASSETS_META_KEY', 'npr_html_assets');
define( 'NPR_AUDIO_META_KEY', 'npr_audio');
define( 'NPR_AUDIO_M3U_META_KEY', 'npr_audio_m3u');
define( 'NPR_PUB_DATE_META_KEY', 'npr_pub_date');
@@ -43,6 +44,9 @@
define( 'NPR_IMAGE_AGENCY_META_KEY', 'npr_image_agency');
define( 'NPR_IMAGE_CAPTION_META_KEY', 'npr_image_caption');
+define( 'NPR_STORY_HAS_LAYOUT_META_KEY', 'npr_has_layout');
+define( 'NPR_STORY_HAS_VIDEO_META_KEY', 'npr_has_video');
+
define( 'NPR_PUSH_STORY_ERROR', 'npr_push_story_error');
define( 'NPR_MAX_QUERIES', 10 );
diff --git a/settings.php b/settings.php
index 7778224..dd424c1 100644
--- a/settings.php
+++ b/settings.php
@@ -91,9 +91,15 @@ function nprstory_settings_init() {
add_settings_field( 'dp_npr_query_run_multi', 'Run the queries on saving changes', 'nprstory_query_run_multi_callback', 'ds_npr_api_get_multi_settings', 'ds_npr_api_get_multi_settings' );
register_setting( 'ds_npr_api_get_multi_settings', 'dp_npr_query_run_multi' , 'nprstory_validation_callback_checkbox');
+
add_settings_field( 'dp_npr_query_multi_cron_interval', 'Interval to run Get Multi cron', 'nprstory_query_multi_cron_interval_callback', 'ds_npr_api_get_multi_settings', 'ds_npr_api_get_multi_settings' );
register_setting( 'ds_npr_api_get_multi_settings', 'dp_npr_query_multi_cron_interval', 'intval' );
+
+ add_settings_field( 'dp_npr_query_use_layout', 'Use rich layout on pulled posts if available', 'nprstory_query_use_layout_callback', 'ds_npr_api_get_multi_settings', 'ds_npr_api_get_multi_settings' );
+ register_setting( 'ds_npr_api_get_multi_settings', 'dp_npr_query_use_layout' , 'nprstory_validation_callback_checkbox');
+
+
add_settings_field( 'ds_npr_pull_post_type', 'NPR Pull Post Type', 'nprstory_pull_post_type_callback', 'ds_npr_api', 'ds_npr_api_settings' );
register_setting( 'ds_npr_api', 'ds_npr_pull_post_type', 'nprstory_validation_callback_select' );
@@ -151,6 +157,19 @@ function nprstory_query_run_multi_callback() {
wp_nonce_field( 'nprstory_nonce_ds_npr_query_run_multi', 'nprstory_nonce_ds_npr_query_run_multi_name', true, true );
}
+function nprstory_query_use_layout_callback() {
+ $use_layout = get_option('dp_npr_query_use_layout');
+ $check_box_string = "If 'layout' is available in the NPR Story API output for your key, checking this box will import posts with more complex HTML to render any images, YouTube videos, Tweets, iframes, or JavaScript-based widgets within the post in the order they appeared on the NPR website. Only the 'primary' image for the story will be sideloaded into the Media Library, all other images will be linked from NPR. If 'layout' is not available in your API results and you want to use this feature, open a ticket with NPR requesting 'layout permissions' for your Story API Key, and include the key in the ticket request. CAUTION: Checking this box will disables the normal 'wp_kses' filtering for imported posts that prevents any JavaScript from being included in the post. We assume that NPR Story API posts will not have malicious scripts.
If 'layout' is available in the NPR Story API output for your key, checking this box will import posts with more complex HTML to render any images, YouTube videos, Tweets, iframes, or JavaScript-based widgets within the post in the order they appeared on the NPR website. Only the 'primary' image for the story will be sideloaded into the Media Library, all other images will be linked from NPR.
If 'layout' is not available in your API results and you want to use this feature, open a ticket with NPR requesting 'layout permissions' for your Story API Key, and include the key in the ticket request.
CAUTION: Checking this box will disables the normal 'wp_kses' filtering for imported posts that prevents any JavaScript from being included in the post. We assume that NPR Story API posts will not have malicious scripts.