Package base :: Package includes :: Module bootstrap
[hide private]

Module bootstrap

source code

Functions that need to be loaded on every Drupal requst
See Also:
Drupy Homepage, Drupal Homepage
Notes:

Author: Brendon Crawford

Copyright: 2008 Brendon Crawford

Contact: message144 at users dot sourceforge dot net

Version: 0.1

Functions [hide private]
 
timer_start(name)
Start the timer with the specified name.
source code
 
timer_read(name)
Read the current timer value without stopping the timer.
source code
 
timer_stop(name)
Stop the timer with the specified name.
source code
 
conf_path(require_settings=True, reset=False)
Find the appropriate configuration directory.
source code
 
drupal_unset_globals()
Unsets all disallowed global variables.
source code
 
conf_init()
Loads the configuration and sets the base URL, cookie domain, and session name correctly.
source code
 
drupal_get_filename(type_, name, filename=None)
Returns and optionally sets the filename for a system item (plugin, theme, etc.).
source code
 
variable_init(conf_={})
Load the persistent variable table.
source code
 
variable_get(name, default_)
Return a persistent variable.
source code
 
variable_set(name, value)
Set a persistent variable.
source code
 
variable_del(name)
Unset a persistent variable.
source code
 
page_get_cache()
Retrieve the current page from the cache.
source code
 
invoke_all(hook)
Call all init or exit hooks without including all plugins.
source code
 
drupal_load(type_, name)
Includes a file with the provided type and name.
source code
 
drupal_page_header()
Set HTTP headers in preparation for a page response.
source code
 
drupal_page_cache_header(cache)
Set HTTP headers in preparation for a cached page response.
source code
 
hooks()
Define the critical hooks that force plugins to always be loaded.
source code
 
drupal_unpack(obj, field='data')
Unserializes and appends elements from a serialized string.
source code
 
referer_uri()
Return the URI of the referring page.
source code
 
check_plain(text)
Encode special characters in a plain-text string for display as HTML.
source code
 
drupal_validate_utf8(text)
Checks whether a string is valid UTF-8.
source code
 
request_uri()
Since php.SERVER['php.REQUEST_URI'] is only available on Apache, we generate an equivalent using other environment variables.
source code
 
watchdog(type, message, variables=[], severity=5, link=None)
Log a system message.
source code
 
drupal_set_message(message=None, type='status', repeat=True)
Set a message which reflects the status of the performed operation.
source code
 
drupal_get_messages(type=None, clear_queue=True)
Return all messages that have been set.
source code
 
drupal_is_denied(ip)
Check to see if an IP address has been blocked.
source code
 
drupal_anonymous_user(session='')
Generates a default anonymous user object.
source code
 
drupal_bootstrap(phase)
A string describing a phase of Drupal to load.
source code
 
_drupal_bootstrap(phase) source code
 
drupal_maintenance_theme()
Enables use of the theme system without requiring database access.
source code
 
get_t()
Return the name of the localisation function.
source code
 
drupal_init_language()
Choose a language for the current page, based on site and user preferences.
source code
 
language_list(field='language', reset=False)
Get a list of languages set up indexed by the specified key
source code
 
language_default(property=None)
Default language used on the site
source code
 
ip_address(reset=False)
If Drupal is behind a reverse proxy, we use the X-Forwarded-For header instead of $_SERVER['REMOTE_ADDR'], which would be the IP address of the proxy server, and not the client's.
source code
 
drupal_function_exists(function, scope=None)
Confirm that a function is available.
source code
 
drupal_autoload_interface(interface)
Confirm that an interface is available.
source code
 
drupal_autoload_class(class_)
Confirm that a class is available.
source code
 
_registry_check_code(type_, name)
Helper for registry_check_{interface, class}.
source code
 
registry_mark_code(type_, name, return_=False)
Collect the resources used for this request.
source code
 
registry_rebuild()
Rescan all enabled plugins and rebuild the registry.
source code
 
registry_cache_hook_implementations(hook, write_to_persistent_cache=False)
Save hook implementations cache.
source code
 
registry_cache_path_files()
Save the files required by the registry for this path.
source code
 
registry_load_path_files(return_=False)
registry_load_path_files
source code
 
