'formidable', 'title' => 'Formidable Forms', ); /** * Get info about extension * @param string $key - Key to get assigned extension info value * @return array|string - Extension Key and Title or Assigned extension info value */ public function info($key = false) { if ($key && isset($this->info[$key])) { return $this->info[$key]; } else { return array( $this->info['key'] => $this->info['title'], ); } } /** * Check if needed plugin active * @return bool - Activated/Not Activated plugin */ public function active() { if (defined('E2PDF_FORMIDABLE_EXTENSION') || $this->helper->load('extension')->is_plugin_active('formidable/formidable.php')) { return true; } return false; } /** * Set option * @param string $key - Key of option * @param string $value - Value of option * @return bool - Status of setting option */ public function set($key, $value) { if (!isset($this->options)) { $this->options = new stdClass(); } $this->options->$key = $value; switch ($key) { case 'item': $this->set('cached_form', false); if ($this->get('item') && $this->get('item') != '-2' && class_exists('FrmForm')) { $form = FrmForm::getOne($this->get('item')); if (isset($form->id)) { $this->set('cached_form', $form); } } break; case 'item1': $this->set('cached_form', false); if ($this->get('item1') && class_exists('FrmForm')) { $form = FrmForm::getOne($this->get('item1')); if (isset($form->id)) { $this->set('cached_form', $form); } } break; case 'item2': $this->set('cached_form2', false); if ($this->get('item2') && class_exists('FrmForm')) { $form = FrmForm::getOne($this->get('item2')); if (isset($form->id)) { $this->set('cached_form2', $form); } } break; case 'dataset': $this->set('cached_entry', false); if ($this->get('cached_form') && $this->get('dataset') && class_exists('FrmEntry')) { if (substr($this->get('dataset'), 0, 4) === 'tmp_') { $this->set('cached_entry', get_transient('e2pdf_' . $this->get('dataset'))); } else { $entry = FrmEntry::getOne($this->get('dataset')); if ($entry && isset($entry->form_id) && $entry->form_id == $this->get('cached_form')->id) { $this->set('cached_entry', $entry); } } } break; case 'dataset2': if ($this->get('cached_form2') && $this->get('dataset2') && class_exists('FrmEntry')) { $entry = FrmEntry::getOne($this->get('dataset2')); if ($entry && isset($entry->form_id) && $entry->form_id == $this->get('cached_form2')->id) { $this->set('cached_entry2', $entry); } } break; default: break; } return true; } /** * Get option by key * @param string $key - Key to get assigned option value * @return mixed */ public function get($key) { if (isset($this->options->$key)) { $value = $this->options->$key; } else { switch ($key) { case 'args': $value = array(); break; default: $value = false; break; } } return $value; } /** * Get items to work with * @return array() - List of available items */ public function items() { $items = array(); if (class_exists('FrmForm')) { $where = array( 'is_template' => 0, 'status' => 'published', ); $forms = FrmForm::getAll($where, 'name'); if ($forms) { foreach ($forms as $key => $form) { $items[] = $this->item($form->id); } } } return $items; } /** * Get entries for export * @param int $item - Form ID * @param string $name - Entries names * @return array() - Entries list */ public function datasets($item_id = false, $name = false) { $item_id = (int) $item_id; $datasets = array(); if (class_exists('FrmEntry') && $item_id) { $where = array( 'it.form_id' => $item_id, ); $entries = FrmEntry::getAll($where, ' ORDER BY id DESC'); if ($entries) { $this->set('item', $item_id); if (class_exists('FrmFieldsHelper') && class_exists('FrmFormsController') && method_exists('FrmFormsController', 'replace_form_name_shortcodes')) { $this->set('cached_shortcodes', FrmFieldsHelper::get_shortcodes($name, $item_id)); } foreach ($entries as $key => $entry) { $this->set('dataset', $entry->id); $entry_title = $this->render($name); if (!$entry_title) { $entry_title = $entry->item_key; } $datasets[] = array( 'key' => $entry->id, 'value' => $entry_title, ); } $this->set('cached_shortcodes', false); } } return $datasets; } /** * Get Dataset Actions * @param int $dataset_id - Dataset ID * @return object */ public function get_dataset_actions($dataset_id = false) { $dataset_id = (int) $dataset_id; if (!$dataset_id) { return false; } $actions = new stdClass(); $actions->view = $this->helper->get_url( array( 'page' => 'formidable-entries', 'frm_action' => 'show', 'id' => $dataset_id, ) ); $actions->delete = false; return $actions; } /** * Get Template Actions * @param int $template - Template ID * @return object */ public function get_template_actions($template = false) { $template = (int) $template; if (!$template) { return; } $actions = new stdClass(); $actions->delete = false; return $actions; } /** * Get item * @param int $item_id - Item ID * @return object - Item */ public function item($item_id = false) { $item_id = (int) $item_id; if (!$item_id && $this->get('item')) { $item_id = $this->get('item'); } $form = false; if (class_exists('FrmForm')) { $form = FrmForm::getOne($item_id); } $item = new stdClass(); if ($form) { $item->id = (string) $item_id; $item->url = $this->helper->get_url( array( 'page' => 'formidable', 'frm_action' => 'edit', 'id' => $item_id, ) ); $item->name = esc_html('' === $form->name ? __('(no title)', 'formidable') : $form->name . ($form->parent_form_id ? __(' (child)', 'formidable') : '')); } else { $item->id = ''; $item->url = ''; $item->name = ''; } return $item; } /** * Render value according to content * @param string $value - Content * @param string $type - Type of rendering value * @param array $field - Field details * @return string - Fully rendered value */ public function render($value, $field = array(), $convert_shortcodes = true, $raw = false) { $value = $this->render_shortcodes($value, $field); if (!$raw) { $value = $this->strip_shortcodes($value); $value = $this->convert_shortcodes($value, $convert_shortcodes, isset($field['type']) && $field['type'] == 'e2pdf-html' ? true : false); $value = $this->helper->load('field')->render_checkbox($value, $this, $field); } return $value; } /** * Load actions for this extension */ public function load_actions() { add_action('frm_notification', array($this, 'action_frm_notification'), 30, 3); add_action('check_ajax_referer', array($this, 'action_check_ajax_referer'), 10, 2); add_action('frm_after_create_entry', array($this, 'action_frm_default_value'), 0, 2); add_action('frm_after_update_entry', array($this, 'action_frm_default_value'), 0, 2); add_action('frm_success_action', array($this, 'action_frm_success_action')); /* Hooks */ add_action('frm_show_entry_sidebar', array($this, 'hook_formidable_entry_view')); add_action('frm_edit_entry_sidebar', array($this, 'hook_formidable_entry_edit')); } /** * Load filters for this extension */ public function load_filters() { if (!get_option('e2pdf_formidable_disable_filter', '0')) { add_filter('frm_display_entry_content', array(new Model_E2pdf_Filter(), 'pre_filter'), 9); add_filter('frm_display_entry_content', array(new Model_E2pdf_Filter(), 'filter'), 25); add_filter('frm_display_entry_content', array($this, 'filter_frm_display_entry_content'), 30); add_filter('frm_content', array(new Model_E2pdf_Filter(), 'pre_filter')); add_filter('frm_content', array(new Model_E2pdf_Filter(), 'filter'), 25); } add_filter('frm_content', array($this, 'filter_frm_content'), 30, 3); add_filter('frm_image_html_array', array($this, 'filter_frm_image_html_array'), 10, 2); add_filter('frm_notification_attachment', array($this, 'filter_frm_notification_attachment'), 30, 3); add_filter('e2pdf_model_options_get_options_options', array($this, 'filter_e2pdf_model_options_get_options_options')); add_filter('frm_main_feedback', array($this, 'filter_frm_main_feedback')); // replace shortcodes on backup add_filter('e2pdf_controller_templates_backup_options', array($this, 'filter_e2pdf_controller_templates_backup_options'), 10, 3); add_filter('e2pdf_controller_templates_backup_pages', array($this, 'filter_e2pdf_controller_templates_backup_pages'), 10, 4); add_filter('e2pdf_controller_templates_backup_actions', array($this, 'filter_e2pdf_controller_templates_backup_actions'), 10, 4); add_filter('e2pdf_controller_templates_backup_replace_shortcodes', array($this, 'filter_e2pdf_controller_templates_backup_replace_shortcodes'), 10, 4); // replace shortcodes on import add_filter('e2pdf_controller_templates_import_options', array($this, 'filter_e2pdf_controller_templates_import_options'), 10, 3); add_filter('e2pdf_controller_templates_import_pages', array($this, 'filter_e2pdf_controller_templates_import_pages'), 10, 5); add_filter('e2pdf_controller_templates_import_actions', array($this, 'filter_e2pdf_controller_templates_import_actions'), 10, 5); add_filter('e2pdf_controller_templates_import_replace_shortcodes', array($this, 'filter_e2pdf_controller_templates_import_replace_shortcodes'), 10, 5); // hooks add_filter('frm_row_actions', array($this, 'hook_formidable_row_actions'), 10, 2); // frm-graph add_filter('frm_graph_shortcode_custom_html', array($this, 'filter_frm_graph_shortcode_custom_html'), 99, 2); } public function action_frm_success_action() { $this->set('iframe_download', true); } public function filter_frm_main_feedback($message) { $this->set('iframe_download', false); return $message; } /** * Render shortcodes which available in this extension * @param string $value - Content * @param string $type - Type of rendering value * @param array $field - Field details * @return string - Value with rendered shortcodes */ public function render_shortcodes($value, $field = array()) { $element_id = isset($field['element_id']) ? $field['element_id'] : false; $checkbox_separated = false; $foreach_wrapper_shortcodes = false; $foreach_inner_shortcodes = false; $signature = false; if ($this->verify()) { if (false !== strpos($value, '[')) { $value = $this->helper->load('field')->pre_shortcodes($value, $this, $field); if (class_exists('FrmProEntry')) { $shortcode_tags = array(); preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $value, $matches); $tagnames = array_intersect($shortcode_tags, $matches[1]); foreach ($matches[1] as $key => $shortcode) { if (false !== strpos($shortcode, ':')) { $shortcode_tags[] = $shortcode; } } $tagnames = array_intersect($shortcode_tags, $matches[1]); if (!empty($tagnames)) { preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $value, $shortcodes); foreach ($shortcodes[0] as $key => $shortcode_value) { $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); $shortcode_details = explode(':', $shortcode[2]); $field_id = $shortcode_details['0']; $child_id = $shortcode_details['1']; $child_entry = 0; $child_field = false; $child_form = false; if (class_exists('FrmField')) { $child_field = FrmField::getOne($field_id); if ($child_field) { $child_form = $child_field->form_id; } } $child_entries = array(); if ($this->get('cached_entry')) { $childs = FrmEntry::getAll(array('parent_item_id' => $this->get('cached_entry')->id), ' ORDER BY it.id ASC', '', true, false); if ($childs && $child_form) { foreach ($childs as $child) { if ($child->form_id == $child_form) { $child_entries[] = $child->id; } } } } if ($this->get('item') == '-2') { if ($this->get('cached_entry2')) { $childs = FrmEntry::getAll(array('parent_item_id' => $this->get('cached_entry2')->id), ' ORDER BY it.id ASC', '', true, false); if ($childs && $child_form) { foreach ($childs as $child) { if ($child->form_id == $child_form) { $child_entries[] = $child->id; } } } } } $new_shortcode = ''; if (!empty($child_entries) && count($child_entries) >= $child_id) { $start = 1; foreach ($child_entries as $key => $sub_entry) { if ($start == $child_id) { $child_entry = $sub_entry; break; } $start++; } $shortcode[2] = 'frm-field-value field_id=' . $field_id . ' entry=' . $child_entry; $new_shortcode = '[' . $shortcode[2] . $shortcode[3] . ']'; } $checkbox_separated = true; $value = str_replace($shortcode_value, $new_shortcode, $value); } } } // Foreach Inner Shortcodes preg_match_all('/\[foreach[^\]]*?\]((?:(?!\[\/foreach).)+)(e2pdf-if|e2pdf-for)((?:(?!\[\/foreach).)+)\[\/foreach[^\]]*?\]/s', $value, $matches); if (!empty($matches[0])) { foreach ($matches[0] as $match) { $new_match = preg_replace('/(\[)(\/?(e2pdf-if|e2pdf-for)[^\]]*?)(\])/', '{{$2}}', $match); $if_shortcodes = $this->helper->load('if')->get_shortcodes(); $if_shortcodes_new = array_map( function ($str) { return str_replace(array('[', ']'), array('{{', '}}'), $str); }, $if_shortcodes ); $value = str_replace($match, str_replace($if_shortcodes, $if_shortcodes_new, $new_match), $value); } $foreach_inner_shortcodes = true; } $value = $this->helper->load('field')->inner_shortcodes($value, $this, $field); /* Default shortcodes support */ $shortcode_tags = array( 'e2pdf-frm-lookup-values', 'e2pdf-frm-data-values', 'default-message', 'default_message', 'default-message2', 'default_message2', ); preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $value, $matches); $tagnames = array_intersect($shortcode_tags, $matches[1]); if (!empty($tagnames)) { preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $value, $shortcodes); foreach ($shortcodes[0] as $key => $shortcode_value) { $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); $atts = shortcode_parse_atts($shortcode[3]); if ($shortcode[2] === 'e2pdf-frm-lookup-values' || $shortcode[2] === 'e2pdf-frm-data-values') { if (!isset($atts['user_id']) && $this->get('user_id')) { $shortcode[3] .= ' user_id="' . $this->get('user_id') . '"'; $value = str_replace($shortcode_value, '[' . $shortcode[2] . $shortcode[3] . ']', $value); } } elseif (($shortcode[2] === 'default-message' || $shortcode[2] === 'default_message') && $this->get('cached_entry') && class_exists('FrmEntriesHelper')) { $default_message = FrmEntriesHelper::replace_default_message( $shortcode_value, array( 'id' => $this->get('cached_entry')->id, 'entry' => clone $this->get('cached_entry'), 'plain_text' => isset($atts['is_plain_text']) && $atts['is_plain_text'] == 'true' ? true : false, 'user_info' => isset($atts['user_info']) && $atts['user_info'] == 'true' ? true : false, ) ); $value = str_replace($shortcode_value, $default_message, $value); } elseif (($shortcode[2] === 'default-message2' || $shortcode[2] == 'default_message2') && $this->get('cached_entry2') && class_exists('FrmEntriesHelper')) { $default_message = FrmEntriesHelper::replace_default_message( str_replace(array('default-message2', 'default_message2'), array('default-message', 'default_message'), $shortcode_value), array( 'id' => $this->get('cached_entry2')->id, 'entry' => clone $this->get('cached_entry2'), 'plain_text' => isset($atts['is_plain_text']) && $atts['is_plain_text'] == 'true' ? true : false, 'user_info' => isset($atts['user_info']) && $atts['user_info'] == 'true' ? true : false, ) ); $value = str_replace($shortcode_value, $default_message, $value); } } } // Foreach Wrapper Shortcodes preg_match_all('/\[foreach[^\]]*?\]((?:(?!\[\/foreach).)+)(e2pdf-format-number|e2pdf-format-date|e2pdf-format-output|e2pdf-math)((?:(?!\[\/foreach).)+)\[\/foreach[^\]]*?\]/s', $value, $matches); if (!empty($matches[0])) { foreach ($matches[0] as $match) { $new_match = preg_replace('/(\[)(\/?(e2pdf-format-number|e2pdf-format-date|e2pdf-format-output|e2pdf-math)[^\]]*?)(\])/', '{{$2}}', $match); $value = str_replace($match, $new_match, $value); $foreach_wrapper_shortcodes = true; } } $value = $this->helper->load('field')->wrapper_shortcodes($value, $this, $field); if (false !== strpos($value, '[')) { if (strpos($value, '[foreach') !== false) { if ($this->get('cached_entry')) { $value = preg_replace('/\[foreach[^\]]*?\](.*?)\[\/foreach(*SKIP)(*FAIL)|\[id\]/is', $this->get('cached_entry')->id, $value); $value = preg_replace('/\[foreach[^\]]*?\](.*?)\[\/foreach(*SKIP)(*FAIL)|\[key\]/is', $this->get('cached_entry')->item_key, $value); } else { $value = preg_replace('/\[foreach[^\]]*?\](.*?)\[\/foreach(*SKIP)(*FAIL)|\[id\]/is', '', $value); $value = preg_replace('/\[foreach[^\]]*?\](.*?)\[\/foreach(*SKIP)(*FAIL)|\[key\]/is', '', $value); } if ($this->get('cached_entry2')) { $value = preg_replace('/\[foreach[^\]]*?\](.*?)\[\/foreach(*SKIP)(*FAIL)|\[id2\]/is', $this->get('cached_entry2')->id, $value); $value = preg_replace('/\[foreach[^\]]*?\](.*?)\[\/foreach(*SKIP)(*FAIL)|\[key2\]/is', $this->get('cached_entry2')->item_key, $value); } else { $value = preg_replace('/\[foreach[^\]]*?\](.*?)\[\/foreach(*SKIP)(*FAIL)|\[id2\]/is', '', $value); $value = preg_replace('/\[foreach[^\]]*?\](.*?)\[\/foreach(*SKIP)(*FAIL)|\[key2\]/is', '', $value); } } else { $replace = array( '[id]' => $this->get('cached_entry') ? $this->get('cached_entry')->id : '', '[key]' => $this->get('cached_entry') ? $this->get('cached_entry')->item_key : '', '[id2]' => $this->get('cached_entry2') ? $this->get('cached_entry2')->id : '', '[key2]' => $this->get('cached_entry2') ? $this->get('cached_entry2')->item_key : '', ); $value = str_replace(array_keys($replace), $replace, $value); } } } /* * Checkboxes separatable fix filter add * @since 0.01.43 */ if ($checkbox_separated) { add_filter('frm_display_value_custom', array($this, 'filter_frm_display_value_custom'), 0, 3); } /* [display-frm-data] shortcode support */ if (false !== strpos($value, '[')) { preg_match_all('/(?=\[display-frm-data\b)(\[(?:[^\[\]]+|(?1))+\])/', $value, $matches); if (!empty($matches[1])) { add_filter('frmpro_fields_replace_shortcodes', array($this, 'filter_frmpro_fields_replace_shortcodes'), 20, 4); foreach ($matches[1] as $match) { if ($this->get('item') == '-2') { if ($this->get('cached_entry') && $this->get('cached_entry2')) { $new_match = apply_filters('frm_content', $match, $this->get('cached_form'), $this->get('cached_entry')); $new_match = apply_filters('frm_content', $new_match, $this->get('cached_form2'), $this->get('cached_entry2')); } elseif ($this->get('cached_entry')) { $new_match = apply_filters('frm_content', $match, $this->get('cached_form'), $this->get('cached_entry')); if ($this->get('cached_form2')) { $new_match = apply_filters('frm_content', $new_match, $this->get('cached_form2'), $this->get('cached_entry')); } } elseif ($this->get('cached_entry2')) { $new_match = apply_filters('frm_content', $match, $this->get('cached_form2'), $this->get('cached_entry2')); if ($this->get('cached_form')) { $new_match = apply_filters('frm_content', $new_match, $this->get('cached_form'), $this->get('cached_entry2')); } } } else { $new_match = apply_filters('frm_content', $match, $this->get('cached_form'), $this->get('cached_entry')); } $value = str_replace($match, $new_match, $value); } remove_filter('frmpro_fields_replace_shortcodes', array($this, 'filter_frmpro_fields_replace_shortcodes'), 20); } } add_filter('frm_filter_view', array($this, 'filter_frm_filter_view')); $value = $this->helper->load('field')->do_shortcodes($value, $this, $field); remove_filter('frm_filter_view', array($this, 'filter_frm_filter_view')); /* * Checkboxes separatable fix filter remove * @since 0.01.43 */ if ($checkbox_separated) { remove_filter('frm_display_value_custom', array($this, 'filter_frm_display_value_custom'), 0); } /* Bug fix for Formidable Forms Signature (2.0.1) */ if (class_exists('FrmFieldFactory')) { $signature_field = FrmFieldFactory::get_field_type('signature'); if ($signature_field->get_display_value('signature') == '') { $signature = true; } } if ($signature) { remove_filter('frm_get_signature_display_value', 'FrmSigAppController::display_signature'); remove_filter('frmpro_fields_replace_shortcodes', 'FrmSigAppController::custom_display_signature'); add_filter('frm_keep_signature_value_array', array($this, 'filter_frm_keep_signature_value_array'), 10, 2); } add_filter('frmpro_fields_replace_shortcodes', array($this, 'filter_frmpro_fields_replace_shortcodes'), 20, 4); $text_signature = !empty($field['type']) && ($field['type'] == 'e2pdf-image' || $field['type'] == 'e2pdf-signature') ? true : false; if ($text_signature) { add_filter('frm_get_signature_display_value', array($this, 'filter_frm_get_signature_display_value'), 20, 3); } if ($this->get('item') == '-2') { if ($this->get('cached_entry') && $this->get('cached_entry2')) { $value = apply_filters('frm_content', $value, $this->get('cached_form'), $this->get('cached_entry')); $value = apply_filters('frm_content', $value, $this->get('cached_form2'), $this->get('cached_entry2')); } elseif ($this->get('cached_entry')) { $value = apply_filters('frm_content', $value, $this->get('cached_form'), $this->get('cached_entry')); if ($this->get('cached_form2')) { $value = apply_filters('frm_content', $value, $this->get('cached_form2'), $this->get('cached_entry')); } } elseif ($this->get('cached_entry2')) { $value = apply_filters('frm_content', $value, $this->get('cached_form2'), $this->get('cached_entry2')); if ($this->get('cached_form')) { $value = apply_filters('frm_content', $value, $this->get('cached_form'), $this->get('cached_entry2')); } } } else { if ($this->get('cached_shortcodes')) { remove_filter('frm_content', 'FrmFormsController::filter_content', 10, 3); add_filter('frm_content', array($this, 'filter_filter_content'), 10, 3); } $value = apply_filters('frm_content', $value, $this->get('cached_form'), $this->get('cached_entry')); if ($this->get('cached_shortcodes')) { remove_filter('frm_content', array($this, 'filter_filter_content'), 10, 3); add_filter('frm_content', 'FrmFormsController::filter_content', 10, 3); } } // Foreach Wrapper Shortcodes Reverse if ($foreach_wrapper_shortcodes) { $value = preg_replace('/(\{\{)(\/?(e2pdf-format-number|e2pdf-format-date|e2pdf-format-output|e2pdf-math)[^\}]*?)(\}\})/', '[$2]', $value); $value = $this->helper->load('field')->wrapper_shortcodes($value, $this, $field, true); } // Foreach Inner Shortcodes Reverse if ($foreach_inner_shortcodes) { preg_match_all('/\{\{(e2pdf-if|e2pdf-for)\}\}(.*?)+\{\{\/(e2pdf-if|e2pdf-for)\}\}/s', $value, $matches); if (!empty($matches[0])) { foreach ($matches[0] as $match) { $new_match = preg_replace('/(\{\{)(\/?(e2pdf-if|e2pdf-for)[^\}]*?)(\}\})/', '[$2]', $match); $value = str_replace($match, str_replace($if_shortcodes_new, $if_shortcodes, $new_match), $value); } } $value = $this->helper->load('field')->inner_shortcodes($value, $this, $field); } // Text Signature if ($text_signature) { remove_filter('frm_get_signature_display_value', array($this, 'filter_frm_get_signature_display_value'), 20); if ($value && false !== strpos($value, ':e2pdf-text-filter:')) { $value = str_replace(':e2pdf-text-filter:', '', $value); $field['properties']['text'] = '1'; } } remove_filter('frmpro_fields_replace_shortcodes', array($this, 'filter_frmpro_fields_replace_shortcodes'), 20); if ($signature) { remove_filter('frm_keep_signature_value_array', array($this, 'filter_frm_keep_signature_value_array')); add_filter('frm_get_signature_display_value', 'FrmSigAppController::display_signature', 10, 3); add_filter('frmpro_fields_replace_shortcodes', 'FrmSigAppController::custom_display_signature', 10, 4); } $value = $this->replace_meta_shortcodes($value); $value = $this->helper->load('field')->render( apply_filters('e2pdf_extension_render_shortcodes_pre_value', $value, $element_id, $this->get('template_id'), $this->get('item'), $this->get('dataset'), $this->get('item2'), $this->get('dataset2')), $this, $field ); } return apply_filters( 'e2pdf_extension_render_shortcodes_value', $value, $element_id, $this->get('template_id'), $this->get('item'), $this->get('dataset'), $this->get('item2'), $this->get('dataset2') ); } /** * Strip unused shortcodes * @param string $value - Content * @return string - Value with removed unused shortcodes */ public function strip_shortcodes($value) { $value = preg_replace('~(?:\[/?)[^/\]]+/?\]~s', '', $value); return $value; } /** * Convert "shortcodes" inside value string * @param string $value - Value string * @param bool $to - Convert From/To * @return string - Converted value */ public function convert_shortcodes($value, $to = false, $html = false) { if ($value) { if ($to) { $search = array('[', ']', '[', ']'); $replace = array('[', ']', '[', ']'); $value = str_replace($search, $replace, $value); if (!$html) { $value = wp_specialchars_decode($value, ENT_QUOTES); } } else { $search = array('[', ']', '[', ']'); $replace = array('[', ']', '[', ']'); $value = str_replace($search, $replace, $value); } } return $value; } public function filter_frm_filter_view($view) { if (isset($view->frm_before_content) && $view->frm_before_content) { $view->frm_before_content = str_replace('[e2pdf-exclude]', '[e2pdf-exclude apply="true"]', $view->frm_before_content); } if (isset($view->post_content) && $view->post_content) { $view->post_content = str_replace('[e2pdf-exclude]', '[e2pdf-exclude apply="true"]', $view->post_content); } if (isset($view->frm_after_content) && $view->frm_after_content) { $view->frm_after_content = str_replace('[e2pdf-exclude]', '[e2pdf-exclude apply="true"]', $view->frm_after_content); } return $view; } public function filter_frm_lookup_is_current_user_filter_needed($is_filter_needed, $field_id, $field_options) { if (FrmField::is_option_true_in_array($field_options, 'lookup_filter_current_user')) { return true; } return $is_filter_needed; } public function filter_frm_keep_signature_value_array($keep_array, $atts) { return true; } /** * Search and update shortcodes for this extension inside content * Auto set of dataset id * @param string $content - Content * @param int $form - ID of form * @param int $dataset_id - ID of dataset * @return string - Content with updates shortcodes */ public function filter_frm_content($content, $form, $dataset_id) { if (false === strpos($content, '[')) { return $content; } $shortcode_tags = array( 'e2pdf-download', 'e2pdf-save', 'e2pdf-view', 'e2pdf-adobesign', 'e2pdf-zapier', ); preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches); $tagnames = array_intersect($shortcode_tags, $matches[1]); if (!empty($tagnames)) { preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes); foreach ($shortcodes[0] as $key => $shortcode_value) { $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); $atts = shortcode_parse_atts($shortcode[3]); if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf } else { if (!isset($atts['dataset']) && isset($atts['id'])) { $template = new Model_E2pdf_Template(); $template->load($atts['id']); if ($template->get('extension') === 'formidable') { $entry_id = is_object($dataset_id) ? $dataset_id->id : $dataset_id; if ($entry_id) { if ($template->get('item') == '-2') { if ($template->get('item1') == $form->id) { $atts['dataset'] = $entry_id; $shortcode[3] .= ' dataset="' . $entry_id . '"'; } elseif (!isset($atts['dataset2']) && $template->get('item2') == $form->id) { $atts['dataset2'] = $entry_id; $shortcode[3] .= ' dataset2="' . $entry_id . '"'; } } else { $atts['dataset'] = $entry_id; $shortcode[3] .= ' dataset="' . $entry_id . '"'; } } } } if (!isset($atts['apply'])) { $shortcode[3] .= ' apply="true"'; } if (!isset($atts['filter'])) { $shortcode[3] .= ' filter="true"'; } if (!isset($atts['iframe_download']) && $this->get('iframe_download')) { $shortcode[3] .= ' iframe_download="true"'; } $content = str_replace($shortcode_value, do_shortcode_tag($shortcode), $content); } } } return $content; } public function filter_frm_display_entry_content($content) { if (false === strpos($content, '[')) { return $content; } $shortcode_tags = array( 'e2pdf-download', 'e2pdf-save', 'e2pdf-view', 'e2pdf-adobesign', 'e2pdf-zapier', ); preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches); $tagnames = array_intersect($shortcode_tags, $matches[1]); if (!empty($tagnames)) { preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes); foreach ($shortcodes[0] as $key => $shortcode_value) { $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); $atts = shortcode_parse_atts($shortcode[3]); if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf } else { if (!isset($atts['apply'])) { $shortcode[3] .= ' apply="true"'; } if (!isset($atts['filter'])) { $shortcode[3] .= ' filter="true"'; } if (!isset($atts['iframe_download'])) { $shortcode[3] .= ' iframe_download="true"'; } $content = str_replace($shortcode_value, do_shortcode_tag($shortcode), $content); } } } return $content; } /** * Filter for checkbox repeatable Label/Value fix * @param array $value - Value * @param obj $field - Field * @param array $atts - Shortcode Attributes * @return mixed - Updated value */ public function filter_frm_display_value_custom($value, $field, $atts = array()) { if (class_exists('FrmProEntriesController')) { $defaults = array( 'html' => 0, 'type' => $field->type, 'keepjs' => 0, ); $atts = array_merge($defaults, $atts); if ($atts['type'] === 'checkbox') { $value = FrmProEntriesController::get_option_label_for_saved_value($value, $field, $atts); } } return $value; } /** * Filter for Signature * @param array $value - Value * @param obj $field - Field * @param array $atts - Shortcode Attributes * @return mixed - Updated value */ public function filter_frm_get_signature_display_value($value, $field, $atts = array()) { if ($value && !empty($value['format']) && $value['format'] == 'typed' && !empty($value['content'])) { $value['content'] = ':e2pdf-text-filter:' . $value['content']; } return $value; } public function filter_frmpro_fields_replace_shortcodes($replace_with, $tag, $atts, $field) { /* Backward compatibility with Formidable Forms PRO < 5.0 */ if (class_exists('FrmProDb') && property_exists('FrmProDb', 'plug_version') && version_compare(FrmProDb::$plug_version, '5.0', '<')) { if ($this->get('item') == '-2' && $this->get('cached_entry2') && $field->form_id == $this->get('cached_entry2')->form_id) { $atts['entry_id'] = $this->get('cached_entry2')->id; $replace_with = FrmProEntryMetaHelper::get_post_or_meta_value($this->get('cached_entry2'), $field, $atts); } } if ($field->type === 'checkbox' && is_array($replace_with)) { if (isset($atts['key']) && $atts['key']) { if (isset($replace_with[$atts['key']])) { $replace_with = $replace_with[$atts['key']]; } else { $replace_with = ''; } } } if ($field->type === 'radio') { if (isset($atts['key']) && $atts['key'] === 'other') { if (isset($field->options) && is_array($field->options)) { $field_key = array_search($replace_with, array_column($field->options, 'value')); if ($field_key !== false) { $replace_with = ''; } } } } return $replace_with; } /** * Generate attachments according shortcodes in Email template * @param array $attachments - List of attachments * @param int $form - ID of form * @param array $args - Arguments * @return array - Updated list of attachments */ public function filter_frm_notification_attachment($attachments, $form, $args) { if (!isset($args['email_key'])) { return $attachments; } $form_actions = FrmFormAction::get_action_for_form($form->id); $dataset_id = $args['entry']->id; $email_key = $args['email_key']; $shortcode_tags = array( 'e2pdf-attachment', 'e2pdf-save', ); foreach ($form_actions as $key => $action) { if ($action->ID === $email_key) { $content = $action->post_content['email_message']; if (false === strpos($content, '[')) { return $attachments; } remove_filter('frm_content', array($this, 'filter_frm_content'), 30); $content = apply_filters('frm_content', $content, $form, $args['entry']); add_filter('frm_content', array($this, 'filter_frm_content'), 30, 3); preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches); $tagnames = array_intersect($shortcode_tags, $matches[1]); if (!empty($tagnames)) { preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes); foreach ($shortcodes[0] as $key => $shortcode_value) { $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); $atts = shortcode_parse_atts($shortcode[3]); $file = false; if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) { if (!isset($atts['dataset']) && isset($atts['id'])) { $template = new Model_E2pdf_Template(); $template->load($atts['id']); if ($template->get('extension') === 'formidable') { $entry_id = is_object($dataset_id) ? $dataset_id->id : $dataset_id; if ($entry_id) { if ($template->get('item') == '-2') { if ($template->get('item1') == $form->id) { $atts['dataset'] = $entry_id; $shortcode[3] .= ' dataset="' . $entry_id . '"'; } elseif (!isset($atts['dataset2']) && $template->get('item2') == $form->id) { $atts['dataset2'] = $entry_id; $shortcode[3] .= ' dataset2="' . $entry_id . '"'; } } else { $atts['dataset'] = $entry_id; $shortcode[3] .= ' dataset="' . $entry_id . '"'; } } } } if (!isset($atts['apply'])) { $shortcode[3] .= ' apply="true"'; } if (!isset($atts['filter'])) { $shortcode[3] .= ' filter="true"'; } $transient = false; if (isset($atts['use_args_entry']) && $atts['use_args_entry'] == 'true' && $atts['dataset'] == $dataset_id) { $dataset = 'tmp_' . $this->helper->load('encryption')->random_md5(); $transient = 'e2pdf_' . $dataset; set_transient($transient, $args['entry'], 1800); $atts['dataset'] = $dataset; $shortcode[3] .= ' dataset="' . $dataset . '"'; } $file = do_shortcode_tag($shortcode); if ($file) { $tmp = false; if (substr($file, 0, 4) === 'tmp:') { $file = substr($file, 4); $tmp = true; } if ($shortcode[2] === 'e2pdf-save' || isset($atts['pdf'])) { if ($tmp) { $this->helper->add('formidable_attachments', $file); } } else { $this->helper->add('formidable_attachments', $file); } $attachments[] = $file; } if ($transient) { delete_transient($transient); } } } } } } return $attachments; } /** * Decrypt protected uploaded file in a File Upload field * @param string $html * @param array $atts * @return string $html */ public function filter_frm_image_html_array($html, $atts) { if (isset($atts['decrypt']) && $atts['decrypt'] && class_exists('FrmProFileField') && class_exists('FrmProFilePayloadBuilder') && class_exists('FrmAppHelper') ) { $id = $atts['media_id']; $permission = isset($atts['permission']) && $atts['permission'] ? true : false; remove_filter('wp_get_attachment_url', 'FrmProFileField::filter_attachment_url'); remove_filter('wp_get_attachment_image_src', 'FrmProFileField::filter_attachment_image_src'); $is_image = wp_attachment_is_image($id); $url = $this->get_file_url($id, $is_image ? $atts['size'] : false); if (!FrmProFileField::user_has_permission($id) && !$permission) { $frm_settings = FrmAppHelper::get_settings(); $html = $frm_settings->admin_permission; } else { $html = $atts['show_image'] ? wp_get_attachment_image($id, $atts['size'], !$is_image) : ''; /* If show_filename=1 is included */ if ($atts['show_filename']) { $label = $this->get_single_file_name($id); if ($atts['show_image']) { $html .= ' ' . $label . ''; } else { $html .= $label; } } /* If neither show_image or show_filename are included, get file URL */ if (!$html) { $html = $url; } /* If add_link=1 is included */ if ($atts['add_link'] || (!$is_image && $atts['add_link_for_non_image'])) { $href = $is_image ? $this->get_file_url($id) : $url; $target = !empty($atts['new_tab']) ? ' target="_blank"' : ''; $html = '' . $html . ''; } if (!empty($atts['class'])) { $html = str_replace(' class="', ' class="' . esc_attr($atts['class'] . ' '), $html); } add_filter('wp_get_attachment_url', 'FrmProFileField::filter_attachment_url', 10, 2); add_filter('wp_get_attachment_image_src', 'FrmProFileField::filter_attachment_image_src', 10, 4); } } return $html; } /** * @param int $id * @param string|int[]|bool $size * @param array $args supported keys include "url" and "leave_size_out_of_payload" * @return string unprotected url to use for our specified file id and size. */ public function get_file_url($id, $size = false, $args = array()) { $url = isset($args['url']) ? $args['url'] : false; $builder = new FrmProFilePayloadBuilder($id, $size, $url); return $builder->get_url(); } /** * Remove Page Breaks for Visual Mapper * @param array $fields - List of fields * @return array - Updated fields */ public function filter_remove_pagebreaks($fields) { foreach ((array) $fields as $field_key => $field) { if ($field->type == 'break') { unset($fields[$field_key]); } } return $fields; } public function filter_frm_match_xml_form($edit_query, $form) { if (isset($edit_query['created_at'])) { $edit_query['created_at'] = date('Y-m-d H:i:s', strtotime('now')); } return $edit_query; } public function filter_frm_show_new_entry_page() { return 'new'; } public function filter_frm_pre_display_form($form) { if (!empty($form->options['single_entry'])) { $form->options['single_entry'] = 0; } return $form; } /** * Add options for Formidable extension * @param array $options - List of options * @return array - Updated options list */ public function filter_e2pdf_model_options_get_options_options($options = array()) { $options['formidable_group'] = array( 'name' => 'Formidable Forms', 'action' => 'extension', 'group' => 'formidable_group', 'options' => array( array( 'name' => __('Auto PDF and Visual Mapper', 'e2pdf'), 'key' => 'e2pdf_formidable_use_keys', 'value' => get_option('e2pdf_formidable_use_keys', '0'), 'default_value' => '0', 'type' => 'checkbox', 'checkbox_value' => '1', 'placeholder' => __('Use Field Keys instead Field IDs', 'e2pdf'), ), array( 'name' => __('Filter', 'e2pdf'), 'key' => 'e2pdf_formidable_disable_filter', 'value' => get_option('e2pdf_formidable_disable_filter', '0'), 'default_value' => '0', 'type' => 'checkbox', 'checkbox_value' => '1', 'placeholder' => __('Disable Filter', 'e2pdf'), ), ), ); return $options; } public function filter_e2pdf_controller_templates_import_options($options) { if (isset($options['item'])) { $options['item']['options'][] = array( 'name' => 'Formidable Forms', 'key' => 'options[formidable_item_new_form]', 'value' => 1, 'default_value' => 0, 'type' => 'radio', 'li' => array( 'class' => 'e2pdf-import-extension-option e2pdf-hide', ), 'options' => array( '1' => 'Recreate Web Form', '0' => 'Overwrite Web Form', ), ); } return $options; } public function filter_e2pdf_controller_templates_backup_options($options, $template, $extension) { if ($extension->loaded('formidable')) { $options['formidable'] = array( 'name' => 'Formidable Forms', 'options' => array( array( 'name' => __('Force shortcodes to use', 'e2pdf'), 'key' => 'options[formidable_force_shortcodes]', 'value' => 0, 'default_value' => 0, 'type' => 'select', 'options' => array( '0' => __('None', 'e2pdf'), '1' => __('Fields IDs', 'e2pdf'), '2' => __('Field Keys', 'e2pdf'), ), ), ), ); } return $options; } public function filter_e2pdf_controller_templates_backup_pages($pages, $options, $template, $extension) { if ($extension->loaded('formidable') && (isset($options['formidable_force_shortcodes']) && $options['formidable_force_shortcodes'])) { $fields = array(); if ($template->get('item') == '-2') { if ($template->get('item1')) { $where = array('fi.form_id' => (int) $template->get('item1')); $item_fields = FrmField::getAll($where, 'id ASC'); if ($item_fields) { $fields = array_merge($fields, $item_fields); } } if ($template->get('item2')) { $where = array('fi.form_id' => (int) $template->get('item2')); $item_fields = FrmField::getAll($where, 'id ASC'); if ($item_fields) { $fields = array_merge($fields, $item_fields); } } } else { $where = array('fi.form_id' => (int) $template->get('item')); $fields = FrmField::getAll($where, 'id ASC'); } $search = array(); $replace = array(); if ($options['formidable_force_shortcodes'] == '1') { foreach ($fields as $field_key => $field) { if (isset($field->field_options['form_select']) && $field->field_options['form_select']) { $sub_where = array('fi.form_id' => $field->field_options['form_select']); $sub_fields = FrmField::getAll($sub_where, 'id ASC'); foreach ($sub_fields as $sub_field_key => $sub_field) { $search[] = $sub_field->field_key; $replace[] = $sub_field->id; } $search[] = $field->field_key; $replace[] = $field->id; } else { $search[] = $field->field_key; $replace[] = $field->id; } } } elseif ($options['formidable_force_shortcodes'] == '2') { foreach ($fields as $field_key => $field) { if (isset($field->field_options['form_select']) && $field->field_options['form_select']) { $sub_where = array('fi.form_id' => $field->field_options['form_select']); $sub_fields = FrmField::getAll($sub_where, 'id ASC'); foreach ($sub_fields as $sub_field_key => $sub_field) { $search[] = $sub_field->id; $replace[] = $sub_field->field_key; } $search[] = $field->id; $replace[] = $field->field_key; } else { $search[] = $field->id; $replace[] = $field->field_key; } } } $search = array_reverse($search); $replace = array_reverse($replace); $list = array_combine($search, $replace); $pages = $this->pages_replace_shortcodes($pages, $list); } return $pages; } public function filter_e2pdf_controller_templates_backup_actions($actions, $options, $template, $extension) { if ($extension->loaded('formidable') && (isset($options['formidable_force_shortcodes']) && $options['formidable_force_shortcodes'])) { $fields = array(); if ($template->get('item') == '-2') { if ($template->get('item1')) { $where = array('fi.form_id' => (int) $template->get('item1')); $item_fields = FrmField::getAll($where, 'id ASC'); if ($item_fields) { $fields = array_merge($fields, $item_fields); } } if ($template->get('item2')) { $where = array('fi.form_id' => (int) $template->get('item2')); $item_fields = FrmField::getAll($where, 'id ASC'); if ($item_fields) { $fields = array_merge($fields, $item_fields); } } } else { $where = array('fi.form_id' => (int) $template->get('item')); $fields = FrmField::getAll($where, 'id ASC'); } $search = array(); $replace = array(); if ($options['formidable_force_shortcodes'] == '1') { foreach ($fields as $field_key => $field) { if (isset($field->field_options['form_select']) && $field->field_options['form_select']) { $sub_where = array('fi.form_id' => $field->field_options['form_select']); $sub_fields = FrmField::getAll($sub_where, 'id ASC'); foreach ($sub_fields as $sub_field_key => $sub_field) { $search[] = $sub_field->field_key; $replace[] = $sub_field->id; } $search[] = $field->field_key; $replace[] = $field->id; } else { $search[] = $field->field_key; $replace[] = $field->id; } } } elseif ($options['formidable_force_shortcodes'] == '2') { foreach ($fields as $field_key => $field) { if (isset($field->field_options['form_select']) && $field->field_options['form_select']) { $sub_where = array('fi.form_id' => $field->field_options['form_select']); $sub_fields = FrmField::getAll($sub_where, 'id ASC'); foreach ($sub_fields as $sub_field_key => $sub_field) { $search[] = $sub_field->id; $replace[] = $sub_field->field_key; } $search[] = $field->id; $replace[] = $field->field_key; } else { $search[] = $field->id; $replace[] = $field->field_key; } } } $search = array_reverse($search); $replace = array_reverse($replace); $list = array_combine($search, $replace); $actions = $this->actions_replace_shortcodes($actions, $list); } return $actions; } public function filter_e2pdf_controller_templates_backup_replace_shortcodes($value, $options, $template, $extension) { if ($extension->loaded('formidable') && (isset($options['formidable_force_shortcodes']) && $options['formidable_force_shortcodes'])) { $fields = array(); if ($template->get('item') == '-2') { if ($template->get('item1')) { $where = array('fi.form_id' => (int) $template->get('item1')); $item_fields = FrmField::getAll($where, 'id ASC'); if ($item_fields) { $fields = array_merge($fields, $item_fields); } } if ($template->get('item2')) { $where = array('fi.form_id' => (int) $template->get('item2')); $item_fields = FrmField::getAll($where, 'id ASC'); if ($item_fields) { $fields = array_merge($fields, $item_fields); } } } else { $where = array('fi.form_id' => (int) $template->get('item')); $fields = FrmField::getAll($where, 'id ASC'); } $search = array(); $replace = array(); if ($options['formidable_force_shortcodes'] == '1') { foreach ($fields as $field_key => $field) { if (isset($field->field_options['form_select']) && $field->field_options['form_select']) { $sub_where = array('fi.form_id' => $field->field_options['form_select']); $sub_fields = FrmField::getAll($sub_where, 'id ASC'); foreach ($sub_fields as $sub_field_key => $sub_field) { $search[] = $sub_field->field_key; $replace[] = $sub_field->id; } $search[] = $field->field_key; $replace[] = $field->id; } else { $search[] = $field->field_key; $replace[] = $field->id; } } } elseif ($options['formidable_force_shortcodes'] == '2') { foreach ($fields as $field_key => $field) { if (isset($field->field_options['form_select']) && $field->field_options['form_select']) { $sub_where = array('fi.form_id' => $field->field_options['form_select']); $sub_fields = FrmField::getAll($sub_where, 'id ASC'); foreach ($sub_fields as $sub_field_key => $sub_field) { $search[] = $sub_field->id; $replace[] = $sub_field->field_key; } $search[] = $field->id; $replace[] = $field->field_key; } else { $search[] = $field->id; $replace[] = $field->field_key; } } } $search = array_reverse($search); $replace = array_reverse($replace); $list = array_combine($search, $replace); $value = $this->replace_shortcodes($value, $list); } return $value; } public function filter_e2pdf_controller_templates_import_pages($pages, $options, $xml, $template, $extension) { if ($extension->loaded('formidable') && $template->get('item') && (($template->get('item') != '-2' && $template->get('item') != (string) $xml->template->item) || ($template->get('item') == '-2' && ($template->get('item1') != (string) $xml->template->item1 || $template->get('item2') != (string) $xml->template->item2))) && $xml->item->formidable && $options['item'] && class_exists('FrmXMLHelper') && class_exists('FrmField') ) { $tmp = tempnam($this->helper->get('tmp_dir'), 'e2pdf'); file_put_contents($tmp, base64_decode((string) $xml->item->formidable), LOCK_EX); $dom = new DOMDocument(); $success = $dom->loadXML(file_get_contents($tmp)); $old_ids = array(); $old_keys = array(); if ($success && function_exists('simplexml_import_dom')) { $item_xml = simplexml_import_dom($dom); foreach ($item_xml->form as $form_key => $form) { if (($template->get('item') != '-2' && (string) $form->id == (string) $xml->template->item) || ($template->get('item') == '-2' && ((string) $form->id == (string) $xml->template->item1 || (string) $form->id == (string) $xml->template->item2))) { foreach ($form->field as $field_key => $field) { $field_options = @json_decode((string) $field->field_options, true); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged if (isset($field_options['form_select']) && $field_options['form_select']) { foreach ($item_xml->form as $sub_form_key => $sub_form) { if ((string) $sub_form->id == $field_options['form_select']) { foreach ($sub_form->field as $sub_field_key => $sub_field) { $old_ids[] = (string) $sub_field->id; $old_keys[] = (string) $sub_field->field_key; } } } $old_ids[] = (string) $field->id; $old_keys[] = (string) $field->field_key; } else { $old_ids[] = (string) $field->id; $old_keys[] = (string) $field->field_key; } } } } } $fields = array(); if ($template->get('item') == '-2') { if ($template->get('item1')) { $where = array('fi.form_id' => (int) $template->get('item1')); $item_fields = FrmField::getAll($where, 'id ASC'); if ($item_fields) { $fields = array_merge($fields, $item_fields); } } if ($template->get('item2')) { $where = array('fi.form_id' => (int) $template->get('item2')); $item_fields = FrmField::getAll($where, 'id ASC'); if ($item_fields) { $fields = array_merge($fields, $item_fields); } } } else { $where = array('fi.form_id' => (int) $template->get('item')); $fields = FrmField::getAll($where, 'id ASC'); } $new_ids = array(); $new_keys = array(); foreach ($fields as $field_key => $field) { if (isset($field->field_options['form_select']) && $field->field_options['form_select']) { $sub_where = array('fi.form_id' => (int) $field->field_options['form_select']); $sub_fields = FrmField::getAll($sub_where, 'id ASC'); foreach ($sub_fields as $sub_field_key => $sub_field) { $new_ids[] = $sub_field->id; $new_keys[] = $sub_field->field_key; } $new_ids[] = $field->id; $new_keys[] = $field->field_key; } else { $new_ids[] = $field->id; $new_keys[] = $field->field_key; } } if (count($old_ids) === count($new_ids)) { $old_ids = array_reverse($old_ids); $new_ids = array_reverse($new_ids); $old_keys = array_reverse($old_keys); $new_keys = array_reverse($new_keys); $list_ids = array_combine($old_ids, $new_ids); $pages = $this->pages_replace_shortcodes($pages, $list_ids); $list_keys = array_combine($old_keys, $new_keys); $pages = $this->pages_replace_shortcodes($pages, $list_keys); } unset($dom); unlink($tmp); } return $pages; } public function filter_e2pdf_controller_templates_import_actions($actions, $options, $xml, $template, $extension) { if ($extension->loaded('formidable') && $template->get('item') && (($template->get('item') != '-2' && $template->get('item') != (string) $xml->template->item) || ($template->get('item') == '-2' && ($template->get('item1') != (string) $xml->template->item1 || $template->get('item2') != (string) $xml->template->item2))) && $xml->item->formidable && $options['item'] && class_exists('FrmXMLHelper') && class_exists('FrmField') ) { $tmp = tempnam($this->helper->get('tmp_dir'), 'e2pdf'); file_put_contents($tmp, base64_decode((string) $xml->item->formidable), LOCK_EX); $dom = new DOMDocument(); $success = $dom->loadXML(file_get_contents($tmp)); $old_ids = array(); $old_keys = array(); if ($success && function_exists('simplexml_import_dom')) { $item_xml = simplexml_import_dom($dom); foreach ($item_xml->form as $form_key => $form) { if (($template->get('item') != '-2' && (string) $form->id == (string) $xml->template->item) || ($template->get('item') == '-2' && ((string) $form->id == (string) $xml->template->item1 || (string) $form->id == (string) $xml->template->item2))) { foreach ($form->field as $field_key => $field) { $field_options = @json_decode((string) $field->field_options, true); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged if (isset($field_options['form_select']) && $field_options['form_select']) { foreach ($item_xml->form as $sub_form_key => $sub_form) { if ((string) $sub_form->id == $field_options['form_select']) { foreach ($sub_form->field as $sub_field_key => $sub_field) { $old_ids[] = (string) $sub_field->id; $old_keys[] = (string) $sub_field->field_key; } } } $old_ids[] = (string) $field->id; $old_keys[] = (string) $field->field_key; } else { $old_ids[] = (string) $field->id; $old_keys[] = (string) $field->field_key; } } } } } $fields = array(); if ($template->get('item') == '-2') { if ($template->get('item1')) { $where = array('fi.form_id' => (int) $template->get('item1')); $item_fields = FrmField::getAll($where, 'id ASC'); if ($item_fields) { $fields = array_merge($fields, $item_fields); } } if ($template->get('item2')) { $where = array('fi.form_id' => (int) $template->get('item2')); $item_fields = FrmField::getAll($where, 'id ASC'); if ($item_fields) { $fields = array_merge($fields, $item_fields); } } } else { $where = array('fi.form_id' => (int) $template->get('item')); $fields = FrmField::getAll($where, 'id ASC'); } $new_ids = array(); $new_keys = array(); foreach ($fields as $field_key => $field) { if (isset($field->field_options['form_select']) && $field->field_options['form_select']) { $sub_where = array('fi.form_id' => (int) $field->field_options['form_select']); $sub_fields = FrmField::getAll($sub_where, 'id ASC'); foreach ($sub_fields as $sub_field_key => $sub_field) { $new_ids[] = $sub_field->id; $new_keys[] = $sub_field->field_key; } $new_ids[] = $field->id; $new_keys[] = $field->field_key; } else { $new_ids[] = $field->id; $new_keys[] = $field->field_key; } } if (count($old_ids) === count($new_ids)) { $old_ids = array_reverse($old_ids); $new_ids = array_reverse($new_ids); $old_keys = array_reverse($old_keys); $new_keys = array_reverse($new_keys); $list_ids = array_combine($old_ids, $new_ids); $actions = $this->actions_replace_shortcodes($actions, $list_ids); $list_keys = array_combine($old_keys, $new_keys); $actions = $this->pages_replace_shortcodes($actions, $list_keys); } unset($dom); unlink($tmp); } return $actions; } public function filter_frm_graph_shortcode_custom_html($html, $data) { if (apply_filters('e2pdf_pdf_render', false)) { return serialize($data['graph_data']); } return $html; } public function filter_e2pdf_controller_templates_import_replace_shortcodes($value, $options, $xml, $template, $extension) { if ($extension->loaded('formidable') && $template->get('item') && (($template->get('item') != '-2' && $template->get('item') != (string) $xml->template->item) || ($template->get('item') == '-2' && ($template->get('item1') != (string) $xml->template->item1 || $template->get('item2') != (string) $xml->template->item2))) && $xml->item->formidable && $options['item'] && class_exists('FrmXMLHelper') && class_exists('FrmField') ) { $tmp = tempnam($this->helper->get('tmp_dir'), 'e2pdf'); file_put_contents($tmp, base64_decode((string) $xml->item->formidable), LOCK_EX); $dom = new DOMDocument(); $success = $dom->loadXML(file_get_contents($tmp)); $old_ids = array(); $old_keys = array(); if ($success && function_exists('simplexml_import_dom')) { $item_xml = simplexml_import_dom($dom); foreach ($item_xml->form as $form_key => $form) { if (($template->get('item') != '-2' && (string) $form->id == (string) $xml->template->item) || ($template->get('item') == '-2' && ((string) $form->id == (string) $xml->template->item1 || (string) $form->id == (string) $xml->template->item2))) { foreach ($form->field as $field_key => $field) { $field_options = @json_decode((string) $field->field_options, true); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged if (isset($field_options['form_select']) && $field_options['form_select']) { foreach ($item_xml->form as $sub_form_key => $sub_form) { if ((string) $sub_form->id == $field_options['form_select']) { foreach ($sub_form->field as $sub_field_key => $sub_field) { $old_ids[] = (string) $sub_field->id; $old_keys[] = (string) $sub_field->field_key; } } } $old_ids[] = (string) $field->id; $old_keys[] = (string) $field->field_key; } else { $old_ids[] = (string) $field->id; $old_keys[] = (string) $field->field_key; } } } } } $fields = array(); if ($template->get('item') == '-2') { if ($template->get('item1')) { $where = array('fi.form_id' => (int) $template->get('item1')); $item_fields = FrmField::getAll($where, 'id ASC'); if ($item_fields) { $fields = array_merge($fields, $item_fields); } } if ($template->get('item2')) { $where = array('fi.form_id' => (int) $template->get('item2')); $item_fields = FrmField::getAll($where, 'id ASC'); if ($item_fields) { $fields = array_merge($fields, $item_fields); } } } else { $where = array('fi.form_id' => (int) $template->get('item')); $fields = FrmField::getAll($where, 'id ASC'); } $new_ids = array(); $new_keys = array(); foreach ($fields as $field_key => $field) { if (isset($field->field_options['form_select']) && $field->field_options['form_select']) { $sub_where = array('fi.form_id' => (int) $field->field_options['form_select']); $sub_fields = FrmField::getAll($sub_where, 'id ASC'); foreach ($sub_fields as $sub_field_key => $sub_field) { $new_ids[] = $sub_field->id; $new_keys[] = $sub_field->field_key; } $new_ids[] = $field->id; $new_keys[] = $field->field_key; } else { $new_ids[] = $field->id; $new_keys[] = $field->field_key; } } if (count($old_ids) === count($new_ids)) { $old_ids = array_reverse($old_ids); $new_ids = array_reverse($new_ids); $old_keys = array_reverse($old_keys); $new_keys = array_reverse($new_keys); $list_ids = array_combine($old_ids, $new_ids); $value = $this->replace_shortcodes($value, $list_ids); $list_keys = array_combine($old_keys, $new_keys); $value = $this->replace_shortcodes($value, $list_keys); } unset($dom); unlink($tmp); } return $value; } /** * Delete attachments that were sent by email */ public function action_frm_notification() { $files = $this->helper->get('formidable_attachments'); if (is_array($files) && !empty($files)) { foreach ($files as $key => $file) { $this->helper->delete_dir(dirname($file) . '/'); } $this->helper->deset('formidable_attachments'); } } /** * Fix to render E2Pdf shortcodes with beforeContent and afterContent inside Formidable Form View Preview */ public function action_check_ajax_referer($action, $result) { if ($action == 'frm_ajax' && false !== $result && isset($_POST['action']) && $_POST['action'] == 'frm_views_process_box_preview') { if (isset($_POST['beforeContent']) && $_POST['beforeContent']) { $_POST['beforeContent'] = $this->filter_view_preview_before_after_content($_POST['beforeContent']); } if (isset($_POST['afterContent']) && $_POST['afterContent']) { $_POST['afterContent'] = $this->filter_view_preview_before_after_content($_POST['afterContent']); } } } public function action_frm_default_value($entry_id, $form_id) { global $wpdb; if ($form_id) { $fields = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . $wpdb->prefix . 'frm_fields` WHERE form_id = %d AND (default_value LIKE %s OR default_value LIKE %s)', $form_id, '%[e2pdf-download%', '%[e2pdf-save%')); if (!empty($fields)) { foreach ($fields as $key => $field) { $meta = FrmEntryMeta::get_entry_meta_by_field($entry_id, $field->id); if ($meta === null) { $new_value = $this->filter_frm_content($field->default_value, FrmForm::getOne($form_id), $entry_id); $added = FrmEntryMeta::add_entry_meta($entry_id, $field->id, null, $new_value); if (!$added) { FrmEntryMeta::update_entry_meta($entry_id, $field->id, null, $new_value); } } } } } } /** * Filter "get" shortcodes with beforeContent and afterContent inside Formidable Form View Preview * @param type $content * @return type */ public function filter_view_preview_before_after_content($content) { if (false !== strpos($content, '[get ') && ( false !== strpos($content, 'e2pdf-download') || false !== strpos($content, 'e2pdf-save') || false !== strpos($content, 'e2pdf-view') || false !== strpos($content, 'e2pdf-adobesign') || false !== strpos($content, 'e2pdf-zapier') || false !== strpos($content, 'e2pdf-attachment') )) { $shortcode_tags = array( 'get', ); preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches); $tagnames = array_intersect($shortcode_tags, $matches[1]); if (!empty($tagnames)) { preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes); foreach ($shortcodes[0] as $key => $shortcode_value) { $content = str_replace($shortcode_value, $this->convert_shortcodes($shortcode_value), $content); } } } return $content; } public function filter_filter_content($content, $form, $entry = false) { $content = FrmFormsController::replace_form_name_shortcodes($content, $form); if (!$entry) { return $content; } if (is_object($form)) { $form = $form->id; } if (!empty($entry->parent_entry)) { $form = $entry->parent_entry->form_id; } $shortcodes = $this->get('cached_shortcodes'); $content = apply_filters('frm_replace_content_shortcodes', $content, $entry, $shortcodes); return $content; } /** * Auto Generate of Template for this extension * @return array - List of elements */ public function auto() { $response = array(); $elements = array(); $form_id = $this->get('item'); $fields = array(); if (class_exists('FrmField')) { $fields = FrmField::get_all_for_form($form_id, '', 'include', 'include'); } if ($fields) { foreach ($fields as $key => $field) { $field_id = get_option('e2pdf_formidable_use_keys', '0') ? $field->field_key : $field->id; if ($field->type === 'lookup' && isset($field->field_options['data_type'])) { if ($field->field_options['data_type'] == 'select') { $field->options = array( '[e2pdf-frm-lookup-values id="' . $field_id . '"]', ); } elseif ($field->field_options['data_type'] == 'radio' || $field->field_options['data_type'] == 'checkbox') { $options = array(); $frm_filter = false; if (class_exists('FrmProFieldsHelper') && method_exists('FrmProFieldsHelper', 'add_default_field_settings')) { if (!has_filter('frm_default_field_options', 'FrmProFieldsHelper::add_default_field_settings')) { add_filter('frm_default_field_options', 'FrmProFieldsHelper::add_default_field_settings', 10, 2); $frm_filter = true; } } $args = array(); $field_array = FrmAppHelper::start_field_array($field); FrmFieldsHelper::prepare_new_front_field($field_array, $field, $args); $field_array = array_merge($field->field_options, $field_array); if (isset($field_array['options']) && is_array($field_array['options'])) { $options = $field_array['options']; } if ($frm_filter) { remove_filter('frm_default_field_options', 'FrmProFieldsHelper::add_default_field_settings'); } $field->options = $options; } $field->type = $field->field_options['data_type']; } elseif ($field->type === 'data' && isset($field->field_options['data_type'])) { if ($field->field_options['data_type'] == 'select') { $field->options = array( '[e2pdf-frm-data-values id="' . $field_id . '"]', ); } elseif ($field->field_options['data_type'] == 'radio' || $field->field_options['data_type'] == 'checkbox') { $options = array(); $frm_filter = false; if (class_exists('FrmProFieldsHelper') && method_exists('FrmProFieldsHelper', 'add_default_field_settings')) { if (!has_filter('frm_default_field_options', 'FrmProFieldsHelper::add_default_field_settings')) { add_filter('frm_default_field_options', 'FrmProFieldsHelper::add_default_field_settings', 10, 2); $frm_filter = true; } } $args = array(); $field->field_options['restrict'] = '0'; $field_array = FrmAppHelper::start_field_array($field); FrmFieldsHelper::prepare_new_front_field($field_array, $field, $args); $field_array = array_merge($field->field_options, $field_array); if (isset($field_array['options']) && is_array($field_array['options'])) { $options = $field_array['options']; } if ($frm_filter) { remove_filter('frm_default_field_options', 'FrmProFieldsHelper::add_default_field_settings'); } $field->options = $options; } $field->type = $field->field_options['data_type']; } /* * Repeatable fields Field ID modification * @since 0.01.42 */ if ($field->type !== 'lookup' && $field->type !== 'data' && isset($field->form_id) && $field->form_id != $form_id) { $field_id = $field_id . ':1'; } switch ($field->type) { case 'divider': if ($field->name) { $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-html', 'block' => true, 'properties' => array( 'top' => '20', 'left' => '20', 'right' => '20', 'width' => '100%', 'height' => 'auto', 'value' => '