diff --git xspf_playlist_node/xspf_playlist_node.module xspf_playlist_node/xspf_playlist_node.module index c0ea7e5..e8bad6c 100644 --- xspf_playlist_node/xspf_playlist_node.module +++ xspf_playlist_node/xspf_playlist_node.module @@ -60,7 +60,7 @@ function xspf_playlist_node_form_node_type_form_alter(&$form, &$form_state) { // Get the current content type $content_type = $form['#node_type']->type; // Build the name of this variable - $variable_name = 'xspf_playlist_node_enabled_type_' . $content_type; + $variable_name = 'xspf_playlist_node_enabled_type'; // Use a custom submit function so we can save this data $form['#submit'][] = 'xspf_playlist_node_type_settings_submit'; @@ -70,13 +70,13 @@ function xspf_playlist_node_form_node_type_form_alter(&$form, &$form_state) { '#type' => 'fieldset', '#title' => t('XSPF Playlists'), '#collapsible' => TRUE, - '#collapsed' => variable_get($variable_name, FALSE) ? FALSE : TRUE, + '#collapsed' => variable_get($variable_name .'_'. $content_type, FALSE) ? FALSE : TRUE, ); $form['xspf_playlists'][$variable_name] = array( '#type' => 'checkbox', '#title' => t('Enabled'), - '#default_value' => variable_get($variable_name, FALSE), + '#default_value' => variable_get($variable_name .'_'. $content_type, FALSE), '#description' => t('Enable XSPF playlists on this content type'), ); @@ -85,7 +85,7 @@ function xspf_playlist_node_form_node_type_form_alter(&$form, &$form_state) { '#title' => t('Select Playlist Files'), ); // select what options will be used to build the playlist - $form['xspf_playlists']['content']['xspf_use_files_' . $content_type] = array( + $form['xspf_playlists']['content']['xspf_use_files'] = array( '#type' => 'select', '#multiple' => TRUE, '#title' => t('Build Playlist From Files'), @@ -99,7 +99,7 @@ function xspf_playlist_node_form_node_type_form_alter(&$form, &$form_state) { $my_node = new StdClass(); $my_node->type = $content_type; foreach (variable_get('xspf_'. $content_type .'_use', array()) as $extension) { - $form['content'][] = xspf_playlist_invoke_fire('xspf_playlist_use', 'config', $my_node, $extension); + $form['xspf_playlists']['content'][] = xspf_playlist_invoke_fire('xspf_playlist_use', 'config', $my_node, $extension); } $form['xspf_playlists']['playlists'] = array( @@ -109,33 +109,16 @@ function xspf_playlist_node_form_node_type_form_alter(&$form, &$form_state) { // settings for item duration. Images need duration tags so that they rotate in the playlist $options = array_values(array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30)); - $form['xspf_playlists']['playlists']['xspf_'. $content_type .'_duration'] = array( + $form['xspf_playlists']['playlists']['xspf_playlist_duration'] = array( '#type' => 'select', '#title' => t('Image duration'), '#options' => $options, - '#default_value' => variable_get('xspf_'. $content_type .'_duration', 10), + '#default_value' => variable_get('xspf_playlist_duration_'. $content_type, 10), '#description' => t('Image files in a playlist need to have a duration (in seconds) for which they are shown.'), ); } - -/** - * Helper function to save the XSPF values coming out of the node type configuration form - * @param unknown_type $form - * @param unknown_type $form_state - * @return unknown_type - */ -function xspf_playlist_node_type_settings_submit($form, $form_state) { - // Process the incoming XSPF variables - foreach ($form_state['values'] as $key => $value) { - if (strpos($key, 'xspf') !== FALSE) { - variable_set($key, $value); - } - } -} - - /* ********************************************** */ /* CONTRIB HOOKS */ /* ********************************************** */ @@ -363,7 +346,7 @@ function xspf_playlist_node_build_file_item($node, $url, $type = null) { if (in_array(strtolower($type), array('jpg', 'gif', 'png'))) { $item[] = array( 'key' => 'duration', - 'value' => variable_get('xspf_'. $node->type .'_duration', 10), + 'value' => variable_get('xspf_playlist_duration_'. $node->type, 10), ); } diff --git xspf_playlist_thumb/xspf_playlist_thumb.module xspf_playlist_thumb/xspf_playlist_thumb.module index 5975246..b3bd3ac 100644 --- xspf_playlist_thumb/xspf_playlist_thumb.module +++ xspf_playlist_thumb/xspf_playlist_thumb.module @@ -14,39 +14,37 @@ * drupal form * @return unknown_type */ -function xspf_playlist_thumb_form_alter(&$form, $form_state, $form_id) { - // alter the node settings - - // alter the settings on the admin/settings/xspf_playlist/CONTENT_TYPE form - if ($form_id == 'xspf_playlist_node_admin_content_type_form') { - - // get the content type - $type = $form['content_type']['#value']; - - // get any modules which implement thumbnails - $fields = module_invoke_all('xspf_playlist_thumbnail', 'define', null); - $form['content']['thetype_'. $type]['xspf_'. $type .'_thumb'] = array( - '#title' => t('Default thumbnail field'), - '#type' => 'select', - '#options' => $fields, - '#multiple' => true, - '#default_value' => variable_get('xspf_'. $type .'_thumb', ''), - '#description' => t('Select the thumbnail type you would like to use. You can select multiple, but if multiple thumbnails for an item exist, the first one found will be used.'), - ); - - // get any modules which implement configuration for thumbnails - $configurations = module_invoke_all('xspf_playlist_thumbnail', 'config', $my_node); - if ($configurations) { - $form['content']['thetype_'. $type][] = $configurations; - } +function xspf_playlist_thumb_form_node_type_form_alter(&$form, $form_state) { + // get the content type + $type = $form['#node_type']->type; + + // get any modules which implement thumbnails + $fields = module_invoke_all('xspf_playlist_thumbnail', 'define', null); + $form['xspf_playlists']['thumbnails'] = array( + '#type' => 'fieldset', + '#title' => t('Select Thumbnails Files'), + ); + $form['xspf_playlists']['thumbnails']['xspf_thumb_types'] = array( + '#title' => t('Thumbnail field Types'), + '#type' => 'select', + '#options' => $fields, + '#multiple' => true, + '#default_value' => variable_get('xspf_thumb_types_'. $type, ''), + '#description' => t('Select the thumbnail type you would like to use. You can select multiple, but if multiple thumbnails for an item exist, the first one found will be used.'), + ); - $form['content']['thetype_'. $type]['xspf_'. $type .'_thumb_first'] = array( - '#title' => t('Use thumbnail only for first playlist item'), - '#type' => 'checkbox', - '#default_value' => variable_get('xspf_'. $type .'_thumb_first', false), - '#description' => t('By default, all items on the playlist have a thumbnail applied. This can create conditions where the thumbnail is shown behind the content being displayed (especially on images). If you check this, a thumbnail will only be show on the first item on the playlist.'), - ); + // get any modules which implement configuration for thumbnails + $configurations = module_invoke_all('xspf_playlist_thumbnail', 'config', $type); + if ($configurations) { + $form['xspf_playlists']['thumbnails'][] = $configurations; } + + $form['xspf_playlists']['thumbnails']['xspf_thumb_first'] = array( + '#title' => t('Use thumbnail only for first playlist item'), + '#type' => 'checkbox', + '#default_value' => variable_get('xspf_thumb_first_'. $type, false), + '#description' => t('By default, all items on the playlist have a thumbnail applied. This can create conditions where the thumbnail is shown behind the content being displayed (especially on images). If you check this, a thumbnail will only be show on the first item on the playlist.'), + ); } @@ -67,18 +65,19 @@ function xspf_playlist_thumb_form_alter(&$form, $form_state, $form_id) { */ function xspf_playlist_thumb_xspf_playlist_item_alter(&$item, $node, $url) { // Look for modules that return potential thumbs. - $modules = variable_get('xspf_'. $node->type .'_thumb', false); + $modules = variable_get('xspf_thumb_types_'. $node->type, false); if ($modules) { foreach ($modules as $module) { // split the name into parts list($module_name, $separator, $config) = split('[--]', $module); // invoke the thumbnail hook if (module_exists($module_name)) { - if ($thumb = module_invoke($module_name, 'xspf_playlist_thumbnail', 'return', $node, $config)) { + $thumb = module_invoke($module_name, 'xspf_playlist_thumbnail', 'return', $node, $config); + if (isset($thumb)) { // Some modules may pass back an array. Only take the first item if (is_array($thumb)) {$thumb = $thumb[0]; } // We're only returning the specified thumb. - xspf_playlist_item_set_value($item, array('key' => 'image', 'value' => $thumb), false, false); + xspf_playlist_item_set_value($item, array('key' => 'image', 'value' => xspf_playlist_url($thumb)), false, false); return; } } @@ -91,28 +90,38 @@ function xspf_playlist_thumb_xspf_playlist_item_alter(&$item, $node, $url) { * implements hook_xspf_playlist_thumbnail * build the default options for the admin screen * @param $op is the operation happening - * @param $node is a node object + * @param $node is a node object, in the case of $op='config' is the node type. * @param $config is which config to run */ function xspf_playlist_thumb_xspf_playlist_thumbnail($op, $node, $config = null) { switch($op){ case 'define': $items = array( - 'xspf_playlist_thumb--1' => t('none'), - 'xspf_playlist_thumb--2' => t('XSPF: Default thumbnail'), - 'xspf_playlist_thumb--3' => t('Drupal: Upload attached files'), + 'xspf_playlist_thumb--1' => t('None'), + 'xspf_playlist_thumb--2' => t('Drupal: Upload attached files'), + 'xspf_playlist_thumb--3' => t('XSPF: CCK Filefield/Imagefield field'), + 'xspf_playlist_thumb--4' => t('XSPF: Default thumbnail'), ); return $items; break; case 'config': // return a configuration array - $form['xspf_playlist_thumb_'. $node->type] = array( + $form['xspf_thumb_cck_filefield'] = array( + '#type' => 'select', + '#title' => t('CCK Filefield/Imagefield field name with the thumbnail'), + '#options' => xspf_playlist_thumb_cck_fields($node), + '#default_value' => variable_get('xspf_thumb_cck_filefield_'. $node, NULL), + '#description' => t('Enter a CCK Filefield/Imagefield Field name with the thumbnail you wish to use'), + '#prefix' => '