You are here

imageinfo_cache.admin.inc in Imageinfo Cache 6.2

Same filename and directory in other branches
  1. 6 imageinfo_cache.admin.inc
  2. 7.3 imageinfo_cache.admin.inc

Configuration page for imageinfo cache module.

File

imageinfo_cache.admin.inc
View 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_imagecache_pregenerate'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use imagecache pre-generation'),
    '#default_value' => variable_get('imageinfo_cache_imagecache_pregenerate', IMAGEINFO_CACHE_IMAGECACHE_PREGENERATE),
    '#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_fields'] = array(
    '#type' => 'fieldset',
    '#title' => t('Imageinfo Cache CCK Settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $links = array();
  foreach (content_types() as $node_type => $info) {
    foreach ($info['fields'] as $filed_name => $data) {
      if ($data['type'] == 'filefield') {
        $links[] = l($info['name'] . ' - ' . $data['field_name'], 'admin/content/node-type/' . str_replace('_', '-', $node_type) . '/fields/' . $filed_name);
      }
    }
  }
  $form['imageinfo_cache_fields']['list'] = array(
    '#type' => 'markup',
    '#value' => implode('<br />', $links),
  );
  $form['imageinfo_cache_httprl_mode'] = array(
    '#type' => 'radios',
    '#title' => t('HTTP Mode'),
    '#default_value' => variable_get('imageinfo_cache_httprl_mode', IMAGEINFO_CACHE_HTTPRL_MODE),
    '#description' => t('Blocking mode will wait for an acknowledgement from the server that the http request was recieved. Non Blocking mode will not wait for any acknowledgement that the request was recieved. Non Blocking mode is faster but does not guarantee that the work will be done. Blocking mode is slower and guarantees that the work will be done.'),
    '#options' => array(
      0 => t('Non Blocking'),
      1 => t('Blocking'),
    ),
  );
  $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_url_key'] = array(
    '#type' => 'textfield',
    '#title' => t('Shared authentication key'),
    '#default_value' => variable_get('imageinfo_cache_url_key', md5(drupal_get_private_key())),
    '#description' => t('Use a 32 character md5 hash. This must match on all servers.'),
  );
  $form['imageinfo_cache_server_addr'] = array(
    '#type' => 'textfield',
    '#title' => t('Server/IP Address to send all image generation requests to'),
    '#default_value' => variable_get('imageinfo_cache_server_addr', FALSE),
    '#description' => t('If left blank it will use the settings found in the <a href="!link">HTTPRL module</a>.', array(
      '!link' => url('admin/settings/httprl'),
    )),
  );
  $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_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'])) {

    // Not an IP address
    if (ip2long($values['imageinfo_cache_server_addr']) === FALSE) {

      // Not a valid hostname
      if (ip2long(gethostbyname($values['imageinfo_cache_server_addr'])) === FALSE) {
        form_set_error('imageinfo_cache_server_addr', t('Must be a valid IP address OR server name.') . gethostbyname($values['imageinfo_cache_server_addr']));
      }
    }
  }
  if (empty($values['imageinfo_cache_url_key']) || !preg_match('/^[a-f0-9]{32}$/', $values['imageinfo_cache_url_key'])) {
    form_set_error('imageinfo_cache_url_key', t('Value must be a valid md5 hash. Recommended md5 hash on this server: %value', array(
      '%value' => md5(drupal_get_private_key()),
    )));
  }

  // Do no set certian variables.
  unset($form_state['values']['list']);
}

/**
 * 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'], IMAGEINFO_CACHE_CCK_WIDGET);
  $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 not selected, settings will apear below allowing one to control what presets will be pregenerated.'),
    '#disabled' => variable_get('imageinfo_cache_imagecache_pregenerate', IMAGEINFO_CACHE_IMAGECACHE_PREGENERATE) ? FALSE : TRUE,
  );
  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,
    '#prefix' => '<div id="imageinfo-cache-settings-widget">',
    '#suffix' => '</div>',
  );

  // Add in submit handler.
  if (!in_array('imageinfo_cache_cck_widget_form_submit', $form['#submit'])) {
    $form['#submit'][] = 'imageinfo_cache_cck_widget_form_submit';
  }
  $widget_vis = "\n\$(imageinfo_cache_update_widget_visibility);\n\$(function(){ \$('#edit-imageinfo-cache-settings-all').change(function (){imageinfo_cache_update_widget_visibility();})});\nfunction imageinfo_cache_update_widget_visibility() {\n  if (\$('#edit-imageinfo-cache-settings-all:checked').val() !== undefined) {\n    \$('#imageinfo-cache-settings-widget').hide();\n  }\n  else {\n    \$('#imageinfo-cache-settings-widget').show();\n  }\n}";
  drupal_add_js($widget_vis, 'inline');
}

/**
 * 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

Namesort descending 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().