@@ -4,11 +4,11 @@ |
||
4 | 4 | |
5 | 5 | abstract class PermalinkHtmlHook |
6 | 6 | { |
7 | - public static function addEventEditorPermalinkButton(int $priority = 10, int $accepted_args = 2) |
|
8 | - { |
|
9 | - add_filter('get_sample_permalink_html', [get_called_class(), 'addButton'], $priority, $accepted_args); |
|
10 | - } |
|
7 | + public static function addEventEditorPermalinkButton(int $priority = 10, int $accepted_args = 2) |
|
8 | + { |
|
9 | + add_filter('get_sample_permalink_html', [get_called_class(), 'addButton'], $priority, $accepted_args); |
|
10 | + } |
|
11 | 11 | |
12 | 12 | |
13 | - abstract public static function addButton(string $html, int $post_id): string; |
|
13 | + abstract public static function addButton(string $html, int $post_id): string; |
|
14 | 14 | } |
@@ -13,107 +13,107 @@ |
||
13 | 13 | |
14 | 14 | class LicenseKeysAdminForm extends FormHandler |
15 | 15 | { |
16 | - public function __construct(EE_Registry $registry) |
|
17 | - { |
|
18 | - parent::__construct( |
|
19 | - LICENSE_KEYS_LABEL, |
|
20 | - LICENSE_KEYS_LABEL, |
|
21 | - LICENSE_KEYS_PG_SLUG, |
|
22 | - '', |
|
23 | - FormHandler::DO_NOT_SETUP_FORM, |
|
24 | - $registry |
|
25 | - ); |
|
26 | - } |
|
16 | + public function __construct(EE_Registry $registry) |
|
17 | + { |
|
18 | + parent::__construct( |
|
19 | + LICENSE_KEYS_LABEL, |
|
20 | + LICENSE_KEYS_LABEL, |
|
21 | + LICENSE_KEYS_PG_SLUG, |
|
22 | + '', |
|
23 | + FormHandler::DO_NOT_SETUP_FORM, |
|
24 | + $registry |
|
25 | + ); |
|
26 | + } |
|
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * @throws EE_Error |
|
31 | - */ |
|
32 | - public function generate(): EE_Form_Section_Proper |
|
33 | - { |
|
34 | - $subsections = (array) apply_filters('FHEE__LicenseKeysAdminForm__generate__form_subsections', []); |
|
35 | - ksort($subsections); |
|
36 | - return new EE_Form_Section_Proper( |
|
37 | - [ |
|
38 | - 'name' => 'license_keys_admin_form', |
|
39 | - 'html_id' => 'license_keys_admin_form', |
|
40 | - 'layout_strategy' => new EE_No_Layout(), |
|
41 | - 'subsections' => $this->addCoreSupportLicenseKey($subsections), |
|
42 | - ] |
|
43 | - ); |
|
44 | - } |
|
29 | + /** |
|
30 | + * @throws EE_Error |
|
31 | + */ |
|
32 | + public function generate(): EE_Form_Section_Proper |
|
33 | + { |
|
34 | + $subsections = (array) apply_filters('FHEE__LicenseKeysAdminForm__generate__form_subsections', []); |
|
35 | + ksort($subsections); |
|
36 | + return new EE_Form_Section_Proper( |
|
37 | + [ |
|
38 | + 'name' => 'license_keys_admin_form', |
|
39 | + 'html_id' => 'license_keys_admin_form', |
|
40 | + 'layout_strategy' => new EE_No_Layout(), |
|
41 | + 'subsections' => $this->addCoreSupportLicenseKey($subsections), |
|
42 | + ] |
|
43 | + ); |
|
44 | + } |
|
45 | 45 | |
46 | 46 | |
47 | - private function addCoreSupportLicenseKey(array $subsections): array |
|
48 | - { |
|
49 | - // we want to move the license key input for core to a different location, |
|
50 | - // so to do that we need to copy it, delete the old location, then add re-add to the form |
|
51 | - $core_license_key = $subsections['event_espresso_core'] ?? null; |
|
52 | - unset($subsections['event_espresso_core']); |
|
53 | - $new_subsections = [ |
|
54 | - 'license_keys_hdr' => new EE_Form_Section_HTML( |
|
55 | - EEH_HTML::h1( |
|
56 | - esc_html__('Event Espresso Core License & Support Keys', 'event_espresso'), |
|
57 | - '', |
|
58 | - 'ee-admin-settings-hdr' |
|
59 | - ) |
|
60 | - ), |
|
61 | - 'event_espresso_core' => $core_license_key, |
|
62 | - 'support_license_notice' => new EE_Form_Section_HTML( |
|
63 | - EEH_HTML::br() |
|
64 | - . EEH_HTML::div( |
|
65 | - '<span class="dashicons dashicons-sos"></span>' |
|
66 | - . EEH_HTML::span( |
|
67 | - esc_html__( |
|
68 | - 'Adding a valid Support License Key will enable automatic update notifications and backend updates.', |
|
69 | - 'event_espresso' |
|
70 | - ) |
|
71 | - ), |
|
72 | - 'support-license-notice-dv', |
|
73 | - 'ee-status-outline ee-status-outline--micro ee-status-outline--info ee-status-bg--info' |
|
74 | - ) |
|
75 | - . EEH_HTML::br() |
|
76 | - . EEH_HTML::div( |
|
77 | - EEH_HTML::span( |
|
78 | - sprintf( |
|
79 | - esc_html__( |
|
80 | - 'If this is a Development or Test site, %sDO NOT%s enter your Support License Key.', |
|
81 | - 'event_espresso' |
|
82 | - ), |
|
83 | - '<strong>', |
|
84 | - '</strong>' |
|
85 | - ) |
|
86 | - ), |
|
87 | - '', |
|
88 | - 'ee-status-outline ee-status-outline--attention' |
|
89 | - ) |
|
90 | - ), |
|
91 | - 'add-on-license-keys-hdr' => new EE_Form_Section_HTML( |
|
92 | - EEH_HTML::h2( |
|
93 | - esc_html__('Add-on License Keys', 'event_espresso'), |
|
94 | - '', |
|
95 | - 'ee-admin-settings-hdr' |
|
96 | - ) |
|
97 | - ), |
|
98 | - 'add-on-license-keys-notice' => new EE_Form_Section_HTML( |
|
99 | - EEH_HTML::div( |
|
100 | - EEH_HTML::span( |
|
101 | - esc_html__( |
|
102 | - 'Please activate an Event Espresso Core support license key first in order to activate your add-on license keys', |
|
103 | - 'event_espresso' |
|
104 | - ) |
|
105 | - ), |
|
106 | - 'add-on-license-keys-notice-dv', |
|
107 | - 'ee-status-outline ee-status-outline--micro ee-status-bg--attention', |
|
108 | - 'display: none;' |
|
109 | - ) |
|
110 | - ), |
|
111 | - ]; |
|
47 | + private function addCoreSupportLicenseKey(array $subsections): array |
|
48 | + { |
|
49 | + // we want to move the license key input for core to a different location, |
|
50 | + // so to do that we need to copy it, delete the old location, then add re-add to the form |
|
51 | + $core_license_key = $subsections['event_espresso_core'] ?? null; |
|
52 | + unset($subsections['event_espresso_core']); |
|
53 | + $new_subsections = [ |
|
54 | + 'license_keys_hdr' => new EE_Form_Section_HTML( |
|
55 | + EEH_HTML::h1( |
|
56 | + esc_html__('Event Espresso Core License & Support Keys', 'event_espresso'), |
|
57 | + '', |
|
58 | + 'ee-admin-settings-hdr' |
|
59 | + ) |
|
60 | + ), |
|
61 | + 'event_espresso_core' => $core_license_key, |
|
62 | + 'support_license_notice' => new EE_Form_Section_HTML( |
|
63 | + EEH_HTML::br() |
|
64 | + . EEH_HTML::div( |
|
65 | + '<span class="dashicons dashicons-sos"></span>' |
|
66 | + . EEH_HTML::span( |
|
67 | + esc_html__( |
|
68 | + 'Adding a valid Support License Key will enable automatic update notifications and backend updates.', |
|
69 | + 'event_espresso' |
|
70 | + ) |
|
71 | + ), |
|
72 | + 'support-license-notice-dv', |
|
73 | + 'ee-status-outline ee-status-outline--micro ee-status-outline--info ee-status-bg--info' |
|
74 | + ) |
|
75 | + . EEH_HTML::br() |
|
76 | + . EEH_HTML::div( |
|
77 | + EEH_HTML::span( |
|
78 | + sprintf( |
|
79 | + esc_html__( |
|
80 | + 'If this is a Development or Test site, %sDO NOT%s enter your Support License Key.', |
|
81 | + 'event_espresso' |
|
82 | + ), |
|
83 | + '<strong>', |
|
84 | + '</strong>' |
|
85 | + ) |
|
86 | + ), |
|
87 | + '', |
|
88 | + 'ee-status-outline ee-status-outline--attention' |
|
89 | + ) |
|
90 | + ), |
|
91 | + 'add-on-license-keys-hdr' => new EE_Form_Section_HTML( |
|
92 | + EEH_HTML::h2( |
|
93 | + esc_html__('Add-on License Keys', 'event_espresso'), |
|
94 | + '', |
|
95 | + 'ee-admin-settings-hdr' |
|
96 | + ) |
|
97 | + ), |
|
98 | + 'add-on-license-keys-notice' => new EE_Form_Section_HTML( |
|
99 | + EEH_HTML::div( |
|
100 | + EEH_HTML::span( |
|
101 | + esc_html__( |
|
102 | + 'Please activate an Event Espresso Core support license key first in order to activate your add-on license keys', |
|
103 | + 'event_espresso' |
|
104 | + ) |
|
105 | + ), |
|
106 | + 'add-on-license-keys-notice-dv', |
|
107 | + 'ee-status-outline ee-status-outline--micro ee-status-bg--attention', |
|
108 | + 'display: none;' |
|
109 | + ) |
|
110 | + ), |
|
111 | + ]; |
|
112 | 112 | |
113 | - if ($core_license_key instanceof LicenseKeyFormInput && $core_license_key->get_default()) { |
|
114 | - unset($new_subsections['support_license_notice']); |
|
115 | - unset($new_subsections['add-on-license-keys-notice']); |
|
116 | - } |
|
117 | - return EEH_Array::insert_into_array($subsections, $new_subsections); |
|
118 | - } |
|
113 | + if ($core_license_key instanceof LicenseKeyFormInput && $core_license_key->get_default()) { |
|
114 | + unset($new_subsections['support_license_notice']); |
|
115 | + unset($new_subsections['add-on-license-keys-notice']); |
|
116 | + } |
|
117 | + return EEH_Array::insert_into_array($subsections, $new_subsections); |
|
118 | + } |
|
119 | 119 | } |
@@ -4,90 +4,90 @@ |
||
4 | 4 | |
5 | 5 | class LicenseStatus |
6 | 6 | { |
7 | - public static function statusNotice(?string $license_status): string |
|
8 | - { |
|
9 | - if (empty($license_status)) { |
|
10 | - return "<span class='ee-status-pill'></span>"; |
|
11 | - } |
|
12 | - $class = self::statusClass($license_status); |
|
13 | - $icon = self::statusIcon($license_status); |
|
14 | - $notice = self::statusMessage($license_status); |
|
15 | - return "<span class='ee-status-pill ee-status-bg--$class'><span class='ee-license-status'>$notice</span> <span class='dashicons dashicons-$icon'></span></span>"; |
|
16 | - } |
|
7 | + public static function statusNotice(?string $license_status): string |
|
8 | + { |
|
9 | + if (empty($license_status)) { |
|
10 | + return "<span class='ee-status-pill'></span>"; |
|
11 | + } |
|
12 | + $class = self::statusClass($license_status); |
|
13 | + $icon = self::statusIcon($license_status); |
|
14 | + $notice = self::statusMessage($license_status); |
|
15 | + return "<span class='ee-status-pill ee-status-bg--$class'><span class='ee-license-status'>$notice</span> <span class='dashicons dashicons-$icon'></span></span>"; |
|
16 | + } |
|
17 | 17 | |
18 | - public static function statusMessages(): array |
|
19 | - { |
|
20 | - return [ |
|
21 | - "deactivated" => esc_html__("license key deactivated", 'event_espresso'), |
|
22 | - "disabled" => esc_html__("license key revoked", 'event_espresso'), |
|
23 | - "expired" => esc_html__("license has expired", 'event_espresso'), |
|
24 | - "inactive" => esc_html__("inactive license key", 'event_espresso'), |
|
25 | - "invalid" => esc_html__("invalid license key", 'event_espresso'), |
|
26 | - "invalid_item_id" => esc_html__("invalid item ID", 'event_espresso'), |
|
27 | - "item_name_mismatch" => esc_html__("invalid license for plugin", 'event_espresso'), |
|
28 | - "key_mismatch" => esc_html__("invalid license for plugin", 'event_espresso'), |
|
29 | - "license_not_activable" => esc_html__("attempting to activate a bundle's parent license", 'event_espresso'), |
|
30 | - "missing" => esc_html__("no license found", 'event_espresso'), |
|
31 | - "missing_url" => esc_html__("site URL not found", 'event_espresso'), |
|
32 | - "no_activations_left" => esc_html__("no activations left", 'event_espresso'), |
|
33 | - "site_inactive" => esc_html__("site is not active for this license", 'event_espresso'), |
|
34 | - "valid" => esc_html__("valid license key", 'event_espresso'), |
|
35 | - ]; |
|
36 | - } |
|
18 | + public static function statusMessages(): array |
|
19 | + { |
|
20 | + return [ |
|
21 | + "deactivated" => esc_html__("license key deactivated", 'event_espresso'), |
|
22 | + "disabled" => esc_html__("license key revoked", 'event_espresso'), |
|
23 | + "expired" => esc_html__("license has expired", 'event_espresso'), |
|
24 | + "inactive" => esc_html__("inactive license key", 'event_espresso'), |
|
25 | + "invalid" => esc_html__("invalid license key", 'event_espresso'), |
|
26 | + "invalid_item_id" => esc_html__("invalid item ID", 'event_espresso'), |
|
27 | + "item_name_mismatch" => esc_html__("invalid license for plugin", 'event_espresso'), |
|
28 | + "key_mismatch" => esc_html__("invalid license for plugin", 'event_espresso'), |
|
29 | + "license_not_activable" => esc_html__("attempting to activate a bundle's parent license", 'event_espresso'), |
|
30 | + "missing" => esc_html__("no license found", 'event_espresso'), |
|
31 | + "missing_url" => esc_html__("site URL not found", 'event_espresso'), |
|
32 | + "no_activations_left" => esc_html__("no activations left", 'event_espresso'), |
|
33 | + "site_inactive" => esc_html__("site is not active for this license", 'event_espresso'), |
|
34 | + "valid" => esc_html__("valid license key", 'event_espresso'), |
|
35 | + ]; |
|
36 | + } |
|
37 | 37 | |
38 | - public static function statusMessage(?string $license_status): string |
|
39 | - { |
|
40 | - $license_statuses = self::statusMessages(); |
|
41 | - return $license_statuses[ $license_status ] ?? esc_html__("An unknown error occurred", 'event_espresso'); |
|
42 | - } |
|
38 | + public static function statusMessage(?string $license_status): string |
|
39 | + { |
|
40 | + $license_statuses = self::statusMessages(); |
|
41 | + return $license_statuses[ $license_status ] ?? esc_html__("An unknown error occurred", 'event_espresso'); |
|
42 | + } |
|
43 | 43 | |
44 | 44 | |
45 | - public static function statusClass(?string $license_status): string |
|
46 | - { |
|
47 | - switch ($license_status) { |
|
48 | - case "valid": |
|
49 | - return "active"; |
|
45 | + public static function statusClass(?string $license_status): string |
|
46 | + { |
|
47 | + switch ($license_status) { |
|
48 | + case "valid": |
|
49 | + return "active"; |
|
50 | 50 | |
51 | - case "deactivated": |
|
52 | - case "expired": |
|
53 | - case "inactive": |
|
54 | - case "site_inactive": |
|
55 | - return "inactive"; |
|
51 | + case "deactivated": |
|
52 | + case "expired": |
|
53 | + case "inactive": |
|
54 | + case "site_inactive": |
|
55 | + return "inactive"; |
|
56 | 56 | |
57 | - case "no_activations_left": |
|
58 | - return "attention"; |
|
57 | + case "no_activations_left": |
|
58 | + return "attention"; |
|
59 | 59 | |
60 | - case "disabled": |
|
61 | - case "revoked": |
|
62 | - case "invalid": |
|
63 | - case "item_name_mismatch": |
|
64 | - case "missing": |
|
65 | - default: |
|
66 | - return "error"; |
|
67 | - } |
|
68 | - } |
|
60 | + case "disabled": |
|
61 | + case "revoked": |
|
62 | + case "invalid": |
|
63 | + case "item_name_mismatch": |
|
64 | + case "missing": |
|
65 | + default: |
|
66 | + return "error"; |
|
67 | + } |
|
68 | + } |
|
69 | 69 | |
70 | 70 | |
71 | - public static function statusIcon(?string $license_status): string |
|
72 | - { |
|
73 | - switch ($license_status) { |
|
74 | - case "valid": |
|
75 | - return "yes-alt"; |
|
71 | + public static function statusIcon(?string $license_status): string |
|
72 | + { |
|
73 | + switch ($license_status) { |
|
74 | + case "valid": |
|
75 | + return "yes-alt"; |
|
76 | 76 | |
77 | - case "expired": |
|
78 | - case "site_inactive": |
|
79 | - return "clock"; |
|
77 | + case "expired": |
|
78 | + case "site_inactive": |
|
79 | + return "clock"; |
|
80 | 80 | |
81 | - case "disabled": |
|
82 | - case "revoked": |
|
83 | - case "invalid": |
|
84 | - case "item_name_mismatch": |
|
85 | - case "no_activations_left": |
|
86 | - return "warning"; |
|
81 | + case "disabled": |
|
82 | + case "revoked": |
|
83 | + case "invalid": |
|
84 | + case "item_name_mismatch": |
|
85 | + case "no_activations_left": |
|
86 | + return "warning"; |
|
87 | 87 | |
88 | - case "missing": |
|
89 | - default: |
|
90 | - return "editor-help"; |
|
91 | - } |
|
92 | - } |
|
88 | + case "missing": |
|
89 | + default: |
|
90 | + return "editor-help"; |
|
91 | + } |
|
92 | + } |
|
93 | 93 | } |
@@ -38,7 +38,7 @@ |
||
38 | 38 | public static function statusMessage(?string $license_status): string |
39 | 39 | { |
40 | 40 | $license_statuses = self::statusMessages(); |
41 | - return $license_statuses[ $license_status ] ?? esc_html__("An unknown error occurred", 'event_espresso'); |
|
41 | + return $license_statuses[$license_status] ?? esc_html__("An unknown error occurred", 'event_espresso'); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 |
@@ -15,45 +15,45 @@ |
||
15 | 15 | */ |
16 | 16 | class LicenseDataEDD implements LicenseDataStrategy |
17 | 17 | { |
18 | - private LicenseKeyData $license_key_data; |
|
18 | + private LicenseKeyData $license_key_data; |
|
19 | 19 | |
20 | - private string $status; |
|
20 | + private string $status; |
|
21 | 21 | |
22 | - private string $expiry; |
|
22 | + private string $expiry; |
|
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * @param LicenseKeyData $license_key_data |
|
27 | - */ |
|
28 | - public function __construct(LicenseKeyData $license_key_data) |
|
29 | - { |
|
30 | - $this->license_key_data = $license_key_data; |
|
31 | - } |
|
25 | + /** |
|
26 | + * @param LicenseKeyData $license_key_data |
|
27 | + */ |
|
28 | + public function __construct(LicenseKeyData $license_key_data) |
|
29 | + { |
|
30 | + $this->license_key_data = $license_key_data; |
|
31 | + } |
|
32 | 32 | |
33 | 33 | |
34 | - public function loadLicenseData() |
|
35 | - { |
|
36 | - $license_data = $this->license_key_data->getLicenseDataForPlugin(Domain::pluginSlug()); |
|
37 | - if (! isset($license_data->license)) { |
|
38 | - $this->status = LicenseData::LICENSE_EXPIRED; |
|
39 | - $this->expiry = ''; |
|
40 | - return; |
|
41 | - } |
|
42 | - $this->status = $license_data->license_key && $license_data->license === LicenseData::LICENSE_VALID |
|
43 | - ? LicenseData::LICENSE_ACTIVE |
|
44 | - : LicenseData::LICENSE_EXPIRED; |
|
45 | - $this->expiry = $license_data->expires ?? ''; |
|
46 | - } |
|
34 | + public function loadLicenseData() |
|
35 | + { |
|
36 | + $license_data = $this->license_key_data->getLicenseDataForPlugin(Domain::pluginSlug()); |
|
37 | + if (! isset($license_data->license)) { |
|
38 | + $this->status = LicenseData::LICENSE_EXPIRED; |
|
39 | + $this->expiry = ''; |
|
40 | + return; |
|
41 | + } |
|
42 | + $this->status = $license_data->license_key && $license_data->license === LicenseData::LICENSE_VALID |
|
43 | + ? LicenseData::LICENSE_ACTIVE |
|
44 | + : LicenseData::LICENSE_EXPIRED; |
|
45 | + $this->expiry = $license_data->expires ?? ''; |
|
46 | + } |
|
47 | 47 | |
48 | 48 | |
49 | - public function getLicenseStatus(): string |
|
50 | - { |
|
51 | - return $this->status; |
|
52 | - } |
|
49 | + public function getLicenseStatus(): string |
|
50 | + { |
|
51 | + return $this->status; |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | - public function getLicenseExpiry(): string |
|
56 | - { |
|
57 | - return $this->expiry; |
|
58 | - } |
|
55 | + public function getLicenseExpiry(): string |
|
56 | + { |
|
57 | + return $this->expiry; |
|
58 | + } |
|
59 | 59 | } |
@@ -4,11 +4,11 @@ |
||
4 | 4 | |
5 | 5 | interface LicenseDataStrategy |
6 | 6 | { |
7 | - public function loadLicenseData(); |
|
7 | + public function loadLicenseData(); |
|
8 | 8 | |
9 | 9 | |
10 | - public function getLicenseStatus(): string; |
|
10 | + public function getLicenseStatus(): string; |
|
11 | 11 | |
12 | 12 | |
13 | - public function getLicenseExpiry(): string; |
|
13 | + public function getLicenseExpiry(): string; |
|
14 | 14 | } |
@@ -29,126 +29,126 @@ |
||
29 | 29 | */ |
30 | 30 | class RestApiSpoofer |
31 | 31 | { |
32 | - protected EED_Core_Rest_Api $rest_module; |
|
32 | + protected EED_Core_Rest_Api $rest_module; |
|
33 | 33 | |
34 | - protected Read $rest_controller; |
|
34 | + protected Read $rest_controller; |
|
35 | 35 | |
36 | - protected WP_REST_Server $wp_rest_server; |
|
36 | + protected WP_REST_Server $wp_rest_server; |
|
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * RestApiSpoofer constructor. |
|
41 | - * |
|
42 | - * @param WP_REST_Server $wp_rest_server |
|
43 | - * @param EED_Core_Rest_Api $rest_module |
|
44 | - * @param Read $rest_api |
|
45 | - * @param string $api_version |
|
46 | - */ |
|
47 | - public function __construct( |
|
48 | - WP_REST_Server $wp_rest_server, |
|
49 | - EED_Core_Rest_Api $rest_module, |
|
50 | - Read $rest_api, |
|
51 | - string $api_version = '4.8.36' |
|
52 | - ) { |
|
53 | - $this->wp_rest_server = $wp_rest_server; |
|
54 | - $this->rest_module = $rest_module; |
|
55 | - $this->rest_controller = $rest_api; |
|
56 | - $this->rest_controller->setRequestedVersion($api_version); |
|
57 | - $this->setUpRestServer(); |
|
58 | - } |
|
39 | + /** |
|
40 | + * RestApiSpoofer constructor. |
|
41 | + * |
|
42 | + * @param WP_REST_Server $wp_rest_server |
|
43 | + * @param EED_Core_Rest_Api $rest_module |
|
44 | + * @param Read $rest_api |
|
45 | + * @param string $api_version |
|
46 | + */ |
|
47 | + public function __construct( |
|
48 | + WP_REST_Server $wp_rest_server, |
|
49 | + EED_Core_Rest_Api $rest_module, |
|
50 | + Read $rest_api, |
|
51 | + string $api_version = '4.8.36' |
|
52 | + ) { |
|
53 | + $this->wp_rest_server = $wp_rest_server; |
|
54 | + $this->rest_module = $rest_module; |
|
55 | + $this->rest_controller = $rest_api; |
|
56 | + $this->rest_controller->setRequestedVersion($api_version); |
|
57 | + $this->setUpRestServer(); |
|
58 | + } |
|
59 | 59 | |
60 | 60 | |
61 | - private function setUpRestServer() |
|
62 | - { |
|
63 | - /* @var WP_REST_Server $wp_rest_server */ |
|
64 | - global $wp_rest_server; |
|
65 | - $wp_rest_server = $this->wp_rest_server; |
|
66 | - EED_Core_Rest_Api::set_hooks_both(); |
|
67 | - do_action('rest_api_init', $this->wp_rest_server); |
|
68 | - } |
|
61 | + private function setUpRestServer() |
|
62 | + { |
|
63 | + /* @var WP_REST_Server $wp_rest_server */ |
|
64 | + global $wp_rest_server; |
|
65 | + $wp_rest_server = $this->wp_rest_server; |
|
66 | + EED_Core_Rest_Api::set_hooks_both(); |
|
67 | + do_action('rest_api_init', $this->wp_rest_server); |
|
68 | + } |
|
69 | 69 | |
70 | 70 | |
71 | - /** |
|
72 | - * @param EEM_Base $model |
|
73 | - * @param array $query_params |
|
74 | - * @param string $include |
|
75 | - * @return array |
|
76 | - * @throws EE_Error |
|
77 | - * @throws InvalidArgumentException |
|
78 | - * @throws InvalidDataTypeException |
|
79 | - * @throws InvalidInterfaceException |
|
80 | - * @throws ModelConfigurationException |
|
81 | - * @throws ReflectionException |
|
82 | - * @throws RestException |
|
83 | - * @throws RestPasswordIncorrectException |
|
84 | - * @throws RestPasswordRequiredException |
|
85 | - * @throws UnexpectedEntityException |
|
86 | - * @throws DomainException |
|
87 | - * @since 5.0.0.p |
|
88 | - */ |
|
89 | - public function getOneApiResult(EEM_Base $model, array $query_params, string $include = '') |
|
90 | - { |
|
91 | - if (! array_key_exists('limit', $query_params)) { |
|
92 | - $query_params['limit'] = 1; |
|
93 | - } |
|
94 | - $result = $this->getApiResults($model, $query_params, $include); |
|
95 | - return $result[0] ?? []; |
|
96 | - } |
|
71 | + /** |
|
72 | + * @param EEM_Base $model |
|
73 | + * @param array $query_params |
|
74 | + * @param string $include |
|
75 | + * @return array |
|
76 | + * @throws EE_Error |
|
77 | + * @throws InvalidArgumentException |
|
78 | + * @throws InvalidDataTypeException |
|
79 | + * @throws InvalidInterfaceException |
|
80 | + * @throws ModelConfigurationException |
|
81 | + * @throws ReflectionException |
|
82 | + * @throws RestException |
|
83 | + * @throws RestPasswordIncorrectException |
|
84 | + * @throws RestPasswordRequiredException |
|
85 | + * @throws UnexpectedEntityException |
|
86 | + * @throws DomainException |
|
87 | + * @since 5.0.0.p |
|
88 | + */ |
|
89 | + public function getOneApiResult(EEM_Base $model, array $query_params, string $include = '') |
|
90 | + { |
|
91 | + if (! array_key_exists('limit', $query_params)) { |
|
92 | + $query_params['limit'] = 1; |
|
93 | + } |
|
94 | + $result = $this->getApiResults($model, $query_params, $include); |
|
95 | + return $result[0] ?? []; |
|
96 | + } |
|
97 | 97 | |
98 | 98 | |
99 | - /** |
|
100 | - * @param EEM_Base $model |
|
101 | - * @param array $query_params |
|
102 | - * @param string $include |
|
103 | - * @return array |
|
104 | - * @throws EE_Error |
|
105 | - * @throws InvalidArgumentException |
|
106 | - * @throws InvalidDataTypeException |
|
107 | - * @throws InvalidInterfaceException |
|
108 | - * @throws ModelConfigurationException |
|
109 | - * @throws ReflectionException |
|
110 | - * @throws RestException |
|
111 | - * @throws RestPasswordIncorrectException |
|
112 | - * @throws RestPasswordRequiredException |
|
113 | - * @throws UnexpectedEntityException |
|
114 | - * @throws DomainException |
|
115 | - * @since 5.0.0.p |
|
116 | - */ |
|
117 | - public function getApiResults(EEM_Base $model, array $query_params, string $include = ''): array |
|
118 | - { |
|
119 | - if (! array_key_exists('caps', $query_params)) { |
|
120 | - $query_params['caps'] = EEM_Base::caps_read_admin; |
|
121 | - } |
|
122 | - if (! array_key_exists('default_where_conditions', $query_params)) { |
|
123 | - $query_params['default_where_conditions'] = 'none'; |
|
124 | - } |
|
125 | - /** @type array $results */ |
|
126 | - $results = $model->get_all_wpdb_results($query_params); |
|
127 | - $rest_request = new WP_REST_Request(); |
|
128 | - $rest_request->set_param('include', $include); |
|
129 | - $rest_request->set_param('caps', 'edit'); |
|
130 | - $nice_results = []; |
|
131 | - foreach ($results as $result) { |
|
132 | - $nice_results[] = $this->rest_controller->createEntityFromWpdbResult( |
|
133 | - $model, |
|
134 | - $result, |
|
135 | - $rest_request |
|
136 | - ); |
|
137 | - } |
|
138 | - return $nice_results; |
|
139 | - } |
|
99 | + /** |
|
100 | + * @param EEM_Base $model |
|
101 | + * @param array $query_params |
|
102 | + * @param string $include |
|
103 | + * @return array |
|
104 | + * @throws EE_Error |
|
105 | + * @throws InvalidArgumentException |
|
106 | + * @throws InvalidDataTypeException |
|
107 | + * @throws InvalidInterfaceException |
|
108 | + * @throws ModelConfigurationException |
|
109 | + * @throws ReflectionException |
|
110 | + * @throws RestException |
|
111 | + * @throws RestPasswordIncorrectException |
|
112 | + * @throws RestPasswordRequiredException |
|
113 | + * @throws UnexpectedEntityException |
|
114 | + * @throws DomainException |
|
115 | + * @since 5.0.0.p |
|
116 | + */ |
|
117 | + public function getApiResults(EEM_Base $model, array $query_params, string $include = ''): array |
|
118 | + { |
|
119 | + if (! array_key_exists('caps', $query_params)) { |
|
120 | + $query_params['caps'] = EEM_Base::caps_read_admin; |
|
121 | + } |
|
122 | + if (! array_key_exists('default_where_conditions', $query_params)) { |
|
123 | + $query_params['default_where_conditions'] = 'none'; |
|
124 | + } |
|
125 | + /** @type array $results */ |
|
126 | + $results = $model->get_all_wpdb_results($query_params); |
|
127 | + $rest_request = new WP_REST_Request(); |
|
128 | + $rest_request->set_param('include', $include); |
|
129 | + $rest_request->set_param('caps', 'edit'); |
|
130 | + $nice_results = []; |
|
131 | + foreach ($results as $result) { |
|
132 | + $nice_results[] = $this->rest_controller->createEntityFromWpdbResult( |
|
133 | + $model, |
|
134 | + $result, |
|
135 | + $rest_request |
|
136 | + ); |
|
137 | + } |
|
138 | + return $nice_results; |
|
139 | + } |
|
140 | 140 | |
141 | 141 | |
142 | - /** |
|
143 | - * @param string $endpoint |
|
144 | - * @return array |
|
145 | - * @since 5.0.0.p |
|
146 | - */ |
|
147 | - public function getModelSchema(string $endpoint) |
|
148 | - { |
|
149 | - $response = $this->wp_rest_server->dispatch( |
|
150 | - new WP_REST_Request('OPTIONS', "/ee/v4.8.36/$endpoint") |
|
151 | - ); |
|
152 | - return $response->get_data(); |
|
153 | - } |
|
142 | + /** |
|
143 | + * @param string $endpoint |
|
144 | + * @return array |
|
145 | + * @since 5.0.0.p |
|
146 | + */ |
|
147 | + public function getModelSchema(string $endpoint) |
|
148 | + { |
|
149 | + $response = $this->wp_rest_server->dispatch( |
|
150 | + new WP_REST_Request('OPTIONS', "/ee/v4.8.36/$endpoint") |
|
151 | + ); |
|
152 | + return $response->get_data(); |
|
153 | + } |
|
154 | 154 | } |
@@ -18,284 +18,284 @@ |
||
18 | 18 | */ |
19 | 19 | class RequestTypeContextDetector |
20 | 20 | { |
21 | - private GraphQLEndpoint $gql_endpoint; |
|
22 | - |
|
23 | - private RequestTypeContextFactoryInterface $factory; |
|
24 | - |
|
25 | - private RequestInterface $request; |
|
26 | - |
|
27 | - private array $globalRouteConditions; |
|
28 | - |
|
29 | - private string $permalink_prefix; |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * RequestTypeContextDetector constructor. |
|
34 | - * |
|
35 | - * @param GraphQLEndpoint $gql_endpoint |
|
36 | - * @param RequestInterface $request |
|
37 | - * @param RequestTypeContextFactoryInterface $factory |
|
38 | - * @param array $globalRouteConditions an array for injecting values that would |
|
39 | - * otherwise be defined as global constants |
|
40 | - * or other global variables for the current |
|
41 | - * request route such as DOING_AJAX |
|
42 | - */ |
|
43 | - public function __construct( |
|
44 | - GraphQLEndpoint $gql_endpoint, |
|
45 | - RequestInterface $request, |
|
46 | - RequestTypeContextFactoryInterface $factory, |
|
47 | - array $globalRouteConditions = [] |
|
48 | - ) { |
|
49 | - $this->gql_endpoint = $gql_endpoint; |
|
50 | - $this->request = $request; |
|
51 | - $this->factory = $factory; |
|
52 | - $this->globalRouteConditions = $globalRouteConditions; |
|
53 | - $permalink_structure = ltrim((string) get_option('permalink_structure'), '/'); |
|
54 | - $this->permalink_prefix = strpos($permalink_structure, 'index.php') === 0 ? '/index.php/' : ''; |
|
55 | - } |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * @param string $globalRouteCondition |
|
60 | - * @param mixed $default |
|
61 | - * @return mixed |
|
62 | - */ |
|
63 | - private function getGlobalRouteCondition(string $globalRouteCondition, $default = false) |
|
64 | - { |
|
65 | - return $this->globalRouteConditions[ $globalRouteCondition ] ?? $default; |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * @return RequestTypeContext |
|
71 | - * @throws InvalidArgumentException |
|
72 | - */ |
|
73 | - public function detectRequestTypeContext(): RequestTypeContext |
|
74 | - { |
|
75 | - // Detect error scrapes |
|
76 | - if ($this->isWordPressErrorScrape()) { |
|
77 | - return $this->factory->create(RequestTypeContext::WP_SCRAPE); |
|
78 | - } |
|
79 | - // Detect activations |
|
80 | - if ($this->isWordPressActivationRequest()) { |
|
81 | - return $this->factory->create(RequestTypeContext::ACTIVATION); |
|
82 | - } |
|
83 | - // Detect EE REST API |
|
84 | - if ($this->isEspressoRestApiRequest()) { |
|
85 | - return $this->factory->create(RequestTypeContext::API); |
|
86 | - } |
|
87 | - // Detect WP REST API |
|
88 | - if ($this->isWordPressRestApiRequest()) { |
|
89 | - return $this->factory->create(RequestTypeContext::WP_API); |
|
90 | - } |
|
91 | - // Detect EE GraphQL |
|
92 | - if ($this->isEspressoGraphQLRequest()) { |
|
93 | - return $this->factory->create(RequestTypeContext::GQL); |
|
94 | - } |
|
95 | - // Detect AJAX |
|
96 | - if ($this->getGlobalRouteCondition('DOING_AJAX')) { |
|
97 | - return $this->isAjaxRequest(); |
|
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')) { |
|
105 | - return $this->factory->create(RequestTypeContext::CLI); |
|
106 | - } |
|
107 | - // detect WordPress admin (ie: "Dashboard") |
|
108 | - if ($this->getGlobalRouteCondition('is_admin')) { |
|
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 RequestTypeContext |
|
126 | - */ |
|
127 | - private function isAjaxRequest(): RequestTypeContext |
|
128 | - { |
|
129 | - if ( |
|
130 | - $this->request->getRequestParam('ee_front_ajax', false, 'bool') |
|
131 | - || $this->request->getRequestParam('data[ee_front_ajax]', false, 'bool') |
|
132 | - ) { |
|
133 | - if (! defined('EE_FRONT_AJAX')) { |
|
134 | - define('EE_FRONT_AJAX', true); |
|
135 | - } |
|
136 | - if (! defined('EE_ADMIN_AJAX')) { |
|
137 | - define('EE_ADMIN_AJAX', false); |
|
138 | - } |
|
139 | - return $this->factory->create(RequestTypeContext::AJAX_FRONT); |
|
140 | - } |
|
141 | - if ( |
|
142 | - $this->request->getRequestParam('ee_admin_ajax', false, 'bool') |
|
143 | - || $this->request->getRequestParam('data[ee_admin_ajax]', false, 'bool') |
|
144 | - ) { |
|
145 | - if (! defined('EE_ADMIN_AJAX')) { |
|
146 | - define('EE_ADMIN_AJAX', true); |
|
147 | - } |
|
148 | - if (! defined('EE_FRONT_AJAX')) { |
|
149 | - define('EE_FRONT_AJAX', false); |
|
150 | - } |
|
151 | - return $this->factory->create(RequestTypeContext::AJAX_ADMIN); |
|
152 | - } |
|
153 | - if ($this->request->getRequestParam('action') === 'heartbeat') { |
|
154 | - return $this->factory->create(RequestTypeContext::AJAX_HEARTBEAT); |
|
155 | - } |
|
156 | - return $this->factory->create(RequestTypeContext::AJAX_OTHER); |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * @return bool |
|
162 | - */ |
|
163 | - private function isWordPressErrorScrape(): bool |
|
164 | - { |
|
165 | - return ( |
|
166 | - $this->request->getRequestParam('wp_scrape_key') !== '' |
|
167 | - && $this->request->getRequestParam('wp_scrape_nonce') !== '' |
|
168 | - ) || ( |
|
169 | - $this->request->getRequestParam('action') === 'error_scrape' |
|
170 | - && $this->request->getRequestParam('_wpnonce') !== '' |
|
171 | - ); |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * @return bool |
|
177 | - */ |
|
178 | - private function isWordPressActivationRequest(): bool |
|
179 | - { |
|
180 | - $action = $this->request->getRequestParam('action'); |
|
181 | - $plugins_page_actions = [ |
|
182 | - 'true', |
|
183 | - 'activate', |
|
184 | - 'activate-multi', |
|
185 | - 'activate-selected', |
|
186 | - 'deactivate', |
|
187 | - 'deactivate-multi', |
|
188 | - 'deactivate-selected', |
|
189 | - 'delete-selected', |
|
190 | - 'disable-auto-update-selected', |
|
191 | - 'enable-auto-update-selected', |
|
192 | - 'update-selected', |
|
193 | - ]; |
|
194 | - return ($this->uriPathMatches('wp-admin/update.php') && $action === 'upload-plugin') |
|
195 | - || ($this->uriPathMatches('wp-admin/plugins.php') && in_array($action, $plugins_page_actions, true)); |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * @param string $extra_path |
|
201 | - * @return bool |
|
202 | - */ |
|
203 | - private function isRestApiRequest(string $extra_path = ''): bool |
|
204 | - { |
|
205 | - $rest_route = $this->request->getRequestParam('rest_route'); |
|
206 | - return ( |
|
207 | - $this->request->getRequestParam('rest_route') !== '' |
|
208 | - && ( $extra_path === '' || strpos($rest_route, $extra_path) !== 0 ) |
|
209 | - ) |
|
210 | - || $this->uriPathMatches(trim(rest_get_url_prefix(), '/') . $extra_path); |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * @return bool |
|
216 | - */ |
|
217 | - private function isEspressoRestApiRequest(): bool |
|
218 | - { |
|
219 | - $api_namespace = '/' . ltrim(Domain::API_NAMESPACE, '/'); |
|
220 | - // Check for URLs like http://mysite.com/?rest_route=/ee... and http://mysite.com/wp-json/ee/... |
|
221 | - return $this->isRestApiRequest($api_namespace); |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - /** |
|
226 | - * Checks for URLs like https://mysite.com/graphql |
|
227 | - * |
|
228 | - * @return bool |
|
229 | - */ |
|
230 | - private function isEspressoGraphQLRequest(): bool |
|
231 | - { |
|
232 | - if ($this->gql_endpoint->isGraphqlRequest()) { |
|
233 | - return true; |
|
234 | - } |
|
235 | - $gql_endpoint = $this->gql_endpoint->getEndpoint(); |
|
236 | - return $this->uriPathMatches($gql_endpoint) || $this->request->requestParamIsSet($gql_endpoint); |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * @return bool |
|
242 | - */ |
|
243 | - private function isWordPressRestApiRequest(): bool |
|
244 | - { |
|
245 | - // Check for URLs like http://mysite.com/?rest_route=/.. and http://mysite.com/wp-json/... |
|
246 | - return $this->isRestApiRequest(); |
|
247 | - } |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * @return bool |
|
252 | - */ |
|
253 | - private function isCronRequest(): bool |
|
254 | - { |
|
255 | - return $this->uriPathMatches('wp-cron.php'); |
|
256 | - } |
|
257 | - |
|
258 | - |
|
259 | - /** |
|
260 | - * @return bool |
|
261 | - */ |
|
262 | - private function isFeedRequest(): bool |
|
263 | - { |
|
264 | - return $this->uriPathMatches('feed'); |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - /** |
|
269 | - * returns true if the current request URI starts with the supplied $component string |
|
270 | - * |
|
271 | - * @param string $component |
|
272 | - * @return bool |
|
273 | - */ |
|
274 | - private function uriPathMatches(string $component): bool |
|
275 | - { |
|
276 | - $request_uri = $this->request->requestUri(true); |
|
277 | - // remove permalink /index.php/ prefix if present |
|
278 | - if (substr($request_uri, 0, strlen($this->permalink_prefix)) === $this->permalink_prefix) { |
|
279 | - $request_uri = substr($request_uri, strlen($this->permalink_prefix)); |
|
280 | - } |
|
281 | - $parts = explode('?', $request_uri); |
|
282 | - $path = trim(reset($parts), '/'); |
|
283 | - return strpos($path, $component) === 0; |
|
284 | - } |
|
285 | - |
|
286 | - |
|
287 | - /** |
|
288 | - * @return bool |
|
289 | - */ |
|
290 | - private function isIframeRoute(): bool |
|
291 | - { |
|
292 | - $is_iframe_route = apply_filters( |
|
293 | - 'FHEE__EventEspresso_core_domain_services_contexts_RequestTypeContextDetector__isIframeRoute', |
|
294 | - $this->request->getRequestParam('event_list', '') === 'iframe' |
|
295 | - || $this->request->getRequestParam('ticket_selector', '') === 'iframe' |
|
296 | - || $this->request->getRequestParam('calendar', '') === 'iframe', |
|
297 | - $this |
|
298 | - ); |
|
299 | - return filter_var($is_iframe_route, FILTER_VALIDATE_BOOLEAN); |
|
300 | - } |
|
21 | + private GraphQLEndpoint $gql_endpoint; |
|
22 | + |
|
23 | + private RequestTypeContextFactoryInterface $factory; |
|
24 | + |
|
25 | + private RequestInterface $request; |
|
26 | + |
|
27 | + private array $globalRouteConditions; |
|
28 | + |
|
29 | + private string $permalink_prefix; |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * RequestTypeContextDetector constructor. |
|
34 | + * |
|
35 | + * @param GraphQLEndpoint $gql_endpoint |
|
36 | + * @param RequestInterface $request |
|
37 | + * @param RequestTypeContextFactoryInterface $factory |
|
38 | + * @param array $globalRouteConditions an array for injecting values that would |
|
39 | + * otherwise be defined as global constants |
|
40 | + * or other global variables for the current |
|
41 | + * request route such as DOING_AJAX |
|
42 | + */ |
|
43 | + public function __construct( |
|
44 | + GraphQLEndpoint $gql_endpoint, |
|
45 | + RequestInterface $request, |
|
46 | + RequestTypeContextFactoryInterface $factory, |
|
47 | + array $globalRouteConditions = [] |
|
48 | + ) { |
|
49 | + $this->gql_endpoint = $gql_endpoint; |
|
50 | + $this->request = $request; |
|
51 | + $this->factory = $factory; |
|
52 | + $this->globalRouteConditions = $globalRouteConditions; |
|
53 | + $permalink_structure = ltrim((string) get_option('permalink_structure'), '/'); |
|
54 | + $this->permalink_prefix = strpos($permalink_structure, 'index.php') === 0 ? '/index.php/' : ''; |
|
55 | + } |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * @param string $globalRouteCondition |
|
60 | + * @param mixed $default |
|
61 | + * @return mixed |
|
62 | + */ |
|
63 | + private function getGlobalRouteCondition(string $globalRouteCondition, $default = false) |
|
64 | + { |
|
65 | + return $this->globalRouteConditions[ $globalRouteCondition ] ?? $default; |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * @return RequestTypeContext |
|
71 | + * @throws InvalidArgumentException |
|
72 | + */ |
|
73 | + public function detectRequestTypeContext(): RequestTypeContext |
|
74 | + { |
|
75 | + // Detect error scrapes |
|
76 | + if ($this->isWordPressErrorScrape()) { |
|
77 | + return $this->factory->create(RequestTypeContext::WP_SCRAPE); |
|
78 | + } |
|
79 | + // Detect activations |
|
80 | + if ($this->isWordPressActivationRequest()) { |
|
81 | + return $this->factory->create(RequestTypeContext::ACTIVATION); |
|
82 | + } |
|
83 | + // Detect EE REST API |
|
84 | + if ($this->isEspressoRestApiRequest()) { |
|
85 | + return $this->factory->create(RequestTypeContext::API); |
|
86 | + } |
|
87 | + // Detect WP REST API |
|
88 | + if ($this->isWordPressRestApiRequest()) { |
|
89 | + return $this->factory->create(RequestTypeContext::WP_API); |
|
90 | + } |
|
91 | + // Detect EE GraphQL |
|
92 | + if ($this->isEspressoGraphQLRequest()) { |
|
93 | + return $this->factory->create(RequestTypeContext::GQL); |
|
94 | + } |
|
95 | + // Detect AJAX |
|
96 | + if ($this->getGlobalRouteCondition('DOING_AJAX')) { |
|
97 | + return $this->isAjaxRequest(); |
|
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')) { |
|
105 | + return $this->factory->create(RequestTypeContext::CLI); |
|
106 | + } |
|
107 | + // detect WordPress admin (ie: "Dashboard") |
|
108 | + if ($this->getGlobalRouteCondition('is_admin')) { |
|
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 RequestTypeContext |
|
126 | + */ |
|
127 | + private function isAjaxRequest(): RequestTypeContext |
|
128 | + { |
|
129 | + if ( |
|
130 | + $this->request->getRequestParam('ee_front_ajax', false, 'bool') |
|
131 | + || $this->request->getRequestParam('data[ee_front_ajax]', false, 'bool') |
|
132 | + ) { |
|
133 | + if (! defined('EE_FRONT_AJAX')) { |
|
134 | + define('EE_FRONT_AJAX', true); |
|
135 | + } |
|
136 | + if (! defined('EE_ADMIN_AJAX')) { |
|
137 | + define('EE_ADMIN_AJAX', false); |
|
138 | + } |
|
139 | + return $this->factory->create(RequestTypeContext::AJAX_FRONT); |
|
140 | + } |
|
141 | + if ( |
|
142 | + $this->request->getRequestParam('ee_admin_ajax', false, 'bool') |
|
143 | + || $this->request->getRequestParam('data[ee_admin_ajax]', false, 'bool') |
|
144 | + ) { |
|
145 | + if (! defined('EE_ADMIN_AJAX')) { |
|
146 | + define('EE_ADMIN_AJAX', true); |
|
147 | + } |
|
148 | + if (! defined('EE_FRONT_AJAX')) { |
|
149 | + define('EE_FRONT_AJAX', false); |
|
150 | + } |
|
151 | + return $this->factory->create(RequestTypeContext::AJAX_ADMIN); |
|
152 | + } |
|
153 | + if ($this->request->getRequestParam('action') === 'heartbeat') { |
|
154 | + return $this->factory->create(RequestTypeContext::AJAX_HEARTBEAT); |
|
155 | + } |
|
156 | + return $this->factory->create(RequestTypeContext::AJAX_OTHER); |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * @return bool |
|
162 | + */ |
|
163 | + private function isWordPressErrorScrape(): bool |
|
164 | + { |
|
165 | + return ( |
|
166 | + $this->request->getRequestParam('wp_scrape_key') !== '' |
|
167 | + && $this->request->getRequestParam('wp_scrape_nonce') !== '' |
|
168 | + ) || ( |
|
169 | + $this->request->getRequestParam('action') === 'error_scrape' |
|
170 | + && $this->request->getRequestParam('_wpnonce') !== '' |
|
171 | + ); |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * @return bool |
|
177 | + */ |
|
178 | + private function isWordPressActivationRequest(): bool |
|
179 | + { |
|
180 | + $action = $this->request->getRequestParam('action'); |
|
181 | + $plugins_page_actions = [ |
|
182 | + 'true', |
|
183 | + 'activate', |
|
184 | + 'activate-multi', |
|
185 | + 'activate-selected', |
|
186 | + 'deactivate', |
|
187 | + 'deactivate-multi', |
|
188 | + 'deactivate-selected', |
|
189 | + 'delete-selected', |
|
190 | + 'disable-auto-update-selected', |
|
191 | + 'enable-auto-update-selected', |
|
192 | + 'update-selected', |
|
193 | + ]; |
|
194 | + return ($this->uriPathMatches('wp-admin/update.php') && $action === 'upload-plugin') |
|
195 | + || ($this->uriPathMatches('wp-admin/plugins.php') && in_array($action, $plugins_page_actions, true)); |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * @param string $extra_path |
|
201 | + * @return bool |
|
202 | + */ |
|
203 | + private function isRestApiRequest(string $extra_path = ''): bool |
|
204 | + { |
|
205 | + $rest_route = $this->request->getRequestParam('rest_route'); |
|
206 | + return ( |
|
207 | + $this->request->getRequestParam('rest_route') !== '' |
|
208 | + && ( $extra_path === '' || strpos($rest_route, $extra_path) !== 0 ) |
|
209 | + ) |
|
210 | + || $this->uriPathMatches(trim(rest_get_url_prefix(), '/') . $extra_path); |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * @return bool |
|
216 | + */ |
|
217 | + private function isEspressoRestApiRequest(): bool |
|
218 | + { |
|
219 | + $api_namespace = '/' . ltrim(Domain::API_NAMESPACE, '/'); |
|
220 | + // Check for URLs like http://mysite.com/?rest_route=/ee... and http://mysite.com/wp-json/ee/... |
|
221 | + return $this->isRestApiRequest($api_namespace); |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + /** |
|
226 | + * Checks for URLs like https://mysite.com/graphql |
|
227 | + * |
|
228 | + * @return bool |
|
229 | + */ |
|
230 | + private function isEspressoGraphQLRequest(): bool |
|
231 | + { |
|
232 | + if ($this->gql_endpoint->isGraphqlRequest()) { |
|
233 | + return true; |
|
234 | + } |
|
235 | + $gql_endpoint = $this->gql_endpoint->getEndpoint(); |
|
236 | + return $this->uriPathMatches($gql_endpoint) || $this->request->requestParamIsSet($gql_endpoint); |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * @return bool |
|
242 | + */ |
|
243 | + private function isWordPressRestApiRequest(): bool |
|
244 | + { |
|
245 | + // Check for URLs like http://mysite.com/?rest_route=/.. and http://mysite.com/wp-json/... |
|
246 | + return $this->isRestApiRequest(); |
|
247 | + } |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * @return bool |
|
252 | + */ |
|
253 | + private function isCronRequest(): bool |
|
254 | + { |
|
255 | + return $this->uriPathMatches('wp-cron.php'); |
|
256 | + } |
|
257 | + |
|
258 | + |
|
259 | + /** |
|
260 | + * @return bool |
|
261 | + */ |
|
262 | + private function isFeedRequest(): bool |
|
263 | + { |
|
264 | + return $this->uriPathMatches('feed'); |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + /** |
|
269 | + * returns true if the current request URI starts with the supplied $component string |
|
270 | + * |
|
271 | + * @param string $component |
|
272 | + * @return bool |
|
273 | + */ |
|
274 | + private function uriPathMatches(string $component): bool |
|
275 | + { |
|
276 | + $request_uri = $this->request->requestUri(true); |
|
277 | + // remove permalink /index.php/ prefix if present |
|
278 | + if (substr($request_uri, 0, strlen($this->permalink_prefix)) === $this->permalink_prefix) { |
|
279 | + $request_uri = substr($request_uri, strlen($this->permalink_prefix)); |
|
280 | + } |
|
281 | + $parts = explode('?', $request_uri); |
|
282 | + $path = trim(reset($parts), '/'); |
|
283 | + return strpos($path, $component) === 0; |
|
284 | + } |
|
285 | + |
|
286 | + |
|
287 | + /** |
|
288 | + * @return bool |
|
289 | + */ |
|
290 | + private function isIframeRoute(): bool |
|
291 | + { |
|
292 | + $is_iframe_route = apply_filters( |
|
293 | + 'FHEE__EventEspresso_core_domain_services_contexts_RequestTypeContextDetector__isIframeRoute', |
|
294 | + $this->request->getRequestParam('event_list', '') === 'iframe' |
|
295 | + || $this->request->getRequestParam('ticket_selector', '') === 'iframe' |
|
296 | + || $this->request->getRequestParam('calendar', '') === 'iframe', |
|
297 | + $this |
|
298 | + ); |
|
299 | + return filter_var($is_iframe_route, FILTER_VALIDATE_BOOLEAN); |
|
300 | + } |
|
301 | 301 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | */ |
63 | 63 | private function getGlobalRouteCondition(string $globalRouteCondition, $default = false) |
64 | 64 | { |
65 | - return $this->globalRouteConditions[ $globalRouteCondition ] ?? $default; |
|
65 | + return $this->globalRouteConditions[$globalRouteCondition] ?? $default; |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | |
@@ -130,10 +130,10 @@ discard block |
||
130 | 130 | $this->request->getRequestParam('ee_front_ajax', false, 'bool') |
131 | 131 | || $this->request->getRequestParam('data[ee_front_ajax]', false, 'bool') |
132 | 132 | ) { |
133 | - if (! defined('EE_FRONT_AJAX')) { |
|
133 | + if ( ! defined('EE_FRONT_AJAX')) { |
|
134 | 134 | define('EE_FRONT_AJAX', true); |
135 | 135 | } |
136 | - if (! defined('EE_ADMIN_AJAX')) { |
|
136 | + if ( ! defined('EE_ADMIN_AJAX')) { |
|
137 | 137 | define('EE_ADMIN_AJAX', false); |
138 | 138 | } |
139 | 139 | return $this->factory->create(RequestTypeContext::AJAX_FRONT); |
@@ -142,10 +142,10 @@ discard block |
||
142 | 142 | $this->request->getRequestParam('ee_admin_ajax', false, 'bool') |
143 | 143 | || $this->request->getRequestParam('data[ee_admin_ajax]', false, 'bool') |
144 | 144 | ) { |
145 | - if (! defined('EE_ADMIN_AJAX')) { |
|
145 | + if ( ! defined('EE_ADMIN_AJAX')) { |
|
146 | 146 | define('EE_ADMIN_AJAX', true); |
147 | 147 | } |
148 | - if (! defined('EE_FRONT_AJAX')) { |
|
148 | + if ( ! defined('EE_FRONT_AJAX')) { |
|
149 | 149 | define('EE_FRONT_AJAX', false); |
150 | 150 | } |
151 | 151 | return $this->factory->create(RequestTypeContext::AJAX_ADMIN); |
@@ -205,9 +205,9 @@ discard block |
||
205 | 205 | $rest_route = $this->request->getRequestParam('rest_route'); |
206 | 206 | return ( |
207 | 207 | $this->request->getRequestParam('rest_route') !== '' |
208 | - && ( $extra_path === '' || strpos($rest_route, $extra_path) !== 0 ) |
|
208 | + && ($extra_path === '' || strpos($rest_route, $extra_path) !== 0) |
|
209 | 209 | ) |
210 | - || $this->uriPathMatches(trim(rest_get_url_prefix(), '/') . $extra_path); |
|
210 | + || $this->uriPathMatches(trim(rest_get_url_prefix(), '/').$extra_path); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | */ |
217 | 217 | private function isEspressoRestApiRequest(): bool |
218 | 218 | { |
219 | - $api_namespace = '/' . ltrim(Domain::API_NAMESPACE, '/'); |
|
219 | + $api_namespace = '/'.ltrim(Domain::API_NAMESPACE, '/'); |
|
220 | 220 | // Check for URLs like http://mysite.com/?rest_route=/ee... and http://mysite.com/wp-json/ee/... |
221 | 221 | return $this->isRestApiRequest($api_namespace); |
222 | 222 | } |
@@ -17,339 +17,339 @@ |
||
17 | 17 | */ |
18 | 18 | class MessageTemplateManager |
19 | 19 | { |
20 | - private EEM_Message_Template $message_template_model; |
|
21 | - |
|
22 | - private EEM_Message_Template_Group $message_template_group_model; |
|
23 | - |
|
24 | - protected MessageTemplateRequestData $form_data; |
|
25 | - |
|
26 | - protected MessageTemplateValidator $validator; |
|
27 | - |
|
28 | - protected RequestInterface $request; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * @param EEM_Message_Template $message_template_model |
|
33 | - * @param EEM_Message_Template_Group $message_template_group_model |
|
34 | - * @param MessageTemplateRequestData $form_data |
|
35 | - * @param MessageTemplateValidator $validator |
|
36 | - * @param RequestInterface $request |
|
37 | - */ |
|
38 | - public function __construct( |
|
39 | - EEM_Message_Template $message_template_model, |
|
40 | - EEM_Message_Template_Group $message_template_group_model, |
|
41 | - MessageTemplateRequestData $form_data, |
|
42 | - MessageTemplateValidator $validator, |
|
43 | - RequestInterface $request |
|
44 | - ) { |
|
45 | - $this->message_template_model = $message_template_model; |
|
46 | - $this->message_template_group_model = $message_template_group_model; |
|
47 | - $this->form_data = $form_data; |
|
48 | - $this->validator = $validator; |
|
49 | - $this->request = $request; |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * @param string|null $messenger |
|
55 | - * @param string|null $message_type |
|
56 | - * @param int $GRP_ID |
|
57 | - * @param bool $global |
|
58 | - * @return array |
|
59 | - * @throws EE_Error |
|
60 | - * @throws ReflectionException |
|
61 | - */ |
|
62 | - public function generateNewTemplates( |
|
63 | - ?string $messenger = '', |
|
64 | - ?string $message_type = '', |
|
65 | - int $GRP_ID = 0, |
|
66 | - bool $global = false |
|
67 | - ): array { |
|
68 | - $this->form_data->setMessageTemplateRequestData(); |
|
69 | - |
|
70 | - $messenger = $messenger ?: $this->form_data->messenger(); |
|
71 | - $message_type = $message_type ?: $this->form_data->messageType(); |
|
72 | - $GRP_ID = $GRP_ID ?: $this->form_data->groupID(); |
|
73 | - |
|
74 | - // if no $message_types are given then that's okay... |
|
75 | - // this may be a messenger that just adds shortcodes, |
|
76 | - // so we just don't generate any templates. |
|
77 | - if (empty($message_type)) { |
|
78 | - return []; |
|
79 | - } |
|
80 | - $new_templates = EEH_MSG_Template::generate_new_templates($messenger, [$message_type], $GRP_ID, $global); |
|
81 | - return $new_templates[0]; |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * @throws DomainException |
|
87 | - * @throws EE_Error |
|
88 | - * @throws ReflectionException |
|
89 | - */ |
|
90 | - public function updateExistingTemplates(): void |
|
91 | - { |
|
92 | - $this->form_data->setMessageTemplateRequestData(); |
|
93 | - $template_fields = $this->form_data->templateFields(); |
|
94 | - |
|
95 | - if ($template_fields) { |
|
96 | - if ( |
|
97 | - $this->validator->validateTemplateFields( |
|
98 | - $this->form_data->messenger(), |
|
99 | - $this->form_data->messageType(), |
|
100 | - $this->form_data->context(), |
|
101 | - $template_fields |
|
102 | - ) |
|
103 | - ) { |
|
104 | - foreach ($template_fields as $template_field => $data) { |
|
105 | - $this->validateTemplateFieldData($template_field, $data); |
|
106 | - $this->updateMessageTemplate( |
|
107 | - $template_field, |
|
108 | - [ |
|
109 | - 'GRP_ID' => $this->form_data->groupID(), |
|
110 | - 'MTP_ID' => $data['MTP_ID'], |
|
111 | - 'MTP_template_field' => $data['name'], |
|
112 | - 'MTP_context' => $this->form_data->context(), |
|
113 | - // if they aren't allowed to use all JS, restrict them to standard allowed post tags |
|
114 | - 'MTP_content' => ! current_user_can('unfiltered_html') |
|
115 | - ? $this->sanitizeMessageTemplateContent($data['content']) |
|
116 | - : $data['content'], |
|
117 | - ] |
|
118 | - ); |
|
119 | - } |
|
120 | - // we can use the last set_column_values for the Message Template Group update |
|
121 | - // (because its the same for all of these specific MTPs) |
|
122 | - $this->updateMessageTemplateGroup( |
|
123 | - [ |
|
124 | - 'GRP_ID' => $this->form_data->groupID(), |
|
125 | - 'MTP_user_id' => $this->form_data->userID(), |
|
126 | - 'MTP_messenger' => $this->form_data->messenger(), |
|
127 | - 'MTP_message_type' => $this->form_data->messageType(), |
|
128 | - 'MTP_is_global' => $this->form_data->isGlobal(), |
|
129 | - 'MTP_is_override' => $this->form_data->isOverride(), |
|
130 | - 'MTP_deleted' => $this->form_data->isDeleted(), |
|
131 | - 'MTP_is_active' => $this->form_data->isActive(), |
|
132 | - 'MTP_name' => $this->form_data->name(), |
|
133 | - 'MTP_description' => $this->form_data->description(), |
|
134 | - ] |
|
135 | - ); |
|
136 | - } |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * @param string $template_field |
|
143 | - * @param array $message_template_fields |
|
144 | - * @return void |
|
145 | - * @throws EE_Error |
|
146 | - * @throws ReflectionException |
|
147 | - */ |
|
148 | - private function updateMessageTemplate(string $template_field, array $message_template_fields): void |
|
149 | - { |
|
150 | - $MTP_ID = $message_template_fields['MTP_ID'] ?? 0; |
|
151 | - // if we have a MTP_ID for this field then update it, otherwise insert. |
|
152 | - // this has already been through the template field validator and sanitized, so it will be |
|
153 | - // safe to insert this field. Why insert? This typically happens when we introduce a new |
|
154 | - // message template field in a messenger/message type and existing users don't have the |
|
155 | - // default setup for it. |
|
156 | - // @link https://events.codebasehq.com/projects/event-espresso/tickets/9465 |
|
157 | - $updated = $MTP_ID |
|
158 | - ? $this->message_template_model->update($message_template_fields, [['MTP_ID' => $MTP_ID]]) |
|
159 | - : $this->message_template_model->insert($message_template_fields); |
|
160 | - |
|
161 | - // updates will return 0 if the field was not changed (ie: no changes = nothing actually updated) |
|
162 | - // but we won't consider that a problem, but if it returns false, then something went BOOM! |
|
163 | - if ($updated === false) { |
|
164 | - EE_Error::add_error( |
|
165 | - sprintf( |
|
166 | - esc_html__('%s field was NOT updated for some reason', 'event_espresso'), |
|
167 | - $template_field |
|
168 | - ), |
|
169 | - __FILE__, |
|
170 | - __FUNCTION__, |
|
171 | - __LINE__ |
|
172 | - ); |
|
173 | - } |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * @param array $form_data |
|
179 | - * @return void |
|
180 | - * @throws EE_Error |
|
181 | - * @throws ReflectionException |
|
182 | - */ |
|
183 | - private function updateMessageTemplateGroup(array $form_data): void |
|
184 | - { |
|
185 | - try { |
|
186 | - $GRP_ID = $form_data['id'] ?? 0; |
|
187 | - $GRP_ID = $form_data['GRP_ID'] ?? $GRP_ID; |
|
188 | - if (! $GRP_ID) { |
|
189 | - throw new RuntimeException( |
|
190 | - esc_html__( |
|
191 | - 'Can not update message template group because no GRP_ID was provided', |
|
192 | - 'event_espresso' |
|
193 | - ) |
|
194 | - ); |
|
195 | - } |
|
196 | - |
|
197 | - $updated = $this->message_template_group_model->update($form_data, [['GRP_ID' => $GRP_ID]]); |
|
198 | - $error_message = esc_html__( |
|
199 | - 'unknown error occurred while updating message template group', |
|
200 | - 'event_espresso' |
|
201 | - ); |
|
202 | - |
|
203 | - if ($updated !== false) { |
|
204 | - $message_template_group = $this->message_template_group_model->get_one_by_ID($GRP_ID); |
|
205 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
206 | - // k now we need to ensure the template_pack and template_variation fields are set. |
|
207 | - $template_pack = $this->request->getRequestParam('MTP_template_pack', 'default'); |
|
208 | - $template_variation = $this->request->getRequestParam('MTP_template_variation', 'default'); |
|
209 | - $message_template_group->set_template_pack_name($template_pack); |
|
210 | - $message_template_group->set_template_pack_variation($template_variation); |
|
211 | - } |
|
212 | - return; |
|
213 | - } |
|
214 | - } catch (RuntimeException $exception) { |
|
215 | - $error_message = $exception->getMessage(); |
|
216 | - } |
|
217 | - |
|
218 | - EE_Error::add_error( |
|
219 | - sprintf( |
|
220 | - esc_html__( |
|
221 | - 'The Message Template Group (%1$d) was NOT updated for the following reason: %2$s', |
|
222 | - 'event_espresso' |
|
223 | - ), |
|
224 | - $form_data['GRP_ID'], |
|
225 | - $error_message |
|
226 | - ), |
|
227 | - __FILE__, |
|
228 | - __FUNCTION__, |
|
229 | - __LINE__ |
|
230 | - ); |
|
231 | - } |
|
232 | - |
|
233 | - |
|
234 | - /** |
|
235 | - * recursively runs wp_kses() on message template content in a model safe manner |
|
236 | - * |
|
237 | - * @param array|string $content |
|
238 | - * @return array|string |
|
239 | - * @since 4.10.29.p |
|
240 | - */ |
|
241 | - private function sanitizeMessageTemplateContent($content) |
|
242 | - { |
|
243 | - if (is_array($content)) { |
|
244 | - foreach ($content as $key => $value) { |
|
245 | - $content[ $key ] = $this->sanitizeMessageTemplateContent($value); |
|
246 | - } |
|
247 | - return $content; |
|
248 | - } |
|
249 | - // remove slashes so wp_kses() works properly |
|
250 | - // wp_kses_stripslashes() only removes slashes from double-quotes, |
|
251 | - // so attributes using single quotes always appear invalid. |
|
252 | - $content = stripslashes($content); |
|
253 | - $content = wp_kses($content, wp_kses_allowed_html('post')); |
|
254 | - // But currently the models expect slashed data, so after wp_kses() |
|
255 | - // runs we need to re-slash the data. Sheesh. |
|
256 | - // See https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587 |
|
257 | - return addslashes($content); |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - /** |
|
262 | - * @param int $GRP_ID |
|
263 | - * @return false|int |
|
264 | - * @throws EE_Error |
|
265 | - * @throws ReflectionException |
|
266 | - */ |
|
267 | - public function trashMessageTemplate(int $GRP_ID) |
|
268 | - { |
|
269 | - return $this->message_template_group_model->delete_by_ID($GRP_ID); |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * @param int $GRP_ID |
|
275 | - * @return bool |
|
276 | - * @throws EE_Error |
|
277 | - */ |
|
278 | - public function restoreMessageTemplate(int $GRP_ID): bool |
|
279 | - { |
|
280 | - return $this->message_template_group_model->restore_by_ID($GRP_ID); |
|
281 | - } |
|
282 | - |
|
283 | - |
|
284 | - /** |
|
285 | - * @param int $GRP_ID |
|
286 | - * @return EE_Message_Template_Group |
|
287 | - * @throws EE_Error |
|
288 | - * @throws ReflectionException |
|
289 | - */ |
|
290 | - private function getMessageTemplateGroup(int $GRP_ID): EE_Message_Template_Group |
|
291 | - { |
|
292 | - $message_template_group = $this->message_template_group_model->get_one_by_ID($GRP_ID); |
|
293 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
294 | - return $message_template_group; |
|
295 | - } |
|
296 | - throw new RuntimeException( |
|
297 | - esc_html__( |
|
298 | - 'Can not permanently delete message template group because an invalid GRP_ID was provided', |
|
299 | - 'event_espresso' |
|
300 | - ) |
|
301 | - ); |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * @param int $GRP_ID |
|
307 | - * @return bool |
|
308 | - * @throws EE_Error |
|
309 | - * @throws ReflectionException |
|
310 | - */ |
|
311 | - public function permanentlyDeleteMessageTemplates(int $GRP_ID): bool |
|
312 | - { |
|
313 | - $message_template_group = $this->getMessageTemplateGroup($GRP_ID); |
|
314 | - // permanently delete all the related Message Templates |
|
315 | - $deleted = $message_template_group->delete_related_permanently('Message_Template'); |
|
316 | - return $deleted > 0; |
|
317 | - } |
|
318 | - |
|
319 | - |
|
320 | - /** |
|
321 | - * @param int $GRP_ID |
|
322 | - * @return bool |
|
323 | - * @throws EE_Error |
|
324 | - * @throws ReflectionException |
|
325 | - */ |
|
326 | - public function permanentlyDeleteMessageTemplateGroup(int $GRP_ID): bool |
|
327 | - { |
|
328 | - if ($this->permanentlyDeleteMessageTemplates($GRP_ID)) { |
|
329 | - return $this->message_template_group_model->delete_permanently([['GRP_ID' => $GRP_ID]]); |
|
330 | - } |
|
331 | - return false; |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - private function validateTemplateFieldData(string $template_field, array $data) |
|
336 | - { |
|
337 | - if ( |
|
338 | - ! ( |
|
339 | - array_key_exists('MTP_ID', $data) |
|
340 | - && array_key_exists('name', $data) |
|
341 | - && array_key_exists('content', $data) |
|
342 | - ) |
|
343 | - ) { |
|
344 | - throw new RuntimeException( |
|
345 | - sprintf( |
|
346 | - esc_html__( |
|
347 | - 'Can not update message template field %1$s because of a missing MTP_ID, name, or content.', |
|
348 | - 'event_espresso' |
|
349 | - ), |
|
350 | - $template_field |
|
351 | - ) |
|
352 | - ); |
|
353 | - } |
|
354 | - } |
|
20 | + private EEM_Message_Template $message_template_model; |
|
21 | + |
|
22 | + private EEM_Message_Template_Group $message_template_group_model; |
|
23 | + |
|
24 | + protected MessageTemplateRequestData $form_data; |
|
25 | + |
|
26 | + protected MessageTemplateValidator $validator; |
|
27 | + |
|
28 | + protected RequestInterface $request; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * @param EEM_Message_Template $message_template_model |
|
33 | + * @param EEM_Message_Template_Group $message_template_group_model |
|
34 | + * @param MessageTemplateRequestData $form_data |
|
35 | + * @param MessageTemplateValidator $validator |
|
36 | + * @param RequestInterface $request |
|
37 | + */ |
|
38 | + public function __construct( |
|
39 | + EEM_Message_Template $message_template_model, |
|
40 | + EEM_Message_Template_Group $message_template_group_model, |
|
41 | + MessageTemplateRequestData $form_data, |
|
42 | + MessageTemplateValidator $validator, |
|
43 | + RequestInterface $request |
|
44 | + ) { |
|
45 | + $this->message_template_model = $message_template_model; |
|
46 | + $this->message_template_group_model = $message_template_group_model; |
|
47 | + $this->form_data = $form_data; |
|
48 | + $this->validator = $validator; |
|
49 | + $this->request = $request; |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * @param string|null $messenger |
|
55 | + * @param string|null $message_type |
|
56 | + * @param int $GRP_ID |
|
57 | + * @param bool $global |
|
58 | + * @return array |
|
59 | + * @throws EE_Error |
|
60 | + * @throws ReflectionException |
|
61 | + */ |
|
62 | + public function generateNewTemplates( |
|
63 | + ?string $messenger = '', |
|
64 | + ?string $message_type = '', |
|
65 | + int $GRP_ID = 0, |
|
66 | + bool $global = false |
|
67 | + ): array { |
|
68 | + $this->form_data->setMessageTemplateRequestData(); |
|
69 | + |
|
70 | + $messenger = $messenger ?: $this->form_data->messenger(); |
|
71 | + $message_type = $message_type ?: $this->form_data->messageType(); |
|
72 | + $GRP_ID = $GRP_ID ?: $this->form_data->groupID(); |
|
73 | + |
|
74 | + // if no $message_types are given then that's okay... |
|
75 | + // this may be a messenger that just adds shortcodes, |
|
76 | + // so we just don't generate any templates. |
|
77 | + if (empty($message_type)) { |
|
78 | + return []; |
|
79 | + } |
|
80 | + $new_templates = EEH_MSG_Template::generate_new_templates($messenger, [$message_type], $GRP_ID, $global); |
|
81 | + return $new_templates[0]; |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * @throws DomainException |
|
87 | + * @throws EE_Error |
|
88 | + * @throws ReflectionException |
|
89 | + */ |
|
90 | + public function updateExistingTemplates(): void |
|
91 | + { |
|
92 | + $this->form_data->setMessageTemplateRequestData(); |
|
93 | + $template_fields = $this->form_data->templateFields(); |
|
94 | + |
|
95 | + if ($template_fields) { |
|
96 | + if ( |
|
97 | + $this->validator->validateTemplateFields( |
|
98 | + $this->form_data->messenger(), |
|
99 | + $this->form_data->messageType(), |
|
100 | + $this->form_data->context(), |
|
101 | + $template_fields |
|
102 | + ) |
|
103 | + ) { |
|
104 | + foreach ($template_fields as $template_field => $data) { |
|
105 | + $this->validateTemplateFieldData($template_field, $data); |
|
106 | + $this->updateMessageTemplate( |
|
107 | + $template_field, |
|
108 | + [ |
|
109 | + 'GRP_ID' => $this->form_data->groupID(), |
|
110 | + 'MTP_ID' => $data['MTP_ID'], |
|
111 | + 'MTP_template_field' => $data['name'], |
|
112 | + 'MTP_context' => $this->form_data->context(), |
|
113 | + // if they aren't allowed to use all JS, restrict them to standard allowed post tags |
|
114 | + 'MTP_content' => ! current_user_can('unfiltered_html') |
|
115 | + ? $this->sanitizeMessageTemplateContent($data['content']) |
|
116 | + : $data['content'], |
|
117 | + ] |
|
118 | + ); |
|
119 | + } |
|
120 | + // we can use the last set_column_values for the Message Template Group update |
|
121 | + // (because its the same for all of these specific MTPs) |
|
122 | + $this->updateMessageTemplateGroup( |
|
123 | + [ |
|
124 | + 'GRP_ID' => $this->form_data->groupID(), |
|
125 | + 'MTP_user_id' => $this->form_data->userID(), |
|
126 | + 'MTP_messenger' => $this->form_data->messenger(), |
|
127 | + 'MTP_message_type' => $this->form_data->messageType(), |
|
128 | + 'MTP_is_global' => $this->form_data->isGlobal(), |
|
129 | + 'MTP_is_override' => $this->form_data->isOverride(), |
|
130 | + 'MTP_deleted' => $this->form_data->isDeleted(), |
|
131 | + 'MTP_is_active' => $this->form_data->isActive(), |
|
132 | + 'MTP_name' => $this->form_data->name(), |
|
133 | + 'MTP_description' => $this->form_data->description(), |
|
134 | + ] |
|
135 | + ); |
|
136 | + } |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * @param string $template_field |
|
143 | + * @param array $message_template_fields |
|
144 | + * @return void |
|
145 | + * @throws EE_Error |
|
146 | + * @throws ReflectionException |
|
147 | + */ |
|
148 | + private function updateMessageTemplate(string $template_field, array $message_template_fields): void |
|
149 | + { |
|
150 | + $MTP_ID = $message_template_fields['MTP_ID'] ?? 0; |
|
151 | + // if we have a MTP_ID for this field then update it, otherwise insert. |
|
152 | + // this has already been through the template field validator and sanitized, so it will be |
|
153 | + // safe to insert this field. Why insert? This typically happens when we introduce a new |
|
154 | + // message template field in a messenger/message type and existing users don't have the |
|
155 | + // default setup for it. |
|
156 | + // @link https://events.codebasehq.com/projects/event-espresso/tickets/9465 |
|
157 | + $updated = $MTP_ID |
|
158 | + ? $this->message_template_model->update($message_template_fields, [['MTP_ID' => $MTP_ID]]) |
|
159 | + : $this->message_template_model->insert($message_template_fields); |
|
160 | + |
|
161 | + // updates will return 0 if the field was not changed (ie: no changes = nothing actually updated) |
|
162 | + // but we won't consider that a problem, but if it returns false, then something went BOOM! |
|
163 | + if ($updated === false) { |
|
164 | + EE_Error::add_error( |
|
165 | + sprintf( |
|
166 | + esc_html__('%s field was NOT updated for some reason', 'event_espresso'), |
|
167 | + $template_field |
|
168 | + ), |
|
169 | + __FILE__, |
|
170 | + __FUNCTION__, |
|
171 | + __LINE__ |
|
172 | + ); |
|
173 | + } |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * @param array $form_data |
|
179 | + * @return void |
|
180 | + * @throws EE_Error |
|
181 | + * @throws ReflectionException |
|
182 | + */ |
|
183 | + private function updateMessageTemplateGroup(array $form_data): void |
|
184 | + { |
|
185 | + try { |
|
186 | + $GRP_ID = $form_data['id'] ?? 0; |
|
187 | + $GRP_ID = $form_data['GRP_ID'] ?? $GRP_ID; |
|
188 | + if (! $GRP_ID) { |
|
189 | + throw new RuntimeException( |
|
190 | + esc_html__( |
|
191 | + 'Can not update message template group because no GRP_ID was provided', |
|
192 | + 'event_espresso' |
|
193 | + ) |
|
194 | + ); |
|
195 | + } |
|
196 | + |
|
197 | + $updated = $this->message_template_group_model->update($form_data, [['GRP_ID' => $GRP_ID]]); |
|
198 | + $error_message = esc_html__( |
|
199 | + 'unknown error occurred while updating message template group', |
|
200 | + 'event_espresso' |
|
201 | + ); |
|
202 | + |
|
203 | + if ($updated !== false) { |
|
204 | + $message_template_group = $this->message_template_group_model->get_one_by_ID($GRP_ID); |
|
205 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
206 | + // k now we need to ensure the template_pack and template_variation fields are set. |
|
207 | + $template_pack = $this->request->getRequestParam('MTP_template_pack', 'default'); |
|
208 | + $template_variation = $this->request->getRequestParam('MTP_template_variation', 'default'); |
|
209 | + $message_template_group->set_template_pack_name($template_pack); |
|
210 | + $message_template_group->set_template_pack_variation($template_variation); |
|
211 | + } |
|
212 | + return; |
|
213 | + } |
|
214 | + } catch (RuntimeException $exception) { |
|
215 | + $error_message = $exception->getMessage(); |
|
216 | + } |
|
217 | + |
|
218 | + EE_Error::add_error( |
|
219 | + sprintf( |
|
220 | + esc_html__( |
|
221 | + 'The Message Template Group (%1$d) was NOT updated for the following reason: %2$s', |
|
222 | + 'event_espresso' |
|
223 | + ), |
|
224 | + $form_data['GRP_ID'], |
|
225 | + $error_message |
|
226 | + ), |
|
227 | + __FILE__, |
|
228 | + __FUNCTION__, |
|
229 | + __LINE__ |
|
230 | + ); |
|
231 | + } |
|
232 | + |
|
233 | + |
|
234 | + /** |
|
235 | + * recursively runs wp_kses() on message template content in a model safe manner |
|
236 | + * |
|
237 | + * @param array|string $content |
|
238 | + * @return array|string |
|
239 | + * @since 4.10.29.p |
|
240 | + */ |
|
241 | + private function sanitizeMessageTemplateContent($content) |
|
242 | + { |
|
243 | + if (is_array($content)) { |
|
244 | + foreach ($content as $key => $value) { |
|
245 | + $content[ $key ] = $this->sanitizeMessageTemplateContent($value); |
|
246 | + } |
|
247 | + return $content; |
|
248 | + } |
|
249 | + // remove slashes so wp_kses() works properly |
|
250 | + // wp_kses_stripslashes() only removes slashes from double-quotes, |
|
251 | + // so attributes using single quotes always appear invalid. |
|
252 | + $content = stripslashes($content); |
|
253 | + $content = wp_kses($content, wp_kses_allowed_html('post')); |
|
254 | + // But currently the models expect slashed data, so after wp_kses() |
|
255 | + // runs we need to re-slash the data. Sheesh. |
|
256 | + // See https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587 |
|
257 | + return addslashes($content); |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + /** |
|
262 | + * @param int $GRP_ID |
|
263 | + * @return false|int |
|
264 | + * @throws EE_Error |
|
265 | + * @throws ReflectionException |
|
266 | + */ |
|
267 | + public function trashMessageTemplate(int $GRP_ID) |
|
268 | + { |
|
269 | + return $this->message_template_group_model->delete_by_ID($GRP_ID); |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * @param int $GRP_ID |
|
275 | + * @return bool |
|
276 | + * @throws EE_Error |
|
277 | + */ |
|
278 | + public function restoreMessageTemplate(int $GRP_ID): bool |
|
279 | + { |
|
280 | + return $this->message_template_group_model->restore_by_ID($GRP_ID); |
|
281 | + } |
|
282 | + |
|
283 | + |
|
284 | + /** |
|
285 | + * @param int $GRP_ID |
|
286 | + * @return EE_Message_Template_Group |
|
287 | + * @throws EE_Error |
|
288 | + * @throws ReflectionException |
|
289 | + */ |
|
290 | + private function getMessageTemplateGroup(int $GRP_ID): EE_Message_Template_Group |
|
291 | + { |
|
292 | + $message_template_group = $this->message_template_group_model->get_one_by_ID($GRP_ID); |
|
293 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
294 | + return $message_template_group; |
|
295 | + } |
|
296 | + throw new RuntimeException( |
|
297 | + esc_html__( |
|
298 | + 'Can not permanently delete message template group because an invalid GRP_ID was provided', |
|
299 | + 'event_espresso' |
|
300 | + ) |
|
301 | + ); |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * @param int $GRP_ID |
|
307 | + * @return bool |
|
308 | + * @throws EE_Error |
|
309 | + * @throws ReflectionException |
|
310 | + */ |
|
311 | + public function permanentlyDeleteMessageTemplates(int $GRP_ID): bool |
|
312 | + { |
|
313 | + $message_template_group = $this->getMessageTemplateGroup($GRP_ID); |
|
314 | + // permanently delete all the related Message Templates |
|
315 | + $deleted = $message_template_group->delete_related_permanently('Message_Template'); |
|
316 | + return $deleted > 0; |
|
317 | + } |
|
318 | + |
|
319 | + |
|
320 | + /** |
|
321 | + * @param int $GRP_ID |
|
322 | + * @return bool |
|
323 | + * @throws EE_Error |
|
324 | + * @throws ReflectionException |
|
325 | + */ |
|
326 | + public function permanentlyDeleteMessageTemplateGroup(int $GRP_ID): bool |
|
327 | + { |
|
328 | + if ($this->permanentlyDeleteMessageTemplates($GRP_ID)) { |
|
329 | + return $this->message_template_group_model->delete_permanently([['GRP_ID' => $GRP_ID]]); |
|
330 | + } |
|
331 | + return false; |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + private function validateTemplateFieldData(string $template_field, array $data) |
|
336 | + { |
|
337 | + if ( |
|
338 | + ! ( |
|
339 | + array_key_exists('MTP_ID', $data) |
|
340 | + && array_key_exists('name', $data) |
|
341 | + && array_key_exists('content', $data) |
|
342 | + ) |
|
343 | + ) { |
|
344 | + throw new RuntimeException( |
|
345 | + sprintf( |
|
346 | + esc_html__( |
|
347 | + 'Can not update message template field %1$s because of a missing MTP_ID, name, or content.', |
|
348 | + 'event_espresso' |
|
349 | + ), |
|
350 | + $template_field |
|
351 | + ) |
|
352 | + ); |
|
353 | + } |
|
354 | + } |
|
355 | 355 | } |
@@ -14,262 +14,262 @@ |
||
14 | 14 | */ |
15 | 15 | class MessageTemplateRequestData |
16 | 16 | { |
17 | - protected ?RequestInterface $request = null; |
|
17 | + protected ?RequestInterface $request = null; |
|
18 | 18 | |
19 | - protected string $context = ''; |
|
19 | + protected string $context = ''; |
|
20 | 20 | |
21 | - protected string $description = ''; |
|
21 | + protected string $description = ''; |
|
22 | 22 | |
23 | - protected string $messenger = ''; |
|
23 | + protected string $messenger = ''; |
|
24 | 24 | |
25 | - protected string $message_type = ''; |
|
25 | + protected string $message_type = ''; |
|
26 | 26 | |
27 | - protected string $name = ''; |
|
27 | + protected string $name = ''; |
|
28 | 28 | |
29 | - protected array $template_fields = []; |
|
29 | + protected array $template_fields = []; |
|
30 | 30 | |
31 | - protected int $group_ID = 0; |
|
31 | + protected int $group_ID = 0; |
|
32 | 32 | |
33 | - protected int $user_ID = 0; |
|
33 | + protected int $user_ID = 0; |
|
34 | 34 | |
35 | - protected bool $is_active = false; |
|
35 | + protected bool $is_active = false; |
|
36 | 36 | |
37 | - protected bool $is_deleted = false; |
|
37 | + protected bool $is_deleted = false; |
|
38 | 38 | |
39 | - protected bool $is_global = false; |
|
39 | + protected bool $is_global = false; |
|
40 | 40 | |
41 | - protected bool $is_override = false; |
|
41 | + protected bool $is_override = false; |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * @param RequestInterface|null $request |
|
46 | - */ |
|
47 | - public function __construct(?RequestInterface $request) |
|
48 | - { |
|
49 | - $this->request = $request; |
|
50 | - } |
|
44 | + /** |
|
45 | + * @param RequestInterface|null $request |
|
46 | + */ |
|
47 | + public function __construct(?RequestInterface $request) |
|
48 | + { |
|
49 | + $this->request = $request; |
|
50 | + } |
|
51 | 51 | |
52 | 52 | |
53 | - public function setMessageTemplateRequestData() |
|
54 | - { |
|
55 | - $this->setContext(); |
|
56 | - $this->setDescription(); |
|
57 | - $this->setGroupID(); |
|
58 | - $this->setIsActive(); |
|
59 | - $this->setIsDeleted(); |
|
60 | - $this->setIsGlobal(); |
|
61 | - $this->setIsOverride(); |
|
62 | - $this->setMessenger(); |
|
63 | - $this->setMessageType(); |
|
64 | - $this->setName(); |
|
65 | - $this->setUserID(); |
|
66 | - $this->setTemplateFields(); |
|
67 | - } |
|
53 | + public function setMessageTemplateRequestData() |
|
54 | + { |
|
55 | + $this->setContext(); |
|
56 | + $this->setDescription(); |
|
57 | + $this->setGroupID(); |
|
58 | + $this->setIsActive(); |
|
59 | + $this->setIsDeleted(); |
|
60 | + $this->setIsGlobal(); |
|
61 | + $this->setIsOverride(); |
|
62 | + $this->setMessenger(); |
|
63 | + $this->setMessageType(); |
|
64 | + $this->setName(); |
|
65 | + $this->setUserID(); |
|
66 | + $this->setTemplateFields(); |
|
67 | + } |
|
68 | 68 | |
69 | 69 | |
70 | - public function context(): string |
|
71 | - { |
|
72 | - return $this->context; |
|
73 | - } |
|
70 | + public function context(): string |
|
71 | + { |
|
72 | + return $this->context; |
|
73 | + } |
|
74 | 74 | |
75 | 75 | |
76 | - public function description(): string |
|
77 | - { |
|
78 | - return $this->description; |
|
79 | - } |
|
76 | + public function description(): string |
|
77 | + { |
|
78 | + return $this->description; |
|
79 | + } |
|
80 | 80 | |
81 | 81 | |
82 | - public function messenger(): string |
|
83 | - { |
|
84 | - return $this->messenger; |
|
85 | - } |
|
82 | + public function messenger(): string |
|
83 | + { |
|
84 | + return $this->messenger; |
|
85 | + } |
|
86 | 86 | |
87 | 87 | |
88 | - public function messageType(): string |
|
89 | - { |
|
90 | - return $this->message_type; |
|
91 | - } |
|
88 | + public function messageType(): string |
|
89 | + { |
|
90 | + return $this->message_type; |
|
91 | + } |
|
92 | 92 | |
93 | 93 | |
94 | - public function name(): string |
|
95 | - { |
|
96 | - return $this->name; |
|
97 | - } |
|
94 | + public function name(): string |
|
95 | + { |
|
96 | + return $this->name; |
|
97 | + } |
|
98 | 98 | |
99 | 99 | |
100 | - public function templateFields(): array |
|
101 | - { |
|
102 | - return $this->template_fields; |
|
103 | - } |
|
100 | + public function templateFields(): array |
|
101 | + { |
|
102 | + return $this->template_fields; |
|
103 | + } |
|
104 | 104 | |
105 | 105 | |
106 | - public function groupID(): int |
|
107 | - { |
|
108 | - return $this->group_ID; |
|
109 | - } |
|
106 | + public function groupID(): int |
|
107 | + { |
|
108 | + return $this->group_ID; |
|
109 | + } |
|
110 | 110 | |
111 | 111 | |
112 | - public function userID(): int |
|
113 | - { |
|
114 | - return $this->user_ID; |
|
115 | - } |
|
112 | + public function userID(): int |
|
113 | + { |
|
114 | + return $this->user_ID; |
|
115 | + } |
|
116 | 116 | |
117 | 117 | |
118 | - public function isActive(): bool |
|
119 | - { |
|
120 | - return $this->is_active; |
|
121 | - } |
|
118 | + public function isActive(): bool |
|
119 | + { |
|
120 | + return $this->is_active; |
|
121 | + } |
|
122 | 122 | |
123 | 123 | |
124 | - public function isDeleted(): bool |
|
125 | - { |
|
126 | - return $this->is_deleted; |
|
127 | - } |
|
124 | + public function isDeleted(): bool |
|
125 | + { |
|
126 | + return $this->is_deleted; |
|
127 | + } |
|
128 | 128 | |
129 | 129 | |
130 | - public function isGlobal(): bool |
|
131 | - { |
|
132 | - return $this->is_global; |
|
133 | - } |
|
130 | + public function isGlobal(): bool |
|
131 | + { |
|
132 | + return $this->is_global; |
|
133 | + } |
|
134 | 134 | |
135 | 135 | |
136 | - public function isOverride(): bool |
|
137 | - { |
|
138 | - return $this->is_override; |
|
139 | - } |
|
136 | + public function isOverride(): bool |
|
137 | + { |
|
138 | + return $this->is_override; |
|
139 | + } |
|
140 | 140 | |
141 | 141 | |
142 | - public function setContext(?string $context = ''): void |
|
143 | - { |
|
144 | - $this->context = $this->request->getRequestParam('context', $context); |
|
145 | - $this->context = $this->request->getRequestParam('MTP_context', $this->context); |
|
146 | - $this->context = strtolower($this->context); |
|
147 | - } |
|
142 | + public function setContext(?string $context = ''): void |
|
143 | + { |
|
144 | + $this->context = $this->request->getRequestParam('context', $context); |
|
145 | + $this->context = $this->request->getRequestParam('MTP_context', $this->context); |
|
146 | + $this->context = strtolower($this->context); |
|
147 | + } |
|
148 | 148 | |
149 | 149 | |
150 | - public function setDescription(?string $description = ''): void |
|
151 | - { |
|
152 | - $this->description = $this->request->getRequestParam( |
|
153 | - 'ee_msg_non_global_fields[MTP_description]', |
|
154 | - $description |
|
155 | - ); |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - public function setGroupID(?int $group_ID = 0): void |
|
160 | - { |
|
161 | - $this->group_ID = $this->request->getRequestParam('group_ID', $group_ID, DataType::INTEGER); |
|
162 | - $this->group_ID = $this->request->getRequestParam('GRP_ID', $this->group_ID, DataType::INTEGER); |
|
163 | - // we need the GRP_ID for the template being used as the base for the new template |
|
164 | - if (empty($this->group_ID)) { |
|
165 | - throw new RuntimeException( |
|
166 | - esc_html__( |
|
167 | - 'In order to create a custom message template the GRP_ID of the template being used as a base is needed', |
|
168 | - 'event_espresso' |
|
169 | - ) |
|
170 | - ); |
|
171 | - } |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - public function setIsActive(bool $is_active = false): void |
|
176 | - { |
|
177 | - $this->is_active = $this->request->getRequestParam('MTP_is_active', $is_active, DataType::BOOLEAN); |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - public function setIsDeleted(bool $is_deleted = false): void |
|
182 | - { |
|
183 | - $this->is_deleted = $this->request->getRequestParam('MTP_deleted', $is_deleted, DataType::BOOLEAN); |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - public function setIsGlobal(bool $is_global = false): void |
|
188 | - { |
|
189 | - $this->is_global = $this->request->getRequestParam('MTP_is_global', $is_global, DataType::BOOLEAN); |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - public function setIsOverride(bool $is_override = false): void |
|
194 | - { |
|
195 | - $this->is_override = $this->request->getRequestParam('MTP_is_override', $is_override, DataType::BOOLEAN); |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - public function setMessenger(?string $messenger = ''): void |
|
200 | - { |
|
201 | - // have to check for multiple params because a previouv dev used different names for the same param >:( |
|
202 | - $this->messenger = $this->request->getRequestParam('msgr', $messenger); |
|
203 | - $this->messenger = $this->request->getRequestParam('messenger', $this->messenger); |
|
204 | - $this->messenger = $this->request->getRequestParam('MTP_messenger', $this->messenger); |
|
205 | - $this->messenger = strtolower($this->messenger); |
|
206 | - if (empty($this->messenger)) { |
|
207 | - throw new RuntimeException( |
|
208 | - esc_html__( |
|
209 | - 'Sorry, but we can\'t create new templates because we\'re missing the messenger', |
|
210 | - 'event_espresso' |
|
211 | - ) |
|
212 | - ); |
|
213 | - } |
|
214 | - } |
|
215 | - |
|
216 | - |
|
217 | - public function setMessageType(?string $message_type = ''): void |
|
218 | - { |
|
219 | - // have to check for multiple params because a previouv dev used different names for the same param >:( |
|
220 | - $this->message_type = $this->request->getRequestParam('mt', $message_type); |
|
221 | - $this->message_type = $this->request->getRequestParam('message_type', $this->message_type); |
|
222 | - $this->message_type = $this->request->getRequestParam('messageType', $this->message_type); |
|
223 | - $this->message_type = $this->request->getRequestParam('MTP_message_type', $this->message_type); |
|
224 | - $this->message_type = strtolower($this->message_type); |
|
225 | - |
|
226 | - if (empty($this->message_type)) { |
|
227 | - throw new RuntimeException( |
|
228 | - esc_html__( |
|
229 | - 'Sorry, but we can\'t create new templates because we\'re missing the message type', |
|
230 | - 'event_espresso' |
|
231 | - ) |
|
232 | - ); |
|
233 | - } |
|
234 | - } |
|
235 | - |
|
236 | - |
|
237 | - public function setName(?string $name = ''): void |
|
238 | - { |
|
239 | - $this->name = $this->request->getRequestParam('ee_msg_non_global_fields[MTP_name]', $name); |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - public function setUserID(?int $user_ID = 0): void |
|
244 | - { |
|
245 | - $this->user_ID = $this->request->getRequestParam('user_id', $user_ID, DataType::INTEGER); |
|
246 | - $this->user_ID = $this->request->getRequestParam('MTP_user_id', $this->user_ID, DataType::INTEGER); |
|
247 | - } |
|
248 | - |
|
249 | - |
|
250 | - private function setTemplateFields(): void |
|
251 | - { |
|
252 | - $this->template_fields = $this->request->getRequestParam( |
|
253 | - 'template_fields', |
|
254 | - null, |
|
255 | - DataType::EDITOR, |
|
256 | - true |
|
257 | - ); |
|
258 | - $this->template_fields = $this->request->getRequestParam( |
|
259 | - 'MTP_template_fields', |
|
260 | - $this->template_fields, |
|
261 | - DataType::EDITOR, |
|
262 | - true |
|
263 | - ); |
|
264 | - if (empty($this->template_fields)) { |
|
265 | - throw new RuntimeException( |
|
266 | - esc_html__( |
|
267 | - 'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.', |
|
268 | - 'event_espresso' |
|
269 | - ) |
|
270 | - ); |
|
271 | - } |
|
272 | - // messages content is expected to be escaped |
|
273 | - $this->template_fields = EEH_Array::addSlashesRecursively($this->template_fields); |
|
274 | - } |
|
150 | + public function setDescription(?string $description = ''): void |
|
151 | + { |
|
152 | + $this->description = $this->request->getRequestParam( |
|
153 | + 'ee_msg_non_global_fields[MTP_description]', |
|
154 | + $description |
|
155 | + ); |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + public function setGroupID(?int $group_ID = 0): void |
|
160 | + { |
|
161 | + $this->group_ID = $this->request->getRequestParam('group_ID', $group_ID, DataType::INTEGER); |
|
162 | + $this->group_ID = $this->request->getRequestParam('GRP_ID', $this->group_ID, DataType::INTEGER); |
|
163 | + // we need the GRP_ID for the template being used as the base for the new template |
|
164 | + if (empty($this->group_ID)) { |
|
165 | + throw new RuntimeException( |
|
166 | + esc_html__( |
|
167 | + 'In order to create a custom message template the GRP_ID of the template being used as a base is needed', |
|
168 | + 'event_espresso' |
|
169 | + ) |
|
170 | + ); |
|
171 | + } |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + public function setIsActive(bool $is_active = false): void |
|
176 | + { |
|
177 | + $this->is_active = $this->request->getRequestParam('MTP_is_active', $is_active, DataType::BOOLEAN); |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + public function setIsDeleted(bool $is_deleted = false): void |
|
182 | + { |
|
183 | + $this->is_deleted = $this->request->getRequestParam('MTP_deleted', $is_deleted, DataType::BOOLEAN); |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + public function setIsGlobal(bool $is_global = false): void |
|
188 | + { |
|
189 | + $this->is_global = $this->request->getRequestParam('MTP_is_global', $is_global, DataType::BOOLEAN); |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + public function setIsOverride(bool $is_override = false): void |
|
194 | + { |
|
195 | + $this->is_override = $this->request->getRequestParam('MTP_is_override', $is_override, DataType::BOOLEAN); |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + public function setMessenger(?string $messenger = ''): void |
|
200 | + { |
|
201 | + // have to check for multiple params because a previouv dev used different names for the same param >:( |
|
202 | + $this->messenger = $this->request->getRequestParam('msgr', $messenger); |
|
203 | + $this->messenger = $this->request->getRequestParam('messenger', $this->messenger); |
|
204 | + $this->messenger = $this->request->getRequestParam('MTP_messenger', $this->messenger); |
|
205 | + $this->messenger = strtolower($this->messenger); |
|
206 | + if (empty($this->messenger)) { |
|
207 | + throw new RuntimeException( |
|
208 | + esc_html__( |
|
209 | + 'Sorry, but we can\'t create new templates because we\'re missing the messenger', |
|
210 | + 'event_espresso' |
|
211 | + ) |
|
212 | + ); |
|
213 | + } |
|
214 | + } |
|
215 | + |
|
216 | + |
|
217 | + public function setMessageType(?string $message_type = ''): void |
|
218 | + { |
|
219 | + // have to check for multiple params because a previouv dev used different names for the same param >:( |
|
220 | + $this->message_type = $this->request->getRequestParam('mt', $message_type); |
|
221 | + $this->message_type = $this->request->getRequestParam('message_type', $this->message_type); |
|
222 | + $this->message_type = $this->request->getRequestParam('messageType', $this->message_type); |
|
223 | + $this->message_type = $this->request->getRequestParam('MTP_message_type', $this->message_type); |
|
224 | + $this->message_type = strtolower($this->message_type); |
|
225 | + |
|
226 | + if (empty($this->message_type)) { |
|
227 | + throw new RuntimeException( |
|
228 | + esc_html__( |
|
229 | + 'Sorry, but we can\'t create new templates because we\'re missing the message type', |
|
230 | + 'event_espresso' |
|
231 | + ) |
|
232 | + ); |
|
233 | + } |
|
234 | + } |
|
235 | + |
|
236 | + |
|
237 | + public function setName(?string $name = ''): void |
|
238 | + { |
|
239 | + $this->name = $this->request->getRequestParam('ee_msg_non_global_fields[MTP_name]', $name); |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + public function setUserID(?int $user_ID = 0): void |
|
244 | + { |
|
245 | + $this->user_ID = $this->request->getRequestParam('user_id', $user_ID, DataType::INTEGER); |
|
246 | + $this->user_ID = $this->request->getRequestParam('MTP_user_id', $this->user_ID, DataType::INTEGER); |
|
247 | + } |
|
248 | + |
|
249 | + |
|
250 | + private function setTemplateFields(): void |
|
251 | + { |
|
252 | + $this->template_fields = $this->request->getRequestParam( |
|
253 | + 'template_fields', |
|
254 | + null, |
|
255 | + DataType::EDITOR, |
|
256 | + true |
|
257 | + ); |
|
258 | + $this->template_fields = $this->request->getRequestParam( |
|
259 | + 'MTP_template_fields', |
|
260 | + $this->template_fields, |
|
261 | + DataType::EDITOR, |
|
262 | + true |
|
263 | + ); |
|
264 | + if (empty($this->template_fields)) { |
|
265 | + throw new RuntimeException( |
|
266 | + esc_html__( |
|
267 | + 'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.', |
|
268 | + 'event_espresso' |
|
269 | + ) |
|
270 | + ); |
|
271 | + } |
|
272 | + // messages content is expected to be escaped |
|
273 | + $this->template_fields = EEH_Array::addSlashesRecursively($this->template_fields); |
|
274 | + } |
|
275 | 275 | } |
@@ -14,7 +14,7 @@ |
||
14 | 14 | */ |
15 | 15 | class MessageTemplateRequestData |
16 | 16 | { |
17 | - protected ?RequestInterface $request = null; |
|
17 | + protected ?RequestInterface $request = null; |
|
18 | 18 | |
19 | 19 | protected string $context = ''; |
20 | 20 |