dolibarr 21.0.0-beta
documentation.class.php
1<?php
2/* Copyright (C) 2024 Anthony Damhet <a.damhet@progiseize.fr>
3 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
29{
35 public $view = array();
36
42 public $menu = array();
43
49 public $summary = array();
50
54 public $db;
55
56
63 public function __construct(DoliDB $db)
64 {
65 $this->db = $db;
66
67 // https://www.figma.com/community/file/1393171578760389765/dolibarr-ui-ux-kit
68
69 // Menu Constructor
70 $this->setMenu();
71 }
72
78 private function setMenu()
79 {
80 global $hookmanager;
81
82
83 $hookmanager->initHooks(array('uidocumentation'));
84
85 $baseUrl = 'admin/tools/ui';
86
87 // Go back to Dolibarr
88 $this->menu['BackToDolibarr'] = array(
89 'url' => DOL_URL_ROOT,
90 'icon' => 'fas fa-arrow-left pictofixedwidth',
91 'submenu' => array(),
92 );
93
94 // Home for Ui documentation
95 $this->menu['DocumentationHome'] = array(
96 'url' => dol_buildpath($baseUrl.'/index.php', 1),
97 'icon' => 'fas fa-book',
98 'submenu' => array(),
99 );
100
101 // Components
102 $this->menu['Components'] = array(
103 'url' => dol_buildpath($baseUrl.'/components/index.php', 1),
104 'icon' => 'fas fa-th-large',
105 'submenu' => array(
106 'Badges' => array(
107 'url' => dol_buildpath($baseUrl.'/components/badges.php', 1),
108 'icon' => 'fas fa-certificate pictofixedwidth',
109 'submenu' => array(),
110 'summary' => array(
111 'DocBasicUsage' => '#badgesection-basicusage',
112 'DocBadgeContextualVariations' => '#badgesection-contextvariations',
113 'DocBadgeDefaultStatus' => '#badgesection-defaultstatus',
114 'DocBadgePillBadges' => '#badgesection-pill',
115 'DocBadgeDotBadges' => '#badgesection-dot',
116 'DocBadgeLinks' => '#badgesection-links',
117 'DocBadgeHelper' => '#badgesection-dolgetbadge'
118 ),
119 ),
120 'Buttons' => array(
121 'url' => dol_buildpath($baseUrl.'/components/buttons.php', 1),
122 'icon' => 'fas fa-mouse pictofixedwidth',
123 'submenu' => array(),
124 'summary' => array(
125 'DocBasicUsage' => '#buttonsection-basicusage',
126 'DocButtonModal' => '#buttonsection-modals',
127 'DocButtonSubmenu' => '#buttonsection-submenu',
128 ),
129 ),
130 'Progress' => array(
131 'url' => dol_buildpath($baseUrl.'/components/progress-bars.php', 1),
132 'icon' => 'fas fa-battery-half pictofixedwidth',
133 'submenu' => array(),
134 'summary' => array(
135 'DocBasicUsage' => '#progresse-section-basic-usage',
136 'DocColorVariants' => '#progress-section-color',
137 'DocStripedVariants' => '#progresse-section-stripped',
138 ),
139 ),
140 'Event Message' => array(
141 'url' => dol_buildpath($baseUrl.'/components/event-message.php', 1),
142 'icon' => 'fas fa-comments pictofixedwidth',
143 'submenu' => array(),
144 'summary' => array(
145 'DocBasicUsage' => '#seteventmessagesection-basicusage',
146 'DocSetEventMessageContextualVariations' => '#seteventmessagesection-contextvariations',
147 )
148 ),
149 ),
150 'summary' => array(
151 'keySum' => '#keySum'
152 )
153 );
154
155 // Elements
156 $this->menu['Content'] = array(
157 'url' => dol_buildpath($baseUrl.'/content/index.php', 1),
158 'icon' => 'fas fa-th-large',
159 'submenu' => array(
160 'Tables' => array(
161 'url' => dol_buildpath('admin/tools/ui/content/tables.php', 1),
162 'icon' => 'fas fa-table pictofixedwidth',
163 'submenu' => array(),
164 'summary' => array(
165 'DocBasicUsage' => '#tablesection-basicusage',
166 'DocTableWithFilters' => '#tablesection-withfilters'
167 ),
168 ),
169 )
170 );
171
172 $parameters = array(
173 'baseUrl' => $baseUrl,
174 );
175 $action = '';
176
177 $reshook = $hookmanager->executeHooks('setMenu', $parameters, $this, $action);
178 if ($reshook < 0) {
179 return false;
180 }
181 }
182
191 public function docHeader($title = '', $arrayofjs = [], $arrayofcss = [])
192 {
193 global $langs;
194 $title = (!empty($title)) ? dol_escape_htmltag($title) : $langs->trans('Documentation');
195
196 $arrayofcss[] = 'admin/tools/ui/css/documentation.css';
197
198 top_htmlhead('', $title, 0, 0, $arrayofjs, $arrayofcss);
199
200 print '<body class="dolibarr-doc">';
201 }
202
207 public function docFooter()
208 {
209 global $langs;
210
211 // DIV FOR SCROLL ANIMATION
212 print '<div id="documentation-scrollwrapper">';
213 print '<div id="documentation-scroll"></div>';
214 print '</div>';
215
216 // JS
217 print '<script src="'.dol_buildpath('admin/tools/ui/js/documentation.js', 1).'"></script>';
218 print '<script src="'.DOL_URL_ROOT.'/core/js/lib_foot.js.php?lang='.$langs->defaultlang.'"></script>';
219
220 print '</body>';
221 print '</html>';
222
224 }
225
231 public function showSidebar()
232 {
233 print '<div class="doc-sidebar">';
234
235 // LOGO
236 print '<div class="sidebar-logo">';
237 if (is_readable(DOL_DOCUMENT_ROOT.'/theme/dolibarr_logo.svg')) {
238 $urllogo = DOL_URL_ROOT.'/theme/dolibarr_logo.svg';
239 print '<img src="'.$urllogo.'" />';
240 }
241 print '</div>';
242
243 // NAVIGATION
244 print '<nav>';
245 if (!empty($this->menu)) {
246 $this->displayMenu($this->menu);
247 }
248 print '</nav>';
249
250 print '</div>';
251 }
252
260 private function displayMenu($menu, $level = 0)
261 {
262 global $langs;
263 $level++;
264
265 print '<ul>';
266 foreach ($menu as $key => $item) {
267 $levelclass = (!empty($item['submenu'])) ? 'li-withsubmenu' : '';
268 $levelclass .= (in_array($key, $this->view)) ? ' active' : '';
269
270 print '<li class="'.$levelclass.' level-'.$level.'">';
271 print '<a href="'.$item['url'].'" class="'.((!empty($item['submenu'])) ? 'link-withsubmenu' : '').'">';
272 print ((!empty($item['icon'])) ? '<i class="menu-icon '.$item['icon'].'" aria-hidden="true"></i>' : '');
273 print '<span class="label">'.$langs->transnoentities($key).'</span>';
274 print ((!empty($item['submenu'])) ? '<i class="submenu-toggle fas fa-chevron-right" aria-hidden="true"></i>' : '');
275 print '</a>';
276 if (!empty($item['submenu'])) {
277 $this->displayMenu($item['submenu'], $level); // Appel récursif pour afficher les sous-menus
278 }
279 echo '</li>';
280 }
281 print '</ul>';
282 }
283
288 public function showBreadcrumb()
289 {
290 global $langs;
291
292 print '<nav class="doc-breadcrumbs">';
293 print '<ul>';
294 print '<li class="breadcrumb-item"><a href="'.$this->menu['DocumentationHome']['url'].'"><i class="'.$this->menu['DocumentationHome']['icon'].'" aria-hidden="true"></i></a></li>';
295 if (!empty($this->view)) {
296 $nb_entries = count($this->view);
297 $i = 0;
298
299 $menu_entry = $this->menu;
300 foreach ($this->view as $page) {
301 $i++;
302 if ($i < $nb_entries && isset($menu_entry[$page])) {
303 print '<li class="breadcrumb-item"><a href="'.$menu_entry[$page]['url'].'">'.$langs->transnoentities($page).'</a></li>';
304 $menu_entry = $menu_entry[$page]['submenu'];
305 } else {
306 print '<li class="breadcrumb-item">'.$langs->transnoentities($page).'</li>';
307 }
308 }
309 } else {
310 print '<li class="breadcrumb-item">'.$langs->trans('Documentation').'</li>';
311 }
312 print '</ul>';
313 print '</nav>';
314 }
315
323 public function showSummary($showsubmenu = 1, $showsubmenu_summary = 1)
324 {
325 $i = 0;
326 $menu_entry = [];
327 if (!empty($this->view)) :
328 // On se place au bon niveau
329 foreach ($this->view as $view) {
330 $i++;
331 if ($i == 1) {
332 $menu_entry = $this->menu[$view];
333 } else {
334 $menu_entry = $menu_entry['submenu'][$view];
335 }
336 }
337 endif;
338
339 if (!empty($menu_entry['summary']) || !empty($menu_entry['submenu'] && $showsubmenu)) {
340 print '<div class="summary-wrapper">';
341 $this->displaySummary($menu_entry);
342 print '</div>';
343 }
344 }
345
346
356 public function displaySummary($menu, $level = 0, $showsubmenu = 1, $showsubmenu_summary = 1)
357 {
358
359 global $langs;
360
361 $level++;
362 print '<ul class="documentation-summary level-'.$level.'"">';
363
364 if (!empty($menu['summary'])) :
365 foreach ($menu['summary'] as $summary_label => $summary_link) {
366 if ($summary_link[0] == '#') {
367 $summary_link = $menu['url'].$summary_link;
368 }
369
370 print '<li><a href="'.$summary_link.'">'.$langs->trans($summary_label).'</a></li>';
371 }
372 endif;
373
374 if ($showsubmenu && !empty($menu['submenu'])) {
375 foreach ($menu['submenu'] as $key => $item) {
376 print '<li class="summary-title ">';
377 print '<h3 class="level-'.$level.'">'.$key.'</h3>';
378 if ($showsubmenu_summary) {
379 $this->displaySummary($item, $level);
380 }
381 print '</li>';
382 }
383 }
384 print '</ul>';
385 }
386
394 public function showCode($lines = array(), $option = 'html')
395 {
396 require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
397 print '<div class="documentation-code">';
398 $content = implode("\n", $lines) . "\n";
399 $doleditor = new DolEditor(md5($content), $content, '', 0, 'Basic', 'In', true, false, 'ace', 0, '99%', 1);
400 print $doleditor->Create(1, '', false, '', $option);
401 print '</div>';
402 }
403}
Class to manage UI documentation.
showBreadcrumb()
Output breadcrumb.
displayMenu($menu, $level=0)
Recursive function to set Menu.
docHeader($title='', $arrayofjs=[], $arrayofcss=[])
Output header + body.
showSummary($showsubmenu=1, $showsubmenu_summary=1)
Output summary.
docFooter()
Output close body + html.
showCode($lines=array(), $option='html')
Output a View Code area.
showSidebar()
Output sidebar.
__construct(DoliDB $db)
Constructor.
setMenu()
Set Documentation Menu.
displaySummary($menu, $level=0, $showsubmenu=1, $showsubmenu_summary=1)
Recursive function for Automatic Summary.
Class to manage a WYSIWYG editor.
Class to manage Dolibarr database access.
dol_htmloutput_events($disabledoutputofmessages=0)
Print formatted messages to output (Used to show messages on html output).
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs=array(), $arrayofcss=array(), $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Output html header of a page.