Using CCK to Customize and Regenerate Thumbnails and Videos with Specific Parameters'; $output .= '

FlashVideo CCK enables users 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 for his/her '; $output .= 'specific node. Below are several examples of where this functionality would be required:

'; $output .= ''; $output .= '

With the power of the Content Construction 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 content type '; $output .= 'using the Content Construction 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.

'; $output .= '

Below are the field names that you can create to override FlashVideo functionality. Please note that each field name MUST be labeled the same as below, otherwise the FlashVideo module will just ignore it.

'; $header = array(t('Field Name'), t('Type'), t('Description')); $rows[] = array(t('flashvideo_regen_thumb'), t('Integer'), t('Used to allow the node editor to regenerate the thumbnail after an edit.')); $rows[] = array(t('flashvideo_regen_video'), t('Integer'), t('Used to allow the node editor to regenerate the video after an edit.')); $rows[] = array(t('flashvideo_output_dir'), t('Text'), t('Used to command the output directory. This is relative to the system files directory.')); $rows[] = array(t('flashvideo_cmd_path'), t('Text'), t('Used to specify the CWD path to the conversion utility executable. Be sure to include the executable in the path. Example /usr/bin/ffmpeg')); $rows[] = array(t('flashvideo_video_args'), t('Text'), t('The arguments given to the conversion utility executable to generate a video. The same format should be used as in the FlashVideo Settings.')); $rows[] = array(t('flashvideo_thumb_args'), t('Text'), t('The arguments given to the conversion utility executable to generate a thumbnail. The same format should be used as in the FlashVideo Settings.')); $rows[] = array(t('flashvideo_thumbsize'), t('Text'), t('The thumbnail size specified in the following format "WIDTH x HEIGHT". Example 130x100')); $rows[] = array(t('flashvideo_thumbwidth'), t('Integer'), t('The integer representation of the thumbnail width.')); $rows[] = array(t('flashvideo_thumbheight'), t('Integer'), t('The integer representation of the thumbnail height.')); $rows[] = array(t('flashvideo_thumbtime'), t('Text'), t('The amount of time to delay before taking a snapshot of the video. Should be in the format: 00:00:00 (hours:minutes:seconds)')); $rows[] = array(t('flashvideo_thumbsecs'), t('Integer'), t('The amount of time in seconds to delay before taking a snapshot of the video.')); $rows[] = array(t('flashvideo_thumbext'), t('Text'), t('The extension of the output thumbnail. Example: For JPG\'s this would be jpg')); $rows[] = array(t('flashvideo_videoext'), t('Text'), t('The extension of the output video. Example: For output FLV\'s, this would be flv')); $rows[] = array(t('flashvideo_videomime'), t('Text'), t('The mime type of the output video.')); $output .= theme('table', $header, $rows); $output .= '

After you have created these custom CCK fields for your content 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) { // We only want to do this on the pending files. if (($flags > 0)) { // We need to load the node to get the CCK variables. $node = node_load($file->nid); // Only if they don't already provide a FLASHVIDEO_USE_CUSTOM flag. if (flashvideo_cck_get_overloaded_params($node, $params)) { // Do we regenerate a thumbnail? $params['create_thumb'] = (($flags & FLASHVIDEO_REGEN_THUMB) == FLASHVIDEO_REGEN_THUMB); // Do we regenerate a video? $params['create_video'] = (($flags & FLASHVIDEO_REGEN_VIDEO) == FLASHVIDEO_REGEN_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; // New parameter to regenerate the thumbnail. $params['regen_thumb'] = 0; // New parameter to regenerate the video. $params['regen_video'] = 0; // Iterate through all of our parameters. foreach ($params as $param => $value) { // Get the overloaded variable name. $overload_name = FLASHVIDEO_PARAM_PREFIX . $param; // Is it set in our node and different from the default? if (isset($node->{$overload_name}) && ($node->{$overload_name}[0]['value'] != $value)) { // If so, then add it to our new parameters. $params[$param] = $node->{$overload_name}[0]['value']; $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 we decide to overide some paramters. if (flashvideo_cck_get_overloaded_params($node, $params)) { $flags = 0; if ($params['regen_video']) { // Set the regenerate video flag. $flags = $flags | FLASHVIDEO_REGEN_VIDEO; } if ($params['regen_thumb']) { // Set the regenerate thumbnail flag. $flags = $flags | FLASHVIDEO_REGEN_THUMB; } 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)) { // Delete the file from the disk. file_delete($file->filepath); // Delete the file from the flashvideo table. db_query("DELETE FROM {flashvideo} WHERE (fid = %d)", $file->fid); // Delete the file from the files 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 all unsuccessful conversions. db_query("DELETE FROM {ffmpeg_data} WHERE (fid = %d)", $file->fid); } // Allow other modules do do some delete operations. module_invoke_all('flashvideo_delete_file', $file, $node->type); // Update the flags for the original video. db_query("UPDATE {flashvideo} SET flags=%d WHERE nid=%d AND oid=fid", $flags, $node->nid); } } } /** * Implementation of 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, $form_state, $form_id) { // Is the form set. if (isset($form['type'])) { // Get the Node Type. $node_type = $form['type']['#value']; // Check for the Node Editor. if ($form_id == $node_type .'_node_form') { // Make sure the FlashVideo module is enabled for this node type. if (flashvideo_variable_get($node_type, 'enable', 0)) { // Get the Default Conversion parameters. $params = flashvideo_get_convert_params($node_type); // Iterate through all parameters. foreach ($params as $param => $value) { // Set the field name for each parameters. $field = FLASHVIDEO_PARAM_PREFIX . $param; // Is this form variable set. if (isset($form[$field])) { // Only set this if they haven't already provided a value. if (!$form[$field][0]['value']['#default_value']) { // If so, then overide the default value. $form[$field][0]['value']['#default_value'] = $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'; // Is this form variable set. if (isset($form[$field])) { // If so, then overide the default value. $form[$field][0]['value']['#default_value'] = 0; } $field = FLASHVIDEO_PARAM_PREFIX .'regen_video'; // Is this form variable set. if (isset($form[$field])) { // If so, then overide the default value. $form[$field][0]['value']['#default_value'] = 0; } } } } }