-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.php
executable file
·116 lines (103 loc) · 4.18 KB
/
plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
/*
Plugin Name: AIESEC EXPA
Description: Plugin based on gis_curl_registration script by Dan Laush upgraded to Wordpress plugin
Version: 0.2
Author: Krzysztof Jackowski
Author URI: https://www.linkedin.com/profile/view?id=202008277&trk=nav_responsive_tab_profile_pic
License: GPL
*/
defined( 'ABSPATH' ) or die( 'Plugin file cannot be accessed directly.' );
// [expa-form program="gt"]
function expa_form( $atts ) {
wp_enqueue_script('jquery');
$a = shortcode_atts( array(
'program' => '',
), $atts );
echo wp_enqueue_style( 'style-name', plugins_url('style.css', __FILE__ ));
if(isset($_GET['utm_source'])){
$utm_source = $_GET["utm_source"];
}else{
$utm_source = "generic";
}
if(isset($_GET['utm_medium'])){
$utm_medium = $_GET["utm_medium"];
}else{
$utm_medium = "generic";
}
if(isset($_GET['utm_campaign'])){
$utm_campaign = $_GET["utm_campaign"];
}else{
$utm_campaign = "generic";
}
if(isset($_GET['bucket'])){
$bucket = $_GET["bucket"];
}else{
$bucket = "n/d";
}
if(isset($_GET['lc'])){
$lc = $_GET["lc"];
}else{
$lc = "n/d";
}
$form = file_get_contents('form.html',TRUE);
$uniqid = uniqid();
if($bucket==""){
$bucket = "n/d";
}
//check if lead parameters where provided if not set to generic
if($utm_source==""){
$utm_source = "generic";
}
if($utm_medium==""){
$utm_medium = "generic";
}
if($utm_campaign==""){
$utm_campaign = "generic";
}
///////Get EXPA Leads from MKT Tracking Tool API/////////////////
$string = file_get_contents(plugins_url('config.json', __FILE__ ));
$config = json_decode($string, true);
$url = $config['api_host'].'/api/v1/get-expa-leads';
$crl = curl_init($url);
$headr = array();
$accesstoken = $config['api_auth_token'];
$headr[] = 'X-Authorization: '.$accesstoken;
curl_setopt($crl, CURLOPT_HTTPHEADER,$headr);
curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($crl);
curl_close($crl);
$leads = json_decode($res);
//var_dump($leads);
$option_list = "";
foreach($leads as $key => $value){
$option_list = $option_list.'<option value="'.$value->expa_name.'">'.$value->keywords.'</option>'."\n";//var_dump($lead->);
}
//////////////////////////////////////////////////////////////////////
////////////Replace elements in form.html////////////////////////////
$form = str_replace("{utm_source}",$utm_source,$form);
$form = str_replace("{utm_medium}",$utm_medium,$form);
$form = str_replace("{utm_campaign}",$utm_campaign,$form);
$form = str_replace("{bucket}",$bucket,$form);
$form = str_replace("{uniqid}",$uniqid,$form);
$form = str_replace("{program}",$a['program'],$form);
$form = str_replace("{path-gis_reg_process}",plugins_url('gis_reg_process.php', __FILE__ ),$form);
$form = str_replace("{path-gis_lcMapper}",plugins_url('gis_lcMapper.js', __FILE__ ),$form);
$form = str_replace("{path-leads-json}",plugins_url('leads.json', __FILE__ ),$form);
$actual_link = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$form = str_replace("{website_url}",$actual_link,$form);
$form = str_replace("{leads-option-list}",$option_list,$form);
$form = str_replace("{lc}",$lc,$form);
$form = str_replace("{path-manage_registration}",plugins_url('manage_registration.php', __FILE__ ),$form);
$form = str_replace("{path-manage_leads}",plugins_url('manage_leads.php', __FILE__ ),$form);
if(isset($_GET["thank_you"]) && $_GET["thank_you"]==="true"){
return "<p>Dziękujemy bardzo za rejestrację. Wkrótce dostaniesz maila z potwierdzeniem założenia konta. Powodzenia w Twojej podróży do kariery!</p>";
} elseif (isset($_GET["error"]) && $_GET["error"]!=""){
$form = str_replace('<div id="error" class="error"><p></p></div>','<div id="error" class="error"><p>'.$_GET["error"].'</p></div>',$form);
return $form;
}
//var_dump( plugins_url('gis_reg_process.php', __FILE__ ));
return $form;
}
add_shortcode( 'expa-form', 'expa_form' );
?>