From 00ac80b615dec4e0ded67d5dd1eaf628dc4a0753 Mon Sep 17 00:00:00 2001 From: Peter Molnar Date: Sat, 14 Mar 2015 09:14:29 +0000 Subject: [PATCH] - adding post time interval limitations - changing options handler to be joined, since all the importers share it commonly at the moment --- importers/keyring-reactions-500px.php | 5 +- importers/keyring-reactions-facebook.php | 6 +- importers/keyring-reactions-flickr.php | 5 +- keyring-reactions-importer.php | 79 +++++++++++++++++++++--- 4 files changed, 81 insertions(+), 14 deletions(-) diff --git a/importers/keyring-reactions-500px.php b/importers/keyring-reactions-500px.php index 7ecfaeb..417eebe 100644 --- a/importers/keyring-reactions-500px.php +++ b/importers/keyring-reactions-500px.php @@ -29,7 +29,7 @@ class Keyring_500px_Reactions extends Keyring_Reactions_Base { * Accept the form submission of the Options page and handle all of the values there. * You'll need to validate/santize things, and probably store options in the DB. When you're * done, set $this->step = 'import' to continue, or 'options' to show the options form again. - */ + * function handle_request_options() { $bools = array('auto_import','auto_approve'); @@ -49,9 +49,10 @@ class Keyring_500px_Reactions extends Keyring_Reactions_Base { 'auto_approve' => (bool) $_POST['auto_approve'], ) ); - $this->step = 'import'; + $this->step = 'options'; } } + */ /** * implementation for all the requests for one method of one post diff --git a/importers/keyring-reactions-facebook.php b/importers/keyring-reactions-facebook.php index e3e7794..dd954c4 100644 --- a/importers/keyring-reactions-facebook.php +++ b/importers/keyring-reactions-facebook.php @@ -31,7 +31,7 @@ class Keyring_Facebook_Reactions extends Keyring_Reactions_Base { * Accept the form submission of the Options page and handle all of the values there. * You'll need to validate/santize things, and probably store options in the DB. When you're * done, set $this->step = 'import' to continue, or 'options' to show the options form again. - */ + * function handle_request_options() { $bools = array('auto_import','auto_approve'); @@ -51,9 +51,9 @@ class Keyring_Facebook_Reactions extends Keyring_Reactions_Base { 'auto_approve' => (bool) $_POST['auto_approve'], ) ); - $this->step = 'import'; + $this->step = 'options'; } - } + }*/ function make_all_requests( $method, $post ) { diff --git a/importers/keyring-reactions-flickr.php b/importers/keyring-reactions-flickr.php index abafbdd..9163af9 100644 --- a/importers/keyring-reactions-flickr.php +++ b/importers/keyring-reactions-flickr.php @@ -28,7 +28,7 @@ class Keyring_Flickr_Reactions extends Keyring_Reactions_Base { * Accept the form submission of the Options page and handle all of the values there. * You'll need to validate/santize things, and probably store options in the DB. When you're * done, set $this->step = 'import' to continue, or 'options' to show the options form again. - */ + * function handle_request_options() { $bools = array('auto_import','auto_approve'); @@ -48,9 +48,10 @@ class Keyring_Flickr_Reactions extends Keyring_Reactions_Base { 'auto_approve' => (bool) $_POST['auto_approve'], ) ); - $this->step = 'import'; + $this->step = 'options'; } } + */ function make_all_requests( $method, $post ) { diff --git a/keyring-reactions-importer.php b/keyring-reactions-importer.php index b812c3b..50e4771 100644 --- a/keyring-reactions-importer.php +++ b/keyring-reactions-importer.php @@ -206,7 +206,29 @@ abstract class Keyring_Reactions_Base { * You'll need to validate/santize things, and probably store options in the DB. When you're * done, set $this->step = 'import' to continue, or 'options' to show the options form again. */ - abstract protected function handle_request_options(); + protected function handle_request_options() { + $bools = array('auto_import','auto_approve'); + + foreach ( $bools as $bool ) { + if ( isset( $_POST[$bool] ) ) + $_POST[$bool] = true; + else + $_POST[$bool] = false; + } + + // If there were errors, output them, otherwise store options and start importing + if ( count( $this->errors ) ) { + $this->step = 'greet'; + } else { + $this->set_option( array( + 'auto_import' => (bool) $_POST['auto_import'], + 'auto_approve' => (bool) $_POST['auto_approve'], + 'limit_posts' => $_POST['limit_posts'], + ) ); + + $this->step = 'import'; + } + } /** * This step will do all the required calls for a specific method for a @@ -316,8 +338,9 @@ abstract class Keyring_Reactions_Base { } else { // Otherwise reset all default/built-ins $this->set_option( array( - 'auto_import' => null, - 'auto_approve' => null, + 'auto_import' => false, + 'auto_approve' => false, + 'limit_posts' => '', static::OPTNAME_POSTS => array(), static::OPTNAME_POSTPOS => 0, ) ); @@ -342,6 +365,13 @@ abstract class Keyring_Reactions_Base { // to handle processing/storing options for import. Make sure to // end it with $this->step = 'import' (if you're ready to continue) $this->handle_request_options(); + if ( method_exists( $this, 'full_custom_request_options' ) ) { + $this->handle_request_options(); + return; + } + else { + $this->handle_request_options(); + } break; } @@ -536,6 +566,30 @@ abstract class Keyring_Reactions_Base { service->get_token()->get_display(); ?> + + + + + + + + @@ -851,11 +905,22 @@ abstract class Keyring_Reactions_Base { //$raw = array ( get_post( 8180 )); $args = array ( - 'meta_key' => 'syndication_urls', - 'post_type' => 'any', - 'posts_per_page' => -1, - 'post_status' => 'publish', + 'meta_key' => 'syndication_urls', + 'post_type' => 'any', + 'posts_per_page' => -1, + 'post_status' => 'publish', + 'orderby' => 'post_date', + 'order' => 'DESC', ); + $limit = $this->get_option('limit_posts'); + if ( $limit != '') { + $args['date_query'] = array( + array( + 'after' => $limit . ' ago', + ) + ); + } + $raw = get_posts( $args ); foreach ( $raw as $p ) {