@@ -13,124 +13,124 @@ |
||
13 | 13 | interface RequestTypeContextCheckerInterface |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * true if the current request involves some form of activation |
|
18 | - * |
|
19 | - * @return bool |
|
20 | - */ |
|
21 | - public function isActivation(); |
|
16 | + /** |
|
17 | + * true if the current request involves some form of activation |
|
18 | + * |
|
19 | + * @return bool |
|
20 | + */ |
|
21 | + public function isActivation(); |
|
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * @param $is_activation |
|
26 | - * @return bool |
|
27 | - */ |
|
28 | - public function setIsActivation($is_activation); |
|
24 | + /** |
|
25 | + * @param $is_activation |
|
26 | + * @return bool |
|
27 | + */ |
|
28 | + public function setIsActivation($is_activation); |
|
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * true if the current request is for the admin and is not being made via AJAX |
|
33 | - * |
|
34 | - * @return bool |
|
35 | - */ |
|
36 | - public function isAdmin(); |
|
31 | + /** |
|
32 | + * true if the current request is for the admin and is not being made via AJAX |
|
33 | + * |
|
34 | + * @return bool |
|
35 | + */ |
|
36 | + public function isAdmin(); |
|
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * true if the current request is for the admin AND is being made via AJAX |
|
41 | - * and the ajax request contains the request parameter "ee_admin_ajax" |
|
42 | - * |
|
43 | - * @return bool |
|
44 | - */ |
|
45 | - public function isAdminAjax(); |
|
39 | + /** |
|
40 | + * true if the current request is for the admin AND is being made via AJAX |
|
41 | + * and the ajax request contains the request parameter "ee_admin_ajax" |
|
42 | + * |
|
43 | + * @return bool |
|
44 | + */ |
|
45 | + public function isAdminAjax(); |
|
46 | 46 | |
47 | 47 | |
48 | - /** |
|
49 | - * true if the current request is being made via AJAX... any AJAX |
|
50 | - * |
|
51 | - * @return bool |
|
52 | - */ |
|
53 | - public function isAjax(); |
|
48 | + /** |
|
49 | + * true if the current request is being made via AJAX... any AJAX |
|
50 | + * |
|
51 | + * @return bool |
|
52 | + */ |
|
53 | + public function isAjax(); |
|
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * true if the current request is for the EE REST API |
|
58 | - * |
|
59 | - * @return bool |
|
60 | - */ |
|
61 | - public function isApi(); |
|
56 | + /** |
|
57 | + * true if the current request is for the EE REST API |
|
58 | + * |
|
59 | + * @return bool |
|
60 | + */ |
|
61 | + public function isApi(); |
|
62 | 62 | |
63 | 63 | |
64 | - /** |
|
65 | - * true if the current request is from the command line |
|
66 | - * |
|
67 | - * @return bool |
|
68 | - */ |
|
69 | - public function isCli(); |
|
64 | + /** |
|
65 | + * true if the current request is from the command line |
|
66 | + * |
|
67 | + * @return bool |
|
68 | + */ |
|
69 | + public function isCli(); |
|
70 | 70 | |
71 | 71 | |
72 | - /** |
|
73 | - * true if the current request is for a WP_Cron |
|
74 | - * |
|
75 | - * @return bool |
|
76 | - */ |
|
77 | - public function isCron(); |
|
72 | + /** |
|
73 | + * true if the current request is for a WP_Cron |
|
74 | + * |
|
75 | + * @return bool |
|
76 | + */ |
|
77 | + public function isCron(); |
|
78 | 78 | |
79 | 79 | |
80 | - /** |
|
81 | - * true if the current request is for either the EE admin or EE frontend AND is being made via AJAX |
|
82 | - * |
|
83 | - * @return bool |
|
84 | - */ |
|
85 | - public function isEeAjax(); |
|
80 | + /** |
|
81 | + * true if the current request is for either the EE admin or EE frontend AND is being made via AJAX |
|
82 | + * |
|
83 | + * @return bool |
|
84 | + */ |
|
85 | + public function isEeAjax(); |
|
86 | 86 | |
87 | 87 | |
88 | - /** |
|
89 | - * true if the current request is for a feed (ie: RSS) |
|
90 | - * |
|
91 | - * @return bool |
|
92 | - */ |
|
93 | - public function isFeed(); |
|
88 | + /** |
|
89 | + * true if the current request is for a feed (ie: RSS) |
|
90 | + * |
|
91 | + * @return bool |
|
92 | + */ |
|
93 | + public function isFeed(); |
|
94 | 94 | |
95 | 95 | |
96 | - /** |
|
97 | - * true if the current request is for the frontend and is not being made via AJAX |
|
98 | - * |
|
99 | - * @return bool |
|
100 | - */ |
|
101 | - public function isFrontend(); |
|
96 | + /** |
|
97 | + * true if the current request is for the frontend and is not being made via AJAX |
|
98 | + * |
|
99 | + * @return bool |
|
100 | + */ |
|
101 | + public function isFrontend(); |
|
102 | 102 | |
103 | 103 | |
104 | - /** |
|
105 | - * @return bool |
|
106 | - */ |
|
107 | - public function isFrontAjax(); |
|
104 | + /** |
|
105 | + * @return bool |
|
106 | + */ |
|
107 | + public function isFrontAjax(); |
|
108 | 108 | |
109 | 109 | |
110 | - /** |
|
111 | - * @return bool |
|
112 | - */ |
|
113 | - public function isIframe(); |
|
110 | + /** |
|
111 | + * @return bool |
|
112 | + */ |
|
113 | + public function isIframe(); |
|
114 | 114 | |
115 | 115 | |
116 | - /** |
|
117 | - * true if the current request is being made via AJAX but is NOT for EE related logic |
|
118 | - * |
|
119 | - * @return bool |
|
120 | - */ |
|
121 | - public function isOtherAjax(); |
|
116 | + /** |
|
117 | + * true if the current request is being made via AJAX but is NOT for EE related logic |
|
118 | + * |
|
119 | + * @return bool |
|
120 | + */ |
|
121 | + public function isOtherAjax(); |
|
122 | 122 | |
123 | 123 | |
124 | - /** |
|
125 | - * true if the current request is a loopback sent from WP core to test for errors |
|
126 | - * |
|
127 | - * @return bool |
|
128 | - */ |
|
129 | - public function isWordPressScrape(); |
|
124 | + /** |
|
125 | + * true if the current request is a loopback sent from WP core to test for errors |
|
126 | + * |
|
127 | + * @return bool |
|
128 | + */ |
|
129 | + public function isWordPressScrape(); |
|
130 | 130 | |
131 | 131 | |
132 | - /** |
|
133 | - * @return string |
|
134 | - */ |
|
135 | - public function slug(); |
|
132 | + /** |
|
133 | + * @return string |
|
134 | + */ |
|
135 | + public function slug(); |
|
136 | 136 | } |
@@ -16,195 +16,195 @@ |
||
16 | 16 | class RequestTypeContextChecker extends ContextChecker implements RequestTypeContextCheckerInterface |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @var RequestTypeContext $request_type |
|
21 | - */ |
|
22 | - private $request_type; |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * RequestTypeContextChecker constructor. |
|
27 | - * |
|
28 | - * @param RequestTypeContext $request_type |
|
29 | - */ |
|
30 | - public function __construct(RequestTypeContext $request_type) |
|
31 | - { |
|
32 | - $this->request_type = $request_type; |
|
33 | - parent::__construct( |
|
34 | - 'RequestTypeContextChecker', |
|
35 | - $this->request_type->validRequestTypes() |
|
36 | - ); |
|
37 | - } |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * true if the current request involves some form of activation |
|
42 | - * |
|
43 | - * @return bool |
|
44 | - */ |
|
45 | - public function isActivation() |
|
46 | - { |
|
47 | - return $this->request_type->isActivation(); |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * @param $is_activation |
|
53 | - * @return bool |
|
54 | - */ |
|
55 | - public function setIsActivation($is_activation) |
|
56 | - { |
|
57 | - return $this->request_type->setIsActivation($is_activation); |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * true if the current request is for the admin and is not being made via AJAX |
|
63 | - * |
|
64 | - * @return bool |
|
65 | - */ |
|
66 | - public function isAdmin() |
|
67 | - { |
|
68 | - return $this->request_type->slug() === RequestTypeContext::ADMIN; |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * true if the current request is for the admin AND is being made via AJAX |
|
74 | - * |
|
75 | - * @return bool |
|
76 | - */ |
|
77 | - public function isAdminAjax() |
|
78 | - { |
|
79 | - return $this->request_type->slug() === RequestTypeContext::AJAX_ADMIN; |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * true if the current request is being made via AJAX... any AJAX |
|
85 | - * |
|
86 | - * @return bool |
|
87 | - */ |
|
88 | - public function isAjax() |
|
89 | - { |
|
90 | - return $this->isEeAjax() || $this->isOtherAjax(); |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * true if the current request is for either the EE admin or EE frontend AND is being made via AJAX |
|
96 | - * |
|
97 | - * @return bool |
|
98 | - */ |
|
99 | - public function isEeAjax() |
|
100 | - { |
|
101 | - return $this->isAdminAjax() || $this->isFrontAjax(); |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * true if the current request is being made via AJAX but is NOT for EE related logic |
|
107 | - * |
|
108 | - * @return bool |
|
109 | - */ |
|
110 | - public function isOtherAjax() |
|
111 | - { |
|
112 | - return $this->request_type->slug() === RequestTypeContext::AJAX_OTHER; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * true if the current request is for the EE REST API |
|
117 | - * |
|
118 | - * @return bool |
|
119 | - */ |
|
120 | - public function isApi() |
|
121 | - { |
|
122 | - return $this->request_type->slug() === RequestTypeContext::API; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * true if the current request is from the command line |
|
128 | - * |
|
129 | - * @return bool |
|
130 | - */ |
|
131 | - public function isCli() |
|
132 | - { |
|
133 | - return $this->request_type->slug() === RequestTypeContext::CLI; |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * true if the current request is for a WP_Cron |
|
139 | - * |
|
140 | - * @return bool |
|
141 | - */ |
|
142 | - public function isCron() |
|
143 | - { |
|
144 | - return $this->request_type->slug() === RequestTypeContext::CRON; |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * true if the current request is for a feed (ie: RSS) |
|
150 | - * |
|
151 | - * @return bool |
|
152 | - */ |
|
153 | - public function isFeed() |
|
154 | - { |
|
155 | - return $this->request_type->slug() === RequestTypeContext::FEED; |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * true if the current request is for the frontend and is not being made via AJAX |
|
161 | - * |
|
162 | - * @return bool |
|
163 | - */ |
|
164 | - public function isFrontend() |
|
165 | - { |
|
166 | - return $this->request_type->slug() === RequestTypeContext::FRONTEND; |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * true if the current request is for the frontend AND is being made via AJAX |
|
172 | - * |
|
173 | - * @return bool |
|
174 | - */ |
|
175 | - public function isFrontAjax() |
|
176 | - { |
|
177 | - return $this->request_type->slug() === RequestTypeContext::AJAX_FRONT; |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * true if the current request is for content that is to be displayed within an iframe |
|
183 | - * |
|
184 | - * @return bool |
|
185 | - */ |
|
186 | - public function isIframe() |
|
187 | - { |
|
188 | - return $this->request_type->slug() === RequestTypeContext::IFRAME; |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * true if the current request is a loopback sent from WP core to test for errors |
|
194 | - * |
|
195 | - * @return bool |
|
196 | - */ |
|
197 | - public function isWordPressScrape() |
|
198 | - { |
|
199 | - return $this->request_type->slug() === RequestTypeContext::WP_SCRAPE; |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * @return string |
|
205 | - */ |
|
206 | - public function slug() |
|
207 | - { |
|
208 | - return $this->request_type->slug(); |
|
209 | - } |
|
19 | + /** |
|
20 | + * @var RequestTypeContext $request_type |
|
21 | + */ |
|
22 | + private $request_type; |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * RequestTypeContextChecker constructor. |
|
27 | + * |
|
28 | + * @param RequestTypeContext $request_type |
|
29 | + */ |
|
30 | + public function __construct(RequestTypeContext $request_type) |
|
31 | + { |
|
32 | + $this->request_type = $request_type; |
|
33 | + parent::__construct( |
|
34 | + 'RequestTypeContextChecker', |
|
35 | + $this->request_type->validRequestTypes() |
|
36 | + ); |
|
37 | + } |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * true if the current request involves some form of activation |
|
42 | + * |
|
43 | + * @return bool |
|
44 | + */ |
|
45 | + public function isActivation() |
|
46 | + { |
|
47 | + return $this->request_type->isActivation(); |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * @param $is_activation |
|
53 | + * @return bool |
|
54 | + */ |
|
55 | + public function setIsActivation($is_activation) |
|
56 | + { |
|
57 | + return $this->request_type->setIsActivation($is_activation); |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * true if the current request is for the admin and is not being made via AJAX |
|
63 | + * |
|
64 | + * @return bool |
|
65 | + */ |
|
66 | + public function isAdmin() |
|
67 | + { |
|
68 | + return $this->request_type->slug() === RequestTypeContext::ADMIN; |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * true if the current request is for the admin AND is being made via AJAX |
|
74 | + * |
|
75 | + * @return bool |
|
76 | + */ |
|
77 | + public function isAdminAjax() |
|
78 | + { |
|
79 | + return $this->request_type->slug() === RequestTypeContext::AJAX_ADMIN; |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * true if the current request is being made via AJAX... any AJAX |
|
85 | + * |
|
86 | + * @return bool |
|
87 | + */ |
|
88 | + public function isAjax() |
|
89 | + { |
|
90 | + return $this->isEeAjax() || $this->isOtherAjax(); |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * true if the current request is for either the EE admin or EE frontend AND is being made via AJAX |
|
96 | + * |
|
97 | + * @return bool |
|
98 | + */ |
|
99 | + public function isEeAjax() |
|
100 | + { |
|
101 | + return $this->isAdminAjax() || $this->isFrontAjax(); |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * true if the current request is being made via AJAX but is NOT for EE related logic |
|
107 | + * |
|
108 | + * @return bool |
|
109 | + */ |
|
110 | + public function isOtherAjax() |
|
111 | + { |
|
112 | + return $this->request_type->slug() === RequestTypeContext::AJAX_OTHER; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * true if the current request is for the EE REST API |
|
117 | + * |
|
118 | + * @return bool |
|
119 | + */ |
|
120 | + public function isApi() |
|
121 | + { |
|
122 | + return $this->request_type->slug() === RequestTypeContext::API; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * true if the current request is from the command line |
|
128 | + * |
|
129 | + * @return bool |
|
130 | + */ |
|
131 | + public function isCli() |
|
132 | + { |
|
133 | + return $this->request_type->slug() === RequestTypeContext::CLI; |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * true if the current request is for a WP_Cron |
|
139 | + * |
|
140 | + * @return bool |
|
141 | + */ |
|
142 | + public function isCron() |
|
143 | + { |
|
144 | + return $this->request_type->slug() === RequestTypeContext::CRON; |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * true if the current request is for a feed (ie: RSS) |
|
150 | + * |
|
151 | + * @return bool |
|
152 | + */ |
|
153 | + public function isFeed() |
|
154 | + { |
|
155 | + return $this->request_type->slug() === RequestTypeContext::FEED; |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * true if the current request is for the frontend and is not being made via AJAX |
|
161 | + * |
|
162 | + * @return bool |
|
163 | + */ |
|
164 | + public function isFrontend() |
|
165 | + { |
|
166 | + return $this->request_type->slug() === RequestTypeContext::FRONTEND; |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * true if the current request is for the frontend AND is being made via AJAX |
|
172 | + * |
|
173 | + * @return bool |
|
174 | + */ |
|
175 | + public function isFrontAjax() |
|
176 | + { |
|
177 | + return $this->request_type->slug() === RequestTypeContext::AJAX_FRONT; |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * true if the current request is for content that is to be displayed within an iframe |
|
183 | + * |
|
184 | + * @return bool |
|
185 | + */ |
|
186 | + public function isIframe() |
|
187 | + { |
|
188 | + return $this->request_type->slug() === RequestTypeContext::IFRAME; |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * true if the current request is a loopback sent from WP core to test for errors |
|
194 | + * |
|
195 | + * @return bool |
|
196 | + */ |
|
197 | + public function isWordPressScrape() |
|
198 | + { |
|
199 | + return $this->request_type->slug() === RequestTypeContext::WP_SCRAPE; |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * @return string |
|
205 | + */ |
|
206 | + public function slug() |
|
207 | + { |
|
208 | + return $this->request_type->slug(); |
|
209 | + } |
|
210 | 210 | } |
@@ -19,137 +19,137 @@ |
||
19 | 19 | class RequestTypeContextDetector |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * @var RequestTypeContextFactory $factory |
|
24 | - */ |
|
25 | - private $factory; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var RequestInterface $request |
|
29 | - */ |
|
30 | - private $request; |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * RequestTypeContextDetector constructor. |
|
35 | - * |
|
36 | - * @param RequestInterface $request |
|
37 | - * @param RequestTypeContextFactory $factory |
|
38 | - */ |
|
39 | - public function __construct(RequestInterface $request, RequestTypeContextFactory $factory) |
|
40 | - { |
|
41 | - $this->request = $request; |
|
42 | - $this->factory = $factory; |
|
43 | - } |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * @return RequestTypeContext |
|
48 | - * @throws InvalidArgumentException |
|
49 | - */ |
|
50 | - public function detectRequestTypeContext() |
|
51 | - { |
|
52 | - // Detect error scrapes |
|
53 | - if ($this->request->getRequestParam('wp_scrape_key') !== null |
|
54 | - && $this->request->getRequestParam('wp_scrape_nonce') !== null |
|
55 | - ) { |
|
56 | - return $this->factory->create(RequestTypeContext::WP_SCRAPE); |
|
57 | - } |
|
58 | - // Detect EE REST API |
|
59 | - if ($this->isEspressoRestApiRequest()) { |
|
60 | - return $this->factory->create(RequestTypeContext::API); |
|
61 | - } |
|
62 | - // Detect AJAX |
|
63 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
64 | - if (filter_var($this->request->getRequestParam('ee_front_ajax'), FILTER_VALIDATE_BOOLEAN)) { |
|
65 | - return $this->factory->create(RequestTypeContext::AJAX_FRONT); |
|
66 | - } |
|
67 | - if (filter_var($this->request->getRequestParam('ee_admin_ajax'), FILTER_VALIDATE_BOOLEAN)) { |
|
68 | - return $this->factory->create(RequestTypeContext::AJAX_ADMIN); |
|
69 | - } |
|
70 | - return $this->factory->create(RequestTypeContext::AJAX_OTHER); |
|
71 | - } |
|
72 | - // Detect WP_Cron |
|
73 | - if ($this->isCronRequest()) { |
|
74 | - return $this->factory->create(RequestTypeContext::CRON); |
|
75 | - } |
|
76 | - // Detect command line requests |
|
77 | - if (defined('WP_CLI') && WP_CLI) { |
|
78 | - return $this->factory->create(RequestTypeContext::CLI); |
|
79 | - } |
|
80 | - // detect WordPress admin (ie: "Dashboard") |
|
81 | - if (is_admin()) { |
|
82 | - return $this->factory->create(RequestTypeContext::ADMIN); |
|
83 | - } |
|
84 | - // Detect iFrames |
|
85 | - if ($this->isIframeRoute()) { |
|
86 | - return $this->factory->create(RequestTypeContext::IFRAME); |
|
87 | - } |
|
88 | - // Detect Feeds |
|
89 | - if ($this->isFeedRequest()) { |
|
90 | - return $this->factory->create(RequestTypeContext::FEED); |
|
91 | - } |
|
92 | - // and by process of elimination... |
|
93 | - return $this->factory->create(RequestTypeContext::FRONTEND); |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * @return bool |
|
99 | - */ |
|
100 | - private function isEspressoRestApiRequest() |
|
101 | - { |
|
102 | - $ee_rest_url_prefix = RecommendedVersions::compareWordPressVersion('4.4.0') |
|
103 | - ? trim(rest_get_url_prefix(), '/') |
|
104 | - : 'wp-json'; |
|
105 | - $ee_rest_url_prefix .= '/' . Domain::API_NAMESPACE; |
|
106 | - return $this->uriPathMatches($ee_rest_url_prefix); |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * @return bool |
|
112 | - */ |
|
113 | - private function isCronRequest() |
|
114 | - { |
|
115 | - return $this->uriPathMatches('wp-cron.php'); |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * @return bool |
|
121 | - */ |
|
122 | - private function isFeedRequest() |
|
123 | - { |
|
124 | - return $this->uriPathMatches('feed'); |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * @param string $component |
|
130 | - * @return bool |
|
131 | - */ |
|
132 | - private function uriPathMatches($component) |
|
133 | - { |
|
134 | - $request_uri = $this->request->requestUri(); |
|
135 | - $parts = explode('?', $request_uri); |
|
136 | - $path = trim(reset($parts), '/'); |
|
137 | - return strpos($path, $component) === 0; |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * @return bool |
|
143 | - */ |
|
144 | - private function isIframeRoute() |
|
145 | - { |
|
146 | - $is_iframe_route = apply_filters( |
|
147 | - 'FHEE__EventEspresso_core_domain_services_contexts_RequestTypeContextDetector__isIframeRoute', |
|
148 | - $this->request->getRequestParam('event_list', '') === 'iframe' |
|
149 | - || $this->request->getRequestParam('ticket_selector', '') === 'iframe' |
|
150 | - || $this->request->getRequestParam('calendar', '') === 'iframe', |
|
151 | - $this |
|
152 | - ); |
|
153 | - return filter_var($is_iframe_route, FILTER_VALIDATE_BOOLEAN); |
|
154 | - } |
|
22 | + /** |
|
23 | + * @var RequestTypeContextFactory $factory |
|
24 | + */ |
|
25 | + private $factory; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var RequestInterface $request |
|
29 | + */ |
|
30 | + private $request; |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * RequestTypeContextDetector constructor. |
|
35 | + * |
|
36 | + * @param RequestInterface $request |
|
37 | + * @param RequestTypeContextFactory $factory |
|
38 | + */ |
|
39 | + public function __construct(RequestInterface $request, RequestTypeContextFactory $factory) |
|
40 | + { |
|
41 | + $this->request = $request; |
|
42 | + $this->factory = $factory; |
|
43 | + } |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * @return RequestTypeContext |
|
48 | + * @throws InvalidArgumentException |
|
49 | + */ |
|
50 | + public function detectRequestTypeContext() |
|
51 | + { |
|
52 | + // Detect error scrapes |
|
53 | + if ($this->request->getRequestParam('wp_scrape_key') !== null |
|
54 | + && $this->request->getRequestParam('wp_scrape_nonce') !== null |
|
55 | + ) { |
|
56 | + return $this->factory->create(RequestTypeContext::WP_SCRAPE); |
|
57 | + } |
|
58 | + // Detect EE REST API |
|
59 | + if ($this->isEspressoRestApiRequest()) { |
|
60 | + return $this->factory->create(RequestTypeContext::API); |
|
61 | + } |
|
62 | + // Detect AJAX |
|
63 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
64 | + if (filter_var($this->request->getRequestParam('ee_front_ajax'), FILTER_VALIDATE_BOOLEAN)) { |
|
65 | + return $this->factory->create(RequestTypeContext::AJAX_FRONT); |
|
66 | + } |
|
67 | + if (filter_var($this->request->getRequestParam('ee_admin_ajax'), FILTER_VALIDATE_BOOLEAN)) { |
|
68 | + return $this->factory->create(RequestTypeContext::AJAX_ADMIN); |
|
69 | + } |
|
70 | + return $this->factory->create(RequestTypeContext::AJAX_OTHER); |
|
71 | + } |
|
72 | + // Detect WP_Cron |
|
73 | + if ($this->isCronRequest()) { |
|
74 | + return $this->factory->create(RequestTypeContext::CRON); |
|
75 | + } |
|
76 | + // Detect command line requests |
|
77 | + if (defined('WP_CLI') && WP_CLI) { |
|
78 | + return $this->factory->create(RequestTypeContext::CLI); |
|
79 | + } |
|
80 | + // detect WordPress admin (ie: "Dashboard") |
|
81 | + if (is_admin()) { |
|
82 | + return $this->factory->create(RequestTypeContext::ADMIN); |
|
83 | + } |
|
84 | + // Detect iFrames |
|
85 | + if ($this->isIframeRoute()) { |
|
86 | + return $this->factory->create(RequestTypeContext::IFRAME); |
|
87 | + } |
|
88 | + // Detect Feeds |
|
89 | + if ($this->isFeedRequest()) { |
|
90 | + return $this->factory->create(RequestTypeContext::FEED); |
|
91 | + } |
|
92 | + // and by process of elimination... |
|
93 | + return $this->factory->create(RequestTypeContext::FRONTEND); |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * @return bool |
|
99 | + */ |
|
100 | + private function isEspressoRestApiRequest() |
|
101 | + { |
|
102 | + $ee_rest_url_prefix = RecommendedVersions::compareWordPressVersion('4.4.0') |
|
103 | + ? trim(rest_get_url_prefix(), '/') |
|
104 | + : 'wp-json'; |
|
105 | + $ee_rest_url_prefix .= '/' . Domain::API_NAMESPACE; |
|
106 | + return $this->uriPathMatches($ee_rest_url_prefix); |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * @return bool |
|
112 | + */ |
|
113 | + private function isCronRequest() |
|
114 | + { |
|
115 | + return $this->uriPathMatches('wp-cron.php'); |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * @return bool |
|
121 | + */ |
|
122 | + private function isFeedRequest() |
|
123 | + { |
|
124 | + return $this->uriPathMatches('feed'); |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * @param string $component |
|
130 | + * @return bool |
|
131 | + */ |
|
132 | + private function uriPathMatches($component) |
|
133 | + { |
|
134 | + $request_uri = $this->request->requestUri(); |
|
135 | + $parts = explode('?', $request_uri); |
|
136 | + $path = trim(reset($parts), '/'); |
|
137 | + return strpos($path, $component) === 0; |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * @return bool |
|
143 | + */ |
|
144 | + private function isIframeRoute() |
|
145 | + { |
|
146 | + $is_iframe_route = apply_filters( |
|
147 | + 'FHEE__EventEspresso_core_domain_services_contexts_RequestTypeContextDetector__isIframeRoute', |
|
148 | + $this->request->getRequestParam('event_list', '') === 'iframe' |
|
149 | + || $this->request->getRequestParam('ticket_selector', '') === 'iframe' |
|
150 | + || $this->request->getRequestParam('calendar', '') === 'iframe', |
|
151 | + $this |
|
152 | + ); |
|
153 | + return filter_var($is_iframe_route, FILTER_VALIDATE_BOOLEAN); |
|
154 | + } |
|
155 | 155 | } |
@@ -16,143 +16,143 @@ |
||
16 | 16 | class RequestTypeContext extends Context |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * indicates that the current request involves some form of activation |
|
21 | - */ |
|
22 | - const ACTIVATION = 'activation-request'; |
|
23 | - |
|
24 | - /** |
|
25 | - * indicates that the current request is for the admin but is not being made via AJAX |
|
26 | - */ |
|
27 | - const ADMIN = 'non-ajax-admin-request'; |
|
28 | - |
|
29 | - /** |
|
30 | - * indicates that the current request is for the admin AND is being made via AJAX |
|
31 | - */ |
|
32 | - const AJAX_ADMIN = 'admin-ajax-request'; |
|
33 | - |
|
34 | - /** |
|
35 | - * indicates that the current request is for the frontend AND is being made via AJAX |
|
36 | - */ |
|
37 | - const AJAX_FRONT = 'frontend-ajax-request'; |
|
38 | - |
|
39 | - /** |
|
40 | - * indicates that the current request is being made via AJAX, but is NOT for EE |
|
41 | - */ |
|
42 | - const AJAX_OTHER = 'other-ajax-request'; |
|
43 | - |
|
44 | - /** |
|
45 | - * indicates that the current request is for the EE REST API |
|
46 | - */ |
|
47 | - const API = 'rest-api'; |
|
48 | - |
|
49 | - /** |
|
50 | - * indicates that the current request is from the command line |
|
51 | - */ |
|
52 | - const CLI = 'command-line'; |
|
53 | - |
|
54 | - /** |
|
55 | - * indicates that the current request is for a WP_Cron |
|
56 | - */ |
|
57 | - const CRON = 'wp-cron'; |
|
58 | - |
|
59 | - /** |
|
60 | - * indicates that the current request is for a feed (ie: RSS) |
|
61 | - */ |
|
62 | - const FEED = 'feed-request'; |
|
63 | - |
|
64 | - /** |
|
65 | - * indicates that the current request is for the frontend but is not being made via AJAX |
|
66 | - */ |
|
67 | - const FRONTEND = 'non-ajax-frontend-request'; |
|
68 | - |
|
69 | - /** |
|
70 | - * indicates that the current request is for content that is to be displayed within an iframe |
|
71 | - */ |
|
72 | - const IFRAME = 'iframe-request'; |
|
73 | - |
|
74 | - /** |
|
75 | - * indicates that the current request is a loopback sent from WP core to test for errors |
|
76 | - */ |
|
77 | - const WP_SCRAPE = 'wordpress-scrape'; |
|
78 | - |
|
79 | - /** |
|
80 | - * @var boolean $is_activation |
|
81 | - */ |
|
82 | - private $is_activation = false; |
|
83 | - |
|
84 | - /** |
|
85 | - * @var array $valid_request_types |
|
86 | - */ |
|
87 | - private $valid_request_types = array(); |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * RequestTypeContext constructor. |
|
92 | - * |
|
93 | - * @param string $slug |
|
94 | - * @param string $description |
|
95 | - * @throws InvalidArgumentException |
|
96 | - */ |
|
97 | - public function __construct($slug, $description) |
|
98 | - { |
|
99 | - parent::__construct($slug, $description); |
|
100 | - if (! in_array($this->slug(), $this->validRequestTypes(), true)) { |
|
101 | - throw new InvalidArgumentException( |
|
102 | - sprintf( |
|
103 | - esc_html__( |
|
104 | - 'The RequestTypeContext slug must be one of the following values: %1$s %2$s', |
|
105 | - 'event_espresso' |
|
106 | - ), |
|
107 | - var_export($this->validRequestTypes(), true) |
|
108 | - ) |
|
109 | - ); |
|
110 | - } |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * @return array |
|
116 | - */ |
|
117 | - public function validRequestTypes() |
|
118 | - { |
|
119 | - if (empty($this->valid_request_types)) { |
|
120 | - $this->valid_request_types = apply_filters( |
|
121 | - 'FHEE__EventEspresso_core_domain_entities_contexts_RequestTypeContext__validRequestTypes', |
|
122 | - array( |
|
123 | - RequestTypeContext::ACTIVATION, |
|
124 | - RequestTypeContext::ADMIN, |
|
125 | - RequestTypeContext::AJAX_ADMIN, |
|
126 | - RequestTypeContext::AJAX_FRONT, |
|
127 | - RequestTypeContext::AJAX_OTHER, |
|
128 | - RequestTypeContext::API, |
|
129 | - RequestTypeContext::CLI, |
|
130 | - RequestTypeContext::CRON, |
|
131 | - RequestTypeContext::FEED, |
|
132 | - RequestTypeContext::FRONTEND, |
|
133 | - RequestTypeContext::IFRAME, |
|
134 | - RequestTypeContext::WP_SCRAPE, |
|
135 | - ) |
|
136 | - ); |
|
137 | - } |
|
138 | - return $this->valid_request_types; |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * @return bool |
|
144 | - */ |
|
145 | - public function isActivation() |
|
146 | - { |
|
147 | - return $this->is_activation; |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * @param bool $is_activation |
|
153 | - */ |
|
154 | - public function setIsActivation($is_activation) |
|
155 | - { |
|
156 | - $this->is_activation = filter_var($is_activation, FILTER_VALIDATE_BOOLEAN); |
|
157 | - } |
|
19 | + /** |
|
20 | + * indicates that the current request involves some form of activation |
|
21 | + */ |
|
22 | + const ACTIVATION = 'activation-request'; |
|
23 | + |
|
24 | + /** |
|
25 | + * indicates that the current request is for the admin but is not being made via AJAX |
|
26 | + */ |
|
27 | + const ADMIN = 'non-ajax-admin-request'; |
|
28 | + |
|
29 | + /** |
|
30 | + * indicates that the current request is for the admin AND is being made via AJAX |
|
31 | + */ |
|
32 | + const AJAX_ADMIN = 'admin-ajax-request'; |
|
33 | + |
|
34 | + /** |
|
35 | + * indicates that the current request is for the frontend AND is being made via AJAX |
|
36 | + */ |
|
37 | + const AJAX_FRONT = 'frontend-ajax-request'; |
|
38 | + |
|
39 | + /** |
|
40 | + * indicates that the current request is being made via AJAX, but is NOT for EE |
|
41 | + */ |
|
42 | + const AJAX_OTHER = 'other-ajax-request'; |
|
43 | + |
|
44 | + /** |
|
45 | + * indicates that the current request is for the EE REST API |
|
46 | + */ |
|
47 | + const API = 'rest-api'; |
|
48 | + |
|
49 | + /** |
|
50 | + * indicates that the current request is from the command line |
|
51 | + */ |
|
52 | + const CLI = 'command-line'; |
|
53 | + |
|
54 | + /** |
|
55 | + * indicates that the current request is for a WP_Cron |
|
56 | + */ |
|
57 | + const CRON = 'wp-cron'; |
|
58 | + |
|
59 | + /** |
|
60 | + * indicates that the current request is for a feed (ie: RSS) |
|
61 | + */ |
|
62 | + const FEED = 'feed-request'; |
|
63 | + |
|
64 | + /** |
|
65 | + * indicates that the current request is for the frontend but is not being made via AJAX |
|
66 | + */ |
|
67 | + const FRONTEND = 'non-ajax-frontend-request'; |
|
68 | + |
|
69 | + /** |
|
70 | + * indicates that the current request is for content that is to be displayed within an iframe |
|
71 | + */ |
|
72 | + const IFRAME = 'iframe-request'; |
|
73 | + |
|
74 | + /** |
|
75 | + * indicates that the current request is a loopback sent from WP core to test for errors |
|
76 | + */ |
|
77 | + const WP_SCRAPE = 'wordpress-scrape'; |
|
78 | + |
|
79 | + /** |
|
80 | + * @var boolean $is_activation |
|
81 | + */ |
|
82 | + private $is_activation = false; |
|
83 | + |
|
84 | + /** |
|
85 | + * @var array $valid_request_types |
|
86 | + */ |
|
87 | + private $valid_request_types = array(); |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * RequestTypeContext constructor. |
|
92 | + * |
|
93 | + * @param string $slug |
|
94 | + * @param string $description |
|
95 | + * @throws InvalidArgumentException |
|
96 | + */ |
|
97 | + public function __construct($slug, $description) |
|
98 | + { |
|
99 | + parent::__construct($slug, $description); |
|
100 | + if (! in_array($this->slug(), $this->validRequestTypes(), true)) { |
|
101 | + throw new InvalidArgumentException( |
|
102 | + sprintf( |
|
103 | + esc_html__( |
|
104 | + 'The RequestTypeContext slug must be one of the following values: %1$s %2$s', |
|
105 | + 'event_espresso' |
|
106 | + ), |
|
107 | + var_export($this->validRequestTypes(), true) |
|
108 | + ) |
|
109 | + ); |
|
110 | + } |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * @return array |
|
116 | + */ |
|
117 | + public function validRequestTypes() |
|
118 | + { |
|
119 | + if (empty($this->valid_request_types)) { |
|
120 | + $this->valid_request_types = apply_filters( |
|
121 | + 'FHEE__EventEspresso_core_domain_entities_contexts_RequestTypeContext__validRequestTypes', |
|
122 | + array( |
|
123 | + RequestTypeContext::ACTIVATION, |
|
124 | + RequestTypeContext::ADMIN, |
|
125 | + RequestTypeContext::AJAX_ADMIN, |
|
126 | + RequestTypeContext::AJAX_FRONT, |
|
127 | + RequestTypeContext::AJAX_OTHER, |
|
128 | + RequestTypeContext::API, |
|
129 | + RequestTypeContext::CLI, |
|
130 | + RequestTypeContext::CRON, |
|
131 | + RequestTypeContext::FEED, |
|
132 | + RequestTypeContext::FRONTEND, |
|
133 | + RequestTypeContext::IFRAME, |
|
134 | + RequestTypeContext::WP_SCRAPE, |
|
135 | + ) |
|
136 | + ); |
|
137 | + } |
|
138 | + return $this->valid_request_types; |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * @return bool |
|
144 | + */ |
|
145 | + public function isActivation() |
|
146 | + { |
|
147 | + return $this->is_activation; |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * @param bool $is_activation |
|
153 | + */ |
|
154 | + public function setIsActivation($is_activation) |
|
155 | + { |
|
156 | + $this->is_activation = filter_var($is_activation, FILTER_VALIDATE_BOOLEAN); |
|
157 | + } |
|
158 | 158 | } |
@@ -17,586 +17,586 @@ |
||
17 | 17 | class Request implements InterminableInterface, RequestInterface, ReservedInstanceInterface |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * $_GET parameters |
|
22 | - * |
|
23 | - * @var array $get |
|
24 | - */ |
|
25 | - private $get; |
|
26 | - |
|
27 | - /** |
|
28 | - * $_POST parameters |
|
29 | - * |
|
30 | - * @var array $post |
|
31 | - */ |
|
32 | - private $post; |
|
33 | - |
|
34 | - /** |
|
35 | - * $_COOKIE parameters |
|
36 | - * |
|
37 | - * @var array $cookie |
|
38 | - */ |
|
39 | - private $cookie; |
|
40 | - |
|
41 | - /** |
|
42 | - * $_SERVER parameters |
|
43 | - * |
|
44 | - * @var array $server |
|
45 | - */ |
|
46 | - private $server; |
|
47 | - |
|
48 | - /** |
|
49 | - * $_REQUEST parameters |
|
50 | - * |
|
51 | - * @var array $request |
|
52 | - */ |
|
53 | - private $request; |
|
54 | - |
|
55 | - /** |
|
56 | - * @var RequestTypeContextCheckerInterface |
|
57 | - */ |
|
58 | - private $request_type; |
|
59 | - |
|
60 | - /** |
|
61 | - * IP address for request |
|
62 | - * |
|
63 | - * @var string $ip_address |
|
64 | - */ |
|
65 | - private $ip_address; |
|
66 | - |
|
67 | - /** |
|
68 | - * @var string $user_agent |
|
69 | - */ |
|
70 | - private $user_agent; |
|
71 | - |
|
72 | - /** |
|
73 | - * true if current user appears to be some kind of bot |
|
74 | - * |
|
75 | - * @var bool $is_bot |
|
76 | - */ |
|
77 | - private $is_bot; |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * @param array $get |
|
82 | - * @param array $post |
|
83 | - * @param array $cookie |
|
84 | - * @param array $server |
|
85 | - */ |
|
86 | - public function __construct(array $get, array $post, array $cookie, array $server) |
|
87 | - { |
|
88 | - // grab request vars |
|
89 | - $this->get = $get; |
|
90 | - $this->post = $post; |
|
91 | - $this->cookie = $cookie; |
|
92 | - $this->server = $server; |
|
93 | - $this->request = array_merge($this->get, $this->post); |
|
94 | - $this->ip_address = $this->visitorIp(); |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * @param RequestTypeContextCheckerInterface $type |
|
100 | - */ |
|
101 | - public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type) |
|
102 | - { |
|
103 | - $this->request_type = $type; |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * @return array |
|
109 | - */ |
|
110 | - public function getParams() |
|
111 | - { |
|
112 | - return $this->get; |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * @return array |
|
118 | - */ |
|
119 | - public function postParams() |
|
120 | - { |
|
121 | - return $this->post; |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * @return array |
|
127 | - */ |
|
128 | - public function cookieParams() |
|
129 | - { |
|
130 | - return $this->cookie; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * @return array |
|
136 | - */ |
|
137 | - public function serverParams() |
|
138 | - { |
|
139 | - return $this->server; |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * returns contents of $_REQUEST |
|
145 | - * |
|
146 | - * @return array |
|
147 | - */ |
|
148 | - public function requestParams() |
|
149 | - { |
|
150 | - return $this->request; |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * @param $key |
|
156 | - * @param $value |
|
157 | - * @param bool $override_ee |
|
158 | - * @return void |
|
159 | - */ |
|
160 | - public function setRequestParam($key, $value, $override_ee = false) |
|
161 | - { |
|
162 | - // don't allow "ee" to be overwritten unless explicitly instructed to do so |
|
163 | - if ($key !== 'ee' |
|
164 | - || ($key === 'ee' && empty($this->request['ee'])) |
|
165 | - || ($key === 'ee' && ! empty($this->request['ee']) && $override_ee) |
|
166 | - ) { |
|
167 | - $this->request[ $key ] = $value; |
|
168 | - } |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * returns the value for a request param if the given key exists |
|
174 | - * |
|
175 | - * @param $key |
|
176 | - * @param null $default |
|
177 | - * @return mixed |
|
178 | - */ |
|
179 | - public function getRequestParam($key, $default = null) |
|
180 | - { |
|
181 | - return $this->requestParameterDrillDown($key, $default, 'get'); |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * check if param exists |
|
187 | - * |
|
188 | - * @param $key |
|
189 | - * @return bool |
|
190 | - */ |
|
191 | - public function requestParamIsSet($key) |
|
192 | - { |
|
193 | - return $this->requestParameterDrillDown($key); |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
199 | - * and return the value for the first match found |
|
200 | - * wildcards can be either of the following: |
|
201 | - * ? to represent a single character of any type |
|
202 | - * * to represent one or more characters of any type |
|
203 | - * |
|
204 | - * @param string $pattern |
|
205 | - * @param null|mixed $default |
|
206 | - * @return false|int |
|
207 | - */ |
|
208 | - public function getMatch($pattern, $default = null) |
|
209 | - { |
|
210 | - return $this->requestParameterDrillDown($pattern, $default, 'match'); |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
216 | - * wildcards can be either of the following: |
|
217 | - * ? to represent a single character of any type |
|
218 | - * * to represent one or more characters of any type |
|
219 | - * returns true if a match is found or false if not |
|
220 | - * |
|
221 | - * @param string $pattern |
|
222 | - * @return false|int |
|
223 | - */ |
|
224 | - public function matches($pattern) |
|
225 | - { |
|
226 | - return $this->requestParameterDrillDown($pattern, null, 'match') !== null; |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard |
|
232 | - * @param string $pattern A string including wildcards to be converted to a regex pattern |
|
233 | - * and used to search through the current request's parameter keys |
|
234 | - * @param array $request_params The array of request parameters to search through |
|
235 | - * @param mixed $default [optional] The value to be returned if no match is found. |
|
236 | - * Default is null |
|
237 | - * @param string $return [optional] Controls what kind of value is returned. |
|
238 | - * Options are: |
|
239 | - * 'bool' will return true or false if match is found or not |
|
240 | - * 'key' will return the first key found that matches the supplied pattern |
|
241 | - * 'value' will return the value for the first request parameter |
|
242 | - * whose key matches the supplied pattern |
|
243 | - * Default is 'value' |
|
244 | - * @return boolean|string |
|
245 | - */ |
|
246 | - private function match($pattern, array $request_params, $default = null, $return = 'value') |
|
247 | - { |
|
248 | - $return = in_array($return, array('bool', 'key', 'value'), true) |
|
249 | - ? $return |
|
250 | - : 'is_set'; |
|
251 | - // replace wildcard chars with regex chars |
|
252 | - $pattern = str_replace( |
|
253 | - array("\*", "\?"), |
|
254 | - array('.*', '.'), |
|
255 | - preg_quote($pattern, '/') |
|
256 | - ); |
|
257 | - foreach ($request_params as $key => $request_param) { |
|
258 | - if (preg_match('/^' . $pattern . '$/is', $key)) { |
|
259 | - // return value for request param |
|
260 | - if ($return === 'value') { |
|
261 | - return $request_params[ $key ]; |
|
262 | - } |
|
263 | - // or actual key or true just to indicate it was found |
|
264 | - return $return === 'key' ? $key : true; |
|
265 | - } |
|
266 | - } |
|
267 | - // match not found so return default value or false |
|
268 | - return $return === 'value' ? $default : false; |
|
269 | - } |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * the supplied key can be a simple string to represent a "top-level" request parameter |
|
274 | - * or represent a key for a request parameter that is nested deeper within the request parameter array, |
|
275 | - * by using square brackets to surround keys for deeper array elements. |
|
276 | - * For example : |
|
277 | - * if the supplied $key was: "first[second][third]" |
|
278 | - * then this will attempt to drill down into the request parameter array to find a value. |
|
279 | - * Given the following request parameters: |
|
280 | - * array( |
|
281 | - * 'first' => array( |
|
282 | - * 'second' => array( |
|
283 | - * 'third' => 'has a value' |
|
284 | - * ) |
|
285 | - * ) |
|
286 | - * ) |
|
287 | - * would return true if default parameters were set |
|
288 | - * |
|
289 | - * @param string $callback |
|
290 | - * @param $key |
|
291 | - * @param null $default |
|
292 | - * @param array $request_params |
|
293 | - * @return bool|mixed|null |
|
294 | - */ |
|
295 | - private function requestParameterDrillDown( |
|
296 | - $key, |
|
297 | - $default = null, |
|
298 | - $callback = 'is_set', |
|
299 | - array $request_params = array() |
|
300 | - ) { |
|
301 | - $callback = in_array($callback, array('is_set', 'get', 'match'), true) |
|
302 | - ? $callback |
|
303 | - : 'is_set'; |
|
304 | - $request_params = ! empty($request_params) |
|
305 | - ? $request_params |
|
306 | - : $this->request; |
|
307 | - // does incoming key represent an array like 'first[second][third]' ? |
|
308 | - if (strpos($key, '[') !== false) { |
|
309 | - // turn it into an actual array |
|
310 | - $key = str_replace(']', '', $key); |
|
311 | - $keys = explode('[', $key); |
|
312 | - $key = array_shift($keys); |
|
313 | - if ($callback === 'match') { |
|
314 | - $real_key = $this->match($key, $request_params, $default, 'key'); |
|
315 | - $key = $real_key ? $real_key : $key; |
|
316 | - } |
|
317 | - // check if top level key exists |
|
318 | - if (isset($request_params[ $key ])) { |
|
319 | - // build a new key to pass along like: 'second[third]' |
|
320 | - // or just 'second' depending on depth of keys |
|
321 | - $key_string = array_shift($keys); |
|
322 | - if (! empty($keys)) { |
|
323 | - $key_string .= '[' . implode('][', $keys) . ']'; |
|
324 | - } |
|
325 | - return $this->requestParameterDrillDown( |
|
326 | - $key_string, |
|
327 | - $default, |
|
328 | - $callback, |
|
329 | - $request_params[ $key ] |
|
330 | - ); |
|
331 | - } |
|
332 | - } |
|
333 | - if ($callback === 'is_set') { |
|
334 | - return isset($request_params[ $key ]); |
|
335 | - } |
|
336 | - if ($callback === 'match') { |
|
337 | - return $this->match($key, $request_params, $default); |
|
338 | - } |
|
339 | - return isset($request_params[ $key ]) |
|
340 | - ? $request_params[ $key ] |
|
341 | - : $default; |
|
342 | - } |
|
343 | - |
|
344 | - |
|
345 | - /** |
|
346 | - * remove param |
|
347 | - * |
|
348 | - * @param $key |
|
349 | - * @param bool $unset_from_global_too |
|
350 | - */ |
|
351 | - public function unSetRequestParam($key, $unset_from_global_too = false) |
|
352 | - { |
|
353 | - unset($this->request[ $key ]); |
|
354 | - if ($unset_from_global_too) { |
|
355 | - unset($_REQUEST[ $key ]); |
|
356 | - } |
|
357 | - } |
|
358 | - |
|
359 | - |
|
360 | - /** |
|
361 | - * @return string |
|
362 | - */ |
|
363 | - public function ipAddress() |
|
364 | - { |
|
365 | - return $this->ip_address; |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - /** |
|
370 | - * attempt to get IP address of current visitor from server |
|
371 | - * plz see: http://stackoverflow.com/a/2031935/1475279 |
|
372 | - * |
|
373 | - * @access public |
|
374 | - * @return string |
|
375 | - */ |
|
376 | - private function visitorIp() |
|
377 | - { |
|
378 | - $visitor_ip = '0.0.0.0'; |
|
379 | - $server_keys = array( |
|
380 | - 'HTTP_CLIENT_IP', |
|
381 | - 'HTTP_X_FORWARDED_FOR', |
|
382 | - 'HTTP_X_FORWARDED', |
|
383 | - 'HTTP_X_CLUSTER_CLIENT_IP', |
|
384 | - 'HTTP_FORWARDED_FOR', |
|
385 | - 'HTTP_FORWARDED', |
|
386 | - 'REMOTE_ADDR', |
|
387 | - ); |
|
388 | - foreach ($server_keys as $key) { |
|
389 | - if (isset($this->server[ $key ])) { |
|
390 | - foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) { |
|
391 | - if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) { |
|
392 | - $visitor_ip = $ip; |
|
393 | - } |
|
394 | - } |
|
395 | - } |
|
396 | - } |
|
397 | - return $visitor_ip; |
|
398 | - } |
|
399 | - |
|
400 | - |
|
401 | - /** |
|
402 | - * @return string |
|
403 | - */ |
|
404 | - public function requestUri() |
|
405 | - { |
|
406 | - $request_uri = filter_input( |
|
407 | - INPUT_SERVER, |
|
408 | - 'REQUEST_URI', |
|
409 | - FILTER_SANITIZE_URL, |
|
410 | - FILTER_NULL_ON_FAILURE |
|
411 | - ); |
|
412 | - if (empty($request_uri)) { |
|
413 | - // fallback sanitization if the above fails |
|
414 | - $request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']); |
|
415 | - } |
|
416 | - return $request_uri; |
|
417 | - } |
|
418 | - |
|
419 | - |
|
420 | - /** |
|
421 | - * @return string |
|
422 | - */ |
|
423 | - public function userAgent() |
|
424 | - { |
|
425 | - return $this->user_agent; |
|
426 | - } |
|
427 | - |
|
428 | - |
|
429 | - /** |
|
430 | - * @param string $user_agent |
|
431 | - */ |
|
432 | - public function setUserAgent($user_agent = '') |
|
433 | - { |
|
434 | - if ($user_agent === '' || ! is_string($user_agent)) { |
|
435 | - $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : ''; |
|
436 | - } |
|
437 | - $this->user_agent = $user_agent; |
|
438 | - } |
|
439 | - |
|
440 | - |
|
441 | - /** |
|
442 | - * @return bool |
|
443 | - */ |
|
444 | - public function isBot() |
|
445 | - { |
|
446 | - return $this->is_bot; |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - /** |
|
451 | - * @param bool $is_bot |
|
452 | - */ |
|
453 | - public function setIsBot($is_bot) |
|
454 | - { |
|
455 | - $this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN); |
|
456 | - } |
|
457 | - |
|
458 | - |
|
459 | - /** |
|
460 | - * @return bool |
|
461 | - */ |
|
462 | - public function isActivation() |
|
463 | - { |
|
464 | - return $this->request_type->isActivation(); |
|
465 | - } |
|
466 | - |
|
467 | - |
|
468 | - /** |
|
469 | - * @param $is_activation |
|
470 | - * @return bool |
|
471 | - */ |
|
472 | - public function setIsActivation($is_activation) |
|
473 | - { |
|
474 | - return $this->request_type->setIsActivation($is_activation); |
|
475 | - } |
|
476 | - |
|
477 | - |
|
478 | - /** |
|
479 | - * @return bool |
|
480 | - */ |
|
481 | - public function isAdmin() |
|
482 | - { |
|
483 | - return $this->request_type->isAdmin(); |
|
484 | - } |
|
485 | - |
|
486 | - |
|
487 | - /** |
|
488 | - * @return bool |
|
489 | - */ |
|
490 | - public function isAdminAjax() |
|
491 | - { |
|
492 | - return $this->request_type->isAdminAjax(); |
|
493 | - } |
|
494 | - |
|
495 | - |
|
496 | - /** |
|
497 | - * @return bool |
|
498 | - */ |
|
499 | - public function isAjax() |
|
500 | - { |
|
501 | - return $this->request_type->isAjax(); |
|
502 | - } |
|
503 | - |
|
504 | - |
|
505 | - /** |
|
506 | - * @return bool |
|
507 | - */ |
|
508 | - public function isEeAjax() |
|
509 | - { |
|
510 | - return $this->request_type->isEeAjax(); |
|
511 | - } |
|
512 | - |
|
513 | - |
|
514 | - /** |
|
515 | - * @return bool |
|
516 | - */ |
|
517 | - public function isOtherAjax() |
|
518 | - { |
|
519 | - return $this->request_type->isOtherAjax(); |
|
520 | - } |
|
521 | - |
|
522 | - |
|
523 | - /** |
|
524 | - * @return bool |
|
525 | - */ |
|
526 | - public function isApi() |
|
527 | - { |
|
528 | - return $this->request_type->isApi(); |
|
529 | - } |
|
530 | - |
|
531 | - |
|
532 | - /** |
|
533 | - * @return bool |
|
534 | - */ |
|
535 | - public function isCli() |
|
536 | - { |
|
537 | - return $this->request_type->isCli(); |
|
538 | - } |
|
539 | - |
|
540 | - |
|
541 | - /** |
|
542 | - * @return bool |
|
543 | - */ |
|
544 | - public function isCron() |
|
545 | - { |
|
546 | - return $this->request_type->isCron(); |
|
547 | - } |
|
548 | - |
|
549 | - |
|
550 | - /** |
|
551 | - * @return bool |
|
552 | - */ |
|
553 | - public function isFeed() |
|
554 | - { |
|
555 | - return $this->request_type->isFeed(); |
|
556 | - } |
|
557 | - |
|
558 | - |
|
559 | - /** |
|
560 | - * @return bool |
|
561 | - */ |
|
562 | - public function isFrontend() |
|
563 | - { |
|
564 | - return $this->request_type->isFrontend(); |
|
565 | - } |
|
566 | - |
|
567 | - |
|
568 | - /** |
|
569 | - * @return bool |
|
570 | - */ |
|
571 | - public function isFrontAjax() |
|
572 | - { |
|
573 | - return $this->request_type->isFrontAjax(); |
|
574 | - } |
|
575 | - |
|
576 | - |
|
577 | - /** |
|
578 | - * @return bool |
|
579 | - */ |
|
580 | - public function isIframe() |
|
581 | - { |
|
582 | - return $this->request_type->isIframe(); |
|
583 | - } |
|
584 | - |
|
585 | - |
|
586 | - /** |
|
587 | - * @return bool |
|
588 | - */ |
|
589 | - public function isWordPressScrape() |
|
590 | - { |
|
591 | - return $this->request_type->isWordPressScrape(); |
|
592 | - } |
|
593 | - |
|
594 | - |
|
595 | - /** |
|
596 | - * @return string |
|
597 | - */ |
|
598 | - public function slug() |
|
599 | - { |
|
600 | - return $this->request_type->slug(); |
|
601 | - } |
|
20 | + /** |
|
21 | + * $_GET parameters |
|
22 | + * |
|
23 | + * @var array $get |
|
24 | + */ |
|
25 | + private $get; |
|
26 | + |
|
27 | + /** |
|
28 | + * $_POST parameters |
|
29 | + * |
|
30 | + * @var array $post |
|
31 | + */ |
|
32 | + private $post; |
|
33 | + |
|
34 | + /** |
|
35 | + * $_COOKIE parameters |
|
36 | + * |
|
37 | + * @var array $cookie |
|
38 | + */ |
|
39 | + private $cookie; |
|
40 | + |
|
41 | + /** |
|
42 | + * $_SERVER parameters |
|
43 | + * |
|
44 | + * @var array $server |
|
45 | + */ |
|
46 | + private $server; |
|
47 | + |
|
48 | + /** |
|
49 | + * $_REQUEST parameters |
|
50 | + * |
|
51 | + * @var array $request |
|
52 | + */ |
|
53 | + private $request; |
|
54 | + |
|
55 | + /** |
|
56 | + * @var RequestTypeContextCheckerInterface |
|
57 | + */ |
|
58 | + private $request_type; |
|
59 | + |
|
60 | + /** |
|
61 | + * IP address for request |
|
62 | + * |
|
63 | + * @var string $ip_address |
|
64 | + */ |
|
65 | + private $ip_address; |
|
66 | + |
|
67 | + /** |
|
68 | + * @var string $user_agent |
|
69 | + */ |
|
70 | + private $user_agent; |
|
71 | + |
|
72 | + /** |
|
73 | + * true if current user appears to be some kind of bot |
|
74 | + * |
|
75 | + * @var bool $is_bot |
|
76 | + */ |
|
77 | + private $is_bot; |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * @param array $get |
|
82 | + * @param array $post |
|
83 | + * @param array $cookie |
|
84 | + * @param array $server |
|
85 | + */ |
|
86 | + public function __construct(array $get, array $post, array $cookie, array $server) |
|
87 | + { |
|
88 | + // grab request vars |
|
89 | + $this->get = $get; |
|
90 | + $this->post = $post; |
|
91 | + $this->cookie = $cookie; |
|
92 | + $this->server = $server; |
|
93 | + $this->request = array_merge($this->get, $this->post); |
|
94 | + $this->ip_address = $this->visitorIp(); |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * @param RequestTypeContextCheckerInterface $type |
|
100 | + */ |
|
101 | + public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type) |
|
102 | + { |
|
103 | + $this->request_type = $type; |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * @return array |
|
109 | + */ |
|
110 | + public function getParams() |
|
111 | + { |
|
112 | + return $this->get; |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * @return array |
|
118 | + */ |
|
119 | + public function postParams() |
|
120 | + { |
|
121 | + return $this->post; |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * @return array |
|
127 | + */ |
|
128 | + public function cookieParams() |
|
129 | + { |
|
130 | + return $this->cookie; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * @return array |
|
136 | + */ |
|
137 | + public function serverParams() |
|
138 | + { |
|
139 | + return $this->server; |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * returns contents of $_REQUEST |
|
145 | + * |
|
146 | + * @return array |
|
147 | + */ |
|
148 | + public function requestParams() |
|
149 | + { |
|
150 | + return $this->request; |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * @param $key |
|
156 | + * @param $value |
|
157 | + * @param bool $override_ee |
|
158 | + * @return void |
|
159 | + */ |
|
160 | + public function setRequestParam($key, $value, $override_ee = false) |
|
161 | + { |
|
162 | + // don't allow "ee" to be overwritten unless explicitly instructed to do so |
|
163 | + if ($key !== 'ee' |
|
164 | + || ($key === 'ee' && empty($this->request['ee'])) |
|
165 | + || ($key === 'ee' && ! empty($this->request['ee']) && $override_ee) |
|
166 | + ) { |
|
167 | + $this->request[ $key ] = $value; |
|
168 | + } |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * returns the value for a request param if the given key exists |
|
174 | + * |
|
175 | + * @param $key |
|
176 | + * @param null $default |
|
177 | + * @return mixed |
|
178 | + */ |
|
179 | + public function getRequestParam($key, $default = null) |
|
180 | + { |
|
181 | + return $this->requestParameterDrillDown($key, $default, 'get'); |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * check if param exists |
|
187 | + * |
|
188 | + * @param $key |
|
189 | + * @return bool |
|
190 | + */ |
|
191 | + public function requestParamIsSet($key) |
|
192 | + { |
|
193 | + return $this->requestParameterDrillDown($key); |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
199 | + * and return the value for the first match found |
|
200 | + * wildcards can be either of the following: |
|
201 | + * ? to represent a single character of any type |
|
202 | + * * to represent one or more characters of any type |
|
203 | + * |
|
204 | + * @param string $pattern |
|
205 | + * @param null|mixed $default |
|
206 | + * @return false|int |
|
207 | + */ |
|
208 | + public function getMatch($pattern, $default = null) |
|
209 | + { |
|
210 | + return $this->requestParameterDrillDown($pattern, $default, 'match'); |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
216 | + * wildcards can be either of the following: |
|
217 | + * ? to represent a single character of any type |
|
218 | + * * to represent one or more characters of any type |
|
219 | + * returns true if a match is found or false if not |
|
220 | + * |
|
221 | + * @param string $pattern |
|
222 | + * @return false|int |
|
223 | + */ |
|
224 | + public function matches($pattern) |
|
225 | + { |
|
226 | + return $this->requestParameterDrillDown($pattern, null, 'match') !== null; |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard |
|
232 | + * @param string $pattern A string including wildcards to be converted to a regex pattern |
|
233 | + * and used to search through the current request's parameter keys |
|
234 | + * @param array $request_params The array of request parameters to search through |
|
235 | + * @param mixed $default [optional] The value to be returned if no match is found. |
|
236 | + * Default is null |
|
237 | + * @param string $return [optional] Controls what kind of value is returned. |
|
238 | + * Options are: |
|
239 | + * 'bool' will return true or false if match is found or not |
|
240 | + * 'key' will return the first key found that matches the supplied pattern |
|
241 | + * 'value' will return the value for the first request parameter |
|
242 | + * whose key matches the supplied pattern |
|
243 | + * Default is 'value' |
|
244 | + * @return boolean|string |
|
245 | + */ |
|
246 | + private function match($pattern, array $request_params, $default = null, $return = 'value') |
|
247 | + { |
|
248 | + $return = in_array($return, array('bool', 'key', 'value'), true) |
|
249 | + ? $return |
|
250 | + : 'is_set'; |
|
251 | + // replace wildcard chars with regex chars |
|
252 | + $pattern = str_replace( |
|
253 | + array("\*", "\?"), |
|
254 | + array('.*', '.'), |
|
255 | + preg_quote($pattern, '/') |
|
256 | + ); |
|
257 | + foreach ($request_params as $key => $request_param) { |
|
258 | + if (preg_match('/^' . $pattern . '$/is', $key)) { |
|
259 | + // return value for request param |
|
260 | + if ($return === 'value') { |
|
261 | + return $request_params[ $key ]; |
|
262 | + } |
|
263 | + // or actual key or true just to indicate it was found |
|
264 | + return $return === 'key' ? $key : true; |
|
265 | + } |
|
266 | + } |
|
267 | + // match not found so return default value or false |
|
268 | + return $return === 'value' ? $default : false; |
|
269 | + } |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * the supplied key can be a simple string to represent a "top-level" request parameter |
|
274 | + * or represent a key for a request parameter that is nested deeper within the request parameter array, |
|
275 | + * by using square brackets to surround keys for deeper array elements. |
|
276 | + * For example : |
|
277 | + * if the supplied $key was: "first[second][third]" |
|
278 | + * then this will attempt to drill down into the request parameter array to find a value. |
|
279 | + * Given the following request parameters: |
|
280 | + * array( |
|
281 | + * 'first' => array( |
|
282 | + * 'second' => array( |
|
283 | + * 'third' => 'has a value' |
|
284 | + * ) |
|
285 | + * ) |
|
286 | + * ) |
|
287 | + * would return true if default parameters were set |
|
288 | + * |
|
289 | + * @param string $callback |
|
290 | + * @param $key |
|
291 | + * @param null $default |
|
292 | + * @param array $request_params |
|
293 | + * @return bool|mixed|null |
|
294 | + */ |
|
295 | + private function requestParameterDrillDown( |
|
296 | + $key, |
|
297 | + $default = null, |
|
298 | + $callback = 'is_set', |
|
299 | + array $request_params = array() |
|
300 | + ) { |
|
301 | + $callback = in_array($callback, array('is_set', 'get', 'match'), true) |
|
302 | + ? $callback |
|
303 | + : 'is_set'; |
|
304 | + $request_params = ! empty($request_params) |
|
305 | + ? $request_params |
|
306 | + : $this->request; |
|
307 | + // does incoming key represent an array like 'first[second][third]' ? |
|
308 | + if (strpos($key, '[') !== false) { |
|
309 | + // turn it into an actual array |
|
310 | + $key = str_replace(']', '', $key); |
|
311 | + $keys = explode('[', $key); |
|
312 | + $key = array_shift($keys); |
|
313 | + if ($callback === 'match') { |
|
314 | + $real_key = $this->match($key, $request_params, $default, 'key'); |
|
315 | + $key = $real_key ? $real_key : $key; |
|
316 | + } |
|
317 | + // check if top level key exists |
|
318 | + if (isset($request_params[ $key ])) { |
|
319 | + // build a new key to pass along like: 'second[third]' |
|
320 | + // or just 'second' depending on depth of keys |
|
321 | + $key_string = array_shift($keys); |
|
322 | + if (! empty($keys)) { |
|
323 | + $key_string .= '[' . implode('][', $keys) . ']'; |
|
324 | + } |
|
325 | + return $this->requestParameterDrillDown( |
|
326 | + $key_string, |
|
327 | + $default, |
|
328 | + $callback, |
|
329 | + $request_params[ $key ] |
|
330 | + ); |
|
331 | + } |
|
332 | + } |
|
333 | + if ($callback === 'is_set') { |
|
334 | + return isset($request_params[ $key ]); |
|
335 | + } |
|
336 | + if ($callback === 'match') { |
|
337 | + return $this->match($key, $request_params, $default); |
|
338 | + } |
|
339 | + return isset($request_params[ $key ]) |
|
340 | + ? $request_params[ $key ] |
|
341 | + : $default; |
|
342 | + } |
|
343 | + |
|
344 | + |
|
345 | + /** |
|
346 | + * remove param |
|
347 | + * |
|
348 | + * @param $key |
|
349 | + * @param bool $unset_from_global_too |
|
350 | + */ |
|
351 | + public function unSetRequestParam($key, $unset_from_global_too = false) |
|
352 | + { |
|
353 | + unset($this->request[ $key ]); |
|
354 | + if ($unset_from_global_too) { |
|
355 | + unset($_REQUEST[ $key ]); |
|
356 | + } |
|
357 | + } |
|
358 | + |
|
359 | + |
|
360 | + /** |
|
361 | + * @return string |
|
362 | + */ |
|
363 | + public function ipAddress() |
|
364 | + { |
|
365 | + return $this->ip_address; |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + /** |
|
370 | + * attempt to get IP address of current visitor from server |
|
371 | + * plz see: http://stackoverflow.com/a/2031935/1475279 |
|
372 | + * |
|
373 | + * @access public |
|
374 | + * @return string |
|
375 | + */ |
|
376 | + private function visitorIp() |
|
377 | + { |
|
378 | + $visitor_ip = '0.0.0.0'; |
|
379 | + $server_keys = array( |
|
380 | + 'HTTP_CLIENT_IP', |
|
381 | + 'HTTP_X_FORWARDED_FOR', |
|
382 | + 'HTTP_X_FORWARDED', |
|
383 | + 'HTTP_X_CLUSTER_CLIENT_IP', |
|
384 | + 'HTTP_FORWARDED_FOR', |
|
385 | + 'HTTP_FORWARDED', |
|
386 | + 'REMOTE_ADDR', |
|
387 | + ); |
|
388 | + foreach ($server_keys as $key) { |
|
389 | + if (isset($this->server[ $key ])) { |
|
390 | + foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) { |
|
391 | + if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) { |
|
392 | + $visitor_ip = $ip; |
|
393 | + } |
|
394 | + } |
|
395 | + } |
|
396 | + } |
|
397 | + return $visitor_ip; |
|
398 | + } |
|
399 | + |
|
400 | + |
|
401 | + /** |
|
402 | + * @return string |
|
403 | + */ |
|
404 | + public function requestUri() |
|
405 | + { |
|
406 | + $request_uri = filter_input( |
|
407 | + INPUT_SERVER, |
|
408 | + 'REQUEST_URI', |
|
409 | + FILTER_SANITIZE_URL, |
|
410 | + FILTER_NULL_ON_FAILURE |
|
411 | + ); |
|
412 | + if (empty($request_uri)) { |
|
413 | + // fallback sanitization if the above fails |
|
414 | + $request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']); |
|
415 | + } |
|
416 | + return $request_uri; |
|
417 | + } |
|
418 | + |
|
419 | + |
|
420 | + /** |
|
421 | + * @return string |
|
422 | + */ |
|
423 | + public function userAgent() |
|
424 | + { |
|
425 | + return $this->user_agent; |
|
426 | + } |
|
427 | + |
|
428 | + |
|
429 | + /** |
|
430 | + * @param string $user_agent |
|
431 | + */ |
|
432 | + public function setUserAgent($user_agent = '') |
|
433 | + { |
|
434 | + if ($user_agent === '' || ! is_string($user_agent)) { |
|
435 | + $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : ''; |
|
436 | + } |
|
437 | + $this->user_agent = $user_agent; |
|
438 | + } |
|
439 | + |
|
440 | + |
|
441 | + /** |
|
442 | + * @return bool |
|
443 | + */ |
|
444 | + public function isBot() |
|
445 | + { |
|
446 | + return $this->is_bot; |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + /** |
|
451 | + * @param bool $is_bot |
|
452 | + */ |
|
453 | + public function setIsBot($is_bot) |
|
454 | + { |
|
455 | + $this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN); |
|
456 | + } |
|
457 | + |
|
458 | + |
|
459 | + /** |
|
460 | + * @return bool |
|
461 | + */ |
|
462 | + public function isActivation() |
|
463 | + { |
|
464 | + return $this->request_type->isActivation(); |
|
465 | + } |
|
466 | + |
|
467 | + |
|
468 | + /** |
|
469 | + * @param $is_activation |
|
470 | + * @return bool |
|
471 | + */ |
|
472 | + public function setIsActivation($is_activation) |
|
473 | + { |
|
474 | + return $this->request_type->setIsActivation($is_activation); |
|
475 | + } |
|
476 | + |
|
477 | + |
|
478 | + /** |
|
479 | + * @return bool |
|
480 | + */ |
|
481 | + public function isAdmin() |
|
482 | + { |
|
483 | + return $this->request_type->isAdmin(); |
|
484 | + } |
|
485 | + |
|
486 | + |
|
487 | + /** |
|
488 | + * @return bool |
|
489 | + */ |
|
490 | + public function isAdminAjax() |
|
491 | + { |
|
492 | + return $this->request_type->isAdminAjax(); |
|
493 | + } |
|
494 | + |
|
495 | + |
|
496 | + /** |
|
497 | + * @return bool |
|
498 | + */ |
|
499 | + public function isAjax() |
|
500 | + { |
|
501 | + return $this->request_type->isAjax(); |
|
502 | + } |
|
503 | + |
|
504 | + |
|
505 | + /** |
|
506 | + * @return bool |
|
507 | + */ |
|
508 | + public function isEeAjax() |
|
509 | + { |
|
510 | + return $this->request_type->isEeAjax(); |
|
511 | + } |
|
512 | + |
|
513 | + |
|
514 | + /** |
|
515 | + * @return bool |
|
516 | + */ |
|
517 | + public function isOtherAjax() |
|
518 | + { |
|
519 | + return $this->request_type->isOtherAjax(); |
|
520 | + } |
|
521 | + |
|
522 | + |
|
523 | + /** |
|
524 | + * @return bool |
|
525 | + */ |
|
526 | + public function isApi() |
|
527 | + { |
|
528 | + return $this->request_type->isApi(); |
|
529 | + } |
|
530 | + |
|
531 | + |
|
532 | + /** |
|
533 | + * @return bool |
|
534 | + */ |
|
535 | + public function isCli() |
|
536 | + { |
|
537 | + return $this->request_type->isCli(); |
|
538 | + } |
|
539 | + |
|
540 | + |
|
541 | + /** |
|
542 | + * @return bool |
|
543 | + */ |
|
544 | + public function isCron() |
|
545 | + { |
|
546 | + return $this->request_type->isCron(); |
|
547 | + } |
|
548 | + |
|
549 | + |
|
550 | + /** |
|
551 | + * @return bool |
|
552 | + */ |
|
553 | + public function isFeed() |
|
554 | + { |
|
555 | + return $this->request_type->isFeed(); |
|
556 | + } |
|
557 | + |
|
558 | + |
|
559 | + /** |
|
560 | + * @return bool |
|
561 | + */ |
|
562 | + public function isFrontend() |
|
563 | + { |
|
564 | + return $this->request_type->isFrontend(); |
|
565 | + } |
|
566 | + |
|
567 | + |
|
568 | + /** |
|
569 | + * @return bool |
|
570 | + */ |
|
571 | + public function isFrontAjax() |
|
572 | + { |
|
573 | + return $this->request_type->isFrontAjax(); |
|
574 | + } |
|
575 | + |
|
576 | + |
|
577 | + /** |
|
578 | + * @return bool |
|
579 | + */ |
|
580 | + public function isIframe() |
|
581 | + { |
|
582 | + return $this->request_type->isIframe(); |
|
583 | + } |
|
584 | + |
|
585 | + |
|
586 | + /** |
|
587 | + * @return bool |
|
588 | + */ |
|
589 | + public function isWordPressScrape() |
|
590 | + { |
|
591 | + return $this->request_type->isWordPressScrape(); |
|
592 | + } |
|
593 | + |
|
594 | + |
|
595 | + /** |
|
596 | + * @return string |
|
597 | + */ |
|
598 | + public function slug() |
|
599 | + { |
|
600 | + return $this->request_type->slug(); |
|
601 | + } |
|
602 | 602 | } |
@@ -23,495 +23,495 @@ |
||
23 | 23 | */ |
24 | 24 | abstract class EE_Gateway |
25 | 25 | { |
26 | - /** |
|
27 | - * a constant used as a possible value for $_currencies_supported to indicate |
|
28 | - * that ALL currencies are supported by this gateway |
|
29 | - */ |
|
30 | - const all_currencies_supported = 'all_currencies_supported'; |
|
31 | - /** |
|
32 | - * Where values are 3-letter currency codes |
|
33 | - * |
|
34 | - * @var array |
|
35 | - */ |
|
36 | - protected $_currencies_supported = array(); |
|
37 | - /** |
|
38 | - * Whether or not this gateway can support SENDING a refund request (ie, initiated by |
|
39 | - * admin in EE's wp-admin page) |
|
40 | - * |
|
41 | - * @var boolean |
|
42 | - */ |
|
43 | - protected $_supports_sending_refunds = false; |
|
44 | - |
|
45 | - /** |
|
46 | - * Whether or not this gateway can support RECEIVING a refund request from the payment |
|
47 | - * provider (ie, initiated by admin on the payment prover's website who sends an IPN to EE) |
|
48 | - * |
|
49 | - * @var boolean |
|
50 | - */ |
|
51 | - protected $_supports_receiving_refunds = false; |
|
52 | - /** |
|
53 | - * Model for querying for existing payments |
|
54 | - * |
|
55 | - * @var EEMI_Payment |
|
56 | - */ |
|
57 | - protected $_pay_model; |
|
58 | - |
|
59 | - /** |
|
60 | - * Model used for adding to the payments log |
|
61 | - * |
|
62 | - * @var EEMI_Payment_Log |
|
63 | - */ |
|
64 | - protected $_pay_log; |
|
65 | - |
|
66 | - /** |
|
67 | - * Used for formatting some input to gateways |
|
68 | - * |
|
69 | - * @var EEHI_Template |
|
70 | - */ |
|
71 | - protected $_template; |
|
72 | - |
|
73 | - /** |
|
74 | - * Concrete class that implements EEHI_Money, used by most gateways |
|
75 | - * |
|
76 | - * @var EEHI_Money |
|
77 | - */ |
|
78 | - protected $_money; |
|
79 | - |
|
80 | - /** |
|
81 | - * Concrete class that implements EEHI_Line_Item, used for manipulating the line item tree |
|
82 | - * |
|
83 | - * @var EEHI_Line_Item |
|
84 | - */ |
|
85 | - protected $_line_item; |
|
86 | - |
|
87 | - /** |
|
88 | - * @var GatewayDataFormatterInterface |
|
89 | - */ |
|
90 | - protected $_gateway_data_formatter; |
|
91 | - |
|
92 | - /** |
|
93 | - * @var FormatterInterface |
|
94 | - */ |
|
95 | - protected $_unsupported_character_remover; |
|
96 | - |
|
97 | - /** |
|
98 | - * The ID of the payment method using this gateway |
|
99 | - * |
|
100 | - * @var int |
|
101 | - */ |
|
102 | - protected $_ID; |
|
103 | - |
|
104 | - /** |
|
105 | - * @var $_debug_mode boolean whether to send requests to teh sandbox site or not |
|
106 | - */ |
|
107 | - protected $_debug_mode; |
|
108 | - /** |
|
109 | - * |
|
110 | - * @var string $_name name to show for this payment method |
|
111 | - */ |
|
112 | - protected $_name; |
|
113 | - /** |
|
114 | - * |
|
115 | - * @var string name to show fir this payment method to admin-type users |
|
116 | - */ |
|
117 | - protected $_admin_name; |
|
118 | - |
|
119 | - /** |
|
120 | - * @return EE_Gateway |
|
121 | - */ |
|
122 | - public function __construct() |
|
123 | - { |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * We don't want to serialize models as they often have circular structures |
|
128 | - * (eg a payment model has a reference to each payment model object; and most |
|
129 | - * payments have a transaction, most transactions have a payment method; |
|
130 | - * most payment methods have a payment method type; most payment method types |
|
131 | - * have a gateway. And if a gateway serializes its models, we start at the |
|
132 | - * beginning again) |
|
133 | - * |
|
134 | - * @return array |
|
135 | - */ |
|
136 | - public function __sleep() |
|
137 | - { |
|
138 | - $properties = get_object_vars($this); |
|
139 | - unset($properties['_pay_model'], $properties['_pay_log']); |
|
140 | - return array_keys($properties); |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Returns whether or not this gateway should support SENDING refunds |
|
145 | - * see $_supports_sending_refunds |
|
146 | - * |
|
147 | - * @return boolean |
|
148 | - */ |
|
149 | - public function supports_sending_refunds() |
|
150 | - { |
|
151 | - return $this->_supports_sending_refunds; |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Returns whether or not this gateway should support RECEIVING refunds |
|
156 | - * see $_supports_receiving_refunds |
|
157 | - * |
|
158 | - * @return boolean |
|
159 | - */ |
|
160 | - public function supports_receiving_refunds() |
|
161 | - { |
|
162 | - return $this->_supports_receiving_refunds; |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * Tries to refund the payment specified, taking into account the extra |
|
168 | - * refund info. Note that if the gateway's _supports_sending_refunds is false, |
|
169 | - * this should just throw an exception. |
|
170 | - * |
|
171 | - * @param EE_Payment $payment |
|
172 | - * @param array $refund_info |
|
173 | - * @return EE_Payment for the refund |
|
174 | - * @throws EE_Error |
|
175 | - */ |
|
176 | - public function do_direct_refund(EE_Payment $payment, $refund_info = null) |
|
177 | - { |
|
178 | - return null; |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * Sets the payment method's settings so the gateway knows where to send the request |
|
184 | - * etc |
|
185 | - * |
|
186 | - * @param array $settings_array |
|
187 | - */ |
|
188 | - public function set_settings($settings_array) |
|
189 | - { |
|
190 | - foreach ($settings_array as $name => $value) { |
|
191 | - $property_name = "_" . $name; |
|
192 | - $this->{$property_name} = $value; |
|
193 | - } |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * See this class description |
|
198 | - * |
|
199 | - * @param EEMI_Payment $payment_model |
|
200 | - */ |
|
201 | - public function set_payment_model($payment_model) |
|
202 | - { |
|
203 | - $this->_pay_model = $payment_model; |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * See this class description |
|
208 | - * |
|
209 | - * @param EEMI_Payment_Log $payment_log_model |
|
210 | - */ |
|
211 | - public function set_payment_log($payment_log_model) |
|
212 | - { |
|
213 | - $this->_pay_log = $payment_log_model; |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * See this class description |
|
218 | - * |
|
219 | - * @param EEHI_Template $template_helper |
|
220 | - */ |
|
221 | - public function set_template_helper($template_helper) |
|
222 | - { |
|
223 | - $this->_template = $template_helper; |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * See this class description |
|
228 | - * |
|
229 | - * @param EEHI_Line_Item $line_item_helper |
|
230 | - */ |
|
231 | - public function set_line_item_helper($line_item_helper) |
|
232 | - { |
|
233 | - $this->_line_item = $line_item_helper; |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * See this class description |
|
238 | - * |
|
239 | - * @param EEHI_Money $money_helper |
|
240 | - */ |
|
241 | - public function set_money_helper($money_helper) |
|
242 | - { |
|
243 | - $this->_money = $money_helper; |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * Sets the gateway data formatter helper |
|
249 | - * |
|
250 | - * @param GatewayDataFormatterInterface $gateway_data_formatter |
|
251 | - * @throws InvalidEntityException if it's not set properly |
|
252 | - */ |
|
253 | - public function set_gateway_data_formatter(GatewayDataFormatterInterface $gateway_data_formatter) |
|
254 | - { |
|
255 | - if (! $gateway_data_formatter instanceof GatewayDataFormatterInterface) { |
|
256 | - throw new InvalidEntityException( |
|
257 | - is_object($gateway_data_formatter) |
|
258 | - ? get_class($gateway_data_formatter) |
|
259 | - : esc_html__('Not an object', 'event_espresso'), |
|
260 | - '\\EventEspresso\\core\\services\\payment_methods\\gateways\\GatewayDataFormatterInterface' |
|
261 | - ); |
|
262 | - } |
|
263 | - $this->_gateway_data_formatter = $gateway_data_formatter; |
|
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * Gets the gateway data formatter |
|
268 | - * |
|
269 | - * @return GatewayDataFormatterInterface |
|
270 | - * @throws InvalidEntityException if it's not set properly |
|
271 | - */ |
|
272 | - protected function _get_gateway_formatter() |
|
273 | - { |
|
274 | - if (! $this->_gateway_data_formatter instanceof GatewayDataFormatterInterface) { |
|
275 | - throw new InvalidEntityException( |
|
276 | - is_object($this->_gateway_data_formatter) |
|
277 | - ? get_class($this->_gateway_data_formatter) |
|
278 | - : esc_html__('Not an object', 'event_espresso'), |
|
279 | - '\\EventEspresso\\core\\services\\payment_methods\\gateways\\GatewayDataFormatterInterface' |
|
280 | - ); |
|
281 | - } |
|
282 | - return $this->_gateway_data_formatter; |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * Sets the helper which will remove unsupported characters for most gateways |
|
288 | - * |
|
289 | - * @param FormatterInterface $formatter |
|
290 | - * @return FormatterInterface |
|
291 | - * @throws InvalidEntityException |
|
292 | - */ |
|
293 | - public function set_unsupported_character_remover(FormatterInterface $formatter) |
|
294 | - { |
|
295 | - if (! $formatter instanceof FormatterInterface) { |
|
296 | - throw new InvalidEntityException( |
|
297 | - is_object($formatter) |
|
298 | - ? get_class($formatter) |
|
299 | - : esc_html__('Not an object', 'event_espresso'), |
|
300 | - '\\EventEspresso\\core\\services\\formatters\\FormatterInterface' |
|
301 | - ); |
|
302 | - } |
|
303 | - $this->_unsupported_character_remover = $formatter; |
|
304 | - } |
|
305 | - |
|
306 | - /** |
|
307 | - * Gets the helper which removes characters which gateways might not support, like emojis etc. |
|
308 | - * |
|
309 | - * @return FormatterInterface |
|
310 | - * @throws InvalidEntityException |
|
311 | - */ |
|
312 | - protected function _get_unsupported_character_remover() |
|
313 | - { |
|
314 | - if (! $this->_unsupported_character_remover instanceof FormatterInterface) { |
|
315 | - throw new InvalidEntityException( |
|
316 | - is_object($this->_unsupported_character_remover) |
|
317 | - ? get_class($this->_unsupported_character_remover) |
|
318 | - : esc_html__('Not an object', 'event_espresso'), |
|
319 | - '\\EventEspresso\\core\\services\\formatters\\FormatterInterface' |
|
320 | - ); |
|
321 | - } |
|
322 | - return $this->_unsupported_character_remover; |
|
323 | - } |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * @param $message |
|
328 | - * @param $payment |
|
329 | - */ |
|
330 | - public function log($message, $object_logged) |
|
331 | - { |
|
332 | - if ($object_logged instanceof EEI_Payment) { |
|
333 | - $type = 'Payment'; |
|
334 | - $id = $object_logged->ID(); |
|
335 | - } elseif ($object_logged instanceof EEI_Transaction) { |
|
336 | - $type = 'Transaction'; |
|
337 | - $id = $object_logged->ID(); |
|
338 | - } else { |
|
339 | - $type = 'Payment_Method'; |
|
340 | - $id = $this->_ID; |
|
341 | - } |
|
342 | - // only log if we're going to store it for longer than the minimum time |
|
343 | - $reg_config = LoaderFactory::getLoader()->load('EE_Registration_Config'); |
|
344 | - if ($reg_config->gateway_log_lifespan !== '1 second') { |
|
345 | - $this->_pay_log->gateway_log($message, $id, $type); |
|
346 | - } |
|
347 | - } |
|
348 | - |
|
349 | - /** |
|
350 | - * Formats the amount so it can generally be sent to gateways |
|
351 | - * |
|
352 | - * @param float $amount |
|
353 | - * @return string |
|
354 | - * @deprecated since 4.9.31 insetad use |
|
355 | - * EventEspresso\core\services\payment_methods\gateways\GatewayDataFormatter::format_currency() |
|
356 | - */ |
|
357 | - public function format_currency($amount) |
|
358 | - { |
|
359 | - return $this->_get_gateway_formatter()->formatCurrency($amount); |
|
360 | - } |
|
361 | - |
|
362 | - /** |
|
363 | - * Returns either an array of all the currency codes supported, |
|
364 | - * or a string indicating they're all supported (EE_gateway::all_currencies_supported) |
|
365 | - * |
|
366 | - * @return mixed array or string |
|
367 | - */ |
|
368 | - public function currencies_supported() |
|
369 | - { |
|
370 | - return $this->_currencies_supported; |
|
371 | - } |
|
372 | - |
|
373 | - /** |
|
374 | - * Returns what a simple summing of items and taxes for this transaction. This |
|
375 | - * can be used to determine if some more complex line items, like promotions, |
|
376 | - * surcharges, or cancellations occurred (in which case we might want to forget |
|
377 | - * about creating an itemized list of purchases and instead only send the total due) |
|
378 | - * |
|
379 | - * @param EE_Transaction $transaction |
|
380 | - * @return float |
|
381 | - */ |
|
382 | - protected function _sum_items_and_taxes(EE_Transaction $transaction) |
|
383 | - { |
|
384 | - $total_line_item = $transaction->total_line_item(); |
|
385 | - $total = 0; |
|
386 | - foreach ($total_line_item->get_items() as $item_line_item) { |
|
387 | - $total += max($item_line_item->total(), 0); |
|
388 | - } |
|
389 | - foreach ($total_line_item->tax_descendants() as $tax_line_item) { |
|
390 | - $total += max($tax_line_item->total(), 0); |
|
391 | - } |
|
392 | - return $total; |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
396 | - * Determines whether or not we can easily itemize the transaction using only |
|
397 | - * items and taxes (ie, no promotions or surcharges or cancellations needed) |
|
398 | - * |
|
399 | - * @param EEI_Payment $payment |
|
400 | - * @return boolean |
|
401 | - */ |
|
402 | - protected function _can_easily_itemize_transaction_for(EEI_Payment $payment) |
|
403 | - { |
|
404 | - return $this->_money->compare_floats( |
|
405 | - $this->_sum_items_and_taxes($payment->transaction()), |
|
406 | - $payment->transaction()->total() |
|
407 | - ) |
|
408 | - && $this->_money->compare_floats( |
|
409 | - $payment->amount(), |
|
410 | - $payment->transaction()->total() |
|
411 | - ); |
|
412 | - } |
|
413 | - |
|
414 | - /** |
|
415 | - * Handles updating the transaction and any other related data based on the payment. |
|
416 | - * You may be tempted to do this as part of do_direct_payment or handle_payment_update, |
|
417 | - * but doing so on those functions might be too early. It's possible that the changes |
|
418 | - * you make to teh transaction or registration or line items may just get overwritten |
|
419 | - * at that point. Instead, you should store any info you need on the payment during those |
|
420 | - * functions, and use that information at this step, which client code will decide |
|
421 | - * for you when it should be called. |
|
422 | - * |
|
423 | - * @param EE_Payment $payment |
|
424 | - * @return void |
|
425 | - */ |
|
426 | - public function update_txn_based_on_payment($payment) |
|
427 | - { |
|
428 | - // maybe update the transaction or line items or registrations |
|
429 | - // but most gateways don't need to do this, because they only update the payment |
|
430 | - } |
|
431 | - |
|
432 | - /** |
|
433 | - * Gets the first event for this payment (it's possible that it could be for multiple) |
|
434 | - * |
|
435 | - * @param EEI_Payment $payment |
|
436 | - * @return EEI_Event|null |
|
437 | - * @deprecated since 4.9.31 instead use EEI_Payment::get_first_event() |
|
438 | - */ |
|
439 | - protected function _get_first_event_for_payment(EEI_Payment $payment) |
|
440 | - { |
|
441 | - return $payment->get_first_event(); |
|
442 | - } |
|
443 | - |
|
444 | - /** |
|
445 | - * Gets the name of the first event for which is being paid |
|
446 | - * |
|
447 | - * @param EEI_Payment $payment |
|
448 | - * @return string |
|
449 | - * @deprecated since 4.9.31 instead use EEI_Payment::get_first_event_name() |
|
450 | - */ |
|
451 | - protected function _get_first_event_name_for_payment(EEI_Payment $payment) |
|
452 | - { |
|
453 | - return $payment->get_first_event_name(); |
|
454 | - } |
|
455 | - |
|
456 | - /** |
|
457 | - * Gets the text to use for a gateway's line item name when this is a partial payment |
|
458 | - * |
|
459 | - * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatPartialPaymentLineItemName($payment) |
|
460 | - * @param EE_Payment $payment |
|
461 | - * @return string |
|
462 | - */ |
|
463 | - protected function _format_partial_payment_line_item_name(EEI_Payment $payment) |
|
464 | - { |
|
465 | - return $this->_get_gateway_formatter()->formatPartialPaymentLineItemName($payment); |
|
466 | - } |
|
467 | - |
|
468 | - /** |
|
469 | - * Gets the text to use for a gateway's line item description when this is a partial payment |
|
470 | - * |
|
471 | - * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatPartialPaymentLineItemDesc() |
|
472 | - * @param EEI_Payment $payment |
|
473 | - * @return string |
|
474 | - */ |
|
475 | - protected function _format_partial_payment_line_item_desc(EEI_Payment $payment) |
|
476 | - { |
|
477 | - return $this->_get_gateway_formatter()->formatPartialPaymentLineItemDesc($payment); |
|
478 | - } |
|
479 | - |
|
480 | - /** |
|
481 | - * Gets the name to use for a line item when sending line items to the gateway |
|
482 | - * |
|
483 | - * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatLineItemName($line_item,$payment) |
|
484 | - * @param EEI_Line_Item $line_item |
|
485 | - * @param EEI_Payment $payment |
|
486 | - * @return string |
|
487 | - */ |
|
488 | - protected function _format_line_item_name(EEI_Line_Item $line_item, EEI_Payment $payment) |
|
489 | - { |
|
490 | - return $this->_get_gateway_formatter()->formatLineItemName($line_item, $payment); |
|
491 | - } |
|
492 | - |
|
493 | - /** |
|
494 | - * Gets the description to use for a line item when sending line items to the gateway |
|
495 | - * |
|
496 | - * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatLineItemDesc($line_item, $payment)) |
|
497 | - * @param EEI_Line_Item $line_item |
|
498 | - * @param EEI_Payment $payment |
|
499 | - * @return string |
|
500 | - */ |
|
501 | - protected function _format_line_item_desc(EEI_Line_Item $line_item, EEI_Payment $payment) |
|
502 | - { |
|
503 | - return $this->_get_gateway_formatter()->formatLineItemDesc($line_item, $payment); |
|
504 | - } |
|
505 | - |
|
506 | - /** |
|
507 | - * Gets the order description that should generlly be sent to gateways |
|
508 | - * |
|
509 | - * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatOrderDescription($payment) |
|
510 | - * @param EEI_Payment $payment |
|
511 | - * @return type |
|
512 | - */ |
|
513 | - protected function _format_order_description(EEI_Payment $payment) |
|
514 | - { |
|
515 | - return $this->_get_gateway_formatter()->formatOrderDescription($payment); |
|
516 | - } |
|
26 | + /** |
|
27 | + * a constant used as a possible value for $_currencies_supported to indicate |
|
28 | + * that ALL currencies are supported by this gateway |
|
29 | + */ |
|
30 | + const all_currencies_supported = 'all_currencies_supported'; |
|
31 | + /** |
|
32 | + * Where values are 3-letter currency codes |
|
33 | + * |
|
34 | + * @var array |
|
35 | + */ |
|
36 | + protected $_currencies_supported = array(); |
|
37 | + /** |
|
38 | + * Whether or not this gateway can support SENDING a refund request (ie, initiated by |
|
39 | + * admin in EE's wp-admin page) |
|
40 | + * |
|
41 | + * @var boolean |
|
42 | + */ |
|
43 | + protected $_supports_sending_refunds = false; |
|
44 | + |
|
45 | + /** |
|
46 | + * Whether or not this gateway can support RECEIVING a refund request from the payment |
|
47 | + * provider (ie, initiated by admin on the payment prover's website who sends an IPN to EE) |
|
48 | + * |
|
49 | + * @var boolean |
|
50 | + */ |
|
51 | + protected $_supports_receiving_refunds = false; |
|
52 | + /** |
|
53 | + * Model for querying for existing payments |
|
54 | + * |
|
55 | + * @var EEMI_Payment |
|
56 | + */ |
|
57 | + protected $_pay_model; |
|
58 | + |
|
59 | + /** |
|
60 | + * Model used for adding to the payments log |
|
61 | + * |
|
62 | + * @var EEMI_Payment_Log |
|
63 | + */ |
|
64 | + protected $_pay_log; |
|
65 | + |
|
66 | + /** |
|
67 | + * Used for formatting some input to gateways |
|
68 | + * |
|
69 | + * @var EEHI_Template |
|
70 | + */ |
|
71 | + protected $_template; |
|
72 | + |
|
73 | + /** |
|
74 | + * Concrete class that implements EEHI_Money, used by most gateways |
|
75 | + * |
|
76 | + * @var EEHI_Money |
|
77 | + */ |
|
78 | + protected $_money; |
|
79 | + |
|
80 | + /** |
|
81 | + * Concrete class that implements EEHI_Line_Item, used for manipulating the line item tree |
|
82 | + * |
|
83 | + * @var EEHI_Line_Item |
|
84 | + */ |
|
85 | + protected $_line_item; |
|
86 | + |
|
87 | + /** |
|
88 | + * @var GatewayDataFormatterInterface |
|
89 | + */ |
|
90 | + protected $_gateway_data_formatter; |
|
91 | + |
|
92 | + /** |
|
93 | + * @var FormatterInterface |
|
94 | + */ |
|
95 | + protected $_unsupported_character_remover; |
|
96 | + |
|
97 | + /** |
|
98 | + * The ID of the payment method using this gateway |
|
99 | + * |
|
100 | + * @var int |
|
101 | + */ |
|
102 | + protected $_ID; |
|
103 | + |
|
104 | + /** |
|
105 | + * @var $_debug_mode boolean whether to send requests to teh sandbox site or not |
|
106 | + */ |
|
107 | + protected $_debug_mode; |
|
108 | + /** |
|
109 | + * |
|
110 | + * @var string $_name name to show for this payment method |
|
111 | + */ |
|
112 | + protected $_name; |
|
113 | + /** |
|
114 | + * |
|
115 | + * @var string name to show fir this payment method to admin-type users |
|
116 | + */ |
|
117 | + protected $_admin_name; |
|
118 | + |
|
119 | + /** |
|
120 | + * @return EE_Gateway |
|
121 | + */ |
|
122 | + public function __construct() |
|
123 | + { |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * We don't want to serialize models as they often have circular structures |
|
128 | + * (eg a payment model has a reference to each payment model object; and most |
|
129 | + * payments have a transaction, most transactions have a payment method; |
|
130 | + * most payment methods have a payment method type; most payment method types |
|
131 | + * have a gateway. And if a gateway serializes its models, we start at the |
|
132 | + * beginning again) |
|
133 | + * |
|
134 | + * @return array |
|
135 | + */ |
|
136 | + public function __sleep() |
|
137 | + { |
|
138 | + $properties = get_object_vars($this); |
|
139 | + unset($properties['_pay_model'], $properties['_pay_log']); |
|
140 | + return array_keys($properties); |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Returns whether or not this gateway should support SENDING refunds |
|
145 | + * see $_supports_sending_refunds |
|
146 | + * |
|
147 | + * @return boolean |
|
148 | + */ |
|
149 | + public function supports_sending_refunds() |
|
150 | + { |
|
151 | + return $this->_supports_sending_refunds; |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Returns whether or not this gateway should support RECEIVING refunds |
|
156 | + * see $_supports_receiving_refunds |
|
157 | + * |
|
158 | + * @return boolean |
|
159 | + */ |
|
160 | + public function supports_receiving_refunds() |
|
161 | + { |
|
162 | + return $this->_supports_receiving_refunds; |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * Tries to refund the payment specified, taking into account the extra |
|
168 | + * refund info. Note that if the gateway's _supports_sending_refunds is false, |
|
169 | + * this should just throw an exception. |
|
170 | + * |
|
171 | + * @param EE_Payment $payment |
|
172 | + * @param array $refund_info |
|
173 | + * @return EE_Payment for the refund |
|
174 | + * @throws EE_Error |
|
175 | + */ |
|
176 | + public function do_direct_refund(EE_Payment $payment, $refund_info = null) |
|
177 | + { |
|
178 | + return null; |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * Sets the payment method's settings so the gateway knows where to send the request |
|
184 | + * etc |
|
185 | + * |
|
186 | + * @param array $settings_array |
|
187 | + */ |
|
188 | + public function set_settings($settings_array) |
|
189 | + { |
|
190 | + foreach ($settings_array as $name => $value) { |
|
191 | + $property_name = "_" . $name; |
|
192 | + $this->{$property_name} = $value; |
|
193 | + } |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * See this class description |
|
198 | + * |
|
199 | + * @param EEMI_Payment $payment_model |
|
200 | + */ |
|
201 | + public function set_payment_model($payment_model) |
|
202 | + { |
|
203 | + $this->_pay_model = $payment_model; |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * See this class description |
|
208 | + * |
|
209 | + * @param EEMI_Payment_Log $payment_log_model |
|
210 | + */ |
|
211 | + public function set_payment_log($payment_log_model) |
|
212 | + { |
|
213 | + $this->_pay_log = $payment_log_model; |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * See this class description |
|
218 | + * |
|
219 | + * @param EEHI_Template $template_helper |
|
220 | + */ |
|
221 | + public function set_template_helper($template_helper) |
|
222 | + { |
|
223 | + $this->_template = $template_helper; |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * See this class description |
|
228 | + * |
|
229 | + * @param EEHI_Line_Item $line_item_helper |
|
230 | + */ |
|
231 | + public function set_line_item_helper($line_item_helper) |
|
232 | + { |
|
233 | + $this->_line_item = $line_item_helper; |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * See this class description |
|
238 | + * |
|
239 | + * @param EEHI_Money $money_helper |
|
240 | + */ |
|
241 | + public function set_money_helper($money_helper) |
|
242 | + { |
|
243 | + $this->_money = $money_helper; |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * Sets the gateway data formatter helper |
|
249 | + * |
|
250 | + * @param GatewayDataFormatterInterface $gateway_data_formatter |
|
251 | + * @throws InvalidEntityException if it's not set properly |
|
252 | + */ |
|
253 | + public function set_gateway_data_formatter(GatewayDataFormatterInterface $gateway_data_formatter) |
|
254 | + { |
|
255 | + if (! $gateway_data_formatter instanceof GatewayDataFormatterInterface) { |
|
256 | + throw new InvalidEntityException( |
|
257 | + is_object($gateway_data_formatter) |
|
258 | + ? get_class($gateway_data_formatter) |
|
259 | + : esc_html__('Not an object', 'event_espresso'), |
|
260 | + '\\EventEspresso\\core\\services\\payment_methods\\gateways\\GatewayDataFormatterInterface' |
|
261 | + ); |
|
262 | + } |
|
263 | + $this->_gateway_data_formatter = $gateway_data_formatter; |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * Gets the gateway data formatter |
|
268 | + * |
|
269 | + * @return GatewayDataFormatterInterface |
|
270 | + * @throws InvalidEntityException if it's not set properly |
|
271 | + */ |
|
272 | + protected function _get_gateway_formatter() |
|
273 | + { |
|
274 | + if (! $this->_gateway_data_formatter instanceof GatewayDataFormatterInterface) { |
|
275 | + throw new InvalidEntityException( |
|
276 | + is_object($this->_gateway_data_formatter) |
|
277 | + ? get_class($this->_gateway_data_formatter) |
|
278 | + : esc_html__('Not an object', 'event_espresso'), |
|
279 | + '\\EventEspresso\\core\\services\\payment_methods\\gateways\\GatewayDataFormatterInterface' |
|
280 | + ); |
|
281 | + } |
|
282 | + return $this->_gateway_data_formatter; |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * Sets the helper which will remove unsupported characters for most gateways |
|
288 | + * |
|
289 | + * @param FormatterInterface $formatter |
|
290 | + * @return FormatterInterface |
|
291 | + * @throws InvalidEntityException |
|
292 | + */ |
|
293 | + public function set_unsupported_character_remover(FormatterInterface $formatter) |
|
294 | + { |
|
295 | + if (! $formatter instanceof FormatterInterface) { |
|
296 | + throw new InvalidEntityException( |
|
297 | + is_object($formatter) |
|
298 | + ? get_class($formatter) |
|
299 | + : esc_html__('Not an object', 'event_espresso'), |
|
300 | + '\\EventEspresso\\core\\services\\formatters\\FormatterInterface' |
|
301 | + ); |
|
302 | + } |
|
303 | + $this->_unsupported_character_remover = $formatter; |
|
304 | + } |
|
305 | + |
|
306 | + /** |
|
307 | + * Gets the helper which removes characters which gateways might not support, like emojis etc. |
|
308 | + * |
|
309 | + * @return FormatterInterface |
|
310 | + * @throws InvalidEntityException |
|
311 | + */ |
|
312 | + protected function _get_unsupported_character_remover() |
|
313 | + { |
|
314 | + if (! $this->_unsupported_character_remover instanceof FormatterInterface) { |
|
315 | + throw new InvalidEntityException( |
|
316 | + is_object($this->_unsupported_character_remover) |
|
317 | + ? get_class($this->_unsupported_character_remover) |
|
318 | + : esc_html__('Not an object', 'event_espresso'), |
|
319 | + '\\EventEspresso\\core\\services\\formatters\\FormatterInterface' |
|
320 | + ); |
|
321 | + } |
|
322 | + return $this->_unsupported_character_remover; |
|
323 | + } |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * @param $message |
|
328 | + * @param $payment |
|
329 | + */ |
|
330 | + public function log($message, $object_logged) |
|
331 | + { |
|
332 | + if ($object_logged instanceof EEI_Payment) { |
|
333 | + $type = 'Payment'; |
|
334 | + $id = $object_logged->ID(); |
|
335 | + } elseif ($object_logged instanceof EEI_Transaction) { |
|
336 | + $type = 'Transaction'; |
|
337 | + $id = $object_logged->ID(); |
|
338 | + } else { |
|
339 | + $type = 'Payment_Method'; |
|
340 | + $id = $this->_ID; |
|
341 | + } |
|
342 | + // only log if we're going to store it for longer than the minimum time |
|
343 | + $reg_config = LoaderFactory::getLoader()->load('EE_Registration_Config'); |
|
344 | + if ($reg_config->gateway_log_lifespan !== '1 second') { |
|
345 | + $this->_pay_log->gateway_log($message, $id, $type); |
|
346 | + } |
|
347 | + } |
|
348 | + |
|
349 | + /** |
|
350 | + * Formats the amount so it can generally be sent to gateways |
|
351 | + * |
|
352 | + * @param float $amount |
|
353 | + * @return string |
|
354 | + * @deprecated since 4.9.31 insetad use |
|
355 | + * EventEspresso\core\services\payment_methods\gateways\GatewayDataFormatter::format_currency() |
|
356 | + */ |
|
357 | + public function format_currency($amount) |
|
358 | + { |
|
359 | + return $this->_get_gateway_formatter()->formatCurrency($amount); |
|
360 | + } |
|
361 | + |
|
362 | + /** |
|
363 | + * Returns either an array of all the currency codes supported, |
|
364 | + * or a string indicating they're all supported (EE_gateway::all_currencies_supported) |
|
365 | + * |
|
366 | + * @return mixed array or string |
|
367 | + */ |
|
368 | + public function currencies_supported() |
|
369 | + { |
|
370 | + return $this->_currencies_supported; |
|
371 | + } |
|
372 | + |
|
373 | + /** |
|
374 | + * Returns what a simple summing of items and taxes for this transaction. This |
|
375 | + * can be used to determine if some more complex line items, like promotions, |
|
376 | + * surcharges, or cancellations occurred (in which case we might want to forget |
|
377 | + * about creating an itemized list of purchases and instead only send the total due) |
|
378 | + * |
|
379 | + * @param EE_Transaction $transaction |
|
380 | + * @return float |
|
381 | + */ |
|
382 | + protected function _sum_items_and_taxes(EE_Transaction $transaction) |
|
383 | + { |
|
384 | + $total_line_item = $transaction->total_line_item(); |
|
385 | + $total = 0; |
|
386 | + foreach ($total_line_item->get_items() as $item_line_item) { |
|
387 | + $total += max($item_line_item->total(), 0); |
|
388 | + } |
|
389 | + foreach ($total_line_item->tax_descendants() as $tax_line_item) { |
|
390 | + $total += max($tax_line_item->total(), 0); |
|
391 | + } |
|
392 | + return $total; |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | + * Determines whether or not we can easily itemize the transaction using only |
|
397 | + * items and taxes (ie, no promotions or surcharges or cancellations needed) |
|
398 | + * |
|
399 | + * @param EEI_Payment $payment |
|
400 | + * @return boolean |
|
401 | + */ |
|
402 | + protected function _can_easily_itemize_transaction_for(EEI_Payment $payment) |
|
403 | + { |
|
404 | + return $this->_money->compare_floats( |
|
405 | + $this->_sum_items_and_taxes($payment->transaction()), |
|
406 | + $payment->transaction()->total() |
|
407 | + ) |
|
408 | + && $this->_money->compare_floats( |
|
409 | + $payment->amount(), |
|
410 | + $payment->transaction()->total() |
|
411 | + ); |
|
412 | + } |
|
413 | + |
|
414 | + /** |
|
415 | + * Handles updating the transaction and any other related data based on the payment. |
|
416 | + * You may be tempted to do this as part of do_direct_payment or handle_payment_update, |
|
417 | + * but doing so on those functions might be too early. It's possible that the changes |
|
418 | + * you make to teh transaction or registration or line items may just get overwritten |
|
419 | + * at that point. Instead, you should store any info you need on the payment during those |
|
420 | + * functions, and use that information at this step, which client code will decide |
|
421 | + * for you when it should be called. |
|
422 | + * |
|
423 | + * @param EE_Payment $payment |
|
424 | + * @return void |
|
425 | + */ |
|
426 | + public function update_txn_based_on_payment($payment) |
|
427 | + { |
|
428 | + // maybe update the transaction or line items or registrations |
|
429 | + // but most gateways don't need to do this, because they only update the payment |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * Gets the first event for this payment (it's possible that it could be for multiple) |
|
434 | + * |
|
435 | + * @param EEI_Payment $payment |
|
436 | + * @return EEI_Event|null |
|
437 | + * @deprecated since 4.9.31 instead use EEI_Payment::get_first_event() |
|
438 | + */ |
|
439 | + protected function _get_first_event_for_payment(EEI_Payment $payment) |
|
440 | + { |
|
441 | + return $payment->get_first_event(); |
|
442 | + } |
|
443 | + |
|
444 | + /** |
|
445 | + * Gets the name of the first event for which is being paid |
|
446 | + * |
|
447 | + * @param EEI_Payment $payment |
|
448 | + * @return string |
|
449 | + * @deprecated since 4.9.31 instead use EEI_Payment::get_first_event_name() |
|
450 | + */ |
|
451 | + protected function _get_first_event_name_for_payment(EEI_Payment $payment) |
|
452 | + { |
|
453 | + return $payment->get_first_event_name(); |
|
454 | + } |
|
455 | + |
|
456 | + /** |
|
457 | + * Gets the text to use for a gateway's line item name when this is a partial payment |
|
458 | + * |
|
459 | + * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatPartialPaymentLineItemName($payment) |
|
460 | + * @param EE_Payment $payment |
|
461 | + * @return string |
|
462 | + */ |
|
463 | + protected function _format_partial_payment_line_item_name(EEI_Payment $payment) |
|
464 | + { |
|
465 | + return $this->_get_gateway_formatter()->formatPartialPaymentLineItemName($payment); |
|
466 | + } |
|
467 | + |
|
468 | + /** |
|
469 | + * Gets the text to use for a gateway's line item description when this is a partial payment |
|
470 | + * |
|
471 | + * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatPartialPaymentLineItemDesc() |
|
472 | + * @param EEI_Payment $payment |
|
473 | + * @return string |
|
474 | + */ |
|
475 | + protected function _format_partial_payment_line_item_desc(EEI_Payment $payment) |
|
476 | + { |
|
477 | + return $this->_get_gateway_formatter()->formatPartialPaymentLineItemDesc($payment); |
|
478 | + } |
|
479 | + |
|
480 | + /** |
|
481 | + * Gets the name to use for a line item when sending line items to the gateway |
|
482 | + * |
|
483 | + * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatLineItemName($line_item,$payment) |
|
484 | + * @param EEI_Line_Item $line_item |
|
485 | + * @param EEI_Payment $payment |
|
486 | + * @return string |
|
487 | + */ |
|
488 | + protected function _format_line_item_name(EEI_Line_Item $line_item, EEI_Payment $payment) |
|
489 | + { |
|
490 | + return $this->_get_gateway_formatter()->formatLineItemName($line_item, $payment); |
|
491 | + } |
|
492 | + |
|
493 | + /** |
|
494 | + * Gets the description to use for a line item when sending line items to the gateway |
|
495 | + * |
|
496 | + * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatLineItemDesc($line_item, $payment)) |
|
497 | + * @param EEI_Line_Item $line_item |
|
498 | + * @param EEI_Payment $payment |
|
499 | + * @return string |
|
500 | + */ |
|
501 | + protected function _format_line_item_desc(EEI_Line_Item $line_item, EEI_Payment $payment) |
|
502 | + { |
|
503 | + return $this->_get_gateway_formatter()->formatLineItemDesc($line_item, $payment); |
|
504 | + } |
|
505 | + |
|
506 | + /** |
|
507 | + * Gets the order description that should generlly be sent to gateways |
|
508 | + * |
|
509 | + * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatOrderDescription($payment) |
|
510 | + * @param EEI_Payment $payment |
|
511 | + * @return type |
|
512 | + */ |
|
513 | + protected function _format_order_description(EEI_Payment $payment) |
|
514 | + { |
|
515 | + return $this->_get_gateway_formatter()->formatOrderDescription($payment); |
|
516 | + } |
|
517 | 517 | } |
@@ -17,23 +17,23 @@ |
||
17 | 17 | class DetectFileEditorRequest extends Middleware |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * converts a Request to a Response |
|
22 | - * |
|
23 | - * @param RequestInterface $request |
|
24 | - * @param ResponseInterface $response |
|
25 | - * @return ResponseInterface |
|
26 | - */ |
|
27 | - public function handleRequest(RequestInterface $request, ResponseInterface $response) |
|
28 | - { |
|
29 | - $this->request = $request; |
|
30 | - $this->response = $response; |
|
31 | - // can't store user data during WP error scrapes if no user exists |
|
32 | - // so don't load the session since it's not going to work anyways |
|
33 | - if ($this->request->isWordPressScrape()) { |
|
34 | - add_filter('FHEE_load_EE_Session', '__return_false', 999); |
|
35 | - } |
|
36 | - $this->response = $this->processRequestStack($this->request, $this->response); |
|
37 | - return $this->response; |
|
38 | - } |
|
20 | + /** |
|
21 | + * converts a Request to a Response |
|
22 | + * |
|
23 | + * @param RequestInterface $request |
|
24 | + * @param ResponseInterface $response |
|
25 | + * @return ResponseInterface |
|
26 | + */ |
|
27 | + public function handleRequest(RequestInterface $request, ResponseInterface $response) |
|
28 | + { |
|
29 | + $this->request = $request; |
|
30 | + $this->response = $response; |
|
31 | + // can't store user data during WP error scrapes if no user exists |
|
32 | + // so don't load the session since it's not going to work anyways |
|
33 | + if ($this->request->isWordPressScrape()) { |
|
34 | + add_filter('FHEE_load_EE_Session', '__return_false', 999); |
|
35 | + } |
|
36 | + $this->response = $this->processRequestStack($this->request, $this->response); |
|
37 | + return $this->response; |
|
38 | + } |
|
39 | 39 | } |
@@ -17,332 +17,332 @@ |
||
17 | 17 | class EED_Recaptcha_Invisible extends EED_Module |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var EE_Registration_Config $config |
|
22 | - */ |
|
23 | - private static $config; |
|
24 | - |
|
25 | - |
|
26 | - /** |
|
27 | - * @return EED_Module|EED_Recaptcha |
|
28 | - */ |
|
29 | - public static function instance() |
|
30 | - { |
|
31 | - return parent::get_instance(__CLASS__); |
|
32 | - } |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * @return void |
|
37 | - * @throws InvalidInterfaceException |
|
38 | - * @throws InvalidDataTypeException |
|
39 | - * @throws InvalidArgumentException |
|
40 | - */ |
|
41 | - public static function set_hooks() |
|
42 | - { |
|
43 | - EED_Recaptcha_Invisible::setProperties(); |
|
44 | - if (EED_Recaptcha_Invisible::useInvisibleRecaptcha()) { |
|
45 | - if (EED_Recaptcha_Invisible::protectForm('ticket_selector')) { |
|
46 | - // ticket selection |
|
47 | - add_filter( |
|
48 | - 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
49 | - array('EED_Recaptcha_Invisible', 'ticketSelectorForm'), |
|
50 | - 10, |
|
51 | - 3 |
|
52 | - ); |
|
53 | - add_action( |
|
54 | - 'EED_Ticket_Selector__process_ticket_selections__before', |
|
55 | - array('EED_Recaptcha_Invisible', 'processTicketSelectorForm') |
|
56 | - ); |
|
57 | - } |
|
58 | - if (EED_Recaptcha_Invisible::protectForm('registration_form')) { |
|
59 | - // checkout |
|
60 | - add_action( |
|
61 | - 'AHEE__EE_SPCO_Reg_Step__display_reg_form__reg_form', |
|
62 | - array('EED_Recaptcha_Invisible', 'spcoRegStepForm') |
|
63 | - ); |
|
64 | - add_filter( |
|
65 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
66 | - array('EED_Recaptcha_Invisible', 'receiveSpcoRegStepForm'), |
|
67 | - 10, |
|
68 | - 2 |
|
69 | - ); |
|
70 | - } |
|
71 | - add_action('loop_end', array('EED_Recaptcha_Invisible', 'localizeScriptVars')); |
|
72 | - } |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * @return void |
|
78 | - * @throws InvalidInterfaceException |
|
79 | - * @throws InvalidDataTypeException |
|
80 | - * @throws InvalidArgumentException |
|
81 | - */ |
|
82 | - public static function set_hooks_admin() |
|
83 | - { |
|
84 | - EED_Recaptcha_Invisible::setProperties(); |
|
85 | - if (EED_Recaptcha_Invisible::protectForm('ticket_selector')) { |
|
86 | - add_action( |
|
87 | - 'EED_Ticket_Selector__process_ticket_selections__before', |
|
88 | - array('EED_Recaptcha_Invisible', 'processTicketSelectorForm') |
|
89 | - ); |
|
90 | - } |
|
91 | - if (EED_Recaptcha_Invisible::protectForm('registration_form')) { |
|
92 | - add_filter( |
|
93 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
94 | - array('EED_Recaptcha_Invisible', 'receiveSpcoRegStepForm'), |
|
95 | - 10, |
|
96 | - 2 |
|
97 | - ); |
|
98 | - } |
|
99 | - // admin settings |
|
100 | - add_action( |
|
101 | - 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
102 | - array('EED_Recaptcha_Invisible', 'adminSettings') |
|
103 | - ); |
|
104 | - add_filter( |
|
105 | - 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
106 | - array('EED_Recaptcha_Invisible', 'updateAdminSettings') |
|
107 | - ); |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * @return void |
|
113 | - * @throws InvalidInterfaceException |
|
114 | - * @throws InvalidDataTypeException |
|
115 | - * @throws InvalidArgumentException |
|
116 | - */ |
|
117 | - public static function setProperties() |
|
118 | - { |
|
119 | - |
|
120 | - EED_Recaptcha_Invisible::$config = EE_Registry::instance()->CFG->registration; |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * @return boolean |
|
126 | - */ |
|
127 | - public static function useInvisibleRecaptcha() |
|
128 | - { |
|
129 | - return EED_Recaptcha_Invisible::$config->use_captcha |
|
130 | - && EED_Recaptcha_Invisible::$config->recaptcha_theme === 'invisible'; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * @param string $form |
|
136 | - * @return boolean |
|
137 | - */ |
|
138 | - public static function protectForm($form) |
|
139 | - { |
|
140 | - return is_array(EED_Recaptcha_Invisible::$config->recaptcha_protected_forms) |
|
141 | - && in_array($form, EED_Recaptcha_Invisible::$config->recaptcha_protected_forms, true); |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * @return void |
|
147 | - * @throws InvalidInterfaceException |
|
148 | - * @throws InvalidDataTypeException |
|
149 | - * @throws InvalidArgumentException |
|
150 | - */ |
|
151 | - public static function localizeScriptVars() |
|
152 | - { |
|
153 | - /** @var \EventEspresso\core\services\request\Request $request */ |
|
154 | - $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
|
155 | - // Invisible Recaptcha is ONLY ever required for the frontend and admin |
|
156 | - // so we don't need to load any JS assets for other types of requests (like AJAX or API). |
|
157 | - if (! ($request->isAdmin() || $request->isFrontend())) { |
|
158 | - return; |
|
159 | - } |
|
160 | - wp_localize_script( |
|
161 | - EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA, |
|
162 | - 'eeRecaptcha', |
|
163 | - RecaptchaFactory::create()->getLocalizedVars() |
|
164 | - ); |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * @return string |
|
170 | - */ |
|
171 | - public static function assetsUrl() |
|
172 | - { |
|
173 | - return plugin_dir_url(__FILE__) . 'assets' . DS; |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * @param \WP $WP |
|
179 | - */ |
|
180 | - public function run($WP) |
|
181 | - { |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * @param EE_Request $request |
|
187 | - * @return bool |
|
188 | - * @throws InvalidArgumentException |
|
189 | - * @throws InvalidDataTypeException |
|
190 | - * @throws InvalidInterfaceException |
|
191 | - * @throws RuntimeException |
|
192 | - */ |
|
193 | - public static function verifyToken(EE_Request $request) |
|
194 | - { |
|
195 | - return RecaptchaFactory::create()->verifyToken($request); |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * @param EE_Form_Section_Proper $reg_form |
|
201 | - * @return void |
|
202 | - * @throws EE_Error |
|
203 | - * @throws InvalidArgumentException |
|
204 | - * @throws InvalidDataTypeException |
|
205 | - * @throws InvalidInterfaceException |
|
206 | - * @throws DomainException |
|
207 | - */ |
|
208 | - public static function spcoRegStepForm(EE_Form_Section_Proper $reg_form) |
|
209 | - { |
|
210 | - // do nothing if form isn't for a reg step or test has already been passed |
|
211 | - if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
212 | - return; |
|
213 | - } |
|
214 | - $default_hidden_inputs = $reg_form->get_subsection('default_hidden_inputs'); |
|
215 | - if ($default_hidden_inputs instanceof EE_Form_Section_Proper) { |
|
216 | - $invisible_recaptcha = RecaptchaFactory::create(); |
|
217 | - $invisible_recaptcha->addToFormSection($default_hidden_inputs); |
|
218 | - } |
|
219 | - } |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * @param EE_Form_Section_Proper $reg_form |
|
224 | - * @return bool |
|
225 | - * @throws InvalidDataTypeException |
|
226 | - * @throws InvalidInterfaceException |
|
227 | - * @throws EE_Error |
|
228 | - * @throws InvalidArgumentException |
|
229 | - */ |
|
230 | - public static function processSpcoRegStepForm(EE_Form_Section_Proper $reg_form) |
|
231 | - { |
|
232 | - return strpos($reg_form->name(), 'reg-step-form') !== false |
|
233 | - && ! RecaptchaFactory::create()->recaptchaPassed(); |
|
234 | - } |
|
235 | - |
|
236 | - |
|
237 | - /** |
|
238 | - * @param array|null $req_data |
|
239 | - * @param EE_Form_Section_Proper $reg_form |
|
240 | - * @return array |
|
241 | - * @throws EE_Error |
|
242 | - * @throws InvalidArgumentException |
|
243 | - * @throws InvalidDataTypeException |
|
244 | - * @throws InvalidInterfaceException |
|
245 | - * @throws RuntimeException |
|
246 | - */ |
|
247 | - public static function receiveSpcoRegStepForm($req_data = array(), EE_Form_Section_Proper $reg_form) |
|
248 | - { |
|
249 | - // do nothing if form isn't for a reg step or test has already been passed |
|
250 | - if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
251 | - return $req_data; |
|
252 | - } |
|
253 | - /** @var EE_Request $request */ |
|
254 | - $request = LoaderFactory::getLoader()->getShared('EE_Request'); |
|
255 | - if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
256 | - if ($request->isAjax()) { |
|
257 | - $json_response = new EE_SPCO_JSON_Response(); |
|
258 | - $json_response->echoAndExit(); |
|
259 | - } |
|
260 | - EEH_URL::safeRedirectAndExit( |
|
261 | - EE_Registry::instance()->CFG->core->reg_page_url() |
|
262 | - ); |
|
263 | - } |
|
264 | - return $req_data; |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - /** |
|
269 | - * @param string $html |
|
270 | - * @param EE_Event $event |
|
271 | - * @param bool $iframe |
|
272 | - * @return string |
|
273 | - * @throws EE_Error |
|
274 | - * @throws InvalidArgumentException |
|
275 | - * @throws InvalidDataTypeException |
|
276 | - * @throws InvalidInterfaceException |
|
277 | - * @throws ReflectionException |
|
278 | - * @throws DomainException |
|
279 | - */ |
|
280 | - public static function ticketSelectorForm($html = '', EE_Event $event, $iframe = false) |
|
281 | - { |
|
282 | - $recaptcha = RecaptchaFactory::create(); |
|
283 | - // do nothing if test has already been passed |
|
284 | - if ($recaptcha->recaptchaPassed()) { |
|
285 | - return $html; |
|
286 | - } |
|
287 | - $html .= $recaptcha->getInputHtml( |
|
288 | - array( |
|
289 | - 'recaptcha_id' => $event->ID(), |
|
290 | - 'iframe' => $iframe, |
|
291 | - 'localized_vars' => $recaptcha->getLocalizedVars(), |
|
292 | - ) |
|
293 | - ); |
|
294 | - return $html; |
|
295 | - } |
|
296 | - |
|
297 | - |
|
298 | - /** |
|
299 | - * @return void |
|
300 | - * @throws InvalidArgumentException |
|
301 | - * @throws InvalidInterfaceException |
|
302 | - * @throws InvalidDataTypeException |
|
303 | - * @throws RuntimeException |
|
304 | - */ |
|
305 | - public static function processTicketSelectorForm() |
|
306 | - { |
|
307 | - // do nothing if test has already been passed |
|
308 | - if (RecaptchaFactory::create()->recaptchaPassed()) { |
|
309 | - return; |
|
310 | - } |
|
311 | - /** @var EE_Request $request */ |
|
312 | - $request = LoaderFactory::getLoader()->getShared('EE_Request'); |
|
313 | - if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
314 | - $event_id = $request->get('tkt-slctr-event-id'); |
|
315 | - $return_url = $request->is_set("tkt-slctr-return-url-{$event_id}") |
|
316 | - ? $request->get("tkt-slctr-return-url-{$event_id}") |
|
317 | - : get_permalink($event_id); |
|
318 | - EEH_URL::safeRedirectAndExit($return_url); |
|
319 | - } |
|
320 | - } |
|
321 | - |
|
322 | - |
|
323 | - /** |
|
324 | - * @throws EE_Error |
|
325 | - * @throws InvalidArgumentException |
|
326 | - * @throws InvalidDataTypeException |
|
327 | - * @throws InvalidInterfaceException |
|
328 | - */ |
|
329 | - public static function adminSettings() |
|
330 | - { |
|
331 | - RecaptchaFactory::getAdminModule()->adminSettings(); |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - /** |
|
336 | - * @param EE_Registration_Config $EE_Registration_Config |
|
337 | - * @return EE_Registration_Config |
|
338 | - * @throws EE_Error |
|
339 | - * @throws InvalidArgumentException |
|
340 | - * @throws InvalidDataTypeException |
|
341 | - * @throws InvalidInterfaceException |
|
342 | - * @throws ReflectionException |
|
343 | - */ |
|
344 | - public static function updateAdminSettings(EE_Registration_Config $EE_Registration_Config) |
|
345 | - { |
|
346 | - return RecaptchaFactory::getAdminModule()->updateAdminSettings($EE_Registration_Config); |
|
347 | - } |
|
20 | + /** |
|
21 | + * @var EE_Registration_Config $config |
|
22 | + */ |
|
23 | + private static $config; |
|
24 | + |
|
25 | + |
|
26 | + /** |
|
27 | + * @return EED_Module|EED_Recaptcha |
|
28 | + */ |
|
29 | + public static function instance() |
|
30 | + { |
|
31 | + return parent::get_instance(__CLASS__); |
|
32 | + } |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * @return void |
|
37 | + * @throws InvalidInterfaceException |
|
38 | + * @throws InvalidDataTypeException |
|
39 | + * @throws InvalidArgumentException |
|
40 | + */ |
|
41 | + public static function set_hooks() |
|
42 | + { |
|
43 | + EED_Recaptcha_Invisible::setProperties(); |
|
44 | + if (EED_Recaptcha_Invisible::useInvisibleRecaptcha()) { |
|
45 | + if (EED_Recaptcha_Invisible::protectForm('ticket_selector')) { |
|
46 | + // ticket selection |
|
47 | + add_filter( |
|
48 | + 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
49 | + array('EED_Recaptcha_Invisible', 'ticketSelectorForm'), |
|
50 | + 10, |
|
51 | + 3 |
|
52 | + ); |
|
53 | + add_action( |
|
54 | + 'EED_Ticket_Selector__process_ticket_selections__before', |
|
55 | + array('EED_Recaptcha_Invisible', 'processTicketSelectorForm') |
|
56 | + ); |
|
57 | + } |
|
58 | + if (EED_Recaptcha_Invisible::protectForm('registration_form')) { |
|
59 | + // checkout |
|
60 | + add_action( |
|
61 | + 'AHEE__EE_SPCO_Reg_Step__display_reg_form__reg_form', |
|
62 | + array('EED_Recaptcha_Invisible', 'spcoRegStepForm') |
|
63 | + ); |
|
64 | + add_filter( |
|
65 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
66 | + array('EED_Recaptcha_Invisible', 'receiveSpcoRegStepForm'), |
|
67 | + 10, |
|
68 | + 2 |
|
69 | + ); |
|
70 | + } |
|
71 | + add_action('loop_end', array('EED_Recaptcha_Invisible', 'localizeScriptVars')); |
|
72 | + } |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * @return void |
|
78 | + * @throws InvalidInterfaceException |
|
79 | + * @throws InvalidDataTypeException |
|
80 | + * @throws InvalidArgumentException |
|
81 | + */ |
|
82 | + public static function set_hooks_admin() |
|
83 | + { |
|
84 | + EED_Recaptcha_Invisible::setProperties(); |
|
85 | + if (EED_Recaptcha_Invisible::protectForm('ticket_selector')) { |
|
86 | + add_action( |
|
87 | + 'EED_Ticket_Selector__process_ticket_selections__before', |
|
88 | + array('EED_Recaptcha_Invisible', 'processTicketSelectorForm') |
|
89 | + ); |
|
90 | + } |
|
91 | + if (EED_Recaptcha_Invisible::protectForm('registration_form')) { |
|
92 | + add_filter( |
|
93 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
94 | + array('EED_Recaptcha_Invisible', 'receiveSpcoRegStepForm'), |
|
95 | + 10, |
|
96 | + 2 |
|
97 | + ); |
|
98 | + } |
|
99 | + // admin settings |
|
100 | + add_action( |
|
101 | + 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
102 | + array('EED_Recaptcha_Invisible', 'adminSettings') |
|
103 | + ); |
|
104 | + add_filter( |
|
105 | + 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
106 | + array('EED_Recaptcha_Invisible', 'updateAdminSettings') |
|
107 | + ); |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * @return void |
|
113 | + * @throws InvalidInterfaceException |
|
114 | + * @throws InvalidDataTypeException |
|
115 | + * @throws InvalidArgumentException |
|
116 | + */ |
|
117 | + public static function setProperties() |
|
118 | + { |
|
119 | + |
|
120 | + EED_Recaptcha_Invisible::$config = EE_Registry::instance()->CFG->registration; |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * @return boolean |
|
126 | + */ |
|
127 | + public static function useInvisibleRecaptcha() |
|
128 | + { |
|
129 | + return EED_Recaptcha_Invisible::$config->use_captcha |
|
130 | + && EED_Recaptcha_Invisible::$config->recaptcha_theme === 'invisible'; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * @param string $form |
|
136 | + * @return boolean |
|
137 | + */ |
|
138 | + public static function protectForm($form) |
|
139 | + { |
|
140 | + return is_array(EED_Recaptcha_Invisible::$config->recaptcha_protected_forms) |
|
141 | + && in_array($form, EED_Recaptcha_Invisible::$config->recaptcha_protected_forms, true); |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * @return void |
|
147 | + * @throws InvalidInterfaceException |
|
148 | + * @throws InvalidDataTypeException |
|
149 | + * @throws InvalidArgumentException |
|
150 | + */ |
|
151 | + public static function localizeScriptVars() |
|
152 | + { |
|
153 | + /** @var \EventEspresso\core\services\request\Request $request */ |
|
154 | + $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
|
155 | + // Invisible Recaptcha is ONLY ever required for the frontend and admin |
|
156 | + // so we don't need to load any JS assets for other types of requests (like AJAX or API). |
|
157 | + if (! ($request->isAdmin() || $request->isFrontend())) { |
|
158 | + return; |
|
159 | + } |
|
160 | + wp_localize_script( |
|
161 | + EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA, |
|
162 | + 'eeRecaptcha', |
|
163 | + RecaptchaFactory::create()->getLocalizedVars() |
|
164 | + ); |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * @return string |
|
170 | + */ |
|
171 | + public static function assetsUrl() |
|
172 | + { |
|
173 | + return plugin_dir_url(__FILE__) . 'assets' . DS; |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * @param \WP $WP |
|
179 | + */ |
|
180 | + public function run($WP) |
|
181 | + { |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * @param EE_Request $request |
|
187 | + * @return bool |
|
188 | + * @throws InvalidArgumentException |
|
189 | + * @throws InvalidDataTypeException |
|
190 | + * @throws InvalidInterfaceException |
|
191 | + * @throws RuntimeException |
|
192 | + */ |
|
193 | + public static function verifyToken(EE_Request $request) |
|
194 | + { |
|
195 | + return RecaptchaFactory::create()->verifyToken($request); |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * @param EE_Form_Section_Proper $reg_form |
|
201 | + * @return void |
|
202 | + * @throws EE_Error |
|
203 | + * @throws InvalidArgumentException |
|
204 | + * @throws InvalidDataTypeException |
|
205 | + * @throws InvalidInterfaceException |
|
206 | + * @throws DomainException |
|
207 | + */ |
|
208 | + public static function spcoRegStepForm(EE_Form_Section_Proper $reg_form) |
|
209 | + { |
|
210 | + // do nothing if form isn't for a reg step or test has already been passed |
|
211 | + if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
212 | + return; |
|
213 | + } |
|
214 | + $default_hidden_inputs = $reg_form->get_subsection('default_hidden_inputs'); |
|
215 | + if ($default_hidden_inputs instanceof EE_Form_Section_Proper) { |
|
216 | + $invisible_recaptcha = RecaptchaFactory::create(); |
|
217 | + $invisible_recaptcha->addToFormSection($default_hidden_inputs); |
|
218 | + } |
|
219 | + } |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * @param EE_Form_Section_Proper $reg_form |
|
224 | + * @return bool |
|
225 | + * @throws InvalidDataTypeException |
|
226 | + * @throws InvalidInterfaceException |
|
227 | + * @throws EE_Error |
|
228 | + * @throws InvalidArgumentException |
|
229 | + */ |
|
230 | + public static function processSpcoRegStepForm(EE_Form_Section_Proper $reg_form) |
|
231 | + { |
|
232 | + return strpos($reg_form->name(), 'reg-step-form') !== false |
|
233 | + && ! RecaptchaFactory::create()->recaptchaPassed(); |
|
234 | + } |
|
235 | + |
|
236 | + |
|
237 | + /** |
|
238 | + * @param array|null $req_data |
|
239 | + * @param EE_Form_Section_Proper $reg_form |
|
240 | + * @return array |
|
241 | + * @throws EE_Error |
|
242 | + * @throws InvalidArgumentException |
|
243 | + * @throws InvalidDataTypeException |
|
244 | + * @throws InvalidInterfaceException |
|
245 | + * @throws RuntimeException |
|
246 | + */ |
|
247 | + public static function receiveSpcoRegStepForm($req_data = array(), EE_Form_Section_Proper $reg_form) |
|
248 | + { |
|
249 | + // do nothing if form isn't for a reg step or test has already been passed |
|
250 | + if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
251 | + return $req_data; |
|
252 | + } |
|
253 | + /** @var EE_Request $request */ |
|
254 | + $request = LoaderFactory::getLoader()->getShared('EE_Request'); |
|
255 | + if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
256 | + if ($request->isAjax()) { |
|
257 | + $json_response = new EE_SPCO_JSON_Response(); |
|
258 | + $json_response->echoAndExit(); |
|
259 | + } |
|
260 | + EEH_URL::safeRedirectAndExit( |
|
261 | + EE_Registry::instance()->CFG->core->reg_page_url() |
|
262 | + ); |
|
263 | + } |
|
264 | + return $req_data; |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + /** |
|
269 | + * @param string $html |
|
270 | + * @param EE_Event $event |
|
271 | + * @param bool $iframe |
|
272 | + * @return string |
|
273 | + * @throws EE_Error |
|
274 | + * @throws InvalidArgumentException |
|
275 | + * @throws InvalidDataTypeException |
|
276 | + * @throws InvalidInterfaceException |
|
277 | + * @throws ReflectionException |
|
278 | + * @throws DomainException |
|
279 | + */ |
|
280 | + public static function ticketSelectorForm($html = '', EE_Event $event, $iframe = false) |
|
281 | + { |
|
282 | + $recaptcha = RecaptchaFactory::create(); |
|
283 | + // do nothing if test has already been passed |
|
284 | + if ($recaptcha->recaptchaPassed()) { |
|
285 | + return $html; |
|
286 | + } |
|
287 | + $html .= $recaptcha->getInputHtml( |
|
288 | + array( |
|
289 | + 'recaptcha_id' => $event->ID(), |
|
290 | + 'iframe' => $iframe, |
|
291 | + 'localized_vars' => $recaptcha->getLocalizedVars(), |
|
292 | + ) |
|
293 | + ); |
|
294 | + return $html; |
|
295 | + } |
|
296 | + |
|
297 | + |
|
298 | + /** |
|
299 | + * @return void |
|
300 | + * @throws InvalidArgumentException |
|
301 | + * @throws InvalidInterfaceException |
|
302 | + * @throws InvalidDataTypeException |
|
303 | + * @throws RuntimeException |
|
304 | + */ |
|
305 | + public static function processTicketSelectorForm() |
|
306 | + { |
|
307 | + // do nothing if test has already been passed |
|
308 | + if (RecaptchaFactory::create()->recaptchaPassed()) { |
|
309 | + return; |
|
310 | + } |
|
311 | + /** @var EE_Request $request */ |
|
312 | + $request = LoaderFactory::getLoader()->getShared('EE_Request'); |
|
313 | + if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
314 | + $event_id = $request->get('tkt-slctr-event-id'); |
|
315 | + $return_url = $request->is_set("tkt-slctr-return-url-{$event_id}") |
|
316 | + ? $request->get("tkt-slctr-return-url-{$event_id}") |
|
317 | + : get_permalink($event_id); |
|
318 | + EEH_URL::safeRedirectAndExit($return_url); |
|
319 | + } |
|
320 | + } |
|
321 | + |
|
322 | + |
|
323 | + /** |
|
324 | + * @throws EE_Error |
|
325 | + * @throws InvalidArgumentException |
|
326 | + * @throws InvalidDataTypeException |
|
327 | + * @throws InvalidInterfaceException |
|
328 | + */ |
|
329 | + public static function adminSettings() |
|
330 | + { |
|
331 | + RecaptchaFactory::getAdminModule()->adminSettings(); |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + /** |
|
336 | + * @param EE_Registration_Config $EE_Registration_Config |
|
337 | + * @return EE_Registration_Config |
|
338 | + * @throws EE_Error |
|
339 | + * @throws InvalidArgumentException |
|
340 | + * @throws InvalidDataTypeException |
|
341 | + * @throws InvalidInterfaceException |
|
342 | + * @throws ReflectionException |
|
343 | + */ |
|
344 | + public static function updateAdminSettings(EE_Registration_Config $EE_Registration_Config) |
|
345 | + { |
|
346 | + return RecaptchaFactory::getAdminModule()->updateAdminSettings($EE_Registration_Config); |
|
347 | + } |
|
348 | 348 | } |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
155 | 155 | // Invisible Recaptcha is ONLY ever required for the frontend and admin |
156 | 156 | // so we don't need to load any JS assets for other types of requests (like AJAX or API). |
157 | - if (! ($request->isAdmin() || $request->isFrontend())) { |
|
157 | + if ( ! ($request->isAdmin() || $request->isFrontend())) { |
|
158 | 158 | return; |
159 | 159 | } |
160 | 160 | wp_localize_script( |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | */ |
171 | 171 | public static function assetsUrl() |
172 | 172 | { |
173 | - return plugin_dir_url(__FILE__) . 'assets' . DS; |
|
173 | + return plugin_dir_url(__FILE__).'assets'.DS; |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | public static function spcoRegStepForm(EE_Form_Section_Proper $reg_form) |
209 | 209 | { |
210 | 210 | // do nothing if form isn't for a reg step or test has already been passed |
211 | - if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
211 | + if ( ! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
212 | 212 | return; |
213 | 213 | } |
214 | 214 | $default_hidden_inputs = $reg_form->get_subsection('default_hidden_inputs'); |
@@ -247,12 +247,12 @@ discard block |
||
247 | 247 | public static function receiveSpcoRegStepForm($req_data = array(), EE_Form_Section_Proper $reg_form) |
248 | 248 | { |
249 | 249 | // do nothing if form isn't for a reg step or test has already been passed |
250 | - if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
250 | + if ( ! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
251 | 251 | return $req_data; |
252 | 252 | } |
253 | 253 | /** @var EE_Request $request */ |
254 | 254 | $request = LoaderFactory::getLoader()->getShared('EE_Request'); |
255 | - if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
255 | + if ( ! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
256 | 256 | if ($request->isAjax()) { |
257 | 257 | $json_response = new EE_SPCO_JSON_Response(); |
258 | 258 | $json_response->echoAndExit(); |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | } |
311 | 311 | /** @var EE_Request $request */ |
312 | 312 | $request = LoaderFactory::getLoader()->getShared('EE_Request'); |
313 | - if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
313 | + if ( ! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
314 | 314 | $event_id = $request->get('tkt-slctr-event-id'); |
315 | 315 | $return_url = $request->is_set("tkt-slctr-return-url-{$event_id}") |
316 | 316 | ? $request->get("tkt-slctr-return-url-{$event_id}") |
@@ -6,79 +6,79 @@ discard block |
||
6 | 6 | class EEM_System_Status |
7 | 7 | { |
8 | 8 | |
9 | - // private instance of the EEM_System_Status object |
|
10 | - protected static $_instance = null; |
|
9 | + // private instance of the EEM_System_Status object |
|
10 | + protected static $_instance = null; |
|
11 | 11 | |
12 | 12 | |
13 | 13 | |
14 | - /** |
|
15 | - * This function is a singleton method used to instantiate the EEM_Attendee object |
|
16 | - * |
|
17 | - * @access public |
|
18 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
19 | - * @return EEM_System_Status |
|
20 | - */ |
|
21 | - public static function instance() |
|
22 | - { |
|
14 | + /** |
|
15 | + * This function is a singleton method used to instantiate the EEM_Attendee object |
|
16 | + * |
|
17 | + * @access public |
|
18 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
19 | + * @return EEM_System_Status |
|
20 | + */ |
|
21 | + public static function instance() |
|
22 | + { |
|
23 | 23 | |
24 | - // check if instance of EEM_System_Status already exists |
|
25 | - if (self::$_instance === null) { |
|
26 | - // instantiate EEM_System_Status |
|
27 | - self::$_instance = new self(); |
|
28 | - } |
|
29 | - return self::$_instance; |
|
30 | - } |
|
31 | - private function __construct() |
|
32 | - { |
|
33 | - } |
|
34 | - /** |
|
35 | - * |
|
36 | - * @return array where each key is a function name on this class, and each value is SOMETHING-- |
|
37 | - * it might be a value, an array, or an object |
|
38 | - */ |
|
39 | - public function get_system_stati() |
|
40 | - { |
|
41 | - return apply_filters( |
|
42 | - 'FHEE__EEM_System_Status__get_system_stati', |
|
43 | - array( |
|
44 | - 'ee_version'=>$this->get_ee_version(), |
|
45 | - 'ee_activation_history'=>$this->get_ee_activation_history(), |
|
46 | - 'ee_config'=>$this->get_ee_config(), |
|
47 | - 'ee_migration_history'=>$this->get_ee_migration_history(), |
|
48 | - 'active_plugins'=>$this->get_active_plugins(), |
|
49 | - 'wp_settings'=>$this->get_wp_settings(), |
|
50 | - 'wp_maintenance_mode' => $this->get_wp_maintenance_mode(), |
|
51 | - 'https_enabled'=>$this->get_https_enabled(), |
|
52 | - 'logging_enabled' => $this->get_logging_enabled(), |
|
53 | - 'remote_posting' => $this->get_remote_posting(), |
|
54 | - 'php_version'=>$this->php_version(), |
|
55 | - 'php.ini_settings'=>$this->get_php_ini_all(), |
|
56 | - 'php_info'=>$this->get_php_info(), |
|
57 | - ), |
|
58 | - $this |
|
59 | - ); |
|
60 | - } |
|
61 | - /** |
|
62 | - * |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - public function get_ee_version() |
|
66 | - { |
|
67 | - return espresso_version(); |
|
68 | - } |
|
69 | - /** |
|
70 | - * |
|
71 | - * @return string |
|
72 | - */ |
|
73 | - public function php_version() |
|
74 | - { |
|
75 | - return phpversion(); |
|
76 | - } |
|
77 | - /** |
|
78 | - * |
|
79 | - * @return array, where each key is a plugin name (lower-cased), values are sub-arrays. |
|
80 | - * Sub-arrays like described in wp function get_plugin_data. Ie, * |
|
81 | - * 'Name' => 'Plugin Name', |
|
24 | + // check if instance of EEM_System_Status already exists |
|
25 | + if (self::$_instance === null) { |
|
26 | + // instantiate EEM_System_Status |
|
27 | + self::$_instance = new self(); |
|
28 | + } |
|
29 | + return self::$_instance; |
|
30 | + } |
|
31 | + private function __construct() |
|
32 | + { |
|
33 | + } |
|
34 | + /** |
|
35 | + * |
|
36 | + * @return array where each key is a function name on this class, and each value is SOMETHING-- |
|
37 | + * it might be a value, an array, or an object |
|
38 | + */ |
|
39 | + public function get_system_stati() |
|
40 | + { |
|
41 | + return apply_filters( |
|
42 | + 'FHEE__EEM_System_Status__get_system_stati', |
|
43 | + array( |
|
44 | + 'ee_version'=>$this->get_ee_version(), |
|
45 | + 'ee_activation_history'=>$this->get_ee_activation_history(), |
|
46 | + 'ee_config'=>$this->get_ee_config(), |
|
47 | + 'ee_migration_history'=>$this->get_ee_migration_history(), |
|
48 | + 'active_plugins'=>$this->get_active_plugins(), |
|
49 | + 'wp_settings'=>$this->get_wp_settings(), |
|
50 | + 'wp_maintenance_mode' => $this->get_wp_maintenance_mode(), |
|
51 | + 'https_enabled'=>$this->get_https_enabled(), |
|
52 | + 'logging_enabled' => $this->get_logging_enabled(), |
|
53 | + 'remote_posting' => $this->get_remote_posting(), |
|
54 | + 'php_version'=>$this->php_version(), |
|
55 | + 'php.ini_settings'=>$this->get_php_ini_all(), |
|
56 | + 'php_info'=>$this->get_php_info(), |
|
57 | + ), |
|
58 | + $this |
|
59 | + ); |
|
60 | + } |
|
61 | + /** |
|
62 | + * |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + public function get_ee_version() |
|
66 | + { |
|
67 | + return espresso_version(); |
|
68 | + } |
|
69 | + /** |
|
70 | + * |
|
71 | + * @return string |
|
72 | + */ |
|
73 | + public function php_version() |
|
74 | + { |
|
75 | + return phpversion(); |
|
76 | + } |
|
77 | + /** |
|
78 | + * |
|
79 | + * @return array, where each key is a plugin name (lower-cased), values are sub-arrays. |
|
80 | + * Sub-arrays like described in wp function get_plugin_data. Ie, * |
|
81 | + * 'Name' => 'Plugin Name', |
|
82 | 82 | 'PluginURI' => 'Plugin URI', |
83 | 83 | 'Version' => 'Version', |
84 | 84 | 'Description' => 'Description', |
@@ -87,221 +87,221 @@ discard block |
||
87 | 87 | 'TextDomain' => 'Text Domain', |
88 | 88 | 'DomainPath' => 'Domain Path', |
89 | 89 | 'Network' => 'Network', |
90 | - */ |
|
91 | - public function get_active_plugins() |
|
92 | - { |
|
93 | - $active_plugins = (array) get_option('active_plugins', array()); |
|
94 | - if (is_multisite()) { |
|
95 | - $active_plugins = array_merge($active_plugins, get_site_option('active_sitewide_plugins', array())); |
|
96 | - } |
|
97 | - $active_plugins = array_map('strtolower', $active_plugins); |
|
98 | - $plugin_info = array(); |
|
99 | - foreach ($active_plugins as $plugin) { |
|
100 | - $plugin_data = @get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin); |
|
90 | + */ |
|
91 | + public function get_active_plugins() |
|
92 | + { |
|
93 | + $active_plugins = (array) get_option('active_plugins', array()); |
|
94 | + if (is_multisite()) { |
|
95 | + $active_plugins = array_merge($active_plugins, get_site_option('active_sitewide_plugins', array())); |
|
96 | + } |
|
97 | + $active_plugins = array_map('strtolower', $active_plugins); |
|
98 | + $plugin_info = array(); |
|
99 | + foreach ($active_plugins as $plugin) { |
|
100 | + $plugin_data = @get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin); |
|
101 | 101 | |
102 | - $plugin_info[ $plugin ] = $plugin_data; |
|
103 | - } |
|
104 | - return $plugin_info; |
|
105 | - } |
|
102 | + $plugin_info[ $plugin ] = $plugin_data; |
|
103 | + } |
|
104 | + return $plugin_info; |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * |
|
109 | - * @return array with keys 'home_url' and 'site_url' |
|
110 | - */ |
|
111 | - public function get_wp_settings() |
|
112 | - { |
|
113 | - $wp_memory_int = $this->let_to_num(WP_MEMORY_LIMIT); |
|
114 | - if ($wp_memory_int < 67108864) { |
|
115 | - $wp_memory_to_display = '<mark class="error">' . sprintf(__('%s - We recommend setting memory to at least 64MB. See: %s Increasing memory allocated to PHP %s', 'event_espresso'), WP_MEMORY_LIMIT, '<a href="http://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP">', '</a>"') . '</mark>'; |
|
116 | - } else { |
|
117 | - $wp_memory_to_display = '<mark class="yes">' . size_format($wp_memory_int) . '</mark>'; |
|
118 | - } |
|
119 | - return array( |
|
120 | - 'name'=>get_bloginfo('name', 'display'), |
|
121 | - 'is_multisite'=>is_multisite(), |
|
122 | - 'version'=> get_bloginfo('version', 'display'), |
|
123 | - 'home_url'=>home_url(), |
|
124 | - 'site_url'=>site_url(), |
|
125 | - 'WP_DEBUG'=>WP_DEBUG, |
|
126 | - 'permalink_structure'=>get_option('permalink_structure'), |
|
127 | - 'theme'=>wp_get_theme(), |
|
128 | - 'gmt_offset'=>get_option('gmt_offset'), |
|
129 | - 'timezone_string'=>get_option('timezone_string'), |
|
130 | - 'admin_email'=> get_bloginfo('admin_email', 'display'), |
|
131 | - 'language'=>get_bloginfo('language', 'display'), |
|
132 | - 'wp_max_upload_size' => size_format(wp_max_upload_size()), |
|
133 | - 'wp_memory' => $wp_memory_to_display |
|
134 | - ); |
|
135 | - } |
|
107 | + /** |
|
108 | + * |
|
109 | + * @return array with keys 'home_url' and 'site_url' |
|
110 | + */ |
|
111 | + public function get_wp_settings() |
|
112 | + { |
|
113 | + $wp_memory_int = $this->let_to_num(WP_MEMORY_LIMIT); |
|
114 | + if ($wp_memory_int < 67108864) { |
|
115 | + $wp_memory_to_display = '<mark class="error">' . sprintf(__('%s - We recommend setting memory to at least 64MB. See: %s Increasing memory allocated to PHP %s', 'event_espresso'), WP_MEMORY_LIMIT, '<a href="http://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP">', '</a>"') . '</mark>'; |
|
116 | + } else { |
|
117 | + $wp_memory_to_display = '<mark class="yes">' . size_format($wp_memory_int) . '</mark>'; |
|
118 | + } |
|
119 | + return array( |
|
120 | + 'name'=>get_bloginfo('name', 'display'), |
|
121 | + 'is_multisite'=>is_multisite(), |
|
122 | + 'version'=> get_bloginfo('version', 'display'), |
|
123 | + 'home_url'=>home_url(), |
|
124 | + 'site_url'=>site_url(), |
|
125 | + 'WP_DEBUG'=>WP_DEBUG, |
|
126 | + 'permalink_structure'=>get_option('permalink_structure'), |
|
127 | + 'theme'=>wp_get_theme(), |
|
128 | + 'gmt_offset'=>get_option('gmt_offset'), |
|
129 | + 'timezone_string'=>get_option('timezone_string'), |
|
130 | + 'admin_email'=> get_bloginfo('admin_email', 'display'), |
|
131 | + 'language'=>get_bloginfo('language', 'display'), |
|
132 | + 'wp_max_upload_size' => size_format(wp_max_upload_size()), |
|
133 | + 'wp_memory' => $wp_memory_to_display |
|
134 | + ); |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * Gets an array of information about the history of ee versions installed |
|
139 | - * @return array |
|
140 | - */ |
|
141 | - public function get_ee_activation_history() |
|
142 | - { |
|
143 | - return get_option('espresso_db_update'); |
|
144 | - } |
|
137 | + /** |
|
138 | + * Gets an array of information about the history of ee versions installed |
|
139 | + * @return array |
|
140 | + */ |
|
141 | + public function get_ee_activation_history() |
|
142 | + { |
|
143 | + return get_option('espresso_db_update'); |
|
144 | + } |
|
145 | 145 | |
146 | 146 | |
147 | - /** |
|
148 | - * Gets an array where keys are ee versions, and their values are arrays indicating all the different times that version was installed |
|
149 | - * @return EE_Data_Migration_Script_Base[] |
|
150 | - */ |
|
151 | - public function get_ee_migration_history() |
|
152 | - { |
|
153 | - $options = EE_Data_Migration_Manager::instance()->get_all_migration_script_options(); |
|
154 | - $presentable_migration_scripts = array(); |
|
155 | - foreach ($options as $option_array) { |
|
156 | - $presentable_migration_scripts[ str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $option_array['option_name']) ] = maybe_unserialize($option_array['option_value']); |
|
157 | - } |
|
158 | - return $presentable_migration_scripts; |
|
147 | + /** |
|
148 | + * Gets an array where keys are ee versions, and their values are arrays indicating all the different times that version was installed |
|
149 | + * @return EE_Data_Migration_Script_Base[] |
|
150 | + */ |
|
151 | + public function get_ee_migration_history() |
|
152 | + { |
|
153 | + $options = EE_Data_Migration_Manager::instance()->get_all_migration_script_options(); |
|
154 | + $presentable_migration_scripts = array(); |
|
155 | + foreach ($options as $option_array) { |
|
156 | + $presentable_migration_scripts[ str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $option_array['option_name']) ] = maybe_unserialize($option_array['option_value']); |
|
157 | + } |
|
158 | + return $presentable_migration_scripts; |
|
159 | 159 | // return get_option(EE_Data_Migration_Manager::data_migrations_option_name);//EE_Data_Migration_Manager::instance()->get_data_migrations_ran(); |
160 | - } |
|
160 | + } |
|
161 | 161 | |
162 | - /** |
|
163 | - * |
|
164 | - * @return array like EE_Config class |
|
165 | - */ |
|
166 | - public function get_ee_config() |
|
167 | - { |
|
168 | - return EE_Config::instance(); |
|
169 | - } |
|
162 | + /** |
|
163 | + * |
|
164 | + * @return array like EE_Config class |
|
165 | + */ |
|
166 | + public function get_ee_config() |
|
167 | + { |
|
168 | + return EE_Config::instance(); |
|
169 | + } |
|
170 | 170 | |
171 | - /** |
|
172 | - * Gets an array of php setup info, pilfered from http://www.php.net/manual/en/function.phpinfo.php#87463 |
|
173 | - * @return array like the output of phpinfo(), but in an array |
|
174 | - */ |
|
175 | - public function get_php_info() |
|
176 | - { |
|
177 | - ob_start(); |
|
178 | - phpinfo(-1); |
|
171 | + /** |
|
172 | + * Gets an array of php setup info, pilfered from http://www.php.net/manual/en/function.phpinfo.php#87463 |
|
173 | + * @return array like the output of phpinfo(), but in an array |
|
174 | + */ |
|
175 | + public function get_php_info() |
|
176 | + { |
|
177 | + ob_start(); |
|
178 | + phpinfo(-1); |
|
179 | 179 | |
180 | - $pi = preg_replace( |
|
181 | - array('#^.*<body>(.*)</body>.*$#ms', '#<h2>PHP License</h2>.*$#ms', |
|
182 | - '#<h1>Configuration</h1>#', "#\r?\n#", "#</(h1|h2|h3|tr)>#", '# +<#', |
|
183 | - "#[ \t]+#", '# #', '# +#', '# class=".*?"#', '%'%', |
|
184 | - '#<tr>(?:.*?)" src="(?:.*?)=(.*?)" alt="PHP Logo" /></a>' |
|
185 | - .'<h1>PHP Version (.*?)</h1>(?:\n+?)</td></tr>#', |
|
186 | - '#<h1><a href="(?:.*?)\?=(.*?)">PHP Credits</a></h1>#', |
|
187 | - '#<tr>(?:.*?)" src="(?:.*?)=(.*?)"(?:.*?)Zend Engine (.*?),(?:.*?)</tr>#', |
|
188 | - "# +#", '#<tr>#', '#</tr>#'), |
|
189 | - array('$1', '', '', '', '</$1>' . "\n", '<', ' ', ' ', ' ', '', ' ', |
|
190 | - '<h2>PHP Configuration</h2>'."\n".'<tr><td>PHP Version</td><td>$2</td></tr>'. |
|
191 | - "\n".'<tr><td>PHP Egg</td><td>$1</td></tr>', |
|
192 | - '<tr><td>PHP Credits Egg</td><td>$1</td></tr>', |
|
193 | - '<tr><td>Zend Engine</td><td>$2</td></tr>' . "\n" . |
|
194 | - '<tr><td>Zend Egg</td><td>$1</td></tr>', ' ', '%S%', '%E%'), |
|
195 | - ob_get_clean() |
|
196 | - ); |
|
180 | + $pi = preg_replace( |
|
181 | + array('#^.*<body>(.*)</body>.*$#ms', '#<h2>PHP License</h2>.*$#ms', |
|
182 | + '#<h1>Configuration</h1>#', "#\r?\n#", "#</(h1|h2|h3|tr)>#", '# +<#', |
|
183 | + "#[ \t]+#", '# #', '# +#', '# class=".*?"#', '%'%', |
|
184 | + '#<tr>(?:.*?)" src="(?:.*?)=(.*?)" alt="PHP Logo" /></a>' |
|
185 | + .'<h1>PHP Version (.*?)</h1>(?:\n+?)</td></tr>#', |
|
186 | + '#<h1><a href="(?:.*?)\?=(.*?)">PHP Credits</a></h1>#', |
|
187 | + '#<tr>(?:.*?)" src="(?:.*?)=(.*?)"(?:.*?)Zend Engine (.*?),(?:.*?)</tr>#', |
|
188 | + "# +#", '#<tr>#', '#</tr>#'), |
|
189 | + array('$1', '', '', '', '</$1>' . "\n", '<', ' ', ' ', ' ', '', ' ', |
|
190 | + '<h2>PHP Configuration</h2>'."\n".'<tr><td>PHP Version</td><td>$2</td></tr>'. |
|
191 | + "\n".'<tr><td>PHP Egg</td><td>$1</td></tr>', |
|
192 | + '<tr><td>PHP Credits Egg</td><td>$1</td></tr>', |
|
193 | + '<tr><td>Zend Engine</td><td>$2</td></tr>' . "\n" . |
|
194 | + '<tr><td>Zend Egg</td><td>$1</td></tr>', ' ', '%S%', '%E%'), |
|
195 | + ob_get_clean() |
|
196 | + ); |
|
197 | 197 | |
198 | - $sections = explode('<h2>', strip_tags($pi, '<h2><th><td>')); |
|
199 | - unset($sections[0]); |
|
198 | + $sections = explode('<h2>', strip_tags($pi, '<h2><th><td>')); |
|
199 | + unset($sections[0]); |
|
200 | 200 | |
201 | - $pi = array(); |
|
202 | - foreach ($sections as $section) { |
|
203 | - $n = substr($section, 0, strpos($section, '</h2>')); |
|
204 | - preg_match_all( |
|
205 | - '#%S%(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?%E%#', |
|
206 | - $section, |
|
207 | - $askapache, |
|
208 | - PREG_SET_ORDER |
|
209 | - ); |
|
210 | - foreach ($askapache as $m) { |
|
211 | - $m2 = isset($m[2]) ? $m[2] : null; |
|
212 | - } |
|
213 | - $pi[ $n ][ $m[1] ]=(!isset($m[3])||$m2==$m[3]) ? $m2 : array_slice($m, 2); |
|
214 | - } |
|
201 | + $pi = array(); |
|
202 | + foreach ($sections as $section) { |
|
203 | + $n = substr($section, 0, strpos($section, '</h2>')); |
|
204 | + preg_match_all( |
|
205 | + '#%S%(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?%E%#', |
|
206 | + $section, |
|
207 | + $askapache, |
|
208 | + PREG_SET_ORDER |
|
209 | + ); |
|
210 | + foreach ($askapache as $m) { |
|
211 | + $m2 = isset($m[2]) ? $m[2] : null; |
|
212 | + } |
|
213 | + $pi[ $n ][ $m[1] ]=(!isset($m[3])||$m2==$m[3]) ? $m2 : array_slice($m, 2); |
|
214 | + } |
|
215 | 215 | |
216 | - return $pi; |
|
217 | - } |
|
216 | + return $pi; |
|
217 | + } |
|
218 | 218 | |
219 | - /** |
|
220 | - * Checks if site responds ot HTTPS |
|
221 | - * @return boolean |
|
222 | - */ |
|
223 | - public function get_https_enabled() |
|
224 | - { |
|
225 | - $home = str_replace("http://", "https://", home_url()); |
|
226 | - $response = wp_remote_get($home); |
|
227 | - if ($response instanceof WP_Error) { |
|
228 | - $error_string = ''; |
|
229 | - foreach ($response->errors as $short_name => $description_array) { |
|
230 | - $error_string .= "<b>$short_name</b>: ".implode(", ", $description_array); |
|
231 | - } |
|
232 | - return $error_string; |
|
233 | - } |
|
234 | - return "ok!"; |
|
235 | - } |
|
236 | - /** |
|
237 | - * Whether or not a .maintenance file is detected |
|
238 | - * @return string descripting wp_maintenance_mode status |
|
239 | - */ |
|
240 | - public function get_wp_maintenance_mode() |
|
241 | - { |
|
242 | - $opened = file_exists(ABSPATH . '.maintenance'); |
|
243 | - return $opened ? sprintf(__('%s.maintenance file detected.%s Wordpress may have a failed auto-update which could prevent Event Espresso from updating the database correctly.', 'event_espresso'), '<strong>', '</strong>') : __('.maintenance file not detected. WordPress is not in maintenance mode.', 'event_espresso') ; |
|
244 | - } |
|
245 | - /** |
|
246 | - * Whether or not logging is enabled |
|
247 | - * @return string descripting logging's status |
|
248 | - */ |
|
249 | - public function get_logging_enabled() |
|
250 | - { |
|
251 | - $opened = @fopen(EVENT_ESPRESSO_UPLOAD_DIR . '/logs/espresso_log.txt', 'a'); |
|
252 | - return $opened ? __('Log Directory is writable', 'event_espresso') : sprintf(__('%sLog directory is NOT writable%s', 'event_espresso'), '<mark class="error"', '</mark>') ; |
|
253 | - } |
|
254 | - /** |
|
255 | - * Whether curl ro fsock works |
|
256 | - * @return string describing posting's status |
|
257 | - */ |
|
258 | - public function get_remote_posting() |
|
259 | - { |
|
260 | - $fsock_works = function_exists('fsockopen'); |
|
261 | - $curl_works = function_exists('curl_init'); |
|
262 | - if ($fsock_works && $curl_works) { |
|
263 | - $status = __('Your server has fsockopen and cURL enabled.', 'event_espresso'); |
|
264 | - } elseif ($fsock_works) { |
|
265 | - $status = __('Your server has fsockopen enabled, cURL is disabled.', 'event_espresso'); |
|
266 | - } elseif ($curl_works) { |
|
267 | - $status = __('Your server has cURL enabled, fsockopen is disabled.', 'event_espresso'); |
|
268 | - } else { |
|
269 | - $status = __('Your server does not have fsockopen or cURL enabled - PayPal IPN and other scripts which communicate with other servers will not work. Contact your hosting provider.', 'event_espresso'). '</mark>'; |
|
270 | - } |
|
271 | - return $status; |
|
272 | - } |
|
273 | - /** |
|
274 | - * Gets all the php.ini settings |
|
275 | - * @return array |
|
276 | - */ |
|
277 | - public function get_php_ini_all() |
|
278 | - { |
|
279 | - return ini_get_all(); |
|
280 | - } |
|
281 | - /** |
|
282 | - * Transforms the php.ini notation for numbers (like '2M') to an integer. |
|
283 | - * |
|
284 | - * @param type $size |
|
285 | - * @return int |
|
286 | - */ |
|
287 | - public function let_to_num($size) |
|
288 | - { |
|
289 | - $l = substr($size, -1); |
|
290 | - $ret = substr($size, 0, -1); |
|
291 | - // phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment |
|
292 | - switch (strtoupper($l)) { |
|
293 | - case 'P': |
|
294 | - $ret *= 1024; |
|
295 | - case 'T': |
|
296 | - $ret *= 1024; |
|
297 | - case 'G': |
|
298 | - $ret *= 1024; |
|
299 | - case 'M': |
|
300 | - $ret *= 1024; |
|
301 | - case 'K': |
|
302 | - $ret *= 1024; |
|
303 | - } |
|
304 | - // phpcs:enable |
|
305 | - return $ret; |
|
306 | - } |
|
219 | + /** |
|
220 | + * Checks if site responds ot HTTPS |
|
221 | + * @return boolean |
|
222 | + */ |
|
223 | + public function get_https_enabled() |
|
224 | + { |
|
225 | + $home = str_replace("http://", "https://", home_url()); |
|
226 | + $response = wp_remote_get($home); |
|
227 | + if ($response instanceof WP_Error) { |
|
228 | + $error_string = ''; |
|
229 | + foreach ($response->errors as $short_name => $description_array) { |
|
230 | + $error_string .= "<b>$short_name</b>: ".implode(", ", $description_array); |
|
231 | + } |
|
232 | + return $error_string; |
|
233 | + } |
|
234 | + return "ok!"; |
|
235 | + } |
|
236 | + /** |
|
237 | + * Whether or not a .maintenance file is detected |
|
238 | + * @return string descripting wp_maintenance_mode status |
|
239 | + */ |
|
240 | + public function get_wp_maintenance_mode() |
|
241 | + { |
|
242 | + $opened = file_exists(ABSPATH . '.maintenance'); |
|
243 | + return $opened ? sprintf(__('%s.maintenance file detected.%s Wordpress may have a failed auto-update which could prevent Event Espresso from updating the database correctly.', 'event_espresso'), '<strong>', '</strong>') : __('.maintenance file not detected. WordPress is not in maintenance mode.', 'event_espresso') ; |
|
244 | + } |
|
245 | + /** |
|
246 | + * Whether or not logging is enabled |
|
247 | + * @return string descripting logging's status |
|
248 | + */ |
|
249 | + public function get_logging_enabled() |
|
250 | + { |
|
251 | + $opened = @fopen(EVENT_ESPRESSO_UPLOAD_DIR . '/logs/espresso_log.txt', 'a'); |
|
252 | + return $opened ? __('Log Directory is writable', 'event_espresso') : sprintf(__('%sLog directory is NOT writable%s', 'event_espresso'), '<mark class="error"', '</mark>') ; |
|
253 | + } |
|
254 | + /** |
|
255 | + * Whether curl ro fsock works |
|
256 | + * @return string describing posting's status |
|
257 | + */ |
|
258 | + public function get_remote_posting() |
|
259 | + { |
|
260 | + $fsock_works = function_exists('fsockopen'); |
|
261 | + $curl_works = function_exists('curl_init'); |
|
262 | + if ($fsock_works && $curl_works) { |
|
263 | + $status = __('Your server has fsockopen and cURL enabled.', 'event_espresso'); |
|
264 | + } elseif ($fsock_works) { |
|
265 | + $status = __('Your server has fsockopen enabled, cURL is disabled.', 'event_espresso'); |
|
266 | + } elseif ($curl_works) { |
|
267 | + $status = __('Your server has cURL enabled, fsockopen is disabled.', 'event_espresso'); |
|
268 | + } else { |
|
269 | + $status = __('Your server does not have fsockopen or cURL enabled - PayPal IPN and other scripts which communicate with other servers will not work. Contact your hosting provider.', 'event_espresso'). '</mark>'; |
|
270 | + } |
|
271 | + return $status; |
|
272 | + } |
|
273 | + /** |
|
274 | + * Gets all the php.ini settings |
|
275 | + * @return array |
|
276 | + */ |
|
277 | + public function get_php_ini_all() |
|
278 | + { |
|
279 | + return ini_get_all(); |
|
280 | + } |
|
281 | + /** |
|
282 | + * Transforms the php.ini notation for numbers (like '2M') to an integer. |
|
283 | + * |
|
284 | + * @param type $size |
|
285 | + * @return int |
|
286 | + */ |
|
287 | + public function let_to_num($size) |
|
288 | + { |
|
289 | + $l = substr($size, -1); |
|
290 | + $ret = substr($size, 0, -1); |
|
291 | + // phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment |
|
292 | + switch (strtoupper($l)) { |
|
293 | + case 'P': |
|
294 | + $ret *= 1024; |
|
295 | + case 'T': |
|
296 | + $ret *= 1024; |
|
297 | + case 'G': |
|
298 | + $ret *= 1024; |
|
299 | + case 'M': |
|
300 | + $ret *= 1024; |
|
301 | + case 'K': |
|
302 | + $ret *= 1024; |
|
303 | + } |
|
304 | + // phpcs:enable |
|
305 | + return $ret; |
|
306 | + } |
|
307 | 307 | } |