registry_get_hook_implementations_cache()
registry_get_hook_implementations_cache
source code
Variables [hide private]
  __version__ = '$Revision: 1 $'
  MAINTENANCE_MODE = False
  CACHE_PERMANENT = 0
  CACHE_TEMPORARY = -1
  CACHE_DISABLED = 0
  CACHE_NORMAL = 1
  CACHE_AGGRESSIVE = 2
  WATCHDOG_ALERT = 1
  WATCHDOG_CRITICAL = 2
  WATCHDOG_ERROR = 3
  WATCHDOG_WARNING = 4
  WATCHDOG_NOTICE = 5
  WATCHDOG_INFO = 6
  WATCHDOG_DEBUG = 7
  DRUPAL_BOOTSTRAP_CONFIGURATION = 0
  DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE = 1
  DRUPAL_BOOTSTRAP_DATABASE = 2
  DRUPAL_BOOTSTRAP_ACCESS = 3
  DRUPAL_BOOTSTRAP_SESSION = 4
  DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE = 5
  DRUPAL_BOOTSTRAP_LANGUAGE = 6
  DRUPAL_BOOTSTRAP_PATH = 7
  DRUPAL_BOOTSTRAP_FULL = 8
  DRUPAL_ANONYMOUS_RID = 9
  DRUPAL_AUTHENTICATED_RID = 10
  LANGUAGE_NEGOTIATION_NONE = 0
  LANGUAGE_NEGOTIATION_PATH_DEFAULT = 1
  LANGUAGE_NEGOTIATION_PATH = 2
  LANGUAGE_NEGOTIATION_DOMAIN = 3
Function Details [hide private]

timer_start(name)

source code 
Start the timer with the specified name. If you start and stop the same timer multiple times, the measured intervals will be accumulated.
Parameters:
  • name - The name of the timer.

timer_read(name)

source code 
Read the current timer value without stopping the timer.
Parameters:
  • name - The name of the timer.
Returns:
The current timer value in ms.

timer_stop(name)

source code 
Stop the timer with the specified name.
Parameters:
  • name - The name of the timer.
Returns:
A timer array. The array contains the number of times the timer has been started and stopped (count) and the accumulated timer value in ms (time).

conf_path(require_settings=True, reset=False)

source code 
Find the appropriate configuration directory. Try finding a matching configuration directory by stripping the website's hostname from left to right and pathname from right to left. The first configuration file found will be used; the remaining will ignored. If no configuration file is found, return a default value 'confdir/default'. Example for a fictitious site installed at http://www.drupal.org:8080/mysite/test/ the 'settings.php' is searched in the following directories: 1. confdir/8080.www.drupal.org.mysite.test 2. confdir/www.drupal.org.mysite.test 3. confdir/drupal.org.mysite.test 4. confdir/org.mysite.test 5. confdir/8080.www.drupal.org.mysite 6. confdir/www.drupal.org.mysite 7. confdir/drupal.org.mysite 8. confdir/org.mysite 9. confdir/8080.www.drupal.org 10. confdir/www.drupal.org 11. confdir/drupal.org 12. confdir/org 13. confdir/default
Parameters:
  • require_settings - Only configuration directories with an existing settings.php file will be recognized. Defaults to TRUE. During initial installation, this is set to FALSE so that Drupal can detect a matching directory, then create a new settings.php file in it.
  • reset - Force a full search for matching directories even if one had been found previously.
Returns:
The path of the matching directory.

drupal_unset_globals()

source code 
Unsets all disallowed global variables. See allowed for what's allowed.

drupal_get_filename(type_, name, filename=None)

source code 
Returns and optionally sets the filename for a system item (plugin, theme, etc.). The filename, whether provided, cached, or retrieved from the database, is only returned if the file exists. This def plays a key role in allowing Drupal's resources (plugins and themes) to be located in different places depending on a site's configuration. For example, a plugin 'foo' may legally be be located in any of these three places: plugins/foo/__init__.py sites/all/plugins/foo/__init__.py sites/example.com/plugins/foo/__init__.py Calling drupal_get_filename('plugin', 'foo') will give you one of the above, depending on where the plugin is located.
Parameters:
  • type - The type of the item (i.e. theme, theme_engine, plugin).
  • 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.
Returns:
The filename of the requested item.

variable_init(conf_={})

source code 
Load the persistent variable table. The variable table is composed of values that have been saved in the table with variable_set() as well as those explicitly specified in the configuration file.

variable_get(name, default_)

source code 
Return a persistent variable.
Parameters:
  • name - The name of the variable to return.
  • default - The default value to use if this variable has never been set.
Returns:
The value of the variable.

variable_set(name, value)

