array( 'label' => 'Flickr Photo', 'description' => t('Store Flickr Photo or Photoset ids and display the photos in nodes and views.'), ), 'flickrfield_photoset' => array( 'label' => 'Flickr photo set', 'description' => t('Field for storing a reference to a Flickr photo set.'), ) ); } /** * Implementation of hook_field_settings(). */ function flickrfield_field_settings($op, $field) { switch ($op) { case 'database columns': if ($field['type'] == 'flickrfield') { $columns = array( 'id' => array('type' => 'varchar', 'length' => 64, 'not null' => FALSE, 'sortable' => TRUE), 'type' => array('type' => 'varchar', 'length' => 10, 'not null' => FALSE, 'sortable' => TRUE), 'nsid' => array('type' => 'varchar', 'length' => 64, 'not null' => FALSE, 'sortable' => TRUE), ); } else if ($field['type'] == 'flickrfield_photoset') { $columns = array( 'flickrid' => array('type' => 'varchar', 'length' => 64, 'not null' => FALSE, 'sortable' => TRUE), ); } return $columns; } } /** * Implementation of hook_widget_info(). */ function flickrfield_widget_info() { return array( 'flickrfield' => array( 'label' => 'Flickr Photo', 'field types' => array('flickrfield'), 'multiple values' => CONTENT_HANDLE_CORE, 'callbacks' => array( 'default value' => CONTENT_CALLBACK_DEFAULT, ), ), 'flickrfield_flickrid' => array( 'label' => 'Flickr Id', 'field types' => array('flickrfield_photoset'), 'multiple values' => CONTENT_HANDLE_CORE, 'callbacks' => array( 'default value' => CONTENT_CALLBACK_DEFAULT, ), ) ); } function flickrfield_elements() { return array( 'flickrfield' => array( '#input' => TRUE, '#columns' => array('type', 'id', 'uid'), '#process' => array('flickrfield_process'), ), 'flickrfield_flickrid' => array( '#input' => TRUE, '#columns' => array('flickrid'), '#process' => array('flickrfield_flickrid_process'), ) ); } function flickrfield_widget(&$form, &$form_state, $field, $items, $delta = 0) { $element = array( '#type' => $field['widget']['type'], '#default_value' => isset($items[$delta]) ? $items[$delta] : '', ); return $element; } function flickrfield_process($element, $edit, $form_state, $form) { $options = array(); $options['photo_id'] = t("Photo"); $options['set_id'] = t("Photoset"); $element['type'] = array( '#type' => 'select', '#title' => t('Item Type'), '#default_value' => !empty($element['#value']['type']) ? $element['#value']['type'] : '', '#options' => $options, ); $element['id'] = array( '#type' => 'textfield', '#title' => t('Id'), '#default_value' => !empty($element['#value']['id']) ? $element['#value']['id'] : '', ); $element['nsid'] = array( '#type' => 'textfield', '#title' => t('User Id'), '#default_value' => !empty($element['#value']['nsid']) ? $element['#value']['nsid'] : variable_get('flickr_default_userid', ''), '#required' => $element['#required'], '#description' => t("The user id of the Flickr user who owns the photos. If this is left blank, the sites's default user will be used. Current default id is @id.", array('@id' => variable_get('flickr_default_userid', ''))), ); return $element; } function flickrfield_flickrid_process($element, $edit, $form_state, $form) { $element['flickrid'] = array( '#type' => 'textfield', '#title' => $element['#title'], '#description' => $element['#description'], '#required' => $element['#required'], '#field_prefix' => t('Flickr ID: '), '#default_value' => !empty($element['#value']['flickrid']) ? $element['#value']['flickrid'] : '', '#size' => 20, '#maxlength' => 20, '#attributes' => array('class' => 'flickrfield_flickrid'), ); return $element; } /** * Implementation of hook_content_is_empty(). */ function flickrfield_content_is_empty($item, $field) { if ($field['type'] == 'flickrfield') { return empty($item['id']); } else if ($field['type'] == 'flickrfield_photoset') { return empty($item['flickrid']); } } /** * Implementation of hook_field_formatter_info(). */ function flickrfield_field_formatter_info() { require_once(drupal_get_path('module', 'flickr') .'/flickr.inc'); $sizes = flickr_photo_sizes(); // Formatters for general Flickr CCK field. foreach ($sizes as $size => $info) { $formatters[$size] = array( 'label' => $info['label'], 'field types' => array('flickrfield'), ); } // Formatters for Flickr photoset CCK field. foreach ($sizes as $size => $info) { $formatters['photoset_primaryphoto_size'. $size .'_nolink'] = array( 'label' => t('Primary set photo at size "@size"', array('@size' => $info['label'])), 'field types' => array('flickrfield_photoset'), ); $formatters['photoset_primaryphoto_size'. $size .'_linknode'] = array( 'label' => t('Primary set photo at size "@size" with link to node', array('@size' => $info['label'])), 'field types' => array('flickrfield_photoset'), ); $formatters['photoset_primaryphoto_size'. $size .'_linkflickrcomset'] = array( 'label' => t('Primary set photo at size "@size" with link to set on Flickr.com', array('@size' => $info['label'])), 'field types' => array('flickrfield_photoset'), ); } $formatters['photoset_flickrcomslideshow'] = array( 'label' => 'Embedded Flickr.com flash slideshow', 'field types' => array('flickrfield_photoset'), ); $formatters['photoset_flickrcomsetlink'] = array( 'label' => 'Link to photo set on Flickr.com', 'field types' => array('flickrfield_photoset'), ); return $formatters; } /** * Implementation of hook_theme(). */ function flickrfield_theme() { require_once(drupal_get_path('module', 'flickr') .'/flickr.inc'); $themes = array(); foreach (flickr_photo_sizes() as $size => $info) { $themes['flickrfield_formatter_'. $size] = array( 'arguments' => array('element'), 'function' => 'theme_flickrfield_field_formatter', ); // Theme function for the primary photo formatters of a Flickr photo set. $themes['flickrfield_formatter_photoset_primaryphoto_size'. $size .'_nolink'] = array( 'arguments' => array('element'), 'function' => 'theme_flickrfield_formatter_photoset_primaryphoto', ); $themes['flickrfield_formatter_photoset_primaryphoto_size'. $size .'_linknode'] = array( 'arguments' => array('element'), 'function' => 'theme_flickrfield_formatter_photoset_primaryphoto', ); $themes['flickrfield_formatter_photoset_primaryphoto_size'. $size .'_linkflickrcomset'] = array( 'arguments' => array('element'), 'function' => 'theme_flickrfield_formatter_photoset_primaryphoto', ); } return $themes + array( 'flickrfield_photo' => array( 'arguments' => array('img', 'photo_url', 'formatter', 'photo_data', 'node'), ), 'flickrfield_photoset' => array( 'arguments' => array('img', 'photo_url', 'formatter', 'photo_data', 'node'), ), 'flickrfield' => array( 'arguments' => array('element'), ), 'flickrfield_flickrid' => array( 'arguments' => array('element'), ), 'flickrfield_photoset_primaryphoto' => array( 'arguments' => array('element'), ), 'flickrfield_formatter_photoset_flickrcomslideshow' => array( 'arguments' => array('element'), ), 'flickrfield_formatter_photoset_flickrcomsetlink' => array( 'arguments' => array('element'), ), ); } /** * Basic flickrfield formatter. */ function theme_flickrfield_field_formatter($element) { require_once(drupal_get_path('module', 'flickr') .'/flickr.inc'); $item = $element['#item']; if (empty($item['id'])) { return; } $node = $element['#node']; $formatter = $element['#formatter']; $field_name = $element['#field_name']; switch ($item['type']) { case 'photo_id': $photo_data = flickr_photo_get_info($item['id']); $img = flickr_img($photo_data, $formatter); $photo_url = flickr_photo_page_url($photo_data['owner'], $photo_data['id']); return theme('flickrfield_photo', $img, $photo_url, $formatter, $photo_data, $node); case 'set_id': $photo_data = flickr_photoset_get_info($item['id']); $img = flickr_img($photo_data, $formatter); $photo_url = flickr_photoset_page_url($photo_data['owner'], $photo_data['id']); return theme('flickrfield_photoset', $img, $photo_url, $formatter, $photo_data, $node); } } /** * Theme a Flickr photo set as the primary photo of that set. */ function theme_flickrfield_formatter_photoset_primaryphoto($element) { require_once(drupal_get_path('module', 'flickr') .'/flickr.inc'); if (empty($element['#item']['flickrid'])) { return; } $formatter_info = explode('_', $element['#formatter']); $set_data = flickr_photoset_get_info($element['#item']['flickrid']); $set_url = flickr_photoset_page_url($set_data['owner'], $set_data['id']); $size = substr($formatter_info[2], -1); $img = flickr_img($set_data, $size); switch ($formatter_info[3]) { case 'linknode': $link = 'node/'. $element['#node']->nid; break; case 'linkflickrcomset': $link = $set_url; break; default: $link = NULL; break; } $title = is_array($photo_data['title']) ? $photo_data['title']['_content'] : $photo_data['title']; return theme('flickrfield_photoset_primaryphoto', $img, $link, $set_url, $size, $title); } /** * Theme a Flickr photo set as an embedded Flickr.com flash slideshow. */ function theme_flickrfield_formatter_photoset_flickrcomslideshow($element) { require_once(drupal_get_path('module', 'flickr') .'/flickr.inc'); if (empty($element['#item']['flickrid'])) { return; } $set_id = $element['#item']['flickrid']; $src = 'http://www.flickr.com/slideShow/index.gne?set_id='. $set_id; return '
' .'' .'
'; } /** * Theme a Flickr photo set as a simple link to the photo set page on Flickr.com. */ function theme_flickrfield_formatter_photoset_flickrcomsetlink($element) { $set_data = flickr_photoset_get_info($element['#item']['flickrid']); $set_url = flickr_photoset_page_url($set_data['owner'], $set_data['id']); return l($set_url, $set_url); } /** * Flickrfield photo themes. * * If we are not on the node, make the photo link back to the node, * otherwise just display the image. To comply with Flickr terms of service * add a link back to the Flickr page. */ function theme_flickrfield_photo($img, $photo_url, $formatter, $photo_data, $node) { $title = is_array($photo_data['title']) ? $photo_data['title']['_content'] : $photo_data['title']; if (arg(0) == 'node' && arg(1) == $node->nid) { $output = '
'. $img .'
'; } else { $output = '
'. l($img, 'node/'. $node->nid, array('attributes' => array('title' => $title), 'absolute' => TRUE, 'html' => TRUE)) . '
'; } $output .= '
'. l(t('Source: Flickr'), $photo_url) .'
'; return $output; } function theme_flickrfield_photoset($img, $photo_url, $formatter, $photo_data, $node) { $output = '
'; if (module_exists('flickr_sets')) { $photos = flickr_set_load($photo_data['id']); foreach ((array) $photos['photoset']['photo'] as $photo) { //insert owner into $photo because theme_flickr_photo needs it $photo['owner'] = $photos['photoset']['owner']; $title = is_array($photo['title']) ? $photo['title']['_content'] : $photo['title']; $img = flickr_img($photo, $formatter); $original = flickr_photo_img($photo); if (arg(0) == 'node' && arg(1) == $node->nid) { $output .= '
'. l($img, $original, array('attributes' => array('title' => $title), 'absolute' => TRUE, 'html' => TRUE)) .'
'; } else { $output .= '
'. l($img, 'node/'. $node->nid, array('attributes' => array('title' => $title), 'absolute' => TRUE, 'html' => TRUE)) . '
'; } } } else { $title = is_array($photo_data['title']) ? $photo_data['title']['_content'] : $photo_data['title']; if (arg(0) == 'node' && arg(1) == $node->nid) { $output .= '
'. $img .'
'; } else { $output .= '
'. l($img, 'node/'. $node->nid, array('attributes' => array('title' => $title), 'absolute' => TRUE, 'html' => TRUE)) . '
'; } } $output .= '
'; $output .= '
'; $output .= '

'. $photo_data['description']['_content'] .'

'; $output .= ''. l(t('Source: Flickr'), $photo_url) .''; $output .= '
'; return $output; } /** * Theme function for showing a primary photo of a photo set with optional link. * Also includes a link to Flickr.com photo set page to comply with terms of service. * @param $img HTML code for image * @param $link link to which the image should link to * @param $set_url url of the photo set on Flickr.com * @param $size the flickr size of the image * @param $title title to use for the link * @return unknown_type */ function theme_flickrfield_photoset_primaryphoto($img, $link, $set_url, $size, $title) { if ($link) { $output = '
'. l($img, $link, array('attributes' => array('title' => $title), 'html' => TRUE)) . '
'; } else { $output = '
'. $img .'
'; } $output .= '
'. l(t('Source: Flickr'), $set_url) .'
'; return $output; } /** * Theme for the form element. * * The form is already rendered by the child elements by the time it comes back here, * just group each delta grouping into its own fieldset. */ function theme_flickrfield($element) { $fields = content_fields(); $field = $fields[$element['#field_name']]; $fieldset = array( '#title' => $field['widget']['label'] .' '. ($element['#delta'] > 0 ? intval($element['#delta'] + 1) : ''), '#value' => $element['#children'], '#collapsible' => FALSE, '#collapsed' => FALSE, '#description' => $element['#description'], '#attributes' => array(), ); return theme('fieldset', $fieldset); } /** * Theme function for the Flickr ID form element. * * The textfield is already rendered by the textfield theme * and the html output lives in $element['#children']. */ function theme_flickrfield_flickrid($element) { return $element['#children']; }