imageinfo_cache.admin.inc in Imageinfo Cache 6
Same filename and directory in other branches
Configuration page for imageinfo cache module.
File
imageinfo_cache.admin.incView source
<?php
/**
* @file
* Configuration page for imageinfo cache module.
*/
/**
* Page generation fucntion for admin/settings/imageinfo-cache
*/
function imageinfo_cache_admin_page() {
$output = '';
return $output . drupal_get_form('imageinfo_cache_admin_form');
}
/**
* Form builder; Displays DB Tuners configuration page.
*/
function imageinfo_cache_admin_form($form_state) {
$form = array();
// $form['imageinfo_cache_theme_imagecache'] = array(
// '#type' => 'checkbox',
// '#title' => t('Use caching for theme_imagecache'),
// '#default_value' => variable_get('imageinfo_cache_theme_imagecache', IMAGEINFO_CACHE_THEME_IMAGECACHE),
// );
// $form['imageinfo_cache_theme_imagefield_image'] = array(
// '#type' => 'checkbox',
// '#title' => t('Use caching for theme_imagefield_image'),
// '#default_value' => variable_get('imageinfo_cache_theme_imagefield_image', IMAGEINFO_CACHE_THEME_IMAGEFIELD_IMAGE),
// );
$form['imageinfo_cache_imagecache_pregenerate'] = array(
'#type' => 'radios',
'#title' => t('Use imagecache pre-generation'),
'#default_value' => variable_get('imageinfo_cache_imagecache_pregenerate', IMAGEINFO_CACHE_IMAGECACHE_PREGENERATE),
'#options' => array(
0 => t('None'),
2 => t('Per CCK Field'),
1 => t('All'),
),
'#description' => t('What presets are pre-generated can be selected on the CCK filefield widget settings on the admin/content/node-type/%/fields/% page.'),
);
$form['imageinfo_cache_async'] = array(
'#type' => 'checkbox',
'#title' => t('Use asynchronous image operations'),
'#default_value' => variable_get('imageinfo_cache_async', IMAGEINFO_CACHE_ASYNC),
'#description' => t('Create a second request that generates the extra info. This is generally faster.'),
);
$form['imageinfo_cache_socket_timeout'] = array(
'#type' => 'textfield',
'#title' => t('Asynchronous socket timeout (seconds)'),
'#default_value' => variable_get('imageinfo_cache_socket_timeout', IMAGEINFO_CACHE_SOCKET_TIMEOUT),
'#description' => t('Keep this as low as possible. If you start to get <em>Asynchronous imageinfo cache primer failed. Using Synchronous mode</em> errors then you might want to increase this number. Must be an INT.'),
);
$form['imageinfo_cache_async_max'] = array(
'#type' => 'textfield',
'#title' => t('Max number of files to send to each async worker'),
'#default_value' => variable_get('imageinfo_cache_async_max', IMAGEINFO_CACHE_ASYNC_MAX),
);
$form['imageinfo_cache_server_addr'] = array(
'#type' => 'textfield',
'#title' => t('IP Address to send all asynchronous requests to'),
'#default_value' => variable_get('imageinfo_cache_server_addr', FALSE),
'#description' => t('If left blank it will use the same server as the request.'),
);
$form['imageinfo_cache_url_key'] = array(
'#type' => 'textfield',
'#title' => t('Shared authentication key'),
'#default_value' => variable_get('imageinfo_cache_url_key', FALSE),
'#description' => t('Use at least a 9 digit key. This must match on all async servers.'),
);
$period = drupal_map_assoc(array(
1800,
2700,
3600,
10800,
21600,
32400,
43200,
64800,
86400,
2 * 86400,
3 * 86400,
4 * 86400,
5 * 86400,
6 * 86400,
604800,
), 'format_interval');
$form['imageinfo_cache_lifetime'] = array(
'#type' => 'select',
'#title' => t('Theme cache lifetime'),
'#default_value' => variable_get('imageinfo_cache_lifetime', IMAGEINFO_CACHE_LIFETIME),
'#options' => $period,
);
return system_settings_form($form);
}
/**
* validate imageinfo_cache_admin_form submissions.
*/
function imageinfo_cache_admin_form_validate($form, &$form_state) {
$values = $form_state['values'];
// Check that imageinfo_cache_socket_timeout is a positive interger.
if (empty($values['imageinfo_cache_socket_timeout']) || !is_numeric($values['imageinfo_cache_socket_timeout']) || $values['imageinfo_cache_socket_timeout'] < 1) {
form_set_error('imageinfo_cache_socket_timeout', t('Number must be a positive interger.'));
}
// Check that imageinfo_cache_async_max is a positive interger.
if (empty($values['imageinfo_cache_async_max']) || !is_numeric($values['imageinfo_cache_async_max']) || $values['imageinfo_cache_async_max'] < 1) {
form_set_error('imageinfo_cache_async_max', t('Number must be a positive interger.'));
}
// If the IP field is not blank, check that its a valid address.
if (!empty($values['imageinfo_cache_server_addr']) && ip2long($values['imageinfo_cache_server_addr']) === FALSE) {
form_set_error('imageinfo_cache_server_addr', t('Must be a valid IP address.'));
}
if (empty($values['imageinfo_cache_url_key']) || !is_numeric($values['imageinfo_cache_url_key']) || $values['imageinfo_cache_url_key'] < 1) {
form_set_error('imageinfo_cache_url_key', t('Number must be a positive interger.'));
}
}
/**
* Called from imageinfo_cache_form_alter().
*/
function imageinfo_cache_cck_widget_form(&$form, $form_state, $form_id) {
$widget_settings = variable_get('imageinfo_cache_cck_widget_' . $form['#field']['type_name'] . '_' . $form['#field']['field_name'], array());
$all = FALSE;
if (!is_array($widget_settings) && $widget_settings == TRUE) {
$all = TRUE;
}
// Add in settings form.
$form['widget']['imageinfo_cache'] = array(
'#type' => 'fieldset',
'#title' => t('Imageinfo Cache'),
'#collapsible' => 1,
'#collapsed' => 1,
'#weight' => 20,
);
$form['widget']['imageinfo_cache']['imageinfo_cache_settings_all'] = array(
'#type' => 'checkbox',
'#title' => t('Select all imagecache presets to pregenerate when an image is uploaded'),
'#default_value' => $all,
'#description' => t('If selected the settings below will be ignored.'),
);
foreach (imagecache_presets() as $preset) {
$presets[$preset['presetid']] = $preset['presetname'];
}
$form['widget']['imageinfo_cache']['imageinfo_cache_settings'] = array(
'#type' => 'checkboxes',
'#title' => t('Select the imagecache presets to pregenerate when an image is uploaded'),
'#options' => $presets,
'#default_value' => $all ? array_flip($presets) : $widget_settings,
);
// Add in submit handler.
if (!in_array('imageinfo_cache_cck_widget_form_submit', $form['#submit'])) {
$form['#submit'][] = 'imageinfo_cache_cck_widget_form_submit';
}
}
/**
* Implements hook_form_submit().
*/
function imageinfo_cache_cck_widget_form_submit($form, &$form_state) {
if (empty($form_state['values']['imageinfo_cache_settings'])) {
return;
}
if ($form_state['values']['imageinfo_cache_settings_all']) {
variable_set('imageinfo_cache_cck_widget_' . $form['#field']['type_name'] . '_' . $form['#field']['field_name'], $form_state['values']['imageinfo_cache_settings_all']);
}
else {
variable_set('imageinfo_cache_cck_widget_' . $form['#field']['type_name'] . '_' . $form['#field']['field_name'], $form_state['values']['imageinfo_cache_settings']);
}
unset($form_state['values']['imageinfo_cache_settings']);
unset($form_state['values']['imageinfo_cache_settings_all']);
}
Functions
Name![]() |
Description |
---|---|
imageinfo_cache_admin_form | Form builder; Displays DB Tuners configuration page. |
imageinfo_cache_admin_form_validate | validate imageinfo_cache_admin_form submissions. |
imageinfo_cache_admin_page | Page generation fucntion for admin/settings/imageinfo-cache |
imageinfo_cache_cck_widget_form | Called from imageinfo_cache_form_alter(). |
imageinfo_cache_cck_widget_form_submit | Implements hook_form_submit(). |