Exemple #1
0
function bb_post_tweet($t)
{
    $access_token = '137364143-B8AuSGSHuTR0CTzEUhGaqhJJgi58Vr5EGf0eVIpT';
    $access_token_secret = 'I6t3BCirrk6YuCTAgVZuXFWN31d0K9sygx6grEgFU0';
    // POST a tweet using OAuth authentication
    $retarr = post_tweet(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, $t, $access_token, $access_token_secret, true, true);
}
function post_ff_tweet()
{
    global $db, $default_tag;
    // Build a list of up to 10 users for #FF tweets
    $user_list = array();
    // Get most mentioned users
    // Don't use leaders or those mentioned by leaders
    // They will tend to repeat too often
    $query = "SELECT count(*) AS cnt, users.screen_name\r\n\t\tFROM tweet_mentions, users\r\n\t\tWHERE tweet_mentions.target_user_id = users.user_id\r\n\t\tAND tweet_mentions.created_at >= now() - interval 7 day\r\n\t\tAND tweet_mentions.source_user_id NOT IN (\r\n\t\t\tSELECT user_id \r\n\t\t\tFROM leaders)\r\n\t\tAND users.user_id NOT IN (\r\n\t\t\tSELECT user_id \r\n\t\t\tFROM leaders)\r\n\t\tGROUP BY tweet_mentions.target_user_id\r\n\t\tORDER BY cnt DESC \r\n\t\tLIMIT 5";
    // Add these users to the $user_list array
    $results = $db->select($query);
    while ($row = mysqli_fetch_assoc($results)) {
        $user_list[] = $row['screen_name'];
    }
    // Get most retweeted users
    // Don't use leaders or those retweeted by leaders
    // They will repeat too often
    $query = "SELECT count(*) AS cnt, users.screen_name\r\n\t\tFROM tweet_retweets, users\r\n\t\tWHERE tweet_retweets.target_user_id = users.user_id\r\n\t\tAND tweet_retweets.created_at >= now() - interval 7 day\r\n\t\tAND tweet_retweets.source_user_id NOT IN (\r\n\t\t\tSELECT user_id \r\n\t\t\tFROM leaders)\r\n\t\tAND users.user_id NOT IN (\r\n\t\t\tSELECT user_id \r\n\t\t\tFROM leaders)\r\n\t\tGROUP BY tweet_retweets.target_user_id\r\n\t\tORDER BY cnt DESC \r\n\t\tLIMIT 10";
    // Add these users to $user_list array, stop at 10 total
    $results = $db->select($query);
    while (($row = mysqli_fetch_assoc($results)) && sizeof($user_list) < 10) {
        if (!in_array($row['screen_name'], $user_list)) {
            $user_list[] = $row['screen_name'];
        }
    }
    // Send a tweet with the first 5 users
    // $default_tag comes from config.php
    $tweet_text1 = '#FF';
    for ($i = 0; $i < 5; ++$i) {
        $tweet_text1 .= ' @' . $user_list[$i];
    }
    $tweet_text1 .= " {$default_tag}";
    $http_code1 = post_tweet($tweet_text1);
    // Send a tweet with the next 5 users
    $tweet_text2 = '#FF';
    for ($i = 5; $i < 10; ++$i) {
        $tweet_text2 .= ' @' . $user_list[$i];
    }
    $tweet_text2 .= " {$default_tag}";
    $http_code2 = post_tweet($tweet_text2);
    // Return results of both tweets
    return array('http_code1' => $http_code1, 'tweet_text1' => $tweet_text1, 'http_code2' => $http_code2, 'tweet_text2' => $tweet_text2);
}
Exemple #3
0
<?php

