You are here

function image_ncck_flickr_import in Embedded Media Field 5

This allows flickr photosets to be imported into nodes

File

contrib/image_ncck/providers/flickr.inc, line 38

Code

function image_ncck_flickr_import($url, $limit = 0, $page = 0) {
  $codes = array();

  // http://www.flickr.com/photos/nikkiana/sets/72157601948647678/
  if (preg_match('@flickr\\.com/photos/([^/]*)/([^/]*)/([^/]*)/@i', $url, $matches)) {
    $page++;

    // flickr starts current page at 1
    $codes['#matches'] = $matches;
    $args = array(
      'photoset_id' => $matches[3],
    );
    if ($limit) {
      $args['per_page'] = $limit;
    }
    $args['page'] = $page;
    $xml = image_ncck_flickr_request('flickr.photosets.getPhotos', $args);

    //    print_r($xml);
    $codes['#pages'] = $xml['photoset']['pages'];
    $codes['#page'] = $xml['photoset']['page'] - 1;
    $codes['#total'] = $xml['photoset']['total'];
    $codes['#per_page'] = $xml['photoset']['per_page'];
    $codes['#set'] = array();
    foreach ($xml['photoset']['photo'] as $photo) {
      $data = image_ncck_flickr_data(NULL, array(
        'value' => $photo['id'],
      ));
      $codes['#set'][] = array(
        '#code' => $photo['id'],
        '#title' => $photo['title'],
        '#link' => image_ncck_flickr_embedded_link($photo['id'], $xml['photoset']['owner']),
        '#thumb' => image_ncck_flickr_image_url($photo['id'], 100, 100, NULL, NULL, NULL),
        '#body' => $data['description'],
        '#tags' => $data['tags'],
      );
    }

    /*
        $data['owner'] = $xml['photo']['owner']['nsid'];
        $data['title'] = $xml['photo']['title']['_content'];*/
  }

  // print_r($codes);
  return $codes;
}