dolibarr 22.0.5
icons.php
1<?php
2/*
3 * Copyright (C) 2024 Anthony Damhet <a.damhet@progiseize.fr>
4 *
5 * This program and files/directory inner it is free software: you can
6 * redistribute it and/or modify it under the terms of the
7 * GNU Affero General Public License (AGPL) as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU AGPL for more details.
15 *
16 * You should have received a copy of the GNU AGPL
17 * along with this program. If not, see <https://www.gnu.org/licenses/agpl-3.0.html>.
18 */
19
20// Load Dolibarr environment
21require '../../../../main.inc.php';
22
30// Protection if external user
31if ($user->socid > 0) {
33}
34
35// Includes
36require_once DOL_DOCUMENT_ROOT . '/admin/tools/ui/class/documentation.class.php';
37
38// Load documentation translations
39$langs->load('uxdocumentation');
40
41//
42$documentation = new Documentation($db);
43
44// Output html head + body - Param is Title
45$documentation->docHeader('Icons', [], ['admin/tools/ui/css/doc-icons.css'], GETPOST('hidenavmenu'));
46
47// Set view for menu and breadcrumb
48// Menu must be set in constructor of documentation class
49$documentation->view = array('Components','Icons');
50$form = new Form($db);
51
52$mode=GETPOST('mode'); // ex : no-btn
53$displayMode = GETPOST('displayMode') == 'kanban' ? 'kanban' : 'icon-only';
54$revertDisplayMode = $displayMode == 'kanban' ? 'icon-only' : 'kanban';
55$revertDisplayName = $displayMode == 'kanban' ? $langs->trans('ViewList') : $langs->trans('ViewKanban');
56$switchDisplayLink = dol_buildpath($documentation->baseUrl . '/components/icons.php', 1) . '?displayMode=' . $revertDisplayMode;
57$switchDisplayLinkIcon = $displayMode == 'kanban' ? 'fa fa-th' : 'fa fa-th-list';
58
59// Output sidebar
60if (!GETPOST('hidenavmenu')) {
61 $documentation->showSidebar();
62}
63?>
64
65<div class="doc-wrapper<?php print GETPOST('hidenavmenu') ? "-bis" : ""; ?>">
66
67 <?php
68 if (!GETPOST('hidenavmenu')) {
69 $documentation->showBreadCrumb();
70 }
71 ?>
72
73 <div class="doc-content-wrapper">
74
75 <h1 class="documentation-title"><?php echo $langs->trans('DocIconsTitle'); ?></h1>
76 <p class="documentation-text"><?php echo $langs->trans('DocIconsMainDescription'); ?></p>
77
78 <!-- Summary -->
79 <?php $documentation->showSummary(); ?>
80
81
82 <!-- List of usage font awesome icon -->
83 <div class="documentation-section" id="img-picto-section-list">
84
85 <?php
86
87 $iconFileName = 'shims.json';
88 $iconFilePath = DOL_DOCUMENT_ROOT . '/theme/common/fontawesome-5/metadata';
89
90 $fontAwesomeIconRaw = file_get_contents($iconFilePath. '/' .$iconFileName);
91 if ($fontAwesomeIconRaw === false) {
92 dol_print_error($db, 'Error missing file '. $iconFilePath . '/' . $iconFileName);
93 }
94
95 $fontAwesomeIcons = json_decode($fontAwesomeIconRaw);
96 if ($fontAwesomeIcons === null) {
97 dol_print_error($db, 'Error decoding '. $iconFilePath . '/' . $iconFileName);
98 }
99 ?>
100
101 <h2 class="documentation-title"><?php echo $langs->trans('DocIconsListImgPicto'); ?></h2>
102 <?php /* <p class="documentation-text"><?php echo $langs->trans('DocDocIconsListDescription'); ?></p>*/ ?>
103
104 <?php print $form->getSearchFilterToolInput(
105 '.documentation-img-picto-icon-list .info-box, .documentation-img-picto-icon-list .doc-icon-list-item',
106 'search-tools-input',
107 '',
108 ['attr' => [
109 'data-no-item-target' => '#img-picto-section-list .search-tool-no-results',
110 ],
111 ]
112 ); ?>
113
114 <div class="right">
115 <?php
116 if ($mode != 'no-btn') {
117 print dolGetButtonTitle($revertDisplayName, '', $switchDisplayLinkIcon, $switchDisplayLink.'#img-picto-section-list', '', 1, ['forcenohideoftext'=>1]);
118 }
119 ?>
120 </div>
121
122 <div class="documentation-example">
123 <div class="documentation-img-picto-icon-list">
124 <?php
125 $arrayofdolibarriconkey = getImgPictoNameList();
126
127 foreach ($arrayofdolibarriconkey as $iconName) {
128 $labelAlt = 'Text on title tag for tooltip';
129
130 if ($displayMode == 'kanban') {
131 $iconCode = img_picto($iconName, $iconName);
132 print '<div class="info-box ">
133 <span class="info-box-icon bg-infobox-expensereport">
134 '.$iconCode.'
135 </span>
136 <div class="info-box-content">
137 <div class="info-box-title" >'. $iconName .'</div>
138 <div class="info-box-lines">
139 <div class="info-box-line spanoverflow nowrap">
140 <div class="inline-block nowraponall">
141 <div class="documentation-code"><pre>'.dol_htmlentities('img_picto(\''.$labelAlt.'\', \''.$iconName.'\')').'</pre></div>
142 </div>
143 </div>
144 </div><!-- /.info-box-lines -->
145 </div><!-- /.info-box-content -->
146 </div>';
147 } else {
148 $tooltip = '<u>'.$langs->trans("DocCodeForMenuOrModuleBuilder").':</u><br>'.$iconName;
149 $tooltip .= '<br><br><u>'.$langs->trans("DocExampleForPHPCode").':</u><br>img_picto(\''.$labelAlt.'\', \''.$iconName.'\')';
150 $iconCode = img_picto($tooltip, $iconName, '', 0, 0, 0, '', 'classfortooltip');
151 print '<span class="doc-icon-list-item">'.$iconCode;
152 print '<span class="doc-icon-hidden-name-for-search">'.$iconName.'</span></span>';
153 }
154 }
155 ?>
156 </div>
157
158 <div class="search-tool-no-results center hidden-search-result" ><?php print $langs->trans('NoResults') ?></div>
159 </div>
160 </div>
161 <!-- -->
162
163
164 <!-- List of usage font awesome icon -->
165 <div class="documentation-section" id="icon-section-list">
166
167 <?php
168
169 $iconFileName = 'shims.json';
170 $iconFilePath = DOL_DOCUMENT_ROOT . '/theme/common/fontawesome-5/metadata';
171
172 $fontAwesomeIconRaw = file_get_contents($iconFilePath. '/' .$iconFileName);
173 if ($fontAwesomeIconRaw === false) {
174 dol_print_error($db, 'Error missing file '. $iconFilePath . '/' . $iconFileName);
175 }
176
177 $fontAwesomeIcons = json_decode($fontAwesomeIconRaw);
178 if ($fontAwesomeIcons === null) {
179 dol_print_error($db, 'Error decoding '. $iconFilePath . '/' . $iconFileName);
180 }
181 ?>
182
183 <h2 class="documentation-title"><?php echo $langs->trans('DocIconsListFontAwesome'); ?></h2>
184 <?php /* <p class="documentation-text"><?php echo $langs->trans('DocDocIconsListDescription'); ?></p>*/ ?>
185
186 <?php print $form->getSearchFilterToolInput('.documentation-fontawesome-icon-list .info-box, .documentation-fontawesome-icon-list .doc-icon-list-item',
187 'search-tools-input',
188 '',
189 ['attr' => [
190 'data-no-item-target' => '#icon-section-list .search-tool-no-results',
191 ],
192 ]
193 ); ?>
194
195 <div class="right">
196 <?php
197 if ($mode != 'no-btn') {
198 print dolGetButtonTitle($revertDisplayName, '', $switchDisplayLinkIcon, $switchDisplayLink.'#icon-section-list', '', 1, ['forcenohideoftext'=>1]);
199 }
200 ?>
201 </div>
202
203 <div class="documentation-example">
204 <div class="documentation-fontawesome-icon-list">
205 <?php
206 $alreadyDisplay = [];
207 if ($fontAwesomeIcons && is_array($fontAwesomeIcons)) {
208 foreach ($fontAwesomeIcons as $iconData) {
209 $class= $iconData[1]??'fa';
210 if (!empty($iconData[2])) {
211 $class.= ' fa-'.$iconData[2];
212 } else {
213 $class.= ' fa-'.$iconData[0];
214 }
215
216 if (in_array($class, $alreadyDisplay)) {
217 continue;
218 }
219
220 $alreadyDisplay[] = $class;
221 $iconCode = '<span class="'.$class.'" ></span>';
222
223 if ($displayMode == 'kanban') {
224 print '<div class="info-box ">
225 <span class="info-box-icon bg-infobox-expensereport">
226 ' . $iconCode . '
227 </span>
228 <div class="info-box-content">
229 <div class="info-box-title" >' . ($iconData[2] ?? ($iconData[0] ?? '')) . '</div>
230 <div class="info-box-lines">
231 <div class="info-box-line spanoverflow nowrap">
232 <div class="inline-block nowraponall">
233 <div class="documentation-code"><pre>' . dol_htmlentities($iconCode) . '</pre></div>
234 </div>
235 </div>
236 </div><!-- /.info-box-lines -->
237 </div><!-- /.info-box-content -->
238 </div>';
239 } else {
240 $tooltip = '<u>'.$langs->trans("DocCodeForMenuOrModuleBuilder").':</u><br>'.$class;
241 print '<span class="doc-icon-list-item classfortooltip" title="'.dol_escape_htmltag($tooltip).'">'.$iconCode.'<span class="doc-icon-hidden-name-for-search">'.$class.'</span></span>';
242 }
243 }
244 }
245 ?>
246 </div>
247
248 <div class="search-tool-no-results center hidden-search-result" ><?php print $langs->trans('NoResults') ?></div>
249 </div>
250 </div>
251 <!-- -->
252 </div>
253 </div>
254
255<?php
256// Output close body + html
257$documentation->docFooter();
Class to manage UI documentation.
Class to manage generation of HTML components Only common components must be here.
info($id)
Load info of user object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
getImgPictoNameList()
Get all usage icon key usable for img_picto(..., key)
dol_htmlentities($string, $flags=ENT_QUOTES|ENT_SUBSTITUTE, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.