source code 
Set a persistent variable.
Parameters:
  • name - The name of the variable to set.
  • value - The value to set. This can be any PHP data type; these functions take care of serialization as necessary.

variable_del(name)

source code 
Unset a persistent variable.
Parameters:
  • name - The name of the variable to undefine.

page_get_cache()

source code 
Retrieve the current page from the cache. Note: we do not serve cached pages when status messages are waiting (from a redirected form submission which was completed).
Parameters:
  • status_only - When set to TRUE, retrieve the status of the page cache only (whether it was started in this request or not).

invoke_all(hook)

source code 
Call all init or exit hooks without including all plugins.
Parameters:
  • hook - The name of the bootstrap hook we wish to invoke.

drupal_load(type_, name)

source code 
Includes a file with the provided type and name. This prevents including a theme, engine, plugin, etc., more than once.
Parameters:
  • type - The type of item to load (i.e. theme, theme_engine, plugin).
  • name - The name of the item to load.
Returns:
TRUE if the item is loaded or has already been loaded.

drupal_page_header()

source code 
Set HTTP headers in preparation for a page response. Authenticated users are always given a 'no-cache' php.header, and will fetch a fresh page on every request. This prevents authenticated users seeing locally cached pages that show them as logged out.

See Also: page_set_cache

drupal_page_cache_header(cache)

source code 
Set HTTP headers in preparation for a cached page response. The general approach here is that anonymous users can keep a local cache of the page, but must revalidate it on every request. Then, they are given a '304 Not Modified' response as long as they stay logged out and the page has not been modified.

drupal_unpack(obj, field='data')

source code 
Unserializes and appends elements from a serialized string.
Parameters:
  • obj - The object to which the elements are appended.
  • field - The attribute of obj whose value should be unserialized.

check_plain(text)

source code 
Encode special characters in a plain-text string for display as HTML. Uses drupal_validate_utf8 to prevent cross site scripting attacks on Internet Explorer 6.

drupal_validate_utf8(text)

source code 
Checks whether a string is valid UTF-8. All functions designed to filter input should use drupal_validate_utf8 to ensure they operate on valid UTF-8 strings to prevent bypass of the filter. When text containing an invalid UTF-8 lead byte (0xC0 - 0xFF) is presented as UTF-8 to Internet Explorer 6, the program may misinterpret subsequent bytes. When these subsequent bytes are HTML control characters such as quotes or angle brackets, parts of the text that were deemed safe by filters end up in locations that are potentially unsafe; An onerror attribute that is outside of a tag, and thus deemed safe by a filter, can be interpreted by the browser as if it were inside the tag. This def exploits preg_match behaviour (since PHP 4.3.5) when used with the u modifier, as a fast way to find invalid UTF-8. When the matched string contains an invalid byte sequence, it will fail silently. preg_match may not fail on 4 and 5 octet sequences, even though they are not supported by the specification. The specific preg_match behaviour is present since PHP 4.3.5.
Parameters:
  • text - The text to check.
Returns:
TRUE if the text is valid UTF-8, FALSE if not.

watchdog(type, message, variables=[], severity=5, link=None)

source code 
Log a system message.
Parameters:
  • type - The category to which this message belongs.
  • message - The message to store in the log. See t() for documentation on how message and variables interact. Keep message translatable by not concatenating dynamic values into it!
  • variables - Array of variables to replace in the message on display or NULL if message is already translated or not possible to translate.
  • severity - The severity of the message, as per RFC 3164
  • link - A link to associate with the message.

See Also: watchdog_severity_levels

drupal_set_message(message=None, type='status', repeat=True)

source code 
Set a message which reflects the status of the performed operation. If the def is called with no arguments, this def returns all set messages without clearing them.
Parameters:
  • message - The message should begin with a capital letter and always ends with a period '.'.
  • type - The type of the message. One of the following values are possible: - 'status' - 'warning' - 'error'
  • repeat - If this is FALSE and the message is already set, then the message won't be repeated.

drupal_get_messages(type=None, clear_queue=True)

source code 
Return all messages that have been set.
Parameters:
  • type - (optional) Only return messages of this type.
  • clear_queue - (optional) Set to FALSE if you do not want to clear the messages queue
Returns:
An associative array, the key is the message type, the value an array of messages. If the type parameter is passed, you get only that type, or an empty array if there are no such messages. If type is not passed, all message types are returned, or an empty array if none exist.

