| 1 |
<?php |
<?php |
| 2 |
// $Id: transcription.module,v 1.7 2008/11/07 18:04:22 grndlvl Exp $ |
// $Id: transcription.module,v 1.8 2008/11/12 15:14:55 grndlvl Exp $ |
| 3 |
|
|
| 4 |
// Initial code by Jonathan DeLaigle (grndlvl). |
// Initial code by Jonathan DeLaigle (grndlvl). |
| 5 |
// Modified by Aaron Winborn for the Media Transcriptions module. |
// Modified by Aaron Winborn for the Media Transcriptions module. |
| 10 |
*/ |
*/ |
| 11 |
|
|
| 12 |
/** |
/** |
| 13 |
|
* Implementation of hook_menu(). |
| 14 |
|
*/ |
| 15 |
|
function transcription_menu($maycache) { |
| 16 |
|
$items = array(); |
| 17 |
|
if (!$maycache) { |
| 18 |
|
if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'transcription' && !is_null(arg(3))) { |
| 19 |
|
$node = node_load(arg(1)); |
| 20 |
|
if ($node->nid) { |
| 21 |
|
$items[] = array('path' => 'node/'. arg(1) .'/transcription/'. arg(3), 'title' => t('View'), |
| 22 |
|
'callback' => 'transcription_handler', |
| 23 |
|
'callback arguments' => array($node, arg(3)), |
| 24 |
|
'access' => node_access('view', $node), |
| 25 |
|
'type' => MENU_CALLBACK); |
| 26 |
|
} |
| 27 |
|
} |
| 28 |
|
} |
| 29 |
|
return $items; |
| 30 |
|
} |
| 31 |
|
|
| 32 |
|
/******************************************* |
| 33 |
|
* BEGIN Transcription handlers (TESTING) |
| 34 |
|
******************************************/ |
| 35 |
|
function transcription_handler($node, $type) { |
| 36 |
|
$fields = content_fields($field_name = NULL, $node->type); |
| 37 |
|
foreach ($fields as $field_name => $field_info) { |
| 38 |
|
if ($field_info['type'] == 'transcription') { |
| 39 |
|
$transcription_field = $node->$field_name; |
| 40 |
|
break; |
| 41 |
|
} |
| 42 |
|
} |
| 43 |
|
|
| 44 |
|
$handlers = module_invoke_all('transcription_type', $type, $transcription_field, $node); |
| 45 |
|
if (empty($handlers[$type])) { |
| 46 |
|
$default_handler = transcription_default_type($type, $transcription_field, $node); |
| 47 |
|
$output = $default_handler[$type]; |
| 48 |
|
} |
| 49 |
|
else { |
| 50 |
|
$output = $handlers[$type]; |
| 51 |
|
} |
| 52 |
|
|
| 53 |
|
print $output; |
| 54 |
|
exit; |
| 55 |
|
} |
| 56 |
|
|
| 57 |
|
function transcription_default_type($type, $transcriptions, $node) { |
| 58 |
|
switch ($type) { |
| 59 |
|
case 'jwplayer': |
| 60 |
|
require(drupal_get_path('module', 'transcription') .'/handler_types/default_jwplayer.inc'); |
| 61 |
|
return array('jwplayer' => $output); |
| 62 |
|
} |
| 63 |
|
} |
| 64 |
|
/******************************************* |
| 65 |
|
* END Transcription handlers (TESTING) |
| 66 |
|
******************************************/ |
| 67 |
|
|
| 68 |
|
/** |
| 69 |
* Implementation of hook_field_info(). |
* Implementation of hook_field_info(). |
| 70 |
*/ |
*/ |
| 71 |
function transcription_field_info() { |
function transcription_field_info() { |
| 123 |
$columns = array( |
$columns = array( |
| 124 |
'transcription' => array('type' => 'varchar', 'not null' => TRUE, 'default' => "''", 'sortable' => TRUE), |
'transcription' => array('type' => 'varchar', 'not null' => TRUE, 'default' => "''", 'sortable' => TRUE), |
| 125 |
'format' => array('type' => 'int', 'length' => 10, 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), |
'format' => array('type' => 'int', 'length' => 10, 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), |
| 126 |
'timemarker' => array('type' => 'int(5)', 'not null' => TRUE, 'default' => 0, 'sortable' => TRUE), |
'begin_timemarker' => array('type' => 'int(5)', 'not null' => TRUE, 'default' => 0, 'sortable' => TRUE), |
| 127 |
|
'end_timemarker' => array('type' => 'int(5)', 'not null' => TRUE, 'default' => 0, 'sortable' => TRUE), |
| 128 |
); |
); |
| 129 |
if ($field['max_length'] == 0 || $field['max_length'] > 255) { |
if ($field['max_length'] == 0 || $field['max_length'] > 255) { |
| 130 |
$columns['transcription']['type'] = 'longtext'; |
$columns['transcription']['type'] = 'longtext'; |
| 156 |
switch ($op) { |
switch ($op) { |
| 157 |
case 'validate': |
case 'validate': |
| 158 |
foreach ($items as $delta => $item) { |
foreach ($items as $delta => $item) { |
| 159 |
$error_field = $field['field_name'] .']['. $delta .'][timemarker'; |
$time_markers = array('begin', 'end'); |
| 160 |
if ($item['timemarker'] != '') { |
foreach ($time_markers as $time_marker) { |
| 161 |
$decimal = split('\.', $item['timemarker']); |
$error_field = $field['field_name'] .']['. $delta .']['. $time_marker .'_timemarker'; |
| 162 |
if (count($decimal) > 1) { |
if ($item[$time_marker .'_timemarker'] != '') { |
| 163 |
form_set_error($error_field, t('Transcription time markers must be represented in seconds as integer, HH:MM:SS, or MM:SS formats only.')); |
if ($item['transcription'] == '') { |
| 164 |
} |
form_set_error($field['field_name'] .']['. $delta .'][transcription', t('You cannot have a time marker without a transcription.')); |
| 165 |
if ($item['transcription'] == '') { |
} |
| 166 |
form_set_error($field['field_name'] .']['. $delta .'][transcription', t('You cannot have a time marker without a transcription.')); |
$decimal = split('\.', $item[$time_marker .'_timemarker']); |
| 167 |
} |
if (count($decimal) > 1) { |
| 168 |
$time_in_seconds = transcription_convert_to_seconds($item['timemarker']); |
form_set_error($error_field, t('Transcription time markers must be represented in seconds as integer, HH:MM:SS, or MM:SS formats only.')); |
| 169 |
if ($time_in_seconds != -1) { |
} |
| 170 |
$item['timemarker'] = $time_in_seconds; |
$time_in_seconds = transcription_convert_to_seconds($item[$time_marker .'_timemarker']); |
| 171 |
} |
if ($time_in_seconds != -1) { |
| 172 |
if (!is_numeric($item['timemarker'])) { |
$item[$time_marker .'_timemarker'] = $time_in_seconds; |
| 173 |
form_set_error($error_field, t('The value for the %transcription_time_marker must be a time.', array('%transcription_time_marker' => t('Transcription time marker')))); |
} |
| 174 |
} |
if (!is_numeric($item[$time_marker .'_timemarker'])) { |
| 175 |
if ($item['timemarker'] > 86400) { |
form_set_error($error_field, t('The value for the %transcription_time_marker must be a time.', array('%transcription_time_marker' => t('Transcription time marker')))); |
| 176 |
form_set_error($error_field, t('The value for the %transcription_time_marker must be less than 24:00:00/8640s.', array('%transcription_time_marker' => t('Transcription time marker')))); |
} |
| 177 |
|
if ($item[$time_marker .'_timemarker'] > 86400) { |
| 178 |
|
form_set_error($error_field, t('The value for the %transcription_time_marker must be less than 24:00:00/8640s.', array('%transcription_time_marker' => t('Transcription time marker')))); |
| 179 |
|
} |
| 180 |
} |
} |
| 181 |
} |
} |
| 182 |
} |
} |
| 183 |
break; |
break; |
| 184 |
case 'submit': |
case 'submit': |
| 185 |
foreach ($items as $delta => $item) { |
foreach ($items as $delta => $item) { |
| 186 |
if ($item['timemarker'] != '') { |
$time_markers = array('begin', 'end'); |
| 187 |
$time_in_seconds = transcription_convert_to_seconds($item['timemarker']); |
foreach ($time_markers as $time_marker) { |
| 188 |
if ($time_in_seconds != -1) { |
if ($item[$time_marker .'_timemarker'] != '') { |
| 189 |
$items[$delta]['timemarker'] = $time_in_seconds; |
$time_in_seconds = transcription_convert_to_seconds($item[$time_marker .'_timemarker']); |
| 190 |
|
if ($time_in_seconds != -1) { |
| 191 |
|
$items[$delta][$time_marker .'_timemarker'] = $time_in_seconds; |
| 192 |
|
} |
| 193 |
} |
} |
| 194 |
} |
} |
| 195 |
} |
} |
| 273 |
if ($field['text_processing']) { |
if ($field['text_processing']) { |
| 274 |
$form[$field['field_name']][$delta]['format'] = filter_form($data['format'], $form[$field['field_name']][$delta]['transcription']['#weight'] + 1, array($field['field_name'], $delta, 'format')); |
$form[$field['field_name']][$delta]['format'] = filter_form($data['format'], $form[$field['field_name']][$delta]['transcription']['#weight'] + 1, array($field['field_name'], $delta, 'format')); |
| 275 |
} |
} |
| 276 |
$form[$field['field_name']][$delta]['timemarker'] = array( |
$form[$field['field_name']][$delta]['begin_timemarker'] = array( |
| 277 |
|
'#type' => 'textfield', |
| 278 |
|
'#title' => t('Begin transcription time marker'), |
| 279 |
|
'#description' => (isset($field['transcription_timemarker_description'])) ? check_plain($field['transcription_timemarker_description']) : '', |
| 280 |
|
'#required' => ($delta == 0) ? $field['required'] : FALSE, |
| 281 |
|
'#size' => 8, |
| 282 |
|
'#maxlength' => 8, |
| 283 |
|
'#default_value' => $data['begin_timemarker'] |
| 284 |
|
); |
| 285 |
|
$form[$field['field_name']][$delta]['end_timemarker'] = array( |
| 286 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 287 |
'#title' => t('Transcription time marker'), |
'#title' => t('End transcription time marker'), |
| 288 |
'#description' => (isset($field['transcription_timemarker_description'])) ? check_plain($field['transcription_timemarker_description']) : '', |
'#description' => (isset($field['transcription_timemarker_description'])) ? check_plain($field['transcription_timemarker_description']) : '', |
| 289 |
'#required' => ($delta == 0) ? $field['required'] : FALSE, |
'#required' => ($delta == 0) ? $field['required'] : FALSE, |
| 290 |
'#size' => 8, |
'#size' => 8, |
| 291 |
'#maxlength' => 8, |
'#maxlength' => 8, |
| 292 |
'#default_value' => $data['timemarker'] |
'#default_value' => $data['end_timemarker'] |
| 293 |
); |
); |
| 294 |
$delta++; |
$delta++; |
| 295 |
} |
} |
| 314 |
if ($field['text_processing']) { |
if ($field['text_processing']) { |
| 315 |
$form[$field['field_name']][$delta]['format'] = filter_form($items[$delta]['format'], $form[$field['field_name']][$delta]['transcription']['#weight'] + 1, array($field['field_name'], $delta, 'format')); |
$form[$field['field_name']][$delta]['format'] = filter_form($items[$delta]['format'], $form[$field['field_name']][$delta]['transcription']['#weight'] + 1, array($field['field_name'], $delta, 'format')); |
| 316 |
} |
} |
| 317 |
$form[$field['field_name']][$delta]['timemarker'] = array( |
$form[$field['field_name']][$delta]['begin_timemarker'] = array( |
| 318 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 319 |
'#required' => ($delta == 0) ? $field['required'] : FALSE, |
'#required' => ($delta == 0) ? $field['required'] : FALSE, |
| 320 |
'#title' => t('Transcription time marker'), |
'#title' => t('Beginning ranscription time marker'), |
| 321 |
|
'#size' => 8, |
| 322 |
|
'#maxlength' => 8, |
| 323 |
|
'#description' => (isset($field['transcription_timemarker_description'])) ? check_plain($field['transcription_timemarker_description']) : '', |
| 324 |
|
); |
| 325 |
|
$form[$field['field_name']][$delta]['End_timemarker'] = array( |
| 326 |
|
'#type' => 'textfield', |
| 327 |
|
'#required' => ($delta == 0) ? $field['required'] : FALSE, |
| 328 |
|
'#title' => t('Ending transcription time marker'), |
| 329 |
'#size' => 8, |
'#size' => 8, |
| 330 |
'#maxlength' => 8, |
'#maxlength' => 8, |
| 331 |
'#description' => (isset($field['transcription_timemarker_description'])) ? check_plain($field['transcription_timemarker_description']) : '', |
'#description' => (isset($field['transcription_timemarker_description'])) ? check_plain($field['transcription_timemarker_description']) : '', |
| 344 |
if ($field['text_processing']) { |
if ($field['text_processing']) { |
| 345 |
$form[$field['field_name']][0]['format'] = filter_form($items[0]['format'], $form[$field['field_name']][0]['transcription']['#weight'] + 1, array($field['field_name'], 0, 'format')); |
$form[$field['field_name']][0]['format'] = filter_form($items[0]['format'], $form[$field['field_name']][0]['transcription']['#weight'] + 1, array($field['field_name'], 0, 'format')); |
| 346 |
} |
} |
| 347 |
$form[$field['field_name']][0]['timemarker'] = array( |
$form[$field['field_name']][0]['begin_timemarker'] = array( |
| 348 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 349 |
'#title' => t('Transcription time marker'), |
'#title' => t('Beginning transcription time marker'), |
| 350 |
'#size' => 8, |
'#size' => 8, |
| 351 |
'#maxlength' => 8, |
'#maxlength' => 8, |
| 352 |
'#description' => (isset($field['transcription_timemarker_description'])) ? check_plain($field['transcription_timemarker_description']) : '', |
'#description' => (isset($field['transcription_timemarker_description'])) ? check_plain($field['transcription_timemarker_description']) : '', |
| 353 |
'#default_value' => isset($items[0]['timemarker']) && $items[0]['timemarker'] != 0 ? $items[0]['timemarker'] : '', |
'#default_value' => isset($items[0]['begin_timemarker']) && $items[0]['begin_timemarker'] != 0 ? $items[0]['begin_timemarker'] : '', |
| 354 |
|
); |
| 355 |
|
$form[$field['field_name']][0]['end_timemarker'] = array( |
| 356 |
|
'#type' => 'textfield', |
| 357 |
|
'#title' => t('Ending transcription time marker'), |
| 358 |
|
'#size' => 8, |
| 359 |
|
'#maxlength' => 8, |
| 360 |
|
'#description' => (isset($field['transcription_timemarker_description'])) ? check_plain($field['transcription_timemarker_description']) : '', |
| 361 |
|
'#default_value' => isset($items[0]['end_timemarker']) && $items[0]['end_timemarker'] != 0 ? $items[0]['end_timemarker'] : '', |
| 362 |
); |
); |
| 363 |
} |
} |
| 364 |
return $form; |
return $form; |
| 370 |
if ($field['multiple']) { |
if ($field['multiple']) { |
| 371 |
if ($field['multiple']) { |
if ($field['multiple']) { |
| 372 |
foreach ($items as $delta => $item) { |
foreach ($items as $delta => $item) { |
| 373 |
if ($item['transcription'] == '' && $item['timemarker'] == '' && $delta > 0) { |
if ($item['transcription'] == '' && $item['begin_timemarker'] == '' && $delta > 0) { |
| 374 |
unset($items[$delta]); |
unset($items[$delta]); |
| 375 |
} |
} |
| 376 |
} |
} |
| 392 |
function theme_transcription($data) { |
function theme_transcription($data) { |
| 393 |
$output = ''; |
$output = ''; |
| 394 |
$output .= $data['transcription']; |
$output .= $data['transcription']; |
| 395 |
if ($data['timemarker'] != 0 && $data['timemarker'] != '') { |
if ($data['begin_timemarker'] != 0 && $data['begin_timemarker'] != '') { |
| 396 |
$output .= ' <span>'. theme('transcription_seconds_to_time', $data['timemarker']) .'</span>'; |
$output .= ' <span class="begin">'. theme('transcription_seconds_to_time', $data['begin_timemarker']) .'</span>'; |
| 397 |
|
} |
| 398 |
|
if ($data['end_timemarker'] != 0 && $data['end_timemarker'] != '') { |
| 399 |
|
$output .= ' <span class="end">'. theme('transcription_seconds_to_time', $data['end_timemarker']) .'</span>'; |
| 400 |
} |
} |
| 401 |
return '<p class="transcription">'. $output .'</p>'; |
return '<p class="transcription">'. $output .'</p>'; |
| 402 |
} |
} |