diff --git a/CHANGELOG.md b/CHANGELOG.md index 0dceed799..438db4c27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ Update from Maintenance > Update as usual - this release has three database chan - Markdown files: the menu beside Upload on a client's Files has Import Markdown Files, which makes a document from each .md file picked, named by the heading it starts with or its file name. A document's page has a Markdown button beside PDF, which downloads it as a .md file - rich text documents too. - Markdown pasted into a document's rich text editor - copied from GitHub, VS Code, Obsidian or an AI chat - goes in as formatting. Ctrl+Shift+V pastes it as it is. - A document's page is easier to read: headings in proportion to the text with room between sections, and tables, code and quotes that look part of it. Under its name are its folder, its template, Markdown when it's written in it, and its review - due, or when it's next due - whose menu has Mark Reviewed and how often. The buttons are Edit, Share and Export (PDF, Markdown or Print), with the rest in the ⋮ menu, now including Template. Beside it, Contents marks the section you're reading, and Linked, Versions and History are tabs of one card: Linked shows each kind of record with its count, opening to the list. +- A document's PDF, and a Knowledge Base article's, look like your invoices and the documentation PDF: your logo and company details at the top, then its name with the client, its folder (an article's category) and when it was last updated and by whom, and its summary. Each later page has the client and the name at the top, and every page your company, Confidential (Knowledge Base for an article) and the date at the foot, with the page number. Tables have lines, code is shaded, a checklist shows its boxes, symbols such as ✓ and → show, and a document with headings has them as bookmarks beside the PDF. - Pictures in tickets are kept as files: a screenshot pasted or dropped into a ticket, a reply or a note - by your team, in the client portal or through the API - and the pictures in a client's email are kept with the ticket as files instead of inside its text. A ticket full of screenshots opens quickly, and so do the tickets list and the client portal. Pictures show where they were put and stay out of the ticket's list of files, and emails carry them as before. - Pictures already inside tickets move to files in the background - the new Ticket Pictures job in Maintenance > Cron does a batch every minute until every ticket is done, then keeps an eye on new ones. - Taking a picture out of a reply or the ticket's details when editing it, or redacting it, deletes it - it no longer opens from an old link. Redact now takes a picture selected on its own, as well as text. @@ -29,6 +30,7 @@ Update from Maintenance > Update as usual - this release has three database chan - Documents created or edited through the API no longer get extra backslashes added before quotes and line breaks, and changing only a document's name through the API no longer changes what it says. - Deleting a client deletes its tickets' attachments and pictures, files and all, and their tasks, watchers and history, instead of leaving them behind. +- Pictures saved as WebP show in a client's documentation PDF and a document's PDF instead of being left out. ### Developer Updates @@ -48,6 +50,7 @@ Update from Maintenance > Update as usual - this release has three database chan - ticketPicturesHtml() points the pictures at /client/ticket_attachment.php in the portal, /guest/guest_ticket_attachment.php on the guest page and at the files in a client export; ticketPicturesAsData() puts a ticket's pictures back as data for an email and the task approval page. emailQueue() takes opts ticket_id (the pictures the client can see), and ticketAgentEmailContent() sets $email['ticket_pictures'] for agents' emails (internal notes' too), which emailInlineImages() turns into inline cid: pictures as before. ticketAttachmentsListedSql() keeps inline pictures out of the attachment lists; opening one isn't audit logged. - New cron job ticket_pictures (cron/ticket_pictures.php, every minute): ticketPicturesSweep() goes through tickets then replies whose text has data:image/, 500 ids at a time, for up to 25 seconds a run. - A picture that can't be saved - the folder not writable, the attachment row not going in - stays as data in the text; ticketPicturesFailed() counts them, ticketPicturesSweep() carries on past a ticket or reply that fails, and the Ticket Pictures job logs a warning (Cron-Ticket-Pictures) when there were any. bulk_add_client_ticket keeps its pictures as files straight away; deleting a client deletes its tickets with ticketDeleteForGood(). +- functions/document_pdf.php: DocumentPdf (TCPDF) and documentPdfRender() draw the document and Knowledge Base article PDFs (export_document in agent/post/document.php, export_kb_article in agent/post/kb.php), from documentPdfDocument() / documentPdfKbArticle(), and are sent with billingPdfSend(). documentPdfParts() splits the purified HTML at its top-level headings (inside a Markdown document's wrapper) for the bookmarks, and puts table lines, header cells and code shading in inline styles, which TCPDF reads where it ignores the style block. clientExportPdfImages() is clientExportPdfDocumentHtml()'s image step on its own, for uploads/documents or uploads/kb, and now turns a WebP picture into a PNG. ## [26.12.2] diff --git a/agent/post/document.php b/agent/post/document.php index e2d2bfc64..d340f70ff 100644 --- a/agent/post/document.php +++ b/agent/post/document.php @@ -446,23 +446,10 @@ if (isset($_GET['export_document'])) { logAudit("Document", "Export", "$session_name exported document " . escapeSql($row['document_name']), $client_id, $document_id); - require_once('../libs/TCPDF/tcpdf.php'); - - $pdf = new TCPDF(); - $pdf->SetCreator(PDF_CREATOR); - $pdf->SetAuthor($session_name); - $pdf->SetTitle($row['document_name']); - $pdf->AddPage(); - $pdf->SetFont('helvetica', '', 12); - // A Markdown checklist's boxes as [x] and [ ] - the PDF's font has no box characters - $pdf_content = preg_replace_callback('#[^<]*#', function ($m) { - return empty($m[1]) ? '[ ]' : '[x]'; - }, $row['document_content']); - $pdf->writeHTML('
' . escapeHtml($summary) . '
' : '') - . documentHtmlPurify((string) $row['kb_article_content']), true, false, true, false, ''); - - // The PDF is the response - nothing may follow it - $pdf->Output(preg_replace('/[^A-Za-z0-9 ._-]/', '', $row['kb_article_title']) . '.pdf', 'I'); - exit; + require_once '../functions/document_pdf.php'; + billingPdfSend(documentPdfRender(documentPdfKbArticle($row))); } diff --git a/functions/client_export.php b/functions/client_export.php index 087e55a86..6e37749da 100644 --- a/functions/client_export.php +++ b/functions/client_export.php @@ -1021,25 +1021,42 @@ function clientExportPdfFacts(array $facts, $label_width = 26) { * page. */ function clientExportPdfDocumentHtml($html, $document_id) { - $html = documentHtmlPurify($html); + return clientExportPdfImages(documentHtmlPurify($html), $document_id); +} + +/** + * The images of purified HTML made fit for TCPDF, as above - its own from + * uploads/<$folder>/| ' . $logo . '' . $e($company['company_name'] ?? '') . ' ' . nl2br($e(implode("\n", $from_lines))) . ' |
+ ' . ($kb ? 'KNOWLEDGE BASE' : 'DOCUMENT') . ' + ' . $e(date('M j, Y')) . ' |
+
This ' . ($kb ? 'article' : 'document') . ' has formatting the PDF cannot show, so here is its text.
' + . nl2br($e(clientExportText((string) $item['html'])))); + } + + $name = trim(preg_replace('/[^A-Za-z0-9 ._-]/', '', $title)); + return ['name' => ($name !== '' ? $name : ($kb ? 'Article' : 'Document')) . '.pdf', 'data' => $pdf->Output('', 'S')]; +}