You are here

function advagg_mod_devel_query_put_contents in Advanced CSS/JS Aggregation 7.2

Writes the variables information to a file.

It will be retrieved on demand via AJAX.

1 call to advagg_mod_devel_query_put_contents()
advagg_mod_devel_shutdown_query in advagg_mod/advagg_mod.module
Returns the rendered query log.

File

advagg_mod/advagg_mod.module, line 3805
Advanced aggregation modifier module.

Code

function advagg_mod_devel_query_put_contents($queries) {
  $request_id = mt_rand(1, 1000000);
  $path = "temporary://devel_querylog";

  // Create the devel_querylog within the temp folder, if needed.
  file_prepare_directory($path, FILE_CREATE_DIRECTORY);

  // Occasionally wipe the querylog dir so that files don't accumulate.
  if (mt_rand(1, 1000) == 401) {
    devel_empty_dir($path);
  }
  $path .= "/{$request_id}.txt";
  $path = file_stream_wrapper_uri_normalize($path);

  // Save queries as a json array. Suppress errors due to recursion.
  $options = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT;
  if (version_compare(PHP_VERSION, '5.5.0', '>=')) {
    $options |= JSON_PARTIAL_OUTPUT_ON_ERROR;
  }
  if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
    $options |= JSON_PRETTY_PRINT;
  }

  // Prevent empty json data due to recursion.
  $depth = 32;
  $json_data = FALSE;
  while (empty($json_data) && $depth > 0) {
    $json_data = @json_encode($queries, $options, $depth);
    $depth--;
  }
  file_put_contents($path, $json_data);
  $settings['devel'] = array(
    // A random string that is sent to the browser.
    // It enables the AJAX to retrieve queries from this request.
    'request_id' => $request_id,
  );
  $inline = 'jQuery.extend(Drupal.settings, ' . json_encode($settings) . ');';
  if (variable_get('advagg_mod_js_defer', ADVAGG_MOD_JS_DEFER) || variable_get('advagg_mod_js_async', ADVAGG_MOD_JS_ASYNC)) {
    $matches[2] = $matches[0] = $inline;
    $inline = advagg_mod_wrap_inline_js($matches);
  }
  $options = array(
    'type' => 'inline',
  );
  $options += drupal_js_defaults($inline);
  $scripts_array = array(
    '#type' => 'scripts',
    '#items' => array(
      $options,
    ),
  );
  $scripts = drupal_render($scripts_array);
  print $scripts;
}