Completed
Branch 973/fix-visible-recaptcha (0580c7)
by
unknown
03:03 queued 30s
created
core/services/request/RequestInterface.php 1 patch
Indentation   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -16,204 +16,204 @@
 block discarded – undo
16 16
 interface RequestInterface extends RequestTypeContextCheckerInterface
17 17
 {
18 18
 
19
-    /**
20
-     * @param RequestTypeContextCheckerInterface $type
21
-     */
22
-    public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type);
19
+	/**
20
+	 * @param RequestTypeContextCheckerInterface $type
21
+	 */
22
+	public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type);
23 23
 
24 24
 
25
-    /**
26
-     * @return array
27
-     */
28
-    public function getParams();
25
+	/**
26
+	 * @return array
27
+	 */
28
+	public function getParams();
29 29
 
30 30
 
31
-    /**
32
-     * @return array
33
-     */
34
-    public function postParams();
35
-
36
-
37
-    /**
38
-     * @return array
39
-     */
40
-    public function cookieParams();
41
-
42
-
43
-    /**
44
-     * @return array
45
-     */
46
-    public function serverParams();
47
-
48
-
49
-    /**
50
-     * @param string $key
51
-     * @param mixed|null $default
52
-     * @return array|int|float|string
53
-     */
54
-    public function getServerParam($key, $default = null);
55
-
56
-
57
-    /**
58
-     * @param string                 $key
59
-     * @param array|int|float|string $value
60
-     * @return void
61
-     */
62
-    public function setServerParam($key, $value);
63
-
64
-
65
-    /**
66
-     * remove param
67
-     *
68
-     * @param string $key
69
-     * @param bool   $unset_from_global_too
70
-     */
71
-    public function unSetServerParam($key, $unset_from_global_too = false);
72
-
73
-
74
-    /**
75
-     * @param string $key
76
-     * @return bool
77
-     */
78
-    public function serverParamIsSet($key);
79
-
80
-
81
-    /**
82
-     * @return array
83
-     */
84
-    public function filesParams();
85
-
86
-
87
-    /**
88
-     * returns sanitized contents of $_REQUEST
89
-     *
90
-     * @return array
91
-     */
92
-    public function requestParams();
93
-
94
-
95
-    /**
96
-     * @param string $key
97
-     * @param string $value
98
-     * @param bool   $override_ee
99
-     * @return void
100
-     */
101
-    public function setRequestParam($key, $value, $override_ee = false);
102
-
103
-
104
-    /**
105
-     * returns   the value for a request param if the given key exists
106
-     *
107
-     * @param string     $key
108
-     * @param mixed|null $default
109
-     * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
110
-     * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
111
-     * @param string     $delimiter for CSV type strings that should be returned as an array
112
-     * @return array|bool|float|int|string
113
-     */
114
-    public function getRequestParam($key, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '');
115
-
116
-
117
-    /**
118
-     * check if param exists
119
-     *
120
-     * @param string $key
121
-     * @return bool
122
-     */
123
-    public function requestParamIsSet($key);
124
-
125
-
126
-    /**
127
-     * check if a request parameter exists whose key that matches the supplied wildcard pattern
128
-     * and return the value for the first match found
129
-     * wildcards can be either of the following:
130
-     *      ? to represent a single character of any type
131
-     *      * to represent one or more characters of any type
132
-     *
133
-     * @param string     $pattern
134
-     * @param mixed|null $default
135
-     * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
136
-     * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
137
-     * @param string     $delimiter for CSV type strings that should be returned as an array
138
-     * @return array|bool|float|int|string
139
-     */
140
-    public function getMatch($pattern, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '');
141
-
142
-
143
-    /**
144
-     * check if a request parameter exists whose key matches the supplied wildcard pattern
145
-     * wildcards can be either of the following:
146
-     *      ? to represent a single character of any type
147
-     *      * to represent one or more characters of any type
148
-     * returns true if a match is found or false if not
149
-     *
150
-     * @param string $pattern
151
-     * @return false|int
152
-     */
153
-    public function matches($pattern);
154
-
155
-
156
-    /**
157
-     * remove param
158
-     *
159
-     * @param string $key
160
-     * @param bool   $unset_from_global_too
161
-     */
162
-    public function unSetRequestParam($key, $unset_from_global_too = false);
163
-
164
-
165
-    /**
166
-     * remove params
167
-     *
168
-     * @param array $keys
169
-     * @param bool  $unset_from_global_too
170
-     */
171
-    public function unSetRequestParams(array $keys, $unset_from_global_too = false);
172
-
173
-
174
-    /**
175
-     * @return string
176
-     */
177
-    public function ipAddress();
178
-
179
-
180
-    /**
181
-     * @param boolean $relativeToWpRoot whether to return the uri relative to WordPress' home URL, or not.
182
-     * @return string
183
-     */
184
-    public function requestUri($relativeToWpRoot = false);
185
-
186
-
187
-    /**
188
-     * @return string
189
-     */
190
-    public function userAgent();
191
-
192
-
193
-    /**
194
-     * @param string $user_agent
195
-     */
196
-    public function setUserAgent($user_agent = '');
197
-
198
-
199
-    /**
200
-     * @return bool
201
-     */
202
-    public function isBot();
203
-
204
-
205
-    /**
206
-     * @param bool $is_bot
207
-     */
208
-    public function setIsBot($is_bot);
209
-
210
-
211
-    /**
212
-     * merges the incoming array of parameters into the existing request parameters
213
-     *
214
-     * @param array $request_params
215
-     * @return mixed
216
-     * @since   4.10.24.p
217
-     */
218
-    public function mergeRequestParams(array $request_params);
31
+	/**
32
+	 * @return array
33
+	 */
34
+	public function postParams();
35
+
36
+
37
+	/**
38
+	 * @return array
39
+	 */
40
+	public function cookieParams();
41
+
42
+
43
+	/**
44
+	 * @return array
45
+	 */
46
+	public function serverParams();
47
+
48
+
49
+	/**
50
+	 * @param string $key
51
+	 * @param mixed|null $default
52
+	 * @return array|int|float|string
53
+	 */
54
+	public function getServerParam($key, $default = null);
55
+
56
+
57
+	/**
58
+	 * @param string                 $key
59
+	 * @param array|int|float|string $value
60
+	 * @return void
61
+	 */
62
+	public function setServerParam($key, $value);
63
+
64
+
65
+	/**
66
+	 * remove param
67
+	 *
68
+	 * @param string $key
69
+	 * @param bool   $unset_from_global_too
70
+	 */
71
+	public function unSetServerParam($key, $unset_from_global_too = false);
72
+
73
+
74
+	/**
75
+	 * @param string $key
76
+	 * @return bool
77
+	 */
78
+	public function serverParamIsSet($key);
79
+
80
+
81
+	/**
82
+	 * @return array
83
+	 */
84
+	public function filesParams();
85
+
86
+
87
+	/**
88
+	 * returns sanitized contents of $_REQUEST
89
+	 *
90
+	 * @return array
91
+	 */
92
+	public function requestParams();
93
+
94
+
95
+	/**
96
+	 * @param string $key
97
+	 * @param string $value
98
+	 * @param bool   $override_ee
99
+	 * @return void
100
+	 */
101
+	public function setRequestParam($key, $value, $override_ee = false);
102
+
103
+
104
+	/**
105
+	 * returns   the value for a request param if the given key exists
106
+	 *
107
+	 * @param string     $key
108
+	 * @param mixed|null $default
109
+	 * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
110
+	 * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
111
+	 * @param string     $delimiter for CSV type strings that should be returned as an array
112
+	 * @return array|bool|float|int|string
113
+	 */
114
+	public function getRequestParam($key, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '');
115
+
116
+
117
+	/**
118
+	 * check if param exists
119
+	 *
120
+	 * @param string $key
121
+	 * @return bool
122
+	 */
123
+	public function requestParamIsSet($key);
124
+
125
+
126
+	/**
127
+	 * check if a request parameter exists whose key that matches the supplied wildcard pattern
128
+	 * and return the value for the first match found
129
+	 * wildcards can be either of the following:
130
+	 *      ? to represent a single character of any type
131
+	 *      * to represent one or more characters of any type
132
+	 *
133
+	 * @param string     $pattern
134
+	 * @param mixed|null $default
135
+	 * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
136
+	 * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
137
+	 * @param string     $delimiter for CSV type strings that should be returned as an array
138
+	 * @return array|bool|float|int|string
139
+	 */
140
+	public function getMatch($pattern, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '');
141
+
142
+
143
+	/**
144
+	 * check if a request parameter exists whose key matches the supplied wildcard pattern
145
+	 * wildcards can be either of the following:
146
+	 *      ? to represent a single character of any type
147
+	 *      * to represent one or more characters of any type
148
+	 * returns true if a match is found or false if not
149
+	 *
150
+	 * @param string $pattern
151
+	 * @return false|int
152
+	 */
153
+	public function matches($pattern);
154
+
155
+
156
+	/**
157
+	 * remove param
158
+	 *
159
+	 * @param string $key
160
+	 * @param bool   $unset_from_global_too
161
+	 */
162
+	public function unSetRequestParam($key, $unset_from_global_too = false);
163
+
164
+
165
+	/**
166
+	 * remove params
167
+	 *
168
+	 * @param array $keys
169
+	 * @param bool  $unset_from_global_too
170
+	 */
171
+	public function unSetRequestParams(array $keys, $unset_from_global_too = false);
172
+
173
+
174
+	/**
175
+	 * @return string
176
+	 */
177
+	public function ipAddress();
178
+
179
+
180
+	/**
181
+	 * @param boolean $relativeToWpRoot whether to return the uri relative to WordPress' home URL, or not.
182
+	 * @return string
183
+	 */
184
+	public function requestUri($relativeToWpRoot = false);
185
+
186
+
187
+	/**
188
+	 * @return string
189
+	 */
190
+	public function userAgent();
191
+
192
+
193
+	/**
194
+	 * @param string $user_agent
195
+	 */
196
+	public function setUserAgent($user_agent = '');
197
+
198
+
199
+	/**
200
+	 * @return bool
201
+	 */
202
+	public function isBot();
203
+
204
+
205
+	/**
206
+	 * @param bool $is_bot
207
+	 */
208
+	public function setIsBot($is_bot);
209
+
210
+
211
+	/**
212
+	 * merges the incoming array of parameters into the existing request parameters
213
+	 *
214
+	 * @param array $request_params
215
+	 * @return mixed
216
+	 * @since   4.10.24.p
217
+	 */
218
+	public function mergeRequestParams(array $request_params);
219 219
 }
Please login to merge, or discard this patch.
core/services/request/ServerParams.php 2 patches
Indentation   +200 added lines, -200 removed lines patch added patch discarded remove patch
@@ -7,204 +7,204 @@
 block discarded – undo
7 7
 class ServerParams
8 8
 {
9 9
 
10
-    /**
11
-     * IP address for request
12
-     *
13
-     * @var string
14
-     */
15
-    protected $ip_address;
16
-
17
-
18
-    /**
19
-     * @var ServerSanitizer
20
-     */
21
-    protected $sanitizer;
22
-
23
-    /**
24
-     * sanitized $_SERVER parameters
25
-     *
26
-     * @var array
27
-     */
28
-    protected $server;
29
-
30
-    /**
31
-     * @var string
32
-     */
33
-    protected $request_uri;
34
-
35
-    /**
36
-     * @var string
37
-     */
38
-    protected $user_agent;
39
-
40
-
41
-    /**
42
-     * ServerParams constructor.
43
-     *
44
-     * @param ServerSanitizer $sanitizer
45
-     * @param array           $server
46
-     */
47
-    public function __construct(ServerSanitizer $sanitizer, array $server = [])
48
-    {
49
-        $this->sanitizer  = $sanitizer;
50
-        $this->server     = $this->cleanServerParams($server);
51
-        $this->ip_address = $this->setVisitorIp();
52
-    }
53
-
54
-
55
-    /**
56
-     * @return array
57
-     */
58
-    private function cleanServerParams(array $server)
59
-    {
60
-        $cleaned = [];
61
-        $server  = ! empty($server) ? $server : $_SERVER;
62
-        foreach ($server as $key => $value) {
63
-            $cleaned[ $key ] = $this->sanitizer->clean($key, $value);
64
-        }
65
-        return $cleaned;
66
-    }
67
-
68
-
69
-    /**
70
-     * @return array
71
-     */
72
-    public function getAllServerParams()
73
-    {
74
-        return $this->server;
75
-    }
76
-
77
-
78
-    /**
79
-     * @param string $key
80
-     * @param mixed|null $default
81
-     * @return array|int|float|string
82
-     */
83
-    public function getServerParam($key, $default = null)
84
-    {
85
-        return $this->serverParamIsSet($key) ? $this->server[ $key ] : $default;
86
-    }
87
-
88
-
89
-    /**
90
-     * @param string                 $key
91
-     * @param array|int|float|string $value
92
-     * @return void
93
-     */
94
-    public function setServerParam($key, $value)
95
-    {
96
-        $clean_value = $this->sanitizer->clean($key, $value);
97
-        $this->server[ $key ] = $clean_value;
98
-        // modify global too
99
-        $_SERVER[ $key ] = $clean_value;
100
-    }
101
-
102
-
103
-    /**
104
-     * @return bool
105
-     */
106
-    public function serverParamIsSet($key)
107
-    {
108
-        return isset($this->server[ $key ]);
109
-    }
110
-
111
-
112
-    /**
113
-     * remove param
114
-     *
115
-     * @param string $key
116
-     * @param bool   $unset_from_global_too
117
-     */
118
-    public function unSetServerParam($key, $unset_from_global_too = false)
119
-    {
120
-        // because unset may not actually remove var
121
-        $this->server[ $key ] = null;
122
-        unset($this->server[ $key ]);
123
-        if ($unset_from_global_too) {
124
-            unset($_SERVER[ $key ]);
125
-        }
126
-    }
127
-
128
-
129
-    /**
130
-     * @return string
131
-     */
132
-    public function ipAddress()
133
-    {
134
-        return $this->ip_address;
135
-    }
136
-
137
-
138
-    /**
139
-     * attempt to get IP address of current visitor from server
140
-     * plz see: http://stackoverflow.com/a/2031935/1475279
141
-     *
142
-     * @access public
143
-     * @return string
144
-     */
145
-    private function setVisitorIp()
146
-    {
147
-        $visitor_ip  = '0.0.0.0';
148
-        $server_keys = [
149
-            'HTTP_CLIENT_IP',
150
-            'HTTP_FORWARDED',
151
-            'HTTP_FORWARDED_FOR',
152
-            'HTTP_X_CLUSTER_CLIENT_IP',
153
-            'HTTP_X_FORWARDED',
154
-            'HTTP_X_FORWARDED_FOR',
155
-            'REMOTE_ADDR',
156
-        ];
157
-        foreach ($server_keys as $key) {
158
-            if (isset($this->server[ $key ])) {
159
-                $potential_ip = array_map('trim', explode(',', $this->server[ $key ]));
160
-                foreach ($potential_ip as $ip) {
161
-                    if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
162
-                        $visitor_ip = $ip;
163
-                    }
164
-                }
165
-            }
166
-        }
167
-        return $visitor_ip;
168
-    }
169
-
170
-
171
-    /**
172
-     * Gets the request's literal URI. Related to `requestUriAfterSiteHomeUri`, see its description for a comparison.
173
-     *
174
-     * @param boolean $relativeToWpRoot If home_url() is "http://mysite.com/wp/", and a request comes to
175
-     *                                  "http://mysite.com/wp/wp-json", setting $relativeToWpRoot=true will return
176
-     *                                  "/wp-json", whereas $relativeToWpRoot=false will return "/wp/wp-json/".
177
-     * @return string
178
-     */
179
-    public function requestUri($relativeToWpRoot = false)
180
-    {
181
-        if ($relativeToWpRoot) {
182
-            $home_path = untrailingslashit(parse_url(home_url(), PHP_URL_PATH));
183
-            return str_replace($home_path, '', $this->server['REQUEST_URI']);
184
-        }
185
-        return $this->server['REQUEST_URI'];
186
-    }
187
-
188
-
189
-    /**
190
-     * @return string
191
-     */
192
-    public function userAgent()
193
-    {
194
-        if (empty($this->user_agent)) {
195
-            $this->setUserAgent();
196
-        }
197
-        return $this->user_agent;
198
-    }
199
-
200
-
201
-    /**
202
-     * @param string $user_agent
203
-     */
204
-    public function setUserAgent($user_agent = '')
205
-    {
206
-        $this->user_agent = $user_agent === '' || ! is_string($user_agent)
207
-            ? $this->getServerParam('HTTP_USER_AGENT')
208
-            : esc_attr($user_agent);
209
-    }
10
+	/**
11
+	 * IP address for request
12
+	 *
13
+	 * @var string
14
+	 */
15
+	protected $ip_address;
16
+
17
+
18
+	/**
19
+	 * @var ServerSanitizer
20
+	 */
21
+	protected $sanitizer;
22
+
23
+	/**
24
+	 * sanitized $_SERVER parameters
25
+	 *
26
+	 * @var array
27
+	 */
28
+	protected $server;
29
+
30
+	/**
31
+	 * @var string
32
+	 */
33
+	protected $request_uri;
34
+
35
+	/**
36
+	 * @var string
37
+	 */
38
+	protected $user_agent;
39
+
40
+
41
+	/**
42
+	 * ServerParams constructor.
43
+	 *
44
+	 * @param ServerSanitizer $sanitizer
45
+	 * @param array           $server
46
+	 */
47
+	public function __construct(ServerSanitizer $sanitizer, array $server = [])
48
+	{
49
+		$this->sanitizer  = $sanitizer;
50
+		$this->server     = $this->cleanServerParams($server);
51
+		$this->ip_address = $this->setVisitorIp();
52
+	}
53
+
54
+
55
+	/**
56
+	 * @return array
57
+	 */
58
+	private function cleanServerParams(array $server)
59
+	{
60
+		$cleaned = [];
61
+		$server  = ! empty($server) ? $server : $_SERVER;
62
+		foreach ($server as $key => $value) {
63
+			$cleaned[ $key ] = $this->sanitizer->clean($key, $value);
64
+		}
65
+		return $cleaned;
66
+	}
67
+
68
+
69
+	/**
70
+	 * @return array
71
+	 */
72
+	public function getAllServerParams()
73
+	{
74
+		return $this->server;
75
+	}
76
+
77
+
78
+	/**
79
+	 * @param string $key
80
+	 * @param mixed|null $default
81
+	 * @return array|int|float|string
82
+	 */
83
+	public function getServerParam($key, $default = null)
84
+	{
85
+		return $this->serverParamIsSet($key) ? $this->server[ $key ] : $default;
86
+	}
87
+
88
+
89
+	/**
90
+	 * @param string                 $key
91
+	 * @param array|int|float|string $value
92
+	 * @return void
93
+	 */
94
+	public function setServerParam($key, $value)
95
+	{
96
+		$clean_value = $this->sanitizer->clean($key, $value);
97
+		$this->server[ $key ] = $clean_value;
98
+		// modify global too
99
+		$_SERVER[ $key ] = $clean_value;
100
+	}
101
+
102
+
103
+	/**
104
+	 * @return bool
105
+	 */
106
+	public function serverParamIsSet($key)
107
+	{
108
+		return isset($this->server[ $key ]);
109
+	}
110
+
111
+
112
+	/**
113
+	 * remove param
114
+	 *
115
+	 * @param string $key
116
+	 * @param bool   $unset_from_global_too
117
+	 */
118
+	public function unSetServerParam($key, $unset_from_global_too = false)
119
+	{
120
+		// because unset may not actually remove var
121
+		$this->server[ $key ] = null;
122
+		unset($this->server[ $key ]);
123
+		if ($unset_from_global_too) {
124
+			unset($_SERVER[ $key ]);
125
+		}
126
+	}
127
+
128
+
129
+	/**
130
+	 * @return string
131
+	 */
132
+	public function ipAddress()
133
+	{
134
+		return $this->ip_address;
135
+	}
136
+
137
+
138
+	/**
139
+	 * attempt to get IP address of current visitor from server
140
+	 * plz see: http://stackoverflow.com/a/2031935/1475279
141
+	 *
142
+	 * @access public
143
+	 * @return string
144
+	 */
145
+	private function setVisitorIp()
146
+	{
147
+		$visitor_ip  = '0.0.0.0';
148
+		$server_keys = [
149
+			'HTTP_CLIENT_IP',
150
+			'HTTP_FORWARDED',
151
+			'HTTP_FORWARDED_FOR',
152
+			'HTTP_X_CLUSTER_CLIENT_IP',
153
+			'HTTP_X_FORWARDED',
154
+			'HTTP_X_FORWARDED_FOR',
155
+			'REMOTE_ADDR',
156
+		];
157
+		foreach ($server_keys as $key) {
158
+			if (isset($this->server[ $key ])) {
159
+				$potential_ip = array_map('trim', explode(',', $this->server[ $key ]));
160
+				foreach ($potential_ip as $ip) {
161
+					if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
162
+						$visitor_ip = $ip;
163
+					}
164
+				}
165
+			}
166
+		}
167
+		return $visitor_ip;
168
+	}
169
+
170
+
171
+	/**
172
+	 * Gets the request's literal URI. Related to `requestUriAfterSiteHomeUri`, see its description for a comparison.
173
+	 *
174
+	 * @param boolean $relativeToWpRoot If home_url() is "http://mysite.com/wp/", and a request comes to
175
+	 *                                  "http://mysite.com/wp/wp-json", setting $relativeToWpRoot=true will return
176
+	 *                                  "/wp-json", whereas $relativeToWpRoot=false will return "/wp/wp-json/".
177
+	 * @return string
178
+	 */
179
+	public function requestUri($relativeToWpRoot = false)
180
+	{
181
+		if ($relativeToWpRoot) {
182
+			$home_path = untrailingslashit(parse_url(home_url(), PHP_URL_PATH));
183
+			return str_replace($home_path, '', $this->server['REQUEST_URI']);
184
+		}
185
+		return $this->server['REQUEST_URI'];
186
+	}
187
+
188
+
189
+	/**
190
+	 * @return string
191
+	 */
192
+	public function userAgent()
193
+	{
194
+		if (empty($this->user_agent)) {
195
+			$this->setUserAgent();
196
+		}
197
+		return $this->user_agent;
198
+	}
199
+
200
+
201
+	/**
202
+	 * @param string $user_agent
203
+	 */
204
+	public function setUserAgent($user_agent = '')
205
+	{
206
+		$this->user_agent = $user_agent === '' || ! is_string($user_agent)
207
+			? $this->getServerParam('HTTP_USER_AGENT')
208
+			: esc_attr($user_agent);
209
+	}
210 210
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
         $cleaned = [];
61 61
         $server  = ! empty($server) ? $server : $_SERVER;
62 62
         foreach ($server as $key => $value) {
63
-            $cleaned[ $key ] = $this->sanitizer->clean($key, $value);
63
+            $cleaned[$key] = $this->sanitizer->clean($key, $value);
64 64
         }
65 65
         return $cleaned;
66 66
     }
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
      */
83 83
     public function getServerParam($key, $default = null)
84 84
     {
85
-        return $this->serverParamIsSet($key) ? $this->server[ $key ] : $default;
85
+        return $this->serverParamIsSet($key) ? $this->server[$key] : $default;
86 86
     }
87 87
 
88 88
 
@@ -94,9 +94,9 @@  discard block
 block discarded – undo
94 94
     public function setServerParam($key, $value)
95 95
     {
96 96
         $clean_value = $this->sanitizer->clean($key, $value);
97
-        $this->server[ $key ] = $clean_value;
97
+        $this->server[$key] = $clean_value;
98 98
         // modify global too
99
-        $_SERVER[ $key ] = $clean_value;
99
+        $_SERVER[$key] = $clean_value;
100 100
     }
101 101
 
102 102
 
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
      */
106 106
     public function serverParamIsSet($key)
107 107
     {
108
-        return isset($this->server[ $key ]);
108
+        return isset($this->server[$key]);
109 109
     }
110 110
 
111 111
 
@@ -118,10 +118,10 @@  discard block
 block discarded – undo
118 118
     public function unSetServerParam($key, $unset_from_global_too = false)
119 119
     {
120 120
         // because unset may not actually remove var
121
-        $this->server[ $key ] = null;
122
-        unset($this->server[ $key ]);
121
+        $this->server[$key] = null;
122
+        unset($this->server[$key]);
123 123
         if ($unset_from_global_too) {
124
-            unset($_SERVER[ $key ]);
124
+            unset($_SERVER[$key]);
125 125
         }
126 126
     }
127 127
 
@@ -155,8 +155,8 @@  discard block
 block discarded – undo
155 155
             'REMOTE_ADDR',
156 156
         ];
157 157
         foreach ($server_keys as $key) {
158
-            if (isset($this->server[ $key ])) {
159
-                $potential_ip = array_map('trim', explode(',', $this->server[ $key ]));
158
+            if (isset($this->server[$key])) {
159
+                $potential_ip = array_map('trim', explode(',', $this->server[$key]));
160 160
                 foreach ($potential_ip as $ip) {
161 161
                     if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
162 162
                         $visitor_ip = $ip;
Please login to merge, or discard this patch.
core/services/request/Request.php 1 patch
Indentation   +503 added lines, -503 removed lines patch added patch discarded remove patch
@@ -17,507 +17,507 @@
 block discarded – undo
17 17
 class Request implements InterminableInterface, RequestInterface, ReservedInstanceInterface
18 18
 {
19 19
 
20
-    /**
21
-     * $_COOKIE parameters
22
-     *
23
-     * @var array
24
-     */
25
-    protected $cookies;
26
-
27
-    /**
28
-     * $_FILES parameters
29
-     *
30
-     * @var array
31
-     */
32
-    protected $files;
33
-
34
-    /**
35
-     * true if current user appears to be some kind of bot
36
-     *
37
-     * @var bool
38
-     */
39
-    protected $is_bot;
40
-
41
-    /**
42
-     * @var RequestParams
43
-     */
44
-    protected $request_params;
45
-
46
-    /**
47
-     * @var RequestTypeContextCheckerInterface
48
-     */
49
-    protected $request_type;
50
-
51
-    /**
52
-     * @var ServerParams
53
-     */
54
-    protected $server_params;
55
-
56
-
57
-    public function __construct(
58
-        RequestParams $request_params,
59
-        ServerParams $server_params,
60
-        array $cookies = [],
61
-        array $files = []
62
-    ) {
63
-        $this->cookies = ! empty($cookies)
64
-            ? $cookies
65
-            : filter_input_array(INPUT_COOKIE, FILTER_SANITIZE_STRING);
66
-        $this->files          = ! empty($files) ? $files : $_FILES;
67
-        $this->request_params = $request_params;
68
-        $this->server_params  = $server_params;
69
-    }
70
-
71
-
72
-    /**
73
-     * @param RequestTypeContextCheckerInterface $type
74
-     */
75
-    public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type)
76
-    {
77
-        $this->request_type = $type;
78
-    }
79
-
80
-
81
-    /**
82
-     * @return array
83
-     */
84
-    public function getParams()
85
-    {
86
-        return $this->request_params->getParams();
87
-    }
88
-
89
-
90
-    /**
91
-     * @return array
92
-     */
93
-    public function postParams()
94
-    {
95
-        return $this->request_params->postParams();
96
-    }
97
-
98
-
99
-    /**
100
-     * @return array
101
-     */
102
-    public function cookieParams()
103
-    {
104
-        return $this->cookies;
105
-    }
106
-
107
-
108
-    /**
109
-     * @return array
110
-     */
111
-    public function serverParams()
112
-    {
113
-        return $this->server_params->getAllServerParams();
114
-    }
115
-
116
-
117
-    /**
118
-     * @param string $key
119
-     * @param mixed|null $default
120
-     * @return array|int|float|string
121
-     */
122
-    public function getServerParam($key, $default = null)
123
-    {
124
-        return $this->server_params->getServerParam($key, $default);
125
-    }
126
-
127
-
128
-    /**
129
-     * @param string                 $key
130
-     * @param array|int|float|string $value
131
-     * @return void
132
-     */
133
-    public function setServerParam($key, $value)
134
-    {
135
-        $this->server_params->setServerParam($key, $value);
136
-    }
137
-
138
-
139
-    /**
140
-     * @param string $key
141
-     * @return bool
142
-     */
143
-    public function serverParamIsSet($key)
144
-    {
145
-        return $this->server_params->serverParamIsSet($key);
146
-    }
147
-
148
-
149
-    /**
150
-     * @return array
151
-     */
152
-    public function filesParams()
153
-    {
154
-        return $this->files;
155
-    }
156
-
157
-
158
-    /**
159
-     * returns sanitized contents of $_REQUEST
160
-     *
161
-     * @return array
162
-     */
163
-    public function requestParams()
164
-    {
165
-        return $this->request_params->requestParams();
166
-    }
167
-
168
-
169
-    /**
170
-     * @param string     $key
171
-     * @param mixed|null $value
172
-     * @param bool       $override_ee
173
-     * @return void
174
-     */
175
-    public function setRequestParam($key, $value, $override_ee = false)
176
-    {
177
-        $this->request_params->setRequestParam($key, $value, $override_ee);
178
-    }
179
-
180
-
181
-    /**
182
-     * merges the incoming array of parameters into the existing request parameters
183
-     *
184
-     * @param array $request_params
185
-     * @return void
186
-     * @since   4.10.24.p
187
-     */
188
-    public function mergeRequestParams(array $request_params)
189
-    {
190
-        $this->request_params->mergeRequestParams($request_params);
191
-    }
192
-
193
-
194
-    /**
195
-     * returns sanitized value for a request param if the given key exists
196
-     *
197
-     * @param string     $key
198
-     * @param mixed|null $default
199
-     * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
200
-     * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
201
-     * @param string     $delimiter for CSV type strings that should be returned as an array
202
-     * @return array|bool|float|int|string
203
-     */
204
-    public function getRequestParam($key, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '')
205
-    {
206
-        return $this->request_params->getRequestParam($key, $default, $type, $is_array, $delimiter);
207
-    }
208
-
209
-
210
-    /**
211
-     * check if param exists
212
-     *
213
-     * @param string $key
214
-     * @return bool
215
-     */
216
-    public function requestParamIsSet($key)
217
-    {
218
-        return $this->request_params->requestParamIsSet($key);
219
-    }
220
-
221
-
222
-    /**
223
-     * check if a request parameter exists whose key that matches the supplied wildcard pattern
224
-     * and return the sanitized value for the first match found
225
-     * wildcards can be either of the following:
226
-     *      ? to represent a single character of any type
227
-     *      * to represent one or more characters of any type
228
-     *
229
-     * @param string     $pattern
230
-     * @param mixed|null $default
231
-     * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
232
-     * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
233
-     * @param string     $delimiter for CSV type strings that should be returned as an array
234
-     * @return array|bool|float|int|string
235
-     */
236
-    public function getMatch($pattern, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '')
237
-    {
238
-        return $this->request_params->getMatch($pattern, $default, $type, $is_array, $delimiter);
239
-    }
240
-
241
-
242
-    /**
243
-     * check if a request parameter exists whose key matches the supplied wildcard pattern
244
-     * wildcards can be either of the following:
245
-     *      ? to represent a single character of any type
246
-     *      * to represent one or more characters of any type
247
-     * returns true if a match is found or false if not
248
-     *
249
-     * @param string $pattern
250
-     * @return bool
251
-     */
252
-    public function matches($pattern)
253
-    {
254
-        return $this->request_params->matches($pattern);
255
-    }
256
-
257
-
258
-    /**
259
-     * remove param
260
-     *
261
-     * @param      $key
262
-     * @param bool $unset_from_global_too
263
-     */
264
-    public function unSetRequestParam($key, $unset_from_global_too = false)
265
-    {
266
-        $this->request_params->unSetRequestParam($key, $unset_from_global_too);
267
-    }
268
-
269
-
270
-    /**
271
-     * remove param
272
-     *
273
-     * @param      $key
274
-     * @param bool $unset_from_global_too
275
-     */
276
-    public function unSetServerParam($key, $unset_from_global_too = false)
277
-    {
278
-        $this->server_params->unSetServerParam($key, $unset_from_global_too);
279
-    }
280
-
281
-
282
-    /**
283
-     * remove params
284
-     *
285
-     * @param array $keys
286
-     * @param bool  $unset_from_global_too
287
-     */
288
-    public function unSetRequestParams(array $keys, $unset_from_global_too = false)
289
-    {
290
-        $this->request_params->unSetRequestParams($keys, $unset_from_global_too);
291
-    }
292
-
293
-
294
-    /**
295
-     * @return string
296
-     */
297
-    public function ipAddress()
298
-    {
299
-        return $this->server_params->ipAddress();
300
-    }
301
-
302
-
303
-    /**
304
-     * Gets the request's literal URI. Related to `requestUriAfterSiteHomeUri`, see its description for a comparison.
305
-     *
306
-     * @param boolean $relativeToWpRoot If home_url() is "http://mysite.com/wp/", and a request comes to
307
-     *                                  "http://mysite.com/wp/wp-json", setting $relativeToWpRoot=true will return
308
-     *                                  "/wp-json", whereas $relativeToWpRoot=false will return "/wp/wp-json/".
309
-     * @return string
310
-     */
311
-    public function requestUri($relativeToWpRoot = false)
312
-    {
313
-        return $this->server_params->requestUri($relativeToWpRoot);
314
-    }
315
-
316
-
317
-    /**
318
-     * @return string
319
-     */
320
-    public function userAgent()
321
-    {
322
-        return $this->server_params->userAgent();
323
-    }
324
-
325
-
326
-    /**
327
-     * @param string $user_agent
328
-     */
329
-    public function setUserAgent($user_agent = '')
330
-    {
331
-        $this->server_params->setUserAgent($user_agent);
332
-    }
333
-
334
-
335
-    /**
336
-     * @return bool
337
-     */
338
-    public function isBot()
339
-    {
340
-        return $this->is_bot;
341
-    }
342
-
343
-
344
-    /**
345
-     * @param bool $is_bot
346
-     */
347
-    public function setIsBot($is_bot)
348
-    {
349
-        $this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN);
350
-    }
351
-
352
-
353
-    /**
354
-     * @return bool
355
-     */
356
-    public function isActivation()
357
-    {
358
-        return $this->request_type->isActivation();
359
-    }
360
-
361
-
362
-    /**
363
-     * @param $is_activation
364
-     * @return bool
365
-     */
366
-    public function setIsActivation($is_activation)
367
-    {
368
-        return $this->request_type->setIsActivation($is_activation);
369
-    }
370
-
371
-
372
-    /**
373
-     * @return bool
374
-     */
375
-    public function isAdmin()
376
-    {
377
-        return $this->request_type->isAdmin();
378
-    }
379
-
380
-
381
-    /**
382
-     * @return bool
383
-     */
384
-    public function isAdminAjax()
385
-    {
386
-        return $this->request_type->isAdminAjax();
387
-    }
388
-
389
-
390
-    /**
391
-     * @return bool
392
-     */
393
-    public function isAjax()
394
-    {
395
-        return $this->request_type->isAjax();
396
-    }
397
-
398
-
399
-    /**
400
-     * @return bool
401
-     */
402
-    public function isEeAjax()
403
-    {
404
-        return $this->request_type->isEeAjax();
405
-    }
406
-
407
-
408
-    /**
409
-     * @return bool
410
-     */
411
-    public function isOtherAjax()
412
-    {
413
-        return $this->request_type->isOtherAjax();
414
-    }
415
-
416
-
417
-    /**
418
-     * @return bool
419
-     */
420
-    public function isApi()
421
-    {
422
-        return $this->request_type->isApi();
423
-    }
424
-
425
-
426
-    /**
427
-     * @return bool
428
-     */
429
-    public function isCli()
430
-    {
431
-        return $this->request_type->isCli();
432
-    }
433
-
434
-
435
-    /**
436
-     * @return bool
437
-     */
438
-    public function isCron()
439
-    {
440
-        return $this->request_type->isCron();
441
-    }
442
-
443
-
444
-    /**
445
-     * @return bool
446
-     */
447
-    public function isFeed()
448
-    {
449
-        return $this->request_type->isFeed();
450
-    }
451
-
452
-
453
-    /**
454
-     * @return bool
455
-     */
456
-    public function isFrontend()
457
-    {
458
-        return $this->request_type->isFrontend();
459
-    }
460
-
461
-
462
-    /**
463
-     * @return bool
464
-     */
465
-    public function isFrontAjax()
466
-    {
467
-        return $this->request_type->isFrontAjax();
468
-    }
469
-
470
-
471
-    /**
472
-     * @return bool
473
-     */
474
-    public function isIframe()
475
-    {
476
-        return $this->request_type->isIframe();
477
-    }
478
-
479
-
480
-    /**
481
-     * @return bool
482
-     */
483
-    public function isWordPressApi()
484
-    {
485
-        return $this->request_type->isWordPressApi();
486
-    }
487
-
488
-
489
-    /**
490
-     * @return bool
491
-     */
492
-    public function isWordPressHeartbeat()
493
-    {
494
-        return $this->request_type->isWordPressHeartbeat();
495
-    }
496
-
497
-
498
-    /**
499
-     * @return bool
500
-     */
501
-    public function isWordPressScrape()
502
-    {
503
-        return $this->request_type->isWordPressScrape();
504
-    }
505
-
506
-
507
-    /**
508
-     * @return string
509
-     */
510
-    public function slug()
511
-    {
512
-        return $this->request_type->slug();
513
-    }
514
-
515
-
516
-    /**
517
-     * @return RequestTypeContextCheckerInterface
518
-     */
519
-    public function getRequestType()
520
-    {
521
-        return $this->request_type;
522
-    }
20
+	/**
21
+	 * $_COOKIE parameters
22
+	 *
23
+	 * @var array
24
+	 */
25
+	protected $cookies;
26
+
27
+	/**
28
+	 * $_FILES parameters
29
+	 *
30
+	 * @var array
31
+	 */
32
+	protected $files;
33
+
34
+	/**
35
+	 * true if current user appears to be some kind of bot
36
+	 *
37
+	 * @var bool
38
+	 */
39
+	protected $is_bot;
40
+
41
+	/**
42
+	 * @var RequestParams
43
+	 */
44
+	protected $request_params;
45
+
46
+	/**
47
+	 * @var RequestTypeContextCheckerInterface
48
+	 */
49
+	protected $request_type;
50
+
51
+	/**
52
+	 * @var ServerParams
53
+	 */
54
+	protected $server_params;
55
+
56
+
57
+	public function __construct(
58
+		RequestParams $request_params,
59
+		ServerParams $server_params,
60
+		array $cookies = [],
61
+		array $files = []
62
+	) {
63
+		$this->cookies = ! empty($cookies)
64
+			? $cookies
65
+			: filter_input_array(INPUT_COOKIE, FILTER_SANITIZE_STRING);
66
+		$this->files          = ! empty($files) ? $files : $_FILES;
67
+		$this->request_params = $request_params;
68
+		$this->server_params  = $server_params;
69
+	}
70
+
71
+
72
+	/**
73
+	 * @param RequestTypeContextCheckerInterface $type
74
+	 */
75
+	public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type)
76
+	{
77
+		$this->request_type = $type;
78
+	}
79
+
80
+
81
+	/**
82
+	 * @return array
83
+	 */
84
+	public function getParams()
85
+	{
86
+		return $this->request_params->getParams();
87
+	}
88
+
89
+
90
+	/**
91
+	 * @return array
92
+	 */
93
+	public function postParams()
94
+	{
95
+		return $this->request_params->postParams();
96
+	}
97
+
98
+
99
+	/**
100
+	 * @return array
101
+	 */
102
+	public function cookieParams()
103
+	{
104
+		return $this->cookies;
105
+	}
106
+
107
+
108
+	/**
109
+	 * @return array
110
+	 */
111
+	public function serverParams()
112
+	{
113
+		return $this->server_params->getAllServerParams();
114
+	}
115
+
116
+
117
+	/**
118
+	 * @param string $key
119
+	 * @param mixed|null $default
120
+	 * @return array|int|float|string
121
+	 */
122
+	public function getServerParam($key, $default = null)
123
+	{
124
+		return $this->server_params->getServerParam($key, $default);
125
+	}
126
+
127
+
128
+	/**
129
+	 * @param string                 $key
130
+	 * @param array|int|float|string $value
131
+	 * @return void
132
+	 */
133
+	public function setServerParam($key, $value)
134
+	{
135
+		$this->server_params->setServerParam($key, $value);
136
+	}
137
+
138
+
139
+	/**
140
+	 * @param string $key
141
+	 * @return bool
142
+	 */
143
+	public function serverParamIsSet($key)
144
+	{
145
+		return $this->server_params->serverParamIsSet($key);
146
+	}
147
+
148
+
149
+	/**
150
+	 * @return array
151
+	 */
152
+	public function filesParams()
153
+	{
154
+		return $this->files;
155
+	}
156
+
157
+
158
+	/**
159
+	 * returns sanitized contents of $_REQUEST
160
+	 *
161
+	 * @return array
162
+	 */
163
+	public function requestParams()
164
+	{
165
+		return $this->request_params->requestParams();
166
+	}
167
+
168
+
169
+	/**
170
+	 * @param string     $key
171
+	 * @param mixed|null $value
172
+	 * @param bool       $override_ee
173
+	 * @return void
174
+	 */
175
+	public function setRequestParam($key, $value, $override_ee = false)
176
+	{
177
+		$this->request_params->setRequestParam($key, $value, $override_ee);
178
+	}
179
+
180
+
181
+	/**
182
+	 * merges the incoming array of parameters into the existing request parameters
183
+	 *
184
+	 * @param array $request_params
185
+	 * @return void
186
+	 * @since   4.10.24.p
187
+	 */
188
+	public function mergeRequestParams(array $request_params)
189
+	{
190
+		$this->request_params->mergeRequestParams($request_params);
191
+	}
192
+
193
+
194
+	/**
195
+	 * returns sanitized value for a request param if the given key exists
196
+	 *
197
+	 * @param string     $key
198
+	 * @param mixed|null $default
199
+	 * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
200
+	 * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
201
+	 * @param string     $delimiter for CSV type strings that should be returned as an array
202
+	 * @return array|bool|float|int|string
203
+	 */
204
+	public function getRequestParam($key, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '')
205
+	{
206
+		return $this->request_params->getRequestParam($key, $default, $type, $is_array, $delimiter);
207
+	}
208
+
209
+
210
+	/**
211
+	 * check if param exists
212
+	 *
213
+	 * @param string $key
214
+	 * @return bool
215
+	 */
216
+	public function requestParamIsSet($key)
217
+	{
218
+		return $this->request_params->requestParamIsSet($key);
219
+	}
220
+
221
+
222
+	/**
223
+	 * check if a request parameter exists whose key that matches the supplied wildcard pattern
224
+	 * and return the sanitized value for the first match found
225
+	 * wildcards can be either of the following:
226
+	 *      ? to represent a single character of any type
227
+	 *      * to represent one or more characters of any type
228
+	 *
229
+	 * @param string     $pattern
230
+	 * @param mixed|null $default
231
+	 * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
232
+	 * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
233
+	 * @param string     $delimiter for CSV type strings that should be returned as an array
234
+	 * @return array|bool|float|int|string
235
+	 */
236
+	public function getMatch($pattern, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '')
237
+	{
238
+		return $this->request_params->getMatch($pattern, $default, $type, $is_array, $delimiter);
239
+	}
240
+
241
+
242
+	/**
243
+	 * check if a request parameter exists whose key matches the supplied wildcard pattern
244
+	 * wildcards can be either of the following:
245
+	 *      ? to represent a single character of any type
246
+	 *      * to represent one or more characters of any type
247
+	 * returns true if a match is found or false if not
248
+	 *
249
+	 * @param string $pattern
250
+	 * @return bool
251
+	 */
252
+	public function matches($pattern)
253
+	{
254
+		return $this->request_params->matches($pattern);
255
+	}
256
+
257
+
258
+	/**
259
+	 * remove param
260
+	 *
261
+	 * @param      $key
262
+	 * @param bool $unset_from_global_too
263
+	 */
264
+	public function unSetRequestParam($key, $unset_from_global_too = false)
265
+	{
266
+		$this->request_params->unSetRequestParam($key, $unset_from_global_too);
267
+	}
268
+
269
+
270
+	/**
271
+	 * remove param
272
+	 *
273
+	 * @param      $key
274
+	 * @param bool $unset_from_global_too
275
+	 */
276
+	public function unSetServerParam($key, $unset_from_global_too = false)
277
+	{
278
+		$this->server_params->unSetServerParam($key, $unset_from_global_too);
279
+	}
280
+
281
+
282
+	/**
283
+	 * remove params
284
+	 *
285
+	 * @param array $keys
286
+	 * @param bool  $unset_from_global_too
287
+	 */
288
+	public function unSetRequestParams(array $keys, $unset_from_global_too = false)
289
+	{
290
+		$this->request_params->unSetRequestParams($keys, $unset_from_global_too);
291
+	}
292
+
293
+
294
+	/**
295
+	 * @return string
296
+	 */
297
+	public function ipAddress()
298
+	{
299
+		return $this->server_params->ipAddress();
300
+	}
301
+
302
+
303
+	/**
304
+	 * Gets the request's literal URI. Related to `requestUriAfterSiteHomeUri`, see its description for a comparison.
305
+	 *
306
+	 * @param boolean $relativeToWpRoot If home_url() is "http://mysite.com/wp/", and a request comes to
307
+	 *                                  "http://mysite.com/wp/wp-json", setting $relativeToWpRoot=true will return
308
+	 *                                  "/wp-json", whereas $relativeToWpRoot=false will return "/wp/wp-json/".
309
+	 * @return string
310
+	 */
311
+	public function requestUri($relativeToWpRoot = false)
312
+	{
313
+		return $this->server_params->requestUri($relativeToWpRoot);
314
+	}
315
+
316
+
317
+	/**
318
+	 * @return string
319
+	 */
320
+	public function userAgent()
321
+	{
322
+		return $this->server_params->userAgent();
323
+	}
324
+
325
+
326
+	/**
327
+	 * @param string $user_agent
328
+	 */
329
+	public function setUserAgent($user_agent = '')
330
+	{
331
+		$this->server_params->setUserAgent($user_agent);
332
+	}
333
+
334
+
335
+	/**
336
+	 * @return bool
337
+	 */
338
+	public function isBot()
339
+	{
340
+		return $this->is_bot;
341
+	}
342
+
343
+
344
+	/**
345
+	 * @param bool $is_bot
346
+	 */
347
+	public function setIsBot($is_bot)
348
+	{
349
+		$this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN);
350
+	}
351
+
352
+
353
+	/**
354
+	 * @return bool
355
+	 */
356
+	public function isActivation()
357
+	{
358
+		return $this->request_type->isActivation();
359
+	}
360
+
361
+
362
+	/**
363
+	 * @param $is_activation
364
+	 * @return bool
365
+	 */
366
+	public function setIsActivation($is_activation)
367
+	{
368
+		return $this->request_type->setIsActivation($is_activation);
369
+	}
370
+
371
+
372
+	/**
373
+	 * @return bool
374
+	 */
375
+	public function isAdmin()
376
+	{
377
+		return $this->request_type->isAdmin();
378
+	}
379
+
380
+
381
+	/**
382
+	 * @return bool
383
+	 */
384
+	public function isAdminAjax()
385
+	{
386
+		return $this->request_type->isAdminAjax();
387
+	}
388
+
389
+
390
+	/**
391
+	 * @return bool
392
+	 */
393
+	public function isAjax()
394
+	{
395
+		return $this->request_type->isAjax();
396
+	}
397
+
398
+
399
+	/**
400
+	 * @return bool
401
+	 */
402
+	public function isEeAjax()
403
+	{
404
+		return $this->request_type->isEeAjax();
405
+	}
406
+
407
+
408
+	/**
409
+	 * @return bool
410
+	 */
411
+	public function isOtherAjax()
412
+	{
413
+		return $this->request_type->isOtherAjax();
414
+	}
415
+
416
+
417
+	/**
418
+	 * @return bool
419
+	 */
420
+	public function isApi()
421
+	{
422
+		return $this->request_type->isApi();
423
+	}
424
+
425
+
426
+	/**
427
+	 * @return bool
428
+	 */
429
+	public function isCli()
430
+	{
431
+		return $this->request_type->isCli();
432
+	}
433
+
434
+
435
+	/**
436
+	 * @return bool
437
+	 */
438
+	public function isCron()
439
+	{
440
+		return $this->request_type->isCron();
441
+	}
442
+
443
+
444
+	/**
445
+	 * @return bool
446
+	 */
447
+	public function isFeed()
448
+	{
449
+		return $this->request_type->isFeed();
450
+	}
451
+
452
+
453
+	/**
454
+	 * @return bool
455
+	 */
456
+	public function isFrontend()
457
+	{
458
+		return $this->request_type->isFrontend();
459
+	}
460
+
461
+
462
+	/**
463
+	 * @return bool
464
+	 */
465
+	public function isFrontAjax()
466
+	{
467
+		return $this->request_type->isFrontAjax();
468
+	}
469
+
470
+
471
+	/**
472
+	 * @return bool
473
+	 */
474
+	public function isIframe()
475
+	{
476
+		return $this->request_type->isIframe();
477
+	}
478
+
479
+
480
+	/**
481
+	 * @return bool
482
+	 */
483
+	public function isWordPressApi()
484
+	{
485
+		return $this->request_type->isWordPressApi();
486
+	}
487
+
488
+
489
+	/**
490
+	 * @return bool
491
+	 */
492
+	public function isWordPressHeartbeat()
493
+	{
494
+		return $this->request_type->isWordPressHeartbeat();
495
+	}
496
+
497
+
498
+	/**
499
+	 * @return bool
500
+	 */
501
+	public function isWordPressScrape()
502
+	{
503
+		return $this->request_type->isWordPressScrape();
504
+	}
505
+
506
+
507
+	/**
508
+	 * @return string
509
+	 */
510
+	public function slug()
511
+	{
512
+		return $this->request_type->slug();
513
+	}
514
+
515
+
516
+	/**
517
+	 * @return RequestTypeContextCheckerInterface
518
+	 */
519
+	public function getRequestType()
520
+	{
521
+		return $this->request_type;
522
+	}
523 523
 }
