Projet

Général

Profil

Révision 27e02aed

Ajouté par Assos Assos il y a plus de 4 ans

-a

Voir les différences:

drupal7/includes/common.inc
760 760
 *   (optional) An array that can have one or more of the following elements:
761 761
 *   - headers: An array containing request headers to send as name/value pairs.
762 762
 *   - method: A string containing the request method. Defaults to 'GET'.
763
 *   - data: A string containing the request body, formatted as
764
 *     'param=value&param=value&...'; to generate this, use http_build_query().
765
 *     Defaults to NULL.
763
 *   - data: An array containing the values for the request body or a string
764
 *     containing the request body, formatted as
765
 *     'param=value&param=value&...'; to generate this, use
766
 *     drupal_http_build_query(). Defaults to NULL.
766 767
 *   - max_redirects: An integer representing how many times a redirect
767 768
 *     may be followed. Defaults to 3.
768 769
 *   - timeout: A float representing the maximum number of seconds the function
......
788 789
 *     easy access the array keys are returned in lower case.
789 790
 *   - data: A string containing the response body that was received.
790 791
 *
791
 * @see http_build_query()
792
 * @see drupal_http_build_query()
792 793
 */
793 794
function drupal_http_request($url, array $options = array()) {
794 795
  // Allow an alternate HTTP client library to replace Drupal's default
......
930 931
    $path .= '?' . $uri['query'];
931 932
  }
932 933

  
934
  // Convert array $options['data'] to query string.
935
  if (is_array($options['data'])) {
936
    $options['data'] = drupal_http_build_query($options['data']);
937
  }
938

  
933 939
  // Only add Content-Length if we actually have any content or if it is a POST
934 940
  // or PUT request. Some non-standard servers get confused by Content-Length in
935 941
  // at least HEAD/GET requests, and Squid always requires Content-Length in
......
4441 4447
    }
4442 4448
  }
4443 4449

  
4444
  $output = '';
4445
  // The index counter is used to keep aggregated and non-aggregated files in
4446
  // order by weight.
4447
  $index = 1;
4448
  $processed = array();
4449
  $files = array();
4450
  // Sort the JavaScript so that it appears in the correct order.
4451
  uasort($items, 'drupal_sort_css_js');
4452

  
4453
  // Provide the page with information about the individual JavaScript files
4454
  // used, information not otherwise available when aggregation is enabled.
4455
  $setting['ajaxPageState']['js'] = array_fill_keys(array_keys($items), 1);
4456
  unset($setting['ajaxPageState']['js']['settings']);
4457
  drupal_add_js($setting, 'setting');
4458

  
4459
  // If we're outputting the header scope, then this might be the final time
4460
  // that drupal_get_js() is running, so add the setting to this output as well
4461
  // as to the drupal_add_js() cache. If $items['settings'] doesn't exist, it's
4462
  // because drupal_get_js() was intentionally passed a $javascript argument
4463
  // stripped off settings, potentially in order to override how settings get
4464
  // output, so in this case, do not add the setting to this output.
4465
  if ($scope == 'header' && isset($items['settings'])) {
4466
    $items['settings']['data'][] = $setting;
4467
  }
4468

  
4469
  $elements = array(
4470
    '#type' => 'scripts',
4471
    '#items' => $items,
4472
  );
4473

  
4474
  return drupal_render($elements);
4475
}
4476

  
4477
/**
4478
 * The #pre_render callback for the "scripts" element.
4479
 *
4480
 * This callback adds elements needed for <script> tags to be rendered.
4481
 *
4482
 * @param array $elements
4483
 *   A render array containing:
4484
 *   - '#items': The JS items as returned by drupal_add_js() and altered by
4485
 *     drupal_get_js().
4486
 *
4487
 * @return array
4488
 *   The $elements variable passed as argument with two more children keys:
4489
 *     - "scripts": contains the Javascript items
4490
 *     - "settings": contains the Javascript settings items.
4491
 *   If those keys are already existing, then the items will be appended and
4492
 *   their keys will be preserved.
4493
 *
4494
 * @see drupal_get_js()
4495
 * @see drupal_add_js()
4496
 */
