initial import from onelab svn codebase
[plewww.git] / modules / help.module
1 <?php
2 // $Id: help.module 144 2007-03-28 07:52:20Z thierry $
3
4 /**
5  * @file
6  * Manages displaying online help.
7  */
8
9 /**
10  * Implementation of hook_menu().
11  */
12 function help_menu($may_cache) {
13   $items = array();
14
15   if ($may_cache) {
16     $admin_access = user_access('access administration pages');
17
18     $items[] = array('path' => 'admin/help', 'title' => t('help'),
19       'callback' => 'help_main',
20       'access' => $admin_access,
21       'weight' => 9);
22
23     foreach (module_implements('help', TRUE) as $module) {
24       $items[] = array('path' => 'admin/help/' . $module,
25         'title' => t($module),
26         'callback' => 'help_page',
27         'type' => MENU_CALLBACK,
28         'access' => $admin_access);
29     }
30   }
31
32   return $items;
33 }
34
35 /**
36  * Menu callback; prints a page listing a glossary of Drupal terminology.
37  */
38 function help_main() {
39   $output = t("
40   <h2>Help topics</h2>
41   <p>Help is available on the following items:</p>
42   %help_pages
43   <h2>Glossary of Drupal terminology</h2>
44   <dl>
45    <dt>Block</dt><dd>A small box containing information or content placed in the left-hand or right-hand sidebar of a web page.</dd>
46    <dt>Comment</dt><dd>A note attached to a node. Usually intended to clarify, explain, criticize, or express an opinion on the original material.</dd>
47    <dt>Moderation</dt>
48    <dd>The activity of making sure a post to a Drupal site fits in with what is expected for that Drupal site.
49     <dl>
50      <dt>Approved</dt><dd>A moderated post which has been accepted by the moderators for publication. (See published).</dd>
51      <dt>Waiting</dt><dd>A moderated post which is still being voted on to be accepted for publication. (See published.)</dd>
52     </dl>
53    </dd>
54    <dt>Node</dt><dd>The basic data unit in Drupal. Everything is a node or an extension of a node.</dd>
55    <dt>Public</dt><dd>See published.</dd>
56    <dt>Published</dt><dd>A node that is viewable by everyone. (See unpublished.)</dd>
57    <dt>Role</dt><dd>A classification users are placed into for the purpose of setting users' permissions.</dd>
58    <dt>Taxonomy</dt><dd>A division of a collection of things into ordered, classified groups. (See <a href=\"%taxonomy\">taxonomy help</a>.)</dd>
59    <dt>Unpublished</dt><dd>A node that is only viewable by administrators and moderators.</dd>
60    <dt>User</dt><dd>A person who has an account at your Drupal site, and is logged in with that account.</dd>
61    <dt>Visitor</dt><dd>A person who does not have an account at your Drupal site or a person who has an account at your Drupal site but is <strong>not</strong> logged in with that account. Also termed \"anonymous user\".</dd>
62   </dl>", array('%help_pages' => help_links_as_list(), '%taxonomy' => url('admin/help/taxonomy')));
63
64   return $output;
65 }
66
67 function help_links_as_list() {
68   $modules = array();
69   foreach (module_implements('help', TRUE) as $module) {
70     if (module_invoke($module, 'help', "admin/help#$module")) {
71       $modules[] = $module;
72     }
73   }
74   sort($modules);
75
76   // Output pretty four-column list
77   $break = ceil(count($modules) / 4);
78   $output = '<div class="help-items"><ul>';
79   foreach ($modules as $i => $module) {
80     $output .= '<li>'. l(t($module), 'admin/help/'. $module) .'</li>';
81     if (($i + 1) % $break == 0) {
82       $output .= '</ul></div><div class="help-items'. ($i + 1 == $break * 3 ? ' help-items-last' : '') .'"><ul>';
83     }
84   }
85   $output .= '</ul></div><br class="clear" />';
86
87   return $output;
88 }
89
90 /**
91  * Implementation of hook_help().
92  */
93 function help_help($section) {
94   switch ($section) {
95     case 'admin/help':
96       $output = t('<p>This guide explains what the various modules in <a href="%Drupal">Drupal</a> do and how to configure them.</p>
97 <p>It is not a substitute for the <a href="%handbook">Drupal handbook</a> available online and should be used in conjunction with it. The online reference handbook might be more up-to-date and has helpful user-contributed comments. It is your definitive reference point for all Drupal documentation.</p>
98 ', array('%Drupal' => 'http://drupal.org', '%handbook' => 'http://drupal.org/handbook'));
99       return $output;
100     case 'admin/help#help':
101       $output = '<p>'. t('The help module displays context sensitive help information. Users can learn how to use modules and accomplish tasks quicker with less errors by clicking on links in provided by the help module.') .'</p>';
102       $output .= t('<p>Modules can make documentation available to other modules with this module. All user help should be presented using this module.  Some examples of help: </p>
103 <ul>
104 <li>The name of a module (unused, but there).</li>
105 <li>The description found on the admin/system/modules page.</li>
106 <li>The module\'s help text, displayed on the admin/help page and through the module\'s individual help link.</li>
107 <li>The help for a distributed authorization module (if applicable).</li>
108 <li>The description of a post type (if applicable).</li>
109 </ul>
110 ');
111       $output .= '<p>'. t('You can not administer the help system.') .'</p>';
112       $output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="%help">Help page</a>.', array('%help' => 'http://drupal.org/handbook/modules/help/')) .'</p>';
113       return $output;
114     case 'admin/modules#description':
115       return t('Manages the display of online help.');
116   }
117 }
118
119 /**
120  * Menu callback; prints a page listing general help for all modules.
121  */
122 function help_page() {
123   $name = arg(2);
124   $output = '';
125   if (module_hook($name, 'help')) {
126     $temp = module_invoke($name, 'help', "admin/help#$name");
127     if (empty($temp)) {
128       $output .= t("No help is available for module %module.", array('%module' => $name));
129     }
130     else {
131       $output .= $temp;
132     }
133   }
134   return $output;
135 }