You are here

function cdn_admin_settings_form in CDN 5

Same name and namespace in other branches
  1. 6 cdn.admin.inc \cdn_admin_settings_form()

Form definition: CDN admin settings form.

1 string reference to 'cdn_admin_settings_form'
cdn_menu in ./cdn.module
Implementation of hook_menu().

File

./cdn.module, line 164

Code

function cdn_admin_settings_form() {
  $form['settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Settings'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['settings']['cdn_cron_method'] = array(
    '#type' => 'radios',
    '#title' => t('Cron method'),
    '#description' => t("Since CDN synchronization typically takes a lot of time (relatively),\n      you may want to run it as a separate cron, so it doesn't slow down the\n      'normal' cron of Drupal core."),
    '#options' => array(
      'core' => t("Drupal core's cron"),
      'cdn' => t("CDN integration's cron"),
    ),
    '#default_value' => variable_get('cdn_cron_method', 'cdn'),
  );
  $form['settings']['cdn_debug_mode'] = array(
    '#type' => 'radios',
    '#title' => t('Debug mode'),
    '#description' => t("If you don't want to use the CDN to serve files to your visitors yet,\n      but you do want to see if it's working well for your site, then enable\n      debug mode.<br />It will only serve files from the CDN if they have the\n      %cdn-debug-mode-permission permission.", array(
      '%cdn-debug-mode-permission' => 'access files on CDN when in debug mode',
    )),
    '#options' => array(
      0 => t('Disabled'),
      1 => t('Enabled'),
    ),
    '#default_value' => variable_get('cdn_debug_mode', 0),
  );
  $form['dev'] = array(
    '#type' => 'fieldset',
    '#title' => t('Development'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['dev']['cdn_dev_page_stats'] = array(
    '#type' => 'radios',
    '#title' => t('Show statistics for the current page'),
    '#description' => t('Shows the CDN integration statistics of the current page, to users with
      the %access-per-page-statistics permissions.', array(
      '%access-per-page-statistics' => 'access per-page statistics',
    )),
    '#options' => array(
      '0' => t('Disabled'),
      '1' => t('Enabled'),
    ),
    '#default_value' => variable_get('cdn_dev_page_stats', 0),
  );
  $form['stats'] = array(
    '#type' => 'fieldset',
    '#title' => t('Site-wide statistics'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $cdn_cron_last = variable_get('cdn_cron_last', NULL);
  $form['stats']['last_run'] = array(
    '#type' => 'fieldset',
    '#title' => t('Last run'),
    '#description' => t('Results from the last CDN synchronization'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  if (isset($cdn_cron_last)) {
    $form['stats']['last_run']['#value'] = '<p>' . t('Last run was !time ago.', array(
      '!time' => format_interval(time() - $cdn_cron_last),
    )) . '</p>' . variable_get('cdn_cron_last_stats', '<p><em>' . t('No statistics available.') . '</em></p>');
  }
  else {
    $form['stats']['last_run']['#value'] = '<p>' . t('No CDN synchronization run has been performed yet. Please check the !status-report to find out what you have to do.', array(
      '!status-report' => l('Status report', 'admin/logs/status'),
    )) . '</p>';
  }
  require_once 'cdn_cron.inc';
  list($files_scheduled, $files_unique_settings, $files_update_settings) = _cdn_cron_get_files_to_sync(variable_get('cdn_sync_filters', array()));
  unset($files_unique_settings, $files_update_settings);
  $files_scheduled_size = 0;
  foreach ($files_scheduled as $file => $size) {
    $files_scheduled_size += $size;
  }
  $files_synced = variable_get('cdn_files_synced', array());
  $files_scheduled_unsynced = array_diff(array_keys($files_scheduled), array_keys($files_synced));
  $files_unscheduled_synced = array_diff(array_keys($files_synced), array_keys($files_scheduled));
  $files_scheduled_synced = array_flip(array_diff(array_flip($files_synced), $files_unscheduled_synced));
  $coverage = count($files_scheduled) == 0 ? 1 : (count($files_scheduled) - count($files_scheduled_unsynced)) / count($files_scheduled);
  $form['stats']['numbers'] = array(
    '#value' => theme('cdn_numbers', $files_scheduled, $files_scheduled_size, $files_synced, $coverage),
  );
  $form['stats']['list_scheduled_unsynced'] = array(
    '#type' => 'fieldset',
    '#title' => t('Files that are scheduled but not yet synchronized (!count)', array(
      '!count' => count($files_scheduled_unsynced),
    )),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['stats']['list_scheduled_unsynced']['table'] = array(
    '#value' => theme('cdn_scheduled_unsynced_files_list', $files_scheduled_unsynced),
  );
  $form['stats']['list_unscheduled_synced'] = array(
    '#type' => 'fieldset',
    '#title' => t('Files that are queued for deletion (!count)', array(
      '!count' => count($files_unscheduled_synced),
    )),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['stats']['list_unscheduled_synced']['table'] = array(
    '#value' => theme('cdn_unscheduled_synced_files_list', $files_unscheduled_synced, $files_synced),
  );
  $form['stats']['list_synced'] = array(
    '#type' => 'fieldset',
    '#title' => t('Synchronized files (!count)', array(
      '!count' => count($files_scheduled_synced),
    )),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['stats']['list_synced']['table'] = array(
    '#value' => theme('cdn_synced_files_list', $files_scheduled_synced),
  );
  return system_settings_form($form);
}