| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * Plugin Name: Contact Form Entries |
|---|
| 4 | * Description: Save form submissions to the database from <a href="https://wordpress.org/plugins/contact-form-7/">Contact Form 7</a>, <a href="https://wordpress.org/plugins/ninja-forms/">Ninja Forms</a>, <a href="https://elementor.com/widgets/form-widget/">Elementor Forms</a> and <a href="https://wordpress.org/plugins/wpforms-lite/">WP Forms</a>. |
|---|
| 5 | * Version: 1.4.0 |
|---|
| 6 | * Requires at least: 3.8 |
|---|
| 7 | * Author URI: https://www.crmperks.com |
|---|
| 8 | * Plugin URI: https://www.crmperks.com/plugins/contact-form-plugins/crm-perks-forms/ |
|---|
| 9 | * Author: CRM Perks |
|---|
| 10 | */ |
|---|
| 11 | // Exit if accessed directly |
|---|
| 12 | if( !defined( 'ABSPATH' ) ) exit; |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | if( !class_exists( 'vxcf_form' ) ): |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | class vxcf_form { |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | public $domain = 'vxcf-leads'; |
|---|
| 22 | public $fields = null; |
|---|
| 23 | |
|---|
| 24 | public static $id = 'vxcf_leads'; |
|---|
| 25 | public static $type = "vxcf_form"; |
|---|
| 26 | public static $path = ''; |
|---|
| 27 | |
|---|
| 28 | public static $version = '1.4.0'; |
|---|
| 29 | public static $upload_folder = 'crm_perks_uploads'; |
|---|
| 30 | public static $db_version=''; |
|---|
| 31 | public static $base_url=''; |
|---|
| 32 | public static $vx_plugins; |
|---|
| 33 | public static $note; |
|---|
| 34 | public static $feeds_res; |
|---|
| 35 | public static $tooltips; |
|---|
| 36 | public static $plugin; |
|---|
| 37 | public static $pages; |
|---|
| 38 | public static $show_screen_options=false; |
|---|
| 39 | public static $sql_join=''; |
|---|
| 40 | public static $sql_where=''; |
|---|
| 41 | public static $sql_field_name=''; |
|---|
| 42 | public static $sql_select_fields=''; |
|---|
| 43 | public static $sql_order_by=''; |
|---|
| 44 | public static $forms; |
|---|
| 45 | public static $form_id; |
|---|
| 46 | public static $user_id; |
|---|
| 47 | public static $is_pr; |
|---|
| 48 | public static $form_id_string; |
|---|
| 49 | public static $form_fields; |
|---|
| 50 | public static $form_fields_temp; |
|---|
| 51 | //data object |
|---|
| 52 | public static $data = null; |
|---|
| 53 | //settings |
|---|
| 54 | public static $meta = null; |
|---|
| 55 | |
|---|
| 56 | public function instance(){ |
|---|
| 57 | |
|---|
| 58 | add_action( 'plugins_loaded', array( $this, 'setup_main' ) ); |
|---|
| 59 | register_deactivation_hook(__FILE__,array($this,'deactivate')); |
|---|
| 60 | register_activation_hook(__FILE__,(array($this,'activate'))); |
|---|
| 61 | self::$path=$this->get_base_path(); |
|---|
| 62 | self::$base_url=vxcf_form::get_base_url(); |
|---|
| 63 | add_action('init', array($this,'init')); |
|---|
| 64 | add_filter('crmperks_forms_field_validation_message',array($this,'validate_crmperks_field'),10,4); |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | public function init(){ |
|---|
| 69 | //save screen and url for all forms |
|---|
| 70 | add_action('wp_footer', array($this,'footer_js'),33); |
|---|
| 71 | wp_register_script( 'vx-tablesorter-js', self::$base_url. 'js/jquery.tablesorter.js',array('jquery') ); |
|---|
| 72 | wp_register_script( 'vx-tablepager-js', self::$base_url. 'js/jquery.tablesorter.pager.js',array('jquery') ); |
|---|
| 73 | wp_register_script( 'vx-tablewidgets-js', self::$base_url. 'js/jquery.tablesorter.widgets.js',array('jquery') ); |
|---|
| 74 | |
|---|
| 75 | //$this->get_form_fields('na_1'); die(); |
|---|
| 76 | if(!empty($_GET['vx_crm_form_action']) && $_GET['vx_crm_form_action'] == 'download_csv'){ |
|---|
| 77 | $key=$this->post('vx_crm_key'); |
|---|
| 78 | $form_ids=get_option('vx_crm_forms_ids'); |
|---|
| 79 | if(is_array($form_ids)){ |
|---|
| 80 | $form_id=array_search($key,$form_ids); |
|---|
| 81 | if(!empty($form_id)){ |
|---|
| 82 | vxcf_form::set_form_fields($form_id); |
|---|
| 83 | self::download_csv($form_id,array('vx_links'=>'false')); |
|---|
| 84 | die(); |
|---|
| 85 | } |
|---|
| 86 | } |
|---|
| 87 | } |
|---|
| 88 | //$form=vxcf_form::get_form_fields('el_2669e21_5190'); var_dump($form); |
|---|
| 89 | //$form=vxcf_form::get_form_fields('wp_5137'); var_dump($form); die(); |
|---|
| 90 | //$form=cfx_form::get_form('1'); var_dump($form); die(); |
|---|
| 91 | |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | public function setup_main(){ |
|---|
| 95 | |
|---|
| 96 | //handling post submission. |
|---|
| 97 | // add_action("gform_entry_created", array($this, 'gf_entry_created'), 40, 2); |
|---|
| 98 | // add_filter('wpcf7_mail_components', array($this, 'submission'), 999, 3); |
|---|
| 99 | // add_filter('wpcf7_posted_data', array($this, 'entry_created')); |
|---|
| 100 | // wordpress sets current user to 0 here wp-includes/rest-api.php rest_cookie_check_errors function |
|---|
| 101 | add_action('rest_api_init', array($this, 'verify_logged_in_user'),10); |
|---|
| 102 | add_filter('wpcf7_before_send_mail', array($this, 'create_entry_cf'),10); |
|---|
| 103 | //add_action('fsctf_mail_sent', array($this, 'create_entry_fscf')); |
|---|
| 104 | add_action("gform_entry_created", array($this, 'create_entry_gf'), 30, 2); |
|---|
| 105 | //formidable |
|---|
| 106 | add_action('frm_after_create_entry', array($this, 'create_entry_fd'), 30, 2); |
|---|
| 107 | //add_action('ninja_forms_post_process', array($this, 'create_entry_na'),30); |
|---|
| 108 | add_action('ninja_forms_after_submission', array($this, 'create_entry_na'),30); |
|---|
| 109 | add_action('iphorm_post_process', array($this, 'create_entry_qu'), 30); |
|---|
| 110 | add_action('caldera_forms_submit_post_process_end', array($this, 'create_entry_ca'), 10, 3); |
|---|
| 111 | add_action('cforms2_after_processing_action', array(&$this, 'create_entry_c2'),30); |
|---|
| 112 | add_action('cntctfrm_get_mail_data', array(&$this, 'create_entry_be'),30); |
|---|
| 113 | add_action('ufbl_email_send', array(&$this, 'create_entry_ul'),30); |
|---|
| 114 | add_action('grunion_pre_message_sent', array(&$this, 'create_entry_jp'),30,3); |
|---|
| 115 | add_filter('crmperks_forms_new_submission', array(&$this, 'create_entry_vf'),40,3); |
|---|
| 116 | //add_action( 'woocommerce_checkout_update_order_meta',array(&$this,'create_entry_wc'), 30, 2 ); |
|---|
| 117 | add_action( 'wpforms_process_entry_save',array(&$this,'create_entry_wp'), 30, 4 ); |
|---|
| 118 | // add_action('cntctfrm_get_attachment_data', array(&$this, 'create_entry_be'),30); |
|---|
| 119 | // add_filter('si_contact_email_fields_posted', array($this, 'test'),10,2); |
|---|
| 120 | //elemntor form |
|---|
| 121 | add_action( 'elementor_pro/forms/new_record', array($this,'create_entry_el'), 10 ); |
|---|
| 122 | // add_action( 'forminator_form_after_handle_submit', array($this,'create_entry_fr'), 10,2 ); |
|---|
| 123 | // add_action( 'forminator_form_after_save_entry', array($this,'create_entry_fr'), 10,2 ); |
|---|
| 124 | //add_filter( 'forminator_form_submit_response', array($this,'create_entry_fr'), 10,2 ); |
|---|
| 125 | |
|---|
| 126 | // add_action('wpcf7_submit', array($this, 'submit'),10, 2); |
|---|
| 127 | //add_action('wpcf7_init', array($this, 'create_entry')); |
|---|
| 128 | //$this->create_entry(); |
|---|
| 129 | add_shortcode('vx-entries', array($this, 'entries_shortcode')); |
|---|
| 130 | |
|---|
| 131 | $pro_file=self::$path . 'pro/pro.php'; |
|---|
| 132 | if(file_exists($pro_file)){ include_once($pro_file); self::$is_pr='1'; } |
|---|
| 133 | |
|---|
| 134 | if(is_admin()){ |
|---|
| 135 | load_plugin_textdomain('contact-form-entries', FALSE, self::plugin_dir_name(). '/languages/' ); |
|---|
| 136 | self::$db_version=get_option(vxcf_form::$type."_version"); |
|---|
| 137 | if(self::$db_version != self::$version && current_user_can( 'manage_options' )){ |
|---|
| 138 | |
|---|
| 139 | $this->install_plugin(); |
|---|
| 140 | |
|---|
| 141 | /* $install_data=get_option(vxcf_form::$type."_install_data"); |
|---|
| 142 | if(empty($install_data)){ |
|---|
| 143 | update_option(vxcf_form::$type."_install_data", array('time'=>current_time( 'timestamp' , 1 ))); |
|---|
| 144 | }*/ |
|---|
| 145 | $meta=$this->get_meta(); |
|---|
| 146 | if(!empty($meta['save_forms'])){ |
|---|
| 147 | $forms=vxcf_form::get_forms(); |
|---|
| 148 | $forms_arr=vxcf_form::forms_list($forms); |
|---|
| 149 | $new_ids=array_diff_key($forms_arr,$meta['save_forms']); |
|---|
| 150 | if(!empty($new_ids)){ |
|---|
| 151 | $disable=array(); |
|---|
| 152 | foreach($new_ids as $k=>$v){ |
|---|
| 153 | $disable[$k]='yes'; |
|---|
| 154 | } |
|---|
| 155 | $meta['disable_track']=$disable; |
|---|
| 156 | unset($meta['save_forms']); |
|---|
| 157 | self::$meta=$meta; |
|---|
| 158 | update_option(vxcf_form::$id.'_meta',$meta); |
|---|
| 159 | } |
|---|
| 160 | } } |
|---|
| 161 | //plugin api |
|---|
| 162 | $this->plugin_api(true); |
|---|
| 163 | require_once(self::$path . "includes/crmperks-cf.php"); |
|---|
| 164 | require_once(self::$path . "includes/plugin-pages.php"); |
|---|
| 165 | self::$pages=new vxcf_form_pages(); |
|---|
| 166 | |
|---|
| 167 | $pro_file=self::$path . 'pro/add-ons.php'; |
|---|
| 168 | if(file_exists($pro_file)){ include_once($pro_file); } |
|---|
| 169 | $pro_file=self::$path . 'wp/crmperks-notices.php'; |
|---|
| 170 | if(file_exists($pro_file)){ include_once($pro_file); } |
|---|
| 171 | //$forms=vxcf_form::get_forms(); |
|---|
| 172 | } |
|---|
| 173 | |
|---|
| 174 | } |
|---|
| 175 | |
|---|
| 176 | |
|---|
| 177 | public function plugin_api($start_instance=false){ |
|---|
| 178 | $file=self::$path . "pro/plugin-api.php"; |
|---|
| 179 | if( file_exists($file)){ |
|---|
| 180 | if(!class_exists('vxcf_plugin_api')){ include_once($file); } |
|---|
| 181 | if(class_exists('vxcf_plugin_api')){ |
|---|
| 182 | $update_id = "400001"; |
|---|
| 183 | $title='Contact Form Entries Plugin'; |
|---|
| 184 | $slug=self::get_slug(); |
|---|
| 185 | $settings_link=self::link_to_settings(); |
|---|
| 186 | $is_plugin_page=self::is_crm_page(); |
|---|
| 187 | self::$plugin=new vxcf_plugin_api(self::$id,self::$version,self::$type,$this->domain,$update_id,$title,$slug,self::$path,$settings_link,$is_plugin_page); |
|---|
| 188 | if($start_instance){ |
|---|
| 189 | self::$plugin->instance(); |
|---|
| 190 | } } |
|---|
| 191 | } |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | public function install_plugin(){ |
|---|
| 195 | $data=vxcf_form::get_data_object(); |
|---|
| 196 | $data->update_table(); |
|---|
| 197 | if(empty(self::$path)){ self::$path=$this->get_base_path(); } |
|---|
| 198 | require_once(self::$path . "includes/install.php"); |
|---|
| 199 | $install=new vxcf_form_install(); |
|---|
| 200 | $install->create_roles(); |
|---|
| 201 | $install->create_upload_dir(); |
|---|
| 202 | update_option(vxcf_form::$type."_version", self::$version); |
|---|
| 203 | } |
|---|
| 204 | public function entries_shortcode($atts){ |
|---|
| 205 | |
|---|
| 206 | $form_id=''; |
|---|
| 207 | if(!empty($atts['form-id'])){ |
|---|
| 208 | $form_id=$atts['form-id']; |
|---|
| 209 | } |
|---|
| 210 | if(!empty($atts['form-name'])){ |
|---|
| 211 | $forms_arr=get_option('vxcf_all_forms',array()); |
|---|
| 212 | if(is_array($forms_arr) && count($forms_arr)>0){ |
|---|
| 213 | foreach($forms_arr as $form_key=>$form_type){ |
|---|
| 214 | if(!empty($form_type['forms']) && is_array($form_type['forms']) && count($form_type['forms'])>0){ |
|---|
| 215 | foreach($form_type['forms'] as $k=>$v){ |
|---|
| 216 | if($v == $atts['form-name']){ |
|---|
| 217 | $form_id=$form_key.'_'.$k; |
|---|
| 218 | } |
|---|
| 219 | } |
|---|
| 220 | } |
|---|
| 221 | } |
|---|
| 222 | } |
|---|
| 223 | } |
|---|
| 224 | $fields=vxcf_form::get_form_fields($form_id); |
|---|
| 225 | $fields['created']=array('name'=>'created','_id'=>'created', 'label'=> __('Created', 'contact-form-entries')); |
|---|
| 226 | |
|---|
| 227 | |
|---|
| 228 | $col_end=count($fields); |
|---|
| 229 | if(!empty($atts['cols'])){ |
|---|
| 230 | $col_end=(int)$atts['cols']; |
|---|
| 231 | } |
|---|
| 232 | $col_start=0; |
|---|
| 233 | if(!empty($atts['col-start'])){ |
|---|
| 234 | $col_start=(int)$atts['col-start']; |
|---|
| 235 | |
|---|
| 236 | } |
|---|
| 237 | |
|---|
| 238 | if(!empty($atts['col-labels'])){ |
|---|
| 239 | $col_labels=array_map('trim',array_map('strtolower',explode(',',$atts['col-labels']))); |
|---|
| 240 | |
|---|
| 241 | if(is_array($fields) && count($fields)>0){ |
|---|
| 242 | foreach($fields as $k=>$v){ |
|---|
| 243 | |
|---|
| 244 | if(isset($v['label'] ) && !in_array( strtolower($v['label']),$col_labels)){ |
|---|
| 245 | unset($fields[$k]); |
|---|
| 246 | } |
|---|
| 247 | } |
|---|
| 248 | } |
|---|
| 249 | }else{ |
|---|
| 250 | $fields=array_splice($fields,$col_start,$col_end); |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | vxcf_form::$form_fields=$fields; |
|---|
| 254 | $css=''; |
|---|
| 255 | if(!empty($atts['font-size'])){ |
|---|
| 256 | // $atts['font-size']='x-small'; |
|---|
| 257 | $css=' style="font-size: '.esc_attr($atts['font-size']).'"'; |
|---|
| 258 | } |
|---|
| 259 | |
|---|
| 260 | |
|---|
| 261 | $class='vx_entries_table '; |
|---|
| 262 | if(!empty($atts['class'])){ |
|---|
| 263 | $class.=$atts['class']; |
|---|
| 264 | } |
|---|
| 265 | $class=' class="'.esc_attr($class).'"'; |
|---|
| 266 | |
|---|
| 267 | $table_id=''; |
|---|
| 268 | if(!empty($atts['id'])){ |
|---|
| 269 | $table_id='id="'.esc_attr($atts['id']).'"'; |
|---|
| 270 | } |
|---|
| 271 | //var_dump($fields); |
|---|
| 272 | $limit='20'; |
|---|
| 273 | if(!empty($atts['limit'])){ |
|---|
| 274 | $limit=(int)$atts['limit']; |
|---|
| 275 | } |
|---|
| 276 | $start='0'; |
|---|
| 277 | if(!empty($atts['start'])){ |
|---|
| 278 | $start=(int)$atts['start']; |
|---|
| 279 | } |
|---|
| 280 | $search=$export=''; |
|---|
| 281 | if($this->do_actions() ){ |
|---|
| 282 | if(!empty($atts['search'])){ |
|---|
| 283 | $search=$atts['search']; |
|---|
| 284 | } |
|---|
| 285 | if(!empty($atts['export'])){ |
|---|
| 286 | $form_ids=get_option('vx_crm_forms_ids'); |
|---|
| 287 | if(!is_array($form_ids)){ $form_ids=array(); } |
|---|
| 288 | if(!isset($form_ids[$form_id])){ |
|---|
| 289 | $form_ids[$form_id]=rand(99999,999999999).uniqid().time().rand(999,9999999).uniqid(); |
|---|
| 290 | update_option('vx_crm_forms_ids',$form_ids); |
|---|
| 291 | } |
|---|
| 292 | $export=$form_ids[$form_id]; |
|---|
| 293 | } |
|---|
| 294 | } |
|---|
| 295 | $page_size='3'; |
|---|
| 296 | if(!empty($atts['per-page'])){ |
|---|
| 297 | $page_size=(int)$atts['per-page']; |
|---|
| 298 | } |
|---|
| 299 | $offset=$this->time_offset(); |
|---|
| 300 | $req=array('start'=>$start,'vx_links'=>'false'); |
|---|
| 301 | if(isset($atts['user-id'])){ |
|---|
| 302 | $req['user_id']=!empty($atts['user-id']) ? (int)$atts['user-id'] : get_current_user_id(); |
|---|
| 303 | } |
|---|
| 304 | $data=vxcf_form::get_data_object(); |
|---|
| 305 | $entries=$data->get_entries($form_id,$limit,$req); |
|---|
| 306 | $leads=array(); |
|---|
| 307 | if(!empty($entries['result'])){ |
|---|
| 308 | $leads=$entries['result']; |
|---|
| 309 | } |
|---|
| 310 | |
|---|
| 311 | $base_url=vxcf_form::get_base_url(); |
|---|
| 312 | if(!empty($atts['sortable'])){ |
|---|
| 313 | wp_enqueue_script( 'vx-tablesorter-js'); |
|---|
| 314 | wp_enqueue_script( 'vx-tablewidgets-js'); |
|---|
| 315 | if(!empty($atts['pager'])){ |
|---|
| 316 | wp_enqueue_script( 'vx-tablepager-js'); |
|---|
| 317 | } |
|---|
| 318 | wp_enqueue_style('vx-tablesorter-css'); |
|---|
| 319 | } |
|---|
| 320 | $leads_table=apply_filters('crmperks_entries_template',self::$path . "templates/leads-table.php"); |
|---|
| 321 | /* foreach($leads as $lead){ |
|---|
| 322 | |
|---|
| 323 | foreach($fields as $field){ |
|---|
| 324 | |
|---|
| 325 | if($field['name'] == 'time'){ |
|---|
| 326 | $field['name']='created'; |
|---|
| 327 | } |
|---|
| 328 | |
|---|
| 329 | $field_label=''; |
|---|
| 330 | if(isset($lead[$field['name']])){ |
|---|
| 331 | $field_label=maybe_unserialize($lead[$field['name']]); |
|---|
| 332 | |
|---|
| 333 | if(is_array($field_label)){ |
|---|
| 334 | $field_label=implode(', ',$field_label); |
|---|
| 335 | }else if($field['name'] == 'created'){ |
|---|
| 336 | $field_label=strtotime($field_label)+$offset; |
|---|
| 337 | $field_label= date('M-d-Y H:i:s',$field_label); |
|---|
| 338 | } |
|---|
| 339 | |
|---|
| 340 | } |
|---|
| 341 | |
|---|
| 342 | } |
|---|
| 343 | |
|---|
| 344 | } die('-----------');*/ |
|---|
| 345 | ob_start(); |
|---|
| 346 | include($leads_table); |
|---|
| 347 | return ob_get_clean(); |
|---|
| 348 | } |
|---|
| 349 | |
|---|
| 350 | public function verify_logged_in_user(){ |
|---|
| 351 | self::$user_id=get_current_user_id(); |
|---|
| 352 | } |
|---|
| 353 | public function create_entry_auto($entry=""){ |
|---|
| 354 | |
|---|
| 355 | /* |
|---|
| 356 | $submission = WPCF7_Submission::get_instance(); |
|---|
| 357 | $uploaded_files = $submission->uploaded_files(); |
|---|
| 358 | $val = $submission->get_posted_data($name); |
|---|
| 359 | |
|---|
| 360 | |
|---|
| 361 | */ |
|---|
| 362 | /*$data_json='{"_wpcf7":"69" ,"your-name" :"touseef ahmad","your-email" :"admin@localhost.com","your-subject":"subject test"}'; |
|---|
| 363 | $files_json='{"your-file":"C:/wamp/www/wp19/wp-content/uploads/wpcf7_uploads/0845175440/cookies.txt"}'; |
|---|
| 364 | $data_arr=json_decode($data_json,true); |
|---|
| 365 | $id=uniqid(); |
|---|
| 366 | $data_arr['your-name']=$id.' name'; |
|---|
| 367 | $data_arr['your-subject']=$id.' subject'; |
|---|
| 368 | $data_arr['your-message']=$id.' '.$data_arr['your-subject'].' '.$id.' '.$data_arr['your-subject'].' '.$id.' '.$data_arr['your-subject'].' '.$id.' '.$data_arr['your-subject'].' '.$id.' '.$data_arr['your-subject'].' '.$id.' '.$data_arr['your-subject']; |
|---|
| 369 | $data_arr['your-emai']=$id.'_email@gmail.com'; |
|---|
| 370 | $files=json_decode($files_json,true); |
|---|
| 371 | $data=array_merge($data_arr,$files);*/ |
|---|
| 372 | // |
|---|
| 373 | $form_id=0; |
|---|
| 374 | if(!empty($data['_wpcf7'])){ |
|---|
| 375 | $form_id=$data['_wpcf7']; |
|---|
| 376 | } |
|---|
| 377 | // |
|---|
| 378 | $tags=vxcf_form::get_form_fields($form_id); |
|---|
| 379 | $arr=array(); |
|---|
| 380 | if(is_array($tags)){ |
|---|
| 381 | foreach($tags as $k=>$v){ |
|---|
| 382 | if(!empty($k) && isset($data[$k])){ |
|---|
| 383 | $arr[$k]=$data[$k]; |
|---|
| 384 | |
|---|
| 385 | } |
|---|
| 386 | } |
|---|
| 387 | } |
|---|
| 388 | if(is_array($arr) && count($arr)>0){ |
|---|
| 389 | $data=vxcf_form::get_data_object(); |
|---|
| 390 | $lead=$data->create_lead($arr,$form_id); |
|---|
| 391 | } |
|---|
| 392 | //var_dump($tags,$arr); die(); |
|---|
| 393 | } |
|---|
| 394 | |
|---|
| 395 | public function create_entry($lead,$form,$type,$info='',$save=true,$entry_id=''){ |
|---|
| 396 | if(!is_array($info)){ $info=array(); } |
|---|
| 397 | |
|---|
| 398 | |
|---|
| 399 | if(is_array($lead) && count($lead)>0){ |
|---|
| 400 | $data=vxcf_form::get_data_object(); |
|---|
| 401 | $form_id=$type.'_'.$form['id']; |
|---|
| 402 | $main=array('form_id'=>$form_id); |
|---|
| 403 | |
|---|
| 404 | $forms=vxcf_form::get_forms(); //var_dump($form_id,$forms,$type,$form['id']); die('----------'); |
|---|
| 405 | if(!isset($forms[$type]['forms'][$form['id']]) ){ |
|---|
| 406 | return; |
|---|
| 407 | } |
|---|
| 408 | $meta=get_option(vxcf_form::$id.'_meta',array()); |
|---|
| 409 | |
|---|
| 410 | if(empty($meta['ip'])){ |
|---|
| 411 | $main=$this->get_lead_info($main,$info); |
|---|
| 412 | }else{ |
|---|
| 413 | $url_temp=$this->get_lead_info(array()); |
|---|
| 414 | if(!empty($url_temp['url'])){ |
|---|
| 415 | $main['url']=$url_temp['url']; |
|---|
| 416 | } |
|---|
| 417 | } |
|---|
| 418 | if(!empty(self::$user_id)){ |
|---|
| 419 | $main['user_id']=self::$user_id; |
|---|
| 420 | } |
|---|
| 421 | $fields=vxcf_form::get_form_fields($form_id); |
|---|
| 422 | |
|---|
| 423 | if(!empty($fields)){ |
|---|
| 424 | foreach($lead as $k=>$v){ |
|---|
| 425 | $type=isset($fields[$k]['type']) ? $fields[$k]['type'] :''; |
|---|
| 426 | if( in_array($type,array('textarea'))){ |
|---|
| 427 | $lead[$k]=sanitize_textarea_field($v); |
|---|
| 428 | }else if(!in_array($type,array('file','mfile'))){ |
|---|
| 429 | $lead[$k]=$this->post($k,$lead); |
|---|
| 430 | } |
|---|
| 431 | } |
|---|
| 432 | } |
|---|
| 433 | $main=apply_filters('vxcf_entries_plugin_before_saving_lead_main',$main,$lead,$entry_id); |
|---|
| 434 | //var_dump($main); die(); |
|---|
| 435 | //set self::$form_fields_temp |
|---|
| 436 | |
|---|
| 437 | $lead=apply_filters('vxcf_entries_plugin_before_saving_lead',$lead,$main); |
|---|
| 438 | $vis_id=''; |
|---|
| 439 | if($save){ |
|---|
| 440 | if(empty($meta['cookies']) && empty($entry_id)){ |
|---|
| 441 | $vis_id=$this->vx_id(); |
|---|
| 442 | $entry_id=$data->get_vis_info_of_day($vis_id,$form_id,'1'); |
|---|
| 443 | } |
|---|
| 444 | $main['type']='0'; $main['is_read']='0'; |
|---|
| 445 | $entry_id=$this->create_update_lead($lead,$main,$entry_id); |
|---|
| 446 | |
|---|
| 447 | } |
|---|
| 448 | |
|---|
| 449 | /* |
|---|
| 450 | // var_dump($detail,$lead,$entry_id); die(); |
|---|
| 451 | $forms_arr=get_option('vxcf_all_forms',array()); |
|---|
| 452 | if(!isset($forms_arr[$type]['label'])){ |
|---|
| 453 | $forms_arr[$type]['label']=$forms[$type]['label']; |
|---|
| 454 | } |
|---|
| 455 | //if stored form does not matches new form |
|---|
| 456 | if(!isset($forms_arr[$type]['forms'][$form['id']]) || $forms[$type]['forms'][$form['id']] != $forms_arr[$type]['forms'][$form['id']] ){ |
|---|
| 457 | $forms_arr[$type]['forms'][$form['id']]=$forms[$type]['forms'][$form['id']]; |
|---|
| 458 | update_option('vxcf_all_forms',$forms_arr,false); |
|---|
| 459 | } |
|---|
| 460 | //update form fields |
|---|
| 461 | $forms_fields=get_option('vxcf_all_fields',array()); |
|---|
| 462 | if( (!empty($forms_fields[$type]['fields'][$form['id']]) && !empty(self::$form_fields_temp[$form_id]) && $forms_fields[$type]['fields'][$form['id']] == self::$form_fields_temp[$form_id]) == false){ |
|---|
| 463 | |
|---|
| 464 | $forms_fields[$type]['fields'][$form['id']]=self::$form_fields_temp[$form_id]; |
|---|
| 465 | update_option('vxcf_all_fields',$forms_fields,false); |
|---|
| 466 | } |
|---|
| 467 | */ |
|---|
| 468 | $main['id']=$entry_id; |
|---|
| 469 | $lead['__vx_entry']=$main; |
|---|
| 470 | if($this->do_actions()){ |
|---|
| 471 | do_action('vx_addons_save_entry',$entry_id,$lead,'cf',$form); |
|---|
| 472 | } |
|---|
| 473 | $lead=apply_filters('vxcf_after_saving_addons',$lead,$entry_id,$type,$form); |
|---|
| 474 | /*$upload=vxcf_form::get_upload_dir(); |
|---|
| 475 | foreach($lead as $k=>$v){ |
|---|
| 476 | if(isset($form['fields'][$k]['type']) && $form['fields'][$k]['type'] == 'file' && !empty($v)){ |
|---|
| 477 | if(is_string($v)){ $v=array($v); } |
|---|
| 478 | $files=array(); |
|---|
| 479 | foreach($v as $f){ |
|---|
| 480 | if(filter_var($f,FILTER_VALIDATE_URL) === false){ |
|---|
| 481 | $base_url=$upload['url']; |
|---|
| 482 | $f=$base_url.$f; |
|---|
| 483 | } |
|---|
| 484 | $files[]=$f; |
|---|
| 485 | } |
|---|
| 486 | $lead[$k]=$files; |
|---|
| 487 | } |
|---|
| 488 | }*/ |
|---|
| 489 | //var_dump($lead); |
|---|
| 490 | |
|---|
| 491 | $form['form_id']=$form['id']=$form_id; |
|---|
| 492 | do_action('vxcf_entry_created',$lead,$entry_id,$form); |
|---|
| 493 | } |
|---|
| 494 | return $entry_id; |
|---|
| 495 | } |
|---|
| 496 | public function create_update_lead($detail,$lead,$entry_id=''){ |
|---|
| 497 | $data=vxcf_form::get_data_object(); |
|---|
| 498 | if(empty($entry_id)){ //no partial entry |
|---|
| 499 | $entry_id=$data->update_lead('',$detail,'',$lead); |
|---|
| 500 | |
|---|
| 501 | }else{ |
|---|
| 502 | $detail_db= $data->get_lead_detail($entry_id); |
|---|
| 503 | $update=$insert=array(); |
|---|
| 504 | if(!empty($detail)){ |
|---|
| 505 | foreach($detail as $k=>$v){ |
|---|
| 506 | if(isset($detail_db[$k]['value'])){ |
|---|
| 507 | if($detail_db[$k]['value'] != $v){ |
|---|
| 508 | $update[$detail_db[$k]['id']]=$v; |
|---|
| 509 | } |
|---|
| 510 | }else{ |
|---|
| 511 | $insert[$k]=$v; |
|---|
| 512 | } |
|---|
| 513 | } } |
|---|
| 514 | $data->update_lead($update,$insert,$entry_id,$lead); |
|---|
| 515 | } |
|---|
| 516 | |
|---|
| 517 | return $entry_id; |
|---|
| 518 | } |
|---|
| 519 | public static function update_entry_meta($entry_id,$meta_key,$meta){ |
|---|
| 520 | if(!empty($entry_id) && !empty($meta) && is_array($meta)){ |
|---|
| 521 | $entry=vxcf_form::get_entry($entry_id); |
|---|
| 522 | $detail=!empty($entry['meta']) ? json_decode($entry['meta'],true) : array(); |
|---|
| 523 | $data=vxcf_form::get_data_object(); |
|---|
| 524 | if(!empty($detail[$meta_key]) && is_array($detail[$meta_key])){ |
|---|
| 525 | $meta=array_merge($detail[$meta_key],$meta); |
|---|
| 526 | } |
|---|
| 527 | $detail[$meta_key]=$meta; |
|---|
| 528 | $data->update_lead('','',$entry_id,array('meta'=>json_encode($detail))); |
|---|
| 529 | } |
|---|
| 530 | } |
|---|
| 531 | public function get_lead_info($info,$meta_info=array()){ |
|---|
| 532 | |
|---|
| 533 | $info['user_id']=get_current_user_id(); |
|---|
| 534 | if(!empty($meta_info['ip'])){ |
|---|
| 535 | $ip=$meta_info['ip']; |
|---|
| 536 | }else{ |
|---|
| 537 | $ip=$this->get_ip(); |
|---|
| 538 | } |
|---|
| 539 | $info['ip']=substr(vxcf_form::clean($ip),0,50); |
|---|
| 540 | $resolution=""; |
|---|
| 541 | if(isset($_POST['vx_width'])){ |
|---|
| 542 | $width=vxcf_form::post('vx_width'); |
|---|
| 543 | $height=vxcf_form::post('vx_height'); |
|---|
| 544 | $resolution=$width." x ".$height; |
|---|
| 545 | $info['screen']=$resolution; |
|---|
| 546 | } |
|---|
| 547 | $user_agent=!empty($meta_info['user_agent']) ? $meta_info['user_agent'] : ''; |
|---|
| 548 | $bro_info=self::browser_info($user_agent); |
|---|
| 549 | //get page url |
|---|
| 550 | $page_url="//$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; |
|---|
| 551 | if(isset($_REQUEST['vx_url'])){ |
|---|
| 552 | $page_url=vxcf_form::post('vx_url'); |
|---|
| 553 | } |
|---|
| 554 | if(!empty($meta_info['url'])){ |
|---|
| 555 | $page_url=vxcf_form::clean($meta_info['url']); |
|---|
| 556 | } |
|---|
| 557 | $page_url=substr($page_url,0,250); |
|---|
| 558 | $info['url']=vxcf_form::clean($page_url); |
|---|
| 559 | $info['browser']=substr(vxcf_form::clean($bro_info['name']),0,50); |
|---|
| 560 | $info['os']=substr(vxcf_form::clean($bro_info['platform']),0,50); |
|---|
| 561 | if(!empty($meta_info['vis_id'])){ |
|---|
| 562 | $info['vis_id']=$meta_info['vis_id']; |
|---|
| 563 | }else{ |
|---|
| 564 | $info['vis_id']=$this->vx_id(); |
|---|
| 565 | } |
|---|
| 566 | $info['vis_id']=vxcf_form::clean($info['vis_id']); |
|---|
| 567 | return $info; |
|---|
| 568 | } |
|---|
| 569 | public function create_entry_vf($entry_id,$entry,$form){ |
|---|
| 570 | //$track=$this->track_form_entry('vf'); |
|---|
| 571 | $track= empty($form['settings']['disable_db']); |
|---|
| 572 | |
|---|
| 573 | return $this->create_entry($entry,$form,'vf','',$track,$entry_id); |
|---|
| 574 | } |
|---|
| 575 | public function create_entry_wp($fields, $entry, $form_id, $form_data){ |
|---|
| 576 | $track=$this->track_form_entry('wp',$form_id); |
|---|
| 577 | |
|---|
| 578 | $upload_files=$lead=array(); |
|---|
| 579 | if(!empty($fields)){ |
|---|
| 580 | foreach($fields as $v){ |
|---|
| 581 | if($v['type'] == 'file-upload'){ |
|---|
| 582 | $v['value']=array_map('trim',explode("\n",$v['value'])); |
|---|
| 583 | $upload_files[$v['id']]=$v['value']; |
|---|
| 584 | }else{ |
|---|
| 585 | $val=$v['value']; |
|---|
| 586 | if(in_array($v['type'],array('payment-select','payment-multiple'))){ |
|---|
| 587 | $val=$v['amount']; |
|---|
| 588 | }else if($v['type'] == 'checkbox'){ |
|---|
| 589 | $val=array_map('trim',explode("\n",$val)); |
|---|
| 590 | } |
|---|
| 591 | $lead[$v['id']]=$val; |
|---|
| 592 | } } |
|---|
| 593 | //var_dump($upload_files); //die(); |
|---|
| 594 | if($track){ |
|---|
| 595 | $upload_files=$this->copy_files($upload_files); |
|---|
| 596 | } |
|---|
| 597 | |
|---|
| 598 | if(is_array($upload_files)){ |
|---|
| 599 | foreach($upload_files as $k=>$v){ |
|---|
| 600 | $lead[$k]=$v; |
|---|
| 601 | } } |
|---|
| 602 | |
|---|
| 603 | $form_arr=array('id'=>$form_data['id'],'name'=>'WP Forms','fields'=>$form_data['fields']); |
|---|
| 604 | if(!empty($form_data['fields']['settings']['form_title'])){ |
|---|
| 605 | $form_arr['name']=$form_data['fields']['settings']['form_title']; |
|---|
| 606 | } |
|---|
| 607 | $this->create_entry($lead,$form_arr,'wp','',$track); |
|---|
| 608 | } |
|---|
| 609 | //var_dump($fields); die(); |
|---|
| 610 | } |
|---|
| 611 | public function create_entry_el( $record){ |
|---|
| 612 | |
|---|
| 613 | $data=$record->get_formatted_data(); |
|---|
| 614 | $form_id_p=$this->post('form_id'); |
|---|
| 615 | $post_id_p=$this->post('post_id'); |
|---|
| 616 | |
|---|
| 617 | $form_id=$form_id_p.'_'.$post_id_p; |
|---|
| 618 | $track=$this->track_form_entry('el',$form_id); |
|---|
| 619 | $fields=self::get_form_fields('el_'.$form_id); |
|---|
| 620 | $upload_files=$lead=array(); |
|---|
| 621 | if(!empty($fields)){ |
|---|
| 622 | foreach($fields as $v){ |
|---|
| 623 | if(isset($data[$v['label']])){ |
|---|
| 624 | $val=$data[$v['label']]; |
|---|
| 625 | if($v['type'] == 'upload'){ |
|---|
| 626 | $upload_files[$v['id']]=$val; |
|---|
| 627 | }else{ |
|---|
| 628 | |
|---|
| 629 | if(in_array($v['type'],array('checkbox','multiselect'))){ |
|---|
| 630 | $val=array_map('trim',explode(',',$val)); |
|---|
| 631 | } |
|---|
| 632 | $lead[$v['id']]=$val; |
|---|
| 633 | } } } |
|---|
| 634 | if($track ){ //&& !empty(self::$is_pr) |
|---|
| 635 | $upload_files=$this->copy_files($upload_files); |
|---|
| 636 | } |
|---|
| 637 | if(is_array($upload_files)){ |
|---|
| 638 | foreach($upload_files as $k=>$v){ |
|---|
| 639 | $lead[$k]=$v; |
|---|
| 640 | } } |
|---|
| 641 | //var_dump($lead,$data); die(); |
|---|
| 642 | $form_arr=array('id'=>$form_id,'name'=>'Elementor Forms','fields'=>$fields); |
|---|
| 643 | |
|---|
| 644 | $all_forms=get_option('vxcf_all_forms',array()); |
|---|
| 645 | if(!isset($all_forms['el'])){ |
|---|
| 646 | $all_forms['el']=array('label'=>'Elementor Forms','forms'=>array()); |
|---|
| 647 | } |
|---|
| 648 | |
|---|
| 649 | if(!isset($all_forms['el']['forms'][$form_id])){ |
|---|
| 650 | $all_forms['el']['forms'][$form_id]='Post '.$post_id_p.' Form #'.$form_id_p; |
|---|
| 651 | update_option('vxcf_all_forms',$all_forms); |
|---|
| 652 | } |
|---|
| 653 | |
|---|
| 654 | $this->create_entry($lead,$form_arr,'el','',$track); |
|---|
| 655 | |
|---|
| 656 | } |
|---|
| 657 | //var_dump($fields); die(); |
|---|
| 658 | } |
|---|
| 659 | public function create_entry_wc($id,$posted){ |
|---|
| 660 | $track=$this->track_form_entry('wc','1'); |
|---|
| 661 | |
|---|
| 662 | $tags=vxcf_form::get_form_fields('wc_1'); |
|---|
| 663 | $order=get_post_meta($id); |
|---|
| 664 | $_order=new WC_Order($id); |
|---|
| 665 | |
|---|
| 666 | $order['qty']=$_order->get_item_count(); |
|---|
| 667 | $order['order_note']=$_order->customer_note; |
|---|
| 668 | $order['order_id']=$id; |
|---|
| 669 | $lead=array(); |
|---|
| 670 | if(!empty($tags)){ |
|---|
| 671 | foreach($tags as $v){ |
|---|
| 672 | if(isset($order[$v['id']])){ |
|---|
| 673 | $k=$v['id']; $val=$order[$k]; |
|---|
| 674 | $lead[$k]=is_array($val) && isset($val[0]) ? $val[0] : $val; |
|---|
| 675 | } |
|---|
| 676 | } |
|---|
| 677 | } |
|---|
| 678 | //var_dump($lead,$order,$tags); die(); |
|---|
| 679 | $form_arr=array('id'=>'1','name'=>'WooCommerce','fields'=>$tags); |
|---|
| 680 | $this->create_entry($lead,$form_arr,'wc','',$track); |
|---|
| 681 | |
|---|
| 682 | } |
|---|
| 683 | public function create_entry_cf($form){ |
|---|
| 684 | |
|---|
| 685 | $form_id=$form->id(); |
|---|
| 686 | $track=$this->track_form_entry('cf',$form_id); |
|---|
| 687 | |
|---|
| 688 | $submission = WPCF7_Submission::get_instance(); |
|---|
| 689 | $uploaded_files = $submission->uploaded_files(); |
|---|
| 690 | |
|---|
| 691 | if($track){ |
|---|
| 692 | $uploaded_files=$this->copy_files($uploaded_files); |
|---|
| 693 | } |
|---|
| 694 | $form_title=$form->title(); |
|---|
| 695 | $tags=vxcf_form::get_form_fields('cf_'.$form_id); |
|---|
| 696 | $post_data=$submission->get_posted_data(); |
|---|
| 697 | //var_dump($post_data); die(); |
|---|
| 698 | $lead=array(); |
|---|
| 699 | if(is_array($post_data)){ |
|---|
| 700 | foreach($post_data as $k=>$val){ |
|---|
| 701 | if(in_array($k,array('vx_width','vx_height','vx_url','g-recaptcha-response'))){ continue; } |
|---|
| 702 | if(isset($tags[$k])){ |
|---|
| 703 | $v=$tags[$k]; //$v is empty for non form fields |
|---|
| 704 | } |
|---|
| 705 | $name=$k; //$v['name'] //if empty then $v is old |
|---|
| 706 | //var_dump($v); |
|---|
| 707 | if(isset($uploaded_files[$name])){ |
|---|
| 708 | $val=$uploaded_files[$name]; |
|---|
| 709 | } |
|---|
| 710 | |
|---|
| 711 | //disabled it @feb-2024 , dnd plugin now uses correct file urls because it converts normal file url to http://localhost/wp6/wp-content/uploads/wp_dndcf7_uploads/wpcf7-files/ |
|---|
| 712 | /* if( !empty($val) && isset($v['type_']) && $v['type_'] == 'mfile' && function_exists('dnd_get_upload_dir') ){ |
|---|
| 713 | $dir=dnd_get_upload_dir(); |
|---|
| 714 | $f_arr=array(); |
|---|
| 715 | foreach($val as $file){ |
|---|
| 716 | $file_name=explode('/',$file); |
|---|
| 717 | if(count($file_name)>1){ //var_dump($file_name,$file); |
|---|
| 718 | $f_arr[]=$dir['upload_url'].'/'.$file_name[1]; |
|---|
| 719 | } |
|---|
| 720 | } |
|---|
| 721 | |
|---|
| 722 | $val=$f_arr; |
|---|
| 723 | }*/ |
|---|
| 724 | if( !empty($val) && is_array($val) && isset($v['type_']) && $v['type_'] == 'mfilea'){ //escape wpcf7-files/testt'"><img src=x onerror=alert(1).jpg |
|---|
| 725 | $temp_val=array(); |
|---|
| 726 | foreach($val as $kk=>$vv){ |
|---|
| 727 | $temp_val[$kk]=sanitize_url($vv); |
|---|
| 728 | } |
|---|
| 729 | $val=$temp_val; |
|---|
| 730 | } |
|---|
| 731 | if(!isset($uploaded_files[$name])){ |
|---|
| 732 | $val=wp_unslash($val); |
|---|
| 733 | } |
|---|
| 734 | $lead[$k]=$val; |
|---|
| 735 | } |
|---|
| 736 | } |
|---|
| 737 | //var_dump($lead,$post_data); die('-----------'); |
|---|
| 738 | |
|---|
| 739 | $form_arr=array('id'=>$form_id,'name'=>$form_title,'fields'=>$tags); |
|---|
| 740 | $this->create_entry($lead,$form_arr,'cf','',$track); |
|---|
| 741 | |
|---|
| 742 | } |
|---|
| 743 | public function create_entry_fr($res,$id){ |
|---|
| 744 | var_dump($res,$id); die(); |
|---|
| 745 | $form_id=$form->id(); |
|---|
| 746 | $track=$this->track_form_entry('cf',$form_id); |
|---|
| 747 | |
|---|
| 748 | $submission = WPCF7_Submission::get_instance(); |
|---|
| 749 | $uploaded_files = $submission->uploaded_files(); |
|---|
| 750 | |
|---|
| 751 | if($track){ |
|---|
| 752 | $uploaded_files=$this->copy_files($uploaded_files); |
|---|
| 753 | } |
|---|
| 754 | $form_title=$form->title(); |
|---|
| 755 | $tags=vxcf_form::get_form_fields('cf_'.$form_id); |
|---|
| 756 | $post_data=$submission->get_posted_data(); |
|---|
| 757 | //var_dump($post_data); die(); |
|---|
| 758 | $lead=array(); |
|---|
| 759 | if(is_array($post_data)){ |
|---|
| 760 | foreach($post_data as $k=>$val){ |
|---|
| 761 | if(in_array($k,array('vx_width','vx_height','vx_url','g-recaptcha-response'))){ continue; } |
|---|
| 762 | if(isset($tags[$k])){ |
|---|
| 763 | $v=$tags[$k]; //$v is empty for non form fields |
|---|
| 764 | } |
|---|
| 765 | $name=$k; //$v['name'] //if empty then $v is old |
|---|
| 766 | //var_dump($v); |
|---|
| 767 | if(isset($uploaded_files[$name])){ |
|---|
| 768 | $val=$uploaded_files[$name]; |
|---|
| 769 | } |
|---|
| 770 | |
|---|
| 771 | if( !empty($val) && is_array($val) && isset($v['type_']) && $v['type_'] == 'mfilea'){ //escape wpcf7-files/testt'"><img src=x onerror=alert(1).jpg |
|---|
| 772 | $temp_val=array(); |
|---|
| 773 | foreach($val as $kk=>$vv){ |
|---|
| 774 | $temp_val[$kk]=sanitize_url($vv); |
|---|
| 775 | } |
|---|
| 776 | $val=$temp_val; |
|---|
| 777 | } |
|---|
| 778 | if(!isset($uploaded_files[$name])){ |
|---|
| 779 | $val=wp_unslash($val); |
|---|
| 780 | } |
|---|
| 781 | $lead[$k]=$val; |
|---|
| 782 | } |
|---|
| 783 | } |
|---|
| 784 | //var_dump($lead,$post_data); die('-----------'); |
|---|
| 785 | |
|---|
| 786 | $form_arr=array('id'=>$form_id,'name'=>$form_title,'fields'=>$tags); |
|---|
| 787 | $this->create_entry($lead,$form_arr,'cf','',$track); |
|---|
| 788 | |
|---|
| 789 | } |
|---|
| 790 | public function create_entry_na($data){ |
|---|
| 791 | |
|---|
| 792 | $form_id=$data['form_id']; |
|---|
| 793 | $track=$this->track_form_entry('na',$form_id); |
|---|
| 794 | |
|---|
| 795 | if(empty($data['form_id'])){ |
|---|
| 796 | return; |
|---|
| 797 | } |
|---|
| 798 | |
|---|
| 799 | $form_title=$data['settings']['title']; |
|---|
| 800 | $lead=$upload_files=array(); |
|---|
| 801 | if(!empty($data['fields'])){ |
|---|
| 802 | foreach($data['fields'] as $v){ |
|---|
| 803 | $field_id=$v['id']; |
|---|
| 804 | if(!empty($v['value'])){ |
|---|
| 805 | if($v['type'] == 'file_upload'){ |
|---|
| 806 | $upload_files[$field_id]=$v['value']; |
|---|
| 807 | }else{ |
|---|
| 808 | $lead[$field_id]=$v['value']; |
|---|
| 809 | } |
|---|
| 810 | } |
|---|
| 811 | } |
|---|
| 812 | if($track){ |
|---|
| 813 | $upload_files=$this->copy_files($upload_files); |
|---|
| 814 | } |
|---|
| 815 | if(is_array($upload_files)){ |
|---|
| 816 | foreach($upload_files as $k=>$v){ |
|---|
| 817 | $lead[$k]=$v; |
|---|
| 818 | } |
|---|
| 819 | } |
|---|
| 820 | $form_arr=array('id'=>$form_id,'name'=>$form_title,'fields'=>$data['fields']); |
|---|
| 821 | $this->create_entry($lead,$form_arr,'na','',$track); |
|---|
| 822 | |
|---|
| 823 | } |
|---|
| 824 | } |
|---|
| 825 | public function create_entry_qu($form){ |
|---|
| 826 | $form_id=$form->getId(); |
|---|
| 827 | $track=$this->track_form_entry('qu',$form_id); |
|---|
| 828 | if(empty($form)){ |
|---|
| 829 | return; |
|---|
| 830 | } |
|---|
| 831 | |
|---|
| 832 | $vals= $form->getValues(); |
|---|
| 833 | $fields=vxcf_form::get_form_fields('qu_'.$form_id); |
|---|
| 834 | |
|---|
| 835 | $lead=$upload_files=array(); |
|---|
| 836 | $field_text='iphorm_'.$form_id.'_'; |
|---|
| 837 | if(is_array($fields) && count($fields)>0){ |
|---|
| 838 | foreach($fields as $field){ |
|---|
| 839 | |
|---|
| 840 | |
|---|
| 841 | if(isset($field['id']) && !empty($vals[$field_text.$field['id']])){ |
|---|
| 842 | $type=$field['type']; |
|---|
| 843 | $id=$field['id']; |
|---|
| 844 | $val=$vals[$field_text.$field['id']]; |
|---|
| 845 | $files=array(); |
|---|
| 846 | if($type == 'file'){ |
|---|
| 847 | if(is_array($val) && count($val)>0){ |
|---|
| 848 | foreach($val as $file){ |
|---|
| 849 | if(isset($file['fullPath'])){ |
|---|
| 850 | $files[]=$file['fullPath']; |
|---|
| 851 | } |
|---|
| 852 | } |
|---|
| 853 | } |
|---|
| 854 | $upload_files[$id]=$files; |
|---|
| 855 | }else{ |
|---|
| 856 | $lead[$id]=$val; |
|---|
| 857 | } |
|---|
| 858 | } |
|---|
| 859 | } |
|---|
| 860 | if($track){ |
|---|
| 861 | $upload_files=$this->copy_files($upload_files); |
|---|
| 862 | } |
|---|
| 863 | if(is_array($upload_files)){ |
|---|
| 864 | foreach($upload_files as $k=>$v){ |
|---|
| 865 | $lead[$k]=$v; |
|---|
| 866 | } |
|---|
| 867 | } |
|---|
| 868 | if(count($lead)>0){ |
|---|
| 869 | $form_arr=array('id'=>$form_id,'name'=>$form->getName(),'fields'=>$fields); |
|---|
| 870 | $this->create_entry($lead,$form_arr,'qu','',$track); |
|---|
| 871 | } |
|---|
| 872 | } |
|---|
| 873 | |
|---|
| 874 | |
|---|
| 875 | } |
|---|
| 876 | public function create_entry_ca($form){ |
|---|
| 877 | $form_id=$form['ID']; |
|---|
| 878 | $track=$this->track_form_entry('ca',$form_id); |
|---|
| 879 | |
|---|
| 880 | global $processed_data; |
|---|
| 881 | |
|---|
| 882 | if(empty($form)){ |
|---|
| 883 | return; |
|---|
| 884 | } |
|---|
| 885 | |
|---|
| 886 | $vals= $processed_data[$form_id]; |
|---|
| 887 | |
|---|
| 888 | $fields=vxcf_form::get_form_fields('ca_'.$form_id); |
|---|
| 889 | //var_dump($fields,$vals); //die(); |
|---|
| 890 | $lead=array(); |
|---|
| 891 | $upload_files=array(); |
|---|
| 892 | if(is_array($fields) && count($fields)>0){ |
|---|
| 893 | foreach($fields as $field){ |
|---|
| 894 | |
|---|
| 895 | |
|---|
| 896 | if(isset($field['name']) && isset($vals[$field['name']])){ |
|---|
| 897 | $type=$field['type']; |
|---|
| 898 | $id=$field['name']; |
|---|
| 899 | $val=$vals[$field['name']]; |
|---|
| 900 | $files=array(); |
|---|
| 901 | if($type == 'file'){ |
|---|
| 902 | if(!is_array($val) && !empty($val)){ |
|---|
| 903 | $val=array($val); |
|---|
| 904 | } |
|---|
| 905 | if(is_array($val) && count($val)>0){ |
|---|
| 906 | $upload_files[$id]=$val; |
|---|
| 907 | } |
|---|
| 908 | } |
|---|
| 909 | $lead[$id]=$val; |
|---|
| 910 | } |
|---|
| 911 | } |
|---|
| 912 | if($track){ |
|---|
| 913 | $upload_files=$this->copy_files($upload_files); |
|---|
| 914 | } |
|---|
| 915 | if(is_array($upload_files)){ |
|---|
| 916 | foreach($upload_files as $k=>$v){ |
|---|
| 917 | $lead[$k]=$v; |
|---|
| 918 | } |
|---|
| 919 | } |
|---|
| 920 | if(count($lead)>0){ |
|---|
| 921 | $form_arr=array('id'=>$form_id,'name'=>$form['name'],'fields'=>$fields); |
|---|
| 922 | $this->create_entry($lead,$form_arr,'ca','',$track); |
|---|
| 923 | } |
|---|
| 924 | } |
|---|
| 925 | |
|---|
| 926 | } |
|---|
| 927 | public function create_entry_be(){ |
|---|
| 928 | $track=$this->track_form_entry('be','1'); |
|---|
| 929 | |
|---|
| 930 | global $cntctfrm_path_of_uploaded_file; |
|---|
| 931 | $fields=vxcf_form::get_form_fields('be_'); |
|---|
| 932 | $lead=array(); |
|---|
| 933 | if(is_array($fields) && count($fields)>0){ |
|---|
| 934 | foreach($fields as $k=>$field){ |
|---|
| 935 | if(isset($_POST['cntctfrm_contact_'.$k])){ |
|---|
| 936 | $lead[$k]=vxcf_form::post('cntctfrm_contact_'.$k); |
|---|
| 937 | }else if($field['type'] == 'file' && !empty($cntctfrm_path_of_uploaded_file)){ |
|---|
| 938 | $files=array($k=>$cntctfrm_path_of_uploaded_file); |
|---|
| 939 | if($track){ |
|---|
| 940 | $files=$this->copy_files($files ); |
|---|
| 941 | } |
|---|
| 942 | if(isset($files[$k])){ |
|---|
| 943 | $lead[$k]=$files[$k]; |
|---|
| 944 | } |
|---|
| 945 | } |
|---|
| 946 | |
|---|
| 947 | } |
|---|
| 948 | } |
|---|
| 949 | if(count($lead)>0){ |
|---|
| 950 | $form_arr=array('id'=>'','name'=>'BestSoft Contact Form','fields'=>$fields); |
|---|
| 951 | $this->create_entry($lead,$form_arr,'be','',$track); |
|---|
| 952 | } |
|---|
| 953 | } |
|---|
| 954 | public function create_entry_ul($to_email){ |
|---|
| 955 | |
|---|
| 956 | $entry=array(); |
|---|
| 957 | if(!empty($_POST['form_data'])){ |
|---|
| 958 | $form_data=vxcf_form::post('form_data'); |
|---|
| 959 | foreach($form_data as $k=>$v){ |
|---|
| 960 | $id=$v['name']; |
|---|
| 961 | if(strpos($id,'[') !== false){ |
|---|
| 962 | $id=substr($id,0,strlen($id)-2); |
|---|
| 963 | } |
|---|
| 964 | |
|---|
| 965 | $value=$v['value']; |
|---|
| 966 | if(isset($entry[$id])){ |
|---|
| 967 | $value=$entry[$id]; |
|---|
| 968 | if(!is_array($value)){ |
|---|
| 969 | $value=array($value); |
|---|
| 970 | } |
|---|
| 971 | $value[]=$v['value']; |
|---|
| 972 | } |
|---|
| 973 | $entry[$id]=$value; |
|---|
| 974 | } |
|---|
| 975 | } |
|---|
| 976 | |
|---|
| 977 | if(empty($entry['form_id'])){ |
|---|
| 978 | return; |
|---|
| 979 | } |
|---|
| 980 | $track=$this->track_form_entry('ul',$entry['form_id']); |
|---|
| 981 | |
|---|
| 982 | |
|---|
| 983 | $form_id=$entry['form_id']; |
|---|
| 984 | |
|---|
| 985 | $fields=vxcf_form::get_form_fields('ul_'.$form_id); |
|---|
| 986 | $lead=array(); |
|---|
| 987 | if(is_array($entry) && count($entry)>0){ |
|---|
| 988 | foreach($entry as $k=>$v){ |
|---|
| 989 | |
|---|
| 990 | if(isset($fields[$k])){ |
|---|
| 991 | $lead[$k]=$v; |
|---|
| 992 | }else{ |
|---|
| 993 | // echo $k.'<hr>'; |
|---|
| 994 | } |
|---|
| 995 | |
|---|
| 996 | } |
|---|
| 997 | } |
|---|
| 998 | |
|---|
| 999 | |
|---|
| 1000 | |
|---|
| 1001 | if(count($lead)>0){ |
|---|
| 1002 | $form= UFBL_Model::get_form_detail($form_id); |
|---|
| 1003 | $form_arr=array('id'=>$form_id,'name'=>$form['form_title'],'fields'=>$fields); |
|---|
| 1004 | $this->create_entry($lead,$form_arr,'ul','',$track); |
|---|
| 1005 | } |
|---|
| 1006 | |
|---|
| 1007 | |
|---|
| 1008 | |
|---|
| 1009 | } |
|---|
| 1010 | |
|---|
| 1011 | public function create_entry_c2($data){ |
|---|
| 1012 | if(empty($data)){ return; } |
|---|
| 1013 | $form_id=$data['id']; |
|---|
| 1014 | $track=$this->track_form_entry('c2',$form_id); |
|---|
| 1015 | if($track === false){ |
|---|
| 1016 | return; |
|---|
| 1017 | } |
|---|
| 1018 | $entry= $data['data']; |
|---|
| 1019 | $fields=vxcf_form::get_form_fields('c2_'.$form_id); |
|---|
| 1020 | $vals=array(); |
|---|
| 1021 | if(is_array($entry) && count($entry)>0){ |
|---|
| 1022 | foreach($entry as $k=>$v){ |
|---|
| 1023 | |
|---|
| 1024 | if(strpos($k,'$$$') === 0 && isset($entry[$v])){ |
|---|
| 1025 | $k=substr($k,3); |
|---|
| 1026 | $vals[$k]=$entry[$v]; |
|---|
| 1027 | } |
|---|
| 1028 | |
|---|
| 1029 | } |
|---|
| 1030 | } |
|---|
| 1031 | |
|---|
| 1032 | $lead=array(); |
|---|
| 1033 | $upload_files=array(); |
|---|
| 1034 | if(is_array($fields) && count($fields)>0){ |
|---|
| 1035 | foreach($fields as $field){ |
|---|
| 1036 | |
|---|
| 1037 | |
|---|
| 1038 | if(isset($field['name']) && isset($vals[$field['name']])){ |
|---|
| 1039 | $type=$field['type']; |
|---|
| 1040 | $id=$field['name']; |
|---|
| 1041 | $val=$vals[$field['name']]; |
|---|
| 1042 | $files=array(); |
|---|
| 1043 | |
|---|
| 1044 | if($type == 'file'){ |
|---|
| 1045 | // $settings = get_option('cforms_settings'); //cforms_upload_dir |
|---|
| 1046 | |
|---|
| 1047 | // if(!empty($settings['form'.$form_id]['cforms_upload_dir'])){ |
|---|
| 1048 | // $upload_dir=explode('$#$',$settings['form'.$form_id]['cforms_upload_dir']); |
|---|
| 1049 | // $val=trim($upload_dir[0],'/').'/'.$val; |
|---|
| 1050 | |
|---|
| 1051 | //} |
|---|
| 1052 | |
|---|
| 1053 | $upload_files[]=array('id'=>$id,'val'=>$val); |
|---|
| 1054 | |
|---|
| 1055 | |
|---|
| 1056 | }else{ |
|---|
| 1057 | if(isset($field['values'])){ |
|---|
| 1058 | $val=explode(',',$val); |
|---|
| 1059 | } |
|---|
| 1060 | $lead[$id]=$val; |
|---|
| 1061 | } |
|---|
| 1062 | } |
|---|
| 1063 | } |
|---|
| 1064 | $files=array(); |
|---|
| 1065 | if(is_array($upload_files) && isset($data['uploaded_files']) && is_array($data['uploaded_files'])){ |
|---|
| 1066 | foreach($upload_files as $k=>$v){ |
|---|
| 1067 | if(isset($data['uploaded_files'][$k]['name'])){ |
|---|
| 1068 | $files[$v['id']]=$data['uploaded_files'][$k]['name']; |
|---|
| 1069 | } |
|---|
| 1070 | } |
|---|
| 1071 | } |
|---|
| 1072 | $uploaded_files=$this->copy_files($files); |
|---|
| 1073 | if(is_array($uploaded_files) && count($uploaded_files)>0){ |
|---|
| 1074 | foreach($uploaded_files as $k=>$v){ |
|---|
| 1075 | $lead[$k]=$v; |
|---|
| 1076 | } |
|---|
| 1077 | } |
|---|
| 1078 | if(count($lead)>0){ |
|---|
| 1079 | $form_arr=array('id'=>$form_id,'name'=>$form['name'],'fields'=>$fields); |
|---|
| 1080 | $this->create_entry($lead,$form_arr,'c2'); |
|---|
| 1081 | } |
|---|
| 1082 | } |
|---|
| 1083 | |
|---|
| 1084 | |
|---|
| 1085 | } |
|---|
| 1086 | public function create_entry_jp($post_i, $all_values, $extra_values){ |
|---|
| 1087 | $post_id=get_the_ID(); |
|---|
| 1088 | $track=$this->track_form_entry('jp',$post_id); |
|---|
| 1089 | |
|---|
| 1090 | |
|---|
| 1091 | $title=get_the_title(); |
|---|
| 1092 | $fields=vxcf_form::get_form_fields('jp_'.$post_id); |
|---|
| 1093 | if(!is_array($all_values)){ |
|---|
| 1094 | $all_values=array(); |
|---|
| 1095 | } |
|---|
| 1096 | /* if(is_array($extra_values)){ |
|---|
| 1097 | $all_values=array_merge($all_values,$extra_values); |
|---|
| 1098 | } */ |
|---|
| 1099 | $lead=array(); |
|---|
| 1100 | if(count($all_values)>0){ |
|---|
| 1101 | foreach($all_values as $k=>$v){ |
|---|
| 1102 | $k=explode('_',$k); |
|---|
| 1103 | |
|---|
| 1104 | if(isset($fields[$k[1]])){ |
|---|
| 1105 | |
|---|
| 1106 | $lead[$k[1]]=$v; |
|---|
| 1107 | } |
|---|
| 1108 | } |
|---|
| 1109 | if(count($lead)>0){ |
|---|
| 1110 | $form_arr=array('id'=>$post_id,'name'=>$title,'fields'=>$fields); |
|---|
| 1111 | $this->create_entry($lead,$form_arr,'jp','',$track); |
|---|
| 1112 | } |
|---|
| 1113 | } |
|---|
| 1114 | |
|---|
| 1115 | // var_dump($fields,$post_id, $all_values, $lead); die(); |
|---|
| 1116 | |
|---|
| 1117 | if(empty($data)){ |
|---|
| 1118 | return; |
|---|
| 1119 | } |
|---|
| 1120 | $form_id=$data['id']; |
|---|
| 1121 | $entry= $data['data']; |
|---|
| 1122 | $fields=vxcf_form::get_form_fields('c2_'.$form_id); |
|---|
| 1123 | $vals=array(); |
|---|
| 1124 | if(is_array($entry) && count($entry)>0){ |
|---|
| 1125 | foreach($entry as $k=>$v){ |
|---|
| 1126 | |
|---|
| 1127 | if(strpos($k,'$$$') === 0 && isset($entry[$v])){ |
|---|
| 1128 | $k=substr($k,3); |
|---|
| 1129 | $vals[$k]=$entry[$v]; |
|---|
| 1130 | } |
|---|
| 1131 | |
|---|
| 1132 | } |
|---|
| 1133 | |
|---|
| 1134 | } |
|---|
| 1135 | |
|---|
| 1136 | $lead=array(); |
|---|
| 1137 | $upload_files=array(); |
|---|
| 1138 | if(is_array($fields) && count($fields)>0){ |
|---|
| 1139 | foreach($fields as $field){ |
|---|
| 1140 | |
|---|
| 1141 | |
|---|
| 1142 | if(isset($field['name']) && isset($vals[$field['name']])){ |
|---|
| 1143 | $type=$field['type']; |
|---|
| 1144 | $id=$field['name']; |
|---|
| 1145 | $val=$vals[$field['name']]; |
|---|
| 1146 | $files=array(); |
|---|
| 1147 | |
|---|
| 1148 | if($type == 'file'){ |
|---|
| 1149 | // $settings = get_option('cforms_settings'); //cforms_upload_dir |
|---|
| 1150 | |
|---|
| 1151 | // if(!empty($settings['form'.$form_id]['cforms_upload_dir'])){ |
|---|
| 1152 | // $upload_dir=explode('$#$',$settings['form'.$form_id]['cforms_upload_dir']); |
|---|
| 1153 | // $val=trim($upload_dir[0],'/').'/'.$val; |
|---|
| 1154 | |
|---|
| 1155 | //} |
|---|
| 1156 | |
|---|
| 1157 | $upload_files[]=array('id'=>$id,'val'=>$val); |
|---|
| 1158 | |
|---|
| 1159 | |
|---|
| 1160 | }else{ |
|---|
| 1161 | if(isset($field['values'])){ |
|---|
| 1162 | $val=explode(',',$val); |
|---|
| 1163 | } |
|---|
| 1164 | $lead[$id]=$val; |
|---|
| 1165 | } |
|---|
| 1166 | } |
|---|
| 1167 | } |
|---|
| 1168 | $files=array(); |
|---|
| 1169 | if(is_array($upload_files) && isset($data['uploaded_files']) && is_array($data['uploaded_files'])){ |
|---|
| 1170 | foreach($upload_files as $k=>$v){ |
|---|
| 1171 | if(isset($data['uploaded_files'][$k]['name'])){ |
|---|
| 1172 | $files[$v['id']]=$data['uploaded_files'][$k]['name']; |
|---|
| 1173 | } |
|---|
| 1174 | } |
|---|
| 1175 | } |
|---|
| 1176 | $uploaded_files=$this->copy_files($files); |
|---|
| 1177 | if(is_array($uploaded_files) && count($uploaded_files)>0){ |
|---|
| 1178 | foreach($uploaded_files as $k=>$v){ |
|---|
| 1179 | $lead[$k]=$v; |
|---|
| 1180 | } |
|---|
| 1181 | } |
|---|
| 1182 | if(count($lead)>0){ |
|---|
| 1183 | $form_arr=array('id'=>$form_id,'name'=>$form['name'],'fields'=>$fields); |
|---|
| 1184 | $this->create_entry($lead,$form_arr,'c2'); |
|---|
| 1185 | } |
|---|
| 1186 | } |
|---|
| 1187 | |
|---|
| 1188 | |
|---|
| 1189 | } |
|---|
| 1190 | public function create_entry_fd($entry_id,$form_id){ |
|---|
| 1191 | $track=$this->track_form_entry('fd',$form_id); |
|---|
| 1192 | |
|---|
| 1193 | $fields=vxcf_form::get_form_fields('fd_'.$form_id); |
|---|
| 1194 | global $wpdb; |
|---|
| 1195 | $table=$wpdb->prefix.'frm_item_metas'; |
|---|
| 1196 | $sql=$wpdb->prepare("Select * from $table where item_id=%d",$entry_id); |
|---|
| 1197 | $entry=$wpdb->get_results($sql,ARRAY_A); |
|---|
| 1198 | $detail=array(); |
|---|
| 1199 | if(is_array($entry) && count($entry)>0){ |
|---|
| 1200 | foreach($entry as $v){ |
|---|
| 1201 | $detail[$v['field_id']]=$v['meta_value']; |
|---|
| 1202 | } |
|---|
| 1203 | } |
|---|
| 1204 | //var_dump($tags); die(); |
|---|
| 1205 | $lead=array(); |
|---|
| 1206 | if(is_array($fields)){ |
|---|
| 1207 | $uploaded_files_form=array(); |
|---|
| 1208 | foreach($fields as $k=>$v){ |
|---|
| 1209 | |
|---|
| 1210 | $name=$v['name']; |
|---|
| 1211 | if(isset($detail[$name])){ |
|---|
| 1212 | $val=maybe_unserialize($detail[$name]); |
|---|
| 1213 | if($v['type'] == 'file'){ |
|---|
| 1214 | $base_url=get_site_url(); |
|---|
| 1215 | if(!is_array($val)){ |
|---|
| 1216 | $val=array($val); |
|---|
| 1217 | } |
|---|
| 1218 | $files=array(); |
|---|
| 1219 | foreach($val as $vv){ |
|---|
| 1220 | if(!empty($vv)){ |
|---|
| 1221 | $vv= wp_get_attachment_url($vv) ; |
|---|
| 1222 | $files[]=str_replace($base_url,trim(ABSPATH,'/'),$vv); |
|---|
| 1223 | } } |
|---|
| 1224 | $uploaded_files_form[$name]=$files; |
|---|
| 1225 | |
|---|
| 1226 | } |
|---|
| 1227 | $lead[$name]=$detail[$name]; |
|---|
| 1228 | } |
|---|
| 1229 | } |
|---|
| 1230 | // |
|---|
| 1231 | if($track){ |
|---|
| 1232 | $uploaded_files_form=$this->copy_files($uploaded_files_form); |
|---|
| 1233 | } |
|---|
| 1234 | if(is_array($uploaded_files_form)){ |
|---|
| 1235 | foreach($uploaded_files_form as $k=>$v){ |
|---|
| 1236 | $lead[$k]=$v; |
|---|
| 1237 | } |
|---|
| 1238 | } |
|---|
| 1239 | } //var_dump($lead,$uploaded_files_form); die(); |
|---|
| 1240 | global $wpdb; |
|---|
| 1241 | $table=$wpdb->prefix.'frm_forms'; |
|---|
| 1242 | $sql=$wpdb->prepare("Select name from $table where id=%d",$form_id); |
|---|
| 1243 | $form_name=$wpdb->get_var($sql); |
|---|
| 1244 | $form_arr=array('id'=>$form_id,'name'=>$form_name,'fields'=>$fields); |
|---|
| 1245 | $this->create_entry($lead,$form_arr,'fd','',$track); |
|---|
| 1246 | |
|---|
| 1247 | } |
|---|
| 1248 | public function create_entry_gf($entry,$form){ |
|---|
| 1249 | $track=$this->track_form_entry('gf',$form['id']); |
|---|
| 1250 | |
|---|
| 1251 | $fields=vxcf_form::get_form_fields('gf_'.$form['id']); |
|---|
| 1252 | $uploaded_files_form =$lead=array(); |
|---|
| 1253 | if( is_array($fields)){ |
|---|
| 1254 | foreach($fields as $field){ |
|---|
| 1255 | $id=$field['id']; |
|---|
| 1256 | $is_name=false; |
|---|
| 1257 | if(isset($field['type']) && in_array($field['type'],array('name','address'))){ |
|---|
| 1258 | $id=(string)$id; $is_name=true; |
|---|
| 1259 | } |
|---|
| 1260 | if(isset($entry[$id])){ |
|---|
| 1261 | $val=$entry[$id]; |
|---|
| 1262 | if(isset($field['type']) ){ |
|---|
| 1263 | if($field['type'] == 'file'){ |
|---|
| 1264 | $file_arr=json_decode($val,true); |
|---|
| 1265 | if(is_array($file_arr)){ |
|---|
| 1266 | $val=$file_arr; |
|---|
| 1267 | } |
|---|
| 1268 | $uploaded_files_form[$id]=$val; |
|---|
| 1269 | }else if(in_array($field['type'],array('radio','multiselect'))){ |
|---|
| 1270 | $val=explode(',',$val); |
|---|
| 1271 | } |
|---|
| 1272 | } |
|---|
| 1273 | if(!empty($val)){ |
|---|
| 1274 | $lead[$id]=$val; |
|---|
| 1275 | } |
|---|
| 1276 | }else if(!$is_name){ |
|---|
| 1277 | // This is for checkboxes |
|---|
| 1278 | $elements = array(); |
|---|
| 1279 | foreach($entry as $key => $value) { |
|---|
| 1280 | if(is_numeric($key) && floor($key) == floor($id) && !empty($value)) { |
|---|
| 1281 | $elements[] = htmlspecialchars($value); |
|---|
| 1282 | }} |
|---|
| 1283 | $lead[$id]=$elements; |
|---|
| 1284 | } } |
|---|
| 1285 | } |
|---|
| 1286 | |
|---|
| 1287 | |
|---|
| 1288 | if($track){ |
|---|
| 1289 | $uploaded_files_form=$this->copy_files($uploaded_files_form); |
|---|
| 1290 | } |
|---|
| 1291 | if(is_array($uploaded_files_form)){ |
|---|
| 1292 | foreach($uploaded_files_form as $k=>$v){ |
|---|
| 1293 | $lead[$k]=$v; |
|---|
| 1294 | } |
|---|
| 1295 | } |
|---|
| 1296 | |
|---|
| 1297 | $form_arr=array('id'=>$form['id'],'name'=>$form['title'],'fields'=>$form['fields']); |
|---|
| 1298 | $this->create_entry($lead,$form_arr,'gf','',$track); |
|---|
| 1299 | // var_dump($lead); die(); |
|---|
| 1300 | } |
|---|
| 1301 | public function create_entry_fscf($data){ |
|---|
| 1302 | if(!isset($data->posted_data)){ |
|---|
| 1303 | return ; |
|---|
| 1304 | } |
|---|
| 1305 | $form_id=$data->form_number; |
|---|
| 1306 | $track=$this->track_form_entry('fs',$form_id); |
|---|
| 1307 | if($track === false){ |
|---|
| 1308 | return; |
|---|
| 1309 | } |
|---|
| 1310 | |
|---|
| 1311 | $form_title=$data->title; |
|---|
| 1312 | $post=$data->posted_data; |
|---|
| 1313 | $files=$data->uploaded_files; |
|---|
| 1314 | // |
|---|
| 1315 | $uploaded_files=$this->copy_files($files); |
|---|
| 1316 | |
|---|
| 1317 | $fields=vxcf_form::get_form_fields('fs_'.$form_id); |
|---|
| 1318 | |
|---|
| 1319 | $lead=array(); |
|---|
| 1320 | if(is_array($fields)){ |
|---|
| 1321 | foreach($fields as $k=>$v){ |
|---|
| 1322 | $name=$v['name']; |
|---|
| 1323 | $val=''; |
|---|
| 1324 | if(isset($uploaded_files[$name])){ |
|---|
| 1325 | $val=$uploaded_files[$name]; |
|---|
| 1326 | }else if(isset($_POST[$name])){ |
|---|
| 1327 | $val=vxcf_form::post($name); |
|---|
| 1328 | } |
|---|
| 1329 | |
|---|
| 1330 | |
|---|
| 1331 | if(!empty($val)){ |
|---|
| 1332 | $lead[$name]=$val; |
|---|
| 1333 | } |
|---|
| 1334 | } |
|---|
| 1335 | } |
|---|
| 1336 | |
|---|
| 1337 | $form_arr=array('id'=>$form_id,'name'=>$form_title,'fields'=>$fields); |
|---|
| 1338 | $this->create_entry($lead,$form_arr,'fs'); |
|---|
| 1339 | |
|---|
| 1340 | |
|---|
| 1341 | } |
|---|
| 1342 | public function copy_files($uploaded_files_form){ |
|---|
| 1343 | $uploaded_files=array(); |
|---|
| 1344 | if(is_array($uploaded_files_form) && count($uploaded_files_form)>0){ |
|---|
| 1345 | $upload=self::get_upload_dir(); |
|---|
| 1346 | $upload_path=$upload['path']; |
|---|
| 1347 | $folder=$upload['folder']; |
|---|
| 1348 | $base_url=get_site_url(); |
|---|
| 1349 | // ini_set('display_errors', '1'); |
|---|
| 1350 | //ini_set('display_startup_errors', '1'); |
|---|
| 1351 | //error_reporting(E_ALL); |
|---|
| 1352 | if($upload_path){ |
|---|
| 1353 | foreach($uploaded_files_form as $k=>$file_arr){ |
|---|
| 1354 | if(empty($file_arr)){ |
|---|
| 1355 | continue; |
|---|
| 1356 | } |
|---|
| 1357 | if(!is_array($file_arr)){ |
|---|
| 1358 | $file_arr=array($file_arr); |
|---|
| 1359 | } |
|---|
| 1360 | $files=array(); |
|---|
| 1361 | foreach($file_arr as $file){ |
|---|
| 1362 | if(empty($file)){ |
|---|
| 1363 | continue; |
|---|
| 1364 | } |
|---|
| 1365 | if(strpos($file,$base_url) === 0){ |
|---|
| 1366 | $file=str_replace($base_url,trim(ABSPATH,'/'),$file); |
|---|
| 1367 | } |
|---|
| 1368 | |
|---|
| 1369 | $file_name_arr=explode('/',$file); |
|---|
| 1370 | $file_name=$file_name_arr[count($file_name_arr)-1]; |
|---|
| 1371 | $file_name=sanitize_file_name($file_name); |
|---|
| 1372 | $file_name = wp_unique_filename( $upload_path, $file_name ); |
|---|
| 1373 | $dest=$upload_path.'/'.$file_name; |
|---|
| 1374 | |
|---|
| 1375 | $copy=copy($file,$dest); |
|---|
| 1376 | /* if(!$copy){ |
|---|
| 1377 | $file=str_replace(ltrim(ABSPATH,'/'),'',$file); |
|---|
| 1378 | $dest=str_replace(ABSPATH,'',$dest); |
|---|
| 1379 | $copy=copy($file,$dest); |
|---|
| 1380 | } */ |
|---|
| 1381 | $uploaded_file=$file; |
|---|
| 1382 | $path=''; |
|---|
| 1383 | if($copy){ |
|---|
| 1384 | chmod($dest, 0644); |
|---|
| 1385 | $uploaded_file=$folder.'/'.$file_name; |
|---|
| 1386 | $files[]=$uploaded_file; |
|---|
| 1387 | } |
|---|
| 1388 | } |
|---|
| 1389 | $uploaded_files[$k]=$files; |
|---|
| 1390 | } |
|---|
| 1391 | } |
|---|
| 1392 | } |
|---|
| 1393 | return $uploaded_files; |
|---|
| 1394 | } |
|---|
| 1395 | public function get_forms_jetpack(){ |
|---|
| 1396 | return get_posts( array( |
|---|
| 1397 | 'numberposts' => -1, |
|---|
| 1398 | 'orderby' => 'ID', |
|---|
| 1399 | 'order' => 'ASC', |
|---|
| 1400 | 'post_type' => 'jetpack' |
|---|
| 1401 | ) ); |
|---|
| 1402 | } |
|---|
| 1403 | public function get_meta(){ |
|---|
| 1404 | if(is_null(self::$meta)){ |
|---|
| 1405 | self::$meta=get_option(vxcf_form::$id.'_meta',array()); |
|---|
| 1406 | } |
|---|
| 1407 | return self::$meta; |
|---|
| 1408 | } |
|---|
| 1409 | public function track_form_entry($type,$form_id){ |
|---|
| 1410 | $meta=$this->get_meta(); |
|---|
| 1411 | $res=true; |
|---|
| 1412 | if(!empty($meta['save_forms']) && empty($meta['save_forms'][$type.'_'.$form_id])){ |
|---|
| 1413 | $res=false; |
|---|
| 1414 | }else if(!empty($meta['disable_track']) && !empty($meta['disable_track'][$type.'_'.$form_id])){ |
|---|
| 1415 | $res=false; |
|---|
| 1416 | } |
|---|
| 1417 | return $res; |
|---|
| 1418 | } |
|---|
| 1419 | public function get_form_jetpack($id=''){ |
|---|
| 1420 | return get_post($id); |
|---|
| 1421 | } |
|---|
| 1422 | public function get_fields_jetpack($post){ |
|---|
| 1423 | $text=$post->post_content; |
|---|
| 1424 | $pattern = '/\[(\[?)(contact-field)(?![\w-])([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)/'; |
|---|
| 1425 | preg_match_all($pattern, $text, $matches, PREG_SET_ORDER); |
|---|
| 1426 | $fields=array(); |
|---|
| 1427 | if(is_array($matches) && count($matches)>0){ |
|---|
| 1428 | foreach($matches as $m){ |
|---|
| 1429 | if(isset($m[3])){ |
|---|
| 1430 | $str=trim($m[3]); |
|---|
| 1431 | $fields[]=shortcode_parse_atts(trim($m[3])); |
|---|
| 1432 | |
|---|
| 1433 | } |
|---|
| 1434 | } |
|---|
| 1435 | } |
|---|
| 1436 | return $fields; |
|---|
| 1437 | } |
|---|
| 1438 | public function get_forms_fscf(){ |
|---|
| 1439 | //fast secure form |
|---|
| 1440 | $global=get_option( 'fs_contact_global'); |
|---|
| 1441 | $forms=array(); |
|---|
| 1442 | if(isset($global['form_list'])){ |
|---|
| 1443 | $forms=$global['form_list']; |
|---|
| 1444 | } |
|---|
| 1445 | return $forms; |
|---|
| 1446 | } |
|---|
| 1447 | public function get_fields_fscf($form_id){ |
|---|
| 1448 | $fields_arr=array(); |
|---|
| 1449 | if(method_exists('FSCF_Util','get_form_options')){ |
|---|
| 1450 | $options=FSCF_Util::get_form_options($form_id, true); |
|---|
| 1451 | if(isset($options['fields']) && is_array($options['fields'])){ |
|---|
| 1452 | $fields=$options['fields']; |
|---|
| 1453 | foreach($fields as $field){ |
|---|
| 1454 | $field['name']=$field['slug']; |
|---|
| 1455 | $fields_arr[]=$field; |
|---|
| 1456 | } |
|---|
| 1457 | } |
|---|
| 1458 | } |
|---|
| 1459 | return $fields_arr; |
|---|
| 1460 | } |
|---|
| 1461 | public function validate_crmperks_field($err_msg,$field_val,$field,$form){ |
|---|
| 1462 | if(empty($err_msg) && !empty($field_val) && !empty($field['dup_check']) && !empty($form['id'])){ |
|---|
| 1463 | $data=self::get_data_object(); |
|---|
| 1464 | $row=$data->search_lead_detail($field_val,'vf_'.$form['id']); |
|---|
| 1465 | //varify no duplicate fields |
|---|
| 1466 | if(!empty($row)){ |
|---|
| 1467 | if($field['valid_err_msg']!=""){ |
|---|
| 1468 | $err_msg=str_replace(array("%field_value%"),array($field_val),$field['valid_err_msg']); |
|---|
| 1469 | }else{ |
|---|
| 1470 | $err_msg=sprintf(__("%s Already Exists",'contact-form-entries'),$field_val); |
|---|
| 1471 | } |
|---|
| 1472 | } |
|---|
| 1473 | } |
|---|
| 1474 | |
|---|
| 1475 | return $err_msg; |
|---|
| 1476 | } |
|---|
| 1477 | public static function file_link($file_url,$base_url=''){ |
|---|
| 1478 | if(filter_var($file_url,FILTER_VALIDATE_URL) === false){ |
|---|
| 1479 | if(empty($base_url)){ |
|---|
| 1480 | $upload=vxcf_form::get_upload_dir(); |
|---|
| 1481 | $base_url=$upload['url']; |
|---|
| 1482 | } |
|---|
| 1483 | $file_url=esc_url($base_url.$file_url); |
|---|
| 1484 | } |
|---|
| 1485 | |
|---|
| 1486 | if(filter_var($file_url,FILTER_VALIDATE_URL)){ |
|---|
| 1487 | $file_arr=explode('/',$file_url); |
|---|
| 1488 | $file_name=$file_arr[count($file_arr)-1]; |
|---|
| 1489 | $file_url='<div><a href="'.esc_url($file_url).'" target="_blank">'.esc_html($file_name)."</a></div>"; |
|---|
| 1490 | } |
|---|
| 1491 | return $file_url; |
|---|
| 1492 | } |
|---|
| 1493 | public function get_ip(){ |
|---|
| 1494 | $ip=''; |
|---|
| 1495 | if (!empty($_SERVER['HTTP_CLIENT_IP'])) { |
|---|
| 1496 | $ip = $_SERVER['HTTP_CLIENT_IP']; |
|---|
| 1497 | } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|---|
| 1498 | $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; |
|---|
| 1499 | } else { |
|---|
| 1500 | $ip = $_SERVER['REMOTE_ADDR']; |
|---|
| 1501 | } |
|---|
| 1502 | if(strpos($ip,',')!== false){ |
|---|
| 1503 | $a=explode(',',$ip); |
|---|
| 1504 | if(isset($a[1])){ $ip=trim($a[1]);} |
|---|
| 1505 | } |
|---|
| 1506 | return $ip; |
|---|
| 1507 | } |
|---|
| 1508 | /** |
|---|
| 1509 | * all form fields + addon fields |
|---|
| 1510 | * |
|---|
| 1511 | * @param mixed $form_id |
|---|
| 1512 | */ |
|---|
| 1513 | public function get_all_fields($form_id){ |
|---|
| 1514 | if($this->fields ){ |
|---|
| 1515 | return $this->fields; |
|---|
| 1516 | } |
|---|
| 1517 | $tags=vxcf_form::get_form_fields($form_id); |
|---|
| 1518 | if(is_array($tags)){ |
|---|
| 1519 | foreach($tags as $id=>$tag){ |
|---|
| 1520 | $fields[$id]=array('id'=>$id,'label'=>$tag); |
|---|
| 1521 | } |
|---|
| 1522 | } |
|---|
| 1523 | |
|---|
| 1524 | $this->fields=$fields=apply_filters('vx_mapping_standard_fields',array('gf'=>array("title"=>__('Contact Form Fields','contact-form-entries'),"fields"=>$fields))); |
|---|
| 1525 | ///var_dump($fields); die(); |
|---|
| 1526 | return $fields; |
|---|
| 1527 | } |
|---|
| 1528 | /** |
|---|
| 1529 | * Create or edit crm feed page |
|---|
| 1530 | * |
|---|
| 1531 | */ |
|---|
| 1532 | public function print_page(){ |
|---|
| 1533 | if(!current_user_can(vxcf_form::$id."_edit_settings")){ |
|---|
| 1534 | die(); |
|---|
| 1535 | } |
|---|
| 1536 | $id=vxcf_form::post('id'); |
|---|
| 1537 | $form_id=vxcf_form::post('form_id'); |
|---|
| 1538 | $ids=array(); |
|---|
| 1539 | if(!empty($id)){ |
|---|
| 1540 | $ids=explode(',',$id); |
|---|
| 1541 | } |
|---|
| 1542 | |
|---|
| 1543 | self::$data=vxcf_form::get_data_object(); |
|---|
| 1544 | $msgs=array(); $is_valid=true; |
|---|
| 1545 | $fields=$leads=array(); |
|---|
| 1546 | |
|---|
| 1547 | $include_notes=isset($_GET['notes']) && $_GET['notes'] == '1' ? true : false; |
|---|
| 1548 | |
|---|
| 1549 | if(is_array($ids) && count($ids)>0){ |
|---|
| 1550 | foreach($ids as $id){ |
|---|
| 1551 | $id=(int)$id; |
|---|
| 1552 | if(!empty($id)){ |
|---|
| 1553 | $entry=apply_filters('vxcf_entries_print_lead',self::$data->get_lead_detail($id),$id); |
|---|
| 1554 | if(!empty($entry)){ |
|---|
| 1555 | $lead=array(); |
|---|
| 1556 | $lead['lead']=$entry; |
|---|
| 1557 | if($include_notes){ |
|---|
| 1558 | $lead['notes']=self::$data->get_lead_notes($id); |
|---|
| 1559 | } |
|---|
| 1560 | $leads[$id]=$lead; |
|---|
| 1561 | } |
|---|
| 1562 | } |
|---|
| 1563 | } |
|---|
| 1564 | } |
|---|
| 1565 | |
|---|
| 1566 | if(empty($leads)){ |
|---|
| 1567 | _e('No Entry Found', 'contact-form-entries'); |
|---|
| 1568 | } |
|---|
| 1569 | |
|---|
| 1570 | if(!empty(self::$form_fields)){ |
|---|
| 1571 | $fields=self::$form_fields; |
|---|
| 1572 | }else{ |
|---|
| 1573 | $fields=vxcf_form::get_form_fields($form_id); |
|---|
| 1574 | } |
|---|
| 1575 | |
|---|
| 1576 | //var_dump($leads,$fields);die(); |
|---|
| 1577 | include_once(self::$path . "templates/print.php"); |
|---|
| 1578 | exit; |
|---|
| 1579 | } |
|---|
| 1580 | /** |
|---|
| 1581 | * gravity forms field select options |
|---|
| 1582 | * |
|---|
| 1583 | * @param mixed $form_id |
|---|
| 1584 | * @param mixed $selected_val |
|---|
| 1585 | */ |
|---|
| 1586 | public function form_fields_options($form_id,$selected_val=""){ |
|---|
| 1587 | if($this->fields == null){ |
|---|
| 1588 | $this->fields=$this->get_all_fields($form_id); |
|---|
| 1589 | } |
|---|
| 1590 | $sel="<option value=''></option>"; |
|---|
| 1591 | $fields=$this->fields; |
|---|
| 1592 | if(is_array($fields)){ |
|---|
| 1593 | foreach($fields as $key=>$fields_arr){ |
|---|
| 1594 | if(is_array($fields_arr['fields'])){ |
|---|
| 1595 | $sel.="<optgroup label='".$fields_arr['title']."'>"; |
|---|
| 1596 | foreach($fields_arr['fields'] as $k=>$v){ |
|---|
| 1597 | $option_k=$k; |
|---|
| 1598 | $option_name=$v; |
|---|
| 1599 | |
|---|
| 1600 | $option_name=$v['label']; |
|---|
| 1601 | |
|---|
| 1602 | $select=""; |
|---|
| 1603 | if($selected_val == $option_k){ |
|---|
| 1604 | $select='selected="selected"'; |
|---|
| 1605 | |
|---|
| 1606 | } |
|---|
| 1607 | $sel.='<option value="'.$option_k.'" '.$select.'>'.$option_name.'</option>'; |
|---|
| 1608 | } } |
|---|
| 1609 | }} |
|---|
| 1610 | return $sel; |
|---|
| 1611 | } |
|---|
| 1612 | /** |
|---|
| 1613 | * uninstall plugin |
|---|
| 1614 | * |
|---|
| 1615 | */ |
|---|
| 1616 | public function uninstall(){ |
|---|
| 1617 | //droping all tables |
|---|
| 1618 | require_once(self::$path . "includes/install.php"); |
|---|
| 1619 | $install=new vxg_install_nimble(); |
|---|
| 1620 | do_action('plugin_status_'.$install->id); |
|---|
| 1621 | $install->remove_data(); |
|---|
| 1622 | $install->remove_roles(); |
|---|
| 1623 | } |
|---|
| 1624 | |
|---|
| 1625 | /** |
|---|
| 1626 | * deactivate |
|---|
| 1627 | * |
|---|
| 1628 | * @param mixed $action |
|---|
| 1629 | */ |
|---|
| 1630 | public function deactivate($action="deactivate"){ |
|---|
| 1631 | do_action('plugin_status_'.vxcf_form::$type,$action); |
|---|
| 1632 | } |
|---|
| 1633 | /** |
|---|
| 1634 | * activate plugin |
|---|
| 1635 | * |
|---|
| 1636 | */ |
|---|
| 1637 | public function activate(){ |
|---|
| 1638 | $this->plugin_api(true); |
|---|
| 1639 | $this->install_plugin(); |
|---|
| 1640 | do_action('plugin_status_'.vxcf_form::$type,'activate'); |
|---|
| 1641 | } |
|---|
| 1642 | /** |
|---|
| 1643 | * display admin notice |
|---|
| 1644 | * |
|---|
| 1645 | * @param mixed $type |
|---|
| 1646 | * @param mixed $message |
|---|
| 1647 | * @param mixed $id |
|---|
| 1648 | */ |
|---|
| 1649 | public static function display_msg($type,$message,$id=""){ |
|---|
| 1650 | //exp |
|---|
| 1651 | global $wp_version; |
|---|
| 1652 | $ver=floatval($wp_version); |
|---|
| 1653 | if($type == "admin"){ |
|---|
| 1654 | ?> |
|---|
| 1655 | <div class="error vx_notice below-h2 notice is-dismissible" data-id="<?php echo esc_attr($id) ?>"><p><span class="dashicons dashicons-megaphone"></span> <b><?php _e('Contact Form Entries Plugin','contact-form-entries') ?>. </b> <?php echo wp_kses_post($message);?> </p> |
|---|
| 1656 | </div> |
|---|
| 1657 | <?php |
|---|
| 1658 | }else{ |
|---|
| 1659 | ?> |
|---|
| 1660 | <tr class="plugin-update-tr"><td colspan="5" class="plugin-update"> |
|---|
| 1661 | <style type="text/css"> .vx_msg a{color: #fff; text-decoration: underline;} .vx_msg a:hover{color: #eee} </style> |
|---|
| 1662 | <div style="background-color: rgba(224, 224, 224, 0.5); padding: 9px; margin: 0px 10px 10px 28px "><div style="background-color: #d54d21; padding: 5px 10px; color: #fff" class="vx_msg"> <span class="dashicons dashicons-info"></span> <?php echo wp_kses_post($message) ?> |
|---|
| 1663 | </div></div></td></tr> |
|---|
| 1664 | <?php |
|---|
| 1665 | } |
|---|
| 1666 | } |
|---|
| 1667 | |
|---|
| 1668 | public function do_actions(){ |
|---|
| 1669 | if(!is_object(self::$plugin) ){ $this->plugin_api(); } |
|---|
| 1670 | if(is_object(self::$plugin) && method_exists(self::$plugin,'valid_addons')){ |
|---|
| 1671 | return self::$plugin->valid_addons(); |
|---|
| 1672 | } |
|---|
| 1673 | |
|---|
| 1674 | return false; |
|---|
| 1675 | } |
|---|
| 1676 | |
|---|
| 1677 | |
|---|
| 1678 | |
|---|
| 1679 | public static function get_upload_folder(){ |
|---|
| 1680 | $folder=get_option('crm_perks_upload_folder',''); |
|---|
| 1681 | if(empty($folder)){ |
|---|
| 1682 | $folder=uniqid().rand(999999,999999999).rand(9999,9999999); |
|---|
| 1683 | update_option('crm_perks_upload_folder', $folder); |
|---|
| 1684 | } |
|---|
| 1685 | return self::$upload_folder.'/'.$folder; |
|---|
| 1686 | } |
|---|
| 1687 | public static function get_upload_dir(){ |
|---|
| 1688 | $upload_dir=wp_upload_dir(); |
|---|
| 1689 | $plugin_folder=self::get_upload_folder(); |
|---|
| 1690 | $time = current_time( 'mysql' ); |
|---|
| 1691 | $y = substr( $time, 0, 4 ); |
|---|
| 1692 | $m = substr( $time, 5, 2 ); |
|---|
| 1693 | $folder=$y.'/'.$m; |
|---|
| 1694 | $upload_path=$upload_dir['basedir'].'/'.$plugin_folder.'/'.$folder; |
|---|
| 1695 | if(!file_exists($upload_path)){ |
|---|
| 1696 | $dir=wp_mkdir_p($upload_path); |
|---|
| 1697 | if(!$dir){$upload_path=''; }else{ |
|---|
| 1698 | $files=array($upload_path.'/index.html',$upload_dir['basedir'].'/'.$plugin_folder.'/'.$y.'/index.html'); |
|---|
| 1699 | foreach($files as $file_name){ |
|---|
| 1700 | if ( ! file_exists( $file_name ) ) { |
|---|
| 1701 | if ( $file_handle = @fopen( $file_name, 'w' ) ) { |
|---|
| 1702 | fwrite( $file_handle, '' ); |
|---|
| 1703 | fclose( $file_handle ); |
|---|
| 1704 | } |
|---|
| 1705 | } } |
|---|
| 1706 | } |
|---|
| 1707 | } |
|---|
| 1708 | return array('path'=>$upload_path,'folder'=>$folder,'folder_name'=>self::$upload_folder,'url'=>$upload_dir['baseurl'].'/'.$plugin_folder.'/','dir'=>$upload_dir['basedir'].'/'.$plugin_folder.'/','basedir'=>$upload_dir['basedir']); |
|---|
| 1709 | } |
|---|
| 1710 | |
|---|
| 1711 | /** |
|---|
| 1712 | * Returns true if the current page is an Feed pages. Returns false if not |
|---|
| 1713 | * |
|---|
| 1714 | * @param mixed $page |
|---|
| 1715 | */ |
|---|
| 1716 | public static function is_crm_page($page=""){ |
|---|
| 1717 | if(empty($page)) { |
|---|
| 1718 | $page = vxcf_form::post("page"); |
|---|
| 1719 | } |
|---|
| 1720 | $tab= vxcf_form::post('tab'); |
|---|
| 1721 | if($page == vxcf_form::$id){ |
|---|
| 1722 | if($tab=='entries'){ |
|---|
| 1723 | return true; |
|---|
| 1724 | }else if($tab == 'settings'){ |
|---|
| 1725 | $ret=true; |
|---|
| 1726 | if(!empty($_GET['section']) && $_GET['section'] != 'entries_settings'){ |
|---|
| 1727 | $ret=false; |
|---|
| 1728 | } |
|---|
| 1729 | return $ret; |
|---|
| 1730 | } } |
|---|
| 1731 | return false; |
|---|
| 1732 | } |
|---|
| 1733 | public static function get_entry($lead_id){ |
|---|
| 1734 | $data=self::get_data_object(); |
|---|
| 1735 | return $data->get_lead($lead_id); |
|---|
| 1736 | } |
|---|
| 1737 | public static function get_entry_detail($lead_id){ |
|---|
| 1738 | $data=self::get_data_object(); |
|---|
| 1739 | return $data->get_lead_detail($lead_id); |
|---|
| 1740 | } |
|---|
| 1741 | |
|---|
| 1742 | public static function get_forms(){ |
|---|
| 1743 | // function submission($components, $contact_form, $mail) |
|---|
| 1744 | //prepare list of contact forms -- |
|---|
| 1745 | /// *NOTE* CF7 changed how it stores forms at some point, support legacy? |
|---|
| 1746 | $all_forms_db=get_option('vxcf_all_forms',array()); //disable saving forms |
|---|
| 1747 | $all_forms=array(); |
|---|
| 1748 | |
|---|
| 1749 | if(!is_array($all_forms)){ |
|---|
| 1750 | $all_forms=array(); |
|---|
| 1751 | } |
|---|
| 1752 | if(class_exists('WPCF7_ContactForm')){ |
|---|
| 1753 | if( !function_exists('wpcf7_contact_forms') ) { |
|---|
| 1754 | $cf_forms = get_posts( array( |
|---|
| 1755 | 'numberposts' => -1, |
|---|
| 1756 | 'orderby' => 'ID', |
|---|
| 1757 | 'order' => 'ASC', |
|---|
| 1758 | 'post_type' => 'wpcf7_contact_form' ) ); |
|---|
| 1759 | } |
|---|
| 1760 | else { |
|---|
| 1761 | $forms = wpcf7_contact_forms(); |
|---|
| 1762 | $cf_forms=array(); |
|---|
| 1763 | if(count($forms)>0){ |
|---|
| 1764 | foreach($forms as $k=>$f){ |
|---|
| 1765 | $v=new stdClass(); |
|---|
| 1766 | if( isset( $f->id ) ) { |
|---|
| 1767 | $v->ID = $f->id; // as serialized option data |
|---|
| 1768 | } |
|---|
| 1769 | if( isset( $f->title ) ) { |
|---|
| 1770 | $v->post_title = $f->title; // as serialized option data |
|---|
| 1771 | } |
|---|
| 1772 | $cf_forms[]=$v; |
|---|
| 1773 | } |
|---|
| 1774 | } |
|---|
| 1775 | } |
|---|
| 1776 | |
|---|
| 1777 | $forms_arr=isset($all_forms['cf']['forms']) && is_array($all_forms['cf']['forms']) ? $all_forms['cf']['forms'] : array(); //do not show deleted forms |
|---|
| 1778 | |
|---|
| 1779 | if(is_array($cf_forms) && count($cf_forms)>0){ |
|---|
| 1780 | $forms_arr=array(); |
|---|
| 1781 | foreach($cf_forms as $form){ |
|---|
| 1782 | if(!empty($form->post_title)){ |
|---|
| 1783 | $forms_arr[$form->ID]=$form->post_title; |
|---|
| 1784 | } |
|---|
| 1785 | } |
|---|
| 1786 | $all_forms['cf']=array('label'=>'Contact Form 7','forms'=>$forms_arr); |
|---|
| 1787 | } |
|---|
| 1788 | /////// |
|---|
| 1789 | } |
|---|
| 1790 | if(class_exists('cfx_form')){ |
|---|
| 1791 | |
|---|
| 1792 | $forms =cfx_form::get_forms(); |
|---|
| 1793 | // $forms = vx_form_admin_pages::get_forms(); |
|---|
| 1794 | $forms_arr=array(); |
|---|
| 1795 | |
|---|
| 1796 | if(is_array($forms) && count($forms)>0){ |
|---|
| 1797 | foreach($forms as $form){ |
|---|
| 1798 | if(!empty($form['id'])){ |
|---|
| 1799 | $forms_arr[$form['id']]= !empty($form['name'] ) ? $form['name'] : '#'.$form['id']; |
|---|
| 1800 | } |
|---|
| 1801 | } |
|---|
| 1802 | |
|---|
| 1803 | $all_forms['vf']=array('label'=>'CRM Perks Forms','forms'=>$forms_arr); |
|---|
| 1804 | } |
|---|
| 1805 | /////// |
|---|
| 1806 | } |
|---|
| 1807 | if(defined('ELEMENTOR_PRO_VERSION') ){ //&& class_exists('ElementorPro\\Plugin') |
|---|
| 1808 | global $wpdb; |
|---|
| 1809 | $data = $wpdb->get_results( "SELECT m.post_id, m.meta_value,p.post_title FROM $wpdb->postmeta m inner join $wpdb->posts p on(m.post_id=p.ID) WHERE p.post_status='publish' and m.meta_key = '_elementor_data' limit 70" , ARRAY_A ); //__elementor_forms_snapshot |
|---|
| 1810 | $forms_arr=array(); |
|---|
| 1811 | |
|---|
| 1812 | foreach($data as $v){ |
|---|
| 1813 | $elforms=json_decode($v['meta_value'],true); |
|---|
| 1814 | $elforms=self::find_el_forms($elforms); |
|---|
| 1815 | foreach($elforms as $form){ |
|---|
| 1816 | $id=$form['id'].'_'.$v['post_id']; |
|---|
| 1817 | |
|---|
| 1818 | $forms_arr[$id]=$form['settings']['form_name'].' - '.substr($v['post_title'],0,200); |
|---|
| 1819 | |
|---|
| 1820 | } |
|---|
| 1821 | } |
|---|
| 1822 | if(!empty($all_forms_db['el']['forms'])){ |
|---|
| 1823 | foreach($all_forms_db['el']['forms'] as $k=>$v){ |
|---|
| 1824 | if(!isset($forms_arr[$k])){ $forms_arr[$k]=$v; } |
|---|
| 1825 | } |
|---|
| 1826 | |
|---|
| 1827 | } |
|---|
| 1828 | if(!empty($forms_arr)){ |
|---|
| 1829 | $all_forms['el']=array('label'=>'Elementor Forms','forms'=>$forms_arr); } |
|---|
| 1830 | // |
|---|
| 1831 | } |
|---|
| 1832 | |
|---|
| 1833 | if(class_exists('GFFormsModel')){ |
|---|
| 1834 | $gf_forms=GFFormsModel::get_forms(); |
|---|
| 1835 | $forms_arr=array(); |
|---|
| 1836 | if(is_array($gf_forms) && count($gf_forms)>0){ |
|---|
| 1837 | foreach($gf_forms as $form){ |
|---|
| 1838 | if(!empty($form->title)){ |
|---|
| 1839 | $forms_arr[$form->id]=$form->title; |
|---|
| 1840 | } |
|---|
| 1841 | } |
|---|
| 1842 | $all_forms['gf']=array('label'=>'Gravity Forms','forms'=>$forms_arr); |
|---|
| 1843 | } |
|---|
| 1844 | } |
|---|
| 1845 | //formidable |
|---|
| 1846 | if(class_exists('FrmForm')){ |
|---|
| 1847 | $gf_forms=FrmForm::getAll(array('status'=>'published','is_template'=>'0')); |
|---|
| 1848 | $forms_arr=isset($all_forms['fd']['forms']) && is_array($all_forms['fd']['forms']) ? $all_forms['fd']['forms'] : array(); |
|---|
| 1849 | if(is_array($gf_forms) && count($gf_forms)>0){ |
|---|
| 1850 | foreach($gf_forms as $form){ |
|---|
| 1851 | if(!empty($form->id)){ |
|---|
| 1852 | $forms_arr[$form->id]=$form->name; |
|---|
| 1853 | } |
|---|
| 1854 | } |
|---|
| 1855 | $all_forms['fd']=array('label'=>'Formidable Forms','forms'=>$forms_arr); |
|---|
| 1856 | } |
|---|
| 1857 | } |
|---|
| 1858 | |
|---|
| 1859 | if(class_exists('siContactForm')){ |
|---|
| 1860 | //fast secure form |
|---|
| 1861 | $global=get_option( 'fs_contact_global'); |
|---|
| 1862 | $fs_forms=array(); |
|---|
| 1863 | if(isset($global['form_list'])){ |
|---|
| 1864 | $fs_forms=$global['form_list']; |
|---|
| 1865 | } |
|---|
| 1866 | $forms_arr=isset($all_forms['fs']['forms']) && is_array($all_forms['fs']['forms']) ? $all_forms['fs']['forms'] : array(); |
|---|
| 1867 | if(is_array($fs_forms) && count($fs_forms)>0){ |
|---|
| 1868 | foreach($fs_forms as $k=>$v){ |
|---|
| 1869 | $forms_arr[$k]=$v; |
|---|
| 1870 | |
|---|
| 1871 | } |
|---|
| 1872 | $all_forms['fs']=array('label'=>'Fast Secure Contact Forms','forms'=>$forms_arr); |
|---|
| 1873 | } |
|---|
| 1874 | } |
|---|
| 1875 | |
|---|
| 1876 | if(class_exists('Grunion_Contact_Form_Plugin')){ |
|---|
| 1877 | global $wpdb; |
|---|
| 1878 | $sql="Select * from {$wpdb->postmeta} where meta_key='_g_feedback_shortcode' limit 300"; |
|---|
| 1879 | $posts=$wpdb->get_results($sql,ARRAY_A); |
|---|
| 1880 | |
|---|
| 1881 | $forms_arr=isset($all_forms['jp']['forms']) && is_array($all_forms['jp']['forms']) ? $all_forms['jp']['forms'] : array(); |
|---|
| 1882 | if(is_array($posts) && count($posts)>0){ |
|---|
| 1883 | foreach($posts as $k=>$v){ |
|---|
| 1884 | $title=get_the_title($v['post_id']); |
|---|
| 1885 | if(!empty($title)){ |
|---|
| 1886 | $forms_arr[$v['post_id']]=$title; |
|---|
| 1887 | } |
|---|
| 1888 | |
|---|
| 1889 | } |
|---|
| 1890 | $all_forms['jp']=array('label'=>'Jetpack Contact Forms','forms'=>$forms_arr); |
|---|
| 1891 | } |
|---|
| 1892 | } |
|---|
| 1893 | |
|---|
| 1894 | if(class_exists('Ninja_Forms') && method_exists(Ninja_Forms(),'form')){ |
|---|
| 1895 | //$forms = Ninja_Forms()->forms()->get_all(); |
|---|
| 1896 | $forms_arr=isset($all_forms['na']['forms']) && is_array($all_forms['na']['forms']) ? $all_forms['na']['forms'] : array(); |
|---|
| 1897 | global $wpdb; |
|---|
| 1898 | $sql = "SELECT `id`, `title`, `created_at` FROM `{$wpdb->prefix}nf3_forms` ORDER BY `title`"; |
|---|
| 1899 | $nf_forms = $wpdb->get_results($sql, ARRAY_A); |
|---|
| 1900 | // die(); |
|---|
| 1901 | //$nf_forms = nf_get_objects_by_type( 'form' ); |
|---|
| 1902 | if(is_array($nf_forms) && count($nf_forms)>0){ |
|---|
| 1903 | foreach($nf_forms as $form){ |
|---|
| 1904 | if(!empty($form['id'])){ |
|---|
| 1905 | // $title = Ninja_Forms()->form( $form['id'] )->get_setting( 'form_title' ); |
|---|
| 1906 | $forms_arr[$form['id']]=$form['title']; |
|---|
| 1907 | } |
|---|
| 1908 | } |
|---|
| 1909 | $all_forms['na']=array('label'=>'Ninja Forms','forms'=>$forms_arr); |
|---|
| 1910 | } |
|---|
| 1911 | |
|---|
| 1912 | } |
|---|
| 1913 | |
|---|
| 1914 | if(function_exists('iphorm_get_all_forms')){ |
|---|
| 1915 | |
|---|
| 1916 | $nf_forms = iphorm_get_all_forms(); |
|---|
| 1917 | $forms_arr=isset($all_forms['qu']['forms']) && is_array($all_forms['qu']['forms']) ? $all_forms['qu']['forms'] : array(); |
|---|
| 1918 | |
|---|
| 1919 | if(is_array($nf_forms) && count($nf_forms)>0){ |
|---|
| 1920 | foreach($nf_forms as $form){ |
|---|
| 1921 | if(!empty($form['id'])){ |
|---|
| 1922 | $forms_arr[$form['id']]=$form['name']; |
|---|
| 1923 | } |
|---|
| 1924 | } |
|---|
| 1925 | $all_forms['qu']=array('label'=>'Quform Forms','forms'=>$forms_arr); |
|---|
| 1926 | } |
|---|
| 1927 | |
|---|
| 1928 | } |
|---|
| 1929 | |
|---|
| 1930 | if(function_exists('cforms2_insert')){ |
|---|
| 1931 | |
|---|
| 1932 | $settings = get_option('cforms_settings'); //cforms_upload_dir |
|---|
| 1933 | $count=$settings['global']['cforms_formcount']; |
|---|
| 1934 | $forms_arr=isset($all_forms['c2']['forms']) && is_array($all_forms['c2']['forms']) ? $all_forms['c2']['forms'] : array(); |
|---|
| 1935 | for ($i=1; $i<=$count; $i++){ |
|---|
| 1936 | $j = ( $i > 1 )?$i:''; |
|---|
| 1937 | |
|---|
| 1938 | $forms_arr[$j]=stripslashes($settings['form'.$j]['cforms'.$j.'_fname']); |
|---|
| 1939 | } |
|---|
| 1940 | |
|---|
| 1941 | $all_forms['c2']=array('label'=>'CForms2 Forms','forms'=>$forms_arr); |
|---|
| 1942 | |
|---|
| 1943 | } |
|---|
| 1944 | if(class_exists('Caldera_Forms_Forms')){ |
|---|
| 1945 | |
|---|
| 1946 | $nf_forms = Caldera_Forms_Forms::get_forms(true,true); |
|---|
| 1947 | $forms_arr=isset($all_forms['ca']['forms']) && is_array($all_forms['ca']['forms']) ? $all_forms['ca']['forms'] : array(); |
|---|
| 1948 | |
|---|
| 1949 | if(is_array($nf_forms) && count($nf_forms)>0){ |
|---|
| 1950 | foreach($nf_forms as $form){ |
|---|
| 1951 | if(!empty($form['ID'])){ |
|---|
| 1952 | $forms_arr[$form['ID']]=$form['name']; |
|---|
| 1953 | } |
|---|
| 1954 | } |
|---|
| 1955 | $all_forms['ca']=array('label'=>'Caldera Forms','forms'=>$forms_arr); |
|---|
| 1956 | } |
|---|
| 1957 | |
|---|
| 1958 | } |
|---|
| 1959 | if(class_exists('UFBL_Model')){ |
|---|
| 1960 | $forms_arr=isset($all_forms['ul']['forms']) && is_array($all_forms['ul']['forms']) ? $all_forms['ul']['forms'] : array(); |
|---|
| 1961 | $ul_forms=UFBL_Model::get_all_forms(); |
|---|
| 1962 | if(is_array($ul_forms) && count($ul_forms)>0){ |
|---|
| 1963 | foreach($ul_forms as $k=>$v){ |
|---|
| 1964 | $forms_arr[$v->form_id]=$v->form_title; |
|---|
| 1965 | } |
|---|
| 1966 | } |
|---|
| 1967 | $all_forms['ul']=array('label'=>'Ultimate Contact Form Builder','forms'=>$forms_arr); |
|---|
| 1968 | } |
|---|
| 1969 | if(class_exists('Woocommerce')){ //disable woo |
|---|
| 1970 | // $all_forms['wc']=array('label'=>'WooCommerce','forms'=>array('1'=>'Woocommerce')); |
|---|
| 1971 | } |
|---|
| 1972 | if(function_exists('cntctfrm_settings')){ |
|---|
| 1973 | |
|---|
| 1974 | $all_forms['be']=array('label'=>'BestSoft Contact Forms','forms'=>array(''=>'Default Contact Form')); |
|---|
| 1975 | } |
|---|
| 1976 | |
|---|
| 1977 | if(function_exists('wpforms') && method_exists(wpforms()->form,'get')){ |
|---|
| 1978 | $forms_arr=wpforms()->form->get( '' ); |
|---|
| 1979 | if(!empty($forms_arr)){ |
|---|
| 1980 | $forms=array(); |
|---|
| 1981 | foreach($forms_arr as $v){ |
|---|
| 1982 | $forms[$v->ID]=$v->post_title; |
|---|
| 1983 | } |
|---|
| 1984 | $all_forms['wp']=array('label'=>'WP Forms','forms'=>$forms); |
|---|
| 1985 | //$forms=json_decode($forms->post_content,true); |
|---|
| 1986 | } |
|---|
| 1987 | } |
|---|
| 1988 | |
|---|
| 1989 | ksort($all_forms); |
|---|
| 1990 | return apply_filters('vx_entries_plugin_forms',$all_forms); |
|---|
| 1991 | } |
|---|
| 1992 | public static function forms_list($forms){ |
|---|
| 1993 | $forms_arr=array(); |
|---|
| 1994 | foreach($forms as $k=>$v){ |
|---|
| 1995 | if(in_array($k,array('vf'))){ continue; } |
|---|
| 1996 | if(!empty($v['forms'])){ |
|---|
| 1997 | foreach($v['forms'] as $form_id=>$form_title){ |
|---|
| 1998 | $forms_arr[$k.'_'.$form_id]=$v['label'].' - '.$form_title; |
|---|
| 1999 | } |
|---|
| 2000 | } |
|---|
| 2001 | } |
|---|
| 2002 | return $forms_arr; |
|---|
| 2003 | } |
|---|
| 2004 | /** |
|---|
| 2005 | * form fields |
|---|
| 2006 | * |
|---|
| 2007 | * @param mixed $form_id |
|---|
| 2008 | */ |
|---|
| 2009 | public static function get_form_fields($form_id){ |
|---|
| 2010 | $form_arr=explode('_',$form_id); |
|---|
| 2011 | $type=$id=''; |
|---|
| 2012 | $fields = array(); |
|---|
| 2013 | if(isset($form_arr[0])){ |
|---|
| 2014 | $type=$form_arr[0]; |
|---|
| 2015 | } |
|---|
| 2016 | if(isset($form_arr[1])){ |
|---|
| 2017 | $id=$form_arr[1]; |
|---|
| 2018 | } |
|---|
| 2019 | |
|---|
| 2020 | switch($type){ |
|---|
| 2021 | case'cf': |
|---|
| 2022 | if(method_exists('WPCF7_ShortcodeManager','get_instance') || method_exists('WPCF7_FormTagsManager','get_instance')){ |
|---|
| 2023 | |
|---|
| 2024 | $form_text=get_post_meta($id,'_form',true); |
|---|
| 2025 | |
|---|
| 2026 | if(method_exists('WPCF7_FormTagsManager','get_instance')){ |
|---|
| 2027 | $manager=WPCF7_FormTagsManager::get_instance(); |
|---|
| 2028 | $contents=$manager->scan($form_text); |
|---|
| 2029 | $tags=$manager->get_scanned_tags(); |
|---|
| 2030 | |
|---|
| 2031 | }else if(method_exists('WPCF7_ShortcodeManager','get_instance')){ // |
|---|
| 2032 | $manager = WPCF7_ShortcodeManager::get_instance(); |
|---|
| 2033 | $contents=$manager->do_shortcode($form_text); |
|---|
| 2034 | $tags=$manager->get_scanned_tags(); |
|---|
| 2035 | } |
|---|
| 2036 | if(isset($_GET['vx_crm_key'])){ |
|---|
| 2037 | |
|---|
| 2038 | } |
|---|
| 2039 | if(is_array($tags)){ |
|---|
| 2040 | foreach($tags as $tag){ //var_dump($tag); |
|---|
| 2041 | if(is_object($tag)){ $tag=(array)$tag; } |
|---|
| 2042 | |
|---|
| 2043 | if(!empty($tag['name'])){ |
|---|
| 2044 | |
|---|
| 2045 | $id=str_replace(' ','',$tag['name']); |
|---|
| 2046 | $field=array('name'=>$id); |
|---|
| 2047 | $field['label']=ucwords(str_replace(array('-','_')," ",$tag['name'])); |
|---|
| 2048 | $field['type_']=$tag['type']; |
|---|
| 2049 | $field['type']=$tag['basetype']; |
|---|
| 2050 | if($tag['basetype'] == 'mfile'){ $field['type']='file'; } |
|---|
| 2051 | $field['req']=strpos($tag['type'],'*') !==false ? 'true' : ''; |
|---|
| 2052 | |
|---|
| 2053 | if($field['type'] == 'select' && !empty($tag['options']) && array_search('multiple',$tag['options'])!== false){ |
|---|
| 2054 | $field['type']='multiselect'; |
|---|
| 2055 | } |
|---|
| 2056 | if(!empty($tag['raw_values'])){ |
|---|
| 2057 | $ops=array(); |
|---|
| 2058 | foreach($tag['raw_values'] as $v){ |
|---|
| 2059 | if(strpos($v,'|') !== false){ |
|---|
| 2060 | $v_arr=explode('|',$v); |
|---|
| 2061 | if(!isset($v_arr[1])){ $v_arr[1]=$v_arr[0]; } |
|---|
| 2062 | $ops[]=array('label'=>$v_arr[0],'value'=>$v_arr[1]); |
|---|
| 2063 | }else{ |
|---|
| 2064 | $ops[]=array('label'=>$v,'value'=>$v); |
|---|
| 2065 | } |
|---|
| 2066 | } |
|---|
| 2067 | $field['values']=$ops; |
|---|
| 2068 | } //var_dump($field); |
|---|
| 2069 | $fields[$id]=$field; |
|---|
| 2070 | } |
|---|
| 2071 | } |
|---|
| 2072 | } |
|---|
| 2073 | } |
|---|
| 2074 | break; |
|---|
| 2075 | case'fs': |
|---|
| 2076 | if(method_exists('FSCF_Util','get_form_options')){ |
|---|
| 2077 | $options=FSCF_Util::get_form_options($id, true); |
|---|
| 2078 | if(isset($options['fields']) && is_array($options['fields'])){ |
|---|
| 2079 | $fs_fields=$options['fields']; |
|---|
| 2080 | foreach($fs_fields as $field){ |
|---|
| 2081 | $field['name']=$field['slug']; |
|---|
| 2082 | if($field['type'] == 'attachment'){ |
|---|
| 2083 | $field['type']='file'; |
|---|
| 2084 | }else if($field['type'] == 'checkbox-multiple'){ |
|---|
| 2085 | $field['type']='checkbox'; |
|---|
| 2086 | }else if($field['type'] == 'select-multiple'){ |
|---|
| 2087 | $field['type']='multiselect'; |
|---|
| 2088 | } |
|---|
| 2089 | if(isset($field['options'])){ |
|---|
| 2090 | $opts_array = explode("\n",$field['options']); |
|---|
| 2091 | $options_arr=array(); $i=0; |
|---|
| 2092 | foreach($opts_array as $k=>$v){ |
|---|
| 2093 | $i++; |
|---|
| 2094 | if($field['type'] == 'select' && preg_match('/^\[(.*)]$/', $v, $matches)){ |
|---|
| 2095 | $v=$matches[1]; $i=0; |
|---|
| 2096 | }else if ( preg_match('/^(.*)(==)(.*)$/', $v, $matches) ) { |
|---|
| 2097 | // is this key==value set? Just display the value |
|---|
| 2098 | $v = $matches[3]; |
|---|
| 2099 | } |
|---|
| 2100 | //////// |
|---|
| 2101 | $options_arr[]=array('text'=>$v,'value'=>$i); |
|---|
| 2102 | } |
|---|
| 2103 | $field['values']=$options_arr; |
|---|
| 2104 | } |
|---|
| 2105 | |
|---|
| 2106 | $fields[]=$field; |
|---|
| 2107 | } |
|---|
| 2108 | } |
|---|
| 2109 | } |
|---|
| 2110 | break; |
|---|
| 2111 | case'jp': |
|---|
| 2112 | $text=get_post_meta($id,'_g_feedback_shortcode',true); |
|---|
| 2113 | $pattern = '/\[(\[?)(contact-field)(?![\w-])([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)/'; |
|---|
| 2114 | preg_match_all($pattern, $text, $matches, PREG_SET_ORDER); |
|---|
| 2115 | if(is_array($matches) && count($matches)>0){ |
|---|
| 2116 | foreach($matches as $m){ |
|---|
| 2117 | if(isset($m[3])){ |
|---|
| 2118 | $str=trim($m[3]); |
|---|
| 2119 | $field=shortcode_parse_atts(trim($m[3])); |
|---|
| 2120 | |
|---|
| 2121 | $field['req']=$field['required'] == '1' ? 'true' : ''; |
|---|
| 2122 | if(isset($field['type'])){ |
|---|
| 2123 | |
|---|
| 2124 | $field['values']=array(array('text'=>'','value'=>'Yes')); |
|---|
| 2125 | if($field['type'] == 'checkbox-multiple'){ |
|---|
| 2126 | $field['type']='checkbox'; |
|---|
| 2127 | } |
|---|
| 2128 | } |
|---|
| 2129 | if(!empty($field['options'])){ |
|---|
| 2130 | $field['values']=explode(',',$field['options']); |
|---|
| 2131 | } |
|---|
| 2132 | $field['name']=$field['label']; |
|---|
| 2133 | $fields[$field['label']]=$field; |
|---|
| 2134 | |
|---|
| 2135 | } |
|---|
| 2136 | } |
|---|
| 2137 | } |
|---|
| 2138 | break; |
|---|
| 2139 | case'na': |
|---|
| 2140 | if(class_exists('Ninja_Forms')){ |
|---|
| 2141 | |
|---|
| 2142 | $form_fields = Ninja_Forms()->form( $id )->get_fields(); //var_dump($form_fields); die('----------'); |
|---|
| 2143 | foreach ($form_fields as $obj) { |
|---|
| 2144 | $field=array(); |
|---|
| 2145 | if( is_object( $obj ) ) { |
|---|
| 2146 | $field = $obj->get_settings(); |
|---|
| 2147 | $field['id']= $obj->get_id(); |
|---|
| 2148 | } |
|---|
| 2149 | |
|---|
| 2150 | $arr=array('name'=>$field['id']); |
|---|
| 2151 | $type=$field['type']; |
|---|
| 2152 | if($type == 'textbox'){ $type='text'; } |
|---|
| 2153 | if($type == 'starrating'){ $type='text'; } |
|---|
| 2154 | if($type == 'file_upload'){ $type='file'; } |
|---|
| 2155 | if(in_array($type,array('spam','confirm','submit','repeater','save','html','hr')) ){ continue; } //|| !isset($field['required']) // it is not set for hidden fields that is why removed it |
|---|
| 2156 | if($type == 'checkbox'){ |
|---|
| 2157 | $arr['values']=array(array('text'=>$field['label'],'value'=>'1')); |
|---|
| 2158 | } |
|---|
| 2159 | if(in_array($type,array('listmultiselect','listcheckbox','listradio','listselect'))){ |
|---|
| 2160 | $type=ltrim($type,'list'); |
|---|
| 2161 | $vals=array(); |
|---|
| 2162 | if(!empty($field['options'])){ |
|---|
| 2163 | foreach($field['options'] as $v){ |
|---|
| 2164 | $vals[]=array('text'=>$v['label'],'value'=>$v['value']); |
|---|
| 2165 | } |
|---|
| 2166 | } |
|---|
| 2167 | $arr['values']=$vals; |
|---|
| 2168 | } |
|---|
| 2169 | |
|---|
| 2170 | $arr['type']=$type; |
|---|
| 2171 | $arr['label']=$field['label']; |
|---|
| 2172 | $arr['req']=!empty($field['required']) ? 'true' : 'false'; |
|---|
| 2173 | $fields[$field['id']]=$arr; |
|---|
| 2174 | } |
|---|
| 2175 | } |
|---|
| 2176 | break; |
|---|
| 2177 | case'fd': |
|---|
| 2178 | global $wpdb; |
|---|
| 2179 | $table=$wpdb->prefix.'frm_fields'; |
|---|
| 2180 | $sql=$wpdb->prepare("Select * from $table where form_id=%d",$id); |
|---|
| 2181 | $fields_arr=$wpdb->get_results($sql,ARRAY_A); |
|---|
| 2182 | if(count($fields_arr)>0){ |
|---|
| 2183 | foreach($fields_arr as $field){ |
|---|
| 2184 | $field['label']=$field['name']; |
|---|
| 2185 | $field['name']=$field['id']; |
|---|
| 2186 | if(!empty($field['options'])){ |
|---|
| 2187 | $field['values']=maybe_unserialize($field['options']); |
|---|
| 2188 | } |
|---|
| 2189 | $fields[$field['id']]=$field; |
|---|
| 2190 | } |
|---|
| 2191 | } |
|---|
| 2192 | break; |
|---|
| 2193 | case'na_test': |
|---|
| 2194 | global $ninja_forms_fields; var_dump($ninja_forms_fields); die(); |
|---|
| 2195 | if(is_array($ninja_forms_fields) && count($ninja_forms_fields)>0){ |
|---|
| 2196 | foreach($ninja_forms_fields as $field){ |
|---|
| 2197 | // $field['label']=$field['name']; |
|---|
| 2198 | // $field['name']=$field['id']; |
|---|
| 2199 | $field['type']=trim($field['type'],'_'); |
|---|
| 2200 | if(!empty($field['options'])){ |
|---|
| 2201 | $field['values']=maybe_unserialize($field['options']); |
|---|
| 2202 | } |
|---|
| 2203 | $fields[]=$field; |
|---|
| 2204 | } |
|---|
| 2205 | } |
|---|
| 2206 | break; |
|---|
| 2207 | case'c2': |
|---|
| 2208 | $settings = get_option('cforms_settings'); |
|---|
| 2209 | $count=$settings['global']['cforms_formcount']; |
|---|
| 2210 | $forms=array(); |
|---|
| 2211 | for($i=1; $i<500; $i++){ |
|---|
| 2212 | if(isset($settings['form'.$id]['cforms'.$id.'_count_field_'.$i])){ |
|---|
| 2213 | $field_str=stripslashes($settings['form'.$id]['cforms'.$id.'_count_field_'.$i]); |
|---|
| 2214 | |
|---|
| 2215 | $field_stat = explode('$#$', $field_str); |
|---|
| 2216 | |
|---|
| 2217 | |
|---|
| 2218 | $field_name = $field_stat[0]; |
|---|
| 2219 | $field_type = $field_stat[1]; |
|---|
| 2220 | $field_required = $field_stat[2] == '1' ? 'true' : ''; |
|---|
| 2221 | $field=array('req'=>$field_required); |
|---|
| 2222 | |
|---|
| 2223 | if ( in_array($field_type,array('multiselectbox','selectbox','radiobuttons','checkbox','checkboxgroup','ccbox','emailtobox')) ){ |
|---|
| 2224 | $field_name_arr=explode('#',$field_name); |
|---|
| 2225 | $field_name=$field_name_arr[0]; |
|---|
| 2226 | unset($field_name_arr[0]); |
|---|
| 2227 | $options=array(); |
|---|
| 2228 | if(count($field_name_arr)>0){ |
|---|
| 2229 | |
|---|
| 2230 | foreach($field_name_arr as $v){ |
|---|
| 2231 | $v=explode('|',$v); |
|---|
| 2232 | $option['value']=$option['label']=$v[0]; |
|---|
| 2233 | |
|---|
| 2234 | if(isset($v[1]) && $field_type!='selectbox'){ |
|---|
| 2235 | $option['value']=$v[1]; |
|---|
| 2236 | } |
|---|
| 2237 | $options[]=$option; |
|---|
| 2238 | |
|---|
| 2239 | } |
|---|
| 2240 | } |
|---|
| 2241 | $field['values']=$options; |
|---|
| 2242 | } |
|---|
| 2243 | if ( in_array($field_type,array('checkbox','checkboxgroup')) ){ |
|---|
| 2244 | $field_type='checkbox'; |
|---|
| 2245 | }else if ( in_array($field_type,array('selectbox','ccbox','emailtobox')) ){ |
|---|
| 2246 | $field_type='select'; |
|---|
| 2247 | }else if ( in_array($field_type,array('multiselectbox')) ){ |
|---|
| 2248 | $field_type='multiselect'; |
|---|
| 2249 | }else if ( in_array($field_type,array('radiobuttons')) ){ |
|---|
| 2250 | $field_type='radio'; |
|---|
| 2251 | }else if ( in_array($field_type,array('upload')) ){ |
|---|
| 2252 | $field_type='file'; |
|---|
| 2253 | } |
|---|
| 2254 | if(!empty($field_name)){ |
|---|
| 2255 | $field_name=explode('|',$field_name); |
|---|
| 2256 | $field_name =$field_name[0]; |
|---|
| 2257 | $field['label']=$field_name; |
|---|
| 2258 | $field['name']=$i; |
|---|
| 2259 | $field['type']=$field_type; |
|---|
| 2260 | $fields[$i]=$field; |
|---|
| 2261 | } |
|---|
| 2262 | }else{ |
|---|
| 2263 | break; |
|---|
| 2264 | } |
|---|
| 2265 | } |
|---|
| 2266 | break; |
|---|
| 2267 | case'ca': |
|---|
| 2268 | if(class_exists('Caldera_Forms')){ |
|---|
| 2269 | $field_types=Caldera_Forms::get_field_types(); |
|---|
| 2270 | $form=get_option($id); |
|---|
| 2271 | if(isset($form['fields']) && is_array($form['fields']) && count($form['fields'])>0){ |
|---|
| 2272 | foreach($form['fields'] as $field){ |
|---|
| 2273 | $type=$field['type']; |
|---|
| 2274 | $field_id=$field['ID']; |
|---|
| 2275 | if(isset($field_types[$type])){ |
|---|
| 2276 | if(!isset($form['fields'][$field_id]) || !isset($field_types[$form['fields'][$field_id]['type']])){ |
|---|
| 2277 | continue; |
|---|
| 2278 | } |
|---|
| 2279 | |
|---|
| 2280 | if(isset($field_types[$form['fields'][$field_id]['type']]['setup']['not_supported'])){ |
|---|
| 2281 | if(in_array('entry_list', $field_types[$form['fields'][$field_id]['type']]['setup']['not_supported'])){ |
|---|
| 2282 | continue; |
|---|
| 2283 | } |
|---|
| 2284 | } |
|---|
| 2285 | if($type == 'paragraph'){ |
|---|
| 2286 | $type='textarea'; |
|---|
| 2287 | }else if($type == 'filtered_select2'){ |
|---|
| 2288 | $type='select'; |
|---|
| 2289 | }else if($type == 'advanced_file'){ |
|---|
| 2290 | $type='file'; |
|---|
| 2291 | } |
|---|
| 2292 | $req=false; |
|---|
| 2293 | if(isset($field['data']['required'])){ |
|---|
| 2294 | $req=$field['data']['required'] == 1 ? 'true': 'false'; |
|---|
| 2295 | } |
|---|
| 2296 | $field['req']=$req; |
|---|
| 2297 | if(isset($field['config']['option']) && is_array($field['config']['option'])){ |
|---|
| 2298 | $options=array(); |
|---|
| 2299 | foreach($field['config']['option'] as $k=>$v){ |
|---|
| 2300 | if($v['value'] == ''){ |
|---|
| 2301 | $v['value']=$v['label']; |
|---|
| 2302 | } |
|---|
| 2303 | $options[]=$v; |
|---|
| 2304 | } |
|---|
| 2305 | $field['values']=$options; |
|---|
| 2306 | } |
|---|
| 2307 | $field['type']=$type; |
|---|
| 2308 | $field['name']=$field_id; |
|---|
| 2309 | $fields[$field_id]=$field; |
|---|
| 2310 | } |
|---|
| 2311 | } |
|---|
| 2312 | } |
|---|
| 2313 | } |
|---|
| 2314 | break; |
|---|
| 2315 | case'qu': |
|---|
| 2316 | /*$form=iphorm_get_form(1); |
|---|
| 2317 | $elems=$form->getElements(); |
|---|
| 2318 | foreach($elems as $k=>$v){ |
|---|
| 2319 | var_dump($v); |
|---|
| 2320 | } */ |
|---|
| 2321 | if(function_exists('iphorm_get_form_config')){ |
|---|
| 2322 | $form = iphorm_get_form_config($id); |
|---|
| 2323 | if(isset($form['elements']) && is_array($form['elements'])){ |
|---|
| 2324 | |
|---|
| 2325 | foreach($form['elements'] as $k=>$v){ |
|---|
| 2326 | if(isset($v['save_to_database']) && $v['save_to_database'] == true){ |
|---|
| 2327 | if(isset($v['options'])){ |
|---|
| 2328 | $v['values']=$v['options']; |
|---|
| 2329 | } |
|---|
| 2330 | $v['req']= isset($v['required']) && $v['required'] == true ? 'true' : 'false'; |
|---|
| 2331 | $v['name']=$v['id']; |
|---|
| 2332 | $fields[]=$v; |
|---|
| 2333 | } |
|---|
| 2334 | } |
|---|
| 2335 | } |
|---|
| 2336 | } |
|---|
| 2337 | break; |
|---|
| 2338 | case'be': |
|---|
| 2339 | $be_fields=array('name'=>'Name','email'=>'Email','address'=>'Address','phone'=>'Phone Number','subject'=>'Subject','message'=>'Message','file'=>'Attachment'); |
|---|
| 2340 | $fields=array(); |
|---|
| 2341 | foreach($be_fields as $k=>$v){ |
|---|
| 2342 | $type='text'; |
|---|
| 2343 | if(in_array($k,array('subject','address'))){ |
|---|
| 2344 | $type='textarea'; |
|---|
| 2345 | }else if($k == 'file'){ |
|---|
| 2346 | $type='file'; |
|---|
| 2347 | } |
|---|
| 2348 | $fields[$k]=array('name'=>$k,'label'=>$v,'type'=>$type); |
|---|
| 2349 | } |
|---|
| 2350 | break; |
|---|
| 2351 | case'vxad': |
|---|
| 2352 | global $vxcf_crm; |
|---|
| 2353 | if(method_exists($vxcf_crm,'get_form_fields')){ |
|---|
| 2354 | $fields=$vxcf_crm->get_form_fields(true); |
|---|
| 2355 | } |
|---|
| 2356 | break; |
|---|
| 2357 | case'el_new': |
|---|
| 2358 | |
|---|
| 2359 | if(isset($form_arr[2])){ |
|---|
| 2360 | $post_id=$form_arr[2]; |
|---|
| 2361 | |
|---|
| 2362 | $formsp=get_post_meta($post_id,'__elementor_forms_snapshot',true); |
|---|
| 2363 | $form=array(); |
|---|
| 2364 | if(!empty($formsp)){ |
|---|
| 2365 | $forms=json_decode($formsp,true); |
|---|
| 2366 | foreach($forms as $v){ |
|---|
| 2367 | if($v['id'] == $id){ |
|---|
| 2368 | $form=$v; |
|---|
| 2369 | } |
|---|
| 2370 | } |
|---|
| 2371 | $fields=array(); |
|---|
| 2372 | if(!empty($form['form'])){ |
|---|
| 2373 | foreach($form['form'] as $tag){ |
|---|
| 2374 | if(!empty($tag['id']) ){ |
|---|
| 2375 | if(empty($tag['type'])){ $tag['type']=$tag['id']; } |
|---|
| 2376 | if(!in_array($tag['type'],array('html','step','honeypot','recaptcha','recaptcha_v3'))){ |
|---|
| 2377 | $field=array('id'=>$tag['id']); |
|---|
| 2378 | $field['name']=$tag['id']; |
|---|
| 2379 | $field['label']=$tag['label']; |
|---|
| 2380 | $field['type']=$tag['type']; |
|---|
| 2381 | $field['req']=!empty($tag['required']) ? 'true' : ''; |
|---|
| 2382 | if(!empty($tag['allow_multiple']) ){ |
|---|
| 2383 | $field['type']='multiselect'; |
|---|
| 2384 | } |
|---|
| 2385 | if($field['type'] == 'acceptance'){ |
|---|
| 2386 | $field['type']='checkbox'; |
|---|
| 2387 | $field['values']=array(array('label'=>$tag['acceptance_text'],'value'=>'on')); |
|---|
| 2388 | } |
|---|
| 2389 | if($field['type'] == 'upload'){ |
|---|
| 2390 | $field['type']='file'; |
|---|
| 2391 | } |
|---|
| 2392 | if(!empty($tag['field_options'])){ |
|---|
| 2393 | $opts_array=explode("\n",$tag['field_options']); |
|---|
| 2394 | $ops=array(); |
|---|
| 2395 | foreach($opts_array as $v){ |
|---|
| 2396 | $v_arr=explode('|',$v); |
|---|
| 2397 | if(!isset($v_arr[1])){ $v_arr[1]=$v_arr[0]; } |
|---|
| 2398 | $ops[]=array('label'=>$v_arr[0],'value'=>$v_arr[1]); |
|---|
| 2399 | } |
|---|
| 2400 | $field['values']=$ops; |
|---|
| 2401 | } |
|---|
| 2402 | $fields[$tag['custom_id']]=$field; |
|---|
| 2403 | } } |
|---|
| 2404 | } |
|---|
| 2405 | } |
|---|
| 2406 | } |
|---|
| 2407 | |
|---|
| 2408 | } |
|---|
| 2409 | break; |
|---|
| 2410 | case'el': |
|---|
| 2411 | if(isset($form_arr[2])){ |
|---|
| 2412 | $post_id=$form_arr[2]; |
|---|
| 2413 | $forms=get_post_meta($post_id,'_elementor_data',true); |
|---|
| 2414 | $forms=json_decode($forms,true); |
|---|
| 2415 | if(!empty($forms)){ |
|---|
| 2416 | $form=self::find_el_form($forms,$id); |
|---|
| 2417 | |
|---|
| 2418 | if(!empty($form['form_fields'])){ |
|---|
| 2419 | foreach($form['form_fields'] as $tag){ |
|---|
| 2420 | if(!empty($tag['custom_id']) ){ |
|---|
| 2421 | if(empty($tag['field_type'])){ $tag['field_type']=$tag['custom_id']; } |
|---|
| 2422 | if(!in_array($tag['field_type'],array('html','step','honeypot','recaptcha','recaptcha_v3'))){ |
|---|
| 2423 | $field=array('id'=>$tag['custom_id']); |
|---|
| 2424 | $field['name']=$tag['custom_id']; |
|---|
| 2425 | $field['label']=$tag['field_label']; |
|---|
| 2426 | $field['type']=$tag['field_type']; |
|---|
| 2427 | $field['req']=!empty($tag['required']) ? 'true' : ''; |
|---|
| 2428 | if(!empty($tag['allow_multiple']) ){ |
|---|
| 2429 | $field['type']='multiselect'; |
|---|
| 2430 | } |
|---|
| 2431 | if($field['type'] == 'acceptance'){ |
|---|
| 2432 | $field['type']='checkbox'; |
|---|
| 2433 | $field['values']=array(array('label'=>$tag['acceptance_text'],'value'=>'on')); |
|---|
| 2434 | } |
|---|
| 2435 | if($field['type'] == 'upload'){ |
|---|
| 2436 | $field['type']='file'; |
|---|
| 2437 | } |
|---|
| 2438 | if(!empty($tag['field_options'])){ |
|---|
| 2439 | $opts_array=explode("\n",$tag['field_options']); |
|---|
| 2440 | $ops=array(); |
|---|
| 2441 | foreach($opts_array as $v){ |
|---|
| 2442 | $v_arr=explode('|',$v); |
|---|
| 2443 | if(!isset($v_arr[1])){ $v_arr[1]=$v_arr[0]; } |
|---|
| 2444 | $ops[]=array('label'=>$v_arr[0],'value'=>$v_arr[1]); |
|---|
| 2445 | } |
|---|
| 2446 | $field['values']=$ops; |
|---|
| 2447 | } |
|---|
| 2448 | $fields[$tag['custom_id']]=$field; |
|---|
| 2449 | } } |
|---|
| 2450 | } |
|---|
| 2451 | } |
|---|
| 2452 | } |
|---|
| 2453 | |
|---|
| 2454 | } |
|---|
| 2455 | break; |
|---|
| 2456 | case'vxad': |
|---|
| 2457 | global $vxcf_crm; |
|---|
| 2458 | if(method_exists($vxcf_crm,'get_form_fields')){ |
|---|
| 2459 | $fields=$vxcf_crm->get_form_fields(true); |
|---|
| 2460 | } |
|---|
| 2461 | |
|---|
| 2462 | |
|---|
| 2463 | break; |
|---|
| 2464 | case'vf': |
|---|
| 2465 | if(method_exists('cfx_form','get_form')){ |
|---|
| 2466 | $fields=array(); |
|---|
| 2467 | $form= cfx_form::get_form($id,true); |
|---|
| 2468 | if(!empty($form['fields'])){ |
|---|
| 2469 | foreach($form['fields'] as $f_id=>$tag){ |
|---|
| 2470 | if(!empty($tag['label'])){//var_dump($tag); |
|---|
| 2471 | $field=array('id'=>$f_id); |
|---|
| 2472 | $field['name']=$f_id; |
|---|
| 2473 | $field['label']=$tag['label']; |
|---|
| 2474 | $field['type']=$tag['type']; |
|---|
| 2475 | $field['req']=!empty($tag['required']) ? 'true' : ''; |
|---|
| 2476 | //$tag['field_val']=trim($tag['field_val']); |
|---|
| 2477 | if(!empty($tag['options'])){ |
|---|
| 2478 | $field['values']=$tag['options']; |
|---|
| 2479 | } |
|---|
| 2480 | $fields[$f_id]=$field; |
|---|
| 2481 | } |
|---|
| 2482 | } |
|---|
| 2483 | } |
|---|
| 2484 | } |
|---|
| 2485 | break; |
|---|
| 2486 | case'ul': |
|---|
| 2487 | if(method_exists('UFBL_Model','get_form_detail')){ |
|---|
| 2488 | $form= UFBL_Model::get_form_detail($id); |
|---|
| 2489 | if(!empty($form['form_detail'])){ |
|---|
| 2490 | $ul_fields=maybe_unserialize($form['form_detail']); //var_dump($ul_fields['field_data']); die(); |
|---|
| 2491 | if(is_array($ul_fields['field_data']) && count($ul_fields['field_data'])>0){ |
|---|
| 2492 | foreach($ul_fields['field_data'] as $k=>$field){ |
|---|
| 2493 | if(isset($field['error_message'])){ |
|---|
| 2494 | $type=$field['field_type']; |
|---|
| 2495 | if($type == 'dropdown'){ |
|---|
| 2496 | $type='select'; |
|---|
| 2497 | if(isset($field['multiple']) && $field['multiple'] == '1'){ |
|---|
| 2498 | $type='multiselect'; |
|---|
| 2499 | } |
|---|
| 2500 | } |
|---|
| 2501 | $field['type']=$type; |
|---|
| 2502 | $field['name']=$k; |
|---|
| 2503 | $field['label']=$field['field_label']; |
|---|
| 2504 | $field['req']=isset($field['required']) && $field['required'] == '1' ? 'true' : ''; |
|---|
| 2505 | if(isset($field['option'])){ |
|---|
| 2506 | $field['values']=$field['option']; |
|---|
| 2507 | } |
|---|
| 2508 | $fields[$k]=$field; |
|---|
| 2509 | } |
|---|
| 2510 | } |
|---|
| 2511 | } |
|---|
| 2512 | } |
|---|
| 2513 | } |
|---|
| 2514 | break; |
|---|
| 2515 | case'gf': |
|---|
| 2516 | if(method_exists('RGFormsModel','get_form_meta')){ |
|---|
| 2517 | $form = RGFormsModel::get_form_meta($id); |
|---|
| 2518 | ///var_dump( $form['fields'] ); |
|---|
| 2519 | $fields=array(); |
|---|
| 2520 | if(isset($form['fields']) && is_array($form['fields']) && count($form['fields'])>0){ |
|---|
| 2521 | foreach($form['fields'] as $field){ |
|---|
| 2522 | $tag=array('id'=>$field->id,'name'=>$field->id.'','label'=>$field->label); |
|---|
| 2523 | $type=$field->type; |
|---|
| 2524 | if($type == 'fileupload'){ |
|---|
| 2525 | $type='file'; |
|---|
| 2526 | }else if($type == 'text'){ |
|---|
| 2527 | $type='textarea'; |
|---|
| 2528 | }else if($type == 'website'){ |
|---|
| 2529 | $type='url'; |
|---|
| 2530 | }else if($type == 'phone'){ |
|---|
| 2531 | $type='tel'; |
|---|
| 2532 | }else if($type == 'list'){ |
|---|
| 2533 | $type='textarea'; |
|---|
| 2534 | } |
|---|
| 2535 | $tag['req']=$field->isRequired !==false ? 'true' : ''; |
|---|
| 2536 | if(isset($field->choices)){ |
|---|
| 2537 | $tag['values']=$field->choices; |
|---|
| 2538 | } |
|---|
| 2539 | $tag['type']=$type; |
|---|
| 2540 | if(in_array($type,array('name','address')) && isset($field->inputs) && count($field->inputs)>0){ |
|---|
| 2541 | foreach($field->inputs as $k=>$v){ |
|---|
| 2542 | if(isset($v['isHidden'])){ |
|---|
| 2543 | continue; |
|---|
| 2544 | } |
|---|
| 2545 | $v['name']=(string)$v['id']; |
|---|
| 2546 | $v['type']=$field['type']; |
|---|
| 2547 | if(isset($v['choices']) && is_array($v['choices']) && count($v['choices'])>0){ |
|---|
| 2548 | $v['type']='select'; |
|---|
| 2549 | $v['values']=$v['choices']; |
|---|
| 2550 | } |
|---|
| 2551 | $fields[]=$v; |
|---|
| 2552 | } |
|---|
| 2553 | }else{ |
|---|
| 2554 | $fields[]=$tag; |
|---|
| 2555 | } |
|---|
| 2556 | |
|---|
| 2557 | } |
|---|
| 2558 | } |
|---|
| 2559 | } |
|---|
| 2560 | break; |
|---|
| 2561 | case'wc': |
|---|
| 2562 | $json='{"billing_first_name":"First name","billing_last_name":"Last name","billing_company":"Company name","billing_country":"Country","billing_address_1":"Address","billing_address_2":"Address 2","billing_city":"Town \/ City","billing_state":"State \/ County","billing_postcode":"Postcode \/ ZIP","billing_phone":"Phone","billing_email":"Email address","shipping_first_name":"First name","shipping_last_name":"Last name","shipping_company":"Company name","shipping_country":"Country","shipping_address_1":"Address","shipping_address_2":"Address 2","shipping_city":"Town \/ City","shipping_state":"State \/ County","shipping_postcode":"Postcode \/ ZIP","order_note":"Order Note","order_id":"Order ID","_customer_user":"User ID","qty":"Quantity","_order_total":"Order Total"}'; |
|---|
| 2563 | $arr=json_decode($json,true); |
|---|
| 2564 | $fields=array(); |
|---|
| 2565 | foreach($arr as $k=>$v){ |
|---|
| 2566 | $label='Shipping '; |
|---|
| 2567 | if(strpos($k,'billing') !== false){ $label='Billing '; } |
|---|
| 2568 | $field=array('id'=>'_'.$k,'name'=>'_'.$k,'label'=>$label.$v,'type'=>'text'); |
|---|
| 2569 | if($k == 'billing_email'){ |
|---|
| 2570 | $field['type']='email'; |
|---|
| 2571 | }else if($k == 'billing_phone'){ |
|---|
| 2572 | $field['type']='tel'; |
|---|
| 2573 | }else if(in_array($k,array('billing_address_1','billing_address_2','shipping_address_1','shipping_address_2','order_note'))){ |
|---|
| 2574 | $field['type']='textarea'; |
|---|
| 2575 | }else if(in_array($k,array('billing_state','shipping_state'))){ |
|---|
| 2576 | $field['type']='state'; |
|---|
| 2577 | }else if(in_array($k,array('billing_country','shipping_country'))){ |
|---|
| 2578 | $field['type']='country'; |
|---|
| 2579 | } |
|---|
| 2580 | $fields[]=$field; |
|---|
| 2581 | } |
|---|
| 2582 | |
|---|
| 2583 | break; |
|---|
| 2584 | case'wp': |
|---|
| 2585 | if(function_exists('wpforms') && method_exists(wpforms()->form,'get')){ |
|---|
| 2586 | $forms_arr=wpforms()->form->get( $id ); |
|---|
| 2587 | if(!empty($forms_arr)){ |
|---|
| 2588 | $form=json_decode($forms_arr->post_content,true); |
|---|
| 2589 | $fields=array(); |
|---|
| 2590 | foreach($form['fields'] as $v){ |
|---|
| 2591 | $type=$v['type']; |
|---|
| 2592 | if($type == 'name'){ $type='text'; } |
|---|
| 2593 | if($type == 'payment-select'){ $type='select'; } |
|---|
| 2594 | if($type == 'payment-multiple'){ $type='radio'; } |
|---|
| 2595 | if($type == 'payment-single'){ $type='text'; } |
|---|
| 2596 | if($type == 'file-upload'){ $type='file'; } |
|---|
| 2597 | if($type == 'date-time'){ $type='date'; } |
|---|
| 2598 | if($type == 'address'){ $type='textarea'; } |
|---|
| 2599 | if($type == 'phone'){ $type='tel'; } |
|---|
| 2600 | $label=isset($v['label']) ? $v['label'] : $type; |
|---|
| 2601 | // if(in_array($type,array('text','textarea','email','number','hidden','select','checkbox','radio','url','password','tel','date','file','number-slider'))){ |
|---|
| 2602 | $field=array('id'=>$v['id'],'name'=>$v['id'],'label'=>$label,'type'=>$type); |
|---|
| 2603 | $field['req']=!empty($v['required']) ? true : false; |
|---|
| 2604 | if(in_array($type,array('radio','checkbox','select'))){ |
|---|
| 2605 | $is_val=false; |
|---|
| 2606 | if(in_array($v['type'],array('payment-select','payment-multiple')) ){ $is_val=true; } //|| (isset($v['show_values'])&& $v['show_values'] ='1' ) front form submission always sends label , not value , we will have to find value from form fields and store real value |
|---|
| 2607 | $choices=array(); |
|---|
| 2608 | if(!empty($v['choices'])){ |
|---|
| 2609 | foreach($v['choices'] as $c){ |
|---|
| 2610 | $c_val=$is_val ? $c['value'] : $c['label']; |
|---|
| 2611 | $choices[]=array('text'=>$c['label'],'value'=>$c_val); |
|---|
| 2612 | } |
|---|
| 2613 | } |
|---|
| 2614 | $field['values']=$choices; |
|---|
| 2615 | } |
|---|
| 2616 | $fields[$v['id']]=$field; |
|---|
| 2617 | // } |
|---|
| 2618 | |
|---|
| 2619 | } |
|---|
| 2620 | } } //var_dump($form['fields']); |
|---|
| 2621 | break; |
|---|
| 2622 | } |
|---|
| 2623 | |
|---|
| 2624 | //allow custom form fields |
|---|
| 2625 | if(empty($fields)){ |
|---|
| 2626 | $fields=apply_filters('vx_entries_plugin_form_fields',$fields,$id,$type); |
|---|
| 2627 | } |
|---|
| 2628 | |
|---|
| 2629 | if(empty($fields)){ |
|---|
| 2630 | //try from stored option |
|---|
| 2631 | $option=get_option('vxcf_all_fields',array()); |
|---|
| 2632 | |
|---|
| 2633 | if(!empty($option[$type]['fields'][$id]) && is_array($option[$type]['fields'][$id])){ |
|---|
| 2634 | $fields=$option[$type]['fields'][$id]; |
|---|
| 2635 | } |
|---|
| 2636 | } |
|---|
| 2637 | |
|---|
| 2638 | $fields_a=array(); |
|---|
| 2639 | if(is_array($fields) && count($fields)>0){ |
|---|
| 2640 | foreach($fields as $k=>$v){ |
|---|
| 2641 | if(isset($v['name']) && $v['name'] != ''){ |
|---|
| 2642 | $v['_id']=$form_id.'-vxvx-'.preg_replace("/[^a-zA-Z0-9]+/", "", $v['name']); |
|---|
| 2643 | $fields_a[$v['name']]=$v; |
|---|
| 2644 | } |
|---|
| 2645 | } |
|---|
| 2646 | } |
|---|
| 2647 | $fields_b=apply_filters('vxcf_entries_plugin_fields', $fields_a,$form_id); |
|---|
| 2648 | |
|---|
| 2649 | self::$form_fields_temp[$form_id]=$fields_b; |
|---|
| 2650 | |
|---|
| 2651 | return $fields_b; |
|---|
| 2652 | } |
|---|
| 2653 | public static function check_option_value($options,$value){ |
|---|
| 2654 | $arr=array(); |
|---|
| 2655 | if(!is_array($value)){$value=array($value); } |
|---|
| 2656 | foreach($value as $v){ |
|---|
| 2657 | $arr[$v]=$v; |
|---|
| 2658 | } |
|---|
| 2659 | if(!empty($options)){ |
|---|
| 2660 | foreach($value as $val){ |
|---|
| 2661 | foreach($options as $option){ |
|---|
| 2662 | if(is_array($option)){ |
|---|
| 2663 | if(isset($option['text'])){ |
|---|
| 2664 | $label=$option['text']; |
|---|
| 2665 | }else if(isset($option['label'])){ |
|---|
| 2666 | $label=$option['label']; |
|---|
| 2667 | } |
|---|
| 2668 | if(isset($option['value']) && $option['value'] == $val){ |
|---|
| 2669 | $arr[$val]=$label; |
|---|
| 2670 | } |
|---|
| 2671 | } |
|---|
| 2672 | } |
|---|
| 2673 | } } |
|---|
| 2674 | return array_values($arr); |
|---|
| 2675 | } |
|---|
| 2676 | |
|---|
| 2677 | public static function get_entries($form_id,$per_page,$page='',$req=array()){ |
|---|
| 2678 | $data=array(); |
|---|
| 2679 | $data_obj=vxcf_form::get_data_object(); |
|---|
| 2680 | if(!empty($form_id)){ |
|---|
| 2681 | $data= $data_obj->get_entries($form_id,$per_page,$req); |
|---|
| 2682 | if(!empty($data['result'])){ |
|---|
| 2683 | $data['result']=apply_filters('vxcf_entries_plugin_leads_table',$data['result'],$form_id,$page); |
|---|
| 2684 | } } |
|---|
| 2685 | return $data; |
|---|
| 2686 | } |
|---|
| 2687 | /** |
|---|
| 2688 | * admin_screen_message function. |
|---|
| 2689 | * |
|---|
| 2690 | * @param mixed $message |
|---|
| 2691 | * @param mixed $level |
|---|
| 2692 | */ |
|---|
| 2693 | public static function screen_msg( $message, $level = 'updated') { |
|---|
| 2694 | echo '<div class="'. esc_attr( $level ) .' fade below-h2 notice is-dismissible"><p>'; |
|---|
| 2695 | echo wp_kses_post($message); |
|---|
| 2696 | echo '</p></div>'; |
|---|
| 2697 | } |
|---|
| 2698 | /** |
|---|
| 2699 | * settings link |
|---|
| 2700 | * |
|---|
| 2701 | * @param mixed $escaped |
|---|
| 2702 | */ |
|---|
| 2703 | public static function link_to_settings( $tab='entries' ) { |
|---|
| 2704 | $q=array('page'=>vxcf_form::$id); |
|---|
| 2705 | if(!empty($tab)){ |
|---|
| 2706 | $q['tab']=$tab; |
|---|
| 2707 | } |
|---|
| 2708 | $url = admin_url('admin.php?'.http_build_query($q)); |
|---|
| 2709 | |
|---|
| 2710 | return $url; |
|---|
| 2711 | } |
|---|
| 2712 | public static function set_form_fields($form_id=''){ |
|---|
| 2713 | |
|---|
| 2714 | if(empty(self::$form_fields)){ |
|---|
| 2715 | self::$forms=$forms=vxcf_form::get_forms(); |
|---|
| 2716 | if(empty($form_id)){ |
|---|
| 2717 | $form_id=vxcf_form::post('form_id'); |
|---|
| 2718 | } |
|---|
| 2719 | self::$form_id=esc_sql($form_id); |
|---|
| 2720 | if(empty(self::$form_id) && !empty(self::$forms)){ |
|---|
| 2721 | $form_key=key($forms); |
|---|
| 2722 | if(isset($forms[$form_key]['forms']) && is_array($forms[$form_key]['forms'])){ |
|---|
| 2723 | $form_i=key($forms[$form_key]['forms']); |
|---|
| 2724 | } |
|---|
| 2725 | self::$form_id=$form_key.'_'.$form_i; |
|---|
| 2726 | } |
|---|
| 2727 | |
|---|
| 2728 | if(!empty(self::$form_id)){ |
|---|
| 2729 | $fields_arr=vxcf_form::get_form_fields(self::$form_id); |
|---|
| 2730 | $fields_arr['vxbrowser']=array('_id'=>self::$form_id.'-vxvx-vxbrowser','name'=>'vxbrowser','label'=>__('System','contact-form-entries'),'is_main'=>'true'); |
|---|
| 2731 | $fields_arr['vxurl']=array('_id'=>self::$form_id.'-vxvx-vxurl','name'=>'vxurl','label'=>__('Source','contact-form-entries'),'is_main'=>'true'); |
|---|
| 2732 | |
|---|
| 2733 | $fields_arr['vxscreen']=array('_id'=>self::$form_id.'-vxvx-vxscreen','name'=>'vxscreen','label'=>__('Screen','contact-form-entries'),'is_main'=>'true'); |
|---|
| 2734 | |
|---|
| 2735 | $fields_arr['vxupdated']=array('_id'=>self::$form_id.'-vxvx-vxupdated','name'=>'vxupdated','label'=>__('Updated','contact-form-entries'),'hide_in_search'=>'true','is_main'=>'true'); |
|---|
| 2736 | |
|---|
| 2737 | $fields_arr['vxcreated']=array('_id'=>self::$form_id.'-vxvx-vxcreated','name'=>'vxcreated','label'=>__('Created','contact-form-entries'),'hide_in_search'=>'true','is_main'=>'true'); |
|---|
| 2738 | |
|---|
| 2739 | self::$form_fields=$fields_arr; |
|---|
| 2740 | } |
|---|
| 2741 | } |
|---|
| 2742 | |
|---|
| 2743 | } |
|---|
| 2744 | public function footer_js(){ |
|---|
| 2745 | ?> |
|---|
| 2746 | <script type="text/javascript"> |
|---|
| 2747 | window.addEventListener("load", function(event) { |
|---|
| 2748 | jQuery(".cfx_form_main,.wpcf7-form,.wpforms-form,.gform_wrapper form").each(function(){ |
|---|
| 2749 | var form=jQuery(this); |
|---|
| 2750 | var screen_width=""; var screen_height=""; |
|---|
| 2751 | if(screen_width == ""){ |
|---|
| 2752 | if(screen){ |
|---|
| 2753 | screen_width=screen.width; |
|---|
| 2754 | }else{ |
|---|
| 2755 | screen_width=jQuery(window).width(); |
|---|
| 2756 | } } |
|---|
| 2757 | if(screen_height == ""){ |
|---|
| 2758 | if(screen){ |
|---|
| 2759 | screen_height=screen.height; |
|---|
| 2760 | }else{ |
|---|
| 2761 | screen_height=jQuery(window).height(); |
|---|
| 2762 | } } |
|---|
| 2763 | form.append('<input type="hidden" name="vx_width" value="'+screen_width+'">'); |
|---|
| 2764 | form.append('<input type="hidden" name="vx_height" value="'+screen_height+'">'); |
|---|
| 2765 | form.append('<input type="hidden" name="vx_url" value="'+window.location.href+'">'); |
|---|
| 2766 | }); |
|---|
| 2767 | |
|---|
| 2768 | }); |
|---|
| 2769 | </script> |
|---|
| 2770 | <?php |
|---|
| 2771 | } |
|---|
| 2772 | /** |
|---|
| 2773 | * Send CURL Request |
|---|
| 2774 | * |
|---|
| 2775 | * @param mixed $body |
|---|
| 2776 | * @param mixed $path |
|---|
| 2777 | * @param mixed $method |
|---|
| 2778 | */ |
|---|
| 2779 | public static function request($path="",$method='POST',$body="",$head=array()) { |
|---|
| 2780 | |
|---|
| 2781 | $args = array( |
|---|
| 2782 | 'body' => $body, |
|---|
| 2783 | 'headers'=> $head, |
|---|
| 2784 | 'method' => strtoupper($method), // GET, POST, PUT, DELETE, etc. |
|---|
| 2785 | 'sslverify' => false, |
|---|
| 2786 | 'timeout' => 20, |
|---|
| 2787 | ); |
|---|
| 2788 | |
|---|
| 2789 | $response = wp_remote_request($path, $args); |
|---|
| 2790 | $result=wp_remote_retrieve_body($response); |
|---|
| 2791 | return $result; |
|---|
| 2792 | } |
|---|
| 2793 | /** |
|---|
| 2794 | * Get variable from array |
|---|
| 2795 | * |
|---|
| 2796 | * @param mixed $key |
|---|
| 2797 | * @param mixed $arr |
|---|
| 2798 | */ |
|---|
| 2799 | public static function post($key, $arr="") { |
|---|
| 2800 | if($arr!=""){ |
|---|
| 2801 | return isset($arr[$key]) ? self::clean($arr[$key]) : ""; |
|---|
| 2802 | } |
|---|
| 2803 | return isset($_REQUEST[$key]) ? self::clean($_REQUEST[$key]) : ""; |
|---|
| 2804 | } |
|---|
| 2805 | public static function clean($var){ |
|---|
| 2806 | if ( is_array( $var ) ) { |
|---|
| 2807 | return array_map( array('vxcf_form','clean'), $var ); |
|---|
| 2808 | } else { |
|---|
| 2809 | return sanitize_text_field(wp_unslash($var)); |
|---|
| 2810 | } |
|---|
| 2811 | } |
|---|
| 2812 | /** |
|---|
| 2813 | * Get WP Encryption key |
|---|
| 2814 | * @return string Encryption key |
|---|
| 2815 | */ |
|---|
| 2816 | public static function get_key(){ |
|---|
| 2817 | $k='Wezj%+l-x.4fNzx%hJ]FORKT5Ay1w,iczS=DZrp~H+ve2@1YnS;;g?_VTTWX~-|t'; |
|---|
| 2818 | if(defined('AUTH_KEY')){ |
|---|
| 2819 | $k=AUTH_KEY; |
|---|
| 2820 | } |
|---|
| 2821 | return substr($k,0,30); |
|---|
| 2822 | } |
|---|
| 2823 | /** |
|---|
| 2824 | * Parse User Agent to get Browser and OS |
|---|
| 2825 | * @param string $u_agent (optional) User Agent |
|---|
| 2826 | * @return array Browser Informations |
|---|
| 2827 | */ |
|---|
| 2828 | public static function browser_info($u_agent=""){ |
|---|
| 2829 | $bname = ''; |
|---|
| 2830 | $platform = ''; |
|---|
| 2831 | $version= ""; $ub=''; |
|---|
| 2832 | if($u_agent == "" && !empty($_SERVER['HTTP_USER_AGENT'])){ |
|---|
| 2833 | $u_agent=$_SERVER['HTTP_USER_AGENT']; |
|---|
| 2834 | } |
|---|
| 2835 | //First get the platform? |
|---|
| 2836 | if (preg_match('/linux/i', $u_agent)) { |
|---|
| 2837 | $platform = 'linux'; |
|---|
| 2838 | } |
|---|
| 2839 | elseif (preg_match('/macintosh|mac os x/i', $u_agent)) { |
|---|
| 2840 | $platform = 'Mac'; |
|---|
| 2841 | } |
|---|
| 2842 | elseif (preg_match('/windows|win32/i', $u_agent)) { |
|---|
| 2843 | $platform = 'Windows'; |
|---|
| 2844 | } |
|---|
| 2845 | ////further refine platform |
|---|
| 2846 | if (preg_match('/iphone/i', $u_agent)) { |
|---|
| 2847 | $platform = "iPhone"; |
|---|
| 2848 | } else if (preg_match('/android/i', $u_agent)) { |
|---|
| 2849 | $platform = "Android"; |
|---|
| 2850 | } else if (preg_match('/blackberry/i', $u_agent)) { |
|---|
| 2851 | $platform = "BlackBerry"; |
|---|
| 2852 | } else if (preg_match('/webos/i', $u_agent)) { |
|---|
| 2853 | $platform = "Mobile"; |
|---|
| 2854 | } else if (preg_match('/ipod/i', $u_agent)) { |
|---|
| 2855 | $platform = "iPod"; |
|---|
| 2856 | } else if (preg_match('/ipad/i', $u_agent)) { |
|---|
| 2857 | $platform = "iPad"; |
|---|
| 2858 | } |
|---|
| 2859 | // Next get the name of the useragent yes seperately and for good reason |
|---|
| 2860 | if(preg_match('/MSIE/i',$u_agent) && !preg_match('/Opera/i',$u_agent)) |
|---|
| 2861 | { |
|---|
| 2862 | $bname = 'Internet Explorer'; |
|---|
| 2863 | $ub = "MSIE"; |
|---|
| 2864 | } |
|---|
| 2865 | elseif(preg_match('/Firefox/i',$u_agent)) |
|---|
| 2866 | { |
|---|
| 2867 | $bname = 'Mozilla Firefox'; |
|---|
| 2868 | $ub = "Firefox"; |
|---|
| 2869 | } |
|---|
| 2870 | elseif(preg_match('/OPR/i',$u_agent)) |
|---|
| 2871 | { |
|---|
| 2872 | $bname = 'Opera'; |
|---|
| 2873 | $ub = "Opera"; |
|---|
| 2874 | } |
|---|
| 2875 | elseif(preg_match('/Chrome/i',$u_agent)) |
|---|
| 2876 | { |
|---|
| 2877 | $bname = 'Google Chrome'; |
|---|
| 2878 | $ub = "Chrome"; |
|---|
| 2879 | } |
|---|
| 2880 | elseif(preg_match('/Safari/i',$u_agent)) |
|---|
| 2881 | { |
|---|
| 2882 | $bname = 'Apple Safari'; |
|---|
| 2883 | $ub = "Safari"; |
|---|
| 2884 | } |
|---|
| 2885 | elseif(preg_match('/Netscape/i',$u_agent)) |
|---|
| 2886 | { |
|---|
| 2887 | $bname = 'Netscape'; |
|---|
| 2888 | $ub = "Netscape"; |
|---|
| 2889 | } |
|---|
| 2890 | |
|---|
| 2891 | // finally get the correct version number |
|---|
| 2892 | $known = array('Version', $ub, 'other'); |
|---|
| 2893 | $pattern = '#(?<browser>' . join('|', $known) . |
|---|
| 2894 | ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#'; |
|---|
| 2895 | if (!preg_match_all($pattern, $u_agent, $matches)) { |
|---|
| 2896 | // we have no matching number just continue |
|---|
| 2897 | } |
|---|
| 2898 | // see how many we have |
|---|
| 2899 | $i = count($matches['browser']); |
|---|
| 2900 | if ($i > 1) { |
|---|
| 2901 | //see if version is before or after the name |
|---|
| 2902 | if (strripos($u_agent,"Version") < strripos($u_agent,$ub)){ |
|---|
| 2903 | $version= $matches['version'][0]; |
|---|
| 2904 | } |
|---|
| 2905 | else { |
|---|
| 2906 | $version= $matches['version'][1]; |
|---|
| 2907 | } |
|---|
| 2908 | } |
|---|
| 2909 | else if ($i > 0){ |
|---|
| 2910 | $version= $matches['version'][0]; |
|---|
| 2911 | } |
|---|
| 2912 | // check if we have a number |
|---|
| 2913 | if ($version==null || $version=="") {$version="?";} |
|---|
| 2914 | return array( |
|---|
| 2915 | 'userAgent' => $u_agent, |
|---|
| 2916 | 'full_name' => $bname, |
|---|
| 2917 | 'name' => $ub, |
|---|
| 2918 | 'version' => $version, |
|---|
| 2919 | 'platform' => $platform, |
|---|
| 2920 | 'pattern' => $pattern |
|---|
| 2921 | ); |
|---|
| 2922 | } |
|---|
| 2923 | |
|---|
| 2924 | public static function download_csv($form_id,$req=array()){ |
|---|
| 2925 | |
|---|
| 2926 | header('Content-disposition: attachment; filename='.date("Y-m-d",current_time('timestamp')).'.csv'); |
|---|
| 2927 | header("Content-Transfer-Encoding: binary"); |
|---|
| 2928 | |
|---|
| 2929 | $now = gmdate("D, d M Y H:i:s"); |
|---|
| 2930 | header("Expires: Tue, 03 Jul 2000 06:00:00 GMT"); |
|---|
| 2931 | header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate"); |
|---|
| 2932 | header("Last-Modified: {$now} GMT"); |
|---|
| 2933 | header('Content-Type: text/html; charset=UTF-8'); |
|---|
| 2934 | // force download |
|---|
| 2935 | header("Content-Type: application/force-download"); |
|---|
| 2936 | header("Content-Type: application/octet-stream"); |
|---|
| 2937 | header("Content-Type: application/download"); |
|---|
| 2938 | $data=vxcf_form::get_entries($form_id,'all','',$req); |
|---|
| 2939 | $leads=$data['result']; |
|---|
| 2940 | $meta=get_option(vxcf_form::$id.'_meta',array()); |
|---|
| 2941 | $sep=','; if(!empty($meta['sep'])){ $sep=trim($meta['sep']); } |
|---|
| 2942 | $upload=vxcf_form::get_upload_dir(); |
|---|
| 2943 | $extra_keys=array('vxbrowser'=>'browser','vxurl'=>'url','vxscreen'=>'screen','vxcreated'=>'created','vxupdated'=>'updated'); |
|---|
| 2944 | $fields=vxcf_form::$form_fields; |
|---|
| 2945 | //echo json_encode($fields); die(); echo json_encode($leads); |
|---|
| 2946 | $field_titles=array('#'); |
|---|
| 2947 | if(is_array($fields)){ |
|---|
| 2948 | foreach($fields as $field){ |
|---|
| 2949 | $field_titles[]=$field['label']; |
|---|
| 2950 | } |
|---|
| 2951 | } |
|---|
| 2952 | // $field_titles[]=__('Created','contact-form-entries'); |
|---|
| 2953 | |
|---|
| 2954 | $fp = fopen('php://output', 'w'); |
|---|
| 2955 | // fputs($fp, $bom =( chr(0xEF) . chr(0xBB) . chr(0xBF) )); |
|---|
| 2956 | fputcsv($fp, $field_titles,$sep); |
|---|
| 2957 | $sno=0; |
|---|
| 2958 | foreach($leads as $lead_row){ |
|---|
| 2959 | $row=!empty($lead_row['detail']) ? $lead_row['detail'] : array(); |
|---|
| 2960 | $sno++; |
|---|
| 2961 | $_row=array($sno); |
|---|
| 2962 | foreach($fields as $k=>$field){ |
|---|
| 2963 | $val=''; |
|---|
| 2964 | if(isset($field['name']) && isset($row[$field['name'].'_field'])){ |
|---|
| 2965 | $val=maybe_unserialize($row[$field['name'].'_field']); |
|---|
| 2966 | } |
|---|
| 2967 | if(isset($extra_keys[$k]) && isset($lead_row[$extra_keys[$k]])){ |
|---|
| 2968 | if($k == 'vxbrowser'){ |
|---|
| 2969 | $val=isset($lead_row['browser']) ? $lead_row['browser'].' ' : ''; |
|---|
| 2970 | $val.=isset($lead_row['os']) ? $lead_row['os'] : ''; |
|---|
| 2971 | }else{ |
|---|
| 2972 | $val=$lead_row[$extra_keys[$k]]; |
|---|
| 2973 | } |
|---|
| 2974 | } |
|---|
| 2975 | |
|---|
| 2976 | if(is_array($val)){ |
|---|
| 2977 | if(isset($field['type']) && in_array($field['type'],array('file','thumb')) && !empty($val) && self::$is_pr){ |
|---|
| 2978 | $temp_val=array(); |
|---|
| 2979 | foreach($val as $kk=>$vv){ |
|---|
| 2980 | if(filter_var($vv,FILTER_VALIDATE_URL) === false){ |
|---|
| 2981 | $temp_val[]=$upload['url'].$vv; |
|---|
| 2982 | } |
|---|
| 2983 | } |
|---|
| 2984 | $val=$temp_val; |
|---|
| 2985 | } |
|---|
| 2986 | |
|---|
| 2987 | $val=implode(' - ',$val); |
|---|
| 2988 | } |
|---|
| 2989 | /* if(function_exists('mb_convert_encoding')){ |
|---|
| 2990 | $val=mb_convert_encoding($val, 'UTF-8'); |
|---|
| 2991 | } */ |
|---|
| 2992 | $_row[]=self::esc_data($val); |
|---|
| 2993 | |
|---|
| 2994 | } |
|---|
| 2995 | |
|---|
| 2996 | $_row[]=$lead_row['created']; |
|---|
| 2997 | |
|---|
| 2998 | fputcsv($fp, $_row,$sep); |
|---|
| 2999 | } |
|---|
| 3000 | fclose($fp); |
|---|
| 3001 | |
|---|
| 3002 | } |
|---|
| 3003 | public static function find_el_form($var,$key=''){ |
|---|
| 3004 | |
|---|
| 3005 | if(is_array($var) && isset($var[0]) ){ |
|---|
| 3006 | foreach($var as $v){ |
|---|
| 3007 | if (!empty($v['elements']) && is_array( $v['elements'] ) ) { |
|---|
| 3008 | $se=self::find_el_form($v['elements'],$key); |
|---|
| 3009 | if(!empty($se)){ return $se; } |
|---|
| 3010 | } |
|---|
| 3011 | if($v['id'] == $key){ // var_dump($v); echo '----<hr>'; |
|---|
| 3012 | return $v['settings']; |
|---|
| 3013 | } |
|---|
| 3014 | } |
|---|
| 3015 | |
|---|
| 3016 | } |
|---|
| 3017 | } |
|---|
| 3018 | public static function find_el_forms($var,&$forms=array()){ |
|---|
| 3019 | |
|---|
| 3020 | if(is_array($var) && isset($var[0]) ){ |
|---|
| 3021 | foreach($var as $v){ |
|---|
| 3022 | if(isset($v['widgetType']) && $v['widgetType'] == 'form'){ |
|---|
| 3023 | $forms[]= $v; |
|---|
| 3024 | } |
|---|
| 3025 | if (!empty($v['elements']) && is_array( $v['elements'] ) ) { |
|---|
| 3026 | self::find_el_forms($v['elements'],$forms); |
|---|
| 3027 | } |
|---|
| 3028 | |
|---|
| 3029 | } |
|---|
| 3030 | |
|---|
| 3031 | } |
|---|
| 3032 | return $forms; |
|---|
| 3033 | } |
|---|
| 3034 | public static function esc_data( $data ) { |
|---|
| 3035 | $xls_chars = array( '=', '+', '-', '@' ); |
|---|
| 3036 | |
|---|
| 3037 | if (function_exists('mb_substr') && in_array( mb_substr( $data, 0, 1 ), $xls_chars, true ) ) { |
|---|
| 3038 | $data = "'" . $data; |
|---|
| 3039 | } |
|---|
| 3040 | |
|---|
| 3041 | return $data; |
|---|
| 3042 | } |
|---|
| 3043 | public function vx_id(){ |
|---|
| 3044 | $vx_id=''; |
|---|
| 3045 | if(!empty($_COOKIE['vx_user'])){ |
|---|
| 3046 | $vx_id=self::clean($_COOKIE['vx_user']); |
|---|
| 3047 | }else{ |
|---|
| 3048 | $vx_id=uniqid().time().rand(9,99999999); |
|---|
| 3049 | $_COOKIE['vx_user']=$vx_id; |
|---|
| 3050 | setcookie('vx_user', $vx_id, time()+25920000, '/'); |
|---|
| 3051 | } |
|---|
| 3052 | |
|---|
| 3053 | return $vx_id; |
|---|
| 3054 | } |
|---|
| 3055 | /** |
|---|
| 3056 | * Get time Offset |
|---|
| 3057 | * |
|---|
| 3058 | */ |
|---|
| 3059 | public static function time_offset(){ |
|---|
| 3060 | $offset = (int) get_option('gmt_offset'); |
|---|
| 3061 | return $offset*3600; |
|---|
| 3062 | } |
|---|
| 3063 | /** |
|---|
| 3064 | * Get variable from array |
|---|
| 3065 | * |
|---|
| 3066 | * @param mixed $key |
|---|
| 3067 | * @param mixed $key2 |
|---|
| 3068 | * @param mixed $arr |
|---|
| 3069 | */ |
|---|
| 3070 | public static function post2($key,$key2, $arr="") { |
|---|
| 3071 | if(is_array($arr)){ |
|---|
| 3072 | return isset($arr[$key][$key2]) ? $arr[$key][$key2] : ""; |
|---|
| 3073 | } |
|---|
| 3074 | return isset($_REQUEST[$key][$key2]) ? self::clean($_REQUEST[$key][$key2]) : ""; |
|---|
| 3075 | } |
|---|
| 3076 | /** |
|---|
| 3077 | * Get variable from array |
|---|
| 3078 | * |
|---|
| 3079 | * @param mixed $key |
|---|
| 3080 | * @param mixed $key2 |
|---|
| 3081 | * @param mixed $arr |
|---|
| 3082 | */ |
|---|
| 3083 | public static function post3($key,$key2,$key3, $arr="") { |
|---|
| 3084 | if(is_array($arr)){ |
|---|
| 3085 | return isset($arr[$key][$key2][$key3]) ? $arr[$key][$key2][$key3] : ""; |
|---|
| 3086 | } |
|---|
| 3087 | return isset($_REQUEST[$key][$key2][$key3]) ? self::clean($_REQUEST[$key][$key2][$key3]) : ""; |
|---|
| 3088 | } |
|---|
| 3089 | /** |
|---|
| 3090 | * get base url |
|---|
| 3091 | * |
|---|
| 3092 | */ |
|---|
| 3093 | public static function get_base_url(){ |
|---|
| 3094 | return plugin_dir_url(__FILE__); |
|---|
| 3095 | } |
|---|
| 3096 | /** |
|---|
| 3097 | * get plugin direcotry name |
|---|
| 3098 | * |
|---|
| 3099 | */ |
|---|
| 3100 | public static function plugin_dir_name(){ |
|---|
| 3101 | $path=self::get_base_path(); |
|---|
| 3102 | return basename($path); |
|---|
| 3103 | } |
|---|
| 3104 | /** |
|---|
| 3105 | * get plugin slug |
|---|
| 3106 | * |
|---|
| 3107 | */ |
|---|
| 3108 | public static function get_slug(){ |
|---|
| 3109 | return plugin_basename(__FILE__); |
|---|
| 3110 | } |
|---|
| 3111 | |
|---|
| 3112 | /** |
|---|
| 3113 | * Returns the physical path of the plugin's root folder |
|---|
| 3114 | * |
|---|
| 3115 | */ |
|---|
| 3116 | public static function get_base_path(){ |
|---|
| 3117 | return plugin_dir_path(__FILE__); |
|---|
| 3118 | } |
|---|
| 3119 | |
|---|
| 3120 | |
|---|
| 3121 | /** |
|---|
| 3122 | * get data object |
|---|
| 3123 | * |
|---|
| 3124 | */ |
|---|
| 3125 | public static function get_data_object(){ |
|---|
| 3126 | require_once(self::$path . "includes/data.php"); |
|---|
| 3127 | if(!is_object(self::$data)) |
|---|
| 3128 | self::$data=new vxcf_form_data(); |
|---|
| 3129 | return self::$data; |
|---|
| 3130 | } |
|---|
| 3131 | |
|---|
| 3132 | |
|---|
| 3133 | |
|---|
| 3134 | } |
|---|
| 3135 | |
|---|
| 3136 | endif; |
|---|
| 3137 | $vxcf_form=new vxcf_form(); |
|---|
| 3138 | $vxcf_form->instance(); |
|---|
| 3139 | if(!isset($vx_cf)){ $vx_cf=array(); } |
|---|
| 3140 | $vx_cf['vxcf_form']='vxcf_form'; |
|---|