[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX] Webmail: ensure that nested table cells are correctly split in pdf...

"Victor Emanouilov \(@kroky\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <68d4ca64c8cd_2cdf520173a@gitlab-sidekiq-low-urgency-cpu-bound-v2-5699cfdd5c-m98qf.mail>

Victor Emanouilov pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
18d1ebd3 by Merci Jacob at 2025-09-25T04:44:01+00:00
[FIX] Webmail: ensure that nested table cells are correctly split in pdf generation process and useless characters are removed
---
* [FIX] Webmail: ensure that nested table cells are correctly split in pdf generation process and useless characters removed

See merge request tikiwiki/tiki!8644

- - - - -


2 changed files:

- lib/pdflib.php
- tiki-webmail.php


Changes:

=====================================
lib/pdflib.php
=====================================
@@ -1170,6 +1170,8 @@ class PdfGenerator
 
     private function checkLargeTables(&$doc)
     {
+        $xpath = new DOMXPath($doc);
+
         //new code to split table large cells
         foreach ($doc->getElementsByTagName('table') as $table) {
             // iterate over each row in the table
@@ -1177,18 +1179,16 @@ class PdfGenerator
             $cloneArr = [];
             foreach ($trs as $tr) {
                 $cloned = 0;
-                foreach ($tr->getElementsByTagName('td') as $td) { // get the columns in this row
-                    if (strlen($td->textContent) > 2000) {
-                        $longValue = $td->nodeValue;
-                        $breaktill = strpos($td->nodeValue, '.', 1000);
+                $directTds = $xpath->query('./td', $tr);
+                foreach ($directTds as $td) { // get the columns in this row
+                    $clones = $this->checkLongTd($td);
+                    if (count($clones)) {
                         if ($cloned == 0) {
-                            $cloneNode = $tr->cloneNode(true);
                             $cloned = 1;
-                            $cloneArr[] = ["node" => $cloneNode,'row' => $tr,'breaktill' => $breaktill];
+                            foreach ($clones as $clone) {
+                                $cloneArr[] = $clone;
+                            }
                         }
-                        $td->textContent = substr($longValue, 0, $breaktill) . '. (cont.)';
-                        $td->setAttribute("style:", "white-space: nowrap");
-                        $td->setAttribute("width", "20%");
                     }
                 }
             }
@@ -1201,6 +1201,33 @@ class PdfGenerator
         $html = @$doc->saveHTML();
     }
 
+    private function checkLongTd(&$td)
+    {
+        $cloneArr = [];
+        $xpath = new DOMXPath($td->ownerDocument);
+        $directTds = $xpath->query('./td', $td);
+        if (count($directTds)) {
+            array_walk(iterator_to_array($directTds), function ($childTd) use (&$cloneArr) {
+                $cloneArr = array_merge($cloneArr, $this->checkLongTd($childTd));
+            });
+        }
+
+        if ($td->nodeType === XML_TEXT_NODE) {
+            if (strlen($td->textContent) > 2000) {
+                $longValue = $td->nodeValue;
+                $breaktill = strpos($td->nodeValue, '.', 1000);
+                $td->textContent = substr($longValue, 0, $breaktill) . '. (cont.)';
+                $td->setAttribute("style:", "white-space: nowrap");
+                $td->setAttribute("width", "20%");
+                $parentTr = $td->parentNode;
+                $cloneNode = $parentTr->cloneNode(true);
+                $cloneArr[] = ['breaktill' => $breaktill, 'node' => $cloneNode, 'row' => $parentTr];
+            }
+        }
+
+        return $cloneArr;
+    }
+
     private function insertNewNodes(&$cloneData, &$table, $start = 1000)
     {
 


=====================================
tiki-webmail.php
=====================================
@@ -108,6 +108,14 @@ if (isset($_POST['display']) && $_POST['display'] == 'pdf') {
         }
         if (isset($_POST['msg_text'])) {
             $msg_text = $_POST['msg_text'];
+            // Remove common email preheader techniques not well handled by PDF generators
+            $patterns = [
+              '/<span[^>]*mcnPreviewText[^>]*>.*?<\/span>/is',
+              '/<div[^>]*max-height:\s*0[^>]*>.*?<\/div>/is',
+              '/<div[^>]*style="[^"]*max-height:\s*0[^"]*"[^>]*>.*?<\/div>/is',
+              '/(?:͏|‌|\x{034F}|\x{200C}|\x{200B}|\x{FEFF})/u', // Remove invisible Unicode chars
+            ];
+            $msg_text = preg_replace($patterns, '', $msg_text);
         }
         if (isset($_POST['header_cc'])) {
             $header_cc = $_POST['header_cc'];



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/18d1ebd3cf50ec77b113a67bd7116b2fd3d0d4c1

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/18d1ebd3cf50ec77b113a67bd7116b2fd3d0d4c1
You're receiving this email because of your account on gitlab.com.

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.