OrderClasses/Controller/Activator.php 0000644 00000004455 14760002214 0012735 0 ustar 00 delete($folder, true);
}
delete_option('_fluentform_pdf_settings');
}
} Classes/Controller/FontManager.php 0000644 00000004010 14760002214 0013165 0 ustar 00 getFontDir();
if(!function_exists('\list_files')) {
$admin_path = ABSPATH .'/wp-admin/';
include_once $admin_path.'includes/file.php';
}
$downloadedFiles = \list_files($fontDir, 1);
$fileNames = [];
foreach ($downloadedFiles as $file) {
$fileNames[] = str_replace($fontDir, '', $file);
}
$coreFonts = $this->getCoreFonts();
$downloadableFonts = [];
foreach ($coreFonts as $coreFont) {
if($limit && count($downloadableFonts) == $limit) {
return $downloadableFonts;
}
if(!in_array($coreFont['name'], $fileNames)) {
$downloadableFonts[] = $coreFont;
}
}
return $downloadableFonts;
}
public function download($fontName)
{
$destination = $this->getFontDir();
$res = wp_remote_get(
$this->github_repo . $fontName,
[
'timeout' => 60,
'stream' => true,
'filename' => $destination . $fontName,
]
);
/* Check for errors and log them to file */
if ( is_wp_error( $res ) ) {
return $res;
}
$res_code = wp_remote_retrieve_response_code( $res );
if ( $res_code !== 200 ) {
return new \WP_Error('failed', __('Core Font API Response Failed', 'fluentform-pdf'));
}
return true;
}
private function getFontDir()
{
$dirStructure = AvailableOptions::getDirStructure();
return $dirStructure['fontDir'].'/';
}
}
Classes/Controller/AvailableOptions.php 0000644 00000027234 14760002214 0014235 0 ustar 00 'A4 (210 x 297mm)',
'Letter' => 'Letter (8.5 x 11in)',
'Legal' => 'Legal (8.5 x 14in)',
'ledger' => 'Ledger / Tabloid (11 x 17in)',
'Executive' => 'Executive (7 x 10in)',
'A0' => 'A0 (841 x 1189mm)',
'A1' => 'A1 (594 x 841mm)',
'A2' => 'A2 (420 x 594mm)',
'A3' => 'A3 (297 x 420mm)',
'A5' => 'A5 (148 x 210mm)',
'A6' => 'A6 (105 x 148mm)',
'A7' => 'A7 (74 x 105mm)',
'A8' => 'A8 (52 x 74mm)',
'A9' => 'A9 (37 x 52mm)',
'A10' => 'A10 (26 x 37mm)',
'B0' => 'B0 (1414 x 1000mm)',
'B1' => 'B1 (1000 x 707mm)',
'B2' => 'B2 (707 x 500mm)',
'B3' => 'B3 (500 x 353mm)',
'B4' => 'B4 (353 x 250mm)',
'B5' => 'B5 (250 x 176mm)',
'B6' => 'B6 (176 x 125mm)',
'B7' => 'B7 (125 x 88mm)',
'B8' => 'B8 (88 x 62mm)',
'B9' => 'B9 (62 x 44mm)',
'B10' => 'B10 (44 x 31mm)',
'C0' => 'C0 (1297 x 917mm)',
'C1' => 'C1 (917 x 648mm)',
'C2' => 'C2 (648 x 458mm)',
'C3' => 'C3 (458 x 324mm)',
'C4' => 'C4 (324 x 229mm)',
'C5' => 'C5 (229 x 162mm)',
'C6' => 'C6 (162 x 114mm)',
'C7' => 'C7 (114 x 81mm)',
'C8' => 'C8 (81 x 57mm)',
'C9' => 'C9 (57 x 40mm)',
'C10' => 'C10 (40 x 28mm)',
'RA0' => 'RA0 (860 x 1220mm)',
'RA1' => 'RA1 (610 x 860mm)',
'RA2' => 'RA2 (430 x 610mm)',
'RA3' => 'RA3 (305 x 430mm)',
'RA4' => 'RA4 (215 x 305mm)',
'SRA0' => 'SRA0 (900 x 1280mm)',
'SRA1' => 'SRA1 (640 x 900mm)',
'SRA2' => 'SRA2 (450 x 640mm)',
'SRA3' => 'SRA3 (320 x 450mm)',
'SRA4' => 'SRA4 (225 x 320mm)',
'B' => 'B (128 x 198mm)',
'A' => 'B (111 x 178mm)',
'DEMY' => 'DEMY (135 x 216mm)',
'ROYAL' => 'ROYAL (135 x 216mm)'
];
}
public static function getOrientations()
{
return [
'P' => "Portrait",
'L' => 'Landscape'
];
}
public static function getFonts()
{
return [
'default' => 'Default',
'serif' => 'Serif',
'monospace' => 'Monospace'
];
}
public static function getDefaultSettings()
{
return [
'font_size' => '16',
"paper_size" => 'A4',
'template' => 'blank',
'orientation' => 'P',
'font' => 'default',
'font_color' => '#000000',
'entry_view' => 'I',
'reverse_text' => 'no',
'accent_color' => '#CCCCCC',
'filename' => 'fluentformpdf'
];
}
public static function commonSettings()
{
return [
[
'key' => 'paper_size',
'label' => __('Paper size', 'fluentform-pdf'),
'component' => 'dropdown',
'tab' => 'tab2',
'tips' => __('select a pdf paper size', 'fluentform-pdf'),
'options' => self::getPaperSizes()
],
[
'key' => 'orientation',
'label' => __('Orientation', 'fluentform-pdf'),
'tab' => 'tab2',
'component' => 'dropdown',
'options' => self::getOrientations()
],
[
'key' => 'font',
'label' => __('Font family', 'fluentform-pdf'),
'component' => 'dropdown',
'tab' => 'tab2',
'options' => self::getFonts()
],
[
'key' => 'font_size',
'label' => __('Font size', 'fluentform-pdf'),
'tab' => 'tab2',
'component' => 'number'
],
[
'key' => 'font_color',
'label' => __('Font color', 'fluentform-pdf'),
'tab' => 'tab2',
'tips' => __('The font color will use in the PDF.', 'fluentform-pdf'),
'component' => 'color_picker'
],
[
'key' => 'accent_color',
'label' => __('Accent color', 'fluentform-pdf'),
'tab' => 'tab2',
'tips' => __('The accent color is used for the page, section titles and the border.', 'fluentform-pdf'),
'component' => 'color_picker'
],
[
'key' => 'entry_view',
'label' => __('Entry view', 'fluentform-pdf'),
'tab' => 'tab2',
'component' => 'radio_choice',
'options' => [
'I' => __('View', 'fluentform-pdf'),
'D' => __('Download', 'fluentform-pdf')
]
],
[
'key' => 'empty_fields',
'label' => __('Show empty fields', 'fluentform-pdf'),
'tab' => 'tab2',
'component' => 'radio_choice',
'options' => [
'yes' => __('Yes', 'fluentform-pdf'),
'no' => __('No', 'fluentform-pdf')
]
],
[
'key' => 'reverse_text',
'label' => __('Reverse text', 'fluentform-pdf'),
'tab' => 'tab2',
'tips' => __('Script like Arabic and Hebrew are written right to left.', 'fluentform-pdf'),
'component' => 'radio_choice',
'options' => [
'yes' => __('Yes', 'fluentform-pdf'),
'no' => __('No', 'fluentform-pdf')
]
]
];
}
public static function slugify($string)
{
return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $string), '-'));
}
public static function getPreferences($settings, $default)
{
$color = Arr::get($settings, 'font_color');
$accent = Arr::get($settings, 'accent_color');
if ($color == '' || null) {
$color = Arr::get($default, 'font_color');
}
if ($accent == '' || null) {
$accent = Arr::get($default, 'accent_color');
}
return [
'color' => $color,
'accent' => $accent,
'font' => Arr::get($settings, 'font', Arr::get($default, 'font')),
'fontSize' => Arr::get($settings, 'font_size', Arr::get($default, 'font_size'))
];
}
public static function getDirStructure()
{
/*
* Todo: Need a fix for multi-site network
*/
$workingPath = wp_upload_dir()['basedir'];
$workingDir = apply_filters_deprecated(
'fluentform_pdf_working_dir',
[
$workingPath . '/FLUENT_PDF_TEMPLATES'
],
FLUENTFORM_FRAMEWORK_UPGRADE,
'fluentform/pdf_working_dir',
'Use fluentform/pdf_working_dir instead of fluentform_pdf_working_dir.'
);
$workingDir = apply_filters('fluentform/pdf_working_dir', $workingPath . '/FLUENT_PDF_TEMPLATES');
$tmpDir = apply_filters_deprecated(
'fluentform_pdf_temp_dir',
[
$workingDir . '/temp'
],
FLUENTFORM_FRAMEWORK_UPGRADE,
'fluentform/pdf_temp_dir',
'Use fluentform/pdf_temp_dir instead of fluentform_pdf_temp_dir.'
);
$tmpDir = apply_filters('fluentform/pdf_temp_dir', $workingDir . '/temp');
$cacheDir = apply_filters_deprecated(
'fluentform_pdf_cache_dir',
[
$workingDir . '/pdfCache'
],
FLUENTFORM_FRAMEWORK_UPGRADE,
'fluentform/pdf_cache_dir',
'Use fluentform/pdf_cache_dir instead of fluentform_pdf_cache_dir.'
);
$cacheDir = apply_filters('fluentform/pdf_cache_dir', $workingDir . '/pdfCache');
$fontDir = apply_filters_deprecated(
'fluentform_pdf_font_dir',
[
$workingDir . '/fonts'
],
FLUENTFORM_FRAMEWORK_UPGRADE,
'fluentform/pdf_font_dir',
'Use fluentform/pdf_font_dir instead of fluentform_pdf_font_dir.'
);
$fontDir = apply_filters('fluentform/pdf_font_dir', $workingDir . '/fonts');
return [
'workingDir' => $workingDir,
'tempDir' => apply_filters('fluentform/pdf_temp_dir', $workingDir . '/temp'),
'pdfCacheDir' => apply_filters('fluentform/pdf_cache_dir', $workingDir . '/pdfCache'),
'fontDir' => apply_filters('fluentform/pdf_font_dir', $workingDir . '/fonts')
];
}
public static function getInstalledFonts()
{
$fonts = [
'Unicode' => [
'dejavusanscondensed' => 'Dejavu Sans Condensed',
'dejavusans' => 'Dejavu Sans',
'dejavuserifcondensed' => 'Dejavu Serif Condensed',
'dejavuserif' => 'Dejavu Serif',
'dejavusansmono' => 'Dejavu Sans Mono',
'freesans' => 'Free Sans',
'freeserif' => 'Free Serif',
'freemono' => 'Free Mono',
'mph2bdamase' => 'MPH 2B Damase',
],
'Indic' => [
'lohitkannada' => 'Lohit Kannada',
'pothana2000' => 'Pothana2000',
],
'Arabic' => [
'xbriyaz' => 'XB Riyaz',
'lateef' => 'Lateef',
'kfgqpcuthmantahanaskh' => 'Bahif Uthman Taha',
],
'Chinese, Japanese, Korean' => [
'sun-exta' => 'Sun Ext',
'unbatang' => 'Un Batang (Korean)',
],
'Other' => [
'estrangeloedessa' => 'Estrangelo Edessa (Syriac)',
'kaputaunicode' => 'Kaputa (Sinhala)',
'abyssinicasil' => 'Abyssinica SIL (Ethiopic)',
'aboriginalsans' => 'Aboriginal Sans (Cherokee / Canadian)',
'jomolhari' => 'Jomolhari (Tibetan)',
'sundaneseunicode' => 'Sundanese (Sundanese)',
'taiheritagepro' => 'Tai Heritage Pro (Tai Viet)',
'aegyptus' => 'Aegyptus (Egyptian Hieroglyphs)',
'akkadian' => 'Akkadian (Cuneiform)',
'aegean' => 'Aegean (Greek)',
'quivira' => 'Quivira (Greek)',
'eeyekunicode' => 'Eeyek (Meetei Mayek)',
'lannaalif' => 'Lanna Alif (Tai Tham)',
'daibannasilbook' => 'Dai Banna SIL (New Tai Lue)',
'garuda' => 'Garuda (Thai)',
'khmeros' => 'Khmer OS (Khmer)',
'dhyana' => 'Dhyana (Lao)',
'tharlon' => 'TharLon (Myanmar / Burmese)',
'padaukbook' => 'Padauk Book (Myanmar / Burmese)',
'zawgyi-one' => 'Zawgyi One (Myanmar / Burmese)',
'ayar' => 'Ayar Myanmar (Myanmar / Burmese)',
'taameydavidclm' => 'Taamey David CLM (Hebrew)',
],
];
$fontList = apply_filters_deprecated(
'fluentform_pdf_font_list',
[
$fonts
],
FLUENTFORM_FRAMEWORK_UPGRADE,
'fluentform/pdf_font_list',
'Use fluentform/pdf_font_list instead of fluentform_pdf_font_list.'
);
return apply_filters('fluentform/pdf_font_list', $fonts);
}
}
Classes/Controller/GlobalPdfManager.php 0000644 00000076707 14760002214 0014137 0 ustar 00 app = $app;
$this->registerHooks();
}
protected function registerHooks()
{
// $this->cleanupTempDir();
add_action('fluentform_pdf_cleanup_tmp_dir', array($this, 'cleanupTempDir'));
// Global settings register
add_filter('fluentform/global_settings_components', [$this, 'globalSettingMenu']);
add_filter('fluentform/form_settings_menu', [$this, 'formSettingsMenu']);
// single form pdf settings fields ajax
add_action(
'wp_ajax_fluentform_get_form_pdf_template_settings',
[$this, 'getFormTemplateSettings']
);
add_action('wp_ajax_fluentform_pdf_admin_ajax_actions', [$this, 'ajaxRoutes']);
/*
* Changed from : fluentform_single_entry_widgets
*/
add_filter('fluentform/submissions_widgets', array($this, 'pushPdfButtons'), 10, 3);
add_filter('fluentform/email_attachments', array($this, 'maybePushToEmail'), 10, 5);
add_action('fluentform/addons_page_render_fluentform_pdf_settings', array($this, 'renderGlobalPage'));
add_action('admin_notices', function () {
if (!get_option($this->optionKey) && Acl::hasAnyFormPermission())
echo fluentform_sanitize_html('
');
});
add_filter('fluentform/pdf_body_parse', function($content, $entryId, $formData, $form){
if(!defined('FLUENTFORMPRO')){
return $content;
}
$processor = new \FluentFormPro\classes\ConditionalContent();
return $processor::initiate($content, $entryId, $formData, $form);
}, 10, 4);
add_filter('fluentform/all_editor_shortcodes', [$this, 'pushShortCode'], 10, 2);
add_filter(
'fluentform/shortcode_parser_callback_pdf.download_link',
[$this, 'createLink'],
10,
2
);
add_filter(
'fluentform/shortcode_parser_callback_pdf.download_link.public',
[$this, 'createPublicLink'],
10,
2
);
add_action('wp_ajax_fluentform_pdf_download', [$this, 'download']);
add_action('wp_ajax_fluentform_pdf_download_public', [$this, 'downloadPublic']);
add_action('wp_ajax_nopriv_fluentform_pdf_download_public', [$this, 'downloadPublic']);
}
public function globalSettingMenu($setting)
{
$setting["pdf_settings"] = [
"hash" => "pdf_settings",
"title" => __("PDF Settings", 'fluentform-pdf')
];
return $setting;
}
public function formSettingsMenu($settingsMenus)
{
$settingsMenus['pdf'] = [
'title' => __('PDF Feeds', 'fluentform-pdf'),
'slug' => 'pdf-feeds',
'hash' => 'pdf',
'route' => '/pdf-feeds'
];
return $settingsMenus;
}
public function ajaxRoutes()
{
$maps = [
'get_global_settings' => 'getGlobalSettingsAjax',
'save_global_settings' => 'saveGlobalSettings',
'get_feeds' => 'getFeedsAjax',
'feed_lists' => 'getFeedListAjax',
'create_feed' => 'createFeedAjax',
'get_feed' => 'getFeedAjax',
'save_feed' => 'saveFeedAjax',
'delete_feed' => 'deleteFeedAjax',
'download_pdf' => 'getPdf',
'downloadFonts' => 'downloadFonts'
];
$route = sanitize_text_field($_REQUEST['route']);
Acl::verify('fluentform_forms_manager');
if (isset($maps[$route])) {
$this->{$maps[$route]}();
}
}
public function getGlobalSettingsAjax()
{
wp_send_json_success([
'settings' => $this->globalSettings(),
'fields' => $this->getGlobalFields()
]);
}
private function globalSettings()
{
$defaults = [
'paper_size' => 'A4',
'orientation' => 'P',
'font' => 'default',
'font_size' => '14',
'font_color' => '#323232',
'accent_color' => '#989797',
'heading_color' => '#000000',
'language_direction' => 'ltr'
];
$option = get_option($this->optionKey);
if (!$option || !is_array($option)) {
return $defaults;
}
return wp_parse_args($option, $defaults);
}
public function saveGlobalSettings()
{
$settings = wp_unslash($_REQUEST['settings']);
$sanitizerMap = [
'accent_color' => 'sanitize_text_field',
'font' => 'sanitize_text_field',
'font_color' => 'sanitize_text_field',
'font_size' => 'intval',
'heading_color' => 'sanitize_text_field',
'language_direction' => 'sanitize_text_field',
'orientation' => 'sanitize_text_field',
'font_family' => 'fluentform_sanitize_html',
];
$settings = $this->sanitizeData($settings, $sanitizerMap);
update_option($this->optionKey, $settings);
wp_send_json_success([
'message' => __('Settings successfully updated', 'fluentform-pdf')
], 200);
}
public function getFeedsAjax()
{
$formId = intval($_REQUEST['form_id']);
$form = wpFluent()->table('fluentform_forms')
->where('id', $formId)
->first();
$feeds = $this->getFeeds($form->id);
wp_send_json_success([
'pdf_feeds' => $feeds,
'templates' => $this->getAvailableTemplates($form)
], 200);
}
public function getFeedListAjax()
{
$formId = intval($_REQUEST['form_id']);
$feeds = $this->getFeeds($formId);
$formattedFeeds = [];
foreach ($feeds as $feed) {
$formattedFeeds[] = [
'label' => $feed['name'],
'id' => $feed['id']
];
}
wp_send_json_success([
'pdf_feeds' => $formattedFeeds
], 200);
}
public function createFeedAjax()
{
$templateName = sanitize_text_field($_REQUEST['template']);
$formId = intval($_REQUEST['form_id']);
$form = wpFluent()->table('fluentform_forms')
->where('id', $formId)
->first();
$templates = $this->getAvailableTemplates($form);
if (!isset($templates[$templateName]) || !$formId) {
wp_send_json_error([
'message' => __('Sorry! No template found!', 'fluentform-pdf')
], 423);
}
$template = $templates[$templateName];
$class = $template['class'];
if (!class_exists($class)) {
wp_send_json_error([
'message' => __('Sorry! No template Class found!', 'fluentform-pdf')
], 423);
}
$instance = new $class($this->app);
$defaultSettings = $instance->getDefaultSettings($form);
$sanitizerMap = [
'header' => 'fluentform_sanitize_html',
'footer' => 'fluentform_sanitize_html',
'body' => 'fluentform_sanitize_html'
];
$defaultSettings = $this->sanitizeData($defaultSettings, $sanitizerMap);
$data = [
'name' => $template['name'],
'template_key' => $templateName,
'settings' => $defaultSettings,
'appearance' => $this->globalSettings()
];
$insertId = wpFluent()->table('fluentform_form_meta')
->insertGetId([
'meta_key' => '_pdf_feeds',
'form_id' => $formId,
'value' => wp_json_encode($data)
]);
wp_send_json_success([
'feed_id' => $insertId,
'message' => __('Feed has been created, edit the feed now')
], 200);
}
private function getFeeds($formId)
{
$feeds = wpFluent()->table('fluentform_form_meta')
->where('form_id', $formId)
->where('meta_key', '_pdf_feeds')
->get();
$formattedFeeds = [];
foreach ($feeds as $feed) {
$settings = json_decode($feed->value, true);
$settings['id'] = $feed->id;
$formattedFeeds[] = $settings;
}
return $formattedFeeds;
}
public function getFeedAjax()
{
$formId = intval($_REQUEST['form_id']);
$form = wpFluent()->table('fluentform_forms')
->where('id', $formId)
->first();
$feedId = intval($_REQUEST['feed_id']);
$feed = wpFluent()->table('fluentform_form_meta')
->where('id', $feedId)
->where('meta_key', '_pdf_feeds')
->first();
$settings = json_decode($feed->value, true);
$templateName = ArrayHelper::get($settings, 'template_key');
$templates = $this->getAvailableTemplates($form);
if (!isset($templates[$templateName]) || !$formId) {
wp_send_json_error([
'message' => __('Sorry! No template found!', 'fluentform-pdf')
], 423);
}
$template = $templates[$templateName];
$class = $template['class'];
if (!class_exists($class)) {
wp_send_json_error([
'message' => __('Sorry! No template Class found!', 'fluentform-pdf')
], 423);
}
$instance = new $class($this->app);
$globalFields = $this->getGlobalFields();
$globalFields['watermark_image'] = [
'key' => 'watermark_image',
'label' => __('Watermark Image', 'fluentform-pdf'),
'component' => 'image_widget'
];
$globalFields['watermark_text'] = [
'key' => 'watermark_text',
'label' => __('Watermark Text', 'fluentform-pdf'),
'component' => 'text',
'placeholder' => __('Watermark text', 'fluentform-pdf')
];
$globalFields['watermark_opacity'] = [
'key' => 'watermark_opacity',
'label' => __('Watermark Opacity', 'fluentform-pdf'),
'component' => 'number',
'inline_tip' => __('Value should be between 1 to 100', 'fluentform-pdf')
];
$globalFields['watermark_img_behind'] = [
'key' => 'watermark_img_behind',
'label' => __('Watermark Position', 'fluentform-pdf'),
'component' => 'checkbox-single',
'inline_tip' => __('Set as background', 'fluentform-pdf')
];
$globalFields['security_pass'] = [
'key' => 'security_pass',
'label' => 'PDF Password',
'component' => 'text',
'inline_tip' => __('If you want to set password please enter password otherwise leave it empty', 'fluentform-pdf')
];
$settingsFields = $instance->getSettingsFields();
$settingsFields[] = [
'key' => 'allow_download',
'label' => __('Allow Download', 'fluentform-pdf'),
'tips' => __('Allow this feed to be downloaded on form submission. Only logged in users will be able to download.', 'fluentform-pdf'),
'component' => 'radio_choice',
'options' => [
true => __('Yes', 'fluentform-pdf'),
false => __('No', 'fluentform-pdf')
]
];
$settingsFields[] = [
'key' => 'shortcode',
'label' => __('Shortcode', 'fluentform-pdf'),
'tips' => __('Use this shortcode on submission message to generate PDF link.', 'fluentform-pdf'),
'component' => 'text',
'readonly' => true
];
$settings['settings']['shortcode'] = '{pdf.download_link.' . $feedId. '}';
wp_send_json_success([
'feed' => $settings,
'settings_fields' => $settingsFields,
'appearance_fields' => $globalFields
], 200);
}
public function saveFeedAjax()
{
$formId = intval($_REQUEST['form_id']);
$form = wpFluent()->table('fluentform_forms')
->where('id', $formId)
->first();
$feedId = intval($_REQUEST['feed_id']);
$feed = wp_unslash($_REQUEST['feed']);
if (empty($feed['name'])) {
wp_send_json_error([
'message' => __('Feed name is required', 'fluentform-pdf')
], 423);
}
$sanitizerMap = [
'name' => 'sanitize_text_field',
'header' => 'fluentform_sanitize_html',
'footer' => 'fluentform_sanitize_html',
'body' => 'fluentform_sanitize_html',
'shortcode' => 'sanitize_text_field',
'allow_download' => 'rest_sanitize_boolean',
'logo' => 'sanitize_url',
'invoice_upper_text' => 'sanitize_text_field',
'invoice_thanks' => 'sanitize_text_field',
'invoice_prefix' => 'sanitize_text_field',
'customer_name' => 'sanitize_text_field',
'customer_email' => 'sanitize_email',
'customer_address' => 'sanitize_text_field'
];
$feed = $this->sanitizeData($feed, $sanitizerMap);
wpFluent()->table('fluentform_form_meta')
->where('id', $feedId)
->update([
'value' => wp_json_encode($feed)
]);
wp_send_json_success([
'message' => __('Settings successfully updated', 'fluentform-pdf')
], 200);
}
public function deleteFeedAjax()
{
$feedId = intval($_REQUEST['feed_id']);
wpFluent()->table('fluentform_form_meta')
->where('id', $feedId)
->where('meta_key', '_pdf_feeds')
->delete();
wp_send_json_success([
'message' => __('Feed successfully deleted', 'fluentform-pdf')
], 200);
}
/*
* @return key => [ path, name]
* To register a new template this filter must hook for path mapping
* filter: fluentform_pdf_template_map
*/
public function getAvailableTemplates($form)
{
$templates = [
"general" => [
'name' => 'General',
'class' => '\FluentFormPdf\Classes\Templates\GeneralTemplate',
'key' => 'general',
'preview' => FLUENTFORM_PDF_URL . 'assets/images/basic_template.png'
]
];
if ($form->has_payment) {
$templates['invoice'] = [
'name' => 'Invoice',
'class' => '\FluentFormPdf\Classes\Templates\InvoiceTemplate',
'key' => 'invoice',
'preview' => FLUENTFORM_PDF_URL . 'assets/images/tabular.png'
];
}
$pdfTemplates = apply_filters_deprecated(
'fluentform_pdf_templates',
[
$templates,
$form
],
FLUENTFORM_FRAMEWORK_UPGRADE,
'fluentform/pdf_templates',
'Use fluentform/pdf_templates instead of fluentform_pdf_templates.'
);
return apply_filters('fluentform/pdf_templates', $templates, $form);
}
/*
* @return [ key name]
* global pdf setting fields
*/
public function getGlobalFields()
{
return [
[
'key' => 'paper_size',
'label' => __('Paper size', 'fluentform-pdf'),
'component' => 'dropdown',
'tips' => __('All available templates are shown here, select a default template', 'fluentform-pdf'),
'options' => AvailableOptions::getPaperSizes()
],
[
'key' => 'orientation',
'label' => __('Orientation', 'fluentform-pdf'),
'component' => 'dropdown',
'options' => AvailableOptions::getOrientations()
],
[
'key' => 'font_family',
'label' => __('Font Family', 'fluentform-pdf'),
'component' => 'dropdown-group',
'placeholder' => __('Select Font', 'fluentform-pdf'),
'options' => AvailableOptions::getInstalledFonts()
],
[
'key' => 'font_size',
'label' => __('Font size', 'fluentform-pdf'),
'component' => 'number'
],
[
'key' => 'font_color',
'label' => __('Font color', 'fluentform-pdf'),
'component' => 'color_picker'
],
[
'key' => 'heading_color',
'label' => __('Heading color', 'fluentform-pdf'),
'tips' => __('Select Heading Color', 'fluentform-pdf'),
'component' => 'color_picker'
],
[
'key' => 'accent_color',
'label' => __('Accent color', 'fluentform-pdf'),
'tips' => __('The accent color is used for the borders, breaks etc.', 'fluentform-pdf'),
'component' => 'color_picker'
],
[
'key' => 'language_direction',
'label' => __('Language Direction', 'fluentform-pdf'),
'tips' => __('Script like Arabic and Hebrew are written right to left. For Arabic/Hebrew please select RTL', 'fluentform-pdf'),
'component' => 'radio_choice',
'options' => [
'ltr' => __('LTR', 'fluentform-pdf'),
'rtl' => __('RTL', 'fluentform-pdf')
]
]
];
}
public function pushPdfButtons($widgets, $data, $submission)
{
$formId = $submission->form->id;
$feeds = $this->getFeeds($formId);
if (!$feeds) {
return $widgets;
}
$widgetData = [
'title' => __('PDF Downloads', 'fluentform-pdf'),
'type' => 'html_content'
];
$fluent_forms_admin_nonce = wp_create_nonce('fluent_forms_admin_nonce');
$contents = '';
foreach ($feeds as $feed) {
$fileName = ShortCodeParser::parse($feed['name'], $submission->id,
json_decode($submission->response, true));
$contents .= '- ' . $fileName . '
';
}
$contents .= '
';
$widgetData['content'] = $contents;
$widgets['pdf_feeds'] = $widgetData;
return $widgets;
}
public function getPdfConfig($settings, $default)
{
return [
'mode' => 'utf-8',
'format' => ArrayHelper::get($settings, 'paper_size', ArrayHelper::get($default, 'paper_size')),
'orientation' => ArrayHelper::get($settings, 'orientation', ArrayHelper::get($default, 'orientation')),
// 'debug' => true //uncomment this debug on development
];
}
/*
* when download button will press
* Pdf rendering will control from here
*/
public function getPdf()
{
$feedId = intval($_REQUEST['id']);
$submissionId = intval($_REQUEST['submission_id']);
$feed = wpFluent()->table('fluentform_form_meta')
->where('id', $feedId)
->where('meta_key', '_pdf_feeds')
->first();
$settings = json_decode($feed->value, true);
$settings['id'] = $feed->id;
$form = wpFluent()->table('fluentform_forms')
->where('id', $feed->form_id)
->first();
$templateName = ArrayHelper::get($settings, 'template_key');
$templates = $this->getAvailableTemplates($form);
if (!isset($templates[$templateName])) {
die(__('Sorry! No template found', 'fluentform-pdf'));
}
$template = $templates[$templateName];
$class = $template['class'];
if (!class_exists($class)) {
die(__('Sorry! No template class found', 'fluentform-pdf'));
}
$instance = new $class($this->app);
$instance->viewPDF($submissionId, $settings);
}
public function maybePushToEmail($emailAttachments, $emailData, $formData, $entry, $form)
{
if (!ArrayHelper::get($emailData, 'pdf_attachments')) {
return $emailAttachments;
}
$pdfFeedIds = ArrayHelper::get($emailData, 'pdf_attachments');
$feeds = wpFluent()->table('fluentform_form_meta')
->whereIn('id', $pdfFeedIds)
->where('meta_key', '_pdf_feeds')
->where('form_id', $form->id)
->get();
$templates = $this->getAvailableTemplates($form);
foreach ($feeds as $feed) {
$settings = json_decode($feed->value, true);
$settings['id'] = $feed->id;
$templateName = ArrayHelper::get($settings, 'template_key');
if (!isset($templates[$templateName])) {
continue;
}
$template = $templates[$templateName];
$class = $template['class'];
if (!class_exists($class)) {
continue;
}
$instance = new $class($this->app);
// we have to compute the file name to make it unique
$fileName = $settings['name'] . '_' . $entry->id . '_' . $feed->id;
//parse shortcodes in file name
$fileName = ShortCodeParser::parse( $fileName, $entry->id, $formData);
$fileName = sanitize_title($fileName, 'pdf-file', 'display');
if(is_multisite()) {
$fileName .= '_'.get_current_blog_id();
}
$file = $instance->outputPDF($entry->id, $settings, $fileName, false);
if ($file) {
$emailAttachments[] = $file;
}
}
return $emailAttachments;
}
public function renderGlobalPage()
{
wp_enqueue_script('fluentform_pdf_admin', FLUENTFORM_PDF_URL . 'assets/js/admin.js', ['jquery'], FLUENTFORM_PDF_VERSION, true);
$fontManager = new FontManager();
$downloadableFiles = $fontManager->getDownloadableFonts();
wp_localize_script('fluentform_pdf_admin', 'fluentform_pdf_admin', [
'ajaxUrl' => admin_url('admin-ajax.php')
]);
$statuses = [];
$globalSettingsUrl = '#';
if (!$downloadableFiles) {
$statuses = $this->getSystemStatuses();
$globalSettingsUrl = admin_url('admin.php?page=fluent_forms_settings#pdf_settings');
if (!get_option($this->optionKey)) {
update_option($this->optionKey, $this->globalSettings(), 'no');
}
}
include FLUENTFORM_PDF_PATH . '/assets/views/admin_screen.php';
}
public function downloadFonts()
{
$fontManager = new FontManager();
$downloadableFiles = $fontManager->getDownloadableFonts(3);
$downloadedFiles = [];
foreach ($downloadableFiles as $downloadableFile) {
$fontName = $downloadableFile['name'];
$res = $fontManager->download($fontName);
$downloadedFiles[] = $fontName;
if (is_wp_error($res)) {
wp_send_json_error([
'message' => __('Font Download failed. Please reload and try again', 'fluentform-pdf')
], 423);
}
}
wp_send_json_success([
'downloaded_files' => $downloadedFiles
], 200);
}
private function getSystemStatuses()
{
$mbString = extension_loaded('mbstring');
$mbRegex = extension_loaded('mbstring') && function_exists('mb_regex_encoding');
$gd = extension_loaded('gd');
$dom = extension_loaded('dom') || class_exists('DOMDocument');
$libXml = extension_loaded('libxml');
$extensions = [
'mbstring' => [
'status' => $mbString,
'label' => ($mbString) ? __('MBString is enabled', 'fluentform-pdf') : __('The PHP Extension MB String could not be detected. Contact your web hosting provider to fix.', 'fluentform-pdf')
],
'mb_regex_encoding' => [
'status' => $mbRegex,
'label' => ($mbRegex) ? __('MBString Regex is enabled', 'fluentform-pdf') : __('The PHP Extension MB String does not have MB Regex enabled. Contact your web hosting provider to fix.', 'fluentform-pdf')
],
'gd' => [
'status' => $gd,
'label' => ($gd) ? __('GD Library is enabled', 'fluentform-pdf') : __('The PHP Extension GD Image Library could not be detected. Contact your web hosting provider to fix.', 'fluentform-pdf')
],
'dom' => [
'status' => $dom,
'label' => ($dom) ? __('PHP Dom is enabled', 'fluentform-pdf') : __('The PHP DOM Extension was not found. Contact your web hosting provider to fix.', 'fluentform-pdf')
],
'libXml' => [
'status' => $libXml,
'label' => ($libXml) ? __('LibXml is OK', 'fluentform-pdf') : __('The PHP Extension libxml could not be detected. Contact your web hosting provider to fix', 'fluentform-pdf')
]
];
$overAllStatus = $mbString && $mbRegex && $gd && $dom && $libXml;
return [
'status' => $overAllStatus,
'extensions' => $extensions
];
}
public function cleanupTempDir()
{
$max_file_age = time() - 6 * 3600; /* Max age is 6 hours old */
$dirs = AvailableOptions::getDirStructure();
$cleanUpDirs = [
$dirs['tempDir'].'/ttfontdata/',
$dirs['pdfCacheDir'].'/'
];
foreach ($cleanUpDirs as $tmp_directory) {
if (is_dir($tmp_directory)) {
try {
$directory_list = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($tmp_directory, \RecursiveDirectoryIterator::SKIP_DOTS),
\RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($directory_list as $file) {
if (in_array($file->getFilename(), ['.htaccess', 'index.html'], true)) {
continue;
}
if ($file->isReadable() && $file->getMTime() < $max_file_age) {
if (!$file->isDir()) {
unlink($file);
}
}
}
} catch (\Exception $e) {
//
}
}
}
}
public function pushShortCode($shortCodes, $formID)
{
$feeds = wpFluent()->table('fluentform_form_meta')
->where('form_id', $formID)
->where('meta_key', '_pdf_feeds')
->get();
$feedShortCodes = [
'{pdf.download_link}' => 'Submission PDF link'
];
foreach ($feeds as $feed) {
$feedSettings = json_decode($feed->value);
$key = '{pdf.download_link.' . $feed->id . '}';
$feedShortCodes[$key] = $feedSettings->name . ' feed PDF link';
}
$shortCodes[] = [
'title' => __('PDF', 'fluentform-pdf'),
'shortcodes' => $feedShortCodes
];
return $shortCodes;
}
/**
* @var string $shortCode
* @var \FluentForm\App\Services\FormBuilder\ShortCodeParser $parser
*/
public function createLink($shortCode, $parser)
{
$form = $parser->getForm();
$entry = $parser->getEntry();
// Currently we are assuming there is only one PDF Feed.
// Hence the PDF Download Link will always be the first one.
$feed = wpFluent()->table('fluentform_form_meta')
->where('form_id', $form->id)
->where('meta_key', '_pdf_feeds')
->first();
if ($feed) {
$feedSettings = json_decode($feed->value, true);
if (ArrayHelper::get($feedSettings, 'settings.allow_download')) {
$nonce = wp_create_nonce('fluent_forms_admin_nonce');
$url = admin_url('admin-ajax.php?action=fluentform_pdf_download&fluent_forms_admin_nonce=' . $nonce . '&submission_id=' . $entry->id . '&id=' . $feed->id);
return $url;
}
}
}
public function download()
{
Acl::verifyNonce();
if (!is_user_logged_in()) {
$message = __('Sorry! You have to login first.', 'fluentform-pdf');
wp_send_json_error([
'message' => $message
], 422);
}
$hasPermission = Acl::hasPermission('fluentform_entries_viewer');
if (!$hasPermission) {
$submissionId = intval($_REQUEST['submission_id']);
$submission = wpFluent()->table('fluentform_submissions')
->where('id', $submissionId)
->where('user_id', get_current_user_id())
->first();
if (!$submission) {
$message = __("You don't have permission to download the PDF.", 'fluentform-pdf');
wp_send_json_error([
'message' => $message
], 422);
}
}
return $this->getPdf();
}
public function createPublicLink($shortCode, $parser)
{
$feedID = str_replace('pdf.download_link.', '', $shortCode);
if ($feedID) {
$feed = wpFluent()->table('fluentform_form_meta')
->where('id', $feedID)
->first();
if ($feed) {
$entry = $parser->getEntry();
$hashedEntryID = base64_encode(Protector::encrypt($entry->id));
$hashedFeedID = base64_encode(Protector::encrypt($feedID));
return admin_url('admin-ajax.php?action=fluentform_pdf_download_public&submission_id=' . $hashedEntryID . '&id=' . $hashedFeedID);
}
}
}
public function downloadPublic()
{
$feedId = intval(Protector::decrypt(base64_decode($_REQUEST['id'])));
$submissionId = intval(Protector::decrypt(base64_decode($_REQUEST['submission_id'])));
$_REQUEST['id'] = $feedId;
$_REQUEST['submission_id'] = $submissionId;
return $this->getPdf();
}
private function sanitizeData($settings, $sanitizerMap)
{
if (fluentformCanUnfilteredHTML()) {
return $settings;
}
return fluentform_backend_sanitizer($settings, $sanitizerMap);
}
}
Classes/Templates/GeneralTemplate.php 0000644 00000010056 14760002214 0013657 0 ustar 00 'PDF Title
',
'footer' => '{DATE j-m-Y} | {PAGENO}/{nbpg} |
',
'body' => '{all_data}'
];
}
public function getSettingsFields()
{
return array(
[
'key' => 'header',
'label' => __('Header Content', 'fluentform-pdf'),
'tips' => __('Write your header content which will be shown every page of the PDF', 'fluentform-pdf'),
'component' => 'wp-editor'
],
[
'key' => 'body',
'label' => __('PDF Body Content', 'fluentform-pdf'),
'tips' => __('Write your Body content for actual PDF body', 'fluentform-pdf'),
'component' => 'wp-editor',
'inline_tip' => defined('FLUENTFORMPRO') ?
sprintf(__('You can use Conditional Content in PDF body, for details please check this %s. ',
'fluentform-pdf'),
'Documentation') : __('Conditional PDF Body Content is supported in Fluent Forms Pro Version',
'fluentform-pdf'),
],
[
'key' => 'footer',
'label' => __('Footer Content', 'fluentform-pdf'),
'tips' => __('Write your Footer content which will be shown every page of the PDF', 'fluentform-pdf'),
'component' => 'wp-editor',
'inline_tip' => __('Write your Footer content which will be shown every page of the PDF', 'fluentform-pdf'),
]
);
}
public function generatePdf($submissionId, $feed, $outPut = 'I', $fileName = '')
{
$settings = $feed['settings'];
$submission = wpFluent()->table('fluentform_submissions')
->where('id', $submissionId)
->first();
$formData = json_decode($submission->response, true);
$settings = ShortCodeParser::parse($settings, $submissionId, $formData, null, false, 'pdfFeed');
if (!empty($settings['header'])) {
$this->headerHtml = $settings['header'];
}
$htmlBody = $settings['body']; // Inserts HTML line breaks before all newlines in a string
$form = wpFluent()->table('fluentform_forms')->find($submission->form_id);
$htmlBody = apply_filters_deprecated(
'ff_pdf_body_parse',
[
$htmlBody,
$submissionId,
$formData,
$form
],
FLUENTFORM_FRAMEWORK_UPGRADE,
'fluentform/pdf_body_parse',
'Use fluentform/pdf_body_parse instead of ff_pdf_body_parse.'
);
$htmlBody = apply_filters('fluentform/pdf_body_parse', $htmlBody, $submissionId, $formData, $form);
$footer = $settings['footer'];
if (!$fileName) {
$fileName = ShortCodeParser::parse($feed['name'], $submissionId, $formData);
$fileName = sanitize_title($fileName, 'pdf-file', 'display');
}
return $this->pdfBuilder($fileName, $feed, $htmlBody, $footer, $outPut);
}
}
Classes/Templates/TemplateManager.php 0000644 00000024512 14760002214 0013656 0 ustar 00 app = $app;
$dirStructure = AvailableOptions::getDirStructure();
$this->workingDir = $dirStructure['workingDir'];
$this->tempDir = $dirStructure['tempDir'];
$this->pdfCacheDir = $dirStructure['pdfCacheDir'];
$this->fontDir = $dirStructure['fontDir'];
}
abstract public function getSettingsFields();
abstract public function generatePdf($submissionId, $settings, $outPut, $fileName = '');
public function viewPDF($submissionId, $settings)
{
$this->generatePdf($submissionId, $settings, 'I');
}
/*
* This name should be unique otherwise, it may just return from another file cache
*/
public function outputPDF($submissionId, $settings, $fileName = '', $forceClear = false)
{
$fileName = $this->pdfCacheDir . '/' . $fileName;
if (!$forceClear && file_exists($fileName . '.pdf')) {
return $fileName . '.pdf';
}
$this->generatePdf($submissionId, $settings, 'F', $fileName);
if (file_exists($fileName . '.pdf')) {
return $fileName . '.pdf';
}
return false;
}
public function downloadPDF($submissionId, $settings)
{
return $this->generatePdf($submissionId, $settings, 'D');
}
public function getGenerator($mpdfConfig)
{
$defaults = [
'fontDir' => [
$this->fontDir
],
'tempDir' => $this->tempDir,
'curlCaCertificate' => ABSPATH . WPINC . '/certificates/ca-bundle.crt',
'curlFollowLocation' => true,
'allow_output_buffering' => true,
'autoLangToFont' => true,
'autoScriptToLang' => true,
'useSubstitutions' => true,
'ignore_invalid_utf8' => true,
'setAutoTopMargin' => 'stretch',
'setAutoBottomMargin' => 'stretch',
'enableImports' => true,
'use_kwt' => true,
'keepColumns' => true,
'biDirectional' => true,
'showWatermarkText' => true,
'showWatermarkImage' => true,
];
$mpdfConfig = wp_parse_args($mpdfConfig, $defaults);
$mpdfConfig = apply_filters_deprecated(
'fluentform_mpdf_config',
[
$mpdfConfig
],
FLUENTFORM_FRAMEWORK_UPGRADE,
'fluentform_mpdf_config',
'Use fluentform_mpdf_config instead of fluentform_mpdf_config.'
);
$mpdfConfig = apply_filters('fluentform/mpdf_config', $mpdfConfig);
if (!class_exists('\Mpdf\Mpdf')) {
require_once FLUENTFORM_PDF_PATH . 'vendor/autoload.php';
}
return new \Mpdf\Mpdf($mpdfConfig);
}
public function pdfBuilder($fileName, $feed, $body = '', $footer = '', $outPut = 'I')
{
$body = str_replace('{page_break}', '', $body);
$appearance = Arr::get($feed, 'appearance');
$mpdfConfig = array(
'mode' => 'utf-8',
'format' => Arr::get($appearance, 'paper_size'),
'margin_header' => 10,
'margin_footer' => 10,
'orientation' => Arr::get($appearance, 'orientation'),
);
if ($fontFamily = ArrayHelper::get($appearance, 'font_family')) {
$mpdfConfig['default_font'] = $fontFamily;
}
if (!defined('FLUENTFORMPRO')) {
$footer .= 'Powered By Fluent Forms
';
}
$pdfGenerator = $this->getGenerator($mpdfConfig);
if (ArrayHelper::get($appearance, 'security_pass')) {
$password = ArrayHelper::get($appearance, 'security_pass');
$pdfGenerator->SetProtection(array(), $password, $password);
}
if (ArrayHelper::get($appearance, 'language_direction') == 'rtl') {
$pdfGenerator->SetDirectionality('rtl');
$body = '' . $body . '
';
if ($footer) {
$footer = '' . $footer . '
';
}
if ($this->headerHtml) {
$this->headerHtml = '' . $this->headerHtml . '
';
}
}
if ($this->headerHtml) {
$this->headerHtml = $this->applyInlineCssStyles($this->headerHtml, $appearance);
$pdfGenerator->SetHTMLHeader($this->headerHtml);
}
$body = $this->applyInlineCssStyles($body, $appearance, true);
if (!empty($appearance['watermark_text']) || !empty($appearance['watermark_image'])) {
$alpha = Arr::get($appearance, 'watermark_opacity');
if (!$alpha || $alpha > 100) {
$alpha = 5;
}
$alpha = $alpha / 100;
if (!empty($appearance['watermark_image'])) {
$pdfGenerator->SetWatermarkImage($appearance['watermark_image'], $alpha);
if( Arr::isTrue($appearance, 'watermark_img_behind' )){
$pdfGenerator->watermarkImgBehind = true;
}
$pdfGenerator->showWatermarkImage = true;
} else {
$pdfGenerator->SetWatermarkText($appearance['watermark_text'], $alpha);
$pdfGenerator->showWatermarkText = true;
}
}
$footer = $this->applyInlineCssStyles($footer, $appearance);
$pdfGenerator->SetHTMLFooter($footer);
$pdfGenerator->WriteHTML('' . $body . '
', \Mpdf\HTMLParserMode::HTML_BODY);
if ($outPut == 'S') {
return $pdfGenerator->Output($fileName . '.pdf', $outPut);
}
$pdfGenerator->Output($fileName . '.pdf', $outPut);
}
public function getPdfCss($appearance)
{
$mainColor = Arr::get($appearance, 'font_color');
if (!$mainColor) {
$mainColor = '#4F4F4F';
}
$secondaryColor = Arr::get($appearance, 'accent_color');
if (!$secondaryColor) {
$secondaryColor = '#EAEAEA';
}
$headingColor = Arr::get($appearance, 'heading_color');
$fontSize = Arr::get($appearance, 'font_size', 14);
ob_start();
?>
.ff_pdf_wrapper, p, li, td, th {
color: ;
font-size: px;
}
.ff_all_data, table {
empty-cells: show;
border-collapse: collapse;
border: 1px solid ;
width: 100%;
color: ;
}
hr {
color: ;
background-color: ;
}
h1, h2, h3, h4, h5, h6 {
color: ;
}
.ff_all_data th {
border-bottom: 1px solid ;
border-top: 1px solid ;
padding-bottom: 10px !important;
}
.ff_all_data tr td {
padding-left: 30px !important;
padding-top: 15px !important;
padding-bottom: 15px !important;
}
.ff_all_data tr td, .ff_all_data tr th {
border: 1px solid ;
text-align: left;
}
table, .ff_all_data {width: 100%; overflow:wrap;} img.alignright { float: right; margin: 0 0 1em 1em; }
img.alignleft { float: left; margin: 0 10px 10px 0; }
.center-image-wrapper {text-align:center;}
.center-image-wrapper img.aligncenter {display: initial; margin: 0; text-align: center;}
.alignright { float: right; }
.alignleft { float: left; }
.aligncenter { display: block; margin-left: auto; margin-right: auto; text-align: center; }
.invoice_title {
padding-bottom: 10px;
display: block;
}
.ffp_table thead th {
background-color: #e3e8ee;
color: #000;
text-align: left;
vertical-align: bottom;
}
table th {
padding: 5px 10px;
}
.ff_rtl table th, .ff_rtl table td {
text-align: right !important;
}
resolveCenteredImage($html);
try {
// apply CSS styles inline for picky email clients
$emogrifier = new Emogrifier($html, $this->getPdfCss($appearance));
if ($keepBodyTag) {
$html = $emogrifier->emogrify();
} else {
$html = $emogrifier->emogrifyBodyContent();
}
} catch (\Exception $e) {
}
return $html;
}
private function resolveCenteredImage($html)
{
if (strpos($html, '
]+>)/i', $html, $matches);
foreach ($matches[0] as $image) {
if (strpos($image, 'aligncenter') !== false) {
$newImg = " $image
";
$newHtml = str_replace($image, $newImg, $html);
if ($newHtml) {
$html = $newHtml;
}
}
}
return $html;
}
}
Classes/Templates/InvoiceTemplate.php 0000644 00000023020 14760002214 0013671 0 ustar 00 '',
'invoice_upper_text' => '',
'invoice_thanks' => 'Thank you for your order',
'invoice_prefix' => '',
'customer_name' => '',
'customer_email' => '',
'customer_address' => ''
];
}
public function getSettingsFields()
{
return array(
[
'key' => 'logo',
'label' => __('Business Logo', 'fluentform-pdf'),
'tips' => __('Your Business Logo which will be shown in the invoice header', 'fluentform-pdf'),
'component' => 'image_widget'
],
[
'key' => 'customer_name',
'label' => __('Customer Name', 'fluentform-pdf'),
'tips' => __('Please select the customer name field from the smartcode dropdown', 'fluentform-pdf'),
'component' => 'value_text'
],
[
'key' => 'customer_email',
'label' => __('Customer Email', 'fluentform-pdf'),
'tips' => __('Please select the customer email field from the smartcode dropdown', 'fluentform-pdf'),
'component' => 'value_text'
],
[
'key' => 'customer_address',
'label' => __('Customer Address', 'fluentform-pdf'),
'tips' => __('Please select the customer address field from the smartcode dropdown', 'fluentform-pdf'),
'component' => 'value_text'
],
[
'key' => 'invoice_prefix',
'label' => __('Invoice Prefix', 'fluentform-pdf'),
'tips' => __('Add your invoice prefix which will be prepended with the invoice number', 'fluentform-pdf'),
'component' => 'value_text'
],
[
'key' => 'invoice_upper_text',
'label' => __('Invoice Body Text', 'fluentform-pdf'),
'tips' => __('Write Invoice body text. This will show before the invoice items', 'fluentform-pdf'),
'component' => 'wp-editor'
],
[
'key' => 'invoice_thanks',
'label' => __('Invoice Footer Text', 'fluentform-pdf'),
'tips' => __('Write Invoice Footer Text. This will show at the end of the invoice', 'fluentform-pdf'),
'component' => 'value_textarea'
]
);
}
public function generatePdf($submissionId, $feed, $outPut, $fileName = '')
{
$settings = $feed['settings'];
$submission = wpFluent()->table('fluentform_submissions')
->where('id', $submissionId)
->first();
$formData = json_decode($submission->response, true);
$settings['invoice_lines'] = '{payment.order_items}';
$invoiceUpperText = Arr::get($settings, 'invoice_upper_text', '');
if (
false !== strpos($invoiceUpperText, '{payment.receipt}') ||
false !== strpos($invoiceUpperText, '{payment.order_items}')
) {
$settings['invoice_lines'] = '';
}
$settings['payment_summary'] = '{payment.summary_list}';
$settings = ShortCodeParser::parse($settings, $submissionId, $formData, null, false, 'pdfFeed');
$htmlBody = $this->generateInvoiceHTML($submission, $settings, $feed);
$htmlBody = str_replace('{page_break}', '', $htmlBody);
$form = wpFluent()->table('fluentform_forms')->find($submissionId);
$htmlBody = apply_filters_deprecated(
'ff_pdf_body_parse',
[
$htmlBody,
$submissionId,
$formData,
$form
],
FLUENTFORM_FRAMEWORK_UPGRADE,
'fluentform/pdf_body_parse',
'Use fluentform/pdf_body_parse instead of ff_pdf_body_parse.'
);
$htmlBody = apply_filters('fluentform/pdf_body_parse', $htmlBody, $submissionId, $formData, $form);
if(!$fileName) {
$fileName = ShortCodeParser::parse( $feed['name'], $submissionId, $formData);
$fileName = sanitize_title($fileName, 'pdf-file', 'display');
}
return $this->pdfBuilder($fileName, $feed, $htmlBody, '', $outPut);
}
private function generateInvoiceHTML($submission, $settings, $feed)
{
$paymentSettings = false;
$logo = Arr::get($settings, 'logo');
if(class_exists('\FluentFormPro\Payments\PaymentHelper')) {
$paymentSettings = \FluentFormPro\Payments\PaymentHelper::getPaymentSettings();
if(!$logo) {
$logo = Arr::get($paymentSettings, 'business_logo');
}
}
ob_start();
?>
|
|
serial_number; ?>
id); ?>
created_at))); ?>
|
ªïµoA` ×ÂçÒ#£ËÛê2o1 @ËrïªTrdŒ7
¸j%0 ZT×–¥FF#“ÛÛú^œ¹ €–Ô}D‰‘QçÆýý}}/ÎÜ @š:l®ë'~Ó= aMŸd]ZdllÕ󺓉)R%
j:.*CÉ0Eª !mÅE¥”È°“T¿ €´•"£Î¤îî&õ½8s 5;ûXF\TÚŽŒÑ¸¾×¾›XÍÞ6 P³½”Ö{êj32ÖGÍOš#0 jk¿•:§HYèÝ> Ð ‘ñ½:yßÚª¶u !"ƒ!
3u¶w¯’Z'0 &2ê3¹µMmÛ @†Ûë/ Ð’!GF;IÑ.o- @‹†u`ÜÞÞÔóÂÌM` ´lˆ‘a£¿¼µ ZdŒÆy_r €B)2ÖGù^멉ÃöZ%0
2¨È¨ég¼¿»¯ç…™‹À (ÌP"cd«Ú^2ûGnÿÿ%íý6 @/T‘qüuJw|WEÆÑOÊ]¨};¹Mã
õÒÑ#÷_ým2 ýÑ÷ÈØØJéæ*ç•Í\_]NÆB£ `F27™LÒÅùÙwßx¼‘FãQÚoN]¯s…9 t}ŒºÛ{*ß‹¯«4ÙX__O£Ñ8Æã´1Þ0Ê‘™À è€>FF[#wwwéîî:ÝÜ\?$GJ£ÑhÕ´*£Ë Ñ·È(é°½˜V_Õ’µµµé(GÄÆÆtŠÕxú×x›À è>EFɃ÷÷÷ßMz<Êѱ±1Ž‘ãÈŸå® tLŸ"#žÑ'u_X&Õ(Çõõlœãñ(G5µÊ(‡À 褾DFŒbt%0žz<ÊQ‰äã‡)UÓ‘ŽŽr €ŽêCd”vZùªbùt„ãú*]<¼ÖÐ¶É 00ñË”þâ¼ë}÷ßý_)ýïÿ¦½rÞÈ
`‡Ø—¶É}<µªOF¬ýüÓÚÎÁÐo,äþâdz
> ù•|_›o“[©F9ú°M®Àè‘ñ?ýË´öË?úm€…Üù7éæ¯þÜM¨É[‘±±åΧŒrÌÄbñïÖrtì0@ @Œd,.ÇÇÓà »°M®À è¡õÂvK})2ÆXƒ‘ËkÛä–t À è¡_ìÎvh*}w)#Ë{î0Àƒƒ£Ö§SyK zh{4Û¶´m`«È¸>ëIsØÛÛ/b†w §ªs2JŒÑf¿Ï…hBÄÅæÖv×"0 z¬‘±VÚ‚‘Ž)).’À è¿Ò#crSÐB‘Ž)-.’EÞ 0<¿¹Hé_ðÆwÑä>¥ÑœöÇûüXÇ_—·ð;]Þp%ÝSb\$ ÃóÏ¿š}Ñ7W)Ï~=úbùÃéJWj\$S¤ Êu7IéÓ׳¯›‡#žO?üp¦E•:]Šù•I` ”éê<¥¿û>,*“ÛÙhÆ*DFw•I` ”'F)N¾}yÓÅéÃcQ"£{ºI` ”#¦>|“ÒåÙÛ—´êT©4€ÈXïÑÖ•¸H ±eëÕÅ|—S¥Î>~é}ŽŒx ÿÙOÒþþaÚÚÞN£Q7ôëR\$»H ´¯Š‹é–ˆ‘ŽÍí”6wVûú¾»ÔÆææô+Üßߧ›ë«tss“nooÒ]á?p×â" €öÅt§Eã¢ïû8
{µ£‘q7™üè¯MØ«‡ö»»Iº¾¾N·ÁRŠ.ÆE í:û8ÿ´¨çDDd|¾úѷȘgtb}}”¶·wRÚž
M&·?Ž¶t5.’À hOì;B*eëbõ©RÉa|i4§qJ÷2Bãúæjúë䙑:t9.’À hÇýÃÈC.¹¦J%‘ñãéWzX¿1
Žë«ÚÖot=.’À hGŒ\ÄNP¹Ä³îñ7)}‘çû÷«îãûD¬ßx¼`<ÖoÌ‚ã:Ëú>ÄE Í‹çÞËS£žª¦\íìçy½®GFÝSšbýÆæÖè»(ˆõ±;ÕÍCp,¢/q‘ @ó"êz`¿8Nik'¥õLG>˜.5¿X¿_ÛÆctãæöfº-îk±Ó§¸H yWçõ}ˈ€“oóM•J"ciÕúÝïÖoÜÜ^OG8ªõ}‹‹$0 šu}‘wíÅsrO•J"ce?X¿±;[¿Ñ#}ÓÃCá Êu}ÙÌ¥ÅT©ÜÇ8T‘±Þ¡'È5(Q¬ßèc\$ ЬëÕ[Ä]æmp+]Œšå @CbD¡ÉéE·×)ç]‘Ákü± hH¬hZÆ]
»µŠ^â @CnŒxø?ø,ß–µOu!2në^QÏ €†49=j{/¥÷?Kik·ÞïSzd¬zº6‹
ibŠT<èÇûïSZkèI¯äȈCîDF³ @OŒ7g£[Íÿ<¥FFœ }rüQd4H` ô@L‰:úIs£Ï$ Ð}MN‰zÈ@` tX%Ã&0 :*Ö\”‘1\ `Igg§s·åðó²ß9‘1L ` §Rº8Méãïf¿6m÷°¾ôrÃ#0 qqyöýß#ñ×îß8H/×ö±ñ°¾³ßwMd‹À XÀÓ¸¨Ä_ûôû”î&/¿V®ì8»„£!2†C` Ì饸¨Ü^ϦL½tb÷h#ÏÞ9èæ;&2†A` ÌḨÜÝ¥ôéëç×eŒ3FìÕ…µ/ý'0 Þ0o\<öܺŒk06·»ÿn‰Œ~ ¯X&.*ÕºŒj+ÛX71¯v·s-o›Èè/ ð‚Uâ¢ë2Ž¿NéúböVèK`¤G‘±6Z+àj¾'2V#0 ž‘#.*±.ãø›”ÎW„UG?J4Œ_¥µ5‘Ñ à‰œqñXF¼ö²º¼¸û5ãíq:8,32noZ<ª½£ À#uÅEåîÃø†j4*/2öööÓÆæfWÒ- àAÝqÁëJŠŒˆ‹ÍlÙÕ .ŠQBdˆ‹Õ `ðº/Þ7mF†¸XÀ k#÷YÃÑFdˆ‹< 0Xw“ïϧèŠÛmjÔddˆ‹| 0X±ík‰§I¿f(Ó¤*MD†¸ÈK` ƒV&Ý•ÈZ`¤š#C\ä'0 €ÁëRdD`eÆcuD†¸¨‡À èXd\_p-Èâ¢> àAW"£kÓsÊâ¢^ à‘.DÆÕÅl¬¡Z%2ÄEý À]ˆŒ¡Ÿ:¾Ldˆ‹f¬ýÃôg÷CøA‡`íçœÖv†~`!÷'éþ«¿uÓX™÷Óäú2ÿö?¤û‡ÖÖGéðgÿImvÿy•O&·éäøSº¿ý‘V\4G` ¼bÞØ6ħ÷ñ)~|š?do½Gâ¢Y¦H ¼¢ÉÓ¤Ôñ`ØCöÚ{$.š'0 Þ 2Ê÷Ü{$.Ú!0 æ 2Ê÷ø=í så‹÷èèÝgâ¢E `"£|%¾7C"0 $2àe ` "ž'0 –$2àÇ À
DüÀ X‘È€ï €DÌ €LD €¬DC'0 2™À ¨È`¨ @MDC$0 j$2 P3‘ÁŒ½Û @éâá÷þî~ú0|ûèAxc¼1ýu}´žÖ×GEÿUdÄÃ|ü%©"#®/®VáO P”iDÜܤ›Ûë鯓ÉäÅË»|òßÇã4ÒæÆVol÷ÆŠ†ÀŸ 7××éêê2ÝÜ\/}9··7Ó¯«ËËét¤Í´µµ]TlˆúΟ 5ñ@Qquy‘îîî²^F¼öõõÕôk4¥íí´¹µ]Ä›-2è3‹¼€V\_]¦O¿MçgÙã⩘fuvv:ý~ñ}K`á7}%0 €FźŠãO¦üMz!ß7¾\GÛD}$0 €FÄëùùi:9ùôêÂí&Ä÷ë8=9n}Š’È o P»x@=9þ8]|]’XPÓ¦by›D}"0 €ZÅš‡Ùj»£/‰èÓÓãtvzÒêh†È / P›˜ÕÆZ‹eÄnS1ÊÒæC´È P‹(mJÔ[¦k3Ž?µ:eJdÐu È*Bc—¦è¢jÊÔååEkW/2è2 d3{øüXìz‹EÄù1
Ó‘AW ‹>ÅE%FaÚ\ü-2è" dÑ·¸¨T‹¿EƉž#0 €•Å§ü}Œ‹Êlñ·ÈxŽÈà) ¬$⢫º!2^&2xL` K‹Cô†‘ñ2‘AE` K‰É8DohDÆËâžLnÆÐ `aÕ§ÕC%2ž···Ÿ6·¶‹º&š'0 €…ž·öp]
‘ñCâ‚ŠÀ '\ßÞÞ¸i"ã;â‚Ç 0·Xw'\ó½¡G†¸à) Ì-¶¤ådžâ‚ç `.15ªÏ‡éjh‘!.x‰À ÞÍ—çnÔ†â‚× àMçg§ƒß5j^}qÁ[Æî ðšXØÝôiÝëëëics3mmmO˜+ww“4¹L¯§äÄ«È88|×Êâë*2⬒œ¡#.˜‡À ^u~ÖÜ®Qñ0¾µ½“vvvŸýß××Gi}s4Ýûý麫ˋ"GWúâ‚y™" ¼èö榱3/F£Q: