PageRenderTime 62ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/apis/6/core.php

https://github.com/fiasco/Drupal-Module-Builder
PHP | 2452 lines | 790 code | 114 blank | 1548 comment | 111 complexity | a744f8ff9ecb90db26d8697040aaf1bc MD5 | raw file
  1. <?php
  2. // $Id: core.php,v 1.168.2.64 2009/06/29 20:25:15 jhodgdon Exp $
  3. /**
  4. * @file
  5. * These are the hooks that are invoked by the Drupal core.
  6. *
  7. * Core hooks are typically called in all modules at once using
  8. * module_invoke_all().
  9. */
  10. /**
  11. * @addtogroup hooks
  12. * @{
  13. */
  14. /**
  15. * Declare information about one or more Drupal actions.
  16. *
  17. * Any module can define any number of Drupal actions. The trigger module is an
  18. * example of a module that uses actions. An action consists of two or three
  19. * parts: (1) an action definition (returned by this hook), (2) a function which
  20. * does the action (which by convention is named module + '_' + description of
  21. * what the function does + '_action'), and an optional form definition
  22. * function that defines a configuration form (which has the name of the action
  23. * with '_form' appended to it.)
  24. *
  25. * @return
  26. * - An array of action descriptions. Each action description is an associative
  27. * array, where the key of the item is the action's function, and the
  28. * following key-value pairs:
  29. * - 'type': (required) the type is determined by what object the action
  30. * acts on. Possible choices are node, user, comment, and system. Or
  31. * whatever your own custom type is. So, for the nodequeue module, the
  32. * type might be set to 'nodequeue' if the action would be performed on a
  33. * nodequeue.
  34. * - 'description': (required) The human-readable name of the action.
  35. * - 'configurable': (required) If FALSE, then the action doesn't require
  36. * any extra configuration. If TRUE, then you should define a form
  37. * function with the same name as the key, but with '_form' appended to
  38. * it (i.e., the form for 'node_assign_owner_action' is
  39. * 'node_assign_owner_action_form'.)
  40. * This function will take the $context as the only parameter, and is
  41. * paired with the usual _submit function, and possibly a _validate
  42. * function.
  43. * - 'hooks': (required) An array of all of the operations this action is
  44. * appropriate for, keyed by hook name. The trigger module uses this to
  45. * filter out inappropriate actions when presenting the interface for
  46. * assigning actions to events. If you are writing actions in your own
  47. * modules and you simply want to declare support for all possible hooks,
  48. * you can set 'hooks' => array('any' => TRUE). Common hooks are 'user',
  49. * 'nodeapi', 'comment', or 'taxonomy'. Any hook that has been described
  50. * to Drupal in hook_hook_info() will work is a possiblity.
  51. * - 'behavior': (optional) Human-readable array of behavior descriptions.
  52. * The only one we have now is 'changes node property'. You will almost
  53. * certainly never have to return this in your own implementations of this
  54. * hook.
  55. *
  56. * The function that is called when the action is triggered is passed two
  57. * parameters - an object of the same type as the 'type' value of the
  58. * hook_action_info array, and a context variable that contains the context
  59. * under which the action is currently running, sent as an array. For example,
  60. * the actions module sets the 'hook' and 'op' keys of the context array (so,
  61. * 'hook' may be 'nodeapi' and 'op' may be 'insert').
  62. */
  63. function hook_action_info() {
  64. return array(
  65. 'comment_unpublish_action' => array(
  66. 'description' => t('Unpublish comment'),
  67. 'type' => 'comment',
  68. 'configurable' => FALSE,
  69. 'hooks' => array(
  70. 'comment' => array('insert', 'update'),
  71. )
  72. ),
  73. 'comment_unpublish_by_keyword_action' => array(
  74. 'description' => t('Unpublish comment containing keyword(s)'),
  75. 'type' => 'comment',
  76. 'configurable' => TRUE,
  77. 'hooks' => array(
  78. 'comment' => array('insert', 'update'),
  79. )
  80. )
  81. );
  82. }
  83. /**
  84. * Execute code after an action is deleted.
  85. *
  86. * @param $aid
  87. * The action ID.
  88. */
  89. function hook_actions_delete($aid) {
  90. db_query("DELETE FROM {actions_assignments} WHERE aid = '%s'", $aid);
  91. }
  92. /**
  93. * Alter the actions declared by another module.
  94. *
  95. * Called by actions_list() to allow modules to alter the return
  96. * values from implementations of hook_action_info().
  97. *
  98. * @see trigger_example_action_info_alter().
  99. */
  100. function hook_action_info_alter(&$actions) {
  101. $actions['node_unpublish_action']['description'] = t('Unpublish and remove from public view.');
  102. }
  103. /**
  104. * Declare a block or set of blocks.
  105. *
  106. * Any module can export a block (or blocks) to be displayed by defining
  107. * the _block hook. This hook is called by theme.inc to display a block,
  108. * and also by block.module to procure the list of available blocks.
  109. *
  110. * @param $op
  111. * What kind of information to retrieve about the block or blocks.
  112. * Possible values:
  113. * - 'list': A list of all blocks defined by the module.
  114. * - 'configure': Configuration form for the block.
  115. * - 'save': Save the configuration options.
  116. * - 'view': Process the block when enabled in a region in order to view its contents.
  117. * @param $delta
  118. * Which block to return (not applicable if $op is 'list'). Although it is
  119. * most commonly an integer starting at 0, this is not mandatory. For
  120. * instance, aggregator.module uses string values for $delta
  121. * @param $edit
  122. * If $op is 'save', the submitted form data from the configuration form.
  123. * @return
  124. * - If $op is 'list': An array of block descriptions. Each block description
  125. * is an associative array, with the following key-value pairs:
  126. * - 'info': (required) The human-readable name of the block.
  127. * - 'cache': A bitmask of flags describing how the block should behave with
  128. * respect to block caching. The following shortcut bitmasks are provided
  129. * as constants in block.module:
  130. * - BLOCK_CACHE_PER_ROLE (default): The block can change depending on the
  131. * roles the user viewing the page belongs to.
  132. * - BLOCK_CACHE_PER_USER: The block can change depending on the user
  133. * viewing the page. This setting can be resource-consuming for sites
  134. * with large number of users, and should only be used when
  135. * BLOCK_CACHE_PER_ROLE is not sufficient.
  136. * - BLOCK_CACHE_PER_PAGE: The block can change depending on the page
  137. * being viewed.
  138. * - BLOCK_CACHE_GLOBAL: The block is the same for every user on every
  139. * page where it is visible.
  140. * - BLOCK_NO_CACHE: The block should not get cached.
  141. * - 'weight', 'status', 'region', 'visibility', 'pages':
  142. * You can give your blocks an explicit weight, enable them, limit them to
  143. * given pages, etc. These settings will be registered when the block is first
  144. * loaded at admin/block, and from there can be changed manually via block
  145. * administration.
  146. * Note that if you set a region that isn't available in a given theme, the
  147. * block will be registered instead to that theme's default region (the first
  148. * item in the _regions array).
  149. * - If $op is 'configure': optionally return the configuration form.
  150. * - If $op is 'save': return nothing.
  151. * - If $op is 'view': return an array which must define a 'subject' element
  152. * and a 'content' element defining the block indexed by $delta.
  153. *
  154. * The functions mymodule_display_block_1 and 2, as used in the example,
  155. * should of course be defined somewhere in your module and return the
  156. * content you want to display to your users. If the "content" element
  157. * is empty, no block will be displayed even if "subject" is present.
  158. *
  159. * After completing your blocks, do not forget to enable them in the
  160. * block admin menu.
  161. *
  162. * For a detailed usage example, see block_example.module.
  163. */
  164. function hook_block($op = 'list', $delta = 0, $edit = array()) {
  165. if ($op == 'list') {
  166. $blocks[0] = array('info' => t('Mymodule block #1 shows ...'),
  167. 'weight' => 0, 'status' => 1, 'region' => 'left');
  168. // BLOCK_CACHE_PER_ROLE will be assumed for block 0.
  169. $blocks[1] = array('info' => t('Mymodule block #2 describes ...'),
  170. 'cache' => BLOCK_CACHE_PER_ROLE | BLOCK_CACHE_PER_PAGE);
  171. return $blocks;
  172. }
  173. else if ($op == 'configure' && $delta == 0) {
  174. $form['items'] = array(
  175. '#type' => 'select',
  176. '#title' => t('Number of items'),
  177. '#default_value' => variable_get('mymodule_block_items', 0),
  178. '#options' => array('1', '2', '3'),
  179. );
  180. return $form;
  181. }
  182. else if ($op == 'save' && $delta == 0) {
  183. variable_set('mymodule_block_items', $edit['items']);
  184. }
  185. else if ($op == 'view') {
  186. switch($delta) {
  187. case 0:
  188. $block = array('subject' => t('Title of block #1'),
  189. 'content' => mymodule_display_block_1());
  190. break;
  191. case 1:
  192. $block = array('subject' => t('Title of block #2'),
  193. 'content' => mymodule_display_block_2());
  194. break;
  195. }
  196. return $block;
  197. }
  198. }
  199. /**
  200. * Act on comments.
  201. *
  202. * This hook allows modules to extend the comments system.
  203. *
  204. * @param $a1
  205. * Dependent on the action being performed.
  206. * - For "validate","update","insert", passes in an array of form values submitted by the user.
  207. * - For all other operations, passes in the comment the action is being performed on.
  208. * @param $op
  209. * What kind of action is being performed. Possible values:
  210. * - "insert": The comment is being inserted.
  211. * - "update": The comment is being updated.
  212. * - "view": The comment is being viewed. This hook can be used to add additional data to the comment before theming.
  213. * - "validate": The user has just finished editing the comment and is
  214. * trying to preview or submit it. This hook can be used to check or
  215. * even modify the node. Errors should be set with form_set_error().
  216. * - "publish": The comment is being published by the moderator.
  217. * - "unpublish": The comment is being unpublished by the moderator.
  218. * - "delete": The comment is being deleted by the moderator.
  219. * @return
  220. * Dependent on the action being performed.
  221. * - For all other operations, nothing.
  222. */
  223. function hook_comment(&$a1, $op) {
  224. if ($op == 'insert' || $op == 'update') {
  225. $nid = $a1['nid'];
  226. }
  227. cache_clear_all_like(drupal_url(array('id' => $nid)));
  228. }
  229. /**
  230. * Perform periodic actions.
  231. *
  232. * Modules that require to schedule some commands to be executed at regular
  233. * intervals can implement hook_cron(). The engine will then call the hook
  234. * at the appropriate intervals defined by the administrator. This interface
  235. * is particularly handy to implement timers or to automate certain tasks.
  236. * Database maintenance, recalculation of settings or parameters, and
  237. * automatic mailings are good candidates for cron tasks.
  238. *
  239. * @return
  240. * None.
  241. *
  242. * This hook will only be called if cron.php is run (e.g. by crontab).
  243. */
  244. function hook_cron() {
  245. $result = db_query('SELECT * FROM {site} WHERE checked = 0 OR checked
  246. + refresh < %d', time());
  247. while ($site = db_fetch_array($result)) {
  248. cloud_update($site);
  249. }
  250. }
  251. /**
  252. * Expose a list of triggers (events) that your module is allowing users to
  253. * assign actions to.
  254. *
  255. * This hook is used by the Triggers API to present information about triggers
  256. * (or events) that your module allows users to assign actions to.
  257. *
  258. * See also hook_action_info().
  259. *
  260. * @return
  261. * - A nested array. The outermost key defines the module that the triggers
  262. * are from. The menu system will use the key to look at the .info file of
  263. * the module and make a local task (a tab) in the trigger UI.
  264. * - The next key defines the hook being described.
  265. * - Inside of that array are a list of arrays keyed by hook operation.
  266. * - Each of those arrays have a key of 'runs when' and a value which is
  267. * an English description of the hook.
  268. *
  269. * For example, the node_hook_info implementation has 'node' as the outermost
  270. * key, as that's the module it's in. Next it has 'nodeapi' as the next key,
  271. * as hook_nodeapi() is what applies to changes in nodes. Finally the keys
  272. * after that are the various operations for hook_nodeapi() that the node module
  273. * is exposing as triggers.
  274. */
  275. function hook_hook_info() {
  276. return array(
  277. 'node' => array(
  278. 'nodeapi' => array(
  279. 'presave' => array(
  280. 'runs when' => t('When either saving a new post or updating an existing post'),
  281. ),
  282. 'insert' => array(
  283. 'runs when' => t('After saving a new post'),
  284. ),
  285. 'update' => array(
  286. 'runs when' => t('After saving an updated post'),
  287. ),
  288. 'delete' => array(
  289. 'runs when' => t('After deleting a post')
  290. ),
  291. 'view' => array(
  292. 'runs when' => t('When content is viewed by an authenticated user')
  293. ),
  294. ),
  295. ),
  296. );
  297. }
  298. /**
  299. * Alter the data being saved to the {menu_router} table after hook_menu is invoked.
  300. *
  301. * This hook is invoked by menu_router_build(). The menu definitions are passed
  302. * in by reference. Each element of the $items array is one item returned
  303. * by a module from hook_menu. Additional items may be added, or existing items
  304. * altered.
  305. *
  306. * @param $items
  307. * Associative array of menu router definitions returned from hook_menu().
  308. * @return
  309. * None.
  310. */
  311. function hook_menu_alter(&$items) {
  312. // Example - disable the page at node/add
  313. $items['node/add']['access callback'] = FALSE;
  314. }
  315. /**
  316. * Alter the data being saved to the {menu_links} table by menu_link_save().
  317. *
  318. * @param $item
  319. * Associative array defining a menu link as passed into menu_link_save().
  320. * @param $menu
  321. * Associative array containg the menu router returned from menu_router_build().
  322. * @return
  323. * None.
  324. */
  325. function hook_menu_link_alter(&$item, $menu) {
  326. // Example 1 - make all new admin links hidden (a.k.a disabled).
  327. if (strpos($item['link_path'], 'admin') === 0 && empty($item['mlid'])) {
  328. $item['hidden'] = 1;
  329. }
  330. // Example 2 - flag a link to be altered by hook_translated_menu_link_alter()
  331. if ($item['link_path'] == 'devel/cache/clear') {
  332. $item['options']['alter'] = TRUE;
  333. }
  334. }
  335. /**
  336. * Alter a menu link after it's translated, but before it's rendered.
  337. *
  338. * This hook may be used, for example, to add a page-specific query string.
  339. * For performance reasons, only links that have $item['options']['alter'] == TRUE
  340. * will be passed into this hook. The $item['options']['alter'] flag should
  341. * generally be set using hook_menu_link_alter().
  342. *
  343. * @param $item
  344. * Associative array defining a menu link after _menu_link_translate()
  345. * @param $map
  346. * Associative array containing the menu $map (path parts and/or objects).
  347. * @return
  348. * None.
  349. */
  350. function hook_translated_menu_link_alter(&$item, $map) {
  351. if ($item['href'] == 'devel/cache/clear') {
  352. $item['localized_options']['query'] = drupal_get_destination();
  353. }
  354. }
  355. /**
  356. * Rewrite database queries, usually for access control.
  357. *
  358. * Add JOIN and WHERE statements to queries and decide whether the primary_field
  359. * shall be made DISTINCT. For node objects, primary field is always called nid.
  360. * For taxonomy terms, it is tid and for vocabularies it is vid. For comments,
  361. * it is cid. Primary table is the table where the primary object (node, file,
  362. * term_node etc.) is.
  363. *
  364. * You shall return an associative array. Possible keys are 'join', 'where' and
  365. * 'distinct'. The value of 'distinct' shall be 1 if you want that the
  366. * primary_field made DISTINCT.
  367. *
  368. * @param $query
  369. * Query to be rewritten.
  370. * @param $primary_table
  371. * Name or alias of the table which has the primary key field for this query.
  372. * Typical table names would be: {blocks}, {comments}, {forum}, {node},
  373. * {menu}, {term_data} or {vocabulary}. However, it is more common for
  374. * $primary_table to contain the usual table alias: b, c, f, n, m, t or v.
  375. * @param $primary_field
  376. * Name of the primary field.
  377. * @param $args
  378. * Array of additional arguments.
  379. * @return
  380. * An array of join statements, where statements, distinct decision.
  381. */
  382. function hook_db_rewrite_sql($query, $primary_table, $primary_field, $args) {
  383. switch ($primary_field) {
  384. case 'nid':
  385. // this query deals with node objects
  386. $return = array();
  387. if ($primary_table != 'n') {
  388. $return['join'] = "LEFT JOIN {node} n ON $primary_table.nid = n.nid";
  389. }
  390. $return['where'] = 'created >' . mktime(0, 0, 0, 1, 1, 2005);
  391. return $return;
  392. break;
  393. case 'tid':
  394. // this query deals with taxonomy objects
  395. break;
  396. case 'vid':
  397. // this query deals with vocabulary objects
  398. break;
  399. }
  400. }
  401. /**
  402. * Allows modules to declare their own Forms API element types and specify their
  403. * default values.
  404. *
  405. * This hook allows modules to declare their own form element types and to
  406. * specify their default values. The values returned by this hook will be
  407. * merged with the elements returned by hook_form() implementations and so
  408. * can return defaults for any Form APIs keys in addition to those explicitly
  409. * mentioned below.
  410. *
  411. * Each of the form element types defined by this hook is assumed to have
  412. * a matching theme function, e.g. theme_elementtype(), which should be
  413. * registered with hook_theme() as normal.
  414. *
  415. * Form more information about custom element types see the explanation at
  416. * @link http://drupal.org/node/169815 http://drupal.org/node/169815 @endlink .
  417. *
  418. * @return
  419. * An associative array describing the element types being defined. The array
  420. * contains a sub-array for each element type, with the machine-readable type
  421. * name as the key. Each sub-array has a number of possible attributes:
  422. * - "#input": boolean indicating whether or not this element carries a value
  423. * (even if it's hidden).
  424. * - "#process": array of callback functions taking $element and $form_state.
  425. * - "#after_build": array of callback functions taking $element and $form_state.
  426. * - "#validate": array of callback functions taking $form and $form_state.
  427. * - "#element_validate": array of callback functions taking $element and
  428. * $form_state.
  429. * - "#pre_render": array of callback functions taking $element and $form_state.
  430. * - "#post_render": array of callback functions taking $element and $form_state.
  431. * - "#submit": array of callback functions taking $form and $form_state.
  432. */
  433. function hook_elements() {
  434. $type['filter_format'] = array('#input' => TRUE);
  435. return $type;
  436. }
  437. /**
  438. * Perform cleanup tasks.
  439. *
  440. * This hook is run at the end of each page request. It is often used for
  441. * page logging and printing out debugging information.
  442. *
  443. * Only use this hook if your code must run even for cached page views.
  444. * If you have code which must run once on all non cached pages, use
  445. * hook_init instead. Thats the usual case. If you implement this hook
  446. * and see an error like 'Call to undefined function', it is likely that
  447. * you are depending on the presence of a module which has not been loaded yet.
  448. * It is not loaded because Drupal is still in bootstrap mode.
  449. *
  450. * @param $destination
  451. * If this hook is invoked as part of a drupal_goto() call, then this argument
  452. * will be a fully-qualified URL that is the destination of the redirect.
  453. * Modules may use this to react appropriately; for example, nothing should
  454. * be output in this case, because PHP will then throw a "headers cannot be
  455. * modified" error when attempting the redirection.
  456. * @return
  457. * None.
  458. */
  459. function hook_exit($destination = NULL) {
  460. db_query('UPDATE {counter} SET hits = hits + 1 WHERE type = 1');
  461. }
  462. /**
  463. * Control access to private file downloads and specify HTTP headers.
  464. *
  465. * This hook allows modules enforce permisisons on file downloads when the
  466. * private file download method is selected. Modules can also provide headers
  467. * to specify information like the file's name or MIME type.
  468. *
  469. * @param $filepath
  470. * String of the file's path.
  471. * @return
  472. * If the user does not have permission to access the file, return -1. If the
  473. * user has permission, return an array with the appropriate headers. If the file
  474. * is not controlled by the current module, the return value should be NULL.
  475. */
  476. function hook_file_download($filepath) {
  477. // Check if the file is controlled by the current module.
  478. if ($filemime = db_result(db_query("SELECT filemime FROM {fileupload} WHERE filepath = '%s'", file_create_path($filepath)))) {
  479. if (user_access('access content')) {
  480. return array('Content-type:' . $filemime);
  481. }
  482. else {
  483. return -1;
  484. }
  485. }
  486. }
  487. /**
  488. * Define content filters.
  489. *
  490. * Content in Drupal is passed through all enabled filters before it is
  491. * output. This lets a module modify content to the site administrator's
  492. * liking.
  493. *
  494. * This hook contains all that is needed for having a module provide filtering
  495. * functionality.
  496. *
  497. * Depending on $op, different tasks are performed.
  498. *
  499. * A module can contain as many filters as it wants. The 'list' operation tells
  500. * the filter system which filters are available. Every filter has a numerical
  501. * 'delta' which is used to refer to it in every operation.
  502. *
  503. * Filtering is a two-step process. First, the content is 'prepared' by calling
  504. * the 'prepare' operation for every filter. The purpose of 'prepare' is to
  505. * escape HTML-like structures. For example, imagine a filter which allows the
  506. * user to paste entire chunks of programming code without requiring manual
  507. * escaping of special HTML characters like @< or @&. If the programming code
  508. * were left untouched, then other filters could think it was HTML and change
  509. * it. For most filters however, the prepare-step is not necessary, and they can
  510. * just return the input without changes.
  511. *
  512. * Filters should not use the 'prepare' step for anything other than escaping,
  513. * because that would short-circuits the control the user has over the order
  514. * in which filters are applied.
  515. *
  516. * The second step is the actual processing step. The result from the
  517. * prepare-step gets passed to all the filters again, this time with the
  518. * 'process' operation. It's here that filters should perform actual changing of
  519. * the content: transforming URLs into hyperlinks, converting smileys into
  520. * images, etc.
  521. *
  522. * An important aspect of the filtering system are 'input formats'. Every input
  523. * format is an entire filter setup: which filters to enable, in what order
  524. * and with what settings. Filters that provide settings should usually store
  525. * these settings per format.
  526. *
  527. * If the filter's behaviour depends on an extensive list and/or external data
  528. * (e.g. a list of smileys, a list of glossary terms) then filters are allowed
  529. * to provide a separate, global configuration page rather than provide settings
  530. * per format. In that case, there should be a link from the format-specific
  531. * settings to the separate settings page.
  532. *
  533. * For performance reasons content is only filtered once; the result is stored
  534. * in the cache table and retrieved the next time the piece of content is
  535. * displayed. If a filter's output is dynamic it can override the cache
  536. * mechanism, but obviously this feature should be used with caution: having one
  537. * 'no cache' filter in a particular input format disables caching for the
  538. * entire format, not just for one filter.
  539. *
  540. * Beware of the filter cache when developing your module: it is advised to set
  541. * your filter to 'no cache' while developing, but be sure to remove it again
  542. * if it's not needed. You can clear the cache by running the SQL query 'DELETE
  543. * FROM cache_filter';
  544. *
  545. * @param $op
  546. * Which filtering operation to perform. Possible values:
  547. * - list: provide a list of available filters.
  548. * Returns an associative array of filter names with numerical keys.
  549. * These keys are used for subsequent operations and passed back through
  550. * the $delta parameter.
  551. * - no cache: Return true if caching should be disabled for this filter.
  552. * - description: Return a short description of what this filter does.
  553. * - prepare: Return the prepared version of the content in $text.
  554. * - process: Return the processed version of the content in $text.
  555. * - settings: Return HTML form controls for the filter's settings. These
  556. * settings are stored with variable_set() when the form is submitted.
  557. * Remember to use the $format identifier in the variable and control names
  558. * to store settings per input format (e.g. "mymodule_setting_$format").
  559. * @param $delta
  560. * Which of the module's filters to use (applies to every operation except
  561. * 'list'). Modules that only contain one filter can ignore this parameter.
  562. * @param $format
  563. * Which input format the filter is being used in (applies to 'prepare',
  564. * 'process' and 'settings').
  565. * @param $text
  566. * The content to filter (applies to 'prepare' and 'process').
  567. * @param $cache_id
  568. * The cache id of the content.
  569. * @return
  570. * The return value depends on $op. The filter hook is designed so that a
  571. * module can return $text for operations it does not use/need.
  572. *
  573. * For a detailed usage example, see filter_example.module. For an example of
  574. * using multiple filters in one module, see filter_filter() and
  575. * filter_filter_tips().
  576. */
  577. function hook_filter($op, $delta = 0, $format = -1, $text = '', $cache_id = 0) {
  578. switch ($op) {
  579. case 'list':
  580. return array(0 => t('Code filter'));
  581. case 'description':
  582. return t('Allows users to post code verbatim using &lt;code&gt; and &lt;?php ?&gt; tags.');
  583. case 'prepare':
  584. // Note: we use the bytes 0xFE and 0xFF to replace < > during the
  585. // filtering process. These bytes are not valid in UTF-8 data and thus
  586. // least likely to cause problems.
  587. $text = preg_replace('@<code>(.+?)</code>@se', "'\xFEcode\xFF'. codefilter_escape('\\1') .'\xFE/code\xFF'", $text);
  588. $text = preg_replace('@<(\?(php)?|%)(.+?)(\?|%)>@se', "'\xFEphp\xFF'. codefilter_escape('\\3') .'\xFE/php\xFF'", $text);
  589. return $text;
  590. case "process":
  591. $text = preg_replace('@\xFEcode\xFF(.+?)\xFE/code\xFF@se', "codefilter_process_code('$1')", $text);
  592. $text = preg_replace('@\xFEphp\xFF(.+?)\xFE/php\xFF@se', "codefilter_process_php('$1')", $text);
  593. return $text;
  594. default:
  595. return $text;
  596. }
  597. }
  598. /**
  599. * Provide tips for using filters.
  600. *
  601. * A module's tips should be informative and to the point. Short tips are
  602. * preferably one-liners.
  603. *
  604. * @param $delta
  605. * Which of this module's filters to use. Modules which only implement one
  606. * filter can ignore this parameter.
  607. * @param $format
  608. * Which format we are providing tips for.
  609. * @param $long
  610. * If set to true, long tips are requested, otherwise short tips are needed.
  611. * @return
  612. * The text of the filter tip.
  613. *
  614. *
  615. */
  616. function hook_filter_tips($delta, $format, $long = false) {
  617. if ($long) {
  618. return t('To post pieces of code, surround them with &lt;code&gt;...&lt;/code&gt; tags. For PHP code, you can use &lt;?php ... ?&gt;, which will also colour it based on syntax.');
  619. }
  620. else {
  621. return t('You may post code using &lt;code&gt;...&lt;/code&gt; (generic) or &lt;?php ... ?&gt; (highlighted PHP) tags.');
  622. }
  623. }
  624. /**
  625. * Insert closing HTML.
  626. *
  627. * This hook enables modules to insert HTML just before the \</body\> closing
  628. * tag of web pages. This is useful for adding JavaScript code to the footer
  629. * and for outputting debug information. It is not possible to add JavaScript
  630. * to the header at this point, and developers wishing to do so should use
  631. * hook_init() instead.
  632. *
  633. * @param $main
  634. * Whether the current page is the front page of the site.
  635. * @return
  636. * The HTML to be inserted.
  637. */
  638. function hook_footer($main = 0) {
  639. if (variable_get('dev_query', 0)) {
  640. return '<div style="clear:both;">'. devel_query_table() .'</div>';
  641. }
  642. }
  643. /**
  644. * Perform alterations to existing database schemas.
  645. *
  646. * When a module modifies the database structure of another module (by
  647. * changing, adding or removing fields, keys or indexes), it should
  648. * implement hook_schema_alter() to update the default $schema to take
  649. * it's changes into account.
  650. *
  651. * See hook_schema() for details on the schema definition structure.
  652. *
  653. * @param $schema
  654. * Nested array describing the schemas for all modules.
  655. * @return
  656. * None.
  657. */
  658. function hook_schema_alter(&$schema) {
  659. // Add field to existing schema.
  660. $schema['users']['fields']['timezone_id'] = array(
  661. 'type' => 'int',
  662. 'not null' => TRUE,
  663. 'default' => 0,
  664. 'description' => 'Per-user timezone configuration.',
  665. );
  666. }
  667. /**
  668. * Perform alterations before a form is rendered.
  669. *
  670. * One popular use of this hook is to add form elements to the node form. When
  671. * altering a node form, the node object retrieved at from $form['#node'].
  672. *
  673. * Note that instead of hook_form_alter(), which is called for all forms, you
  674. * can also use hook_form_FORM_ID_alter() to alter a specific form.
  675. *
  676. * @param $form
  677. * Nested array of form elements that comprise the form.
  678. * @param $form_state
  679. * A keyed array containing the current state of the form.
  680. * @param $form_id
  681. * String representing the name of the form itself. Typically this is the
  682. * name of the function that generated the form.
  683. */
  684. function hook_form_alter(&$form, $form_state, $form_id) {
  685. if ('node_type_form' == $form_id) {
  686. $form['workflow']['upload'] = array(
  687. '#type' => 'radios',
  688. '#title' => t('Attachments'),
  689. '#default_value' => variable_get('upload_'. $form['#node_type']->type, 1),
  690. '#options' => array(t('Disabled'), t('Enabled')),
  691. );
  692. }
  693. }
  694. /**
  695. * Provide a form-specific alteration instead of the global hook_form_alter().
  696. *
  697. * Modules can implement hook_form_FORM_ID_alter() to modify a specific form,
  698. * rather than implementing hook_form_alter() and checking the form ID, or
  699. * using long switch statements to alter multiple forms.
  700. *
  701. * Note that this hook fires before hook_form_alter(). Therefore all
  702. * implementations of hook_form_FORM_ID_alter() will run before all
  703. * implementations of hook_form_alter(), regardless of the module order.
  704. *
  705. * @param $form
  706. * Nested array of form elements that comprise the form.
  707. * @param $form_state
  708. * A keyed array containing the current state of the form.
  709. * @return
  710. * None.
  711. *
  712. * @see drupal_prepare_form().
  713. */
  714. function hook_form_FORM_ID_alter(&$form, &$form_state) {
  715. // Modification for the form with the given form ID goes here. For example, if
  716. // FORM_ID is "user_register" this code would run only on the user
  717. // registration form.
  718. // Add a checkbox to registration form about agreeing to terms of use.
  719. $form['terms_of_use'] = array(
  720. '#type' => 'checkbox',
  721. '#title' => t("I agree with the website's terms and conditions."),
  722. '#required' => TRUE,
  723. );
  724. }
  725. /**
  726. * Map form_ids to builder functions.
  727. *
  728. * This hook allows modules to build multiple forms from a single form "factory"
  729. * function but each form will have a different form id for submission,
  730. * validation, theming or alteration by other modules.
  731. *
  732. * The callback arguments will be passed as parameters to the function. Callers
  733. * of drupal_get_form() are also able to pass in parameters. These will be
  734. * appended after those specified by hook_forms().
  735. *
  736. * See node_forms() for an actual example of how multiple forms share a common
  737. * building function.
  738. *
  739. * @return
  740. * An array keyed by form id with callbacks and optional, callback arguments.
  741. */
  742. function hook_forms() {
  743. $forms['mymodule_first_form'] = array(
  744. 'callback' => 'mymodule_form_builder',
  745. 'callback arguments' => array('some parameter'),
  746. );
  747. $forms['mymodule_second_form'] = array(
  748. 'callback' => 'mymodule_form_builder',
  749. );
  750. return $forms;
  751. }
  752. /**
  753. * Provide online user help.
  754. *
  755. * By implementing hook_help(), a module can make documentation
  756. * available to the engine or to other modules. All user help should be
  757. * returned using this hook; developer help should be provided with
  758. * Doxygen/api.module comments.
  759. *
  760. * @param $path
  761. * A Drupal menu router path the help is being requested for, e.g.
  762. * admin/node or user/edit. If the router path includes a % wildcard,
  763. * then this will appear in the path - for example all node pages will
  764. * have the path node/% or node/%/view.
  765. * Also recognizes special descriptors after a "#" sign. Some examples:
  766. * - admin/help#modulename
  767. * The module's help text, displayed on the admin/help page and through
  768. * the module's individual help link.
  769. * - user/help#modulename
  770. * The help for a distributed authorization module (if applicable).
  771. * @param $arg
  772. * An array that corresponds to the return of the arg() function - if a module
  773. * needs to provide help for a page with additional parameters after the
  774. * Drupal path or help for a specific value for a wildcard in the path, then
  775. * the values in this array can be referenced. For example you could provide
  776. * help for user/1 by looking for the path user/% and $arg[1] == '1'. This
  777. * array should always be used rather than directly invoking arg(). Note that
  778. * depending on which module is invoking hook_help, $arg may contain only,
  779. * empty strings. Regardless, $arg[0] to $arg[11] will always be set.
  780. * @return
  781. * A localized string containing the help text. Every web link, l(), or
  782. * url() must be replaced with %something and put into the final t()
  783. * call:
  784. * $output .= 'A role defines a group of users that have certain
  785. * privileges as defined in %permission.';
  786. * $output = t($output, array('%permission' => l(t('user permissions'),
  787. * 'admin/user/permission')));
  788. *
  789. * For a detailed usage example, see page_example.module.
  790. */
  791. function hook_help($path, $arg) {
  792. switch ($path) {
  793. case 'admin/help#block':
  794. 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>';
  795. case 'admin/build/block':
  796. 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>
  797. <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>
  798. <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')));
  799. }
  800. }
  801. /**
  802. * Perform setup tasks. See also, hook_init.
  803. *
  804. * This hook is run at the beginning of the page request. It is typically
  805. * used to set up global parameters which are needed later in the request.
  806. *
  807. * Only use this hook if your code must run even for cached page views.This hook
  808. * is called before modules or most include files are loaded into memory.
  809. * It happens while Drupal is still in bootstrap mode.
  810. *
  811. * @return
  812. * None.
  813. */
  814. function hook_boot() {
  815. // we need user_access() in the shutdown function. make sure it gets loaded
  816. drupal_load('module', 'user');
  817. register_shutdown_function('devel_shutdown');
  818. }
  819. /**
  820. * Perform setup tasks. See also, hook_boot.
  821. *
  822. * This hook is run at the beginning of the page request. It is typically
  823. * used to set up global parameters which are needed later in the request.
  824. * when this hook is called, all modules are already loaded in memory.
  825. *
  826. * For example, this hook is a typical place for modules to add CSS or JS
  827. * that should be present on every page. This hook is not run on cached
  828. * pages - though CSS or JS added this way will be present on a cached page.
  829. *
  830. * @return
  831. * None.
  832. */
  833. function hook_init() {
  834. drupal_add_css(drupal_get_path('module', 'book') .'/book.css');
  835. }
  836. /**
  837. * Define internal Drupal links.
  838. *
  839. * This hook enables modules to add links to many parts of Drupal. Links
  840. * may be added in nodes or in the navigation block, for example.
  841. *
  842. * The returned array should be a keyed array of link entries. Each link can
  843. * be in one of two formats.
  844. *
  845. * The first format will use the l() function to render the link:
  846. * - attributes: Optional. See l() for usage.
  847. * - fragment: Optional. See l() for usage.
  848. * - href: Required. The URL of the link.
  849. * - html: Optional. See l() for usage.
  850. * - query: Optional. See l() for usage.
  851. * - title: Required. The name of the link.
  852. *
  853. * The second format can be used for non-links. Leaving out the href index will
  854. * select this format:
  855. * - title: Required. The text or HTML code to display.
  856. * - attributes: Optional. An associative array of HTML attributes to apply to the span tag.
  857. * - html: Optional. If not set to true, check_plain() will be run on the title before it is displayed.
  858. *
  859. * @param $type
  860. * An identifier declaring what kind of link is being requested.
  861. * Possible values:
  862. * - comment: Links to be placed below a comment being viewed.
  863. * - node: Links to be placed below a node being viewed.
  864. * @param $object
  865. * A node object or a comment object according to the $type.
  866. * @param $teaser
  867. * In case of node link: a 0/1 flag depending on whether the node is
  868. * displayed with its teaser or its full form.
  869. * @return
  870. * An array of the requested links.
  871. *
  872. */
  873. function hook_link($type, $object, $teaser = FALSE) {
  874. $links = array();
  875. if ($type == 'node' && isset($object->parent)) {
  876. if (!$teaser) {
  877. if (book_access('create', $object)) {
  878. $links['book_add_child'] = array(
  879. 'title' => t('add child page'),
  880. 'href' => "node/add/book/parent/$object->nid",
  881. );
  882. }
  883. if (user_access('see printer-friendly version')) {
  884. $links['book_printer'] = array(
  885. 'title' => t('printer-friendly version'),
  886. 'href' => 'book/export/html/'. $object->nid,
  887. 'attributes' => array('title' => t('Show a printer-friendly version of this book page and its sub-pages.'))
  888. );
  889. }
  890. }
  891. }
  892. $links['sample_link'] = array(
  893. 'title' => t('go somewhere'),
  894. 'href' => 'node/add',
  895. 'query' => 'foo=bar',
  896. 'fragment' => 'anchorname',
  897. 'attributes' => array('title' => t('go to another page')),
  898. );
  899. // Example of a link that's not an anchor
  900. if ($type == 'video') {
  901. if (variable_get('video_playcounter', 1) && user_access('view play counter')) {
  902. $links['play_counter'] = array(
  903. 'title' => format_plural($object->play_counter, '1 play', '@count plays'),
  904. );
  905. }
  906. }
  907. return $links;
  908. }
  909. /**
  910. * Perform alterations before links on a node are rendered. One popular use of
  911. * this hook is to modify/remove links from other modules. If you want to add a link
  912. * to the links section of a node, use hook_link instead.
  913. *
  914. * @param $links
  915. * Nested array of links for the node keyed by providing module.
  916. * @param $node
  917. * A node object that contains the links.
  918. * @return
  919. * None.
  920. */
  921. function hook_link_alter(&$links, $node) {
  922. foreach ($links as $module => $link) {
  923. if (strstr($module, 'taxonomy_term')) {
  924. // Link back to the forum and not the taxonomy term page
  925. $links[$module]['href'] = str_replace('taxonomy/term', 'forum', $link['href']);
  926. }
  927. }
  928. }
  929. /**
  930. * Perform alterations profile items before they are rendered. You may omit/add/re-sort/re-categorize, etc.
  931. *
  932. * @param $account
  933. * A user object whose profile is being rendered. Profile items
  934. * are stored in $account->content.
  935. * @return
  936. * None.
  937. */
  938. function hook_profile_alter(&$account) {
  939. foreach ($account->content AS $key => $field) {
  940. // do something
  941. }
  942. }
  943. /**
  944. * Alter any aspect of email sent by Drupal. You can use this hook to add a
  945. * common site footer to all outgoing email, add extra header fields, and/or
  946. * modify the email in any way. HTML-izing the outgoing email is one possibility.
  947. * See also drupal_mail().
  948. *
  949. * @param $message
  950. * A structured array containing the message to be altered. Keys in this
  951. * array include:
  952. * - 'id'
  953. * An id to identify the mail sent. Look at module source code or
  954. * drupal_mail() for possible id values.
  955. * - 'to'
  956. * The mail address or addresses the message will be sent to. The
  957. * formatting of this string must comply with RFC 2822.
  958. * - 'subject'
  959. * Subject of the e-mail to be sent. This must not contain any newline
  960. * characters, or the mail may not be sent properly.
  961. * - 'body'
  962. * An array of lines containing the message to be sent. Drupal will format
  963. * the correct line endings for you.
  964. * - 'from'
  965. * The address the message will be marked as being from, which is either a
  966. * custom address or the site-wide default email address.
  967. * - 'headers'
  968. * Associative array containing mail headers, such as From, Sender,
  969. * MIME-Version, Content-Type, etc.
  970. */
  971. function hook_mail_alter(&$message) {
  972. if ($message['id'] == 'my_message') {
  973. $message['body'] .= "\n\n--\nMail sent out from " . variable_get('sitename', t('Drupal'));
  974. }
  975. }
  976. /**
  977. * Define menu items and page callbacks.
  978. *
  979. * This hook enables modules to register paths, which determines whose
  980. * requests are to be handled. Depending on the type of registration
  981. * requested by each path, a link is placed in the the navigation block and/or
  982. * an item appears in the menu administration page (q=admin/menu).
  983. *
  984. * This hook is called rarely - for example when modules are enabled.
  985. *
  986. * @return
  987. * An array of menu items. Each menu item has a key corresponding to the
  988. * Drupal path being registered. The item is an associative array that may
  989. * contain the following key-value pairs:
  990. *
  991. * - "title": Required. The untranslated title of the menu item.
  992. * - "title callback": Function to generate the title, defaults to t().
  993. * If you require only the raw string to be output, set this to FALSE.
  994. * - "title arguments": Arguments to send to t() or your custom callback.
  995. * - "description": The untranslated description of the menu item.
  996. * - "page callback": The function to call to display a web page when the user
  997. * visits the path. If omitted, the parent menu item's callback will be used
  998. * instead.
  999. * - "page arguments": An array of arguments to pass to the page callback
  1000. * function. Integer values pass the corresponding URL component (see arg()).
  1001. * - "access callback": A function returning a boolean value that determines
  1002. * whether the user has access rights to this menu item. Defaults to
  1003. * user_access() unless a value is inherited from a parent menu item..
  1004. * - "access arguments": An array of arguments to pass to the access callback
  1005. * function. Integer values pass the corresponding URL component.
  1006. * - "file": A file that will be included before the callbacks are accessed;
  1007. * this allows callback functions to be in separate files. The file should
  1008. * be relative to the implementing module's directory unless otherwise
  1009. * specified by the "file path" option.
  1010. * - "file path": The path to the folder containing the file specified in
  1011. * "file". This defaults to the path to the module implementing the hook.
  1012. * - "weight": An integer that determines relative position of items in the
  1013. * menu; higher-weighted items sink. Defaults to 0. When in doubt, leave
  1014. * this alone; the default alphabetical order is usually best.
  1015. * - "menu_name": Optional. Set this to a custom menu if you don't want your
  1016. * item to be placed in Navigation.
  1017. * - "type": A bitmask of flags describing properties of the menu item.
  1018. * Many shortcut bitmasks are provided as constants in menu.inc:
  1019. * - MENU_NORMAL_ITEM: Normal menu items show up in the menu tree and can be
  1020. * moved/hidden by the administrator.
  1021. * - MENU_CALLBACK: Callbacks simply register a path so that the correct
  1022. * function is fired when the URL is accessed.
  1023. * - MENU_SUGGESTED_ITEM: Modules may "suggest" menu items that the
  1024. * administrator may enable.
  1025. * - MENU_LOCAL_TASK: Local tasks are rendered as tabs by default.
  1026. * - MENU_DEFAULT_LOCAL_TASK: Every set of local tasks should provide one
  1027. * "default" task, that links to the same path as its parent when clicked.
  1028. * If the "type" key is omitted, MENU_NORMAL_ITEM is assumed.
  1029. *
  1030. * For a detailed usage example, see page_example.module.
  1031. *
  1032. * For comprehensive documentation on the menu system, see
  1033. * @link http://drupal.org/node/102338 http://drupal.org/node/102338 @endlink .
  1034. *
  1035. */
  1036. function hook_menu() {
  1037. $items = array();
  1038. $items['blog'] = array(
  1039. 'title' => 'blogs',
  1040. 'description' => 'Listing of blogs.',
  1041. 'page callback' => 'blog_page',
  1042. 'access arguments' => array('access content'),
  1043. 'type' => MENU_SUGGESTED_ITEM,
  1044. );
  1045. $items['blog/feed'] = array(
  1046. 'title' => 'RSS feed',
  1047. 'page callback' => 'blog_feed',
  1048. 'access arguments' => array('access content'),
  1049. 'type' => MENU_CALLBACK,
  1050. );
  1051. return $items;
  1052. }
  1053. /**
  1054. * Alter the information parsed from module and theme .info files
  1055. *
  1056. * This hook is invoked in module_rebuild_cache() and in system_theme_data().
  1057. * A module may implement this hook in order to add to or alter the data
  1058. * generated by reading the .info file with drupal_parse_info_file().
  1059. *
  1060. * @param &$info
  1061. * The .info file contents, passed by reference so that it can be altered.
  1062. * @param $file
  1063. * Full information about the module or theme, including $file->name, and
  1064. * $file->filename
  1065. */
  1066. function hook_system_info_alter(&$info, $file) {
  1067. // Only fill this in if the .info file does not define a 'datestamp'.
  1068. if (empty($info['datestamp'])) {
  1069. $info['datestamp'] = filemtime($file->filename);
  1070. }
  1071. }
  1072. /**
  1073. * Alter the information about available updates for projects.
  1074. *
  1075. * @param $projects
  1076. * Reference to an array of information about available updates to each
  1077. * project installed on the system.
  1078. *
  1079. * @see update_calculate_project_data()
  1080. */
  1081. function hook_update_status_alter(&$projects) {
  1082. $settings = variable_get('update_advanced_project_settings', array());
  1083. foreach ($projects as $project => $project_info) {
  1084. if (isset($settings[$project]) && isset($settings[$project]['check']) &&
  1085. ($settings[$project]['check'] == 'never' ||
  1086. (isset($project_info['recommended']) &&
  1087. $settings[$project]['check'] === $project_info['recommended']))) {
  1088. $projects[$project]['status'] = UPDATE_NOT_CHECKED;
  1089. $projects[$project]['reason'] = t('Ignored from settings');
  1090. if (!empty($settings[$project]['notes'])) {
  1091. $projects[$project]['extra'][] = array(
  1092. 'class' => 'admin-note',
  1093. 'label' => t('Administrator note'),
  1094. 'data' => $settings[$project]['notes'],
  1095. );
  1096. }
  1097. }
  1098. }
  1099. }
  1100. /**
  1101. * Alter the list of projects before fetching data and comparing versions.
  1102. *
  1103. * Most modules will never need to implement this hook. It is for advanced
  1104. * interaction with the update status module: mere mortals need not apply.
  1105. * The primary use-case for this hook is to add projects to the list, for
  1106. * example, to provide update status data on disabled modules and themes. A
  1107. * contributed module might want to hide projects from the list, for example,
  1108. * if there is a site-specific module that doesn't have any official releases,
  1109. * that module could remove itself from this list to avoid "No available
  1110. * releases found" warnings on the available updates report. In rare cases, a
  1111. * module might want to alter the data associated with a project already in
  1112. * the list.
  1113. *
  1114. * @param $projects
  1115. * Reference to an array of the projects installed on the system. This
  1116. * includes all the metadata documented in the comments below for each
  1117. * project (either module or theme) that is currently enabled. The array is
  1118. * initially populated inside update_get_projects() with the help of
  1119. * _update_process_info_list(), so look there for examples of how to
  1120. * populate the array with real values.
  1121. *
  1122. * @see update_get_projects()
  1123. * @see _update_process_info_list()
  1124. */
  1125. function hook_update_projects_alter(&$projects) {
  1126. // Hide a site-specific module from the list.
  1127. unset($projects['site_specific_module']);
  1128. // Add a disabled module to the list.
  1129. // The key for the array should be the machine-readable project "short name".
  1130. $projects['disabled_project_name'] = array(
  1131. // Machine-readable project short name (same as the array key above).
  1132. 'name' => 'disabled_project_name',
  1133. // Array of values from the main .info file for this project.
  1134. 'info' => array(
  1135. 'name' => 'Some disabled module',
  1136. 'description' => 'A module not enabled on the site that you want to see in the available updates report.',
  1137. 'version' => '6.x-1.0',
  1138. 'core' => '6.x',
  1139. // The maximum file change time (the "ctime" returned by the filectime()
  1140. // PHP method) for all of the .info files included in this project.
  1141. '_info_file_ctime' => 1243888165,
  1142. ),
  1143. // The date stamp when the project was released, if known. If the disabled
  1144. // project was an officially packaged release from drupal.org, this will
  1145. // be included in the .info file as the 'datestamp' field. This only
  1146. // really matters for development snapshot releases that are regenerated,
  1147. // so it can be left undefined or set to 0 in most cases.
  1148. 'datestamp' => 1243888185,
  1149. // Any modules (or themes) included in this project. Keyed by machine-
  1150. // readable "short name", value is the human-readable project name printed
  1151. // in the UI.
  1152. 'includes' => array(
  1153. 'disabled_project' => 'Disabled module',
  1154. 'disabled_project_helper' => 'Disabled module helper module',
  1155. 'disabled_project_foo' => 'Disabled module foo add-on module',
  1156. ),
  1157. // Does this project contain a 'module', 'theme', 'disabled-module', or
  1158. // 'disabled-theme'?
  1159. 'project_type' => 'disabled-module',
  1160. );
  1161. }
  1162. /**
  1163. * Inform the node access system what permissions the user has.
  1164. *
  1165. * This hook is for implementation by node access modules. In addition to
  1166. * managing access rights for nodes, the node access module must tell
  1167. * the node access system what 'grant IDs' the current user has. In many
  1168. * cases, the grant IDs will simply be role IDs, but grant IDs can be
  1169. * arbitrary based upon the module.
  1170. *
  1171. * For example, modules can maintain their own lists of users, where each
  1172. * list has an ID. In that case, the module could return a list of all
  1173. * IDs of all lists that the current user is a member of.
  1174. *
  1175. * A node access module may implement as many realms as necessary to
  1176. * properly define the access privileges for the nodes.
  1177. *
  1178. * @param $account
  1179. * The user object whose grants are requested.
  1180. * @param $op
  1181. * The node operation to be performed, such as "view", "update", or "delete".
  1182. * @return
  1183. * An array whose keys are "realms" of grants such as "user" or "role", and
  1184. * whose values are linear lists of grant IDs.
  1185. *
  1186. * For a detailed example, see node_access_example.module.
  1187. *
  1188. * @ingroup node_access
  1189. */
  1190. function hook_node_grants($account, $op) {
  1191. if (user_access('access private content', $account)) {
  1192. $grants['example'] = array(1);
  1193. }
  1194. $grants['example_owner'] = array($user->uid);
  1195. return $grants;
  1196. }
  1197. /**
  1198. * Set permissions for a node to be written to the database.
  1199. *
  1200. * When a node is saved, a module implementing node access will be asked
  1201. * if it is interested in the access permissions to a node. If it is
  1202. * interested, it must respond with an array of array of permissions for that
  1203. * node.
  1204. *
  1205. * Each item in the array should contain:
  1206. *
  1207. * 'realm'
  1208. * This should only be realms for which the module has returned
  1209. * grant IDs in hook_node_grants.
  1210. * 'gid'
  1211. * This is a 'grant ID', which can have an arbitrary meaning per realm.
  1212. * 'grant_view'
  1213. * If set to TRUE a user with the gid in the realm can view this node.
  1214. * 'grant_edit'
  1215. * If set to TRUE a user with the gid in the realm can edit this node.
  1216. * 'grant_delete'
  1217. * If set to TRUE a user with the gid in the realm can delete this node.
  1218. * 'priority'
  1219. * If multiple modules seek to set permissions on a node, the realms
  1220. * that have the highest priority will win out, and realms with a lower
  1221. * priority will not be written. If there is any doubt, it is best to
  1222. * leave this 0.
  1223. *
  1224. * @ingroup node_access
  1225. */
  1226. function hook_node_access_records($node) {
  1227. if (node_access_example_disabling()) {
  1228. return;
  1229. }
  1230. // We only care about the node if it's been marked private. If not, it is
  1231. // treated just like any other node and we completely ignore it.
  1232. if ($node->private) {
  1233. $grants = array();
  1234. $grants[] = array(
  1235. 'realm' => 'example',
  1236. 'gid' => TRUE,
  1237. 'grant_view' => TRUE,
  1238. 'grant_update' => FALSE,
  1239. 'grant_delete' => FALSE,
  1240. 'priority' => 0,
  1241. );
  1242. // For the example_author array, the GID is equivalent to a UID, which
  1243. // means there are many many groups of just 1 user.
  1244. $grants[] = array(
  1245. 'realm' => 'example_author',
  1246. 'gid' => $node->uid,
  1247. 'grant_view' => TRUE,
  1248. 'grant_update' => TRUE,
  1249. 'grant_delete' => TRUE,
  1250. 'priority' => 0,
  1251. );
  1252. return $grants;
  1253. }
  1254. }
  1255. /**
  1256. * Add mass node operations.
  1257. *
  1258. * This hook enables modules to inject custom operations into the mass operations
  1259. * dropdown found at admin/content/node, by associating a callback function with
  1260. * the operation, which is called when the form is submitted. The callback function
  1261. * receives one initial argument, which is an array of the checked nodes.
  1262. *
  1263. * @return
  1264. * An array of operations. Each operation is an associative array that may
  1265. * contain the following key-value pairs:
  1266. * - "label": Required. The label for the operation, displayed in the dropdown menu.
  1267. * - "callback": Required. The function to call for the operation.
  1268. * - "callback arguments": Optional. An array of additional arguments to pass to
  1269. * the callback function.
  1270. *
  1271. */
  1272. function hook_node_operations() {
  1273. $operations = array(
  1274. 'approve' => array(
  1275. 'label' => t('Approve the selected posts'),
  1276. 'callback' => 'node_operations_approve',
  1277. ),
  1278. 'promote' => array(
  1279. 'label' => t('Promote the selected posts'),
  1280. 'callback' => 'node_operations_promote',
  1281. ),
  1282. 'sticky' => array(
  1283. 'label' => t('Make the selected posts sticky'),
  1284. 'callback' => 'node_operations_sticky',
  1285. ),
  1286. 'demote' => array(
  1287. 'label' => t('Demote the selected posts'),
  1288. 'callback' => 'node_operations_demote',
  1289. ),
  1290. 'unpublish' => array(
  1291. 'label' => t('Unpublish the selected posts'),
  1292. 'callback' => 'node_operations_unpublish',
  1293. ),
  1294. 'delete' => array(
  1295. 'label' => t('Delete the selected posts'),
  1296. ),
  1297. );
  1298. return $operations;
  1299. }
  1300. /**
  1301. * Act on nodes defined by other modules.
  1302. *
  1303. * Despite what its name might make you think, hook_nodeapi() is not
  1304. * reserved for node modules. On the contrary, it allows modules to react
  1305. * to actions affecting all kinds of nodes, regardless of whether that
  1306. * module defined the node.
  1307. *
  1308. * It is common to find hook_nodeapi() used in conjunction with
  1309. * hook_form_alter(). Modules use hook_form_alter() to place additional form
  1310. * elements onto the node edit form, and hook_nodeapi() is used to read and
  1311. * write those values to and from the database.
  1312. *
  1313. * @param &$node
  1314. * The node the action is being performed on.
  1315. * @param $op
  1316. * What kind of action is being performed. Possible values:
  1317. * - "alter": the $node->content array has been rendered, so the node body or
  1318. * teaser is filtered and now contains HTML. This op should only be used when
  1319. * text substitution, filtering, or other raw text operations are necessary.
  1320. * - "delete": The node is being deleted.
  1321. * - "delete revision": The revision of the node is deleted. You can delete data
  1322. * associated with that revision.
  1323. * - "insert": The node is being created (inserted in the database).
  1324. * - "load": The node is about to be loaded from the database. This hook
  1325. * can be used to load additional data at this time.
  1326. * - "prepare": The node is about to be shown on the add/edit form.
  1327. * - "prepare translation": The node is being cloned for translation. Load
  1328. * additional data or copy values from $node->translation_source.
  1329. * - "print": Prepare a node view for printing. Used for printer-friendly
  1330. * view in book_module
  1331. * - "rss item": An RSS feed is generated. The module can return properties
  1332. * to be added to the RSS item generated for this node. See comment_nodeapi()
  1333. * and upload_nodeapi() for examples. The $node passed can also be modified
  1334. * to add or remove contents to the feed item.
  1335. * - "search result": The node is displayed as a search result. If you
  1336. * want to display extra information with the result, return it.
  1337. * - "presave": The node passed validation and is about to be saved. Modules may
  1338. * use this to make changes to the node before it is saved to the database.
  1339. * - "update": The node is being updated.
  1340. * - "update index": The node is being indexed. If you want additional
  1341. * information to be indexed which is not already visible through
  1342. * nodeapi "view", then you should return it here.
  1343. * - "validate": The user has just finished editing the node and is
  1344. * trying to preview or submit it. This hook can be used to check
  1345. * the node data. Errors should be set with form_set_error().
  1346. * - "view": The node content is being assembled before rendering. The module
  1347. * may add elements $node->content prior to rendering. This hook will be
  1348. * called after hook_view(). The format of $node->content is the same as
  1349. * used by Forms API.
  1350. * @param $a3
  1351. * - For "view", passes in the $teaser parameter from node_view().
  1352. * - For "validate", passes in the $form parameter from node_validate().
  1353. * @param $a4
  1354. * - For "view", passes in the $page parameter from node_view().
  1355. * @return
  1356. * This varies depending on the operation.
  1357. * - The "presave", "insert", "update", "delete", "print" and "view"
  1358. * operations have no return value.
  1359. * - The "load" operation should return an array containing pairs
  1360. * of fields => values to be merged into the node object.
  1361. *
  1362. * If you are writing a node module, do not use this hook to perform
  1363. * actions on your type of node alone. Instead, use the hooks set aside
  1364. * for node modules, such as hook_insert() and hook_form(). That said, for
  1365. * some operations, such as "delete revision" or "rss item" there is no
  1366. * corresponding hook so even the module defining the node will need to
  1367. * implement hook_nodeapi().
  1368. */
  1369. function hook_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  1370. switch ($op) {
  1371. case 'presave':
  1372. if ($node->nid && $node->moderate) {
  1373. // Reset votes when node is updated:
  1374. $node->score = 0;
  1375. $node->users = '';
  1376. $node->votes = 0;
  1377. }
  1378. break;
  1379. case 'insert':
  1380. case 'update':
  1381. if ($node->moderate && user_access('access submission queue')) {
  1382. drupal_set_message(t('The post is queued for approval'));
  1383. }
  1384. elseif ($node->moderate) {
  1385. drupal_set_message(t('The post is queued for approval. The editors will decide whether it should be published.'));
  1386. }
  1387. break;
  1388. case 'view':
  1389. $node->content['my_additional_field'] = array(
  1390. '#value' => theme('mymodule_my_additional_field', $additional_field),
  1391. '#weight' => 10,
  1392. );
  1393. break;
  1394. }
  1395. }
  1396. /**
  1397. * Define user permissions.
  1398. *
  1399. * This hook can supply permissions that the module defines, so that they
  1400. * can be selected on the user permissions page and used to restrict
  1401. * access to actions the module performs.
  1402. *
  1403. * @return
  1404. * An array of permissions strings.
  1405. *
  1406. * The permissions in the array must not be wrapped with the function t(),
  1407. * since this could lead to privilege escalation if someone "translated"
  1408. * one permission string into a higher privelege string. The string extractor
  1409. * takes care of extracting permission names defined in the perm hook for
  1410. * translation.
  1411. *
  1412. * Permissions are checked using user_access().
  1413. *
  1414. * For a detailed usage example, see page_example.module.
  1415. */
  1416. function hook_perm() {
  1417. return array('administer my module');
  1418. }
  1419. /**
  1420. * Ping another server.
  1421. *
  1422. * This hook allows a module to notify other sites of updates on your
  1423. * Drupal site.
  1424. *
  1425. * @param $name
  1426. * The name of your Drupal site.
  1427. * @param $url
  1428. * The URL of your Drupal site.
  1429. * @return
  1430. * None.
  1431. */
  1432. function hook_ping($name = '', $url = '') {
  1433. $feed = url('node/feed');
  1434. $client = new xmlrpc_client('/RPC2', 'rpc.weblogs.com', 80);
  1435. $message = new xmlrpcmsg('weblogUpdates.ping',
  1436. array(new xmlrpcval($name), new xmlrpcval($url)));
  1437. $result = $client->send($message);
  1438. if (!$result || $result->faultCode()) {
  1439. watchdog('error', 'failed to notify "weblogs.com" (site)');
  1440. }
  1441. unset($client);
  1442. }
  1443. /**
  1444. * Define a custom search routine.
  1445. *
  1446. * This hook allows a module to perform searches on content it defines
  1447. * (custom node types, users, or comments, for example) when a site search
  1448. * is performed.
  1449. *
  1450. * Note that you can use form API to extend the search. You will need to use
  1451. * hook_form_alter() to add any additional required form elements. You can
  1452. * process their values on submission using a custom validation function.
  1453. * You will need to merge any custom search values into the search keys
  1454. * using a key:value syntax. This allows all search queries to have a clean
  1455. * and permanent URL. See node_form_alter() for an example.
  1456. *
  1457. * The example given here is for node.module, which uses the indexed search
  1458. * capabilities. To do this, node module also implements hook_update_index()
  1459. * which is used to create and maintain the index.
  1460. *
  1461. * We call do_search() with the keys, the module name, and extra SQL fragments
  1462. * to use when searching. See hook_update_index() for more information.
  1463. *
  1464. * @param $op
  1465. * A string defining which operation to perform:
  1466. * - 'admin': The hook should return a form array, containing any fieldsets
  1467. * the module wants to add to the Search settings page at
  1468. * admin/settings/search.
  1469. * - 'name': The hook should return a translated name defining the type of
  1470. * items that are searched for with this module ('content', 'users', ...).
  1471. * - 'reset': The search index is going to be rebuilt. Modules which use
  1472. * hook_update_index() should update their indexing bookkeeping so that it
  1473. * starts from scratch the next time hook_update_index() is called.
  1474. * - 'search': The hook should perform a search using the keywords in $keys.
  1475. * - 'status': If the module implements hook_update_index(), it should return
  1476. * an array containing the following keys:
  1477. * - remaining: The amount of items that still need to be indexed.
  1478. * - total: The total amount of items (both indexed and unindexed).
  1479. * @param $keys
  1480. * The search keywords as entered by the user.
  1481. * @return
  1482. * This varies depending on the operation.
  1483. * - 'admin': The form array for the Search settings page at
  1484. * admin/settings/search.
  1485. * - 'name': The translated string of 'Content'.
  1486. * - 'reset': None.
  1487. * - 'search': An array of search results. To use the default search result
  1488. * display, each item should have the following keys':
  1489. * - 'link': Required. The URL of the found item.
  1490. * - 'type': The type of item.
  1491. * - 'title': Required. The name of the item.
  1492. * - 'user': The author of the item.
  1493. * - 'date': A timestamp when the item was last modified.
  1494. * - 'extra': An array of optional extra information items.
  1495. * - 'snippet': An excerpt or preview to show with the result (can be
  1496. * generated with search_excerpt()).
  1497. * - 'status': An associative array with the key-value pairs:
  1498. * - 'remaining': The number of items left to index.
  1499. * - 'total': The total number of items to index.
  1500. *
  1501. * @ingroup search
  1502. */
  1503. function hook_search($op = 'search', $keys = null) {
  1504. switch ($op) {
  1505. case 'name':
  1506. return t('Content');
  1507. case 'reset':
  1508. db_query("UPDATE {search_dataset} SET reindex = %d WHERE type = 'node'", time());
  1509. return;
  1510. case 'status':
  1511. $total = db_result(db_query('SELECT COUNT(*) FROM {node} WHERE status = 1'));
  1512. $remaining = db_result(db_query("SELECT COUNT(*) FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE n.status = 1 AND (d.sid IS NULL OR d.reindex <> 0)"));
  1513. return array('remaining' => $remaining, 'total' => $total);
  1514. case 'admin':
  1515. $form = array();
  1516. // Output form for defining rank factor weights.
  1517. $form['content_ranking'] = array(
  1518. '#type' => 'fieldset',
  1519. '#title' => t('Content ranking'),
  1520. );
  1521. $form['content_ranking']['#theme'] = 'node_search_admin';
  1522. $form['content_ranking']['info'] = array(
  1523. '#value' => '<em>'. t('The following numbers control which properties the content search should favor when ordering the results. Higher numbers mean more influence, zero means the property is ignored. Changing these numbers does not require the search index to be rebuilt. Changes take effect immediately.') .'</em>'
  1524. );
  1525. $ranking = array('node_rank_relevance' => t('Keyword relevance'),
  1526. 'node_rank_recent' => t('Recently posted'));
  1527. if (module_exists('comment')) {
  1528. $ranking['node_rank_comments'] = t('Number of comments');
  1529. }
  1530. if (module_exists('statistics') && variable_get('statistics_count_content_views', 0)) {
  1531. $ranking['node_rank_views'] = t('Number of views');
  1532. }
  1533. // Note: reversed to reflect that higher number = higher ranking.
  1534. $options = drupal_map_assoc(range(0, 10));
  1535. foreach ($ranking as $var => $title) {
  1536. $form['content_ranking']['factors'][$var] = array(
  1537. '#title' => $title,
  1538. '#type' => 'select',
  1539. '#options' => $options,
  1540. '#default_value' => variable_get($var, 5),
  1541. );
  1542. }
  1543. return $form;
  1544. case 'search':
  1545. // Build matching conditions
  1546. list($join1, $where1) = _db_rewrite_sql();
  1547. $arguments1 = array();
  1548. $conditions1 = 'n.status = 1';
  1549. if ($type = search_query_extract($keys, 'type')) {
  1550. $types = array();
  1551. foreach (explode(',', $type) as $t) {
  1552. $types[] = "n.type = '%s'";
  1553. $arguments1[] = $t;
  1554. }
  1555. $conditions1 .= ' AND ('. implode(' OR ', $types) .')';
  1556. $keys = search_query_insert($keys, 'type');
  1557. }
  1558. if ($category = search_query_extract($keys, 'category')) {
  1559. $categories = array();
  1560. foreach (explode(',', $category) as $c) {
  1561. $categories[] = "tn.tid = %d";
  1562. $arguments1[] = $c;
  1563. }
  1564. $conditions1 .= ' AND ('. implode(' OR ', $categories) .')';
  1565. $join1 .= ' INNER JOIN {term_node} tn ON n.vid = tn.vid';
  1566. $keys = search_query_insert($keys, 'category');
  1567. }
  1568. // Build ranking expression (we try to map each parameter to a
  1569. // uniform distribution in the range 0..1).
  1570. $ranking = array();
  1571. $arguments2 = array();
  1572. $join2 = '';
  1573. // Used to avoid joining on node_comment_statistics twice
  1574. $stats_join = FALSE;
  1575. $total = 0;
  1576. if ($weight = (int)variable_get('node_rank_relevance', 5)) {
  1577. // Average relevance values hover around 0.15
  1578. $ranking[] = '%d * i.relevance';
  1579. $arguments2[] = $weight;
  1580. $total += $weight;
  1581. }
  1582. if ($weight = (int)variable_get('node_rank_recent', 5)) {
  1583. // Exponential decay with half-life of 6 months, starting at last indexed node
  1584. $ranking[] = '%d * POW(2, (GREATEST(MAX(n.created), MAX(n.changed), MAX(c.last_comment_timestamp)) - %d) * 6.43e-8)';
  1585. $arguments2[] = $weight;
  1586. $arguments2[] = (int)variable_get('node_cron_last', 0);
  1587. $join2 .= ' LEFT JOIN {node_comment_statistics} c ON c.nid = i.sid';
  1588. $stats_join = TRUE;
  1589. $total += $weight;
  1590. }
  1591. if (module_exists('comment') && $weight = (int)variable_get('node_rank_comments', 5)) {
  1592. // Inverse law that maps the highest reply count on the site to 1 and 0 to 0.
  1593. $scale = variable_get('node_cron_comments_scale', 0.0);
  1594. $ranking[] = '%d * (2.0 - 2.0 / (1.0 + MAX(c.comment_count) * %f))';
  1595. $arguments2[] = $weight;
  1596. $arguments2[] = $scale;
  1597. if (!$stats_join) {
  1598. $join2 .= ' LEFT JOIN {node_comment_statistics} c ON c.nid = i.sid';
  1599. }
  1600. $total += $weight;
  1601. }
  1602. if (module_exists('statistics') && variable_get('statistics_count_content_views', 0) &&
  1603. $weight = (int)variable_get('node_rank_views', 5)) {
  1604. // Inverse law that maps the highest view count on the site to 1 and 0 to 0.
  1605. $scale = variable_get('node_cron_views_scale', 0.0);
  1606. $ranking[] = '%d * (2.0 - 2.0 / (1.0 + MAX(nc.totalcount) * %f))';
  1607. $arguments2[] = $weight;
  1608. $arguments2[] = $scale;
  1609. $join2 .= ' LEFT JOIN {node_counter} nc ON nc.nid = i.sid';
  1610. $total += $weight;
  1611. }
  1612. // When all search factors are disabled (ie they have a weight of zero),
  1613. // the default score is based only on keyword relevance and there is no need to
  1614. // adjust the score of each item.
  1615. if ($total == 0) {
  1616. $select2 = 'i.relevance AS score';
  1617. $total = 1;
  1618. }
  1619. else {
  1620. $select2 = implode(' + ', $ranking) . ' AS score';
  1621. }
  1622. // Do search.
  1623. $find = do_search($keys, 'node', 'INNER JOIN {node} n ON n.nid = i.sid '. $join1, $conditions1 . (empty($where1) ? '' : ' AND '. $where1), $arguments1, $select2, $join2, $arguments2);
  1624. // Load results.
  1625. $results = array();
  1626. foreach ($find as $item) {
  1627. // Build the node body.
  1628. $node = node_load($item->sid);
  1629. $node->build_mode = NODE_BUILD_SEARCH_RESULT;
  1630. $node = node_build_content($node, FALSE, FALSE);
  1631. $node->body = drupal_render($node->content);
  1632. // Fetch comments for snippet.
  1633. $node->body .= module_invoke('comment', 'nodeapi', $node, 'update index');
  1634. // Fetch terms for snippet.
  1635. $node->body .= module_invoke('taxonomy', 'nodeapi', $node, 'update index');
  1636. $extra = node_invoke_nodeapi($node, 'search result');
  1637. $results[] = array(
  1638. 'link' => url('node/'. $item->sid, array('absolute' => TRUE)),
  1639. 'type' => check_plain(node_get_types('name', $node)),
  1640. 'title' => $node->title,
  1641. 'user' => theme('username', $node),
  1642. 'date' => $node->changed,
  1643. 'node' => $node,
  1644. 'extra' => $extra,
  1645. 'score' => $item->score / $total,
  1646. 'snippet' => search_excerpt($keys, $node->body),
  1647. );
  1648. }
  1649. return $results;
  1650. }
  1651. }
  1652. /**
  1653. * Preprocess text for the search index.
  1654. *
  1655. * This hook is called both for text added to the search index, as well as
  1656. * the keywords users have submitted for searching.
  1657. *
  1658. * This is required for example to allow Japanese or Chinese text to be
  1659. * searched. As these languages do not use spaces, it needs to be split into
  1660. * separate words before it can be indexed. There are various external
  1661. * libraries for this.
  1662. *
  1663. * @param $text
  1664. * The text to split. This is a single piece of plain-text that was
  1665. * extracted from between two HTML tags. Will not contain any HTML entities.
  1666. * @return
  1667. * The text after processing.
  1668. */
  1669. function hook_search_preprocess($text) {
  1670. // Do processing on $text
  1671. return $text;
  1672. }
  1673. /**
  1674. * Act on taxonomy changes.
  1675. *
  1676. * This hook allows modules to take action when the terms and vocabularies
  1677. * in the taxonomy are modified.
  1678. *
  1679. * @param $op
  1680. * What is being done to $array. Possible values:
  1681. * - "delete"
  1682. * - "insert"
  1683. * - "update"
  1684. * @param $type
  1685. * What manner of item $array is. Possible values:
  1686. * - "term"
  1687. * - "vocabulary"
  1688. * @param $array
  1689. * The item on which $op is being performed. Possible values:
  1690. * - for vocabularies, 'insert' and 'update' ops:
  1691. * $form_values from taxonomy_form_vocabulary_submit()
  1692. * - for vocabularies, 'delete' op:
  1693. * $vocabulary from taxonomy_get_vocabulary() cast to an array
  1694. * - for terms, 'insert' and 'update' ops:
  1695. * $form_values from taxonomy_form_term_submit()
  1696. * - for terms, 'delete' op:
  1697. * $term from taxonomy_get_term() cast to an array
  1698. * @return
  1699. * None.
  1700. */
  1701. function hook_taxonomy($op, $type, $array = NULL) {
  1702. if ($type == 'vocabulary' && ($op == 'insert' || $op == 'update')) {
  1703. if (variable_get('forum_nav_vocabulary', '') == ''
  1704. && in_array('forum', $array['nodes'])) {
  1705. // since none is already set, silently set this vocabulary as the
  1706. // navigation vocabulary
  1707. variable_set('forum_nav_vocabulary', $array['vid']);
  1708. }
  1709. }
  1710. }
  1711. /**
  1712. * Register a module (or theme's) theme implementations.
  1713. *
  1714. * Modules and themes implementing this return an array of arrays. The key
  1715. * to each sub-array is the internal name of the hook, and the array contains
  1716. * info about the hook. Each array may contain the following items:
  1717. *
  1718. * - arguments: (required) An array of arguments that this theme hook uses. This
  1719. * value allows the theme layer to properly utilize templates. The
  1720. * array keys represent the name of the variable, and the value will be
  1721. * used as the default value if not specified to the theme() function.
  1722. * These arguments must be in the same order that they will be given to
  1723. * the theme() function.
  1724. * - file: The file the implementation resides in. This file will be included
  1725. * prior to the theme being rendered, to make sure that the function or
  1726. * preprocess function (as needed) is actually loaded; this makes it possible
  1727. * to split theme functions out into separate files quite easily.
  1728. * - path: Override the path of the file to be used. Ordinarily the module or
  1729. * theme path will be used, but if the file will not be in the default path,
  1730. * include it here. This path should be relative to the Drupal root
  1731. * directory.
  1732. * - template: If specified, this theme implementation is a template, and this
  1733. * is the template file <b>without an extension</b>. Do not put .tpl.php
  1734. * on this file; that extension will be added automatically by the default
  1735. * rendering engine (which is PHPTemplate). If 'path', above, is specified,
  1736. * the template should also be in this path.
  1737. * - function: If specified, this will be the function name to invoke for this
  1738. * implementation. If neither file nor function is specified, a default
  1739. * function name will be assumed. For example, if a module registers
  1740. * the 'node' theme hook, 'theme_node' will be assigned to its function.
  1741. * If the chameleon theme registers the node hook, it will be assigned
  1742. * 'chameleon_node' as its function.
  1743. * - pattern: A regular expression pattern to be used to allow this theme
  1744. * implementation to have a dynamic name. The convention is to use __ to
  1745. * differentiate the dynamic portion of the theme. For example, to allow
  1746. * forums to be themed individually, the pattern might be: 'forum__'. Then,
  1747. * when the forum is themed, call: <code>theme(array('forum__'. $tid, 'forum'),
  1748. * $forum)</code>.
  1749. * - preprocess functions: A list of functions used to preprocess this data.
  1750. * Ordinarily this won't be used; it's automatically filled in. By default,
  1751. * for a module this will be filled in as template_preprocess_HOOK. For
  1752. * a theme this will be filled in as phptemplate_preprocess and
  1753. * phptemplate_preprocess_HOOK as well as themename_preprocess and
  1754. * themename_preprocess_HOOK.
  1755. * - override preprocess functions: Set to TRUE when a theme does NOT want the
  1756. * standard preprocess functions to run. This can be used to give a theme
  1757. * FULL control over how variables are set. For example, if a theme wants
  1758. * total control over how certain variables in the page.tpl.php are set,
  1759. * this can be set to true. Please keep in mind that when this is used
  1760. * by a theme, that theme becomes responsible for making sure necessary
  1761. * variables are set.
  1762. * - type: (automatically derived) Where the theme hook is defined:
  1763. * 'module', 'theme_engine', or 'theme'.
  1764. * - theme path: (automatically derived) The directory path of the theme or
  1765. * module, so that it doesn't need to be looked up.
  1766. * - theme paths: (automatically derived) An array of template suggestions where
  1767. * .tpl.php files related to this theme hook may be found.
  1768. *
  1769. * The following parameters are all optional.
  1770. *
  1771. * @param $existing
  1772. * An array of existing implementations that may be used for override
  1773. * purposes. This is primarily useful for themes that may wish to examine
  1774. * existing implementations to extract data (such as arguments) so that
  1775. * it may properly register its own, higher priority implementations.
  1776. * @param $type
  1777. * What 'type' is being processed. This is primarily useful so that themes
  1778. * tell if they are the actual theme being called or a parent theme.
  1779. * May be one of:
  1780. * - module: A module is being checked for theme implementations.
  1781. * - base_theme_engine: A theme engine is being checked for a theme which is a parent of the actual theme being used.
  1782. * - theme_engine: A theme engine is being checked for the actual theme being used.
  1783. * - base_theme: A base theme is being checked for theme implementations.
  1784. * - theme: The actual theme in use is being checked.
  1785. * @param $theme
  1786. * The actual name of theme that is being being checked (mostly only useful for
  1787. * theme engine).
  1788. * @param $path
  1789. * The directory path of the theme or module, so that it doesn't need to be
  1790. * looked up.
  1791. *
  1792. * @return
  1793. * A keyed array of theme hooks.
  1794. */
  1795. function hook_theme($existing, $type, $theme, $path) {
  1796. return array(
  1797. 'forum_display' => array(
  1798. 'arguments' => array('forums' => NULL, 'topics' => NULL, 'parents' => NULL, 'tid' => NULL, 'sortby' => NULL, 'forum_per_page' => NULL),
  1799. ),
  1800. 'forum_list' => array(
  1801. 'arguments' => array('forums' => NULL, 'parents' => NULL, 'tid' => NULL),
  1802. ),
  1803. 'forum_topic_list' => array(
  1804. 'arguments' => array('tid' => NULL, 'topics' => NULL, 'sortby' => NULL, 'forum_per_page' => NULL),
  1805. ),
  1806. 'forum_icon' => array(
  1807. 'arguments' => array('new_posts' => NULL, 'num_posts' => 0, 'comment_mode' => 0, 'sticky' => 0),
  1808. ),
  1809. 'forum_topic_navigation' => array(
  1810. 'arguments' => array('node' => NULL),
  1811. ),
  1812. );
  1813. }
  1814. /**
  1815. * Alter the theme registry information returned from hook_theme().
  1816. *
  1817. * The theme registry stores information about all available theme hooks,
  1818. * including which callback functions those hooks will call when triggered,
  1819. * what template files are exposed by these hooks, and so on.
  1820. *
  1821. * Note that this hook is only executed as the theme cache is re-built.
  1822. * Changes here will not be visible until the next cache clear.
  1823. *
  1824. * The $theme_registry array is keyed by theme hook name, and contains the
  1825. * information returned from hook_theme(), as well as additional properties
  1826. * added by _theme_process_registry().
  1827. *
  1828. * For example:
  1829. * @code
  1830. * $theme_registry['user_profile'] = array(
  1831. * 'arguments' => array(
  1832. * 'account' => NULL,
  1833. * ),
  1834. * 'template' => 'modules/user/user-profile',
  1835. * 'file' => 'modules/user/user.pages.inc',
  1836. * 'type' => 'module',
  1837. * 'theme path' => 'modules/user',
  1838. * 'theme paths' => array(
  1839. * 0 => 'modules/user',
  1840. * ),
  1841. * 'preprocess functions' => array(
  1842. * 0 => 'template_preprocess',
  1843. * 1 => 'template_preprocess_user_profile',
  1844. * ),
  1845. * )
  1846. * );
  1847. * @endcode
  1848. *
  1849. * @param $theme_registry
  1850. * The entire cache of theme registry information, post-processing.
  1851. * @see hook_theme()
  1852. * @see _theme_process_registry()
  1853. */
  1854. function hook_theme_registry_alter(&$theme_registry) {
  1855. // Kill the next/previous forum topic navigation links.
  1856. foreach ($theme_registry['forum_topic_navigation']['preprocess functions'] as $key => $value) {
  1857. if ($value = 'template_preprocess_forum_topic_navigation') {
  1858. unset($theme_registry['forum_topic_navigation']['preprocess functions'][$key]);
  1859. }
  1860. }
  1861. }
  1862. /**
  1863. * Update Drupal's full-text index for this module.
  1864. *
  1865. * Modules can implement this hook if they want to use the full-text indexing
  1866. * mechanism in Drupal.
  1867. *
  1868. * This hook is called every cron run if search.module is enabled. A module
  1869. * should check which of its items were modified or added since the last
  1870. * run. It is advised that you implement a throttling mechanism which indexes
  1871. * at most 'search_cron_limit' items per run (see example below).
  1872. *
  1873. * You should also be aware that indexing may take too long and be aborted if
  1874. * there is a PHP time limit. That's why you should update your internal
  1875. * bookkeeping multiple times per run, preferably after every item that
  1876. * is indexed.
  1877. *
  1878. * Per item that needs to be indexed, you should call search_index() with
  1879. * its content as a single HTML string. The search indexer will analyse the
  1880. * HTML and use it to assign higher weights to important words (such as
  1881. * titles). It will also check for links that point to nodes, and use them to
  1882. * boost the ranking of the target nodes.
  1883. *
  1884. * @ingroup search
  1885. */
  1886. function hook_update_index() {
  1887. $last = variable_get('node_cron_last', 0);
  1888. $limit = (int)variable_get('search_cron_limit', 100);
  1889. $result = db_query_range('SELECT n.nid, c.last_comment_timestamp FROM {node} n LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid WHERE n.status = 1 AND n.moderate = 0 AND (n.created > %d OR n.changed > %d OR c.last_comment_timestamp > %d) ORDER BY GREATEST(n.created, n.changed, c.last_comment_timestamp) ASC', $last, $last, $last, 0, $limit);
  1890. while ($node = db_fetch_object($result)) {
  1891. $last_comment = $node->last_comment_timestamp;
  1892. $node = node_load(array('nid' => $node->nid));
  1893. // We update this variable per node in case cron times out, or if the node
  1894. // cannot be indexed (PHP nodes which call drupal_goto, for example).
  1895. // In rare cases this can mean a node is only partially indexed, but the
  1896. // chances of this happening are very small.
  1897. variable_set('node_cron_last', max($last_comment, $node->changed, $node->created));
  1898. // Get node output (filtered and with module-specific fields).
  1899. if (node_hook($node, 'view')) {
  1900. node_invoke($node, 'view', false, false);
  1901. }
  1902. else {
  1903. $node = node_prepare($node, false);
  1904. }
  1905. // Allow modules to change $node->body before viewing.
  1906. node_invoke_nodeapi($node, 'view', false, false);
  1907. $text = '<h1>'. drupal_specialchars($node->title) .'</h1>'. $node->body;
  1908. // Fetch extra data normally not visible
  1909. $extra = node_invoke_nodeapi($node, 'update index');
  1910. foreach ($extra as $t) {
  1911. $text .= $t;
  1912. }
  1913. // Update index
  1914. search_index($node->nid, 'node', $text);
  1915. }
  1916. }
  1917. /**
  1918. * Act on user account actions.
  1919. *
  1920. * This hook allows modules to react when operations are performed on user
  1921. * accounts.
  1922. *
  1923. * @param $op
  1924. * What kind of action is being performed. Possible values (in alphabetical order):
  1925. * - "after_update": The user object has been updated and changed. Use this if
  1926. * (probably along with 'insert') if you want to reuse some information from
  1927. * the user object.
  1928. * - "categories": A set of user information categories is requested.
  1929. * - "delete": The user account is being deleted. The module should remove its
  1930. * custom additions to the user object from the database.
  1931. * - "form": The user account edit form is about to be displayed. The module
  1932. * should present the form elements it wishes to inject into the form.
  1933. * - "insert": The user account is being added. The module should save its
  1934. * custom additions to the user object into the database and set the saved
  1935. * fields to NULL in $edit.
  1936. * - "load": The user account is being loaded. The module may respond to this
  1937. * and insert additional information into the user object.
  1938. * - "login": The user just logged in.
  1939. * - "logout": The user just logged out.
  1940. * - "register": The user account registration form is about to be displayed.
  1941. * The module should present the form elements it wishes to inject into the
  1942. * form.
  1943. * - "submit": Modify the account before it gets saved.
  1944. * - "update": The user account is being changed. The module should save its
  1945. * custom additions to the user object into the database and set the saved
  1946. * fields to NULL in $edit.
  1947. * - "validate": The user account is about to be modified. The module should
  1948. * validate its custom additions to the user object, registering errors as
  1949. * necessary.
  1950. * - "view": The user's account information is being displayed. The module
  1951. * should format its custom additions for display, and add them to the
  1952. * $account->content array.
  1953. * @param &$edit
  1954. * The array of form values submitted by the user.
  1955. * @param &$account
  1956. * The user object on which the operation is being performed.
  1957. * @param $category
  1958. * The active category of user information being edited.
  1959. * @return
  1960. * This varies depending on the operation.
  1961. * - "categories": A linear array of associative arrays. These arrays have
  1962. * keys:
  1963. * - "name": The internal name of the category.
  1964. * - "title": The human-readable, localized name of the category.
  1965. * - "weight": An integer specifying the category's sort ordering.
  1966. * - "delete": None.
  1967. * - "form", "register": A $form array containing the form elements to display.
  1968. * - "insert": None.
  1969. * - "load": None.
  1970. * - "login": None.
  1971. * - "logout": None.
  1972. * - "submit": None.
  1973. * - "update": None.
  1974. * - "validate": None.
  1975. * - "view": None.
  1976. */
  1977. function hook_user($op, &$edit, &$account, $category = NULL) {
  1978. if ($op == 'form' && $category == 'account') {
  1979. $form['comment_settings'] = array(
  1980. '#type' => 'fieldset',
  1981. '#title' => t('Comment settings'),
  1982. '#collapsible' => TRUE,
  1983. '#weight' => 4);
  1984. $form['comment_settings']['signature'] = array(
  1985. '#type' => 'textarea',
  1986. '#title' => t('Signature'),
  1987. '#default_value' => $edit['signature'],
  1988. '#description' => t('Your signature will be publicly displayed at the end of your comments.'));
  1989. return $form;
  1990. }
  1991. }
  1992. /**
  1993. * Add mass user operations.
  1994. *
  1995. * This hook enables modules to inject custom operations into the mass operations
  1996. * dropdown found at admin/user/user, by associating a callback function with
  1997. * the operation, which is called when the form is submitted. The callback function
  1998. * receives one initial argument, which is an array of the checked users.
  1999. *
  2000. * @return
  2001. * An array of operations. Each operation is an associative array that may
  2002. * contain the following key-value pairs:
  2003. * - "label": Required. The label for the operation, displayed in the dropdown menu.
  2004. * - "callback": Required. The function to call for the operation.
  2005. * - "callback arguments": Optional. An array of additional arguments to pass to
  2006. * the callback function.
  2007. *
  2008. */
  2009. function hook_user_operations() {
  2010. $operations = array(
  2011. 'unblock' => array(
  2012. 'label' => t('Unblock the selected users'),
  2013. 'callback' => 'user_user_operations_unblock',
  2014. ),
  2015. 'block' => array(
  2016. 'label' => t('Block the selected users'),
  2017. 'callback' => 'user_user_operations_block',
  2018. ),
  2019. 'delete' => array(
  2020. 'label' => t('Delete the selected users'),
  2021. ),
  2022. );
  2023. return $operations;
  2024. }
  2025. /**
  2026. * Register XML-RPC callbacks.
  2027. *
  2028. * This hook lets a module register callback functions to be called when
  2029. * particular XML-RPC methods are invoked by a client.
  2030. *
  2031. * @return
  2032. * An array which maps XML-RPC methods to Drupal functions. Each array
  2033. * element is either a pair of method => function or an array with four
  2034. * entries:
  2035. * - The XML-RPC method name (for example, module.function).
  2036. * - The Drupal callback function (for example, module_function).
  2037. * - The method signature is an array of XML-RPC types. The first element
  2038. * of this array is the type of return value and then you should write a
  2039. * list of the types of the parameters. XML-RPC types are the following
  2040. * (See the types at @link http://www.xmlrpc.com/spec http://www.xmlrpc.com/spec @endlink ):
  2041. * - "boolean": 0 (false) or 1 (true).
  2042. * - "double": a floating point number (for example, -12.214).
  2043. * - "int": a integer number (for example, -12).
  2044. * - "array": an array without keys (for example, array(1, 2, 3)).
  2045. * - "struct": an associative array or an object (for example,
  2046. * array('one' => 1, 'two' => 2)).
  2047. * - "date": when you return a date, then you may either return a
  2048. * timestamp (time(), mktime() etc.) or an ISO8601 timestamp. When
  2049. * date is specified as an input parameter, then you get an object,
  2050. * which is described in the function xmlrpc_date
  2051. * - "base64": a string containing binary data, automatically
  2052. * encoded/decoded automatically.
  2053. * - "string": anything else, typically a string.
  2054. * - A descriptive help string, enclosed in a t() function for translation
  2055. * purposes.
  2056. * Both forms are shown in the example.
  2057. */
  2058. function hook_xmlrpc() {
  2059. return array(
  2060. 'drupal.login' => 'drupal_login',
  2061. array(
  2062. 'drupal.site.ping',
  2063. 'drupal_directory_ping',
  2064. array('boolean', 'string', 'string', 'string', 'string', 'string'),
  2065. t('Handling ping request'))
  2066. );
  2067. }
  2068. /**
  2069. * Log an event message
  2070. *
  2071. * This hook allows modules to route log events to custom destinations, such as
  2072. * SMS, Email, pager, syslog, ...etc.
  2073. *
  2074. * @param $log_entry
  2075. * An associative array containing the following keys:
  2076. * - type: The type of message for this entry. For contributed modules, this is
  2077. * normally the module name. Do not use 'debug', use severity WATCHDOG_DEBUG instead.
  2078. * - user: The user object for the user who was logged in when the event happened.
  2079. * - request_uri: The Request URI for the page the event happened in.
  2080. * - referer: The page that referred the use to the page where the event occurred.
  2081. * - ip: The IP address where the request for the page came from.
  2082. * - timestamp: The UNIX timetamp of the date/time the event occurred
  2083. * - severity: One of the following values as defined in RFC 3164 http://www.faqs.org/rfcs/rfc3164.html
  2084. * WATCHDOG_EMERG Emergency: system is unusable
  2085. * WATCHDOG_ALERT Alert: action must be taken immediately
  2086. * WATCHDOG_CRITICAL Critical: critical conditions
  2087. * WATCHDOG_ERROR Error: error conditions
  2088. * WATCHDOG_WARNING Warning: warning conditions
  2089. * WATCHDOG_NOTICE Notice: normal but significant condition
  2090. * WATCHDOG_INFO Informational: informational messages
  2091. * WATCHDOG_DEBUG Debug: debug-level messages
  2092. * - link: an optional link provided by the module that called the watchdog() function.
  2093. * - message: The text of the message to be logged.
  2094. *
  2095. * @return
  2096. * None.
  2097. */
  2098. function hook_watchdog($log_entry) {
  2099. global $base_url, $language;
  2100. $severity_list = array(
  2101. WATCHDOG_EMERG => t('Emergency'),
  2102. WATCHDOG_ALERT => t('Alert'),
  2103. WATCHDOG_CRITICAL => t('Critical'),
  2104. WATCHDOG_ERROR => t('Error'),
  2105. WATCHDOG_WARNING => t('Warning'),
  2106. WATCHDOG_NOTICE => t('Notice'),
  2107. WATCHDOG_INFO => t('Info'),
  2108. WATCHDOG_DEBUG => t('Debug'),
  2109. );
  2110. $to = 'someone@example.com';
  2111. $params = array();
  2112. $params['subject'] = t('[@site_name] @severity_desc: Alert from your web site', array(
  2113. '@site_name' => variable_get('site_name', 'Drupal'),
  2114. '@severity_desc' => $severity_list[$log_entry['severity']]
  2115. ));
  2116. $params['message'] = "\nSite: @base_url";
  2117. $params['message'] .= "\nSeverity: (@severity) @severity_desc";
  2118. $params['message'] .= "\nTimestamp: @timestamp";
  2119. $params['message'] .= "\nType: @type";
  2120. $params['message'] .= "\nIP Address: @ip";
  2121. $params['message'] .= "\nRequest URI: @request_uri";
  2122. $params['message'] .= "\nReferrer URI: @referer_uri";
  2123. $params['message'] .= "\nUser: (@uid) @name";
  2124. $params['message'] .= "\nLink: @link";
  2125. $params['message'] .= "\nMessage: \n\n@message";
  2126. $params['message'] = t($params['message'], array(
  2127. '@base_url' => $base_url,
  2128. '@severity' => $log_entry['severity'],
  2129. '@severity_desc' => $severity_list[$log_entry['severity']],
  2130. '@timestamp' => format_date($log_entry['timestamp']),
  2131. '@type' => $log_entry['type'],
  2132. '@ip' => $log_entry['ip'],
  2133. '@request_uri' => $log_entry['request_uri'],
  2134. '@referer_uri' => $log_entry['referer'],
  2135. '@uid' => $log_entry['user']->uid,
  2136. '@name' => $log_entry['user']->name,
  2137. '@link' => strip_tags($log_entry['link']),
  2138. '@message' => strip_tags($log_entry['message']),
  2139. ));
  2140. drupal_mail('emaillog', 'log', $to, $language, $params);
  2141. }
  2142. /**
  2143. * Prepare a message based on parameters; called from drupal_mail().
  2144. *
  2145. * @param $key
  2146. * An identifier of the mail.
  2147. * @param $message
  2148. * An array to be filled in. Keys in this array include:
  2149. * - 'id':
  2150. * An id to identify the mail sent. Look at module source code
  2151. * or drupal_mail() for possible id values.
  2152. * - 'to':
  2153. * The address or addresses the message will be sent to. The
  2154. * formatting of this string must comply with RFC 2822.
  2155. * - 'subject':
  2156. * Subject of the e-mail to be sent. This must not contain any
  2157. * newline characters, or the mail may not be sent properly.
  2158. * drupal_mail() sets this to an empty string when the hook is invoked.
  2159. * - 'body':
  2160. * An array of lines containing the message to be sent. Drupal will format
  2161. * the correct line endings for you. drupal_mail() sets this to an empty array
  2162. * when the hook is invoked.
  2163. * - 'from':
  2164. * The address the message will be marked as being from, which is set by
  2165. * drupal_mail() to either a custom address or the site-wide default email
  2166. * address when the hook is invoked.
  2167. * - 'headers:
  2168. * Associative array containing mail headers, such as From, Sender, MIME-Version,
  2169. * Content-Type, etc. drupal_mail() pre-fills several headers in this array.
  2170. * @param $params
  2171. * An arbitrary array of parameters set by the caller to drupal_mail.
  2172. */
  2173. function hook_mail($key, &$message, $params) {
  2174. $account = $params['account'];
  2175. $context = $params['context'];
  2176. $variables = array(
  2177. '%site_name' => variable_get('site_name', 'Drupal'),
  2178. '%username' => $account->name,
  2179. );
  2180. if ($context['hook'] == 'taxonomy') {
  2181. $object = $params['object'];
  2182. $vocabulary = taxonomy_vocabulary_load($object->vid);
  2183. $variables += array(
  2184. '%term_name' => $object->name,
  2185. '%term_description' => $object->description,
  2186. '%term_id' => $object->tid,
  2187. '%vocabulary_name' => $vocabulary->name,
  2188. '%vocabulary_description' => $vocabulary->description,
  2189. '%vocabulary_id' => $vocabulary->vid,
  2190. );
  2191. }
  2192. // Node-based variable translation is only available if we have a node.
  2193. if (isset($params['node'])) {
  2194. $node = $params['node'];
  2195. $variables += array(
  2196. '%uid' => $node->uid,
  2197. '%node_url' => url('node/'. $node->nid, array('absolute' => TRUE)),
  2198. '%node_type' => node_get_types('name', $node),
  2199. '%title' => $node->title,
  2200. '%teaser' => $node->teaser,
  2201. '%body' => $node->body,
  2202. );
  2203. }
  2204. $subject = strtr($context['subject'], $variables);
  2205. $body = strtr($context['message'], $variables);
  2206. $message['subject'] .= str_replace(array("\r", "\n"), '', $subject);
  2207. $message['body'][] = drupal_html_to_text($body);
  2208. }
  2209. /**
  2210. * Add a list of cache tables to be cleared.
  2211. *
  2212. * This hook allows your module to add cache table names to the list of cache
  2213. * tables that will be cleared by the Clear button on the Performance page or
  2214. * whenever drupal_flush_all_caches is invoked.
  2215. *
  2216. * @see drupal_flush_all_caches()
  2217. * @see system_clear_cache_submit()
  2218. *
  2219. * @param None.
  2220. *
  2221. * @return
  2222. * An array of cache table names.
  2223. */
  2224. function hook_flush_caches() {
  2225. return array('cache_example');
  2226. }
  2227. /**
  2228. * Allows modules to provide an alternative path for the terms it manages.
  2229. *
  2230. * For vocabularies not maintained by taxonomy.module, give the maintaining
  2231. * module a chance to provide a path for terms in that vocabulary.
  2232. *
  2233. * "Not maintained by taxonomy.module" is misleading. It means that the vocabulary
  2234. * table contains a module name in the 'module' column. Any module may update this
  2235. * column and will then be called to provide an alternative path for the terms
  2236. * it recognizes (manages).
  2237. *
  2238. * This hook should be used rather than hard-coding a "taxonomy/term/xxx" path.
  2239. *
  2240. * @see taxonomy_term_path()
  2241. *
  2242. * @param $term
  2243. * A term object.
  2244. * @return
  2245. * An internal Drupal path.
  2246. */
  2247. function hook_term_path($term) {
  2248. return 'taxonomy/term/'. $term->tid;
  2249. }
  2250. /**
  2251. * Allows modules to define their own text groups that can be translated.
  2252. *
  2253. * @param $op
  2254. * Type of operation. Currently, only supports 'groups'.
  2255. */
  2256. function hook_locale($op = 'groups') {
  2257. switch ($op) {
  2258. case 'groups':
  2259. return array('custom' => t('Custom'));
  2260. }
  2261. }
  2262. /**
  2263. * custom_url_rewrite_outbound is not a hook, it's a function you can add to
  2264. * settings.php to alter all links generated by Drupal. This function is called from url().
  2265. * This function is called very frequently (100+ times per page) so performance is
  2266. * critical.
  2267. *
  2268. * This function should change the value of $path and $options by reference.
  2269. *
  2270. * @param $path
  2271. * The alias of the $original_path as defined in the database.
  2272. * If there is no match in the database it'll be the same as $original_path
  2273. * @param $options
  2274. * An array of link attributes such as querystring and fragment. See url().
  2275. * @param $original_path
  2276. * The unaliased Drupal path that is being linked to.
  2277. */
  2278. function custom_url_rewrite_outbound(&$path, &$options, $original_path) {
  2279. global $user;
  2280. // Change all 'node' to 'article'.
  2281. if (preg_match('|^node(/.*)|', $path, $matches)) {
  2282. $path = 'article'. $matches[1];
  2283. }
  2284. // Create a path called 'e' which lands the user on her profile edit page.
  2285. if ($path == 'user/'. $user->uid .'/edit') {
  2286. $path = 'e';
  2287. }
  2288. }
  2289. /**
  2290. * custom_url_rewrite_inbound is not a hook, it's a function you can add to
  2291. * settings.php to alter incoming requests so they map to a Drupal path.
  2292. * This function is called before modules are loaded and
  2293. * the menu system is initialized and it changes $_GET['q'].
  2294. *
  2295. * This function should change the value of $result by reference.
  2296. *
  2297. * @param $result
  2298. * The Drupal path based on the database. If there is no match in the database it'll be the same as $path.
  2299. * @param $path
  2300. * The path to be rewritten.
  2301. * @param $path_language
  2302. * An optional language code to rewrite the path into.
  2303. */
  2304. function custom_url_rewrite_inbound(&$result, $path, $path_language) {
  2305. global $user;
  2306. // Change all article/x requests to node/x
  2307. if (preg_match('|^article(/.*)|', $path, $matches)) {
  2308. $result = 'node'. $matches[1];
  2309. }
  2310. // Redirect a path called 'e' to the user's profile edit page.
  2311. if ($path == 'e') {
  2312. $result = 'user/'. $user->uid .'/edit';
  2313. }
  2314. }
  2315. /**
  2316. * Perform alterations on translation links.
  2317. *
  2318. * A translation link may need to point to a different path or use a translated
  2319. * link text before going through l(), which will just handle the path aliases.
  2320. *
  2321. * @param $links
  2322. * Nested array of links keyed by language code.
  2323. * @param $path
  2324. * The current path.
  2325. * @return
  2326. * None.
  2327. */
  2328. function hook_translation_link_alter(&$links, $path) {
  2329. global $language;
  2330. if (isset($links[$language])) {
  2331. foreach ($links[$language] as $link) {
  2332. $link['attributes']['class'] .= ' active-language';
  2333. }
  2334. }
  2335. }
  2336. /**
  2337. * @} End of "addtogroup hooks".
  2338. */