| 1 |
<?php
|
| 2 |
// $Id: itunes.admin.inc,v 1.6 2009/07/31 22:45:06 drewish Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Admin settings for iTunes.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Settings form.
|
| 11 |
*/
|
| 12 |
function itunes_admin_settings() {
|
| 13 |
$node_types = node_get_types();
|
| 14 |
$content_module_exists = module_exists('content');
|
| 15 |
$content_types = $content_module_exists ? content_types() : array();
|
| 16 |
|
| 17 |
// Build a list of node types that iTunes could operate on.
|
| 18 |
$options = array();
|
| 19 |
foreach ($node_types as $type) {
|
| 20 |
$options[$type->type] = $type->name;
|
| 21 |
}
|
| 22 |
$form['itunes_types'] = array(
|
| 23 |
'#title' => t('Enable iTunes fields'),
|
| 24 |
'#type' => 'checkboxes',
|
| 25 |
'#options' => $options,
|
| 26 |
'#default_value' => variable_get('itunes_types', array('audio')),
|
| 27 |
);
|
| 28 |
|
| 29 |
// If FileField is enabled allow selection of the enclosure's source.
|
| 30 |
if ($content_module_exists && module_exists('filefield')) {
|
| 31 |
$fields = variable_get('itunes_enclosure_source', array());
|
| 32 |
$form['itunes_enclosure_source'] = array(
|
| 33 |
'#tree' => TRUE,
|
| 34 |
);
|
| 35 |
// Build the node's filefield selector.
|
| 36 |
foreach ($node_types as $type) {
|
| 37 |
$content = $content_types[$type->type];
|
| 38 |
$options = array(NULL => t('- None -'));
|
| 39 |
foreach ($content['fields'] as $field_name => $field) {
|
| 40 |
if ($field['type'] == 'filefield') {
|
| 41 |
$options[$field_name] = $field['widget']['label'];
|
| 42 |
}
|
| 43 |
}
|
| 44 |
$form['itunes_enclosure_source'][$type->type] = array(
|
| 45 |
'#type' => 'select',
|
| 46 |
'#options' => $options,
|
| 47 |
'#default_value' => empty($fields[$type->type]) ? NULL : $fields[$type->type],
|
| 48 |
'#access' => count($options) > 1,
|
| 49 |
);
|
| 50 |
}
|
| 51 |
}
|
| 52 |
|
| 53 |
// If taxonomy is enabled allow selection of the tags' source.
|
| 54 |
if (module_exists('taxonomy')) {
|
| 55 |
$vocabs = variable_get('itunes_keyword_source', array());
|
| 56 |
$form['itunes_keyword_source'] = array(
|
| 57 |
'#tree' => TRUE,
|
| 58 |
);
|
| 59 |
foreach ($node_types as $type) {
|
| 60 |
$type_vocabs = taxonomy_get_vocabularies($type->type);
|
| 61 |
$options = array(NULL => t('- None -'));
|
| 62 |
foreach ($type_vocabs as $vid => $vocab) {
|
| 63 |
$options[$vid] = $vocab->name;
|
| 64 |
}
|
| 65 |
$form['itunes_keyword_source'][$type->type] = array(
|
| 66 |
'#type' => 'select',
|
| 67 |
'#options' => $options,
|
| 68 |
'#default_value' => empty($vocabs[$type->type]) ? NULL : $vocabs[$type->type],
|
| 69 |
'#access' => count($options) > 1,
|
| 70 |
);
|
| 71 |
}
|
| 72 |
}
|
| 73 |
|
| 74 |
// Allow selection of the author's source.
|
| 75 |
$author_source = variable_get('itunes_author_source', array());
|
| 76 |
$form['itunes_author_source'] = array(
|
| 77 |
'#tree' => TRUE,
|
| 78 |
);
|
| 79 |
foreach ($node_types as $type) {
|
| 80 |
$options = array(
|
| 81 |
NULL => t('- None -'),
|
| 82 |
'node_author' => t('Node author'),
|
| 83 |
);
|
| 84 |
if ($content_module_exists) {
|
| 85 |
$content = $content_types[$type->type];
|
| 86 |
foreach ($content['fields'] as $field_name => $field) {
|
| 87 |
if ($field['type'] == 'text' && $field['widget']['type'] == 'text_textfield') {
|
| 88 |
$options[$field_name] = $field['widget']['label'];
|
| 89 |
}
|
| 90 |
elseif ($field['type'] == 'userreference') {
|
| 91 |
$options[$field_name] = $field['widget']['label'];
|
| 92 |
}
|
| 93 |
}
|
| 94 |
}
|
| 95 |
$form['itunes_author_source'][$type->type] = array(
|
| 96 |
'#type' => 'select',
|
| 97 |
'#options' => $options,
|
| 98 |
'#default_value' => empty($author_source[$type->type]) ? NULL : $author_source[$type->type],
|
| 99 |
);
|
| 100 |
}
|
| 101 |
|
| 102 |
$form = system_settings_form($form);
|
| 103 |
$form['#validate'][] = 'itunes_admin_settings_validate';
|
| 104 |
$form['#theme'] = 'itunes_admin_settings';
|
| 105 |
return $form;
|
| 106 |
}
|
| 107 |
|
| 108 |
function itunes_admin_settings_validate($form, &$form_state) {
|
| 109 |
// Retrieve selected types - Forms API sets the value of unselected checkboxes to 0.
|
| 110 |
$form_state['values']['itunes_types'] = array_keys(array_filter($form_state['values']['itunes_types']));
|
| 111 |
}
|
| 112 |
|
| 113 |
function theme_itunes_admin_settings($form) {
|
| 114 |
$rows = array();
|
| 115 |
$header = array($form['itunes_types']['#title']);
|
| 116 |
unset($form['itunes_types']['#title']);
|
| 117 |
|
| 118 |
$has_filefields = FALSE;
|
| 119 |
$has_vocabularies = FALSE;
|
| 120 |
foreach (element_children($form['itunes_types']) as $key) {
|
| 121 |
$row = array(drupal_render($form['itunes_types'][$key]));
|
| 122 |
if (isset($form['itunes_enclosure_source'][$key])) {
|
| 123 |
$row[] = drupal_render($form['itunes_enclosure_source'][$key]);
|
| 124 |
$has_filefields = TRUE;
|
| 125 |
}
|
| 126 |
if (isset($form['itunes_keyword_source'][$key])) {
|
| 127 |
$row[] = drupal_render($form['itunes_keyword_source'][$key]);
|
| 128 |
$has_vocabularies = TRUE;
|
| 129 |
}
|
| 130 |
$row[] = drupal_render($form['itunes_author_source'][$key]);
|
| 131 |
|
| 132 |
$rows[] = $row;
|
| 133 |
}
|
| 134 |
|
| 135 |
if ($has_filefields) {
|
| 136 |
$header[] = t('FileField to list in RSS feeds');
|
| 137 |
}
|
| 138 |
if ($has_vocabularies) {
|
| 139 |
$header[] = t('Vocabulary to use as keywords');
|
| 140 |
}
|
| 141 |
$header[] = t('Source to use as author');
|
| 142 |
|
| 143 |
return theme('table', $header, $rows) . drupal_render($form);
|
| 144 |
}
|