@@ -13,132 +13,132 @@ |
||
| 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 for the WP REST API |
|
| 126 | - * |
|
| 127 | - * @return bool |
|
| 128 | - */ |
|
| 129 | - public function isWordPressApi(); |
|
| 124 | + /** |
|
| 125 | + * true if the current request is for the WP REST API |
|
| 126 | + * |
|
| 127 | + * @return bool |
|
| 128 | + */ |
|
| 129 | + public function isWordPressApi(); |
|
| 130 | 130 | |
| 131 | 131 | |
| 132 | - /** |
|
| 133 | - * true if the current request is a loopback sent from WP core to test for errors |
|
| 134 | - * |
|
| 135 | - * @return bool |
|
| 136 | - */ |
|
| 137 | - public function isWordPressScrape(); |
|
| 132 | + /** |
|
| 133 | + * true if the current request is a loopback sent from WP core to test for errors |
|
| 134 | + * |
|
| 135 | + * @return bool |
|
| 136 | + */ |
|
| 137 | + public function isWordPressScrape(); |
|
| 138 | 138 | |
| 139 | 139 | |
| 140 | - /** |
|
| 141 | - * @return string |
|
| 142 | - */ |
|
| 143 | - public function slug(); |
|
| 140 | + /** |
|
| 141 | + * @return string |
|
| 142 | + */ |
|
| 143 | + public function slug(); |
|
| 144 | 144 | } |
@@ -16,206 +16,206 @@ |
||
| 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 for the WP REST API |
|
| 194 | - * |
|
| 195 | - * @return bool |
|
| 196 | - */ |
|
| 197 | - public function isWordPressApi() |
|
| 198 | - { |
|
| 199 | - return $this->request_type->slug() === RequestTypeContext::WP_API; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * true if the current request is a loopback sent from WP core to test for errors |
|
| 205 | - * |
|
| 206 | - * @return bool |
|
| 207 | - */ |
|
| 208 | - public function isWordPressScrape() |
|
| 209 | - { |
|
| 210 | - return $this->request_type->slug() === RequestTypeContext::WP_SCRAPE; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * @return string |
|
| 216 | - */ |
|
| 217 | - public function slug() |
|
| 218 | - { |
|
| 219 | - return $this->request_type->slug(); |
|
| 220 | - } |
|
| 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 for the WP REST API |
|
| 194 | + * |
|
| 195 | + * @return bool |
|
| 196 | + */ |
|
| 197 | + public function isWordPressApi() |
|
| 198 | + { |
|
| 199 | + return $this->request_type->slug() === RequestTypeContext::WP_API; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * true if the current request is a loopback sent from WP core to test for errors |
|
| 205 | + * |
|
| 206 | + * @return bool |
|
| 207 | + */ |
|
| 208 | + public function isWordPressScrape() |
|
| 209 | + { |
|
| 210 | + return $this->request_type->slug() === RequestTypeContext::WP_SCRAPE; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * @return string |
|
| 216 | + */ |
|
| 217 | + public function slug() |
|
| 218 | + { |
|
| 219 | + return $this->request_type->slug(); |
|
| 220 | + } |
|
| 221 | 221 | } |
@@ -16,149 +16,149 @@ |
||
| 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 for the WP REST API |
|
| 76 | - */ |
|
| 77 | - const WP_API = 'wp-rest-api'; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * indicates that the current request is a loopback sent from WP core to test for errors |
|
| 81 | - */ |
|
| 82 | - const WP_SCRAPE = 'wordpress-scrape'; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @var boolean $is_activation |
|
| 86 | - */ |
|
| 87 | - private $is_activation = false; |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @var array $valid_request_types |
|
| 91 | - */ |
|
| 92 | - private $valid_request_types = array(); |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * RequestTypeContext constructor. |
|
| 97 | - * |
|
| 98 | - * @param string $slug |
|
| 99 | - * @param string $description |
|
| 100 | - * @throws InvalidArgumentException |
|
| 101 | - */ |
|
| 102 | - public function __construct($slug, $description) |
|
| 103 | - { |
|
| 104 | - parent::__construct($slug, $description); |
|
| 105 | - if (! in_array($this->slug(), $this->validRequestTypes(), true)) { |
|
| 106 | - throw new InvalidArgumentException( |
|
| 107 | - sprintf( |
|
| 108 | - esc_html__( |
|
| 109 | - 'The RequestTypeContext slug must be one of the following values: %1$s %2$s', |
|
| 110 | - 'event_espresso' |
|
| 111 | - ), |
|
| 112 | - var_export($this->validRequestTypes(), true) |
|
| 113 | - ) |
|
| 114 | - ); |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * @return array |
|
| 121 | - */ |
|
| 122 | - public function validRequestTypes() |
|
| 123 | - { |
|
| 124 | - if (empty($this->valid_request_types)) { |
|
| 125 | - $this->valid_request_types = apply_filters( |
|
| 126 | - 'FHEE__EventEspresso_core_domain_entities_contexts_RequestTypeContext__validRequestTypes', |
|
| 127 | - array( |
|
| 128 | - RequestTypeContext::ACTIVATION, |
|
| 129 | - RequestTypeContext::ADMIN, |
|
| 130 | - RequestTypeContext::AJAX_ADMIN, |
|
| 131 | - RequestTypeContext::AJAX_FRONT, |
|
| 132 | - RequestTypeContext::AJAX_OTHER, |
|
| 133 | - RequestTypeContext::API, |
|
| 134 | - RequestTypeContext::CLI, |
|
| 135 | - RequestTypeContext::CRON, |
|
| 136 | - RequestTypeContext::FEED, |
|
| 137 | - RequestTypeContext::FRONTEND, |
|
| 138 | - RequestTypeContext::IFRAME, |
|
| 139 | - RequestTypeContext::WP_API, |
|
| 140 | - RequestTypeContext::WP_SCRAPE, |
|
| 141 | - ) |
|
| 142 | - ); |
|
| 143 | - } |
|
| 144 | - return $this->valid_request_types; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * @return bool |
|
| 150 | - */ |
|
| 151 | - public function isActivation() |
|
| 152 | - { |
|
| 153 | - return $this->is_activation; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * @param bool $is_activation |
|
| 159 | - */ |
|
| 160 | - public function setIsActivation($is_activation) |
|
| 161 | - { |
|
| 162 | - $this->is_activation = filter_var($is_activation, FILTER_VALIDATE_BOOLEAN); |
|
| 163 | - } |
|
| 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 for the WP REST API |
|
| 76 | + */ |
|
| 77 | + const WP_API = 'wp-rest-api'; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * indicates that the current request is a loopback sent from WP core to test for errors |
|
| 81 | + */ |
|
| 82 | + const WP_SCRAPE = 'wordpress-scrape'; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @var boolean $is_activation |
|
| 86 | + */ |
|
| 87 | + private $is_activation = false; |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @var array $valid_request_types |
|
| 91 | + */ |
|
| 92 | + private $valid_request_types = array(); |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * RequestTypeContext constructor. |
|
| 97 | + * |
|
| 98 | + * @param string $slug |
|
| 99 | + * @param string $description |
|
| 100 | + * @throws InvalidArgumentException |
|
| 101 | + */ |
|
| 102 | + public function __construct($slug, $description) |
|
| 103 | + { |
|
| 104 | + parent::__construct($slug, $description); |
|
| 105 | + if (! in_array($this->slug(), $this->validRequestTypes(), true)) { |
|
| 106 | + throw new InvalidArgumentException( |
|
| 107 | + sprintf( |
|
| 108 | + esc_html__( |
|
| 109 | + 'The RequestTypeContext slug must be one of the following values: %1$s %2$s', |
|
| 110 | + 'event_espresso' |
|
| 111 | + ), |
|
| 112 | + var_export($this->validRequestTypes(), true) |
|
| 113 | + ) |
|
| 114 | + ); |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * @return array |
|
| 121 | + */ |
|
| 122 | + public function validRequestTypes() |
|
| 123 | + { |
|
| 124 | + if (empty($this->valid_request_types)) { |
|
| 125 | + $this->valid_request_types = apply_filters( |
|
| 126 | + 'FHEE__EventEspresso_core_domain_entities_contexts_RequestTypeContext__validRequestTypes', |
|
| 127 | + array( |
|
| 128 | + RequestTypeContext::ACTIVATION, |
|
| 129 | + RequestTypeContext::ADMIN, |
|
| 130 | + RequestTypeContext::AJAX_ADMIN, |
|
| 131 | + RequestTypeContext::AJAX_FRONT, |
|
| 132 | + RequestTypeContext::AJAX_OTHER, |
|
| 133 | + RequestTypeContext::API, |
|
| 134 | + RequestTypeContext::CLI, |
|
| 135 | + RequestTypeContext::CRON, |
|
| 136 | + RequestTypeContext::FEED, |
|
| 137 | + RequestTypeContext::FRONTEND, |
|
| 138 | + RequestTypeContext::IFRAME, |
|
| 139 | + RequestTypeContext::WP_API, |
|
| 140 | + RequestTypeContext::WP_SCRAPE, |
|
| 141 | + ) |
|
| 142 | + ); |
|
| 143 | + } |
|
| 144 | + return $this->valid_request_types; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * @return bool |
|
| 150 | + */ |
|
| 151 | + public function isActivation() |
|
| 152 | + { |
|
| 153 | + return $this->is_activation; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * @param bool $is_activation |
|
| 159 | + */ |
|
| 160 | + public function setIsActivation($is_activation) |
|
| 161 | + { |
|
| 162 | + $this->is_activation = filter_var($is_activation, FILTER_VALIDATE_BOOLEAN); |
|
| 163 | + } |
|
| 164 | 164 | } |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | * |
| 175 | 175 | * @param $key |
| 176 | 176 | * @param null $default |
| 177 | - * @return mixed |
|
| 177 | + * @return integer |
|
| 178 | 178 | */ |
| 179 | 179 | public function getRequestParam($key, $default = null) |
| 180 | 180 | { |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | * would return true if default parameters were set |
| 288 | 288 | * |
| 289 | 289 | * @param string $callback |
| 290 | - * @param $key |
|
| 290 | + * @param string $key |
|
| 291 | 291 | * @param null $default |
| 292 | 292 | * @param array $request_params |
| 293 | 293 | * @return bool|mixed|null |
@@ -17,596 +17,596 @@ |
||
| 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 mixed |
|
| 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 bool |
|
| 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 isWordPressApi() |
|
| 590 | - { |
|
| 591 | - return $this->request_type->isWordPressApi(); |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - |
|
| 595 | - |
|
| 596 | - /** |
|
| 597 | - * @return bool |
|
| 598 | - */ |
|
| 599 | - public function isWordPressScrape() |
|
| 600 | - { |
|
| 601 | - return $this->request_type->isWordPressScrape(); |
|
| 602 | - } |
|
| 603 | - |
|
| 604 | - |
|
| 605 | - /** |
|
| 606 | - * @return string |
|
| 607 | - */ |
|
| 608 | - public function slug() |
|
| 609 | - { |
|
| 610 | - return $this->request_type->slug(); |
|
| 611 | - } |
|
| 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 mixed |
|
| 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 bool |
|
| 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 isWordPressApi() |
|
| 590 | + { |
|
| 591 | + return $this->request_type->isWordPressApi(); |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + |
|
| 595 | + |
|
| 596 | + /** |
|
| 597 | + * @return bool |
|
| 598 | + */ |
|
| 599 | + public function isWordPressScrape() |
|
| 600 | + { |
|
| 601 | + return $this->request_type->isWordPressScrape(); |
|
| 602 | + } |
|
| 603 | + |
|
| 604 | + |
|
| 605 | + /** |
|
| 606 | + * @return string |
|
| 607 | + */ |
|
| 608 | + public function slug() |
|
| 609 | + { |
|
| 610 | + return $this->request_type->slug(); |
|
| 611 | + } |
|
| 612 | 612 | } |
@@ -17,116 +17,116 @@ |
||
| 17 | 17 | class RequestTypeContextFactory implements RequestTypeContextFactoryInterface |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @var LoaderInterface $loader |
|
| 22 | - */ |
|
| 23 | - private $loader; |
|
| 20 | + /** |
|
| 21 | + * @var LoaderInterface $loader |
|
| 22 | + */ |
|
| 23 | + private $loader; |
|
| 24 | 24 | |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * RequestTypeContextFactory constructor. |
|
| 28 | - * |
|
| 29 | - * @param LoaderInterface $loader |
|
| 30 | - */ |
|
| 31 | - public function __construct(LoaderInterface $loader) |
|
| 32 | - { |
|
| 33 | - $this->loader = $loader; |
|
| 34 | - } |
|
| 26 | + /** |
|
| 27 | + * RequestTypeContextFactory constructor. |
|
| 28 | + * |
|
| 29 | + * @param LoaderInterface $loader |
|
| 30 | + */ |
|
| 31 | + public function __construct(LoaderInterface $loader) |
|
| 32 | + { |
|
| 33 | + $this->loader = $loader; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @param string $slug |
|
| 39 | - * @return RequestTypeContext |
|
| 40 | - */ |
|
| 41 | - public function create($slug) |
|
| 42 | - { |
|
| 43 | - switch ($slug) { |
|
| 44 | - case RequestTypeContext::ACTIVATION: |
|
| 45 | - $description = esc_html__( |
|
| 46 | - 'The current request is for some form of activation', |
|
| 47 | - 'event_espresso' |
|
| 48 | - ); |
|
| 49 | - break; |
|
| 50 | - case RequestTypeContext::API: |
|
| 51 | - $description = esc_html__( |
|
| 52 | - 'The current request is for the EE REST API', |
|
| 53 | - 'event_espresso' |
|
| 54 | - ); |
|
| 55 | - break; |
|
| 56 | - case RequestTypeContext::AJAX_FRONT: |
|
| 57 | - $description = esc_html__( |
|
| 58 | - 'The current request is for the frontend via AJAX', |
|
| 59 | - 'event_espresso' |
|
| 60 | - ); |
|
| 61 | - break; |
|
| 62 | - case RequestTypeContext::AJAX_ADMIN: |
|
| 63 | - $description = esc_html__( |
|
| 64 | - 'The current request is for the admin via AJAX', |
|
| 65 | - 'event_espresso' |
|
| 66 | - ); |
|
| 67 | - break; |
|
| 68 | - case RequestTypeContext::AJAX_OTHER: |
|
| 69 | - $description = esc_html__( |
|
| 70 | - 'The current request is for non-EE related code via AJAX', |
|
| 71 | - 'event_espresso' |
|
| 72 | - ); |
|
| 73 | - break; |
|
| 74 | - case RequestTypeContext::CRON: |
|
| 75 | - $description = esc_html__( |
|
| 76 | - 'The current request is for a WP_Cron', |
|
| 77 | - 'event_espresso' |
|
| 78 | - ); |
|
| 79 | - break; |
|
| 80 | - case RequestTypeContext::CLI: |
|
| 81 | - $description = esc_html__( |
|
| 82 | - 'The current request is from the command line', |
|
| 83 | - 'event_espresso' |
|
| 84 | - ); |
|
| 85 | - break; |
|
| 86 | - case RequestTypeContext::ADMIN: |
|
| 87 | - $description = esc_html__( |
|
| 88 | - 'The current request is for the admin', |
|
| 89 | - 'event_espresso' |
|
| 90 | - ); |
|
| 91 | - break; |
|
| 92 | - case RequestTypeContext::IFRAME: |
|
| 93 | - $description = esc_html__( |
|
| 94 | - 'The current request is for an iframe', |
|
| 95 | - 'event_espresso' |
|
| 96 | - ); |
|
| 97 | - break; |
|
| 98 | - case RequestTypeContext::FEED: |
|
| 99 | - $description = esc_html__( |
|
| 100 | - 'The current request is for a feed (ie: RSS)', |
|
| 101 | - 'event_espresso' |
|
| 102 | - ); |
|
| 103 | - break; |
|
| 104 | - case RequestTypeContext::WP_API: |
|
| 105 | - $description = esc_html__( |
|
| 106 | - 'The current request is for the WordPress REST API', |
|
| 107 | - 'event_espresso' |
|
| 108 | - ); |
|
| 109 | - break; |
|
| 110 | - case RequestTypeContext::WP_SCRAPE: |
|
| 111 | - $description = esc_html__( |
|
| 112 | - 'The current request is for a WordPress loopback scrape', |
|
| 113 | - 'event_espresso' |
|
| 114 | - ); |
|
| 115 | - break; |
|
| 116 | - case RequestTypeContext::FRONTEND: |
|
| 117 | - default: |
|
| 118 | - $description = esc_html__( |
|
| 119 | - 'The current request is for the frontend', |
|
| 120 | - 'event_espresso' |
|
| 121 | - ); |
|
| 122 | - break; |
|
| 123 | - } |
|
| 124 | - // we're using the Loader with sharing turned on, |
|
| 125 | - // so that the generated RequestTypeContext object is accessible anywhere |
|
| 126 | - // by simply requesting it again from the loader |
|
| 127 | - return $this->loader->getShared( |
|
| 128 | - 'EventEspresso\core\domain\entities\contexts\RequestTypeContext', |
|
| 129 | - array($slug, $description) |
|
| 130 | - ); |
|
| 131 | - } |
|
| 37 | + /** |
|
| 38 | + * @param string $slug |
|
| 39 | + * @return RequestTypeContext |
|
| 40 | + */ |
|
| 41 | + public function create($slug) |
|
| 42 | + { |
|
| 43 | + switch ($slug) { |
|
| 44 | + case RequestTypeContext::ACTIVATION: |
|
| 45 | + $description = esc_html__( |
|
| 46 | + 'The current request is for some form of activation', |
|
| 47 | + 'event_espresso' |
|
| 48 | + ); |
|
| 49 | + break; |
|
| 50 | + case RequestTypeContext::API: |
|
| 51 | + $description = esc_html__( |
|
| 52 | + 'The current request is for the EE REST API', |
|
| 53 | + 'event_espresso' |
|
| 54 | + ); |
|
| 55 | + break; |
|
| 56 | + case RequestTypeContext::AJAX_FRONT: |
|
| 57 | + $description = esc_html__( |
|
| 58 | + 'The current request is for the frontend via AJAX', |
|
| 59 | + 'event_espresso' |
|
| 60 | + ); |
|
| 61 | + break; |
|
| 62 | + case RequestTypeContext::AJAX_ADMIN: |
|
| 63 | + $description = esc_html__( |
|
| 64 | + 'The current request is for the admin via AJAX', |
|
| 65 | + 'event_espresso' |
|
| 66 | + ); |
|
| 67 | + break; |
|
| 68 | + case RequestTypeContext::AJAX_OTHER: |
|
| 69 | + $description = esc_html__( |
|
| 70 | + 'The current request is for non-EE related code via AJAX', |
|
| 71 | + 'event_espresso' |
|
| 72 | + ); |
|
| 73 | + break; |
|
| 74 | + case RequestTypeContext::CRON: |
|
| 75 | + $description = esc_html__( |
|
| 76 | + 'The current request is for a WP_Cron', |
|
| 77 | + 'event_espresso' |
|
| 78 | + ); |
|
| 79 | + break; |
|
| 80 | + case RequestTypeContext::CLI: |
|
| 81 | + $description = esc_html__( |
|
| 82 | + 'The current request is from the command line', |
|
| 83 | + 'event_espresso' |
|
| 84 | + ); |
|
| 85 | + break; |
|
| 86 | + case RequestTypeContext::ADMIN: |
|
| 87 | + $description = esc_html__( |
|
| 88 | + 'The current request is for the admin', |
|
| 89 | + 'event_espresso' |
|
| 90 | + ); |
|
| 91 | + break; |
|
| 92 | + case RequestTypeContext::IFRAME: |
|
| 93 | + $description = esc_html__( |
|
| 94 | + 'The current request is for an iframe', |
|
| 95 | + 'event_espresso' |
|
| 96 | + ); |
|
| 97 | + break; |
|
| 98 | + case RequestTypeContext::FEED: |
|
| 99 | + $description = esc_html__( |
|
| 100 | + 'The current request is for a feed (ie: RSS)', |
|
| 101 | + 'event_espresso' |
|
| 102 | + ); |
|
| 103 | + break; |
|
| 104 | + case RequestTypeContext::WP_API: |
|
| 105 | + $description = esc_html__( |
|
| 106 | + 'The current request is for the WordPress REST API', |
|
| 107 | + 'event_espresso' |
|
| 108 | + ); |
|
| 109 | + break; |
|
| 110 | + case RequestTypeContext::WP_SCRAPE: |
|
| 111 | + $description = esc_html__( |
|
| 112 | + 'The current request is for a WordPress loopback scrape', |
|
| 113 | + 'event_espresso' |
|
| 114 | + ); |
|
| 115 | + break; |
|
| 116 | + case RequestTypeContext::FRONTEND: |
|
| 117 | + default: |
|
| 118 | + $description = esc_html__( |
|
| 119 | + 'The current request is for the frontend', |
|
| 120 | + 'event_espresso' |
|
| 121 | + ); |
|
| 122 | + break; |
|
| 123 | + } |
|
| 124 | + // we're using the Loader with sharing turned on, |
|
| 125 | + // so that the generated RequestTypeContext object is accessible anywhere |
|
| 126 | + // by simply requesting it again from the loader |
|
| 127 | + return $this->loader->getShared( |
|
| 128 | + 'EventEspresso\core\domain\entities\contexts\RequestTypeContext', |
|
| 129 | + array($slug, $description) |
|
| 130 | + ); |
|
| 131 | + } |
|
| 132 | 132 | } |
@@ -15,9 +15,9 @@ |
||
| 15 | 15 | interface RequestTypeContextFactoryInterface |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * @param string $slug |
|
| 20 | - * @return RequestTypeContext |
|
| 21 | - */ |
|
| 22 | - public function create($slug); |
|
| 18 | + /** |
|
| 19 | + * @param string $slug |
|
| 20 | + * @return RequestTypeContext |
|
| 21 | + */ |
|
| 22 | + public function create($slug); |
|
| 23 | 23 | } |
@@ -18,41 +18,41 @@ |
||
| 18 | 18 | class SetRequestTypeContextChecker extends Middleware |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * converts a Request to a Response |
|
| 23 | - * |
|
| 24 | - * @param RequestInterface $request |
|
| 25 | - * @param ResponseInterface $response |
|
| 26 | - * @return ResponseInterface |
|
| 27 | - * @throws InvalidArgumentException |
|
| 28 | - */ |
|
| 29 | - public function handleRequest(RequestInterface $request, ResponseInterface $response) |
|
| 30 | - { |
|
| 31 | - $this->request = $request; |
|
| 32 | - $this->response = $response; |
|
| 33 | - /** @var RequestTypeContextDetector $request_type_context_detector */ |
|
| 34 | - $request_type_context_detector = $this->loader->getShared( |
|
| 35 | - 'EventEspresso\core\domain\services\contexts\RequestTypeContextDetector', |
|
| 36 | - array( |
|
| 37 | - $this->request, |
|
| 38 | - $this->loader->getShared( |
|
| 39 | - 'EventEspresso\core\domain\services\contexts\RequestTypeContextFactory', |
|
| 40 | - array($this->loader) |
|
| 41 | - ), |
|
| 42 | - array( |
|
| 43 | - 'DOING_AJAX' => defined('DOING_AJAX') && DOING_AJAX, |
|
| 44 | - 'WP_CLI' => defined('WP_CLI') && WP_CLI, |
|
| 45 | - 'is_admin' => is_admin(), |
|
| 46 | - ) |
|
| 47 | - ) |
|
| 48 | - ); |
|
| 49 | - $request_type_context = $request_type_context_detector->detectRequestTypeContext(); |
|
| 50 | - $request_type_context_checker = $this->loader->getShared( |
|
| 51 | - 'EventEspresso\core\domain\services\contexts\RequestTypeContextChecker', |
|
| 52 | - array($request_type_context) |
|
| 53 | - ); |
|
| 54 | - $this->request->setRequestTypeContextChecker($request_type_context_checker); |
|
| 55 | - $this->response = $this->processRequestStack($this->request, $this->response); |
|
| 56 | - return $this->response; |
|
| 57 | - } |
|
| 21 | + /** |
|
| 22 | + * converts a Request to a Response |
|
| 23 | + * |
|
| 24 | + * @param RequestInterface $request |
|
| 25 | + * @param ResponseInterface $response |
|
| 26 | + * @return ResponseInterface |
|
| 27 | + * @throws InvalidArgumentException |
|
| 28 | + */ |
|
| 29 | + public function handleRequest(RequestInterface $request, ResponseInterface $response) |
|
| 30 | + { |
|
| 31 | + $this->request = $request; |
|
| 32 | + $this->response = $response; |
|
| 33 | + /** @var RequestTypeContextDetector $request_type_context_detector */ |
|
| 34 | + $request_type_context_detector = $this->loader->getShared( |
|
| 35 | + 'EventEspresso\core\domain\services\contexts\RequestTypeContextDetector', |
|
| 36 | + array( |
|
| 37 | + $this->request, |
|
| 38 | + $this->loader->getShared( |
|
| 39 | + 'EventEspresso\core\domain\services\contexts\RequestTypeContextFactory', |
|
| 40 | + array($this->loader) |
|
| 41 | + ), |
|
| 42 | + array( |
|
| 43 | + 'DOING_AJAX' => defined('DOING_AJAX') && DOING_AJAX, |
|
| 44 | + 'WP_CLI' => defined('WP_CLI') && WP_CLI, |
|
| 45 | + 'is_admin' => is_admin(), |
|
| 46 | + ) |
|
| 47 | + ) |
|
| 48 | + ); |
|
| 49 | + $request_type_context = $request_type_context_detector->detectRequestTypeContext(); |
|
| 50 | + $request_type_context_checker = $this->loader->getShared( |
|
| 51 | + 'EventEspresso\core\domain\services\contexts\RequestTypeContextChecker', |
|
| 52 | + array($request_type_context) |
|
| 53 | + ); |
|
| 54 | + $this->request->setRequestTypeContextChecker($request_type_context_checker); |
|
| 55 | + $this->response = $this->processRequestStack($this->request, $this->response); |
|
| 56 | + return $this->response; |
|
| 57 | + } |
|
| 58 | 58 | } |
@@ -27,322 +27,322 @@ |
||
| 27 | 27 | class CoreAssetManager extends AssetManager |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - // WordPress core / Third party JS asset handles |
|
| 31 | - const JS_HANDLE_JQUERY = 'jquery'; |
|
| 32 | - |
|
| 33 | - const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate'; |
|
| 34 | - |
|
| 35 | - const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods'; |
|
| 36 | - |
|
| 37 | - const JS_HANDLE_UNDERSCORE = 'underscore'; |
|
| 38 | - |
|
| 39 | - const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core'; |
|
| 40 | - |
|
| 41 | - // EE JS assets handles |
|
| 42 | - const JS_HANDLE_EE_MANIFEST = 'ee-manifest'; |
|
| 43 | - |
|
| 44 | - const JS_HANDLE_EE_JS_CORE = 'eejs-core'; |
|
| 45 | - |
|
| 46 | - const JS_HANDLE_EE_VENDOR = 'eventespresso-vendor'; |
|
| 47 | - |
|
| 48 | - const JS_HANDLE_EE_CORE = 'espresso_core'; |
|
| 49 | - |
|
| 50 | - const JS_HANDLE_EE_I18N = 'eei18n'; |
|
| 51 | - |
|
| 52 | - const JS_HANDLE_EE_ACCOUNTING = 'ee-accounting'; |
|
| 53 | - |
|
| 54 | - const JS_HANDLE_EE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page'; |
|
| 55 | - |
|
| 56 | - // EE CSS assets handles |
|
| 57 | - const CSS_HANDLE_EE_DEFAULT = 'espresso_default'; |
|
| 58 | - |
|
| 59 | - const CSS_HANDLE_EE_CUSTOM = 'espresso_custom_css'; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @var EE_Currency_Config $currency_config |
|
| 63 | - */ |
|
| 64 | - protected $currency_config; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @var EE_Template_Config $template_config |
|
| 68 | - */ |
|
| 69 | - protected $template_config; |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * CoreAssetRegister constructor. |
|
| 74 | - * |
|
| 75 | - * @param AssetCollection $assets |
|
| 76 | - * @param EE_Currency_Config $currency_config |
|
| 77 | - * @param EE_Template_Config $template_config |
|
| 78 | - * @param DomainInterface $domain |
|
| 79 | - * @param Registry $registry |
|
| 80 | - */ |
|
| 81 | - public function __construct( |
|
| 82 | - AssetCollection $assets, |
|
| 83 | - EE_Currency_Config $currency_config, |
|
| 84 | - EE_Template_Config $template_config, |
|
| 85 | - DomainInterface $domain, |
|
| 86 | - Registry $registry |
|
| 87 | - ) { |
|
| 88 | - $this->currency_config = $currency_config; |
|
| 89 | - $this->template_config = $template_config; |
|
| 90 | - parent::__construct($domain, $assets, $registry); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @since 4.9.62.p |
|
| 96 | - * @throws DuplicateCollectionIdentifierException |
|
| 97 | - * @throws InvalidArgumentException |
|
| 98 | - * @throws InvalidDataTypeException |
|
| 99 | - * @throws InvalidEntityException |
|
| 100 | - */ |
|
| 101 | - public function addAssets() |
|
| 102 | - { |
|
| 103 | - $this->addJavascriptFiles(); |
|
| 104 | - $this->addStylesheetFiles(); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @since 4.9.62.p |
|
| 110 | - * @throws DuplicateCollectionIdentifierException |
|
| 111 | - * @throws InvalidArgumentException |
|
| 112 | - * @throws InvalidDataTypeException |
|
| 113 | - * @throws InvalidEntityException |
|
| 114 | - */ |
|
| 115 | - public function addJavascriptFiles() |
|
| 116 | - { |
|
| 117 | - $this->loadCoreJs(); |
|
| 118 | - $this->loadJqueryValidate(); |
|
| 119 | - $this->loadAccountingJs(); |
|
| 120 | - add_action( |
|
| 121 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script', |
|
| 122 | - array($this, 'loadQtipJs') |
|
| 123 | - ); |
|
| 124 | - $this->registerAdminAssets(); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * @since 4.9.62.p |
|
| 130 | - * @throws DuplicateCollectionIdentifierException |
|
| 131 | - * @throws InvalidDataTypeException |
|
| 132 | - * @throws InvalidEntityException |
|
| 133 | - */ |
|
| 134 | - public function addStylesheetFiles() |
|
| 135 | - { |
|
| 136 | - $this->loadCoreCss(); |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * core default javascript |
|
| 142 | - * |
|
| 143 | - * @since 4.9.62.p |
|
| 144 | - * @throws DuplicateCollectionIdentifierException |
|
| 145 | - * @throws InvalidArgumentException |
|
| 146 | - * @throws InvalidDataTypeException |
|
| 147 | - * @throws InvalidEntityException |
|
| 148 | - */ |
|
| 149 | - private function loadCoreJs() |
|
| 150 | - { |
|
| 151 | - $this->addJavascript( |
|
| 152 | - CoreAssetManager::JS_HANDLE_EE_MANIFEST, |
|
| 153 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'manifest') |
|
| 154 | - ); |
|
| 155 | - |
|
| 156 | - $this->addJavascript( |
|
| 157 | - CoreAssetManager::JS_HANDLE_EE_JS_CORE, |
|
| 158 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'eejs'), |
|
| 159 | - array(CoreAssetManager::JS_HANDLE_EE_MANIFEST) |
|
| 160 | - ) |
|
| 161 | - ->setHasInlineData(); |
|
| 162 | - |
|
| 163 | - $this->addJavascript( |
|
| 164 | - CoreAssetManager::JS_HANDLE_EE_VENDOR, |
|
| 165 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'vendor'), |
|
| 166 | - array(CoreAssetManager::JS_HANDLE_EE_JS_CORE) |
|
| 167 | - ); |
|
| 168 | - |
|
| 169 | - $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest')); |
|
| 170 | - $this->registry->addData( |
|
| 171 | - 'paths', |
|
| 172 | - array( |
|
| 173 | - 'rest_route' => rest_url('ee/v4.8.36/'), |
|
| 174 | - 'site_url' => site_url('/'), |
|
| 175 | - 'admin_url' => admin_url('/'), |
|
| 176 | - ) |
|
| 177 | - ); |
|
| 178 | - |
|
| 179 | - $this->addJavascript( |
|
| 180 | - CoreAssetManager::JS_HANDLE_EE_CORE, |
|
| 181 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 182 | - array(CoreAssetManager::JS_HANDLE_JQUERY) |
|
| 183 | - ) |
|
| 184 | - ->setInlineDataCallback( |
|
| 185 | - function () { |
|
| 186 | - wp_localize_script( |
|
| 187 | - CoreAssetManager::JS_HANDLE_EE_CORE, |
|
| 188 | - CoreAssetManager::JS_HANDLE_EE_I18N, |
|
| 189 | - EE_Registry::$i18n_js_strings |
|
| 190 | - ); |
|
| 191 | - } |
|
| 192 | - ); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * @since 4.9.62.p |
|
| 198 | - * @throws DuplicateCollectionIdentifierException |
|
| 199 | - * @throws InvalidDataTypeException |
|
| 200 | - * @throws InvalidEntityException |
|
| 201 | - */ |
|
| 202 | - private function loadCoreCss() |
|
| 203 | - { |
|
| 204 | - if ($this->template_config->enable_default_style && ! is_admin()) { |
|
| 205 | - $this->addStylesheet( |
|
| 206 | - CoreAssetManager::CSS_HANDLE_EE_DEFAULT, |
|
| 207 | - is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
| 208 | - ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
| 209 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
| 210 | - array('dashicons') |
|
| 211 | - ); |
|
| 212 | - //Load custom style sheet if available |
|
| 213 | - if ($this->template_config->custom_style_sheet !== null) { |
|
| 214 | - $this->addStylesheet( |
|
| 215 | - CoreAssetManager::CSS_HANDLE_EE_CUSTOM, |
|
| 216 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
| 217 | - array(CoreAssetManager::CSS_HANDLE_EE_DEFAULT) |
|
| 218 | - ); |
|
| 219 | - } |
|
| 220 | - } |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * jQuery Validate for form validation |
|
| 226 | - * |
|
| 227 | - * @since 4.9.62.p |
|
| 228 | - * @throws DuplicateCollectionIdentifierException |
|
| 229 | - * @throws InvalidDataTypeException |
|
| 230 | - * @throws InvalidEntityException |
|
| 231 | - */ |
|
| 232 | - private function loadJqueryValidate() |
|
| 233 | - { |
|
| 234 | - $this->addJavascript( |
|
| 235 | - CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE, |
|
| 236 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
| 237 | - array(CoreAssetManager::JS_HANDLE_JQUERY) |
|
| 238 | - ) |
|
| 239 | - ->setVersion('1.15.0'); |
|
| 240 | - |
|
| 241 | - $this->addJavascript( |
|
| 242 | - CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA, |
|
| 243 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
| 244 | - array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE) |
|
| 245 | - ) |
|
| 246 | - ->setVersion('1.15.0'); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * accounting.js for performing client-side calculations |
|
| 252 | - * |
|
| 253 | - * @since 4.9.62.p |
|
| 254 | - * @throws DuplicateCollectionIdentifierException |
|
| 255 | - * @throws InvalidDataTypeException |
|
| 256 | - * @throws InvalidEntityException |
|
| 257 | - */ |
|
| 258 | - private function loadAccountingJs() |
|
| 259 | - { |
|
| 260 | - //accounting.js library |
|
| 261 | - // @link http://josscrowcroft.github.io/accounting.js/ |
|
| 262 | - $this->addJavascript( |
|
| 263 | - CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE, |
|
| 264 | - EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
| 265 | - array(CoreAssetManager::JS_HANDLE_UNDERSCORE) |
|
| 266 | - ) |
|
| 267 | - ->setVersion('0.3.2'); |
|
| 268 | - |
|
| 269 | - $currency_config = $this->currency_config; |
|
| 270 | - $this->addJavascript( |
|
| 271 | - CoreAssetManager::JS_HANDLE_EE_ACCOUNTING, |
|
| 272 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
| 273 | - array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE) |
|
| 274 | - ) |
|
| 275 | - ->setInlineDataCallback( |
|
| 276 | - function () use ($currency_config) { |
|
| 277 | - wp_localize_script( |
|
| 278 | - CoreAssetManager::JS_HANDLE_EE_ACCOUNTING, |
|
| 279 | - 'EE_ACCOUNTING_CFG', |
|
| 280 | - array( |
|
| 281 | - 'currency' => array( |
|
| 282 | - 'symbol' => $currency_config->sign, |
|
| 283 | - 'format' => array( |
|
| 284 | - 'pos' => $currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
| 285 | - 'neg' => $currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
| 286 | - 'zero' => $currency_config->sign_b4 ? '%s--' : '--%s', |
|
| 287 | - ), |
|
| 288 | - 'decimal' => $currency_config->dec_mrk, |
|
| 289 | - 'thousand' => $currency_config->thsnds, |
|
| 290 | - 'precision' => $currency_config->dec_plc, |
|
| 291 | - ), |
|
| 292 | - 'number' => array( |
|
| 293 | - 'precision' => $currency_config->dec_plc, |
|
| 294 | - 'thousand' => $currency_config->thsnds, |
|
| 295 | - 'decimal' => $currency_config->dec_mrk, |
|
| 296 | - ), |
|
| 297 | - ) |
|
| 298 | - ); |
|
| 299 | - } |
|
| 300 | - ) |
|
| 301 | - ->setVersion(); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * registers assets for cleaning your ears |
|
| 307 | - * |
|
| 308 | - * @param JavascriptAsset $script |
|
| 309 | - */ |
|
| 310 | - public function loadQtipJs(JavascriptAsset $script) |
|
| 311 | - { |
|
| 312 | - // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
| 313 | - // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 314 | - if ( |
|
| 315 | - $script->handle() === CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE |
|
| 316 | - && apply_filters('FHEE_load_qtip', false) |
|
| 317 | - ) { |
|
| 318 | - EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
| 319 | - } |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * assets that are used in the WordPress admin |
|
| 325 | - * |
|
| 326 | - * @since 4.9.62.p |
|
| 327 | - * @throws DuplicateCollectionIdentifierException |
|
| 328 | - * @throws InvalidDataTypeException |
|
| 329 | - * @throws InvalidEntityException |
|
| 330 | - */ |
|
| 331 | - private function registerAdminAssets() |
|
| 332 | - { |
|
| 333 | - $this->addJavascript( |
|
| 334 | - CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE, |
|
| 335 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'wp-plugins-page'), |
|
| 336 | - array( |
|
| 337 | - CoreAssetManager::JS_HANDLE_JQUERY, |
|
| 338 | - CoreAssetManager::JS_HANDLE_EE_VENDOR, |
|
| 339 | - ) |
|
| 340 | - ) |
|
| 341 | - ->setRequiresTranslation(); |
|
| 342 | - |
|
| 343 | - $this->addStylesheet( |
|
| 344 | - CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE, |
|
| 345 | - $this->registry->getCssUrl($this->domain->assetNamespace(), 'wp-plugins-page') |
|
| 346 | - ); |
|
| 347 | - } |
|
| 30 | + // WordPress core / Third party JS asset handles |
|
| 31 | + const JS_HANDLE_JQUERY = 'jquery'; |
|
| 32 | + |
|
| 33 | + const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate'; |
|
| 34 | + |
|
| 35 | + const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods'; |
|
| 36 | + |
|
| 37 | + const JS_HANDLE_UNDERSCORE = 'underscore'; |
|
| 38 | + |
|
| 39 | + const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core'; |
|
| 40 | + |
|
| 41 | + // EE JS assets handles |
|
| 42 | + const JS_HANDLE_EE_MANIFEST = 'ee-manifest'; |
|
| 43 | + |
|
| 44 | + const JS_HANDLE_EE_JS_CORE = 'eejs-core'; |
|
| 45 | + |
|
| 46 | + const JS_HANDLE_EE_VENDOR = 'eventespresso-vendor'; |
|
| 47 | + |
|
| 48 | + const JS_HANDLE_EE_CORE = 'espresso_core'; |
|
| 49 | + |
|
| 50 | + const JS_HANDLE_EE_I18N = 'eei18n'; |
|
| 51 | + |
|
| 52 | + const JS_HANDLE_EE_ACCOUNTING = 'ee-accounting'; |
|
| 53 | + |
|
| 54 | + const JS_HANDLE_EE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page'; |
|
| 55 | + |
|
| 56 | + // EE CSS assets handles |
|
| 57 | + const CSS_HANDLE_EE_DEFAULT = 'espresso_default'; |
|
| 58 | + |
|
| 59 | + const CSS_HANDLE_EE_CUSTOM = 'espresso_custom_css'; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @var EE_Currency_Config $currency_config |
|
| 63 | + */ |
|
| 64 | + protected $currency_config; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @var EE_Template_Config $template_config |
|
| 68 | + */ |
|
| 69 | + protected $template_config; |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * CoreAssetRegister constructor. |
|
| 74 | + * |
|
| 75 | + * @param AssetCollection $assets |
|
| 76 | + * @param EE_Currency_Config $currency_config |
|
| 77 | + * @param EE_Template_Config $template_config |
|
| 78 | + * @param DomainInterface $domain |
|
| 79 | + * @param Registry $registry |
|
| 80 | + */ |
|
| 81 | + public function __construct( |
|
| 82 | + AssetCollection $assets, |
|
| 83 | + EE_Currency_Config $currency_config, |
|
| 84 | + EE_Template_Config $template_config, |
|
| 85 | + DomainInterface $domain, |
|
| 86 | + Registry $registry |
|
| 87 | + ) { |
|
| 88 | + $this->currency_config = $currency_config; |
|
| 89 | + $this->template_config = $template_config; |
|
| 90 | + parent::__construct($domain, $assets, $registry); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @since 4.9.62.p |
|
| 96 | + * @throws DuplicateCollectionIdentifierException |
|
| 97 | + * @throws InvalidArgumentException |
|
| 98 | + * @throws InvalidDataTypeException |
|
| 99 | + * @throws InvalidEntityException |
|
| 100 | + */ |
|
| 101 | + public function addAssets() |
|
| 102 | + { |
|
| 103 | + $this->addJavascriptFiles(); |
|
| 104 | + $this->addStylesheetFiles(); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @since 4.9.62.p |
|
| 110 | + * @throws DuplicateCollectionIdentifierException |
|
| 111 | + * @throws InvalidArgumentException |
|
| 112 | + * @throws InvalidDataTypeException |
|
| 113 | + * @throws InvalidEntityException |
|
| 114 | + */ |
|
| 115 | + public function addJavascriptFiles() |
|
| 116 | + { |
|
| 117 | + $this->loadCoreJs(); |
|
| 118 | + $this->loadJqueryValidate(); |
|
| 119 | + $this->loadAccountingJs(); |
|
| 120 | + add_action( |
|
| 121 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script', |
|
| 122 | + array($this, 'loadQtipJs') |
|
| 123 | + ); |
|
| 124 | + $this->registerAdminAssets(); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * @since 4.9.62.p |
|
| 130 | + * @throws DuplicateCollectionIdentifierException |
|
| 131 | + * @throws InvalidDataTypeException |
|
| 132 | + * @throws InvalidEntityException |
|
| 133 | + */ |
|
| 134 | + public function addStylesheetFiles() |
|
| 135 | + { |
|
| 136 | + $this->loadCoreCss(); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * core default javascript |
|
| 142 | + * |
|
| 143 | + * @since 4.9.62.p |
|
| 144 | + * @throws DuplicateCollectionIdentifierException |
|
| 145 | + * @throws InvalidArgumentException |
|
| 146 | + * @throws InvalidDataTypeException |
|
| 147 | + * @throws InvalidEntityException |
|
| 148 | + */ |
|
| 149 | + private function loadCoreJs() |
|
| 150 | + { |
|
| 151 | + $this->addJavascript( |
|
| 152 | + CoreAssetManager::JS_HANDLE_EE_MANIFEST, |
|
| 153 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'manifest') |
|
| 154 | + ); |
|
| 155 | + |
|
| 156 | + $this->addJavascript( |
|
| 157 | + CoreAssetManager::JS_HANDLE_EE_JS_CORE, |
|
| 158 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'eejs'), |
|
| 159 | + array(CoreAssetManager::JS_HANDLE_EE_MANIFEST) |
|
| 160 | + ) |
|
| 161 | + ->setHasInlineData(); |
|
| 162 | + |
|
| 163 | + $this->addJavascript( |
|
| 164 | + CoreAssetManager::JS_HANDLE_EE_VENDOR, |
|
| 165 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'vendor'), |
|
| 166 | + array(CoreAssetManager::JS_HANDLE_EE_JS_CORE) |
|
| 167 | + ); |
|
| 168 | + |
|
| 169 | + $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest')); |
|
| 170 | + $this->registry->addData( |
|
| 171 | + 'paths', |
|
| 172 | + array( |
|
| 173 | + 'rest_route' => rest_url('ee/v4.8.36/'), |
|
| 174 | + 'site_url' => site_url('/'), |
|
| 175 | + 'admin_url' => admin_url('/'), |
|
| 176 | + ) |
|
| 177 | + ); |
|
| 178 | + |
|
| 179 | + $this->addJavascript( |
|
| 180 | + CoreAssetManager::JS_HANDLE_EE_CORE, |
|
| 181 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 182 | + array(CoreAssetManager::JS_HANDLE_JQUERY) |
|
| 183 | + ) |
|
| 184 | + ->setInlineDataCallback( |
|
| 185 | + function () { |
|
| 186 | + wp_localize_script( |
|
| 187 | + CoreAssetManager::JS_HANDLE_EE_CORE, |
|
| 188 | + CoreAssetManager::JS_HANDLE_EE_I18N, |
|
| 189 | + EE_Registry::$i18n_js_strings |
|
| 190 | + ); |
|
| 191 | + } |
|
| 192 | + ); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * @since 4.9.62.p |
|
| 198 | + * @throws DuplicateCollectionIdentifierException |
|
| 199 | + * @throws InvalidDataTypeException |
|
| 200 | + * @throws InvalidEntityException |
|
| 201 | + */ |
|
| 202 | + private function loadCoreCss() |
|
| 203 | + { |
|
| 204 | + if ($this->template_config->enable_default_style && ! is_admin()) { |
|
| 205 | + $this->addStylesheet( |
|
| 206 | + CoreAssetManager::CSS_HANDLE_EE_DEFAULT, |
|
| 207 | + is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
| 208 | + ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
| 209 | + : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
| 210 | + array('dashicons') |
|
| 211 | + ); |
|
| 212 | + //Load custom style sheet if available |
|
| 213 | + if ($this->template_config->custom_style_sheet !== null) { |
|
| 214 | + $this->addStylesheet( |
|
| 215 | + CoreAssetManager::CSS_HANDLE_EE_CUSTOM, |
|
| 216 | + EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
| 217 | + array(CoreAssetManager::CSS_HANDLE_EE_DEFAULT) |
|
| 218 | + ); |
|
| 219 | + } |
|
| 220 | + } |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * jQuery Validate for form validation |
|
| 226 | + * |
|
| 227 | + * @since 4.9.62.p |
|
| 228 | + * @throws DuplicateCollectionIdentifierException |
|
| 229 | + * @throws InvalidDataTypeException |
|
| 230 | + * @throws InvalidEntityException |
|
| 231 | + */ |
|
| 232 | + private function loadJqueryValidate() |
|
| 233 | + { |
|
| 234 | + $this->addJavascript( |
|
| 235 | + CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE, |
|
| 236 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
| 237 | + array(CoreAssetManager::JS_HANDLE_JQUERY) |
|
| 238 | + ) |
|
| 239 | + ->setVersion('1.15.0'); |
|
| 240 | + |
|
| 241 | + $this->addJavascript( |
|
| 242 | + CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA, |
|
| 243 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
| 244 | + array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE) |
|
| 245 | + ) |
|
| 246 | + ->setVersion('1.15.0'); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * accounting.js for performing client-side calculations |
|
| 252 | + * |
|
| 253 | + * @since 4.9.62.p |
|
| 254 | + * @throws DuplicateCollectionIdentifierException |
|
| 255 | + * @throws InvalidDataTypeException |
|
| 256 | + * @throws InvalidEntityException |
|
| 257 | + */ |
|
| 258 | + private function loadAccountingJs() |
|
| 259 | + { |
|
| 260 | + //accounting.js library |
|
| 261 | + // @link http://josscrowcroft.github.io/accounting.js/ |
|
| 262 | + $this->addJavascript( |
|
| 263 | + CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE, |
|
| 264 | + EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
| 265 | + array(CoreAssetManager::JS_HANDLE_UNDERSCORE) |
|
| 266 | + ) |
|
| 267 | + ->setVersion('0.3.2'); |
|
| 268 | + |
|
| 269 | + $currency_config = $this->currency_config; |
|
| 270 | + $this->addJavascript( |
|
| 271 | + CoreAssetManager::JS_HANDLE_EE_ACCOUNTING, |
|
| 272 | + EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
| 273 | + array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE) |
|
| 274 | + ) |
|
| 275 | + ->setInlineDataCallback( |
|
| 276 | + function () use ($currency_config) { |
|
| 277 | + wp_localize_script( |
|
| 278 | + CoreAssetManager::JS_HANDLE_EE_ACCOUNTING, |
|
| 279 | + 'EE_ACCOUNTING_CFG', |
|
| 280 | + array( |
|
| 281 | + 'currency' => array( |
|
| 282 | + 'symbol' => $currency_config->sign, |
|
| 283 | + 'format' => array( |
|
| 284 | + 'pos' => $currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
| 285 | + 'neg' => $currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
| 286 | + 'zero' => $currency_config->sign_b4 ? '%s--' : '--%s', |
|
| 287 | + ), |
|
| 288 | + 'decimal' => $currency_config->dec_mrk, |
|
| 289 | + 'thousand' => $currency_config->thsnds, |
|
| 290 | + 'precision' => $currency_config->dec_plc, |
|
| 291 | + ), |
|
| 292 | + 'number' => array( |
|
| 293 | + 'precision' => $currency_config->dec_plc, |
|
| 294 | + 'thousand' => $currency_config->thsnds, |
|
| 295 | + 'decimal' => $currency_config->dec_mrk, |
|
| 296 | + ), |
|
| 297 | + ) |
|
| 298 | + ); |
|
| 299 | + } |
|
| 300 | + ) |
|
| 301 | + ->setVersion(); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * registers assets for cleaning your ears |
|
| 307 | + * |
|
| 308 | + * @param JavascriptAsset $script |
|
| 309 | + */ |
|
| 310 | + public function loadQtipJs(JavascriptAsset $script) |
|
| 311 | + { |
|
| 312 | + // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
| 313 | + // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 314 | + if ( |
|
| 315 | + $script->handle() === CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE |
|
| 316 | + && apply_filters('FHEE_load_qtip', false) |
|
| 317 | + ) { |
|
| 318 | + EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * assets that are used in the WordPress admin |
|
| 325 | + * |
|
| 326 | + * @since 4.9.62.p |
|
| 327 | + * @throws DuplicateCollectionIdentifierException |
|
| 328 | + * @throws InvalidDataTypeException |
|
| 329 | + * @throws InvalidEntityException |
|
| 330 | + */ |
|
| 331 | + private function registerAdminAssets() |
|
| 332 | + { |
|
| 333 | + $this->addJavascript( |
|
| 334 | + CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE, |
|
| 335 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'wp-plugins-page'), |
|
| 336 | + array( |
|
| 337 | + CoreAssetManager::JS_HANDLE_JQUERY, |
|
| 338 | + CoreAssetManager::JS_HANDLE_EE_VENDOR, |
|
| 339 | + ) |
|
| 340 | + ) |
|
| 341 | + ->setRequiresTranslation(); |
|
| 342 | + |
|
| 343 | + $this->addStylesheet( |
|
| 344 | + CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE, |
|
| 345 | + $this->registry->getCssUrl($this->domain->assetNamespace(), 'wp-plugins-page') |
|
| 346 | + ); |
|
| 347 | + } |
|
| 348 | 348 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | |
| 44 | 44 | const JS_HANDLE_EE_JS_CORE = 'eejs-core'; |
| 45 | 45 | |
| 46 | - const JS_HANDLE_EE_VENDOR = 'eventespresso-vendor'; |
|
| 46 | + const JS_HANDLE_EE_VENDOR = 'eventespresso-vendor'; |
|
| 47 | 47 | |
| 48 | 48 | const JS_HANDLE_EE_CORE = 'espresso_core'; |
| 49 | 49 | |
@@ -178,11 +178,11 @@ discard block |
||
| 178 | 178 | |
| 179 | 179 | $this->addJavascript( |
| 180 | 180 | CoreAssetManager::JS_HANDLE_EE_CORE, |
| 181 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 181 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', |
|
| 182 | 182 | array(CoreAssetManager::JS_HANDLE_JQUERY) |
| 183 | 183 | ) |
| 184 | 184 | ->setInlineDataCallback( |
| 185 | - function () { |
|
| 185 | + function() { |
|
| 186 | 186 | wp_localize_script( |
| 187 | 187 | CoreAssetManager::JS_HANDLE_EE_CORE, |
| 188 | 188 | CoreAssetManager::JS_HANDLE_EE_I18N, |
@@ -204,16 +204,16 @@ discard block |
||
| 204 | 204 | if ($this->template_config->enable_default_style && ! is_admin()) { |
| 205 | 205 | $this->addStylesheet( |
| 206 | 206 | CoreAssetManager::CSS_HANDLE_EE_DEFAULT, |
| 207 | - is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
| 207 | + is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/style.css') |
|
| 208 | 208 | ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
| 209 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
| 209 | + : EE_GLOBAL_ASSETS_URL.'css/espresso_default.css', |
|
| 210 | 210 | array('dashicons') |
| 211 | 211 | ); |
| 212 | 212 | //Load custom style sheet if available |
| 213 | 213 | if ($this->template_config->custom_style_sheet !== null) { |
| 214 | 214 | $this->addStylesheet( |
| 215 | 215 | CoreAssetManager::CSS_HANDLE_EE_CUSTOM, |
| 216 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
| 216 | + EVENT_ESPRESSO_UPLOAD_URL.'css/'.$this->template_config->custom_style_sheet, |
|
| 217 | 217 | array(CoreAssetManager::CSS_HANDLE_EE_DEFAULT) |
| 218 | 218 | ); |
| 219 | 219 | } |
@@ -233,14 +233,14 @@ discard block |
||
| 233 | 233 | { |
| 234 | 234 | $this->addJavascript( |
| 235 | 235 | CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE, |
| 236 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
| 236 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.min.js', |
|
| 237 | 237 | array(CoreAssetManager::JS_HANDLE_JQUERY) |
| 238 | 238 | ) |
| 239 | 239 | ->setVersion('1.15.0'); |
| 240 | 240 | |
| 241 | 241 | $this->addJavascript( |
| 242 | 242 | CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA, |
| 243 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
| 243 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.additional-methods.min.js', |
|
| 244 | 244 | array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE) |
| 245 | 245 | ) |
| 246 | 246 | ->setVersion('1.15.0'); |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | // @link http://josscrowcroft.github.io/accounting.js/ |
| 262 | 262 | $this->addJavascript( |
| 263 | 263 | CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE, |
| 264 | - EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
| 264 | + EE_THIRD_PARTY_URL.'accounting/accounting.js', |
|
| 265 | 265 | array(CoreAssetManager::JS_HANDLE_UNDERSCORE) |
| 266 | 266 | ) |
| 267 | 267 | ->setVersion('0.3.2'); |
@@ -269,11 +269,11 @@ discard block |
||
| 269 | 269 | $currency_config = $this->currency_config; |
| 270 | 270 | $this->addJavascript( |
| 271 | 271 | CoreAssetManager::JS_HANDLE_EE_ACCOUNTING, |
| 272 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
| 272 | + EE_GLOBAL_ASSETS_URL.'scripts/ee-accounting-config.js', |
|
| 273 | 273 | array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE) |
| 274 | 274 | ) |
| 275 | 275 | ->setInlineDataCallback( |
| 276 | - function () use ($currency_config) { |
|
| 276 | + function() use ($currency_config) { |
|
| 277 | 277 | wp_localize_script( |
| 278 | 278 | CoreAssetManager::JS_HANDLE_EE_ACCOUNTING, |
| 279 | 279 | 'EE_ACCOUNTING_CFG', |
@@ -56,6 +56,8 @@ |
||
| 56 | 56 | |
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | + * @param string $globalRouteCondition |
|
| 60 | + * @param boolean $default |
|
| 59 | 61 | * @return mixed |
| 60 | 62 | */ |
| 61 | 63 | private function getGlobalRouteCondition($globalRouteCondition, $default) |
@@ -18,171 +18,171 @@ |
||
| 18 | 18 | class RequestTypeContextDetector |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var RequestTypeContextFactoryInterface $factory |
|
| 23 | - */ |
|
| 24 | - private $factory; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @var RequestInterface $request |
|
| 28 | - */ |
|
| 29 | - private $request; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var array $globalRouteConditions |
|
| 33 | - */ |
|
| 34 | - private $globalRouteConditions; |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * RequestTypeContextDetector constructor. |
|
| 39 | - * |
|
| 40 | - * @param RequestInterface $request |
|
| 41 | - * @param RequestTypeContextFactoryInterface $factory |
|
| 42 | - * @param array $globalRouteConditions an array for injecting values that would |
|
| 43 | - * otherwise be defined as global constants |
|
| 44 | - * or other global variables for the current |
|
| 45 | - * request route such as DOING_AJAX |
|
| 46 | - */ |
|
| 47 | - public function __construct( |
|
| 48 | - RequestInterface $request, |
|
| 49 | - RequestTypeContextFactoryInterface $factory, |
|
| 50 | - array $globalRouteConditions = array() |
|
| 51 | - ) { |
|
| 52 | - $this->request = $request; |
|
| 53 | - $this->factory = $factory; |
|
| 54 | - $this->globalRouteConditions = $globalRouteConditions; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @return mixed |
|
| 60 | - */ |
|
| 61 | - private function getGlobalRouteCondition($globalRouteCondition, $default) |
|
| 62 | - { |
|
| 63 | - return isset($this->globalRouteConditions[ $globalRouteCondition ]) |
|
| 64 | - ? $this->globalRouteConditions[ $globalRouteCondition ] |
|
| 65 | - : $default; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @return RequestTypeContext |
|
| 71 | - * @throws InvalidArgumentException |
|
| 72 | - */ |
|
| 73 | - public function detectRequestTypeContext() |
|
| 74 | - { |
|
| 75 | - // Detect error scrapes |
|
| 76 | - if ($this->request->getRequestParam('wp_scrape_key') !== null |
|
| 77 | - && $this->request->getRequestParam('wp_scrape_nonce') !== null |
|
| 78 | - ) { |
|
| 79 | - return $this->factory->create(RequestTypeContext::WP_SCRAPE); |
|
| 80 | - } |
|
| 81 | - // Detect EE REST API |
|
| 82 | - if ($this->isEspressoRestApiRequest()) { |
|
| 83 | - return $this->factory->create(RequestTypeContext::API); |
|
| 84 | - } |
|
| 85 | - // Detect WP REST API |
|
| 86 | - if ($this->isWordPressRestApiRequest()) { |
|
| 87 | - return $this->factory->create(RequestTypeContext::WP_API); |
|
| 88 | - } |
|
| 89 | - // Detect AJAX |
|
| 90 | - if ($this->getGlobalRouteCondition('DOING_AJAX', false)) { |
|
| 91 | - if (filter_var($this->request->getRequestParam('ee_front_ajax'), FILTER_VALIDATE_BOOLEAN)) { |
|
| 92 | - return $this->factory->create(RequestTypeContext::AJAX_FRONT); |
|
| 93 | - } |
|
| 94 | - if (filter_var($this->request->getRequestParam('ee_admin_ajax'), FILTER_VALIDATE_BOOLEAN)) { |
|
| 95 | - return $this->factory->create(RequestTypeContext::AJAX_ADMIN); |
|
| 96 | - } |
|
| 97 | - return $this->factory->create(RequestTypeContext::AJAX_OTHER); |
|
| 98 | - } |
|
| 99 | - // Detect WP_Cron |
|
| 100 | - if ($this->isCronRequest()) { |
|
| 101 | - return $this->factory->create(RequestTypeContext::CRON); |
|
| 102 | - } |
|
| 103 | - // Detect command line requests |
|
| 104 | - if ($this->getGlobalRouteCondition('WP_CLI', false)) { |
|
| 105 | - return $this->factory->create(RequestTypeContext::CLI); |
|
| 106 | - } |
|
| 107 | - // detect WordPress admin (ie: "Dashboard") |
|
| 108 | - if ($this->getGlobalRouteCondition('is_admin', false)) { |
|
| 109 | - return $this->factory->create(RequestTypeContext::ADMIN); |
|
| 110 | - } |
|
| 111 | - // Detect iFrames |
|
| 112 | - if ($this->isIframeRoute()) { |
|
| 113 | - return $this->factory->create(RequestTypeContext::IFRAME); |
|
| 114 | - } |
|
| 115 | - // Detect Feeds |
|
| 116 | - if ($this->isFeedRequest()) { |
|
| 117 | - return $this->factory->create(RequestTypeContext::FEED); |
|
| 118 | - } |
|
| 119 | - // and by process of elimination... |
|
| 120 | - return $this->factory->create(RequestTypeContext::FRONTEND); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * @return bool |
|
| 126 | - */ |
|
| 127 | - private function isEspressoRestApiRequest() |
|
| 128 | - { |
|
| 129 | - return $this->uriPathMatches(trim(rest_get_url_prefix(), '/') . '/' . Domain::API_NAMESPACE); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * @return bool |
|
| 136 | - */ |
|
| 137 | - private function isWordPressRestApiRequest() |
|
| 138 | - { |
|
| 139 | - return $this->uriPathMatches(trim(rest_get_url_prefix(), '/')); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * @return bool |
|
| 145 | - */ |
|
| 146 | - private function isCronRequest() |
|
| 147 | - { |
|
| 148 | - return $this->uriPathMatches('wp-cron.php'); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * @return bool |
|
| 154 | - */ |
|
| 155 | - private function isFeedRequest() |
|
| 156 | - { |
|
| 157 | - return $this->uriPathMatches('feed'); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * @param string $component |
|
| 163 | - * @return bool |
|
| 164 | - */ |
|
| 165 | - private function uriPathMatches($component) |
|
| 166 | - { |
|
| 167 | - $request_uri = $this->request->requestUri(); |
|
| 168 | - $parts = explode('?', $request_uri); |
|
| 169 | - $path = trim(reset($parts), '/'); |
|
| 170 | - return strpos($path, $component) === 0; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * @return bool |
|
| 176 | - */ |
|
| 177 | - private function isIframeRoute() |
|
| 178 | - { |
|
| 179 | - $is_iframe_route = apply_filters( |
|
| 180 | - 'FHEE__EventEspresso_core_domain_services_contexts_RequestTypeContextDetector__isIframeRoute', |
|
| 181 | - $this->request->getRequestParam('event_list', '') === 'iframe' |
|
| 182 | - || $this->request->getRequestParam('ticket_selector', '') === 'iframe' |
|
| 183 | - || $this->request->getRequestParam('calendar', '') === 'iframe', |
|
| 184 | - $this |
|
| 185 | - ); |
|
| 186 | - return filter_var($is_iframe_route, FILTER_VALIDATE_BOOLEAN); |
|
| 187 | - } |
|
| 21 | + /** |
|
| 22 | + * @var RequestTypeContextFactoryInterface $factory |
|
| 23 | + */ |
|
| 24 | + private $factory; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @var RequestInterface $request |
|
| 28 | + */ |
|
| 29 | + private $request; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var array $globalRouteConditions |
|
| 33 | + */ |
|
| 34 | + private $globalRouteConditions; |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * RequestTypeContextDetector constructor. |
|
| 39 | + * |
|
| 40 | + * @param RequestInterface $request |
|
| 41 | + * @param RequestTypeContextFactoryInterface $factory |
|
| 42 | + * @param array $globalRouteConditions an array for injecting values that would |
|
| 43 | + * otherwise be defined as global constants |
|
| 44 | + * or other global variables for the current |
|
| 45 | + * request route such as DOING_AJAX |
|
| 46 | + */ |
|
| 47 | + public function __construct( |
|
| 48 | + RequestInterface $request, |
|
| 49 | + RequestTypeContextFactoryInterface $factory, |
|
| 50 | + array $globalRouteConditions = array() |
|
| 51 | + ) { |
|
| 52 | + $this->request = $request; |
|
| 53 | + $this->factory = $factory; |
|
| 54 | + $this->globalRouteConditions = $globalRouteConditions; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @return mixed |
|
| 60 | + */ |
|
| 61 | + private function getGlobalRouteCondition($globalRouteCondition, $default) |
|
| 62 | + { |
|
| 63 | + return isset($this->globalRouteConditions[ $globalRouteCondition ]) |
|
| 64 | + ? $this->globalRouteConditions[ $globalRouteCondition ] |
|
| 65 | + : $default; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @return RequestTypeContext |
|
| 71 | + * @throws InvalidArgumentException |
|
| 72 | + */ |
|
| 73 | + public function detectRequestTypeContext() |
|
| 74 | + { |
|
| 75 | + // Detect error scrapes |
|
| 76 | + if ($this->request->getRequestParam('wp_scrape_key') !== null |
|
| 77 | + && $this->request->getRequestParam('wp_scrape_nonce') !== null |
|
| 78 | + ) { |
|
| 79 | + return $this->factory->create(RequestTypeContext::WP_SCRAPE); |
|
| 80 | + } |
|
| 81 | + // Detect EE REST API |
|
| 82 | + if ($this->isEspressoRestApiRequest()) { |
|
| 83 | + return $this->factory->create(RequestTypeContext::API); |
|
| 84 | + } |
|
| 85 | + // Detect WP REST API |
|
| 86 | + if ($this->isWordPressRestApiRequest()) { |
|
| 87 | + return $this->factory->create(RequestTypeContext::WP_API); |
|
| 88 | + } |
|
| 89 | + // Detect AJAX |
|
| 90 | + if ($this->getGlobalRouteCondition('DOING_AJAX', false)) { |
|
| 91 | + if (filter_var($this->request->getRequestParam('ee_front_ajax'), FILTER_VALIDATE_BOOLEAN)) { |
|
| 92 | + return $this->factory->create(RequestTypeContext::AJAX_FRONT); |
|
| 93 | + } |
|
| 94 | + if (filter_var($this->request->getRequestParam('ee_admin_ajax'), FILTER_VALIDATE_BOOLEAN)) { |
|
| 95 | + return $this->factory->create(RequestTypeContext::AJAX_ADMIN); |
|
| 96 | + } |
|
| 97 | + return $this->factory->create(RequestTypeContext::AJAX_OTHER); |
|
| 98 | + } |
|
| 99 | + // Detect WP_Cron |
|
| 100 | + if ($this->isCronRequest()) { |
|
| 101 | + return $this->factory->create(RequestTypeContext::CRON); |
|
| 102 | + } |
|
| 103 | + // Detect command line requests |
|
| 104 | + if ($this->getGlobalRouteCondition('WP_CLI', false)) { |
|
| 105 | + return $this->factory->create(RequestTypeContext::CLI); |
|
| 106 | + } |
|
| 107 | + // detect WordPress admin (ie: "Dashboard") |
|
| 108 | + if ($this->getGlobalRouteCondition('is_admin', false)) { |
|
| 109 | + return $this->factory->create(RequestTypeContext::ADMIN); |
|
| 110 | + } |
|
| 111 | + // Detect iFrames |
|
| 112 | + if ($this->isIframeRoute()) { |
|
| 113 | + return $this->factory->create(RequestTypeContext::IFRAME); |
|
| 114 | + } |
|
| 115 | + // Detect Feeds |
|
| 116 | + if ($this->isFeedRequest()) { |
|
| 117 | + return $this->factory->create(RequestTypeContext::FEED); |
|
| 118 | + } |
|
| 119 | + // and by process of elimination... |
|
| 120 | + return $this->factory->create(RequestTypeContext::FRONTEND); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * @return bool |
|
| 126 | + */ |
|
| 127 | + private function isEspressoRestApiRequest() |
|
| 128 | + { |
|
| 129 | + return $this->uriPathMatches(trim(rest_get_url_prefix(), '/') . '/' . Domain::API_NAMESPACE); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * @return bool |
|
| 136 | + */ |
|
| 137 | + private function isWordPressRestApiRequest() |
|
| 138 | + { |
|
| 139 | + return $this->uriPathMatches(trim(rest_get_url_prefix(), '/')); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * @return bool |
|
| 145 | + */ |
|
| 146 | + private function isCronRequest() |
|
| 147 | + { |
|
| 148 | + return $this->uriPathMatches('wp-cron.php'); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * @return bool |
|
| 154 | + */ |
|
| 155 | + private function isFeedRequest() |
|
| 156 | + { |
|
| 157 | + return $this->uriPathMatches('feed'); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * @param string $component |
|
| 163 | + * @return bool |
|
| 164 | + */ |
|
| 165 | + private function uriPathMatches($component) |
|
| 166 | + { |
|
| 167 | + $request_uri = $this->request->requestUri(); |
|
| 168 | + $parts = explode('?', $request_uri); |
|
| 169 | + $path = trim(reset($parts), '/'); |
|
| 170 | + return strpos($path, $component) === 0; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * @return bool |
|
| 176 | + */ |
|
| 177 | + private function isIframeRoute() |
|
| 178 | + { |
|
| 179 | + $is_iframe_route = apply_filters( |
|
| 180 | + 'FHEE__EventEspresso_core_domain_services_contexts_RequestTypeContextDetector__isIframeRoute', |
|
| 181 | + $this->request->getRequestParam('event_list', '') === 'iframe' |
|
| 182 | + || $this->request->getRequestParam('ticket_selector', '') === 'iframe' |
|
| 183 | + || $this->request->getRequestParam('calendar', '') === 'iframe', |
|
| 184 | + $this |
|
| 185 | + ); |
|
| 186 | + return filter_var($is_iframe_route, FILTER_VALIDATE_BOOLEAN); |
|
| 187 | + } |
|
| 188 | 188 | } |
@@ -60,8 +60,8 @@ discard block |
||
| 60 | 60 | */ |
| 61 | 61 | private function getGlobalRouteCondition($globalRouteCondition, $default) |
| 62 | 62 | { |
| 63 | - return isset($this->globalRouteConditions[ $globalRouteCondition ]) |
|
| 64 | - ? $this->globalRouteConditions[ $globalRouteCondition ] |
|
| 63 | + return isset($this->globalRouteConditions[$globalRouteCondition]) |
|
| 64 | + ? $this->globalRouteConditions[$globalRouteCondition] |
|
| 65 | 65 | : $default; |
| 66 | 66 | } |
| 67 | 67 | |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | */ |
| 127 | 127 | private function isEspressoRestApiRequest() |
| 128 | 128 | { |
| 129 | - return $this->uriPathMatches(trim(rest_get_url_prefix(), '/') . '/' . Domain::API_NAMESPACE); |
|
| 129 | + return $this->uriPathMatches(trim(rest_get_url_prefix(), '/').'/'.Domain::API_NAMESPACE); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | |