From c5c96b2f315ee71a6356b1fa9b0eba280c99ff5c Mon Sep 17 00:00:00 2001
From: Jirrod Glynn
Date: Tue, 26 Apr 2016 14:23:28 -0500
Subject: [PATCH 1/9] Fixed php warning bugs that show when debugging is turned
on.
split() is deprecated. Check if variables are objects. Functions follow strict standards.
---
classes/NPRAPI.php | 10 +++++++---
classes/NPRAPIWordpress.php | 6 +++---
2 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/classes/NPRAPI.php b/classes/NPRAPI.php
index 4d0747e..4de4a27 100644
--- a/classes/NPRAPI.php
+++ b/classes/NPRAPI.php
@@ -45,7 +45,9 @@ function prepare_request() {
}
- function send_request() {
+ // Edit - Function has no parameters. Without parameters, throws error
+ // Strict standards: Declaration of NPRAPIWordpress::send_request() should be compatible with NPRAPI::send_request()
+ function send_request($nprml, $post_ID ) {
}
@@ -61,7 +63,9 @@ function flatten() {
}
- function create_NPRML() {
+ // Edit - Function has no parameters. Without parameters, throws error
+ // Strict standards: Declaration of NPRAPIWordpress::create_NPRML() should be compatible with NPRAPI::create_NPRML()
+ function create_NPRML( $post ) {
}
@@ -146,7 +150,7 @@ function parse() {
//if the query didn't have a sort parameter, reverse the order so that we end up with
//stories in reverse-chron order.
//there are no params and 'sort=' is not in the URL
- if (empty($this->request->params) && !stristr($this->request->url, 'sort=')){
+ if (empty($this->request->params) && isset($this->request->url) && !stristr($this->request->url, 'sort=')){
$this->stories = array_reverse($this->stories);
}
//there are params, and sort is not one of them
diff --git a/classes/NPRAPIWordpress.php b/classes/NPRAPIWordpress.php
index 41d07c5..b2bfad9 100644
--- a/classes/NPRAPIWordpress.php
+++ b/classes/NPRAPIWordpress.php
@@ -56,10 +56,10 @@ function query_by_url( $url ) {
//fill out the $this->request->param array so we can know what params were sent
$parsed_url = parse_url( $url );
if ( ! empty( $parsed_url['query'] ) ) {
- $parms = split( '&', $parsed_url['query'] );
+ $parms = explode( '&', $parsed_url['query'] );
if ( ! empty( $params ) ){
foreach ( $params as $p ){
- $attrs = split( '=', $p );
+ $attrs = explode( '=', $p );
$this->request->param[$attrs[0]] = $attrs[1];
}
}
@@ -511,7 +511,7 @@ function get_transcript_body( $story ) {
$transcript_body = "";
if ( ! empty( $story->transcript ) ) {
foreach ( $story->transcript as $transcript ) {
- if ( $transcript->type == 'api' ) {
+ if ( is_object($transcript) && $transcript->type == 'api' ) {
$response = wp_remote_get( $transcript->value );
if ( !is_wp_error( $response ) ) {
$transcript_body .= "
Transcript :
";
From 4dc1c4095e0cee48b4b10129810ab74f5e07d448 Mon Sep 17 00:00:00 2001
From: Jirrod Glynn
Date: Tue, 26 Apr 2016 16:19:19 -0500
Subject: [PATCH 2/9] Fixed static call to object
Static class name provided inside an object, instead of reference to object.
---
get_stories.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/get_stories.php b/get_stories.php
index a4e823b..b85daf6 100644
--- a/get_stories.php
+++ b/get_stories.php
@@ -127,6 +127,7 @@ function DS_NPR_API() {
}
add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
add_action( 'load-posts_page_get-npr-stories', array( 'DS_NPR_API', 'load_page_hook' ) );
+ add_action( 'load-posts_page_get-npr-stories', array( $this, 'load_page_hook' ) );
}
function admin_menu() {
From a589116f8c926879d96b76a82e0b38e51c2d60e7 Mon Sep 17 00:00:00 2001
From: Jirrod Glynn
Date: Tue, 26 Apr 2016 16:32:12 -0500
Subject: [PATCH 3/9] Fixed error undefined index
---
push_story.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/push_story.php b/push_story.php
index 3a5b4dd..1c81d57 100644
--- a/push_story.php
+++ b/push_story.php
@@ -421,6 +421,6 @@ function save_send_to_nprone( $post_ID ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return false;
if ( ! current_user_can( 'edit_page', $post_ID ) ) return false;
if ( empty( $post_ID ) ) return false;
- $value = ($_POST['send_to_nprone']) ? 1 : 0;
+ $value = isset($_POST['send_to_nprone']) and ($_POST['send_to_nprone']) ? 1 : 0;
update_post_meta( $post_ID, '_send_to_nprone', $value );
}
\ No newline at end of file
From 087710ad16c990425edd9f4b536aaed5bd627539 Mon Sep 17 00:00:00 2001
From: Jirrod Glynn
Date: Wed, 27 Apr 2016 12:04:11 -0500
Subject: [PATCH 4/9] PHP debug error fixes
Make sure object is an object before checking if it is empty, same with arrays. Also added into get_stories a change that should have gone with last commit.
---
classes/NPRAPI.php | 5 +++--
get_stories.php | 1 -
push_story.php | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/classes/NPRAPI.php b/classes/NPRAPI.php
index 4de4a27..bf9cabd 100644
--- a/classes/NPRAPI.php
+++ b/classes/NPRAPI.php
@@ -85,12 +85,13 @@ function parse() {
$object = simplexml_load_string($xml);
$this->add_simplexml_attributes($object, $this);
- if (!empty($object->message)) {
+ if ( isset( $object->message ) && !empty($object->message)) {
+ $this->message = new StdClass;
$this->message->id = $this->get_attribute($object->message, 'id');
$this->message->level = $this->get_attribute($object->message, 'level');
}
- if (!empty($object->list->story)) {
+ if ( isset($object->list->story ) && !empty($object->list->story)) {
foreach ($object->list->story as $story) {
$parsed = new NPRMLEntity();
$this->add_simplexml_attributes($story, $parsed);
diff --git a/get_stories.php b/get_stories.php
index b85daf6..98689d5 100644
--- a/get_stories.php
+++ b/get_stories.php
@@ -126,7 +126,6 @@ function DS_NPR_API() {
return;
}
add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
- add_action( 'load-posts_page_get-npr-stories', array( 'DS_NPR_API', 'load_page_hook' ) );
add_action( 'load-posts_page_get-npr-stories', array( $this, 'load_page_hook' ) );
}
diff --git a/push_story.php b/push_story.php
index 1c81d57..21b6b92 100644
--- a/push_story.php
+++ b/push_story.php
@@ -66,7 +66,7 @@ function npr_delete ( $post_ID ) {
}
$api_id_meta = get_post_meta( $post_ID, NPR_STORY_ID_META_KEY );
- $api_id = $api_id_meta[0];
+ $api_id = is_array($api_id_meta) && !empty($api_id_meta) ? $api_id_meta[0] : false;
$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' );
From 15e954e1f4d263af1195145b007057405f3baeb9 Mon Sep 17 00:00:00 2001
From: Jirrod Glynn
Date: Wed, 27 Apr 2016 13:54:47 -0500
Subject: [PATCH 5/9] More PHP error fixes
Object and variable checking conditionals
---
classes/NPRAPIWordpress.php | 37 ++++++++++++++++++++-----------------
1 file changed, 20 insertions(+), 17 deletions(-)
diff --git a/classes/NPRAPIWordpress.php b/classes/NPRAPIWordpress.php
index b2bfad9..0af462d 100644
--- a/classes/NPRAPIWordpress.php
+++ b/classes/NPRAPIWordpress.php
@@ -168,22 +168,25 @@ function update_posts_from_stories( $publish = TRUE ) {
}
//construct delimited string if there are multiple bylines
- if ( is_array( $story->byline ) && !empty( $story->byline ) ) {
+ if ( isset( $story->byline ) && is_array( $story->byline ) && !empty( $story->byline ) ) {
$i = 0;
foreach ( $story->byline as $single ) {
- if ( $i==0 ) {
- $multi_by_line .= $single->name->value; //builds multi byline string without delimiter on first pass
- } else {
- $multi_by_line .= '|' . $single->name->value ; //builds multi byline string with delimiter
- }
- $by_line = $single->name->value; //overwrites so as to save just the last byline for previous single byline themes
-
- if ( ! empty( $single->link ) ) {
- foreach( $single->link as $link ) {
- if ($link->type == 'html' ) {
- $byline_link = $link->value; //overwrites so as to save just the last byline link for previous single byline themes
- $multi_by_line .= '~' . $link->value; //builds multi byline string links
- }
+ if( is_object( $single ) ) {
+ if( isset( $single->name ) ) {
+ if ( $i==0 ) {
+ $multi_by_line .= $single->name->value; //builds multi byline string without delimiter on first pass
+ } else {
+ $multi_by_line .= '|' . $single->name->value ; //builds multi byline string with delimiter
+ }
+ $by_line = $single->name->value; //overwrites so as to save just the last byline for previous single byline themes
+ }
+ if ( isset( $single->link ) && ! empty( $single->link ) ) {
+ foreach( $single->link as $link ) {
+ if ($link->type == 'html' ) {
+ $byline_link = $link->value; //overwrites so as to save just the last byline link for previous single byline themes
+ $multi_by_line .= '~' . $link->value; //builds multi byline string links
+ }
+ }
}
}
$i++;
@@ -252,16 +255,16 @@ function update_posts_from_stories( $publish = TRUE ) {
if ( ! empty( $image->enlargement ) ) {
$image_url = $image->enlargement->src;
} else {
- if ( ! empty( $image->crop ) ) {
+ if ( is_object( $image->crop ) && ! empty( $image->crop ) ) {
foreach ( $image->crop as $crop ) {
- if ( $crop->type == 'enlargement' ) {
+ if ( isset( $crop->type ) && $crop->type == 'enlargement' ) {
$image_url = $crop->src;
continue;
}
}
if ( empty( $image_url ) ) {
foreach ( $image->crop as $crop ) {
- if ( $crop->type == 'standard' ) {
+ if ( isset( $crop->type ) && $crop->type == 'standard' ) {
$image_url = $crop->src;
continue;
}
From f8ca82ae6bcf60cf00367f3b862d3677294ec185 Mon Sep 17 00:00:00 2001
From: Jirrod Glynn
Date: Wed, 27 Apr 2016 14:47:32 -0500
Subject: [PATCH 6/9] Adds tags to multi importer!
Adds the ability to add tags to stories imported with the NPR API Get Multi tool.
---
classes/NPRAPIWordpress.php | 8 +++++++-
get_stories.php | 2 +-
settings.php | 14 +++++++++++++-
3 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/classes/NPRAPIWordpress.php b/classes/NPRAPIWordpress.php
index 0af462d..5034f2c 100644
--- a/classes/NPRAPIWordpress.php
+++ b/classes/NPRAPIWordpress.php
@@ -92,8 +92,10 @@ function query_by_url( $url ) {
* available from the NPR API if the pubDate on the API is after the pubDate originally stored locally.
*
* @param unknown_type $publish
+ * @param bool|num $qnum - the query number of story being updated
+ * primarily used for adding tags to new stories
*/
- function update_posts_from_stories( $publish = TRUE ) {
+ function update_posts_from_stories( $publish = TRUE, $qnum = false ) {
$pull_post_type = get_option( 'ds_npr_pull_post_type' );
if ( empty( $pull_post_type ) ) {
$pull_post_type = 'post';
@@ -148,6 +150,10 @@ function update_posts_from_stories( $publish = TRUE ) {
'post_type' => $pull_post_type,
'post_date' => $post_date,
);
+
+ if( false !== $qnum ) {
+ $args['tags_input'] = get_option('ds_npr_query_tags_'.$qnum);
+ }
//check the last modified date and pub date (sometimes the API just updates the pub date), if the story hasn't changed, just go on
if ( $post_mod_date != strtotime( $story->lastModifiedDate->value ) || $post_pub_date != strtotime( $story->pubDate->value ) ) {
diff --git a/get_stories.php b/get_stories.php
index 98689d5..80a74c6 100644
--- a/get_stories.php
+++ b/get_stories.php
@@ -55,7 +55,7 @@ public static function ds_npr_story_cron_pull() {
if ( $pub_option == 'Publish' ) {
$pub_flag = TRUE;
}
- $story = $api->update_posts_from_stories($pub_flag);
+ $story = $api->update_posts_from_stories($pub_flag, $i);
} else {
if ( empty($story) ) {
error_log('Not going to save story. Return from query='. $query_string .', we got an error='.$api->message->id. ' error');
diff --git a/settings.php b/settings.php
index 8198944..115d910 100644
--- a/settings.php
+++ b/settings.php
@@ -69,6 +69,10 @@ function ds_npr_settings_init() {
//ds_npr_query_publish_
add_settings_field( 'ds_npr_query_publish_' . $i, 'Publish Stories ' . $i, 'ds_npr_api_query_publish_callback', 'ds_npr_api_get_multi_settings', 'ds_npr_api_get_multi_settings', $i );
register_setting( 'ds_npr_api_get_multi_settings', 'ds_npr_query_publish_' . $i );
+
+ // add tag(s) to imported stories
+ add_settings_field( 'ds_npr_query_tags_' . $i, 'Add Tags ' . $i, 'ds_npr_api_query_tags_callback', 'ds_npr_api_get_multi_settings', 'ds_npr_api_get_multi_settings', $i );
+ register_setting( 'ds_npr_api_get_multi_settings', 'ds_npr_query_tags_' . $i );
}
add_settings_field( 'dp_npr_query_run_multi', 'Run the queries on saving changes', 'dp_npr_query_run_multi_callback', 'ds_npr_api_get_multi_settings', 'ds_npr_api_get_multi_settings' );
@@ -156,7 +160,7 @@ function ds_npr_api_query_publish_callback( $i ){
$option_string .= "value='" . esc_attr($key) . "'>" . esc_html($key) . " ";
echo $option_string;
}
- echo "