| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Provides the admin and profile forms.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Form builder; Generate a form to set default settings.
|
| 11 |
*/
|
| 12 |
function profile_blog_info_admin_form() {
|
| 13 |
$period = drupal_map_assoc(array(900, 1800, 3600, 7200, 10800, 21600, 32400, 43200, 64800, 86400, 172800, 259200, 604800, 1209600, 2419200), 'format_interval');
|
| 14 |
|
| 15 |
$form = array();
|
| 16 |
|
| 17 |
$form['profile_blog_info_profile_category'] = array('#type' => 'textfield',
|
| 18 |
'#title' => t('Profile Category'),
|
| 19 |
'#default_value' => variable_get('profile_blog_info_profile_category', ''),
|
| 20 |
'#autocomplete_path' => 'admin/user/profile/autocomplete',
|
| 21 |
'#description' => t('The category the new field should be part of. Categories are used to group fields logically. An example category is "Personal information".'),
|
| 22 |
);
|
| 23 |
|
| 24 |
$form['profile_blog_info_fieldset'] = array('#type' => 'textfield',
|
| 25 |
'#title' => t('Fieldset name'),
|
| 26 |
'#default_value' => variable_get('profile_blog_info_fieldset', t('Blog Information')),
|
| 27 |
'#autocomplete_path' => 'admin/user/profile/autocomplete',
|
| 28 |
'#description' => t('The name of the fieldset containing the information about the RSS feed. An example would be "Blog information".'),
|
| 29 |
);
|
| 30 |
|
| 31 |
$form['profile_blog_info_blog'] = array('#type' => 'textfield',
|
| 32 |
'#title' => t('Title field title'),
|
| 33 |
'#default_value' => variable_get('profile_blog_info_blog', t('Blog or homepage')),
|
| 34 |
'#description' => t('The title to display above the blog/homepage field.'),
|
| 35 |
);
|
| 36 |
|
| 37 |
$form['profile_blog_info_title'] = array('#type' => 'textfield',
|
| 38 |
'#title' => t('Title field title'),
|
| 39 |
'#default_value' => variable_get('profile_blog_info_title', t('Title')),
|
| 40 |
'#description' => t('The title to display above the title field.'),
|
| 41 |
);
|
| 42 |
|
| 43 |
$form['profile_blog_info_rss'] = array('#type' => 'textfield',
|
| 44 |
'#title' => t('RSS field title'),
|
| 45 |
'#default_value' => variable_get('profile_blog_info_rss', t('RSS')),
|
| 46 |
'#description' => t('The title to display above the RSS field.'),
|
| 47 |
);
|
| 48 |
|
| 49 |
$form['profile_blog_info_explanation'] = array('#type' => 'textarea',
|
| 50 |
'#title' => t('Explanation'),
|
| 51 |
'#default_value' => variable_get('profile_blog_info_explanation', ''),
|
| 52 |
'#description' => t('An optional explanation to go with the new field. The explanation will be shown to the user.'),
|
| 53 |
);
|
| 54 |
|
| 55 |
$form['profile_blog_info_required'] = array('#type' => 'checkbox',
|
| 56 |
'#title' => t('The user must enter a value.'),
|
| 57 |
'#default_value' => variable_get('profile_blog_info_required', 0),
|
| 58 |
);
|
| 59 |
$form['profile_blog_info_register'] = array('#type' => 'checkbox',
|
| 60 |
'#title' => t('Visible in user registration form.'),
|
| 61 |
'#default_value' => variable_get('profile_blog_info_register', 0),
|
| 62 |
);
|
| 63 |
|
| 64 |
$form['profile_blog_info_refresh'] = array('#type' => 'select',
|
| 65 |
'#title' => t('Default Update interval for new items'),
|
| 66 |
'#default_value' => variable_get('profile_blog_info_refresh', 900),
|
| 67 |
'#options' => $period,
|
| 68 |
'#description' => t('The length of time between feed updates. (Requires a correctly configured <a href="@cron">cron maintenance task</a>.)', array('@cron' => url('admin/reports/status'))),
|
| 69 |
);
|
| 70 |
|
| 71 |
// Handling of categories:
|
| 72 |
$options = array();
|
| 73 |
$categories = db_query('SELECT cid, title FROM {aggregator_category} ORDER BY title');
|
| 74 |
while ($category = db_fetch_object($categories)) {
|
| 75 |
$options[$category->cid] = check_plain($category->title);
|
| 76 |
}
|
| 77 |
if ($options) {
|
| 78 |
$form['profile_blog_info_category'] = array('#type' => 'checkboxes',
|
| 79 |
'#title' => t('Default aggregator category for news items'),
|
| 80 |
'#default_value' => variable_get('profile_blog_info_category', array()),
|
| 81 |
'#options' => $options,
|
| 82 |
'#description' => t('New feed items are automatically filed in the checked categories.'),
|
| 83 |
);
|
| 84 |
}
|
| 85 |
$form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration') );
|
| 86 |
$form['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults') );
|
| 87 |
|
| 88 |
if (!empty($_POST) && form_get_errors()) {
|
| 89 |
drupal_set_message(t('The settings have not been saved because of the errors.'), 'error');
|
| 90 |
}
|
| 91 |
$form['#submit'][] = 'system_settings_form_submit';
|
| 92 |
$form['#submit'][] = 'drupal_flush_all_caches';
|
| 93 |
$form['#theme'] = 'system_settings_form';
|
| 94 |
|
| 95 |
return $form;
|
| 96 |
}
|
| 97 |
|
| 98 |
function profile_blog_info_admin_form_submit($form, &$form_state) {
|
| 99 |
$op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
|
| 100 |
|
| 101 |
// Exclude unnecessary elements.
|
| 102 |
unset($form_state['values']['submit'], $form_state['values']['reset'], $form_state['values']['form_id'], $form_state['values']['op'], $form_state['values']['form_token'], $form_state['values']['form_build_id']);
|
| 103 |
|
| 104 |
foreach ($form_state['values'] as $key => $value) {
|
| 105 |
if ($op == t('Reset to defaults')) {
|
| 106 |
variable_del($key);
|
| 107 |
}
|
| 108 |
else {
|
| 109 |
if (is_array($value) && isset($form_state['values']['array_filter'])) {
|
| 110 |
$value = array_keys(array_filter($value));
|
| 111 |
}
|
| 112 |
variable_set($key, $value);
|
| 113 |
}
|
| 114 |
}
|
| 115 |
if ($op == t('Reset to defaults')) {
|
| 116 |
drupal_set_message(t('The configuration options have been reset to their default values.'));
|
| 117 |
}
|
| 118 |
else {
|
| 119 |
drupal_set_message(t('The configuration options have been saved.'));
|
| 120 |
}
|
| 121 |
|
| 122 |
cache_clear_all();
|
| 123 |
drupal_rebuild_theme_registry();
|
| 124 |
menu_rebuild();
|
| 125 |
return;
|
| 126 |
}
|