| 2 |
|
|
| 3 |
// $Id: audio_import.module,v 1.6 2007/08/06 03:00:58 drewish Exp $ |
// $Id: audio_import.module,v 1.6 2007/08/06 03:00:58 drewish Exp $ |
| 4 |
|
|
| 5 |
function audio_import_help($section = '') { |
function audio_import_help($section, $arg) { |
| 6 |
switch ($section) { |
switch ($section) { |
| 7 |
case 'admin/content/audio_import': |
case 'admin/content/audio_import': |
| 8 |
$output = '<p>'. t("Import multiple audio files and save them as audio nodes. The files will be moved from their location into the audio module's files directory. ") |
return '<p>'. t("Import multiple audio files and save them as audio nodes. The files will be moved from their location into the audio module's files directory. ") |
| 9 |
. t("Searching for files ending with %extensions in %dirpath directory.", array('%dirpath' => realpath(variable_get('audio_import_path', '')), '%extensions' => variable_get('audio_allowed_extensions', 'mp3 wav ogg'))) .'</p>'; |
. t("Searching for files ending with %extensions in %dirpath directory.", array('%dirpath' => realpath(variable_get('audio_import_path', '')), '%extensions' => variable_get('audio_allowed_extensions', 'mp3 wav ogg'))) .'</p>'; |
| 10 |
return $output; |
case 'admin/help#audio': |
| 11 |
case 'admin/help#audio_import': |
return '<p>'. t("The audio_import module allows users with 'administer audio' permission to import audio files and create audio nodes from them. ") .'</p>'; |
|
$output = '<p>'. t("The audio_import module allows users with 'administer audio' permission to import audio files and create audio nodes from them. ") .'</p>'; |
|
|
return $output; |
|
| 12 |
case 'admin/settings/audio_import': |
case 'admin/settings/audio_import': |
| 13 |
return t("Configure the audio import module's settings."); |
return t("Configure the audio import module's settings."); |
|
default: |
|
|
return null; |
|
| 14 |
} |
} |
| 15 |
} |
} |
| 16 |
|
|
| 17 |
function audio_import_menu($may_cache) { |
function audio_import_menu() { |
| 18 |
$items = array(); |
$items = array(); |
| 19 |
if ($may_cache) { |
|
| 20 |
$items[] = array( |
$items['admin/content/audio_import'] = array( |
| 21 |
'path' => 'admin/content/audio_import', |
'title' => 'Audio import', |
| 22 |
'title' => t('Audio import'), |
'description' => 'Import audio from the filesystem.', |
| 23 |
'callback' => 'drupal_get_form', |
'page callback' => 'drupal_get_form', |
| 24 |
'callback arguments' => array('audio_import_form'), |
'page arguments' => array('audio_import_form'), |
| 25 |
'access' => user_access('administer audio'), |
'access arguments' => array('administer audio'), |
| 26 |
'type' => MENU_NORMAL_ITEM, |
'type' => MENU_NORMAL_ITEM, |
| 27 |
'description' => t('Import audio from the filesystem.') |
); |
| 28 |
); |
$items['admin/settings/audio_import'] = array( |
| 29 |
$items[] = array( |
'title' => 'Audio import settings', |
| 30 |
'path' => 'admin/settings/audio_import', |
'description' => 'Change settings for the Audio Import module.', |
| 31 |
'title' => t('Audio import settings'), |
'page callback' => 'drupal_get_form', |
| 32 |
'callback' => 'drupal_get_form', |
'page arguments' => array('audio_import_admin_settings'), |
| 33 |
'callback arguments' => array('audio_import_admin_settings'), |
'access arguments' => array('administer site configuration'), |
| 34 |
'access' => user_access('administer site configuration'), |
'type' => MENU_NORMAL_ITEM, |
| 35 |
'type' => MENU_NORMAL_ITEM, |
); |
|
'description' => t('Change settings for the Audio Import module.') |
|
|
); |
|
|
} |
|
| 36 |
|
|
| 37 |
return $items; |
return $items; |
| 38 |
} |
} |
| 48 |
// convert the extensions setting into a regex for file scanning |
// convert the extensions setting into a regex for file scanning |
| 49 |
$extensions = variable_get('audio_allowed_extensions', 'mp3 wav ogg'); |
$extensions = variable_get('audio_allowed_extensions', 'mp3 wav ogg'); |
| 50 |
$extensions = preg_split('/[\s,]+/', $extensions, -1, PREG_SPLIT_NO_EMPTY); |
$extensions = preg_split('/[\s,]+/', $extensions, -1, PREG_SPLIT_NO_EMPTY); |
| 51 |
$filemask = '.*(\.'. implode('|\.', $extensions).')$'; |
$filemask = '.*(\.'. implode('|\.', $extensions) .')$'; |
| 52 |
|
|
| 53 |
$options = array(); |
$options = array(); |
| 54 |
$files = file_scan_directory($dirpath, $filemask); |
$files = file_scan_directory($dirpath, $filemask); |
| 85 |
return $form; |
return $form; |
| 86 |
} |
} |
| 87 |
|
|
| 88 |
|
/** |
| 89 |
|
* Implementation of hook_theme |
| 90 |
|
*/ |
| 91 |
|
function audio_import_theme() { |
| 92 |
|
return array( |
| 93 |
|
'audio_import_form' => array( |
| 94 |
|
'arguments' => array('form'), |
| 95 |
|
), |
| 96 |
|
); |
| 97 |
|
} |
| 98 |
|
|
| 99 |
function theme_audio_import_form($form) { |
function theme_audio_import_form($form) { |
| 100 |
$output = ''; |
$output = ''; |
| 101 |
if (isset($form['audio_import_files']) && $form['audio_import_files']['#type'] == 'checkboxes') { |
if (isset($form['audio_import_files']) && $form['audio_import_files']['#type'] == 'checkboxes') { |
| 114 |
return $output . drupal_render($form); |
return $output . drupal_render($form); |
| 115 |
} |
} |
| 116 |
|
|
| 117 |
function audio_import_form_submit($form_id, $form_values) { |
function audio_import_form_submit($form, &$form_state) { |
| 118 |
$op = isset($form_values['op']) ? $form_values['op'] : ''; |
$op = isset($form_state['values']['op']) ? $form_state['values']['op'] : ''; |
| 119 |
if ($op == t('Import')) { |
if ($op == t('Import')) { |
| 120 |
$dirpath = variable_get('audio_import_path', ''); |
$dirpath = variable_get('audio_import_path', ''); |
| 121 |
if (file_check_directory($dirpath)) { |
if (file_check_directory($dirpath)) { |
| 122 |
$nodes = array(); |
$nodes = array(); |
| 123 |
$files = array(); |
$files = array(); |
| 124 |
foreach (array_filter($form_values['audio_import_files']) as $index) { |
foreach (array_filter($form_state['values']['audio_import_files']) as $index) { |
| 125 |
// try to avoid php's script timeout with a bunch of large files or |
// try to avoid php's script timeout with a bunch of large files or |
| 126 |
// a slow machine |
// a slow machine |
| 127 |
set_time_limit(0); |
set_time_limit(0); |
| 128 |
|
|
| 129 |
$origname = $form_values['file_list'][$index]; |
$origname = $form_state['values']['file_list'][$index]; |
| 130 |
$filename = file_check_location($dirpath .'/'. $origname, $dirpath); |
$filename = file_check_location($dirpath .'/'. $origname, $dirpath); |
| 131 |
if ($filename) { |
if ($filename) { |
| 132 |
$node = audio_api_insert($filename); |
$node = audio_api_insert($filename); |
| 159 |
$form['audio_import_path'] = array( |
$form['audio_import_path'] = array( |
| 160 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 161 |
'#title' => t('Import path'), |
'#title' => t('Import path'), |
| 162 |
'#default_value' => variable_get('audio_import_path', file_directory_temp() . '/audio/'), |
'#default_value' => variable_get('audio_import_path', file_directory_temp() .'/audio/'), |
| 163 |
'#after_build' => array('_audio_import_settings_check_directory'), |
'#after_build' => array('_audio_import_settings_check_directory'), |
| 164 |
'#description' => t("The directory to import audio nodes from. Drupal will need to have write access to this directory so we can move the file.") .'<br />' |
'#description' => t("The directory to import audio nodes from. Drupal will need to have write access to this directory so we can move the file.") .'<br />' |
| 165 |
. t("<strong>Note:</strong> a path begining with a <kbd>/</kbd> indicates the path is relative to the server's root, one starting without specifies a path relative to Drupal's root. I.e. <kbd>/tmp/audio</kbd> would be the temp directory off the root while <kbd>tmp/audio</kbd> would be inside Drupal's directory."), |
. t("<strong>Note:</strong> a path begining with a <kbd>/</kbd> indicates the path is relative to the server's root, one starting without specifies a path relative to Drupal's root. I.e. <kbd>/tmp/audio</kbd> would be the temp directory off the root while <kbd>tmp/audio</kbd> would be inside Drupal's directory."), |
| 176 |
* @see system_check_directory() |
* @see system_check_directory() |
| 177 |
*/ |
*/ |
| 178 |
function _audio_import_settings_check_directory($form_element) { |
function _audio_import_settings_check_directory($form_element) { |
| 179 |
$importDir = $form_element['#value']; |
$import_dir = $form_element['#value']; |
| 180 |
file_check_directory($importDir, 0, $form_element['#parents'][0]); |
file_check_directory($import_dir, 0, $form_element['#parents'][0]); |
| 181 |
$audioDir = variable_get('audio_file_path', file_directory_path() .'/audio'); |
$audio_dir = variable_get('audio_file_path', file_directory_path() .'/audio'); |
| 182 |
if (realpath($importDir) == realpath($audioDir)) { |
if (realpath($import_dir) == realpath($audio_dir)) { |
| 183 |
form_set_error($form_element['#parents'][0], t("You can't import from the audio module's directory. The import deletes the original files so you would just be asking for trouble.")); |
form_set_error($form_element['#parents'][0], t("You can't import from the audio module's directory. The import deletes the original files so you would just be asking for trouble.")); |
| 184 |
} |
} |
| 185 |
return $form_element; |
return $form_element; |