diff --git a/js/frontend.js b/js/frontend.js
index e957056..b4ea9ea 100644
--- a/js/frontend.js
+++ b/js/frontend.js
@@ -35,23 +35,48 @@ window.addEventListener('load', function(event)
{
var downloads = document.createElement('div');
downloads.className = 'wpcf7-pdf-forms-response-output';
-
+ var alldownloadlink = false;
+ var allpdfviewer = false;
+
for(var i=0; i
subdir = wp_unique_filename( $this->get_downloads_path(), $random_num );
-
+
return $this->subdir;
}
@@ -126,6 +126,15 @@ public function add_file( $srcfile, $filename )
return $this;
}
+
+ /**
+ * Adds additional options to response
+ */
+ public function set_options( $id, $options )
+ {
+ $this->files[$id]['options'] = $options;
+ return $this;
+ }
/**
* Returns added files
diff --git a/pdf-forms-for-contact-form-7.php b/pdf-forms-for-contact-form-7.php
index 805646f..476bde3 100644
--- a/pdf-forms-for-contact-form-7.php
+++ b/pdf-forms-for-contact-form-7.php
@@ -82,6 +82,9 @@ public function plugin_init()
add_action( 'wpcf7_after_save', array( $this, 'update_post_attachments' ) );
add_filter( 'wpcf7_form_response_output', array( $this, 'change_response_nojs' ), 10, 4 );
+
+ // wpcf7_pdf_forms_downloads using shortcode to redirected page
+ add_shortcode('wpcf7_pdf_forms_downloads', array( $this, 'shortcode_download_links_response' ));
if( defined( 'WPCF7_VERSION' ) && version_compare( WPCF7_VERSION, '5.2' ) >= 0 )
// hook wpcf7_feedback_response (works only with CF7 version 5.2+)
@@ -98,7 +101,7 @@ public function plugin_init()
// TODO: allow users to run this manually
add_action( 'admin_init', array( $this, 'upgrade_data' ) );
}
-
+
/*
* Runs after the plugin have been activated/deactivated
*/
@@ -559,8 +562,9 @@ public function post_add_pdf( $post_id, $attachment_id, $options )
return $attachment_id;
}
- private static $pdf_options = array('skip_empty' => false, 'attach_to_mail_1' => true, 'attach_to_mail_2' => false, 'flatten' => false, 'filename' => "", 'save_directory'=>"", 'download_link' => false );
-
+ private static $pdf_options = array('skip_empty' => false, 'attach_to_mail_1' => true, 'attach_to_mail_2' => false, 'flatten' => false, 'filename' => "", 'save_directory'=>"", 'download_link' => false, 'auto_download' => false, 'pdf_viewer' => false );
+ private static $public_pdf_options = array('download_link', 'auto_download', 'pdf_viewer');
+
/**
* Updates post attachment options
*/
@@ -1077,12 +1081,16 @@ public function fill_pdfs( $contact_form, &$abort, $submission )
$attach_to_mail_2 = $attachment['options']['attach_to_mail_2'] || strpos( $mail2["attachments"], "[pdf-form-".$attachment_id."]" ) !== FALSE;
$save_directory = strval( $attachment['options']['save_directory'] );
$create_download_link = $attachment['options']['download_link'];
+ $create_auto_download = $attachment['options']['auto_download'];
+ $create_pdf_viewer = $attachment['options']['pdf_viewer'];
// skip file if it is not used anywhere
if( !$attach_to_mail_1
&& !$attach_to_mail_2
&& $save_directory === ""
- && !$create_download_link )
+ && !$create_download_link
+ && !$create_auto_download
+ && !$create_pdf_viewer )
continue;
$options = array();
@@ -1171,8 +1179,18 @@ public function fill_pdfs( $contact_form, &$abort, $submission )
}
$create_download_link = $filedata['options']['download_link'];
- if ( $create_download_link )
- $this->get_downloads()->add_file( $filedata['file'], $filedata['filename'] );
+ $create_auto_download = $filedata['options']['auto_download'];
+ $create_pdf_viewer = $filedata['options']['pdf_viewer'];
+ $public_options = array_filter( $filedata['options'],
+ function ( $key ) use ( $public_pdf_options )
+ {
+ return in_array( $key, self::$public_pdf_options );
+ }, ARRAY_FILTER_USE_KEY );
+
+ if ( $create_download_link || $create_auto_download || $create_pdf_viewer )
+ $this->get_downloads()
+ ->add_file( $filedata['file'], $filedata['filename'] )
+ ->set_options( $id, $public_options );
}
}
}
@@ -1933,6 +1951,9 @@ public function render_tag_generator( $contact_form, $args = '' )
'filename' => esc_html__( 'Filename (mail-tags can be used)', 'pdf-forms-for-contact-form-7' ),
'save-directory'=> esc_html__( 'Save PDF file on the server at the given path relative to wp-content/uploads (mail-tags can be used; if empty, PDF file is not saved on disk)', 'pdf-forms-for-contact-form-7' ),
'download-link' => esc_html__( 'Add filled PDF download link to form submission response', 'pdf-forms-for-contact-form-7' ),
+ 'shortcode-title' => esc_html__( 'If your form redirects, use [wpcf7_pdf_forms_downloads] shortcode to display download links on the redirect page.', 'pdf-forms-for-contact-form-7' ),
+ 'auto-download' => esc_html__( 'Automatically download filled PDF after form submission', 'pdf-forms-for-contact-form-7' ),
+ 'pdf-viewer' => esc_html__( 'PDF viewer', 'pdf-forms-for-contact-form-7' ),
'field-mapping' => esc_html__( 'Field Mapper Tool', 'pdf-forms-for-contact-form-7' ),
'field-mapping-help' => esc_html__( 'This tool can be used to link form fields and mail-tags with fields in the attached PDF files. Form tags can also be generated. When your users submit the form, input from form fields and other mail-tags will be inserted into the correspoinding fields in the PDF file.', 'pdf-forms-for-contact-form-7' ),
'pdf-field' => esc_html__( 'PDF field', 'pdf-forms-for-contact-form-7' ),
@@ -2014,11 +2035,15 @@ public function change_response_js( $response, $result )
array(
'filename' => $file['filename'],
'url' => $file['url'],
- 'size' => size_format( filesize( $file['filepath'] ) )
+ 'size' => size_format( filesize( $file['filepath'] ) ),
+ 'options' => $file['options']
);
// make sure to enable cron if it is down so that old download files get cleaned up
$this->enable_cron();
+
+ // keeping files in cookie to be accessed on the redirect page.
+ setcookie('wpcf7_pdf_forms_files', json_encode( $this->downloads->get_files() ), time() + 3600, "/");
}
return $response;
@@ -2038,6 +2063,50 @@ public function change_response_nojs( $output, $class, $content, $contact_form )
{
$downloads = '';
foreach( $this->downloads->get_files() as $file )
+ {
+ if( $file['options']['download_link'] == true )
+ $downloads .= "" .
+ self::replace_tags(
+ esc_html__( "{icon} {a-href-url}{filename}{/a} {i}({size}){/i}", 'pdf-forms-for-contact-form-7' ),
+ array(
+ 'icon' => '
',
+ 'a-href-url' => '
',
+ 'filename' => esc_html( $file['filename'] ),
+ '/a' => '',
+ 'i' => '
',
+ 'size' => esc_html( size_format( filesize( $file['filepath'] ) ) ),
+ '/i' => '',
+ )
+ )
+ . "
";
+
+ if( $file['options']['pdf_viewer'] == true )
+ $downloads .= "";
+ }
+ $output .= "$downloads
";
+
+ // make sure to enable cron if it is down so that old download files get cleaned up
+ $this->enable_cron();
+ }
+ }
+
+ return $output;
+ }
+
+ /*
+ * function that runs when the shortcode is called
+ */
+ public function shortcode_download_links_response()
+ {
+ $output = '';
+ if( isset( $_COOKIE['wpcf7_pdf_forms_files'] ) )
+ {
+ $get_files = stripslashes( $_COOKIE['wpcf7_pdf_forms_files'] );
+ $get_files = json_decode( $get_files, true );
+ $downloads = '';
+ foreach( $get_files as $file )
+ {
+ if( $file['options']['download_link'] == true || $file['options']['auto_download'] == true )
$downloads .= "" .
self::replace_tags(
esc_html__( "{icon} {a-href-url}{filename}{/a} {i}({size}){/i}", 'pdf-forms-for-contact-form-7' ),
@@ -2052,15 +2121,14 @@ public function change_response_nojs( $output, $class, $content, $contact_form )
)
)
. "
";
- $output .= "$downloads
";
-
- // make sure to enable cron if it is down so that old download files get cleaned up
- $this->enable_cron();
}
+ $output .= "$downloads
";
}
-
+
return $output;
}
+
+
}
WPCF7_Pdf_Forms::get_instance();