예제 #1
0
function send_to_identica(&$model, &$rec)
{
    if (!get_profile_id()) {
        return;
    }
    // if the Record does not have a title or uri, bail out
    if (!isset($rec->title) || !isset($rec->uri)) {
        return;
    }
    if (get_option('identica_status') != 'enabled') {
        return;
    }
    // truncate the tweet at 140 chars
    $notice_content = substr($rec->title, 0, 140);
    // activate Twitter Tools
    $_GET['activate'] = true;
    // trip the init() function
    aktt_init();
    // get the Twitter Tools object
    global $aktt;
    // make a new tweet object
    $tweet = new aktt_tweet();
    // set the tweetbody
    $tweet->tw_text = stripslashes($notice_content);
    // send the dent to Identica
    global $db;
    $aktt->twitter_username = get_option('aktt_identica_username');
    $aktt->twitter_password = md5_decrypt(stripslashes(get_option('aktt_identica_password')), $db->dbname);
    do_dent($tweet);
}
예제 #2
0
function send_to_twitter(&$model, &$rec)
{
    if (!get_profile_id()) {
        return;
    }
    // if the Record does not have a title or uri, bail out
    if (!isset($rec->title) || !isset($rec->uri)) {
        return;
    }
    if (get_option('twitter_status') != 'enabled') {
        return;
    }
    global $db, $prefix;
    $sql = "SELECT oauth_key,oauth_secret FROM " . $prefix . "twitter_users WHERE profile_id = " . get_profile_id();
    $result = $db->get_result($sql);
    if ($db->num_rows($result) == 1) {
        // http://abrah.am
        lib_include('twitteroauth');
        $key = $db->result_value($result, 0, 'oauth_key');
        $secret = $db->result_value($result, 0, 'oauth_secret');
        $consumer_key = environment('twitterKey');
        $consumer_secret = environment('twitterSecret');
        $to = new TwitterOAuth($consumer_key, $consumer_secret, $key, $secret);
        $notice_content = substr($rec->title, 0, 140);
        $content = $to->OAuthRequest('https://twitter.com/statuses/update.xml', array('status' => $notice_content), 'POST');
    } else {
        wp_plugin_include('twitter-tools');
        // set a flag on aktt
        global $aktt;
        $aktt->tweet_from_sidebar = false;
        // truncate the tweet at 140 chars
        $notice_content = substr($rec->title, 0, 140);
        // activate Twitter Tools
        $_GET['activate'] = true;
        // trip the init() function
        aktt_init();
        // make a new tweet object
        $tweet = new aktt_tweet();
        // set the tweetbody
        $tweet->tw_text = stripslashes($notice_content);
        // send the tweet to Twitter
        $aktt->do_tweet($tweet);
    }
}
예제 #3
0
function update_my_tweets()
{
    $profile_id = get_profile_id();
    if (!$profile_id) {
        return;
    }
    // activate Twitter Tools
    $_GET['activate'] = true;
    // trip the init() function
    aktt_init();
    // get the Twitter Tools object
    global $wpdb, $aktt, $db;
    if (empty($aktt->twitter_username) || empty($aktt->twitter_password)) {
        return;
    }
    // make a new tweet object
    $tweet = new aktt_tweet();
    // let the last update run for 5 minutes
    if (time() - intval(get_option('aktt_doing_tweet_download')) < 300) {
        return;
    }
    update_option('aktt_doing_tweet_download', time());
    if (empty($aktt->twitter_username) || empty($aktt->twitter_password)) {
        update_option('aktt_doing_tweet_download', '0');
        die;
    }
    require_once ABSPATH . WPINC . '/class-snoopy.php';
    $snoop = new Snoopy();
    $snoop->agent = 'Twitter Tools http://alexking.org/projects/wordpress';
    $snoop->user = $aktt->twitter_username;
    $snoop->pass = $aktt->twitter_password;
    $snoop->fetch('http://tweetpass.com/statuses/friends_timeline.json');
    if (!strpos($snoop->response_code, '200')) {
        update_option('aktt_doing_tweet_download', '0');
        return;
    }
    $data = $snoop->results;
    $hash = md5($data);
    if ($hash == get_option('aktt_update_hash')) {
        update_option('aktt_doing_tweet_download', '0');
        return;
    }
    $json = new Services_JSON();
    $tweets = $json->decode($data);
    if (is_array($tweets) && count($tweets) > 0) {
        $tweet_ids = array();
        foreach ($tweets as $tweet) {
            $tweet_ids[] = $wpdb->escape($tweet->id);
        }
        $existing_ids = $wpdb->get_col("\n      SELECT tw_id\n      FROM {$wpdb->aktt}\n      WHERE tw_id\n      IN ('" . implode("', '", $tweet_ids) . "')\n    ");
        $new_tweets = array();
        foreach ($tweets as $tw_data) {
            if (!$existing_ids || !in_array($tw_data->id, $existing_ids)) {
                $tweet = new aktt_tweet($tw_data->id, $tw_data->text);
                $tweet->tw_created_at = $tweet->twdate_to_time($tw_data->created_at);
                $new_tweets[] = $tweet;
            }
        }
        foreach ($new_tweets as $tweet) {
            $AkTwitter =& $db->get_table('ak_twitter');
            $Entry =& $db->get_table('entries');
            $t = $AkTwitter->find_by('tw_id', $tweet->tw_id);
            if (!$t) {
                $tweet->add();
                $created = date("Y-m-d H:i:s", $tweet->tw_created_at - 8 * 3600);
                $t = $AkTwitter->find($db->last_insert_id($AkTwitter));
                if ($t) {
                    $t->set_etag();
                }
                $atomentry = $Entry->find_by(array('resource' => 'ak_twitter', 'record_id' => $t->id), $t->id);
                if ($atomentry) {
                    $result = $db->get_result("UPDATE entries SET last_modified = '{$created}' WHERE id = " . $atomentry->id);
                }
                $user = new Snoopy();
                $user->agent = 'Twitter Tools http://alexking.org/projects/wordpress';
                $user->user = $aktt->twitter_username;
                $user->pass = $aktt->twitter_password;
                $user->fetch('http://tweetpass.com/statuses/show/' . $tweet->tw_id . '.json');
                $data = $user->results;
                $json = new Services_JSON();
                $notice = $json->decode($data);
                $uarr = $notice->user;
                $TwitterUser =& $db->model('TwitterUser');
                $twuser = $TwitterUser->find_by('twitter_id', $uarr->id);
                if (!$twuser) {
                    $twuser = $TwitterUser->base();
                    $twuser->set_value('description', $uarr->description);
                    $twuser->set_value('screen_name', $uarr->screen_name);
                    $twuser->set_value('url', $uarr->url);
                    $twuser->set_value('name', $uarr->name);
                    $twuser->set_value('protected', $uarr->protected);
                    $twuser->set_value('followers_count', $uarr->followers_count);
                    $twuser->set_value('profile_image_url', $uarr->profile_image_url);
                    $twuser->set_value('location', $uarr->location);
                    $twuser->set_value('twitter_id', $uarr->id);
                    $twuser->save_changes();
                }
                $t->set_value('profile_id', $twuser->twitter_id);
                $t->save_changes();
            }
            $AkTwitter->has_and_belongs_to_many('identities');
            $join =& $db->get_table($Entry->join_table_for('ak_twitter', 'identities'));
            $j = $join->base();
            $j->set_value('aktwitter_id', $t->id);
            $j->set_value('identity_id', get_profile_id());
            $j->save_changes();
        }
    }
    update_option('aktt_update_hash', $hash);
    update_option('aktt_last_tweet_download', time());
    update_option('aktt_doing_tweet_download', '0');
}