summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xedit_image.php25
-rwxr-xr-xtemplates/edit_image.tpl16
2 files changed, 41 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' );
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}
</div>
+ {if $gContent->mInfo.mime_type == 'application/pdf'}
+ <div class="form-group">
+ {formlabel label="Extracted Text"}
+ {forminput}
+ <textarea class="input-xlarge" rows="6" cols="50" readonly="readonly">{$gContent->mInfo.data|escape}</textarea>
+ {/forminput}
+ </div>
+ <div class="form-group">
+ {forminput}
+ {forminput label="checkbox"}
+ <input type="checkbox" name="reload_pdf" value="1"/> {tr}Re-extract text layer from PDF{/tr}
+ {/forminput}
+ {/forminput}
+ </div>
+ {else}
<div class="form-group">
{formlabel label="Description" for="image-desc"}
{forminput}
<textarea name="edit" class="input-xlarge" id="image-desc" rows="4" cols="50">{$gContent->mInfo.data|escape}</textarea>
{/forminput}
</div>
+ {/if}
<div class="form-group">
{if $gContent->getDownloadUrl()}