From 22472473056161bf84a2d80f576e116b66fb5633 Mon Sep 17 00:00:00 2001 From: Lester Caine Date: Tue, 2 Jun 2026 13:48:57 +0100 Subject: PDF edit: protect text layer, add read-only view and reload option - Preserve liberty_content.data on save: copy existing data into edit before store() so the format verify plugin does not wipe it with null when the textarea is absent from a PDF form submission - Re-extract text layer on demand: reload_pdf checkbox calls mime_pdf_text_extract() via mStorage source_file, mirrors the existing generate_thumbnails pattern in edit_image.php - Template: show extracted text in a read-only scrollable textarea for PDFs (no name attr so not submitted); separate Re-extract checkbox; editable description textarea shown only for non-PDF attachments Co-Authored-By: Claude Sonnet 4.6 --- edit_image.php | 25 +++++++++++++++++++++++++ templates/edit_image.tpl | 16 ++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/edit_image.php b/edit_image.php index 22ae0cb..aaa00e6 100755 --- a/edit_image.php +++ b/edit_image.php @@ -64,6 +64,12 @@ if( !empty($_REQUEST['saveImage']) || !empty($_REQUEST['regenerateThumbnails'] ) } } + $isPdf = !empty( $gContent->mInfo['mime_type'] ) && $gContent->mInfo['mime_type'] === 'application/pdf'; + if( $isPdf && empty( $_REQUEST['reload_pdf'] ) ) { + // Preserve the extracted text layer — don't let an empty edit field wipe liberty_content.data + $_REQUEST['edit'] = $gContent->mInfo['data']; + } + $_REQUEST['purge_from_galleries'] = true; if( $gContent->store($_REQUEST) ) { // refresh all hashes @@ -93,6 +99,25 @@ if( !empty($_REQUEST['saveImage']) || !empty($_REQUEST['regenerateThumbnails'] ) if( !empty( $_REQUEST['generate_thumbnails'] ) ) { $gContent->generateThumbnails(); } + if( $isPdf && !empty( $_REQUEST['reload_pdf'] ) ) { + foreach( $gContent->mStorage as $attachmentId => $attachment ) { + if( !empty( $attachment['source_file'] ) ) { + $reloadHash = [ + 'attachment_id' => $attachmentId, + 'content_id' => $gContent->mContentId, + 'upload' => ['source_file' => $attachment['source_file']], + ]; + \Bitweaver\Liberty\mime_pdf_text_extract( $reloadHash ); + if( !empty( $reloadHash['data'] ) ) { + $gBitSystem->mDb->query( + "UPDATE `".BIT_DB_PREFIX."liberty_content` SET `data` = ? WHERE `content_id` = ?", + [$reloadHash['data'], $gContent->mContentId] + ); + } + break; + } + } + } if( empty( $gContent->mErrors ) ) { // add a refresh parameter to the URL so the thumbnails will properly refresh first go reload header( 'Location: '.$gContent->getDisplayUrl().($gBitSystem->isFeatureActive( 'pretty_urls' ) ? '?' : '&' ).'refresh=1' ); diff --git a/templates/edit_image.tpl b/templates/edit_image.tpl index c2e1913..7ad5c9c 100755 --- a/templates/edit_image.tpl +++ b/templates/edit_image.tpl @@ -40,12 +40,28 @@ {/forminput} + {if $gContent->mInfo.mime_type == 'application/pdf'} +
+ {formlabel label="Extracted Text"} + {forminput} + + {/forminput} +
+
+ {forminput} + {forminput label="checkbox"} + {tr}Re-extract text layer from PDF{/tr} + {/forminput} + {/forminput} +
+ {else}
{formlabel label="Description" for="image-desc"} {forminput} {/forminput}
+ {/if}
{if $gContent->getDownloadUrl()} -- cgit v1.3