diff options
| author | Lester Caine <lester@lsces.co.uk> | 2026-06-02 13:48:57 +0100 |
|---|---|---|
| committer | Lester Caine <lester@lsces.co.uk> | 2026-06-02 13:48:57 +0100 |
| commit | 22472473056161bf84a2d80f576e116b66fb5633 (patch) | |
| tree | 988a77836a8d37cf8a167236b1e10085fac12944 /edit_image.php | |
| parent | 15c37d5d3be71f19e0d49748569e853b53522372 (diff) | |
| download | fisheye-22472473056161bf84a2d80f576e116b66fb5633.tar.gz fisheye-22472473056161bf84a2d80f576e116b66fb5633.tar.bz2 fisheye-22472473056161bf84a2d80f576e116b66fb5633.zip | |
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 <noreply@anthropic.com>
Diffstat (limited to 'edit_image.php')
| -rwxr-xr-x | edit_image.php | 25 |
1 files changed, 25 insertions, 0 deletions
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' ); |
