@@ -24,72 +24,72 @@ |
||
24 | 24 | */ |
25 | 25 | class EventFilterHeader extends AdminPageHeaderDecorator |
26 | 26 | { |
27 | - /** |
|
28 | - * @var EEM_Event $event_model |
|
29 | - */ |
|
30 | - private $event_model; |
|
27 | + /** |
|
28 | + * @var EEM_Event $event_model |
|
29 | + */ |
|
30 | + private $event_model; |
|
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * EventFilterHeader constructor. |
|
35 | - * |
|
36 | - * @param RequestInterface $request |
|
37 | - * @param EEM_Event $event_model |
|
38 | - */ |
|
39 | - public function __construct(RequestInterface $request, EEM_Event $event_model) |
|
40 | - { |
|
41 | - parent::__construct($request); |
|
42 | - $this->event_model = $event_model; |
|
43 | - } |
|
33 | + /** |
|
34 | + * EventFilterHeader constructor. |
|
35 | + * |
|
36 | + * @param RequestInterface $request |
|
37 | + * @param EEM_Event $event_model |
|
38 | + */ |
|
39 | + public function __construct(RequestInterface $request, EEM_Event $event_model) |
|
40 | + { |
|
41 | + parent::__construct($request); |
|
42 | + $this->event_model = $event_model; |
|
43 | + } |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * @param string $text |
|
48 | - * @return string |
|
49 | - * @throws EE_Error |
|
50 | - * @throws InvalidDataTypeException |
|
51 | - * @throws InvalidInterfaceException |
|
52 | - * @throws InvalidArgumentException |
|
53 | - * @throws ReflectionException |
|
54 | - * @since 4.10.2.p |
|
55 | - */ |
|
56 | - public function getHeaderText($text = '') |
|
57 | - { |
|
58 | - $EVT_ID = $this->request->getRequestParam('EVT_ID'); |
|
59 | - $EVT_ID = $this->request->getRequestParam('event_id', $EVT_ID, 'int'); |
|
60 | - $reg_status_code = $this->request->getRequestParam('_reg_status', ''); |
|
61 | - $reg_statuses = $reg_status_code |
|
62 | - ? EEM_Status::instance()->localized_status( |
|
63 | - [$reg_status_code => 'APPROVED'], |
|
64 | - false, |
|
65 | - 'lowercase' |
|
66 | - ) |
|
67 | - : []; |
|
68 | - $reg_status = $reg_statuses[ $reg_status_code ] ?? ''; |
|
69 | - if ($EVT_ID) { |
|
70 | - $event = $this->event_model->get_one_by_ID($EVT_ID); |
|
71 | - if ($event instanceof EE_Event) { |
|
72 | - $text .= sprintf( |
|
73 | - /* translators: %s: <h3> %s: <a href>Event Name</a> %s: </h3> */ |
|
74 | - // phpcs:ignore WordPress.WP.I18n.UnorderedPlaceholdersText |
|
75 | - esc_html__('%s Viewing%s registrations for the event: %s%s', 'event_espresso'), |
|
76 | - '<h3 class="ee-filter-header__text">', |
|
77 | - $reg_status ? " <span class='ee-status-outline ee-status-outline--micro ee-status-bg--$reg_status_code'>$reg_status</span>" : '', |
|
78 | - ' <a href="' |
|
79 | - . EE_Admin_Page::add_query_args_and_nonce( |
|
80 | - array( |
|
81 | - 'action' => 'edit', |
|
82 | - 'post' => $event->ID(), |
|
83 | - ), |
|
84 | - EVENTS_ADMIN_URL |
|
85 | - ) |
|
86 | - . '">' |
|
87 | - . $event->get('EVT_name') |
|
88 | - . '</a> ', |
|
89 | - '</h3>' |
|
90 | - ); |
|
91 | - } |
|
92 | - } |
|
93 | - return $text; |
|
94 | - } |
|
46 | + /** |
|
47 | + * @param string $text |
|
48 | + * @return string |
|
49 | + * @throws EE_Error |
|
50 | + * @throws InvalidDataTypeException |
|
51 | + * @throws InvalidInterfaceException |
|
52 | + * @throws InvalidArgumentException |
|
53 | + * @throws ReflectionException |
|
54 | + * @since 4.10.2.p |
|
55 | + */ |
|
56 | + public function getHeaderText($text = '') |
|
57 | + { |
|
58 | + $EVT_ID = $this->request->getRequestParam('EVT_ID'); |
|
59 | + $EVT_ID = $this->request->getRequestParam('event_id', $EVT_ID, 'int'); |
|
60 | + $reg_status_code = $this->request->getRequestParam('_reg_status', ''); |
|
61 | + $reg_statuses = $reg_status_code |
|
62 | + ? EEM_Status::instance()->localized_status( |
|
63 | + [$reg_status_code => 'APPROVED'], |
|
64 | + false, |
|
65 | + 'lowercase' |
|
66 | + ) |
|
67 | + : []; |
|
68 | + $reg_status = $reg_statuses[ $reg_status_code ] ?? ''; |
|
69 | + if ($EVT_ID) { |
|
70 | + $event = $this->event_model->get_one_by_ID($EVT_ID); |
|
71 | + if ($event instanceof EE_Event) { |
|
72 | + $text .= sprintf( |
|
73 | + /* translators: %s: <h3> %s: <a href>Event Name</a> %s: </h3> */ |
|
74 | + // phpcs:ignore WordPress.WP.I18n.UnorderedPlaceholdersText |
|
75 | + esc_html__('%s Viewing%s registrations for the event: %s%s', 'event_espresso'), |
|
76 | + '<h3 class="ee-filter-header__text">', |
|
77 | + $reg_status ? " <span class='ee-status-outline ee-status-outline--micro ee-status-bg--$reg_status_code'>$reg_status</span>" : '', |
|
78 | + ' <a href="' |
|
79 | + . EE_Admin_Page::add_query_args_and_nonce( |
|
80 | + array( |
|
81 | + 'action' => 'edit', |
|
82 | + 'post' => $event->ID(), |
|
83 | + ), |
|
84 | + EVENTS_ADMIN_URL |
|
85 | + ) |
|
86 | + . '">' |
|
87 | + . $event->get('EVT_name') |
|
88 | + . '</a> ', |
|
89 | + '</h3>' |
|
90 | + ); |
|
91 | + } |
|
92 | + } |
|
93 | + return $text; |
|
94 | + } |
|
95 | 95 | } |
@@ -65,7 +65,7 @@ |
||
65 | 65 | 'lowercase' |
66 | 66 | ) |
67 | 67 | : []; |
68 | - $reg_status = $reg_statuses[ $reg_status_code ] ?? ''; |
|
68 | + $reg_status = $reg_statuses[$reg_status_code] ?? ''; |
|
69 | 69 | if ($EVT_ID) { |
70 | 70 | $event = $this->event_model->get_one_by_ID($EVT_ID); |
71 | 71 | if ($event instanceof EE_Event) { |
@@ -14,118 +14,118 @@ |
||
14 | 14 | */ |
15 | 15 | class Basic implements EmailValidatorInterface |
16 | 16 | { |
17 | - /** |
|
18 | - * @param string $email_address |
|
19 | - * @return bool |
|
20 | - * @throws EmailValidationException |
|
21 | - */ |
|
22 | - public function validate(string $email_address): bool |
|
23 | - { |
|
24 | - if (! preg_match('/^.+@\S+$/', $email_address)) { |
|
25 | - // email not in correct {string}@{string} format |
|
26 | - throw new EmailValidationException( |
|
27 | - esc_html__('Email does not have the required @ sign.', 'event_espresso') |
|
28 | - ); |
|
29 | - } |
|
30 | - if (substr_count($email_address, '@') > 1) { |
|
31 | - // more than one email address? |
|
32 | - throw new EmailValidationException( |
|
33 | - esc_html__('Only one email address allowed (multiple @ sign detected).', 'event_espresso') |
|
34 | - ); |
|
35 | - } |
|
36 | - $atIndex = $this->getAtIndex($email_address); |
|
37 | - $local = $this->getLocalPartOfEmail($email_address, $atIndex); |
|
38 | - $localLen = strlen($local); |
|
39 | - if ($localLen < 1) { |
|
40 | - // no local part |
|
41 | - throw new EmailValidationException( |
|
42 | - esc_html__('Email local-part (before the @) is required.', 'event_espresso') |
|
43 | - ); |
|
44 | - } |
|
45 | - if ($localLen > 64) { |
|
46 | - // local part length exceeded |
|
47 | - throw new EmailValidationException( |
|
48 | - esc_html__('Email local-part (before the @) is too long.', 'event_espresso') |
|
49 | - ); |
|
50 | - } |
|
51 | - if ($local[0] === '.') { |
|
52 | - // local part starts with '.' |
|
53 | - throw new EmailValidationException( |
|
54 | - esc_html__('Email local-part (before the @) must not begin with a period.', 'event_espresso') |
|
55 | - ); |
|
56 | - } |
|
57 | - if ($local[ $localLen - 1 ] === '.') { |
|
58 | - // local part starts or ends with '.' |
|
59 | - throw new EmailValidationException( |
|
60 | - esc_html__('Email local-part (before the @) must not end with a period.', 'event_espresso') |
|
61 | - ); |
|
62 | - } |
|
63 | - if (preg_match('/\\.\\./', $local)) { |
|
64 | - // local part has two consecutive dots |
|
65 | - throw new EmailValidationException( |
|
66 | - esc_html__( |
|
67 | - 'Email local-part (before the @) must not have two consecutive periods.', |
|
68 | - 'event_espresso' |
|
69 | - ) |
|
70 | - ); |
|
71 | - } |
|
72 | - $domain = $this->getDomainPartOfEmail($email_address, $atIndex); |
|
73 | - $domainLen = strlen($domain); |
|
74 | - if ($domainLen < 1) { |
|
75 | - throw new EmailValidationException( |
|
76 | - esc_html__('Email domain (after the @) is required.', 'event_espresso') |
|
77 | - ); |
|
78 | - } |
|
79 | - if ($domainLen > 255) { |
|
80 | - // domain part length exceeded |
|
81 | - throw new EmailValidationException( |
|
82 | - esc_html__('Email domain (after the @) is too long.', 'event_espresso') |
|
83 | - ); |
|
84 | - } |
|
85 | - if (preg_match('/\\.\\./', $domain)) { |
|
86 | - // domain part has two consecutive dots |
|
87 | - throw new EmailValidationException( |
|
88 | - esc_html__('Email domain (after the @) must not have two consecutive periods.', 'event_espresso') |
|
89 | - ); |
|
90 | - } |
|
91 | - return true; |
|
92 | - } |
|
17 | + /** |
|
18 | + * @param string $email_address |
|
19 | + * @return bool |
|
20 | + * @throws EmailValidationException |
|
21 | + */ |
|
22 | + public function validate(string $email_address): bool |
|
23 | + { |
|
24 | + if (! preg_match('/^.+@\S+$/', $email_address)) { |
|
25 | + // email not in correct {string}@{string} format |
|
26 | + throw new EmailValidationException( |
|
27 | + esc_html__('Email does not have the required @ sign.', 'event_espresso') |
|
28 | + ); |
|
29 | + } |
|
30 | + if (substr_count($email_address, '@') > 1) { |
|
31 | + // more than one email address? |
|
32 | + throw new EmailValidationException( |
|
33 | + esc_html__('Only one email address allowed (multiple @ sign detected).', 'event_espresso') |
|
34 | + ); |
|
35 | + } |
|
36 | + $atIndex = $this->getAtIndex($email_address); |
|
37 | + $local = $this->getLocalPartOfEmail($email_address, $atIndex); |
|
38 | + $localLen = strlen($local); |
|
39 | + if ($localLen < 1) { |
|
40 | + // no local part |
|
41 | + throw new EmailValidationException( |
|
42 | + esc_html__('Email local-part (before the @) is required.', 'event_espresso') |
|
43 | + ); |
|
44 | + } |
|
45 | + if ($localLen > 64) { |
|
46 | + // local part length exceeded |
|
47 | + throw new EmailValidationException( |
|
48 | + esc_html__('Email local-part (before the @) is too long.', 'event_espresso') |
|
49 | + ); |
|
50 | + } |
|
51 | + if ($local[0] === '.') { |
|
52 | + // local part starts with '.' |
|
53 | + throw new EmailValidationException( |
|
54 | + esc_html__('Email local-part (before the @) must not begin with a period.', 'event_espresso') |
|
55 | + ); |
|
56 | + } |
|
57 | + if ($local[ $localLen - 1 ] === '.') { |
|
58 | + // local part starts or ends with '.' |
|
59 | + throw new EmailValidationException( |
|
60 | + esc_html__('Email local-part (before the @) must not end with a period.', 'event_espresso') |
|
61 | + ); |
|
62 | + } |
|
63 | + if (preg_match('/\\.\\./', $local)) { |
|
64 | + // local part has two consecutive dots |
|
65 | + throw new EmailValidationException( |
|
66 | + esc_html__( |
|
67 | + 'Email local-part (before the @) must not have two consecutive periods.', |
|
68 | + 'event_espresso' |
|
69 | + ) |
|
70 | + ); |
|
71 | + } |
|
72 | + $domain = $this->getDomainPartOfEmail($email_address, $atIndex); |
|
73 | + $domainLen = strlen($domain); |
|
74 | + if ($domainLen < 1) { |
|
75 | + throw new EmailValidationException( |
|
76 | + esc_html__('Email domain (after the @) is required.', 'event_espresso') |
|
77 | + ); |
|
78 | + } |
|
79 | + if ($domainLen > 255) { |
|
80 | + // domain part length exceeded |
|
81 | + throw new EmailValidationException( |
|
82 | + esc_html__('Email domain (after the @) is too long.', 'event_espresso') |
|
83 | + ); |
|
84 | + } |
|
85 | + if (preg_match('/\\.\\./', $domain)) { |
|
86 | + // domain part has two consecutive dots |
|
87 | + throw new EmailValidationException( |
|
88 | + esc_html__('Email domain (after the @) must not have two consecutive periods.', 'event_espresso') |
|
89 | + ); |
|
90 | + } |
|
91 | + return true; |
|
92 | + } |
|
93 | 93 | |
94 | 94 | |
95 | - /** |
|
96 | - * returns the location of the @ symbol |
|
97 | - * |
|
98 | - * @param string $email_address |
|
99 | - * @return bool|int |
|
100 | - */ |
|
101 | - protected function getAtIndex(string $email_address) |
|
102 | - { |
|
103 | - return strrpos($email_address, '@'); |
|
104 | - } |
|
95 | + /** |
|
96 | + * returns the location of the @ symbol |
|
97 | + * |
|
98 | + * @param string $email_address |
|
99 | + * @return bool|int |
|
100 | + */ |
|
101 | + protected function getAtIndex(string $email_address) |
|
102 | + { |
|
103 | + return strrpos($email_address, '@'); |
|
104 | + } |
|
105 | 105 | |
106 | 106 | |
107 | - /** |
|
108 | - * Gets the local part of the email |
|
109 | - * |
|
110 | - * @param string $email_address |
|
111 | - * @param bool|int $atIndex |
|
112 | - * @return bool|string |
|
113 | - */ |
|
114 | - protected function getLocalPartOfEmail(string $email_address, $atIndex) |
|
115 | - { |
|
116 | - return substr($email_address, 0, $atIndex); |
|
117 | - } |
|
107 | + /** |
|
108 | + * Gets the local part of the email |
|
109 | + * |
|
110 | + * @param string $email_address |
|
111 | + * @param bool|int $atIndex |
|
112 | + * @return bool|string |
|
113 | + */ |
|
114 | + protected function getLocalPartOfEmail(string $email_address, $atIndex) |
|
115 | + { |
|
116 | + return substr($email_address, 0, $atIndex); |
|
117 | + } |
|
118 | 118 | |
119 | 119 | |
120 | - /** |
|
121 | - * Gets the domain part of the email |
|
122 | - * |
|
123 | - * @param string $email_address |
|
124 | - * @param bool|int $atIndex |
|
125 | - * @return bool|string |
|
126 | - */ |
|
127 | - protected function getDomainPartOfEmail(string $email_address, $atIndex) |
|
128 | - { |
|
129 | - return substr($email_address, $atIndex + 1); |
|
130 | - } |
|
120 | + /** |
|
121 | + * Gets the domain part of the email |
|
122 | + * |
|
123 | + * @param string $email_address |
|
124 | + * @param bool|int $atIndex |
|
125 | + * @return bool|string |
|
126 | + */ |
|
127 | + protected function getDomainPartOfEmail(string $email_address, $atIndex) |
|
128 | + { |
|
129 | + return substr($email_address, $atIndex + 1); |
|
130 | + } |
|
131 | 131 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | */ |
22 | 22 | public function validate(string $email_address): bool |
23 | 23 | { |
24 | - if (! preg_match('/^.+@\S+$/', $email_address)) { |
|
24 | + if ( ! preg_match('/^.+@\S+$/', $email_address)) { |
|
25 | 25 | // email not in correct {string}@{string} format |
26 | 26 | throw new EmailValidationException( |
27 | 27 | esc_html__('Email does not have the required @ sign.', 'event_espresso') |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | esc_html__('Email local-part (before the @) must not begin with a period.', 'event_espresso') |
55 | 55 | ); |
56 | 56 | } |
57 | - if ($local[ $localLen - 1 ] === '.') { |
|
57 | + if ($local[$localLen - 1] === '.') { |
|
58 | 58 | // local part starts or ends with '.' |
59 | 59 | throw new EmailValidationException( |
60 | 60 | esc_html__('Email local-part (before the @) must not end with a period.', 'event_espresso') |
@@ -9,92 +9,92 @@ |
||
9 | 9 | */ |
10 | 10 | class MaintenanceStatus |
11 | 11 | { |
12 | - /** |
|
13 | - * Entire site is in maintenance mode |
|
14 | - */ |
|
15 | - public const FULL_SITE = 'FULL_SITE'; |
|
16 | - |
|
17 | - /** |
|
18 | - * Frontend is in maintenance mode, but admin is available |
|
19 | - */ |
|
20 | - public const PUBLIC_ONLY = 'PUBLIC_ONLY'; |
|
21 | - |
|
22 | - /** |
|
23 | - * Maintenance mode is disabled |
|
24 | - */ |
|
25 | - public const DISABLED = 'DISABLED'; |
|
26 | - |
|
27 | - |
|
28 | - private static string $status = MaintenanceStatus::DISABLED; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * returns true if maintenance mode is enabled for the entire site (admin & frontend) |
|
33 | - * |
|
34 | - * @return bool |
|
35 | - */ |
|
36 | - public static function isFullSite(): bool |
|
37 | - { |
|
38 | - return MaintenanceStatus::$status === MaintenanceStatus::FULL_SITE; |
|
39 | - } |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * returns true if maintenance mode is NOT enabled for the entire site (admin & frontend) |
|
44 | - * PLZ NOTE: this does not mean that maintenance mode is NOT enabled for the frontend only |
|
45 | - * |
|
46 | - * @return bool |
|
47 | - */ |
|
48 | - public static function isNotFullSite(): bool |
|
49 | - { |
|
50 | - return MaintenanceStatus::$status !== MaintenanceStatus::FULL_SITE; |
|
51 | - } |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * returns true if maintenance mode is enabled for the site's frontend only |
|
56 | - * |
|
57 | - * @return bool |
|
58 | - */ |
|
59 | - public static function isPublicOnly(): bool |
|
60 | - { |
|
61 | - return MaintenanceStatus::$status === MaintenanceStatus::PUBLIC_ONLY; |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * returns true if maintenance mode is NOT enabled in any way |
|
67 | - * |
|
68 | - * @return bool |
|
69 | - */ |
|
70 | - public static function isDisabled(): bool |
|
71 | - { |
|
72 | - return MaintenanceStatus::$status === MaintenanceStatus::DISABLED; |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * returns true if maintenance mode is enabled for the site in some way (admin and/or frontend) |
|
78 | - * |
|
79 | - * @return bool |
|
80 | - */ |
|
81 | - public static function isNotDisabled(): bool |
|
82 | - { |
|
83 | - return MaintenanceStatus::$status !== MaintenanceStatus::DISABLED; |
|
84 | - } |
|
85 | - |
|
86 | - public static function setFullSiteMaintenanceMode(): void |
|
87 | - { |
|
88 | - MaintenanceStatus::$status = MaintenanceStatus::FULL_SITE; |
|
89 | - } |
|
90 | - |
|
91 | - public static function setPublicOnlyMaintenanceMode(): void |
|
92 | - { |
|
93 | - MaintenanceStatus::$status = MaintenanceStatus::PUBLIC_ONLY; |
|
94 | - } |
|
95 | - |
|
96 | - public static function disableMaintenanceMode(): void |
|
97 | - { |
|
98 | - MaintenanceStatus::$status = MaintenanceStatus::DISABLED; |
|
99 | - } |
|
12 | + /** |
|
13 | + * Entire site is in maintenance mode |
|
14 | + */ |
|
15 | + public const FULL_SITE = 'FULL_SITE'; |
|
16 | + |
|
17 | + /** |
|
18 | + * Frontend is in maintenance mode, but admin is available |
|
19 | + */ |
|
20 | + public const PUBLIC_ONLY = 'PUBLIC_ONLY'; |
|
21 | + |
|
22 | + /** |
|
23 | + * Maintenance mode is disabled |
|
24 | + */ |
|
25 | + public const DISABLED = 'DISABLED'; |
|
26 | + |
|
27 | + |
|
28 | + private static string $status = MaintenanceStatus::DISABLED; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * returns true if maintenance mode is enabled for the entire site (admin & frontend) |
|
33 | + * |
|
34 | + * @return bool |
|
35 | + */ |
|
36 | + public static function isFullSite(): bool |
|
37 | + { |
|
38 | + return MaintenanceStatus::$status === MaintenanceStatus::FULL_SITE; |
|
39 | + } |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * returns true if maintenance mode is NOT enabled for the entire site (admin & frontend) |
|
44 | + * PLZ NOTE: this does not mean that maintenance mode is NOT enabled for the frontend only |
|
45 | + * |
|
46 | + * @return bool |
|
47 | + */ |
|
48 | + public static function isNotFullSite(): bool |
|
49 | + { |
|
50 | + return MaintenanceStatus::$status !== MaintenanceStatus::FULL_SITE; |
|
51 | + } |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * returns true if maintenance mode is enabled for the site's frontend only |
|
56 | + * |
|
57 | + * @return bool |
|
58 | + */ |
|
59 | + public static function isPublicOnly(): bool |
|
60 | + { |
|
61 | + return MaintenanceStatus::$status === MaintenanceStatus::PUBLIC_ONLY; |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * returns true if maintenance mode is NOT enabled in any way |
|
67 | + * |
|
68 | + * @return bool |
|
69 | + */ |
|
70 | + public static function isDisabled(): bool |
|
71 | + { |
|
72 | + return MaintenanceStatus::$status === MaintenanceStatus::DISABLED; |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * returns true if maintenance mode is enabled for the site in some way (admin and/or frontend) |
|
78 | + * |
|
79 | + * @return bool |
|
80 | + */ |
|
81 | + public static function isNotDisabled(): bool |
|
82 | + { |
|
83 | + return MaintenanceStatus::$status !== MaintenanceStatus::DISABLED; |
|
84 | + } |
|
85 | + |
|
86 | + public static function setFullSiteMaintenanceMode(): void |
|
87 | + { |
|
88 | + MaintenanceStatus::$status = MaintenanceStatus::FULL_SITE; |
|
89 | + } |
|
90 | + |
|
91 | + public static function setPublicOnlyMaintenanceMode(): void |
|
92 | + { |
|
93 | + MaintenanceStatus::$status = MaintenanceStatus::PUBLIC_ONLY; |
|
94 | + } |
|
95 | + |
|
96 | + public static function disableMaintenanceMode(): void |
|
97 | + { |
|
98 | + MaintenanceStatus::$status = MaintenanceStatus::DISABLED; |
|
99 | + } |
|
100 | 100 | } |
@@ -20,2601 +20,2601 @@ discard block |
||
20 | 20 | */ |
21 | 21 | final class EE_Config implements ResettableInterface |
22 | 22 | { |
23 | - const OPTION_NAME = 'ee_config'; |
|
24 | - |
|
25 | - const LOG_NAME = 'ee_config_log'; |
|
26 | - |
|
27 | - const LOG_LENGTH = 100; |
|
28 | - |
|
29 | - const ADDON_OPTION_NAMES = 'ee_config_option_names'; |
|
30 | - |
|
31 | - /** |
|
32 | - * instance of the EE_Config object |
|
33 | - * |
|
34 | - * @var EE_Config $_instance |
|
35 | - * @access private |
|
36 | - */ |
|
37 | - private static $_instance; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var boolean $_logging_enabled |
|
41 | - */ |
|
42 | - private static $_logging_enabled = false; |
|
43 | - |
|
44 | - /** |
|
45 | - * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
46 | - */ |
|
47 | - private $legacy_shortcodes_manager; |
|
48 | - |
|
49 | - /** |
|
50 | - * An StdClass whose property names are addon slugs, |
|
51 | - * and values are their config classes |
|
52 | - * |
|
53 | - * @var StdClass |
|
54 | - */ |
|
55 | - public $addons; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var EE_Admin_Config |
|
59 | - */ |
|
60 | - public $admin; |
|
61 | - |
|
62 | - /** |
|
63 | - * @var EE_Core_Config |
|
64 | - */ |
|
65 | - public $core; |
|
66 | - |
|
67 | - /** |
|
68 | - * @var EE_Currency_Config |
|
69 | - */ |
|
70 | - public $currency; |
|
71 | - |
|
72 | - /** |
|
73 | - * @var EE_Organization_Config |
|
74 | - */ |
|
75 | - public $organization; |
|
76 | - |
|
77 | - /** |
|
78 | - * @var EE_Registration_Config |
|
79 | - */ |
|
80 | - public $registration; |
|
81 | - |
|
82 | - /** |
|
83 | - * @var EE_Template_Config |
|
84 | - */ |
|
85 | - public $template_settings; |
|
86 | - |
|
87 | - /** |
|
88 | - * Holds EE environment values. |
|
89 | - * |
|
90 | - * @var EE_Environment_Config |
|
91 | - */ |
|
92 | - public $environment; |
|
93 | - |
|
94 | - /** |
|
95 | - * settings pertaining to Google maps |
|
96 | - * |
|
97 | - * @var EE_Map_Config |
|
98 | - */ |
|
99 | - public $map_settings; |
|
100 | - |
|
101 | - /** |
|
102 | - * settings pertaining to Taxes |
|
103 | - * |
|
104 | - * @var EE_Tax_Config |
|
105 | - */ |
|
106 | - public $tax_settings; |
|
107 | - |
|
108 | - /** |
|
109 | - * Settings pertaining to global messages settings. |
|
110 | - * |
|
111 | - * @var EE_Messages_Config |
|
112 | - */ |
|
113 | - public $messages; |
|
114 | - |
|
115 | - /** |
|
116 | - * @deprecated |
|
117 | - * @var EE_Gateway_Config |
|
118 | - */ |
|
119 | - public $gateway; |
|
120 | - |
|
121 | - /** |
|
122 | - * @var array |
|
123 | - */ |
|
124 | - private $_addon_option_names = array(); |
|
125 | - |
|
126 | - /** |
|
127 | - * @var array |
|
128 | - */ |
|
129 | - private static $_module_route_map = array(); |
|
130 | - |
|
131 | - /** |
|
132 | - * @var array |
|
133 | - */ |
|
134 | - private static $_module_forward_map = array(); |
|
135 | - |
|
136 | - /** |
|
137 | - * @var array |
|
138 | - */ |
|
139 | - private static $_module_view_map = array(); |
|
140 | - |
|
141 | - /** |
|
142 | - * @var bool |
|
143 | - */ |
|
144 | - private static $initialized = false; |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * @singleton method used to instantiate class object |
|
149 | - * @access public |
|
150 | - * @return EE_Config instance |
|
151 | - */ |
|
152 | - public static function instance() |
|
153 | - { |
|
154 | - // check if class object is instantiated, and instantiated properly |
|
155 | - if (! self::$_instance instanceof EE_Config) { |
|
156 | - self::$_instance = new self(); |
|
157 | - } |
|
158 | - return self::$_instance; |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * Resets the config |
|
164 | - * |
|
165 | - * @param bool $hard_reset if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE |
|
166 | - * (default) leaves the database alone, and merely resets the EE_Config object to |
|
167 | - * reflect its state in the database |
|
168 | - * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave |
|
169 | - * $_instance as NULL. Useful in case you want to forget about the old instance on |
|
170 | - * EE_Config, but might not be ready to instantiate EE_Config currently (eg if the |
|
171 | - * site was put into maintenance mode) |
|
172 | - * @return EE_Config |
|
173 | - */ |
|
174 | - public static function reset($hard_reset = false, $reinstantiate = true) |
|
175 | - { |
|
176 | - if (self::$_instance instanceof EE_Config) { |
|
177 | - if ($hard_reset) { |
|
178 | - self::$_instance->legacy_shortcodes_manager = null; |
|
179 | - self::$_instance->_addon_option_names = array(); |
|
180 | - self::$_instance->_initialize_config(); |
|
181 | - self::$_instance->update_espresso_config(); |
|
182 | - } |
|
183 | - self::$_instance->update_addon_option_names(); |
|
184 | - } |
|
185 | - self::$_instance = null; |
|
186 | - self::$initialized = false; |
|
187 | - // we don't need to reset the static properties imo because those should |
|
188 | - // only change when a module is added or removed. Currently we don't |
|
189 | - // support removing a module during a request when it previously existed |
|
190 | - if ($reinstantiate) { |
|
191 | - return self::instance(); |
|
192 | - } else { |
|
193 | - return null; |
|
194 | - } |
|
195 | - } |
|
196 | - |
|
197 | - |
|
198 | - private function __construct() |
|
199 | - { |
|
200 | - if (self::$initialized) { |
|
201 | - return; |
|
202 | - } |
|
203 | - self::$initialized = true; |
|
204 | - do_action('AHEE__EE_Config__construct__begin', $this); |
|
205 | - EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false); |
|
206 | - // setup empty config classes |
|
207 | - $this->_initialize_config(); |
|
208 | - // load existing EE site settings |
|
209 | - $this->_load_core_config(); |
|
210 | - // confirm everything loaded correctly and set filtered defaults if not |
|
211 | - $this->_verify_config(); |
|
212 | - // register shortcodes and modules |
|
213 | - add_action( |
|
214 | - 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
215 | - [$this, 'register_shortcodes_and_modules'], |
|
216 | - 999 |
|
217 | - ); |
|
218 | - // initialize shortcodes and modules |
|
219 | - add_action('AHEE__EE_System__core_loaded_and_ready', [$this, 'initialize_shortcodes_and_modules']); |
|
220 | - // register widgets |
|
221 | - add_action('widgets_init', [$this, 'widgets_init'], 10); |
|
222 | - // shutdown |
|
223 | - add_action('shutdown', [$this, 'shutdown'], 10); |
|
224 | - // construct__end hook |
|
225 | - do_action('AHEE__EE_Config__construct__end', $this); |
|
226 | - // hardcoded hack |
|
227 | - $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
228 | - } |
|
229 | - |
|
230 | - |
|
231 | - /** |
|
232 | - * @return boolean |
|
233 | - */ |
|
234 | - public static function logging_enabled() |
|
235 | - { |
|
236 | - return self::$_logging_enabled; |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * use to get the current theme if needed from static context |
|
242 | - * |
|
243 | - * @return string current theme set. |
|
244 | - */ |
|
245 | - public static function get_current_theme() |
|
246 | - { |
|
247 | - return self::$_instance->template_settings->current_espresso_theme ?? 'Espresso_Arabica_2014'; |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - /** |
|
252 | - * _initialize_config |
|
253 | - * |
|
254 | - * @access private |
|
255 | - * @return void |
|
256 | - */ |
|
257 | - private function _initialize_config() |
|
258 | - { |
|
259 | - EE_Config::trim_log(); |
|
260 | - // set defaults |
|
261 | - $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array()); |
|
262 | - $this->addons = new stdClass(); |
|
263 | - // set _module_route_map |
|
264 | - EE_Config::$_module_route_map = array(); |
|
265 | - // set _module_forward_map |
|
266 | - EE_Config::$_module_forward_map = array(); |
|
267 | - // set _module_view_map |
|
268 | - EE_Config::$_module_view_map = array(); |
|
269 | - } |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * load core plugin configuration |
|
274 | - * |
|
275 | - * @access private |
|
276 | - * @return void |
|
277 | - */ |
|
278 | - private function _load_core_config() |
|
279 | - { |
|
280 | - // load_core_config__start hook |
|
281 | - do_action('AHEE__EE_Config___load_core_config__start', $this); |
|
282 | - $espresso_config = (array) $this->get_espresso_config(); |
|
283 | - // need to move the "addons" element to the end of the config array |
|
284 | - // in case an addon config references one of the other config classes |
|
285 | - $addons = $espresso_config['addons'] ?? new StdClass(); |
|
286 | - unset($espresso_config['addons']); |
|
287 | - $espresso_config['addons'] = $addons; |
|
288 | - foreach ($espresso_config as $config => $settings) { |
|
289 | - // load_core_config__start hook |
|
290 | - $settings = apply_filters( |
|
291 | - 'FHEE__EE_Config___load_core_config__config_settings', |
|
292 | - $settings, |
|
293 | - $config, |
|
294 | - $this |
|
295 | - ); |
|
296 | - if (is_object($settings) && property_exists($this, $config)) { |
|
297 | - $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
298 | - // call configs populate method to ensure any defaults are set for empty values. |
|
299 | - if (method_exists($settings, 'populate')) { |
|
300 | - $this->{$config}->populate(); |
|
301 | - } |
|
302 | - if (method_exists($settings, 'do_hooks')) { |
|
303 | - $this->{$config}->do_hooks(); |
|
304 | - } |
|
305 | - } |
|
306 | - } |
|
307 | - if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) { |
|
308 | - $this->update_espresso_config(); |
|
309 | - } |
|
310 | - // load_core_config__end hook |
|
311 | - do_action('AHEE__EE_Config___load_core_config__end', $this); |
|
312 | - } |
|
313 | - |
|
314 | - |
|
315 | - /** |
|
316 | - * _verify_config |
|
317 | - * |
|
318 | - * @access protected |
|
319 | - * @return void |
|
320 | - */ |
|
321 | - protected function _verify_config() |
|
322 | - { |
|
323 | - $this->core = $this->core instanceof EE_Core_Config |
|
324 | - ? $this->core |
|
325 | - : new EE_Core_Config(); |
|
326 | - $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core); |
|
327 | - $this->organization = $this->organization instanceof EE_Organization_Config |
|
328 | - ? $this->organization |
|
329 | - : new EE_Organization_Config(); |
|
330 | - $this->organization = apply_filters( |
|
331 | - 'FHEE__EE_Config___initialize_config__organization', |
|
332 | - $this->organization |
|
333 | - ); |
|
334 | - $this->currency = $this->currency instanceof EE_Currency_Config |
|
335 | - ? $this->currency |
|
336 | - : new EE_Currency_Config(); |
|
337 | - $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency); |
|
338 | - $this->registration = $this->registration instanceof EE_Registration_Config |
|
339 | - ? $this->registration |
|
340 | - : new EE_Registration_Config(); |
|
341 | - $this->registration = apply_filters( |
|
342 | - 'FHEE__EE_Config___initialize_config__registration', |
|
343 | - $this->registration |
|
344 | - ); |
|
345 | - $this->admin = $this->admin instanceof EE_Admin_Config |
|
346 | - ? $this->admin |
|
347 | - : new EE_Admin_Config(); |
|
348 | - $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin); |
|
349 | - $this->template_settings = $this->template_settings instanceof EE_Template_Config |
|
350 | - ? $this->template_settings |
|
351 | - : new EE_Template_Config(); |
|
352 | - $this->template_settings = apply_filters( |
|
353 | - 'FHEE__EE_Config___initialize_config__template_settings', |
|
354 | - $this->template_settings |
|
355 | - ); |
|
356 | - $this->map_settings = $this->map_settings instanceof EE_Map_Config |
|
357 | - ? $this->map_settings |
|
358 | - : new EE_Map_Config(); |
|
359 | - $this->map_settings = apply_filters( |
|
360 | - 'FHEE__EE_Config___initialize_config__map_settings', |
|
361 | - $this->map_settings |
|
362 | - ); |
|
363 | - $this->environment = $this->environment instanceof EE_Environment_Config |
|
364 | - ? $this->environment |
|
365 | - : new EE_Environment_Config(); |
|
366 | - $this->environment = apply_filters( |
|
367 | - 'FHEE__EE_Config___initialize_config__environment', |
|
368 | - $this->environment |
|
369 | - ); |
|
370 | - $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config |
|
371 | - ? $this->tax_settings |
|
372 | - : new EE_Tax_Config(); |
|
373 | - $this->tax_settings = apply_filters( |
|
374 | - 'FHEE__EE_Config___initialize_config__tax_settings', |
|
375 | - $this->tax_settings |
|
376 | - ); |
|
377 | - $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages); |
|
378 | - $this->messages = $this->messages instanceof EE_Messages_Config |
|
379 | - ? $this->messages |
|
380 | - : new EE_Messages_Config(); |
|
381 | - $this->gateway = $this->gateway instanceof EE_Gateway_Config |
|
382 | - ? $this->gateway |
|
383 | - : new EE_Gateway_Config(); |
|
384 | - $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway); |
|
385 | - $this->legacy_shortcodes_manager = null; |
|
386 | - } |
|
387 | - |
|
388 | - |
|
389 | - /** |
|
390 | - * get_espresso_config |
|
391 | - * |
|
392 | - * @access public |
|
393 | - * @return array of espresso config stuff |
|
394 | - */ |
|
395 | - public function get_espresso_config() |
|
396 | - { |
|
397 | - // grab espresso configuration |
|
398 | - return apply_filters( |
|
399 | - 'FHEE__EE_Config__get_espresso_config__CFG', |
|
400 | - get_option(EE_Config::OPTION_NAME, array()) |
|
401 | - ); |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * double_check_config_comparison |
|
407 | - * |
|
408 | - * @access public |
|
409 | - * @param string $option |
|
410 | - * @param $old_value |
|
411 | - * @param $value |
|
412 | - */ |
|
413 | - public function double_check_config_comparison($option, $old_value, $value) |
|
414 | - { |
|
415 | - // make sure we're checking the ee config |
|
416 | - if ($option === EE_Config::OPTION_NAME) { |
|
417 | - // run a loose comparison of the old value against the new value for type and properties, |
|
418 | - // but NOT exact instance like WP update_option does (ie: NOT type safe comparison) |
|
419 | - if ($value != $old_value) { |
|
420 | - // if they are NOT the same, then remove the hook, |
|
421 | - // which means the subsequent update results will be based solely on the update query results |
|
422 | - // the reason we do this is because, as stated above, |
|
423 | - // WP update_option performs an exact instance comparison (===) on any update values passed to it |
|
424 | - // this happens PRIOR to serialization and any subsequent update. |
|
425 | - // If values are found to match their previous old value, |
|
426 | - // then WP bails before performing any update. |
|
427 | - // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version |
|
428 | - // it just pulled from the db, with the one being passed to it (which will not match). |
|
429 | - // HOWEVER, once the object is serialized and passed off to MySQL to update, |
|
430 | - // MySQL MAY ALSO NOT perform the update because |
|
431 | - // the string it sees in the db looks the same as the new one it has been passed!!! |
|
432 | - // This results in the query returning an "affected rows" value of ZERO, |
|
433 | - // which gets returned immediately by WP update_option and looks like an error. |
|
434 | - remove_action('update_option', array($this, 'check_config_updated')); |
|
435 | - } |
|
436 | - } |
|
437 | - } |
|
438 | - |
|
439 | - |
|
440 | - /** |
|
441 | - * update_espresso_config |
|
442 | - * |
|
443 | - * @access public |
|
444 | - */ |
|
445 | - protected function _reset_espresso_addon_config() |
|
446 | - { |
|
447 | - $this->_addon_option_names = array(); |
|
448 | - foreach ($this->addons as $addon_name => $addon_config_obj) { |
|
449 | - $addon_config_obj = maybe_unserialize($addon_config_obj); |
|
450 | - if ($addon_config_obj instanceof EE_Config_Base) { |
|
451 | - $this->update_config('addons', $addon_name, $addon_config_obj, false); |
|
452 | - } |
|
453 | - $this->addons->{$addon_name} = null; |
|
454 | - } |
|
455 | - } |
|
456 | - |
|
457 | - |
|
458 | - /** |
|
459 | - * update_espresso_config |
|
460 | - * |
|
461 | - * @access public |
|
462 | - * @param bool $add_success |
|
463 | - * @param bool $add_error |
|
464 | - * @return bool |
|
465 | - */ |
|
466 | - public function update_espresso_config($add_success = false, $add_error = true) |
|
467 | - { |
|
468 | - // don't allow config updates during WP heartbeats |
|
469 | - /** @var RequestInterface $request */ |
|
470 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
471 | - if ($request->isWordPressHeartbeat()) { |
|
472 | - return false; |
|
473 | - } |
|
474 | - // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197 |
|
475 | - // $clone = clone( self::$_instance ); |
|
476 | - // self::$_instance = NULL; |
|
477 | - do_action('AHEE__EE_Config__update_espresso_config__begin', $this); |
|
478 | - $this->_reset_espresso_addon_config(); |
|
479 | - // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional |
|
480 | - // but BEFORE the actual update occurs |
|
481 | - add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3); |
|
482 | - // don't want to persist legacy_shortcodes_manager, but don't want to lose it either |
|
483 | - $legacy_shortcodes_manager = $this->legacy_shortcodes_manager; |
|
484 | - $this->legacy_shortcodes_manager = null; |
|
485 | - // now update "ee_config" |
|
486 | - $saved = update_option(EE_Config::OPTION_NAME, $this); |
|
487 | - $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
488 | - EE_Config::log(EE_Config::OPTION_NAME); |
|
489 | - // if not saved... check if the hook we just added still exists; |
|
490 | - // if it does, it means one of two things: |
|
491 | - // that update_option bailed at the($value === $old_value) conditional, |
|
492 | - // or... |
|
493 | - // the db update query returned 0 rows affected |
|
494 | - // (probably because the data value was the same from its perspective) |
|
495 | - // so the existence of the hook means that a negative result from update_option is NOT an error, |
|
496 | - // but just means no update occurred, so don't display an error to the user. |
|
497 | - // BUT... if update_option returns FALSE, AND the hook is missing, |
|
498 | - // then it means that something truly went wrong |
|
499 | - $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved; |
|
500 | - // remove our action since we don't want it in the system anymore |
|
501 | - remove_action('update_option', array($this, 'double_check_config_comparison'), 1); |
|
502 | - do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved); |
|
503 | - // self::$_instance = $clone; |
|
504 | - // unset( $clone ); |
|
505 | - // if config remains the same or was updated successfully |
|
506 | - if ($saved) { |
|
507 | - if ($add_success) { |
|
508 | - EE_Error::add_success( |
|
509 | - esc_html__('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'), |
|
510 | - __FILE__, |
|
511 | - __FUNCTION__, |
|
512 | - __LINE__ |
|
513 | - ); |
|
514 | - } |
|
515 | - return true; |
|
516 | - } else { |
|
517 | - if ($add_error) { |
|
518 | - EE_Error::add_error( |
|
519 | - esc_html__('The Event Espresso Configuration Settings were not updated.', 'event_espresso'), |
|
520 | - __FILE__, |
|
521 | - __FUNCTION__, |
|
522 | - __LINE__ |
|
523 | - ); |
|
524 | - } |
|
525 | - return false; |
|
526 | - } |
|
527 | - } |
|
528 | - |
|
529 | - |
|
530 | - /** |
|
531 | - * _verify_config_params |
|
532 | - * |
|
533 | - * @access private |
|
534 | - * @param string $section |
|
535 | - * @param string $name |
|
536 | - * @param string $config_class |
|
537 | - * @param EE_Config_Base $config_obj |
|
538 | - * @param array $tests_to_run |
|
539 | - * @param bool $display_errors |
|
540 | - * @return bool TRUE on success, FALSE on fail |
|
541 | - */ |
|
542 | - private function _verify_config_params( |
|
543 | - $section = '', |
|
544 | - $name = '', |
|
545 | - $config_class = '', |
|
546 | - $config_obj = null, |
|
547 | - $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8), |
|
548 | - $display_errors = true |
|
549 | - ) { |
|
550 | - try { |
|
551 | - foreach ($tests_to_run as $test) { |
|
552 | - switch ($test) { |
|
553 | - // TEST #1 : check that section was set |
|
554 | - case 1: |
|
555 | - if (empty($section)) { |
|
556 | - if ($display_errors) { |
|
557 | - throw new EE_Error( |
|
558 | - sprintf( |
|
559 | - esc_html__( |
|
560 | - 'No configuration section has been provided while attempting to save "%s".', |
|
561 | - 'event_espresso' |
|
562 | - ), |
|
563 | - $config_class |
|
564 | - ) |
|
565 | - ); |
|
566 | - } |
|
567 | - return false; |
|
568 | - } |
|
569 | - break; |
|
570 | - // TEST #2 : check that settings section exists |
|
571 | - case 2: |
|
572 | - if (! isset($this->{$section})) { |
|
573 | - if ($display_errors) { |
|
574 | - throw new EE_Error( |
|
575 | - sprintf( |
|
576 | - esc_html__('The "%s" configuration section does not exist.', 'event_espresso'), |
|
577 | - $section |
|
578 | - ) |
|
579 | - ); |
|
580 | - } |
|
581 | - return false; |
|
582 | - } |
|
583 | - break; |
|
584 | - // TEST #3 : check that section is the proper format |
|
585 | - case 3: |
|
586 | - if ( |
|
587 | - ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
588 | - ) { |
|
589 | - if ($display_errors) { |
|
590 | - throw new EE_Error( |
|
591 | - sprintf( |
|
592 | - esc_html__( |
|
593 | - 'The "%s" configuration settings have not been formatted correctly.', |
|
594 | - 'event_espresso' |
|
595 | - ), |
|
596 | - $section |
|
597 | - ) |
|
598 | - ); |
|
599 | - } |
|
600 | - return false; |
|
601 | - } |
|
602 | - break; |
|
603 | - // TEST #4 : check that config section name has been set |
|
604 | - case 4: |
|
605 | - if (empty($name)) { |
|
606 | - if ($display_errors) { |
|
607 | - throw new EE_Error( |
|
608 | - esc_html__( |
|
609 | - 'No name has been provided for the specific configuration section.', |
|
610 | - 'event_espresso' |
|
611 | - ) |
|
612 | - ); |
|
613 | - } |
|
614 | - return false; |
|
615 | - } |
|
616 | - break; |
|
617 | - // TEST #5 : check that a config class name has been set |
|
618 | - case 5: |
|
619 | - if (empty($config_class)) { |
|
620 | - if ($display_errors) { |
|
621 | - throw new EE_Error( |
|
622 | - esc_html__( |
|
623 | - 'No class name has been provided for the specific configuration section.', |
|
624 | - 'event_espresso' |
|
625 | - ) |
|
626 | - ); |
|
627 | - } |
|
628 | - return false; |
|
629 | - } |
|
630 | - break; |
|
631 | - // TEST #6 : verify config class is accessible |
|
632 | - case 6: |
|
633 | - if (! class_exists($config_class)) { |
|
634 | - if ($display_errors) { |
|
635 | - throw new EE_Error( |
|
636 | - sprintf( |
|
637 | - esc_html__( |
|
638 | - 'The "%s" class does not exist. Please ensure that an autoloader has been set for it.', |
|
639 | - 'event_espresso' |
|
640 | - ), |
|
641 | - $config_class |
|
642 | - ) |
|
643 | - ); |
|
644 | - } |
|
645 | - return false; |
|
646 | - } |
|
647 | - break; |
|
648 | - // TEST #7 : check that config has even been set |
|
649 | - case 7: |
|
650 | - if (! isset($this->{$section}->{$name})) { |
|
651 | - if ($display_errors) { |
|
652 | - throw new EE_Error( |
|
653 | - sprintf( |
|
654 | - esc_html__('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
655 | - $section, |
|
656 | - $name |
|
657 | - ) |
|
658 | - ); |
|
659 | - } |
|
660 | - return false; |
|
661 | - } else { |
|
662 | - // and make sure it's not serialized |
|
663 | - $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name}); |
|
664 | - } |
|
665 | - break; |
|
666 | - // TEST #8 : check that config is the requested type |
|
667 | - case 8: |
|
668 | - if (! $this->{$section}->{$name} instanceof $config_class) { |
|
669 | - if ($display_errors) { |
|
670 | - throw new EE_Error( |
|
671 | - sprintf( |
|
672 | - esc_html__( |
|
673 | - 'The configuration for "%1$s->%2$s" is not of the "%3$s" class.', |
|
674 | - 'event_espresso' |
|
675 | - ), |
|
676 | - $section, |
|
677 | - $name, |
|
678 | - $config_class |
|
679 | - ) |
|
680 | - ); |
|
681 | - } |
|
682 | - return false; |
|
683 | - } |
|
684 | - break; |
|
685 | - // TEST #9 : verify config object |
|
686 | - case 9: |
|
687 | - if (! $config_obj instanceof EE_Config_Base) { |
|
688 | - if ($display_errors) { |
|
689 | - throw new EE_Error( |
|
690 | - sprintf( |
|
691 | - esc_html__('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
692 | - print_r($config_obj, true) |
|
693 | - ) |
|
694 | - ); |
|
695 | - } |
|
696 | - return false; |
|
697 | - } |
|
698 | - break; |
|
699 | - } |
|
700 | - } |
|
701 | - } catch (EE_Error $e) { |
|
702 | - $e->get_error(); |
|
703 | - } |
|
704 | - // you have successfully run the gauntlet |
|
705 | - return true; |
|
706 | - } |
|
707 | - |
|
708 | - |
|
709 | - /** |
|
710 | - * _generate_config_option_name |
|
711 | - * |
|
712 | - * @access protected |
|
713 | - * @param string $section |
|
714 | - * @param string $name |
|
715 | - * @return string |
|
716 | - */ |
|
717 | - private function _generate_config_option_name($section = '', $name = '') |
|
718 | - { |
|
719 | - return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
720 | - } |
|
721 | - |
|
722 | - |
|
723 | - /** |
|
724 | - * _set_config_class |
|
725 | - * ensures that a config class is set, either from a passed config class or one generated from the config name |
|
726 | - * |
|
727 | - * @access private |
|
728 | - * @param string $config_class |
|
729 | - * @param string $name |
|
730 | - * @return string |
|
731 | - */ |
|
732 | - private function _set_config_class($config_class = '', $name = '') |
|
733 | - { |
|
734 | - return ! empty($config_class) |
|
735 | - ? $config_class |
|
736 | - : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
737 | - } |
|
738 | - |
|
739 | - |
|
740 | - /** |
|
741 | - * @param string $section |
|
742 | - * @param string $name |
|
743 | - * @param string $config_class |
|
744 | - * @param EE_Config_Base|null $config_obj |
|
745 | - * @return EE_Config_Base |
|
746 | - */ |
|
747 | - public function set_config( |
|
748 | - string $section = '', |
|
749 | - string $name = '', |
|
750 | - string $config_class = '', |
|
751 | - EE_Config_Base $config_obj = null |
|
752 | - ): ?EE_Config_Base { |
|
753 | - // ensure config class is set to something |
|
754 | - $config_class = $this->_set_config_class($config_class, $name); |
|
755 | - // run tests 1-4, 6, and 7 to verify all config params are set and valid |
|
756 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
757 | - return null; |
|
758 | - } |
|
759 | - $config_option_name = $this->_generate_config_option_name($section, $name); |
|
760 | - // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
|
761 | - if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
762 | - $this->_addon_option_names[ $config_option_name ] = $config_class; |
|
763 | - $this->update_addon_option_names(); |
|
764 | - } |
|
765 | - // verify the incoming config object but suppress errors |
|
766 | - if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
767 | - $config_obj = new $config_class(); |
|
768 | - } |
|
769 | - if (get_option($config_option_name)) { |
|
770 | - EE_Config::log($config_option_name); |
|
771 | - try { |
|
772 | - update_option($config_option_name, $config_obj); |
|
773 | - } catch (Exception $exception) { |
|
774 | - throw new DomainException( |
|
775 | - sprintf( |
|
776 | - esc_html__( |
|
777 | - 'The following exception occurred while attempting to update the "%1$s" class for config section "%2$s->%3$s": %4$s', |
|
778 | - 'event_espresso' |
|
779 | - ), |
|
780 | - $config_class, |
|
781 | - $section, |
|
782 | - $name, |
|
783 | - $exception->getMessage() |
|
784 | - ) |
|
785 | - ); |
|
786 | - } |
|
787 | - $this->{$section}->{$name} = $config_obj; |
|
788 | - return $this->{$section}->{$name}; |
|
789 | - } else { |
|
790 | - // create a wp-option for this config |
|
791 | - if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
792 | - $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
793 | - return $this->{$section}->{$name}; |
|
794 | - } else { |
|
795 | - EE_Error::add_error( |
|
796 | - sprintf(esc_html__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
797 | - __FILE__, |
|
798 | - __FUNCTION__, |
|
799 | - __LINE__ |
|
800 | - ); |
|
801 | - return null; |
|
802 | - } |
|
803 | - } |
|
804 | - } |
|
805 | - |
|
806 | - |
|
807 | - /** |
|
808 | - * update_config |
|
809 | - * Important: the config object must ALREADY be set, otherwise this will produce an error. |
|
810 | - * |
|
811 | - * @access public |
|
812 | - * @param string $section |
|
813 | - * @param string $name |
|
814 | - * @param EE_Config_Base|string $config_obj |
|
815 | - * @param bool $throw_errors |
|
816 | - * @return bool |
|
817 | - */ |
|
818 | - public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) |
|
819 | - { |
|
820 | - // don't allow config updates during WP heartbeats |
|
821 | - /** @var RequestInterface $request */ |
|
822 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
823 | - if ($request->isWordPressHeartbeat()) { |
|
824 | - return false; |
|
825 | - } |
|
826 | - $config_obj = maybe_unserialize($config_obj); |
|
827 | - // get class name of the incoming object |
|
828 | - $config_class = get_class($config_obj); |
|
829 | - // run tests 1-5 and 9 to verify config |
|
830 | - if ( |
|
831 | - ! $this->_verify_config_params( |
|
832 | - $section, |
|
833 | - $name, |
|
834 | - $config_class, |
|
835 | - $config_obj, |
|
836 | - array(1, 2, 3, 4, 7, 9) |
|
837 | - ) |
|
838 | - ) { |
|
839 | - return false; |
|
840 | - } |
|
841 | - $config_option_name = $this->_generate_config_option_name($section, $name); |
|
842 | - // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
|
843 | - if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
844 | - // save new config to db |
|
845 | - if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
846 | - return true; |
|
847 | - } |
|
848 | - } else { |
|
849 | - // first check if the record already exists |
|
850 | - $existing_config = get_option($config_option_name); |
|
851 | - $config_obj = serialize($config_obj); |
|
852 | - // just return if db record is already up-to-date (NOT type safe comparison) |
|
853 | - if ($existing_config == $config_obj) { |
|
854 | - $this->{$section}->{$name} = $config_obj; |
|
855 | - return true; |
|
856 | - } elseif (update_option($config_option_name, $config_obj)) { |
|
857 | - EE_Config::log($config_option_name); |
|
858 | - // update wp-option for this config class |
|
859 | - $this->{$section}->{$name} = $config_obj; |
|
860 | - return true; |
|
861 | - } elseif ($throw_errors) { |
|
862 | - EE_Error::add_error( |
|
863 | - sprintf( |
|
864 | - esc_html__( |
|
865 | - 'The "%1$s" object stored at"%2$s" was not successfully updated in the database.', |
|
866 | - 'event_espresso' |
|
867 | - ), |
|
868 | - $config_class, |
|
869 | - 'EE_Config->' . $section . '->' . $name |
|
870 | - ), |
|
871 | - __FILE__, |
|
872 | - __FUNCTION__, |
|
873 | - __LINE__ |
|
874 | - ); |
|
875 | - } |
|
876 | - } |
|
877 | - return false; |
|
878 | - } |
|
879 | - |
|
880 | - |
|
881 | - /** |
|
882 | - * get_config |
|
883 | - * |
|
884 | - * @access public |
|
885 | - * @param string $section |
|
886 | - * @param string $name |
|
887 | - * @param string $config_class |
|
888 | - * @return mixed EE_Config_Base | NULL |
|
889 | - */ |
|
890 | - public function get_config($section = '', $name = '', $config_class = '') |
|
891 | - { |
|
892 | - // ensure config class is set to something |
|
893 | - $config_class = $this->_set_config_class($config_class, $name); |
|
894 | - // run tests 1-4, 6 and 7 to verify that all params have been set |
|
895 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
896 | - return null; |
|
897 | - } |
|
898 | - // now test if the requested config object exists, but suppress errors |
|
899 | - if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
900 | - // config already exists, so pass it back |
|
901 | - return $this->{$section}->{$name}; |
|
902 | - } |
|
903 | - // load config option from db if it exists |
|
904 | - $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
905 | - // verify the newly retrieved config object, but suppress errors |
|
906 | - if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
907 | - // config is good, so set it and pass it back |
|
908 | - $this->{$section}->{$name} = $config_obj; |
|
909 | - return $this->{$section}->{$name}; |
|
910 | - } |
|
911 | - // oops! $config_obj is not already set and does not exist in the db, so create a new one |
|
912 | - $config_obj = $this->set_config($section, $name, $config_class); |
|
913 | - // verify the newly created config object |
|
914 | - if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
915 | - return $this->{$section}->{$name}; |
|
916 | - } else { |
|
917 | - EE_Error::add_error( |
|
918 | - sprintf(esc_html__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
919 | - __FILE__, |
|
920 | - __FUNCTION__, |
|
921 | - __LINE__ |
|
922 | - ); |
|
923 | - } |
|
924 | - return null; |
|
925 | - } |
|
926 | - |
|
927 | - |
|
928 | - /** |
|
929 | - * get_config_option |
|
930 | - * |
|
931 | - * @access public |
|
932 | - * @param string $config_option_name |
|
933 | - * @return mixed EE_Config_Base | FALSE |
|
934 | - */ |
|
935 | - public function get_config_option($config_option_name = '') |
|
936 | - { |
|
937 | - // retrieve the wp-option for this config class. |
|
938 | - $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
939 | - if (empty($config_option)) { |
|
940 | - EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
941 | - } |
|
942 | - return $config_option; |
|
943 | - } |
|
944 | - |
|
945 | - |
|
946 | - /** |
|
947 | - * log |
|
948 | - * |
|
949 | - * @param string $config_option_name |
|
950 | - */ |
|
951 | - public static function log($config_option_name = '') |
|
952 | - { |
|
953 | - if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
954 | - $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
955 | - /** @var RequestParams $request */ |
|
956 | - $request = LoaderFactory::getLoader()->getShared(RequestParams::class); |
|
957 | - $config_log[ (string) microtime(true) ] = array( |
|
958 | - 'config_name' => $config_option_name, |
|
959 | - 'request' => $request->requestParams(), |
|
960 | - ); |
|
961 | - update_option(EE_Config::LOG_NAME, $config_log); |
|
962 | - } |
|
963 | - } |
|
964 | - |
|
965 | - |
|
966 | - /** |
|
967 | - * trim_log |
|
968 | - * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
|
969 | - */ |
|
970 | - public static function trim_log() |
|
971 | - { |
|
972 | - if (! EE_Config::logging_enabled()) { |
|
973 | - return; |
|
974 | - } |
|
975 | - $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
976 | - $log_length = count($config_log); |
|
977 | - if ($log_length > EE_Config::LOG_LENGTH) { |
|
978 | - ksort($config_log); |
|
979 | - $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
980 | - update_option(EE_Config::LOG_NAME, $config_log); |
|
981 | - } |
|
982 | - } |
|
983 | - |
|
984 | - |
|
985 | - /** |
|
986 | - * get_page_for_posts |
|
987 | - * if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the |
|
988 | - * wp-option "page_for_posts", or "posts" if no page is selected |
|
989 | - * |
|
990 | - * @access public |
|
991 | - * @return string |
|
992 | - */ |
|
993 | - public static function get_page_for_posts() |
|
994 | - { |
|
995 | - $page_for_posts = get_option('page_for_posts'); |
|
996 | - if (! $page_for_posts) { |
|
997 | - return 'posts'; |
|
998 | - } |
|
999 | - global $wpdb; |
|
1000 | - $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
1001 | - return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
1002 | - } |
|
1003 | - |
|
1004 | - |
|
1005 | - /** |
|
1006 | - * register_shortcodes_and_modules. |
|
1007 | - * At this point, it's too early to tell if we're maintenance mode or not. |
|
1008 | - * In fact, this is where we give modules a chance to let core know they exist |
|
1009 | - * so they can help trigger maintenance mode if it's needed |
|
1010 | - * |
|
1011 | - * @access public |
|
1012 | - * @return void |
|
1013 | - */ |
|
1014 | - public function register_shortcodes_and_modules() |
|
1015 | - { |
|
1016 | - // allow modules to set hooks for the rest of the system |
|
1017 | - EE_Registry::instance()->modules = $this->_register_modules(); |
|
1018 | - } |
|
1019 | - |
|
1020 | - |
|
1021 | - /** |
|
1022 | - * initialize_shortcodes_and_modules |
|
1023 | - * meaning they can start adding their hooks to get stuff done |
|
1024 | - * |
|
1025 | - * @access public |
|
1026 | - * @return void |
|
1027 | - */ |
|
1028 | - public function initialize_shortcodes_and_modules() |
|
1029 | - { |
|
1030 | - // allow modules to set hooks for the rest of the system |
|
1031 | - $this->_initialize_modules(); |
|
1032 | - } |
|
1033 | - |
|
1034 | - |
|
1035 | - /** |
|
1036 | - * widgets_init |
|
1037 | - * |
|
1038 | - * @access private |
|
1039 | - * @return void |
|
1040 | - */ |
|
1041 | - public function widgets_init() |
|
1042 | - { |
|
1043 | - // only init widgets on admin pages when not in complete maintenance, and |
|
1044 | - // on frontend when not in any maintenance mode |
|
1045 | - if ( |
|
1046 | - MaintenanceStatus::isDisabled() |
|
1047 | - || (is_admin() && MaintenanceStatus::isNotFullSite()) |
|
1048 | - ) { |
|
1049 | - // grab list of installed widgets |
|
1050 | - $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
1051 | - // filter list of modules to register |
|
1052 | - $widgets_to_register = apply_filters( |
|
1053 | - 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
1054 | - $widgets_to_register |
|
1055 | - ); |
|
1056 | - if (! empty($widgets_to_register)) { |
|
1057 | - // cycle thru widget folders |
|
1058 | - foreach ($widgets_to_register as $widget_path) { |
|
1059 | - // add to list of installed widget modules |
|
1060 | - EE_Config::register_ee_widget($widget_path); |
|
1061 | - } |
|
1062 | - } |
|
1063 | - // filter list of installed modules |
|
1064 | - EE_Registry::instance()->widgets = apply_filters( |
|
1065 | - 'FHEE__EE_Config__register_widgets__installed_widgets', |
|
1066 | - EE_Registry::instance()->widgets |
|
1067 | - ); |
|
1068 | - } |
|
1069 | - } |
|
1070 | - |
|
1071 | - |
|
1072 | - /** |
|
1073 | - * register_ee_widget - makes core aware of this widget |
|
1074 | - * |
|
1075 | - * @access public |
|
1076 | - * @param string $widget_path - full path up to and including widget folder |
|
1077 | - * @return void |
|
1078 | - */ |
|
1079 | - public static function register_ee_widget($widget_path = null) |
|
1080 | - { |
|
1081 | - do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
1082 | - $widget_ext = '.widget.php'; |
|
1083 | - // make all separators match |
|
1084 | - $widget_path = rtrim(str_replace('\\', DS, $widget_path), DS); |
|
1085 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
1086 | - if (strpos($widget_path, $widget_ext) !== false) { |
|
1087 | - // grab and shortcode file name from directory name and break apart at dots |
|
1088 | - $file_name = explode('.', basename($widget_path)); |
|
1089 | - // take first segment from file name pieces and remove class prefix if it exists |
|
1090 | - $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
1091 | - // sanitize shortcode directory name |
|
1092 | - $widget = sanitize_key($widget); |
|
1093 | - // now we need to rebuild the shortcode path |
|
1094 | - $widget_path = explode('/', $widget_path); |
|
1095 | - // remove last segment |
|
1096 | - array_pop($widget_path); |
|
1097 | - // glue it back together |
|
1098 | - $widget_path = implode(DS, $widget_path); |
|
1099 | - } else { |
|
1100 | - // grab and sanitize widget directory name |
|
1101 | - $widget = sanitize_key(basename($widget_path)); |
|
1102 | - } |
|
1103 | - // create classname from widget directory name |
|
1104 | - $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
1105 | - // add class prefix |
|
1106 | - $widget_class = 'EEW_' . $widget; |
|
1107 | - // does the widget exist ? |
|
1108 | - if (! is_readable($widget_path . '/' . $widget_class . $widget_ext)) { |
|
1109 | - $msg = sprintf( |
|
1110 | - esc_html__( |
|
1111 | - 'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
|
1112 | - 'event_espresso' |
|
1113 | - ), |
|
1114 | - $widget_class, |
|
1115 | - $widget_path . '/' . $widget_class . $widget_ext |
|
1116 | - ); |
|
1117 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1118 | - return; |
|
1119 | - } |
|
1120 | - // load the widget class file |
|
1121 | - require_once($widget_path . '/' . $widget_class . $widget_ext); |
|
1122 | - // verify that class exists |
|
1123 | - if (! class_exists($widget_class)) { |
|
1124 | - $msg = sprintf(esc_html__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
1125 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1126 | - return; |
|
1127 | - } |
|
1128 | - register_widget($widget_class); |
|
1129 | - // add to array of registered widgets |
|
1130 | - EE_Registry::instance()->widgets->{$widget_class} = $widget_path . '/' . $widget_class . $widget_ext; |
|
1131 | - } |
|
1132 | - |
|
1133 | - |
|
1134 | - /** |
|
1135 | - * _register_modules |
|
1136 | - * |
|
1137 | - * @access private |
|
1138 | - * @return array |
|
1139 | - */ |
|
1140 | - private function _register_modules() |
|
1141 | - { |
|
1142 | - // grab list of installed modules |
|
1143 | - $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
1144 | - // filter list of modules to register |
|
1145 | - $modules_to_register = apply_filters( |
|
1146 | - 'FHEE__EE_Config__register_modules__modules_to_register', |
|
1147 | - $modules_to_register |
|
1148 | - ); |
|
1149 | - if (! empty($modules_to_register)) { |
|
1150 | - // loop through folders |
|
1151 | - foreach ($modules_to_register as $module_path) { |
|
1152 | - /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
|
1153 | - if ( |
|
1154 | - $module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
1155 | - && $module_path !== EE_MODULES . 'gateways' |
|
1156 | - ) { |
|
1157 | - // add to list of installed modules |
|
1158 | - EE_Config::register_module($module_path); |
|
1159 | - } |
|
1160 | - } |
|
1161 | - } |
|
1162 | - // filter list of installed modules |
|
1163 | - return apply_filters( |
|
1164 | - 'FHEE__EE_Config___register_modules__installed_modules', |
|
1165 | - EE_Registry::instance()->modules |
|
1166 | - ); |
|
1167 | - } |
|
1168 | - |
|
1169 | - |
|
1170 | - /** |
|
1171 | - * register_module - makes core aware of this module |
|
1172 | - * |
|
1173 | - * @access public |
|
1174 | - * @param string $module_path - full path up to and including module folder |
|
1175 | - * @return bool |
|
1176 | - */ |
|
1177 | - public static function register_module($module_path = null) |
|
1178 | - { |
|
1179 | - do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
1180 | - $module_ext = '.module.php'; |
|
1181 | - // make all separators match |
|
1182 | - $module_path = str_replace(array('\\', '/'), '/', $module_path); |
|
1183 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
1184 | - if (strpos($module_path, $module_ext) !== false) { |
|
1185 | - // grab and shortcode file name from directory name and break apart at dots |
|
1186 | - $module_file = explode('.', basename($module_path)); |
|
1187 | - // now we need to rebuild the shortcode path |
|
1188 | - $module_path = explode('/', $module_path); |
|
1189 | - // remove last segment |
|
1190 | - array_pop($module_path); |
|
1191 | - // glue it back together |
|
1192 | - $module_path = implode('/', $module_path) . '/'; |
|
1193 | - // take first segment from file name pieces and sanitize it |
|
1194 | - $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
1195 | - // ensure class prefix is added |
|
1196 | - $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
1197 | - } else { |
|
1198 | - // we need to generate the filename based off of the folder name |
|
1199 | - // grab and sanitize module name |
|
1200 | - $module = strtolower(basename($module_path)); |
|
1201 | - $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
1202 | - // like trailingslashit() |
|
1203 | - $module_path = rtrim($module_path, '/') . '/'; |
|
1204 | - // create classname from module directory name |
|
1205 | - $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
1206 | - // add class prefix |
|
1207 | - $module_class = 'EED_' . $module; |
|
1208 | - } |
|
1209 | - // does the module exist ? |
|
1210 | - if (! is_readable($module_path . '/' . $module_class . $module_ext)) { |
|
1211 | - $msg = sprintf( |
|
1212 | - esc_html__( |
|
1213 | - 'The requested %s module file could not be found or is not readable due to file permissions.', |
|
1214 | - 'event_espresso' |
|
1215 | - ), |
|
1216 | - $module |
|
1217 | - ); |
|
1218 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1219 | - return false; |
|
1220 | - } |
|
1221 | - // load the module class file |
|
1222 | - require_once($module_path . $module_class . $module_ext); |
|
1223 | - // verify that class exists |
|
1224 | - if (! class_exists($module_class)) { |
|
1225 | - $msg = sprintf(esc_html__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
1226 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1227 | - return false; |
|
1228 | - } |
|
1229 | - // add to array of registered modules |
|
1230 | - EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
1231 | - do_action( |
|
1232 | - 'AHEE__EE_Config__register_module__complete', |
|
1233 | - $module_class, |
|
1234 | - EE_Registry::instance()->modules->{$module_class} |
|
1235 | - ); |
|
1236 | - return true; |
|
1237 | - } |
|
1238 | - |
|
1239 | - |
|
1240 | - /** |
|
1241 | - * _initialize_modules |
|
1242 | - * allow modules to set hooks for the rest of the system |
|
1243 | - * |
|
1244 | - * @access private |
|
1245 | - * @return void |
|
1246 | - */ |
|
1247 | - private function _initialize_modules() |
|
1248 | - { |
|
1249 | - // cycle thru shortcode folders |
|
1250 | - foreach (EE_Registry::instance()->modules as $module_class => $module_path) { |
|
1251 | - // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
1252 | - // which set hooks ? |
|
1253 | - if (is_admin() && is_callable([$module_class, 'set_hooks_admin'])) { |
|
1254 | - // fire immediately |
|
1255 | - call_user_func([$module_class, 'set_hooks_admin']); |
|
1256 | - } else { |
|
1257 | - // delay until other systems are online |
|
1258 | - add_action( |
|
1259 | - 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
1260 | - array($module_class, 'set_hooks') |
|
1261 | - ); |
|
1262 | - } |
|
1263 | - } |
|
1264 | - } |
|
1265 | - |
|
1266 | - |
|
1267 | - /** |
|
1268 | - * register_route - adds module method routes to route_map |
|
1269 | - * |
|
1270 | - * @access public |
|
1271 | - * @param string $route - "pretty" public alias for module method |
|
1272 | - * @param string $module - module name (classname without EED_ prefix) |
|
1273 | - * @param string $method_name - the actual module method to be routed to |
|
1274 | - * @param string $key - url param key indicating a route is being called |
|
1275 | - * @return bool |
|
1276 | - */ |
|
1277 | - public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') |
|
1278 | - { |
|
1279 | - do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
1280 | - $module = str_replace('EED_', '', $module); |
|
1281 | - $module_class = 'EED_' . $module; |
|
1282 | - if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
1283 | - $msg = sprintf(esc_html__('The module %s has not been registered.', 'event_espresso'), $module); |
|
1284 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1285 | - return false; |
|
1286 | - } |
|
1287 | - if (empty($route)) { |
|
1288 | - $msg = sprintf(esc_html__('No route has been supplied.', 'event_espresso'), $route); |
|
1289 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1290 | - return false; |
|
1291 | - } |
|
1292 | - if (! method_exists('EED_' . $module, $method_name)) { |
|
1293 | - $msg = sprintf( |
|
1294 | - esc_html__('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
1295 | - $route |
|
1296 | - ); |
|
1297 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1298 | - return false; |
|
1299 | - } |
|
1300 | - EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name); |
|
1301 | - return true; |
|
1302 | - } |
|
1303 | - |
|
1304 | - |
|
1305 | - /** |
|
1306 | - * get_route - get module method route |
|
1307 | - * |
|
1308 | - * @access public |
|
1309 | - * @param string $route - "pretty" public alias for module method |
|
1310 | - * @param string $key - url param key indicating a route is being called |
|
1311 | - * @return string |
|
1312 | - */ |
|
1313 | - public static function get_route($route = null, $key = 'ee') |
|
1314 | - { |
|
1315 | - do_action('AHEE__EE_Config__get_route__begin', $route); |
|
1316 | - $route = (string) apply_filters('FHEE__EE_Config__get_route', $route); |
|
1317 | - if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) { |
|
1318 | - return EE_Config::$_module_route_map[ $key ][ $route ]; |
|
1319 | - } |
|
1320 | - return null; |
|
1321 | - } |
|
1322 | - |
|
1323 | - |
|
1324 | - /** |
|
1325 | - * get_routes - get ALL module method routes |
|
1326 | - * |
|
1327 | - * @access public |
|
1328 | - * @return array |
|
1329 | - */ |
|
1330 | - public static function get_routes() |
|
1331 | - { |
|
1332 | - return EE_Config::$_module_route_map; |
|
1333 | - } |
|
1334 | - |
|
1335 | - |
|
1336 | - /** |
|
1337 | - * register_forward - allows modules to forward request to another module for further processing |
|
1338 | - * |
|
1339 | - * @access public |
|
1340 | - * @param string $route - "pretty" public alias for module method |
|
1341 | - * @param integer $status - integer value corresponding to status constant strings set in module parent |
|
1342 | - * class, allows different forwards to be served based on status |
|
1343 | - * @param array|string $forward - function name or array( class, method ) |
|
1344 | - * @param string $key - url param key indicating a route is being called |
|
1345 | - * @return bool |
|
1346 | - */ |
|
1347 | - public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
|
1348 | - { |
|
1349 | - do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
1350 | - if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
1351 | - $msg = sprintf( |
|
1352 | - esc_html__('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
1353 | - $route |
|
1354 | - ); |
|
1355 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1356 | - return false; |
|
1357 | - } |
|
1358 | - if (empty($forward)) { |
|
1359 | - $msg = sprintf(esc_html__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
1360 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1361 | - return false; |
|
1362 | - } |
|
1363 | - if (is_array($forward)) { |
|
1364 | - if (! isset($forward[1])) { |
|
1365 | - $msg = sprintf( |
|
1366 | - esc_html__('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
1367 | - $route |
|
1368 | - ); |
|
1369 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1370 | - return false; |
|
1371 | - } |
|
1372 | - if (! method_exists($forward[0], $forward[1])) { |
|
1373 | - $msg = sprintf( |
|
1374 | - esc_html__('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
1375 | - $forward[1], |
|
1376 | - $route |
|
1377 | - ); |
|
1378 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1379 | - return false; |
|
1380 | - } |
|
1381 | - } elseif (! function_exists($forward)) { |
|
1382 | - $msg = sprintf( |
|
1383 | - esc_html__('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
1384 | - $forward, |
|
1385 | - $route |
|
1386 | - ); |
|
1387 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1388 | - return false; |
|
1389 | - } |
|
1390 | - EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward; |
|
1391 | - return true; |
|
1392 | - } |
|
1393 | - |
|
1394 | - |
|
1395 | - /** |
|
1396 | - * get_forward - get forwarding route |
|
1397 | - * |
|
1398 | - * @access public |
|
1399 | - * @param string $route - "pretty" public alias for module method |
|
1400 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
1401 | - * allows different forwards to be served based on status |
|
1402 | - * @param string $key - url param key indicating a route is being called |
|
1403 | - * @return string |
|
1404 | - */ |
|
1405 | - public static function get_forward($route = null, $status = 0, $key = 'ee') |
|
1406 | - { |
|
1407 | - do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
1408 | - if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) { |
|
1409 | - return apply_filters( |
|
1410 | - 'FHEE__EE_Config__get_forward', |
|
1411 | - EE_Config::$_module_forward_map[ $key ][ $route ][ $status ], |
|
1412 | - $route, |
|
1413 | - $status |
|
1414 | - ); |
|
1415 | - } |
|
1416 | - return null; |
|
1417 | - } |
|
1418 | - |
|
1419 | - |
|
1420 | - /** |
|
1421 | - * register_forward - allows modules to specify different view templates for different method routes and status |
|
1422 | - * results |
|
1423 | - * |
|
1424 | - * @access public |
|
1425 | - * @param string $route - "pretty" public alias for module method |
|
1426 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
1427 | - * allows different views to be served based on status |
|
1428 | - * @param string $view |
|
1429 | - * @param string $key - url param key indicating a route is being called |
|
1430 | - * @return bool |
|
1431 | - */ |
|
1432 | - public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
|
1433 | - { |
|
1434 | - do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
1435 | - if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
1436 | - $msg = sprintf( |
|
1437 | - esc_html__('The module route %s for this view has not been registered.', 'event_espresso'), |
|
1438 | - $route |
|
1439 | - ); |
|
1440 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1441 | - return false; |
|
1442 | - } |
|
1443 | - if (! is_readable($view)) { |
|
1444 | - $msg = sprintf( |
|
1445 | - esc_html__( |
|
1446 | - 'The %s view file could not be found or is not readable due to file permissions.', |
|
1447 | - 'event_espresso' |
|
1448 | - ), |
|
1449 | - $view |
|
1450 | - ); |
|
1451 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1452 | - return false; |
|
1453 | - } |
|
1454 | - EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view; |
|
1455 | - return true; |
|
1456 | - } |
|
1457 | - |
|
1458 | - |
|
1459 | - /** |
|
1460 | - * get_view - get view for route and status |
|
1461 | - * |
|
1462 | - * @access public |
|
1463 | - * @param string $route - "pretty" public alias for module method |
|
1464 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
1465 | - * allows different views to be served based on status |
|
1466 | - * @param string $key - url param key indicating a route is being called |
|
1467 | - * @return string |
|
1468 | - */ |
|
1469 | - public static function get_view($route = null, $status = 0, $key = 'ee') |
|
1470 | - { |
|
1471 | - do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
1472 | - if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) { |
|
1473 | - return apply_filters( |
|
1474 | - 'FHEE__EE_Config__get_view', |
|
1475 | - EE_Config::$_module_view_map[ $key ][ $route ][ $status ], |
|
1476 | - $route, |
|
1477 | - $status |
|
1478 | - ); |
|
1479 | - } |
|
1480 | - return null; |
|
1481 | - } |
|
1482 | - |
|
1483 | - |
|
1484 | - public function update_addon_option_names() |
|
1485 | - { |
|
1486 | - update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
1487 | - } |
|
1488 | - |
|
1489 | - |
|
1490 | - public function shutdown() |
|
1491 | - { |
|
1492 | - $this->update_addon_option_names(); |
|
1493 | - } |
|
1494 | - |
|
1495 | - |
|
1496 | - /** |
|
1497 | - * @return LegacyShortcodesManager |
|
1498 | - */ |
|
1499 | - public static function getLegacyShortcodesManager() |
|
1500 | - { |
|
1501 | - if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
1502 | - EE_Config::instance()->legacy_shortcodes_manager = LoaderFactory::getLoader()->getShared( |
|
1503 | - LegacyShortcodesManager::class |
|
1504 | - ); |
|
1505 | - } |
|
1506 | - return EE_Config::instance()->legacy_shortcodes_manager; |
|
1507 | - } |
|
1508 | - |
|
1509 | - |
|
1510 | - /** |
|
1511 | - * register_shortcode - makes core aware of this shortcode |
|
1512 | - * |
|
1513 | - * @deprecated 4.9.26 |
|
1514 | - * @param string $shortcode_path - full path up to and including shortcode folder |
|
1515 | - * @return bool |
|
1516 | - */ |
|
1517 | - public static function register_shortcode($shortcode_path = null) |
|
1518 | - { |
|
1519 | - EE_Error::doing_it_wrong( |
|
1520 | - __METHOD__, |
|
1521 | - esc_html__( |
|
1522 | - 'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.', |
|
1523 | - 'event_espresso' |
|
1524 | - ), |
|
1525 | - '4.9.26' |
|
1526 | - ); |
|
1527 | - return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path); |
|
1528 | - } |
|
1529 | -} |
|
1530 | - |
|
1531 | -/** |
|
1532 | - * Base class used for config classes. These classes should generally not have |
|
1533 | - * magic functions in use, except we'll allow them to magically set and get stuff... |
|
1534 | - * basically, they should just be well-defined stdClasses |
|
1535 | - */ |
|
1536 | -class EE_Config_Base |
|
1537 | -{ |
|
1538 | - /** |
|
1539 | - * Utility function for escaping the value of a property and returning. |
|
1540 | - * |
|
1541 | - * @param string $property property name (checks to see if exists). |
|
1542 | - * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
1543 | - * @throws EE_Error |
|
1544 | - */ |
|
1545 | - public function get_pretty($property) |
|
1546 | - { |
|
1547 | - if (! property_exists($this, $property)) { |
|
1548 | - throw new EE_Error( |
|
1549 | - sprintf( |
|
1550 | - esc_html__( |
|
1551 | - '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
|
1552 | - 'event_espresso' |
|
1553 | - ), |
|
1554 | - get_class($this), |
|
1555 | - $property |
|
1556 | - ) |
|
1557 | - ); |
|
1558 | - } |
|
1559 | - // just handling escaping of strings for now. |
|
1560 | - if (is_string($this->{$property})) { |
|
1561 | - return stripslashes($this->{$property}); |
|
1562 | - } |
|
1563 | - return $this->{$property}; |
|
1564 | - } |
|
1565 | - |
|
1566 | - |
|
1567 | - public function populate() |
|
1568 | - { |
|
1569 | - // grab defaults via a new instance of this class. |
|
1570 | - $class_name = get_class($this); |
|
1571 | - $defaults = new $class_name(); |
|
1572 | - // loop through the properties for this class and see if they are set. If they are NOT, then grab the |
|
1573 | - // default from our $defaults object. |
|
1574 | - foreach (get_object_vars($defaults) as $property => $value) { |
|
1575 | - if ($this->{$property} === null) { |
|
1576 | - $this->{$property} = $value; |
|
1577 | - } |
|
1578 | - } |
|
1579 | - // cleanup |
|
1580 | - unset($defaults); |
|
1581 | - } |
|
1582 | - |
|
1583 | - |
|
1584 | - /** |
|
1585 | - * __isset |
|
1586 | - * |
|
1587 | - * @param $a |
|
1588 | - * @return bool |
|
1589 | - */ |
|
1590 | - public function __isset($a) |
|
1591 | - { |
|
1592 | - return false; |
|
1593 | - } |
|
1594 | - |
|
1595 | - |
|
1596 | - /** |
|
1597 | - * __unset |
|
1598 | - * |
|
1599 | - * @param $a |
|
1600 | - * @return bool |
|
1601 | - */ |
|
1602 | - public function __unset($a) |
|
1603 | - { |
|
1604 | - return false; |
|
1605 | - } |
|
1606 | - |
|
1607 | - |
|
1608 | - /** |
|
1609 | - * __clone |
|
1610 | - */ |
|
1611 | - public function __clone() |
|
1612 | - { |
|
1613 | - } |
|
1614 | - |
|
1615 | - |
|
1616 | - /** |
|
1617 | - * __wakeup |
|
1618 | - */ |
|
1619 | - public function __wakeup() |
|
1620 | - { |
|
1621 | - } |
|
1622 | - |
|
1623 | - |
|
1624 | - /** |
|
1625 | - * __destruct |
|
1626 | - */ |
|
1627 | - public function __destruct() |
|
1628 | - { |
|
1629 | - } |
|
1630 | -} |
|
1631 | - |
|
1632 | -/** |
|
1633 | - * Class for defining what's in the EE_Config relating to registration settings |
|
1634 | - */ |
|
1635 | -class EE_Core_Config extends EE_Config_Base |
|
1636 | -{ |
|
1637 | - const OPTION_NAME_UXIP = 'ee_ueip_optin'; |
|
1638 | - |
|
1639 | - |
|
1640 | - public $current_blog_id; |
|
1641 | - |
|
1642 | - public $ee_ueip_optin; |
|
1643 | - |
|
1644 | - public $ee_ueip_has_notified; |
|
1645 | - |
|
1646 | - /** |
|
1647 | - * Not to be confused with the 4 critical page variables (See |
|
1648 | - * get_critical_pages_array()), this is just an array of wp posts that have EE |
|
1649 | - * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode |
|
1650 | - * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array. |
|
1651 | - * |
|
1652 | - * @var array |
|
1653 | - */ |
|
1654 | - public $post_shortcodes; |
|
1655 | - |
|
1656 | - public $module_route_map; |
|
1657 | - |
|
1658 | - public $module_forward_map; |
|
1659 | - |
|
1660 | - public $module_view_map; |
|
1661 | - |
|
1662 | - /** |
|
1663 | - * The next 4 vars are the IDs of critical EE pages. |
|
1664 | - * |
|
1665 | - * @var int |
|
1666 | - */ |
|
1667 | - public $reg_page_id; |
|
1668 | - |
|
1669 | - public $txn_page_id; |
|
1670 | - |
|
1671 | - public $thank_you_page_id; |
|
1672 | - |
|
1673 | - public $cancel_page_id; |
|
1674 | - |
|
1675 | - /** |
|
1676 | - * The next 4 vars are the URLs of critical EE pages. |
|
1677 | - * |
|
1678 | - * @var int |
|
1679 | - */ |
|
1680 | - public $reg_page_url; |
|
1681 | - |
|
1682 | - public $txn_page_url; |
|
1683 | - |
|
1684 | - public $thank_you_page_url; |
|
1685 | - |
|
1686 | - public $cancel_page_url; |
|
1687 | - |
|
1688 | - /** |
|
1689 | - * The next vars relate to the custom slugs for EE CPT routes |
|
1690 | - */ |
|
1691 | - public $event_cpt_slug; |
|
1692 | - |
|
1693 | - /** |
|
1694 | - * This caches the _ee_ueip_option in case this config is reset in the same |
|
1695 | - * request across blog switches in a multisite context. |
|
1696 | - * Avoids extra queries to the db for this option. |
|
1697 | - * |
|
1698 | - * @var bool |
|
1699 | - */ |
|
1700 | - public static $ee_ueip_option; |
|
1701 | - |
|
1702 | - |
|
1703 | - /** |
|
1704 | - * class constructor |
|
1705 | - * |
|
1706 | - * @access public |
|
1707 | - */ |
|
1708 | - public function __construct() |
|
1709 | - { |
|
1710 | - // set default organization settings |
|
1711 | - $this->current_blog_id = get_current_blog_id(); |
|
1712 | - $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id; |
|
1713 | - $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
|
1714 | - $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
1715 | - $this->post_shortcodes = array(); |
|
1716 | - $this->module_route_map = array(); |
|
1717 | - $this->module_forward_map = array(); |
|
1718 | - $this->module_view_map = array(); |
|
1719 | - // critical EE page IDs |
|
1720 | - $this->reg_page_id = 0; |
|
1721 | - $this->txn_page_id = 0; |
|
1722 | - $this->thank_you_page_id = 0; |
|
1723 | - $this->cancel_page_id = 0; |
|
1724 | - // critical EE page URLs |
|
1725 | - $this->reg_page_url = ''; |
|
1726 | - $this->txn_page_url = ''; |
|
1727 | - $this->thank_you_page_url = ''; |
|
1728 | - $this->cancel_page_url = ''; |
|
1729 | - // cpt slugs |
|
1730 | - $this->event_cpt_slug = esc_html__('events', 'event_espresso'); |
|
1731 | - // ueip constant check |
|
1732 | - if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
1733 | - $this->ee_ueip_optin = false; |
|
1734 | - $this->ee_ueip_has_notified = true; |
|
1735 | - } |
|
1736 | - } |
|
1737 | - |
|
1738 | - |
|
1739 | - /** |
|
1740 | - * @return array |
|
1741 | - */ |
|
1742 | - public function get_critical_pages_array() |
|
1743 | - { |
|
1744 | - return array( |
|
1745 | - $this->reg_page_id, |
|
1746 | - $this->txn_page_id, |
|
1747 | - $this->thank_you_page_id, |
|
1748 | - $this->cancel_page_id, |
|
1749 | - ); |
|
1750 | - } |
|
1751 | - |
|
1752 | - |
|
1753 | - /** |
|
1754 | - * @return array |
|
1755 | - */ |
|
1756 | - public function get_critical_pages_shortcodes_array() |
|
1757 | - { |
|
1758 | - return array( |
|
1759 | - $this->reg_page_id => 'ESPRESSO_CHECKOUT', |
|
1760 | - $this->txn_page_id => 'ESPRESSO_TXN_PAGE', |
|
1761 | - $this->thank_you_page_id => 'ESPRESSO_THANK_YOU', |
|
1762 | - $this->cancel_page_id => 'ESPRESSO_CANCELLED', |
|
1763 | - ); |
|
1764 | - } |
|
1765 | - |
|
1766 | - |
|
1767 | - /** |
|
1768 | - * gets/returns URL for EE reg_page |
|
1769 | - * |
|
1770 | - * @access public |
|
1771 | - * @return string |
|
1772 | - */ |
|
1773 | - public function reg_page_url() |
|
1774 | - { |
|
1775 | - if (! $this->reg_page_url) { |
|
1776 | - $this->reg_page_url = add_query_arg( |
|
1777 | - array('uts' => time()), |
|
1778 | - get_permalink($this->reg_page_id) |
|
1779 | - ) . '#checkout'; |
|
1780 | - } |
|
1781 | - return $this->reg_page_url; |
|
1782 | - } |
|
1783 | - |
|
1784 | - |
|
1785 | - /** |
|
1786 | - * gets/returns URL for EE txn_page |
|
1787 | - * |
|
1788 | - * @param array $query_args like what gets passed to |
|
1789 | - * add_query_arg() as the first argument |
|
1790 | - * @access public |
|
1791 | - * @return string |
|
1792 | - */ |
|
1793 | - public function txn_page_url($query_args = array()) |
|
1794 | - { |
|
1795 | - if (! $this->txn_page_url) { |
|
1796 | - $this->txn_page_url = get_permalink($this->txn_page_id); |
|
1797 | - } |
|
1798 | - if ($query_args) { |
|
1799 | - return add_query_arg($query_args, $this->txn_page_url); |
|
1800 | - } else { |
|
1801 | - return $this->txn_page_url; |
|
1802 | - } |
|
1803 | - } |
|
1804 | - |
|
1805 | - |
|
1806 | - /** |
|
1807 | - * gets/returns URL for EE thank_you_page |
|
1808 | - * |
|
1809 | - * @param array $query_args like what gets passed to |
|
1810 | - * add_query_arg() as the first argument |
|
1811 | - * @access public |
|
1812 | - * @return string |
|
1813 | - */ |
|
1814 | - public function thank_you_page_url($query_args = array()) |
|
1815 | - { |
|
1816 | - if (! $this->thank_you_page_url) { |
|
1817 | - $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
1818 | - } |
|
1819 | - if ($query_args) { |
|
1820 | - return add_query_arg($query_args, $this->thank_you_page_url); |
|
1821 | - } else { |
|
1822 | - return $this->thank_you_page_url; |
|
1823 | - } |
|
1824 | - } |
|
1825 | - |
|
1826 | - |
|
1827 | - /** |
|
1828 | - * gets/returns URL for EE cancel_page |
|
1829 | - * |
|
1830 | - * @access public |
|
1831 | - * @return string |
|
1832 | - */ |
|
1833 | - public function cancel_page_url() |
|
1834 | - { |
|
1835 | - if (! $this->cancel_page_url) { |
|
1836 | - $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
1837 | - } |
|
1838 | - return $this->cancel_page_url; |
|
1839 | - } |
|
1840 | - |
|
1841 | - |
|
1842 | - /** |
|
1843 | - * Resets all critical page urls to their original state. Used primarily by the __sleep() magic method currently. |
|
1844 | - * |
|
1845 | - * @since 4.7.5 |
|
1846 | - */ |
|
1847 | - protected function _reset_urls() |
|
1848 | - { |
|
1849 | - $this->reg_page_url = ''; |
|
1850 | - $this->txn_page_url = ''; |
|
1851 | - $this->cancel_page_url = ''; |
|
1852 | - $this->thank_you_page_url = ''; |
|
1853 | - } |
|
1854 | - |
|
1855 | - |
|
1856 | - /** |
|
1857 | - * Used to return what the optin value is set for the EE User Experience Program. |
|
1858 | - * This accounts for multisite and this value being requested for a subsite. In multisite, the value is set |
|
1859 | - * on the main site only. |
|
1860 | - * |
|
1861 | - * @return bool |
|
1862 | - */ |
|
1863 | - protected function _get_main_ee_ueip_optin() |
|
1864 | - { |
|
1865 | - // if this is the main site then we can just bypass our direct query. |
|
1866 | - if (is_main_site()) { |
|
1867 | - return get_option(self::OPTION_NAME_UXIP, false); |
|
1868 | - } |
|
1869 | - // is this already cached for this request? If so use it. |
|
1870 | - if (EE_Core_Config::$ee_ueip_option !== null) { |
|
1871 | - return EE_Core_Config::$ee_ueip_option; |
|
1872 | - } |
|
1873 | - global $wpdb; |
|
1874 | - $current_network_main_site = is_multisite() ? get_current_site() : null; |
|
1875 | - $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
1876 | - $option = self::OPTION_NAME_UXIP; |
|
1877 | - // set correct table for query |
|
1878 | - $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
1879 | - // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
|
1880 | - // get_blog_option() does a switch_to_blog and that could cause infinite recursion because EE_Core_Config might be |
|
1881 | - // re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
|
1882 | - // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
|
1883 | - // for the purpose of caching. |
|
1884 | - $pre = apply_filters('pre_option_' . $option, false, $option); |
|
1885 | - if (false !== $pre) { |
|
1886 | - EE_Core_Config::$ee_ueip_option = $pre; |
|
1887 | - return EE_Core_Config::$ee_ueip_option; |
|
1888 | - } |
|
1889 | - $row = $wpdb->get_row( |
|
1890 | - $wpdb->prepare( |
|
1891 | - "SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", |
|
1892 | - $option |
|
1893 | - ) |
|
1894 | - ); |
|
1895 | - if (is_object($row)) { |
|
1896 | - $value = $row->option_value; |
|
1897 | - } else { // option does not exist so use default. |
|
1898 | - EE_Core_Config::$ee_ueip_option = apply_filters('default_option_' . $option, false, $option); |
|
1899 | - return EE_Core_Config::$ee_ueip_option; |
|
1900 | - } |
|
1901 | - EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
1902 | - return EE_Core_Config::$ee_ueip_option; |
|
1903 | - } |
|
1904 | - |
|
1905 | - |
|
1906 | - /** |
|
1907 | - * Utility function for escaping the value of a property and returning. |
|
1908 | - * |
|
1909 | - * @param string $property property name (checks to see if exists). |
|
1910 | - * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
1911 | - * @throws EE_Error |
|
1912 | - */ |
|
1913 | - public function get_pretty($property) |
|
1914 | - { |
|
1915 | - if ($property === self::OPTION_NAME_UXIP) { |
|
1916 | - return $this->ee_ueip_optin ? 'yes' : 'no'; |
|
1917 | - } |
|
1918 | - return parent::get_pretty($property); |
|
1919 | - } |
|
1920 | - |
|
1921 | - |
|
1922 | - /** |
|
1923 | - * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values |
|
1924 | - * on the object. |
|
1925 | - * |
|
1926 | - * @return array |
|
1927 | - */ |
|
1928 | - public function __sleep() |
|
1929 | - { |
|
1930 | - // reset all url properties |
|
1931 | - $this->_reset_urls(); |
|
1932 | - // return what to save to db |
|
1933 | - return array_keys(get_object_vars($this)); |
|
1934 | - } |
|
1935 | -} |
|
1936 | - |
|
1937 | -/** |
|
1938 | - * Config class for storing info on the Organization |
|
1939 | - */ |
|
1940 | -class EE_Organization_Config extends EE_Config_Base |
|
1941 | -{ |
|
1942 | - /** |
|
1943 | - * @var string $name |
|
1944 | - * eg EE4.1 |
|
1945 | - */ |
|
1946 | - public $name; |
|
1947 | - |
|
1948 | - /** |
|
1949 | - * @var string $address_1 |
|
1950 | - * eg 123 Onna Road |
|
1951 | - */ |
|
1952 | - public $address_1 = ''; |
|
1953 | - |
|
1954 | - /** |
|
1955 | - * @var string $address_2 |
|
1956 | - * eg PO Box 123 |
|
1957 | - */ |
|
1958 | - public $address_2 = ''; |
|
1959 | - |
|
1960 | - /** |
|
1961 | - * @var string $city |
|
1962 | - * eg Inna City |
|
1963 | - */ |
|
1964 | - public $city = ''; |
|
1965 | - |
|
1966 | - /** |
|
1967 | - * @var int $STA_ID |
|
1968 | - * eg 4 |
|
1969 | - */ |
|
1970 | - public $STA_ID = 0; |
|
1971 | - |
|
1972 | - /** |
|
1973 | - * @var string $CNT_ISO |
|
1974 | - * eg US |
|
1975 | - */ |
|
1976 | - public $CNT_ISO = 'US'; |
|
1977 | - |
|
1978 | - /** |
|
1979 | - * @var string $zip |
|
1980 | - * eg 12345 or V1A 2B3 |
|
1981 | - */ |
|
1982 | - public $zip = ''; |
|
1983 | - |
|
1984 | - /** |
|
1985 | - * @var string $email |
|
1986 | - * eg [email protected] |
|
1987 | - */ |
|
1988 | - public $email; |
|
1989 | - |
|
1990 | - /** |
|
1991 | - * @var string $phone |
|
1992 | - * eg. 111-111-1111 |
|
1993 | - */ |
|
1994 | - public $phone = ''; |
|
1995 | - |
|
1996 | - /** |
|
1997 | - * @var string $vat |
|
1998 | - * VAT/Tax Number |
|
1999 | - */ |
|
2000 | - public $vat = ''; |
|
2001 | - |
|
2002 | - /** |
|
2003 | - * @var string $logo_url |
|
2004 | - * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg |
|
2005 | - */ |
|
2006 | - public $logo_url = ''; |
|
2007 | - |
|
2008 | - /** |
|
2009 | - * The below are all various properties for holding links to organization social network profiles |
|
2010 | - */ |
|
2011 | - /** |
|
2012 | - * facebook (facebook.com/profile.name) |
|
2013 | - * |
|
2014 | - * @var string |
|
2015 | - */ |
|
2016 | - public $facebook = ''; |
|
2017 | - |
|
2018 | - /** |
|
2019 | - * twitter (twitter.com/twitter_handle) |
|
2020 | - * |
|
2021 | - * @var string |
|
2022 | - */ |
|
2023 | - public $twitter = ''; |
|
2024 | - |
|
2025 | - /** |
|
2026 | - * linkedin (linkedin.com/in/profile_name) |
|
2027 | - * |
|
2028 | - * @var string |
|
2029 | - */ |
|
2030 | - public $linkedin = ''; |
|
2031 | - |
|
2032 | - /** |
|
2033 | - * pinterest (www.pinterest.com/profile_name) |
|
2034 | - * |
|
2035 | - * @var string |
|
2036 | - */ |
|
2037 | - public $pinterest = ''; |
|
2038 | - |
|
2039 | - /** |
|
2040 | - * google+ (google.com/+profileName) |
|
2041 | - * |
|
2042 | - * @var string |
|
2043 | - */ |
|
2044 | - public $google = ''; |
|
2045 | - |
|
2046 | - /** |
|
2047 | - * instagram (instagram.com/handle) |
|
2048 | - * |
|
2049 | - * @var string |
|
2050 | - */ |
|
2051 | - public $instagram = ''; |
|
2052 | - |
|
2053 | - |
|
2054 | - /** |
|
2055 | - * class constructor |
|
2056 | - * |
|
2057 | - * @access public |
|
2058 | - */ |
|
2059 | - public function __construct() |
|
2060 | - { |
|
2061 | - // set default organization settings |
|
2062 | - // decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded |
|
2063 | - $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
|
2064 | - $this->email = get_bloginfo('admin_email'); |
|
2065 | - } |
|
2066 | -} |
|
2067 | - |
|
2068 | -/** |
|
2069 | - * Class for defining what's in the EE_Config relating to currency |
|
2070 | - */ |
|
2071 | -class EE_Currency_Config extends EE_Config_Base |
|
2072 | -{ |
|
2073 | - /** |
|
2074 | - * @var string $code |
|
2075 | - * eg 'US' |
|
2076 | - */ |
|
2077 | - public $code; |
|
2078 | - |
|
2079 | - /** |
|
2080 | - * @var string $name |
|
2081 | - * eg 'Dollar' |
|
2082 | - */ |
|
2083 | - public $name; |
|
2084 | - |
|
2085 | - /** |
|
2086 | - * plural name |
|
2087 | - * |
|
2088 | - * @var string $plural |
|
2089 | - * eg 'Dollars' |
|
2090 | - */ |
|
2091 | - public $plural; |
|
2092 | - |
|
2093 | - /** |
|
2094 | - * currency sign |
|
2095 | - * |
|
2096 | - * @var string $sign |
|
2097 | - * eg '$' |
|
2098 | - */ |
|
2099 | - public $sign; |
|
2100 | - |
|
2101 | - /** |
|
2102 | - * Whether the currency sign should come before the number or not |
|
2103 | - * |
|
2104 | - * @var boolean $sign_b4 |
|
2105 | - */ |
|
2106 | - public $sign_b4; |
|
2107 | - |
|
2108 | - /** |
|
2109 | - * How many digits should come after the decimal place |
|
2110 | - * |
|
2111 | - * @var int $dec_plc |
|
2112 | - */ |
|
2113 | - public $dec_plc; |
|
2114 | - |
|
2115 | - /** |
|
2116 | - * Symbol to use for decimal mark |
|
2117 | - * |
|
2118 | - * @var string $dec_mrk |
|
2119 | - * eg '.' |
|
2120 | - */ |
|
2121 | - public $dec_mrk; |
|
2122 | - |
|
2123 | - /** |
|
2124 | - * Symbol to use for thousands |
|
2125 | - * |
|
2126 | - * @var string $thsnds |
|
2127 | - * eg ',' |
|
2128 | - */ |
|
2129 | - public $thsnds; |
|
2130 | - |
|
2131 | - |
|
2132 | - /** |
|
2133 | - * @param string|null $CNT_ISO |
|
2134 | - * @throws EE_Error |
|
2135 | - * @throws ReflectionException |
|
2136 | - */ |
|
2137 | - public function __construct(?string $CNT_ISO = 'US') |
|
2138 | - { |
|
2139 | - if ($CNT_ISO && $CNT_ISO === $this->code) { |
|
2140 | - return; |
|
2141 | - } |
|
2142 | - // get country code from organization settings or use default |
|
2143 | - $ORG_CNT = isset(EE_Registry::instance()->CFG->organization) |
|
2144 | - && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
2145 | - ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
2146 | - : 'US'; |
|
2147 | - // but override if requested |
|
2148 | - $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
|
2149 | - // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists |
|
2150 | - $this->setCurrency($CNT_ISO); |
|
2151 | - // fallback to hardcoded defaults, in case the above failed |
|
2152 | - if (empty($this->code)) { |
|
2153 | - $this->setFallbackCurrency(); |
|
2154 | - } |
|
2155 | - } |
|
2156 | - |
|
2157 | - |
|
2158 | - /** |
|
2159 | - * @param string|null $CNT_ISO |
|
2160 | - * @throws EE_Error |
|
2161 | - * @throws ReflectionException |
|
2162 | - */ |
|
2163 | - public function setCurrency(?string $CNT_ISO = 'US') |
|
2164 | - { |
|
2165 | - if (empty($CNT_ISO) || DbStatus::isOffline()) { |
|
2166 | - return; |
|
2167 | - } |
|
2168 | - |
|
2169 | - /** @var TableAnalysis $table_analysis */ |
|
2170 | - $table_analysis = EE_Registry::instance()->create('TableAnalysis', [], true); |
|
2171 | - if (! $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())) { |
|
2172 | - return; |
|
2173 | - } |
|
2174 | - // retrieve the country settings from the db, just in case they have been customized |
|
2175 | - $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
2176 | - if (! $country instanceof EE_Country) { |
|
2177 | - throw new DomainException( |
|
2178 | - sprintf( |
|
2179 | - esc_html__('Invalid Country ISO Code: %1$s', 'event_espresso'), |
|
2180 | - $CNT_ISO |
|
2181 | - ) |
|
2182 | - ); |
|
2183 | - } |
|
2184 | - $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
2185 | - $this->name = $country->currency_name_single(); // Dollar |
|
2186 | - $this->plural = $country->currency_name_plural(); // Dollars |
|
2187 | - $this->sign = $country->currency_sign(); // currency sign: $ |
|
2188 | - $this->sign_b4 = $country->currency_sign_before(); // currency sign before or after |
|
2189 | - $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
2190 | - $this->dec_mrk = $country->currency_decimal_mark(); // decimal mark: ',' = 0,01 or '.' = 0.01 |
|
2191 | - $this->thsnds = $country->currency_thousands_separator(); // thousands sep: ',' = 1,000 or '.' = 1.000 |
|
2192 | - } |
|
2193 | - |
|
2194 | - |
|
2195 | - private function setFallbackCurrency() |
|
2196 | - { |
|
2197 | - // set default currency settings |
|
2198 | - $this->code = 'USD'; |
|
2199 | - $this->name = esc_html__('Dollar', 'event_espresso'); |
|
2200 | - $this->plural = esc_html__('Dollars', 'event_espresso'); |
|
2201 | - $this->sign = '$'; |
|
2202 | - $this->sign_b4 = true; |
|
2203 | - $this->dec_plc = 2; |
|
2204 | - $this->dec_mrk = '.'; |
|
2205 | - $this->thsnds = ','; |
|
2206 | - } |
|
2207 | - |
|
2208 | - |
|
2209 | - /** |
|
2210 | - * @param string|null $CNT_ISO |
|
2211 | - * @return EE_Currency_Config |
|
2212 | - * @throws EE_Error |
|
2213 | - * @throws ReflectionException |
|
2214 | - */ |
|
2215 | - public static function getCurrencyConfig(?string $CNT_ISO = ''): EE_Currency_Config |
|
2216 | - { |
|
2217 | - // if CNT_ISO passed lets try to get currency settings for it. |
|
2218 | - $currency_config = ! empty($CNT_ISO) |
|
2219 | - ? new EE_Currency_Config($CNT_ISO) |
|
2220 | - : null; |
|
2221 | - // default currency settings for site if not set |
|
2222 | - if ($currency_config instanceof EE_Currency_Config) { |
|
2223 | - return $currency_config; |
|
2224 | - } |
|
2225 | - EE_Config::instance()->currency = EE_Config::instance()->currency instanceof EE_Currency_Config |
|
2226 | - ? EE_Config::instance()->currency |
|
2227 | - : new EE_Currency_Config(); |
|
2228 | - return EE_Config::instance()->currency; |
|
2229 | - } |
|
2230 | -} |
|
2231 | - |
|
2232 | -/** |
|
2233 | - * Class for defining what's in the EE_Config relating to registration settings |
|
2234 | - */ |
|
2235 | -class EE_Registration_Config extends EE_Config_Base |
|
2236 | -{ |
|
2237 | - /** |
|
2238 | - * Default registration status |
|
2239 | - * |
|
2240 | - * @var string $default_STS_ID |
|
2241 | - * eg 'RPP' |
|
2242 | - */ |
|
2243 | - public $default_STS_ID; |
|
2244 | - |
|
2245 | - /** |
|
2246 | - * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of |
|
2247 | - * registrations) |
|
2248 | - * |
|
2249 | - * @var int |
|
2250 | - */ |
|
2251 | - public $default_maximum_number_of_tickets; |
|
2252 | - |
|
2253 | - /** |
|
2254 | - * level of validation to apply to email addresses |
|
2255 | - * |
|
2256 | - * @var string $email_validation_level |
|
2257 | - * options: 'basic', 'wp_default', 'i18n', 'i18n_dns' |
|
2258 | - */ |
|
2259 | - public $email_validation_level; |
|
2260 | - |
|
2261 | - /** |
|
2262 | - * whether to show alternate payment options during the reg process if payment status is pending |
|
2263 | - * |
|
2264 | - * @var boolean $show_pending_payment_options |
|
2265 | - */ |
|
2266 | - public $show_pending_payment_options; |
|
2267 | - |
|
2268 | - /** |
|
2269 | - * an array of SPCO reg steps where: |
|
2270 | - * the keys denotes the reg step order |
|
2271 | - * each element consists of an array with the following elements: |
|
2272 | - * "file_path" => the file path to the EE_SPCO_Reg_Step class |
|
2273 | - * "class_name" => the specific EE_SPCO_Reg_Step child class name |
|
2274 | - * "slug" => the URL param used to trigger the reg step |
|
2275 | - * |
|
2276 | - * @var array $reg_steps |
|
2277 | - */ |
|
2278 | - public $reg_steps; |
|
2279 | - |
|
2280 | - /** |
|
2281 | - * Whether registration confirmation should be the last page of SPCO |
|
2282 | - * |
|
2283 | - * @var boolean $reg_confirmation_last |
|
2284 | - */ |
|
2285 | - public $reg_confirmation_last; |
|
2286 | - |
|
2287 | - /** |
|
2288 | - * Whether to enable the EE Bot Trap |
|
2289 | - * |
|
2290 | - * @var boolean $use_bot_trap |
|
2291 | - */ |
|
2292 | - public $use_bot_trap; |
|
2293 | - |
|
2294 | - /** |
|
2295 | - * Whether to encrypt some data sent by the EE Bot Trap |
|
2296 | - * |
|
2297 | - * @var boolean $use_encryption |
|
2298 | - */ |
|
2299 | - public $use_encryption; |
|
2300 | - |
|
2301 | - /** |
|
2302 | - * Whether to use ReCaptcha |
|
2303 | - * |
|
2304 | - * @var boolean $use_captcha |
|
2305 | - */ |
|
2306 | - public $use_captcha; |
|
2307 | - |
|
2308 | - /** |
|
2309 | - * ReCaptcha Theme |
|
2310 | - * |
|
2311 | - * @var string $recaptcha_theme |
|
2312 | - * options: 'dark', 'light', 'invisible' |
|
2313 | - */ |
|
2314 | - public $recaptcha_theme; |
|
2315 | - |
|
2316 | - /** |
|
2317 | - * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha. |
|
2318 | - * |
|
2319 | - * @var string $recaptcha_badge |
|
2320 | - * options: 'bottomright', 'bottomleft', 'inline' |
|
2321 | - */ |
|
2322 | - public $recaptcha_badge; |
|
2323 | - |
|
2324 | - /** |
|
2325 | - * ReCaptcha Type |
|
2326 | - * |
|
2327 | - * @var string $recaptcha_type |
|
2328 | - * options: 'audio', 'image' |
|
2329 | - */ |
|
2330 | - public $recaptcha_type; |
|
2331 | - |
|
2332 | - /** |
|
2333 | - * ReCaptcha language |
|
2334 | - * |
|
2335 | - * @var string $recaptcha_language |
|
2336 | - * eg 'en' |
|
2337 | - */ |
|
2338 | - public $recaptcha_language; |
|
2339 | - |
|
2340 | - /** |
|
2341 | - * ReCaptcha public key |
|
2342 | - * |
|
2343 | - * @var string $recaptcha_publickey |
|
2344 | - */ |
|
2345 | - public $recaptcha_publickey; |
|
2346 | - |
|
2347 | - /** |
|
2348 | - * ReCaptcha private key |
|
2349 | - * |
|
2350 | - * @var string $recaptcha_privatekey |
|
2351 | - */ |
|
2352 | - public $recaptcha_privatekey; |
|
2353 | - |
|
2354 | - /** |
|
2355 | - * array of form names protected by ReCaptcha |
|
2356 | - * |
|
2357 | - * @var array $recaptcha_protected_forms |
|
2358 | - */ |
|
2359 | - public $recaptcha_protected_forms; |
|
23 | + const OPTION_NAME = 'ee_config'; |
|
24 | + |
|
25 | + const LOG_NAME = 'ee_config_log'; |
|
26 | + |
|
27 | + const LOG_LENGTH = 100; |
|
28 | + |
|
29 | + const ADDON_OPTION_NAMES = 'ee_config_option_names'; |
|
30 | + |
|
31 | + /** |
|
32 | + * instance of the EE_Config object |
|
33 | + * |
|
34 | + * @var EE_Config $_instance |
|
35 | + * @access private |
|
36 | + */ |
|
37 | + private static $_instance; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var boolean $_logging_enabled |
|
41 | + */ |
|
42 | + private static $_logging_enabled = false; |
|
43 | + |
|
44 | + /** |
|
45 | + * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
46 | + */ |
|
47 | + private $legacy_shortcodes_manager; |
|
48 | + |
|
49 | + /** |
|
50 | + * An StdClass whose property names are addon slugs, |
|
51 | + * and values are their config classes |
|
52 | + * |
|
53 | + * @var StdClass |
|
54 | + */ |
|
55 | + public $addons; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var EE_Admin_Config |
|
59 | + */ |
|
60 | + public $admin; |
|
61 | + |
|
62 | + /** |
|
63 | + * @var EE_Core_Config |
|
64 | + */ |
|
65 | + public $core; |
|
66 | + |
|
67 | + /** |
|
68 | + * @var EE_Currency_Config |
|
69 | + */ |
|
70 | + public $currency; |
|
71 | + |
|
72 | + /** |
|
73 | + * @var EE_Organization_Config |
|
74 | + */ |
|
75 | + public $organization; |
|
76 | + |
|
77 | + /** |
|
78 | + * @var EE_Registration_Config |
|
79 | + */ |
|
80 | + public $registration; |
|
81 | + |
|
82 | + /** |
|
83 | + * @var EE_Template_Config |
|
84 | + */ |
|
85 | + public $template_settings; |
|
86 | + |
|
87 | + /** |
|
88 | + * Holds EE environment values. |
|
89 | + * |
|
90 | + * @var EE_Environment_Config |
|
91 | + */ |
|
92 | + public $environment; |
|
93 | + |
|
94 | + /** |
|
95 | + * settings pertaining to Google maps |
|
96 | + * |
|
97 | + * @var EE_Map_Config |
|
98 | + */ |
|
99 | + public $map_settings; |
|
100 | + |
|
101 | + /** |
|
102 | + * settings pertaining to Taxes |
|
103 | + * |
|
104 | + * @var EE_Tax_Config |
|
105 | + */ |
|
106 | + public $tax_settings; |
|
107 | + |
|
108 | + /** |
|
109 | + * Settings pertaining to global messages settings. |
|
110 | + * |
|
111 | + * @var EE_Messages_Config |
|
112 | + */ |
|
113 | + public $messages; |
|
114 | + |
|
115 | + /** |
|
116 | + * @deprecated |
|
117 | + * @var EE_Gateway_Config |
|
118 | + */ |
|
119 | + public $gateway; |
|
120 | + |
|
121 | + /** |
|
122 | + * @var array |
|
123 | + */ |
|
124 | + private $_addon_option_names = array(); |
|
125 | + |
|
126 | + /** |
|
127 | + * @var array |
|
128 | + */ |
|
129 | + private static $_module_route_map = array(); |
|
130 | + |
|
131 | + /** |
|
132 | + * @var array |
|
133 | + */ |
|
134 | + private static $_module_forward_map = array(); |
|
135 | + |
|
136 | + /** |
|
137 | + * @var array |
|
138 | + */ |
|
139 | + private static $_module_view_map = array(); |
|
140 | + |
|
141 | + /** |
|
142 | + * @var bool |
|
143 | + */ |
|
144 | + private static $initialized = false; |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * @singleton method used to instantiate class object |
|
149 | + * @access public |
|
150 | + * @return EE_Config instance |
|
151 | + */ |
|
152 | + public static function instance() |
|
153 | + { |
|
154 | + // check if class object is instantiated, and instantiated properly |
|
155 | + if (! self::$_instance instanceof EE_Config) { |
|
156 | + self::$_instance = new self(); |
|
157 | + } |
|
158 | + return self::$_instance; |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * Resets the config |
|
164 | + * |
|
165 | + * @param bool $hard_reset if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE |
|
166 | + * (default) leaves the database alone, and merely resets the EE_Config object to |
|
167 | + * reflect its state in the database |
|
168 | + * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave |
|
169 | + * $_instance as NULL. Useful in case you want to forget about the old instance on |
|
170 | + * EE_Config, but might not be ready to instantiate EE_Config currently (eg if the |
|
171 | + * site was put into maintenance mode) |
|
172 | + * @return EE_Config |
|
173 | + */ |
|
174 | + public static function reset($hard_reset = false, $reinstantiate = true) |
|
175 | + { |
|
176 | + if (self::$_instance instanceof EE_Config) { |
|
177 | + if ($hard_reset) { |
|
178 | + self::$_instance->legacy_shortcodes_manager = null; |
|
179 | + self::$_instance->_addon_option_names = array(); |
|
180 | + self::$_instance->_initialize_config(); |
|
181 | + self::$_instance->update_espresso_config(); |
|
182 | + } |
|
183 | + self::$_instance->update_addon_option_names(); |
|
184 | + } |
|
185 | + self::$_instance = null; |
|
186 | + self::$initialized = false; |
|
187 | + // we don't need to reset the static properties imo because those should |
|
188 | + // only change when a module is added or removed. Currently we don't |
|
189 | + // support removing a module during a request when it previously existed |
|
190 | + if ($reinstantiate) { |
|
191 | + return self::instance(); |
|
192 | + } else { |
|
193 | + return null; |
|
194 | + } |
|
195 | + } |
|
196 | + |
|
197 | + |
|
198 | + private function __construct() |
|
199 | + { |
|
200 | + if (self::$initialized) { |
|
201 | + return; |
|
202 | + } |
|
203 | + self::$initialized = true; |
|
204 | + do_action('AHEE__EE_Config__construct__begin', $this); |
|
205 | + EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false); |
|
206 | + // setup empty config classes |
|
207 | + $this->_initialize_config(); |
|
208 | + // load existing EE site settings |
|
209 | + $this->_load_core_config(); |
|
210 | + // confirm everything loaded correctly and set filtered defaults if not |
|
211 | + $this->_verify_config(); |
|
212 | + // register shortcodes and modules |
|
213 | + add_action( |
|
214 | + 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
215 | + [$this, 'register_shortcodes_and_modules'], |
|
216 | + 999 |
|
217 | + ); |
|
218 | + // initialize shortcodes and modules |
|
219 | + add_action('AHEE__EE_System__core_loaded_and_ready', [$this, 'initialize_shortcodes_and_modules']); |
|
220 | + // register widgets |
|
221 | + add_action('widgets_init', [$this, 'widgets_init'], 10); |
|
222 | + // shutdown |
|
223 | + add_action('shutdown', [$this, 'shutdown'], 10); |
|
224 | + // construct__end hook |
|
225 | + do_action('AHEE__EE_Config__construct__end', $this); |
|
226 | + // hardcoded hack |
|
227 | + $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
228 | + } |
|
229 | + |
|
230 | + |
|
231 | + /** |
|
232 | + * @return boolean |
|
233 | + */ |
|
234 | + public static function logging_enabled() |
|
235 | + { |
|
236 | + return self::$_logging_enabled; |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * use to get the current theme if needed from static context |
|
242 | + * |
|
243 | + * @return string current theme set. |
|
244 | + */ |
|
245 | + public static function get_current_theme() |
|
246 | + { |
|
247 | + return self::$_instance->template_settings->current_espresso_theme ?? 'Espresso_Arabica_2014'; |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + /** |
|
252 | + * _initialize_config |
|
253 | + * |
|
254 | + * @access private |
|
255 | + * @return void |
|
256 | + */ |
|
257 | + private function _initialize_config() |
|
258 | + { |
|
259 | + EE_Config::trim_log(); |
|
260 | + // set defaults |
|
261 | + $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array()); |
|
262 | + $this->addons = new stdClass(); |
|
263 | + // set _module_route_map |
|
264 | + EE_Config::$_module_route_map = array(); |
|
265 | + // set _module_forward_map |
|
266 | + EE_Config::$_module_forward_map = array(); |
|
267 | + // set _module_view_map |
|
268 | + EE_Config::$_module_view_map = array(); |
|
269 | + } |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * load core plugin configuration |
|
274 | + * |
|
275 | + * @access private |
|
276 | + * @return void |
|
277 | + */ |
|
278 | + private function _load_core_config() |
|
279 | + { |
|
280 | + // load_core_config__start hook |
|
281 | + do_action('AHEE__EE_Config___load_core_config__start', $this); |
|
282 | + $espresso_config = (array) $this->get_espresso_config(); |
|
283 | + // need to move the "addons" element to the end of the config array |
|
284 | + // in case an addon config references one of the other config classes |
|
285 | + $addons = $espresso_config['addons'] ?? new StdClass(); |
|
286 | + unset($espresso_config['addons']); |
|
287 | + $espresso_config['addons'] = $addons; |
|
288 | + foreach ($espresso_config as $config => $settings) { |
|
289 | + // load_core_config__start hook |
|
290 | + $settings = apply_filters( |
|
291 | + 'FHEE__EE_Config___load_core_config__config_settings', |
|
292 | + $settings, |
|
293 | + $config, |
|
294 | + $this |
|
295 | + ); |
|
296 | + if (is_object($settings) && property_exists($this, $config)) { |
|
297 | + $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
298 | + // call configs populate method to ensure any defaults are set for empty values. |
|
299 | + if (method_exists($settings, 'populate')) { |
|
300 | + $this->{$config}->populate(); |
|
301 | + } |
|
302 | + if (method_exists($settings, 'do_hooks')) { |
|
303 | + $this->{$config}->do_hooks(); |
|
304 | + } |
|
305 | + } |
|
306 | + } |
|
307 | + if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) { |
|
308 | + $this->update_espresso_config(); |
|
309 | + } |
|
310 | + // load_core_config__end hook |
|
311 | + do_action('AHEE__EE_Config___load_core_config__end', $this); |
|
312 | + } |
|
313 | + |
|
314 | + |
|
315 | + /** |
|
316 | + * _verify_config |
|
317 | + * |
|
318 | + * @access protected |
|
319 | + * @return void |
|
320 | + */ |
|
321 | + protected function _verify_config() |
|
322 | + { |
|
323 | + $this->core = $this->core instanceof EE_Core_Config |
|
324 | + ? $this->core |
|
325 | + : new EE_Core_Config(); |
|
326 | + $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core); |
|
327 | + $this->organization = $this->organization instanceof EE_Organization_Config |
|
328 | + ? $this->organization |
|
329 | + : new EE_Organization_Config(); |
|
330 | + $this->organization = apply_filters( |
|
331 | + 'FHEE__EE_Config___initialize_config__organization', |
|
332 | + $this->organization |
|
333 | + ); |
|
334 | + $this->currency = $this->currency instanceof EE_Currency_Config |
|
335 | + ? $this->currency |
|
336 | + : new EE_Currency_Config(); |
|
337 | + $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency); |
|
338 | + $this->registration = $this->registration instanceof EE_Registration_Config |
|
339 | + ? $this->registration |
|
340 | + : new EE_Registration_Config(); |
|
341 | + $this->registration = apply_filters( |
|
342 | + 'FHEE__EE_Config___initialize_config__registration', |
|
343 | + $this->registration |
|
344 | + ); |
|
345 | + $this->admin = $this->admin instanceof EE_Admin_Config |
|
346 | + ? $this->admin |
|
347 | + : new EE_Admin_Config(); |
|
348 | + $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin); |
|
349 | + $this->template_settings = $this->template_settings instanceof EE_Template_Config |
|
350 | + ? $this->template_settings |
|
351 | + : new EE_Template_Config(); |
|
352 | + $this->template_settings = apply_filters( |
|
353 | + 'FHEE__EE_Config___initialize_config__template_settings', |
|
354 | + $this->template_settings |
|
355 | + ); |
|
356 | + $this->map_settings = $this->map_settings instanceof EE_Map_Config |
|
357 | + ? $this->map_settings |
|
358 | + : new EE_Map_Config(); |
|
359 | + $this->map_settings = apply_filters( |
|
360 | + 'FHEE__EE_Config___initialize_config__map_settings', |
|
361 | + $this->map_settings |
|
362 | + ); |
|
363 | + $this->environment = $this->environment instanceof EE_Environment_Config |
|
364 | + ? $this->environment |
|
365 | + : new EE_Environment_Config(); |
|
366 | + $this->environment = apply_filters( |
|
367 | + 'FHEE__EE_Config___initialize_config__environment', |
|
368 | + $this->environment |
|
369 | + ); |
|
370 | + $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config |
|
371 | + ? $this->tax_settings |
|
372 | + : new EE_Tax_Config(); |
|
373 | + $this->tax_settings = apply_filters( |
|
374 | + 'FHEE__EE_Config___initialize_config__tax_settings', |
|
375 | + $this->tax_settings |
|
376 | + ); |
|
377 | + $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages); |
|
378 | + $this->messages = $this->messages instanceof EE_Messages_Config |
|
379 | + ? $this->messages |
|
380 | + : new EE_Messages_Config(); |
|
381 | + $this->gateway = $this->gateway instanceof EE_Gateway_Config |
|
382 | + ? $this->gateway |
|
383 | + : new EE_Gateway_Config(); |
|
384 | + $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway); |
|
385 | + $this->legacy_shortcodes_manager = null; |
|
386 | + } |
|
387 | + |
|
388 | + |
|
389 | + /** |
|
390 | + * get_espresso_config |
|
391 | + * |
|
392 | + * @access public |
|
393 | + * @return array of espresso config stuff |
|
394 | + */ |
|
395 | + public function get_espresso_config() |
|
396 | + { |
|
397 | + // grab espresso configuration |
|
398 | + return apply_filters( |
|
399 | + 'FHEE__EE_Config__get_espresso_config__CFG', |
|
400 | + get_option(EE_Config::OPTION_NAME, array()) |
|
401 | + ); |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * double_check_config_comparison |
|
407 | + * |
|
408 | + * @access public |
|
409 | + * @param string $option |
|
410 | + * @param $old_value |
|
411 | + * @param $value |
|
412 | + */ |
|
413 | + public function double_check_config_comparison($option, $old_value, $value) |
|
414 | + { |
|
415 | + // make sure we're checking the ee config |
|
416 | + if ($option === EE_Config::OPTION_NAME) { |
|
417 | + // run a loose comparison of the old value against the new value for type and properties, |
|
418 | + // but NOT exact instance like WP update_option does (ie: NOT type safe comparison) |
|
419 | + if ($value != $old_value) { |
|
420 | + // if they are NOT the same, then remove the hook, |
|
421 | + // which means the subsequent update results will be based solely on the update query results |
|
422 | + // the reason we do this is because, as stated above, |
|
423 | + // WP update_option performs an exact instance comparison (===) on any update values passed to it |
|
424 | + // this happens PRIOR to serialization and any subsequent update. |
|
425 | + // If values are found to match their previous old value, |
|
426 | + // then WP bails before performing any update. |
|
427 | + // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version |
|
428 | + // it just pulled from the db, with the one being passed to it (which will not match). |
|
429 | + // HOWEVER, once the object is serialized and passed off to MySQL to update, |
|
430 | + // MySQL MAY ALSO NOT perform the update because |
|
431 | + // the string it sees in the db looks the same as the new one it has been passed!!! |
|
432 | + // This results in the query returning an "affected rows" value of ZERO, |
|
433 | + // which gets returned immediately by WP update_option and looks like an error. |
|
434 | + remove_action('update_option', array($this, 'check_config_updated')); |
|
435 | + } |
|
436 | + } |
|
437 | + } |
|
438 | + |
|
439 | + |
|
440 | + /** |
|
441 | + * update_espresso_config |
|
442 | + * |
|
443 | + * @access public |
|
444 | + */ |
|
445 | + protected function _reset_espresso_addon_config() |
|
446 | + { |
|
447 | + $this->_addon_option_names = array(); |
|
448 | + foreach ($this->addons as $addon_name => $addon_config_obj) { |
|
449 | + $addon_config_obj = maybe_unserialize($addon_config_obj); |
|
450 | + if ($addon_config_obj instanceof EE_Config_Base) { |
|
451 | + $this->update_config('addons', $addon_name, $addon_config_obj, false); |
|
452 | + } |
|
453 | + $this->addons->{$addon_name} = null; |
|
454 | + } |
|
455 | + } |
|
456 | + |
|
457 | + |
|
458 | + /** |
|
459 | + * update_espresso_config |
|
460 | + * |
|
461 | + * @access public |
|
462 | + * @param bool $add_success |
|
463 | + * @param bool $add_error |
|
464 | + * @return bool |
|
465 | + */ |
|
466 | + public function update_espresso_config($add_success = false, $add_error = true) |
|
467 | + { |
|
468 | + // don't allow config updates during WP heartbeats |
|
469 | + /** @var RequestInterface $request */ |
|
470 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
471 | + if ($request->isWordPressHeartbeat()) { |
|
472 | + return false; |
|
473 | + } |
|
474 | + // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197 |
|
475 | + // $clone = clone( self::$_instance ); |
|
476 | + // self::$_instance = NULL; |
|
477 | + do_action('AHEE__EE_Config__update_espresso_config__begin', $this); |
|
478 | + $this->_reset_espresso_addon_config(); |
|
479 | + // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional |
|
480 | + // but BEFORE the actual update occurs |
|
481 | + add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3); |
|
482 | + // don't want to persist legacy_shortcodes_manager, but don't want to lose it either |
|
483 | + $legacy_shortcodes_manager = $this->legacy_shortcodes_manager; |
|
484 | + $this->legacy_shortcodes_manager = null; |
|
485 | + // now update "ee_config" |
|
486 | + $saved = update_option(EE_Config::OPTION_NAME, $this); |
|
487 | + $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
488 | + EE_Config::log(EE_Config::OPTION_NAME); |
|
489 | + // if not saved... check if the hook we just added still exists; |
|
490 | + // if it does, it means one of two things: |
|
491 | + // that update_option bailed at the($value === $old_value) conditional, |
|
492 | + // or... |
|
493 | + // the db update query returned 0 rows affected |
|
494 | + // (probably because the data value was the same from its perspective) |
|
495 | + // so the existence of the hook means that a negative result from update_option is NOT an error, |
|
496 | + // but just means no update occurred, so don't display an error to the user. |
|
497 | + // BUT... if update_option returns FALSE, AND the hook is missing, |
|
498 | + // then it means that something truly went wrong |
|
499 | + $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved; |
|
500 | + // remove our action since we don't want it in the system anymore |
|
501 | + remove_action('update_option', array($this, 'double_check_config_comparison'), 1); |
|
502 | + do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved); |
|
503 | + // self::$_instance = $clone; |
|
504 | + // unset( $clone ); |
|
505 | + // if config remains the same or was updated successfully |
|
506 | + if ($saved) { |
|
507 | + if ($add_success) { |
|
508 | + EE_Error::add_success( |
|
509 | + esc_html__('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'), |
|
510 | + __FILE__, |
|
511 | + __FUNCTION__, |
|
512 | + __LINE__ |
|
513 | + ); |
|
514 | + } |
|
515 | + return true; |
|
516 | + } else { |
|
517 | + if ($add_error) { |
|
518 | + EE_Error::add_error( |
|
519 | + esc_html__('The Event Espresso Configuration Settings were not updated.', 'event_espresso'), |
|
520 | + __FILE__, |
|
521 | + __FUNCTION__, |
|
522 | + __LINE__ |
|
523 | + ); |
|
524 | + } |
|
525 | + return false; |
|
526 | + } |
|
527 | + } |
|
528 | + |
|
529 | + |
|
530 | + /** |
|
531 | + * _verify_config_params |
|
532 | + * |
|
533 | + * @access private |
|
534 | + * @param string $section |
|
535 | + * @param string $name |
|
536 | + * @param string $config_class |
|
537 | + * @param EE_Config_Base $config_obj |
|
538 | + * @param array $tests_to_run |
|
539 | + * @param bool $display_errors |
|
540 | + * @return bool TRUE on success, FALSE on fail |
|
541 | + */ |
|
542 | + private function _verify_config_params( |
|
543 | + $section = '', |
|
544 | + $name = '', |
|
545 | + $config_class = '', |
|
546 | + $config_obj = null, |
|
547 | + $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8), |
|
548 | + $display_errors = true |
|
549 | + ) { |
|
550 | + try { |
|
551 | + foreach ($tests_to_run as $test) { |
|
552 | + switch ($test) { |
|
553 | + // TEST #1 : check that section was set |
|
554 | + case 1: |
|
555 | + if (empty($section)) { |
|
556 | + if ($display_errors) { |
|
557 | + throw new EE_Error( |
|
558 | + sprintf( |
|
559 | + esc_html__( |
|
560 | + 'No configuration section has been provided while attempting to save "%s".', |
|
561 | + 'event_espresso' |
|
562 | + ), |
|
563 | + $config_class |
|
564 | + ) |
|
565 | + ); |
|
566 | + } |
|
567 | + return false; |
|
568 | + } |
|
569 | + break; |
|
570 | + // TEST #2 : check that settings section exists |
|
571 | + case 2: |
|
572 | + if (! isset($this->{$section})) { |
|
573 | + if ($display_errors) { |
|
574 | + throw new EE_Error( |
|
575 | + sprintf( |
|
576 | + esc_html__('The "%s" configuration section does not exist.', 'event_espresso'), |
|
577 | + $section |
|
578 | + ) |
|
579 | + ); |
|
580 | + } |
|
581 | + return false; |
|
582 | + } |
|
583 | + break; |
|
584 | + // TEST #3 : check that section is the proper format |
|
585 | + case 3: |
|
586 | + if ( |
|
587 | + ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
588 | + ) { |
|
589 | + if ($display_errors) { |
|
590 | + throw new EE_Error( |
|
591 | + sprintf( |
|
592 | + esc_html__( |
|
593 | + 'The "%s" configuration settings have not been formatted correctly.', |
|
594 | + 'event_espresso' |
|
595 | + ), |
|
596 | + $section |
|
597 | + ) |
|
598 | + ); |
|
599 | + } |
|
600 | + return false; |
|
601 | + } |
|
602 | + break; |
|
603 | + // TEST #4 : check that config section name has been set |
|
604 | + case 4: |
|
605 | + if (empty($name)) { |
|
606 | + if ($display_errors) { |
|
607 | + throw new EE_Error( |
|
608 | + esc_html__( |
|
609 | + 'No name has been provided for the specific configuration section.', |
|
610 | + 'event_espresso' |
|
611 | + ) |
|
612 | + ); |
|
613 | + } |
|
614 | + return false; |
|
615 | + } |
|
616 | + break; |
|
617 | + // TEST #5 : check that a config class name has been set |
|
618 | + case 5: |
|
619 | + if (empty($config_class)) { |
|
620 | + if ($display_errors) { |
|
621 | + throw new EE_Error( |
|
622 | + esc_html__( |
|
623 | + 'No class name has been provided for the specific configuration section.', |
|
624 | + 'event_espresso' |
|
625 | + ) |
|
626 | + ); |
|
627 | + } |
|
628 | + return false; |
|
629 | + } |
|
630 | + break; |
|
631 | + // TEST #6 : verify config class is accessible |
|
632 | + case 6: |
|
633 | + if (! class_exists($config_class)) { |
|
634 | + if ($display_errors) { |
|
635 | + throw new EE_Error( |
|
636 | + sprintf( |
|
637 | + esc_html__( |
|
638 | + 'The "%s" class does not exist. Please ensure that an autoloader has been set for it.', |
|
639 | + 'event_espresso' |
|
640 | + ), |
|
641 | + $config_class |
|
642 | + ) |
|
643 | + ); |
|
644 | + } |
|
645 | + return false; |
|
646 | + } |
|
647 | + break; |
|
648 | + // TEST #7 : check that config has even been set |
|
649 | + case 7: |
|
650 | + if (! isset($this->{$section}->{$name})) { |
|
651 | + if ($display_errors) { |
|
652 | + throw new EE_Error( |
|
653 | + sprintf( |
|
654 | + esc_html__('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
655 | + $section, |
|
656 | + $name |
|
657 | + ) |
|
658 | + ); |
|
659 | + } |
|
660 | + return false; |
|
661 | + } else { |
|
662 | + // and make sure it's not serialized |
|
663 | + $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name}); |
|
664 | + } |
|
665 | + break; |
|
666 | + // TEST #8 : check that config is the requested type |
|
667 | + case 8: |
|
668 | + if (! $this->{$section}->{$name} instanceof $config_class) { |
|
669 | + if ($display_errors) { |
|
670 | + throw new EE_Error( |
|
671 | + sprintf( |
|
672 | + esc_html__( |
|
673 | + 'The configuration for "%1$s->%2$s" is not of the "%3$s" class.', |
|
674 | + 'event_espresso' |
|
675 | + ), |
|
676 | + $section, |
|
677 | + $name, |
|
678 | + $config_class |
|
679 | + ) |
|
680 | + ); |
|
681 | + } |
|
682 | + return false; |
|
683 | + } |
|
684 | + break; |
|
685 | + // TEST #9 : verify config object |
|
686 | + case 9: |
|
687 | + if (! $config_obj instanceof EE_Config_Base) { |
|
688 | + if ($display_errors) { |
|
689 | + throw new EE_Error( |
|
690 | + sprintf( |
|
691 | + esc_html__('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
692 | + print_r($config_obj, true) |
|
693 | + ) |
|
694 | + ); |
|
695 | + } |
|
696 | + return false; |
|
697 | + } |
|
698 | + break; |
|
699 | + } |
|
700 | + } |
|
701 | + } catch (EE_Error $e) { |
|
702 | + $e->get_error(); |
|
703 | + } |
|
704 | + // you have successfully run the gauntlet |
|
705 | + return true; |
|
706 | + } |
|
707 | + |
|
708 | + |
|
709 | + /** |
|
710 | + * _generate_config_option_name |
|
711 | + * |
|
712 | + * @access protected |
|
713 | + * @param string $section |
|
714 | + * @param string $name |
|
715 | + * @return string |
|
716 | + */ |
|
717 | + private function _generate_config_option_name($section = '', $name = '') |
|
718 | + { |
|
719 | + return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
720 | + } |
|
721 | + |
|
722 | + |
|
723 | + /** |
|
724 | + * _set_config_class |
|
725 | + * ensures that a config class is set, either from a passed config class or one generated from the config name |
|
726 | + * |
|
727 | + * @access private |
|
728 | + * @param string $config_class |
|
729 | + * @param string $name |
|
730 | + * @return string |
|
731 | + */ |
|
732 | + private function _set_config_class($config_class = '', $name = '') |
|
733 | + { |
|
734 | + return ! empty($config_class) |
|
735 | + ? $config_class |
|
736 | + : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
737 | + } |
|
738 | + |
|
739 | + |
|
740 | + /** |
|
741 | + * @param string $section |
|
742 | + * @param string $name |
|
743 | + * @param string $config_class |
|
744 | + * @param EE_Config_Base|null $config_obj |
|
745 | + * @return EE_Config_Base |
|
746 | + */ |
|
747 | + public function set_config( |
|
748 | + string $section = '', |
|
749 | + string $name = '', |
|
750 | + string $config_class = '', |
|
751 | + EE_Config_Base $config_obj = null |
|
752 | + ): ?EE_Config_Base { |
|
753 | + // ensure config class is set to something |
|
754 | + $config_class = $this->_set_config_class($config_class, $name); |
|
755 | + // run tests 1-4, 6, and 7 to verify all config params are set and valid |
|
756 | + if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
757 | + return null; |
|
758 | + } |
|
759 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
760 | + // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
|
761 | + if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
762 | + $this->_addon_option_names[ $config_option_name ] = $config_class; |
|
763 | + $this->update_addon_option_names(); |
|
764 | + } |
|
765 | + // verify the incoming config object but suppress errors |
|
766 | + if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
767 | + $config_obj = new $config_class(); |
|
768 | + } |
|
769 | + if (get_option($config_option_name)) { |
|
770 | + EE_Config::log($config_option_name); |
|
771 | + try { |
|
772 | + update_option($config_option_name, $config_obj); |
|
773 | + } catch (Exception $exception) { |
|
774 | + throw new DomainException( |
|
775 | + sprintf( |
|
776 | + esc_html__( |
|
777 | + 'The following exception occurred while attempting to update the "%1$s" class for config section "%2$s->%3$s": %4$s', |
|
778 | + 'event_espresso' |
|
779 | + ), |
|
780 | + $config_class, |
|
781 | + $section, |
|
782 | + $name, |
|
783 | + $exception->getMessage() |
|
784 | + ) |
|
785 | + ); |
|
786 | + } |
|
787 | + $this->{$section}->{$name} = $config_obj; |
|
788 | + return $this->{$section}->{$name}; |
|
789 | + } else { |
|
790 | + // create a wp-option for this config |
|
791 | + if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
792 | + $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
793 | + return $this->{$section}->{$name}; |
|
794 | + } else { |
|
795 | + EE_Error::add_error( |
|
796 | + sprintf(esc_html__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
797 | + __FILE__, |
|
798 | + __FUNCTION__, |
|
799 | + __LINE__ |
|
800 | + ); |
|
801 | + return null; |
|
802 | + } |
|
803 | + } |
|
804 | + } |
|
805 | + |
|
806 | + |
|
807 | + /** |
|
808 | + * update_config |
|
809 | + * Important: the config object must ALREADY be set, otherwise this will produce an error. |
|
810 | + * |
|
811 | + * @access public |
|
812 | + * @param string $section |
|
813 | + * @param string $name |
|
814 | + * @param EE_Config_Base|string $config_obj |
|
815 | + * @param bool $throw_errors |
|
816 | + * @return bool |
|
817 | + */ |
|
818 | + public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) |
|
819 | + { |
|
820 | + // don't allow config updates during WP heartbeats |
|
821 | + /** @var RequestInterface $request */ |
|
822 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
823 | + if ($request->isWordPressHeartbeat()) { |
|
824 | + return false; |
|
825 | + } |
|
826 | + $config_obj = maybe_unserialize($config_obj); |
|
827 | + // get class name of the incoming object |
|
828 | + $config_class = get_class($config_obj); |
|
829 | + // run tests 1-5 and 9 to verify config |
|
830 | + if ( |
|
831 | + ! $this->_verify_config_params( |
|
832 | + $section, |
|
833 | + $name, |
|
834 | + $config_class, |
|
835 | + $config_obj, |
|
836 | + array(1, 2, 3, 4, 7, 9) |
|
837 | + ) |
|
838 | + ) { |
|
839 | + return false; |
|
840 | + } |
|
841 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
842 | + // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
|
843 | + if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
844 | + // save new config to db |
|
845 | + if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
846 | + return true; |
|
847 | + } |
|
848 | + } else { |
|
849 | + // first check if the record already exists |
|
850 | + $existing_config = get_option($config_option_name); |
|
851 | + $config_obj = serialize($config_obj); |
|
852 | + // just return if db record is already up-to-date (NOT type safe comparison) |
|
853 | + if ($existing_config == $config_obj) { |
|
854 | + $this->{$section}->{$name} = $config_obj; |
|
855 | + return true; |
|
856 | + } elseif (update_option($config_option_name, $config_obj)) { |
|
857 | + EE_Config::log($config_option_name); |
|
858 | + // update wp-option for this config class |
|
859 | + $this->{$section}->{$name} = $config_obj; |
|
860 | + return true; |
|
861 | + } elseif ($throw_errors) { |
|
862 | + EE_Error::add_error( |
|
863 | + sprintf( |
|
864 | + esc_html__( |
|
865 | + 'The "%1$s" object stored at"%2$s" was not successfully updated in the database.', |
|
866 | + 'event_espresso' |
|
867 | + ), |
|
868 | + $config_class, |
|
869 | + 'EE_Config->' . $section . '->' . $name |
|
870 | + ), |
|
871 | + __FILE__, |
|
872 | + __FUNCTION__, |
|
873 | + __LINE__ |
|
874 | + ); |
|
875 | + } |
|
876 | + } |
|
877 | + return false; |
|
878 | + } |
|
879 | + |
|
880 | + |
|
881 | + /** |
|
882 | + * get_config |
|
883 | + * |
|
884 | + * @access public |
|
885 | + * @param string $section |
|
886 | + * @param string $name |
|
887 | + * @param string $config_class |
|
888 | + * @return mixed EE_Config_Base | NULL |
|
889 | + */ |
|
890 | + public function get_config($section = '', $name = '', $config_class = '') |
|
891 | + { |
|
892 | + // ensure config class is set to something |
|
893 | + $config_class = $this->_set_config_class($config_class, $name); |
|
894 | + // run tests 1-4, 6 and 7 to verify that all params have been set |
|
895 | + if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
896 | + return null; |
|
897 | + } |
|
898 | + // now test if the requested config object exists, but suppress errors |
|
899 | + if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
900 | + // config already exists, so pass it back |
|
901 | + return $this->{$section}->{$name}; |
|
902 | + } |
|
903 | + // load config option from db if it exists |
|
904 | + $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
905 | + // verify the newly retrieved config object, but suppress errors |
|
906 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
907 | + // config is good, so set it and pass it back |
|
908 | + $this->{$section}->{$name} = $config_obj; |
|
909 | + return $this->{$section}->{$name}; |
|
910 | + } |
|
911 | + // oops! $config_obj is not already set and does not exist in the db, so create a new one |
|
912 | + $config_obj = $this->set_config($section, $name, $config_class); |
|
913 | + // verify the newly created config object |
|
914 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
915 | + return $this->{$section}->{$name}; |
|
916 | + } else { |
|
917 | + EE_Error::add_error( |
|
918 | + sprintf(esc_html__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
919 | + __FILE__, |
|
920 | + __FUNCTION__, |
|
921 | + __LINE__ |
|
922 | + ); |
|
923 | + } |
|
924 | + return null; |
|
925 | + } |
|
926 | + |
|
927 | + |
|
928 | + /** |
|
929 | + * get_config_option |
|
930 | + * |
|
931 | + * @access public |
|
932 | + * @param string $config_option_name |
|
933 | + * @return mixed EE_Config_Base | FALSE |
|
934 | + */ |
|
935 | + public function get_config_option($config_option_name = '') |
|
936 | + { |
|
937 | + // retrieve the wp-option for this config class. |
|
938 | + $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
939 | + if (empty($config_option)) { |
|
940 | + EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
941 | + } |
|
942 | + return $config_option; |
|
943 | + } |
|
944 | + |
|
945 | + |
|
946 | + /** |
|
947 | + * log |
|
948 | + * |
|
949 | + * @param string $config_option_name |
|
950 | + */ |
|
951 | + public static function log($config_option_name = '') |
|
952 | + { |
|
953 | + if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
954 | + $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
955 | + /** @var RequestParams $request */ |
|
956 | + $request = LoaderFactory::getLoader()->getShared(RequestParams::class); |
|
957 | + $config_log[ (string) microtime(true) ] = array( |
|
958 | + 'config_name' => $config_option_name, |
|
959 | + 'request' => $request->requestParams(), |
|
960 | + ); |
|
961 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
962 | + } |
|
963 | + } |
|
964 | + |
|
965 | + |
|
966 | + /** |
|
967 | + * trim_log |
|
968 | + * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
|
969 | + */ |
|
970 | + public static function trim_log() |
|
971 | + { |
|
972 | + if (! EE_Config::logging_enabled()) { |
|
973 | + return; |
|
974 | + } |
|
975 | + $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
976 | + $log_length = count($config_log); |
|
977 | + if ($log_length > EE_Config::LOG_LENGTH) { |
|
978 | + ksort($config_log); |
|
979 | + $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
980 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
981 | + } |
|
982 | + } |
|
983 | + |
|
984 | + |
|
985 | + /** |
|
986 | + * get_page_for_posts |
|
987 | + * if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the |
|
988 | + * wp-option "page_for_posts", or "posts" if no page is selected |
|
989 | + * |
|
990 | + * @access public |
|
991 | + * @return string |
|
992 | + */ |
|
993 | + public static function get_page_for_posts() |
|
994 | + { |
|
995 | + $page_for_posts = get_option('page_for_posts'); |
|
996 | + if (! $page_for_posts) { |
|
997 | + return 'posts'; |
|
998 | + } |
|
999 | + global $wpdb; |
|
1000 | + $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
1001 | + return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
1002 | + } |
|
1003 | + |
|
1004 | + |
|
1005 | + /** |
|
1006 | + * register_shortcodes_and_modules. |
|
1007 | + * At this point, it's too early to tell if we're maintenance mode or not. |
|
1008 | + * In fact, this is where we give modules a chance to let core know they exist |
|
1009 | + * so they can help trigger maintenance mode if it's needed |
|
1010 | + * |
|
1011 | + * @access public |
|
1012 | + * @return void |
|
1013 | + */ |
|
1014 | + public function register_shortcodes_and_modules() |
|
1015 | + { |
|
1016 | + // allow modules to set hooks for the rest of the system |
|
1017 | + EE_Registry::instance()->modules = $this->_register_modules(); |
|
1018 | + } |
|
1019 | + |
|
1020 | + |
|
1021 | + /** |
|
1022 | + * initialize_shortcodes_and_modules |
|
1023 | + * meaning they can start adding their hooks to get stuff done |
|
1024 | + * |
|
1025 | + * @access public |
|
1026 | + * @return void |
|
1027 | + */ |
|
1028 | + public function initialize_shortcodes_and_modules() |
|
1029 | + { |
|
1030 | + // allow modules to set hooks for the rest of the system |
|
1031 | + $this->_initialize_modules(); |
|
1032 | + } |
|
1033 | + |
|
1034 | + |
|
1035 | + /** |
|
1036 | + * widgets_init |
|
1037 | + * |
|
1038 | + * @access private |
|
1039 | + * @return void |
|
1040 | + */ |
|
1041 | + public function widgets_init() |
|
1042 | + { |
|
1043 | + // only init widgets on admin pages when not in complete maintenance, and |
|
1044 | + // on frontend when not in any maintenance mode |
|
1045 | + if ( |
|
1046 | + MaintenanceStatus::isDisabled() |
|
1047 | + || (is_admin() && MaintenanceStatus::isNotFullSite()) |
|
1048 | + ) { |
|
1049 | + // grab list of installed widgets |
|
1050 | + $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
1051 | + // filter list of modules to register |
|
1052 | + $widgets_to_register = apply_filters( |
|
1053 | + 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
1054 | + $widgets_to_register |
|
1055 | + ); |
|
1056 | + if (! empty($widgets_to_register)) { |
|
1057 | + // cycle thru widget folders |
|
1058 | + foreach ($widgets_to_register as $widget_path) { |
|
1059 | + // add to list of installed widget modules |
|
1060 | + EE_Config::register_ee_widget($widget_path); |
|
1061 | + } |
|
1062 | + } |
|
1063 | + // filter list of installed modules |
|
1064 | + EE_Registry::instance()->widgets = apply_filters( |
|
1065 | + 'FHEE__EE_Config__register_widgets__installed_widgets', |
|
1066 | + EE_Registry::instance()->widgets |
|
1067 | + ); |
|
1068 | + } |
|
1069 | + } |
|
1070 | + |
|
1071 | + |
|
1072 | + /** |
|
1073 | + * register_ee_widget - makes core aware of this widget |
|
1074 | + * |
|
1075 | + * @access public |
|
1076 | + * @param string $widget_path - full path up to and including widget folder |
|
1077 | + * @return void |
|
1078 | + */ |
|
1079 | + public static function register_ee_widget($widget_path = null) |
|
1080 | + { |
|
1081 | + do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
1082 | + $widget_ext = '.widget.php'; |
|
1083 | + // make all separators match |
|
1084 | + $widget_path = rtrim(str_replace('\\', DS, $widget_path), DS); |
|
1085 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
1086 | + if (strpos($widget_path, $widget_ext) !== false) { |
|
1087 | + // grab and shortcode file name from directory name and break apart at dots |
|
1088 | + $file_name = explode('.', basename($widget_path)); |
|
1089 | + // take first segment from file name pieces and remove class prefix if it exists |
|
1090 | + $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
1091 | + // sanitize shortcode directory name |
|
1092 | + $widget = sanitize_key($widget); |
|
1093 | + // now we need to rebuild the shortcode path |
|
1094 | + $widget_path = explode('/', $widget_path); |
|
1095 | + // remove last segment |
|
1096 | + array_pop($widget_path); |
|
1097 | + // glue it back together |
|
1098 | + $widget_path = implode(DS, $widget_path); |
|
1099 | + } else { |
|
1100 | + // grab and sanitize widget directory name |
|
1101 | + $widget = sanitize_key(basename($widget_path)); |
|
1102 | + } |
|
1103 | + // create classname from widget directory name |
|
1104 | + $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
1105 | + // add class prefix |
|
1106 | + $widget_class = 'EEW_' . $widget; |
|
1107 | + // does the widget exist ? |
|
1108 | + if (! is_readable($widget_path . '/' . $widget_class . $widget_ext)) { |
|
1109 | + $msg = sprintf( |
|
1110 | + esc_html__( |
|
1111 | + 'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
|
1112 | + 'event_espresso' |
|
1113 | + ), |
|
1114 | + $widget_class, |
|
1115 | + $widget_path . '/' . $widget_class . $widget_ext |
|
1116 | + ); |
|
1117 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1118 | + return; |
|
1119 | + } |
|
1120 | + // load the widget class file |
|
1121 | + require_once($widget_path . '/' . $widget_class . $widget_ext); |
|
1122 | + // verify that class exists |
|
1123 | + if (! class_exists($widget_class)) { |
|
1124 | + $msg = sprintf(esc_html__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
1125 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1126 | + return; |
|
1127 | + } |
|
1128 | + register_widget($widget_class); |
|
1129 | + // add to array of registered widgets |
|
1130 | + EE_Registry::instance()->widgets->{$widget_class} = $widget_path . '/' . $widget_class . $widget_ext; |
|
1131 | + } |
|
1132 | + |
|
1133 | + |
|
1134 | + /** |
|
1135 | + * _register_modules |
|
1136 | + * |
|
1137 | + * @access private |
|
1138 | + * @return array |
|
1139 | + */ |
|
1140 | + private function _register_modules() |
|
1141 | + { |
|
1142 | + // grab list of installed modules |
|
1143 | + $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
1144 | + // filter list of modules to register |
|
1145 | + $modules_to_register = apply_filters( |
|
1146 | + 'FHEE__EE_Config__register_modules__modules_to_register', |
|
1147 | + $modules_to_register |
|
1148 | + ); |
|
1149 | + if (! empty($modules_to_register)) { |
|
1150 | + // loop through folders |
|
1151 | + foreach ($modules_to_register as $module_path) { |
|
1152 | + /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
|
1153 | + if ( |
|
1154 | + $module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
1155 | + && $module_path !== EE_MODULES . 'gateways' |
|
1156 | + ) { |
|
1157 | + // add to list of installed modules |
|
1158 | + EE_Config::register_module($module_path); |
|
1159 | + } |
|
1160 | + } |
|
1161 | + } |
|
1162 | + // filter list of installed modules |
|
1163 | + return apply_filters( |
|
1164 | + 'FHEE__EE_Config___register_modules__installed_modules', |
|
1165 | + EE_Registry::instance()->modules |
|
1166 | + ); |
|
1167 | + } |
|
1168 | + |
|
1169 | + |
|
1170 | + /** |
|
1171 | + * register_module - makes core aware of this module |
|
1172 | + * |
|
1173 | + * @access public |
|
1174 | + * @param string $module_path - full path up to and including module folder |
|
1175 | + * @return bool |
|
1176 | + */ |
|
1177 | + public static function register_module($module_path = null) |
|
1178 | + { |
|
1179 | + do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
1180 | + $module_ext = '.module.php'; |
|
1181 | + // make all separators match |
|
1182 | + $module_path = str_replace(array('\\', '/'), '/', $module_path); |
|
1183 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
1184 | + if (strpos($module_path, $module_ext) !== false) { |
|
1185 | + // grab and shortcode file name from directory name and break apart at dots |
|
1186 | + $module_file = explode('.', basename($module_path)); |
|
1187 | + // now we need to rebuild the shortcode path |
|
1188 | + $module_path = explode('/', $module_path); |
|
1189 | + // remove last segment |
|
1190 | + array_pop($module_path); |
|
1191 | + // glue it back together |
|
1192 | + $module_path = implode('/', $module_path) . '/'; |
|
1193 | + // take first segment from file name pieces and sanitize it |
|
1194 | + $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
1195 | + // ensure class prefix is added |
|
1196 | + $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
1197 | + } else { |
|
1198 | + // we need to generate the filename based off of the folder name |
|
1199 | + // grab and sanitize module name |
|
1200 | + $module = strtolower(basename($module_path)); |
|
1201 | + $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
1202 | + // like trailingslashit() |
|
1203 | + $module_path = rtrim($module_path, '/') . '/'; |
|
1204 | + // create classname from module directory name |
|
1205 | + $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
1206 | + // add class prefix |
|
1207 | + $module_class = 'EED_' . $module; |
|
1208 | + } |
|
1209 | + // does the module exist ? |
|
1210 | + if (! is_readable($module_path . '/' . $module_class . $module_ext)) { |
|
1211 | + $msg = sprintf( |
|
1212 | + esc_html__( |
|
1213 | + 'The requested %s module file could not be found or is not readable due to file permissions.', |
|
1214 | + 'event_espresso' |
|
1215 | + ), |
|
1216 | + $module |
|
1217 | + ); |
|
1218 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1219 | + return false; |
|
1220 | + } |
|
1221 | + // load the module class file |
|
1222 | + require_once($module_path . $module_class . $module_ext); |
|
1223 | + // verify that class exists |
|
1224 | + if (! class_exists($module_class)) { |
|
1225 | + $msg = sprintf(esc_html__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
1226 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1227 | + return false; |
|
1228 | + } |
|
1229 | + // add to array of registered modules |
|
1230 | + EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
1231 | + do_action( |
|
1232 | + 'AHEE__EE_Config__register_module__complete', |
|
1233 | + $module_class, |
|
1234 | + EE_Registry::instance()->modules->{$module_class} |
|
1235 | + ); |
|
1236 | + return true; |
|
1237 | + } |
|
1238 | + |
|
1239 | + |
|
1240 | + /** |
|
1241 | + * _initialize_modules |
|
1242 | + * allow modules to set hooks for the rest of the system |
|
1243 | + * |
|
1244 | + * @access private |
|
1245 | + * @return void |
|
1246 | + */ |
|
1247 | + private function _initialize_modules() |
|
1248 | + { |
|
1249 | + // cycle thru shortcode folders |
|
1250 | + foreach (EE_Registry::instance()->modules as $module_class => $module_path) { |
|
1251 | + // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
1252 | + // which set hooks ? |
|
1253 | + if (is_admin() && is_callable([$module_class, 'set_hooks_admin'])) { |
|
1254 | + // fire immediately |
|
1255 | + call_user_func([$module_class, 'set_hooks_admin']); |
|
1256 | + } else { |
|
1257 | + // delay until other systems are online |
|
1258 | + add_action( |
|
1259 | + 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
1260 | + array($module_class, 'set_hooks') |
|
1261 | + ); |
|
1262 | + } |
|
1263 | + } |
|
1264 | + } |
|
1265 | + |
|
1266 | + |
|
1267 | + /** |
|
1268 | + * register_route - adds module method routes to route_map |
|
1269 | + * |
|
1270 | + * @access public |
|
1271 | + * @param string $route - "pretty" public alias for module method |
|
1272 | + * @param string $module - module name (classname without EED_ prefix) |
|
1273 | + * @param string $method_name - the actual module method to be routed to |
|
1274 | + * @param string $key - url param key indicating a route is being called |
|
1275 | + * @return bool |
|
1276 | + */ |
|
1277 | + public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') |
|
1278 | + { |
|
1279 | + do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
1280 | + $module = str_replace('EED_', '', $module); |
|
1281 | + $module_class = 'EED_' . $module; |
|
1282 | + if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
1283 | + $msg = sprintf(esc_html__('The module %s has not been registered.', 'event_espresso'), $module); |
|
1284 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1285 | + return false; |
|
1286 | + } |
|
1287 | + if (empty($route)) { |
|
1288 | + $msg = sprintf(esc_html__('No route has been supplied.', 'event_espresso'), $route); |
|
1289 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1290 | + return false; |
|
1291 | + } |
|
1292 | + if (! method_exists('EED_' . $module, $method_name)) { |
|
1293 | + $msg = sprintf( |
|
1294 | + esc_html__('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
1295 | + $route |
|
1296 | + ); |
|
1297 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1298 | + return false; |
|
1299 | + } |
|
1300 | + EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name); |
|
1301 | + return true; |
|
1302 | + } |
|
1303 | + |
|
1304 | + |
|
1305 | + /** |
|
1306 | + * get_route - get module method route |
|
1307 | + * |
|
1308 | + * @access public |
|
1309 | + * @param string $route - "pretty" public alias for module method |
|
1310 | + * @param string $key - url param key indicating a route is being called |
|
1311 | + * @return string |
|
1312 | + */ |
|
1313 | + public static function get_route($route = null, $key = 'ee') |
|
1314 | + { |
|
1315 | + do_action('AHEE__EE_Config__get_route__begin', $route); |
|
1316 | + $route = (string) apply_filters('FHEE__EE_Config__get_route', $route); |
|
1317 | + if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) { |
|
1318 | + return EE_Config::$_module_route_map[ $key ][ $route ]; |
|
1319 | + } |
|
1320 | + return null; |
|
1321 | + } |
|
1322 | + |
|
1323 | + |
|
1324 | + /** |
|
1325 | + * get_routes - get ALL module method routes |
|
1326 | + * |
|
1327 | + * @access public |
|
1328 | + * @return array |
|
1329 | + */ |
|
1330 | + public static function get_routes() |
|
1331 | + { |
|
1332 | + return EE_Config::$_module_route_map; |
|
1333 | + } |
|
1334 | + |
|
1335 | + |
|
1336 | + /** |
|
1337 | + * register_forward - allows modules to forward request to another module for further processing |
|
1338 | + * |
|
1339 | + * @access public |
|
1340 | + * @param string $route - "pretty" public alias for module method |
|
1341 | + * @param integer $status - integer value corresponding to status constant strings set in module parent |
|
1342 | + * class, allows different forwards to be served based on status |
|
1343 | + * @param array|string $forward - function name or array( class, method ) |
|
1344 | + * @param string $key - url param key indicating a route is being called |
|
1345 | + * @return bool |
|
1346 | + */ |
|
1347 | + public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
|
1348 | + { |
|
1349 | + do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
1350 | + if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
1351 | + $msg = sprintf( |
|
1352 | + esc_html__('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
1353 | + $route |
|
1354 | + ); |
|
1355 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1356 | + return false; |
|
1357 | + } |
|
1358 | + if (empty($forward)) { |
|
1359 | + $msg = sprintf(esc_html__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
1360 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1361 | + return false; |
|
1362 | + } |
|
1363 | + if (is_array($forward)) { |
|
1364 | + if (! isset($forward[1])) { |
|
1365 | + $msg = sprintf( |
|
1366 | + esc_html__('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
1367 | + $route |
|
1368 | + ); |
|
1369 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1370 | + return false; |
|
1371 | + } |
|
1372 | + if (! method_exists($forward[0], $forward[1])) { |
|
1373 | + $msg = sprintf( |
|
1374 | + esc_html__('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
1375 | + $forward[1], |
|
1376 | + $route |
|
1377 | + ); |
|
1378 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1379 | + return false; |
|
1380 | + } |
|
1381 | + } elseif (! function_exists($forward)) { |
|
1382 | + $msg = sprintf( |
|
1383 | + esc_html__('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
1384 | + $forward, |
|
1385 | + $route |
|
1386 | + ); |
|
1387 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1388 | + return false; |
|
1389 | + } |
|
1390 | + EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward; |
|
1391 | + return true; |
|
1392 | + } |
|
1393 | + |
|
1394 | + |
|
1395 | + /** |
|
1396 | + * get_forward - get forwarding route |
|
1397 | + * |
|
1398 | + * @access public |
|
1399 | + * @param string $route - "pretty" public alias for module method |
|
1400 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
1401 | + * allows different forwards to be served based on status |
|
1402 | + * @param string $key - url param key indicating a route is being called |
|
1403 | + * @return string |
|
1404 | + */ |
|
1405 | + public static function get_forward($route = null, $status = 0, $key = 'ee') |
|
1406 | + { |
|
1407 | + do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
1408 | + if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) { |
|
1409 | + return apply_filters( |
|
1410 | + 'FHEE__EE_Config__get_forward', |
|
1411 | + EE_Config::$_module_forward_map[ $key ][ $route ][ $status ], |
|
1412 | + $route, |
|
1413 | + $status |
|
1414 | + ); |
|
1415 | + } |
|
1416 | + return null; |
|
1417 | + } |
|
1418 | + |
|
1419 | + |
|
1420 | + /** |
|
1421 | + * register_forward - allows modules to specify different view templates for different method routes and status |
|
1422 | + * results |
|
1423 | + * |
|
1424 | + * @access public |
|
1425 | + * @param string $route - "pretty" public alias for module method |
|
1426 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
1427 | + * allows different views to be served based on status |
|
1428 | + * @param string $view |
|
1429 | + * @param string $key - url param key indicating a route is being called |
|
1430 | + * @return bool |
|
1431 | + */ |
|
1432 | + public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
|
1433 | + { |
|
1434 | + do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
1435 | + if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
1436 | + $msg = sprintf( |
|
1437 | + esc_html__('The module route %s for this view has not been registered.', 'event_espresso'), |
|
1438 | + $route |
|
1439 | + ); |
|
1440 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1441 | + return false; |
|
1442 | + } |
|
1443 | + if (! is_readable($view)) { |
|
1444 | + $msg = sprintf( |
|
1445 | + esc_html__( |
|
1446 | + 'The %s view file could not be found or is not readable due to file permissions.', |
|
1447 | + 'event_espresso' |
|
1448 | + ), |
|
1449 | + $view |
|
1450 | + ); |
|
1451 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1452 | + return false; |
|
1453 | + } |
|
1454 | + EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view; |
|
1455 | + return true; |
|
1456 | + } |
|
1457 | + |
|
1458 | + |
|
1459 | + /** |
|
1460 | + * get_view - get view for route and status |
|
1461 | + * |
|
1462 | + * @access public |
|
1463 | + * @param string $route - "pretty" public alias for module method |
|
1464 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
1465 | + * allows different views to be served based on status |
|
1466 | + * @param string $key - url param key indicating a route is being called |
|
1467 | + * @return string |
|
1468 | + */ |
|
1469 | + public static function get_view($route = null, $status = 0, $key = 'ee') |
|
1470 | + { |
|
1471 | + do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
1472 | + if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) { |
|
1473 | + return apply_filters( |
|
1474 | + 'FHEE__EE_Config__get_view', |
|
1475 | + EE_Config::$_module_view_map[ $key ][ $route ][ $status ], |
|
1476 | + $route, |
|
1477 | + $status |
|
1478 | + ); |
|
1479 | + } |
|
1480 | + return null; |
|
1481 | + } |
|
1482 | + |
|
1483 | + |
|
1484 | + public function update_addon_option_names() |
|
1485 | + { |
|
1486 | + update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
1487 | + } |
|
1488 | + |
|
1489 | + |
|
1490 | + public function shutdown() |
|
1491 | + { |
|
1492 | + $this->update_addon_option_names(); |
|
1493 | + } |
|
1494 | + |
|
1495 | + |
|
1496 | + /** |
|
1497 | + * @return LegacyShortcodesManager |
|
1498 | + */ |
|
1499 | + public static function getLegacyShortcodesManager() |
|
1500 | + { |
|
1501 | + if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
1502 | + EE_Config::instance()->legacy_shortcodes_manager = LoaderFactory::getLoader()->getShared( |
|
1503 | + LegacyShortcodesManager::class |
|
1504 | + ); |
|
1505 | + } |
|
1506 | + return EE_Config::instance()->legacy_shortcodes_manager; |
|
1507 | + } |
|
1508 | + |
|
1509 | + |
|
1510 | + /** |
|
1511 | + * register_shortcode - makes core aware of this shortcode |
|
1512 | + * |
|
1513 | + * @deprecated 4.9.26 |
|
1514 | + * @param string $shortcode_path - full path up to and including shortcode folder |
|
1515 | + * @return bool |
|
1516 | + */ |
|
1517 | + public static function register_shortcode($shortcode_path = null) |
|
1518 | + { |
|
1519 | + EE_Error::doing_it_wrong( |
|
1520 | + __METHOD__, |
|
1521 | + esc_html__( |
|
1522 | + 'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.', |
|
1523 | + 'event_espresso' |
|
1524 | + ), |
|
1525 | + '4.9.26' |
|
1526 | + ); |
|
1527 | + return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path); |
|
1528 | + } |
|
1529 | +} |
|
2360 | 1530 | |
2361 | - /** |
|
2362 | - * ReCaptcha width |
|
2363 | - * |
|
2364 | - * @var int $recaptcha_width |
|
2365 | - * @deprecated |
|
2366 | - */ |
|
2367 | - public $recaptcha_width; |
|
1531 | +/** |
|
1532 | + * Base class used for config classes. These classes should generally not have |
|
1533 | + * magic functions in use, except we'll allow them to magically set and get stuff... |
|
1534 | + * basically, they should just be well-defined stdClasses |
|
1535 | + */ |
|
1536 | +class EE_Config_Base |
|
1537 | +{ |
|
1538 | + /** |
|
1539 | + * Utility function for escaping the value of a property and returning. |
|
1540 | + * |
|
1541 | + * @param string $property property name (checks to see if exists). |
|
1542 | + * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
1543 | + * @throws EE_Error |
|
1544 | + */ |
|
1545 | + public function get_pretty($property) |
|
1546 | + { |
|
1547 | + if (! property_exists($this, $property)) { |
|
1548 | + throw new EE_Error( |
|
1549 | + sprintf( |
|
1550 | + esc_html__( |
|
1551 | + '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
|
1552 | + 'event_espresso' |
|
1553 | + ), |
|
1554 | + get_class($this), |
|
1555 | + $property |
|
1556 | + ) |
|
1557 | + ); |
|
1558 | + } |
|
1559 | + // just handling escaping of strings for now. |
|
1560 | + if (is_string($this->{$property})) { |
|
1561 | + return stripslashes($this->{$property}); |
|
1562 | + } |
|
1563 | + return $this->{$property}; |
|
1564 | + } |
|
1565 | + |
|
1566 | + |
|
1567 | + public function populate() |
|
1568 | + { |
|
1569 | + // grab defaults via a new instance of this class. |
|
1570 | + $class_name = get_class($this); |
|
1571 | + $defaults = new $class_name(); |
|
1572 | + // loop through the properties for this class and see if they are set. If they are NOT, then grab the |
|
1573 | + // default from our $defaults object. |
|
1574 | + foreach (get_object_vars($defaults) as $property => $value) { |
|
1575 | + if ($this->{$property} === null) { |
|
1576 | + $this->{$property} = $value; |
|
1577 | + } |
|
1578 | + } |
|
1579 | + // cleanup |
|
1580 | + unset($defaults); |
|
1581 | + } |
|
1582 | + |
|
1583 | + |
|
1584 | + /** |
|
1585 | + * __isset |
|
1586 | + * |
|
1587 | + * @param $a |
|
1588 | + * @return bool |
|
1589 | + */ |
|
1590 | + public function __isset($a) |
|
1591 | + { |
|
1592 | + return false; |
|
1593 | + } |
|
1594 | + |
|
1595 | + |
|
1596 | + /** |
|
1597 | + * __unset |
|
1598 | + * |
|
1599 | + * @param $a |
|
1600 | + * @return bool |
|
1601 | + */ |
|
1602 | + public function __unset($a) |
|
1603 | + { |
|
1604 | + return false; |
|
1605 | + } |
|
1606 | + |
|
1607 | + |
|
1608 | + /** |
|
1609 | + * __clone |
|
1610 | + */ |
|
1611 | + public function __clone() |
|
1612 | + { |
|
1613 | + } |
|
1614 | + |
|
1615 | + |
|
1616 | + /** |
|
1617 | + * __wakeup |
|
1618 | + */ |
|
1619 | + public function __wakeup() |
|
1620 | + { |
|
1621 | + } |
|
1622 | + |
|
1623 | + |
|
1624 | + /** |
|
1625 | + * __destruct |
|
1626 | + */ |
|
1627 | + public function __destruct() |
|
1628 | + { |
|
1629 | + } |
|
1630 | +} |
|
2368 | 1631 | |
2369 | - /** |
|
2370 | - * Whether invalid attempts to directly access the registration checkout page should be tracked. |
|
2371 | - * |
|
2372 | - * @var boolean $track_invalid_checkout_access |
|
2373 | - */ |
|
2374 | - protected $track_invalid_checkout_access = true; |
|
1632 | +/** |
|
1633 | + * Class for defining what's in the EE_Config relating to registration settings |
|
1634 | + */ |
|
1635 | +class EE_Core_Config extends EE_Config_Base |
|
1636 | +{ |
|
1637 | + const OPTION_NAME_UXIP = 'ee_ueip_optin'; |
|
1638 | + |
|
1639 | + |
|
1640 | + public $current_blog_id; |
|
1641 | + |
|
1642 | + public $ee_ueip_optin; |
|
1643 | + |
|
1644 | + public $ee_ueip_has_notified; |
|
1645 | + |
|
1646 | + /** |
|
1647 | + * Not to be confused with the 4 critical page variables (See |
|
1648 | + * get_critical_pages_array()), this is just an array of wp posts that have EE |
|
1649 | + * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode |
|
1650 | + * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array. |
|
1651 | + * |
|
1652 | + * @var array |
|
1653 | + */ |
|
1654 | + public $post_shortcodes; |
|
1655 | + |
|
1656 | + public $module_route_map; |
|
1657 | + |
|
1658 | + public $module_forward_map; |
|
1659 | + |
|
1660 | + public $module_view_map; |
|
1661 | + |
|
1662 | + /** |
|
1663 | + * The next 4 vars are the IDs of critical EE pages. |
|
1664 | + * |
|
1665 | + * @var int |
|
1666 | + */ |
|
1667 | + public $reg_page_id; |
|
1668 | + |
|
1669 | + public $txn_page_id; |
|
1670 | + |
|
1671 | + public $thank_you_page_id; |
|
1672 | + |
|
1673 | + public $cancel_page_id; |
|
1674 | + |
|
1675 | + /** |
|
1676 | + * The next 4 vars are the URLs of critical EE pages. |
|
1677 | + * |
|
1678 | + * @var int |
|
1679 | + */ |
|
1680 | + public $reg_page_url; |
|
1681 | + |
|
1682 | + public $txn_page_url; |
|
1683 | + |
|
1684 | + public $thank_you_page_url; |
|
1685 | + |
|
1686 | + public $cancel_page_url; |
|
1687 | + |
|
1688 | + /** |
|
1689 | + * The next vars relate to the custom slugs for EE CPT routes |
|
1690 | + */ |
|
1691 | + public $event_cpt_slug; |
|
1692 | + |
|
1693 | + /** |
|
1694 | + * This caches the _ee_ueip_option in case this config is reset in the same |
|
1695 | + * request across blog switches in a multisite context. |
|
1696 | + * Avoids extra queries to the db for this option. |
|
1697 | + * |
|
1698 | + * @var bool |
|
1699 | + */ |
|
1700 | + public static $ee_ueip_option; |
|
1701 | + |
|
1702 | + |
|
1703 | + /** |
|
1704 | + * class constructor |
|
1705 | + * |
|
1706 | + * @access public |
|
1707 | + */ |
|
1708 | + public function __construct() |
|
1709 | + { |
|
1710 | + // set default organization settings |
|
1711 | + $this->current_blog_id = get_current_blog_id(); |
|
1712 | + $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id; |
|
1713 | + $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
|
1714 | + $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
1715 | + $this->post_shortcodes = array(); |
|
1716 | + $this->module_route_map = array(); |
|
1717 | + $this->module_forward_map = array(); |
|
1718 | + $this->module_view_map = array(); |
|
1719 | + // critical EE page IDs |
|
1720 | + $this->reg_page_id = 0; |
|
1721 | + $this->txn_page_id = 0; |
|
1722 | + $this->thank_you_page_id = 0; |
|
1723 | + $this->cancel_page_id = 0; |
|
1724 | + // critical EE page URLs |
|
1725 | + $this->reg_page_url = ''; |
|
1726 | + $this->txn_page_url = ''; |
|
1727 | + $this->thank_you_page_url = ''; |
|
1728 | + $this->cancel_page_url = ''; |
|
1729 | + // cpt slugs |
|
1730 | + $this->event_cpt_slug = esc_html__('events', 'event_espresso'); |
|
1731 | + // ueip constant check |
|
1732 | + if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
1733 | + $this->ee_ueip_optin = false; |
|
1734 | + $this->ee_ueip_has_notified = true; |
|
1735 | + } |
|
1736 | + } |
|
1737 | + |
|
1738 | + |
|
1739 | + /** |
|
1740 | + * @return array |
|
1741 | + */ |
|
1742 | + public function get_critical_pages_array() |
|
1743 | + { |
|
1744 | + return array( |
|
1745 | + $this->reg_page_id, |
|
1746 | + $this->txn_page_id, |
|
1747 | + $this->thank_you_page_id, |
|
1748 | + $this->cancel_page_id, |
|
1749 | + ); |
|
1750 | + } |
|
1751 | + |
|
1752 | + |
|
1753 | + /** |
|
1754 | + * @return array |
|
1755 | + */ |
|
1756 | + public function get_critical_pages_shortcodes_array() |
|
1757 | + { |
|
1758 | + return array( |
|
1759 | + $this->reg_page_id => 'ESPRESSO_CHECKOUT', |
|
1760 | + $this->txn_page_id => 'ESPRESSO_TXN_PAGE', |
|
1761 | + $this->thank_you_page_id => 'ESPRESSO_THANK_YOU', |
|
1762 | + $this->cancel_page_id => 'ESPRESSO_CANCELLED', |
|
1763 | + ); |
|
1764 | + } |
|
1765 | + |
|
1766 | + |
|
1767 | + /** |
|
1768 | + * gets/returns URL for EE reg_page |
|
1769 | + * |
|
1770 | + * @access public |
|
1771 | + * @return string |
|
1772 | + */ |
|
1773 | + public function reg_page_url() |
|
1774 | + { |
|
1775 | + if (! $this->reg_page_url) { |
|
1776 | + $this->reg_page_url = add_query_arg( |
|
1777 | + array('uts' => time()), |
|
1778 | + get_permalink($this->reg_page_id) |
|
1779 | + ) . '#checkout'; |
|
1780 | + } |
|
1781 | + return $this->reg_page_url; |
|
1782 | + } |
|
1783 | + |
|
1784 | + |
|
1785 | + /** |
|
1786 | + * gets/returns URL for EE txn_page |
|
1787 | + * |
|
1788 | + * @param array $query_args like what gets passed to |
|
1789 | + * add_query_arg() as the first argument |
|
1790 | + * @access public |
|
1791 | + * @return string |
|
1792 | + */ |
|
1793 | + public function txn_page_url($query_args = array()) |
|
1794 | + { |
|
1795 | + if (! $this->txn_page_url) { |
|
1796 | + $this->txn_page_url = get_permalink($this->txn_page_id); |
|
1797 | + } |
|
1798 | + if ($query_args) { |
|
1799 | + return add_query_arg($query_args, $this->txn_page_url); |
|
1800 | + } else { |
|
1801 | + return $this->txn_page_url; |
|
1802 | + } |
|
1803 | + } |
|
1804 | + |
|
1805 | + |
|
1806 | + /** |
|
1807 | + * gets/returns URL for EE thank_you_page |
|
1808 | + * |
|
1809 | + * @param array $query_args like what gets passed to |
|
1810 | + * add_query_arg() as the first argument |
|
1811 | + * @access public |
|
1812 | + * @return string |
|
1813 | + */ |
|
1814 | + public function thank_you_page_url($query_args = array()) |
|
1815 | + { |
|
1816 | + if (! $this->thank_you_page_url) { |
|
1817 | + $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
1818 | + } |
|
1819 | + if ($query_args) { |
|
1820 | + return add_query_arg($query_args, $this->thank_you_page_url); |
|
1821 | + } else { |
|
1822 | + return $this->thank_you_page_url; |
|
1823 | + } |
|
1824 | + } |
|
1825 | + |
|
1826 | + |
|
1827 | + /** |
|
1828 | + * gets/returns URL for EE cancel_page |
|
1829 | + * |
|
1830 | + * @access public |
|
1831 | + * @return string |
|
1832 | + */ |
|
1833 | + public function cancel_page_url() |
|
1834 | + { |
|
1835 | + if (! $this->cancel_page_url) { |
|
1836 | + $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
1837 | + } |
|
1838 | + return $this->cancel_page_url; |
|
1839 | + } |
|
1840 | + |
|
1841 | + |
|
1842 | + /** |
|
1843 | + * Resets all critical page urls to their original state. Used primarily by the __sleep() magic method currently. |
|
1844 | + * |
|
1845 | + * @since 4.7.5 |
|
1846 | + */ |
|
1847 | + protected function _reset_urls() |
|
1848 | + { |
|
1849 | + $this->reg_page_url = ''; |
|
1850 | + $this->txn_page_url = ''; |
|
1851 | + $this->cancel_page_url = ''; |
|
1852 | + $this->thank_you_page_url = ''; |
|
1853 | + } |
|
1854 | + |
|
1855 | + |
|
1856 | + /** |
|
1857 | + * Used to return what the optin value is set for the EE User Experience Program. |
|
1858 | + * This accounts for multisite and this value being requested for a subsite. In multisite, the value is set |
|
1859 | + * on the main site only. |
|
1860 | + * |
|
1861 | + * @return bool |
|
1862 | + */ |
|
1863 | + protected function _get_main_ee_ueip_optin() |
|
1864 | + { |
|
1865 | + // if this is the main site then we can just bypass our direct query. |
|
1866 | + if (is_main_site()) { |
|
1867 | + return get_option(self::OPTION_NAME_UXIP, false); |
|
1868 | + } |
|
1869 | + // is this already cached for this request? If so use it. |
|
1870 | + if (EE_Core_Config::$ee_ueip_option !== null) { |
|
1871 | + return EE_Core_Config::$ee_ueip_option; |
|
1872 | + } |
|
1873 | + global $wpdb; |
|
1874 | + $current_network_main_site = is_multisite() ? get_current_site() : null; |
|
1875 | + $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
1876 | + $option = self::OPTION_NAME_UXIP; |
|
1877 | + // set correct table for query |
|
1878 | + $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
1879 | + // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
|
1880 | + // get_blog_option() does a switch_to_blog and that could cause infinite recursion because EE_Core_Config might be |
|
1881 | + // re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
|
1882 | + // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
|
1883 | + // for the purpose of caching. |
|
1884 | + $pre = apply_filters('pre_option_' . $option, false, $option); |
|
1885 | + if (false !== $pre) { |
|
1886 | + EE_Core_Config::$ee_ueip_option = $pre; |
|
1887 | + return EE_Core_Config::$ee_ueip_option; |
|
1888 | + } |
|
1889 | + $row = $wpdb->get_row( |
|
1890 | + $wpdb->prepare( |
|
1891 | + "SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", |
|
1892 | + $option |
|
1893 | + ) |
|
1894 | + ); |
|
1895 | + if (is_object($row)) { |
|
1896 | + $value = $row->option_value; |
|
1897 | + } else { // option does not exist so use default. |
|
1898 | + EE_Core_Config::$ee_ueip_option = apply_filters('default_option_' . $option, false, $option); |
|
1899 | + return EE_Core_Config::$ee_ueip_option; |
|
1900 | + } |
|
1901 | + EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
1902 | + return EE_Core_Config::$ee_ueip_option; |
|
1903 | + } |
|
1904 | + |
|
1905 | + |
|
1906 | + /** |
|
1907 | + * Utility function for escaping the value of a property and returning. |
|
1908 | + * |
|
1909 | + * @param string $property property name (checks to see if exists). |
|
1910 | + * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
1911 | + * @throws EE_Error |
|
1912 | + */ |
|
1913 | + public function get_pretty($property) |
|
1914 | + { |
|
1915 | + if ($property === self::OPTION_NAME_UXIP) { |
|
1916 | + return $this->ee_ueip_optin ? 'yes' : 'no'; |
|
1917 | + } |
|
1918 | + return parent::get_pretty($property); |
|
1919 | + } |
|
1920 | + |
|
1921 | + |
|
1922 | + /** |
|
1923 | + * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values |
|
1924 | + * on the object. |
|
1925 | + * |
|
1926 | + * @return array |
|
1927 | + */ |
|
1928 | + public function __sleep() |
|
1929 | + { |
|
1930 | + // reset all url properties |
|
1931 | + $this->_reset_urls(); |
|
1932 | + // return what to save to db |
|
1933 | + return array_keys(get_object_vars($this)); |
|
1934 | + } |
|
1935 | +} |
|
2375 | 1936 | |
2376 | - /** |
|
2377 | - * Whether to show the privacy policy consent checkbox |
|
2378 | - * |
|
2379 | - * @var bool |
|
2380 | - */ |
|
2381 | - public $consent_checkbox_enabled; |
|
1937 | +/** |
|
1938 | + * Config class for storing info on the Organization |
|
1939 | + */ |
|
1940 | +class EE_Organization_Config extends EE_Config_Base |
|
1941 | +{ |
|
1942 | + /** |
|
1943 | + * @var string $name |
|
1944 | + * eg EE4.1 |
|
1945 | + */ |
|
1946 | + public $name; |
|
1947 | + |
|
1948 | + /** |
|
1949 | + * @var string $address_1 |
|
1950 | + * eg 123 Onna Road |
|
1951 | + */ |
|
1952 | + public $address_1 = ''; |
|
1953 | + |
|
1954 | + /** |
|
1955 | + * @var string $address_2 |
|
1956 | + * eg PO Box 123 |
|
1957 | + */ |
|
1958 | + public $address_2 = ''; |
|
1959 | + |
|
1960 | + /** |
|
1961 | + * @var string $city |
|
1962 | + * eg Inna City |
|
1963 | + */ |
|
1964 | + public $city = ''; |
|
1965 | + |
|
1966 | + /** |
|
1967 | + * @var int $STA_ID |
|
1968 | + * eg 4 |
|
1969 | + */ |
|
1970 | + public $STA_ID = 0; |
|
1971 | + |
|
1972 | + /** |
|
1973 | + * @var string $CNT_ISO |
|
1974 | + * eg US |
|
1975 | + */ |
|
1976 | + public $CNT_ISO = 'US'; |
|
1977 | + |
|
1978 | + /** |
|
1979 | + * @var string $zip |
|
1980 | + * eg 12345 or V1A 2B3 |
|
1981 | + */ |
|
1982 | + public $zip = ''; |
|
1983 | + |
|
1984 | + /** |
|
1985 | + * @var string $email |
|
1986 | + * eg [email protected] |
|
1987 | + */ |
|
1988 | + public $email; |
|
1989 | + |
|
1990 | + /** |
|
1991 | + * @var string $phone |
|
1992 | + * eg. 111-111-1111 |
|
1993 | + */ |
|
1994 | + public $phone = ''; |
|
1995 | + |
|
1996 | + /** |
|
1997 | + * @var string $vat |
|
1998 | + * VAT/Tax Number |
|
1999 | + */ |
|
2000 | + public $vat = ''; |
|
2001 | + |
|
2002 | + /** |
|
2003 | + * @var string $logo_url |
|
2004 | + * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg |
|
2005 | + */ |
|
2006 | + public $logo_url = ''; |
|
2007 | + |
|
2008 | + /** |
|
2009 | + * The below are all various properties for holding links to organization social network profiles |
|
2010 | + */ |
|
2011 | + /** |
|
2012 | + * facebook (facebook.com/profile.name) |
|
2013 | + * |
|
2014 | + * @var string |
|
2015 | + */ |
|
2016 | + public $facebook = ''; |
|
2017 | + |
|
2018 | + /** |
|
2019 | + * twitter (twitter.com/twitter_handle) |
|
2020 | + * |
|
2021 | + * @var string |
|
2022 | + */ |
|
2023 | + public $twitter = ''; |
|
2024 | + |
|
2025 | + /** |
|
2026 | + * linkedin (linkedin.com/in/profile_name) |
|
2027 | + * |
|
2028 | + * @var string |
|
2029 | + */ |
|
2030 | + public $linkedin = ''; |
|
2031 | + |
|
2032 | + /** |
|
2033 | + * pinterest (www.pinterest.com/profile_name) |
|
2034 | + * |
|
2035 | + * @var string |
|
2036 | + */ |
|
2037 | + public $pinterest = ''; |
|
2038 | + |
|
2039 | + /** |
|
2040 | + * google+ (google.com/+profileName) |
|
2041 | + * |
|
2042 | + * @var string |
|
2043 | + */ |
|
2044 | + public $google = ''; |
|
2045 | + |
|
2046 | + /** |
|
2047 | + * instagram (instagram.com/handle) |
|
2048 | + * |
|
2049 | + * @var string |
|
2050 | + */ |
|
2051 | + public $instagram = ''; |
|
2052 | + |
|
2053 | + |
|
2054 | + /** |
|
2055 | + * class constructor |
|
2056 | + * |
|
2057 | + * @access public |
|
2058 | + */ |
|
2059 | + public function __construct() |
|
2060 | + { |
|
2061 | + // set default organization settings |
|
2062 | + // decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded |
|
2063 | + $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
|
2064 | + $this->email = get_bloginfo('admin_email'); |
|
2065 | + } |
|
2066 | +} |
|
2382 | 2067 | |
2383 | - /** |
|
2384 | - * Label text to show on the checkbox |
|
2385 | - * |
|
2386 | - * @var string |
|
2387 | - */ |
|
2388 | - public $consent_checkbox_label_text; |
|
2068 | +/** |
|
2069 | + * Class for defining what's in the EE_Config relating to currency |
|
2070 | + */ |
|
2071 | +class EE_Currency_Config extends EE_Config_Base |
|
2072 | +{ |
|
2073 | + /** |
|
2074 | + * @var string $code |
|
2075 | + * eg 'US' |
|
2076 | + */ |
|
2077 | + public $code; |
|
2078 | + |
|
2079 | + /** |
|
2080 | + * @var string $name |
|
2081 | + * eg 'Dollar' |
|
2082 | + */ |
|
2083 | + public $name; |
|
2084 | + |
|
2085 | + /** |
|
2086 | + * plural name |
|
2087 | + * |
|
2088 | + * @var string $plural |
|
2089 | + * eg 'Dollars' |
|
2090 | + */ |
|
2091 | + public $plural; |
|
2092 | + |
|
2093 | + /** |
|
2094 | + * currency sign |
|
2095 | + * |
|
2096 | + * @var string $sign |
|
2097 | + * eg '$' |
|
2098 | + */ |
|
2099 | + public $sign; |
|
2100 | + |
|
2101 | + /** |
|
2102 | + * Whether the currency sign should come before the number or not |
|
2103 | + * |
|
2104 | + * @var boolean $sign_b4 |
|
2105 | + */ |
|
2106 | + public $sign_b4; |
|
2107 | + |
|
2108 | + /** |
|
2109 | + * How many digits should come after the decimal place |
|
2110 | + * |
|
2111 | + * @var int $dec_plc |
|
2112 | + */ |
|
2113 | + public $dec_plc; |
|
2114 | + |
|
2115 | + /** |
|
2116 | + * Symbol to use for decimal mark |
|
2117 | + * |
|
2118 | + * @var string $dec_mrk |
|
2119 | + * eg '.' |
|
2120 | + */ |
|
2121 | + public $dec_mrk; |
|
2122 | + |
|
2123 | + /** |
|
2124 | + * Symbol to use for thousands |
|
2125 | + * |
|
2126 | + * @var string $thsnds |
|
2127 | + * eg ',' |
|
2128 | + */ |
|
2129 | + public $thsnds; |
|
2130 | + |
|
2131 | + |
|
2132 | + /** |
|
2133 | + * @param string|null $CNT_ISO |
|
2134 | + * @throws EE_Error |
|
2135 | + * @throws ReflectionException |
|
2136 | + */ |
|
2137 | + public function __construct(?string $CNT_ISO = 'US') |
|
2138 | + { |
|
2139 | + if ($CNT_ISO && $CNT_ISO === $this->code) { |
|
2140 | + return; |
|
2141 | + } |
|
2142 | + // get country code from organization settings or use default |
|
2143 | + $ORG_CNT = isset(EE_Registry::instance()->CFG->organization) |
|
2144 | + && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
2145 | + ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
2146 | + : 'US'; |
|
2147 | + // but override if requested |
|
2148 | + $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
|
2149 | + // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists |
|
2150 | + $this->setCurrency($CNT_ISO); |
|
2151 | + // fallback to hardcoded defaults, in case the above failed |
|
2152 | + if (empty($this->code)) { |
|
2153 | + $this->setFallbackCurrency(); |
|
2154 | + } |
|
2155 | + } |
|
2156 | + |
|
2157 | + |
|
2158 | + /** |
|
2159 | + * @param string|null $CNT_ISO |
|
2160 | + * @throws EE_Error |
|
2161 | + * @throws ReflectionException |
|
2162 | + */ |
|
2163 | + public function setCurrency(?string $CNT_ISO = 'US') |
|
2164 | + { |
|
2165 | + if (empty($CNT_ISO) || DbStatus::isOffline()) { |
|
2166 | + return; |
|
2167 | + } |
|
2168 | + |
|
2169 | + /** @var TableAnalysis $table_analysis */ |
|
2170 | + $table_analysis = EE_Registry::instance()->create('TableAnalysis', [], true); |
|
2171 | + if (! $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())) { |
|
2172 | + return; |
|
2173 | + } |
|
2174 | + // retrieve the country settings from the db, just in case they have been customized |
|
2175 | + $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
2176 | + if (! $country instanceof EE_Country) { |
|
2177 | + throw new DomainException( |
|
2178 | + sprintf( |
|
2179 | + esc_html__('Invalid Country ISO Code: %1$s', 'event_espresso'), |
|
2180 | + $CNT_ISO |
|
2181 | + ) |
|
2182 | + ); |
|
2183 | + } |
|
2184 | + $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
2185 | + $this->name = $country->currency_name_single(); // Dollar |
|
2186 | + $this->plural = $country->currency_name_plural(); // Dollars |
|
2187 | + $this->sign = $country->currency_sign(); // currency sign: $ |
|
2188 | + $this->sign_b4 = $country->currency_sign_before(); // currency sign before or after |
|
2189 | + $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
2190 | + $this->dec_mrk = $country->currency_decimal_mark(); // decimal mark: ',' = 0,01 or '.' = 0.01 |
|
2191 | + $this->thsnds = $country->currency_thousands_separator(); // thousands sep: ',' = 1,000 or '.' = 1.000 |
|
2192 | + } |
|
2193 | + |
|
2194 | + |
|
2195 | + private function setFallbackCurrency() |
|
2196 | + { |
|
2197 | + // set default currency settings |
|
2198 | + $this->code = 'USD'; |
|
2199 | + $this->name = esc_html__('Dollar', 'event_espresso'); |
|
2200 | + $this->plural = esc_html__('Dollars', 'event_espresso'); |
|
2201 | + $this->sign = '$'; |
|
2202 | + $this->sign_b4 = true; |
|
2203 | + $this->dec_plc = 2; |
|
2204 | + $this->dec_mrk = '.'; |
|
2205 | + $this->thsnds = ','; |
|
2206 | + } |
|
2207 | + |
|
2208 | + |
|
2209 | + /** |
|
2210 | + * @param string|null $CNT_ISO |
|
2211 | + * @return EE_Currency_Config |
|
2212 | + * @throws EE_Error |
|
2213 | + * @throws ReflectionException |
|
2214 | + */ |
|
2215 | + public static function getCurrencyConfig(?string $CNT_ISO = ''): EE_Currency_Config |
|
2216 | + { |
|
2217 | + // if CNT_ISO passed lets try to get currency settings for it. |
|
2218 | + $currency_config = ! empty($CNT_ISO) |
|
2219 | + ? new EE_Currency_Config($CNT_ISO) |
|
2220 | + : null; |
|
2221 | + // default currency settings for site if not set |
|
2222 | + if ($currency_config instanceof EE_Currency_Config) { |
|
2223 | + return $currency_config; |
|
2224 | + } |
|
2225 | + EE_Config::instance()->currency = EE_Config::instance()->currency instanceof EE_Currency_Config |
|
2226 | + ? EE_Config::instance()->currency |
|
2227 | + : new EE_Currency_Config(); |
|
2228 | + return EE_Config::instance()->currency; |
|
2229 | + } |
|
2230 | +} |
|
2389 | 2231 | |
2390 | - /* |
|
2232 | +/** |
|
2233 | + * Class for defining what's in the EE_Config relating to registration settings |
|
2234 | + */ |
|
2235 | +class EE_Registration_Config extends EE_Config_Base |
|
2236 | +{ |
|
2237 | + /** |
|
2238 | + * Default registration status |
|
2239 | + * |
|
2240 | + * @var string $default_STS_ID |
|
2241 | + * eg 'RPP' |
|
2242 | + */ |
|
2243 | + public $default_STS_ID; |
|
2244 | + |
|
2245 | + /** |
|
2246 | + * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of |
|
2247 | + * registrations) |
|
2248 | + * |
|
2249 | + * @var int |
|
2250 | + */ |
|
2251 | + public $default_maximum_number_of_tickets; |
|
2252 | + |
|
2253 | + /** |
|
2254 | + * level of validation to apply to email addresses |
|
2255 | + * |
|
2256 | + * @var string $email_validation_level |
|
2257 | + * options: 'basic', 'wp_default', 'i18n', 'i18n_dns' |
|
2258 | + */ |
|
2259 | + public $email_validation_level; |
|
2260 | + |
|
2261 | + /** |
|
2262 | + * whether to show alternate payment options during the reg process if payment status is pending |
|
2263 | + * |
|
2264 | + * @var boolean $show_pending_payment_options |
|
2265 | + */ |
|
2266 | + public $show_pending_payment_options; |
|
2267 | + |
|
2268 | + /** |
|
2269 | + * an array of SPCO reg steps where: |
|
2270 | + * the keys denotes the reg step order |
|
2271 | + * each element consists of an array with the following elements: |
|
2272 | + * "file_path" => the file path to the EE_SPCO_Reg_Step class |
|
2273 | + * "class_name" => the specific EE_SPCO_Reg_Step child class name |
|
2274 | + * "slug" => the URL param used to trigger the reg step |
|
2275 | + * |
|
2276 | + * @var array $reg_steps |
|
2277 | + */ |
|
2278 | + public $reg_steps; |
|
2279 | + |
|
2280 | + /** |
|
2281 | + * Whether registration confirmation should be the last page of SPCO |
|
2282 | + * |
|
2283 | + * @var boolean $reg_confirmation_last |
|
2284 | + */ |
|
2285 | + public $reg_confirmation_last; |
|
2286 | + |
|
2287 | + /** |
|
2288 | + * Whether to enable the EE Bot Trap |
|
2289 | + * |
|
2290 | + * @var boolean $use_bot_trap |
|
2291 | + */ |
|
2292 | + public $use_bot_trap; |
|
2293 | + |
|
2294 | + /** |
|
2295 | + * Whether to encrypt some data sent by the EE Bot Trap |
|
2296 | + * |
|
2297 | + * @var boolean $use_encryption |
|
2298 | + */ |
|
2299 | + public $use_encryption; |
|
2300 | + |
|
2301 | + /** |
|
2302 | + * Whether to use ReCaptcha |
|
2303 | + * |
|
2304 | + * @var boolean $use_captcha |
|
2305 | + */ |
|
2306 | + public $use_captcha; |
|
2307 | + |
|
2308 | + /** |
|
2309 | + * ReCaptcha Theme |
|
2310 | + * |
|
2311 | + * @var string $recaptcha_theme |
|
2312 | + * options: 'dark', 'light', 'invisible' |
|
2313 | + */ |
|
2314 | + public $recaptcha_theme; |
|
2315 | + |
|
2316 | + /** |
|
2317 | + * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha. |
|
2318 | + * |
|
2319 | + * @var string $recaptcha_badge |
|
2320 | + * options: 'bottomright', 'bottomleft', 'inline' |
|
2321 | + */ |
|
2322 | + public $recaptcha_badge; |
|
2323 | + |
|
2324 | + /** |
|
2325 | + * ReCaptcha Type |
|
2326 | + * |
|
2327 | + * @var string $recaptcha_type |
|
2328 | + * options: 'audio', 'image' |
|
2329 | + */ |
|
2330 | + public $recaptcha_type; |
|
2331 | + |
|
2332 | + /** |
|
2333 | + * ReCaptcha language |
|
2334 | + * |
|
2335 | + * @var string $recaptcha_language |
|
2336 | + * eg 'en' |
|
2337 | + */ |
|
2338 | + public $recaptcha_language; |
|
2339 | + |
|
2340 | + /** |
|
2341 | + * ReCaptcha public key |
|
2342 | + * |
|
2343 | + * @var string $recaptcha_publickey |
|
2344 | + */ |
|
2345 | + public $recaptcha_publickey; |
|
2346 | + |
|
2347 | + /** |
|
2348 | + * ReCaptcha private key |
|
2349 | + * |
|
2350 | + * @var string $recaptcha_privatekey |
|
2351 | + */ |
|
2352 | + public $recaptcha_privatekey; |
|
2353 | + |
|
2354 | + /** |
|
2355 | + * array of form names protected by ReCaptcha |
|
2356 | + * |
|
2357 | + * @var array $recaptcha_protected_forms |
|
2358 | + */ |
|
2359 | + public $recaptcha_protected_forms; |
|
2360 | + |
|
2361 | + /** |
|
2362 | + * ReCaptcha width |
|
2363 | + * |
|
2364 | + * @var int $recaptcha_width |
|
2365 | + * @deprecated |
|
2366 | + */ |
|
2367 | + public $recaptcha_width; |
|
2368 | + |
|
2369 | + /** |
|
2370 | + * Whether invalid attempts to directly access the registration checkout page should be tracked. |
|
2371 | + * |
|
2372 | + * @var boolean $track_invalid_checkout_access |
|
2373 | + */ |
|
2374 | + protected $track_invalid_checkout_access = true; |
|
2375 | + |
|
2376 | + /** |
|
2377 | + * Whether to show the privacy policy consent checkbox |
|
2378 | + * |
|
2379 | + * @var bool |
|
2380 | + */ |
|
2381 | + public $consent_checkbox_enabled; |
|
2382 | + |
|
2383 | + /** |
|
2384 | + * Label text to show on the checkbox |
|
2385 | + * |
|
2386 | + * @var string |
|
2387 | + */ |
|
2388 | + public $consent_checkbox_label_text; |
|
2389 | + |
|
2390 | + /* |
|
2391 | 2391 | * String describing how long to keep payment logs. Passed into DateTime constructor |
2392 | 2392 | * @var string |
2393 | 2393 | */ |
2394 | - public $gateway_log_lifespan = '1 week'; |
|
2395 | - |
|
2396 | - /** |
|
2397 | - * Enable copy attendee info at form |
|
2398 | - * |
|
2399 | - * @var boolean $enable_copy_attendee |
|
2400 | - */ |
|
2401 | - protected $copy_attendee_info = true; |
|
2402 | - |
|
2403 | - /** |
|
2404 | - * @var bool|int|string|null $skip_reg_confirmation |
|
2405 | - * @deprecated |
|
2406 | - */ |
|
2407 | - public $skip_reg_confirmation; |
|
2408 | - |
|
2409 | - |
|
2410 | - |
|
2411 | - |
|
2412 | - /** |
|
2413 | - * class constructor |
|
2414 | - * |
|
2415 | - * @access public |
|
2416 | - */ |
|
2417 | - public function __construct() |
|
2418 | - { |
|
2419 | - // set default registration settings |
|
2420 | - $this->default_STS_ID = EEM_Registration::status_id_pending_payment; |
|
2421 | - $this->email_validation_level = 'wp_default'; |
|
2422 | - $this->show_pending_payment_options = true; |
|
2423 | - $this->reg_steps = array(); |
|
2424 | - $this->reg_confirmation_last = false; |
|
2425 | - $this->use_bot_trap = true; |
|
2426 | - $this->use_encryption = true; |
|
2427 | - $this->use_captcha = false; |
|
2428 | - $this->recaptcha_theme = 'light'; |
|
2429 | - $this->recaptcha_badge = 'bottomleft'; |
|
2430 | - $this->recaptcha_type = 'image'; |
|
2431 | - $this->recaptcha_language = 'en'; |
|
2432 | - $this->recaptcha_publickey = null; |
|
2433 | - $this->recaptcha_privatekey = null; |
|
2434 | - $this->recaptcha_protected_forms = array(); |
|
2435 | - $this->recaptcha_width = 500; |
|
2436 | - $this->default_maximum_number_of_tickets = 10; |
|
2437 | - $this->consent_checkbox_enabled = false; |
|
2438 | - $this->consent_checkbox_label_text = ''; |
|
2439 | - $this->gateway_log_lifespan = '7 days'; |
|
2440 | - $this->copy_attendee_info = true; |
|
2441 | - } |
|
2442 | - |
|
2443 | - |
|
2444 | - /** |
|
2445 | - * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
2446 | - * |
|
2447 | - * @since 4.8.8.rc.019 |
|
2448 | - */ |
|
2449 | - public function do_hooks() |
|
2450 | - { |
|
2451 | - add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
2452 | - add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event')); |
|
2453 | - add_action('setup_theme', array($this, 'setDefaultCheckboxLabelText')); |
|
2454 | - } |
|
2455 | - |
|
2456 | - |
|
2457 | - /** |
|
2458 | - * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the |
|
2459 | - * EVT_default_registration_status field matches the config setting for default_STS_ID. |
|
2460 | - */ |
|
2461 | - public function set_default_reg_status_on_EEM_Event() |
|
2462 | - { |
|
2463 | - EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
2464 | - } |
|
2465 | - |
|
2466 | - |
|
2467 | - /** |
|
2468 | - * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field |
|
2469 | - * for Events matches the config setting for default_maximum_number_of_tickets |
|
2470 | - */ |
|
2471 | - public function set_default_max_ticket_on_EEM_Event() |
|
2472 | - { |
|
2473 | - EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets); |
|
2474 | - } |
|
2475 | - |
|
2476 | - |
|
2477 | - /** |
|
2478 | - * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is |
|
2479 | - * constructed because that happens before we can get the privacy policy page's permalink. |
|
2480 | - * |
|
2481 | - * @throws InvalidArgumentException |
|
2482 | - * @throws InvalidDataTypeException |
|
2483 | - * @throws InvalidInterfaceException |
|
2484 | - */ |
|
2485 | - public function setDefaultCheckboxLabelText() |
|
2486 | - { |
|
2487 | - if ( |
|
2488 | - $this->getConsentCheckboxLabelText() === null |
|
2489 | - || $this->getConsentCheckboxLabelText() === '' |
|
2490 | - ) { |
|
2491 | - $opening_a_tag = ''; |
|
2492 | - $closing_a_tag = ''; |
|
2493 | - if (function_exists('get_privacy_policy_url')) { |
|
2494 | - $privacy_page_url = get_privacy_policy_url(); |
|
2495 | - if (! empty($privacy_page_url)) { |
|
2496 | - $opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">'; |
|
2497 | - $closing_a_tag = '</a>'; |
|
2498 | - } |
|
2499 | - } |
|
2500 | - $loader = LoaderFactory::getLoader(); |
|
2501 | - $org_config = $loader->getShared('EE_Organization_Config'); |
|
2502 | - /** |
|
2503 | - * @var $org_config EE_Organization_Config |
|
2504 | - */ |
|
2505 | - |
|
2506 | - $this->setConsentCheckboxLabelText( |
|
2507 | - sprintf( |
|
2508 | - esc_html__( |
|
2509 | - 'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.', |
|
2510 | - 'event_espresso' |
|
2511 | - ), |
|
2512 | - $org_config->name, |
|
2513 | - $opening_a_tag, |
|
2514 | - $closing_a_tag |
|
2515 | - ) |
|
2516 | - ); |
|
2517 | - } |
|
2518 | - } |
|
2519 | - |
|
2520 | - |
|
2521 | - /** |
|
2522 | - * @return boolean |
|
2523 | - */ |
|
2524 | - public function track_invalid_checkout_access() |
|
2525 | - { |
|
2526 | - return $this->track_invalid_checkout_access; |
|
2527 | - } |
|
2528 | - |
|
2529 | - |
|
2530 | - /** |
|
2531 | - * @param boolean $track_invalid_checkout_access |
|
2532 | - */ |
|
2533 | - public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
2534 | - { |
|
2535 | - $this->track_invalid_checkout_access = filter_var( |
|
2536 | - $track_invalid_checkout_access, |
|
2537 | - FILTER_VALIDATE_BOOLEAN |
|
2538 | - ); |
|
2539 | - } |
|
2540 | - |
|
2541 | - /** |
|
2542 | - * @return boolean |
|
2543 | - */ |
|
2544 | - public function copyAttendeeInfo() |
|
2545 | - { |
|
2546 | - return $this->copy_attendee_info; |
|
2547 | - } |
|
2548 | - |
|
2549 | - |
|
2550 | - /** |
|
2551 | - * @param boolean $copy_attendee_info |
|
2552 | - */ |
|
2553 | - public function setCopyAttendeeInfo($copy_attendee_info) |
|
2554 | - { |
|
2555 | - $this->copy_attendee_info = filter_var( |
|
2556 | - $copy_attendee_info, |
|
2557 | - FILTER_VALIDATE_BOOLEAN |
|
2558 | - ); |
|
2559 | - } |
|
2560 | - |
|
2561 | - |
|
2562 | - /** |
|
2563 | - * Gets the options to make available for the gateway log lifespan |
|
2564 | - * @return array |
|
2565 | - */ |
|
2566 | - public function gatewayLogLifespanOptions() |
|
2567 | - { |
|
2568 | - return (array) apply_filters( |
|
2569 | - 'FHEE_EE_Admin_Config__gatewayLogLifespanOptions', |
|
2570 | - array( |
|
2571 | - '1 second' => esc_html__('Don\'t Log At All', 'event_espresso'), |
|
2572 | - '1 day' => esc_html__('1 Day', 'event_espresso'), |
|
2573 | - '7 days' => esc_html__('7 Days', 'event_espresso'), |
|
2574 | - '14 days' => esc_html__('14 Days', 'event_espresso'), |
|
2575 | - '30 days' => esc_html__('30 Days', 'event_espresso') |
|
2576 | - ) |
|
2577 | - ); |
|
2578 | - } |
|
2579 | - |
|
2580 | - |
|
2581 | - /** |
|
2582 | - * @return bool |
|
2583 | - */ |
|
2584 | - public function isConsentCheckboxEnabled() |
|
2585 | - { |
|
2586 | - return $this->consent_checkbox_enabled; |
|
2587 | - } |
|
2588 | - |
|
2589 | - |
|
2590 | - /** |
|
2591 | - * @param bool $consent_checkbox_enabled |
|
2592 | - */ |
|
2593 | - public function setConsentCheckboxEnabled($consent_checkbox_enabled) |
|
2594 | - { |
|
2595 | - $this->consent_checkbox_enabled = filter_var( |
|
2596 | - $consent_checkbox_enabled, |
|
2597 | - FILTER_VALIDATE_BOOLEAN |
|
2598 | - ); |
|
2599 | - } |
|
2600 | - |
|
2601 | - |
|
2602 | - /** |
|
2603 | - * @return string |
|
2604 | - */ |
|
2605 | - public function getConsentCheckboxLabelText() |
|
2606 | - { |
|
2607 | - return $this->consent_checkbox_label_text; |
|
2608 | - } |
|
2609 | - |
|
2610 | - |
|
2611 | - /** |
|
2612 | - * @param string $consent_checkbox_label_text |
|
2613 | - */ |
|
2614 | - public function setConsentCheckboxLabelText($consent_checkbox_label_text) |
|
2615 | - { |
|
2616 | - $this->consent_checkbox_label_text = (string) $consent_checkbox_label_text; |
|
2617 | - } |
|
2394 | + public $gateway_log_lifespan = '1 week'; |
|
2395 | + |
|
2396 | + /** |
|
2397 | + * Enable copy attendee info at form |
|
2398 | + * |
|
2399 | + * @var boolean $enable_copy_attendee |
|
2400 | + */ |
|
2401 | + protected $copy_attendee_info = true; |
|
2402 | + |
|
2403 | + /** |
|
2404 | + * @var bool|int|string|null $skip_reg_confirmation |
|
2405 | + * @deprecated |
|
2406 | + */ |
|
2407 | + public $skip_reg_confirmation; |
|
2408 | + |
|
2409 | + |
|
2410 | + |
|
2411 | + |
|
2412 | + /** |
|
2413 | + * class constructor |
|
2414 | + * |
|
2415 | + * @access public |
|
2416 | + */ |
|
2417 | + public function __construct() |
|
2418 | + { |
|
2419 | + // set default registration settings |
|
2420 | + $this->default_STS_ID = EEM_Registration::status_id_pending_payment; |
|
2421 | + $this->email_validation_level = 'wp_default'; |
|
2422 | + $this->show_pending_payment_options = true; |
|
2423 | + $this->reg_steps = array(); |
|
2424 | + $this->reg_confirmation_last = false; |
|
2425 | + $this->use_bot_trap = true; |
|
2426 | + $this->use_encryption = true; |
|
2427 | + $this->use_captcha = false; |
|
2428 | + $this->recaptcha_theme = 'light'; |
|
2429 | + $this->recaptcha_badge = 'bottomleft'; |
|
2430 | + $this->recaptcha_type = 'image'; |
|
2431 | + $this->recaptcha_language = 'en'; |
|
2432 | + $this->recaptcha_publickey = null; |
|
2433 | + $this->recaptcha_privatekey = null; |
|
2434 | + $this->recaptcha_protected_forms = array(); |
|
2435 | + $this->recaptcha_width = 500; |
|
2436 | + $this->default_maximum_number_of_tickets = 10; |
|
2437 | + $this->consent_checkbox_enabled = false; |
|
2438 | + $this->consent_checkbox_label_text = ''; |
|
2439 | + $this->gateway_log_lifespan = '7 days'; |
|
2440 | + $this->copy_attendee_info = true; |
|
2441 | + } |
|
2442 | + |
|
2443 | + |
|
2444 | + /** |
|
2445 | + * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
2446 | + * |
|
2447 | + * @since 4.8.8.rc.019 |
|
2448 | + */ |
|
2449 | + public function do_hooks() |
|
2450 | + { |
|
2451 | + add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
2452 | + add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event')); |
|
2453 | + add_action('setup_theme', array($this, 'setDefaultCheckboxLabelText')); |
|
2454 | + } |
|
2455 | + |
|
2456 | + |
|
2457 | + /** |
|
2458 | + * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the |
|
2459 | + * EVT_default_registration_status field matches the config setting for default_STS_ID. |
|
2460 | + */ |
|
2461 | + public function set_default_reg_status_on_EEM_Event() |
|
2462 | + { |
|
2463 | + EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
2464 | + } |
|
2465 | + |
|
2466 | + |
|
2467 | + /** |
|
2468 | + * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field |
|
2469 | + * for Events matches the config setting for default_maximum_number_of_tickets |
|
2470 | + */ |
|
2471 | + public function set_default_max_ticket_on_EEM_Event() |
|
2472 | + { |
|
2473 | + EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets); |
|
2474 | + } |
|
2475 | + |
|
2476 | + |
|
2477 | + /** |
|
2478 | + * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is |
|
2479 | + * constructed because that happens before we can get the privacy policy page's permalink. |
|
2480 | + * |
|
2481 | + * @throws InvalidArgumentException |
|
2482 | + * @throws InvalidDataTypeException |
|
2483 | + * @throws InvalidInterfaceException |
|
2484 | + */ |
|
2485 | + public function setDefaultCheckboxLabelText() |
|
2486 | + { |
|
2487 | + if ( |
|
2488 | + $this->getConsentCheckboxLabelText() === null |
|
2489 | + || $this->getConsentCheckboxLabelText() === '' |
|
2490 | + ) { |
|
2491 | + $opening_a_tag = ''; |
|
2492 | + $closing_a_tag = ''; |
|
2493 | + if (function_exists('get_privacy_policy_url')) { |
|
2494 | + $privacy_page_url = get_privacy_policy_url(); |
|
2495 | + if (! empty($privacy_page_url)) { |
|
2496 | + $opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">'; |
|
2497 | + $closing_a_tag = '</a>'; |
|
2498 | + } |
|
2499 | + } |
|
2500 | + $loader = LoaderFactory::getLoader(); |
|
2501 | + $org_config = $loader->getShared('EE_Organization_Config'); |
|
2502 | + /** |
|
2503 | + * @var $org_config EE_Organization_Config |
|
2504 | + */ |
|
2505 | + |
|
2506 | + $this->setConsentCheckboxLabelText( |
|
2507 | + sprintf( |
|
2508 | + esc_html__( |
|
2509 | + 'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.', |
|
2510 | + 'event_espresso' |
|
2511 | + ), |
|
2512 | + $org_config->name, |
|
2513 | + $opening_a_tag, |
|
2514 | + $closing_a_tag |
|
2515 | + ) |
|
2516 | + ); |
|
2517 | + } |
|
2518 | + } |
|
2519 | + |
|
2520 | + |
|
2521 | + /** |
|
2522 | + * @return boolean |
|
2523 | + */ |
|
2524 | + public function track_invalid_checkout_access() |
|
2525 | + { |
|
2526 | + return $this->track_invalid_checkout_access; |
|
2527 | + } |
|
2528 | + |
|
2529 | + |
|
2530 | + /** |
|
2531 | + * @param boolean $track_invalid_checkout_access |
|
2532 | + */ |
|
2533 | + public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
2534 | + { |
|
2535 | + $this->track_invalid_checkout_access = filter_var( |
|
2536 | + $track_invalid_checkout_access, |
|
2537 | + FILTER_VALIDATE_BOOLEAN |
|
2538 | + ); |
|
2539 | + } |
|
2540 | + |
|
2541 | + /** |
|
2542 | + * @return boolean |
|
2543 | + */ |
|
2544 | + public function copyAttendeeInfo() |
|
2545 | + { |
|
2546 | + return $this->copy_attendee_info; |
|
2547 | + } |
|
2548 | + |
|
2549 | + |
|
2550 | + /** |
|
2551 | + * @param boolean $copy_attendee_info |
|
2552 | + */ |
|
2553 | + public function setCopyAttendeeInfo($copy_attendee_info) |
|
2554 | + { |
|
2555 | + $this->copy_attendee_info = filter_var( |
|
2556 | + $copy_attendee_info, |
|
2557 | + FILTER_VALIDATE_BOOLEAN |
|
2558 | + ); |
|
2559 | + } |
|
2560 | + |
|
2561 | + |
|
2562 | + /** |
|
2563 | + * Gets the options to make available for the gateway log lifespan |
|
2564 | + * @return array |
|
2565 | + */ |
|
2566 | + public function gatewayLogLifespanOptions() |
|
2567 | + { |
|
2568 | + return (array) apply_filters( |
|
2569 | + 'FHEE_EE_Admin_Config__gatewayLogLifespanOptions', |
|
2570 | + array( |
|
2571 | + '1 second' => esc_html__('Don\'t Log At All', 'event_espresso'), |
|
2572 | + '1 day' => esc_html__('1 Day', 'event_espresso'), |
|
2573 | + '7 days' => esc_html__('7 Days', 'event_espresso'), |
|
2574 | + '14 days' => esc_html__('14 Days', 'event_espresso'), |
|
2575 | + '30 days' => esc_html__('30 Days', 'event_espresso') |
|
2576 | + ) |
|
2577 | + ); |
|
2578 | + } |
|
2579 | + |
|
2580 | + |
|
2581 | + /** |
|
2582 | + * @return bool |
|
2583 | + */ |
|
2584 | + public function isConsentCheckboxEnabled() |
|
2585 | + { |
|
2586 | + return $this->consent_checkbox_enabled; |
|
2587 | + } |
|
2588 | + |
|
2589 | + |
|
2590 | + /** |
|
2591 | + * @param bool $consent_checkbox_enabled |
|
2592 | + */ |
|
2593 | + public function setConsentCheckboxEnabled($consent_checkbox_enabled) |
|
2594 | + { |
|
2595 | + $this->consent_checkbox_enabled = filter_var( |
|
2596 | + $consent_checkbox_enabled, |
|
2597 | + FILTER_VALIDATE_BOOLEAN |
|
2598 | + ); |
|
2599 | + } |
|
2600 | + |
|
2601 | + |
|
2602 | + /** |
|
2603 | + * @return string |
|
2604 | + */ |
|
2605 | + public function getConsentCheckboxLabelText() |
|
2606 | + { |
|
2607 | + return $this->consent_checkbox_label_text; |
|
2608 | + } |
|
2609 | + |
|
2610 | + |
|
2611 | + /** |
|
2612 | + * @param string $consent_checkbox_label_text |
|
2613 | + */ |
|
2614 | + public function setConsentCheckboxLabelText($consent_checkbox_label_text) |
|
2615 | + { |
|
2616 | + $this->consent_checkbox_label_text = (string) $consent_checkbox_label_text; |
|
2617 | + } |
|
2618 | 2618 | } |
2619 | 2619 | |
2620 | 2620 | /** |
@@ -2622,134 +2622,134 @@ discard block |
||
2622 | 2622 | */ |
2623 | 2623 | class EE_Admin_Config extends EE_Config_Base |
2624 | 2624 | { |
2625 | - private $useAdvancedEditor = true; |
|
2626 | - |
|
2627 | - public $use_remote_logging = false; |
|
2628 | - |
|
2629 | - public $show_reg_footer = false; |
|
2630 | - |
|
2631 | - private $is_caffeinated; |
|
2632 | - |
|
2633 | - public $use_dashboard_widget = false; |
|
2634 | - |
|
2635 | - public $use_personnel_manager = false; |
|
2636 | - |
|
2637 | - public $use_event_timezones = false; |
|
2638 | - |
|
2639 | - /** |
|
2640 | - * adds extra layer of encoding to session data to prevent serialization errors |
|
2641 | - * but is incompatible with some server configuration errors |
|
2642 | - * if you get "500 internal server errors" during registration, try turning this on |
|
2643 | - * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
2644 | - * |
|
2645 | - * @var boolean $encode_session_data |
|
2646 | - */ |
|
2647 | - private $encode_session_data = false; |
|
2648 | - |
|
2649 | - public ?string $log_file_name = ''; |
|
2650 | - |
|
2651 | - public ?string $debug_file_name = ''; |
|
2652 | - |
|
2653 | - public ?string $remote_logging_url = ''; |
|
2654 | - |
|
2655 | - public ?string $affiliate_id = 'default'; |
|
2656 | - |
|
2657 | - /** |
|
2658 | - * @var int|null $events_in_dashboard |
|
2659 | - * @deprecated |
|
2660 | - */ |
|
2661 | - public ?int $events_in_dashboard = 30; |
|
2662 | - |
|
2663 | - |
|
2664 | - public function __construct() |
|
2665 | - { |
|
2666 | - /** @var EventEspresso\core\domain\Domain $domain */ |
|
2667 | - $domain = LoaderFactory::getLoader()->getShared('EventEspresso\core\domain\Domain'); |
|
2668 | - $this->is_caffeinated = $domain->isCaffeinated(); |
|
2669 | - |
|
2670 | - // set default general admin settings |
|
2671 | - $this->show_reg_footer = apply_filters( |
|
2672 | - 'FHEE__EE_Admin_Config__show_reg_footer__default', |
|
2673 | - false |
|
2674 | - ); |
|
2675 | - } |
|
2676 | - |
|
2677 | - |
|
2678 | - /** |
|
2679 | - * @param bool $reset |
|
2680 | - * @return string |
|
2681 | - */ |
|
2682 | - public function log_file_name(bool $reset = false): ?string |
|
2683 | - { |
|
2684 | - if (empty($this->log_file_name) || $reset) { |
|
2685 | - $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
2686 | - EE_Config::instance()->update_espresso_config(false, false); |
|
2687 | - } |
|
2688 | - return $this->log_file_name; |
|
2689 | - } |
|
2690 | - |
|
2691 | - |
|
2692 | - /** |
|
2693 | - * @param bool $reset |
|
2694 | - * @return string |
|
2695 | - */ |
|
2696 | - public function debug_file_name(bool $reset = false): ?string |
|
2697 | - { |
|
2698 | - if (empty($this->debug_file_name) || $reset) { |
|
2699 | - $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
2700 | - EE_Config::instance()->update_espresso_config(false, false); |
|
2701 | - } |
|
2702 | - return $this->debug_file_name; |
|
2703 | - } |
|
2704 | - |
|
2705 | - |
|
2706 | - /** |
|
2707 | - * @return string |
|
2708 | - */ |
|
2709 | - public function affiliate_id(): ?string |
|
2710 | - { |
|
2711 | - return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
2712 | - } |
|
2713 | - |
|
2714 | - |
|
2715 | - /** |
|
2716 | - * @return boolean |
|
2717 | - */ |
|
2718 | - public function encode_session_data(): bool |
|
2719 | - { |
|
2720 | - return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
2721 | - } |
|
2722 | - |
|
2723 | - |
|
2724 | - /** |
|
2725 | - * @param bool|int|string $encode_session_data |
|
2726 | - */ |
|
2727 | - public function set_encode_session_data($encode_session_data) |
|
2728 | - { |
|
2729 | - $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
2730 | - } |
|
2625 | + private $useAdvancedEditor = true; |
|
2731 | 2626 | |
2732 | - /** |
|
2733 | - * @return boolean |
|
2734 | - */ |
|
2735 | - public function useAdvancedEditor(): bool |
|
2736 | - { |
|
2737 | - return $this->useAdvancedEditor && $this->is_caffeinated; |
|
2738 | - } |
|
2739 | - |
|
2740 | - /** |
|
2741 | - * @param bool|int|string $use_advanced_editor |
|
2742 | - */ |
|
2743 | - public function setUseAdvancedEditor($use_advanced_editor = true) |
|
2744 | - { |
|
2745 | - $this->useAdvancedEditor = filter_var( |
|
2746 | - apply_filters( |
|
2747 | - 'FHEE__EE_Admin_Config__setUseAdvancedEditor__use_advanced_editor', |
|
2748 | - $use_advanced_editor |
|
2749 | - ), |
|
2750 | - FILTER_VALIDATE_BOOLEAN |
|
2751 | - ); |
|
2752 | - } |
|
2627 | + public $use_remote_logging = false; |
|
2628 | + |
|
2629 | + public $show_reg_footer = false; |
|
2630 | + |
|
2631 | + private $is_caffeinated; |
|
2632 | + |
|
2633 | + public $use_dashboard_widget = false; |
|
2634 | + |
|
2635 | + public $use_personnel_manager = false; |
|
2636 | + |
|
2637 | + public $use_event_timezones = false; |
|
2638 | + |
|
2639 | + /** |
|
2640 | + * adds extra layer of encoding to session data to prevent serialization errors |
|
2641 | + * but is incompatible with some server configuration errors |
|
2642 | + * if you get "500 internal server errors" during registration, try turning this on |
|
2643 | + * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
2644 | + * |
|
2645 | + * @var boolean $encode_session_data |
|
2646 | + */ |
|
2647 | + private $encode_session_data = false; |
|
2648 | + |
|
2649 | + public ?string $log_file_name = ''; |
|
2650 | + |
|
2651 | + public ?string $debug_file_name = ''; |
|
2652 | + |
|
2653 | + public ?string $remote_logging_url = ''; |
|
2654 | + |
|
2655 | + public ?string $affiliate_id = 'default'; |
|
2656 | + |
|
2657 | + /** |
|
2658 | + * @var int|null $events_in_dashboard |
|
2659 | + * @deprecated |
|
2660 | + */ |
|
2661 | + public ?int $events_in_dashboard = 30; |
|
2662 | + |
|
2663 | + |
|
2664 | + public function __construct() |
|
2665 | + { |
|
2666 | + /** @var EventEspresso\core\domain\Domain $domain */ |
|
2667 | + $domain = LoaderFactory::getLoader()->getShared('EventEspresso\core\domain\Domain'); |
|
2668 | + $this->is_caffeinated = $domain->isCaffeinated(); |
|
2669 | + |
|
2670 | + // set default general admin settings |
|
2671 | + $this->show_reg_footer = apply_filters( |
|
2672 | + 'FHEE__EE_Admin_Config__show_reg_footer__default', |
|
2673 | + false |
|
2674 | + ); |
|
2675 | + } |
|
2676 | + |
|
2677 | + |
|
2678 | + /** |
|
2679 | + * @param bool $reset |
|
2680 | + * @return string |
|
2681 | + */ |
|
2682 | + public function log_file_name(bool $reset = false): ?string |
|
2683 | + { |
|
2684 | + if (empty($this->log_file_name) || $reset) { |
|
2685 | + $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
2686 | + EE_Config::instance()->update_espresso_config(false, false); |
|
2687 | + } |
|
2688 | + return $this->log_file_name; |
|
2689 | + } |
|
2690 | + |
|
2691 | + |
|
2692 | + /** |
|
2693 | + * @param bool $reset |
|
2694 | + * @return string |
|
2695 | + */ |
|
2696 | + public function debug_file_name(bool $reset = false): ?string |
|
2697 | + { |
|
2698 | + if (empty($this->debug_file_name) || $reset) { |
|
2699 | + $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
2700 | + EE_Config::instance()->update_espresso_config(false, false); |
|
2701 | + } |
|
2702 | + return $this->debug_file_name; |
|
2703 | + } |
|
2704 | + |
|
2705 | + |
|
2706 | + /** |
|
2707 | + * @return string |
|
2708 | + */ |
|
2709 | + public function affiliate_id(): ?string |
|
2710 | + { |
|
2711 | + return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
2712 | + } |
|
2713 | + |
|
2714 | + |
|
2715 | + /** |
|
2716 | + * @return boolean |
|
2717 | + */ |
|
2718 | + public function encode_session_data(): bool |
|
2719 | + { |
|
2720 | + return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
2721 | + } |
|
2722 | + |
|
2723 | + |
|
2724 | + /** |
|
2725 | + * @param bool|int|string $encode_session_data |
|
2726 | + */ |
|
2727 | + public function set_encode_session_data($encode_session_data) |
|
2728 | + { |
|
2729 | + $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
2730 | + } |
|
2731 | + |
|
2732 | + /** |
|
2733 | + * @return boolean |
|
2734 | + */ |
|
2735 | + public function useAdvancedEditor(): bool |
|
2736 | + { |
|
2737 | + return $this->useAdvancedEditor && $this->is_caffeinated; |
|
2738 | + } |
|
2739 | + |
|
2740 | + /** |
|
2741 | + * @param bool|int|string $use_advanced_editor |
|
2742 | + */ |
|
2743 | + public function setUseAdvancedEditor($use_advanced_editor = true) |
|
2744 | + { |
|
2745 | + $this->useAdvancedEditor = filter_var( |
|
2746 | + apply_filters( |
|
2747 | + 'FHEE__EE_Admin_Config__setUseAdvancedEditor__use_advanced_editor', |
|
2748 | + $use_advanced_editor |
|
2749 | + ), |
|
2750 | + FILTER_VALIDATE_BOOLEAN |
|
2751 | + ); |
|
2752 | + } |
|
2753 | 2753 | } |
2754 | 2754 | |
2755 | 2755 | /** |
@@ -2757,69 +2757,69 @@ discard block |
||
2757 | 2757 | */ |
2758 | 2758 | class EE_Template_Config extends EE_Config_Base |
2759 | 2759 | { |
2760 | - /** |
|
2761 | - * @var EE_Ticket_Selector_Config|stdClass|null |
|
2762 | - */ |
|
2763 | - public $EED_Ticket_Selector; |
|
2764 | - |
|
2765 | - /** |
|
2766 | - * @var EE_Event_Single_Config|stdClass|null |
|
2767 | - */ |
|
2768 | - public $EED_Event_Single; |
|
2769 | - |
|
2770 | - /** |
|
2771 | - * @var EE_Events_Archive_Config|stdClass|null |
|
2772 | - */ |
|
2773 | - public $EED_Events_Archive; |
|
2774 | - |
|
2775 | - /** |
|
2776 | - * @var EE_People_Config|stdClass|null |
|
2777 | - * @since 5.0.12.p |
|
2778 | - */ |
|
2779 | - public $EED_People_Single; |
|
2780 | - |
|
2781 | - public string $current_espresso_theme = ''; |
|
2782 | - |
|
2783 | - public bool $display_address_in_regform = true; |
|
2784 | - |
|
2785 | - /** |
|
2786 | - * @var bool|int|string|null $enable_default_style |
|
2787 | - * @deprecated |
|
2788 | - */ |
|
2789 | - public $enable_default_style; |
|
2790 | - |
|
2791 | - /** |
|
2792 | - * @var bool|int|string|null $display_description_on_multi_reg_page |
|
2793 | - * @deprecated |
|
2794 | - */ |
|
2795 | - public $display_description_on_multi_reg_page; |
|
2796 | - |
|
2797 | - /** |
|
2798 | - * @var bool|int|string|null $use_custom_templates |
|
2799 | - * @deprecated |
|
2800 | - */ |
|
2801 | - public $use_custom_templates; |
|
2802 | - |
|
2803 | - /** |
|
2804 | - * @var bool|int|string|null $custom_style_sheet |
|
2805 | - * @deprecated |
|
2806 | - */ |
|
2807 | - public $custom_style_sheet; |
|
2808 | - |
|
2809 | - |
|
2810 | - /** |
|
2811 | - * class constructor |
|
2812 | - * |
|
2813 | - * @access public |
|
2814 | - */ |
|
2815 | - public function __construct() |
|
2816 | - { |
|
2817 | - // set default template settings |
|
2818 | - $this->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
2819 | - $this->EED_Event_Single = null; |
|
2820 | - $this->EED_Events_Archive = null; |
|
2821 | - $this->EED_Ticket_Selector = null; |
|
2822 | - } |
|
2760 | + /** |
|
2761 | + * @var EE_Ticket_Selector_Config|stdClass|null |
|
2762 | + */ |
|
2763 | + public $EED_Ticket_Selector; |
|
2764 | + |
|
2765 | + /** |
|
2766 | + * @var EE_Event_Single_Config|stdClass|null |
|
2767 | + */ |
|
2768 | + public $EED_Event_Single; |
|
2769 | + |
|
2770 | + /** |
|
2771 | + * @var EE_Events_Archive_Config|stdClass|null |
|
2772 | + */ |
|
2773 | + public $EED_Events_Archive; |
|
2774 | + |
|
2775 | + /** |
|
2776 | + * @var EE_People_Config|stdClass|null |
|
2777 | + * @since 5.0.12.p |
|
2778 | + */ |
|
2779 | + public $EED_People_Single; |
|
2780 | + |
|
2781 | + public string $current_espresso_theme = ''; |
|
2782 | + |
|
2783 | + public bool $display_address_in_regform = true; |
|
2784 | + |
|
2785 | + /** |
|
2786 | + * @var bool|int|string|null $enable_default_style |
|
2787 | + * @deprecated |
|
2788 | + */ |
|
2789 | + public $enable_default_style; |
|
2790 | + |
|
2791 | + /** |
|
2792 | + * @var bool|int|string|null $display_description_on_multi_reg_page |
|
2793 | + * @deprecated |
|
2794 | + */ |
|
2795 | + public $display_description_on_multi_reg_page; |
|
2796 | + |
|
2797 | + /** |
|
2798 | + * @var bool|int|string|null $use_custom_templates |
|
2799 | + * @deprecated |
|
2800 | + */ |
|
2801 | + public $use_custom_templates; |
|
2802 | + |
|
2803 | + /** |
|
2804 | + * @var bool|int|string|null $custom_style_sheet |
|
2805 | + * @deprecated |
|
2806 | + */ |
|
2807 | + public $custom_style_sheet; |
|
2808 | + |
|
2809 | + |
|
2810 | + /** |
|
2811 | + * class constructor |
|
2812 | + * |
|
2813 | + * @access public |
|
2814 | + */ |
|
2815 | + public function __construct() |
|
2816 | + { |
|
2817 | + // set default template settings |
|
2818 | + $this->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
2819 | + $this->EED_Event_Single = null; |
|
2820 | + $this->EED_Events_Archive = null; |
|
2821 | + $this->EED_Ticket_Selector = null; |
|
2822 | + } |
|
2823 | 2823 | } |
2824 | 2824 | |
2825 | 2825 | /** |
@@ -2827,114 +2827,114 @@ discard block |
||
2827 | 2827 | */ |
2828 | 2828 | class EE_Map_Config extends EE_Config_Base |
2829 | 2829 | { |
2830 | - /** |
|
2831 | - * @var boolean $use_google_maps |
|
2832 | - */ |
|
2833 | - public $use_google_maps; |
|
2834 | - |
|
2835 | - /** |
|
2836 | - * @var string $api_key |
|
2837 | - */ |
|
2838 | - public $google_map_api_key; |
|
2839 | - |
|
2840 | - /** |
|
2841 | - * @var int $event_details_map_width |
|
2842 | - */ |
|
2843 | - public $event_details_map_width; |
|
2844 | - |
|
2845 | - /** |
|
2846 | - * @var int $event_details_map_height |
|
2847 | - */ |
|
2848 | - public $event_details_map_height; |
|
2849 | - |
|
2850 | - /** |
|
2851 | - * @var int $event_details_map_zoom |
|
2852 | - */ |
|
2853 | - public $event_details_map_zoom; |
|
2854 | - |
|
2855 | - /** |
|
2856 | - * @var boolean $event_details_display_nav |
|
2857 | - */ |
|
2858 | - public $event_details_display_nav; |
|
2859 | - |
|
2860 | - /** |
|
2861 | - * @var boolean $event_details_nav_size |
|
2862 | - */ |
|
2863 | - public $event_details_nav_size; |
|
2864 | - |
|
2865 | - /** |
|
2866 | - * @var string $event_details_control_type |
|
2867 | - */ |
|
2868 | - public $event_details_control_type; |
|
2869 | - |
|
2870 | - /** |
|
2871 | - * @var string $event_details_map_align |
|
2872 | - */ |
|
2873 | - public $event_details_map_align; |
|
2874 | - |
|
2875 | - /** |
|
2876 | - * @var int $event_list_map_width |
|
2877 | - */ |
|
2878 | - public $event_list_map_width; |
|
2879 | - |
|
2880 | - /** |
|
2881 | - * @var int $event_list_map_height |
|
2882 | - */ |
|
2883 | - public $event_list_map_height; |
|
2884 | - |
|
2885 | - /** |
|
2886 | - * @var int $event_list_map_zoom |
|
2887 | - */ |
|
2888 | - public $event_list_map_zoom; |
|
2889 | - |
|
2890 | - /** |
|
2891 | - * @var boolean $event_list_display_nav |
|
2892 | - */ |
|
2893 | - public $event_list_display_nav; |
|
2894 | - |
|
2895 | - /** |
|
2896 | - * @var boolean $event_list_nav_size |
|
2897 | - */ |
|
2898 | - public $event_list_nav_size; |
|
2899 | - |
|
2900 | - /** |
|
2901 | - * @var string $event_list_control_type |
|
2902 | - */ |
|
2903 | - public $event_list_control_type; |
|
2904 | - |
|
2905 | - /** |
|
2906 | - * @var string $event_list_map_align |
|
2907 | - */ |
|
2908 | - public $event_list_map_align; |
|
2909 | - |
|
2910 | - |
|
2911 | - /** |
|
2912 | - * class constructor |
|
2913 | - * |
|
2914 | - * @access public |
|
2915 | - */ |
|
2916 | - public function __construct() |
|
2917 | - { |
|
2918 | - // set default map settings |
|
2919 | - $this->use_google_maps = true; |
|
2920 | - $this->google_map_api_key = ''; |
|
2921 | - // for event details pages (reg page) |
|
2922 | - $this->event_details_map_width = 585; // ee_map_width_single |
|
2923 | - $this->event_details_map_height = 362; // ee_map_height_single |
|
2924 | - $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
2925 | - $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
2926 | - $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
2927 | - $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
2928 | - $this->event_details_map_align = 'center'; // ee_map_align_single |
|
2929 | - // for event list pages |
|
2930 | - $this->event_list_map_width = 300; // ee_map_width |
|
2931 | - $this->event_list_map_height = 185; // ee_map_height |
|
2932 | - $this->event_list_map_zoom = 12; // ee_map_zoom |
|
2933 | - $this->event_list_display_nav = false; // ee_map_nav_display |
|
2934 | - $this->event_list_nav_size = true; // ee_map_nav_size |
|
2935 | - $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
2936 | - $this->event_list_map_align = 'center'; // ee_map_align |
|
2937 | - } |
|
2830 | + /** |
|
2831 | + * @var boolean $use_google_maps |
|
2832 | + */ |
|
2833 | + public $use_google_maps; |
|
2834 | + |
|
2835 | + /** |
|
2836 | + * @var string $api_key |
|
2837 | + */ |
|
2838 | + public $google_map_api_key; |
|
2839 | + |
|
2840 | + /** |
|
2841 | + * @var int $event_details_map_width |
|
2842 | + */ |
|
2843 | + public $event_details_map_width; |
|
2844 | + |
|
2845 | + /** |
|
2846 | + * @var int $event_details_map_height |
|
2847 | + */ |
|
2848 | + public $event_details_map_height; |
|
2849 | + |
|
2850 | + /** |
|
2851 | + * @var int $event_details_map_zoom |
|
2852 | + */ |
|
2853 | + public $event_details_map_zoom; |
|
2854 | + |
|
2855 | + /** |
|
2856 | + * @var boolean $event_details_display_nav |
|
2857 | + */ |
|
2858 | + public $event_details_display_nav; |
|
2859 | + |
|
2860 | + /** |
|
2861 | + * @var boolean $event_details_nav_size |
|
2862 | + */ |
|
2863 | + public $event_details_nav_size; |
|
2864 | + |
|
2865 | + /** |
|
2866 | + * @var string $event_details_control_type |
|
2867 | + */ |
|
2868 | + public $event_details_control_type; |
|
2869 | + |
|
2870 | + /** |
|
2871 | + * @var string $event_details_map_align |
|
2872 | + */ |
|
2873 | + public $event_details_map_align; |
|
2874 | + |
|
2875 | + /** |
|
2876 | + * @var int $event_list_map_width |
|
2877 | + */ |
|
2878 | + public $event_list_map_width; |
|
2879 | + |
|
2880 | + /** |
|
2881 | + * @var int $event_list_map_height |
|
2882 | + */ |
|
2883 | + public $event_list_map_height; |
|
2884 | + |
|
2885 | + /** |
|
2886 | + * @var int $event_list_map_zoom |
|
2887 | + */ |
|
2888 | + public $event_list_map_zoom; |
|
2889 | + |
|
2890 | + /** |
|
2891 | + * @var boolean $event_list_display_nav |
|
2892 | + */ |
|
2893 | + public $event_list_display_nav; |
|
2894 | + |
|
2895 | + /** |
|
2896 | + * @var boolean $event_list_nav_size |
|
2897 | + */ |
|
2898 | + public $event_list_nav_size; |
|
2899 | + |
|
2900 | + /** |
|
2901 | + * @var string $event_list_control_type |
|
2902 | + */ |
|
2903 | + public $event_list_control_type; |
|
2904 | + |
|
2905 | + /** |
|
2906 | + * @var string $event_list_map_align |
|
2907 | + */ |
|
2908 | + public $event_list_map_align; |
|
2909 | + |
|
2910 | + |
|
2911 | + /** |
|
2912 | + * class constructor |
|
2913 | + * |
|
2914 | + * @access public |
|
2915 | + */ |
|
2916 | + public function __construct() |
|
2917 | + { |
|
2918 | + // set default map settings |
|
2919 | + $this->use_google_maps = true; |
|
2920 | + $this->google_map_api_key = ''; |
|
2921 | + // for event details pages (reg page) |
|
2922 | + $this->event_details_map_width = 585; // ee_map_width_single |
|
2923 | + $this->event_details_map_height = 362; // ee_map_height_single |
|
2924 | + $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
2925 | + $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
2926 | + $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
2927 | + $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
2928 | + $this->event_details_map_align = 'center'; // ee_map_align_single |
|
2929 | + // for event list pages |
|
2930 | + $this->event_list_map_width = 300; // ee_map_width |
|
2931 | + $this->event_list_map_height = 185; // ee_map_height |
|
2932 | + $this->event_list_map_zoom = 12; // ee_map_zoom |
|
2933 | + $this->event_list_display_nav = false; // ee_map_nav_display |
|
2934 | + $this->event_list_nav_size = true; // ee_map_nav_size |
|
2935 | + $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
2936 | + $this->event_list_map_align = 'center'; // ee_map_align |
|
2937 | + } |
|
2938 | 2938 | } |
2939 | 2939 | |
2940 | 2940 | /** |
@@ -2942,46 +2942,46 @@ discard block |
||
2942 | 2942 | */ |
2943 | 2943 | class EE_Events_Archive_Config extends EE_Config_Base |
2944 | 2944 | { |
2945 | - public $display_status_banner; |
|
2945 | + public $display_status_banner; |
|
2946 | 2946 | |
2947 | - public $display_description; |
|
2947 | + public $display_description; |
|
2948 | 2948 | |
2949 | - public $display_ticket_selector; |
|
2949 | + public $display_ticket_selector; |
|
2950 | 2950 | |
2951 | - public $display_datetimes; |
|
2951 | + public $display_datetimes; |
|
2952 | 2952 | |
2953 | - public $display_venue; |
|
2953 | + public $display_venue; |
|
2954 | 2954 | |
2955 | - public $display_expired_events; |
|
2955 | + public $display_expired_events; |
|
2956 | 2956 | |
2957 | - public $use_sortable_display_order; |
|
2957 | + public $use_sortable_display_order; |
|
2958 | 2958 | |
2959 | - public $display_order_tickets; |
|
2959 | + public $display_order_tickets; |
|
2960 | 2960 | |
2961 | - public $display_order_datetimes; |
|
2961 | + public $display_order_datetimes; |
|
2962 | 2962 | |
2963 | - public $display_order_event; |
|
2963 | + public $display_order_event; |
|
2964 | 2964 | |
2965 | - public $display_order_venue; |
|
2965 | + public $display_order_venue; |
|
2966 | 2966 | |
2967 | 2967 | |
2968 | - /** |
|
2969 | - * class constructor |
|
2970 | - */ |
|
2971 | - public function __construct() |
|
2972 | - { |
|
2973 | - $this->display_status_banner = 0; |
|
2974 | - $this->display_description = 1; |
|
2975 | - $this->display_ticket_selector = 0; |
|
2976 | - $this->display_datetimes = 1; |
|
2977 | - $this->display_venue = 0; |
|
2978 | - $this->display_expired_events = 0; |
|
2979 | - $this->use_sortable_display_order = false; |
|
2980 | - $this->display_order_tickets = 100; |
|
2981 | - $this->display_order_datetimes = 110; |
|
2982 | - $this->display_order_event = 120; |
|
2983 | - $this->display_order_venue = 130; |
|
2984 | - } |
|
2968 | + /** |
|
2969 | + * class constructor |
|
2970 | + */ |
|
2971 | + public function __construct() |
|
2972 | + { |
|
2973 | + $this->display_status_banner = 0; |
|
2974 | + $this->display_description = 1; |
|
2975 | + $this->display_ticket_selector = 0; |
|
2976 | + $this->display_datetimes = 1; |
|
2977 | + $this->display_venue = 0; |
|
2978 | + $this->display_expired_events = 0; |
|
2979 | + $this->use_sortable_display_order = false; |
|
2980 | + $this->display_order_tickets = 100; |
|
2981 | + $this->display_order_datetimes = 110; |
|
2982 | + $this->display_order_event = 120; |
|
2983 | + $this->display_order_venue = 130; |
|
2984 | + } |
|
2985 | 2985 | } |
2986 | 2986 | |
2987 | 2987 | /** |
@@ -2989,34 +2989,34 @@ discard block |
||
2989 | 2989 | */ |
2990 | 2990 | class EE_Event_Single_Config extends EE_Config_Base |
2991 | 2991 | { |
2992 | - public $display_status_banner_single; |
|
2992 | + public $display_status_banner_single; |
|
2993 | 2993 | |
2994 | - public $display_venue; |
|
2994 | + public $display_venue; |
|
2995 | 2995 | |
2996 | - public $use_sortable_display_order; |
|
2996 | + public $use_sortable_display_order; |
|
2997 | 2997 | |
2998 | - public $display_order_tickets; |
|
2998 | + public $display_order_tickets; |
|
2999 | 2999 | |
3000 | - public $display_order_datetimes; |
|
3000 | + public $display_order_datetimes; |
|
3001 | 3001 | |
3002 | - public $display_order_event; |
|
3002 | + public $display_order_event; |
|
3003 | 3003 | |
3004 | - public $display_order_venue; |
|
3004 | + public $display_order_venue; |
|
3005 | 3005 | |
3006 | 3006 | |
3007 | - /** |
|
3008 | - * class constructor |
|
3009 | - */ |
|
3010 | - public function __construct() |
|
3011 | - { |
|
3012 | - $this->display_status_banner_single = 0; |
|
3013 | - $this->display_venue = 1; |
|
3014 | - $this->use_sortable_display_order = false; |
|
3015 | - $this->display_order_tickets = 100; |
|
3016 | - $this->display_order_datetimes = 110; |
|
3017 | - $this->display_order_event = 120; |
|
3018 | - $this->display_order_venue = 130; |
|
3019 | - } |
|
3007 | + /** |
|
3008 | + * class constructor |
|
3009 | + */ |
|
3010 | + public function __construct() |
|
3011 | + { |
|
3012 | + $this->display_status_banner_single = 0; |
|
3013 | + $this->display_venue = 1; |
|
3014 | + $this->use_sortable_display_order = false; |
|
3015 | + $this->display_order_tickets = 100; |
|
3016 | + $this->display_order_datetimes = 110; |
|
3017 | + $this->display_order_event = 120; |
|
3018 | + $this->display_order_venue = 130; |
|
3019 | + } |
|
3020 | 3020 | } |
3021 | 3021 | |
3022 | 3022 | /** |
@@ -3024,172 +3024,172 @@ discard block |
||
3024 | 3024 | */ |
3025 | 3025 | class EE_Ticket_Selector_Config extends EE_Config_Base |
3026 | 3026 | { |
3027 | - /** |
|
3028 | - * constant to indicate that a datetime selector should NEVER be shown for ticket selectors |
|
3029 | - */ |
|
3030 | - const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector'; |
|
3031 | - |
|
3032 | - /** |
|
3033 | - * constant to indicate that a datetime selector should only be shown for ticket selectors |
|
3034 | - * when the number of datetimes for the event matches the value set for $datetime_selector_threshold |
|
3035 | - */ |
|
3036 | - const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector'; |
|
3037 | - |
|
3038 | - /** |
|
3039 | - * @var boolean $show_ticket_sale_columns |
|
3040 | - */ |
|
3041 | - public $show_ticket_sale_columns; |
|
3042 | - |
|
3043 | - /** |
|
3044 | - * @var boolean $show_ticket_details |
|
3045 | - */ |
|
3046 | - public $show_ticket_details; |
|
3047 | - |
|
3048 | - /** |
|
3049 | - * @var boolean $show_expired_tickets |
|
3050 | - */ |
|
3051 | - public $show_expired_tickets; |
|
3052 | - |
|
3053 | - /** |
|
3054 | - * whether to display a dropdown box populated with event datetimes |
|
3055 | - * that toggles which tickets are displayed for a ticket selector. |
|
3056 | - * uses one of the *_DATETIME_SELECTOR constants defined above |
|
3057 | - * |
|
3058 | - * @var string $show_datetime_selector |
|
3059 | - */ |
|
3060 | - private $show_datetime_selector = 'no_datetime_selector'; |
|
3061 | - |
|
3062 | - /** |
|
3063 | - * the number of datetimes an event has to have before conditionally displaying a datetime selector |
|
3064 | - * |
|
3065 | - * @var int $datetime_selector_threshold |
|
3066 | - */ |
|
3067 | - private $datetime_selector_threshold = 3; |
|
3068 | - |
|
3069 | - /** |
|
3070 | - * determines the maximum number of "checked" dates in the date and time filter |
|
3071 | - * |
|
3072 | - * @var int $datetime_selector_checked |
|
3073 | - */ |
|
3074 | - private $datetime_selector_max_checked = 10; |
|
3075 | - |
|
3076 | - |
|
3077 | - /** |
|
3078 | - * class constructor |
|
3079 | - */ |
|
3080 | - public function __construct() |
|
3081 | - { |
|
3082 | - $this->show_ticket_sale_columns = true; |
|
3083 | - $this->show_ticket_details = true; |
|
3084 | - $this->show_expired_tickets = true; |
|
3085 | - $this->show_datetime_selector = EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
3086 | - $this->datetime_selector_threshold = 3; |
|
3087 | - $this->datetime_selector_max_checked = 10; |
|
3088 | - } |
|
3089 | - |
|
3090 | - |
|
3091 | - /** |
|
3092 | - * returns true if a datetime selector should be displayed |
|
3093 | - * |
|
3094 | - * @param array $datetimes |
|
3095 | - * @return bool |
|
3096 | - */ |
|
3097 | - public function showDatetimeSelector(array $datetimes) |
|
3098 | - { |
|
3099 | - // if the settings are NOT: don't show OR below threshold, THEN active = true |
|
3100 | - return ! ( |
|
3101 | - $this->getShowDatetimeSelector() === EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
3102 | - || ( |
|
3103 | - $this->getShowDatetimeSelector() === EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR |
|
3104 | - && count($datetimes) < $this->getDatetimeSelectorThreshold() |
|
3105 | - ) |
|
3106 | - ); |
|
3107 | - } |
|
3108 | - |
|
3109 | - |
|
3110 | - /** |
|
3111 | - * @return string |
|
3112 | - */ |
|
3113 | - public function getShowDatetimeSelector() |
|
3114 | - { |
|
3115 | - return $this->show_datetime_selector; |
|
3116 | - } |
|
3117 | - |
|
3118 | - |
|
3119 | - /** |
|
3120 | - * @param bool $keys_only |
|
3121 | - * @return array |
|
3122 | - */ |
|
3123 | - public function getShowDatetimeSelectorOptions($keys_only = true) |
|
3124 | - { |
|
3125 | - return $keys_only |
|
3126 | - ? array( |
|
3127 | - EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR, |
|
3128 | - EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR, |
|
3129 | - ) |
|
3130 | - : array( |
|
3131 | - EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__( |
|
3132 | - 'Do not show date & time filter', |
|
3133 | - 'event_espresso' |
|
3134 | - ), |
|
3135 | - EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__( |
|
3136 | - 'Maybe show date & time filter', |
|
3137 | - 'event_espresso' |
|
3138 | - ), |
|
3139 | - ); |
|
3140 | - } |
|
3141 | - |
|
3142 | - |
|
3143 | - /** |
|
3144 | - * @param string $show_datetime_selector |
|
3145 | - */ |
|
3146 | - public function setShowDatetimeSelector($show_datetime_selector) |
|
3147 | - { |
|
3148 | - $this->show_datetime_selector = in_array( |
|
3149 | - $show_datetime_selector, |
|
3150 | - $this->getShowDatetimeSelectorOptions(), |
|
3151 | - true |
|
3152 | - ) |
|
3153 | - ? $show_datetime_selector |
|
3154 | - : EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
3155 | - } |
|
3156 | - |
|
3157 | - |
|
3158 | - /** |
|
3159 | - * @return int |
|
3160 | - */ |
|
3161 | - public function getDatetimeSelectorThreshold() |
|
3162 | - { |
|
3163 | - return $this->datetime_selector_threshold; |
|
3164 | - } |
|
3165 | - |
|
3166 | - |
|
3167 | - /** |
|
3168 | - * @param int $datetime_selector_threshold |
|
3169 | - */ |
|
3170 | - public function setDatetimeSelectorThreshold($datetime_selector_threshold) |
|
3171 | - { |
|
3172 | - $datetime_selector_threshold = absint($datetime_selector_threshold); |
|
3173 | - $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3; |
|
3174 | - } |
|
3175 | - |
|
3176 | - |
|
3177 | - /** |
|
3178 | - * @return int |
|
3179 | - */ |
|
3180 | - public function getDatetimeSelectorMaxChecked() |
|
3181 | - { |
|
3182 | - return $this->datetime_selector_max_checked; |
|
3183 | - } |
|
3184 | - |
|
3185 | - |
|
3186 | - /** |
|
3187 | - * @param int $datetime_selector_max_checked |
|
3188 | - */ |
|
3189 | - public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked) |
|
3190 | - { |
|
3191 | - $this->datetime_selector_max_checked = absint($datetime_selector_max_checked); |
|
3192 | - } |
|
3027 | + /** |
|
3028 | + * constant to indicate that a datetime selector should NEVER be shown for ticket selectors |
|
3029 | + */ |
|
3030 | + const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector'; |
|
3031 | + |
|
3032 | + /** |
|
3033 | + * constant to indicate that a datetime selector should only be shown for ticket selectors |
|
3034 | + * when the number of datetimes for the event matches the value set for $datetime_selector_threshold |
|
3035 | + */ |
|
3036 | + const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector'; |
|
3037 | + |
|
3038 | + /** |
|
3039 | + * @var boolean $show_ticket_sale_columns |
|
3040 | + */ |
|
3041 | + public $show_ticket_sale_columns; |
|
3042 | + |
|
3043 | + /** |
|
3044 | + * @var boolean $show_ticket_details |
|
3045 | + */ |
|
3046 | + public $show_ticket_details; |
|
3047 | + |
|
3048 | + /** |
|
3049 | + * @var boolean $show_expired_tickets |
|
3050 | + */ |
|
3051 | + public $show_expired_tickets; |
|
3052 | + |
|
3053 | + /** |
|
3054 | + * whether to display a dropdown box populated with event datetimes |
|
3055 | + * that toggles which tickets are displayed for a ticket selector. |
|
3056 | + * uses one of the *_DATETIME_SELECTOR constants defined above |
|
3057 | + * |
|
3058 | + * @var string $show_datetime_selector |
|
3059 | + */ |
|
3060 | + private $show_datetime_selector = 'no_datetime_selector'; |
|
3061 | + |
|
3062 | + /** |
|
3063 | + * the number of datetimes an event has to have before conditionally displaying a datetime selector |
|
3064 | + * |
|
3065 | + * @var int $datetime_selector_threshold |
|
3066 | + */ |
|
3067 | + private $datetime_selector_threshold = 3; |
|
3068 | + |
|
3069 | + /** |
|
3070 | + * determines the maximum number of "checked" dates in the date and time filter |
|
3071 | + * |
|
3072 | + * @var int $datetime_selector_checked |
|
3073 | + */ |
|
3074 | + private $datetime_selector_max_checked = 10; |
|
3075 | + |
|
3076 | + |
|
3077 | + /** |
|
3078 | + * class constructor |
|
3079 | + */ |
|
3080 | + public function __construct() |
|
3081 | + { |
|
3082 | + $this->show_ticket_sale_columns = true; |
|
3083 | + $this->show_ticket_details = true; |
|
3084 | + $this->show_expired_tickets = true; |
|
3085 | + $this->show_datetime_selector = EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
3086 | + $this->datetime_selector_threshold = 3; |
|
3087 | + $this->datetime_selector_max_checked = 10; |
|
3088 | + } |
|
3089 | + |
|
3090 | + |
|
3091 | + /** |
|
3092 | + * returns true if a datetime selector should be displayed |
|
3093 | + * |
|
3094 | + * @param array $datetimes |
|
3095 | + * @return bool |
|
3096 | + */ |
|
3097 | + public function showDatetimeSelector(array $datetimes) |
|
3098 | + { |
|
3099 | + // if the settings are NOT: don't show OR below threshold, THEN active = true |
|
3100 | + return ! ( |
|
3101 | + $this->getShowDatetimeSelector() === EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
3102 | + || ( |
|
3103 | + $this->getShowDatetimeSelector() === EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR |
|
3104 | + && count($datetimes) < $this->getDatetimeSelectorThreshold() |
|
3105 | + ) |
|
3106 | + ); |
|
3107 | + } |
|
3108 | + |
|
3109 | + |
|
3110 | + /** |
|
3111 | + * @return string |
|
3112 | + */ |
|
3113 | + public function getShowDatetimeSelector() |
|
3114 | + { |
|
3115 | + return $this->show_datetime_selector; |
|
3116 | + } |
|
3117 | + |
|
3118 | + |
|
3119 | + /** |
|
3120 | + * @param bool $keys_only |
|
3121 | + * @return array |
|
3122 | + */ |
|
3123 | + public function getShowDatetimeSelectorOptions($keys_only = true) |
|
3124 | + { |
|
3125 | + return $keys_only |
|
3126 | + ? array( |
|
3127 | + EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR, |
|
3128 | + EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR, |
|
3129 | + ) |
|
3130 | + : array( |
|
3131 | + EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__( |
|
3132 | + 'Do not show date & time filter', |
|
3133 | + 'event_espresso' |
|
3134 | + ), |
|
3135 | + EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__( |
|
3136 | + 'Maybe show date & time filter', |
|
3137 | + 'event_espresso' |
|
3138 | + ), |
|
3139 | + ); |
|
3140 | + } |
|
3141 | + |
|
3142 | + |
|
3143 | + /** |
|
3144 | + * @param string $show_datetime_selector |
|
3145 | + */ |
|
3146 | + public function setShowDatetimeSelector($show_datetime_selector) |
|
3147 | + { |
|
3148 | + $this->show_datetime_selector = in_array( |
|
3149 | + $show_datetime_selector, |
|
3150 | + $this->getShowDatetimeSelectorOptions(), |
|
3151 | + true |
|
3152 | + ) |
|
3153 | + ? $show_datetime_selector |
|
3154 | + : EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
3155 | + } |
|
3156 | + |
|
3157 | + |
|
3158 | + /** |
|
3159 | + * @return int |
|
3160 | + */ |
|
3161 | + public function getDatetimeSelectorThreshold() |
|
3162 | + { |
|
3163 | + return $this->datetime_selector_threshold; |
|
3164 | + } |
|
3165 | + |
|
3166 | + |
|
3167 | + /** |
|
3168 | + * @param int $datetime_selector_threshold |
|
3169 | + */ |
|
3170 | + public function setDatetimeSelectorThreshold($datetime_selector_threshold) |
|
3171 | + { |
|
3172 | + $datetime_selector_threshold = absint($datetime_selector_threshold); |
|
3173 | + $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3; |
|
3174 | + } |
|
3175 | + |
|
3176 | + |
|
3177 | + /** |
|
3178 | + * @return int |
|
3179 | + */ |
|
3180 | + public function getDatetimeSelectorMaxChecked() |
|
3181 | + { |
|
3182 | + return $this->datetime_selector_max_checked; |
|
3183 | + } |
|
3184 | + |
|
3185 | + |
|
3186 | + /** |
|
3187 | + * @param int $datetime_selector_max_checked |
|
3188 | + */ |
|
3189 | + public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked) |
|
3190 | + { |
|
3191 | + $this->datetime_selector_max_checked = absint($datetime_selector_max_checked); |
|
3192 | + } |
|
3193 | 3193 | } |
3194 | 3194 | |
3195 | 3195 | /** |
@@ -3201,79 +3201,79 @@ discard block |
||
3201 | 3201 | */ |
3202 | 3202 | class EE_Environment_Config extends EE_Config_Base |
3203 | 3203 | { |
3204 | - /** |
|
3205 | - * Hold any php environment variables that we want to track. |
|
3206 | - * |
|
3207 | - * @var stdClass; |
|
3208 | - */ |
|
3209 | - public $php; |
|
3210 | - |
|
3211 | - |
|
3212 | - /** |
|
3213 | - * constructor |
|
3214 | - */ |
|
3215 | - public function __construct() |
|
3216 | - { |
|
3217 | - $this->php = new stdClass(); |
|
3218 | - $this->_set_php_values(); |
|
3219 | - } |
|
3220 | - |
|
3221 | - |
|
3222 | - /** |
|
3223 | - * This sets the php environment variables. |
|
3224 | - * |
|
3225 | - * @since 4.4.0 |
|
3226 | - * @return void |
|
3227 | - */ |
|
3228 | - protected function _set_php_values() |
|
3229 | - { |
|
3230 | - $this->php->max_input_vars = ini_get('max_input_vars'); |
|
3231 | - $this->php->version = phpversion(); |
|
3232 | - } |
|
3233 | - |
|
3234 | - |
|
3235 | - /** |
|
3236 | - * helper method for determining whether input_count is |
|
3237 | - * reaching the potential maximum the server can handle |
|
3238 | - * according to max_input_vars |
|
3239 | - * |
|
3240 | - * @param int $input_count the count of input vars. |
|
3241 | - * @return string error message |
|
3242 | - */ |
|
3243 | - public function max_input_vars_limit_check($input_count = 0) |
|
3244 | - { |
|
3245 | - if ( |
|
3246 | - ! empty($this->php->max_input_vars) |
|
3247 | - && ($input_count >= $this->php->max_input_vars) |
|
3248 | - ) { |
|
3249 | - // check the server setting because the config value could be stale |
|
3250 | - $max_input_vars = ini_get('max_input_vars'); |
|
3251 | - if ($input_count >= $max_input_vars) { |
|
3252 | - return sprintf( |
|
3253 | - esc_html__( |
|
3254 | - 'The maximum number of inputs on this page has been exceeded. You cannot make edits to this page because of your server\'s PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.%1$sPlease contact your web host and ask them to raise the "max_input_vars" limit.', |
|
3255 | - 'event_espresso' |
|
3256 | - ), |
|
3257 | - '<br>', |
|
3258 | - $input_count, |
|
3259 | - $max_input_vars |
|
3260 | - ); |
|
3261 | - } |
|
3262 | - } |
|
3263 | - return ''; |
|
3264 | - } |
|
3265 | - |
|
3266 | - |
|
3267 | - /** |
|
3268 | - * The purpose of this method is just to force rechecking php values so if they've changed, they get updated. |
|
3269 | - * |
|
3270 | - * @since 4.4.1 |
|
3271 | - * @return void |
|
3272 | - */ |
|
3273 | - public function recheck_values() |
|
3274 | - { |
|
3275 | - $this->_set_php_values(); |
|
3276 | - } |
|
3204 | + /** |
|
3205 | + * Hold any php environment variables that we want to track. |
|
3206 | + * |
|
3207 | + * @var stdClass; |
|
3208 | + */ |
|
3209 | + public $php; |
|
3210 | + |
|
3211 | + |
|
3212 | + /** |
|
3213 | + * constructor |
|
3214 | + */ |
|
3215 | + public function __construct() |
|
3216 | + { |
|
3217 | + $this->php = new stdClass(); |
|
3218 | + $this->_set_php_values(); |
|
3219 | + } |
|
3220 | + |
|
3221 | + |
|
3222 | + /** |
|
3223 | + * This sets the php environment variables. |
|
3224 | + * |
|
3225 | + * @since 4.4.0 |
|
3226 | + * @return void |
|
3227 | + */ |
|
3228 | + protected function _set_php_values() |
|
3229 | + { |
|
3230 | + $this->php->max_input_vars = ini_get('max_input_vars'); |
|
3231 | + $this->php->version = phpversion(); |
|
3232 | + } |
|
3233 | + |
|
3234 | + |
|
3235 | + /** |
|
3236 | + * helper method for determining whether input_count is |
|
3237 | + * reaching the potential maximum the server can handle |
|
3238 | + * according to max_input_vars |
|
3239 | + * |
|
3240 | + * @param int $input_count the count of input vars. |
|
3241 | + * @return string error message |
|
3242 | + */ |
|
3243 | + public function max_input_vars_limit_check($input_count = 0) |
|
3244 | + { |
|
3245 | + if ( |
|
3246 | + ! empty($this->php->max_input_vars) |
|
3247 | + && ($input_count >= $this->php->max_input_vars) |
|
3248 | + ) { |
|
3249 | + // check the server setting because the config value could be stale |
|
3250 | + $max_input_vars = ini_get('max_input_vars'); |
|
3251 | + if ($input_count >= $max_input_vars) { |
|
3252 | + return sprintf( |
|
3253 | + esc_html__( |
|
3254 | + 'The maximum number of inputs on this page has been exceeded. You cannot make edits to this page because of your server\'s PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.%1$sPlease contact your web host and ask them to raise the "max_input_vars" limit.', |
|
3255 | + 'event_espresso' |
|
3256 | + ), |
|
3257 | + '<br>', |
|
3258 | + $input_count, |
|
3259 | + $max_input_vars |
|
3260 | + ); |
|
3261 | + } |
|
3262 | + } |
|
3263 | + return ''; |
|
3264 | + } |
|
3265 | + |
|
3266 | + |
|
3267 | + /** |
|
3268 | + * The purpose of this method is just to force rechecking php values so if they've changed, they get updated. |
|
3269 | + * |
|
3270 | + * @since 4.4.1 |
|
3271 | + * @return void |
|
3272 | + */ |
|
3273 | + public function recheck_values() |
|
3274 | + { |
|
3275 | + $this->_set_php_values(); |
|
3276 | + } |
|
3277 | 3277 | } |
3278 | 3278 | |
3279 | 3279 | /** |
@@ -3285,21 +3285,21 @@ discard block |
||
3285 | 3285 | */ |
3286 | 3286 | class EE_Tax_Config extends EE_Config_Base |
3287 | 3287 | { |
3288 | - /* |
|
3288 | + /* |
|
3289 | 3289 | * flag to indicate whether to display ticket prices with the taxes included |
3290 | 3290 | * |
3291 | 3291 | * @var boolean $prices_displayed_including_taxes |
3292 | 3292 | */ |
3293 | - public $prices_displayed_including_taxes; |
|
3293 | + public $prices_displayed_including_taxes; |
|
3294 | 3294 | |
3295 | 3295 | |
3296 | - /** |
|
3297 | - * class constructor |
|
3298 | - */ |
|
3299 | - public function __construct() |
|
3300 | - { |
|
3301 | - $this->prices_displayed_including_taxes = true; |
|
3302 | - } |
|
3296 | + /** |
|
3297 | + * class constructor |
|
3298 | + */ |
|
3299 | + public function __construct() |
|
3300 | + { |
|
3301 | + $this->prices_displayed_including_taxes = true; |
|
3302 | + } |
|
3303 | 3303 | } |
3304 | 3304 | |
3305 | 3305 | /** |
@@ -3312,19 +3312,19 @@ discard block |
||
3312 | 3312 | */ |
3313 | 3313 | class EE_Messages_Config extends EE_Config_Base |
3314 | 3314 | { |
3315 | - /** |
|
3316 | - * This is an integer representing the deletion threshold in months for when old messages will get deleted. |
|
3317 | - * A value of 0 represents never deleting. Default is 0. |
|
3318 | - * |
|
3319 | - * @var integer |
|
3320 | - */ |
|
3321 | - public $delete_threshold; |
|
3322 | - |
|
3323 | - |
|
3324 | - public function __construct() |
|
3325 | - { |
|
3326 | - $this->delete_threshold = 0; |
|
3327 | - } |
|
3315 | + /** |
|
3316 | + * This is an integer representing the deletion threshold in months for when old messages will get deleted. |
|
3317 | + * A value of 0 represents never deleting. Default is 0. |
|
3318 | + * |
|
3319 | + * @var integer |
|
3320 | + */ |
|
3321 | + public $delete_threshold; |
|
3322 | + |
|
3323 | + |
|
3324 | + public function __construct() |
|
3325 | + { |
|
3326 | + $this->delete_threshold = 0; |
|
3327 | + } |
|
3328 | 3328 | } |
3329 | 3329 | |
3330 | 3330 | /** |
@@ -3334,31 +3334,31 @@ discard block |
||
3334 | 3334 | */ |
3335 | 3335 | class EE_Gateway_Config extends EE_Config_Base |
3336 | 3336 | { |
3337 | - /** |
|
3338 | - * Array with keys that are payment gateways slugs, and values are arrays |
|
3339 | - * with any config info the gateway wants to store |
|
3340 | - * |
|
3341 | - * @var array |
|
3342 | - */ |
|
3343 | - public $payment_settings; |
|
3344 | - |
|
3345 | - /** |
|
3346 | - * Where keys are gateway slugs, and values are booleans indicating whether |
|
3347 | - * the gateway is stored in the uploads directory |
|
3348 | - * |
|
3349 | - * @var array |
|
3350 | - */ |
|
3351 | - public $active_gateways; |
|
3352 | - |
|
3353 | - |
|
3354 | - /** |
|
3355 | - * class constructor |
|
3356 | - * |
|
3357 | - * @deprecated |
|
3358 | - */ |
|
3359 | - public function __construct() |
|
3360 | - { |
|
3361 | - $this->payment_settings = array(); |
|
3362 | - $this->active_gateways = array('Invoice' => false); |
|
3363 | - } |
|
3337 | + /** |
|
3338 | + * Array with keys that are payment gateways slugs, and values are arrays |
|
3339 | + * with any config info the gateway wants to store |
|
3340 | + * |
|
3341 | + * @var array |
|
3342 | + */ |
|
3343 | + public $payment_settings; |
|
3344 | + |
|
3345 | + /** |
|
3346 | + * Where keys are gateway slugs, and values are booleans indicating whether |
|
3347 | + * the gateway is stored in the uploads directory |
|
3348 | + * |
|
3349 | + * @var array |
|
3350 | + */ |
|
3351 | + public $active_gateways; |
|
3352 | + |
|
3353 | + |
|
3354 | + /** |
|
3355 | + * class constructor |
|
3356 | + * |
|
3357 | + * @deprecated |
|
3358 | + */ |
|
3359 | + public function __construct() |
|
3360 | + { |
|
3361 | + $this->payment_settings = array(); |
|
3362 | + $this->active_gateways = array('Invoice' => false); |
|
3363 | + } |
|
3364 | 3364 | } |
@@ -12,298 +12,298 @@ |
||
12 | 12 | */ |
13 | 13 | class AllowedTags |
14 | 14 | { |
15 | - private static array $attributes = [ |
|
16 | - 'accept-charset' => true, |
|
17 | - 'action' => true, |
|
18 | - 'alt' => true, |
|
19 | - 'allow' => true, |
|
20 | - 'allowfullscreen' => true, |
|
21 | - 'align' => true, |
|
22 | - 'aria-controls' => true, |
|
23 | - 'aria-current' => true, |
|
24 | - 'aria-describedby' => true, |
|
25 | - 'aria-details' => true, |
|
26 | - 'aria-expanded' => true, |
|
27 | - 'aria-hidden' => true, |
|
28 | - 'aria-label' => true, |
|
29 | - 'aria-labelledby' => true, |
|
30 | - 'aria-live' => true, |
|
31 | - 'autocomplete' => true, |
|
32 | - 'bgcolor' => true, |
|
33 | - 'border' => true, |
|
34 | - 'cellpadding' => true, |
|
35 | - 'cellspacing' => true, |
|
36 | - 'checked' => true, |
|
37 | - 'class' => true, |
|
38 | - 'cols' => true, |
|
39 | - 'content' => true, |
|
40 | - 'data-*' => true, |
|
41 | - 'dir' => true, |
|
42 | - 'disabled' => true, |
|
43 | - 'enctype' => true, |
|
44 | - 'extension' => true, |
|
45 | - 'for' => true, |
|
46 | - 'frameborder' => true, |
|
47 | - 'height' => true, |
|
48 | - 'href' => true, |
|
49 | - 'id' => true, |
|
50 | - 'itemprop' => true, |
|
51 | - 'itemscope' => true, |
|
52 | - 'itemtype' => true, |
|
53 | - 'label' => true, |
|
54 | - 'lang' => true, |
|
55 | - 'leftmargin' => true, |
|
56 | - 'marginheight' => true, |
|
57 | - 'marginwidth' => true, |
|
58 | - 'max' => true, |
|
59 | - 'maxlength' => true, |
|
60 | - 'media' => true, |
|
61 | - 'method' => true, |
|
62 | - 'min' => true, |
|
63 | - 'multiple' => true, |
|
64 | - 'name' => true, |
|
65 | - 'novalidate' => true, |
|
66 | - 'onclick' => true, |
|
67 | - 'placeholder' => true, |
|
68 | - 'property' => true, |
|
69 | - 'readonly' => true, |
|
70 | - 'rel' => true, |
|
71 | - 'required' => true, |
|
72 | - 'rows' => true, |
|
73 | - 'selected' => true, |
|
74 | - 'src' => true, |
|
75 | - 'size' => true, |
|
76 | - 'style' => true, |
|
77 | - 'step' => true, |
|
78 | - 'tabindex' => true, |
|
79 | - 'target' => true, |
|
80 | - 'title' => true, |
|
81 | - 'topmargin' => true, |
|
82 | - 'type' => true, |
|
83 | - 'value' => true, |
|
84 | - 'width' => true, |
|
85 | - 'http-equiv' => true, |
|
86 | - ]; |
|
15 | + private static array $attributes = [ |
|
16 | + 'accept-charset' => true, |
|
17 | + 'action' => true, |
|
18 | + 'alt' => true, |
|
19 | + 'allow' => true, |
|
20 | + 'allowfullscreen' => true, |
|
21 | + 'align' => true, |
|
22 | + 'aria-controls' => true, |
|
23 | + 'aria-current' => true, |
|
24 | + 'aria-describedby' => true, |
|
25 | + 'aria-details' => true, |
|
26 | + 'aria-expanded' => true, |
|
27 | + 'aria-hidden' => true, |
|
28 | + 'aria-label' => true, |
|
29 | + 'aria-labelledby' => true, |
|
30 | + 'aria-live' => true, |
|
31 | + 'autocomplete' => true, |
|
32 | + 'bgcolor' => true, |
|
33 | + 'border' => true, |
|
34 | + 'cellpadding' => true, |
|
35 | + 'cellspacing' => true, |
|
36 | + 'checked' => true, |
|
37 | + 'class' => true, |
|
38 | + 'cols' => true, |
|
39 | + 'content' => true, |
|
40 | + 'data-*' => true, |
|
41 | + 'dir' => true, |
|
42 | + 'disabled' => true, |
|
43 | + 'enctype' => true, |
|
44 | + 'extension' => true, |
|
45 | + 'for' => true, |
|
46 | + 'frameborder' => true, |
|
47 | + 'height' => true, |
|
48 | + 'href' => true, |
|
49 | + 'id' => true, |
|
50 | + 'itemprop' => true, |
|
51 | + 'itemscope' => true, |
|
52 | + 'itemtype' => true, |
|
53 | + 'label' => true, |
|
54 | + 'lang' => true, |
|
55 | + 'leftmargin' => true, |
|
56 | + 'marginheight' => true, |
|
57 | + 'marginwidth' => true, |
|
58 | + 'max' => true, |
|
59 | + 'maxlength' => true, |
|
60 | + 'media' => true, |
|
61 | + 'method' => true, |
|
62 | + 'min' => true, |
|
63 | + 'multiple' => true, |
|
64 | + 'name' => true, |
|
65 | + 'novalidate' => true, |
|
66 | + 'onclick' => true, |
|
67 | + 'placeholder' => true, |
|
68 | + 'property' => true, |
|
69 | + 'readonly' => true, |
|
70 | + 'rel' => true, |
|
71 | + 'required' => true, |
|
72 | + 'rows' => true, |
|
73 | + 'selected' => true, |
|
74 | + 'src' => true, |
|
75 | + 'size' => true, |
|
76 | + 'style' => true, |
|
77 | + 'step' => true, |
|
78 | + 'tabindex' => true, |
|
79 | + 'target' => true, |
|
80 | + 'title' => true, |
|
81 | + 'topmargin' => true, |
|
82 | + 'type' => true, |
|
83 | + 'value' => true, |
|
84 | + 'width' => true, |
|
85 | + 'http-equiv' => true, |
|
86 | + ]; |
|
87 | 87 | |
88 | - private static array $tags = [ |
|
89 | - 'a', |
|
90 | - 'abbr', |
|
91 | - 'b', |
|
92 | - 'br', |
|
93 | - 'code', |
|
94 | - 'div', |
|
95 | - 'em', |
|
96 | - 'h1', |
|
97 | - 'h2', |
|
98 | - 'h3', |
|
99 | - 'h4', |
|
100 | - 'h5', |
|
101 | - 'h6', |
|
102 | - 'hr', |
|
103 | - 'i', |
|
104 | - 'img', |
|
105 | - 'li', |
|
106 | - 'ol', |
|
107 | - 'p', |
|
108 | - 'pre', |
|
109 | - 'small', |
|
110 | - 'span', |
|
111 | - 'strong', |
|
112 | - 'table', |
|
113 | - 'td', |
|
114 | - 'tr', |
|
115 | - 'ul', |
|
116 | - ]; |
|
88 | + private static array $tags = [ |
|
89 | + 'a', |
|
90 | + 'abbr', |
|
91 | + 'b', |
|
92 | + 'br', |
|
93 | + 'code', |
|
94 | + 'div', |
|
95 | + 'em', |
|
96 | + 'h1', |
|
97 | + 'h2', |
|
98 | + 'h3', |
|
99 | + 'h4', |
|
100 | + 'h5', |
|
101 | + 'h6', |
|
102 | + 'hr', |
|
103 | + 'i', |
|
104 | + 'img', |
|
105 | + 'li', |
|
106 | + 'ol', |
|
107 | + 'p', |
|
108 | + 'pre', |
|
109 | + 'small', |
|
110 | + 'span', |
|
111 | + 'strong', |
|
112 | + 'table', |
|
113 | + 'td', |
|
114 | + 'tr', |
|
115 | + 'ul', |
|
116 | + ]; |
|
117 | 117 | |
118 | - private static array $allowed_tags = []; |
|
118 | + private static array $allowed_tags = []; |
|
119 | 119 | |
120 | - private static array $allowed_with_embed_tags = []; |
|
120 | + private static array $allowed_with_embed_tags = []; |
|
121 | 121 | |
122 | - private static array $allowed_with_form_tags = []; |
|
122 | + private static array $allowed_with_form_tags = []; |
|
123 | 123 | |
124 | - private static array $allowed_with_script_and_style_tags = []; |
|
124 | + private static array $allowed_with_script_and_style_tags = []; |
|
125 | 125 | |
126 | - private static array $allowed_with_full_tags = []; |
|
126 | + private static array $allowed_with_full_tags = []; |
|
127 | 127 | |
128 | 128 | |
129 | - /** |
|
130 | - * merges additional tags and attributes into the WP post tags |
|
131 | - */ |
|
132 | - private static function initializeAllowedTags() |
|
133 | - { |
|
134 | - $allowed_post_tags = wp_kses_allowed_html('post'); |
|
135 | - $allowed_tags = []; |
|
136 | - foreach (AllowedTags::$tags as $tag) { |
|
137 | - $allowed_tags[ $tag ] = AllowedTags::$attributes; |
|
138 | - } |
|
139 | - AllowedTags::$allowed_tags = array_merge_recursive($allowed_post_tags, $allowed_tags); |
|
140 | - } |
|
129 | + /** |
|
130 | + * merges additional tags and attributes into the WP post tags |
|
131 | + */ |
|
132 | + private static function initializeAllowedTags() |
|
133 | + { |
|
134 | + $allowed_post_tags = wp_kses_allowed_html('post'); |
|
135 | + $allowed_tags = []; |
|
136 | + foreach (AllowedTags::$tags as $tag) { |
|
137 | + $allowed_tags[ $tag ] = AllowedTags::$attributes; |
|
138 | + } |
|
139 | + AllowedTags::$allowed_tags = array_merge_recursive($allowed_post_tags, $allowed_tags); |
|
140 | + } |
|
141 | 141 | |
142 | 142 | |
143 | - /** |
|
144 | - * merges embed tags and attributes into the EE all tags |
|
145 | - */ |
|
146 | - private static function initializeWithEmbedTags() |
|
147 | - { |
|
148 | - $all_tags = AllowedTags::getAllowedTags(); |
|
149 | - $embed_tags = [ |
|
150 | - 'iframe' => AllowedTags::$attributes, |
|
151 | - ]; |
|
152 | - AllowedTags::$allowed_with_embed_tags = array_merge_recursive($all_tags, $embed_tags); |
|
153 | - } |
|
143 | + /** |
|
144 | + * merges embed tags and attributes into the EE all tags |
|
145 | + */ |
|
146 | + private static function initializeWithEmbedTags() |
|
147 | + { |
|
148 | + $all_tags = AllowedTags::getAllowedTags(); |
|
149 | + $embed_tags = [ |
|
150 | + 'iframe' => AllowedTags::$attributes, |
|
151 | + ]; |
|
152 | + AllowedTags::$allowed_with_embed_tags = array_merge_recursive($all_tags, $embed_tags); |
|
153 | + } |
|
154 | 154 | |
155 | 155 | |
156 | - /** |
|
157 | - * merges form tags and attributes into the EE all tags |
|
158 | - */ |
|
159 | - private static function initializeWithFormTags() |
|
160 | - { |
|
161 | - $all_tags = AllowedTags::getAllowedTags(); |
|
162 | - $form_tags = [ |
|
163 | - 'button' => AllowedTags::$attributes, |
|
164 | - 'fieldset' => AllowedTags::$attributes, |
|
165 | - 'form' => AllowedTags::$attributes, |
|
166 | - 'input' => AllowedTags::$attributes, |
|
167 | - 'label' => AllowedTags::$attributes, |
|
168 | - 'optgroup' => AllowedTags::$attributes, |
|
169 | - 'option' => AllowedTags::$attributes, |
|
170 | - 'output' => AllowedTags::$attributes, |
|
171 | - 'select' => AllowedTags::$attributes, |
|
172 | - 'textarea' => AllowedTags::$attributes, |
|
173 | - ]; |
|
174 | - AllowedTags::$allowed_with_form_tags = array_merge_recursive($all_tags, $form_tags); |
|
175 | - } |
|
156 | + /** |
|
157 | + * merges form tags and attributes into the EE all tags |
|
158 | + */ |
|
159 | + private static function initializeWithFormTags() |
|
160 | + { |
|
161 | + $all_tags = AllowedTags::getAllowedTags(); |
|
162 | + $form_tags = [ |
|
163 | + 'button' => AllowedTags::$attributes, |
|
164 | + 'fieldset' => AllowedTags::$attributes, |
|
165 | + 'form' => AllowedTags::$attributes, |
|
166 | + 'input' => AllowedTags::$attributes, |
|
167 | + 'label' => AllowedTags::$attributes, |
|
168 | + 'optgroup' => AllowedTags::$attributes, |
|
169 | + 'option' => AllowedTags::$attributes, |
|
170 | + 'output' => AllowedTags::$attributes, |
|
171 | + 'select' => AllowedTags::$attributes, |
|
172 | + 'textarea' => AllowedTags::$attributes, |
|
173 | + ]; |
|
174 | + AllowedTags::$allowed_with_form_tags = array_merge_recursive($all_tags, $form_tags); |
|
175 | + } |
|
176 | 176 | |
177 | 177 | |
178 | - /** |
|
179 | - * merges form script and style tags and attributes into the EE all tags |
|
180 | - */ |
|
181 | - private static function initializeWithScriptAndStyleTags() |
|
182 | - { |
|
183 | - $all_tags = AllowedTags::getAllowedTags(); |
|
184 | - $script_and_style_tags = [ |
|
185 | - 'link' => AllowedTags::$attributes, |
|
186 | - 'noscript' => AllowedTags::$attributes, |
|
187 | - 'script' => AllowedTags::$attributes, |
|
188 | - 'style' => AllowedTags::$attributes, |
|
189 | - ]; |
|
190 | - AllowedTags::$allowed_with_script_and_style_tags = array_merge_recursive($all_tags, $script_and_style_tags); |
|
191 | - } |
|
178 | + /** |
|
179 | + * merges form script and style tags and attributes into the EE all tags |
|
180 | + */ |
|
181 | + private static function initializeWithScriptAndStyleTags() |
|
182 | + { |
|
183 | + $all_tags = AllowedTags::getAllowedTags(); |
|
184 | + $script_and_style_tags = [ |
|
185 | + 'link' => AllowedTags::$attributes, |
|
186 | + 'noscript' => AllowedTags::$attributes, |
|
187 | + 'script' => AllowedTags::$attributes, |
|
188 | + 'style' => AllowedTags::$attributes, |
|
189 | + ]; |
|
190 | + AllowedTags::$allowed_with_script_and_style_tags = array_merge_recursive($all_tags, $script_and_style_tags); |
|
191 | + } |
|
192 | 192 | |
193 | 193 | |
194 | - /** |
|
195 | - * merges all head and body tags and attributes into the EE all tags |
|
196 | - */ |
|
197 | - private static function initializeWithFullTags() |
|
198 | - { |
|
199 | - $all_tags = AllowedTags::getAllowedTags(); |
|
200 | - $full_tags = [ |
|
201 | - 'body' => AllowedTags::$attributes, |
|
202 | - 'button' => AllowedTags::$attributes, |
|
203 | - 'circle' => [ |
|
204 | - 'cx' => true, |
|
205 | - 'cy' => true, |
|
206 | - 'fill' => true, |
|
207 | - 'r' => true, |
|
208 | - ], |
|
209 | - 'defs' => AllowedTags::$attributes, |
|
210 | - 'fieldset' => AllowedTags::$attributes, |
|
211 | - 'form' => AllowedTags::$attributes, |
|
212 | - 'g' => AllowedTags::$attributes, |
|
213 | - 'head' => AllowedTags::$attributes, |
|
214 | - 'html' => AllowedTags::$attributes, |
|
215 | - 'iframe' => AllowedTags::$attributes, |
|
216 | - 'input' => AllowedTags::$attributes, |
|
217 | - 'label' => AllowedTags::$attributes, |
|
218 | - 'link' => AllowedTags::$attributes, |
|
219 | - 'meta' => AllowedTags::$attributes, |
|
220 | - 'noscript' => AllowedTags::$attributes, |
|
221 | - 'optgroup' => AllowedTags::$attributes, |
|
222 | - 'option' => AllowedTags::$attributes, |
|
223 | - 'output' => AllowedTags::$attributes, |
|
224 | - 'path' => [ |
|
225 | - 'class' => true, |
|
226 | - 'd' => true |
|
227 | - ], |
|
228 | - 'script' => AllowedTags::$attributes, |
|
229 | - 'select' => AllowedTags::$attributes, |
|
230 | - 'style' => AllowedTags::$attributes, |
|
231 | - 'svg' => [ |
|
232 | - 'aria-hidden' => true, |
|
233 | - 'class' => true, |
|
234 | - 'display' => true, |
|
235 | - 'fill' => true, |
|
236 | - 'focusable' => true, |
|
237 | - 'height' => true, |
|
238 | - 'stroke' => true, |
|
239 | - 'stroke-width' => true, |
|
240 | - 'viewBox' => true, |
|
241 | - 'width' => true, |
|
242 | - 'xmlns' => true, |
|
243 | - ], |
|
244 | - 'textarea' => AllowedTags::$attributes, |
|
245 | - 'title' => AllowedTags::$attributes, |
|
246 | - ]; |
|
247 | - AllowedTags::$allowed_with_full_tags = array_merge_recursive($all_tags, $full_tags); |
|
248 | - } |
|
194 | + /** |
|
195 | + * merges all head and body tags and attributes into the EE all tags |
|
196 | + */ |
|
197 | + private static function initializeWithFullTags() |
|
198 | + { |
|
199 | + $all_tags = AllowedTags::getAllowedTags(); |
|
200 | + $full_tags = [ |
|
201 | + 'body' => AllowedTags::$attributes, |
|
202 | + 'button' => AllowedTags::$attributes, |
|
203 | + 'circle' => [ |
|
204 | + 'cx' => true, |
|
205 | + 'cy' => true, |
|
206 | + 'fill' => true, |
|
207 | + 'r' => true, |
|
208 | + ], |
|
209 | + 'defs' => AllowedTags::$attributes, |
|
210 | + 'fieldset' => AllowedTags::$attributes, |
|
211 | + 'form' => AllowedTags::$attributes, |
|
212 | + 'g' => AllowedTags::$attributes, |
|
213 | + 'head' => AllowedTags::$attributes, |
|
214 | + 'html' => AllowedTags::$attributes, |
|
215 | + 'iframe' => AllowedTags::$attributes, |
|
216 | + 'input' => AllowedTags::$attributes, |
|
217 | + 'label' => AllowedTags::$attributes, |
|
218 | + 'link' => AllowedTags::$attributes, |
|
219 | + 'meta' => AllowedTags::$attributes, |
|
220 | + 'noscript' => AllowedTags::$attributes, |
|
221 | + 'optgroup' => AllowedTags::$attributes, |
|
222 | + 'option' => AllowedTags::$attributes, |
|
223 | + 'output' => AllowedTags::$attributes, |
|
224 | + 'path' => [ |
|
225 | + 'class' => true, |
|
226 | + 'd' => true |
|
227 | + ], |
|
228 | + 'script' => AllowedTags::$attributes, |
|
229 | + 'select' => AllowedTags::$attributes, |
|
230 | + 'style' => AllowedTags::$attributes, |
|
231 | + 'svg' => [ |
|
232 | + 'aria-hidden' => true, |
|
233 | + 'class' => true, |
|
234 | + 'display' => true, |
|
235 | + 'fill' => true, |
|
236 | + 'focusable' => true, |
|
237 | + 'height' => true, |
|
238 | + 'stroke' => true, |
|
239 | + 'stroke-width' => true, |
|
240 | + 'viewBox' => true, |
|
241 | + 'width' => true, |
|
242 | + 'xmlns' => true, |
|
243 | + ], |
|
244 | + 'textarea' => AllowedTags::$attributes, |
|
245 | + 'title' => AllowedTags::$attributes, |
|
246 | + ]; |
|
247 | + AllowedTags::$allowed_with_full_tags = array_merge_recursive($all_tags, $full_tags); |
|
248 | + } |
|
249 | 249 | |
250 | 250 | |
251 | - /** |
|
252 | - * @return array[] |
|
253 | - */ |
|
254 | - public static function getAllowedTags(): array |
|
255 | - { |
|
256 | - if (empty(AllowedTags::$allowed_tags)) { |
|
257 | - AllowedTags::initializeAllowedTags(); |
|
258 | - } |
|
259 | - return AllowedTags::$allowed_tags; |
|
260 | - } |
|
251 | + /** |
|
252 | + * @return array[] |
|
253 | + */ |
|
254 | + public static function getAllowedTags(): array |
|
255 | + { |
|
256 | + if (empty(AllowedTags::$allowed_tags)) { |
|
257 | + AllowedTags::initializeAllowedTags(); |
|
258 | + } |
|
259 | + return AllowedTags::$allowed_tags; |
|
260 | + } |
|
261 | 261 | |
262 | 262 | |
263 | - /** |
|
264 | - * @return array[] |
|
265 | - */ |
|
266 | - public static function getWithEmbedTags(): array |
|
267 | - { |
|
268 | - if (empty(AllowedTags::$allowed_with_embed_tags)) { |
|
269 | - AllowedTags::initializeWithEmbedTags(); |
|
270 | - } |
|
271 | - return AllowedTags::$allowed_with_embed_tags; |
|
272 | - } |
|
263 | + /** |
|
264 | + * @return array[] |
|
265 | + */ |
|
266 | + public static function getWithEmbedTags(): array |
|
267 | + { |
|
268 | + if (empty(AllowedTags::$allowed_with_embed_tags)) { |
|
269 | + AllowedTags::initializeWithEmbedTags(); |
|
270 | + } |
|
271 | + return AllowedTags::$allowed_with_embed_tags; |
|
272 | + } |
|
273 | 273 | |
274 | 274 | |
275 | - /** |
|
276 | - * @return array[] |
|
277 | - */ |
|
278 | - public static function getWithFormTags(): array |
|
279 | - { |
|
280 | - if (empty(AllowedTags::$allowed_with_form_tags)) { |
|
281 | - AllowedTags::initializeWithFormTags(); |
|
282 | - } |
|
283 | - return AllowedTags::$allowed_with_form_tags; |
|
284 | - } |
|
275 | + /** |
|
276 | + * @return array[] |
|
277 | + */ |
|
278 | + public static function getWithFormTags(): array |
|
279 | + { |
|
280 | + if (empty(AllowedTags::$allowed_with_form_tags)) { |
|
281 | + AllowedTags::initializeWithFormTags(); |
|
282 | + } |
|
283 | + return AllowedTags::$allowed_with_form_tags; |
|
284 | + } |
|
285 | 285 | |
286 | 286 | |
287 | - /** |
|
288 | - * @return array[] |
|
289 | - */ |
|
290 | - public static function getWithScriptAndStyleTags(): array |
|
291 | - { |
|
292 | - if (empty(AllowedTags::$allowed_with_script_and_style_tags)) { |
|
293 | - AllowedTags::initializeWithScriptAndStyleTags(); |
|
294 | - } |
|
295 | - return AllowedTags::$allowed_with_script_and_style_tags; |
|
296 | - } |
|
287 | + /** |
|
288 | + * @return array[] |
|
289 | + */ |
|
290 | + public static function getWithScriptAndStyleTags(): array |
|
291 | + { |
|
292 | + if (empty(AllowedTags::$allowed_with_script_and_style_tags)) { |
|
293 | + AllowedTags::initializeWithScriptAndStyleTags(); |
|
294 | + } |
|
295 | + return AllowedTags::$allowed_with_script_and_style_tags; |
|
296 | + } |
|
297 | 297 | |
298 | 298 | |
299 | - /** |
|
300 | - * @return array[] |
|
301 | - */ |
|
302 | - public static function getWithFullTags(): array |
|
303 | - { |
|
304 | - if (empty(AllowedTags::$allowed_with_full_tags)) { |
|
305 | - AllowedTags::initializeWithFullTags(); |
|
306 | - } |
|
307 | - return AllowedTags::$allowed_with_full_tags; |
|
308 | - } |
|
299 | + /** |
|
300 | + * @return array[] |
|
301 | + */ |
|
302 | + public static function getWithFullTags(): array |
|
303 | + { |
|
304 | + if (empty(AllowedTags::$allowed_with_full_tags)) { |
|
305 | + AllowedTags::initializeWithFullTags(); |
|
306 | + } |
|
307 | + return AllowedTags::$allowed_with_full_tags; |
|
308 | + } |
|
309 | 309 | } |
@@ -134,7 +134,7 @@ |
||
134 | 134 | $allowed_post_tags = wp_kses_allowed_html('post'); |
135 | 135 | $allowed_tags = []; |
136 | 136 | foreach (AllowedTags::$tags as $tag) { |
137 | - $allowed_tags[ $tag ] = AllowedTags::$attributes; |
|
137 | + $allowed_tags[$tag] = AllowedTags::$attributes; |
|
138 | 138 | } |
139 | 139 | AllowedTags::$allowed_tags = array_merge_recursive($allowed_post_tags, $allowed_tags); |
140 | 140 | } |
@@ -6,49 +6,49 @@ discard block |
||
6 | 6 | |
7 | 7 | class AdminPageModalContainer |
8 | 8 | { |
9 | - private string $modal_ID; |
|
9 | + private string $modal_ID; |
|
10 | 10 | |
11 | - private string $modal_class; |
|
11 | + private string $modal_class; |
|
12 | 12 | |
13 | - private string $trigger_ID; |
|
13 | + private string $trigger_ID; |
|
14 | 14 | |
15 | - private string $header; |
|
15 | + private string $header; |
|
16 | 16 | |
17 | - private string $content; |
|
17 | + private string $content; |
|
18 | 18 | |
19 | - private string $footer; |
|
19 | + private string $footer; |
|
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * @param string $modal_ID |
|
24 | - * @param string $trigger_ID |
|
25 | - * @param string $header |
|
26 | - * @param string $content |
|
27 | - * @param string $footer |
|
28 | - * @param string $modal_class |
|
29 | - */ |
|
30 | - public function __construct( |
|
31 | - string $modal_ID, |
|
32 | - string $trigger_ID, |
|
33 | - string $header, |
|
34 | - string $content, |
|
35 | - string $footer = '', |
|
36 | - string $modal_class = '' |
|
37 | - ) { |
|
38 | - $this->modal_ID = esc_attr($modal_ID); |
|
39 | - $this->trigger_ID = esc_attr($trigger_ID); |
|
40 | - $this->header = esc_html($header); |
|
41 | - $this->content = wp_kses($content, AllowedTags::getWithFullTags()); |
|
42 | - $this->footer = wp_kses($footer, AllowedTags::getWithFullTags()); |
|
43 | - $this->modal_class = ! empty($modal_class) ? "$modal_class " : ''; |
|
44 | - add_action('admin_print_footer_scripts', [$this, 'renderModal'], 998); |
|
45 | - add_action('admin_print_footer_scripts', [$this, 'printJs'], 999); |
|
46 | - } |
|
22 | + /** |
|
23 | + * @param string $modal_ID |
|
24 | + * @param string $trigger_ID |
|
25 | + * @param string $header |
|
26 | + * @param string $content |
|
27 | + * @param string $footer |
|
28 | + * @param string $modal_class |
|
29 | + */ |
|
30 | + public function __construct( |
|
31 | + string $modal_ID, |
|
32 | + string $trigger_ID, |
|
33 | + string $header, |
|
34 | + string $content, |
|
35 | + string $footer = '', |
|
36 | + string $modal_class = '' |
|
37 | + ) { |
|
38 | + $this->modal_ID = esc_attr($modal_ID); |
|
39 | + $this->trigger_ID = esc_attr($trigger_ID); |
|
40 | + $this->header = esc_html($header); |
|
41 | + $this->content = wp_kses($content, AllowedTags::getWithFullTags()); |
|
42 | + $this->footer = wp_kses($footer, AllowedTags::getWithFullTags()); |
|
43 | + $this->modal_class = ! empty($modal_class) ? "$modal_class " : ''; |
|
44 | + add_action('admin_print_footer_scripts', [$this, 'renderModal'], 998); |
|
45 | + add_action('admin_print_footer_scripts', [$this, 'printJs'], 999); |
|
46 | + } |
|
47 | 47 | |
48 | 48 | |
49 | - public function renderModal() |
|
50 | - { |
|
51 | - echo " |
|
49 | + public function renderModal() |
|
50 | + { |
|
51 | + echo " |
|
52 | 52 | <div id='$this->modal_ID' class='{$this->modal_class}ee-modal__overlay ee-modal__overlay--closed'> |
53 | 53 | <div class='ee-modal'> |
54 | 54 | <div class='ee-modal__header'> |
@@ -64,12 +64,12 @@ discard block |
||
64 | 64 | </div> |
65 | 65 | </div> |
66 | 66 | "; |
67 | - } |
|
67 | + } |
|
68 | 68 | |
69 | 69 | |
70 | - public function printJs() |
|
71 | - { |
|
72 | - ?> |
|
70 | + public function printJs() |
|
71 | + { |
|
72 | + ?> |
|
73 | 73 | <script type="text/javascript"> |
74 | 74 | jq2 = jQuery.noConflict(); |
75 | 75 | jq2(function ($) { |
@@ -97,5 +97,5 @@ discard block |
||
97 | 97 | |
98 | 98 | </script> |
99 | 99 | <?php |
100 | - } |
|
100 | + } |
|
101 | 101 | } |
@@ -19,216 +19,216 @@ |
||
19 | 19 | */ |
20 | 20 | abstract class EspressoShortcode implements ShortcodeInterface |
21 | 21 | { |
22 | - public const CACHE_TRANSIENT_PREFIX = 'SC_'; |
|
23 | - public const SHORTCODE_PREFIX = 'ESPRESSO_'; |
|
24 | - |
|
25 | - private PostRelatedCacheManager $cache_manager; |
|
26 | - |
|
27 | - /** |
|
28 | - * true if ShortcodeInterface::initializeShortcode() has been called |
|
29 | - * if false, then that will get called before processing |
|
30 | - * |
|
31 | - * @var bool $initialized |
|
32 | - */ |
|
33 | - private bool $initialized = false; |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * EspressoShortcode constructor |
|
38 | - * |
|
39 | - * @param PostRelatedCacheManager $cache_manager |
|
40 | - */ |
|
41 | - public function __construct(PostRelatedCacheManager $cache_manager) |
|
42 | - { |
|
43 | - $this->cache_manager = $cache_manager; |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * @return void |
|
49 | - */ |
|
50 | - public function shortcodeHasBeenInitialized() |
|
51 | - { |
|
52 | - $this->initialized = true; |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * enqueues scripts then processes the shortcode |
|
58 | - * |
|
59 | - * @param array|string $attributes |
|
60 | - * @return string |
|
61 | - * @throws EE_Error |
|
62 | - * @throws ReflectionException |
|
63 | - */ |
|
64 | - final public function processShortcodeCallback($attributes = array()): string |
|
65 | - { |
|
66 | - if ($this instanceof EnqueueAssetsInterface) { |
|
67 | - if (is_admin()) { |
|
68 | - $this->enqueueAdminScripts(); |
|
69 | - } else { |
|
70 | - $this->enqueueScripts(); |
|
71 | - } |
|
72 | - } |
|
73 | - $attributes = is_array($attributes) ? $attributes : []; |
|
74 | - return $this->shortcodeContent( |
|
75 | - $this->sanitizeAttributes($attributes) |
|
76 | - ); |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * If shortcode caching is enabled for the shortcode, |
|
82 | - * and cached results exist, then that will be returned |
|
83 | - * else new content will be generated. |
|
84 | - * If caching is enabled, then the new content will be cached for later. |
|
85 | - * |
|
86 | - * @param array $attributes |
|
87 | - * @return mixed|string |
|
88 | - * @throws EE_Error |
|
89 | - * @throws ReflectionException |
|
90 | - */ |
|
91 | - private function shortcodeContent(array $attributes) |
|
92 | - { |
|
93 | - $post_ID = $this->currentPostID(); |
|
94 | - // something like "SC_EVENTS-123" |
|
95 | - $cache_ID = $this->shortcodeCacheID($post_ID); |
|
96 | - $this->cache_manager->clearPostRelatedCacheOnUpdate($post_ID, $cache_ID); |
|
97 | - return $this->cache_manager->get( |
|
98 | - $cache_ID, |
|
99 | - // serialized attributes |
|
100 | - wp_json_encode($attributes), |
|
101 | - // Closure for generating content if cache is expired |
|
102 | - function () use ($attributes) { |
|
103 | - if ($this->initialized() === false) { |
|
104 | - $this->initializeShortcode(); |
|
105 | - } |
|
106 | - return $this->processShortcode($attributes); |
|
107 | - }, |
|
108 | - // filterable cache expiration set by each shortcode |
|
109 | - apply_filters( |
|
110 | - 'FHEE__EventEspresso_core_services_shortcodes_EspressoShortcode__shortcodeContent__cache_expiration', |
|
111 | - $this->cacheExpiration(), |
|
112 | - $this->getTag(), |
|
113 | - $this |
|
114 | - ) |
|
115 | - ); |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * @return int |
|
121 | - * @throws EE_Error |
|
122 | - * @throws ReflectionException |
|
123 | - */ |
|
124 | - private function currentPostID(): int |
|
125 | - { |
|
126 | - // try to get EE_Event any way we can |
|
127 | - $event = EEH_Event_View::get_event(); |
|
128 | - // then get some kind of ID |
|
129 | - if ($event instanceof EE_Event) { |
|
130 | - return $event->ID(); |
|
131 | - } |
|
132 | - global $post; |
|
133 | - if ($post instanceof WP_Post) { |
|
134 | - return $post->ID; |
|
135 | - } |
|
136 | - return 0; |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * @param int $post_ID |
|
142 | - * @return string |
|
143 | - */ |
|
144 | - private function shortcodeCacheID(int $post_ID): string |
|
145 | - { |
|
146 | - $tag = str_replace(EspressoShortcode::SHORTCODE_PREFIX, '', $this->getTag()); |
|
147 | - return EspressoShortcode::CACHE_TRANSIENT_PREFIX . "$tag-$post_ID"; |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * array for defining custom attribute sanitization callbacks, |
|
153 | - * where keys match keys in your attributes array, |
|
154 | - * and values represent the sanitization function you wish to be applied to that attribute. |
|
155 | - * So for example, if you had an integer attribute named "event_id" |
|
156 | - * that you wanted to be sanitized using absint(), |
|
157 | - * then you would return the following: |
|
158 | - * array('event_id' => 'absint') |
|
159 | - * Entering 'skip_sanitization' for the callback value |
|
160 | - * means that no sanitization will be applied |
|
161 | - * on the assumption that the attribute |
|
162 | - * will be sanitized at some point... right? |
|
163 | - * You wouldn't pass around unsanitized attributes would you? |
|
164 | - * That would be very Tom Foolery of you!!! |
|
165 | - * |
|
166 | - * @return array |
|
167 | - */ |
|
168 | - protected function customAttributeSanitizationMap(): array |
|
169 | - { |
|
170 | - return array(); |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * Performs basic sanitization on shortcode attributes |
|
176 | - * Since incoming attributes from the shortcode usage in the WP editor will all be strings, |
|
177 | - * most attributes will by default be sanitized using the sanitize_text_field() function. |
|
178 | - * This can be overridden using the customAttributeSanitizationMap() method (see above), |
|
179 | - * all other attributes would be sanitized using the defaults in the switch statement below |
|
180 | - * |
|
181 | - * @param array $attributes |
|
182 | - * @return array |
|
183 | - */ |
|
184 | - private function sanitizeAttributes(array $attributes): array |
|
185 | - { |
|
186 | - $custom_sanitization = $this->customAttributeSanitizationMap(); |
|
187 | - foreach ($attributes as $key => $value) { |
|
188 | - // is a custom sanitization callback specified ? |
|
189 | - if (isset($custom_sanitization[ $key ])) { |
|
190 | - $callback = $custom_sanitization[ $key ]; |
|
191 | - if ($callback === 'skip_sanitization') { |
|
192 | - $attributes[ $key ] = $value; |
|
193 | - continue; |
|
194 | - } |
|
195 | - if (function_exists($callback)) { |
|
196 | - $attributes[ $key ] = $callback($value); |
|
197 | - continue; |
|
198 | - } |
|
199 | - } |
|
200 | - switch (true) { |
|
201 | - case $value === null: |
|
202 | - case is_int($value): |
|
203 | - case is_float($value): |
|
204 | - // typical booleans |
|
205 | - case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true): |
|
206 | - $attributes[ $key ] = $value; |
|
207 | - break; |
|
208 | - case is_string($value): |
|
209 | - $attributes[ $key ] = sanitize_text_field($value); |
|
210 | - break; |
|
211 | - case is_array($value): |
|
212 | - $attributes[ $key ] = $this->sanitizeAttributes($value); |
|
213 | - break; |
|
214 | - default: |
|
215 | - // only remaining data types are Object and Resource |
|
216 | - // which are not allowed as shortcode attributes |
|
217 | - $attributes[ $key ] = null; |
|
218 | - break; |
|
219 | - } |
|
220 | - } |
|
221 | - return $attributes; |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - /** |
|
226 | - * Returns whether this shortcode has been initialized |
|
227 | - * |
|
228 | - * @return bool |
|
229 | - */ |
|
230 | - public function initialized(): bool |
|
231 | - { |
|
232 | - return $this->initialized; |
|
233 | - } |
|
22 | + public const CACHE_TRANSIENT_PREFIX = 'SC_'; |
|
23 | + public const SHORTCODE_PREFIX = 'ESPRESSO_'; |
|
24 | + |
|
25 | + private PostRelatedCacheManager $cache_manager; |
|
26 | + |
|
27 | + /** |
|
28 | + * true if ShortcodeInterface::initializeShortcode() has been called |
|
29 | + * if false, then that will get called before processing |
|
30 | + * |
|
31 | + * @var bool $initialized |
|
32 | + */ |
|
33 | + private bool $initialized = false; |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * EspressoShortcode constructor |
|
38 | + * |
|
39 | + * @param PostRelatedCacheManager $cache_manager |
|
40 | + */ |
|
41 | + public function __construct(PostRelatedCacheManager $cache_manager) |
|
42 | + { |
|
43 | + $this->cache_manager = $cache_manager; |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * @return void |
|
49 | + */ |
|
50 | + public function shortcodeHasBeenInitialized() |
|
51 | + { |
|
52 | + $this->initialized = true; |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * enqueues scripts then processes the shortcode |
|
58 | + * |
|
59 | + * @param array|string $attributes |
|
60 | + * @return string |
|
61 | + * @throws EE_Error |
|
62 | + * @throws ReflectionException |
|
63 | + */ |
|
64 | + final public function processShortcodeCallback($attributes = array()): string |
|
65 | + { |
|
66 | + if ($this instanceof EnqueueAssetsInterface) { |
|
67 | + if (is_admin()) { |
|
68 | + $this->enqueueAdminScripts(); |
|
69 | + } else { |
|
70 | + $this->enqueueScripts(); |
|
71 | + } |
|
72 | + } |
|
73 | + $attributes = is_array($attributes) ? $attributes : []; |
|
74 | + return $this->shortcodeContent( |
|
75 | + $this->sanitizeAttributes($attributes) |
|
76 | + ); |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * If shortcode caching is enabled for the shortcode, |
|
82 | + * and cached results exist, then that will be returned |
|
83 | + * else new content will be generated. |
|
84 | + * If caching is enabled, then the new content will be cached for later. |
|
85 | + * |
|
86 | + * @param array $attributes |
|
87 | + * @return mixed|string |
|
88 | + * @throws EE_Error |
|
89 | + * @throws ReflectionException |
|
90 | + */ |
|
91 | + private function shortcodeContent(array $attributes) |
|
92 | + { |
|
93 | + $post_ID = $this->currentPostID(); |
|
94 | + // something like "SC_EVENTS-123" |
|
95 | + $cache_ID = $this->shortcodeCacheID($post_ID); |
|
96 | + $this->cache_manager->clearPostRelatedCacheOnUpdate($post_ID, $cache_ID); |
|
97 | + return $this->cache_manager->get( |
|
98 | + $cache_ID, |
|
99 | + // serialized attributes |
|
100 | + wp_json_encode($attributes), |
|
101 | + // Closure for generating content if cache is expired |
|
102 | + function () use ($attributes) { |
|
103 | + if ($this->initialized() === false) { |
|
104 | + $this->initializeShortcode(); |
|
105 | + } |
|
106 | + return $this->processShortcode($attributes); |
|
107 | + }, |
|
108 | + // filterable cache expiration set by each shortcode |
|
109 | + apply_filters( |
|
110 | + 'FHEE__EventEspresso_core_services_shortcodes_EspressoShortcode__shortcodeContent__cache_expiration', |
|
111 | + $this->cacheExpiration(), |
|
112 | + $this->getTag(), |
|
113 | + $this |
|
114 | + ) |
|
115 | + ); |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * @return int |
|
121 | + * @throws EE_Error |
|
122 | + * @throws ReflectionException |
|
123 | + */ |
|
124 | + private function currentPostID(): int |
|
125 | + { |
|
126 | + // try to get EE_Event any way we can |
|
127 | + $event = EEH_Event_View::get_event(); |
|
128 | + // then get some kind of ID |
|
129 | + if ($event instanceof EE_Event) { |
|
130 | + return $event->ID(); |
|
131 | + } |
|
132 | + global $post; |
|
133 | + if ($post instanceof WP_Post) { |
|
134 | + return $post->ID; |
|
135 | + } |
|
136 | + return 0; |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * @param int $post_ID |
|
142 | + * @return string |
|
143 | + */ |
|
144 | + private function shortcodeCacheID(int $post_ID): string |
|
145 | + { |
|
146 | + $tag = str_replace(EspressoShortcode::SHORTCODE_PREFIX, '', $this->getTag()); |
|
147 | + return EspressoShortcode::CACHE_TRANSIENT_PREFIX . "$tag-$post_ID"; |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * array for defining custom attribute sanitization callbacks, |
|
153 | + * where keys match keys in your attributes array, |
|
154 | + * and values represent the sanitization function you wish to be applied to that attribute. |
|
155 | + * So for example, if you had an integer attribute named "event_id" |
|
156 | + * that you wanted to be sanitized using absint(), |
|
157 | + * then you would return the following: |
|
158 | + * array('event_id' => 'absint') |
|
159 | + * Entering 'skip_sanitization' for the callback value |
|
160 | + * means that no sanitization will be applied |
|
161 | + * on the assumption that the attribute |
|
162 | + * will be sanitized at some point... right? |
|
163 | + * You wouldn't pass around unsanitized attributes would you? |
|
164 | + * That would be very Tom Foolery of you!!! |
|
165 | + * |
|
166 | + * @return array |
|
167 | + */ |
|
168 | + protected function customAttributeSanitizationMap(): array |
|
169 | + { |
|
170 | + return array(); |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * Performs basic sanitization on shortcode attributes |
|
176 | + * Since incoming attributes from the shortcode usage in the WP editor will all be strings, |
|
177 | + * most attributes will by default be sanitized using the sanitize_text_field() function. |
|
178 | + * This can be overridden using the customAttributeSanitizationMap() method (see above), |
|
179 | + * all other attributes would be sanitized using the defaults in the switch statement below |
|
180 | + * |
|
181 | + * @param array $attributes |
|
182 | + * @return array |
|
183 | + */ |
|
184 | + private function sanitizeAttributes(array $attributes): array |
|
185 | + { |
|
186 | + $custom_sanitization = $this->customAttributeSanitizationMap(); |
|
187 | + foreach ($attributes as $key => $value) { |
|
188 | + // is a custom sanitization callback specified ? |
|
189 | + if (isset($custom_sanitization[ $key ])) { |
|
190 | + $callback = $custom_sanitization[ $key ]; |
|
191 | + if ($callback === 'skip_sanitization') { |
|
192 | + $attributes[ $key ] = $value; |
|
193 | + continue; |
|
194 | + } |
|
195 | + if (function_exists($callback)) { |
|
196 | + $attributes[ $key ] = $callback($value); |
|
197 | + continue; |
|
198 | + } |
|
199 | + } |
|
200 | + switch (true) { |
|
201 | + case $value === null: |
|
202 | + case is_int($value): |
|
203 | + case is_float($value): |
|
204 | + // typical booleans |
|
205 | + case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true): |
|
206 | + $attributes[ $key ] = $value; |
|
207 | + break; |
|
208 | + case is_string($value): |
|
209 | + $attributes[ $key ] = sanitize_text_field($value); |
|
210 | + break; |
|
211 | + case is_array($value): |
|
212 | + $attributes[ $key ] = $this->sanitizeAttributes($value); |
|
213 | + break; |
|
214 | + default: |
|
215 | + // only remaining data types are Object and Resource |
|
216 | + // which are not allowed as shortcode attributes |
|
217 | + $attributes[ $key ] = null; |
|
218 | + break; |
|
219 | + } |
|
220 | + } |
|
221 | + return $attributes; |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + /** |
|
226 | + * Returns whether this shortcode has been initialized |
|
227 | + * |
|
228 | + * @return bool |
|
229 | + */ |
|
230 | + public function initialized(): bool |
|
231 | + { |
|
232 | + return $this->initialized; |
|
233 | + } |
|
234 | 234 | } |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | // serialized attributes |
100 | 100 | wp_json_encode($attributes), |
101 | 101 | // Closure for generating content if cache is expired |
102 | - function () use ($attributes) { |
|
102 | + function() use ($attributes) { |
|
103 | 103 | if ($this->initialized() === false) { |
104 | 104 | $this->initializeShortcode(); |
105 | 105 | } |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | private function shortcodeCacheID(int $post_ID): string |
145 | 145 | { |
146 | 146 | $tag = str_replace(EspressoShortcode::SHORTCODE_PREFIX, '', $this->getTag()); |
147 | - return EspressoShortcode::CACHE_TRANSIENT_PREFIX . "$tag-$post_ID"; |
|
147 | + return EspressoShortcode::CACHE_TRANSIENT_PREFIX."$tag-$post_ID"; |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | |
@@ -186,14 +186,14 @@ discard block |
||
186 | 186 | $custom_sanitization = $this->customAttributeSanitizationMap(); |
187 | 187 | foreach ($attributes as $key => $value) { |
188 | 188 | // is a custom sanitization callback specified ? |
189 | - if (isset($custom_sanitization[ $key ])) { |
|
190 | - $callback = $custom_sanitization[ $key ]; |
|
189 | + if (isset($custom_sanitization[$key])) { |
|
190 | + $callback = $custom_sanitization[$key]; |
|
191 | 191 | if ($callback === 'skip_sanitization') { |
192 | - $attributes[ $key ] = $value; |
|
192 | + $attributes[$key] = $value; |
|
193 | 193 | continue; |
194 | 194 | } |
195 | 195 | if (function_exists($callback)) { |
196 | - $attributes[ $key ] = $callback($value); |
|
196 | + $attributes[$key] = $callback($value); |
|
197 | 197 | continue; |
198 | 198 | } |
199 | 199 | } |
@@ -203,18 +203,18 @@ discard block |
||
203 | 203 | case is_float($value): |
204 | 204 | // typical booleans |
205 | 205 | case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true): |
206 | - $attributes[ $key ] = $value; |
|
206 | + $attributes[$key] = $value; |
|
207 | 207 | break; |
208 | 208 | case is_string($value): |
209 | - $attributes[ $key ] = sanitize_text_field($value); |
|
209 | + $attributes[$key] = sanitize_text_field($value); |
|
210 | 210 | break; |
211 | 211 | case is_array($value): |
212 | - $attributes[ $key ] = $this->sanitizeAttributes($value); |
|
212 | + $attributes[$key] = $this->sanitizeAttributes($value); |
|
213 | 213 | break; |
214 | 214 | default: |
215 | 215 | // only remaining data types are Object and Resource |
216 | 216 | // which are not allowed as shortcode attributes |
217 | - $attributes[ $key ] = null; |
|
217 | + $attributes[$key] = null; |
|
218 | 218 | break; |
219 | 219 | } |
220 | 220 | } |
@@ -17,146 +17,146 @@ |
||
17 | 17 | */ |
18 | 18 | class TableAnalysis extends EE_Base |
19 | 19 | { |
20 | - /** |
|
21 | - * The maximum number of characters that can be indexed on a column using utf8mb4 collation, |
|
22 | - * see https://events.codebasehq.com/redirect?https://make.wordpress.org/core/2015/04/02/the-utf8mb4-upgrade/ |
|
23 | - */ |
|
24 | - public const INDEX_COLUMN_SIZE = 191; |
|
25 | - |
|
26 | - public const INDEX_TYPE_INDEX = 'INDEX'; |
|
27 | - |
|
28 | - public const INDEX_TYPE_UNIQUE = 'UNIQUE'; |
|
29 | - |
|
30 | - private array $known_tables = []; |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * Returns the table name which will definitely have the wpdb prefix on the front, |
|
35 | - * except if it currently has the wpdb->base_prefix on the front, in which case |
|
36 | - * it will have the wpdb->base_prefix on it |
|
37 | - * |
|
38 | - * @param string $table_name |
|
39 | - * @return string $tableName, having ensured it has the wpdb prefix on the front |
|
40 | - * @global wpdb $wpdb |
|
41 | - */ |
|
42 | - public function ensureTableNameHasPrefix(string $table_name): string |
|
43 | - { |
|
44 | - global $wpdb; |
|
45 | - return strpos($table_name, $wpdb->base_prefix) === 0 ? $table_name : $wpdb->prefix . $table_name; |
|
46 | - } |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * Indicates whether the table has any entries. $table_name can |
|
51 | - * optionally start with $wpdb->prefix or not |
|
52 | - * |
|
53 | - * @param string $table_name |
|
54 | - * @return bool |
|
55 | - * @global wpdb $wpdb |
|
56 | - */ |
|
57 | - public function tableIsEmpty(string $table_name): bool |
|
58 | - { |
|
59 | - global $wpdb; |
|
60 | - $table_name = $this->ensureTableNameHasPrefix($table_name); |
|
61 | - if ($this->tableExists($table_name)) { |
|
62 | - $count = $wpdb->get_var("SELECT COUNT(*) FROM $table_name"); |
|
63 | - return absint($count) === 0; |
|
64 | - } |
|
65 | - return false; |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * Indicates whether the table exists. $table_name can optionally |
|
71 | - * have the $wpdb->prefix on the beginning, or not. |
|
72 | - * |
|
73 | - * @param string $table_name |
|
74 | - * @return bool |
|
75 | - * @global wpdb $wpdb |
|
76 | - * @global array $EZSQL_ERROR |
|
77 | - */ |
|
78 | - public function tableExists(string $table_name): bool |
|
79 | - { |
|
80 | - $table_name = $this->ensureTableNameHasPrefix($table_name); |
|
81 | - if (isset($this->known_tables[ $table_name ])) { |
|
82 | - return true; |
|
83 | - } |
|
84 | - global $wpdb, $EZSQL_ERROR; |
|
85 | - // ignore if this causes an SQL error |
|
86 | - $old_error = $wpdb->last_error; |
|
87 | - $old_suppress_errors = $wpdb->suppress_errors(); |
|
88 | - $old_show_errors_value = $wpdb->show_errors(false); |
|
89 | - $ezsql_error_cache = $EZSQL_ERROR; |
|
90 | - $wpdb->get_results("SELECT * from $table_name LIMIT 1"); |
|
91 | - $wpdb->show_errors($old_show_errors_value); |
|
92 | - $wpdb->suppress_errors($old_suppress_errors); |
|
93 | - $new_error = $wpdb->last_error; |
|
94 | - $wpdb->last_error = $old_error; |
|
95 | - $EZSQL_ERROR = $ezsql_error_cache; |
|
96 | - // if there was a table doesn't exist error |
|
97 | - if (! empty($new_error)) { |
|
98 | - if ( |
|
99 | - in_array( |
|
100 | - EEH_Activation::last_wpdb_error_code(), |
|
101 | - [ |
|
102 | - 1051, // bad table |
|
103 | - 1109, // unknown table |
|
104 | - 117, // no such table |
|
105 | - ] |
|
106 | - ) |
|
107 | - || preg_match( |
|
108 | - '~^Table .* doesn\'t exist~', |
|
109 | - $new_error |
|
110 | - ) // in case not using mysql and error codes aren't reliable, just check for this error string |
|
111 | - ) { |
|
112 | - return false; |
|
113 | - } |
|
114 | - // log this because that's weird. Just use the normal PHP error log |
|
115 | - error_log( |
|
116 | - sprintf( |
|
117 | - esc_html__( |
|
118 | - 'Event Espresso error detected when checking if table existed: %1$s (it wasn\'t just that the table didn\'t exist either)', |
|
119 | - 'event_espresso' |
|
120 | - ), |
|
121 | - $new_error |
|
122 | - ) |
|
123 | - ); |
|
124 | - } |
|
125 | - $this->known_tables[ $table_name ] = true; |
|
126 | - return true; |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * @param string $table_name |
|
132 | - * @param string $index_name |
|
133 | - * @return array of columns used on that index, Each entry is an object with the following properties { |
|
134 | - * } |
|
135 | - */ |
|
136 | - public function showIndexes(string $table_name, string $index_name): array |
|
137 | - { |
|
138 | - global $wpdb; |
|
139 | - if (! $this->tableExists($table_name)) { |
|
140 | - return []; |
|
141 | - } |
|
142 | - $table_name = $this->ensureTableNameHasPrefix($table_name); |
|
143 | - $index_exists_query = "SHOW INDEX FROM $table_name WHERE Key_name = '$index_name'"; |
|
144 | - return $wpdb->get_results($index_exists_query); |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * @param string $table_name |
|
150 | - * @param string $index_name |
|
151 | - * @return bool |
|
152 | - * @since 5.0.13.p |
|
153 | - */ |
|
154 | - public function indexExists(string $table_name, string $index_name): bool |
|
155 | - { |
|
156 | - global $wpdb; |
|
157 | - $table_name = $this->ensureTableNameHasPrefix($table_name); |
|
158 | - $index_exists_query = "SHOW INDEX FROM $table_name WHERE key_name = '$index_name'"; |
|
159 | - // using get_var with the $index_exists_query returns the table's name |
|
160 | - return $this->tableExists($table_name) && $wpdb->get_var($index_exists_query) === $table_name; |
|
161 | - } |
|
20 | + /** |
|
21 | + * The maximum number of characters that can be indexed on a column using utf8mb4 collation, |
|
22 | + * see https://events.codebasehq.com/redirect?https://make.wordpress.org/core/2015/04/02/the-utf8mb4-upgrade/ |
|
23 | + */ |
|
24 | + public const INDEX_COLUMN_SIZE = 191; |
|
25 | + |
|
26 | + public const INDEX_TYPE_INDEX = 'INDEX'; |
|
27 | + |
|
28 | + public const INDEX_TYPE_UNIQUE = 'UNIQUE'; |
|
29 | + |
|
30 | + private array $known_tables = []; |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * Returns the table name which will definitely have the wpdb prefix on the front, |
|
35 | + * except if it currently has the wpdb->base_prefix on the front, in which case |
|
36 | + * it will have the wpdb->base_prefix on it |
|
37 | + * |
|
38 | + * @param string $table_name |
|
39 | + * @return string $tableName, having ensured it has the wpdb prefix on the front |
|
40 | + * @global wpdb $wpdb |
|
41 | + */ |
|
42 | + public function ensureTableNameHasPrefix(string $table_name): string |
|
43 | + { |
|
44 | + global $wpdb; |
|
45 | + return strpos($table_name, $wpdb->base_prefix) === 0 ? $table_name : $wpdb->prefix . $table_name; |
|
46 | + } |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * Indicates whether the table has any entries. $table_name can |
|
51 | + * optionally start with $wpdb->prefix or not |
|
52 | + * |
|
53 | + * @param string $table_name |
|
54 | + * @return bool |
|
55 | + * @global wpdb $wpdb |
|
56 | + */ |
|
57 | + public function tableIsEmpty(string $table_name): bool |
|
58 | + { |
|
59 | + global $wpdb; |
|
60 | + $table_name = $this->ensureTableNameHasPrefix($table_name); |
|
61 | + if ($this->tableExists($table_name)) { |
|
62 | + $count = $wpdb->get_var("SELECT COUNT(*) FROM $table_name"); |
|
63 | + return absint($count) === 0; |
|
64 | + } |
|
65 | + return false; |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * Indicates whether the table exists. $table_name can optionally |
|
71 | + * have the $wpdb->prefix on the beginning, or not. |
|
72 | + * |
|
73 | + * @param string $table_name |
|
74 | + * @return bool |
|
75 | + * @global wpdb $wpdb |
|
76 | + * @global array $EZSQL_ERROR |
|
77 | + */ |
|
78 | + public function tableExists(string $table_name): bool |
|
79 | + { |
|
80 | + $table_name = $this->ensureTableNameHasPrefix($table_name); |
|
81 | + if (isset($this->known_tables[ $table_name ])) { |
|
82 | + return true; |
|
83 | + } |
|
84 | + global $wpdb, $EZSQL_ERROR; |
|
85 | + // ignore if this causes an SQL error |
|
86 | + $old_error = $wpdb->last_error; |
|
87 | + $old_suppress_errors = $wpdb->suppress_errors(); |
|
88 | + $old_show_errors_value = $wpdb->show_errors(false); |
|
89 | + $ezsql_error_cache = $EZSQL_ERROR; |
|
90 | + $wpdb->get_results("SELECT * from $table_name LIMIT 1"); |
|
91 | + $wpdb->show_errors($old_show_errors_value); |
|
92 | + $wpdb->suppress_errors($old_suppress_errors); |
|
93 | + $new_error = $wpdb->last_error; |
|
94 | + $wpdb->last_error = $old_error; |
|
95 | + $EZSQL_ERROR = $ezsql_error_cache; |
|
96 | + // if there was a table doesn't exist error |
|
97 | + if (! empty($new_error)) { |
|
98 | + if ( |
|
99 | + in_array( |
|
100 | + EEH_Activation::last_wpdb_error_code(), |
|
101 | + [ |
|
102 | + 1051, // bad table |
|
103 | + 1109, // unknown table |
|
104 | + 117, // no such table |
|
105 | + ] |
|
106 | + ) |
|
107 | + || preg_match( |
|
108 | + '~^Table .* doesn\'t exist~', |
|
109 | + $new_error |
|
110 | + ) // in case not using mysql and error codes aren't reliable, just check for this error string |
|
111 | + ) { |
|
112 | + return false; |
|
113 | + } |
|
114 | + // log this because that's weird. Just use the normal PHP error log |
|
115 | + error_log( |
|
116 | + sprintf( |
|
117 | + esc_html__( |
|
118 | + 'Event Espresso error detected when checking if table existed: %1$s (it wasn\'t just that the table didn\'t exist either)', |
|
119 | + 'event_espresso' |
|
120 | + ), |
|
121 | + $new_error |
|
122 | + ) |
|
123 | + ); |
|
124 | + } |
|
125 | + $this->known_tables[ $table_name ] = true; |
|
126 | + return true; |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * @param string $table_name |
|
132 | + * @param string $index_name |
|
133 | + * @return array of columns used on that index, Each entry is an object with the following properties { |
|
134 | + * } |
|
135 | + */ |
|
136 | + public function showIndexes(string $table_name, string $index_name): array |
|
137 | + { |
|
138 | + global $wpdb; |
|
139 | + if (! $this->tableExists($table_name)) { |
|
140 | + return []; |
|
141 | + } |
|
142 | + $table_name = $this->ensureTableNameHasPrefix($table_name); |
|
143 | + $index_exists_query = "SHOW INDEX FROM $table_name WHERE Key_name = '$index_name'"; |
|
144 | + return $wpdb->get_results($index_exists_query); |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * @param string $table_name |
|
150 | + * @param string $index_name |
|
151 | + * @return bool |
|
152 | + * @since 5.0.13.p |
|
153 | + */ |
|
154 | + public function indexExists(string $table_name, string $index_name): bool |
|
155 | + { |
|
156 | + global $wpdb; |
|
157 | + $table_name = $this->ensureTableNameHasPrefix($table_name); |
|
158 | + $index_exists_query = "SHOW INDEX FROM $table_name WHERE key_name = '$index_name'"; |
|
159 | + // using get_var with the $index_exists_query returns the table's name |
|
160 | + return $this->tableExists($table_name) && $wpdb->get_var($index_exists_query) === $table_name; |
|
161 | + } |
|
162 | 162 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | public function ensureTableNameHasPrefix(string $table_name): string |
43 | 43 | { |
44 | 44 | global $wpdb; |
45 | - return strpos($table_name, $wpdb->base_prefix) === 0 ? $table_name : $wpdb->prefix . $table_name; |
|
45 | + return strpos($table_name, $wpdb->base_prefix) === 0 ? $table_name : $wpdb->prefix.$table_name; |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | public function tableExists(string $table_name): bool |
79 | 79 | { |
80 | 80 | $table_name = $this->ensureTableNameHasPrefix($table_name); |
81 | - if (isset($this->known_tables[ $table_name ])) { |
|
81 | + if (isset($this->known_tables[$table_name])) { |
|
82 | 82 | return true; |
83 | 83 | } |
84 | 84 | global $wpdb, $EZSQL_ERROR; |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | $wpdb->last_error = $old_error; |
95 | 95 | $EZSQL_ERROR = $ezsql_error_cache; |
96 | 96 | // if there was a table doesn't exist error |
97 | - if (! empty($new_error)) { |
|
97 | + if ( ! empty($new_error)) { |
|
98 | 98 | if ( |
99 | 99 | in_array( |
100 | 100 | EEH_Activation::last_wpdb_error_code(), |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | ) |
123 | 123 | ); |
124 | 124 | } |
125 | - $this->known_tables[ $table_name ] = true; |
|
125 | + $this->known_tables[$table_name] = true; |
|
126 | 126 | return true; |
127 | 127 | } |
128 | 128 | |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | public function showIndexes(string $table_name, string $index_name): array |
137 | 137 | { |
138 | 138 | global $wpdb; |
139 | - if (! $this->tableExists($table_name)) { |
|
139 | + if ( ! $this->tableExists($table_name)) { |
|
140 | 140 | return []; |
141 | 141 | } |
142 | 142 | $table_name = $this->ensureTableNameHasPrefix($table_name); |
@@ -16,297 +16,297 @@ |
||
16 | 16 | */ |
17 | 17 | class TableManager extends EE_Base |
18 | 18 | { |
19 | - private ?TableAnalysis $table_analysis; |
|
19 | + private ?TableAnalysis $table_analysis; |
|
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * TableManager constructor. |
|
24 | - * |
|
25 | - * @param TableAnalysis $TableAnalysis |
|
26 | - */ |
|
27 | - public function __construct(TableAnalysis $TableAnalysis) |
|
28 | - { |
|
29 | - $this->table_analysis = $TableAnalysis; |
|
30 | - } |
|
22 | + /** |
|
23 | + * TableManager constructor. |
|
24 | + * |
|
25 | + * @param TableAnalysis $TableAnalysis |
|
26 | + */ |
|
27 | + public function __construct(TableAnalysis $TableAnalysis) |
|
28 | + { |
|
29 | + $this->table_analysis = $TableAnalysis; |
|
30 | + } |
|
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * Gets the injected table analyzer, or throws an exception |
|
35 | - * |
|
36 | - * @return TableAnalysis |
|
37 | - * @throws EE_Error |
|
38 | - */ |
|
39 | - protected function getTableAnalysis(): ?TableAnalysis |
|
40 | - { |
|
41 | - if ($this->table_analysis instanceof TableAnalysis) { |
|
42 | - return $this->table_analysis; |
|
43 | - } else { |
|
44 | - throw new EE_Error( |
|
45 | - sprintf( |
|
46 | - esc_html__('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
47 | - get_class($this) |
|
48 | - ) |
|
49 | - ); |
|
50 | - } |
|
51 | - } |
|
33 | + /** |
|
34 | + * Gets the injected table analyzer, or throws an exception |
|
35 | + * |
|
36 | + * @return TableAnalysis |
|
37 | + * @throws EE_Error |
|
38 | + */ |
|
39 | + protected function getTableAnalysis(): ?TableAnalysis |
|
40 | + { |
|
41 | + if ($this->table_analysis instanceof TableAnalysis) { |
|
42 | + return $this->table_analysis; |
|
43 | + } else { |
|
44 | + throw new EE_Error( |
|
45 | + sprintf( |
|
46 | + esc_html__('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
47 | + get_class($this) |
|
48 | + ) |
|
49 | + ); |
|
50 | + } |
|
51 | + } |
|
52 | 52 | |
53 | 53 | |
54 | - /** |
|
55 | - * @param string $table_name which can optionally start with $wpdb->prefix or not |
|
56 | - * @param string $column_name |
|
57 | - * @param string $column_info |
|
58 | - * @return bool|false|int |
|
59 | - * @throws EE_Error |
|
60 | - */ |
|
61 | - public function addColumn(string $table_name, string $column_name, string $column_info = 'INT UNSIGNED NOT NULL') |
|
62 | - { |
|
63 | - if (apply_filters('FHEE__EEH_Activation__add_column_if_it_doesnt_exist__short_circuit', false)) { |
|
64 | - return false; |
|
65 | - } |
|
66 | - global $wpdb; |
|
67 | - $full_table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
68 | - $columns = $this->getTableColumns($table_name); |
|
69 | - if (! in_array($column_name, $columns)) { |
|
70 | - $alter_query = "ALTER TABLE $full_table_name ADD $column_name $column_info"; |
|
71 | - return $wpdb->query($alter_query); |
|
72 | - } |
|
73 | - return true; |
|
74 | - } |
|
54 | + /** |
|
55 | + * @param string $table_name which can optionally start with $wpdb->prefix or not |
|
56 | + * @param string $column_name |
|
57 | + * @param string $column_info |
|
58 | + * @return bool|false|int |
|
59 | + * @throws EE_Error |
|
60 | + */ |
|
61 | + public function addColumn(string $table_name, string $column_name, string $column_info = 'INT UNSIGNED NOT NULL') |
|
62 | + { |
|
63 | + if (apply_filters('FHEE__EEH_Activation__add_column_if_it_doesnt_exist__short_circuit', false)) { |
|
64 | + return false; |
|
65 | + } |
|
66 | + global $wpdb; |
|
67 | + $full_table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
68 | + $columns = $this->getTableColumns($table_name); |
|
69 | + if (! in_array($column_name, $columns)) { |
|
70 | + $alter_query = "ALTER TABLE $full_table_name ADD $column_name $column_info"; |
|
71 | + return $wpdb->query($alter_query); |
|
72 | + } |
|
73 | + return true; |
|
74 | + } |
|
75 | 75 | |
76 | 76 | |
77 | - /** |
|
78 | - * Gets the name of all columns on the table. $table_name can |
|
79 | - * optionally start with $wpdb->prefix or not |
|
80 | - * |
|
81 | - * @param string $table_name |
|
82 | - * @return array |
|
83 | - * @throws EE_Error |
|
84 | - * @global wpdb $wpdb |
|
85 | - */ |
|
86 | - public function getTableColumns(string $table_name): array |
|
87 | - { |
|
88 | - global $wpdb; |
|
89 | - $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
90 | - $field_array = []; |
|
91 | - if (! empty($table_name)) { |
|
92 | - $columns = $wpdb->get_results("SHOW COLUMNS FROM $table_name "); |
|
93 | - if ($columns !== false) { |
|
94 | - foreach ($columns as $column) { |
|
95 | - $field_array[] = $column->Field; |
|
96 | - } |
|
97 | - } |
|
98 | - } |
|
99 | - return $field_array; |
|
100 | - } |
|
77 | + /** |
|
78 | + * Gets the name of all columns on the table. $table_name can |
|
79 | + * optionally start with $wpdb->prefix or not |
|
80 | + * |
|
81 | + * @param string $table_name |
|
82 | + * @return array |
|
83 | + * @throws EE_Error |
|
84 | + * @global wpdb $wpdb |
|
85 | + */ |
|
86 | + public function getTableColumns(string $table_name): array |
|
87 | + { |
|
88 | + global $wpdb; |
|
89 | + $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
90 | + $field_array = []; |
|
91 | + if (! empty($table_name)) { |
|
92 | + $columns = $wpdb->get_results("SHOW COLUMNS FROM $table_name "); |
|
93 | + if ($columns !== false) { |
|
94 | + foreach ($columns as $column) { |
|
95 | + $field_array[] = $column->Field; |
|
96 | + } |
|
97 | + } |
|
98 | + } |
|
99 | + return $field_array; |
|
100 | + } |
|
101 | 101 | |
102 | 102 | |
103 | - /** |
|
104 | - * Drops the specified table from the database. $table_name can |
|
105 | - * optionally start with $wpdb->prefix or not |
|
106 | - * |
|
107 | - * @param string $table_name |
|
108 | - * @return bool|int |
|
109 | - * @throws EE_Error |
|
110 | - * @global wpdb $wpdb |
|
111 | - */ |
|
112 | - public function dropTable(string $table_name) |
|
113 | - { |
|
114 | - global $wpdb; |
|
115 | - if ($this->getTableAnalysis()->tableExists($table_name)) { |
|
116 | - $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
117 | - return $wpdb->query("DROP TABLE IF EXISTS $table_name"); |
|
118 | - } |
|
119 | - return 0; |
|
120 | - } |
|
103 | + /** |
|
104 | + * Drops the specified table from the database. $table_name can |
|
105 | + * optionally start with $wpdb->prefix or not |
|
106 | + * |
|
107 | + * @param string $table_name |
|
108 | + * @return bool|int |
|
109 | + * @throws EE_Error |
|
110 | + * @global wpdb $wpdb |
|
111 | + */ |
|
112 | + public function dropTable(string $table_name) |
|
113 | + { |
|
114 | + global $wpdb; |
|
115 | + if ($this->getTableAnalysis()->tableExists($table_name)) { |
|
116 | + $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
117 | + return $wpdb->query("DROP TABLE IF EXISTS $table_name"); |
|
118 | + } |
|
119 | + return 0; |
|
120 | + } |
|
121 | 121 | |
122 | 122 | |
123 | - /** |
|
124 | - * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
125 | - * each table name provided has a wpdb prefix attached, and that it exists. |
|
126 | - * Returns the list actually deleted |
|
127 | - * |
|
128 | - * @param string[] $table_names |
|
129 | - * @return array of table names which we deleted |
|
130 | - * @throws EE_Error |
|
131 | - * @global WPDB $wpdb |
|
132 | - */ |
|
133 | - public function dropTables(array $table_names): array |
|
134 | - { |
|
135 | - $tables_to_delete = []; |
|
136 | - foreach ($table_names as $table_name) { |
|
137 | - $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
138 | - if ($this->getTableAnalysis()->tableExists($table_name)) { |
|
139 | - $tables_to_delete[ $table_name ] = $table_name; |
|
140 | - } |
|
141 | - } |
|
142 | - if (! empty($tables_to_delete)) { |
|
143 | - global $wpdb; |
|
144 | - // make sure we only have a unique strings in the array. |
|
145 | - $tables_to_delete = array_unique($tables_to_delete); |
|
146 | - $wpdb->query('DROP TABLE ' . implode(', ', $tables_to_delete)); |
|
147 | - } |
|
148 | - return $tables_to_delete; |
|
149 | - } |
|
123 | + /** |
|
124 | + * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
125 | + * each table name provided has a wpdb prefix attached, and that it exists. |
|
126 | + * Returns the list actually deleted |
|
127 | + * |
|
128 | + * @param string[] $table_names |
|
129 | + * @return array of table names which we deleted |
|
130 | + * @throws EE_Error |
|
131 | + * @global WPDB $wpdb |
|
132 | + */ |
|
133 | + public function dropTables(array $table_names): array |
|
134 | + { |
|
135 | + $tables_to_delete = []; |
|
136 | + foreach ($table_names as $table_name) { |
|
137 | + $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
138 | + if ($this->getTableAnalysis()->tableExists($table_name)) { |
|
139 | + $tables_to_delete[ $table_name ] = $table_name; |
|
140 | + } |
|
141 | + } |
|
142 | + if (! empty($tables_to_delete)) { |
|
143 | + global $wpdb; |
|
144 | + // make sure we only have a unique strings in the array. |
|
145 | + $tables_to_delete = array_unique($tables_to_delete); |
|
146 | + $wpdb->query('DROP TABLE ' . implode(', ', $tables_to_delete)); |
|
147 | + } |
|
148 | + return $tables_to_delete; |
|
149 | + } |
|
150 | 150 | |
151 | 151 | |
152 | - /** |
|
153 | - * Drops the specified index from the specified table. $table_name can |
|
154 | - * optionally start with $wpdb->prefix or not |
|
155 | - * |
|
156 | - * @param string $table_name |
|
157 | - * @param string $index_name |
|
158 | - * @return bool|int the number of indexes dropped. False if there was a datbase error |
|
159 | - * @throws EE_Error |
|
160 | - * @global wpdb $wpdb |
|
161 | - */ |
|
162 | - public function dropIndex(string $table_name, string $index_name) |
|
163 | - { |
|
164 | - if (apply_filters('FHEE__EEH_Activation__drop_index__short_circuit', false)) { |
|
165 | - return 0; |
|
166 | - } |
|
167 | - global $wpdb; |
|
168 | - $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
169 | - if ($this->getTableAnalysis()->indexExists($table_name, $index_name)) { |
|
170 | - return $wpdb->query("ALTER TABLE $table_name DROP INDEX $index_name"); |
|
171 | - } |
|
172 | - return 0; |
|
173 | - } |
|
152 | + /** |
|
153 | + * Drops the specified index from the specified table. $table_name can |
|
154 | + * optionally start with $wpdb->prefix or not |
|
155 | + * |
|
156 | + * @param string $table_name |
|
157 | + * @param string $index_name |
|
158 | + * @return bool|int the number of indexes dropped. False if there was a datbase error |
|
159 | + * @throws EE_Error |
|
160 | + * @global wpdb $wpdb |
|
161 | + */ |
|
162 | + public function dropIndex(string $table_name, string $index_name) |
|
163 | + { |
|
164 | + if (apply_filters('FHEE__EEH_Activation__drop_index__short_circuit', false)) { |
|
165 | + return 0; |
|
166 | + } |
|
167 | + global $wpdb; |
|
168 | + $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
169 | + if ($this->getTableAnalysis()->indexExists($table_name, $index_name)) { |
|
170 | + return $wpdb->query("ALTER TABLE $table_name DROP INDEX $index_name"); |
|
171 | + } |
|
172 | + return 0; |
|
173 | + } |
|
174 | 174 | |
175 | 175 | |
176 | - /** |
|
177 | - * Just creates the requested table. $table_name can |
|
178 | - * optionally start with $wpdb->prefix or not |
|
179 | - * |
|
180 | - * @param string $table_name |
|
181 | - * @param string $create_sql defining the table's columns and indexes |
|
182 | - * @param string $engine (no need to specify "ENGINE=", that's implied) |
|
183 | - * @return void |
|
184 | - * @throws EE_Error |
|
185 | - */ |
|
186 | - public function createTable(string $table_name, string $create_sql, string $engine = 'InnoDB') |
|
187 | - { |
|
188 | - $engine = apply_filters( |
|
189 | - 'FHEE__EventEspresso_core_services_database_TableManager__createTable__engine', |
|
190 | - $engine, |
|
191 | - $table_name, |
|
192 | - $create_sql |
|
193 | - ); |
|
194 | - // does $sql contain valid column information? ( LPT: https://regex101.com/ is great for working out regex patterns ) |
|
195 | - if (preg_match('((((.*?))(,\s))+)', $create_sql, $valid_column_data)) { |
|
196 | - $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
197 | - /** @var wpdb $wpdb */ |
|
198 | - global $wpdb; |
|
199 | - $SQL = "CREATE TABLE $table_name ( $create_sql ) ENGINE=$engine " . $wpdb->get_charset_collate(); |
|
176 | + /** |
|
177 | + * Just creates the requested table. $table_name can |
|
178 | + * optionally start with $wpdb->prefix or not |
|
179 | + * |
|
180 | + * @param string $table_name |
|
181 | + * @param string $create_sql defining the table's columns and indexes |
|
182 | + * @param string $engine (no need to specify "ENGINE=", that's implied) |
|
183 | + * @return void |
|
184 | + * @throws EE_Error |
|
185 | + */ |
|
186 | + public function createTable(string $table_name, string $create_sql, string $engine = 'InnoDB') |
|
187 | + { |
|
188 | + $engine = apply_filters( |
|
189 | + 'FHEE__EventEspresso_core_services_database_TableManager__createTable__engine', |
|
190 | + $engine, |
|
191 | + $table_name, |
|
192 | + $create_sql |
|
193 | + ); |
|
194 | + // does $sql contain valid column information? ( LPT: https://regex101.com/ is great for working out regex patterns ) |
|
195 | + if (preg_match('((((.*?))(,\s))+)', $create_sql, $valid_column_data)) { |
|
196 | + $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
197 | + /** @var wpdb $wpdb */ |
|
198 | + global $wpdb; |
|
199 | + $SQL = "CREATE TABLE $table_name ( $create_sql ) ENGINE=$engine " . $wpdb->get_charset_collate(); |
|
200 | 200 | |
201 | - // get $wpdb to echo errors, but buffer them. This way at least WE know an error |
|
202 | - // happened. And then we can choose to tell the end user |
|
203 | - $old_show_errors_policy = $wpdb->show_errors(); |
|
204 | - $old_error_suppression_policy = $wpdb->suppress_errors(false); |
|
201 | + // get $wpdb to echo errors, but buffer them. This way at least WE know an error |
|
202 | + // happened. And then we can choose to tell the end user |
|
203 | + $old_show_errors_policy = $wpdb->show_errors(); |
|
204 | + $old_error_suppression_policy = $wpdb->suppress_errors(false); |
|
205 | 205 | |
206 | - if (! function_exists('dbDelta')) { |
|
207 | - require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
208 | - } |
|
206 | + if (! function_exists('dbDelta')) { |
|
207 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
208 | + } |
|
209 | 209 | |
210 | - ob_start(); |
|
211 | - dbDelta($SQL); |
|
212 | - $output = ob_get_contents(); |
|
213 | - ob_end_clean(); |
|
214 | - $wpdb->show_errors($old_show_errors_policy); |
|
215 | - $wpdb->suppress_errors($old_error_suppression_policy); |
|
216 | - if (! empty($output)) { |
|
217 | - throw new EE_Error($output); |
|
218 | - } |
|
219 | - } else { |
|
220 | - throw new EE_Error( |
|
221 | - sprintf( |
|
222 | - esc_html__( |
|
223 | - 'The following table creation SQL does not contain valid information about the table columns: %1$s %2$s', |
|
224 | - 'event_espresso' |
|
225 | - ), |
|
226 | - '<br />', |
|
227 | - $create_sql |
|
228 | - ) |
|
229 | - ); |
|
230 | - } |
|
231 | - } |
|
210 | + ob_start(); |
|
211 | + dbDelta($SQL); |
|
212 | + $output = ob_get_contents(); |
|
213 | + ob_end_clean(); |
|
214 | + $wpdb->show_errors($old_show_errors_policy); |
|
215 | + $wpdb->suppress_errors($old_error_suppression_policy); |
|
216 | + if (! empty($output)) { |
|
217 | + throw new EE_Error($output); |
|
218 | + } |
|
219 | + } else { |
|
220 | + throw new EE_Error( |
|
221 | + sprintf( |
|
222 | + esc_html__( |
|
223 | + 'The following table creation SQL does not contain valid information about the table columns: %1$s %2$s', |
|
224 | + 'event_espresso' |
|
225 | + ), |
|
226 | + '<br />', |
|
227 | + $create_sql |
|
228 | + ) |
|
229 | + ); |
|
230 | + } |
|
231 | + } |
|
232 | 232 | |
233 | 233 | |
234 | - /** |
|
235 | - * Drops the specified index if it's size differs from $desired_index_size. |
|
236 | - * WordPress' dbdelta method doesn't automatically change index sizes, so this |
|
237 | - * method can be used to only drop the index if needed, and afterwards dbdelta can be used as normal. |
|
238 | - * If the table doesn't exist, or it exists but the index does not, or returns false |
|
239 | - * |
|
240 | - * @param string $table_name |
|
241 | - * @param string $index_name |
|
242 | - * @param string $column_name if none is provided, we assume the column name matches the index |
|
243 | - * (often true in EE) |
|
244 | - * @param string|int $index_size defaults to TableAnalysis::index_col_size, the max for utf8mb4. |
|
245 | - * @return bool whether an index was dropped or not |
|
246 | - * @throws /EE_Error if table analysis object isn't defined |
|
247 | - */ |
|
248 | - public function dropIndexIfSizeNot( |
|
249 | - string $table_name, |
|
250 | - string $index_name, |
|
251 | - string $column_name = '', |
|
252 | - $index_size = TableAnalysis::INDEX_COLUMN_SIZE |
|
253 | - ) { |
|
254 | - if ($column_name === '') { |
|
255 | - $column_name = $index_name; |
|
256 | - } |
|
257 | - if (! $this->getTableAnalysis()->tableExists($table_name)) { |
|
258 | - return false; |
|
259 | - } |
|
260 | - $index_entries = $this->getTableAnalysis()->showIndexes($table_name, $index_name); |
|
261 | - if (empty($index_entries)) { |
|
262 | - return false; |
|
263 | - } |
|
264 | - foreach ($index_entries as $index_entry) { |
|
265 | - if ( |
|
266 | - $column_name === $index_entry->Column_name |
|
267 | - && (string) $index_size !== $index_entry->Sub_part |
|
268 | - ) { |
|
269 | - return $this->dropIndex($table_name, $index_name); |
|
270 | - } |
|
271 | - } |
|
272 | - return false; |
|
273 | - } |
|
234 | + /** |
|
235 | + * Drops the specified index if it's size differs from $desired_index_size. |
|
236 | + * WordPress' dbdelta method doesn't automatically change index sizes, so this |
|
237 | + * method can be used to only drop the index if needed, and afterwards dbdelta can be used as normal. |
|
238 | + * If the table doesn't exist, or it exists but the index does not, or returns false |
|
239 | + * |
|
240 | + * @param string $table_name |
|
241 | + * @param string $index_name |
|
242 | + * @param string $column_name if none is provided, we assume the column name matches the index |
|
243 | + * (often true in EE) |
|
244 | + * @param string|int $index_size defaults to TableAnalysis::index_col_size, the max for utf8mb4. |
|
245 | + * @return bool whether an index was dropped or not |
|
246 | + * @throws /EE_Error if table analysis object isn't defined |
|
247 | + */ |
|
248 | + public function dropIndexIfSizeNot( |
|
249 | + string $table_name, |
|
250 | + string $index_name, |
|
251 | + string $column_name = '', |
|
252 | + $index_size = TableAnalysis::INDEX_COLUMN_SIZE |
|
253 | + ) { |
|
254 | + if ($column_name === '') { |
|
255 | + $column_name = $index_name; |
|
256 | + } |
|
257 | + if (! $this->getTableAnalysis()->tableExists($table_name)) { |
|
258 | + return false; |
|
259 | + } |
|
260 | + $index_entries = $this->getTableAnalysis()->showIndexes($table_name, $index_name); |
|
261 | + if (empty($index_entries)) { |
|
262 | + return false; |
|
263 | + } |
|
264 | + foreach ($index_entries as $index_entry) { |
|
265 | + if ( |
|
266 | + $column_name === $index_entry->Column_name |
|
267 | + && (string) $index_size !== $index_entry->Sub_part |
|
268 | + ) { |
|
269 | + return $this->dropIndex($table_name, $index_name); |
|
270 | + } |
|
271 | + } |
|
272 | + return false; |
|
273 | + } |
|
274 | 274 | |
275 | 275 | |
276 | - /** |
|
277 | - * @param string $table_name |
|
278 | - * @param string $index_name |
|
279 | - * @param string $column_name |
|
280 | - * @param string $index_type |
|
281 | - * @param string|null $index_size |
|
282 | - * @param bool $descending |
|
283 | - * @throws EE_Error |
|
284 | - */ |
|
285 | - public function addIndex( |
|
286 | - string $table_name, |
|
287 | - string $index_name, |
|
288 | - string $column_name, |
|
289 | - string $index_type = TableAnalysis::INDEX_TYPE_INDEX, |
|
290 | - ?string $index_size = null, |
|
291 | - bool $descending = false |
|
292 | - ) { |
|
293 | - if (apply_filters('FHEE__EEH_Activation__add_index__short_circuit', false)) { |
|
294 | - return; |
|
295 | - } |
|
296 | - global $wpdb; |
|
297 | - $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
298 | - if (! $this->getTableAnalysis()->indexExists($table_name, $index_name)) { |
|
299 | - // ensure index type is valid |
|
300 | - $index_type = in_array($index_type, [TableAnalysis::INDEX_TYPE_INDEX, TableAnalysis::INDEX_TYPE_UNIQUE]) |
|
301 | - ? $index_type |
|
302 | - : TableAnalysis::INDEX_TYPE_INDEX; |
|
303 | - // ensure index size does not exceed max allowed for utf8mb4 |
|
304 | - $index_size = $index_size ? max($index_size, TableAnalysis::INDEX_COLUMN_SIZE) : null; |
|
305 | - // if index size is set, then add it to the column name |
|
306 | - $column_name = $index_size ? "$column_name($index_size)" : $column_name; |
|
307 | - // add DESC to the column name for indexes that will benefit from that (like timestamps) |
|
308 | - $column_name = $descending ? "$column_name DESC" : $column_name; |
|
309 | - $wpdb->query("ALTER TABLE $table_name ADD $index_type $index_name ($column_name);"); |
|
310 | - } |
|
311 | - } |
|
276 | + /** |
|
277 | + * @param string $table_name |
|
278 | + * @param string $index_name |
|
279 | + * @param string $column_name |
|
280 | + * @param string $index_type |
|
281 | + * @param string|null $index_size |
|
282 | + * @param bool $descending |
|
283 | + * @throws EE_Error |
|
284 | + */ |
|
285 | + public function addIndex( |
|
286 | + string $table_name, |
|
287 | + string $index_name, |
|
288 | + string $column_name, |
|
289 | + string $index_type = TableAnalysis::INDEX_TYPE_INDEX, |
|
290 | + ?string $index_size = null, |
|
291 | + bool $descending = false |
|
292 | + ) { |
|
293 | + if (apply_filters('FHEE__EEH_Activation__add_index__short_circuit', false)) { |
|
294 | + return; |
|
295 | + } |
|
296 | + global $wpdb; |
|
297 | + $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
298 | + if (! $this->getTableAnalysis()->indexExists($table_name, $index_name)) { |
|
299 | + // ensure index type is valid |
|
300 | + $index_type = in_array($index_type, [TableAnalysis::INDEX_TYPE_INDEX, TableAnalysis::INDEX_TYPE_UNIQUE]) |
|
301 | + ? $index_type |
|
302 | + : TableAnalysis::INDEX_TYPE_INDEX; |
|
303 | + // ensure index size does not exceed max allowed for utf8mb4 |
|
304 | + $index_size = $index_size ? max($index_size, TableAnalysis::INDEX_COLUMN_SIZE) : null; |
|
305 | + // if index size is set, then add it to the column name |
|
306 | + $column_name = $index_size ? "$column_name($index_size)" : $column_name; |
|
307 | + // add DESC to the column name for indexes that will benefit from that (like timestamps) |
|
308 | + $column_name = $descending ? "$column_name DESC" : $column_name; |
|
309 | + $wpdb->query("ALTER TABLE $table_name ADD $index_type $index_name ($column_name);"); |
|
310 | + } |
|
311 | + } |
|
312 | 312 | } |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | global $wpdb; |
67 | 67 | $full_table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
68 | 68 | $columns = $this->getTableColumns($table_name); |
69 | - if (! in_array($column_name, $columns)) { |
|
69 | + if ( ! in_array($column_name, $columns)) { |
|
70 | 70 | $alter_query = "ALTER TABLE $full_table_name ADD $column_name $column_info"; |
71 | 71 | return $wpdb->query($alter_query); |
72 | 72 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | global $wpdb; |
89 | 89 | $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
90 | 90 | $field_array = []; |
91 | - if (! empty($table_name)) { |
|
91 | + if ( ! empty($table_name)) { |
|
92 | 92 | $columns = $wpdb->get_results("SHOW COLUMNS FROM $table_name "); |
93 | 93 | if ($columns !== false) { |
94 | 94 | foreach ($columns as $column) { |
@@ -136,14 +136,14 @@ discard block |
||
136 | 136 | foreach ($table_names as $table_name) { |
137 | 137 | $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
138 | 138 | if ($this->getTableAnalysis()->tableExists($table_name)) { |
139 | - $tables_to_delete[ $table_name ] = $table_name; |
|
139 | + $tables_to_delete[$table_name] = $table_name; |
|
140 | 140 | } |
141 | 141 | } |
142 | - if (! empty($tables_to_delete)) { |
|
142 | + if ( ! empty($tables_to_delete)) { |
|
143 | 143 | global $wpdb; |
144 | 144 | // make sure we only have a unique strings in the array. |
145 | 145 | $tables_to_delete = array_unique($tables_to_delete); |
146 | - $wpdb->query('DROP TABLE ' . implode(', ', $tables_to_delete)); |
|
146 | + $wpdb->query('DROP TABLE '.implode(', ', $tables_to_delete)); |
|
147 | 147 | } |
148 | 148 | return $tables_to_delete; |
149 | 149 | } |
@@ -196,15 +196,15 @@ discard block |
||
196 | 196 | $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
197 | 197 | /** @var wpdb $wpdb */ |
198 | 198 | global $wpdb; |
199 | - $SQL = "CREATE TABLE $table_name ( $create_sql ) ENGINE=$engine " . $wpdb->get_charset_collate(); |
|
199 | + $SQL = "CREATE TABLE $table_name ( $create_sql ) ENGINE=$engine ".$wpdb->get_charset_collate(); |
|
200 | 200 | |
201 | 201 | // get $wpdb to echo errors, but buffer them. This way at least WE know an error |
202 | 202 | // happened. And then we can choose to tell the end user |
203 | 203 | $old_show_errors_policy = $wpdb->show_errors(); |
204 | 204 | $old_error_suppression_policy = $wpdb->suppress_errors(false); |
205 | 205 | |
206 | - if (! function_exists('dbDelta')) { |
|
207 | - require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
206 | + if ( ! function_exists('dbDelta')) { |
|
207 | + require_once(ABSPATH.'wp-admin/includes/upgrade.php'); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | ob_start(); |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | ob_end_clean(); |
214 | 214 | $wpdb->show_errors($old_show_errors_policy); |
215 | 215 | $wpdb->suppress_errors($old_error_suppression_policy); |
216 | - if (! empty($output)) { |
|
216 | + if ( ! empty($output)) { |
|
217 | 217 | throw new EE_Error($output); |
218 | 218 | } |
219 | 219 | } else { |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | if ($column_name === '') { |
255 | 255 | $column_name = $index_name; |
256 | 256 | } |
257 | - if (! $this->getTableAnalysis()->tableExists($table_name)) { |
|
257 | + if ( ! $this->getTableAnalysis()->tableExists($table_name)) { |
|
258 | 258 | return false; |
259 | 259 | } |
260 | 260 | $index_entries = $this->getTableAnalysis()->showIndexes($table_name, $index_name); |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | } |
296 | 296 | global $wpdb; |
297 | 297 | $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
298 | - if (! $this->getTableAnalysis()->indexExists($table_name, $index_name)) { |
|
298 | + if ( ! $this->getTableAnalysis()->indexExists($table_name, $index_name)) { |
|
299 | 299 | // ensure index type is valid |
300 | 300 | $index_type = in_array($index_type, [TableAnalysis::INDEX_TYPE_INDEX, TableAnalysis::INDEX_TYPE_UNIQUE]) |
301 | 301 | ? $index_type |