drupal_is_denied(ip)

source code 
Check to see if an IP address has been blocked. Blocked IP addresses are stored in the database by default. However for performance reasons we allow an override in settings.php. This allows us to avoid querying the database at this critical stage of the bootstrap if an administrative interface for IP address blocking is not required.
Parameters:
  • $ip - string IP address to check.
Returns:
bool TRUE if access is denied, FALSE if access is allowed.

drupal_anonymous_user(session='')

source code 
Generates a default anonymous user object.
Returns:
Object - the user object.

drupal_bootstrap(phase)

source code 
A string describing a phase of Drupal to load. Each phase adds to the previous one, so invoking a later phase automatically runs the earlier phases too. The most important usage is that if you want to access the Drupal database from a script without loading anything else, you can include bootstrap.inc, and call drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE).
Parameters:
  • phase - A constant. Allowed values are: DRUPAL_BOOTSTRAP_CONFIGURATION: initialize configuration. DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE: try to call a non-database cache fetch routine. DRUPAL_BOOTSTRAP_DATABASE: initialize database layer. DRUPAL_BOOTSTRAP_ACCESS: identify and reject banned hosts. DRUPAL_BOOTSTRAP_SESSION: initialize session handling. DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE: load bootstrap.inc and plugin.inc, start the variable system and try to serve a page from the cache. DRUPAL_BOOTSTRAP_LANGUAGE: identify the language used on the page. DRUPAL_BOOTSTRAP_PATH: set php.GET['q'] to Drupal path of request. DRUPAL_BOOTSTRAP_FULL: Drupal is fully loaded, validate and fix input data.

drupal_maintenance_theme()

source code 
Enables use of the theme system without requiring database access. Loads and initializes the theme system for site installs, updates and when the site is in offline mode. This also applies when the database fails.

See Also: _drupal_maintenance_theme

get_t()

source code 
Return the name of the localisation function. Use in code that needs to run both during installation and normal operation.

language_list(field='language', reset=False)

source code 
Get a list of languages set up indexed by the specified key
Parameters:
  • field - The field to index the list with.
  • reset - Boolean to request a reset of the list.

language_default(property=None)

source code 
Default language used on the site
Parameters:
  • property - Optional property of the language object to return

ip_address(reset=False)

source code 
If Drupal is behind a reverse proxy, we use the X-Forwarded-For header instead of $_SERVER['REMOTE_ADDR'], which would be the IP address of the proxy server, and not the client's. If Drupal is run in a cluster we use the X-Cluster-Client-Ip header instead.
Parameters:
  • $reset - Reset the current IP address saved in static.
Returns:
IP address of client machine, adjusted for reverse proxy and/or cluster environments.

drupal_function_exists(function, scope=None)

source code 
Confirm that a function is available. If the function is already available, this function does nothing. If the function is not available, it tries to load the file where the function lives. If the file is not available, it returns False, so that it can be used as a drop-in replacement for php.function_exists(). DRUPY(BC): This function needs to be heavily modified
Parameters:
  • function - The name of the function to check or load.
  • scope - Scope to check
Returns:
True if the function is now available, False otherwise.

drupal_autoload_interface(interface)

source code 
Confirm that an interface is available. This function parallels drupal_function_exists(), but is rarely called directly. Instead, it is registered as an spl_autoload() handler, and PHP calls it for us when necessary.
Parameters:
  • interface - The name of the interface to check or load.
Returns:
True if the interface is currently available, False otherwise.

drupal_autoload_class(class_)

source code 
Confirm that a class is available. This function parallels drupal_function_exists(), but is rarely called directly. Instead, it is registered as an spl_autoload() handler, and PHP calls it for us when necessary.
Parameters:
  • class - The name of the class to check or load.
Returns:
True if the class is currently available, False otherwise.

registry_mark_code(type_, name, return_=False)

source code 
Collect the resources used for this request.
Parameters:
  • type - The type of resource.
  • name - The name of the resource.
  • return - Boolean flag to indicate whether to return the resources.

registry_rebuild()

source code 
Rescan all enabled plugins and rebuild the registry. Rescans all code in plugins or includes directory, storing a mapping of each function, file, and hook implementation in the database.

registry_cache_hook_implementations(hook, write_to_persistent_cache=False)

source code 
Save hook implementations cache.
Parameters:
  • hook - Array with the hook name and list of plugins that implement it.
  • write_to_persistent_cache - Whether to write to the persistent cache.