dolibarr 22.0.5
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
59 public $baseUrl = 'admin/tools/ui';
60
67 public function __construct(DoliDB $db)
68 {
69 $this->db = $db;
70
71 // https://www.figma.com/community/file/1393171578760389765/dolibarr-ui-ux-kit
72
73 // Menu Constructor
74 $this->setMenu();
75 }
76
82 private function setMenu()
83 {
84 global $hookmanager;
85
86 $hookmanager->initHooks(array('uidocumentation'));
87
88 // Go back to Dolibarr
89 $this->menu['BackToDolibarr'] = array(
90 'url' => DOL_URL_ROOT,
91 'icon' => 'fas fa-arrow-left',
92 'submenu' => array(),
93 );
94
95 // Home for Ui documentation
96 $this->menu['DocumentationHome'] = array(
97 'url' => dol_buildpath($this->baseUrl.'/index.php', 1),
98 'icon' => 'fas fa-book',
99 'submenu' => array(),
100 );
101
102 // Components
103 $this->menu['Components'] = array(
104 'url' => dol_buildpath($this->baseUrl.'/components/index.php', 1),
105 'icon' => 'fas fa-th-large',
106 'submenu' => array(
107 'Badges' => array(
108 'url' => dol_buildpath($this->baseUrl.'/components/badges.php', 1),
109 'icon' => 'fas fa-certificate',
110 'submenu' => array(),
111 'summary' => array(
112 'DocBasicUsage' => '#badgesection-basicusage',
113 'DocBadgeContextualVariations' => '#badgesection-contextvariations',
114 'DocBadgeDefaultStatus' => '#badgesection-defaultstatus',
115 'DocBadgePillBadges' => '#badgesection-pill',
116 'DocBadgeDotBadges' => '#badgesection-dot',
117 'DocBadgeLinks' => '#badgesection-links',
118 'DocBadgeHelper' => '#badgesection-dolgetbadge'
119 ),
120 ),
121 'Buttons' => array(
122 'url' => dol_buildpath($this->baseUrl.'/components/buttons.php', 1),
123 'icon' => 'fas fa-mouse',
124 'submenu' => array(),
125 'summary' => array(
126 'DocBasicUsage' => '#buttonsection-basicusage',
127 'DocButtonModal' => '#buttonsection-modals',
128 'DocButtonSubmenu' => '#buttonsection-submenu',
129 ),
130 ),
131 'Icons' => array(
132 'url' => dol_buildpath($this->baseUrl.'/components/icons.php', 1),
133 'icon' => 'far fa-flag',
134 'submenu' => array(),
135 'summary' => array(
136 'DocIconsList' => '#img-picto-section-list',
137 'DocIconsFontAwesomeList' => '#icon-section-list',
138 ),
139 ),
140 'Progress' => array(
141 'url' => dol_buildpath($this->baseUrl.'/components/progress-bars.php', 1),
142 'icon' => 'fas fa-battery-half',
143 'submenu' => array(),
144 'summary' => array(
145 'DocBasicUsage' => '#progresse-section-basic-usage',
146 'DocColorVariants' => '#progress-section-color',
147 'DocStripedVariants' => '#progresse-section-stripped',
148 ),
149 ),
150 'Event Message' => array(
151 'url' => dol_buildpath($this->baseUrl.'/components/event-message.php', 1),
152 'icon' => 'fas fa-comments',
153 'submenu' => array(),
154 'summary' => array(
155 'DocBasicUsage' => '#seteventmessagesection-basicusage',
156 'DocSetEventMessageContextualVariations' => '#seteventmessagesection-contextvariations',
157 )
158 ),
159 'Inputs' => array(
160 'url' => dol_buildpath($this->baseUrl.'/components/inputs.php', 1),
161 'icon' => 'fas fa-comments',
162 'submenu' => array(),
163 'summary' => array(
164 'DocBasicUsage' => '#setinputssection-basicusage',
165 'DocHelperFunctionsInputUsage' => '#setinputssection-helperfunctions',
166 'DocHelperFunctionsGetSearchFilterToolInput' => '#setinputssection-getSearchFilterToolInput',
167 )
168 ),
169 ),
170 );
171
172 // Elements
173 $this->menu['Content'] = array(
174 'url' => dol_buildpath($this->baseUrl.'/content/index.php', 1),
175 'icon' => 'far fa-file-alt',
176 'submenu' => array(
177 'Tables' => array(
178 'url' => dol_buildpath('admin/tools/ui/content/tables.php', 1),
179 'icon' => 'fas fa-table',
180 'submenu' => array(),
181 'summary' => array(
182 'DocBasicUsage' => '#tablesection-basicusage',
183 'DocTableWithFilters' => '#tablesection-withfilters',
184 'DocTableBeforeFilters' => '#tablesection-beforefilters',
185 'DocTableCSSClass' => '#tablesection-cssclasses',
186 ),
187 ),
188 )
189 );
190
191 // Elements
192 $this->menu['Resources'] = array(
193 'url' => dol_buildpath($this->baseUrl.'/resources/index.php', 1),
194 'icon' => 'fas fa-wrench',
195 'submenu' => array(
196 'Contributing' => array(
197 'url' => dol_buildpath($this->baseUrl.'/resources/contributing.php', 1),
198 'icon' => 'fas fa-code',
199 'submenu' => array(),
200 'summary' => array(
201 'DocContributeStep1' => '#contributesection-step1',
202 'DocContributeStep2' => '#contributesection-step2',
203 'DocContributeStep3' => '#contributesection-step3',
204 ),
205 ),
206 )
207 );
208
209
210
211 // Elements
212 $this->menu['ExperimentalUx'] = array(
213 'url' => dol_buildpath($this->baseUrl.'/experimental/index.php', 1),
214 'icon' => 'fas fa-flask',
215 'submenu' => array(
216 'ExperimentalUxIntroductionMenu' => array(
217 'url' => dol_buildpath($this->baseUrl.'/experimental/index.php', 1),
218 'icon' => 'fas fa-flask',
219 'submenu' => array(),
220 'summary' => array(
221 'Index' => '#top',
222 'ExperimentalUxIntroductionTitle' => '#experimental-ux-introduction',
223 'ExperimentalUxContributionTitle' => '#experimental-ux-contribution',
224 ),
225 ),
226
227 'ExperimentalUxFreezeTooltip' => array(
228 'url' => dol_buildpath($this->baseUrl.'/experimental/experiments/freeze-tooltip/index.php', 1),
229 'icon' => 'fas fa-flask',
230 'submenu' => array(),
231 'summary' => array(),
232 ),
233
234 'ExperimentalUxInputAjaxFeedback' => array(
235 'url' => dol_buildpath($this->baseUrl.'/experimental/experiments/input-feedback/index.php', 1),
236 'icon' => 'fas fa-flask',
237 'submenu' => array(),
238 'summary' => array(),
239 ),
240
241 'ExperimentalUxIntuitiveSelect' => array(
242 'url' => dol_buildpath($this->baseUrl.'/experimental/experiments/intuitive-select/index.php', 1),
243 'icon' => 'fas fa-flask',
244 'submenu' => array(),
245 'summary' => array(),
246 ),
247 )
248 );
249
250 $parameters = array(
251 'baseUrl' => $this->baseUrl,
252 );
253 $action = '';
254
255 $reshook = $hookmanager->executeHooks('setMenu', $parameters, $this, $action);
256 if ($reshook < 0) {
257 return false;
258 }
259 }
260
270 public function docHeader($title = '', $arrayofjs = [], $arrayofcss = [], $hidenavmenu = '')
271 {
272 global $langs;
273 $title = (!empty($title)) ? dol_escape_htmltag($title) : $langs->trans('Documentation');
274
275 $arrayofcss[] = 'admin/tools/ui/css/documentation.css';
276
277 top_htmlhead('', $title, 0, 0, $arrayofjs, $arrayofcss);
278
279 print '<body class="dolibarr-doc'.($hidenavmenu ? "-bis" : "").'">';
280 }
281
286 public function docFooter()
287 {
288 global $langs;
289
290 // DIV FOR SCROLL ANIMATION
291 print '<div id="documentation-scrollwrapper">';
292 print '<div id="documentation-scroll"></div>';
293 print '</div>';
294
295 // JS
296 print '<script src="'.dol_buildpath('admin/tools/ui/js/documentation.js', 1).'"></script>';
297 print '<script src="'.DOL_URL_ROOT.'/core/js/lib_foot.js.php?lang='.$langs->defaultlang.'"></script>';
298
299 print '</body>';
300 print '</html>';
301
303 }
304
310 public function showSidebar()
311 {
312 print '<div class="doc-sidebar">';
313
314 // LOGO
315 print '<div class="sidebar-logo">';
316 if (is_readable(DOL_DOCUMENT_ROOT.'/theme/dolibarr_logo.svg')) {
317 $urllogo = DOL_URL_ROOT.'/theme/dolibarr_logo.svg';
318 print '<img src="'.$urllogo.'" />';
319 }
320 print '</div>';
321
322 // NAVIGATION
323 print '<nav>';
324 if (!empty($this->menu)) {
325 $this->displayMenu($this->menu);
326 }
327 print '</nav>';
328
329 print '</div>';
330 }
331
339 private function displayMenu($menu, $level = 0)
340 {
341 global $langs;
342 $level++;
343
344 print '<ul>';
345 foreach ($menu as $key => $item) {
346 $levelclass = (!empty($item['submenu'])) ? 'li-withsubmenu' : '';
347 $levelclass .= (in_array($key, $this->view)) ? ' active' : '';
348 $levelclass .= ($key == 'BackToDolibarr') ? ' li-withseparator' : '';
349
350 print '<li class="'.trim($levelclass).' level-'.$level.'">';
351 print '<a href="'.$item['url'].'" class="'.((!empty($item['submenu'])) ? 'link-withsubmenu' : '').'">';
352 print ((!empty($item['icon'])) ? '<i class="menu-icon '.$item['icon'].' pictofixedwidth" aria-hidden="true"></i>' : '');
353 print '<span class="label">'.$langs->transnoentities($key).'</span>';
354 print ((!empty($item['submenu'])) ? '<i class="submenu-toggle fas fa-chevron-right" aria-hidden="true"></i>' : '');
355 print '</a>';
356 if (!empty($item['submenu'])) {
357 $this->displayMenu($item['submenu'], $level); // Appel récursif pour afficher les sous-menus
358 }
359 echo '</li>';
360 }
361 print '</ul>';
362 }
363
368 public function showBreadcrumb()
369 {
370 global $langs;
371
372 print '<nav class="doc-breadcrumbs">';
373 print '<ul>';
374 print '<li class="breadcrumb-item"><a href="'.$this->menu['DocumentationHome']['url'].'"><i class="'.$this->menu['DocumentationHome']['icon'].'" aria-hidden="true"></i></a></li>';
375 if (!empty($this->view)) {
376 $nb_entries = count($this->view);
377 $i = 0;
378
379 $menu_entry = $this->menu;
380 foreach ($this->view as $page) {
381 $i++;
382 if ($i < $nb_entries && isset($menu_entry[$page])) {
383 print '<li class="breadcrumb-item"><a href="'.$menu_entry[$page]['url'].'">'.$langs->transnoentities($page).'</a></li>';
384 $menu_entry = $menu_entry[$page]['submenu'];
385 } else {
386 print '<li class="breadcrumb-item">'.$langs->transnoentities($page).'</li>';
387 }
388 }
389 } else {
390 print '<li class="breadcrumb-item">'.$langs->trans('Documentation').'</li>';
391 }
392 print '</ul>';
393 print '</nav>';
394 }
395
403 public function showSummary($showsubmenu = 1, $showsubmenu_summary = 1)
404 {
405 $i = 0;
406 $menu_entry = [];
407 if (!empty($this->view)) {
408 // On se place au bon niveau
409 foreach ($this->view as $view) {
410 $i++;
411 if ($i == 1) {
412 $menu_entry = $this->menu[$view];
413 } else {
414 $menu_entry = $menu_entry['submenu'][$view];
415 }
416 }
417 }
418
419 if (!empty($menu_entry['summary']) || (!empty($menu_entry['submenu']) && $showsubmenu)) {
420 print '<div class="summary-wrapper">';
421 $this->displaySummary($menu_entry);
422 print '</div>';
423 }
424 }
425
426
436 public function displaySummary($menu, $level = 0, $showsubmenu = 1, $showsubmenu_summary = 1)
437 {
438 global $langs;
439
440 $level++;
441 print '<ul class="documentation-summary level-'.$level.'"">';
442
443 if (!empty($menu['summary'])) {
444 foreach ($menu['summary'] as $summary_label => $summary_link) {
445 /*
446 if ($summary_link[0] == '#') {
447 $tmp_summary_link = $menu['url'];
448 if (GETPOSTINT('hidenavmenu')) {
449 $tmp_summary_link .= (strpos($tmp_summary_link, '?') === false ? '?' : '&').'hidenavmenu=1';
450 }
451 if (GETPOSTINT('displayMode')) {
452 $tmp_summary_link .= (strpos($tmp_summary_link, '?') === false ? '?' : '&').'displayMode=1';
453 }
454 $summary_link = $tmp_summary_link;
455 }
456 */
457
458 print '<li><a href="'.$summary_link.'">'.$langs->trans($summary_label).'</a></li>';
459 }
460 }
461
462 if ($showsubmenu && !empty($menu['submenu'])) {
463 foreach ($menu['submenu'] as $key => $item) {
464 print '<li class="summary-title ">';
465 print '<h3 class="level-'.$level.'">'.$langs->trans($key).'</h3>';
466 if ($showsubmenu_summary) {
467 $this->displaySummary($item, $level);
468 }
469 print '</li>';
470 }
471 }
472 print '</ul>';
473 }
474
482 public function showCode($lines = array(), $option = 'html')
483 {
484 require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
485 print '<div class="documentation-code">';
486
487 if (isset($lines[0])) {
488 if ($option === 'html' && strpos(strtolower($lines[0]), '<!doctype') === false) {
489 array_unshift($lines, '<!DOCTYPE html>', '');
490 }
491 }
492
493 $content = implode("\n", $lines) . "\n";
494 $doleditor = new DolEditor(md5($content), $content, '', 0, 'Basic', 'In', true, false, 'ace', 0, '99%', 1);
495 print $doleditor->Create(1, '', false, '', $option);
496 print '</div>';
497 }
498}
Class to manage UI documentation.
showBreadcrumb()
Output breadcrumb.
displayMenu($menu, $level=0)
Recursive function to set Menu.
showSummary($showsubmenu=1, $showsubmenu_summary=1)
Output summary.
docFooter()
Output close body + html.
showCode($lines=array(), $option='html')
Output a View Code area.
docHeader($title='', $arrayofjs=[], $arrayofcss=[], $hidenavmenu='')
Output header + body.
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.