@@ -30,185 +30,185 @@ |
||
30 | 30 | class ShortcodesManager |
31 | 31 | { |
32 | 32 | |
33 | - /** |
|
34 | - * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
35 | - */ |
|
36 | - private $legacy_shortcodes_manager; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var ShortcodeInterface[] $shortcodes |
|
40 | - */ |
|
41 | - private $shortcodes; |
|
42 | - |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * ShortcodesManager constructor |
|
47 | - * |
|
48 | - * @param LegacyShortcodesManager $legacy_shortcodes_manager |
|
49 | - */ |
|
50 | - public function __construct(LegacyShortcodesManager $legacy_shortcodes_manager) { |
|
51 | - $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
52 | - // assemble a list of installed and active shortcodes |
|
53 | - add_action( |
|
54 | - 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
55 | - array($this, 'registerShortcodes'), |
|
56 | - 999 |
|
57 | - ); |
|
58 | - // call add_shortcode() for all installed shortcodes |
|
59 | - add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'addShortcodes')); |
|
60 | - // check content for shortcodes, the old way, and the more efficient new way |
|
61 | - add_action('parse_query', array($this->legacy_shortcodes_manager, 'initializeShortcodes'), 5); |
|
62 | - add_action('get_header', array($this, 'getHeader')); |
|
63 | - } |
|
64 | - |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * @return CollectionInterface|ShortcodeInterface[] |
|
69 | - * @throws InvalidIdentifierException |
|
70 | - * @throws InvalidInterfaceException |
|
71 | - * @throws InvalidFilePathException |
|
72 | - * @throws InvalidEntityException |
|
73 | - * @throws InvalidDataTypeException |
|
74 | - * @throws InvalidClassException |
|
75 | - */ |
|
76 | - public function getShortcodes() |
|
77 | - { |
|
78 | - if ( ! $this->shortcodes instanceof CollectionInterface) { |
|
79 | - $this->shortcodes = $this->loadShortcodesCollection(); |
|
80 | - } |
|
81 | - return $this->shortcodes; |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * @return CollectionInterface|ShortcodeInterface[] |
|
88 | - * @throws InvalidIdentifierException |
|
89 | - * @throws InvalidInterfaceException |
|
90 | - * @throws InvalidFilePathException |
|
91 | - * @throws InvalidEntityException |
|
92 | - * @throws InvalidDataTypeException |
|
93 | - * @throws InvalidClassException |
|
94 | - */ |
|
95 | - protected function loadShortcodesCollection() |
|
96 | - { |
|
97 | - $loader = new CollectionLoader( |
|
98 | - new CollectionDetails( |
|
99 | - // collection name |
|
100 | - 'shortcodes', |
|
101 | - // collection interface |
|
102 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
103 | - // FQCNs for classes to add (all classes within that namespace will be loaded) |
|
104 | - array('EventEspresso\core\domain\entities\shortcodes'), |
|
105 | - // filepaths to classes to add |
|
106 | - array(), |
|
107 | - // filemask to use if parsing folder for files to add |
|
108 | - '', |
|
109 | - // what to use as identifier for collection entities |
|
110 | - // using CLASS NAME prevents duplicates (works like a singleton) |
|
111 | - CollectionDetails::ID_CLASS_NAME |
|
112 | - ) |
|
113 | - ); |
|
114 | - return $loader->getCollection(); |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * @return void |
|
121 | - * @throws InvalidInterfaceException |
|
122 | - * @throws InvalidIdentifierException |
|
123 | - * @throws InvalidFilePathException |
|
124 | - * @throws InvalidEntityException |
|
125 | - * @throws InvalidDataTypeException |
|
126 | - * @throws InvalidClassException |
|
127 | - */ |
|
128 | - public function registerShortcodes() |
|
129 | - { |
|
130 | - $this->shortcodes = apply_filters( |
|
131 | - 'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection', |
|
132 | - $this->getShortcodes() |
|
133 | - ); |
|
134 | - $this->legacy_shortcodes_manager->registerShortcodes(); |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * @return void |
|
141 | - */ |
|
142 | - public function addShortcodes() |
|
143 | - { |
|
144 | - // cycle thru shortcode folders |
|
145 | - foreach ($this->shortcodes as $shortcode) { |
|
146 | - /** @var ShortcodeInterface $shortcode */ |
|
147 | - if ( $shortcode instanceof EnqueueAssetsInterface) { |
|
148 | - add_action('wp_enqueue_scripts', array($shortcode, 'registerScriptsAndStylesheets'), 10); |
|
149 | - add_action('wp_enqueue_scripts', array($shortcode, 'enqueueStylesheets'), 11); |
|
150 | - } |
|
151 | - // add_shortcode() if it has not already been added |
|
152 | - if ( ! shortcode_exists($shortcode->getTag())) { |
|
153 | - add_shortcode($shortcode->getTag(), array($shortcode, 'processShortcodeCallback')); |
|
154 | - } |
|
155 | - } |
|
156 | - $this->legacy_shortcodes_manager->addShortcodes(); |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * callback for the WP "get_header" hook point |
|
163 | - * checks posts for EE shortcodes, and initializes them, |
|
164 | - * then toggles filter switch that loads core default assets |
|
165 | - * |
|
166 | - * @return void |
|
167 | - */ |
|
168 | - public function getHeader() |
|
169 | - { |
|
170 | - global $wp_query; |
|
171 | - if (empty($wp_query->posts)) { |
|
172 | - return; |
|
173 | - } |
|
174 | - $load_assets = false; |
|
175 | - // array of posts displayed in current request |
|
176 | - $posts = is_array($wp_query->posts) ? $wp_query->posts : array($wp_query->posts); |
|
177 | - foreach ($posts as $post) { |
|
178 | - // now check post content and excerpt for EE shortcodes |
|
179 | - $load_assets = $this->parseContentForShortcodes($post->post_content) |
|
180 | - ? true |
|
181 | - : $load_assets; |
|
182 | - } |
|
183 | - if ($load_assets) { |
|
184 | - $this->legacy_shortcodes_manager->registry()->REQ->set_espresso_page(true); |
|
185 | - add_filter('FHEE_load_css', '__return_true'); |
|
186 | - add_filter('FHEE_load_js', '__return_true'); |
|
187 | - } |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * checks supplied content against list of shortcodes, |
|
194 | - * then initializes any found shortcodes, and returns true. |
|
195 | - * returns false if no shortcodes found. |
|
196 | - * |
|
197 | - * @param string $content |
|
198 | - * @return bool |
|
199 | - */ |
|
200 | - public function parseContentForShortcodes($content) |
|
201 | - { |
|
202 | - $has_shortcode = false; |
|
203 | - foreach ($this->shortcodes as $shortcode) { |
|
204 | - /** @var ShortcodeInterface $shortcode */ |
|
205 | - if (has_shortcode($content, $shortcode->getTag())) { |
|
206 | - $shortcode->initializeShortcode(); |
|
207 | - $has_shortcode = true; |
|
208 | - } |
|
209 | - } |
|
210 | - return $has_shortcode; |
|
211 | - } |
|
33 | + /** |
|
34 | + * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
35 | + */ |
|
36 | + private $legacy_shortcodes_manager; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var ShortcodeInterface[] $shortcodes |
|
40 | + */ |
|
41 | + private $shortcodes; |
|
42 | + |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * ShortcodesManager constructor |
|
47 | + * |
|
48 | + * @param LegacyShortcodesManager $legacy_shortcodes_manager |
|
49 | + */ |
|
50 | + public function __construct(LegacyShortcodesManager $legacy_shortcodes_manager) { |
|
51 | + $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
52 | + // assemble a list of installed and active shortcodes |
|
53 | + add_action( |
|
54 | + 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
55 | + array($this, 'registerShortcodes'), |
|
56 | + 999 |
|
57 | + ); |
|
58 | + // call add_shortcode() for all installed shortcodes |
|
59 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'addShortcodes')); |
|
60 | + // check content for shortcodes, the old way, and the more efficient new way |
|
61 | + add_action('parse_query', array($this->legacy_shortcodes_manager, 'initializeShortcodes'), 5); |
|
62 | + add_action('get_header', array($this, 'getHeader')); |
|
63 | + } |
|
64 | + |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * @return CollectionInterface|ShortcodeInterface[] |
|
69 | + * @throws InvalidIdentifierException |
|
70 | + * @throws InvalidInterfaceException |
|
71 | + * @throws InvalidFilePathException |
|
72 | + * @throws InvalidEntityException |
|
73 | + * @throws InvalidDataTypeException |
|
74 | + * @throws InvalidClassException |
|
75 | + */ |
|
76 | + public function getShortcodes() |
|
77 | + { |
|
78 | + if ( ! $this->shortcodes instanceof CollectionInterface) { |
|
79 | + $this->shortcodes = $this->loadShortcodesCollection(); |
|
80 | + } |
|
81 | + return $this->shortcodes; |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * @return CollectionInterface|ShortcodeInterface[] |
|
88 | + * @throws InvalidIdentifierException |
|
89 | + * @throws InvalidInterfaceException |
|
90 | + * @throws InvalidFilePathException |
|
91 | + * @throws InvalidEntityException |
|
92 | + * @throws InvalidDataTypeException |
|
93 | + * @throws InvalidClassException |
|
94 | + */ |
|
95 | + protected function loadShortcodesCollection() |
|
96 | + { |
|
97 | + $loader = new CollectionLoader( |
|
98 | + new CollectionDetails( |
|
99 | + // collection name |
|
100 | + 'shortcodes', |
|
101 | + // collection interface |
|
102 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
103 | + // FQCNs for classes to add (all classes within that namespace will be loaded) |
|
104 | + array('EventEspresso\core\domain\entities\shortcodes'), |
|
105 | + // filepaths to classes to add |
|
106 | + array(), |
|
107 | + // filemask to use if parsing folder for files to add |
|
108 | + '', |
|
109 | + // what to use as identifier for collection entities |
|
110 | + // using CLASS NAME prevents duplicates (works like a singleton) |
|
111 | + CollectionDetails::ID_CLASS_NAME |
|
112 | + ) |
|
113 | + ); |
|
114 | + return $loader->getCollection(); |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * @return void |
|
121 | + * @throws InvalidInterfaceException |
|
122 | + * @throws InvalidIdentifierException |
|
123 | + * @throws InvalidFilePathException |
|
124 | + * @throws InvalidEntityException |
|
125 | + * @throws InvalidDataTypeException |
|
126 | + * @throws InvalidClassException |
|
127 | + */ |
|
128 | + public function registerShortcodes() |
|
129 | + { |
|
130 | + $this->shortcodes = apply_filters( |
|
131 | + 'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection', |
|
132 | + $this->getShortcodes() |
|
133 | + ); |
|
134 | + $this->legacy_shortcodes_manager->registerShortcodes(); |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * @return void |
|
141 | + */ |
|
142 | + public function addShortcodes() |
|
143 | + { |
|
144 | + // cycle thru shortcode folders |
|
145 | + foreach ($this->shortcodes as $shortcode) { |
|
146 | + /** @var ShortcodeInterface $shortcode */ |
|
147 | + if ( $shortcode instanceof EnqueueAssetsInterface) { |
|
148 | + add_action('wp_enqueue_scripts', array($shortcode, 'registerScriptsAndStylesheets'), 10); |
|
149 | + add_action('wp_enqueue_scripts', array($shortcode, 'enqueueStylesheets'), 11); |
|
150 | + } |
|
151 | + // add_shortcode() if it has not already been added |
|
152 | + if ( ! shortcode_exists($shortcode->getTag())) { |
|
153 | + add_shortcode($shortcode->getTag(), array($shortcode, 'processShortcodeCallback')); |
|
154 | + } |
|
155 | + } |
|
156 | + $this->legacy_shortcodes_manager->addShortcodes(); |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * callback for the WP "get_header" hook point |
|
163 | + * checks posts for EE shortcodes, and initializes them, |
|
164 | + * then toggles filter switch that loads core default assets |
|
165 | + * |
|
166 | + * @return void |
|
167 | + */ |
|
168 | + public function getHeader() |
|
169 | + { |
|
170 | + global $wp_query; |
|
171 | + if (empty($wp_query->posts)) { |
|
172 | + return; |
|
173 | + } |
|
174 | + $load_assets = false; |
|
175 | + // array of posts displayed in current request |
|
176 | + $posts = is_array($wp_query->posts) ? $wp_query->posts : array($wp_query->posts); |
|
177 | + foreach ($posts as $post) { |
|
178 | + // now check post content and excerpt for EE shortcodes |
|
179 | + $load_assets = $this->parseContentForShortcodes($post->post_content) |
|
180 | + ? true |
|
181 | + : $load_assets; |
|
182 | + } |
|
183 | + if ($load_assets) { |
|
184 | + $this->legacy_shortcodes_manager->registry()->REQ->set_espresso_page(true); |
|
185 | + add_filter('FHEE_load_css', '__return_true'); |
|
186 | + add_filter('FHEE_load_js', '__return_true'); |
|
187 | + } |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * checks supplied content against list of shortcodes, |
|
194 | + * then initializes any found shortcodes, and returns true. |
|
195 | + * returns false if no shortcodes found. |
|
196 | + * |
|
197 | + * @param string $content |
|
198 | + * @return bool |
|
199 | + */ |
|
200 | + public function parseContentForShortcodes($content) |
|
201 | + { |
|
202 | + $has_shortcode = false; |
|
203 | + foreach ($this->shortcodes as $shortcode) { |
|
204 | + /** @var ShortcodeInterface $shortcode */ |
|
205 | + if (has_shortcode($content, $shortcode->getTag())) { |
|
206 | + $shortcode->initializeShortcode(); |
|
207 | + $has_shortcode = true; |
|
208 | + } |
|
209 | + } |
|
210 | + return $has_shortcode; |
|
211 | + } |
|
212 | 212 | |
213 | 213 | } |
214 | 214 | // End of file ShortcodesManager.php |
@@ -25,429 +25,429 @@ |
||
25 | 25 | class LegacyShortcodesManager |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * @var EE_Registry $registry |
|
30 | - */ |
|
31 | - private $registry; |
|
32 | - |
|
33 | - |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * LegacyShortcodesManager constructor. |
|
38 | - * |
|
39 | - * @param \EE_Registry $registry |
|
40 | - */ |
|
41 | - public function __construct(EE_Registry $registry) |
|
42 | - { |
|
43 | - $this->registry = $registry; |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * @return EE_Registry |
|
50 | - */ |
|
51 | - public function registry() |
|
52 | - { |
|
53 | - return $this->registry; |
|
54 | - } |
|
55 | - |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * registerShortcodes |
|
60 | - * |
|
61 | - * @return void |
|
62 | - */ |
|
63 | - public function registerShortcodes() |
|
64 | - { |
|
65 | - $this->registry->shortcodes = $this->getShortcodes(); |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * getShortcodes |
|
72 | - * |
|
73 | - * @return array |
|
74 | - */ |
|
75 | - public function getShortcodes() |
|
76 | - { |
|
77 | - // previously this method would glob the shortcodes directory |
|
78 | - // then filter that list of shortcodes to register, |
|
79 | - // but now we are going to just supply an empty array. |
|
80 | - // this allows any shortcodes that have not yet been converted to the new system |
|
81 | - // to still get loaded and processed, albeit using the same legacy logic as before |
|
82 | - $shortcodes_to_register = apply_filters( |
|
83 | - 'FHEE__EE_Config__register_shortcodes__shortcodes_to_register', |
|
84 | - array() |
|
85 | - ); |
|
86 | - if ( ! empty($shortcodes_to_register)) { |
|
87 | - // cycle thru shortcode folders |
|
88 | - foreach ($shortcodes_to_register as $shortcode_path) { |
|
89 | - // add to list of installed shortcode modules |
|
90 | - $this->registerShortcode($shortcode_path); |
|
91 | - } |
|
92 | - } |
|
93 | - // filter list of installed modules |
|
94 | - return apply_filters( |
|
95 | - 'FHEE__EE_Config___register_shortcodes__installed_shortcodes', |
|
96 | - ! empty($this->registry->shortcodes) |
|
97 | - ? $this->registry->shortcodes |
|
98 | - : array() |
|
99 | - ); |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * register_shortcode - makes core aware of this shortcode |
|
106 | - * |
|
107 | - * @access public |
|
108 | - * @param string $shortcode_path - full path up to and including shortcode folder |
|
109 | - * @return bool |
|
110 | - */ |
|
111 | - public function registerShortcode($shortcode_path = null) |
|
112 | - { |
|
113 | - do_action('AHEE__EE_Config__register_shortcode__begin', $shortcode_path); |
|
114 | - $shortcode_ext = '.shortcode.php'; |
|
115 | - // make all separators match |
|
116 | - $shortcode_path = str_replace(array('\\', '/'), DS, $shortcode_path); |
|
117 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
118 | - if (strpos($shortcode_path, $shortcode_ext) !== false) { |
|
119 | - // grab shortcode file name from directory name and break apart at dots |
|
120 | - $shortcode_file = explode('.', basename($shortcode_path)); |
|
121 | - // take first segment from file name pieces and remove class prefix if it exists |
|
122 | - $shortcode = strpos($shortcode_file[0], 'EES_') === 0 |
|
123 | - ? substr($shortcode_file[0], 4) |
|
124 | - : $shortcode_file[0]; |
|
125 | - // sanitize shortcode directory name |
|
126 | - $shortcode = sanitize_key($shortcode); |
|
127 | - // now we need to rebuild the shortcode path |
|
128 | - $shortcode_path = explode(DS, $shortcode_path); |
|
129 | - // remove last segment |
|
130 | - array_pop($shortcode_path); |
|
131 | - // glue it back together |
|
132 | - $shortcode_path = implode(DS, $shortcode_path) . DS; |
|
133 | - } else { |
|
134 | - // we need to generate the filename based off of the folder name |
|
135 | - // grab and sanitize shortcode directory name |
|
136 | - $shortcode = sanitize_key(basename($shortcode_path)); |
|
137 | - $shortcode_path = rtrim($shortcode_path, DS) . DS; |
|
138 | - } |
|
139 | - // create classname from shortcode directory or file name |
|
140 | - $shortcode = str_replace(' ', '_', ucwords(str_replace('_', ' ', $shortcode))); |
|
141 | - // add class prefix |
|
142 | - $shortcode_class = 'EES_' . $shortcode; |
|
143 | - // does the shortcode exist ? |
|
144 | - if ( ! is_readable($shortcode_path . DS . $shortcode_class . $shortcode_ext)) { |
|
145 | - $msg = sprintf( |
|
146 | - esc_html__( |
|
147 | - 'The requested %s shortcode file could not be found or is not readable due to file permissions. It should be in %s', |
|
148 | - 'event_espresso' |
|
149 | - ), |
|
150 | - $shortcode_class, |
|
151 | - $shortcode_path . DS . $shortcode_class . $shortcode_ext |
|
152 | - ); |
|
153 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
154 | - return false; |
|
155 | - } |
|
156 | - // load the shortcode class file |
|
157 | - require_once($shortcode_path . $shortcode_class . $shortcode_ext); |
|
158 | - // verify that class exists |
|
159 | - if ( ! class_exists($shortcode_class)) { |
|
160 | - $msg = sprintf( |
|
161 | - esc_html__('The requested %s shortcode class does not exist.', 'event_espresso'), |
|
162 | - $shortcode_class |
|
163 | - ); |
|
164 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
165 | - return false; |
|
166 | - } |
|
167 | - $shortcode = strtoupper($shortcode); |
|
168 | - // add to array of registered shortcodes |
|
169 | - $this->registry->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext; |
|
170 | - return true; |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * _initialize_shortcodes |
|
177 | - * allow shortcodes to set hooks for the rest of the system |
|
178 | - * |
|
179 | - * @access private |
|
180 | - * @return void |
|
181 | - */ |
|
182 | - public function addShortcodes() |
|
183 | - { |
|
184 | - // cycle thru shortcode folders |
|
185 | - foreach ($this->registry->shortcodes as $shortcode => $shortcode_path) { |
|
186 | - // add class prefix |
|
187 | - $shortcode_class = 'EES_' . $shortcode; |
|
188 | - // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
189 | - // which set hooks ? |
|
190 | - if (is_admin()) { |
|
191 | - // fire immediately |
|
192 | - call_user_func(array($shortcode_class, 'set_hooks_admin')); |
|
193 | - } else { |
|
194 | - // delay until other systems are online |
|
195 | - add_action( |
|
196 | - 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
197 | - array($shortcode_class, 'set_hooks') |
|
198 | - ); |
|
199 | - // convert classname to UPPERCASE and create WP shortcode. |
|
200 | - $shortcode_tag = strtoupper($shortcode); |
|
201 | - // but first check if the shortcode has already |
|
202 | - // been added before assigning 'fallback_shortcode_processor' |
|
203 | - if ( ! shortcode_exists($shortcode_tag)) { |
|
204 | - // NOTE: this shortcode declaration will get overridden if the shortcode |
|
205 | - // is successfully detected in the post content in initializeShortcode() |
|
206 | - add_shortcode($shortcode_tag, array($shortcode_class, 'fallback_shortcode_processor')); |
|
207 | - } |
|
208 | - } |
|
209 | - } |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * callback for the WP "get_header" hook point |
|
216 | - * checks posts for EE shortcodes, and initializes them, |
|
217 | - * then toggles filter switch that loads core default assets |
|
218 | - * |
|
219 | - * @param \WP_Query $wp_query |
|
220 | - * @return void |
|
221 | - */ |
|
222 | - public function initializeShortcodes(WP_Query $wp_query) |
|
223 | - { |
|
224 | - if (empty($this->registry->shortcodes) || ! $wp_query->is_main_query() || is_admin()) { |
|
225 | - return; |
|
226 | - } |
|
227 | - global $wp; |
|
228 | - /** @var EE_Front_controller $Front_Controller */ |
|
229 | - $Front_Controller = $this->registry->load_core('Front_Controller', array(), false); |
|
230 | - do_action('AHEE__EE_Front_Controller__initialize_shortcodes__begin', $wp, $Front_Controller); |
|
231 | - $Front_Controller->Request_Handler()->set_request_vars(); |
|
232 | - // grab post_name from request |
|
233 | - $current_post = apply_filters( |
|
234 | - 'FHEE__EE_Front_Controller__initialize_shortcodes__current_post_name', |
|
235 | - $Front_Controller->Request_Handler()->get('post_name') |
|
236 | - ); |
|
237 | - $show_on_front = get_option('show_on_front'); |
|
238 | - // if it's not set, then check if frontpage is blog |
|
239 | - if (empty($current_post)) { |
|
240 | - // yup.. this is the posts page, prepare to load all shortcode modules |
|
241 | - $current_post = 'posts'; |
|
242 | - // unless.. |
|
243 | - if ($show_on_front === 'page') { |
|
244 | - // some other page is set as the homepage |
|
245 | - $page_on_front = get_option('page_on_front'); |
|
246 | - if ($page_on_front) { |
|
247 | - // k now we need to find the post_name for this page |
|
248 | - global $wpdb; |
|
249 | - $page_on_front = $wpdb->get_var( |
|
250 | - $wpdb->prepare( |
|
251 | - "SELECT post_name from {$wpdb->posts} WHERE post_type='page' AND post_status='publish' AND ID=%d", |
|
252 | - $page_on_front |
|
253 | - ) |
|
254 | - ); |
|
255 | - // set the current post slug to what it actually is |
|
256 | - $current_post = $page_on_front ? $page_on_front : $current_post; |
|
257 | - } |
|
258 | - } |
|
259 | - } |
|
260 | - // in case $current_post is hierarchical like: /parent-page/current-page |
|
261 | - $current_post = basename($current_post); |
|
262 | - if ( |
|
263 | - // is current page/post the "blog" page ? |
|
264 | - $current_post === EE_Config::get_page_for_posts() |
|
265 | - // or are we on a category page? |
|
266 | - || ( |
|
267 | - is_array(term_exists($current_post, 'category')) |
|
268 | - || array_key_exists('category_name', $wp->query_vars) |
|
269 | - ) |
|
270 | - ) { |
|
271 | - // initialize all legacy shortcodes |
|
272 | - $load_assets = $this->parseContentForShortcodes('', true); |
|
273 | - } else { |
|
274 | - global $wpdb; |
|
275 | - $post_content = $wpdb->get_var( |
|
276 | - $wpdb->prepare( |
|
277 | - "SELECT post_content from {$wpdb->posts} WHERE post_status='publish' AND post_name=%s", |
|
278 | - $current_post |
|
279 | - ) |
|
280 | - ); |
|
281 | - $load_assets = $this->parseContentForShortcodes($post_content); |
|
282 | - } |
|
283 | - if ($load_assets) { |
|
284 | - $this->registry->REQ->set_espresso_page(true); |
|
285 | - add_filter('FHEE_load_css', '__return_true'); |
|
286 | - add_filter('FHEE_load_js', '__return_true'); |
|
287 | - } |
|
288 | - do_action('AHEE__EE_Front_Controller__initialize_shortcodes__end', $Front_Controller); |
|
289 | - } |
|
290 | - |
|
291 | - |
|
292 | - |
|
293 | - /** |
|
294 | - * checks supplied content against list of legacy shortcodes, |
|
295 | - * then initializes any found shortcodes, and returns true. |
|
296 | - * returns false if no shortcodes found. |
|
297 | - * |
|
298 | - * @param string $content |
|
299 | - * @param bool $load_all if true, then ALL active legacy shortcodes will be initialized |
|
300 | - * @return bool |
|
301 | - */ |
|
302 | - public function parseContentForShortcodes($content = '', $load_all = false) |
|
303 | - { |
|
304 | - $has_shortcode = false; |
|
305 | - foreach ($this->registry->shortcodes as $shortcode_class => $shortcode) { |
|
306 | - if ($load_all || has_shortcode($content, $shortcode_class) ) { |
|
307 | - // load up the shortcode |
|
308 | - $this->initializeShortcode($shortcode_class); |
|
309 | - $has_shortcode = true; |
|
310 | - } |
|
311 | - } |
|
312 | - return $has_shortcode; |
|
313 | - } |
|
314 | - |
|
315 | - |
|
316 | - |
|
317 | - /** |
|
318 | - * given a shortcode name, will instantiate the shortcode and call it's run() method |
|
319 | - * |
|
320 | - * @param string $shortcode_class |
|
321 | - * @param WP $wp |
|
322 | - */ |
|
323 | - public function initializeShortcode($shortcode_class = '', WP $wp = null) |
|
324 | - { |
|
325 | - // don't do anything if shortcode is already initialized |
|
326 | - if ( |
|
327 | - empty($this->registry->shortcodes->{$shortcode_class}) |
|
328 | - || ! is_string($this->registry->shortcodes->{$shortcode_class}) |
|
329 | - ) { |
|
330 | - return; |
|
331 | - } |
|
332 | - // let's pause to reflect on this... |
|
333 | - $sc_reflector = new ReflectionClass(LegacyShortcodesManager::addShortcodeClassPrefix($shortcode_class)); |
|
334 | - // ensure that class is actually a shortcode |
|
335 | - if ( |
|
336 | - defined('WP_DEBUG') |
|
337 | - && WP_DEBUG === true |
|
338 | - && ! $sc_reflector->isSubclassOf('EES_Shortcode') |
|
339 | - ) { |
|
340 | - EE_Error::add_error( |
|
341 | - sprintf( |
|
342 | - esc_html__( |
|
343 | - 'The requested %s shortcode is not of the class "EES_Shortcode". Please check your files.', |
|
344 | - 'event_espresso' |
|
345 | - ), |
|
346 | - $shortcode_class |
|
347 | - ), |
|
348 | - __FILE__, |
|
349 | - __FUNCTION__, |
|
350 | - __LINE__ |
|
351 | - ); |
|
352 | - add_filter('FHEE_run_EE_the_content', '__return_true'); |
|
353 | - return; |
|
354 | - } |
|
355 | - global $wp; |
|
356 | - // and pass the request object to the run method |
|
357 | - $this->registry->shortcodes->{$shortcode_class} = $sc_reflector->newInstance(); |
|
358 | - // fire the shortcode class's run method, so that it can activate resources |
|
359 | - $this->registry->shortcodes->{$shortcode_class}->run($wp); |
|
360 | - } |
|
361 | - |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * get classname, remove EES_prefix, and convert to UPPERCASE |
|
366 | - * |
|
367 | - * @param string $class_name |
|
368 | - * @return string |
|
369 | - */ |
|
370 | - public static function generateShortcodeTagFromClassName($class_name) |
|
371 | - { |
|
372 | - return strtoupper(str_replace('EES_', '', $class_name)); |
|
373 | - } |
|
374 | - |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * add EES_prefix and Capitalize words |
|
379 | - * |
|
380 | - * @param string $tag |
|
381 | - * @return string |
|
382 | - */ |
|
383 | - public static function generateShortcodeClassNameFromTag($tag) |
|
384 | - { |
|
385 | - // order of operation runs from inside to out |
|
386 | - // 5) maybe add prefix |
|
387 | - return LegacyShortcodesManager::addShortcodeClassPrefix( |
|
388 | - // 4) find spaces, replace with underscores |
|
389 | - str_replace( |
|
390 | - ' ', |
|
391 | - '_', |
|
392 | - // 3) capitalize first letter of each word |
|
393 | - ucwords( |
|
394 | - // 2) also change to lowercase so ucwords() will work |
|
395 | - strtolower( |
|
396 | - // 1) find underscores, replace with spaces so ucwords() will work |
|
397 | - str_replace( |
|
398 | - '_', |
|
399 | - ' ', |
|
400 | - $tag |
|
401 | - ) |
|
402 | - ) |
|
403 | - ) |
|
404 | - ) |
|
405 | - ); |
|
406 | - } |
|
407 | - |
|
408 | - |
|
409 | - |
|
410 | - /** |
|
411 | - * maybe add EES_prefix |
|
412 | - * |
|
413 | - * @param string $class_name |
|
414 | - * @return string |
|
415 | - */ |
|
416 | - public static function addShortcodeClassPrefix($class_name) |
|
417 | - { |
|
418 | - return strpos($class_name, 'EES_') === 0 ? $class_name : 'EES_' . $class_name; |
|
419 | - } |
|
420 | - |
|
421 | - |
|
422 | - |
|
423 | - /** |
|
424 | - * @return array |
|
425 | - */ |
|
426 | - public function getEspressoShortcodeTags() |
|
427 | - { |
|
428 | - static $shortcode_tags = array(); |
|
429 | - if (empty($shortcode_tags)) { |
|
430 | - $shortcode_tags = array_keys((array)$this->registry->shortcodes); |
|
431 | - } |
|
432 | - return $shortcode_tags; |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - |
|
437 | - /** |
|
438 | - * @param string $content |
|
439 | - * @return string |
|
440 | - */ |
|
441 | - public function doShortcode($content) |
|
442 | - { |
|
443 | - foreach ($this->getEspressoShortcodeTags() as $shortcode_tag) { |
|
444 | - if (strpos($content, $shortcode_tag) !== false) { |
|
445 | - $shortcode_class = LegacyShortcodesManager::generateShortcodeClassNameFromTag($shortcode_tag); |
|
446 | - $this->initializeShortcode($shortcode_class); |
|
447 | - } |
|
448 | - } |
|
449 | - return do_shortcode($content); |
|
450 | - } |
|
28 | + /** |
|
29 | + * @var EE_Registry $registry |
|
30 | + */ |
|
31 | + private $registry; |
|
32 | + |
|
33 | + |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * LegacyShortcodesManager constructor. |
|
38 | + * |
|
39 | + * @param \EE_Registry $registry |
|
40 | + */ |
|
41 | + public function __construct(EE_Registry $registry) |
|
42 | + { |
|
43 | + $this->registry = $registry; |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * @return EE_Registry |
|
50 | + */ |
|
51 | + public function registry() |
|
52 | + { |
|
53 | + return $this->registry; |
|
54 | + } |
|
55 | + |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * registerShortcodes |
|
60 | + * |
|
61 | + * @return void |
|
62 | + */ |
|
63 | + public function registerShortcodes() |
|
64 | + { |
|
65 | + $this->registry->shortcodes = $this->getShortcodes(); |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * getShortcodes |
|
72 | + * |
|
73 | + * @return array |
|
74 | + */ |
|
75 | + public function getShortcodes() |
|
76 | + { |
|
77 | + // previously this method would glob the shortcodes directory |
|
78 | + // then filter that list of shortcodes to register, |
|
79 | + // but now we are going to just supply an empty array. |
|
80 | + // this allows any shortcodes that have not yet been converted to the new system |
|
81 | + // to still get loaded and processed, albeit using the same legacy logic as before |
|
82 | + $shortcodes_to_register = apply_filters( |
|
83 | + 'FHEE__EE_Config__register_shortcodes__shortcodes_to_register', |
|
84 | + array() |
|
85 | + ); |
|
86 | + if ( ! empty($shortcodes_to_register)) { |
|
87 | + // cycle thru shortcode folders |
|
88 | + foreach ($shortcodes_to_register as $shortcode_path) { |
|
89 | + // add to list of installed shortcode modules |
|
90 | + $this->registerShortcode($shortcode_path); |
|
91 | + } |
|
92 | + } |
|
93 | + // filter list of installed modules |
|
94 | + return apply_filters( |
|
95 | + 'FHEE__EE_Config___register_shortcodes__installed_shortcodes', |
|
96 | + ! empty($this->registry->shortcodes) |
|
97 | + ? $this->registry->shortcodes |
|
98 | + : array() |
|
99 | + ); |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * register_shortcode - makes core aware of this shortcode |
|
106 | + * |
|
107 | + * @access public |
|
108 | + * @param string $shortcode_path - full path up to and including shortcode folder |
|
109 | + * @return bool |
|
110 | + */ |
|
111 | + public function registerShortcode($shortcode_path = null) |
|
112 | + { |
|
113 | + do_action('AHEE__EE_Config__register_shortcode__begin', $shortcode_path); |
|
114 | + $shortcode_ext = '.shortcode.php'; |
|
115 | + // make all separators match |
|
116 | + $shortcode_path = str_replace(array('\\', '/'), DS, $shortcode_path); |
|
117 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
118 | + if (strpos($shortcode_path, $shortcode_ext) !== false) { |
|
119 | + // grab shortcode file name from directory name and break apart at dots |
|
120 | + $shortcode_file = explode('.', basename($shortcode_path)); |
|
121 | + // take first segment from file name pieces and remove class prefix if it exists |
|
122 | + $shortcode = strpos($shortcode_file[0], 'EES_') === 0 |
|
123 | + ? substr($shortcode_file[0], 4) |
|
124 | + : $shortcode_file[0]; |
|
125 | + // sanitize shortcode directory name |
|
126 | + $shortcode = sanitize_key($shortcode); |
|
127 | + // now we need to rebuild the shortcode path |
|
128 | + $shortcode_path = explode(DS, $shortcode_path); |
|
129 | + // remove last segment |
|
130 | + array_pop($shortcode_path); |
|
131 | + // glue it back together |
|
132 | + $shortcode_path = implode(DS, $shortcode_path) . DS; |
|
133 | + } else { |
|
134 | + // we need to generate the filename based off of the folder name |
|
135 | + // grab and sanitize shortcode directory name |
|
136 | + $shortcode = sanitize_key(basename($shortcode_path)); |
|
137 | + $shortcode_path = rtrim($shortcode_path, DS) . DS; |
|
138 | + } |
|
139 | + // create classname from shortcode directory or file name |
|
140 | + $shortcode = str_replace(' ', '_', ucwords(str_replace('_', ' ', $shortcode))); |
|
141 | + // add class prefix |
|
142 | + $shortcode_class = 'EES_' . $shortcode; |
|
143 | + // does the shortcode exist ? |
|
144 | + if ( ! is_readable($shortcode_path . DS . $shortcode_class . $shortcode_ext)) { |
|
145 | + $msg = sprintf( |
|
146 | + esc_html__( |
|
147 | + 'The requested %s shortcode file could not be found or is not readable due to file permissions. It should be in %s', |
|
148 | + 'event_espresso' |
|
149 | + ), |
|
150 | + $shortcode_class, |
|
151 | + $shortcode_path . DS . $shortcode_class . $shortcode_ext |
|
152 | + ); |
|
153 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
154 | + return false; |
|
155 | + } |
|
156 | + // load the shortcode class file |
|
157 | + require_once($shortcode_path . $shortcode_class . $shortcode_ext); |
|
158 | + // verify that class exists |
|
159 | + if ( ! class_exists($shortcode_class)) { |
|
160 | + $msg = sprintf( |
|
161 | + esc_html__('The requested %s shortcode class does not exist.', 'event_espresso'), |
|
162 | + $shortcode_class |
|
163 | + ); |
|
164 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
165 | + return false; |
|
166 | + } |
|
167 | + $shortcode = strtoupper($shortcode); |
|
168 | + // add to array of registered shortcodes |
|
169 | + $this->registry->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext; |
|
170 | + return true; |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * _initialize_shortcodes |
|
177 | + * allow shortcodes to set hooks for the rest of the system |
|
178 | + * |
|
179 | + * @access private |
|
180 | + * @return void |
|
181 | + */ |
|
182 | + public function addShortcodes() |
|
183 | + { |
|
184 | + // cycle thru shortcode folders |
|
185 | + foreach ($this->registry->shortcodes as $shortcode => $shortcode_path) { |
|
186 | + // add class prefix |
|
187 | + $shortcode_class = 'EES_' . $shortcode; |
|
188 | + // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
189 | + // which set hooks ? |
|
190 | + if (is_admin()) { |
|
191 | + // fire immediately |
|
192 | + call_user_func(array($shortcode_class, 'set_hooks_admin')); |
|
193 | + } else { |
|
194 | + // delay until other systems are online |
|
195 | + add_action( |
|
196 | + 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
197 | + array($shortcode_class, 'set_hooks') |
|
198 | + ); |
|
199 | + // convert classname to UPPERCASE and create WP shortcode. |
|
200 | + $shortcode_tag = strtoupper($shortcode); |
|
201 | + // but first check if the shortcode has already |
|
202 | + // been added before assigning 'fallback_shortcode_processor' |
|
203 | + if ( ! shortcode_exists($shortcode_tag)) { |
|
204 | + // NOTE: this shortcode declaration will get overridden if the shortcode |
|
205 | + // is successfully detected in the post content in initializeShortcode() |
|
206 | + add_shortcode($shortcode_tag, array($shortcode_class, 'fallback_shortcode_processor')); |
|
207 | + } |
|
208 | + } |
|
209 | + } |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * callback for the WP "get_header" hook point |
|
216 | + * checks posts for EE shortcodes, and initializes them, |
|
217 | + * then toggles filter switch that loads core default assets |
|
218 | + * |
|
219 | + * @param \WP_Query $wp_query |
|
220 | + * @return void |
|
221 | + */ |
|
222 | + public function initializeShortcodes(WP_Query $wp_query) |
|
223 | + { |
|
224 | + if (empty($this->registry->shortcodes) || ! $wp_query->is_main_query() || is_admin()) { |
|
225 | + return; |
|
226 | + } |
|
227 | + global $wp; |
|
228 | + /** @var EE_Front_controller $Front_Controller */ |
|
229 | + $Front_Controller = $this->registry->load_core('Front_Controller', array(), false); |
|
230 | + do_action('AHEE__EE_Front_Controller__initialize_shortcodes__begin', $wp, $Front_Controller); |
|
231 | + $Front_Controller->Request_Handler()->set_request_vars(); |
|
232 | + // grab post_name from request |
|
233 | + $current_post = apply_filters( |
|
234 | + 'FHEE__EE_Front_Controller__initialize_shortcodes__current_post_name', |
|
235 | + $Front_Controller->Request_Handler()->get('post_name') |
|
236 | + ); |
|
237 | + $show_on_front = get_option('show_on_front'); |
|
238 | + // if it's not set, then check if frontpage is blog |
|
239 | + if (empty($current_post)) { |
|
240 | + // yup.. this is the posts page, prepare to load all shortcode modules |
|
241 | + $current_post = 'posts'; |
|
242 | + // unless.. |
|
243 | + if ($show_on_front === 'page') { |
|
244 | + // some other page is set as the homepage |
|
245 | + $page_on_front = get_option('page_on_front'); |
|
246 | + if ($page_on_front) { |
|
247 | + // k now we need to find the post_name for this page |
|
248 | + global $wpdb; |
|
249 | + $page_on_front = $wpdb->get_var( |
|
250 | + $wpdb->prepare( |
|
251 | + "SELECT post_name from {$wpdb->posts} WHERE post_type='page' AND post_status='publish' AND ID=%d", |
|
252 | + $page_on_front |
|
253 | + ) |
|
254 | + ); |
|
255 | + // set the current post slug to what it actually is |
|
256 | + $current_post = $page_on_front ? $page_on_front : $current_post; |
|
257 | + } |
|
258 | + } |
|
259 | + } |
|
260 | + // in case $current_post is hierarchical like: /parent-page/current-page |
|
261 | + $current_post = basename($current_post); |
|
262 | + if ( |
|
263 | + // is current page/post the "blog" page ? |
|
264 | + $current_post === EE_Config::get_page_for_posts() |
|
265 | + // or are we on a category page? |
|
266 | + || ( |
|
267 | + is_array(term_exists($current_post, 'category')) |
|
268 | + || array_key_exists('category_name', $wp->query_vars) |
|
269 | + ) |
|
270 | + ) { |
|
271 | + // initialize all legacy shortcodes |
|
272 | + $load_assets = $this->parseContentForShortcodes('', true); |
|
273 | + } else { |
|
274 | + global $wpdb; |
|
275 | + $post_content = $wpdb->get_var( |
|
276 | + $wpdb->prepare( |
|
277 | + "SELECT post_content from {$wpdb->posts} WHERE post_status='publish' AND post_name=%s", |
|
278 | + $current_post |
|
279 | + ) |
|
280 | + ); |
|
281 | + $load_assets = $this->parseContentForShortcodes($post_content); |
|
282 | + } |
|
283 | + if ($load_assets) { |
|
284 | + $this->registry->REQ->set_espresso_page(true); |
|
285 | + add_filter('FHEE_load_css', '__return_true'); |
|
286 | + add_filter('FHEE_load_js', '__return_true'); |
|
287 | + } |
|
288 | + do_action('AHEE__EE_Front_Controller__initialize_shortcodes__end', $Front_Controller); |
|
289 | + } |
|
290 | + |
|
291 | + |
|
292 | + |
|
293 | + /** |
|
294 | + * checks supplied content against list of legacy shortcodes, |
|
295 | + * then initializes any found shortcodes, and returns true. |
|
296 | + * returns false if no shortcodes found. |
|
297 | + * |
|
298 | + * @param string $content |
|
299 | + * @param bool $load_all if true, then ALL active legacy shortcodes will be initialized |
|
300 | + * @return bool |
|
301 | + */ |
|
302 | + public function parseContentForShortcodes($content = '', $load_all = false) |
|
303 | + { |
|
304 | + $has_shortcode = false; |
|
305 | + foreach ($this->registry->shortcodes as $shortcode_class => $shortcode) { |
|
306 | + if ($load_all || has_shortcode($content, $shortcode_class) ) { |
|
307 | + // load up the shortcode |
|
308 | + $this->initializeShortcode($shortcode_class); |
|
309 | + $has_shortcode = true; |
|
310 | + } |
|
311 | + } |
|
312 | + return $has_shortcode; |
|
313 | + } |
|
314 | + |
|
315 | + |
|
316 | + |
|
317 | + /** |
|
318 | + * given a shortcode name, will instantiate the shortcode and call it's run() method |
|
319 | + * |
|
320 | + * @param string $shortcode_class |
|
321 | + * @param WP $wp |
|
322 | + */ |
|
323 | + public function initializeShortcode($shortcode_class = '', WP $wp = null) |
|
324 | + { |
|
325 | + // don't do anything if shortcode is already initialized |
|
326 | + if ( |
|
327 | + empty($this->registry->shortcodes->{$shortcode_class}) |
|
328 | + || ! is_string($this->registry->shortcodes->{$shortcode_class}) |
|
329 | + ) { |
|
330 | + return; |
|
331 | + } |
|
332 | + // let's pause to reflect on this... |
|
333 | + $sc_reflector = new ReflectionClass(LegacyShortcodesManager::addShortcodeClassPrefix($shortcode_class)); |
|
334 | + // ensure that class is actually a shortcode |
|
335 | + if ( |
|
336 | + defined('WP_DEBUG') |
|
337 | + && WP_DEBUG === true |
|
338 | + && ! $sc_reflector->isSubclassOf('EES_Shortcode') |
|
339 | + ) { |
|
340 | + EE_Error::add_error( |
|
341 | + sprintf( |
|
342 | + esc_html__( |
|
343 | + 'The requested %s shortcode is not of the class "EES_Shortcode". Please check your files.', |
|
344 | + 'event_espresso' |
|
345 | + ), |
|
346 | + $shortcode_class |
|
347 | + ), |
|
348 | + __FILE__, |
|
349 | + __FUNCTION__, |
|
350 | + __LINE__ |
|
351 | + ); |
|
352 | + add_filter('FHEE_run_EE_the_content', '__return_true'); |
|
353 | + return; |
|
354 | + } |
|
355 | + global $wp; |
|
356 | + // and pass the request object to the run method |
|
357 | + $this->registry->shortcodes->{$shortcode_class} = $sc_reflector->newInstance(); |
|
358 | + // fire the shortcode class's run method, so that it can activate resources |
|
359 | + $this->registry->shortcodes->{$shortcode_class}->run($wp); |
|
360 | + } |
|
361 | + |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * get classname, remove EES_prefix, and convert to UPPERCASE |
|
366 | + * |
|
367 | + * @param string $class_name |
|
368 | + * @return string |
|
369 | + */ |
|
370 | + public static function generateShortcodeTagFromClassName($class_name) |
|
371 | + { |
|
372 | + return strtoupper(str_replace('EES_', '', $class_name)); |
|
373 | + } |
|
374 | + |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * add EES_prefix and Capitalize words |
|
379 | + * |
|
380 | + * @param string $tag |
|
381 | + * @return string |
|
382 | + */ |
|
383 | + public static function generateShortcodeClassNameFromTag($tag) |
|
384 | + { |
|
385 | + // order of operation runs from inside to out |
|
386 | + // 5) maybe add prefix |
|
387 | + return LegacyShortcodesManager::addShortcodeClassPrefix( |
|
388 | + // 4) find spaces, replace with underscores |
|
389 | + str_replace( |
|
390 | + ' ', |
|
391 | + '_', |
|
392 | + // 3) capitalize first letter of each word |
|
393 | + ucwords( |
|
394 | + // 2) also change to lowercase so ucwords() will work |
|
395 | + strtolower( |
|
396 | + // 1) find underscores, replace with spaces so ucwords() will work |
|
397 | + str_replace( |
|
398 | + '_', |
|
399 | + ' ', |
|
400 | + $tag |
|
401 | + ) |
|
402 | + ) |
|
403 | + ) |
|
404 | + ) |
|
405 | + ); |
|
406 | + } |
|
407 | + |
|
408 | + |
|
409 | + |
|
410 | + /** |
|
411 | + * maybe add EES_prefix |
|
412 | + * |
|
413 | + * @param string $class_name |
|
414 | + * @return string |
|
415 | + */ |
|
416 | + public static function addShortcodeClassPrefix($class_name) |
|
417 | + { |
|
418 | + return strpos($class_name, 'EES_') === 0 ? $class_name : 'EES_' . $class_name; |
|
419 | + } |
|
420 | + |
|
421 | + |
|
422 | + |
|
423 | + /** |
|
424 | + * @return array |
|
425 | + */ |
|
426 | + public function getEspressoShortcodeTags() |
|
427 | + { |
|
428 | + static $shortcode_tags = array(); |
|
429 | + if (empty($shortcode_tags)) { |
|
430 | + $shortcode_tags = array_keys((array)$this->registry->shortcodes); |
|
431 | + } |
|
432 | + return $shortcode_tags; |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + |
|
437 | + /** |
|
438 | + * @param string $content |
|
439 | + * @return string |
|
440 | + */ |
|
441 | + public function doShortcode($content) |
|
442 | + { |
|
443 | + foreach ($this->getEspressoShortcodeTags() as $shortcode_tag) { |
|
444 | + if (strpos($content, $shortcode_tag) !== false) { |
|
445 | + $shortcode_class = LegacyShortcodesManager::generateShortcodeClassNameFromTag($shortcode_tag); |
|
446 | + $this->initializeShortcode($shortcode_class); |
|
447 | + } |
|
448 | + } |
|
449 | + return do_shortcode($content); |
|
450 | + } |
|
451 | 451 | |
452 | 452 | |
453 | 453 |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php use EventEspresso\core\services\shortcodes\LegacyShortcodesManager; |
2 | 2 | |
3 | 3 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
4 | - exit('No direct script access allowed'); |
|
4 | + exit('No direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | |
@@ -16,1528 +16,1528 @@ discard block |
||
16 | 16 | final class EE_Config |
17 | 17 | { |
18 | 18 | |
19 | - const OPTION_NAME = 'ee_config'; |
|
20 | - |
|
21 | - const LOG_NAME = 'ee_config_log'; |
|
22 | - |
|
23 | - const LOG_LENGTH = 100; |
|
24 | - |
|
25 | - const ADDON_OPTION_NAMES = 'ee_config_option_names'; |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * instance of the EE_Config object |
|
30 | - * |
|
31 | - * @var EE_Config $_instance |
|
32 | - * @access private |
|
33 | - */ |
|
34 | - private static $_instance; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var boolean $_logging_enabled |
|
38 | - */ |
|
39 | - private static $_logging_enabled = false; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
43 | - */ |
|
44 | - private $legacy_shortcodes_manager; |
|
45 | - |
|
46 | - /** |
|
47 | - * An StdClass whose property names are addon slugs, |
|
48 | - * and values are their config classes |
|
49 | - * |
|
50 | - * @var StdClass |
|
51 | - */ |
|
52 | - public $addons; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var EE_Admin_Config |
|
56 | - */ |
|
57 | - public $admin; |
|
58 | - |
|
59 | - /** |
|
60 | - * @var EE_Core_Config |
|
61 | - */ |
|
62 | - public $core; |
|
63 | - |
|
64 | - /** |
|
65 | - * @var EE_Currency_Config |
|
66 | - */ |
|
67 | - public $currency; |
|
68 | - |
|
69 | - /** |
|
70 | - * @var EE_Organization_Config |
|
71 | - */ |
|
72 | - public $organization; |
|
73 | - |
|
74 | - /** |
|
75 | - * @var EE_Registration_Config |
|
76 | - */ |
|
77 | - public $registration; |
|
78 | - |
|
79 | - /** |
|
80 | - * @var EE_Template_Config |
|
81 | - */ |
|
82 | - public $template_settings; |
|
83 | - |
|
84 | - /** |
|
85 | - * Holds EE environment values. |
|
86 | - * |
|
87 | - * @var EE_Environment_Config |
|
88 | - */ |
|
89 | - public $environment; |
|
90 | - |
|
91 | - /** |
|
92 | - * settings pertaining to Google maps |
|
93 | - * |
|
94 | - * @var EE_Map_Config |
|
95 | - */ |
|
96 | - public $map_settings; |
|
97 | - |
|
98 | - /** |
|
99 | - * settings pertaining to Taxes |
|
100 | - * |
|
101 | - * @var EE_Tax_Config |
|
102 | - */ |
|
103 | - public $tax_settings; |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * Settings pertaining to global messages settings. |
|
108 | - * |
|
109 | - * @var EE_Messages_Config |
|
110 | - */ |
|
111 | - public $messages; |
|
112 | - |
|
113 | - /** |
|
114 | - * @deprecated |
|
115 | - * @var EE_Gateway_Config |
|
116 | - */ |
|
117 | - public $gateway; |
|
118 | - |
|
119 | - /** |
|
120 | - * @var array $_addon_option_names |
|
121 | - * @access private |
|
122 | - */ |
|
123 | - private $_addon_option_names = array(); |
|
124 | - |
|
125 | - /** |
|
126 | - * @var array $_module_route_map |
|
127 | - * @access private |
|
128 | - */ |
|
129 | - private static $_module_route_map = array(); |
|
130 | - |
|
131 | - /** |
|
132 | - * @var array $_module_forward_map |
|
133 | - * @access private |
|
134 | - */ |
|
135 | - private static $_module_forward_map = array(); |
|
136 | - |
|
137 | - /** |
|
138 | - * @var array $_module_view_map |
|
139 | - * @access private |
|
140 | - */ |
|
141 | - private static $_module_view_map = array(); |
|
142 | - |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * @singleton method used to instantiate class object |
|
147 | - * @access public |
|
148 | - * @return EE_Config instance |
|
149 | - */ |
|
150 | - public static function instance() |
|
151 | - { |
|
152 | - // check if class object is instantiated, and instantiated properly |
|
153 | - if (! self::$_instance instanceof EE_Config) { |
|
154 | - self::$_instance = new self(); |
|
155 | - } |
|
156 | - return self::$_instance; |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * Resets the config |
|
163 | - * |
|
164 | - * @param bool $hard_reset if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE |
|
165 | - * (default) leaves the database alone, and merely resets the EE_Config object to |
|
166 | - * reflect its state in the database |
|
167 | - * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave |
|
168 | - * $_instance as NULL. Useful in case you want to forget about the old instance on |
|
169 | - * EE_Config, but might not be ready to instantiate EE_Config currently (eg if the |
|
170 | - * site was put into maintenance mode) |
|
171 | - * @return EE_Config |
|
172 | - */ |
|
173 | - public static function reset($hard_reset = false, $reinstantiate = true) |
|
174 | - { |
|
175 | - if (self::$_instance instanceof EE_Config) { |
|
176 | - if ($hard_reset) { |
|
177 | - self::$_instance->legacy_shortcodes_manager = null; |
|
178 | - self::$_instance->_addon_option_names = array(); |
|
179 | - self::$_instance->_initialize_config(); |
|
180 | - self::$_instance->update_espresso_config(); |
|
181 | - } |
|
182 | - self::$_instance->update_addon_option_names(); |
|
183 | - } |
|
184 | - self::$_instance = null; |
|
185 | - //we don't need to reset the static properties imo because those should |
|
186 | - //only change when a module is added or removed. Currently we don't |
|
187 | - //support removing a module during a request when it previously existed |
|
188 | - if ($reinstantiate) { |
|
189 | - return self::instance(); |
|
190 | - } else { |
|
191 | - return null; |
|
192 | - } |
|
193 | - } |
|
194 | - |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * class constructor |
|
199 | - * |
|
200 | - * @access private |
|
201 | - */ |
|
202 | - private function __construct() |
|
203 | - { |
|
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 | - array($this, 'register_shortcodes_and_modules'), |
|
216 | - 999 |
|
217 | - ); |
|
218 | - // initialize shortcodes and modules |
|
219 | - add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules')); |
|
220 | - // register widgets |
|
221 | - add_action('widgets_init', array($this, 'widgets_init'), 10); |
|
222 | - // shutdown |
|
223 | - add_action('shutdown', array($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 | - /** |
|
233 | - * @return boolean |
|
234 | - */ |
|
235 | - public static function logging_enabled() |
|
236 | - { |
|
237 | - return self::$_logging_enabled; |
|
238 | - } |
|
239 | - |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * use to get the current theme if needed from static context |
|
244 | - * |
|
245 | - * @return string current theme set. |
|
246 | - */ |
|
247 | - public static function get_current_theme() |
|
248 | - { |
|
249 | - return isset(self::$_instance->template_settings->current_espresso_theme) |
|
250 | - ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014'; |
|
251 | - } |
|
252 | - |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * _initialize_config |
|
257 | - * |
|
258 | - * @access private |
|
259 | - * @return void |
|
260 | - */ |
|
261 | - private function _initialize_config() |
|
262 | - { |
|
263 | - EE_Config::trim_log(); |
|
264 | - //set defaults |
|
265 | - $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array()); |
|
266 | - $this->addons = new stdClass(); |
|
267 | - // set _module_route_map |
|
268 | - EE_Config::$_module_route_map = array(); |
|
269 | - // set _module_forward_map |
|
270 | - EE_Config::$_module_forward_map = array(); |
|
271 | - // set _module_view_map |
|
272 | - EE_Config::$_module_view_map = array(); |
|
273 | - } |
|
274 | - |
|
275 | - |
|
276 | - |
|
277 | - /** |
|
278 | - * load core plugin configuration |
|
279 | - * |
|
280 | - * @access private |
|
281 | - * @return void |
|
282 | - */ |
|
283 | - private function _load_core_config() |
|
284 | - { |
|
285 | - // load_core_config__start hook |
|
286 | - do_action('AHEE__EE_Config___load_core_config__start', $this); |
|
287 | - $espresso_config = $this->get_espresso_config(); |
|
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 | - /** |
|
317 | - * _verify_config |
|
318 | - * |
|
319 | - * @access protected |
|
320 | - * @return void |
|
321 | - */ |
|
322 | - protected function _verify_config() |
|
323 | - { |
|
324 | - $this->core = $this->core instanceof EE_Core_Config |
|
325 | - ? $this->core |
|
326 | - : new EE_Core_Config(); |
|
327 | - $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core); |
|
328 | - $this->organization = $this->organization instanceof EE_Organization_Config |
|
329 | - ? $this->organization |
|
330 | - : new EE_Organization_Config(); |
|
331 | - $this->organization = apply_filters( |
|
332 | - 'FHEE__EE_Config___initialize_config__organization', |
|
333 | - $this->organization |
|
334 | - ); |
|
335 | - $this->currency = $this->currency instanceof EE_Currency_Config |
|
336 | - ? $this->currency |
|
337 | - : new EE_Currency_Config(); |
|
338 | - $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency); |
|
339 | - $this->registration = $this->registration instanceof EE_Registration_Config |
|
340 | - ? $this->registration |
|
341 | - : new EE_Registration_Config(); |
|
342 | - $this->registration = apply_filters( |
|
343 | - 'FHEE__EE_Config___initialize_config__registration', |
|
344 | - $this->registration |
|
345 | - ); |
|
346 | - $this->admin = $this->admin instanceof EE_Admin_Config |
|
347 | - ? $this->admin |
|
348 | - : new EE_Admin_Config(); |
|
349 | - $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin); |
|
350 | - $this->template_settings = $this->template_settings instanceof EE_Template_Config |
|
351 | - ? $this->template_settings |
|
352 | - : new EE_Template_Config(); |
|
353 | - $this->template_settings = apply_filters( |
|
354 | - 'FHEE__EE_Config___initialize_config__template_settings', |
|
355 | - $this->template_settings |
|
356 | - ); |
|
357 | - $this->map_settings = $this->map_settings instanceof EE_Map_Config |
|
358 | - ? $this->map_settings |
|
359 | - : new EE_Map_Config(); |
|
360 | - $this->map_settings = apply_filters('FHEE__EE_Config___initialize_config__map_settings', |
|
361 | - $this->map_settings); |
|
362 | - $this->environment = $this->environment instanceof EE_Environment_Config |
|
363 | - ? $this->environment |
|
364 | - : new EE_Environment_Config(); |
|
365 | - $this->environment = apply_filters('FHEE__EE_Config___initialize_config__environment', |
|
366 | - $this->environment); |
|
367 | - $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config |
|
368 | - ? $this->tax_settings |
|
369 | - : new EE_Tax_Config(); |
|
370 | - $this->tax_settings = apply_filters('FHEE__EE_Config___initialize_config__tax_settings', |
|
371 | - $this->tax_settings); |
|
372 | - $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages); |
|
373 | - $this->messages = $this->messages instanceof EE_Messages_Config |
|
374 | - ? $this->messages |
|
375 | - : new EE_Messages_Config(); |
|
376 | - $this->gateway = $this->gateway instanceof EE_Gateway_Config |
|
377 | - ? $this->gateway |
|
378 | - : new EE_Gateway_Config(); |
|
379 | - $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway); |
|
380 | - $this->legacy_shortcodes_manager = null; |
|
381 | - } |
|
382 | - |
|
383 | - |
|
384 | - /** |
|
385 | - * get_espresso_config |
|
386 | - * |
|
387 | - * @access public |
|
388 | - * @return array of espresso config stuff |
|
389 | - */ |
|
390 | - public function get_espresso_config() |
|
391 | - { |
|
392 | - // grab espresso configuration |
|
393 | - return apply_filters( |
|
394 | - 'FHEE__EE_Config__get_espresso_config__CFG', |
|
395 | - get_option(EE_Config::OPTION_NAME, array()) |
|
396 | - ); |
|
397 | - } |
|
398 | - |
|
399 | - |
|
400 | - |
|
401 | - /** |
|
402 | - * double_check_config_comparison |
|
403 | - * |
|
404 | - * @access public |
|
405 | - * @param string $option |
|
406 | - * @param $old_value |
|
407 | - * @param $value |
|
408 | - */ |
|
409 | - public function double_check_config_comparison($option = '', $old_value, $value) |
|
410 | - { |
|
411 | - // make sure we're checking the ee config |
|
412 | - if ($option === EE_Config::OPTION_NAME) { |
|
413 | - // run a loose comparison of the old value against the new value for type and properties, |
|
414 | - // but NOT exact instance like WP update_option does (ie: NOT type safe comparison) |
|
415 | - if ($value != $old_value) { |
|
416 | - // if they are NOT the same, then remove the hook, |
|
417 | - // which means the subsequent update results will be based solely on the update query results |
|
418 | - // the reason we do this is because, as stated above, |
|
419 | - // WP update_option performs an exact instance comparison (===) on any update values passed to it |
|
420 | - // this happens PRIOR to serialization and any subsequent update. |
|
421 | - // If values are found to match their previous old value, |
|
422 | - // then WP bails before performing any update. |
|
423 | - // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version |
|
424 | - // it just pulled from the db, with the one being passed to it (which will not match). |
|
425 | - // HOWEVER, once the object is serialized and passed off to MySQL to update, |
|
426 | - // MySQL MAY ALSO NOT perform the update because |
|
427 | - // the string it sees in the db looks the same as the new one it has been passed!!! |
|
428 | - // This results in the query returning an "affected rows" value of ZERO, |
|
429 | - // which gets returned immediately by WP update_option and looks like an error. |
|
430 | - remove_action('update_option', array($this, 'check_config_updated')); |
|
431 | - } |
|
432 | - } |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - |
|
437 | - /** |
|
438 | - * update_espresso_config |
|
439 | - * |
|
440 | - * @access public |
|
441 | - */ |
|
442 | - protected function _reset_espresso_addon_config() |
|
443 | - { |
|
444 | - $this->_addon_option_names = array(); |
|
445 | - foreach ($this->addons as $addon_name => $addon_config_obj) { |
|
446 | - $addon_config_obj = maybe_unserialize($addon_config_obj); |
|
447 | - $config_class = get_class($addon_config_obj); |
|
448 | - if ($addon_config_obj instanceof $config_class && ! $addon_config_obj instanceof __PHP_Incomplete_Class) { |
|
449 | - $this->update_config('addons', $addon_name, $addon_config_obj, false); |
|
450 | - } |
|
451 | - $this->addons->{$addon_name} = null; |
|
452 | - } |
|
453 | - } |
|
454 | - |
|
455 | - |
|
456 | - |
|
457 | - /** |
|
458 | - * update_espresso_config |
|
459 | - * |
|
460 | - * @access public |
|
461 | - * @param bool $add_success |
|
462 | - * @param bool $add_error |
|
463 | - * @return bool |
|
464 | - */ |
|
465 | - public function update_espresso_config($add_success = false, $add_error = true) |
|
466 | - { |
|
467 | - // don't allow config updates during WP heartbeats |
|
468 | - if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
469 | - return false; |
|
470 | - } |
|
471 | - // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197 |
|
472 | - //$clone = clone( self::$_instance ); |
|
473 | - //self::$_instance = NULL; |
|
474 | - do_action('AHEE__EE_Config__update_espresso_config__begin', $this); |
|
475 | - $this->_reset_espresso_addon_config(); |
|
476 | - // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional |
|
477 | - // but BEFORE the actual update occurs |
|
478 | - add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3); |
|
479 | - // don't want to persist legacy_shortcodes_manager, but don't want to lose it either |
|
480 | - $legacy_shortcodes_manager = $this->legacy_shortcodes_manager; |
|
481 | - $this->legacy_shortcodes_manager = null; |
|
482 | - // now update "ee_config" |
|
483 | - $saved = update_option(EE_Config::OPTION_NAME, $this); |
|
484 | - $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
485 | - EE_Config::log(EE_Config::OPTION_NAME); |
|
486 | - // if not saved... check if the hook we just added still exists; |
|
487 | - // if it does, it means one of two things: |
|
488 | - // that update_option bailed at the ( $value === $old_value ) conditional, |
|
489 | - // or... |
|
490 | - // the db update query returned 0 rows affected |
|
491 | - // (probably because the data value was the same from it's perspective) |
|
492 | - // so the existence of the hook means that a negative result from update_option is NOT an error, |
|
493 | - // but just means no update occurred, so don't display an error to the user. |
|
494 | - // BUT... if update_option returns FALSE, AND the hook is missing, |
|
495 | - // then it means that something truly went wrong |
|
496 | - $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved; |
|
497 | - // remove our action since we don't want it in the system anymore |
|
498 | - remove_action('update_option', array($this, 'double_check_config_comparison'), 1); |
|
499 | - do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved); |
|
500 | - //self::$_instance = $clone; |
|
501 | - //unset( $clone ); |
|
502 | - // if config remains the same or was updated successfully |
|
503 | - if ($saved) { |
|
504 | - if ($add_success) { |
|
505 | - EE_Error::add_success( |
|
506 | - __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'), |
|
507 | - __FILE__, |
|
508 | - __FUNCTION__, |
|
509 | - __LINE__ |
|
510 | - ); |
|
511 | - } |
|
512 | - return true; |
|
513 | - } else { |
|
514 | - if ($add_error) { |
|
515 | - EE_Error::add_error( |
|
516 | - __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'), |
|
517 | - __FILE__, |
|
518 | - __FUNCTION__, |
|
519 | - __LINE__ |
|
520 | - ); |
|
521 | - } |
|
522 | - return false; |
|
523 | - } |
|
524 | - } |
|
525 | - |
|
526 | - |
|
527 | - |
|
528 | - /** |
|
529 | - * _verify_config_params |
|
530 | - * |
|
531 | - * @access private |
|
532 | - * @param string $section |
|
533 | - * @param string $name |
|
534 | - * @param string $config_class |
|
535 | - * @param EE_Config_Base $config_obj |
|
536 | - * @param array $tests_to_run |
|
537 | - * @param bool $display_errors |
|
538 | - * @return bool TRUE on success, FALSE on fail |
|
539 | - */ |
|
540 | - private function _verify_config_params( |
|
541 | - $section = '', |
|
542 | - $name = '', |
|
543 | - $config_class = '', |
|
544 | - $config_obj = null, |
|
545 | - $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8), |
|
546 | - $display_errors = true |
|
547 | - ) { |
|
548 | - try { |
|
549 | - foreach ($tests_to_run as $test) { |
|
550 | - switch ($test) { |
|
551 | - // TEST #1 : check that section was set |
|
552 | - case 1 : |
|
553 | - if (empty($section)) { |
|
554 | - if ($display_errors) { |
|
555 | - throw new EE_Error( |
|
556 | - sprintf( |
|
557 | - __( |
|
558 | - 'No configuration section has been provided while attempting to save "%s".', |
|
559 | - 'event_espresso' |
|
560 | - ), |
|
561 | - $config_class |
|
562 | - ) |
|
563 | - ); |
|
564 | - } |
|
565 | - return false; |
|
566 | - } |
|
567 | - break; |
|
568 | - // TEST #2 : check that settings section exists |
|
569 | - case 2 : |
|
570 | - if (! isset($this->{$section})) { |
|
571 | - if ($display_errors) { |
|
572 | - throw new EE_Error( |
|
573 | - sprintf( |
|
574 | - __('The "%s" configuration section does not exist.', 'event_espresso'), |
|
575 | - $section |
|
576 | - ) |
|
577 | - ); |
|
578 | - } |
|
579 | - return false; |
|
580 | - } |
|
581 | - break; |
|
582 | - // TEST #3 : check that section is the proper format |
|
583 | - case 3 : |
|
584 | - if ( |
|
585 | - ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
586 | - ) { |
|
587 | - if ($display_errors) { |
|
588 | - throw new EE_Error( |
|
589 | - sprintf( |
|
590 | - __( |
|
591 | - 'The "%s" configuration settings have not been formatted correctly.', |
|
592 | - 'event_espresso' |
|
593 | - ), |
|
594 | - $section |
|
595 | - ) |
|
596 | - ); |
|
597 | - } |
|
598 | - return false; |
|
599 | - } |
|
600 | - break; |
|
601 | - // TEST #4 : check that config section name has been set |
|
602 | - case 4 : |
|
603 | - if (empty($name)) { |
|
604 | - if ($display_errors) { |
|
605 | - throw new EE_Error( |
|
606 | - __( |
|
607 | - 'No name has been provided for the specific configuration section.', |
|
608 | - 'event_espresso' |
|
609 | - ) |
|
610 | - ); |
|
611 | - } |
|
612 | - return false; |
|
613 | - } |
|
614 | - break; |
|
615 | - // TEST #5 : check that a config class name has been set |
|
616 | - case 5 : |
|
617 | - if (empty($config_class)) { |
|
618 | - if ($display_errors) { |
|
619 | - throw new EE_Error( |
|
620 | - __( |
|
621 | - 'No class name has been provided for the specific configuration section.', |
|
622 | - 'event_espresso' |
|
623 | - ) |
|
624 | - ); |
|
625 | - } |
|
626 | - return false; |
|
627 | - } |
|
628 | - break; |
|
629 | - // TEST #6 : verify config class is accessible |
|
630 | - case 6 : |
|
631 | - if (! class_exists($config_class)) { |
|
632 | - if ($display_errors) { |
|
633 | - throw new EE_Error( |
|
634 | - sprintf( |
|
635 | - __( |
|
636 | - 'The "%s" class does not exist. Please ensure that an autoloader has been set for it.', |
|
637 | - 'event_espresso' |
|
638 | - ), |
|
639 | - $config_class |
|
640 | - ) |
|
641 | - ); |
|
642 | - } |
|
643 | - return false; |
|
644 | - } |
|
645 | - break; |
|
646 | - // TEST #7 : check that config has even been set |
|
647 | - case 7 : |
|
648 | - if (! isset($this->{$section}->{$name})) { |
|
649 | - if ($display_errors) { |
|
650 | - throw new EE_Error( |
|
651 | - sprintf( |
|
652 | - __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
653 | - $section, |
|
654 | - $name |
|
655 | - ) |
|
656 | - ); |
|
657 | - } |
|
658 | - return false; |
|
659 | - } else { |
|
660 | - // and make sure it's not serialized |
|
661 | - $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name}); |
|
662 | - } |
|
663 | - break; |
|
664 | - // TEST #8 : check that config is the requested type |
|
665 | - case 8 : |
|
666 | - if (! $this->{$section}->{$name} instanceof $config_class) { |
|
667 | - if ($display_errors) { |
|
668 | - throw new EE_Error( |
|
669 | - sprintf( |
|
670 | - __( |
|
671 | - 'The configuration for "%1$s->%2$s" is not of the "%3$s" class.', |
|
672 | - 'event_espresso' |
|
673 | - ), |
|
674 | - $section, |
|
675 | - $name, |
|
676 | - $config_class |
|
677 | - ) |
|
678 | - ); |
|
679 | - } |
|
680 | - return false; |
|
681 | - } |
|
682 | - break; |
|
683 | - // TEST #9 : verify config object |
|
684 | - case 9 : |
|
685 | - if (! $config_obj instanceof EE_Config_Base) { |
|
686 | - if ($display_errors) { |
|
687 | - throw new EE_Error( |
|
688 | - sprintf( |
|
689 | - __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
690 | - print_r($config_obj, true) |
|
691 | - ) |
|
692 | - ); |
|
693 | - } |
|
694 | - return false; |
|
695 | - } |
|
696 | - break; |
|
697 | - } |
|
698 | - } |
|
699 | - } catch (EE_Error $e) { |
|
700 | - $e->get_error(); |
|
701 | - } |
|
702 | - // you have successfully run the gauntlet |
|
703 | - return true; |
|
704 | - } |
|
705 | - |
|
706 | - |
|
707 | - |
|
708 | - /** |
|
709 | - * _generate_config_option_name |
|
710 | - * |
|
711 | - * @access protected |
|
712 | - * @param string $section |
|
713 | - * @param string $name |
|
714 | - * @return string |
|
715 | - */ |
|
716 | - private function _generate_config_option_name($section = '', $name = '') |
|
717 | - { |
|
718 | - return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
719 | - } |
|
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 | - /** |
|
742 | - * set_config |
|
743 | - * |
|
744 | - * @access protected |
|
745 | - * @param string $section |
|
746 | - * @param string $name |
|
747 | - * @param string $config_class |
|
748 | - * @param EE_Config_Base $config_obj |
|
749 | - * @return EE_Config_Base |
|
750 | - */ |
|
751 | - public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null) |
|
752 | - { |
|
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 | - update_option($config_option_name, $config_obj); |
|
772 | - $this->{$section}->{$name} = $config_obj; |
|
773 | - return $this->{$section}->{$name}; |
|
774 | - } else { |
|
775 | - // create a wp-option for this config |
|
776 | - if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
777 | - $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
778 | - return $this->{$section}->{$name}; |
|
779 | - } else { |
|
780 | - EE_Error::add_error( |
|
781 | - sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
782 | - __FILE__, |
|
783 | - __FUNCTION__, |
|
784 | - __LINE__ |
|
785 | - ); |
|
786 | - return null; |
|
787 | - } |
|
788 | - } |
|
789 | - } |
|
790 | - |
|
791 | - |
|
792 | - |
|
793 | - /** |
|
794 | - * update_config |
|
795 | - * Important: the config object must ALREADY be set, otherwise this will produce an error. |
|
796 | - * |
|
797 | - * @access public |
|
798 | - * @param string $section |
|
799 | - * @param string $name |
|
800 | - * @param EE_Config_Base|string $config_obj |
|
801 | - * @param bool $throw_errors |
|
802 | - * @return bool |
|
803 | - */ |
|
804 | - public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) |
|
805 | - { |
|
806 | - // don't allow config updates during WP heartbeats |
|
807 | - if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
808 | - return false; |
|
809 | - } |
|
810 | - $config_obj = maybe_unserialize($config_obj); |
|
811 | - // get class name of the incoming object |
|
812 | - $config_class = get_class($config_obj); |
|
813 | - // run tests 1-5 and 9 to verify config |
|
814 | - if (! $this->_verify_config_params( |
|
815 | - $section, |
|
816 | - $name, |
|
817 | - $config_class, |
|
818 | - $config_obj, |
|
819 | - array(1, 2, 3, 4, 7, 9) |
|
820 | - ) |
|
821 | - ) { |
|
822 | - return false; |
|
823 | - } |
|
824 | - $config_option_name = $this->_generate_config_option_name($section, $name); |
|
825 | - // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
|
826 | - if (! isset($this->_addon_option_names[$config_option_name])) { |
|
827 | - // save new config to db |
|
828 | - if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
829 | - return true; |
|
830 | - } |
|
831 | - } else { |
|
832 | - // first check if the record already exists |
|
833 | - $existing_config = get_option($config_option_name); |
|
834 | - $config_obj = serialize($config_obj); |
|
835 | - // just return if db record is already up to date (NOT type safe comparison) |
|
836 | - if ($existing_config == $config_obj) { |
|
837 | - $this->{$section}->{$name} = $config_obj; |
|
838 | - return true; |
|
839 | - } else if (update_option($config_option_name, $config_obj)) { |
|
840 | - EE_Config::log($config_option_name); |
|
841 | - // update wp-option for this config class |
|
842 | - $this->{$section}->{$name} = $config_obj; |
|
843 | - return true; |
|
844 | - } elseif ($throw_errors) { |
|
845 | - EE_Error::add_error( |
|
846 | - sprintf( |
|
847 | - __( |
|
848 | - 'The "%1$s" object stored at"%2$s" was not successfully updated in the database.', |
|
849 | - 'event_espresso' |
|
850 | - ), |
|
851 | - $config_class, |
|
852 | - 'EE_Config->' . $section . '->' . $name |
|
853 | - ), |
|
854 | - __FILE__, |
|
855 | - __FUNCTION__, |
|
856 | - __LINE__ |
|
857 | - ); |
|
858 | - } |
|
859 | - } |
|
860 | - return false; |
|
861 | - } |
|
862 | - |
|
863 | - |
|
864 | - |
|
865 | - /** |
|
866 | - * get_config |
|
867 | - * |
|
868 | - * @access public |
|
869 | - * @param string $section |
|
870 | - * @param string $name |
|
871 | - * @param string $config_class |
|
872 | - * @return mixed EE_Config_Base | NULL |
|
873 | - */ |
|
874 | - public function get_config($section = '', $name = '', $config_class = '') |
|
875 | - { |
|
876 | - // ensure config class is set to something |
|
877 | - $config_class = $this->_set_config_class($config_class, $name); |
|
878 | - // run tests 1-4, 6 and 7 to verify that all params have been set |
|
879 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
880 | - return null; |
|
881 | - } |
|
882 | - // now test if the requested config object exists, but suppress errors |
|
883 | - if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
884 | - // config already exists, so pass it back |
|
885 | - return $this->{$section}->{$name}; |
|
886 | - } |
|
887 | - // load config option from db if it exists |
|
888 | - $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
889 | - // verify the newly retrieved config object, but suppress errors |
|
890 | - if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
891 | - // config is good, so set it and pass it back |
|
892 | - $this->{$section}->{$name} = $config_obj; |
|
893 | - return $this->{$section}->{$name}; |
|
894 | - } |
|
895 | - // oops! $config_obj is not already set and does not exist in the db, so create a new one |
|
896 | - $config_obj = $this->set_config($section, $name, $config_class); |
|
897 | - // verify the newly created config object |
|
898 | - if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
899 | - return $this->{$section}->{$name}; |
|
900 | - } else { |
|
901 | - EE_Error::add_error( |
|
902 | - sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
903 | - __FILE__, |
|
904 | - __FUNCTION__, |
|
905 | - __LINE__ |
|
906 | - ); |
|
907 | - } |
|
908 | - return null; |
|
909 | - } |
|
910 | - |
|
911 | - |
|
912 | - |
|
913 | - /** |
|
914 | - * get_config_option |
|
915 | - * |
|
916 | - * @access public |
|
917 | - * @param string $config_option_name |
|
918 | - * @return mixed EE_Config_Base | FALSE |
|
919 | - */ |
|
920 | - public function get_config_option($config_option_name = '') |
|
921 | - { |
|
922 | - // retrieve the wp-option for this config class. |
|
923 | - $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
924 | - if (empty($config_option)) { |
|
925 | - EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
926 | - } |
|
927 | - return $config_option; |
|
928 | - } |
|
929 | - |
|
930 | - |
|
931 | - |
|
932 | - /** |
|
933 | - * log |
|
934 | - * |
|
935 | - * @param string $config_option_name |
|
936 | - */ |
|
937 | - public static function log($config_option_name = '') |
|
938 | - { |
|
939 | - if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
940 | - $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
941 | - //copy incoming $_REQUEST and sanitize it so we can save it |
|
942 | - $_request = $_REQUEST; |
|
943 | - array_walk_recursive($_request, 'sanitize_text_field'); |
|
944 | - $config_log[(string)microtime(true)] = array( |
|
945 | - 'config_name' => $config_option_name, |
|
946 | - 'request' => $_request, |
|
947 | - ); |
|
948 | - update_option(EE_Config::LOG_NAME, $config_log); |
|
949 | - } |
|
950 | - } |
|
951 | - |
|
952 | - |
|
953 | - |
|
954 | - /** |
|
955 | - * trim_log |
|
956 | - * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
|
957 | - */ |
|
958 | - public static function trim_log() |
|
959 | - { |
|
960 | - if (! EE_Config::logging_enabled()) { |
|
961 | - return; |
|
962 | - } |
|
963 | - $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
964 | - $log_length = count($config_log); |
|
965 | - if ($log_length > EE_Config::LOG_LENGTH) { |
|
966 | - ksort($config_log); |
|
967 | - $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
968 | - update_option(EE_Config::LOG_NAME, $config_log); |
|
969 | - } |
|
970 | - } |
|
971 | - |
|
972 | - |
|
973 | - |
|
974 | - /** |
|
975 | - * get_page_for_posts |
|
976 | - * if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the |
|
977 | - * wp-option "page_for_posts", or "posts" if no page is selected |
|
978 | - * |
|
979 | - * @access public |
|
980 | - * @return string |
|
981 | - */ |
|
982 | - public static function get_page_for_posts() |
|
983 | - { |
|
984 | - $page_for_posts = get_option('page_for_posts'); |
|
985 | - if (! $page_for_posts) { |
|
986 | - return 'posts'; |
|
987 | - } |
|
988 | - /** @type WPDB $wpdb */ |
|
989 | - global $wpdb; |
|
990 | - $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
991 | - return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
992 | - } |
|
993 | - |
|
994 | - |
|
995 | - |
|
996 | - /** |
|
997 | - * register_shortcodes_and_modules. |
|
998 | - * At this point, it's too early to tell if we're maintenance mode or not. |
|
999 | - * In fact, this is where we give modules a chance to let core know they exist |
|
1000 | - * so they can help trigger maintenance mode if it's needed |
|
1001 | - * |
|
1002 | - * @access public |
|
1003 | - * @return void |
|
1004 | - */ |
|
1005 | - public function register_shortcodes_and_modules() |
|
1006 | - { |
|
1007 | - // allow modules to set hooks for the rest of the system |
|
1008 | - EE_Registry::instance()->modules = $this->_register_modules(); |
|
1009 | - } |
|
1010 | - |
|
1011 | - |
|
1012 | - |
|
1013 | - /** |
|
1014 | - * initialize_shortcodes_and_modules |
|
1015 | - * meaning they can start adding their hooks to get stuff done |
|
1016 | - * |
|
1017 | - * @access public |
|
1018 | - * @return void |
|
1019 | - */ |
|
1020 | - public function initialize_shortcodes_and_modules() |
|
1021 | - { |
|
1022 | - // allow modules to set hooks for the rest of the system |
|
1023 | - $this->_initialize_modules(); |
|
1024 | - } |
|
1025 | - |
|
1026 | - |
|
1027 | - |
|
1028 | - /** |
|
1029 | - * widgets_init |
|
1030 | - * |
|
1031 | - * @access private |
|
1032 | - * @return void |
|
1033 | - */ |
|
1034 | - public function widgets_init() |
|
1035 | - { |
|
1036 | - //only init widgets on admin pages when not in complete maintenance, and |
|
1037 | - //on frontend when not in any maintenance mode |
|
1038 | - if ( |
|
1039 | - ! EE_Maintenance_Mode::instance()->level() |
|
1040 | - || ( |
|
1041 | - is_admin() |
|
1042 | - && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
1043 | - ) |
|
1044 | - ) { |
|
1045 | - // grab list of installed widgets |
|
1046 | - $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
1047 | - // filter list of modules to register |
|
1048 | - $widgets_to_register = apply_filters( |
|
1049 | - 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
1050 | - $widgets_to_register |
|
1051 | - ); |
|
1052 | - if (! empty($widgets_to_register)) { |
|
1053 | - // cycle thru widget folders |
|
1054 | - foreach ($widgets_to_register as $widget_path) { |
|
1055 | - // add to list of installed widget modules |
|
1056 | - EE_Config::register_ee_widget($widget_path); |
|
1057 | - } |
|
1058 | - } |
|
1059 | - // filter list of installed modules |
|
1060 | - EE_Registry::instance()->widgets = apply_filters( |
|
1061 | - 'FHEE__EE_Config__register_widgets__installed_widgets', |
|
1062 | - EE_Registry::instance()->widgets |
|
1063 | - ); |
|
1064 | - } |
|
1065 | - } |
|
1066 | - |
|
1067 | - |
|
1068 | - |
|
1069 | - /** |
|
1070 | - * register_ee_widget - makes core aware of this widget |
|
1071 | - * |
|
1072 | - * @access public |
|
1073 | - * @param string $widget_path - full path up to and including widget folder |
|
1074 | - * @return void |
|
1075 | - */ |
|
1076 | - public static function register_ee_widget($widget_path = null) |
|
1077 | - { |
|
1078 | - do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
1079 | - $widget_ext = '.widget.php'; |
|
1080 | - // make all separators match |
|
1081 | - $widget_path = rtrim(str_replace('/\\', DS, $widget_path), DS); |
|
1082 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
1083 | - if (strpos($widget_path, $widget_ext) !== false) { |
|
1084 | - // grab and shortcode file name from directory name and break apart at dots |
|
1085 | - $file_name = explode('.', basename($widget_path)); |
|
1086 | - // take first segment from file name pieces and remove class prefix if it exists |
|
1087 | - $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
1088 | - // sanitize shortcode directory name |
|
1089 | - $widget = sanitize_key($widget); |
|
1090 | - // now we need to rebuild the shortcode path |
|
1091 | - $widget_path = explode(DS, $widget_path); |
|
1092 | - // remove last segment |
|
1093 | - array_pop($widget_path); |
|
1094 | - // glue it back together |
|
1095 | - $widget_path = implode(DS, $widget_path); |
|
1096 | - } else { |
|
1097 | - // grab and sanitize widget directory name |
|
1098 | - $widget = sanitize_key(basename($widget_path)); |
|
1099 | - } |
|
1100 | - // create classname from widget directory name |
|
1101 | - $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
1102 | - // add class prefix |
|
1103 | - $widget_class = 'EEW_' . $widget; |
|
1104 | - // does the widget exist ? |
|
1105 | - if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) { |
|
1106 | - $msg = sprintf( |
|
1107 | - __( |
|
1108 | - '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', |
|
1109 | - 'event_espresso' |
|
1110 | - ), |
|
1111 | - $widget_class, |
|
1112 | - $widget_path . DS . $widget_class . $widget_ext |
|
1113 | - ); |
|
1114 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1115 | - return; |
|
1116 | - } |
|
1117 | - // load the widget class file |
|
1118 | - require_once($widget_path . DS . $widget_class . $widget_ext); |
|
1119 | - // verify that class exists |
|
1120 | - if (! class_exists($widget_class)) { |
|
1121 | - $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
1122 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1123 | - return; |
|
1124 | - } |
|
1125 | - register_widget($widget_class); |
|
1126 | - // add to array of registered widgets |
|
1127 | - EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext; |
|
1128 | - } |
|
1129 | - |
|
1130 | - |
|
1131 | - |
|
1132 | - /** |
|
1133 | - * _register_modules |
|
1134 | - * |
|
1135 | - * @access private |
|
1136 | - * @return array |
|
1137 | - */ |
|
1138 | - private function _register_modules() |
|
1139 | - { |
|
1140 | - // grab list of installed modules |
|
1141 | - $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
1142 | - // filter list of modules to register |
|
1143 | - $modules_to_register = apply_filters( |
|
1144 | - 'FHEE__EE_Config__register_modules__modules_to_register', |
|
1145 | - $modules_to_register |
|
1146 | - ); |
|
1147 | - if (! empty($modules_to_register)) { |
|
1148 | - // loop through folders |
|
1149 | - foreach ($modules_to_register as $module_path) { |
|
1150 | - /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
|
1151 | - if ( |
|
1152 | - $module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
1153 | - && $module_path !== EE_MODULES . 'gateways' |
|
1154 | - ) { |
|
1155 | - // add to list of installed modules |
|
1156 | - EE_Config::register_module($module_path); |
|
1157 | - } |
|
1158 | - } |
|
1159 | - } |
|
1160 | - // filter list of installed modules |
|
1161 | - return apply_filters( |
|
1162 | - 'FHEE__EE_Config___register_modules__installed_modules', |
|
1163 | - EE_Registry::instance()->modules |
|
1164 | - ); |
|
1165 | - } |
|
1166 | - |
|
1167 | - |
|
1168 | - |
|
1169 | - /** |
|
1170 | - * register_module - makes core aware of this module |
|
1171 | - * |
|
1172 | - * @access public |
|
1173 | - * @param string $module_path - full path up to and including module folder |
|
1174 | - * @return bool |
|
1175 | - */ |
|
1176 | - public static function register_module($module_path = null) |
|
1177 | - { |
|
1178 | - do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
1179 | - $module_ext = '.module.php'; |
|
1180 | - // make all separators match |
|
1181 | - $module_path = str_replace(array('\\', '/'), DS, $module_path); |
|
1182 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
1183 | - if (strpos($module_path, $module_ext) !== false) { |
|
1184 | - // grab and shortcode file name from directory name and break apart at dots |
|
1185 | - $module_file = explode('.', basename($module_path)); |
|
1186 | - // now we need to rebuild the shortcode path |
|
1187 | - $module_path = explode(DS, $module_path); |
|
1188 | - // remove last segment |
|
1189 | - array_pop($module_path); |
|
1190 | - // glue it back together |
|
1191 | - $module_path = implode(DS, $module_path) . DS; |
|
1192 | - // take first segment from file name pieces and sanitize it |
|
1193 | - $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
1194 | - // ensure class prefix is added |
|
1195 | - $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
1196 | - } else { |
|
1197 | - // we need to generate the filename based off of the folder name |
|
1198 | - // grab and sanitize module name |
|
1199 | - $module = strtolower(basename($module_path)); |
|
1200 | - $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
1201 | - // like trailingslashit() |
|
1202 | - $module_path = rtrim($module_path, DS) . DS; |
|
1203 | - // create classname from module directory name |
|
1204 | - $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
1205 | - // add class prefix |
|
1206 | - $module_class = 'EED_' . $module; |
|
1207 | - } |
|
1208 | - // does the module exist ? |
|
1209 | - if (! is_readable($module_path . DS . $module_class . $module_ext)) { |
|
1210 | - $msg = sprintf( |
|
1211 | - __( |
|
1212 | - 'The requested %s module file could not be found or is not readable due to file permissions.', |
|
1213 | - 'event_espresso' |
|
1214 | - ), |
|
1215 | - $module |
|
1216 | - ); |
|
1217 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1218 | - return false; |
|
1219 | - } |
|
1220 | - // load the module class file |
|
1221 | - require_once($module_path . $module_class . $module_ext); |
|
1222 | - // verify that class exists |
|
1223 | - if (! class_exists($module_class)) { |
|
1224 | - $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
1225 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1226 | - return false; |
|
1227 | - } |
|
1228 | - // add to array of registered modules |
|
1229 | - EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
1230 | - do_action( |
|
1231 | - 'AHEE__EE_Config__register_module__complete', |
|
1232 | - $module_class, |
|
1233 | - EE_Registry::instance()->modules->{$module_class} |
|
1234 | - ); |
|
1235 | - return true; |
|
1236 | - } |
|
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()) { |
|
1254 | - // fire immediately |
|
1255 | - call_user_func(array($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 | - /** |
|
1269 | - * register_route - adds module method routes to route_map |
|
1270 | - * |
|
1271 | - * @access public |
|
1272 | - * @param string $route - "pretty" public alias for module method |
|
1273 | - * @param string $module - module name (classname without EED_ prefix) |
|
1274 | - * @param string $method_name - the actual module method to be routed to |
|
1275 | - * @param string $key - url param key indicating a route is being called |
|
1276 | - * @return bool |
|
1277 | - */ |
|
1278 | - public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') |
|
1279 | - { |
|
1280 | - do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
1281 | - $module = str_replace('EED_', '', $module); |
|
1282 | - $module_class = 'EED_' . $module; |
|
1283 | - if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
1284 | - $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
|
1285 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1286 | - return false; |
|
1287 | - } |
|
1288 | - if (empty($route)) { |
|
1289 | - $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
|
1290 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1291 | - return false; |
|
1292 | - } |
|
1293 | - if (! method_exists('EED_' . $module, $method_name)) { |
|
1294 | - $msg = sprintf( |
|
1295 | - __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
1296 | - $route |
|
1297 | - ); |
|
1298 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1299 | - return false; |
|
1300 | - } |
|
1301 | - EE_Config::$_module_route_map[$key][$route] = array('EED_' . $module, $method_name); |
|
1302 | - return true; |
|
1303 | - } |
|
1304 | - |
|
1305 | - |
|
1306 | - |
|
1307 | - /** |
|
1308 | - * get_route - get module method route |
|
1309 | - * |
|
1310 | - * @access public |
|
1311 | - * @param string $route - "pretty" public alias for module method |
|
1312 | - * @param string $key - url param key indicating a route is being called |
|
1313 | - * @return string |
|
1314 | - */ |
|
1315 | - public static function get_route($route = null, $key = 'ee') |
|
1316 | - { |
|
1317 | - do_action('AHEE__EE_Config__get_route__begin', $route); |
|
1318 | - $route = (string)apply_filters('FHEE__EE_Config__get_route', $route); |
|
1319 | - if (isset(EE_Config::$_module_route_map[$key][$route])) { |
|
1320 | - return EE_Config::$_module_route_map[$key][$route]; |
|
1321 | - } |
|
1322 | - return null; |
|
1323 | - } |
|
1324 | - |
|
1325 | - |
|
1326 | - |
|
1327 | - /** |
|
1328 | - * get_routes - get ALL module method routes |
|
1329 | - * |
|
1330 | - * @access public |
|
1331 | - * @return array |
|
1332 | - */ |
|
1333 | - public static function get_routes() |
|
1334 | - { |
|
1335 | - return EE_Config::$_module_route_map; |
|
1336 | - } |
|
1337 | - |
|
1338 | - |
|
1339 | - |
|
1340 | - /** |
|
1341 | - * register_forward - allows modules to forward request to another module for further processing |
|
1342 | - * |
|
1343 | - * @access public |
|
1344 | - * @param string $route - "pretty" public alias for module method |
|
1345 | - * @param integer $status - integer value corresponding to status constant strings set in module parent |
|
1346 | - * class, allows different forwards to be served based on status |
|
1347 | - * @param array|string $forward - function name or array( class, method ) |
|
1348 | - * @param string $key - url param key indicating a route is being called |
|
1349 | - * @return bool |
|
1350 | - */ |
|
1351 | - public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
|
1352 | - { |
|
1353 | - do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
1354 | - if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
1355 | - $msg = sprintf( |
|
1356 | - __('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
1357 | - $route |
|
1358 | - ); |
|
1359 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1360 | - return false; |
|
1361 | - } |
|
1362 | - if (empty($forward)) { |
|
1363 | - $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
1364 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1365 | - return false; |
|
1366 | - } |
|
1367 | - if (is_array($forward)) { |
|
1368 | - if (! isset($forward[1])) { |
|
1369 | - $msg = sprintf( |
|
1370 | - __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
1371 | - $route |
|
1372 | - ); |
|
1373 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1374 | - return false; |
|
1375 | - } |
|
1376 | - if (! method_exists($forward[0], $forward[1])) { |
|
1377 | - $msg = sprintf( |
|
1378 | - __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
1379 | - $forward[1], |
|
1380 | - $route |
|
1381 | - ); |
|
1382 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1383 | - return false; |
|
1384 | - } |
|
1385 | - } else if (! function_exists($forward)) { |
|
1386 | - $msg = sprintf( |
|
1387 | - __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
1388 | - $forward, |
|
1389 | - $route |
|
1390 | - ); |
|
1391 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1392 | - return false; |
|
1393 | - } |
|
1394 | - EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward; |
|
1395 | - return true; |
|
1396 | - } |
|
1397 | - |
|
1398 | - |
|
1399 | - |
|
1400 | - /** |
|
1401 | - * get_forward - get forwarding route |
|
1402 | - * |
|
1403 | - * @access public |
|
1404 | - * @param string $route - "pretty" public alias for module method |
|
1405 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
1406 | - * allows different forwards to be served based on status |
|
1407 | - * @param string $key - url param key indicating a route is being called |
|
1408 | - * @return string |
|
1409 | - */ |
|
1410 | - public static function get_forward($route = null, $status = 0, $key = 'ee') |
|
1411 | - { |
|
1412 | - do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
1413 | - if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) { |
|
1414 | - return apply_filters( |
|
1415 | - 'FHEE__EE_Config__get_forward', |
|
1416 | - EE_Config::$_module_forward_map[$key][$route][$status], |
|
1417 | - $route, |
|
1418 | - $status |
|
1419 | - ); |
|
1420 | - } |
|
1421 | - return null; |
|
1422 | - } |
|
1423 | - |
|
1424 | - |
|
1425 | - |
|
1426 | - /** |
|
1427 | - * register_forward - allows modules to specify different view templates for different method routes and status |
|
1428 | - * results |
|
1429 | - * |
|
1430 | - * @access public |
|
1431 | - * @param string $route - "pretty" public alias for module method |
|
1432 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
1433 | - * allows different views to be served based on status |
|
1434 | - * @param string $view |
|
1435 | - * @param string $key - url param key indicating a route is being called |
|
1436 | - * @return bool |
|
1437 | - */ |
|
1438 | - public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
|
1439 | - { |
|
1440 | - do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
1441 | - if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
1442 | - $msg = sprintf( |
|
1443 | - __('The module route %s for this view has not been registered.', 'event_espresso'), |
|
1444 | - $route |
|
1445 | - ); |
|
1446 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1447 | - return false; |
|
1448 | - } |
|
1449 | - if (! is_readable($view)) { |
|
1450 | - $msg = sprintf( |
|
1451 | - __( |
|
1452 | - 'The %s view file could not be found or is not readable due to file permissions.', |
|
1453 | - 'event_espresso' |
|
1454 | - ), |
|
1455 | - $view |
|
1456 | - ); |
|
1457 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1458 | - return false; |
|
1459 | - } |
|
1460 | - EE_Config::$_module_view_map[$key][$route][absint($status)] = $view; |
|
1461 | - return true; |
|
1462 | - } |
|
1463 | - |
|
1464 | - |
|
1465 | - |
|
1466 | - /** |
|
1467 | - * get_view - get view for route and status |
|
1468 | - * |
|
1469 | - * @access public |
|
1470 | - * @param string $route - "pretty" public alias for module method |
|
1471 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
1472 | - * allows different views to be served based on status |
|
1473 | - * @param string $key - url param key indicating a route is being called |
|
1474 | - * @return string |
|
1475 | - */ |
|
1476 | - public static function get_view($route = null, $status = 0, $key = 'ee') |
|
1477 | - { |
|
1478 | - do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
1479 | - if (isset(EE_Config::$_module_view_map[$key][$route][$status])) { |
|
1480 | - return apply_filters( |
|
1481 | - 'FHEE__EE_Config__get_view', |
|
1482 | - EE_Config::$_module_view_map[$key][$route][$status], |
|
1483 | - $route, |
|
1484 | - $status |
|
1485 | - ); |
|
1486 | - } |
|
1487 | - return null; |
|
1488 | - } |
|
1489 | - |
|
1490 | - |
|
1491 | - |
|
1492 | - public function update_addon_option_names() |
|
1493 | - { |
|
1494 | - update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
1495 | - } |
|
1496 | - |
|
1497 | - |
|
1498 | - |
|
1499 | - public function shutdown() |
|
1500 | - { |
|
1501 | - $this->update_addon_option_names(); |
|
1502 | - } |
|
1503 | - |
|
1504 | - |
|
1505 | - |
|
1506 | - /** |
|
1507 | - * @return LegacyShortcodesManager |
|
1508 | - */ |
|
1509 | - public static function getLegacyShortcodesManager() |
|
1510 | - { |
|
1511 | - |
|
1512 | - if ( ! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
1513 | - EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager( |
|
1514 | - EE_Registry::instance() |
|
1515 | - ); |
|
1516 | - } |
|
1517 | - return EE_Config::instance()->legacy_shortcodes_manager; |
|
1518 | - } |
|
1519 | - |
|
1520 | - |
|
1521 | - |
|
1522 | - /** |
|
1523 | - * register_shortcode - makes core aware of this shortcode |
|
1524 | - * |
|
1525 | - * @deprecated 4.9.26 |
|
1526 | - * @param string $shortcode_path - full path up to and including shortcode folder |
|
1527 | - * @return bool |
|
1528 | - */ |
|
1529 | - public static function register_shortcode($shortcode_path = null) |
|
1530 | - { |
|
1531 | - EE_Error::doing_it_wrong( |
|
1532 | - __METHOD__, |
|
1533 | - __( |
|
1534 | - '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.', |
|
1535 | - 'event_espresso' |
|
1536 | - ), |
|
1537 | - '4.9.26' |
|
1538 | - ); |
|
1539 | - return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path); |
|
1540 | - } |
|
19 | + const OPTION_NAME = 'ee_config'; |
|
20 | + |
|
21 | + const LOG_NAME = 'ee_config_log'; |
|
22 | + |
|
23 | + const LOG_LENGTH = 100; |
|
24 | + |
|
25 | + const ADDON_OPTION_NAMES = 'ee_config_option_names'; |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * instance of the EE_Config object |
|
30 | + * |
|
31 | + * @var EE_Config $_instance |
|
32 | + * @access private |
|
33 | + */ |
|
34 | + private static $_instance; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var boolean $_logging_enabled |
|
38 | + */ |
|
39 | + private static $_logging_enabled = false; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
43 | + */ |
|
44 | + private $legacy_shortcodes_manager; |
|
45 | + |
|
46 | + /** |
|
47 | + * An StdClass whose property names are addon slugs, |
|
48 | + * and values are their config classes |
|
49 | + * |
|
50 | + * @var StdClass |
|
51 | + */ |
|
52 | + public $addons; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var EE_Admin_Config |
|
56 | + */ |
|
57 | + public $admin; |
|
58 | + |
|
59 | + /** |
|
60 | + * @var EE_Core_Config |
|
61 | + */ |
|
62 | + public $core; |
|
63 | + |
|
64 | + /** |
|
65 | + * @var EE_Currency_Config |
|
66 | + */ |
|
67 | + public $currency; |
|
68 | + |
|
69 | + /** |
|
70 | + * @var EE_Organization_Config |
|
71 | + */ |
|
72 | + public $organization; |
|
73 | + |
|
74 | + /** |
|
75 | + * @var EE_Registration_Config |
|
76 | + */ |
|
77 | + public $registration; |
|
78 | + |
|
79 | + /** |
|
80 | + * @var EE_Template_Config |
|
81 | + */ |
|
82 | + public $template_settings; |
|
83 | + |
|
84 | + /** |
|
85 | + * Holds EE environment values. |
|
86 | + * |
|
87 | + * @var EE_Environment_Config |
|
88 | + */ |
|
89 | + public $environment; |
|
90 | + |
|
91 | + /** |
|
92 | + * settings pertaining to Google maps |
|
93 | + * |
|
94 | + * @var EE_Map_Config |
|
95 | + */ |
|
96 | + public $map_settings; |
|
97 | + |
|
98 | + /** |
|
99 | + * settings pertaining to Taxes |
|
100 | + * |
|
101 | + * @var EE_Tax_Config |
|
102 | + */ |
|
103 | + public $tax_settings; |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * Settings pertaining to global messages settings. |
|
108 | + * |
|
109 | + * @var EE_Messages_Config |
|
110 | + */ |
|
111 | + public $messages; |
|
112 | + |
|
113 | + /** |
|
114 | + * @deprecated |
|
115 | + * @var EE_Gateway_Config |
|
116 | + */ |
|
117 | + public $gateway; |
|
118 | + |
|
119 | + /** |
|
120 | + * @var array $_addon_option_names |
|
121 | + * @access private |
|
122 | + */ |
|
123 | + private $_addon_option_names = array(); |
|
124 | + |
|
125 | + /** |
|
126 | + * @var array $_module_route_map |
|
127 | + * @access private |
|
128 | + */ |
|
129 | + private static $_module_route_map = array(); |
|
130 | + |
|
131 | + /** |
|
132 | + * @var array $_module_forward_map |
|
133 | + * @access private |
|
134 | + */ |
|
135 | + private static $_module_forward_map = array(); |
|
136 | + |
|
137 | + /** |
|
138 | + * @var array $_module_view_map |
|
139 | + * @access private |
|
140 | + */ |
|
141 | + private static $_module_view_map = array(); |
|
142 | + |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * @singleton method used to instantiate class object |
|
147 | + * @access public |
|
148 | + * @return EE_Config instance |
|
149 | + */ |
|
150 | + public static function instance() |
|
151 | + { |
|
152 | + // check if class object is instantiated, and instantiated properly |
|
153 | + if (! self::$_instance instanceof EE_Config) { |
|
154 | + self::$_instance = new self(); |
|
155 | + } |
|
156 | + return self::$_instance; |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * Resets the config |
|
163 | + * |
|
164 | + * @param bool $hard_reset if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE |
|
165 | + * (default) leaves the database alone, and merely resets the EE_Config object to |
|
166 | + * reflect its state in the database |
|
167 | + * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave |
|
168 | + * $_instance as NULL. Useful in case you want to forget about the old instance on |
|
169 | + * EE_Config, but might not be ready to instantiate EE_Config currently (eg if the |
|
170 | + * site was put into maintenance mode) |
|
171 | + * @return EE_Config |
|
172 | + */ |
|
173 | + public static function reset($hard_reset = false, $reinstantiate = true) |
|
174 | + { |
|
175 | + if (self::$_instance instanceof EE_Config) { |
|
176 | + if ($hard_reset) { |
|
177 | + self::$_instance->legacy_shortcodes_manager = null; |
|
178 | + self::$_instance->_addon_option_names = array(); |
|
179 | + self::$_instance->_initialize_config(); |
|
180 | + self::$_instance->update_espresso_config(); |
|
181 | + } |
|
182 | + self::$_instance->update_addon_option_names(); |
|
183 | + } |
|
184 | + self::$_instance = null; |
|
185 | + //we don't need to reset the static properties imo because those should |
|
186 | + //only change when a module is added or removed. Currently we don't |
|
187 | + //support removing a module during a request when it previously existed |
|
188 | + if ($reinstantiate) { |
|
189 | + return self::instance(); |
|
190 | + } else { |
|
191 | + return null; |
|
192 | + } |
|
193 | + } |
|
194 | + |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * class constructor |
|
199 | + * |
|
200 | + * @access private |
|
201 | + */ |
|
202 | + private function __construct() |
|
203 | + { |
|
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 | + array($this, 'register_shortcodes_and_modules'), |
|
216 | + 999 |
|
217 | + ); |
|
218 | + // initialize shortcodes and modules |
|
219 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules')); |
|
220 | + // register widgets |
|
221 | + add_action('widgets_init', array($this, 'widgets_init'), 10); |
|
222 | + // shutdown |
|
223 | + add_action('shutdown', array($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 | + /** |
|
233 | + * @return boolean |
|
234 | + */ |
|
235 | + public static function logging_enabled() |
|
236 | + { |
|
237 | + return self::$_logging_enabled; |
|
238 | + } |
|
239 | + |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * use to get the current theme if needed from static context |
|
244 | + * |
|
245 | + * @return string current theme set. |
|
246 | + */ |
|
247 | + public static function get_current_theme() |
|
248 | + { |
|
249 | + return isset(self::$_instance->template_settings->current_espresso_theme) |
|
250 | + ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014'; |
|
251 | + } |
|
252 | + |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * _initialize_config |
|
257 | + * |
|
258 | + * @access private |
|
259 | + * @return void |
|
260 | + */ |
|
261 | + private function _initialize_config() |
|
262 | + { |
|
263 | + EE_Config::trim_log(); |
|
264 | + //set defaults |
|
265 | + $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array()); |
|
266 | + $this->addons = new stdClass(); |
|
267 | + // set _module_route_map |
|
268 | + EE_Config::$_module_route_map = array(); |
|
269 | + // set _module_forward_map |
|
270 | + EE_Config::$_module_forward_map = array(); |
|
271 | + // set _module_view_map |
|
272 | + EE_Config::$_module_view_map = array(); |
|
273 | + } |
|
274 | + |
|
275 | + |
|
276 | + |
|
277 | + /** |
|
278 | + * load core plugin configuration |
|
279 | + * |
|
280 | + * @access private |
|
281 | + * @return void |
|
282 | + */ |
|
283 | + private function _load_core_config() |
|
284 | + { |
|
285 | + // load_core_config__start hook |
|
286 | + do_action('AHEE__EE_Config___load_core_config__start', $this); |
|
287 | + $espresso_config = $this->get_espresso_config(); |
|
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 | + /** |
|
317 | + * _verify_config |
|
318 | + * |
|
319 | + * @access protected |
|
320 | + * @return void |
|
321 | + */ |
|
322 | + protected function _verify_config() |
|
323 | + { |
|
324 | + $this->core = $this->core instanceof EE_Core_Config |
|
325 | + ? $this->core |
|
326 | + : new EE_Core_Config(); |
|
327 | + $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core); |
|
328 | + $this->organization = $this->organization instanceof EE_Organization_Config |
|
329 | + ? $this->organization |
|
330 | + : new EE_Organization_Config(); |
|
331 | + $this->organization = apply_filters( |
|
332 | + 'FHEE__EE_Config___initialize_config__organization', |
|
333 | + $this->organization |
|
334 | + ); |
|
335 | + $this->currency = $this->currency instanceof EE_Currency_Config |
|
336 | + ? $this->currency |
|
337 | + : new EE_Currency_Config(); |
|
338 | + $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency); |
|
339 | + $this->registration = $this->registration instanceof EE_Registration_Config |
|
340 | + ? $this->registration |
|
341 | + : new EE_Registration_Config(); |
|
342 | + $this->registration = apply_filters( |
|
343 | + 'FHEE__EE_Config___initialize_config__registration', |
|
344 | + $this->registration |
|
345 | + ); |
|
346 | + $this->admin = $this->admin instanceof EE_Admin_Config |
|
347 | + ? $this->admin |
|
348 | + : new EE_Admin_Config(); |
|
349 | + $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin); |
|
350 | + $this->template_settings = $this->template_settings instanceof EE_Template_Config |
|
351 | + ? $this->template_settings |
|
352 | + : new EE_Template_Config(); |
|
353 | + $this->template_settings = apply_filters( |
|
354 | + 'FHEE__EE_Config___initialize_config__template_settings', |
|
355 | + $this->template_settings |
|
356 | + ); |
|
357 | + $this->map_settings = $this->map_settings instanceof EE_Map_Config |
|
358 | + ? $this->map_settings |
|
359 | + : new EE_Map_Config(); |
|
360 | + $this->map_settings = apply_filters('FHEE__EE_Config___initialize_config__map_settings', |
|
361 | + $this->map_settings); |
|
362 | + $this->environment = $this->environment instanceof EE_Environment_Config |
|
363 | + ? $this->environment |
|
364 | + : new EE_Environment_Config(); |
|
365 | + $this->environment = apply_filters('FHEE__EE_Config___initialize_config__environment', |
|
366 | + $this->environment); |
|
367 | + $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config |
|
368 | + ? $this->tax_settings |
|
369 | + : new EE_Tax_Config(); |
|
370 | + $this->tax_settings = apply_filters('FHEE__EE_Config___initialize_config__tax_settings', |
|
371 | + $this->tax_settings); |
|
372 | + $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages); |
|
373 | + $this->messages = $this->messages instanceof EE_Messages_Config |
|
374 | + ? $this->messages |
|
375 | + : new EE_Messages_Config(); |
|
376 | + $this->gateway = $this->gateway instanceof EE_Gateway_Config |
|
377 | + ? $this->gateway |
|
378 | + : new EE_Gateway_Config(); |
|
379 | + $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway); |
|
380 | + $this->legacy_shortcodes_manager = null; |
|
381 | + } |
|
382 | + |
|
383 | + |
|
384 | + /** |
|
385 | + * get_espresso_config |
|
386 | + * |
|
387 | + * @access public |
|
388 | + * @return array of espresso config stuff |
|
389 | + */ |
|
390 | + public function get_espresso_config() |
|
391 | + { |
|
392 | + // grab espresso configuration |
|
393 | + return apply_filters( |
|
394 | + 'FHEE__EE_Config__get_espresso_config__CFG', |
|
395 | + get_option(EE_Config::OPTION_NAME, array()) |
|
396 | + ); |
|
397 | + } |
|
398 | + |
|
399 | + |
|
400 | + |
|
401 | + /** |
|
402 | + * double_check_config_comparison |
|
403 | + * |
|
404 | + * @access public |
|
405 | + * @param string $option |
|
406 | + * @param $old_value |
|
407 | + * @param $value |
|
408 | + */ |
|
409 | + public function double_check_config_comparison($option = '', $old_value, $value) |
|
410 | + { |
|
411 | + // make sure we're checking the ee config |
|
412 | + if ($option === EE_Config::OPTION_NAME) { |
|
413 | + // run a loose comparison of the old value against the new value for type and properties, |
|
414 | + // but NOT exact instance like WP update_option does (ie: NOT type safe comparison) |
|
415 | + if ($value != $old_value) { |
|
416 | + // if they are NOT the same, then remove the hook, |
|
417 | + // which means the subsequent update results will be based solely on the update query results |
|
418 | + // the reason we do this is because, as stated above, |
|
419 | + // WP update_option performs an exact instance comparison (===) on any update values passed to it |
|
420 | + // this happens PRIOR to serialization and any subsequent update. |
|
421 | + // If values are found to match their previous old value, |
|
422 | + // then WP bails before performing any update. |
|
423 | + // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version |
|
424 | + // it just pulled from the db, with the one being passed to it (which will not match). |
|
425 | + // HOWEVER, once the object is serialized and passed off to MySQL to update, |
|
426 | + // MySQL MAY ALSO NOT perform the update because |
|
427 | + // the string it sees in the db looks the same as the new one it has been passed!!! |
|
428 | + // This results in the query returning an "affected rows" value of ZERO, |
|
429 | + // which gets returned immediately by WP update_option and looks like an error. |
|
430 | + remove_action('update_option', array($this, 'check_config_updated')); |
|
431 | + } |
|
432 | + } |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + |
|
437 | + /** |
|
438 | + * update_espresso_config |
|
439 | + * |
|
440 | + * @access public |
|
441 | + */ |
|
442 | + protected function _reset_espresso_addon_config() |
|
443 | + { |
|
444 | + $this->_addon_option_names = array(); |
|
445 | + foreach ($this->addons as $addon_name => $addon_config_obj) { |
|
446 | + $addon_config_obj = maybe_unserialize($addon_config_obj); |
|
447 | + $config_class = get_class($addon_config_obj); |
|
448 | + if ($addon_config_obj instanceof $config_class && ! $addon_config_obj instanceof __PHP_Incomplete_Class) { |
|
449 | + $this->update_config('addons', $addon_name, $addon_config_obj, false); |
|
450 | + } |
|
451 | + $this->addons->{$addon_name} = null; |
|
452 | + } |
|
453 | + } |
|
454 | + |
|
455 | + |
|
456 | + |
|
457 | + /** |
|
458 | + * update_espresso_config |
|
459 | + * |
|
460 | + * @access public |
|
461 | + * @param bool $add_success |
|
462 | + * @param bool $add_error |
|
463 | + * @return bool |
|
464 | + */ |
|
465 | + public function update_espresso_config($add_success = false, $add_error = true) |
|
466 | + { |
|
467 | + // don't allow config updates during WP heartbeats |
|
468 | + if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
469 | + return false; |
|
470 | + } |
|
471 | + // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197 |
|
472 | + //$clone = clone( self::$_instance ); |
|
473 | + //self::$_instance = NULL; |
|
474 | + do_action('AHEE__EE_Config__update_espresso_config__begin', $this); |
|
475 | + $this->_reset_espresso_addon_config(); |
|
476 | + // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional |
|
477 | + // but BEFORE the actual update occurs |
|
478 | + add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3); |
|
479 | + // don't want to persist legacy_shortcodes_manager, but don't want to lose it either |
|
480 | + $legacy_shortcodes_manager = $this->legacy_shortcodes_manager; |
|
481 | + $this->legacy_shortcodes_manager = null; |
|
482 | + // now update "ee_config" |
|
483 | + $saved = update_option(EE_Config::OPTION_NAME, $this); |
|
484 | + $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
485 | + EE_Config::log(EE_Config::OPTION_NAME); |
|
486 | + // if not saved... check if the hook we just added still exists; |
|
487 | + // if it does, it means one of two things: |
|
488 | + // that update_option bailed at the ( $value === $old_value ) conditional, |
|
489 | + // or... |
|
490 | + // the db update query returned 0 rows affected |
|
491 | + // (probably because the data value was the same from it's perspective) |
|
492 | + // so the existence of the hook means that a negative result from update_option is NOT an error, |
|
493 | + // but just means no update occurred, so don't display an error to the user. |
|
494 | + // BUT... if update_option returns FALSE, AND the hook is missing, |
|
495 | + // then it means that something truly went wrong |
|
496 | + $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved; |
|
497 | + // remove our action since we don't want it in the system anymore |
|
498 | + remove_action('update_option', array($this, 'double_check_config_comparison'), 1); |
|
499 | + do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved); |
|
500 | + //self::$_instance = $clone; |
|
501 | + //unset( $clone ); |
|
502 | + // if config remains the same or was updated successfully |
|
503 | + if ($saved) { |
|
504 | + if ($add_success) { |
|
505 | + EE_Error::add_success( |
|
506 | + __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'), |
|
507 | + __FILE__, |
|
508 | + __FUNCTION__, |
|
509 | + __LINE__ |
|
510 | + ); |
|
511 | + } |
|
512 | + return true; |
|
513 | + } else { |
|
514 | + if ($add_error) { |
|
515 | + EE_Error::add_error( |
|
516 | + __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'), |
|
517 | + __FILE__, |
|
518 | + __FUNCTION__, |
|
519 | + __LINE__ |
|
520 | + ); |
|
521 | + } |
|
522 | + return false; |
|
523 | + } |
|
524 | + } |
|
525 | + |
|
526 | + |
|
527 | + |
|
528 | + /** |
|
529 | + * _verify_config_params |
|
530 | + * |
|
531 | + * @access private |
|
532 | + * @param string $section |
|
533 | + * @param string $name |
|
534 | + * @param string $config_class |
|
535 | + * @param EE_Config_Base $config_obj |
|
536 | + * @param array $tests_to_run |
|
537 | + * @param bool $display_errors |
|
538 | + * @return bool TRUE on success, FALSE on fail |
|
539 | + */ |
|
540 | + private function _verify_config_params( |
|
541 | + $section = '', |
|
542 | + $name = '', |
|
543 | + $config_class = '', |
|
544 | + $config_obj = null, |
|
545 | + $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8), |
|
546 | + $display_errors = true |
|
547 | + ) { |
|
548 | + try { |
|
549 | + foreach ($tests_to_run as $test) { |
|
550 | + switch ($test) { |
|
551 | + // TEST #1 : check that section was set |
|
552 | + case 1 : |
|
553 | + if (empty($section)) { |
|
554 | + if ($display_errors) { |
|
555 | + throw new EE_Error( |
|
556 | + sprintf( |
|
557 | + __( |
|
558 | + 'No configuration section has been provided while attempting to save "%s".', |
|
559 | + 'event_espresso' |
|
560 | + ), |
|
561 | + $config_class |
|
562 | + ) |
|
563 | + ); |
|
564 | + } |
|
565 | + return false; |
|
566 | + } |
|
567 | + break; |
|
568 | + // TEST #2 : check that settings section exists |
|
569 | + case 2 : |
|
570 | + if (! isset($this->{$section})) { |
|
571 | + if ($display_errors) { |
|
572 | + throw new EE_Error( |
|
573 | + sprintf( |
|
574 | + __('The "%s" configuration section does not exist.', 'event_espresso'), |
|
575 | + $section |
|
576 | + ) |
|
577 | + ); |
|
578 | + } |
|
579 | + return false; |
|
580 | + } |
|
581 | + break; |
|
582 | + // TEST #3 : check that section is the proper format |
|
583 | + case 3 : |
|
584 | + if ( |
|
585 | + ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
586 | + ) { |
|
587 | + if ($display_errors) { |
|
588 | + throw new EE_Error( |
|
589 | + sprintf( |
|
590 | + __( |
|
591 | + 'The "%s" configuration settings have not been formatted correctly.', |
|
592 | + 'event_espresso' |
|
593 | + ), |
|
594 | + $section |
|
595 | + ) |
|
596 | + ); |
|
597 | + } |
|
598 | + return false; |
|
599 | + } |
|
600 | + break; |
|
601 | + // TEST #4 : check that config section name has been set |
|
602 | + case 4 : |
|
603 | + if (empty($name)) { |
|
604 | + if ($display_errors) { |
|
605 | + throw new EE_Error( |
|
606 | + __( |
|
607 | + 'No name has been provided for the specific configuration section.', |
|
608 | + 'event_espresso' |
|
609 | + ) |
|
610 | + ); |
|
611 | + } |
|
612 | + return false; |
|
613 | + } |
|
614 | + break; |
|
615 | + // TEST #5 : check that a config class name has been set |
|
616 | + case 5 : |
|
617 | + if (empty($config_class)) { |
|
618 | + if ($display_errors) { |
|
619 | + throw new EE_Error( |
|
620 | + __( |
|
621 | + 'No class name has been provided for the specific configuration section.', |
|
622 | + 'event_espresso' |
|
623 | + ) |
|
624 | + ); |
|
625 | + } |
|
626 | + return false; |
|
627 | + } |
|
628 | + break; |
|
629 | + // TEST #6 : verify config class is accessible |
|
630 | + case 6 : |
|
631 | + if (! class_exists($config_class)) { |
|
632 | + if ($display_errors) { |
|
633 | + throw new EE_Error( |
|
634 | + sprintf( |
|
635 | + __( |
|
636 | + 'The "%s" class does not exist. Please ensure that an autoloader has been set for it.', |
|
637 | + 'event_espresso' |
|
638 | + ), |
|
639 | + $config_class |
|
640 | + ) |
|
641 | + ); |
|
642 | + } |
|
643 | + return false; |
|
644 | + } |
|
645 | + break; |
|
646 | + // TEST #7 : check that config has even been set |
|
647 | + case 7 : |
|
648 | + if (! isset($this->{$section}->{$name})) { |
|
649 | + if ($display_errors) { |
|
650 | + throw new EE_Error( |
|
651 | + sprintf( |
|
652 | + __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
653 | + $section, |
|
654 | + $name |
|
655 | + ) |
|
656 | + ); |
|
657 | + } |
|
658 | + return false; |
|
659 | + } else { |
|
660 | + // and make sure it's not serialized |
|
661 | + $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name}); |
|
662 | + } |
|
663 | + break; |
|
664 | + // TEST #8 : check that config is the requested type |
|
665 | + case 8 : |
|
666 | + if (! $this->{$section}->{$name} instanceof $config_class) { |
|
667 | + if ($display_errors) { |
|
668 | + throw new EE_Error( |
|
669 | + sprintf( |
|
670 | + __( |
|
671 | + 'The configuration for "%1$s->%2$s" is not of the "%3$s" class.', |
|
672 | + 'event_espresso' |
|
673 | + ), |
|
674 | + $section, |
|
675 | + $name, |
|
676 | + $config_class |
|
677 | + ) |
|
678 | + ); |
|
679 | + } |
|
680 | + return false; |
|
681 | + } |
|
682 | + break; |
|
683 | + // TEST #9 : verify config object |
|
684 | + case 9 : |
|
685 | + if (! $config_obj instanceof EE_Config_Base) { |
|
686 | + if ($display_errors) { |
|
687 | + throw new EE_Error( |
|
688 | + sprintf( |
|
689 | + __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
690 | + print_r($config_obj, true) |
|
691 | + ) |
|
692 | + ); |
|
693 | + } |
|
694 | + return false; |
|
695 | + } |
|
696 | + break; |
|
697 | + } |
|
698 | + } |
|
699 | + } catch (EE_Error $e) { |
|
700 | + $e->get_error(); |
|
701 | + } |
|
702 | + // you have successfully run the gauntlet |
|
703 | + return true; |
|
704 | + } |
|
705 | + |
|
706 | + |
|
707 | + |
|
708 | + /** |
|
709 | + * _generate_config_option_name |
|
710 | + * |
|
711 | + * @access protected |
|
712 | + * @param string $section |
|
713 | + * @param string $name |
|
714 | + * @return string |
|
715 | + */ |
|
716 | + private function _generate_config_option_name($section = '', $name = '') |
|
717 | + { |
|
718 | + return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
719 | + } |
|
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 | + /** |
|
742 | + * set_config |
|
743 | + * |
|
744 | + * @access protected |
|
745 | + * @param string $section |
|
746 | + * @param string $name |
|
747 | + * @param string $config_class |
|
748 | + * @param EE_Config_Base $config_obj |
|
749 | + * @return EE_Config_Base |
|
750 | + */ |
|
751 | + public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null) |
|
752 | + { |
|
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 | + update_option($config_option_name, $config_obj); |
|
772 | + $this->{$section}->{$name} = $config_obj; |
|
773 | + return $this->{$section}->{$name}; |
|
774 | + } else { |
|
775 | + // create a wp-option for this config |
|
776 | + if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
777 | + $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
778 | + return $this->{$section}->{$name}; |
|
779 | + } else { |
|
780 | + EE_Error::add_error( |
|
781 | + sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
782 | + __FILE__, |
|
783 | + __FUNCTION__, |
|
784 | + __LINE__ |
|
785 | + ); |
|
786 | + return null; |
|
787 | + } |
|
788 | + } |
|
789 | + } |
|
790 | + |
|
791 | + |
|
792 | + |
|
793 | + /** |
|
794 | + * update_config |
|
795 | + * Important: the config object must ALREADY be set, otherwise this will produce an error. |
|
796 | + * |
|
797 | + * @access public |
|
798 | + * @param string $section |
|
799 | + * @param string $name |
|
800 | + * @param EE_Config_Base|string $config_obj |
|
801 | + * @param bool $throw_errors |
|
802 | + * @return bool |
|
803 | + */ |
|
804 | + public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) |
|
805 | + { |
|
806 | + // don't allow config updates during WP heartbeats |
|
807 | + if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
808 | + return false; |
|
809 | + } |
|
810 | + $config_obj = maybe_unserialize($config_obj); |
|
811 | + // get class name of the incoming object |
|
812 | + $config_class = get_class($config_obj); |
|
813 | + // run tests 1-5 and 9 to verify config |
|
814 | + if (! $this->_verify_config_params( |
|
815 | + $section, |
|
816 | + $name, |
|
817 | + $config_class, |
|
818 | + $config_obj, |
|
819 | + array(1, 2, 3, 4, 7, 9) |
|
820 | + ) |
|
821 | + ) { |
|
822 | + return false; |
|
823 | + } |
|
824 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
825 | + // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
|
826 | + if (! isset($this->_addon_option_names[$config_option_name])) { |
|
827 | + // save new config to db |
|
828 | + if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
829 | + return true; |
|
830 | + } |
|
831 | + } else { |
|
832 | + // first check if the record already exists |
|
833 | + $existing_config = get_option($config_option_name); |
|
834 | + $config_obj = serialize($config_obj); |
|
835 | + // just return if db record is already up to date (NOT type safe comparison) |
|
836 | + if ($existing_config == $config_obj) { |
|
837 | + $this->{$section}->{$name} = $config_obj; |
|
838 | + return true; |
|
839 | + } else if (update_option($config_option_name, $config_obj)) { |
|
840 | + EE_Config::log($config_option_name); |
|
841 | + // update wp-option for this config class |
|
842 | + $this->{$section}->{$name} = $config_obj; |
|
843 | + return true; |
|
844 | + } elseif ($throw_errors) { |
|
845 | + EE_Error::add_error( |
|
846 | + sprintf( |
|
847 | + __( |
|
848 | + 'The "%1$s" object stored at"%2$s" was not successfully updated in the database.', |
|
849 | + 'event_espresso' |
|
850 | + ), |
|
851 | + $config_class, |
|
852 | + 'EE_Config->' . $section . '->' . $name |
|
853 | + ), |
|
854 | + __FILE__, |
|
855 | + __FUNCTION__, |
|
856 | + __LINE__ |
|
857 | + ); |
|
858 | + } |
|
859 | + } |
|
860 | + return false; |
|
861 | + } |
|
862 | + |
|
863 | + |
|
864 | + |
|
865 | + /** |
|
866 | + * get_config |
|
867 | + * |
|
868 | + * @access public |
|
869 | + * @param string $section |
|
870 | + * @param string $name |
|
871 | + * @param string $config_class |
|
872 | + * @return mixed EE_Config_Base | NULL |
|
873 | + */ |
|
874 | + public function get_config($section = '', $name = '', $config_class = '') |
|
875 | + { |
|
876 | + // ensure config class is set to something |
|
877 | + $config_class = $this->_set_config_class($config_class, $name); |
|
878 | + // run tests 1-4, 6 and 7 to verify that all params have been set |
|
879 | + if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
880 | + return null; |
|
881 | + } |
|
882 | + // now test if the requested config object exists, but suppress errors |
|
883 | + if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
884 | + // config already exists, so pass it back |
|
885 | + return $this->{$section}->{$name}; |
|
886 | + } |
|
887 | + // load config option from db if it exists |
|
888 | + $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
889 | + // verify the newly retrieved config object, but suppress errors |
|
890 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
891 | + // config is good, so set it and pass it back |
|
892 | + $this->{$section}->{$name} = $config_obj; |
|
893 | + return $this->{$section}->{$name}; |
|
894 | + } |
|
895 | + // oops! $config_obj is not already set and does not exist in the db, so create a new one |
|
896 | + $config_obj = $this->set_config($section, $name, $config_class); |
|
897 | + // verify the newly created config object |
|
898 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
899 | + return $this->{$section}->{$name}; |
|
900 | + } else { |
|
901 | + EE_Error::add_error( |
|
902 | + sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
903 | + __FILE__, |
|
904 | + __FUNCTION__, |
|
905 | + __LINE__ |
|
906 | + ); |
|
907 | + } |
|
908 | + return null; |
|
909 | + } |
|
910 | + |
|
911 | + |
|
912 | + |
|
913 | + /** |
|
914 | + * get_config_option |
|
915 | + * |
|
916 | + * @access public |
|
917 | + * @param string $config_option_name |
|
918 | + * @return mixed EE_Config_Base | FALSE |
|
919 | + */ |
|
920 | + public function get_config_option($config_option_name = '') |
|
921 | + { |
|
922 | + // retrieve the wp-option for this config class. |
|
923 | + $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
924 | + if (empty($config_option)) { |
|
925 | + EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
926 | + } |
|
927 | + return $config_option; |
|
928 | + } |
|
929 | + |
|
930 | + |
|
931 | + |
|
932 | + /** |
|
933 | + * log |
|
934 | + * |
|
935 | + * @param string $config_option_name |
|
936 | + */ |
|
937 | + public static function log($config_option_name = '') |
|
938 | + { |
|
939 | + if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
940 | + $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
941 | + //copy incoming $_REQUEST and sanitize it so we can save it |
|
942 | + $_request = $_REQUEST; |
|
943 | + array_walk_recursive($_request, 'sanitize_text_field'); |
|
944 | + $config_log[(string)microtime(true)] = array( |
|
945 | + 'config_name' => $config_option_name, |
|
946 | + 'request' => $_request, |
|
947 | + ); |
|
948 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
949 | + } |
|
950 | + } |
|
951 | + |
|
952 | + |
|
953 | + |
|
954 | + /** |
|
955 | + * trim_log |
|
956 | + * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
|
957 | + */ |
|
958 | + public static function trim_log() |
|
959 | + { |
|
960 | + if (! EE_Config::logging_enabled()) { |
|
961 | + return; |
|
962 | + } |
|
963 | + $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
964 | + $log_length = count($config_log); |
|
965 | + if ($log_length > EE_Config::LOG_LENGTH) { |
|
966 | + ksort($config_log); |
|
967 | + $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
968 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
969 | + } |
|
970 | + } |
|
971 | + |
|
972 | + |
|
973 | + |
|
974 | + /** |
|
975 | + * get_page_for_posts |
|
976 | + * if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the |
|
977 | + * wp-option "page_for_posts", or "posts" if no page is selected |
|
978 | + * |
|
979 | + * @access public |
|
980 | + * @return string |
|
981 | + */ |
|
982 | + public static function get_page_for_posts() |
|
983 | + { |
|
984 | + $page_for_posts = get_option('page_for_posts'); |
|
985 | + if (! $page_for_posts) { |
|
986 | + return 'posts'; |
|
987 | + } |
|
988 | + /** @type WPDB $wpdb */ |
|
989 | + global $wpdb; |
|
990 | + $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
991 | + return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
992 | + } |
|
993 | + |
|
994 | + |
|
995 | + |
|
996 | + /** |
|
997 | + * register_shortcodes_and_modules. |
|
998 | + * At this point, it's too early to tell if we're maintenance mode or not. |
|
999 | + * In fact, this is where we give modules a chance to let core know they exist |
|
1000 | + * so they can help trigger maintenance mode if it's needed |
|
1001 | + * |
|
1002 | + * @access public |
|
1003 | + * @return void |
|
1004 | + */ |
|
1005 | + public function register_shortcodes_and_modules() |
|
1006 | + { |
|
1007 | + // allow modules to set hooks for the rest of the system |
|
1008 | + EE_Registry::instance()->modules = $this->_register_modules(); |
|
1009 | + } |
|
1010 | + |
|
1011 | + |
|
1012 | + |
|
1013 | + /** |
|
1014 | + * initialize_shortcodes_and_modules |
|
1015 | + * meaning they can start adding their hooks to get stuff done |
|
1016 | + * |
|
1017 | + * @access public |
|
1018 | + * @return void |
|
1019 | + */ |
|
1020 | + public function initialize_shortcodes_and_modules() |
|
1021 | + { |
|
1022 | + // allow modules to set hooks for the rest of the system |
|
1023 | + $this->_initialize_modules(); |
|
1024 | + } |
|
1025 | + |
|
1026 | + |
|
1027 | + |
|
1028 | + /** |
|
1029 | + * widgets_init |
|
1030 | + * |
|
1031 | + * @access private |
|
1032 | + * @return void |
|
1033 | + */ |
|
1034 | + public function widgets_init() |
|
1035 | + { |
|
1036 | + //only init widgets on admin pages when not in complete maintenance, and |
|
1037 | + //on frontend when not in any maintenance mode |
|
1038 | + if ( |
|
1039 | + ! EE_Maintenance_Mode::instance()->level() |
|
1040 | + || ( |
|
1041 | + is_admin() |
|
1042 | + && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
1043 | + ) |
|
1044 | + ) { |
|
1045 | + // grab list of installed widgets |
|
1046 | + $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
1047 | + // filter list of modules to register |
|
1048 | + $widgets_to_register = apply_filters( |
|
1049 | + 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
1050 | + $widgets_to_register |
|
1051 | + ); |
|
1052 | + if (! empty($widgets_to_register)) { |
|
1053 | + // cycle thru widget folders |
|
1054 | + foreach ($widgets_to_register as $widget_path) { |
|
1055 | + // add to list of installed widget modules |
|
1056 | + EE_Config::register_ee_widget($widget_path); |
|
1057 | + } |
|
1058 | + } |
|
1059 | + // filter list of installed modules |
|
1060 | + EE_Registry::instance()->widgets = apply_filters( |
|
1061 | + 'FHEE__EE_Config__register_widgets__installed_widgets', |
|
1062 | + EE_Registry::instance()->widgets |
|
1063 | + ); |
|
1064 | + } |
|
1065 | + } |
|
1066 | + |
|
1067 | + |
|
1068 | + |
|
1069 | + /** |
|
1070 | + * register_ee_widget - makes core aware of this widget |
|
1071 | + * |
|
1072 | + * @access public |
|
1073 | + * @param string $widget_path - full path up to and including widget folder |
|
1074 | + * @return void |
|
1075 | + */ |
|
1076 | + public static function register_ee_widget($widget_path = null) |
|
1077 | + { |
|
1078 | + do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
1079 | + $widget_ext = '.widget.php'; |
|
1080 | + // make all separators match |
|
1081 | + $widget_path = rtrim(str_replace('/\\', DS, $widget_path), DS); |
|
1082 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
1083 | + if (strpos($widget_path, $widget_ext) !== false) { |
|
1084 | + // grab and shortcode file name from directory name and break apart at dots |
|
1085 | + $file_name = explode('.', basename($widget_path)); |
|
1086 | + // take first segment from file name pieces and remove class prefix if it exists |
|
1087 | + $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
1088 | + // sanitize shortcode directory name |
|
1089 | + $widget = sanitize_key($widget); |
|
1090 | + // now we need to rebuild the shortcode path |
|
1091 | + $widget_path = explode(DS, $widget_path); |
|
1092 | + // remove last segment |
|
1093 | + array_pop($widget_path); |
|
1094 | + // glue it back together |
|
1095 | + $widget_path = implode(DS, $widget_path); |
|
1096 | + } else { |
|
1097 | + // grab and sanitize widget directory name |
|
1098 | + $widget = sanitize_key(basename($widget_path)); |
|
1099 | + } |
|
1100 | + // create classname from widget directory name |
|
1101 | + $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
1102 | + // add class prefix |
|
1103 | + $widget_class = 'EEW_' . $widget; |
|
1104 | + // does the widget exist ? |
|
1105 | + if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) { |
|
1106 | + $msg = sprintf( |
|
1107 | + __( |
|
1108 | + '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', |
|
1109 | + 'event_espresso' |
|
1110 | + ), |
|
1111 | + $widget_class, |
|
1112 | + $widget_path . DS . $widget_class . $widget_ext |
|
1113 | + ); |
|
1114 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1115 | + return; |
|
1116 | + } |
|
1117 | + // load the widget class file |
|
1118 | + require_once($widget_path . DS . $widget_class . $widget_ext); |
|
1119 | + // verify that class exists |
|
1120 | + if (! class_exists($widget_class)) { |
|
1121 | + $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
1122 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1123 | + return; |
|
1124 | + } |
|
1125 | + register_widget($widget_class); |
|
1126 | + // add to array of registered widgets |
|
1127 | + EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext; |
|
1128 | + } |
|
1129 | + |
|
1130 | + |
|
1131 | + |
|
1132 | + /** |
|
1133 | + * _register_modules |
|
1134 | + * |
|
1135 | + * @access private |
|
1136 | + * @return array |
|
1137 | + */ |
|
1138 | + private function _register_modules() |
|
1139 | + { |
|
1140 | + // grab list of installed modules |
|
1141 | + $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
1142 | + // filter list of modules to register |
|
1143 | + $modules_to_register = apply_filters( |
|
1144 | + 'FHEE__EE_Config__register_modules__modules_to_register', |
|
1145 | + $modules_to_register |
|
1146 | + ); |
|
1147 | + if (! empty($modules_to_register)) { |
|
1148 | + // loop through folders |
|
1149 | + foreach ($modules_to_register as $module_path) { |
|
1150 | + /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
|
1151 | + if ( |
|
1152 | + $module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
1153 | + && $module_path !== EE_MODULES . 'gateways' |
|
1154 | + ) { |
|
1155 | + // add to list of installed modules |
|
1156 | + EE_Config::register_module($module_path); |
|
1157 | + } |
|
1158 | + } |
|
1159 | + } |
|
1160 | + // filter list of installed modules |
|
1161 | + return apply_filters( |
|
1162 | + 'FHEE__EE_Config___register_modules__installed_modules', |
|
1163 | + EE_Registry::instance()->modules |
|
1164 | + ); |
|
1165 | + } |
|
1166 | + |
|
1167 | + |
|
1168 | + |
|
1169 | + /** |
|
1170 | + * register_module - makes core aware of this module |
|
1171 | + * |
|
1172 | + * @access public |
|
1173 | + * @param string $module_path - full path up to and including module folder |
|
1174 | + * @return bool |
|
1175 | + */ |
|
1176 | + public static function register_module($module_path = null) |
|
1177 | + { |
|
1178 | + do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
1179 | + $module_ext = '.module.php'; |
|
1180 | + // make all separators match |
|
1181 | + $module_path = str_replace(array('\\', '/'), DS, $module_path); |
|
1182 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
1183 | + if (strpos($module_path, $module_ext) !== false) { |
|
1184 | + // grab and shortcode file name from directory name and break apart at dots |
|
1185 | + $module_file = explode('.', basename($module_path)); |
|
1186 | + // now we need to rebuild the shortcode path |
|
1187 | + $module_path = explode(DS, $module_path); |
|
1188 | + // remove last segment |
|
1189 | + array_pop($module_path); |
|
1190 | + // glue it back together |
|
1191 | + $module_path = implode(DS, $module_path) . DS; |
|
1192 | + // take first segment from file name pieces and sanitize it |
|
1193 | + $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
1194 | + // ensure class prefix is added |
|
1195 | + $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
1196 | + } else { |
|
1197 | + // we need to generate the filename based off of the folder name |
|
1198 | + // grab and sanitize module name |
|
1199 | + $module = strtolower(basename($module_path)); |
|
1200 | + $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
1201 | + // like trailingslashit() |
|
1202 | + $module_path = rtrim($module_path, DS) . DS; |
|
1203 | + // create classname from module directory name |
|
1204 | + $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
1205 | + // add class prefix |
|
1206 | + $module_class = 'EED_' . $module; |
|
1207 | + } |
|
1208 | + // does the module exist ? |
|
1209 | + if (! is_readable($module_path . DS . $module_class . $module_ext)) { |
|
1210 | + $msg = sprintf( |
|
1211 | + __( |
|
1212 | + 'The requested %s module file could not be found or is not readable due to file permissions.', |
|
1213 | + 'event_espresso' |
|
1214 | + ), |
|
1215 | + $module |
|
1216 | + ); |
|
1217 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1218 | + return false; |
|
1219 | + } |
|
1220 | + // load the module class file |
|
1221 | + require_once($module_path . $module_class . $module_ext); |
|
1222 | + // verify that class exists |
|
1223 | + if (! class_exists($module_class)) { |
|
1224 | + $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
1225 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1226 | + return false; |
|
1227 | + } |
|
1228 | + // add to array of registered modules |
|
1229 | + EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
1230 | + do_action( |
|
1231 | + 'AHEE__EE_Config__register_module__complete', |
|
1232 | + $module_class, |
|
1233 | + EE_Registry::instance()->modules->{$module_class} |
|
1234 | + ); |
|
1235 | + return true; |
|
1236 | + } |
|
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()) { |
|
1254 | + // fire immediately |
|
1255 | + call_user_func(array($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 | + /** |
|
1269 | + * register_route - adds module method routes to route_map |
|
1270 | + * |
|
1271 | + * @access public |
|
1272 | + * @param string $route - "pretty" public alias for module method |
|
1273 | + * @param string $module - module name (classname without EED_ prefix) |
|
1274 | + * @param string $method_name - the actual module method to be routed to |
|
1275 | + * @param string $key - url param key indicating a route is being called |
|
1276 | + * @return bool |
|
1277 | + */ |
|
1278 | + public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') |
|
1279 | + { |
|
1280 | + do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
1281 | + $module = str_replace('EED_', '', $module); |
|
1282 | + $module_class = 'EED_' . $module; |
|
1283 | + if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
1284 | + $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
|
1285 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1286 | + return false; |
|
1287 | + } |
|
1288 | + if (empty($route)) { |
|
1289 | + $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
|
1290 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1291 | + return false; |
|
1292 | + } |
|
1293 | + if (! method_exists('EED_' . $module, $method_name)) { |
|
1294 | + $msg = sprintf( |
|
1295 | + __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
1296 | + $route |
|
1297 | + ); |
|
1298 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1299 | + return false; |
|
1300 | + } |
|
1301 | + EE_Config::$_module_route_map[$key][$route] = array('EED_' . $module, $method_name); |
|
1302 | + return true; |
|
1303 | + } |
|
1304 | + |
|
1305 | + |
|
1306 | + |
|
1307 | + /** |
|
1308 | + * get_route - get module method route |
|
1309 | + * |
|
1310 | + * @access public |
|
1311 | + * @param string $route - "pretty" public alias for module method |
|
1312 | + * @param string $key - url param key indicating a route is being called |
|
1313 | + * @return string |
|
1314 | + */ |
|
1315 | + public static function get_route($route = null, $key = 'ee') |
|
1316 | + { |
|
1317 | + do_action('AHEE__EE_Config__get_route__begin', $route); |
|
1318 | + $route = (string)apply_filters('FHEE__EE_Config__get_route', $route); |
|
1319 | + if (isset(EE_Config::$_module_route_map[$key][$route])) { |
|
1320 | + return EE_Config::$_module_route_map[$key][$route]; |
|
1321 | + } |
|
1322 | + return null; |
|
1323 | + } |
|
1324 | + |
|
1325 | + |
|
1326 | + |
|
1327 | + /** |
|
1328 | + * get_routes - get ALL module method routes |
|
1329 | + * |
|
1330 | + * @access public |
|
1331 | + * @return array |
|
1332 | + */ |
|
1333 | + public static function get_routes() |
|
1334 | + { |
|
1335 | + return EE_Config::$_module_route_map; |
|
1336 | + } |
|
1337 | + |
|
1338 | + |
|
1339 | + |
|
1340 | + /** |
|
1341 | + * register_forward - allows modules to forward request to another module for further processing |
|
1342 | + * |
|
1343 | + * @access public |
|
1344 | + * @param string $route - "pretty" public alias for module method |
|
1345 | + * @param integer $status - integer value corresponding to status constant strings set in module parent |
|
1346 | + * class, allows different forwards to be served based on status |
|
1347 | + * @param array|string $forward - function name or array( class, method ) |
|
1348 | + * @param string $key - url param key indicating a route is being called |
|
1349 | + * @return bool |
|
1350 | + */ |
|
1351 | + public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
|
1352 | + { |
|
1353 | + do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
1354 | + if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
1355 | + $msg = sprintf( |
|
1356 | + __('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
1357 | + $route |
|
1358 | + ); |
|
1359 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1360 | + return false; |
|
1361 | + } |
|
1362 | + if (empty($forward)) { |
|
1363 | + $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
1364 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1365 | + return false; |
|
1366 | + } |
|
1367 | + if (is_array($forward)) { |
|
1368 | + if (! isset($forward[1])) { |
|
1369 | + $msg = sprintf( |
|
1370 | + __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
1371 | + $route |
|
1372 | + ); |
|
1373 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1374 | + return false; |
|
1375 | + } |
|
1376 | + if (! method_exists($forward[0], $forward[1])) { |
|
1377 | + $msg = sprintf( |
|
1378 | + __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
1379 | + $forward[1], |
|
1380 | + $route |
|
1381 | + ); |
|
1382 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1383 | + return false; |
|
1384 | + } |
|
1385 | + } else if (! function_exists($forward)) { |
|
1386 | + $msg = sprintf( |
|
1387 | + __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
1388 | + $forward, |
|
1389 | + $route |
|
1390 | + ); |
|
1391 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1392 | + return false; |
|
1393 | + } |
|
1394 | + EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward; |
|
1395 | + return true; |
|
1396 | + } |
|
1397 | + |
|
1398 | + |
|
1399 | + |
|
1400 | + /** |
|
1401 | + * get_forward - get forwarding route |
|
1402 | + * |
|
1403 | + * @access public |
|
1404 | + * @param string $route - "pretty" public alias for module method |
|
1405 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
1406 | + * allows different forwards to be served based on status |
|
1407 | + * @param string $key - url param key indicating a route is being called |
|
1408 | + * @return string |
|
1409 | + */ |
|
1410 | + public static function get_forward($route = null, $status = 0, $key = 'ee') |
|
1411 | + { |
|
1412 | + do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
1413 | + if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) { |
|
1414 | + return apply_filters( |
|
1415 | + 'FHEE__EE_Config__get_forward', |
|
1416 | + EE_Config::$_module_forward_map[$key][$route][$status], |
|
1417 | + $route, |
|
1418 | + $status |
|
1419 | + ); |
|
1420 | + } |
|
1421 | + return null; |
|
1422 | + } |
|
1423 | + |
|
1424 | + |
|
1425 | + |
|
1426 | + /** |
|
1427 | + * register_forward - allows modules to specify different view templates for different method routes and status |
|
1428 | + * results |
|
1429 | + * |
|
1430 | + * @access public |
|
1431 | + * @param string $route - "pretty" public alias for module method |
|
1432 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
1433 | + * allows different views to be served based on status |
|
1434 | + * @param string $view |
|
1435 | + * @param string $key - url param key indicating a route is being called |
|
1436 | + * @return bool |
|
1437 | + */ |
|
1438 | + public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
|
1439 | + { |
|
1440 | + do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
1441 | + if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
1442 | + $msg = sprintf( |
|
1443 | + __('The module route %s for this view has not been registered.', 'event_espresso'), |
|
1444 | + $route |
|
1445 | + ); |
|
1446 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1447 | + return false; |
|
1448 | + } |
|
1449 | + if (! is_readable($view)) { |
|
1450 | + $msg = sprintf( |
|
1451 | + __( |
|
1452 | + 'The %s view file could not be found or is not readable due to file permissions.', |
|
1453 | + 'event_espresso' |
|
1454 | + ), |
|
1455 | + $view |
|
1456 | + ); |
|
1457 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1458 | + return false; |
|
1459 | + } |
|
1460 | + EE_Config::$_module_view_map[$key][$route][absint($status)] = $view; |
|
1461 | + return true; |
|
1462 | + } |
|
1463 | + |
|
1464 | + |
|
1465 | + |
|
1466 | + /** |
|
1467 | + * get_view - get view for route and status |
|
1468 | + * |
|
1469 | + * @access public |
|
1470 | + * @param string $route - "pretty" public alias for module method |
|
1471 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
1472 | + * allows different views to be served based on status |
|
1473 | + * @param string $key - url param key indicating a route is being called |
|
1474 | + * @return string |
|
1475 | + */ |
|
1476 | + public static function get_view($route = null, $status = 0, $key = 'ee') |
|
1477 | + { |
|
1478 | + do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
1479 | + if (isset(EE_Config::$_module_view_map[$key][$route][$status])) { |
|
1480 | + return apply_filters( |
|
1481 | + 'FHEE__EE_Config__get_view', |
|
1482 | + EE_Config::$_module_view_map[$key][$route][$status], |
|
1483 | + $route, |
|
1484 | + $status |
|
1485 | + ); |
|
1486 | + } |
|
1487 | + return null; |
|
1488 | + } |
|
1489 | + |
|
1490 | + |
|
1491 | + |
|
1492 | + public function update_addon_option_names() |
|
1493 | + { |
|
1494 | + update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
1495 | + } |
|
1496 | + |
|
1497 | + |
|
1498 | + |
|
1499 | + public function shutdown() |
|
1500 | + { |
|
1501 | + $this->update_addon_option_names(); |
|
1502 | + } |
|
1503 | + |
|
1504 | + |
|
1505 | + |
|
1506 | + /** |
|
1507 | + * @return LegacyShortcodesManager |
|
1508 | + */ |
|
1509 | + public static function getLegacyShortcodesManager() |
|
1510 | + { |
|
1511 | + |
|
1512 | + if ( ! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
1513 | + EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager( |
|
1514 | + EE_Registry::instance() |
|
1515 | + ); |
|
1516 | + } |
|
1517 | + return EE_Config::instance()->legacy_shortcodes_manager; |
|
1518 | + } |
|
1519 | + |
|
1520 | + |
|
1521 | + |
|
1522 | + /** |
|
1523 | + * register_shortcode - makes core aware of this shortcode |
|
1524 | + * |
|
1525 | + * @deprecated 4.9.26 |
|
1526 | + * @param string $shortcode_path - full path up to and including shortcode folder |
|
1527 | + * @return bool |
|
1528 | + */ |
|
1529 | + public static function register_shortcode($shortcode_path = null) |
|
1530 | + { |
|
1531 | + EE_Error::doing_it_wrong( |
|
1532 | + __METHOD__, |
|
1533 | + __( |
|
1534 | + '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.', |
|
1535 | + 'event_espresso' |
|
1536 | + ), |
|
1537 | + '4.9.26' |
|
1538 | + ); |
|
1539 | + return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path); |
|
1540 | + } |
|
1541 | 1541 | |
1542 | 1542 | |
1543 | 1543 | |
@@ -1549,684 +1549,108 @@ discard block |
||
1549 | 1549 | * Base class used for config classes. These classes should generally not have |
1550 | 1550 | * magic functions in use, except we'll allow them to magically set and get stuff... |
1551 | 1551 | * basically, they should just be well-defined stdClasses |
1552 | - */ |
|
1553 | -class EE_Config_Base |
|
1554 | -{ |
|
1555 | - |
|
1556 | - /** |
|
1557 | - * Utility function for escaping the value of a property and returning. |
|
1558 | - * |
|
1559 | - * @param string $property property name (checks to see if exists). |
|
1560 | - * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
1561 | - * @throws \EE_Error |
|
1562 | - */ |
|
1563 | - public function get_pretty($property) |
|
1564 | - { |
|
1565 | - if (! property_exists($this, $property)) { |
|
1566 | - throw new EE_Error( |
|
1567 | - sprintf( |
|
1568 | - __( |
|
1569 | - '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
|
1570 | - 'event_espresso' |
|
1571 | - ), |
|
1572 | - get_class($this), |
|
1573 | - $property |
|
1574 | - ) |
|
1575 | - ); |
|
1576 | - } |
|
1577 | - //just handling escaping of strings for now. |
|
1578 | - if (is_string($this->{$property})) { |
|
1579 | - return stripslashes($this->{$property}); |
|
1580 | - } |
|
1581 | - return $this->{$property}; |
|
1582 | - } |
|
1583 | - |
|
1584 | - |
|
1585 | - |
|
1586 | - public function populate() |
|
1587 | - { |
|
1588 | - //grab defaults via a new instance of this class. |
|
1589 | - $class_name = get_class($this); |
|
1590 | - $defaults = new $class_name; |
|
1591 | - //loop through the properties for this class and see if they are set. If they are NOT, then grab the |
|
1592 | - //default from our $defaults object. |
|
1593 | - foreach (get_object_vars($defaults) as $property => $value) { |
|
1594 | - if ($this->{$property} === null) { |
|
1595 | - $this->{$property} = $value; |
|
1596 | - } |
|
1597 | - } |
|
1598 | - //cleanup |
|
1599 | - unset($defaults); |
|
1600 | - } |
|
1601 | - |
|
1602 | - |
|
1603 | - |
|
1604 | - /** |
|
1605 | - * __isset |
|
1606 | - * |
|
1607 | - * @param $a |
|
1608 | - * @return bool |
|
1609 | - */ |
|
1610 | - public function __isset($a) |
|
1611 | - { |
|
1612 | - return false; |
|
1613 | - } |
|
1614 | - |
|
1615 | - |
|
1616 | - |
|
1617 | - /** |
|
1618 | - * __unset |
|
1619 | - * |
|
1620 | - * @param $a |
|
1621 | - * @return bool |
|
1622 | - */ |
|
1623 | - public function __unset($a) |
|
1624 | - { |
|
1625 | - return false; |
|
1626 | - } |
|
1627 | - |
|
1628 | - |
|
1629 | - |
|
1630 | - /** |
|
1631 | - * __clone |
|
1632 | - */ |
|
1633 | - public function __clone() |
|
1634 | - { |
|
1635 | - } |
|
1636 | - |
|
1637 | - |
|
1638 | - |
|
1639 | - /** |
|
1640 | - * __wakeup |
|
1641 | - */ |
|
1642 | - public function __wakeup() |
|
1643 | - { |
|
1644 | - } |
|
1645 | - |
|
1646 | - |
|
1647 | - |
|
1648 | - /** |
|
1649 | - * __destruct |
|
1650 | - */ |
|
1651 | - public function __destruct() |
|
1652 | - { |
|
1653 | - } |
|
1654 | -} |
|
1655 | - |
|
1656 | - |
|
1657 | - |
|
1658 | -/** |
|
1659 | - * Class for defining what's in the EE_Config relating to registration settings |
|
1660 | - */ |
|
1661 | -class EE_Core_Config extends EE_Config_Base |
|
1662 | -{ |
|
1663 | - |
|
1664 | - public $current_blog_id; |
|
1665 | - |
|
1666 | - public $ee_ueip_optin; |
|
1667 | - |
|
1668 | - public $ee_ueip_has_notified; |
|
1669 | - |
|
1670 | - /** |
|
1671 | - * Not to be confused with the 4 critical page variables (See |
|
1672 | - * get_critical_pages_array()), this is just an array of wp posts that have EE |
|
1673 | - * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode |
|
1674 | - * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array. |
|
1675 | - * |
|
1676 | - * @var array |
|
1677 | - */ |
|
1678 | - public $post_shortcodes; |
|
1679 | - |
|
1680 | - public $module_route_map; |
|
1681 | - |
|
1682 | - public $module_forward_map; |
|
1683 | - |
|
1684 | - public $module_view_map; |
|
1685 | - |
|
1686 | - /** |
|
1687 | - * The next 4 vars are the IDs of critical EE pages. |
|
1688 | - * |
|
1689 | - * @var int |
|
1690 | - */ |
|
1691 | - public $reg_page_id; |
|
1692 | - |
|
1693 | - public $txn_page_id; |
|
1694 | - |
|
1695 | - public $thank_you_page_id; |
|
1696 | - |
|
1697 | - public $cancel_page_id; |
|
1698 | - |
|
1699 | - /** |
|
1700 | - * The next 4 vars are the URLs of critical EE pages. |
|
1701 | - * |
|
1702 | - * @var int |
|
1703 | - */ |
|
1704 | - public $reg_page_url; |
|
1705 | - |
|
1706 | - public $txn_page_url; |
|
1707 | - |
|
1708 | - public $thank_you_page_url; |
|
1709 | - |
|
1710 | - public $cancel_page_url; |
|
1711 | - |
|
1712 | - /** |
|
1713 | - * The next vars relate to the custom slugs for EE CPT routes |
|
1714 | - */ |
|
1715 | - public $event_cpt_slug; |
|
1716 | - |
|
1717 | - |
|
1718 | - /** |
|
1719 | - * This caches the _ee_ueip_option in case this config is reset in the same |
|
1720 | - * request across blog switches in a multisite context. |
|
1721 | - * Avoids extra queries to the db for this option. |
|
1722 | - * |
|
1723 | - * @var bool |
|
1724 | - */ |
|
1725 | - public static $ee_ueip_option; |
|
1726 | - |
|
1727 | - |
|
1728 | - |
|
1729 | - /** |
|
1730 | - * class constructor |
|
1731 | - * |
|
1732 | - * @access public |
|
1733 | - */ |
|
1734 | - public function __construct() |
|
1735 | - { |
|
1736 | - // set default organization settings |
|
1737 | - $this->current_blog_id = get_current_blog_id(); |
|
1738 | - $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id; |
|
1739 | - $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
|
1740 | - $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
1741 | - $this->post_shortcodes = array(); |
|
1742 | - $this->module_route_map = array(); |
|
1743 | - $this->module_forward_map = array(); |
|
1744 | - $this->module_view_map = array(); |
|
1745 | - // critical EE page IDs |
|
1746 | - $this->reg_page_id = 0; |
|
1747 | - $this->txn_page_id = 0; |
|
1748 | - $this->thank_you_page_id = 0; |
|
1749 | - $this->cancel_page_id = 0; |
|
1750 | - // critical EE page URLs |
|
1751 | - $this->reg_page_url = ''; |
|
1752 | - $this->txn_page_url = ''; |
|
1753 | - $this->thank_you_page_url = ''; |
|
1754 | - $this->cancel_page_url = ''; |
|
1755 | - //cpt slugs |
|
1756 | - $this->event_cpt_slug = __('events', 'event_espresso'); |
|
1757 | - //ueip constant check |
|
1758 | - if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
1759 | - $this->ee_ueip_optin = false; |
|
1760 | - $this->ee_ueip_has_notified = true; |
|
1761 | - } |
|
1762 | - } |
|
1763 | - |
|
1764 | - |
|
1765 | - |
|
1766 | - /** |
|
1767 | - * @return array |
|
1768 | - */ |
|
1769 | - public function get_critical_pages_array() |
|
1770 | - { |
|
1771 | - return array( |
|
1772 | - $this->reg_page_id, |
|
1773 | - $this->txn_page_id, |
|
1774 | - $this->thank_you_page_id, |
|
1775 | - $this->cancel_page_id, |
|
1776 | - ); |
|
1777 | - } |
|
1778 | - |
|
1779 | - |
|
1780 | - |
|
1781 | - /** |
|
1782 | - * @return array |
|
1783 | - */ |
|
1784 | - public function get_critical_pages_shortcodes_array() |
|
1785 | - { |
|
1786 | - return array( |
|
1787 | - $this->reg_page_id => 'ESPRESSO_CHECKOUT', |
|
1788 | - $this->txn_page_id => 'ESPRESSO_TXN_PAGE', |
|
1789 | - $this->thank_you_page_id => 'ESPRESSO_THANK_YOU', |
|
1790 | - $this->cancel_page_id => 'ESPRESSO_CANCELLED', |
|
1791 | - ); |
|
1792 | - } |
|
1793 | - |
|
1794 | - |
|
1795 | - |
|
1796 | - /** |
|
1797 | - * gets/returns URL for EE reg_page |
|
1798 | - * |
|
1799 | - * @access public |
|
1800 | - * @return string |
|
1801 | - */ |
|
1802 | - public function reg_page_url() |
|
1803 | - { |
|
1804 | - if (! $this->reg_page_url) { |
|
1805 | - $this->reg_page_url = add_query_arg( |
|
1806 | - array('uts' => time()), |
|
1807 | - get_permalink($this->reg_page_id) |
|
1808 | - ) . '#checkout'; |
|
1809 | - } |
|
1810 | - return $this->reg_page_url; |
|
1811 | - } |
|
1812 | - |
|
1813 | - |
|
1814 | - |
|
1815 | - /** |
|
1816 | - * gets/returns URL for EE txn_page |
|
1817 | - * |
|
1818 | - * @param array $query_args like what gets passed to |
|
1819 | - * add_query_arg() as the first argument |
|
1820 | - * @access public |
|
1821 | - * @return string |
|
1822 | - */ |
|
1823 | - public function txn_page_url($query_args = array()) |
|
1824 | - { |
|
1825 | - if (! $this->txn_page_url) { |
|
1826 | - $this->txn_page_url = get_permalink($this->txn_page_id); |
|
1827 | - } |
|
1828 | - if ($query_args) { |
|
1829 | - return add_query_arg($query_args, $this->txn_page_url); |
|
1830 | - } else { |
|
1831 | - return $this->txn_page_url; |
|
1832 | - } |
|
1833 | - } |
|
1834 | - |
|
1835 | - |
|
1836 | - |
|
1837 | - /** |
|
1838 | - * gets/returns URL for EE thank_you_page |
|
1839 | - * |
|
1840 | - * @param array $query_args like what gets passed to |
|
1841 | - * add_query_arg() as the first argument |
|
1842 | - * @access public |
|
1843 | - * @return string |
|
1844 | - */ |
|
1845 | - public function thank_you_page_url($query_args = array()) |
|
1846 | - { |
|
1847 | - if (! $this->thank_you_page_url) { |
|
1848 | - $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
1849 | - } |
|
1850 | - if ($query_args) { |
|
1851 | - return add_query_arg($query_args, $this->thank_you_page_url); |
|
1852 | - } else { |
|
1853 | - return $this->thank_you_page_url; |
|
1854 | - } |
|
1855 | - } |
|
1856 | - |
|
1857 | - |
|
1858 | - |
|
1859 | - /** |
|
1860 | - * gets/returns URL for EE cancel_page |
|
1861 | - * |
|
1862 | - * @access public |
|
1863 | - * @return string |
|
1864 | - */ |
|
1865 | - public function cancel_page_url() |
|
1866 | - { |
|
1867 | - if (! $this->cancel_page_url) { |
|
1868 | - $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
1869 | - } |
|
1870 | - return $this->cancel_page_url; |
|
1871 | - } |
|
1872 | - |
|
1873 | - |
|
1874 | - |
|
1875 | - /** |
|
1876 | - * Resets all critical page urls to their original state. Used primarily by the __sleep() magic method currently. |
|
1877 | - * |
|
1878 | - * @since 4.7.5 |
|
1879 | - */ |
|
1880 | - protected function _reset_urls() |
|
1881 | - { |
|
1882 | - $this->reg_page_url = ''; |
|
1883 | - $this->txn_page_url = ''; |
|
1884 | - $this->cancel_page_url = ''; |
|
1885 | - $this->thank_you_page_url = ''; |
|
1886 | - } |
|
1887 | - |
|
1888 | - |
|
1889 | - |
|
1890 | - /** |
|
1891 | - * Used to return what the optin value is set for the EE User Experience Program. |
|
1892 | - * This accounts for multisite and this value being requested for a subsite. In multisite, the value is set |
|
1893 | - * on the main site only. |
|
1894 | - * |
|
1895 | - * @return mixed|void |
|
1896 | - */ |
|
1897 | - protected function _get_main_ee_ueip_optin() |
|
1898 | - { |
|
1899 | - //if this is the main site then we can just bypass our direct query. |
|
1900 | - if (is_main_site()) { |
|
1901 | - return get_option('ee_ueip_optin', false); |
|
1902 | - } |
|
1903 | - //is this already cached for this request? If so use it. |
|
1904 | - if ( ! empty(EE_Core_Config::$ee_ueip_option)) { |
|
1905 | - return EE_Core_Config::$ee_ueip_option; |
|
1906 | - } |
|
1907 | - global $wpdb; |
|
1908 | - $current_network_main_site = is_multisite() ? get_current_site() : null; |
|
1909 | - $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
1910 | - $option = 'ee_ueip_optin'; |
|
1911 | - //set correct table for query |
|
1912 | - $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
1913 | - //rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
|
1914 | - //get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
|
1915 | - //re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
|
1916 | - //this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
|
1917 | - //for the purpose of caching. |
|
1918 | - $pre = apply_filters('pre_option_' . $option, false, $option); |
|
1919 | - if (false !== $pre) { |
|
1920 | - EE_Core_Config::$ee_ueip_option = $pre; |
|
1921 | - return EE_Core_Config::$ee_ueip_option; |
|
1922 | - } |
|
1923 | - $row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", |
|
1924 | - $option)); |
|
1925 | - if (is_object($row)) { |
|
1926 | - $value = $row->option_value; |
|
1927 | - } else { //option does not exist so use default. |
|
1928 | - return apply_filters('default_option_' . $option, false, $option); |
|
1929 | - } |
|
1930 | - EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
1931 | - return EE_Core_Config::$ee_ueip_option; |
|
1932 | - } |
|
1933 | - |
|
1934 | - |
|
1935 | - |
|
1936 | - /** |
|
1937 | - * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values |
|
1938 | - * on the object. |
|
1939 | - * |
|
1940 | - * @return array |
|
1941 | - */ |
|
1942 | - public function __sleep() |
|
1943 | - { |
|
1944 | - //reset all url properties |
|
1945 | - $this->_reset_urls(); |
|
1946 | - //return what to save to db |
|
1947 | - return array_keys(get_object_vars($this)); |
|
1948 | - } |
|
1949 | - |
|
1950 | -} |
|
1951 | - |
|
1952 | - |
|
1953 | - |
|
1954 | -/** |
|
1955 | - * Config class for storing info on the Organization |
|
1956 | - */ |
|
1957 | -class EE_Organization_Config extends EE_Config_Base |
|
1958 | -{ |
|
1959 | - |
|
1960 | - /** |
|
1961 | - * @var string $name |
|
1962 | - * eg EE4.1 |
|
1963 | - */ |
|
1964 | - public $name; |
|
1965 | - |
|
1966 | - /** |
|
1967 | - * @var string $address_1 |
|
1968 | - * eg 123 Onna Road |
|
1969 | - */ |
|
1970 | - public $address_1; |
|
1971 | - |
|
1972 | - /** |
|
1973 | - * @var string $address_2 |
|
1974 | - * eg PO Box 123 |
|
1975 | - */ |
|
1976 | - public $address_2; |
|
1977 | - |
|
1978 | - /** |
|
1979 | - * @var string $city |
|
1980 | - * eg Inna City |
|
1981 | - */ |
|
1982 | - public $city; |
|
1983 | - |
|
1984 | - /** |
|
1985 | - * @var int $STA_ID |
|
1986 | - * eg 4 |
|
1987 | - */ |
|
1988 | - public $STA_ID; |
|
1989 | - |
|
1990 | - /** |
|
1991 | - * @var string $CNT_ISO |
|
1992 | - * eg US |
|
1993 | - */ |
|
1994 | - public $CNT_ISO; |
|
1995 | - |
|
1996 | - /** |
|
1997 | - * @var string $zip |
|
1998 | - * eg 12345 or V1A 2B3 |
|
1999 | - */ |
|
2000 | - public $zip; |
|
2001 | - |
|
2002 | - /** |
|
2003 | - * @var string $email |
|
2004 | - * eg [email protected] |
|
2005 | - */ |
|
2006 | - public $email; |
|
2007 | - |
|
2008 | - |
|
2009 | - /** |
|
2010 | - * @var string $phone |
|
2011 | - * eg. 111-111-1111 |
|
2012 | - */ |
|
2013 | - public $phone; |
|
2014 | - |
|
2015 | - |
|
2016 | - /** |
|
2017 | - * @var string $vat |
|
2018 | - * VAT/Tax Number |
|
2019 | - */ |
|
2020 | - public $vat; |
|
2021 | - |
|
2022 | - /** |
|
2023 | - * @var string $logo_url |
|
2024 | - * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg |
|
2025 | - */ |
|
2026 | - public $logo_url; |
|
2027 | - |
|
2028 | - |
|
2029 | - /** |
|
2030 | - * The below are all various properties for holding links to organization social network profiles |
|
2031 | - * |
|
2032 | - * @var string |
|
2033 | - */ |
|
2034 | - /** |
|
2035 | - * facebook (facebook.com/profile.name) |
|
2036 | - * |
|
2037 | - * @var string |
|
2038 | - */ |
|
2039 | - public $facebook; |
|
2040 | - |
|
2041 | - |
|
2042 | - /** |
|
2043 | - * twitter (twitter.com/twitter_handle) |
|
2044 | - * |
|
2045 | - * @var string |
|
2046 | - */ |
|
2047 | - public $twitter; |
|
2048 | - |
|
2049 | - |
|
2050 | - /** |
|
2051 | - * linkedin (linkedin.com/in/profile_name) |
|
2052 | - * |
|
2053 | - * @var string |
|
2054 | - */ |
|
2055 | - public $linkedin; |
|
2056 | - |
|
2057 | - |
|
2058 | - /** |
|
2059 | - * pinterest (www.pinterest.com/profile_name) |
|
2060 | - * |
|
2061 | - * @var string |
|
2062 | - */ |
|
2063 | - public $pinterest; |
|
2064 | - |
|
2065 | - |
|
2066 | - /** |
|
2067 | - * google+ (google.com/+profileName) |
|
2068 | - * |
|
2069 | - * @var string |
|
2070 | - */ |
|
2071 | - public $google; |
|
2072 | - |
|
2073 | - |
|
2074 | - /** |
|
2075 | - * instagram (instagram.com/handle) |
|
2076 | - * |
|
2077 | - * @var string |
|
2078 | - */ |
|
2079 | - public $instagram; |
|
2080 | - |
|
2081 | - |
|
2082 | - |
|
2083 | - /** |
|
2084 | - * class constructor |
|
2085 | - * |
|
2086 | - * @access public |
|
2087 | - */ |
|
2088 | - public function __construct() |
|
2089 | - { |
|
2090 | - // set default organization settings |
|
2091 | - $this->name = get_bloginfo('name'); |
|
2092 | - $this->address_1 = '123 Onna Road'; |
|
2093 | - $this->address_2 = 'PO Box 123'; |
|
2094 | - $this->city = 'Inna City'; |
|
2095 | - $this->STA_ID = 4; |
|
2096 | - $this->CNT_ISO = 'US'; |
|
2097 | - $this->zip = '12345'; |
|
2098 | - $this->email = get_bloginfo('admin_email'); |
|
2099 | - $this->phone = ''; |
|
2100 | - $this->vat = '123456789'; |
|
2101 | - $this->logo_url = ''; |
|
2102 | - $this->facebook = ''; |
|
2103 | - $this->twitter = ''; |
|
2104 | - $this->linkedin = ''; |
|
2105 | - $this->pinterest = ''; |
|
2106 | - $this->google = ''; |
|
2107 | - $this->instagram = ''; |
|
2108 | - } |
|
2109 | - |
|
2110 | -} |
|
2111 | - |
|
2112 | - |
|
2113 | - |
|
2114 | -/** |
|
2115 | - * Class for defining what's in the EE_Config relating to currency |
|
2116 | - */ |
|
2117 | -class EE_Currency_Config extends EE_Config_Base |
|
2118 | -{ |
|
2119 | - |
|
2120 | - /** |
|
2121 | - * @var string $code |
|
2122 | - * eg 'US' |
|
2123 | - */ |
|
2124 | - public $code; |
|
2125 | - |
|
2126 | - /** |
|
2127 | - * @var string $name |
|
2128 | - * eg 'Dollar' |
|
2129 | - */ |
|
2130 | - public $name; |
|
2131 | - |
|
2132 | - /** |
|
2133 | - * plural name |
|
2134 | - * |
|
2135 | - * @var string $plural |
|
2136 | - * eg 'Dollars' |
|
2137 | - */ |
|
2138 | - public $plural; |
|
2139 | - |
|
2140 | - /** |
|
2141 | - * currency sign |
|
2142 | - * |
|
2143 | - * @var string $sign |
|
2144 | - * eg '$' |
|
2145 | - */ |
|
2146 | - public $sign; |
|
2147 | - |
|
2148 | - /** |
|
2149 | - * Whether the currency sign should come before the number or not |
|
2150 | - * |
|
2151 | - * @var boolean $sign_b4 |
|
2152 | - */ |
|
2153 | - public $sign_b4; |
|
2154 | - |
|
2155 | - /** |
|
2156 | - * How many digits should come after the decimal place |
|
2157 | - * |
|
2158 | - * @var int $dec_plc |
|
2159 | - */ |
|
2160 | - public $dec_plc; |
|
2161 | - |
|
2162 | - /** |
|
2163 | - * Symbol to use for decimal mark |
|
2164 | - * |
|
2165 | - * @var string $dec_mrk |
|
2166 | - * eg '.' |
|
2167 | - */ |
|
2168 | - public $dec_mrk; |
|
2169 | - |
|
2170 | - /** |
|
2171 | - * Symbol to use for thousands |
|
2172 | - * |
|
2173 | - * @var string $thsnds |
|
2174 | - * eg ',' |
|
2175 | - */ |
|
2176 | - public $thsnds; |
|
2177 | - |
|
2178 | - |
|
1552 | + */ |
|
1553 | +class EE_Config_Base |
|
1554 | +{ |
|
2179 | 1555 | |
2180 | - /** |
|
2181 | - * class constructor |
|
2182 | - * |
|
2183 | - * @access public |
|
2184 | - * @param string $CNT_ISO |
|
2185 | - * @throws \EE_Error |
|
2186 | - */ |
|
2187 | - public function __construct($CNT_ISO = '') |
|
2188 | - { |
|
2189 | - /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */ |
|
2190 | - $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
2191 | - // get country code from organization settings or use default |
|
2192 | - $ORG_CNT = isset(EE_Registry::instance()->CFG->organization) |
|
2193 | - && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
2194 | - ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
2195 | - : ''; |
|
2196 | - // but override if requested |
|
2197 | - $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
|
2198 | - // 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 |
|
2199 | - if ( |
|
2200 | - ! empty($CNT_ISO) |
|
2201 | - && EE_Maintenance_Mode::instance()->models_can_query() |
|
2202 | - && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table()) |
|
2203 | - ) { |
|
2204 | - // retrieve the country settings from the db, just in case they have been customized |
|
2205 | - $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
2206 | - if ($country instanceof EE_Country) { |
|
2207 | - $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
2208 | - $this->name = $country->currency_name_single(); // Dollar |
|
2209 | - $this->plural = $country->currency_name_plural(); // Dollars |
|
2210 | - $this->sign = $country->currency_sign(); // currency sign: $ |
|
2211 | - $this->sign_b4 = $country->currency_sign_before(); // currency sign before or after: $TRUE or FALSE$ |
|
2212 | - $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
2213 | - $this->dec_mrk = $country->currency_decimal_mark(); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
2214 | - $this->thsnds = $country->currency_thousands_separator(); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
2215 | - } |
|
2216 | - } |
|
2217 | - // fallback to hardcoded defaults, in case the above failed |
|
2218 | - if (empty($this->code)) { |
|
2219 | - // set default currency settings |
|
2220 | - $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
2221 | - $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
2222 | - $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
2223 | - $this->sign = '$'; // currency sign: $ |
|
2224 | - $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
2225 | - $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
2226 | - $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
2227 | - $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
2228 | - } |
|
2229 | - } |
|
1556 | + /** |
|
1557 | + * Utility function for escaping the value of a property and returning. |
|
1558 | + * |
|
1559 | + * @param string $property property name (checks to see if exists). |
|
1560 | + * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
1561 | + * @throws \EE_Error |
|
1562 | + */ |
|
1563 | + public function get_pretty($property) |
|
1564 | + { |
|
1565 | + if (! property_exists($this, $property)) { |
|
1566 | + throw new EE_Error( |
|
1567 | + sprintf( |
|
1568 | + __( |
|
1569 | + '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
|
1570 | + 'event_espresso' |
|
1571 | + ), |
|
1572 | + get_class($this), |
|
1573 | + $property |
|
1574 | + ) |
|
1575 | + ); |
|
1576 | + } |
|
1577 | + //just handling escaping of strings for now. |
|
1578 | + if (is_string($this->{$property})) { |
|
1579 | + return stripslashes($this->{$property}); |
|
1580 | + } |
|
1581 | + return $this->{$property}; |
|
1582 | + } |
|
1583 | + |
|
1584 | + |
|
1585 | + |
|
1586 | + public function populate() |
|
1587 | + { |
|
1588 | + //grab defaults via a new instance of this class. |
|
1589 | + $class_name = get_class($this); |
|
1590 | + $defaults = new $class_name; |
|
1591 | + //loop through the properties for this class and see if they are set. If they are NOT, then grab the |
|
1592 | + //default from our $defaults object. |
|
1593 | + foreach (get_object_vars($defaults) as $property => $value) { |
|
1594 | + if ($this->{$property} === null) { |
|
1595 | + $this->{$property} = $value; |
|
1596 | + } |
|
1597 | + } |
|
1598 | + //cleanup |
|
1599 | + unset($defaults); |
|
1600 | + } |
|
1601 | + |
|
1602 | + |
|
1603 | + |
|
1604 | + /** |
|
1605 | + * __isset |
|
1606 | + * |
|
1607 | + * @param $a |
|
1608 | + * @return bool |
|
1609 | + */ |
|
1610 | + public function __isset($a) |
|
1611 | + { |
|
1612 | + return false; |
|
1613 | + } |
|
1614 | + |
|
1615 | + |
|
1616 | + |
|
1617 | + /** |
|
1618 | + * __unset |
|
1619 | + * |
|
1620 | + * @param $a |
|
1621 | + * @return bool |
|
1622 | + */ |
|
1623 | + public function __unset($a) |
|
1624 | + { |
|
1625 | + return false; |
|
1626 | + } |
|
1627 | + |
|
1628 | + |
|
1629 | + |
|
1630 | + /** |
|
1631 | + * __clone |
|
1632 | + */ |
|
1633 | + public function __clone() |
|
1634 | + { |
|
1635 | + } |
|
1636 | + |
|
1637 | + |
|
1638 | + |
|
1639 | + /** |
|
1640 | + * __wakeup |
|
1641 | + */ |
|
1642 | + public function __wakeup() |
|
1643 | + { |
|
1644 | + } |
|
1645 | + |
|
1646 | + |
|
1647 | + |
|
1648 | + /** |
|
1649 | + * __destruct |
|
1650 | + */ |
|
1651 | + public function __destruct() |
|
1652 | + { |
|
1653 | + } |
|
2230 | 1654 | } |
2231 | 1655 | |
2232 | 1656 | |
@@ -2234,203 +1658,779 @@ discard block |
||
2234 | 1658 | /** |
2235 | 1659 | * Class for defining what's in the EE_Config relating to registration settings |
2236 | 1660 | */ |
2237 | -class EE_Registration_Config extends EE_Config_Base |
|
1661 | +class EE_Core_Config extends EE_Config_Base |
|
2238 | 1662 | { |
2239 | 1663 | |
2240 | - /** |
|
2241 | - * Default registration status |
|
2242 | - * |
|
2243 | - * @var string $default_STS_ID |
|
2244 | - * eg 'RPP' |
|
2245 | - */ |
|
2246 | - public $default_STS_ID; |
|
2247 | - |
|
2248 | - /** |
|
2249 | - * level of validation to apply to email addresses |
|
2250 | - * |
|
2251 | - * @var string $email_validation_level |
|
2252 | - * options: 'basic', 'wp_default', 'i18n', 'i18n_dns' |
|
2253 | - */ |
|
2254 | - public $email_validation_level; |
|
2255 | - |
|
2256 | - /** |
|
2257 | - * whether or not to show alternate payment options during the reg process if payment status is pending |
|
2258 | - * |
|
2259 | - * @var boolean $show_pending_payment_options |
|
2260 | - */ |
|
2261 | - public $show_pending_payment_options; |
|
2262 | - |
|
2263 | - /** |
|
2264 | - * Whether to skip the registration confirmation page |
|
2265 | - * |
|
2266 | - * @var boolean $skip_reg_confirmation |
|
2267 | - */ |
|
2268 | - public $skip_reg_confirmation; |
|
2269 | - |
|
2270 | - /** |
|
2271 | - * an array of SPCO reg steps where: |
|
2272 | - * the keys denotes the reg step order |
|
2273 | - * each element consists of an array with the following elements: |
|
2274 | - * "file_path" => the file path to the EE_SPCO_Reg_Step class |
|
2275 | - * "class_name" => the specific EE_SPCO_Reg_Step child class name |
|
2276 | - * "slug" => the URL param used to trigger the reg step |
|
2277 | - * |
|
2278 | - * @var array $reg_steps |
|
2279 | - */ |
|
2280 | - public $reg_steps; |
|
2281 | - |
|
2282 | - /** |
|
2283 | - * Whether registration confirmation should be the last page of SPCO |
|
2284 | - * |
|
2285 | - * @var boolean $reg_confirmation_last |
|
2286 | - */ |
|
2287 | - public $reg_confirmation_last; |
|
2288 | - |
|
2289 | - /** |
|
2290 | - * Whether or not to enable the EE Bot Trap |
|
2291 | - * |
|
2292 | - * @var boolean $use_bot_trap |
|
2293 | - */ |
|
2294 | - public $use_bot_trap; |
|
2295 | - |
|
2296 | - /** |
|
2297 | - * Whether or not to encrypt some data sent by the EE Bot Trap |
|
2298 | - * |
|
2299 | - * @var boolean $use_encryption |
|
2300 | - */ |
|
2301 | - public $use_encryption; |
|
2302 | - |
|
2303 | - /** |
|
2304 | - * Whether or not to use ReCaptcha |
|
2305 | - * |
|
2306 | - * @var boolean $use_captcha |
|
2307 | - */ |
|
2308 | - public $use_captcha; |
|
2309 | - |
|
2310 | - /** |
|
2311 | - * ReCaptcha Theme |
|
2312 | - * |
|
2313 | - * @var string $recaptcha_theme |
|
2314 | - * options: 'dark ', 'light' |
|
2315 | - */ |
|
2316 | - public $recaptcha_theme; |
|
2317 | - |
|
2318 | - /** |
|
2319 | - * ReCaptcha Type |
|
2320 | - * |
|
2321 | - * @var string $recaptcha_type |
|
2322 | - * options: 'audio', 'image' |
|
2323 | - */ |
|
2324 | - public $recaptcha_type; |
|
2325 | - |
|
2326 | - /** |
|
2327 | - * ReCaptcha language |
|
2328 | - * |
|
2329 | - * @var string $recaptcha_language |
|
2330 | - * eg 'en' |
|
2331 | - */ |
|
2332 | - public $recaptcha_language; |
|
2333 | - |
|
2334 | - /** |
|
2335 | - * ReCaptcha public key |
|
2336 | - * |
|
2337 | - * @var string $recaptcha_publickey |
|
2338 | - */ |
|
2339 | - public $recaptcha_publickey; |
|
2340 | - |
|
2341 | - /** |
|
2342 | - * ReCaptcha private key |
|
2343 | - * |
|
2344 | - * @var string $recaptcha_privatekey |
|
2345 | - */ |
|
2346 | - public $recaptcha_privatekey; |
|
1664 | + public $current_blog_id; |
|
1665 | + |
|
1666 | + public $ee_ueip_optin; |
|
1667 | + |
|
1668 | + public $ee_ueip_has_notified; |
|
1669 | + |
|
1670 | + /** |
|
1671 | + * Not to be confused with the 4 critical page variables (See |
|
1672 | + * get_critical_pages_array()), this is just an array of wp posts that have EE |
|
1673 | + * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode |
|
1674 | + * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array. |
|
1675 | + * |
|
1676 | + * @var array |
|
1677 | + */ |
|
1678 | + public $post_shortcodes; |
|
1679 | + |
|
1680 | + public $module_route_map; |
|
1681 | + |
|
1682 | + public $module_forward_map; |
|
1683 | + |
|
1684 | + public $module_view_map; |
|
1685 | + |
|
1686 | + /** |
|
1687 | + * The next 4 vars are the IDs of critical EE pages. |
|
1688 | + * |
|
1689 | + * @var int |
|
1690 | + */ |
|
1691 | + public $reg_page_id; |
|
1692 | + |
|
1693 | + public $txn_page_id; |
|
1694 | + |
|
1695 | + public $thank_you_page_id; |
|
1696 | + |
|
1697 | + public $cancel_page_id; |
|
1698 | + |
|
1699 | + /** |
|
1700 | + * The next 4 vars are the URLs of critical EE pages. |
|
1701 | + * |
|
1702 | + * @var int |
|
1703 | + */ |
|
1704 | + public $reg_page_url; |
|
1705 | + |
|
1706 | + public $txn_page_url; |
|
1707 | + |
|
1708 | + public $thank_you_page_url; |
|
1709 | + |
|
1710 | + public $cancel_page_url; |
|
1711 | + |
|
1712 | + /** |
|
1713 | + * The next vars relate to the custom slugs for EE CPT routes |
|
1714 | + */ |
|
1715 | + public $event_cpt_slug; |
|
1716 | + |
|
1717 | + |
|
1718 | + /** |
|
1719 | + * This caches the _ee_ueip_option in case this config is reset in the same |
|
1720 | + * request across blog switches in a multisite context. |
|
1721 | + * Avoids extra queries to the db for this option. |
|
1722 | + * |
|
1723 | + * @var bool |
|
1724 | + */ |
|
1725 | + public static $ee_ueip_option; |
|
1726 | + |
|
1727 | + |
|
1728 | + |
|
1729 | + /** |
|
1730 | + * class constructor |
|
1731 | + * |
|
1732 | + * @access public |
|
1733 | + */ |
|
1734 | + public function __construct() |
|
1735 | + { |
|
1736 | + // set default organization settings |
|
1737 | + $this->current_blog_id = get_current_blog_id(); |
|
1738 | + $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id; |
|
1739 | + $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
|
1740 | + $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
1741 | + $this->post_shortcodes = array(); |
|
1742 | + $this->module_route_map = array(); |
|
1743 | + $this->module_forward_map = array(); |
|
1744 | + $this->module_view_map = array(); |
|
1745 | + // critical EE page IDs |
|
1746 | + $this->reg_page_id = 0; |
|
1747 | + $this->txn_page_id = 0; |
|
1748 | + $this->thank_you_page_id = 0; |
|
1749 | + $this->cancel_page_id = 0; |
|
1750 | + // critical EE page URLs |
|
1751 | + $this->reg_page_url = ''; |
|
1752 | + $this->txn_page_url = ''; |
|
1753 | + $this->thank_you_page_url = ''; |
|
1754 | + $this->cancel_page_url = ''; |
|
1755 | + //cpt slugs |
|
1756 | + $this->event_cpt_slug = __('events', 'event_espresso'); |
|
1757 | + //ueip constant check |
|
1758 | + if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
1759 | + $this->ee_ueip_optin = false; |
|
1760 | + $this->ee_ueip_has_notified = true; |
|
1761 | + } |
|
1762 | + } |
|
1763 | + |
|
1764 | + |
|
1765 | + |
|
1766 | + /** |
|
1767 | + * @return array |
|
1768 | + */ |
|
1769 | + public function get_critical_pages_array() |
|
1770 | + { |
|
1771 | + return array( |
|
1772 | + $this->reg_page_id, |
|
1773 | + $this->txn_page_id, |
|
1774 | + $this->thank_you_page_id, |
|
1775 | + $this->cancel_page_id, |
|
1776 | + ); |
|
1777 | + } |
|
1778 | + |
|
1779 | + |
|
1780 | + |
|
1781 | + /** |
|
1782 | + * @return array |
|
1783 | + */ |
|
1784 | + public function get_critical_pages_shortcodes_array() |
|
1785 | + { |
|
1786 | + return array( |
|
1787 | + $this->reg_page_id => 'ESPRESSO_CHECKOUT', |
|
1788 | + $this->txn_page_id => 'ESPRESSO_TXN_PAGE', |
|
1789 | + $this->thank_you_page_id => 'ESPRESSO_THANK_YOU', |
|
1790 | + $this->cancel_page_id => 'ESPRESSO_CANCELLED', |
|
1791 | + ); |
|
1792 | + } |
|
1793 | + |
|
1794 | + |
|
1795 | + |
|
1796 | + /** |
|
1797 | + * gets/returns URL for EE reg_page |
|
1798 | + * |
|
1799 | + * @access public |
|
1800 | + * @return string |
|
1801 | + */ |
|
1802 | + public function reg_page_url() |
|
1803 | + { |
|
1804 | + if (! $this->reg_page_url) { |
|
1805 | + $this->reg_page_url = add_query_arg( |
|
1806 | + array('uts' => time()), |
|
1807 | + get_permalink($this->reg_page_id) |
|
1808 | + ) . '#checkout'; |
|
1809 | + } |
|
1810 | + return $this->reg_page_url; |
|
1811 | + } |
|
1812 | + |
|
1813 | + |
|
1814 | + |
|
1815 | + /** |
|
1816 | + * gets/returns URL for EE txn_page |
|
1817 | + * |
|
1818 | + * @param array $query_args like what gets passed to |
|
1819 | + * add_query_arg() as the first argument |
|
1820 | + * @access public |
|
1821 | + * @return string |
|
1822 | + */ |
|
1823 | + public function txn_page_url($query_args = array()) |
|
1824 | + { |
|
1825 | + if (! $this->txn_page_url) { |
|
1826 | + $this->txn_page_url = get_permalink($this->txn_page_id); |
|
1827 | + } |
|
1828 | + if ($query_args) { |
|
1829 | + return add_query_arg($query_args, $this->txn_page_url); |
|
1830 | + } else { |
|
1831 | + return $this->txn_page_url; |
|
1832 | + } |
|
1833 | + } |
|
1834 | + |
|
1835 | + |
|
1836 | + |
|
1837 | + /** |
|
1838 | + * gets/returns URL for EE thank_you_page |
|
1839 | + * |
|
1840 | + * @param array $query_args like what gets passed to |
|
1841 | + * add_query_arg() as the first argument |
|
1842 | + * @access public |
|
1843 | + * @return string |
|
1844 | + */ |
|
1845 | + public function thank_you_page_url($query_args = array()) |
|
1846 | + { |
|
1847 | + if (! $this->thank_you_page_url) { |
|
1848 | + $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
1849 | + } |
|
1850 | + if ($query_args) { |
|
1851 | + return add_query_arg($query_args, $this->thank_you_page_url); |
|
1852 | + } else { |
|
1853 | + return $this->thank_you_page_url; |
|
1854 | + } |
|
1855 | + } |
|
1856 | + |
|
1857 | + |
|
1858 | + |
|
1859 | + /** |
|
1860 | + * gets/returns URL for EE cancel_page |
|
1861 | + * |
|
1862 | + * @access public |
|
1863 | + * @return string |
|
1864 | + */ |
|
1865 | + public function cancel_page_url() |
|
1866 | + { |
|
1867 | + if (! $this->cancel_page_url) { |
|
1868 | + $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
1869 | + } |
|
1870 | + return $this->cancel_page_url; |
|
1871 | + } |
|
1872 | + |
|
1873 | + |
|
1874 | + |
|
1875 | + /** |
|
1876 | + * Resets all critical page urls to their original state. Used primarily by the __sleep() magic method currently. |
|
1877 | + * |
|
1878 | + * @since 4.7.5 |
|
1879 | + */ |
|
1880 | + protected function _reset_urls() |
|
1881 | + { |
|
1882 | + $this->reg_page_url = ''; |
|
1883 | + $this->txn_page_url = ''; |
|
1884 | + $this->cancel_page_url = ''; |
|
1885 | + $this->thank_you_page_url = ''; |
|
1886 | + } |
|
1887 | + |
|
1888 | + |
|
1889 | + |
|
1890 | + /** |
|
1891 | + * Used to return what the optin value is set for the EE User Experience Program. |
|
1892 | + * This accounts for multisite and this value being requested for a subsite. In multisite, the value is set |
|
1893 | + * on the main site only. |
|
1894 | + * |
|
1895 | + * @return mixed|void |
|
1896 | + */ |
|
1897 | + protected function _get_main_ee_ueip_optin() |
|
1898 | + { |
|
1899 | + //if this is the main site then we can just bypass our direct query. |
|
1900 | + if (is_main_site()) { |
|
1901 | + return get_option('ee_ueip_optin', false); |
|
1902 | + } |
|
1903 | + //is this already cached for this request? If so use it. |
|
1904 | + if ( ! empty(EE_Core_Config::$ee_ueip_option)) { |
|
1905 | + return EE_Core_Config::$ee_ueip_option; |
|
1906 | + } |
|
1907 | + global $wpdb; |
|
1908 | + $current_network_main_site = is_multisite() ? get_current_site() : null; |
|
1909 | + $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
1910 | + $option = 'ee_ueip_optin'; |
|
1911 | + //set correct table for query |
|
1912 | + $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
1913 | + //rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
|
1914 | + //get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
|
1915 | + //re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
|
1916 | + //this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
|
1917 | + //for the purpose of caching. |
|
1918 | + $pre = apply_filters('pre_option_' . $option, false, $option); |
|
1919 | + if (false !== $pre) { |
|
1920 | + EE_Core_Config::$ee_ueip_option = $pre; |
|
1921 | + return EE_Core_Config::$ee_ueip_option; |
|
1922 | + } |
|
1923 | + $row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", |
|
1924 | + $option)); |
|
1925 | + if (is_object($row)) { |
|
1926 | + $value = $row->option_value; |
|
1927 | + } else { //option does not exist so use default. |
|
1928 | + return apply_filters('default_option_' . $option, false, $option); |
|
1929 | + } |
|
1930 | + EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
1931 | + return EE_Core_Config::$ee_ueip_option; |
|
1932 | + } |
|
1933 | + |
|
1934 | + |
|
1935 | + |
|
1936 | + /** |
|
1937 | + * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values |
|
1938 | + * on the object. |
|
1939 | + * |
|
1940 | + * @return array |
|
1941 | + */ |
|
1942 | + public function __sleep() |
|
1943 | + { |
|
1944 | + //reset all url properties |
|
1945 | + $this->_reset_urls(); |
|
1946 | + //return what to save to db |
|
1947 | + return array_keys(get_object_vars($this)); |
|
1948 | + } |
|
2347 | 1949 | |
2348 | - /** |
|
2349 | - * ReCaptcha width |
|
2350 | - * |
|
2351 | - * @var int $recaptcha_width |
|
2352 | - * @deprecated |
|
2353 | - */ |
|
2354 | - public $recaptcha_width; |
|
1950 | +} |
|
2355 | 1951 | |
2356 | - /** |
|
2357 | - * Whether or not invalid attempts to directly access the registration checkout page should be tracked. |
|
2358 | - * |
|
2359 | - * @var boolean $track_invalid_checkout_access |
|
2360 | - */ |
|
2361 | - protected $track_invalid_checkout_access = true; |
|
2362 | 1952 | |
2363 | 1953 | |
1954 | +/** |
|
1955 | + * Config class for storing info on the Organization |
|
1956 | + */ |
|
1957 | +class EE_Organization_Config extends EE_Config_Base |
|
1958 | +{ |
|
2364 | 1959 | |
2365 | - /** |
|
2366 | - * class constructor |
|
2367 | - * |
|
2368 | - * @access public |
|
2369 | - */ |
|
2370 | - public function __construct() |
|
2371 | - { |
|
2372 | - // set default registration settings |
|
2373 | - $this->default_STS_ID = EEM_Registration::status_id_pending_payment; |
|
2374 | - $this->email_validation_level = 'wp_default'; |
|
2375 | - $this->show_pending_payment_options = true; |
|
2376 | - $this->skip_reg_confirmation = false; |
|
2377 | - $this->reg_steps = array(); |
|
2378 | - $this->reg_confirmation_last = false; |
|
2379 | - $this->use_bot_trap = true; |
|
2380 | - $this->use_encryption = true; |
|
2381 | - $this->use_captcha = false; |
|
2382 | - $this->recaptcha_theme = 'light'; |
|
2383 | - $this->recaptcha_type = 'image'; |
|
2384 | - $this->recaptcha_language = 'en'; |
|
2385 | - $this->recaptcha_publickey = null; |
|
2386 | - $this->recaptcha_privatekey = null; |
|
2387 | - $this->recaptcha_width = 500; |
|
2388 | - } |
|
2389 | - |
|
2390 | - |
|
2391 | - |
|
2392 | - /** |
|
2393 | - * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
2394 | - * |
|
2395 | - * @since 4.8.8.rc.019 |
|
2396 | - */ |
|
2397 | - public function do_hooks() |
|
2398 | - { |
|
2399 | - add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
2400 | - } |
|
1960 | + /** |
|
1961 | + * @var string $name |
|
1962 | + * eg EE4.1 |
|
1963 | + */ |
|
1964 | + public $name; |
|
1965 | + |
|
1966 | + /** |
|
1967 | + * @var string $address_1 |
|
1968 | + * eg 123 Onna Road |
|
1969 | + */ |
|
1970 | + public $address_1; |
|
1971 | + |
|
1972 | + /** |
|
1973 | + * @var string $address_2 |
|
1974 | + * eg PO Box 123 |
|
1975 | + */ |
|
1976 | + public $address_2; |
|
1977 | + |
|
1978 | + /** |
|
1979 | + * @var string $city |
|
1980 | + * eg Inna City |
|
1981 | + */ |
|
1982 | + public $city; |
|
1983 | + |
|
1984 | + /** |
|
1985 | + * @var int $STA_ID |
|
1986 | + * eg 4 |
|
1987 | + */ |
|
1988 | + public $STA_ID; |
|
1989 | + |
|
1990 | + /** |
|
1991 | + * @var string $CNT_ISO |
|
1992 | + * eg US |
|
1993 | + */ |
|
1994 | + public $CNT_ISO; |
|
1995 | + |
|
1996 | + /** |
|
1997 | + * @var string $zip |
|
1998 | + * eg 12345 or V1A 2B3 |
|
1999 | + */ |
|
2000 | + public $zip; |
|
2001 | + |
|
2002 | + /** |
|
2003 | + * @var string $email |
|
2004 | + * eg [email protected] |
|
2005 | + */ |
|
2006 | + public $email; |
|
2007 | + |
|
2008 | + |
|
2009 | + /** |
|
2010 | + * @var string $phone |
|
2011 | + * eg. 111-111-1111 |
|
2012 | + */ |
|
2013 | + public $phone; |
|
2014 | + |
|
2015 | + |
|
2016 | + /** |
|
2017 | + * @var string $vat |
|
2018 | + * VAT/Tax Number |
|
2019 | + */ |
|
2020 | + public $vat; |
|
2021 | + |
|
2022 | + /** |
|
2023 | + * @var string $logo_url |
|
2024 | + * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg |
|
2025 | + */ |
|
2026 | + public $logo_url; |
|
2027 | + |
|
2028 | + |
|
2029 | + /** |
|
2030 | + * The below are all various properties for holding links to organization social network profiles |
|
2031 | + * |
|
2032 | + * @var string |
|
2033 | + */ |
|
2034 | + /** |
|
2035 | + * facebook (facebook.com/profile.name) |
|
2036 | + * |
|
2037 | + * @var string |
|
2038 | + */ |
|
2039 | + public $facebook; |
|
2040 | + |
|
2041 | + |
|
2042 | + /** |
|
2043 | + * twitter (twitter.com/twitter_handle) |
|
2044 | + * |
|
2045 | + * @var string |
|
2046 | + */ |
|
2047 | + public $twitter; |
|
2048 | + |
|
2049 | + |
|
2050 | + /** |
|
2051 | + * linkedin (linkedin.com/in/profile_name) |
|
2052 | + * |
|
2053 | + * @var string |
|
2054 | + */ |
|
2055 | + public $linkedin; |
|
2056 | + |
|
2057 | + |
|
2058 | + /** |
|
2059 | + * pinterest (www.pinterest.com/profile_name) |
|
2060 | + * |
|
2061 | + * @var string |
|
2062 | + */ |
|
2063 | + public $pinterest; |
|
2064 | + |
|
2065 | + |
|
2066 | + /** |
|
2067 | + * google+ (google.com/+profileName) |
|
2068 | + * |
|
2069 | + * @var string |
|
2070 | + */ |
|
2071 | + public $google; |
|
2072 | + |
|
2073 | + |
|
2074 | + /** |
|
2075 | + * instagram (instagram.com/handle) |
|
2076 | + * |
|
2077 | + * @var string |
|
2078 | + */ |
|
2079 | + public $instagram; |
|
2080 | + |
|
2081 | + |
|
2082 | + |
|
2083 | + /** |
|
2084 | + * class constructor |
|
2085 | + * |
|
2086 | + * @access public |
|
2087 | + */ |
|
2088 | + public function __construct() |
|
2089 | + { |
|
2090 | + // set default organization settings |
|
2091 | + $this->name = get_bloginfo('name'); |
|
2092 | + $this->address_1 = '123 Onna Road'; |
|
2093 | + $this->address_2 = 'PO Box 123'; |
|
2094 | + $this->city = 'Inna City'; |
|
2095 | + $this->STA_ID = 4; |
|
2096 | + $this->CNT_ISO = 'US'; |
|
2097 | + $this->zip = '12345'; |
|
2098 | + $this->email = get_bloginfo('admin_email'); |
|
2099 | + $this->phone = ''; |
|
2100 | + $this->vat = '123456789'; |
|
2101 | + $this->logo_url = ''; |
|
2102 | + $this->facebook = ''; |
|
2103 | + $this->twitter = ''; |
|
2104 | + $this->linkedin = ''; |
|
2105 | + $this->pinterest = ''; |
|
2106 | + $this->google = ''; |
|
2107 | + $this->instagram = ''; |
|
2108 | + } |
|
2401 | 2109 | |
2110 | +} |
|
2402 | 2111 | |
2403 | 2112 | |
2404 | - /** |
|
2405 | - * @return void |
|
2406 | - */ |
|
2407 | - public function set_default_reg_status_on_EEM_Event() |
|
2408 | - { |
|
2409 | - EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
2410 | - } |
|
2411 | 2113 | |
2114 | +/** |
|
2115 | + * Class for defining what's in the EE_Config relating to currency |
|
2116 | + */ |
|
2117 | +class EE_Currency_Config extends EE_Config_Base |
|
2118 | +{ |
|
2412 | 2119 | |
2120 | + /** |
|
2121 | + * @var string $code |
|
2122 | + * eg 'US' |
|
2123 | + */ |
|
2124 | + public $code; |
|
2125 | + |
|
2126 | + /** |
|
2127 | + * @var string $name |
|
2128 | + * eg 'Dollar' |
|
2129 | + */ |
|
2130 | + public $name; |
|
2131 | + |
|
2132 | + /** |
|
2133 | + * plural name |
|
2134 | + * |
|
2135 | + * @var string $plural |
|
2136 | + * eg 'Dollars' |
|
2137 | + */ |
|
2138 | + public $plural; |
|
2139 | + |
|
2140 | + /** |
|
2141 | + * currency sign |
|
2142 | + * |
|
2143 | + * @var string $sign |
|
2144 | + * eg '$' |
|
2145 | + */ |
|
2146 | + public $sign; |
|
2147 | + |
|
2148 | + /** |
|
2149 | + * Whether the currency sign should come before the number or not |
|
2150 | + * |
|
2151 | + * @var boolean $sign_b4 |
|
2152 | + */ |
|
2153 | + public $sign_b4; |
|
2154 | + |
|
2155 | + /** |
|
2156 | + * How many digits should come after the decimal place |
|
2157 | + * |
|
2158 | + * @var int $dec_plc |
|
2159 | + */ |
|
2160 | + public $dec_plc; |
|
2161 | + |
|
2162 | + /** |
|
2163 | + * Symbol to use for decimal mark |
|
2164 | + * |
|
2165 | + * @var string $dec_mrk |
|
2166 | + * eg '.' |
|
2167 | + */ |
|
2168 | + public $dec_mrk; |
|
2169 | + |
|
2170 | + /** |
|
2171 | + * Symbol to use for thousands |
|
2172 | + * |
|
2173 | + * @var string $thsnds |
|
2174 | + * eg ',' |
|
2175 | + */ |
|
2176 | + public $thsnds; |
|
2177 | + |
|
2178 | + |
|
2179 | + |
|
2180 | + /** |
|
2181 | + * class constructor |
|
2182 | + * |
|
2183 | + * @access public |
|
2184 | + * @param string $CNT_ISO |
|
2185 | + * @throws \EE_Error |
|
2186 | + */ |
|
2187 | + public function __construct($CNT_ISO = '') |
|
2188 | + { |
|
2189 | + /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */ |
|
2190 | + $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
2191 | + // get country code from organization settings or use default |
|
2192 | + $ORG_CNT = isset(EE_Registry::instance()->CFG->organization) |
|
2193 | + && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
2194 | + ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
2195 | + : ''; |
|
2196 | + // but override if requested |
|
2197 | + $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
|
2198 | + // 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 |
|
2199 | + if ( |
|
2200 | + ! empty($CNT_ISO) |
|
2201 | + && EE_Maintenance_Mode::instance()->models_can_query() |
|
2202 | + && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table()) |
|
2203 | + ) { |
|
2204 | + // retrieve the country settings from the db, just in case they have been customized |
|
2205 | + $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
2206 | + if ($country instanceof EE_Country) { |
|
2207 | + $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
2208 | + $this->name = $country->currency_name_single(); // Dollar |
|
2209 | + $this->plural = $country->currency_name_plural(); // Dollars |
|
2210 | + $this->sign = $country->currency_sign(); // currency sign: $ |
|
2211 | + $this->sign_b4 = $country->currency_sign_before(); // currency sign before or after: $TRUE or FALSE$ |
|
2212 | + $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
2213 | + $this->dec_mrk = $country->currency_decimal_mark(); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
2214 | + $this->thsnds = $country->currency_thousands_separator(); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
2215 | + } |
|
2216 | + } |
|
2217 | + // fallback to hardcoded defaults, in case the above failed |
|
2218 | + if (empty($this->code)) { |
|
2219 | + // set default currency settings |
|
2220 | + $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
2221 | + $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
2222 | + $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
2223 | + $this->sign = '$'; // currency sign: $ |
|
2224 | + $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
2225 | + $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
2226 | + $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
2227 | + $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
2228 | + } |
|
2229 | + } |
|
2230 | +} |
|
2413 | 2231 | |
2414 | - /** |
|
2415 | - * @return boolean |
|
2416 | - */ |
|
2417 | - public function track_invalid_checkout_access() |
|
2418 | - { |
|
2419 | - return $this->track_invalid_checkout_access; |
|
2420 | - } |
|
2421 | 2232 | |
2422 | 2233 | |
2234 | +/** |
|
2235 | + * Class for defining what's in the EE_Config relating to registration settings |
|
2236 | + */ |
|
2237 | +class EE_Registration_Config extends EE_Config_Base |
|
2238 | +{ |
|
2423 | 2239 | |
2424 | - /** |
|
2425 | - * @param boolean $track_invalid_checkout_access |
|
2426 | - */ |
|
2427 | - public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
2428 | - { |
|
2429 | - $this->track_invalid_checkout_access = filter_var( |
|
2430 | - $track_invalid_checkout_access, |
|
2431 | - FILTER_VALIDATE_BOOLEAN |
|
2432 | - ); |
|
2433 | - } |
|
2240 | + /** |
|
2241 | + * Default registration status |
|
2242 | + * |
|
2243 | + * @var string $default_STS_ID |
|
2244 | + * eg 'RPP' |
|
2245 | + */ |
|
2246 | + public $default_STS_ID; |
|
2247 | + |
|
2248 | + /** |
|
2249 | + * level of validation to apply to email addresses |
|
2250 | + * |
|
2251 | + * @var string $email_validation_level |
|
2252 | + * options: 'basic', 'wp_default', 'i18n', 'i18n_dns' |
|
2253 | + */ |
|
2254 | + public $email_validation_level; |
|
2255 | + |
|
2256 | + /** |
|
2257 | + * whether or not to show alternate payment options during the reg process if payment status is pending |
|
2258 | + * |
|
2259 | + * @var boolean $show_pending_payment_options |
|
2260 | + */ |
|
2261 | + public $show_pending_payment_options; |
|
2262 | + |
|
2263 | + /** |
|
2264 | + * Whether to skip the registration confirmation page |
|
2265 | + * |
|
2266 | + * @var boolean $skip_reg_confirmation |
|
2267 | + */ |
|
2268 | + public $skip_reg_confirmation; |
|
2269 | + |
|
2270 | + /** |
|
2271 | + * an array of SPCO reg steps where: |
|
2272 | + * the keys denotes the reg step order |
|
2273 | + * each element consists of an array with the following elements: |
|
2274 | + * "file_path" => the file path to the EE_SPCO_Reg_Step class |
|
2275 | + * "class_name" => the specific EE_SPCO_Reg_Step child class name |
|
2276 | + * "slug" => the URL param used to trigger the reg step |
|
2277 | + * |
|
2278 | + * @var array $reg_steps |
|
2279 | + */ |
|
2280 | + public $reg_steps; |
|
2281 | + |
|
2282 | + /** |
|
2283 | + * Whether registration confirmation should be the last page of SPCO |
|
2284 | + * |
|
2285 | + * @var boolean $reg_confirmation_last |
|
2286 | + */ |
|
2287 | + public $reg_confirmation_last; |
|
2288 | + |
|
2289 | + /** |
|
2290 | + * Whether or not to enable the EE Bot Trap |
|
2291 | + * |
|
2292 | + * @var boolean $use_bot_trap |
|
2293 | + */ |
|
2294 | + public $use_bot_trap; |
|
2295 | + |
|
2296 | + /** |
|
2297 | + * Whether or not to encrypt some data sent by the EE Bot Trap |
|
2298 | + * |
|
2299 | + * @var boolean $use_encryption |
|
2300 | + */ |
|
2301 | + public $use_encryption; |
|
2302 | + |
|
2303 | + /** |
|
2304 | + * Whether or not to use ReCaptcha |
|
2305 | + * |
|
2306 | + * @var boolean $use_captcha |
|
2307 | + */ |
|
2308 | + public $use_captcha; |
|
2309 | + |
|
2310 | + /** |
|
2311 | + * ReCaptcha Theme |
|
2312 | + * |
|
2313 | + * @var string $recaptcha_theme |
|
2314 | + * options: 'dark ', 'light' |
|
2315 | + */ |
|
2316 | + public $recaptcha_theme; |
|
2317 | + |
|
2318 | + /** |
|
2319 | + * ReCaptcha Type |
|
2320 | + * |
|
2321 | + * @var string $recaptcha_type |
|
2322 | + * options: 'audio', 'image' |
|
2323 | + */ |
|
2324 | + public $recaptcha_type; |
|
2325 | + |
|
2326 | + /** |
|
2327 | + * ReCaptcha language |
|
2328 | + * |
|
2329 | + * @var string $recaptcha_language |
|
2330 | + * eg 'en' |
|
2331 | + */ |
|
2332 | + public $recaptcha_language; |
|
2333 | + |
|
2334 | + /** |
|
2335 | + * ReCaptcha public key |
|
2336 | + * |
|
2337 | + * @var string $recaptcha_publickey |
|
2338 | + */ |
|
2339 | + public $recaptcha_publickey; |
|
2340 | + |
|
2341 | + /** |
|
2342 | + * ReCaptcha private key |
|
2343 | + * |
|
2344 | + * @var string $recaptcha_privatekey |
|
2345 | + */ |
|
2346 | + public $recaptcha_privatekey; |
|
2347 | + |
|
2348 | + /** |
|
2349 | + * ReCaptcha width |
|
2350 | + * |
|
2351 | + * @var int $recaptcha_width |
|
2352 | + * @deprecated |
|
2353 | + */ |
|
2354 | + public $recaptcha_width; |
|
2355 | + |
|
2356 | + /** |
|
2357 | + * Whether or not invalid attempts to directly access the registration checkout page should be tracked. |
|
2358 | + * |
|
2359 | + * @var boolean $track_invalid_checkout_access |
|
2360 | + */ |
|
2361 | + protected $track_invalid_checkout_access = true; |
|
2362 | + |
|
2363 | + |
|
2364 | + |
|
2365 | + /** |
|
2366 | + * class constructor |
|
2367 | + * |
|
2368 | + * @access public |
|
2369 | + */ |
|
2370 | + public function __construct() |
|
2371 | + { |
|
2372 | + // set default registration settings |
|
2373 | + $this->default_STS_ID = EEM_Registration::status_id_pending_payment; |
|
2374 | + $this->email_validation_level = 'wp_default'; |
|
2375 | + $this->show_pending_payment_options = true; |
|
2376 | + $this->skip_reg_confirmation = false; |
|
2377 | + $this->reg_steps = array(); |
|
2378 | + $this->reg_confirmation_last = false; |
|
2379 | + $this->use_bot_trap = true; |
|
2380 | + $this->use_encryption = true; |
|
2381 | + $this->use_captcha = false; |
|
2382 | + $this->recaptcha_theme = 'light'; |
|
2383 | + $this->recaptcha_type = 'image'; |
|
2384 | + $this->recaptcha_language = 'en'; |
|
2385 | + $this->recaptcha_publickey = null; |
|
2386 | + $this->recaptcha_privatekey = null; |
|
2387 | + $this->recaptcha_width = 500; |
|
2388 | + } |
|
2389 | + |
|
2390 | + |
|
2391 | + |
|
2392 | + /** |
|
2393 | + * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
2394 | + * |
|
2395 | + * @since 4.8.8.rc.019 |
|
2396 | + */ |
|
2397 | + public function do_hooks() |
|
2398 | + { |
|
2399 | + add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
2400 | + } |
|
2401 | + |
|
2402 | + |
|
2403 | + |
|
2404 | + /** |
|
2405 | + * @return void |
|
2406 | + */ |
|
2407 | + public function set_default_reg_status_on_EEM_Event() |
|
2408 | + { |
|
2409 | + EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
2410 | + } |
|
2411 | + |
|
2412 | + |
|
2413 | + |
|
2414 | + /** |
|
2415 | + * @return boolean |
|
2416 | + */ |
|
2417 | + public function track_invalid_checkout_access() |
|
2418 | + { |
|
2419 | + return $this->track_invalid_checkout_access; |
|
2420 | + } |
|
2421 | + |
|
2422 | + |
|
2423 | + |
|
2424 | + /** |
|
2425 | + * @param boolean $track_invalid_checkout_access |
|
2426 | + */ |
|
2427 | + public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
2428 | + { |
|
2429 | + $this->track_invalid_checkout_access = filter_var( |
|
2430 | + $track_invalid_checkout_access, |
|
2431 | + FILTER_VALIDATE_BOOLEAN |
|
2432 | + ); |
|
2433 | + } |
|
2434 | 2434 | |
2435 | 2435 | |
2436 | 2436 | |
@@ -2444,160 +2444,160 @@ discard block |
||
2444 | 2444 | class EE_Admin_Config extends EE_Config_Base |
2445 | 2445 | { |
2446 | 2446 | |
2447 | - /** |
|
2448 | - * @var boolean $use_personnel_manager |
|
2449 | - */ |
|
2450 | - public $use_personnel_manager; |
|
2451 | - |
|
2452 | - /** |
|
2453 | - * @var boolean $use_dashboard_widget |
|
2454 | - */ |
|
2455 | - public $use_dashboard_widget; |
|
2456 | - |
|
2457 | - /** |
|
2458 | - * @var int $events_in_dashboard |
|
2459 | - */ |
|
2460 | - public $events_in_dashboard; |
|
2461 | - |
|
2462 | - /** |
|
2463 | - * @var boolean $use_event_timezones |
|
2464 | - */ |
|
2465 | - public $use_event_timezones; |
|
2466 | - |
|
2467 | - /** |
|
2468 | - * @var boolean $use_full_logging |
|
2469 | - */ |
|
2470 | - public $use_full_logging; |
|
2471 | - |
|
2472 | - /** |
|
2473 | - * @var string $log_file_name |
|
2474 | - */ |
|
2475 | - public $log_file_name; |
|
2476 | - |
|
2477 | - /** |
|
2478 | - * @var string $debug_file_name |
|
2479 | - */ |
|
2480 | - public $debug_file_name; |
|
2481 | - |
|
2482 | - /** |
|
2483 | - * @var boolean $use_remote_logging |
|
2484 | - */ |
|
2485 | - public $use_remote_logging; |
|
2486 | - |
|
2487 | - /** |
|
2488 | - * @var string $remote_logging_url |
|
2489 | - */ |
|
2490 | - public $remote_logging_url; |
|
2491 | - |
|
2492 | - /** |
|
2493 | - * @var boolean $show_reg_footer |
|
2494 | - */ |
|
2495 | - public $show_reg_footer; |
|
2496 | - |
|
2497 | - /** |
|
2498 | - * @var string $affiliate_id |
|
2499 | - */ |
|
2500 | - public $affiliate_id; |
|
2501 | - |
|
2502 | - /** |
|
2503 | - * help tours on or off (global setting) |
|
2504 | - * |
|
2505 | - * @var boolean |
|
2506 | - */ |
|
2507 | - public $help_tour_activation; |
|
2508 | - |
|
2509 | - /** |
|
2510 | - * adds extra layer of encoding to session data to prevent serialization errors |
|
2511 | - * but is incompatible with some server configuration errors |
|
2512 | - * if you get "500 internal server errors" during registration, try turning this on |
|
2513 | - * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
2514 | - * |
|
2515 | - * @var boolean $encode_session_data |
|
2516 | - */ |
|
2517 | - private $encode_session_data = false; |
|
2518 | - |
|
2519 | - |
|
2520 | - |
|
2521 | - /** |
|
2522 | - * class constructor |
|
2523 | - * |
|
2524 | - * @access public |
|
2525 | - */ |
|
2526 | - public function __construct() |
|
2527 | - { |
|
2528 | - // set default general admin settings |
|
2529 | - $this->use_personnel_manager = true; |
|
2530 | - $this->use_dashboard_widget = true; |
|
2531 | - $this->events_in_dashboard = 30; |
|
2532 | - $this->use_event_timezones = false; |
|
2533 | - $this->use_full_logging = false; |
|
2534 | - $this->use_remote_logging = false; |
|
2535 | - $this->remote_logging_url = null; |
|
2536 | - $this->show_reg_footer = true; |
|
2537 | - $this->affiliate_id = 'default'; |
|
2538 | - $this->help_tour_activation = true; |
|
2539 | - $this->encode_session_data = false; |
|
2540 | - } |
|
2541 | - |
|
2542 | - |
|
2543 | - |
|
2544 | - /** |
|
2545 | - * @param bool $reset |
|
2546 | - * @return string |
|
2547 | - */ |
|
2548 | - public function log_file_name($reset = false) |
|
2549 | - { |
|
2550 | - if (empty($this->log_file_name) || $reset) { |
|
2551 | - $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
2552 | - EE_Config::instance()->update_espresso_config(false, false); |
|
2553 | - } |
|
2554 | - return $this->log_file_name; |
|
2555 | - } |
|
2556 | - |
|
2557 | - |
|
2558 | - |
|
2559 | - /** |
|
2560 | - * @param bool $reset |
|
2561 | - * @return string |
|
2562 | - */ |
|
2563 | - public function debug_file_name($reset = false) |
|
2564 | - { |
|
2565 | - if (empty($this->debug_file_name) || $reset) { |
|
2566 | - $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
2567 | - EE_Config::instance()->update_espresso_config(false, false); |
|
2568 | - } |
|
2569 | - return $this->debug_file_name; |
|
2570 | - } |
|
2571 | - |
|
2572 | - |
|
2573 | - |
|
2574 | - /** |
|
2575 | - * @return string |
|
2576 | - */ |
|
2577 | - public function affiliate_id() |
|
2578 | - { |
|
2579 | - return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
2580 | - } |
|
2581 | - |
|
2582 | - |
|
2583 | - |
|
2584 | - /** |
|
2585 | - * @return boolean |
|
2586 | - */ |
|
2587 | - public function encode_session_data() |
|
2588 | - { |
|
2589 | - return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
2590 | - } |
|
2591 | - |
|
2592 | - |
|
2593 | - |
|
2594 | - /** |
|
2595 | - * @param boolean $encode_session_data |
|
2596 | - */ |
|
2597 | - public function set_encode_session_data($encode_session_data) |
|
2598 | - { |
|
2599 | - $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
2600 | - } |
|
2447 | + /** |
|
2448 | + * @var boolean $use_personnel_manager |
|
2449 | + */ |
|
2450 | + public $use_personnel_manager; |
|
2451 | + |
|
2452 | + /** |
|
2453 | + * @var boolean $use_dashboard_widget |
|
2454 | + */ |
|
2455 | + public $use_dashboard_widget; |
|
2456 | + |
|
2457 | + /** |
|
2458 | + * @var int $events_in_dashboard |
|
2459 | + */ |
|
2460 | + public $events_in_dashboard; |
|
2461 | + |
|
2462 | + /** |
|
2463 | + * @var boolean $use_event_timezones |
|
2464 | + */ |
|
2465 | + public $use_event_timezones; |
|
2466 | + |
|
2467 | + /** |
|
2468 | + * @var boolean $use_full_logging |
|
2469 | + */ |
|
2470 | + public $use_full_logging; |
|
2471 | + |
|
2472 | + /** |
|
2473 | + * @var string $log_file_name |
|
2474 | + */ |
|
2475 | + public $log_file_name; |
|
2476 | + |
|
2477 | + /** |
|
2478 | + * @var string $debug_file_name |
|
2479 | + */ |
|
2480 | + public $debug_file_name; |
|
2481 | + |
|
2482 | + /** |
|
2483 | + * @var boolean $use_remote_logging |
|
2484 | + */ |
|
2485 | + public $use_remote_logging; |
|
2486 | + |
|
2487 | + /** |
|
2488 | + * @var string $remote_logging_url |
|
2489 | + */ |
|
2490 | + public $remote_logging_url; |
|
2491 | + |
|
2492 | + /** |
|
2493 | + * @var boolean $show_reg_footer |
|
2494 | + */ |
|
2495 | + public $show_reg_footer; |
|
2496 | + |
|
2497 | + /** |
|
2498 | + * @var string $affiliate_id |
|
2499 | + */ |
|
2500 | + public $affiliate_id; |
|
2501 | + |
|
2502 | + /** |
|
2503 | + * help tours on or off (global setting) |
|
2504 | + * |
|
2505 | + * @var boolean |
|
2506 | + */ |
|
2507 | + public $help_tour_activation; |
|
2508 | + |
|
2509 | + /** |
|
2510 | + * adds extra layer of encoding to session data to prevent serialization errors |
|
2511 | + * but is incompatible with some server configuration errors |
|
2512 | + * if you get "500 internal server errors" during registration, try turning this on |
|
2513 | + * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
2514 | + * |
|
2515 | + * @var boolean $encode_session_data |
|
2516 | + */ |
|
2517 | + private $encode_session_data = false; |
|
2518 | + |
|
2519 | + |
|
2520 | + |
|
2521 | + /** |
|
2522 | + * class constructor |
|
2523 | + * |
|
2524 | + * @access public |
|
2525 | + */ |
|
2526 | + public function __construct() |
|
2527 | + { |
|
2528 | + // set default general admin settings |
|
2529 | + $this->use_personnel_manager = true; |
|
2530 | + $this->use_dashboard_widget = true; |
|
2531 | + $this->events_in_dashboard = 30; |
|
2532 | + $this->use_event_timezones = false; |
|
2533 | + $this->use_full_logging = false; |
|
2534 | + $this->use_remote_logging = false; |
|
2535 | + $this->remote_logging_url = null; |
|
2536 | + $this->show_reg_footer = true; |
|
2537 | + $this->affiliate_id = 'default'; |
|
2538 | + $this->help_tour_activation = true; |
|
2539 | + $this->encode_session_data = false; |
|
2540 | + } |
|
2541 | + |
|
2542 | + |
|
2543 | + |
|
2544 | + /** |
|
2545 | + * @param bool $reset |
|
2546 | + * @return string |
|
2547 | + */ |
|
2548 | + public function log_file_name($reset = false) |
|
2549 | + { |
|
2550 | + if (empty($this->log_file_name) || $reset) { |
|
2551 | + $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
2552 | + EE_Config::instance()->update_espresso_config(false, false); |
|
2553 | + } |
|
2554 | + return $this->log_file_name; |
|
2555 | + } |
|
2556 | + |
|
2557 | + |
|
2558 | + |
|
2559 | + /** |
|
2560 | + * @param bool $reset |
|
2561 | + * @return string |
|
2562 | + */ |
|
2563 | + public function debug_file_name($reset = false) |
|
2564 | + { |
|
2565 | + if (empty($this->debug_file_name) || $reset) { |
|
2566 | + $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
2567 | + EE_Config::instance()->update_espresso_config(false, false); |
|
2568 | + } |
|
2569 | + return $this->debug_file_name; |
|
2570 | + } |
|
2571 | + |
|
2572 | + |
|
2573 | + |
|
2574 | + /** |
|
2575 | + * @return string |
|
2576 | + */ |
|
2577 | + public function affiliate_id() |
|
2578 | + { |
|
2579 | + return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
2580 | + } |
|
2581 | + |
|
2582 | + |
|
2583 | + |
|
2584 | + /** |
|
2585 | + * @return boolean |
|
2586 | + */ |
|
2587 | + public function encode_session_data() |
|
2588 | + { |
|
2589 | + return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
2590 | + } |
|
2591 | + |
|
2592 | + |
|
2593 | + |
|
2594 | + /** |
|
2595 | + * @param boolean $encode_session_data |
|
2596 | + */ |
|
2597 | + public function set_encode_session_data($encode_session_data) |
|
2598 | + { |
|
2599 | + $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
2600 | + } |
|
2601 | 2601 | |
2602 | 2602 | |
2603 | 2603 | |
@@ -2611,71 +2611,71 @@ discard block |
||
2611 | 2611 | class EE_Template_Config extends EE_Config_Base |
2612 | 2612 | { |
2613 | 2613 | |
2614 | - /** |
|
2615 | - * @var boolean $enable_default_style |
|
2616 | - */ |
|
2617 | - public $enable_default_style; |
|
2618 | - |
|
2619 | - /** |
|
2620 | - * @var string $custom_style_sheet |
|
2621 | - */ |
|
2622 | - public $custom_style_sheet; |
|
2623 | - |
|
2624 | - /** |
|
2625 | - * @var boolean $display_address_in_regform |
|
2626 | - */ |
|
2627 | - public $display_address_in_regform; |
|
2628 | - |
|
2629 | - /** |
|
2630 | - * @var int $display_description_on_multi_reg_page |
|
2631 | - */ |
|
2632 | - public $display_description_on_multi_reg_page; |
|
2633 | - |
|
2634 | - /** |
|
2635 | - * @var boolean $use_custom_templates |
|
2636 | - */ |
|
2637 | - public $use_custom_templates; |
|
2638 | - |
|
2639 | - /** |
|
2640 | - * @var string $current_espresso_theme |
|
2641 | - */ |
|
2642 | - public $current_espresso_theme; |
|
2643 | - |
|
2644 | - /** |
|
2645 | - * @var EE_Ticket_Selector_Config $EED_Ticket_Selector |
|
2646 | - */ |
|
2647 | - public $EED_Ticket_Selector; |
|
2648 | - |
|
2649 | - /** |
|
2650 | - * @var EE_Event_Single_Config $EED_Event_Single |
|
2651 | - */ |
|
2652 | - public $EED_Event_Single; |
|
2653 | - |
|
2654 | - /** |
|
2655 | - * @var EE_Events_Archive_Config $EED_Events_Archive |
|
2656 | - */ |
|
2657 | - public $EED_Events_Archive; |
|
2658 | - |
|
2659 | - |
|
2660 | - |
|
2661 | - /** |
|
2662 | - * class constructor |
|
2663 | - * |
|
2664 | - * @access public |
|
2665 | - */ |
|
2666 | - public function __construct() |
|
2667 | - { |
|
2668 | - // set default template settings |
|
2669 | - $this->enable_default_style = true; |
|
2670 | - $this->custom_style_sheet = null; |
|
2671 | - $this->display_address_in_regform = true; |
|
2672 | - $this->display_description_on_multi_reg_page = false; |
|
2673 | - $this->use_custom_templates = false; |
|
2674 | - $this->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
2675 | - $this->EED_Event_Single = null; |
|
2676 | - $this->EED_Events_Archive = null; |
|
2677 | - $this->EED_Ticket_Selector = null; |
|
2678 | - } |
|
2614 | + /** |
|
2615 | + * @var boolean $enable_default_style |
|
2616 | + */ |
|
2617 | + public $enable_default_style; |
|
2618 | + |
|
2619 | + /** |
|
2620 | + * @var string $custom_style_sheet |
|
2621 | + */ |
|
2622 | + public $custom_style_sheet; |
|
2623 | + |
|
2624 | + /** |
|
2625 | + * @var boolean $display_address_in_regform |
|
2626 | + */ |
|
2627 | + public $display_address_in_regform; |
|
2628 | + |
|
2629 | + /** |
|
2630 | + * @var int $display_description_on_multi_reg_page |
|
2631 | + */ |
|
2632 | + public $display_description_on_multi_reg_page; |
|
2633 | + |
|
2634 | + /** |
|
2635 | + * @var boolean $use_custom_templates |
|
2636 | + */ |
|
2637 | + public $use_custom_templates; |
|
2638 | + |
|
2639 | + /** |
|
2640 | + * @var string $current_espresso_theme |
|
2641 | + */ |
|
2642 | + public $current_espresso_theme; |
|
2643 | + |
|
2644 | + /** |
|
2645 | + * @var EE_Ticket_Selector_Config $EED_Ticket_Selector |
|
2646 | + */ |
|
2647 | + public $EED_Ticket_Selector; |
|
2648 | + |
|
2649 | + /** |
|
2650 | + * @var EE_Event_Single_Config $EED_Event_Single |
|
2651 | + */ |
|
2652 | + public $EED_Event_Single; |
|
2653 | + |
|
2654 | + /** |
|
2655 | + * @var EE_Events_Archive_Config $EED_Events_Archive |
|
2656 | + */ |
|
2657 | + public $EED_Events_Archive; |
|
2658 | + |
|
2659 | + |
|
2660 | + |
|
2661 | + /** |
|
2662 | + * class constructor |
|
2663 | + * |
|
2664 | + * @access public |
|
2665 | + */ |
|
2666 | + public function __construct() |
|
2667 | + { |
|
2668 | + // set default template settings |
|
2669 | + $this->enable_default_style = true; |
|
2670 | + $this->custom_style_sheet = null; |
|
2671 | + $this->display_address_in_regform = true; |
|
2672 | + $this->display_description_on_multi_reg_page = false; |
|
2673 | + $this->use_custom_templates = false; |
|
2674 | + $this->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
2675 | + $this->EED_Event_Single = null; |
|
2676 | + $this->EED_Events_Archive = null; |
|
2677 | + $this->EED_Ticket_Selector = null; |
|
2678 | + } |
|
2679 | 2679 | |
2680 | 2680 | } |
2681 | 2681 | |
@@ -2687,115 +2687,115 @@ discard block |
||
2687 | 2687 | class EE_Map_Config extends EE_Config_Base |
2688 | 2688 | { |
2689 | 2689 | |
2690 | - /** |
|
2691 | - * @var boolean $use_google_maps |
|
2692 | - */ |
|
2693 | - public $use_google_maps; |
|
2694 | - |
|
2695 | - /** |
|
2696 | - * @var string $api_key |
|
2697 | - */ |
|
2698 | - public $google_map_api_key; |
|
2699 | - |
|
2700 | - /** |
|
2701 | - * @var int $event_details_map_width |
|
2702 | - */ |
|
2703 | - public $event_details_map_width; |
|
2704 | - |
|
2705 | - /** |
|
2706 | - * @var int $event_details_map_height |
|
2707 | - */ |
|
2708 | - public $event_details_map_height; |
|
2709 | - |
|
2710 | - /** |
|
2711 | - * @var int $event_details_map_zoom |
|
2712 | - */ |
|
2713 | - public $event_details_map_zoom; |
|
2714 | - |
|
2715 | - /** |
|
2716 | - * @var boolean $event_details_display_nav |
|
2717 | - */ |
|
2718 | - public $event_details_display_nav; |
|
2719 | - |
|
2720 | - /** |
|
2721 | - * @var boolean $event_details_nav_size |
|
2722 | - */ |
|
2723 | - public $event_details_nav_size; |
|
2724 | - |
|
2725 | - /** |
|
2726 | - * @var string $event_details_control_type |
|
2727 | - */ |
|
2728 | - public $event_details_control_type; |
|
2729 | - |
|
2730 | - /** |
|
2731 | - * @var string $event_details_map_align |
|
2732 | - */ |
|
2733 | - public $event_details_map_align; |
|
2734 | - |
|
2735 | - /** |
|
2736 | - * @var int $event_list_map_width |
|
2737 | - */ |
|
2738 | - public $event_list_map_width; |
|
2739 | - |
|
2740 | - /** |
|
2741 | - * @var int $event_list_map_height |
|
2742 | - */ |
|
2743 | - public $event_list_map_height; |
|
2744 | - |
|
2745 | - /** |
|
2746 | - * @var int $event_list_map_zoom |
|
2747 | - */ |
|
2748 | - public $event_list_map_zoom; |
|
2749 | - |
|
2750 | - /** |
|
2751 | - * @var boolean $event_list_display_nav |
|
2752 | - */ |
|
2753 | - public $event_list_display_nav; |
|
2754 | - |
|
2755 | - /** |
|
2756 | - * @var boolean $event_list_nav_size |
|
2757 | - */ |
|
2758 | - public $event_list_nav_size; |
|
2759 | - |
|
2760 | - /** |
|
2761 | - * @var string $event_list_control_type |
|
2762 | - */ |
|
2763 | - public $event_list_control_type; |
|
2764 | - |
|
2765 | - /** |
|
2766 | - * @var string $event_list_map_align |
|
2767 | - */ |
|
2768 | - public $event_list_map_align; |
|
2769 | - |
|
2770 | - |
|
2771 | - |
|
2772 | - /** |
|
2773 | - * class constructor |
|
2774 | - * |
|
2775 | - * @access public |
|
2776 | - */ |
|
2777 | - public function __construct() |
|
2778 | - { |
|
2779 | - // set default map settings |
|
2780 | - $this->use_google_maps = true; |
|
2781 | - $this->google_map_api_key = ''; |
|
2782 | - // for event details pages (reg page) |
|
2783 | - $this->event_details_map_width = 585; // ee_map_width_single |
|
2784 | - $this->event_details_map_height = 362; // ee_map_height_single |
|
2785 | - $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
2786 | - $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
2787 | - $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
2788 | - $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
2789 | - $this->event_details_map_align = 'center'; // ee_map_align_single |
|
2790 | - // for event list pages |
|
2791 | - $this->event_list_map_width = 300; // ee_map_width |
|
2792 | - $this->event_list_map_height = 185; // ee_map_height |
|
2793 | - $this->event_list_map_zoom = 12; // ee_map_zoom |
|
2794 | - $this->event_list_display_nav = false; // ee_map_nav_display |
|
2795 | - $this->event_list_nav_size = true; // ee_map_nav_size |
|
2796 | - $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
2797 | - $this->event_list_map_align = 'center'; // ee_map_align |
|
2798 | - } |
|
2690 | + /** |
|
2691 | + * @var boolean $use_google_maps |
|
2692 | + */ |
|
2693 | + public $use_google_maps; |
|
2694 | + |
|
2695 | + /** |
|
2696 | + * @var string $api_key |
|
2697 | + */ |
|
2698 | + public $google_map_api_key; |
|
2699 | + |
|
2700 | + /** |
|
2701 | + * @var int $event_details_map_width |
|
2702 | + */ |
|
2703 | + public $event_details_map_width; |
|
2704 | + |
|
2705 | + /** |
|
2706 | + * @var int $event_details_map_height |
|
2707 | + */ |
|
2708 | + public $event_details_map_height; |
|
2709 | + |
|
2710 | + /** |
|
2711 | + * @var int $event_details_map_zoom |
|
2712 | + */ |
|
2713 | + public $event_details_map_zoom; |
|
2714 | + |
|
2715 | + /** |
|
2716 | + * @var boolean $event_details_display_nav |
|
2717 | + */ |
|
2718 | + public $event_details_display_nav; |
|
2719 | + |
|
2720 | + /** |
|
2721 | + * @var boolean $event_details_nav_size |
|
2722 | + */ |
|
2723 | + public $event_details_nav_size; |
|
2724 | + |
|
2725 | + /** |
|
2726 | + * @var string $event_details_control_type |
|
2727 | + */ |
|
2728 | + public $event_details_control_type; |
|
2729 | + |
|
2730 | + /** |
|
2731 | + * @var string $event_details_map_align |
|
2732 | + */ |
|
2733 | + public $event_details_map_align; |
|
2734 | + |
|
2735 | + /** |
|
2736 | + * @var int $event_list_map_width |
|
2737 | + */ |
|
2738 | + public $event_list_map_width; |
|
2739 | + |
|
2740 | + /** |
|
2741 | + * @var int $event_list_map_height |
|
2742 | + */ |
|
2743 | + public $event_list_map_height; |
|
2744 | + |
|
2745 | + /** |
|
2746 | + * @var int $event_list_map_zoom |
|
2747 | + */ |
|
2748 | + public $event_list_map_zoom; |
|
2749 | + |
|
2750 | + /** |
|
2751 | + * @var boolean $event_list_display_nav |
|
2752 | + */ |
|
2753 | + public $event_list_display_nav; |
|
2754 | + |
|
2755 | + /** |
|
2756 | + * @var boolean $event_list_nav_size |
|
2757 | + */ |
|
2758 | + public $event_list_nav_size; |
|
2759 | + |
|
2760 | + /** |
|
2761 | + * @var string $event_list_control_type |
|
2762 | + */ |
|
2763 | + public $event_list_control_type; |
|
2764 | + |
|
2765 | + /** |
|
2766 | + * @var string $event_list_map_align |
|
2767 | + */ |
|
2768 | + public $event_list_map_align; |
|
2769 | + |
|
2770 | + |
|
2771 | + |
|
2772 | + /** |
|
2773 | + * class constructor |
|
2774 | + * |
|
2775 | + * @access public |
|
2776 | + */ |
|
2777 | + public function __construct() |
|
2778 | + { |
|
2779 | + // set default map settings |
|
2780 | + $this->use_google_maps = true; |
|
2781 | + $this->google_map_api_key = ''; |
|
2782 | + // for event details pages (reg page) |
|
2783 | + $this->event_details_map_width = 585; // ee_map_width_single |
|
2784 | + $this->event_details_map_height = 362; // ee_map_height_single |
|
2785 | + $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
2786 | + $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
2787 | + $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
2788 | + $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
2789 | + $this->event_details_map_align = 'center'; // ee_map_align_single |
|
2790 | + // for event list pages |
|
2791 | + $this->event_list_map_width = 300; // ee_map_width |
|
2792 | + $this->event_list_map_height = 185; // ee_map_height |
|
2793 | + $this->event_list_map_zoom = 12; // ee_map_zoom |
|
2794 | + $this->event_list_display_nav = false; // ee_map_nav_display |
|
2795 | + $this->event_list_nav_size = true; // ee_map_nav_size |
|
2796 | + $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
2797 | + $this->event_list_map_align = 'center'; // ee_map_align |
|
2798 | + } |
|
2799 | 2799 | |
2800 | 2800 | } |
2801 | 2801 | |
@@ -2807,47 +2807,47 @@ discard block |
||
2807 | 2807 | class EE_Events_Archive_Config extends EE_Config_Base |
2808 | 2808 | { |
2809 | 2809 | |
2810 | - public $display_status_banner; |
|
2810 | + public $display_status_banner; |
|
2811 | 2811 | |
2812 | - public $display_description; |
|
2812 | + public $display_description; |
|
2813 | 2813 | |
2814 | - public $display_ticket_selector; |
|
2814 | + public $display_ticket_selector; |
|
2815 | 2815 | |
2816 | - public $display_datetimes; |
|
2816 | + public $display_datetimes; |
|
2817 | 2817 | |
2818 | - public $display_venue; |
|
2818 | + public $display_venue; |
|
2819 | 2819 | |
2820 | - public $display_expired_events; |
|
2820 | + public $display_expired_events; |
|
2821 | 2821 | |
2822 | - public $use_sortable_display_order; |
|
2822 | + public $use_sortable_display_order; |
|
2823 | 2823 | |
2824 | - public $display_order_tickets; |
|
2824 | + public $display_order_tickets; |
|
2825 | 2825 | |
2826 | - public $display_order_datetimes; |
|
2826 | + public $display_order_datetimes; |
|
2827 | 2827 | |
2828 | - public $display_order_event; |
|
2828 | + public $display_order_event; |
|
2829 | 2829 | |
2830 | - public $display_order_venue; |
|
2830 | + public $display_order_venue; |
|
2831 | 2831 | |
2832 | 2832 | |
2833 | 2833 | |
2834 | - /** |
|
2835 | - * class constructor |
|
2836 | - */ |
|
2837 | - public function __construct() |
|
2838 | - { |
|
2839 | - $this->display_status_banner = 0; |
|
2840 | - $this->display_description = 1; |
|
2841 | - $this->display_ticket_selector = 0; |
|
2842 | - $this->display_datetimes = 1; |
|
2843 | - $this->display_venue = 0; |
|
2844 | - $this->display_expired_events = 0; |
|
2845 | - $this->use_sortable_display_order = false; |
|
2846 | - $this->display_order_tickets = 100; |
|
2847 | - $this->display_order_datetimes = 110; |
|
2848 | - $this->display_order_event = 120; |
|
2849 | - $this->display_order_venue = 130; |
|
2850 | - } |
|
2834 | + /** |
|
2835 | + * class constructor |
|
2836 | + */ |
|
2837 | + public function __construct() |
|
2838 | + { |
|
2839 | + $this->display_status_banner = 0; |
|
2840 | + $this->display_description = 1; |
|
2841 | + $this->display_ticket_selector = 0; |
|
2842 | + $this->display_datetimes = 1; |
|
2843 | + $this->display_venue = 0; |
|
2844 | + $this->display_expired_events = 0; |
|
2845 | + $this->use_sortable_display_order = false; |
|
2846 | + $this->display_order_tickets = 100; |
|
2847 | + $this->display_order_datetimes = 110; |
|
2848 | + $this->display_order_event = 120; |
|
2849 | + $this->display_order_venue = 130; |
|
2850 | + } |
|
2851 | 2851 | } |
2852 | 2852 | |
2853 | 2853 | |
@@ -2858,35 +2858,35 @@ discard block |
||
2858 | 2858 | class EE_Event_Single_Config extends EE_Config_Base |
2859 | 2859 | { |
2860 | 2860 | |
2861 | - public $display_status_banner_single; |
|
2861 | + public $display_status_banner_single; |
|
2862 | 2862 | |
2863 | - public $display_venue; |
|
2863 | + public $display_venue; |
|
2864 | 2864 | |
2865 | - public $use_sortable_display_order; |
|
2865 | + public $use_sortable_display_order; |
|
2866 | 2866 | |
2867 | - public $display_order_tickets; |
|
2867 | + public $display_order_tickets; |
|
2868 | 2868 | |
2869 | - public $display_order_datetimes; |
|
2869 | + public $display_order_datetimes; |
|
2870 | 2870 | |
2871 | - public $display_order_event; |
|
2871 | + public $display_order_event; |
|
2872 | 2872 | |
2873 | - public $display_order_venue; |
|
2873 | + public $display_order_venue; |
|
2874 | 2874 | |
2875 | 2875 | |
2876 | 2876 | |
2877 | - /** |
|
2878 | - * class constructor |
|
2879 | - */ |
|
2880 | - public function __construct() |
|
2881 | - { |
|
2882 | - $this->display_status_banner_single = 0; |
|
2883 | - $this->display_venue = 1; |
|
2884 | - $this->use_sortable_display_order = false; |
|
2885 | - $this->display_order_tickets = 100; |
|
2886 | - $this->display_order_datetimes = 110; |
|
2887 | - $this->display_order_event = 120; |
|
2888 | - $this->display_order_venue = 130; |
|
2889 | - } |
|
2877 | + /** |
|
2878 | + * class constructor |
|
2879 | + */ |
|
2880 | + public function __construct() |
|
2881 | + { |
|
2882 | + $this->display_status_banner_single = 0; |
|
2883 | + $this->display_venue = 1; |
|
2884 | + $this->use_sortable_display_order = false; |
|
2885 | + $this->display_order_tickets = 100; |
|
2886 | + $this->display_order_datetimes = 110; |
|
2887 | + $this->display_order_event = 120; |
|
2888 | + $this->display_order_venue = 130; |
|
2889 | + } |
|
2890 | 2890 | } |
2891 | 2891 | |
2892 | 2892 | |
@@ -2897,152 +2897,152 @@ discard block |
||
2897 | 2897 | class EE_Ticket_Selector_Config extends EE_Config_Base |
2898 | 2898 | { |
2899 | 2899 | |
2900 | - /** |
|
2901 | - * constant to indicate that a datetime selector should NEVER be shown for ticket selectors |
|
2902 | - */ |
|
2903 | - const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector'; |
|
2904 | - |
|
2905 | - /** |
|
2906 | - * constant to indicate that a datetime selector should only be shown for ticket selectors |
|
2907 | - * when the number of datetimes for the event matches the value set for $datetime_selector_threshold |
|
2908 | - */ |
|
2909 | - const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector'; |
|
2910 | - |
|
2911 | - /** |
|
2912 | - * @var boolean $show_ticket_sale_columns |
|
2913 | - */ |
|
2914 | - public $show_ticket_sale_columns; |
|
2915 | - |
|
2916 | - /** |
|
2917 | - * @var boolean $show_ticket_details |
|
2918 | - */ |
|
2919 | - public $show_ticket_details; |
|
2920 | - |
|
2921 | - /** |
|
2922 | - * @var boolean $show_expired_tickets |
|
2923 | - */ |
|
2924 | - public $show_expired_tickets; |
|
2925 | - |
|
2926 | - /** |
|
2927 | - * whether or not to display a dropdown box populated with event datetimes |
|
2928 | - * that toggles which tickets are displayed for a ticket selector. |
|
2929 | - * uses one of the *_DATETIME_SELECTOR constants defined above |
|
2930 | - * |
|
2931 | - * @var string $show_datetime_selector |
|
2932 | - */ |
|
2933 | - private $show_datetime_selector = 'no_datetime_selector'; |
|
2934 | - |
|
2935 | - /** |
|
2936 | - * the number of datetimes an event has to have before conditionally displaying a datetime selector |
|
2937 | - * |
|
2938 | - * @var int $datetime_selector_threshold |
|
2939 | - */ |
|
2940 | - private $datetime_selector_threshold = 3; |
|
2941 | - |
|
2942 | - |
|
2943 | - |
|
2944 | - /** |
|
2945 | - * class constructor |
|
2946 | - */ |
|
2947 | - public function __construct() |
|
2948 | - { |
|
2949 | - $this->show_ticket_sale_columns = true; |
|
2950 | - $this->show_ticket_details = true; |
|
2951 | - $this->show_expired_tickets = true; |
|
2952 | - $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
2953 | - $this->datetime_selector_threshold = 3; |
|
2954 | - } |
|
2955 | - |
|
2956 | - |
|
2957 | - |
|
2958 | - /** |
|
2959 | - * returns true if a datetime selector should be displayed |
|
2960 | - * |
|
2961 | - * @param array $datetimes |
|
2962 | - * @return bool |
|
2963 | - */ |
|
2964 | - public function showDatetimeSelector(array $datetimes) |
|
2965 | - { |
|
2966 | - // if the settings are NOT: don't show OR below threshold, THEN active = true |
|
2967 | - return ! ( |
|
2968 | - $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
2969 | - || ( |
|
2970 | - $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR |
|
2971 | - && count($datetimes) < $this->getDatetimeSelectorThreshold() |
|
2972 | - ) |
|
2973 | - ); |
|
2974 | - } |
|
2975 | - |
|
2976 | - |
|
2977 | - |
|
2978 | - /** |
|
2979 | - * @return string |
|
2980 | - */ |
|
2981 | - public function getShowDatetimeSelector() |
|
2982 | - { |
|
2983 | - return $this->show_datetime_selector; |
|
2984 | - } |
|
2985 | - |
|
2986 | - |
|
2987 | - |
|
2988 | - /** |
|
2989 | - * @param bool $keys_only |
|
2990 | - * @return array |
|
2991 | - */ |
|
2992 | - public function getShowDatetimeSelectorOptions($keys_only = true) |
|
2993 | - { |
|
2994 | - return $keys_only |
|
2995 | - ? array( |
|
2996 | - \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR, |
|
2997 | - \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR, |
|
2998 | - ) |
|
2999 | - : array( |
|
3000 | - \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__( |
|
3001 | - 'Do not show date & time filter', 'event_espresso' |
|
3002 | - ), |
|
3003 | - \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__( |
|
3004 | - 'Maybe show date & time filter', 'event_espresso' |
|
3005 | - ), |
|
3006 | - ); |
|
3007 | - } |
|
3008 | - |
|
3009 | - |
|
3010 | - |
|
3011 | - /** |
|
3012 | - * @param string $show_datetime_selector |
|
3013 | - */ |
|
3014 | - public function setShowDatetimeSelector($show_datetime_selector) |
|
3015 | - { |
|
3016 | - $this->show_datetime_selector = in_array( |
|
3017 | - $show_datetime_selector, |
|
3018 | - $this->getShowDatetimeSelectorOptions(), |
|
3019 | - true |
|
3020 | - ) |
|
3021 | - ? $show_datetime_selector |
|
3022 | - : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
3023 | - } |
|
3024 | - |
|
3025 | - |
|
3026 | - |
|
3027 | - /** |
|
3028 | - * @return int |
|
3029 | - */ |
|
3030 | - public function getDatetimeSelectorThreshold() |
|
3031 | - { |
|
3032 | - return $this->datetime_selector_threshold; |
|
3033 | - } |
|
3034 | - |
|
3035 | - |
|
3036 | - |
|
3037 | - |
|
3038 | - /** |
|
3039 | - * @param int $datetime_selector_threshold |
|
3040 | - */ |
|
3041 | - public function setDatetimeSelectorThreshold($datetime_selector_threshold) |
|
3042 | - { |
|
3043 | - $datetime_selector_threshold = absint($datetime_selector_threshold); |
|
3044 | - $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3; |
|
3045 | - } |
|
2900 | + /** |
|
2901 | + * constant to indicate that a datetime selector should NEVER be shown for ticket selectors |
|
2902 | + */ |
|
2903 | + const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector'; |
|
2904 | + |
|
2905 | + /** |
|
2906 | + * constant to indicate that a datetime selector should only be shown for ticket selectors |
|
2907 | + * when the number of datetimes for the event matches the value set for $datetime_selector_threshold |
|
2908 | + */ |
|
2909 | + const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector'; |
|
2910 | + |
|
2911 | + /** |
|
2912 | + * @var boolean $show_ticket_sale_columns |
|
2913 | + */ |
|
2914 | + public $show_ticket_sale_columns; |
|
2915 | + |
|
2916 | + /** |
|
2917 | + * @var boolean $show_ticket_details |
|
2918 | + */ |
|
2919 | + public $show_ticket_details; |
|
2920 | + |
|
2921 | + /** |
|
2922 | + * @var boolean $show_expired_tickets |
|
2923 | + */ |
|
2924 | + public $show_expired_tickets; |
|
2925 | + |
|
2926 | + /** |
|
2927 | + * whether or not to display a dropdown box populated with event datetimes |
|
2928 | + * that toggles which tickets are displayed for a ticket selector. |
|
2929 | + * uses one of the *_DATETIME_SELECTOR constants defined above |
|
2930 | + * |
|
2931 | + * @var string $show_datetime_selector |
|
2932 | + */ |
|
2933 | + private $show_datetime_selector = 'no_datetime_selector'; |
|
2934 | + |
|
2935 | + /** |
|
2936 | + * the number of datetimes an event has to have before conditionally displaying a datetime selector |
|
2937 | + * |
|
2938 | + * @var int $datetime_selector_threshold |
|
2939 | + */ |
|
2940 | + private $datetime_selector_threshold = 3; |
|
2941 | + |
|
2942 | + |
|
2943 | + |
|
2944 | + /** |
|
2945 | + * class constructor |
|
2946 | + */ |
|
2947 | + public function __construct() |
|
2948 | + { |
|
2949 | + $this->show_ticket_sale_columns = true; |
|
2950 | + $this->show_ticket_details = true; |
|
2951 | + $this->show_expired_tickets = true; |
|
2952 | + $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
2953 | + $this->datetime_selector_threshold = 3; |
|
2954 | + } |
|
2955 | + |
|
2956 | + |
|
2957 | + |
|
2958 | + /** |
|
2959 | + * returns true if a datetime selector should be displayed |
|
2960 | + * |
|
2961 | + * @param array $datetimes |
|
2962 | + * @return bool |
|
2963 | + */ |
|
2964 | + public function showDatetimeSelector(array $datetimes) |
|
2965 | + { |
|
2966 | + // if the settings are NOT: don't show OR below threshold, THEN active = true |
|
2967 | + return ! ( |
|
2968 | + $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
2969 | + || ( |
|
2970 | + $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR |
|
2971 | + && count($datetimes) < $this->getDatetimeSelectorThreshold() |
|
2972 | + ) |
|
2973 | + ); |
|
2974 | + } |
|
2975 | + |
|
2976 | + |
|
2977 | + |
|
2978 | + /** |
|
2979 | + * @return string |
|
2980 | + */ |
|
2981 | + public function getShowDatetimeSelector() |
|
2982 | + { |
|
2983 | + return $this->show_datetime_selector; |
|
2984 | + } |
|
2985 | + |
|
2986 | + |
|
2987 | + |
|
2988 | + /** |
|
2989 | + * @param bool $keys_only |
|
2990 | + * @return array |
|
2991 | + */ |
|
2992 | + public function getShowDatetimeSelectorOptions($keys_only = true) |
|
2993 | + { |
|
2994 | + return $keys_only |
|
2995 | + ? array( |
|
2996 | + \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR, |
|
2997 | + \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR, |
|
2998 | + ) |
|
2999 | + : array( |
|
3000 | + \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__( |
|
3001 | + 'Do not show date & time filter', 'event_espresso' |
|
3002 | + ), |
|
3003 | + \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__( |
|
3004 | + 'Maybe show date & time filter', 'event_espresso' |
|
3005 | + ), |
|
3006 | + ); |
|
3007 | + } |
|
3008 | + |
|
3009 | + |
|
3010 | + |
|
3011 | + /** |
|
3012 | + * @param string $show_datetime_selector |
|
3013 | + */ |
|
3014 | + public function setShowDatetimeSelector($show_datetime_selector) |
|
3015 | + { |
|
3016 | + $this->show_datetime_selector = in_array( |
|
3017 | + $show_datetime_selector, |
|
3018 | + $this->getShowDatetimeSelectorOptions(), |
|
3019 | + true |
|
3020 | + ) |
|
3021 | + ? $show_datetime_selector |
|
3022 | + : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
3023 | + } |
|
3024 | + |
|
3025 | + |
|
3026 | + |
|
3027 | + /** |
|
3028 | + * @return int |
|
3029 | + */ |
|
3030 | + public function getDatetimeSelectorThreshold() |
|
3031 | + { |
|
3032 | + return $this->datetime_selector_threshold; |
|
3033 | + } |
|
3034 | + |
|
3035 | + |
|
3036 | + |
|
3037 | + |
|
3038 | + /** |
|
3039 | + * @param int $datetime_selector_threshold |
|
3040 | + */ |
|
3041 | + public function setDatetimeSelectorThreshold($datetime_selector_threshold) |
|
3042 | + { |
|
3043 | + $datetime_selector_threshold = absint($datetime_selector_threshold); |
|
3044 | + $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3; |
|
3045 | + } |
|
3046 | 3046 | |
3047 | 3047 | |
3048 | 3048 | |
@@ -3060,85 +3060,85 @@ discard block |
||
3060 | 3060 | class EE_Environment_Config extends EE_Config_Base |
3061 | 3061 | { |
3062 | 3062 | |
3063 | - /** |
|
3064 | - * Hold any php environment variables that we want to track. |
|
3065 | - * |
|
3066 | - * @var stdClass; |
|
3067 | - */ |
|
3068 | - public $php; |
|
3069 | - |
|
3070 | - |
|
3071 | - |
|
3072 | - /** |
|
3073 | - * constructor |
|
3074 | - */ |
|
3075 | - public function __construct() |
|
3076 | - { |
|
3077 | - $this->php = new stdClass(); |
|
3078 | - $this->_set_php_values(); |
|
3079 | - } |
|
3080 | - |
|
3081 | - |
|
3082 | - |
|
3083 | - /** |
|
3084 | - * This sets the php environment variables. |
|
3085 | - * |
|
3086 | - * @since 4.4.0 |
|
3087 | - * @return void |
|
3088 | - */ |
|
3089 | - protected function _set_php_values() |
|
3090 | - { |
|
3091 | - $this->php->max_input_vars = ini_get('max_input_vars'); |
|
3092 | - $this->php->version = phpversion(); |
|
3093 | - } |
|
3094 | - |
|
3095 | - |
|
3096 | - |
|
3097 | - /** |
|
3098 | - * helper method for determining whether input_count is |
|
3099 | - * reaching the potential maximum the server can handle |
|
3100 | - * according to max_input_vars |
|
3101 | - * |
|
3102 | - * @param int $input_count the count of input vars. |
|
3103 | - * @return array { |
|
3104 | - * An array that represents whether available space and if no available space the error |
|
3105 | - * message. |
|
3106 | - * @type bool $has_space whether more inputs can be added. |
|
3107 | - * @type string $msg Any message to be displayed. |
|
3108 | - * } |
|
3109 | - */ |
|
3110 | - public function max_input_vars_limit_check($input_count = 0) |
|
3111 | - { |
|
3112 | - if (! empty($this->php->max_input_vars) |
|
3113 | - && ($input_count >= $this->php->max_input_vars) |
|
3114 | - && (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9) |
|
3115 | - ) { |
|
3116 | - return sprintf( |
|
3117 | - __( |
|
3118 | - 'The maximum number of inputs on this page has been exceeded. You cannot add anymore items (i.e. tickets, datetimes, custom fields) on this page because of your servers PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.', |
|
3119 | - 'event_espresso' |
|
3120 | - ), |
|
3121 | - '<br>', |
|
3122 | - $input_count, |
|
3123 | - $this->php->max_input_vars |
|
3124 | - ); |
|
3125 | - } else { |
|
3126 | - return ''; |
|
3127 | - } |
|
3128 | - } |
|
3129 | - |
|
3130 | - |
|
3131 | - |
|
3132 | - /** |
|
3133 | - * The purpose of this method is just to force rechecking php values so if they've changed, they get updated. |
|
3134 | - * |
|
3135 | - * @since 4.4.1 |
|
3136 | - * @return void |
|
3137 | - */ |
|
3138 | - public function recheck_values() |
|
3139 | - { |
|
3140 | - $this->_set_php_values(); |
|
3141 | - } |
|
3063 | + /** |
|
3064 | + * Hold any php environment variables that we want to track. |
|
3065 | + * |
|
3066 | + * @var stdClass; |
|
3067 | + */ |
|
3068 | + public $php; |
|
3069 | + |
|
3070 | + |
|
3071 | + |
|
3072 | + /** |
|
3073 | + * constructor |
|
3074 | + */ |
|
3075 | + public function __construct() |
|
3076 | + { |
|
3077 | + $this->php = new stdClass(); |
|
3078 | + $this->_set_php_values(); |
|
3079 | + } |
|
3080 | + |
|
3081 | + |
|
3082 | + |
|
3083 | + /** |
|
3084 | + * This sets the php environment variables. |
|
3085 | + * |
|
3086 | + * @since 4.4.0 |
|
3087 | + * @return void |
|
3088 | + */ |
|
3089 | + protected function _set_php_values() |
|
3090 | + { |
|
3091 | + $this->php->max_input_vars = ini_get('max_input_vars'); |
|
3092 | + $this->php->version = phpversion(); |
|
3093 | + } |
|
3094 | + |
|
3095 | + |
|
3096 | + |
|
3097 | + /** |
|
3098 | + * helper method for determining whether input_count is |
|
3099 | + * reaching the potential maximum the server can handle |
|
3100 | + * according to max_input_vars |
|
3101 | + * |
|
3102 | + * @param int $input_count the count of input vars. |
|
3103 | + * @return array { |
|
3104 | + * An array that represents whether available space and if no available space the error |
|
3105 | + * message. |
|
3106 | + * @type bool $has_space whether more inputs can be added. |
|
3107 | + * @type string $msg Any message to be displayed. |
|
3108 | + * } |
|
3109 | + */ |
|
3110 | + public function max_input_vars_limit_check($input_count = 0) |
|
3111 | + { |
|
3112 | + if (! empty($this->php->max_input_vars) |
|
3113 | + && ($input_count >= $this->php->max_input_vars) |
|
3114 | + && (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9) |
|
3115 | + ) { |
|
3116 | + return sprintf( |
|
3117 | + __( |
|
3118 | + 'The maximum number of inputs on this page has been exceeded. You cannot add anymore items (i.e. tickets, datetimes, custom fields) on this page because of your servers PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.', |
|
3119 | + 'event_espresso' |
|
3120 | + ), |
|
3121 | + '<br>', |
|
3122 | + $input_count, |
|
3123 | + $this->php->max_input_vars |
|
3124 | + ); |
|
3125 | + } else { |
|
3126 | + return ''; |
|
3127 | + } |
|
3128 | + } |
|
3129 | + |
|
3130 | + |
|
3131 | + |
|
3132 | + /** |
|
3133 | + * The purpose of this method is just to force rechecking php values so if they've changed, they get updated. |
|
3134 | + * |
|
3135 | + * @since 4.4.1 |
|
3136 | + * @return void |
|
3137 | + */ |
|
3138 | + public function recheck_values() |
|
3139 | + { |
|
3140 | + $this->_set_php_values(); |
|
3141 | + } |
|
3142 | 3142 | |
3143 | 3143 | |
3144 | 3144 | |
@@ -3156,22 +3156,22 @@ discard block |
||
3156 | 3156 | class EE_Tax_Config extends EE_Config_Base |
3157 | 3157 | { |
3158 | 3158 | |
3159 | - /* |
|
3159 | + /* |
|
3160 | 3160 | * flag to indicate whether or not to display ticket prices with the taxes included |
3161 | 3161 | * |
3162 | 3162 | * @var boolean $prices_displayed_including_taxes |
3163 | 3163 | */ |
3164 | - public $prices_displayed_including_taxes; |
|
3164 | + public $prices_displayed_including_taxes; |
|
3165 | 3165 | |
3166 | 3166 | |
3167 | 3167 | |
3168 | - /** |
|
3169 | - * class constructor |
|
3170 | - */ |
|
3171 | - public function __construct() |
|
3172 | - { |
|
3173 | - $this->prices_displayed_including_taxes = true; |
|
3174 | - } |
|
3168 | + /** |
|
3169 | + * class constructor |
|
3170 | + */ |
|
3171 | + public function __construct() |
|
3172 | + { |
|
3173 | + $this->prices_displayed_including_taxes = true; |
|
3174 | + } |
|
3175 | 3175 | } |
3176 | 3176 | |
3177 | 3177 | |
@@ -3186,17 +3186,17 @@ discard block |
||
3186 | 3186 | class EE_Messages_Config extends EE_Config_Base |
3187 | 3187 | { |
3188 | 3188 | |
3189 | - /** |
|
3190 | - * This is an integer representing the deletion threshold in months for when old messages will get deleted. |
|
3191 | - * A value of 0 represents never deleting. Default is 0. |
|
3192 | - * |
|
3193 | - * @var integer |
|
3194 | - */ |
|
3195 | - public $delete_threshold; |
|
3196 | - |
|
3197 | - public function __construct() { |
|
3198 | - $this->delete_threshold = 0; |
|
3199 | - } |
|
3189 | + /** |
|
3190 | + * This is an integer representing the deletion threshold in months for when old messages will get deleted. |
|
3191 | + * A value of 0 represents never deleting. Default is 0. |
|
3192 | + * |
|
3193 | + * @var integer |
|
3194 | + */ |
|
3195 | + public $delete_threshold; |
|
3196 | + |
|
3197 | + public function __construct() { |
|
3198 | + $this->delete_threshold = 0; |
|
3199 | + } |
|
3200 | 3200 | } |
3201 | 3201 | |
3202 | 3202 | |
@@ -3208,34 +3208,34 @@ discard block |
||
3208 | 3208 | class EE_Gateway_Config extends EE_Config_Base |
3209 | 3209 | { |
3210 | 3210 | |
3211 | - /** |
|
3212 | - * Array with keys that are payment gateways slugs, and values are arrays |
|
3213 | - * with any config info the gateway wants to store |
|
3214 | - * |
|
3215 | - * @var array |
|
3216 | - */ |
|
3217 | - public $payment_settings; |
|
3218 | - |
|
3219 | - /** |
|
3220 | - * Where keys are gateway slugs, and values are booleans indicating whether or not |
|
3221 | - * the gateway is stored in the uploads directory |
|
3222 | - * |
|
3223 | - * @var array |
|
3224 | - */ |
|
3225 | - public $active_gateways; |
|
3226 | - |
|
3227 | - |
|
3228 | - |
|
3229 | - /** |
|
3230 | - * class constructor |
|
3231 | - * |
|
3232 | - * @deprecated |
|
3233 | - */ |
|
3234 | - public function __construct() |
|
3235 | - { |
|
3236 | - $this->payment_settings = array(); |
|
3237 | - $this->active_gateways = array('Invoice' => false); |
|
3238 | - } |
|
3211 | + /** |
|
3212 | + * Array with keys that are payment gateways slugs, and values are arrays |
|
3213 | + * with any config info the gateway wants to store |
|
3214 | + * |
|
3215 | + * @var array |
|
3216 | + */ |
|
3217 | + public $payment_settings; |
|
3218 | + |
|
3219 | + /** |
|
3220 | + * Where keys are gateway slugs, and values are booleans indicating whether or not |
|
3221 | + * the gateway is stored in the uploads directory |
|
3222 | + * |
|
3223 | + * @var array |
|
3224 | + */ |
|
3225 | + public $active_gateways; |
|
3226 | + |
|
3227 | + |
|
3228 | + |
|
3229 | + /** |
|
3230 | + * class constructor |
|
3231 | + * |
|
3232 | + * @deprecated |
|
3233 | + */ |
|
3234 | + public function __construct() |
|
3235 | + { |
|
3236 | + $this->payment_settings = array(); |
|
3237 | + $this->active_gateways = array('Invoice' => false); |
|
3238 | + } |
|
3239 | 3239 | } |
3240 | 3240 | |
3241 | 3241 | // End of file EE_Config.core.php |