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