public static function nprstory_cron_pull() { // here we should get the list of IDs/full urls that need to be checked hourly //because this is run on cron, and may be fired off by an non-admin, we need to load a bunch of stuff require_once ABSPATH . 'wp-admin/includes/file.php'; require_once ABSPATH . 'wp-admin/includes/media.php'; // This is debug code. It may be save future devs some time; please keep it around. /* $now = gmDate("D, d M Y G:i:s O "); error_log("right now the time is -- ".$now); // debug use */ // here we go. $num = get_option('ds_npr_num'); for ($i = 0; $i < $num; $i++) { $api = new NPRAPIWordpress(); $q = 'ds_npr_query_' . $i; $query_string = get_option($q); if (!empty($query_string)) { nprstory_error_log('Cron ' . $i . ' querying NPR API for ' . $query_string); //if the query string contains the pull url and 'query', just make request from the API if (stristr($query_string, get_option('ds_npr_api_pull_url')) && stristr($query_string, 'query')) { $api->query_by_url($query_string); } else { //if the string doesn't contain the base url, try to query using an ID if (stristr($query_string, 'http:')) { error_log('Not going to run query because the query string contains http and is not pointing to the pullURL: ' . $query_string); // debug use } else { $params = array('id' => $query_string, 'apiKey' => get_option('ds_npr_api_key')); $api->request($params, 'query', get_option('ds_npr_api_pull_url')); } } $api->parse(); try { if (empty($api->message) || $api->message->level != 'warning') { //check the publish flag and send that along. $pub_flag = FALSE; $pub_option = get_option('ds_npr_query_publish_' . $i); if ($pub_option == 'Publish') { $pub_flag = TRUE; } $story = $api->update_posts_from_stories($pub_flag, $i); } 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 } } } catch (Exception $e) { error_log('NPR Story API: error in ' . __FUNCTION__ . ' like this :' . $e); // debug use } } } }
public static function ds_npr_story_cron_pull() { // here we should get the list of IDs/full urls that need to be checked hourly //because this is run on cron, and may be fired off by an non-admin, we need to load a bunch of stuff require_once WP_PLUGIN_DIR . '/../../wp-admin/includes/file.php'; require_once WP_PLUGIN_DIR . '/../../wp-admin/includes/media.php'; require_once WP_PLUGIN_DIR . '/../../wp-admin/includes/admin.php'; require_once WP_PLUGIN_DIR . '/../../wp-load.php'; require_once WP_PLUGIN_DIR . '/../../wp-includes/class-wp-error.php'; //this was debug code it may be good keep it around for a bit //$now = gmDate("D, d M Y G:i:s O "); //error_log("right now the time is -- ".$now); //here we go. $num = get_option('ds_npr_num'); for ($i = 0; $i < $num; $i++) { $api = new NPRAPIWordpress(); $q = 'ds_npr_query_' . $i; $query_string = get_option($q); if (!empty($query_string)) { error_log('Cron ' . $i . ' querying NPR API for ' . $query_string); //if the query string contains the pull url and 'query', just make request from the API if (stristr($query_string, get_option('ds_npr_api_pull_url')) && stristr($query_string, 'query')) { $api->query_by_url($query_string); } else { //if the string doesn't contain the base url, try to query using an ID if (stristr($query_string, 'http:')) { error_log('Not going to run query because the query string contains http and is not pointing to the pullURL'); } else { $params = array('id' => $query_string, 'apiKey' => get_option('ds_npr_api_key')); $api->request($params, 'query', get_option('ds_npr_api_pull_url')); } } $api->parse(); //var_dump($api); try { if (empty($api->message) || $api->message->level != 'warning') { //check the publish flag and send that along. $pub_flag = FALSE; $pub_option = get_option('ds_npr_query_publish_' . $i); if ($pub_option == 'Publish') { $pub_flag = TRUE; } $story = $api->update_posts_from_stories($pub_flag); } else { if (empty($story)) { error_log('Not going to save story. Return from query=' . $query_string . ', we got an error=' . $api->message->id . ' error'); } } } catch (Exception $e) { error_log('we have an error going in ' . __FUNCTION__ . ' like this :' . $e); } } } }