From e84ea68218e5f82d9ed0170ffa1b03a3a8cbf680 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 15 Oct 2025 18:58:53 +0200 Subject: [PATCH 1/9] FIX wrong getEntiy element name (#35771) --- htdocs/core/boxes/box_last_knowledgerecord.php | 2 +- htdocs/core/boxes/box_last_modified_knowledgerecord.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/boxes/box_last_knowledgerecord.php b/htdocs/core/boxes/box_last_knowledgerecord.php index 9f4d98999ac..cc1b158f356 100644 --- a/htdocs/core/boxes/box_last_knowledgerecord.php +++ b/htdocs/core/boxes/box_last_knowledgerecord.php @@ -93,7 +93,7 @@ class box_last_knowledgerecord extends ModeleBoxes if ($user->hasRight('knowledgemanagement', 'knowledgerecord', 'read')) { $sql = 'SELECT k.rowid as id, k.date_creation, k.ref, k.lang, k.question, k.status as status'; $sql .= " FROM ".MAIN_DB_PREFIX."knowledgemanagement_knowledgerecord as k"; - $sql .= " WHERE k.entity IN (".getEntity('knowledgemanagement').")"; + $sql .= " WHERE k.entity IN (".getEntity('knowledgerecord').")"; if ($user->socid) { $sql .= " AND k.fk_soc= ".((int) $user->socid); diff --git a/htdocs/core/boxes/box_last_modified_knowledgerecord.php b/htdocs/core/boxes/box_last_modified_knowledgerecord.php index c41d141d5e8..cc8c47bf46a 100644 --- a/htdocs/core/boxes/box_last_modified_knowledgerecord.php +++ b/htdocs/core/boxes/box_last_modified_knowledgerecord.php @@ -93,7 +93,7 @@ class box_last_modified_knowledgerecord extends ModeleBoxes if ($user->hasRight('knowledgemanagement', 'knowledgerecord', 'read')) { $sql = 'SELECT k.rowid as id, k.date_creation, k.ref, k.lang, k.question, k.status as status'; $sql .= " FROM ".MAIN_DB_PREFIX."knowledgemanagement_knowledgerecord as k"; - $sql .= " WHERE k.entity IN (".getEntity('knowledgemanagement').")"; + $sql .= " WHERE k.entity IN (".getEntity('knowledgerecord').")"; if ($user->socid) { $sql .= " AND k.fk_soc= ".((int) $user->socid); From f85108b8aca1684ce9cec36cda09901adb322606 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 15 Oct 2025 18:59:33 +0200 Subject: [PATCH 2/9] FIX check if category module is enabled (#35770) --- .../core/modules/modKnowledgeManagement.class.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/htdocs/core/modules/modKnowledgeManagement.class.php b/htdocs/core/modules/modKnowledgeManagement.class.php index d7352647f24..a777585745b 100644 --- a/htdocs/core/modules/modKnowledgeManagement.class.php +++ b/htdocs/core/modules/modKnowledgeManagement.class.php @@ -300,9 +300,9 @@ class modKnowledgeManagement extends DolibarrModules 'langs' => 'knowledgemanagement', 'position' => 101, // Define condition to show or hide menu entry. Use '$conf->knowledgemanagement->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected. - 'enabled' => '$conf->knowledgemanagement->enabled', + 'enabled' => 'isModEnabled("knowledgemanagement")', // Use 'perms'=>'$user->rights->knowledgemanagement->level1->level2' if you want your menu with a permission rules - 'perms' => '$user->rights->knowledgemanagement->knowledgerecord->read', + 'perms' => '$user->hasRight("knowledgemanagement", "knowledgerecord", "read")', 'target' => '', // 0=Menu for internal users, 1=external users, 2=both 'user' => 2, @@ -320,9 +320,9 @@ class modKnowledgeManagement extends DolibarrModules 'langs' => 'knowledgemanagement', 'position' => 111, // Define condition to show or hide menu entry. Use '$conf->knowledgemanagement->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected. - 'enabled' => '$conf->knowledgemanagement->enabled', + 'enabled' => 'isModEnabled("knowledgemanagement")', // Use 'perms'=>'$user->rights->knowledgemanagement->level1->level2' if you want your menu with a permission rules - 'perms' => '$user->rights->knowledgemanagement->knowledgerecord->read', + 'perms' => '$user->hasRight("knowledgemanagement", "knowledgerecord", "read")', 'target' => '', // 0=Menu for internal users, 1=external users, 2=both 'user' => 2, @@ -340,7 +340,7 @@ class modKnowledgeManagement extends DolibarrModules 'langs' => 'knowledgemanagement', 'position' => 110, // Define condition to show or hide menu entry. Use '$conf->knowledgemanagement->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected. - 'enabled' => '$conf->knowledgemanagement->enabled', + 'enabled' => 'isModEnabled("knowledgemanagement")', // Use 'perms'=>'$user->rights->knowledgemanagement->level1->level2' if you want your menu with a permission rules 'perms' => '$user->hasRight("knowledgemanagement", "knowledgerecord", "write")', 'target' => '', @@ -355,8 +355,8 @@ class modKnowledgeManagement extends DolibarrModules 'url' => '/categories/index.php?type=13', 'langs' => 'knowledgemanagement', 'position' => 112, - 'enabled' => '$conf->knowledgemanagement->enabled', - 'perms' => '$user->rights->knowledgemanagement->knowledgerecord->read', + 'enabled' => 'isModEnabled("knowledgemanagement") && isModenabled("category")', + 'perms' => '$user->hasRight("knowledgemanagement", "knowledgerecord", "read")', 'target' => '', 'user' => 0 ); From ef445760790d962b1a5ef4ee4e8f995ecdf43915 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 16 Oct 2025 21:13:00 +0200 Subject: [PATCH 3/9] Fix bad test on non existing $result --- htdocs/core/actions_setnotes.inc.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/htdocs/core/actions_setnotes.inc.php b/htdocs/core/actions_setnotes.inc.php index ac8c65a0670..c536e383870 100644 --- a/htdocs/core/actions_setnotes.inc.php +++ b/htdocs/core/actions_setnotes.inc.php @@ -47,7 +47,9 @@ if ($action == 'setnote_public' && !empty($permissionnote) && !GETPOST('cancel', $object->fetch($id); // Fetch may not be already done } - $result_update = $object->update_note(dol_html_entity_decode(GETPOST('note_public', 'restricthtml'), ENT_QUOTES | ENT_HTML5, 'UTF-8', 1), '_public'); + $notePublic = GETPOST('note_public', 'restricthtml'); + + $result_update = $object->update_note(dol_html_entity_decode($notePublic, ENT_QUOTES | ENT_HTML5, 'UTF-8', 1), '_public'); if ($result_update < 0) { setEventMessages($object->error, $object->errors, 'errors'); @@ -82,10 +84,6 @@ if ($action == 'setnote_public' && !empty($permissionnote) && !GETPOST('cancel', if ($resultGenDoc < 0) { setEventMessages($object->error, $object->errors, 'warnings'); } - - if ($result < 0) { - dol_print_error($db, $object->error, $object->errors); - } } } } elseif ($action == 'setnote_private' && !empty($permissionnote) && !GETPOST('cancel', 'alpha')) { // Set public note @@ -97,7 +95,10 @@ if ($action == 'setnote_public' && !empty($permissionnote) && !GETPOST('cancel', if (empty($object->id)) { $object->fetch($id); // Fetch may not be already done } - $result = $object->update_note(dol_html_entity_decode(GETPOST('note_private', 'restricthtml'), ENT_QUOTES | ENT_HTML5, 'UTF-8', 1), '_private'); + + $notePrivate = GETPOST('note_private', 'restricthtml'); + + $result = $object->update_note(dol_html_entity_decode($notePrivate, ENT_QUOTES | ENT_HTML5, 'UTF-8', 1), '_private'); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } From 5d3c80e0afcb22c4be5fad3adda32ab0f0e2a185 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 16 Oct 2025 21:19:00 +0200 Subject: [PATCH 4/9] FIx try a better fo for #35792 --- htdocs/core/lib/functions.lib.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 19380ee10bd..127f048cf5f 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -8793,6 +8793,12 @@ function dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox = 0, $check = ' do { $oldstringtoclean = $out; + $outishtml = 0; + if (dol_textishtml($out)) { + $outishtml = 1; + } + + // HTML sanitizer by DOMDocument if (!empty($out) && getDolGlobalString('MAIN_RESTRICTHTML_ONLY_VALID_HTML') && $check != 'restricthtmlallowunvalid') { try { libxml_use_internal_errors(false); // Avoid to fill memory with xml errors @@ -8809,7 +8815,7 @@ function dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox = 0, $check = ' // like 'abc' that wrongly ends up, without the trick, with '

abc

' // Add also a trick to solve utf8 lost. // I don't know what the xml encoding is the trick for - if (dol_textishtml($out)) { + if ($outishtml) { //$out = '
'.$out.'
'; $out = '
'.$out.'
'; //$out = '
'.$out.'
'; @@ -8832,6 +8838,10 @@ function dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox = 0, $check = ' // $out = preg_replace('/^<\?xml encoding="UTF-8">
/', '', $out); // $out = preg_replace('/<\/div>$/', '', $out); // var_dump('rrrrrrrrrrrrrrrrrrrrrrrrrrrrr'.$out); + + if (!$outishtml) { // If $out was not HTML content we made before a dol_nl2br so we must do the opposite operation now + $out = str_replace('
', '', $out); + } } catch (Exception $e) { // If error, invalid HTML string with no way to clean it //print $e->getMessage(); @@ -8839,8 +8849,10 @@ function dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox = 0, $check = ' } } - if (!empty($out) && getDolGlobalString('MAIN_RESTRICTHTML_ONLY_VALID_HTML_TIDY') && !in_array($check, array('restricthtmlallowunvalid', 'restricthtmlallowlinkscript'))) { - // Tidy can't be used for restricthtmlallowunvalid and restricthtmlallowlinkscript + // HTML sanitizer by Tidy + // Tidy can't be used for restricthtmlallowunvalid and restricthtmlallowlinkscript + // Tidy can't be used for non html text content as it is corrupting the new lines fields. + if (!empty($out) && getDolGlobalString('MAIN_RESTRICTHTML_ONLY_VALID_HTML_TIDY') && !in_array($check, array('restricthtmlallowunvalid', 'restricthtmlallowlinkscript')) && $outishtml) { // TODO Try to implement a hack for restricthtmlallowlinkscript by renaming tag and