Skip to content
No description or website provided.
PHP
Find file
Latest commit 0b6b6ca Aug 11, 2015 @CrookedNumber CrookedNumber Trying to conform all files to the Wordpress coding standard.
diff --git a/classes/NPRAPIWordpress.php b/classes/NPRAPIWordpress.php
index a2736ef..41d07c5 100644
--- a/classes/NPRAPIWordpress.php
+++ b/classes/NPRAPIWordpress.php
@@ -6,8 +6,8 @@
  * Defines a class for NPRML creation/transmission and retreival/parsing
  * Unlike NPRAPI class, NPRAPIDrupal is drupal-specific
  */
-require_once ('NPRAPI.php');
-require_once ('nprml.php');
+require_once( 'NPRAPI.php' );
+require_once( 'nprml.php' );

 class NPRAPIWordpress extends NPRAPI {

@@ -24,14 +24,14 @@ class NPRAPIWordpress extends NPRAPI {
    * @param string $base
    *   The base URL of the request (i.e., HTTP://EXAMPLE.COM/path) with no trailing slash.
    */
-  function request($params = array(), $path = 'query', $base = self::NPRAPI_PULL_URL) {
+  function request( $params = array(), $path = 'query', $base = self::NPRAPI_PULL_URL ) {

     $this->request->params = $params;
     $this->request->path = $path;
     $this->request->base = $base;

     $queries = array();
-    foreach ($this->request->params as $k => $v) {
+    foreach ( $this->request->params as $k => $v ) {
       $queries[] = "$k=$v";
     }
     $request_url = $this->request->base . '/' . $this->request->path . '?' . implode('&', $queries);
@@ -45,50 +45,46 @@ class NPRAPIWordpress extends NPRAPI {
    *
    * @param string $url -- the full url to query.
    */
-  function query_by_url($url){
-  	//check to see if the API key is included, if not, add the one from the options
-  	if (!stristr($url, 'apiKey=')){
-  		$url .= '&apiKey='. get_option( 'ds_npr_api_key' );
-  	}
+    function query_by_url( $url ) {
+        //check to see if the API key is included, if not, add the one from the options
+        if ( ! stristr( $url, 'apiKey=' ) ) {
+            $url .= '&apiKey='. get_option( 'ds_npr_api_key' );
+        }

-  	$this->request->request_url = $url;
+        $this->request->request_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']);
-	  	if (!empty($params)){
-		  	foreach ($params as $p){
-		  		$attrs = split('=', $p);
-	  			$this->request->param[$attrs[0]] = $attrs[1];
-		  	}
-	  	}
-  	}
-    $response = wp_remote_get( $url );
-    if( !is_wp_error( $response ) ) {
-	    $this->response = $response;
-	    if ($response['response']['code'] == self::NPRAPI_STATUS_OK) {
-
-	      if ($response['body']) {
-	        $this->xml = $response['body'];
-	      }
-	      else {
-	        $this->notice[] = t('No data available.');
-	      }
-	    }
-	    else {
-	    	ds_npr_show_message('An error occurred pulling your story from the NPR API.  The API responded with message ='. $response['response']['message'], TRUE );
-	    }
-    }
-    else {
-    	$error_text = '';
-    	if (!empty($response->errors['http_request_failed'][0])){
-	    	$error_text = '<br> HTTP Error response =  '. $response->errors['http_request_failed'][0];
-    	}
-    	ds_npr_show_message('Error pulling story for url='.$url . $error_text, TRUE);
-    	error_log('Error retrieving story for 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'] );
+            if ( ! empty( $params ) ){
+                foreach ( $params as $p ){
+                    $attrs = split( '=', $p );
+                    $this->request->param[$attrs[0]] = $attrs[1];
+                }
+            }
+        }
+        $response = wp_remote_get( $url );
+        if ( !is_wp_error( $response ) ) {
+            $this->response = $response;
+            if ( $response['response']['code'] == self::NPRAPI_STATUS_OK ) {
+                if ( $response['body'] ) {
+                    $this->xml = $response['body'];
+                } else {
+                    $this->notice[] = t( 'No data available.' );
+                }
+            } else {
+                ds_npr_show_message( 'An error occurred pulling your story from the NPR API.  The API responded with message =' . $response['response']['message'], TRUE );
+	       }
+        } else {
+            $error_text = '';
+            if ( ! empty( $response->errors['http_request_failed'][0] ) ) {
+                $error_text = '<br> HTTP Error response =  '. $response->errors['http_request_failed'][0];
+            }
+            ds_npr_show_message( 'Error pulling story for url='.$url . $error_text, TRUE );
+            error_log( 'Error retrieving story for url='.$url );
+        }
     }
-  }

   /**
    *
@@ -97,324 +93,313 @@ class NPRAPIWordpress extends NPRAPI {
    *
    * @param unknown_type $publish
    */
-	function update_posts_from_stories($publish = TRUE ) {
-		$pull_post_type = get_option('ds_npr_pull_post_type');;
-		if (empty($pull_post_type)){
+    function update_posts_from_stories( $publish = TRUE ) {
+		$pull_post_type = get_option( 'ds_npr_pull_post_type' );
+		if ( empty( $pull_post_type ) ) {
 			$pull_post_type = 'post';
 		}

-		if (!empty($this->stories)){
+		if ( ! empty( $this->stories ) ) {
 			$single_story = TRUE;
-			if (sizeof($this->stories) > 1){
+			if ( sizeof( $this->stories ) > 1) {
 				$single_story = FALSE;
 			}
-			foreach ($this->stories as $story) {
-
-				$exists = new WP_Query( array( 'meta_key' => NPR_STORY_ID_META_KEY,
-	                                       'meta_value' => $story->id,
-	        															 'post_type' => $pull_post_type,
-	        															 'post_status' => 'any' ));
-
-	        //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;
-
-	        if ( $exists->found_posts ) {
-	            $existing = $exists->post;
-	            $post_id = $existing->ID;
-	            $existing_status = $exists->posts[0]->post_status;
-	            $post_mod_date_meta = get_post_meta($existing->ID, NPR_LAST_MODIFIED_DATE_KEY);
-	            if (!empty($post_mod_date_meta[0])){
-		            $post_mod_date = strtotime($post_mod_date_meta[0]);
-	            }
-	            $post_pub_date_meta = get_post_meta($existing->ID, NPR_PUB_DATE_META_KEY);
-	            if (!empty($post_pub_date_meta[0])){
-	            	$post_pub_date = strtotime($post_pub_date_meta[0]);
-	            }
-	        }
-	        else {
-	            $existing = null;
-	        }
+			foreach ( $this->stories as $story ) {
+				$exists = new WP_Query(
+				    array( 'meta_key' => NPR_STORY_ID_META_KEY,
+                        'meta_value' => $story->id,
+                        'post_type' => $pull_post_type,
+                        'post_status' => 'any'
+                    )
+                );
+
+                //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;
+
+                if ( $exists->found_posts ) {
+                    $existing = $exists->post;
+                    $post_id = $existing->ID;
+                    $existing_status = $exists->posts[0]->post_status;
+                    $post_mod_date_meta = get_post_meta( $existing->ID, NPR_LAST_MODIFIED_DATE_KEY );
+                    if ( ! empty( $post_mod_date_meta[0] ) ) {
+                        $post_mod_date = strtotime( $post_mod_date_meta[0] );
+                    }
+                    $post_pub_date_meta = get_post_meta( $existing->ID, NPR_PUB_DATE_META_KEY );
+                    if ( ! empty( $post_pub_date_meta[0] ) ) {
+                        $post_pub_date = strtotime($post_pub_date_meta[0]);
+                    }
+                } else {
+                    $existing = null;
+                }

-	        //add the transcript
+                //add the transcript
+                $story->body .= $this->get_transcript_body($story);

-					$story->body .= $this->get_transcript_body($story);
-
-					$story_date = new DateTime($story->storyDate->value);
-					$post_date = $story_date->format('Y-m-d H:i:s');
+                $story_date = new DateTime($story->storyDate->value);
+				$post_date = $story_date->format('Y-m-d H:i:s');

-	        //set the story as draft, so we don't try ingesting it
-	        $args = array(
-	            'post_title'   => $story->title,
-	            'post_excerpt' => $story->teaser,
-	            'post_content' => $story->body,
+                //set the story as draft, so we don't try ingesting it
+                $args = array(
+                    'post_title'   => $story->title,
+                    'post_excerpt' => $story->teaser,
+                    'post_content' => $story->body,
 	        		'post_status'  => 'draft',
 	        		'post_type'    => $pull_post_type,
-	        		'post_date'		 => $post_date,
-	        );
-					//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)) ){
+                    'post_date'    => $post_date,
+                );
+				//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 ) ) {

-						$by_line = '';
-		        $byline_link = '';
-		        $multi_by_line = '';
-		        //continue to save single byline into npr_byline as is, but also set multi to false
-		        if (isset($story->byline->name->value)){ //fails if there are multiple bylines or no bylines
-		        	$by_line = $story->byline->name->value;
-		        	$multi_by_line = 0; //only single author, set multi to false
-		        	if (!empty($story->byline->link)){
-		        		foreach($story->byline->link as $link){
-		        			if ($link->type == 'html'){
-		        				$byline_link = $link->value;
-		        			}
-		        		}
-		        	}
-					 }
+                    $by_line = '';
+                    $byline_link = '';
+                    $multi_by_line = '';
+                    //continue to save single byline into npr_byline as is, but also set multi to false
+                    if ( isset( $story->byline->name->value ) ) { //fails if there are multiple bylines or no bylines
+                        $by_line = $story->byline->name->value;
+                        $multi_by_line = 0; //only single author, set multi to false
+                        if ( ! empty( $story->byline->link ) ) {
+                            foreach( $story->byline->link as $link ) {
+                                if ( $link->type == 'html' ) {
+                                    $byline_link = $link->value;
+                                }
+                            }
+                        }
+                    }

-						//construct delimited string if there are multiple bylines
-		        if(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
+                    //construct delimited string if there are multiple bylines
+                    if ( 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
-										}
-		        			}
-			        	}
-							  $i++;
-							}
-						}
-		        //set the meta RETRIEVED so when we publish the post, we dont' try ingesting it
-		        $metas = array(
-		            NPR_STORY_ID_META_KEY      => $story->id,
-		            NPR_API_LINK_META_KEY      => $story->link['api']->value,
-		            NPR_HTML_LINK_META_KEY     => $story->link['html']->value,
-		            //NPR_SHORT_LINK_META_KEY    => $story->link['short']->value,
-		            NPR_STORY_CONTENT_META_KEY => $story->body,
-		            NPR_BYLINE_META_KEY        => $by_line,
-		            NPR_BYLINE_LINK_META_KEY   => $byline_link,
-		            NPR_MULTI_BYLINE_META_KEY  => $multi_by_line,
-		            NPR_RETRIEVED_STORY_META_KEY => 1,
-		            NPR_PUB_DATE_META_KEY => $story->pubDate->value,
-		            NPR_STORY_DATE_MEATA_KEY => $story->storyDate->value,
-								NPR_LAST_MODIFIED_DATE_KEY=> $story->lastModifiedDate->value,
-		        );
-		        //get audio
-		        if ( isset($story->audio) ) {
-		        	$mp3_array = array();
-		        	$m3u_array = array();
-		        	foreach ($story->audio as $n => $audio){
-								if (!empty($audio->format->mp3['mp3']) && $audio->permissions->download->allow == 'true'){
-									if ($audio->format->mp3['mp3']->type == 'mp3' ){
-										$mp3_array[] = $audio->format->mp3['mp3']->value;
-									}
-									if ($audio->format->mp3['m3u']->type == 'm3u' ){
-			 	       			$m3u_array[] = $audio->format->mp3['m3u']->value;
-									}
-								}
-		        	}
-		        	$metas[NPR_AUDIO_META_KEY] =  implode(',', $mp3_array);
-		        	$metas[NPR_AUDIO_M3U_META_KEY] = implode(',', $m3u_array);
-		        }
-		        if ( $existing ) {
-		            $created = false;
-		            $args[ 'ID' ] = $existing->ID;
-		        }
-		        else {
-		            $created = true;
-		        }
-		        $post_id = wp_insert_post( $args );
+                            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
+								    }
+                                }
+                            }
+                            $i++;
+                        }
+				    }
+                    //set the meta RETRIEVED so when we publish the post, we dont' try ingesting it
+                    $metas = array(
+                        NPR_STORY_ID_META_KEY        => $story->id,
+                        NPR_API_LINK_META_KEY        => $story->link['api']->value,
+                        NPR_HTML_LINK_META_KEY       => $story->link['html']->value,
+                        //NPR_SHORT_LINK_META_KEY    => $story->link['short']->value,
+                        NPR_STORY_CONTENT_META_KEY   => $story->body,
+                        NPR_BYLINE_META_KEY          => $by_line,
+                        NPR_BYLINE_LINK_META_KEY     => $byline_link,
+                        NPR_MULTI_BYLINE_META_KEY    => $multi_by_line,
+                        NPR_RETRIEVED_STORY_META_KEY => 1,
+                        NPR_PUB_DATE_META_KEY        => $story->pubDate->value,
+                        NPR_STORY_DATE_MEATA_KEY     => $story->storyDate->value,
+                        NPR_LAST_MODIFIED_DATE_KEY   => $story->lastModifiedDate->value,
+                    );
+                    //get audio
+                    if ( isset($story->audio) ) {
+                        $mp3_array = array();
+                        $m3u_array = array();
+                        foreach ( $story->audio as $n => $audio ) {
+                            if ( ! empty( $audio->format->mp3['mp3']) && $audio->permissions->download->allow == 'true' ) {
+				                if ($audio->format->mp3['mp3']->type == 'mp3' ) {
+				                    $mp3_array[] = $audio->format->mp3['mp3']->value;
+				                }
+				                if ($audio->format->mp3['m3u']->type == 'm3u' ) {
+                                    $m3u_array[] = $audio->format->mp3['m3u']->value;
+                                }
+				            }
+                        }
+                        $metas[NPR_AUDIO_META_KEY] = implode( ',', $mp3_array );
+                        $metas[NPR_AUDIO_M3U_META_KEY] = implode( ',', $m3u_array );
+                    }
+                    if ( $existing ) {
+                        $created = false;
+                        $args[ 'ID' ] = $existing->ID;
+                    } else {
+                        $created = true;
+                    }
+                    $post_id = wp_insert_post( $args );

-		        //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.
-						if (isset($story->image[0])){
-
-							//are there any images saved for this post, probably on update, but no sense looking of the post didn't already exist
-							if ($existing){
-								$image_args = array(
-									'order'=> 'ASC',
-									'post_mime_type' => 'image',
-									'post_parent' => $post_id,
-									'post_status' => null,
-									'post_type' => 'attachment',
-									'post_date'		 => $post_date,
-									);
-								$attached_images = get_children( $image_args );
-							}
+                    //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.
+                    if ( isset( $story->image[0] ) ) {

-
-		        	foreach ($story->image as $image){
-								$image_url = '';
-		        		//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;
-		        		}
-		        		else {
-		        			if (!empty($image->crop)) {
-		        				foreach ($image->crop as $crop){
-		        					if ($crop->type == 'enlargement') {
-		        						$image_url = $crop->src;
-		        						continue;
-		        					}
-		        				}
-		        				if (empty($image_url)){
-			        				foreach ($image->crop as $crop){
-			        					if ($crop->type == 'standard') {
-			        						$image_url = $crop->src;
-			        						continue;
-			        					}
-			        				}
-		        				}
-		        			}
-		        		}
-
-		        		if (empty($image_url)){
-		        			$image_url = $image->src;
-			        	}
-			        	error_log('Got image from :'.$image_url);
-		        		// Download file to temp location
-			          $tmp = download_url( $image_url );
-
-		            // Set variables for storage
-		            // fix file filename for query strings
-		            preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $image_url, $matches);
-		            $file_array['name'] = basename($matches[0]);
-		            $file_array['tmp_name'] = $tmp;
-
-		            $file_OK = TRUE;
-		            // If error storing temporarily, unlink
-		            if ( is_wp_error( $tmp ) ) {
-		            	@unlink($file_array['tmp_name']);
-		              $file_array['tmp_name'] = '';
-		              $file_OK = FALSE;
-		            }
+				    //are there any images saved for this post, probably on update, but no sense looking of the post didn't already exist
+                        if ( $existing ) {
+                            $image_args = array(
+                                'order'=> 'ASC',
+                                'post_mime_type' => 'image',
+                                'post_parent' => $post_id,
+                                'post_status' => null,
+                                'post_type' => 'attachment',
+                                'post_date'	=> $post_date,
+				            );
+                            $attached_images = get_children( $image_args );
+                        }
+                        foreach ( $story->image as $image ) {
+                            $image_url = '';
+		        		    //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;
+                            } else {
+                                if ( ! empty( $image->crop ) ) {
+                                    foreach ( $image->crop as $crop ) {
+                                        if ( $crop->type == 'enlargement' ) {
+                                            $image_url = $crop->src;
+                                            continue;
+                                        }
+                                    }
+                                    if ( empty( $image_url ) ) {
+                                        foreach ( $image->crop as $crop ) {
+                                            if ( $crop->type == 'standard' ) {
+                                                $image_url = $crop->src;
+                                                continue;
+                                            }
+                                        }
+                                    }
+                                }
+                            }

-		            // do the validation and storage stuff
-		            $id = media_handle_sideload( $file_array, $post_id, $image->title->value );
-		            // If error storing permanently, unlink
-		            if ( is_wp_error($id) ) {
-		            	@unlink($file_array['tmp_name']);
-		            	$file_OK = FALSE;
-		            }
-		            else {
-		            	$image_post = get_post($id);
-		            	if (!empty($attached_images)) {
-			            	foreach($attached_images as $att_image){
-			            			//see if the filename is very similar
-			            			$att_guid = explode('.', $att_image->guid);
-			            			//so if the already attached image name is part of the name of the file
-			            			//coming in, ignore the new/temp file, it's probably the same
-			            			if (strstr($image_post->guid, $att_guid[0])){
-			            				@unlink($file_array['tmp_name']);
-			            				wp_delete_attachment($id);
-			            				$file_OK = FALSE;
-			            			}
-			            	}
-		            	}
+                            if ( empty( $image_url ) ) {
+                                $image_url = $image->src;
+                            }
+                            error_log('Got image from :' . $image_url);
+                            // Download file to temp location
+                            $tmp = download_url( $image_url );
+
+                            // Set variables for storage
+                            // fix file filename for query strings
+                            preg_match( '/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $image_url, $matches );
+                            $file_array['name'] = basename( $matches[0] );
+                            $file_array['tmp_name'] = $tmp;
+
+                            $file_OK = TRUE;
+                            // If error storing temporarily, unlink
+                            if ( is_wp_error( $tmp ) ) {
+                                @unlink($file_array['tmp_name']);
+                                $file_array['tmp_name'] = '';
+                                $file_OK = FALSE;
+                            }

-		            }
+                            // do the validation and storage stuff
+                            $id = media_handle_sideload( $file_array, $post_id, $image->title->value );
+                            // If error storing permanently, unlink
+                            if ( is_wp_error($id) ) {
+                                @unlink( $file_array['tmp_name'] );
+                                $file_OK = FALSE;
+                            } else {
+                                $image_post = get_post( $id );
+                                if ( ! empty( $attached_images ) ) {
+			            	        foreach( $attached_images as $att_image ) {
+			            	            //see if the filename is very similar
+                                        $att_guid = explode( '.', $att_image->guid );
+                                        //so if the already attached image name is part of the name of the file
+                                        //coming in, ignore the new/temp file, it's probably the same
+                                        if ( strstr ( $image_post->guid, $att_guid[0] ) ) {
+                                            @unlink( $file_array['tmp_name'] );
+                                            wp_delete_attachment( $id );
+                                            $file_OK = FALSE;
+                                        }
+                                    }
+                                }
+                            }

-		            //set the primary image
-		            if ($image->type == 'primary' && $file_OK){
-                        add_post_meta($post_id, '_thumbnail_id', $id, true);
-                        //get any image meta data and attatch it to the image post
-                        $image_metas = array(
-                            NPR_IMAGE_CREDIT_META_KEY =>$image->producer->value,
-                            NPR_IMAGE_AGENCY_META_KEY =>$image->provider->value,
-                            NPR_IMAGE_CAPTION_META_KEY =>$image->caption->value,
-                        );
-                        foreach ( $image_metas as $k => $v ) {
-                            update_post_meta( $post_id, $k, $v );
+                            //set the primary image
+                            if ( $image->type == 'primary' && $file_OK ) {
+                                add_post_meta( $post_id, '_thumbnail_id', $id, true );
+                                //get any image meta data and attatch it to the image post
+                                $image_metas = array(
+                                    NPR_IMAGE_CREDIT_META_KEY =>$image->producer->value,
+                                    NPR_IMAGE_AGENCY_META_KEY =>$image->provider->value,
+                                    NPR_IMAGE_CAPTION_META_KEY =>$image->caption->value,
+                                );
+                                foreach ( $image_metas as $k => $v ) {
+                                    update_post_meta( $post_id, $k, $v );
+                                }
+                            }
                         }
                     }

-		        	}
-		        }
-
-		        foreach ( $metas as $k => $v ) {
-		            update_post_meta( $post_id, $k, $v );
-		        }
+                    foreach ( $metas as $k => $v ) {
+                        update_post_meta( $post_id, $k, $v );
+                    }

-		        $args = array(
-		        		'post_title'   => $story->title,
-		            'post_content' => $story->body,
-		        		'post_excerpt' => $story->teaser,
-		        		'post_type'    => $pull_post_type,
-		            'ID'   => $post_id,
-		        		'post_date'		 => $post_date,
-		        );
+                    $args = array(
+                        'post_title'   => $story->title,
+                        'post_content' => $story->body,
+                        'post_excerpt' => $story->teaser,
+                        'post_type'    => $pull_post_type,
+                        'ID'   => $post_id,
+                        'post_date'		 => $post_date,
+                    );
+
+                    //set author
+                    if ( ! empty( $by_line ) ) {
+                        $userQuery = new WP_User_Query( array(
+                            'search' => trim($by_line),
+                            'search_columns' => array(
+                                'nickname'
+                                )
+                            )
+                        );

-                //set author
-                if (!empty($by_line)) {
-                    $userQuery = new WP_User_Query(array(
-                        'search' => trim($by_line),
-                        'search_columns' => array(
-                            'nickname'
-                        )
-                    ));
+                        $user_results = $userQuery->get_results();
+                        if ( count( $user_results ) == 1 && isset( $user_results[0]->data->ID) ) {
+                            $args['post_author'] = $user_results[0]->data->ID;
+                        }
+                    }

-                    $user_results = $userQuery->get_results();
-                    if (count($user_results) == 1 && isset($user_results[0]->data->ID)) {
-                        $args['post_author'] = $user_results[0]->data->ID;
+                    //now set the status
+                    if ( ! $existing ) {
+                        if ( $publish ) {
+                            $args['post_status'] = 'publish';
+                        } else {
+                            $args['post_status'] = 'draft';
+                        }
+                    } else {
+                        //if the post existed, save its status
+                        $args['post_status'] = $existing_status;
                     }
+                    $ret = wp_insert_post( $args );
                 }

-                //now set the status
-                if ( ! $existing ) {
-		        	if ($publish){
-		            $args['post_status'] = 'publish';
-		        	}
-		        	else {
-		        		$args['post_status'] = 'draft';
-		        	}
-		        }
-		        else {
-		        	//if the post existed, save its status
-		        	$args['post_status'] = $existing_status;
-		        }
-		        $ret = wp_insert_post( $args );
-					}
-
                 //set categories for story
                 $category_ids = array();
-                if (is_array($story->parent)) {
-                    foreach ($story->parent as $parent) {
-                        if (isset($parent->type) && $parent->type == 'category') {
-                            $category_id = get_cat_ID($parent->title->value);
-                            if (!empty($category_id)) {
+                if ( is_array( $story->parent ) ) {
+                    foreach ( $story->parent as $parent ) {
+                        if ( isset( $parent->type ) && $parent->type == 'category' ) {
+                            $category_id = get_cat_ID( $parent->title->value );
+                            if ( ! empty( $category_id ) ) {
                                 $category_ids[] = $category_id;
                             }
                         }
                     }
-                } elseif (isset($story->parent->type) && $story->parent->type == 'category') {
-                    $category_id = get_cat_ID($story->parent->title->value);
-                    if (!empty($category_id)) {
+                } elseif ( isset( $story->parent->type ) && $story->parent->type == 'category') {
+                    $category_id = get_cat_ID( $story->parent->title->value );
+                    if ( ! empty( $category_id) ) {
                         $category_ids[] = $category_id;
                     }
                 }
-
-                if (count($category_ids) > 0 && is_integer($ret)) {
-                    wp_set_post_categories($ret, $category_ids);
+                if ( count( $category_ids ) > 0 && is_integer( $ret ) ) {
+                    wp_set_post_categories( $ret, $category_ids );
                 }
-			}
-
-			if ($single_story){
-				return $post_id;
-			}
-		}
-
-    return;
-	}
+            }
+            if ( $single_story ) {
+                return $post_id;
+            }
+        }
+        return;
+    }

@@ -427,70 +412,68 @@ class NPRAPIWordpress extends NPRAPI {
    * @return string
    *   An NPRML string.
    */
-  function create_NPRML($post) {
-		//using some old helper code
-		return as_nprml($post);
-  }
+    function create_NPRML( $post ) {
+        //using some old helper code
+        return as_nprml( $post );
+    }

   /**
    * This function will send the push request to the NPR API to add/update a story.
    *
    * @see NPRAPI::send_request()
    */
-  function send_request ($nprml, $post_ID) {
-		$error_text = '';
-  	$org_id = get_option( 'ds_npr_api_org_id' );
-  	if (!empty($org_id)){
-	    $url = add_query_arg( array(
-	        'orgId'  => $org_id,
-	        'apiKey' => get_option( 'ds_npr_api_key' )
-	    ), get_option( 'ds_npr_api_push_url' ) . '/story' );
-
-	    error_log('Sending nprml = '.$nprml);
+    function send_request ( $nprml, $post_ID ) {
+        $error_text = '';
+        $org_id = get_option( 'ds_npr_api_org_id' );
+        if ( ! empty( $org_id ) ) {
+            $url = add_query_arg( array(
+                'orgId'  => $org_id,
+                'apiKey' => get_option( 'ds_npr_api_key' )
+            ), get_option( 'ds_npr_api_push_url' ) . '/story' );
+
+            error_log('Sending nprml = ' . $nprml);

-	    $result = wp_remote_post( $url, array( 'body' => $nprml ) );
-	    if ( !is_wp_error($result) ) {
-		    if(  $result['response']['code'] == 200 ) {
-			    $body = wp_remote_retrieve_body( $result );
-			    if ( $body ) {
-			        $response_xml = simplexml_load_string( $body );
-			        $npr_story_id = (string) $response_xml->list->story['id'];
-			        update_post_meta( $post_ID, NPR_STORY_ID_META_KEY, $npr_story_id );
-			    }
-			    else {
-			        error_log( 'NPR API Push ERROR: ' . print_r( $result, true ) );
-			    }
-		    }
-		    else {
-		    	$error_text = '';
-		    	if (!empty($result['response']['message'])){
-			    	$error_text = 'Error pushing story with post_id = '. $post_ID .' for url='.$url . ' HTTP Error response =  '. $result['response']['message'];
-		    	}
-		    	$body = wp_remote_retrieve_body( $result );
+            $result = wp_remote_post( $url, array( 'body' => $nprml ) );
+            if ( ! is_wp_error( $result ) ) {
+                if ( $result['response']['code'] == 200 ) {
+                    $body = wp_remote_retrieve_body( $result );
+                    if ( $body ) {
+                        $response_xml = simplexml_load_string( $body );
+                        $npr_story_id = (string) $response_xml->list->story['id'];
+                        update_post_meta( $post_ID, NPR_STORY_ID_META_KEY, $npr_story_id );
+                    }
+                    else {
+                        error_log( 'NPR API Push ERROR: ' . print_r( $result, true ) );
+                    }
+                } else {
+                    $error_text = '';
+                    if ( ! empty( $result['response']['message'] ) ) {
+                        $error_text = 'Error pushing story with post_id = '. $post_ID .' for url='.$url . ' HTTP Error response =  '. $result['response']['message'];
+                    }
+                    $body = wp_remote_retrieve_body( $result );

-			    if ( $body ) {
-			    	$response_xml = simplexml_load_string( $body );
-			    	$error_text .= '  API Error Message = ' .$response_xml->message->text;
-			    }
-		    	error_log('Error returned from API ' . $error_text);
-		    }
-	    } else {
-	    	$error_text = 'WP Error returned from sending story with post_id = '. $post_ID .' for url='.$url . ' to API ='. $result->get_error_message();
-	    	error_log($error_text);
-	    }
-  	} else {
-  		$error_text = 'Tried to push, but OrgID was not set for post_id ='. $post_ID;
-  		error_log($error_text);
-  	}
-
-		if (!empty($error_text)){
-	  	update_post_meta( $post_ID, NPR_PUSH_STORY_ERROR, $error_text );
+                    if ( $body ) {
+                        $response_xml = simplexml_load_string( $body );
+                        $error_text .= '  API Error Message = ' . $response_xml->message->text;
+                    }
+                    error_log('Error returned from API ' . $error_text);
+                }
+            } else {
+                $error_text = 'WP Error returned from sending story with post_id = '. $post_ID .' for url='.$url . ' to API ='. $result->get_error_message();
+                error_log($error_text);
+            }
+        } else {
+            $error_text = 'Tried to push, but OrgID was not set for post_id ='. $post_ID;
+            error_log($error_text);
+        }
+
+		if ( ! empty( $error_text ) ) {
+            update_post_meta( $post_ID, NPR_PUSH_STORY_ERROR, $error_text );
 		}
 		else {
-			delete_post_meta($post_ID, NPR_PUSH_STORY_ERROR);
+			delete_post_meta( $post_ID, NPR_PUSH_STORY_ERROR );
 		}
-
-  }
+    }

   /**
    *
@@ -499,24 +482,23 @@ class NPRAPIWordpress extends NPRAPI {
    *
    * @param  $api_id
    */
-  function send_delete($api_id){
-
-  	$url = add_query_arg( array(
-        'orgId'  => get_option( 'ds_npr_api_org_id' ),
-        'apiKey' => get_option( 'ds_npr_api_key' ),
+    function send_delete( $api_id ) {
+        $url = add_query_arg( array(
+            'orgId'  => get_option( 'ds_npr_api_org_id' ),
+            'apiKey' => get_option( 'ds_npr_api_key' ),
   			'id' => $api_id
-    ), get_option( 'ds_npr_api_push_url' ) . '/story' );
+        ), get_option( 'ds_npr_api_push_url' ) . '/story' );
+
 		//wp doesn't let me do a wp_remote_post with method=DELETE so we have to make our own curl request.  fun
 		//a lot of this code came from WP's class-http object
 		//$result = wp_remote_post( $url, array( 'method' => 'DELETE' ) );
-		$handle = curl_init();
-		curl_setopt( $handle, CURLOPT_CUSTOMREQUEST, 'DELETE' );
-	  curl_setopt( $handle, CURLOPT_URL, $url);
-	  curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
+        $handle = curl_init();
+        curl_setopt( $handle, CURLOPT_CUSTOMREQUEST, 'DELETE' );
+        curl_setopt( $handle, CURLOPT_URL, $url );
+        curl_setopt( $handle, CURLOPT_RETURNTRANSFER, TRUE );
 		curl_exec( $handle );
 		curl_close( $handle );
-
-  }
+    }

   /**
    *
@@ -525,24 +507,24 @@ class NPRAPIWordpress extends NPRAPI {
    *
    * @param  $story
    */
-  function get_transcript_body($story){
-  	$transcript_body = "";
-	  if (!empty($story->transcript)){
-	  	foreach ($story->transcript as $transcript){
-	    	if ($transcript->type == 'api'){
-			  	$response = wp_remote_get( $transcript->value );
-    			if( !is_wp_error( $response ) ) {
-    				$transcript_body .= "<p><strong>Transcript :</strong><p>";
-    				$body_xml = simplexml_load_string($response['body']);
-    				if (!empty($body_xml->paragraph)){
-	    				foreach($body_xml->paragraph as $paragraph){
-	    					$transcript_body .= (strip_tags($paragraph)) . '<p>';
-	    				}
-    				}
-    			}
-	    	}
-	  	}
-	  }
-	  return $transcript_body;
-  }
+    function get_transcript_body( $story ) {
+        $transcript_body = "";
+        if ( ! empty( $story->transcript ) ) {
+            foreach ( $story->transcript as $transcript ) {
+                if ( $transcript->type == 'api' ) {
+                    $response = wp_remote_get( $transcript->value );
+                    if ( !is_wp_error( $response ) ) {
+                        $transcript_body .= "<p><strong>Transcript :</strong><p>";
+                        $body_xml = simplexml_load_string( $response['body'] );
+                        if ( ! empty( $body_xml->paragraph ) ) {
+                            foreach( $body_xml->paragraph as $paragraph ) {
+                                $transcript_body .= (strip_tags( $paragraph )) . '<p>';
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        return $transcript_body;
+    }
 }
diff --git a/classes/nprml.php b/classes/nprml.php
index f06e65a..4988453 100644
--- a/classes/nprml.php
+++ b/classes/nprml.php
@@ -11,7 +11,6 @@ function as_nprml( $post ) {
         'children' => array( array( 'tag' => 'story', 'children' => $story ), ),
     );
     $ret_xml = array_to_xml( 'nprml', array( 'version' => '0.93' ), $doc );
-
     return $ret_xml;
 }

@@ -29,37 +28,36 @@ function post_to_nprml_story( $post ) {
         'attr' => array( 'type' => 'html' ),
         'text' => get_permalink( $post ),
     );
-    $use_custom = get_option('dp_npr_push_use_custom_map');
+    $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);
+    $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;
     }

-    $custom_content_meta = get_option('ds_npr_api_mapping_body');
-    if ($use_custom && !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);
+    $custom_content_meta = get_option( 'ds_npr_api_mapping_body' );
+    if ( $use_custom && ! 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);
     	$post_for_teaser = $post;
     	$post_for_teaser->post_content = $content;
-    	if (empty($teaser_text)){
+        if ( empty( $teaser_text ) ){
 	    	$teaser_text = nai_get_excerpt( $post_for_teaser );
     	}
-    }
-    else {
-	    $content = $post->post_content ;
-	    if (empty($teaser_text)){
+    } else {
+	    $content = $post->post_content;
+	    if ( empty( $teaser_text ) ) {
 		    $teaser_text = nai_get_excerpt( $post );
 	    }
     }
     //lets see if there are any plugins that need to fix their shortcodes before we run do_shortcode
-    if (has_filter('npr_ds_shortcode_filter')) {
-	    $content = apply_filters('npr_ds_shortcode_filter', $content);
+    if ( has_filter( 'npr_ds_shortcode_filter' ) ) {
+	    $content = apply_filters( 'npr_ds_shortcode_filter', $content );
     }
 	  //let any plugin that has short codes try and replace those with HTML
-	  $content = do_shortcode( $content );
+    $content = do_shortcode( $content );
     //for any remaining short codes, nuke 'em
     $content = strip_shortcodes( $content );
     $content = apply_filters( 'the_content', $content );
@@ -68,15 +66,14 @@ function post_to_nprml_story( $post ) {
         'tag' => 'teaser',
         'text' => $teaser_text,
     );
-    $custom_title_meta = get_option('ds_npr_api_mapping_title');
-    if ($use_custom && !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);
+    $custom_title_meta = get_option( 'ds_npr_api_mapping_title' );
+    if ( $use_custom && !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(
 	        'tag' => 'title',
 	        'text' => $custom_title,
 	    );
-    }
-    else {
+    } else {
 	    $story[] = array(
 	        'tag' => 'title',
 	        'text' => $post->post_title,
@@ -92,49 +89,54 @@ function post_to_nprml_story( $post ) {
      *
      */
     $byline = FALSE;
-    $custom_byline_meta = get_option('ds_npr_api_mapping_byline');
-    if ($use_custom && !empty($custom_byline_meta) && $custom_byline_meta != '#NONE#' && in_array($custom_content_meta,$post_metas)){
- 			$byline = TRUE;
+    $custom_byline_meta = get_option( 'ds_npr_api_mapping_byline' );
+    if ($use_custom && ! empty( $custom_byline_meta ) && $custom_byline_meta != '#NONE#' && in_array( $custom_content_meta,$post_metas ) ) {
+        $byline = TRUE;
     	$story[] = array(
 	        'tag' => 'byline',
-    			'children' => array ( array(
-								'tag' => 'name',
-	        			'text' => get_post_meta($post->ID, $custom_byline_meta, true),
-    			)),
-	    );
+            'children' => array(
+                array(
+                    'tag' => 'name',
+                    'text' => get_post_meta( $post->ID, $custom_byline_meta, true ),
+                )
+            ),
+	   );
     }
-    if (function_exists('get_coauthors')){
-    	$coauthors = get_coauthors($post->ID);
-    	if (!empty($coauthors)){
-    		$byline = TRUE;
-				foreach($coauthors as $i=>$co){
-					$story[] = array(
-	       		'tag' => 'byline',
-						'children' => array ( array(
-								'tag' => 'name',
-	       										'text' => $co->display_name,
-	   												)
-	   									));
-				}
-    	}
-    	else {
-    		error_log('we do not have co authors');
+    if ( function_exists( 'get_coauthors' ) ) {
+        $coauthors = get_coauthors( $post->ID );
+        if ( ! empty( $coauthors ) ) {
+            $byline = TRUE;
+            foreach( $coauthors as $i=>$co ) {
+                $story[] = array(
+                    'tag' => 'byline',
+                    'children' => array(
+                        array(
+                            'tag' => 'name',
+                            'text' => $co->display_name,
+                        )
+                    )
+                );
+            }
+        } else {
+            error_log( 'we do not have co authors' );
     	}
-   	}
-   	else {
+    } else {
    		error_log('can not find get_coauthors');
    	}
-		if (!$byline){
-			$story[] = array(
-	        		'tag' => 'byline',
-							'children' => array ( array('tag' => 'name',
-		        		'text' => get_the_author_meta( 'display_name', $post->post_author ),
-							)),
-	    			);
+    if ( ! $byline ) {
+        $story[] = array(
+            'tag' => 'byline',
+            'children' => array (
+                array(
+                    'tag' => 'name',
+                    'text' => get_the_author_meta( 'display_name', $post->post_author ),
+				)
+            ),
+        );
     }

     // NPR One
-    if (!empty($_POST['send_to_nprone'])) {
+    if ( ! empty( $_POST['send_to_nprone'] ) ) {
         $story[] = array(
             'tag' => 'parent',
             'attr' => array( 'id' => '319418027', 'type' => 'collection' ),
@@ -168,170 +170,175 @@ function post_to_nprml_story( $post ) {
         'children' => split_paragraphs( $content ),
     );

-    $perms_group = get_option('ds_npr_story_default_permission');
-    if (!empty($perms_group)){
+    $perms_group = get_option( 'ds_npr_story_default_permission' );
+    if (!empty( $perms_group ) ) {
      	$story[] = array(
-    			'tag' => 'permissions',
-    			'children' => array ( array(
+            'tag' => 'permissions',
+            'children' => array (
+                array(
     				'tag' => 'permGroup',
 			     	'attr' => array( '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');
+    $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');
     */
     $args = array(
-			'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);
+        '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 );

-		foreach ($images as $image){
-			$custom_credit = '';
-			$custom_agency = '';
-			$image_metas = get_post_custom_keys($image->ID);
-	    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);
+    foreach ( $images as $image ) {
+        $custom_credit = '';
+        $custom_agency = '';
+        $image_metas = get_post_custom_keys( $image->ID );
+	    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)){
-	    	$custom_agency = get_post_meta($image->ID, $custom_media_agency, true);
+        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);
 	    }

-			if ($use_custom && !empty($dist_media_option) && $dist_media_option != '#NONE#' && in_array($dist_media_option,$image_metas)){
-	    	$dist_media = get_post_meta($image->ID, $dist_media_option, true);
+        if ( $use_custom && !empty( $dist_media_option ) && $dist_media_option != '#NONE#' && in_array( $dist_media_option,$image_metas ) ) {
+	    	$dist_media = get_post_meta( $image->ID, $dist_media_option, true );
 	    }

-			//if the image field for distribute is set and polarity then send it.
-			//all kinds of other math when polarity is negative or the field isn't set.
-			$image_type = 'standard';
-			if ($image->ID == $primary_image){
-				$image_type = 'primary';
-			}
+        //if the image field for distribute is set and polarity then send it.
+        //all kinds of other math when polarity is negative or the field isn't set.
+        $image_type = 'standard';
+        if ( $image->ID == $primary_image ) {
+            $image_type = 'primary';
+        }

-			//is the image in the content?  If so, tell the APi with a flag that CorePublisher knows
-			//WP may add something like "-150X150" to the end of the filename, before the extension.  Isn't that nice?
-			$image_name_parts = split(".", $image_guid);
-			$image_regex = "/". $image_name_parts[0] . "\-[a-zA-Z0-9]*" . $image_name_parts[1] . "/";
-			$in_body = "";
-			if (preg_match($image_regex, $content)) {
-				if (strstr($image->guid, '?')){
+        //is the image in the content?  If so, tell the APi with a flag that CorePublisher knows
+        //WP may add something like "-150X150" to the end of the filename, before the extension.  Isn't that nice?
+        $image_name_parts = split( ".", $image_guid );
+        $image_regex = "/" . $image_name_parts[0] . "\-[a-zA-Z0-9]*" . $image_name_parts[1] . "/";
+        $in_body = "";
+        if ( preg_match( $image_regex, $content ) ) {
+				if ( strstr( $image->guid, '?') ) {
 					$in_body = "&origin=body";
-				}
-				else {
+				} else {
 					$in_body = "?origin=body";
 				}
-			}
-			$story[] = array(
-				'tag' => 'image',
-				'attr' => array( 'src' => $image->guid . $in_body, 'type' => $image_type ),
-				'children' => array ( array(
-						'tag' => 'title',
-						'text' => $image->post_title,
-						),
-						array(
-							'tag' => 'caption',
-							'text' => $image->post_excerpt,
- 						),
- 						array(
- 							'tag' => 'producer',
- 							'text' => $custom_credit
- 						),
- 						array(
- 							'tag' => 'provider',
- 							'text' => $custom_agency
- 						)
-					),
-			);
-		}
+        }
+        $story[] = array(
+            'tag' => 'image',
+            'attr' => array( 'src' => $image->guid . $in_body, 'type' => $image_type ),
+            'children' => array(
+                array(
+				    'tag' => 'title',
+				    'text' => $image->post_title,
+				),
+				array(
+				    'tag' => 'caption',
+				    'text' => $image->post_excerpt,
+ 			    ),
+ 			    array(
+ 			        'tag' => 'producer',
+ 			        'text' => $custom_credit
+ 			    ),
+ 			    array(
+ 			        'tag' => 'provider',
+ 			        'text' => $custom_agency
+ 			    )
+            ),
+        );
+    }

-		//should be able to do the same as image for audio, with post_mime_typ = 'audio' or something.
-		$args = array(
-			'order'=> 'DESC',
-			'post_mime_type' => 'audio',
-			'post_parent' => $post->ID,
-			'post_status' => null,
-			'post_type' => 'attachment'
-		);
-		$audios = get_children( $args );
+    //should be able to do the same as image for audio, with post_mime_typ = 'audio' or something.
+    $args = array(
+        'order'=> 'DESC',
+        'post_mime_type' => 'audio',
+        'post_parent' => $post->ID,
+        'post_status' => null,
+        'post_type' => 'attachment'
+    );
+    $audios = get_children( $args );

-		foreach ($audios as $audio){
-		    $audio_meta = wp_get_attachment_metadata($audio->ID);
-			$caption = $audio->post_excerpt;
-			//if we don't have excerpt filled in, try content
-			if (empty($caption)) {
-				$caption = $audio->post_content;
-			}
+    foreach ( $audios as $audio ) {
+        $audio_meta = wp_get_attachment_metadata( $audio->ID );
+        $caption = $audio->post_excerpt;
+        //if we don't have excerpt filled in, try content
+        if ( empty( $caption ) ) {
+            $caption = $audio->post_content;
+        }

-			$story[] = array(
-      	'tag' => 'audio',
-        'children' => array(
-        	array(
-          	'tag' => 'format',
-            'children' => array ( array(
-            	'tag' => 'mp3',
-              'text' => $audio->guid,
-            )),
-          ),
-          array(
-            'tag' => 'description',
-            'text' => $caption,
-          ),
-          array(
-            'tag' => 'duration',
-            'text' => $audio_meta['length'],
-          ),
-        ),
-      );
-		}
+        $story[] = array(
+            'tag' => 'audio',
+            'children' => array(
+                array(
+                    'tag' => 'format',
+                    'children' => array (
+                        array(
+            	           'tag' => 'mp3',
+                            'text' => $audio->guid,
+                        )
+                    ),
+                ),
+                array(
+                    'tag' => 'description',
+                    'text' => $caption,
+                ),
+                array(
+                    'tag' => 'duration',
+                    'text' => $audio_meta['length'],
+                ),
+            ),
+        );
+    }

-		if ($enclosures = get_metadata('post', $post->ID, 'enclosure')) {
-		  // This logic is specifically driven by enclosure metadata items that are
-		  // created by the PowerPress podcasting plug-in. It will likely have to be
-		  // re-worked if we need to accomodate other plug-ins that use enclosures.
-		  foreach($enclosures as $enclosure) {
-		    $pieces = explode("\n", $enclosure);
+    if ( $enclosures = get_metadata( 'post', $post->ID, 'enclosure' ) ) {

-		    if (!empty($pieces[3])) {
-		      $metadata = unserialize($pieces[3]);
-		      $duration = (!empty($metadata['duration'])) ? nprapi_convert_duration($metadata['duration']) : NULL;
+        // This logic is specifically driven by enclosure metadata items that are
+        // created by the PowerPress podcasting plug-in. It will likely have to be
+        // re-worked if we need to accomodate other plug-ins that use enclosures.
+        foreach( $enclosures as $enclosure ) {
+            $pieces = explode( "\n", $enclosure );
+		    if ( !empty( $pieces[3] ) ) {
+                $metadata = unserialize( $pieces[3] );
+                $duration = ( ! empty($metadata['duration'] ) ) ? nprapi_convert_duration( $metadata['duration'] ) : NULL;
 		    }
 		    $story[] = array(
-              'tag' => 'audio',
-              'children' => array(
-                array(
-                  'tag' => 'duration',
-                  'text' => (!empty($duration)) ? $duration : 0,
-                ),
-                array(
-                  'tag' => 'format',
-                  'children' => array(
+                'tag' => 'audio',
+                'children' => array(
                     array(
-                      'tag' => 'mp3',
-                      'text' => $pieces[0],
+                        'tag' => 'duration',
+                        'text' => ( !empty($duration) ) ? $duration : 0,
+                    ),
+                    array(
+                        'tag' => 'format',
+                        'children' => array(
+                            array(
+                            'tag' => 'mp3',
+                            'text' => $pieces[0],
+                            ),
+                        ),
                     ),
-                  ),
                 ),
-              ),
             );
-		  }
-		}
-  return $story;
+        }
+    }
+    return $story;
 }

 // Convert "HH:MM:SS" duration (not time) into seconds
-function nprapi_convert_duration($duration) {
-  $pieces = explode(':', $duration);
-  $duration_in_seconds = ($pieces[0] * 60 * 60 + $pieces[1] * 60 + $pieces[2]);
+function nprapi_convert_duration( $duration ) {
+  $pieces = explode( ':', $duration );
+  $duration_in_seconds = ( $pieces[0] * 60 * 60 + $pieces[1] * 60 + $pieces[2] );
   return $duration_in_seconds;
 }

@@ -349,7 +356,6 @@ function split_paragraphs( $html ) {
         );
         $num++;
     }
-
     return $graphs;
 }

@@ -360,20 +366,15 @@ function split_paragraphs( $html ) {
 function array_to_xml( $tag, $attrs, $data ) {
     $xml = new DOMDocument();
     $xml->formatOutput = true;
-
     $root = $xml->createElement( $tag );
-
     foreach ( $attrs as $k => $v ) {
         $root->setAttribute( $k, $v );
     }
-
     foreach ( $data as $item ) {
         $elemxml = item_to_xml( $item, $xml );
         $root->appendChild( $elemxml );
     }
-
     $xml->appendChild( $root );
-
     return $xml->saveXML();
 }

@@ -438,7 +439,6 @@ function nai_get_excerpt( $post, $word_count = 30 ) {
     } else {
         $text = implode( ' ', $words );
     }
-
     return $text;
 }

diff --git a/ds-npr-api.php b/ds-npr-api.php
index aaa857e..acf610f 100644
--- a/ds-npr-api.php
+++ b/ds-npr-api.php
@@ -45,119 +45,110 @@ define( 'NPR_IMAGE_CAPTION_META_KEY', 'npr_image_caption');

 define( 'NPR_PUSH_STORY_ERROR', 'npr_push_story_error');

-define('NPR_MAX_QUERIES', 10);
+define( 'NPR_MAX_QUERIES', 10 );

-define('DS_NPR_PLUGIN_DIR', plugin_dir_path(__FILE__) );
+define( 'DS_NPR_PLUGIN_DIR', plugin_dir_path(__FILE__) );

-define('NPR_POST_TYPE', 'npr_story_post');
-require_once( DS_NPR_PLUGIN_DIR .'/settings.php' );
-require_once( DS_NPR_PLUGIN_DIR .'/classes/NPRAPIWordpress.php');
+define( 'NPR_POST_TYPE', 'npr_story_post' );
+require_once( DS_NPR_PLUGIN_DIR . '/settings.php' );
+require_once( DS_NPR_PLUGIN_DIR . '/classes/NPRAPIWordpress.php');

-require_once( DS_NPR_PLUGIN_DIR .'/get_stories.php');
+require_once( DS_NPR_PLUGIN_DIR . '/get_stories.php');
 //add the cron to get stories
-register_activation_hook(DS_NPR_PLUGIN_DIR .'/ds-npr-api.php', 'ds_npr_story_activation');
-add_action('npr_ds_hourly_cron', array ('DS_NPR_API','ds_npr_story_cron_pull'));
-register_deactivation_hook(DS_NPR_PLUGIN_DIR .'/ds-npr-api.php', 'ds_npr_story_deactivation');
+register_activation_hook( DS_NPR_PLUGIN_DIR . '/ds-npr-api.php', 'ds_npr_story_activation' );
+add_action( 'npr_ds_hourly_cron', array ( 'DS_NPR_API','ds_npr_story_cron_pull' ) );
+register_deactivation_hook( DS_NPR_PLUGIN_DIR . '/ds-npr-api.php', 'ds_npr_story_deactivation' );

 function ds_npr_story_activation() {
-
 	global $wpdb;
-
-	if (function_exists('is_multisite') && is_multisite()) {
+	if ( function_exists( 'is_multisite' ) && is_multisite() ) {
 	  // check if it is a network activation - if so, run the activation function for each blog id
-		$old_blog = $wpdb->blogid;
+        $old_blog = $wpdb->blogid;
 		// Get all blog ids
-		$blogids = $wpdb->get_col($wpdb->prepare("SELECT blog_id FROM $wpdb->blogs"));
-		foreach ($blogids as $blog_id) {
-			switch_to_blog($blog_id);
-			_ds_npr_activate();
+		$blogids = $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs" ) );
+		foreach ( $blogids as $blog_id ) {
+            switch_to_blog( $blog_id );
+            _ds_npr_activate();
 		}
-		switch_to_blog($old_blog);
-	}
-	else {
-		_ds_npr_activate();
+		switch_to_blog( $old_blog );
+	} else {
+        _ds_npr_activate();
 	}
 }

 function _ds_npr_activate() {
-
-	update_option('dp_npr_query_multi_cron_interval', 60);
-	if ( !wp_next_scheduled( 'npr_ds_hourly_cron' ) ) {
-		error_log('turning on cron event');
-		wp_schedule_event( time(), 'hourly', 'npr_ds_hourly_cron');
+	update_option( 'dp_npr_query_multi_cron_interval', 60 );
+	if ( ! wp_next_scheduled( 'npr_ds_hourly_cron' ) ) {
+		error_log( 'turning on cron event' );
+		wp_schedule_event( time(), 'hourly', 'npr_ds_hourly_cron' );
 	}

-	$num =  get_option('ds_npr_num');
-	if (empty($num)){
-		update_option('ds_npr_num', 5);
+	$num =  get_option( 'ds_npr_num' );
+	if ( empty($num) ) {
+		update_option( 'ds_npr_num', 5 );
 	}

 	$def_url = 'http://api.npr.org';
 	$pull_url = get_option( 'ds_npr_api_pull_url' );
-	if (empty($pull_url)){
-		update_option('ds_npr_api_pull_url', $def_url);
+	if ( empty( $pull_url ) ) {
+		update_option( 'ds_npr_api_pull_url', $def_url );
 	}

 }

 function ds_npr_story_deactivation() {
 	global $wpdb;
-
-	if (function_exists('is_multisite') && is_multisite()) {
+	if ( function_exists( 'is_multisite' ) && is_multisite() ) {
 	  // check if it is a network activation - if so, run the activation function for each blog id
 		$old_blog = $wpdb->blogid;
 		// Get all blog ids
-		$blogids = $wpdb->get_col($wpdb->prepare("SELECT blog_id FROM $wpdb->blogs"));
-		foreach ($blogids as $blog_id) {
-			switch_to_blog($blog_id);
+		$blogids = $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs" ) );
+		foreach ( $blogids as $blog_id ) {
+			switch_to_blog( $blog_id );
 			_ds_npr_deactivate();
 		}
-		switch_to_blog($old_blog);
-	}
-	else {
+		switch_to_blog( $old_blog );
+	} else {
 		_ds_npr_deactivate();
 	}
 }

 function _ds_npr_deactivate() {
-
-	wp_clear_scheduled_hook('npr_ds_hourly_cron');
-
-	$num =  get_option('ds_npr_num');
-	if (!empty($num)){
-		delete_option('ds_npr_num');
+	wp_clear_scheduled_hook( 'npr_ds_hourly_cron' );
+	$num =  get_option( 'ds_npr_num' );
+	if ( ! empty($num) ) {
+		delete_option( 'ds_npr_num' );
 	}

 	$push_url = get_option( 'ds_npr_api_push_url' );
-	if (!empty($push_url)){
-		delete_option('ds_npr_api_push_url');
+	if ( ! empty( $push_url ) ) {
+		delete_option( 'ds_npr_api_push_url' );
 	}
 }

-function ds_npr_show_message($message, $errormsg = false)
-{
-	if ($errormsg) {
+function ds_npr_show_message( $message, $errormsg = false ) {
+	if ( $errormsg ) {
 		echo '<div id="message" class="error">';
-	}
-	else {
+	} else {
 		echo '<div id="message" class="updated fade">';
 	}
-
 	echo "<p><strong>$message</strong></p></div>";
-}
-require_once('push_story.php');
+}
+
+require_once( 'push_story.php' );

 add_action( 'init', 'ds_npr_create_post_type' );
+
 function ds_npr_create_post_type() {
 	register_post_type( NPR_POST_TYPE,
 		array(
 			'labels' => …

README.md

WP-DS-NPR-API

Something went wrong with that request. Please try again.