From 65e4e46dbbdd0b2e25977e0365ac215f8f6f399e Mon Sep 17 00:00:00 2001 From: Heshan Wanigasooriya Date: Sat, 8 Jan 2011 08:44:45 +0000 Subject: Updating module for drupal7 file system API --- plugins/video_zencoder/includes/zencoder.inc | 4 +- .../video_zencoder/transcoders/video_zencoder.inc | 4 +- plugins/video_zencoder/video_zencoder.module | 2 +- transcoders/video_ffmpeg.inc | 4 +- types/videoftp/videoftp_widget.inc | 70 +++++++++++----------- video.field.inc | 23 +++---- video.module | 50 ++++++++++------ 7 files changed, 80 insertions(+), 77 deletions(-) diff --git a/plugins/video_zencoder/includes/zencoder.inc b/plugins/video_zencoder/includes/zencoder.inc index 3b9f305..61023a0 100644 --- a/plugins/video_zencoder/includes/zencoder.inc +++ b/plugins/video_zencoder/includes/zencoder.inc @@ -55,7 +55,7 @@ class video_zencoder_api { // thumbnails // Setup our thmbnail path. $video_thumb_path = variable_get('video_thumb_path', 'video_thumbs'); - $final_thumb_path = file_directory_path() . '/' . $video_thumb_path . '/' . $file->fid; + $final_thumb_path = file_default_scheme() . ':/' . $video_thumb_path . '/' . $file->fid; // Notifications // if(!empty($notify_url)) @@ -240,7 +240,7 @@ class video_zencoder_api { } else { $errors = ''; foreach ($request->errors as $error) { - if($error == 'Email has already been taken'){ + if ($error == 'Email has already been taken') { drupal_set_message(t('Your account already exists on Zencoder. So !login to here and enter API key below', array('!login' => l(t('login'), 'https://app.zencoder.com/session/new')))); variable_set('video_zencoder_api_key', 'Please enter your API Key'); return TRUE; diff --git a/plugins/video_zencoder/transcoders/video_zencoder.inc b/plugins/video_zencoder/transcoders/video_zencoder.inc index db447ec..3a11c87 100644 --- a/plugins/video_zencoder/transcoders/video_zencoder.inc +++ b/plugins/video_zencoder/transcoders/video_zencoder.inc @@ -21,12 +21,12 @@ class video_zencoder implements transcoder_interface { global $user; // Setup our thmbnail path. $video_thumb_path = variable_get('video_thumb_path', 'video_thumbs'); - $final_thumb_path = file_directory_path() . '/' . $video_thumb_path . '/' . $video['fid']; + $final_thumb_path = file_default_scheme() . ':/' . $video_thumb_path . '/' . $video['fid']; // Ensure the destination directory exists and is writable. $directories = explode('/', $final_thumb_path); // Get the file system directory. - $file_system = file_directory_path(); + $file_system = file_default_scheme() . ':/'; foreach ($directories as $directory) { $full_path = isset($full_path) ? $full_path . '/' . $directory : $directory; // Don't check directories outside the file system path. diff --git a/plugins/video_zencoder/video_zencoder.module b/plugins/video_zencoder/video_zencoder.module index f8a779b..16e9ab1 100644 --- a/plugins/video_zencoder/video_zencoder.module +++ b/plugins/video_zencoder/video_zencoder.module @@ -90,7 +90,7 @@ function _video_zencoder_postback_jobs() { // this will update the default thumbnails, if user want to select another one then they wil need to edit the node // Setup our thmbnail path. $video_thumb_path = variable_get('video_thumb_path', 'video_thumbs'); - $final_thumb_path = file_directory_path() . '/' . $video_thumb_path . '/' . $fid; + $final_thumb_path = file_default_scheme() . ':/' . $video_thumb_path . '/' . $fid; // $i = rand(0, (variable_get('no_of_video_thumbs', 5) - 1)); $filename = $fid . '_' . sprintf("%04d", 1) . '.png'; $thumbfile = $final_thumb_path . '/' . $filename; diff --git a/transcoders/video_ffmpeg.inc b/transcoders/video_ffmpeg.inc index 04cdbff..601f0f6 100644 --- a/transcoders/video_ffmpeg.inc +++ b/transcoders/video_ffmpeg.inc @@ -53,12 +53,12 @@ class video_ffmpeg implements transcoder_interface { global $user; // Setup our thmbnail path. $video_thumb_path = variable_get('video_thumb_path', 'video_thumbs'); - $final_thumb_path = file_directory_path() . '/' . $video_thumb_path . '/' . $video['fid']; + $final_thumb_path = file_default_scheme() . ':/' . $video_thumb_path . '/' . $video['fid']; // Ensure the destination directory exists and is writable. $directories = explode('/', $final_thumb_path); // Get the file system directory. - $file_system = file_directory_path(); + $file_system = file_default_scheme() . ':/'; foreach ($directories as $directory) { $full_path = isset($full_path) ? $full_path . '/' . $directory : $directory; // Don't check directories outside the file system path. diff --git a/types/videoftp/videoftp_widget.inc b/types/videoftp/videoftp_widget.inc index d674660..cd5de67 100644 --- a/types/videoftp/videoftp_widget.inc +++ b/types/videoftp/videoftp_widget.inc @@ -1,4 +1,5 @@ 'fieldset', - '#title' => t('Path settings'), + '#title' => t('Path settings'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#weight' => 2, @@ -33,7 +34,7 @@ function videoftp_widget_settings_form($widget) { '#default_value' => ltrim(ltrim($widget['file_path'], "videos"), "/"), '#description' => t('Optional subdirectory within the "files/videos/" directory where files will be moved and stored. Do not include preceding or trailing slashes.'), '#element_validate' => array('video_widget_settings_file_path_validate', '_filefield_widget_settings_file_path_validate'), - ); + ); $form['path_settings']['ftp_path'] = array( '#type' => 'textfield', '#title' => t('FTP Filepath'), @@ -55,11 +56,11 @@ function videoftp_widget_settings_form($widget) { */ function videoftp_widget_settings_validate($widget) { // Check that only web images are specified in the callback. - if(!video_web_extensions($widget['file_extensions'])) { + if (!video_web_extensions($widget['file_extensions'])) { form_set_error('file_extensions', t('Only web-standard videos are supported through the videoftp widget. If needing to upload other types of files, change the widget to use a standard file upload.')); } // Check for our ftp filepath and try to create it, if not it will throw an error. - $ftp_path = file_directory_path().'/'.$widget['ftp_path']; + $ftp_path = file_default_scheme() . ':/' . $widget['ftp_path']; file_check_directory($ftp_path, true, 'ftp_path'); } @@ -67,7 +68,7 @@ function videoftp_widget_settings_validate($widget) { * Implementation of CCK's hook_widget_settings($op = 'save'). */ function videoftp_widget_settings_save($widget) { - return array('file_extensions', 'file_path', 'ftp_path', 'autothumbnail','autoconversion', 'default_dimensions', 'default_player_dimensions', 'default_video_thumb'); + return array('file_extensions', 'file_path', 'ftp_path', 'autothumbnail', 'autoconversion', 'default_dimensions', 'default_player_dimensions', 'default_video_thumb'); } /** @@ -78,8 +79,7 @@ function videoftp_widget_value($element, $edit = FALSE) { // Creating so we load up our empty values. $file = field_file_load($element['#default_value']['fid']); $item = $element['#default_value']; - } - else { + } else { // Reset our item array for our data. $item = array_merge($element['#default_value'], $edit); $field = content_fields($element['#field_name'], $element['#type_name']); @@ -127,7 +127,7 @@ function videoftp_widget_process($element, $edit, &$form_state, $form) { $delta = $element['#delta']; $field = content_fields($element['#field_name'], $element['#type_name']); $element['#theme'] = 'videoftp_widget_item'; - + if (isset($element['preview']) && $element['#value']['fid'] != 0) { $element['preview']['#value'] = theme('videoftp_widget_preview', $element['#value']); } @@ -142,11 +142,11 @@ function videoftp_widget_process($element, $edit, &$form_state, $form) { '#type' => 'submit', '#value' => t('Attach'), '#submit' => array('node_form_submit_build_node'), - '#ahah' => array( // with JavaScript - 'path' => 'videoftp/ahah/'. $element['#type_name'] .'/'. $element['#field_name'] .'/'. $element['#delta'], - 'wrapper' => $element['#id'] .'-ahah-wrapper', - 'method' => 'replace', - 'effect' => 'fade', + '#ahah' => array(// with JavaScript + 'path' => 'videoftp/ahah/' . $element['#type_name'] . '/' . $element['#field_name'] . '/' . $element['#delta'], + 'wrapper' => $element['#id'] . '-ahah-wrapper', + 'method' => 'replace', + 'effect' => 'fade', ), '#field_name' => $element['#field_name'], '#delta' => $element['#delta'], @@ -156,16 +156,16 @@ function videoftp_widget_process($element, $edit, &$form_state, $form) { '#post' => $element['#post'], ); $element['videoftp_remove'] = array( - // With default CCK edit forms, $element['#parents'] is array($element['#field_name'], $element['#delta']). - // However, if some module (for example, flexifield) places our widget deeper in the tree, we want to - // use that information in constructing the button name. - '#name' => implode('_', $element['#parents']) .'_videoftp_remove', + // With default CCK edit forms, $element['#parents'] is array($element['#field_name'], $element['#delta']). + // However, if some module (for example, flexifield) places our widget deeper in the tree, we want to + // use that information in constructing the button name. + '#name' => implode('_', $element['#parents']) . '_videoftp_remove', '#type' => 'submit', '#value' => t('Remove'), '#submit' => array('node_form_submit_build_node'), - '#ahah' => array( // with JavaScript - 'path' => 'videoftp/ahah/'. $element['#type_name'] .'/'. $element['#field_name'] .'/'. $element['#delta'], - 'wrapper' => $element['#id'] .'-ahah-wrapper', + '#ahah' => array(// with JavaScript + 'path' => 'videoftp/ahah/' . $element['#type_name'] . '/' . $element['#field_name'] . '/' . $element['#delta'], + 'wrapper' => $element['#id'] . '-ahah-wrapper', 'method' => 'replace', 'effect' => 'fade', ), @@ -195,7 +195,7 @@ function videoftp_widget_process($element, $edit, &$form_state, $form) { // Set access on the buttons and select. $element['videoftp_attach']['#access'] = empty($item['fid']); $element['videoftp_remove']['#access'] = !empty($item['fid']); - + $options = videoftp_options($field); $element['ftpselect'] = array( '#type' => 'select', @@ -225,12 +225,12 @@ function videoftp_widget_process($element, $edit, &$form_state, $form) { ); // Create our thumbnails - if($field['widget']['autothumbnail']) { + if ($field['widget']['autothumbnail']) { video_thumb_process($element); } - + // Add our extra fields if in preview mode - if(!empty($item['fid'])) { + if (!empty($item['fid'])) { video_widget_element_settings($element); } @@ -245,12 +245,12 @@ function videoftp_widget_process($element, $edit, &$form_state, $form) { // does not get the values in $form. $form_state['#field_info'][$field['field_name']] = $field; - $element['#attributes']['id'] = $element['#id'] .'-ahah-wrapper'; - $element['#prefix'] = '
'; + $element['#attributes']['id'] = $element['#id'] . '-ahah-wrapper'; + $element['#prefix'] = '
'; $element['#suffix'] = '
'; // Lets use the clicked_button #submit[0] value here instead and see how that works out for now... - if($form_state['submitted'] == 1) { + if ($form_state['submitted'] == 1) { video_widget_process($element, $form_state); } return $element; @@ -258,16 +258,16 @@ function videoftp_widget_process($element, $edit, &$form_state, $form) { function videoftp_save_upload($element) { global $user; - $upload_name = $element['#field_name'] .'_'. $element['#delta']; + $upload_name = $element['#field_name'] . '_' . $element['#delta']; $delta = $element['#delta']; $field = content_fields($element['#field_name'], $element['#type_name']); $video = $element['#post'][$field['field_name']][$delta]['ftpselect']; - $ftp_path = file_directory_path().'/'.$field['widget']['ftp_path']; + $ftp_path = file_default_scheme() . ':/' . $field['widget']['ftp_path']; - if (empty($video) || !file_exists($ftp_path.'/'.$video)) { + if (empty($video) || !file_exists($ftp_path . '/' . $video)) { return 0; } - + $dest = filefield_widget_file_path($field); if (!field_file_check_directory($dest, FILE_CREATE_DIRECTORY)) { watchdog('filefield', 'The upload directory %directory for the file field %field (content type %type) could not be created or is not accessible. A newly uploaded file could not be saved in this directory as a consequence, and the upload was canceled.', array('%directory' => $dest, '%field' => $element['#field_name'], '%type' => $element['#type_name'])); @@ -279,14 +279,14 @@ function videoftp_save_upload($element) { $file = new stdClass(); $file->uid = $user->uid; $file->filename = file_munge_filename(trim(basename($video), '.'), $field['widget']['file_extensions']); - $file->filepath = $ftp_path.'/'.$video; + $file->filepath = $ftp_path . '/' . $video; $file->filemime = file_get_mimetype($file->filename); $file->filesize = filesize($file->filepath); $file->status = FILE_STATUS_TEMPORARY; $file->timestamp = time(); //lets move our file from the ftp folder to the files directory - if(file_move($file, $dest)) { + if (file_move($file, $dest)) { // Insert new record to the database. drupal_write_record('files', $file); } @@ -298,9 +298,9 @@ function videoftp_options($field) { $options = array(); $options[] = t('Select Video'); // Lets setup our ftp_path. - $ftp_path = file_directory_path().'/'.$field['widget']['ftp_path']; + $ftp_path = file_default_scheme() . ':/' . $field['widget']['ftp_path']; // We are going to scan the directory and pull out the available video types by extension. - $extensions = explode(" ",$field['widget']['file_extensions']); + $extensions = explode(" ", $field['widget']['file_extensions']); $video_files = scandir($ftp_path); foreach ($video_files as $file) { $ext = pathinfo($file); diff --git a/video.field.inc b/video.field.inc index 55bac41..93696c5 100644 --- a/video.field.inc +++ b/video.field.inc @@ -23,8 +23,8 @@ function video_field_info() { 'file_extensions' => 'mp4 ogg avi mov wmv flv', 'file_directory' => '', 'max_filesize' => '', - 'max_resolution' => '', - 'min_resolution' => '', + 'default_dimensions' => '', + 'default_player_dimensions' => '', ), 'default_widget' => 'video_upload', 'default_formatter' => 'video', @@ -83,8 +83,6 @@ function video_field_prepare_view($entity_type, $entities, $field, $instances, $ if ($file = file_load($field['settings']['default_video_thumbnail'])) { $items[$id][0] = (array) $file + array( 'is_default' => TRUE, - 'alt' => '', - 'title' => '', ); } } @@ -240,14 +238,8 @@ function video_field_widget_process($element, &$form_state, $form) { $item = $element['#value']; $item['fid'] = $element['fid']['#value']; - $instance = field_widget_instance($element, $form_state); + $field = field_widget_field($element, $form_state); - $settings = $instance['settings']; - - $widget_settings = $instance['widget']['settings']; -// echo '
';
-//  print_r($instance);
-//  die();
   $element['#theme'] = 'theme_video_widget';
   $element['#attached']['css'][] = drupal_get_path('module', 'image') . '/video.css';
 
@@ -260,18 +252,17 @@ function video_field_widget_process($element, &$form_state, $form) {
   }
 
   // Title is not necessary for each individual field.
-  if ($settings['multiple'] > 0) {
+  if ($field['cardinality'] < 0) {
     unset($element['#title']);
   }
 
   // Create our thumbnails
-  if ($settings['widget']['autothumbnail']) {
-    video_thumb_process($element);
-  }
+  video_thumb_process($element, $form_state);
+
 
   // Add our extra fields if in preview mode
   if (!empty($item['fid'])) {
-    video_widget_element_settings($element);
+    video_widget_element_settings($element, $form_state);
   }
 
   // Lets use the clicked_button #submit[0] value here instead and see how that works out for now...
diff --git a/video.module b/video.module
index 89ded9a..2cc0cdf 100644
--- a/video.module
+++ b/video.module
@@ -259,16 +259,18 @@ function video_node_update_submit($form, &$form_state) {
  * Utility function that will add a preview of thumbnails for you to select when uploading videos.
  */
 
-function video_thumb_process(&$element) {
+function video_thumb_process(&$element, &$form_state) {
   // Developed for ffmpeg support
   $file = $element['#value'];
   $delta = $file['fid'];
-  $field = content_fields($element['#field_name'], $element['#type_name']);
+  $field = field_widget_field($element, $form_state);
+  $instance = field_widget_instance($element, $form_state);
+  $settings = $instance['widget']['settings'];
   $gen_fail = FALSE;
 
   if (isset($element['preview']) && $file['fid'] != 0) {
     $default_thumb = '';
-    if (in_array($field['widget']['autothumbnail'], array('auto', 'auto_fallback'))) {
+    if (in_array($field['settings']['autothumbnail'], array('auto', 'auto_fallback'))) {
 
       module_load_include('inc', 'video', '/includes/transcoder');
       $transcoder = new video_transcoder;
@@ -299,8 +301,8 @@ function video_thumb_process(&$element) {
       }
     }
 
-    if ((!empty($gen_fail) && $field['widget']['autothumbnail'] == 'auto_fallback') ||
-        $field['widget']['autothumbnail'] == 'manual_upload') {
+    if ((!empty($gen_fail) && $field['settings']['autothumbnail'] == 'auto_fallback') ||
+        $field['settings']['autothumbnail'] == 'manual_upload') {
 
       $element['data']['video_thumb_file'] = array(
         '#name' => 'files[' . $element['#field_name'] . '_' . $element['#delta'] . '_thumbs]',
@@ -320,8 +322,8 @@ function video_thumb_process(&$element) {
     // @todo Add smaller video preview instead of thumbnail?
     if (isset($file['data']['video_thumb']) && !empty($file['data']['video_thumb'])) {
       $large_thumb = array('filepath' => $file['data']['video_thumb']);
-    } elseif (!empty($field['widget']['default_video_thumb'])) {
-      $large_thumb = $field['widget']['default_video_thumb'];
+    } elseif (!empty($field['settings']['default_video_thumb'])) {
+      $large_thumb = $field['settings']['default_video_thumb'];
     } else {
       $large_thumb = array('filepath' => $default_thumb);
     }
@@ -406,7 +408,7 @@ function video_file_delete($file) {
 
   //now lets delete our video thumbnails and folder.
   $video_thumb_path = variable_get('video_thumb_path', 'video_thumbs');
-  $thumb_folder = file_directory_path() . '/' . $video_thumb_path . '/' . $file->fid;
+  $thumb_folder = file_default_scheme() . ':/' . $video_thumb_path . '/' . $file->fid;
   // Recursively delete our folder and files
   rmdirr($thumb_folder);
   // Let other modules to know about the file delete
@@ -448,21 +450,31 @@ function video_views_api() {
  * Process elements loads on settings
  * @param  $element
  */
-function video_widget_element_settings(&$element) {
+function video_widget_element_settings(&$element, &$form_state) {
   $file = $element['#value'];
   $delta = $element['#delta'];
-  $field = content_fields($element['#field_name'], $element['#type_name']);
+
+  $field = field_widget_field($element, $form_state);
+  $instance = field_widget_instance($element, $form_state);
+  $settings = $instance['widget']['settings'];
   // Check if using the default width and replace tokens.
   $default_dimensions = user_access('override player dimensions');
   $description = t('Set your video dimensions.  This will create your player with these dimensions.');
   //setup our default dimensions.
-  $dimensions = $field['widget']['default_dimensions'];
-  $player_dimensions = $field['widget']['default_player_dimensions'];
+  $dimensions = $settings['default_dimensions'];
+  $player_dimensions = $settings['default_player_dimensions'];
   // Lets figure out our dimensions for our video and add astericks next to our options.
   $options = video_explode("\n", variable_get("video_metadata_dimensions", video_default_dimensions()));
-  if ($field['widget']['autoconversion'] && isset($element['preview']) && $file['fid'] != 0 && $default_dimensions) {
+  if ($field['settings']['autoconversion'] && isset($element['preview']) && $file['fid'] != 0 && $default_dimensions) {
     $video_info = _video_dimensions_options($options, $file['filepath']);
-    $description = t('Set your video dimensions.  This will create your player and transcode your video with these dimensions.  Your video size is !size, if you choose a higher resolution, this could cause video distortion.  You are shown dimensions that match your aspect ratio, if you choose dimensions that do not match your ratio, we will pad your video by adding black bars on either the top or bottom while maintaining your videos original aspect ratio.', array('!size' => $video_info['width'] . 'x' . $video_info['height']));
+    $description = t('Set your video dimensions.  This will create your player
+      and transcode your video with these dimensions.  Your video size is !size,
+      if you choose a higher resolution, this could cause video distortion.
+      You are shown dimensions that match your aspect ratio,
+      if you choose dimensions that do not match your ratio, we will pad your
+      video by adding black bars on either the top or bottom while maintaining
+      your videos original aspect ratio.',
+            array('!size' => $video_info['width'] . 'x' . $video_info['height']));
     //setup our default display of dimensions.
     //lets go through our options looking for a matching resolution
     foreach ($options as $key => $value) {
@@ -505,7 +517,7 @@ function video_widget_element_settings(&$element) {
   }
 
   // only in preview mode and then create thumbnails
-  if ($field['widget']['autoconversion']) {
+  if ($field['settings']['autoconversion']) {
     if (user_access('bypass conversion video')) {
       $element['data']['bypass_autoconversion'] = array(
         '#type' => 'checkbox',
@@ -564,11 +576,11 @@ function video_widget_element_settings(&$element) {
  */
 function video_widget_process(&$element, &$form_state) {
   $item = $element['#value'];
-  $field = content_fields($element['#field_name'], $element['#type_name']);
+  $field = field_widget_field($element, $form_state);
   switch ($form_state['clicked_button']['#submit'][0]) {
     case 'node_form_submit':
       // Auto convert our video file
-      if ($field['widget']['autoconversion']) {
+      if ($field['settings']['autoconversion']) {
         video_convert_process($element);
         //lets set our node status to unpublished if our video is not converted.
         if (isset($element['#unpublish']) && $element['#unpublish']) {
@@ -604,7 +616,7 @@ function video_widget_process(&$element, &$form_state) {
  */
 function video_upload_manual_thumb(&$element) {
 
-  $destination = file_directory_path() . '/video_thumbs/' . $element['#value']['fid'];
+  $destination = file_default_scheme() . ':/' . 'video_thumbs/' . $element['#value']['fid'];
   if (!field_file_check_directory($destination, FILE_CREATE_DIRECTORY)) {
     form_set_error('video_thumb_upload', t('The thumbnail image could not be uploaded. The destination %destination does not exist or is not writable by the server.', array('%destination' => dirname($destination))));
     return;
@@ -837,7 +849,7 @@ function video_default_field_settings($settings) {
 function video_default_widget_settings_validate($element, &$form_state) {
   return;
   // Verify the destination exists
-  $destination = file_directory_path() . '/video_thumbs';
+  $destination = file_default_scheme() . ':/' . 'video_thumbs';
   if (!field_file_check_directory($destination, FILE_CREATE_DIRECTORY)) {
     form_set_error('default_video_thumb', t('The default image could not be uploaded. The destination %destination does not exist or is not writable by the server.', array('%destination' => dirname($destination))));
     return;
-- 
cgit v1.2.3