View source
<?php
function metatags_quick_admin_auto_settings($form, $form_state) {
$current_settings = variable_get('metatags_quick_auto_settings', '');
$type_names = node_type_get_names();
$form['applicable_content_types'] = array(
'#type' => 'checkboxes',
'#title' => t('Applicable content types'),
'#options' => $type_names,
'#default_value' => isset($current_settings['applicable_content_types']) ? $current_settings['applicable_content_types'] : array(),
'#description' => t('Select the content types for which auto settings should be applied'),
'#ajax' => array(
'callback' => 'metatags_quick_extra_ajax_callback',
'wrapper' => 'metatags-quick-auto-default-keywords',
'method' => 'replace',
),
);
$form['global_keywords'] = array(
'#type' => 'textfield',
'#title' => t('Global keywords'),
'#maxlength' => variable_get('metatags_quick_default_field_length', 255),
'#default_value' => isset($current_settings['global_keywords']) ? $current_settings['global_keywords'] : '',
'#description' => t('Enter a comma separated list of keywords. Global keywords will be always added to applicable content types.'),
);
$form['default_keywords'] = array(
'#type' => 'fieldset',
'#title' => t('Default keywords'),
'#collapsible' => true,
'#description' => t('Enter a comma separated list of keywords for the content types below, if you want them to be included automatifcally by default.'),
'#tree' => true,
'#prefix' => '<div id="metatags-quick-auto-default-keywords">',
'#suffix' => '</div>',
);
$applicable_content_types = array();
$available_content_types = array();
if (!empty($form_state['values']['applicable_content_types'])) {
$applicable_content_types = array_values($form_state['values']['applicable_content_types']);
}
elseif (isset($current_settings['applicable_content_types'])) {
$applicable_content_types = array_values($current_settings['applicable_content_types']);
}
foreach ($type_names as $machine_name => $type_name) {
$exists = in_array($machine_name, $applicable_content_types, true);
if ($exists) {
$available_content_types[$machine_name] = $type_name;
}
}
foreach ($available_content_types as $machine_name => $type_name) {
if (isset($current_settings['default_keywords']) && isset($current_settings['default_keywords'][$machine_name])) {
$default_value = $current_settings['default_keywords'][$machine_name];
}
else {
$default_value = '';
}
$form['default_keywords'][$machine_name] = array(
'#type' => 'textfield',
'#title' => $type_name,
'#maxlength' => variable_get('metatags_quick_default_field_length', 255),
'#default_value' => $default_value,
);
}
$vocabularies = taxonomy_vocabulary_get_names();
$options = array();
foreach ($vocabularies as $machine_name => $vocabulary) {
$options[$machine_name] = $vocabulary->name;
}
$form['auto_keywords_vocabularies'] = array(
'#type' => 'checkboxes',
'#title' => t('Auto-keywords vocabularies'),
'#options' => $options,
'#default_value' => isset($current_settings['auto_keywords_vocabularies']) ? $current_settings['auto_keywords_vocabularies'] : array(),
'#description' => t('Select the vocabularies which contain terms you want to add to the keywords meta tag for nodes. The terms of these vocabularies are added before the global and default keywords but after the page-specific keywords.'),
);
$form['meta_description'] = array(
'#type' => 'fieldset',
'#title' => t('Meta Description'),
'#collapsible' => true,
'#description' => t('These options specify how meta description is to be generated from the node content.'),
'#tree' => true,
);
if (isset($current_settings['meta_description']) && isset($current_settings['meta_description']['auto_generate'])) {
$default_value = $current_settings['meta_description']['auto_generate'];
}
else {
$default_value = '';
}
$form['meta_description']['auto_generate'] = array(
'#type' => 'checkbox',
'#title' => t('Auto generate meta description'),
'#default_value' => $default_value,
);
if (isset($current_settings['meta_description']) && isset($current_settings['meta_description']['source'])) {
$default_value = $current_settings['meta_description']['source'];
}
else {
$default_value = '';
}
$options = array(
'body' => t('Generate meta tags content from the node body'),
'teaser' => t('Generate meta tags content from the node teaser'),
'either' => t('Generate meta tags content from the node teaser, or the node body when the node teaser is empty'),
);
$form['meta_description']['source'] = array(
'#type' => 'radios',
'#title' => t('Generation source'),
'#options' => $options,
'#default_value' => $default_value,
);
$form['op'] = array(
'#value' => t('Submit'),
'#type' => 'submit',
);
return $form;
}
function metatags_quick_admin_auto_settings_submit($form, $form_state) {
$new_settings = array(
'applicable_content_types' => $form_state['values']['applicable_content_types'],
'global_keywords' => $form_state['values']['global_keywords'],
'auto_keywords_vocabularies' => $form_state['values']['auto_keywords_vocabularies'],
);
foreach ($form_state['values']['default_keywords'] as $machine_name => $value) {
$new_settings['default_keywords'][$machine_name] = $value;
}
foreach ($form_state['values']['meta_description'] as $key => $value) {
$new_settings['meta_description'][$key] = $value;
}
variable_set('metatags_quick_auto_settings', $new_settings);
drupal_set_message(t('Auto settings saved for Meta tags (quick)'), 'status');
}
function metatags_quick_ajax_callback($form, $form_state) {
return $form['default_keywords'];
}