| 1 |
<?php
|
| 2 |
// $Id: flickr_cck.module,v 1.10 2007/02/08 23:32:52 aaron Exp $
|
| 3 |
|
| 4 |
// TODO: only needed by 4.7, because 4.7 flickr.module doesn't implement this
|
| 5 |
if (!function_exists('flickr_user_find_by_username')) {
|
| 6 |
|
| 7 |
function flickr_user_find_by_username($username) {
|
| 8 |
if (function_exists('flickr_request')) {
|
| 9 |
return flickr_request(
|
| 10 |
'flickr.people.findByUsername',
|
| 11 |
array('username' => $username)
|
| 12 |
);
|
| 13 |
}
|
| 14 |
else {
|
| 15 |
drupal_set_message(t('You must have the Flickr module installed to find Flickr usernames.'), 'error');
|
| 16 |
}
|
| 17 |
}
|
| 18 |
|
| 19 |
} // end if !function_exists
|
| 20 |
|
| 21 |
// TODO: only needed by 4.7...
|
| 22 |
// we can remove entirely after proper branching
|
| 23 |
if (!function_exists('module_exists')) {
|
| 24 |
|
| 25 |
GLOBAL $flickr_cck_drupal_4_7;
|
| 26 |
$flickr_cck_drupal_4_7 = true;
|
| 27 |
function module_exists($module) {
|
| 28 |
return module_exist($module);
|
| 29 |
}
|
| 30 |
|
| 31 |
function flickr_cck_photo_img($photo, $size = NULL, $format = NULL) {
|
| 32 |
// early images don't have a farm setting so default to 1.
|
| 33 |
$farm = isset($photo['farm']) ? $photo['farm'] : 1;
|
| 34 |
$server = $photo['server'];
|
| 35 |
// photoset's use primary instead of id to specify the image.
|
| 36 |
$id = isset($photo['primary']) ? $photo['primary'] : $photo['id'];
|
| 37 |
$secret = $photo['secret'];
|
| 38 |
|
| 39 |
return "http://farm{$farm}.static.flickr.com/{$server}/{$id}_{$secret}" .($size ? "_$size." : '.') . ($size == 'o' ? $format : 'jpg');
|
| 40 |
}
|
| 41 |
|
| 42 |
} // endif !function_exists
|
| 43 |
|
| 44 |
/**Implementation of hook_field_info **/
|
| 45 |
|
| 46 |
function flickr_cck_field_info() {
|
| 47 |
$fields = array(
|
| 48 |
'flickr_cck_flash_slideshow' => array('label' => t('Flickr Flash Slideshow')),
|
| 49 |
// 'flickr_cck_html_badge' => array('label' => t('Flickr HTML Badge')),
|
| 50 |
'flickr_cck_flash_badge' => array('label' => t('Flickr Flash Badge')),
|
| 51 |
);
|
| 52 |
if (module_exists('slideshow_creator')) {
|
| 53 |
$fields['flickr_cck_api_slideshow'] = array('label' => t('Flickr API Slideshow (requires Slideshow Creator)'));
|
| 54 |
}
|
| 55 |
return $fields;
|
| 56 |
}
|
| 57 |
|
| 58 |
/** Implementation of hook_field_settings **/
|
| 59 |
|
| 60 |
function flickr_cck_field_settings($op, $field) {
|
| 61 |
switch ($op) {
|
| 62 |
|
| 63 |
case 'database columns':
|
| 64 |
$columns = array(
|
| 65 |
'username' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => "''", 'sortable' => TRUE),
|
| 66 |
'value' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => "''", 'sortable' => TRUE),
|
| 67 |
'photoset' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => "''", 'sortable' => TRUE),
|
| 68 |
'tags' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => "''", 'sortable' => TRUE),
|
| 69 |
'tag_mode' => array('type' => 'int', 'not null' => FALSE, 'default' => NULL, 'sortable' => TRUE),
|
| 70 |
'text' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => "''", 'sortable' => TRUE),
|
| 71 |
);
|
| 72 |
switch ($field['type']) {
|
| 73 |
case 'flickr_cck_flash_slideshow':
|
| 74 |
case 'flickr_cck_html_badge':
|
| 75 |
case 'flickr_cck_flash_badge':
|
| 76 |
case 'flickr_cck_api_slideshow':
|
| 77 |
break;
|
| 78 |
}
|
| 79 |
return $columns;
|
| 80 |
}
|
| 81 |
}
|
| 82 |
|
| 83 |
/** Implementation of hook_field **/
|
| 84 |
|
| 85 |
function flickr_cck_field($op, &$node, $field, &$items, $teaser, $page) {
|
| 86 |
switch ($op) {
|
| 87 |
case 'view':
|
| 88 |
foreach ($items as $delta => $item) {
|
| 89 |
$items[$delta]['view'] = content_format($field, $item, 'default', $node);
|
| 90 |
}
|
| 91 |
return theme('field', $node, $field, $items, $teaser, $page);
|
| 92 |
|
| 93 |
case 'validate':
|
| 94 |
if ($field['multiple']) {
|
| 95 |
foreach ($items as $delta => $item) {
|
| 96 |
$error_field = $field['field_name'].']['.$delta.'][username';
|
| 97 |
|
| 98 |
_flickr_cck_field_validate_id($field, $item, $error_field);
|
| 99 |
}
|
| 100 |
}
|
| 101 |
else {
|
| 102 |
$error_field = $field['field_name'];
|
| 103 |
|
| 104 |
_flickr_cck_field_validate_id($field, $items[0], $error_field);
|
| 105 |
}
|
| 106 |
break;
|
| 107 |
|
| 108 |
case 'submit':
|
| 109 |
if ($field['multiple']) {
|
| 110 |
foreach ($items as $delta => $item) {
|
| 111 |
$error_field = $field['field_name'].']['.$delta.'][username';
|
| 112 |
$items[$delta]['value'] = _flickr_cck_field_submit_id($item);
|
| 113 |
}
|
| 114 |
}
|
| 115 |
else {
|
| 116 |
$error_field = $field['field_name'];
|
| 117 |
$items[0]['value'] = _flickr_cck_field_submit_id($items[0]);
|
| 118 |
}
|
| 119 |
break;
|
| 120 |
}
|
| 121 |
}
|
| 122 |
|
| 123 |
/**
|
| 124 |
* make sure we have a valid flickr user when using flickr_cck_id
|
| 125 |
*/
|
| 126 |
function _flickr_cck_field_validate_id($field, $item, $error_field) {
|
| 127 |
$uid = $item['username'];
|
| 128 |
if (preg_match('/^\d+@N\d+$/', $uid) || !$uid) {
|
| 129 |
// it's already a uid
|
| 130 |
return $item['username'];
|
| 131 |
}
|
| 132 |
else {
|
| 133 |
$response = flickr_user_find_by_username($uid);
|
| 134 |
if (!isset($response['stat']) || $response['stat'] != 'ok') {
|
| 135 |
form_set_error($error_field, t('%uid is not a Flickr user id and it does not appear to be a valid user name. Flickr reported %error-message', array('%uid' => $uid, '%error-message' => $response['message'])));
|
| 136 |
} else {
|
| 137 |
return $response['user']['id'];
|
| 138 |
}
|
| 139 |
}
|
| 140 |
}
|
| 141 |
|
| 142 |
/**
|
| 143 |
* replace flickr username with the returned id. this goes in the field 'value'
|
| 144 |
*/
|
| 145 |
function _flickr_cck_field_submit_id($item) {
|
| 146 |
if (!$item['username']) {
|
| 147 |
$item['value'] = '';
|
| 148 |
}
|
| 149 |
// ... replace the usernames with a user id ...
|
| 150 |
else if (preg_match('/^\d+@N\d+$/', $item['username']) == 0) {
|
| 151 |
$username = $item['username'];
|
| 152 |
$response = flickr_user_find_by_username($username);
|
| 153 |
if (isset($response['stat']) && $response['stat'] == 'ok') {
|
| 154 |
drupal_set_message(t("The Flickr username %username has been replaced with the corresponding user id %uid.", array('%username' => $item['value'], '%uid' => $response['user']['id'])));
|
| 155 |
$item['value'] = $response['user']['id'];
|
| 156 |
}
|
| 157 |
} else {
|
| 158 |
// the username is the id
|
| 159 |
$item['value'] = $item['username'];
|
| 160 |
}
|
| 161 |
return $item['value'];
|
| 162 |
}
|
| 163 |
|
| 164 |
/** Implementation of hook_field_formatter_info **/
|
| 165 |
function flickr_cck_field_formatter_info() {
|
| 166 |
$types = array('flickr_cck_flash_slideshow', 'flickr_cck_html_badge', 'flickr_cck_flash_badge', 'flickr_cck_api_slideshow');
|
| 167 |
$formats = array(
|
| 168 |
'default' => array(
|
| 169 |
'label' => t('Default'),
|
| 170 |
'field types' => $types,
|
| 171 |
),
|
| 172 |
'flash_slideshow' => array(
|
| 173 |
'label' => t('Flash Slideshow'),
|
| 174 |
'field types' => $types,
|
| 175 |
),
|
| 176 |
'flash_badge' => array(
|
| 177 |
'label' => t('Flash Badge'),
|
| 178 |
'field types' => $types,
|
| 179 |
),
|
| 180 |
// TODO
|
| 181 |
// 'html_badge' => array(
|
| 182 |
// 'label' => t('HTML Badge'),
|
| 183 |
// 'field types' => $types,
|
| 184 |
// ),
|
| 185 |
);
|
| 186 |
if (module_exists('slideshow_creator')) {
|
| 187 |
$formats['api_slideshow'] = array(
|
| 188 |
'label' => t('API Slideshow'),
|
| 189 |
'field types' => $types,
|
| 190 |
);
|
| 191 |
}
|
| 192 |
return $formats;
|
| 193 |
}
|
| 194 |
|
| 195 |
/** Implementation of hook_field_formatter **/
|
| 196 |
|
| 197 |
function flickr_cck_field_formatter($field, $item, $formatter, $node) {
|
| 198 |
if (!isset($item['value'])) {
|
| 199 |
return '';
|
| 200 |
}
|
| 201 |
|
| 202 |
switch ($formatter) {
|
| 203 |
case 'flash_slideshow':
|
| 204 |
$output .= theme('flickr_cck_flash_slideshow', $field, $item);
|
| 205 |
break;
|
| 206 |
case 'flash_badge':
|
| 207 |
$output .= theme('flickr_cck_flash_badge', $field, $item);
|
| 208 |
break;
|
| 209 |
case 'html_badge':
|
| 210 |
break;
|
| 211 |
case 'api_slideshow':
|
| 212 |
$output .= theme('flickr_cck_api_slideshow', $field, $item);
|
| 213 |
break;
|
| 214 |
case 'default':
|
| 215 |
default:
|
| 216 |
switch ($field['type']) {
|
| 217 |
case 'flickr_cck_flash_slideshow':
|
| 218 |
$output .= theme('flickr_cck_flash_slideshow', $field, $item);
|
| 219 |
break;
|
| 220 |
case 'flickr_cck_html_badge':
|
| 221 |
break;
|
| 222 |
case 'flickr_cck_flash_badge':
|
| 223 |
$output .= theme('flickr_cck_flash_badge', $field, $item);
|
| 224 |
break;
|
| 225 |
case 'flickr_cck_api_slideshow':
|
| 226 |
$output .= theme('flickr_cck_api_slideshow', $field, $item);
|
| 227 |
break;
|
| 228 |
}
|
| 229 |
}
|
| 230 |
return $output;
|
| 231 |
}
|
| 232 |
|
| 233 |
/** Widgets **/
|
| 234 |
|
| 235 |
/** Implementation of hook_widget_info **/
|
| 236 |
function flickr_cck_widget_info() {
|
| 237 |
return array(
|
| 238 |
'flickr_cck_textfields' => array(
|
| 239 |
'label' => t('Text Fields'),
|
| 240 |
'field types' => array('flickr_cck_flash_slideshow', 'flickr_cck_flash_badge', 'flickr_cck_api_slideshow'),
|
| 241 |
),
|
| 242 |
// TODO
|
| 243 |
// 'flickr_cck_html_badge_textfields' => array(
|
| 244 |
// 'label' => t('Text Fields'),
|
| 245 |
// 'field types' => array('flickr_cck_html_badge', ),
|
| 246 |
// ),
|
| 247 |
// TODO
|
| 248 |
// 'flickr_cck_tn_selector' => array(
|
| 249 |
// 'label' => t('Thumbnail Selector'),
|
| 250 |
// 'field types' => array('flickr_cck_api_slideshow', ),
|
| 251 |
// ),
|
| 252 |
);
|
| 253 |
}
|
| 254 |
|
| 255 |
function flickr_cck_widget_settings($op, $widget) {
|
| 256 |
global $flickr_cck_drupal_4_7;
|
| 257 |
switch ($op) {
|
| 258 |
case 'form':
|
| 259 |
$form = array();
|
| 260 |
if ($widget['type'] == 'flickr_cck_textfields') {
|
| 261 |
$form['flash_slideshow'] = array(
|
| 262 |
'#type' => 'fieldset',
|
| 263 |
'#title' => t('Flickr Flash Slideshow Settings'),
|
| 264 |
'#description' => t('These settings control how this field is displayed as a Flickr Flash Slideshow.'),
|
| 265 |
'#collapsible' => true,
|
| 266 |
'#collapsed' => false,
|
| 267 |
);
|
| 268 |
$form['flash_slideshow']['flash_width'] = array(
|
| 269 |
'#type' => 'textfield',
|
| 270 |
'#title' => t('Flickr flash width'),
|
| 271 |
'#default_value' => $widget['flash_width'] ? $widget['flash_width'] : 500,
|
| 272 |
'#required' => true,
|
| 273 |
'#description' => t('The width of the Flickr flash slideshow frame. This must be at least 500 pixels wide.'),
|
| 274 |
);
|
| 275 |
$form['flash_slideshow']['flash_height'] = array(
|
| 276 |
'#type' => 'textfield',
|
| 277 |
'#title' => t('Flickr flash height'),
|
| 278 |
'#default_value' => $widget['flash_height'] ? $widget['flash_height'] : 500,
|
| 279 |
'#required' => true,
|
| 280 |
'#description' => t('The height of the Flickr flash slideshow frame. This must be at least 500 pixels tall.'),
|
| 281 |
);
|
| 282 |
if (module_exists('slideshow_creator') && module_exists('flickr')) {
|
| 283 |
$form['api_slideshow'] = array(
|
| 284 |
'#type' => 'fieldset',
|
| 285 |
'#title' => t('Flickr API Slideshow Settings'),
|
| 286 |
'#description' => t('When the Slideshow Creator module is active, these settings control how this field is displayed when using that module.'),
|
| 287 |
'#collapsible' => true,
|
| 288 |
'#collapsed' => false,
|
| 289 |
);
|
| 290 |
$options = array();
|
| 291 |
// TODO: for 4.7 only; remove when branched
|
| 292 |
if ($flickr_cck_drupal_4_7) {
|
| 293 |
foreach (flickr_photo_sizes() as $size => $value) {
|
| 294 |
$options[$size] = $value;
|
| 295 |
}
|
| 296 |
}
|
| 297 |
else {
|
| 298 |
foreach (flickr_photo_sizes() as $size => $value) {
|
| 299 |
$options[$size] = t('@label (@description)', array('@label' => $value['label'], '@description' => $value['description']));
|
| 300 |
}
|
| 301 |
}
|
| 302 |
$form['api_slideshow']['api_size'] = array(
|
| 303 |
'#type' => 'select',
|
| 304 |
'#title' => t('Image Size'),
|
| 305 |
'#options' => $options,
|
| 306 |
'#default_value' => $widget['api_size'] ? $widget['api_size'] : 's',
|
| 307 |
'#description' => t('This controls the size of the images displayed in the slideshow.'),
|
| 308 |
);
|
| 309 |
$options = array('default' => t('Default'), 'top' => t('Top'), 'bottom' => t('Bottom'), 'reverse' => t('Reverse'));
|
| 310 |
$form['api_slideshow']['api_layout'] = array(
|
| 311 |
'#type' => 'select',
|
| 312 |
'#title' => t('Slideshow Layout'),
|
| 313 |
'#options' => $options,
|
| 314 |
'#default_value' => $widget['api_layout'] ? $widget['api_layout'] : 'default',
|
| 315 |
'#description' => t('This controls the layout of the slideshow.'),
|
| 316 |
);
|
| 317 |
$form['api_slideshow']['api_rotate_speed'] = array(
|
| 318 |
'#type' => 'textfield',
|
| 319 |
'#title' => t('Transition'),
|
| 320 |
'#default_value' => isset($widget['api_rotate_speed']) ? $widget['api_rotate_speed'] : 5,
|
| 321 |
'#description' => t('If greater than 0, this determines how many seconds an image will be displayed before transitioning to the next image..'),
|
| 322 |
);
|
| 323 |
$form['api_slideshow']['api_blend'] = array(
|
| 324 |
'#type' => 'textfield',
|
| 325 |
'#title' => t('Fade'),
|
| 326 |
'#default_value' => isset($widget['api_blend']) ? $widget['api_blend'] : 2,
|
| 327 |
'#description' => t('If greater than 0, this determines how many seconds an image will fade before transitioning to the next image.'),
|
| 328 |
);
|
| 329 |
}
|
| 330 |
}
|
| 331 |
else if ($widget['type'] == 'flickr_cck_html_badge_text') {
|
| 332 |
$form['buddy_icon'] = array(
|
| 333 |
'#type' => 'select',
|
| 334 |
'#title' => t('Display Buddy Icon'),
|
| 335 |
'#default_value' => $widget['buddy_icon'],
|
| 336 |
'#options' => array(0 => t('Configurable'), 1 => t('Yes'), 2 => t('No')),
|
| 337 |
'#description' => t('If selected, and a Flickr username/id is included in the Flickr information, then the Flickr user\'s Buddy Icon will be displayed under the badge. If \'Configurable\', then this may be configured when creating the badge.'),
|
| 338 |
);
|
| 339 |
$form['number_of_photos'] = array(
|
| 340 |
'#type' => 'select',
|
| 341 |
'#title' => t('Number of Photos'),
|
| 342 |
'#default_value' => $widget['number_of_photos'],
|
| 343 |
'#options' => array(0 => t('Configurable'), 1, 3, 5, 10),
|
| 344 |
'#description' => t('How many photos will be displayed in a badge? If \'Configurable\', then this may be chosen when creating a badge. Otherwise, created badges will display up to this number of available photos.'),
|
| 345 |
);
|
| 346 |
$form['which_photos'] = array(
|
| 347 |
'#type' => 'select',
|
| 348 |
'#title' => t('Which Photos'),
|
| 349 |
'#default_value' => $widget['which_photos'],
|
| 350 |
'#options' => array(0 => t('Configurable'), 1 => t('Most recent'), 2 => t('A random selection')),
|
| 351 |
'#description' => t('Should the badge display the most recent photos or a random selection? If \'Configurable\', then this may be configured when creating the badge.'),
|
| 352 |
);
|
| 353 |
$form['photo_size'] = array(
|
| 354 |
'#type' => 'select',
|
| 355 |
'#title' => t('Photo Size'),
|
| 356 |
'#default_value' => $widget['photo_size'],
|
| 357 |
'#options' => array(0 => t('Configurable'), 1 => t('Square'), 2 => t('Thumbnail'), 3 => t('Mid-size')),
|
| 358 |
);
|
| 359 |
$form['orientation'] = array(
|
| 360 |
'#type' => 'select',
|
| 361 |
'#title' => t('Orientation'),
|
| 362 |
'#default_value' => $widget['orientation'],
|
| 363 |
'#options' => array(0 => t('Configurable'), 1 => t('Vertical'), 2 => t('Horizontal'), 3 => t('Custom')),
|
| 364 |
);
|
| 365 |
}
|
| 366 |
return $form;
|
| 367 |
|
| 368 |
case 'validate':
|
| 369 |
if ($widget['type'] == 'flickr_cck_textfields') {
|
| 370 |
if (!is_numeric($widget['flash_width']) || intval($widget['flash_width']) != $widget['flash_width'] || $widget['flash_width'] < 500) {
|
| 371 |
form_set_error('flash_width', t('"Width" must be a positive integer at least 500.'));
|
| 372 |
}
|
| 373 |
if (!is_numeric($widget['flash_height']) || intval($widget['flash_height']) != $widget['flash_height'] || $widget['flash_height'] < 500) {
|
| 374 |
form_set_error('flash_height', t('"Height" must be a positive integer at least 500.'));
|
| 375 |
}
|
| 376 |
}
|
| 377 |
break;
|
| 378 |
|
| 379 |
case 'save':
|
| 380 |
if ($widget['widget']['type'] == 'flickr_cck_textfields') {
|
| 381 |
return array('flash_width', 'flash_height', 'api_size', 'api_layout', 'api_rotate_speed', 'api_blend', );
|
| 382 |
}
|
| 383 |
else if ($widget['widget']['type'] == 'flickr_cck_html_badge_text') {
|
| 384 |
return array('badge_type', 'buddy_icon', 'number_of_photos', 'which_photos', 'photo_size', 'orientation', );
|
| 385 |
}
|
| 386 |
break;
|
| 387 |
}
|
| 388 |
}
|
| 389 |
|
| 390 |
/** Implementation of hook_widget **/
|
| 391 |
|
| 392 |
function flickr_cck_widget($op, &$node, $field, &$node_field) {
|
| 393 |
switch ($op) {
|
| 394 |
case 'form':
|
| 395 |
$form = array();
|
| 396 |
|
| 397 |
$form['flickr_cck_fieldset'] = array(
|
| 398 |
'#type' => 'fieldset',
|
| 399 |
'#title' => t($field['widget']['label']),
|
| 400 |
'#description' => $field['widget']['description'],
|
| 401 |
'#collapsible' => true,
|
| 402 |
'#collapsed' => false,
|
| 403 |
);
|
| 404 |
|
| 405 |
$form['flickr_cck_fieldset'][$field['field_name']] = array('#tree' => TRUE);
|
| 406 |
$textfield = 'username';
|
| 407 |
$field['required'] = FALSE;
|
| 408 |
$textfield_title = t('Flickr Username or ID');
|
| 409 |
|
| 410 |
if ($field['multiple']) {
|
| 411 |
$form['flickr_cck_fieldset'][$field['field_name']]['#type'] = 'fieldset';
|
| 412 |
$form['flickr_cck_fieldset'][$field['field_name']]['#title'] = t($field['widget']['label']);
|
| 413 |
$delta = 0;
|
| 414 |
foreach ($node_field as $data) {
|
| 415 |
if (isset($data[$textfield])) {
|
| 416 |
$form['flickr_cck_fieldset'][$field['field_name']][$delta][$textfield] = array(
|
| 417 |
'#type' => 'textfield',
|
| 418 |
'#title' => $textfield_title,
|
| 419 |
'#default_value' => $data[$textfield],
|
| 420 |
'#required' => ($delta == 0) ? $field['required'] : FALSE,
|
| 421 |
'#maxlength' => 255,
|
| 422 |
);
|
| 423 |
$form['flickr_cck_fieldset'][$field['field_name']][$delta]['value'] = array(
|
| 424 |
'#type' => 'textfield',
|
| 425 |
'#title' => t('Flickr User ID'),
|
| 426 |
'#default_value' => $data['value'],
|
| 427 |
'#disabled' => true,
|
| 428 |
// TODO: only needed for 4.7; remove once branched
|
| 429 |
'#attributes' => array('disabled' => 'disabled'),
|
| 430 |
);
|
| 431 |
$form['flickr_cck_fieldset'][$field['field_name']][$delta]['photoset'] = array(
|
| 432 |
'#type' => 'textfield',
|
| 433 |
'#title' => t('Flickr Photoset ID'),
|
| 434 |
'#default_value' => $data['photoset'],
|
| 435 |
'#required' => ($delta == 0) ? $field['required'] : FALSE,
|
| 436 |
'#maxlength' => 255,
|
| 437 |
);
|
| 438 |
$form['flickr_cck_fieldset'][$field['field_name']][$delta]['tags'] = array(
|
| 439 |
'#type' => 'textfield',
|
| 440 |
'#title' => t('Flickr Tags'),
|
| 441 |
'#default_value' => $data['tags'],
|
| 442 |
'#required' => ($delta == 0) ? $field['required'] : FALSE,
|
| 443 |
'#maxlength' => 255,
|
| 444 |
'#description' => t('Enter the tags of photos you wish to match. If you wish to display photos matching multiple tags, separate the tags with commas. For instance, you could search for \'daisy chains\' or \'daisy, chains\'.'),
|
| 445 |
);
|
| 446 |
$form['flickr_cck_fieldset'][$field['field_name']][$delta]['tagmode'] = array(
|
| 447 |
'#type' => 'select',
|
| 448 |
'#title' => t('Flickr Tag Mode'),
|
| 449 |
'#default_value' => $data['tag_mode'],
|
| 450 |
'#required' => ($delta == 0) ? $field['required'] : FALSE,
|
| 451 |
'#options' => array(
|
| 452 |
0 => t('Any Tags'),
|
| 453 |
1 => t('All Tags'),
|
| 454 |
),
|
| 455 |
'#description' => t('If you select \'Any Tags\', then photos matching any of the comma-separated tags will be displayed. If you select \'All Tags\', then only photos matching all of the comma-separated tags will be displayed.'),
|
| 456 |
);
|
| 457 |
$form['flickr_cck_fieldset'][$field['field_name']][$delta]['text'] = array(
|
| 458 |
'#type' => 'textfield',
|
| 459 |
'#title' => t('Flickr Text Search'),
|
| 460 |
'#default_value' => $data['text'],
|
| 461 |
'#required' => ($delta == 0) ? $field['required'] : FALSE,
|
| 462 |
'#maxlength' => 255,
|
| 463 |
'#description' => t('Enter the text of the photos you wish to search. This will return photos that the text matches for photo titles, descriptions, or tags.'),
|
| 464 |
);
|
| 465 |
$delta++;
|
| 466 |
}
|
| 467 |
}
|
| 468 |
foreach (range($delta, $delta + 2) as $delta) {
|
| 469 |
$form['flickr_cck_fieldset'][$field['field_name']][$delta][$textfield] = array(
|
| 470 |
'#type' => 'textfield',
|
| 471 |
'#title' => $textfield_title,
|
| 472 |
'#default_value' => '',
|
| 473 |
'#required' => ($delta == 0) ? $field['required'] : FALSE,
|
| 474 |
'#maxlength' => 255,
|
| 475 |
);
|
| 476 |
if ($textfield == 'username') {
|
| 477 |
$form['flickr_cck_fieldset'][$field['field_name']][$delta]['value'] = array(
|
| 478 |
'#type' => 'textfield',
|
| 479 |
'#title' => t('Flickr User ID'),
|
| 480 |
'#default_value' => '',
|
| 481 |
'#disabled' => true,
|
| 482 |
// TODO: only needed for 4.7; remove once branched
|
| 483 |
'#attributes' => array('disabled' => 'disabled'),
|
| 484 |
);
|
| 485 |
}
|
| 486 |
$form['flickr_cck_fieldset'][$field['field_name']][$delta]['photoset'] = array(
|
| 487 |
'#type' => 'textfield',
|
| 488 |
'#title' => t('Flickr Photoset ID'),
|
| 489 |
'#default_value' => $data['photoset'],
|
| 490 |
'#required' => ($delta == 0) ? $field['required'] : FALSE,
|
| 491 |
'#maxlength' => 255,
|
| 492 |
);
|
| 493 |
$form['flickr_cck_fieldset'][$field['field_name']][$delta]['tags'] = array(
|
| 494 |
'#type' => 'textfield',
|
| 495 |
'#title' => t('Flickr Tags'),
|
| 496 |
'#default_value' => $data['tags'],
|
| 497 |
'#required' => ($delta == 0) ? $field['required'] : FALSE,
|
| 498 |
'#maxlength' => 255,
|
| 499 |
'#description' => t('Enter the tags of photos you wish to match. If you wish to display photos matching multiple tags, separate the tags with commas. For instance, you could search for \'daisy chains\' or \'daisy, chains\'.'),
|
| 500 |
);
|
| 501 |
$form['flickr_cck_fieldset'][$field['field_name']][$delta]['tag_mode'] = array(
|
| 502 |
'#type' => 'select',
|
| 503 |
'#title' => t('Flickr Tag Mode'),
|
| 504 |
'#default_value' => $data['tag_mode'],
|
| 505 |
'#required' => ($delta == 0) ? $field['required'] : FALSE,
|
| 506 |
'#options' => array(
|
| 507 |
0 => t('Any Tags'),
|
| 508 |
1 => t('All Tags'),
|
| 509 |
),
|
| 510 |
'#description' => t('If you select \'Any Tags\', then photos matching any of the comma-separated tags will be displayed. If you select \'All Tags\', then only photos matching all of the comma-separated tags will be displayed.'),
|
| 511 |
);
|
| 512 |
$form['flickr_cck_fieldset'][$field['field_name']][$delta]['text'] = array(
|
| 513 |
'#type' => 'textfield',
|
| 514 |
'#title' => t('Flickr Text Search'),
|
| 515 |
'#default_value' => $data['text'],
|
| 516 |
'#required' => ($delta == 0) ? $field['required'] : FALSE,
|
| 517 |
'#maxlength' => 255,
|
| 518 |
'#description' => t('Enter the text of the photos you wish to search. This will return photos that the text matches for photo titles, descriptions, or tags.'),
|
| 519 |
);
|
| 520 |
}
|
| 521 |
}
|
| 522 |
else {
|
| 523 |
$form['flickr_cck_fieldset'][$field['field_name']][0][$textfield] = array(
|
| 524 |
'#type' => 'textfield',
|
| 525 |
'#title' => $textfield_title, //t($field['widget']['label']),
|
| 526 |
'#default_value' => isset($node_field[0][$textfield]) ? $node_field[0][$textfield] : '',
|
| 527 |
'#required' => $field['required'],
|
| 528 |
'#maxlength' => 255,
|
| 529 |
);
|
| 530 |
if ($textfield == 'username') {
|
| 531 |
$form['flickr_cck_fieldset'][$field['field_name']][0]['value'] = array(
|
| 532 |
'#type' => 'textfield',
|
| 533 |
'#title' => t('Flickr User ID'),
|
| 534 |
'#default_value' => isset($node_field[0]['value']) ? $node_field[0]['value'] : '',
|
| 535 |
'#disabled' => true,
|
| 536 |
// TODO: only needed for 4.7; remove once branched
|
| 537 |
'#attributes' => array('disabled' => 'disabled'),
|
| 538 |
);
|
| 539 |
$form['flickr_cck_fieldset'][$field['field_name']][0]['photoset'] = array(
|
| 540 |
'#type' => 'textfield',
|
| 541 |
'#title' => t('Flickr Photoset ID'),
|
| 542 |
'#default_value' => $node_field[0]['photoset'],
|
| 543 |
'#required' => ($delta == 0) ? $field['required'] : FALSE,
|
| 544 |
'#maxlength' => 255,
|
| 545 |
);
|
| 546 |
$form['flickr_cck_fieldset'][$field['field_name']][0]['tags'] = array(
|
| 547 |
'#type' => 'textfield',
|
| 548 |
'#title' => t('Flickr Tags'),
|
| 549 |
'#default_value' => $node_field[0]['tags'],
|
| 550 |
'#required' => ($delta == 0) ? $field['required'] : FALSE,
|
| 551 |
'#maxlength' => 255,
|
| 552 |
'#description' => t('Enter the tags of photos you wish to match. If you wish to display photos matching multiple tags, separate the tags with commas. For instance, you could search for \'daisy chains\' or \'daisy, chains\'.'),
|
| 553 |
);
|
| 554 |
$form['flickr_cck_fieldset'][$field['field_name']][0]['tag_mode'] = array(
|
| 555 |
'#type' => 'select',
|
| 556 |
'#title' => t('Flickr Tag Mode'),
|
| 557 |
'#default_value' => $node_field[0]['tag_mode'],
|
| 558 |
'#required' => ($delta == 0) ? $field['required'] : FALSE,
|
| 559 |
'#options' => array(
|
| 560 |
0 => t('Any Tags'),
|
| 561 |
1 => t('All Tags'),
|
| 562 |
),
|
| 563 |
'#description' => t('If you select \'Any Tags\', then photos matching any of the comma-separated tags will be displayed. If you select \'All Tags\', then only photos matching all of the comma-separated tags will be displayed.'),
|
| 564 |
);
|
| 565 |
$form['flickr_cck_fieldset'][$field['field_name']][0]['text'] = array(
|
| 566 |
'#type' => 'textfield',
|
| 567 |
'#title' => t('Flickr Text Search'),
|
| 568 |
'#default_value' => $node_field[0]['text'],
|
| 569 |
'#required' => ($delta == 0) ? $field['required'] : FALSE,
|
| 570 |
'#maxlength' => 255,
|
| 571 |
'#description' => t('Enter the text of the photos you wish to search. This will return photos that the text matches for photo titles, descriptions, or tags.'),
|
| 572 |
);
|
| 573 |
}
|
| 574 |
}
|
| 575 |
return $form;
|
| 576 |
}
|
| 577 |
}
|
| 578 |
|
| 579 |
function theme_flickr_cck_flash_slideshow($field, $item) {
|
| 580 |
$width = $field['widget']['flash_width'];
|
| 581 |
$width = ($width ? "width=$width" : '');
|
| 582 |
$height = $field['widget']['flash_height'];
|
| 583 |
$height = ($height ? "height=$height" : '');
|
| 584 |
|
| 585 |
if (!$field['value']) {
|
| 586 |
$field['value'] = _flickr_cck_field_submit_id($field);
|
| 587 |
}
|
| 588 |
$id = 'user_id=' . drupal_urlencode($item['value']);
|
| 589 |
$id .= '&set_id=' . drupal_urlencode($item['photoset']);
|
| 590 |
$id .= '&tags=' . drupal_urlencode($item['tags']);
|
| 591 |
$id .= '&tag_mode=' . ($item['tag_mode'] ? 'all' : 'any');
|
| 592 |
$id .= '&text=' . drupal_urlencode($item['text']);
|
| 593 |
|
| 594 |
$output .= "<iframe align=center src=\"http://www.flickr.com/slideShow/index.gne?$id\" frameBorder=0 $width scrolling=no $height></iframe>";
|
| 595 |
return $output;
|
| 596 |
}
|
| 597 |
|
| 598 |
function theme_flickr_cck_flash_badge($field, $item) {
|
| 599 |
$stylesheet = drupal_get_path('theme', $_GLOBAL['theme_key'].'/flickr_cck.css');
|
| 600 |
if (! file_exists($stylesheet) ) {
|
| 601 |
$stylesheet = drupal_get_path('module', 'flickr_cck')."/flickr_cck.css";
|
| 602 |
}
|
| 603 |
// TODO: check for 4.7; remove else after branching
|
| 604 |
if (function_exists('drupal_add_css')) {
|
| 605 |
drupal_add_css($stylesheet);
|
| 606 |
}
|
| 607 |
else {
|
| 608 |
theme_add_style($stylesheet);
|
| 609 |
}
|
| 610 |
|
| 611 |
$tags = drupal_urlencode($item['tags']);
|
| 612 |
$id .= '&zg_person_id=' . drupal_urlencode($item['value']);
|
| 613 |
$id .= '&zg_set_id=' . drupal_urlencode($item['photoset']);
|
| 614 |
$id .= '&zg_tags=' . drupal_urlencode($tags);
|
| 615 |
$id .= '&zg_tag_mode=' . ($item['tag_mode'] ? 'all' : 'any');
|
| 616 |
$id .= '&zg_tags=' . drupal_urlencode($text);
|
| 617 |
$bg_color = 'ffffff';
|
| 618 |
$badge_url = 'http://www.flickr.com/apps/badge/badge_iframe.gne?zg_bg_color=' . $bg_color . $id;
|
| 619 |
|
| 620 |
$output .= "\n\n" . '<!-- Start of Flickr Badge -->' . "\n";
|
| 621 |
$output .= ' <div class="flickr_flash_badge">' . "\n";
|
| 622 |
$output .= ' <iframe style="background-color:#' . $bg_color . '; border-color:#' . $bg_color . '; border:none;" width="113" height="151" frameborder="0" scrolling="no" src="' . $badge_url . '" title="Flickr Badge"></iframe>' . "\n";
|
| 623 |
$output .= ' </div><!--close flickr_badge-->' . "\n";
|
| 624 |
$output .= '<!-- End of Flickr Badge -->' . "\n\n";
|
| 625 |
return $output;
|
| 626 |
}
|
| 627 |
|
| 628 |
function theme_flickr_cck_api_slideshow($field, $item) {
|
| 629 |
// for 4.7 only TODO
|
| 630 |
GLOBAL $flickr_cck_drupal_4_7;
|
| 631 |
static $count = 0;
|
| 632 |
if (!module_hook('slideshow_creator', 'process_text')) {
|
| 633 |
return theme('flickr_cck_flash_badge', $field, $item);
|
| 634 |
}
|
| 635 |
|
| 636 |
$size = $field['widget']['api_size'] ? $field['widget']['api_size'] : 's';
|
| 637 |
|
| 638 |
$version = '2';
|
| 639 |
$rotate_speed = isset($field['widget']['api_rotate_speed']) ? $field['widget']['api_rotate_speed'] : 5;
|
| 640 |
$slideshow_name = 'flash_cck_slideshow_' . $count++;
|
| 641 |
$blend = isset($field['widget']['api_blend']) ? $field['widget']['api_blend'] : 2;
|
| 642 |
$layout = $field['widget']['api_layout'] ? $field['widget']['api_layout'] : 'default';
|
| 643 |
|
| 644 |
if ($item['value']) {
|
| 645 |
$args['user_id'] = $item['value'];
|
| 646 |
}
|
| 647 |
if ($item['set_id']) {
|
| 648 |
$args['set_id'] = $item['photoset'];
|
| 649 |
}
|
| 650 |
if ($item['tags']) {
|
| 651 |
$args['tags'] = $item['tags'];
|
| 652 |
$args['tag_mode'] = $item['tag_mode'] ? 'all' : 'any';
|
| 653 |
}
|
| 654 |
if ($item['text']) {
|
| 655 |
$args['text'] = $item['text'];
|
| 656 |
}
|
| 657 |
$flickr_images = flickr_request('flickr.photos.search', $args);
|
| 658 |
|
| 659 |
$images = array();
|
| 660 |
foreach ($flickr_images['photos']['photo'] as $flickr_image) {
|
| 661 |
$image = array();
|
| 662 |
// TODO: 4.7 only
|
| 663 |
if ($flickr_cck_drupal_4_7) {
|
| 664 |
$image['image_url'] = flickr_cck_photo_img($flickr_image, $size, $format = NULL);
|
| 665 |
}
|
| 666 |
else {
|
| 667 |
$image['image_url'] = flickr_photo_img($flickr_image, $size, $format = NULL);
|
| 668 |
}
|
| 669 |
$image['link'] = flickr_photo_page_url($flickr_image['owner'], $flickr_image['id']);
|
| 670 |
$image['title'] = $flickr_image['title'];
|
| 671 |
$image['description'] = $flickr_image['title'];
|
| 672 |
$image['target'] = $item['target'] ? $item['target'] : '_self';
|
| 673 |
$images[] = (object)$image;
|
| 674 |
}
|
| 675 |
|
| 676 |
$text .= "[slideshow: $version, rotate=$rotate_speed, blend=$blend, name=$slideshow_name, layout=$layout";
|
| 677 |
foreach ($images as $image) {
|
| 678 |
$text .= ", img=|$image->image_url|$image->link|$image->title|$image->description|$image->target|";
|
| 679 |
}
|
| 680 |
$text .= ']';
|
| 681 |
|
| 682 |
$output = module_invoke('slideshow_creator', 'process_text', $text);
|
| 683 |
return $output;
|
| 684 |
}
|