-1, 'post_type' => 'wpforms' ); $wpforms = get_posts($args); if ($wpforms) { foreach ($wpforms as $post) { $form_id = $post->ID; $form_title = $post->post_title; $forms[$form_id] = $form_title; } } else { $forms[0] = esc_html__("No form", "pdf-for-wpforms"); } return $forms; } function wpforms_form_settings_pdf_single_after() { ?>

post_type) && $post->post_type == "yeepdf") || (isset($_GET["post_type"]) && $_GET["post_type"] == "yeepdf")) { if (isset($post->ID)) { $id_entry = get_post_meta($post->ID, '_pdfcreator_wpforms_entry', true); if ($id_entry != "" && $id_entry != 0) { $table_wp_submissions = $wpdb->prefix . "wpforms_entry_fields"; $results = $wpdb->get_results( $wpdb->prepare( "SELECT id,value,field_id FROM $table_wp_submissions WHERE entry_id = %s ORDER BY entry_id DESC LIMIT 200", $id_entry ), ARRAY_A ); foreach ($results as $rs) { $shortcodes["{field_id='" . $rs["field_id"] . "'}"] = $rs["value"]; $shortcodes['{field_id="' . $rs["field_id"] . '"}'] = $rs["value"]; } } $form_id = get_post_meta($post->ID, '_pdfcreator_wpforms', true); if (!empty($form_id)) { $form = wpforms()->form->get(absint($form_id)); if (!empty($form->post_content)) { $f_data = wpforms_decode($form->post_content); if (!empty($f_data['fields'])) { foreach ($f_data['fields'] as $f_id => $f_val) { if ($f_val['type'] === 'html' && isset($f_val['code'])) { $shortcodes["{field_id='" . $f_id . "'}"] = $f_val['code']; $shortcodes['{field_id="' . $f_id . '"}'] = $f_val['code']; } elseif ($f_val['type'] === 'content' && isset($f_val['content'])) { $shortcodes["{field_id='" . $f_id . "'}"] = $f_val['content']; $shortcodes['{field_id="' . $f_id . '"}'] = $f_val['content']; } } } } } } } return $shortcodes; } function yeepdf_output_html($html, $data_attrs) { global $wpdb; $table_wp_submissions = $wpdb->prefix . "wpforms_entry_fields"; $query = $wpdb->prepare('SHOW TABLES LIKE %s', $wpdb->esc_like($table_wp_submissions)); if ($wpdb->get_var($query) == $table_wp_submissions) { $template_id = $data_attrs["id_template"]; $id_entry = get_post_meta($template_id, '_pdfcreator_wpforms_entry', true); $shortcodes = array(); if ($id_entry != "" && $id_entry != 0) { $results = $wpdb->get_results( $wpdb->prepare( "SELECT id,value,field_id FROM $table_wp_submissions WHERE entry_id = %s ORDER BY entry_id DESC LIMIT 200", $id_entry ), ARRAY_A ); foreach ($results as $rs) { $shortcodes["{field_id='" . $rs["field_id"] . "'}"] = $rs["value"]; $shortcodes['{field_id="' . $rs["field_id"] . '"}'] = $rs["value"]; } } $form_id = get_post_meta($template_id, '_pdfcreator_wpforms', true); if (!empty($form_id)) { $form = wpforms()->form->get(absint($form_id)); if (!empty($form->post_content)) { $f_data = wpforms_decode($form->post_content); if (!empty($f_data['fields'])) { foreach ($f_data['fields'] as $f_id => $f_val) { if ($f_val['type'] === 'html' && isset($f_val['code'])) { $shortcodes["{field_id='" . $f_id . "'}"] = $f_val['code']; $shortcodes['{field_id="' . $f_id . '"}'] = $f_val['code']; } elseif ($f_val['type'] === 'content' && isset($f_val['content'])) { $shortcodes["{field_id='" . $f_id . "'}"] = $f_val['content']; $shortcodes['{field_id="' . $f_id . '"}'] = $f_val['content']; } } } } } if (!empty($shortcodes)) { $html = str_replace(array_keys($shortcodes), array_values($shortcodes), $html); } } return $html; } function yeepdf_wp_get_entries() { global $wpdb; $table_wp_submissions = $wpdb->prefix . "wpforms_entries"; $query = $wpdb->prepare('SHOW TABLES LIKE %s', $wpdb->esc_like($table_wp_submissions)); if ($wpdb->get_var($query) == $table_wp_submissions) { $data = sanitize_text_field($_POST["form_id"]); if ($data != "" && $data > 0) { $results = $wpdb->get_results( $wpdb->prepare( "SELECT entry_id,fields FROM $table_wp_submissions WHERE form_id = %s ORDER BY entry_id DESC LIMIT 20", $data ), ARRAY_A ); if (count($results) > 0) { foreach ($results as $rs) { $check = ""; $name = ""; $data_json = json_decode($rs["fields"], true); if (count($data_json) > 0) { foreach ($data_json as $data_fields) { $name = $data_fields["name"] . " - " . $rs["entry_id"]; break; } } ?> .wpforms-order-summary-preview, .wpforms-order-summary-preview th, .wpforms-order-summary-preview td{ border-collapse: collapse; padding: 10px; text-align: left; } .wpforms-order-summary-preview td { border: none !important; } .wpforms-order-summary-preview tr{ border: 1px solid #888888; } .wpforms-order-summary-preview-total { font-weight: bold; } .wpforms-order-summary-placeholder-hidden,.wpforms-order-summary-placeholder { display: none !important; } .wpforms-order-summary-item-quantity { text-align: center !important; } is_pro(); } else { return false; } } function settings_js() { global $post; $add_libs = false; if ((isset($post->post_type) && $post->post_type == "yeepdf") || (isset($_GET["post_type"]) && $_GET["post_type"] == "yeepdf")) { $add_libs = true; } $add_libs = apply_filters("yeepdf_add_libs", $add_libs); if ((isset($_GET["page"]) && $_GET["page"] == "wpforms-builder") || $add_libs) { wp_enqueue_script('yeepdf_wpforms', BUIDER_PDF_WPFORMS_PLUGIN_URL . 'wpforms/yeepdf-wpforms.js', array("jquery")); wp_localize_script("yeepdf_wpforms", "yeepdf_wpforms", array("pro" => "pro")); } } function yeepdf_add_libs($add) { if (isset($_GET["page"]) && $_GET["page"] == "wpforms-builder") { $add = true; } return $add; } function wpforms_smarttags_process_value($content, $tag_name, $form_data) { if (isset($form_data["cover_r_to_br"]) && $form_data["cover_r_to_br"] && isset($content)) { $new_content = nl2br($content); $content = apply_filters("yeepdf_format_br", $new_content, $content); } return $content; } function wpforms_builder_strings($strings) { $add = array( 'yeepdf_creator_delete' => esc_html__('Are you sure you want to delete this pdf?', "pdf-for-wpforms"), 'yeepdf_creator_prompt' => esc_html__('Enter a pdf name', "pdf-for-wpforms"), 'yeepdf_creator_ph' => esc_html__('Eg: User pdf', "pdf-for-wpforms"), 'yeepdf_creator_error' => esc_html__('You must provide a pdf name', "pdf-for-wpforms") ); return array_merge($strings, $add); } public function clear_empty_rules($conditionals) { if (empty($conditionals) || !is_array($conditionals)) { return []; } foreach ($conditionals as $group_id => $group) { if (empty($group) || !is_array($group)) { unset($conditionals[$group_id]); continue; } foreach ($group as $rule_id => $rule) { if (!isset($rule['field']) || '' === $rule['field']) { unset($conditionals[$group_id][$rule_id]); } } if (empty($conditionals[$group_id])) { unset($conditionals[$group_id]); } } return $conditionals; } function process_pdf_conditionals($process, $fields, $form_data, $id) { $settings = $form_data['settings']; if ( empty($settings['yeepdf_creator'][$id]['conditional_logic']) || empty($settings['yeepdf_creator'][$id]['conditional_type']) || empty($settings['yeepdf_creator'][$id]['conditionals']) ) { return $process; } $conditionals = $this->clear_empty_rules($settings['yeepdf_creator'][$id]['conditionals']); if (empty($conditionals)) { return $process; } $type = $settings['yeepdf_creator'][$id]['conditional_type']; if (function_exists("wpforms_conditional_logic")) { $process = wpforms_conditional_logic()->process($fields, $form_data, $conditionals); } if ('stop' === $type) { $process = !$process; } if (!$process) { } return $process; } function add_link_download($action_links, $entry, $form_data) { $upload_dir = wp_upload_dir(); $datas = wpforms()->entry_meta->get_meta(array("entry_id" => $entry->entry_id, "type" => "pdf_link")); $url_re = get_admin_url() . "admin.php?page=wpforms-entries&view=details&entry_id=" . $entry->entry_id . "&action=regenerate_pdf"; $url_re = wp_nonce_url($url_re, 'regenerate_pdf'); $action_links["pdf_recreate"] = array( 'url' => $url_re, 'icon' => 'dashicons-media-text', 'label' => esc_html__("Re-generate PDF", "pdf-for-wpforms"), ); if (isset($datas[0]->data)) { $path_main = json_decode($datas[0]->data, true); if (count($path_main) > 0) { $i = 1; foreach ($path_main as $url) { $pdf_name = pathinfo(wp_basename(parse_url($url, PHP_URL_PATH)), PATHINFO_FILENAME); $action_links["pdf" . $i] = array( 'url' => $url, 'target' => 'blank', 'icon' => 'dashicons-media-text', 'label' => !empty($pdf_name) ? esc_html($pdf_name . ".pdf") : esc_html__("Download PDF", "pdf-for-wpforms") . " " . $i, ); $i++; } } } return $action_links; } function wpforms_entry_details_init($wpforms) { if (empty($_GET['action']) || $_GET['action'] !== 'regenerate_pdf') { return; } $this->regenerate_pdf($wpforms); printf( '

%2$s

', // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped esc_attr(implode(' ', array("notice", "notice-success", "wpforms-notice"))), 'Re-generated PDF' // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ); } //click resend pdf function regenerate_pdf($wpforms) { if (empty($_GET['action']) || $_GET['action'] !== 'regenerate_pdf') { return; } // Security check. if (empty($_GET['_wpnonce']) || !wp_verify_nonce(sanitize_key($_GET['_wpnonce']), 'regenerate_pdf')) { return; } if ($this->is_pro()) { $fields = wpforms_decode($wpforms->entry->fields); $entry = (array) wpforms()->entry->get($wpforms->entry->entry_id); $form_data = wpforms_decode($wpforms->form->post_content); $entry_id = $wpforms->entry->entry_id; $entry_fields = json_decode($entry["fields"], true); $entry["fields"] = $entry_fields; $this->save_pdf($fields, $entry, $form_data, $entry_id); } } //click resend notify function resend($emails) { if ($this->is_pro()) { $fields = $emails->fields; $entry = (array) wpforms()->entry->get($emails->entry_id); $form_data = $emails->form_data; $entry_id = $emails->entry_id; $entry_fields = json_decode($entry["fields"], true); $entry["fields"] = $entry_fields; $this->save_pdf($fields, $entry, $form_data, $entry_id); } return $emails; } function save_pdf($fields, $entry, $form_data, $entry_id) { foreach ($form_data["fields"] as $id => $field) { if ($field["type"] == "repeater") { $columns = $field['columns']; $all_base_ids = []; foreach ($columns as $column) { if (!empty($column['fields']) && is_array($column['fields'])) { $all_base_ids = array_merge($all_base_ids, $column['fields']); } } //var_dump($all_base_ids); $rows = []; $i = 1; while (true) { $suffix = ($i === 1) ? '' : '_' . $i; // Kiểm tra field đầu tiên của danh sách có tồn tại ở hàng này không $check_id = $all_base_ids[0] . $suffix; if (!isset($fields[$check_id])) { break; // Hết hàng thì nghỉ } $row_data = []; foreach ($all_base_ids as $id) { $current_key = $id . $suffix; // Lấy value và name để làm bảng cho chuẩn $row_data[$id] = [ 'label' => $fields[$current_key]['name'] ?? "Field $id", 'value' => $fields[$current_key]['value'] ?? '' ]; } $rows[] = $row_data; $i++; } $table_html = ''; if (!empty($rows)) { $table_html .= ''; // Header (Lấy label từ hàng đầu tiên) $table_html .= ''; foreach ($rows[0] as $data) { $table_html .= ''; } $table_html .= ''; // Body (Dữ liệu các hàng) $table_html .= ''; foreach ($rows as $row) { $table_html .= ''; foreach ($row as $data) { $table_html .= ''; } $table_html .= ''; } $table_html .= '
' . esc_html($data['label']) . '
' . esc_html($data['value']) . '
'; } else { $table_html = '

'; } $entry["fields"][$field["id"]] = [ "name" => $field["label"], "value" => $table_html, "id" => $field["id"], "type" => "text" ]; $fields[$field["id"]] = [ "name" => $field["label"], "value" => $table_html, "id" => $field["id"], "type" => "text" ]; $form_data[$field["id"]] = $table_html; } } $this->form_data = $form_data; $this->fields = $fields; $this->entry_id = $entry_id; $this->entry = $entry; if ($this->created) { return; } $this->created = true; $form_id = $form_data["id"]; $form_data["cover_r_to_br"] = true; $attachments_notifications = $this->attachments_notifications; $attachments = array(); $upload_dir = wp_upload_dir(); $form_settings = $form_data["settings"]; //cập nhật settings mới if (!isset($form_settings["yeepdf_creator_enable"])) { if (isset($form_settings["pdf_creator_enable"])) { $form_settings["yeepdf_creator_enable"] = $form_settings["pdf_creator_enable"]; } } if (!isset($form_settings["yeepdf_creator"])) { if (isset($form_settings["pdf_creator"])) { $form_settings["yeepdf_creator"] = $form_settings["pdf_creator"]; } } if (isset($form_settings["yeepdf_creator_enable"]) && $form_settings["yeepdf_creator_enable"] == 1) { $pdfs = $form_settings["yeepdf_creator"]; $data_entry = array(); foreach ($entry as $k => $v) { if ($k == "fields") { foreach ($v as $key => $vl) { if (is_array($vl)) { if (isset($vl["value"])) { if (is_array($vl["value"])) { $vl = implode(", ", $vl["value"]); } else { $vl = $vl["value"]; } } else { $vl = implode(", ", $vl); } } $vl = str_replace("\r", "
", $vl); $data_entry["{field_id='" . $key . "'}"] = $vl; } } else { if (is_array($v)) { $v = array_filter($v, function ($item) { return is_scalar($item); }); $v = implode(", ", $v); } if (is_string($v)) { $vl = str_replace("\r", "
", $v); $data_entry['{' . $k . '}'] = $v; } } } foreach ($pdfs as $id => $pdf) { $list_notifitions = array(); foreach ($pdf as $pdf_key => $pdf_value) { if (preg_match("/pdf_notifications_/", $pdf_key)) { if ($pdf_value == 1) { $keys = explode("_", $pdf_key); $list_notifitions[] = end($keys); } } } $template_id = $pdf["template_id"]; $name = ""; if (isset($pdf["yeepdf_name"])) { $name = $pdf["yeepdf_name"]; } $password = ""; if (isset($pdf["yeepdf_password"])) { $password = $pdf["yeepdf_password"]; } $conditional_logic = ""; if (isset($pdf["conditional_logic"])) { $conditional_logic = $pdf["conditional_logic"]; } $process = $this->process_pdf_conditionals(true, $fields, $form_data, $id); if (!$process) { continue; } if ($name == "") { $name = "contact-form"; } else { $name = wpforms_process_smart_tags($name, $form_data, $fields, $entry_id); } if ($password != "") { $password = wpforms_process_smart_tags($password, $form_data, $fields, $entry_id); } $name = sanitize_file_name($name); $data_send_settings = array( "id_template" => $template_id, "type" => "html", "name" => $name, "datas" => $data_entry, "return_html" => true, ); $message = Yeepdf_Create_PDF::pdf_creator_preview($data_send_settings); $message = $this->add_all_fields($message, $form_data, $fields, $entry_id); if (!empty($form_data['fields'])) { $special_tags = []; foreach ($form_data['fields'] as $f_id => $f_val) { if ($f_val['type'] === 'html' && isset($f_val['code'])) { $special_tags["{field_id='" . $f_id . "'}"] = $f_val['code']; $special_tags['{field_id="' . $f_id . '"}'] = $f_val['code']; $special_tags["{field_html_id='" . $f_id . "'}"] = $f_val['code']; $special_tags['{field_html_id="' . $f_id . '"}'] = $f_val['code']; } elseif ($f_val['type'] === 'content' && isset($f_val['content'])) { $special_tags["{field_id='" . $f_id . "'}"] = $f_val['content']; $special_tags['{field_id="' . $f_id . '"}'] = $f_val['content']; $special_tags["{field_html_id='" . $f_id . "'}"] = $f_val['content']; $special_tags['{field_html_id="' . $f_id . '"}'] = $f_val['content']; } } if (!empty($special_tags)) { $message = str_replace(array_keys($special_tags), array_values($special_tags), $message); } } $message = wpforms_process_smart_tags($message, $form_data, $fields, $entry_id); $pattern = '/]*class="[^"]*wpforms-order-summary-placeholder-hidden[^"]*"[^>]*>.*?<\/tr>/is'; $message = preg_replace($pattern, '', $message); if (isset($pdf["yeepdf_save_dropbox"]) && $pdf["yeepdf_save_dropbox"] == 1) { $save_dropbox = true; } else { $save_dropbox = false; } $data_send_settings_download = array( "id_template" => $template_id, "type" => "upload", "name" => $name, "datas" => $data_entry, "html" => $message, "password" => $password, "save_dropbox" => $save_dropbox, ); $data_send_settings_download = apply_filters("pdf_before_render_datas", $data_send_settings_download); $folder_uploads = Yeepdf_Create_PDF::pdf_creator_preview($data_send_settings_download); $attachments[] = $folder_uploads["url"]; update_option("yeepdf_download_wpforms", $folder_uploads["url"]); foreach ($list_notifitions as $notifi) { $attachments_notifications[$notifi][] = $folder_uploads["path"]; } } if ($this->is_pro()) { wpforms()->entry_meta->add( [ 'entry_id' => absint($entry_id), 'form_id' => absint($form_id), 'user_id' => get_current_user_id(), 'type' => 'pdf_link', 'data' => json_encode($attachments), ], 'entry_meta' ); } $this->attachments_notifications = $attachments_notifications; } } function add_attachments($email, $email_obj) { $attachments = array(); $attachments_notifications = $this->attachments_notifications; if (!isset($email_obj->form_data, $email_obj->notification_id, $email_obj->fields)) { return $email; } $form_data = $email_obj->form_data; $notification_id = $email_obj->notification_id; $entry_fields = $email_obj->fields; if (array_key_exists($notification_id, $attachments_notifications)) { $link_wp = get_option("yeepdf_download_wpforms"); $email['message'] = str_replace("[yeepdf_download_wpforms]", $link_wp, $email["message"]); $email['attachments'] = array_merge((array) $email['attachments'], $attachments_notifications[$notification_id]); } return $email; } function wpforms_emails_mailer_get_message($message, $mailer) { $link_wp = get_option("yeepdf_download_wpforms"); $message = str_replace(array("[yeepdf_download_wpforms]"), $link_wp, $message); return $message; } function add_tab_settings_sections($sections) { $sections["yeepdf_creator"] = esc_html__("PDF", "pdf-for-wpforms"); return $sections; } function add_tab_settings($settings) { ?>
form_settings_pdf_creator($settings) ?>
form->ID; $form_settings = !empty($settings->form_data['settings']) ? $settings->form_data['settings'] : []; $form_data = !empty($settings->form_data) ? $settings->form_data : []; //nếu không tồn tại settings mới thì lấy settings củ if (!isset($form_settings['yeepdf_creator_enable'])) { if (isset($form_settings['pdf_creator_enable'])) { $form_settings["yeepdf_creator_enable"] = $form_settings['pdf_creator_enable']; } } if (!isset($form_settings['yeepdf_creator'])) { if (isset($form_settings['pdf_creator'])) { $form_settings["yeepdf_creator"] = $form_settings['pdf_creator']; } } $form_data["settings"] = $form_settings; $pdfs = is_array($form_settings) && isset($form_settings['yeepdf_creator']) ? $form_settings['yeepdf_creator'] : []; if (empty($pdfs)) { $next_id = 2; $pdfs[1]['template_id'] = !empty($form_settings['yeepdf_creator_template_id']) ? $form_settings['yeepdf_creator_template_id'] : ''; $pdfs[1]['name'] = !empty($form_settings['yeepdf_creator_name']) ? $form_settings['yeepdf_creator_name'] : ''; $pdfs[1]['password'] = !empty($form_settings['yeepdf_creator_password']) ? $form_settings['yeepdf_creator_password'] : ''; } else { $next_id = max(array_keys($pdfs)) + 1; } $default_pdfs_key = min(array_keys($pdfs)); $hidden = empty($form_settings['yeepdf_creator_enable']) ? 'hidden' : ''; ?>
empty($form_settings['yeepdf_creator_enable']) ? 0 : 1, 'class' => 'pdfcreator_datas_enable', 'input_class' => 'pdfcreator_datas_enable', 'data' => array("tab" => ".wpforms-yeepdf_creator") ] ); $yeepdfs = get_posts(array('post_type' => 'yeepdf', 'post_status' => 'publish', 'numberposts' => -1)); $list_templates = array(); if ($yeepdfs) { foreach ($yeepdfs as $post) { $post_id = $post->ID; $list_templates[$post_id] = $post->post_title; } } else { $list_templates[-1] = esc_html__("No template", "pdf-for-wpforms"); } $notifications_datas = is_array($form_settings) && isset($form_settings['notifications']) ? $form_settings['notifications'] : []; if (empty($notifications_datas)) { $notifications_datas[1]['name'] = "Default"; } foreach ($pdfs as $id => $pdf) { $name = !empty($pdf['name']) ? $pdf['name'] : esc_html__('Default PDF', "pdf-for-wpforms"); $closed_state = ''; $toggle_state = ''; $block_classes = 'wpforms-yeepdf_creator wpforms-builder-settings-block ' . $hidden; $from_name_after = apply_filters('wpforms_builder_yeepdf_creator_from_name_after', '', $settings->form_data, $id); if (!empty($settings->form_data['id']) && 'closed' === wpforms_builder_settings_block_get_state($settings->form_data['id'], $id, 'yeepdf_creator')) { $closed_state = 'style="display:none"'; $toggle_state = ''; } if ($default_pdfs_key === $id) { $block_classes .= ' wpforms-builder-settings-block-default'; } do_action('wpforms_form_settings_yeepdf_creator_single_before', $settings, $id); ?>
> $list_templates, 'parent' => 'settings', 'subsection' => $id, 'input_id' => 'wpforms-panel-field-pdf-1-' . $id, 'input_class' => 'wpforms-panel-field-pdf-1', 'class' => 'gform-kitchen-sink-template_id ' . $class_logic_type_id, ] ); ?> $notifications_data) { if (isset($notifications_data["notification_name"])) { $notification_name = $notifications_data["notification_name"]; } else { $notification_name = "Default Notification"; } wpforms_panel_field( 'checkbox', 'yeepdf_creator', 'pdf_notifications_' . $id_n, $form_data, esc_html($notification_name), [ 'tooltip' => esc_html__("Send the PDF as an email attachment for the selected notifications.", "pdf-for-wpforms"), 'parent' => 'settings', 'subsection' => $id, ] ); } wpforms_panel_field( 'text', 'yeepdf_creator', 'yeepdf_name', $form_data, esc_html__('PDF Template Custom Name', "pdf-for-wpforms"), [ 'rows' => 6, 'default' => "", 'smarttags' => [ 'type' => 'all', ], 'parent' => 'settings', 'subsection' => $id, 'class' => 'email-msg', 'after' => '

{name}.pdf

', ] ); do_action('wpforms_form_settings_pdf_single_after', $settings, $id); ?>
'; } } if (count($datas) > 0) { return implode("
", $datas); } return $value; } function add_head_settings($post) { global $wpdb; if (isset($_GET["post"])) { $post_id = sanitize_text_field($_GET["post"]); } else { $post_id = $post->ID; } $data = get_post_meta($post_id, '_pdfcreator_wpforms', true); ?>
"Form Name", "{form_id}" => "Form ID", "{entry_id}" => "Entry ID", "{entry_details_url}" => "Entry Details URL", "{all_fields}" => "{all_fields}", "{all_fields_full}" => "{all_fields_full}", ); $form = wpforms()->form->get(absint($form_id)); // If the form doesn't exists, abort. if (empty($form)) { return $shortcode; } // Pull and format the form data out of the form object. $form_data = !empty($form->post_content) ? wpforms_decode($form->post_content) : ''; // Setup the form fields. $form_fields = !empty($form_data['fields']) && is_array($form_data['fields']) ? $form_data['fields'] : []; if (is_array($form_fields)) { foreach ($form_fields as $id => $datas) { $label = $id; if (!empty($datas["label"])) { $label = $datas["label"]; } elseif (!empty($datas["name"])) { $label = $datas["name"]; } elseif (!empty($datas["type"])) { $label = ucfirst($datas["type"]) . " #" . $id; } $inner_shortcode["{field_id='" . $id . "'}"] = $label; } } $inner_shortcode["{entry_id}"] = 'Entry Id'; $shortcode["WPForms"] = $inner_shortcode; } } return $shortcode; } function add_all_fields($message, $form_data, $fields, $entry_id) { $pattern = '/\{(all_fields(_full)?)([^}]*)\}/i'; if (!preg_match($pattern, $message)) { return $message; } $message = preg_replace_callback($pattern, function ($matches) { $tag = strtolower($matches[1]); $attrs_str = $matches[3] ?? ''; $is_full = ($tag === 'all_fields_full'); $allowed_ids = []; $excluded_ids = []; if (!empty($attrs_str)) { if (preg_match('/(?:fields|include)\s*=\s*["\']([^"\']+)["\']/i', $attrs_str, $m)) { $allowed_ids = array_map('trim', explode(',', $m[1])); } if (preg_match('/exclude\s*=\s*["\']([^"\']+)["\']/i', $attrs_str, $m)) { $excluded_ids = array_map('trim', explode(',', $m[1])); } } return $this->process_field_values($is_full, $allowed_ids, $excluded_ids); }, $message); return $message; } public function process_field_values($is_full = false, $allowed_ids = [], $excluded_ids = []) { // If both fields and form_data fields are empty, return an empty message. if (empty($this->fields) && empty($this->form_data['fields'])) { return ''; } // If no message was generated, create an empty message. $default_message = esc_html__('An empty form was submitted.', 'wpforms-lite'); /** * Filter whether to display empty fields in the email. * * @since 1.8.5 * @deprecated 1.8.5.2 * * @param bool $show_empty_fields Whether to display empty fields in the email. */ $show_empty_fields = apply_filters_deprecated( // phpcs:disable WPForms.Comments.ParamTagHooks.InvalidParamTagsQuantity 'wpforms_emails_notifications_display_empty_fields', [false], '1.8.5.2 of the WPForms plugin', 'wpforms_email_display_empty_fields' ); /** This filter is documented in /includes/emails/class-emails.php */ $show_empty_fields = apply_filters( // phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName 'wpforms_email_display_empty_fields', false ); $message = $this->process_html_message($show_empty_fields, $is_full, $allowed_ids, $excluded_ids); return empty($message) ? $default_message : $message; } public function process_html_message($show_empty_fields = false, $is_full = false, $allowed_ids = [], $excluded_ids = []) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity $message = ''; /** * Filter the list of field types to display in the email. * * @since 1.8.5 * @deprecated 1.8.5.2 * * @param array $other_fields List of field types. * @param array $form_data Form data. */ $default_other_fields = $is_full ? ['html', 'content', 'divider', 'pagebreak'] : []; $other_fields = apply_filters_deprecated( // phpcs:disable WPForms.Comments.ParamTagHooks.InvalidParamTagsQuantity 'wpforms_emails_notifications_display_other_fields', [$default_other_fields, $this->form_data], '1.8.5.2 of the WPForms plugin', 'wpforms_email_display_other_fields' ); /** This filter is documented in /includes/emails/class-emails.php */ $other_fields = apply_filters( // phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName 'wpforms_email_display_other_fields', $default_other_fields, $this ); if (empty($this->form_data['fields']) || !is_array($this->form_data['fields'])) { return ''; } foreach ($this->form_data['fields'] as $field_id => $field) { if (!empty($allowed_ids) && !in_array((string) $field_id, $allowed_ids, true)) { continue; } if (!empty($excluded_ids) && in_array((string) $field_id, $excluded_ids, true)) { continue; } $field_type = !empty($field['type']) ? $field['type'] : ''; $is_special_field = false; // Check if the field is empty in $this->fields. if (empty($this->fields[$field_id])) { // Check if the field type is in $other_fields, otherwise skip. if (empty($other_fields) || !in_array($field_type, $other_fields, true)) { continue; } // Handle specific field types. list($field_name, $field_val) = $this->process_special_field_values($field); $is_special_field = true; } else { // Handle fields that are not empty in $this->fields. if (!$show_empty_fields && (!isset($this->fields[$field_id]['value']) || (string) $this->fields[$field_id]['value'] === '')) { continue; } $field_name = isset($this->fields[$field_id]['name']) ? $this->fields[$field_id]['name'] : ''; $field_val = empty($this->fields[$field_id]['value']) && !is_numeric($this->fields[$field_id]['value']) ? '' . esc_html__('(empty)', 'wpforms-lite') . '' : $this->fields[$field_id]['value']; } // Render special non-input fields if ($is_special_field) { if (in_array($field_type, ['html', 'content'], true)) { $message .= ''; if (!empty($field['name']) && $field['name'] !== esc_html__('HTML / Code Block', 'wpforms-lite')) { $message .= ''; $message .= ''; } else { $message .= ''; } $message .= ''; continue; } if (in_array($field_type, ['divider', 'pagebreak'], true)) { $message .= ''; $message .= ''; $message .= ''; continue; } } // Set a default field name if empty. if (empty($field_name) && $field_name !== null) { $field_name = $this->get_default_field_name($field_id); } /** This filter is documented in src/SmartTags/SmartTag/FieldHtmlId.php.*/ $field_val = apply_filters( // phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName 'wpforms_html_field_value', $field_val, isset($this->fields[$field_id]) ? $this->fields[$field_id] : $field, $this->form_data, 'email-html' ); // Replace new lines with
tags. $field_val = str_replace(["\r\n", "\r", "\n"], '
', $field_val); // Append the field item to the message. $message .= ''; $message .= ''; $message .= ''; $message .= ''; } return $message . '
' . esc_html($field['name']) . ' ' . $field_val . ' ' . $field_val . '
' . $field_name . (!empty($field_val) ? '
' . $field_val . '
' : '') . '
' . $field_name . ' ' . $field_val . '
'; } public function get_default_field_name($field_id) { return sprintf( /* translators: %1$d - field ID. */ esc_html__('Field ID #%1$d', 'wpforms-lite'), absint($field_id) ); } public function process_special_field_values($field) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity $field_name = null; $field_val = null; // Use a switch-case statement to handle specific field types. switch ($field['type']) { case 'divider': $field_name = !empty($field['label']) ? str_repeat('—', 3) . ' ' . $field['label'] . ' ' . str_repeat('—', 3) : null; $field_val = !empty($field['description']) ? $field['description'] : ''; break; case 'pagebreak': // Skip if position is 'bottom'. if (!empty($field['position']) && $field['position'] === 'bottom') { break; } $title = !empty($field['title']) ? $field['title'] : esc_html__('Page Break', 'wpforms-lite'); $field_name = str_repeat('—', 6) . ' ' . $title . ' ' . str_repeat('—', 6); break; case 'html': // Skip if the field is conditionally hidden. if ($this->is_field_conditionally_hidden($field['id'])) { break; } $field_name = !empty($field['name']) ? $field['name'] : esc_html__('HTML / Code Block', 'wpforms-lite'); $field_val = $field['code']; break; case 'content': // Skip if the field is conditionally hidden. if ($this->is_field_conditionally_hidden($field['id'])) { break; } $field_name = esc_html__('Content', 'wpforms-lite'); $field_val = $field['content']; break; default: $field_name = ''; $field_val = ''; break; } return [$field_name, $field_val]; } public function is_field_conditionally_hidden($field_id) { return !empty($this->form_data['fields'][$field_id]['conditionals']) && !wpforms_conditional_logic_fields()->field_is_visible($this->form_data, $field_id); } public function wrap_content_with_table_row($content, $form_data, $fields, $entry_id) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh // If the content is empty, return it as is. if (empty($content)) { return $content; } // Process the smart tags in the content. $processed_content = $this->process_tag($content, $form_data, $fields, $entry_id); // If the content doesn't contain any smart tags, wrap it in a table row, and return early. // Don't go beyond this point if the content doesn't contain any smart tags. if (!preg_match('/{\w+}/', $processed_content)) { //return '' . $processed_content . ''; return $processed_content; } // Split the content into lines and remove empty lines. $lines = array_filter(explode("\n", $content), 'strlen'); // Initialize an empty string to store the modified content. $modified_content = ''; // Iterate through each line. foreach ($lines as $line) { // Trim the line. $trimmed_line = $this->process_tag(trim($line), $form_data, $fields, $entry_id); // Extract tags at the beginning of the line. preg_match('/^(?:\{[^}]+}\s*)+/i', $trimmed_line, $before_line_tags); if (!empty($before_line_tags[0])) { // Include the extracted tags at the beginning to the modified content. $modified_content .= trim($before_line_tags[0]); // Remove the extracted tags from the trimmed line. $trimmed_line = trim(substr($trimmed_line, strlen($before_line_tags[0]))); } // Extract all smart tags from the remaining content. preg_match_all('/\{([^}]+)}/i', $trimmed_line, $after_line_tags); // Remove the smart tags from the content. $content_without_smart_tags = str_replace($after_line_tags[0], '', $trimmed_line); if (!empty($content_without_smart_tags)) { // Wrap the content without the smart tags in a new table row. //$modified_content .= '' . $content_without_smart_tags . ''; $modified_content .= $content_without_smart_tags; } if (!empty($after_line_tags[0])) { // Move all smart tags to the end of the line after the closing tag. $modified_content .= implode(' ', $after_line_tags[0]); } } // Return the modified content. return $modified_content; } public function process_tag($input = '', $form_data = '', $fields = '', $entry_id = '') { return wpforms_process_smart_tags($input, $form_data, $fields, $entry_id); } } $yeepdf_settings_wpforms = new Superaddons_Pdf_Creator_Wpfroms_Backend;