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; } $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.'), ); } } /* ******************************************************* */ /* XSPF PLAYLIST HOOKS */ /* ******************************************************* */ /** * Implementation of hook_xspf_playlist_item_alter(). * Add the thumbnail into the playlist * * Add player and bookmark metadata. * @param array $item * @param object $node * @param string $url * @param string $thumb * @param $meta */ 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); if ($modules) { foreach ($modules as $module) { // split the 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', $item, $node, $config)) { // Some modules may pass back an array. Only take the first item if (is_array($thumb)) { $thumb = $thumb[0]; } $thumb = '/'.$thumb; // We're only returning the specified thumb. xspf_playlist_item_set_value($item, array('key' => 'image', 'value' => $thumb), false, false); return; } } } } } /** * 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 $config is which config to run */ function xspf_playlist_thumb_xspf_playlist_thumbnail($op, &$item, $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--4' => t("CrAzY Al: Attached with same filename as FLV"), ); return $items; break; case 'config': // return a configuration array $form['xspf_playlist_thumb_'. $node->type] = array( '#type' => 'textfield', '#title' => t('Path to default thumbnail'), '#default_value' => variable_get('xspf_playlist_thumb_'. $node->type, null), '#description' => t('Enter a path to a thumbnail you wish to use as a default'), '#prefix' => '
', '#suffix' => '
', ); return $form; break; case 'return': switch ($config){ case 1: return; break; case 2: // return default thumbnail return variable_get('xspf_playlist_thumb_'. $node->type, null); break; case 3: return xspf_playlist_thumb_get_attached_files($node); break; case 4: $images = xspf_playlist_thumb_get_attached_files($node); // Find an attached image that has the same base filename as the current item... $pi = pathinfo($item[1]['value']); // PHP sucks $item_name = basename($item[1]['value'], $pi['extension']); foreach(xspf_playlist_thumb_get_attached_files($node) as $img) { $pi = pathinfo($item[1]['value']); if(basename($img, $pi['extension']) == $item_name) { return $img; } } // ... or return the image array and let it picj the first one. return $images; } break; } } /* ******************************************************* */ /* INTERNAL FUNCTIONS */ /* ******************************************************* */ /** * Return an array of files attached to a node suitable for use as thumbnail images. * * @param $node * is a drupal node object * @param $url * string $path to locaton * @param $all * boolean - will return one or all thumbnails with this node * @return string */ function xspf_playlist_thumb_get_attached_files($node) { if (isset($node->files)) { $thumbs = array(); foreach($node->files as $file) { // check the mime type of the file if (strstr($file->filemime, 'image')) { $thumbs[] = $file->filepath; } } if ($thumbs) {return $thumbs;} } } /* ******************************************************** */ /* THIS IS ALL OLD STUFF WHICH SHOULD BE REIMPLEMENTED AT * SOME POINT IN THE NEAR FUTURE */ /** * this wraps the theme image function so we can pass urls and paths */ /* function theme_xspf_playlist_thumb_image($path, $alt = '', $title = '', $attributes = '', $getsize = false) { if (strstr($path, 'http://')) { $attributes = drupal_attributes($attributes); return ''. check_plain($alt) .''; } else { return theme('image', $path, $alt, $title, $attributes, $getsize); } } */ /** * this builds the images that can be used for picking * @param $thumbs is an array of thumbnails * @param int $xid is the playlist id that this is related to * @return html */ /* function theme_xspf_playlist_thumbnailer_picker($thumbs, $xid) { $output = array(); // Add the JS and CSS. $path = drupal_get_path('module', 'xspf_playlist_thumb'); drupal_add_js($path . '/xspf_playlist_thumb.js'); drupal_add_css($path . '/xspf_playlist_thumb.css'); $output[] = '
'; foreach ($thumbs as $id => $path) { $output[] = '
'. theme('xspf_playlist_thumb_image', $path) ."
\n"; } $output[] = '
'; $output[] = '
'; return implode($output); } */ /** * Save data for a given thumbnail item. * * @param array $item * An item to be saved having the following keys: * - string type: The type of object, e.g., 'node'. * - id: The ID of the object, e.g., a node's nid value. * - vid: A version ID if the object takes one, e.g., a node's vid value. * - item_path: The path to a file representing the playlist item. * - thumbnail_path: The path to a file representing the playlist * item's thumbnail image. */ /* function xspf_playlist_thumb_save($item) { // Use a VID as the primary key if present, otherwise an ID. $key = isset($item['vid']) && $item['vid'] ? 'vid' : 'id'; // Test for an existing record. $result = db_fetch_array(db_query("SELECT * FROM {xspf_playlist_thumb} WHERE $key = %d AND type = '%s'", $item[$key], $item['type'])); // If found, update. if ($result[$item[$key]]) { db_query("UPDATE {xspf_playlist_thumb} SET item_path = '%s', thumbnail_path = '%s' WHERE $key = %d AND type = '%s'", $item['item_path'], $item['thumbnail_path'], $item[$key], $item['type']); } // Otherwise, create a new record. else { db_query("INSERT INTO {xspf_playlist_thumb} (type, id, vid, item_path, thumbnail_path) VALUES ('%s', %d, %d, '%s', '%s')", $item['type'], $item['id'], $item['vid'], $item['item_path'], $item['thumbnail_path']); } } */ /** * Delete existing thumbnail data for an item. * * @param string $type * The type of object, e.g., 'node'. * @param int $id * The ID of the object, e.g., a node's nid value. * @param int $vid * A version ID if the object takes one, e.g., a node's vid value. */ /* function xspf_playlist_thumb_delete($type, $id = NULL, $vid = NULL) { if ($vid) { db_query("DELETE FROM {xspf_playlist_thumb} WHERE vid = %d AND type = '%s'", $vid, $type); } elseif ($id) { db_query("DELETE FROM {xspf_playlist_thumb} WHERE id = %d AND type = '%s'", $id, $type); } } */ /** * Retrieve data for a given thumbnail item. * * @param array $item * An item to be saved having the following keys: * - type: The type of object, e.g., 'node'. * - id: The ID of the object, e.g., a node's nid value. * - vid: A version ID if the object takes one, e.g., a node's vid value. * - item_path: The path to a file representing the playlist item. * - thumbnail_path: The path to a file representing the playlist * item's thumbnail image. */ function xspf_playlist_thumb_load($item) { // At a minimum, test for a given type. $conditions = array("type = '%s'"); $parameters = array($item['type']); // For other properties, test for them if present in the incoming item. $fields = array( 'id' => '%d', 'vid' => '%d', 'item_path' => "'%s'", 'thumbnail_path' => "'%s'", ); foreach ($fields as $key => $placeholder) { if (isset($item[$key])) { $conditions[] = 'id = ' . $placeholder; $parameters[] = $item[$key]; } } return db_fetch_array(db_query('SELECT * FROM {xspf_playlist_thumb} WHERE ' . implode(' AND ', $conditions), $parameters)); } /** * @TODO need to figure out if this is going to be supported * Implementation of hook_nodeapi * * @param object $node * @param string $op * @param boolean $a3 * @param boolean $a4 */ /* function xspf_playlist_thumb_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { // Are any thumbnails being submitted? if (($op == 'insert' || $op == 'update') && isset($node->xspf_thumbnails)) { xspf_playlist_node_thumb_save($node); } elseif ($op == 'delete') { xspf_playlist_node_thumb_delete($node); } elseif ($op == 'delete revision') { xspf_playlist_node_thumb_delete($node, TRUE); } } */