/** * Request handler * * @return void */ static function controller() { if (isset($_GET['aktt_action'])) { switch ($_GET['aktt_action']) { case 'download_account_tweets': if (empty($_GET['acct_id']) || !AKTT::social_key_auth()) { wp_die(__('Sorry, try again.', 'twitter-tools')); } $acct_id = intval($_GET['acct_id']); self::get_social_accounts(); if (isset(self::$accounts[$acct_id])) { if ($tweets = self::$accounts[$acct_id]->download_tweets()) { self::$accounts[$acct_id]->save_tweets($tweets); } } die; break; case 'import_tweet': // check for status_id && auth key if (empty($_GET['tweet_id']) || !AKTT::social_key_auth()) { wp_die(__('Sorry, try again.', 'twitter-tools')); } // check for account_name $username = !empty($_GET['username']) ? stripslashes($_GET['username']) : null; // download tweet $tweet = self::download_tweet($_GET['tweet_id'], $username); if (!is_a($tweet, 'stdClass')) { wp_die('Failed to download tweet.'); } // store tweet $t = new AKTT_Tweet($tweet); if (!$t->exists_by_guid()) { $t->add(); } die; break; case 'backfill_tweet_data': if (empty($_GET['tweet_id']) || !AKTT::social_key_auth()) { wp_die(__('Sorry, try again.', 'twitter-tools')); } $t = new AKTT_Tweet(stripslashes($_GET['tweet_id'])); if (!$t->get_post()) { die; } $usernames = wp_get_object_terms($t->post->ID, 'aktt_accounts'); $username = $usernames[0]->slug; $tweet = self::download_tweet($_GET['tweet_id'], $username); if (!is_a($tweet, 'stdClass')) { wp_die('Failed to download tweet'); } $t->update_twitter_data($tweet); die; break; } } }
function aktt_upgrade_30_run($count = 25) { global $wpdb; // pull next tweet(s) $count = intval($count); $tweets = $wpdb->get_results("\n\t\tSELECT *\n\t\tFROM {$wpdb->aktt}\n\t\tWHERE upgrade_30 = 0\n\t\tLIMIT {$count}\n\t"); // upgrade if (count($tweets)) { $upgraded = array(); $username = get_option('aktt_twitter_username'); // already passed sanity check to make sure this exists foreach ($tweets as $tweet) { if (trim($tweet->tw_text) == '') { continue; } $t = new AKTT_Tweet($tweet->tw_id); $t->data = new stdClass(); $t->data->id = $t->data->id_str = $tweet->tw_id; $t->data->text = $tweet->tw_text; $t->data->created_at = date('D M d H:i:s +0000 Y', strtotime($tweet->tw_created_at . ' +0000')); $t->data->in_reply_to_screen_name = $tweet->tw_reply_username; $t->data->in_reply_to_status_id = $t->data->in_reply_to_status_id_str = $tweet->tw_reply_tweet; $t->data->user = new stdClass(); $t->data->user->screen_name = $username; $t->raw_data = json_encode($t->data); // skip if duplicate if ($t->exists_by_guid()) { // already there, so mark as upgraded $upgraded[] = intval($tweet->id); continue; } if ($t->add()) { // add meta - upgraded tweet update_post_meta($t->post_id, '_aktt_upgraded_30', 1); update_post_meta($t->post_id, '_aktt_30_backfill_needed', 1); $upgraded[] = intval($tweet->id); } } if (count($upgraded)) { $wpdb->query("\n\t\t\t\tUPDATE {$wpdb->aktt}\n\t\t\t\tSET upgrade_30 = 1\n\t\t\t\tWHERE id IN (" . implode(',', $upgraded) . ")\n\t\t\t"); } } // return stats $to_upgrade = $wpdb->get_var("\n\t\tSELECT count(id)\n\t\tFROM {$wpdb->aktt}\n\t\tWHERE upgrade_30 = 0\n\t"); return $to_upgrade; }