| 1 |
<?php |
<?php |
| 2 |
// $Id: flickrfield.module,v 1.4 2008/09/30 10:35:08 karens Exp $ |
// $Id: flickrfield.module,v 1.4.2.1 2009/01/30 10:39:01 paulbooker Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 34 |
'label' => 'Flickr Photo', |
'label' => 'Flickr Photo', |
| 35 |
'description' => t('Store Flickr Photo or Photoset ids and display the photos in nodes and views.'), |
'description' => t('Store Flickr Photo or Photoset ids and display the photos in nodes and views.'), |
| 36 |
), |
), |
| 37 |
|
'flickrfield_photoset' => array( |
| 38 |
|
'label' => 'Flickr photo set', |
| 39 |
|
'description' => t('Field for storing a reference to a Flickr photo set.'), |
| 40 |
|
) |
| 41 |
); |
); |
| 42 |
} |
} |
| 43 |
|
|
| 47 |
function flickrfield_field_settings($op, $field) { |
function flickrfield_field_settings($op, $field) { |
| 48 |
switch ($op) { |
switch ($op) { |
| 49 |
case 'database columns': |
case 'database columns': |
| 50 |
|
if ($field['type'] == 'flickrfield') { |
| 51 |
$columns = array( |
$columns = array( |
| 52 |
'id' => array('type' => 'varchar', 'length' => 64, 'not null' => FALSE, 'sortable' => TRUE), |
'id' => array('type' => 'varchar', 'length' => 64, 'not null' => FALSE, 'sortable' => TRUE), |
| 53 |
'type' => array('type' => 'varchar', 'length' => 10, 'not null' => FALSE, 'sortable' => TRUE), |
'type' => array('type' => 'varchar', 'length' => 10, 'not null' => FALSE, 'sortable' => TRUE), |
| 54 |
'nsid' => array('type' => 'varchar', 'length' => 64, 'not null' => FALSE, 'sortable' => TRUE), |
'nsid' => array('type' => 'varchar', 'length' => 64, 'not null' => FALSE, 'sortable' => TRUE), |
| 55 |
); |
); |
| 56 |
|
} |
| 57 |
|
else if ($field['type'] == 'flickrfield_photoset') { |
| 58 |
|
$columns = array( |
| 59 |
|
'flickrid' => array('type' => 'varchar', 'length' => 64, 'not null' => FALSE, 'sortable' => TRUE), |
| 60 |
|
); |
| 61 |
|
} |
| 62 |
return $columns; |
return $columns; |
| 63 |
} |
} |
| 64 |
} |
} |
| 76 |
'default value' => CONTENT_CALLBACK_DEFAULT, |
'default value' => CONTENT_CALLBACK_DEFAULT, |
| 77 |
), |
), |
| 78 |
), |
), |
| 79 |
|
'flickrfield_flickrid' => array( |
| 80 |
|
'label' => 'Flickr Id', |
| 81 |
|
'field types' => array('flickrfield_photoset'), |
| 82 |
|
'multiple values' => CONTENT_HANDLE_CORE, |
| 83 |
|
'callbacks' => array( |
| 84 |
|
'default value' => CONTENT_CALLBACK_DEFAULT, |
| 85 |
|
), |
| 86 |
|
) |
| 87 |
); |
); |
| 88 |
} |
} |
| 89 |
|
|
| 94 |
'#columns' => array('type', 'id', 'uid'), |
'#columns' => array('type', 'id', 'uid'), |
| 95 |
'#process' => array('flickrfield_process'), |
'#process' => array('flickrfield_process'), |
| 96 |
), |
), |
| 97 |
|
'flickrfield_flickrid' => array( |
| 98 |
|
'#input' => TRUE, |
| 99 |
|
'#columns' => array('flickrid'), |
| 100 |
|
'#process' => array('flickrfield_flickrid_process'), |
| 101 |
|
) |
| 102 |
); |
); |
| 103 |
} |
} |
| 104 |
|
|
| 135 |
return $element; |
return $element; |
| 136 |
} |
} |
| 137 |
|
|
| 138 |
|
function flickrfield_flickrid_process($element, $edit, $form_state, $form) { |
| 139 |
|
$element['flickrid'] = array( |
| 140 |
|
'#type' => 'textfield', |
| 141 |
|
'#title' => $element['#title'], |
| 142 |
|
'#description' => $element['#description'], |
| 143 |
|
'#required' => $element['#required'], |
| 144 |
|
'#field_prefix' => t('Flickr ID: '), |
| 145 |
|
'#default_value' => !empty($element['#value']['flickrid']) ? $element['#value']['flickrid'] : '', |
| 146 |
|
'#size' => 20, |
| 147 |
|
'#maxlength' => 20, |
| 148 |
|
'#attributes' => array('class' => 'flickrfield_flickrid'), |
| 149 |
|
); |
| 150 |
|
return $element; |
| 151 |
|
} |
| 152 |
|
|
| 153 |
/** |
/** |
| 154 |
* Implementation of hook_content_is_empty(). |
* Implementation of hook_content_is_empty(). |
| 155 |
*/ |
*/ |
| 156 |
function flickrfield_content_is_empty($item, $field) { |
function flickrfield_content_is_empty($item, $field) { |
| 157 |
|
if ($field['type'] == 'flickrfield') { |
| 158 |
return empty($item['id']); |
return empty($item['id']); |
| 159 |
|
} else if ($field['type'] == 'flickrfield_photoset') { |
| 160 |
|
return empty($item['flickrid']); |
| 161 |
|
} |
| 162 |
} |
} |
| 163 |
|
|
| 164 |
/** |
/** |
| 166 |
*/ |
*/ |
| 167 |
function flickrfield_field_formatter_info() { |
function flickrfield_field_formatter_info() { |
| 168 |
require_once(drupal_get_path('module', 'flickr') .'/flickr.inc'); |
require_once(drupal_get_path('module', 'flickr') .'/flickr.inc'); |
| 169 |
foreach (flickr_photo_sizes() as $size => $info) { |
$sizes = flickr_photo_sizes(); |
| 170 |
|
// Formatters for general Flickr CCK field. |
| 171 |
|
foreach ($sizes as $size => $info) { |
| 172 |
$formatters[$size] = array( |
$formatters[$size] = array( |
| 173 |
'label' => $info['label'], |
'label' => $info['label'], |
| 174 |
'field types' => array('flickrfield'), |
'field types' => array('flickrfield'), |
| 175 |
); |
); |
| 176 |
} |
} |
| 177 |
|
// Formatters for Flickr photoset CCK field. |
| 178 |
|
foreach ($sizes as $size => $info) { |
| 179 |
|
$formatters['photoset_primaryphoto_size'. $size .'_nolink'] = array( |
| 180 |
|
'label' => t('Primary set photo at size "@size"', array('@size' => $info['label'])), |
| 181 |
|
'field types' => array('flickrfield_photoset'), |
| 182 |
|
); |
| 183 |
|
$formatters['photoset_primaryphoto_size'. $size .'_linknode'] = array( |
| 184 |
|
'label' => t('Primary set photo at size "@size" with link to node', array('@size' => $info['label'])), |
| 185 |
|
'field types' => array('flickrfield_photoset'), |
| 186 |
|
); |
| 187 |
|
$formatters['photoset_primaryphoto_size'. $size .'_linkflickrcomset'] = array( |
| 188 |
|
'label' => t('Primary set photo at size "@size" with link to set on Flickr.com', array('@size' => $info['label'])), |
| 189 |
|
'field types' => array('flickrfield_photoset'), |
| 190 |
|
); |
| 191 |
|
} |
| 192 |
|
$formatters['photoset_flickrcomslideshow'] = array( |
| 193 |
|
'label' => 'Embedded Flickr.com flash slideshow', |
| 194 |
|
'field types' => array('flickrfield_photoset'), |
| 195 |
|
); |
| 196 |
|
$formatters['photoset_flickrcomsetlink'] = array( |
| 197 |
|
'label' => 'Link to photo set on Flickr.com', |
| 198 |
|
'field types' => array('flickrfield_photoset'), |
| 199 |
|
); |
| 200 |
return $formatters; |
return $formatters; |
| 201 |
} |
} |
| 202 |
|
|
| 211 |
'arguments' => array('element'), |
'arguments' => array('element'), |
| 212 |
'function' => 'theme_flickrfield_field_formatter', |
'function' => 'theme_flickrfield_field_formatter', |
| 213 |
); |
); |
| 214 |
|
// Theme function for the primary photo formatters of a Flickr photo set. |
| 215 |
|
$themes['flickrfield_formatter_photoset_primaryphoto_size'. $size .'_nolink'] = array( |
| 216 |
|
'arguments' => array('element'), |
| 217 |
|
'function' => 'theme_flickrfield_formatter_photoset_primaryphoto', |
| 218 |
|
); |
| 219 |
|
$themes['flickrfield_formatter_photoset_primaryphoto_size'. $size .'_linknode'] = array( |
| 220 |
|
'arguments' => array('element'), |
| 221 |
|
'function' => 'theme_flickrfield_formatter_photoset_primaryphoto', |
| 222 |
|
); |
| 223 |
|
$themes['flickrfield_formatter_photoset_primaryphoto_size'. $size .'_linkflickrcomset'] = array( |
| 224 |
|
'arguments' => array('element'), |
| 225 |
|
'function' => 'theme_flickrfield_formatter_photoset_primaryphoto', |
| 226 |
|
); |
| 227 |
} |
} |
| 228 |
return $themes + array( |
return $themes + array( |
| 229 |
'flickrfield_photo' => array( |
'flickrfield_photo' => array( |
| 235 |
'flickrfield' => array( |
'flickrfield' => array( |
| 236 |
'arguments' => array('element'), |
'arguments' => array('element'), |
| 237 |
), |
), |
| 238 |
|
'flickrfield_flickrid' => array( |
| 239 |
|
'arguments' => array('element'), |
| 240 |
|
), |
| 241 |
|
'flickrfield_photoset_primaryphoto' => array( |
| 242 |
|
'arguments' => array('element'), |
| 243 |
|
), |
| 244 |
|
'flickrfield_formatter_photoset_flickrcomslideshow' => array( |
| 245 |
|
'arguments' => array('element'), |
| 246 |
|
), |
| 247 |
|
'flickrfield_formatter_photoset_flickrcomsetlink' => array( |
| 248 |
|
'arguments' => array('element'), |
| 249 |
|
), |
| 250 |
); |
); |
| 251 |
} |
} |
| 252 |
|
|
| 277 |
} |
} |
| 278 |
|
|
| 279 |
/** |
/** |
| 280 |
|
* Theme a Flickr photo set as the primary photo of that set. |
| 281 |
|
*/ |
| 282 |
|
function theme_flickrfield_formatter_photoset_primaryphoto($element) { |
| 283 |
|
require_once(drupal_get_path('module', 'flickr') .'/flickr.inc'); |
| 284 |
|
if (empty($element['#item']['flickrid'])) { |
| 285 |
|
return; |
| 286 |
|
} |
| 287 |
|
$formatter_info = explode('_', $element['#formatter']); |
| 288 |
|
$set_data = flickr_photoset_get_info($element['#item']['flickrid']); |
| 289 |
|
$set_url = flickr_photoset_page_url($set_data['owner'], $set_data['id']); |
| 290 |
|
$size = substr($formatter_info[2], -1); |
| 291 |
|
$img = flickr_img($set_data, $size); |
| 292 |
|
switch ($formatter_info[3]) { |
| 293 |
|
case 'linknode': |
| 294 |
|
$link = 'node/'. $element['#node']->nid; |
| 295 |
|
break; |
| 296 |
|
case 'linkflickrcomset': |
| 297 |
|
$link = $set_url; |
| 298 |
|
break; |
| 299 |
|
default: |
| 300 |
|
$link = NULL; |
| 301 |
|
break; |
| 302 |
|
} |
| 303 |
|
$title = is_array($photo_data['title']) ? $photo_data['title']['_content'] : $photo_data['title']; |
| 304 |
|
|
| 305 |
|
return theme('flickrfield_photoset_primaryphoto', $img, $link, $set_url, $size, $title); |
| 306 |
|
} |
| 307 |
|
|
| 308 |
|
/** |
| 309 |
|
* Theme a Flickr photo set as an embedded Flickr.com flash slideshow. |
| 310 |
|
*/ |
| 311 |
|
function theme_flickrfield_formatter_photoset_flickrcomslideshow($element) { |
| 312 |
|
require_once(drupal_get_path('module', 'flickr') .'/flickr.inc'); |
| 313 |
|
if (empty($element['#item']['flickrid'])) { |
| 314 |
|
return; |
| 315 |
|
} |
| 316 |
|
$set_id = $element['#item']['flickrid']; |
| 317 |
|
$src = 'http://www.flickr.com/slideShow/index.gne?set_id='. $set_id; |
| 318 |
|
return '<div class="flickr-photoset-slideshow">' |
| 319 |
|
.'<iframe align="center" src="' . $src .'" frameBorder="0" width="500" scrolling="no" height="500"></iframe>' |
| 320 |
|
.'</div>'; |
| 321 |
|
} |
| 322 |
|
|
| 323 |
|
/** |
| 324 |
|
* Theme a Flickr photo set as a simple link to the photo set page on Flickr.com. |
| 325 |
|
*/ |
| 326 |
|
function theme_flickrfield_formatter_photoset_flickrcomsetlink($element) { |
| 327 |
|
$set_data = flickr_photoset_get_info($element['#item']['flickrid']); |
| 328 |
|
$set_url = flickr_photoset_page_url($set_data['owner'], $set_data['id']); |
| 329 |
|
return l($set_url, $set_url); |
| 330 |
|
} |
| 331 |
|
|
| 332 |
|
/** |
| 333 |
* Flickrfield photo themes. |
* Flickrfield photo themes. |
| 334 |
* |
* |
| 335 |
* If we are not on the node, make the photo link back to the node, |
* If we are not on the node, make the photo link back to the node, |
| 361 |
} |
} |
| 362 |
|
|
| 363 |
/** |
/** |
| 364 |
|
* Theme function for showing a primary photo of a photo set with optional link. |
| 365 |
|
* Also includes a link to Flickr.com photo set page to comply with terms of service. |
| 366 |
|
* @param $img HTML code for image |
| 367 |
|
* @param $link link to which the image should link to |
| 368 |
|
* @param $set_url url of the photo set on Flickr.com |
| 369 |
|
* @param $size the flickr size of the image |
| 370 |
|
* @param $title title to use for the link |
| 371 |
|
* @return unknown_type |
| 372 |
|
*/ |
| 373 |
|
function theme_flickrfield_photoset_primaryphoto($img, $link, $set_url, $size, $title) { |
| 374 |
|
if ($link) { |
| 375 |
|
$output = '<div class="flickr-photoset-img">'. l($img, $link, array('attributes' => array('title' => $title), 'html' => TRUE)) . '</div>'; |
| 376 |
|
} |
| 377 |
|
else { |
| 378 |
|
$output = '<div class="flickr-photoset-img">'. $img .'</div>'; |
| 379 |
|
} |
| 380 |
|
$output .= '<div class="flickr-citation">'. l(t('Source: Flickr'), $set_url) .'</div>'; |
| 381 |
|
return $output; |
| 382 |
|
} |
| 383 |
|
|
| 384 |
|
/** |
| 385 |
* Theme for the form element. |
* Theme for the form element. |
| 386 |
* |
* |
| 387 |
* The form is already rendered by the child elements by the time it comes back here, |
* The form is already rendered by the child elements by the time it comes back here, |
| 400 |
); |
); |
| 401 |
return theme('fieldset', $fieldset); |
return theme('fieldset', $fieldset); |
| 402 |
} |
} |
| 403 |
|
|
| 404 |
|
/** |
| 405 |
|
* Theme function for the Flickr ID form element. |
| 406 |
|
* |
| 407 |
|
* The textfield is already rendered by the textfield theme |
| 408 |
|
* and the html output lives in $element['#children']. |
| 409 |
|
*/ |
| 410 |
|
function theme_flickrfield_flickrid($element) { |
| 411 |
|
return $element['#children']; |
| 412 |
|
} |