-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrucss-tests.php
175 lines (124 loc) · 4.92 KB
/
rucss-tests.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
// License validation tool
include('classes/loader.php');
$url = $_GET['url'];
$warmup_url = $_GET['url_warmup'];
?>
<?php
include('inc/header.php');
include('inc/nav.php');
?>
<div class="container-fluid">
<div class="grids">
<div class="clearfix"></div>
<div class="row p-4 py-0">
<div class="col-12">
<h2>RUCSS testing tool</h2>
<small>If pages still contains CSS files or not all CSS files are removed, go to Step 1 and check the <strong>unprocessedcss</strong>. If everything is finished this should be empty, but if there are some files pending to process continue with steps 2 and 3.</small><br><br>
<?php if($_GET['mode'] != "standalone") { ?>
<h3 style="margin-top: 40px;"><span class="badge badge-warning">Step 1</span> unProcessedCss</h3>
<p>Check if the URL receives <strong>unprocessedcss</strong> from our SaaS:</p>
<form action="rucss-tests.php" method="get">
<input name="action" value="unprocessedcss" type="hidden">
<div class="form-row">
<div class="col">
<input type="text" class="form-control" id="url" name="url" autocomplete="false" value="<?php echo $url; ?>" placeholder="Use the full URL including https://">
</div>
<div class="col">
<button type="submit" class="btn btn-primary mb-2">Test response from SaaS ›</button>
</div>
</div>
</form>
<?php
// TEST URL unprocessedcss
if($_GET['action'] == 'unprocessedcss' ) {
// prepare basic variables
$rucss_url = $_GET['url'].'?nowprocket';
$rucss_html = file_get_contents($rucss_url);
// create CURL post array
$post_fields = [
'html' => $rucss_html,
'url' => $rucss_url,
'config[rucss_safelist][]' => '',
];
// do the CURL request
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://central-saas.wp-rocket.me/api",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $post_fields,
CURLOPT_ENCODING => "",
CURLOPT_TIMEOUT => 30));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
// process the response
$response_object = json_decode($response, true);
// display the response
echo '<div class="api-results alert alert-info">';
echo '<h4>API Reply: List of unProcessedCss</h4>';
echo '<pre>';
foreach ($response_object['contents']["unProcessedCss"] as $unprocessed ) {
echo '<div><a class="btn btn-secondary btn-xs" target="_blank" href="?mode=standalone&action=warmup&url_warmup='.$unprocessed['content'].'">warmup resource ›</a> - '.$unprocessed['content'].'</div>';
}
echo '</pre>';
echo '</div>';
}
?>
<hr>
<h3 style="margin-top: 40px;"><span class="badge badge-warning">Step 2</span> Clean the Used CSS</h3>
<p>Is unProcessedCss empty?<br>- <strong>NO</strong> wait for 30 minutes, and test step 1 again. <br>- <strong>YES</strong> something went wrong. <strong>clean the Used CSS</strong> at the WP Admin, and test if everything is removed.
</p>
<hr>
<?php } // standalone warmup ?>
<h3 style="margin-top: 40px;"><span class="badge badge-warning">Step 3</span> Manual Warmup</h3>
<p>If after 30 minutes we still have unProcessedCSS then either our queue is too big or the file could NOT be processed. Manually try to warmup the file</p>
<form action="rucss-tests.php" method="get">
<input name="action" value="warmup" type="hidden">
<div class="form-row">
<div class="col">
<input type="text" class="form-control" id="url_warmup" name="url_warmup" autocomplete="false" value="<?php echo $warmup_url; ?>" placeholder="CSS or JS File to Warmup">
</div>
<div class="col">
<button type="submit" class="btn btn-primary mb-2">Warmup resource ›</button>
</div>
</div>
</form>
<?php
// TEST URL unprocessedcss
if($_GET['action'] == 'warmup' ) {
// prepare basic variables
$warmup_content = file_get_contents($warmup_url);
$parsed_url = parse_url($warmup_url);
$warmup_type = pathinfo($parsed_url['path'], PATHINFO_EXTENSION);
// create CURL post array
$post_fields = [
'resources[0][content]' => $warmup_content,
'resources[0][url]' => $warmup_url,
'resources[0][type]' => $warmup_type,
];
// do the CURL request
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://central-saas.wp-rocket.me/warmup",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $post_fields,
CURLOPT_ENCODING => "",
CURLOPT_TIMEOUT => 30));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
// process the response
$response_object = json_decode($response, true);
// display the response
echo '<div class="api-results alert alert-info">';
echo '<h4>API Reply: Warmup Resource </h4>';
echo '<pre>';
echo var_dump($response_object);
echo '</pre>';
echo '</div>';
}
?>
</div>
</div>
<?php include('inc/footer.php');