4497
function drupal_pre_render_scripts(array $elements) {
4450 4498
  $preprocess_js = (variable_get('preprocess_js', FALSE) && (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update'));
4451 4499

  
4452 4500
  // A dummy query-string is added to filenames, to gain control over
......
4467 4515
  // third-party code might require the use of a different query string.
4468 4516
  $js_version_string = variable_get('drupal_js_version_query_string', 'v=');
4469 4517

  
4470
  // Sort the JavaScript so that it appears in the correct order.
4471
  uasort($items, 'drupal_sort_css_js');
4518
  $files = array();
4472 4519

  
4473
  // Provide the page with information about the individual JavaScript files
4474
  // used, information not otherwise available when aggregation is enabled.
4475
  $setting['ajaxPageState']['js'] = array_fill_keys(array_keys($items), 1);
4476
  unset($setting['ajaxPageState']['js']['settings']);
4477
  drupal_add_js($setting, 'setting');
4520
  $scripts = isset($elements['scripts']) ? $elements['scripts'] : array();
4521
  $scripts += array('#weight' => 0);
4478 4522

  
4479
  // If we're outputting the header scope, then this might be the final time
4480
  // that drupal_get_js() is running, so add the setting to this output as well
4481
  // as to the drupal_add_js() cache. If $items['settings'] doesn't exist, it's
4482
  // because drupal_get_js() was intentionally passed a $javascript argument
4483
  // stripped off settings, potentially in order to override how settings get
4484
  // output, so in this case, do not add the setting to this output.
4485
  if ($scope == 'header' && isset($items['settings'])) {
4486
    $items['settings']['data'][] = $setting;
4487
  }
4523
  $settings = isset($elements['settings']) ? $elements['settings'] : array();
4524
  $settings += array('#weight' => $scripts['#weight'] + 10);
4525

  
4526
  // The index counter is used to keep aggregated and non-aggregated files in
4527
  // order by weight. Use existing scripts count as a starting point.
4528
  $index = count(element_children($scripts)) + 1;
4488 4529

  
4489 4530
  // Loop through the JavaScript to construct the rendered output.
4490 4531
  $element = array(
4532
    '#type' => 'html_tag',
4491 4533
    '#tag' => 'script',
4492 4534
    '#value' => '',
4493 4535
    '#attributes' => array(
4494 4536
      'type' => 'text/javascript',
4495 4537
    ),
4496 4538
  );
4497
  foreach ($items as $item) {
4539

  
4540
  foreach ($elements['#items'] as $item) {
4498 4541
    $query_string =  empty($item['version']) ? $default_query_string : $js_version_string . $item['version'];
4499 4542

  
4500 4543
    switch ($item['type']) {
......
4503 4546
        $js_element['#value_prefix'] = $embed_prefix;
4504 4547
        $js_element['#value'] = 'jQuery.extend(Drupal.settings, ' . drupal_json_encode(drupal_array_merge_deep_array($item['data'])) . ");";
4505 4548
        $js_element['#value_suffix'] = $embed_suffix;
4506
        $output .= theme('html_tag', array('element' => $js_element));
4549
        $settings[] = $js_element;
4507 4550
        break;
4508 4551

  
4509 4552
      case 'inline':
......
4514 4557
        $js_element['#value_prefix'] = $embed_prefix;
4515 4558
        $js_element['#value'] = $item['data'];
4516 4559
        $js_element['#value_suffix'] = $embed_suffix;
4517
        $processed[$index++] = theme('html_tag', array('element' => $js_element));
4560
        $scripts[$index++] = $js_element;
4518 4561
        break;
4519 4562

  
4520 4563
      case 'file':
......
4525 4568
          }
4526 4569
          $query_string_separator = (strpos($item['data'], '?') !== FALSE) ? '&' : '?';
4527 4570
          $js_element['#attributes']['src'] = file_create_url($item['data']) . $query_string_separator . ($item['cache'] ? $query_string : REQUEST_TIME);
4528
          $processed[$index++] = theme('html_tag', array('element' => $js_element));
4571
          $scripts[$index++] = $js_element;
4529 4572
        }
4530 4573
        else {
4531 4574
          // By increasing the index for each aggregated file, we maintain
......
4536 4579
          // leading to better front-end performance of a website as a whole.
4537 4580
          // See drupal_add_js() for details.
4538 4581
          $key = 'aggregate_' . $item['group'] . '_' . $item['every_page'] . '_' . $index;
4539
          $processed[$key] = '';
4582
          $scripts[$key] = '';
4540 4583
          $files[$key][$item['data']] = $item;
4541 4584
        }
4542 4585
        break;
......
4548 4591
          $js_element['#attributes']['defer'] = 'defer';
4549 4592
        }
4550 4593
        $js_element['#attributes']['src'] = $item['data'];
4551
        $processed[$index++] = theme('html_tag', array('element' => $js_element));
4594
        $scripts[$index++] = $js_element;
4552 4595
        break;
4553 4596
    }
4554 4597
  }
......
4563 4606
        $preprocess_file = file_create_url($uri);
4564 4607
        $js_element = $element;
4565 4608
        $js_element['#attributes']['src'] = $preprocess_file;
4566
        $processed[$key] = theme('html_tag', array('element' => $js_element));
4609
        $scripts[$key] = $js_element;
4567 4610
      }
4568 4611
    }
4569 4612
  }
4570 4613

  
4571
  // Keep the order of JS files consistent as some are preprocessed and others are not.
4572
  // Make sure any inline or JS setting variables appear last after libraries have loaded.
4573
  return implode('', $processed) . $output;
4614
  // Keep the order of JS files consistent as some are preprocessed and others
4615
  // are not. Make sure any inline or JS setting variables appear last after
4616
  // libraries have loaded.
4617
  $element['scripts'] = $scripts;
4618
  $element['settings'] = $settings;
4619

  
4620
  return $element;
4574 4621
}
4575 4622

  
4576 4623
/**
......
6952 6999
      'variables' => array(),
6953 7000
    ),
6954 7001
    'table' => array(
6955
      'variables' => array('header' => NULL, 'rows' => NULL, 'attributes' => array(), 'caption' => NULL, 'colgroups' => array(), 'sticky' => TRUE, 'empty' => ''),
7002
      'variables' => array(
7003
        'header' => NULL,
7004
        'footer' => NULL,
7005
        'rows' => NULL,
7006
        'attributes' => array(),
7007
        'caption' => NULL,
7008
        'colgroups' => array(),
7009
        'sticky' => TRUE,
7010
        'empty' => '',
7011
      ),
6956 7012
    ),
6957 7013
    'tablesort_indicator' => array(
6958 7014
      'variables' => array('style' => NULL),

Formats disponibles : Unified diff