drupal_to_js

Хочешь помочь с переводом? Это очень просто и быстро. Лишь зарегистрируйся, и можешь тут же начать переводить.

includes/common.inc, строка 2396

Версии
5 – 6
drupal_to_js($var)

Преобразует переменную на PHP в её JavaScript'овый эквивалент.

Мы используем безопасные для HTML строки, то есть с экранированными <, > и &.

▾ 7 функции вызывают drupal_to_js()

drupal_get_js in includes/common.inc
Returns a themed presentation of all JavaScript code for the current page.
drupal_json in includes/common.inc
Возвращает данные в формате JSON.
drupal_to_js in includes/common.inc
Преобразует переменную на PHP в её JavaScript'овый эквивалент.
profile_admin_settings_autocomplete in modules/profile/profile.admin.inc
Retrieve a pipe delimited string of autocomplete suggestions for profile categories
system_date_time_lookup in modules/system/system.admin.inc
Возвращает даты для данного формата строки с помощью AJAX.
upload_js in modules/upload/upload.module
Коллбэк меню для JavaScript загрузок файлов.
_locale_rebuild_js in includes/locale.inc
Создает(заменяет) JavaScript-файл перевода для указанного языка.

Код

<?php
function drupal_to_js($var) {
  switch (gettype($var)) {
    case 'boolean':
      return $var ? 'true' : 'false'; // Lowercase necessary!
    case 'integer':
    case 'double':
      return $var;
    case 'resource':
    case 'string':
      return '"'. str_replace(array("\r", "\n", "<", ">", "&"),
                              array('\r', '\n', '\x3c', '\x3e', '\x26'),
                              addslashes($var)) .'"';
    case 'array':
      // Arrays in JSON can't be associative. If the array is empty or if it
      // has sequential whole number keys starting with 0, it's not associative
      // so we can go ahead and convert it as an array.
      if (empty ($var) || array_keys($var) === range(0, sizeof($var) - 1)) {
        $output = array();
        foreach ($var as $v) {
          $output[] = drupal_to_js($v);
        }
        return '[ '. implode(', ', $output) .' ]';
      }
      // Otherwise, fall through to convert the array as an object.
    case 'object':
      $output = array();
      foreach ($var as $k => $v) {
        $output[] = drupal_to_js(strval($k)) .': '. drupal_to_js($v);
      }
      return '{ '. implode(', ', $output) .' }';
    default:
      return 'null';
  }
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии

Вход в систему