Skip to content
This repository has been archived by the owner on Mar 26, 2021. It is now read-only.

Fixed php warning bugs that show when debugging is turned on #16

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
15 changes: 10 additions & 5 deletions classes/NPRAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {

}

Expand All @@ -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 ) {

}

Expand All @@ -81,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);
Expand Down Expand Up @@ -146,7 +151,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
Expand Down
53 changes: 32 additions & 21 deletions classes/NPRAPIWordpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -148,6 +150,12 @@ function update_posts_from_stories( $publish = TRUE ) {
'post_type' => $pull_post_type,
'post_date' => $post_date,
);

if( false !== $qnum ) {
$args['tags_input'] = 'NPR, ' . get_option('ds_npr_query_tags_'.$qnum);
} else {
$args['tags_input'] = 'NPR';
}
//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 ) ) {

Expand All @@ -168,22 +176,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++;
Expand Down Expand Up @@ -252,16 +263,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;
}
Expand Down Expand Up @@ -511,7 +522,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 .= "<p><strong>Transcript :</strong><p>";
Expand Down
4 changes: 2 additions & 2 deletions ds-npr-api.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
/**
* Plugin Name: WP DS NPR API
* Plugin Name: KCPT NPR API Fork
* Description: A collection of tools for reusing content from NPR.org supplied by Digital Services.
* Version: 1.5.2
* Author: Kevin Moylan
* Author: Kevin Moylan | Editied by KCPT
* License: GPLv2
*/
/*
Expand Down
4 changes: 2 additions & 2 deletions get_stories.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -126,7 +126,7 @@ 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' ) );
}

function admin_menu() {
Expand Down
4 changes: 2 additions & 2 deletions push_story.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down Expand Up @@ -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 );
}
16 changes: 14 additions & 2 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function ds_npr_settings_init() {

add_settings_section( 'ds_npr_api_get_multi_settings', 'NPR API multiple get settings', 'ds_npr_api_get_multi_settings_callback', 'ds_npr_api_get_multi_settings' );

add_settings_field( 'ds_npr_num', 'Number of things to get', 'ds_npr_api_num_multi_callback', 'ds_npr_api_get_multi_settings', 'ds_npr_api_get_multi_settings' );
add_settings_field( 'ds_npr_num', 'Number of queries to run', 'ds_npr_api_num_multi_callback', 'ds_npr_api_get_multi_settings', 'ds_npr_api_get_multi_settings' );
register_setting( 'ds_npr_api_get_multi_settings', 'ds_npr_num' );
$num = get_option( 'ds_npr_num' );
if ( empty($num) ) {
Expand All @@ -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' );
Expand Down Expand Up @@ -156,7 +160,7 @@ function ds_npr_api_query_publish_callback( $i ){
$option_string .= "value='" . esc_attr($key) . "'>" . esc_html($key) . " </option>";
echo $option_string;
}
echo "</select> </div><p><hr></p>";
echo "</select> </div>";
}

function ds_npr_api_query_callback( $i ) {
Expand All @@ -165,6 +169,14 @@ function ds_npr_api_query_callback( $i ) {
echo "<input type='text' value='$option' name='$name' style='width: 300px;' />";
}

function ds_npr_api_query_tags_callback( $i ) {
$name = 'ds_npr_query_tags_' . $i;
$option = get_option( $name );

echo "<input type='text' value='$option' name='$name' style='width: 300px;' /> <p> Add tag(s) to each story pulled from NPR (comma separated). The NPR tag is added automatically. </p>";
echo "<p><hr></p>";
}

function ds_npr_api_num_multi_callback() {
$option = get_option('ds_npr_num');
echo "<input type='text' value='$option' name='ds_npr_num' style='width: 30px;' /> <p> Increase the number of queries by changing the number in the field above.";
Expand Down