drupal_get_filename

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

includes/bootstrap.inc, строка 373

Версии
5 – 6
drupal_get_filename($type, $name, $filename = NULL)

Returns and optionally sets the filename for a system item (module, theme, etc.). The filename, whether provided, cached, or retrieved from the database, is only returned if the file exists.

This function plays a key role in allowing Drupal's resources (modules and themes) to be located in different places depending on a site's configuration. For example, a module 'foo' may legally be be located in any of these three places:

modules/foo/foo.module sites/all/modules/foo/foo.module sites/example.com/modules/foo/foo.module

Calling drupal_get_filename('module', 'foo') will give you one of the above, depending on where the module is located.

Параметры

$type Типа элемента (напр., тема, движок темизации, модуль).

$name The name of the item for which the filename is requested.

$filename The filename of the item if it is to be set explicitly rather than by consulting the database.

Возвращаемое значение

The filename of the requested item.

▾ 6 функции вызывают drupal_get_filename()

drupal_get_path in includes/common.inc
Возвращает адрес системного элемента (модуль, тема и т.п.)
drupal_install_profile in includes/install.inc
Install a profile (i.e. a set of modules) from scratch. The profile must be verified first using drupal_verify_profile().
drupal_load in includes/bootstrap.inc
Includes a file with the provided type and name. This prevents including a theme, engine, module, etc., more than once.
module_list in includes/module.inc
Генерирует список всех загруженных модулей. В ходе инициализации (бутстрапа), возвращает только жизненно важные модули. Смотри bootstrap.inc
system_modules_uninstall_confirm_form in modules/system/system.module
Confirm uninstall of selected modules.
system_theme_data in modules/system/system.module
Collect data about all currently available themes

Код

<?php
function drupal_get_filename($type, $name, $filename = NULL) {
  static $files = array();
  global $active_db;

  if (!isset($files[$type])) {
    $files[$type] = array();
  }

  if (!empty($filename) && file_exists($filename)) {
    $files[$type][$name] = $filename;
  }
  elseif (isset($files[$type][$name])) {
    // nothing
  }
  // Verify that we have an active database connection, before querying
  // the database.  This is required because this function is called both
  // before we have a database connection (i.e. during installation) and
  // when a database connection fails.
  elseif ($active_db && (($file = db_result(db_query("SELECT filename FROM {system} WHERE name = '%s' AND type = '%s'", $name, $type))) && file_exists($file))) {
    $files[$type][$name] = $file;
  }
  else {
    // Fallback to searching the filesystem if the database connection is
    // not established or the requested file is not found.
    $config = conf_path();
    $dir = (($type == 'theme_engine') ? 'themes/engines' : "${type}s");
    $file = (($type == 'theme_engine') ? "$name.engine" : "$name.$type");

    foreach (array("$config/$dir/$file", "$config/$dir/$name/$file", "$dir/$file", "$dir/$name/$file") as $file) {
      if (file_exists($file)) {
        $files[$type][$name] = $file;
        break;
      }
    }
  }

  return $files[$type][$name];
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии

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