File manager - Edit - /home/premiey/www/wp-includes/images/media/entries.tar
Back
map-el.php 0000666 00000007226 15165335044 0006451 0 ustar 00 <?php namespace MetForm\Core\Entries; defined('ABSPATH') || exit; Class Map_El { /** * @var array */ private $_el = []; /** * @var mixed */ private $_el_list; /** * @var mixed */ private static $instance; /** * @param $data * @param $el_list */ public static function data($data, $el_list) { self::$instance = new self($data, $el_list); return self::$instance; } /** * @param $data * @param $el_list * @return mixed */ public function __construct($data, $el_list) { $this->_el_list = $el_list; $this->search_el($data); return $this; } /** * @return mixed */ public function get_el() { return $this->_el; } /** * @param $data * @return null */ private function search_el($data) { if (!is_array($data)) { return; } foreach ($data as $k => $v) { if (is_array($v->elements) && !empty($v->elements)) { $this->search_el($v->elements); } else { if ($v->elType == 'widget' && in_array(str_replace('[]', '', $v->widgetType), $this->_el_list)) { if (isset($v->settings->mf_input_name)) { $this->_el[$v->settings->mf_input_name] = $v->settings; $this->_el[$v->settings->mf_input_name]->widgetType = $v->widgetType; } else { $this->_el[$v->widgetType] = (object) [ 'mf_input_label' => (isset($v->settings->mf_input_label) ? $v->settings->mf_input_label : ''), 'mf_input_name' => (isset($v->widgetType) ? $v->widgetType : ''), 'mf_input_placeholder' => (isset($v->settings->mf_input_placeholder) ? $v->settings->mf_input_placeholder : ''), 'mf_input_min_length' => (isset($v->settings->mf_input_min_length) ? $v->settings->mf_input_min_length : ''), 'mf_input_max_length' => (isset($v->settings->mf_input_max_length) ? $v->settings->mf_input_max_length : ''), 'mf_input_length_type' => (isset($v->settings->mf_input_length_type) ? $v->settings->mf_input_length_type : ''), 'mf_input_validation_expression' => (isset($v->settings->mf_input_validation_expression) ? $v->settings->mf_input_validation_expression : ''), 'widgetType' => (isset($v->widgetType) ? $v->widgetType : '') ]; } } elseif (!empty($v->widgetType) && $v->widgetType === 'mf-button') { if (!empty($v->settings->mf_hidden_input) && is_array($v->settings->mf_hidden_input)) { foreach ($v->settings->mf_hidden_input as $value) { $this->_el[$value->mf_hidden_input_name] = (object) [ 'mf_input_label' => (isset($value->mf_hidden_input_name) ? ucwords(str_replace(['-', '_'], ' ', $value->mf_hidden_input_name)) : ''), 'mf_input_name' => (isset($value->mf_hidden_input_name) ? $value->mf_hidden_input_name : ''), 'widgetType' => (isset($v->widgetType) ? $v->widgetType : '') ]; } } } } } } } file-data-validation.php 0000666 00000021156 15165335044 0011252 0 ustar 00 <?php namespace MetForm\Core\Entries; defined('ABSPATH') || exit; class File_Data_Validation { /** * @var mixed */ private static $fields_setting; /** * @var array */ private static $response = []; /** * @param $fields_setting * @param $file_data */ public static function validate($fields_setting, $file_data) { self::$fields_setting = $fields_setting; foreach ($file_data as $input_name => $file_data) { self::file_size_validation($input_name, $file_data); self::file_extension_validation($input_name, $file_data); } return self::$response; } /** * @param $input_name * @param $file_data */ private static function file_size_validation($input_name, $file_data) { if(!isset(self::$fields_setting[$input_name])){ self::$response[$input_name] = [esc_html__("No File found", 'metform')]; return; } $field_setting = self::$fields_setting[$input_name]; $limit_status = isset($field_setting->mf_input_file_size_status) && $field_setting->mf_input_file_size_status == 'on' ? true : false; if ($limit_status) { $file_size_limit = isset($field_setting->mf_input_file_size_limit) ? $field_setting->mf_input_file_size_limit : 128; $file_size = is_array($file_data['size']) ? array_sum($file_data['size']) / 1024 : $file_data['size'] / 1024; if ($file_size > $file_size_limit) { // translators: Error message for file size limit. %s is the input name, %u is the file size limit in kilobytes. $error_message = sprintf(esc_html__('%$1s size cannot exceed %2$u kb.','metform'), $input_name, // Value for %s placeholder (input_name) $file_size_limit // Value for %u placeholder (file_size_limit) ); self::$response[$input_name] = [$error_message]; } } } /** * @param $input_name * @param $file_data * @return null */ private static function file_extension_validation($input_name, $file_data) { if(!isset(self::$fields_setting[$input_name])){ self::$response[$input_name] = [esc_html__("No File found", 'metform')]; return; } $field_setting = self::$fields_setting[$input_name]; $allowed_file_types = isset($field_setting->mf_input_file_types) ? $field_setting->mf_input_file_types : ['.jpg', '.jpeg', '.gif', '.png']; if(is_array($file_data['name'])){ foreach ($file_data['name'] as $key => $value) { $file_extension = '.' . strtolower(pathinfo($value, PATHINFO_EXTENSION)); if (in_array($file_extension, $allowed_file_types) === true && array_key_exists($file_extension, self::mimes()) === true) { if (function_exists('finfo_open')) { $mime_type = self::mimes()[$file_extension]; $finfo = finfo_open(FILEINFO_MIME); $mime = finfo_file($finfo, $file_data['tmp_name'][$key]); finfo_close($finfo); if (is_int(strpos($mime, $mime_type['mime']))) { continue; } } else { continue; } } self::$response[$input_name] = // translators: Error message for allowed file types. %1$s is the input name, %2$s is a list of allowed file types. [sprintf(esc_html__('%1$s only allow %2$s file types.','metform'), $input_name, implode(', ', $allowed_file_types) )]; return; } } } /** * @return mixed */ private static function mimes() { $mimes = [ '.docx' => [ 'mime' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' ], '.png' => [ 'mime' => 'image/png' ], '.jpg' => [ 'mime' => 'image/jpeg' ], '.jpeg' => [ 'mime' => 'image/jpeg' ], '.gif' => [ 'mime' => 'image/gif' ], '.pdf' => [ 'mime' => 'application/pdf' ], '.doc' => [ 'mime' => 'application/msword' ], '.icon' => [ 'mime' => 'image/x-icon' ], '.pptx' => [ 'mime' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation' ], '.ppt' => [ 'mime' => 'application/vnd.ms-powerpoint' ], '.pps' => [ 'mime' => 'application/vnd.ms-powerpoint' ], '.ppsx' => [ 'mime' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation' ], '.odt' => [ 'mime' => 'application/vnd.oasis.opendocument.text' ], '.xls' => [ 'mime' => 'application/vnd.ms-excel' ], '.xlsx' => [ 'mime' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ], '.psd' => [ 'mime' => 'image/vnd.adobe.photoshop' ], '.mp3' => [ 'mime' => 'audio/mpeg' ], '.m4a' => [ 'mime' => 'audio/x-m4a' ], '.ogg' => [ 'mime' => 'audio/ogg' ], '.wav' => [ 'mime' => 'audio/x-wav' ], '.mp4' => [ 'mime' => 'video/mp4' ], '.m4v' => [ 'mime' => 'video/x-m4v' ], '.mov' => [ 'mime' => 'video/quicktime' ], '.wmv' => [ 'mime' => 'video/x-ms-asf' ], '.avi' => [ 'mime' => 'video/x-msvideo' ], '.mpg' => [ 'mime' => 'video/mpeg' ], '.ogv' => [ 'mime' => 'video/ogg' ], '.3gp' => [ 'mime' => 'video/3gpp' ], '.3g2' => [ 'mime' => 'video/3gpp2' ], '.zip' => [ 'mime' => 'application/zip' ], '.csv' => [ 'mime' => 'text/plain' ], '.stl' => [ 'mime' => 'application/octet-stream' ], '.stp' => [ 'mime' => 'text/plain; charset=us-ascii' ] ]; return $mimes; } /** * Check every file widget is there any invalid large files uploaded by user * @param $mf_files * @param $file_data * @param $fields * @return array */ public static function check_files( array $mf_files, array $file_data, array $fields ): array { foreach ($mf_files as $index => $single_file_widget) { $s_files = $file_data[$single_file_widget] ?? []; // if single file upload if (isset($file_data[$single_file_widget]) && !is_array($file_data[$single_file_widget]['error'])) { if (($file_data[$single_file_widget]['error']) == UPLOAD_ERR_NO_FILE) { continue; } if (($file_data[$single_file_widget]['error']) == UPLOAD_ERR_INI_SIZE) { self::$response['status'] = 0; self::$response['error'] = esc_html__($s_files['name'] . ' file size exceeded ' . size_format(wp_max_upload_size(), 2), 'metform'); return self::$response; } } // if multiple file upload is enabled foreach ($s_files['error'] as $key => $sf) { if (($sf) == UPLOAD_ERR_NO_FILE) { continue; } if (($sf) == UPLOAD_ERR_INI_SIZE) { self::$response['status'] = 0; self::$response['error'] = esc_html__($s_files['name'][$key] . ' file size exceeded ' . size_format(wp_max_upload_size(), 2), 'metform'); return self::$response; } } } return self::$response; } } metform-shortcode.php 0000666 00000002521 15165335044 0010730 0 ustar 00 <?php namespace MetForm\Core\Entries; defined( 'ABSPATH' ) || exit; Class Metform_Shortcode{ use \MetForm\Traits\Singleton; private $all_keys; private $all_values; private $main_data; public function get_process_shortcode($string){ $replace = str_replace($this->all_keys, $this->all_values, $string); return $replace; } public function set_values($main_data){ $this->main_data = $main_data; $this->formate_keys(); $this->formate_values(); return $this; } public function get_all_keys(){ return $this->all_keys; } public function get_all_values(){ return $this->all_values; } public function set_all_keys($main_data){ $this->main_data = $main_data; $this->formate_keys(); return $this; } public function set_all_values($main_data){ $this->main_data = $main_data; $this->formate_values(); return $this; } public function formate_keys(){ $this->all_keys = array_map(function($v){ return "[".$v."]"; }, array_keys($this->main_data) ); } public function formate_values(){ $this->all_values = array_map(function($value){ return (is_array($value) ? implode(', ', $value) : $value); }, $this->main_data); } } hooks.php 0000666 00000014017 15165335044 0006415 0 ustar 00 <?php namespace MetForm\Core\Entries; defined('ABSPATH') || exit; class Hooks { use \MetForm\Traits\Singleton; public function __construct() { add_filter('manage_metform-entry_posts_columns', [$this, 'set_columns']); add_action('manage_metform-entry_posts_custom_column', [$this, 'render_column'], 10, 2); add_filter('parse_query', [$this, 'query_filter']); add_filter('wp_mail_from_name', [$this, 'wp_mail_from']); add_filter('upload_mimes', [$this, 'metfom_additional_upload_mimes']); } public function set_columns($columns) { $date_column = $columns['date']; unset($columns['date']); $columns['form_name'] = esc_html__('Form Name', 'metform'); $columns['referral'] = esc_html__('Referral','metform'); if(class_exists('\MetForm_Pro\Plugin')) { $columns['email_verified'] = esc_html__('Email Verified','metform'); } $columns['date'] = esc_html($date_column); // Show PDF export column when pro plugin is activated if(in_array('metform-pro/metform-pro.php', apply_filters('active_plugins', get_option('active_plugins')))): $columns['export_actions'] = esc_html__('Export Actions', 'metform'); endif; return $columns; } public function render_column($column, $post_id) { if(!empty(get_option('permalink_structure', true))) { $entry_api = get_rest_url('', 'metform-pro/v1/pdf-export/entry?entry_id'); }else{ $entry_api = get_rest_url('', 'metform-pro/v1/pdf-export/entry&entry_id'); } switch ($column) { case 'form_name': $form_id = get_post_meta($post_id, 'metform_entries__form_id', true); $form_name = get_post((int) $form_id); $post_title = (isset($form_name->post_title) ? $form_name->post_title : ''); global $wp; $current_url = add_query_arg($wp->query_string . "&mf_form_id=" . $form_id, '', home_url($wp->request)); echo "<a data-metform-form-id=" . esc_attr($form_id) . " class='mf-entry-filter mf-entry-flter-form_id' href=" . esc_url($current_url) . ">" . esc_html($post_title) . "</a>"; break; case 'referral': $page_id = get_post_meta( $post_id, 'mf_page_id',true ); global $wp; $current_url = add_query_arg($wp->query_string . "&mf_ref_id=" . $page_id, '', home_url($wp->request)); echo "<a class='mf-entry-filter mf-entry-flter-form_id' href='" . esc_url($current_url) . "'>".esc_html(get_the_title($page_id))."</a>"; break; case 'email_verified': $email_verified = get_post_meta($post_id, 'email_verified', true); if($email_verified == true) { echo "<button type='button' style='background:#00cd00;box-shadow:1px 1px 5px rgba(0, 205, 0, 0.3);border:none;color:white;padding:2px 6px 3px;border-radius: 5px;font-weight:400'>".esc_html__('Yes', 'metform')."</button>"; }else { echo "<button type='button' style='background:#888;border:none;color:white;padding:2px 6px 3px;border-radius: 5px;font-weight:400'>".esc_html__('No', 'metform')."</button>"; } break; case 'export_actions': // Show PDF export button when pro plugin is activated if(in_array('metform-pro/metform-pro.php', apply_filters('active_plugins', get_option('active_plugins')))): echo "<button class='metform-pdf-export-btn attr-btn attr-btn-primary' data-id=". esc_attr($post_id) ." data-nonce ='". esc_attr(wp_create_nonce('metform-pdf-export'))."' data-rest-api=".esc_url($entry_api).'='.esc_attr($post_id).">".esc_html__('PDF Export', 'metform')." <i class='pdf-spinner'></i></button"; endif; } } public function query_filter($query) { global $pagenow; //phpcs:ignore WordPress.Security.NonceVerification -- Ignore because of This is CPT page $current_page = isset($_GET['post_type']) ? sanitize_key($_GET['post_type']) : ''; if ( is_admin() && 'metform-entry' == $current_page && 'edit.php' == $pagenow && $query->query_vars['post_type'] == 'metform-entry' && isset($_GET['mf_form_id']) //phpcs:ignore WordPress.Security.NonceVerification && $_GET['mf_form_id'] != 'all' //phpcs:ignore WordPress.Security.NonceVerification ) { $form_id = sanitize_key($_GET['mf_form_id']); //phpcs:ignore WordPress.Security.NonceVerification $query->query_vars['meta_key'] = 'metform_entries__form_id'; $query->query_vars['meta_value'] = $form_id; $query->query_vars['meta_compare'] = '='; } if ( is_admin() && 'metform-entry' == $current_page && 'edit.php' == $pagenow && $query->query_vars['post_type'] == 'metform-entry' && isset($_GET['mf_ref_id']) //phpcs:ignore WordPress.Security.NonceVerification && $_GET['mf_ref_id'] != 'all' //phpcs:ignore WordPress.Security.NonceVerification ) { $page_id = sanitize_key($_GET['mf_ref_id']); //phpcs:ignore WordPress.Security.NonceVerification $query->query_vars['meta_key'] = 'mf_page_id'; $query->query_vars['meta_value'] = $page_id; $query->query_vars['meta_compare'] = '='; } } public function wp_mail_from($name) { return get_bloginfo('name'); } /** * Metform Additional Upload Mimes * * @since 3.8.9 * @access public * @param array $mimes * @return array */ public function metfom_additional_upload_mimes( $mimes ) { $mimes['stl'] = 'application/octet-stream'; $mimes['psd'] = 'image/vnd.adobe.photoshop'; $mimes['stp'] = 'text/plain; charset=us-ascii'; return $mimes; } } action.php 0000666 00000161661 15165335044 0006557 0 ustar 00 <?php namespace MetForm\Core\Entries; use MetForm_Pro\Utils\Helper; defined('ABSPATH') || exit; class Action { use \MetForm\Traits\Singleton; private $key_form_id; private $key_form_data; //private $key_form_settings; private $key_browser_data; private $key_form_total_entries; private $key_form_file; private $key_payment_status; private $post_type; private $fields; private $entry_id; private $entry_serial_no; private $form_id; private $form_data; private $form_settings; private $title; private $entry_count; private $email_name; private $file_upload_info; private $inserted_form_data; private $response; public function __construct() { $this->response = (object) [ 'status' => 0, 'store_entries' => 1, 'error' => [ esc_html__('Something went wrong.', 'metform'), ], 'data' => [ 'message' => '', ], ]; //$this->key_form_settings = 'metform_form__form_setting'; $this->key_form_total_entries = 'metform_form__form_total_entries'; $this->key_browser_data = 'metform_form__entry_browser_data'; $this->key_form_id = 'metform_entries__form_id'; $this->key_form_data = 'metform_entries__form_data'; $this->key_form_file = 'metform_entries__file_upload_new'; $this->key_payment_status = 'metform_entries__payment_status'; $this->post_type = Base::instance()->cpt->get_name(); } public function submit($form_id, $form_data, $file_data, $page_id = '') { $hidden_fields = isset($form_data['hidden-fields']) ? json_decode($form_data['hidden-fields'], true) : []; foreach ($hidden_fields as $key) { unset($form_data[$key]); } // if form is not published return $current_status = get_post_status ( $form_id ); if( 'trash' == $current_status || ( !current_user_can( 'edit_posts') && 'draft' == $current_status) ){ $this->response->error[0] = esc_html__('You are not permitted to access this form', 'metform'); return $this->response; } $this->fields = $this->get_fields($form_id); if(isset($this->fields['mf-recaptcha']) && !isset($form_data['g-recaptcha-response']) && !isset($form_data['g-recaptcha-response-v3'])) { $this->response->status = 0; $this->response->error[] = esc_html__('Unauthorized submission.', 'metform'); return $this->response; } if(isset($this->fields['mf-simple-captcha']) && !isset($form_data['mf-captcha-challenge'])){ $this->response->status = 0; $this->response->error[] = esc_html__('Unauthorized submission.', 'metform'); return $this->response; } // check for file widget if ($this->get_input_name_by_widget_type('mf-file-upload')) { $mf_files = $this->get_input_name_by_widget_type('mf-file-upload'); $response = File_Data_Validation::check_files($mf_files, $file_data, $this->fields); if(isset($response['status']) && $response['status'] == 0){ $this->response->status = 0; $this->response->error[0] = $response['error'] ?? esc_html__('File size exceeded.', 'metform'); return $this->response; } // validate files if (count(File_Data_Validation::validate($this->fields, $file_data)) > 0) { $this->response->status = 0; $this->response->error[] = esc_html__('You are trying to upload wrong file!', 'metform'); return $this->response; } } $this->form_id = $form_id; $this->title = get_the_title($this->form_id); $this->form_settings = \MetForm\Core\Forms\Action::instance()->get_all_data($form_id); $this->response->data['hide_form'] = (!isset($this->form_settings['hide_form_after_submission']) ? '' : $this->form_settings['hide_form_after_submission']); $this->response->data['form_data'] = $form_data; $email_name = $this->get_input_name_by_widget_type('mf-email')?? []; if(count($email_name) > 0 && class_exists('\MetForm_Pro\Core\Features\Entries\Unique_Validation')){ $validated_data = \MetForm_Pro\Core\Features\Entries\Unique_Validation::check_unique_fields($form_id, $form_data, $this->fields ); if($validated_data['status'] === 1){ $this->response->status = 0; $this->response->error = []; $this->response->error[0] = sprintf(esc_html__('%1$s %2$s already exist.', 'metform'), $validated_data['input_label'], $validated_data['duplicate_field']); return $this->response; } } $this->email_name = (isset($email_name[0]) ? $email_name[0] : null); // nonce check if (!$this->mf_is_woo_exists()) { if (!isset($form_data['form_nonce']) || !wp_verify_nonce($form_data['form_nonce'], 'form_nonce')) { $this->response->status = 0; $this->response->error[] = esc_html__('Unauthorized submission.', 'metform'); return $this->response; } } // validate form with max length, min length, length type and expression $validate = $this->validate_form_data($form_data); if ($validate == false) { $this->response->status = 0; $this->response->error = [ esc_html__('Form validation failed', 'metform') ]; return $this->response; } $filter_validate = apply_filters('mf_after_validation_check', ['is_valid' => $validate, 'form_data' => $form_data , 'file_data' => $file_data]); if (isset($filter_validate['is_valid']) && $filter_validate['is_valid'] == false) { $this->response->status = 0; $this->response->error = [ $filter_validate['message'] ?? esc_html__('Form validation failed', 'metform') ]; return $this->response; } // google recaptcha condition and action if ((isset($form_data['g-recaptcha-response']) || isset($form_data['g-recaptcha-response-v3'])) && (isset($this->fields['mf-recaptcha'])) && (isset($this->form_settings['mf_recaptcha_site_key'])) && $this->form_settings['mf_recaptcha_site_key'] != '') { if (isset($form_data['g-recaptcha-response']) && ($form_data['g-recaptcha-response'] == "")) { $this->response->status = 0; $this->response->error[] = esc_html__('Please solve the recaptcha.', 'metform'); return $this->response; } if ((isset($this->form_settings['mf_recaptcha_version']) && ($this->form_settings['mf_recaptcha_version'] == 'recaptcha-v3')) && (!isset($form_data['g-recaptcha-response-v3']) || ($form_data['g-recaptcha-response-v3'] == ""))) { $this->response->status = 0; $this->response->error[] = esc_html__('Google captcha token not found.', 'metform'); return $this->response; } if ((isset($this->form_settings['mf_recaptcha_version']) && ($this->form_settings['mf_recaptcha_version'] == 'recaptcha-v2')) && isset($form_data['g-recaptcha-response'])) { $response = \MetForm\Core\Integrations\Google_Recaptcha::instance()->verify_captcha_v2($form_data, $this->form_settings); } if ((isset($this->form_settings['mf_recaptcha_version']) && ($this->form_settings['mf_recaptcha_version'] == 'recaptcha-v3')) && isset($form_data['g-recaptcha-response-v3'])) { $response = \MetForm\Core\Integrations\Google_Recaptcha::instance()->verify_captcha_v3($form_data, $this->form_settings); } //$this->response->data['responseKeys'] = $response['responseKeys']; $this->response->status = $response['status']; if ($response['status'] == 0) { $this->response->error[] = (isset($response['error']) ? $response['error'] : ''); return $this->response; } } // Captcha solve conditiona and action if (isset($form_data['mf-captcha-challenge'])) { if (($form_data['mf-captcha-challenge']) == "") { $this->response->status = 0; $this->response->error = [ esc_html__('Please solve the recaptcha.', 'metform') ]; return $this->response; } session_start(); if(!empty($_SERVER['REQUEST_TIME'])){ $time = sanitize_text_field(wp_unslash($_SERVER['REQUEST_TIME'])); } $timeout_duration = 1800; if ( isset($_SESSION['LAST_ACTIVITY']) && ($time - $_SESSION['LAST_ACTIVITY']) > $timeout_duration ) { session_unset(); session_destroy(); session_start(); } $_SESSION['LAST_ACTIVITY'] = $time; if (!isset($_SESSION['mf_captcha_text'])) { $this->response->status = 0; $this->response->error = [ esc_html__('Time out of this captcha. Please reload or choose another one.', 'metform') ]; return $this->response; } if (isset($form_data['mf-captcha-challenge']) && isset($_SESSION['mf_captcha_text']) && ($form_data['mf-captcha-challenge'] == $_SESSION['mf_captcha_text'])) { $this->response->status = 1; //$this->response->data['captcha'] = esc_html__('Captcha is verified.', 'metform'); } else { $this->response->status = 0; $this->response->error = [ esc_html__('Enter correct captcha.', 'metform') ]; return $this->response; } } // user login check and action $required_loggin = isset($this->form_settings['require_login']) ? ((int) ($this->form_settings['require_login'])) : 0; if (($required_loggin == 1) && (!is_user_logged_in())) { $this->response->status = 0; $this->response->error = [ esc_html__('You must be logged in to submit form.', 'metform') ]; return $this->response; } // Total entry limit check and prevent if (isset($this->form_settings['limit_total_entries_status'])) { $entry_limit = ((int) ($this->form_settings['limit_total_entries_status'])); if (($entry_limit == 1) && ($this->get_entry_count() >= $this->form_settings['limit_total_entries'])) { $this->response->status = 0; $this->response->error = [ esc_html__('Form submission limit exceeded.', 'metform') ]; return $this->response; } } // signature input upload as image from base64 if (class_exists('\MetForm_Pro\Base\Package') && isset($form_data['mf-signature'])) { $signature_input = $this->get_input_name_by_widget_type('mf-signature'); $this->response->data['signature_name'] = $signature_input; $this->response->data['signature_input_data'] = $form_data['mf-signature']; if ($signature_input != null) { $inputs = (is_array($signature_input) ? $signature_input : []); foreach ($inputs as $input) { $b64string = isset($form_data[$input]) ? $form_data[$input] : ''; $status = $this->covert_base64_to_png($input, $b64string); $form_data[$input] = (isset($status['url']) ? $status['url'] : ''); } } //$this->response->data['signature_input'] = $signature_input; } // file upload check and action $file_input_names = $this->get_input_name_by_widget_type('mf-file-upload'); if ((!empty($file_data)) && ($file_input_names != null)) { $this->upload_file($file_data, $file_input_names); } /** * ============================== * Mailster action * ============================== */ if (class_exists('\MetForm_Pro\Core\Integrations\Email\Mailster\Mailster')) { if (isset($this->form_settings['mf_mailster']) && $this->form_settings['mf_mailster'] == '1') { $mailster = new \MetForm_Pro\Core\Integrations\Email\Mailster\Mailster(); $mailster->action($form_id, $form_data, $this->form_settings); } } // mailchimp email store action if (class_exists('\MetForm\Core\Integrations\Mail_Chimp')) { if (isset($this->form_settings['mf_mail_chimp']) && $this->form_settings['mf_mail_chimp'] == '1' && $this->email_name != null && $form_data[$this->email_name] != '') { $mail_chimp = new \MetForm\Core\Integrations\Mail_Chimp(); if (array_key_exists("mf-listing-optin", $this->fields) && isset($form_data['mf-listing-optin'])) { $response = $mail_chimp->call_api($form_data, ['auth' => $this->form_settings, 'email_name' => $this->email_name]); } elseif (!array_key_exists('mf-listing-optin', $this->fields)) { $response = $mail_chimp->call_api($form_data, ['auth' => $this->form_settings, 'email_name' => $this->email_name]); } $this->response->status = isset($response['status']) ? $response['status'] : 0; if($this->response->status == 0) $this->response->error = [ esc_html__('Problem with your mailchimp integration.', 'metform') ]; } } // ActiveCampaign email store action if (class_exists('MetForm_Pro\Core\Integrations\Email\Activecampaign\Active_Campaign')) { if (isset($this->form_settings['mf_active_campaign']) && $this->form_settings['mf_active_campaign'] == '1' && $this->email_name != null && $form_data[$this->email_name] != '') { $active_campaign = new \MetForm_Pro\Core\Integrations\Email\Activecampaign\Active_Campaign(); $response = $active_campaign->call_api($form_data, ['auth' => $this->form_settings, 'email_name' => $this->email_name]); $this->response->status = isset($response['status']) ? $response['status'] : 0; $this->response->active_campaign = isset($response['msgs']) ? $response['msgs'] : []; if($this->response->status == 0) $this->response->error = [ esc_html__('Problem with your activeCampaign integration.', 'metform') ]; } } // GetResponse email store action if (class_exists('\MetForm_Pro\Core\Integrations\Email\Getresponse\Get_Response')) { if (isset($this->form_settings['mf_get_response']) && $this->form_settings['mf_get_response'] == '1' && $this->email_name != null && $form_data[$this->email_name] != '') { $get_response = new \MetForm_Pro\Core\Integrations\Email\Getresponse\Get_Response(); $response = $get_response->call_api($form_data, ['auth' => $this->form_settings, 'email_name' => $this->email_name]); $this->response->status = isset($response['status']) ? $response['status'] : 0; if($this->response->status == 0) $this->response->error = [ esc_html__('Problem with your GetResponse integration.', 'metform') ]; } } // data submit to zapier action and check if (class_exists('\MetForm_Pro\Core\Integrations\Zapier')) { if (isset($this->form_settings['mf_zapier']) && $this->form_settings['mf_zapier'] == '1') { $url = $this->form_settings['mf_zapier_webhook']; if (array_key_exists('mf-listing-optin', $this->fields) && isset($form_data['mf-listing-optin'])) { $zapier = new \MetForm_Pro\Core\Integrations\Zapier(); $response = $zapier->call_webhook($form_data, ['url' => $url, 'email_name' => $this->email_name]); } elseif (!array_key_exists('mf-listing-optin', $this->fields)) { $zapier = new \MetForm_Pro\Core\Integrations\Zapier(); $response = $zapier->call_webhook($form_data, ['url' => $url, 'email_name' => $this->email_name]); } $this->response->status = isset($response['status']) ? $response['status'] : 0; if($this->response->status == 0) $this->response->error = [ esc_html__('Problem with your zapier integration.', 'metform') ]; } } // data submit to slack check and action if (class_exists('\MetForm\Core\Integrations\Slack')) { if (isset($this->form_settings['mf_slack']) && $this->form_settings['mf_slack'] == '1' && $this->email_name != null && $form_data[$this->email_name] != '') { $url = $this->form_settings['mf_slack_webhook']; //$this->response->data['slack_hook'] = $url; if (array_key_exists('mf-listing-optin', $this->fields) && isset($form_data['mf-listing-optin'])) { $slack = new \MetForm\Core\Integrations\Slack(); $response = $slack->call_webhook($form_data, ['url' => $url, 'email_name' => $this->email_name]); } elseif (!array_key_exists('mf-listing-optin', $this->fields)) { $slack = new \MetForm\Core\Integrations\Slack(); $response = $slack->call_webhook($form_data, ['url' => $url, 'email_name' => $this->email_name]); } $this->response->status = isset($response['status']) ? $response['status'] : 0; if($this->response->status == 0) $this->response->error = [ esc_html__('Problem with your slack integration.', 'metform') ]; } } /** * Checking if convertKit is exists * If exists calling the api */ if (class_exists('\MetForm_Pro\Core\Integrations\Convert_Kit')) { if (isset($this->form_settings['mf_convert_kit']) && $this->form_settings['mf_convert_kit'] == '1' && $this->email_name != null && $form_data[$this->email_name] != '') { $cKit = new \MetForm_Pro\Core\Integrations\Convert_Kit(false); $response = $cKit->call_api($form_data, ['mail_settings' => $this->form_settings, 'email_name' => $this->email_name]); $this->response->status = isset($response['status']) ? $response['status'] : 0; if($this->response->status == 0) $this->response->error = [ esc_html__('Problem with convertKit.', 'metform') ]; } } /* * Aweber integration * */ if (class_exists('\MetForm_Pro\Core\Integrations\Aweber')) { if (isset($this->form_settings['mf_mail_aweber']) && $this->form_settings['mf_mail_aweber'] == '1' && $this->email_name != null && $form_data[$this->email_name] != '') { $aweber = new \MetForm_Pro\Core\Integrations\Aweber(false); $response = $aweber->call_api($form_data, ['mail_settings' => $this->form_settings, 'email_name' => $this->email_name]); $this->response->status = isset($response['status']) ? $response['status'] : 0; if($this->response->status == 0) $this->response->error = [ esc_html__('Problem with your Aweber integration.', 'metform') ]; } } if (defined('MAILPOET_VERSION') && class_exists('\MetForm_Pro\Core\Integrations\Mail_Poet')) { if (isset($this->form_settings['mf_mail_poet']) && $this->form_settings['mf_mail_poet'] == '1' && $this->email_name != null && $form_data[$this->email_name] != '') { $mPoet = new \MetForm_Pro\Core\Integrations\Mail_Poet(false); $response = $mPoet->call_api($form_data, ['mail_settings' => $this->form_settings, 'email_name' => $this->email_name]); $this->response->status = isset($response['status']) ? $response['status'] : 0; if($this->response->status == 0) $this->response->error = [ esc_html__('Problem with your Mail Poet integration.', 'metform') ]; } } if (class_exists('Metform_Pro\Core\Integrations\Fluent_Crm')) { if (isset($this->form_settings['mf_fluent']) && $this->form_settings['mf_fluent'] == '1' && $this->email_name != null && !empty($form_data[$this->email_name])) { \Metform_Pro\Core\Integrations\Fluent_Crm::send_data($this->form_settings['mf_fluent_webhook'], $form_data, $this->email_name); } } // sanitize form submitted data $this->sanitize($form_data); //set submitted data array and key to a class $all_data = !empty($this->form_data) && is_array($this->form_data) ? $this->form_data : []; if (isset($this->form_settings['store_entries']) && $this->form_settings['store_entries'] == 1) { $defaults = [ 'post_title' => '', 'post_status' => 'draft', 'post_content' => '', 'post_type' => $this->post_type, ]; $this->entry_id = wp_insert_post($defaults); update_post_meta($this->entry_id, 'mf_page_id', $page_id); $entry_serial_no = get_option('metform_last_entry_serial_no'); $all_data = array_merge($all_data, ['mf_id' => ++$entry_serial_no, 'mf_form_name' => $this->title]); update_option('metform_last_entry_serial_no', $entry_serial_no); update_post_meta($this->entry_id, 'metform_entries_serial_no', $entry_serial_no); }else{ $this->response->status = '1'; $this->response->store_entries = '0'; } Metform_Shortcode::instance()->set_values($all_data); $attributes = [ 'email_field_name' => $this->email_name, 'file_data' => $file_data, 'file_upload_info' => $this->file_upload_info, ]; do_action("metform_before_store_form_data", $form_id, $form_data, $this->form_settings, $attributes); $this->form_data = apply_filters("metform_filter_before_store_form_data", $this->form_data, $form_id , $this->form_settings, $attributes); // Store data in database $this->store($form_id, $this->form_data); do_action("metform_after_store_form_data", $form_id, $form_data, $this->form_settings, $attributes); $this->response->data['redirect_to'] = !empty($this->form_settings['redirect_to']) ? $this->form_settings['redirect_to'] : ''; $bypass_form_data = json_decode(get_post_meta($form_id, 'mf_redirect_params_status', true)); if($bypass_form_data){ $url_redirect_params = $this->get_redirect_url_params(); if($url_redirect_params){ $this->response->data['redirect_to'] = add_query_arg($url_redirect_params, $this->response->data['redirect_to']); } } // data submit to a rest api check and action if (class_exists('\MetForm_Pro\Core\Integrations\Rest_Api') && isset($this->form_settings['mf_rest_api']) && ($this->form_settings['mf_rest_api_url'] != '')) { $url = $this->form_settings['mf_rest_api_url']; $method = $this->form_settings['mf_rest_api_method']; $rest_api = new \MetForm_Pro\Core\Integrations\Rest_Api(); $ref_url = isset($_SERVER['HTTP_REFERER']) ? sanitize_url($_SERVER['HTTP_REFERER']) : ''; $response = $rest_api->call_api( [ 'entries' => json_encode($this->form_data), 'entry_id' => (($this->entry_id != null) ? $this->entry_id : ''), 'form_id' => $form_data['id'], 'version' => \MetForm\Plugin::instance()->version(), 'file_uploads' => json_encode($this->file_upload_info), 'referrer_url' => $ref_url ], [ 'url' => $url, 'method' => $method, ] ); $this->response->status = isset($response['status']) ? $response['status'] : 0; if($this->response->status == 0) $this->response->error = [ esc_html__('Problem with your RestApi integration.', 'metform') ]; } // send confirmation email to user if (isset($this->form_settings['enable_user_notification']) && $this->form_settings['enable_user_notification'] == 1) { $this->send_user_email($this->form_data, $this->file_upload_info); } // send notification email to admins if (isset($this->form_settings['enable_admin_notification']) && $this->form_settings['enable_admin_notification'] == 1) { $this->send_admin_email($this->form_data, $this->file_upload_info); } $this->response->data['message'] = isset($this->form_settings['success_message']) ? $this->form_settings['success_message'] : ''; $paymet_method = $this->get_input_name_by_widget_type('mf-payment-method'); if (class_exists('\MetForm_Pro\Core\Integrations\Payment\Paypal') && isset($this->form_settings['mf_paypal']) && isset($this->form_settings['mf_paypal_email']) && ($this->form_settings['mf_paypal_email'] != '') && isset($paymet_method[0]) && ($paymet_method[0] != null)) { if (isset($this->form_data[$paymet_method[0]]) && $this->form_data[$paymet_method[0]] == 'paypal') { update_post_meta($this->entry_id, $this->key_payment_status, 'unpaid'); $rest_url = get_rest_url(null, 'metform/v1/entries/'); $this->response->data['redirect_to'] = $rest_url . "paypal/pay?entry_id=" . $this->entry_id; $this->response->data['message'] = $this->form_settings['success_message'] . esc_html__(' Please wait... Redirecting to paypal.', 'metform'); } } if (!isset($paymet_method[0])) { $paymet_method[0] = null; } if (class_exists('\MetForm_Pro\Core\Integrations\Payment\Stripe') && ($paymet_method[0] != null)) { if (isset($this->form_data[$paymet_method[0]]) && $this->form_data[$paymet_method[0]] == 'stripe') { update_post_meta($this->entry_id, $this->key_payment_status, 'unpaid'); $payment_widget_name = \MetForm\Core\Entries\Action::instance()->get_input_name_by_widget_type('mf-payment-method', $this->fields); $widget = is_array($payment_widget_name) ? current($payment_widget_name) : ''; $amount_filed = isset($this->fields[$widget]->mf_input_payment_field_name) ? $this->fields[$widget]->mf_input_payment_field_name : ''; $amount = isset($this->form_data[$amount_filed]) ? $this->form_data[$amount_filed] : 0; $currency = $this->form_settings['mf_payment_currency'] ?? 'USD'; //$this->response->data['payment_method'] = $this->form_data[$paymet_method[0]]; $icon_url = !empty($this->form_settings['mf_stripe_image_url']) ? $this->form_settings['mf_stripe_image_url'] : 'https://stripe.com/img/documentation/checkout/marketplace.png'; // set key for check payment $livekey = isset($this->form_settings['mf_stripe_live_publishiable_key']) ? $this->form_settings['mf_stripe_live_publishiable_key'] : ''; $livekey_test = isset($this->form_settings['mf_stripe_test_publishiable_key']) ? $this->form_settings['mf_stripe_test_publishiable_key'] : ''; $sandbox = isset($this->form_settings['mf_stripe_sandbox']) ? true : false; $live_keys = ($sandbox) ? $livekey_test : $livekey; $payment['name_post'] = $this->form_settings['form_title']; $payment['description'] = $this->form_id; $payment['amount'] = $amount; $payment['currency_code'] = $currency; $payment['keys'] = $live_keys; $payment['image_url'] = $icon_url; $payment['entry_id'] = $this->entry_id; $payment['form_id'] = $this->form_id; $payment['sandbox'] = $sandbox; $this->response->data['payment_data'] = (object) $payment; $rest_url = get_rest_url(null, 'metform/v1/entries/'); $this->response->data['ajax_stripe'] = $rest_url . "stripe/pay?entry_id=" . $this->entry_id; $this->response->data['message'] = $this->form_settings['success_message'] . esc_html__(' Please wait... Open a Stripe Popup Box.', 'metform'); } } /** * Woocommerce */ if (class_exists('WooCommerce')) { if ( isset($_POST['mf-woo-checkout']) && $_POST['mf-woo-checkout'] == 'yes' && class_exists('\MetForm_Pro\Core\Integrations\Ecommerce\Woocommerce\Pay')) { $woo_pay = new \MetForm_Pro\Core\Integrations\Ecommerce\Woocommerce\Pay(); $woo_pay->action($form_data, $this->entry_id); } } /** * Post submission */ if (class_exists('\MetForm_Pro\Core\Integrations\Post\Form_To_Post\Post')) { if (isset($this->form_settings['mf_form_to_post']) && $this->form_settings['mf_form_to_post'] == 1) { $post_submission = new \MetForm_Pro\Core\Integrations\Post\Form_To_Post\Post(); $post_submission->create_post( $form_data, $this->form_settings, $this->form_id, $this->entry_id, $this->file_upload_info ); } } if(!empty($this->entry_id) && !empty($this->form_data[$this->email_name])) { if(!empty($this->form_settings['email_verification_enable']) && $this->form_settings['email_verification_enable'] == 1) { do_action('met_form_email_verification', $this->entry_id, $this->form_data[$this->email_name], $this->form_settings); } } return $this->response; } public function validate_form_data($form_data) { $field_count = 0; $errors = 0; $hidden_fields = isset($form_data['hidden-fields']) ? json_decode($form_data['hidden-fields'], true) : []; foreach ($form_data as $key => $value) { if (in_array($key, $hidden_fields)) { continue; } if (!is_array($value)) { $is_required = isset($this->fields[$key]->mf_input_required) && $this->fields[$key]->mf_input_required == "yes"; if(!$is_required && trim($value) == '') { continue; } $field_count++; $min = ((isset($this->fields[$key]->mf_input_min_length) && $this->fields[$key]->mf_input_min_length != '') ? $this->fields[$key]->mf_input_min_length : ''); $max = ((isset($this->fields[$key]->mf_input_max_length) && $this->fields[$key]->mf_input_max_length != '') ? $this->fields[$key]->mf_input_max_length : ''); $validation_type = ((isset($this->fields[$key]->mf_input_validation_type) && $this->fields[$key]->mf_input_validation_type != '') ? $this->fields[$key]->mf_input_validation_type : 'none'); $expression = ((isset($this->fields[$key]->mf_input_validation_expression) && $this->fields[$key]->mf_input_validation_expression != '') ? $this->fields[$key]->mf_input_validation_expression : ''); $type = str_replace(['by_', '_length'], '', $validation_type); $str_length = ''; if ($validation_type == 'by_word_length') { $str_length = str_word_count($value); } else if ($validation_type == 'by_character_length') { $str_length = strlen($value); if ($this->fields[$key]->widgetType === 'mf-number') { $str_length = $value; } } if ((!in_array($validation_type, ['none', 'by_expresssion_based'])) && ($min != '') && ($min > $str_length)) { $errors++; $this->response->status = 0; $this->response->error[] = esc_html((($this->fields[$key]->mf_input_label != '') ? $this->fields[$key]->mf_input_label : $key) . " minimum input " . $min . " " . $type); } if ((!in_array($validation_type, ['none', 'by_expresssion_based'])) && ($max != '') && ($max < $str_length)) { $errors++; $this->response->status = 0; $this->response->error[] = esc_html((($this->fields[$key]->mf_input_label != '') ? $this->fields[$key]->mf_input_label : $key) . " maximum input " . $max . " " . $type); } if (($validation_type == 'by_expresssion_based') && ($expression != '') && (!preg_match("/" . $expression . "/", $value))) { $errors++; $this->response->status = 0; $this->response->error[] = esc_html((($this->fields[$key]->mf_input_label != '') ? $this->fields[$key]->mf_input_label : $key) . " input criteria is not matched."); } if($validation_type == 'by_range'){ $min = ((isset($this->fields[$key]->mf_input_min_value) && $this->fields[$key]->mf_input_min_value != '') ? $this->fields[$key]->mf_input_min_value : ''); $max = ((isset($this->fields[$key]->mf_input_max_value) && $this->fields[$key]->mf_input_max_value != '') ? $this->fields[$key]->mf_input_max_value : ''); if (($min != '') && ($min > intval(trim($value)))) { $errors++; $this->response->status = 0; $this->response->error[] = esc_html((($this->fields[$key]->mf_input_label != '') ? $this->fields[$key]->mf_input_label : $key) . " minimum input " . $min . " " . $type); } if (($max != '') && ($max < intval(trim($value)))) { $errors++; $this->response->status = 0; $this->response->error[] = esc_html((($this->fields[$key]->mf_input_label != '') ? $this->fields[$key]->mf_input_label : $key) . " maximum input " . $max . " " . $type); } } } } return (($errors > 0) ? false : true); } public function store($form_id, $form_data) { $this->form_id = $form_id; //$this->sanitize($form_data); if (isset($this->form_settings['store_entries']) && $this->form_settings['store_entries'] == 1) { $this->insert(); } } private function insert() { // google sheet if(class_exists('\MetForm_Pro\Core\Integrations\Google_Sheet\WF_Google_Sheet')) { if(isset($this->form_settings['mf_google_sheet']) && $this->form_settings['mf_google_sheet'] == 1) { $sheetdata = null; if(isset($this->form_settings['mf_google_spreadsheets_list_id']) && isset($this->form_settings['mf_google_sheets_list_id'])){ $sheetdata = [ "sheet_id" => $this->form_settings['mf_google_spreadsheets_list_id'], "sheet_title_no" => $this->form_settings['mf_google_sheets_list_id'], ]; } $sheet = \MetForm_Pro\Core\Integrations\Google_Sheet\WF_Google_Sheet::instance()->insert($this->form_id, $this->title, $this->form_data, $this->file_upload_info, $this->get_fields($this->form_id), $sheetdata ); if($sheet === false) { $this->response->error[] = esc_html__('ssl certificate or google oauth credentials problem', 'metform'); $this->response->status = 0; return $this->response; } } } $form_settings = $this->form_settings; $form_id = $this->form_id; if (class_exists('\MetForm_Pro\Core\Integrations\Sms\Sms')) { if (isset($form_settings['mf_sms_status']) && $form_settings['mf_sms_status'] == 1) { if (isset($form_settings['mf_sms_user_status']) && $form_settings['mf_sms_user_status'] == 1) { $mobile_number = $this->get_input_name_by_widget_type('mf-mobile'); if (isset($mobile_number[0])) { $message = isset($form_settings['mf_sms_user_body']) ? $form_settings['mf_sms_user_body'] : ''; \MetForm_Pro\Core\Integrations\Sms\Sms::send_sms('twilio', $form_settings, $this->form_data[$mobile_number[0]], $message); } } if (isset($form_settings['mf_sms_admin_status']) && $form_settings['mf_sms_admin_status'] == 1 && isset($form_settings['mf_sms_admin_to'])) { $message = isset($form_settings['mf_sms_admin_body']) ? $form_settings['mf_sms_admin_body'] : ''; \MetForm_Pro\Core\Integrations\Sms\Sms::send_sms('twilio', $form_settings, $form_settings['mf_sms_admin_to'], $message); } } } $this->form_settings['entry_title'] = (isset($this->form_settings['entry_title']) ? $this->form_settings['entry_title'] : 'Entry # [mf_id]'); $update = array( 'ID' => $this->entry_id, 'post_title' => Metform_Shortcode::instance()->get_process_shortcode($this->form_settings['entry_title']), 'post_status' => 'publish', 'post_content' => '', ); wp_update_post($update); $this->response->data['form_id'] = $form_id; $this->response->data['entry_id'] = $this->entry_id; $entry_count = $this->get_entry_count(); $entry_count++; update_post_meta($form_id, $this->key_form_total_entries, $entry_count); update_post_meta($this->entry_id, $this->key_form_id, $form_id); update_post_meta($this->entry_id, $this->key_form_data, $this->form_data); update_post_meta($this->entry_id, $this->key_form_file, $this->file_upload_info); if (isset($form_settings['capture_user_browser_data']) && $form_settings['capture_user_browser_data'] == '1') { update_post_meta($this->entry_id, $this->key_browser_data, $this->get_browser_data()); $this->response->status = 1; } // entries of logged in user data if (is_user_logged_in()) { update_post_meta($this->entry_id, 'metform_entries__user_id', get_current_user_id()); } $this->response->status = 1; $this->response->data['store'] = $this->form_data; //## set stransient token for data access checking set_transient('transient_mf_form_data_entry_id_'.$this->entry_id, $this->entry_id, 15*60); $mf_make_str_for_hashing = $this->entry_id.get_current_user_id(); $mf_hashed_str_for_access_check = password_hash($mf_make_str_for_hashing,PASSWORD_DEFAULT); // setup cookie for current submission. setcookie(base64_encode('mf-cookie'), $mf_hashed_str_for_access_check, time()+(60*15),'/'); } private function update() { update_post_meta($this->entry_id, $this->key_form_id, $this->form_id); update_post_meta($this->entry_id, $this->key_form_data, $this->form_data); $this->response->status = 1; } public function send_user_email($form_data, $file_info) { $user_mail = (isset($form_data[$this->email_name]) ? $form_data[$this->email_name] : null); $subject = isset($this->form_settings['user_email_subject']) ? $this->form_settings['user_email_subject'] : get_bloginfo('name'); $from = isset($this->form_settings['user_email_from']) ? $this->form_settings['user_email_from'] : null; $reply_to = isset($this->form_settings['user_email_reply_to']) ? $this->form_settings['user_email_reply_to'] : null; $body = nl2br(isset($this->form_settings['user_email_body']) ? $this->form_settings['user_email_body'] : null); $user_email_attached_submission_copy = isset($this->form_settings['user_email_attach_submission_copy']) ? $this->form_settings['user_email_attach_submission_copy'] : null; //replace data from shortcode $body = Metform_Shortcode::instance()->get_process_shortcode($body); $reply_to = Metform_Shortcode::instance()->get_process_shortcode($reply_to); $subject = Metform_Shortcode::instance()->get_process_shortcode($subject); if($user_email_attached_submission_copy == "1"){ $body = "<html><body><h2 style='text-align: center;'>" . get_the_title($this->form_id) . "</h2><h4 style='text-align: center;'>" . $body . "</h4>"; $form_html = \MetForm\Core\Entries\Form_Data::format_data_for_mail($this->form_id, $form_data, $file_info); $body .= $form_html . "</body></html>"; }else{ $body = "<html><body><h2 style='text-align: center;'>" . get_the_title($this->form_id) . "</h2><h4 style='text-align: center;'>" . $body . "</h4>" . "</body></html>"; } $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n"; $headers .= 'From: ' . $from . "\r\n" . 'Reply-To: ' . $reply_to . "\r\n" . 'X-Mailer: PHP/' . phpversion(); if (!$user_mail) { if(current_user_can( 'manage_options' )){ $this->response->status = 0; $this->response->error[] = esc_html__('Mail not found.', 'metform'); } } else { $status = wp_mail($user_mail, $subject, $body, $headers); if(current_user_can( 'manage_options' )){ if(empty($status)){ $this->response->error[] = esc_html__('Please setup your SMTP mail server.', 'metform'); $this->response->status = 0; } } } } public function send_admin_email($form_data, $file_info) { $subject = isset($this->form_settings['admin_email_subject']) ? $this->form_settings['admin_email_subject'] : null; $from = isset($this->form_settings['admin_email_from']) ? $this->form_settings['admin_email_from'] : null; $reply_to = isset($this->form_settings['admin_email_reply_to']) ? $this->form_settings['admin_email_reply_to'] : null; $body = nl2br(isset($this->form_settings['admin_email_body']) ? $this->form_settings['admin_email_body'] : null); $admin_email_attached_submision_copy = isset($this->form_settings['admin_email_attach_submission_copy']) ? $this->form_settings['admin_email_attach_submission_copy'] : null; //replace data from shortcode $body = Metform_Shortcode::instance()->get_process_shortcode($body); $from = Metform_Shortcode::instance()->get_process_shortcode($from); $reply_to = Metform_Shortcode::instance()->get_process_shortcode($reply_to); $subject = Metform_Shortcode::instance()->get_process_shortcode($subject); $body = "<html><body><h2 style='text-align: center;'>" . get_the_title($this->form_id) . "</h2><h4 style='text-align: center;'>" . $body . "</h4>"; $form_html = \MetForm\Core\Entries\Form_Data::format_data_for_mail($this->form_id, $form_data, $file_info); $body .= $form_html; if (isset($this->form_settings['store_entries']) && $this->form_settings['store_entries'] == 1) { $edit_link = get_edit_post_link($this->entry_id); $body .= '<a href="' . $edit_link . '">' . $edit_link . '</a>'; } $body .= "</body></html>"; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n"; $headers .= 'From: ' . $from . "\r\n" . 'Reply-To: ' . $reply_to . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $mail = isset($this->form_settings['admin_email_to']) ? $this->form_settings['admin_email_to'] : null; $mail = Metform_Shortcode::instance()->get_process_shortcode($mail); if (!$mail) { if(current_user_can( 'manage_options' )){ $this->response->status = 0; $this->response->error[] = esc_html__('Admin mail not found to send email.', 'metform'); } } else { $admin_email = preg_replace('/\s+/', '', $mail); $admin_emails = explode(",", $admin_email); foreach ($admin_emails as $email) { $status = wp_mail($email, $subject, $body, $headers); } if(current_user_can( 'manage_options' )){ if(empty($status)){ $this->response->error[] = esc_html__('Please setup your SMTP mail server.', 'metform'); $this->response->status = 0; } } } } /** * Check if woocommerce is exists */ public static function mf_is_woo_exists() { if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) { return true; } return false; } public function get_fields($form_id = null) { if ($form_id != null) { $this->form_id = $form_id; } $input_widgets = \Metform\Widgets\Manifest::instance()->get_input_widgets(); $widget_input_data = get_post_meta($this->form_id, '_elementor_data', true); $widget_input_data = json_decode($widget_input_data); return Map_El::data($widget_input_data, $input_widgets)->get_el(); } public function sanitize($form_data, $fields = null) { if ($fields == null) { $fields = $this->fields; } foreach ($form_data as $key => $value) { if (isset($fields[$key])) { $this->form_data[$key] = $value; /** * Credit card value sanitizaton & type insertion */ if ($fields[$key]->widgetType == "mf-credit-card" && !empty(trim($value))) { $this->form_data[$key] = str_repeat('*', strlen(str_replace(' ', '', $value)) - 4) . substr(str_replace(' ', '', $value), -4); $this->form_data[$key . '--type'] = $form_data[$key . '--type']; #insert credit card type } } // If it's quiz form if(isset($this->form_settings['form_type']) && $this->form_settings['form_type'] == 'quiz-form'){ $quiz_data_keys = [ 'wrong-answer', 'right-answer', 'quiz-marks', 'total-question', ]; if(in_array($key, $quiz_data_keys)){ $this->form_data[$key] = $value; } } } $repeaters = $this->get_input_name_by_widget_type('mf-simple-repeater'); $repeaters = (is_array($repeaters) ? $repeaters : []); foreach ($repeaters as $repeater) { if (isset($this->form_data[$repeater])) { $repeater_process_data = $this->process_repeater_data($this->form_data[$repeater]); $this->form_data[$repeater] = $repeater_process_data; } } } public function upload_file($file_data, $file_input_names) { foreach ($file_input_names as $i => $input_name) { // initial upload status, status use as array for multiple file $upload[$input_name]['status'] = false; $this->handle_file($file_data, $input_name); } } private function handle_file($file_data, $input_name) { if (empty($file_data[$input_name])) { return; } if(!function_exists('wp_handle_upload')){ // need to require WordPress wp_handle_upload function require_once ABSPATH . 'wp-admin/includes/file.php'; } // Filter to modify upload directory add_filter('upload_dir', [$this, 'modify_metform_upload_dir']); // remove_filter('upload_dir', [$this, 'modify_metform_upload_dir']); $files = $file_data[$input_name]; $total_files = (isset($file_data[$input_name]['name']) && is_array($file_data[$input_name]['name'])) ? count($file_data[$input_name]['name']) : 0; $failed = false; $uploaded_info = []; for ($index = 0; $index < $total_files; $index++) { if (isset($files['name'][$index]) && $files['name'][$index] != '') { $file = [ 'name' => "entry-file-".wp_hash(microtime(), 'secure_auth').'.'.pathinfo($files['name'][$index], PATHINFO_EXTENSION), 'type' => $files['type'][$index], 'tmp_name' => $files['tmp_name'][$index], 'error' => isset($files['error'][$index]) ? $files['error'][$index] : null, 'size' => $files['size'][$index], ]; $upload = \wp_handle_upload($file, array('test_form' => false)); if (isset($upload['error']) && $upload['error']) { $failed = true; break; } else { $uploaded_info[] = [ 'name' => $files['name'][$index], 'url' => $upload['url'], 'file' => $upload['file'], 'type' => $files['type'][$index], ]; } } } if ($failed) { $this->response->status = 0; $this->response->error[] = esc_html__('There was an error uploading your file.', 'metform'); } else { $this->file_upload_info[$input_name] = $uploaded_info; $this->response->status = 1; } } /** * Modify default upload directory for upload metform entires */ public function modify_metform_upload_dir($upload_dir) { $custom_upload_folder = 'metform-uploads'; // Initialize WordPress filesystem global $wp_filesystem; if (empty($wp_filesystem)) { require_once ABSPATH . '/wp-admin/includes/file.php'; WP_Filesystem(); } // Setup paths $upload_path = $upload_dir['basedir'] . '/' . $custom_upload_folder; $upload_url = $upload_dir['baseurl'] . '/' . $custom_upload_folder; $upload_dir['path'] = $upload_path; $upload_dir['url'] = $upload_url; $upload_dir['subdir'] = '/' . $custom_upload_folder; // Create directory if it doesn't exist if (!$wp_filesystem->is_dir($upload_path)) { $wp_filesystem->mkdir($upload_path); } // Create index.php file for folder protection $index_file = $upload_path . '/index.php'; if (!$wp_filesystem->exists($index_file)) { $wp_filesystem->put_contents($index_file, '<?php // Silence is golden.'); } // Create .htaccess file for additional security rules $htaccess_file = $upload_path . '/.htaccess'; if (!$wp_filesystem->exists($htaccess_file)) { $rules = '# Disable parsing of PHP for some server configurations to modify rules use metform_upload_root_htaccess_rules filter hook. <Files *> SetHandler none SetHandler default-handler Options -ExecCGI Options -Indexes RemoveHandler .cgi .php .php3 .php4 .php5 .phtml .pl .py .pyc .pyo </Files> <IfModule mod_php5.c> php_flag engine off </IfModule> <IfModule headers_module> Header set X-Robots-Tag "noindex" </IfModule>'; /** * A filter to allow the htaccess rules * * @since 3.8.7 * * @param mixed $rules The Rules of what to parse or not to parse */ $rules = apply_filters( 'metform_upload_root_htaccess_rules', $rules ); if ( ! empty( $rules ) ) { if(!function_exists('insert_with_markers')){ require_once( ABSPATH . 'wp-admin/includes/misc.php' ); } insert_with_markers( $htaccess_file, 'MetForm', $rules ); } } return $upload_dir; } private function get_redirect_url_params(){ $url_data = []; // get current form redirect url params $redireact_params = get_post_meta($this->form_id, 'mf_redirect_params', true); if(trim($redireact_params)){ $redireact_params = json_decode($redireact_params, true); if(is_array($redireact_params)){ foreach($redireact_params as $r_key => $r_params){ foreach($this->form_data as $d_key => $f_data){ // check for key match if(trim($r_params) == trim($d_key)){ $url_data[$r_key] = $f_data; } } } return $url_data; } } return false; } /** * Converting an png image string to png image file. * * @param $input * @param $b64string * * @return array */ public function covert_base64_to_png($input, $b64string) { $status = []; $upload_dir = wp_upload_dir(); $upload_path = $upload_dir['path']; $upload_url = $upload_dir['url']; $bin = str_replace('data:image/png;base64,', '', $b64string, $ct); $decoded = base64_decode($bin); $img_name = '/' . $input . time() . '.png'; $img_file = $upload_path . $img_name; $img_url = $upload_url . $img_name; $img = file_put_contents($img_file, $decoded); if ($img) { $status['status'] = true; $status['url'] = $img_url; } else { $status['status'] = false; } return $status; } public function get_entry_count($form_id = null) { if ($form_id != null) { $this->form_id = $form_id; } global $wpdb; $entry_count = $wpdb->get_results($wpdb->prepare(" SELECT COUNT( `post_id` ) as `count` FROM `" . $wpdb->prefix . "postmeta` WHERE `meta_key` LIKE %s AND `meta_value` = %d ",'metform_entries__form_id',$this->form_id), OBJECT); $entry_count = $entry_count[0]->count; $this->entry_count = $entry_count; return $entry_count; } public function get_browser_data() { if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip = sanitize_text_field(wp_unslash($_SERVER['HTTP_CLIENT_IP'])); } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip = sanitize_text_field(wp_unslash($_SERVER['HTTP_X_FORWARDED_FOR'])); } else { $ip = isset($_SERVER['REMOTE_ADDR']) ? sanitize_text_field(wp_unslash($_SERVER['REMOTE_ADDR'])):''; } $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? sanitize_text_field(wp_unslash($_SERVER['HTTP_USER_AGENT'])):''; return [ 'IP' => $ip, 'User_Agent' => $user_agent, ]; } public function get_input_name_by_widget_type($widget_type, $fields = null) { global $w; if ($fields != null) { $this->fields = $fields; } $response = []; $w = $widget_type; $files = array_values(array_filter($this->fields, function ($v) { global $w; if ($v->widgetType == $w) { return $v; } })); foreach ($files as $file) { $response[] = $file->mf_input_name; } if (!empty($response)) { return $response; } else { return null; } } public function process_repeater_data($repeater_data) { $data = []; if (is_array($repeater_data)) { foreach ($repeater_data as $index => $value) { if (is_array($value)) { foreach ($value as $input_name => $input_value) { $proc_key = $input_name . "-" . ((int)$index + 1); if (is_array($input_value)) { $data[$proc_key] = implode(', ', $input_value); } else { $data[$proc_key] = $input_value; } } } } } return $data; } } meta-data.php 0000666 00000036146 15165335044 0007136 0 ustar 00 <?php namespace MetForm\Core\Entries; defined('ABSPATH') || exit; #[\AllowDynamicProperties] class Meta_Data { private $browser_data = null; private $file_meta_data = null; private $form_id; private $form_data; private $form_settings; private $fields; public function __construct() { $this->cpt = new Cpt(); add_action('save_post', [$this, 'store_form_data_cmb']); add_action('add_meta_boxes', [$this, 'add_form_id_cmb']); add_action('add_meta_boxes', [$this, 'add_form_data_cmb']); add_action('add_meta_boxes', [$this, 'add_browser_data_cmb']); add_action('add_meta_boxes', [$this, 'add_file_upload_cmb']); add_action('admin_init', [$this, 'show_hide_payment_woo_meta_box']); } /** * @description - checks if the post has any data of payment methods and woocommerce checkout. * Based on the data it shows/hides the payment methods and woocommerce checkout meta box. * @reference - https://prnt.sc/TJSnTkhK4hWy */ function show_hide_payment_woo_meta_box() { $post_id = isset($_GET['post']) ? sanitize_text_field(wp_unslash($_GET['post'])) : ''; //phpcs:ignore WordPress.Security.NonceVerification -- Nonce can't be added in CPT edit page URL $getPaymentStatus = get_post_meta($post_id, 'metform_entries__payment_status', true); $getPaymentInvoiceStatus = get_post_meta($post_id, 'metform_entries__payment_invoice', true); if($getPaymentStatus || $getPaymentInvoiceStatus){ add_action('add_meta_boxes', [$this, 'add_form_payment_status_cmb']); } $getWooCheckoutStatus = get_post_meta($post_id, 'mf_woo_order_id', true); if($getWooCheckoutStatus){ add_action('add_meta_boxes', [$this, 'add_woo_payment_status_cmb']); } } function add_form_id_cmb() { add_meta_box( 'metform_entries__form_id', esc_html__('Info', 'metform'), [$this, 'show_form_id_cmb'], $this->cpt->get_name(), 'side', 'high' ); } function show_form_id_cmb($post) { wp_nonce_field('meta_nonce', 'meta_nonce'); $this->form_id = get_post_meta($post->ID, 'metform_entries__form_id', true); // get fields by form id for further use $this->fields = Action::instance()->get_fields($this->form_id); $form_title = get_the_title((int)$this->form_id); ?> <div class="metform-entry-data container"> <table class='mf-entry-data' cellpadding="5" cellspacing="0"> <tbody> <tr class="mf-data-label"> <td colspan='2'><strong><?php esc_html_e('Form Name ', 'metform'); ?></strong></td> </tr> <tr class='mf-data-value'> <td><?php echo esc_attr($form_title); ?></td> </tr> <tr class="mf-data-label"> <td colspan='2'><strong><?php esc_html_e('Entry ID', 'metform'); ?></strong></td> </tr> <tr class='mf-data-value'> <td> <?php $metform_entries_serial_no = get_post_meta($post->ID, 'metform_entries_serial_no', true); echo esc_html(isset($metform_entries_serial_no)? $metform_entries_serial_no : ''); ?> </td> </tr> <tr class="mf-data-label"> <td colspan='2'><strong><?php esc_html_e('Entry By', 'metform'); ?></strong></td> </tr> <tr class='mf-data-value'> <td> <?php $logged_user_id = get_post_meta($post->ID, 'metform_entries__user_id', true); if($logged_user_id){ $author_obj = get_user_by('id', $logged_user_id); $profile_link = "<a href='". wp_nonce_url(admin_url()."/user-edit.php?user_id={$logged_user_id}")."'> {$author_obj->data->user_login} </a>"; echo wp_kses($profile_link, array('a' => ['href'=>[]])); }else{ echo esc_html__("Visitor", "metform"); } ?> </td> </tr> </tbody> </table> </div> <?php } function add_form_data_cmb() { // Get the form settings data //phpcs:ignore WordPress.Security.NonceVerification -- Nonce can't be added in CPT edit page URL $post_id = isset($_GET['post']) ? sanitize_text_field(wp_unslash($_GET['post'])) : ''; $form_id = get_post_meta($post_id, 'metform_entries__form_id', true); $form_settings = \MetForm\Core\Forms\Action::instance()->get_all_data($form_id); // Change the form entries main title based on the form type $data_title = esc_html__('Data', 'metform'); if(isset($form_settings['form_type']) && $form_settings['form_type'] == 'quiz-form'){ $data_title = esc_html__('Quiz Data', 'metform'); } add_meta_box( 'metform_entries__form_data', $data_title, [$this, 'show_form_data_cmb'], $this->cpt->get_name(), 'normal', 'high' ); } function add_browser_data_cmb() { // call browser data meta when browser data present //phpcs:ignore WordPress.Security.NonceVerification -- Nonce can't be added in CPT edit page URL $post_id = (isset($_GET['post']) ? sanitize_text_field(wp_unslash($_GET['post'])) : ''); $form_id = get_post_meta($post_id, 'metform_entries__form_id', true); $form_settings = \MetForm\Core\Forms\Action::instance()->get_all_data($form_id); $this->browser_data = get_post_meta($post_id, 'metform_form__entry_browser_data', true); if ($this->browser_data == '' && !isset($form_settings['capture_user_browser_data'])) { return; } add_meta_box( 'metform_form__entry_browser_data', esc_html__('Browser Data', 'metform'), [$this, 'show_browser_data_cmb'], $this->cpt->get_name(), 'side', 'low' ); } function show_browser_data_cmb($post) { if ($this->browser_data != '') { ?> <div class="metform-entry-data container"> <table class='mf-entry-data' cellpadding="5" cellspacing="0"> <?php foreach ($this->browser_data as $key => $value) { ?> <tbody> <tr class="mf-data-label"> <td colspan='2'><strong><?php echo esc_attr($key); ?></strong></td> </tr> <tr class='mf-data-value'> <td><?php echo esc_attr($value); ?></td> </tr> </tbody> <?php } ?> </table> </div> <?php } else { echo esc_html__('Browser data not captured.', 'metform'); } } function add_file_upload_cmb() { // call file meta when file data present //phpcs:ignore WordPress.Security.NonceVerification -- Nonce can't be added in CPT edit page URL $post_id = (isset($_GET['post']) ? sanitize_text_field(wp_unslash($_GET['post'])) : ''); $file_meta_data = get_post_meta($post_id, 'metform_entries__file_upload', true); $file_meta_data_new = get_post_meta($post_id, 'metform_entries__file_upload_new', true); if(is_array($file_meta_data) || is_array($file_meta_data_new)){ add_meta_box( 'metform_entries__file_upload', esc_html__('Files', 'metform'), [$this, 'show_file_upload_cmb'], $this->cpt->get_name(), 'normal', 'low' ); } } function show_form_data_cmb($post) { wp_nonce_field('meta_nonce', 'meta_nonce'); $this->form_data = get_post_meta($post->ID, 'metform_entries__form_data', true); $this->form_data = (isset($this->form_data)) ? $this->form_data : ""; // format all form data into html table if ($this->form_data != '') { $form_html = \MetForm\Core\Entries\Form_Data::format_form_data($this->form_id, $this->form_data); \MetForm\Utils\Util::metform_content_renderer($form_html); } } function show_file_upload_cmb($post) { // call file meta when file data present //phpcs:ignore WordPress.Security.NonceVerification -- Nonce can't be added in CPT edit page URL $post_id = (isset($_GET['post']) ? sanitize_text_field(wp_unslash($_GET['post'])) : ''); $file_meta_data = get_post_meta($post_id, 'metform_entries__file_upload', true); if (!is_array($file_meta_data)) { $file_meta_data = get_post_meta($post_id, 'metform_entries__file_upload_new', true); if(!is_array($file_meta_data)) { return; } else { foreach($file_meta_data as $key => $value) { if(!empty($value)) { $this->show_file($value, $key); } } } } else { $this->show_file($file_meta_data); } } public function show_file($files, $name = false) { echo '<ul>'; if($name) { echo '<li>'; echo esc_html(((isset($this->fields[$name]->mf_input_label)) ? $this->fields[$name]->mf_input_label : $name) . " : "); echo '</li><ul style="padding-left:15px;">'; } foreach($files as $key => $file) { if(is_null($name)) { $name = $key; } echo "<li><i class='mf mf-file-2'></i>"; $file_url = isset($file['url']) ? $file['url'] : ''; $file_type = isset($file['type']) ? $file['type'] : ''; if ($file_url != '') { if(!$name) { echo esc_html(((isset($this->fields[$key]->mf_input_label)) ? $this->fields[$key]->mf_input_label : $key+1) . " : "); } echo "<a target='_blank' class='mf-file-url' href=" . esc_url($file_url) . " download>" . esc_html__('Download', 'metform') . "</a>"; echo((in_array($file_type, ['image/jpeg', 'image/png', 'image/jpg', 'image/gif', 'image/ico'])) ? ' | <a href="#" class="" data-toggle="modal" data-target="#mfFileUploadModal' . esc_attr($name . $key) . '">' . esc_html__('View', 'metform') . '</a>' : ''); } else { echo esc_html(((isset($this->fields[$name]->mf_input_label)) ? $this->fields[$name]->mf_input_label : $key) . " : ") . esc_html__('This file is not uploaded.', 'metform'); } echo "</li>"; $this->file_modal($name.$key, $file_url); } echo '</ul></ul>'; } public function file_modal($key, $file_url) { ?> <div class="attr-modal attr-fade mf-modal-container" id="mfFileUploadModal<?php echo esc_attr($key) ?>" tabindex="-1" role="dialog" aria-labelledby="mfFileUploadodalMLabel" aria-hidden="true"> <div class="attr-modal-dialog" role="document"> <div class="attr-modal-content"> <div class="attr-modal-header"> <button type="button" class="attr-close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="attr-modal-body"> <img class="attr-img-responsive" src="<?php echo esc_url($file_url); ?>"> </div> </div> </div> </div> <?php } function store_form_data_cmb($post_id) { // add save code here } function add_woo_payment_status_cmb() { add_meta_box( 'metform_entries__woo_checkout_status', esc_html__('Woocommerce Checkout', 'metform'), [$this, 'show_woo_checkout_status_cmb'], $this->cpt->get_name(), 'side', 'high' ); } function show_woo_checkout_status_cmb($post) { $order_id = get_post_meta($post->ID, 'mf_woo_order_id', true); if($order_id == null) { return; } $order = wc_get_order($order_id); $order_url = get_admin_url() . 'post.php?post=' . $order_id . '&action=edit'; ?> <div class="metform-entry-data container"> <table class='mf-entry-data' cellpadding="5" cellspacing="0"> <tbody> <tr class="mf-data-label"> <td colspan='2'><strong><?php esc_html_e('Order ID ', 'metform'); ?></strong></td> </tr> <tr class='mf-data-value'> <td><?php echo esc_attr($order_id); ?></td> </tr> <tr class="mf-data-label"> <td colspan='2'><strong><?php esc_html_e('Order Status', 'metform'); ?></strong></td> </tr> <tr class='mf-data-value'> <td><?php echo esc_attr($order->get_status()); ?></td> </tr> <tr class="mf-data-label"> <td colspan='2'><strong><?php esc_html_e('Total', 'metform'); ?></strong></td> </tr> <tr class='mf-data-value'> <td><?php echo esc_attr($order->get_total() . ' ' . $order->get_currency()); ?></td> </tr> <tr class="mf-data-label"> </tr> <tr class='mf-data-value'> <td><a class="button" href="<?php echo esc_url($order_url); ?>" target="__blank"><?php echo esc_html__('Order Details', 'metform'); ?></a></td> </tr> </tbody> </table> </div> <?php } function add_form_payment_status_cmb() { add_meta_box( 'metform_entries__payment_status', esc_html__('Payment', 'metform'), [$this, 'show_form_payment_status_cmb'], $this->cpt->get_name(), 'side', 'high' ); } function show_form_payment_status_cmb($post) { echo "Status : " . esc_html(get_post_meta($post->ID, 'metform_entries__payment_status', true)) . "<br>"; if (get_post_meta($post->ID, 'metform_entries__payment_invoice', true)) { echo "Invoice : "; echo esc_html(get_post_meta($post->ID, 'metform_entries__payment_invoice', true)) . "<br>"; } } } api.php 0000666 00000012671 15165335044 0006047 0 ustar 00 <?php namespace MetForm\Core\Entries; use MetForm\Core\Integrations\Get_Response; use MetForm\Core\Integrations\Mail_Chimp; defined('ABSPATH') || exit; class Api extends \MetForm\Base\Api { public function config() { $this->prefix = 'entries'; $this->param = "/(?P<id>\w+)"; } public function post_insert() { $url = wp_get_referer(); $post_id = url_to_postid($url); $post_id; $id = $this->request['id']; $form_data = $this->request->get_params(); $file_data = $this->request->get_file_params(); return Action::instance()->submit($id, $form_data, $file_data,$post_id); } public function get_export() { if(!current_user_can('manage_options')) { return; } $id = $this->request['id']; return Export::instance()->export_data($id); } public function get_get_response_list_id() { if(!current_user_can('manage_options')) { return; } $post_id = $this->request['id']; return get_option('wpmet_get_response_list_' . $post_id); } public function get_paypal() { $args = [ 'method' => (isset($this->request['action']) ? $this->request['action'] : ''), 'action' => (isset($this->request['id']) ? $this->request['id'] : ''), 'entry_id' => (isset($this->request['entry_id']) ? $this->request['entry_id'] : ''), ]; if (class_exists('\MetForm_Pro\Core\Integrations\Payment\Paypal')) { return \MetForm_Pro\Core\Integrations\Payment\Paypal::instance()->init($args, $this->request); } return 'Pro needed'; } public function get_stripe() { $args = [ 'method' => (isset($this->request['action']) ? $this->request['action'] : ''), 'action' => (isset($this->request['id']) ? $this->request['id'] : ''), 'entry_id' => (isset($this->request['entry_id']) ? $this->request['entry_id'] : ''), 'token' => (isset($this->request['token']) ? $this->request['token'] : ''), ]; if (class_exists('\MetForm_Pro\Core\Integrations\Payment\Stripe')) { return \MetForm_Pro\Core\Integrations\Payment\Stripe::instance()->init($args); } return 'Pro needed'; } public function get_views() { return $this->request->get_params(); } public function get_get_response_list() { if(!current_user_can('manage_options')) { return; } $post_id = $this->request['id']; return get_option('wpmet_get_response_list_' . $post_id); } public function get_store_get_response_list() { if(!current_user_can('manage_options')) { return; } if (class_exists('\MetForm_Pro\Core\Integrations\Email\Getresponse\Get_Response')) { $post_id = $this->request['id']; $data = \MetForm\Core\Forms\Action::instance()->get_all_data($post_id); $api_key = isset($data['mf_get_reponse_api_key']) ? $data['mf_get_reponse_api_key'] : null; $get_response_list = \MetForm_Pro\Core\Integrations\Email\Getresponse\Get_Response::get_list($api_key); delete_option('wpmet_get_response_list_' . $post_id, $get_response_list); update_option('wpmet_get_response_list_' . $post_id, $get_response_list); return get_option('wpmet_get_response_list_' . $post_id); } return 'error'; } public function get_get_mailchimp_list() { if(!current_user_can('manage_options')) { return; } $post_id = $this->request['id']; return get_option('wpmet_get_mailchimp_list_' . $post_id); } public function get_store_mailchimp_list() { if(!current_user_can('manage_options')) { return; } $post_id = $this->request['id']; $data = \MetForm\Core\Forms\Action::instance()->get_all_data($post_id); $api_key = $data['mf_mailchimp_api_key']; $mailChimp_list = json_decode(Mail_Chimp::get_list($api_key)['body']); delete_option('wpmet_get_mailchimp_list_' . $post_id, $mailChimp_list); update_option('wpmet_get_mailchimp_list_' . $post_id, $mailChimp_list); return get_option('wpmet_get_mailchimp_list_' . $post_id, $mailChimp_list); } public function get_google_spreadsheet_list() { if(!current_user_can('manage_options')) { return; } if (!class_exists('\MetForm_Pro\Core\Integrations\Google_Sheet\WF_Google_Sheet')) { return 'Pro needed'; } $google = new \MetForm_Pro\Core\Integrations\Google_Sheet\WF_Google_Sheet; $response = $google->get_all_spreadsheets(); return $response ; } public function get_google_sheet_list() { if(!current_user_can('manage_options')) { return; } if (!class_exists('\MetForm_Pro\Core\Integrations\Google_Sheet\WF_Google_Sheet')) { return 'Pro needed'; } // $spreadsheetID = $this->request['spreadsheetID']; $sheetID = $this->request['sheetID']; $google = new \MetForm_Pro\Core\Integrations\Google_Sheet\WF_Google_Sheet; $response = $google->get_sheets_details_from_spreadsheet($sheetID); return $response ; } } cpt.php 0000666 00000007361 15165335044 0006064 0 ustar 00 <?php namespace MetForm\Core\Entries; defined( 'ABSPATH' ) || exit; Class Cpt extends \MetForm\Base\Cpt { public function get_name(){ return 'metform-entry'; } public function post_type() { $labels = array( 'name' => esc_html_x( 'Entries', 'Post Type General Name', 'metform' ), 'singular_name' => esc_html_x( 'Entry', 'Post Type Singular Name', 'metform' ), 'menu_name' => esc_html__( 'Entry', 'metform' ), 'name_admin_bar' => esc_html__( 'Entry', 'metform' ), 'archives' => esc_html__( 'Entry Archives', 'metform' ), 'attributes' => esc_html__( 'Entry Attributes', 'metform' ), 'parent_item_colon' => esc_html__( 'Parent Item:', 'metform' ), 'all_items' => esc_html__( 'Entries', 'metform' ), 'add_new_item' => esc_html__( 'Add New Item', 'metform' ), 'add_new' => esc_html__( 'Add New', 'metform' ), 'new_item' => esc_html__( 'New Item', 'metform' ), 'edit_item' => esc_html__( 'Edit Item', 'metform' ), 'update_item' => esc_html__( 'Update Item', 'metform' ), 'view_item' => esc_html__( 'View Item', 'metform' ), 'view_items' => esc_html__( 'View Items', 'metform' ), 'search_items' => esc_html__( 'Search Item', 'metform' ), 'not_found' => esc_html__( 'Not found', 'metform' ), 'not_found_in_trash' => esc_html__( 'Not found in Trash', 'metform' ), 'featured_image' => esc_html__( 'Featured Image', 'metform' ), 'set_featured_image' => esc_html__( 'Set featured image', 'metform' ), 'remove_featured_image' => esc_html__( 'Remove featured image', 'metform' ), 'use_featured_image' => esc_html__( 'Use as featured image', 'metform' ), 'insert_into_item' => esc_html__( 'Insert into item', 'metform' ), 'uploaded_to_this_item' => esc_html__( 'Uploaded to this item', 'metform' ), 'items_list' => esc_html__( 'Form entries list', 'metform' ), 'items_list_navigation' => esc_html__( 'Form entries list navigation', 'metform' ), 'filter_items_list' => esc_html__( 'Filter from entry list', 'metform' ), ); $args = array( 'label' => esc_html__( 'Form entry', 'metform' ), 'description' => esc_html__( 'metform-entry', 'metform' ), 'labels' => $labels, 'supports' => ['title'], 'capabilities' => ['create_posts' => 'do_not_allow'], 'map_meta_cap' => true, 'hierarchical' => false, 'public' => false, 'show_ui' => true, 'show_in_menu' => "metform-menu", 'menu_icon' => 'dashicons-format-aside', 'menu_position' => 5, 'show_in_admin_bar' => false, 'show_in_nav_menus' => false, 'can_export' => true, 'has_archive' => false, 'publicly_queryable' => false, 'rewrite' => false, 'query_var' => true, 'exclude_from_search' => true, 'capability_type' => 'page', 'show_in_rest' => true, 'rest_base' => $this->get_name(), ); return $args; } } export.php 0000666 00000011755 15165335044 0006621 0 ustar 00 <?php namespace MetForm\Core\Entries; use MetForm\Traits\Singleton; defined('ABSPATH') || exit; class Export { use Singleton; public function export_data($form_id) { if (!current_user_can('manage_options')) { return; } $fields = Action::instance()->get_fields($form_id); $title = get_the_title($form_id); global $wpdb; $entries = $wpdb->get_results($wpdb->prepare("SELECT `post_id` FROM `" . $wpdb->prefix . "postmeta` WHERE `meta_key` = 'metform_entries__form_id' AND `meta_value` = %d", $form_id), OBJECT); $entries = (is_array($entries)) ? $entries : []; $export = []; $header = []; foreach ($entries as $entry) { $entry_modify = []; $form_entry = get_post_meta($entry->post_id, 'metform_entries__form_data', true); $form_entry = (is_array($form_entry) ? $form_entry : []); $file_entry = get_post_meta($entry->post_id, 'metform_entries__file_upload_new', true); $file_entry = (is_array($file_entry) ? $file_entry : []); $entry_data = array_merge($form_entry, $file_entry); $entry_data = (is_array($entry_data)) ? $entry_data : []; $entry_modify['ID'] = $entry->post_id; $header['__id'] = 'ID'; foreach ($fields as $key => $value) { $header_key = (($value->mf_input_name != '') ? htmlspecialchars($value->mf_input_name) : $key); $header[$header_key] = empty($value->mf_input_label) ? $key : htmlspecialchars($value->mf_input_label); if ($value->widgetType == 'mf-file-upload' && isset($entry_data[$key])) { $entry_modify[$header_key] = (isset($entry_data[$key]) ? ((isset($entry_data[$key]['url'])) ? $entry_data[$key]['url'] : ' ') : ' '); for ($index = 0; $index < isset( $entry_data[$key] ) && is_array($entry_data[$key]) ? count($entry_data[$key]) : 0 ; $index++) { $entry_modify[$header_key] .= (esc_url($entry_data[$key][$index]['url']) . " \n"); } } else if ($value->widgetType == 'mf-simple-repeater') { $data_string = ''; if (is_array($entry_data[$key])) { foreach ($entry_data[$key] as $key => $value) { $data_string .= htmlspecialchars($key) . ": " . htmlspecialchars($value) . " \n"; } } $entry_modify[$header_key] = $data_string; } else { $entry_modify[$header_key] = (isset($entry_data[$key]) ? ((is_array($entry_data[$key])) ? implode(', ', $entry_data[$key]) : ($entry_data[$key])) : ' '); } // Prevent CSV injection by prefixing a single quote to values that begin with '=', '+', '-', '@' if (preg_match('/^(\=|\+|\-|\@)/', $entry_modify[$header_key])) { $entry_modify[$header_key] = "'" . ltrim($entry_modify[$header_key], '='); // ltrim remove the equal sign from the formula `=HYPERLINK()` will be `HYPERLINK()` } } $entry_modify['DATE'] = get_the_date('d-m-Y', $entry->post_id); $export[] = $entry_modify; $header['__dt'] = 'DATE'; } $file_name = $title . "-export-" . time() . ".csv"; // Sanitize the file name to prevent directory traversal $file_name = sanitize_file_name($file_name); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header('Content-Description: File Transfer'); header("Content-type: text/csv"); // Sanitize the file name to prevent CSV injection header("Content-Disposition: attachment; filename=\"" . str_replace(array('"', "'", "\\", "\0"), '', $file_name) . "\""); header("Expires: 0"); header("Pragma: public"); $file_pointer = @fopen('php://output', 'w'); $csv_header = false; // sort data usort($export, function ($item1, $item2) { return $item1['ID'] <=> $item2['ID']; }); foreach ($export as $data) { // Add a header row if it hasn't been added yet if (!$csv_header) { // Use the keys from $data as the titles // Sanitize the header row to prevent CSV injection fputcsv($file_pointer, array_map(function ($value) { return str_replace(array('"', "'", "\\", "\0"), '', $value); }, $header)); $csv_header = true; } // Sanitize the data to prevent CSV injection $sanitized_data = array_map(function ($value) { return str_replace(array('"', "'", "\\", "\0"), '', $value); }, $data); // Put the sanitized data into the stream fputcsv($file_pointer, $sanitized_data); } // Close the file fclose($file_pointer); exit; } } base.php 0000666 00000000571 15165335044 0006204 0 ustar 00 <?php namespace MetForm\Core\Entries; defined( 'ABSPATH' ) || exit; Class Base{ use \MetForm\Traits\Singleton; public $cpt; public $api; public $meta_data; public function __construct(){ Hooks::instance(); $this->cpt = new Cpt(); $this->api = new Api(); $this->meta_data = new Meta_Data(); } } form-data.php 0000666 00000064574 15165335044 0007161 0 ustar 00 <?php namespace MetForm\Core\Entries; defined('ABSPATH') || exit; class Form_Data { private static $form_data = null; private static function get_form_data($form_id) { if (static::$form_data) { return static::$form_data; } $map_data = \MetForm\Core\Entries\Action::instance()->get_fields($form_id); return static::$form_data = json_decode(json_encode($map_data), true); } protected static function criteriaMet($conditional_value, $conditional_operator, $conditional_field_value) { switch ($conditional_operator) { case '<': return $conditional_value < $conditional_field_value; case '<=': return $conditional_value <= $conditional_field_value; case '>': return $conditional_value > $conditional_field_value; case '>=': return $conditional_value >= $conditional_field_value; case '==': return $conditional_value == $conditional_field_value; case '!=': return $conditional_value != $conditional_field_value; case 'empty': return empty($conditional_value); case 'not-empty': return !empty($conditional_value); default: return false; } } public static function format_form_data($form_id, $form_data) { $map_data = static::get_form_data($form_id); $form_settings = \MetForm\Core\Forms\Action::instance()->get_all_data($form_id); ob_start(); ?> <div class="metform-entry-data container"> <table class='mf-entry-data' style="word-break: break-all;" cellpadding="5" cellspacing="0"> <tbody> <?php foreach ($map_data as $key => $value) { if (in_array($value['widgetType'], ['mf-simple-captcha', 'mf-recaptcha', 'mf-file-upload'])) { continue; } $conditions = isset($map_data[$key]["mf_conditional_logic_form_list"]) ? $map_data[$key]["mf_conditional_logic_form_list"] : []; $no_of_condition = count($conditions); $checking_result = array(); $condition_match_criteria = !empty($map_data[$key]["mf_conditional_logic_form_and_or_operators"]) ? $map_data[$key]["mf_conditional_logic_form_and_or_operators"] : ''; list($map_data, $form_data, $checking_result) = self::condition_criteria_match($map_data, $key, $conditions, $form_data, $checking_result); if ($no_of_condition > 1 && $condition_match_criteria == "or") { if (!in_array(true, $checking_result)) { continue; } } else { if (in_array(false, $checking_result)) { continue; } } echo "<tr class='mf-data-label'>"; echo "<td colspan='2'><strong>" . esc_html(($map_data[$key]['mf_input_label'] != '') ? $map_data[$key]['mf_input_label'] : $key) . "</strong></td>"; echo "</tr>"; $entriy_row_correct_class = ''; if(isset($form_settings['form_type']) && $form_settings['form_type'] === 'quiz-form' && isset($form_data['wrong-answer']) && isset($form_data['right-answer'])){ $wrong_answers = explode(",", $form_data['wrong-answer']); $right_answers = explode(",", $form_data['right-answer']); // Find thefield if it exists in the right answers array if(in_array($map_data[$key]['mf_input_name'], $right_answers)){ $entriy_row_correct_class = 'mf_correct_result'; } elseif( in_array($map_data[$key]['mf_input_name'], $wrong_answers) ){ $entriy_row_correct_class = 'mf_wrong_result'; } } echo sprintf("<tr class='mf-data-value %s'>", esc_attr($entriy_row_correct_class)); echo "<td class='mf-value-space'> </td>"; if (!in_array($value['widgetType'], ['mf-file-upload', 'mf-textarea', 'mf-simple-repeater', 'mf-signature', 'mf-like-dislike', 'mf-credit-card','mf-image-select','mf-checkbox','mf-mobile'])) { $label = isset($map_data[$key]['mf_input_label']) ? $map_data[$key]['mf_input_label'] : ''; if ($label && isset($map_data[$key]['mf_input_list']) && is_array($map_data[$key]['mf_input_list']) && isset($form_settings['mf_field_name_show'] ) && $form_settings['mf_field_name_show'] == 1) { $selected_values = isset($form_data[$key]) ? explode(',', $form_data[$key]) : array(); $values = array(); foreach ($map_data[$key]['mf_input_list'] as $item) { // Check if 'label' key exists in the item if ( isset($item['label']) && in_array($item['value'], $selected_values) ) { $values[$item['label']] = $item['label'] . ' - ' . $item['value']; } if ( isset($item['mf_input_option_text']) && isset($item['mf_input_option_value']) && $item['mf_input_option_value'] == $form_data[$key] ) { $option_text = $item['mf_input_option_text'] .' - '. $item['mf_input_option_value'] ; } } $result = implode(', ', $values); if(!empty($result)){ echo "<td>" . esc_html($result) . "</td>"; }else{ echo "<td>" . esc_html( $option_text ) . "</td>"; } } else if(isset($value['widgetType']) && $value['widgetType'] == 'mf-text-editor') { echo "<td>" . wp_kses_post($form_data[$key]) . "</td>"; }else{ $output = isset($form_data[$key]) ? (is_array($form_data[$key]) ? implode(', ', $form_data[$key]) : $form_data[$key]) : ''; echo "<td>" . esc_html($output) . "</td>"; } } if (isset($value['widgetType']) && $value['widgetType'] == 'mf-mobile') { $output = isset($form_data[$key]) && !empty($form_data[$key]) ? '+' . esc_html($form_data[$key]) : ''; echo "<td>" . $output . "</td>"; } if (isset($value['widgetType']) && $value['widgetType'] == 'mf-checkbox') { $label = isset($map_data[$key]['mf_input_label']) ? $map_data[$key]['mf_input_label'] : ''; if ($label && isset($map_data[$key]['mf_input_list']) && is_array($map_data[$key]['mf_input_list']) && isset($form_settings['mf_field_name_show']) && $form_settings['mf_field_name_show'] == 1) { $selected_values = isset($form_data[$key]) ? explode(',', $form_data[$key]) : array(); $values = array(); foreach ($map_data[$key]['mf_input_list'] as $item) { if (isset($item['mf_input_option_text']) && in_array($item['mf_input_option_value'], $selected_values)) { $values[$item['mf_input_option_text']] = $item['mf_input_option_text'] . ' - ' . $item['mf_input_option_value']; } } $result = implode(', ', $values); if (!empty($result)) { echo "<td>" . esc_html($result) . "</td>"; } } else { $output = isset($form_data[$key]) ? (is_array($form_data[$key]) ? implode(', ', $form_data[$key]) : $form_data[$key]) : ''; echo "<td>" . esc_html($output) . "</td>"; } } if (isset($value['widgetType']) && $value['widgetType'] == 'mf-image-select') { $selected_value = isset($form_data[$key]) ? $form_data[$key] : ''; $option_text = ''; $option_value = ''; foreach ($map_data[$key]['mf_input_list'] as $item) { if (isset($item['mf_input_option_value']) && $item['mf_input_option_value'] == $selected_value ) { if (isset($item['mf_image_select_title']) && $item['mf_image_select_title'] !== '') { // If mf_image_select_title is not empty, use it in the option text. $option_text = $item['mf_image_select_title'] . ' - ' . $item['mf_input_option_value']; } else { // If mf_image_select_title is empty, use mf_input_option_value. $option_text = $item['mf_input_option_value']; } $option_value = $item['mf_input_option_value']; } } if (isset($form_settings['mf_field_name_show']) && $form_settings['mf_field_name_show'] == 1) { echo "<td>" . esc_html($option_text) . "</td>"; } else { echo "<td>" . esc_html($option_value) . "</td>"; } } if (isset($value['widgetType']) && $value['widgetType'] == 'mf-signature') { echo "<td><img class='signature-img' src='" . esc_attr(isset($form_data[$key]) ? $form_data[$key] : '') . "'></td>"; } if (isset($value['widgetType']) && $value['widgetType'] == 'mf-textarea') { echo "<td>" . wp_kses( isset($form_data[$key]) ? nl2br( $form_data[$key] ) : '', [ 'br' => [] ]) . "</td>"; } if (isset($value['widgetType']) && $value['widgetType'] == 'mf-simple-repeater') { echo "<td>"; $repeater_data = ((array_key_exists($key, $form_data)) ? $form_data[$key] : []); $count_index = 0; // number of repeater input field counter $previous_level = null; foreach ($repeater_data as $k => $v) { $repeater_level = null; if ((isset($map_data[$key]["mf_input_repeater"][$count_index]["mf_input_repeater_label"]))) { $repeater_level = $map_data[$key]["mf_input_repeater"][$count_index]["mf_input_repeater_label"]; } if ((isset($map_data[$key]["mf_input_repeater"][$count_index - 1]["mf_input_repeater_label"]))) { $previous_level = $map_data[$key]["mf_input_repeater"][$count_index - 1]["mf_input_repeater_label"]; } if ($repeater_level == null && $previous_level != null) { $repeater_level = $previous_level; } echo "<strong>" . esc_html(($repeater_level != null) ? $repeater_level : $k) . ": </strong>"; if ($repeater_level && isset($map_data[$key]["mf_input_repeater"][$count_index]["mf_input_repeater_option"]) && isset($form_settings['mf_field_name_show']) && $form_settings['mf_field_name_show'] == 1) { $options = explode("\n", $map_data[$key]["mf_input_repeater"][$count_index]["mf_input_repeater_option"]); $optionOutput = []; $selected_options = explode(',', $v); foreach ($options as $option) { list($optionName, $optionValue) = explode('|', $option); if (in_array($optionValue, $selected_options)) { $optionOutput[] = "$optionName - $optionValue"; } } echo wp_kses_post("<span>" . implode(", ", $optionOutput) . "</span>"); } else { echo wp_kses_post("<span>" . esc_html($v) . "</span>"); } echo "<br>"; $count_index++; if ($count_index == count($map_data[$key]["mf_input_repeater"])) { $count_index = 0; echo "<div class='simple-repeater-entry-data-divider'></div>"; } } echo "</td>"; } /** * Credit Card form data entries */ if (isset($value['widgetType']) && $value['widgetType'] == 'mf-credit-card') { echo "<td><strong>". esc_html__('Number:', 'metform') ."</strong> " . esc_html(isset($form_data[$key]) ? $form_data[$key] : '') . "</br>"; if (isset($form_data[$key . '--type'])) { $type = $form_data[$key . '--type']; $type = ($type === "amex") ? 'Amerian Express' : $type; echo "<strong>".esc_html__('Type:', 'metform')."</strong> " . esc_html(ucfirst($type)) . " Card</td>"; } } if (isset($value['widgetType']) && ($value['widgetType'] == 'mf-like-dislike')) { $like_dislike = (isset($form_data[$key]) ? $form_data[$key] : ''); echo "<td>"; echo (($like_dislike == '1') ? "<span class='dashicons dashicons-thumbs-up'></span>" : ""); echo (($like_dislike == '0') ? "<span class='dashicons dashicons-thumbs-down'></span>" : ""); echo "</td>"; } echo "</tr>"; } ?> <?php do_action('metform_after_entries_table_data', $form_id, $form_data, $map_data); ?> </tbody> </table> </div> <?php $data_html = ob_get_contents(); ob_end_clean(); return $data_html; } public static function format_data_for_mail($form_id, $form_data, $file_info) { $map_data = static::get_form_data($form_id); //$file_meta_data = get_post_meta( $post_id, 'metform_entries__file_upload', true ); ob_start(); ?> <div style="border-left:5px solid #2EB5AB;padding-left:5px;"> <table width="100%" cellpadding="5" cellspacing="0" bgcolor="#FFFFFF" style="border: 1px solid #EAF2FA; word-break: break-word;"> <tbody> <?php foreach ($map_data as $key => $value) { if (in_array($value['widgetType'], ['mf-simple-captcha', 'mf-recaptcha', 'mf-file-upload', 'mf-button'])) { continue; } $conditions = isset($map_data[$key]["mf_conditional_logic_form_list"]) ? $map_data[$key]["mf_conditional_logic_form_list"] : []; $no_of_condition = count($conditions); $checking_result = array(); $condition_match_criteria = !empty($map_data[$key]["mf_conditional_logic_form_and_or_operators"]) ? $map_data[$key]["mf_conditional_logic_form_and_or_operators"] : ''; list($map_data, $form_data, $checking_result) = self::condition_criteria_match($map_data, $key, $conditions, $form_data, $checking_result); if ($no_of_condition > 1 && $condition_match_criteria == "or") { if (!in_array(true, $checking_result)) { continue; } } else { if (in_array(false, $checking_result)) { continue; } } echo "<tr bgcolor='#EAF2FA'>"; echo "<td colspan='2'><strong>" . esc_html(($map_data[$key]['mf_input_label'] != '') ? $map_data[$key]['mf_input_label'] : $key) . "</strong></td>"; echo "</tr>"; echo "<tr bgcolor='#FFFFFF'>"; echo "<td width='20'> </td>"; if (!in_array($value['widgetType'], ['mf-file-upload', 'mf-textarea', 'mf-simple-repeater', 'mf-signature', 'mf-credit-card'])) { echo "<td>" . esc_html((array_key_exists($key, $form_data) ? ((is_array($form_data[$key])) ? implode(', ', $form_data[$key]) : $form_data[$key]) : ' ')) . "</td>"; } if (isset($value['widgetType']) && $value['widgetType'] == 'mf-textarea') { echo "<td><pre style='font:inherit;margin:0;'>" . esc_html(isset($form_data[$key]) ? $form_data[$key] : '') . "</pre></td>"; } if (isset($value['widgetType']) && $value['widgetType'] == 'mf-signature') { echo "<td><img width='200' height='100' src='" . esc_attr(isset($form_data[$key]) ? $form_data[$key] : '') . "'></td>"; } if (isset($value['widgetType']) && $value['widgetType'] == 'mf-simple-repeater') { echo "<td>"; $repeater_data = ((array_key_exists($key, $form_data)) ? $form_data[$key] : []); // counter and variables $count_index = 0 ; // number of repeter input field counter $previous_level = null; foreach ($repeater_data as $k => $v) { $repeter_level = null; if((isset($map_data[$key]["mf_input_repeater"][$count_index]["mf_input_repeater_label"]))){ $repeter_level = $map_data[$key]["mf_input_repeater"][$count_index]["mf_input_repeater_label"]; } if((isset($map_data[$key]["mf_input_repeater"][$count_index-1]["mf_input_repeater_label"]))){ // store previous level $previous_level = $map_data[$key]["mf_input_repeater"][$count_index-1]["mf_input_repeater_label"]; } if($repeter_level == null && $previous_level != null){ // repeter level empty then set previous level to repeter level $repeter_level = $previous_level; } echo "<strong>" . esc_html( ($repeter_level != null)? $repeter_level : $k) . ": </strong>"; echo "<span>" . esc_html($v) . "</span>"; echo "<br>"; $count_index ++; if($count_index == count($map_data[$key]["mf_input_repeater"])){ // repeter input field count exceed count_index repeter has repetition set count_index 0 $count_index = 0; echo "<div class='simple-repeater-entry-data-divider'></div>"; } } echo "</td>"; } /** * Credit Card form data entries */ if (isset($value['widgetType']) && $value['widgetType'] == 'mf-credit-card') { echo "<td><strong>". esc_html__('Number:', 'metform') ."</strong> " . esc_html(isset($form_data[$key]) ? $form_data[$key] : '') . "</br>"; if (isset($form_data[$key . '--type'])) { $type = $form_data[$key . '--type']; $type = ($type === "amex") ? 'Amerian Express' : $type; echo "<strong>".esc_html__('Type:', 'metform')."</strong> " . esc_html(ucfirst($type)) . " Card</td>"; } } echo "</tr>"; } if (!empty($file_info)) { foreach ($file_info as $key => $file) { echo "<tr bgcolor='#EAF2FA'>"; echo "<td colspan='2'><strong>" . esc_html(($map_data[$key]['mf_input_label'] != '') ? $map_data[$key]['mf_input_label'] : $key) . "</strong></td>"; echo "</tr>"; echo "<tr bgcolor='#FFFFFF'>"; echo "<td width='20'> </td>"; echo "<td>"; foreach($file as $value) { echo "<a href='" . esc_url(isset($value['url']) ? $value['url'] : '') . "'>".esc_html__('Download', 'metform')."</a> "; } echo "</td>"; echo "</tr>"; } } ?> </tbody> </table> </div> <?php $data_html = ob_get_contents(); ob_end_clean(); return $data_html; } /** * @param mixed $map_data * @param int|string $key * @param mixed $conditions * @param $form_data * @param array $checking_result * @return array */ public static function condition_criteria_match($map_data, $key, $conditions, $form_data, $checking_result) { if (!empty($map_data[$key]["mf_conditional_logic_form_enable"]) && $map_data[$key]["mf_conditional_logic_form_enable"] == "yes") { foreach ($conditions as $key=> $condition) { $conditional_field_name = !empty($condition["mf_conditional_logic_form_if"]) ? $condition["mf_conditional_logic_form_if"] : ''; $conditional_operator = !empty($condition["mf_conditional_logic_form_comparison_operators"]) ? $condition["mf_conditional_logic_form_comparison_operators"] : 'not-empty'; // operator value not-empty hole backend theke data ase na tai not-empty default vabe dewa hoise.. // if condition logic change after submission previous entries condition also change. $conditional_field_value = !empty($condition["mf_conditional_logic_form_value"]) ? $condition["mf_conditional_logic_form_value"] : ''; $conditional_value_data = !empty($form_data[$conditional_field_name]) ? $form_data[$conditional_field_name] : ''; $condition_value_array = explode(",",$conditional_value_data); $condition_value_index = array_search($conditional_field_value, $condition_value_array); $conditional_value = isset($condition_value_array[$condition_value_index])? $condition_value_array[$condition_value_index] : ""; $criteria_match = static::criteriaMet($conditional_value, $conditional_operator, $conditional_field_value); array_push($checking_result, $criteria_match); } } return array($map_data, $form_data, $checking_result); } }
| ver. 1.4 |
Github
|
.
| PHP 5.4.45 | Generation time: 0 |
proxy
|
phpinfo
|
Settings