You are here

function cdn_admin_other_settings_form in CDN 7.2

Same name and namespace in other branches
  1. 6.2 cdn.admin.inc \cdn_admin_other_settings_form()
  2. 6 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
Implements hook_menu().

File

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

Code

function cdn_admin_other_settings_form($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['cdn_seo'] = array(
    '#type' => 'fieldset',
    '#title' => t('SEO: duplicate content prevention'),
    '#description' => t("By default most CDNs will cache full HTML pages if accessed. This means\n      that a copy of your site may appear in search engines. This is confusing, unprofessional and potentially bad for SEO.\n      <br />\n      <em>Duplicate content prevention</em> is enabled by default and ensures the CDN will redirect users to your actual ('canonical') site."),
  );
  $form['cdn_seo'][CDN_SEO_REDIRECT_VARIABLE] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable duplicate content prevention'),
    '#default_value' => variable_get(CDN_SEO_REDIRECT_VARIABLE, CDN_SEO_REDIRECT_DEFAULT),
  );
  $form['cdn_seo'][CDN_SEO_USER_AGENTS_VARIABLE] = array(
    '#type' => 'textarea',
    '#title' => t('CDN user agents'),
    '#description' => t('A case-insensitive list of CDN user agents. These will be substring-matched against the detected user agent of a request. One per line.'),
    '#default_value' => variable_get(CDN_SEO_USER_AGENTS_VARIABLE, CDN_SEO_USER_AGENTS_DEFAULT),
    '#states' => array(
      'visible' => array(
        ':input[name="' . CDN_SEO_REDIRECT_VARIABLE . '"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  $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, ''),
      '#states' => array(
        'visible' => array(
          ':input[name="' . CDN_HTTPS_SUPPORT_VARIABLE . '"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
  }
  $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,
  );
  return system_settings_form($form);
}