Please login to merge, or discard this patch.
core/data_migration_scripts/EE_DMS_Core_4_5_0.dms.php 1 patch
Indentation   +229 added lines, -229 removed lines patch added patch discarded remove patch
@@ -18,9 +18,9 @@  discard block
 block discarded – undo
18 18
 $stages = glob(EE_CORE . 'data_migration_scripts/4_5_0_stages/*');
19 19
 $class_to_filepath = array();
20 20
 foreach ($stages as $filepath) {
21
-    $matches = array();
22
-    preg_match('~4_5_0_stages/(.*).dmsstage.php~', $filepath, $matches);
23
-    $class_to_filepath[ $matches[1] ] = $filepath;
21
+	$matches = array();
22
+	preg_match('~4_5_0_stages/(.*).dmsstage.php~', $filepath, $matches);
23
+	$class_to_filepath[ $matches[1] ] = $filepath;
24 24
 }
25 25
 // give addons a chance to autoload their stages too
26 26
 $class_to_filepath = apply_filters('FHEE__EE_DMS_4_5_0__autoloaded_stages', $class_to_filepath);
@@ -33,59 +33,59 @@  discard block
 block discarded – undo
33 33
 
34 34
 
35 35
 
36
-    /**
37
-     * EE_DMS_Core_4_5_0 constructor.
38
-     *
39
-     * @param TableManager  $table_manager
40
-     * @param TableAnalysis $table_analysis
41
-     */
42
-    public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
43
-    {
44
-        $this->_pretty_name = esc_html__("Data Update to Event Espresso 4.5.0", "event_espresso");
45
-        $this->_priority = 10;
46
-        $this->_migration_stages = array(
47
-            new EE_DMS_4_5_0_update_wp_user_for_tickets(),
48
-            new EE_DMS_4_5_0_update_wp_user_for_prices(),
49
-            new EE_DMS_4_5_0_update_wp_user_for_price_types(),
50
-            new EE_DMS_4_5_0_update_wp_user_for_question_groups(),
51
-            new EE_DMS_4_5_0_invoice_settings(),
52
-        );
53
-        parent::__construct($table_manager, $table_analysis);
54
-    }
36
+	/**
37
+	 * EE_DMS_Core_4_5_0 constructor.
38
+	 *
39
+	 * @param TableManager  $table_manager
40
+	 * @param TableAnalysis $table_analysis
41
+	 */
42
+	public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
43
+	{
44
+		$this->_pretty_name = esc_html__("Data Update to Event Espresso 4.5.0", "event_espresso");
45
+		$this->_priority = 10;
46
+		$this->_migration_stages = array(
47
+			new EE_DMS_4_5_0_update_wp_user_for_tickets(),
48
+			new EE_DMS_4_5_0_update_wp_user_for_prices(),
49
+			new EE_DMS_4_5_0_update_wp_user_for_price_types(),
50
+			new EE_DMS_4_5_0_update_wp_user_for_question_groups(),
51
+			new EE_DMS_4_5_0_invoice_settings(),
52
+		);
53
+		parent::__construct($table_manager, $table_analysis);
54
+	}
55 55
 
56 56
 
57 57
 
58
-    public function can_migrate_from_version($version_array)
59
-    {
60
-        $version_string = $version_array['Core'];
61
-        if (version_compare($version_string, '4.5.0.decaf', '<') && version_compare($version_string, '4.3.0.decaf', '>=')) {
58
+	public function can_migrate_from_version($version_array)
59
+	{
60
+		$version_string = $version_array['Core'];
61
+		if (version_compare($version_string, '4.5.0.decaf', '<') && version_compare($version_string, '4.3.0.decaf', '>=')) {
62 62
 //          echo "$version_string can be migrated from";
63
-            return true;
64
-        } elseif (! $version_string) {
63
+			return true;
64
+		} elseif (! $version_string) {
65 65
 //          echo "no version string provided: $version_string";
66
-            // no version string provided... this must be pre 4.3
67
-            return false;// changed mind. dont want people thinking they should migrate yet because they cant
68
-        } else {
66
+			// no version string provided... this must be pre 4.3
67
+			return false;// changed mind. dont want people thinking they should migrate yet because they cant
68
+		} else {
69 69
 //          echo "$version_string doesnt apply";
70
-            return false;
71
-        }
72
-    }
70
+			return false;
71
+		}
72
+	}
73 73
 
74 74
 
75 75
 
76
-    public function schema_changes_before_migration()
77
-    {
78
-        // relies on 4.1's EEH_Activation::create_table
79
-        require_once(EE_HELPERS . 'EEH_Activation.helper.php');
80
-        $table_name = 'esp_answer';
81
-        $sql = "ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
76
+	public function schema_changes_before_migration()
77
+	{
78
+		// relies on 4.1's EEH_Activation::create_table
79
+		require_once(EE_HELPERS . 'EEH_Activation.helper.php');
80
+		$table_name = 'esp_answer';
81
+		$sql = "ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
82 82
 					REG_ID int(10) unsigned NOT NULL,
83 83
 					QST_ID int(10) unsigned NOT NULL,
84 84
 					ANS_value text NOT NULL,
85 85
 					PRIMARY KEY  (ANS_ID)";
86
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
87
-        $table_name = 'esp_attendee_meta';
88
-        $sql = "ATTM_ID int(10) unsigned NOT	NULL AUTO_INCREMENT,
86
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
87
+		$table_name = 'esp_attendee_meta';
88
+		$sql = "ATTM_ID int(10) unsigned NOT	NULL AUTO_INCREMENT,
89 89
 						ATT_ID bigint(20) unsigned NOT NULL,
90 90
 						ATT_fname varchar(45) NOT NULL,
91 91
 						ATT_lname varchar(45) NOT	NULL,
@@ -101,9 +101,9 @@  discard block
 block discarded – undo
101 101
 								KEY ATT_fname (ATT_fname),
102 102
 								KEY ATT_lname (ATT_lname),
103 103
 								KEY ATT_email (ATT_email(191))";
104
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
105
-        $table_name = 'esp_country';
106
-        $sql = "CNT_ISO varchar(2) COLLATE utf8_bin NOT NULL,
104
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
105
+		$table_name = 'esp_country';
106
+		$sql = "CNT_ISO varchar(2) COLLATE utf8_bin NOT NULL,
107 107
 					  CNT_ISO3 varchar(3) COLLATE utf8_bin NOT NULL,
108 108
 					  RGN_ID tinyint(3) unsigned DEFAULT NULL,
109 109
 					  CNT_name varchar(45) COLLATE utf8_bin NOT NULL,
@@ -119,9 +119,9 @@  discard block
 block discarded – undo
119 119
 					  CNT_is_EU tinyint(1) DEFAULT '0',
120 120
 					  CNT_active tinyint(1) DEFAULT '0',
121 121
 					  PRIMARY KEY  (CNT_ISO)";
122
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
123
-        $table_name = 'esp_datetime';
124
-        $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
122
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
123
+		$table_name = 'esp_datetime';
124
+		$sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
125 125
 				  EVT_ID bigint(20) unsigned NOT NULL,
126 126
 				  DTT_name varchar(255) NOT NULL DEFAULT '',
127 127
 				  DTT_description text NOT NULL,
@@ -136,9 +136,9 @@  discard block
 block discarded – undo
136 136
 						PRIMARY KEY  (DTT_ID),
137 137
 						KEY EVT_ID (EVT_ID),
138 138
 						KEY DTT_is_primary (DTT_is_primary)";
139
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
140
-        $table_name = 'esp_event_meta';
141
-        $sql = "
139
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
140
+		$table_name = 'esp_event_meta';
141
+		$sql = "
142 142
 			EVTM_ID int(10) NOT NULL AUTO_INCREMENT,
143 143
 			EVT_ID bigint(20) unsigned NOT NULL,
144 144
 			EVT_display_desc tinyint(1) unsigned NOT NULL DEFAULT 1,
@@ -153,31 +153,31 @@  discard block
 block discarded – undo
153 153
 			EVT_external_URL varchar(200) NULL,
154 154
 			EVT_donations tinyint(1) NULL,
155 155
 			PRIMARY KEY  (EVTM_ID)";
156
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
157
-        $table_name = 'esp_event_question_group';
158
-        $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
156
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
157
+		$table_name = 'esp_event_question_group';
158
+		$sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
159 159
 					EVT_ID bigint(20) unsigned NOT NULL,
160 160
 					QSG_ID int(10) unsigned NOT NULL,
161 161
 					EQG_primary tinyint(1) unsigned NOT NULL DEFAULT 0,
162 162
 					PRIMARY KEY  (EQG_ID)";
163
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
164
-        $table_name = 'esp_event_venue';
165
-        $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT,
163
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
164
+		$table_name = 'esp_event_venue';
165
+		$sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT,
166 166
 				EVT_ID bigint(20) unsigned NOT NULL,
167 167
 				VNU_ID bigint(20) unsigned NOT NULL,
168 168
 				EVV_primary tinyint(1) unsigned NOT NULL DEFAULT 0,
169 169
 				PRIMARY KEY  (EVV_ID)";
170
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
171
-        $table_name = 'esp_extra_meta';
172
-        $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT,
170
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
171
+		$table_name = 'esp_extra_meta';
172
+		$sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT,
173 173
 				OBJ_ID int(11) DEFAULT NULL,
174 174
 				EXM_type varchar(45) DEFAULT NULL,
175 175
 				EXM_key varchar(45) DEFAULT NULL,
176 176
 				EXM_value text,
177 177
 				PRIMARY KEY  (EXM_ID)";
178
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
179
-        $table_name = 'esp_line_item';
180
-        $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT,
178
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
179
+		$table_name = 'esp_line_item';
180
+		$sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT,
181 181
 				LIN_code varchar(245) NOT NULL DEFAULT '',
182 182
 				TXN_ID int(11) DEFAULT NULL,
183 183
 				LIN_name varchar(245) NOT NULL DEFAULT '',
@@ -193,19 +193,19 @@  discard block
 block discarded – undo
193 193
 				OBJ_ID int(11) DEFAULT NULL,
194 194
 				OBJ_type varchar(45)DEFAULT NULL,
195 195
 				PRIMARY KEY  (LIN_ID)";
196
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
197
-        $table_name = 'esp_message_template';
198
-        $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
196
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
197
+		$table_name = 'esp_message_template';
198
+		$sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
199 199
 					GRP_ID int(10) unsigned NOT NULL,
200 200
 					MTP_context varchar(50) NOT NULL,
201 201
 					MTP_template_field varchar(30) NOT NULL,
202 202
 					MTP_content text NOT NULL,
203 203
 					PRIMARY KEY  (MTP_ID),
204 204
 					KEY GRP_ID (GRP_ID)";
205
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
206
-        $this->_get_table_manager()->dropIndex('esp_message_template_group', 'EVT_ID');
207
-        $table_name = 'esp_message_template_group';
208
-        $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
205
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
206
+		$this->_get_table_manager()->dropIndex('esp_message_template_group', 'EVT_ID');
207
+		$table_name = 'esp_message_template_group';
208
+		$sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
209 209
 					MTP_user_id int(10) NOT NULL DEFAULT '1',
210 210
 					MTP_name varchar(245) NOT NULL DEFAULT '',
211 211
 					MTP_description varchar(245) NOT NULL DEFAULT '',
@@ -217,17 +217,17 @@  discard block
 block discarded – undo
217 217
 					MTP_is_active tinyint(1) NOT NULL DEFAULT '1',
218 218
 					PRIMARY KEY  (GRP_ID),
219 219
 					KEY MTP_user_id (MTP_user_id)";
220
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
221
-        $table_name = 'esp_event_message_template';
222
-        $sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
220
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
221
+		$table_name = 'esp_event_message_template';
222
+		$sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
223 223
 					EVT_ID bigint(20) unsigned NOT NULL DEFAULT 0,
224 224
 					GRP_ID int(10) unsigned NOT NULL DEFAULT 0,
225 225
 					PRIMARY KEY  (EMT_ID),
226 226
 					KEY EVT_ID (EVT_ID),
227 227
 					KEY GRP_ID (GRP_ID)";
228
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
229
-        $table_name = 'esp_payment';
230
-        $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
228
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
229
+		$table_name = 'esp_payment';
230
+		$sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
231 231
 					TXN_ID int(10) unsigned DEFAULT NULL,
232 232
 					STS_ID varchar(3) COLLATE utf8_bin DEFAULT NULL,
233 233
 					PAY_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
@@ -243,28 +243,28 @@  discard block
 block discarded – undo
243 243
 					PRIMARY KEY  (PAY_ID),
244 244
 					KEY TXN_ID (TXN_ID),
245 245
 					KEY PAY_timestamp (PAY_timestamp)";
246
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
247
-        $table_name = "esp_ticket_price";
248
-        $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
246
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
247
+		$table_name = "esp_ticket_price";
248
+		$sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
249 249
 					  TKT_ID int(10) unsigned NOT NULL,
250 250
 					  PRC_ID int(10) unsigned NOT NULL,
251 251
 					  PRIMARY KEY  (TKP_ID)";
252
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
253
-        $table_name = "esp_datetime_ticket";
254
-        $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
252
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
253
+		$table_name = "esp_datetime_ticket";
254
+		$sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
255 255
 					  DTT_ID int(10) unsigned NOT NULL,
256 256
 					  TKT_ID int(10) unsigned NOT NULL,
257 257
 					  PRIMARY KEY  (DTK_ID)";
258
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
259
-        $table_name = "esp_ticket_template";
260
-        $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
258
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
259
+		$table_name = "esp_ticket_template";
260
+		$sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
261 261
 					  TTM_name varchar(45) NOT NULL,
262 262
 					  TTM_description text,
263 263
 					  TTM_file varchar(45),
264 264
 					  PRIMARY KEY  (TTM_ID)";
265
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
266
-        $table_name = 'esp_question';
267
-        $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
265
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
266
+		$table_name = 'esp_question';
267
+		$sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
268 268
 					QST_display_text text NOT NULL,
269 269
 					QST_admin_label varchar(255) NOT NULL,
270 270
 					QST_system varchar(25) DEFAULT NULL,
@@ -276,25 +276,25 @@  discard block
 block discarded – undo
276 276
 					QST_wp_user bigint(20) unsigned NULL,
277 277
 					QST_deleted tinyint(1) unsigned NOT NULL DEFAULT 0,
278 278
 					PRIMARY KEY  (QST_ID)';
279
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
280
-        $table_name = 'esp_question_group_question';
281
-        $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
279
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
280
+		$table_name = 'esp_question_group_question';
281
+		$sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
282 282
 					QSG_ID int(10) unsigned NOT NULL,
283 283
 					QST_ID int(10) unsigned NOT NULL,
284 284
 					QGQ_order int(10) unsigned NOT NULL DEFAULT 0,
285 285
 					PRIMARY KEY  (QGQ_ID) ";
286
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
287
-        $table_name = 'esp_question_option';
288
-        $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
286
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
287
+		$table_name = 'esp_question_option';
288
+		$sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
289 289
 					QSO_value varchar(255) NOT NULL,
290 290
 					QSO_desc text NOT NULL,
291 291
 					QST_ID int(10) unsigned NOT NULL,
292 292
 					QSO_order int(10) unsigned NOT NULL DEFAULT 0,
293 293
 					QSO_deleted tinyint(1) unsigned NOT NULL DEFAULT 0,
294 294
 					PRIMARY KEY  (QSO_ID)";
295
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
296
-        $table_name = 'esp_registration';
297
-        $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
295
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
296
+		$table_name = 'esp_registration';
297
+		$sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
298 298
 					  EVT_ID bigint(20) unsigned NOT NULL,
299 299
 					  ATT_ID bigint(20) unsigned NOT NULL,
300 300
 					  TXN_ID int(10) unsigned NOT NULL,
@@ -317,25 +317,25 @@  discard block
 block discarded – undo
317 317
 					  KEY STS_ID (STS_ID),
318 318
 					  KEY REG_url_link (REG_url_link),
319 319
 					  KEY REG_code (REG_code)";
320
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
321
-        $table_name = 'esp_checkin';
322
-        $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
320
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
321
+		$table_name = 'esp_checkin';
322
+		$sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
323 323
 					REG_ID int(10) unsigned NOT NULL,
324 324
 					DTT_ID int(10) unsigned NOT NULL,
325 325
 					CHK_in tinyint(1) unsigned NOT NULL DEFAULT 1,
326 326
 					CHK_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
327 327
 					PRIMARY KEY  (CHK_ID)";
328
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
329
-        $table_name = 'esp_state';
330
-        $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT,
328
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
329
+		$table_name = 'esp_state';
330
+		$sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT,
331 331
 					  CNT_ISO varchar(2) COLLATE utf8_bin NOT NULL,
332 332
 					  STA_abbrev varchar(6) COLLATE utf8_bin NOT NULL,
333 333
 					  STA_name varchar(100) COLLATE utf8_bin NOT NULL,
334 334
 					  STA_active tinyint(1) DEFAULT '1',
335 335
 					  PRIMARY KEY  (STA_ID)";
336
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
337
-        $table_name = 'esp_status';
338
-        $sql = "STS_ID varchar(3) COLLATE utf8_bin NOT NULL,
336
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
337
+		$table_name = 'esp_status';
338
+		$sql = "STS_ID varchar(3) COLLATE utf8_bin NOT NULL,
339 339
 					  STS_code varchar(45) COLLATE utf8_bin NOT NULL,
340 340
 					  STS_type set('event','registration','transaction','payment','email') COLLATE utf8_bin NOT NULL,
341 341
 					  STS_can_edit tinyint(1) NOT NULL DEFAULT 0,
@@ -343,9 +343,9 @@  discard block
 block discarded – undo
343 343
 					  STS_open tinyint(1) NOT NULL DEFAULT 1,
344 344
 					  UNIQUE KEY STS_ID_UNIQUE (STS_ID),
345 345
 					  KEY STS_type (STS_type)";
346
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
347
-        $table_name = 'esp_transaction';
348
-        $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
346
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
347
+		$table_name = 'esp_transaction';
348
+		$sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
349 349
 					  TXN_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
350 350
 					  TXN_total decimal(10,3) DEFAULT '0.00',
351 351
 					  TXN_paid decimal(10,3) NOT NULL DEFAULT '0.00',
@@ -356,9 +356,9 @@  discard block
 block discarded – undo
356 356
 					  PRIMARY KEY  (TXN_ID),
357 357
 					  KEY TXN_timestamp (TXN_timestamp),
358 358
 					  KEY STS_ID (STS_ID)";
359
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
360
-        $table_name = 'esp_venue_meta';
361
-        $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT,
359
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
360
+		$table_name = 'esp_venue_meta';
361
+		$sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT,
362 362
 			VNU_ID bigint(20) unsigned NOT NULL DEFAULT 0,
363 363
 			VNU_address varchar(255) DEFAULT NULL,
364 364
 			VNU_address2 varchar(255) DEFAULT NULL,
@@ -376,10 +376,10 @@  discard block
 block discarded – undo
376 376
 			PRIMARY KEY  (VNUM_ID),
377 377
 			KEY STA_ID (STA_ID),
378 378
 			KEY CNT_ISO (CNT_ISO)";
379
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
380
-        // modified tables
381
-        $table_name = "esp_price";
382
-        $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
379
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
380
+		// modified tables
381
+		$table_name = "esp_price";
382
+		$sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
383 383
 					  PRT_ID tinyint(3) unsigned NOT NULL,
384 384
 					  PRC_amount decimal(10,3) NOT NULL DEFAULT '0.00',
385 385
 					  PRC_name varchar(245) NOT NULL,
@@ -391,9 +391,9 @@  discard block
 block discarded – undo
391 391
 					  PRC_wp_user bigint(20) unsigned NULL,
392 392
 					  PRC_parent int(10) unsigned DEFAULT 0,
393 393
 					  PRIMARY KEY  (PRC_ID)";
394
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
395
-        $table_name = "esp_price_type";
396
-        $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
394
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
395
+		$table_name = "esp_price_type";
396
+		$sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
397 397
 				  PRT_name varchar(45) NOT NULL,
398 398
 				  PBT_ID tinyint(3) unsigned NOT NULL DEFAULT '1',
399 399
 				  PRT_is_percent tinyint(1) NOT NULL DEFAULT '0',
@@ -402,9 +402,9 @@  discard block
 block discarded – undo
402 402
 				  PRT_deleted tinyint(1) NOT NULL DEFAULT '0',
403 403
 				  UNIQUE KEY PRT_name_UNIQUE (PRT_name),
404 404
 				  PRIMARY KEY  (PRT_ID)";
405
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
406
-        $table_name = "esp_ticket";
407
-        $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
405
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
406
+		$table_name = "esp_ticket";
407
+		$sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
408 408
 					  TTM_ID int(10) unsigned NOT NULL,
409 409
 					  TKT_name varchar(245) NOT NULL DEFAULT '',
410 410
 					  TKT_description text NOT NULL,
@@ -425,10 +425,10 @@  discard block
 block discarded – undo
425 425
 					  TKT_parent int(10) unsigned DEFAULT '0',
426 426
 					  TKT_deleted tinyint(1) NOT NULL DEFAULT '0',
427 427
 					  PRIMARY KEY  (TKT_ID)";
428
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
429
-        $this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_identifier_UNIQUE');
430
-        $table_name = 'esp_question_group';
431
-        $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
428
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
429
+		$this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_identifier_UNIQUE');
430
+		$table_name = 'esp_question_group';
431
+		$sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
432 432
 					QSG_name varchar(255) NOT NULL,
433 433
 					QSG_identifier varchar(100) NOT NULL,
434 434
 					QSG_desc text NULL,
@@ -440,133 +440,133 @@  discard block
 block discarded – undo
440 440
 					QSG_wp_user bigint(20) unsigned NULL,
441 441
 					PRIMARY KEY  (QSG_ID),
442 442
 					UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier ASC)';
443
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
444
-        $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0');
445
-        // (because many need to convert old string states to foreign keys into the states table)
446
-        $script_4_1_defaults->insert_default_states();
447
-        $script_4_1_defaults->insert_default_countries();
448
-        // schema on price, price_types and tickets has changed so use the DEFAULT method in here instead of 4.1's and later.
449
-        $this->insert_default_price_types();
450
-        $this->insert_default_prices();
451
-        $this->insert_default_tickets();
452
-        // setting up the config wp option pretty well counts as a 'schema change', or at least should happen ehre
453
-        EE_Config::instance()->update_espresso_config(false, true);
454
-        return true;
455
-    }
443
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
444
+		$script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0');
445
+		// (because many need to convert old string states to foreign keys into the states table)
446
+		$script_4_1_defaults->insert_default_states();
447
+		$script_4_1_defaults->insert_default_countries();
448
+		// schema on price, price_types and tickets has changed so use the DEFAULT method in here instead of 4.1's and later.
449
+		$this->insert_default_price_types();
450
+		$this->insert_default_prices();
451
+		$this->insert_default_tickets();
452
+		// setting up the config wp option pretty well counts as a 'schema change', or at least should happen ehre
453
+		EE_Config::instance()->update_espresso_config(false, true);
454
+		return true;
455
+	}
456 456
 
457 457
 
458 458
 
459
-    /**
460
-     * @return boolean
461
-     */
462
-    public function schema_changes_after_migration()
463
-    {
464
-        return true;
465
-    }
459
+	/**
460
+	 * @return boolean
461
+	 */
462
+	public function schema_changes_after_migration()
463
+	{
464
+		return true;
465
+	}
466 466
 
467 467
 
468 468
 
469
-    public function migration_page_hooks()
470
-    {
471
-    }
469
+	public function migration_page_hooks()
470
+	{
471
+	}
472 472
 
473 473
 
474 474
 
475
-    /**
476
-     * insert_default_price_types
477
-     *
478
-     * @since 4.5.0
479
-     * @return void
480
-     */
481
-    public function insert_default_price_types()
482
-    {
483
-        global $wpdb;
484
-        $price_type_table = $wpdb->prefix . "esp_price_type";
485
-        if ($this->_get_table_analysis()->tableExists($price_type_table)) {
486
-            $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table;
487
-            $price_types_exist = $wpdb->get_var($SQL);
488
-            if (! $price_types_exist) {
489
-                $user_id = EEH_Activation::get_default_creator_id();
490
-                $SQL = "INSERT INTO $price_type_table ( PRT_ID, PRT_name, PBT_ID, PRT_is_percent, PRT_order, PRT_wp_user, PRT_deleted ) VALUES
475
+	/**
476
+	 * insert_default_price_types
477
+	 *
478
+	 * @since 4.5.0
479
+	 * @return void
480
+	 */
481
+	public function insert_default_price_types()
482
+	{
483
+		global $wpdb;
484
+		$price_type_table = $wpdb->prefix . "esp_price_type";
485
+		if ($this->_get_table_analysis()->tableExists($price_type_table)) {
486
+			$SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table;
487
+			$price_types_exist = $wpdb->get_var($SQL);
488
+			if (! $price_types_exist) {
489
+				$user_id = EEH_Activation::get_default_creator_id();
490
+				$SQL = "INSERT INTO $price_type_table ( PRT_ID, PRT_name, PBT_ID, PRT_is_percent, PRT_order, PRT_wp_user, PRT_deleted ) VALUES
491 491
 							(1, '" . esc_html__('Base Price', 'event_espresso') . "', 1,  0, 0, $user_id, 0),
492 492
 							(2, '" . esc_html__('Percent Discount', 'event_espresso') . "', 2,  1, 20, $user_id, 0),
493 493
 							(3, '" . esc_html__('Dollar Discount', 'event_espresso') . "', 2,  0, 30, $user_id, 0),
494 494
 							(4, '" . esc_html__('Percent Surcharge', 'event_espresso') . "', 3,  1, 40, $user_id,  0),
495 495
 							(5, '" . esc_html__('Dollar Surcharge', 'event_espresso') . "', 3,  0, 50, $user_id, 0);";
496
-                $SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_price_types__SQL', $SQL);
497
-                $wpdb->query($SQL);
498
-            }
499
-        }
500
-    }
496
+				$SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_price_types__SQL', $SQL);
497
+				$wpdb->query($SQL);
498
+			}
499
+		}
500
+	}
501 501
 
