function insert_feeds_in_db($feed_url, $blog, $twitter, $bdd) { try { // step 1 : get the flux $content = file_get_contents($feed_url); $x = new SimpleXmlElement($content); if (!isset($x->channel->item)) { return; } foreach ($x->channel->item as $entry) { $title = mb_convert_encoding($entry->title, 'HTML-ENTITIES', 'UTF-8'); $title = addslashes($title); $link = $entry->link; // create tweet $tweet = create_tweet($title, $link, $twitter); // step 2 : insert in db $request = 'INSERT INTO list_of_feeds VALUES(\'' . $tweet . '\', \'' . $blog . '\')'; $bdd->exec($request); // just the first one break; } echo "\n" . 'Feeds saved in DB of ' . $blog . "\n"; } catch (Exception $e) { echo 'Exception reçue : ', $e->getMessage(), "\n"; } }
function thanks_for_RT($message, $where) { global $consumerKey, $consumerSecret, $OAuthToken, $OAuthSecret; // create new instance $tweet = new TwitterOAuth($consumerKey, $consumerSecret, $OAuthToken, $OAuthSecret); $thanks_tweet = $message; // get $retweets = $tweet->get('statuses/retweets_of_me'); $retweets_id = array(); foreach ($retweets as $user) { $retweets_id[] = array('tweet_id' => $user->id_str, 'created_at' => $user->created_at, 'text' => $user->text); } $screen_names = array(); // for each retweet, get the last user who retweeded. foreach ($retweets_id as $current_retweet) { $method = 'statuses/' . $current_retweet['tweet_id'] . '/retweeted_by'; $retweet = $tweet->get($method, array('count' => '1')); if (!isset($retweet)) { continue; } $screen_name = $retweet[0]->screen_name; $screen_names[] = $screen_name; } // delete doublon $screen_names = array_unique($screen_names); if (sizeof($screen_names) == 0) { return; } foreach ($screen_names as $screen_name) { $more_140 = create_tweet($thanks_tweet, $screen_name, $where); if ($more_140 == false) { break; } } echo $thanks_tweet . "\n"; send_tweet($thanks_tweet); }