? xspf_playlist_thumb.patch Index: xspf_playlist_thumb.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/xspf_playlist/xspf_playlist_thumb/xspf_playlist_thumb.module,v retrieving revision 1.1.2.3.2.1 diff -u -p -r1.1.2.3.2.1 xspf_playlist_thumb.module --- xspf_playlist_thumb.module 14 Dec 2008 19:06:32 -0000 1.1.2.3.2.1 +++ xspf_playlist_thumb.module 13 Feb 2009 23:49:15 -0000 @@ -15,10 +15,46 @@ function xspf_playlist_thumb_get_attache $thumbs[] = $file->filepath; } } - if ($thumbs) {return $thumbs;} + return $thumbs?$thumbs:''; } } +/** + * Return an array of files defined in a CCK Imagefield/Filefield field in a node suitable for use as thumbnail images. + * + * @param $node + * A node object. + * @param $field_name + * CCK Field name where is the thumbnail + */ +function xspf_playlist_thumb_get_cck_imagefield_files($node,$field_name) { + if (isset($node->{$field_name})) { + $thumbs = array(); + foreach($node->{$field_name} as $field) { + $thumbs[] = $GLOBALS['base_path'] . $field['filepath']; + } + return $thumbs?$thumbs:''; + } +} + +/** + * This function gets a list of all CCK fields that can be used for this content type + * + */ +function xspf_playlist_thumb_cck_fields($content_type) { + // get our content type's field + $fields = content_fields(NULL, $content_type); + if ($fields) { + foreach ($fields as $name => $field) { + // only bother with specified field types Filefield and Imagefield + if (in_array($field['type'], array('image', 'filefield') )) { + $return[$field['field_name']] .= t('CCK !type: !name', array('!type' => $field['type'], '!name' => $field['widget']['label'])); + } + } + return $return; + } +} + /* ******************************************************* */ /* xspf_playlist xspf hooks */ /* ******************************************************* */ @@ -37,6 +73,7 @@ function xspf_playlist_thumb_xspf_playli 'xspf_playlist_thumb--1' => t('none'), 'xspf_playlist_thumb--2' => t('XSPF: Default thumbnail'), 'xspf_playlist_thumb--3' => t('XSPF: Attached files'), + 'xspf_playlist_thumb--4' => t('XSPF: CCK Imagefield/Filefield field'), ); return $items; break; @@ -51,7 +88,16 @@ function xspf_playlist_thumb_xspf_playli '#prefix' => '
', '#suffix' => '
', ); - return $form; + $form['xspf_playlist_thumb_cck_imagefield_field_'. $node->type] = array( + '#type' => 'select', + '#title' => t('CCK Field Name with the thumbnail'), + '#options' => xspf_playlist_thumb_cck_fields($node->type), + '#default_value' => variable_get('xspf_playlist_thumb_cck_imagefield_field_'. $node->type, null), + '#description' => t('Enter a CCK Imagefield/Filefield Field name with the thumbnail you wish to use'), + '#prefix' => '
', + '#suffix' => '
', + ); + return $form; break; case 'return': @@ -68,6 +114,9 @@ function xspf_playlist_thumb_xspf_playli return xspf_playlist_thumb_get_attached_files($node); break; + case 4: + return xspf_playlist_thumb_get_cck_imagefield_files($node, variable_get('xspf_playlist_thumb_cck_imagefield_field_'. $node->type, null)); + break; } break; }