"fieldset", "#weight" => -1, "#title" => "Dash Media Player: ImageCache Settings", ); // Get all of the presets. $presets = array(); $presets[0] = 'none'; $result = db_query("SELECT * FROM {imagecache_preset}"); while( $preset = db_fetch_object( $result ) ) { $presets[$preset->presetid] = $preset->presetname; } $image_presets = db_fetch_object( db_query( "SELECT * FROM {dashplayer_imagecache} WHERE field_name='%s'", $form['#field']['field_name'] )); $form['dashplayer_imagecache']['node_preset'] = array( '#type' => 'select', '#title' => t('Node: ImageCache Preset'), '#description' => t('Select the ImageCache preset that you would like to use for the Dash Player node display.'), '#options' => $presets, '#default_value' => ($image_presets ? $image_presets->node_pid : 0), ); $form['dashplayer_imagecache']['thumb_preset'] = array( '#type' => 'select', '#title' => t('Thumbnail: ImageCache Preset'), '#description' => t('Select the ImageCache preset that you would like to use for the Dash Player thumbnail display.'), '#options' => $presets, '#default_value' => ($image_presets ? $image_presets->thumb_pid : 0), ); $form['#submit'][] = 'dashplayer_imagecache_submit'; } } function dashplayer_imagecache_exists( $node_type, $field_name ) { $sql = "SELECT COUNT(*) FROM {dashplayer_imagecache} WHERE node_type='%s' AND field_name='%s'"; return db_result( db_query( $sql, $node_type, $field_name ) ); } function dashplayer_imagecache_delete( $node_type, $field_name ) { $sql = "DELETE FROM {dashplayer_imagecache} WHERE node_type='%s' AND field_name='%s'"; db_query( $sql, $node_type, $field_name ); } function dashplayer_imagecache_submit( $form, &$form_state ) { $node_type = $form['#field']['type_name']; $field_name = $form['#field']['field_name']; $node_pid = $form['dashplayer_imagecache']['#post']['node_preset']; $thumb_pid = $form['dashplayer_imagecache']['#post']['thumb_preset']; // Search for this field name in the table. if( dashplayer_imagecache_exists( $node_type, $field_name ) ) { if( !$node_pid && !$thumb_pid ) { dashplayer_imagecache_delete( $node_type, $field_name ); } else { $sql = "UPDATE {dashplayer_imagecache} SET node_pid=%d, thumb_pid=%d WHERE node_type='%s' AND field_name='%s'"; db_query( $sql, $node_pid, $thumb_pid, $node_type, $field_name ); } } else { if( $node_pid || $thumb_pid ) { $sql = "INSERT INTO {dashplayer_imagecache} (node_type, field_name, node_pid, thumb_pid) VALUES ( '%s', '%s', %d, %d )"; db_query( $sql, $node_type, $field_name, $node_pid, $thumb_pid ); } } } function dashplayer_imagecache_content_fieldapi( $op, $field ) { if( $op == 'delete instance' ) { $field_name = $field['field_name']; $node_type = $field['type_name']; if( dashplayer_imagecache_exists( $node_type, $field_name ) ) { dashplayer_imagecache_delete( $node_type, $field_name ); } } } function dashplayer_imagecache_get_file( $presetid, $filename, $type ) { $preset_name = db_result( db_query( "SELECT presetname FROM {imagecache_preset} WHERE presetid=%d", $presetid ) ); $preset->filename = $type; $preset->filepath = file_directory_path() .'/imagecache/' . $preset_name . '/' . $filename; $preset->weight = -8; $preset->mediatype = "image"; $preset->mediaclass = "image"; return $preset; } function dashplayer_imagecache_nodeapi( &$node, $op, $teaser ) { if( $op == 'load' ) { $additions = array(); $image = db_fetch_object( db_query( "SELECT * FROM {dashplayer_imagecache} WHERE node_type='%s'", $node->type ) ); // Make sure that we have an image, and the field has been populated. if( $image && $node->{$image->field_name} && $node->{$image->field_name}[0] ) { $filename = $node->{$image->field_name}[0]['filename']; if( $filename ) { if( $image->node_pid ) { $additions["dashplayer_images"][] = dashplayer_imagecache_get_file( $image->node_pid, $filename, "preview" ); } if( $image->thumb_pid ) { $additions["dashplayer_images"][] = dashplayer_imagecache_get_file( $image->thumb_pid, $filename, "thumbnail" ); } } } return $additions; } }