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

Commit

Permalink
Merge pull request #39 from fastmover/master
Browse files Browse the repository at this point in the history
Added auto tagging
  • Loading branch information
Mike Douglas authored Dec 20, 2016
2 parents 1e9c7d4 + c41a0eb commit ac0a7f7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 4 additions & 1 deletion classes/NPRAPIWordpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function query_by_url( $url ) {
* @param bool $publish
* @return int|null $post_id or null
*/
function update_posts_from_stories( $publish = TRUE ) {
function update_posts_from_stories( $publish = TRUE, $qnum = false ) {

This comment has been minimized.

Copy link
@mikeschinkel

mikeschinkel Feb 5, 2017

Contributor

Instead of using $qnum here, why not use $opts=array() to future proof this?

Inside of the method use $opts=wp_parse_args($opts,array('query_number' => false));

I added these changes to my latest PR.

$pull_post_type = get_option( 'ds_npr_pull_post_type' );
if ( empty( $pull_post_type ) ) {
$pull_post_type = 'post';
Expand Down Expand Up @@ -154,6 +154,9 @@ function update_posts_from_stories( $publish = TRUE ) {
'post_type' => $pull_post_type,
'post_date' => $post_date,
);
if( false !== $qnum ) {

This comment has been minimized.

Copy link
@mikeschinkel

mikeschinkel Feb 5, 2017

Contributor

Along with the above suggestion you would change reference to $qnum to be $opts['query_number'].

$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 ) ) {

Expand Down
2 changes: 1 addition & 1 deletion get_stories.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static function nprstory_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);

This comment has been minimized.

Copy link
@mikeschinkel

mikeschinkel Feb 5, 2017

Contributor

Along with above suggestion you would pass in "query_number={$i}" instead of passing in just $i here.

} 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
Expand Down
15 changes: 15 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ function nprstory_settings_init() {

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

add_settings_field( 'ds_npr_num', 'Number of things to get', 'nprstory_api_num_multi_callback', 'ds_npr_api_get_multi_settings', 'ds_npr_api_get_multi_settings' );

add_settings_field( 'ds_npr_num', 'Number of things to get', 'nprstory_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', 'intval' );

Expand All @@ -72,6 +74,10 @@ function nprstory_settings_init() {
//ds_npr_query_publish_
add_settings_field( 'ds_npr_query_publish_' . $i, 'Publish Stories ' . $i, 'nprstory_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 , 'nprstory_validation_callback_select');

// Add tags
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', 'nprstory_query_run_multi_callback', 'ds_npr_api_get_multi_settings', 'ds_npr_api_get_multi_settings' );
Expand Down Expand Up @@ -170,6 +176,15 @@ function nprstory_api_query_callback( $i ) {

}

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).</p>";
wp_nonce_field( 'nprstory_nonce_ds_npr_tags_' . $i, 'nprstory_nonce_ds_npr_tags_' . $i . '_name', true, true );
echo "<p><hr></p>";
}

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

0 comments on commit ac0a7f7

Please sign in to comment.