'gravity', 'title' => 'Gravity Forms', ); // info public function info($key = false) { if ($key && isset($this->info[$key])) { return $this->info[$key]; } else { return array( $this->info['key'] => $this->info['title'], ); } } // active public function active() { if (defined('E2PDF_GRAVITY_EXTENSION') || $this->helper->load('extension')->is_plugin_active('gravityforms/gravityforms.php')) { return true; } return false; } // set 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') && class_exists('GFFormsModel')) { $this->set('cached_form', GFFormsModel::get_form_meta($this->get('item'))); } break; case 'dataset': $this->set('cached_entry', array()); if ($this->get('dataset') && class_exists('GFFormsModel')) { $entry = GFFormsModel::get_entry($this->get('dataset')); if ($entry && !is_wp_error($entry) && isset($entry['form_id'])) { $this->set('cached_entry', $entry); } } break; default: break; } return true; } // get 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; } // items public function items() { $items = array(); if (class_exists('GFFormsModel')) { $forms = GFFormsModel::get_forms(null, 'title'); if ($forms) { foreach ($forms as $key => $form) { $items[] = $this->item($form->id); } } } return $items; } // datasets public function datasets($item_id = false, $name = false) { $item_id = (int) $item_id; $datasets = array(); if (class_exists('GFAPI') && $item_id) { $paging = array( 'offset' => 0, 'page_size' => 9999999, ); $entries = GFAPI::get_entries($item_id, array(), array(), $paging); if ($entries) { $this->set('item', $item_id); foreach ($entries as $key => $entry) { $this->set('dataset', $entry['id']); $entry_title = $this->render($name); if (!$entry_title) { $entry_title = $entry['id']; } $datasets[] = array( 'key' => $entry['id'], 'value' => $entry_title, ); } } } return $datasets; } // dataset actions public function get_dataset_actions($dataset_id = false) { $dataset_id = (int) $dataset_id; if (!$dataset_id) { return false; } $entry = GFFormsModel::get_entry($dataset_id); $item = $entry && !is_wp_error($entry) && is_array($entry) && isset($entry['form_id']) ? $entry['form_id'] : '0'; $actions = new stdClass(); $actions->view = $this->helper->get_url( array( 'page' => 'gf_entries', 'view' => 'entry', 'id' => $item, 'lid' => $dataset_id, ) ); $actions->delete = false; return $actions; } // template actions public function get_template_actions($template = false) { $template = (int) $template; if (!$template) { return; } $actions = new stdClass(); $actions->delete = false; return $actions; } // 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('GFFormsModel')) { $form = GFFormsModel::get_form_meta($item_id); } $item = new stdClass(); if ($form) { $item->id = (string) $item_id; $item->url = $this->helper->get_url( array( 'page' => 'gf_edit_forms', 'id' => $item_id, ) ); $item->name = $form['title']; } else { $item->id = ''; $item->url = ''; $item->name = ''; } return $item; } // render 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 public function load_actions() { add_action('gform_after_email', array($this, 'action_gform_after_email'), 30); add_action('gform_after_update_entry', array($this, 'action_gform_after_update_entry'), 0, 2); // hooks add_action('gform_entries_first_column_actions', array($this, 'hook_gravity_row_actions'), 10, 4); } // load filters public function load_filters() { add_filter('gform_confirmation', array($this, 'filter_gform_confirmation'), 30, 4); add_filter('gform_notification', array($this, 'filter_gform_notification'), 30, 3); add_filter('gform_twilio_message', array($this, 'filter_gform_twilio_message'), 30, 4); add_filter('gform_entry_post_save', array($this, 'filter_gform_entry_post_save'), 0, 2); add_filter('gform_entry_field_value', array($this, 'filter_gform_entry_field_value'), 10, 4); add_filter('gform_merge_tag_filter', array($this, 'filter_gform_merge_tag_filter'), 10, 5); add_filter('gform_entries_field_value', array($this, 'filter_gform_entries_field_value'), 10, 4); /* Hooks */ add_filter('gform_entry_detail_meta_boxes', array($this, 'hook_gravity_entry_view'), 10, 3); } // render shortcodes public function render_shortcodes($value, $field = array()) { $element_id = isset($field['element_id']) ? $field['element_id'] : false; if ($this->verify()) { if (false !== strpos($value, '[')) { $value = $this->helper->load('field')->pre_shortcodes($value, $this, $field); $value = $this->helper->load('field')->inner_shortcodes($value, $this, $field); $value = $this->helper->load('field')->wrapper_shortcodes($value, $this, $field); } $gv_request = false; if (false !== strpos($value, '[gravityview') && function_exists('gravityview') && gravityview()->request->is_admin()) { $gv_request = gravityview()->request; gravityview()->request = new GV\Frontend_Request(); } $value = $this->helper->load('field')->do_shortcodes($value, $this, $field); if ($gv_request !== false) { gravityview()->request = $gv_request; } if (class_exists('GFCommon') && $this->get('cached_form') && $this->get('cached_entry')) { add_filter('gp_template_paths', array($this, 'filter_gp_template_paths'), 30, 2); add_filter('gform_merge_tag_filter', array($this, 'filter_gform_merge_tag_filter_tags'), 30, 5); add_filter('gform_display_product_summary', '__return_false', 30); $value = GFCommon::replace_variables($value, $this->get('cached_form'), $this->get('cached_entry'), false, false, false, 'text'); remove_filter('gform_display_product_summary', '__return_false', 30); remove_filter('gform_merge_tag_filter', array($this, 'filter_gform_merge_tag_filter_tags'), 30, 5); remove_filter('gp_template_paths', array($this, 'filter_gp_template_paths'), 30, 2); } $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'), false, false), $this, $field ); } return apply_filters( 'e2pdf_extension_render_shortcodes_value', $value, $element_id, $this->get('template_id'), $this->get('item'), $this->get('dataset'), false, false ); } // strip shortcodes public function strip_shortcodes($value) { $value = preg_replace('~(?:\[/?)[^/\]]+/?\]~s', '', $value); $value = preg_replace('~a\:\d+\:{[^}]*}(*SKIP)(*FAIL)|{[^}]*}~', '', $value); return $value; } // strip math public function strip_math($value, &$replacements) { if ($value) { preg_match_all('/\{[^}]+\}/', $value, $matches); foreach ($matches[0] as $match) { $index = count($replacements) + 1; $replacements[] = $match; $value = str_replace($match, '%' . $index . '$s', $value); } } return $value; } // convert shortcodes 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; } // auto public function auto() { $item = $this->get('item'); $response = array(); $elements = array(); $merged_tags = array(); $form = false; if (class_exists('GFFormsModel')) { $form = GFFormsModel::get_form_meta($item); } if ($form) { if (class_exists('GFCommon')) { foreach ($form['fields'] as $field) { $merged_tags = $this->get_field_merge_tags($merged_tags, $field); } } foreach ($form['fields'] as $field) { if ($this->get('nested') && !in_array($field->id, $this->get('nested_fields'), false)) { continue; } if ($field->type == 'product' || $field->type == 'shipping' || $field->type == 'option') { if ($field->inputType == 'select') { $field->type = 'select'; } elseif ($field->inputType == 'radio') { $field->type = 'radio'; } elseif ($field->inputType == 'checkbox') { $field->type = 'checkbox'; } elseif ($field->inputType == 'price') { $field->type = 'text'; } } if ($field->type == 'survey') { if ($field->inputType == 'rating') { $field->type = 'radio'; foreach ($field->choices as $key => $choice) { $field->choices[$key]['value'] = $choice['text']; } } elseif ($field->inputType == 'select') { $field->type = 'select'; $field->enableChoiceValue = false; foreach ($field->choices as $key => $choice) { $field->choices[$key]['value'] = $choice['text']; } } elseif ($field->inputType == 'rank') { $field->type = 'textarea'; } else { $field->type = $field->inputType; } } switch ($field->type) { case 'repeater': $value = isset($field->label) ? $field->label : ''; $value .= isset($field->id) ? ':' . $field->id : ''; if ($value) { if (!empty($field->fields)) { foreach ($field->fields as $sub_field) { $sub_value = isset($sub_field->label) ? $sub_field->label : ''; $sub_value .= isset($field->id) ? ':' . $field->id : ''; if ($sub_value) { $sub_field->id = $sub_field->id; $elements = $this->auto_fields($elements, $sub_field, $merged_tags, $item); } } } } break; default: $elements = $this->auto_fields($elements, $field, $merged_tags, $item); break; } } } $response['page'] = array( 'bottom' => '20', 'top' => '20', 'left' => '20', 'right' => '20', ); $response['elements'] = $elements; return $response; } // auto fields public function auto_fields($elements, $field, $merged_tags, $item) { switch ($field->type) { case 'text': case 'number': case 'date': case 'time': case 'phone': case 'website': case 'email': case 'post_title': case 'post_excerpt': case 'post_tags': case 'post_custom_field': case 'quantity': case 'shipping': case 'total': $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : ''; if ($this->get('nested')) { if (substr($value, -1) == '}') { $value = substr($value, 0, -1) . ':filter[' . $field->id . '],index[0]}'; } } $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-html', 'block' => true, 'properties' => array( 'top' => '20', 'left' => '20', 'right' => '20', 'width' => '100%', 'height' => 'auto', 'value' => $field->label, 'pass' => $field->enablePasswordInput ? '1' : '0', ), ) ); $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-input', 'properties' => array( 'top' => '5', 'width' => '100%', 'height' => 'auto', 'value' => $value, ), ) ); break; case 'list': $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-html', 'block' => true, 'properties' => array( 'top' => '20', 'left' => '20', 'right' => '20', 'width' => '100%', 'height' => 'auto', 'value' => $field->label, ), ) ); if ($field->enableColumns) { $width = number_format(floor((100 / count($field->choices)) * 100) / 100, 2); foreach ($field->choices as $key => $choice) { $field_id = (int) $key + 1; $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : ''; if ($this->get('nested')) { if (substr($value, -1) == '}') { $value = substr($value, 0, -1) . ':filter[' . $field->id . ':1_' . $field_id . '],index[0]}'; } } else { if (substr($value, -1) == '}') { $value = substr($value, 0, -1) . '1_' . $field_id . '}'; } } $float = true; if ($key == '0') { $float = false; } $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-html', 'block' => true, 'float' => $float, 'properties' => array( 'top' => '5', 'left' => '20', 'right' => '20', 'width' => $width . '%', 'height' => 'auto', 'value' => $choice['text'], ), ) ); $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-input', 'properties' => array( 'top' => '5', 'width' => '100%', 'height' => 'auto', 'value' => $value, ), ) ); } } else { $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : ''; if ($this->get('nested')) { if (substr($value, -1) == '}') { $value = substr($value, 0, -1) . ':filter[' . $field->id . ':1],index[0]}'; } } else { if (substr($value, -1) == '}') { $value = substr($value, 0, -1) . '1}'; } } $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-input', 'properties' => array( 'top' => '5', 'width' => '100%', 'height' => 'auto', 'value' => $value, ), ) ); } break; case 'fileupload': case 'textarea': case 'post_content': $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : ''; if ($this->get('nested')) { if (substr($value, -1) == '}') { $value = substr($value, 0, -1) . ':filter[' . $field->id . '],index[0]}'; } } $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-html', 'block' => true, 'properties' => array( 'top' => '20', 'left' => '20', 'right' => '20', 'width' => '100%', 'height' => 'auto', 'value' => $field->label, ), ) ); $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-textarea', 'properties' => array( 'top' => '5', 'width' => '100%', 'height' => 'auto', 'value' => $value, ), ) ); break; case 'select': case 'multiselect': case 'post_category': case 'option': $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-html', 'block' => true, 'properties' => array( 'top' => '20', 'left' => '20', 'right' => '20', 'width' => '100%', 'height' => 'auto', 'value' => $field->label, ), ) ); $options_tmp = array(); if (isset($field->choices) && is_array($field->choices)) { foreach ($field->choices as $opt_key => $option) { $options_tmp[] = isset($option['value']) ? $option['value'] : ''; } } $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : ''; if ($this->get('nested')) { if ($field->enableChoiceValue && $value) { if (substr($value, -1) == '}') { $value = substr($value, 0, -1) . ':value,filter[' . $field->id . '],index[0]}'; } } else { if (substr($value, -1) == '}') { $value = substr($value, 0, -1) . ':filter[' . $field->id . '],index[0]}'; } } } else { if ($field->enableChoiceValue && $value) { if (substr($value, -1) == '}') { $value = substr($value, 0, -1) . (substr_count($value, ':') >= 2 ? ',value' : ':value') . '}'; } } } $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-select', 'properties' => array( 'top' => '5', 'width' => '100%', 'height' => 'auto', 'options' => implode("\n", $options_tmp), 'value' => $value, 'height' => $field->type == 'multiselect' ? '80' : 'auto', 'multiline' => $field->type == 'multiselect' ? '1' : '0', ), ) ); break; case 'checkbox': $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-html', 'block' => true, 'properties' => array( 'top' => '20', 'left' => '20', 'right' => '20', 'width' => '100%', 'height' => 'auto', 'value' => $field->label, ), ) ); if (isset($field->choices) && is_array($field->choices)) { $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : ''; if ($this->get('nested')) { if ($field->enableChoiceValue && $value) { if (substr($value, -1) == '}') { $value = substr($value, 0, -1) . ':value,filter[' . $field->id . '],index[0]}'; } } else { if (substr($value, -1) == '}') { $value = substr($value, 0, -1) . ':filter[' . $field->id . '],index[0]}'; } } } else { if ($field->enableChoiceValue && $value) { if (substr($value, -1) == '}') { $value = substr($value, 0, -1) . (substr_count($value, ':') >= 2 ? ',value' : ':value') . '}'; } } } foreach ($field->choices as $opt_key => $option) { $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-checkbox', 'properties' => array( 'top' => '5', 'width' => 'auto', 'height' => 'auto', 'value' => $value, 'option' => isset($option['value']) ? $option['value'] : '', ), ) ); $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-html', 'float' => true, 'properties' => array( 'left' => '5', 'width' => '100%', 'height' => 'auto', 'value' => isset($option['text']) ? $option['text'] : '', ), ) ); } } break; case 'radio': $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-html', 'block' => true, 'properties' => array( 'top' => '20', 'left' => '20', 'right' => '20', 'width' => '100%', 'height' => 'auto', 'value' => $field->label, ), ) ); if (isset($field->choices) && is_array($field->choices)) { $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : ''; if ($this->get('nested')) { if ($field->enableChoiceValue && $value) { if (substr($value, -1) == '}') { $value = substr($value, 0, -1) . ':value,filter[' . $field->id . '],index[0]}'; } } else { if (substr($value, -1) == '}') { $value = substr($value, 0, -1) . ':filter[' . $field->id . '],index[0]}'; } } } else { if ($field->enableChoiceValue && $value) { if (substr($value, -1) == '}') { $value = substr($value, 0, -1) . (substr_count($value, ':') >= 2 ? ',value' : ':value') . '}'; } } } $choices = array(); foreach ($field->choices as $opt_key => $option) { if (!$value && isset($field->inputs) && isset($field->inputs[$opt_key]['id'])) { $value = isset($merged_tags[$field->inputs[$opt_key]['id']]) ? $merged_tags[$field->inputs[$opt_key]['id']] : ''; if ($field->enableChoiceValue && $value) { if (substr($value, -1) == '}') { $value = substr($value, 0, -1) . (substr_count($value, ':') >= 2 ? ',value' : ':value') . '}'; } } } if (isset($option['value'])) { $choices[] = $option['value']; } $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-radio', 'properties' => array( 'top' => '5', 'width' => 'auto', 'height' => 'auto', 'value' => $value, 'option' => isset($option['value']) ? $option['value'] : '', 'group' => $value, ), ) ); $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-html', 'float' => true, 'properties' => array( 'left' => '5', 'width' => '100%', 'height' => 'auto', 'value' => isset($option['text']) ? $option['text'] : '', ), ) ); } //other choice if ($field->enableOtherChoice) { $actions_radio = array(); $actions_input = array(); if (!empty($choices)) { $conditions = array(); $conditions[1] = array( 'condition' => '!=', 'if' => $value, 'value' => '', ); foreach ($choices as $choice) { $conditions[] = array( 'condition' => '!=', 'if' => $value, 'value' => $choice, ); } $actions_radio = array( '0' => array( 'order' => '0', 'action' => 'change', 'apply' => 'all', 'change' => 'gf_other_choice', 'property' => 'value', 'conditions' => $conditions, ), ); $actions_input = array( '0' => array( 'order' => '0', 'action' => 'change', 'apply' => 'all', 'change' => $value, 'property' => 'value', 'conditions' => $conditions, ), ); } $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-radio', 'properties' => array( 'top' => '5', 'width' => 'auto', 'height' => 'auto', 'value' => $value, 'option' => 'gf_other_choice', 'group' => $value, ), 'actions' => $actions_radio, ) ); $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-input', 'float' => true, 'properties' => array( 'left' => '5', 'width' => '100%', 'height' => 'auto', 'value' => '', ), 'actions' => $actions_input, ) ); } } break; case 'name': foreach ($field['inputs'] as $key => $input) { if (isset($input->isHidden) && $input->isHidden) { unset($field['inputs'][$key]); } } $width = '100%'; if (count($field['inputs']) == '3') { $width = '33.3%'; } else { $width = 100 / count($field['inputs']) . '%'; } foreach ($field['inputs'] as $key => $sub_field) { $elements[] = $this->auto_field( $sub_field, array( 'type' => 'e2pdf-html', 'block' => true, 'float' => $key == '0' ? false : true, 'properties' => array( 'top' => '20', 'left' => '20', 'right' => '20', 'width' => $width, 'height' => 'auto', 'value' => isset($sub_field['label']) && $sub_field['label'] ? $sub_field['label'] : '', ), ) ); $value = isset($merged_tags[$sub_field['id']]) ? $merged_tags[$sub_field['id']] : ''; if ($this->get('nested')) { if (substr($value, -1) == '}') { $value = substr($value, 0, -1) . ':filter[' . $sub_field['id'] . '],index[0]}'; } } if (isset($sub_field['choices']) && is_array($sub_field['choices'])) { $options_tmp = array(); foreach ($sub_field['choices'] as $opt_key => $option) { $options_tmp[] = isset($option['value']) ? $option['value'] : ''; } $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-select', 'properties' => array( 'top' => '5', 'width' => '100%', 'height' => 'auto', 'options' => implode("\n", $options_tmp), 'value' => $value, 'height' => 'auto', 'multiline' => '0', ), ) ); } else { $elements[] = $this->auto_field( $sub_field, array( 'type' => 'e2pdf-input', 'properties' => array( 'top' => '5', 'width' => '100%', 'height' => 'auto', 'value' => $value, ), ) ); } } break; case 'address': $index = 0; foreach ($field['inputs'] as $key => $sub_field) { if (isset($sub_field['isHidden']) && $sub_field['isHidden']) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf } else { $value = isset($merged_tags[$sub_field['id']]) ? $merged_tags[$sub_field['id']] : ''; if ($this->get('nested')) { if (substr($value, -1) == '}') { $value = substr($value, 0, -1) . ':filter[' . $sub_field['id'] . '],index[0]}'; } } $elements[] = $this->auto_field( $sub_field, array( 'type' => 'e2pdf-html', 'block' => true, 'float' => $index == '0' ? false : true, 'properties' => array( 'top' => '20', 'left' => '20', 'right' => '20', 'width' => $key == '0' || $key == '1' ? '100%' : '50%', 'height' => 'auto', 'value' => isset($sub_field['label']) && $sub_field['label'] ? $sub_field['label'] : '', ), ) ); $elements[] = $this->auto_field( $sub_field, array( 'type' => 'e2pdf-input', 'properties' => array( 'top' => '5', 'width' => '100%', 'height' => 'auto', 'value' => $value, ), ) ); $index++; } } break; case 'consent': $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-html', 'block' => true, 'properties' => array( 'top' => '20', 'left' => '20', 'right' => '20', 'width' => '100%', 'height' => 'auto', 'value' => $field->label, ), ) ); $value = isset($merged_tags[$field->id . '.1']) ? $merged_tags[$field->id . '.1'] : ''; if ($this->get('nested')) { if (substr($value, -1) == '}') { $value = substr($value, 0, -1) . ':filter[' . $field->id . '.1],index[0]}'; } } $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-checkbox', 'properties' => array( 'top' => '5', 'width' => 'auto', 'height' => 'auto', 'value' => $value, 'option' => '1', ), ) ); $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-html', 'float' => true, 'properties' => array( 'left' => '5', 'width' => '100%', 'height' => 'auto', 'value' => $field->checkboxLabel, ), ) ); break; case 'post_image': $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : ''; if ($this->get('nested')) { if (substr($value, -1) == '}') { $value = substr($value, 0, -1) . ':filter[' . $field->id . '],index[0]}'; } } $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-html', 'block' => true, 'properties' => array( 'top' => '20', 'left' => '20', 'right' => '20', 'width' => '100%', 'height' => 'auto', 'value' => $field->label, ), ) ); $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-image', 'properties' => array( 'top' => '5', 'width' => '100', 'height' => '100', 'value' => $value, 'dimension' => '1', ), ) ); if ($field->displayTitle) { $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : ''; if ($this->get('nested')) { if (substr($value, -1) == '}') { $value = substr($value, 0, -1) . ':title,filter[' . $field->id . '],index[0]}'; } } else { if (substr($value, -1) == '}') { $value = substr($value, 0, -1) . ':title}'; } } $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-html', 'block' => true, 'properties' => array( 'top' => '20', 'left' => '20', 'right' => '20', 'width' => '100%', 'height' => 'auto', 'value' => __('Title', 'gravityforms'), ), ) ); $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-input', 'properties' => array( 'top' => '5', 'width' => '100%', 'height' => 'auto', 'value' => $value, 'dimension' => '1', ), ) ); } if ($field->displayCaption) { $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : ''; if ($this->get('nested')) { if (substr($value, -1) == '}') { $value = substr($value, 0, -1) . ':caption,filter[' . $field->id . '],index[0]}'; } } else { if (substr($value, -1) == '}') { $value = substr($value, 0, -1) . ':caption}'; } } $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-html', 'block' => true, 'properties' => array( 'top' => '20', 'left' => '20', 'right' => '20', 'width' => '100%', 'height' => 'auto', 'value' => __('Caption', 'gravityforms'), ), ) ); $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-input', 'properties' => array( 'top' => '5', 'width' => '100%', 'height' => 'auto', 'value' => $value, 'dimension' => '1', ), ) ); } if ($field->displayDescription) { $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : ''; if ($this->get('nested')) { if (substr($value, -1) == '}') { $value = substr($value, 0, -1) . ':description,filter[' . $field->id . '],index[0]}'; } } else { if (substr($value, -1) == '}') { $value = substr($value, 0, -1) . ':description}'; } } $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-html', 'block' => true, 'properties' => array( 'top' => '20', 'left' => '20', 'right' => '20', 'width' => '100%', 'height' => 'auto', 'value' => __('Description', 'gravityforms'), ), ) ); $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-input', 'properties' => array( 'top' => '5', 'width' => '100%', 'height' => 'auto', 'value' => $value && substr($value, -1) == '}' ? substr($value, 0, -1) . ':description}' : '', 'dimension' => '1', ), ) ); } break; case 'html': $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-html', 'block' => true, 'properties' => array( 'top' => '20', 'left' => '20', 'right' => '20', 'width' => '100%', 'height' => 'auto', 'value' => $field->content, ), ) ); break; case 'product': if ($field->inputType != 'hiddenproduct') { $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-html', 'block' => true, 'properties' => array( 'top' => '20', 'left' => '20', 'right' => '20', 'width' => '100%', 'height' => 'auto', 'value' => $field->label, ), ) ); if ($field->inputType == 'singleproduct' || $field->inputType == 'calculation') { if ($field->disableQuantity) { $width = '50%'; } else { $width = '33.3%'; } foreach ($field['inputs'] as $key => $sub_field) { if ($field->disableQuantity && $key == '2') { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf } else { $value = isset($merged_tags[$sub_field['id']]) ? $merged_tags[$sub_field['id']] : ''; if ($this->get('nested')) { if (substr($value, -1) == '}') { $value = substr($value, 0, -1) . ':filter[' . $sub_field['id'] . '],index[0]}'; } } $elements[] = $this->auto_field( $sub_field, array( 'type' => 'e2pdf-html', 'block' => true, 'float' => $key == '0' ? false : true, 'properties' => array( 'top' => '5', 'left' => '20', 'right' => '20', 'width' => $width, 'height' => 'auto', 'value' => isset($sub_field['label']) && $sub_field['label'] ? $sub_field['label'] : '', ), ) ); $elements[] = $this->auto_field( $sub_field, array( 'type' => 'e2pdf-input', 'properties' => array( 'top' => '5', 'width' => '100%', 'height' => 'auto', 'value' => $value, ), ) ); } } } } break; case 'signature': $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-html', 'block' => true, 'properties' => array( 'top' => '20', 'left' => '20', 'right' => '20', 'width' => '100%', 'height' => 'auto', 'value' => $field->label, ), ) ); $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : ''; if ($this->get('nested')) { if (substr($value, -1) == '}') { $value = substr($value, 0, -1) . ':filter[' . $field->id . '],index[0]}'; } } $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-signature', 'properties' => array( 'top' => '5', 'width' => '100%', 'height' => '150', 'dimension' => '1', 'block_dimension' => '1', 'value' => $value, ), ) ); break; case 'form': if (isset($field->gpnfForm) && $field->gpnfForm) { $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : ''; if ($value) { $this->set('item', $field->gpnfForm); $this->set('nested', $value); $nested_fields = array(); if (isset($field->gpnfFields) && is_array($field->gpnfFields)) { $nested_fields = $field->gpnfFields; } $this->set('nested_fields', $nested_fields); $nested_form = $this->auto(); if (!empty($nested_form['elements'])) { $elements = array_merge($elements, $nested_form['elements']); } $this->set('item', $item); $this->set('nested', ''); } } break; case 'likert': $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-html', 'block' => true, 'properties' => array( 'top' => '20', 'left' => '20', 'right' => '20', 'width' => '100%', 'height' => 'auto', 'value' => $field->label, ), ) ); if (isset($field->gsurveyLikertEnableMultipleRows) && $field->gsurveyLikertEnableMultipleRows) { foreach ($field['inputs'] as $key => $sub_field) { $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-html', 'block' => true, 'properties' => array( 'top' => '5', 'left' => '20', 'right' => '20', 'width' => '100%', 'height' => 'auto', 'value' => $sub_field['label'], ), ) ); if (isset($field->choices) && is_array($field->choices)) { $value = isset($merged_tags[$sub_field['id']]) ? $merged_tags[$sub_field['id']] : ''; if ($field->enableChoiceValue && $value) { if (substr($value, -1) == '}') { $value = substr($value, 0, -1) . (substr_count($value, ':') >= 2 ? ',value' : ':value') . '}'; } } $choices = array(); foreach ($field->choices as $opt_key => $option) { if (!$value && isset($field->inputs) && isset($field->inputs[$opt_key]['id'])) { $value = isset($merged_tags[$field->inputs[$opt_key]['id']]) ? $merged_tags[$field->inputs[$opt_key]['id']] : ''; if ($field->enableChoiceValue && $value) { if (substr($value, -1) == '}') { $value = substr($value, 0, -1) . (substr_count($value, ':') >= 2 ? ',value' : ':value') . '}'; } } } if (isset($option['value'])) { $choices[] = $option['value']; } $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-radio', 'properties' => array( 'top' => '5', 'width' => 'auto', 'height' => 'auto', 'value' => $value, 'option' => isset($option['text']) ? $option['text'] : '', 'group' => $value, ), ) ); $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-html', 'float' => true, 'properties' => array( 'left' => '5', 'width' => '100%', 'height' => 'auto', 'value' => isset($option['text']) ? $option['text'] : '', ), ) ); } } } } else { if (isset($field->choices) && is_array($field->choices)) { $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : ''; if ($field->enableChoiceValue && $value) { if (substr($value, -1) == '}') { $value = substr($value, 0, -1) . (substr_count($value, ':') >= 2 ? ',value' : ':value') . '}'; } } $choices = array(); foreach ($field->choices as $opt_key => $option) { if (!$value && isset($field->inputs) && isset($field->inputs[$opt_key]['id'])) { $value = isset($merged_tags[$field->inputs[$opt_key]['id']]) ? $merged_tags[$field->inputs[$opt_key]['id']] : ''; if ($field->enableChoiceValue && $value) { if (substr($value, -1) == '}') { $value = substr($value, 0, -1) . (substr_count($value, ':') >= 2 ? ',value' : ':value') . '}'; } } } if (isset($option['value'])) { $choices[] = $option['value']; } $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-radio', 'properties' => array( 'top' => '5', 'width' => 'auto', 'height' => 'auto', 'value' => $value, 'option' => isset($option['text']) ? $option['text'] : '', 'group' => $value, ), ) ); $elements[] = $this->auto_field( $field, array( 'type' => 'e2pdf-html', 'float' => true, 'properties' => array( 'left' => '5', 'width' => '100%', 'height' => 'auto', 'value' => isset($option['text']) ? $option['text'] : '', ), ) ); } } } break; case 'repeater': $value = isset($field->label) ? $field->label : ''; $value .= isset($field->id) ? ':' . $field->id : ''; if ($value) { if (!empty($field->fields)) { foreach ($field->fields as $sub_field) { $sub_value = isset($sub_field->label) ? $sub_field->label : ''; $sub_value .= isset($field->id) ? ':' . $field->id : ''; if ($sub_value) { $sub_field->id = $sub_field->id; $elements = $this->auto_fields($elements, $sub_field, $merged_tags, $item); } } } } break; default: break; } return $elements; } // auto field public function auto_field($field = false, $element = array()) { if (!$field) { return false; } if (!isset($element['block'])) { $element['block'] = false; } if (!isset($element['float'])) { $element['float'] = false; } return $element; } // verify public function verify() { if ($this->get('cached_form') && $this->get('cached_entry')) { if ($this->get('cached_entry')['form_id'] == $this->get('item')) { return true; } } return false; } // auto form public function auto_form($template, $data = array()) { if ($template->get('ID')) { $auto_form_label = isset($data['auto_form_label']) && $data['auto_form_label'] ? $data['auto_form_label'] : false; $auto_form_shortcode = isset($data['auto_form_shortcode']) ? true : false; if (class_exists('GFAPI')) { $confirmation_id = uniqid(); $form = array( 'title' => $template->get('title'), 'fields' => array( ), 'confirmations' => array(), ); $form['confirmations'][$confirmation_id] = array( 'id' => $confirmation_id, 'name' => __('Default Confirmation', 'gravityforms'), 'isDefault' => true, 'type' => 'message', /* translators: %d: E2Pdf Template ID */ 'message' => sprintf(__('Thanks for contacting us! We will get in touch with you shortly. [e2pdf-download id="%d"]', 'e2pdf'), $template->get('ID')), 'url' => '', 'pageId' => '', 'queryString' => '', ); $pages = $template->get('pages'); $checkboxes = array(); $radios = array(); $field_id = 1; foreach ($pages as $page_key => $page) { if (isset($page['elements']) && !empty($page['elements'])) { foreach ($page['elements'] as $element_key => $element) { $type = false; $labels = array(); $label = ''; if ($auto_form_shortcode) { $labels[] = $field_id; } if ($auto_form_label && $auto_form_label == 'value' && isset($element['value']) && $element['value']) { $labels[] = $element['value']; } elseif ($auto_form_label && $auto_form_label == 'name' && isset($element['name']) && $element['name']) { $labels[] = $element['name']; } if ($element['type'] == 'e2pdf-input' || $element['type'] == 'e2pdf-signature') { $type = 'text'; $label = !empty($labels) ? implode(' ', $labels) : 'Text'; } elseif ($element['type'] == 'e2pdf-textarea') { $type = 'textarea'; $label = !empty($labels) ? implode(' ', $labels) : 'Textarea'; } elseif ($element['type'] == 'e2pdf-select') { $type = 'select'; $label = !empty($labels) ? implode(' ', $labels) : 'Select'; $choices = array(); $field_options = array(); if (isset($element['properties']['options'])) { $field_options = explode("\n", $element['properties']['options']); foreach ($field_options as $option) { $choices[] = array( 'text' => $option, 'value' => $option, ); } } } elseif ($element['type'] == 'e2pdf-checkbox') { $field_key = array_search($element['name'], array_column($checkboxes, 'name'), false); if ($field_key !== false) { $checkbox = array_search($checkboxes[$field_key]['id'], array_column($form['fields'], 'id'), false); if ($checkbox !== false) { $form['fields'][$checkbox]['choices'][] = array( 'text' => $element['properties']['option'], 'value' => $element['properties']['option'], ); $num = count($form['fields'][$checkbox]['inputs']) + 1; $form['fields'][$checkbox]['inputs'][] = array( 'id' => $field_id . '.' . $num, 'label' => $element['properties']['option'], ); $pages[$page_key]['elements'][$element_key]['value'] = '{' . $form['fields'][$checkbox]['label'] . ':' . $form['fields'][$checkbox]['id'] . '}'; } } else { $label = !empty($labels) ? implode(' ', $labels) : 'Checkbox'; $type = 'checkbox'; $checkboxes[] = array( 'id' => $field_id, 'name' => $element['name'], ); $choices = array( array( 'text' => $element['properties']['option'], 'value' => $element['properties']['option'], ), ); $inputs = array( array( 'id' => $field_id . '.1', 'label' => $element['properties']['option'], ), ); } } elseif ($element['type'] == 'e2pdf-radio') { if (isset($element['properties']['group']) && $element['properties']['group']) { $element['name'] = $element['properties']['group']; } else { $element['name'] = $element['element_id']; } $field_key = array_search($element['name'], array_column($radios, 'name'), false); if ($field_key !== false) { $radio = array_search($radios[$field_key]['id'], array_column($form['fields'], 'id'), false); if ($radio !== false) { $form['fields'][$radio]['choices'][] = array( 'text' => $element['properties']['option'], 'value' => $element['properties']['option'], ); $pages[$page_key]['elements'][$element_key]['value'] = '{' . $form['fields'][$radio]['label'] . ':' . $form['fields'][$radio]['id'] . '}'; } } else { $label = !empty($labels) ? implode(' ', $labels) : 'Radio'; $type = 'radio'; $radios[] = array( 'id' => $field_id, 'name' => $element['name'], ); $choices = array( array( 'text' => $element['properties']['option'], 'value' => $element['properties']['option'], ), ); } } if ($type) { $field = array( 'id' => $field_id, 'type' => $type, 'label' => $label, ); if ($type == 'select' || $type == 'radio' || $type == 'checkbox') { $field['choices'] = $choices; } if ($type == 'checkbox') { $field['inputs'] = $inputs; } $form['fields'][] = $field; $pages[$page_key]['elements'][$element_key]['value'] = '{' . $label . ':' . $field_id . '}'; if (isset($element['properties']['esig'])) { unset($pages[$page_key]['elements'][$element_key]['properties']['esig']); } $field_id++; } } } } $item = GFAPI::add_form($form); if (!is_wp_error($item)) { $template->set('item', $item); $template->set('pages', $pages); } } } return $template; } // visual mapper public function visual_mapper() { $item = $this->get('item'); $html = ''; $source = ''; if ($item && function_exists('gravity_form')) { ob_start(); $form = false; if (class_exists('GFFormsModel')) { $form = GFFormsModel::get_form_meta($item); } if ($form) { add_filter('gform_pre_render', array($this, 'filter_gform_pre_render'), 30); $source = gravity_form($item, true, true, false, null, false, 0, false); remove_filter('gform_pre_render', array($this, 'filter_gform_pre_render'), 30); if ($source) { $dom = new DOMDocument(); if ($this->get('nested')) { $source = str_replace(array('