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

"Adrien Mbuya Maloba \(@adrienmaloba\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <6a8847373fe41_3818cf7c63651@gitlab-sidekiq-low-urgency-cpu-bound-v2-59d866f86d-6bg6f.mail>

Adrien Mbuya Maloba pushed to branch 27.x at Tiki Wiki CMS Groupware / Tiki


Commits:
5dbfcb23 by Josaphat Imani at 2026-08-21T15:34:49+03:00
[FIX] Pdflib: Convert PDF cover image url to local path
---
* [FIX] Pdflib: Convert PDF cover image url to local path
---
* [FIX] Pdflib: Convert PDF cover image url to local path
---
* [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

(cherry picked from commit 6063dadb727b08e776d6404eedb91edaa85d623e)

See merge request tikiwiki/tiki!10628

(cherry picked from commit 91e6fdf8d73976dd8c834333a4398fe61ec0fe07)

See merge request tikiwiki/tiki!10746

(cherry picked from commit ddf746f9d9d6071a8196c223bcc27fdad18b84ee)

See merge request tikiwiki/tiki!10902

- - - - -


1 changed file:

- lib/pdflib.php


Changes:

=====================================
lib/pdflib.php
=====================================
@@ -278,6 +278,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;
@@ -937,6 +941,42 @@ class PdfGenerator
         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/5dbfcb23593d6494cb2da9f194a57c0af4f4ebe5

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/5dbfcb23593d6494cb2da9f194a57c0af4f4ebe5
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.