| 1 |
<?php |
<?php |
| 2 |
// $Id: audio.module,v 1.117 2007/07/30 19:12:50 drewish Exp $ |
// $Id: audio.module,v 1.118 2007/07/30 19:45:38 drewish Exp $ |
| 3 |
|
|
| 4 |
include(drupal_get_path('module', 'audio') .'/audio_theme.inc'); |
include(drupal_get_path('module', 'audio') .'/audio_theme.inc'); |
| 5 |
if (module_exists('views')) { |
if (module_exists('views')) { |
| 392 |
form_set_error('audio_upload', t("A file must be provided. If you tried uploading a file, make sure it's less than the upload size limit.")); |
form_set_error('audio_upload', t("A file must be provided. If you tried uploading a file, make sure it's less than the upload size limit.")); |
| 393 |
} |
} |
| 394 |
|
|
| 395 |
// Build the title from metadata. |
// Build the title from metadata. If there's not title format use the default. |
| 396 |
form_set_value($form['title'], audio_build_title($node)); |
if (!isset($node->title_format)) { |
| 397 |
|
$node->title_format = variable_get('audio_default_title_format', '[audio-tag-title] by [audio-tag-artist]'); |
| 398 |
|
} |
| 399 |
|
form_set_value($form['title'], token_replace($node->title_format, 'node', $node)); |
| 400 |
} |
} |
| 401 |
|
|
| 402 |
/** |
/** |
| 642 |
$type = node_get_types('type', $node); |
$type = node_get_types('type', $node); |
| 643 |
|
|
| 644 |
if ($type->has_title) { |
if ($type->has_title) { |
| 645 |
$form['title_format'] = array( |
$form['title']['#weight'] = -5; |
| 646 |
|
$form['title']['title_format'] = array( |
| 647 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 648 |
'#title' => check_plain($type->title_label), |
'#title' => check_plain($type->title_label), |
| 649 |
'#default_value' => isset($node->title_format) ? $node->title_format : variable_get('audio_default_title_format', '!title by !artist'), |
'#default_value' => isset($node->title_format) ? $node->title_format : variable_get('audio_default_title_format', '[audio-tag-title] by [audio-tag-artist]'), |
| 650 |
'#description' => t("The title can use the file's metadata. Depending on what's filled out, you maybe able to use any of the following variables: " ) .'!filename !'. implode(' !', audio_get_tags_allowed()), |
'#description' => t("The title can use the file's metadata. You can use the tokens listed below to insert information into the title."), |
| 651 |
'#required' => TRUE, |
'#required' => TRUE, |
| 652 |
'#weight' => -5, |
|
| 653 |
|
); |
| 654 |
|
$form['title']['token_help'] = array( |
| 655 |
|
'#title' => t('Token list'), |
| 656 |
|
'#type' => 'fieldset', |
| 657 |
|
'#collapsible' => TRUE, |
| 658 |
|
'#collapsed' => TRUE, |
| 659 |
|
'#description' => t('This is a list of the tokens that can be used in the title of audio nodes.'), |
| 660 |
|
'help' => array('#value' => theme('token_help', 'node')), |
| 661 |
); |
); |
| 662 |
} |
} |
| 663 |
|
|
| 847 |
} |
} |
| 848 |
|
|
| 849 |
/** |
/** |
|
* Build a title for the node. |
|
|
* |
|
|
* @param $node |
|
|
* Node object with title_format and audio_tags values. |
|
|
* @return |
|
|
* String with node's title. |
|
|
*/ |
|
|
function audio_build_title($node) { |
|
|
// If there's not title format use the default. |
|
|
if (!isset($node->title_format)) { |
|
|
$node->title_format = variable_get('audio_default_title_format', '!title by !artist'); |
|
|
} |
|
|
|
|
|
// Build a list of parameters. |
|
|
$params = array( |
|
|
'!filename' => $node->audio_file->filename, |
|
|
); |
|
|
foreach (audio_get_tags_allowed() as $tag) { |
|
|
$params['!'. $tag] = isset($node->audio_tags[$tag]) ? $node->audio_tags[$tag] : ''; |
|
|
} |
|
|
|
|
|
return t($node->title_format, $params); |
|
|
} |
|
|
|
|
|
/** |
|
| 850 |
* Implementation of hook_user(). |
* Implementation of hook_user(). |
| 851 |
*/ |
*/ |
| 852 |
function audio_user($op, &$edit, &$user, $category = NULL) { |
function audio_user($op, &$edit, &$user, $category = NULL) { |
| 904 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 905 |
'#title' => t('Default node title format'), |
'#title' => t('Default node title format'), |
| 906 |
'#maxlength' => 128, |
'#maxlength' => 128, |
| 907 |
'#default_value' => variable_get('audio_default_title_format', '!artist - !title'), |
'#default_value' => variable_get('audio_default_title_format', '[audio-tag-artist] - [audio-tag-title]'), |
| 908 |
'#description' => t("The audio node's title can use the file's metadata as variables. This will be used as the default title for all new audio nodes. The following values can be used: ") .'!filename !'. implode(' !', audio_get_tags_allowed()), |
'#description' => t("The audio node's title can use the file's metadata as variables. This will be used as the default title for all new audio nodes. By using the tokens listed below, you can automatically create titles from things like a song's artist or title."), |
| 909 |
); |
); |
| 910 |
$form['audio_teaser_format'] = array( |
$form['audio_teaser_format'] = array( |
| 911 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 912 |
'#title' => t('Node teaser format'), |
'#title' => t('Node teaser format'), |
| 913 |
'#maxlength' => 128, |
'#maxlength' => 128, |
| 914 |
'#default_value' => variable_get('audio_teaser_format', '!player<br />!filelength'), |
'#default_value' => variable_get('audio_teaser_format', '[audio-player]<br />[audio-file-length]'), |
| 915 |
'#description' => t("Specify a teaser format for all audio nodes. In addition to the tags allowed in the title, the following variables are also available: "). '!filelength !fileformat !player', |
'#description' => t("Use this setting to customize the teasers for audio nodes. Using the tokens listed below you can select what information about the file will be displayed."), |
| 916 |
|
); |
| 917 |
|
$form['token_help'] = array( |
| 918 |
|
'#title' => t('List of available tokens'), |
| 919 |
|
'#type' => 'fieldset', |
| 920 |
|
'#collapsible' => TRUE, |
| 921 |
|
'#collapsed' => TRUE, |
| 922 |
|
'#description' => t('This is a list of the tokens that can be used in the titles and teasers of audio nodes.'), |
| 923 |
|
'help' => array('#value' => theme('token_help', 'node')), |
| 924 |
); |
); |
| 925 |
$form['audio_allowed_extensions'] = array( |
$form['audio_allowed_extensions'] = array( |
| 926 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 1622 |
} |
} |
| 1623 |
|
|
| 1624 |
// ...then save it. |
// ...then save it. |
|
$node->title = audio_build_title($node); |
|
| 1625 |
$node = node_submit($node); |
$node = node_submit($node); |
| 1626 |
node_save($node); |
node_save($node); |
| 1627 |
|
|
| 1686 |
// Tags. |
// Tags. |
| 1687 |
foreach (audio_get_tags_allowed() as $tag) { |
foreach (audio_get_tags_allowed() as $tag) { |
| 1688 |
if (isset($node->audio_tags[$tag])) { |
if (isset($node->audio_tags[$tag])) { |
| 1689 |
$tokens['audio-tag-'. $tag] = $node->audio_tags[$tag]; |
$tokens['audio-tag-'. strtr($tag, '_', '-')] = $node->audio_tags[$tag]; |
| 1690 |
} |
} |
| 1691 |
} |
} |
| 1692 |
// File info. |
|
| 1693 |
|
// Formatted file info. |
| 1694 |
|
$tokens['audio-file-length'] = theme('audio_format_filelength', $node->audio_fileinfo); |
| 1695 |
|
$tokens['audio-file-format'] = theme('audio_format_fileformat', $node->audio_fileinfo); |
| 1696 |
|
|
| 1697 |
|
// Raw file info. |
| 1698 |
$keys = array('sample_rate', 'channel_mode', 'bitrate', 'bitrate_mode', 'playtime'); |
$keys = array('sample_rate', 'channel_mode', 'bitrate', 'bitrate_mode', 'playtime'); |
| 1699 |
foreach ($keys as $key) { |
foreach ($keys as $key) { |
| 1700 |
if (isset($node->audio_fileinfo[$key])) { |
if (isset($node->audio_fileinfo[$key])) { |
| 1710 |
|
|
| 1711 |
// Play and download links. |
// Play and download links. |
| 1712 |
if (isset($node->url_play)) { |
if (isset($node->url_play)) { |
| 1713 |
|
$tokens['audio-player'] = audio_get_node_player($node); |
| 1714 |
$tokens['audio-url-play'] = $node->url_play; |
$tokens['audio-url-play'] = $node->url_play; |
| 1715 |
} |
} |
| 1716 |
if (isset($node->url_download)) { |
if (isset($node->url_download)) { |
| 1717 |
$tokens['audio-url-download'] = $node->url_download; |
$tokens['audio-url-download'] = $node->url_download; |
| 1718 |
} |
} |
| 1719 |
|
|
| 1720 |
return $tokens; |
return $tokens; |
| 1721 |
} |
} |
| 1722 |
} |
} |
| 1725 |
* Implementation of the token.module's hook_token_values(). |
* Implementation of the token.module's hook_token_values(). |
| 1726 |
* |
* |
| 1727 |
* @param $type |
* @param $type |
| 1728 |
* Tndicates the context that token help is being generated for. Unlike |
* Indicates the context that token help is being generated for. Unlike |
| 1729 |
* hook_token_values however, you should show ALL tokens at the same time if |
* hook_token_values however, you should show ALL tokens at the same time if |
| 1730 |
* $type is 'all'. |
* $type is 'all'. |
| 1731 |
* @return |
* @return |
| 1732 |
* Array of token information. |
* Array of token information. |
| 1735 |
if ($type == 'node' || $type == 'all') { |
if ($type == 'node' || $type == 'all') { |
| 1736 |
// Tags. |
// Tags. |
| 1737 |
foreach (audio_get_tags_allowed() as $tag) { |
foreach (audio_get_tags_allowed() as $tag) { |
| 1738 |
$tokens['node']['audio-tag-'. $tag] = t("Audio node @tag tag value.", array('@tag' => $tag)); |
$tokens['node']['audio-tag-'. strtr($tag, '_', '-')] = t("Audio node @tag tag value.", array('@tag' => $tag)); |
| 1739 |
} |
} |
| 1740 |
|
|
| 1741 |
// File info. |
// Formatted file info. |
| 1742 |
|
$tokens['node']['audio-file-length'] = t("Audio node formatted file length information."); |
| 1743 |
|
$tokens['node']['audio-file-format'] = t("Audio node formatted file format information."); |
| 1744 |
|
|
| 1745 |
|
// Raw file info. |
| 1746 |
$tokens['node']['audio-sample-rate'] = t("Audio node sample rate, integer i.e. 44100."); |
$tokens['node']['audio-sample-rate'] = t("Audio node sample rate, integer i.e. 44100."); |
| 1747 |
$tokens['node']['audio-channel-mode'] = t("Audio node channels, i.e. mono, stereo."); |
$tokens['node']['audio-channel-mode'] = t("Audio node channels, i.e. mono, stereo."); |
| 1748 |
$tokens['node']['audio-bitrate'] = t("Audio node bitrate, integer i.e. 19200."); |
$tokens['node']['audio-bitrate'] = t("Audio node bitrate, integer i.e. 19200."); |
| 1754 |
$tokens['node']['audio-filesize'] = t("Audio node file size, in bytes."); |
$tokens['node']['audio-filesize'] = t("Audio node file size, in bytes."); |
| 1755 |
|
|
| 1756 |
// Play and download links. |
// Play and download links. |
| 1757 |
|
$tokens['node']['audio-player'] = t("Audio node player."); |
| 1758 |
$tokens['node']['audio-url-play'] = t("Audio node play URL."); |
$tokens['node']['audio-url-play'] = t("Audio node play URL."); |
| 1759 |
$tokens['node']['audio-url-download'] = t("Audio node download URL."); |
$tokens['node']['audio-url-download'] = t("Audio node download URL."); |
| 1760 |
return $tokens; |
return $tokens; |