You are here

public function SocialContentTumblr::getRows in Social Content 7.2

Get the rows to import.

Parameters

mixed $last_id: The id of the last import.

Return value

mixed The array of the rows, or FALSE on error.

Overrides SocialContent::getRows

File

modules/tumblr/social_content_tumblr.class.inc, line 157
Social Content Tumblr class.

Class

SocialContentTumblr
@file Social Content Tumblr class.

Code

public function getRows($last_id = NULL) {
  $settings = $this->settings['instance'];
  $global_settings = $this->settings['global'];
  $url = $global_settings['api_url'] . '/blog/' . $settings['host_name'];
  $params['api_key'] = $global_settings['oauth_consumer_key'];
  if (!empty($settings['limit'])) {
    $params['limit'] = $settings['limit'];
  }
  if (!empty($last_id)) {
    $params['offset'] = $last_id;
  }
  $params = drupal_http_build_query($params);
  $rows = array();
  foreach ($settings['type'] as $key => $value) {
    if (!$value) {
      continue;
    }
    $response = drupal_http_request($url . "/posts/{$key}?{$params}");
    if ($response->code == 200) {
      $data = json_decode($response->data);
      if (isset($data->response->posts)) {

        // Add blog title to each row.
        foreach ($data->response->posts as &$post) {
          $post->blog_title = $data->response->blog->title;
        }
        $rows += $data->response->posts;
      }
    }
  }
  return $rows;
}