require 'globals.php';
require 'oauth_helper.php';
// Fill in the next 2 variables based on the user we're doing this for.
// Currently these are hard coded for matthew101HS:
$access_token = '15201275-loypZtq58TRB1qoIIu6fTw6TSEqluGZ1aMKgVJjJe';
$access_token_secret = 'haKjTuzH9N6UPhOBZDKSsu6FAZzIvLNbwGhi5wfy00Y';
$tweet = 'Hello World!';
// POST a tweet using OAuth authentication
$retarr = post_tweet(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, $tweet, $access_token, $access_token_secret, false, true);
exit(0);
/**
* Call twitter to post a tweet
* @param string $consumer_key obtained when you registered your app
* @param string $consumer_secret obtained when you registered your app
* @param string $status_message
* @param string $access_token obtained from get_request_token
* @param string $access_token_secret obtained from get_request_token
* @param bool $usePost use HTTP POST instead of GET
* @param bool $passOAuthInHeader pass OAuth credentials in HTTP header
* @return response string or empty array on error
*/
function post_tweet($consumer_key, $consumer_secret, $status_message, $access_token, $access_token_secret, $usePost = false, $passOAuthInHeader = true)
{
    $retarr = array();
    // return value
    $response = array();
    //$url = 'http://api.twitter.com/1/statuses/update.json';
    $url = 'http://api.twitter.com/1.1/friendships/incoming.json';
    //$params['status'] = $status_message;
Exemple #4
0
 function reset()
 {
     global $db;
     require_once dirname(__FILE__) . '/connectDB.php';
     require_once dirname(__FILE__) . '/user.php';
     $today = date('d');
     $startdate = strtotime(date('Y-m-') . ($today + 1));
     require_once dirname(__FILE__) . '/twitter.php';
     post_tweet('Server ' . $this->getName() . ' restarted.  New Round begins ' . date('Y-m-d H:i O', $startdate) . '. http://t.heproject.com/server/' . $this->getID());
     $players = mysql_query("SELECT user_id FROM server_data WHERE server_id=" . $this->getID() . " AND `key`='gold'", $db) or die(mysql_error());
     while ($player = mysql_fetch_assoc($players)) {
         $player_data = new user($player['user_id'], $this, true);
         mysql_query("INSERT INTO board (round_end, server_id, user_id, score) VALUES ({$startdate}, {$this->id}, " . $player['user_id'] . ", " . $player_data->calculateScore() . ")") or die(mysql_error());
         if ($player_data->getValue('twitter')) {
             //send_tweet($player_data->getValue('twitter'), 'Server '.$this->getName().' restarted.  New Round begins '.date('Y-m-d H:i',$startdate));
         } else {
             if ($player_data->getValue('email')) {
                 mail($player_data->getValue('email'), '[The Project] Server ' . $this->getName() . ' restarted', ' New Round begins ' . date('Y-m-d H:i O', $startdate) . ".\n\n <http://t.heproject.com/server/" . $this->getID() . '>', 'From: t@heproject.com');
             }
         }
     }
     mysql_query("UPDATE servers SET previous_week=" . $startdate . ", previous_day=" . $startdate . "  WHERE server_id={$this->id}", $db) or die(mysql_error());
     mysql_query("DELETE FROM server_data WHERE server_id={$this->id}", $db) or die(mysql_error());
     mysql_query("DELETE FROM server_cities WHERE server_id={$this->id}", $db) or die(mysql_error());
     mysql_query("DELETE FROM server_cities_data WHERE server_id={$this->id}", $db) or die(mysql_error());
     mysql_query("DELETE FROM server_unit_transaction WHERE server_id={$this->id}", $db) or die(mysql_error());
     mysql_query("DELETE FROM server_building_transaction WHERE server_id={$this->id}", $db) or die(mysql_error());
     mysql_query("DELETE FROM server_attack_results WHERE server_id={$this->id}", $db) or die(mysql_error());
 }
<?php

/**
* post_tweet.php
* Example of posting a tweet with OAuth
* Latest copy of this code: 
* http://140dev.com/twitter-api-programming-tutorials/hello-twitter-oauth-php/
* @author Adam Green <*****@*****.**>
* @license GNU Public License
*/
$tweet_text = 'Hello Twitter';
print "Posting...\n";
$result = post_tweet($tweet_text);
print "Response code: " . $result . "\n";
function post_tweet($tweet_text)
{
    // Use Matt Harris' OAuth library to make the connection
    // This lives at: https://github.com/themattharris/tmhOAuth
    require_once 'tmhoauth/tmhOAuth.php';
    // Set the authorization values
    // In keeping with the OAuth tradition of maximum confusion,
    // the names of some of these values are different from the Twitter Dev interface
    // user_token is called Access Token on the Dev site
    // user_secret is called Access Token Secret on the Dev site
    // The values here have asterisks to hide the true contents
    // You need to use the actual values from Twitter
    $connection = new tmhOAuth(array('consumer_key' => '******', 'consumer_secret' => '******', 'user_token' => '******', 'user_secret' => '******'));
    // Make the API call
    $connection->request('POST', $connection->url('1/statuses/update'), array('status' => $tweet_text));
    return $connection->response['code'];
}
<?php

//
// Run this as a cronjob every minute
require 'config.php';
require 'db_lib.php';
$db = new db();
require 'oauth_lib.php';
$connection = get_connection();
// Load tweeting functions
require 'autotweet_lib.php';
// Get any tweets scheduled for the current day and time
$query = "SELECT id, tweet_text\r\n\tFROM autotweet_scheduled\r\n\tWHERE (tweet_date = date(now())\r\n\t\tAND tweet_hour = hour(now())\r\n\t\tAND tweet_minute = minute(now()))\r\n\tAND NOT posted";
$results = $db->select($query);
while ($row = mysqli_fetch_assoc($results)) {
    $id = $row['id'];
    $tweet_text = $row['tweet_text'];
    // Post this tweet
    $http_code = post_tweet($tweet_text);
    // Flag it as having been posted
    // Even if the $http_code is not 200, this is still flagged as posted
    // It is safer to not try to repeat this posting to avoid duplication
    $db->update('autotweet_scheduled', 'posted=1', "id={$id}");
    // Log this tweet
    $db->insert('autotweet_log', "tweet_type='text', scheduled=1, id={$id}, tweet_text='{$tweet_text}', http_code={$http_code}");
}