-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscrap.php
More file actions
140 lines (115 loc) · 4.11 KB
/
scrap.php
File metadata and controls
140 lines (115 loc) · 4.11 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
$rawhtmlAWeber = file_get_contents( 'rawhtmlform_aweber.txt' );
$rawhtmlMailChimp = file_get_contents( 'rawhtmlform_mailchimp.txt' );
$rawhtmlGetResponse = file_get_contents( 'rawhtmlform_getresponse.txt' );
$rawhtmlActiveCampaign = file_get_contents( 'rawhtmlform_activecampaign.txt' );
$rawhtmlMadMimi = file_get_contents( 'rawhtmlform_madmimi.txt' );
$document = new DOMDocument();
libxml_use_internal_errors(true);
$document->loadHTML( $rawhtmlAWeber );
libxml_clear_errors();
$form = $document->getElementsByTagName( 'form' );
$input = $document->getElementsByTagName( 'input' );
$optinParams = array();
if ( $form->length > 0 ) {
for ( $i=0; $i<$form->length; $i++ ) {
$formTag = $form->item( $i );
$action = $formTag->attributes->getNamedItem( 'action' )->value;
$method = $formTag->attributes->getNamedItem( 'method' )->value;
$optinParams['action'] = $action;
$optinParams['method'] = $method;
}
}
if ( $input->length > 0 ) {
for ( $i=0; $i<$input->length; $i++ ) {
$inputTag = $input->item( $i );
$nameAttr = $inputTag->attributes->getNamedItem( 'name' );
if ( !is_null( $nameAttr ) ) {
$name = $nameAttr->value;
} else {
$name = '';
}
$type = $inputTag->attributes->getNamedItem( 'type' )->value;
if ( $type == 'hidden' || $type == 'submit' ) {
$hiddenValue = $inputTag->attributes->getNamedItem( 'value' )->value;
$optinParams['hiddenfields'][] = array( 'name' => $name, 'value' => $hiddenValue );
} else {
$optinParams['fields'][] = $name;
}
}
}
$optinFields = array();
foreach ( $optinParams['fields'] as $field ) {
$lowerCaseField = strtolower( $field );
if ( strpos( $lowerCaseField, 'email' ) !== false ) {
$optinFields['fields']['email'][$field] = 'mtasuandi@outlook.com';
}
if ( $lowerCaseField != 'fullname' ) {
if ( strpos( $lowerCaseField, 'fname' ) !== false || strpos( $lowerCaseField, 'firstname' ) !== false ) {
$optinFields['fields']['name'][$field] = 'First Name';
}
if ( strpos( $lowerCaseField, 'lname' ) !== false || strpos( $lowerCaseField, 'lastname' ) !== false ) {
$optinFields['fields']['name'][$field] = 'Last Name';
}
}
if ( strpos( $lowerCaseField, 'name' ) !== false || strpos( $lowerCaseField, 'fullname' ) !== false ) {
$optinFields['fields']['name'][$field] = 'Full Name';
}
if ( strpos( $lowerCaseField, 'phone' ) !== false ) {
$optinFields['fields']['phone'][$field] = '+6281220504072';
}
if( preg_match( '([a-zA-Z].*[0-9]|[0-9].*[a-zA-Z])', $lowerCaseField ) ) {
$optinFields['fields']['unique'][$field] = '';
}
}
foreach ( $optinParams['hiddenfields'] as $hiddenfield ) {
$optinFields['fields']['hidden'][$hiddenfield['name']] = $hiddenfield['value'];
}
$emailField = array();
if ( isset( $optinFields['fields']['email'] ) ) {
$emailField = $optinFields['fields']['email'];
}
$nameField = array();
if ( isset( $optinFields['fields']['name'] ) ) {
$nameField = $optinFields['fields']['name'];
}
$phoneField = array();
if ( isset( $optinFields['fields']['phone'] ) ) {
$phoneField = $optinFields['fields']['phone'];
}
$uniqueField = array();
if ( isset( $optinFields['fields']['unique'] ) ) {
$uniqueField = $optinFields['fields']['unique'];
}
$hiddenField = array();
if ( isset( $optinFields['fields']['hidden'] ) ) {
$hiddenField = $optinFields['fields']['hidden'];
}
$optinSendParam = array_merge(
$emailField,
$nameField,
$phoneField,
$uniqueField,
$hiddenField
);
// echo "<pre>"; print_r( $optinSendParam ); echo "</pre>"; exit();
$postData = '';
foreach ( $optinSendParam as $k => $v ) {
$postData .= $k . '='.$v.'&';
}
$postData = rtrim( $postData, '&' );
$ch = curl_init();
$url = $optinParams['action'];
$urlPost = $url;
if ( strpos( $url, 'http:' ) === false && strpos( $url, 'https:' ) === false ) {
$urlPost = 'https:' . $url;
}
curl_setopt( $ch, CURLOPT_URL, $urlPost );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $postData );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
$output = curl_exec( $ch );
curl_close( $ch );
var_dump( $output );