From b95f47a59cde0422e5d9050f5b176093ef5744f3 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Mon, 25 Mar 2024 11:22:33 +0100 Subject: [PATCH] 13177 Fixed multi-span --- .../rest-api/models/VisualConsole/Item.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/pandora_console/include/rest-api/models/VisualConsole/Item.php b/pandora_console/include/rest-api/models/VisualConsole/Item.php index e51b47c97e..2dc3108bd3 100644 --- a/pandora_console/include/rest-api/models/VisualConsole/Item.php +++ b/pandora_console/include/rest-api/models/VisualConsole/Item.php @@ -1859,6 +1859,30 @@ class Item extends CachedModel $save = array_merge($dataModelEncode, $dataEncode); if (!empty($save['label'])) { + // Multi-span problem with TinyMCE. Do not delete. + $dom = new \DOMDocument(); + $dom->loadHTML(io_safe_output($save['label'])); + + // XPath object. + $xpath = new \DOMXPath($dom); + + // Find all span tags with style attribute. + $span_nodes = $xpath->query('//span[@style]'); + + if ($span_nodes->length > 1) { + $style = ''; + foreach ($span_nodes as $span) { + $style .= $span->getAttribute('style'); + } + + $last_span = $span_nodes[($span_nodes->length - 1)]; + + // Set style. + $last_span->setAttribute('style', $style); + + $save['label'] = io_safe_input($dom->saveHTML()); + } + $save['label'] = io_safe_output(io_safe_input(str_replace("'", "\'", $save['label']))); }