/apis/6/core.php
PHP | 2452 lines | 790 code | 114 blank | 1548 comment | 111 complexity | a744f8ff9ecb90db26d8697040aaf1bc MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- <?php
- // $Id: core.php,v 1.168.2.64 2009/06/29 20:25:15 jhodgdon Exp $
- /**
- * @file
- * These are the hooks that are invoked by the Drupal core.
- *
- * Core hooks are typically called in all modules at once using
- * module_invoke_all().
- */
- /**
- * @addtogroup hooks
- * @{
- */
- /**
- * Declare information about one or more Drupal actions.
- *
- * Any module can define any number of Drupal actions. The trigger module is an
- * example of a module that uses actions. An action consists of two or three
- * parts: (1) an action definition (returned by this hook), (2) a function which
- * does the action (which by convention is named module + '_' + description of
- * what the function does + '_action'), and an optional form definition
- * function that defines a configuration form (which has the name of the action
- * with '_form' appended to it.)
- *
- * @return
- * - An array of action descriptions. Each action description is an associative
- * array, where the key of the item is the action's function, and the
- * following key-value pairs:
- * - 'type': (required) the type is determined by what object the action
- * acts on. Possible choices are node, user, comment, and system. Or
- * whatever your own custom type is. So, for the nodequeue module, the
- * type might be set to 'nodequeue' if the action would be performed on a
- * nodequeue.
- * - 'description': (required) The human-readable name of the action.
- * - 'configurable': (required) If FALSE, then the action doesn't require
- * any extra configuration. If TRUE, then you should define a form
- * function with the same name as the key, but with '_form' appended to
- * it (i.e., the form for 'node_assign_owner_action' is
- * 'node_assign_owner_action_form'.)
- * This function will take the $context as the only parameter, and is
- * paired with the usual _submit function, and possibly a _validate
- * function.
- * - 'hooks': (required) An array of all of the operations this action is
- * appropriate for, keyed by hook name. The trigger module uses this to
- * filter out inappropriate actions when presenting the interface for
- * assigning actions to events. If you are writing actions in your own
- * modules and you simply want to declare support for all possible hooks,
- * you can set 'hooks' => array('any' => TRUE). Common hooks are 'user',
- * 'nodeapi', 'comment', or 'taxonomy'. Any hook that has been described
- * to Drupal in hook_hook_info() will work is a possiblity.
- * - 'behavior': (optional) Human-readable array of behavior descriptions.
- * The only one we have now is 'changes node property'. You will almost
- * certainly never have to return this in your own implementations of this
- * hook.
- *
- * The function that is called when the action is triggered is passed two
- * parameters - an object of the same type as the 'type' value of the
- * hook_action_info array, and a context variable that contains the context
- * under which the action is currently running, sent as an array. For example,
- * the actions module sets the 'hook' and 'op' keys of the context array (so,
- * 'hook' may be 'nodeapi' and 'op' may be 'insert').
- */
- function hook_action_info() {
- return array(
- 'comment_unpublish_action' => array(
- 'description' => t('Unpublish comment'),
- 'type' => 'comment',
- 'configurable' => FALSE,
- 'hooks' => array(
- 'comment' => array('insert', 'update'),
- )
- ),
- 'comment_unpublish_by_keyword_action' => array(
- 'description' => t('Unpublish comment containing keyword(s)'),
- 'type' => 'comment',
- 'configurable' => TRUE,
- 'hooks' => array(
- 'comment' => array('insert', 'update'),
- )
- )
- );
- }
- /**
- * Execute code after an action is deleted.
- *
- * @param $aid
- * The action ID.
- */
- function hook_actions_delete($aid) {
- db_query("DELETE FROM {actions_assignments} WHERE aid = '%s'", $aid);
- }
- /**
- * Alter the actions declared by another module.
- *
- * Called by actions_list() to allow modules to alter the return
- * values from implementations of hook_action_info().
- *
- * @see trigger_example_action_info_alter().
- */
- function hook_action_info_alter(&$actions) {
- $actions['node_unpublish_action']['description'] = t('Unpublish and remove from public view.');
- }
- /**
- * Declare a block or set of blocks.
- *
- * Any module can export a block (or blocks) to be displayed by defining
- * the _block hook. This hook is called by theme.inc to display a block,
- * and also by block.module to procure the list of available blocks.
- *
- * @param $op
- * What kind of information to retrieve about the block or blocks.
- * Possible values:
- * - 'list': A list of all blocks defined by the module.
- * - 'configure': Configuration form for the block.
- * - 'save': Save the configuration options.
- * - 'view': Process the block when enabled in a region in order to view its contents.
- * @param $delta
- * Which block to return (not applicable if $op is 'list'). Although it is
- * most commonly an integer starting at 0, this is not mandatory. For
- * instance, aggregator.module uses string values for $delta
- * @param $edit
- * If $op is 'save', the submitted form data from the configuration form.
- * @return
- * - If $op is 'list': An array of block descriptions. Each block description
- * is an associative array, with the following key-value pairs:
- * - 'info': (required) The human-readable name of the block.
- * - 'cache': A bitmask of flags describing how the block should behave with
- * respect to block caching. The following shortcut bitmasks are provided
- * as constants in block.module:
- * - BLOCK_CACHE_PER_ROLE (default): The block can change depending on the
- * roles the user viewing the page belongs to.
- * - BLOCK_CACHE_PER_USER: The block can change depending on the user
- * viewing the page. This setting can be resource-consuming for sites
- * with large number of users, and should only be used when
- * BLOCK_CACHE_PER_ROLE is not sufficient.
- * - BLOCK_CACHE_PER_PAGE: The block can change depending on the page
- * being viewed.
- * - BLOCK_CACHE_GLOBAL: The block is the same for every user on every
- * page where it is visible.
- * - BLOCK_NO_CACHE: The block should not get cached.
- * - 'weight', 'status', 'region', 'visibility', 'pages':
- * You can give your blocks an explicit weight, enable them, limit them to
- * given pages, etc. These settings will be registered when the block is first
- * loaded at admin/block, and from there can be changed manually via block
- * administration.
- * Note that if you set a region that isn't available in a given theme, the
- * block will be registered instead to that theme's default region (the first
- * item in the _regions array).
- * - If $op is 'configure': optionally return the configuration form.
- * - If $op is 'save': return nothing.
- * - If $op is 'view': return an array which must define a 'subject' element
- * and a 'content' element defining the block indexed by $delta.
- *
- * The functions mymodule_display_block_1 and 2, as used in the example,
- * should of course be defined somewhere in your module and return the
- * content you want to display to your users. If the "content" element
- * is empty, no block will be displayed even if "subject" is present.
- *
- * After completing your blocks, do not forget to enable them in the
- * block admin menu.
- *
- * For a detailed usage example, see block_example.module.
- */
- function hook_block($op = 'list', $delta = 0, $edit = array()) {
- if ($op == 'list') {
- $blocks[0] = array('info' => t('Mymodule block #1 shows ...'),
- 'weight' => 0, 'status' => 1, 'region' => 'left');
- // BLOCK_CACHE_PER_ROLE will be assumed for block 0.
- $blocks[1] = array('info' => t('Mymodule block #2 describes ...'),
- 'cache' => BLOCK_CACHE_PER_ROLE | BLOCK_CACHE_PER_PAGE);
- return $blocks;
- }
- else if ($op == 'configure' && $delta == 0) {
- $form['items'] = array(
- '#type' => 'select',
- '#title' => t('Number of items'),
- '#default_value' => variable_get('mymodule_block_items', 0),
- '#options' => array('1', '2', '3'),
- );
- return $form;
- }
- else if ($op == 'save' && $delta == 0) {
- variable_set('mymodule_block_items', $edit['items']);
- }
- else if ($op == 'view') {
- switch($delta) {
- case 0:
- $block = array('subject' => t('Title of block #1'),
- 'content' => mymodule_display_block_1());
- break;
- case 1:
- $block = array('subject' => t('Title of block #2'),
- 'content' => mymodule_display_block_2());
- break;
- }
- return $block;
- }
- }
- /**
- * Act on comments.
- *
- * This hook allows modules to extend the comments system.
- *
- * @param $a1
- * Dependent on the action being performed.
- * - For "validate","update","insert", passes in an array of form values submitted by the user.
- * - For all other operations, passes in the comment the action is being performed on.
- * @param $op
- * What kind of action is being performed. Possible values:
- * - "insert": The comment is being inserted.
- * - "update": The comment is being updated.
- * - "view": The comment is being viewed. This hook can be used to add additional data to the comment before theming.
- * - "validate": The user has just finished editing the comment and is
- * trying to preview or submit it. This hook can be used to check or
- * even modify the node. Errors should be set with form_set_error().
- * - "publish": The comment is being published by the moderator.
- * - "unpublish": The comment is being unpublished by the moderator.
- * - "delete": The comment is being deleted by the moderator.
- * @return
- * Dependent on the action being performed.
- * - For all other operations, nothing.
- */
- function hook_comment(&$a1, $op) {
- if ($op == 'insert' || $op == 'update') {
- $nid = $a1['nid'];
- }
- cache_clear_all_like(drupal_url(array('id' => $nid)));
- }
- /**
- * Perform periodic actions.
- *
- * Modules that require to schedule some commands to be executed at regular
- * intervals can implement hook_cron(). The engine will then call the hook
- * at the appropriate intervals defined by the administrator. This interface
- * is particularly handy to implement timers or to automate certain tasks.
- * Database maintenance, recalculation of settings or parameters, and
- * automatic mailings are good candidates for cron tasks.
- *
- * @return
- * None.
- *
- * This hook will only be called if cron.php is run (e.g. by crontab).
- */
- function hook_cron() {
- $result = db_query('SELECT * FROM {site} WHERE checked = 0 OR checked
- + refresh < %d', time());
- while ($site = db_fetch_array($result)) {
- cloud_update($site);
- }
- }
- /**
- * Expose a list of triggers (events) that your module is allowing users to
- * assign actions to.
- *
- * This hook is used by the Triggers API to present information about triggers
- * (or events) that your module allows users to assign actions to.
- *
- * See also hook_action_info().
- *
- * @return
- * - A nested array. The outermost key defines the module that the triggers
- * are from. The menu system will use the key to look at the .info file of
- * the module and make a local task (a tab) in the trigger UI.
- * - The next key defines the hook being described.
- * - Inside of that array are a list of arrays keyed by hook operation.
- * - Each of those arrays have a key of 'runs when' and a value which is
- * an English description of the hook.
- *
- * For example, the node_hook_info implementation has 'node' as the outermost
- * key, as that's the module it's in. Next it has 'nodeapi' as the next key,
- * as hook_nodeapi() is what applies to changes in nodes. Finally the keys
- * after that are the various operations for hook_nodeapi() that the node module
- * is exposing as triggers.
- */
- function hook_hook_info() {
- return array(
- 'node' => array(
- 'nodeapi' => array(
- 'presave' => array(
- 'runs when' => t('When either saving a new post or updating an existing post'),
- ),
- 'insert' => array(
- 'runs when' => t('After saving a new post'),
- ),
- 'update' => array(
- 'runs when' => t('After saving an updated post'),
- ),
- 'delete' => array(
- 'runs when' => t('After deleting a post')
- ),
- 'view' => array(
- 'runs when' => t('When content is viewed by an authenticated user')
- ),
- ),
- ),
- );
- }
- /**
- * Alter the data being saved to the {menu_router} table after hook_menu is invoked.
- *
- * This hook is invoked by menu_router_build(). The menu definitions are passed
- * in by reference. Each element of the $items array is one item returned
- * by a module from hook_menu. Additional items may be added, or existing items
- * altered.
- *
- * @param $items
- * Associative array of menu router definitions returned from hook_menu().
- * @return
- * None.
- */
- function hook_menu_alter(&$items) {
- // Example - disable the page at node/add
- $items['node/add']['access callback'] = FALSE;
- }
- /**
- * Alter the data being saved to the {menu_links} table by menu_link_save().
- *
- * @param $item
- * Associative array defining a menu link as passed into menu_link_save().
- * @param $menu
- * Associative array containg the menu router returned from menu_router_build().
- * @return
- * None.
- */
- function hook_menu_link_alter(&$item, $menu) {
- // Example 1 - make all new admin links hidden (a.k.a disabled).
- if (strpos($item['link_path'], 'admin') === 0 && empty($item['mlid'])) {
- $item['hidden'] = 1;
- }
- // Example 2 - flag a link to be altered by hook_translated_menu_link_alter()
- if ($item['link_path'] == 'devel/cache/clear') {
- $item['options']['alter'] = TRUE;
- }
- }
- /**
- * Alter a menu link after it's translated, but before it's rendered.
- *
- * This hook may be used, for example, to add a page-specific query string.
- * For performance reasons, only links that have $item['options']['alter'] == TRUE
- * will be passed into this hook. The $item['options']['alter'] flag should
- * generally be set using hook_menu_link_alter().
- *
- * @param $item
- * Associative array defining a menu link after _menu_link_translate()
- * @param $map
- * Associative array containing the menu $map (path parts and/or objects).
- * @return
- * None.
- */
- function hook_translated_menu_link_alter(&$item, $map) {
- if ($item['href'] == 'devel/cache/clear') {
- $item['localized_options']['query'] = drupal_get_destination();
- }
- }
- /**
- * Rewrite database queries, usually for access control.
- *
- * Add JOIN and WHERE statements to queries and decide whether the primary_field
- * shall be made DISTINCT. For node objects, primary field is always called nid.
- * For taxonomy terms, it is tid and for vocabularies it is vid. For comments,
- * it is cid. Primary table is the table where the primary object (node, file,
- * term_node etc.) is.
- *
- * You shall return an associative array. Possible keys are 'join', 'where' and
- * 'distinct'. The value of 'distinct' shall be 1 if you want that the
- * primary_field made DISTINCT.
- *
- * @param $query
- * Query to be rewritten.
- * @param $primary_table
- * Name or alias of the table which has the primary key field for this query.
- * Typical table names would be: {blocks}, {comments}, {forum}, {node},
- * {menu}, {term_data} or {vocabulary}. However, it is more common for
- * $primary_table to contain the usual table alias: b, c, f, n, m, t or v.
- * @param $primary_field
- * Name of the primary field.
- * @param $args
- * Array of additional arguments.
- * @return
- * An array of join statements, where statements, distinct decision.
- */
- function hook_db_rewrite_sql($query, $primary_table, $primary_field, $args) {
- switch ($primary_field) {
- case 'nid':
- // this query deals with node objects
- $return = array();
- if ($primary_table != 'n') {
- $return['join'] = "LEFT JOIN {node} n ON $primary_table.nid = n.nid";
- }
- $return['where'] = 'created >' . mktime(0, 0, 0, 1, 1, 2005);
- return $return;
- break;
- case 'tid':
- // this query deals with taxonomy objects
- break;
- case 'vid':
- // this query deals with vocabulary objects
- break;
- }
- }
- /**
- * Allows modules to declare their own Forms API element types and specify their
- * default values.
- *
- * This hook allows modules to declare their own form element types and to
- * specify their default values. The values returned by this hook will be
- * merged with the elements returned by hook_form() implementations and so
- * can return defaults for any Form APIs keys in addition to those explicitly
- * mentioned below.
- *
- * Each of the form element types defined by this hook is assumed to have
- * a matching theme function, e.g. theme_elementtype(), which should be
- * registered with hook_theme() as normal.
- *
- * Form more information about custom element types see the explanation at
- * @link http://drupal.org/node/169815 http://drupal.org/node/169815 @endlink .
- *
- * @return
- * An associative array describing the element types being defined. The array
- * contains a sub-array for each element type, with the machine-readable type
- * name as the key. Each sub-array has a number of possible attributes:
- * - "#input": boolean indicating whether or not this element carries a value
- * (even if it's hidden).
- * - "#process": array of callback functions taking $element and $form_state.
- * - "#after_build": array of callback functions taking $element and $form_state.
- * - "#validate": array of callback functions taking $form and $form_state.
- * - "#element_validate": array of callback functions taking $element and
- * $form_state.
- * - "#pre_render": array of callback functions taking $element and $form_state.
- * - "#post_render": array of callback functions taking $element and $form_state.
- * - "#submit": array of callback functions taking $form and $form_state.
- */
- function hook_elements() {
- $type['filter_format'] = array('#input' => TRUE);
- return $type;
- }
- /**
- * Perform cleanup tasks.
- *
- * This hook is run at the end of each page request. It is often used for
- * page logging and printing out debugging information.
- *
- * Only use this hook if your code must run even for cached page views.
- * If you have code which must run once on all non cached pages, use
- * hook_init instead. Thats the usual case. If you implement this hook
- * and see an error like 'Call to undefined function', it is likely that
- * you are depending on the presence of a module which has not been loaded yet.
- * It is not loaded because Drupal is still in bootstrap mode.
- *
- * @param $destination
- * If this hook is invoked as part of a drupal_goto() call, then this argument
- * will be a fully-qualified URL that is the destination of the redirect.
- * Modules may use this to react appropriately; for example, nothing should
- * be output in this case, because PHP will then throw a "headers cannot be
- * modified" error when attempting the redirection.
- * @return
- * None.
- */
- function hook_exit($destination = NULL) {
- db_query('UPDATE {counter} SET hits = hits + 1 WHERE type = 1');
- }
- /**
- * Control access to private file downloads and specify HTTP headers.
- *
- * This hook allows modules enforce permisisons on file downloads when the
- * private file download method is selected. Modules can also provide headers
- * to specify information like the file's name or MIME type.
- *
- * @param $filepath
- * String of the file's path.
- * @return
- * If the user does not have permission to access the file, return -1. If the
- * user has permission, return an array with the appropriate headers. If the file
- * is not controlled by the current module, the return value should be NULL.
- */
- function hook_file_download($filepath) {
- // Check if the file is controlled by the current module.
- if ($filemime = db_result(db_query("SELECT filemime FROM {fileupload} WHERE filepath = '%s'", file_create_path($filepath)))) {
- if (user_access('access content')) {
- return array('Content-type:' . $filemime);
- }
- else {
- return -1;
- }
- }
- }
- /**
- * Define content filters.
- *
- * Content in Drupal is passed through all enabled filters before it is
- * output. This lets a module modify content to the site administrator's
- * liking.
- *
- * This hook contains all that is needed for having a module provide filtering
- * functionality.
- *
- * Depending on $op, different tasks are performed.
- *
- * A module can contain as many filters as it wants. The 'list' operation tells
- * the filter system which filters are available. Every filter has a numerical
- * 'delta' which is used to refer to it in every operation.
- *
- * Filtering is a two-step process. First, the content is 'prepared' by calling
- * the 'prepare' operation for every filter. The purpose of 'prepare' is to
- * escape HTML-like structures. For example, imagine a filter which allows the
- * user to paste entire chunks of programming code without requiring manual
- * escaping of special HTML characters like @< or @&. If the programming code
- * were left untouched, then other filters could think it was HTML and change
- * it. For most filters however, the prepare-step is not necessary, and they can
- * just return the input without changes.
- *
- * Filters should not use the 'prepare' step for anything other than escaping,
- * because that would short-circuits the control the user has over the order
- * in which filters are applied.
- *
- * The second step is the actual processing step. The result from the
- * prepare-step gets passed to all the filters again, this time with the
- * 'process' operation. It's here that filters should perform actual changing of
- * the content: transforming URLs into hyperlinks, converting smileys into
- * images, etc.
- *
- * An important aspect of the filtering system are 'input formats'. Every input
- * format is an entire filter setup: which filters to enable, in what order
- * and with what settings. Filters that provide settings should usually store
- * these settings per format.
- *
- * If the filter's behaviour depends on an extensive list and/or external data
- * (e.g. a list of smileys, a list of glossary terms) then filters are allowed
- * to provide a separate, global configuration page rather than provide settings
- * per format. In that case, there should be a link from the format-specific
- * settings to the separate settings page.
- *
- * For performance reasons content is only filtered once; the result is stored
- * in the cache table and retrieved the next time the piece of content is
- * displayed. If a filter's output is dynamic it can override the cache
- * mechanism, but obviously this feature should be used with caution: having one
- * 'no cache' filter in a particular input format disables caching for the
- * entire format, not just for one filter.
- *
- * Beware of the filter cache when developing your module: it is advised to set
- * your filter to 'no cache' while developing, but be sure to remove it again
- * if it's not needed. You can clear the cache by running the SQL query 'DELETE
- * FROM cache_filter';
- *
- * @param $op
- * Which filtering operation to perform. Possible values:
- * - list: provide a list of available filters.
- * Returns an associative array of filter names with numerical keys.
- * These keys are used for subsequent operations and passed back through
- * the $delta parameter.
- * - no cache: Return true if caching should be disabled for this filter.
- * - description: Return a short description of what this filter does.
- * - prepare: Return the prepared version of the content in $text.
- * - process: Return the processed version of the content in $text.
- * - settings: Return HTML form controls for the filter's settings. These
- * settings are stored with variable_set() when the form is submitted.
- * Remember to use the $format identifier in the variable and control names
- * to store settings per input format (e.g. "mymodule_setting_$format").
- * @param $delta
- * Which of the module's filters to use (applies to every operation except
- * 'list'). Modules that only contain one filter can ignore this parameter.
- * @param $format
- * Which input format the filter is being used in (applies to 'prepare',
- * 'process' and 'settings').
- * @param $text
- * The content to filter (applies to 'prepare' and 'process').
- * @param $cache_id
- * The cache id of the content.
- * @return
- * The return value depends on $op. The filter hook is designed so that a
- * module can return $text for operations it does not use/need.
- *
- * For a detailed usage example, see filter_example.module. For an example of
- * using multiple filters in one module, see filter_filter() and
- * filter_filter_tips().
- */
- function hook_filter($op, $delta = 0, $format = -1, $text = '', $cache_id = 0) {
- switch ($op) {
- case 'list':
- return array(0 => t('Code filter'));
- case 'description':
- return t('Allows users to post code verbatim using <code> and <?php ?> tags.');
- case 'prepare':
- // Note: we use the bytes 0xFE and 0xFF to replace < > during the
- // filtering process. These bytes are not valid in UTF-8 data and thus
- // least likely to cause problems.
- $text = preg_replace('@<code>(.+?)</code>@se', "'\xFEcode\xFF'. codefilter_escape('\\1') .'\xFE/code\xFF'", $text);
- $text = preg_replace('@<(\?(php)?|%)(.+?)(\?|%)>@se', "'\xFEphp\xFF'. codefilter_escape('\\3') .'\xFE/php\xFF'", $text);
- return $text;
- case "process":
- $text = preg_replace('@\xFEcode\xFF(.+?)\xFE/code\xFF@se', "codefilter_process_code('$1')", $text);
- $text = preg_replace('@\xFEphp\xFF(.+?)\xFE/php\xFF@se', "codefilter_process_php('$1')", $text);
- return $text;
- default:
- return $text;
- }
- }
- /**
- * Provide tips for using filters.
- *
- * A module's tips should be informative and to the point. Short tips are
- * preferably one-liners.
- *
- * @param $delta
- * Which of this module's filters to use. Modules which only implement one
- * filter can ignore this parameter.
- * @param $format
- * Which format we are providing tips for.
- * @param $long
- * If set to true, long tips are requested, otherwise short tips are needed.
- * @return
- * The text of the filter tip.
- *
- *
- */
- function hook_filter_tips($delta, $format, $long = false) {
- if ($long) {
- return t('To post pieces of code, surround them with <code>...</code> tags. For PHP code, you can use <?php ... ?>, which will also colour it based on syntax.');
- }
- else {
- return t('You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.');
- }
- }
- /**
- * Insert closing HTML.
- *
- * This hook enables modules to insert HTML just before the \</body\> closing
- * tag of web pages. This is useful for adding JavaScript code to the footer
- * and for outputting debug information. It is not possible to add JavaScript
- * to the header at this point, and developers wishing to do so should use
- * hook_init() instead.
- *
- * @param $main
- * Whether the current page is the front page of the site.
- * @return
- * The HTML to be inserted.
- */
- function hook_footer($main = 0) {
- if (variable_get('dev_query', 0)) {
- return '<div style="clear:both;">'. devel_query_table() .'</div>';
- }
- }
- /**
- * Perform alterations to existing database schemas.
- *
- * When a module modifies the database structure of another module (by
- * changing, adding or removing fields, keys or indexes), it should
- * implement hook_schema_alter() to update the default $schema to take
- * it's changes into account.
- *
- * See hook_schema() for details on the schema definition structure.
- *
- * @param $schema
- * Nested array describing the schemas for all modules.
- * @return
- * None.
- */
- function hook_schema_alter(&$schema) {
- // Add field to existing schema.
- $schema['users']['fields']['timezone_id'] = array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => 'Per-user timezone configuration.',
- );
- }
- /**
- * Perform alterations before a form is rendered.
- *
- * One popular use of this hook is to add form elements to the node form. When
- * altering a node form, the node object retrieved at from $form['#node'].
- *
- * Note that instead of hook_form_alter(), which is called for all forms, you
- * can also use hook_form_FORM_ID_alter() to alter a specific form.
- *
- * @param $form
- * Nested array of form elements that comprise the form.
- * @param $form_state
- * A keyed array containing the current state of the form.
- * @param $form_id
- * String representing the name of the form itself. Typically this is the
- * name of the function that generated the form.
- */
- function hook_form_alter(&$form, $form_state, $form_id) {
- if ('node_type_form' == $form_id) {
- $form['workflow']['upload'] = array(
- '#type' => 'radios',
- '#title' => t('Attachments'),
- '#default_value' => variable_get('upload_'. $form['#node_type']->type, 1),
- '#options' => array(t('Disabled'), t('Enabled')),
- );
- }
- }
- /**
- * Provide a form-specific alteration instead of the global hook_form_alter().
- *
- * Modules can implement hook_form_FORM_ID_alter() to modify a specific form,
- * rather than implementing hook_form_alter() and checking the form ID, or
- * using long switch statements to alter multiple forms.
- *
- * Note that this hook fires before hook_form_alter(). Therefore all
- * implementations of hook_form_FORM_ID_alter() will run before all
- * implementations of hook_form_alter(), regardless of the module order.
- *
- * @param $form
- * Nested array of form elements that comprise the form.
- * @param $form_state
- * A keyed array containing the current state of the form.
- * @return
- * None.
- *
- * @see drupal_prepare_form().
- */
- function hook_form_FORM_ID_alter(&$form, &$form_state) {
- // Modification for the form with the given form ID goes here. For example, if
- // FORM_ID is "user_register" this code would run only on the user
- // registration form.
- // Add a checkbox to registration form about agreeing to terms of use.
- $form['terms_of_use'] = array(
- '#type' => 'checkbox',
- '#title' => t("I agree with the website's terms and conditions."),
- '#required' => TRUE,
- );
- }
- /**
- * Map form_ids to builder functions.
- *
- * This hook allows modules to build multiple forms from a single form "factory"
- * function but each form will have a different form id for submission,
- * validation, theming or alteration by other modules.
- *
- * The callback arguments will be passed as parameters to the function. Callers
- * of drupal_get_form() are also able to pass in parameters. These will be
- * appended after those specified by hook_forms().
- *
- * See node_forms() for an actual example of how multiple forms share a common
- * building function.
- *
- * @return
- * An array keyed by form id with callbacks and optional, callback arguments.
- */
- function hook_forms() {
- $forms['mymodule_first_form'] = array(
- 'callback' => 'mymodule_form_builder',
- 'callback arguments' => array('some parameter'),
- );
- $forms['mymodule_second_form'] = array(
- 'callback' => 'mymodule_form_builder',
- );
- return $forms;
- }
- /**
- * Provide online user help.
- *
- * By implementing hook_help(), a module can make documentation
- * available to the engine or to other modules. All user help should be
- * returned using this hook; developer help should be provided with
- * Doxygen/api.module comments.
- *
- * @param $path
- * A Drupal menu router path the help is being requested for, e.g.
- * admin/node or user/edit. If the router path includes a % wildcard,
- * then this will appear in the path - for example all node pages will
- * have the path node/% or node/%/view.
- * Also recognizes special descriptors after a "#" sign. Some examples:
- * - admin/help#modulename
- * The module's help text, displayed on the admin/help page and through
- * the module's individual help link.
- * - user/help#modulename
- * The help for a distributed authorization module (if applicable).
- * @param $arg
- * An array that corresponds to the return of the arg() function - if a module
- * needs to provide help for a page with additional parameters after the
- * Drupal path or help for a specific value for a wildcard in the path, then
- * the values in this array can be referenced. For example you could provide
- * help for user/1 by looking for the path user/% and $arg[1] == '1'. This
- * array should always be used rather than directly invoking arg(). Note that
- * depending on which module is invoking hook_help, $arg may contain only,
- * empty strings. Regardless, $arg[0] to $arg[11] will always be set.
- * @return
- * A localized string containing the help text. Every web link, l(), or
- * url() must be replaced with %something and put into the final t()
- * call:
- * $output .= 'A role defines a group of users that have certain
- * privileges as defined in %permission.';
- * $output = t($output, array('%permission' => l(t('user permissions'),
- * 'admin/user/permission')));
- *
- * For a detailed usage example, see page_example.module.
- */
- function hook_help($path, $arg) {
- switch ($path) {
- case 'admin/help#block':
- return '<p>'. t('Blocks are boxes of content that may be rendered into certain regions of your web pages, for example, into sidebars. Blocks are usually generated automatically by modules (e.g., Recent Forum Topics), but administrators can also define custom blocks.') .'</p>';
- case 'admin/build/block':
- return t('<p>Blocks are boxes of content that may be rendered into certain regions of your web pages, for example, into sidebars. They are usually generated automatically by modules, but administrators can create blocks manually.</p>
- <p>If you want certain blocks to disable themselves temporarily during high server loads, check the "Throttle" box. You can configure the auto-throttle on the <a href="@throttle">throttle configuration page</a> after having enabled the throttle module.</p>
- <p>You can configure the behaviour of each block (for example, specifying on which pages and for what users it will appear) by clicking the "configure" link for each block.</p>', array('@throttle' => url('admin/settings/throttle')));
- }
- }
- /**
- * Perform setup tasks. See also, hook_init.
- *
- * This hook is run at the beginning of the page request. It is typically
- * used to set up global parameters which are needed later in the request.
- *
- * Only use this hook if your code must run even for cached page views.This hook
- * is called before modules or most include files are loaded into memory.
- * It happens while Drupal is still in bootstrap mode.
- *
- * @return
- * None.
- */
- function hook_boot() {
- // we need user_access() in the shutdown function. make sure it gets loaded
- drupal_load('module', 'user');
- register_shutdown_function('devel_shutdown');
- }
- /**
- * Perform setup tasks. See also, hook_boot.
- *
- * This hook is run at the beginning of the page request. It is typically
- * used to set up global parameters which are needed later in the request.
- * when this hook is called, all modules are already loaded in memory.
- *
- * For example, this hook is a typical place for modules to add CSS or JS
- * that should be present on every page. This hook is not run on cached
- * pages - though CSS or JS added this way will be present on a cached page.
- *
- * @return
- * None.
- */
- function hook_init() {
- drupal_add_css(drupal_get_path('module', 'book') .'/book.css');
- }
- /**
- * Define internal Drupal links.
- *
- * This hook enables modules to add links to many parts of Drupal. Links
- * may be added in nodes or in the navigation block, for example.
- *
- * The returned array should be a keyed array of link entries. Each link can
- * be in one of two formats.
- *
- * The first format will use the l() function to render the link:
- * - attributes: Optional. See l() for usage.
- * - fragment: Optional. See l() for usage.
- * - href: Required. The URL of the link.
- * - html: Optional. See l() for usage.
- * - query: Optional. See l() for usage.
- * - title: Required. The name of the link.
- *
- * The second format can be used for non-links. Leaving out the href index will
- * select this format:
- * - title: Required. The text or HTML code to display.
- * - attributes: Optional. An associative array of HTML attributes to apply to the span tag.
- * - html: Optional. If not set to true, check_plain() will be run on the title before it is displayed.
- *
- * @param $type
- * An identifier declaring what kind of link is being requested.
- * Possible values:
- * - comment: Links to be placed below a comment being viewed.
- * - node: Links to be placed below a node being viewed.
- * @param $object
- * A node object or a comment object according to the $type.
- * @param $teaser
- * In case of node link: a 0/1 flag depending on whether the node is
- * displayed with its teaser or its full form.
- * @return
- * An array of the requested links.
- *
- */
- function hook_link($type, $object, $teaser = FALSE) {
- $links = array();
- if ($type == 'node' && isset($object->parent)) {
- if (!$teaser) {
- if (book_access('create', $object)) {
- $links['book_add_child'] = array(
- 'title' => t('add child page'),
- 'href' => "node/add/book/parent/$object->nid",
- );
- }
- if (user_access('see printer-friendly version')) {
- $links['book_printer'] = array(
- 'title' => t('printer-friendly version'),
- 'href' => 'book/export/html/'. $object->nid,
- 'attributes' => array('title' => t('Show a printer-friendly version of this book page and its sub-pages.'))
- );
- }
- }
- }
- $links['sample_link'] = array(
- 'title' => t('go somewhere'),
- 'href' => 'node/add',
- 'query' => 'foo=bar',
- 'fragment' => 'anchorname',
- 'attributes' => array('title' => t('go to another page')),
- );
- // Example of a link that's not an anchor
- if ($type == 'video') {
- if (variable_get('video_playcounter', 1) && user_access('view play counter')) {
- $links['play_counter'] = array(
- 'title' => format_plural($object->play_counter, '1 play', '@count plays'),
- );
- }
- }
- return $links;
- }
- /**
- * Perform alterations before links on a node are rendered. One popular use of
- * this hook is to modify/remove links from other modules. If you want to add a link
- * to the links section of a node, use hook_link instead.
- *
- * @param $links
- * Nested array of links for the node keyed by providing module.
- * @param $node
- * A node object that contains the links.
- * @return
- * None.
- */
- function hook_link_alter(&$links, $node) {
- foreach ($links as $module => $link) {
- if (strstr($module, 'taxonomy_term')) {
- // Link back to the forum and not the taxonomy term page
- $links[$module]['href'] = str_replace('taxonomy/term', 'forum', $link['href']);
- }
- }
- }
- /**
- * Perform alterations profile items before they are rendered. You may omit/add/re-sort/re-categorize, etc.
- *
- * @param $account
- * A user object whose profile is being rendered. Profile items
- * are stored in $account->content.
- * @return
- * None.
- */
- function hook_profile_alter(&$account) {
- foreach ($account->content AS $key => $field) {
- // do something
- }
- }
- /**
- * Alter any aspect of email sent by Drupal. You can use this hook to add a
- * common site footer to all outgoing email, add extra header fields, and/or
- * modify the email in any way. HTML-izing the outgoing email is one possibility.
- * See also drupal_mail().
- *
- * @param $message
- * A structured array containing the message to be altered. Keys in this
- * array include:
- * - 'id'
- * An id to identify the mail sent. Look at module source code or
- * drupal_mail() for possible id values.
- * - 'to'
- * The mail address or addresses the message will be sent to. The
- * formatting of this string must comply with RFC 2822.
- * - 'subject'
- * Subject of the e-mail to be sent. This must not contain any newline
- * characters, or the mail may not be sent properly.
- * - 'body'
- * An array of lines containing the message to be sent. Drupal will format
- * the correct line endings for you.
- * - 'from'
- * The address the message will be marked as being from, which is either a
- * custom address or the site-wide default email address.
- * - 'headers'
- * Associative array containing mail headers, such as From, Sender,
- * MIME-Version, Content-Type, etc.
- */
- function hook_mail_alter(&$message) {
- if ($message['id'] == 'my_message') {
- $message['body'] .= "\n\n--\nMail sent out from " . variable_get('sitename', t('Drupal'));
- }
- }
- /**
- * Define menu items and page callbacks.
- *
- * This hook enables modules to register paths, which determines whose
- * requests are to be handled. Depending on the type of registration
- * requested by each path, a link is placed in the the navigation block and/or
- * an item appears in the menu administration page (q=admin/menu).
- *
- * This hook is called rarely - for example when modules are enabled.
- *
- * @return
- * An array of menu items. Each menu item has a key corresponding to the
- * Drupal path being registered. The item is an associative array that may
- * contain the following key-value pairs:
- *
- * - "title": Required. The untranslated title of the menu item.
- * - "title callback": Function to generate the title, defaults to t().
- * If you require only the raw string to be output, set this to FALSE.
- * - "title arguments": Arguments to send to t() or your custom callback.
- * - "description": The untranslated description of the menu item.
- * - "page callback": The function to call to display a web page when the user
- * visits the path. If omitted, the parent menu item's callback will be used
- * instead.
- * - "page arguments": An array of arguments to pass to the page callback
- * function. Integer values pass the corresponding URL component (see arg()).
- * - "access callback": A function returning a boolean value that determines
- * whether the user has access rights to this menu item. Defaults to
- * user_access() unless a value is inherited from a parent menu item..
- * - "access arguments": An array of arguments to pass to the access callback
- * function. Integer values pass the corresponding URL component.
- * - "file": A file that will be included before the callbacks are accessed;
- * this allows callback functions to be in separate files. The file should
- * be relative to the implementing module's directory unless otherwise
- * specified by the "file path" option.
- * - "file path": The path to the folder containing the file specified in
- * "file". This defaults to the path to the module implementing the hook.
- * - "weight": An integer that determines relative position of items in the
- * menu; higher-weighted items sink. Defaults to 0. When in doubt, leave
- * this alone; the default alphabetical order is usually best.
- * - "menu_name": Optional. Set this to a custom menu if you don't want your
- * item to be placed in Navigation.
- * - "type": A bitmask of flags describing properties of the menu item.
- * Many shortcut bitmasks are provided as constants in menu.inc:
- * - MENU_NORMAL_ITEM: Normal menu items show up in the menu tree and can be
- * moved/hidden by the administrator.
- * - MENU_CALLBACK: Callbacks simply register a path so that the correct
- * function is fired when the URL is accessed.
- * - MENU_SUGGESTED_ITEM: Modules may "suggest" menu items that the
- * administrator may enable.
- * - MENU_LOCAL_TASK: Local tasks are rendered as tabs by default.
- * - MENU_DEFAULT_LOCAL_TASK: Every set of local tasks should provide one
- * "default" task, that links to the same path as its parent when clicked.
- * If the "type" key is omitted, MENU_NORMAL_ITEM is assumed.
- *
- * For a detailed usage example, see page_example.module.
- *
- * For comprehensive documentation on the menu system, see
- * @link http://drupal.org/node/102338 http://drupal.org/node/102338 @endlink .
- *
- */
- function hook_menu() {
- $items = array();
- $items['blog'] = array(
- 'title' => 'blogs',
- 'description' => 'Listing of blogs.',
- 'page callback' => 'blog_page',
- 'access arguments' => array('access content'),
- 'type' => MENU_SUGGESTED_ITEM,
- );
- $items['blog/feed'] = array(
- 'title' => 'RSS feed',
- 'page callback' => 'blog_feed',
- 'access arguments' => array('access content'),
- 'type' => MENU_CALLBACK,
- );
- return $items;
- }
- /**
- * Alter the information parsed from module and theme .info files
- *
- * This hook is invoked in module_rebuild_cache() and in system_theme_data().
- * A module may implement this hook in order to add to or alter the data
- * generated by reading the .info file with drupal_parse_info_file().
- *
- * @param &$info
- * The .info file contents, passed by reference so that it can be altered.
- * @param $file
- * Full information about the module or theme, including $file->name, and
- * $file->filename
- */
- function hook_system_info_alter(&$info, $file) {
- // Only fill this in if the .info file does not define a 'datestamp'.
- if (empty($info['datestamp'])) {
- $info['datestamp'] = filemtime($file->filename);
- }
- }
- /**
- * Alter the information about available updates for projects.
- *
- * @param $projects
- * Reference to an array of information about available updates to each
- * project installed on the system.
- *
- * @see update_calculate_project_data()
- */
- function hook_update_status_alter(&$projects) {
- $settings = variable_get('update_advanced_project_settings', array());
- foreach ($projects as $project => $project_info) {
- if (isset($settings[$project]) && isset($settings[$project]['check']) &&
- ($settings[$project]['check'] == 'never' ||
- (isset($project_info['recommended']) &&
- $settings[$project]['check'] === $project_info['recommended']))) {
- $projects[$project]['status'] = UPDATE_NOT_CHECKED;
- $projects[$project]['reason'] = t('Ignored from settings');
- if (!empty($settings[$project]['notes'])) {
- $projects[$project]['extra'][] = array(
- 'class' => 'admin-note',
- 'label' => t('Administrator note'),
- 'data' => $settings[$project]['notes'],
- );
- }
- }
- }
- }
- /**
- * Alter the list of projects before fetching data and comparing versions.
- *
- * Most modules will never need to implement this hook. It is for advanced
- * interaction with the update status module: mere mortals need not apply.
- * The primary use-case for this hook is to add projects to the list, for
- * example, to provide update status data on disabled modules and themes. A
- * contributed module might want to hide projects from the list, for example,
- * if there is a site-specific module that doesn't have any official releases,
- * that module could remove itself from this list to avoid "No available
- * releases found" warnings on the available updates report. In rare cases, a
- * module might want to alter the data associated with a project already in
- * the list.
- *
- * @param $projects
- * Reference to an array of the projects installed on the system. This
- * includes all the metadata documented in the comments below for each
- * project (either module or theme) that is currently enabled. The array is
- * initially populated inside update_get_projects() with the help of
- * _update_process_info_list(), so look there for examples of how to
- * populate the array with real values.
- *
- * @see update_get_projects()
- * @see _update_process_info_list()
- */
- function hook_update_projects_alter(&$projects) {
- // Hide a site-specific module from the list.
- unset($projects['site_specific_module']);
- // Add a disabled module to the list.
- // The key for the array should be the machine-readable project "short name".
- $projects['disabled_project_name'] = array(
- // Machine-readable project short name (same as the array key above).
- 'name' => 'disabled_project_name',
- // Array of values from the main .info file for this project.
- 'info' => array(
- 'name' => 'Some disabled module',
- 'description' => 'A module not enabled on the site that you want to see in the available updates report.',
- 'version' => '6.x-1.0',
- 'core' => '6.x',
- // The maximum file change time (the "ctime" returned by the filectime()
- // PHP method) for all of the .info files included in this project.
- '_info_file_ctime' => 1243888165,
- ),
- // The date stamp when the project was released, if known. If the disabled
- // project was an officially packaged release from drupal.org, this will
- // be included in the .info file as the 'datestamp' field. This only
- // really matters for development snapshot releases that are regenerated,
- // so it can be left undefined or set to 0 in most cases.
- 'datestamp' => 1243888185,
- // Any modules (or themes) included in this project. Keyed by machine-
- // readable "short name", value is the human-readable project name printed
- // in the UI.
- 'includes' => array(
- 'disabled_project' => 'Disabled module',
- 'disabled_project_helper' => 'Disabled module helper module',
- 'disabled_project_foo' => 'Disabled module foo add-on module',
- ),
- // Does this project contain a 'module', 'theme', 'disabled-module', or
- // 'disabled-theme'?
- 'project_type' => 'disabled-module',
- );
- }
- /**
- * Inform the node acces…
Large files files are truncated, but you can click here to view the full file