HEX
Server: LiteSpeed
System: Linux node612.namehero.net 4.18.0-553.121.1.lve.el8.x86_64 #1 SMP Thu Apr 30 16:40:41 UTC 2026 x86_64
User: dfwparty (1186)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //home/dfwparty/santadallas.com/wp-content/plugins/ws-form-pdf/ws-form-pdf.php
<?php

	/**
	 * @link              https://wsform.com/knowledgebase/pdf/
	 * @since             1.0.0
	 * @package           WS_Form_PDF
	 *
	 * @wordpress-plugin
	 * Plugin Name:       WS Form PRO - PDF
	 * Plugin URI:        https://wsform.com/knowledgebase/pdf/
	 * Description:       PDF add-on for WS Form PRO
	 * Version:           1.2.7
	 * Requires at least: 5.4
	 * Requires PHP:      5.6
	 * License:           GPLv3 or later
	 * License URI:       https://www.gnu.org/licenses/gpl-3.0.html
 	 * Author:            WS Form
  	 * Author URI:        https://wsform.com/
	 * Text Domain:       ws-form-pdf
	 */

	use Dompdf\Dompdf;
	use Dompdf\Options;

	Class WS_Form_Add_On_PDF {

		const WS_FORM_PRO_ID 			= 'ws-form-pro/ws-form.php';
		const WS_FORM_PRO_VERSION_MIN 	= '1.9.88';

		function __construct() {

			// Load plugin.php
			if(!function_exists('is_plugin_active')) {

				include_once(ABSPATH . 'wp-admin/includes/plugin.php');
			}

			// Admin init
			add_action('plugins_loaded', array($this, 'plugins_loaded'), 20);
		}

		function plugins_loaded() {

			if(self::is_dependency_ok()) {

				new WS_Form_Action_PDF();

			} else {

				self::dependency_error();

				if(isset($_GET['activate'])) { unset($_GET['activate']); }
			}
		}

		function activate() {

			if (!self::is_dependency_ok()) {

				self::dependency_error();
			}
		}

		// Check dependencies
		function is_dependency_ok() {

			if(!defined('WS_FORM_VERSION')) { return false; }

			return(

				is_plugin_active(self::WS_FORM_PRO_ID) &&
				(version_compare(WS_FORM_VERSION, self::WS_FORM_PRO_VERSION_MIN) >= 0)
			);
		}

		// Add error notice action - Pro
		function dependency_error() {

			// Show error notification
			add_action('after_plugin_row_' . plugin_basename(__FILE__), array($this, 'dependency_error_notification'), 10, 2);
		}

		// Dependency error - Notification
		function dependency_error_notification($file, $plugin) {

			// Checks
			if(!current_user_can('update_plugins')) { return; }
			if($file != plugin_basename(__FILE__)) { return; }

			// Build notice
			$dependency_notice = sprintf('<tr class="plugin-update-tr"><td colspan="3" class="plugin-update colspanchange"><div class="update-message notice inline notice-error notice-alt"><p>%s</p></div></td></tr>', sprintf(__('This add-on requires %s (version %s or later) to be installed and activated.', 'ws-form-pdf'), '<a href="https://wsform.com?utm_source=ws_form_pro&utm_medium=plugins" target="_blank">WS Form PRO</a>', self::WS_FORM_PRO_VERSION_MIN));

			// Show notice
			echo $dependency_notice;
		}
	}

	$wsf_add_on_pdf = new WS_Form_Add_On_PDF();	

	register_activation_hook(__FILE__, array($wsf_add_on_pdf, 'activate'));

	// This gets fired by WS Form when it is ready to register add-ons
	add_action('wsf_plugins_loaded', function() {

		class WS_Form_Action_PDF extends WS_Form_Action {

			public $id = 'pdf';
			public $label;

			public $pdf_email_attach;
			public $pdf_email_filename;
			public $pdf_email_template;

			public $pdf_salesforce_attach;
			public $pdf_salesforce_filename;
			public $pdf_salesforce_template;

			public $licensing;

			// Constants
			const WS_FORM_LICENSE_ITEM_ID = 2855;
			const WS_FORM_LICENSE_NAME = 'PDF add-on for WS Form PRO';
			const WS_FORM_LICENSE_VERSION = '1.2.7';
			const WS_FORM_LICENSE_AUTHOR = 'WS Form';

			public function __construct() {

				// Filters
				add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links'), 10, 1);
				add_filter('wsf_config_options', array($this, 'config_options'), 10, 1);
				add_filter('wsf_table_submit_column_actions', array($this, 'table_submit_column_actions'), 10, 3);
				add_filter('wsf_action_email_settings', array($this, 'action_email_settings'), 10, 1);
				add_filter('wsf_action_salesforce_settings', array($this, 'action_salesforce_settings'), 10, 1);
				add_filter('wsf_config_meta_keys', array($this, 'config_meta_keys'), 10, 2);
				add_filter('wsf_config_parse_variables', array( $this, 'config_parse_variables' ), 10, 1);
				add_filter('wsf_action_email_email_attachments', array($this, 'action_email_email_attachments'), 10, 5);
				add_filter('wsf_action_salesforce_attachments', array($this, 'action_salesforce_attachments'), 10, 5);
				add_filter('wsf_config_field_types', array($this, 'config_field_types'), 10, 2);

				// Actions
				add_action('wsf_table_submit_action', array($this, 'table_submit_action'), 10, 2);
				add_action('rest_api_init', array($this, 'rest_api_init'), 10, 0);

				// Licensing
				$this->licensing = new WS_Form_Licensing(

					self::WS_FORM_LICENSE_ITEM_ID,
					$this->id,
					self::WS_FORM_LICENSE_NAME,
					self::WS_FORM_LICENSE_VERSION,
					self::WS_FORM_LICENSE_AUTHOR,
					__FILE__
				);
				$this->licensing->transient_check();
				add_action('admin_init', array($this->licensing, 'updater'));
				add_filter('wsf_settings_static', array($this, 'settings_static'), 10, 2);
				add_filter('wsf_settings_button', array($this, 'settings_button'), 10, 3);
				add_filter('wsf_settings_update_fields', array($this, 'settings_update_fields'), 10, 2);

				// Register init action
				add_action('init', array($this, 'init'));
			}

			// Init
			public function init() {

				// Set label
				$this->label = __('PDF', 'ws-form-pdf');
			}

			// Config parse variables
			public function config_parse_variables($parse_variables) {

				$parse_variables['pdf'] = array(

					'label' => __('PDF', 'ws-form-pdf'),

					'variables' => array(

						'pdf_url' => array(

							'label' => __('PDF URL (Download)', 'ws-form-pdf'),
							'function' => array($this, 'variable_pdf_url'),
							'description' => __('Returns the URL to the PDF. URL downloads the PDF.', 'ws-form-pdf'),
							'value' => ''
						),

						'pdf_url_view' => array(

							'label' => __('PDF URL (View)', 'ws-form-pdf'),
							'function' => array($this, 'variable_pdf_url_view'),
							'description' => __('Returns the URL to the PDF. URL shows the PDF in the browser.', 'ws-form-pdf'),
							'value' => ''
						),

						'pdf_link' => array(

							'label' => __('PDF Link (Download)', 'ws-form-pdf'),
							'function' => array($this, 'variable_pdf_link'),
							'description' => __('Returns a \'Download PDF\' link to the PDF.', 'ws-form-pdf'),
							'value' => ''
						),

						'pdf_link_view' => array(

							'label' => __('PDF Link (View)', 'ws-form-pdf'),
							'function' => array($this, 'variable_pdf_link_view'),
							'description' => __('Returns a \'View PDF\' link to the PDF.', 'ws-form-pdf'),
							'value' => ''
						)
					)
				);

				return $parse_variables;
			}

			// Get license item ID
			public function get_license_item_id() {

				return self::WS_FORM_LICENSE_ITEM_ID;
			}

			// Action - Email - Settings
			public function action_email_settings($settings) {

				$settings->fieldsets['email']['meta_keys'][] = 'action_email_pdf_attach';
				$settings->fieldsets['email']['meta_keys'][] = 'action_email_pdf_filename';
				$settings->fieldsets['email']['meta_keys'][] = 'action_email_pdf_template';

				return $settings;
			}

			// Action - Salesforce - Settings
			public function action_salesforce_settings($settings) {

				$settings->fieldsets['salesforce']['meta_keys'][] = 'action_salesforce_pdf_attach';
				$settings->fieldsets['salesforce']['meta_keys'][] = 'action_salesforce_pdf_filename';
				$settings->fieldsets['salesforce']['meta_keys'][] = 'action_salesforce_pdf_template';

				return $settings;
			}

			// Action - Email - Email attachments
			public function action_email_email_attachments($email_attachments, $form, $submit, $config, $temp_path) {

				// Load config
				self::load_config($config);

				// Check for PDF attachment
				if($this->pdf_email_attach) {

					// Convert to object
					$form_object = json_decode(json_encode($form));

					// Get PDF data
					$pdf_data = self::pdf_get_data($form_object, $submit, $this->pdf_email_template);

					// Build PDF filename
					if($this->pdf_email_filename == '') {

						// Use default
						$pdf_filename = self::pdf_get_filename();

					} else {

						// Use filename specified by user
						$pdf_filename = WS_Form_Common::parse_variables_process($this->pdf_email_filename, $form, $submit, 'text/plain');

						// Sanitize
						$pdf_filename = sanitize_file_name($pdf_filename);

						// Check extension is pdf
						$pdf_filename_extension = strtolower(pathinfo($pdf_filename, PATHINFO_EXTENSION));
						if($pdf_filename_extension !== 'pdf') { $pdf_filename .= '.pdf'; }
					}

					// PDF filename filter hook
					$pdf_filename = apply_filters('wsf_action_pdf_filename', $pdf_filename, $form, $submit);

					// Create temporary directory for storing attachment files
					if(!file_exists($temp_path)) { mkdir($temp_path); }

					// Get destination filename
					$filename_destination = $temp_path . '/' . $pdf_filename;

					// Write PDF data to destination
					file_put_contents($filename_destination, $pdf_data);

					// Add to attachments
					$email_attachments[] = array(

						'path' => $filename_destination,
						'unlink_after_use' => true
					);
				}

				return $email_attachments;
			}

			// Action - Salesforce - Attachments
			public function action_salesforce_attachments($attachments, $form, $submit, $config, $temp_path) {

				// Load config
				self::load_config($config);

				// Check for PDF attachment
				if($this->pdf_salesforce_attach) {

					// Convert to object
					$form_object = json_decode(json_encode($form));

					// Get PDF data
					$pdf_data = self::pdf_get_data($form_object, $submit, $this->pdf_salesforce_template);

					// Build PDF filename
					if($this->pdf_salesforce_filename == '') {

						// Use default
						$pdf_filename = self::pdf_get_filename();

					} else {

						// Use filename specified by user
						$pdf_filename = WS_Form_Common::parse_variables_process($this->pdf_salesforce_filename, $form, $submit, 'text/plain');

						// Sanitize
						$pdf_filename = sanitize_file_name($pdf_filename);

						// Check extension is pdf
						$pdf_filename_extension = strtolower(pathinfo($pdf_filename, PATHINFO_EXTENSION));
						if($pdf_filename_extension !== 'pdf') { $pdf_filename .= '.pdf'; }
					}

					// PDF filename filter hook
					$pdf_filename = apply_filters('wsf_action_pdf_filename', $pdf_filename, $form, $submit);

					// Create temporary directory for storing attachment files
					if(!file_exists($temp_path)) { mkdir($temp_path); }

					// Get destination filename
					$filename_destination = $temp_path . '/' . $pdf_filename;

					// Write PDF data to destination
					file_put_contents($filename_destination, $pdf_data);

					// Add to attachments
					$attachments[] = array(

						'name' => $pdf_filename,
						'type' => 'application/pdf',
						'path' => $filename_destination,
						'unlink_after_use' => true
					);
				}

				return $attachments;
			}

			// Load config
			public function load_config($config) {

				// Get configuration
				$this->pdf_email_attach = parent::get_config($config, 'action_email_pdf_attach');
				$this->pdf_email_filename = parent::get_config($config, 'action_email_pdf_filename');
				$this->pdf_email_template = parent::get_config($config, 'action_email_pdf_template');

				$this->pdf_salesforce_attach = parent::get_config($config, 'action_salesforce_pdf_attach');
				$this->pdf_salesforce_filename = parent::get_config($config, 'action_salesforce_pdf_filename');
				$this->pdf_salesforce_template = parent::get_config($config, 'action_salesforce_pdf_template');
			}

			// Variable - pdf_url
			public function variable_pdf_url($form, $submit, $content_type) {

				// Get form ID
				$form_id = $form->id;

				// Get submit hash
				$submit_hash = $submit->hash;

				return self::get_pdf_url($submit_hash, $form_id, true);
			}

			// Variable - pdf_url_view
			public function variable_pdf_url_view($form, $submit, $content_type) {

				// Get form ID
				$form_id = $form->id;

				// Get submit hash
				$submit_hash = $submit->hash;

				return self::get_pdf_url($submit_hash, $form_id, false);
			}

			// Variable - pdf_link
			public function variable_pdf_link($form, $submit, $content_type) {

				return self::variable_pdf_link_get($form, $submit, $content_type, true);
			}

			// Variable - pdf_link_view
			public function variable_pdf_link_view($form, $submit, $content_type) {

				return self::variable_pdf_link_get($form, $submit, $content_type, false);
			}

			// Variable - pdf_link / pdf_link_view get
			public function variable_pdf_link_get($form, $submit, $content_type, $download = true) {

				// Get form ID
				$form_id = $form->id;

				// Get submit hash
				$submit_hash = $submit->hash;

				// Get PDF URL
				$link_url = self::get_pdf_url($submit_hash, $form_id, $download);

				// Get link text
				$link_text = ($download ? __('Download PDF', 'ws-form-pdf') : __('View PDF', 'ws-form-pdf'));

				// Return link according to content type
				switch($content_type) {

					case 'text/plain' :

						return sprintf(

							'%s: %s',
							$link_text,
							$link_url
						);

					default :

						return sprintf(

							'<a href="%s">%s</a>',
							$link_url,
							$link_text
						);
				}
			}

			// Get PDF URL
			public function get_pdf_url($submit_hash, $form_id, $download = true) {

				// Check form ID
				$form_id = absint($form_id);
				if($form_id == '') { return ''; }

				// Check submit hash
				if(!WS_Form_Common::check_submit_hash($submit_hash)) { return ''; }

				// Build hash array
				$hash_array = (object) array(

					'form_id' => $form_id,
					'submit_hash' => $submit_hash,
					'download' => $download
				);

				// Convert to JSON
				$hash_json = json_encode($hash_array);

				// Encrypt hash
				$ws_form_encryption = new WS_Form_Encryption();
				$hash_encrypted = $ws_form_encryption->encrypt($hash_json, self::get_encryption_key());

				// Return URL
				return WS_Form_Common::get_api_path(

					// API path
					sprintf('action/' . $this->id . '/download/%s', $hash_encrypted)
				);
			}

			// API - Get PDF
			public function api_get_pdf($parameters) {

				// Get hash
				$hash = WS_Form_Common::get_query_var('hash', false, $parameters);
				if(empty($hash)) { self::pdf_error(__('Not found', 'ws-form-pdf')); }

				// Decrypt hash
				$ws_form_encryption = new WS_Form_Encryption();
				$hash_decrypted = $ws_form_encryption->decrypt($hash, self::get_encryption_key());

				// Decode JSON
				$hash_decoded = json_decode($hash_decrypted);

				// Check hash
				if(
					is_null($hash_decoded) ||
					!is_object($hash_decoded) ||
					!isset($hash_decoded->form_id) ||
					!isset($hash_decoded->submit_hash)
				) {
					self::pdf_error(__('Not found', 'ws-form-pdf'));
				}

				// Get form ID
				$form_id = absint($hash_decoded->form_id);

				// Get submit hash
				$submit_hash = $hash_decoded->submit_hash;

				// Get download
				$download = isset($hash_decoded->download) ? $hash_decoded->download : true;

				// Check inputs
				if(
					($form_id === 0) ||
					!WS_Form_Common::check_submit_hash($submit_hash)
				) {
					self::pdf_error(__('Not found', 'ws-form-pdf'));
				}

				try {

					// Export PDF
					self::pdf_export(false, $form_id, $submit_hash, $download);

				} catch (Exception $e) {

					self::pdf_error($e->getMessage());
				}
			}

			// Process error
			public function pdf_error($error_message) {

				header('Content-Type: text/html');

				die(sprintf("<pre>PDF Error: %s</pre>", esc_html($error_message)));
			}

			// Get PDF encryption key
			public function get_encryption_key() {

				// Get key
				$key = WS_Form_Common::option_get('action_' . $this->id . '_encryption_key');

				// If no key exists, generate one
				if(empty($key)) {

					// Generate key
					$ws_form_encryption = new WS_Form_Encryption();
					$key = $ws_form_encryption->create_random_key();

					// Set key
					WS_Form_Common::option_set('action_' . $this->id . '_encryption_key', $key);
				}

				return $key;
			}

			// PDF - Export
			public function pdf_export($submit_id, $form_id = false, $submit_hash = false, $download = true) {

				// Get submit
				$ws_form_submit = New WS_Form_Submit();

				if($submit_id !== false) {

					// Admin
					$ws_form_submit->id = $submit_id;
					$ws_form_submit->db_read(true, false);
					$ws_form_submit->db_form_object_read();

				} else {

					// Public
					$ws_form_submit->form_id = $form_id;
					$ws_form_submit->hash = $submit_hash;
					$ws_form_submit->db_read_by_hash(true, false, true, true);
					$ws_form_submit->db_form_object_read(true);
				}

				// Clear hidden meta values
				$submit_parse = clone $ws_form_submit;
				$submit_parse->clear_hidden_meta_values();

				// Get data
				try {

					$pdf_data = self::pdf_get_data($ws_form_submit->form_object, $submit_parse);

				} catch (Exception $e) {

					self::pdf_error($e->getMessage());
				}

				// Build filename
				$pdf_filename = self::pdf_get_filename();

				// PDF filename filter hook
				$pdf_filename = apply_filters('wsf_action_pdf_filename', $pdf_filename, $ws_form_submit->form_object, $submit_parse);

				// HTTP headers
				header('Content-Type: application/pdf');
				header(sprintf('Content-Disposition: %s; filename=%s', ($download ? 'attachment' : 'inline'), sanitize_file_name($pdf_filename)));
				header('Content-Transfer-Encoding: binary');
				header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
				header('Cache-Control: private', false);
				header('Expires: 0');
				header('Pragma: public');

				// Start CSV output
				$pdf_out = fopen('php://output', 'w');

				// Write data
				fwrite($pdf_out, $pdf_data);

				// Close
				fclose($pdf_out);

				exit;
			}

			// PDF - Get filename
			public function pdf_get_filename() {

				return WS_Form_Common::filename_datestamp('ws-form-submit', 'pdf');
			}

			// PDF - Get data
			public function pdf_get_data($form, $ws_form_submit, $template = false) {

				$plugin_dir = sprintf('%s/', dirname(__FILE__));

				// Get form ID
				$form_id = $form->id;

				// Load DOMPDF
				require_once $plugin_dir . 'includes/composer/vendor/autoload.php';

				// Build template path
				$template_path = 'pdf/templates';

				// Apply filter
				$template_path = apply_filters(

					'wsf_action_' . $this->id . '_template_path',
					$template_path,
					$form,
					$ws_form_submit,
					$template
				);

				// Apply filter - Legacy
				$template_path = apply_filters(

					'wsf_file_upload_path_pdf',
					$template_path
				);

				// Get template directory
				$upload_dir = WS_Form_Common::upload_dir_create($template_path);
				if($upload_dir['error']) { self::api_throw_error($upload_dir['error']); }
				$template_dir = $upload_dir['dir'];

				// Default file name
				$file_name = sprintf('%stemplates/standard.html', $plugin_dir);

				// Check for a custom template name
				$file_name_custom_found = false;
				if(!empty($template)) {

					// Sanitize file name
					$pdf_template = basename(sanitize_file_name($template));

					$file_name_custom = sprintf('%s/%s', $template_dir, $pdf_template);

					if(file_exists($file_name_custom)) {

						$file_name = $file_name_custom;
						$file_name_custom_found = true;
					}
				}

				// Check for a custom form template
				if($file_name_custom_found === false) {

					$file_name_custom = sprintf('%s/%u.html', $template_dir, $form_id);

					if(file_exists($file_name_custom)) {

						$file_name = $file_name_custom;
					}
				}

				// Get PDF template
				$pdf_template = file_get_contents($file_name);

				// Get PDF HTML
				$pdf_html = WS_Form_Common::parse_variables_process($pdf_template, $form, $ws_form_submit, 'text/html');

				// Parse settings
				$pdf_html_lookups = array(

					'pdf_default_font' => sanitize_text_field(apply_filters(

						'wsf_action_' . $this->id . '_default_font',
						WS_Form_Common::option_get('action_' . $this->id . '_default_font', 'sans-serif'),
						$form,
						$ws_form_submit,
						$template
					)),

					'pdf_default_font_size' => sanitize_text_field(apply_filters(

						'wsf_action_' . $this->id . '_default_font_size',
						sprintf('%upx', WS_Form_Common::option_get('action_' . $this->id . '_default_font_size', '16')),
						$form,
						$ws_form_submit,
						$template
					))
				);

				$pdf_html = WS_Form_Common::mask_parse($pdf_html, $pdf_html_lookups);

				// Initialize DOMPDF object
				$dompdf = new Dompdf();

				// Load from HTML
				$dompdf->loadHtml($pdf_html);

				// Get paper size
				$paper_size = apply_filters(

					'wsf_action_' . $this->id . '_paper_size',
					WS_Form_Common::option_get('action_' . $this->id . '_paper_size', 'letter'),
					$form,
					$ws_form_submit,
					$template
				);
				if(!in_array($paper_size, array_keys(self::get_paper_sizes()))) {

					$paper_size = 'letter';
				}

				// Get orientation
				$orientation = apply_filters(

					'wsf_action_' . $this->id . '_orientation',
					WS_Form_Common::option_get('action_' . $this->id . '_orientation', 'portrait'),
					$form,
					$ws_form_submit,
					$template
				);
				if(!in_array($orientation, array('portrait', 'landscape'))) {

					$orientation = 'portait';
				}

				// Setup the paper size and orientation
				$dompdf->setPaper($paper_size, $orientation);

				// Options
				$options = new Options();
				$options->setIsRemoteEnabled(true);
				$dompdf->setOptions($options);

				// Render
				$dompdf->render();

				// Get output
				return $dompdf->output();
			}

			// Build REST API endpoints
			public function rest_api_init() {

				// Download PDF
				register_rest_route(WS_FORM_RESTFUL_NAMESPACE, '/action/' . $this->id . '/download/(?P<hash>[a-f0-9]+)/', array('methods' => 'GET', 'callback' => array($this, 'api_get_pdf'), 'permission_callback' => function () { return true; }));
			}

			// Config - Meta keys
			public function config_meta_keys($meta_keys = array(), $form_id = 0) {

				// Email - Attach PDF
				$meta_keys['action_email_pdf_attach']	= array(

					'label'						=>	__('Attach PDF', 'ws-form-pdf'),
					'type'						=>	'checkbox',
					'default'					=>	'',
					'help'						=>	__('Attach a PDF file of this submission to the email?', 'ws-form-pdf')
				);

				// Email - Custom PDF filename
				$meta_keys['action_email_pdf_filename']	= array(

					'label'						=>	__('Custom PDF Filename', 'ws-form-pdf'),
					'type'						=>	'text',
					'default'					=>	'',
					'help'						=>	__('Enter a custom filename for the PDF attachment. Leave blank to use default.', 'ws-form-pdf'),
					'placeholder'				=>	self::pdf_get_filename(),
					'condition'					=>	array(

						array(

							'logic'			=>	'==',
							'meta_key'		=>	'action_email_pdf_attach',
							'meta_value'	=>	'on'
						)
					)
				);

				// Email - Custom PDF template
				$meta_keys['action_email_pdf_template']	= array(

					'label'						=>	__('Custom PDF Template', 'ws-form-pdf'),
					'type'						=>	'text',
					'default'					=>	'',
					'help'						=>	sprintf(

						'%s <a href="https://wsform.com/knowledgebase/pdf/#custom-templates" target="_blank">Learn more</a>',
						__('Enter a custom filename for the PDF template.', 'ws-form-pdf'),
						__('Learn more', 'ws-form-pdf')
					),
					'condition'					=>	array(

						array(

							'logic'			=>	'==',
							'meta_key'		=>	'action_email_pdf_attach',
							'meta_value'	=>	'on'
						)
					)
				);

				// Salesforce - Attach PDF
				$meta_keys['action_salesforce_pdf_attach']	= array(

					'label'						=>	__('Attach PDF', 'ws-form-pdf'),
					'type'						=>	'checkbox',
					'default'					=>	'',
					'help'						=>	__('Attach a PDF file of this submission to the object?', 'ws-form-pdf')
				);

				// Salesforce - Custom PDF filename
				$meta_keys['action_salesforce_pdf_filename']	= array(

					'label'						=>	__('Custom PDF Filename', 'ws-form-pdf'),
					'type'						=>	'text',
					'default'					=>	'',
					'help'						=>	__('Enter a custom filename for the PDF attachment. Leave blank to use default.', 'ws-form-pdf'),
					'placeholder'				=>	self::pdf_get_filename(),
					'condition'					=>	array(

						array(

							'logic'			=>	'==',
							'meta_key'		=>	'action_salesforce_pdf_attach',
							'meta_value'	=>	'on'
						)
					)
				);

				// Salesforce - Custom PDF template
				$meta_keys['action_salesforce_pdf_template']	= array(

					'label'						=>	__('Custom PDF Template', 'ws-form-pdf'),
					'type'						=>	'text',
					'default'					=>	'',
					'help'						=>	sprintf(

						'%s <a href="https://wsform.com/knowledgebase/pdf/#custom-templates" target="_blank">Learn more</a>',
						__('Enter a custom filename for the PDF template.', 'ws-form-pdf'),
						__('Learn more', 'ws-form-pdf')
					),
					'condition'					=>	array(

						array(

							'logic'			=>	'==',
							'meta_key'		=>	'action_salesforce_pdf_attach',
							'meta_value'	=>	'on'
						)
					)
				);

				return $meta_keys;
			}

			// Submissions page - Table actions
			public function table_submit_column_actions($actions, $item, $status) {

				// Get submissions ID
				$id = absint($item['id']);

				// Export PDF
				$actions['pdf'] = sprintf('<a href="#" data-action="wsf-pdf" data-id="%u">%s</a>', $id, __('Export PDF', 'ws-form-pdf'));

				return $actions;
			}

			// Submissions page - Action
			public function table_submit_action($action, $submit_id) {

				switch($action) {

					case 'wsf-pdf' : self::pdf_export($submit_id); break;
				}
			}

			// Plug-in field types for this action
			public function config_field_types($field_types) {

				$field_types[$this->id] = array(

					'label' =>	__('PDF', 'ws-form-pdf'),
					'types' =>	array(

						'pdf_page_break' => array (

							'label'					=>	__('Page Break', 'ws-form-pdf'),
							'pro_required'			=>	!WS_Form_Common::is_edition('pro'),
							'label_default'			=>	__('PDF Page Break', 'ws-form-pdf'),
							'mask_field'			=>	'<div style="page-break-after: always;"></div>',
							'label_disabled'		=>	true,
							'submit_save'			=>	false,
							'submit_edit'			=>	false,
							'progress'				=>	false,
							'conditional'			=>	array(

								'exclude_condition'		=>	true,
								'exclude_then'			=>	true,
								'exclude_else'			=>	true
							),
							'icon'					=>	'<svg width="14" height="18" viewBox="0 0 14 18"><path fill="#444" d="M13,12 L1,12 L1,18 L13,18 L13,12 Z M12,13 L12,18 L2,18 L2,13 L12,13 Z"></path><path fill="#444" d="M0 8.5 0 9.5 2 9.5 2 8.5z"></path><path fill="#444" d="M3 8.5 3 9.5 5 9.5 5 8.5z"></path><path fill="#444" d="M6 8.5 6 9.5 8 9.5 8 8.5z"></path><path fill="#444" d="M9 8.5 9 9.5 11 9.5 11 8.5z"></path><path fill="#444" d="M12 8.5 12 9.5 14 9.5 14 8.5z"></path><path fill="#444" d="M1,0 L1,6 L13,6 L13,0 L1,0 Z M12,0 L12,5 L2,5 L2,0 L12,0 Z"></path></svg>',
							'static'				=>	true,
							'mask_wrappers_drop'	=>	true,

							'fieldsets'	=> array(

								// Tab: Basic
								'basic'	=> array(

									'label'			=>	__('Basic', 'ws-form-pdf')
								)
							)
						)
					)
				);

				return $field_types;
			}

			// Plugin action link
			public function plugin_action_links($links) {

				// Settings
				array_unshift($links, sprintf('<a href="%s">%s</a>', WS_Form_Common::get_admin_url('ws-form-settings', false, 'tab=action_' . $this->id), __('Settings', 'ws-form-pdf')));

				return $links;
			}

			// Plug-in options for this action
			public function config_options($options) {

				$options['action_' . $this->id] = array(

					'label'		=>	$this->label,
					'fields'	=>	array(

						'action_' . $this->id . '_license_version'	=>	array(

							'label'		=>	__('Add-on Version', 'ws-form-pdf'),
							'type'		=>	'static'
						),

						'action_' . $this->id . '_license_key'	=>	array(

							'label'		=>	__('Add-on License Key', 'ws-form-pdf'),
							'type'		=>	'text',
							'help'		=>	__('Enter your PDF add-on for WS Form PRO license key here.', 'ws-form-pdf'),
							'button'	=>	'license_action_' . $this->id,
							'action'	=>	$this->id
						),

						'action_' . $this->id . '_license_status'	=>	array(

							'label'		=>	__('Add-on License Status', 'ws-form-pdf'),
							'type'		=>	'static'
						),

						'action_' . $this->id . '_paper_size'	=>	array(

							'label'		=>	__('Paper Size', 'ws-form-pdf'),
							'type'		=>	'select',
							'default'	=>	'letter',
							'options'	=>	self::get_paper_sizes()
						),

						'action_' . $this->id . '_orientation'	=>	array(

							'label'		=>	__('Orientation', 'ws-form-pdf'),
							'type'		=>	'select',
							'default'	=>	'portrait',
							'options'	=>	array(

								'portrait' => array('text' => __('Portrait', 'ws-form-pdf')),
								'landscape' => array('text' => __('Landscape', 'ws-form-pdf'))
							)
						),

						'action_' . $this->id . '_default_font'	=>	array(

							'label'		=>	__('Font Family', 'ws-form-pdf'),
							'type'		=>	'select',
							'default'	=>	'sans-serif',
							'options'	=>	array(

								'sans-serif' => array('text' => 'Sans Serif'),
								'serif' => array('text' => 'Serif'),
								'courier' => array('text' => 'Courier'),
								'dejavu sans' => array('text' => 'DejaVu Sans'),
								'dejavu sans mono' => array('text' => 'Dejavu Sans Mono'),
								'dejavu serif' => array('text' => 'Dejavu Serif'),
								'zapfdingbats' => array('text' => 'Zapf Dingbats'),
								'symbol' => array('text' => 'Symbol')
							)
						),

						'action_' . $this->id . '_default_font_size'	=>	array(

							'label'		=>	__('Font Size (Pixels)', 'ws-form-pdf'),
							'type'		=>	'number',
							'default'	=>	'16'
						)
					)
				);

				return $options;
			}

			// Get paper sizes
			public function get_paper_sizes() {

				return array(

					'a4' => array('text' => 'A4 (210mm x 297mm)'),
					'letter' => array('text' => 'Letter (8.5" x 11")'),
					'legal' => array('text' => 'Legal (8.5" x 14")'),
					'ledger' => array('text' => 'Ledger / Tabloid (11" x 17")'),
					'executive' => array('text' => 'Executive (7" x 10")'),
					'4a0' => array('text' => '4A0 (1682mm x 2378mm)'),
					'2a0' => array('text' => '4A0 (1189mm x 1682mm)'),
					'a0' => array('text' => 'A0 (841mm x 1189mm)'),
					'a1' => array('text' => 'A1 (594mm x 841mm)'),
					'a2' => array('text' => 'A2 (420mm x 594mm)'),
					'a3' => array('text' => 'A3 (297mm x 420mm)'),
					'a5' => array('text' => 'A5 (148mm x 210mm)'),
					'a6' => array('text' => 'A6 (105mm x 148mm)'),
					'a7' => array('text' => 'A7 (74mm x 105mm)'),
					'a8' => array('text' => 'A8 (52mm x 74mm)'),
					'a9' => array('text' => 'A9 (37mm x 52mm)'),
					'a10' => array('text' => 'A10 (26mm x 37mm)'),
					'b0' => array('text' => 'B0 (1414mm x 1000mm)'),
					'b1' => array('text' => 'B1 (1000mm x 707mm)'),
					'b2' => array('text' => 'B2 (707mm x 500mm)'),
					'b3' => array('text' => 'B3 (500mm x 353mm)'),
					'b4' => array('text' => 'B4 (353mm x 250mm)'),
					'b5' => array('text' => 'B5 (250mm x 176mm)'),
					'b6' => array('text' => 'B6 (176mm x 125mm)'),
					'b7' => array('text' => 'B7 (125mm x 88mm)'),
					'b8' => array('text' => 'B8 (88mm x 62mm)'),
					'b9' => array('text' => 'B9 (62mm x 44mm)'),
					'b10' => array('text' => 'B10 (44mm x 31mm)'),
					'c0' => array('text' => 'C0 (1297mm x 917mm)'),
					'c1' => array('text' => 'C1 (917mm x 648mm)'),
					'c2' => array('text' => 'C2 (648mm x 458mm)'),
					'c3' => array('text' => 'C3 (458mm x 324mm)'),
					'c4' => array('text' => 'C4 (324mm x 229mm)'),
					'c5' => array('text' => 'C5 (229mm x 162mm)'),
					'c6' => array('text' => 'C6 (162mm x 114mm)'),
					'c7' => array('text' => 'C7 (114mm x 81mm)'),
					'c8' => array('text' => 'C8 (81mm x 57mm)'),
					'c9' => array('text' => 'C9 (57mm x 40mm)'),
					'c10' => array('text' => 'C10 (40mm x 28mm)'),
					'ra0' => array('text' => 'RA0 (860mm x 1220mm)'),
					'ra1' => array('text' => 'RA1 (610mm x 860mm)'),
					'ra2' => array('text' => 'RA2 (430mm x 610mm)'),
					'ra3' => array('text' => 'RA3 (305mm x 430mm)'),
					'ra4' => array('text' => 'RA4 (215mm x 305mm)'),
					'sra0' => array('text' => 'SRA0 (900mm x 1280mm)'),
					'sra1' => array('text' => 'SRA1 (640mm x 900mm)'),
					'sra2' => array('text' => 'SRA2 (450mm x 640mm)'),
					'sra3' => array('text' => 'SRA3 (320mm x 450mm)'),
					'sra4' => array('text' => 'SRA4 (225mm x 320mm)')
				);
			}

			// Settings - Static
			public function settings_static($value, $field) {

				switch ($field) {

					case 'action_' . $this->id . '_license_version' :

						$value = self::WS_FORM_LICENSE_VERSION;
						break;

					case 'action_' . $this->id . '_license_status' :

						$value = $this->licensing->license_status();
						break;
				}

				return $value;
			}

			// Settings - Button
			public function settings_button($value, $field, $button) {

				switch($button) {

					case 'license_action_' . $this->id :

						$license_activated = WS_Form_Common::option_get('action_' . $this->id . '_license_activated', false);
						if($license_activated) {

							$value = '<input class="wsf-button" type="button" data-action="wsf-mode-submit" data-mode="deactivate" value="' . __('Deactivate', 'ws-form-pdf') . '" />';

						} else {

							$value = '<input class="wsf-button" type="button" data-action="wsf-mode-submit" data-mode="activate" value="' . __('Activate', 'ws-form-pdf') . '" />';
						}

						break;
				}
				
				return $value;
			}

			// Settings - Update fields
			public function settings_update_fields($field, $value) {

				switch ($field) {

					case 'action_' . $this->id . '_license_key' :

						$mode = WS_Form_Common::get_query_var('action_mode');

						switch($mode) {

							case 'activate' :

								$this->licensing->activate($value);
								break;

							case 'deactivate' :

								$this->licensing->deactivate($value);
								break;
						}

						break;
				}
			}
		}
	});