Exemple #1
0
if ($run_cron == true) {
    /*
    New to 0.3 - Some people on super cheap hosting seem to get
    SQL errors - output them if they occur
    */
    $db->output_error = 1;
    //Set cron status
    $cron->set_cron_state('follow', 1);
    //Get credentials
    $ap_creds = $db->get_ap_creds();
    //Loop through all accounts
    $q1 = $db->query("SELECT * FROM " . DB_PREFIX . "authed_users ORDER BY (followers_count + friends_count) ASC");
    while ($q1a = $db->fetch_array($q1)) {
        //Defines
        $connection = new TwitterOAuth($ap_creds['consumer_key'], $ap_creds['consumer_secret'], $q1a['oauth_token'], $q1a['oauth_token_secret']);
        $cron->set_user_id($q1a['id']);
        $cron->set_first_pass_done($q1a['fr_fw_fp']);
        $cron->set_log($q1a['log_data']);
        $cron->set_throttle_time(0, 'fr');
        $cron->set_throttle_time(0, 'fw');
        $cron->set_fr_fw_issue(0);
        //Refresh details
        $content = $connection->get('account/verify_credentials');
        if ($connection->http_code == 200) {
            //Update DB
            $tw_user = array('id' => $q1a['id'], 'profile_image_url' => $content->profile_image_url, 'screen_name' => $content->screen_name, 'followers_count' => $content->followers_count, 'friends_count' => $content->friends_count, 'last_updated' => date("Y-m-d H:i:s"));
            $db->store_authed_user($tw_user);
            /*
            API Version 1.1 has really killed the limits here; from 350 per hour to 15 per
            15 minutes. Also Follower and Friend lists are now separately rate limited; code
            adjusted below to set individual throttle rates. Thanks Twitter, real helpful (not).
}
if ($run_cron != true) {
    exit;
}
if (!is_connected()) {
    //internet connection seems broken
    exit;
}
$db->output_error = 1;
//Set cron status
$cron->set_cron_state('bot_tweets', 1);
$cron->set_log(1);
$ap_creds = $db->get_ap_creds();
$configs = $db->query("\n    SELECT *\n      FROM " . DB_PREFIX . "users_config\n     WHERE tweet_bot_status=1;\n");
while ($userConfig = mysql_fetch_array($configs, MYSQL_ASSOC)) {
    $cron->set_user_id($userConfig['user_id']);
    $tweetRate = $userConfig['tweeting_rate'];
    $authUserData = $db->get_user_data($userConfig['user_id']);
    $connection = new TwitterOAuth($ap_creds['consumer_key'], $ap_creds['consumer_secret'], $authUserData['oauth_token'], $authUserData['oauth_token_secret']);
    $tweetsToSend = $db->query("\n        SELECT id, tweet_content\n          FROM " . DB_PREFIX . "tweets_queue\n         WHERE datetime_tweeted IS NULL\n               AND user_id='{$userConfig['user_id']}'\n         LIMIT {$tweetRate};\n    ");
    while ($tweet = mysql_fetch_array($tweetsToSend, MYSQL_ASSOC)) {
        $connection->post('statuses/update', array('status' => $tweet['tweet_content']));
        //Log result - reasons for a non 200 include duplicate tweets, too many tweets
        //posted in a period of time, etc etc.
        if ($connection->http_code == 200) {
            $cron->store_cron_log(7, $cron_txts[18] . $tweet['tweet_content'] . $cron_txts[19], '');
        } else {
            $cron->store_cron_log(7, $cron_txts[18] . $tweet['tweet_content'] . $cron_txts[20], '');
        }
        $postedDateTime = date('Y-m-d H:i:s');
        $db->query("\n            UPDATE " . DB_PREFIX . "tweets_queue\n               SET datetime_tweeted='{$postedDateTime}'\n             WHERE id={$tweet['id']};\n        ");
    echo mainFuncs::push_response(23);
    $run_cron = false;
} else {
    if ($cron->get_cron_state('upd_info') == 1 || $cron->get_cron_state('follow') == 1) {
        echo mainFuncs::push_response(24);
        $run_cron = false;
    }
}
if ($run_cron != true) {
    exit;
}
$db->output_error = 1;
//Set cron status
$cron->set_cron_state('upd_info', 1);
$cron->set_log(1);
$cron->set_user_id(CRON_SEARCH_AUTH_ID);
//Get credentials
$ap_creds = $db->get_ap_creds();
$authUserData = $db->get_user_data(CRON_SEARCH_AUTH_ID);
$connection = new TwitterOAuth($ap_creds['consumer_key'], $ap_creds['consumer_secret'], $authUserData['oauth_token'], $authUserData['oauth_token_secret']);
$rate_con = $cron->get_remaining_hits();
$usersRequestsRemaining = intval($rate_con['ul_remaining']);
while ($usersRequestsRemaining > 10) {
    $result = getIds($db);
    $user_ids = array();
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
        $user_ids[] = $row['user_id'];
    }
    if (empty($user_ids)) {
        $cron->set_cron_state('upd_info', 0);
        exit;