/** * Fetch a single tweet * * This function is not used in the plugin, it's here to be used when debugging or for custom use * * @param string $id Tweet ID ('454752497002115072' in 'https://twitter.com/ozh/statuses/454752497002115072') * @return bool|object false if not found, or tweet object (see https://dev.twitter.com/docs/platform-objects/tweets) */ function ozh_ta_get_single_tweet($id) { global $ozh_ta; if (!ozh_ta_is_configured()) { ozh_ta_debug('Config incomplete, cannot import tweets'); return false; } $api = 'https://api.twitter.com/1.1/statuses/show.json?id=' . $id; $headers = array('Authorization' => 'Bearer ' . $ozh_ta['access_token']); ozh_ta_debug("Polling {$api}"); $response = wp_remote_get($api, array('headers' => $headers, 'timeout' => 10)); $tweet = json_decode(wp_remote_retrieve_body($response)); if (isset($tweet->errors)) { ozh_ta_debug("Error with tweet #{$id} : " . $tweet->errors[0]->message); return false; } return $tweet; }
function ozh_ta_reload($url, $delay = 30) { $url = str_replace('&', '&', $url); ozh_ta_debug("Reloading {$url} in {$delay}"); ?> <p>Your browser will refresh this page in <strong id='countdown'><?php echo "{$delay}"; ?> </strong> seconds. If the page does not refresh, click here: <a class="button" href="<?php echo $url; ?> ">Next please</a></p> <script type='text/javascript'> var seconds = <?php echo $delay; ?> ; var millisec=0; var ts; function ozh_ta_display(){ if ( millisec <= 0 ){ millisec = 9; seconds -=1; } if ( seconds <= -1 ) { millisec = 0; seconds += 1; } else { millisec -= 1; } jQuery('#countdown').text( seconds+"."+millisec ); ts = setTimeout("ozh_ta_display()",100); if( seconds == 0 && millisec == 1 ) { clearTimeout( ts ); ozh_ta_nextpage(); } } ozh_ta_display(); function ozh_ta_nextpage() { window.location="<?php echo $url; ?> "; } </script><?php }
function ozh_ta_cron_import() { ozh_ta_require('import.php'); ozh_ta_debug('Starting cron job'); ozh_ta_get_tweets(); }
/** * Schedule next twitter archiving * * @param int $delay Number of second before next archiving */ function ozh_ta_schedule_next($delay = 30) { wp_clear_scheduled_hook('ozh_ta_cron_import'); ozh_ta_debug("Schedule cleared"); if ($delay) { wp_schedule_single_event(time() + $delay, 'ozh_ta_cron_import'); ozh_ta_debug("Schedule next in {$delay}"); } }
function ozh_ta_twitter_avatar($echo = true) { $what = ozh_ta_get_total('profile_image_url'); ozh_ta_debug($what); if ($echo) { echo $what; } return $what; }