function cdn_admin_details_form_validate in CDN 6.2
Same name and namespace in other branches
- 7.2 cdn.admin.inc \cdn_admin_details_form_validate()
Default validate callback for the details form.
File
- ./
cdn.admin.inc, line 424 - Settings administration UI.
Code
function cdn_admin_details_form_validate($form, &$form_state) {
// If ctools_dependent supported required dependent form items, this ugly
// piece of code would not be necessary.
if ($form_state['values'][CDN_MODE_VARIABLE] == CDN_MODE_BASIC) {
if (empty($form_state['values'][CDN_BASIC_MAPPING_VARIABLE])) {
form_error($form['settings'][CDN_BASIC_MAPPING_VARIABLE], t('!name field is required.', array(
'!name' => $form['settings'][CDN_BASIC_MAPPING_VARIABLE]['#title'],
)));
}
}
else {
if (empty($form_state['values'][CDN_ADVANCED_SYNCED_FILES_DB_VARIABLE])) {
form_error($form['settings'][CDN_ADVANCED_SYNCED_FILES_DB_VARIABLE], t('!name field is required.', array(
'!name' => $form['settings'][CDN_ADVANCED_SYNCED_FILES_DB_VARIABLE]['#title'],
)));
}
}
// When in Origin Pull mode, check the CDN mapping for CDNs/reverse proxies.
if ($form_state['values'][CDN_MODE_VARIABLE] == CDN_MODE_BASIC) {
$domains = cdn_get_domains();
$token = md5(rand());
variable_set('cdn_reverse_proxy_test', $token);
$yays = array();
$nays = array();
foreach ($domains as $domain) {
$url = 'http://' . $domain . base_path() . 'cdn/farfuture/reverse-proxy-test/' . $token;
$r1 = drupal_http_request($url);
$r2 = drupal_http_request($url);
unset($r1->headers);
unset($r2->headers);
$args = array(
'%domain' => $domain,
);
if ($r1 == $r2) {
$yays[] = t('%domain is a CDN or a reverse proxy.', $args);
}
else {
if ($r1->code == 404) {
$nays[] = t('%domain is a static file server.', $args);
}
else {
$nays[] = t('%domain uses the same web server as this Drupal site.', $args);
}
}
}
variable_set('cdn_reverse_proxy_test', FALSE);
if (!empty($yays)) {
drupal_set_message(t('Perfect domains: !yay-list', array(
'!yay-list' => theme('item_list', array(
'items' => $yays,
)),
)));
}
if (!empty($nays)) {
drupal_set_message(t('Potentially problematic domains: !nay-list', array(
'!nay-list' => theme('item_list', array(
'items' => $nays,
)),
)), 'warning');
}
}
elseif ($form_state['values'][CDN_MODE_VARIABLE] == CDN_MODE_ADVANCED) {
$synced_files_db = $form_state['values'][CDN_ADVANCED_SYNCED_FILES_DB_VARIABLE];
_cdn_admin_validate_synced_files_db($synced_files_db, CDN_ADVANCED_SYNCED_FILES_DB_VARIABLE);
}
}