/** * 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; } } }