| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: WP Contact Form HubSpot |
| 4 |
* Description: Integrates Contact Form 7 and <a href="https://wordpress.org/plugins/contact-form-entries/">Contact Form Entries Plugin</a> and many other forms with HubSpot allowing form submissions to be automatically sent to your HubSpot account |
| 5 |
* Version: 1.4.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/contact-form-hubspot-plugin/ |
| 9 |
* Author: CRM Perks |
| 10 |
* Text Domain: contact-form-hubspot |
| 11 |
* Domain Path: /languages/ |
| 12 |
*/ |
| 13 |
// Exit if accessed directly |
| 14 |
if( !defined( 'ABSPATH' ) ) exit; |
| 15 |
|
| 16 |
|
| 17 |
if( !class_exists( 'vxcf_hubspot' ) ): |
| 18 |
|
| 19 |
|
| 20 |
class vxcf_hubspot { |
| 21 |
|
| 22 |
|
| 23 |
public $url = "https://www.crmperks.com"; |
| 24 |
|
| 25 |
public $crm_name = "hubspot"; |
| 26 |
public $id = "vxcf_hubspot"; |
| 27 |
public $domain = "vxcf-hubspot"; |
| 28 |
public $version = "1.4.5"; |
| 29 |
public $update_id = "6000001"; |
| 30 |
public $min_cf_version = "1.0"; |
| 31 |
public $type = "vxcf_hubspot"; |
| 32 |
public $fields = null; |
| 33 |
public $form_fields = null; |
| 34 |
public $data = null; |
| 35 |
|
| 36 |
private $filter_condition; |
| 37 |
private $plugin_dir= ""; |
| 38 |
private $temp; |
| 39 |
private $crm_arr= false; |
| 40 |
public $notice_js= false; |
| 41 |
public static $title='Contact Form HubSpot Plugin'; |
| 42 |
public static $path = ''; |
| 43 |
public static $slug = ""; |
| 44 |
public static $debug_html = ''; |
| 45 |
public static $save_key=''; |
| 46 |
public static $lic_msg = ""; |
| 47 |
public static $db_version=''; |
| 48 |
public static $vx_plugins; |
| 49 |
public static $note; |
| 50 |
public static $feeds_res; |
| 51 |
public static $cf_status=''; |
| 52 |
public static $cf_status_msg=''; |
| 53 |
public static $tooltips; |
| 54 |
public static $entry_created=false; |
| 55 |
public static $plugin; |
| 56 |
public static $api_timeout; |
| 57 |
public static $is_pr; |
| 58 |
|
| 59 |
public function instance(){ |
| 60 |
add_action( 'plugins_loaded', array( $this, 'setup_main' ) ); |
| 61 |
register_deactivation_hook(__FILE__,array($this,'deactivate')); |
| 62 |
register_activation_hook(__FILE__,(array($this,'activate'))); |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
} |
| 67 |
/** |
| 68 |
* Plugin starting point. Will load appropriate files |
| 69 |
* |
| 70 |
*/ |
| 71 |
public function init(){ |
| 72 |
/* self::$cf_status= $this->cf_status(); |
| 73 |
if(self::$cf_status !== 1){ |
| 74 |
add_action( 'admin_notices', array( $this, 'install_cf_notice' ) ); |
| 75 |
add_action( 'after_plugin_row_'.self::$slug, array( $this, 'install_cf_notice_plugin_row' ) ); |
| 76 |
return; |
| 77 |
} */ |
| 78 |
|
| 79 |
self::$db_version=get_option($this->type."_version"); |
| 80 |
|
| 81 |
if(self::$db_version != $this->version && current_user_can( 'manage_options' )){ |
| 82 |
$this->install_plugin(); |
| 83 |
} |
| 84 |
|
| 85 |
$pro_file=self::$path . 'wp/crmperks-notices.php'; |
| 86 |
if(file_exists($pro_file)){ |
| 87 |
include_once($pro_file); |
| 88 |
}else{ |
| 89 |
//plugin api |
| 90 |
$this->plugin_api(true); |
| 91 |
self::$is_pr=true; |
| 92 |
$pro_file=self::$path . 'pro/add-ons.php'; |
| 93 |
if(file_exists($pro_file)){ |
| 94 |
include_once($pro_file); |
| 95 |
} } |
| 96 |
|
| 97 |
require_once(self::$path . "includes/crmperks-cf.php"); |
| 98 |
require_once(self::$path . "includes/plugin-pages.php"); |
| 99 |
|
| 100 |
/* |
| 101 |
$url='https://forms.hubspot.com/uploads/form/v2/{portalId}/{formGuid}'; |
| 102 |
$url='https://api.hsforms.com/submissions/v3/integration/submit/4968363/bcf10a14-721f-4f6e-bef9-4e4c2da69cd5'; |
| 103 |
$info=$this->get_info('3'); |
| 104 |
$api=$this->get_api($info); //'forms/v2/forms' |
| 105 |
$body=array('firstname'=>'Touseefa','lastname'=>'Ahada','emails'=>'aaas5asa@gmail.com','phone'=>'03027470285'); |
| 106 |
//$body=http_build_query($body); //,'sfdcCampaignId'=>'','goToWebinarWebinarKey'=>'' |
| 107 |
$post=array('submittedAta'=>time(),'context'=>array('pageUri'=>'https://local.virtualbrix.net','pageName'=>'Local Test','ipAddress'=>'120.23.56.58')); |
| 108 |
$post['legalConsentOptions']=array('consent'=>array('consentToProcess'=>true,"text"=>'I agree to allow Example Company to store and process my personal data.','communications'=>array(array('value'=>true,'text'=>'Text','subscriptionTypeId'=>'5388809')))); |
| 109 |
foreach($body as $k=>$v){ |
| 110 |
$post['fields'][]=array('name'=>$k,'value'=>$v); |
| 111 |
} |
| 112 |
//$res=$api->post_hubspot_arr($url,'post', $post); |
| 113 |
//$url='email/public/v1/subscriptions'; |
| 114 |
//$url='forms/v2/forms'; |
| 115 |
$res=$api->get_entry($url,'65651'); |
| 116 |
var_dump($res); |
| 117 |
die();*/ |
| 118 |
|
| 119 |
} |
| 120 |
|
| 121 |
/** |
| 122 |
* create tables and roles |
| 123 |
* |
| 124 |
*/ |
| 125 |
public function setup_main(){ |
| 126 |
|
| 127 |
|
| 128 |
add_action('cfx_form_submitted', array($this, 'entry_created_crmperks'),10,3); |
| 129 |
add_action('vxcf_entry_created', array($this, 'entry_created'),10,3); |
| 130 |
add_action('vx_contact_created', array($this, 'entry_created_contacts'),10,3); |
| 131 |
add_action('vx_callcenter_entry_created', array($this, 'entry_created_callcenter'),10,3); |
| 132 |
|
| 133 |
add_filter('wpcf7_before_send_mail', array($this, 'create_entry_cf'),99); |
| 134 |
//formidable |
| 135 |
add_action('frm_after_create_entry', array($this, 'create_entry_fd'), 99, 2); |
| 136 |
add_action('ninja_forms_after_submission', array($this, 'create_entry_na'),99); |
| 137 |
add_action( 'wpforms_process_entry_save',array(&$this,'create_entry_wp'), 99, 4 ); |
| 138 |
//elemntor form |
| 139 |
add_action( 'elementor_pro/forms/new_record', array($this,'create_entry_el'), 99 ); |
| 140 |
|
| 141 |
// $d=new vx_dialpad(); |
| 142 |
// $d->entry_created_hook('calls','1'); |
| 143 |
if(is_admin()){ |
| 144 |
self::$path=$this->get_base_path(); |
| 145 |
add_action('init', array($this,'init')); |
| 146 |
//loading translations |
| 147 |
load_plugin_textdomain('contact-form-hubspot-crm', FALSE, $this->plugin_dir_name(). '/languages/' ); |
| 148 |
$this->maybe_install(true); |
| 149 |
} |
| 150 |
|
| 151 |
} |
| 152 |
|
| 153 |
public function plugin_api($start_instance=false){ |
| 154 |
if(empty(self::$path)){ self::$path=$this->get_base_path(); } |
| 155 |
$api_file=self::$path . "pro/plugin-api.php"; |
| 156 |
if(!class_exists('vxcf_plugin_api') && file_exists( $api_file)){ |
| 157 |
require_once( $api_file ); |
| 158 |
} |
| 159 |
if(class_exists('vxcf_plugin_api')){ |
| 160 |
$slug=$this->get_slug(); |
| 161 |
$settings_link=$this->link_to_settings(); |
| 162 |
$is_plugin_page=$this->is_crm_page(); |
| 163 |
self::$plugin=new vxcf_plugin_api($this->id,$this->version,$this->type,$this->domain,$this->update_id,self::$title,$slug,self::$path,$settings_link,$is_plugin_page); |
| 164 |
if($start_instance){ |
| 165 |
self::$plugin->instance(); |
| 166 |
} |
| 167 |
} } |
| 168 |
/** |
| 169 |
* create tables and roles |
| 170 |
* |
| 171 |
*/ |
| 172 |
public function maybe_install($version_check=false){ |
| 173 |
|
| 174 |
if(current_user_can( 'manage_options' )){ |
| 175 |
self::$db_version=get_option($this->type."_version"); |
| 176 |
$do_install=false; |
| 177 |
if($version_check == false){ |
| 178 |
$do_install=true; |
| 179 |
}else if(self::$db_version != $this->version){ |
| 180 |
$do_install=true; |
| 181 |
} |
| 182 |
if($do_install){ |
| 183 |
$data=$this->get_data_object(); |
| 184 |
$data->update_table(); |
| 185 |
update_option($this->type."_version", $this->version); |
| 186 |
//add post permissions |
| 187 |
require_once(self::$path . "includes/install.php"); |
| 188 |
$install=new vxcf_hubspot_install(); |
| 189 |
$install->create_roles(); |
| 190 |
} |
| 191 |
} |
| 192 |
} |
| 193 |
public function form_submitted($form){ |
| 194 |
|
| 195 |
//entries plugin exists , do not use this hook |
| 196 |
if(class_exists('vxcf_form')){ return; } |
| 197 |
$form_id=$form->id(); |
| 198 |
$submission = WPCF7_Submission::get_instance(); |
| 199 |
|
| 200 |
$lead = $submission->uploaded_files(); |
| 201 |
if(!is_array($lead)){ $lead=array(); } |
| 202 |
$form_title=$form->title(); |
| 203 |
$tags=array(); |
| 204 |
|
| 205 |
if(method_exists('WPCF7_ShortcodeManager','get_instance') || method_exists('WPCF7_FormTagsManager','get_instance')){ |
| 206 |
|
| 207 |
$form_text=get_post_meta($form_id ,'_form',true); |
| 208 |
|
| 209 |
if(method_exists('WPCF7_FormTagsManager','get_instance')){ |
| 210 |
$manager=WPCF7_FormTagsManager::get_instance(); |
| 211 |
$contents=$manager->scan($form_text); |
| 212 |
$tags=$manager->get_scanned_tags(); |
| 213 |
|
| 214 |
}else if(method_exists('WPCF7_ShortcodeManager','get_instance')){ // |
| 215 |
$manager = WPCF7_ShortcodeManager::get_instance(); |
| 216 |
$contents=$manager->do_shortcode($form_text); |
| 217 |
$tags=$manager->get_scanned_tags(); |
| 218 |
} } |
| 219 |
|
| 220 |
|
| 221 |
if(is_array($tags)){ |
| 222 |
foreach($tags as $k=>$v){ |
| 223 |
if(!empty($v['name'])){ |
| 224 |
$name=$v['name']; |
| 225 |
$val=$submission->get_posted_data($name); |
| 226 |
if(!isset($lead[$name])){ $lead[$name]=$val; } |
| 227 |
|
| 228 |
} } |
| 229 |
} |
| 230 |
//var_dump($lead); |
| 231 |
$form_arr=array('id'=>'cf_'.$form_id,'name'=>$form_title,'fields'=>$tags); |
| 232 |
$this->entry_created($lead,'0',$form_arr); |
| 233 |
|
| 234 |
} |
| 235 |
public function create_entry_cf($form){ |
| 236 |
if(class_exists('vxcf_form')){ return; } |
| 237 |
$form_id=$form->id(); |
| 238 |
|
| 239 |
$submission = WPCF7_Submission::get_instance(); |
| 240 |
$uploaded_files = $submission->uploaded_files(); |
| 241 |
|
| 242 |
$form_title=$form->title(); |
| 243 |
$tags=$this->get_form_fields('cf_'.$form_id); |
| 244 |
$post_data=$submission->get_posted_data(); |
| 245 |
//var_dump($post_data); die(); |
| 246 |
$lead=array(); |
| 247 |
if(is_array($post_data)){ |
| 248 |
foreach($post_data as $k=>$val){ |
| 249 |
if(in_array($k,array('vx_width','vx_height','vx_url','g-recaptcha-response'))){ continue; } |
| 250 |
if(isset($tags[$k])){ |
| 251 |
$v=$tags[$k]; //$v is empty for non form fields |
| 252 |
} |
| 253 |
$name=$k; //$v['name'] //if empty then $v is old |
| 254 |
//var_dump($v); |
| 255 |
if(isset($uploaded_files[$name])){ |
| 256 |
$val=$uploaded_files[$name]; |
| 257 |
} |
| 258 |
|
| 259 |
if( !empty($val) && isset($v['basetype']) && $v['basetype'] == 'mfile' && function_exists('dnd_get_upload_dir') ){ |
| 260 |
$dir=dnd_get_upload_dir(); |
| 261 |
$f_arr=array(); |
| 262 |
foreach($val as $file){ |
| 263 |
$file_name=explode('/',$file); |
| 264 |
if(count($file_name)>1){ |
| 265 |
$f_arr[]=$dir['upload_url'].'/'.end($file_name); |
| 266 |
} |
| 267 |
} |
| 268 |
$val=$f_arr; |
| 269 |
} |
| 270 |
if(!isset($uploaded_files[$name])){ |
| 271 |
$val=wp_unslash($val); |
| 272 |
} |
| 273 |
$lead[$k]=$val; |
| 274 |
} |
| 275 |
} |
| 276 |
//var_dump($lead,$post_data); die('-----------'); |
| 277 |
$form_arr=array('id'=>'cf_'.$form_id,'name'=>$form_title,'fields'=>$tags); |
| 278 |
$this->entry_created($lead,'0',$form_arr); |
| 279 |
|
| 280 |
} |
| 281 |
public function create_entry_na($data){ |
| 282 |
if(class_exists('vxcf_form')){ return; } |
| 283 |
$form_id=$data['form_id']; |
| 284 |
|
| 285 |
|
| 286 |
if(empty($data['form_id'])){ |
| 287 |
return; |
| 288 |
} |
| 289 |
|
| 290 |
$form_title=$data['settings']['title']; |
| 291 |
$lead=$upload_files=array(); |
| 292 |
if(!empty($data['fields'])){ |
| 293 |
foreach($data['fields'] as $v){ |
| 294 |
$field_id=$v['id']; |
| 295 |
if(!empty($v['value'])){ |
| 296 |
if($v['type'] == 'file_upload'){ |
| 297 |
$upload_files[$field_id]=$v['value']; |
| 298 |
}else{ |
| 299 |
$lead[$field_id]=$v['value']; |
| 300 |
} |
| 301 |
} |
| 302 |
} |
| 303 |
|
| 304 |
if(is_array($upload_files)){ |
| 305 |
foreach($upload_files as $k=>$v){ |
| 306 |
$lead[$k]=$v; |
| 307 |
} |
| 308 |
} |
| 309 |
$form_arr=array('id'=>'na_'.$form_id,'name'=>$form_title,'fields'=>$data['fields']); |
| 310 |
$this->entry_created($lead,'0',$form_arr); |
| 311 |
|
| 312 |
} |
| 313 |
} |
| 314 |
|
| 315 |
public function create_entry_wp($fields, $entry, $form_id, $form_data){ |
| 316 |
if(class_exists('vxcf_form')){ return; } |
| 317 |
|
| 318 |
|
| 319 |
$upload_files=$lead=array(); |
| 320 |
if(!empty($fields)){ |
| 321 |
foreach($fields as $v){ |
| 322 |
if($v['type'] == 'file-upload'){ |
| 323 |
$v['value']=array_map('trim',explode("\n",$v['value'])); |
| 324 |
$upload_files[$v['id']]=$v['value']; |
| 325 |
}else{ |
| 326 |
$val=$v['value']; |
| 327 |
if(in_array($v['type'],array('payment-select','payment-multiple'))){ |
| 328 |
$val=$v['amount']; |
| 329 |
}else if($v['type'] == 'checkbox'){ |
| 330 |
$val=array_map('trim',explode("\n",$val)); |
| 331 |
} |
| 332 |
$lead[$v['id']]=$val; |
| 333 |
} } |
| 334 |
|
| 335 |
|
| 336 |
if(is_array($upload_files)){ |
| 337 |
foreach($upload_files as $k=>$v){ |
| 338 |
$lead[$k]=$v; |
| 339 |
} } |
| 340 |
|
| 341 |
$form_arr=array('id'=>'wp_'.$form_data['id'],'name'=>'WP Forms','fields'=>$form_data['fields']); |
| 342 |
if(!empty($form_data['fields']['settings']['form_title'])){ |
| 343 |
$form_arr['name']=$form_data['fields']['settings']['form_title']; |
| 344 |
} |
| 345 |
$id=isset($entry['id']) ? $entry['id'] : '0'; |
| 346 |
$this->entry_created($lead,$id,$form_arr); |
| 347 |
} |
| 348 |
//var_dump($fields); die(); |
| 349 |
} |
| 350 |
public function create_entry_el( $record){ |
| 351 |
if(class_exists('vxcf_form')){ return; } |
| 352 |
$data=$record->get_formatted_data(); |
| 353 |
$form_id_p=$this->post('form_id'); |
| 354 |
$post_id_p=$this->post('post_id'); |
| 355 |
|
| 356 |
$form_id=$form_id_p.'_'.$post_id_p; |
| 357 |
|
| 358 |
$fields=$this->get_form_fields('el_'.$form_id); |
| 359 |
$upload_files=$lead=array(); |
| 360 |
if(!empty($fields)){ |
| 361 |
foreach($fields as $v){ |
| 362 |
if(isset($data[$v['label']])){ |
| 363 |
$val=$data[$v['label']]; |
| 364 |
if($v['type'] == 'upload'){ |
| 365 |
$upload_files[$v['id']]=$val; |
| 366 |
}else{ |
| 367 |
|
| 368 |
if(in_array($v['type'],array('checkbox','multiselect'))){ |
| 369 |
$val=array_map('trim',explode(',',$val)); |
| 370 |
} |
| 371 |
$lead[$v['id']]=$val; |
| 372 |
} } } |
| 373 |
|
| 374 |
if(is_array($upload_files)){ |
| 375 |
foreach($upload_files as $k=>$v){ |
| 376 |
$lead[$k]=$v; |
| 377 |
} } |
| 378 |
//var_dump($lead,$data); die(); |
| 379 |
$form_arr=array('id'=>'el_'.$form_id,'name'=>'Elementor Forms','fields'=>$fields); |
| 380 |
$this->entry_created($lead,'0',$form_arr); |
| 381 |
|
| 382 |
} |
| 383 |
//var_dump($fields); die(); |
| 384 |
} |
| 385 |
public function create_entry_fd($entry_id,$form_id){ |
| 386 |
if(class_exists('vxcf_form')){ return; } |
| 387 |
|
| 388 |
$fields=$this->get_form_fields('fd_'.$form_id); |
| 389 |
global $wpdb; |
| 390 |
$table=$wpdb->prefix.'frm_item_metas'; |
| 391 |
$sql=$wpdb->prepare("Select * from $table where item_id=%d",$entry_id); |
| 392 |
$entry=$wpdb->get_results($sql,ARRAY_A); |
| 393 |
$detail=array(); |
| 394 |
if(is_array($entry) && count($entry)>0){ |
| 395 |
foreach($entry as $v){ |
| 396 |
$detail[$v['field_id']]=$v['meta_value']; |
| 397 |
} |
| 398 |
} |
| 399 |
//var_dump($tags); die(); |
| 400 |
$lead=array(); |
| 401 |
if(is_array($fields)){ |
| 402 |
$uploaded_files_form=array(); |
| 403 |
foreach($fields as $k=>$v){ |
| 404 |
|
| 405 |
$name=$v['name']; |
| 406 |
if(isset($detail[$name])){ |
| 407 |
$val=$detail[$name]; |
| 408 |
if($v['type'] == 'file'){ |
| 409 |
$val= wp_get_attachment_url($val) ; |
| 410 |
$base_url=get_site_url(); |
| 411 |
$val=str_replace($base_url,trim(ABSPATH,'/'),$val); |
| 412 |
$uploaded_files_form[$name]=$val; |
| 413 |
} |
| 414 |
$lead[$name]=$detail[$name]; |
| 415 |
} |
| 416 |
} |
| 417 |
// |
| 418 |
|
| 419 |
if(is_array($uploaded_files_form)){ |
| 420 |
foreach($uploaded_files_form as $k=>$v){ |
| 421 |
$lead[$k]=$v; |
| 422 |
} |
| 423 |
} |
| 424 |
} |
| 425 |
global $wpdb; |
| 426 |
$table=$wpdb->prefix.'frm_forms'; |
| 427 |
$sql=$wpdb->prepare("Select name from $table where id=%d",$form_id); |
| 428 |
$form_name=$wpdb->get_var($sql); |
| 429 |
$form_arr=array('id'=>'fd_'.$form_id,'name'=>$form_name,'fields'=>$fields); |
| 430 |
$this->entry_created($lead,'0',$form_arr); |
| 431 |
} |
| 432 |
/** |
| 433 |
* contact form entry created |
| 434 |
* |
| 435 |
* @param mixed $entry |
| 436 |
* @param mixed $form |
| 437 |
*/ |
| 438 |
public function entry_created($entry,$entry_id,$form){ |
| 439 |
|
| 440 |
self::$entry_created=true; |
| 441 |
|
| 442 |
if($this->do_actions()){ |
| 443 |
do_action('vx_addons_save_entry',$entry_id,$entry,'cf',$form); |
| 444 |
} |
| 445 |
|
| 446 |
$entry['__vx_id']=$entry_id; |
| 447 |
$this->push($entry,$form,'submit',false); |
| 448 |
} |
| 449 |
public function entry_created_crmperks($entry_id,$entry,$form){ |
| 450 |
self::$entry_created=true; |
| 451 |
if($this->do_actions()){ |
| 452 |
do_action('vx_addons_save_entry',$entry_id,$entry,'vf',$form); |
| 453 |
} |
| 454 |
|
| 455 |
$form['id']='vf_'.$form['id']; |
| 456 |
$form['cfx_type']='vf'; |
| 457 |
$entry['__vx_id']=$entry_id; |
| 458 |
$this->push($entry,$form,'',false); |
| 459 |
} |
| 460 |
public function entry_created_contacts($entry,$entry_id,$form){ |
| 461 |
|
| 462 |
if($this->do_actions()){ |
| 463 |
do_action('vx_addons_save_entry',$entry_id,$entry,'cc',$form); |
| 464 |
} |
| 465 |
|
| 466 |
$entry['__vx_id']=$entry_id; |
| 467 |
$this->push($entry,$form,'',false); |
| 468 |
} |
| 469 |
public function entry_created_callcenter($entry,$entry_id,$form){ |
| 470 |
$this->push($entry,$form,'',false); |
| 471 |
} |
| 472 |
|
| 473 |
/** |
| 474 |
* Install Contact Form Notice |
| 475 |
* |
| 476 |
*/ |
| 477 |
public function install_cf_notice(){ |
| 478 |
$message=self::$cf_status_msg; |
| 479 |
if(!empty($message)){ |
| 480 |
$this->display_msg('admin',$message,'gravity'); |
| 481 |
$this->notice_js=true; |
| 482 |
|
| 483 |
} |
| 484 |
} |
| 485 |
public function submit(){ |
| 486 |
$entry='{"your-name":"Your Name (required)","your-email":"admin@localhost.com","your-subject":"subject test","your-message":"sdfsdfsdfsdf","your-country":["India"],"your-sports":["Tennis"],"your-fruit":["Banana"],"your-browser":"Safari","your-file":""}'; |
| 487 |
$form='{"id":69,"name":"Contact form 1"}'; |
| 488 |
$entry=json_decode($entry,true); |
| 489 |
$form=json_decode($form,true); |
| 490 |
apply_filters('vx_addons_save_entry',false,$entry_id,$entry,'cf',$form); |
| 491 |
$entry['__vx_id']="1"; |
| 492 |
$p=$this->push($entry,$form); |
| 493 |
var_dump($p); die(); |
| 494 |
} |
| 495 |
|
| 496 |
/** |
| 497 |
* Install Contact Form Notice (plugin row) |
| 498 |
* |
| 499 |
*/ |
| 500 |
public function install_cf_notice_plugin_row(){ |
| 501 |
$message=self::$cf_status_msg; |
| 502 |
if(!empty($message)){ |
| 503 |
$this->display_msg('',$message,'gravity'); |
| 504 |
} |
| 505 |
} |
| 506 |
/** |
| 507 |
* display admin notice |
| 508 |
* |
| 509 |
* @param mixed $type |
| 510 |
* @param mixed $message |
| 511 |
* @param mixed $id |
| 512 |
*/ |
| 513 |
public function display_msg($type,$message,$id=""){ |
| 514 |
//exp |
| 515 |
global $wp_version; |
| 516 |
$ver=floatval($wp_version); |
| 517 |
if($type == "admin"){ |
| 518 |
if($ver<4.2){ |
| 519 |
?> |
| 520 |
<div class="error vx_notice notice" data-id="<?php echo esc_attr($id) ?>"><p style="display: table"><span style="display: table-cell; width: 98%"><span class="dashicons dashicons-megaphone"></span> <b><?php esc_html_e('Contact Form HubSpot Plugin','contact-form-hubspot-crm') ?>. </b><?php echo wp_kses_post($message);?> </span> |
| 521 |
<span style="display: table-cell; padding-left: 10px; vertical-align: middle;"><a href="#" class="notice-dismiss" title="<?php esc_html_e('Dismiss Notice','contact-form-hubspot-crm') ?>">dismiss</a></span> </p></div> |
| 522 |
<?php |
| 523 |
}else{ |
| 524 |
?> |
| 525 |
<div class="error vx_notice notice below-h2 is-dismissible" data-id="<?php echo esc_attr($id) ?>"><p><span class="dashicons dashicons-megaphone"></span> <b><?php esc_html_e('Contact Form HubSpot Plugin','contact-form-hubspot-crm') ?>. </b> <?php echo wp_kses_post($message);?> </p> |
| 526 |
</div> |
| 527 |
<?php |
| 528 |
} |
| 529 |
}else{ |
| 530 |
?> |
| 531 |
<tr class="plugin-update-tr"><td colspan="5" class="plugin-update"> |
| 532 |
<style type="text/css"> .vx_msg a{color: #fff; text-decoration: underline;} .vx_msg a:hover{color: #eee} </style> |
| 533 |
<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) ?> |
| 534 |
</div></div></td></tr> |
| 535 |
<?php |
| 536 |
} |
| 537 |
} |
| 538 |
/** |
| 539 |
* admin_screen_message function. |
| 540 |
* |
| 541 |
* @param mixed $message |
| 542 |
* @param mixed $level |
| 543 |
*/ |
| 544 |
public function screen_msg( $message, $level = 'updated') { |
| 545 |
echo '<div class="'. esc_attr( $level ) .' fade notice below-h2 is-dismissible"><p>'; |
| 546 |
echo wp_kses_post($message) ; |
| 547 |
echo '</p></div>'; |
| 548 |
} |
| 549 |
|
| 550 |
/** |
| 551 |
* Contact Form status |
| 552 |
* |
| 553 |
*/ |
| 554 |
public function cf_status() { |
| 555 |
|
| 556 |
$installed = 0; |
| 557 |
if(!class_exists('vxcf_form')) { |
| 558 |
if(file_exists(WP_PLUGIN_DIR.'/contact-form-entries-pro/contact-form-entries-pro.php')) { |
| 559 |
$installed=2; |
| 560 |
} |
| 561 |
}else{ |
| 562 |
$installed=1; |
| 563 |
if(!$this->is_cf_supported()){ |
| 564 |
$installed=3; |
| 565 |
} |
| 566 |
} |
| 567 |
if($installed !=1){ |
| 568 |
if($installed === 0){ // not found |
| 569 |
$message = sprintf(__("%sContact Form Entries%s is required. %s it today!%s", 'contact-form-hubspot-crm'), "<a href='https://www.crmperks.com/'>", "</a>", "<a href='https://www.crmperks.com/'>", "</a>"); |
| 570 |
}else if($installed === 2){ // not active |
| 571 |
$message = sprintf(__('Contact Form Entries is installed but not active. %sActivate Contact Form Entries%s to use the Contact Form HubSpot Plugin','contact-form-hubspot-crm'), '<strong><a href="'.wp_nonce_url(admin_url('plugins.php?action=activate&plugin=contact-form-entries-pro/contact-form-entries-pro.php'), 'activate-plugin_contact-form-entries-pro/contact-form-entries-pro.php').'">', '</a></strong>'); |
| 572 |
} else if($installed === 3){ // not supported |
| 573 |
$message = sprintf(__("A higher version of %sContact Form Entries%s is required. %sPurchase it today!%s", 'contact-form-hubspot-crm'), "<a href='https://www.crmperks.com/'>", "</a>", "<a href='https://www.crmperks.com/'>", "</a>"); |
| 574 |
} |
| 575 |
self::$cf_status_msg=$message; |
| 576 |
} |
| 577 |
return $installed; |
| 578 |
} |
| 579 |
|
| 580 |
|
| 581 |
/** |
| 582 |
* Returns true if the current page is an Feed pages. Returns false if not |
| 583 |
* |
| 584 |
* @param mixed $page |
| 585 |
*/ |
| 586 |
public function is_crm_page($page=""){ |
| 587 |
if(empty($page)) { |
| 588 |
$page = $this->post("page"); |
| 589 |
} |
| 590 |
return $page == $this->id; |
| 591 |
} |
| 592 |
|
| 593 |
|
| 594 |
/** |
| 595 |
* form fields |
| 596 |
* |
| 597 |
* @param mixed $form_id |
| 598 |
*/ |
| 599 |
/** |
| 600 |
* form fields |
| 601 |
* |
| 602 |
* @param mixed $form_id |
| 603 |
*/ |
| 604 |
public function get_form_fields($form_id){ |
| 605 |
$fields=array(); |
| 606 |
|
| 607 |
$fields=apply_filters('vx_add_crm_form_fields',$fields,$form_id); |
| 608 |
if(empty($fields)){ |
| 609 |
global $vxcf_form; |
| 610 |
|
| 611 |
if(is_object($vxcf_form) && method_exists($vxcf_form,'get_form_fields')){ |
| 612 |
$fields=$vxcf_form->get_form_fields($form_id); |
| 613 |
}else{ |
| 614 |
|
| 615 |
$form_arr=explode('_',$form_id); |
| 616 |
$type=$id=''; |
| 617 |
$fields = array(); |
| 618 |
if(isset($form_arr[0])){ |
| 619 |
$type=$form_arr[0]; |
| 620 |
} |
| 621 |
if(isset($form_arr[1])){ |
| 622 |
$id=$form_arr[1]; |
| 623 |
} |
| 624 |
switch($type){ |
| 625 |
case'cf': |
| 626 |
if(method_exists('WPCF7_ShortcodeManager','get_instance') || method_exists('WPCF7_FormTagsManager','get_instance')){ |
| 627 |
$id=substr($form_id,3); |
| 628 |
$form_text=get_post_meta($id,'_form',true); |
| 629 |
|
| 630 |
if(method_exists('WPCF7_FormTagsManager','get_instance')){ |
| 631 |
$manager=WPCF7_FormTagsManager::get_instance(); |
| 632 |
$contents=$manager->scan($form_text); |
| 633 |
$tags=$manager->get_scanned_tags(); |
| 634 |
|
| 635 |
}else if(method_exists('WPCF7_ShortcodeManager','get_instance')){ // |
| 636 |
$manager = WPCF7_ShortcodeManager::get_instance(); |
| 637 |
$contents=$manager->do_shortcode($form_text); |
| 638 |
$tags=$manager->get_scanned_tags(); |
| 639 |
} |
| 640 |
|
| 641 |
if(is_array($tags)){ |
| 642 |
foreach($tags as $tag){ |
| 643 |
if(is_object($tag)){ $tag=(array)$tag; } |
| 644 |
if(!empty($tag['name'])){ |
| 645 |
$id=str_replace(' ','',$tag['name']); |
| 646 |
$tag['label']=ucwords(str_replace(array('-','_')," ",$tag['name'])); |
| 647 |
$tag['type_']=$tag['type']; |
| 648 |
$tag['type']=$tag['basetype']; |
| 649 |
$tag['req']=strpos($tag['type'],'*') !==false ? 'true' : ''; |
| 650 |
if($tag['type'] == 'select' && !empty($tag['options']) && array_search('multiple',$tag['options'])!== false){ |
| 651 |
$tag['type']='multiselect'; |
| 652 |
} |
| 653 |
$fields[$id]=$tag; |
| 654 |
} |
| 655 |
} |
| 656 |
} |
| 657 |
} |
| 658 |
break; |
| 659 |
case'na': |
| 660 |
if(class_exists('Ninja_Forms')){ |
| 661 |
|
| 662 |
$form_fields = Ninja_Forms()->form( $id )->get_fields(); //var_dump($form_fields); die('----------'); |
| 663 |
foreach ($form_fields as $obj) { |
| 664 |
$field=array(); |
| 665 |
if( is_object( $obj ) ) { |
| 666 |
$field = $obj->get_settings(); |
| 667 |
$field['id']= $obj->get_id(); |
| 668 |
} |
| 669 |
|
| 670 |
$arr=array('name'=>$field['id']); |
| 671 |
$type=$field['type']; |
| 672 |
if($type == 'textbox'){ $type='text'; } |
| 673 |
if($type == 'starrating'){ $type='text'; } |
| 674 |
if($type == 'file_upload'){ $type='file'; } |
| 675 |
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 |
| 676 |
if($type == 'checkbox'){ |
| 677 |
$arr['values']=array(array('text'=>$field['label'],'value'=>'1')); |
| 678 |
} |
| 679 |
if(in_array($type,array('listmultiselect','listcheckbox','listradio','listselect'))){ |
| 680 |
$type=ltrim($type,'list'); |
| 681 |
$vals=array(); |
| 682 |
if(!empty($field['options'])){ |
| 683 |
foreach($field['options'] as $v){ |
| 684 |
$vals[]=array('text'=>$v['label'],'value'=>$v['value']); |
| 685 |
} |
| 686 |
} |
| 687 |
$arr['values']=$vals; |
| 688 |
} |
| 689 |
|
| 690 |
$arr['type']=$type; |
| 691 |
$arr['label']=$field['label']; |
| 692 |
$arr['req']=!empty($field['required']) ? 'true' : 'false'; |
| 693 |
$fields[$field['id']]=$arr; |
| 694 |
} |
| 695 |
} |
| 696 |
break; |
| 697 |
case'el': |
| 698 |
if(isset($form_arr[2])){ |
| 699 |
$post_id=$form_arr[2]; |
| 700 |
$forms=get_post_meta($post_id,'_elementor_data',true); |
| 701 |
$forms=json_decode($forms,true); |
| 702 |
if(!empty($forms)){ |
| 703 |
$form=self::find_el_form($forms,$id); |
| 704 |
|
| 705 |
if(!empty($form['form_fields'])){ |
| 706 |
foreach($form['form_fields'] as $tag){ |
| 707 |
if(!empty($tag['custom_id']) ){ |
| 708 |
if(empty($tag['field_type'])){ $tag['field_type']=$tag['custom_id']; } |
| 709 |
if(!in_array($tag['field_type'],array('html','step','honeypot','recaptcha','recaptcha_v3'))){ |
| 710 |
$field=array('id'=>$tag['custom_id']); |
| 711 |
$field['name']=$tag['custom_id']; |
| 712 |
$field['label']=$tag['field_label']; |
| 713 |
$field['type']=$tag['field_type']; |
| 714 |
$field['req']=!empty($tag['required']) ? 'true' : ''; |
| 715 |
if(!empty($tag['allow_multiple']) ){ |
| 716 |
$field['type']='multiselect'; |
| 717 |
} |
| 718 |
if($field['type'] == 'acceptance'){ |
| 719 |
$field['type']='checkbox'; |
| 720 |
$field['values']=array(array('label'=>$tag['acceptance_text'],'value'=>'on')); |
| 721 |
} |
| 722 |
if($field['type'] == 'upload'){ |
| 723 |
$field['type']='file'; |
| 724 |
} |
| 725 |
if(!empty($tag['field_options'])){ |
| 726 |
$opts_array=explode("\n",$tag['field_options']); |
| 727 |
$ops=array(); |
| 728 |
foreach($opts_array as $v){ |
| 729 |
$v_arr=explode('|',$v); |
| 730 |
if(!isset($v_arr[1])){ $v_arr[1]=$v_arr[0]; } |
| 731 |
$ops[]=array('label'=>$v_arr[0],'value'=>$v_arr[1]); |
| 732 |
} |
| 733 |
$field['values']=$ops; |
| 734 |
} |
| 735 |
$fields[$tag['custom_id']]=$field; |
| 736 |
} } |
| 737 |
} |
| 738 |
} |
| 739 |
} |
| 740 |
|
| 741 |
} |
| 742 |
break; |
| 743 |
case'fd': |
| 744 |
global $wpdb; |
| 745 |
$table=$wpdb->prefix.'frm_fields'; |
| 746 |
$sql=$wpdb->prepare("Select * from $table where form_id=%d",$id); |
| 747 |
$fields_arr=$wpdb->get_results($sql,ARRAY_A); |
| 748 |
if(count($fields_arr)>0){ |
| 749 |
foreach($fields_arr as $field){ |
| 750 |
$field['label']=$field['name']; |
| 751 |
$field['name']=$field['id']; |
| 752 |
if(!empty($field['options'])){ |
| 753 |
$field['values']=maybe_unserialize($field['options']); |
| 754 |
} |
| 755 |
$fields[$field['id']]=$field; |
| 756 |
} |
| 757 |
} |
| 758 |
break; |
| 759 |
case'wp': |
| 760 |
if(function_exists('wpforms') && method_exists(wpforms()->form,'get')){ |
| 761 |
$forms_arr=wpforms()->form->get( $id ); |
| 762 |
if(!empty($forms_arr)){ |
| 763 |
$form=json_decode($forms_arr->post_content,true); |
| 764 |
$fields=array(); |
| 765 |
foreach($form['fields'] as $v){ |
| 766 |
$type=$v['type']; |
| 767 |
if($type == 'name'){ $type='text'; } |
| 768 |
if($type == 'payment-select'){ $type='select'; } |
| 769 |
if($type == 'payment-multiple'){ $type='radio'; } |
| 770 |
if($type == 'payment-single'){ $type='text'; } |
| 771 |
if($type == 'file-upload'){ $type='file'; } |
| 772 |
if($type == 'date-time'){ $type='date'; } |
| 773 |
if($type == 'address'){ $type='textarea'; } |
| 774 |
if($type == 'phone'){ $type='tel'; } |
| 775 |
$label=isset($v['label']) ? $v['label'] : $type; |
| 776 |
// if(in_array($type,array('text','textarea','email','number','hidden','select','checkbox','radio','url','password','tel','date','file','number-slider'))){ |
| 777 |
$field=array('id'=>$v['id'],'name'=>$v['id'],'label'=>$label,'type'=>$type); |
| 778 |
$field['req']=!empty($v['required']) ? true : false; |
| 779 |
if(in_array($type,array('radio','checkbox','select'))){ |
| 780 |
$is_val=false; |
| 781 |
if(in_array($v['type'],array('payment-select','payment-multiple'))){ $is_val=true; } |
| 782 |
$choices=array(); |
| 783 |
if(!empty($v['choices'])){ |
| 784 |
foreach($v['choices'] as $c){ |
| 785 |
$c_val=$is_val ? $c['value'] : $c['label']; |
| 786 |
$choices[]=array('text'=>$c['label'],'value'=>$c_val); |
| 787 |
} |
| 788 |
} |
| 789 |
$field['values']=$choices; |
| 790 |
} |
| 791 |
$fields[$v['id']]=$field; |
| 792 |
// } |
| 793 |
|
| 794 |
} |
| 795 |
} } //var_dump($form['fields']); |
| 796 |
break; |
| 797 |
} |
| 798 |
} |
| 799 |
} |
| 800 |
return $fields; |
| 801 |
|
| 802 |
|
| 803 |
} |
| 804 |
public static function find_el_form($var,$key=''){ |
| 805 |
|
| 806 |
if(is_array($var) && isset($var[0]) ){ |
| 807 |
foreach($var as $v){ |
| 808 |
if (!empty($v['elements']) && is_array( $v['elements'] ) ) { |
| 809 |
$se=self::find_el_form($v['elements'],$key); |
| 810 |
if(!empty($se)){ return $se; } |
| 811 |
} |
| 812 |
if($v['id'] == $key){ // var_dump($v); echo '----<hr>'; |
| 813 |
return $v['settings']; |
| 814 |
} |
| 815 |
} |
| 816 |
|
| 817 |
} |
| 818 |
} |
| 819 |
public static function find_el_forms($var,&$forms=array()){ |
| 820 |
|
| 821 |
if(is_array($var) && isset($var[0]) ){ |
| 822 |
foreach($var as $v){ |
| 823 |
if(isset($v['widgetType']) && $v['widgetType'] == 'form'){ |
| 824 |
$forms[]= $v; |
| 825 |
} |
| 826 |
if (!empty($v['elements']) && is_array( $v['elements'] ) ) { |
| 827 |
self::find_el_forms($v['elements'],$forms); |
| 828 |
} |
| 829 |
|
| 830 |
} |
| 831 |
|
| 832 |
} |
| 833 |
return $forms; |
| 834 |
} |
| 835 |
|
| 836 |
public function get_form($form_id){ |
| 837 |
$form=array('id'=>$form_id); |
| 838 |
$form['name']='Contact Form'; |
| 839 |
|
| 840 |
return $form; |
| 841 |
} |
| 842 |
|
| 843 |
|
| 844 |
/** |
| 845 |
* settings link |
| 846 |
* |
| 847 |
* @param mixed $escaped |
| 848 |
*/ |
| 849 |
public function link_to_settings( $tab='' ) { |
| 850 |
$q=array('page'=>$this->id); |
| 851 |
if(!empty($tab)){ |
| 852 |
$q['tab']=$tab; |
| 853 |
} |
| 854 |
$url = admin_url('admin.php?'.http_build_query($q)); |
| 855 |
|
| 856 |
return $url; |
| 857 |
} |
| 858 |
|
| 859 |
|
| 860 |
/** |
| 861 |
* Get CRM info |
| 862 |
* |
| 863 |
*/ |
| 864 |
public function get_info($id){ |
| 865 |
$data=$this->get_data_object(); |
| 866 |
$info=$data->get_account($id); |
| 867 |
$data=array(); $meta=$info_arr=array(); |
| 868 |
if(is_array($info)){ |
| 869 |
if(!empty($info['data'])){ |
| 870 |
$info['data']=trim($info['data']); |
| 871 |
if(strpos($info['data'],'{') !== 0){ |
| 872 |
$info['data']=$this->de_crypt($info['data']); |
| 873 |
} |
| 874 |
$info_arr=json_decode($info['data'],true); |
| 875 |
if(!is_array($info_arr)){ |
| 876 |
$info_arr=array(); |
| 877 |
} |
| 878 |
} |
| 879 |
|
| 880 |
$info_arr['time']=$info['time']; |
| 881 |
$info_arr['id']=$info['id']; |
| 882 |
$info['data']=$info_arr; |
| 883 |
if(!empty($info['meta'])){ |
| 884 |
$meta=json_decode($info['meta'],true); |
| 885 |
} |
| 886 |
$info['meta']=is_array($meta) ? $meta : array(); |
| 887 |
|
| 888 |
} |
| 889 |
return $info; |
| 890 |
} |
| 891 |
/** |
| 892 |
* update account |
| 893 |
* |
| 894 |
* @param mixed $data |
| 895 |
* @param mixed $id |
| 896 |
*/ |
| 897 |
public function update_info($data,$id) { |
| 898 |
|
| 899 |
if(empty($id)){ |
| 900 |
return; |
| 901 |
} |
| 902 |
|
| 903 |
$time = current_time( 'mysql' ,1); |
| 904 |
|
| 905 |
$sql=array('updated'=>$time); |
| 906 |
if(is_array($data)){ |
| 907 |
|
| 908 |
|
| 909 |
if(isset($data['meta'])){ |
| 910 |
$sql['meta']= json_encode($data['meta']); |
| 911 |
} |
| 912 |
if( isset($data['data']) && is_array($data['data'])){ |
| 913 |
$_data=$this->get_data_object(); |
| 914 |
$acount=$_data->get_account($id); |
| 915 |
if(array_key_exists('time' , $data['data']) && empty($data['data']['time'])){ |
| 916 |
$sql['time']= $time; |
| 917 |
$sql['status']= '2'; |
| 918 |
} |
| 919 |
if(isset($data['data']['class'])){ |
| 920 |
$sql['status']= $data['data']['class'] == 'updated' ? '1' : '2'; |
| 921 |
} |
| 922 |
if(isset($data['data']['meta'])){ |
| 923 |
unset($data['data']['meta']); |
| 924 |
} |
| 925 |
if(isset($data['data']['status'])){ |
| 926 |
unset($data['data']['status']); |
| 927 |
} |
| 928 |
if(isset($data['data']['name'])){ |
| 929 |
$sql['name']=$data['data']['name']; |
| 930 |
// unset($data['data']['name']); |
| 931 |
}else if(isset($_GET['id'])){ |
| 932 |
$sql['name']="Account #".$this->post('id'); |
| 933 |
} |
| 934 |
|
| 935 |
$enc_str=json_encode($data['data']); |
| 936 |
//$enc_str=$this->en_crypt($enc_str); |
| 937 |
$sql['data']=$enc_str; |
| 938 |
} |
| 939 |
} |
| 940 |
|
| 941 |
$data=$this->get_data_object(); |
| 942 |
$result = $data->update_info_data($sql,$id); |
| 943 |
|
| 944 |
|
| 945 |
return $result; |
| 946 |
} |
| 947 |
|
| 948 |
/** |
| 949 |
* contact form field values, modify check boxes etc |
| 950 |
* |
| 951 |
* @param mixed $entry |
| 952 |
* @param mixed $form |
| 953 |
* @param mixed $gf_field_id |
| 954 |
* @param mixed $crm_field_id |
| 955 |
* @param mixed $custom |
| 956 |
*/ |
| 957 |
public function verify_field_val($entry,$field_id,$sf_id=''){ |
| 958 |
$value=null; |
| 959 |
|
| 960 |
|
| 961 |
if(isset($entry[$field_id])){ |
| 962 |
$value=$entry[$field_id]; |
| 963 |
if(is_array($value) && isset($value['value'])){ |
| 964 |
$value=$value['value']; |
| 965 |
} |
| 966 |
if(!is_array($value)){ |
| 967 |
// $value=maybe_unserialize($value); |
| 968 |
} |
| 969 |
}else if(isset($_REQUEST[$field_id])){ |
| 970 |
$value=$this->post($field_id); |
| 971 |
} |
| 972 |
$fields=$this->form_fields; |
| 973 |
$type=isset($fields[$field_id]['type']) ? $fields[$field_id]['type'] : ''; |
| 974 |
if( $type == 'file' && !empty($value)){ |
| 975 |
if(class_exists('vxcf_form')){ |
| 976 |
$upload=vxcf_form::get_upload_dir(); |
| 977 |
$temp_files=array(); |
| 978 |
if(!is_array($value)){ $value=array($value); } |
| 979 |
foreach($value as $f){ |
| 980 |
if(filter_var($f,FILTER_VALIDATE_URL) === false){ |
| 981 |
if(strpos($sf_id,'vx_list_files') !== false){ |
| 982 |
$f=$upload['dir'].$f; |
| 983 |
}else{ |
| 984 |
$f=$upload['url'].$f; //url , dir |
| 985 |
} } |
| 986 |
$temp_files[]=$f; |
| 987 |
} $value=$temp_files; |
| 988 |
} |
| 989 |
$value=trim(implode(' ',$value)); |
| 990 |
}else if( is_array($value) && count($value) == 1 ){ |
| 991 |
$value=trim(implode(' ',$value)); |
| 992 |
} |
| 993 |
return $value; |
| 994 |
} |
| 995 |
/** |
| 996 |
* filter enteries |
| 997 |
* |
| 998 |
* @param mixed $feed |
| 999 |
* @param mixed $entry |
| 1000 |
* @param mixed $form |
| 1001 |
*/ |
| 1002 |
public function check_filter($feed,$entry){ |
| 1003 |
$filters=$this->post('filters',$feed); |
| 1004 |
|
| 1005 |
$final=$this->filter_condition=null; |
| 1006 |
if(is_array($filters)){ |
| 1007 |
$time=current_time('timestamp'); |
| 1008 |
foreach($filters as $filter_s){ |
| 1009 |
$check=null; $and=null; |
| 1010 |
if(is_array($filter_s)){ |
| 1011 |
foreach($filter_s as $filter){ |
| 1012 |
$field=$filter['field']; |
| 1013 |
$fval=$filter['value']; |
| 1014 |
$val=$this->verify_field_val($entry,$field); |
| 1015 |
if(is_array($val)){ $val=trim(implode(' ',$val)); } |
| 1016 |
switch($filter['op']){ |
| 1017 |
case"is": $check=$fval == $val; break; |
| 1018 |
case"is_not": $check=$fval != $val; break; |
| 1019 |
case"contains": $check=strpos($val,$fval) !==false; break; |
| 1020 |
case"not_contains": $check=strpos($val,$fval) ===false; break; |
| 1021 |
case"is_in": $check=strpos($fval,$val) !==false; break; |
| 1022 |
case"not_in": $check=strpos($fval,$val) ===false; break; |
| 1023 |
case"starts": $check=strpos($val,$fval) === 0; break; |
| 1024 |
case"not_starts": $check=strpos($val,$fval) !== 0; break; |
| 1025 |
case"ends": $check=(strpos($val,$fval)+strlen($fval)) == strlen($val); break; |
| 1026 |
case"not_ends": $check=(strpos($val,$fval)+strlen($fval)) != strlen($val); break; |
| 1027 |
case"less": $check=(float)$val<(float)$fval; break; |
| 1028 |
case"greater": $check=(float)$val>(float)$fval; break; |
| 1029 |
case"less_date": $check=strtotime($val,$time) < strtotime($fval,$time); break; |
| 1030 |
case"greater_date": $check=strtotime($val,$time) > strtotime($fval,$time); break; |
| 1031 |
case"equal_date": $check=strtotime($val,$time) == strtotime($fval,$time); break; |
| 1032 |
case"empty": $check=$val == ""; break; |
| 1033 |
case"not_empty": $check=$val != ""; break; |
| 1034 |
} |
| 1035 |
$and_c[]=array("check"=>$check,"field_val"=>$fval,"input"=>$val,"field"=>$field,"op"=>$filter['op']); |
| 1036 |
if($check !== null){ |
| 1037 |
if($and !== null){ |
| 1038 |
$and=$and && $check; |
| 1039 |
}else{ |
| 1040 |
$and=$check; |
| 1041 |
} |
| 1042 |
} |
| 1043 |
} //end and loop filter |
| 1044 |
} |
| 1045 |
if($and !== null){ |
| 1046 |
if($final !== null){ |
| 1047 |
$final=$final || $and; |
| 1048 |
}else{ |
| 1049 |
$final=$and; |
| 1050 |
} |
| 1051 |
} |
| 1052 |
$this->filter_condition[]=$and_c; |
| 1053 |
} // end or loop |
| 1054 |
} |
| 1055 |
|
| 1056 |
return $final === null ? true : $final; |
| 1057 |
} |
| 1058 |
/** |
| 1059 |
* Logs page row |
| 1060 |
* |
| 1061 |
* @param mixed $feed |
| 1062 |
*/ |
| 1063 |
public function verify_log($feed){ |
| 1064 |
$link="N/A"; $desc=__("Added to ",'contact-form-hubspot-crm'); |
| 1065 |
$status_imgs=array("1"=>"created","2"=>"updated","4"=>"filtered",'5'=>'deleted'); |
| 1066 |
$feed['status_img']=isset($status_imgs[$feed["status"]]) ? $status_imgs[$feed["status"]] : 'failed'; |
| 1067 |
if(!empty($feed['crm_id'])&& !empty($feed['object']) && !empty($feed['status'])){ |
| 1068 |
if(!empty($feed['crm_id'])){ |
| 1069 |
$link=$feed['crm_id']; |
| 1070 |
} |
| 1071 |
if($feed['link'] !=""){ |
| 1072 |
$link='<a href="'.$feed['link'].'" title="'.$feed['crm_id'].'" target="_blank">'.$feed['crm_id'].'</a>'; |
| 1073 |
} |
| 1074 |
if($feed['status'] == 2){ |
| 1075 |
$desc="Updated to "; |
| 1076 |
} |
| 1077 |
$desc.=$feed['object']; |
| 1078 |
|
| 1079 |
}else if($feed['status'] == 5){ |
| 1080 |
$desc=sprintf(__("%s Deleted",'contact-form-hubspot-crm'),$feed['object']); |
| 1081 |
}else if($feed['status'] == 4){ |
| 1082 |
$desc=sprintf(__("%s Filtered",'contact-form-hubspot-crm'),$feed['object']); |
| 1083 |
}else{ |
| 1084 |
$desc= !empty($feed['error']) ? $feed['error'] : esc_html__("Unknown Error",'contact-form-hubspot-crm'); |
| 1085 |
} |
| 1086 |
if($feed['status'] == 1 && empty($feed['crm_id'])){ |
| 1087 |
$desc=__('Form submitted ','contact-form-hubspot-crm'); |
| 1088 |
$objects=$this->get_objects(); |
| 1089 |
if(isset($objects[$feed['object']])){ |
| 1090 |
$desc.=$objects[$feed['object']]; |
| 1091 |
} |
| 1092 |
} |
| 1093 |
$title=__("Failed",'contact-form-hubspot-crm'); |
| 1094 |
if($feed['status'] == 1){ |
| 1095 |
$title=__("Created",'contact-form-hubspot-crm'); |
| 1096 |
}else if($feed['status'] == 2){ |
| 1097 |
$title=__("Updated",'contact-form-hubspot-crm'); |
| 1098 |
}else if($feed['status'] == 4){ |
| 1099 |
$title=__("Filtered",'contact-form-hubspot-crm'); |
| 1100 |
}else if($feed['status'] == 5){ |
| 1101 |
$title=__("Deleted",'contact-form-hubspot-crm'); |
| 1102 |
} |
| 1103 |
$feed['_crm_id']= !empty($feed['crm_id']) ? $feed['crm_id'] : "N/A"; |
| 1104 |
$feed['a_link']=$link; |
| 1105 |
$feed['desc']=$desc; |
| 1106 |
$feed['title']=$title; |
| 1107 |
return $feed; |
| 1108 |
} |
| 1109 |
/** |
| 1110 |
* get address components |
| 1111 |
* |
| 1112 |
* @param mixed $entry |
| 1113 |
* @param mixed $field_id |
| 1114 |
* @param mixed $type |
| 1115 |
*/ |
| 1116 |
private function get_address($entry, $field_id,$type=""){ |
| 1117 |
$street_value = str_replace(" ", " ", trim($entry[$field_id . ".1"])); |
| 1118 |
$street2_value = str_replace(" ", " ", trim($entry[$field_id . ".2"])); |
| 1119 |
$city_value = str_replace(" ", " ", trim($entry[$field_id . ".3"])); |
| 1120 |
$state_value = str_replace(" ", " ", trim($entry[$field_id . ".4"])); |
| 1121 |
$zip_value = trim($entry[$field_id . ".5"]); |
| 1122 |
if(method_exists('GF_Field_Address','get_country_code')){ |
| 1123 |
$field_c=new GF_Field_Address(); |
| 1124 |
$country_value=$field_c->get_country_code(trim($entry[$field_id . ".6"])); |
| 1125 |
}else{ |
| 1126 |
$country_value = GFCommon::get_country_code(trim($entry[$field_id . ".6"])); |
| 1127 |
} |
| 1128 |
$country =trim($entry[$field_id . ".6"]); |
| 1129 |
$address = $street_value; |
| 1130 |
$address .= !empty($address) && !empty($street2_value) ? " $street2_value" : $street2_value; |
| 1131 |
if($type =="json"){ |
| 1132 |
$arr=array("street"=>$address,"city"=>$city_value,"state"=>$state_value,"zip"=>$zip_value,"country"=>$country); |
| 1133 |
return json_encode($arr); |
| 1134 |
} |
| 1135 |
$address .= !empty($address) && (!empty($city_value) || !empty($state_value)) ? " $city_value" : $city_value; |
| 1136 |
$address .= !empty($address) && !empty($city_value) && !empty($state_value) ? " $state_value" : $state_value; |
| 1137 |
$address .= !empty($address) && !empty($zip_value) ? " $zip_value" : $zip_value; |
| 1138 |
$address .= !empty($address) && !empty($country_value) ? " $country_value" : $country_value; |
| 1139 |
|
| 1140 |
return $address; |
| 1141 |
} |
| 1142 |
|
| 1143 |
/** |
| 1144 |
* Add checkbox to entry info - option to send entry to crm |
| 1145 |
* |
| 1146 |
* @param mixed $form_id |
| 1147 |
* @param mixed $lead |
| 1148 |
*/ |
| 1149 |
public function entry_info_send_checkbox( $form_id, $lead ) { |
| 1150 |
|
| 1151 |
// If this entry's form isn't connected to crm, don't show the checkbox |
| 1152 |
if(!$this->show_send_to_crm_button() ) { return; } |
| 1153 |
|
| 1154 |
// If this is not the Edit screen, get outta here. |
| 1155 |
if(empty($_POST["screen_mode"]) || $_POST["screen_mode"] === 'view') { return; } |
| 1156 |
|
| 1157 |
if(!current_user_can($this->id."_send_to_crm")){return; } |
| 1158 |
|
| 1159 |
if( apply_filters( $this->id.'_show_manual_export_button', true ) ) { |
| 1160 |
printf('<input type="checkbox" name="'.esc_attr($this->id).'_update" id="'.esc_attr($this->id).'_update" value="1" /><label for="'.esc_attr($this->id).'_update" title="%s">%s</label><br /><br />', esc_html__('Create or update this entry in HubSpot. The fields will be mapped according to the form feed settings.', 'contact-form-hubspot-crm'), esc_html__('Send to HubSpot', 'contact-form-hubspot-crm')); |
| 1161 |
} else { |
| 1162 |
echo '<input type="hidden" name="'.esc_attr($this->id).'_update" id="'.esc_attr($this->id).'_update" value="1" />'; |
| 1163 |
} |
| 1164 |
} |
| 1165 |
/** |
| 1166 |
* Add button to entry info - option to send entry to crm |
| 1167 |
* |
| 1168 |
* @param mixed $button |
| 1169 |
*/ |
| 1170 |
public function entry_info_send_button( $button = '' ) { |
| 1171 |
// If this entry's form isn't connected to crm, don't show the button |
| 1172 |
if(!$this->show_send_to_crm_button()) { return $button; } |
| 1173 |
if(!current_user_can($this->id."_send_to_crm")){return; } |
| 1174 |
// Is this the view or the edit screen? |
| 1175 |
$mode = empty($_POST["screen_mode"]) ? "view" : $this->post("screen_mode"); |
| 1176 |
if($mode === 'view') { |
| 1177 |
$margin=""; |
| 1178 |
if(defined("vx_btn")){ |
| 1179 |
$margin="margin-top: 5px;"; |
| 1180 |
}else{define('vx_btn','true');} |
| 1181 |
$button.= '<input type="submit" class="button button-large button-secondary alignright" name="'.esc_attr($this->id).'_send" style="margin-left:5px; '.$margin.'" title="'.__('Create or update this entry in HubSpot. The fields will be mapped according to the form feed settings.','contact-form-hubspot-crm').'" value="'.__('Send to HubSpot', 'contact-form-hubspot-crm').'" onclick="jQuery(\'#action\').val(\'send_to_crm\')" />'; |
| 1182 |
//logs button |
| 1183 |
|
| 1184 |
$entry_id=$this->post('lid'); |
| 1185 |
$form_id = rgget('id'); |
| 1186 |
if(empty($entry_id)){ |
| 1187 |
$entry_id=$this->get_entry_id($form_id); |
| 1188 |
} |
| 1189 |
$log_url=admin_url( 'admin.php?page=gf_edit_forms&view=settings&subview='.$this->id.'&tab=log&id='.$this->post('id').'&entry_id='.$entry_id); |
| 1190 |
$button.= '<a class="button button-large button-secondary alignright" style="margin-left:5px; margin-top:5px; " title="'.__('Go to HubSpot Logs','contact-form-hubspot-crm').'" href="'.esc_url($log_url).'">'.__('HubSpot Logs','contact-form-hubspot-crm').'</a>'; |
| 1191 |
|
| 1192 |
} |
| 1193 |
return $button; |
| 1194 |
} |
| 1195 |
/** |
| 1196 |
* Whether to show the Entry "Send to CRM" button or not |
| 1197 |
* |
| 1198 |
* If the entry's form has been mapped to CRM feed, show the Send to CRM button. Otherwise, don't. |
| 1199 |
* |
| 1200 |
* @return boolean True: Show the button; False: don't show the button. |
| 1201 |
*/ |
| 1202 |
private function show_send_to_crm_button() { |
| 1203 |
|
| 1204 |
$form_id = rgget('id'); |
| 1205 |
|
| 1206 |
return $this->has_feed($form_id); |
| 1207 |
} |
| 1208 |
/** |
| 1209 |
* Does the current form have a feed assigned to it? |
| 1210 |
* @param INT $form_id Form ID |
| 1211 |
* @return boolean |
| 1212 |
*/ |
| 1213 |
function has_feed($form_id) { |
| 1214 |
$data=$this->get_data_object(); |
| 1215 |
$feeds = $data->get_feed_by_form( $form_id , true); |
| 1216 |
|
| 1217 |
return !empty($feeds); |
| 1218 |
} |
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
/** |
| 1223 |
* if contact form installed and supported |
| 1224 |
* |
| 1225 |
*/ |
| 1226 |
private function is_cf_supported(){ |
| 1227 |
if(class_exists("vxcf_form")){ |
| 1228 |
global $vxcf_form; |
| 1229 |
$version='1.0'; |
| 1230 |
if($vxcf_form->version){ |
| 1231 |
$version=$vxcf_form->version; |
| 1232 |
} |
| 1233 |
$is_correct_version = version_compare($version, $this->min_cf_version, ">="); |
| 1234 |
return $is_correct_version; |
| 1235 |
} |
| 1236 |
else{ |
| 1237 |
return false; |
| 1238 |
} |
| 1239 |
} |
| 1240 |
/** |
| 1241 |
* uninstall plugin |
| 1242 |
* |
| 1243 |
*/ |
| 1244 |
public function uninstall(){ |
| 1245 |
//droping all tables |
| 1246 |
require_once(self::$path . "includes/install.php"); |
| 1247 |
$install=new vxcf_hubspot_install(); |
| 1248 |
do_action('uninstall_vx_plugin_'.$install->id); |
| 1249 |
$install->remove_data(); |
| 1250 |
$install->remove_roles(); |
| 1251 |
} |
| 1252 |
/** |
| 1253 |
* email validation |
| 1254 |
* |
| 1255 |
* @param mixed $email |
| 1256 |
*/ |
| 1257 |
public function is_valid_email($email){ |
| 1258 |
if(function_exists('filter_var')){ |
| 1259 |
if(filter_var($email, FILTER_VALIDATE_EMAIL)){ |
| 1260 |
return true; |
| 1261 |
} |
| 1262 |
}else{ |
| 1263 |
if(strpos($email,"@")>1){ |
| 1264 |
return true; |
| 1265 |
} |
| 1266 |
} |
| 1267 |
return false; |
| 1268 |
} |
| 1269 |
/** |
| 1270 |
* deactivate |
| 1271 |
* |
| 1272 |
* @param mixed $action |
| 1273 |
*/ |
| 1274 |
public function deactivate($action="deactivate"){ |
| 1275 |
do_action('plugin_status_'.$this->type,$action); |
| 1276 |
} |
| 1277 |
/** |
| 1278 |
* activate plugin |
| 1279 |
* |
| 1280 |
*/ |
| 1281 |
public function activate(){ |
| 1282 |
$this->plugin_api(true); |
| 1283 |
$this->maybe_install(); |
| 1284 |
do_action('plugin_status_'.$this->type,'activate'); |
| 1285 |
} |
| 1286 |
/** |
| 1287 |
* Send CURL Request |
| 1288 |
* |
| 1289 |
* @param mixed $body |
| 1290 |
* @param mixed $path |
| 1291 |
* @param mixed $method |
| 1292 |
*/ |
| 1293 |
public function request($path="",$method='POST',$body="",$head=array()) { |
| 1294 |
|
| 1295 |
$args = array( |
| 1296 |
'body' => $body, |
| 1297 |
'headers'=> $head, |
| 1298 |
'method' => strtoupper($method), // GET, POST, PUT, DELETE, etc. |
| 1299 |
'sslverify' => false, |
| 1300 |
'timeout' => 20, |
| 1301 |
); |
| 1302 |
|
| 1303 |
$response = wp_remote_request($path, $args); |
| 1304 |
|
| 1305 |
if(is_wp_error($response)) { |
| 1306 |
$this->error_msg= $response->get_error_message(); |
| 1307 |
return false; |
| 1308 |
} else if(isset($response['response']['code']) && $response['response']['code'] != 200 && $response['response']['code'] != 404) { |
| 1309 |
$this->error_msg = strip_tags($response['body']); |
| 1310 |
return false; |
| 1311 |
} else if(!$response) { |
| 1312 |
return false; |
| 1313 |
} |
| 1314 |
$result=wp_remote_retrieve_body($response); |
| 1315 |
return $result; |
| 1316 |
} |
| 1317 |
|
| 1318 |
/** |
| 1319 |
* Formates User Informations and submitted form to string |
| 1320 |
* This string is sent to email and hubspot |
| 1321 |
* @param array $info User informations |
| 1322 |
* @param bool $is_html If HTML needed or not |
| 1323 |
* @return string formated string |
| 1324 |
*/ |
| 1325 |
public function format_user_info($info,$is_html=false){ |
| 1326 |
$str=""; $file=""; |
| 1327 |
if($is_html){ |
| 1328 |
self::$path=$this->get_base_path(); |
| 1329 |
if(file_exists(self::$path."templates/email.php")){ |
| 1330 |
ob_start(); |
| 1331 |
include_once(self::$path."templates/email.php"); |
| 1332 |
$file= ob_get_contents(); // data is now in here |
| 1333 |
ob_end_clean(); |
| 1334 |
} |
| 1335 |
if(trim($file) == "") |
| 1336 |
$is_html=false; |
| 1337 |
} |
| 1338 |
if(isset($info['info']) && is_array($info['info'])){ |
| 1339 |
if($is_html){ |
| 1340 |
if(isset($info['info_title'])){ |
| 1341 |
$str.='<tr><td style="font-family: Helvetica, Arial, sans-serif;background-color: #C35050; height: 36px; color: #fff; font-size: 24px; padding: 0px 10px">'.$info['info_title'].'</td></tr>'."\n"; |
| 1342 |
} |
| 1343 |
if(is_array($info['info']) && count($info['info'])>0){ |
| 1344 |
$str.='<tr><td style="padding: 10px;"><table border="0" cellpadding="0" cellspacing="0" width="100%;"><tbody>'; |
| 1345 |
foreach($info['info'] as $f_k=>$f_val){ |
| 1346 |
$str.='<tr><td style="padding-top: 10px;color: #303030;font-family: Helvetica;font-size: 13px;line-height: 150%;text-align: right; font-weight: bold; width: 28%; padding-right: 10px;">'.$f_k.'</td><td style="padding-top: 10px;color: #303030;font-family: Helvetica;font-size: 13px;line-height: 150%;text-align: left; word-break:break-all;">'.$f_val.'</td></tr>'."\n"; |
| 1347 |
} |
| 1348 |
$str.="</table></td></tr>"; |
| 1349 |
} |
| 1350 |
}else{ |
| 1351 |
if(isset($info['title'])) |
| 1352 |
$str.="\n".$info['title']."\n"; |
| 1353 |
foreach($info['info'] as $f_k=>$f_val){ |
| 1354 |
$str.=$f_k." : ".$f_val."\n"; |
| 1355 |
} |
| 1356 |
} |
| 1357 |
} |
| 1358 |
if($is_html){ |
| 1359 |
$str=str_replace(array("{title}","{msg}","{sf_contents}"),array($info['title'],$info['msg'],$str),$file); |
| 1360 |
} |
| 1361 |
return $str; |
| 1362 |
} |
| 1363 |
|
| 1364 |
|
| 1365 |
/** |
| 1366 |
* if plugin user is valid |
| 1367 |
* |
| 1368 |
* @param mixed $update |
| 1369 |
*/ |
| 1370 |
|
| 1371 |
public function is_valid_user($update){ |
| 1372 |
return is_array($update) && isset($update['user']['user']) && $update['user']['user']!=""&& isset($update['user']['expires']); |
| 1373 |
} |
| 1374 |
public function post($key, $arr="") { |
| 1375 |
if($arr!=""){ |
| 1376 |
return isset($arr[$key]) ? $arr[$key] : ""; |
| 1377 |
} |
| 1378 |
return isset($_REQUEST[$key]) ? self::clean($_REQUEST[$key]) : ""; |
| 1379 |
} |
| 1380 |
public static function clean($var,$key=''){ |
| 1381 |
if ( is_array( $var ) ) { |
| 1382 |
$a=array(); |
| 1383 |
foreach($var as $k=>$v){ |
| 1384 |
$a[$k]=self::clean($v,$k); |
| 1385 |
} |
| 1386 |
return $a; |
| 1387 |
}else { |
| 1388 |
$var=wp_unslash($var); |
| 1389 |
if(in_array($key,array('note_val','value'))){ |
| 1390 |
$var=sanitize_textarea_field($var); |
| 1391 |
}else{ |
| 1392 |
$var=sanitize_text_field($var); |
| 1393 |
} |
| 1394 |
return $var; |
| 1395 |
} |
| 1396 |
} |
| 1397 |
public static function get_key(){ |
| 1398 |
$k='Wezj%+l-x.4fNzx%hJ]FORKT5Ay1w,iczS=DZrp~H+ve2@1YnS;;g?_VTTWX~-|t'; |
| 1399 |
if(defined('AUTH_KEY')){ |
| 1400 |
$k=AUTH_KEY; |
| 1401 |
} |
| 1402 |
return substr($k,0,30); |
| 1403 |
} |
| 1404 |
/** |
| 1405 |
* check if other version of this plugin exists |
| 1406 |
* |
| 1407 |
*/ |
| 1408 |
public function other_plugin_version(){ |
| 1409 |
$status=0; |
| 1410 |
if(class_exists('vxcf_hubspot_wp')){ |
| 1411 |
$status=1; |
| 1412 |
}else if( file_exists(WP_PLUGIN_DIR.'/contact-form-hubspot-crm/contact-form-hubspot-crm.php')) { |
| 1413 |
$status=2; |
| 1414 |
} |
| 1415 |
return $status; |
| 1416 |
} |
| 1417 |
/** |
| 1418 |
* Get time Offset |
| 1419 |
* |
| 1420 |
*/ |
| 1421 |
public function time_offset(){ |
| 1422 |
$offset = (int) get_option('gmt_offset'); |
| 1423 |
return $offset*3600; |
| 1424 |
} |
| 1425 |
/** |
| 1426 |
* Decrypts Values |
| 1427 |
* @param array $info HubSpot encrypted API info |
| 1428 |
* @return array API settings |
| 1429 |
*/ |
| 1430 |
public static function de_crypt($info){ |
| 1431 |
$info=trim($info); |
| 1432 |
if($info == "") |
| 1433 |
return ''; |
| 1434 |
$str=base64_decode($info); |
| 1435 |
$key=self::get_key(); |
| 1436 |
$decrypted_string=''; |
| 1437 |
if(function_exists("openssl_encrypt") && strpos($str,':')!==false ) { |
| 1438 |
$method='AES-256-CBC'; |
| 1439 |
$arr = explode(':', $str); |
| 1440 |
if(isset($arr[1]) && $arr[1]!=""){ |
| 1441 |
$decrypted_string=openssl_decrypt($arr[0],$method,$key,false, base64_decode($arr[1])); |
| 1442 |
} |
| 1443 |
}else{ |
| 1444 |
$decrypted_string=$str; |
| 1445 |
} |
| 1446 |
return $decrypted_string; |
| 1447 |
} |
| 1448 |
/** |
| 1449 |
* Encrypts Values |
| 1450 |
* @param string $str |
| 1451 |
* @return string Encrypted Value |
| 1452 |
*/ |
| 1453 |
public static function en_crypt($str){ |
| 1454 |
$str=trim($str); |
| 1455 |
if($str == "") |
| 1456 |
return ''; |
| 1457 |
$key=self::get_key(); |
| 1458 |
if(function_exists("openssl_encrypt")) { |
| 1459 |
$method='AES-256-CBC'; |
| 1460 |
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($method)); |
| 1461 |
$enc_str=openssl_encrypt($str,$method, $key,false,$iv); |
| 1462 |
$enc_str.=":".base64_encode($iv); |
| 1463 |
}else{ |
| 1464 |
$enc_str=$str; |
| 1465 |
} |
| 1466 |
$enc_str=base64_encode($enc_str); |
| 1467 |
return $enc_str; |
| 1468 |
} |
| 1469 |
|
| 1470 |
/** |
| 1471 |
* Get variable from array |
| 1472 |
* |
| 1473 |
* @param mixed $key |
| 1474 |
* @param mixed $key2 |
| 1475 |
* @param mixed $arr |
| 1476 |
*/ |
| 1477 |
public function post2($key,$key2, $arr="") { |
| 1478 |
if(is_array($arr)){ |
| 1479 |
return isset($arr[$key][$key2]) ? self::clean($arr[$key][$key2]) : ""; |
| 1480 |
} |
| 1481 |
return isset($_REQUEST[$key][$key2]) ? self::clean($_REQUEST[$key][$key2]) : ""; |
| 1482 |
} |
| 1483 |
/** |
| 1484 |
* Get variable from array |
| 1485 |
* |
| 1486 |
* @param mixed $key |
| 1487 |
* @param mixed $key2 |
| 1488 |
* @param mixed $arr |
| 1489 |
*/ |
| 1490 |
public function post3($key,$key2,$key3, $arr="") { |
| 1491 |
if(is_array($arr)){ |
| 1492 |
return isset($arr[$key][$key2][$key3]) ? self::clean($arr[$key][$key2][$key3]) : ""; |
| 1493 |
} |
| 1494 |
return isset($_REQUEST[$key][$key2][$key3]) ? self::clean($_REQUEST[$key][$key2][$key3]) : ""; |
| 1495 |
} |
| 1496 |
/** |
| 1497 |
* get base url |
| 1498 |
* |
| 1499 |
*/ |
| 1500 |
public function get_base_url(){ |
| 1501 |
return plugin_dir_url(__FILE__); |
| 1502 |
} |
| 1503 |
/** |
| 1504 |
* get plugin direcotry name |
| 1505 |
* |
| 1506 |
*/ |
| 1507 |
public function plugin_dir_name(){ |
| 1508 |
if(!empty($this->plugin_dir)){ |
| 1509 |
return $this->plugin_dir; |
| 1510 |
} |
| 1511 |
if(empty(self::$path)){ |
| 1512 |
self::$path=$this->get_base_path(); |
| 1513 |
} |
| 1514 |
$this->plugin_dir=basename(self::$path); |
| 1515 |
return $this->plugin_dir; |
| 1516 |
} |
| 1517 |
/** |
| 1518 |
* get plugin slug |
| 1519 |
* |
| 1520 |
*/ |
| 1521 |
public function get_slug(){ |
| 1522 |
return plugin_basename(__FILE__); |
| 1523 |
} |
| 1524 |
public function do_actions(){ |
| 1525 |
if(!is_object(self::$plugin) ){ $this->plugin_api(); } |
| 1526 |
if(is_object(self::$plugin) && method_exists(self::$plugin,'valid_addons')){ |
| 1527 |
return self::$plugin->valid_addons(); |
| 1528 |
} |
| 1529 |
|
| 1530 |
return false; |
| 1531 |
} |
| 1532 |
/** |
| 1533 |
* Returns the physical path of the plugin's root folder |
| 1534 |
* |
| 1535 |
*/ |
| 1536 |
public function get_base_path(){ |
| 1537 |
return plugin_dir_path(__FILE__); |
| 1538 |
} |
| 1539 |
|
| 1540 |
/** |
| 1541 |
* get api object |
| 1542 |
* |
| 1543 |
* @param mixed $settings |
| 1544 |
* @return vxg_api_zoho |
| 1545 |
*/ |
| 1546 |
public function get_api($crm=""){ |
| 1547 |
$api = false; |
| 1548 |
$api_class=$this->id."_api"; |
| 1549 |
if(!class_exists($api_class)) |
| 1550 |
require_once(self::$path."api/api.php"); |
| 1551 |
|
| 1552 |
$api = new $api_class($crm); |
| 1553 |
return $api; |
| 1554 |
} |
| 1555 |
/** |
| 1556 |
* get contact form entry |
| 1557 |
* |
| 1558 |
*/ |
| 1559 |
public function get_cf_entry($entry_id,$type=''){ |
| 1560 |
$entry=array(); |
| 1561 |
|
| 1562 |
if($type == 'addon'){ |
| 1563 |
|
| 1564 |
if( class_exists( 'vxcf_crm' ) && !empty( $entry_id ) ) { |
| 1565 |
$entry = vxcf_crm::get_entry( $entry_id ); |
| 1566 |
$entry['__vx_id']=$entry_id; |
| 1567 |
$entry['form_id']='vx_contacts'; |
| 1568 |
} |
| 1569 |
} |
| 1570 |
else{ |
| 1571 |
if( class_exists( 'vxcf_form' ) && !empty( $entry_id ) ) { |
| 1572 |
$entry = vxcf_form::get_entry( $entry_id ); |
| 1573 |
$entry['__vx_id']=$entry_id; |
| 1574 |
} |
| 1575 |
} |
| 1576 |
return $entry; |
| 1577 |
} |
| 1578 |
/** |
| 1579 |
* get contact form entry |
| 1580 |
* |
| 1581 |
*/ |
| 1582 |
public function get_cf_entry_detail($entry_id){ |
| 1583 |
$entry=array(); |
| 1584 |
// Fetch entry (use new GF API from version 1.8) |
| 1585 |
if( class_exists( 'vxcf_form' ) && !empty( $entry_id ) ) { |
| 1586 |
$entry = vxcf_form::get_entry_detail( $entry_id ); |
| 1587 |
} |
| 1588 |
return $entry; |
| 1589 |
} |
| 1590 |
/** |
| 1591 |
* get data object |
| 1592 |
* |
| 1593 |
*/ |
| 1594 |
public function get_data_object(){ |
| 1595 |
require_once(self::$path . "includes/data.php"); |
| 1596 |
if(!is_object($this->data)) |
| 1597 |
$this->data=new vxcf_hubspot_data(); |
| 1598 |
return $this->data; |
| 1599 |
} |
| 1600 |
|
| 1601 |
|
| 1602 |
/** |
| 1603 |
* push form data to crm |
| 1604 |
* |
| 1605 |
* @param mixed $entry |
| 1606 |
* @param mixed $form |
| 1607 |
* @param mixed $is_admin |
| 1608 |
*/ |
| 1609 |
public function push($entry, $form,$event="",$is_admin=true,$log=""){ |
| 1610 |
|
| 1611 |
$data_db=$this->get_data_object(); |
| 1612 |
$log_id=''; $feeds_meta=array(); |
| 1613 |
if(!empty($log)){ |
| 1614 |
if(isset($log['id'])){ |
| 1615 |
$log_id=$log['id']; |
| 1616 |
} |
| 1617 |
$log_feed=$data_db->get_feed($log['feed_id']); |
| 1618 |
|
| 1619 |
if(!empty($log_feed)){ |
| 1620 |
$feeds_meta=array($log_feed); |
| 1621 |
} |
| 1622 |
}else{ |
| 1623 |
//get feeds of a form |
| 1624 |
$feeds=$data_db->get_feed_by_form($form['id'],true); |
| 1625 |
|
| 1626 |
if(is_array($feeds) && count($feeds)>0){ |
| 1627 |
$e=2000; $k=1000; $i=1; |
| 1628 |
foreach($feeds as $feed){ |
| 1629 |
$data=isset($feed['data']) ? json_decode($feed['data'],true) : array(); |
| 1630 |
$meta=isset($feed['meta']) ? json_decode($feed['meta'],true) : array(); |
| 1631 |
$feed['meta']=$meta; |
| 1632 |
$feed['data']=$data; |
| 1633 |
|
| 1634 |
if(!empty($data['contact_check'])){ |
| 1635 |
$feeds_meta[$e++]=$feed; |
| 1636 |
}else if(!empty($data['company_check'])){ |
| 1637 |
$feeds_meta[$k++]=$feed; |
| 1638 |
}else{ |
| 1639 |
$feeds_meta[$i++]=$feed; |
| 1640 |
} |
| 1641 |
} |
| 1642 |
ksort($feeds_meta); |
| 1643 |
} |
| 1644 |
|
| 1645 |
} |
| 1646 |
|
| 1647 |
$entry_id=$this->post('__vx_id',$entry); |
| 1648 |
$type='cf'; |
| 1649 |
if($form['id'] == 'vx_contacts'){ |
| 1650 |
$type='cc'; |
| 1651 |
} |
| 1652 |
if(isset($form['id'])){ |
| 1653 |
$entry['_vx_form_id']=$form['id']; |
| 1654 |
} |
| 1655 |
if( isset($form['name'])){ |
| 1656 |
$entry['_vx_form_name']=$form['name']; |
| 1657 |
}else if( isset($form['title'])){ |
| 1658 |
$entry['_vx_form_name']=$form['title']; |
| 1659 |
} |
| 1660 |
|
| 1661 |
$local_time=current_time( 'mysql'); |
| 1662 |
$entry['_vx_created']=isset($entry['__vx_entry']['created']) ? $entry['__vx_entry']['created'] : $local_time; |
| 1663 |
$entry['_vx_updated']=isset($entry['__vx_entry']['updated']) ? $entry['__vx_entry']['updated'] : $local_time; if(!empty($entry['_vx_created'])){ |
| 1664 |
$entry['_vx_created']=date('m/d/Y h:i A',strtotime($entry['_vx_created'])); |
| 1665 |
} |
| 1666 |
if(!empty($entry['_vx_updated'])){ |
| 1667 |
$entry['_vx_updated']=date('m/d/Y h:i A',strtotime($entry['_vx_updated'])); |
| 1668 |
} |
| 1669 |
if(!empty($entry['__vx_entry'])){ |
| 1670 |
$entry['_vx_url']=$entry['__vx_entry']['url']; |
| 1671 |
} |
| 1672 |
// if(!is_admin()){ |
| 1673 |
$entry['_vx_htuk']=isset($_COOKIE['hubspotutk']) ? $_COOKIE['hubspotutk'] : null; |
| 1674 |
if(empty($entry['_vx_url'])){ |
| 1675 |
$entry['_vx_url']=$_SERVER['HTTP_REFERER']; |
| 1676 |
} |
| 1677 |
// } |
| 1678 |
if(empty($entry['_vx_url'])){ |
| 1679 |
$entry['_vx_url']=site_url(); |
| 1680 |
} |
| 1681 |
$back_id = url_to_postid($entry['_vx_url']); |
| 1682 |
if( !empty($back_id) ){ |
| 1683 |
$entry['_vx_title'] = get_the_title( $back_id ); |
| 1684 |
} |
| 1685 |
$entry['_vx_ip']=$this->get_client_ip(); |
| 1686 |
|
| 1687 |
|
| 1688 |
if(empty($form['__vx_addons']) && ($event == '' || $event == 'update' || $event == 'submit')){ |
| 1689 |
$entry=apply_filters('vx_crm_post_fields',$entry,$entry_id,$type,$form); |
| 1690 |
} |
| 1691 |
//var_dump($entry,$entry_id,$type); die('--------'); |
| 1692 |
$screen_msg_class="updated"; $notice=""; $log_link=''; |
| 1693 |
if(is_array($feeds_meta) && count($feeds_meta)>0){ |
| 1694 |
foreach($feeds_meta as $feed){ |
| 1695 |
$temp=array(); |
| 1696 |
$force_send=false; |
| 1697 |
$post_comment=true; |
| 1698 |
$screen_msg=""; |
| 1699 |
$parent_id=0; |
| 1700 |
if(isset($entry['__vx_parent_id'])){ |
| 1701 |
$parent_id=$entry['__vx_parent_id']; |
| 1702 |
} |
| 1703 |
$object=$this->post('object',$feed); |
| 1704 |
|
| 1705 |
if(empty($object)){ |
| 1706 |
continue; |
| 1707 |
} |
| 1708 |
|
| 1709 |
$data=$meta=array(); |
| 1710 |
if(is_array($feed)){ |
| 1711 |
if(isset($feed['data']) && is_array($feed['data'])){ |
| 1712 |
$data=$feed['data']; |
| 1713 |
$feed=array_merge($feed,$data); |
| 1714 |
} |
| 1715 |
// |
| 1716 |
if(isset($feed['meta']) && is_array($feed['meta'])){ |
| 1717 |
$meta=$feed['meta']; |
| 1718 |
$feed=array_merge($feed,$meta); |
| 1719 |
} |
| 1720 |
} |
| 1721 |
|
| 1722 |
if( in_array($event,array('restore','update','delete','add_note','delete_note'))){ |
| 1723 |
$is_admin=true; |
| 1724 |
$search_object=$object; |
| 1725 |
if(in_array($event,array('add_note','delete_note')) && !empty($log)){ |
| 1726 |
self::$note=array('id'=>$log['parent_id']); |
| 1727 |
if($event == 'add_note'){ |
| 1728 |
$note=json_decode($log['data'],true); |
| 1729 |
if(!empty($note['Title']['value'])){ |
| 1730 |
self::$note['title']=$note['Title']['value']; |
| 1731 |
self::$note['body']=$note['Body']['value']; |
| 1732 |
} |
| 1733 |
} |
| 1734 |
} |
| 1735 |
if($event == 'delete_note' && !empty(self::$note)){ |
| 1736 |
$parent_id=self::$note['id']; |
| 1737 |
} |
| 1738 |
|
| 1739 |
if(in_array($event,array('delete_note','add_note'))){ |
| 1740 |
//check feed |
| 1741 |
$order_notes=$this->post('entry_notes',$feed); //if notes sync not enabled in feed return |
| 1742 |
|
| 1743 |
if( empty($order_notes)){ |
| 1744 |
continue; |
| 1745 |
} |
| 1746 |
//change main object to Note |
| 1747 |
$feed['related_object']=$object; |
| 1748 |
$object=$feed['object']='Note'; |
| 1749 |
} |
| 1750 |
if($event == 'delete_note'){ |
| 1751 |
//when deleting note search note object |
| 1752 |
$search_object='Note'; |
| 1753 |
} |
| 1754 |
$_data=$this->get_data_object(); |
| 1755 |
$feed_log=$_data->get_feed_log($feed['id'],$entry_id,$search_object,$parent_id); |
| 1756 |
//var_dump($feed_log); die(); |
| 1757 |
if($event == 'restore' && $feed_log['status'] != 5) { // only allow successfully deleted records |
| 1758 |
continue; |
| 1759 |
} |
| 1760 |
if( in_array($event,array('update','delete') ) && !in_array($feed_log['status'],array(1,2) ) ){ // only allow successfully sent records |
| 1761 |
continue; |
| 1762 |
} |
| 1763 |
if(empty($feed_log['crm_id']) || empty($feed_log['object']) || $feed_log['object'] != $search_object){ |
| 1764 |
|
| 1765 |
continue; |
| 1766 |
} |
| 1767 |
if($event !='restore'){ |
| 1768 |
$feed['crm_id']=$feed_log['crm_id']; |
| 1769 |
unset($feed['primary_key']); |
| 1770 |
} |
| 1771 |
$feed['event']=$event; |
| 1772 |
// add note and save related extra info |
| 1773 |
if( $event == 'add_note' && !empty(self::$note)){ |
| 1774 |
$temp=array('Title'=>array('value'=>self::$note['title']),'Body'=>array('value'=>self::$note['body']),'ParentId'=>array('value'=> $feed['crm_id'])); |
| 1775 |
$parent_id=self::$note['id']; |
| 1776 |
$feed['note_object_link']='<a href="'.$feed_log['link'].'" target="_blank">'.$feed_log['crm_id'].'</a>'; |
| 1777 |
} |
| 1778 |
// delete not and save extra info |
| 1779 |
if( $event == 'delete_note'){ |
| 1780 |
|
| 1781 |
$feed_log_arr= json_decode($feed_log['extra'],true); |
| 1782 |
if(isset($feed_log_arr['note_object_link'])){ |
| 1783 |
$feed['note_object_link']=$feed_log_arr['note_object_link']; |
| 1784 |
} |
| 1785 |
$temp=array('ParentId'=>array('value'=> $feed['crm_id'])); |
| 1786 |
} |
| 1787 |
//delete object |
| 1788 |
if( $event == 'delete'){ |
| 1789 |
$temp=array('Id'=>array('value'=> $feed['crm_id'])); |
| 1790 |
} |
| 1791 |
// |
| 1792 |
if(!in_array($event , array('update','restore') )){ |
| 1793 |
//do not apply filters when adding note , deleting note , entry etc |
| 1794 |
$force_send=true; |
| 1795 |
} |
| 1796 |
//do not post comment in al other cases |
| 1797 |
$post_comment=false; |
| 1798 |
|
| 1799 |
} |
| 1800 |
// var_dump(self::$note,$object,$feed['note_object'],$feed['object'],$feed['crm_id'],$feed['event'],$temp,$force_send); |
| 1801 |
if(isset($entry['__vx_data'])){ |
| 1802 |
$force_send=true; |
| 1803 |
$temp=$entry['__vx_data']; |
| 1804 |
} |
| 1805 |
|
| 1806 |
if(!$force_send && isset($data['map']) && is_array($data['map']) && count($data['map'])>0){ |
| 1807 |
|
| 1808 |
$custom= isset($meta['fields']) && is_array($meta['fields']) ? $meta['fields'] : array(); |
| 1809 |
if(empty($this->form_fields)){ |
| 1810 |
$this->form_fields=$this->get_form_fields($form['id']); |
| 1811 |
} |
| 1812 |
foreach($data['map'] as $k=>$v){ |
| 1813 |
/// |
| 1814 |
$value=null; |
| 1815 |
if(!empty($v)){ //if value not empty |
| 1816 |
if($this->post('type',$v) == "value"){ //custom value |
| 1817 |
$value=trim($this->post('value',$v)); |
| 1818 |
$value=$this->process_tags($entry,$value); |
| 1819 |
|
| 1820 |
}else{ //general field |
| 1821 |
$field=$this->post('field',$v); |
| 1822 |
if($field !=""){ |
| 1823 |
$value=$this->verify_field_val($entry,$field); |
| 1824 |
|
| 1825 |
if(!empty($value) && in_array($k,array('date_of_birth')) ){ |
| 1826 |
$date_format=get_option('date_format'); |
| 1827 |
$value=date($date_format,strtotime($value)); |
| 1828 |
} |
| 1829 |
|
| 1830 |
} |
| 1831 |
if($value =='' && in_array($k,array('email'))){ |
| 1832 |
$value=null; |
| 1833 |
} |
| 1834 |
} |
| 1835 |
if(!is_null($value) && isset($custom[$k])){ |
| 1836 |
$temp[$k]=array("value"=>$value,"label"=>$custom[$k]['label']); |
| 1837 |
} |
| 1838 |
} |
| 1839 |
} |
| 1840 |
// var_dump($temp); die(); |
| 1841 |
|
| 1842 |
if($object == 'Order'){ |
| 1843 |
$temp['Status']=array('value'=>'Draft','label'=>'Draft'); |
| 1844 |
} |
| 1845 |
//change owner id |
| 1846 |
if(isset($data['owner']) && $data['owner'] == "1"){ |
| 1847 |
$feed['OwnerId']=array('value'=> $data['user'],'label'=>'Owner ID'); |
| 1848 |
} |
| 1849 |
|
| 1850 |
//add account or contract |
| 1851 |
|
| 1852 |
if(!empty($data['company_check']) && !empty($data['object_company'])){ |
| 1853 |
$company_feed=$data['object_company']; |
| 1854 |
if( isset(self::$feeds_res[$company_feed]) ){ |
| 1855 |
|
| 1856 |
$company_res=self::$feeds_res[$company_feed]; |
| 1857 |
///// |
| 1858 |
if(!empty($company_res['id'])){ |
| 1859 |
$feed['_vx_company_id']=array('value'=> $company_res['id'],'label'=>'Company ID'); |
| 1860 |
}else{ //if empty continue |
| 1861 |
// continue; |
| 1862 |
} |
| 1863 |
} |
| 1864 |
|
| 1865 |
} |
| 1866 |
|
| 1867 |
if(!empty($data['contact_check']) && !empty($data['object_contact'])){ |
| 1868 |
$contact_feed=$data['object_contact']; |
| 1869 |
if( isset(self::$feeds_res[$contact_feed]) ){ |
| 1870 |
|
| 1871 |
$contact_res=self::$feeds_res[$contact_feed]; |
| 1872 |
|
| 1873 |
///// |
| 1874 |
if(!empty($contact_res['id'])){ |
| 1875 |
$feed['_vx_contact_id']=array('value'=> $contact_res['id'],'label'=>'Contact ID'); |
| 1876 |
}else{ //if empty continue |
| 1877 |
// continue; |
| 1878 |
} |
| 1879 |
} |
| 1880 |
} |
| 1881 |
// |
| 1882 |
if(!empty($data['note_check']) ){ |
| 1883 |
$entry_note=''; $entry_note_title=''; |
| 1884 |
if(!empty($data['note_fields']) && is_array($data['note_fields'])){ |
| 1885 |
$data['note_val']='{'.implode("}\n{",$data['note_fields'])."}"; |
| 1886 |
} |
| 1887 |
if(!empty($data['note_val'])){ |
| 1888 |
$entry_note=$this->process_tags($entry,$data['note_val']); |
| 1889 |
if(empty($entry_note_title)){ |
| 1890 |
$entry_note_title=substr($entry_note,0,20); |
| 1891 |
} |
| 1892 |
if(!empty($entry_note)){ |
| 1893 |
$feed['__vx_entry_note']=array('Title'=>$entry_note_title,'Body'=>nl2br($entry_note)); |
| 1894 |
} |
| 1895 |
} |
| 1896 |
} |
| 1897 |
// |
| 1898 |
} |
| 1899 |
|
| 1900 |
$no_filter=true; |
| 1901 |
//not submitted by admin |
| 1902 |
if( !$is_admin && $this->post('manual_export',$data) == "1"){ //if manual export is yes |
| 1903 |
continue; |
| 1904 |
} |
| 1905 |
if(isset($_REQUEST['bulk_action']) && $_REQUEST['bulk_action'] =="send_to_crm_bulk_force" && !empty($log_id)){ |
| 1906 |
$force_send=true; |
| 1907 |
} |
| 1908 |
if(!$force_send && $this->post('optin_enabled',$data) == "1"){ //apply filters if not sending by force and optin is enabled |
| 1909 |
$no_filter=$this->check_filter($data,$entry); |
| 1910 |
$res=array("status"=>"4","extra"=>array("filter"=>$this->filter_condition),"data"=>$temp); |
| 1911 |
} |
| 1912 |
$account=$this->post('account',$feed); |
| 1913 |
$feed['meta']=$meta; |
| 1914 |
$feed['data']=$data; |
| 1915 |
$info=$this->get_info($account); |
| 1916 |
|
| 1917 |
if($no_filter){ //get $res if no filter , other wise use filtered $res |
| 1918 |
$api=$this->get_api($info); |
| 1919 |
$feed['_vx_entry']=$entry; |
| 1920 |
$res=$api->push_object($feed['object'],$temp,$feed); |
| 1921 |
} |
| 1922 |
|
| 1923 |
$feed_id=$this->post('id',$feed); |
| 1924 |
self::$feeds_res[$feed_id]=$res; |
| 1925 |
$status=$res['status']; $error=""; $id=""; |
| 1926 |
if($this->post('id',$res)!=""){ |
| 1927 |
$id=$res['id']; |
| 1928 |
$action=$this->post('action',$res); |
| 1929 |
|
| 1930 |
if($action == "Added"){ |
| 1931 |
if(empty($res['link'])){ |
| 1932 |
$msg=sprintf(__('Successfully Added to HubSpot (%s) with ID # %s .', 'contact-form-hubspot-crm'),$feed['object'],$res['id']); |
| 1933 |
}else{ |
| 1934 |
$msg=sprintf(__('Successfully Added to HubSpot (%s) with ID # %s . View entry at %s', 'contact-form-hubspot-crm'),$feed['object'],$res['id'],$res['link']); |
| 1935 |
} |
| 1936 |
$screen_msg=__( 'Entry added in HubSpot', 'contact-form-hubspot-crm'); |
| 1937 |
}else{ |
| 1938 |
if(empty($res['link'])){ |
| 1939 |
$msg=sprintf(__('Successfully Updated to HubSpot (%s) with ID # %s . View entry at %s', 'contact-form-hubspot-crm'),$feed['object'],$res['id'],$res['link']); |
| 1940 |
}else{ |
| 1941 |
$msg=sprintf(__('Successfully Updated to HubSpot (%s) with ID # %s .', 'contact-form-hubspot-crm'),$feed['object'],$res['id']); |
| 1942 |
} |
| 1943 |
if($event == 'delete'){ |
| 1944 |
$screen_msg=__( 'Entry deleted from HubSpot', 'contact-form-hubspot-crm'); |
| 1945 |
}else{ |
| 1946 |
$screen_msg=__( 'Entry updated in HubSpot', 'contact-form-hubspot-crm'); |
| 1947 |
} |
| 1948 |
} |
| 1949 |
|
| 1950 |
|
| 1951 |
}else if($this->post('status',$res) == 4){ |
| 1952 |
$screen_msg=$msg=__( 'Entry filtered', 'contact-form-hubspot-crm'); |
| 1953 |
}else if(strpos($object,'vxf_') !== false && !empty($res['status'])){ |
| 1954 |
$objects=$this->get_objects($info); |
| 1955 |
if(isset($objects[$object])){ |
| 1956 |
$object=$objects[$object]; |
| 1957 |
} |
| 1958 |
$screen_msg=__('Form Submitted to Hubspot.' , 'contact-form-hubspot-crm' ); |
| 1959 |
|
| 1960 |
}else{ |
| 1961 |
$screen_msg_class="error"; |
| 1962 |
$screen_msg=__('Errors when adding to HubSpot. Entry not sent! Check the Entry Notes below for more details.' , 'contact-form-hubspot-crm' ); |
| 1963 |
if($log_id!=""){ |
| 1964 |
//message for bulk actions in logs |
| 1965 |
$screen_msg=__('Errors when adding to HubSpot. Entry not sent' , 'contact-form-hubspot-crm' ); |
| 1966 |
} |
| 1967 |
$msg=sprintf(__('Error while creating %s', 'contact-form-hubspot-crm'),$feed['object']); |
| 1968 |
if($this->post('error',$res)!=""){ |
| 1969 |
$error= is_array($res['error']) ? json_encode($res['error']) : $res['error']; |
| 1970 |
$msg.=" ($error)"; |
| 1971 |
|
| 1972 |
$_REQUEST['VXGHubSpotError']=$msg; //front end form error for admin only |
| 1973 |
} |
| 1974 |
if(!$is_admin){ |
| 1975 |
$info['msg']=$msg; |
| 1976 |
$this->send_error_email($info,$entry,$form); |
| 1977 |
} |
| 1978 |
|
| 1979 |
} |
| 1980 |
|
| 1981 |
//insert log |
| 1982 |
$arr=array("object"=>$feed["object"],"form_id"=>$form['id'],"status"=>$status,"entry_id"=>$entry_id,"crm_id"=>$id,"meta"=>$error,"time"=>date('Y-m-d H:i:s'),"data"=>$this->post('data',$res),"response"=>$this->post('response',$res),"extra"=>$this->post('extra',$res),"feed_id"=>$this->post('id',$feed),'parent_id'=>$parent_id,'event'=>$event,"link"=>$this->post('link',$res)); |
| 1983 |
$settings=get_option($this->type.'_settings',array()); |
| 1984 |
// if($this->post('disable_log',$settings) !="yes"){ |
| 1985 |
$insert_id=$data_db->insert_log($arr,$log_id); |
| 1986 |
// } |
| 1987 |
$log_link=''; |
| 1988 |
if(!empty($insert_id)){ // |
| 1989 |
$log_url=admin_url( 'admin.php?page='.$this->id.'&tab=logs&log_id='.$insert_id); |
| 1990 |
$log_link=' <a href="'.esc_url($log_url).'" class="vx_log_link" data-id="'.$insert_id.'">'.__('View Detail','contact-form-hubspot-crm')."</a>"; |
| 1991 |
$screen_msg.=$log_link; |
| 1992 |
} |
| 1993 |
if($post_comment){ |
| 1994 |
//insert entry comment |
| 1995 |
//$this->add_note($entry["id"], $msg); |
| 1996 |
} |
| 1997 |
if($notice!=""){ |
| 1998 |
$notice.='<br/>'; |
| 1999 |
} |
| 2000 |
$notice.='<b>'.$object.': </b>'.$screen_msg; |
| 2001 |
|
| 2002 |
} |
| 2003 |
} |
| 2004 |
return array("msg"=>$notice,"class"=>$screen_msg_class); |
| 2005 |
} |
| 2006 |
|
| 2007 |
public function process_tags($entry,$value){ |
| 2008 |
//starts with { and ends } , any char in brackets except { |
| 2009 |
preg_match_all('/\{[^\{]+\}/',$value,$matches); |
| 2010 |
if(!empty($matches[0])){ |
| 2011 |
$vals=array(); |
| 2012 |
foreach($matches[0] as $m){ |
| 2013 |
$m=trim($m,'{}'); |
| 2014 |
$val_cust=$this->verify_field_val($entry,$m); |
| 2015 |
if(is_array($val_cust)){ $val_cust=trim(implode(' ',$val_cust)); } |
| 2016 |
$vals['{'.$m.'}']=$val_cust; |
| 2017 |
} |
| 2018 |
$value=str_replace(array_keys($vals),array_values($vals),$value); |
| 2019 |
} |
| 2020 |
return $value; |
| 2021 |
} |
| 2022 |
|
| 2023 |
public function get_client_ip() { |
| 2024 |
$ip=''; |
| 2025 |
if (!empty($_SERVER['HTTP_CLIENT_IP'])) { |
| 2026 |
$ip = $_SERVER['HTTP_CLIENT_IP']; |
| 2027 |
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
| 2028 |
$ip = $_SERVER['HTTP_X_FORWARDED_FOR']; |
| 2029 |
} else { |
| 2030 |
$ip = $_SERVER['REMOTE_ADDR']; |
| 2031 |
} |
| 2032 |
if(strpos($ip,',')!== false){ |
| 2033 |
$a=explode(',',$ip); |
| 2034 |
if(isset($a[1])){ $ip=trim($a[1]);} |
| 2035 |
} |
| 2036 |
return $ip; |
| 2037 |
} |
| 2038 |
/** |
| 2039 |
* Send error email |
| 2040 |
* |
| 2041 |
* @param mixed $info |
| 2042 |
* @param mixed $entry |
| 2043 |
* @param mixed $form |
| 2044 |
*/ |
| 2045 |
public function send_error_email($info,$entry,$form){ |
| 2046 |
if(!empty($info['data']['error_email'])){ |
| 2047 |
$subject="Error While Posting to HubSpot"; |
| 2048 |
$entry_link=add_query_arg(array('page' => 'vxcf_leads','tab'=>'entries', 'id' => $entry['__vx_id']), admin_url('admin.php')); |
| 2049 |
$page_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; |
| 2050 |
|
| 2051 |
$detail=array( |
| 2052 |
"Time"=>date('d/M/y H:i:s',current_time('timestamp')), |
| 2053 |
"Page URL"=>'<a href="'.$page_url.'" style="word-break:break-all;">'.$page_url.'</a>', |
| 2054 |
"Entry ID"=>'<a href="'.$entry_link.'" target="_blank" style="word-break:break-all;">'.$entry_link.'</a>' |
| 2055 |
); |
| 2056 |
if(isset($form['title'])){ |
| 2057 |
$detail["Form Name"]=$form['title']; |
| 2058 |
$detail["Form Id"]=$form['id']; |
| 2059 |
} |
| 2060 |
$email_info=array("msg"=>$info['msg'],"title"=>__('HubSpot','contact-form-hubspot-crm')." Error","info_title"=>"More Detail","info"=>$detail); |
| 2061 |
$email_body=$this->format_user_info($email_info,true); |
| 2062 |
|
| 2063 |
$error_emails=explode(",",$info['data']['error_email']); |
| 2064 |
$headers = array('Content-Type: text/html; charset=UTF-8'); |
| 2065 |
foreach($error_emails as $email) |
| 2066 |
wp_mail(trim($email),$subject, $email_body,$headers); |
| 2067 |
|
| 2068 |
} |
| 2069 |
|
| 2070 |
} |
| 2071 |
/** |
| 2072 |
* Get Objects from local options or from hubspot |
| 2073 |
* |
| 2074 |
* @param mixed $check_option |
| 2075 |
* @return array |
| 2076 |
*/ |
| 2077 |
public function get_objects($info="",$refresh=false){ |
| 2078 |
|
| 2079 |
$objects=array("Contact"=>'Contact',"Company"=>'Company',"Deal"=>'Deal',"Ticket"=>'Ticket',"Task"=>'Task','leads'=>'Leads','orders'=>'Orders','invoices'=>'Invoices','carts'=>'Carts','products'=>'Products'); //,'quotes'=>'Quotes' |
| 2080 |
if(isset($info['data']) && is_array($info['data']) && !(isset($info['data']['api']) && $info['data']['api'] == 'api' && empty($info['data']['object_lib']) )){ |
| 2081 |
$objects['0-420']='Listings'; |
| 2082 |
$objects['0-421']='Appointemts'; |
| 2083 |
$objects['0-162']='Services'; |
| 2084 |
$objects['0-410']='Courses'; |
| 2085 |
} |
| 2086 |
if(!empty($info)){ |
| 2087 |
$meta=$this->post('meta',$info); |
| 2088 |
}else{ |
| 2089 |
$meta=get_option($this->id.'_meta',array()); |
| 2090 |
} |
| 2091 |
|
| 2092 |
if(empty($meta['objects'])){ |
| 2093 |
$refresh=true; |
| 2094 |
}else if(!$refresh){ |
| 2095 |
$objects=$meta['objects']; |
| 2096 |
} |
| 2097 |
|
| 2098 |
if($refresh){ |
| 2099 |
$api=$this->get_api($info); |
| 2100 |
$custom_objects=$api->get_custom_objects(); |
| 2101 |
if(!empty($custom_objects)){ |
| 2102 |
$objects=array_merge($objects,$custom_objects); |
| 2103 |
} |
| 2104 |
$res=$api->get_forms(); |
| 2105 |
|
| 2106 |
if(is_array($res) && isset($res[0])){ |
| 2107 |
foreach($res as $v){ |
| 2108 |
if(!empty($v['portalId'])){ |
| 2109 |
$meta['portal_id']=$v['portalId']; |
| 2110 |
} |
| 2111 |
$objects['vxf_'.$v['guid']]=$v['name']; |
| 2112 |
} |
| 2113 |
} |
| 2114 |
|
| 2115 |
if(is_array($objects) && !empty($info['id'])){ |
| 2116 |
$option=get_option($this->id.'_meta',array()); |
| 2117 |
$meta_objects=$objects; |
| 2118 |
if(!empty($option['objects']) && is_array($option['objects'])){ |
| 2119 |
$meta_objects=array_merge($option['objects'],$objects); |
| 2120 |
} |
| 2121 |
/* if(!empty($token['access_token'])){ |
| 2122 |
$path='integrations/v1/me'; |
| 2123 |
$res=$this->post_hubspot_arr($path); |
| 2124 |
if(!empty($res['portalId'])){ |
| 2125 |
$info['portal_id']=$res['portalId']; |
| 2126 |
} |
| 2127 |
} */ |
| 2128 |
$option['objects']=$meta_objects; |
| 2129 |
update_option($this->id.'_meta',$option); //save objects for logs search option |
| 2130 |
$meta["objects"]=$objects; |
| 2131 |
$this->update_info(array("meta"=>$meta),$info['id']); |
| 2132 |
} |
| 2133 |
} |
| 2134 |
return $objects; |
| 2135 |
} |
| 2136 |
/** |
| 2137 |
* web2lead fields |
| 2138 |
* |
| 2139 |
* @param mixed $module |
| 2140 |
* @param mixed $map |
| 2141 |
*/ |
| 2142 |
public function web_fields($module,$map){ |
| 2143 |
//////////////////////////// |
| 2144 |
$web['Lead']='{"1":{"label":"First Name","max":"40","name":"first_name","type":"text"},"2":{"label":"Last Name","max":"80","name":"last_name","type":"text","req":"true"},"3":{"label":"Email","max":"80","name":"email","type":"text","req":"true"},"4":{"label":"Company","max":"40","name":"company","type":"text"},"5":{"label":"City","max":"40","name":"city","type":"text"},"6":{"label":"State/Province","max":"20","name":"state","type":"text"},"7":{"label":"Salutation","name":"salutation","type":"select"},"8":{"label":"Title","max":"40","name":"title","type":"text"},"9":{"label":"Website","max":"80","name":"URL","type":"text"},"10":{"label":"Phone","max":"40","name":"phone","type":"text"},"11":{"label":"Mobile","max":"40","name":"mobile","type":"text"},"12":{"label":"Fax","max":"40","name":"fax","type":"text"},"13":{"label":"Address","name":"street","type":"select"},"14":{"label":"Zip","max":"20","name":"zip","type":"text"},"15":{"label":"Country","max":"40","name":"country","type":"text"},"16":{"label":"Description","name":"description","type":"select"},"17":{"label":"Lead Source","name":"lead_source","type":"select"},"18":{"label":"Industry","name":"industry","type":"select"},"19":{"label":"Rating","name":"rating","type":"select"},"20":{"label":"Annual Revenue","name":"revenue","type":"text"},"21":{"label":"Employees","name":"employees","type":"text"},"22":{"label":"Email Opt Out","name":"emailOptOut","type":"checkbox"},"23":{"label":"Fax Opt Out","name":"faxOptOut","type":"checkbox"},"24":{"label":"Do Not Call","name":"doNotCall","type":"checkbox"}}'; |
| 2145 |
$web['Case']='{"1":{"label":"Contact Name","max":"80","name":"name","type":"text"},"2":{"label":"Email","max":"80","name":"email","type":"text"},"3":{"label":"Phone","max":"40","name":"phone","type":"text"},"4":{"label":"Subject","max":"80","name":"subject","type":"text"},"5":{"label":"Description","name":"description","type":"select"},"6":{"label":"Company","max":"80","name":"company","type":"text"},"7":{"label":"Type","name":"type","type":"select"},"8":{"label":"Status","name":"status","type":"select"},"9":{"label":"Case Reason","name":"reason","type":"select"},"10":{"label":"Priority","name":"priority","type":"select"}}'; |
| 2146 |
////////////////// |
| 2147 |
if(isset($web[$module])){ |
| 2148 |
$fields=json_decode($web[$module],true); |
| 2149 |
foreach($map as $k=>$v){ |
| 2150 |
if(isset($v['name_c'])) |
| 2151 |
$fields[$k]=$v; |
| 2152 |
} |
| 2153 |
} |
| 2154 |
return $fields; |
| 2155 |
} |
| 2156 |
|
| 2157 |
/** |
| 2158 |
* check if user conected to crm |
| 2159 |
* |
| 2160 |
* @param mixed $settings |
| 2161 |
*/ |
| 2162 |
public function api_is_valid($info="") { |
| 2163 |
|
| 2164 |
if(isset($info['data']['class']) && is_array($info['data']) && $info['data']['class'] =='updated'){ |
| 2165 |
return true; |
| 2166 |
}else{ |
| 2167 |
return false;} |
| 2168 |
} |
| 2169 |
} |
| 2170 |
|
| 2171 |
$vxcf_hubspot=new vxcf_hubspot(); |
| 2172 |
$vxcf_hubspot->instance(); |
| 2173 |
$vx_cf['vxcf_hubspot']='vxcf_hubspot'; |
| 2174 |
endif; |
| 2175 |
|
| 2176 |
|