Version Description
- Fix support for PHP 5.3
Download this release
Release Info
Developer | unbouncewordpress |
Plugin | Unbounce Landing Pages |
Version | 1.0.32 |
Comparing to | |
See all releases |
Code changes from version 1.0.31 to 1.0.32
- UBCompatibility.php +134 -69
- UBConfig.php +382 -371
- UBDiagnostics.php +97 -64
- UBEvents.php +65 -51
- UBHTTP.php +342 -300
- UBIcon.php +7 -6
- UBLogger.php +74 -57
- UBPageTable.php +35 -32
- UBTemplate.php +20 -19
- UBUtil.php +74 -74
- UBWPListTable.php +1205 -1100
- Unbounce-Page.php +241 -206
- readme.txt +14 -2
- templates/authorize_button.php +12 -10
- templates/diagnostics.php +57 -65
- templates/main.php +29 -27
- templates/main_authorized.php +15 -11
- templates/main_authorized_footer.php +5 -2
- templates/main_failed_authorization.php +18 -10
- templates/main_header.php +8 -8
- templates/main_unauthorized.php +12 -8
- templates/main_unauthorized_footer.php +1 -1
UBCompatibility.php
CHANGED
@@ -3,85 +3,150 @@
|
|
3 |
// taken from: http://php.net/manual/en/function.http-response-code.php
|
4 |
// For 4.3.0 <= PHP <= 5.4.0
|
5 |
if (!function_exists('http_response_code')) {
|
6 |
-
|
7 |
-
|
8 |
-
if ($code !== NULL) {
|
9 |
-
|
10 |
-
switch ($code) {
|
11 |
-
case 100: $text = 'Continue'; break;
|
12 |
-
case 101: $text = 'Switching Protocols'; break;
|
13 |
-
case 200: $text = 'OK'; break;
|
14 |
-
case 201: $text = 'Created'; break;
|
15 |
-
case 202: $text = 'Accepted'; break;
|
16 |
-
case 203: $text = 'Non-Authoritative Information'; break;
|
17 |
-
case 204: $text = 'No Content'; break;
|
18 |
-
case 205: $text = 'Reset Content'; break;
|
19 |
-
case 206: $text = 'Partial Content'; break;
|
20 |
-
case 300: $text = 'Multiple Choices'; break;
|
21 |
-
case 301: $text = 'Moved Permanently'; break;
|
22 |
-
case 302: $text = 'Moved Temporarily'; break;
|
23 |
-
case 303: $text = 'See Other'; break;
|
24 |
-
case 304: $text = 'Not Modified'; break;
|
25 |
-
case 305: $text = 'Use Proxy'; break;
|
26 |
-
case 400: $text = 'Bad Request'; break;
|
27 |
-
case 401: $text = 'Unauthorized'; break;
|
28 |
-
case 402: $text = 'Payment Required'; break;
|
29 |
-
case 403: $text = 'Forbidden'; break;
|
30 |
-
case 404: $text = 'Not Found'; break;
|
31 |
-
case 405: $text = 'Method Not Allowed'; break;
|
32 |
-
case 406: $text = 'Not Acceptable'; break;
|
33 |
-
case 407: $text = 'Proxy Authentication Required'; break;
|
34 |
-
case 408: $text = 'Request Time-out'; break;
|
35 |
-
case 409: $text = 'Conflict'; break;
|
36 |
-
case 410: $text = 'Gone'; break;
|
37 |
-
case 411: $text = 'Length Required'; break;
|
38 |
-
case 412: $text = 'Precondition Failed'; break;
|
39 |
-
case 413: $text = 'Request Entity Too Large'; break;
|
40 |
-
case 414: $text = 'Request-URI Too Large'; break;
|
41 |
-
case 415: $text = 'Unsupported Media Type'; break;
|
42 |
-
case 500: $text = 'Internal Server Error'; break;
|
43 |
-
case 501: $text = 'Not Implemented'; break;
|
44 |
-
case 502: $text = 'Bad Gateway'; break;
|
45 |
-
case 503: $text = 'Service Unavailable'; break;
|
46 |
-
case 504: $text = 'Gateway Time-out'; break;
|
47 |
-
case 505: $text = 'HTTP Version not supported'; break;
|
48 |
-
default:
|
49 |
-
exit('Unknown http status code "' . htmlentities($code) . '"');
|
50 |
-
break;
|
51 |
-
}
|
52 |
-
|
53 |
-
$protocol = (isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1');
|
54 |
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
-
|
58 |
|
59 |
-
|
60 |
|
61 |
-
|
|
|
|
|
|
|
62 |
|
|
|
63 |
}
|
64 |
-
|
65 |
-
return $code;
|
66 |
-
|
67 |
-
}
|
68 |
}
|
69 |
|
70 |
// taken from: http://php.net/manual/en/function.getallheaders.php
|
71 |
-
if (!function_exists('getallheaders'))
|
72 |
-
{
|
73 |
function getallheaders()
|
74 |
{
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
}
|
83 |
-
return $headers;
|
84 |
}
|
85 |
}
|
86 |
-
|
87 |
-
?>
|
3 |
// taken from: http://php.net/manual/en/function.http-response-code.php
|
4 |
// For 4.3.0 <= PHP <= 5.4.0
|
5 |
if (!function_exists('http_response_code')) {
|
6 |
+
function http_response_code($code = null)
|
7 |
+
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
+
if ($code !== null) {
|
10 |
+
switch ($code) {
|
11 |
+
case 100:
|
12 |
+
$text = 'Continue';
|
13 |
+
break;
|
14 |
+
case 101:
|
15 |
+
$text = 'Switching Protocols';
|
16 |
+
break;
|
17 |
+
case 200:
|
18 |
+
$text = 'OK';
|
19 |
+
break;
|
20 |
+
case 201:
|
21 |
+
$text = 'Created';
|
22 |
+
break;
|
23 |
+
case 202:
|
24 |
+
$text = 'Accepted';
|
25 |
+
break;
|
26 |
+
case 203:
|
27 |
+
$text = 'Non-Authoritative Information';
|
28 |
+
break;
|
29 |
+
case 204:
|
30 |
+
$text = 'No Content';
|
31 |
+
break;
|
32 |
+
case 205:
|
33 |
+
$text = 'Reset Content';
|
34 |
+
break;
|
35 |
+
case 206:
|
36 |
+
$text = 'Partial Content';
|
37 |
+
break;
|
38 |
+
case 300:
|
39 |
+
$text = 'Multiple Choices';
|
40 |
+
break;
|
41 |
+
case 301:
|
42 |
+
$text = 'Moved Permanently';
|
43 |
+
break;
|
44 |
+
case 302:
|
45 |
+
$text = 'Moved Temporarily';
|
46 |
+
break;
|
47 |
+
case 303:
|
48 |
+
$text = 'See Other';
|
49 |
+
break;
|
50 |
+
case 304:
|
51 |
+
$text = 'Not Modified';
|
52 |
+
break;
|
53 |
+
case 305:
|
54 |
+
$text = 'Use Proxy';
|
55 |
+
break;
|
56 |
+
case 400:
|
57 |
+
$text = 'Bad Request';
|
58 |
+
break;
|
59 |
+
case 401:
|
60 |
+
$text = 'Unauthorized';
|
61 |
+
break;
|
62 |
+
case 402:
|
63 |
+
$text = 'Payment Required';
|
64 |
+
break;
|
65 |
+
case 403:
|
66 |
+
$text = 'Forbidden';
|
67 |
+
break;
|
68 |
+
case 404:
|
69 |
+
$text = 'Not Found';
|
70 |
+
break;
|
71 |
+
case 405:
|
72 |
+
$text = 'Method Not Allowed';
|
73 |
+
break;
|
74 |
+
case 406:
|
75 |
+
$text = 'Not Acceptable';
|
76 |
+
break;
|
77 |
+
case 407:
|
78 |
+
$text = 'Proxy Authentication Required';
|
79 |
+
break;
|
80 |
+
case 408:
|
81 |
+
$text = 'Request Time-out';
|
82 |
+
break;
|
83 |
+
case 409:
|
84 |
+
$text = 'Conflict';
|
85 |
+
break;
|
86 |
+
case 410:
|
87 |
+
$text = 'Gone';
|
88 |
+
break;
|
89 |
+
case 411:
|
90 |
+
$text = 'Length Required';
|
91 |
+
break;
|
92 |
+
case 412:
|
93 |
+
$text = 'Precondition Failed';
|
94 |
+
break;
|
95 |
+
case 413:
|
96 |
+
$text = 'Request Entity Too Large';
|
97 |
+
break;
|
98 |
+
case 414:
|
99 |
+
$text = 'Request-URI Too Large';
|
100 |
+
break;
|
101 |
+
case 415:
|
102 |
+
$text = 'Unsupported Media Type';
|
103 |
+
break;
|
104 |
+
case 500:
|
105 |
+
$text = 'Internal Server Error';
|
106 |
+
break;
|
107 |
+
case 501:
|
108 |
+
$text = 'Not Implemented';
|
109 |
+
break;
|
110 |
+
case 502:
|
111 |
+
$text = 'Bad Gateway';
|
112 |
+
break;
|
113 |
+
case 503:
|
114 |
+
$text = 'Service Unavailable';
|
115 |
+
break;
|
116 |
+
case 504:
|
117 |
+
$text = 'Gateway Time-out';
|
118 |
+
break;
|
119 |
+
case 505:
|
120 |
+
$text = 'HTTP Version not supported';
|
121 |
+
break;
|
122 |
+
default:
|
123 |
+
exit('Unknown http status code "' . htmlentities($code) . '"');
|
124 |
+
break;
|
125 |
+
}
|
126 |
|
127 |
+
$protocol = (isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1');
|
128 |
|
129 |
+
header($protocol . ' ' . $code . ' ' . $text);
|
130 |
|
131 |
+
$GLOBALS['http_response_code'] = $code;
|
132 |
+
} else {
|
133 |
+
$code = (isset($GLOBALS['http_response_code']) ? $GLOBALS['http_response_code'] : 200);
|
134 |
+
}
|
135 |
|
136 |
+
return $code;
|
137 |
}
|
|
|
|
|
|
|
|
|
138 |
}
|
139 |
|
140 |
// taken from: http://php.net/manual/en/function.getallheaders.php
|
141 |
+
if (!function_exists('getallheaders')) {
|
|
|
142 |
function getallheaders()
|
143 |
{
|
144 |
+
$headers = '';
|
145 |
+
foreach ($_SERVER as $name => $value) {
|
146 |
+
if (substr($name, 0, 5) == 'HTTP_') {
|
147 |
+
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
|
148 |
+
}
|
149 |
+
}
|
150 |
+
return $headers;
|
|
|
|
|
151 |
}
|
152 |
}
|
|
|
|
UBConfig.php
CHANGED
@@ -1,400 +1,411 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
class UBConfig
|
|
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
|
10 |
// Option keys
|
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 |
-
public static function default_page_server_domain() {
|
50 |
-
$domain = getenv('UB_PAGE_SERVER_DOMAIN');
|
51 |
-
return $domain ? $domain : 'wp.unbounce.com';
|
52 |
-
}
|
53 |
-
|
54 |
-
public static function default_remote_log_url() {
|
55 |
-
$url = getenv('UB_REMOTE_LOG_URL');
|
56 |
-
if ($url == null) {
|
57 |
-
return 'https://events-gateway.unbounce.com/events/wordpress_logs';
|
58 |
}
|
59 |
-
return $url;
|
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 |
'failure_message' => $failure_message),
|
140 |
null, null, null);
|
141 |
-
}
|
142 |
-
|
143 |
-
public static function domain() {
|
144 |
-
return parse_url(get_home_url(), PHP_URL_HOST);
|
145 |
-
}
|
146 |
-
|
147 |
-
public static function domain_with_port() {
|
148 |
-
$port = parse_url(get_home_url(), PHP_URL_PORT);
|
149 |
-
$host = parse_url(get_home_url(), PHP_URL_HOST);
|
150 |
-
if ($port) {
|
151 |
-
return $host . ':' . $port;
|
152 |
-
} else {
|
153 |
-
return $host;
|
154 |
}
|
155 |
-
}
|
156 |
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
UBLogger::warning($failure_message);
|
161 |
-
return UBConfig::create_failure_response($failure_message);
|
162 |
}
|
163 |
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
CURLOPT_HTTPHEADER => array('Host: ' . $domain, 'If-None-Match: ' . $etag),
|
173 |
-
CURLOPT_RETURNTRANSFER => true,
|
174 |
-
CURLOPT_FOLLOWLOCATION => false,
|
175 |
-
CURLOPT_TIMEOUT => 5
|
176 |
-
);
|
177 |
-
|
178 |
-
UBLogger::debug("Retrieving routes from '$url', etag: '$etag', host: '$domain'");
|
179 |
-
|
180 |
-
curl_setopt_array($curl, $curl_options);
|
181 |
-
$data = curl_exec($curl);
|
182 |
-
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
183 |
-
$header_size = strlen($data) - curl_getinfo($curl, CURLINFO_SIZE_DOWNLOAD);
|
184 |
-
$curl_error = null;
|
185 |
-
$etag = null;
|
186 |
-
$max_age = null;
|
187 |
-
|
188 |
-
// when having an CURL error, http_code is 0
|
189 |
-
if ($http_code == 0) {
|
190 |
-
$curl_error = curl_error($curl);
|
191 |
-
}
|
192 |
-
|
193 |
-
curl_close($curl);
|
194 |
-
|
195 |
-
$headers = substr($data, 0, $header_size);
|
196 |
-
|
197 |
-
$matches = array();
|
198 |
-
$does_match = preg_match('/ETag: (\S+)/is', $headers, $matches);
|
199 |
-
if ($does_match) {
|
200 |
-
$etag = $matches[1];
|
201 |
-
}
|
202 |
-
|
203 |
-
$matches = array();
|
204 |
-
$does_match = preg_match('/Cache-Control: max-age=(\S+)/is', $headers, $matches);
|
205 |
-
if ($does_match) {
|
206 |
-
$max_age = $matches[1];
|
207 |
-
}
|
208 |
-
|
209 |
-
if ($http_code == 200) {
|
210 |
-
$body = substr($data, $header_size);
|
211 |
-
list($success, $result) = UBConfig::url_list_from_sitemap($body);
|
212 |
-
|
213 |
-
if ($success) {
|
214 |
-
UBLogger::debug("Retrieved new routes, HTTP code: '$http_code'");
|
215 |
-
return UBConfig::create_new_response($etag, $max_age, $result);
|
216 |
}
|
217 |
-
else {
|
218 |
-
$errors = join(', ', $result);
|
219 |
-
$failure_message = "An error occurred while processing pages, XML errors: '$errors'";
|
220 |
-
UBLogger::warning($failure_message);
|
221 |
-
return UBConfig::create_failure_response($failure_message);
|
222 |
-
}
|
223 |
-
}
|
224 |
-
if ($http_code == 304) {
|
225 |
-
UBLogger::debug("Routes have not changed, HTTP code: '$http_code'");
|
226 |
-
return UBConfig::create_same_response($etag, $max_age);
|
227 |
-
}
|
228 |
-
if ($http_code == 404) {
|
229 |
-
UBLogger::debug("No routes to retrieve, HTTP code: '$http_code'");
|
230 |
-
return UBConfig::create_none_response();
|
231 |
-
}
|
232 |
-
else {
|
233 |
-
$failure_message = "An error occurred while retrieving routes; HTTP code: '$http_code'; Error: " . $curl_error;
|
234 |
-
UBLogger::warning($failure_message);
|
235 |
-
return UBConfig::create_failure_response($failure_message);
|
236 |
-
}
|
237 |
-
|
238 |
-
} catch (Exception $e) {
|
239 |
-
$failure_message = "An error occurred while retrieving routes; Error: " . $e;
|
240 |
-
UBLogger::warning($failure_message);
|
241 |
-
return UBConfig::create_failure_response($failure_message);
|
242 |
}
|
243 |
-
}
|
244 |
|
245 |
-
|
246 |
-
|
247 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
248 |
}
|
249 |
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
libxml_use_internal_errors($use_internal_errors);
|
255 |
-
$urls = array();
|
256 |
-
|
257 |
-
// Valid XML that is not a valid sitemap.xml will be considered an empty sitemap.xml.
|
258 |
-
// We have no easy way to tell the difference between the two.
|
259 |
-
if (isset($sitemap->url)) {
|
260 |
-
foreach ($sitemap->url as $sitemap_url) {
|
261 |
-
if (isset($sitemap_url->loc)) {
|
262 |
-
$url = (string) $sitemap_url->loc;
|
263 |
-
// URLs come in with protocol and trailing slash, we need just host and path with no
|
264 |
-
// trailing slash internally.
|
265 |
-
$urls[] = parse_url($url, PHP_URL_HOST) . rtrim(parse_url($url, PHP_URL_PATH), '/');
|
266 |
-
}
|
267 |
}
|
268 |
-
}
|
269 |
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
281 |
}
|
282 |
-
}
|
283 |
-
|
284 |
-
public static function _read_unbounce_domain_info($options_getter,
|
285 |
-
$options_setter,
|
286 |
-
$fetch_proxyable_url_set,
|
287 |
-
$domain,
|
288 |
-
$expire_now=false) {
|
289 |
-
|
290 |
-
$proxyable_url_set = null;
|
291 |
-
|
292 |
-
$cache_max_time_default = 10;
|
293 |
-
|
294 |
-
$ps_domain = $options_getter(UBConfig::UB_PAGE_SERVER_DOMAIN_KEY, UBConfig::default_page_server_domain());
|
295 |
-
$domains_info = $options_getter(UBConfig::UB_ROUTES_CACHE_KEY);
|
296 |
-
$domain_info = UBUtil::array_fetch($domains_info, $domain, array());
|
297 |
-
|
298 |
-
$proxyable_url_set = UBUtil::array_fetch($domain_info, 'proxyable_url_set');
|
299 |
-
$proxyable_url_set_fetched_at = UBUtil::array_fetch($domain_info, 'proxyable_url_set_fetched_at');
|
300 |
-
$proxyable_url_set_cache_timeout = UBUtil::array_fetch($domain_info, 'proxyable_url_set_cache_timeout');
|
301 |
-
$proxyable_url_set_etag = UBUtil::array_fetch($domain_info, 'proxyable_url_set_etag');
|
302 |
-
|
303 |
-
$cache_max_time = is_null($proxyable_url_set_cache_timeout) ? $cache_max_time_default : $proxyable_url_set_cache_timeout;
|
304 |
-
|
305 |
-
$current_time = time();
|
306 |
-
|
307 |
-
if ($expire_now ||
|
308 |
-
is_null($proxyable_url_set) ||
|
309 |
-
($current_time - $proxyable_url_set_fetched_at > $cache_max_time)) {
|
310 |
-
|
311 |
-
try {
|
312 |
-
|
313 |
-
$can_fetch = UBUtil::get_lock();
|
314 |
-
UBLogger::debug('Locking: ' . $can_fetch);
|
315 |
-
|
316 |
-
if ($can_fetch) {
|
317 |
-
|
318 |
-
$result_array = call_user_func($fetch_proxyable_url_set,
|
319 |
-
$domain,
|
320 |
-
$proxyable_url_set_etag,
|
321 |
-
$ps_domain);
|
322 |
-
|
323 |
-
list($routes_status, $etag, $max_age, $proxyable_url_set_new) = $result_array;
|
324 |
-
|
325 |
-
if ($routes_status['status'] == 'NEW') {
|
326 |
-
$domain_info['proxyable_url_set'] = $proxyable_url_set_new;
|
327 |
-
$domain_info['proxyable_url_set_etag'] = $etag;
|
328 |
-
$domain_info['proxyable_url_set_cache_timeout'] = $max_age;
|
329 |
-
}
|
330 |
-
elseif ($routes_status['status'] == 'SAME') {
|
331 |
-
// Just extend the cache
|
332 |
-
$domain_info['proxyable_url_set_cache_timeout'] = $max_age;
|
333 |
-
}
|
334 |
-
elseif ($routes_status['status'] == 'NONE') {
|
335 |
-
$domain_info['proxyable_url_set'] = array();
|
336 |
-
$domain_info['proxyable_url_set_etag'] = null;
|
337 |
-
}
|
338 |
-
elseif ($routes_status['status'] == 'FAILURE') {
|
339 |
-
UBLogger::warning('Route fetching failed');
|
340 |
-
}
|
341 |
-
else {
|
342 |
-
UBLogger::warning("Unknown response from route fetcher: '$routes_status'");
|
343 |
-
}
|
344 |
-
|
345 |
-
// Creation of domain_info entry
|
346 |
-
$domain_info['proxyable_url_set_fetched_at'] = $current_time;
|
347 |
-
$domain_info['last_status'] = $routes_status['status'];
|
348 |
-
if ($routes_status['status'] == 'FAILURE') {
|
349 |
-
$domain_info['failure_message'] = $routes_status['failure_message'];
|
350 |
-
}
|
351 |
-
$domains_info[$domain] = $domain_info;
|
352 |
-
// set autoload to false so that options are always loaded from DB
|
353 |
-
$options_setter(UBConfig::UB_ROUTES_CACHE_KEY, $domains_info, false);
|
354 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
355 |
}
|
356 |
-
}
|
357 |
-
catch (Exception $e) {
|
358 |
-
UBLogger::warning('Could not update sitemap: ' . $e);
|
359 |
-
}
|
360 |
|
361 |
-
|
362 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
363 |
}
|
364 |
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
return UBConfig::_read_unbounce_domain_info(
|
374 |
-
'get_option',
|
375 |
-
'update_option',
|
376 |
-
'UBConfig::fetch_proxyable_url_set',
|
377 |
-
$domain,
|
378 |
-
$expire_now);
|
379 |
-
}
|
380 |
-
|
381 |
-
public static function is_authorized_domain($domain0) {
|
382 |
-
$pieces = explode(':', $domain0);
|
383 |
-
$domain = $pieces[0];
|
384 |
-
return in_array($domain, UBConfig::authorized_domains());
|
385 |
-
}
|
386 |
-
|
387 |
-
public static function update_authorization_options($domains, $data) {
|
388 |
-
update_option(UBConfig::UB_USER_ID_KEY, $data['user_id']);
|
389 |
-
update_option(UBConfig::UB_DOMAIN_ID_KEY, $data['domain_id']);
|
390 |
-
update_option(UBConfig::UB_CLIENT_ID_KEY, $data['client_id']);
|
391 |
-
update_option(UBConfig::UB_AUTHORIZED_DOMAINS_KEY, $domains);
|
392 |
-
update_option(UBConfig::UB_HAS_AUTHORIZED_KEY, true);
|
393 |
-
}
|
394 |
-
|
395 |
-
public static function int_min() {
|
396 |
-
return (PHP_INT_MAX * -1) - 1;
|
397 |
-
}
|
398 |
|
|
|
|
|
|
|
|
|
399 |
}
|
400 |
-
?>
|
1 |
<?php
|
2 |
|
3 |
+
class UBConfig
|
4 |
+
{
|
5 |
|
6 |
+
const UB_PLUGIN_NAME = 'ub-wordpress';
|
7 |
+
const UB_CACHE_TIMEOUT_ENV_KEY = 'UB_WP_ROUTES_CACHE_EXP';
|
8 |
+
const UB_USER_AGENT = 'Unbounce WP Plugin 1.0.32';
|
9 |
+
const UB_VERSION = '1.0.32';
|
10 |
|
11 |
// Option keys
|
12 |
+
const UB_ROUTES_CACHE_KEY = 'ub-route-cache';
|
13 |
+
const UB_REMOTE_DEBUG_KEY = 'ub-remote-debug';
|
14 |
+
const UB_PAGE_SERVER_DOMAIN_KEY = 'ub-page-server-domain';
|
15 |
+
const UB_REMOTE_LOG_URL_KEY = 'ub-remote-log-url';
|
16 |
+
const UB_REMOTE_EVENTS_URL_KEY = 'ub-remote-events-url';
|
17 |
+
const UB_API_URL_KEY = 'ub-api-url';
|
18 |
+
const UB_API_CLIENT_ID_KEY = 'ub-api-client-id';
|
19 |
+
const UB_AUTHORIZED_DOMAINS_KEY = 'ub-authorized-domains';
|
20 |
+
const UB_HAS_AUTHORIZED_KEY = 'ub-has-authorized';
|
21 |
+
const UB_USER_ID_KEY = 'ub-user-id';
|
22 |
+
const UB_DOMAIN_ID_KEY = 'ub-domain-id';
|
23 |
+
const UB_CLIENT_ID_KEY = 'ub-client-id';
|
24 |
+
const UB_PROXY_ERROR_MESSAGE_KEY = 'ub-proxy-error-message';
|
25 |
+
const UB_ALLOW_PUBLIC_ADDRESS_X_FORWARDED_FOR = 'ub-allow-public-address-x-forwarded-for';
|
26 |
+
|
27 |
+
const UB_LOCK_NAME = 'ub-sql-lock';
|
28 |
+
|
29 |
+
public static function ub_option_keys()
|
30 |
+
{
|
31 |
+
// All options, used by UBDiagnostics and deactivation hook
|
32 |
+
// Arrays are not allowed in class constants, so use a function
|
33 |
+
return array(
|
34 |
+
UBConfig::UB_ROUTES_CACHE_KEY,
|
35 |
+
UBConfig::UB_REMOTE_DEBUG_KEY,
|
36 |
+
UBConfig::UB_PAGE_SERVER_DOMAIN_KEY,
|
37 |
+
UBConfig::UB_REMOTE_LOG_URL_KEY,
|
38 |
+
UBConfig::UB_REMOTE_EVENTS_URL_KEY,
|
39 |
+
UBConfig::UB_API_URL_KEY,
|
40 |
+
UBConfig::UB_API_CLIENT_ID_KEY,
|
41 |
+
UBConfig::UB_AUTHORIZED_DOMAINS_KEY,
|
42 |
+
UBConfig::UB_HAS_AUTHORIZED_KEY,
|
43 |
+
UBConfig::UB_USER_ID_KEY,
|
44 |
+
UBConfig::UB_DOMAIN_ID_KEY,
|
45 |
+
UBConfig::UB_CLIENT_ID_KEY,
|
46 |
+
UBConfig::UB_PROXY_ERROR_MESSAGE_KEY,
|
47 |
+
UBConfig::UB_ALLOW_PUBLIC_ADDRESS_X_FORWARDED_FOR
|
48 |
+
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
}
|
|
|
|
|
50 |
|
51 |
+
public static function default_page_server_domain()
|
52 |
+
{
|
53 |
+
$domain = getenv('UB_PAGE_SERVER_DOMAIN');
|
54 |
+
return $domain ? $domain : 'wp.unbounce.com';
|
55 |
}
|
56 |
+
|
57 |
+
public static function default_remote_log_url()
|
58 |
+
{
|
59 |
+
$url = getenv('UB_REMOTE_LOG_URL');
|
60 |
+
if ($url == null) {
|
61 |
+
return 'https://events-gateway.unbounce.com/events/wordpress_logs';
|
62 |
+
}
|
63 |
+
return $url;
|
64 |
+
}
|
65 |
+
|
66 |
+
public static function default_remote_events_url()
|
67 |
+
{
|
68 |
+
$url = getenv('UB_REMOTE_EVENTS_URL');
|
69 |
+
if ($url == null) {
|
70 |
+
return 'https://events-gateway.unbounce.com/events/domains';
|
71 |
+
}
|
72 |
+
return $url;
|
73 |
+
}
|
74 |
+
|
75 |
+
public static function default_api_url()
|
76 |
+
{
|
77 |
+
$url = getenv('UB_API_URL');
|
78 |
+
return $url ? $url : 'https://api.unbounce.com';
|
79 |
+
}
|
80 |
+
|
81 |
+
public static function default_api_client_id()
|
82 |
+
{
|
83 |
+
$client_id = getenv('UB_API_CLIENT_ID');
|
84 |
+
return $client_id ? $client_id : '660a311881321b9d4e777993e50875dec5da9cc4ef44369d121544b21da52b92';
|
85 |
+
}
|
86 |
+
|
87 |
+
public static function default_authorized_domains()
|
88 |
+
{
|
89 |
+
$domains = getenv('UB_AUTHORIZED_DOMAINS');
|
90 |
+
return $domains ? explode(',', $domains) : array();
|
91 |
+
}
|
92 |
+
|
93 |
+
public static function page_server_domain()
|
94 |
+
{
|
95 |
+
return get_option(UBConfig::UB_PAGE_SERVER_DOMAIN_KEY, UBConfig::default_page_server_domain());
|
96 |
+
}
|
97 |
+
|
98 |
+
public static function remote_log_url()
|
99 |
+
{
|
100 |
+
return get_option(UBConfig::UB_REMOTE_LOG_URL_KEY, UBConfig::default_remote_log_url());
|
101 |
+
}
|
102 |
+
|
103 |
+
public static function remote_events_url()
|
104 |
+
{
|
105 |
+
return get_option(UBConfig::UB_REMOTE_EVENTS_URL_KEY, UBConfig::default_remote_events_url());
|
106 |
+
}
|
107 |
+
|
108 |
+
public static function api_url()
|
109 |
+
{
|
110 |
+
return get_option(UBConfig::UB_API_URL_KEY, UBConfig::default_api_url());
|
111 |
+
}
|
112 |
+
|
113 |
+
public static function api_client_id()
|
114 |
+
{
|
115 |
+
return get_option(UBConfig::UB_API_CLIENT_ID_KEY, UBConfig::default_api_client_id());
|
116 |
+
}
|
117 |
+
|
118 |
+
public static function authorized_domains()
|
119 |
+
{
|
120 |
+
return get_option(UBConfig::UB_AUTHORIZED_DOMAINS_KEY, UBConfig::default_authorized_domains());
|
121 |
+
}
|
122 |
+
|
123 |
+
public static function has_authorized()
|
124 |
+
{
|
125 |
+
return (bool) get_option(UBConfig::UB_HAS_AUTHORIZED_KEY);
|
126 |
+
}
|
127 |
+
|
128 |
+
public static function debug_loggging_enabled()
|
129 |
+
{
|
130 |
+
return (defined('UB_ENABLE_LOCAL_LOGGING') && UB_ENABLE_LOCAL_LOGGING) || self::remote_debug_logging_enabled();
|
131 |
+
}
|
132 |
+
|
133 |
+
public static function remote_debug_logging_enabled()
|
134 |
+
{
|
135 |
+
return get_option(UBConfig::UB_REMOTE_DEBUG_KEY, 0) == 1;
|
136 |
+
}
|
137 |
+
|
138 |
+
public static function allow_public_address_x_forwarded_for()
|
139 |
+
{
|
140 |
+
return get_option(UBConfig::UB_ALLOW_PUBLIC_ADDRESS_X_FORWARDED_FOR, 0) == 1;
|
141 |
+
}
|
142 |
+
|
143 |
+
public static function create_none_response()
|
144 |
+
{
|
145 |
+
return array(array('status' => 'NONE'), null, null, null);
|
146 |
+
}
|
147 |
+
|
148 |
+
public static function create_same_response($etag, $max_age)
|
149 |
+
{
|
150 |
+
return array(array('status' => 'SAME'), $etag, $max_age, null);
|
151 |
+
}
|
152 |
+
|
153 |
+
public static function create_new_response($etag, $max_age, $proxyable_url_set)
|
154 |
+
{
|
155 |
+
return array(array('status' => 'NEW'), $etag, $max_age, $proxyable_url_set);
|
156 |
+
}
|
157 |
+
|
158 |
+
public static function create_failure_response($failure_message)
|
159 |
+
{
|
160 |
+
return array(array('status' => 'FAILURE',
|
161 |
'failure_message' => $failure_message),
|
162 |
null, null, null);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
}
|
|
|
164 |
|
165 |
+
public static function domain()
|
166 |
+
{
|
167 |
+
return parse_url(get_home_url(), PHP_URL_HOST);
|
|
|
|
|
168 |
}
|
169 |
|
170 |
+
public static function domain_with_port()
|
171 |
+
{
|
172 |
+
$port = parse_url(get_home_url(), PHP_URL_PORT);
|
173 |
+
$host = parse_url(get_home_url(), PHP_URL_HOST);
|
174 |
+
if ($port) {
|
175 |
+
return $host . ':' . $port;
|
176 |
+
} else {
|
177 |
+
return $host;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
178 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
179 |
}
|
|
|
180 |
|
181 |
+
public static function fetch_proxyable_url_set($domain, $etag, $ps_domain)
|
182 |
+
{
|
183 |
+
if (!$domain) {
|
184 |
+
$failure_message = 'Domain not provided, not fetching sitemap.xml';
|
185 |
+
UBLogger::warning($failure_message);
|
186 |
+
return UBConfig::create_failure_response($failure_message);
|
187 |
+
}
|
188 |
+
|
189 |
+
try {
|
190 |
+
$url = 'https://' . $ps_domain . '/sitemap.xml';
|
191 |
+
$curl = curl_init();
|
192 |
+
$curl_options = array(
|
193 |
+
CURLOPT_URL => $url,
|
194 |
+
CURLOPT_CUSTOMREQUEST => "GET",
|
195 |
+
CURLOPT_HEADER => true,
|
196 |
+
CURLOPT_USERAGENT => UBConfig::UB_USER_AGENT,
|
197 |
+
CURLOPT_HTTPHEADER => array('Host: ' . $domain, 'If-None-Match: ' . $etag),
|
198 |
+
CURLOPT_RETURNTRANSFER => true,
|
199 |
+
CURLOPT_FOLLOWLOCATION => false,
|
200 |
+
CURLOPT_TIMEOUT => 5
|
201 |
+
);
|
202 |
+
|
203 |
+
UBLogger::debug("Retrieving routes from '$url', etag: '$etag', host: '$domain'");
|
204 |
+
|
205 |
+
curl_setopt_array($curl, $curl_options);
|
206 |
+
$data = curl_exec($curl);
|
207 |
+
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
208 |
+
$header_size = strlen($data) - curl_getinfo($curl, CURLINFO_SIZE_DOWNLOAD);
|
209 |
+
$curl_error = null;
|
210 |
+
$etag = null;
|
211 |
+
$max_age = null;
|
212 |
+
|
213 |
+
// when having an CURL error, http_code is 0
|
214 |
+
if ($http_code == 0) {
|
215 |
+
$curl_error = curl_error($curl);
|
216 |
+
}
|
217 |
+
|
218 |
+
curl_close($curl);
|
219 |
+
|
220 |
+
$headers = substr($data, 0, $header_size);
|
221 |
+
|
222 |
+
$matches = array();
|
223 |
+
$does_match = preg_match('/ETag: (\S+)/is', $headers, $matches);
|
224 |
+
if ($does_match) {
|
225 |
+
$etag = $matches[1];
|
226 |
+
}
|
227 |
+
|
228 |
+
$matches = array();
|
229 |
+
$does_match = preg_match('/Cache-Control: max-age=(\S+)/is', $headers, $matches);
|
230 |
+
if ($does_match) {
|
231 |
+
$max_age = $matches[1];
|
232 |
+
}
|
233 |
+
|
234 |
+
if ($http_code == 200) {
|
235 |
+
$body = substr($data, $header_size);
|
236 |
+
list($success, $result) = UBConfig::url_list_from_sitemap($body);
|
237 |
+
|
238 |
+
if ($success) {
|
239 |
+
UBLogger::debug("Retrieved new routes, HTTP code: '$http_code'");
|
240 |
+
return UBConfig::create_new_response($etag, $max_age, $result);
|
241 |
+
} else {
|
242 |
+
$errors = join(', ', $result);
|
243 |
+
$failure_message = "An error occurred while processing pages, XML errors: '$errors'";
|
244 |
+
UBLogger::warning($failure_message);
|
245 |
+
return UBConfig::create_failure_response($failure_message);
|
246 |
+
}
|
247 |
+
}
|
248 |
+
if ($http_code == 304) {
|
249 |
+
UBLogger::debug("Routes have not changed, HTTP code: '$http_code'");
|
250 |
+
return UBConfig::create_same_response($etag, $max_age);
|
251 |
+
}
|
252 |
+
if ($http_code == 404) {
|
253 |
+
UBLogger::debug("No routes to retrieve, HTTP code: '$http_code'");
|
254 |
+
return UBConfig::create_none_response();
|
255 |
+
} else {
|
256 |
+
$failure_message = "An error occurred while retrieving routes;
|
257 |
+
HTTP code: '$http_code';
|
258 |
+
Error: " . $curl_error;
|
259 |
+
UBLogger::warning($failure_message);
|
260 |
+
return UBConfig::create_failure_response($failure_message);
|
261 |
+
}
|
262 |
+
} catch (Exception $e) {
|
263 |
+
$failure_message = "An error occurred while retrieving routes; Error: " . $e;
|
264 |
+
UBLogger::warning($failure_message);
|
265 |
+
return UBConfig::create_failure_response($failure_message);
|
266 |
+
}
|
267 |
}
|
268 |
|
269 |
+
public static function url_list_from_sitemap($string)
|
270 |
+
{
|
271 |
+
if (is_null($string)) {
|
272 |
+
return array(false, array('input is null'));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
273 |
}
|
|
|
274 |
|
275 |
+
$use_internal_errors = libxml_use_internal_errors(true);
|
276 |
+
$sitemap = simplexml_load_string($string);
|
277 |
+
|
278 |
+
if ($sitemap !== false) {
|
279 |
+
libxml_use_internal_errors($use_internal_errors);
|
280 |
+
$urls = array();
|
281 |
+
|
282 |
+
// Valid XML that is not a valid sitemap.xml will be considered an empty sitemap.xml.
|
283 |
+
// We have no easy way to tell the difference between the two.
|
284 |
+
if (isset($sitemap->url)) {
|
285 |
+
foreach ($sitemap->url as $sitemap_url) {
|
286 |
+
if (isset($sitemap_url->loc)) {
|
287 |
+
$url = (string) $sitemap_url->loc;
|
288 |
+
// URLs come in with protocol and trailing slash, we need just host and path with no
|
289 |
+
// trailing slash internally.
|
290 |
+
$urls[] = parse_url($url, PHP_URL_HOST) . rtrim(parse_url($url, PHP_URL_PATH), '/');
|
291 |
+
}
|
292 |
+
}
|
293 |
+
}
|
294 |
+
|
295 |
+
return array(true, $urls);
|
296 |
+
} else {
|
297 |
+
// libXMLError has no default tostring, use print_r to get a string representation of it
|
298 |
+
$errors = array_map(function ($error) {
|
299 |
+
return print_r($error, true);
|
300 |
+
}, libxml_get_errors());
|
301 |
+
// Return what we tried to parse for debugging
|
302 |
+
$errors[] = "XML content: ${string}";
|
303 |
+
libxml_use_internal_errors($use_internal_errors);
|
304 |
+
return array(false, $errors);
|
305 |
+
}
|
306 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
307 |
|
308 |
+
public static function read_unbounce_domain_info($domain, $expire_now = false)
|
309 |
+
{
|
310 |
+
// Bail out if curl is not installed to prevent fatal error
|
311 |
+
if (!UBDiagnostics::is_curl_installed()) {
|
312 |
+
return array();
|
313 |
+
}
|
314 |
+
|
315 |
+
$proxyable_url_set = null;
|
316 |
+
$cache_max_time_default = 10;
|
317 |
+
|
318 |
+
$ps_domain = get_option(UBConfig::UB_PAGE_SERVER_DOMAIN_KEY, UBConfig::default_page_server_domain());
|
319 |
+
$domains_info = get_option(UBConfig::UB_ROUTES_CACHE_KEY, array());
|
320 |
+
|
321 |
+
if (!is_array($domains_info)) {
|
322 |
+
// This is a regression from BEE-878. We aren't sure why the data could be corrupted.
|
323 |
+
$domains_info = array();
|
324 |
}
|
|
|
|
|
|
|
|
|
325 |
|
326 |
+
$domain_info = UBUtil::array_fetch($domains_info, $domain, array());
|
327 |
+
|
328 |
+
$proxyable_url_set = UBUtil::array_fetch($domain_info, 'proxyable_url_set');
|
329 |
+
$proxyable_url_set_fetched_at = UBUtil::array_fetch($domain_info, 'proxyable_url_set_fetched_at');
|
330 |
+
$proxyable_url_set_cache_timeout = UBUtil::array_fetch($domain_info, 'proxyable_url_set_cache_timeout');
|
331 |
+
$proxyable_url_set_etag = UBUtil::array_fetch($domain_info, 'proxyable_url_set_etag');
|
332 |
+
|
333 |
+
$cache_max_time = is_null($proxyable_url_set_cache_timeout) ?
|
334 |
+
$cache_max_time_default :
|
335 |
+
$proxyable_url_set_cache_timeout;
|
336 |
+
|
337 |
+
$current_time = time();
|
338 |
+
|
339 |
+
if ($expire_now ||
|
340 |
+
is_null($proxyable_url_set) ||
|
341 |
+
($current_time - $proxyable_url_set_fetched_at > $cache_max_time)) {
|
342 |
+
try {
|
343 |
+
$can_fetch = UBUtil::get_lock();
|
344 |
+
UBLogger::debug('Locking: ' . $can_fetch);
|
345 |
+
|
346 |
+
if ($can_fetch) {
|
347 |
+
$result_array = UBConfig::fetch_proxyable_url_set($domain, $proxyable_url_set_etag, $ps_domain);
|
348 |
+
|
349 |
+
list($routes_status, $etag, $max_age, $proxyable_url_set_new) = $result_array;
|
350 |
+
|
351 |
+
if ($routes_status['status'] == 'NEW') {
|
352 |
+
$domain_info['proxyable_url_set'] = $proxyable_url_set_new;
|
353 |
+
$domain_info['proxyable_url_set_etag'] = $etag;
|
354 |
+
$domain_info['proxyable_url_set_cache_timeout'] = $max_age;
|
355 |
+
} elseif ($routes_status['status'] == 'SAME') {
|
356 |
+
// Just extend the cache
|
357 |
+
$domain_info['proxyable_url_set_cache_timeout'] = $max_age;
|
358 |
+
} elseif ($routes_status['status'] == 'NONE') {
|
359 |
+
$domain_info['proxyable_url_set'] = array();
|
360 |
+
$domain_info['proxyable_url_set_etag'] = null;
|
361 |
+
} elseif ($routes_status['status'] == 'FAILURE') {
|
362 |
+
UBLogger::warning('Route fetching failed');
|
363 |
+
} else {
|
364 |
+
UBLogger::warning("Unknown response from route fetcher: '$routes_status'");
|
365 |
+
}
|
366 |
+
|
367 |
+
// Creation of domain_info entry
|
368 |
+
$domain_info['proxyable_url_set_fetched_at'] = $current_time;
|
369 |
+
$domain_info['last_status'] = $routes_status['status'];
|
370 |
+
if ($routes_status['status'] == 'FAILURE') {
|
371 |
+
$domain_info['failure_message'] = $routes_status['failure_message'];
|
372 |
+
}
|
373 |
+
$domains_info[$domain] = $domain_info;
|
374 |
+
// set autoload to false so that options are always loaded from DB
|
375 |
+
update_option(UBConfig::UB_ROUTES_CACHE_KEY, $domains_info, false);
|
376 |
+
}
|
377 |
+
} catch (Exception $e) {
|
378 |
+
UBLogger::warning('Could not update sitemap: ' . $e);
|
379 |
+
}
|
380 |
+
|
381 |
+
$release_result = UBUtil::release_lock();
|
382 |
+
UBLogger::debug('Unlocking: ' . $release_result);
|
383 |
+
}
|
384 |
+
|
385 |
+
return UBUtil::array_select_by_key(
|
386 |
+
$domain_info,
|
387 |
+
array('proxyable_url_set', 'proxyable_url_set_fetched_at', 'failure_message', 'last_status')
|
388 |
+
);
|
389 |
+
}
|
390 |
+
|
391 |
+
public static function is_authorized_domain($domain0)
|
392 |
+
{
|
393 |
+
$pieces = explode(':', $domain0);
|
394 |
+
$domain = $pieces[0];
|
395 |
+
return in_array($domain, UBConfig::authorized_domains());
|
396 |
}
|
397 |
|
398 |
+
public static function update_authorization_options($domains, $data)
|
399 |
+
{
|
400 |
+
update_option(UBConfig::UB_USER_ID_KEY, $data['user_id']);
|
401 |
+
update_option(UBConfig::UB_DOMAIN_ID_KEY, $data['domain_id']);
|
402 |
+
update_option(UBConfig::UB_CLIENT_ID_KEY, $data['client_id']);
|
403 |
+
update_option(UBConfig::UB_AUTHORIZED_DOMAINS_KEY, $domains);
|
404 |
+
update_option(UBConfig::UB_HAS_AUTHORIZED_KEY, true);
|
405 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
406 |
|
407 |
+
public static function int_min()
|
408 |
+
{
|
409 |
+
return (PHP_INT_MAX * -1) - 1;
|
410 |
+
}
|
411 |
}
|
|
UBDiagnostics.php
CHANGED
@@ -1,78 +1,111 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
class UBDiagnostics
|
|
|
4 |
|
5 |
-
|
6 |
-
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
'Domain is Authorized' => UBConfig::is_authorized_domain($domain),
|
17 |
-
'Can Fetch Page Listing' => UBDiagnostics::last_status_success($domain_info),
|
18 |
-
'Supported PHP Version' => version_compare(phpversion(),
|
19 |
-
UBDiagnostics::SUPPORTED_PHP_VERSION,
|
20 |
-
'>='),
|
21 |
-
'Supported Wordpress Version' => version_compare(UBDiagnostics::wordpress_version(),
|
22 |
-
UBDiagnostics::SUPPORTED_WP_VERSION,
|
23 |
-
'>=')
|
24 |
-
);
|
25 |
-
}
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
'Plugin Details' => print_r(get_plugins(), true),
|
38 |
-
'Curl Version' => UBDiagnostics::curl_version(),
|
39 |
-
'Configuration Options' => print_r(ini_get_all(), true),
|
40 |
-
'Extensions' => print_r(get_loaded_extensions(), true),
|
41 |
-
'Operating System' => php_uname(),
|
42 |
-
'Checks' => print_r(UBDiagnostics::checks($domain, $domain_info), true),
|
43 |
-
'Options' => print_r(UBDiagnostics::ub_options(), true)
|
44 |
-
);
|
45 |
-
}
|
46 |
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
return 'N/A';
|
63 |
}
|
64 |
-
}
|
65 |
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
|
|
|
|
|
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
|
|
|
|
76 |
|
|
|
|
|
|
|
|
|
|
|
77 |
}
|
78 |
-
?>
|
1 |
<?php
|
2 |
|
3 |
+
class UBDiagnostics
|
4 |
+
{
|
5 |
|
6 |
+
const SUPPORTED_PHP_VERSION = '5.3';
|
7 |
+
const SUPPORTED_WP_VERSION = '4.0';
|
8 |
|
9 |
+
public static function checks($domain, $domain_info)
|
10 |
+
{
|
11 |
+
return array_merge(self::domain_checks($domain, $domain_info), self::system_checks());
|
12 |
+
}
|
13 |
+
|
14 |
+
public static function domain_checks($domain, $domain_info)
|
15 |
+
{
|
16 |
+
return array(
|
17 |
+
'Domain is Authorized' => UBConfig::is_authorized_domain($domain),
|
18 |
+
'Can Fetch Page Listing' => UBDiagnostics::last_status_success($domain_info),
|
19 |
+
);
|
20 |
+
}
|
21 |
+
|
22 |
+
|
23 |
+
public static function system_checks()
|
24 |
+
{
|
25 |
+
return array(
|
26 |
+
'Curl Support' => self::is_curl_installed(),
|
27 |
+
'Permalink Structure' => get_option('permalink_structure', '') !== '',
|
28 |
+
'Supported PHP Version' => version_compare(
|
29 |
+
phpversion(),
|
30 |
+
UBDiagnostics::SUPPORTED_PHP_VERSION,
|
31 |
+
'>='
|
32 |
+
),
|
33 |
+
'Supported Wordpress Version' => version_compare(
|
34 |
+
UBDiagnostics::wordpress_version(),
|
35 |
+
UBDiagnostics::SUPPORTED_WP_VERSION,
|
36 |
+
'>='
|
37 |
+
)
|
38 |
+
);
|
39 |
+
}
|
40 |
|
41 |
+
public static function is_curl_installed()
|
42 |
+
{
|
43 |
+
return function_exists('curl_init');
|
44 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
+
public static function should_show_warning($domain, $domain_info)
|
47 |
+
{
|
48 |
+
$domain_issue = in_array(false, self::domain_checks($domain, $domain_info));
|
49 |
+
$system_issue = in_array(false, self::system_checks());
|
50 |
+
if (UBConfig::has_authorized()) {
|
51 |
+
return $domain_issue || $system_issue;
|
52 |
+
} else {
|
53 |
+
return $system_issue;
|
54 |
+
}
|
55 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
+
public static function details($domain, $domain_info)
|
58 |
+
{
|
59 |
+
return array(
|
60 |
+
'PHP Version' => phpversion(),
|
61 |
+
'WordPress Version' => UBDiagnostics::wordpress_version(),
|
62 |
+
'Unbounce Plugin Version' => '1.0.32',
|
63 |
+
'Permalink Structure' => get_option('permalink_structure', ''),
|
64 |
+
'Domain' => $domain,
|
65 |
+
'Domain Authorized' => print_r(UBConfig::is_authorized_domain($domain), true),
|
66 |
+
'Has Authorized' => print_r(UBConfig::has_authorized(), true),
|
67 |
+
'Active Plugins' => print_r(get_option('active_plugins'), true),
|
68 |
+
'Plugin Details' => print_r(get_plugins(), true),
|
69 |
+
'Curl Version' => UBDiagnostics::curl_version(),
|
70 |
+
'Configuration Options' => print_r(ini_get_all(), true),
|
71 |
+
'Extensions' => print_r(get_loaded_extensions(), true),
|
72 |
+
'Operating System' => php_uname(),
|
73 |
+
'Checks' => print_r(UBDiagnostics::checks($domain, $domain_info), true),
|
74 |
+
'Options' => print_r(UBDiagnostics::ub_options(), true)
|
75 |
+
);
|
76 |
+
}
|
77 |
|
78 |
+
private static function ub_options()
|
79 |
+
{
|
80 |
+
$option_values = array_map(function ($key) {
|
81 |
+
return get_option($key);
|
82 |
+
}, UBConfig::ub_option_keys());
|
83 |
|
84 |
+
// Return an array where the key is the option key and the value
|
85 |
+
// the option value:
|
86 |
+
// array('ub-option-key' => 'option value')
|
87 |
+
return array_combine(UBConfig::ub_option_keys(), $option_values);
|
|
|
88 |
}
|
|
|
89 |
|
90 |
+
private static function curl_version()
|
91 |
+
{
|
92 |
+
if (function_exists('curl_version')) {
|
93 |
+
return print_r(curl_version(), true);
|
94 |
+
} else {
|
95 |
+
return 'N/A';
|
96 |
+
}
|
97 |
+
}
|
98 |
|
99 |
+
private static function wordpress_version()
|
100 |
+
{
|
101 |
+
global $wp_version;
|
102 |
+
include(ABSPATH . WPINC . '/version.php');
|
103 |
+
return $wp_version;
|
104 |
+
}
|
105 |
|
106 |
+
private static function last_status_success($domain_info)
|
107 |
+
{
|
108 |
+
$last_status = UBUtil::array_fetch($domain_info, 'last_status');
|
109 |
+
return $last_status !== null && $last_status !== 'FAILURE';
|
110 |
+
}
|
111 |
}
|
|
UBEvents.php
CHANGED
@@ -1,63 +1,77 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
class UBEvents
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
$event = array(
|
21 |
-
'domain_name' => $data['domain_name'],
|
22 |
-
'first_authorization' => (boolean) $data['first_authorization'],
|
23 |
-
'metadata' => array()
|
24 |
-
);
|
25 |
-
|
26 |
-
if ($data['domain_id']) {
|
27 |
-
$event['domain_id'] = UBEvents::maybe_convert_to_int($data['domain_id']);
|
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 |
-
$data);
|
53 |
-
$json_unescaped = json_encode($event);
|
54 |
-
return str_replace('\\/', '/', $json_unescaped);
|
55 |
-
}
|
56 |
-
|
57 |
-
private static function default_attributes() {
|
58 |
-
$datetime = new DateTime('NOW', new DateTimeZone('UTC'));
|
59 |
-
return array('id' => uniqid(),
|
60 |
'time_sent' => $datetime->format('Y-m-d\TH:i:s\Z'),
|
61 |
'source' => UBConfig::UB_USER_AGENT . ' ' . gethostname());
|
62 |
-
|
63 |
-
}
|
1 |
<?php
|
2 |
|
3 |
+
class UBEvents
|
4 |
+
{
|
5 |
+
|
6 |
+
public static function successful_authorization_event($data)
|
7 |
+
{
|
8 |
+
return UBEvents::event(
|
9 |
+
'WordPressSuccessfulAuthorizationEventV1.0',
|
10 |
+
UBEvents::authorization_event($data)
|
11 |
+
);
|
12 |
+
}
|
13 |
+
|
14 |
+
public static function failed_authorization_event($data)
|
15 |
+
{
|
16 |
+
return UBEvents::event(
|
17 |
+
'WordPressFailedAuthorizationEventV1.0',
|
18 |
+
UBEvents::authorization_event($data)
|
19 |
+
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
}
|
21 |
|
22 |
+
public static function log_event($data)
|
23 |
+
{
|
24 |
+
return UBEvents::event('WordpressLogV1.0', $data);
|
25 |
}
|
26 |
|
27 |
+
private static function authorization_event($data)
|
28 |
+
{
|
29 |
+
$event = array(
|
30 |
+
'domain_name' => $data['domain_name'],
|
31 |
+
'first_authorization' => (boolean) $data['first_authorization'],
|
32 |
+
'metadata' => array()
|
33 |
+
);
|
34 |
+
|
35 |
+
if ($data['domain_id']) {
|
36 |
+
$event['domain_id'] = UBEvents::maybe_convert_to_int($data['domain_id']);
|
37 |
+
}
|
38 |
+
|
39 |
+
if ($data['user_id']) {
|
40 |
+
$event['metadata']['user_id'] = UBEvents::maybe_convert_to_int($data['user_id']);
|
41 |
+
}
|
42 |
+
|
43 |
+
if ($data['client_id']) {
|
44 |
+
$event['metadata']['client_id'] = UBEvents::maybe_convert_to_int($data['client_id']);
|
45 |
+
}
|
46 |
+
|
47 |
+
return $event;
|
48 |
}
|
49 |
|
50 |
+
private static function maybe_convert_to_int($str)
|
51 |
+
{
|
52 |
+
if (is_numeric($str)) {
|
53 |
+
return intval($str);
|
54 |
+
} else {
|
55 |
+
return $str;
|
56 |
+
}
|
57 |
+
}
|
58 |
|
59 |
+
private static function event($type, $data)
|
60 |
+
{
|
61 |
+
$event = array_merge(
|
62 |
+
array('type' => $type),
|
63 |
+
UBEvents::default_attributes(),
|
64 |
+
$data
|
65 |
+
);
|
66 |
+
$json_unescaped = json_encode($event);
|
67 |
+
return str_replace('\\/', '/', $json_unescaped);
|
68 |
}
|
69 |
+
|
70 |
+
private static function default_attributes()
|
71 |
+
{
|
72 |
+
$datetime = new DateTime('NOW', new DateTimeZone('UTC'));
|
73 |
+
return array('id' => uniqid(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
'time_sent' => $datetime->format('Y-m-d\TH:i:s\Z'),
|
75 |
'source' => UBConfig::UB_USER_AGENT . ' ' . gethostname());
|
76 |
+
}
|
77 |
+
}
|
UBHTTP.php
CHANGED
@@ -1,330 +1,372 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
class UBHTTP
|
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 |
join($existing_powered_by, ', ') . ', ' .
|
48 |
$fetch_powered_by_value($header_string);
|
49 |
-
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
|
|
|
|
56 |
UBHTTP::is_private_ip_address($current_ip))) {
|
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 |
-
// We must show curl that we've processed every byte of the input header
|
82 |
-
return strlen($header_string);
|
83 |
-
};
|
84 |
-
}
|
85 |
-
|
86 |
-
public static function stream_response_function() {
|
87 |
-
return function ($curl, $string) {
|
88 |
-
// Stream the body to the client
|
89 |
-
echo $string;
|
90 |
-
|
91 |
-
// We must show curl that we've processed every byte of the input string
|
92 |
-
return strlen($string);
|
93 |
-
};
|
94 |
-
}
|
95 |
-
|
96 |
-
public static function determine_protocol($server_global, $wp_is_ssl) {
|
97 |
-
$forwarded_proto = UBUtil::array_fetch($server_global, 'HTTP_X_FORWARDED_PROTO');
|
98 |
-
$request_scheme = UBUtil::array_fetch($server_global, 'REQUEST_SCHEME');
|
99 |
-
$script_uri = UBUtil::array_fetch($server_global, 'SCRIPT_URI');
|
100 |
-
$script_uri_scheme = parse_url($script_uri, PHP_URL_SCHEME);
|
101 |
-
$https = UBUtil::array_fetch($server_global, 'HTTPS', 'off');
|
102 |
-
|
103 |
-
UBLogger::debug_var('UBHTTP::forwarded_proto', $forwarded_proto);
|
104 |
-
UBLogger::debug_var('UBHTTP::request_scheme', $request_scheme);
|
105 |
-
UBLogger::debug_var('UBHTTP::script_uri', $script_uri);
|
106 |
-
UBLogger::debug_var('UBHTTP::script_uri_scheme', $script_uri_scheme);
|
107 |
-
UBLogger::debug_var('UBHTTP::https', $https);
|
108 |
-
|
109 |
-
// X-Forwarded-Proto should be respected first, as it is what the end
|
110 |
-
// user will see (if Wordpress is behind a load balancer).
|
111 |
-
if(UBHTTP::is_valid_protocol($forwarded_proto)) {
|
112 |
-
return $forwarded_proto . '://';
|
113 |
}
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
UBLogger::debug_var('sent_headers', print_r($headers, true));
|
173 |
-
|
174 |
-
$stream_headers = UBHTTP::stream_headers_function($existing_headers);
|
175 |
-
$stream_body = UBHTTP::stream_response_function();
|
176 |
-
$curl = curl_init();
|
177 |
-
// http://php.net/manual/en/function.curl-setopt.php
|
178 |
-
$curl_options = array(
|
179 |
-
CURLOPT_URL => $target_url,
|
180 |
-
CURLOPT_POST => $method == "POST",
|
181 |
-
CURLOPT_CUSTOMREQUEST => $method,
|
182 |
-
CURLOPT_USERAGENT => $user_agent,
|
183 |
-
CURLOPT_COOKIE => $cookie_string,
|
184 |
-
CURLOPT_HTTPHEADER => $headers,
|
185 |
-
CURLOPT_HEADERFUNCTION => $stream_headers,
|
186 |
-
CURLOPT_WRITEFUNCTION => $stream_body,
|
187 |
-
CURLOPT_FOLLOWLOCATION => false,
|
188 |
-
CURLOPT_TIMEOUT => 30
|
189 |
-
);
|
190 |
-
|
191 |
-
if ($method == "POST") {
|
192 |
-
// Use raw post body to allow the same post key to occur more than once
|
193 |
-
$curl_options[CURLOPT_POSTFIELDS] = file_get_contents('php://input');
|
194 |
}
|
195 |
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
$result = array(true, null);
|
205 |
}
|
206 |
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
public static function is_lightbox($proxyable_url_set, $url_without_protocol) {
|
232 |
-
return UBHTTP::is_extract_url_proxyable($proxyable_url_set,
|
233 |
-
UBHTTP::$lightbox_url_regex,
|
234 |
-
1,
|
235 |
-
$url_without_protocol);
|
236 |
-
}
|
237 |
-
|
238 |
-
public static function is_variant($proxyable_url_set, $url_without_protocol) {
|
239 |
-
return UBHTTP::is_extract_url_proxyable($proxyable_url_set,
|
240 |
-
UBHTTP::$variant_url_regex,
|
241 |
-
1,
|
242 |
-
$url_without_protocol);
|
243 |
-
}
|
244 |
-
|
245 |
-
public static function is_tracking_link($proxyable_url_set, $url_without_protocol) {
|
246 |
-
return UBHTTP::is_extract_url_proxyable($proxyable_url_set,
|
247 |
-
"/^(.+)?\/(clkn|clkg)\/?/",
|
248 |
-
1,
|
249 |
-
$url_without_protocol);
|
250 |
-
}
|
251 |
-
|
252 |
-
public static function get_url_purpose($proxyable_url_set, $http_method, $url) {
|
253 |
-
$host = parse_url($url, PHP_URL_HOST);
|
254 |
-
$path = rtrim(parse_url($url, PHP_URL_PATH), '/');
|
255 |
-
$url_without_protocol = $host . $path;
|
256 |
-
|
257 |
-
UBLogger::debug_var('get_url_purpose $host', $host);
|
258 |
-
UBLogger::debug_var('get_url_purpose $path', $path);
|
259 |
-
UBLogger::debug_var('get_url_purpose $url_without_protocol', $url_without_protocol);
|
260 |
-
|
261 |
-
if ($http_method == 'GET' && $path == '/_ubhc') {
|
262 |
-
return 'HealthCheck';
|
263 |
-
} elseif ($http_method == "POST" &&
|
264 |
preg_match("/^\/(fsn|fsg|fs)\/?$/", $path)) {
|
265 |
-
|
266 |
-
|
267 |
UBHTTP::is_tracking_link($proxyable_url_set, $url_without_protocol)) {
|
268 |
-
|
269 |
-
|
270 |
(in_array($url_without_protocol, $proxyable_url_set) ||
|
271 |
UBHTTP::is_confirmation_dialog($proxyable_url_set, $url_without_protocol) ||
|
272 |
UBHTTP::is_lightbox($proxyable_url_set, $url_without_protocol) ||
|
273 |
UBHTTP::is_variant($proxyable_url_set, $url_without_protocol))) {
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
|
|
280 |
}
|
281 |
-
}
|
282 |
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
|
|
|
|
|
|
323 |
. ' - Error: ' . $e;
|
324 |
-
|
|
|
325 |
}
|
326 |
-
}
|
327 |
-
|
328 |
}
|
329 |
-
|
330 |
-
?>
|
1 |
<?php
|
2 |
|
3 |
+
class UBHTTP
|
4 |
+
{
|
5 |
+
public static $powered_by_header_regex = '/^X-Powered-By: (.+)$/i';
|
6 |
+
public static $form_confirmation_url_regex = '/(.+)\/[a-z]+-form_confirmation\.html/i';
|
7 |
+
public static $lightbox_url_regex = '/(.+)\/[a-z]+-[0-9]+-lightbox\.html/i';
|
8 |
+
public static $variant_url_regex = '/(.+)\/[a-z]+\.html/i';
|
9 |
+
public static $pie_htc_url = '/PIE.htc';
|
10 |
+
// Suppress Etag and Last-Modified so that browser doesn't send
|
11 |
+
// If-None-Match and If-Modified-Since header (to bypass front-end caches)
|
12 |
+
// @codingStandardsIgnoreLine
|
13 |
+
public static $response_header_whitelist = '/^(Content-Type:|Location:|Link:|Content-Location:|Set-Cookie:|X-Server-Instance:|X-Unbounce-PageId:|X-Unbounce-Variant:|X-Unbounce-VisitorID:)/i';
|
14 |
+
public static $request_header_blacklist = '/^(Accept-Encoding:)/i';
|
15 |
+
|
16 |
+
public static function is_private_ip_address($ip_address)
|
17 |
+
{
|
18 |
+
return !filter_var(
|
19 |
+
$ip_address,
|
20 |
+
FILTER_VALIDATE_IP,
|
21 |
+
FILTER_FLAG_NO_PRIV_RANGE + FILTER_FLAG_NO_RES_RANGE
|
22 |
+
);
|
23 |
+
}
|
24 |
+
|
25 |
+
public static function cookie_string_from_array($cookies)
|
26 |
+
{
|
27 |
+
$join_cookie_values = function ($k, $v) {
|
28 |
+
return $k . '=' . $v;
|
29 |
+
};
|
30 |
+
$cookie_strings = array_map(
|
31 |
+
$join_cookie_values,
|
32 |
+
array_keys($cookies),
|
33 |
+
$cookies
|
34 |
+
);
|
35 |
+
return join('; ', $cookie_strings);
|
36 |
+
}
|
37 |
+
|
38 |
+
private static function fetch_header_value_function($regex)
|
39 |
+
{
|
40 |
+
return function ($header_string) use ($regex) {
|
41 |
+
$matches = array();
|
42 |
+
preg_match(
|
43 |
+
$regex,
|
44 |
+
$header_string,
|
45 |
+
$matches
|
46 |
+
);
|
47 |
+
return $matches[1];
|
48 |
+
};
|
49 |
+
}
|
50 |
+
|
51 |
+
public static function rewrite_x_powered_by_header($header_string, $existing_headers)
|
52 |
+
{
|
53 |
+
$fetch_powered_by_value = UBHTTP::fetch_header_value_function(UBHTTP::$powered_by_header_regex);
|
54 |
+
|
55 |
+
$existing_powered_by = preg_grep(
|
56 |
+
UBHTTP::$powered_by_header_regex,
|
57 |
+
$existing_headers
|
58 |
+
);
|
59 |
+
|
60 |
+
$existing_powered_by = array_map(
|
61 |
+
$fetch_powered_by_value,
|
62 |
+
$existing_powered_by
|
63 |
+
);
|
64 |
+
|
65 |
+
return 'X-Powered-By: ' .
|
66 |
join($existing_powered_by, ', ') . ', ' .
|
67 |
$fetch_powered_by_value($header_string);
|
68 |
+
}
|
69 |
|
70 |
+
public static function get_proxied_for_header(
|
71 |
+
$out_headers,
|
72 |
+
$forwarded_for,
|
73 |
+
$current_ip
|
74 |
+
) {
|
75 |
+
if ($forwarded_for !== null &&
|
76 |
+
(UBConfig::allow_public_address_x_forwarded_for() ||
|
77 |
UBHTTP::is_private_ip_address($current_ip))) {
|
78 |
+
$proxied_for = $forwarded_for;
|
79 |
+
} else {
|
80 |
+
$proxied_for = $current_ip;
|
81 |
+
}
|
82 |
+
|
83 |
+
$out_headers[] = 'X-Proxied-For: ' . $proxied_for;
|
84 |
+
return $out_headers;
|
85 |
}
|
86 |
|
87 |
+
public static function stream_headers_function($existing_headers)
|
88 |
+
{
|
89 |
+
return function ($curl, $header_string) use ($existing_headers) {
|
90 |
+
$http_status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
91 |
+
|
92 |
+
http_response_code($http_status_code);
|
93 |
+
|
94 |
+
if (preg_match(UBHTTP::$powered_by_header_regex, $header_string) == 1) {
|
95 |
+
$result = UBHTTP::rewrite_x_powered_by_header($header_string, $existing_headers);
|
96 |
+
header($result);
|
97 |
+
} elseif (preg_match(UBHTTP::$response_header_whitelist, $header_string)) {
|
98 |
+
// false means don't replace the exsisting header
|
99 |
+
header($header_string, false);
|
100 |
+
}
|
101 |
+
|
102 |
+
// We must show curl that we've processed every byte of the input header
|
103 |
+
return strlen($header_string);
|
104 |
+
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
}
|
106 |
+
|
107 |
+
public static function stream_response_function()
|
108 |
+
{
|
109 |
+
return function ($curl, $string) {
|
110 |
+
// Stream the body to the client
|
111 |
+
echo $string;
|
112 |
+
|
113 |
+
// We must show curl that we've processed every byte of the input string
|
114 |
+
return strlen($string);
|
115 |
+
};
|
116 |
}
|
117 |
+
|
118 |
+
public static function determine_protocol($server_global, $wp_is_ssl)
|
119 |
+
{
|
120 |
+
$forwarded_proto = UBUtil::array_fetch($server_global, 'HTTP_X_FORWARDED_PROTO');
|
121 |
+
$request_scheme = UBUtil::array_fetch($server_global, 'REQUEST_SCHEME');
|
122 |
+
$script_uri = UBUtil::array_fetch($server_global, 'SCRIPT_URI');
|
123 |
+
$script_uri_scheme = parse_url($script_uri, PHP_URL_SCHEME);
|
124 |
+
$https = UBUtil::array_fetch($server_global, 'HTTPS', 'off');
|
125 |
+
|
126 |
+
UBLogger::debug_var('UBHTTP::forwarded_proto', $forwarded_proto);
|
127 |
+
UBLogger::debug_var('UBHTTP::request_scheme', $request_scheme);
|
128 |
+
UBLogger::debug_var('UBHTTP::script_uri', $script_uri);
|
129 |
+
UBLogger::debug_var('UBHTTP::script_uri_scheme', $script_uri_scheme);
|
130 |
+
UBLogger::debug_var('UBHTTP::https', $https);
|
131 |
+
|
132 |
+
// X-Forwarded-Proto should be respected first, as it is what the end
|
133 |
+
// user will see (if Wordpress is behind a load balancer).
|
134 |
+
if (UBHTTP::is_valid_protocol($forwarded_proto)) {
|
135 |
+
return $forwarded_proto . '://';
|
136 |
+
} // Wordpress' is_ssl() may return the correct boolean for http/https if
|
137 |
+
// the site was setup properly.
|
138 |
+
elseif ($wp_is_ssl || !is_null($https) && $https !== 'off') {
|
139 |
+
return 'https://';
|
140 |
+
} // Next use REQUEST_SCHEME, if it is available. This is the recommended way
|
141 |
+
// to get the protocol, but it is not available on all hosts.
|
142 |
+
elseif (UBHTTP::is_valid_protocol($request_scheme)) {
|
143 |
+
return $request_scheme . '://';
|
144 |
+
} // Next try to pull it out of the SCRIPT_URI. This is also not always available.
|
145 |
+
elseif (UBHTTP::is_valid_protocol($script_uri_scheme)) {
|
146 |
+
return $script_uri_scheme . '://';
|
147 |
+
} // We default to http as most HTTPS sites will also have HTTP available.
|
148 |
+
else {
|
149 |
+
return 'http://';
|
150 |
+
}
|
151 |
}
|
152 |
+
|
153 |
+
private static function is_valid_protocol($protocol)
|
154 |
+
{
|
155 |
+
return $protocol === 'http' || $protocol === 'https';
|
156 |
}
|
157 |
+
|
158 |
+
// taken from: http://stackoverflow.com/a/13036310/322727
|
159 |
+
private static function convert_headers_to_curl($headers)
|
160 |
+
{
|
161 |
+
// map to curl-friendly format
|
162 |
+
$req_headers = array();
|
163 |
+
array_walk($headers, function (&$v, $k) use (&$req_headers) {
|
164 |
+
array_push($req_headers, $k . ": " . $v);
|
165 |
+
});
|
166 |
+
|
167 |
+
return $req_headers;
|
168 |
}
|
|
|
169 |
|
170 |
+
public static function stream_request(
|
171 |
+
$method,
|
172 |
+
$target_url,
|
173 |
+
$cookie_string,
|
174 |
+
$headers0,
|
175 |
+
$user_agent
|
176 |
+
) {
|
177 |
+
|
178 |
+
// Always add this header to responses to show it comes from our plugin.
|
179 |
+
header("X-Unbounce-Plugin: 1", false);
|
180 |
+
|
181 |
+
$existing_headers = headers_list();
|
182 |
+
$forwarded_for = UBUtil::array_fetch($_SERVER, 'HTTP_X_FORWARDED_FOR');
|
183 |
+
$remote_ip = UBUtil::array_fetch($_SERVER, 'REMOTE_ADDR');
|
184 |
+
|
185 |
+
$headers1 = UBHTTP::convert_headers_to_curl($headers0);
|
186 |
+
$curl_headers = array_filter($headers1, function ($key) {
|
187 |
+
return !preg_match(UBHTTP::$request_header_blacklist, $key);
|
188 |
+
});
|
189 |
+
|
190 |
+
$headers = UBHTTP::get_proxied_for_header(
|
191 |
+
$curl_headers,
|
192 |
+
$forwarded_for,
|
193 |
+
$remote_ip
|
194 |
+
);
|
195 |
+
UBLogger::debug_var('target_url', $target_url);
|
196 |
+
UBLogger::debug_var('original_headers', print_r($headers0, true));
|
197 |
+
UBLogger::debug_var('sent_headers', print_r($headers, true));
|
198 |
+
|
199 |
+
$stream_headers = UBHTTP::stream_headers_function($existing_headers);
|
200 |
+
$stream_body = UBHTTP::stream_response_function();
|
201 |
+
$curl = curl_init();
|
202 |
+
// http://php.net/manual/en/function.curl-setopt.php
|
203 |
+
$curl_options = array(
|
204 |
+
CURLOPT_URL => $target_url,
|
205 |
+
CURLOPT_POST => $method == "POST",
|
206 |
+
CURLOPT_CUSTOMREQUEST => $method,
|
207 |
+
CURLOPT_USERAGENT => $user_agent,
|
208 |
+
CURLOPT_COOKIE => $cookie_string,
|
209 |
+
CURLOPT_HTTPHEADER => $headers,
|
210 |
+
CURLOPT_HEADERFUNCTION => $stream_headers,
|
211 |
+
CURLOPT_WRITEFUNCTION => $stream_body,
|
212 |
+
CURLOPT_FOLLOWLOCATION => false,
|
213 |
+
CURLOPT_TIMEOUT => 30
|
214 |
+
);
|
215 |
+
|
216 |
+
if ($method == "POST") {
|
217 |
+
// Use raw post body to allow the same post key to occur more than once
|
218 |
+
$curl_options[CURLOPT_POSTFIELDS] = file_get_contents('php://input');
|
219 |
+
}
|
220 |
+
|
221 |
+
curl_setopt_array($curl, $curl_options);
|
222 |
+
$resp = curl_exec($curl);
|
223 |
+
if (!$resp) {
|
224 |
+
$message = "Error proxying to '{$target_url}': '{curl_error($curl)}' - Code: {curl_errno($curl)}";
|
225 |
+
UBLogger::warning($message);
|
226 |
+
http_response_code(500);
|
227 |
+
$result = array(false, $message);
|
228 |
+
} else {
|
229 |
+
$result = array(true, null);
|
230 |
+
}
|
231 |
+
|
232 |
+
curl_close($curl);
|
233 |
+
|
234 |
+
return $result;
|
235 |
+
}
|
236 |
|
237 |
+
public static function is_extract_url_proxyable(
|
238 |
+
$proxyable_url_set,
|
239 |
+
$extract_regex,
|
240 |
+
$match_position,
|
241 |
+
$url
|
242 |
+
) {
|
243 |
+
$matches = array();
|
244 |
+
$does_match = preg_match(
|
245 |
+
$extract_regex,
|
246 |
+
$url,
|
247 |
+
$matches
|
248 |
+
);
|
249 |
+
|
250 |
+
return $does_match && in_array($matches[1], $proxyable_url_set);
|
251 |
+
}
|
252 |
+
|
253 |
+
public static function is_confirmation_dialog($proxyable_url_set, $url_without_protocol)
|
254 |
+
{
|
255 |
+
return UBHTTP::is_extract_url_proxyable(
|
256 |
+
$proxyable_url_set,
|
257 |
+
UBHTTP::$form_confirmation_url_regex,
|
258 |
+
1,
|
259 |
+
$url_without_protocol
|
260 |
+
);
|
261 |
+
}
|
262 |
+
|
263 |
+
public static function is_lightbox($proxyable_url_set, $url_without_protocol)
|
264 |
+
{
|
265 |
+
return UBHTTP::is_extract_url_proxyable(
|
266 |
+
$proxyable_url_set,
|
267 |
+
UBHTTP::$lightbox_url_regex,
|
268 |
+
1,
|
269 |
+
$url_without_protocol
|
270 |
+
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
271 |
}
|
272 |
|
273 |
+
public static function is_variant($proxyable_url_set, $url_without_protocol)
|
274 |
+
{
|
275 |
+
return UBHTTP::is_extract_url_proxyable(
|
276 |
+
$proxyable_url_set,
|
277 |
+
UBHTTP::$variant_url_regex,
|
278 |
+
1,
|
279 |
+
$url_without_protocol
|
280 |
+
);
|
|
|
281 |
}
|
282 |
|
283 |
+
public static function is_tracking_link($proxyable_url_set, $url_without_protocol)
|
284 |
+
{
|
285 |
+
return UBHTTP::is_extract_url_proxyable(
|
286 |
+
$proxyable_url_set,
|
287 |
+
"/^(.+)?\/(clkn|clkg)\/?/",
|
288 |
+
1,
|
289 |
+
$url_without_protocol
|
290 |
+
);
|
291 |
+
}
|
292 |
+
|
293 |
+
public static function get_url_purpose($proxyable_url_set, $http_method, $url)
|
294 |
+
{
|
295 |
+
$host = parse_url($url, PHP_URL_HOST);
|
296 |
+
$path = rtrim(parse_url($url, PHP_URL_PATH), '/');
|
297 |
+
$url_without_protocol = $host . $path;
|
298 |
+
|
299 |
+
UBLogger::debug_var('get_url_purpose $host', $host);
|
300 |
+
UBLogger::debug_var('get_url_purpose $path', $path);
|
301 |
+
UBLogger::debug_var('get_url_purpose $url_without_protocol', $url_without_protocol);
|
302 |
+
|
303 |
+
if ($http_method == 'GET' && $path == '/_ubhc') {
|
304 |
+
return 'HealthCheck';
|
305 |
+
} elseif ($http_method == "POST" &&
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
306 |
preg_match("/^\/(fsn|fsg|fs)\/?$/", $path)) {
|
307 |
+
return "SubmitLead";
|
308 |
+
} elseif ($http_method == "GET" &&
|
309 |
UBHTTP::is_tracking_link($proxyable_url_set, $url_without_protocol)) {
|
310 |
+
return "TrackClick";
|
311 |
+
} elseif (($http_method == "GET" || $http_method == "POST") &&
|
312 |
(in_array($url_without_protocol, $proxyable_url_set) ||
|
313 |
UBHTTP::is_confirmation_dialog($proxyable_url_set, $url_without_protocol) ||
|
314 |
UBHTTP::is_lightbox($proxyable_url_set, $url_without_protocol) ||
|
315 |
UBHTTP::is_variant($proxyable_url_set, $url_without_protocol))) {
|
316 |
+
return "ViewLandingPage";
|
317 |
+
} elseif ($http_method == "GET" && $path == UBHTTP::$pie_htc_url) {
|
318 |
+
// proxy PIE.htc
|
319 |
+
return "ViewLandingPage";
|
320 |
+
} else {
|
321 |
+
return null;
|
322 |
+
}
|
323 |
}
|
|
|
324 |
|
325 |
+
public static function send_event_to_events_gateway($url, $data_string)
|
326 |
+
{
|
327 |
+
try {
|
328 |
+
$stream_function = function ($curl, $str) {
|
329 |
+
return strlen($str);
|
330 |
+
};
|
331 |
+
|
332 |
+
$curl = curl_init();
|
333 |
+
$curl_options = array(
|
334 |
+
CURLOPT_URL => $url,
|
335 |
+
CURLOPT_CUSTOMREQUEST => 'POST',
|
336 |
+
CURLOPT_USERAGENT => UBConfig::UB_USER_AGENT,
|
337 |
+
CURLOPT_FOLLOWLOCATION => false,
|
338 |
+
CURLOPT_HTTPHEADER => array(
|
339 |
+
'Content-Type: application/json',
|
340 |
+
'Content-Length: ' . strlen($data_string)
|
341 |
+
),
|
342 |
+
CURLOPT_HEADERFUNCTION => $stream_function,
|
343 |
+
CURLOPT_WRITEFUNCTION => $stream_function,
|
344 |
+
CURLOPT_POSTFIELDS => $data_string,
|
345 |
+
CURLOPT_TIMEOUT => 2
|
346 |
+
);
|
347 |
+
curl_setopt_array($curl, $curl_options);
|
348 |
+
$success = curl_exec($curl);
|
349 |
+
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
350 |
+
|
351 |
+
if (!$success) {
|
352 |
+
$message = 'Unable to send log messages to ' . $url . ': "'
|
353 |
+
. curl_error($curl) . '" - HTTP status: ' . curl_errno($curl);
|
354 |
+
UBLogger::warning($message);
|
355 |
+
} elseif ($http_code >= 200 && $http_code < 300) {
|
356 |
+
$message = 'Successfully sent log messsages to ' . $url
|
357 |
+
. ' - HTTP status: ' . $http_code;
|
358 |
+
UBLogger::debug($message);
|
359 |
+
} else {
|
360 |
+
$message = 'Unable to send log messages to ' . $url
|
361 |
+
. ' - HTTP status: ' . $http_code;
|
362 |
+
UBLogger::warning($message);
|
363 |
+
}
|
364 |
+
|
365 |
+
curl_close($curl);
|
366 |
+
} catch (Exception $e) {
|
367 |
+
$message = 'Unable to send log messages to ' . $url
|
368 |
. ' - Error: ' . $e;
|
369 |
+
UBLogger::warning($message);
|
370 |
+
}
|
371 |
}
|
|
|
|
|
372 |
}
|
|
|
|
UBIcon.php
CHANGED
@@ -1,9 +1,10 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
class UBIcon
|
4 |
-
|
5 |
-
|
6 |
-
|
|
|
|
|
|
|
7 |
}
|
8 |
-
|
9 |
-
?>
|
1 |
<?php
|
2 |
|
3 |
+
class UBIcon
|
4 |
+
{
|
5 |
+
public static function base64_encoded_svg()
|
6 |
+
{
|
7 |
+
// @codingStandardsIgnoreLine
|
8 |
+
return 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxzdmcKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIgogICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIgogICB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiCiAgIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgdmlld0JveD0iMCAwIDI1Mi43ODY2NyAyNTIuNzg2NjciCiAgIGhlaWdodD0iMjUyLjc4NjY3IgogICB3aWR0aD0iMjUyLjc4NjY3IgogICB4bWw6c3BhY2U9InByZXNlcnZlIgogICB2ZXJzaW9uPSIxLjEiCiAgIGlkPSJzdmcyIj48bWV0YWRhdGEKICAgICBpZD0ibWV0YWRhdGE4Ij48cmRmOlJERj48Y2M6V29yawogICAgICAgICByZGY6YWJvdXQ9IiI+PGRjOmZvcm1hdD5pbWFnZS9zdmcreG1sPC9kYzpmb3JtYXQ+PGRjOnR5cGUKICAgICAgICAgICByZGY6cmVzb3VyY2U9Imh0dHA6Ly9wdXJsLm9yZy9kYy9kY21pdHlwZS9TdGlsbEltYWdlIiAvPjwvY2M6V29yaz48L3JkZjpSREY+PC9tZXRhZGF0YT48ZGVmcwogICAgIGlkPSJkZWZzNiIgLz48ZwogICAgIHRyYW5zZm9ybT0ibWF0cml4KDEuMzMzMzMzMywwLDAsLTEuMzMzMzMzMywwLDI1Mi43ODY2NykiCiAgICAgaWQ9ImcxMCI+PGcKICAgICAgIHRyYW5zZm9ybT0ic2NhbGUoMC4xKSIKICAgICAgIGlkPSJnMTIiPjxwYXRoCiAgICAgICAgIGlkPSJwYXRoMTQiCiAgICAgICAgIHN0eWxlPSJmaWxsOiNmZmZmZmY7ZmlsbC1vcGFjaXR5OjE7ZmlsbC1ydWxlOm5vbnplcm87c3Ryb2tlOm5vbmUiCiAgICAgICAgIGQ9Ik0gOTQ3Ljk1MywxODk1LjkgQyA0MjQuMzkxLDE4OTUuOSAwLDE0NzEuNDkgMCw5NDcuOTUzIDAsNDI0LjQxNCA0MjQuMzkxLDAgOTQ3Ljk1MywwIGMgNTIzLjU2NywwIDk0Ny45NTcsNDI0LjQxNCA5NDcuOTU3LDk0Ny45NTMgMCw1MjMuNTM3IC00MjQuMzksOTQ3Ljk0NyAtOTQ3Ljk1Nyw5NDcuOTQ3IHogTSA2ODUuODU1LDI4MS4yMjcgYyAxMC40ODUsNjcuNDg4IDIwLjQ4MSwxMjkuNTA3IDI5LjgyNSwxODYuNzQyIC0yMDguNzc0LDEwNC42NDQgLTM0MS4wODIsMzE1LjMxNiAtMzA3LjM0LDU1OC43OTEgNDYuMDU4LDMzMC42NyAzMDAuNjY0LDUwMC4yNSA2MjAuODYsNDcxLjQgMjQuMjgsMzQuMzcgNTAuOTMsNjcuMzUgODEuMjYsOTkuMjYgNTQuMDIsNjAuMzkgMTM0LjM1LDYyLjI5IDk4LjIyLC05LjI4IC03Mi44MiwtMTM3LjggLTEwMS42LC0yNDEuODQgLTE2NC4xNSwtNDA4LjkyIC02Mi4zNDIsLTE3Ny43IC0xNTguNzA2LC00MzguNTEzIC0yODYuOTg3LC04OTYuNDYyIC05LjI3NywtNDEuOTM0IC03NS4wMDQsLTM1LjI1IC03MS42ODgsLTEuNTMxIHogTSAxNDg4LjA1LDg4OC40ODQgQyAxNDQ2LjQyLDU3Mi43NSAxMTUxLjMsMzkzLjU3IDg1Ny45NDUsNDI0LjUwOCBjIDIxLjI5Myw3MS45ODggMzEuMzc5LDEwMi42OTEgNTYuMDU5LDE2MC43MTkgMTguNjIxLDMzLjQ4OCA4OC4zMzYsNDcuMTc1IDE0Mi40NjYsNzAuMTgzIDEwOS45NSwzOS41MTYgMTk0LjM5LDEzNy42NiAyMTAuMzUsMjYxLjUxMiAxMS4yMyw4Ny44MDggLTE0LjQyLDE3MS45NDggLTY0LjcsMjM2Ljk3OCAtMzUuMTYsNDQuNjIgLTY4LjMsNzEuNjYgLTU2Ljk4LDExMy41NSAxNi42NSw1Ni41NCAyOS40Miw5OC41MSA2MC40OCwxNjkuNTggMTkyLjc1LC0xMDMuNTMgMzEyLjkxLC0zMTguNTcgMjgyLjQzLC01NDguNTQ2IiAvPjxwYXRoCiAgICAgICAgIGlkPSJwYXRoMTYiCiAgICAgICAgIHN0eWxlPSJmaWxsOiNmZmZmZmY7ZmlsbC1vcGFjaXR5OjE7ZmlsbC1ydWxlOm5vbnplcm87c3Ryb2tlOm5vbmUiCiAgICAgICAgIGQ9Im0gNjI5LjgwMSw5OTguNDY1IGMgLTEwLjg3NSwtODQuNDY5IDEyLjEyOSwtMTY1LjA4MiA1OC4yMzQsLTIyOC42NzYgMzAuNzMxLC00MS4wNDcgNTQuMjcsLTY0Ljk4IDY1Ljc5NywtODMuODEyIDM3Ljk4OCwyMDUuNzA3IDY1LjQwMiwzMTIuMTE3IDEwMS45MzgsNDMxLjUwMyAxNi4zNzUsNDkuODcgNDMuNTA3LDExOS44MiA2My4xNDgsMTY3LjQ1IC0yMy40MjYsLTcuODQgLTU2LjY1NiwtMTYuNTYgLTgzLjc5NywtMjcuMTggLTEwNy40OTIsLTQwLjMxIC0xODkuNjY4LC0xMzcuNDQgLTIwNS4zMiwtMjU5LjI4NSIgLz48L2c+PC9nPjwvc3ZnPg==';
|
9 |
+
}
|
10 |
}
|
|
|
|
UBLogger.php
CHANGED
@@ -1,78 +1,95 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
class UBLogger
|
|
|
4 |
|
5 |
// should be called when the plugin is loaded
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
9 |
}
|
10 |
-
$GLOBALS['wp_log_plugins'][UBConfig::UB_PLUGIN_NAME] = array();
|
11 |
-
$GLOBALS['wp_log_plugins'][UBConfig::UB_PLUGIN_NAME . '-vars'] = array();
|
12 |
-
}
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
}
|
22 |
-
}
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
private static function log_wp_log($log_entry) {
|
30 |
-
$GLOBALS['wp_log'][UBConfig::UB_PLUGIN_NAME][] = $log_entry;
|
31 |
-
}
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
40 |
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
UBLogger::log_wp_log($log_entry);
|
45 |
-
UBLogger::log_error_log($log_entry);
|
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 |
-
?>
|
1 |
<?php
|
2 |
|
3 |
+
class UBLogger
|
4 |
+
{
|
5 |
|
6 |
// should be called when the plugin is loaded
|
7 |
+
public static function setup_logger()
|
8 |
+
{
|
9 |
+
if (!isset($GLOBALS['wp_log_plugins'])) {
|
10 |
+
$GLOBALS['wp_log_plugins'] = array();
|
11 |
+
}
|
12 |
+
$GLOBALS['wp_log_plugins'][UBConfig::UB_PLUGIN_NAME] = array();
|
13 |
+
$GLOBALS['wp_log_plugins'][UBConfig::UB_PLUGIN_NAME . '-vars'] = array();
|
14 |
}
|
|
|
|
|
|
|
15 |
|
16 |
+
public static function upload_logs_to_unbounce($url)
|
17 |
+
{
|
18 |
+
// The assumption is that if curl is not installed will likely have
|
19 |
+
// reached support and would have been diagnosed through diagnostics
|
20 |
+
if (!UBDiagnostics::is_curl_installed()) {
|
21 |
+
return;
|
22 |
+
}
|
23 |
+
|
24 |
+
if (UBConfig::remote_debug_logging_enabled()) {
|
25 |
+
$data = array(
|
26 |
+
'messages' => $GLOBALS['wp_log'][UBConfig::UB_PLUGIN_NAME],
|
27 |
+
'vars' => $GLOBALS['wp_log'][UBConfig::UB_PLUGIN_NAME . '-vars'],
|
28 |
+
);
|
29 |
+
UBHTTP::send_event_to_events_gateway($url, UBEvents::log_event($data));
|
30 |
+
}
|
31 |
}
|
|
|
32 |
|
33 |
+
public static function format_log_entry($level, $msg)
|
34 |
+
{
|
35 |
+
$msg = is_string($msg) ? $msg : print_r($msg, true);
|
36 |
+
return '[' . UBConfig::UB_PLUGIN_NAME . '] [' . $level . '] ' . $msg;
|
37 |
+
}
|
|
|
|
|
|
|
38 |
|
39 |
+
private static function log_wp_log($log_entry)
|
40 |
+
{
|
41 |
+
$GLOBALS['wp_log'][UBConfig::UB_PLUGIN_NAME][] = $log_entry;
|
42 |
+
}
|
43 |
|
44 |
+
private static function log_wp_log_var($var, $val)
|
45 |
+
{
|
46 |
+
$GLOBALS['wp_log'][UBConfig::UB_PLUGIN_NAME . '-vars'][$var] = $val;
|
47 |
+
}
|
48 |
|
49 |
+
private static function log_error_log($log_entry)
|
50 |
+
{
|
51 |
+
error_log($log_entry);
|
|
|
|
|
52 |
}
|
|
|
53 |
|
54 |
+
public static function log($level, $msg)
|
55 |
+
{
|
56 |
+
if (UBConfig::debug_loggging_enabled()) {
|
57 |
+
$log_entry = UBLogger::format_log_entry($level, $msg);
|
58 |
+
UBLogger::log_wp_log($log_entry);
|
59 |
+
UBLogger::log_error_log($log_entry);
|
60 |
+
}
|
61 |
}
|
|
|
62 |
|
63 |
+
public static function log_var($level, $var, $val)
|
64 |
+
{
|
65 |
+
if (UBConfig::debug_loggging_enabled()) {
|
66 |
+
UBLogger::log($level, '$' . $var . ': ' . $val);
|
67 |
+
UBLogger::log_wp_log_var($var, $val);
|
68 |
+
}
|
69 |
+
}
|
70 |
|
71 |
+
public static function info($msg)
|
72 |
+
{
|
73 |
+
UBLogger::log('INFO', $msg);
|
74 |
+
}
|
75 |
|
76 |
+
public static function warning($msg)
|
77 |
+
{
|
78 |
+
UBLogger::log('WARNING', $msg);
|
79 |
+
}
|
80 |
|
81 |
+
public static function debug($msg)
|
82 |
+
{
|
83 |
+
UBLogger::log('DEBUG', $msg);
|
84 |
+
}
|
85 |
|
86 |
+
public static function debug_var($var, $val)
|
87 |
+
{
|
88 |
+
UBLogger::log_var('DEBUG', $var, $val);
|
89 |
+
}
|
90 |
|
91 |
+
public static function config($msg)
|
92 |
+
{
|
93 |
+
UBLogger::log('CONFIG', $msg);
|
94 |
+
}
|
95 |
}
|
|
|
|
UBPageTable.php
CHANGED
@@ -1,46 +1,49 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
class UBPageTable extends UBWPListTable
|
|
|
4 |
|
5 |
-
|
6 |
|
7 |
-
|
8 |
-
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
|
14 |
-
|
15 |
-
}
|
16 |
-
|
17 |
-
protected function column_default($item, $column_name) {
|
18 |
-
switch($column_name) {
|
19 |
-
case 'url':
|
20 |
-
return "<a href=\"//${item[$column_name]}\" target=\"_blank\">${item[$column_name]}</a>";
|
21 |
-
break;
|
22 |
-
default:
|
23 |
-
return $item[$column_name];
|
24 |
}
|
25 |
-
}
|
26 |
-
|
27 |
-
protected function display_tablenav($which) {
|
28 |
-
}
|
29 |
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
-
|
34 |
-
|
35 |
}
|
36 |
|
37 |
-
|
38 |
-
|
|
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
|
44 |
-
|
|
|
45 |
|
46 |
-
|
|
|
|
|
|
|
|
1 |
<?php
|
2 |
|
3 |
+
class UBPageTable extends UBWPListTable
|
4 |
+
{
|
5 |
|
6 |
+
private $item_scroll_threshold = 10;
|
7 |
|
8 |
+
public function __construct($page_urls)
|
9 |
+
{
|
10 |
+
parent::__construct();
|
11 |
|
12 |
+
$this->items = array_map(function ($url) {
|
13 |
+
return array('url' => $url);
|
14 |
+
}, $page_urls);
|
15 |
|
16 |
+
$this->_column_headers = array(array('url' => 'Url'), array(), array());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
}
|
|
|
|
|
|
|
|
|
18 |
|
19 |
+
protected function column_default($item, $column_name)
|
20 |
+
{
|
21 |
+
switch ($column_name) {
|
22 |
+
case 'url':
|
23 |
+
return "<a href=\"//${item[$column_name]}\" target=\"_blank\">${item[$column_name]}</a>";
|
24 |
+
break;
|
25 |
+
default:
|
26 |
+
return $item[$column_name];
|
27 |
+
}
|
28 |
+
}
|
29 |
|
30 |
+
protected function display_tablenav($which)
|
31 |
+
{
|
32 |
}
|
33 |
|
34 |
+
protected function get_table_classes()
|
35 |
+
{
|
36 |
+
$super = parent::get_table_classes();
|
37 |
|
38 |
+
if (count($this->items) > $this->item_scroll_threshold) {
|
39 |
+
$super[] = 'ub-table-scroll';
|
40 |
+
}
|
41 |
|
42 |
+
return $super;
|
43 |
+
}
|
44 |
|
45 |
+
public function no_items()
|
46 |
+
{
|
47 |
+
_e('None of your Unbounce pages have been published to WordPress.');
|
48 |
+
}
|
49 |
+
}
|
UBTemplate.php
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
class UBTemplate
|
|
|
4 |
|
5 |
/*
|
6 |
* Renders a PHP template with local variables.
|
@@ -21,25 +22,25 @@ class UBTemplate {
|
|
21 |
*
|
22 |
*/
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
31 |
}
|
32 |
-
return ob_get_clean();
|
33 |
-
}
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
private static function join_paths() {
|
40 |
-
return preg_replace('~[/\\\]+~', DIRECTORY_SEPARATOR, implode(DIRECTORY_SEPARATOR, func_get_args()));
|
41 |
-
}
|
42 |
|
|
|
|
|
|
|
|
|
43 |
}
|
44 |
-
|
45 |
-
?>
|
1 |
<?php
|
2 |
|
3 |
+
class UBTemplate
|
4 |
+
{
|
5 |
|
6 |
/*
|
7 |
* Renders a PHP template with local variables.
|
22 |
*
|
23 |
*/
|
24 |
|
25 |
+
public static function render($template, $vars = array())
|
26 |
+
{
|
27 |
+
ob_start();
|
28 |
+
try {
|
29 |
+
extract($vars);
|
30 |
+
include(UBTemplate::template_path($template));
|
31 |
+
} catch (Exception $e) {
|
32 |
+
echo $e;
|
33 |
+
}
|
34 |
+
return ob_get_clean();
|
35 |
}
|
|
|
|
|
36 |
|
37 |
+
public static function template_path($template)
|
38 |
+
{
|
39 |
+
return UBTemplate::join_paths(dirname(__FILE__), 'templates', $template . '.php');
|
40 |
+
}
|
|
|
|
|
|
|
41 |
|
42 |
+
private static function join_paths()
|
43 |
+
{
|
44 |
+
return preg_replace('~[/\\\]+~', DIRECTORY_SEPARATOR, implode(DIRECTORY_SEPARATOR, func_get_args()));
|
45 |
+
}
|
46 |
}
|
|
|
|
UBUtil.php
CHANGED
@@ -1,89 +1,90 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
class UBUtil
|
|
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
public static function array_fetch($array, $index, $default = null) {
|
10 |
-
return isset($array[$index]) ? $array[$index] : $default;
|
11 |
-
}
|
12 |
-
|
13 |
-
public static function time_ago($timestamp) {
|
14 |
-
$now = new DateTime('now');
|
15 |
-
$from = new DateTime();
|
16 |
-
$from->setTimestamp($timestamp);
|
17 |
-
$diff = date_diff($now, $from);
|
18 |
-
|
19 |
-
if($diff->y > 0) {
|
20 |
-
$message = $diff->y . ' year'. ($diff->y > 1 ? 's' : '');
|
21 |
-
}
|
22 |
-
else if($diff->m > 0) {
|
23 |
-
$message = $diff->m . ' month'. ($diff->m > 1 ? 's' : '');
|
24 |
-
}
|
25 |
-
else if($diff->d > 0) {
|
26 |
-
$message = $diff->d . ' day' . ($diff->d > 1 ? 's' : '');
|
27 |
-
}
|
28 |
-
else if($diff->h > 0) {
|
29 |
-
$message = $diff->h . ' hour' . ($diff->h > 1 ? 's' : '');
|
30 |
-
}
|
31 |
-
else if($diff->i > 0) {
|
32 |
-
$message = $diff->i . ' minute' . ($diff->i > 1 ? 's' : '');
|
33 |
-
}
|
34 |
-
else if($diff->s > 0) {
|
35 |
-
$message = $diff->s . ' second' . ($diff->s > 1? 's' : '');
|
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 |
-
catch (Exception $e) {
|
69 |
-
// ensure backward compatibility on failure
|
70 |
-
return true;
|
71 |
-
}
|
72 |
-
}
|
73 |
|
74 |
-
|
75 |
-
|
|
|
76 |
|
77 |
-
|
78 |
-
|
79 |
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
}
|
86 |
-
}
|
87 |
|
88 |
/**
|
89 |
* Checks if the current page is a preview page (from on GET parameters).
|
@@ -96,10 +97,9 @@ class UBUtil {
|
|
96 |
* - previewing pages
|
97 |
* - previewing drafts (of posts & pages)
|
98 |
*/
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
}
|
105 |
-
?>
|
1 |
<?php
|
2 |
|
3 |
+
class UBUtil
|
4 |
+
{
|
5 |
|
6 |
+
public static function array_select_by_key($input, $keep)
|
7 |
+
{
|
8 |
+
return array_intersect_key($input, array_flip($keep));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
}
|
10 |
+
|
11 |
+
public static function array_fetch($array, $index, $default = null)
|
12 |
+
{
|
13 |
+
return isset($array[$index]) ? $array[$index] : $default;
|
14 |
}
|
15 |
|
16 |
+
public static function time_ago($timestamp)
|
17 |
+
{
|
18 |
+
$now = new DateTime('now');
|
19 |
+
$from = new DateTime();
|
20 |
+
$from->setTimestamp($timestamp);
|
21 |
+
$diff = date_diff($now, $from);
|
22 |
+
|
23 |
+
if ($diff->y > 0) {
|
24 |
+
$message = $diff->y . ' year'. ($diff->y > 1 ? 's' : '');
|
25 |
+
} elseif ($diff->m > 0) {
|
26 |
+
$message = $diff->m . ' month'. ($diff->m > 1 ? 's' : '');
|
27 |
+
} elseif ($diff->d > 0) {
|
28 |
+
$message = $diff->d . ' day' . ($diff->d > 1 ? 's' : '');
|
29 |
+
} elseif ($diff->h > 0) {
|
30 |
+
$message = $diff->h . ' hour' . ($diff->h > 1 ? 's' : '');
|
31 |
+
} elseif ($diff->i > 0) {
|
32 |
+
$message = $diff->i . ' minute' . ($diff->i > 1 ? 's' : '');
|
33 |
+
} elseif ($diff->s > 0) {
|
34 |
+
$message = $diff->s . ' second' . ($diff->s > 1? 's' : '');
|
35 |
+
} else {
|
36 |
+
$message = 'a moment';
|
37 |
+
}
|
38 |
+
|
39 |
+
return $message . ' ago';
|
40 |
+
}
|
41 |
|
42 |
+
public static function clear_flash()
|
43 |
+
{
|
44 |
+
foreach ($_COOKIE as $cookie_name => $value) {
|
45 |
+
if (strpos($cookie_name, 'ub-flash-') === 0) {
|
46 |
+
setcookie($cookie_name, '', time() - 60);
|
47 |
+
}
|
48 |
+
}
|
49 |
}
|
|
|
50 |
|
51 |
+
public static function get_flash($cookie_name, $default = null)
|
52 |
+
{
|
53 |
+
return UBUtil::array_fetch($_COOKIE, "ub-flash-${cookie_name}", $default);
|
54 |
+
}
|
55 |
|
56 |
+
public static function set_flash($cookie_name, $value)
|
57 |
+
{
|
58 |
+
setcookie("ub-flash-${cookie_name}", $value, time() + 60);
|
59 |
+
}
|
60 |
|
61 |
+
public static function get_lock()
|
62 |
+
{
|
63 |
+
global $wpdb;
|
64 |
|
65 |
+
try {
|
66 |
+
$lock = $wpdb->get_var('select coalesce(get_lock("' . UBConfig::UB_LOCK_NAME . '",0), 0);');
|
67 |
|
68 |
+
return (bool) $lock;
|
69 |
+
} catch (Exception $e) {
|
70 |
+
// ensure backward compatibility on failure
|
71 |
+
return true;
|
72 |
+
}
|
73 |
}
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
+
public static function release_lock()
|
76 |
+
{
|
77 |
+
global $wpdb;
|
78 |
|
79 |
+
try {
|
80 |
+
$release = $wpdb->get_var('select coalesce(release_lock("' . UBConfig::UB_LOCK_NAME . '"), 0);');
|
81 |
|
82 |
+
return (bool) $release;
|
83 |
+
} catch (Exception $e) {
|
84 |
+
// ensure backward compatibility on failure
|
85 |
+
return true;
|
86 |
+
}
|
87 |
}
|
|
|
88 |
|
89 |
/**
|
90 |
* Checks if the current page is a preview page (from on GET parameters).
|
97 |
* - previewing pages
|
98 |
* - previewing drafts (of posts & pages)
|
99 |
*/
|
100 |
+
public static function is_wordpress_preview($get_params)
|
101 |
+
{
|
102 |
+
return isset($get_params['preview'])
|
103 |
+
&& (isset($get_params['p']) || isset($get_params['page_id']) || isset($get_params['preview_id']));
|
104 |
+
}
|
105 |
}
|
|
UBWPListTable.php
CHANGED
@@ -8,1134 +8,1239 @@
|
|
8 |
* @package WordPress
|
9 |
* @subpackage List_Table
|
10 |
*/
|
11 |
-
class UBWPListTable
|
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 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
336 |
?>
|
337 |
<p class="search-box">
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
</p>
|
342 |
<?php
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
525 |
SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
|
526 |
FROM $wpdb->posts
|
527 |
WHERE post_type = %s
|
528 |
ORDER BY post_date DESC
|
529 |
-
", $post_type
|
530 |
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
|
541 |
-
|
542 |
|
543 |
-
|
544 |
-
|
|
|
545 |
|
546 |
-
|
547 |
?>
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
<?php
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
|
|
|
|
566 |
?>
|
567 |
-
|
568 |
<?php
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
|
|
580 |
?>
|
581 |
-
|
582 |
-
|
583 |
<?php
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
|
|
597 |
<?php
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
|
816 |
-
|
817 |
-
|
818 |
-
|
819 |
-
|
820 |
-
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
-
|
825 |
-
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
-
|
860 |
-
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
|
870 |
-
|
871 |
-
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
-
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
|
906 |
-
|
907 |
-
|
908 |
-
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
-
|
916 |
-
|
917 |
-
|
918 |
-
|
919 |
-
|
920 |
-
|
921 |
-
|
922 |
-
|
923 |
-
|
924 |
-
|
925 |
-
|
926 |
-
|
927 |
-
|
928 |
-
|
929 |
-
|
930 |
-
|
931 |
-
|
932 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
933 |
|
934 |
?>
|
935 |
-
<table class="wp-list-table <?php echo implode(
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
-
|
944 |
-
|
945 |
-
|
946 |
-
|
947 |
-
|
948 |
-
|
949 |
-
|
950 |
-
|
951 |
-
|
952 |
-
|
953 |
-
|
954 |
|
955 |
</table>
|
956 |
<?php
|
957 |
-
|
958 |
-
|
959 |
-
|
960 |
-
|
961 |
-
|
962 |
-
|
963 |
-
|
964 |
-
|
965 |
-
|
966 |
-
|
967 |
-
|
968 |
-
|
969 |
-
|
970 |
-
|
971 |
-
|
972 |
-
|
973 |
-
|
974 |
-
|
975 |
-
|
976 |
-
|
977 |
-
|
978 |
-
|
979 |
-
|
980 |
-
|
981 |
-
|
|
|
|
|
|
|
982 |
?>
|
983 |
-
|
984 |
|
985 |
-
|
986 |
-
|
987 |
-
|
988 |
<?php
|
989 |
-
|
990 |
-
|
991 |
?>
|
992 |
|
993 |
-
|
994 |
-
|
995 |
<?php
|
996 |
-
|
997 |
-
|
998 |
-
|
999 |
-
|
1000 |
-
|
1001 |
-
|
1002 |
-
|
1003 |
-
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
1007 |
-
|
1008 |
-
|
1009 |
-
|
1010 |
-
|
1011 |
-
|
1012 |
-
|
1013 |
-
|
1014 |
-
|
1015 |
-
|
1016 |
-
|
1017 |
-
|
1018 |
-
|
1019 |
-
|
1020 |
-
|
1021 |
-
|
1022 |
-
|
1023 |
-
|
1024 |
-
|
1025 |
-
|
1026 |
-
|
1027 |
-
|
1028 |
-
|
1029 |
-
|
1030 |
-
|
1031 |
-
|
1032 |
-
|
1033 |
-
|
1034 |
-
|
1035 |
-
|
1036 |
-
|
1037 |
-
|
1038 |
-
|
1039 |
-
|
1040 |
-
|
1041 |
-
|
1042 |
-
|
1043 |
-
|
1044 |
-
|
1045 |
-
|
1046 |
-
|
1047 |
-
|
1048 |
-
|
1049 |
-
|
1050 |
-
|
1051 |
-
|
1052 |
-
|
1053 |
-
|
1054 |
-
|
1055 |
-
|
1056 |
-
|
1057 |
-
|
1058 |
-
|
1059 |
-
|
1060 |
-
|
1061 |
-
|
1062 |
-
|
1063 |
-
|
1064 |
-
|
1065 |
-
|
1066 |
-
|
1067 |
-
|
1068 |
-
|
1069 |
-
|
1070 |
-
|
1071 |
-
|
1072 |
-
|
1073 |
-
|
1074 |
-
|
1075 |
-
|
1076 |
-
|
1077 |
-
|
1078 |
-
|
1079 |
-
|
1080 |
-
|
1081 |
-
|
1082 |
-
|
1083 |
-
|
1084 |
-
|
1085 |
-
|
1086 |
-
|
1087 |
-
|
1088 |
-
|
1089 |
-
|
1090 |
-
|
1091 |
-
|
1092 |
-
|
1093 |
-
|
1094 |
-
|
1095 |
-
|
1096 |
-
|
1097 |
-
|
1098 |
-
|
1099 |
-
|
1100 |
-
|
1101 |
-
|
1102 |
-
|
1103 |
-
|
1104 |
-
|
1105 |
-
|
1106 |
-
|
1107 |
-
|
1108 |
-
|
1109 |
-
|
1110 |
-
|
1111 |
-
|
1112 |
-
|
1113 |
-
|
1114 |
-
|
1115 |
-
|
1116 |
-
|
1117 |
-
|
1118 |
-
|
1119 |
-
|
1120 |
-
|
1121 |
-
|
1122 |
-
|
1123 |
-
|
1124 |
-
|
1125 |
-
|
1126 |
-
|
1127 |
-
|
1128 |
-
|
1129 |
-
|
1130 |
-
|
1131 |
-
|
1132 |
-
|
1133 |
-
|
1134 |
-
|
1135 |
-
|
1136 |
-
|
1137 |
-
|
1138 |
-
|
1139 |
-
|
1140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1141 |
}
|
8 |
* @package WordPress
|
9 |
* @subpackage List_Table
|
10 |
*/
|
11 |
+
class UBWPListTable
|
12 |
+
{
|
13 |
+
|
14 |
+
/**
|
15 |
+
* The current list of items
|
16 |
+
*
|
17 |
+
* @since 3.1.0
|
18 |
+
* @var array
|
19 |
+
* @access public
|
20 |
+
*/
|
21 |
+
public $items;
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Various information about the current table
|
25 |
+
*
|
26 |
+
* @since 3.1.0
|
27 |
+
* @var array
|
28 |
+
* @access protected
|
29 |
+
*/
|
30 |
+
protected $_args;
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Various information needed for displaying the pagination
|
34 |
+
*
|
35 |
+
* @since 3.1.0
|
36 |
+
* @var array
|
37 |
+
*/
|
38 |
+
protected $_pagination_args = array();
|
39 |
+
|
40 |
+
/**
|
41 |
+
* The current screen
|
42 |
+
*
|
43 |
+
* @since 3.1.0
|
44 |
+
* @var object
|
45 |
+
* @access protected
|
46 |
+
*/
|
47 |
+
protected $screen;
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Cached bulk actions
|
51 |
+
*
|
52 |
+
* @since 3.1.0
|
53 |
+
* @var array
|
54 |
+
* @access private
|
55 |
+
*/
|
56 |
+
private $_actions;
|
57 |
+
|
58 |
+
/**
|
59 |
+
* Cached pagination output
|
60 |
+
*
|
61 |
+
* @since 3.1.0
|
62 |
+
* @var string
|
63 |
+
* @access private
|
64 |
+
*/
|
65 |
+
private $_pagination;
|
66 |
+
|
67 |
+
/**
|
68 |
+
* The view switcher modes.
|
69 |
+
*
|
70 |
+
* @since 4.1.0
|
71 |
+
* @var array
|
72 |
+
* @access protected
|
73 |
+
*/
|
74 |
+
protected $modes = array();
|
75 |
+
|
76 |
+
/**
|
77 |
+
* Stores the value returned by ->get_column_info()
|
78 |
+
*
|
79 |
+
* @var array
|
80 |
+
*/
|
81 |
+
protected $_column_headers;
|
82 |
+
|
83 |
+
protected $compat_fields = array( '_args', '_pagination_args', 'screen', '_actions', '_pagination' );
|
84 |
+
|
85 |
+
protected $compat_methods = array( 'set_pagination_args', 'get_views', 'get_bulk_actions', 'bulk_actions',
|
86 |
+
'row_actions', 'months_dropdown', 'view_switcher', 'comments_bubble', 'get_items_per_page', 'pagination',
|
87 |
+
'get_sortable_columns', 'get_column_info', 'get_table_classes', 'display_tablenav', 'extra_tablenav',
|
88 |
+
'single_row_columns' );
|
89 |
+
|
90 |
+
/**
|
91 |
+
* Constructor.
|
92 |
+
*
|
93 |
+
* The child class should call this constructor from its own constructor to override
|
94 |
+
* the default $args.
|
95 |
+
*
|
96 |
+
* @since 3.1.0
|
97 |
+
* @access public
|
98 |
+
*
|
99 |
+
* @param array|string $args {
|
100 |
+
* Array or string of arguments.
|
101 |
+
*
|
102 |
+
* @type string $plural Plural value used for labels and the objects being listed.
|
103 |
+
* This affects things such as CSS class-names and nonces used
|
104 |
+
* in the list table, e.g. 'posts'. Default empty.
|
105 |
+
* @type string $singular Singular label for an object being listed, e.g. 'post'.
|
106 |
+
* Default empty
|
107 |
+
* @type bool $ajax Whether the list table supports AJAX. This includes loading
|
108 |
+
* and sorting data, for example. If true, the class will call
|
109 |
+
* the {@see _js_vars()} method in the footer to provide variables
|
110 |
+
* to any scripts handling AJAX events. Default false.
|
111 |
+
* @type string $screen String containing the hook name used to determine the current
|
112 |
+
* screen. If left null, the current screen will be automatically set.
|
113 |
+
* Default null.
|
114 |
+
* }
|
115 |
+
*/
|
116 |
+
public function __construct($args = array())
|
117 |
+
{
|
118 |
+
$args = wp_parse_args($args, array(
|
119 |
+
'plural' => '',
|
120 |
+
'singular' => '',
|
121 |
+
'ajax' => false,
|
122 |
+
'screen' => null,
|
123 |
+
));
|
124 |
+
|
125 |
+
$this->screen = convert_to_screen($args['screen']);
|
126 |
+
|
127 |
+
add_filter("manage_{$this->screen->id}_columns", array( $this, 'get_columns' ), 0);
|
128 |
+
|
129 |
+
if (!$args['plural']) {
|
130 |
+
$args['plural'] = $this->screen->base;
|
131 |
+
}
|
132 |
+
|
133 |
+
$args['plural'] = sanitize_key($args['plural']);
|
134 |
+
$args['singular'] = sanitize_key($args['singular']);
|
135 |
+
|
136 |
+
$this->_args = $args;
|
137 |
+
|
138 |
+
if ($args['ajax']) {
|
139 |
+
// wp_enqueue_script( 'list-table' );
|
140 |
+
add_action('admin_footer', array( $this, '_js_vars' ));
|
141 |
+
}
|
142 |
+
|
143 |
+
if (empty($this->modes)) {
|
144 |
+
$this->modes = array(
|
145 |
+
'list' => __('List View'),
|
146 |
+
'excerpt' => __('Excerpt View')
|
147 |
+
);
|
148 |
+
}
|
149 |
+
}
|
150 |
+
|
151 |
+
/**
|
152 |
+
* Make private properties readable for backwards compatibility.
|
153 |
+
*
|
154 |
+
* @since 4.0.0
|
155 |
+
* @access public
|
156 |
+
*
|
157 |
+
* @param string $name Property to get.
|
158 |
+
* @return mixed Property.
|
159 |
+
*/
|
160 |
+
public function __get($name)
|
161 |
+
{
|
162 |
+
if (in_array($name, $this->compat_fields)) {
|
163 |
+
return $this->$name;
|
164 |
+
}
|
165 |
+
}
|
166 |
+
|
167 |
+
/**
|
168 |
+
* Make private properties settable for backwards compatibility.
|
169 |
+
*
|
170 |
+
* @since 4.0.0
|
171 |
+
* @access public
|
172 |
+
*
|
173 |
+
* @param string $name Property to check if set.
|
174 |
+
* @param mixed $value Property value.
|
175 |
+
* @return mixed Newly-set property.
|
176 |
+
*/
|
177 |
+
public function __set($name, $value)
|
178 |
+
{
|
179 |
+
if (in_array($name, $this->compat_fields)) {
|
180 |
+
return $this->$name = $value;
|
181 |
+
}
|
182 |
+
}
|
183 |
+
|
184 |
+
/**
|
185 |
+
* Make private properties checkable for backwards compatibility.
|
186 |
+
*
|
187 |
+
* @since 4.0.0
|
188 |
+
* @access public
|
189 |
+
*
|
190 |
+
* @param string $name Property to check if set.
|
191 |
+
* @return bool Whether the property is set.
|
192 |
+
*/
|
193 |
+
public function __isset($name)
|
194 |
+
{
|
195 |
+
if (in_array($name, $this->compat_fields)) {
|
196 |
+
return isset($this->$name);
|
197 |
+
}
|
198 |
+
}
|
199 |
+
|
200 |
+
/**
|
201 |
+
* Make private properties un-settable for backwards compatibility.
|
202 |
+
*
|
203 |
+
* @since 4.0.0
|
204 |
+
* @access public
|
205 |
+
*
|
206 |
+
* @param string $name Property to unset.
|
207 |
+
*/
|
208 |
+
public function __unset($name)
|
209 |
+
{
|
210 |
+
if (in_array($name, $this->compat_fields)) {
|
211 |
+
unset($this->$name);
|
212 |
+
}
|
213 |
+
}
|
214 |
+
|
215 |
+
/**
|
216 |
+
* Make private/protected methods readable for backwards compatibility.
|
217 |
+
*
|
218 |
+
* @since 4.0.0
|
219 |
+
* @access public
|
220 |
+
*
|
221 |
+
* @param callable $name Method to call.
|
222 |
+
* @param array $arguments Arguments to pass when calling.
|
223 |
+
* @return mixed|bool Return value of the callback, false otherwise.
|
224 |
+
*/
|
225 |
+
public function __call($name, $arguments)
|
226 |
+
{
|
227 |
+
if (in_array($name, $this->compat_methods)) {
|
228 |
+
return call_user_func_array(array( $this, $name ), $arguments);
|
229 |
+
}
|
230 |
+
return false;
|
231 |
+
}
|
232 |
+
|
233 |
+
/**
|
234 |
+
* Checks the current user's permissions
|
235 |
+
*
|
236 |
+
* @since 3.1.0
|
237 |
+
* @access public
|
238 |
+
* @abstract
|
239 |
+
*/
|
240 |
+
public function ajax_user_can()
|
241 |
+
{
|
242 |
+
die('function WP_List_Table::ajax_user_can() must be over-ridden in a sub-class.');
|
243 |
+
}
|
244 |
+
|
245 |
+
/**
|
246 |
+
* Prepares the list of items for displaying.
|
247 |
+
* @uses WP_List_Table::set_pagination_args()
|
248 |
+
*
|
249 |
+
* @since 3.1.0
|
250 |
+
* @access public
|
251 |
+
* @abstract
|
252 |
+
*/
|
253 |
+
public function prepare_items()
|
254 |
+
{
|
255 |
+
die('function WP_List_Table::prepare_items() must be over-ridden in a sub-class.');
|
256 |
+
}
|
257 |
+
|
258 |
+
/**
|
259 |
+
* An internal method that sets all the necessary pagination arguments
|
260 |
+
*
|
261 |
+
* @param array $args An associative array with information about the pagination
|
262 |
+
* @access protected
|
263 |
+
*/
|
264 |
+
protected function set_pagination_args($args)
|
265 |
+
{
|
266 |
+
$args = wp_parse_args($args, array(
|
267 |
+
'total_items' => 0,
|
268 |
+
'total_pages' => 0,
|
269 |
+
'per_page' => 0,
|
270 |
+
));
|
271 |
+
|
272 |
+
if (!$args['total_pages'] && $args['per_page'] > 0) {
|
273 |
+
$args['total_pages'] = ceil($args['total_items'] / $args['per_page']);
|
274 |
+
}
|
275 |
+
|
276 |
+
$doingAjax = defined('DOING_AJAX') && DOING_AJAX;
|
277 |
+
|
278 |
+
// Redirect if page number is invalid and headers are not already sent.
|
279 |
+
if (!headers_sent() && !$doingAjax && $args['total_pages'] > 0 && $this->get_pagenum() > $args['total_pages']) {
|
280 |
+
wp_redirect(add_query_arg('paged', $args['total_pages']));
|
281 |
+
exit;
|
282 |
+
}
|
283 |
+
|
284 |
+
$this->_pagination_args = $args;
|
285 |
+
}
|
286 |
+
|
287 |
+
/**
|
288 |
+
* Access the pagination args.
|
289 |
+
*
|
290 |
+
* @since 3.1.0
|
291 |
+
* @access public
|
292 |
+
*
|
293 |
+
* @param string $key Pagination argument to retrieve. Common values include 'total_items',
|
294 |
+
* 'total_pages', 'per_page', or 'infinite_scroll'.
|
295 |
+
* @return int Number of items that correspond to the given pagination argument.
|
296 |
+
*/
|
297 |
+
public function get_pagination_arg($key)
|
298 |
+
{
|
299 |
+
if ('page' == $key) {
|
300 |
+
return $this->get_pagenum();
|
301 |
+
}
|
302 |
+
|
303 |
+
if (isset($this->_pagination_args[$key])) {
|
304 |
+
return $this->_pagination_args[$key];
|
305 |
+
}
|
306 |
+
}
|
307 |
+
|
308 |
+
/**
|
309 |
+
* Whether the table has items to display or not
|
310 |
+
*
|
311 |
+
* @since 3.1.0
|
312 |
+
* @access public
|
313 |
+
*
|
314 |
+
* @return bool
|
315 |
+
*/
|
316 |
+
public function has_items()
|
317 |
+
{
|
318 |
+
return !empty($this->items);
|
319 |
+
}
|
320 |
+
|
321 |
+
/**
|
322 |
+
* Message to be displayed when there are no items
|
323 |
+
*
|
324 |
+
* @since 3.1.0
|
325 |
+
* @access public
|
326 |
+
*/
|
327 |
+
public function no_items()
|
328 |
+
{
|
329 |
+
_e('No items found.');
|
330 |
+
}
|
331 |
+
|
332 |
+
/**
|
333 |
+
* Display the search box.
|
334 |
+
*
|
335 |
+
* @since 3.1.0
|
336 |
+
* @access public
|
337 |
+
*
|
338 |
+
* @param string $text The search button text
|
339 |
+
* @param string $input_id The search input id
|
340 |
+
*/
|
341 |
+
public function search_box($text, $input_id)
|
342 |
+
{
|
343 |
+
if (empty($_REQUEST['s']) && !$this->has_items()) {
|
344 |
+
return;
|
345 |
+
}
|
346 |
+
|
347 |
+
$input_id = $input_id . '-search-input';
|
348 |
+
|
349 |
+
if (! empty($_REQUEST['orderby'])) {
|
350 |
+
echo '<input type="hidden" name="orderby" value="' . esc_attr($_REQUEST['orderby']) . '" />';
|
351 |
+
}
|
352 |
+
if (! empty($_REQUEST['order'])) {
|
353 |
+
echo '<input type="hidden" name="order" value="' . esc_attr($_REQUEST['order']) . '" />';
|
354 |
+
}
|
355 |
+
if (! empty($_REQUEST['post_mime_type'])) {
|
356 |
+
echo '<input type="hidden" name="post_mime_type" value="' . esc_attr($_REQUEST['post_mime_type']) . '" />';
|
357 |
+
}
|
358 |
+
if (! empty($_REQUEST['detached'])) {
|
359 |
+
echo '<input type="hidden" name="detached" value="' . esc_attr($_REQUEST['detached']) . '" />';
|
360 |
+
}
|
361 |
?>
|
362 |
<p class="search-box">
|
363 |
+
<label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label>
|
364 |
+
<input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" />
|
365 |
+
<?php submit_button($text, 'button', '', false, array('id' => 'search-submit')); ?>
|
366 |
</p>
|
367 |
<?php
|
368 |
+
}
|
369 |
+
|
370 |
+
/**
|
371 |
+
* Get an associative array ( id => link ) with the list
|
372 |
+
* of views available on this table.
|
373 |
+
*
|
374 |
+
* @since 3.1.0
|
375 |
+
* @access protected
|
376 |
+
*
|
377 |
+
* @return array
|
378 |
+
*/
|
379 |
+
protected function get_views()
|
380 |
+
{
|
381 |
+
return array();
|
382 |
+
}
|
383 |
+
|
384 |
+
/**
|
385 |
+
* Display the list of views available on this table.
|
386 |
+
*
|
387 |
+
* @since 3.1.0
|
388 |
+
* @access public
|
389 |
+
*/
|
390 |
+
public function views()
|
391 |
+
{
|
392 |
+
$views = $this->get_views();
|
393 |
+
/**
|
394 |
+
* Filter the list of available list table views.
|
395 |
+
*
|
396 |
+
* The dynamic portion of the hook name, `$this->screen->id`, refers
|
397 |
+
* to the ID of the current screen, usually a string.
|
398 |
+
*
|
399 |
+
* @since 3.5.0
|
400 |
+
*
|
401 |
+
* @param array $views An array of available list table views.
|
402 |
+
*/
|
403 |
+
$views = apply_filters("views_{$this->screen->id}", $views);
|
404 |
+
|
405 |
+
if (empty($views)) {
|
406 |
+
return;
|
407 |
+
}
|
408 |
+
|
409 |
+
echo "<ul class='subsubsub'>\n";
|
410 |
+
foreach ($views as $class => $view) {
|
411 |
+
$views[ $class ] = "\t<li class='$class'>$view";
|
412 |
+
}
|
413 |
+
echo implode(" |</li>\n", $views) . "</li>\n";
|
414 |
+
echo "</ul>";
|
415 |
+
}
|
416 |
+
|
417 |
+
/**
|
418 |
+
* Get an associative array ( option_name => option_title ) with the list
|
419 |
+
* of bulk actions available on this table.
|
420 |
+
*
|
421 |
+
* @since 3.1.0
|
422 |
+
* @access protected
|
423 |
+
*
|
424 |
+
* @return array
|
425 |
+
*/
|
426 |
+
protected function get_bulk_actions()
|
427 |
+
{
|
428 |
+
return array();
|
429 |
+
}
|
430 |
+
|
431 |
+
/**
|
432 |
+
* Display the bulk actions dropdown.
|
433 |
+
*
|
434 |
+
* @since 3.1.0
|
435 |
+
* @access protected
|
436 |
+
*
|
437 |
+
* @param string $which The location of the bulk actions: 'top' or 'bottom'.
|
438 |
+
* This is designated as optional for backwards-compatibility.
|
439 |
+
*/
|
440 |
+
protected function bulk_actions($which = '')
|
441 |
+
{
|
442 |
+
if (is_null($this->_actions)) {
|
443 |
+
$no_new_actions = $this->_actions = $this->get_bulk_actions();
|
444 |
+
/**
|
445 |
+
* Filter the list table Bulk Actions drop-down.
|
446 |
+
*
|
447 |
+
* The dynamic portion of the hook name, `$this->screen->id`, refers
|
448 |
+
* to the ID of the current screen, usually a string.
|
449 |
+
*
|
450 |
+
* This filter can currently only be used to remove bulk actions.
|
451 |
+
*
|
452 |
+
* @since 3.5.0
|
453 |
+
*
|
454 |
+
* @param array $actions An array of the available bulk actions.
|
455 |
+
*/
|
456 |
+
$this->_actions = apply_filters("bulk_actions-{$this->screen->id}", $this->_actions);
|
457 |
+
$this->_actions = array_intersect_assoc($this->_actions, $no_new_actions);
|
458 |
+
$two = '';
|
459 |
+
} else {
|
460 |
+
$two = '2';
|
461 |
+
}
|
462 |
+
|
463 |
+
if (empty($this->_actions)) {
|
464 |
+
return;
|
465 |
+
}
|
466 |
+
|
467 |
+
echo "<label for='bulk-action-selector-" . esc_attr($which) . "' class='screen-reader-text'>" .
|
468 |
+
__('Select bulk action') . "</label>";
|
469 |
+
echo "<select name='action$two' id='bulk-action-selector-" . esc_attr($which) . "'>\n";
|
470 |
+
echo "<option value='-1' selected='selected'>" . __('Bulk Actions') . "</option>\n";
|
471 |
+
|
472 |
+
foreach ($this->_actions as $name => $title) {
|
473 |
+
$class = 'edit' == $name ? ' class="hide-if-no-js"' : '';
|
474 |
+
|
475 |
+
echo "\t<option value='$name'$class>$title</option>\n";
|
476 |
+
}
|
477 |
+
|
478 |
+
echo "</select>\n";
|
479 |
+
|
480 |
+
submit_button(__('Apply'), 'action', '', false, array( 'id' => "doaction$two" ));
|
481 |
+
echo "\n";
|
482 |
+
}
|
483 |
+
|
484 |
+
/**
|
485 |
+
* Get the current action selected from the bulk actions dropdown.
|
486 |
+
*
|
487 |
+
* @since 3.1.0
|
488 |
+
* @access public
|
489 |
+
*
|
490 |
+
* @return string|bool The action name or False if no action was selected
|
491 |
+
*/
|
492 |
+
public function current_action()
|
493 |
+
{
|
494 |
+
if (isset($_REQUEST['filter_action']) && ! empty($_REQUEST['filter_action'])) {
|
495 |
+
return false;
|
496 |
+
}
|
497 |
+
|
498 |
+
if (isset($_REQUEST['action']) && -1 != $_REQUEST['action']) {
|
499 |
+
return $_REQUEST['action'];
|
500 |
+
}
|
501 |
+
|
502 |
+
if (isset($_REQUEST['action2']) && -1 != $_REQUEST['action2']) {
|
503 |
+
return $_REQUEST['action2'];
|
504 |
+
}
|
505 |
+
|
506 |
+
return false;
|
507 |
+
}
|
508 |
+
|
509 |
+
/**
|
510 |
+
* Generate row actions div
|
511 |
+
*
|
512 |
+
* @since 3.1.0
|
513 |
+
* @access protected
|
514 |
+
*
|
515 |
+
* @param array $actions The list of actions
|
516 |
+
* @param bool $always_visible Whether the actions should be always visible
|
517 |
+
* @return string
|
518 |
+
*/
|
519 |
+
protected function row_actions($actions, $always_visible = false)
|
520 |
+
{
|
521 |
+
$action_count = count($actions);
|
522 |
+
$i = 0;
|
523 |
+
|
524 |
+
if (!$action_count) {
|
525 |
+
return '';
|
526 |
+
}
|
527 |
+
|
528 |
+
$out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';
|
529 |
+
foreach ($actions as $action => $link) {
|
530 |
+
++$i;
|
531 |
+
( $i == $action_count ) ? $sep = '' : $sep = ' | ';
|
532 |
+
$out .= "<span class='$action'>$link$sep</span>";
|
533 |
+
}
|
534 |
+
$out .= '</div>';
|
535 |
+
|
536 |
+
return $out;
|
537 |
+
}
|
538 |
+
|
539 |
+
/**
|
540 |
+
* Display a monthly dropdown for filtering items
|
541 |
+
*
|
542 |
+
* @since 3.1.0
|
543 |
+
* @access protected
|
544 |
+
*
|
545 |
+
* @param string $post_type
|
546 |
+
*/
|
547 |
+
protected function months_dropdown($post_type)
|
548 |
+
{
|
549 |
+
global $wpdb, $wp_locale;
|
550 |
+
|
551 |
+
/**
|
552 |
+
* Filter whether to remove the 'Months' drop-down from the post list table.
|
553 |
+
*
|
554 |
+
* @since 4.2.0
|
555 |
+
*
|
556 |
+
* @param bool $disable Whether to disable the drop-down. Default false.
|
557 |
+
* @param string $post_type The post type.
|
558 |
+
*/
|
559 |
+
if (apply_filters('disable_months_dropdown', false, $post_type)) {
|
560 |
+
return;
|
561 |
+
}
|
562 |
+
|
563 |
+
$months = $wpdb->get_results($wpdb->prepare("
|
564 |
SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
|
565 |
FROM $wpdb->posts
|
566 |
WHERE post_type = %s
|
567 |
ORDER BY post_date DESC
|
568 |
+
", $post_type));
|
569 |
|
570 |
+
/**
|
571 |
+
* Filter the 'Months' drop-down results.
|
572 |
+
*
|
573 |
+
* @since 3.7.0
|
574 |
+
*
|
575 |
+
* @param object $months The months drop-down query results.
|
576 |
+
* @param string $post_type The post type.
|
577 |
+
*/
|
578 |
+
$months = apply_filters('months_dropdown_results', $months, $post_type);
|
579 |
|
580 |
+
$month_count = count($months);
|
581 |
|
582 |
+
if (!$month_count || ( 1 == $month_count && 0 == $months[0]->month )) {
|
583 |
+
return;
|
584 |
+
}
|
585 |
|
586 |
+
$m = isset($_GET['m']) ? (int) $_GET['m'] : 0;
|
587 |
?>
|
588 |
+
<label for="filter-by-date" class="screen-reader-text"><?php _e('Filter by date'); ?></label>
|
589 |
+
<select name="m" id="filter-by-date">
|
590 |
+
<option<?php selected($m, 0); ?> value="0"><?php _e('All dates'); ?></option>
|
591 |
<?php
|
592 |
+
foreach ($months as $arc_row) {
|
593 |
+
if (0 == $arc_row->year) {
|
594 |
+
continue;
|
595 |
+
}
|
596 |
+
|
597 |
+
$month = zeroise($arc_row->month, 2);
|
598 |
+
$year = $arc_row->year;
|
599 |
+
|
600 |
+
printf(
|
601 |
+
"<option %s value='%s'>%s</option>\n",
|
602 |
+
selected($m, $year . $month, false),
|
603 |
+
esc_attr($arc_row->year . $month),
|
604 |
+
/* translators: 1: month name, 2: 4-digit year */
|
605 |
+
sprintf(__('%1$s %2$d'), $wp_locale->get_month($month), $year)
|
606 |
+
);
|
607 |
+
}
|
608 |
?>
|
609 |
+
</select>
|
610 |
<?php
|
611 |
+
}
|
612 |
+
|
613 |
+
/**
|
614 |
+
* Display a view switcher
|
615 |
+
*
|
616 |
+
* @since 3.1.0
|
617 |
+
* @access protected
|
618 |
+
*
|
619 |
+
* @param string $current_mode
|
620 |
+
*/
|
621 |
+
protected function view_switcher($current_mode)
|
622 |
+
{
|
623 |
?>
|
624 |
+
<input type="hidden" name="mode" value="<?php echo esc_attr($current_mode); ?>" />
|
625 |
+
<div class="view-switch">
|
626 |
<?php
|
627 |
+
foreach ($this->modes as $mode => $title) {
|
628 |
+
$classes = array( 'view-' . $mode );
|
629 |
+
if ($current_mode == $mode) {
|
630 |
+
$classes[] = 'current';
|
631 |
+
}
|
632 |
+
printf(
|
633 |
+
"<a href='%s' class='%s' id='view-switch-$mode'><span class='screen-reader-text'>%s</span></a>\n",
|
634 |
+
esc_url(add_query_arg('mode', $mode)),
|
635 |
+
implode(' ', $classes),
|
636 |
+
$title
|
637 |
+
);
|
638 |
+
}
|
639 |
+
?>
|
640 |
+
</div>
|
641 |
<?php
|
642 |
+
}
|
643 |
+
|
644 |
+
/**
|
645 |
+
* Display a comment count bubble
|
646 |
+
*
|
647 |
+
* @since 3.1.0
|
648 |
+
* @access protected
|
649 |
+
*
|
650 |
+
* @param int $post_id The post ID.
|
651 |
+
* @param int $pending_comments Number of pending comments.
|
652 |
+
*/
|
653 |
+
protected function comments_bubble($post_id, $pending_comments)
|
654 |
+
{
|
655 |
+
$pending_phrase = sprintf(__('%s pending'), number_format($pending_comments));
|
656 |
+
|
657 |
+
if ($pending_comments) {
|
658 |
+
echo '<strong>';
|
659 |
+
}
|
660 |
+
|
661 |
+
printf(
|
662 |
+
'<a href="%s" title="%s" class="post-com-count"><span class="comment-count">%s</span></a>',
|
663 |
+
esc_url(add_query_arg('p', $post_id, admin_url('edit-comments.php'))),
|
664 |
+
esc_attr($pending_phrase),
|
665 |
+
number_format_i18n(get_comments_number())
|
666 |
+
);
|
667 |
+
|
668 |
+
if ($pending_comments) {
|
669 |
+
echo '</strong>';
|
670 |
+
}
|
671 |
+
}
|
672 |
+
|
673 |
+
/**
|
674 |
+
* Get the current page number
|
675 |
+
*
|
676 |
+
* @since 3.1.0
|
677 |
+
* @access public
|
678 |
+
*
|
679 |
+
* @return int
|
680 |
+
*/
|
681 |
+
public function get_pagenum()
|
682 |
+
{
|
683 |
+
$pagenum = isset($_REQUEST['paged']) ? absint($_REQUEST['paged']) : 0;
|
684 |
+
|
685 |
+
if (isset($this->_pagination_args['total_pages']) && $pagenum > $this->_pagination_args['total_pages']) {
|
686 |
+
$pagenum = $this->_pagination_args['total_pages'];
|
687 |
+
}
|
688 |
+
|
689 |
+
return max(1, $pagenum);
|
690 |
+
}
|
691 |
+
|
692 |
+
/**
|
693 |
+
* Get number of items to display on a single page
|
694 |
+
*
|
695 |
+
* @since 3.1.0
|
696 |
+
* @access protected
|
697 |
+
*
|
698 |
+
* @param string $option
|
699 |
+
* @param int $default
|
700 |
+
* @return int
|
701 |
+
*/
|
702 |
+
protected function get_items_per_page($option, $default = 20)
|
703 |
+
{
|
704 |
+
$per_page = (int) get_user_option($option);
|
705 |
+
if (empty($per_page) || $per_page < 1) {
|
706 |
+
$per_page = $default;
|
707 |
+
}
|
708 |
+
|
709 |
+
/**
|
710 |
+
* Filter the number of items to be displayed on each page of the list table.
|
711 |
+
*
|
712 |
+
* The dynamic hook name, $option, refers to the `per_page` option depending
|
713 |
+
* on the type of list table in use. Possible values include: 'edit_comments_per_page',
|
714 |
+
* 'sites_network_per_page', 'site_themes_network_per_page', 'themes_network_per_page',
|
715 |
+
* 'users_network_per_page', 'edit_post_per_page', 'edit_page_per_page',
|
716 |
+
* 'edit_{$post_type}_per_page', etc.
|
717 |
+
*
|
718 |
+
* @since 2.9.0
|
719 |
+
*
|
720 |
+
* @param int $per_page Number of items to be displayed. Default 20.
|
721 |
+
*/
|
722 |
+
return (int) apply_filters($option, $per_page);
|
723 |
+
}
|
724 |
+
|
725 |
+
/**
|
726 |
+
* Display the pagination.
|
727 |
+
*
|
728 |
+
* @since 3.1.0
|
729 |
+
* @access protected
|
730 |
+
*
|
731 |
+
* @param string $which
|
732 |
+
*/
|
733 |
+
protected function pagination($which)
|
734 |
+
{
|
735 |
+
if (empty($this->_pagination_args)) {
|
736 |
+
return;
|
737 |
+
}
|
738 |
+
|
739 |
+
$total_items = $this->_pagination_args['total_items'];
|
740 |
+
$total_pages = $this->_pagination_args['total_pages'];
|
741 |
+
$infinite_scroll = false;
|
742 |
+
if (isset($this->_pagination_args['infinite_scroll'])) {
|
743 |
+
$infinite_scroll = $this->_pagination_args['infinite_scroll'];
|
744 |
+
}
|
745 |
+
|
746 |
+
$output = '<span class="displaying-num">'
|
747 |
+
. sprintf(_n('1 item', '%s items', $total_items), number_format_i18n($total_items))
|
748 |
+
. '</span>';
|
749 |
+
|
750 |
+
$current = $this->get_pagenum();
|
751 |
+
|
752 |
+
$current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
|
753 |
+
|
754 |
+
$current_url = remove_query_arg(array( 'hotkeys_highlight_last', 'hotkeys_highlight_first' ), $current_url);
|
755 |
+
|
756 |
+
$page_links = array();
|
757 |
+
|
758 |
+
$disable_first = $disable_last = '';
|
759 |
+
if ($current == 1) {
|
760 |
+
$disable_first = ' disabled';
|
761 |
+
}
|
762 |
+
if ($current == $total_pages) {
|
763 |
+
$disable_last = ' disabled';
|
764 |
+
}
|
765 |
+
$page_links[] = sprintf(
|
766 |
+
"<a class='%s' title='%s' href='%s'>%s</a>",
|
767 |
+
'first-page' . $disable_first,
|
768 |
+
esc_attr__('Go to the first page'),
|
769 |
+
esc_url(remove_query_arg('paged', $current_url)),
|
770 |
+
'«'
|
771 |
+
);
|
772 |
+
|
773 |
+
$page_links[] = sprintf(
|
774 |
+
"<a class='%s' title='%s' href='%s'>%s</a>",
|
775 |
+
'prev-page' . $disable_first,
|
776 |
+
esc_attr__('Go to the previous page'),
|
777 |
+
esc_url(add_query_arg('paged', max(1, $current-1), $current_url)),
|
778 |
+
'‹'
|
779 |
+
);
|
780 |
+
|
781 |
+
if ('bottom' == $which) {
|
782 |
+
$html_current_page = $current;
|
783 |
+
} else {
|
784 |
+
$html_current_page = sprintf(
|
785 |
+
"%s<input class='current-page' id='current-page-selector' title='%s'
|
786 |
+
type='text'name='paged' value='%s' size='%d' />",
|
787 |
+
'<label for="current-page-selector" class="screen-reader-text">' . __('Select Page') . '</label>',
|
788 |
+
esc_attr__('Current page'),
|
789 |
+
$current,
|
790 |
+
strlen($total_pages)
|
791 |
+
);
|
792 |
+
}
|
793 |
+
$html_total_pages = sprintf("<span class='total-pages'>%s</span>", number_format_i18n($total_pages));
|
794 |
+
$page_links[] = '<span class="paging-input">'
|
795 |
+
. sprintf(_x('%1$s of %2$s', 'paging'), $html_current_page, $html_total_pages)
|
796 |
+
. '</span>';
|
797 |
+
|
798 |
+
$page_links[] = sprintf(
|
799 |
+
"<a class='%s' title='%s' href='%s'>%s</a>",
|
800 |
+
'next-page' . $disable_last,
|
801 |
+
esc_attr__('Go to the next page'),
|
802 |
+
esc_url(add_query_arg('paged', min($total_pages, $current+1), $current_url)),
|
803 |
+
'›'
|
804 |
+
);
|
805 |
+
|
806 |
+
$page_links[] = sprintf(
|
807 |
+
"<a class='%s' title='%s' href='%s'>%s</a>",
|
808 |
+
'last-page' . $disable_last,
|
809 |
+
esc_attr__('Go to the last page'),
|
810 |
+
esc_url(add_query_arg('paged', $total_pages, $current_url)),
|
811 |
+
'»'
|
812 |
+
);
|
813 |
+
|
814 |
+
$pagination_links_class = 'pagination-links';
|
815 |
+
if (! empty($infinite_scroll)) {
|
816 |
+
$pagination_links_class = ' hide-if-js';
|
817 |
+
}
|
818 |
+
$output .= "\n<span class='$pagination_links_class'>" . join("\n", $page_links) . '</span>';
|
819 |
+
|
820 |
+
if ($total_pages) {
|
821 |
+
$page_class = $total_pages < 2 ? ' one-page' : '';
|
822 |
+
} else {
|
823 |
+
$page_class = ' no-pages';
|
824 |
+
}
|
825 |
+
$this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>";
|
826 |
+
|
827 |
+
echo $this->_pagination;
|
828 |
+
}
|
829 |
+
|
830 |
+
/**
|
831 |
+
* Get a list of columns. The format is:
|
832 |
+
* 'internal-name' => 'Title'
|
833 |
+
*
|
834 |
+
* @since 3.1.0
|
835 |
+
* @access public
|
836 |
+
* @abstract
|
837 |
+
*
|
838 |
+
* @return array
|
839 |
+
*/
|
840 |
+
public function get_columns()
|
841 |
+
{
|
842 |
+
die('function WP_List_Table::get_columns() must be over-ridden in a sub-class.');
|
843 |
+
}
|
844 |
+
|
845 |
+
/**
|
846 |
+
* Get a list of sortable columns. The format is:
|
847 |
+
* 'internal-name' => 'orderby'
|
848 |
+
* or
|
849 |
+
* 'internal-name' => array( 'orderby', true )
|
850 |
+
*
|
851 |
+
* The second format will make the initial sorting order be descending
|
852 |
+
*
|
853 |
+
* @since 3.1.0
|
854 |
+
* @access protected
|
855 |
+
*
|
856 |
+
* @return array
|
857 |
+
*/
|
858 |
+
protected function get_sortable_columns()
|
859 |
+
{
|
860 |
+
return array();
|
861 |
+
}
|
862 |
+
|
863 |
+
/**
|
864 |
+
* Get a list of all, hidden and sortable columns, with filter applied
|
865 |
+
*
|
866 |
+
* @since 3.1.0
|
867 |
+
* @access protected
|
868 |
+
*
|
869 |
+
* @return array
|
870 |
+
*/
|
871 |
+
protected function get_column_info()
|
872 |
+
{
|
873 |
+
if (isset($this->_column_headers)) {
|
874 |
+
return $this->_column_headers;
|
875 |
+
}
|
876 |
+
|
877 |
+
$columns = get_column_headers($this->screen);
|
878 |
+
$hidden = get_hidden_columns($this->screen);
|
879 |
+
|
880 |
+
$sortable_columns = $this->get_sortable_columns();
|
881 |
+
/**
|
882 |
+
* Filter the list table sortable columns for a specific screen.
|
883 |
+
*
|
884 |
+
* The dynamic portion of the hook name, `$this->screen->id`, refers
|
885 |
+
* to the ID of the current screen, usually a string.
|
886 |
+
*
|
887 |
+
* @since 3.5.0
|
888 |
+
*
|
889 |
+
* @param array $sortable_columns An array of sortable columns.
|
890 |
+
*/
|
891 |
+
$_sortable = apply_filters("manage_{$this->screen->id}_sortable_columns", $sortable_columns);
|
892 |
+
|
893 |
+
$sortable = array();
|
894 |
+
foreach ($_sortable as $id => $data) {
|
895 |
+
if (empty($data)) {
|
896 |
+
continue;
|
897 |
+
}
|
898 |
+
|
899 |
+
$data = (array) $data;
|
900 |
+
if (!isset($data[1])) {
|
901 |
+
$data[1] = false;
|
902 |
+
}
|
903 |
+
|
904 |
+
$sortable[$id] = $data;
|
905 |
+
}
|
906 |
+
|
907 |
+
$this->_column_headers = array( $columns, $hidden, $sortable );
|
908 |
+
|
909 |
+
return $this->_column_headers;
|
910 |
+
}
|
911 |
+
|
912 |
+
/**
|
913 |
+
* Return number of visible columns
|
914 |
+
*
|
915 |
+
* @since 3.1.0
|
916 |
+
* @access public
|
917 |
+
*
|
918 |
+
* @return int
|
919 |
+
*/
|
920 |
+
public function get_column_count()
|
921 |
+
{
|
922 |
+
list ( $columns, $hidden ) = $this->get_column_info();
|
923 |
+
$hidden = array_intersect(array_keys($columns), array_filter($hidden));
|
924 |
+
return count($columns) - count($hidden);
|
925 |
+
}
|
926 |
+
|
927 |
+
/**
|
928 |
+
* Print column headers, accounting for hidden and sortable columns.
|
929 |
+
*
|
930 |
+
* @since 3.1.0
|
931 |
+
* @access public
|
932 |
+
*
|
933 |
+
* @param bool $with_id Whether to set the id attribute or not
|
934 |
+
*/
|
935 |
+
public function print_column_headers($with_id = true)
|
936 |
+
{
|
937 |
+
list( $columns, $hidden, $sortable ) = $this->get_column_info();
|
938 |
+
|
939 |
+
$current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
|
940 |
+
$current_url = remove_query_arg('paged', $current_url);
|
941 |
+
|
942 |
+
if (isset($_GET['orderby'])) {
|
943 |
+
$current_orderby = $_GET['orderby'];
|
944 |
+
} else {
|
945 |
+
$current_orderby = '';
|
946 |
+
}
|
947 |
+
|
948 |
+
if (isset($_GET['order']) && 'desc' == $_GET['order']) {
|
949 |
+
$current_order = 'desc';
|
950 |
+
} else {
|
951 |
+
$current_order = 'asc';
|
952 |
+
}
|
953 |
+
|
954 |
+
if (! empty($columns['cb'])) {
|
955 |
+
static $cb_counter = 1;
|
956 |
+
$columns['cb'] = sprintf(
|
957 |
+
'<label class="screen-reader-text" for="cb-select-all-%s">%s</label>
|
958 |
+
<input id="cb-select-all-%s" type="checkbox" />',
|
959 |
+
$cb_counter,
|
960 |
+
__('Select All'),
|
961 |
+
$cb_counter
|
962 |
+
);
|
963 |
+
$cb_counter++;
|
964 |
+
}
|
965 |
+
|
966 |
+
foreach ($columns as $column_key => $column_display_name) {
|
967 |
+
$class = array( 'manage-column', "column-$column_key" );
|
968 |
+
|
969 |
+
$style = '';
|
970 |
+
if (in_array($column_key, $hidden)) {
|
971 |
+
$style = 'display:none;';
|
972 |
+
}
|
973 |
+
|
974 |
+
$style = ' style="' . $style . '"';
|
975 |
+
|
976 |
+
if ('cb' == $column_key) {
|
977 |
+
$class[] = 'check-column';
|
978 |
+
} elseif (in_array($column_key, array( 'posts', 'comments', 'links' ))) {
|
979 |
+
$class[] = 'num';
|
980 |
+
}
|
981 |
+
|
982 |
+
if (isset($sortable[$column_key])) {
|
983 |
+
list( $orderby, $desc_first ) = $sortable[$column_key];
|
984 |
+
|
985 |
+
if ($current_orderby == $orderby) {
|
986 |
+
$order = 'asc' == $current_order ? 'desc' : 'asc';
|
987 |
+
$class[] = 'sorted';
|
988 |
+
$class[] = $current_order;
|
989 |
+
} else {
|
990 |
+
$order = $desc_first ? 'desc' : 'asc';
|
991 |
+
$class[] = 'sortable';
|
992 |
+
$class[] = $desc_first ? 'asc' : 'desc';
|
993 |
+
}
|
994 |
+
|
995 |
+
$column_display_name = sprintf(
|
996 |
+
'<a href="%s"><span>%s</span><span class="sorting-indicator"></span></a>',
|
997 |
+
esc_url(add_query_arg(compact('orderby', 'order'), $current_url)),
|
998 |
+
$column_display_name
|
999 |
+
);
|
1000 |
+
}
|
1001 |
+
|
1002 |
+
$id = $with_id ? "id='$column_key'" : '';
|
1003 |
+
|
1004 |
+
if (!empty($class)) {
|
1005 |
+
$class = "class='" . join(' ', $class) . "'";
|
1006 |
+
}
|
1007 |
+
|
1008 |
+
echo "<th scope='col' $id $class $style>$column_display_name</th>";
|
1009 |
+
}
|
1010 |
+
}
|
1011 |
+
|
1012 |
+
/**
|
1013 |
+
* Display the table
|
1014 |
+
*
|
1015 |
+
* @since 3.1.0
|
1016 |
+
* @access public
|
1017 |
+
*/
|
1018 |
+
public function display()
|
1019 |
+
{
|
1020 |
+
$singular = $this->_args['singular'];
|
1021 |
+
|
1022 |
+
$this->display_tablenav('top');
|
1023 |
|
1024 |
?>
|
1025 |
+
<table class="wp-list-table <?php echo implode(' ', $this->get_table_classes()); ?>">
|
1026 |
+
<thead>
|
1027 |
+
<tr>
|
1028 |
+
<?php $this->print_column_headers(); ?>
|
1029 |
+
</tr>
|
1030 |
+
</thead>
|
1031 |
+
|
1032 |
+
<tbody id="the-list"<?php
|
1033 |
+
if ($singular) {
|
1034 |
+
echo " data-wp-lists='list:$singular'";
|
1035 |
+
} ?>>
|
1036 |
+
<?php $this->display_rows_or_placeholder(); ?>
|
1037 |
+
</tbody>
|
1038 |
+
|
1039 |
+
<tfoot>
|
1040 |
+
<tr>
|
1041 |
+
<?php $this->print_column_headers(false); ?>
|
1042 |
+
</tr>
|
1043 |
+
</tfoot>
|
1044 |
|
1045 |
</table>
|
1046 |
<?php
|
1047 |
+
$this->display_tablenav('bottom');
|
1048 |
+
}
|
1049 |
+
|
1050 |
+
/**
|
1051 |
+
* Get a list of CSS classes for the list table table tag.
|
1052 |
+
*
|
1053 |
+
* @since 3.1.0
|
1054 |
+
* @access protected
|
1055 |
+
*
|
1056 |
+
* @return array List of CSS classes for the table tag.
|
1057 |
+
*/
|
1058 |
+
protected function get_table_classes()
|
1059 |
+
{
|
1060 |
+
return array( 'widefat', 'fixed', 'striped', $this->_args['plural'] );
|
1061 |
+
}
|
1062 |
+
|
1063 |
+
/**
|
1064 |
+
* Generate the table navigation above or below the table
|
1065 |
+
*
|
1066 |
+
* @since 3.1.0
|
1067 |
+
* @access protected
|
1068 |
+
* @param string $which
|
1069 |
+
*/
|
1070 |
+
protected function display_tablenav($which)
|
1071 |
+
{
|
1072 |
+
if ('top' == $which) {
|
1073 |
+
wp_nonce_field('bulk-' . $this->_args['plural']);
|
1074 |
+
}
|
1075 |
?>
|
1076 |
+
<div class="tablenav <?php echo esc_attr($which); ?>">
|
1077 |
|
1078 |
+
<div class="alignleft actions bulkactions">
|
1079 |
+
<?php $this->bulk_actions($which); ?>
|
1080 |
+
</div>
|
1081 |
<?php
|
1082 |
+
$this->extra_tablenav($which);
|
1083 |
+
$this->pagination($which);
|
1084 |
?>
|
1085 |
|
1086 |
+
<br class="clear" />
|
1087 |
+
</div>
|
1088 |
<?php
|
1089 |
+
}
|
1090 |
+
|
1091 |
+
/**
|
1092 |
+
* Extra controls to be displayed between bulk actions and pagination
|
1093 |
+
*
|
1094 |
+
* @since 3.1.0
|
1095 |
+
* @access protected
|
1096 |
+
*
|
1097 |
+
* @param string $which
|
1098 |
+
*/
|
1099 |
+
protected function extra_tablenav($which)
|
1100 |
+
{
|
1101 |
+
}
|
1102 |
+
|
1103 |
+
/**
|
1104 |
+
* Generate the tbody element for the list table.
|
1105 |
+
*
|
1106 |
+
* @since 3.1.0
|
1107 |
+
* @access public
|
1108 |
+
*/
|
1109 |
+
public function display_rows_or_placeholder()
|
1110 |
+
{
|
1111 |
+
if ($this->has_items()) {
|
1112 |
+
$this->display_rows();
|
1113 |
+
} else {
|
1114 |
+
echo '<tr class="no-items"><td class="colspanchange" colspan="' . $this->get_column_count() . '">';
|
1115 |
+
$this->no_items();
|
1116 |
+
echo '</td></tr>';
|
1117 |
+
}
|
1118 |
+
}
|
1119 |
+
|
1120 |
+
/**
|
1121 |
+
* Generate the table rows
|
1122 |
+
*
|
1123 |
+
* @since 3.1.0
|
1124 |
+
* @access public
|
1125 |
+
*/
|
1126 |
+
public function display_rows()
|
1127 |
+
{
|
1128 |
+
foreach ($this->items as $item) {
|
1129 |
+
$this->single_row($item);
|
1130 |
+
}
|
1131 |
+
}
|
1132 |
+
|
1133 |
+
/**
|
1134 |
+
* Generates content for a single row of the table
|
1135 |
+
*
|
1136 |
+
* @since 3.1.0
|
1137 |
+
* @access public
|
1138 |
+
*
|
1139 |
+
* @param object $item The current item
|
1140 |
+
*/
|
1141 |
+
public function single_row($item)
|
1142 |
+
{
|
1143 |
+
echo '<tr>';
|
1144 |
+
$this->single_row_columns($item);
|
1145 |
+
echo '</tr>';
|
1146 |
+
}
|
1147 |
+
|
1148 |
+
protected function column_default($item, $column_name)
|
1149 |
+
{
|
1150 |
+
}
|
1151 |
+
|
1152 |
+
protected function column_cb($item)
|
1153 |
+
{
|
1154 |
+
}
|
1155 |
+
|
1156 |
+
/**
|
1157 |
+
* Generates the columns for a single row of the table
|
1158 |
+
*
|
1159 |
+
* @since 3.1.0
|
1160 |
+
* @access protected
|
1161 |
+
*
|
1162 |
+
* @param object $item The current item
|
1163 |
+
*/
|
1164 |
+
protected function single_row_columns($item)
|
1165 |
+
{
|
1166 |
+
list( $columns, $hidden ) = $this->get_column_info();
|
1167 |
+
|
1168 |
+
foreach ($columns as $column_name => $column_display_name) {
|
1169 |
+
$class = "class='$column_name column-$column_name'";
|
1170 |
+
|
1171 |
+
$style = '';
|
1172 |
+
if (in_array($column_name, $hidden)) {
|
1173 |
+
$style = ' style="display:none;"';
|
1174 |
+
}
|
1175 |
+
|
1176 |
+
$attributes = "$class$style";
|
1177 |
+
|
1178 |
+
if ('cb' == $column_name) {
|
1179 |
+
echo '<th scope="row" class="check-column">';
|
1180 |
+
echo $this->column_cb($item);
|
1181 |
+
echo '</th>';
|
1182 |
+
} elseif (method_exists($this, 'column_' . $column_name)) {
|
1183 |
+
echo "<td $attributes>";
|
1184 |
+
echo call_user_func(array( $this, 'column_' . $column_name ), $item);
|
1185 |
+
echo "</td>";
|
1186 |
+
} else {
|
1187 |
+
echo "<td $attributes>";
|
1188 |
+
echo $this->column_default($item, $column_name);
|
1189 |
+
echo "</td>";
|
1190 |
+
}
|
1191 |
+
}
|
1192 |
+
}
|
1193 |
+
|
1194 |
+
/**
|
1195 |
+
* Handle an incoming ajax request (called from admin-ajax.php)
|
1196 |
+
*
|
1197 |
+
* @since 3.1.0
|
1198 |
+
* @access public
|
1199 |
+
*/
|
1200 |
+
public function ajax_response()
|
1201 |
+
{
|
1202 |
+
$this->prepare_items();
|
1203 |
+
|
1204 |
+
ob_start();
|
1205 |
+
if (! empty($_REQUEST['no_placeholder'])) {
|
1206 |
+
$this->display_rows();
|
1207 |
+
} else {
|
1208 |
+
$this->display_rows_or_placeholder();
|
1209 |
+
}
|
1210 |
+
|
1211 |
+
$rows = ob_get_clean();
|
1212 |
+
|
1213 |
+
$response = array( 'rows' => $rows );
|
1214 |
+
|
1215 |
+
if (isset($this->_pagination_args['total_items'])) {
|
1216 |
+
$response['total_items_i18n'] = sprintf(
|
1217 |
+
_n('1 item', '%s items', $this->_pagination_args['total_items']),
|
1218 |
+
number_format_i18n($this->_pagination_args['total_items'])
|
1219 |
+
);
|
1220 |
+
}
|
1221 |
+
if (isset($this->_pagination_args['total_pages'])) {
|
1222 |
+
$response['total_pages'] = $this->_pagination_args['total_pages'];
|
1223 |
+
$response['total_pages_i18n'] = number_format_i18n($this->_pagination_args['total_pages']);
|
1224 |
+
}
|
1225 |
+
|
1226 |
+
die(wp_json_encode($response));
|
1227 |
+
}
|
1228 |
+
|
1229 |
+
/**
|
1230 |
+
* Send required variables to JavaScript land
|
1231 |
+
*
|
1232 |
+
* @access public
|
1233 |
+
*/
|
1234 |
+
public function _js_vars()
|
1235 |
+
{
|
1236 |
+
$args = array(
|
1237 |
+
'class' => get_class($this),
|
1238 |
+
'screen' => array(
|
1239 |
+
'id' => $this->screen->id,
|
1240 |
+
'base' => $this->screen->base,
|
1241 |
+
)
|
1242 |
+
);
|
1243 |
+
|
1244 |
+
printf("<script type='text/javascript'>list_args = %s;</script>\n", wp_json_encode($args));
|
1245 |
+
}
|
1246 |
}
|
Unbounce-Page.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: Unbounce Landing Pages
|
4 |
Plugin URI: http://unbounce.com
|
5 |
Description: Unbounce is the most powerful standalone landing page builder available.
|
6 |
-
Version: 1.0.
|
7 |
Author: Unbounce
|
8 |
Author URI: http://unbounce.com
|
9 |
License: GPLv2
|
@@ -21,273 +21,308 @@ require_once dirname(__FILE__) . '/UBPageTable.php';
|
|
21 |
require_once dirname(__FILE__) . '/UBEvents.php';
|
22 |
require_once dirname(__FILE__) . '/UBTemplate.php';
|
23 |
|
24 |
-
register_activation_hook(__FILE__, function() {
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
});
|
46 |
|
47 |
-
register_deactivation_hook(__FILE__, function() {
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
});
|
52 |
|
53 |
-
add_action('init', function() {
|
54 |
-
|
55 |
-
|
56 |
-
$domain = UBConfig::domain();
|
57 |
|
58 |
-
|
59 |
-
UBLogger::info("Domain: $domain has not been authorized");
|
60 |
-
return;
|
61 |
-
}
|
62 |
|
63 |
-
|
|
|
|
|
|
|
64 |
|
65 |
-
|
66 |
-
$http_method = UBUtil::array_fetch($_SERVER, 'REQUEST_METHOD');
|
67 |
-
$referer = UBUtil::array_fetch($_SERVER, 'HTTP_REFERER');
|
68 |
-
$user_agent = UBUtil::array_fetch($_SERVER, 'HTTP_USER_AGENT');
|
69 |
-
$protocol = UBHTTP::determine_protocol($_SERVER, is_ssl());
|
70 |
-
$current_path = UBUtil::array_fetch($_SERVER, 'REQUEST_URI');
|
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 |
-
define('DONOTCACHEPAGE', true);
|
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 |
}, UBConfig::int_min());
|
167 |
|
168 |
-
add_action('admin_init', function() {
|
169 |
-
|
170 |
|
171 |
// Disable incompatible scripts
|
172 |
|
173 |
// WPML
|
174 |
-
|
175 |
|
176 |
// Enqueue our own scripts
|
177 |
|
178 |
// Main page
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
|
188 |
// Diagnostics page
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
|
|
|
|
|
|
|
|
194 |
// Re-enable incompatible scripts
|
195 |
|
196 |
// WPML
|
197 |
-
|
198 |
|
199 |
-
|
200 |
-
|
|
|
|
|
201 |
}, 0);
|
202 |
|
203 |
-
add_action('admin_menu', function() {
|
204 |
// Main admin page
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
|
|
|
|
|
|
|
|
220 |
|
221 |
// Diagnostics page
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
|
226 |
-
|
227 |
-
|
|
|
228 |
'checks' => UBDiagnostics::checks($domain, $domain_info),
|
229 |
'details' => UBDiagnostics::details($domain, $domain_info),
|
230 |
'domain' => $domain,
|
231 |
'permalink_url' => admin_url('options-permalink.php'),
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
return $domain == UBConfig::domain();
|
247 |
-
});
|
248 |
-
|
249 |
-
if($domains && is_array($domains)) {
|
250 |
-
$authorization = 'success';
|
251 |
-
$has_authorized = get_option(UBConfig::UB_HAS_AUTHORIZED_KEY, false);
|
252 |
-
|
253 |
-
$data = array(
|
254 |
-
'domain_name' => UBConfig::domain(),
|
255 |
-
'first_authorization' => !$has_authorized,
|
256 |
-
'user_id' => UBUtil::array_fetch($_POST, 'user_id', ''),
|
257 |
-
'client_id' => UBUtil::array_fetch($_POST, 'client_id', ''),
|
258 |
-
'domain_id' => UBUtil::array_fetch($_POST, 'domain_id', ''),
|
259 |
);
|
|
|
260 |
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
265 |
} else {
|
266 |
-
|
267 |
}
|
268 |
-
UBHTTP::send_event_to_events_gateway(UBConfig::remote_events_url(), $event);
|
269 |
-
} else {
|
270 |
-
$authorization = 'failure';
|
271 |
-
}
|
272 |
|
273 |
-
|
274 |
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
});
|
279 |
|
280 |
-
add_action('admin_post_flush_unbounce_pages', function() {
|
281 |
-
|
282 |
// Expire cache and redirect
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
});
|
288 |
|
289 |
-
add_action('shutdown', function() {
|
290 |
-
|
291 |
});
|
292 |
-
|
293 |
-
?>
|
3 |
Plugin Name: Unbounce Landing Pages
|
4 |
Plugin URI: http://unbounce.com
|
5 |
Description: Unbounce is the most powerful standalone landing page builder available.
|
6 |
+
Version: 1.0.32
|
7 |
Author: Unbounce
|
8 |
Author URI: http://unbounce.com
|
9 |
License: GPLv2
|
21 |
require_once dirname(__FILE__) . '/UBEvents.php';
|
22 |
require_once dirname(__FILE__) . '/UBTemplate.php';
|
23 |
|
24 |
+
register_activation_hook(__FILE__, function () {
|
25 |
+
add_option(UBConfig::UB_ROUTES_CACHE_KEY, array());
|
26 |
+
add_option(UBConfig::UB_REMOTE_DEBUG_KEY, 0);
|
27 |
+
add_option(
|
28 |
+
UBConfig::UB_PAGE_SERVER_DOMAIN_KEY,
|
29 |
+
UBConfig::default_page_server_domain()
|
30 |
+
);
|
31 |
+
add_option(
|
32 |
+
UBConfig::UB_REMOTE_LOG_URL_KEY,
|
33 |
+
UBConfig::default_remote_log_url()
|
34 |
+
);
|
35 |
+
add_option(
|
36 |
+
UBConfig::UB_API_URL_KEY,
|
37 |
+
UBConfig::default_api_url()
|
38 |
+
);
|
39 |
+
add_option(
|
40 |
+
UBConfig::UB_API_CLIENT_ID_KEY,
|
41 |
+
UBConfig::default_api_client_id()
|
42 |
+
);
|
43 |
+
add_option(
|
44 |
+
UBConfig::UB_AUTHORIZED_DOMAINS_KEY,
|
45 |
+
UBConfig::default_authorized_domains()
|
46 |
+
);
|
47 |
+
add_option(UBConfig::UB_HAS_AUTHORIZED_KEY, '');
|
48 |
+
add_option(
|
49 |
+
UBConfig::UB_REMOTE_EVENTS_URL_KEY,
|
50 |
+
UBConfig::default_remote_events_url()
|
51 |
+
);
|
52 |
+
add_option(UBConfig::UB_USER_ID_KEY, '');
|
53 |
+
add_option(UBConfig::UB_DOMAIN_ID_KEY, '');
|
54 |
+
add_option(UBConfig::UB_CLIENT_ID_KEY, '');
|
55 |
+
add_option(UBConfig::UB_PROXY_ERROR_MESSAGE_KEY, '');
|
56 |
+
add_option(UBConfig::UB_ALLOW_PUBLIC_ADDRESS_X_FORWARDED_FOR, 0);
|
57 |
});
|
58 |
|
59 |
+
register_deactivation_hook(__FILE__, function () {
|
60 |
+
foreach (UBConfig::ub_option_keys() as $key) {
|
61 |
+
delete_option($key);
|
62 |
+
}
|
63 |
});
|
64 |
|
65 |
+
add_action('init', function () {
|
66 |
+
UBLogger::setup_logger();
|
|
|
|
|
67 |
|
68 |
+
$domain = UBConfig::domain();
|
|
|
|
|
|
|
69 |
|
70 |
+
if (!UBConfig::is_authorized_domain($domain)) {
|
71 |
+
UBLogger::info("Domain: $domain has not been authorized");
|
72 |
+
return;
|
73 |
+
}
|
74 |
|
75 |
+
$start = microtime(true);
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
+
$ps_domain = UBConfig::page_server_domain();
|
78 |
+
$http_method = UBUtil::array_fetch($_SERVER, 'REQUEST_METHOD');
|
79 |
+
$referer = UBUtil::array_fetch($_SERVER, 'HTTP_REFERER');
|
80 |
+
$user_agent = UBUtil::array_fetch($_SERVER, 'HTTP_USER_AGENT');
|
81 |
+
$protocol = UBHTTP::determine_protocol($_SERVER, is_ssl());
|
82 |
+
$current_path = UBUtil::array_fetch($_SERVER, 'REQUEST_URI');
|
83 |
|
84 |
+
$raw_url = $protocol . $ps_domain . $current_path;
|
85 |
+
$current_url = $protocol . $domain . $current_path;
|
86 |
|
87 |
+
$domain_info = UBConfig::read_unbounce_domain_info($domain, false);
|
88 |
+
$proxyable_url_set = UBUtil::array_fetch($domain_info, 'proxyable_url_set', array());
|
89 |
+
|
90 |
+
UBLogger::debug_var('ps_domain', $ps_domain);
|
91 |
+
UBLogger::debug_var('http_method', $http_method);
|
92 |
+
UBLogger::debug_var('referer', $referer);
|
93 |
+
UBLogger::debug_var('user_agent', $user_agent);
|
94 |
+
UBLogger::debug_var('protocol', $protocol);
|
95 |
+
UBLogger::debug_var('domain', $domain);
|
96 |
+
UBLogger::debug_var('current_path', $current_path);
|
97 |
+
UBLogger::debug_var('raw_url', $raw_url);
|
98 |
+
UBLogger::debug_var('current_url', $current_url);
|
99 |
|
100 |
////////////////////
|
101 |
|
102 |
+
$url_purpose = UBHTTP::get_url_purpose(
|
103 |
+
$proxyable_url_set,
|
104 |
+
$http_method,
|
105 |
+
$current_url
|
106 |
+
);
|
107 |
+
if ($url_purpose == null) {
|
108 |
+
UBLogger::debug("ignoring request to URL " . $current_url);
|
109 |
+
} elseif (is_user_logged_in() && UBUtil::is_wordpress_preview($_GET)) {
|
110 |
+
UBLogger::debug("Serving Wordpress Preview instead of landing page on root");
|
111 |
+
} elseif ($url_purpose == 'HealthCheck') {
|
112 |
+
if (UBConfig::domain_with_port() !== UBUtil::array_fetch($_SERVER, 'HTTP_HOST')) {
|
113 |
+
http_response_code(412);
|
114 |
+
}
|
115 |
+
|
116 |
+
header('Content-Type: application/json');
|
117 |
+
$version = UBConfig::UB_VERSION;
|
118 |
+
echo "{\"ub_wordpress\":{\"version\":\"$version\"}}";
|
119 |
+
exit(0);
|
120 |
+
} else {
|
121 |
+
// Disable caching plugins. This should take care of:
|
122 |
+
// - W3 Total Cache
|
123 |
+
// - WP Super Cache
|
124 |
+
// - ZenCache (Previously QuickCache)
|
125 |
+
if (!defined('DONOTCACHEPAGE')) {
|
126 |
+
define('DONOTCACHEPAGE', true);
|
127 |
+
}
|
|
|
|
|
128 |
|
129 |
+
if (!defined('DONOTCDN')) {
|
130 |
+
define('DONOTCDN', true);
|
131 |
+
}
|
132 |
|
133 |
+
if (!defined('DONOTCACHEDB')) {
|
134 |
+
define('DONOTCACHEDB', true);
|
135 |
+
}
|
136 |
|
137 |
+
if (!defined('DONOTMINIFY')) {
|
138 |
+
define('DONOTMINIFY', true);
|
139 |
+
}
|
140 |
|
141 |
+
if (!defined('DONOTCACHEOBJECT')) {
|
142 |
+
define('DONOTCACHEOBJECT', true);
|
143 |
+
}
|
144 |
|
145 |
+
UBLogger::debug("perform ''" . $url_purpose . "'' on received URL " . $current_url);
|
146 |
|
147 |
+
$cookies_to_forward = UBUtil::array_select_by_key(
|
148 |
+
$_COOKIE,
|
149 |
+
array('ubvs', 'ubpv', 'ubvt', 'hubspotutk')
|
150 |
+
);
|
151 |
|
152 |
+
$cookie_string = UBHTTP::cookie_string_from_array($cookies_to_forward);
|
153 |
|
154 |
+
$all_headers = getallheaders();
|
155 |
+
$all_headers['Host'] = $domain;
|
156 |
|
157 |
+
// Make sure we don't get cached by Wordpress hosts like WPEngine
|
158 |
+
header('Cache-Control: max-age=0; private');
|
159 |
|
160 |
+
list($success, $message) = UBHTTP::stream_request(
|
161 |
+
$http_method,
|
162 |
+
$raw_url,
|
163 |
+
$cookie_string,
|
164 |
+
$all_headers,
|
165 |
+
$user_agent
|
166 |
+
);
|
167 |
|
168 |
+
if ($success === false) {
|
169 |
+
update_option(UBConfig::UB_PROXY_ERROR_MESSAGE_KEY, $message);
|
170 |
+
}
|
171 |
|
172 |
+
$end = microtime(true);
|
173 |
+
$time_taken = ($end - $start) * 1000;
|
174 |
|
175 |
+
UBLogger::debug_var('time_taken', $time_taken);
|
176 |
+
UBLogger::debug("proxying for $current_url done successfuly -- took $time_taken ms");
|
177 |
|
178 |
+
exit(0);
|
179 |
+
}
|
180 |
}, UBConfig::int_min());
|
181 |
|
182 |
+
add_action('admin_init', function () {
|
183 |
+
UBUtil::clear_flash();
|
184 |
|
185 |
// Disable incompatible scripts
|
186 |
|
187 |
// WPML
|
188 |
+
wp_dequeue_script('installer-admin');
|
189 |
|
190 |
// Enqueue our own scripts
|
191 |
|
192 |
// Main page
|
193 |
+
wp_enqueue_script(
|
194 |
+
'ub-rx',
|
195 |
+
plugins_url('js/rx.lite.compat.min.js', __FILE__)
|
196 |
+
);
|
197 |
+
wp_enqueue_script(
|
198 |
+
'set-unbounce-domains-js',
|
199 |
+
plugins_url('js/set-unbounce-domains.js', __FILE__),
|
200 |
+
array('jquery', 'ub-rx')
|
201 |
+
);
|
202 |
+
wp_enqueue_script(
|
203 |
+
'unbounce-page-js',
|
204 |
+
plugins_url('js/unbounce-page.js', __FILE__),
|
205 |
+
array('jquery')
|
206 |
+
);
|
207 |
|
208 |
// Diagnostics page
|
209 |
+
wp_enqueue_script(
|
210 |
+
'ub-clipboard-js',
|
211 |
+
plugins_url('js/clipboard.min.js', __FILE__)
|
212 |
+
);
|
213 |
+
wp_enqueue_script(
|
214 |
+
'unbounce-diagnostics-js',
|
215 |
+
plugins_url('js/unbounce-diagnostics.js', __FILE__),
|
216 |
+
array('jquery', 'ub-clipboard-js')
|
217 |
+
);
|
218 |
// Re-enable incompatible scripts
|
219 |
|
220 |
// WPML
|
221 |
+
wp_enqueue_script('installer-admin');
|
222 |
|
223 |
+
wp_enqueue_style(
|
224 |
+
'unbounce-pages-css',
|
225 |
+
plugins_url('css/unbounce-pages.css', __FILE__)
|
226 |
+
);
|
227 |
}, 0);
|
228 |
|
229 |
+
add_action('admin_menu', function () {
|
230 |
// Main admin page
|
231 |
+
$print_admin_panel = function () {
|
232 |
+
$domain = UBConfig::domain();
|
233 |
+
$domain_info = UBConfig::read_unbounce_domain_info($domain, false);
|
234 |
+
|
235 |
+
echo UBTemplate::render(
|
236 |
+
'main',
|
237 |
+
array('domain_info' => $domain_info,
|
238 |
+
'domain' => $domain)
|
239 |
+
);
|
240 |
+
};
|
241 |
+
|
242 |
+
add_menu_page(
|
243 |
+
'Unbounce Pages',
|
244 |
+
'Unbounce Pages',
|
245 |
+
'manage_options',
|
246 |
+
'unbounce-pages',
|
247 |
+
$print_admin_panel,
|
248 |
+
UBIcon::base64_encoded_svg()
|
249 |
+
);
|
250 |
|
251 |
// Diagnostics page
|
252 |
+
$print_diagnostics_panel = function () {
|
253 |
+
$domain = UBConfig::domain();
|
254 |
+
$domain_info = UBConfig::read_unbounce_domain_info($domain, false);
|
255 |
|
256 |
+
echo UBTemplate::render(
|
257 |
+
'diagnostics',
|
258 |
+
array('img_url' => plugins_url('img/unbounce-logo-blue.png', __FILE__),
|
259 |
'checks' => UBDiagnostics::checks($domain, $domain_info),
|
260 |
'details' => UBDiagnostics::details($domain, $domain_info),
|
261 |
'domain' => $domain,
|
262 |
'permalink_url' => admin_url('options-permalink.php'),
|
263 |
+
'curl_error_message' => UBUtil::array_fetch(
|
264 |
+
$domain_info,
|
265 |
+
'failure_message'
|
266 |
+
))
|
267 |
+
);
|
268 |
+
};
|
269 |
+
|
270 |
+
add_submenu_page(
|
271 |
+
'unbounce-pages',
|
272 |
+
'Unbounce Pages Diagnostics',
|
273 |
+
'Unbounce Pages Diagnostics',
|
274 |
+
'manage_options',
|
275 |
+
'unbounce-pages-diagnostics',
|
276 |
+
$print_diagnostics_panel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
277 |
);
|
278 |
+
});
|
279 |
|
280 |
+
add_action('admin_post_set_unbounce_domains', function () {
|
281 |
+
$domains_list = UBUtil::array_fetch($_POST, 'domains', '');
|
282 |
+
$domains = array_filter(explode(',', $domains_list), function ($domain) {
|
283 |
+
return $domain == UBConfig::domain();
|
284 |
+
});
|
285 |
+
|
286 |
+
if ($domains && is_array($domains)) {
|
287 |
+
$authorization = 'success';
|
288 |
+
$has_authorized = get_option(UBConfig::UB_HAS_AUTHORIZED_KEY, false);
|
289 |
+
|
290 |
+
$data = array(
|
291 |
+
'domain_name' => UBConfig::domain(),
|
292 |
+
'first_authorization' => !$has_authorized,
|
293 |
+
'user_id' => UBUtil::array_fetch($_POST, 'user_id', ''),
|
294 |
+
'client_id' => UBUtil::array_fetch($_POST, 'client_id', ''),
|
295 |
+
'domain_id' => UBUtil::array_fetch($_POST, 'domain_id', ''),
|
296 |
+
);
|
297 |
+
|
298 |
+
UBConfig::update_authorization_options($domains, $data);
|
299 |
+
|
300 |
+
if (UBConfig::is_authorized_domain(UBConfig::domain())) {
|
301 |
+
$event = UBEvents::successful_authorization_event($data);
|
302 |
+
} else {
|
303 |
+
$event = UBEvents::failed_authorization_event($data);
|
304 |
+
}
|
305 |
+
UBHTTP::send_event_to_events_gateway(UBConfig::remote_events_url(), $event);
|
306 |
} else {
|
307 |
+
$authorization = 'failure';
|
308 |
}
|
|
|
|
|
|
|
|
|
309 |
|
310 |
+
UBUtil::set_flash('authorization', $authorization);
|
311 |
|
312 |
+
status_header(301);
|
313 |
+
$location = admin_url('admin.php?page=unbounce-pages');
|
314 |
+
header("Location: $location");
|
315 |
});
|
316 |
|
317 |
+
add_action('admin_post_flush_unbounce_pages', function () {
|
318 |
+
$domain = UBConfig::domain();
|
319 |
// Expire cache and redirect
|
320 |
+
$_domain_info = UBConfig::read_unbounce_domain_info($domain, true);
|
321 |
+
status_header(301);
|
322 |
+
$location = admin_url('admin.php?page=unbounce-pages');
|
323 |
+
header("Location: $location");
|
324 |
});
|
325 |
|
326 |
+
add_action('shutdown', function () {
|
327 |
+
UBLogger::upload_logs_to_unbounce(UBConfig::remote_log_url());
|
328 |
});
|
|
|
|
readme.txt
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
Contributors: unbouncewordpress
|
3 |
Tags: Unbounce, AB testing, A/B testing, split testing, CRO, conversion optimization, wordpress landing page, wp landing pages, splash pages, landing pages, squeeze pages, lead gen, lead generation, email list, responsive landing pages, templates, inbound marketing, ppc, analytics
|
4 |
Requires at least: 4.1.5
|
5 |
-
Tested up to: 4.
|
6 |
-
Stable tag: 1.0.
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
@@ -94,6 +94,18 @@ You should add a rule to your cache to avoid caching Unbounce Pages which have t
|
|
94 |
|
95 |
== Changelog ==
|
96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
= 1.0.28 =
|
98 |
* Disables the unbounce plugin when editing drafts as a logged in user.
|
99 |
|
2 |
Contributors: unbouncewordpress
|
3 |
Tags: Unbounce, AB testing, A/B testing, split testing, CRO, conversion optimization, wordpress landing page, wp landing pages, splash pages, landing pages, squeeze pages, lead gen, lead generation, email list, responsive landing pages, templates, inbound marketing, ppc, analytics
|
4 |
Requires at least: 4.1.5
|
5 |
+
Tested up to: 4.7.2
|
6 |
+
Stable tag: 1.0.32
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
94 |
|
95 |
== Changelog ==
|
96 |
|
97 |
+
= 1.0.32 =
|
98 |
+
* Fix support for PHP 5.3
|
99 |
+
|
100 |
+
= 1.0.31 =
|
101 |
+
* Un-released 1.0.30 (same as 1.0.29)
|
102 |
+
|
103 |
+
= 1.0.30 =
|
104 |
+
* Minor bug fix
|
105 |
+
|
106 |
+
= 1.0.29 =
|
107 |
+
* Minor bug fix
|
108 |
+
|
109 |
= 1.0.28 =
|
110 |
* Disables the unbounce plugin when editing drafts as a logged in user.
|
111 |
|
templates/authorize_button.php
CHANGED
@@ -3,22 +3,24 @@
|
|
3 |
<input type="hidden" name="user_id" />
|
4 |
<input type="hidden" name="domain_id" />
|
5 |
<input type="hidden" name="client_id" />
|
6 |
-
|
7 |
<?php echo $outer_text; ?>
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
17 |
'data-set-domains-url' => admin_url('admin-post.php?action=set_unbounce_domains'),
|
18 |
'data-redirect-uri' => admin_url('admin.php?page=unbounce-pages'),
|
19 |
'data-api-url' => UBConfig::api_url(),
|
20 |
'data-api-client-id' => UBConfig::api_client_id(),
|
21 |
'data-wordpress-domain-name' => $domain,
|
22 |
'style' => $style,
|
23 |
-
|
|
|
24 |
</form>
|
3 |
<input type="hidden" name="user_id" />
|
4 |
<input type="hidden" name="domain_id" />
|
5 |
<input type="hidden" name="client_id" />
|
6 |
+
<?php if (isset($outer_text)) { ?>
|
7 |
<?php echo $outer_text; ?>
|
8 |
+
<?php } ?>
|
9 |
+
<?php $style = isset($outer_text) ? 'vertical-align: baseline' : ''; ?>
|
10 |
+
<?php
|
11 |
|
12 |
+
echo get_submit_button(
|
13 |
+
$text,
|
14 |
+
$is_primary ? 'primary' : 'secondary',
|
15 |
+
'set-unbounce-domains',
|
16 |
+
$wrap_in_p,
|
17 |
+
array(
|
18 |
'data-set-domains-url' => admin_url('admin-post.php?action=set_unbounce_domains'),
|
19 |
'data-redirect-uri' => admin_url('admin.php?page=unbounce-pages'),
|
20 |
'data-api-url' => UBConfig::api_url(),
|
21 |
'data-api-client-id' => UBConfig::api_client_id(),
|
22 |
'data-wordpress-domain-name' => $domain,
|
23 |
'style' => $style,
|
24 |
+
)
|
25 |
+
); ?>
|
26 |
</form>
|
templates/diagnostics.php
CHANGED
@@ -1,70 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<div class="ub-plugin-wrapper">
|
2 |
<img class="ub-logo" src="<?php echo $img_url; ?>" />
|
3 |
<h1 class="ub-unbounce-pages-heading">Unbounce Pages Diagnostics</h1>
|
4 |
<a href="<?php echo admin_url('admin.php?page=unbounce-pages'); ?>">Main Plugin Page</a>
|
5 |
<br/>
|
6 |
<ul class="ub-diagnostics-checks">
|
7 |
-
|
8 |
<?php $css_class = ($success ? 'dashicons-yes' : 'dashicons-no-alt'); ?>
|
9 |
<li>
|
10 |
<span class='dashicons <?php echo $css_class; ?>'></span>
|
11 |
-
<?php
|
12 |
-
|
13 |
-
<?php
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
By default WordPress uses web URLs which have question marks
|
24 |
-
and lots of numbers in them; however, this default structure
|
25 |
-
will not work with the Unbounce Plugin. Please update your
|
26 |
-
<a href="<?php echo $permalink_url; ?>">WordPress Permalink
|
27 |
-
Structure</a> and change to anything other than the default
|
28 |
-
WordPress setting.
|
29 |
-
</p>
|
30 |
-
<?php break; ?>
|
31 |
-
<?php case 'Domain is Authorized': ?>
|
32 |
-
<p class="ub-diagnostics-check-description">
|
33 |
-
Your Domain (<?php echo $domain ?>) needs to be added to your
|
34 |
-
Unbounce account, please return to the main plugin page, select
|
35 |
-
"Add My Domain In Unbounce". After adding your domain in
|
36 |
-
Unbounce, return to the main plugin page and select the "Update
|
37 |
-
WordPress Enabled Domains".
|
38 |
-
</p>
|
39 |
-
<?php break; ?>
|
40 |
-
<?php case 'Can Fetch Page Listing': ?>
|
41 |
-
<p class="ub-diagnostics-check-description">
|
42 |
-
We are unable to fetch the page listing from Unbounce, please
|
43 |
-
contact your hosting provider or IT professional to ensure Curl
|
44 |
-
Supported is installed and enabled.
|
45 |
-
</p>
|
46 |
-
<?php if ($curl_error_message) { ?>
|
47 |
-
<p class="ub-diagnostics-check-description"><?php echo $curl_error_message; ?></p>
|
48 |
-
<?php } ?>
|
49 |
-
<?php break; ?>
|
50 |
-
<?php case 'Supported PHP Version': ?>
|
51 |
-
<p class="ub-diagnostics-check-description">
|
52 |
-
The Unbounce Pages plugin is supported when using PHP version
|
53 |
-
5.3 or higher, please contact your hosting provider or IT
|
54 |
-
professional and update to a supported version.
|
55 |
-
</p>
|
56 |
-
<?php break; ?>
|
57 |
-
<?php case 'Supported Wordpress Version': ?>
|
58 |
-
<p class="ub-diagnostics-check-description">
|
59 |
-
The Unbounce Pages plugin is supported on WordPress versions 4.0
|
60 |
-
and higher, please contact your hosting provider or IT
|
61 |
-
professional and update to a supported version.
|
62 |
-
</p>
|
63 |
-
<?php break; ?>
|
64 |
-
<?php } ?>
|
65 |
-
<?php } ?>
|
66 |
</li>
|
67 |
-
|
68 |
</ul>
|
69 |
|
70 |
<h2>Details</h2>
|
@@ -75,16 +59,24 @@
|
|
75 |
please also provide details on your hosting provider.
|
76 |
</p>
|
77 |
<textarea id="ub-diagnostics-text" rows="10" cols="100">
|
78 |
-
|
79 |
-
|
80 |
-
|
|
|
|
|
|
|
|
|
81 |
</textarea>
|
82 |
<div id="ub-diagnostics-copy-result"></div>
|
83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
|
85 |
-
|
86 |
-
'primary',
|
87 |
-
'ub-diagnostics-copy',
|
88 |
-
false,
|
89 |
-
array('data-clipboard-target' => '#ub-diagnostics-text')); ?>
|
90 |
</div>
|
1 |
+
<?php
|
2 |
+
|
3 |
+
$diagnostic_descriptions = array(
|
4 |
+
'Curl Support' => 'Curl is not currently enabled, please contact your hosting provider
|
5 |
+
or IT professional to enable Curl support.',
|
6 |
+
'Permalink Structure' => "By default WordPress uses web URLs which have question marks
|
7 |
+
and lots of numbers in them; however, this default structure
|
8 |
+
will not work with the Unbounce Plugin. Please update your
|
9 |
+
<a href=\"{$permalink_url}\">WordPress Permalink
|
10 |
+
Structure</a> and change to anything other than the default
|
11 |
+
WordPress setting.",
|
12 |
+
'Domain is Authorized' => "Your Domain ({$domain}) needs to be added to your
|
13 |
+
Unbounce account, please return to the main plugin page, select
|
14 |
+
\"Add My Domain In Unbounce\". After adding your domain in
|
15 |
+
Unbounce, return to the main plugin page and select the \"Update
|
16 |
+
WordPress Enabled Domains\".",
|
17 |
+
'Can Fetch Page Listing' => 'We are unable to fetch the page listing from Unbounce, please
|
18 |
+
contact your hosting provider or IT professional to ensure Curl
|
19 |
+
Supported is installed and enabled.',
|
20 |
+
'Supported PHP Version' => 'The Unbounce Pages plugin is supported when using PHP version
|
21 |
+
5.3 or higher, please contact your hosting provider or IT
|
22 |
+
professional and update to a supported version.',
|
23 |
+
'Supported Wordpress Version' => 'The Unbounce Pages plugin is supported on WordPress versions 4.0
|
24 |
+
and higher, please contact your hosting provider or IT
|
25 |
+
professional and update to a supported version.',
|
26 |
+
);
|
27 |
+
|
28 |
+
?>
|
29 |
<div class="ub-plugin-wrapper">
|
30 |
<img class="ub-logo" src="<?php echo $img_url; ?>" />
|
31 |
<h1 class="ub-unbounce-pages-heading">Unbounce Pages Diagnostics</h1>
|
32 |
<a href="<?php echo admin_url('admin.php?page=unbounce-pages'); ?>">Main Plugin Page</a>
|
33 |
<br/>
|
34 |
<ul class="ub-diagnostics-checks">
|
35 |
+
<?php foreach ($checks as $check => $success) : ?>
|
36 |
<?php $css_class = ($success ? 'dashicons-yes' : 'dashicons-no-alt'); ?>
|
37 |
<li>
|
38 |
<span class='dashicons <?php echo $css_class; ?>'></span>
|
39 |
+
<?php
|
40 |
+
echo $check;
|
|
|
41 |
|
42 |
+
if (!$success) {
|
43 |
+
foreach ($diagnostic_descriptions as $title => $description) {
|
44 |
+
if ($title == $check) {
|
45 |
+
echo '<p class="ub-diagnostics-check-description">' . $description . '</p>';
|
46 |
+
}
|
47 |
+
}
|
48 |
+
}
|
49 |
+
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
</li>
|
51 |
+
<?php endforeach; ?>
|
52 |
</ul>
|
53 |
|
54 |
<h2>Details</h2>
|
59 |
please also provide details on your hosting provider.
|
60 |
</p>
|
61 |
<textarea id="ub-diagnostics-text" rows="10" cols="100">
|
62 |
+
<?php
|
63 |
+
|
64 |
+
foreach ($details as $detail_name => $detail) {
|
65 |
+
echo "[${detail_name}] ${detail}\n";
|
66 |
+
}
|
67 |
+
|
68 |
+
?>
|
69 |
</textarea>
|
70 |
<div id="ub-diagnostics-copy-result"></div>
|
71 |
+
<?php
|
72 |
+
|
73 |
+
echo get_submit_button(
|
74 |
+
'Copy to Clipboard',
|
75 |
+
'primary',
|
76 |
+
'ub-diagnostics-copy',
|
77 |
+
false,
|
78 |
+
array('data-clipboard-target' => '#ub-diagnostics-text')
|
79 |
+
);
|
80 |
|
81 |
+
?>
|
|
|
|
|
|
|
|
|
82 |
</div>
|
templates/main.php
CHANGED
@@ -3,42 +3,44 @@
|
|
3 |
echo '<div class="ub-plugin-wrapper>';
|
4 |
|
5 |
$is_authorized = UBConfig::is_authorized_domain($domain);
|
6 |
-
$diagnostics_failed = in_array(false, UBDiagnostics::checks($domain, $domain_info));
|
7 |
|
8 |
-
echo UBTemplate::render(
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
15 |
|
16 |
if ($is_authorized) {
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
22 |
'domain' => $domain,
|
23 |
'proxyable_url_set' => $proxyable_url_set,
|
24 |
'last_refreshed' => $last_refreshed,
|
25 |
-
|
|
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
} else {
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
}
|
42 |
|
43 |
echo '</div>';
|
44 |
-
?>
|
3 |
echo '<div class="ub-plugin-wrapper>';
|
4 |
|
5 |
$is_authorized = UBConfig::is_authorized_domain($domain);
|
|
|
6 |
|
7 |
+
echo UBTemplate::render(
|
8 |
+
'main_header',
|
9 |
+
array(
|
10 |
+
'img_url' => plugins_url('img/unbounce-logo-blue.png', __FILE__),
|
11 |
+
'is_authorized' => $is_authorized,
|
12 |
+
'authorization' => UBUtil::get_flash('authorization'),
|
13 |
+
'show_warning' => UBDiagnostics::should_show_warning($domain, $domain_info)
|
14 |
+
)
|
15 |
+
);
|
16 |
|
17 |
if ($is_authorized) {
|
18 |
+
$proxyable_url_set = UBUtil::array_fetch($domain_info, 'proxyable_url_set', array());
|
19 |
+
$proxyable_url_set_fetched_at = UBUtil::array_fetch($domain_info, 'proxyable_url_set_fetched_at');
|
20 |
+
$last_refreshed = UBUtil::time_ago($proxyable_url_set_fetched_at);
|
21 |
+
echo UBTemplate::render(
|
22 |
+
'main_authorized',
|
23 |
+
array(
|
24 |
'domain' => $domain,
|
25 |
'proxyable_url_set' => $proxyable_url_set,
|
26 |
'last_refreshed' => $last_refreshed,
|
27 |
+
)
|
28 |
+
);
|
29 |
|
30 |
+
add_action('in_admin_footer', function () {
|
31 |
+
echo UBTemplate::render('main_authorized_footer');
|
32 |
+
});
|
33 |
} else {
|
34 |
+
if (UBConfig::has_authorized()) {
|
35 |
+
// They've attempted to authorize, but this domain isn't in the list
|
36 |
+
echo UBTemplate::render('main_failed_authorization', array('domain' => $domain));
|
37 |
+
} else {
|
38 |
+
echo UBTemplate::render('main_unauthorized', array('domain' => $domain));
|
39 |
+
}
|
40 |
|
41 |
+
add_action('in_admin_footer', function () {
|
42 |
+
echo UBTemplate::render('main_unauthorized_footer');
|
43 |
+
});
|
44 |
}
|
45 |
|
46 |
echo '</div>';
|
|
templates/main_authorized.php
CHANGED
@@ -3,26 +3,30 @@
|
|
3 |
<form method="get" action="https://app.unbounce.com" target="_blank">
|
4 |
<?php
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
11 |
</form>
|
12 |
|
13 |
<div class="ub-page-list">
|
14 |
-
|
15 |
-
|
16 |
|
17 |
<p>Last refreshed <?php echo $last_refreshed; ?>.</p>
|
18 |
|
19 |
-
|
20 |
|
21 |
-
|
22 |
-
|
|
|
23 |
'text' => 'Update WordPress Enabled Domains',
|
24 |
'domain' => $domain,
|
25 |
'wrap_in_p' => false,
|
26 |
'is_primary' => false,
|
27 |
-
|
|
|
28 |
</div>
|
3 |
<form method="get" action="https://app.unbounce.com" target="_blank">
|
4 |
<?php
|
5 |
|
6 |
+
echo get_submit_button(
|
7 |
+
'Manage Pages In Unbounce',
|
8 |
+
'primary',
|
9 |
+
'flush-unbounce-pages',
|
10 |
+
false,
|
11 |
+
array('style' => 'margin-top: 10px')
|
12 |
+
); ?>
|
13 |
</form>
|
14 |
|
15 |
<div class="ub-page-list">
|
16 |
+
<?php $table = new UBPageTable($proxyable_url_set); ?>
|
17 |
+
<?php echo $table->display(); ?>
|
18 |
|
19 |
<p>Last refreshed <?php echo $last_refreshed; ?>.</p>
|
20 |
|
21 |
+
<?php
|
22 |
|
23 |
+
echo UBTemplate::render(
|
24 |
+
'authorize_button',
|
25 |
+
array(
|
26 |
'text' => 'Update WordPress Enabled Domains',
|
27 |
'domain' => $domain,
|
28 |
'wrap_in_p' => false,
|
29 |
'is_primary' => false,
|
30 |
+
)
|
31 |
+
); ?>
|
32 |
</div>
|
templates/main_authorized_footer.php
CHANGED
@@ -17,5 +17,8 @@ $refresh_button = get_submit_button('refreshing the Published Pages list', 'seco
|
|
17 |
<a href="http://documentation.unbounce.com/hc/en-us/articles/205069824-Integrating-with-WordPress" target="_blank">
|
18 |
Check out our knowledge base.
|
19 |
</a>
|
20 |
-
<br
|
21 |
-
<
|
|
|
|
|
|
17 |
<a href="http://documentation.unbounce.com/hc/en-us/articles/205069824-Integrating-with-WordPress" target="_blank">
|
18 |
Check out our knowledge base.
|
19 |
</a>
|
20 |
+
<br/>
|
21 |
+
<a class="ub-diagnostics-link" href="<?php echo $diagnostics_url ?>">
|
22 |
+
Click here for troubleshooting and plugin diagnostics
|
23 |
+
</a>
|
24 |
+
<p class="ub-version">Unbounce Version 1.0.32</p>
|
templates/main_failed_authorization.php
CHANGED
@@ -1,25 +1,33 @@
|
|
1 |
<div class="error">
|
2 |
-
<p>It looks like <strong><?php echo $domain; ?></strong> has not been added as a WordPress domain
|
|
|
3 |
</div>
|
4 |
|
5 |
<form method="get" action="https://app.unbounce.com/add_wordpress_domain" target="_blank">
|
6 |
<input type="hidden" name="domain_name" value="<?php echo $domain; ?>" />
|
7 |
-
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
14 |
</form>
|
15 |
|
16 |
<?php
|
17 |
|
18 |
-
echo UBTemplate::render(
|
19 |
-
|
|
|
20 |
'text' => 'Update WordPress Enabled Domains',
|
21 |
'domain' => $domain,
|
22 |
'wrap_in_p' => false,
|
23 |
'is_primary' => false,
|
24 |
'outer_text' => 'After adding your domain in Unbounce, come back here and ',
|
25 |
-
|
|
1 |
<div class="error">
|
2 |
+
<p>It looks like <strong><?php echo $domain; ?></strong> has not been added as a WordPress domain
|
3 |
+
in your Unbounce account.</p>
|
4 |
</div>
|
5 |
|
6 |
<form method="get" action="https://app.unbounce.com/add_wordpress_domain" target="_blank">
|
7 |
<input type="hidden" name="domain_name" value="<?php echo $domain; ?>" />
|
8 |
+
<?php
|
9 |
|
10 |
+
get_submit_Button(
|
11 |
+
'Add My Domain in Unbounce',
|
12 |
+
'primary',
|
13 |
+
null,
|
14 |
+
true,
|
15 |
+
array(
|
16 |
+
'id' => 'add-domain',
|
17 |
+
'onclick' => 'swap_primary_buttons("add-domain", "set-unbounce-domains");',
|
18 |
+
)
|
19 |
+
); ?>
|
20 |
</form>
|
21 |
|
22 |
<?php
|
23 |
|
24 |
+
echo UBTemplate::render(
|
25 |
+
'authorize_button',
|
26 |
+
array(
|
27 |
'text' => 'Update WordPress Enabled Domains',
|
28 |
'domain' => $domain,
|
29 |
'wrap_in_p' => false,
|
30 |
'is_primary' => false,
|
31 |
'outer_text' => 'After adding your domain in Unbounce, come back here and ',
|
32 |
+
)
|
33 |
+
); ?>
|
templates/main_header.php
CHANGED
@@ -1,21 +1,21 @@
|
|
1 |
<img class="ub-logo src=<?php echo $img_url; ?>" />
|
2 |
<h1 class="ub-unbounce-pages-heading">Unbounce Pages</h1>
|
3 |
|
4 |
-
<?php if ($authorization === 'success' && $is_authorized)
|
5 |
<div class="updated"><p>Authorized with Unbounce and WordPress domain successfully enabled.</p></div>
|
6 |
-
<?php
|
7 |
<div class="updated"><p>Successfully authorized with Unbounce.</p></div>
|
8 |
-
<?php
|
9 |
<div class="error"><p>Sorry, there was an error authorizing with Unbounce. Please try again.</p></div>
|
10 |
-
<?php
|
11 |
|
12 |
<?php // Only show error if they've never authorized, otherwise it will be shown right away ?>
|
13 |
-
<?php if (
|
14 |
<div class="error">
|
15 |
<p>
|
16 |
We have identified a configuration issue with this Unbounce Pages Plugin and your WordPress
|
17 |
-
configuration, please <a href="<?php echo admin_url('admin.php?page=unbounce-pages-diagnostics'); ?>">click here
|
18 |
-
for more details.
|
19 |
</p>
|
20 |
</div>
|
21 |
-
<?php
|
1 |
<img class="ub-logo src=<?php echo $img_url; ?>" />
|
2 |
<h1 class="ub-unbounce-pages-heading">Unbounce Pages</h1>
|
3 |
|
4 |
+
<?php if ($authorization === 'success' && $is_authorized) : ?>
|
5 |
<div class="updated"><p>Authorized with Unbounce and WordPress domain successfully enabled.</p></div>
|
6 |
+
<?php elseif ($authorization === 'success') : ?>
|
7 |
<div class="updated"><p>Successfully authorized with Unbounce.</p></div>
|
8 |
+
<?php elseif ($authorization === 'failure') : ?>
|
9 |
<div class="error"><p>Sorry, there was an error authorizing with Unbounce. Please try again.</p></div>
|
10 |
+
<?php endif; ?>
|
11 |
|
12 |
<?php // Only show error if they've never authorized, otherwise it will be shown right away ?>
|
13 |
+
<?php if ($show_warning) : ?>
|
14 |
<div class="error">
|
15 |
<p>
|
16 |
We have identified a configuration issue with this Unbounce Pages Plugin and your WordPress
|
17 |
+
configuration, please <a href="<?php echo admin_url('admin.php?page=unbounce-pages-diagnostics'); ?>">click here
|
18 |
+
</a> for more details.
|
19 |
</p>
|
20 |
</div>
|
21 |
+
<?php endif; ?>
|
templates/main_unauthorized.php
CHANGED
@@ -1,14 +1,18 @@
|
|
1 |
-
<div class="ub-authorize-message">
|
|
|
|
|
2 |
|
3 |
<?php
|
4 |
|
5 |
-
echo UBTemplate::render(
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
12 |
|
13 |
<form method="get" action="http://unbounce.com/landing-pages-for-wordpress/" target='_blank'>
|
14 |
<input type="hidden" name="utm_medium" value="product" />
|
1 |
+
<div class="ub-authorize-message">
|
2 |
+
Before you can publish your pages to WordPress you will have to authorize your Unbounce account.
|
3 |
+
</div>
|
4 |
|
5 |
<?php
|
6 |
|
7 |
+
echo UBTemplate::render(
|
8 |
+
'authorize_button',
|
9 |
+
array(
|
10 |
+
'text' => 'Authorize With Unbounce',
|
11 |
+
'domain' => $domain,
|
12 |
+
'wrap_in_p' => true,
|
13 |
+
'is_primary' => true,
|
14 |
+
)
|
15 |
+
) ?>
|
16 |
|
17 |
<form method="get" action="http://unbounce.com/landing-pages-for-wordpress/" target='_blank'>
|
18 |
<input type="hidden" name="utm_medium" value="product" />
|
templates/main_unauthorized_footer.php
CHANGED
@@ -4,4 +4,4 @@
|
|
4 |
<a class="ub-diagnostics-link" href="<?php echo admin_url('admin.php?page=unbounce-pages-diagnostics'); ?>">
|
5 |
Click here for troubleshooting and plugin diagnostics
|
6 |
</a>
|
7 |
-
<p class="ub-version">Unbounce Version 1.0.
|
4 |
<a class="ub-diagnostics-link" href="<?php echo admin_url('admin.php?page=unbounce-pages-diagnostics'); ?>">
|
5 |
Click here for troubleshooting and plugin diagnostics
|
6 |
</a>
|
7 |
+
<p class="ub-version">Unbounce Version 1.0.32</p>
|