Skip to content
This repository has been archived by the owner on Mar 16, 2023. It is now read-only.

Commit

Permalink
add extract and update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Fiebig committed Aug 4, 2017
1 parent 7c2b81c commit 4f970e4
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions faf-pdfextract.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,37 @@
*/
function extractPdfContent($id)
{
if (!`which pdftotext` || get_post_mime_type($id) !== 'application/pdf') {
if (wp_is_post_revision($id)){
return;
//throw new Exception('Du benötigst pdftotext (poppler utils) auf deinem Server!');
}

$file = get_attached_file($id);
if (is_file($file)) {
$txt = $file.'.txt';
if (get_post_mime_type($id) !== 'application/pdf') {
return;
}

if (!`which pdftotext`) {
//return;
$content = 'Du benötigst pdftotext (poppler utils) auf deinem Server!';
} else {
$file = get_attached_file($id);
if (is_file($file)) {
$txt = $file . '.txt';

system('pdftotext -layout '.$file.' '.$txt);
system('pdftotext -layout ' . $file . ' ' . $txt);

if (is_file($txt)) {
$content = file_get_contents($txt);
update_post_meta($id, 'content', $content);
if (is_file($txt)) {
$content = file_get_contents($txt);
}
}
}

$data = [];
$data['ID'] = $id;
$data['post_content'] = $content;

remove_action('edit_attachment', 'extractPdfContent');
wp_update_post($data);
add_action('edit_attachment', 'extractPdfContent');
}
add_action('save_post', 'extractPdfContent');
add_action('edit_attachment', 'extractPdfContent', 10, 2);
add_action('add_attachment', 'extractPdfContent', 10, 2);

0 comments on commit 4f970e4

Please sign in to comment.