You are here

function advagg_admin_info_form in Advanced CSS/JS Aggregation 6

Same name and namespace in other branches
  1. 7.2 advagg.admin.inc \advagg_admin_info_form()

Form builder; Configure advagg settings.

See also

system_settings_form()

1 string reference to 'advagg_admin_info_form'
advagg_admin_info_page in ./advagg.admin.inc
Page generation function for admin/settings/advagg/info

File

./advagg.admin.inc, line 35
Admin page callbacks for the advanced CSS/JS aggregation module.

Code

function advagg_admin_info_form() {
  $form = array();
  $form['info'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#title' => t('Hook Theme Info'),
  );
  init_theme();
  $hooks = theme_get_registry();
  $data = implode("\n", $hooks['page']['preprocess functions']);
  $form['info']['advagg_debug_info'] = array(
    '#type' => 'textarea',
    '#default_value' => $data,
    '#rows' => count($hooks['page']['preprocess functions']) + 1,
  );
  $types = db_query("SELECT DISTINCT(filetype) FROM {advagg_files}");
  while ($type = db_result($types)) {
    $form[$type] = array(
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#title' => t('@type files', array(
        '@type' => drupal_strtoupper($type),
      )),
    );

    // filename  filename_md5  checksum  filetype  counter   data
    $results = db_query("SELECT * FROM {advagg_files} WHERE filetype = '%s'", $type);
    while ($row = db_fetch_array($results)) {
      $data = advagg_get_file_data($row['filename_md5']);
      if (!empty($data)) {
        list($data, $rows) = advagg_form_print_r($data);
        $form[$type][$row['filename_md5']] = array(
          '#type' => 'textarea',
          '#title' => check_plain($row['filename']),
          '#default_value' => $data,
          '#rows' => $rows - 1,
          '#description' => t('File has changed %counter times', array(
            '%counter' => $row['counter'],
          )),
        );
      }
      else {
        $form[$type][$row['filename_md5']] = array(
          '#type' => 'markup',
          '#value' => '<div>' . format_plural($row['counter'], 'changed 1 time - %file<br />', 'changed %counter times - %file<br /></div>', array(
            '%counter' => $row['counter'],
            '%file' => $row['filename'],
          )),
        );
      }
    }
  }

  // Get hooks in use.
  $hooks = array(
    'advagg_css_alter' => array(),
    'advagg_css_inline_alter' => array(),
    'advagg_css_pre_alter' => array(),
    'advagg_css_extra_alter' => array(),
    'advagg_js_alter' => array(),
    'advagg_js_inline_alter' => array(),
    'advagg_js_pre_alter' => array(),
    'advagg_js_extra_alter' => array(),
    'advagg_js_header_footer_alter' => array(),
    'advagg_filenames_alter' => array(),
    'advagg_files_table' => array(),
    'advagg_master_reset' => array(),
    'advagg_disable_processor' => array(),
    'advagg_disable_page_cache' => array(),
    'advagg_bundler_analysis_alter' => array(),
  );
  foreach ($hooks as $hook => $values) {
    $hooks[$hook] = module_implements($hook);
  }

  // Record function overrides. Not working currently.
  //   $hooks['advagg_css_render_function'] = array(variable_get('advagg_css_render_function', ADVAGG_CSS_RENDER_FUNCTION));
  //   $hooks['advagg_js_render_function'] = array(variable_get('advagg_js_render_function', ADVAGG_JS_RENDER_FUNCTION));
  //   $hooks['advagg_file_save_function'] = array(variable_get('advagg_file_save_function', ADVAGG_FILE_SAVE_FUNCTION));
  // Output hooks in form.
  foreach ($hooks as $hook => $values) {
    if (empty($values)) {
      $form['hooks_implemented'][$hook] = array(
        '#type' => 'markup',
        '#value' => '<div><strong>' . check_plain($hook) . ':</strong><br />&nbsp;&nbsp;&nbsp;&nbsp;' . t('None') . '</div>',
      );
    }
    else {
      $form['hooks_implemented'][$hook] = array(
        '#type' => 'markup',
        '#value' => '<div><strong>' . check_plain($hook) . ':</strong><br />&nbsp;&nbsp;&nbsp;&nbsp;' . filter_xss(implode('<br />&nbsp;&nbsp;&nbsp;&nbsp;', $values)) . '</div>',
      );
    }
  }
  $form['hooks_implemented'] += array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#title' => t('Modules implementing advagg hooks'),
  );

  // If any files are missing list them.
  // TODO: Reset missing files list.
  $results = db_query("SELECT * FROM {advagg_files} WHERE checksum = '-1' ORDER BY filetype ASC");
  while ($row = db_fetch_array($results)) {
    $form['missing'][$row['filename_md5']] = array(
      '#type' => 'markup',
      '#value' => '<div>' . check_plain($row['filename']) . '<br /></div>',
    );
  }
  if (!empty($form['missing'])) {
    $form['missing'] += array(
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
      '#title' => t('Missing files'),
    );
  }

  // Asynchronous raw output
  $form['async'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#title' => t('Asynchronous debug info'),
  );
  list($css_path, $js_path) = advagg_get_root_files_dir();
  $filepath = $css_path . '/css_missing' . mt_rand() . time() . '_0.css';
  $url = _advagg_build_url($filepath);
  $htauth_user = variable_get('advagg_async_test_username', '');
  $htauth_pass = variable_get('advagg_async_test_password', '');
  $headers = array(
    'Host' => $_SERVER['HTTP_HOST'],
    'Connection' => 'close',
  );
  if ($htauth_user && $htauth_pass) {
    $headers['Authorization'] = 'Basic ' . base64_encode($htauth_user . ':' . $htauth_pass);
  }
  timer_start(__FUNCTION__ . 'local');
  $data_local = drupal_http_request($url, $headers);
  $data_local->timer = timer_stop(__FUNCTION__ . 'local');
  list($data, $rows) = advagg_form_print_r($data_local);
  $form['async']['normal'] = array(
    '#type' => 'textarea',
    '#title' => check_plain($url),
    '#default_value' => $data,
    '#rows' => min($rows + 1, 50),
  );
  if (module_exists('cdn')) {
    global $conf;
    $path_blacklist = variable_get(CDN_EXCEPTION_DRUPAL_PATH_BLACKLIST_VARIABLE, CDN_EXCEPTION_DRUPAL_PATH_BLACKLIST_DEFAULT);
    $conf[CDN_EXCEPTION_DRUPAL_PATH_BLACKLIST_VARIABLE] = '';
    $url_cdn = advagg_build_uri($filepath);
    $conf[CDN_EXCEPTION_DRUPAL_PATH_BLACKLIST_VARIABLE] = $path_blacklist;

    // Send request and also time it.
    timer_start(__FUNCTION__ . 'cdn');
    $data_cdn = drupal_http_request($url_cdn);
    $data_cdn->timer = timer_stop(__FUNCTION__ . 'cdn');
    list($data, $rows) = advagg_form_print_r($data_cdn);
    $form['async']['cdn'] = array(
      '#type' => 'textarea',
      '#title' => check_plain($url_cdn),
      '#default_value' => $data,
      '#rows' => min($rows + 1, 50),
    );
  }
  return $form;
}