[TikiWiki-commits] [Git][tikiwiki/tiki][29.x] [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 | <6914790299935_2ce2fe037720@gitlab-sidekiq-low-urgency-cpu-bound-v2-f8dc7c8b7-g6bwv.mail> |
Victor Emanouilov pushed to branch 29.x at Tiki Wiki CMS Groupware / Tiki
Commits:
35fb41e9 by Merci Jacob at 2025-11-12T12:01:35+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/35fb41e94c36b20a06983589098b10f6a7fb642f
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/35fb41e94c36b20a06983589098b10f6a7fb642f
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