You are here

function cdn_admin_other_settings_form in CDN 6.2

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

Form definition; other settings.

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

File

./cdn.admin.inc, line 238
Settings administration UI.

Code

function cdn_admin_other_settings_form(&$form_state) {
  $form = array();
  _cdn_settings_form_prepare($form, $form_state);
  if (variable_get(CDN_MODE_VARIABLE, CDN_MODE_BASIC) == CDN_MODE_ADVANCED) {
    $form[CDN_DRUPAL_ROOT_VARIABLE] = array(
      '#type' => 'textfield',
      '#title' => t('Drupal root directory'),
      '#description' => t('In 99% of the cases the default value is sufficient and correct. In
        some advanced setups that make use of symbolic links however, it is
        possible that the Drupal root directory is incorrectly detected. In
        those cases, you should enter it here.<br />
        <strong>This setting only affects the status report, it does not affect
        the CDN integration itself in any way.</strong>'),
      '#required' => TRUE,
      '#default_value' => variable_get(CDN_DRUPAL_ROOT_VARIABLE, realpath('.')),
    );
  }
  $form['https'] = array(
    '#type' => 'fieldset',
    '#title' => t('HTTPS'),
  );
  $form['https'][CDN_HTTPS_SUPPORT_VARIABLE] = array(
    '#type' => 'checkbox',
    '#title' => t('CDN supports HTTPS'),
    '#default_value' => variable_get(CDN_HTTPS_SUPPORT_VARIABLE, FALSE),
    '#description' => _cdn_help('admin-other-https') . t('Enable if you use HTTPS and your CDN supports it too.'),
  );
  if (variable_get(CDN_MODE_VARIABLE, CDN_MODE_BASIC) == CDN_MODE_BASIC) {
    $form['https'][CDN_BASIC_MAPPING_HTTPS_VARIABLE] = array(
      '#type' => 'textarea',
      '#title' => t('CDN mapping for HTTPS'),
      '#description' => t('If your CDN supports HTTPS, but requires you to
                            use different URLs, then you can define an
                            alternative CDN mapping here. This overrides the
                            "regular" CDN mapping completely, when using
                            HTTPS.'),
      '#size' => 35,
      '#default_value' => variable_get(CDN_BASIC_MAPPING_HTTPS_VARIABLE, ''),
      '#process' => array(
        'ctools_dependent_process',
      ),
      '#dependency' => array(
        'edit-cdn-https-support' => array(
          '1',
        ),
      ),
    );
  }
  $path_explanation = t("Enter one file pattern per line. The '*' character is a wildcard.<br />\n    Example file patterns are <code>*.js</code> for all JavaScript files and\n    <code>mytheme/*.css</code> for all CSS files in the <code>mytheme</code>\n    directory.");
  $form['exceptions'] = array(
    '#type' => 'fieldset',
    '#title' => t('Exceptions'),
    '#description' => _cdn_help('admin-other-exceptions') . t('Which files should be served from a CDN is not as
                         simple as it seems: there are bound to be exceptions.
                         You can easily define those exceptions here, either
                         by file URL, Drupal path or by Drupal path for
                         authenticated users.'),
  );
  $form['exceptions']['file_path'] = array(
    '#type' => 'fieldset',
    '#title' => t('File URL'),
    '#description' => t("Files that are marked to not be served from the CDN\n    because of a match in the blacklist, can be overridden to be served from\n    the CDN after all, if they have a match in the whitelist."),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['exceptions']['file_path'][CDN_EXCEPTION_FILE_PATH_BLACKLIST_VARIABLE] = array(
    '#type' => 'textarea',
    '#title' => t('Blacklist'),
    '#default_value' => variable_get(CDN_EXCEPTION_FILE_PATH_BLACKLIST_VARIABLE, CDN_EXCEPTION_FILE_PATH_BLACKLIST_DEFAULT),
    '#description' => $path_explanation,
  );
  $blacklist_modules = module_implements('cdn_blacklist');
  $blacklist_modules = array_unique(array_merge($blacklist_modules, module_implements('cdn_blacklist_alter')));
  $blacklist_modules_string = '';
  for ($i = 0; $i < count($blacklist_modules); $i++) {
    $blacklist_modules_string .= '<code>' . $blacklist_modules[$i] . '</code>';
    if ($i < count($blacklist_modules) - 1) {
      $blacklist_modules_string .= ', ';
    }
  }
  $form['exceptions']['file_path']['cdn_hook_blacklist'] = array(
    '#type' => 'textarea',
    '#title' => t('Blacklist from modules'),
    '#default_value' => cdn_get_blacklist(TRUE),
    '#description' => t('Blacklist from <code>hook_cdn_blacklist()</code> and
                        <code>hook_cdn_blacklist_alter()</code>. Automatically
                        updated when cron runs. Generated from the following
                        modules: !module-list.', array(
      '!module-list' => $blacklist_modules_string,
    )),
    '#disabled' => TRUE,
  );
  $form['exceptions']['file_path'][CDN_EXCEPTION_FILE_PATH_WHITELIST_VARIABLE] = array(
    '#type' => 'textarea',
    '#title' => t('Whitelist'),
    '#default_value' => variable_get(CDN_EXCEPTION_FILE_PATH_WHITELIST_VARIABLE, CDN_EXCEPTION_FILE_PATH_WHITELIST_DEFAULT),
    '#description' => $path_explanation,
  );
  $form['exceptions']['drupal_path'] = array(
    '#type' => 'fieldset',
    '#title' => t('Drupal path'),
    '#description' => t("Drupal paths entered in this blacklist will not serve\n                         any files from the CDN. This blacklist is applied for\n                         <em>all</em> users."),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['exceptions']['drupal_path'][CDN_EXCEPTION_DRUPAL_PATH_BLACKLIST_VARIABLE] = array(
    '#type' => 'textarea',
    '#title' => t('Blacklist'),
    '#default_value' => variable_get(CDN_EXCEPTION_DRUPAL_PATH_BLACKLIST_VARIABLE, CDN_EXCEPTION_DRUPAL_PATH_BLACKLIST_DEFAULT),
    '#description' => t("Enter one page per line as Drupal paths. The '*' character is a\n      wildcard. Example paths are %blog for the blog page and %blog-wildcard\n      for every personal blog. %front is the front page.", array(
      '%blog' => 'blog',
      '%blog-wildcard' => 'blog/*',
      '%front' => '<front>',
    )),
  );
  $form['exceptions']['auth_users'] = array(
    '#type' => 'fieldset',
    '#title' => t('Drupal path for authenticated users'),
    '#description' => t("Drupal paths entered in this blacklist will not serve\n                         any files from the CDN. This blacklist is applied for\n                         <em>authenticated users only</em>."),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['exceptions']['auth_users'][CDN_EXCEPTION_AUTH_USERS_BLACKLIST_VARIABLE] = array(
    '#type' => 'textarea',
    '#title' => t('Blacklist'),
    '#default_value' => variable_get(CDN_EXCEPTION_AUTH_USERS_BLACKLIST_VARIABLE, CDN_EXCEPTION_AUTH_USERS_BLACKLIST_DEFAULT),
    '#description' => $path_explanation,
  );
  $form['cdn_pick_server'] = array(
    '#type' => 'fieldset',
    '#title' => 'cdn_pick_server()',
    '#description' => t('It is possible to achieve very advanced types of CDN
                         integration by implementing the
                         <code>cdn_pick_server()</code> function (consult the
                         included README for examples). However, to lower the
                         barrier to start using it, it has been made possible
                         to just enter the body of that function right here,
                         in the settings of the CDN module, so you would not
                         have to create a small module for it.'),
  );
  if (function_exists('cdn_pick_server')) {
    $form['cdn_pick_server']['defined_in_code'] = array(
      '#type' => 'item',
      '#title' => t('Defined in code'),
      '#value' => 'The <code>cdn_pick_server()</code> function is already defined in code.',
    );
  }
  else {
    $php_code = variable_get(CDN_PICK_SERVER_PHP_CODE_VARIABLE, '');
    $form['cdn_pick_server'][CDN_PICK_SERVER_PHP_CODE_VARIABLE] = array(
      '#type' => 'textarea',
      '#title' => t('PHP code for cdn_pick_server()'),
      '#description' => _cdn_help('admin-other-cdn-pick-server') . t('PHP code to select the most appropriate CDN server.'),
      '#cols' => 60,
      '#rows' => $php_code != '' ? count(explode("\n", $php_code)) + 1 : 5,
      '#default_value' => $php_code,
    );
  }
  return system_settings_form($form);
}