[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX] Pdflib: Convert PDF cover image url to local path

"Victor Emanouilov \(@kroky\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <6a352f18403e6_38196dec299be@gitlab-sidekiq-low-urgency-cpu-bound-v2-798c48c846-wqh6r.mail>

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


Commits:
6063dadb by Josaphat Imani at 2026-06-19T11:40:22+00:00
[FIX] Pdflib: Convert PDF cover image url to local path
---
* [FIX] Pdflib: Convert PDF cover image url to local path

See merge request tikiwiki/tiki!10551

- - - - -


1 changed file:

- lib/pdflib.php


Changes:

=====================================
lib/pdflib.php
=====================================
@@ -319,6 +319,10 @@ class PdfGenerator
         $wikilib = TikiLib::lib('wiki');
         //checking and getting plugin_pdf parameters if set
         $pdfSettings = $this->getPDFSettings($html, $prefs, $params);
+
+        if (! empty($pdfSettings['coverpage_image_settings']) && $pdfSettings['coverpage_image_settings'] !== 'off') {
+            $pdfSettings['coverpage_image_settings'] = $this->resolveFileGalleryImageToLocalPath($pdfSettings['coverpage_image_settings']);
+        }
         //Add page title with content enabled in prefs and page indiviual settings
         if (($prefs['feature_page_title'] == 'y' && isset($params['page']) && $wikilib->get_page_hide_title($params['page']) == 0 && $pdfSettings['pagetitle'] != 'n') || $pdfSettings['pagetitle'] == 'y') {
             $html = '<h1>' . $params['page'] . '</h1>' . $html;
@@ -1072,6 +1076,42 @@ HTML;
         return $pageContent;
     }
 
+    /**
+     * If the given URL points to a Tiki file gallery image, extract its file ID,
+     * resolve the local filesystem path, and return that path
+     * so mPDF can read the image directly without an HTTP round-trip.
+     * Returns the original value unchanged for any other URL or when the file is
+     * not stored locally.
+     */
+    private function resolveFileGalleryImageToLocalPath(string $url): string
+    {
+        global $base_url;
+
+        // Normalize and strip base URL so we can parse both legacy and SEFURL
+        $relative = html_entity_decode(trim($url), ENT_QUOTES);
+
+        if (! empty($base_url) && str_starts_with($relative, $base_url)) {
+            $relative = substr($relative, strlen($base_url));
+        }
+        $relative = ltrim($relative, '/');
+
+        $filegalLib = TikiLib::lib('filegal');
+
+        $fileId = (int) $filegalLib->getLinkFileId($relative);
+
+        if ($fileId > 0) {
+            $file = \Tiki\FileGallery\File::id($fileId);
+            if ($file->exists()) {
+                $wrapper = $file->getWrapper();
+                if ($wrapper->isFileLocal()) {
+                    return $wrapper->getReadableFile();
+                }
+            }
+        }
+
+        return $url;
+    }
+
     public function getPDFSettings($html, $prefs, $params)
     {
         $pdfSettings = [];



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/6063dadb727b08e776d6404eedb91edaa85d623e

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/6063dadb727b08e776d6404eedb91edaa85d623e
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help

_______________________________________________
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.