Forum: drugs-and-users.org (self-hosted SMF). Dev box: 192.168.233.129, /var/www/html. Two branches in play: live SMF 2.0.19 (primary, confirmed fully working as of v2.16) and a separate SMF 2.1 test install at /var/www/html/smf21 (paused, several open items below).
Mod name: pdf_bbcode (class PDFBBCode, file PDFBBC.php). Adds a [pdf][/pdf] BBCode tag rendering a self-hosted Mozilla PDF.js viewer, plus a per-post opt-in toggle ([pdf=autodisplay][/pdf] / [pdf=noautodisplay][/pdf], default off) for auto-embedding every .pdf attachment on that post with no ID needed. Fully separate from an old, abandoned package-manager mod line (Duncan85:PDF_Tag) — that lineage is dead, ignore it entirely.
Current shipped version: v2.16 (naming convention: dot, not underscore — pdf_bbcode_v2.16.zip).
| File | Status | Use it? |
|---|---|---|
PDFBBC.php |
Working, current. Holds validateUrl (URL form), validateAttachment (ID form + auto-detect + autodisplay/noautodisplay toggle), findPdfAttachment(), currentMsgId() (new, replaces dead mechanism), shouldAutoDisplay() (new), button() (rewritten for cross-branch safety, untested on 2.1) |
Yes — current base |
package-info.xml |
Two <install> blocks: 1.0 - 2.0.99 (code-based hook registration + <modification> reference) and 2.1 - 2.1.99 (declarative <hook> tags, 2.1-only, <file> auto-embed patch NOT yet added to this block — see open items) |
Yes |
pdf_register.php / pdf_unregister.php |
2.0.x-only, code-action hook registration. Dead integrate_pre_parsebbc step already fully removed |
Yes |
pdf_display_patch.xml |
Separate <modification>-rooted file (required — SMF rejects inline <file> ops directly under <install>). Flags is_pdf + carries pdf_id_msg through in Display.php's native attachment loop; echoes PDF.js iframe in Display.template.php only if PDFBBCode::shouldAutoDisplay($attachment['pdf_id_msg']) returns true |
Yes |
pdfjs/ (self-hosted PDF.js) |
viewer.mjs hand-edited: scrollModeOnLoad changed -1 → 3 (ScrollMode.PAGE) for single-page/scrollable display |
Yes, don't revert |
pdf_bbcode.english.php, pdf.gif |
No known issues | Yes |
readme.txt |
User-facing usage doc. Needs updating to reflect v2.16's real feature set (toggle tags, revived auto-detect) — not yet updated this session | Update before next distribution |
integrate_pre_parsebbc does not exist at all on the 2.0.19 fork (grep-confirmed). Dead end, permanently abandoned as a mechanism.$context['ila']['msg'], set by the already-installed Post_and_PM_Inline_Attachments (ILA) mod's ILA_Setup(), called directly from inside parse_bbc() itself in Subs.php (line ~1794, confirmed via grep + sed — this fork has Subs.php patched by the ILA mod, not by us). This is reliable on every parse_bbc() call. PDFBBCode::currentMsgId() reads this.loadAttachmentContext() (where the is_pdf flag gets computed) is called early inside parse_bbc() itself (via ILA's own internal chain), i.e. before our own [pdf=...] tags in that same message get parsed. This means a toggle tag CANNOT retroactively change that message's own is_pdf flag computation — but this doesn't matter, because the actual echo/render decision happens later, in Display.template.php at template-render time, by which point every message on the page has already been fully parsed via parse_bbc() (and so every toggle tag has already run). This is why shouldAutoDisplay() is checked in the template's echo condition, not baked into the is_pdf flag itself.<file> search/replace blocks as direct children of <install> (throws Undefined XML attribute: destination). Fix: separate document, root <modification>, referenced via <modification>filename.xml</modification> — confirmed working, this is how pdf_display_patch.xml is structured.Play_Media_Attachments (already installed, working) patches Display.php/Display.template.php directly; verified anchors, confirmed to exist verbatim in Andrew's live files:
Display.php: 'is_approved' => $attachment['approved'],Display.template.php: if ($attachment['is_image']Our patch uses these same two anchors.
$_REQUEST['topic'] instead of unreliable $context['current_topic']. Working.schemeless() helper stripping http(s): from all built URLs. Working.'parameters' regex-matching approach silently failed to populate params on this fork — switched to unparsed_equals_content type (same mechanism [code=php] uses). Working.[pdf=ID][/pdf]) now queries the attachment's real filename before building the iframe; renders nothing (not a broken viewer) if it's not actually a .pdf. Working, tested against a real non-PDF attachment.is_pdf = true purely by filename suffix, confirmed correctly handling multiple PDFs on one post independently.Play_Media_Attachments' own patch to the same loop. Not this mod's bug; not pursued further.integrate_bbc_buttons does exist (Subs-Editor.php ~line 1767) but is called with two args ($context['bbc_tags'], $editor_tag_map), and $context['bbc_tags'] is an array of rows, each a flat array of button-def arrays ('code', 'description', optional 'image'; 'before'/'after' deprecated but not removed). Old code's array_splice($buttons[0], 4, 0, $temp) was fragile and likely the cause of the missing 2.1 button. Fixed (untested) in button(): now appends a whole new row — works identically on 2.0.x and 2.1.x's shared row/button shape.PDFBBC.php and from the hand-patched Display.php trace line (pdfbbc_autotrace.log, confirmed removed from Dev by Andrew, was never part of any installed package)./var/www/html/smf21) — Andrew explicitly paused 2.1 work to finish 2.0.x first.[pdf][/pdf] with literally empty content between tags "vanishes, no autodisplay." Not diagnosed at all yet. Hypothesis (unconfirmed): 2.1's BBC content-matching regex may require 1+ character of content, so an empty tag body never matches unparsed_content. Needs live investigation on 2.1.pdf_display_patch.xml is currently only wired into the 1.0 - 2.0.99 install block in package-info.xml. If/when 2.1 auto-embed is wanted, the same <modification> reference needs adding to the 2.1 - 2.1.99 block too (each <install for="..."> is independent, operations aren't shared automatically) — not yet done, not yet needed since 2.1 work is paused.readme.txt needs updating to reflect v2.16's real feature set (toggle tags exist now, auto-detect actually works via the ila mechanism) — not yet done.Resume SMF 2.1 work: install v2.16 fresh on /var/www/html/smf21 (full clean install, not a file-swap, since the button fix and toggle mechanism are structural), then retest in this order:
[pdf] toolbar button now appear (verifies the button() row-append fix)?[pdf]https://.../file.pdf[/pdf] (plain URL form) render correctly?[pdf][/pdf] vanishes" bug — start by checking 2.1's actual BBC-tag regex/matching code for unparsed_content types to see if it requires non-empty content.