@@ -47,7 +47,7 @@ |
||
47 | 47 | /** |
48 | 48 | * This retrieves any EE_Message_Template_Group in the repo by its ID. |
49 | 49 | * |
50 | - * @param $GRP_ID |
|
50 | + * @param integer $GRP_ID |
|
51 | 51 | * @return EE_Message_Template_Group | null |
52 | 52 | */ |
53 | 53 | public function get_by_ID($GRP_ID) |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
3 | - exit('No direct script access allowed'); |
|
3 | + exit('No direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | |
@@ -16,89 +16,89 @@ discard block |
||
16 | 16 | { |
17 | 17 | |
18 | 18 | |
19 | - public function __construct() |
|
20 | - { |
|
21 | - $this->interface = 'EE_Message_Template_Group'; |
|
22 | - } |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + $this->interface = 'EE_Message_Template_Group'; |
|
22 | + } |
|
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * Adds the Message Template Group object to the repository. |
|
27 | - * |
|
28 | - * @param $message_template_group |
|
29 | - * @param int $EVT_ID Some templates are specific to EVT, so this is provided as a way of |
|
30 | - * indexing the template by key. |
|
31 | - * @return bool |
|
32 | - */ |
|
33 | - public function add($message_template_group, $EVT_ID = null) |
|
34 | - { |
|
35 | - if ($message_template_group instanceof $this->interface) { |
|
36 | - $data['key'] = $this->get_key( |
|
37 | - $message_template_group->messenger(), |
|
38 | - $message_template_group->message_type(), |
|
39 | - $EVT_ID |
|
40 | - ); |
|
41 | - return parent::add($message_template_group, $data); |
|
42 | - } |
|
43 | - return false; |
|
44 | - } |
|
25 | + /** |
|
26 | + * Adds the Message Template Group object to the repository. |
|
27 | + * |
|
28 | + * @param $message_template_group |
|
29 | + * @param int $EVT_ID Some templates are specific to EVT, so this is provided as a way of |
|
30 | + * indexing the template by key. |
|
31 | + * @return bool |
|
32 | + */ |
|
33 | + public function add($message_template_group, $EVT_ID = null) |
|
34 | + { |
|
35 | + if ($message_template_group instanceof $this->interface) { |
|
36 | + $data['key'] = $this->get_key( |
|
37 | + $message_template_group->messenger(), |
|
38 | + $message_template_group->message_type(), |
|
39 | + $EVT_ID |
|
40 | + ); |
|
41 | + return parent::add($message_template_group, $data); |
|
42 | + } |
|
43 | + return false; |
|
44 | + } |
|
45 | 45 | |
46 | 46 | |
47 | - /** |
|
48 | - * This retrieves any EE_Message_Template_Group in the repo by its ID. |
|
49 | - * |
|
50 | - * @param $GRP_ID |
|
51 | - * @return EE_Message_Template_Group | null |
|
52 | - */ |
|
53 | - public function get_by_ID($GRP_ID) |
|
54 | - { |
|
55 | - $this->rewind(); |
|
56 | - while ($this->valid()) { |
|
57 | - if ($this->current()->ID() === $GRP_ID) { |
|
58 | - $grp = $this->current(); |
|
59 | - $this->rewind(); |
|
60 | - return $grp; |
|
61 | - } |
|
62 | - $this->next(); |
|
63 | - } |
|
64 | - return null; |
|
65 | - } |
|
47 | + /** |
|
48 | + * This retrieves any EE_Message_Template_Group in the repo by its ID. |
|
49 | + * |
|
50 | + * @param $GRP_ID |
|
51 | + * @return EE_Message_Template_Group | null |
|
52 | + */ |
|
53 | + public function get_by_ID($GRP_ID) |
|
54 | + { |
|
55 | + $this->rewind(); |
|
56 | + while ($this->valid()) { |
|
57 | + if ($this->current()->ID() === $GRP_ID) { |
|
58 | + $grp = $this->current(); |
|
59 | + $this->rewind(); |
|
60 | + return $grp; |
|
61 | + } |
|
62 | + $this->next(); |
|
63 | + } |
|
64 | + return null; |
|
65 | + } |
|
66 | 66 | |
67 | 67 | |
68 | - /** |
|
69 | - * Generates a hash used to identify a given Message Template Group. |
|
70 | - * |
|
71 | - * @param string $messenger The EE_messenger->name |
|
72 | - * @param string $message_type The EE_message_type->name |
|
73 | - * @param int $EVT_ID Optional. If the template is for a specific EVT then that should be included. |
|
74 | - * @return string |
|
75 | - */ |
|
76 | - public function get_key($messenger, $message_type, $EVT_ID = 0) |
|
77 | - { |
|
78 | - return md5($messenger . $message_type . $EVT_ID); |
|
79 | - } |
|
68 | + /** |
|
69 | + * Generates a hash used to identify a given Message Template Group. |
|
70 | + * |
|
71 | + * @param string $messenger The EE_messenger->name |
|
72 | + * @param string $message_type The EE_message_type->name |
|
73 | + * @param int $EVT_ID Optional. If the template is for a specific EVT then that should be included. |
|
74 | + * @return string |
|
75 | + */ |
|
76 | + public function get_key($messenger, $message_type, $EVT_ID = 0) |
|
77 | + { |
|
78 | + return md5($messenger . $message_type . $EVT_ID); |
|
79 | + } |
|
80 | 80 | |
81 | 81 | |
82 | - /** |
|
83 | - * This returns a saved EE_Message_Template_Group object if there is one in the repository indexed by a key matching |
|
84 | - * the given string. |
|
85 | - * |
|
86 | - * @param string $key @see EE_Message_Template_Group::get_key() to setup a key formatted for searching. |
|
87 | - * @return null|EE_Message_Template_Group |
|
88 | - */ |
|
89 | - public function get_by_key($key) |
|
90 | - { |
|
91 | - $this->rewind(); |
|
92 | - while ($this->valid()) { |
|
93 | - $data = $this->getInfo(); |
|
94 | - if (isset($data['key']) && $data['key'] === $key) { |
|
95 | - $handler = $this->current(); |
|
96 | - $this->rewind(); |
|
97 | - return $handler; |
|
98 | - } |
|
99 | - $this->next(); |
|
100 | - } |
|
101 | - return null; |
|
102 | - } |
|
82 | + /** |
|
83 | + * This returns a saved EE_Message_Template_Group object if there is one in the repository indexed by a key matching |
|
84 | + * the given string. |
|
85 | + * |
|
86 | + * @param string $key @see EE_Message_Template_Group::get_key() to setup a key formatted for searching. |
|
87 | + * @return null|EE_Message_Template_Group |
|
88 | + */ |
|
89 | + public function get_by_key($key) |
|
90 | + { |
|
91 | + $this->rewind(); |
|
92 | + while ($this->valid()) { |
|
93 | + $data = $this->getInfo(); |
|
94 | + if (isset($data['key']) && $data['key'] === $key) { |
|
95 | + $handler = $this->current(); |
|
96 | + $this->rewind(); |
|
97 | + return $handler; |
|
98 | + } |
|
99 | + $this->next(); |
|
100 | + } |
|
101 | + return null; |
|
102 | + } |
|
103 | 103 | |
104 | 104 | } //end EE_Message_Template_Group_Collection |
105 | 105 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | 3 | exit('No direct script access allowed'); |
4 | 4 | } |
5 | 5 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | */ |
76 | 76 | public function get_key($messenger, $message_type, $EVT_ID = 0) |
77 | 77 | { |
78 | - return md5($messenger . $message_type . $EVT_ID); |
|
78 | + return md5($messenger.$message_type.$EVT_ID); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | use EventEspresso\core\services\shortcodes\ShortcodesManager; |
3 | 3 | |
4 | 4 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
5 | - exit('No direct script access allowed'); |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | |
@@ -19,1412 +19,1412 @@ discard block |
||
19 | 19 | { |
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
24 | - * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
25 | - */ |
|
26 | - const req_type_normal = 0; |
|
27 | - |
|
28 | - /** |
|
29 | - * Indicates this is a brand new installation of EE so we should install |
|
30 | - * tables and default data etc |
|
31 | - */ |
|
32 | - const req_type_new_activation = 1; |
|
33 | - |
|
34 | - /** |
|
35 | - * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
36 | - * and we just exited maintenance mode). We MUST check the database is setup properly |
|
37 | - * and that default data is setup too |
|
38 | - */ |
|
39 | - const req_type_reactivation = 2; |
|
40 | - |
|
41 | - /** |
|
42 | - * indicates that EE has been upgraded since its previous request. |
|
43 | - * We may have data migration scripts to call and will want to trigger maintenance mode |
|
44 | - */ |
|
45 | - const req_type_upgrade = 3; |
|
46 | - |
|
47 | - /** |
|
48 | - * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
49 | - */ |
|
50 | - const req_type_downgrade = 4; |
|
51 | - |
|
52 | - /** |
|
53 | - * @deprecated since version 4.6.0.dev.006 |
|
54 | - * Now whenever a new_activation is detected the request type is still just |
|
55 | - * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
56 | - * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
57 | - * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
58 | - * (Specifically, when the migration manager indicates migrations are finished |
|
59 | - * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
60 | - */ |
|
61 | - const req_type_activation_but_not_installed = 5; |
|
62 | - |
|
63 | - /** |
|
64 | - * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
65 | - */ |
|
66 | - const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * instance of the EE_System object |
|
71 | - * |
|
72 | - * @var $_instance |
|
73 | - * @access private |
|
74 | - */ |
|
75 | - private static $_instance = null; |
|
76 | - |
|
77 | - /** |
|
78 | - * @type EE_Registry $Registry |
|
79 | - * @access protected |
|
80 | - */ |
|
81 | - protected $registry; |
|
82 | - |
|
83 | - /** |
|
84 | - * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
85 | - * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
86 | - * |
|
87 | - * @var int |
|
88 | - */ |
|
89 | - private $_req_type; |
|
90 | - |
|
91 | - /** |
|
92 | - * Whether or not there was a non-micro version change in EE core version during this request |
|
93 | - * |
|
94 | - * @var boolean |
|
95 | - */ |
|
96 | - private $_major_version_change = false; |
|
97 | - |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * @singleton method used to instantiate class object |
|
102 | - * @access public |
|
103 | - * @param \EE_Registry $Registry |
|
104 | - * @return \EE_System |
|
105 | - */ |
|
106 | - public static function instance(EE_Registry $Registry = null) |
|
107 | - { |
|
108 | - // check if class object is instantiated |
|
109 | - if ( ! self::$_instance instanceof EE_System) { |
|
110 | - self::$_instance = new self($Registry); |
|
111 | - } |
|
112 | - return self::$_instance; |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * resets the instance and returns it |
|
119 | - * |
|
120 | - * @return EE_System |
|
121 | - */ |
|
122 | - public static function reset() |
|
123 | - { |
|
124 | - self::$_instance->_req_type = null; |
|
125 | - //make sure none of the old hooks are left hanging around |
|
126 | - remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
127 | - //we need to reset the migration manager in order for it to detect DMSs properly |
|
128 | - EE_Data_Migration_Manager::reset(); |
|
129 | - self::instance()->detect_activations_or_upgrades(); |
|
130 | - self::instance()->perform_activations_upgrades_and_migrations(); |
|
131 | - return self::instance(); |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * sets hooks for running rest of system |
|
138 | - * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
139 | - * starting EE Addons from any other point may lead to problems |
|
140 | - * |
|
141 | - * @access private |
|
142 | - * @param \EE_Registry $Registry |
|
143 | - */ |
|
144 | - private function __construct(EE_Registry $Registry) |
|
145 | - { |
|
146 | - $this->registry = $Registry; |
|
147 | - do_action('AHEE__EE_System__construct__begin', $this); |
|
148 | - // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
149 | - add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons')); |
|
150 | - // when an ee addon is activated, we want to call the core hook(s) again |
|
151 | - // because the newly-activated addon didn't get a chance to run at all |
|
152 | - add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
153 | - // detect whether install or upgrade |
|
154 | - add_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'), |
|
155 | - 3); |
|
156 | - // load EE_Config, EE_Textdomain, etc |
|
157 | - add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5); |
|
158 | - // load EE_Config, EE_Textdomain, etc |
|
159 | - add_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
160 | - array($this, 'register_shortcodes_modules_and_widgets'), 7); |
|
161 | - // you wanna get going? I wanna get going... let's get going! |
|
162 | - add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9); |
|
163 | - //other housekeeping |
|
164 | - //exclude EE critical pages from wp_list_pages |
|
165 | - add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10); |
|
166 | - // ALL EE Addons should use the following hook point to attach their initial setup too |
|
167 | - // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
168 | - do_action('AHEE__EE_System__construct__complete', $this); |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * load_espresso_addons |
|
175 | - * allow addons to load first so that they can set hooks for running DMS's, etc |
|
176 | - * this is hooked into both: |
|
177 | - * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
178 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
179 | - * and the WP 'activate_plugin' hookpoint |
|
180 | - * |
|
181 | - * @access public |
|
182 | - * @return void |
|
183 | - */ |
|
184 | - public function load_espresso_addons() |
|
185 | - { |
|
186 | - // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
187 | - // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
188 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
189 | - //load and setup EE_Capabilities |
|
190 | - $this->registry->load_core('Capabilities'); |
|
191 | - //caps need to be initialized on every request so that capability maps are set. |
|
192 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
193 | - $this->registry->CAP->init_caps(); |
|
194 | - do_action('AHEE__EE_System__load_espresso_addons'); |
|
195 | - //if the WP API basic auth plugin isn't already loaded, load it now. |
|
196 | - //We want it for mobile apps. Just include the entire plugin |
|
197 | - //also, don't load the basic auth when a plugin is getting activated, because |
|
198 | - //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
199 | - //and causes a fatal error |
|
200 | - if ( ! function_exists('json_basic_auth_handler') |
|
201 | - && ! function_exists('json_basic_auth_error') |
|
202 | - && ! ( |
|
203 | - isset($_GET['action']) |
|
204 | - && in_array($_GET['action'], array('activate', 'activate-selected')) |
|
205 | - ) |
|
206 | - && ! ( |
|
207 | - isset($_GET['activate']) |
|
208 | - && $_GET['activate'] === 'true' |
|
209 | - ) |
|
210 | - ) { |
|
211 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
212 | - } |
|
213 | - do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
214 | - } |
|
215 | - |
|
216 | - |
|
217 | - |
|
218 | - /** |
|
219 | - * detect_activations_or_upgrades |
|
220 | - * Checks for activation or upgrade of core first; |
|
221 | - * then also checks if any registered addons have been activated or upgraded |
|
222 | - * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
223 | - * which runs during the WP 'plugins_loaded' action at priority 3 |
|
224 | - * |
|
225 | - * @access public |
|
226 | - * @return void |
|
227 | - */ |
|
228 | - public function detect_activations_or_upgrades() |
|
229 | - { |
|
230 | - //first off: let's make sure to handle core |
|
231 | - $this->detect_if_activation_or_upgrade(); |
|
232 | - foreach ($this->registry->addons as $addon) { |
|
233 | - //detect teh request type for that addon |
|
234 | - $addon->detect_activation_or_upgrade(); |
|
235 | - } |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * detect_if_activation_or_upgrade |
|
242 | - * Takes care of detecting whether this is a brand new install or code upgrade, |
|
243 | - * and either setting up the DB or setting up maintenance mode etc. |
|
244 | - * |
|
245 | - * @access public |
|
246 | - * @return void |
|
247 | - */ |
|
248 | - public function detect_if_activation_or_upgrade() |
|
249 | - { |
|
250 | - do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
251 | - // load M-Mode class |
|
252 | - $this->registry->load_core('Maintenance_Mode'); |
|
253 | - // check if db has been updated, or if its a brand-new installation |
|
254 | - $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
255 | - $request_type = $this->detect_req_type($espresso_db_update); |
|
256 | - //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
257 | - switch ($request_type) { |
|
258 | - case EE_System::req_type_new_activation: |
|
259 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
260 | - $this->_handle_core_version_change($espresso_db_update); |
|
261 | - break; |
|
262 | - case EE_System::req_type_reactivation: |
|
263 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
264 | - $this->_handle_core_version_change($espresso_db_update); |
|
265 | - break; |
|
266 | - case EE_System::req_type_upgrade: |
|
267 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
268 | - //migrations may be required now that we've upgraded |
|
269 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
270 | - $this->_handle_core_version_change($espresso_db_update); |
|
271 | - // echo "done upgrade";die; |
|
272 | - break; |
|
273 | - case EE_System::req_type_downgrade: |
|
274 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
275 | - //its possible migrations are no longer required |
|
276 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
277 | - $this->_handle_core_version_change($espresso_db_update); |
|
278 | - break; |
|
279 | - case EE_System::req_type_normal: |
|
280 | - default: |
|
281 | - // $this->_maybe_redirect_to_ee_about(); |
|
282 | - break; |
|
283 | - } |
|
284 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
285 | - } |
|
286 | - |
|
287 | - |
|
288 | - |
|
289 | - /** |
|
290 | - * Updates the list of installed versions and sets hooks for |
|
291 | - * initializing the database later during the request |
|
292 | - * |
|
293 | - * @param array $espresso_db_update |
|
294 | - */ |
|
295 | - protected function _handle_core_version_change($espresso_db_update) |
|
296 | - { |
|
297 | - $this->update_list_of_installed_versions($espresso_db_update); |
|
298 | - //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
299 | - add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
300 | - array($this, 'initialize_db_if_no_migrations_required')); |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
307 | - * information about what versions of EE have been installed and activated, |
|
308 | - * NOT necessarily the state of the database |
|
309 | - * |
|
310 | - * @param null $espresso_db_update |
|
311 | - * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it |
|
312 | - * from the options table |
|
313 | - * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
314 | - */ |
|
315 | - private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
316 | - { |
|
317 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
318 | - if ( ! $espresso_db_update) { |
|
319 | - $espresso_db_update = get_option('espresso_db_update'); |
|
320 | - } |
|
321 | - // check that option is an array |
|
322 | - if ( ! is_array($espresso_db_update)) { |
|
323 | - // if option is FALSE, then it never existed |
|
324 | - if ($espresso_db_update === false) { |
|
325 | - // make $espresso_db_update an array and save option with autoload OFF |
|
326 | - $espresso_db_update = array(); |
|
327 | - add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
328 | - } else { |
|
329 | - // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
330 | - $espresso_db_update = array($espresso_db_update => array()); |
|
331 | - update_option('espresso_db_update', $espresso_db_update); |
|
332 | - } |
|
333 | - } else { |
|
334 | - $corrected_db_update = array(); |
|
335 | - //if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
336 | - foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
337 | - if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
338 | - //the key is an int, and the value IS NOT an array |
|
339 | - //so it must be numerically-indexed, where values are versions installed... |
|
340 | - //fix it! |
|
341 | - $version_string = $should_be_array; |
|
342 | - $corrected_db_update[$version_string] = array('unknown-date'); |
|
343 | - } else { |
|
344 | - //ok it checks out |
|
345 | - $corrected_db_update[$should_be_version_string] = $should_be_array; |
|
346 | - } |
|
347 | - } |
|
348 | - $espresso_db_update = $corrected_db_update; |
|
349 | - update_option('espresso_db_update', $espresso_db_update); |
|
350 | - } |
|
351 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
352 | - return $espresso_db_update; |
|
353 | - } |
|
354 | - |
|
355 | - |
|
356 | - |
|
357 | - /** |
|
358 | - * Does the traditional work of setting up the plugin's database and adding default data. |
|
359 | - * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
360 | - * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
361 | - * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
362 | - * so that it will be done when migrations are finished |
|
363 | - * |
|
364 | - * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
365 | - * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
366 | - * This is a resource-intensive job |
|
367 | - * so we prefer to only do it when necessary |
|
368 | - * @return void |
|
369 | - */ |
|
370 | - public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
371 | - { |
|
372 | - $request_type = $this->detect_req_type(); |
|
373 | - //only initialize system if we're not in maintenance mode. |
|
374 | - if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
375 | - update_option('ee_flush_rewrite_rules', true); |
|
376 | - if ($verify_schema) { |
|
377 | - EEH_Activation::initialize_db_and_folders(); |
|
378 | - } |
|
379 | - EEH_Activation::initialize_db_content(); |
|
380 | - EEH_Activation::system_initialization(); |
|
381 | - if ($initialize_addons_too) { |
|
382 | - $this->initialize_addons(); |
|
383 | - } |
|
384 | - } else { |
|
385 | - EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
386 | - } |
|
387 | - if ($request_type === EE_System::req_type_new_activation |
|
388 | - || $request_type === EE_System::req_type_reactivation |
|
389 | - || ( |
|
390 | - $request_type === EE_System::req_type_upgrade |
|
391 | - && $this->is_major_version_change() |
|
392 | - ) |
|
393 | - ) { |
|
394 | - add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
395 | - } |
|
396 | - } |
|
397 | - |
|
398 | - |
|
399 | - |
|
400 | - /** |
|
401 | - * Initializes the db for all registered addons |
|
402 | - */ |
|
403 | - public function initialize_addons() |
|
404 | - { |
|
405 | - //foreach registered addon, make sure its db is up-to-date too |
|
406 | - foreach ($this->registry->addons as $addon) { |
|
407 | - $addon->initialize_db_if_no_migrations_required(); |
|
408 | - } |
|
409 | - } |
|
410 | - |
|
411 | - |
|
412 | - |
|
413 | - /** |
|
414 | - * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
415 | - * |
|
416 | - * @param array $version_history |
|
417 | - * @param string $current_version_to_add version to be added to the version history |
|
418 | - * @return boolean success as to whether or not this option was changed |
|
419 | - */ |
|
420 | - public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
421 | - { |
|
422 | - if ( ! $version_history) { |
|
423 | - $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
424 | - } |
|
425 | - if ($current_version_to_add == null) { |
|
426 | - $current_version_to_add = espresso_version(); |
|
427 | - } |
|
428 | - $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
429 | - // re-save |
|
430 | - return update_option('espresso_db_update', $version_history); |
|
431 | - } |
|
432 | - |
|
433 | - |
|
434 | - |
|
435 | - /** |
|
436 | - * Detects if the current version indicated in the has existed in the list of |
|
437 | - * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
438 | - * |
|
439 | - * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
440 | - * If not supplied, fetches it from the options table. |
|
441 | - * Also, caches its result so later parts of the code can also know whether |
|
442 | - * there's been an update or not. This way we can add the current version to |
|
443 | - * espresso_db_update, but still know if this is a new install or not |
|
444 | - * @return int one of the constants on EE_System::req_type_ |
|
445 | - */ |
|
446 | - public function detect_req_type($espresso_db_update = null) |
|
447 | - { |
|
448 | - if ($this->_req_type === null) { |
|
449 | - $espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update |
|
450 | - : $this->fix_espresso_db_upgrade_option(); |
|
451 | - $this->_req_type = $this->detect_req_type_given_activation_history($espresso_db_update, |
|
452 | - 'ee_espresso_activation', espresso_version()); |
|
453 | - $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
454 | - } |
|
455 | - return $this->_req_type; |
|
456 | - } |
|
457 | - |
|
458 | - |
|
459 | - |
|
460 | - /** |
|
461 | - * Returns whether or not there was a non-micro version change (ie, change in either |
|
462 | - * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
463 | - * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
464 | - * |
|
465 | - * @param $activation_history |
|
466 | - * @return bool |
|
467 | - */ |
|
468 | - protected function _detect_major_version_change($activation_history) |
|
469 | - { |
|
470 | - $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
471 | - $previous_version_parts = explode('.', $previous_version); |
|
472 | - $current_version_parts = explode('.', espresso_version()); |
|
473 | - return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
474 | - && ($previous_version_parts[0] !== $current_version_parts[0] |
|
475 | - || $previous_version_parts[1] !== $current_version_parts[1] |
|
476 | - ); |
|
477 | - } |
|
478 | - |
|
479 | - |
|
480 | - |
|
481 | - /** |
|
482 | - * Returns true if either the major or minor version of EE changed during this request. |
|
483 | - * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
484 | - * |
|
485 | - * @return bool |
|
486 | - */ |
|
487 | - public function is_major_version_change() |
|
488 | - { |
|
489 | - return $this->_major_version_change; |
|
490 | - } |
|
491 | - |
|
492 | - |
|
493 | - |
|
494 | - /** |
|
495 | - * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
496 | - * histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily |
|
497 | - * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
498 | - * just activated to (for core that will always be espresso_version()) |
|
499 | - * |
|
500 | - * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
501 | - * ee plugin. for core that's 'espresso_db_update' |
|
502 | - * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to |
|
503 | - * indicate that this plugin was just activated |
|
504 | - * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
505 | - * espresso_version()) |
|
506 | - * @return int one of the constants on EE_System::req_type_* |
|
507 | - */ |
|
508 | - public static function detect_req_type_given_activation_history( |
|
509 | - $activation_history_for_addon, |
|
510 | - $activation_indicator_option_name, |
|
511 | - $version_to_upgrade_to |
|
512 | - ) { |
|
513 | - $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
514 | - if ($activation_history_for_addon) { |
|
515 | - //it exists, so this isn't a completely new install |
|
516 | - //check if this version already in that list of previously installed versions |
|
517 | - if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
518 | - //it a version we haven't seen before |
|
519 | - if ($version_is_higher === 1) { |
|
520 | - $req_type = EE_System::req_type_upgrade; |
|
521 | - } else { |
|
522 | - $req_type = EE_System::req_type_downgrade; |
|
523 | - } |
|
524 | - delete_option($activation_indicator_option_name); |
|
525 | - } else { |
|
526 | - // its not an update. maybe a reactivation? |
|
527 | - if (get_option($activation_indicator_option_name, false)) { |
|
528 | - if ($version_is_higher === -1) { |
|
529 | - $req_type = EE_System::req_type_downgrade; |
|
530 | - } elseif ($version_is_higher === 0) { |
|
531 | - //we've seen this version before, but it's an activation. must be a reactivation |
|
532 | - $req_type = EE_System::req_type_reactivation; |
|
533 | - } else {//$version_is_higher === 1 |
|
534 | - $req_type = EE_System::req_type_upgrade; |
|
535 | - } |
|
536 | - delete_option($activation_indicator_option_name); |
|
537 | - } else { |
|
538 | - //we've seen this version before and the activation indicate doesn't show it was just activated |
|
539 | - if ($version_is_higher === -1) { |
|
540 | - $req_type = EE_System::req_type_downgrade; |
|
541 | - } elseif ($version_is_higher === 0) { |
|
542 | - //we've seen this version before and it's not an activation. its normal request |
|
543 | - $req_type = EE_System::req_type_normal; |
|
544 | - } else {//$version_is_higher === 1 |
|
545 | - $req_type = EE_System::req_type_upgrade; |
|
546 | - } |
|
547 | - } |
|
548 | - } |
|
549 | - } else { |
|
550 | - //brand new install |
|
551 | - $req_type = EE_System::req_type_new_activation; |
|
552 | - delete_option($activation_indicator_option_name); |
|
553 | - } |
|
554 | - return $req_type; |
|
555 | - } |
|
556 | - |
|
557 | - |
|
558 | - |
|
559 | - /** |
|
560 | - * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
561 | - * the $activation_history_for_addon |
|
562 | - * |
|
563 | - * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
564 | - * sometimes containing 'unknown-date' |
|
565 | - * @param string $version_to_upgrade_to (current version) |
|
566 | - * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
567 | - * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
568 | - * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
569 | - * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
570 | - */ |
|
571 | - protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
572 | - { |
|
573 | - //find the most recently-activated version |
|
574 | - $most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
575 | - return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
576 | - } |
|
577 | - |
|
578 | - |
|
579 | - |
|
580 | - /** |
|
581 | - * Gets the most recently active version listed in the activation history, |
|
582 | - * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
583 | - * |
|
584 | - * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
585 | - * sometimes containing 'unknown-date' |
|
586 | - * @return string |
|
587 | - */ |
|
588 | - protected static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
589 | - { |
|
590 | - $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
591 | - $most_recently_active_version = '0.0.0.dev.000'; |
|
592 | - if (is_array($activation_history)) { |
|
593 | - foreach ($activation_history as $version => $times_activated) { |
|
594 | - //check there is a record of when this version was activated. Otherwise, |
|
595 | - //mark it as unknown |
|
596 | - if ( ! $times_activated) { |
|
597 | - $times_activated = array('unknown-date'); |
|
598 | - } |
|
599 | - if (is_string($times_activated)) { |
|
600 | - $times_activated = array($times_activated); |
|
601 | - } |
|
602 | - foreach ($times_activated as $an_activation) { |
|
603 | - if ($an_activation != 'unknown-date' && $an_activation > $most_recently_active_version_activation) { |
|
604 | - $most_recently_active_version = $version; |
|
605 | - $most_recently_active_version_activation = $an_activation == 'unknown-date' |
|
606 | - ? '1970-01-01 00:00:00' : $an_activation; |
|
607 | - } |
|
608 | - } |
|
609 | - } |
|
610 | - } |
|
611 | - return $most_recently_active_version; |
|
612 | - } |
|
613 | - |
|
614 | - |
|
615 | - |
|
616 | - /** |
|
617 | - * This redirects to the about EE page after activation |
|
618 | - * |
|
619 | - * @return void |
|
620 | - */ |
|
621 | - public function redirect_to_about_ee() |
|
622 | - { |
|
623 | - $notices = EE_Error::get_notices(false); |
|
624 | - //if current user is an admin and it's not an ajax or rest request |
|
625 | - if ( |
|
626 | - ! (defined('DOING_AJAX') && DOING_AJAX) |
|
627 | - && ! (defined('REST_REQUEST') && REST_REQUEST) |
|
628 | - && ! isset($notices['errors']) |
|
629 | - && apply_filters( |
|
630 | - 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
631 | - $this->registry->CAP->current_user_can('manage_options', 'espresso_about_default') |
|
632 | - ) |
|
633 | - ) { |
|
634 | - $query_params = array('page' => 'espresso_about'); |
|
635 | - if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) { |
|
636 | - $query_params['new_activation'] = true; |
|
637 | - } |
|
638 | - if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) { |
|
639 | - $query_params['reactivation'] = true; |
|
640 | - } |
|
641 | - $url = add_query_arg($query_params, admin_url('admin.php')); |
|
642 | - wp_safe_redirect($url); |
|
643 | - exit(); |
|
644 | - } |
|
645 | - } |
|
646 | - |
|
647 | - |
|
648 | - |
|
649 | - /** |
|
650 | - * load_core_configuration |
|
651 | - * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
652 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
653 | - * |
|
654 | - * @return void |
|
655 | - */ |
|
656 | - public function load_core_configuration() |
|
657 | - { |
|
658 | - do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
659 | - $this->registry->load_core('EE_Load_Textdomain'); |
|
660 | - //load textdomain |
|
661 | - EE_Load_Textdomain::load_textdomain(); |
|
662 | - // load and setup EE_Config and EE_Network_Config |
|
663 | - $this->registry->load_core('Config'); |
|
664 | - $this->registry->load_core('Network_Config'); |
|
665 | - // setup autoloaders |
|
666 | - // enable logging? |
|
667 | - if ($this->registry->CFG->admin->use_full_logging) { |
|
668 | - $this->registry->load_core('Log'); |
|
669 | - } |
|
670 | - // check for activation errors |
|
671 | - $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
672 | - if ($activation_errors) { |
|
673 | - EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
674 | - update_option('ee_plugin_activation_errors', false); |
|
675 | - } |
|
676 | - // get model names |
|
677 | - $this->_parse_model_names(); |
|
678 | - //load caf stuff a chance to play during the activation process too. |
|
679 | - $this->_maybe_brew_regular(); |
|
680 | - do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
681 | - } |
|
682 | - |
|
683 | - |
|
684 | - |
|
685 | - /** |
|
686 | - * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
687 | - * |
|
688 | - * @return void |
|
689 | - */ |
|
690 | - private function _parse_model_names() |
|
691 | - { |
|
692 | - //get all the files in the EE_MODELS folder that end in .model.php |
|
693 | - $models = glob(EE_MODELS . '*.model.php'); |
|
694 | - $model_names = array(); |
|
695 | - $non_abstract_db_models = array(); |
|
696 | - foreach ($models as $model) { |
|
697 | - // get model classname |
|
698 | - $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
699 | - $short_name = str_replace('EEM_', '', $classname); |
|
700 | - $reflectionClass = new ReflectionClass($classname); |
|
701 | - if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
702 | - $non_abstract_db_models[$short_name] = $classname; |
|
703 | - } |
|
704 | - $model_names[$short_name] = $classname; |
|
705 | - } |
|
706 | - $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
707 | - $this->registry->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names', |
|
708 | - $non_abstract_db_models); |
|
709 | - } |
|
710 | - |
|
711 | - |
|
712 | - |
|
713 | - /** |
|
714 | - * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
715 | - * that need to be setup before our EE_System launches. |
|
716 | - * |
|
717 | - * @return void |
|
718 | - */ |
|
719 | - private function _maybe_brew_regular() |
|
720 | - { |
|
721 | - if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
722 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
723 | - } |
|
724 | - } |
|
725 | - |
|
726 | - |
|
727 | - |
|
728 | - /** |
|
729 | - * register_shortcodes_modules_and_widgets |
|
730 | - * generate lists of shortcodes and modules, then verify paths and classes |
|
731 | - * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
732 | - * which runs during the WP 'plugins_loaded' action at priority 7 |
|
733 | - * |
|
734 | - * @access public |
|
735 | - * @return void |
|
736 | - */ |
|
737 | - public function register_shortcodes_modules_and_widgets() |
|
738 | - { |
|
739 | - try { |
|
740 | - // load, register, and add shortcodes the new way |
|
741 | - new ShortcodesManager( |
|
742 | - // and the old way, but we'll put it under control of the new system |
|
743 | - EE_Config::getLegacyShortcodesManager() |
|
744 | - ); |
|
745 | - } catch (Exception $exception) { |
|
746 | - new ExceptionStackTraceDisplay($exception); |
|
747 | - } |
|
748 | - do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
749 | - // check for addons using old hookpoint |
|
750 | - if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
751 | - $this->_incompatible_addon_error(); |
|
752 | - } |
|
753 | - } |
|
754 | - |
|
755 | - |
|
756 | - |
|
757 | - /** |
|
758 | - * _incompatible_addon_error |
|
759 | - * |
|
760 | - * @access public |
|
761 | - * @return void |
|
762 | - */ |
|
763 | - private function _incompatible_addon_error() |
|
764 | - { |
|
765 | - // get array of classes hooking into here |
|
766 | - $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons'); |
|
767 | - if ( ! empty($class_names)) { |
|
768 | - $msg = __('The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
769 | - 'event_espresso'); |
|
770 | - $msg .= '<ul>'; |
|
771 | - foreach ($class_names as $class_name) { |
|
772 | - $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
773 | - $class_name) . '</b></li>'; |
|
774 | - } |
|
775 | - $msg .= '</ul>'; |
|
776 | - $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
777 | - 'event_espresso'); |
|
778 | - // save list of incompatible addons to wp-options for later use |
|
779 | - add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
780 | - if (is_admin()) { |
|
781 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
782 | - } |
|
783 | - } |
|
784 | - } |
|
785 | - |
|
786 | - |
|
787 | - |
|
788 | - /** |
|
789 | - * brew_espresso |
|
790 | - * begins the process of setting hooks for initializing EE in the correct order |
|
791 | - * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint |
|
792 | - * which runs during the WP 'plugins_loaded' action at priority 9 |
|
793 | - * |
|
794 | - * @return void |
|
795 | - */ |
|
796 | - public function brew_espresso() |
|
797 | - { |
|
798 | - do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
799 | - // load some final core systems |
|
800 | - add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
801 | - add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
802 | - add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
803 | - add_action('init', array($this, 'load_controllers'), 7); |
|
804 | - add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
805 | - add_action('init', array($this, 'initialize'), 10); |
|
806 | - add_action('init', array($this, 'initialize_last'), 100); |
|
807 | - add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100); |
|
808 | - if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
809 | - // pew pew pew |
|
810 | - $this->registry->load_core('PUE'); |
|
811 | - do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
812 | - } |
|
813 | - do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
814 | - } |
|
815 | - |
|
816 | - |
|
817 | - |
|
818 | - /** |
|
819 | - * set_hooks_for_core |
|
820 | - * |
|
821 | - * @access public |
|
822 | - * @return void |
|
823 | - */ |
|
824 | - public function set_hooks_for_core() |
|
825 | - { |
|
826 | - $this->_deactivate_incompatible_addons(); |
|
827 | - do_action('AHEE__EE_System__set_hooks_for_core'); |
|
828 | - } |
|
829 | - |
|
830 | - |
|
831 | - |
|
832 | - /** |
|
833 | - * Using the information gathered in EE_System::_incompatible_addon_error, |
|
834 | - * deactivates any addons considered incompatible with the current version of EE |
|
835 | - */ |
|
836 | - private function _deactivate_incompatible_addons() |
|
837 | - { |
|
838 | - $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
839 | - if ( ! empty($incompatible_addons)) { |
|
840 | - $active_plugins = get_option('active_plugins', array()); |
|
841 | - foreach ($active_plugins as $active_plugin) { |
|
842 | - foreach ($incompatible_addons as $incompatible_addon) { |
|
843 | - if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
844 | - unset($_GET['activate']); |
|
845 | - espresso_deactivate_plugin($active_plugin); |
|
846 | - } |
|
847 | - } |
|
848 | - } |
|
849 | - } |
|
850 | - } |
|
851 | - |
|
852 | - |
|
853 | - |
|
854 | - /** |
|
855 | - * perform_activations_upgrades_and_migrations |
|
856 | - * |
|
857 | - * @access public |
|
858 | - * @return void |
|
859 | - */ |
|
860 | - public function perform_activations_upgrades_and_migrations() |
|
861 | - { |
|
862 | - //first check if we had previously attempted to setup EE's directories but failed |
|
863 | - if (EEH_Activation::upload_directories_incomplete()) { |
|
864 | - EEH_Activation::create_upload_directories(); |
|
865 | - } |
|
866 | - do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
867 | - } |
|
868 | - |
|
869 | - |
|
870 | - |
|
871 | - /** |
|
872 | - * load_CPTs_and_session |
|
873 | - * |
|
874 | - * @access public |
|
875 | - * @return void |
|
876 | - */ |
|
877 | - public function load_CPTs_and_session() |
|
878 | - { |
|
879 | - do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
880 | - // register Custom Post Types |
|
881 | - $this->registry->load_core('Register_CPTs'); |
|
882 | - do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
883 | - } |
|
884 | - |
|
885 | - |
|
886 | - |
|
887 | - /** |
|
888 | - * load_controllers |
|
889 | - * this is the best place to load any additional controllers that needs access to EE core. |
|
890 | - * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
891 | - * time |
|
892 | - * |
|
893 | - * @access public |
|
894 | - * @return void |
|
895 | - */ |
|
896 | - public function load_controllers() |
|
897 | - { |
|
898 | - do_action('AHEE__EE_System__load_controllers__start'); |
|
899 | - // let's get it started |
|
900 | - if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
901 | - do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
902 | - $this->registry->load_core('Front_Controller'); |
|
903 | - } else if ( ! EE_FRONT_AJAX) { |
|
904 | - do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
905 | - EE_Registry::instance()->load_core('Admin'); |
|
906 | - } |
|
907 | - do_action('AHEE__EE_System__load_controllers__complete'); |
|
908 | - } |
|
909 | - |
|
910 | - |
|
911 | - |
|
912 | - /** |
|
913 | - * core_loaded_and_ready |
|
914 | - * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
915 | - * |
|
916 | - * @access public |
|
917 | - * @return void |
|
918 | - */ |
|
919 | - public function core_loaded_and_ready() |
|
920 | - { |
|
921 | - $this->registry->load_core('Session'); |
|
922 | - do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
923 | - // load_espresso_template_tags |
|
924 | - if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
925 | - require_once(EE_PUBLIC . 'template_tags.php'); |
|
926 | - } |
|
927 | - do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
928 | - $this->registry->create('EventEspresso\core\services\assets\Registry'); |
|
929 | - wp_enqueue_script('espresso_core'); |
|
930 | - } |
|
931 | - |
|
932 | - |
|
933 | - |
|
934 | - /** |
|
935 | - * initialize |
|
936 | - * this is the best place to begin initializing client code |
|
937 | - * |
|
938 | - * @access public |
|
939 | - * @return void |
|
940 | - */ |
|
941 | - public function initialize() |
|
942 | - { |
|
943 | - do_action('AHEE__EE_System__initialize'); |
|
944 | - } |
|
945 | - |
|
946 | - |
|
947 | - |
|
948 | - /** |
|
949 | - * initialize_last |
|
950 | - * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to |
|
951 | - * initialize has done so |
|
952 | - * |
|
953 | - * @access public |
|
954 | - * @return void |
|
955 | - */ |
|
956 | - public function initialize_last() |
|
957 | - { |
|
958 | - do_action('AHEE__EE_System__initialize_last'); |
|
959 | - } |
|
960 | - |
|
961 | - |
|
962 | - |
|
963 | - /** |
|
964 | - * set_hooks_for_shortcodes_modules_and_addons |
|
965 | - * this is the best place for other systems to set callbacks for hooking into other parts of EE |
|
966 | - * this happens at the very beginning of the wp_loaded hookpoint |
|
967 | - * |
|
968 | - * @access public |
|
969 | - * @return void |
|
970 | - */ |
|
971 | - public function set_hooks_for_shortcodes_modules_and_addons() |
|
972 | - { |
|
973 | - // do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' ); |
|
974 | - } |
|
975 | - |
|
976 | - |
|
977 | - |
|
978 | - /** |
|
979 | - * do_not_cache |
|
980 | - * sets no cache headers and defines no cache constants for WP plugins |
|
981 | - * |
|
982 | - * @access public |
|
983 | - * @return void |
|
984 | - */ |
|
985 | - public static function do_not_cache() |
|
986 | - { |
|
987 | - // set no cache constants |
|
988 | - if ( ! defined('DONOTCACHEPAGE')) { |
|
989 | - define('DONOTCACHEPAGE', true); |
|
990 | - } |
|
991 | - if ( ! defined('DONOTCACHCEOBJECT')) { |
|
992 | - define('DONOTCACHCEOBJECT', true); |
|
993 | - } |
|
994 | - if ( ! defined('DONOTCACHEDB')) { |
|
995 | - define('DONOTCACHEDB', true); |
|
996 | - } |
|
997 | - // add no cache headers |
|
998 | - add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
999 | - // plus a little extra for nginx and Google Chrome |
|
1000 | - add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
1001 | - // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
1002 | - remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
1003 | - } |
|
1004 | - |
|
1005 | - |
|
1006 | - |
|
1007 | - /** |
|
1008 | - * extra_nocache_headers |
|
1009 | - * |
|
1010 | - * @access public |
|
1011 | - * @param $headers |
|
1012 | - * @return array |
|
1013 | - */ |
|
1014 | - public static function extra_nocache_headers($headers) |
|
1015 | - { |
|
1016 | - // for NGINX |
|
1017 | - $headers['X-Accel-Expires'] = 0; |
|
1018 | - // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
1019 | - $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
1020 | - return $headers; |
|
1021 | - } |
|
1022 | - |
|
1023 | - |
|
1024 | - |
|
1025 | - /** |
|
1026 | - * nocache_headers |
|
1027 | - * |
|
1028 | - * @access public |
|
1029 | - * @return void |
|
1030 | - */ |
|
1031 | - public static function nocache_headers() |
|
1032 | - { |
|
1033 | - nocache_headers(); |
|
1034 | - } |
|
1035 | - |
|
1036 | - |
|
1037 | - |
|
1038 | - /** |
|
1039 | - * espresso_toolbar_items |
|
1040 | - * |
|
1041 | - * @access public |
|
1042 | - * @param WP_Admin_Bar $admin_bar |
|
1043 | - * @return void |
|
1044 | - */ |
|
1045 | - public function espresso_toolbar_items(WP_Admin_Bar $admin_bar) |
|
1046 | - { |
|
1047 | - // if in full M-Mode, or its an AJAX request, or user is NOT an admin |
|
1048 | - if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance |
|
1049 | - || defined('DOING_AJAX') |
|
1050 | - || ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level') |
|
1051 | - ) { |
|
1052 | - return; |
|
1053 | - } |
|
1054 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1055 | - $menu_class = 'espresso_menu_item_class'; |
|
1056 | - //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
|
1057 | - //because they're only defined in each of their respective constructors |
|
1058 | - //and this might be a frontend request, in which case they aren't available |
|
1059 | - $events_admin_url = admin_url("admin.php?page=espresso_events"); |
|
1060 | - $reg_admin_url = admin_url("admin.php?page=espresso_registrations"); |
|
1061 | - $extensions_admin_url = admin_url("admin.php?page=espresso_packages"); |
|
1062 | - //Top Level |
|
1063 | - $admin_bar->add_menu(array( |
|
1064 | - 'id' => 'espresso-toolbar', |
|
1065 | - 'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' |
|
1066 | - . _x('Event Espresso', 'admin bar menu group label', 'event_espresso') |
|
1067 | - . '</span>', |
|
1068 | - 'href' => $events_admin_url, |
|
1069 | - 'meta' => array( |
|
1070 | - 'title' => __('Event Espresso', 'event_espresso'), |
|
1071 | - 'class' => $menu_class . 'first', |
|
1072 | - ), |
|
1073 | - )); |
|
1074 | - //Events |
|
1075 | - if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) { |
|
1076 | - $admin_bar->add_menu(array( |
|
1077 | - 'id' => 'espresso-toolbar-events', |
|
1078 | - 'parent' => 'espresso-toolbar', |
|
1079 | - 'title' => __('Events', 'event_espresso'), |
|
1080 | - 'href' => $events_admin_url, |
|
1081 | - 'meta' => array( |
|
1082 | - 'title' => __('Events', 'event_espresso'), |
|
1083 | - 'target' => '', |
|
1084 | - 'class' => $menu_class, |
|
1085 | - ), |
|
1086 | - )); |
|
1087 | - } |
|
1088 | - if ($this->registry->CAP->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) { |
|
1089 | - //Events Add New |
|
1090 | - $admin_bar->add_menu(array( |
|
1091 | - 'id' => 'espresso-toolbar-events-new', |
|
1092 | - 'parent' => 'espresso-toolbar-events', |
|
1093 | - 'title' => __('Add New', 'event_espresso'), |
|
1094 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url), |
|
1095 | - 'meta' => array( |
|
1096 | - 'title' => __('Add New', 'event_espresso'), |
|
1097 | - 'target' => '', |
|
1098 | - 'class' => $menu_class, |
|
1099 | - ), |
|
1100 | - )); |
|
1101 | - } |
|
1102 | - if (is_single() && (get_post_type() == 'espresso_events')) { |
|
1103 | - //Current post |
|
1104 | - global $post; |
|
1105 | - if ($this->registry->CAP->current_user_can('ee_edit_event', |
|
1106 | - 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID) |
|
1107 | - ) { |
|
1108 | - //Events Edit Current Event |
|
1109 | - $admin_bar->add_menu(array( |
|
1110 | - 'id' => 'espresso-toolbar-events-edit', |
|
1111 | - 'parent' => 'espresso-toolbar-events', |
|
1112 | - 'title' => __('Edit Event', 'event_espresso'), |
|
1113 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID), |
|
1114 | - $events_admin_url), |
|
1115 | - 'meta' => array( |
|
1116 | - 'title' => __('Edit Event', 'event_espresso'), |
|
1117 | - 'target' => '', |
|
1118 | - 'class' => $menu_class, |
|
1119 | - ), |
|
1120 | - )); |
|
1121 | - } |
|
1122 | - } |
|
1123 | - //Events View |
|
1124 | - if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1125 | - 'ee_admin_bar_menu_espresso-toolbar-events-view') |
|
1126 | - ) { |
|
1127 | - $admin_bar->add_menu(array( |
|
1128 | - 'id' => 'espresso-toolbar-events-view', |
|
1129 | - 'parent' => 'espresso-toolbar-events', |
|
1130 | - 'title' => __('View', 'event_espresso'), |
|
1131 | - 'href' => $events_admin_url, |
|
1132 | - 'meta' => array( |
|
1133 | - 'title' => __('View', 'event_espresso'), |
|
1134 | - 'target' => '', |
|
1135 | - 'class' => $menu_class, |
|
1136 | - ), |
|
1137 | - )); |
|
1138 | - } |
|
1139 | - if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) { |
|
1140 | - //Events View All |
|
1141 | - $admin_bar->add_menu(array( |
|
1142 | - 'id' => 'espresso-toolbar-events-all', |
|
1143 | - 'parent' => 'espresso-toolbar-events-view', |
|
1144 | - 'title' => __('All', 'event_espresso'), |
|
1145 | - 'href' => $events_admin_url, |
|
1146 | - 'meta' => array( |
|
1147 | - 'title' => __('All', 'event_espresso'), |
|
1148 | - 'target' => '', |
|
1149 | - 'class' => $menu_class, |
|
1150 | - ), |
|
1151 | - )); |
|
1152 | - } |
|
1153 | - if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1154 | - 'ee_admin_bar_menu_espresso-toolbar-events-today') |
|
1155 | - ) { |
|
1156 | - //Events View Today |
|
1157 | - $admin_bar->add_menu(array( |
|
1158 | - 'id' => 'espresso-toolbar-events-today', |
|
1159 | - 'parent' => 'espresso-toolbar-events-view', |
|
1160 | - 'title' => __('Today', 'event_espresso'), |
|
1161 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
1162 | - $events_admin_url), |
|
1163 | - 'meta' => array( |
|
1164 | - 'title' => __('Today', 'event_espresso'), |
|
1165 | - 'target' => '', |
|
1166 | - 'class' => $menu_class, |
|
1167 | - ), |
|
1168 | - )); |
|
1169 | - } |
|
1170 | - if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1171 | - 'ee_admin_bar_menu_espresso-toolbar-events-month') |
|
1172 | - ) { |
|
1173 | - //Events View This Month |
|
1174 | - $admin_bar->add_menu(array( |
|
1175 | - 'id' => 'espresso-toolbar-events-month', |
|
1176 | - 'parent' => 'espresso-toolbar-events-view', |
|
1177 | - 'title' => __('This Month', 'event_espresso'), |
|
1178 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
1179 | - $events_admin_url), |
|
1180 | - 'meta' => array( |
|
1181 | - 'title' => __('This Month', 'event_espresso'), |
|
1182 | - 'target' => '', |
|
1183 | - 'class' => $menu_class, |
|
1184 | - ), |
|
1185 | - )); |
|
1186 | - } |
|
1187 | - //Registration Overview |
|
1188 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1189 | - 'ee_admin_bar_menu_espresso-toolbar-registrations') |
|
1190 | - ) { |
|
1191 | - $admin_bar->add_menu(array( |
|
1192 | - 'id' => 'espresso-toolbar-registrations', |
|
1193 | - 'parent' => 'espresso-toolbar', |
|
1194 | - 'title' => __('Registrations', 'event_espresso'), |
|
1195 | - 'href' => $reg_admin_url, |
|
1196 | - 'meta' => array( |
|
1197 | - 'title' => __('Registrations', 'event_espresso'), |
|
1198 | - 'target' => '', |
|
1199 | - 'class' => $menu_class, |
|
1200 | - ), |
|
1201 | - )); |
|
1202 | - } |
|
1203 | - //Registration Overview Today |
|
1204 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1205 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today') |
|
1206 | - ) { |
|
1207 | - $admin_bar->add_menu(array( |
|
1208 | - 'id' => 'espresso-toolbar-registrations-today', |
|
1209 | - 'parent' => 'espresso-toolbar-registrations', |
|
1210 | - 'title' => __('Today', 'event_espresso'), |
|
1211 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
1212 | - $reg_admin_url), |
|
1213 | - 'meta' => array( |
|
1214 | - 'title' => __('Today', 'event_espresso'), |
|
1215 | - 'target' => '', |
|
1216 | - 'class' => $menu_class, |
|
1217 | - ), |
|
1218 | - )); |
|
1219 | - } |
|
1220 | - //Registration Overview Today Completed |
|
1221 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1222 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved') |
|
1223 | - ) { |
|
1224 | - $admin_bar->add_menu(array( |
|
1225 | - 'id' => 'espresso-toolbar-registrations-today-approved', |
|
1226 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
1227 | - 'title' => __('Approved', 'event_espresso'), |
|
1228 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1229 | - 'action' => 'default', |
|
1230 | - 'status' => 'today', |
|
1231 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
1232 | - ), $reg_admin_url), |
|
1233 | - 'meta' => array( |
|
1234 | - 'title' => __('Approved', 'event_espresso'), |
|
1235 | - 'target' => '', |
|
1236 | - 'class' => $menu_class, |
|
1237 | - ), |
|
1238 | - )); |
|
1239 | - } |
|
1240 | - //Registration Overview Today Pending\ |
|
1241 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1242 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending') |
|
1243 | - ) { |
|
1244 | - $admin_bar->add_menu(array( |
|
1245 | - 'id' => 'espresso-toolbar-registrations-today-pending', |
|
1246 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
1247 | - 'title' => __('Pending', 'event_espresso'), |
|
1248 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1249 | - 'action' => 'default', |
|
1250 | - 'status' => 'today', |
|
1251 | - 'reg_status' => EEM_Registration::status_id_pending_payment, |
|
1252 | - ), $reg_admin_url), |
|
1253 | - 'meta' => array( |
|
1254 | - 'title' => __('Pending Payment', 'event_espresso'), |
|
1255 | - 'target' => '', |
|
1256 | - 'class' => $menu_class, |
|
1257 | - ), |
|
1258 | - )); |
|
1259 | - } |
|
1260 | - //Registration Overview Today Incomplete |
|
1261 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1262 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved') |
|
1263 | - ) { |
|
1264 | - $admin_bar->add_menu(array( |
|
1265 | - 'id' => 'espresso-toolbar-registrations-today-not-approved', |
|
1266 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
1267 | - 'title' => __('Not Approved', 'event_espresso'), |
|
1268 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1269 | - 'action' => 'default', |
|
1270 | - 'status' => 'today', |
|
1271 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1272 | - ), $reg_admin_url), |
|
1273 | - 'meta' => array( |
|
1274 | - 'title' => __('Not Approved', 'event_espresso'), |
|
1275 | - 'target' => '', |
|
1276 | - 'class' => $menu_class, |
|
1277 | - ), |
|
1278 | - )); |
|
1279 | - } |
|
1280 | - //Registration Overview Today Incomplete |
|
1281 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1282 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled') |
|
1283 | - ) { |
|
1284 | - $admin_bar->add_menu(array( |
|
1285 | - 'id' => 'espresso-toolbar-registrations-today-cancelled', |
|
1286 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
1287 | - 'title' => __('Cancelled', 'event_espresso'), |
|
1288 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1289 | - 'action' => 'default', |
|
1290 | - 'status' => 'today', |
|
1291 | - '_reg_status' => EEM_Registration::status_id_cancelled, |
|
1292 | - ), $reg_admin_url), |
|
1293 | - 'meta' => array( |
|
1294 | - 'title' => __('Cancelled', 'event_espresso'), |
|
1295 | - 'target' => '', |
|
1296 | - 'class' => $menu_class, |
|
1297 | - ), |
|
1298 | - )); |
|
1299 | - } |
|
1300 | - //Registration Overview This Month |
|
1301 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1302 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month') |
|
1303 | - ) { |
|
1304 | - $admin_bar->add_menu(array( |
|
1305 | - 'id' => 'espresso-toolbar-registrations-month', |
|
1306 | - 'parent' => 'espresso-toolbar-registrations', |
|
1307 | - 'title' => __('This Month', 'event_espresso'), |
|
1308 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
1309 | - $reg_admin_url), |
|
1310 | - 'meta' => array( |
|
1311 | - 'title' => __('This Month', 'event_espresso'), |
|
1312 | - 'target' => '', |
|
1313 | - 'class' => $menu_class, |
|
1314 | - ), |
|
1315 | - )); |
|
1316 | - } |
|
1317 | - //Registration Overview This Month Approved |
|
1318 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1319 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved') |
|
1320 | - ) { |
|
1321 | - $admin_bar->add_menu(array( |
|
1322 | - 'id' => 'espresso-toolbar-registrations-month-approved', |
|
1323 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
1324 | - 'title' => __('Approved', 'event_espresso'), |
|
1325 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1326 | - 'action' => 'default', |
|
1327 | - 'status' => 'month', |
|
1328 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
1329 | - ), $reg_admin_url), |
|
1330 | - 'meta' => array( |
|
1331 | - 'title' => __('Approved', 'event_espresso'), |
|
1332 | - 'target' => '', |
|
1333 | - 'class' => $menu_class, |
|
1334 | - ), |
|
1335 | - )); |
|
1336 | - } |
|
1337 | - //Registration Overview This Month Pending |
|
1338 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1339 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending') |
|
1340 | - ) { |
|
1341 | - $admin_bar->add_menu(array( |
|
1342 | - 'id' => 'espresso-toolbar-registrations-month-pending', |
|
1343 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
1344 | - 'title' => __('Pending', 'event_espresso'), |
|
1345 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1346 | - 'action' => 'default', |
|
1347 | - 'status' => 'month', |
|
1348 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
1349 | - ), $reg_admin_url), |
|
1350 | - 'meta' => array( |
|
1351 | - 'title' => __('Pending', 'event_espresso'), |
|
1352 | - 'target' => '', |
|
1353 | - 'class' => $menu_class, |
|
1354 | - ), |
|
1355 | - )); |
|
1356 | - } |
|
1357 | - //Registration Overview This Month Not Approved |
|
1358 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1359 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved') |
|
1360 | - ) { |
|
1361 | - $admin_bar->add_menu(array( |
|
1362 | - 'id' => 'espresso-toolbar-registrations-month-not-approved', |
|
1363 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
1364 | - 'title' => __('Not Approved', 'event_espresso'), |
|
1365 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1366 | - 'action' => 'default', |
|
1367 | - 'status' => 'month', |
|
1368 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1369 | - ), $reg_admin_url), |
|
1370 | - 'meta' => array( |
|
1371 | - 'title' => __('Not Approved', 'event_espresso'), |
|
1372 | - 'target' => '', |
|
1373 | - 'class' => $menu_class, |
|
1374 | - ), |
|
1375 | - )); |
|
1376 | - } |
|
1377 | - //Registration Overview This Month Cancelled |
|
1378 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1379 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled') |
|
1380 | - ) { |
|
1381 | - $admin_bar->add_menu(array( |
|
1382 | - 'id' => 'espresso-toolbar-registrations-month-cancelled', |
|
1383 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
1384 | - 'title' => __('Cancelled', 'event_espresso'), |
|
1385 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1386 | - 'action' => 'default', |
|
1387 | - 'status' => 'month', |
|
1388 | - '_reg_status' => EEM_Registration::status_id_cancelled, |
|
1389 | - ), $reg_admin_url), |
|
1390 | - 'meta' => array( |
|
1391 | - 'title' => __('Cancelled', 'event_espresso'), |
|
1392 | - 'target' => '', |
|
1393 | - 'class' => $menu_class, |
|
1394 | - ), |
|
1395 | - )); |
|
1396 | - } |
|
1397 | - //Extensions & Services |
|
1398 | - if ($this->registry->CAP->current_user_can('ee_read_ee', |
|
1399 | - 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services') |
|
1400 | - ) { |
|
1401 | - $admin_bar->add_menu(array( |
|
1402 | - 'id' => 'espresso-toolbar-extensions-and-services', |
|
1403 | - 'parent' => 'espresso-toolbar', |
|
1404 | - 'title' => __('Extensions & Services', 'event_espresso'), |
|
1405 | - 'href' => $extensions_admin_url, |
|
1406 | - 'meta' => array( |
|
1407 | - 'title' => __('Extensions & Services', 'event_espresso'), |
|
1408 | - 'target' => '', |
|
1409 | - 'class' => $menu_class, |
|
1410 | - ), |
|
1411 | - )); |
|
1412 | - } |
|
1413 | - } |
|
1414 | - |
|
1415 | - |
|
1416 | - |
|
1417 | - /** |
|
1418 | - * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
1419 | - * never returned with the function. |
|
1420 | - * |
|
1421 | - * @param array $exclude_array any existing pages being excluded are in this array. |
|
1422 | - * @return array |
|
1423 | - */ |
|
1424 | - public function remove_pages_from_wp_list_pages($exclude_array) |
|
1425 | - { |
|
1426 | - return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
1427 | - } |
|
22 | + /** |
|
23 | + * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
24 | + * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
25 | + */ |
|
26 | + const req_type_normal = 0; |
|
27 | + |
|
28 | + /** |
|
29 | + * Indicates this is a brand new installation of EE so we should install |
|
30 | + * tables and default data etc |
|
31 | + */ |
|
32 | + const req_type_new_activation = 1; |
|
33 | + |
|
34 | + /** |
|
35 | + * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
36 | + * and we just exited maintenance mode). We MUST check the database is setup properly |
|
37 | + * and that default data is setup too |
|
38 | + */ |
|
39 | + const req_type_reactivation = 2; |
|
40 | + |
|
41 | + /** |
|
42 | + * indicates that EE has been upgraded since its previous request. |
|
43 | + * We may have data migration scripts to call and will want to trigger maintenance mode |
|
44 | + */ |
|
45 | + const req_type_upgrade = 3; |
|
46 | + |
|
47 | + /** |
|
48 | + * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
49 | + */ |
|
50 | + const req_type_downgrade = 4; |
|
51 | + |
|
52 | + /** |
|
53 | + * @deprecated since version 4.6.0.dev.006 |
|
54 | + * Now whenever a new_activation is detected the request type is still just |
|
55 | + * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
56 | + * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
57 | + * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
58 | + * (Specifically, when the migration manager indicates migrations are finished |
|
59 | + * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
60 | + */ |
|
61 | + const req_type_activation_but_not_installed = 5; |
|
62 | + |
|
63 | + /** |
|
64 | + * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
65 | + */ |
|
66 | + const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * instance of the EE_System object |
|
71 | + * |
|
72 | + * @var $_instance |
|
73 | + * @access private |
|
74 | + */ |
|
75 | + private static $_instance = null; |
|
76 | + |
|
77 | + /** |
|
78 | + * @type EE_Registry $Registry |
|
79 | + * @access protected |
|
80 | + */ |
|
81 | + protected $registry; |
|
82 | + |
|
83 | + /** |
|
84 | + * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
85 | + * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
86 | + * |
|
87 | + * @var int |
|
88 | + */ |
|
89 | + private $_req_type; |
|
90 | + |
|
91 | + /** |
|
92 | + * Whether or not there was a non-micro version change in EE core version during this request |
|
93 | + * |
|
94 | + * @var boolean |
|
95 | + */ |
|
96 | + private $_major_version_change = false; |
|
97 | + |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * @singleton method used to instantiate class object |
|
102 | + * @access public |
|
103 | + * @param \EE_Registry $Registry |
|
104 | + * @return \EE_System |
|
105 | + */ |
|
106 | + public static function instance(EE_Registry $Registry = null) |
|
107 | + { |
|
108 | + // check if class object is instantiated |
|
109 | + if ( ! self::$_instance instanceof EE_System) { |
|
110 | + self::$_instance = new self($Registry); |
|
111 | + } |
|
112 | + return self::$_instance; |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * resets the instance and returns it |
|
119 | + * |
|
120 | + * @return EE_System |
|
121 | + */ |
|
122 | + public static function reset() |
|
123 | + { |
|
124 | + self::$_instance->_req_type = null; |
|
125 | + //make sure none of the old hooks are left hanging around |
|
126 | + remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
127 | + //we need to reset the migration manager in order for it to detect DMSs properly |
|
128 | + EE_Data_Migration_Manager::reset(); |
|
129 | + self::instance()->detect_activations_or_upgrades(); |
|
130 | + self::instance()->perform_activations_upgrades_and_migrations(); |
|
131 | + return self::instance(); |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * sets hooks for running rest of system |
|
138 | + * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
139 | + * starting EE Addons from any other point may lead to problems |
|
140 | + * |
|
141 | + * @access private |
|
142 | + * @param \EE_Registry $Registry |
|
143 | + */ |
|
144 | + private function __construct(EE_Registry $Registry) |
|
145 | + { |
|
146 | + $this->registry = $Registry; |
|
147 | + do_action('AHEE__EE_System__construct__begin', $this); |
|
148 | + // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
149 | + add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons')); |
|
150 | + // when an ee addon is activated, we want to call the core hook(s) again |
|
151 | + // because the newly-activated addon didn't get a chance to run at all |
|
152 | + add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
153 | + // detect whether install or upgrade |
|
154 | + add_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'), |
|
155 | + 3); |
|
156 | + // load EE_Config, EE_Textdomain, etc |
|
157 | + add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5); |
|
158 | + // load EE_Config, EE_Textdomain, etc |
|
159 | + add_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
160 | + array($this, 'register_shortcodes_modules_and_widgets'), 7); |
|
161 | + // you wanna get going? I wanna get going... let's get going! |
|
162 | + add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9); |
|
163 | + //other housekeeping |
|
164 | + //exclude EE critical pages from wp_list_pages |
|
165 | + add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10); |
|
166 | + // ALL EE Addons should use the following hook point to attach their initial setup too |
|
167 | + // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
168 | + do_action('AHEE__EE_System__construct__complete', $this); |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * load_espresso_addons |
|
175 | + * allow addons to load first so that they can set hooks for running DMS's, etc |
|
176 | + * this is hooked into both: |
|
177 | + * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
178 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
179 | + * and the WP 'activate_plugin' hookpoint |
|
180 | + * |
|
181 | + * @access public |
|
182 | + * @return void |
|
183 | + */ |
|
184 | + public function load_espresso_addons() |
|
185 | + { |
|
186 | + // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
187 | + // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
188 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
189 | + //load and setup EE_Capabilities |
|
190 | + $this->registry->load_core('Capabilities'); |
|
191 | + //caps need to be initialized on every request so that capability maps are set. |
|
192 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
193 | + $this->registry->CAP->init_caps(); |
|
194 | + do_action('AHEE__EE_System__load_espresso_addons'); |
|
195 | + //if the WP API basic auth plugin isn't already loaded, load it now. |
|
196 | + //We want it for mobile apps. Just include the entire plugin |
|
197 | + //also, don't load the basic auth when a plugin is getting activated, because |
|
198 | + //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
199 | + //and causes a fatal error |
|
200 | + if ( ! function_exists('json_basic_auth_handler') |
|
201 | + && ! function_exists('json_basic_auth_error') |
|
202 | + && ! ( |
|
203 | + isset($_GET['action']) |
|
204 | + && in_array($_GET['action'], array('activate', 'activate-selected')) |
|
205 | + ) |
|
206 | + && ! ( |
|
207 | + isset($_GET['activate']) |
|
208 | + && $_GET['activate'] === 'true' |
|
209 | + ) |
|
210 | + ) { |
|
211 | + include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
212 | + } |
|
213 | + do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
214 | + } |
|
215 | + |
|
216 | + |
|
217 | + |
|
218 | + /** |
|
219 | + * detect_activations_or_upgrades |
|
220 | + * Checks for activation or upgrade of core first; |
|
221 | + * then also checks if any registered addons have been activated or upgraded |
|
222 | + * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
223 | + * which runs during the WP 'plugins_loaded' action at priority 3 |
|
224 | + * |
|
225 | + * @access public |
|
226 | + * @return void |
|
227 | + */ |
|
228 | + public function detect_activations_or_upgrades() |
|
229 | + { |
|
230 | + //first off: let's make sure to handle core |
|
231 | + $this->detect_if_activation_or_upgrade(); |
|
232 | + foreach ($this->registry->addons as $addon) { |
|
233 | + //detect teh request type for that addon |
|
234 | + $addon->detect_activation_or_upgrade(); |
|
235 | + } |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * detect_if_activation_or_upgrade |
|
242 | + * Takes care of detecting whether this is a brand new install or code upgrade, |
|
243 | + * and either setting up the DB or setting up maintenance mode etc. |
|
244 | + * |
|
245 | + * @access public |
|
246 | + * @return void |
|
247 | + */ |
|
248 | + public function detect_if_activation_or_upgrade() |
|
249 | + { |
|
250 | + do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
251 | + // load M-Mode class |
|
252 | + $this->registry->load_core('Maintenance_Mode'); |
|
253 | + // check if db has been updated, or if its a brand-new installation |
|
254 | + $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
255 | + $request_type = $this->detect_req_type($espresso_db_update); |
|
256 | + //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
257 | + switch ($request_type) { |
|
258 | + case EE_System::req_type_new_activation: |
|
259 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
260 | + $this->_handle_core_version_change($espresso_db_update); |
|
261 | + break; |
|
262 | + case EE_System::req_type_reactivation: |
|
263 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
264 | + $this->_handle_core_version_change($espresso_db_update); |
|
265 | + break; |
|
266 | + case EE_System::req_type_upgrade: |
|
267 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
268 | + //migrations may be required now that we've upgraded |
|
269 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
270 | + $this->_handle_core_version_change($espresso_db_update); |
|
271 | + // echo "done upgrade";die; |
|
272 | + break; |
|
273 | + case EE_System::req_type_downgrade: |
|
274 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
275 | + //its possible migrations are no longer required |
|
276 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
277 | + $this->_handle_core_version_change($espresso_db_update); |
|
278 | + break; |
|
279 | + case EE_System::req_type_normal: |
|
280 | + default: |
|
281 | + // $this->_maybe_redirect_to_ee_about(); |
|
282 | + break; |
|
283 | + } |
|
284 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
285 | + } |
|
286 | + |
|
287 | + |
|
288 | + |
|
289 | + /** |
|
290 | + * Updates the list of installed versions and sets hooks for |
|
291 | + * initializing the database later during the request |
|
292 | + * |
|
293 | + * @param array $espresso_db_update |
|
294 | + */ |
|
295 | + protected function _handle_core_version_change($espresso_db_update) |
|
296 | + { |
|
297 | + $this->update_list_of_installed_versions($espresso_db_update); |
|
298 | + //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
299 | + add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
300 | + array($this, 'initialize_db_if_no_migrations_required')); |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
307 | + * information about what versions of EE have been installed and activated, |
|
308 | + * NOT necessarily the state of the database |
|
309 | + * |
|
310 | + * @param null $espresso_db_update |
|
311 | + * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it |
|
312 | + * from the options table |
|
313 | + * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
314 | + */ |
|
315 | + private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
316 | + { |
|
317 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
318 | + if ( ! $espresso_db_update) { |
|
319 | + $espresso_db_update = get_option('espresso_db_update'); |
|
320 | + } |
|
321 | + // check that option is an array |
|
322 | + if ( ! is_array($espresso_db_update)) { |
|
323 | + // if option is FALSE, then it never existed |
|
324 | + if ($espresso_db_update === false) { |
|
325 | + // make $espresso_db_update an array and save option with autoload OFF |
|
326 | + $espresso_db_update = array(); |
|
327 | + add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
328 | + } else { |
|
329 | + // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
330 | + $espresso_db_update = array($espresso_db_update => array()); |
|
331 | + update_option('espresso_db_update', $espresso_db_update); |
|
332 | + } |
|
333 | + } else { |
|
334 | + $corrected_db_update = array(); |
|
335 | + //if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
336 | + foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
337 | + if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
338 | + //the key is an int, and the value IS NOT an array |
|
339 | + //so it must be numerically-indexed, where values are versions installed... |
|
340 | + //fix it! |
|
341 | + $version_string = $should_be_array; |
|
342 | + $corrected_db_update[$version_string] = array('unknown-date'); |
|
343 | + } else { |
|
344 | + //ok it checks out |
|
345 | + $corrected_db_update[$should_be_version_string] = $should_be_array; |
|
346 | + } |
|
347 | + } |
|
348 | + $espresso_db_update = $corrected_db_update; |
|
349 | + update_option('espresso_db_update', $espresso_db_update); |
|
350 | + } |
|
351 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
352 | + return $espresso_db_update; |
|
353 | + } |
|
354 | + |
|
355 | + |
|
356 | + |
|
357 | + /** |
|
358 | + * Does the traditional work of setting up the plugin's database and adding default data. |
|
359 | + * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
360 | + * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
361 | + * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
362 | + * so that it will be done when migrations are finished |
|
363 | + * |
|
364 | + * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
365 | + * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
366 | + * This is a resource-intensive job |
|
367 | + * so we prefer to only do it when necessary |
|
368 | + * @return void |
|
369 | + */ |
|
370 | + public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
371 | + { |
|
372 | + $request_type = $this->detect_req_type(); |
|
373 | + //only initialize system if we're not in maintenance mode. |
|
374 | + if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
375 | + update_option('ee_flush_rewrite_rules', true); |
|
376 | + if ($verify_schema) { |
|
377 | + EEH_Activation::initialize_db_and_folders(); |
|
378 | + } |
|
379 | + EEH_Activation::initialize_db_content(); |
|
380 | + EEH_Activation::system_initialization(); |
|
381 | + if ($initialize_addons_too) { |
|
382 | + $this->initialize_addons(); |
|
383 | + } |
|
384 | + } else { |
|
385 | + EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
386 | + } |
|
387 | + if ($request_type === EE_System::req_type_new_activation |
|
388 | + || $request_type === EE_System::req_type_reactivation |
|
389 | + || ( |
|
390 | + $request_type === EE_System::req_type_upgrade |
|
391 | + && $this->is_major_version_change() |
|
392 | + ) |
|
393 | + ) { |
|
394 | + add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
395 | + } |
|
396 | + } |
|
397 | + |
|
398 | + |
|
399 | + |
|
400 | + /** |
|
401 | + * Initializes the db for all registered addons |
|
402 | + */ |
|
403 | + public function initialize_addons() |
|
404 | + { |
|
405 | + //foreach registered addon, make sure its db is up-to-date too |
|
406 | + foreach ($this->registry->addons as $addon) { |
|
407 | + $addon->initialize_db_if_no_migrations_required(); |
|
408 | + } |
|
409 | + } |
|
410 | + |
|
411 | + |
|
412 | + |
|
413 | + /** |
|
414 | + * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
415 | + * |
|
416 | + * @param array $version_history |
|
417 | + * @param string $current_version_to_add version to be added to the version history |
|
418 | + * @return boolean success as to whether or not this option was changed |
|
419 | + */ |
|
420 | + public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
421 | + { |
|
422 | + if ( ! $version_history) { |
|
423 | + $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
424 | + } |
|
425 | + if ($current_version_to_add == null) { |
|
426 | + $current_version_to_add = espresso_version(); |
|
427 | + } |
|
428 | + $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
429 | + // re-save |
|
430 | + return update_option('espresso_db_update', $version_history); |
|
431 | + } |
|
432 | + |
|
433 | + |
|
434 | + |
|
435 | + /** |
|
436 | + * Detects if the current version indicated in the has existed in the list of |
|
437 | + * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
438 | + * |
|
439 | + * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
440 | + * If not supplied, fetches it from the options table. |
|
441 | + * Also, caches its result so later parts of the code can also know whether |
|
442 | + * there's been an update or not. This way we can add the current version to |
|
443 | + * espresso_db_update, but still know if this is a new install or not |
|
444 | + * @return int one of the constants on EE_System::req_type_ |
|
445 | + */ |
|
446 | + public function detect_req_type($espresso_db_update = null) |
|
447 | + { |
|
448 | + if ($this->_req_type === null) { |
|
449 | + $espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update |
|
450 | + : $this->fix_espresso_db_upgrade_option(); |
|
451 | + $this->_req_type = $this->detect_req_type_given_activation_history($espresso_db_update, |
|
452 | + 'ee_espresso_activation', espresso_version()); |
|
453 | + $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
454 | + } |
|
455 | + return $this->_req_type; |
|
456 | + } |
|
457 | + |
|
458 | + |
|
459 | + |
|
460 | + /** |
|
461 | + * Returns whether or not there was a non-micro version change (ie, change in either |
|
462 | + * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
463 | + * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
464 | + * |
|
465 | + * @param $activation_history |
|
466 | + * @return bool |
|
467 | + */ |
|
468 | + protected function _detect_major_version_change($activation_history) |
|
469 | + { |
|
470 | + $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
471 | + $previous_version_parts = explode('.', $previous_version); |
|
472 | + $current_version_parts = explode('.', espresso_version()); |
|
473 | + return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
474 | + && ($previous_version_parts[0] !== $current_version_parts[0] |
|
475 | + || $previous_version_parts[1] !== $current_version_parts[1] |
|
476 | + ); |
|
477 | + } |
|
478 | + |
|
479 | + |
|
480 | + |
|
481 | + /** |
|
482 | + * Returns true if either the major or minor version of EE changed during this request. |
|
483 | + * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
484 | + * |
|
485 | + * @return bool |
|
486 | + */ |
|
487 | + public function is_major_version_change() |
|
488 | + { |
|
489 | + return $this->_major_version_change; |
|
490 | + } |
|
491 | + |
|
492 | + |
|
493 | + |
|
494 | + /** |
|
495 | + * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
496 | + * histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily |
|
497 | + * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
498 | + * just activated to (for core that will always be espresso_version()) |
|
499 | + * |
|
500 | + * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
501 | + * ee plugin. for core that's 'espresso_db_update' |
|
502 | + * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to |
|
503 | + * indicate that this plugin was just activated |
|
504 | + * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
505 | + * espresso_version()) |
|
506 | + * @return int one of the constants on EE_System::req_type_* |
|
507 | + */ |
|
508 | + public static function detect_req_type_given_activation_history( |
|
509 | + $activation_history_for_addon, |
|
510 | + $activation_indicator_option_name, |
|
511 | + $version_to_upgrade_to |
|
512 | + ) { |
|
513 | + $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
514 | + if ($activation_history_for_addon) { |
|
515 | + //it exists, so this isn't a completely new install |
|
516 | + //check if this version already in that list of previously installed versions |
|
517 | + if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
518 | + //it a version we haven't seen before |
|
519 | + if ($version_is_higher === 1) { |
|
520 | + $req_type = EE_System::req_type_upgrade; |
|
521 | + } else { |
|
522 | + $req_type = EE_System::req_type_downgrade; |
|
523 | + } |
|
524 | + delete_option($activation_indicator_option_name); |
|
525 | + } else { |
|
526 | + // its not an update. maybe a reactivation? |
|
527 | + if (get_option($activation_indicator_option_name, false)) { |
|
528 | + if ($version_is_higher === -1) { |
|
529 | + $req_type = EE_System::req_type_downgrade; |
|
530 | + } elseif ($version_is_higher === 0) { |
|
531 | + //we've seen this version before, but it's an activation. must be a reactivation |
|
532 | + $req_type = EE_System::req_type_reactivation; |
|
533 | + } else {//$version_is_higher === 1 |
|
534 | + $req_type = EE_System::req_type_upgrade; |
|
535 | + } |
|
536 | + delete_option($activation_indicator_option_name); |
|
537 | + } else { |
|
538 | + //we've seen this version before and the activation indicate doesn't show it was just activated |
|
539 | + if ($version_is_higher === -1) { |
|
540 | + $req_type = EE_System::req_type_downgrade; |
|
541 | + } elseif ($version_is_higher === 0) { |
|
542 | + //we've seen this version before and it's not an activation. its normal request |
|
543 | + $req_type = EE_System::req_type_normal; |
|
544 | + } else {//$version_is_higher === 1 |
|
545 | + $req_type = EE_System::req_type_upgrade; |
|
546 | + } |
|
547 | + } |
|
548 | + } |
|
549 | + } else { |
|
550 | + //brand new install |
|
551 | + $req_type = EE_System::req_type_new_activation; |
|
552 | + delete_option($activation_indicator_option_name); |
|
553 | + } |
|
554 | + return $req_type; |
|
555 | + } |
|
556 | + |
|
557 | + |
|
558 | + |
|
559 | + /** |
|
560 | + * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
561 | + * the $activation_history_for_addon |
|
562 | + * |
|
563 | + * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
564 | + * sometimes containing 'unknown-date' |
|
565 | + * @param string $version_to_upgrade_to (current version) |
|
566 | + * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
567 | + * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
568 | + * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
569 | + * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
570 | + */ |
|
571 | + protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
572 | + { |
|
573 | + //find the most recently-activated version |
|
574 | + $most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
575 | + return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
576 | + } |
|
577 | + |
|
578 | + |
|
579 | + |
|
580 | + /** |
|
581 | + * Gets the most recently active version listed in the activation history, |
|
582 | + * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
583 | + * |
|
584 | + * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
585 | + * sometimes containing 'unknown-date' |
|
586 | + * @return string |
|
587 | + */ |
|
588 | + protected static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
589 | + { |
|
590 | + $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
591 | + $most_recently_active_version = '0.0.0.dev.000'; |
|
592 | + if (is_array($activation_history)) { |
|
593 | + foreach ($activation_history as $version => $times_activated) { |
|
594 | + //check there is a record of when this version was activated. Otherwise, |
|
595 | + //mark it as unknown |
|
596 | + if ( ! $times_activated) { |
|
597 | + $times_activated = array('unknown-date'); |
|
598 | + } |
|
599 | + if (is_string($times_activated)) { |
|
600 | + $times_activated = array($times_activated); |
|
601 | + } |
|
602 | + foreach ($times_activated as $an_activation) { |
|
603 | + if ($an_activation != 'unknown-date' && $an_activation > $most_recently_active_version_activation) { |
|
604 | + $most_recently_active_version = $version; |
|
605 | + $most_recently_active_version_activation = $an_activation == 'unknown-date' |
|
606 | + ? '1970-01-01 00:00:00' : $an_activation; |
|
607 | + } |
|
608 | + } |
|
609 | + } |
|
610 | + } |
|
611 | + return $most_recently_active_version; |
|
612 | + } |
|
613 | + |
|
614 | + |
|
615 | + |
|
616 | + /** |
|
617 | + * This redirects to the about EE page after activation |
|
618 | + * |
|
619 | + * @return void |
|
620 | + */ |
|
621 | + public function redirect_to_about_ee() |
|
622 | + { |
|
623 | + $notices = EE_Error::get_notices(false); |
|
624 | + //if current user is an admin and it's not an ajax or rest request |
|
625 | + if ( |
|
626 | + ! (defined('DOING_AJAX') && DOING_AJAX) |
|
627 | + && ! (defined('REST_REQUEST') && REST_REQUEST) |
|
628 | + && ! isset($notices['errors']) |
|
629 | + && apply_filters( |
|
630 | + 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
631 | + $this->registry->CAP->current_user_can('manage_options', 'espresso_about_default') |
|
632 | + ) |
|
633 | + ) { |
|
634 | + $query_params = array('page' => 'espresso_about'); |
|
635 | + if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) { |
|
636 | + $query_params['new_activation'] = true; |
|
637 | + } |
|
638 | + if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) { |
|
639 | + $query_params['reactivation'] = true; |
|
640 | + } |
|
641 | + $url = add_query_arg($query_params, admin_url('admin.php')); |
|
642 | + wp_safe_redirect($url); |
|
643 | + exit(); |
|
644 | + } |
|
645 | + } |
|
646 | + |
|
647 | + |
|
648 | + |
|
649 | + /** |
|
650 | + * load_core_configuration |
|
651 | + * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
652 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
653 | + * |
|
654 | + * @return void |
|
655 | + */ |
|
656 | + public function load_core_configuration() |
|
657 | + { |
|
658 | + do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
659 | + $this->registry->load_core('EE_Load_Textdomain'); |
|
660 | + //load textdomain |
|
661 | + EE_Load_Textdomain::load_textdomain(); |
|
662 | + // load and setup EE_Config and EE_Network_Config |
|
663 | + $this->registry->load_core('Config'); |
|
664 | + $this->registry->load_core('Network_Config'); |
|
665 | + // setup autoloaders |
|
666 | + // enable logging? |
|
667 | + if ($this->registry->CFG->admin->use_full_logging) { |
|
668 | + $this->registry->load_core('Log'); |
|
669 | + } |
|
670 | + // check for activation errors |
|
671 | + $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
672 | + if ($activation_errors) { |
|
673 | + EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
674 | + update_option('ee_plugin_activation_errors', false); |
|
675 | + } |
|
676 | + // get model names |
|
677 | + $this->_parse_model_names(); |
|
678 | + //load caf stuff a chance to play during the activation process too. |
|
679 | + $this->_maybe_brew_regular(); |
|
680 | + do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
681 | + } |
|
682 | + |
|
683 | + |
|
684 | + |
|
685 | + /** |
|
686 | + * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
687 | + * |
|
688 | + * @return void |
|
689 | + */ |
|
690 | + private function _parse_model_names() |
|
691 | + { |
|
692 | + //get all the files in the EE_MODELS folder that end in .model.php |
|
693 | + $models = glob(EE_MODELS . '*.model.php'); |
|
694 | + $model_names = array(); |
|
695 | + $non_abstract_db_models = array(); |
|
696 | + foreach ($models as $model) { |
|
697 | + // get model classname |
|
698 | + $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
699 | + $short_name = str_replace('EEM_', '', $classname); |
|
700 | + $reflectionClass = new ReflectionClass($classname); |
|
701 | + if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
702 | + $non_abstract_db_models[$short_name] = $classname; |
|
703 | + } |
|
704 | + $model_names[$short_name] = $classname; |
|
705 | + } |
|
706 | + $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
707 | + $this->registry->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names', |
|
708 | + $non_abstract_db_models); |
|
709 | + } |
|
710 | + |
|
711 | + |
|
712 | + |
|
713 | + /** |
|
714 | + * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
715 | + * that need to be setup before our EE_System launches. |
|
716 | + * |
|
717 | + * @return void |
|
718 | + */ |
|
719 | + private function _maybe_brew_regular() |
|
720 | + { |
|
721 | + if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
722 | + require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
723 | + } |
|
724 | + } |
|
725 | + |
|
726 | + |
|
727 | + |
|
728 | + /** |
|
729 | + * register_shortcodes_modules_and_widgets |
|
730 | + * generate lists of shortcodes and modules, then verify paths and classes |
|
731 | + * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
732 | + * which runs during the WP 'plugins_loaded' action at priority 7 |
|
733 | + * |
|
734 | + * @access public |
|
735 | + * @return void |
|
736 | + */ |
|
737 | + public function register_shortcodes_modules_and_widgets() |
|
738 | + { |
|
739 | + try { |
|
740 | + // load, register, and add shortcodes the new way |
|
741 | + new ShortcodesManager( |
|
742 | + // and the old way, but we'll put it under control of the new system |
|
743 | + EE_Config::getLegacyShortcodesManager() |
|
744 | + ); |
|
745 | + } catch (Exception $exception) { |
|
746 | + new ExceptionStackTraceDisplay($exception); |
|
747 | + } |
|
748 | + do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
749 | + // check for addons using old hookpoint |
|
750 | + if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
751 | + $this->_incompatible_addon_error(); |
|
752 | + } |
|
753 | + } |
|
754 | + |
|
755 | + |
|
756 | + |
|
757 | + /** |
|
758 | + * _incompatible_addon_error |
|
759 | + * |
|
760 | + * @access public |
|
761 | + * @return void |
|
762 | + */ |
|
763 | + private function _incompatible_addon_error() |
|
764 | + { |
|
765 | + // get array of classes hooking into here |
|
766 | + $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons'); |
|
767 | + if ( ! empty($class_names)) { |
|
768 | + $msg = __('The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
769 | + 'event_espresso'); |
|
770 | + $msg .= '<ul>'; |
|
771 | + foreach ($class_names as $class_name) { |
|
772 | + $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
773 | + $class_name) . '</b></li>'; |
|
774 | + } |
|
775 | + $msg .= '</ul>'; |
|
776 | + $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
777 | + 'event_espresso'); |
|
778 | + // save list of incompatible addons to wp-options for later use |
|
779 | + add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
780 | + if (is_admin()) { |
|
781 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
782 | + } |
|
783 | + } |
|
784 | + } |
|
785 | + |
|
786 | + |
|
787 | + |
|
788 | + /** |
|
789 | + * brew_espresso |
|
790 | + * begins the process of setting hooks for initializing EE in the correct order |
|
791 | + * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint |
|
792 | + * which runs during the WP 'plugins_loaded' action at priority 9 |
|
793 | + * |
|
794 | + * @return void |
|
795 | + */ |
|
796 | + public function brew_espresso() |
|
797 | + { |
|
798 | + do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
799 | + // load some final core systems |
|
800 | + add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
801 | + add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
802 | + add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
803 | + add_action('init', array($this, 'load_controllers'), 7); |
|
804 | + add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
805 | + add_action('init', array($this, 'initialize'), 10); |
|
806 | + add_action('init', array($this, 'initialize_last'), 100); |
|
807 | + add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100); |
|
808 | + if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
809 | + // pew pew pew |
|
810 | + $this->registry->load_core('PUE'); |
|
811 | + do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
812 | + } |
|
813 | + do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
814 | + } |
|
815 | + |
|
816 | + |
|
817 | + |
|
818 | + /** |
|
819 | + * set_hooks_for_core |
|
820 | + * |
|
821 | + * @access public |
|
822 | + * @return void |
|
823 | + */ |
|
824 | + public function set_hooks_for_core() |
|
825 | + { |
|
826 | + $this->_deactivate_incompatible_addons(); |
|
827 | + do_action('AHEE__EE_System__set_hooks_for_core'); |
|
828 | + } |
|
829 | + |
|
830 | + |
|
831 | + |
|
832 | + /** |
|
833 | + * Using the information gathered in EE_System::_incompatible_addon_error, |
|
834 | + * deactivates any addons considered incompatible with the current version of EE |
|
835 | + */ |
|
836 | + private function _deactivate_incompatible_addons() |
|
837 | + { |
|
838 | + $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
839 | + if ( ! empty($incompatible_addons)) { |
|
840 | + $active_plugins = get_option('active_plugins', array()); |
|
841 | + foreach ($active_plugins as $active_plugin) { |
|
842 | + foreach ($incompatible_addons as $incompatible_addon) { |
|
843 | + if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
844 | + unset($_GET['activate']); |
|
845 | + espresso_deactivate_plugin($active_plugin); |
|
846 | + } |
|
847 | + } |
|
848 | + } |
|
849 | + } |
|
850 | + } |
|
851 | + |
|
852 | + |
|
853 | + |
|
854 | + /** |
|
855 | + * perform_activations_upgrades_and_migrations |
|
856 | + * |
|
857 | + * @access public |
|
858 | + * @return void |
|
859 | + */ |
|
860 | + public function perform_activations_upgrades_and_migrations() |
|
861 | + { |
|
862 | + //first check if we had previously attempted to setup EE's directories but failed |
|
863 | + if (EEH_Activation::upload_directories_incomplete()) { |
|
864 | + EEH_Activation::create_upload_directories(); |
|
865 | + } |
|
866 | + do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
867 | + } |
|
868 | + |
|
869 | + |
|
870 | + |
|
871 | + /** |
|
872 | + * load_CPTs_and_session |
|
873 | + * |
|
874 | + * @access public |
|
875 | + * @return void |
|
876 | + */ |
|
877 | + public function load_CPTs_and_session() |
|
878 | + { |
|
879 | + do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
880 | + // register Custom Post Types |
|
881 | + $this->registry->load_core('Register_CPTs'); |
|
882 | + do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
883 | + } |
|
884 | + |
|
885 | + |
|
886 | + |
|
887 | + /** |
|
888 | + * load_controllers |
|
889 | + * this is the best place to load any additional controllers that needs access to EE core. |
|
890 | + * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
891 | + * time |
|
892 | + * |
|
893 | + * @access public |
|
894 | + * @return void |
|
895 | + */ |
|
896 | + public function load_controllers() |
|
897 | + { |
|
898 | + do_action('AHEE__EE_System__load_controllers__start'); |
|
899 | + // let's get it started |
|
900 | + if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
901 | + do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
902 | + $this->registry->load_core('Front_Controller'); |
|
903 | + } else if ( ! EE_FRONT_AJAX) { |
|
904 | + do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
905 | + EE_Registry::instance()->load_core('Admin'); |
|
906 | + } |
|
907 | + do_action('AHEE__EE_System__load_controllers__complete'); |
|
908 | + } |
|
909 | + |
|
910 | + |
|
911 | + |
|
912 | + /** |
|
913 | + * core_loaded_and_ready |
|
914 | + * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
915 | + * |
|
916 | + * @access public |
|
917 | + * @return void |
|
918 | + */ |
|
919 | + public function core_loaded_and_ready() |
|
920 | + { |
|
921 | + $this->registry->load_core('Session'); |
|
922 | + do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
923 | + // load_espresso_template_tags |
|
924 | + if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
925 | + require_once(EE_PUBLIC . 'template_tags.php'); |
|
926 | + } |
|
927 | + do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
928 | + $this->registry->create('EventEspresso\core\services\assets\Registry'); |
|
929 | + wp_enqueue_script('espresso_core'); |
|
930 | + } |
|
931 | + |
|
932 | + |
|
933 | + |
|
934 | + /** |
|
935 | + * initialize |
|
936 | + * this is the best place to begin initializing client code |
|
937 | + * |
|
938 | + * @access public |
|
939 | + * @return void |
|
940 | + */ |
|
941 | + public function initialize() |
|
942 | + { |
|
943 | + do_action('AHEE__EE_System__initialize'); |
|
944 | + } |
|
945 | + |
|
946 | + |
|
947 | + |
|
948 | + /** |
|
949 | + * initialize_last |
|
950 | + * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to |
|
951 | + * initialize has done so |
|
952 | + * |
|
953 | + * @access public |
|
954 | + * @return void |
|
955 | + */ |
|
956 | + public function initialize_last() |
|
957 | + { |
|
958 | + do_action('AHEE__EE_System__initialize_last'); |
|
959 | + } |
|
960 | + |
|
961 | + |
|
962 | + |
|
963 | + /** |
|
964 | + * set_hooks_for_shortcodes_modules_and_addons |
|
965 | + * this is the best place for other systems to set callbacks for hooking into other parts of EE |
|
966 | + * this happens at the very beginning of the wp_loaded hookpoint |
|
967 | + * |
|
968 | + * @access public |
|
969 | + * @return void |
|
970 | + */ |
|
971 | + public function set_hooks_for_shortcodes_modules_and_addons() |
|
972 | + { |
|
973 | + // do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' ); |
|
974 | + } |
|
975 | + |
|
976 | + |
|
977 | + |
|
978 | + /** |
|
979 | + * do_not_cache |
|
980 | + * sets no cache headers and defines no cache constants for WP plugins |
|
981 | + * |
|
982 | + * @access public |
|
983 | + * @return void |
|
984 | + */ |
|
985 | + public static function do_not_cache() |
|
986 | + { |
|
987 | + // set no cache constants |
|
988 | + if ( ! defined('DONOTCACHEPAGE')) { |
|
989 | + define('DONOTCACHEPAGE', true); |
|
990 | + } |
|
991 | + if ( ! defined('DONOTCACHCEOBJECT')) { |
|
992 | + define('DONOTCACHCEOBJECT', true); |
|
993 | + } |
|
994 | + if ( ! defined('DONOTCACHEDB')) { |
|
995 | + define('DONOTCACHEDB', true); |
|
996 | + } |
|
997 | + // add no cache headers |
|
998 | + add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
999 | + // plus a little extra for nginx and Google Chrome |
|
1000 | + add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
1001 | + // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
1002 | + remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
1003 | + } |
|
1004 | + |
|
1005 | + |
|
1006 | + |
|
1007 | + /** |
|
1008 | + * extra_nocache_headers |
|
1009 | + * |
|
1010 | + * @access public |
|
1011 | + * @param $headers |
|
1012 | + * @return array |
|
1013 | + */ |
|
1014 | + public static function extra_nocache_headers($headers) |
|
1015 | + { |
|
1016 | + // for NGINX |
|
1017 | + $headers['X-Accel-Expires'] = 0; |
|
1018 | + // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
1019 | + $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
1020 | + return $headers; |
|
1021 | + } |
|
1022 | + |
|
1023 | + |
|
1024 | + |
|
1025 | + /** |
|
1026 | + * nocache_headers |
|
1027 | + * |
|
1028 | + * @access public |
|
1029 | + * @return void |
|
1030 | + */ |
|
1031 | + public static function nocache_headers() |
|
1032 | + { |
|
1033 | + nocache_headers(); |
|
1034 | + } |
|
1035 | + |
|
1036 | + |
|
1037 | + |
|
1038 | + /** |
|
1039 | + * espresso_toolbar_items |
|
1040 | + * |
|
1041 | + * @access public |
|
1042 | + * @param WP_Admin_Bar $admin_bar |
|
1043 | + * @return void |
|
1044 | + */ |
|
1045 | + public function espresso_toolbar_items(WP_Admin_Bar $admin_bar) |
|
1046 | + { |
|
1047 | + // if in full M-Mode, or its an AJAX request, or user is NOT an admin |
|
1048 | + if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance |
|
1049 | + || defined('DOING_AJAX') |
|
1050 | + || ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level') |
|
1051 | + ) { |
|
1052 | + return; |
|
1053 | + } |
|
1054 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1055 | + $menu_class = 'espresso_menu_item_class'; |
|
1056 | + //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
|
1057 | + //because they're only defined in each of their respective constructors |
|
1058 | + //and this might be a frontend request, in which case they aren't available |
|
1059 | + $events_admin_url = admin_url("admin.php?page=espresso_events"); |
|
1060 | + $reg_admin_url = admin_url("admin.php?page=espresso_registrations"); |
|
1061 | + $extensions_admin_url = admin_url("admin.php?page=espresso_packages"); |
|
1062 | + //Top Level |
|
1063 | + $admin_bar->add_menu(array( |
|
1064 | + 'id' => 'espresso-toolbar', |
|
1065 | + 'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' |
|
1066 | + . _x('Event Espresso', 'admin bar menu group label', 'event_espresso') |
|
1067 | + . '</span>', |
|
1068 | + 'href' => $events_admin_url, |
|
1069 | + 'meta' => array( |
|
1070 | + 'title' => __('Event Espresso', 'event_espresso'), |
|
1071 | + 'class' => $menu_class . 'first', |
|
1072 | + ), |
|
1073 | + )); |
|
1074 | + //Events |
|
1075 | + if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) { |
|
1076 | + $admin_bar->add_menu(array( |
|
1077 | + 'id' => 'espresso-toolbar-events', |
|
1078 | + 'parent' => 'espresso-toolbar', |
|
1079 | + 'title' => __('Events', 'event_espresso'), |
|
1080 | + 'href' => $events_admin_url, |
|
1081 | + 'meta' => array( |
|
1082 | + 'title' => __('Events', 'event_espresso'), |
|
1083 | + 'target' => '', |
|
1084 | + 'class' => $menu_class, |
|
1085 | + ), |
|
1086 | + )); |
|
1087 | + } |
|
1088 | + if ($this->registry->CAP->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) { |
|
1089 | + //Events Add New |
|
1090 | + $admin_bar->add_menu(array( |
|
1091 | + 'id' => 'espresso-toolbar-events-new', |
|
1092 | + 'parent' => 'espresso-toolbar-events', |
|
1093 | + 'title' => __('Add New', 'event_espresso'), |
|
1094 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url), |
|
1095 | + 'meta' => array( |
|
1096 | + 'title' => __('Add New', 'event_espresso'), |
|
1097 | + 'target' => '', |
|
1098 | + 'class' => $menu_class, |
|
1099 | + ), |
|
1100 | + )); |
|
1101 | + } |
|
1102 | + if (is_single() && (get_post_type() == 'espresso_events')) { |
|
1103 | + //Current post |
|
1104 | + global $post; |
|
1105 | + if ($this->registry->CAP->current_user_can('ee_edit_event', |
|
1106 | + 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID) |
|
1107 | + ) { |
|
1108 | + //Events Edit Current Event |
|
1109 | + $admin_bar->add_menu(array( |
|
1110 | + 'id' => 'espresso-toolbar-events-edit', |
|
1111 | + 'parent' => 'espresso-toolbar-events', |
|
1112 | + 'title' => __('Edit Event', 'event_espresso'), |
|
1113 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID), |
|
1114 | + $events_admin_url), |
|
1115 | + 'meta' => array( |
|
1116 | + 'title' => __('Edit Event', 'event_espresso'), |
|
1117 | + 'target' => '', |
|
1118 | + 'class' => $menu_class, |
|
1119 | + ), |
|
1120 | + )); |
|
1121 | + } |
|
1122 | + } |
|
1123 | + //Events View |
|
1124 | + if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1125 | + 'ee_admin_bar_menu_espresso-toolbar-events-view') |
|
1126 | + ) { |
|
1127 | + $admin_bar->add_menu(array( |
|
1128 | + 'id' => 'espresso-toolbar-events-view', |
|
1129 | + 'parent' => 'espresso-toolbar-events', |
|
1130 | + 'title' => __('View', 'event_espresso'), |
|
1131 | + 'href' => $events_admin_url, |
|
1132 | + 'meta' => array( |
|
1133 | + 'title' => __('View', 'event_espresso'), |
|
1134 | + 'target' => '', |
|
1135 | + 'class' => $menu_class, |
|
1136 | + ), |
|
1137 | + )); |
|
1138 | + } |
|
1139 | + if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) { |
|
1140 | + //Events View All |
|
1141 | + $admin_bar->add_menu(array( |
|
1142 | + 'id' => 'espresso-toolbar-events-all', |
|
1143 | + 'parent' => 'espresso-toolbar-events-view', |
|
1144 | + 'title' => __('All', 'event_espresso'), |
|
1145 | + 'href' => $events_admin_url, |
|
1146 | + 'meta' => array( |
|
1147 | + 'title' => __('All', 'event_espresso'), |
|
1148 | + 'target' => '', |
|
1149 | + 'class' => $menu_class, |
|
1150 | + ), |
|
1151 | + )); |
|
1152 | + } |
|
1153 | + if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1154 | + 'ee_admin_bar_menu_espresso-toolbar-events-today') |
|
1155 | + ) { |
|
1156 | + //Events View Today |
|
1157 | + $admin_bar->add_menu(array( |
|
1158 | + 'id' => 'espresso-toolbar-events-today', |
|
1159 | + 'parent' => 'espresso-toolbar-events-view', |
|
1160 | + 'title' => __('Today', 'event_espresso'), |
|
1161 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
1162 | + $events_admin_url), |
|
1163 | + 'meta' => array( |
|
1164 | + 'title' => __('Today', 'event_espresso'), |
|
1165 | + 'target' => '', |
|
1166 | + 'class' => $menu_class, |
|
1167 | + ), |
|
1168 | + )); |
|
1169 | + } |
|
1170 | + if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1171 | + 'ee_admin_bar_menu_espresso-toolbar-events-month') |
|
1172 | + ) { |
|
1173 | + //Events View This Month |
|
1174 | + $admin_bar->add_menu(array( |
|
1175 | + 'id' => 'espresso-toolbar-events-month', |
|
1176 | + 'parent' => 'espresso-toolbar-events-view', |
|
1177 | + 'title' => __('This Month', 'event_espresso'), |
|
1178 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
1179 | + $events_admin_url), |
|
1180 | + 'meta' => array( |
|
1181 | + 'title' => __('This Month', 'event_espresso'), |
|
1182 | + 'target' => '', |
|
1183 | + 'class' => $menu_class, |
|
1184 | + ), |
|
1185 | + )); |
|
1186 | + } |
|
1187 | + //Registration Overview |
|
1188 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1189 | + 'ee_admin_bar_menu_espresso-toolbar-registrations') |
|
1190 | + ) { |
|
1191 | + $admin_bar->add_menu(array( |
|
1192 | + 'id' => 'espresso-toolbar-registrations', |
|
1193 | + 'parent' => 'espresso-toolbar', |
|
1194 | + 'title' => __('Registrations', 'event_espresso'), |
|
1195 | + 'href' => $reg_admin_url, |
|
1196 | + 'meta' => array( |
|
1197 | + 'title' => __('Registrations', 'event_espresso'), |
|
1198 | + 'target' => '', |
|
1199 | + 'class' => $menu_class, |
|
1200 | + ), |
|
1201 | + )); |
|
1202 | + } |
|
1203 | + //Registration Overview Today |
|
1204 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1205 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today') |
|
1206 | + ) { |
|
1207 | + $admin_bar->add_menu(array( |
|
1208 | + 'id' => 'espresso-toolbar-registrations-today', |
|
1209 | + 'parent' => 'espresso-toolbar-registrations', |
|
1210 | + 'title' => __('Today', 'event_espresso'), |
|
1211 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
1212 | + $reg_admin_url), |
|
1213 | + 'meta' => array( |
|
1214 | + 'title' => __('Today', 'event_espresso'), |
|
1215 | + 'target' => '', |
|
1216 | + 'class' => $menu_class, |
|
1217 | + ), |
|
1218 | + )); |
|
1219 | + } |
|
1220 | + //Registration Overview Today Completed |
|
1221 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1222 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved') |
|
1223 | + ) { |
|
1224 | + $admin_bar->add_menu(array( |
|
1225 | + 'id' => 'espresso-toolbar-registrations-today-approved', |
|
1226 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
1227 | + 'title' => __('Approved', 'event_espresso'), |
|
1228 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1229 | + 'action' => 'default', |
|
1230 | + 'status' => 'today', |
|
1231 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
1232 | + ), $reg_admin_url), |
|
1233 | + 'meta' => array( |
|
1234 | + 'title' => __('Approved', 'event_espresso'), |
|
1235 | + 'target' => '', |
|
1236 | + 'class' => $menu_class, |
|
1237 | + ), |
|
1238 | + )); |
|
1239 | + } |
|
1240 | + //Registration Overview Today Pending\ |
|
1241 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1242 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending') |
|
1243 | + ) { |
|
1244 | + $admin_bar->add_menu(array( |
|
1245 | + 'id' => 'espresso-toolbar-registrations-today-pending', |
|
1246 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
1247 | + 'title' => __('Pending', 'event_espresso'), |
|
1248 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1249 | + 'action' => 'default', |
|
1250 | + 'status' => 'today', |
|
1251 | + 'reg_status' => EEM_Registration::status_id_pending_payment, |
|
1252 | + ), $reg_admin_url), |
|
1253 | + 'meta' => array( |
|
1254 | + 'title' => __('Pending Payment', 'event_espresso'), |
|
1255 | + 'target' => '', |
|
1256 | + 'class' => $menu_class, |
|
1257 | + ), |
|
1258 | + )); |
|
1259 | + } |
|
1260 | + //Registration Overview Today Incomplete |
|
1261 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1262 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved') |
|
1263 | + ) { |
|
1264 | + $admin_bar->add_menu(array( |
|
1265 | + 'id' => 'espresso-toolbar-registrations-today-not-approved', |
|
1266 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
1267 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1268 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1269 | + 'action' => 'default', |
|
1270 | + 'status' => 'today', |
|
1271 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1272 | + ), $reg_admin_url), |
|
1273 | + 'meta' => array( |
|
1274 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1275 | + 'target' => '', |
|
1276 | + 'class' => $menu_class, |
|
1277 | + ), |
|
1278 | + )); |
|
1279 | + } |
|
1280 | + //Registration Overview Today Incomplete |
|
1281 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1282 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled') |
|
1283 | + ) { |
|
1284 | + $admin_bar->add_menu(array( |
|
1285 | + 'id' => 'espresso-toolbar-registrations-today-cancelled', |
|
1286 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
1287 | + 'title' => __('Cancelled', 'event_espresso'), |
|
1288 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1289 | + 'action' => 'default', |
|
1290 | + 'status' => 'today', |
|
1291 | + '_reg_status' => EEM_Registration::status_id_cancelled, |
|
1292 | + ), $reg_admin_url), |
|
1293 | + 'meta' => array( |
|
1294 | + 'title' => __('Cancelled', 'event_espresso'), |
|
1295 | + 'target' => '', |
|
1296 | + 'class' => $menu_class, |
|
1297 | + ), |
|
1298 | + )); |
|
1299 | + } |
|
1300 | + //Registration Overview This Month |
|
1301 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1302 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month') |
|
1303 | + ) { |
|
1304 | + $admin_bar->add_menu(array( |
|
1305 | + 'id' => 'espresso-toolbar-registrations-month', |
|
1306 | + 'parent' => 'espresso-toolbar-registrations', |
|
1307 | + 'title' => __('This Month', 'event_espresso'), |
|
1308 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
1309 | + $reg_admin_url), |
|
1310 | + 'meta' => array( |
|
1311 | + 'title' => __('This Month', 'event_espresso'), |
|
1312 | + 'target' => '', |
|
1313 | + 'class' => $menu_class, |
|
1314 | + ), |
|
1315 | + )); |
|
1316 | + } |
|
1317 | + //Registration Overview This Month Approved |
|
1318 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1319 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved') |
|
1320 | + ) { |
|
1321 | + $admin_bar->add_menu(array( |
|
1322 | + 'id' => 'espresso-toolbar-registrations-month-approved', |
|
1323 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
1324 | + 'title' => __('Approved', 'event_espresso'), |
|
1325 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1326 | + 'action' => 'default', |
|
1327 | + 'status' => 'month', |
|
1328 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
1329 | + ), $reg_admin_url), |
|
1330 | + 'meta' => array( |
|
1331 | + 'title' => __('Approved', 'event_espresso'), |
|
1332 | + 'target' => '', |
|
1333 | + 'class' => $menu_class, |
|
1334 | + ), |
|
1335 | + )); |
|
1336 | + } |
|
1337 | + //Registration Overview This Month Pending |
|
1338 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1339 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending') |
|
1340 | + ) { |
|
1341 | + $admin_bar->add_menu(array( |
|
1342 | + 'id' => 'espresso-toolbar-registrations-month-pending', |
|
1343 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
1344 | + 'title' => __('Pending', 'event_espresso'), |
|
1345 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1346 | + 'action' => 'default', |
|
1347 | + 'status' => 'month', |
|
1348 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
1349 | + ), $reg_admin_url), |
|
1350 | + 'meta' => array( |
|
1351 | + 'title' => __('Pending', 'event_espresso'), |
|
1352 | + 'target' => '', |
|
1353 | + 'class' => $menu_class, |
|
1354 | + ), |
|
1355 | + )); |
|
1356 | + } |
|
1357 | + //Registration Overview This Month Not Approved |
|
1358 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1359 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved') |
|
1360 | + ) { |
|
1361 | + $admin_bar->add_menu(array( |
|
1362 | + 'id' => 'espresso-toolbar-registrations-month-not-approved', |
|
1363 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
1364 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1365 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1366 | + 'action' => 'default', |
|
1367 | + 'status' => 'month', |
|
1368 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1369 | + ), $reg_admin_url), |
|
1370 | + 'meta' => array( |
|
1371 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1372 | + 'target' => '', |
|
1373 | + 'class' => $menu_class, |
|
1374 | + ), |
|
1375 | + )); |
|
1376 | + } |
|
1377 | + //Registration Overview This Month Cancelled |
|
1378 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1379 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled') |
|
1380 | + ) { |
|
1381 | + $admin_bar->add_menu(array( |
|
1382 | + 'id' => 'espresso-toolbar-registrations-month-cancelled', |
|
1383 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
1384 | + 'title' => __('Cancelled', 'event_espresso'), |
|
1385 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1386 | + 'action' => 'default', |
|
1387 | + 'status' => 'month', |
|
1388 | + '_reg_status' => EEM_Registration::status_id_cancelled, |
|
1389 | + ), $reg_admin_url), |
|
1390 | + 'meta' => array( |
|
1391 | + 'title' => __('Cancelled', 'event_espresso'), |
|
1392 | + 'target' => '', |
|
1393 | + 'class' => $menu_class, |
|
1394 | + ), |
|
1395 | + )); |
|
1396 | + } |
|
1397 | + //Extensions & Services |
|
1398 | + if ($this->registry->CAP->current_user_can('ee_read_ee', |
|
1399 | + 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services') |
|
1400 | + ) { |
|
1401 | + $admin_bar->add_menu(array( |
|
1402 | + 'id' => 'espresso-toolbar-extensions-and-services', |
|
1403 | + 'parent' => 'espresso-toolbar', |
|
1404 | + 'title' => __('Extensions & Services', 'event_espresso'), |
|
1405 | + 'href' => $extensions_admin_url, |
|
1406 | + 'meta' => array( |
|
1407 | + 'title' => __('Extensions & Services', 'event_espresso'), |
|
1408 | + 'target' => '', |
|
1409 | + 'class' => $menu_class, |
|
1410 | + ), |
|
1411 | + )); |
|
1412 | + } |
|
1413 | + } |
|
1414 | + |
|
1415 | + |
|
1416 | + |
|
1417 | + /** |
|
1418 | + * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
1419 | + * never returned with the function. |
|
1420 | + * |
|
1421 | + * @param array $exclude_array any existing pages being excluded are in this array. |
|
1422 | + * @return array |
|
1423 | + */ |
|
1424 | + public function remove_pages_from_wp_list_pages($exclude_array) |
|
1425 | + { |
|
1426 | + return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
1427 | + } |
|
1428 | 1428 | |
1429 | 1429 | |
1430 | 1430 |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | { |
186 | 186 | // set autoloaders for all of the classes implementing EEI_Plugin_API |
187 | 187 | // which provide helpers for EE plugin authors to more easily register certain components with EE. |
188 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
188 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api'); |
|
189 | 189 | //load and setup EE_Capabilities |
190 | 190 | $this->registry->load_core('Capabilities'); |
191 | 191 | //caps need to be initialized on every request so that capability maps are set. |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | && $_GET['activate'] === 'true' |
209 | 209 | ) |
210 | 210 | ) { |
211 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
211 | + include_once EE_THIRD_PARTY.'wp-api-basic-auth'.DS.'basic-auth.php'; |
|
212 | 212 | } |
213 | 213 | do_action('AHEE__EE_System__load_espresso_addons__complete'); |
214 | 214 | } |
@@ -690,7 +690,7 @@ discard block |
||
690 | 690 | private function _parse_model_names() |
691 | 691 | { |
692 | 692 | //get all the files in the EE_MODELS folder that end in .model.php |
693 | - $models = glob(EE_MODELS . '*.model.php'); |
|
693 | + $models = glob(EE_MODELS.'*.model.php'); |
|
694 | 694 | $model_names = array(); |
695 | 695 | $non_abstract_db_models = array(); |
696 | 696 | foreach ($models as $model) { |
@@ -718,8 +718,8 @@ discard block |
||
718 | 718 | */ |
719 | 719 | private function _maybe_brew_regular() |
720 | 720 | { |
721 | - if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
722 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
721 | + if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH.'brewing_regular.php')) { |
|
722 | + require_once EE_CAFF_PATH.'brewing_regular.php'; |
|
723 | 723 | } |
724 | 724 | } |
725 | 725 | |
@@ -769,8 +769,8 @@ discard block |
||
769 | 769 | 'event_espresso'); |
770 | 770 | $msg .= '<ul>'; |
771 | 771 | foreach ($class_names as $class_name) { |
772 | - $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
773 | - $class_name) . '</b></li>'; |
|
772 | + $msg .= '<li><b>Event Espresso - '.str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
773 | + $class_name).'</b></li>'; |
|
774 | 774 | } |
775 | 775 | $msg .= '</ul>'; |
776 | 776 | $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
@@ -921,8 +921,8 @@ discard block |
||
921 | 921 | $this->registry->load_core('Session'); |
922 | 922 | do_action('AHEE__EE_System__core_loaded_and_ready'); |
923 | 923 | // load_espresso_template_tags |
924 | - if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
925 | - require_once(EE_PUBLIC . 'template_tags.php'); |
|
924 | + if (is_readable(EE_PUBLIC.'template_tags.php')) { |
|
925 | + require_once(EE_PUBLIC.'template_tags.php'); |
|
926 | 926 | } |
927 | 927 | do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
928 | 928 | $this->registry->create('EventEspresso\core\services\assets\Registry'); |
@@ -1068,7 +1068,7 @@ discard block |
||
1068 | 1068 | 'href' => $events_admin_url, |
1069 | 1069 | 'meta' => array( |
1070 | 1070 | 'title' => __('Event Espresso', 'event_espresso'), |
1071 | - 'class' => $menu_class . 'first', |
|
1071 | + 'class' => $menu_class.'first', |
|
1072 | 1072 | ), |
1073 | 1073 | )); |
1074 | 1074 | //Events |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | use EventEspresso\core\exceptions\InvalidSessionDataException; |
3 | 3 | use EventEspresso\core\services\cache\CacheStorageInterface; |
4 | 4 | |
5 | -if (!defined( 'EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed');} |
|
5 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed'); } |
|
6 | 6 | /** |
7 | 7 | * |
8 | 8 | * EE_Session class |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * array for defining default session vars |
109 | 109 | * @var array |
110 | 110 | */ |
111 | - private $_default_session_vars = array ( |
|
111 | + private $_default_session_vars = array( |
|
112 | 112 | 'id' => null, |
113 | 113 | 'user_id' => null, |
114 | 114 | 'ip_address' => null, |
@@ -136,8 +136,8 @@ discard block |
||
136 | 136 | // check if class object is instantiated |
137 | 137 | // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: |
138 | 138 | // add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
139 | - if ( ! self::$_instance instanceof EE_Session && apply_filters( 'FHEE_load_EE_Session', true ) ) { |
|
140 | - self::$_instance = new self($cache_storage, $encryption ); |
|
139 | + if ( ! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) { |
|
140 | + self::$_instance = new self($cache_storage, $encryption); |
|
141 | 141 | } |
142 | 142 | return self::$_instance; |
143 | 143 | } |
@@ -152,15 +152,15 @@ discard block |
||
152 | 152 | * @throws \EE_Error |
153 | 153 | * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
154 | 154 | */ |
155 | - protected function __construct(CacheStorageInterface $cache_storage, EE_Encryption $encryption = null ) { |
|
155 | + protected function __construct(CacheStorageInterface $cache_storage, EE_Encryption $encryption = null) { |
|
156 | 156 | |
157 | 157 | // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
158 | - if ( ! apply_filters( 'FHEE_load_EE_Session', true ) ) { |
|
158 | + if ( ! apply_filters('FHEE_load_EE_Session', true)) { |
|
159 | 159 | return; |
160 | 160 | } |
161 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
162 | - if ( ! defined( 'ESPRESSO_SESSION' ) ) { |
|
163 | - define( 'ESPRESSO_SESSION', true ); |
|
161 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
162 | + if ( ! defined('ESPRESSO_SESSION')) { |
|
163 | + define('ESPRESSO_SESSION', true); |
|
164 | 164 | } |
165 | 165 | // default session lifespan in seconds |
166 | 166 | $this->_lifespan = apply_filters( |
@@ -174,12 +174,12 @@ discard block |
||
174 | 174 | * } |
175 | 175 | */ |
176 | 176 | // retrieve session options from db |
177 | - $session_settings = (array) get_option( 'ee_session_settings', array() ); |
|
178 | - if ( ! empty( $session_settings )) { |
|
177 | + $session_settings = (array) get_option('ee_session_settings', array()); |
|
178 | + if ( ! empty($session_settings)) { |
|
179 | 179 | // cycle though existing session options |
180 | - foreach ( $session_settings as $var_name => $session_setting ) { |
|
180 | + foreach ($session_settings as $var_name => $session_setting) { |
|
181 | 181 | // set values for class properties |
182 | - $var_name = '_' . $var_name; |
|
182 | + $var_name = '_'.$var_name; |
|
183 | 183 | $this->{$var_name} = $session_setting; |
184 | 184 | } |
185 | 185 | } |
@@ -190,15 +190,15 @@ discard block |
||
190 | 190 | // encrypt data via: $this->encryption->encrypt(); |
191 | 191 | $this->encryption = $encryption; |
192 | 192 | // filter hook allows outside functions/classes/plugins to change default empty cart |
193 | - $extra_default_session_vars = apply_filters( 'FHEE__EE_Session__construct__extra_default_session_vars', array() ); |
|
194 | - array_merge( $this->_default_session_vars, $extra_default_session_vars ); |
|
193 | + $extra_default_session_vars = apply_filters('FHEE__EE_Session__construct__extra_default_session_vars', array()); |
|
194 | + array_merge($this->_default_session_vars, $extra_default_session_vars); |
|
195 | 195 | // apply default session vars |
196 | 196 | $this->_set_defaults(); |
197 | 197 | add_action('AHEE__EE_System__initialize', array($this, 'open_session')); |
198 | 198 | // check request for 'clear_session' param |
199 | - add_action( 'AHEE__EE_Request_Handler__construct__complete', array( $this, 'wp_loaded' )); |
|
199 | + add_action('AHEE__EE_Request_Handler__construct__complete', array($this, 'wp_loaded')); |
|
200 | 200 | // once everything is all said and done, |
201 | - add_action( 'shutdown', array( $this, 'update' ), 100 ); |
|
201 | + add_action('shutdown', array($this, 'update'), 100); |
|
202 | 202 | $this->configure_garbage_collection_filters(); |
203 | 203 | } |
204 | 204 | |
@@ -286,11 +286,11 @@ discard block |
||
286 | 286 | */ |
287 | 287 | private function _set_defaults() { |
288 | 288 | // set some defaults |
289 | - foreach ( $this->_default_session_vars as $key => $default_var ) { |
|
290 | - if ( is_array( $default_var )) { |
|
291 | - $this->_session_data[ $key ] = array(); |
|
289 | + foreach ($this->_default_session_vars as $key => $default_var) { |
|
290 | + if (is_array($default_var)) { |
|
291 | + $this->_session_data[$key] = array(); |
|
292 | 292 | } else { |
293 | - $this->_session_data[ $key ] = ''; |
|
293 | + $this->_session_data[$key] = ''; |
|
294 | 294 | } |
295 | 295 | } |
296 | 296 | } |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | * @param \EE_Checkout $checkout |
346 | 346 | * @return bool |
347 | 347 | */ |
348 | - public function set_checkout( EE_Checkout $checkout ) { |
|
348 | + public function set_checkout(EE_Checkout $checkout) { |
|
349 | 349 | $this->_session_data['checkout'] = $checkout; |
350 | 350 | return TRUE; |
351 | 351 | } |
@@ -378,9 +378,9 @@ discard block |
||
378 | 378 | * @return bool |
379 | 379 | * @throws \EE_Error |
380 | 380 | */ |
381 | - public function set_transaction( EE_Transaction $transaction ) { |
|
381 | + public function set_transaction(EE_Transaction $transaction) { |
|
382 | 382 | // first remove the session from the transaction before we save the transaction in the session |
383 | - $transaction->set_txn_session_data( NULL ); |
|
383 | + $transaction->set_txn_session_data(NULL); |
|
384 | 384 | $this->_session_data['transaction'] = $transaction; |
385 | 385 | return TRUE; |
386 | 386 | } |
@@ -416,15 +416,15 @@ discard block |
||
416 | 416 | * @param bool $reset_cache |
417 | 417 | * @return array |
418 | 418 | */ |
419 | - public function get_session_data( $key = NULL, $reset_cache = FALSE ) { |
|
420 | - if ( $reset_cache ) { |
|
419 | + public function get_session_data($key = NULL, $reset_cache = FALSE) { |
|
420 | + if ($reset_cache) { |
|
421 | 421 | $this->reset_cart(); |
422 | 422 | $this->reset_checkout(); |
423 | 423 | $this->reset_transaction(); |
424 | 424 | } |
425 | - if ( ! empty( $key )) { |
|
426 | - return isset( $this->_session_data[ $key ] ) ? $this->_session_data[ $key ] : NULL; |
|
427 | - } else { |
|
425 | + if ( ! empty($key)) { |
|
426 | + return isset($this->_session_data[$key]) ? $this->_session_data[$key] : NULL; |
|
427 | + } else { |
|
428 | 428 | return $this->_session_data; |
429 | 429 | } |
430 | 430 | } |
@@ -437,20 +437,20 @@ discard block |
||
437 | 437 | * @param array $data |
438 | 438 | * @return TRUE on success, FALSE on fail |
439 | 439 | */ |
440 | - public function set_session_data( $data ) { |
|
440 | + public function set_session_data($data) { |
|
441 | 441 | |
442 | 442 | // nothing ??? bad data ??? go home! |
443 | - if ( empty( $data ) || ! is_array( $data )) { |
|
444 | - EE_Error::add_error( __( 'No session data or invalid session data was provided.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
443 | + if (empty($data) || ! is_array($data)) { |
|
444 | + EE_Error::add_error(__('No session data or invalid session data was provided.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
445 | 445 | return FALSE; |
446 | 446 | } |
447 | 447 | |
448 | - foreach ( $data as $key =>$value ) { |
|
449 | - if ( isset( $this->_default_session_vars[ $key ] )) { |
|
450 | - EE_Error::add_error( sprintf( __( 'Sorry! %s is a default session datum and can not be reset.', 'event_espresso' ), $key ), __FILE__, __FUNCTION__, __LINE__ ); |
|
448 | + foreach ($data as $key =>$value) { |
|
449 | + if (isset($this->_default_session_vars[$key])) { |
|
450 | + EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.', 'event_espresso'), $key), __FILE__, __FUNCTION__, __LINE__); |
|
451 | 451 | return FALSE; |
452 | 452 | } else { |
453 | - $this->_session_data[ $key ] = $value; |
|
453 | + $this->_session_data[$key] = $value; |
|
454 | 454 | } |
455 | 455 | } |
456 | 456 | |
@@ -468,9 +468,9 @@ discard block |
||
468 | 468 | * @throws \EE_Error |
469 | 469 | */ |
470 | 470 | private function _espresso_session() { |
471 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
471 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
472 | 472 | // check that session has started |
473 | - if ( session_id() === '' ) { |
|
473 | + if (session_id() === '') { |
|
474 | 474 | //starts a new session if one doesn't already exist, or re-initiates an existing one |
475 | 475 | session_start(); |
476 | 476 | } |
@@ -479,39 +479,39 @@ discard block |
||
479 | 479 | // and the visitors IP |
480 | 480 | $this->_ip_address = $this->_visitor_ip(); |
481 | 481 | // set the "user agent" |
482 | - $this->_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? esc_attr( $_SERVER['HTTP_USER_AGENT'] ) : FALSE; |
|
482 | + $this->_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? esc_attr($_SERVER['HTTP_USER_AGENT']) : FALSE; |
|
483 | 483 | // now let's retrieve what's in the db |
484 | 484 | $session_data = $this->_retrieve_session_data(); |
485 | - if (! empty($session_data)) { |
|
485 | + if ( ! empty($session_data)) { |
|
486 | 486 | // get the current time in UTC |
487 | - $this->_time = isset( $this->_time ) ? $this->_time : time(); |
|
487 | + $this->_time = isset($this->_time) ? $this->_time : time(); |
|
488 | 488 | // and reset the session expiration |
489 | - $this->_expiration = isset( $session_data['expiration'] ) |
|
489 | + $this->_expiration = isset($session_data['expiration']) |
|
490 | 490 | ? $session_data['expiration'] |
491 | 491 | : $this->_time + $this->_lifespan; |
492 | 492 | } else { |
493 | 493 | // set initial site access time and the session expiration |
494 | 494 | $this->_set_init_access_and_expiration(); |
495 | 495 | // set referer |
496 | - $this->_session_data[ 'pages_visited' ][ $this->_session_data['init_access'] ] = isset( $_SERVER['HTTP_REFERER'] ) |
|
497 | - ? esc_attr( $_SERVER['HTTP_REFERER'] ) |
|
496 | + $this->_session_data['pages_visited'][$this->_session_data['init_access']] = isset($_SERVER['HTTP_REFERER']) |
|
497 | + ? esc_attr($_SERVER['HTTP_REFERER']) |
|
498 | 498 | : ''; |
499 | 499 | // no previous session = go back and create one (on top of the data above) |
500 | 500 | return FALSE; |
501 | 501 | } |
502 | 502 | // now the user agent |
503 | - if ( $session_data['user_agent'] !== $this->_user_agent ) { |
|
503 | + if ($session_data['user_agent'] !== $this->_user_agent) { |
|
504 | 504 | return FALSE; |
505 | 505 | } |
506 | 506 | // wait a minute... how old are you? |
507 | - if ( $this->_time > $this->_expiration ) { |
|
507 | + if ($this->_time > $this->_expiration) { |
|
508 | 508 | // yer too old fer me! |
509 | 509 | $this->_expired = true; |
510 | 510 | // wipe out everything that isn't a default session datum |
511 | - $this->clear_session( __CLASS__, __FUNCTION__ ); |
|
511 | + $this->clear_session(__CLASS__, __FUNCTION__); |
|
512 | 512 | } |
513 | 513 | // make event espresso session data available to plugin |
514 | - $this->_session_data = array_merge( $this->_session_data, $session_data ); |
|
514 | + $this->_session_data = array_merge($this->_session_data, $session_data); |
|
515 | 515 | return TRUE; |
516 | 516 | |
517 | 517 | } |
@@ -527,7 +527,7 @@ discard block |
||
527 | 527 | */ |
528 | 528 | protected function _retrieve_session_data() |
529 | 529 | { |
530 | - $ssn_key = EE_Session::session_id_prefix . $this->_sid; |
|
530 | + $ssn_key = EE_Session::session_id_prefix.$this->_sid; |
|
531 | 531 | try { |
532 | 532 | // we're using WP's Transient API to store session data using the PHP session ID as the option name |
533 | 533 | $session_data = $this->cache_storage->get($ssn_key, false); |
@@ -536,7 +536,7 @@ discard block |
||
536 | 536 | } |
537 | 537 | if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
538 | 538 | $hash_check = $this->cache_storage->get( |
539 | - EE_Session::hash_check_prefix . $this->_sid, |
|
539 | + EE_Session::hash_check_prefix.$this->_sid, |
|
540 | 540 | false |
541 | 541 | ); |
542 | 542 | if ($hash_check && $hash_check !== md5($session_data)) { |
@@ -546,7 +546,7 @@ discard block |
||
546 | 546 | 'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.', |
547 | 547 | 'event_espresso' |
548 | 548 | ), |
549 | - EE_Session::session_id_prefix . $this->_sid |
|
549 | + EE_Session::session_id_prefix.$this->_sid |
|
550 | 550 | ), |
551 | 551 | __FILE__, __FUNCTION__, __LINE__ |
552 | 552 | ); |
@@ -558,17 +558,17 @@ discard block |
||
558 | 558 | $row = $wpdb->get_row( |
559 | 559 | $wpdb->prepare( |
560 | 560 | "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", |
561 | - '_transient_' . $ssn_key |
|
561 | + '_transient_'.$ssn_key |
|
562 | 562 | ) |
563 | 563 | ); |
564 | 564 | $session_data = is_object($row) ? $row->option_value : null; |
565 | 565 | if ($session_data) { |
566 | 566 | $session_data = preg_replace_callback( |
567 | 567 | '!s:(d+):"(.*?)";!', |
568 | - function ($match) { |
|
568 | + function($match) { |
|
569 | 569 | return $match[1] === strlen($match[2]) |
570 | 570 | ? $match[0] |
571 | - : 's:' . strlen($match[2]) . ':"' . $match[2] . '";'; |
|
571 | + : 's:'.strlen($match[2]).':"'.$match[2].'";'; |
|
572 | 572 | }, |
573 | 573 | $session_data |
574 | 574 | ); |
@@ -589,7 +589,7 @@ discard block |
||
589 | 589 | 'event_espresso' |
590 | 590 | ); |
591 | 591 | $msg .= WP_DEBUG |
592 | - ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data) |
|
592 | + ? '<br><pre>'.print_r($session_data, true).'</pre><br>'.$this->find_serialize_error($session_data) |
|
593 | 593 | : ''; |
594 | 594 | throw new InvalidSessionDataException($msg, 0, $e); |
595 | 595 | } |
@@ -602,11 +602,11 @@ discard block |
||
602 | 602 | 'event_espresso' |
603 | 603 | ); |
604 | 604 | $msg .= WP_DEBUG |
605 | - ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data) |
|
605 | + ? '<br><pre>'.print_r($session_data, true).'</pre><br>'.$this->find_serialize_error($session_data) |
|
606 | 606 | : ''; |
607 | 607 | throw new InvalidSessionDataException($msg); |
608 | 608 | } |
609 | - if ( isset($session_data['transaction'] ) && absint($session_data['transaction'] ) !== 0 ) { |
|
609 | + if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) { |
|
610 | 610 | $session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID( |
611 | 611 | $session_data['transaction'] |
612 | 612 | ); |
@@ -627,12 +627,12 @@ discard block |
||
627 | 627 | */ |
628 | 628 | protected function _generate_session_id() { |
629 | 629 | // check if the SID was passed explicitly, otherwise get from session, then add salt and hash it to reduce length |
630 | - if ( isset( $_REQUEST[ 'EESID' ] ) ) { |
|
631 | - $session_id = sanitize_text_field( $_REQUEST[ 'EESID' ] ); |
|
630 | + if (isset($_REQUEST['EESID'])) { |
|
631 | + $session_id = sanitize_text_field($_REQUEST['EESID']); |
|
632 | 632 | } else { |
633 | - $session_id = md5( session_id() . get_current_blog_id() . $this->_get_sid_salt() ); |
|
633 | + $session_id = md5(session_id().get_current_blog_id().$this->_get_sid_salt()); |
|
634 | 634 | } |
635 | - return apply_filters( 'FHEE__EE_Session___generate_session_id__session_id', $session_id ); |
|
635 | + return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | |
@@ -644,20 +644,20 @@ discard block |
||
644 | 644 | */ |
645 | 645 | protected function _get_sid_salt() { |
646 | 646 | // was session id salt already saved to db ? |
647 | - if ( empty( $this->_sid_salt ) ) { |
|
647 | + if (empty($this->_sid_salt)) { |
|
648 | 648 | // no? then maybe use WP defined constant |
649 | - if ( defined( 'AUTH_SALT' ) ) { |
|
649 | + if (defined('AUTH_SALT')) { |
|
650 | 650 | $this->_sid_salt = AUTH_SALT; |
651 | 651 | } |
652 | 652 | // if salt doesn't exist or is too short |
653 | - if ( strlen( $this->_sid_salt ) < 32 ) { |
|
653 | + if (strlen($this->_sid_salt) < 32) { |
|
654 | 654 | // create a new one |
655 | - $this->_sid_salt = wp_generate_password( 64 ); |
|
655 | + $this->_sid_salt = wp_generate_password(64); |
|
656 | 656 | } |
657 | 657 | // and save it as a permanent session setting |
658 | - $session_settings = get_option( 'ee_session_settings' ); |
|
659 | - $session_settings[ 'sid_salt' ] = $this->_sid_salt; |
|
660 | - update_option( 'ee_session_settings', $session_settings ); |
|
658 | + $session_settings = get_option('ee_session_settings'); |
|
659 | + $session_settings['sid_salt'] = $this->_sid_salt; |
|
660 | + update_option('ee_session_settings', $session_settings); |
|
661 | 661 | } |
662 | 662 | return $this->_sid_salt; |
663 | 663 | } |
@@ -686,19 +686,19 @@ discard block |
||
686 | 686 | * @return TRUE on success, FALSE on fail |
687 | 687 | * @throws \EE_Error |
688 | 688 | */ |
689 | - public function update( $new_session = FALSE ) { |
|
690 | - $this->_session_data = isset( $this->_session_data ) |
|
691 | - && is_array( $this->_session_data ) |
|
692 | - && isset( $this->_session_data['id']) |
|
689 | + public function update($new_session = FALSE) { |
|
690 | + $this->_session_data = isset($this->_session_data) |
|
691 | + && is_array($this->_session_data) |
|
692 | + && isset($this->_session_data['id']) |
|
693 | 693 | ? $this->_session_data |
694 | 694 | : array(); |
695 | - if ( empty( $this->_session_data )) { |
|
695 | + if (empty($this->_session_data)) { |
|
696 | 696 | $this->_set_defaults(); |
697 | 697 | } |
698 | 698 | $session_data = array(); |
699 | - foreach ( $this->_session_data as $key => $value ) { |
|
699 | + foreach ($this->_session_data as $key => $value) { |
|
700 | 700 | |
701 | - switch( $key ) { |
|
701 | + switch ($key) { |
|
702 | 702 | |
703 | 703 | case 'id' : |
704 | 704 | // session ID |
@@ -716,7 +716,7 @@ discard block |
||
716 | 716 | break; |
717 | 717 | |
718 | 718 | case 'init_access' : |
719 | - $session_data['init_access'] = absint( $value ); |
|
719 | + $session_data['init_access'] = absint($value); |
|
720 | 720 | break; |
721 | 721 | |
722 | 722 | case 'last_access' : |
@@ -726,7 +726,7 @@ discard block |
||
726 | 726 | |
727 | 727 | case 'expiration' : |
728 | 728 | // when the session expires |
729 | - $session_data['expiration'] = ! empty( $this->_expiration ) |
|
729 | + $session_data['expiration'] = ! empty($this->_expiration) |
|
730 | 730 | ? $this->_expiration |
731 | 731 | : $session_data['init_access'] + $this->_lifespan; |
732 | 732 | break; |
@@ -738,11 +738,11 @@ discard block |
||
738 | 738 | |
739 | 739 | case 'pages_visited' : |
740 | 740 | $page_visit = $this->_get_page_visit(); |
741 | - if ( $page_visit ) { |
|
741 | + if ($page_visit) { |
|
742 | 742 | // set pages visited where the first will be the http referrer |
743 | - $this->_session_data[ 'pages_visited' ][ $this->_time ] = $page_visit; |
|
743 | + $this->_session_data['pages_visited'][$this->_time] = $page_visit; |
|
744 | 744 | // we'll only save the last 10 page visits. |
745 | - $session_data[ 'pages_visited' ] = array_slice( $this->_session_data['pages_visited'], -10 ); |
|
745 | + $session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10); |
|
746 | 746 | } |
747 | 747 | break; |
748 | 748 | |
@@ -756,9 +756,9 @@ discard block |
||
756 | 756 | |
757 | 757 | $this->_session_data = $session_data; |
758 | 758 | // creating a new session does not require saving to the db just yet |
759 | - if ( ! $new_session ) { |
|
759 | + if ( ! $new_session) { |
|
760 | 760 | // ready? let's save |
761 | - if ( $this->_save_session_to_db() ) { |
|
761 | + if ($this->_save_session_to_db()) { |
|
762 | 762 | return TRUE; |
763 | 763 | } else { |
764 | 764 | return FALSE; |
@@ -778,9 +778,9 @@ discard block |
||
778 | 778 | * @throws \EE_Error |
779 | 779 | */ |
780 | 780 | private function _create_espresso_session( ) { |
781 | - do_action( 'AHEE_log', __CLASS__, __FUNCTION__, '' ); |
|
781 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, ''); |
|
782 | 782 | // use the update function for now with $new_session arg set to TRUE |
783 | - return $this->update( TRUE ) ? TRUE : FALSE; |
|
783 | + return $this->update(TRUE) ? TRUE : FALSE; |
|
784 | 784 | } |
785 | 785 | |
786 | 786 | |
@@ -800,7 +800,7 @@ discard block |
||
800 | 800 | EE_Registry::instance()->REQ->front_ajax |
801 | 801 | || ( |
802 | 802 | // OR an admin request that is NOT AJAX |
803 | - ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) |
|
803 | + ! (defined('DOING_AJAX') && DOING_AJAX) |
|
804 | 804 | && is_admin() |
805 | 805 | ) |
806 | 806 | || ( |
@@ -813,8 +813,8 @@ discard block |
||
813 | 813 | return false; |
814 | 814 | } |
815 | 815 | $transaction = $this->transaction(); |
816 | - if ( $transaction instanceof EE_Transaction ) { |
|
817 | - if ( ! $transaction->ID() ) { |
|
816 | + if ($transaction instanceof EE_Transaction) { |
|
817 | + if ( ! $transaction->ID()) { |
|
818 | 818 | $transaction->save(); |
819 | 819 | } |
820 | 820 | $this->_session_data['transaction'] = $transaction->ID(); |
@@ -823,19 +823,19 @@ discard block |
||
823 | 823 | $session_data = serialize($this->_session_data); |
824 | 824 | // do we need to also encode it to avoid corrupted data when saved to the db? |
825 | 825 | $session_data = $this->_use_encryption |
826 | - ? $this->encryption->base64_string_encode( $session_data ) |
|
826 | + ? $this->encryption->base64_string_encode($session_data) |
|
827 | 827 | : $session_data; |
828 | 828 | // maybe save hash check |
829 | - if ( apply_filters( 'FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG ) ) { |
|
829 | + if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
|
830 | 830 | $this->cache_storage->add( |
831 | - EE_Session::hash_check_prefix . $this->_sid, |
|
831 | + EE_Session::hash_check_prefix.$this->_sid, |
|
832 | 832 | md5($session_data), |
833 | 833 | $this->_lifespan |
834 | 834 | ); |
835 | 835 | } |
836 | 836 | // we're using the Transient API for storing session data, |
837 | 837 | return $this->cache_storage->add( |
838 | - EE_Session::session_id_prefix . $this->_sid, |
|
838 | + EE_Session::session_id_prefix.$this->_sid, |
|
839 | 839 | $session_data, |
840 | 840 | $this->_lifespan |
841 | 841 | ); |
@@ -864,10 +864,10 @@ discard block |
||
864 | 864 | 'HTTP_FORWARDED', |
865 | 865 | 'REMOTE_ADDR' |
866 | 866 | ); |
867 | - foreach ( $server_keys as $key ){ |
|
868 | - if ( isset( $_SERVER[ $key ] )) { |
|
869 | - foreach ( array_map( 'trim', explode( ',', $_SERVER[ $key ] )) as $ip ) { |
|
870 | - if ( $ip === '127.0.0.1' || filter_var( $ip, FILTER_VALIDATE_IP ) !== FALSE ) { |
|
867 | + foreach ($server_keys as $key) { |
|
868 | + if (isset($_SERVER[$key])) { |
|
869 | + foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) { |
|
870 | + if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== FALSE) { |
|
871 | 871 | $visitor_ip = $ip; |
872 | 872 | } |
873 | 873 | } |
@@ -886,32 +886,32 @@ discard block |
||
886 | 886 | * @return string |
887 | 887 | */ |
888 | 888 | public function _get_page_visit() { |
889 | - $page_visit = home_url('/') . 'wp-admin/admin-ajax.php'; |
|
889 | + $page_visit = home_url('/').'wp-admin/admin-ajax.php'; |
|
890 | 890 | // check for request url |
891 | - if ( isset( $_SERVER['REQUEST_URI'] )) { |
|
891 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
892 | 892 | $http_host = ''; |
893 | 893 | $page_id = '?'; |
894 | 894 | $e_reg = ''; |
895 | - $request_uri = esc_url( $_SERVER['REQUEST_URI'] ); |
|
896 | - $ru_bits = explode( '?', $request_uri ); |
|
895 | + $request_uri = esc_url($_SERVER['REQUEST_URI']); |
|
896 | + $ru_bits = explode('?', $request_uri); |
|
897 | 897 | $request_uri = $ru_bits[0]; |
898 | 898 | // check for and grab host as well |
899 | - if ( isset( $_SERVER['HTTP_HOST'] )) { |
|
900 | - $http_host = esc_url( $_SERVER['HTTP_HOST'] ); |
|
899 | + if (isset($_SERVER['HTTP_HOST'])) { |
|
900 | + $http_host = esc_url($_SERVER['HTTP_HOST']); |
|
901 | 901 | } |
902 | 902 | // check for page_id in SERVER REQUEST |
903 | - if ( isset( $_REQUEST['page_id'] )) { |
|
903 | + if (isset($_REQUEST['page_id'])) { |
|
904 | 904 | // rebuild $e_reg without any of the extra parameters |
905 | - $page_id = '?page_id=' . esc_attr( $_REQUEST['page_id'] ) . '&'; |
|
905 | + $page_id = '?page_id='.esc_attr($_REQUEST['page_id']).'&'; |
|
906 | 906 | } |
907 | 907 | // check for $e_reg in SERVER REQUEST |
908 | - if ( isset( $_REQUEST['ee'] )) { |
|
908 | + if (isset($_REQUEST['ee'])) { |
|
909 | 909 | // rebuild $e_reg without any of the extra parameters |
910 | - $e_reg = 'ee=' . esc_attr( $_REQUEST['ee'] ); |
|
910 | + $e_reg = 'ee='.esc_attr($_REQUEST['ee']); |
|
911 | 911 | } |
912 | - $page_visit = rtrim( $http_host . $request_uri . $page_id . $e_reg, '?' ); |
|
912 | + $page_visit = rtrim($http_host.$request_uri.$page_id.$e_reg, '?'); |
|
913 | 913 | } |
914 | - return $page_visit !== home_url( '/wp-admin/admin-ajax.php' ) ? $page_visit : ''; |
|
914 | + return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : ''; |
|
915 | 915 | |
916 | 916 | } |
917 | 917 | |
@@ -941,14 +941,14 @@ discard block |
||
941 | 941 | * @return void |
942 | 942 | * @throws \EE_Error |
943 | 943 | */ |
944 | - public function clear_session( $class = '', $function = '' ) { |
|
944 | + public function clear_session($class = '', $function = '') { |
|
945 | 945 | //echo '<h3 style="color:#999;line-height:.9em;"><span style="color:#2EA2CC">' . __CLASS__ . '</span>::<span style="color:#E76700">' . __FUNCTION__ . '( ' . $class . '::' . $function . '() )</span><br/><span style="font-size:9px;font-weight:normal;">' . __FILE__ . '</span> <b style="font-size:10px;"> ' . __LINE__ . ' </b></h3>'; |
946 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()' ); |
|
946 | + do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : '.$class.'::'.$function.'()'); |
|
947 | 947 | $this->reset_cart(); |
948 | 948 | $this->reset_checkout(); |
949 | 949 | $this->reset_transaction(); |
950 | 950 | // wipe out everything that isn't a default session datum |
951 | - $this->reset_data( array_keys( $this->_session_data )); |
|
951 | + $this->reset_data(array_keys($this->_session_data)); |
|
952 | 952 | // reset initial site access time and the session expiration |
953 | 953 | $this->_set_init_access_and_expiration(); |
954 | 954 | $this->_save_session_to_db(); |
@@ -963,42 +963,42 @@ discard block |
||
963 | 963 | * @param bool $show_all_notices |
964 | 964 | * @return TRUE on success, FALSE on fail |
965 | 965 | */ |
966 | - public function reset_data( $data_to_reset = array(), $show_all_notices = FALSE ) { |
|
966 | + public function reset_data($data_to_reset = array(), $show_all_notices = FALSE) { |
|
967 | 967 | // if $data_to_reset is not in an array, then put it in one |
968 | - if ( ! is_array( $data_to_reset ) ) { |
|
969 | - $data_to_reset = array ( $data_to_reset ); |
|
968 | + if ( ! is_array($data_to_reset)) { |
|
969 | + $data_to_reset = array($data_to_reset); |
|
970 | 970 | } |
971 | 971 | // nothing ??? go home! |
972 | - if ( empty( $data_to_reset )) { |
|
973 | - EE_Error::add_error( __( 'No session data could be reset, because no session var name was provided.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
972 | + if (empty($data_to_reset)) { |
|
973 | + EE_Error::add_error(__('No session data could be reset, because no session var name was provided.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
974 | 974 | return FALSE; |
975 | 975 | } |
976 | 976 | $return_value = TRUE; |
977 | 977 | // since $data_to_reset is an array, cycle through the values |
978 | - foreach ( $data_to_reset as $reset ) { |
|
978 | + foreach ($data_to_reset as $reset) { |
|
979 | 979 | |
980 | 980 | // first check to make sure it is a valid session var |
981 | - if ( isset( $this->_session_data[ $reset ] )) { |
|
981 | + if (isset($this->_session_data[$reset])) { |
|
982 | 982 | // then check to make sure it is not a default var |
983 | - if ( ! array_key_exists( $reset, $this->_default_session_vars )) { |
|
983 | + if ( ! array_key_exists($reset, $this->_default_session_vars)) { |
|
984 | 984 | // remove session var |
985 | - unset( $this->_session_data[ $reset ] ); |
|
986 | - if ( $show_all_notices ) { |
|
987 | - EE_Error::add_success( sprintf( __( 'The session variable %s was removed.', 'event_espresso' ), $reset ), __FILE__, __FUNCTION__, __LINE__ ); |
|
985 | + unset($this->_session_data[$reset]); |
|
986 | + if ($show_all_notices) { |
|
987 | + EE_Error::add_success(sprintf(__('The session variable %s was removed.', 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__); |
|
988 | 988 | } |
989 | - $return_value = !isset($return_value) ? TRUE : $return_value; |
|
989 | + $return_value = ! isset($return_value) ? TRUE : $return_value; |
|
990 | 990 | |
991 | 991 | } else { |
992 | 992 | // yeeeeeeeeerrrrrrrrrrr OUT !!!! |
993 | - if ( $show_all_notices ) { |
|
994 | - EE_Error::add_error( sprintf( __( 'Sorry! %s is a default session datum and can not be reset.', 'event_espresso' ), $reset ), __FILE__, __FUNCTION__, __LINE__ ); |
|
993 | + if ($show_all_notices) { |
|
994 | + EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.', 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__); |
|
995 | 995 | } |
996 | 996 | $return_value = FALSE; |
997 | 997 | } |
998 | 998 | |
999 | - } else if ( $show_all_notices ) { |
|
999 | + } else if ($show_all_notices) { |
|
1000 | 1000 | // oops! that session var does not exist! |
1001 | - EE_Error::add_error( sprintf( __( 'The session item provided, %s, is invalid or does not exist.', 'event_espresso' ), $reset ), __FILE__, __FUNCTION__, __LINE__ ); |
|
1001 | + EE_Error::add_error(sprintf(__('The session item provided, %s, is invalid or does not exist.', 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__); |
|
1002 | 1002 | $return_value = FALSE; |
1003 | 1003 | } |
1004 | 1004 | |
@@ -1017,8 +1017,8 @@ discard block |
||
1017 | 1017 | * @throws \EE_Error |
1018 | 1018 | */ |
1019 | 1019 | public function wp_loaded() { |
1020 | - if ( isset( EE_Registry::instance()->REQ ) && EE_Registry::instance()->REQ->is_set( 'clear_session' )) { |
|
1021 | - $this->clear_session( __CLASS__, __FUNCTION__ ); |
|
1020 | + if (isset(EE_Registry::instance()->REQ) && EE_Registry::instance()->REQ->is_set('clear_session')) { |
|
1021 | + $this->clear_session(__CLASS__, __FUNCTION__); |
|
1022 | 1022 | } |
1023 | 1023 | } |
1024 | 1024 | |
@@ -1054,7 +1054,7 @@ discard block |
||
1054 | 1054 | // or use that for the new transient cleanup query limit |
1055 | 1055 | add_filter( |
1056 | 1056 | 'FHEE__TransientCacheStorage__clearExpiredTransients__limit', |
1057 | - function () use ($expired_session_transient_delete_query_limit) { |
|
1057 | + function() use ($expired_session_transient_delete_query_limit) { |
|
1058 | 1058 | return $expired_session_transient_delete_query_limit; |
1059 | 1059 | } |
1060 | 1060 | ); |
@@ -1068,34 +1068,34 @@ discard block |
||
1068 | 1068 | * @param $data1 |
1069 | 1069 | * @return string |
1070 | 1070 | */ |
1071 | - private function find_serialize_error( $data1 ) { |
|
1071 | + private function find_serialize_error($data1) { |
|
1072 | 1072 | $error = '<pre>'; |
1073 | 1073 | $data2 = preg_replace_callback( |
1074 | 1074 | '!s:(\d+):"(.*?)";!', |
1075 | - function ( $match ) { |
|
1076 | - return ( $match[1] === strlen( $match[2] ) ) |
|
1075 | + function($match) { |
|
1076 | + return ($match[1] === strlen($match[2])) |
|
1077 | 1077 | ? $match[0] |
1078 | 1078 | : 's:' |
1079 | - . strlen( $match[2] ) |
|
1079 | + . strlen($match[2]) |
|
1080 | 1080 | . ':"' |
1081 | 1081 | . $match[2] |
1082 | 1082 | . '";'; |
1083 | 1083 | }, |
1084 | 1084 | $data1 |
1085 | 1085 | ); |
1086 | - $max = ( strlen( $data1 ) > strlen( $data2 ) ) ? strlen( $data1 ) : strlen( $data2 ); |
|
1087 | - $error .= $data1 . PHP_EOL; |
|
1088 | - $error .= $data2 . PHP_EOL; |
|
1089 | - for ( $i = 0; $i < $max; $i++ ) { |
|
1090 | - if ( @$data1[ $i ] !== @$data2[ $i ] ) { |
|
1091 | - $error .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL; |
|
1092 | - $error .= "\t-> ORD number " . ord( @$data1[ $i ] ) . ' != ' . ord( @$data2[ $i ] ) . PHP_EOL; |
|
1093 | - $error .= "\t-> Line Number = $i" . PHP_EOL; |
|
1094 | - $start = ( $i - 20 ); |
|
1095 | - $start = ( $start < 0 ) ? 0 : $start; |
|
1086 | + $max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2); |
|
1087 | + $error .= $data1.PHP_EOL; |
|
1088 | + $error .= $data2.PHP_EOL; |
|
1089 | + for ($i = 0; $i < $max; $i++) { |
|
1090 | + if (@$data1[$i] !== @$data2[$i]) { |
|
1091 | + $error .= 'Difference '.@$data1[$i].' != '.@$data2[$i].PHP_EOL; |
|
1092 | + $error .= "\t-> ORD number ".ord(@$data1[$i]).' != '.ord(@$data2[$i]).PHP_EOL; |
|
1093 | + $error .= "\t-> Line Number = $i".PHP_EOL; |
|
1094 | + $start = ($i - 20); |
|
1095 | + $start = ($start < 0) ? 0 : $start; |
|
1096 | 1096 | $length = 40; |
1097 | 1097 | $point = $max - $i; |
1098 | - if ( $point < 20 ) { |
|
1098 | + if ($point < 20) { |
|
1099 | 1099 | $rlength = 1; |
1100 | 1100 | $rpoint = -$point; |
1101 | 1101 | } else { |
@@ -1104,16 +1104,16 @@ discard block |
||
1104 | 1104 | } |
1105 | 1105 | $error .= "\t-> Section Data1 = "; |
1106 | 1106 | $error .= substr_replace( |
1107 | - substr( $data1, $start, $length ), |
|
1108 | - "<b style=\"color:green\">{$data1[ $i ]}</b>", |
|
1107 | + substr($data1, $start, $length), |
|
1108 | + "<b style=\"color:green\">{$data1[$i]}</b>", |
|
1109 | 1109 | $rpoint, |
1110 | 1110 | $rlength |
1111 | 1111 | ); |
1112 | 1112 | $error .= PHP_EOL; |
1113 | 1113 | $error .= "\t-> Section Data2 = "; |
1114 | 1114 | $error .= substr_replace( |
1115 | - substr( $data2, $start, $length ), |
|
1116 | - "<b style=\"color:red\">{$data2[ $i ]}</b>", |
|
1115 | + substr($data2, $start, $length), |
|
1116 | + "<b style=\"color:red\">{$data2[$i]}</b>", |
|
1117 | 1117 | $rpoint, |
1118 | 1118 | $rlength |
1119 | 1119 | ); |
@@ -24,82 +24,82 @@ |
||
24 | 24 | |
25 | 25 | |
26 | 26 | |
27 | - /** |
|
28 | - * the actual shortcode tag that gets registered with WordPress |
|
29 | - * |
|
30 | - * @return string |
|
31 | - */ |
|
32 | - public function getTag() |
|
33 | - { |
|
34 | - return 'ESPRESSO_TICKET_SELECTOR'; |
|
35 | - } |
|
36 | - |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * the time in seconds to cache the results of the processShortcode() method |
|
41 | - * 0 means the processShortcode() results will NOT be cached at all |
|
42 | - * |
|
43 | - * @return int |
|
44 | - */ |
|
45 | - public function cacheExpiration() |
|
46 | - { |
|
47 | - return MINUTE_IN_SECONDS; |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * a place for adding any initialization code that needs to run prior to wp_header(). |
|
53 | - * this may be required for shortcodes that utilize a corresponding module, |
|
54 | - * and need to enqueue assets for that module |
|
55 | - * |
|
56 | - * @return void |
|
57 | - */ |
|
58 | - public function initializeShortcode() |
|
59 | - { |
|
60 | - add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
61 | - $this->shortcodeHasBeenInitialized(); |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * callback that runs when the shortcode is encountered in post content. |
|
68 | - * IMPORTANT !!! |
|
69 | - * remember that shortcode content should be RETURNED and NOT echoed out |
|
70 | - * |
|
71 | - * @param array $attributes |
|
72 | - * @return string |
|
73 | - * @throws InvalidArgumentException |
|
74 | - */ |
|
75 | - public function processShortcode($attributes = array()) |
|
76 | - { |
|
77 | - extract($attributes, EXTR_OVERWRITE); |
|
78 | - $event_id = isset($event_id) ? $event_id : 0; |
|
79 | - $event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($event_id); |
|
80 | - if (! $event instanceof EE_Event) { |
|
81 | - new ExceptionStackTraceDisplay( |
|
82 | - new InvalidArgumentException( |
|
83 | - sprintf( |
|
84 | - esc_html__( |
|
85 | - 'A valid Event ID is required to use the "%1$s" shortcode.%4$sAn Event with an ID of "%2$s" could not be found.%4$sPlease verify that the shortcode added to this post\'s content includes an "%3$s" argument and that it\'s value corresponds to a valid Event ID.', |
|
86 | - 'event_espresso' |
|
87 | - ), |
|
88 | - $this->getTag(), |
|
89 | - $event_id, |
|
90 | - 'event_id', |
|
91 | - '<br />' |
|
92 | - ) |
|
93 | - ) |
|
94 | - ); |
|
95 | - return ''; |
|
96 | - } |
|
97 | - ob_start(); |
|
98 | - do_action('AHEE_event_details_before_post', $event_id); |
|
99 | - espresso_ticket_selector($event); |
|
100 | - do_action('AHEE_event_details_after_post'); |
|
101 | - return ob_get_clean(); |
|
102 | - } |
|
27 | + /** |
|
28 | + * the actual shortcode tag that gets registered with WordPress |
|
29 | + * |
|
30 | + * @return string |
|
31 | + */ |
|
32 | + public function getTag() |
|
33 | + { |
|
34 | + return 'ESPRESSO_TICKET_SELECTOR'; |
|
35 | + } |
|
36 | + |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * the time in seconds to cache the results of the processShortcode() method |
|
41 | + * 0 means the processShortcode() results will NOT be cached at all |
|
42 | + * |
|
43 | + * @return int |
|
44 | + */ |
|
45 | + public function cacheExpiration() |
|
46 | + { |
|
47 | + return MINUTE_IN_SECONDS; |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * a place for adding any initialization code that needs to run prior to wp_header(). |
|
53 | + * this may be required for shortcodes that utilize a corresponding module, |
|
54 | + * and need to enqueue assets for that module |
|
55 | + * |
|
56 | + * @return void |
|
57 | + */ |
|
58 | + public function initializeShortcode() |
|
59 | + { |
|
60 | + add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
61 | + $this->shortcodeHasBeenInitialized(); |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * callback that runs when the shortcode is encountered in post content. |
|
68 | + * IMPORTANT !!! |
|
69 | + * remember that shortcode content should be RETURNED and NOT echoed out |
|
70 | + * |
|
71 | + * @param array $attributes |
|
72 | + * @return string |
|
73 | + * @throws InvalidArgumentException |
|
74 | + */ |
|
75 | + public function processShortcode($attributes = array()) |
|
76 | + { |
|
77 | + extract($attributes, EXTR_OVERWRITE); |
|
78 | + $event_id = isset($event_id) ? $event_id : 0; |
|
79 | + $event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($event_id); |
|
80 | + if (! $event instanceof EE_Event) { |
|
81 | + new ExceptionStackTraceDisplay( |
|
82 | + new InvalidArgumentException( |
|
83 | + sprintf( |
|
84 | + esc_html__( |
|
85 | + 'A valid Event ID is required to use the "%1$s" shortcode.%4$sAn Event with an ID of "%2$s" could not be found.%4$sPlease verify that the shortcode added to this post\'s content includes an "%3$s" argument and that it\'s value corresponds to a valid Event ID.', |
|
86 | + 'event_espresso' |
|
87 | + ), |
|
88 | + $this->getTag(), |
|
89 | + $event_id, |
|
90 | + 'event_id', |
|
91 | + '<br />' |
|
92 | + ) |
|
93 | + ) |
|
94 | + ); |
|
95 | + return ''; |
|
96 | + } |
|
97 | + ob_start(); |
|
98 | + do_action('AHEE_event_details_before_post', $event_id); |
|
99 | + espresso_ticket_selector($event); |
|
100 | + do_action('AHEE_event_details_after_post'); |
|
101 | + return ob_get_clean(); |
|
102 | + } |
|
103 | 103 | |
104 | 104 | |
105 | 105 | } |
@@ -77,7 +77,7 @@ |
||
77 | 77 | extract($attributes, EXTR_OVERWRITE); |
78 | 78 | $event_id = isset($event_id) ? $event_id : 0; |
79 | 79 | $event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($event_id); |
80 | - if (! $event instanceof EE_Event) { |
|
80 | + if ( ! $event instanceof EE_Event) { |
|
81 | 81 | new ExceptionStackTraceDisplay( |
82 | 82 | new InvalidArgumentException( |
83 | 83 | sprintf( |
@@ -34,139 +34,139 @@ |
||
34 | 34 | |
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * the actual shortcode tag that gets registered with WordPress |
|
39 | - * |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - public function getTag() |
|
43 | - { |
|
44 | - return 'ESPRESSO_EVENTS'; |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * the time in seconds to cache the results of the processShortcode() method |
|
51 | - * 0 means the processShortcode() results will NOT be cached at all |
|
52 | - * |
|
53 | - * @return int |
|
54 | - */ |
|
55 | - public function cacheExpiration() |
|
56 | - { |
|
57 | - return MINUTE_IN_SECONDS * 5; |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * a place for adding any initialization code that needs to run prior to wp_header(). |
|
64 | - * this may be required for shortcodes that utilize a corresponding module, |
|
65 | - * and need to enqueue assets for that module |
|
66 | - * |
|
67 | - * @return void |
|
68 | - */ |
|
69 | - public function initializeShortcode() |
|
70 | - { |
|
71 | - EED_Events_Archive::instance()->event_list(); |
|
72 | - $this->shortcodeHasBeenInitialized(); |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * callback that runs when the shortcode is encountered in post content. |
|
79 | - * IMPORTANT !!! |
|
80 | - * remember that shortcode content should be RETURNED and NOT echoed out |
|
81 | - * |
|
82 | - * @param array $attributes |
|
83 | - * @return string |
|
84 | - */ |
|
85 | - public function processShortcode($attributes = array()) |
|
86 | - { |
|
87 | - // grab attributes and merge with defaults |
|
88 | - $attributes = $this->getAttributes($attributes); |
|
89 | - // make sure we use the_excerpt() |
|
90 | - add_filter('FHEE__EES_Espresso_Events__process_shortcode__true', '__return_true'); |
|
91 | - // apply query filters |
|
92 | - add_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true'); |
|
93 | - // run the query |
|
94 | - global $wp_query; |
|
95 | - // yes we have to overwrite the main wp query, but it's ok... |
|
96 | - // we're going to reset it again below, so everything will be Hunky Dory (amazing album) |
|
97 | - $wp_query = new EventListQuery($attributes); |
|
98 | - // check what template is loaded and load filters accordingly |
|
99 | - EED_Events_Archive::instance()->template_include('loop-espresso_events.php'); |
|
100 | - // load our template |
|
101 | - $event_list = EEH_Template::locate_template( |
|
102 | - 'loop-espresso_events.php', |
|
103 | - array(), |
|
104 | - true, |
|
105 | - true |
|
106 | - ); |
|
107 | - // now reset the query and post data |
|
108 | - wp_reset_query(); |
|
109 | - wp_reset_postdata(); |
|
110 | - EED_Events_Archive::remove_all_events_archive_filters(); |
|
111 | - // remove query filters |
|
112 | - remove_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true'); |
|
113 | - // pull our content from the output buffer and return it |
|
114 | - return $event_list; |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * merge incoming attributes with filtered defaults |
|
121 | - * |
|
122 | - * @param array $attributes |
|
123 | - * @return array |
|
124 | - */ |
|
125 | - private function getAttributes(array $attributes) |
|
126 | - { |
|
127 | - return array_merge( |
|
128 | - (array)apply_filters( |
|
129 | - 'EES_Espresso_Events__process_shortcode__default_espresso_events_shortcode_atts', |
|
130 | - array( |
|
131 | - 'title' => '', |
|
132 | - 'limit' => 10, |
|
133 | - 'css_class' => '', |
|
134 | - 'show_expired' => false, |
|
135 | - 'month' => '', |
|
136 | - 'category_slug' => '', |
|
137 | - 'order_by' => 'start_date', |
|
138 | - 'sort' => 'ASC', |
|
139 | - 'show_title' => true, |
|
140 | - ) |
|
141 | - ), |
|
142 | - $attributes |
|
143 | - ); |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * array for defining custom attribute sanitization callbacks, |
|
150 | - * where keys match keys in your attributes array, |
|
151 | - * and values represent the sanitization function you wish to be applied to that attribute. |
|
152 | - * So for example, if you had an integer attribute named "event_id" |
|
153 | - * that you wanted to be sanitized using absint(), |
|
154 | - * then you would pass the following for your $custom_sanitization array: |
|
155 | - * array('event_id' => 'absint') |
|
156 | - * |
|
157 | - * @return array |
|
158 | - */ |
|
159 | - protected function customAttributeSanitizationMap() |
|
160 | - { |
|
161 | - // the following get sanitized/whitelisted in EEH_Event_Query |
|
162 | - return array( |
|
163 | - 'category_slug' => 'skip_sanitization', |
|
164 | - 'show_expired' => 'skip_sanitization', |
|
165 | - 'order_by' => 'skip_sanitization', |
|
166 | - 'month' => 'skip_sanitization', |
|
167 | - 'sort' => 'skip_sanitization', |
|
168 | - ); |
|
169 | - } |
|
37 | + /** |
|
38 | + * the actual shortcode tag that gets registered with WordPress |
|
39 | + * |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + public function getTag() |
|
43 | + { |
|
44 | + return 'ESPRESSO_EVENTS'; |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * the time in seconds to cache the results of the processShortcode() method |
|
51 | + * 0 means the processShortcode() results will NOT be cached at all |
|
52 | + * |
|
53 | + * @return int |
|
54 | + */ |
|
55 | + public function cacheExpiration() |
|
56 | + { |
|
57 | + return MINUTE_IN_SECONDS * 5; |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * a place for adding any initialization code that needs to run prior to wp_header(). |
|
64 | + * this may be required for shortcodes that utilize a corresponding module, |
|
65 | + * and need to enqueue assets for that module |
|
66 | + * |
|
67 | + * @return void |
|
68 | + */ |
|
69 | + public function initializeShortcode() |
|
70 | + { |
|
71 | + EED_Events_Archive::instance()->event_list(); |
|
72 | + $this->shortcodeHasBeenInitialized(); |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * callback that runs when the shortcode is encountered in post content. |
|
79 | + * IMPORTANT !!! |
|
80 | + * remember that shortcode content should be RETURNED and NOT echoed out |
|
81 | + * |
|
82 | + * @param array $attributes |
|
83 | + * @return string |
|
84 | + */ |
|
85 | + public function processShortcode($attributes = array()) |
|
86 | + { |
|
87 | + // grab attributes and merge with defaults |
|
88 | + $attributes = $this->getAttributes($attributes); |
|
89 | + // make sure we use the_excerpt() |
|
90 | + add_filter('FHEE__EES_Espresso_Events__process_shortcode__true', '__return_true'); |
|
91 | + // apply query filters |
|
92 | + add_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true'); |
|
93 | + // run the query |
|
94 | + global $wp_query; |
|
95 | + // yes we have to overwrite the main wp query, but it's ok... |
|
96 | + // we're going to reset it again below, so everything will be Hunky Dory (amazing album) |
|
97 | + $wp_query = new EventListQuery($attributes); |
|
98 | + // check what template is loaded and load filters accordingly |
|
99 | + EED_Events_Archive::instance()->template_include('loop-espresso_events.php'); |
|
100 | + // load our template |
|
101 | + $event_list = EEH_Template::locate_template( |
|
102 | + 'loop-espresso_events.php', |
|
103 | + array(), |
|
104 | + true, |
|
105 | + true |
|
106 | + ); |
|
107 | + // now reset the query and post data |
|
108 | + wp_reset_query(); |
|
109 | + wp_reset_postdata(); |
|
110 | + EED_Events_Archive::remove_all_events_archive_filters(); |
|
111 | + // remove query filters |
|
112 | + remove_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true'); |
|
113 | + // pull our content from the output buffer and return it |
|
114 | + return $event_list; |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * merge incoming attributes with filtered defaults |
|
121 | + * |
|
122 | + * @param array $attributes |
|
123 | + * @return array |
|
124 | + */ |
|
125 | + private function getAttributes(array $attributes) |
|
126 | + { |
|
127 | + return array_merge( |
|
128 | + (array)apply_filters( |
|
129 | + 'EES_Espresso_Events__process_shortcode__default_espresso_events_shortcode_atts', |
|
130 | + array( |
|
131 | + 'title' => '', |
|
132 | + 'limit' => 10, |
|
133 | + 'css_class' => '', |
|
134 | + 'show_expired' => false, |
|
135 | + 'month' => '', |
|
136 | + 'category_slug' => '', |
|
137 | + 'order_by' => 'start_date', |
|
138 | + 'sort' => 'ASC', |
|
139 | + 'show_title' => true, |
|
140 | + ) |
|
141 | + ), |
|
142 | + $attributes |
|
143 | + ); |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * array for defining custom attribute sanitization callbacks, |
|
150 | + * where keys match keys in your attributes array, |
|
151 | + * and values represent the sanitization function you wish to be applied to that attribute. |
|
152 | + * So for example, if you had an integer attribute named "event_id" |
|
153 | + * that you wanted to be sanitized using absint(), |
|
154 | + * then you would pass the following for your $custom_sanitization array: |
|
155 | + * array('event_id' => 'absint') |
|
156 | + * |
|
157 | + * @return array |
|
158 | + */ |
|
159 | + protected function customAttributeSanitizationMap() |
|
160 | + { |
|
161 | + // the following get sanitized/whitelisted in EEH_Event_Query |
|
162 | + return array( |
|
163 | + 'category_slug' => 'skip_sanitization', |
|
164 | + 'show_expired' => 'skip_sanitization', |
|
165 | + 'order_by' => 'skip_sanitization', |
|
166 | + 'month' => 'skip_sanitization', |
|
167 | + 'sort' => 'skip_sanitization', |
|
168 | + ); |
|
169 | + } |
|
170 | 170 | |
171 | 171 | |
172 | 172 |
@@ -5,9 +5,9 @@ |
||
5 | 5 | interface SessionIdentifierInterface |
6 | 6 | { |
7 | 7 | |
8 | - /** |
|
9 | - * @return string |
|
10 | - */ |
|
11 | - public function id(); |
|
8 | + /** |
|
9 | + * @return string |
|
10 | + */ |
|
11 | + public function id(); |
|
12 | 12 | |
13 | 13 | } |
14 | 14 | \ No newline at end of file |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use EventEspresso\core\services\loaders\LoaderInterface; |
5 | 5 | |
6 | 6 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
7 | - exit('No direct script access allowed'); |
|
7 | + exit('No direct script access allowed'); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | |
@@ -22,660 +22,660 @@ discard block |
||
22 | 22 | { |
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * This means that the requested class dependency is not present in the dependency map |
|
27 | - */ |
|
28 | - const not_registered = 0; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
33 | - */ |
|
34 | - const load_new_object = 1; |
|
35 | - |
|
36 | - /** |
|
37 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
38 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
39 | - */ |
|
40 | - const load_from_cache = 2; |
|
41 | - |
|
42 | - /** |
|
43 | - * @type EE_Dependency_Map $_instance |
|
44 | - */ |
|
45 | - protected static $_instance; |
|
46 | - |
|
47 | - /** |
|
48 | - * @type EE_Request $request |
|
49 | - */ |
|
50 | - protected $_request; |
|
51 | - |
|
52 | - /** |
|
53 | - * @type EE_Response $response |
|
54 | - */ |
|
55 | - protected $_response; |
|
56 | - |
|
57 | - /** |
|
58 | - * @type LoaderInterface $loader |
|
59 | - */ |
|
60 | - protected $loader; |
|
61 | - |
|
62 | - /** |
|
63 | - * @type array $_dependency_map |
|
64 | - */ |
|
65 | - protected $_dependency_map = array(); |
|
66 | - |
|
67 | - /** |
|
68 | - * @type array $_class_loaders |
|
69 | - */ |
|
70 | - protected $_class_loaders = array(); |
|
71 | - |
|
72 | - /** |
|
73 | - * @type array $_aliases |
|
74 | - */ |
|
75 | - protected $_aliases = array(); |
|
76 | - |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * EE_Dependency_Map constructor. |
|
81 | - * |
|
82 | - * @param EE_Request $request |
|
83 | - * @param EE_Response $response |
|
84 | - */ |
|
85 | - protected function __construct(EE_Request $request, EE_Response $response) |
|
86 | - { |
|
87 | - $this->_request = $request; |
|
88 | - $this->_response = $response; |
|
89 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
90 | - do_action('EE_Dependency_Map____construct'); |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * @throws InvalidDataTypeException |
|
97 | - * @throws InvalidInterfaceException |
|
98 | - * @throws InvalidArgumentException |
|
99 | - */ |
|
100 | - public function initialize() |
|
101 | - { |
|
102 | - $this->_register_core_dependencies(); |
|
103 | - $this->_register_core_class_loaders(); |
|
104 | - $this->_register_core_aliases(); |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * @singleton method used to instantiate class object |
|
111 | - * @access public |
|
112 | - * @param EE_Request $request |
|
113 | - * @param EE_Response $response |
|
114 | - * @return EE_Dependency_Map |
|
115 | - */ |
|
116 | - public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
117 | - { |
|
118 | - // check if class object is instantiated, and instantiated properly |
|
119 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
120 | - self::$_instance = new EE_Dependency_Map($request, $response); |
|
121 | - } |
|
122 | - return self::$_instance; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * @param LoaderInterface $loader |
|
129 | - */ |
|
130 | - public function setLoader(LoaderInterface $loader) |
|
131 | - { |
|
132 | - $this->loader = $loader; |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * @param string $class |
|
139 | - * @param array $dependencies |
|
140 | - * @return boolean |
|
141 | - */ |
|
142 | - public static function register_dependencies($class, $dependencies) |
|
143 | - { |
|
144 | - if (! isset(self::$_instance->_dependency_map[$class])) { |
|
145 | - // we need to make sure that any aliases used when registering a dependency |
|
146 | - // get resolved to the correct class name |
|
147 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
148 | - $alias = self::$_instance->get_alias($dependency); |
|
149 | - unset($dependencies[$dependency]); |
|
150 | - $dependencies[$alias] = $load_source; |
|
151 | - } |
|
152 | - self::$_instance->_dependency_map[$class] = (array)$dependencies; |
|
153 | - return true; |
|
154 | - } |
|
155 | - return false; |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * @param string $class_name |
|
162 | - * @param string $loader |
|
163 | - * @return bool |
|
164 | - * @throws EE_Error |
|
165 | - */ |
|
166 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
167 | - { |
|
168 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
169 | - if ( |
|
170 | - ! is_callable($loader) |
|
171 | - && ( |
|
172 | - strpos($loader, 'load_') !== 0 |
|
173 | - || ! method_exists('EE_Registry', $loader) |
|
174 | - ) |
|
175 | - ) { |
|
176 | - throw new EE_Error( |
|
177 | - sprintf( |
|
178 | - esc_html__('"%1$s" is not a valid loader method on EE_Registry.', 'event_espresso'), |
|
179 | - $loader |
|
180 | - ) |
|
181 | - ); |
|
182 | - } |
|
183 | - $class_name = self::$_instance->get_alias($class_name); |
|
184 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
185 | - self::$_instance->_class_loaders[$class_name] = $loader; |
|
186 | - return true; |
|
187 | - } |
|
188 | - return false; |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * @return array |
|
195 | - */ |
|
196 | - public function dependency_map() |
|
197 | - { |
|
198 | - return $this->_dependency_map; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
205 | - * |
|
206 | - * @param string $class_name |
|
207 | - * @return boolean |
|
208 | - */ |
|
209 | - public function has($class_name = '') |
|
210 | - { |
|
211 | - return isset($this->_dependency_map[$class_name]) ? true : false; |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
218 | - * |
|
219 | - * @param string $class_name |
|
220 | - * @param string $dependency |
|
221 | - * @return bool |
|
222 | - */ |
|
223 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
224 | - { |
|
225 | - $dependency = $this->get_alias($dependency); |
|
226 | - return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
227 | - ? true |
|
228 | - : false; |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
235 | - * |
|
236 | - * @param string $class_name |
|
237 | - * @param string $dependency |
|
238 | - * @return int |
|
239 | - */ |
|
240 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
241 | - { |
|
242 | - $dependency = $this->get_alias($dependency); |
|
243 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
244 | - ? $this->_dependency_map[$class_name][$dependency] |
|
245 | - : EE_Dependency_Map::not_registered; |
|
246 | - } |
|
247 | - |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * @param string $class_name |
|
252 | - * @return string | Closure |
|
253 | - */ |
|
254 | - public function class_loader($class_name) |
|
255 | - { |
|
256 | - // don't use loaders for FQCNs |
|
257 | - if(strpos($class_name, '\\') !== false){ |
|
258 | - return ''; |
|
259 | - } |
|
260 | - $class_name = $this->get_alias($class_name); |
|
261 | - return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
262 | - } |
|
263 | - |
|
264 | - |
|
265 | - |
|
266 | - /** |
|
267 | - * @return array |
|
268 | - */ |
|
269 | - public function class_loaders() |
|
270 | - { |
|
271 | - return $this->_class_loaders; |
|
272 | - } |
|
273 | - |
|
274 | - |
|
275 | - |
|
276 | - /** |
|
277 | - * adds an alias for a classname |
|
278 | - * |
|
279 | - * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
280 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
281 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
282 | - */ |
|
283 | - public function add_alias($class_name, $alias, $for_class = '') |
|
284 | - { |
|
285 | - if ($for_class !== '') { |
|
286 | - if (! isset($this->_aliases[$for_class])) { |
|
287 | - $this->_aliases[$for_class] = array(); |
|
288 | - } |
|
289 | - $this->_aliases[$for_class][$class_name] = $alias; |
|
290 | - } |
|
291 | - $this->_aliases[$class_name] = $alias; |
|
292 | - } |
|
293 | - |
|
294 | - |
|
295 | - |
|
296 | - /** |
|
297 | - * returns TRUE if the provided class name has an alias |
|
298 | - * |
|
299 | - * @param string $class_name |
|
300 | - * @param string $for_class |
|
301 | - * @return bool |
|
302 | - */ |
|
303 | - public function has_alias($class_name = '', $for_class = '') |
|
304 | - { |
|
305 | - return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
306 | - || ( |
|
307 | - isset($this->_aliases[$class_name]) |
|
308 | - && ! is_array($this->_aliases[$class_name]) |
|
309 | - ); |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - |
|
314 | - /** |
|
315 | - * returns alias for class name if one exists, otherwise returns the original classname |
|
316 | - * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
317 | - * for example: |
|
318 | - * if the following two entries were added to the _aliases array: |
|
319 | - * array( |
|
320 | - * 'interface_alias' => 'some\namespace\interface' |
|
321 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
322 | - * ) |
|
323 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
324 | - * to load an instance of 'some\namespace\classname' |
|
325 | - * |
|
326 | - * @param string $class_name |
|
327 | - * @param string $for_class |
|
328 | - * @return string |
|
329 | - */ |
|
330 | - public function get_alias($class_name = '', $for_class = '') |
|
331 | - { |
|
332 | - if (! $this->has_alias($class_name, $for_class)) { |
|
333 | - return $class_name; |
|
334 | - } |
|
335 | - if ($for_class !== '') { |
|
336 | - return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
337 | - } |
|
338 | - return $this->get_alias($this->_aliases[$class_name]); |
|
339 | - } |
|
340 | - |
|
341 | - |
|
342 | - |
|
343 | - /** |
|
344 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
345 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
346 | - * This is done by using the following class constants: |
|
347 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
348 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
349 | - */ |
|
350 | - protected function _register_core_dependencies() |
|
351 | - { |
|
352 | - $this->_dependency_map = array( |
|
353 | - 'EE_Request_Handler' => array( |
|
354 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
355 | - ), |
|
356 | - 'EE_System' => array( |
|
357 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
358 | - ), |
|
359 | - 'EE_Session' => array( |
|
360 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
361 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
362 | - ), |
|
363 | - 'EE_Cart' => array( |
|
364 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
365 | - ), |
|
366 | - 'EE_Front_Controller' => array( |
|
367 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
368 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
369 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
370 | - ), |
|
371 | - 'EE_Messenger_Collection_Loader' => array( |
|
372 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
373 | - ), |
|
374 | - 'EE_Message_Type_Collection_Loader' => array( |
|
375 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
376 | - ), |
|
377 | - 'EE_Message_Resource_Manager' => array( |
|
378 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
379 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
380 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
381 | - ), |
|
382 | - 'EE_Message_Factory' => array( |
|
383 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
384 | - ), |
|
385 | - 'EE_messages' => array( |
|
386 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
387 | - ), |
|
388 | - 'EE_Messages_Generator' => array( |
|
389 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
390 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
391 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
392 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
393 | - ), |
|
394 | - 'EE_Messages_Processor' => array( |
|
395 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
396 | - ), |
|
397 | - 'EE_Messages_Queue' => array( |
|
398 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
399 | - ), |
|
400 | - 'EE_Messages_Template_Defaults' => array( |
|
401 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
402 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
403 | - ), |
|
404 | - 'EE_Message_To_Generate_From_Request' => array( |
|
405 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
406 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
407 | - ), |
|
408 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
409 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
410 | - ), |
|
411 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
412 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
413 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
414 | - ), |
|
415 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
416 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
417 | - ), |
|
418 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
419 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
420 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
421 | - ), |
|
422 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
423 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
424 | - ), |
|
425 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
426 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
427 | - ), |
|
428 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
429 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
430 | - ), |
|
431 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
432 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
433 | - ), |
|
434 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
435 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
436 | - ), |
|
437 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
438 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
439 | - ), |
|
440 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
441 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
442 | - ), |
|
443 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
444 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
445 | - ), |
|
446 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
447 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
448 | - ), |
|
449 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
450 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
451 | - ), |
|
452 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
453 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
454 | - ), |
|
455 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
456 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
457 | - ), |
|
458 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
459 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
460 | - ), |
|
461 | - 'EE_Data_Migration_Class_Base' => array( |
|
462 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
463 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
464 | - ), |
|
465 | - 'EE_DMS_Core_4_1_0' => array( |
|
466 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
467 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
468 | - ), |
|
469 | - 'EE_DMS_Core_4_2_0' => array( |
|
470 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
471 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
472 | - ), |
|
473 | - 'EE_DMS_Core_4_3_0' => array( |
|
474 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
475 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
476 | - ), |
|
477 | - 'EE_DMS_Core_4_4_0' => array( |
|
478 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
479 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
480 | - ), |
|
481 | - 'EE_DMS_Core_4_5_0' => array( |
|
482 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
483 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
484 | - ), |
|
485 | - 'EE_DMS_Core_4_6_0' => array( |
|
486 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
487 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
488 | - ), |
|
489 | - 'EE_DMS_Core_4_7_0' => array( |
|
490 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
491 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
492 | - ), |
|
493 | - 'EE_DMS_Core_4_8_0' => array( |
|
494 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
495 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
496 | - ), |
|
497 | - 'EE_DMS_Core_4_9_0' => array( |
|
498 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
499 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
500 | - ), |
|
501 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
502 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
503 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
504 | - ), |
|
505 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
506 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
507 | - ), |
|
508 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
509 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
510 | - ), |
|
511 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
512 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
513 | - ), |
|
514 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
515 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
516 | - ), |
|
517 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
518 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
519 | - ), |
|
520 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
521 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
522 | - ), |
|
523 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
524 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
525 | - ), |
|
526 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
527 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
528 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
529 | - ), |
|
530 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
531 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
532 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
533 | - ), |
|
534 | - ); |
|
535 | - } |
|
536 | - |
|
537 | - |
|
538 | - |
|
539 | - /** |
|
540 | - * Registers how core classes are loaded. |
|
541 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
542 | - * 'EE_Request_Handler' => 'load_core' |
|
543 | - * 'EE_Messages_Queue' => 'load_lib' |
|
544 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
545 | - * or, if greater control is required, by providing a custom closure. For example: |
|
546 | - * 'Some_Class' => function () { |
|
547 | - * return new Some_Class(); |
|
548 | - * }, |
|
549 | - * This is required for instantiating dependencies |
|
550 | - * where an interface has been type hinted in a class constructor. For example: |
|
551 | - * 'Required_Interface' => function () { |
|
552 | - * return new A_Class_That_Implements_Required_Interface(); |
|
553 | - * }, |
|
554 | - */ |
|
555 | - protected function _register_core_class_loaders() |
|
556 | - { |
|
557 | - //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
558 | - //be used in a closure. |
|
559 | - $request = &$this->_request; |
|
560 | - $response = &$this->_response; |
|
561 | - $loader = &$this->loader; |
|
562 | - $this->_class_loaders = array( |
|
563 | - //load_core |
|
564 | - 'EE_Capabilities' => 'load_core', |
|
565 | - 'EE_Encryption' => 'load_core', |
|
566 | - 'EE_Front_Controller' => 'load_core', |
|
567 | - 'EE_Module_Request_Router' => 'load_core', |
|
568 | - 'EE_Registry' => 'load_core', |
|
569 | - 'EE_Request' => function () use (&$request) { |
|
570 | - return $request; |
|
571 | - }, |
|
572 | - 'EE_Response' => function () use (&$response) { |
|
573 | - return $response; |
|
574 | - }, |
|
575 | - 'EE_Request_Handler' => 'load_core', |
|
576 | - 'EE_Session' => 'load_core', |
|
577 | - 'EE_System' => 'load_core', |
|
578 | - //load_lib |
|
579 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
580 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
581 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
582 | - 'EE_Messenger_Collection' => 'load_lib', |
|
583 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
584 | - 'EE_Messages_Processor' => 'load_lib', |
|
585 | - 'EE_Message_Repository' => 'load_lib', |
|
586 | - 'EE_Messages_Queue' => 'load_lib', |
|
587 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
588 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
589 | - 'EE_Messages_Generator' => function () { |
|
590 | - return EE_Registry::instance()->load_lib( |
|
591 | - 'Messages_Generator', |
|
592 | - array(), |
|
593 | - false, |
|
594 | - false |
|
595 | - ); |
|
596 | - }, |
|
597 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
598 | - return EE_Registry::instance()->load_lib( |
|
599 | - 'Messages_Template_Defaults', |
|
600 | - $arguments, |
|
601 | - false, |
|
602 | - false |
|
603 | - ); |
|
604 | - }, |
|
605 | - //load_model |
|
606 | - 'EEM_Message_Template_Group' => 'load_model', |
|
607 | - 'EEM_Message_Template' => 'load_model', |
|
608 | - //load_helper |
|
609 | - 'EEH_Parse_Shortcodes' => function () { |
|
610 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
611 | - return new EEH_Parse_Shortcodes(); |
|
612 | - } |
|
613 | - return null; |
|
614 | - }, |
|
615 | - 'EE_Template_Config' => function () { |
|
616 | - return EE_Config::instance()->template_settings; |
|
617 | - }, |
|
618 | - 'EE_Currency_Config' => function () { |
|
619 | - return EE_Config::instance()->currency; |
|
620 | - }, |
|
621 | - 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
622 | - return $loader; |
|
623 | - }, |
|
624 | - ); |
|
625 | - } |
|
626 | - |
|
627 | - |
|
628 | - |
|
629 | - /** |
|
630 | - * can be used for supplying alternate names for classes, |
|
631 | - * or for connecting interface names to instantiable classes |
|
632 | - */ |
|
633 | - protected function _register_core_aliases() |
|
634 | - { |
|
635 | - $this->_aliases = array( |
|
636 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
637 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
638 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
639 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
640 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
641 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
642 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
643 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
644 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
645 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
646 | - 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
647 | - 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
648 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
649 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
650 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
651 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
652 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
653 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
654 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
655 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
656 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
657 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
658 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
659 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
660 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
661 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
662 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
663 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
664 | - 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
665 | - ); |
|
666 | - } |
|
667 | - |
|
668 | - |
|
669 | - |
|
670 | - /** |
|
671 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
672 | - * request Primarily used by unit tests. |
|
673 | - */ |
|
674 | - public function reset() |
|
675 | - { |
|
676 | - $this->_register_core_class_loaders(); |
|
677 | - $this->_register_core_dependencies(); |
|
678 | - } |
|
25 | + /** |
|
26 | + * This means that the requested class dependency is not present in the dependency map |
|
27 | + */ |
|
28 | + const not_registered = 0; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
33 | + */ |
|
34 | + const load_new_object = 1; |
|
35 | + |
|
36 | + /** |
|
37 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
38 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
39 | + */ |
|
40 | + const load_from_cache = 2; |
|
41 | + |
|
42 | + /** |
|
43 | + * @type EE_Dependency_Map $_instance |
|
44 | + */ |
|
45 | + protected static $_instance; |
|
46 | + |
|
47 | + /** |
|
48 | + * @type EE_Request $request |
|
49 | + */ |
|
50 | + protected $_request; |
|
51 | + |
|
52 | + /** |
|
53 | + * @type EE_Response $response |
|
54 | + */ |
|
55 | + protected $_response; |
|
56 | + |
|
57 | + /** |
|
58 | + * @type LoaderInterface $loader |
|
59 | + */ |
|
60 | + protected $loader; |
|
61 | + |
|
62 | + /** |
|
63 | + * @type array $_dependency_map |
|
64 | + */ |
|
65 | + protected $_dependency_map = array(); |
|
66 | + |
|
67 | + /** |
|
68 | + * @type array $_class_loaders |
|
69 | + */ |
|
70 | + protected $_class_loaders = array(); |
|
71 | + |
|
72 | + /** |
|
73 | + * @type array $_aliases |
|
74 | + */ |
|
75 | + protected $_aliases = array(); |
|
76 | + |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * EE_Dependency_Map constructor. |
|
81 | + * |
|
82 | + * @param EE_Request $request |
|
83 | + * @param EE_Response $response |
|
84 | + */ |
|
85 | + protected function __construct(EE_Request $request, EE_Response $response) |
|
86 | + { |
|
87 | + $this->_request = $request; |
|
88 | + $this->_response = $response; |
|
89 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
90 | + do_action('EE_Dependency_Map____construct'); |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * @throws InvalidDataTypeException |
|
97 | + * @throws InvalidInterfaceException |
|
98 | + * @throws InvalidArgumentException |
|
99 | + */ |
|
100 | + public function initialize() |
|
101 | + { |
|
102 | + $this->_register_core_dependencies(); |
|
103 | + $this->_register_core_class_loaders(); |
|
104 | + $this->_register_core_aliases(); |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * @singleton method used to instantiate class object |
|
111 | + * @access public |
|
112 | + * @param EE_Request $request |
|
113 | + * @param EE_Response $response |
|
114 | + * @return EE_Dependency_Map |
|
115 | + */ |
|
116 | + public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
117 | + { |
|
118 | + // check if class object is instantiated, and instantiated properly |
|
119 | + if (! self::$_instance instanceof EE_Dependency_Map) { |
|
120 | + self::$_instance = new EE_Dependency_Map($request, $response); |
|
121 | + } |
|
122 | + return self::$_instance; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * @param LoaderInterface $loader |
|
129 | + */ |
|
130 | + public function setLoader(LoaderInterface $loader) |
|
131 | + { |
|
132 | + $this->loader = $loader; |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * @param string $class |
|
139 | + * @param array $dependencies |
|
140 | + * @return boolean |
|
141 | + */ |
|
142 | + public static function register_dependencies($class, $dependencies) |
|
143 | + { |
|
144 | + if (! isset(self::$_instance->_dependency_map[$class])) { |
|
145 | + // we need to make sure that any aliases used when registering a dependency |
|
146 | + // get resolved to the correct class name |
|
147 | + foreach ((array)$dependencies as $dependency => $load_source) { |
|
148 | + $alias = self::$_instance->get_alias($dependency); |
|
149 | + unset($dependencies[$dependency]); |
|
150 | + $dependencies[$alias] = $load_source; |
|
151 | + } |
|
152 | + self::$_instance->_dependency_map[$class] = (array)$dependencies; |
|
153 | + return true; |
|
154 | + } |
|
155 | + return false; |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * @param string $class_name |
|
162 | + * @param string $loader |
|
163 | + * @return bool |
|
164 | + * @throws EE_Error |
|
165 | + */ |
|
166 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
167 | + { |
|
168 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
169 | + if ( |
|
170 | + ! is_callable($loader) |
|
171 | + && ( |
|
172 | + strpos($loader, 'load_') !== 0 |
|
173 | + || ! method_exists('EE_Registry', $loader) |
|
174 | + ) |
|
175 | + ) { |
|
176 | + throw new EE_Error( |
|
177 | + sprintf( |
|
178 | + esc_html__('"%1$s" is not a valid loader method on EE_Registry.', 'event_espresso'), |
|
179 | + $loader |
|
180 | + ) |
|
181 | + ); |
|
182 | + } |
|
183 | + $class_name = self::$_instance->get_alias($class_name); |
|
184 | + if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
185 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
186 | + return true; |
|
187 | + } |
|
188 | + return false; |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * @return array |
|
195 | + */ |
|
196 | + public function dependency_map() |
|
197 | + { |
|
198 | + return $this->_dependency_map; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
205 | + * |
|
206 | + * @param string $class_name |
|
207 | + * @return boolean |
|
208 | + */ |
|
209 | + public function has($class_name = '') |
|
210 | + { |
|
211 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
218 | + * |
|
219 | + * @param string $class_name |
|
220 | + * @param string $dependency |
|
221 | + * @return bool |
|
222 | + */ |
|
223 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
224 | + { |
|
225 | + $dependency = $this->get_alias($dependency); |
|
226 | + return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
227 | + ? true |
|
228 | + : false; |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
235 | + * |
|
236 | + * @param string $class_name |
|
237 | + * @param string $dependency |
|
238 | + * @return int |
|
239 | + */ |
|
240 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
241 | + { |
|
242 | + $dependency = $this->get_alias($dependency); |
|
243 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
244 | + ? $this->_dependency_map[$class_name][$dependency] |
|
245 | + : EE_Dependency_Map::not_registered; |
|
246 | + } |
|
247 | + |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * @param string $class_name |
|
252 | + * @return string | Closure |
|
253 | + */ |
|
254 | + public function class_loader($class_name) |
|
255 | + { |
|
256 | + // don't use loaders for FQCNs |
|
257 | + if(strpos($class_name, '\\') !== false){ |
|
258 | + return ''; |
|
259 | + } |
|
260 | + $class_name = $this->get_alias($class_name); |
|
261 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
262 | + } |
|
263 | + |
|
264 | + |
|
265 | + |
|
266 | + /** |
|
267 | + * @return array |
|
268 | + */ |
|
269 | + public function class_loaders() |
|
270 | + { |
|
271 | + return $this->_class_loaders; |
|
272 | + } |
|
273 | + |
|
274 | + |
|
275 | + |
|
276 | + /** |
|
277 | + * adds an alias for a classname |
|
278 | + * |
|
279 | + * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
280 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
281 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
282 | + */ |
|
283 | + public function add_alias($class_name, $alias, $for_class = '') |
|
284 | + { |
|
285 | + if ($for_class !== '') { |
|
286 | + if (! isset($this->_aliases[$for_class])) { |
|
287 | + $this->_aliases[$for_class] = array(); |
|
288 | + } |
|
289 | + $this->_aliases[$for_class][$class_name] = $alias; |
|
290 | + } |
|
291 | + $this->_aliases[$class_name] = $alias; |
|
292 | + } |
|
293 | + |
|
294 | + |
|
295 | + |
|
296 | + /** |
|
297 | + * returns TRUE if the provided class name has an alias |
|
298 | + * |
|
299 | + * @param string $class_name |
|
300 | + * @param string $for_class |
|
301 | + * @return bool |
|
302 | + */ |
|
303 | + public function has_alias($class_name = '', $for_class = '') |
|
304 | + { |
|
305 | + return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
306 | + || ( |
|
307 | + isset($this->_aliases[$class_name]) |
|
308 | + && ! is_array($this->_aliases[$class_name]) |
|
309 | + ); |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + |
|
314 | + /** |
|
315 | + * returns alias for class name if one exists, otherwise returns the original classname |
|
316 | + * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
317 | + * for example: |
|
318 | + * if the following two entries were added to the _aliases array: |
|
319 | + * array( |
|
320 | + * 'interface_alias' => 'some\namespace\interface' |
|
321 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
322 | + * ) |
|
323 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
324 | + * to load an instance of 'some\namespace\classname' |
|
325 | + * |
|
326 | + * @param string $class_name |
|
327 | + * @param string $for_class |
|
328 | + * @return string |
|
329 | + */ |
|
330 | + public function get_alias($class_name = '', $for_class = '') |
|
331 | + { |
|
332 | + if (! $this->has_alias($class_name, $for_class)) { |
|
333 | + return $class_name; |
|
334 | + } |
|
335 | + if ($for_class !== '') { |
|
336 | + return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
337 | + } |
|
338 | + return $this->get_alias($this->_aliases[$class_name]); |
|
339 | + } |
|
340 | + |
|
341 | + |
|
342 | + |
|
343 | + /** |
|
344 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
345 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
346 | + * This is done by using the following class constants: |
|
347 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
348 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
349 | + */ |
|
350 | + protected function _register_core_dependencies() |
|
351 | + { |
|
352 | + $this->_dependency_map = array( |
|
353 | + 'EE_Request_Handler' => array( |
|
354 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
355 | + ), |
|
356 | + 'EE_System' => array( |
|
357 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
358 | + ), |
|
359 | + 'EE_Session' => array( |
|
360 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
361 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
362 | + ), |
|
363 | + 'EE_Cart' => array( |
|
364 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
365 | + ), |
|
366 | + 'EE_Front_Controller' => array( |
|
367 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
368 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
369 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
370 | + ), |
|
371 | + 'EE_Messenger_Collection_Loader' => array( |
|
372 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
373 | + ), |
|
374 | + 'EE_Message_Type_Collection_Loader' => array( |
|
375 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
376 | + ), |
|
377 | + 'EE_Message_Resource_Manager' => array( |
|
378 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
379 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
380 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
381 | + ), |
|
382 | + 'EE_Message_Factory' => array( |
|
383 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
384 | + ), |
|
385 | + 'EE_messages' => array( |
|
386 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
387 | + ), |
|
388 | + 'EE_Messages_Generator' => array( |
|
389 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
390 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
391 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
392 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
393 | + ), |
|
394 | + 'EE_Messages_Processor' => array( |
|
395 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
396 | + ), |
|
397 | + 'EE_Messages_Queue' => array( |
|
398 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
399 | + ), |
|
400 | + 'EE_Messages_Template_Defaults' => array( |
|
401 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
402 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
403 | + ), |
|
404 | + 'EE_Message_To_Generate_From_Request' => array( |
|
405 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
406 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
407 | + ), |
|
408 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
409 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
410 | + ), |
|
411 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
412 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
413 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
414 | + ), |
|
415 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
416 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
417 | + ), |
|
418 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
419 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
420 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
421 | + ), |
|
422 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
423 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
424 | + ), |
|
425 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
426 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
427 | + ), |
|
428 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
429 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
430 | + ), |
|
431 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
432 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
433 | + ), |
|
434 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
435 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
436 | + ), |
|
437 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
438 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
439 | + ), |
|
440 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
441 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
442 | + ), |
|
443 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
444 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
445 | + ), |
|
446 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
447 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
448 | + ), |
|
449 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
450 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
451 | + ), |
|
452 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
453 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
454 | + ), |
|
455 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
456 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
457 | + ), |
|
458 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
459 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
460 | + ), |
|
461 | + 'EE_Data_Migration_Class_Base' => array( |
|
462 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
463 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
464 | + ), |
|
465 | + 'EE_DMS_Core_4_1_0' => array( |
|
466 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
467 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
468 | + ), |
|
469 | + 'EE_DMS_Core_4_2_0' => array( |
|
470 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
471 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
472 | + ), |
|
473 | + 'EE_DMS_Core_4_3_0' => array( |
|
474 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
475 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
476 | + ), |
|
477 | + 'EE_DMS_Core_4_4_0' => array( |
|
478 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
479 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
480 | + ), |
|
481 | + 'EE_DMS_Core_4_5_0' => array( |
|
482 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
483 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
484 | + ), |
|
485 | + 'EE_DMS_Core_4_6_0' => array( |
|
486 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
487 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
488 | + ), |
|
489 | + 'EE_DMS_Core_4_7_0' => array( |
|
490 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
491 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
492 | + ), |
|
493 | + 'EE_DMS_Core_4_8_0' => array( |
|
494 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
495 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
496 | + ), |
|
497 | + 'EE_DMS_Core_4_9_0' => array( |
|
498 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
499 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
500 | + ), |
|
501 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
502 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
503 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
504 | + ), |
|
505 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
506 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
507 | + ), |
|
508 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
509 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
510 | + ), |
|
511 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
512 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
513 | + ), |
|
514 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
515 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
516 | + ), |
|
517 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
518 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
519 | + ), |
|
520 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
521 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
522 | + ), |
|
523 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
524 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
525 | + ), |
|
526 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
527 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
528 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
529 | + ), |
|
530 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
531 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
532 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
533 | + ), |
|
534 | + ); |
|
535 | + } |
|
536 | + |
|
537 | + |
|
538 | + |
|
539 | + /** |
|
540 | + * Registers how core classes are loaded. |
|
541 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
542 | + * 'EE_Request_Handler' => 'load_core' |
|
543 | + * 'EE_Messages_Queue' => 'load_lib' |
|
544 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
545 | + * or, if greater control is required, by providing a custom closure. For example: |
|
546 | + * 'Some_Class' => function () { |
|
547 | + * return new Some_Class(); |
|
548 | + * }, |
|
549 | + * This is required for instantiating dependencies |
|
550 | + * where an interface has been type hinted in a class constructor. For example: |
|
551 | + * 'Required_Interface' => function () { |
|
552 | + * return new A_Class_That_Implements_Required_Interface(); |
|
553 | + * }, |
|
554 | + */ |
|
555 | + protected function _register_core_class_loaders() |
|
556 | + { |
|
557 | + //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
558 | + //be used in a closure. |
|
559 | + $request = &$this->_request; |
|
560 | + $response = &$this->_response; |
|
561 | + $loader = &$this->loader; |
|
562 | + $this->_class_loaders = array( |
|
563 | + //load_core |
|
564 | + 'EE_Capabilities' => 'load_core', |
|
565 | + 'EE_Encryption' => 'load_core', |
|
566 | + 'EE_Front_Controller' => 'load_core', |
|
567 | + 'EE_Module_Request_Router' => 'load_core', |
|
568 | + 'EE_Registry' => 'load_core', |
|
569 | + 'EE_Request' => function () use (&$request) { |
|
570 | + return $request; |
|
571 | + }, |
|
572 | + 'EE_Response' => function () use (&$response) { |
|
573 | + return $response; |
|
574 | + }, |
|
575 | + 'EE_Request_Handler' => 'load_core', |
|
576 | + 'EE_Session' => 'load_core', |
|
577 | + 'EE_System' => 'load_core', |
|
578 | + //load_lib |
|
579 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
580 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
581 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
582 | + 'EE_Messenger_Collection' => 'load_lib', |
|
583 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
584 | + 'EE_Messages_Processor' => 'load_lib', |
|
585 | + 'EE_Message_Repository' => 'load_lib', |
|
586 | + 'EE_Messages_Queue' => 'load_lib', |
|
587 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
588 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
589 | + 'EE_Messages_Generator' => function () { |
|
590 | + return EE_Registry::instance()->load_lib( |
|
591 | + 'Messages_Generator', |
|
592 | + array(), |
|
593 | + false, |
|
594 | + false |
|
595 | + ); |
|
596 | + }, |
|
597 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
598 | + return EE_Registry::instance()->load_lib( |
|
599 | + 'Messages_Template_Defaults', |
|
600 | + $arguments, |
|
601 | + false, |
|
602 | + false |
|
603 | + ); |
|
604 | + }, |
|
605 | + //load_model |
|
606 | + 'EEM_Message_Template_Group' => 'load_model', |
|
607 | + 'EEM_Message_Template' => 'load_model', |
|
608 | + //load_helper |
|
609 | + 'EEH_Parse_Shortcodes' => function () { |
|
610 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
611 | + return new EEH_Parse_Shortcodes(); |
|
612 | + } |
|
613 | + return null; |
|
614 | + }, |
|
615 | + 'EE_Template_Config' => function () { |
|
616 | + return EE_Config::instance()->template_settings; |
|
617 | + }, |
|
618 | + 'EE_Currency_Config' => function () { |
|
619 | + return EE_Config::instance()->currency; |
|
620 | + }, |
|
621 | + 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
622 | + return $loader; |
|
623 | + }, |
|
624 | + ); |
|
625 | + } |
|
626 | + |
|
627 | + |
|
628 | + |
|
629 | + /** |
|
630 | + * can be used for supplying alternate names for classes, |
|
631 | + * or for connecting interface names to instantiable classes |
|
632 | + */ |
|
633 | + protected function _register_core_aliases() |
|
634 | + { |
|
635 | + $this->_aliases = array( |
|
636 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
637 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
638 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
639 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
640 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
641 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
642 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
643 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
644 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
645 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
646 | + 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
647 | + 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
648 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
649 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
650 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
651 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
652 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
653 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
654 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
655 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
656 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
657 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
658 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
659 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
660 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
661 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
662 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
663 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
664 | + 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
665 | + ); |
|
666 | + } |
|
667 | + |
|
668 | + |
|
669 | + |
|
670 | + /** |
|
671 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
672 | + * request Primarily used by unit tests. |
|
673 | + */ |
|
674 | + public function reset() |
|
675 | + { |
|
676 | + $this->_register_core_class_loaders(); |
|
677 | + $this->_register_core_dependencies(); |
|
678 | + } |
|
679 | 679 | |
680 | 680 | |
681 | 681 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
4 | 4 | use EventEspresso\core\services\loaders\LoaderInterface; |
5 | 5 | |
6 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
6 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
7 | 7 | exit('No direct script access allowed'); |
8 | 8 | } |
9 | 9 | |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | public static function instance(EE_Request $request = null, EE_Response $response = null) |
117 | 117 | { |
118 | 118 | // check if class object is instantiated, and instantiated properly |
119 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
119 | + if ( ! self::$_instance instanceof EE_Dependency_Map) { |
|
120 | 120 | self::$_instance = new EE_Dependency_Map($request, $response); |
121 | 121 | } |
122 | 122 | return self::$_instance; |
@@ -141,15 +141,15 @@ discard block |
||
141 | 141 | */ |
142 | 142 | public static function register_dependencies($class, $dependencies) |
143 | 143 | { |
144 | - if (! isset(self::$_instance->_dependency_map[$class])) { |
|
144 | + if ( ! isset(self::$_instance->_dependency_map[$class])) { |
|
145 | 145 | // we need to make sure that any aliases used when registering a dependency |
146 | 146 | // get resolved to the correct class name |
147 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
147 | + foreach ((array) $dependencies as $dependency => $load_source) { |
|
148 | 148 | $alias = self::$_instance->get_alias($dependency); |
149 | 149 | unset($dependencies[$dependency]); |
150 | 150 | $dependencies[$alias] = $load_source; |
151 | 151 | } |
152 | - self::$_instance->_dependency_map[$class] = (array)$dependencies; |
|
152 | + self::$_instance->_dependency_map[$class] = (array) $dependencies; |
|
153 | 153 | return true; |
154 | 154 | } |
155 | 155 | return false; |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | ); |
182 | 182 | } |
183 | 183 | $class_name = self::$_instance->get_alias($class_name); |
184 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
184 | + if ( ! isset(self::$_instance->_class_loaders[$class_name])) { |
|
185 | 185 | self::$_instance->_class_loaders[$class_name] = $loader; |
186 | 186 | return true; |
187 | 187 | } |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | public function class_loader($class_name) |
255 | 255 | { |
256 | 256 | // don't use loaders for FQCNs |
257 | - if(strpos($class_name, '\\') !== false){ |
|
257 | + if (strpos($class_name, '\\') !== false) { |
|
258 | 258 | return ''; |
259 | 259 | } |
260 | 260 | $class_name = $this->get_alias($class_name); |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | public function add_alias($class_name, $alias, $for_class = '') |
284 | 284 | { |
285 | 285 | if ($for_class !== '') { |
286 | - if (! isset($this->_aliases[$for_class])) { |
|
286 | + if ( ! isset($this->_aliases[$for_class])) { |
|
287 | 287 | $this->_aliases[$for_class] = array(); |
288 | 288 | } |
289 | 289 | $this->_aliases[$for_class][$class_name] = $alias; |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | */ |
330 | 330 | public function get_alias($class_name = '', $for_class = '') |
331 | 331 | { |
332 | - if (! $this->has_alias($class_name, $for_class)) { |
|
332 | + if ( ! $this->has_alias($class_name, $for_class)) { |
|
333 | 333 | return $class_name; |
334 | 334 | } |
335 | 335 | if ($for_class !== '') { |
@@ -566,10 +566,10 @@ discard block |
||
566 | 566 | 'EE_Front_Controller' => 'load_core', |
567 | 567 | 'EE_Module_Request_Router' => 'load_core', |
568 | 568 | 'EE_Registry' => 'load_core', |
569 | - 'EE_Request' => function () use (&$request) { |
|
569 | + 'EE_Request' => function() use (&$request) { |
|
570 | 570 | return $request; |
571 | 571 | }, |
572 | - 'EE_Response' => function () use (&$response) { |
|
572 | + 'EE_Response' => function() use (&$response) { |
|
573 | 573 | return $response; |
574 | 574 | }, |
575 | 575 | 'EE_Request_Handler' => 'load_core', |
@@ -586,7 +586,7 @@ discard block |
||
586 | 586 | 'EE_Messages_Queue' => 'load_lib', |
587 | 587 | 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
588 | 588 | 'EE_Message_Template_Group_Collection' => 'load_lib', |
589 | - 'EE_Messages_Generator' => function () { |
|
589 | + 'EE_Messages_Generator' => function() { |
|
590 | 590 | return EE_Registry::instance()->load_lib( |
591 | 591 | 'Messages_Generator', |
592 | 592 | array(), |
@@ -594,7 +594,7 @@ discard block |
||
594 | 594 | false |
595 | 595 | ); |
596 | 596 | }, |
597 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
597 | + 'EE_Messages_Template_Defaults' => function($arguments = array()) { |
|
598 | 598 | return EE_Registry::instance()->load_lib( |
599 | 599 | 'Messages_Template_Defaults', |
600 | 600 | $arguments, |
@@ -606,19 +606,19 @@ discard block |
||
606 | 606 | 'EEM_Message_Template_Group' => 'load_model', |
607 | 607 | 'EEM_Message_Template' => 'load_model', |
608 | 608 | //load_helper |
609 | - 'EEH_Parse_Shortcodes' => function () { |
|
609 | + 'EEH_Parse_Shortcodes' => function() { |
|
610 | 610 | if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
611 | 611 | return new EEH_Parse_Shortcodes(); |
612 | 612 | } |
613 | 613 | return null; |
614 | 614 | }, |
615 | - 'EE_Template_Config' => function () { |
|
615 | + 'EE_Template_Config' => function() { |
|
616 | 616 | return EE_Config::instance()->template_settings; |
617 | 617 | }, |
618 | - 'EE_Currency_Config' => function () { |
|
618 | + 'EE_Currency_Config' => function() { |
|
619 | 619 | return EE_Config::instance()->currency; |
620 | 620 | }, |
621 | - 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
621 | + 'EventEspresso\core\services\loaders\Loader' => function() use (&$loader) { |
|
622 | 622 | return $loader; |
623 | 623 | }, |
624 | 624 | ); |
@@ -199,13 +199,13 @@ discard block |
||
199 | 199 | ); |
200 | 200 | return CollectionLoader::ENTITY_ADDED; |
201 | 201 | } |
202 | - do_action( |
|
203 | - 'FHEE__CollectionLoader__addEntityToCollection__entity_not_added', |
|
204 | - $this, |
|
205 | - $this->collection_details->collectionName(), |
|
206 | - $this->collection_details |
|
207 | - ); |
|
208 | - return CollectionLoader::ENTITY_NOT_ADDED; |
|
202 | + do_action( |
|
203 | + 'FHEE__CollectionLoader__addEntityToCollection__entity_not_added', |
|
204 | + $this, |
|
205 | + $this->collection_details->collectionName(), |
|
206 | + $this->collection_details |
|
207 | + ); |
|
208 | + return CollectionLoader::ENTITY_NOT_ADDED; |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | |
@@ -220,37 +220,37 @@ discard block |
||
220 | 220 | * @throws \EventEspresso\core\exceptions\InvalidEntityException |
221 | 221 | */ |
222 | 222 | protected function setIdentifier( $entity, $identifier ) { |
223 | - switch($this->collection_details->identifierType()) { |
|
224 | - // every unique object gets added to the collection, but not duplicates of the exact same object |
|
225 | - case CollectionDetails::ID_OBJECT_HASH : |
|
226 | - $identifier = spl_object_hash($entity); |
|
227 | - break; |
|
228 | - // only one entity per class can be added to collection, like a singleton |
|
229 | - case CollectionDetails::ID_CLASS_NAME : |
|
230 | - $identifier = get_class($entity); |
|
231 | - break; |
|
232 | - // objects added to the collection based on entity callback, so the entity itself decides |
|
233 | - case CollectionDetails::ID_CALLBACK_METHOD : |
|
234 | - $identifier_callback = $this->collection_details->identifierCallback(); |
|
235 | - if ( ! method_exists($entity, $identifier_callback)) { |
|
236 | - throw new InvalidEntityException( |
|
237 | - $entity, |
|
238 | - $this->collection_details->getCollectionInterface(), |
|
239 | - sprintf( |
|
240 | - __( |
|
241 | - 'The current collection is configured to use a method named "%1$s" when setting or retrieving objects. The supplied entity is an instance |
|
223 | + switch($this->collection_details->identifierType()) { |
|
224 | + // every unique object gets added to the collection, but not duplicates of the exact same object |
|
225 | + case CollectionDetails::ID_OBJECT_HASH : |
|
226 | + $identifier = spl_object_hash($entity); |
|
227 | + break; |
|
228 | + // only one entity per class can be added to collection, like a singleton |
|
229 | + case CollectionDetails::ID_CLASS_NAME : |
|
230 | + $identifier = get_class($entity); |
|
231 | + break; |
|
232 | + // objects added to the collection based on entity callback, so the entity itself decides |
|
233 | + case CollectionDetails::ID_CALLBACK_METHOD : |
|
234 | + $identifier_callback = $this->collection_details->identifierCallback(); |
|
235 | + if ( ! method_exists($entity, $identifier_callback)) { |
|
236 | + throw new InvalidEntityException( |
|
237 | + $entity, |
|
238 | + $this->collection_details->getCollectionInterface(), |
|
239 | + sprintf( |
|
240 | + __( |
|
241 | + 'The current collection is configured to use a method named "%1$s" when setting or retrieving objects. The supplied entity is an instance |
|
242 | 242 | of "%2$s", but does not contain this method.', |
243 | - 'event_espresso' |
|
244 | - ), |
|
245 | - $identifier_callback, |
|
246 | - get_class($entity) |
|
247 | - ) |
|
248 | - ); |
|
249 | - } |
|
250 | - $identifier = $entity->{$identifier_callback}(); |
|
251 | - break; |
|
252 | - |
|
253 | - } |
|
243 | + 'event_espresso' |
|
244 | + ), |
|
245 | + $identifier_callback, |
|
246 | + get_class($entity) |
|
247 | + ) |
|
248 | + ); |
|
249 | + } |
|
250 | + $identifier = $entity->{$identifier_callback}(); |
|
251 | + break; |
|
252 | + |
|
253 | + } |
|
254 | 254 | return apply_filters( |
255 | 255 | 'FHEE__CollectionLoader__addEntityToCollection__identifier', |
256 | 256 | $identifier, |
@@ -19,155 +19,155 @@ discard block |
||
19 | 19 | class BasicCacheManager implements CacheManagerInterface |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * @type string |
|
24 | - */ |
|
25 | - const CACHE_PREFIX = 'ee_cache_'; |
|
26 | - |
|
27 | - /** |
|
28 | - * set to true to monitor when content is being served from cache or not |
|
29 | - * |
|
30 | - * @type boolean |
|
31 | - */ |
|
32 | - const DEBUG = false; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var CacheStorageInterface $cache_storage |
|
36 | - */ |
|
37 | - private $cache_storage; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var SessionIdentifierInterface $session |
|
41 | - */ |
|
42 | - private $session; |
|
43 | - |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * BasicCacheManager constructor. |
|
48 | - * |
|
49 | - * @param CacheStorageInterface $cache_storage [required] |
|
50 | - * @param SessionIdentifierInterface $session |
|
51 | - */ |
|
52 | - public function __construct(CacheStorageInterface $cache_storage, SessionIdentifierInterface $session) |
|
53 | - { |
|
54 | - $this->cache_storage = $cache_storage; |
|
55 | - $this->session = $session; |
|
56 | - } |
|
57 | - |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * returns a string that will be prepended to all cache identifiers |
|
62 | - * |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - public function cachePrefix() |
|
66 | - { |
|
67 | - return BasicCacheManager::CACHE_PREFIX; |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * @param string $id_prefix [required] Prepended to all cache IDs. Can be helpful in finding specific cache types. |
|
74 | - * May also be helpful to include an additional specific identifier, |
|
75 | - * such as a post ID as part of the $id_prefix so that individual caches |
|
76 | - * can be found and/or cleared. ex: "venue-28", or "shortcode-156". |
|
77 | - * BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id. |
|
78 | - * @param string $cache_id [required] Additional identifying details that make this cache unique. |
|
79 | - * It is advisable to use some of the actual data |
|
80 | - * that is used to generate the content being cached, |
|
81 | - * in order to guarantee that the cache id is unique for that content. |
|
82 | - * The cache id will be md5'd before usage to make it more db friendly, |
|
83 | - * and the entire cache id string will be truncated to 190 characters. |
|
84 | - * @param Closure $callback [required] since the point of caching is to avoid generating content when not |
|
85 | - * necessary, |
|
86 | - * we wrap our content creation in a Closure so that it is not executed until needed. |
|
87 | - * @param int $expiration |
|
88 | - * @return Closure|mixed |
|
89 | - */ |
|
90 | - public function get($id_prefix, $cache_id, Closure $callback, $expiration = HOUR_IN_SECONDS) |
|
91 | - { |
|
92 | - $content = ''; |
|
93 | - $expiration = absint( |
|
94 | - apply_filters( |
|
95 | - 'FHEE__CacheManager__get__cache_expiration', |
|
96 | - $expiration, |
|
97 | - $id_prefix, |
|
98 | - $cache_id |
|
99 | - ) |
|
100 | - ); |
|
101 | - $cache_id = $this->generateCacheIdentifier($id_prefix, $cache_id); |
|
102 | - // is caching enabled for this content ? |
|
103 | - if ($expiration) { |
|
104 | - $content = $this->cache_storage->get($cache_id); |
|
105 | - } |
|
106 | - // any existing content ? |
|
107 | - if (empty($content)) { |
|
108 | - // nope! let's generate some new stuff |
|
109 | - $content = $callback(); |
|
110 | - // save the new content if caching is enabled |
|
111 | - if ($expiration) { |
|
112 | - $this->cache_storage->add($cache_id, $content, $expiration); |
|
113 | - if (BasicCacheManager::DEBUG || WP_DEBUG) { |
|
114 | - $content .= $this->displayCacheNotice($cache_id, 'REFRESH CACHE'); |
|
115 | - } |
|
116 | - } |
|
117 | - } else { |
|
118 | - if (BasicCacheManager::DEBUG || WP_DEBUG) { |
|
119 | - $content .= $this->displayCacheNotice($cache_id, 'CACHED CONTENT'); |
|
120 | - } |
|
121 | - } |
|
122 | - return $content; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * Generates a unique identifier string for the cache |
|
129 | - * |
|
130 | - * @param string $id_prefix [required] see BasicCacheManager::get() |
|
131 | - * @param string $cache_id [required] see BasicCacheManager::get() |
|
132 | - * @return string |
|
133 | - */ |
|
134 | - private function generateCacheIdentifier($id_prefix, $cache_id) |
|
135 | - { |
|
136 | - // let's make the cached content unique for this session |
|
137 | - $cache_id .= $this->session->id(); |
|
138 | - // and for this "page" |
|
139 | - $cache_id .= filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_URL); |
|
140 | - // with these parameters |
|
141 | - $cache_id .= filter_input(INPUT_SERVER, 'QUERY_STRING', FILTER_SANITIZE_URL); |
|
142 | - // then md5 the above to control it's length, add all of our prefixes, and truncate |
|
143 | - return substr($this->cachePrefix() . $id_prefix . '-' . md5($cache_id), 0, 182); |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * @param array|string $cache_id [required] Could be an ID prefix affecting many caches |
|
150 | - * or a specific ID targeting a single cache item |
|
151 | - * @return void |
|
152 | - */ |
|
153 | - public function clear($cache_id) |
|
154 | - { |
|
155 | - // ensure incoming arg is in an array |
|
156 | - $cache_id = is_array($cache_id) ? $cache_id : array($cache_id); |
|
157 | - // delete corresponding transients for the supplied id prefix |
|
158 | - $this->cache_storage->deleteMany($cache_id); |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * @param array|string $cache_id [required] Could be an ID prefix affecting many caches |
|
165 | - * or a specific ID targeting a single cache item |
|
166 | - * @param string $type |
|
167 | - * @return string |
|
168 | - */ |
|
169 | - private function displayCacheNotice($cache_id, $type) { |
|
170 | - return ' |
|
22 | + /** |
|
23 | + * @type string |
|
24 | + */ |
|
25 | + const CACHE_PREFIX = 'ee_cache_'; |
|
26 | + |
|
27 | + /** |
|
28 | + * set to true to monitor when content is being served from cache or not |
|
29 | + * |
|
30 | + * @type boolean |
|
31 | + */ |
|
32 | + const DEBUG = false; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var CacheStorageInterface $cache_storage |
|
36 | + */ |
|
37 | + private $cache_storage; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var SessionIdentifierInterface $session |
|
41 | + */ |
|
42 | + private $session; |
|
43 | + |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * BasicCacheManager constructor. |
|
48 | + * |
|
49 | + * @param CacheStorageInterface $cache_storage [required] |
|
50 | + * @param SessionIdentifierInterface $session |
|
51 | + */ |
|
52 | + public function __construct(CacheStorageInterface $cache_storage, SessionIdentifierInterface $session) |
|
53 | + { |
|
54 | + $this->cache_storage = $cache_storage; |
|
55 | + $this->session = $session; |
|
56 | + } |
|
57 | + |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * returns a string that will be prepended to all cache identifiers |
|
62 | + * |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + public function cachePrefix() |
|
66 | + { |
|
67 | + return BasicCacheManager::CACHE_PREFIX; |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * @param string $id_prefix [required] Prepended to all cache IDs. Can be helpful in finding specific cache types. |
|
74 | + * May also be helpful to include an additional specific identifier, |
|
75 | + * such as a post ID as part of the $id_prefix so that individual caches |
|
76 | + * can be found and/or cleared. ex: "venue-28", or "shortcode-156". |
|
77 | + * BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id. |
|
78 | + * @param string $cache_id [required] Additional identifying details that make this cache unique. |
|
79 | + * It is advisable to use some of the actual data |
|
80 | + * that is used to generate the content being cached, |
|
81 | + * in order to guarantee that the cache id is unique for that content. |
|
82 | + * The cache id will be md5'd before usage to make it more db friendly, |
|
83 | + * and the entire cache id string will be truncated to 190 characters. |
|
84 | + * @param Closure $callback [required] since the point of caching is to avoid generating content when not |
|
85 | + * necessary, |
|
86 | + * we wrap our content creation in a Closure so that it is not executed until needed. |
|
87 | + * @param int $expiration |
|
88 | + * @return Closure|mixed |
|
89 | + */ |
|
90 | + public function get($id_prefix, $cache_id, Closure $callback, $expiration = HOUR_IN_SECONDS) |
|
91 | + { |
|
92 | + $content = ''; |
|
93 | + $expiration = absint( |
|
94 | + apply_filters( |
|
95 | + 'FHEE__CacheManager__get__cache_expiration', |
|
96 | + $expiration, |
|
97 | + $id_prefix, |
|
98 | + $cache_id |
|
99 | + ) |
|
100 | + ); |
|
101 | + $cache_id = $this->generateCacheIdentifier($id_prefix, $cache_id); |
|
102 | + // is caching enabled for this content ? |
|
103 | + if ($expiration) { |
|
104 | + $content = $this->cache_storage->get($cache_id); |
|
105 | + } |
|
106 | + // any existing content ? |
|
107 | + if (empty($content)) { |
|
108 | + // nope! let's generate some new stuff |
|
109 | + $content = $callback(); |
|
110 | + // save the new content if caching is enabled |
|
111 | + if ($expiration) { |
|
112 | + $this->cache_storage->add($cache_id, $content, $expiration); |
|
113 | + if (BasicCacheManager::DEBUG || WP_DEBUG) { |
|
114 | + $content .= $this->displayCacheNotice($cache_id, 'REFRESH CACHE'); |
|
115 | + } |
|
116 | + } |
|
117 | + } else { |
|
118 | + if (BasicCacheManager::DEBUG || WP_DEBUG) { |
|
119 | + $content .= $this->displayCacheNotice($cache_id, 'CACHED CONTENT'); |
|
120 | + } |
|
121 | + } |
|
122 | + return $content; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * Generates a unique identifier string for the cache |
|
129 | + * |
|
130 | + * @param string $id_prefix [required] see BasicCacheManager::get() |
|
131 | + * @param string $cache_id [required] see BasicCacheManager::get() |
|
132 | + * @return string |
|
133 | + */ |
|
134 | + private function generateCacheIdentifier($id_prefix, $cache_id) |
|
135 | + { |
|
136 | + // let's make the cached content unique for this session |
|
137 | + $cache_id .= $this->session->id(); |
|
138 | + // and for this "page" |
|
139 | + $cache_id .= filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_URL); |
|
140 | + // with these parameters |
|
141 | + $cache_id .= filter_input(INPUT_SERVER, 'QUERY_STRING', FILTER_SANITIZE_URL); |
|
142 | + // then md5 the above to control it's length, add all of our prefixes, and truncate |
|
143 | + return substr($this->cachePrefix() . $id_prefix . '-' . md5($cache_id), 0, 182); |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * @param array|string $cache_id [required] Could be an ID prefix affecting many caches |
|
150 | + * or a specific ID targeting a single cache item |
|
151 | + * @return void |
|
152 | + */ |
|
153 | + public function clear($cache_id) |
|
154 | + { |
|
155 | + // ensure incoming arg is in an array |
|
156 | + $cache_id = is_array($cache_id) ? $cache_id : array($cache_id); |
|
157 | + // delete corresponding transients for the supplied id prefix |
|
158 | + $this->cache_storage->deleteMany($cache_id); |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * @param array|string $cache_id [required] Could be an ID prefix affecting many caches |
|
165 | + * or a specific ID targeting a single cache item |
|
166 | + * @param string $type |
|
167 | + * @return string |
|
168 | + */ |
|
169 | + private function displayCacheNotice($cache_id, $type) { |
|
170 | + return ' |
|
171 | 171 | <div class="ee-cached-content-notice" style="position:fixed; bottom:0; left: 0;"> |
172 | 172 | <p style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;margin:0 0 3px 5px"> |
173 | 173 | <b>' . $type . '</b><span style="color:#999"> : </span> |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | <span style="margin-left:2em;">' . __FILE__ . '</span> |
176 | 176 | </p> |
177 | 177 | </div>'; |
178 | - } |
|
178 | + } |
|
179 | 179 | |
180 | 180 | } |
181 | 181 | // End of file BasicCacheManager.php |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | // with these parameters |
141 | 141 | $cache_id .= filter_input(INPUT_SERVER, 'QUERY_STRING', FILTER_SANITIZE_URL); |
142 | 142 | // then md5 the above to control it's length, add all of our prefixes, and truncate |
143 | - return substr($this->cachePrefix() . $id_prefix . '-' . md5($cache_id), 0, 182); |
|
143 | + return substr($this->cachePrefix().$id_prefix.'-'.md5($cache_id), 0, 182); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | |
@@ -170,9 +170,9 @@ discard block |
||
170 | 170 | return ' |
171 | 171 | <div class="ee-cached-content-notice" style="position:fixed; bottom:0; left: 0;"> |
172 | 172 | <p style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;margin:0 0 3px 5px"> |
173 | - <b>' . $type . '</b><span style="color:#999"> : </span> |
|
174 | - <span>' . $cache_id . '</span> |
|
175 | - <span style="margin-left:2em;">' . __FILE__ . '</span> |
|
173 | + <b>' . $type.'</b><span style="color:#999"> : </span> |
|
174 | + <span>' . $cache_id.'</span> |
|
175 | + <span style="margin-left:2em;">' . __FILE__.'</span> |
|
176 | 176 | </p> |
177 | 177 | </div>'; |
178 | 178 | } |