502 502
 
503 503
 
504
-    /**
505
-     * insert DEFAULT prices.
506
-     *  If we're INSTALLING 4.x CAF, then we add a few extra DEFAULT prices
507
-     * when EEH_Activaion's initialize_db_content is called via  ahook in
508
-     * EE_Brewing_regular
509
-     *
510
-     * @since 4.5.0
511
-     * @return void
512
-     */
513
-    public function insert_default_prices()
514
-    {
515
-        global $wpdb;
516
-        $price_table = $wpdb->prefix . "esp_price";
517
-        if ($this->_get_table_analysis()->tableExists($price_table)) {
518
-            $SQL = 'SELECT COUNT(PRC_ID) FROM ' . $price_table;
519
-            $prices_exist = $wpdb->get_var($SQL);
520
-            if (! $prices_exist) {
521
-                $user_id = EEH_Activation::get_default_creator_id();
522
-                $SQL = "INSERT INTO $price_table
504
+	/**
505
+	 * insert DEFAULT prices.
506
+	 *  If we're INSTALLING 4.x CAF, then we add a few extra DEFAULT prices
507
+	 * when EEH_Activaion's initialize_db_content is called via  ahook in
508
+	 * EE_Brewing_regular
509
+	 *
510
+	 * @since 4.5.0
511
+	 * @return void
512
+	 */
513
+	public function insert_default_prices()
514
+	{
515
+		global $wpdb;
516
+		$price_table = $wpdb->prefix . "esp_price";
517
+		if ($this->_get_table_analysis()->tableExists($price_table)) {
518
+			$SQL = 'SELECT COUNT(PRC_ID) FROM ' . $price_table;
519
+			$prices_exist = $wpdb->get_var($SQL);
520
+			if (! $prices_exist) {
521
+				$user_id = EEH_Activation::get_default_creator_id();
522
+				$SQL = "INSERT INTO $price_table
523 523
 							(PRC_ID, PRT_ID, PRC_amount, PRC_name, PRC_desc,  PRC_is_default, PRC_overrides, PRC_wp_user, PRC_order, PRC_deleted, PRC_parent ) VALUES
524 524
 							(1, 1, '0.00', 'Admission', '', 1, NULL, $user_id, 0, 0, 0);";
525
-                $SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_prices__SQL', $SQL);
526
-                $wpdb->query($SQL);
527
-            }
528
-        }
529
-    }
525
+				$SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_prices__SQL', $SQL);
526
+				$wpdb->query($SQL);
527
+			}
528
+		}
529
+	}
530 530
 
531 531
 
532 532
 
533
-    /**
534
-     * insert DEFAULT ticket
535
-     * Almost identical to EE_DMS_Core_4_3_0::insert_default_tickets, except is aware of the TKT_wp_user field
536
-     *
537
-     * @since 4.5.0
538
-     * @return void
539
-     */
540
-    public function insert_default_tickets()
541
-    {
542
-        global $wpdb;
543
-        $ticket_table = $wpdb->prefix . "esp_ticket";
544
-        if ($this->_get_table_analysis()->tableExists($ticket_table)) {
545
-            $SQL = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table;
546
-            $tickets_exist = $wpdb->get_var($SQL);
547
-            if (! $tickets_exist) {
548
-                $user_id = EEH_Activation::get_default_creator_id();
549
-                $SQL = "INSERT INTO $ticket_table
533
+	/**
534
+	 * insert DEFAULT ticket
535
+	 * Almost identical to EE_DMS_Core_4_3_0::insert_default_tickets, except is aware of the TKT_wp_user field
536
+	 *
537
+	 * @since 4.5.0
538
+	 * @return void
539
+	 */
540
+	public function insert_default_tickets()
541
+	{
542
+		global $wpdb;
543
+		$ticket_table = $wpdb->prefix . "esp_ticket";
544
+		if ($this->_get_table_analysis()->tableExists($ticket_table)) {
545
+			$SQL = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table;
546
+			$tickets_exist = $wpdb->get_var($SQL);
547
+			if (! $tickets_exist) {
548
+				$user_id = EEH_Activation::get_default_creator_id();
549
+				$SQL = "INSERT INTO $ticket_table
550 550
 					( TKT_ID, TTM_ID, TKT_name, TKT_description, TKT_qty, TKT_sold, TKT_uses, TKT_required, TKT_min, TKT_max, TKT_price, TKT_start_date, TKT_end_date, TKT_taxable, TKT_order, TKT_row, TKT_is_default, TKT_parent, TKT_wp_user, TKT_deleted ) VALUES
551 551
 					( 1, 0, '"
552
-                       . esc_html__("Free Ticket", "event_espresso")
553
-                       . "', '', 100, 0, -1, 0, 0, -1, 0.00, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0, 0, 1, 1, 0, $user_id, 0);";
554
-                $SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_tickets__SQL', $SQL);
555
-                $wpdb->query($SQL);
556
-            }
557
-        }
558
-        $ticket_price_table = $wpdb->prefix . "esp_ticket_price";
559
-        if ($this->_get_table_analysis()->tableExists($ticket_price_table)) {
560
-            $SQL = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table;
561
-            $ticket_prc_exist = $wpdb->get_var($SQL);
562
-            if (! $ticket_prc_exist) {
563
-                $SQL = "INSERT INTO $ticket_price_table
552
+					   . esc_html__("Free Ticket", "event_espresso")
553
+					   . "', '', 100, 0, -1, 0, 0, -1, 0.00, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0, 0, 1, 1, 0, $user_id, 0);";
554
+				$SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_tickets__SQL', $SQL);
555
+				$wpdb->query($SQL);
556
+			}
557
+		}
558
+		$ticket_price_table = $wpdb->prefix . "esp_ticket_price";
559
+		if ($this->_get_table_analysis()->tableExists($ticket_price_table)) {
560
+			$SQL = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table;
561
+			$ticket_prc_exist = $wpdb->get_var($SQL);
562
+			if (! $ticket_prc_exist) {
563
+				$SQL = "INSERT INTO $ticket_price_table
564 564
 				( TKP_ID, TKT_ID, PRC_ID ) VALUES
565 565
 				( 1, 1, 1 )
566 566
 				";
567
-                $SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_tickets__SQL__ticket_price', $SQL);
568
-                $wpdb->query($SQL);
569
-            }
570
-        }
571
-    }
567
+				$SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_tickets__SQL__ticket_price', $SQL);
568
+				$wpdb->query($SQL);
569
+			}
570
+		}
571
+	}
572 572
 }
Please login to merge, or discard this patch.
core/data_migration_scripts/EE_DMS_Core_4_1_0.dms.php 2 patches
Indentation   +1178 added lines, -1178 removed lines patch added patch discarded remove patch
@@ -14,11 +14,11 @@  discard block
 block discarded – undo
14 14
 $stages = glob(EE_CORE . 'data_migration_scripts/4_1_0_stages/*');
15 15
 $class_to_filepath = array();
16 16
 if (! empty($stages)) {
17
-    foreach ($stages as $filepath) {
18
-        $matches = array();
19
-        preg_match('~4_1_0_stages/(.*).dmsstage.php~', $filepath, $matches);
20
-        $class_to_filepath[ $matches[1] ] = $filepath;
21
-    }
17
+	foreach ($stages as $filepath) {
18
+		$matches = array();
19
+		preg_match('~4_1_0_stages/(.*).dmsstage.php~', $filepath, $matches);
20
+		$class_to_filepath[ $matches[1] ] = $filepath;
21
+	}
22 22
 }
23 23
 // give addons a chance to autoload their stages too
24 24
 $class_to_filepath = apply_filters('FHEE__EE_DMS_4_1_0__autoloaded_stages', $class_to_filepath);
@@ -46,91 +46,91 @@  discard block
 block discarded – undo
46 46
 
47 47
 
48 48
 
49
-    /**
50
-     * EE_DMS_Core_4_1_0 constructor.
51
-     *
52
-     * @param TableManager  $table_manager
53
-     * @param TableAnalysis $table_analysis
54
-     */
55
-    public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
56
-    {
57
-        $this->_pretty_name = esc_html__("Data Migration from Event Espresso 3 to Event Espresso 4.1.0", "event_espresso");
58
-        $this->_priority = 10;
59
-        $this->_migration_stages = array(
60
-                new EE_DMS_4_1_0_org_options(),
61
-                new EE_DMS_4_1_0_shortcodes(),
62
-                new EE_DMS_4_1_0_gateways(),
63
-                new EE_DMS_4_1_0_events(),
64
-                new EE_DMS_4_1_0_prices(),
65
-                new EE_DMS_4_1_0_category_details(),
66
-                new EE_DMS_4_1_0_event_category(),
67
-                new EE_DMS_4_1_0_venues(),
68
-                new EE_DMS_4_1_0_event_venue(),
69
-                new EE_DMS_4_1_0_question_groups(),
70
-                new EE_DMS_4_1_0_questions(),
71
-                new EE_DMS_4_1_0_question_group_question(),
72
-                new EE_DMS_4_1_0_event_question_group(),
73
-                new EE_DMS_4_1_0_attendees(),
74
-                new EE_DMS_4_1_0_line_items(),
75
-                new EE_DMS_4_1_0_answers(),
76
-                new EE_DMS_4_1_0_checkins(),
77
-        );
78
-        parent::__construct($table_manager, $table_analysis);
79
-    }
80
-
81
-
82
-
83
-    /**
84
-     * Checks if this 3.1 Check-in table exists. If it doesn't we can't migrate Check-ins
85
-     *
86
-     * @global wpdb $wpdb
87
-     * @return boolean
88
-     */
89
-    private function _checkin_table_exists()
90
-    {
91
-        global $wpdb;
92
-        $results = $wpdb->get_results("SHOW TABLES LIKE '" . $wpdb->prefix . "events_attendee_checkin" . "'");
93
-        if ($results) {
94
-            return true;
95
-        } else {
96
-            return false;
97
-        }
98
-    }
99
-
100
-
101
-
102
-    public function can_migrate_from_version($version_array)
103
-    {
104
-        $version_string = $version_array['Core'];
105
-        if (version_compare($version_string, '4.0.0.decaf', '<') && version_compare($version_string, '3.1.26', '>=')) {
49
+	/**
50
+	 * EE_DMS_Core_4_1_0 constructor.
51
+	 *
52
+	 * @param TableManager  $table_manager
53
+	 * @param TableAnalysis $table_analysis
54
+	 */
55
+	public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
56
+	{
57
+		$this->_pretty_name = esc_html__("Data Migration from Event Espresso 3 to Event Espresso 4.1.0", "event_espresso");
58
+		$this->_priority = 10;
59
+		$this->_migration_stages = array(
60
+				new EE_DMS_4_1_0_org_options(),
61
+				new EE_DMS_4_1_0_shortcodes(),
62
+				new EE_DMS_4_1_0_gateways(),
63
+				new EE_DMS_4_1_0_events(),
64
+				new EE_DMS_4_1_0_prices(),
65
+				new EE_DMS_4_1_0_category_details(),
66
+				new EE_DMS_4_1_0_event_category(),
67
+				new EE_DMS_4_1_0_venues(),
68
+				new EE_DMS_4_1_0_event_venue(),
69
+				new EE_DMS_4_1_0_question_groups(),
70
+				new EE_DMS_4_1_0_questions(),
71
+				new EE_DMS_4_1_0_question_group_question(),
72
+				new EE_DMS_4_1_0_event_question_group(),
73
+				new EE_DMS_4_1_0_attendees(),
74
+				new EE_DMS_4_1_0_line_items(),
75
+				new EE_DMS_4_1_0_answers(),
76
+				new EE_DMS_4_1_0_checkins(),
77
+		);
78
+		parent::__construct($table_manager, $table_analysis);
79
+	}
80
+
81
+
82
+
83
+	/**
84
+	 * Checks if this 3.1 Check-in table exists. If it doesn't we can't migrate Check-ins
85
+	 *
86
+	 * @global wpdb $wpdb
87
+	 * @return boolean
88
+	 */
89
+	private function _checkin_table_exists()
90
+	{
91
+		global $wpdb;
92
+		$results = $wpdb->get_results("SHOW TABLES LIKE '" . $wpdb->prefix . "events_attendee_checkin" . "'");
93
+		if ($results) {
94
+			return true;
95
+		} else {
96
+			return false;
97
+		}
98
+	}
99
+
100
+
101
+
102
+	public function can_migrate_from_version($version_array)
103
+	{
104
+		$version_string = $version_array['Core'];
105
+		if (version_compare($version_string, '4.0.0.decaf', '<') && version_compare($version_string, '3.1.26', '>=')) {
106 106
 //          echo "$version_string can be migrated fro";
107
-            return true;
108
-        } elseif (! $version_string) {
107
+			return true;
108
+		} elseif (! $version_string) {
109 109
 //          echo "no version string provided: $version_string";
110
-            // no version string provided... this must be pre 4.1
111
-            // because since 4.1 we're
112
-            return false;// changed mind. dont want people thinking they should migrate yet because they cant
113
-        } else {
110
+			// no version string provided... this must be pre 4.1
111
+			// because since 4.1 we're
112
+			return false;// changed mind. dont want people thinking they should migrate yet because they cant
113
+		} else {
114 114
 //          echo "$version_string doesnt apply";
115
-            return false;
116
-        }
117
-    }
115
+			return false;
116
+		}
117
+	}
118 118
 
119 119
 
120 120
 
