Unbounce Landing Pages - Version 1.0.30

Version Description

  • Minor bug fix
Download this release

Release Info

Developer unbouncewordpress
Plugin Icon Unbounce Landing Pages
Version 1.0.30
Comparing to
See all releases

Code changes from version 1.0.29 to 1.0.30

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