Using CCK to Customize and Regenerate Thumbnails and Videos with specific parameters
';
$output .= '
Since FlashVideo version 2.2, a method has been in place to provide node specific parameters to create or regenerate the thumbnail or video. '; $output .= 'This method allows for any node creator or updater to override the parameters specified by the FlashVideo Settings to create custom functionality out of their '; $output .= 'specific node. Below are several examples of where this functionality would be required.
'; $output .= 'These are just a sample of the added power with the new version of FlashVideo 2.2. Now, with the power of the Content Creation Kit, specific parameters can be '; $output .= 'given to the FlashVideo node type that will customize how that node generates the Video or Thumbnail. Here\'s how it works. When you create your new node type '; $output .= 'using the Content Creation Kit module, you can now provide several different parameters that will be used to command the FlashVideo module during the conversion process. With these CCK '; $output .= 'parameters defined, they will then be visible during the node entry and updating, allowing very specific power over the conversion of that node. '; $output .= 'In other words, any parameter that you provide in these CCK data fields will simply override the default functionality provided in the FlashVideo Settings for that Node Type. The whole idea is fairly straight forward if you are familiar with CCK. '; $output .= 'You can basically think of this new feature as placing the customizable that the FlashVideo Settings has within each node submitted or updated.
'; $output .= 'Below are the parameters that you can create to override FlashVideo functionality. Please note that each parameter MUST be labeled the same as below, otherwise the FlashVideo Module will just ignore it.
After you have created these custom CCK fields for your node type, you will then have the power over the FlashVideo module during node insertions and updates.
'; return $output; case 'admin/settings/modules#description': return t('Allows you to use CCK to override FlashVideo Settings for each node entry.'); } } /** * Hook from the FlashVideo module that gets all params to overate. */ function flashvideo_cck_flashvideo_get_params($file, $flags, $params) { if( ($flags > 0) ) { // We only want to do this on the pending files. $node = node_load($file->nid); // We need to load the node to get the CCK variables. if(flashvideo_cck_get_overloaded_params($node, $params)) { // Only if they don't already provide a FLASHVIDEO_USE_CUSTOM flag. $params['create_thumb'] = (($flags & FLASHVIDEO_REGEN_THUMB) == FLASHVIDEO_REGEN_THUMB); // Do we regenerate a thumbnail? $params['create_video'] = (($flags & FLASHVIDEO_REGEN_VIDEO) == FLASHVIDEO_REGEN_VIDEO); // Do we regenerate a video? } } return $params; } /** * Gets the overloaded parameters specified by that particular node. * * You can override any of the conversion parameters by using CCK. * This will allow you to create or regenerate the thumbnail or video according to new parameters provided in the CCK fields. * This section will search for any parameters provided with CCK and then re-generate the thumbnail * according to those overrided parameters. * * @param $node * A standard Drupal node * * @param $params * An array of the default parameters. */ function flashvideo_cck_get_overloaded_params($node, &$params) { $params_overloaded = FALSE; $params['regen_thumb'] = 0; // New parameter to regenerate the thumbnail. $params['regen_video'] = 0; // New parameter to regenerate the video. foreach($params as $param => $value) { // Iterate through all of our parameters. $overload_name = FLASHVIDEO_PARAM_PREFIX . $param; // Get the overloaded variable name. if(isset($node->{$overload_name}) && ($node->{$overload_name}[0]['value'] != $value)) { // Is it set in our node and different from the default? $params[$param] = $node->{$overload_name}[0]['value']; // If so, then add it to our new parameters. $params_overloaded = TRUE; } } return $params_overloaded; } /** * FlashVideo hook once each node get submitted.. * * This is the FlashVideo CCK hook to set up all the default values for the overidable parameters. */ function flashvideo_cck_flashvideo_submit($node, $params) { if(flashvideo_cck_get_overloaded_params($node, $params)) { // If we decide to overide some paramters. $flags = 0; if($params['regen_video']) { $flags = $flags | FLASHVIDEO_REGEN_VIDEO; // Set the regenerate video flag. } if($params['regen_thumb']) { $flags = $flags | FLASHVIDEO_REGEN_THUMB; // Set the regenerate thumbnail flag. } if( $params['regen_video'] || $params['regen_thumb'] ) { // Grab all files in this node that are from the FlashVideo table, except the Original Video $files = db_query("SELECT * FROM {flashvideo} fv LEFT JOIN {files} f ON fv.fid = f.fid WHERE (fv.nid=%d) AND (fv.fid <> fv.oid)", $node->nid); while($file = db_fetch_object($files)) { $file_is_flash = flashvideo_is_flash($file->filemime); if( ($params['regen_video'] && $file_is_flash) || ($params['regen_thumb'] && !$file_is_flash) ) { file_delete($file->filepath); // Delete the file from the disk. db_query("DELETE FROM {flashvideo} WHERE (fid = %d)", $file->fid); // Delete the file from the flahvideo table. db_query("DELETE FROM {files} WHERE (fid = %d)", $file->fid); // Delete the file from the files table. db_query("DELETE FROM {upload} WHERE (fid = %d)", $file->fid); // Delete the file from the files table. } db_query("DELETE FROM {ffmpeg_data} WHERE (fid = %d)", $file->fid); // Delete all unsuccessful conversions. } db_query("UPDATE {flashvideo} SET flags=%d WHERE nid=%d AND oid=fid", $flags, $node->nid); // Update the flags for the original video. } } } /** * Hook Form Alter. * * This is the FlashVideo CCK hook to set up all the default values for the overidable parameters. */ function flashvideo_cck_form_alter($form_id, &$form) { if (isset($form['type'])) { // Is the form set. $node_type = $form['type']['#value']; // Get the Node Type. if($form_id == $node_type.'_node_form') { // Check for the Node Editor. if(flashvideo_variable_get($node_type, 'enable', 0)) { // Make sure the FlashVideo module is enabled for this node type. $params = flashvideo_get_convert_params($node_type); // Get the Default Conversion parameters. foreach($params as $param => $value) { // Iterate through all parameters. $field = FLASHVIDEO_PARAM_PREFIX . $param; // Set the field name for each parameters. if(isset($form[$field])) { // Is this form variable set. if(!$form[$field][0]['value']['#default_value']) { // Only set this if they haven't already provided a value. $form[$field][0]['value']['#default_value'] = $value; // If so, then overide the default value. } } } /** * We need to make sure that the regenerate parameters are set to 0... * This will keep from having unnecessary regenerates. */ $field = FLASHVIDEO_PARAM_PREFIX . 'regen_thumb'; if(isset($form[$field])) { // Is this form variable set. $form[$field][0]['value']['#default_value'] = 0; // If so, then overide the default value. } $field = FLASHVIDEO_PARAM_PREFIX . 'regen_video'; if(isset($form[$field])) { // Is this form variable set. $form[$field][0]['value']['#default_value'] = 0; // If so, then overide the default value. } } } } } ?>