121
-    public function schema_changes_before_migration()
122
-    {
123
-        // relies on 4.1's EEH_Activation::create_table
124
-        require_once(EE_HELPERS . 'EEH_Activation.helper.php');
125
-        $table_name = 'esp_answer';
126
-        $sql = "ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
121
+	public function schema_changes_before_migration()
122
+	{
123
+		// relies on 4.1's EEH_Activation::create_table
124
+		require_once(EE_HELPERS . 'EEH_Activation.helper.php');
125
+		$table_name = 'esp_answer';
126
+		$sql = "ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
127 127
 					REG_ID int(10) unsigned NOT NULL,
128 128
 					QST_ID int(10) unsigned NOT NULL,
129 129
 					ANS_value text NOT NULL,
130 130
 					PRIMARY KEY  (ANS_ID)";
131
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
132
-        $table_name = 'esp_attendee_meta';
133
-        $sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
131
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
132
+		$table_name = 'esp_attendee_meta';
133
+		$sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
134 134
 						ATT_ID bigint(20) unsigned NOT NULL,
135 135
 						ATT_fname varchar(45) NOT NULL,
136 136
 						ATT_lname varchar(45) NOT NULL,
@@ -146,9 +146,9 @@  discard block
 block discarded – undo
146 146
 								KEY ATT_fname (ATT_fname),
147 147
 								KEY ATT_lname (ATT_lname),
148 148
 								KEY ATT_email (ATT_email(191))";
149
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
150
-        $table_name = 'esp_country';
151
-        $sql = "CNT_ISO varchar(2) COLLATE utf8_bin NOT NULL,
149
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
150
+		$table_name = 'esp_country';
151
+		$sql = "CNT_ISO varchar(2) COLLATE utf8_bin NOT NULL,
152 152
 					  CNT_ISO3 varchar(3) COLLATE utf8_bin NOT NULL,
153 153
 					  RGN_ID tinyint(3) unsigned DEFAULT NULL,
154 154
 					  CNT_name varchar(45) COLLATE utf8_bin NOT NULL,
@@ -164,9 +164,9 @@  discard block
 block discarded – undo
164 164
 					  CNT_is_EU tinyint(1) DEFAULT '0',
165 165
 					  CNT_active tinyint(1) DEFAULT '0',
166 166
 					  PRIMARY KEY  (CNT_ISO)";
167
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
168
-        $table_name = 'esp_datetime';
169
-        $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
167
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
168
+		$table_name = 'esp_datetime';
169
+		$sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
170 170
 				  EVT_ID bigint(20) unsigned NOT NULL,
171 171
 				  DTT_EVT_start datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
172 172
 				  DTT_EVT_end datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
@@ -179,9 +179,9 @@  discard block
 block discarded – undo
179 179
 						PRIMARY KEY  (DTT_ID),
180 180
 						KEY EVT_ID (EVT_ID),
181 181
 						KEY DTT_is_primary (DTT_is_primary)";
182
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
183
-        $table_name = 'esp_event_meta';
184
-        $sql = "
182
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
183
+		$table_name = 'esp_event_meta';
184
+		$sql = "
185 185
 			EVTM_ID int(10) NOT NULL AUTO_INCREMENT,
186 186
 			EVT_ID bigint(20) unsigned NOT NULL,
187 187
 			EVT_display_desc tinyint(1) unsigned NOT NULL DEFAULT 1,
@@ -196,31 +196,31 @@  discard block
 block discarded – undo
196 196
 			EVT_external_URL varchar(200) NULL,
197 197
 			EVT_donations tinyint(1) NULL,
198 198
 			PRIMARY KEY  (EVTM_ID)";
199
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
200
-        $table_name = 'esp_event_question_group';
201
-        $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
199
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
200
+		$table_name = 'esp_event_question_group';
201
+		$sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
202 202
 					EVT_ID bigint(20) unsigned NOT NULL,
203 203
 					QSG_ID int(10) unsigned NOT NULL,
204 204
 					EQG_primary tinyint(1) unsigned NOT NULL DEFAULT 0,
205 205
 					PRIMARY KEY  (EQG_ID)";
206
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
207
-        $table_name = 'esp_event_venue';
208
-        $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT,
206
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
207
+		$table_name = 'esp_event_venue';
208
+		$sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT,
209 209
 				EVT_ID bigint(20) unsigned NOT NULL,
210 210
 				VNU_ID bigint(20) unsigned NOT NULL,
211 211
 				EVV_primary tinyint(1) unsigned NOT NULL DEFAULT 0,
212 212
 				PRIMARY KEY  (EVV_ID)";
213
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
214
-        $table_name = 'esp_extra_meta';
215
-        $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT,
213
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
214
+		$table_name = 'esp_extra_meta';
215
+		$sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT,
216 216
 				OBJ_ID int(11) DEFAULT NULL,
217 217
 				EXM_type varchar(45) DEFAULT NULL,
218 218
 				EXM_key varchar(45) DEFAULT NULL,
219 219
 				EXM_value text,
220 220
 				PRIMARY KEY  (EXM_ID)";
221
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
222
-        $table_name = 'esp_line_item';
223
-        $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT,
221
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
222
+		$table_name = 'esp_line_item';
223
+		$sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT,
224 224
 				LIN_code varchar(245) NOT NULL DEFAULT '',
225 225
 				TXN_ID int(11) DEFAULT NULL,
226 226
 				LIN_name varchar(245) NOT NULL DEFAULT '',
@@ -236,18 +236,18 @@  discard block
 block discarded – undo
236 236
 				OBJ_ID int(11) DEFAULT NULL,
237 237
 				OBJ_type varchar(45)DEFAULT NULL,
238 238
 				PRIMARY KEY  (LIN_ID)";
239
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
240
-        $table_name = 'esp_message_template';
241
-        $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
239
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
240
+		$table_name = 'esp_message_template';
241
+		$sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
242 242
 					GRP_ID int(10) unsigned NOT NULL,
243 243
 					MTP_context varchar(50) NOT NULL,
244 244
 					MTP_template_field varchar(30) NOT NULL,
245 245
 					MTP_content text NOT NULL,
246 246
 					PRIMARY KEY  (MTP_ID),
247 247
 					KEY GRP_ID (GRP_ID)";
248
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
249
-        $table_name = 'esp_message_template_group';
250
-        $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
248
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
249
+		$table_name = 'esp_message_template_group';
250
+		$sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
251 251
 					EVT_ID bigint(20) unsigned DEFAULT NULL,
252 252
 					MTP_user_id int(10) NOT NULL DEFAULT '1',
253 253
 					MTP_messenger varchar(30) NOT NULL,
@@ -259,9 +259,9 @@  discard block
 block discarded – undo
259 259
 					PRIMARY KEY  (GRP_ID),
260 260
 					KEY EVT_ID (EVT_ID),
261 261
 					KEY MTP_user_id (MTP_user_id)";
262
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
263
-        $table_name = 'esp_payment';
264
-        $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
262
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
263
+		$table_name = 'esp_payment';
264
+		$sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
265 265
 					TXN_ID int(10) unsigned DEFAULT NULL,
266 266
 					STS_ID varchar(3) COLLATE utf8_bin DEFAULT NULL,
267 267
 					PAY_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
@@ -277,9 +277,9 @@  discard block
 block discarded – undo
277 277
 					PRIMARY KEY  (PAY_ID),
278 278
 					KEY TXN_ID (TXN_ID),
279 279
 					KEY PAY_timestamp (PAY_timestamp)";
280
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
281
-        $table_name = "esp_ticket";
282
-        $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
280
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
281
+		$table_name = "esp_ticket";
282
+		$sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
283 283
 					  TTM_ID int(10) unsigned NOT NULL,
284 284
 					  TKT_name varchar(245) NOT NULL DEFAULT '',
285 285
 					  TKT_description text NOT NULL,
@@ -298,28 +298,28 @@  discard block
 block discarded – undo
298 298
 					  TKT_parent int(10) unsigned DEFAULT '0',
299 299
 					  TKT_deleted tinyint(1) NOT NULL DEFAULT '0',
300 300
 					  PRIMARY KEY  (TKT_ID)";
301
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
302
-        $table_name = "esp_ticket_price";
303
-        $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
301
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
302
+		$table_name = "esp_ticket_price";
303
+		$sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
304 304
 					  TKT_ID int(10) unsigned NOT NULL,
305 305
 					  PRC_ID int(10) unsigned NOT NULL,
306 306
 					  PRIMARY KEY  (TKP_ID)";
307
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
308
-        $table_name = "esp_datetime_ticket";
309
-        $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
307
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
308
+		$table_name = "esp_datetime_ticket";
309
+		$sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
310 310
 					  DTT_ID int(10) unsigned NOT NULL,
311 311
 					  TKT_ID int(10) unsigned NOT NULL,
312 312
 					  PRIMARY KEY  (DTK_ID)";
313
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
314
-        $table_name = "esp_ticket_template";
315
-        $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
313
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
314
+		$table_name = "esp_ticket_template";
315
+		$sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
316 316
 					  TTM_name varchar(45) NOT NULL,
317 317
 					  TTM_description text,
318 318
 					  TTM_file varchar(45),
319 319
 					  PRIMARY KEY  (TTM_ID)";
320
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
321
-        $table_name = "esp_price";
322
-        $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
320
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
321
+		$table_name = "esp_price";
322
+		$sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
323 323
 					  PRT_ID tinyint(3) unsigned NOT NULL,
324 324
 					  PRC_amount decimal(10,3) NOT NULL DEFAULT '0.00',
325 325
 					  PRC_name varchar(245) NOT NULL,
@@ -330,9 +330,9 @@  discard block
 block discarded – undo
330 330
 					  PRC_order tinyint(3) unsigned NOT NULL DEFAULT '0',
331 331
 					  PRC_parent int(10) unsigned DEFAULT 0,
332 332
 					  PRIMARY KEY  (PRC_ID)";
333
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
334
-        $table_name = "esp_price_type";
335
-        $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
333
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
334
+		$table_name = "esp_price_type";
335
+		$sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
336 336
 				  PRT_name varchar(45) NOT NULL,
337 337
 				  PBT_ID tinyint(3) unsigned NOT NULL DEFAULT '1',
338 338
 				  PRT_is_percent tinyint(1) NOT NULL DEFAULT '0',
@@ -340,9 +340,9 @@  discard block
 block discarded – undo
340 340
 				  PRT_deleted tinyint(1) NOT NULL DEFAULT '0',
341 341
 				  UNIQUE KEY PRT_name_UNIQUE (PRT_name),
342 342
 				  PRIMARY KEY  (PRT_ID)";
343
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
344
-        $table_name = 'esp_question';
345
-        $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
343
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
344
+		$table_name = 'esp_question';
345
+		$sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
346 346
 					QST_display_text text NOT NULL,
347 347
 					QST_admin_label varchar(255) NOT NULL,
348 348
 					QST_system varchar(25) DEFAULT NULL,
@@ -354,10 +354,10 @@  discard block
 block discarded – undo
354 354
 					QST_wp_user bigint(20) unsigned NULL,
355 355
 					QST_deleted tinyint(1) unsigned NOT NULL DEFAULT 0,
356 356
 					PRIMARY KEY  (QST_ID)';
357
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
358
-        $this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_identifier_UNIQUE');
359
-        $table_name = 'esp_question_group';
360
-        $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
357
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
358
+		$this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_identifier_UNIQUE');
359
+		$table_name = 'esp_question_group';
360
+		$sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
361 361
 					QSG_name varchar(255) NOT NULL,
362 362
 					QSG_identifier varchar(100) NOT NULL,
363 363
 					QSG_desc text NULL,
@@ -368,23 +368,23 @@  discard block
 block discarded – undo
368 368
 					QSG_deleted tinyint(1) unsigned NOT NULL DEFAULT 0,
369 369
 					PRIMARY KEY  (QSG_ID),
370 370
 					UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier ASC)';
371
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
372
-        $table_name = 'esp_question_group_question';
373
-        $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
371
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
372
+		$table_name = 'esp_question_group_question';
373
+		$sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
374 374
 					QSG_ID int(10) unsigned NOT NULL,
375 375
 					QST_ID int(10) unsigned NOT NULL,
376 376
 					PRIMARY KEY  (QGQ_ID) ";
377
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
378
-        $table_name = 'esp_question_option';
379
-        $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
377
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
378
+		$table_name = 'esp_question_option';
379
+		$sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
380 380
 					QSO_value varchar(255) NOT NULL,
381 381
 					QSO_desc text NOT NULL,
382 382
 					QST_ID int(10) unsigned NOT NULL,
383 383
 					QSO_deleted tinyint(1) unsigned NOT NULL DEFAULT 0,
384 384
 					PRIMARY KEY  (QSO_ID)";
385
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
386
-        $table_name = 'esp_registration';
387
-        $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
385
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
386
+		$table_name = 'esp_registration';
387
+		$sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
388 388
 					  EVT_ID bigint(20) unsigned NOT NULL,
389 389
 					  ATT_ID bigint(20) unsigned NOT NULL,
390 390
 					  TXN_ID int(10) unsigned NOT NULL,
@@ -407,25 +407,25 @@  discard block
 block discarded – undo
407 407
 					  KEY STS_ID (STS_ID),
408 408
 					  KEY REG_url_link (REG_url_link),
409 409
 					  KEY REG_code (REG_code)";
410
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
411
-        $table_name = 'esp_checkin';
412
-        $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
410
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
411
+		$table_name = 'esp_checkin';
412
+		$sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
413 413
 					REG_ID int(10) unsigned NOT NULL,
414 414
 					DTT_ID int(10) unsigned NOT NULL,
415 415
 					CHK_in tinyint(1) unsigned NOT NULL DEFAULT 1,
416 416
 					CHK_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
417 417
 					PRIMARY KEY  (CHK_ID)";
418
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
419
-        $table_name = 'esp_state';
420
-        $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT,
418
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
419
+		$table_name = 'esp_state';
420
+		$sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT,
421 421
 					  CNT_ISO varchar(2) COLLATE utf8_bin NOT NULL,
422 422
 					  STA_abbrev varchar(6) COLLATE utf8_bin NOT NULL,
423 423
 					  STA_name varchar(100) COLLATE utf8_bin NOT NULL,
424 424
 					  STA_active tinyint(1) DEFAULT '1',
425 425
 					  PRIMARY KEY  (STA_ID)";
426
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
427
-        $table_name = 'esp_status';
428
-        $sql = "STS_ID varchar(3) COLLATE utf8_bin NOT NULL,
426
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
427
+		$table_name = 'esp_status';
428
+		$sql = "STS_ID varchar(3) COLLATE utf8_bin NOT NULL,
429 429
 					  STS_code varchar(45) COLLATE utf8_bin NOT NULL,
430 430
 					  STS_type set('event','registration','transaction','payment','email') COLLATE utf8_bin NOT NULL,
431 431
 					  STS_can_edit tinyint(1) NOT NULL DEFAULT 0,
@@ -433,9 +433,9 @@  discard block
 block discarded – undo
433 433
 					  STS_open tinyint(1) NOT NULL DEFAULT 1,
434 434
 					  UNIQUE KEY STS_ID_UNIQUE (STS_ID),
435 435
 					  KEY STS_type (STS_type)";
436
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
437
-        $table_name = 'esp_transaction';
438
-        $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
436
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
437
+		$table_name = 'esp_transaction';
438
+		$sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
439 439
 					  TXN_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
440 440
 					  TXN_total decimal(10,3) DEFAULT '0.00',
441 441
 					  TXN_paid decimal(10,3) NOT NULL DEFAULT '0.00',
@@ -445,9 +445,9 @@  discard block
 block discarded – undo
445 445
 					  PRIMARY KEY  (TXN_ID),
446 446
 					  KEY TXN_timestamp (TXN_timestamp),
447 447
 					  KEY STS_ID (STS_ID)";
448
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
449
-        $table_name = 'esp_venue_meta';
450
-        $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT,
448
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
449
+		$table_name = 'esp_venue_meta';
450
+		$sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT,
451 451
 			VNU_ID bigint(20) unsigned NOT NULL DEFAULT 0,
452 452
 			VNU_address varchar(255) DEFAULT NULL,
453 453
 			VNU_address2 varchar(255) DEFAULT NULL,
@@ -465,52 +465,52 @@  discard block
 block discarded – undo
465 465
 			PRIMARY KEY  (VNUM_ID),
466 466
 			KEY STA_ID (STA_ID),
467 467
 			KEY CNT_ISO (CNT_ISO)";
468
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
469
-        // setting up the default stats and countries is also essential for the data migrations to run
470
-        // (because many need to convert old string states to foreign keys into the states table)
471
-        $this->insert_default_states();
472
-        $this->insert_default_countries();
473
-        // setting up default prices, price types, and tickets is also essential for the price migrations
474
-        $this->insert_default_price_types();
475
-        $this->insert_default_prices();
476
-        $this->insert_default_tickets();
477
-        // setting up the config wp option pretty well counts as a 'schema change', or at least should happen ehre
478
-        EE_Config::instance()->update_espresso_config(false, true);
479
-        return true;
480
-    }
481
-
482
-
483
-
484
-    /**
485
-     * Yes we could have cleaned up the ee3 tables here. But just in case someone
486
-     * didn't backup their DB, and decides they want ot keep using EE3, we'll
487
-     * leave them for now. Mayeb remove them in 4.5 or something.
488
-     *
489
-     * @return boolean
490
-     */
491
-    public function schema_changes_after_migration()
492
-    {
493
-        return true;
494
-    }
495
-
496
-
497
-
498
-    /**
499
-     * insert_default_states
500
-     *
501
-     * @access public
502
-     * @static
503
-     * @return void
504
-     */
505
-    public function insert_default_states()
506
-    {
507
-        global $wpdb;
508
-        $state_table = $wpdb->prefix . "esp_state";
509
-        if ($this->_get_table_analysis()->tableExists($state_table)) {
510
-            $SQL = "SELECT COUNT('STA_ID') FROM " . $state_table;
511
-            $states = $wpdb->get_var($SQL);
512
-            if (! $states) {
513
-                $SQL = "INSERT INTO " . $state_table . "
468
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
469
+		// setting up the default stats and countries is also essential for the data migrations to run
470
+		// (because many need to convert old string states to foreign keys into the states table)
471
+		$this->insert_default_states();
472
+		$this->insert_default_countries();
473
+		// setting up default prices, price types, and tickets is also essential for the price migrations
474
+		$this->insert_default_price_types();
475
+		$this->insert_default_prices();
476
+		$this->insert_default_tickets();
477
+		// setting up the config wp option pretty well counts as a 'schema change', or at least should happen ehre
478
+		EE_Config::instance()->update_espresso_config(false, true);
479
+		return true;
480
+	}
481
+
482
+
483
+
484
+	/**
485
+	 * Yes we could have cleaned up the ee3 tables here. But just in case someone
486
+	 * didn't backup their DB, and decides they want ot keep using EE3, we'll
487
+	 * leave them for now. Mayeb remove them in 4.5 or something.
488
+	 *
489
+	 * @return boolean
490
+	 */
491
+	public function schema_changes_after_migration()
492
+	{
493
+		return true;
494
+	}
495
+
496
+
497
+
498
+	/**
499
+	 * insert_default_states
500
+	 *
501
+	 * @access public
502
+	 * @static
503
+	 * @return void
504
+	 */
505
+	public function insert_default_states()
506
+	{
507
+		global $wpdb;
508
+		$state_table = $wpdb->prefix . "esp_state";
509
+		if ($this->_get_table_analysis()->tableExists($state_table)) {
510
+			$SQL = "SELECT COUNT('STA_ID') FROM " . $state_table;
511
+			$states = $wpdb->get_var($SQL);
512
+			if (! $states) {
513
+				$SQL = "INSERT INTO " . $state_table . "
514 514
 				(STA_ID, CNT_ISO, STA_abbrev, STA_name, STA_active) VALUES
515 515
 				(1, 'US', 'AK', 'Alaska', 1),
516 516
 				(2, 'US', 'AL', 'Alabama', 1),
@@ -584,29 +584,29 @@  discard block
 block discarded – undo
584 584
 				(70, 'CA', 'NT', 'Northwest Territories', 1),
585 585
 				(71, 'CA', 'NU', 'Nunavut', 1),
586 586
 				(72, 'CA', 'YT', 'Yukon', 1);";
587
-                $wpdb->query($SQL);
588
-            }
589
-        }
590
-    }
591
-
592
-
593
-
594
-    /**
595
-     * insert_default_countries
596
-     *
597
-     * @access public
598
-     * @static
599
-     * @return void
600
-     */
601
-    public function insert_default_countries()
602
-    {
603
-        global $wpdb;
604
-        $country_table = $wpdb->prefix . "esp_country";
605
-        if ($this->_get_table_analysis()->tableExists($country_table)) {
606
-            $SQL = "SELECT COUNT('CNT_ISO') FROM " . $country_table;
607
-            $countries = $wpdb->get_var($SQL);
608
-            if (! $countries) {
609
-                $SQL = "INSERT INTO " . $country_table . "
587
+				$wpdb->query($SQL);
588
+			}
589
+		}
590
+	}
591
+
592
+
593
+
594
+	/**
595
+	 * insert_default_countries
596
+	 *
597
+	 * @access public
598
+	 * @static
599
+	 * @return void
600
+	 */
601
+	public function insert_default_countries()
602
+	{
603
+		global $wpdb;
604
+		$country_table = $wpdb->prefix . "esp_country";
605
+		if ($this->_get_table_analysis()->tableExists($country_table)) {
606
+			$SQL = "SELECT COUNT('CNT_ISO') FROM " . $country_table;
607
+			$countries = $wpdb->get_var($SQL);
608
+			if (! $countries) {
609
+				$SQL = "INSERT INTO " . $country_table . "
610 610
 				(CNT_ISO, CNT_ISO3, RGN_ID, CNT_name, CNT_cur_code, CNT_cur_single, CNT_cur_plural, CNT_cur_sign, CNT_cur_sign_b4, CNT_cur_dec_plc, CNT_tel_code, CNT_is_EU, CNT_active) VALUES
611 611
 				('AD', 'AND', 0, 'Andorra', 'EUR', 'Euro', 'Euros', '€', 1, 2, '+376', 0, 0),
612 612
 				('AE', 'ARE', 0, 'United Arab Emirates', 'AED', 'Dirham', 'Dirhams', 'د.إ', 1, 2, '+971', 0, 0),
@@ -834,984 +834,984 @@  discard block
 block discarded – undo
834 834
 				('ZA', 'ZAF', 0, 'South Africa', 'ZAR', 'Rand', 'Rands', 'R', 1, 2, '+27', 0, 0),
835 835
 				('ZM', 'ZMB', 0, 'Zambia', 'ZMK', 'Kwacha', 'Kwachas', '', 1, 2, '+260', 0, 0),
836 836
 				('ZW', 'ZWE', 0, 'Zimbabwe', 'ZWD', 'Dollar', 'Dollars', 'Z$', 1, 2, '+263', 0, 0);";
837
-                $wpdb->query($SQL);
838
-            }
839
-        }
840
-    }
841
-
842
-
843
-
844
-    /**
845
-     * insert_default_price_types
846
-     *
847
-     * @access public
848
-     * @static
849
-     * @return void
850
-     */
851
-    public function insert_default_price_types()
852
-    {
853
-        global $wpdb;
854
-        $price_type_table = $wpdb->prefix . "esp_price_type";
855
-        if ($this->_get_table_analysis()->tableExists($price_type_table)) {
856
-            $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table;
857
-            $price_types_exist = $wpdb->get_var($SQL);
858
-            if (! $price_types_exist) {
859
-                $SQL = "INSERT INTO $price_type_table ( PRT_ID, PRT_name, PBT_ID, PRT_is_percent, PRT_order, PRT_deleted ) VALUES
837
+				$wpdb->query($SQL);
838
+			}
839
+		}
840
+	}
841
+
842
+
843
+
844
+	/**
845
+	 * insert_default_price_types
846
+	 *
847
+	 * @access public
848
+	 * @static
849
+	 * @return void
850
+	 */
851
+	public function insert_default_price_types()
852
+	{
853
+		global $wpdb;
854
+		$price_type_table = $wpdb->prefix . "esp_price_type";
855
+		if ($this->_get_table_analysis()->tableExists($price_type_table)) {
856
+			$SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table;
857
+			$price_types_exist = $wpdb->get_var($SQL);
858
+			if (! $price_types_exist) {
859
+				$SQL = "INSERT INTO $price_type_table ( PRT_ID, PRT_name, PBT_ID, PRT_is_percent, PRT_order, PRT_deleted ) VALUES
860 860
 							(1, '" . esc_html__('Base Price', 'event_espresso') . "', 1,  0, 0, 0),
861 861
 							(2, '" . esc_html__('Percent Discount', 'event_espresso') . "', 2,  1, 20, 0),
862 862
 							(3, '" . esc_html__('Fixed Discount', 'event_espresso') . "', 2,  0, 30, 0),
863 863
 							(4, '" . esc_html__('Percent Surcharge', 'event_espresso') . "', 3,  1, 40, 0),
864 864
 							(5, '" . esc_html__('Fixed Surcharge', 'event_espresso') . "', 3,  0, 50, 0);";
865
-                $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_price_types__SQL', $SQL);
866
-                $wpdb->query($SQL);
867
-            }
868
-        }
869
-    }
870
-
871
-
872
-
873
-    /**
874
-     * insert_default_prices. We assume we're upgrading to regular here.
875
-     * If we're INSTALLING 4.1 CAF, then we add a few extra default prices
876
-     * when EEH_Activaion's initialize_db_content is called via  ahook in
877
-     * EE_BRewing_regular
878
-     *
879
-     * @access public
880
-     * @static
881
-     * @return void
882
-     */
883
-    public function insert_default_prices()
884
-    {
885
-        global $wpdb;
886
-        $price_table = $wpdb->prefix . "esp_price";
887
-        if ($this->_get_table_analysis()->tableExists($price_table)) {
888
-            $SQL = 'SELECT COUNT(PRC_ID) FROM ' . $price_table;
889
-            $prices_exist = $wpdb->get_var($SQL);
890
-            if (! $prices_exist) {
891
-                $SQL = "INSERT INTO $price_table
865
+				$SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_price_types__SQL', $SQL);
866
+				$wpdb->query($SQL);
867
+			}
868
+		}
869
+	}
870
+
871
+
872
+
873
+	/**
874
+	 * insert_default_prices. We assume we're upgrading to regular here.
875
+	 * If we're INSTALLING 4.1 CAF, then we add a few extra default prices
876
+	 * when EEH_Activaion's initialize_db_content is called via  ahook in
877
+	 * EE_BRewing_regular
878
+	 *
879
+	 * @access public
880
+	 * @static
881
+	 * @return void
882
+	 */
883
+	public function insert_default_prices()
884
+	{
885
+		global $wpdb;
886
+		$price_table = $wpdb->prefix . "esp_price";
887
+		if ($this->_get_table_analysis()->tableExists($price_table)) {
888
+			$SQL = 'SELECT COUNT(PRC_ID) FROM ' . $price_table;
889
+			$prices_exist = $wpdb->get_var($SQL);
890
+			if (! $prices_exist) {
891
+				$SQL = "INSERT INTO $price_table
892 892
 							(PRC_ID, PRT_ID, PRC_amount, PRC_name, PRC_desc,  PRC_is_default, PRC_overrides, PRC_order, PRC_deleted, PRC_parent ) VALUES
893 893
 							(1, 1, '0.00', 'Admission', '', 1, null, 0, 0, 0);";
894
-                $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_prices__SQL', $SQL);
895
-                $wpdb->query($SQL);
896
-            }
897
-        }
898
-    }
899
-
900
-
901
-
902
-    /**
903
-     * insert default ticket
904
-     *
905
-     * @access public
906
-     * @static
907
-     * @return void
908
-     */
909
-    public function insert_default_tickets()
910
-    {
911
-        global $wpdb;
912
-        $ticket_table = $wpdb->prefix . "esp_ticket";
913
-        if ($this->_get_table_analysis()->tableExists($ticket_table)) {
914
-            $SQL = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table;
915
-            $tickets_exist = $wpdb->get_var($SQL);
916
-            if (! $tickets_exist) {
917
-                $SQL = "INSERT INTO $ticket_table
894
+				$SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_prices__SQL', $SQL);
895
+				$wpdb->query($SQL);
896
+			}
897
+		}
898
+	}
899
+
900
+
901
+
902
+	/**
903
+	 * insert default ticket
904
+	 *
905
+	 * @access public
906
+	 * @static
907
+	 * @return void
908
+	 */
909
+	public function insert_default_tickets()
910
+	{
911
+		global $wpdb;
912
+		$ticket_table = $wpdb->prefix . "esp_ticket";
913
+		if ($this->_get_table_analysis()->tableExists($ticket_table)) {
914
+			$SQL = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table;
915
+			$tickets_exist = $wpdb->get_var($SQL);
916
+			if (! $tickets_exist) {
917
+				$SQL = "INSERT INTO $ticket_table
918 918
 					( TKT_ID, TTM_ID, TKT_name, TKT_description, TKT_qty, TKT_sold, TKT_uses, TKT_min, TKT_max, TKT_price, TKT_start_date, TKT_end_date, TKT_taxable, TKT_order, TKT_row, TKT_is_default, TKT_parent, TKT_deleted ) VALUES
919 919
 					( 1, 0, '"
920
-                       . esc_html__("Free Ticket", "event_espresso")
921
-                       . "', '', 100, 0, -1, 0, -1, 0.00, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0, 0, 1, 1, 0, 0);";
922
-                $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_tickets__SQL', $SQL);
923
-                $wpdb->query($SQL);
924
-            }
925
-        }
926
-        $ticket_price_table = $wpdb->prefix . "esp_ticket_price";
927
-        if ($this->_get_table_analysis()->tableExists($ticket_price_table)) {
928
-            $SQL = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table;
929
-            $ticket_prc_exist = $wpdb->get_var($SQL);
930
-            if (! $ticket_prc_exist) {
931
-                $SQL = "INSERT INTO $ticket_price_table
920
+					   . esc_html__("Free Ticket", "event_espresso")
921
+					   . "', '', 100, 0, -1, 0, -1, 0.00, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0, 0, 1, 1, 0, 0);";
922
+				$SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_tickets__SQL', $SQL);
923
+				$wpdb->query($SQL);
924
+			}
925
+		}
926
+		$ticket_price_table = $wpdb->prefix . "esp_ticket_price";
927
+		if ($this->_get_table_analysis()->tableExists($ticket_price_table)) {
928
+			$SQL = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table;
929
+			$ticket_prc_exist = $wpdb->get_var($SQL);
930
+			if (! $ticket_prc_exist) {
931
+				$SQL = "INSERT INTO $ticket_price_table
932 932
 				( TKP_ID, TKT_ID, PRC_ID ) VALUES
933 933
 				( 1, 1, 1 )
934 934
 				";
935
-                $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_tickets__SQL__ticket_price', $SQL);
936
-                $wpdb->query($SQL);
937
-            }
938
-        }
939
-    }
940
-
941
-
942
-
943
-    /**
944
-     * Gets a country entry as an array, or creates one if none is found. Much like EEM_Country::instance()->get_one(),
945
-     * but is independent of outside code which can change in future versions of EE. Also, $country_name CAN be a 3.1
946
-     * country ID (int), a 2-letter ISO, 3-letter ISO, or name
947
-     *
948
-     * @global type  $wpdb
949
-     * @param string $country_name
950
-     * @return array where keys are columns, values are column values
951
-     */
952
-    public function get_or_create_country($country_name)
953
-    {
954
-        if (! $country_name) {
955
-            throw new EE_Error(esc_html__("Could not get a country because country name is blank", "event_espresso"));
956
-        }
957
-        global $wpdb;
958
-        $country_table = $wpdb->prefix . "esp_country";
959
-        if (is_int($country_name)) {
960
-            $country_name = $this->get_iso_from_3_1_country_id($country_name);
961
-        }
962
-        $country = $wpdb->get_row($wpdb->prepare("SELECT * FROM $country_table WHERE
935
+				$SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_tickets__SQL__ticket_price', $SQL);
936
+				$wpdb->query($SQL);
937
+			}
938
+		}
939
+	}
940
+
941
+
942
+
943
+	/**
944
+	 * Gets a country entry as an array, or creates one if none is found. Much like EEM_Country::instance()->get_one(),
945
+	 * but is independent of outside code which can change in future versions of EE. Also, $country_name CAN be a 3.1
946
+	 * country ID (int), a 2-letter ISO, 3-letter ISO, or name
947
+	 *
948
+	 * @global type  $wpdb
949
+	 * @param string $country_name
950
+	 * @return array where keys are columns, values are column values
951
+	 */
952
+	public function get_or_create_country($country_name)
953
+	{
954
+		if (! $country_name) {
955
+			throw new EE_Error(esc_html__("Could not get a country because country name is blank", "event_espresso"));
956
+		}
957
+		global $wpdb;
958
+		$country_table = $wpdb->prefix . "esp_country";
959
+		if (is_int($country_name)) {
960
+			$country_name = $this->get_iso_from_3_1_country_id($country_name);
961
+		}
962
+		$country = $wpdb->get_row($wpdb->prepare("SELECT * FROM $country_table WHERE
963 963
 			CNT_ISO LIKE %s OR
964 964
 			CNT_ISO3 LIKE %s OR
965 965
 			CNT_name LIKE %s LIMIT 1", $country_name, $country_name, $country_name), ARRAY_A);
966
-        if (! $country) {
967
-            // insert a new one then
968
-            $cols_n_values = array(
969
-                    'CNT_ISO'         => $this->_find_available_country_iso(2),
970
-                    'CNT_ISO3'        => $this->_find_available_country_iso(3),
971
-                    'RGN_ID'          => 0,
972
-                    'CNT_name'        => $country_name,
973
-                    'CNT_cur_code'    => 'USD',
974
-                    'CNT_cur_single'  => 'Dollar',
975
-                    'CNT_cur_plural'  => 'Dollars',
976
-                    'CNT_cur_sign'    => '&#36;',
977
-                    'CNT_cur_sign_b4' => true,
978
-                    'CNT_cur_dec_plc' => 2,
979
-                    'CNT_cur_dec_mrk' => '.',
980
-                    'CNT_cur_thsnds'  => ',',
981
-                    'CNT_tel_code'    => '+1',
982
-                    'CNT_is_EU'       => false,
983
-                    'CNT_active'      => true,
984
-            );
985
-            $data_types = array(
986
-                    '%s',// CNT_ISO
987
-                    '%s',// CNT_ISO3
988
-                    '%d',// RGN_ID
989
-                    '%s',// CNT_name
990
-                    '%s',// CNT_cur_code
991
-                    '%s',// CNT_cur_single
992
-                    '%s',// CNT_cur_plural
993
-                    '%s',// CNT_cur_sign
994
-                    '%d',// CNT_cur_sign_b4
995
-                    '%d',// CNT_cur_dec_plc
996
-                    '%s',// CNT_cur_dec_mrk
997
-                    '%s',// CNT_cur_thsnds
998
-                    '%s',// CNT_tel_code
999
-                    '%d',// CNT_is_EU
1000
-                    '%d',// CNT_active
1001
-            );
1002
-            $success = $wpdb->insert(
1003
-                $country_table,
1004
-                $cols_n_values,
1005
-                $data_types
1006
-            );
1007
-            if (! $success) {
1008
-                throw new EE_Error($this->_create_error_message_for_db_insertion(
1009
-                    'N/A',
1010
-                    array('country_id' => $country_name),
1011
-                    $country_table,
1012
-                    $cols_n_values,
1013
-                    $data_types
1014
-                ));
1015
-            }
1016
-            $country = $cols_n_values;
1017
-        }
1018
-        return $country;
1019
-    }
1020
-
1021
-
1022
-
1023
-    /**
1024
-     * finds a country iso which hasnt been used yet
1025
-     *
1026
-     * @global type $wpdb
1027
-     * @return string
1028
-     */
1029
-    private function _find_available_country_iso($num_letters = 2)
1030
-    {
1031
-        global $wpdb;
1032
-        $country_table = $wpdb->prefix . "esp_country";
1033
-        $attempts = 0;
1034
-        do {
1035
-            $current_iso = strtoupper(wp_generate_password($num_letters, false));
1036
-            $country_with_that_iso = $wpdb->get_var($wpdb->prepare("SELECT count(CNT_ISO) FROM "
1037
-                                                                   . $country_table
1038
-                                                                   . " WHERE CNT_ISO=%s", $current_iso));
1039
-            $attempts++;
1040
-            // keep going until we find an available country code, or we arbitrarily
1041
-            // decide we've tried this enough. Somehow they have way too many countries
1042
-            // (probably because they're mis-using the EE3 country_id like a custom question)
1043
-        } while (intval($country_with_that_iso) && $attempts < 200);
1044
-        return $current_iso;
1045
-    }
1046
-
1047
-
1048
-
1049
-    /**
1050
-     * Gets a state entry as an array, or creates one if none is found. Much like EEM_State::instance()->get_one(), but
1051
-     * is independent of outside code which can change in future versions of EE
1052
-     *
1053
-     * @global type  $wpdb
1054
-     * @param string $state_name
1055
-     * @return array where keys are columns, values are column values
1056
-     */
1057
-    public function get_or_create_state($state_name, $country_name = '')
1058
-    {
1059
-        if (! $state_name) {
1060
-            throw new EE_Error(esc_html__(
1061
-                "Could not get-or-create state because no state name was provided",
1062
-                "event_espresso"
1063
-            ));
1064
-        }
1065
-        try {
1066
-            $country = $this->get_or_create_country($country_name);
1067
-            $country_iso = $country['CNT_ISO'];
1068
-        } catch (EE_Error $e) {
1069
-            $country_iso = $this->get_default_country_iso();
1070
-        }
1071
-        global $wpdb;
1072
-        $state_table = $wpdb->prefix . "esp_state";
1073
-        $state = $wpdb->get_row($wpdb->prepare("SELECT * FROM $state_table WHERE
966
+		if (! $country) {
967
+			// insert a new one then
968
+			$cols_n_values = array(
969
+					'CNT_ISO'         => $this->_find_available_country_iso(2),
970
+					'CNT_ISO3'        => $this->_find_available_country_iso(3),
971
+					'RGN_ID'          => 0,
972
+					'CNT_name'        => $country_name,
973
+					'CNT_cur_code'    => 'USD',
974
+					'CNT_cur_single'  => 'Dollar',
975
+					'CNT_cur_plural'  => 'Dollars',
976
+					'CNT_cur_sign'    => '&#36;',
977
+					'CNT_cur_sign_b4' => true,
978
+					'CNT_cur_dec_plc' => 2,
979
+					'CNT_cur_dec_mrk' => '.',
980
+					'CNT_cur_thsnds'  => ',',
981
+					'CNT_tel_code'    => '+1',
982
+					'CNT_is_EU'       => false,
983
+					'CNT_active'      => true,
984
+			);
985
+			$data_types = array(
986
+					'%s',// CNT_ISO
987
+					'%s',// CNT_ISO3
988
+					'%d',// RGN_ID
989
+					'%s',// CNT_name
990
+					'%s',// CNT_cur_code
991
+					'%s',// CNT_cur_single
992
+					'%s',// CNT_cur_plural
993
+					'%s',// CNT_cur_sign
994
+					'%d',// CNT_cur_sign_b4
995
+					'%d',// CNT_cur_dec_plc
996
+					'%s',// CNT_cur_dec_mrk
997
+					'%s',// CNT_cur_thsnds
998
+					'%s',// CNT_tel_code
999
+					'%d',// CNT_is_EU
1000
+					'%d',// CNT_active
1001
+			);
1002
+			$success = $wpdb->insert(
1003
+				$country_table,
1004
+				$cols_n_values,
1005
+				$data_types
1006
+			);
1007
+			if (! $success) {
1008
+				throw new EE_Error($this->_create_error_message_for_db_insertion(
1009
+					'N/A',
1010
+					array('country_id' => $country_name),
1011
+					$country_table,
1012
+					$cols_n_values,
1013
+					$data_types
1014
+				));
1015
+			}
1016
+			$country = $cols_n_values;
1017
+		}
1018
+		return $country;
1019
+	}
1020
+
1021
+
1022
+
1023
+	/**
1024
+	 * finds a country iso which hasnt been used yet
1025
+	 *
1026
+	 * @global type $wpdb
1027
+	 * @return string
1028
+	 */
1029
+	private function _find_available_country_iso($num_letters = 2)
1030
+	{
1031
+		global $wpdb;
1032
+		$country_table = $wpdb->prefix . "esp_country";
1033
+		$attempts = 0;
1034
+		do {
1035
+			$current_iso = strtoupper(wp_generate_password($num_letters, false));
1036
+			$country_with_that_iso = $wpdb->get_var($wpdb->prepare("SELECT count(CNT_ISO) FROM "
1037
+																   . $country_table
1038
+																   . " WHERE CNT_ISO=%s", $current_iso));
1039
+			$attempts++;
1040
+			// keep going until we find an available country code, or we arbitrarily
1041
+			// decide we've tried this enough. Somehow they have way too many countries
1042
+			// (probably because they're mis-using the EE3 country_id like a custom question)
1043
+		} while (intval($country_with_that_iso) && $attempts < 200);
1044
+		return $current_iso;
1045
+	}
1046
+
1047
+
1048
+
1049
+	/**
1050
+	 * Gets a state entry as an array, or creates one if none is found. Much like EEM_State::instance()->get_one(), but
1051
+	 * is independent of outside code which can change in future versions of EE
1052
+	 *
1053
+	 * @global type  $wpdb
1054
+	 * @param string $state_name
1055
+	 * @return array where keys are columns, values are column values
1056
+	 */
1057
+	public function get_or_create_state($state_name, $country_name = '')
1058
+	{
1059
+		if (! $state_name) {
1060
+			throw new EE_Error(esc_html__(
1061
+				"Could not get-or-create state because no state name was provided",
1062
+				"event_espresso"
1063
+			));
1064
+		}
1065
+		try {
1066
+			$country = $this->get_or_create_country($country_name);
1067
+			$country_iso = $country['CNT_ISO'];
1068
+		} catch (EE_Error $e) {
1069
+			$country_iso = $this->get_default_country_iso();
1070
+		}
1071
+		global $wpdb;
1072
+		$state_table = $wpdb->prefix . "esp_state";
1073
+		$state = $wpdb->get_row($wpdb->prepare("SELECT * FROM $state_table WHERE
1074 1074
 			(STA_abbrev LIKE %s OR
1075 1075
 			STA_name LIKE %s) AND
1076 1076
 			CNT_ISO LIKE %s LIMIT 1", $state_name, $state_name, $country_iso), ARRAY_A);
1077
-        if (! $state) {
1078
-            // insert a new one then
1079
-            $cols_n_values = array(
1080
-                    'CNT_ISO'    => $country_iso,
1081
-                    'STA_abbrev' => substr($state_name, 0, 6),
1082
-                    'STA_name'   => $state_name,
1083
-                    'STA_active' => true,
1084
-            );
1085
-            $data_types = array(
1086
-                    '%s',// CNT_ISO
1087
-                    '%s',// STA_abbrev
1088
-                    '%s',// STA_name
1089
-                    '%d',// STA_active
1090
-            );
1091
-            $success = $wpdb->insert($state_table, $cols_n_values, $data_types);
1092
-            if (! $success) {
1093
-                throw new EE_Error($this->_create_error_message_for_db_insertion(
1094
-                    'N/A',
1095
-                    array('state' => $state_name, 'country_id' => $country_name),
1096
-                    $state_table,
1097
-                    $cols_n_values,
1098
-                    $data_types
1099
-                ));
1100
-            }
1101
-            $state = $cols_n_values;
1102
-            $state['STA_ID'] = $wpdb->insert_id;
1103
-        }
1104
-        return $state;
1105
-    }
1106
-
1107
-
1108
-
1109
-    /**
1110
-     * Fixes times like "5:00 PM" into the expected 24-hour format "17:00".
1111
-     * THis is actually just copied from the 3.1 JSON API because it needed to do the exact same thing
1112
-     *
1113
-     * @param type $timeString
1114
-     * @return string in the php DATETIME format: "G:i" (24-hour format hour with leading zeros, a colon, and minutes
1115
-     *                with leading zeros)
1116
-     */
1117
-    public function convertTimeFromAMPM($timeString)
1118
-    {
1119
-        $matches = array();
1120
-        preg_match("~(\\d*):(\\d*)~", $timeString, $matches);
1121
-        if (! $matches || count($matches) < 3) {
1122
-            $hour = '00';
1123
-            $minutes = '00';
1124
-        } else {
1125
-            $hour = intval($matches[1]);
1126
-            $minutes = $matches[2];
1127
-        }
1128
-        if (strpos($timeString, 'PM') || strpos($timeString, 'pm')) {
1129
-            $hour = intval($hour) + 12;
1130
-        }
1131
-        $hour = str_pad("$hour", 2, '0', STR_PAD_LEFT);
1132
-        $minutes = str_pad("$minutes", 2, '0', STR_PAD_LEFT);
1133
-        return "$hour:$minutes";
1134
-    }
1135
-
1136
-
1137
-
1138
-    /**
1139
-     * Gets the ISO3 fora country given its 3.1 country ID.
1140
-     *
1141
-     * @param int $country_id
1142
-     * @return string the country's ISO3 code
1143
-     */
1144
-    public function get_iso_from_3_1_country_id($country_id)
1145
-    {
1146
-        $old_countries = array(
1147
-                array(64, 'United States', 'US', 'USA', 1),
1148
-                array(15, 'Australia', 'AU', 'AUS', 1),
1149
-                array(39, 'Canada', 'CA', 'CAN', 1),
1150
-                array(171, 'United Kingdom', 'GB', 'GBR', 1),
1151
-                array(70, 'France', 'FR', 'FRA', 2),
1152
-                array(111, 'Italy', 'IT', 'ITA', 2),
1153
-                array(63, 'Spain', 'ES', 'ESP', 2),
1154
-                array(1, 'Afghanistan', 'AF', 'AFG', 1),
1155
-                array(2, 'Albania', 'AL', 'ALB', 1),
1156
-                array(3, 'Germany', 'DE', 'DEU', 2),
1157
-                array(198, 'Switzerland', 'CH', 'CHE', 1),
1158
-                array(87, 'Netherlands', 'NL', 'NLD', 2),
1159
-                array(197, 'Sweden', 'SE', 'SWE', 1),
1160
-                array(230, 'Akrotiri and Dhekelia', 'CY', 'CYP', 2),
1161
-                array(4, 'Andorra', 'AD', 'AND', 2),
1162
-                array(5, 'Angola', 'AO', 'AGO', 1),
1163
-                array(6, 'Anguilla', 'AI', 'AIA', 1),
1164
-                array(7, 'Antarctica', 'AQ', 'ATA', 1),
1165
-                array(8, 'Antigua and Barbuda', 'AG', 'ATG', 1),
1166
-                array(10, 'Saudi Arabia', 'SA', 'SAU', 1),
1167
-                array(11, 'Algeria', 'DZ', 'DZA', 1),
1168
-                array(12, 'Argentina', 'AR', 'ARG', 1),
1169
-                array(13, 'Armenia', 'AM', 'ARM', 1),
1170
-                array(14, 'Aruba', 'AW', 'ABW', 1),
1171
-                array(16, 'Austria', 'AT', 'AUT', 2),
1172
-                array(17, 'Azerbaijan', 'AZ', 'AZE', 1),
1173
-                array(18, 'Bahamas', 'BS', 'BHS', 1),
1174
-                array(19, 'Bahrain', 'BH', 'BHR', 1),
1175
-                array(20, 'Bangladesh', 'BD', 'BGD', 1),
1176
-                array(21, 'Barbados', 'BB', 'BRB', 1),
1177
-                array(22, 'Belgium ', 'BE', 'BEL', 2),
1178
-                array(23, 'Belize', 'BZ', 'BLZ', 1),
1179
-                array(24, 'Benin', 'BJ', 'BEN', 1),
1180
-                array(25, 'Bermudas', 'BM', 'BMU', 1),
1181
-                array(26, 'Belarus', 'BY', 'BLR', 1),
1182
-                array(27, 'Bolivia', 'BO', 'BOL', 1),
1183
-                array(28, 'Bosnia and Herzegovina', 'BA', 'BIH', 1),
1184
-                array(29, 'Botswana', 'BW', 'BWA', 1),
1185
-                array(96, 'Bouvet Island', 'BV', 'BVT', 1),
1186
-                array(30, 'Brazil', 'BR', 'BRA', 1),
1187
-                array(31, 'Brunei', 'BN', 'BRN', 1),
1188
-                array(32, 'Bulgaria', 'BG', 'BGR', 1),
1189
-                array(33, 'Burkina Faso', 'BF', 'BFA', 1),
1190
-                array(34, 'Burundi', 'BI', 'BDI', 1),
1191
-                array(35, 'Bhutan', 'BT', 'BTN', 1),
1192
-                array(36, 'Cape Verde', 'CV', 'CPV', 1),
1193
-                array(37, 'Cambodia', 'KH', 'KHM', 1),
1194
-                array(38, 'Cameroon', 'CM', 'CMR', 1),
1195
-                array(98, 'Cayman Islands', 'KY', 'CYM', 1),
1196
-                array(172, 'Central African Republic', 'CF', 'CAF', 1),
1197
-                array(40, 'Chad', 'TD', 'TCD', 1),
1198
-                array(41, 'Chile', 'CL', 'CHL', 1),
1199
-                array(42, 'China', 'CN', 'CHN', 1),
1200
-                array(105, 'Christmas Island', 'CX', 'CXR', 1),
1201
-                array(43, 'Cyprus', 'CY', 'CYP', 2),
1202
-                array(99, 'Cocos Island', 'CC', 'CCK', 1),
1203
-                array(100, 'Cook Islands', 'CK', 'COK', 1),
1204
-                array(44, 'Colombia', 'CO', 'COL', 1),
1205
-                array(45, 'Comoros', 'KM', 'COM', 1),
1206
-                array(46, 'Congo', 'CG', 'COG', 1),
1207
-                array(47, 'North Korea', 'KP', 'PRK', 1),
1208
-                array(50, 'Costa Rica', 'CR', 'CRI', 1),
1209
-                array(51, 'Croatia', 'HR', 'HRV', 1),
1210
-                array(52, 'Cuba', 'CU', 'CUB', 1),
1211
-                array(173, 'Czech Republic', 'CZ', 'CZE', 1),
1212
-                array(53, 'Denmark', 'DK', 'DNK', 1),
1213
-                array(54, 'Djibouti', 'DJ', 'DJI', 1),
1214
-                array(55, 'Dominica', 'DM', 'DMA', 1),
1215
-                array(174, 'Dominican Republic', 'DO', 'DOM', 1),
1216
-                array(56, 'Ecuador', 'EC', 'ECU', 1),
1217
-                array(57, 'Egypt', 'EG', 'EGY', 1),
1218
-                array(58, 'El Salvador', 'SV', 'SLV', 1),
1219
-                array(60, 'Eritrea', 'ER', 'ERI', 1),
1220
-                array(61, 'Slovakia', 'SK', 'SVK', 2),
1221
-                array(62, 'Slovenia', 'SI', 'SVN', 2),
1222
-                array(65, 'Estonia', 'EE', 'EST', 2),
1223
-                array(66, 'Ethiopia', 'ET', 'ETH', 1),
1224
-                array(102, 'Faroe islands', 'FO', 'FRO', 1),
1225
-                array(103, 'Falkland Islands', 'FK', 'FLK', 1),
1226
-                array(67, 'Fiji', 'FJ', 'FJI', 1),
1227
-                array(69, 'Finland', 'FI', 'FIN', 2),
1228
-                array(71, 'Gabon', 'GA', 'GAB', 1),
1229
-                array(72, 'Gambia', 'GM', 'GMB', 1),
1230
-                array(73, 'Georgia', 'GE', 'GEO', 1),
1231
-                array(74, 'Ghana', 'GH', 'GHA', 1),
1232
-                array(75, 'Gibraltar', 'GI', 'GIB', 1),
1233
-                array(76, 'Greece', 'GR', 'GRC', 2),
1234
-                array(77, 'Grenada', 'GD', 'GRD', 1),
1235
-                array(78, 'Greenland', 'GL', 'GRL', 1),
1236
-                array(79, 'Guadeloupe', 'GP', 'GLP', 1),
1237
-                array(80, 'Guam', 'GU', 'GUM', 1),
1238
-                array(81, 'Guatemala', 'GT', 'GTM', 1),
1239
-                array(82, 'Guinea', 'GN', 'GIN', 1),
1240
-                array(83, 'Equatorial Guinea', 'GQ', 'GNQ', 1),
1241
-                array(84, 'Guinea-Bissau', 'GW', 'GNB', 1),
1242
-                array(85, 'Guyana', 'GY', 'GUY', 1),
1243
-                array(86, 'Haiti', 'HT', 'HTI', 1),
1244
-                array(88, 'Honduras', 'HN', 'HND', 1),
1245
-                array(89, 'Hong Kong', 'HK', 'HKG', 1),
1246
-                array(90, 'Hungary', 'HU', 'HUN', 1),
1247
-                array(91, 'India', 'IN', 'IND', 1),
1248
-                array(205, 'British Indian Ocean Territory', 'IO', 'IOT', 1),
1249
-                array(92, 'Indonesia', 'ID', 'IDN', 1),
1250
-                array(93, 'Iraq', 'IQ', 'IRQ', 1),
1251
-                array(94, 'Iran', 'IR', 'IRN', 1),
1252
-                array(95, 'Ireland', 'IE', 'IRL', 2),
1253
-                array(97, 'Iceland', 'IS', 'ISL', 1),
1254
-                array(110, 'Israel', 'IL', 'ISR', 1),
1255
-                array(49, 'Ivory Coast ', 'CI', 'CIV', 1),
1256
-                array(112, 'Jamaica', 'JM', 'JAM', 1),
1257
-                array(113, 'Japan', 'JP', 'JPN', 1),
1258
-                array(114, 'Jordan', 'JO', 'JOR', 1),
1259
-                array(115, 'Kazakhstan', 'KZ', 'KAZ', 1),
1260
-                array(116, 'Kenya', 'KE', 'KEN', 1),
1261
-                array(117, 'Kyrgyzstan', 'KG', 'KGZ', 1),
1262
-                array(118, 'Kiribati', 'KI', 'KIR', 1),
1263
-                array(48, 'South Korea', 'KR', 'KOR', 1),
1264
-                array(228, 'Kosovo', 'XK', 'XKV', 2),
1265
-                // there is no official ISO code for Kosovo yet (http://geonames.wordpress.com/2010/03/08/xk-country-code-for-kosovo/) so using a temporary country code and a modified 3 character code for ISO code -- this should be updated if/when Kosovo gets its own ISO code
1266
-                array(119, 'Kuwait', 'KW', 'KWT', 1),
1267
-                array(120, 'Laos', 'LA', 'LAO', 1),
1268
-                array(121, 'Latvia', 'LV', 'LVA', 2),
1269
-                array(122, 'Lesotho', 'LS', 'LSO', 1),
1270
-                array(123, 'Lebanon', 'LB', 'LBN', 1),
1271
-                array(124, 'Liberia', 'LR', 'LBR', 1),
1272
-                array(125, 'Libya', 'LY', 'LBY', 1),
1273
-                array(126, 'Liechtenstein', 'LI', 'LIE', 1),
1274
-                array(127, 'Lithuania', 'LT', 'LTU', 2),
1275
-                array(128, 'Luxemburg', 'LU', 'LUX', 2),
1276
-                array(129, 'Macao', 'MO', 'MAC', 1),
1277
-                array(130, 'Macedonia', 'MK', 'MKD', 1),
1278
-                array(131, 'Madagascar', 'MG', 'MDG', 1),
1279
-                array(132, 'Malaysia', 'MY', 'MYS', 1),
1280
-                array(133, 'Malawi', 'MW', 'MWI', 1),
1281
-                array(134, 'Maldivas', 'MV', 'MDV', 1),
1282
-                array(135, 'Mali', 'ML', 'MLI', 1),
1283
-                array(136, 'Malta', 'MT', 'MLT', 2),
1284
-                array(101, 'Northern Marianas', 'MP', 'MNP', 1),
1285
-                array(137, 'Morocco', 'MA', 'MAR', 1),
1286
-                array(104, 'Marshall islands', 'MH', 'MHL', 1),
1287
-                array(138, 'Martinique', 'MQ', 'MTQ', 1),
1288
-                array(139, 'Mauritius', 'MU', 'MUS', 1),
1289
-                array(140, 'Mauritania', 'MR', 'MRT', 1),
1290
-                array(141, 'Mayote', 'YT', 'MYT', 2),
1291
-                array(142, 'Mexico', 'MX', 'MEX', 1),
1292
-                array(143, 'Micronesia', 'FM', 'FSM', 1),
1293
-                array(144, 'Moldova', 'MD', 'MDA', 1),
1294
-                array(145, 'Monaco', 'MC', 'MCO', 2),
1295
-                array(146, 'Mongolia', 'MN', 'MNG', 1),
1296
-                array(147, 'Montserrat', 'MS', 'MSR', 1),
1297
-                array(227, 'Montenegro', 'ME', 'MNE', 2),
1298
-                array(148, 'Mozambique', 'MZ', 'MOZ', 1),
1299
-                array(149, 'Myanmar', 'MM', 'MMR', 1),
1300
-                array(150, 'Namibia', 'NA', 'NAM', 1),
1301
-                array(151, 'Nauru', 'NR', 'NRU', 1),
1302
-                array(152, 'Nepal', 'NP', 'NPL', 1),
1303
-                array(9, 'Netherlands Antilles', 'AN', 'ANT', 1),
1304
-                array(153, 'Nicaragua', 'NI', 'NIC', 1),
1305
-                array(154, 'Niger', 'NE', 'NER', 1),
1306
-                array(155, 'Nigeria', 'NG', 'NGA', 1),
1307
-                array(156, 'Niue', 'NU', 'NIU', 1),
1308
-                array(157, 'Norway', 'NO', 'NOR', 1),
1309
-                array(158, 'New Caledonia', 'NC', 'NCL', 1),
1310
-                array(159, 'New Zealand', 'NZ', 'NZL', 1),
1311
-                array(160, 'Oman', 'OM', 'OMN', 1),
1312
-                array(161, 'Pakistan', 'PK', 'PAK', 1),
1313
-                array(162, 'Palau', 'PW', 'PLW', 1),
1314
-                array(163, 'Panama', 'PA', 'PAN', 1),
1315
-                array(164, 'Papua New Guinea', 'PG', 'PNG', 1),
1316
-                array(165, 'Paraguay', 'PY', 'PRY', 1),
1317
-                array(166, 'Peru', 'PE', 'PER', 1),
1318
-                array(68, 'Philippines', 'PH', 'PHL', 1),
1319
-                array(167, 'Poland', 'PL', 'POL', 1),
1320
-                array(168, 'Portugal', 'PT', 'PRT', 2),
1321
-                array(169, 'Puerto Rico', 'PR', 'PRI', 1),
1322
-                array(170, 'Qatar', 'QA', 'QAT', 1),
1323
-                array(176, 'Rwanda', 'RW', 'RWA', 1),
1324
-                array(177, 'Romania', 'RO', 'ROM', 2),
1325
-                array(178, 'Russia', 'RU', 'RUS', 1),
1326
-                array(229, 'Saint Pierre and Miquelon', 'PM', 'SPM', 2),
1327
-                array(180, 'Samoa', 'WS', 'WSM', 1),
1328
-                array(181, 'American Samoa', 'AS', 'ASM', 1),
1329
-                array(183, 'San Marino', 'SM', 'SMR', 2),
1330
-                array(184, 'Saint Vincent and the Grenadines', 'VC', 'VCT', 1),
1331
-                array(185, 'Saint Helena', 'SH', 'SHN', 1),
1332
-                array(186, 'Saint Lucia', 'LC', 'LCA', 1),
1333
-                array(188, 'Senegal', 'SN', 'SEN', 1),
1334
-                array(189, 'Seychelles', 'SC', 'SYC', 1),
1335
-                array(190, 'Sierra Leona', 'SL', 'SLE', 1),
1336
-                array(191, 'Singapore', 'SG', 'SGP', 1),
1337
-                array(192, 'Syria', 'SY', 'SYR', 1),
1338
-                array(193, 'Somalia', 'SO', 'SOM', 1),
1339
-                array(194, 'Sri Lanka', 'LK', 'LKA', 1),
1340
-                array(195, 'South Africa', 'ZA', 'ZAF', 1),
1341
-                array(196, 'Sudan', 'SD', 'SDN', 1),
1342
-                array(199, 'Suriname', 'SR', 'SUR', 1),
1343
-                array(200, 'Swaziland', 'SZ', 'SWZ', 1),
1344
-                array(201, 'Thailand', 'TH', 'THA', 1),
1345
-                array(202, 'Taiwan', 'TW', 'TWN', 1),
1346
-                array(203, 'Tanzania', 'TZ', 'TZA', 1),
1347
-                array(204, 'Tajikistan', 'TJ', 'TJK', 1),
1348
-                array(206, 'Timor-Leste', 'TL', 'TLS', 1),
1349
-                array(207, 'Togo', 'TG', 'TGO', 1),
1350
-                array(208, 'Tokelau', 'TK', 'TKL', 1),
1351
-                array(209, 'Tonga', 'TO', 'TON', 1),
1352
-                array(210, 'Trinidad and Tobago', 'TT', 'TTO', 1),
1353
-                array(211, 'Tunisia', 'TN', 'TUN', 1),
1354
-                array(212, 'Turkmenistan', 'TM', 'TKM', 1),
1355
-                array(213, 'Turkey', 'TR', 'TUR', 1),
1356
-                array(214, 'Tuvalu', 'TV', 'TUV', 1),
1357
-                array(215, 'Ukraine', 'UA', 'UKR', 1),
1358
-                array(216, 'Uganda', 'UG', 'UGA', 1),
1359
-                array(59, 'United Arab Emirates', 'AE', 'ARE', 1),
1360
-                array(217, 'Uruguay', 'UY', 'URY', 1),
1361
-                array(218, 'Uzbekistan', 'UZ', 'UZB', 1),
1362
-                array(219, 'Vanuatu', 'VU', 'VUT', 1),
1363
-                array(220, 'Vatican City', 'VA', 'VAT', 2),
1364
-                array(221, 'Venezuela', 'VE', 'VEN', 1),
1365
-                array(222, 'Vietnam', 'VN', 'VNM', 1),
1366
-                array(108, 'Virgin Islands', 'VI', 'VIR', 1),
1367
-                array(223, 'Yemen', 'YE', 'YEM', 1),
1368
-                array(225, 'Zambia', 'ZM', 'ZMB', 1),
1369
-                array(226, 'Zimbabwe', 'ZW', 'ZWE', 1),
1370
-        );
1371
-        $country_iso = 'US';
1372
-        foreach ($old_countries as $country_array) {
1373
-            // note: index 0 is the 3.1 country ID
1374
-            if ($country_array[0] == $country_id) {
1375
-                // note: index 2 is the ISO
1376
-                $country_iso = $country_array[2];
1377
-                break;
1378
-            }
1379
-        }
1380
-        return $country_iso;
1381
-    }
1382
-
1383
-
1384
-
1385
-    /**
1386
-     * Gets the ISO3 for the
1387
-     *
1388
-     * @return string
1389
-     */
1390
-    public function get_default_country_iso()
1391
-    {
1392
-        $old_org_options = get_option('events_organization_settings');
1393
-        $iso = $this->get_iso_from_3_1_country_id($old_org_options['organization_country']);
1394
-        return $iso;
1395
-    }
1396
-
1397
-
1398
-
1399
-    /**
1400
-     * Converst a 3.1 payment status to its equivalent 4.1 regisration status
1401
-     *
1402
-     * @param string  $payment_status                   possible value for 3.1's evens_attendee.payment_status
1403
-     * @param boolean $this_thing_required_pre_approval whether the thing we're considering (the general setting's
1404
-     *                                                  default payment status, the event's default payment status, or
1405
-     *                                                  the attendee's payment status) required pre-approval.
1406
-     * @return string STS_ID for use in 4.1
1407
-     */
1408
-    public function convert_3_1_payment_status_to_4_1_STS_ID($payment_status, $this_thing_required_pre_approval = false)
1409
-    {
1410
-        // EE team can read the related discussion: https://app.asana.com/0/2400967562914/9418495544455
1411
-        if ($this_thing_required_pre_approval) {
1412
-            return 'RNA';
1413
-        } else {
1414
-            $mapping = $default_reg_stati_conversions = array(
1415
-                    'Completed'        => 'RAP',
1416
-                    ''                 => 'RPP',
1417
-                    'Incomplete'       => 'RPP',
1418
-                    'Pending'          => 'RAP',
1419
-                    // stati that only occurred on 3.1 attendees:
1420
-                    'Payment Declined' => 'RPP',
1421
-                    'Not Completed'    => 'RPP',
1422
-                    'Cancelled'        => 'RPP',
1423
-                    'Declined'         => 'RPP',
1424
-            );
1425
-        }
1426
-        return isset($mapping[ $payment_status ]) ? $mapping[ $payment_status ] : 'RNA';
1427
-    }
1428
-
1429
-
1430
-
1431
-    /**
1432
-     * Makes sure the 3.1's image url is converted to an image attachment post to the 4.1 CPT event
1433
-     * and sets it as the featured image on the CPT event
1434
-     *
1435
-     * @param type                            $old_event
1436
-     * @param type                            $new_cpt_id
1437
-     * @param  EE_Data_Migration_Script_Stage $migration_stage the stage which called this, where errors should be added
1438
-     * @return boolean whether or not we had to do the big job of creating an image attachment
1439
-     */
1440
-    public function convert_image_url_to_attachment_and_attach_to_post(
1441
-        $guid,
1442
-        $new_cpt_id,
1443
-        EE_Data_Migration_Script_Stage $migration_stage
1444
-    ) {
1445
-        $created_attachment_post = false;
1446
-        $guid = $this->_get_original_guid($guid);
1447
-        if ($guid) {
1448
-            // check for an existing attachment post with this guid
1449
-            $attachment_post_id = $this->_get_image_attachment_id_by_GUID($guid);
1450
-            if (! $attachment_post_id) {
1451
-                // post thumbnail with that GUID doesn't exist, we should create one
1452
-                $attachment_post_id = $this->_create_image_attachment_from_GUID($guid, $migration_stage);
1453
-                $created_attachment_post = true;
1454
-            }
1455
-            // double-check we actually have an attachment post
1456
-            if ($attachment_post_id) {
1457
-                update_post_meta($new_cpt_id, '_thumbnail_id', $attachment_post_id);
1458
-            } else {
1459
-                $migration_stage->add_error(sprintf(esc_html__(
1460
-                    "Could not update event image %s for CPT with ID %d, but attachments post ID is %d",
1461
-                    "event_espresso"
1462
-                ), $guid, $new_cpt_id, $attachment_post_id));
1463
-            }
1464
-        }
1465
-        return $created_attachment_post;
1466
-    }
1467
-
1468
-
1469
-
1470
-    /**
1471
-     * In 3.1, the event thumbnail image DOESN'T point to the orignal image, but instead
1472
-     * to a large thumbnail (which has nearly the same GUID, except it adds "-{width}x{height}" before the filetype,
1473
-     * or whatever dimensions it is. Eg 'http://mysite.com/image1-300x400.jpg' instead of
1474
-     * 'http://mysite.com/image1.jpg' ). This function attempts to strip that off and get the original file, if it
1475
-     * exists
1476
-     *
1477
-     * @param string $guid_in_old_event
1478
-     * @return string either the original guid, or $guid_in_old_event if we couldn't figure out what the original was
1479
-     */
1480
-    private function _get_original_guid($guid_in_old_event)
1481
-    {
1482
-        $original_guid = preg_replace('~-\d*x\d*\.~', '.', $guid_in_old_event, 1);
1483
-        // do a head request to verify the file exists
1484
-        $head_response = wp_remote_head($original_guid);
1485
-        if (! $head_response instanceof WP_Error && $head_response['response']['message'] == 'OK') {
1486
-            return $original_guid;
1487
-        } else {
1488
-            return $guid_in_old_event;
1489
-        }
1490
-    }
1491
-
1492
-
1493
-
1494
-    /**
1495
-     * Creates an image attachment post for the GUID. If the GUID points to a remote image,
1496
-     * we download it to our uploads directory so that it can be properly processed (eg, creates different sizes of
1497
-     * thumbnails)
1498
-     *
1499
-     * @param type                           $guid
1500
-     * @param EE_Data_Migration_Script_Stage $migration_stage
1501
-     * @return int
1502
-     */
1503
-    private function _create_image_attachment_from_GUID($guid, EE_Data_Migration_Script_Stage $migration_stage)
1504
-    {
1505
-        if (! $guid) {
1506
-            $migration_stage->add_error(sprintf(esc_html__(
1507
-                "Cannot create image attachment for a blank GUID!",
1508
-                "event_espresso"
1509
-            )));
1510
-            return 0;
1511
-        }
1512
-        $wp_filetype = wp_check_filetype(basename($guid), null);
1513
-        $wp_upload_dir = wp_upload_dir();
1514
-        // if the file is located remotely, download it to our uploads DIR, because wp_genereate_attachmnet_metadata needs the file to be local
1515
-        if (strpos($guid, $wp_upload_dir['url']) === false) {
1516
-            // image is located remotely. download it and place it in the uploads directory
1517
-            if (! is_readable($guid)) {
1518
-                $migration_stage->add_error(sprintf(esc_html__(
1519
-                    "Could not create image attachment from non-existent file: %s",
1520
-                    "event_espresso"
1521
-                ), $guid));
1522
-                return 0;
1523
-            }
1524
-            $contents = file_get_contents($guid);
1525
-            if ($contents === false) {
1526
-                $migration_stage->add_error(sprintf(esc_html__(
1527
-                    "Could not read image at %s, and therefore couldnt create an attachment post for it.",
1528
-                    "event_espresso"
1529
-                ), $guid));
1530
-                return false;
1531
-            }
1532
-            $local_filepath = $wp_upload_dir['path'] . '/' . basename($guid);
1533
-            $savefile = fopen($local_filepath, 'w');
1534
-            fwrite($savefile, $contents);
1535
-            fclose($savefile);
1536
-            $guid = str_replace($wp_upload_dir['path'], $wp_upload_dir['url'], $local_filepath);
1537
-        } else {
1538
-            $local_filepath = str_replace($wp_upload_dir['url'], $wp_upload_dir['path'], $guid);
1539
-        }
1540
-        $attachment = array(
1541
-                'guid'           => $guid,
1542
-                'post_mime_type' => $wp_filetype['type'],
1543
-                'post_title'     => preg_replace('/\.[^.]+$/', '', basename($guid)),
1544
-                'post_content'   => '',
1545
-                'post_status'    => 'inherit',
1546
-        );
1547
-        $attach_id = wp_insert_attachment($attachment, $guid);
1548
-        if (! $attach_id) {
1549
-            $migration_stage->add_error(sprintf(esc_html__(
1550
-                "Could not create image attachment post from image '%s'. Attachment data was %s.",
1551
-                "event_espresso"
1552
-            ), $guid, $this->_json_encode($attachment)));
1553
-            return $attach_id;
1554
-        }
1555
-        // you must first include the image.php file
1556
-        // for the function wp_generate_attachment_metadata() to work
1557
-        require_once(ABSPATH . 'wp-admin/includes/image.php');
1558
-        $attach_data = wp_generate_attachment_metadata($attach_id, $local_filepath);
1559
-        if (! $attach_data) {
1560
-            $migration_stage->add_error(sprintf(esc_html__(
1561
-                "Coudl not genereate attachment metadata for attachment post %d with filepath %s and GUID %s. Please check the file was downloaded properly.",
1562
-                "event_espresso"
1563
-            ), $attach_id, $local_filepath, $guid));
1564
-            return $attach_id;
1565
-        }
1566
-        $metadata_save_result = wp_update_attachment_metadata($attach_id, $attach_data);
1567
-        if (! $metadata_save_result) {
1568
-            $migration_stage->add_error(sprintf(esc_html__(
1569
-                "Could not update attachment metadata for attachment %d with data %s",
1570
-                "event_espresso"
1571
-            ), $attach_id, $this->_json_encode($attach_data)));
1572
-        }
1573
-        return $attach_id;
1574
-    }
1575
-
1576
-
1577
-
1578
-    /**
1579
-     * Finds the attachment post containing info about an image attachment given the GUID (link to the image itself),
1580
-     * and returns its ID.
1581
-     *
1582
-     * @global type  $wpdb
1583
-     * @param string $guid
1584
-     * @return int
1585
-     */
1586
-    private function _get_image_attachment_id_by_GUID($guid)
1587
-    {
1588
-        global $wpdb;
1589
-        $attachment_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid=%s LIMIT 1", $guid));
1590
-        return $attachment_id;
1591
-    }
1592
-
1593
-
1594
-
1595
-    /**
1596
-     * Returns a mysql-formatted DATETIME in UTC time, given a $DATETIME_string
1597
-     * (and optionally a timezone; if none is given, the wp default is used)
1598
-     *
1599
-     * @param EE_Data_Migration_Script_base $stage
1600
-     * @param array                         $row_of_data , the row from the DB (as an array) we're trying to find the
1601
-     *                                                   UTC time for
1602
-     * @param string                        $DATETIME_string
1603
-     * @param string                        $timezone
1604
-     * @return string
1605
-     */
1606
-    public function convert_date_string_to_utc(
1607
-        EE_Data_Migration_Script_Stage $stage,
1608
-        $row_of_data,
1609
-        $DATETIME_string,
1610
-        $timezone = null
1611
-    ) {
1612
-        $original_tz = $timezone;
1613
-        if (! $timezone) {
1614
-            $timezone = $this->_get_wp_timezone();
1615
-        }
1616
-        if (! $timezone) {
1617
-            $stage->add_error(sprintf(
1618
-                esc_html__("Could not find timezone given %s for %s", "event_espresso"),
1619
-                $original_tz,
1620
-                $row_of_data
1621
-            ));
1622
-            $timezone = 'UTC';
1623
-        }
1624
-        try {
1625
-            $date_obj = new DateTime($DATETIME_string, new DateTimeZone($timezone));
1626
-            EEH_DTT_Helper::setTimezone($date_obj, new DateTimeZone('UTC'));
1627
-        } catch (Exception $e) {
1628
-            $stage->add_error(sprintf(esc_html__(
1629
-                "Could not convert time string '%s' using timezone '%s' into a proper DATETIME. Using current time instead.",
1630
-                "event_espresso"
1631
-            ), $DATETIME_string, $timezone));
1632
-            $date_obj = new DateTime();
1633
-        }
1634
-        return $date_obj->format('Y-m-d H:i:s');
1635
-    }
1636
-
1637
-
1638
-
1639
-    /**
1640
-     * Gets the default timezone string from wordpress (even if they set a gmt offset)
1641
-     *
1642
-     * @return string
1643
-     */
1644
-    private function _get_wp_timezone()
1645
-    {
1646
-        $timezone = empty($timezone) ? get_option('timezone_string') : $timezone;
1647
-        // if timezone is STILL empty then let's get the GMT offset and then set the timezone_string using our converter
1648
-        if (empty($timezone)) {
1649
-            // let's get a the WordPress UTC offset
1650
-            $offset = get_option('gmt_offset');
1651
-            $timezone = $this->timezone_convert_to_string_from_offset($offset);
1652
-        }
1653
-        return $timezone;
1654
-    }
1655
-
1656
-
1657
-
1658
-    /**
1659
-     * Gets the wordpress timezone string from a UTC offset
1660
-     *
1661
-     * @param int $offset
1662
-     * @return boolean
1663
-     */
1664
-    private function timezone_convert_to_string_from_offset($offset)
1665
-    {
1666
-        // shamelessly taken from bottom comment at http://ca1.php.net/manual/en/function.timezone-name-from-abbr.php because timezone_name_from_abbr() did not work as expected - its not reliable
1667
-        $offset *= 3600; // convert hour offset to seconds
1668
-        $abbrarray = timezone_abbreviations_list();
1669
-        foreach ($abbrarray as $abbr) {
1670
-            foreach ($abbr as $city) {
1671
-                if ($city['offset'] == $offset) {
1672
-                    return $city['timezone_id'];
1673
-                }
1674
-            }
1675
-        }
1676
-        return false;
1677
-    }
1678
-
1679
-
1680
-
1681
-    public function migration_page_hooks()
1682
-    {
1683
-        add_filter(
1684
-            'FHEE__ee_migration_page__header',
1685
-            array($this, '_migrate_page_hook_simplify_version_strings'),
1686
-            10,
1687
-            3
1688
-        );
1689
-        add_filter(
1690
-            'FHEE__ee_migration_page__p_after_header',
1691
-            array($this, '_migration_page_hook_simplify_next_db_state'),
1692
-            10,
1693
-            2
1694
-        );
1695
-        add_filter(
1696
-            'FHEE__ee_migration_page__option_1_main',
1697
-            array($this, '_migrate_page_hook_simplify_version_strings'),
1698
-            10,
1699
-            3
1700
-        );
1701
-        add_filter(
1702
-            'FHEE__ee_migration_page__option_1_button_text',
1703
-            array($this, '_migrate_page_hook_simplify_version_strings'),
1704
-            10,
1705
-            3
1706
-        );
1707
-        add_action(
1708
-            'AHEE__ee_migration_page__option_1_extra_details',
1709
-            array($this, '_migration_page_hook_option_1_extra_details'),
1710
-            10,
1711
-            3
1712
-        );
1713
-        add_filter(
1714
-            'FHEE__ee_migration_page__option_2_main',
1715
-            array($this, '_migrate_page_hook_simplify_version_strings'),
1716
-            10,
1717
-            4
1718
-        );
1719
-        add_filter(
1720
-            'FHEE__ee_migration_page__option_2_button_text',
1721
-            array($this, '_migration_page_hook_simplify_next_db_state'),
1722
-            10,
1723
-            2
1724
-        );
1725
-        add_filter(
1726
-            'FHEE__ee_migration_page__option_2_details',
1727
-            array($this, '_migration_page_hook_simplify_next_db_state'),
1728
-            10,
1729
-            2
1730
-        );
1731
-        add_action(
1732
-            'AHEE__ee_migration_page__after_migration_options_table',
1733
-            array($this, '_migration_page_hook_after_migration_options_table')
1734
-        );
1735
-        add_filter(
1736
-            'FHEE__ee_migration_page__done_migration_header',
1737
-            array($this, '_migration_page_hook_simplify_next_db_state'),
1738
-            10,
1739
-            2
1740
-        );
1741
-        add_filter(
1742
-            'FHEE__ee_migration_page__p_after_done_migration_header',
1743
-            array($this, '_migration_page_hook_simplify_next_db_state'),
1744
-            10,
1745
-            2
1746
-        );
1747
-        add_filter(
1748
-            'FHEE__ee_migration_page__migration_options_template',
1749
-            array($this,'use_migration_options_from_ee3_template')
1750
-        );
1751
-    }
1752
-
1753
-
1754
-
1755
-    public function _migrate_page_hook_simplify_version_strings(
1756
-        $old_content,
1757
-        $current_db_state,
1758
-        $next_db_state,
1759
-        $ultimate_db_state = null
1760
-    ) {
1761
-        return str_replace(
1762
-            array($current_db_state, $next_db_state, $ultimate_db_state),
1763
-            array(esc_html__('EE3', 'event_espresso'), esc_html__('EE4', 'event_espresso'), esc_html__("EE4", 'event_espresso')),
1764
-            $old_content
1765
-        );
1766
-    }
1767
-
1768
-
1769
-
1770
-    public function _migration_page_hook_simplify_next_db_state($old_content, $next_db_state)
1771
-    {
1772
-        return str_replace($next_db_state, esc_html__("EE4", 'event_espresso'), $old_content);
1773
-    }
1774
-
1775
-
1776
-
1777
-    public function _migration_page_hook_option_1_extra_details()
1778
-    {
1779
-        ?>
1077
+		if (! $state) {
1078
+			// insert a new one then
1079
+			$cols_n_values = array(
1080
+					'CNT_ISO'    => $country_iso,
1081
+					'STA_abbrev' => substr($state_name, 0, 6),
1082
+					'STA_name'   => $state_name,
1083
+					'STA_active' => true,
1084
+			);
1085
+			$data_types = array(
1086
+					'%s',// CNT_ISO
1087
+					'%s',// STA_abbrev
1088
+					'%s',// STA_name
1089
+					'%d',// STA_active
1090
+			);
1091
+			$success = $wpdb->insert($state_table, $cols_n_values, $data_types);
1092
+			if (! $success) {
1093
+				throw new EE_Error($this->_create_error_message_for_db_insertion(
1094
+					'N/A',
1095
+					array('state' => $state_name, 'country_id' => $country_name),
1096
+					$state_table,
1097
+					$cols_n_values,
1098
+					$data_types
1099
+				));
1100
+			}
1101
+			$state = $cols_n_values;
1102
+			$state['STA_ID'] = $wpdb->insert_id;
1103
+		}
1104
+		return $state;
1105
+	}
1106
+
1107
+
1108
+
1109
+	/**
1110
+	 * Fixes times like "5:00 PM" into the expected 24-hour format "17:00".
1111
+	 * THis is actually just copied from the 3.1 JSON API because it needed to do the exact same thing
1112
+	 *
1113
+	 * @param type $timeString
1114
+	 * @return string in the php DATETIME format: "G:i" (24-hour format hour with leading zeros, a colon, and minutes
1115
+	 *                with leading zeros)
1116
+	 */
1117
+	public function convertTimeFromAMPM($timeString)
1118
+	{
1119
+		$matches = array();
1120
+		preg_match("~(\\d*):(\\d*)~", $timeString, $matches);
1121
+		if (! $matches || count($matches) < 3) {
1122
+			$hour = '00';
1123
+			$minutes = '00';
1124
+		} else {
1125
+			$hour = intval($matches[1]);
1126
+			$minutes = $matches[2];
1127
+		}
1128
+		if (strpos($timeString, 'PM') || strpos($timeString, 'pm')) {
1129
+			$hour = intval($hour) + 12;
1130
+		}
1131
+		$hour = str_pad("$hour", 2, '0', STR_PAD_LEFT);
1132
+		$minutes = str_pad("$minutes", 2, '0', STR_PAD_LEFT);
1133
+		return "$hour:$minutes";
1134
+	}
1135
+
1136
+
1137
+
1138
+	/**
1139
+	 * Gets the ISO3 fora country given its 3.1 country ID.
1140
+	 *
1141
+	 * @param int $country_id
1142
+	 * @return string the country's ISO3 code
1143
+	 */
1144
+	public function get_iso_from_3_1_country_id($country_id)
1145
+	{
1146
+		$old_countries = array(
1147
+				array(64, 'United States', 'US', 'USA', 1),
1148
+				array(15, 'Australia', 'AU', 'AUS', 1),
1149
+				array(39, 'Canada', 'CA', 'CAN', 1),
1150
+				array(171, 'United Kingdom', 'GB', 'GBR', 1),
1151
+				array(70, 'France', 'FR', 'FRA', 2),
1152
+				array(111, 'Italy', 'IT', 'ITA', 2),
1153
+				array(63, 'Spain', 'ES', 'ESP', 2),
1154
+				array(1, 'Afghanistan', 'AF', 'AFG', 1),
1155
+				array(2, 'Albania', 'AL', 'ALB', 1),
1156
+				array(3, 'Germany', 'DE', 'DEU', 2),
1157
+				array(198, 'Switzerland', 'CH', 'CHE', 1),
1158
+				array(87, 'Netherlands', 'NL', 'NLD', 2),
1159
+				array(197, 'Sweden', 'SE', 'SWE', 1),
1160
+				array(230, 'Akrotiri and Dhekelia', 'CY', 'CYP', 2),
1161
+				array(4, 'Andorra', 'AD', 'AND', 2),
1162
+				array(5, 'Angola', 'AO', 'AGO', 1),
1163
+				array(6, 'Anguilla', 'AI', 'AIA', 1),
1164
+				array(7, 'Antarctica', 'AQ', 'ATA', 1),
1165
+				array(8, 'Antigua and Barbuda', 'AG', 'ATG', 1),
1166
+				array(10, 'Saudi Arabia', 'SA', 'SAU', 1),
1167
+				array(11, 'Algeria', 'DZ', 'DZA', 1),
1168
+				array(12, 'Argentina', 'AR', 'ARG', 1),
1169
+				array(13, 'Armenia', 'AM', 'ARM', 1),
1170
+				array(14, 'Aruba', 'AW', 'ABW', 1),
1171
+				array(16, 'Austria', 'AT', 'AUT', 2),
1172
+				array(17, 'Azerbaijan', 'AZ', 'AZE', 1),
1173
+				array(18, 'Bahamas', 'BS', 'BHS', 1),
1174
+				array(19, 'Bahrain', 'BH', 'BHR', 1),
1175
+				array(20, 'Bangladesh', 'BD', 'BGD', 1),
1176
+				array(21, 'Barbados', 'BB', 'BRB', 1),
1177
+				array(22, 'Belgium ', 'BE', 'BEL', 2),
1178
+				array(23, 'Belize', 'BZ', 'BLZ', 1),
1179
+				array(24, 'Benin', 'BJ', 'BEN', 1),
1180
+				array(25, 'Bermudas', 'BM', 'BMU', 1),
1181
+				array(26, 'Belarus', 'BY', 'BLR', 1),
1182
+				array(27, 'Bolivia', 'BO', 'BOL', 1),
1183
+				array(28, 'Bosnia and Herzegovina', 'BA', 'BIH', 1),
1184
+				array(29, 'Botswana', 'BW', 'BWA', 1),
1185
+				array(96, 'Bouvet Island', 'BV', 'BVT', 1),
1186
+				array(30, 'Brazil', 'BR', 'BRA', 1),
1187
+				array(31, 'Brunei', 'BN', 'BRN', 1),
1188
+				array(32, 'Bulgaria', 'BG', 'BGR', 1),
1189
+				array(33, 'Burkina Faso', 'BF', 'BFA', 1),
1190
+				array(34, 'Burundi', 'BI', 'BDI', 1),
1191
+				array(35, 'Bhutan', 'BT', 'BTN', 1),
1192
+				array(36, 'Cape Verde', 'CV', 'CPV', 1),
1193
+				array(37, 'Cambodia', 'KH', 'KHM', 1),
1194
+				array(38, 'Cameroon', 'CM', 'CMR', 1),
1195
+				array(98, 'Cayman Islands', 'KY', 'CYM', 1),
1196
+				array(172, 'Central African Republic', 'CF', 'CAF', 1),
1197
+				array(40, 'Chad', 'TD', 'TCD', 1),
1198
+				array(41, 'Chile', 'CL', 'CHL', 1),
1199
+				array(42, 'China', 'CN', 'CHN', 1),
1200
+				array(105, 'Christmas Island', 'CX', 'CXR', 1),
1201
+				array(43, 'Cyprus', 'CY', 'CYP', 2),
1202
+				array(99, 'Cocos Island', 'CC', 'CCK', 1),
1203
+				array(100, 'Cook Islands', 'CK', 'COK', 1),
1204
+				array(44, 'Colombia', 'CO', 'COL', 1),
1205
+				array(45, 'Comoros', 'KM', 'COM', 1),
1206
+				array(46, 'Congo', 'CG', 'COG', 1),
1207
+				array(47, 'North Korea', 'KP', 'PRK', 1),
1208
+				array(50, 'Costa Rica', 'CR', 'CRI', 1),
1209
+				array(51, 'Croatia', 'HR', 'HRV', 1),
1210
+				array(52, 'Cuba', 'CU', 'CUB', 1),
1211
+				array(173, 'Czech Republic', 'CZ', 'CZE', 1),
1212
+				array(53, 'Denmark', 'DK', 'DNK', 1),
1213
+				array(54, 'Djibouti', 'DJ', 'DJI', 1),
1214
+				array(55, 'Dominica', 'DM', 'DMA', 1),
1215
+				array(174, 'Dominican Republic', 'DO', 'DOM', 1),
1216
+				array(56, 'Ecuador', 'EC', 'ECU', 1),
1217
+				array(57, 'Egypt', 'EG', 'EGY', 1),
1218
+				array(58, 'El Salvador', 'SV', 'SLV', 1),
1219
+				array(60, 'Eritrea', 'ER', 'ERI', 1),
1220
+				array(61, 'Slovakia', 'SK', 'SVK', 2),
1221
+				array(62, 'Slovenia', 'SI', 'SVN', 2),
1222
+				array(65, 'Estonia', 'EE', 'EST', 2),
1223
+				array(66, 'Ethiopia', 'ET', 'ETH', 1),
1224
+				array(102, 'Faroe islands', 'FO', 'FRO', 1),
1225
+				array(103, 'Falkland Islands', 'FK', 'FLK', 1),
1226
+				array(67, 'Fiji', 'FJ', 'FJI', 1),
1227
+				array(69, 'Finland', 'FI', 'FIN', 2),
1228
+				array(71, 'Gabon', 'GA', 'GAB', 1),
1229
+				array(72, 'Gambia', 'GM', 'GMB', 1),
1230
+				array(73, 'Georgia', 'GE', 'GEO', 1),
1231
+				array(74, 'Ghana', 'GH', 'GHA', 1),
1232
+				array(75, 'Gibraltar', 'GI', 'GIB', 1),
1233
+				array(76, 'Greece', 'GR', 'GRC', 2),
1234
+				array(77, 'Grenada', 'GD', 'GRD', 1),
1235
+				array(78, 'Greenland', 'GL', 'GRL', 1),
1236
+				array(79, 'Guadeloupe', 'GP', 'GLP', 1),
1237
+				array(80, 'Guam', 'GU', 'GUM', 1),
1238
+				array(81, 'Guatemala', 'GT', 'GTM', 1),
1239
+				array(82, 'Guinea', 'GN', 'GIN', 1),
1240
+				array(83, 'Equatorial Guinea', 'GQ', 'GNQ', 1),
1241
+				array(84, 'Guinea-Bissau', 'GW', 'GNB', 1),
1242
+				array(85, 'Guyana', 'GY', 'GUY', 1),
1243
+				array(86, 'Haiti', 'HT', 'HTI', 1),
1244
+				array(88, 'Honduras', 'HN', 'HND', 1),
1245
+				array(89, 'Hong Kong', 'HK', 'HKG', 1),
1246
+				array(90, 'Hungary', 'HU', 'HUN', 1),
1247
+				array(91, 'India', 'IN', 'IND', 1),
1248
+				array(205, 'British Indian Ocean Territory', 'IO', 'IOT', 1),
1249
+				array(92, 'Indonesia', 'ID', 'IDN', 1),
1250
+				array(93, 'Iraq', 'IQ', 'IRQ', 1),
1251
+				array(94, 'Iran', 'IR', 'IRN', 1),
1252
+				array(95, 'Ireland', 'IE', 'IRL', 2),
1253
+				array(97, 'Iceland', 'IS', 'ISL', 1),
1254
+				array(110, 'Israel', 'IL', 'ISR', 1),
1255
+				array(49, 'Ivory Coast ', 'CI', 'CIV', 1),
1256
+				array(112, 'Jamaica', 'JM', 'JAM', 1),
1257
+				array(113, 'Japan', 'JP', 'JPN', 1),
1258
+				array(114, 'Jordan', 'JO', 'JOR', 1),
1259
+				array(115, 'Kazakhstan', 'KZ', 'KAZ', 1),
1260
+				array(116, 'Kenya', 'KE', 'KEN', 1),
1261
+				array(117, 'Kyrgyzstan', 'KG', 'KGZ', 1),
1262
+				array(118, 'Kiribati', 'KI', 'KIR', 1),
1263
+				array(48, 'South Korea', 'KR', 'KOR', 1),
1264
+				array(228, 'Kosovo', 'XK', 'XKV', 2),
1265
+				// there is no official ISO code for Kosovo yet (http://geonames.wordpress.com/2010/03/08/xk-country-code-for-kosovo/) so using a temporary country code and a modified 3 character code for ISO code -- this should be updated if/when Kosovo gets its own ISO code
1266
+				array(119, 'Kuwait', 'KW', 'KWT', 1),
1267
+				array(120, 'Laos', 'LA', 'LAO', 1),
1268
+				array(121, 'Latvia', 'LV', 'LVA', 2),
1269
+				array(122, 'Lesotho', 'LS', 'LSO', 1),
1270
+				array(123, 'Lebanon', 'LB', 'LBN', 1),
1271
+				array(124, 'Liberia', 'LR', 'LBR', 1),
1272
+				array(125, 'Libya', 'LY', 'LBY', 1),
1273
+				array(126, 'Liechtenstein', 'LI', 'LIE', 1),
1274
+				array(127, 'Lithuania', 'LT', 'LTU', 2),
1275
+				array(128, 'Luxemburg', 'LU', 'LUX', 2),
1276
+				array(129, 'Macao', 'MO', 'MAC', 1),
1277
+				array(130, 'Macedonia', 'MK', 'MKD', 1),
1278
+				array(131, 'Madagascar', 'MG', 'MDG', 1),
1279
+				array(132, 'Malaysia', 'MY', 'MYS', 1),
1280
+				array(133, 'Malawi', 'MW', 'MWI', 1),
1281
+				array(134, 'Maldivas', 'MV', 'MDV', 1),
1282
+				array(135, 'Mali', 'ML', 'MLI', 1),
1283
+				array(136, 'Malta', 'MT', 'MLT', 2),
1284
+				array(101, 'Northern Marianas', 'MP', 'MNP', 1),
1285
+				array(137, 'Morocco', 'MA', 'MAR', 1),
1286
+				array(104, 'Marshall islands', 'MH', 'MHL', 1),
1287
+				array(138, 'Martinique', 'MQ', 'MTQ', 1),
1288
+				array(139, 'Mauritius', 'MU', 'MUS', 1),
1289
+				array(140, 'Mauritania', 'MR', 'MRT', 1),
1290
+				array(141, 'Mayote', 'YT', 'MYT', 2),
1291
+				array(142, 'Mexico', 'MX', 'MEX', 1),
1292
+				array(143, 'Micronesia', 'FM', 'FSM', 1),
1293
+				array(144, 'Moldova', 'MD', 'MDA', 1),
1294
+				array(145, 'Monaco', 'MC', 'MCO', 2),
1295
+				array(146, 'Mongolia', 'MN', 'MNG', 1),
1296
+				array(147, 'Montserrat', 'MS', 'MSR', 1),
1297
+				array(227, 'Montenegro', 'ME', 'MNE', 2),
1298
+				array(148, 'Mozambique', 'MZ', 'MOZ', 1),
1299
+				array(149, 'Myanmar', 'MM', 'MMR', 1),
1300
+				array(150, 'Namibia', 'NA', 'NAM', 1),
1301
+				array(151, 'Nauru', 'NR', 'NRU', 1),
1302
+				array(152, 'Nepal', 'NP', 'NPL', 1),
1303
+				array(9, 'Netherlands Antilles', 'AN', 'ANT', 1),
1304
+				array(153, 'Nicaragua', 'NI', 'NIC', 1),
1305
+				array(154, 'Niger', 'NE', 'NER', 1),
1306
+				array(155, 'Nigeria', 'NG', 'NGA', 1),
1307
+				array(156, 'Niue', 'NU', 'NIU', 1),
1308
+				array(157, 'Norway', 'NO', 'NOR', 1),
1309
+				array(158, 'New Caledonia', 'NC', 'NCL', 1),
1310
+				array(159, 'New Zealand', 'NZ', 'NZL', 1),
1311
+				array(160, 'Oman', 'OM', 'OMN', 1),
1312
+				array(161, 'Pakistan', 'PK', 'PAK', 1),
1313
+				array(162, 'Palau', 'PW', 'PLW', 1),
1314
+				array(163, 'Panama', 'PA', 'PAN', 1),
1315
+				array(164, 'Papua New Guinea', 'PG', 'PNG', 1),
1316
+				array(165, 'Paraguay', 'PY', 'PRY', 1),
1317
+				array(166, 'Peru', 'PE', 'PER', 1),
1318
+				array(68, 'Philippines', 'PH', 'PHL', 1),
1319
+				array(167, 'Poland', 'PL', 'POL', 1),
1320
+				array(168, 'Portugal', 'PT', 'PRT', 2),
1321
+				array(169, 'Puerto Rico', 'PR', 'PRI', 1),
1322
+				array(170, 'Qatar', 'QA', 'QAT', 1),
1323
+				array(176, 'Rwanda', 'RW', 'RWA', 1),
1324
+				array(177, 'Romania', 'RO', 'ROM', 2),
1325
+				array(178, 'Russia', 'RU', 'RUS', 1),
1326
+				array(229, 'Saint Pierre and Miquelon', 'PM', 'SPM', 2),
1327
+				array(180, 'Samoa', 'WS', 'WSM', 1),
1328
+				array(181, 'American Samoa', 'AS', 'ASM', 1),
1329
+				array(183, 'San Marino', 'SM', 'SMR', 2),
1330
+				array(184, 'Saint Vincent and the Grenadines', 'VC', 'VCT', 1),
1331
+				array(185, 'Saint Helena', 'SH', 'SHN', 1),
1332
+				array(186, 'Saint Lucia', 'LC', 'LCA', 1),
1333
+				array(188, 'Senegal', 'SN', 'SEN', 1),
1334
+				array(189, 'Seychelles', 'SC', 'SYC', 1),
1335
+				array(190, 'Sierra Leona', 'SL', 'SLE', 1),
1336
+				array(191, 'Singapore', 'SG', 'SGP', 1),
1337
+				array(192, 'Syria', 'SY', 'SYR', 1),
1338
+				array(193, 'Somalia', 'SO', 'SOM', 1),
1339
+				array(194, 'Sri Lanka', 'LK', 'LKA', 1),
1340
+				array(195, 'South Africa', 'ZA', 'ZAF', 1),
1341
+				array(196, 'Sudan', 'SD', 'SDN', 1),
1342
+				array(199, 'Suriname', 'SR', 'SUR', 1),
1343
+				array(200, 'Swaziland', 'SZ', 'SWZ', 1),
1344
+				array(201, 'Thailand', 'TH', 'THA', 1),
1345
+				array(202, 'Taiwan', 'TW', 'TWN', 1),
1346
+				array(203, 'Tanzania', 'TZ', 'TZA', 1),
1347
+				array(204, 'Tajikistan', 'TJ', 'TJK', 1),
1348
+				array(206, 'Timor-Leste', 'TL', 'TLS', 1),
1349
+				array(207, 'Togo', 'TG', 'TGO', 1),
1350
+				array(208, 'Tokelau', 'TK', 'TKL', 1),
1351
+				array(209, 'Tonga', 'TO', 'TON', 1),
1352
+				array(210, 'Trinidad and Tobago', 'TT', 'TTO', 1),
1353
+				array(211, 'Tunisia', 'TN', 'TUN', 1),
1354
+				array(212, 'Turkmenistan', 'TM', 'TKM', 1),
1355
+				array(213, 'Turkey', 'TR', 'TUR', 1),
1356
+				array(214, 'Tuvalu', 'TV', 'TUV', 1),
1357
+				array(215, 'Ukraine', 'UA', 'UKR', 1),
1358
+				array(216, 'Uganda', 'UG', 'UGA', 1),
1359
+				array(59, 'United Arab Emirates', 'AE', 'ARE', 1),
1360
+				array(217, 'Uruguay', 'UY', 'URY', 1),
1361
+				array(218, 'Uzbekistan', 'UZ', 'UZB', 1),
1362
+				array(219, 'Vanuatu', 'VU', 'VUT', 1),
1363
+				array(220, 'Vatican City', 'VA', 'VAT', 2),
1364
+				array(221, 'Venezuela', 'VE', 'VEN', 1),
1365
+				array(222, 'Vietnam', 'VN', 'VNM', 1),
1366
+				array(108, 'Virgin Islands', 'VI', 'VIR', 1),
1367
+				array(223, 'Yemen', 'YE', 'YEM', 1),
1368
+				array(225, 'Zambia', 'ZM', 'ZMB', 1),
1369
+				array(226, 'Zimbabwe', 'ZW', 'ZWE', 1),
1370
+		);
1371
+		$country_iso = 'US';
1372
+		foreach ($old_countries as $country_array) {
1373
+			// note: index 0 is the 3.1 country ID
1374
+			if ($country_array[0] == $country_id) {
1375
+				// note: index 2 is the ISO
1376
+				$country_iso = $country_array[2];
1377
+				break;
1378
+			}
1379
+		}
1380
+		return $country_iso;
1381
+	}
1382
+
1383
+
1384
+
1385
+	/**
1386
+	 * Gets the ISO3 for the
1387
+	 *
1388
+	 * @return string
1389
+	 */
1390
+	public function get_default_country_iso()
1391
+	{
1392
+		$old_org_options = get_option('events_organization_settings');
1393
+		$iso = $this->get_iso_from_3_1_country_id($old_org_options['organization_country']);
1394
+		return $iso;
1395
+	}
1396
+
1397
+
1398
+
1399
+	/**
1400
+	 * Converst a 3.1 payment status to its equivalent 4.1 regisration status
1401
+	 *
1402
+	 * @param string  $payment_status                   possible value for 3.1's evens_attendee.payment_status
1403
+	 * @param boolean $this_thing_required_pre_approval whether the thing we're considering (the general setting's
1404
+	 *                                                  default payment status, the event's default payment status, or
1405
+	 *                                                  the attendee's payment status) required pre-approval.
1406
+	 * @return string STS_ID for use in 4.1
1407
+	 */
1408
+	public function convert_3_1_payment_status_to_4_1_STS_ID($payment_status, $this_thing_required_pre_approval = false)
1409
+	{
1410
+		// EE team can read the related discussion: https://app.asana.com/0/2400967562914/9418495544455
1411
+		if ($this_thing_required_pre_approval) {
1412
+			return 'RNA';
1413
+		} else {
1414
+			$mapping = $default_reg_stati_conversions = array(
1415
+					'Completed'        => 'RAP',
1416
+					''                 => 'RPP',
1417
+					'Incomplete'       => 'RPP',
1418
+					'Pending'          => 'RAP',
1419
+					// stati that only occurred on 3.1 attendees:
1420
+					'Payment Declined' => 'RPP',
1421
+					'Not Completed'    => 'RPP',
1422
+					'Cancelled'        => 'RPP',
1423
+					'Declined'         => 'RPP',
1424
+			);
1425
+		}
1426
+		return isset($mapping[ $payment_status ]) ? $mapping[ $payment_status ] : 'RNA';
1427
+	}
1428
+
1429
+
1430
+
1431
+	/**
1432
+	 * Makes sure the 3.1's image url is converted to an image attachment post to the 4.1 CPT event
1433
+	 * and sets it as the featured image on the CPT event
1434
+	 *
1435
+	 * @param type                            $old_event
1436
+	 * @param type                            $new_cpt_id
1437
+	 * @param  EE_Data_Migration_Script_Stage $migration_stage the stage which called this, where errors should be added
1438
+	 * @return boolean whether or not we had to do the big job of creating an image attachment
1439
+	 */
1440
+	public function convert_image_url_to_attachment_and_attach_to_post(
1441
+		$guid,
1442
+		$new_cpt_id,
1443
+		EE_Data_Migration_Script_Stage $migration_stage
1444
+	) {
1445
+		$created_attachment_post = false;
1446
+		$guid = $this->_get_original_guid($guid);
1447
+		if ($guid) {
1448
+			// check for an existing attachment post with this guid
1449
+			$attachment_post_id = $this->_get_image_attachment_id_by_GUID($guid);
1450
+			if (! $attachment_post_id) {
1451
+				// post thumbnail with that GUID doesn't exist, we should create one
1452
+				$attachment_post_id = $this->_create_image_attachment_from_GUID($guid, $migration_stage);
1453
+				$created_attachment_post = true;
1454
+			}
1455
+			// double-check we actually have an attachment post
1456
+			if ($attachment_post_id) {
1457
+				update_post_meta($new_cpt_id, '_thumbnail_id', $attachment_post_id);
1458
+			} else {
1459
+				$migration_stage->add_error(sprintf(esc_html__(
1460
+					"Could not update event image %s for CPT with ID %d, but attachments post ID is %d",
1461
+					"event_espresso"
1462
+				), $guid, $new_cpt_id, $attachment_post_id));
1463
+			}
1464
+		}
1465
+		return $created_attachment_post;
1466
+	}
1467
+
1468
+
1469
+
1470
+	/**
1471
+	 * In 3.1, the event thumbnail image DOESN'T point to the orignal image, but instead
1472
+	 * to a large thumbnail (which has nearly the same GUID, except it adds "-{width}x{height}" before the filetype,
1473
+	 * or whatever dimensions it is. Eg 'http://mysite.com/image1-300x400.jpg' instead of
1474
+	 * 'http://mysite.com/image1.jpg' ). This function attempts to strip that off and get the original file, if it
1475
+	 * exists
1476
+	 *
1477
+	 * @param string $guid_in_old_event
1478
+	 * @return string either the original guid, or $guid_in_old_event if we couldn't figure out what the original was
1479
+	 */
1480
+	private function _get_original_guid($guid_in_old_event)
1481
+	{
1482
+		$original_guid = preg_replace('~-\d*x\d*\.~', '.', $guid_in_old_event, 1);
1483
+		// do a head request to verify the file exists
1484
+		$head_response = wp_remote_head($original_guid);
1485
+		if (! $head_response instanceof WP_Error && $head_response['response']['message'] == 'OK') {
1486
+			return $original_guid;
1487
+		} else {
1488
+			return $guid_in_old_event;
1489
+		}
1490
+	}
1491
+
1492
+
1493
+
1494
+	/**
1495
+	 * Creates an image attachment post for the GUID. If the GUID points to a remote image,
1496
+	 * we download it to our uploads directory so that it can be properly processed (eg, creates different sizes of
1497
+	 * thumbnails)
1498
+	 *
1499
+	 * @param type                           $guid
1500
+	 * @param EE_Data_Migration_Script_Stage $migration_stage
1501
+	 * @return int
1502
+	 */
1503
+	private function _create_image_attachment_from_GUID($guid, EE_Data_Migration_Script_Stage $migration_stage)
1504
+	{
1505
+		if (! $guid) {
1506
+			$migration_stage->add_error(sprintf(esc_html__(
1507
+				"Cannot create image attachment for a blank GUID!",
1508
+				"event_espresso"
1509
+			)));
1510
+			return 0;
1511
+		}
1512
+		$wp_filetype = wp_check_filetype(basename($guid), null);
1513
+		$wp_upload_dir = wp_upload_dir();
1514
+		// if the file is located remotely, download it to our uploads DIR, because wp_genereate_attachmnet_metadata needs the file to be local
1515
+		if (strpos($guid, $wp_upload_dir['url']) === false) {
1516
+			// image is located remotely. download it and place it in the uploads directory
1517
+			if (! is_readable($guid)) {
1518
+				$migration_stage->add_error(sprintf(esc_html__(
1519
+					"Could not create image attachment from non-existent file: %s",
1520
+					"event_espresso"
1521
+				), $guid));
1522
+				return 0;
1523
+			}
1524
+			$contents = file_get_contents($guid);
1525
+			if ($contents === false) {
1526
+				$migration_stage->add_error(sprintf(esc_html__(
1527
+					"Could not read image at %s, and therefore couldnt create an attachment post for it.",
1528
+					"event_espresso"
1529
+				), $guid));
1530
+				return false;
1531
+			}
1532
+			$local_filepath = $wp_upload_dir['path'] . '/' . basename($guid);
1533
+			$savefile = fopen($local_filepath, 'w');
1534
+			fwrite($savefile, $contents);
1535
+			fclose($savefile);
1536
+			$guid = str_replace($wp_upload_dir['path'], $wp_upload_dir['url'], $local_filepath);
1537
+		} else {
1538
+			$local_filepath = str_replace($wp_upload_dir['url'], $wp_upload_dir['path'], $guid);
1539
+		}
1540
+		$attachment = array(
1541
+				'guid'           => $guid,
1542
+				'post_mime_type' => $wp_filetype['type'],
1543
+				'post_title'     => preg_replace('/\.[^.]+$/', '', basename($guid)),
1544
+				'post_content'   => '',
1545
+				'post_status'    => 'inherit',
1546
+		);
1547
+		$attach_id = wp_insert_attachment($attachment, $guid);
1548
+		if (! $attach_id) {
1549
+			$migration_stage->add_error(sprintf(esc_html__(
1550
+				"Could not create image attachment post from image '%s'. Attachment data was %s.",
1551
+				"event_espresso"
1552
+			), $guid, $this->_json_encode($attachment)));
1553
+			return $attach_id;
1554
+		}
1555
+		// you must first include the image.php file
1556
+		// for the function wp_generate_attachment_metadata() to work
1557
+		require_once(ABSPATH . 'wp-admin/includes/image.php');
1558
+		$attach_data = wp_generate_attachment_metadata($attach_id, $local_filepath);
1559
+		if (! $attach_data) {
1560
+			$migration_stage->add_error(sprintf(esc_html__(
1561
+				"Coudl not genereate attachment metadata for attachment post %d with filepath %s and GUID %s. Please check the file was downloaded properly.",
1562
+				"event_espresso"
1563
+			), $attach_id, $local_filepath, $guid));
1564
+			return $attach_id;
1565
+		}
1566
+		$metadata_save_result = wp_update_attachment_metadata($attach_id, $attach_data);
1567
+		if (! $metadata_save_result) {
1568
+			$migration_stage->add_error(sprintf(esc_html__(
1569
+				"Could not update attachment metadata for attachment %d with data %s",
1570
+				"event_espresso"
1571
+			), $attach_id, $this->_json_encode($attach_data)));
1572
+		}
1573
+		return $attach_id;
1574
+	}
1575
+
1576
+
1577
+
1578
+	/**
1579
+	 * Finds the attachment post containing info about an image attachment given the GUID (link to the image itself),
1580
+	 * and returns its ID.
1581
+	 *
1582
+	 * @global type  $wpdb
1583
+	 * @param string $guid
1584
+	 * @return int
1585
+	 */
1586
+	private function _get_image_attachment_id_by_GUID($guid)
1587
+	{
1588
+		global $wpdb;
1589
+		$attachment_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid=%s LIMIT 1", $guid));
1590
+		return $attachment_id;
1591
+	}
1592
+
1593
+
1594
+
1595
+	/**
1596
+	 * Returns a mysql-formatted DATETIME in UTC time, given a $DATETIME_string
1597
+	 * (and optionally a timezone; if none is given, the wp default is used)
1598
+	 *
1599
+	 * @param EE_Data_Migration_Script_base $stage
1600
+	 * @param array                         $row_of_data , the row from the DB (as an array) we're trying to find the
1601
+	 *                                                   UTC time for
1602
+	 * @param string                        $DATETIME_string
1603
+	 * @param string                        $timezone
1604
+	 * @return string
1605
+	 */
1606
+	public function convert_date_string_to_utc(
1607
+		EE_Data_Migration_Script_Stage $stage,
1608
+		$row_of_data,
1609
+		$DATETIME_string,
1610
+		$timezone = null
1611
+	) {
1612
+		$original_tz = $timezone;
1613
+		if (! $timezone) {
1614
+			$timezone = $this->_get_wp_timezone();
1615
+		}
1616
+		if (! $timezone) {
1617
+			$stage->add_error(sprintf(
1618
+				esc_html__("Could not find timezone given %s for %s", "event_espresso"),
1619
+				$original_tz,
1620
+				$row_of_data
1621
+			));
1622
+			$timezone = 'UTC';
1623
+		}
1624
+		try {
1625
+			$date_obj = new DateTime($DATETIME_string, new DateTimeZone($timezone));
1626
+			EEH_DTT_Helper::setTimezone($date_obj, new DateTimeZone('UTC'));
1627
+		} catch (Exception $e) {
1628
+			$stage->add_error(sprintf(esc_html__(
1629
+				"Could not convert time string '%s' using timezone '%s' into a proper DATETIME. Using current time instead.",
1630
+				"event_espresso"
1631
+			), $DATETIME_string, $timezone));
1632
+			$date_obj = new DateTime();
1633
+		}
1634
+		return $date_obj->format('Y-m-d H:i:s');
1635
+	}
1636
+
1637
+
1638
+
1639
+	/**
1640
+	 * Gets the default timezone string from wordpress (even if they set a gmt offset)
1641
+	 *
1642
+	 * @return string
1643
+	 */
1644
+	private function _get_wp_timezone()
1645
+	{
1646
+		$timezone = empty($timezone) ? get_option('timezone_string') : $timezone;
1647
+		// if timezone is STILL empty then let's get the GMT offset and then set the timezone_string using our converter
1648
+		if (empty($timezone)) {
1649
+			// let's get a the WordPress UTC offset
1650
+			$offset = get_option('gmt_offset');
1651
+			$timezone = $this->timezone_convert_to_string_from_offset($offset);
1652
+		}
1653
+		return $timezone;
1654
+	}
1655
+
1656
+
1657
+
1658
+	/**
1659
+	 * Gets the wordpress timezone string from a UTC offset
1660
+	 *
1661
+	 * @param int $offset
1662
+	 * @return boolean
1663
+	 */
1664
+	private function timezone_convert_to_string_from_offset($offset)
1665
+	{
1666
+		// shamelessly taken from bottom comment at http://ca1.php.net/manual/en/function.timezone-name-from-abbr.php because timezone_name_from_abbr() did not work as expected - its not reliable
1667
+		$offset *= 3600; // convert hour offset to seconds
1668
+		$abbrarray = timezone_abbreviations_list();
1669
+		foreach ($abbrarray as $abbr) {
1670
+			foreach ($abbr as $city) {
1671
+				if ($city['offset'] == $offset) {
1672
+					return $city['timezone_id'];
1673
+				}
1674
+			}
1675
+		}
1676
+		return false;
1677
+	}
1678
+
1679
+
1680
+
1681
+	public function migration_page_hooks()
1682
+	{
1683
+		add_filter(
1684
+			'FHEE__ee_migration_page__header',
1685
+			array($this, '_migrate_page_hook_simplify_version_strings'),
1686
+			10,
1687
+			3
1688
+		);
1689
+		add_filter(
1690
+			'FHEE__ee_migration_page__p_after_header',
1691
+			array($this, '_migration_page_hook_simplify_next_db_state'),
1692
+			10,
1693
+			2
1694
+		);
1695
+		add_filter(
1696
+			'FHEE__ee_migration_page__option_1_main',
1697
+			array($this, '_migrate_page_hook_simplify_version_strings'),
1698
+			10,
1699
+			3
1700
+		);
1701
+		add_filter(
1702
+			'FHEE__ee_migration_page__option_1_button_text',
1703
+			array($this, '_migrate_page_hook_simplify_version_strings'),
1704
+			10,
1705
+			3
1706
+		);
1707
+		add_action(
1708
+			'AHEE__ee_migration_page__option_1_extra_details',
1709
+			array($this, '_migration_page_hook_option_1_extra_details'),
1710
+			10,
1711
+			3
1712
+		);
1713
+		add_filter(
1714
+			'FHEE__ee_migration_page__option_2_main',
1715
+			array($this, '_migrate_page_hook_simplify_version_strings'),
1716
+			10,
1717
+			4
1718
+		);
1719
+		add_filter(
1720
+			'FHEE__ee_migration_page__option_2_button_text',
1721
+			array($this, '_migration_page_hook_simplify_next_db_state'),
1722
+			10,
1723
+			2
1724
+		);
1725
+		add_filter(
1726
+			'FHEE__ee_migration_page__option_2_details',
1727
+			array($this, '_migration_page_hook_simplify_next_db_state'),
1728
+			10,
1729
+			2
1730
+		);
1731
+		add_action(
1732
+			'AHEE__ee_migration_page__after_migration_options_table',
1733
+			array($this, '_migration_page_hook_after_migration_options_table')
1734
+		);
1735
+		add_filter(
1736
+			'FHEE__ee_migration_page__done_migration_header',
1737
+			array($this, '_migration_page_hook_simplify_next_db_state'),
1738
+			10,
1739
+			2
1740
+		);
1741
+		add_filter(
1742
+			'FHEE__ee_migration_page__p_after_done_migration_header',
1743
+			array($this, '_migration_page_hook_simplify_next_db_state'),
1744
+			10,
1745
+			2
1746
+		);
1747
+		add_filter(
1748
+			'FHEE__ee_migration_page__migration_options_template',
1749
+			array($this,'use_migration_options_from_ee3_template')
1750
+		);
1751
+	}
1752
+
1753
+
1754
+
1755
+	public function _migrate_page_hook_simplify_version_strings(
1756
+		$old_content,
1757
+		$current_db_state,
1758
+		$next_db_state,
1759
+		$ultimate_db_state = null
1760
+	) {
1761
+		return str_replace(
1762
+			array($current_db_state, $next_db_state, $ultimate_db_state),
1763
+			array(esc_html__('EE3', 'event_espresso'), esc_html__('EE4', 'event_espresso'), esc_html__("EE4", 'event_espresso')),
1764
+			$old_content
1765
+		);
1766
+	}
1767
+
1768
+
1769
+
1770
+	public function _migration_page_hook_simplify_next_db_state($old_content, $next_db_state)
1771
+	{
1772
+		return str_replace($next_db_state, esc_html__("EE4", 'event_espresso'), $old_content);
1773
+	}
1774
+
1775
+
1776
+
1777
+	public function _migration_page_hook_option_1_extra_details()
1778
+	{
1779
+		?>
1780 1780
         <p><?php printf(esc_html__(
1781
-            "Note: many of your EE3 shortcodes will be changed to EE4 shortcodes during this migration (among many other things). Should you revert to EE3, then you should restore to your backup or manually change the EE4 shortcodes back to their EE3 equivalents",
1782
-            "event_espresso"
1783
-        )); ?></p><?php
1784
-    }
1781
+			"Note: many of your EE3 shortcodes will be changed to EE4 shortcodes during this migration (among many other things). Should you revert to EE3, then you should restore to your backup or manually change the EE4 shortcodes back to their EE3 equivalents",
1782
+			"event_espresso"
1783
+		)); ?></p><?php
1784
+	}
1785 1785
 
1786 1786
 
1787 1787
 
1788
-    public function _migration_page_hook_after_migration_options_table()
1789
-    {
1790
-        ?><p class="ee-attention">
1788
+	public function _migration_page_hook_after_migration_options_table()
1789
+	{
1790
+		?><p class="ee-attention">
1791 1791
         <strong><span class="reminder-spn">
1792 1792
                 <?php esc_html_e(
1793
-                    "Important note to those using Event Espresso 3 addons: ",
1794
-                    "event_espresso"
1795
-                ); ?></span></strong>
1793
+					"Important note to those using Event Espresso 3 addons: ",
1794
+					"event_espresso"
1795
+				); ?></span></strong>
1796 1796
         <br/>
1797 1797
         <?php esc_html_e(
1798
-            "Unless an addon's description on our website explicitly states that it is compatible with EE4, you should consider it incompatible and know that it WILL NOT WORK correctly with this new version of Event Espresso 4 (EE4). As well, any data for incompatible addons will NOT BE MIGRATED until an updated EE4 compatible version of the addon is available. If you want, or need to keep using your EE3 addons, you should simply continue using EE3 until EE4 compatible versions of your addons become available. To continue using EE3 for now, just deactivate EE4 and reactivate EE3.",
1799
-            "event_espresso"
1800
-        ); ?>
1798
+			"Unless an addon's description on our website explicitly states that it is compatible with EE4, you should consider it incompatible and know that it WILL NOT WORK correctly with this new version of Event Espresso 4 (EE4). As well, any data for incompatible addons will NOT BE MIGRATED until an updated EE4 compatible version of the addon is available. If you want, or need to keep using your EE3 addons, you should simply continue using EE3 until EE4 compatible versions of your addons become available. To continue using EE3 for now, just deactivate EE4 and reactivate EE3.",
1799
+			"event_espresso"
1800
+		); ?>
1801 1801
         </p><?php
1802
-    }
1802
+	}
1803 1803
 
1804 1804
 
1805 1805
 
1806
-    /**
1807
-     * When showing the migration options, show more options and info than normal (ie, give folks the option
1808
-     * to start using EE4 without migrating. From EE3 that's fine, because it doesn't actually remove any data, because
1809
-     * EE4 doesn't have any yet. But when migrating from EE4 it would remove old data, so its not a great idea).
1810
-     * @param $template_filepath
1811
-     * @return string
1812
-     */
1813
-    public function use_migration_options_from_ee3_template($template_filepath)
1814
-    {
1815
-        return EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee3.template.php';
1816
-    }
1806
+	/**
1807
+	 * When showing the migration options, show more options and info than normal (ie, give folks the option
1808
+	 * to start using EE4 without migrating. From EE3 that's fine, because it doesn't actually remove any data, because
1809
+	 * EE4 doesn't have any yet. But when migrating from EE4 it would remove old data, so its not a great idea).
1810
+	 * @param $template_filepath
1811
+	 * @return string
1812
+	 */
1813
+	public function use_migration_options_from_ee3_template($template_filepath)
1814
+	{
1815
+		return EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee3.template.php';
1816
+	}
1817 1817
 }
Please login to merge, or discard this patch.
Spacing   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -11,13 +11,13 @@  discard block
 block discarded – undo
11 11
 // unfortunately, this needs to be done upon INCLUSION of this file,
12 12
 // instead of construction, because it only gets constructed on first page load
13 13
 // (all other times it gets resurrected from a wordpress option)
14
-$stages = glob(EE_CORE . 'data_migration_scripts/4_1_0_stages/*');
14
+$stages = glob(EE_CORE.'data_migration_scripts/4_1_0_stages/*');
15 15
 $class_to_filepath = array();
16
-if (! empty($stages)) {
16
+if ( ! empty($stages)) {
17 17
     foreach ($stages as $filepath) {
18 18
         $matches = array();
19 19
         preg_match('~4_1_0_stages/(.*).dmsstage.php~', $filepath, $matches);
20
-        $class_to_filepath[ $matches[1] ] = $filepath;
20
+        $class_to_filepath[$matches[1]] = $filepath;
21 21
     }
22 22
 }
23 23
 // give addons a chance to autoload their stages too
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
     private function _checkin_table_exists()
90 90
     {
91 91
         global $wpdb;
92
-        $results = $wpdb->get_results("SHOW TABLES LIKE '" . $wpdb->prefix . "events_attendee_checkin" . "'");
92
+        $results = $wpdb->get_results("SHOW TABLES LIKE '".$wpdb->prefix."events_attendee_checkin"."'");
93 93
         if ($results) {
94 94
             return true;
95 95
         } else {
@@ -105,11 +105,11 @@  discard block
 block discarded – undo
105 105
         if (version_compare($version_string, '4.0.0.decaf', '<') && version_compare($version_string, '3.1.26', '>=')) {
106 106
 //          echo "$version_string can be migrated fro";
107 107
             return true;
108
-        } elseif (! $version_string) {
108
+        } elseif ( ! $version_string) {
109 109
 //          echo "no version string provided: $version_string";
110 110
             // no version string provided... this must be pre 4.1
111 111
             // because since 4.1 we're
112
-            return false;// changed mind. dont want people thinking they should migrate yet because they cant
112
+            return false; // changed mind. dont want people thinking they should migrate yet because they cant
113 113
         } else {
114 114
 //          echo "$version_string doesnt apply";
115 115
             return false;
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
     public function schema_changes_before_migration()
122 122
     {
123 123
         // relies on 4.1's EEH_Activation::create_table
124
-        require_once(EE_HELPERS . 'EEH_Activation.helper.php');
124
+        require_once(EE_HELPERS.'EEH_Activation.helper.php');
125 125
         $table_name = 'esp_answer';
126 126
         $sql = "ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
127 127
 					REG_ID int(10) unsigned NOT NULL,
@@ -505,12 +505,12 @@  discard block
 block discarded – undo
505 505
     public function insert_default_states()
506 506
     {
507 507
         global $wpdb;
508
-        $state_table = $wpdb->prefix . "esp_state";
508
+        $state_table = $wpdb->prefix."esp_state";
509 509
         if ($this->_get_table_analysis()->tableExists($state_table)) {
510
-            $SQL = "SELECT COUNT('STA_ID') FROM " . $state_table;
510
+            $SQL = "SELECT COUNT('STA_ID') FROM ".$state_table;
511 511
             $states = $wpdb->get_var($SQL);
512
-            if (! $states) {
513
-                $SQL = "INSERT INTO " . $state_table . "
512
+            if ( ! $states) {
513
+                $SQL = "INSERT INTO ".$state_table."
514 514
 				(STA_ID, CNT_ISO, STA_abbrev, STA_name, STA_active) VALUES
515 515
 				(1, 'US', 'AK', 'Alaska', 1),
516 516
 				(2, 'US', 'AL', 'Alabama', 1),
@@ -601,12 +601,12 @@  discard block
 block discarded – undo
601 601
     public function insert_default_countries()
602 602
     {
603 603
         global $wpdb;
604
-        $country_table = $wpdb->prefix . "esp_country";
604
+        $country_table = $wpdb->prefix."esp_country";
605 605
         if ($this->_get_table_analysis()->tableExists($country_table)) {
606
-            $SQL = "SELECT COUNT('CNT_ISO') FROM " . $country_table;
606
+            $SQL = "SELECT COUNT('CNT_ISO') FROM ".$country_table;
607 607
             $countries = $wpdb->get_var($SQL);
608
-            if (! $countries) {
609
-                $SQL = "INSERT INTO " . $country_table . "
608
+            if ( ! $countries) {
609
+                $SQL = "INSERT INTO ".$country_table."
610 610
 				(CNT_ISO, CNT_ISO3, RGN_ID, CNT_name, CNT_cur_code, CNT_cur_single, CNT_cur_plural, CNT_cur_sign, CNT_cur_sign_b4, CNT_cur_dec_plc, CNT_tel_code, CNT_is_EU, CNT_active) VALUES
611 611
 				('AD', 'AND', 0, 'Andorra', 'EUR', 'Euro', 'Euros', '€', 1, 2, '+376', 0, 0),
612 612
 				('AE', 'ARE', 0, 'United Arab Emirates', 'AED', 'Dirham', 'Dirhams', 'د.إ', 1, 2, '+971', 0, 0),
@@ -851,17 +851,17 @@  discard block
 block discarded – undo
851 851
     public function insert_default_price_types()
852 852
     {
853 853
         global $wpdb;
854
-        $price_type_table = $wpdb->prefix . "esp_price_type";
854
+        $price_type_table = $wpdb->prefix."esp_price_type";
855 855
         if ($this->_get_table_analysis()->tableExists($price_type_table)) {
856
-            $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table;
856
+            $SQL = 'SELECT COUNT(PRT_ID) FROM '.$price_type_table;
857 857
             $price_types_exist = $wpdb->get_var($SQL);
858
-            if (! $price_types_exist) {
858
+            if ( ! $price_types_exist) {
859 859
                 $SQL = "INSERT INTO $price_type_table ( PRT_ID, PRT_name, PBT_ID, PRT_is_percent, PRT_order, PRT_deleted ) VALUES
860
-							(1, '" . esc_html__('Base Price', 'event_espresso') . "', 1,  0, 0, 0),
861
-							(2, '" . esc_html__('Percent Discount', 'event_espresso') . "', 2,  1, 20, 0),
862
-							(3, '" . esc_html__('Fixed Discount', 'event_espresso') . "', 2,  0, 30, 0),
863
-							(4, '" . esc_html__('Percent Surcharge', 'event_espresso') . "', 3,  1, 40, 0),
864
-							(5, '" . esc_html__('Fixed Surcharge', 'event_espresso') . "', 3,  0, 50, 0);";
860
+							(1, '".esc_html__('Base Price', 'event_espresso')."', 1,  0, 0, 0),
861
+							(2, '" . esc_html__('Percent Discount', 'event_espresso')."', 2,  1, 20, 0),
862
+							(3, '" . esc_html__('Fixed Discount', 'event_espresso')."', 2,  0, 30, 0),
863
+							(4, '" . esc_html__('Percent Surcharge', 'event_espresso')."', 3,  1, 40, 0),
864
+							(5, '" . esc_html__('Fixed Surcharge', 'event_espresso')."', 3,  0, 50, 0);";
865 865
                 $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_price_types__SQL', $SQL);
866 866
                 $wpdb->query($SQL);
867 867
             }
@@ -883,11 +883,11 @@  discard block
 block discarded – undo
883 883
     public function insert_default_prices()
884 884
     {
885 885
         global $wpdb;
886
-        $price_table = $wpdb->prefix . "esp_price";
886
+        $price_table = $wpdb->prefix."esp_price";
887 887
         if ($this->_get_table_analysis()->tableExists($price_table)) {
888
-            $SQL = 'SELECT COUNT(PRC_ID) FROM ' . $price_table;
888
+            $SQL = 'SELECT COUNT(PRC_ID) FROM '.$price_table;
889 889
             $prices_exist = $wpdb->get_var($SQL);
890
-            if (! $prices_exist) {
890
+            if ( ! $prices_exist) {
891 891
                 $SQL = "INSERT INTO $price_table
892 892
 							(PRC_ID, PRT_ID, PRC_amount, PRC_name, PRC_desc,  PRC_is_default, PRC_overrides, PRC_order, PRC_deleted, PRC_parent ) VALUES
893 893
 							(1, 1, '0.00', 'Admission', '', 1, null, 0, 0, 0);";
@@ -909,11 +909,11 @@  discard block
 block discarded – undo
909 909
     public function insert_default_tickets()
910 910
     {
911 911
         global $wpdb;
912
-        $ticket_table = $wpdb->prefix . "esp_ticket";
912
+        $ticket_table = $wpdb->prefix."esp_ticket";
913 913
         if ($this->_get_table_analysis()->tableExists($ticket_table)) {
914
-            $SQL = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table;
914
+            $SQL = 'SELECT COUNT(TKT_ID) FROM '.$ticket_table;
915 915
             $tickets_exist = $wpdb->get_var($SQL);
916
-            if (! $tickets_exist) {
916
+            if ( ! $tickets_exist) {
917 917
                 $SQL = "INSERT INTO $ticket_table
918 918
 					( TKT_ID, TTM_ID, TKT_name, TKT_description, TKT_qty, TKT_sold, TKT_uses, TKT_min, TKT_max, TKT_price, TKT_start_date, TKT_end_date, TKT_taxable, TKT_order, TKT_row, TKT_is_default, TKT_parent, TKT_deleted ) VALUES
919 919
 					( 1, 0, '"
@@ -923,11 +923,11 @@  discard block
 block discarded – undo
923 923
                 $wpdb->query($SQL);
924 924
             }
925 925
         }
926
-        $ticket_price_table = $wpdb->prefix . "esp_ticket_price";
926
+        $ticket_price_table = $wpdb->prefix."esp_ticket_price";
927 927
         if ($this->_get_table_analysis()->tableExists($ticket_price_table)) {
928
-            $SQL = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table;
928
+            $SQL = 'SELECT COUNT(TKP_ID) FROM '.$ticket_price_table;
929 929
             $ticket_prc_exist = $wpdb->get_var($SQL);
930
-            if (! $ticket_prc_exist) {
930
+            if ( ! $ticket_prc_exist) {
931 931
                 $SQL = "INSERT INTO $ticket_price_table
932 932
 				( TKP_ID, TKT_ID, PRC_ID ) VALUES
933 933
 				( 1, 1, 1 )
@@ -951,11 +951,11 @@  discard block
 block discarded – undo
951 951
      */
952 952
     public function get_or_create_country($country_name)
953 953
     {
954
-        if (! $country_name) {
954
+        if ( ! $country_name) {
955 955
             throw new EE_Error(esc_html__("Could not get a country because country name is blank", "event_espresso"));
956 956
         }
957 957
         global $wpdb;
958
-        $country_table = $wpdb->prefix . "esp_country";
958
+        $country_table = $wpdb->prefix."esp_country";
959 959
         if (is_int($country_name)) {
960 960
             $country_name = $this->get_iso_from_3_1_country_id($country_name);
961 961
         }
@@ -963,7 +963,7 @@  discard block
 block discarded – undo
963 963
 			CNT_ISO LIKE %s OR
964 964
 			CNT_ISO3 LIKE %s OR
965 965
 			CNT_name LIKE %s LIMIT 1", $country_name, $country_name, $country_name), ARRAY_A);
966
-        if (! $country) {
966
+        if ( ! $country) {
967 967
             // insert a new one then
968 968
             $cols_n_values = array(
969 969
                     'CNT_ISO'         => $this->_find_available_country_iso(2),
@@ -983,28 +983,28 @@  discard block
 block discarded – undo
983 983
                     'CNT_active'      => true,
984 984
             );
985 985
             $data_types = array(
986
-                    '%s',// CNT_ISO
987
-                    '%s',// CNT_ISO3
988
-                    '%d',// RGN_ID
989
-                    '%s',// CNT_name
990
-                    '%s',// CNT_cur_code
991
-                    '%s',// CNT_cur_single
992
-                    '%s',// CNT_cur_plural
993
-                    '%s',// CNT_cur_sign
994
-                    '%d',// CNT_cur_sign_b4
995
-                    '%d',// CNT_cur_dec_plc
996
-                    '%s',// CNT_cur_dec_mrk
997
-                    '%s',// CNT_cur_thsnds
998
-                    '%s',// CNT_tel_code
999
-                    '%d',// CNT_is_EU
1000
-                    '%d',// CNT_active
986
+                    '%s', // CNT_ISO
987
+                    '%s', // CNT_ISO3
988
+                    '%d', // RGN_ID
989
+                    '%s', // CNT_name
990
+                    '%s', // CNT_cur_code
991
+                    '%s', // CNT_cur_single
992
+                    '%s', // CNT_cur_plural
993
+                    '%s', // CNT_cur_sign
994
+                    '%d', // CNT_cur_sign_b4
995
+                    '%d', // CNT_cur_dec_plc
996
+                    '%s', // CNT_cur_dec_mrk
997
+                    '%s', // CNT_cur_thsnds
998
+                    '%s', // CNT_tel_code
999
+                    '%d', // CNT_is_EU
1000
+                    '%d', // CNT_active
1001 1001
             );
1002 1002
             $success = $wpdb->insert(
1003 1003
                 $country_table,
1004 1004
                 $cols_n_values,
1005 1005
                 $data_types
1006 1006
             );
1007
-            if (! $success) {
1007
+            if ( ! $success) {
1008 1008
                 throw new EE_Error($this->_create_error_message_for_db_insertion(
1009 1009
                     'N/A',
1010 1010
                     array('country_id' => $country_name),
@@ -1029,7 +1029,7 @@  discard block
 block discarded – undo
1029 1029
     private function _find_available_country_iso($num_letters = 2)
1030 1030
     {
1031 1031
         global $wpdb;
1032
-        $country_table = $wpdb->prefix . "esp_country";
1032
+        $country_table = $wpdb->prefix."esp_country";
1033 1033
         $attempts = 0;
1034 1034
         do {
1035 1035
             $current_iso = strtoupper(wp_generate_password($num_letters, false));
@@ -1040,7 +1040,7 @@  discard block
 block discarded – undo
1040 1040
             // keep going until we find an available country code, or we arbitrarily
1041 1041
             // decide we've tried this enough. Somehow they have way too many countries
1042 1042
             // (probably because they're mis-using the EE3 country_id like a custom question)
1043
-        } while (intval($country_with_that_iso) && $attempts < 200);
1043
+        }while (intval($country_with_that_iso) && $attempts < 200);
1044 1044
         return $current_iso;
1045 1045
     }
1046 1046
 
@@ -1056,7 +1056,7 @@  discard block
 block discarded – undo
1056 1056
      */
1057 1057
     public function get_or_create_state($state_name, $country_name = '')
1058 1058
     {
1059
-        if (! $state_name) {
1059
+        if ( ! $state_name) {
1060 1060
             throw new EE_Error(esc_html__(
1061 1061
                 "Could not get-or-create state because no state name was provided",
1062 1062
                 "event_espresso"
@@ -1069,12 +1069,12 @@  discard block
 block discarded – undo
1069 1069
             $country_iso = $this->get_default_country_iso();
1070 1070
         }
1071 1071
         global $wpdb;
1072
-        $state_table = $wpdb->prefix . "esp_state";
1072
+        $state_table = $wpdb->prefix."esp_state";
1073 1073
         $state = $wpdb->get_row($wpdb->prepare("SELECT * FROM $state_table WHERE
1074 1074
 			(STA_abbrev LIKE %s OR
1075 1075
 			STA_name LIKE %s) AND
1076 1076
 			CNT_ISO LIKE %s LIMIT 1", $state_name, $state_name, $country_iso), ARRAY_A);
1077
-        if (! $state) {
1077
+        if ( ! $state) {
1078 1078
             // insert a new one then
1079 1079
             $cols_n_values = array(
1080 1080
                     'CNT_ISO'    => $country_iso,
@@ -1083,13 +1083,13 @@  discard block
 block discarded – undo
1083 1083
                     'STA_active' => true,
1084 1084
             );
1085 1085
             $data_types = array(
1086
-                    '%s',// CNT_ISO
1087
-                    '%s',// STA_abbrev
1088
-                    '%s',// STA_name
1089
-                    '%d',// STA_active
1086
+                    '%s', // CNT_ISO
1087
+                    '%s', // STA_abbrev
1088
+                    '%s', // STA_name
1089
+                    '%d', // STA_active
1090 1090
             );
1091 1091
             $success = $wpdb->insert($state_table, $cols_n_values, $data_types);
1092
-            if (! $success) {
1092
+            if ( ! $success) {
1093 1093
                 throw new EE_Error($this->_create_error_message_for_db_insertion(
1094 1094
                     'N/A',
1095 1095
                     array('state' => $state_name, 'country_id' => $country_name),
@@ -1118,7 +1118,7 @@  discard block
 block discarded – undo
1118 1118
     {
1119 1119
         $matches = array();
1120 1120
         preg_match("~(\\d*):(\\d*)~", $timeString, $matches);
1121
-        if (! $matches || count($matches) < 3) {
1121
+        if ( ! $matches || count($matches) < 3) {
1122 1122
             $hour = '00';
1123 1123
             $minutes = '00';
1124 1124
         } else {
@@ -1423,7 +1423,7 @@  discard block
 block discarded – undo
1423 1423
                     'Declined'         => 'RPP',
1424 1424
             );
1425 1425
         }
1426
-        return isset($mapping[ $payment_status ]) ? $mapping[ $payment_status ] : 'RNA';
1426
+        return isset($mapping[$payment_status]) ? $mapping[$payment_status] : 'RNA';
1427 1427
     }
1428 1428
 
1429 1429
 
@@ -1447,7 +1447,7 @@  discard block
 block discarded – undo
1447 1447
         if ($guid) {
1448 1448
             // check for an existing attachment post with this guid
1449 1449
             $attachment_post_id = $this->_get_image_attachment_id_by_GUID($guid);
1450
-            if (! $attachment_post_id) {
1450
+            if ( ! $attachment_post_id) {
1451 1451
                 // post thumbnail with that GUID doesn't exist, we should create one
1452 1452
                 $attachment_post_id = $this->_create_image_attachment_from_GUID($guid, $migration_stage);
1453 1453
                 $created_attachment_post = true;
@@ -1482,7 +1482,7 @@  discard block
 block discarded – undo
1482 1482
         $original_guid = preg_replace('~-\d*x\d*\.~', '.', $guid_in_old_event, 1);
1483 1483
         // do a head request to verify the file exists
1484 1484
         $head_response = wp_remote_head($original_guid);
1485
-        if (! $head_response instanceof WP_Error && $head_response['response']['message'] == 'OK') {
1485
+        if ( ! $head_response instanceof WP_Error && $head_response['response']['message'] == 'OK') {
1486 1486
             return $original_guid;
1487 1487
         } else {
1488 1488
             return $guid_in_old_event;
@@ -1502,7 +1502,7 @@  discard block
 block discarded – undo
1502 1502
      */
1503 1503
     private function _create_image_attachment_from_GUID($guid, EE_Data_Migration_Script_Stage $migration_stage)
1504 1504
     {
1505
-        if (! $guid) {
1505
+        if ( ! $guid) {
1506 1506
             $migration_stage->add_error(sprintf(esc_html__(
1507 1507
                 "Cannot create image attachment for a blank GUID!",
1508 1508
                 "event_espresso"
@@ -1514,7 +1514,7 @@  discard block
 block discarded – undo
1514 1514
         // if the file is located remotely, download it to our uploads DIR, because wp_genereate_attachmnet_metadata needs the file to be local
1515 1515
         if (strpos($guid, $wp_upload_dir['url']) === false) {
1516 1516
             // image is located remotely. download it and place it in the uploads directory
1517
-            if (! is_readable($guid)) {
1517
+            if ( ! is_readable($guid)) {
1518 1518
                 $migration_stage->add_error(sprintf(esc_html__(
1519 1519
                     "Could not create image attachment from non-existent file: %s",
1520 1520
                     "event_espresso"
@@ -1529,7 +1529,7 @@  discard block
 block discarded – undo
1529 1529
                 ), $guid));
1530 1530
                 return false;
1531 1531
             }
1532
-            $local_filepath = $wp_upload_dir['path'] . '/' . basename($guid);
1532
+            $local_filepath = $wp_upload_dir['path'].'/'.basename($guid);
1533 1533
             $savefile = fopen($local_filepath, 'w');
1534 1534
             fwrite($savefile, $contents);
1535 1535
             fclose($savefile);
@@ -1545,7 +1545,7 @@  discard block
 block discarded – undo
1545 1545
                 'post_status'    => 'inherit',
1546 1546
         );
1547 1547
         $attach_id = wp_insert_attachment($attachment, $guid);
1548
-        if (! $attach_id) {
1548
+        if ( ! $attach_id) {
1549 1549
             $migration_stage->add_error(sprintf(esc_html__(
1550 1550
                 "Could not create image attachment post from image '%s'. Attachment data was %s.",
1551 1551
                 "event_espresso"
@@ -1554,9 +1554,9 @@  discard block
 block discarded – undo
1554 1554
         }
1555 1555
         // you must first include the image.php file
1556 1556
         // for the function wp_generate_attachment_metadata() to work
1557
-        require_once(ABSPATH . 'wp-admin/includes/image.php');
1557
+        require_once(ABSPATH.'wp-admin/includes/image.php');
1558 1558
         $attach_data = wp_generate_attachment_metadata($attach_id, $local_filepath);
1559
-        if (! $attach_data) {
1559
+        if ( ! $attach_data) {
1560 1560
             $migration_stage->add_error(sprintf(esc_html__(
1561 1561
                 "Coudl not genereate attachment metadata for attachment post %d with filepath %s and GUID %s. Please check the file was downloaded properly.",
1562 1562
                 "event_espresso"
@@ -1564,7 +1564,7 @@  discard block
 block discarded – undo
1564 1564
             return $attach_id;
1565 1565
         }
1566 1566
         $metadata_save_result = wp_update_attachment_metadata($attach_id, $attach_data);
1567
-        if (! $metadata_save_result) {
1567
+        if ( ! $metadata_save_result) {
1568 1568
             $migration_stage->add_error(sprintf(esc_html__(
1569 1569
                 "Could not update attachment metadata for attachment %d with data %s",
1570 1570
                 "event_espresso"
@@ -1610,10 +1610,10 @@  discard block
 block discarded – undo
1610 1610
         $timezone = null
1611 1611
     ) {
1612 1612
         $original_tz = $timezone;
1613
-        if (! $timezone) {
1613
+        if ( ! $timezone) {
1614 1614
             $timezone = $this->_get_wp_timezone();
1615 1615
         }
1616
-        if (! $timezone) {
1616
+        if ( ! $timezone) {
1617 1617
             $stage->add_error(sprintf(
1618 1618
                 esc_html__("Could not find timezone given %s for %s", "event_espresso"),
1619 1619
                 $original_tz,
@@ -1746,7 +1746,7 @@  discard block
 block discarded – undo
1746 1746
         );
1747 1747
         add_filter(
1748 1748
             'FHEE__ee_migration_page__migration_options_template',
1749
-            array($this,'use_migration_options_from_ee3_template')
1749
+            array($this, 'use_migration_options_from_ee3_template')
1750 1750
         );
1751 1751
     }
1752 1752
 
@@ -1812,6 +1812,6 @@  discard block
 block discarded – undo
1812 1812
      */
1813 1813
     public function use_migration_options_from_ee3_template($template_filepath)
1814 1814
     {
1815
-        return EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee3.template.php';
1815
+        return EE_MAINTENANCE_TEMPLATE_PATH.'migration_options_from_ee3.template.php';
1816 1816
     }
1817 1817
 }
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.6.2');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.6.2');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.10.33.rc.000');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.10.33.rc.000');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
141 141
\ No newline at end of file
Please login to merge, or discard this patch.
form_sections/strategies/layout/EE_Div_Per_Section_Layout.strategy.php 1 patch
Indentation   +162 added lines, -162 removed lines patch added patch discarded remove patch
@@ -12,166 +12,166 @@
 block discarded – undo
12 12
 class EE_Div_Per_Section_Layout extends EE_Form_Section_Layout_Base
13 13
 {
14 14
 
15
-    /**
16
-     * opening div tag for a form
17
-     *
18
-     * @return string
19
-     */
20
-    public function layout_form_begin()
21
-    {
22
-        return EEH_HTML::div(
23
-            '',
24
-            $this->_form_section->html_id(),
25
-            $this->_form_section->html_class(),
26
-            $this->_form_section->html_style()
27
-        );
28
-    }
29
-
30
-
31
-
32
-    /**
33
-     * Lays out the row for the input, including label and errors
34
-     *
35
-     * @param EE_Form_Input_Base $input
36
-     * @return string
37
-     * @throws \EE_Error
38
-     */
39
-    public function layout_input($input)
40
-    {
41
-        $html = '';
42
-        // set something unique for the id
43
-        $html_id = (string) $input->html_id() !== ''
44
-            ? (string) $input->html_id()
45
-            : spl_object_hash($input);
46
-        // and add a generic input type class
47
-        $html_class = $this->processHtmlClasses(
48
-            sanitize_key(str_replace('_', '-', get_class($input))),
49
-            '-dv'
50
-        );
51
-        if ($input instanceof EE_Hidden_Input) {
52
-            $html .= EEH_HTML::nl() . $input->get_html_for_input();
53
-        } elseif ($input instanceof EE_Submit_Input) {
54
-            $input_class = $this->processHtmlClasses($input->html_class(), '-submit-dv');
55
-            $html .= EEH_HTML::div(
56
-                $input->get_html_for_input(),
57
-                $html_id . '-submit-dv',
58
-                "$input_class $html_class"
59
-            );
60
-        } elseif ($input instanceof EE_Select_Input) {
61
-            $input_class = $this->processHtmlClasses($input->html_class(), '-input-dv');
62
-            $html .= EEH_HTML::div(
63
-                EEH_HTML::nl(1) . $input->get_html_for_label() .
64
-                EEH_HTML::nl() . $input->get_html_for_errors() .
65
-                EEH_HTML::nl() . $input->get_html_for_input() .
66
-                EEH_HTML::nl() . $input->get_html_for_help(),
67
-                $html_id . '-input-dv',
68
-                "$input_class $html_class"
69
-            );
70
-        } elseif ($input instanceof EE_Form_Input_With_Options_Base) {
71
-            $input_class = $this->processHtmlClasses($input->html_class(), '-input-dv');
72
-            $html .= EEH_HTML::div(
73
-                EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) .
74
-                EEH_HTML::nl() . $input->get_html_for_errors() .
75
-                EEH_HTML::nl() . $input->get_html_for_input() .
76
-                EEH_HTML::nl() . $input->get_html_for_help(),
77
-                $html_id . '-input-dv',
78
-                "$input_class $html_class"
79
-            );
80
-        } else {
81
-            $input_class = $this->processHtmlClasses($input->html_class(), '-input-dv');
82
-            $html .= EEH_HTML::div(
83
-                EEH_HTML::nl(1) . $input->get_html_for_label() .
84
-                EEH_HTML::nl() . $input->get_html_for_errors() .
85
-                EEH_HTML::nl() . $input->get_html_for_input() .
86
-                EEH_HTML::nl() . $input->get_html_for_help(),
87
-                $html_id . '-input-dv',
88
-                "$input_class $html_class"
89
-            );
90
-        }
91
-        return $html;
92
-    }
93
-
94
-
95
-    /**
96
-     * appends one or more css classes in a string with the provided suffix
97
-     *
98
-     * @param array|string $classes
99
-     * @param string $suffix
100
-     * @return string
101
-     * @since 4.10.31.p
102
-     */
103
-    private function processHtmlClasses($classes, string $suffix): string
104
-    {
105
-        $html_classes = [];
106
-        $classes = is_string($classes) ? explode(' ', $classes) : $classes;
107
-        $classes = (array) $classes;
108
-        foreach ($classes as $class) {
109
-            // don't append suffix if class already has "-js" suffix
110
-            $html_classes[] = strpos($class, '-js') !== strlen($class) - 3
111
-                ? "$class$suffix"
112
-                : $class;
113
-        }
114
-        return implode(' ', $html_classes);
115
-    }
116
-
117
-
118
-
119
-    /**
120
-     *
121
-     * _display_label_for_option_type_question
122
-     * Gets the HTML for the 'label', which is just text for this (because labels
123
-     * should be for each input)
124
-     *
125
-     * @param EE_Form_Input_With_Options_Base $input
126
-     * @return string
127
-     */
128
-    protected function _display_label_for_option_type_question(EE_Form_Input_With_Options_Base $input)
129
-    {
130
-        if ($input->display_html_label_text()) {
131
-            $html_label_text = $input->html_label_text();
132
-            $label_html = EEH_HTML::div(
133
-                $input->required()
134
-                    ? $html_label_text . EEH_HTML::span('*', '', 'ee-asterisk')
135
-                    : $html_label_text,
136
-                $input->html_label_id(),
137
-                $input->required()
138
-                    ? 'ee-required-label ' . $input->html_label_class()
139
-                    : $input->html_label_class(),
140
-                $input->html_label_style(),
141
-                $input->other_html_attributes()
142
-            );
143
-            // if no content was provided to EEH_HTML::div() above (ie: an empty label),
144
-            // then we need to close the div manually
145
-            if (empty($html_label_text)) {
146
-                $label_html .= EEH_HTML::divx($input->html_label_id(), $input->html_label_class());
147
-            }
148
-            return $label_html;
149
-        }
150
-        return '';
151
-    }
152
-
153
-
154
-
155
-    /**
156
-     * Lays out a row for the subsection
157
-     *
158
-     * @param EE_Form_Section_Proper $form_section
159
-     * @return string
160
-     */
161
-    public function layout_subsection($form_section)
162
-    {
163
-        return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1);
164
-    }
165
-
166
-
167
-
168
-    /**
169
-     * closing div tag for a form
170
-     *
171
-     * @return string
172
-     */
173
-    public function layout_form_end()
174
-    {
175
-        return EEH_HTML::divx($this->_form_section->html_id(), $this->_form_section->html_class());
176
-    }
15
+	/**
16
+	 * opening div tag for a form
17
+	 *
18
+	 * @return string
19
+	 */
20
+	public function layout_form_begin()
21
+	{
22
+		return EEH_HTML::div(
23
+			'',
24
+			$this->_form_section->html_id(),
25
+			$this->_form_section->html_class(),
26
+			$this->_form_section->html_style()
27
+		);
28
+	}
29
+
30
+
31
+
32
+	/**
33
+	 * Lays out the row for the input, including label and errors
34
+	 *
35
+	 * @param EE_Form_Input_Base $input
36
+	 * @return string
37
+	 * @throws \EE_Error
38
+	 */
39
+	public function layout_input($input)
40
+	{
41
+		$html = '';
42
+		// set something unique for the id
43
+		$html_id = (string) $input->html_id() !== ''
44
+			? (string) $input->html_id()
45
+			: spl_object_hash($input);
46
+		// and add a generic input type class
47
+		$html_class = $this->processHtmlClasses(
48
+			sanitize_key(str_replace('_', '-', get_class($input))),
49
+			'-dv'
50
+		);
51
+		if ($input instanceof EE_Hidden_Input) {
52
+			$html .= EEH_HTML::nl() . $input->get_html_for_input();
53
+		} elseif ($input instanceof EE_Submit_Input) {
54
+			$input_class = $this->processHtmlClasses($input->html_class(), '-submit-dv');
55
+			$html .= EEH_HTML::div(
56
+				$input->get_html_for_input(),
57
+				$html_id . '-submit-dv',
58
+				"$input_class $html_class"
59
+			);
60
+		} elseif ($input instanceof EE_Select_Input) {
61
+			$input_class = $this->processHtmlClasses($input->html_class(), '-input-dv');
62
+			$html .= EEH_HTML::div(
63
+				EEH_HTML::nl(1) . $input->get_html_for_label() .
64
+				EEH_HTML::nl() . $input->get_html_for_errors() .
65
+				EEH_HTML::nl() . $input->get_html_for_input() .
66
+				EEH_HTML::nl() . $input->get_html_for_help(),
67
+				$html_id . '-input-dv',
68
+				"$input_class $html_class"
69
+			);
70
+		} elseif ($input instanceof EE_Form_Input_With_Options_Base) {
71
+			$input_class = $this->processHtmlClasses($input->html_class(), '-input-dv');
72
+			$html .= EEH_HTML::div(
73
+				EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) .
74
+				EEH_HTML::nl() . $input->get_html_for_errors() .
75
+				EEH_HTML::nl() . $input->get_html_for_input() .
76
+				EEH_HTML::nl() . $input->get_html_for_help(),
77
+				$html_id . '-input-dv',
78
+				"$input_class $html_class"
79
+			);
80
+		} else {
81
+			$input_class = $this->processHtmlClasses($input->html_class(), '-input-dv');
82
+			$html .= EEH_HTML::div(
83
+				EEH_HTML::nl(1) . $input->get_html_for_label() .
84
+				EEH_HTML::nl() . $input->get_html_for_errors() .
85
+				EEH_HTML::nl() . $input->get_html_for_input() .
86
+				EEH_HTML::nl() . $input->get_html_for_help(),
87
+				$html_id . '-input-dv',
88
+				"$input_class $html_class"
89
+			);
90
+		}
91
+		return $html;
92
+	}
93
+
94
+
95
+	/**
96
+	 * appends one or more css classes in a string with the provided suffix
97
+	 *
98
+	 * @param array|string $classes
99
+	 * @param string $suffix
100
+	 * @return string
101
+	 * @since 4.10.31.p
102
+	 */
103
+	private function processHtmlClasses($classes, string $suffix): string
104
+	{
105
+		$html_classes = [];
106
+		$classes = is_string($classes) ? explode(' ', $classes) : $classes;
107
+		$classes = (array) $classes;
108
+		foreach ($classes as $class) {
109
+			// don't append suffix if class already has "-js" suffix
110
+			$html_classes[] = strpos($class, '-js') !== strlen($class) - 3
111
+				? "$class$suffix"
112
+				: $class;
113
+		}
114
+		return implode(' ', $html_classes);
115
+	}
116
+
117
+
118
+
119
+	/**
120
+	 *
121
+	 * _display_label_for_option_type_question
122
+	 * Gets the HTML for the 'label', which is just text for this (because labels
123
+	 * should be for each input)
124
+	 *
125
+	 * @param EE_Form_Input_With_Options_Base $input
126
+	 * @return string
127
+	 */
128
+	protected function _display_label_for_option_type_question(EE_Form_Input_With_Options_Base $input)
129
+	{
130
+		if ($input->display_html_label_text()) {
131
+			$html_label_text = $input->html_label_text();
132
+			$label_html = EEH_HTML::div(
133
+				$input->required()
134
+					? $html_label_text . EEH_HTML::span('*', '', 'ee-asterisk')
135
+					: $html_label_text,
136
+				$input->html_label_id(),
137
+				$input->required()
138
+					? 'ee-required-label ' . $input->html_label_class()
139
+					: $input->html_label_class(),
140
+				$input->html_label_style(),
141
+				$input->other_html_attributes()
142
+			);
143
+			// if no content was provided to EEH_HTML::div() above (ie: an empty label),
144
+			// then we need to close the div manually
145
+			if (empty($html_label_text)) {
146
+				$label_html .= EEH_HTML::divx($input->html_label_id(), $input->html_label_class());
147
+			}
148
+			return $label_html;
149
+		}
150
+		return '';
151
+	}
152
+
153
+
154
+
155
+	/**
156
+	 * Lays out a row for the subsection
157
+	 *
158
+	 * @param EE_Form_Section_Proper $form_section
159
+	 * @return string
160
+	 */
161
+	public function layout_subsection($form_section)
162
+	{
163
+		return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1);
164
+	}
165
+
166
+
167
+
168
+	/**
169
+	 * closing div tag for a form
170
+	 *
171
+	 * @return string
172
+	 */
173
+	public function layout_form_end()
174
+	{
175
+		return EEH_HTML::divx($this->_form_section->html_id(), $this->_form_section->html_class());
176
+	}
177 177
 }
Please login to merge, or discard this patch.
core/admin/EE_Admin_List_Table.core.php 1 patch
Indentation   +883 added lines, -883 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 use EventEspresso\core\services\request\sanitizers\AllowedTags;
4 4
 
5 5
 if (! class_exists('WP_List_Table')) {
6
-    require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
6
+	require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
7 7
 }
8 8
 
9 9
 
@@ -21,896 +21,896 @@  discard block
 block discarded – undo
21 21
  */
22 22
 abstract class EE_Admin_List_Table extends WP_List_Table
23 23
 {
24
-    const ACTION_COPY    = 'duplicate';
25
-
26
-    const ACTION_DELETE  = 'delete';
27
-
28
-    const ACTION_EDIT    = 'edit';
29
-
30
-    const ACTION_RESTORE = 'restore';
31
-
32
-    const ACTION_TRASH   = 'trash';
33
-
34
-    protected static $actions = [
35
-        self::ACTION_COPY,
36
-        self::ACTION_DELETE,
37
-        self::ACTION_EDIT,
38
-        self::ACTION_RESTORE,
39
-        self::ACTION_TRASH,
40
-    ];
41
-
42
-    /**
43
-     * holds the data that will be processed for the table
44
-     *
45
-     * @var array $_data
46
-     */
47
-    protected $_data;
48
-
49
-
50
-    /**
51
-     * This holds the value of all the data available for the given view (for all pages).
52
-     *
53
-     * @var int $_all_data_count
54
-     */
55
-    protected $_all_data_count;
56
-
57
-
58
-    /**
59
-     * Will contain the count of trashed items for the view label.
60
-     *
61
-     * @var int $_trashed_count
62
-     */
63
-    protected $_trashed_count;
64
-
65
-
66
-    /**
67
-     * This is what will be referenced as the slug for the current screen
68
-     *
69
-     * @var string $_screen
70
-     */
71
-    protected $_screen;
72
-
73
-
74
-    /**
75
-     * this is the EE_Admin_Page object
76
-     *
77
-     * @var EE_Admin_Page $_admin_page
78
-     */
79
-    protected $_admin_page;
80
-
81
-
82
-    /**
83
-     * The current view
84
-     *
85
-     * @var string $_view
86
-     */
87
-    protected $_view;
88
-
89
-
90
-    /**
91
-     * array of possible views for this table
92
-     *
93
-     * @var array $_views
94
-     */
95
-    protected $_views;
96
-
97
-
98
-    /**
99
-     * An array of key => value pairs containing information about the current table
100
-     * array(
101
-     *        'plural' => 'plural label',
102
-     *        'singular' => 'singular label',
103
-     *        'ajax' => false, //whether to use ajax or not
104
-     *        'screen' => null, //string used to reference what screen this is
105
-     *        (WP_List_table converts to screen object)
106
-     * )
107
-     *
108
-     * @var array $_wp_list_args
109
-     */
110
-    protected $_wp_list_args;
111
-
112
-    /**
113
-     * an array of column names
114
-     * array(
115
-     *    'internal-name' => 'Title'
116
-     * )
117
-     *
118
-     * @var array $_columns
119
-     */
120
-    protected $_columns;
121
-
122
-    /**
123
-     * An array of sortable columns
124
-     * array(
125
-     *    'internal-name' => 'orderby' //or
126
-     *    'internal-name' => array( 'orderby', true )
127
-     * )
128
-     *
129
-     * @var array $_sortable_columns
130
-     */
131
-    protected $_sortable_columns;
132
-
133
-    /**
134
-     * callback method used to perform AJAX row reordering
135
-     *
136
-     * @var string $_ajax_sorting_callback
137
-     */
138
-    protected $_ajax_sorting_callback;
139
-
140
-    /**
141
-     * An array of hidden columns (if needed)
142
-     * array('internal-name', 'internal-name')
143
-     *
144
-     * @var array $_hidden_columns
145
-     */
146
-    protected $_hidden_columns;
147
-
148
-    /**
149
-     * holds the per_page value
150
-     *
151
-     * @var int $_per_page
152
-     */
153
-    protected $_per_page;
154
-
155
-    /**
156
-     * holds what page number is currently being viewed
157
-     *
158
-     * @var int $_current_page
159
-     */
160
-    protected $_current_page;
161
-
162
-    /**
163
-     * the reference string for the nonce_action
164
-     *
165
-     * @var string $_nonce_action_ref
166
-     */
167
-    protected $_nonce_action_ref;
168
-
169
-    /**
170
-     * property to hold incoming request data (as set by the admin_page_core)
171
-     *
172
-     * @var array $_req_data
173
-     */
174
-    protected $_req_data;
175
-
176
-
177
-    /**
178
-     * yes / no array for admin form fields
179
-     *
180
-     * @var array $_yes_no
181
-     */
182
-    protected $_yes_no = [];
183
-
184
-    /**
185
-     * Array describing buttons that should appear at the bottom of the page
186
-     * Keys are strings that represent the button's function (specifically a key in _labels['buttons']),
187
-     * and the values are another array with the following keys
188
-     * array(
189
-     *    'route' => 'page_route',
190
-     *    'extra_request' => array('evt_id' => 1 ); //extra request vars that need to be included in the button.
191
-     * )
192
-     *
193
-     * @var array $_bottom_buttons
194
-     */
195
-    protected $_bottom_buttons = [];
196
-
197
-
198
-    /**
199
-     * Used to indicate what should be the primary column for the list table.
200
-     * If not present then falls back to what WP calculates
201
-     * as the primary column.
202
-     *
203
-     * @type string $_primary_column
204
-     */
205
-    protected $_primary_column = '';
206
-
207
-
208
-    /**
209
-     * Used to indicate whether the table has a checkbox column or not.
210
-     *
211
-     * @type bool $_has_checkbox_column
212
-     */
213
-    protected $_has_checkbox_column = false;
214
-
215
-
216
-    /**
217
-     * @param EE_Admin_Page $admin_page we use this for obtaining everything we need in the list table
218
-     */
219
-    public function __construct(EE_Admin_Page $admin_page)
220
-    {
221
-        $this->_admin_page   = $admin_page;
222
-        $this->_req_data     = $this->_admin_page->get_request_data();
223
-        $this->_view         = $this->_admin_page->get_view();
224
-        $this->_views        = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views;
225
-        $this->_current_page = $this->get_pagenum();
226
-        $this->_screen       = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view();
227
-        $this->_yes_no       = [
228
-            esc_html__('No', 'event_espresso'),
229
-            esc_html__('Yes', 'event_espresso')
230
-        ];
231
-
232
-        $this->_per_page = $this->get_items_per_page($this->_screen . '_per_page');
233
-
234
-        $this->_setup_data();
235
-        $this->_add_view_counts();
236
-
237
-        $this->_nonce_action_ref = $this->_view;
238
-
239
-        $this->_set_properties();
240
-
241
-        // set primary column
242
-        add_filter('list_table_primary_column', [$this, 'set_primary_column']);
243
-
244
-        // set parent defaults
245
-        parent::__construct($this->_wp_list_args);
246
-
247
-        $this->prepare_items();
248
-    }
249
-
250
-
251
-    /**
252
-     * _setup_data
253
-     * this method is used to setup the $_data, $_all_data_count, and _per_page properties
254
-     *
255
-     * @return void
256
-     * @uses $this->_admin_page
257
-     */
258
-    abstract protected function _setup_data();
259
-
260
-
261
-    /**
262
-     * set the properties that this class needs to be able to execute wp_list_table properly
263
-     * properties set:
264
-     * _wp_list_args = what the arguments required for the parent _wp_list_table.
265
-     * _columns = set the columns in an array.
266
-     * _sortable_columns = columns that are sortable (array).
267
-     * _hidden_columns = columns that are hidden (array)
268
-     * _default_orderby = the default orderby for sorting.
269
-     *
270
-     * @abstract
271
-     * @access protected
272
-     * @return void
273
-     */
274
-    abstract protected function _set_properties();
275
-
276
-
277
-    /**
278
-     * _get_table_filters
279
-     * We use this to assemble and return any filters that are associated with this table that help further refine what
280
-     * gets shown in the table.
281
-     *
282
-     * @abstract
283
-     * @access protected
284
-     * @return string
285
-     */
286
-    abstract protected function _get_table_filters();
287
-
288
-
289
-    /**
290
-     * this is a method that child class will do to add counts to the views array so when views are displayed the
291
-     * counts of the views is accurate.
292
-     *
293
-     * @abstract
294
-     * @access protected
295
-     * @return void
296
-     */
297
-    abstract protected function _add_view_counts();
298
-
299
-
300
-    /**
301
-     * _get_hidden_fields
302
-     * returns a html string of hidden fields so if any table filters are used the current view will be respected.
303
-     *
304
-     * @return string
305
-     */
306
-    protected function _get_hidden_fields()
307
-    {
308
-        $action = isset($this->_req_data['route']) ? $this->_req_data['route'] : '';
309
-        $action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action;
310
-        // if action is STILL empty, then we set it to default
311
-        $action = empty($action) ? 'default' : $action;
312
-        $field  = '<input type="hidden" name="page" value="' . esc_attr($this->_req_data['page']) . '" />' . "\n";
313
-        $field  .= '<input type="hidden" name="route" value="' . esc_attr($action) . '" />' . "\n";
314
-        $field  .= '<input type="hidden" name="perpage" value="' . esc_attr($this->_per_page) . '" />' . "\n";
315
-
316
-        $bulk_actions = $this->_get_bulk_actions();
317
-        foreach ($bulk_actions as $bulk_action => $label) {
318
-            $field .= '<input type="hidden" name="' . $bulk_action . '_nonce"'
319
-                      . ' value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n";
320
-        }
321
-
322
-        return $field;
323
-    }
324
-
325
-
326
-    /**
327
-     * _set_column_info
328
-     * we're using this to set the column headers property.
329
-     *
330
-     * @access protected
331
-     * @return void
332
-     */
333
-    protected function _set_column_info()
334
-    {
335
-        $columns   = $this->get_columns();
336
-        $hidden    = $this->get_hidden_columns();
337
-        $_sortable = $this->get_sortable_columns();
338
-
339
-        /**
340
-         * Dynamic hook allowing for adding sortable columns in this list table.
341
-         * Note that $this->screen->id is in the format
342
-         * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
343
-         * table it is: event-espresso_page_espresso_messages.
344
-         * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
345
-         * hook prefix ("event-espresso") will be different.
346
-         *
347
-         * @var array
348
-         */
349
-        $_sortable = apply_filters("FHEE_manage_{$this->screen->id}_sortable_columns", $_sortable, $this->_screen);
350
-
351
-        $sortable = [];
352
-        foreach ($_sortable as $id => $data) {
353
-            if (empty($data)) {
354
-                continue;
355
-            }
356
-            // fix for offset errors with WP_List_Table default get_columninfo()
357
-            if (is_array($data)) {
358
-                $_data[0] = key($data);
359
-                $_data[1] = isset($data[1]) ? $data[1] : false;
360
-            } else {
361
-                $_data[0] = $data;
362
-            }
363
-
364
-            $data = (array) $data;
365
-
366
-            if (! isset($data[1])) {
367
-                $_data[1] = false;
368
-            }
369
-
370
-            $sortable[ $id ] = $_data;
371
-        }
372
-        $primary               = $this->get_primary_column_name();
373
-        $this->_column_headers = [$columns, $hidden, $sortable, $primary];
374
-    }
375
-
376
-
377
-    /**
378
-     * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814)
379
-     *
380
-     * @return string
381
-     */
382
-    protected function get_primary_column_name()
383
-    {
384
-        foreach (class_parents($this) as $parent) {
385
-            if ($parent === 'WP_List_Table' && method_exists($parent, 'get_primary_column_name')) {
386
-                return parent::get_primary_column_name();
387
-            }
388
-        }
389
-        return $this->_primary_column;
390
-    }
391
-
392
-
393
-    /**
394
-     * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814)
395
-     *
396
-     * @param EE_Base_Class $item
397
-     * @param string        $column_name
398
-     * @param string        $primary
399
-     * @return string
400
-     */
401
-    protected function handle_row_actions($item, $column_name, $primary)
402
-    {
403
-        foreach (class_parents($this) as $parent) {
404
-            if ($parent === 'WP_List_Table' && method_exists($parent, 'handle_row_actions')) {
405
-                return parent::handle_row_actions($item, $column_name, $primary);
406
-            }
407
-        }
408
-        return '';
409
-    }
410
-
411
-
412
-    /**
413
-     * _get_bulk_actions
414
-     * This is a wrapper called by WP_List_Table::get_bulk_actions()
415
-     *
416
-     * @access protected
417
-     * @return array bulk_actions
418
-     */
419
-    protected function _get_bulk_actions()
420
-    {
421
-        $actions = [];
422
-        // the _views property should have the bulk_actions, so let's go through and extract them into a properly
423
-        // formatted array for the wp_list_table();
424
-        foreach ($this->_views as $view => $args) {
425
-            if ($this->_view === $view && isset($args['bulk_action']) && is_array($args['bulk_action'])) {
426
-                // each bulk action will correspond with a admin page route, so we can check whatever the capability is
427
-                // for that page route and skip adding the bulk action if no access for the current logged in user.
428
-                foreach ($args['bulk_action'] as $route => $label) {
429
-                    if ($this->_admin_page->check_user_access($route, true)) {
430
-                        $actions[ $route ] = $label;
431
-                    }
432
-                }
433
-            }
434
-        }
435
-        return $actions;
436
-    }
437
-
438
-
439
-    /**
440
-     * Generate the table navigation above or below the table.
441
-     * Overrides the parent table nav in WP_List_Table so we can hide the bulk action div if there are no bulk actions.
442
-     *
443
-     * @throws EE_Error
444
-     * @since 4.9.44.rc.001
445
-     */
446
-    public function display_tablenav($which)
447
-    {
448
-        if ('top' === $which) {
449
-            wp_nonce_field('bulk-' . $this->_args['plural']);
450
-        }
451
-        ?>
24
+	const ACTION_COPY    = 'duplicate';
25
+
26
+	const ACTION_DELETE  = 'delete';
27
+
28
+	const ACTION_EDIT    = 'edit';
29
+
30
+	const ACTION_RESTORE = 'restore';
31
+
32
+	const ACTION_TRASH   = 'trash';
33
+
34
+	protected static $actions = [
35
+		self::ACTION_COPY,
36
+		self::ACTION_DELETE,
37
+		self::ACTION_EDIT,
38
+		self::ACTION_RESTORE,
39
+		self::ACTION_TRASH,
40
+	];
41
+
42
+	/**
43
+	 * holds the data that will be processed for the table
44
+	 *
45
+	 * @var array $_data
46
+	 */
47
+	protected $_data;
48
+
49
+
50
+	/**
51
+	 * This holds the value of all the data available for the given view (for all pages).
52
+	 *
53
+	 * @var int $_all_data_count
54
+	 */
55
+	protected $_all_data_count;
56
+
57
+
58
+	/**
59
+	 * Will contain the count of trashed items for the view label.
60
+	 *
61
+	 * @var int $_trashed_count
62
+	 */
63
+	protected $_trashed_count;
64
+
65
+
66
+	/**
67
+	 * This is what will be referenced as the slug for the current screen
68
+	 *
69
+	 * @var string $_screen
70
+	 */
71
+	protected $_screen;
72
+
73
+
74
+	/**
75
+	 * this is the EE_Admin_Page object
76
+	 *
77
+	 * @var EE_Admin_Page $_admin_page
78
+	 */
79
+	protected $_admin_page;
80
+
81
+
82
+	/**
83
+	 * The current view
84
+	 *
85
+	 * @var string $_view
86
+	 */
87
+	protected $_view;
88
+
89
+
90
+	/**
91
+	 * array of possible views for this table
92
+	 *
93
+	 * @var array $_views
94
+	 */
95
+	protected $_views;
96
+
97
+
98
+	/**
99
+	 * An array of key => value pairs containing information about the current table
100
+	 * array(
101
+	 *        'plural' => 'plural label',
102
+	 *        'singular' => 'singular label',
103
+	 *        'ajax' => false, //whether to use ajax or not
104
+	 *        'screen' => null, //string used to reference what screen this is
105
+	 *        (WP_List_table converts to screen object)
106
+	 * )
107
+	 *
108
+	 * @var array $_wp_list_args
109
+	 */
110
+	protected $_wp_list_args;
111
+
112
+	/**
113
+	 * an array of column names
114
+	 * array(
115
+	 *    'internal-name' => 'Title'
116
+	 * )
117
+	 *
118
+	 * @var array $_columns
119
+	 */
120
+	protected $_columns;
121
+
122
+	/**
123
+	 * An array of sortable columns
124
+	 * array(
125
+	 *    'internal-name' => 'orderby' //or
126
+	 *    'internal-name' => array( 'orderby', true )
127
+	 * )
128
+	 *
129
+	 * @var array $_sortable_columns
130
+	 */
131
+	protected $_sortable_columns;
132
+
133
+	/**
134
+	 * callback method used to perform AJAX row reordering
135
+	 *
136
+	 * @var string $_ajax_sorting_callback
137
+	 */
138
+	protected $_ajax_sorting_callback;
139
+
140
+	/**
141
+	 * An array of hidden columns (if needed)
142
+	 * array('internal-name', 'internal-name')
143
+	 *
144
+	 * @var array $_hidden_columns
145
+	 */
146
+	protected $_hidden_columns;
147
+
148
+	/**
149
+	 * holds the per_page value
150
+	 *
151
+	 * @var int $_per_page
152
+	 */
153
+	protected $_per_page;
154
+
155
+	/**
156
+	 * holds what page number is currently being viewed
157
+	 *
158
+	 * @var int $_current_page
159
+	 */
160
+	protected $_current_page;
161
+
162
+	/**
163
+	 * the reference string for the nonce_action
164
+	 *
165
+	 * @var string $_nonce_action_ref
166
+	 */
167
+	protected $_nonce_action_ref;
168
+
169
+	/**
170
+	 * property to hold incoming request data (as set by the admin_page_core)
171
+	 *
172
+	 * @var array $_req_data
173
+	 */
174
+	protected $_req_data;
175
+
176
+
177
+	/**
178
+	 * yes / no array for admin form fields
179
+	 *
180
+	 * @var array $_yes_no
181
+	 */
182
+	protected $_yes_no = [];
183
+
184
+	/**
185
+	 * Array describing buttons that should appear at the bottom of the page
186
+	 * Keys are strings that represent the button's function (specifically a key in _labels['buttons']),
187
+	 * and the values are another array with the following keys
188
+	 * array(
189
+	 *    'route' => 'page_route',
190
+	 *    'extra_request' => array('evt_id' => 1 ); //extra request vars that need to be included in the button.
191
+	 * )
192
+	 *
193
+	 * @var array $_bottom_buttons
194
+	 */
195
+	protected $_bottom_buttons = [];
196
+
197
+
198
+	/**
199
+	 * Used to indicate what should be the primary column for the list table.
200
+	 * If not present then falls back to what WP calculates
201
+	 * as the primary column.
202
+	 *
203
+	 * @type string $_primary_column
204
+	 */
205
+	protected $_primary_column = '';
206
+
207
+
208
+	/**
209
+	 * Used to indicate whether the table has a checkbox column or not.
210
+	 *
211
+	 * @type bool $_has_checkbox_column
212
+	 */
213
+	protected $_has_checkbox_column = false;
214
+
215
+
216
+	/**
217
+	 * @param EE_Admin_Page $admin_page we use this for obtaining everything we need in the list table
218
+	 */
219
+	public function __construct(EE_Admin_Page $admin_page)
220
+	{
221
+		$this->_admin_page   = $admin_page;
222
+		$this->_req_data     = $this->_admin_page->get_request_data();
223
+		$this->_view         = $this->_admin_page->get_view();
224
+		$this->_views        = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views;
225
+		$this->_current_page = $this->get_pagenum();
226
+		$this->_screen       = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view();
227
+		$this->_yes_no       = [
228
+			esc_html__('No', 'event_espresso'),
229
+			esc_html__('Yes', 'event_espresso')
230
+		];
231
+
232
+		$this->_per_page = $this->get_items_per_page($this->_screen . '_per_page');
233
+
234
+		$this->_setup_data();
235
+		$this->_add_view_counts();
236
+
237
+		$this->_nonce_action_ref = $this->_view;
238
+
239
+		$this->_set_properties();
240
+
241
+		// set primary column
242
+		add_filter('list_table_primary_column', [$this, 'set_primary_column']);
243
+
244
+		// set parent defaults
245
+		parent::__construct($this->_wp_list_args);
246
+
247
+		$this->prepare_items();
248
+	}
249
+
250
+
251
+	/**
252
+	 * _setup_data
253
+	 * this method is used to setup the $_data, $_all_data_count, and _per_page properties
254
+	 *
255
+	 * @return void
256
+	 * @uses $this->_admin_page
257
+	 */
258
+	abstract protected function _setup_data();
259
+
260
+
261
+	/**
262
+	 * set the properties that this class needs to be able to execute wp_list_table properly
263
+	 * properties set:
264
+	 * _wp_list_args = what the arguments required for the parent _wp_list_table.
265
+	 * _columns = set the columns in an array.
266
+	 * _sortable_columns = columns that are sortable (array).
267
+	 * _hidden_columns = columns that are hidden (array)
268
+	 * _default_orderby = the default orderby for sorting.
269
+	 *
270
+	 * @abstract
271
+	 * @access protected
272
+	 * @return void
273
+	 */
274
+	abstract protected function _set_properties();
275
+
276
+
277
+	/**
278
+	 * _get_table_filters
279
+	 * We use this to assemble and return any filters that are associated with this table that help further refine what
280
+	 * gets shown in the table.
281
+	 *
282
+	 * @abstract
283
+	 * @access protected
284
+	 * @return string
285
+	 */
286
+	abstract protected function _get_table_filters();
287
+
288
+
289
+	/**
290
+	 * this is a method that child class will do to add counts to the views array so when views are displayed the
291
+	 * counts of the views is accurate.
292
+	 *
293
+	 * @abstract
294
+	 * @access protected
295
+	 * @return void
296
+	 */
297
+	abstract protected function _add_view_counts();
298
+
299
+
300
+	/**
301
+	 * _get_hidden_fields
302
+	 * returns a html string of hidden fields so if any table filters are used the current view will be respected.
303
+	 *
304
+	 * @return string
305
+	 */
306
+	protected function _get_hidden_fields()
307
+	{
308
+		$action = isset($this->_req_data['route']) ? $this->_req_data['route'] : '';
309
+		$action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action;
310
+		// if action is STILL empty, then we set it to default
311
+		$action = empty($action) ? 'default' : $action;
312
+		$field  = '<input type="hidden" name="page" value="' . esc_attr($this->_req_data['page']) . '" />' . "\n";
313
+		$field  .= '<input type="hidden" name="route" value="' . esc_attr($action) . '" />' . "\n";
314
+		$field  .= '<input type="hidden" name="perpage" value="' . esc_attr($this->_per_page) . '" />' . "\n";
315
+
316
+		$bulk_actions = $this->_get_bulk_actions();
317
+		foreach ($bulk_actions as $bulk_action => $label) {
318
+			$field .= '<input type="hidden" name="' . $bulk_action . '_nonce"'
319
+					  . ' value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n";
320
+		}
321
+
322
+		return $field;
323
+	}
324
+
325
+
326
+	/**
327
+	 * _set_column_info
328
+	 * we're using this to set the column headers property.
329
+	 *
330
+	 * @access protected
331
+	 * @return void
332
+	 */
333
+	protected function _set_column_info()
334
+	{
335
+		$columns   = $this->get_columns();
336
+		$hidden    = $this->get_hidden_columns();
337
+		$_sortable = $this->get_sortable_columns();
338
+
339
+		/**
340
+		 * Dynamic hook allowing for adding sortable columns in this list table.
341
+		 * Note that $this->screen->id is in the format
342
+		 * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
343
+		 * table it is: event-espresso_page_espresso_messages.
344
+		 * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
345
+		 * hook prefix ("event-espresso") will be different.
346
+		 *
347
+		 * @var array
348
+		 */
349
+		$_sortable = apply_filters("FHEE_manage_{$this->screen->id}_sortable_columns", $_sortable, $this->_screen);
350
+
351
+		$sortable = [];
352
+		foreach ($_sortable as $id => $data) {
353
+			if (empty($data)) {
354
+				continue;
355
+			}
356
+			// fix for offset errors with WP_List_Table default get_columninfo()
357
+			if (is_array($data)) {
358
+				$_data[0] = key($data);
359
+				$_data[1] = isset($data[1]) ? $data[1] : false;
360
+			} else {
361
+				$_data[0] = $data;
362
+			}
363
+
364
+			$data = (array) $data;
365
+
366
+			if (! isset($data[1])) {
367
+				$_data[1] = false;
368
+			}
369
+
370
+			$sortable[ $id ] = $_data;
371
+		}
372
+		$primary               = $this->get_primary_column_name();
373
+		$this->_column_headers = [$columns, $hidden, $sortable, $primary];
374
+	}
375
+
376
+
377
+	/**
378
+	 * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814)
379
+	 *
380
+	 * @return string
381
+	 */
382
+	protected function get_primary_column_name()
383
+	{
384
+		foreach (class_parents($this) as $parent) {
385
+			if ($parent === 'WP_List_Table' && method_exists($parent, 'get_primary_column_name')) {
386
+				return parent::get_primary_column_name();
387
+			}
388
+		}
389
+		return $this->_primary_column;
390
+	}
391
+
392
+
393
+	/**
394
+	 * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814)
395
+	 *
396
+	 * @param EE_Base_Class $item
397
+	 * @param string        $column_name
398
+	 * @param string        $primary
399
+	 * @return string
400
+	 */
401
+	protected function handle_row_actions($item, $column_name, $primary)
402
+	{
403
+		foreach (class_parents($this) as $parent) {
404
+			if ($parent === 'WP_List_Table' && method_exists($parent, 'handle_row_actions')) {
405
+				return parent::handle_row_actions($item, $column_name, $primary);
406
+			}
407
+		}
408
+		return '';
409
+	}
410
+
411
+
412
+	/**
413
+	 * _get_bulk_actions
414
+	 * This is a wrapper called by WP_List_Table::get_bulk_actions()
415
+	 *
416
+	 * @access protected
417
+	 * @return array bulk_actions
418
+	 */
419
+	protected function _get_bulk_actions()
420
+	{
421
+		$actions = [];
422
+		// the _views property should have the bulk_actions, so let's go through and extract them into a properly
423
+		// formatted array for the wp_list_table();
424
+		foreach ($this->_views as $view => $args) {
425
+			if ($this->_view === $view && isset($args['bulk_action']) && is_array($args['bulk_action'])) {
426
+				// each bulk action will correspond with a admin page route, so we can check whatever the capability is
427
+				// for that page route and skip adding the bulk action if no access for the current logged in user.
428
+				foreach ($args['bulk_action'] as $route => $label) {
429
+					if ($this->_admin_page->check_user_access($route, true)) {
430
+						$actions[ $route ] = $label;
431
+					}
432
+				}
433
+			}
434
+		}
435
+		return $actions;
436
+	}
437
+
438
+
439
+	/**
440
+	 * Generate the table navigation above or below the table.
441
+	 * Overrides the parent table nav in WP_List_Table so we can hide the bulk action div if there are no bulk actions.
442
+	 *
443
+	 * @throws EE_Error
444
+	 * @since 4.9.44.rc.001
445
+	 */
446
+	public function display_tablenav($which)
447
+	{
448
+		if ('top' === $which) {
449
+			wp_nonce_field('bulk-' . $this->_args['plural']);
450
+		}
451
+		?>
452 452
         <div class="tablenav <?php echo esc_attr($which); ?>">
453 453
             <?php if ($this->_get_bulk_actions()) { ?>
454 454
                 <div class="alignleft actions bulkactions">
455 455
                     <?php $this->bulk_actions(); ?>
456 456
                 </div>
457 457
             <?php }
458
-            $this->extra_tablenav($which);
459
-            $this->pagination($which);
460
-            ?>
458
+			$this->extra_tablenav($which);
459
+			$this->pagination($which);
460
+			?>
461 461
 
462 462
             <br class="clear" />
463 463
         </div>
464 464
         <?php
465
-    }
466
-
467
-
468
-    /**
469
-     * _filters
470
-     * This receives the filters array from children _get_table_filters() and assembles the string including the filter
471
-     * button.
472
-     *
473
-     * @access private
474
-     * @return void  echos html showing filters
475
-     */
476
-    private function _filters()
477
-    {
478
-        $classname = get_class($this);
479
-        $filters   = apply_filters(
480
-            "FHEE__{$classname}__filters",
481
-            (array) $this->_get_table_filters(),
482
-            $this,
483
-            $this->_screen
484
-        );
485
-
486
-        if (empty($filters)) {
487
-            return;
488
-        }
489
-
490
-        echo '<div class="ee-list-table-filters actions alignleft">';
491
-        foreach ($filters as $filter) {
492
-            echo wp_kses($filter, AllowedTags::getWithFormTags());
493
-        }
494
-        // add filter button at end
495
-        echo '<input type="submit" class="ee-list-table-filter-submit button button--secondary" value="'
496
-             . esc_html__('Filter', 'event_espresso')
497
-             . '" id="post-query-submit" />';
498
-        echo '<input type="hidden" id="ee-list-table-use-filters" name="use_filters" value="no"/>';
499
-
500
-        // add reset filters button at end
501
-        echo '<a class="button button--secondary"  href="'
502
-             . esc_url_raw($this->_admin_page->get_current_page_view_url())
503
-             . '" style="display:inline-block">'
504
-             . esc_html__('Reset Filters', 'event_espresso')
505
-             . '</a>';
506
-        echo '</div>';
507
-    }
508
-
509
-
510
-    /**
511
-     * Callback for 'list_table_primary_column' WordPress filter
512
-     * If child EE_Admin_List_Table classes set the _primary_column property then that will be set as the primary
513
-     * column when class is instantiated.
514
-     *
515
-     * @param string $column_name
516
-     * @return string
517
-     * @see WP_List_Table::get_primary_column_name
518
-     */
519
-    public function set_primary_column($column_name)
520
-    {
521
-        return ! empty($this->_primary_column) ? $this->_primary_column : $column_name;
522
-    }
523
-
524
-
525
-    /**
526
-     *
527
-     */
528
-    public function prepare_items()
529
-    {
530
-
531
-        $this->_set_column_info();
532
-        // $this->_column_headers = $this->get_column_info();
533
-        $total_items = $this->_all_data_count;
534
-        $this->process_bulk_action();
535
-
536
-        $this->items = $this->_data;
537
-        $this->set_pagination_args(
538
-            [
539
-                'total_items' => $total_items,
540
-                'per_page'    => $this->_per_page,
541
-                'total_pages' => ceil($total_items / $this->_per_page),
542
-            ]
543
-        );
544
-    }
545
-
546
-
547
-    /**
548
-     * @param object|array $item
549
-     * @return string html content for the column
550
-     */
551
-    protected function column_cb($item)
552
-    {
553
-        return '';
554
-    }
555
-
556
-
557
-    /**
558
-     * This column is the default for when there is no defined column method for a registered column.
559
-     * This can be overridden by child classes, but allows for hooking in for custom columns.
560
-     *
561
-     * @param EE_Base_Class $item
562
-     * @param string        $column_name The column being called.
563
-     * @return string html content for the column
564
-     */
565
-    public function column_default($item, $column_name)
566
-    {
567
-        /**
568
-         * Dynamic hook allowing for adding additional column content in this list table.
569
-         * Note that $this->screen->id is in the format
570
-         * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
571
-         * table it is: event-espresso_page_espresso_messages.
572
-         * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
573
-         * hook prefix ("event-espresso") will be different.
574
-         */
575
-        ob_start();
576
-        do_action(
577
-            'AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id,
578
-            $item,
579
-            $this->_screen
580
-        );
581
-        return ob_get_clean();
582
-    }
583
-
584
-
585
-    /**
586
-     * Get a list of columns. The format is:
587
-     * 'internal-name' => 'Title'
588
-     *
589
-     * @return array
590
-     * @since  3.1.0
591
-     * @access public
592
-     * @abstract
593
-     */
594
-    public function get_columns()
595
-    {
596
-        /**
597
-         * Dynamic hook allowing for adding additional columns in this list table.
598
-         * Note that $this->screen->id is in the format
599
-         * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
600
-         * table it is: event-espresso_page_espresso_messages.
601
-         * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
602
-         * hook prefix ("event-espresso") will be different.
603
-         *
604
-         * @var array
605
-         */
606
-        return apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen);
607
-    }
608
-
609
-
610
-    /**
611
-     * Get an associative array ( id => link ) with the list
612
-     * of views available on this table.
613
-     *
614
-     * @return array
615
-     * @since  3.1.0
616
-     * @access protected
617
-     */
618
-    public function get_views()
619
-    {
620
-        return $this->_views;
621
-    }
622
-
623
-
624
-    /**
625
-     * Generate the views html.
626
-     */
627
-    public function display_views()
628
-    {
629
-        $views           = $this->get_views();
630
-        $assembled_views = [];
631
-
632
-        if (empty($views)) {
633
-            return;
634
-        }
635
-        echo "<ul class='subsubsub'>\n";
636
-        foreach ($views as $view) {
637
-            $count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0;
638
-            if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) {
639
-                $filter = "<li";
640
-                $filter .= $view['class'] ? " class='" . esc_attr($view['class']) . "'" : '';
641
-                $filter .= ">";
642
-                $filter .= '<a href="' . esc_url_raw($view['url']) . '">' . esc_html($view['label']) . '</a>';
643
-                $filter .= '<span class="count">(' . $count . ')</span>';
644
-                $filter .= '</li>';
645
-                $assembled_views[ $view['slug'] ] = $filter;
646
-            }
647
-        }
648
-
649
-        echo ! empty($assembled_views)
650
-            ? implode("<li style='margin:0 .5rem;'>|</li>", $assembled_views)
651
-            : '';
652
-        echo "</ul>";
653
-    }
654
-
655
-
656
-    /**
657
-     * Generates content for a single row of the table
658
-     *
659
-     * @param EE_Base_Class $item The current item
660
-     * @since  4.1
661
-     * @access public
662
-     */
663
-    public function single_row($item)
664
-    {
665
-        $row_class = $this->_get_row_class($item);
666
-        echo '<tr class="' . esc_attr($row_class) . '">';
667
-        $this->single_row_columns($item); // already escaped
668
-        echo '</tr>';
669
-    }
670
-
671
-
672
-    /**
673
-     * This simply sets up the row class for the table rows.
674
-     * Allows for easier overriding of child methods for setting up sorting.
675
-     *
676
-     * @param EE_Base_Class $item the current item
677
-     * @return string
678
-     */
679
-    protected function _get_row_class($item)
680
-    {
681
-        static $row_class = '';
682
-        $row_class = ($row_class === '' ? 'alternate' : '');
683
-
684
-        $new_row_class = $row_class;
685
-
686
-        if (! empty($this->_ajax_sorting_callback)) {
687
-            $new_row_class .= ' rowsortable';
688
-        }
689
-
690
-        return $new_row_class;
691
-    }
692
-
693
-
694
-    /**
695
-     * @return array
696
-     */
697
-    public function get_sortable_columns()
698
-    {
699
-        return (array) $this->_sortable_columns;
700
-    }
701
-
702
-
703
-    /**
704
-     * @return string
705
-     */
706
-    public function get_ajax_sorting_callback()
707
-    {
708
-        return $this->_ajax_sorting_callback;
709
-    }
710
-
711
-
712
-    /**
713
-     * @return array
714
-     */
715
-    public function get_hidden_columns()
716
-    {
717
-        $user_id     = get_current_user_id();
718
-        $has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id);
719
-        if (empty($has_default) && ! empty($this->_hidden_columns)) {
720
-            update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true);
721
-            update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true);
722
-        }
723
-        $ref = 'manage' . $this->screen->id . 'columnshidden';
724
-        return (array) get_user_option($ref, $user_id);
725
-    }
726
-
727
-
728
-    /**
729
-     * Generates the columns for a single row of the table.
730
-     * Overridden from wp_list_table so as to allow us to filter the column content for a given
731
-     * column.
732
-     *
733
-     * @param EE_Base_Class $item The current item
734
-     * @since 3.1.0
735
-     */
736
-    public function single_row_columns($item)
737
-    {
738
-        [$columns, $hidden, $sortable, $primary] = $this->get_column_info();
739
-
740
-        foreach ($columns as $column_name => $column_display_name) {
741
-
742
-            /**
743
-             * With WordPress version 4.3.RC+ WordPress started using the hidden css class to control whether columns
744
-             * are hidden or not instead of using "display:none;".  This bit of code provides backward compat.
745
-             */
746
-            $hidden_class = in_array($column_name, $hidden) ? ' hidden' : '';
747
-
748
-            $classes = $column_name . ' column-' . $column_name . $hidden_class;
749
-            if ($primary === $column_name) {
750
-                $classes .= ' has-row-actions column-primary';
751
-            }
752
-
753
-            $data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"';
754
-
755
-            $class = 'class="' . esc_attr($classes) . '"';
756
-
757
-            $attributes = "{$class}{$data}";
758
-
759
-            if ($column_name === 'cb') {
760
-                echo '<th scope="row" class="check-column">';
761
-                echo apply_filters(
762
-                    'FHEE__EE_Admin_List_Table__single_row_columns__column_cb_content',
763
-                    $this->column_cb($item), // already escaped
764
-                    $item,
765
-                    $this
766
-                );
767
-                echo '</th>';
768
-            } elseif (method_exists($this, 'column_' . $column_name)) {
769
-                echo "<td $attributes>"; // already escaped
770
-                echo apply_filters(
771
-                    'FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content',
772
-                    call_user_func([$this, 'column_' . $column_name], $item),
773
-                    $item,
774
-                    $this
775
-                );
776
-                echo wp_kses($this->handle_row_actions($item, $column_name, $primary), AllowedTags::getWithFormTags());
777
-                echo "</td>";
778
-            } else {
779
-                echo "<td $attributes>"; // already escaped
780
-                echo apply_filters(
781
-                    'FHEE__EE_Admin_List_Table__single_row_columns__column_default__column_content',
782
-                    $this->column_default($item, $column_name),
783
-                    $item,
784
-                    $column_name,
785
-                    $this
786
-                );
787
-                echo wp_kses($this->handle_row_actions($item, $column_name, $primary), AllowedTags::getWithFormTags());
788
-                echo "</td>";
789
-            }
790
-        }
791
-    }
792
-
793
-
794
-    /**
795
-     * Extra controls to be displayed between bulk actions and pagination
796
-     *
797
-     * @access public
798
-     * @param string $which
799
-     * @throws EE_Error
800
-     */
801
-    public function extra_tablenav($which)
802
-    {
803
-        if ($which === 'top') {
804
-            $this->_filters();
805
-            echo wp_kses($this->_get_hidden_fields(), AllowedTags::getWithFormTags());
806
-        } else {
807
-            echo '<div class="list-table-bottom-buttons alignleft actions">';
808
-            foreach ($this->_bottom_buttons as $type => $action) {
809
-                $route         = $action['route'] ?? '';
810
-                $extra_request = $action['extra_request'] ?? '';
811
-                // already escaped
812
-                echo wp_kses($this->_admin_page->get_action_link_or_button(
813
-                    $route,
814
-                    $type,
815
-                    $extra_request,
816
-                    'button button--secondary'
817
-                ), AllowedTags::getWithFormTags());
818
-            }
819
-            do_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', $this, $this->_screen);
820
-            echo '</div>';
821
-        }
822
-    }
823
-
824
-
825
-    /**
826
-     * Get an associative array ( option_name => option_title ) with the list
827
-     * of bulk actions available on this table.
828
-     *
829
-     * @return array
830
-     * @since  3.1.0
831
-     * @access protected
832
-     */
833
-    public function get_bulk_actions()
834
-    {
835
-        return (array) $this->_get_bulk_actions();
836
-    }
837
-
838
-
839
-    /**
840
-     * Processing bulk actions.
841
-     */
842
-    public function process_bulk_action()
843
-    {
844
-        // this is not used it is handled by the child EE_Admin_Page class (routes).  However, including here for
845
-        // reference in case there is a case where it gets used.
846
-    }
847
-
848
-
849
-    /**
850
-     * returns the EE admin page this list table is associated with
851
-     *
852
-     * @return EE_Admin_Page
853
-     */
854
-    public function get_admin_page()
855
-    {
856
-        return $this->_admin_page;
857
-    }
858
-
859
-
860
-    /**
861
-     * A "helper" function for all children to provide an html string of
862
-     * actions to output in their content.  It is preferable for child classes
863
-     * to use this method for generating their actions content so that it's
864
-     * filterable by plugins
865
-     *
866
-     * @param string        $action_container           what are the html container
867
-     *                                                  elements for this actions string?
868
-     * @param string        $action_class               What class is for the container
869
-     *                                                  element.
870
-     * @param string        $action_items               The contents for the action items
871
-     *                                                  container.  This is filtered before
872
-     *                                                  returned.
873
-     * @param string        $action_id                  What id (optional) is used for the
874
-     *                                                  container element.
875
-     * @param EE_Base_Class $item                       The object for the column displaying
876
-     *                                                  the actions.
877
-     * @return string The assembled action elements container.
878
-     */
879
-    protected function _action_string(
880
-        $action_items,
881
-        $item,
882
-        $action_container = 'ul',
883
-        $action_class = '',
884
-        $action_id = ''
885
-    ) {
886
-        $action_class = ! empty($action_class) ? ' class="' . esc_attr($action_class) . '"' : '';
887
-        $action_id    = ! empty($action_id) ? ' id="' . esc_attr($action_id) . '"' : '';
888
-        $open_tag     = ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : '';
889
-        $close_tag    = ! empty($action_container) ? '</' . $action_container . '>' : '';
890
-        try {
891
-            $content = apply_filters(
892
-                'FHEE__EE_Admin_List_Table___action_string__action_items',
893
-                $action_items,
894
-                $item,
895
-                $this
896
-            );
897
-        } catch (Exception $e) {
898
-            if (WP_DEBUG) {
899
-                EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
900
-            }
901
-            $content = $action_items;
902
-        }
903
-        return "{$open_tag}{$content}{$close_tag}";
904
-    }
905
-
906
-
907
-    /**
908
-     * @return string
909
-     */
910
-    protected function getReturnUrl()
911
-    {
912
-        $host = $this->_admin_page->get_request()->getServerParam('HTTP_HOST');
913
-        $uri  = $this->_admin_page->get_request()->getServerParam('REQUEST_URI');
914
-        return urlencode(esc_url_raw("//{$host}{$uri}"));
915
-    }
465
+	}
466
+
467
+
468
+	/**
469
+	 * _filters
470
+	 * This receives the filters array from children _get_table_filters() and assembles the string including the filter
471
+	 * button.
472
+	 *
473
+	 * @access private
474
+	 * @return void  echos html showing filters
475
+	 */
476
+	private function _filters()
477
+	{
478
+		$classname = get_class($this);
479
+		$filters   = apply_filters(
480
+			"FHEE__{$classname}__filters",
481
+			(array) $this->_get_table_filters(),
482
+			$this,
483
+			$this->_screen
484
+		);
485
+
486
+		if (empty($filters)) {
487
+			return;
488
+		}
489
+
490
+		echo '<div class="ee-list-table-filters actions alignleft">';
491
+		foreach ($filters as $filter) {
492
+			echo wp_kses($filter, AllowedTags::getWithFormTags());
493
+		}
494
+		// add filter button at end
495
+		echo '<input type="submit" class="ee-list-table-filter-submit button button--secondary" value="'
496
+			 . esc_html__('Filter', 'event_espresso')
497
+			 . '" id="post-query-submit" />';
498
+		echo '<input type="hidden" id="ee-list-table-use-filters" name="use_filters" value="no"/>';
499
+
500
+		// add reset filters button at end
501
+		echo '<a class="button button--secondary"  href="'
502
+			 . esc_url_raw($this->_admin_page->get_current_page_view_url())
503
+			 . '" style="display:inline-block">'
504
+			 . esc_html__('Reset Filters', 'event_espresso')
505
+			 . '</a>';
506
+		echo '</div>';
507
+	}
508
+
509
+
510
+	/**
511
+	 * Callback for 'list_table_primary_column' WordPress filter
512
+	 * If child EE_Admin_List_Table classes set the _primary_column property then that will be set as the primary
513
+	 * column when class is instantiated.
514
+	 *
515
+	 * @param string $column_name
516
+	 * @return string
517
+	 * @see WP_List_Table::get_primary_column_name
518
+	 */
519
+	public function set_primary_column($column_name)
520
+	{
521
+		return ! empty($this->_primary_column) ? $this->_primary_column : $column_name;
522
+	}
523
+
524
+
525
+	/**
526
+	 *
527
+	 */
528
+	public function prepare_items()
529
+	{
530
+
531
+		$this->_set_column_info();
532
+		// $this->_column_headers = $this->get_column_info();
533
+		$total_items = $this->_all_data_count;
534
+		$this->process_bulk_action();
535
+
536
+		$this->items = $this->_data;
537
+		$this->set_pagination_args(
538
+			[
539
+				'total_items' => $total_items,
540
+				'per_page'    => $this->_per_page,
541
+				'total_pages' => ceil($total_items / $this->_per_page),
542
+			]
543
+		);
544
+	}
545
+
546
+
547
+	/**
548
+	 * @param object|array $item
549
+	 * @return string html content for the column
550
+	 */
551
+	protected function column_cb($item)
552
+	{
553
+		return '';
554
+	}
555
+
556
+
557
+	/**
558
+	 * This column is the default for when there is no defined column method for a registered column.
559
+	 * This can be overridden by child classes, but allows for hooking in for custom columns.
560
+	 *
561
+	 * @param EE_Base_Class $item
562
+	 * @param string        $column_name The column being called.
563
+	 * @return string html content for the column
564
+	 */
565
+	public function column_default($item, $column_name)
566
+	{
567
+		/**
568
+		 * Dynamic hook allowing for adding additional column content in this list table.
569
+		 * Note that $this->screen->id is in the format
570
+		 * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
571
+		 * table it is: event-espresso_page_espresso_messages.
572
+		 * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
573
+		 * hook prefix ("event-espresso") will be different.
574
+		 */
575
+		ob_start();
576
+		do_action(
577
+			'AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id,
578
+			$item,
579
+			$this->_screen
580
+		);
581
+		return ob_get_clean();
582
+	}
583
+
584
+
585
+	/**
586
+	 * Get a list of columns. The format is:
587
+	 * 'internal-name' => 'Title'
588
+	 *
589
+	 * @return array
590
+	 * @since  3.1.0
591
+	 * @access public
592
+	 * @abstract
593
+	 */
594
+	public function get_columns()
595
+	{
596
+		/**
597
+		 * Dynamic hook allowing for adding additional columns in this list table.
598
+		 * Note that $this->screen->id is in the format
599
+		 * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
600
+		 * table it is: event-espresso_page_espresso_messages.
601
+		 * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
602
+		 * hook prefix ("event-espresso") will be different.
603
+		 *
604
+		 * @var array
605
+		 */
606
+		return apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen);
607
+	}
608
+
609
+
610
+	/**
611
+	 * Get an associative array ( id => link ) with the list
612
+	 * of views available on this table.
613
+	 *
614
+	 * @return array
615
+	 * @since  3.1.0
616
+	 * @access protected
617
+	 */
618
+	public function get_views()
619
+	{
620
+		return $this->_views;
621
+	}
622
+
623
+
624
+	/**
625
+	 * Generate the views html.
626
+	 */
627
+	public function display_views()
628
+	{
629
+		$views           = $this->get_views();
630
+		$assembled_views = [];
631
+
632
+		if (empty($views)) {
633
+			return;
634
+		}
635
+		echo "<ul class='subsubsub'>\n";
636
+		foreach ($views as $view) {
637
+			$count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0;
638
+			if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) {
639
+				$filter = "<li";
640
+				$filter .= $view['class'] ? " class='" . esc_attr($view['class']) . "'" : '';
641
+				$filter .= ">";
642
+				$filter .= '<a href="' . esc_url_raw($view['url']) . '">' . esc_html($view['label']) . '</a>';
643
+				$filter .= '<span class="count">(' . $count . ')</span>';
644
+				$filter .= '</li>';
645
+				$assembled_views[ $view['slug'] ] = $filter;
646
+			}
647
+		}
648
+
649
+		echo ! empty($assembled_views)
650
+			? implode("<li style='margin:0 .5rem;'>|</li>", $assembled_views)
651
+			: '';
652
+		echo "</ul>";
653
+	}
654
+
655
+
656
+	/**
657
+	 * Generates content for a single row of the table
658
+	 *
659
+	 * @param EE_Base_Class $item The current item
660
+	 * @since  4.1
661
+	 * @access public
662
+	 */
663
+	public function single_row($item)
664
+	{
665
+		$row_class = $this->_get_row_class($item);
666
+		echo '<tr class="' . esc_attr($row_class) . '">';
667
+		$this->single_row_columns($item); // already escaped
668
+		echo '</tr>';
669
+	}
670
+
671
+
672
+	/**
673
+	 * This simply sets up the row class for the table rows.
674
+	 * Allows for easier overriding of child methods for setting up sorting.
675
+	 *
676
+	 * @param EE_Base_Class $item the current item
677
+	 * @return string
678
+	 */
679
+	protected function _get_row_class($item)
680
+	{
681
+		static $row_class = '';
682
+		$row_class = ($row_class === '' ? 'alternate' : '');
683
+
684
+		$new_row_class = $row_class;
685
+
686
+		if (! empty($this->_ajax_sorting_callback)) {
687
+			$new_row_class .= ' rowsortable';
688
+		}
689
+
690
+		return $new_row_class;
691
+	}
692
+
693
+
694
+	/**
695
+	 * @return array
696
+	 */
697
+	public function get_sortable_columns()
698
+	{
699
+		return (array) $this->_sortable_columns;
700
+	}
701
+
702
+
703
+	/**
704
+	 * @return string
705
+	 */
706
+	public function get_ajax_sorting_callback()
707
+	{
708
+		return $this->_ajax_sorting_callback;
709
+	}
710
+
711
+
712
+	/**
713
+	 * @return array
714
+	 */
715
+	public function get_hidden_columns()
716
+	{
717
+		$user_id     = get_current_user_id();
718
+		$has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id);
719
+		if (empty($has_default) && ! empty($this->_hidden_columns)) {
720
+			update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true);
721
+			update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true);
722
+		}
723
+		$ref = 'manage' . $this->screen->id . 'columnshidden';
724
+		return (array) get_user_option($ref, $user_id);
725
+	}
726
+
727
+
728
+	/**
729
+	 * Generates the columns for a single row of the table.
730
+	 * Overridden from wp_list_table so as to allow us to filter the column content for a given
731
+	 * column.
732
+	 *
733
+	 * @param EE_Base_Class $item The current item
734
+	 * @since 3.1.0
735
+	 */
736
+	public function single_row_columns($item)
737
+	{
738
+		[$columns, $hidden, $sortable, $primary] = $this->get_column_info();
739
+
740
+		foreach ($columns as $column_name => $column_display_name) {
741
+
742
+			/**
743
+			 * With WordPress version 4.3.RC+ WordPress started using the hidden css class to control whether columns
744
+			 * are hidden or not instead of using "display:none;".  This bit of code provides backward compat.
745
+			 */
746
+			$hidden_class = in_array($column_name, $hidden) ? ' hidden' : '';
747
+
748
+			$classes = $column_name . ' column-' . $column_name . $hidden_class;
749
+			if ($primary === $column_name) {
750
+				$classes .= ' has-row-actions column-primary';
751
+			}
752
+
753
+			$data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"';
754
+
755
+			$class = 'class="' . esc_attr($classes) . '"';
756
+
757
+			$attributes = "{$class}{$data}";
758
+
759
+			if ($column_name === 'cb') {
760
+				echo '<th scope="row" class="check-column">';
761
+				echo apply_filters(
762
+					'FHEE__EE_Admin_List_Table__single_row_columns__column_cb_content',
763
+					$this->column_cb($item), // already escaped
764
+					$item,
765
+					$this
766
+				);
767
+				echo '</th>';
768
+			} elseif (method_exists($this, 'column_' . $column_name)) {
769
+				echo "<td $attributes>"; // already escaped
770
+				echo apply_filters(
771
+					'FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content',
772
+					call_user_func([$this, 'column_' . $column_name], $item),
773
+					$item,
774
+					$this
775
+				);
776
+				echo wp_kses($this->handle_row_actions($item, $column_name, $primary), AllowedTags::getWithFormTags());
777
+				echo "</td>";
778
+			} else {
779
+				echo "<td $attributes>"; // already escaped
780
+				echo apply_filters(
781
+					'FHEE__EE_Admin_List_Table__single_row_columns__column_default__column_content',
782
+					$this->column_default($item, $column_name),
783
+					$item,
784
+					$column_name,
785
+					$this
786
+				);
787
+				echo wp_kses($this->handle_row_actions($item, $column_name, $primary), AllowedTags::getWithFormTags());
788
+				echo "</td>";
789
+			}
790
+		}
791
+	}
792
+
793
+
794
+	/**
795
+	 * Extra controls to be displayed between bulk actions and pagination
796
+	 *
797
+	 * @access public
798
+	 * @param string $which
799
+	 * @throws EE_Error
800
+	 */
801
+	public function extra_tablenav($which)
802
+	{
803
+		if ($which === 'top') {
804
+			$this->_filters();
805
+			echo wp_kses($this->_get_hidden_fields(), AllowedTags::getWithFormTags());
806
+		} else {
807
+			echo '<div class="list-table-bottom-buttons alignleft actions">';
808
+			foreach ($this->_bottom_buttons as $type => $action) {
809
+				$route         = $action['route'] ?? '';
810
+				$extra_request = $action['extra_request'] ?? '';
811
+				// already escaped
812
+				echo wp_kses($this->_admin_page->get_action_link_or_button(
813
+					$route,
814
+					$type,
815
+					$extra_request,
816
+					'button button--secondary'
817
+				), AllowedTags::getWithFormTags());
818
+			}
819
+			do_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', $this, $this->_screen);
820
+			echo '</div>';
821
+		}
822
+	}
823
+
824
+
825
+	/**
826
+	 * Get an associative array ( option_name => option_title ) with the list
827
+	 * of bulk actions available on this table.
828
+	 *
829
+	 * @return array
830
+	 * @since  3.1.0
831
+	 * @access protected
832
+	 */
833
+	public function get_bulk_actions()
834
+	{
835
+		return (array) $this->_get_bulk_actions();
836
+	}
837
+
838
+
839
+	/**
840
+	 * Processing bulk actions.
841
+	 */
842
+	public function process_bulk_action()
843
+	{
844
+		// this is not used it is handled by the child EE_Admin_Page class (routes).  However, including here for
845
+		// reference in case there is a case where it gets used.
846
+	}
847
+
848
+
849
+	/**
850
+	 * returns the EE admin page this list table is associated with
851
+	 *
852
+	 * @return EE_Admin_Page
853
+	 */
854
+	public function get_admin_page()
855
+	{
856
+		return $this->_admin_page;
857
+	}
858
+
859
+
860
+	/**
861
+	 * A "helper" function for all children to provide an html string of
862
+	 * actions to output in their content.  It is preferable for child classes
863
+	 * to use this method for generating their actions content so that it's
864
+	 * filterable by plugins
865
+	 *
866
+	 * @param string        $action_container           what are the html container
867
+	 *                                                  elements for this actions string?
868
+	 * @param string        $action_class               What class is for the container
869
+	 *                                                  element.
870
+	 * @param string        $action_items               The contents for the action items
871
+	 *                                                  container.  This is filtered before
872
+	 *                                                  returned.
873
+	 * @param string        $action_id                  What id (optional) is used for the
874
+	 *                                                  container element.
875
+	 * @param EE_Base_Class $item                       The object for the column displaying
876
+	 *                                                  the actions.
877
+	 * @return string The assembled action elements container.
878
+	 */
879
+	protected function _action_string(
880
+		$action_items,
881
+		$item,
882
+		$action_container = 'ul',
883
+		$action_class = '',
884
+		$action_id = ''
885
+	) {
886
+		$action_class = ! empty($action_class) ? ' class="' . esc_attr($action_class) . '"' : '';
887
+		$action_id    = ! empty($action_id) ? ' id="' . esc_attr($action_id) . '"' : '';
888
+		$open_tag     = ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : '';
889
+		$close_tag    = ! empty($action_container) ? '</' . $action_container . '>' : '';
890
+		try {
891
+			$content = apply_filters(
892
+				'FHEE__EE_Admin_List_Table___action_string__action_items',
893
+				$action_items,
894
+				$item,
895
+				$this
896
+			);
897
+		} catch (Exception $e) {
898
+			if (WP_DEBUG) {
899
+				EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
900
+			}
901
+			$content = $action_items;
902
+		}
903
+		return "{$open_tag}{$content}{$close_tag}";
904
+	}
905
+
906
+
907
+	/**
908
+	 * @return string
909
+	 */
910
+	protected function getReturnUrl()
911
+	{
912
+		$host = $this->_admin_page->get_request()->getServerParam('HTTP_HOST');
913
+		$uri  = $this->_admin_page->get_request()->getServerParam('REQUEST_URI');
914
+		return urlencode(esc_url_raw("//{$host}{$uri}"));
915
+	}
916 916
 }
Please login to merge, or discard this patch.