You are here

public function SocialContentYoutube::getRows in Social Content 7.2

Get the rows to import.

Parameters

mixed $last_id: The id of the last import.

Return value

array Array with the rows.

Overrides SocialContent::getRows

File

modules/youtube/social_content_youtube.class.inc, line 172
Social Content Youtube class.

Class

SocialContentYoutube
@file Social Content Youtube class.

Code

public function getRows($last_id = NULL) {
  $settings = $this->settings['instance'];
  $global_settings = $this->settings['global'];
  if (!empty($settings['youtube_id'])) {
    $params = array(
      'order' => 'date',
      'part' => 'snippet,id',
      'key' => $global_settings['api_key'],
      'channelId' => $settings['youtube_id'],
      'type' => 'video',
    );
    if (!empty($settings['limit'])) {
      $params['maxResults'] = $settings['limit'];
    }
    $url = $global_settings['api_url'] . '/search';
    $result = $this
      ->httpRequest(url($url, array(
      'query' => $params,
      'external' => TRUE,
    )));
    if ($result->code == 200) {
      $data = json_decode($result->data);

      // $items->id is an object causes conflicts.
      foreach ($data->items as &$item) {
        $id_number = $item->id->videoId;
        unset($item->id);
        $item->id = $id_number;
      }
      return $data->items;
    }
    else {
      watchdog('social_content_youtube', 'Error fetching feed, data: %data', array(
        '%data' => $result->data,
      ), WATCHDOG_WARNING);
      return FALSE;
    }
  }
  return array();
}