You are here

function advagg_js_compress_test_compression in Advanced CSS/JS Aggregation 6

Same name and namespace in other branches
  1. 7 advagg_js_compress/advagg_js_compress.module \advagg_js_compress_test_compression()

Run various theme functions so the cache is primed.

Parameters

$files_to_test: array with md5 and filename.

Return value

TRUE if all files are compressible. List of files that failed otherwise.

3 calls to advagg_js_compress_test_compression()
advagg_js_compress_advagg_files_table in advagg_js_compress/advagg_js_compress.module
Implement hook_advagg_files_table.
advagg_js_compress_check_callback in advagg_js_compress/advagg_js_compress.install
Check to see if the CSS/JS generator is working.
advagg_js_compress_prep in advagg_js_compress/advagg_js_compress.module
Compress a JS string

File

advagg_js_compress/advagg_js_compress.module, line 348
Advanced CSS/JS aggregation js compression module.

Code

function advagg_js_compress_test_compression($files_to_test) {
  global $base_path;
  $bad_files = array();

  // Blacklist jquery.min.js from getting compressed.
  if (module_exists('jquery_update')) {
    foreach ($files_to_test as $key => $info) {
      if (strpos($info['filename'], 'jquery.min.js') !== FALSE) {

        // Add file to the bad list.
        $bad_files[] = $info;
        unset($files_to_test[$key]);

        // Get file data.
        $filename_md5 = md5($info['filename']);
        $lock_name = 'advagg_set_file_data_' . $filename_md5;
        if (!lock_acquire($lock_name, 10)) {
          lock_wait($lock_name);
          continue;
        }
        $data = advagg_get_file_data($filename_md5);

        // Set to -2
        if (!isset($data->data['advagg_js_compress']['tested']['jsminplus']) || $data->data['advagg_js_compress']['tested']['jsminplus'] != -2) {
          $data['advagg_js_compress']['tested']['jsminplus'] = -2;
          advagg_set_file_data($filename_md5, $data);
        }
        lock_release($lock_name);
      }
    }
  }
  foreach ($files_to_test as $info) {
    $key = variable_get('advagg_js_compress_url_key', FALSE);
    if (empty($key)) {
      $key = mt_rand();
      variable_set('advagg_js_compress_url_key', $key);
    }

    // Clear the cache for this file
    cache_clear_all($info['filename'], 'cache_advagg_js_compress_file');

    // Setup request URL and headers.
    $query['values'] = $info;
    $query['key'] = $key;
    $query_string = http_build_query($query, '', '&');
    $url = _advagg_build_url('advagg/js_compress_test_file');
    $headers = array(
      'Host' => $_SERVER['HTTP_HOST'],
      'Content-Type' => 'application/x-www-form-urlencoded',
      'Connection' => 'close',
    );
    $results = drupal_http_request($url, $headers, 'POST', $query_string);

    // Get file data.
    $filename_md5 = md5($info['filename']);
    $data = advagg_get_file_data($filename_md5);

    // Mark as a bad file.
    if (empty($data['advagg_js_compress']['tested']['jsminplus']) || $data['advagg_js_compress']['tested']['jsminplus'] != 1) {
      $bad_files[] = $info;
    }
  }
  if (empty($bad_files)) {
    return TRUE;
  }
  return $bad_files;
}