You are here

function socialfeed_twitter in Social Feed 6

Retrieves Data from Twitter.

2 calls to socialfeed_twitter()
socialfeed_cron in ./socialfeed.module
Implements hook_cron().
socialfeed_settings_form_submit in ./socialfeed.module
Implements form_submit().

File

./socialfeed.module, line 439
Module for fetching data from Facebook, Twitter, Youtube, and Foursquare. This module provides block content retrieved from a

Code

function socialfeed_twitter() {
  $twitterprofile = variable_get('socialfeed_twitter_profile_id', FALSE);
  $twitter_url = "http://twitter.com/statuses/user_timeline/{$twitterprofile}.xml";
  $buffer = drupal_http_request($twitter_url, array(), 'GET', NULL, 1);
  if ($buffer->status_message == 'OK') {
    libxml_use_internal_errors(TRUE);
    try {
      $xml = new SimpleXMLElement($buffer->data);
    } catch (Exception $e) {

      // Retreat!
      return;
    }
    $status = $xml->status;

    /**
     * Inserts Twitter Data.
     */
    function socialfeed_twitter_insert($table, $data) {
      $query = "SELECT * FROM {socialfeed_post} WHERE id = '%s'";
      $sql = db_query_range($query, $data->id, 0, 1);
      while ($item = db_fetch_object($sql)) {
        $myterms[] = $item;
      }
      if (!$myterms) {
        $post = array();
        $post['time'] = strtotime($data->created_at);
        $post['message'] = $data->text;
        $post['post_type'] = 'twitter';
        $post['id'] = $data->id;
        $post['name'] = $data->user->screen_name;
        drupal_write_record('socialfeed_post', $post);
      }
    }
    if ($status) {
      foreach ($status as $object) {
        socialfeed_twitter_insert("socialfeed_post", $object);
      }
    }
  }
}