@@ -5,80 +5,80 @@ |
||
5 | 5 | class EE_Two_Column_Layout extends EE_Form_Section_Layout_Base |
6 | 6 | { |
7 | 7 | |
8 | - /** |
|
9 | - * Should be used to start teh form section (Eg a table tag, or a div tag, etc.) |
|
10 | - * |
|
11 | - * @param array $additional_args |
|
12 | - * @return string |
|
13 | - */ |
|
14 | - public function layout_form_begin($additional_args = array()) |
|
15 | - { |
|
16 | - return EEH_HTML::table( |
|
17 | - '', |
|
18 | - $this->_form_section->html_id(), |
|
19 | - $this->_form_section->html_class(), |
|
20 | - $this->_form_section->html_style() |
|
21 | - ) . EEH_HTML::tbody(); |
|
22 | - } |
|
8 | + /** |
|
9 | + * Should be used to start teh form section (Eg a table tag, or a div tag, etc.) |
|
10 | + * |
|
11 | + * @param array $additional_args |
|
12 | + * @return string |
|
13 | + */ |
|
14 | + public function layout_form_begin($additional_args = array()) |
|
15 | + { |
|
16 | + return EEH_HTML::table( |
|
17 | + '', |
|
18 | + $this->_form_section->html_id(), |
|
19 | + $this->_form_section->html_class(), |
|
20 | + $this->_form_section->html_style() |
|
21 | + ) . EEH_HTML::tbody(); |
|
22 | + } |
|
23 | 23 | |
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * Should be used to end the form section (eg a /table tag, or a /div tag, etc) |
|
28 | - * |
|
29 | - * @param array $additional_args |
|
30 | - * @return string |
|
31 | - */ |
|
32 | - public function layout_form_end($additional_args = array()) |
|
33 | - { |
|
34 | - return EEH_HTML::tbodyx() . EEH_HTML::tablex($this->_form_section->html_id()); |
|
35 | - } |
|
26 | + /** |
|
27 | + * Should be used to end the form section (eg a /table tag, or a /div tag, etc) |
|
28 | + * |
|
29 | + * @param array $additional_args |
|
30 | + * @return string |
|
31 | + */ |
|
32 | + public function layout_form_end($additional_args = array()) |
|
33 | + { |
|
34 | + return EEH_HTML::tbodyx() . EEH_HTML::tablex($this->_form_section->html_id()); |
|
35 | + } |
|
36 | 36 | |
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * Lays out the row for the input, including label and errors |
|
41 | - * |
|
42 | - * @param EE_Form_Input_Base $input |
|
43 | - * @return string |
|
44 | - */ |
|
45 | - public function layout_input($input) |
|
46 | - { |
|
47 | - $html = ''; |
|
48 | - if ($input instanceof EE_Hidden_Input) { |
|
49 | - $html .= $input->get_html_for_input(); |
|
50 | - } else { |
|
51 | - $html_for_input = $input->get_html_for_input(); |
|
52 | - $html_for_input .= $input->get_html_for_errors() != '' |
|
53 | - ? EEH_HTML::nl() . $input->get_html_for_errors() |
|
54 | - : ''; |
|
55 | - $html_for_input .= $input->get_html_for_help() != '' ? EEH_HTML::nl() . $input->get_html_for_help() : ''; |
|
56 | - $html .= EEH_HTML::tr( |
|
57 | - EEH_HTML::th($input->get_html_for_label()) . |
|
58 | - EEH_HTML::td($html_for_input) |
|
59 | - ); |
|
60 | - } |
|
61 | - return $html; |
|
62 | - } |
|
39 | + /** |
|
40 | + * Lays out the row for the input, including label and errors |
|
41 | + * |
|
42 | + * @param EE_Form_Input_Base $input |
|
43 | + * @return string |
|
44 | + */ |
|
45 | + public function layout_input($input) |
|
46 | + { |
|
47 | + $html = ''; |
|
48 | + if ($input instanceof EE_Hidden_Input) { |
|
49 | + $html .= $input->get_html_for_input(); |
|
50 | + } else { |
|
51 | + $html_for_input = $input->get_html_for_input(); |
|
52 | + $html_for_input .= $input->get_html_for_errors() != '' |
|
53 | + ? EEH_HTML::nl() . $input->get_html_for_errors() |
|
54 | + : ''; |
|
55 | + $html_for_input .= $input->get_html_for_help() != '' ? EEH_HTML::nl() . $input->get_html_for_help() : ''; |
|
56 | + $html .= EEH_HTML::tr( |
|
57 | + EEH_HTML::th($input->get_html_for_label()) . |
|
58 | + EEH_HTML::td($html_for_input) |
|
59 | + ); |
|
60 | + } |
|
61 | + return $html; |
|
62 | + } |
|
63 | 63 | |
64 | 64 | |
65 | 65 | |
66 | - /** |
|
67 | - * Lays out a row for the subsection |
|
68 | - * |
|
69 | - * @param EE_Form_Section_Proper $form_section |
|
70 | - * @return string |
|
71 | - */ |
|
72 | - public function layout_subsection($form_section) |
|
73 | - { |
|
74 | - $html = ''; |
|
75 | - if ($form_section instanceof EE_Form_Section_HTML) { |
|
76 | - $html .= $form_section->get_html(); |
|
77 | - } else { |
|
78 | - $html .= EEH_HTML::tr( |
|
79 | - EEH_HTML::td($form_section->get_html(), '', '', '', 'colspan="2"') |
|
80 | - ); |
|
81 | - } |
|
82 | - return $html; |
|
83 | - } |
|
66 | + /** |
|
67 | + * Lays out a row for the subsection |
|
68 | + * |
|
69 | + * @param EE_Form_Section_Proper $form_section |
|
70 | + * @return string |
|
71 | + */ |
|
72 | + public function layout_subsection($form_section) |
|
73 | + { |
|
74 | + $html = ''; |
|
75 | + if ($form_section instanceof EE_Form_Section_HTML) { |
|
76 | + $html .= $form_section->get_html(); |
|
77 | + } else { |
|
78 | + $html .= EEH_HTML::tr( |
|
79 | + EEH_HTML::td($form_section->get_html(), '', '', '', 'colspan="2"') |
|
80 | + ); |
|
81 | + } |
|
82 | + return $html; |
|
83 | + } |
|
84 | 84 | } |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | $this->_form_section->html_id(), |
19 | 19 | $this->_form_section->html_class(), |
20 | 20 | $this->_form_section->html_style() |
21 | - ) . EEH_HTML::tbody(); |
|
21 | + ).EEH_HTML::tbody(); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | */ |
32 | 32 | public function layout_form_end($additional_args = array()) |
33 | 33 | { |
34 | - return EEH_HTML::tbodyx() . EEH_HTML::tablex($this->_form_section->html_id()); |
|
34 | + return EEH_HTML::tbodyx().EEH_HTML::tablex($this->_form_section->html_id()); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | |
@@ -50,11 +50,11 @@ discard block |
||
50 | 50 | } else { |
51 | 51 | $html_for_input = $input->get_html_for_input(); |
52 | 52 | $html_for_input .= $input->get_html_for_errors() != '' |
53 | - ? EEH_HTML::nl() . $input->get_html_for_errors() |
|
53 | + ? EEH_HTML::nl().$input->get_html_for_errors() |
|
54 | 54 | : ''; |
55 | - $html_for_input .= $input->get_html_for_help() != '' ? EEH_HTML::nl() . $input->get_html_for_help() : ''; |
|
55 | + $html_for_input .= $input->get_html_for_help() != '' ? EEH_HTML::nl().$input->get_html_for_help() : ''; |
|
56 | 56 | $html .= EEH_HTML::tr( |
57 | - EEH_HTML::th($input->get_html_for_label()) . |
|
57 | + EEH_HTML::th($input->get_html_for_label()). |
|
58 | 58 | EEH_HTML::td($html_for_input) |
59 | 59 | ); |
60 | 60 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -27,201 +27,201 @@ discard block |
||
27 | 27 | class EE_Template_Layout extends EE_Div_Per_Section_Layout |
28 | 28 | { |
29 | 29 | |
30 | - protected $_layout_template_file = null; |
|
31 | - |
|
32 | - protected $_layout_begin_template_file = null; |
|
33 | - |
|
34 | - protected $_input_template_file = null; |
|
35 | - |
|
36 | - protected $_subsection_template_file = null; |
|
37 | - |
|
38 | - protected $_layout_end_template_file = null; |
|
39 | - |
|
40 | - protected $_template_args = array(); |
|
41 | - |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * @param array $template_options { |
|
46 | - * @type string $_layout_template_file |
|
47 | - * @type string $_begin_template_file |
|
48 | - * @type string $_input_template_file |
|
49 | - * @type string $_subsection_template_file |
|
50 | - * @type string $_end_template_file |
|
51 | - * @type array $_template_args |
|
52 | - * } |
|
53 | - */ |
|
54 | - public function __construct($template_options = array()) |
|
55 | - { |
|
56 | - // loop through incoming options |
|
57 | - foreach ($template_options as $key => $value) { |
|
58 | - // add underscore to $key to match property names |
|
59 | - $_key = '_' . $key; |
|
60 | - if (property_exists($this, $_key)) { |
|
61 | - $this->{$_key} = $value; |
|
62 | - } |
|
63 | - } |
|
64 | - parent::__construct(); |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * Also has the side effect of enqueuing any needed JS and CSS for |
|
71 | - * this form. |
|
72 | - * Creates all the HTML necessary for displaying this form, its inputs, and |
|
73 | - * proper subsections. |
|
74 | - * Returns the HTML |
|
75 | - * |
|
76 | - * @return string |
|
77 | - */ |
|
78 | - public function layout_form() |
|
79 | - { |
|
80 | - if ($this->_layout_template_file) { |
|
81 | - return EEH_Template::locate_template($this->_layout_template_file, $this->template_args(), true, true); |
|
82 | - } else { |
|
83 | - return parent::layout_form(); |
|
84 | - } |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * opening div tag for a form |
|
91 | - * |
|
92 | - * @return string |
|
93 | - */ |
|
94 | - public function layout_form_begin() |
|
95 | - { |
|
96 | - if ($this->_layout_begin_template_file) { |
|
97 | - return EEH_Template::locate_template( |
|
98 | - $this->_layout_begin_template_file, |
|
99 | - $this->template_args(), |
|
100 | - true, |
|
101 | - true |
|
102 | - ); |
|
103 | - } else { |
|
104 | - return parent::layout_form_begin(); |
|
105 | - } |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * If an input_template_file was provided upon construction, uses that to layout the input. Otherwise uses parent. |
|
112 | - * |
|
113 | - * @see EE_DIv_Per_Section_Layout::layout_input() for documentation |
|
114 | - * @param EE_Form_Input_Base $input |
|
115 | - * @return string |
|
116 | - */ |
|
117 | - public function layout_input($input) |
|
118 | - { |
|
119 | - if ($this->_input_template_file) { |
|
120 | - return EEH_Template::locate_template($this->_input_template_file, array('input' => $input), true, true); |
|
121 | - } |
|
122 | - return parent::layout_input($input); |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * If a subsection_template_file was provided upon construction, uses that to layout the subsection. Otherwise uses parent. |
|
129 | - * |
|
130 | - * @see EE_Div_Per_Section_Layout::layout_subsection() for documentation |
|
131 | - * @param EE_Form_Section_Proper $form_section |
|
132 | - * @return string |
|
133 | - */ |
|
134 | - public function layout_subsection($form_section) |
|
135 | - { |
|
136 | - if ($this->_subsection_template_file) { |
|
137 | - return EEH_Template::locate_template($this->_subsection_template_file, $this->template_args(), true, true); |
|
138 | - } |
|
139 | - return parent::layout_subsection($form_section); |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * closing div tag for a form |
|
146 | - * |
|
147 | - * @return string |
|
148 | - */ |
|
149 | - public function layout_form_end() |
|
150 | - { |
|
151 | - if ($this->_layout_end_template_file) { |
|
152 | - return EEH_Template::locate_template($this->_layout_end_template_file, $this->template_args(), true, true); |
|
153 | - } else { |
|
154 | - return parent::layout_form_end(); |
|
155 | - } |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * @param array $template_args |
|
162 | - */ |
|
163 | - public function set_template_args($template_args = array()) |
|
164 | - { |
|
165 | - $this->_template_args = $template_args; |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * @param array $template_args |
|
172 | - */ |
|
173 | - public function add_template_args($template_args = array()) |
|
174 | - { |
|
175 | - $this->_template_args = array_merge_recursive($this->_template_args, $template_args); |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * @return array |
|
182 | - */ |
|
183 | - public function template_args() |
|
184 | - { |
|
185 | - foreach ($this->form_section()->subsections() as $subsection_name => $subsection) { |
|
186 | - $subsection_name = self::prep_form_subsection_key_name($subsection_name); |
|
187 | - if (strpos($subsection_name, '[') !== false) { |
|
188 | - $sub_name = explode('[', $subsection_name); |
|
189 | - $this->_template_args[$sub_name[0]][rtrim($sub_name[1], ']')] = $this->layout_subsection($subsection); |
|
190 | - } else { |
|
191 | - $this->_template_args[$subsection_name] = $this->layout_subsection($subsection); |
|
192 | - } |
|
193 | - } |
|
194 | - // d( $this->_template_args ); |
|
195 | - return $this->_template_args; |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * prep_form_section_key_name |
|
202 | - * |
|
203 | - * @access public |
|
204 | - * @param string $subsection_name |
|
205 | - * @return string |
|
206 | - */ |
|
207 | - public static function prep_form_subsection_key_name($subsection_name = '') |
|
208 | - { |
|
209 | - $subsection_name = str_replace(array('-', ' '), array('', '_'), $subsection_name); |
|
210 | - return is_numeric(substr($subsection_name, 0, 1)) ? 'form_' . $subsection_name : $subsection_name; |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * get_subform - just a wrapper for the above method |
|
217 | - * |
|
218 | - * @access public |
|
219 | - * @param string $subsection_name |
|
220 | - * @return string |
|
221 | - */ |
|
222 | - public static function get_subform_name($subsection_name = '') |
|
223 | - { |
|
224 | - return EE_Template_Layout::prep_form_subsection_key_name($subsection_name); |
|
225 | - } |
|
30 | + protected $_layout_template_file = null; |
|
31 | + |
|
32 | + protected $_layout_begin_template_file = null; |
|
33 | + |
|
34 | + protected $_input_template_file = null; |
|
35 | + |
|
36 | + protected $_subsection_template_file = null; |
|
37 | + |
|
38 | + protected $_layout_end_template_file = null; |
|
39 | + |
|
40 | + protected $_template_args = array(); |
|
41 | + |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * @param array $template_options { |
|
46 | + * @type string $_layout_template_file |
|
47 | + * @type string $_begin_template_file |
|
48 | + * @type string $_input_template_file |
|
49 | + * @type string $_subsection_template_file |
|
50 | + * @type string $_end_template_file |
|
51 | + * @type array $_template_args |
|
52 | + * } |
|
53 | + */ |
|
54 | + public function __construct($template_options = array()) |
|
55 | + { |
|
56 | + // loop through incoming options |
|
57 | + foreach ($template_options as $key => $value) { |
|
58 | + // add underscore to $key to match property names |
|
59 | + $_key = '_' . $key; |
|
60 | + if (property_exists($this, $_key)) { |
|
61 | + $this->{$_key} = $value; |
|
62 | + } |
|
63 | + } |
|
64 | + parent::__construct(); |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * Also has the side effect of enqueuing any needed JS and CSS for |
|
71 | + * this form. |
|
72 | + * Creates all the HTML necessary for displaying this form, its inputs, and |
|
73 | + * proper subsections. |
|
74 | + * Returns the HTML |
|
75 | + * |
|
76 | + * @return string |
|
77 | + */ |
|
78 | + public function layout_form() |
|
79 | + { |
|
80 | + if ($this->_layout_template_file) { |
|
81 | + return EEH_Template::locate_template($this->_layout_template_file, $this->template_args(), true, true); |
|
82 | + } else { |
|
83 | + return parent::layout_form(); |
|
84 | + } |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * opening div tag for a form |
|
91 | + * |
|
92 | + * @return string |
|
93 | + */ |
|
94 | + public function layout_form_begin() |
|
95 | + { |
|
96 | + if ($this->_layout_begin_template_file) { |
|
97 | + return EEH_Template::locate_template( |
|
98 | + $this->_layout_begin_template_file, |
|
99 | + $this->template_args(), |
|
100 | + true, |
|
101 | + true |
|
102 | + ); |
|
103 | + } else { |
|
104 | + return parent::layout_form_begin(); |
|
105 | + } |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * If an input_template_file was provided upon construction, uses that to layout the input. Otherwise uses parent. |
|
112 | + * |
|
113 | + * @see EE_DIv_Per_Section_Layout::layout_input() for documentation |
|
114 | + * @param EE_Form_Input_Base $input |
|
115 | + * @return string |
|
116 | + */ |
|
117 | + public function layout_input($input) |
|
118 | + { |
|
119 | + if ($this->_input_template_file) { |
|
120 | + return EEH_Template::locate_template($this->_input_template_file, array('input' => $input), true, true); |
|
121 | + } |
|
122 | + return parent::layout_input($input); |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * If a subsection_template_file was provided upon construction, uses that to layout the subsection. Otherwise uses parent. |
|
129 | + * |
|
130 | + * @see EE_Div_Per_Section_Layout::layout_subsection() for documentation |
|
131 | + * @param EE_Form_Section_Proper $form_section |
|
132 | + * @return string |
|
133 | + */ |
|
134 | + public function layout_subsection($form_section) |
|
135 | + { |
|
136 | + if ($this->_subsection_template_file) { |
|
137 | + return EEH_Template::locate_template($this->_subsection_template_file, $this->template_args(), true, true); |
|
138 | + } |
|
139 | + return parent::layout_subsection($form_section); |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * closing div tag for a form |
|
146 | + * |
|
147 | + * @return string |
|
148 | + */ |
|
149 | + public function layout_form_end() |
|
150 | + { |
|
151 | + if ($this->_layout_end_template_file) { |
|
152 | + return EEH_Template::locate_template($this->_layout_end_template_file, $this->template_args(), true, true); |
|
153 | + } else { |
|
154 | + return parent::layout_form_end(); |
|
155 | + } |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * @param array $template_args |
|
162 | + */ |
|
163 | + public function set_template_args($template_args = array()) |
|
164 | + { |
|
165 | + $this->_template_args = $template_args; |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * @param array $template_args |
|
172 | + */ |
|
173 | + public function add_template_args($template_args = array()) |
|
174 | + { |
|
175 | + $this->_template_args = array_merge_recursive($this->_template_args, $template_args); |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * @return array |
|
182 | + */ |
|
183 | + public function template_args() |
|
184 | + { |
|
185 | + foreach ($this->form_section()->subsections() as $subsection_name => $subsection) { |
|
186 | + $subsection_name = self::prep_form_subsection_key_name($subsection_name); |
|
187 | + if (strpos($subsection_name, '[') !== false) { |
|
188 | + $sub_name = explode('[', $subsection_name); |
|
189 | + $this->_template_args[$sub_name[0]][rtrim($sub_name[1], ']')] = $this->layout_subsection($subsection); |
|
190 | + } else { |
|
191 | + $this->_template_args[$subsection_name] = $this->layout_subsection($subsection); |
|
192 | + } |
|
193 | + } |
|
194 | + // d( $this->_template_args ); |
|
195 | + return $this->_template_args; |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * prep_form_section_key_name |
|
202 | + * |
|
203 | + * @access public |
|
204 | + * @param string $subsection_name |
|
205 | + * @return string |
|
206 | + */ |
|
207 | + public static function prep_form_subsection_key_name($subsection_name = '') |
|
208 | + { |
|
209 | + $subsection_name = str_replace(array('-', ' '), array('', '_'), $subsection_name); |
|
210 | + return is_numeric(substr($subsection_name, 0, 1)) ? 'form_' . $subsection_name : $subsection_name; |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * get_subform - just a wrapper for the above method |
|
217 | + * |
|
218 | + * @access public |
|
219 | + * @param string $subsection_name |
|
220 | + * @return string |
|
221 | + */ |
|
222 | + public static function get_subform_name($subsection_name = '') |
|
223 | + { |
|
224 | + return EE_Template_Layout::prep_form_subsection_key_name($subsection_name); |
|
225 | + } |
|
226 | 226 | } |
227 | 227 | // End of file EE_Template_Layout.strategy.php |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | 4 | |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | // loop through incoming options |
57 | 57 | foreach ($template_options as $key => $value) { |
58 | 58 | // add underscore to $key to match property names |
59 | - $_key = '_' . $key; |
|
59 | + $_key = '_'.$key; |
|
60 | 60 | if (property_exists($this, $_key)) { |
61 | 61 | $this->{$_key} = $value; |
62 | 62 | } |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | public static function prep_form_subsection_key_name($subsection_name = '') |
208 | 208 | { |
209 | 209 | $subsection_name = str_replace(array('-', ' '), array('', '_'), $subsection_name); |
210 | - return is_numeric(substr($subsection_name, 0, 1)) ? 'form_' . $subsection_name : $subsection_name; |
|
210 | + return is_numeric(substr($subsection_name, 0, 1)) ? 'form_'.$subsection_name : $subsection_name; |
|
211 | 211 | } |
212 | 212 | |
213 | 213 |
@@ -111,7 +111,7 @@ |
||
111 | 111 | * |
112 | 112 | * @abstract |
113 | 113 | * @access protected |
114 | - * @return array |
|
114 | + * @return string[] |
|
115 | 115 | */ |
116 | 116 | protected function _get_table_filters() |
117 | 117 | { |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | /** |
@@ -22,106 +22,106 @@ discard block |
||
22 | 22 | class EE_Admin_Transactions_List_Table extends EE_Admin_List_Table |
23 | 23 | { |
24 | 24 | |
25 | - private $_status; |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * @param \Transactions_Admin_Page $admin_page |
|
30 | - */ |
|
31 | - public function __construct(\Transactions_Admin_Page $admin_page) |
|
32 | - { |
|
33 | - parent::__construct($admin_page); |
|
34 | - $this->_status = $this->_admin_page->get_transaction_status_array(); |
|
35 | - } |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - *_setup_data |
|
40 | - */ |
|
41 | - protected function _setup_data() |
|
42 | - { |
|
43 | - $this->_data = $this->_admin_page->get_transactions($this->_per_page); |
|
44 | - $status = ! empty($this->_req_data['status']) ? $this->_req_data['status'] : 'all'; |
|
45 | - $this->_all_data_count = $this->_admin_page->get_transactions($this->_per_page, true, $status); |
|
46 | - } |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - *_set_properties |
|
51 | - */ |
|
52 | - protected function _set_properties() |
|
53 | - { |
|
54 | - $this->_wp_list_args = array( |
|
55 | - 'singular' => __('transaction', 'event_espresso'), |
|
56 | - 'plural' => __('transactions', 'event_espresso'), |
|
57 | - 'ajax' => true, |
|
58 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
59 | - ); |
|
60 | - $ID_column_name = __('ID', 'event_espresso'); |
|
61 | - $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">'; |
|
62 | - $ID_column_name .= __('Transaction Date', 'event_espresso'); |
|
63 | - $ID_column_name .= '</span> '; |
|
64 | - $this->_columns = array( |
|
65 | - 'TXN_ID' => $ID_column_name, |
|
66 | - 'TXN_timestamp' => __('Transaction Date', 'event_espresso'), |
|
67 | - 'TXN_total' => __('Total', 'event_espresso'), |
|
68 | - 'TXN_paid' => __('Paid', 'event_espresso'), |
|
69 | - 'ATT_fname' => __('Primary Registrant', 'event_espresso'), |
|
70 | - 'event_name' => __('Event', 'event_espresso'), |
|
71 | - 'actions' => __('Actions', 'event_espresso'), |
|
72 | - ); |
|
73 | - |
|
74 | - $this->_sortable_columns = array( |
|
75 | - 'TXN_ID' => array('TXN_ID' => false), |
|
76 | - 'event_name' => array('event_name' => false), |
|
77 | - 'ATT_fname' => array('ATT_fname' => false), |
|
78 | - 'TXN_timestamp' => array('TXN_timestamp' => true) //true means its already sorted |
|
79 | - ); |
|
80 | - |
|
81 | - $this->_primary_column = 'TXN_ID'; |
|
82 | - |
|
83 | - $this->_hidden_columns = array(); |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * This simply sets up the row class for the table rows. |
|
89 | - * Allows for easier overriding of child methods for setting up sorting. |
|
90 | - * |
|
91 | - * @param EE_Transaction $item the current item |
|
92 | - * @return string |
|
93 | - * @throws \EE_Error |
|
94 | - */ |
|
95 | - protected function _get_row_class($item) |
|
96 | - { |
|
97 | - $class = parent::_get_row_class($item); |
|
98 | - //add status class |
|
99 | - $class .= ' ee-status-strip txn-status-' . $item->status_ID(); |
|
100 | - if ($this->_has_checkbox_column) { |
|
101 | - $class .= ' has-checkbox-column'; |
|
102 | - } |
|
103 | - return $class; |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * _get_table_filters |
|
109 | - * We use this to assemble and return any filters that are associated with this table that help further refine what |
|
110 | - * get's shown in the table. |
|
111 | - * |
|
112 | - * @abstract |
|
113 | - * @access protected |
|
114 | - * @return array |
|
115 | - */ |
|
116 | - protected function _get_table_filters() |
|
117 | - { |
|
118 | - $filters = array(); |
|
119 | - $start_date = isset($this->_req_data['txn-filter-start-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) : date('m/d/Y', |
|
120 | - strtotime('-10 year')); |
|
121 | - $end_date = isset($this->_req_data['txn-filter-end-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) : date('m/d/Y', |
|
122 | - current_time('timestamp')); |
|
123 | - ob_start(); |
|
124 | - ?> |
|
25 | + private $_status; |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * @param \Transactions_Admin_Page $admin_page |
|
30 | + */ |
|
31 | + public function __construct(\Transactions_Admin_Page $admin_page) |
|
32 | + { |
|
33 | + parent::__construct($admin_page); |
|
34 | + $this->_status = $this->_admin_page->get_transaction_status_array(); |
|
35 | + } |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + *_setup_data |
|
40 | + */ |
|
41 | + protected function _setup_data() |
|
42 | + { |
|
43 | + $this->_data = $this->_admin_page->get_transactions($this->_per_page); |
|
44 | + $status = ! empty($this->_req_data['status']) ? $this->_req_data['status'] : 'all'; |
|
45 | + $this->_all_data_count = $this->_admin_page->get_transactions($this->_per_page, true, $status); |
|
46 | + } |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + *_set_properties |
|
51 | + */ |
|
52 | + protected function _set_properties() |
|
53 | + { |
|
54 | + $this->_wp_list_args = array( |
|
55 | + 'singular' => __('transaction', 'event_espresso'), |
|
56 | + 'plural' => __('transactions', 'event_espresso'), |
|
57 | + 'ajax' => true, |
|
58 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
59 | + ); |
|
60 | + $ID_column_name = __('ID', 'event_espresso'); |
|
61 | + $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">'; |
|
62 | + $ID_column_name .= __('Transaction Date', 'event_espresso'); |
|
63 | + $ID_column_name .= '</span> '; |
|
64 | + $this->_columns = array( |
|
65 | + 'TXN_ID' => $ID_column_name, |
|
66 | + 'TXN_timestamp' => __('Transaction Date', 'event_espresso'), |
|
67 | + 'TXN_total' => __('Total', 'event_espresso'), |
|
68 | + 'TXN_paid' => __('Paid', 'event_espresso'), |
|
69 | + 'ATT_fname' => __('Primary Registrant', 'event_espresso'), |
|
70 | + 'event_name' => __('Event', 'event_espresso'), |
|
71 | + 'actions' => __('Actions', 'event_espresso'), |
|
72 | + ); |
|
73 | + |
|
74 | + $this->_sortable_columns = array( |
|
75 | + 'TXN_ID' => array('TXN_ID' => false), |
|
76 | + 'event_name' => array('event_name' => false), |
|
77 | + 'ATT_fname' => array('ATT_fname' => false), |
|
78 | + 'TXN_timestamp' => array('TXN_timestamp' => true) //true means its already sorted |
|
79 | + ); |
|
80 | + |
|
81 | + $this->_primary_column = 'TXN_ID'; |
|
82 | + |
|
83 | + $this->_hidden_columns = array(); |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * This simply sets up the row class for the table rows. |
|
89 | + * Allows for easier overriding of child methods for setting up sorting. |
|
90 | + * |
|
91 | + * @param EE_Transaction $item the current item |
|
92 | + * @return string |
|
93 | + * @throws \EE_Error |
|
94 | + */ |
|
95 | + protected function _get_row_class($item) |
|
96 | + { |
|
97 | + $class = parent::_get_row_class($item); |
|
98 | + //add status class |
|
99 | + $class .= ' ee-status-strip txn-status-' . $item->status_ID(); |
|
100 | + if ($this->_has_checkbox_column) { |
|
101 | + $class .= ' has-checkbox-column'; |
|
102 | + } |
|
103 | + return $class; |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * _get_table_filters |
|
109 | + * We use this to assemble and return any filters that are associated with this table that help further refine what |
|
110 | + * get's shown in the table. |
|
111 | + * |
|
112 | + * @abstract |
|
113 | + * @access protected |
|
114 | + * @return array |
|
115 | + */ |
|
116 | + protected function _get_table_filters() |
|
117 | + { |
|
118 | + $filters = array(); |
|
119 | + $start_date = isset($this->_req_data['txn-filter-start-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) : date('m/d/Y', |
|
120 | + strtotime('-10 year')); |
|
121 | + $end_date = isset($this->_req_data['txn-filter-end-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) : date('m/d/Y', |
|
122 | + current_time('timestamp')); |
|
123 | + ob_start(); |
|
124 | + ?> |
|
125 | 125 | <label for="txn-filter-start-date">Display Transactions from </label> |
126 | 126 | <input id="txn-filter-start-date" class="datepicker" type="text" value="<?php echo $start_date; ?>" |
127 | 127 | name="txn-filter-start-date" size="15"/> |
@@ -129,361 +129,361 @@ discard block |
||
129 | 129 | <input id="txn-filter-end-date" class="datepicker" type="text" value="<?php echo $end_date; ?>" |
130 | 130 | name="txn-filter-end-date" size="15"/> |
131 | 131 | <?php |
132 | - $filters[] = ob_get_contents(); |
|
133 | - ob_end_clean(); |
|
134 | - return $filters; |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - *_add_view_counts |
|
140 | - */ |
|
141 | - protected function _add_view_counts() |
|
142 | - { |
|
143 | - $this->_views['all']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'all'); |
|
144 | - $this->_views['abandoned']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'abandoned'); |
|
145 | - $this->_views['failed']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'failed'); |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * column TXN_ID |
|
151 | - * |
|
152 | - * @param \EE_Transaction $item |
|
153 | - * @return string |
|
154 | - * @throws \EE_Error |
|
155 | - */ |
|
156 | - public function column_TXN_ID(EE_Transaction $item) |
|
157 | - { |
|
158 | - $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
159 | - 'action' => 'view_transaction', |
|
160 | - 'TXN_ID' => $item->ID(), |
|
161 | - ), TXN_ADMIN_URL); |
|
162 | - $content = '<a href="' . $view_lnk_url . '" title="' . esc_attr__('Go to Transaction Details', |
|
163 | - 'event_espresso') . '">' . $item->ID() . '</a>'; |
|
164 | - |
|
165 | - //txn timestamp |
|
166 | - $content .= ' <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($item) . '</span>'; |
|
167 | - return $content; |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * @param \EE_Transaction $item |
|
173 | - * @return mixed|string|void |
|
174 | - * @throws \EE_Error |
|
175 | - */ |
|
176 | - protected function _get_txn_timestamp(EE_Transaction $item) |
|
177 | - { |
|
178 | - //txn timestamp |
|
179 | - // is TXN less than 2 hours old ? |
|
180 | - if ( |
|
181 | - ($item->failed() || $item->is_abandoned()) |
|
182 | - && ( |
|
183 | - (time() - EE_Registry::instance()->SSN->lifespan()) < $item->datetime(false, true) |
|
184 | - ) |
|
185 | - ) { |
|
186 | - $timestamp = __('TXN in progress...', 'event_espresso'); |
|
187 | - } else { |
|
188 | - $timestamp = $item->get_i18n_datetime('TXN_timestamp'); |
|
189 | - } |
|
190 | - return $timestamp; |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * column_cb |
|
196 | - * |
|
197 | - * @param \EE_Transaction $item |
|
198 | - * @return string |
|
199 | - * @throws \EE_Error |
|
200 | - */ |
|
201 | - public function column_cb($item) |
|
202 | - { |
|
203 | - return sprintf('<input type="checkbox" name="%1$s[]" value="%2$s" />', $this->_wp_list_args['singular'], |
|
204 | - $item->ID()); |
|
205 | - } |
|
206 | - |
|
207 | - |
|
208 | - /** |
|
209 | - * column_TXN_timestamp |
|
210 | - * |
|
211 | - * @param \EE_Transaction $item |
|
212 | - * @return string |
|
213 | - * @throws \EE_Error |
|
214 | - */ |
|
215 | - public function column_TXN_timestamp(EE_Transaction $item) |
|
216 | - { |
|
217 | - $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
218 | - 'action' => 'view_transaction', |
|
219 | - 'TXN_ID' => $item->ID(), |
|
220 | - ), TXN_ADMIN_URL); |
|
221 | - $txn_date = '<a href="' . $view_lnk_url . '" title="' . esc_attr__('View Transaction Details for TXN #', |
|
222 | - 'event_espresso') . $item->ID() . '">' . $this->_get_txn_timestamp($item) . '</a>'; |
|
223 | - //status |
|
224 | - $txn_date .= '<br><span class="ee-status-text-small">' . EEH_Template::pretty_status($item->status_ID(), false, |
|
225 | - 'sentence') . '</span>'; |
|
226 | - return $txn_date; |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * column_TXN_total |
|
232 | - * |
|
233 | - * @param \EE_Transaction $item |
|
234 | - * @return string |
|
235 | - * @throws \EE_Error |
|
236 | - */ |
|
237 | - public function column_TXN_total(EE_Transaction $item) |
|
238 | - { |
|
239 | - if ($item->get('TXN_total') > 0) { |
|
240 | - return '<span class="txn-pad-rght">' . apply_filters('FHEE__EE_Admin_Transactions_List_Table__column_TXN_total__TXN_total', |
|
241 | - $item->get_pretty('TXN_total'), $item) . '</span>'; |
|
242 | - } else { |
|
243 | - return '<span class="txn-overview-free-event-spn">' . __('free', 'event_espresso') . '</span>'; |
|
244 | - } |
|
245 | - } |
|
246 | - |
|
247 | - |
|
248 | - /** |
|
249 | - * column_TXN_paid |
|
250 | - * |
|
251 | - * @param \EE_Transaction $item |
|
252 | - * @return mixed|string |
|
253 | - * @throws \EE_Error |
|
254 | - */ |
|
255 | - public function column_TXN_paid(EE_Transaction $item) |
|
256 | - { |
|
257 | - $transaction_total = $item->get('TXN_total'); |
|
258 | - $transaction_paid = $item->get('TXN_paid'); |
|
259 | - |
|
260 | - if (\EEH_Money::compare_floats($transaction_total, 0, '>')) { |
|
261 | - // monies owing |
|
262 | - $span_class = 'txn-overview-part-payment-spn'; |
|
263 | - if (\EEH_Money::compare_floats($transaction_paid, $transaction_total, '>=')) { |
|
264 | - // paid in full |
|
265 | - $span_class = 'txn-overview-full-payment-spn'; |
|
266 | - } elseif (\EEH_Money::compare_floats($transaction_paid, 0, '==')) { |
|
267 | - // no payments made |
|
268 | - $span_class = 'txn-overview-no-payment-spn'; |
|
269 | - } |
|
270 | - } else { |
|
271 | - $span_class = 'txn-overview-free-event-spn'; |
|
272 | - $transaction_paid = 0; |
|
273 | - } |
|
274 | - |
|
275 | - $payment_method = $item->payment_method(); |
|
276 | - $payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name() : __('Unknown', |
|
277 | - 'event_espresso'); |
|
278 | - |
|
279 | - $content = '<span class="' . $span_class . ' txn-pad-rght">' . $transaction_paid !== 0 ? $item->get_pretty('TXN_paid') : $transaction_paid . '</span>'; |
|
280 | - if ($transaction_paid > 0) { |
|
281 | - $content .= '<br><span class="ee-status-text-small">' . sprintf(__('...via %s', 'event_espresso'), |
|
282 | - $payment_method_name) . '</span>'; |
|
283 | - } |
|
284 | - return $content; |
|
285 | - } |
|
286 | - |
|
287 | - |
|
288 | - /** |
|
289 | - * column_ATT_fname |
|
290 | - * |
|
291 | - * @param \EE_Transaction $item |
|
292 | - * @return string|void |
|
293 | - * @throws \EE_Error |
|
294 | - */ |
|
295 | - public function column_ATT_fname(EE_Transaction $item) |
|
296 | - { |
|
297 | - $primary_reg = $item->primary_registration(); |
|
298 | - $attendee = $primary_reg->get_first_related('Attendee'); |
|
299 | - if ($attendee instanceof EE_Attendee) { |
|
300 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
301 | - 'action' => 'view_registration', |
|
302 | - '_REG_ID' => $primary_reg->ID(), |
|
303 | - ), REG_ADMIN_URL); |
|
304 | - $content = EE_Registry::instance()->CAP->current_user_can('ee_read_registration', |
|
305 | - 'espresso_registrations_view_registration', |
|
306 | - $primary_reg->ID()) ? '<a href="' . $edit_lnk_url . '" title="' . esc_attr__('View Registration Details', |
|
307 | - 'event_espresso') . '">' . $attendee->full_name() . '</a>' : $attendee->full_name(); |
|
308 | - $content .= '<br>' . $attendee->email(); |
|
309 | - return $content; |
|
310 | - } |
|
311 | - return $item->failed() || $item->is_abandoned() ? __('no contact record.', |
|
312 | - 'event_espresso') : __('No contact record, because the transaction was abandoned or the registration process failed.', |
|
313 | - 'event_espresso'); |
|
314 | - } |
|
315 | - |
|
316 | - |
|
317 | - /** |
|
318 | - * column_ATT_email |
|
319 | - * |
|
320 | - * @param \EE_Transaction $item |
|
321 | - * @return string|void |
|
322 | - * @throws \EE_Error |
|
323 | - */ |
|
324 | - public function column_ATT_email(EE_Transaction $item) |
|
325 | - { |
|
326 | - $attendee = $item->primary_registration()->get_first_related('Attendee'); |
|
327 | - if (! empty($attendee)) { |
|
328 | - return '<a href="mailto:' . $attendee->get('ATT_email') . '">' . $attendee->get('ATT_email') . '</a>'; |
|
329 | - } else { |
|
330 | - return $item->failed() || $item->is_abandoned() |
|
331 | - ? __('no contact record.', 'event_espresso') |
|
332 | - : __( |
|
333 | - 'No contact record, because the transaction was abandoned or the registration process failed.', |
|
334 | - 'event_espresso' |
|
335 | - ); |
|
336 | - } |
|
337 | - } |
|
338 | - |
|
339 | - |
|
340 | - /** |
|
341 | - * column_event_name |
|
342 | - * |
|
343 | - * @param \EE_Transaction $item |
|
344 | - * @return string|void |
|
345 | - * @throws \EE_Error |
|
346 | - */ |
|
347 | - public function column_event_name(EE_Transaction $item) |
|
348 | - { |
|
349 | - $actions = array(); |
|
350 | - $event = $item->primary_registration()->get_first_related('Event'); |
|
351 | - if (! empty($event)) { |
|
352 | - $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $event->ID()), |
|
353 | - EVENTS_ADMIN_URL); |
|
354 | - $event_name = $event->get('EVT_name'); |
|
355 | - |
|
356 | - //filter this view by transactions for this event |
|
357 | - $txn_by_event_lnk = EE_Admin_Page::add_query_args_and_nonce(array( |
|
358 | - 'action' => 'default', |
|
359 | - 'EVT_ID' => $event->ID(), |
|
360 | - )); |
|
361 | - if (EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'espresso_events_edit', $event->ID())) { |
|
362 | - $actions['filter_by_event'] = '<a href="' . $txn_by_event_lnk . '" title="' . esc_attr__('Filter transactions by this event', |
|
363 | - 'event_espresso') . '">' . __('View Transactions for this event', 'event_espresso') . '</a>'; |
|
364 | - } |
|
365 | - |
|
366 | - return sprintf('%1$s %2$s', |
|
367 | - EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'espresso_events_edit', |
|
368 | - $event->ID()) ? '<a href="' . $edit_event_url . '" title="' . sprintf(esc_attr__('Edit Event: %s', |
|
369 | - 'event_espresso'), $event->get('EVT_name')) . '">' . wp_trim_words($event_name, 30, |
|
370 | - '...') . '</a>' : wp_trim_words($event_name, 30, '...'), $this->row_actions($actions)); |
|
371 | - } else { |
|
372 | - return __('The event associated with this transaction via the primary registration cannot be retrieved.', |
|
373 | - 'event_espresso'); |
|
374 | - } |
|
375 | - } |
|
376 | - |
|
377 | - |
|
378 | - /** |
|
379 | - * column_actions |
|
380 | - * |
|
381 | - * @param \EE_Transaction $item |
|
382 | - * @return string |
|
383 | - * @throws \EE_Error |
|
384 | - */ |
|
385 | - public function column_actions(EE_Transaction $item) |
|
386 | - { |
|
387 | - |
|
388 | - $registration = $item->primary_registration(); |
|
389 | - $attendee = $registration->attendee(); |
|
390 | - |
|
391 | - //Build row actions |
|
392 | - $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
393 | - 'action' => 'view_transaction', |
|
394 | - 'TXN_ID' => $item->ID(), |
|
395 | - ), TXN_ADMIN_URL); |
|
396 | - $dl_invoice_lnk_url = $registration->invoice_url(); |
|
397 | - $dl_receipt_lnk_url = $registration->receipt_url(); |
|
398 | - $view_reg_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
399 | - 'action' => 'view_registration', |
|
400 | - '_REG_ID' => $registration->ID(), |
|
401 | - ), REG_ADMIN_URL); |
|
402 | - $send_pay_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
403 | - 'action' => 'send_payment_reminder', |
|
404 | - 'TXN_ID' => $item->ID(), |
|
405 | - ), TXN_ADMIN_URL); |
|
406 | - $related_messages_link = EEH_MSG_Template::get_message_action_link('see_notifications_for', null, array( |
|
407 | - 'TXN_ID' => $item->ID(), |
|
408 | - )); |
|
409 | - |
|
410 | - //Build row actions |
|
411 | - $view_lnk = ' |
|
132 | + $filters[] = ob_get_contents(); |
|
133 | + ob_end_clean(); |
|
134 | + return $filters; |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + *_add_view_counts |
|
140 | + */ |
|
141 | + protected function _add_view_counts() |
|
142 | + { |
|
143 | + $this->_views['all']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'all'); |
|
144 | + $this->_views['abandoned']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'abandoned'); |
|
145 | + $this->_views['failed']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'failed'); |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * column TXN_ID |
|
151 | + * |
|
152 | + * @param \EE_Transaction $item |
|
153 | + * @return string |
|
154 | + * @throws \EE_Error |
|
155 | + */ |
|
156 | + public function column_TXN_ID(EE_Transaction $item) |
|
157 | + { |
|
158 | + $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
159 | + 'action' => 'view_transaction', |
|
160 | + 'TXN_ID' => $item->ID(), |
|
161 | + ), TXN_ADMIN_URL); |
|
162 | + $content = '<a href="' . $view_lnk_url . '" title="' . esc_attr__('Go to Transaction Details', |
|
163 | + 'event_espresso') . '">' . $item->ID() . '</a>'; |
|
164 | + |
|
165 | + //txn timestamp |
|
166 | + $content .= ' <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($item) . '</span>'; |
|
167 | + return $content; |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * @param \EE_Transaction $item |
|
173 | + * @return mixed|string|void |
|
174 | + * @throws \EE_Error |
|
175 | + */ |
|
176 | + protected function _get_txn_timestamp(EE_Transaction $item) |
|
177 | + { |
|
178 | + //txn timestamp |
|
179 | + // is TXN less than 2 hours old ? |
|
180 | + if ( |
|
181 | + ($item->failed() || $item->is_abandoned()) |
|
182 | + && ( |
|
183 | + (time() - EE_Registry::instance()->SSN->lifespan()) < $item->datetime(false, true) |
|
184 | + ) |
|
185 | + ) { |
|
186 | + $timestamp = __('TXN in progress...', 'event_espresso'); |
|
187 | + } else { |
|
188 | + $timestamp = $item->get_i18n_datetime('TXN_timestamp'); |
|
189 | + } |
|
190 | + return $timestamp; |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * column_cb |
|
196 | + * |
|
197 | + * @param \EE_Transaction $item |
|
198 | + * @return string |
|
199 | + * @throws \EE_Error |
|
200 | + */ |
|
201 | + public function column_cb($item) |
|
202 | + { |
|
203 | + return sprintf('<input type="checkbox" name="%1$s[]" value="%2$s" />', $this->_wp_list_args['singular'], |
|
204 | + $item->ID()); |
|
205 | + } |
|
206 | + |
|
207 | + |
|
208 | + /** |
|
209 | + * column_TXN_timestamp |
|
210 | + * |
|
211 | + * @param \EE_Transaction $item |
|
212 | + * @return string |
|
213 | + * @throws \EE_Error |
|
214 | + */ |
|
215 | + public function column_TXN_timestamp(EE_Transaction $item) |
|
216 | + { |
|
217 | + $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
218 | + 'action' => 'view_transaction', |
|
219 | + 'TXN_ID' => $item->ID(), |
|
220 | + ), TXN_ADMIN_URL); |
|
221 | + $txn_date = '<a href="' . $view_lnk_url . '" title="' . esc_attr__('View Transaction Details for TXN #', |
|
222 | + 'event_espresso') . $item->ID() . '">' . $this->_get_txn_timestamp($item) . '</a>'; |
|
223 | + //status |
|
224 | + $txn_date .= '<br><span class="ee-status-text-small">' . EEH_Template::pretty_status($item->status_ID(), false, |
|
225 | + 'sentence') . '</span>'; |
|
226 | + return $txn_date; |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * column_TXN_total |
|
232 | + * |
|
233 | + * @param \EE_Transaction $item |
|
234 | + * @return string |
|
235 | + * @throws \EE_Error |
|
236 | + */ |
|
237 | + public function column_TXN_total(EE_Transaction $item) |
|
238 | + { |
|
239 | + if ($item->get('TXN_total') > 0) { |
|
240 | + return '<span class="txn-pad-rght">' . apply_filters('FHEE__EE_Admin_Transactions_List_Table__column_TXN_total__TXN_total', |
|
241 | + $item->get_pretty('TXN_total'), $item) . '</span>'; |
|
242 | + } else { |
|
243 | + return '<span class="txn-overview-free-event-spn">' . __('free', 'event_espresso') . '</span>'; |
|
244 | + } |
|
245 | + } |
|
246 | + |
|
247 | + |
|
248 | + /** |
|
249 | + * column_TXN_paid |
|
250 | + * |
|
251 | + * @param \EE_Transaction $item |
|
252 | + * @return mixed|string |
|
253 | + * @throws \EE_Error |
|
254 | + */ |
|
255 | + public function column_TXN_paid(EE_Transaction $item) |
|
256 | + { |
|
257 | + $transaction_total = $item->get('TXN_total'); |
|
258 | + $transaction_paid = $item->get('TXN_paid'); |
|
259 | + |
|
260 | + if (\EEH_Money::compare_floats($transaction_total, 0, '>')) { |
|
261 | + // monies owing |
|
262 | + $span_class = 'txn-overview-part-payment-spn'; |
|
263 | + if (\EEH_Money::compare_floats($transaction_paid, $transaction_total, '>=')) { |
|
264 | + // paid in full |
|
265 | + $span_class = 'txn-overview-full-payment-spn'; |
|
266 | + } elseif (\EEH_Money::compare_floats($transaction_paid, 0, '==')) { |
|
267 | + // no payments made |
|
268 | + $span_class = 'txn-overview-no-payment-spn'; |
|
269 | + } |
|
270 | + } else { |
|
271 | + $span_class = 'txn-overview-free-event-spn'; |
|
272 | + $transaction_paid = 0; |
|
273 | + } |
|
274 | + |
|
275 | + $payment_method = $item->payment_method(); |
|
276 | + $payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name() : __('Unknown', |
|
277 | + 'event_espresso'); |
|
278 | + |
|
279 | + $content = '<span class="' . $span_class . ' txn-pad-rght">' . $transaction_paid !== 0 ? $item->get_pretty('TXN_paid') : $transaction_paid . '</span>'; |
|
280 | + if ($transaction_paid > 0) { |
|
281 | + $content .= '<br><span class="ee-status-text-small">' . sprintf(__('...via %s', 'event_espresso'), |
|
282 | + $payment_method_name) . '</span>'; |
|
283 | + } |
|
284 | + return $content; |
|
285 | + } |
|
286 | + |
|
287 | + |
|
288 | + /** |
|
289 | + * column_ATT_fname |
|
290 | + * |
|
291 | + * @param \EE_Transaction $item |
|
292 | + * @return string|void |
|
293 | + * @throws \EE_Error |
|
294 | + */ |
|
295 | + public function column_ATT_fname(EE_Transaction $item) |
|
296 | + { |
|
297 | + $primary_reg = $item->primary_registration(); |
|
298 | + $attendee = $primary_reg->get_first_related('Attendee'); |
|
299 | + if ($attendee instanceof EE_Attendee) { |
|
300 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
301 | + 'action' => 'view_registration', |
|
302 | + '_REG_ID' => $primary_reg->ID(), |
|
303 | + ), REG_ADMIN_URL); |
|
304 | + $content = EE_Registry::instance()->CAP->current_user_can('ee_read_registration', |
|
305 | + 'espresso_registrations_view_registration', |
|
306 | + $primary_reg->ID()) ? '<a href="' . $edit_lnk_url . '" title="' . esc_attr__('View Registration Details', |
|
307 | + 'event_espresso') . '">' . $attendee->full_name() . '</a>' : $attendee->full_name(); |
|
308 | + $content .= '<br>' . $attendee->email(); |
|
309 | + return $content; |
|
310 | + } |
|
311 | + return $item->failed() || $item->is_abandoned() ? __('no contact record.', |
|
312 | + 'event_espresso') : __('No contact record, because the transaction was abandoned or the registration process failed.', |
|
313 | + 'event_espresso'); |
|
314 | + } |
|
315 | + |
|
316 | + |
|
317 | + /** |
|
318 | + * column_ATT_email |
|
319 | + * |
|
320 | + * @param \EE_Transaction $item |
|
321 | + * @return string|void |
|
322 | + * @throws \EE_Error |
|
323 | + */ |
|
324 | + public function column_ATT_email(EE_Transaction $item) |
|
325 | + { |
|
326 | + $attendee = $item->primary_registration()->get_first_related('Attendee'); |
|
327 | + if (! empty($attendee)) { |
|
328 | + return '<a href="mailto:' . $attendee->get('ATT_email') . '">' . $attendee->get('ATT_email') . '</a>'; |
|
329 | + } else { |
|
330 | + return $item->failed() || $item->is_abandoned() |
|
331 | + ? __('no contact record.', 'event_espresso') |
|
332 | + : __( |
|
333 | + 'No contact record, because the transaction was abandoned or the registration process failed.', |
|
334 | + 'event_espresso' |
|
335 | + ); |
|
336 | + } |
|
337 | + } |
|
338 | + |
|
339 | + |
|
340 | + /** |
|
341 | + * column_event_name |
|
342 | + * |
|
343 | + * @param \EE_Transaction $item |
|
344 | + * @return string|void |
|
345 | + * @throws \EE_Error |
|
346 | + */ |
|
347 | + public function column_event_name(EE_Transaction $item) |
|
348 | + { |
|
349 | + $actions = array(); |
|
350 | + $event = $item->primary_registration()->get_first_related('Event'); |
|
351 | + if (! empty($event)) { |
|
352 | + $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $event->ID()), |
|
353 | + EVENTS_ADMIN_URL); |
|
354 | + $event_name = $event->get('EVT_name'); |
|
355 | + |
|
356 | + //filter this view by transactions for this event |
|
357 | + $txn_by_event_lnk = EE_Admin_Page::add_query_args_and_nonce(array( |
|
358 | + 'action' => 'default', |
|
359 | + 'EVT_ID' => $event->ID(), |
|
360 | + )); |
|
361 | + if (EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'espresso_events_edit', $event->ID())) { |
|
362 | + $actions['filter_by_event'] = '<a href="' . $txn_by_event_lnk . '" title="' . esc_attr__('Filter transactions by this event', |
|
363 | + 'event_espresso') . '">' . __('View Transactions for this event', 'event_espresso') . '</a>'; |
|
364 | + } |
|
365 | + |
|
366 | + return sprintf('%1$s %2$s', |
|
367 | + EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'espresso_events_edit', |
|
368 | + $event->ID()) ? '<a href="' . $edit_event_url . '" title="' . sprintf(esc_attr__('Edit Event: %s', |
|
369 | + 'event_espresso'), $event->get('EVT_name')) . '">' . wp_trim_words($event_name, 30, |
|
370 | + '...') . '</a>' : wp_trim_words($event_name, 30, '...'), $this->row_actions($actions)); |
|
371 | + } else { |
|
372 | + return __('The event associated with this transaction via the primary registration cannot be retrieved.', |
|
373 | + 'event_espresso'); |
|
374 | + } |
|
375 | + } |
|
376 | + |
|
377 | + |
|
378 | + /** |
|
379 | + * column_actions |
|
380 | + * |
|
381 | + * @param \EE_Transaction $item |
|
382 | + * @return string |
|
383 | + * @throws \EE_Error |
|
384 | + */ |
|
385 | + public function column_actions(EE_Transaction $item) |
|
386 | + { |
|
387 | + |
|
388 | + $registration = $item->primary_registration(); |
|
389 | + $attendee = $registration->attendee(); |
|
390 | + |
|
391 | + //Build row actions |
|
392 | + $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
393 | + 'action' => 'view_transaction', |
|
394 | + 'TXN_ID' => $item->ID(), |
|
395 | + ), TXN_ADMIN_URL); |
|
396 | + $dl_invoice_lnk_url = $registration->invoice_url(); |
|
397 | + $dl_receipt_lnk_url = $registration->receipt_url(); |
|
398 | + $view_reg_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
399 | + 'action' => 'view_registration', |
|
400 | + '_REG_ID' => $registration->ID(), |
|
401 | + ), REG_ADMIN_URL); |
|
402 | + $send_pay_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
403 | + 'action' => 'send_payment_reminder', |
|
404 | + 'TXN_ID' => $item->ID(), |
|
405 | + ), TXN_ADMIN_URL); |
|
406 | + $related_messages_link = EEH_MSG_Template::get_message_action_link('see_notifications_for', null, array( |
|
407 | + 'TXN_ID' => $item->ID(), |
|
408 | + )); |
|
409 | + |
|
410 | + //Build row actions |
|
411 | + $view_lnk = ' |
|
412 | 412 | <li> |
413 | 413 | <a href="' . $view_lnk_url . '" title="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="tiny-text"> |
414 | 414 | <span class="dashicons dashicons-cart"></span> |
415 | 415 | </a> |
416 | 416 | </li>'; |
417 | 417 | |
418 | - $dl_invoice_lnk = ''; |
|
419 | - //only show invoice link if message type is active. |
|
420 | - if ($attendee instanceof EE_Attendee && EEH_MSG_Template::is_mt_active('invoice')) { |
|
421 | - $dl_invoice_lnk = ' |
|
418 | + $dl_invoice_lnk = ''; |
|
419 | + //only show invoice link if message type is active. |
|
420 | + if ($attendee instanceof EE_Attendee && EEH_MSG_Template::is_mt_active('invoice')) { |
|
421 | + $dl_invoice_lnk = ' |
|
422 | 422 | <li> |
423 | 423 | <a title="' . esc_attr__('View Transaction Invoice', |
424 | - 'event_espresso') . '" target="_blank" href="' . $dl_invoice_lnk_url . '" class="tiny-text"> |
|
424 | + 'event_espresso') . '" target="_blank" href="' . $dl_invoice_lnk_url . '" class="tiny-text"> |
|
425 | 425 | <span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span> |
426 | 426 | </a> |
427 | 427 | </li>'; |
428 | - } |
|
428 | + } |
|
429 | 429 | |
430 | - $dl_receipt_lnk = ''; |
|
431 | - //only show receipt link if message type is active. |
|
432 | - if ($attendee instanceof EE_Attendee && EEH_MSG_Template::is_mt_active('receipt')) { |
|
433 | - $dl_receipt_lnk = ' |
|
430 | + $dl_receipt_lnk = ''; |
|
431 | + //only show receipt link if message type is active. |
|
432 | + if ($attendee instanceof EE_Attendee && EEH_MSG_Template::is_mt_active('receipt')) { |
|
433 | + $dl_receipt_lnk = ' |
|
434 | 434 | <li> |
435 | 435 | <a title="' . esc_attr__('View Transaction Receipt', |
436 | - 'event_espresso') . '" target="_blank" href="' . $dl_receipt_lnk_url . '" class="tiny-text"> |
|
436 | + 'event_espresso') . '" target="_blank" href="' . $dl_receipt_lnk_url . '" class="tiny-text"> |
|
437 | 437 | <span class="dashicons dashicons-media-default ee-icon-size-18"></span> |
438 | 438 | </a> |
439 | 439 | </li>'; |
440 | - } |
|
441 | - |
|
442 | - //only show payment reminder link if the message type is active. |
|
443 | - if (EEH_MSG_Template::is_mt_active('payment_reminder')) { |
|
444 | - $send_pay_lnk = $attendee instanceof EE_Attendee |
|
445 | - && EE_Registry::instance()->CAP->current_user_can( |
|
446 | - 'ee_send_message', |
|
447 | - 'espresso_transactions_send_payment_reminder' |
|
448 | - ) |
|
449 | - ? ' |
|
440 | + } |
|
441 | + |
|
442 | + //only show payment reminder link if the message type is active. |
|
443 | + if (EEH_MSG_Template::is_mt_active('payment_reminder')) { |
|
444 | + $send_pay_lnk = $attendee instanceof EE_Attendee |
|
445 | + && EE_Registry::instance()->CAP->current_user_can( |
|
446 | + 'ee_send_message', |
|
447 | + 'espresso_transactions_send_payment_reminder' |
|
448 | + ) |
|
449 | + ? ' |
|
450 | 450 | <li> |
451 | 451 | <a href="' . $send_pay_lnk_url . '" title="' . esc_attr__('Send Payment Reminder', |
452 | - 'event_espresso') . '" class="tiny-text"> |
|
452 | + 'event_espresso') . '" class="tiny-text"> |
|
453 | 453 | <span class="dashicons dashicons-email-alt"></span> |
454 | 454 | </a> |
455 | 455 | </li>' |
456 | - : ''; |
|
457 | - $send_pay_lnk = $item->get('STS_ID') !== EEM_Transaction::complete_status_code |
|
458 | - && $item->get('STS_ID') !== EEM_Transaction::overpaid_status_code |
|
459 | - ? $send_pay_lnk |
|
460 | - : ''; |
|
461 | - } else { |
|
462 | - $send_pay_lnk = ''; |
|
463 | - } |
|
464 | - |
|
465 | - $view_reg_lnk = EE_Registry::instance()->CAP->current_user_can( |
|
466 | - 'ee_read_registration', |
|
467 | - 'espresso_registrations_view_registration', |
|
468 | - $registration->ID() |
|
469 | - ) |
|
470 | - ? ' |
|
456 | + : ''; |
|
457 | + $send_pay_lnk = $item->get('STS_ID') !== EEM_Transaction::complete_status_code |
|
458 | + && $item->get('STS_ID') !== EEM_Transaction::overpaid_status_code |
|
459 | + ? $send_pay_lnk |
|
460 | + : ''; |
|
461 | + } else { |
|
462 | + $send_pay_lnk = ''; |
|
463 | + } |
|
464 | + |
|
465 | + $view_reg_lnk = EE_Registry::instance()->CAP->current_user_can( |
|
466 | + 'ee_read_registration', |
|
467 | + 'espresso_registrations_view_registration', |
|
468 | + $registration->ID() |
|
469 | + ) |
|
470 | + ? ' |
|
471 | 471 | <li> |
472 | 472 | <a href="' . $view_reg_lnk_url . '" title="' . esc_attr__('View Registration Details', |
473 | - 'event_espresso') . '" class="tiny-text"> |
|
473 | + 'event_espresso') . '" class="tiny-text"> |
|
474 | 474 | <span class="dashicons dashicons-clipboard"></span> |
475 | 475 | </a> |
476 | 476 | </li>' |
477 | - : ''; |
|
477 | + : ''; |
|
478 | 478 | |
479 | - $view_related_messages_lnk = ''; |
|
480 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
481 | - $view_related_messages_lnk = '<li>' . $related_messages_link . '</li>'; |
|
482 | - } |
|
479 | + $view_related_messages_lnk = ''; |
|
480 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
481 | + $view_related_messages_lnk = '<li>' . $related_messages_link . '</li>'; |
|
482 | + } |
|
483 | 483 | |
484 | - return $this->_action_string($view_lnk . $dl_invoice_lnk . $dl_receipt_lnk . $view_reg_lnk . $send_pay_lnk . $view_related_messages_lnk, |
|
485 | - $item, 'ul', 'txn-overview-actions-ul'); |
|
486 | - } |
|
484 | + return $this->_action_string($view_lnk . $dl_invoice_lnk . $dl_receipt_lnk . $view_reg_lnk . $send_pay_lnk . $view_related_messages_lnk, |
|
485 | + $item, 'ul', 'txn-overview-actions-ul'); |
|
486 | + } |
|
487 | 487 | |
488 | 488 | |
489 | 489 | } |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | 4 | |
@@ -57,11 +57,11 @@ discard block |
||
57 | 57 | 'ajax' => true, |
58 | 58 | 'screen' => $this->_admin_page->get_current_screen()->id, |
59 | 59 | ); |
60 | - $ID_column_name = __('ID', 'event_espresso'); |
|
60 | + $ID_column_name = __('ID', 'event_espresso'); |
|
61 | 61 | $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">'; |
62 | 62 | $ID_column_name .= __('Transaction Date', 'event_espresso'); |
63 | 63 | $ID_column_name .= '</span> '; |
64 | - $this->_columns = array( |
|
64 | + $this->_columns = array( |
|
65 | 65 | 'TXN_ID' => $ID_column_name, |
66 | 66 | 'TXN_timestamp' => __('Transaction Date', 'event_espresso'), |
67 | 67 | 'TXN_total' => __('Total', 'event_espresso'), |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | { |
97 | 97 | $class = parent::_get_row_class($item); |
98 | 98 | //add status class |
99 | - $class .= ' ee-status-strip txn-status-' . $item->status_ID(); |
|
99 | + $class .= ' ee-status-strip txn-status-'.$item->status_ID(); |
|
100 | 100 | if ($this->_has_checkbox_column) { |
101 | 101 | $class .= ' has-checkbox-column'; |
102 | 102 | } |
@@ -159,11 +159,11 @@ discard block |
||
159 | 159 | 'action' => 'view_transaction', |
160 | 160 | 'TXN_ID' => $item->ID(), |
161 | 161 | ), TXN_ADMIN_URL); |
162 | - $content = '<a href="' . $view_lnk_url . '" title="' . esc_attr__('Go to Transaction Details', |
|
163 | - 'event_espresso') . '">' . $item->ID() . '</a>'; |
|
162 | + $content = '<a href="'.$view_lnk_url.'" title="'.esc_attr__('Go to Transaction Details', |
|
163 | + 'event_espresso').'">'.$item->ID().'</a>'; |
|
164 | 164 | |
165 | 165 | //txn timestamp |
166 | - $content .= ' <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($item) . '</span>'; |
|
166 | + $content .= ' <span class="show-on-mobile-view-only">'.$this->_get_txn_timestamp($item).'</span>'; |
|
167 | 167 | return $content; |
168 | 168 | } |
169 | 169 | |
@@ -218,11 +218,11 @@ discard block |
||
218 | 218 | 'action' => 'view_transaction', |
219 | 219 | 'TXN_ID' => $item->ID(), |
220 | 220 | ), TXN_ADMIN_URL); |
221 | - $txn_date = '<a href="' . $view_lnk_url . '" title="' . esc_attr__('View Transaction Details for TXN #', |
|
222 | - 'event_espresso') . $item->ID() . '">' . $this->_get_txn_timestamp($item) . '</a>'; |
|
221 | + $txn_date = '<a href="'.$view_lnk_url.'" title="'.esc_attr__('View Transaction Details for TXN #', |
|
222 | + 'event_espresso').$item->ID().'">'.$this->_get_txn_timestamp($item).'</a>'; |
|
223 | 223 | //status |
224 | - $txn_date .= '<br><span class="ee-status-text-small">' . EEH_Template::pretty_status($item->status_ID(), false, |
|
225 | - 'sentence') . '</span>'; |
|
224 | + $txn_date .= '<br><span class="ee-status-text-small">'.EEH_Template::pretty_status($item->status_ID(), false, |
|
225 | + 'sentence').'</span>'; |
|
226 | 226 | return $txn_date; |
227 | 227 | } |
228 | 228 | |
@@ -237,10 +237,10 @@ discard block |
||
237 | 237 | public function column_TXN_total(EE_Transaction $item) |
238 | 238 | { |
239 | 239 | if ($item->get('TXN_total') > 0) { |
240 | - return '<span class="txn-pad-rght">' . apply_filters('FHEE__EE_Admin_Transactions_List_Table__column_TXN_total__TXN_total', |
|
241 | - $item->get_pretty('TXN_total'), $item) . '</span>'; |
|
240 | + return '<span class="txn-pad-rght">'.apply_filters('FHEE__EE_Admin_Transactions_List_Table__column_TXN_total__TXN_total', |
|
241 | + $item->get_pretty('TXN_total'), $item).'</span>'; |
|
242 | 242 | } else { |
243 | - return '<span class="txn-overview-free-event-spn">' . __('free', 'event_espresso') . '</span>'; |
|
243 | + return '<span class="txn-overview-free-event-spn">'.__('free', 'event_espresso').'</span>'; |
|
244 | 244 | } |
245 | 245 | } |
246 | 246 | |
@@ -276,10 +276,10 @@ discard block |
||
276 | 276 | $payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name() : __('Unknown', |
277 | 277 | 'event_espresso'); |
278 | 278 | |
279 | - $content = '<span class="' . $span_class . ' txn-pad-rght">' . $transaction_paid !== 0 ? $item->get_pretty('TXN_paid') : $transaction_paid . '</span>'; |
|
279 | + $content = '<span class="'.$span_class.' txn-pad-rght">'.$transaction_paid !== 0 ? $item->get_pretty('TXN_paid') : $transaction_paid.'</span>'; |
|
280 | 280 | if ($transaction_paid > 0) { |
281 | - $content .= '<br><span class="ee-status-text-small">' . sprintf(__('...via %s', 'event_espresso'), |
|
282 | - $payment_method_name) . '</span>'; |
|
281 | + $content .= '<br><span class="ee-status-text-small">'.sprintf(__('...via %s', 'event_espresso'), |
|
282 | + $payment_method_name).'</span>'; |
|
283 | 283 | } |
284 | 284 | return $content; |
285 | 285 | } |
@@ -301,11 +301,11 @@ discard block |
||
301 | 301 | 'action' => 'view_registration', |
302 | 302 | '_REG_ID' => $primary_reg->ID(), |
303 | 303 | ), REG_ADMIN_URL); |
304 | - $content = EE_Registry::instance()->CAP->current_user_can('ee_read_registration', |
|
304 | + $content = EE_Registry::instance()->CAP->current_user_can('ee_read_registration', |
|
305 | 305 | 'espresso_registrations_view_registration', |
306 | - $primary_reg->ID()) ? '<a href="' . $edit_lnk_url . '" title="' . esc_attr__('View Registration Details', |
|
307 | - 'event_espresso') . '">' . $attendee->full_name() . '</a>' : $attendee->full_name(); |
|
308 | - $content .= '<br>' . $attendee->email(); |
|
306 | + $primary_reg->ID()) ? '<a href="'.$edit_lnk_url.'" title="'.esc_attr__('View Registration Details', |
|
307 | + 'event_espresso').'">'.$attendee->full_name().'</a>' : $attendee->full_name(); |
|
308 | + $content .= '<br>'.$attendee->email(); |
|
309 | 309 | return $content; |
310 | 310 | } |
311 | 311 | return $item->failed() || $item->is_abandoned() ? __('no contact record.', |
@@ -324,8 +324,8 @@ discard block |
||
324 | 324 | public function column_ATT_email(EE_Transaction $item) |
325 | 325 | { |
326 | 326 | $attendee = $item->primary_registration()->get_first_related('Attendee'); |
327 | - if (! empty($attendee)) { |
|
328 | - return '<a href="mailto:' . $attendee->get('ATT_email') . '">' . $attendee->get('ATT_email') . '</a>'; |
|
327 | + if ( ! empty($attendee)) { |
|
328 | + return '<a href="mailto:'.$attendee->get('ATT_email').'">'.$attendee->get('ATT_email').'</a>'; |
|
329 | 329 | } else { |
330 | 330 | return $item->failed() || $item->is_abandoned() |
331 | 331 | ? __('no contact record.', 'event_espresso') |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | { |
349 | 349 | $actions = array(); |
350 | 350 | $event = $item->primary_registration()->get_first_related('Event'); |
351 | - if (! empty($event)) { |
|
351 | + if ( ! empty($event)) { |
|
352 | 352 | $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $event->ID()), |
353 | 353 | EVENTS_ADMIN_URL); |
354 | 354 | $event_name = $event->get('EVT_name'); |
@@ -359,15 +359,15 @@ discard block |
||
359 | 359 | 'EVT_ID' => $event->ID(), |
360 | 360 | )); |
361 | 361 | if (EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'espresso_events_edit', $event->ID())) { |
362 | - $actions['filter_by_event'] = '<a href="' . $txn_by_event_lnk . '" title="' . esc_attr__('Filter transactions by this event', |
|
363 | - 'event_espresso') . '">' . __('View Transactions for this event', 'event_espresso') . '</a>'; |
|
362 | + $actions['filter_by_event'] = '<a href="'.$txn_by_event_lnk.'" title="'.esc_attr__('Filter transactions by this event', |
|
363 | + 'event_espresso').'">'.__('View Transactions for this event', 'event_espresso').'</a>'; |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | return sprintf('%1$s %2$s', |
367 | 367 | EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'espresso_events_edit', |
368 | - $event->ID()) ? '<a href="' . $edit_event_url . '" title="' . sprintf(esc_attr__('Edit Event: %s', |
|
369 | - 'event_espresso'), $event->get('EVT_name')) . '">' . wp_trim_words($event_name, 30, |
|
370 | - '...') . '</a>' : wp_trim_words($event_name, 30, '...'), $this->row_actions($actions)); |
|
368 | + $event->ID()) ? '<a href="'.$edit_event_url.'" title="'.sprintf(esc_attr__('Edit Event: %s', |
|
369 | + 'event_espresso'), $event->get('EVT_name')).'">'.wp_trim_words($event_name, 30, |
|
370 | + '...').'</a>' : wp_trim_words($event_name, 30, '...'), $this->row_actions($actions)); |
|
371 | 371 | } else { |
372 | 372 | return __('The event associated with this transaction via the primary registration cannot be retrieved.', |
373 | 373 | 'event_espresso'); |
@@ -389,7 +389,7 @@ discard block |
||
389 | 389 | $attendee = $registration->attendee(); |
390 | 390 | |
391 | 391 | //Build row actions |
392 | - $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
392 | + $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
393 | 393 | 'action' => 'view_transaction', |
394 | 394 | 'TXN_ID' => $item->ID(), |
395 | 395 | ), TXN_ADMIN_URL); |
@@ -399,7 +399,7 @@ discard block |
||
399 | 399 | 'action' => 'view_registration', |
400 | 400 | '_REG_ID' => $registration->ID(), |
401 | 401 | ), REG_ADMIN_URL); |
402 | - $send_pay_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
402 | + $send_pay_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
403 | 403 | 'action' => 'send_payment_reminder', |
404 | 404 | 'TXN_ID' => $item->ID(), |
405 | 405 | ), TXN_ADMIN_URL); |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | //Build row actions |
411 | 411 | $view_lnk = ' |
412 | 412 | <li> |
413 | - <a href="' . $view_lnk_url . '" title="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="tiny-text"> |
|
413 | + <a href="' . $view_lnk_url.'" title="'.esc_attr__('View Transaction Details', 'event_espresso').'" class="tiny-text"> |
|
414 | 414 | <span class="dashicons dashicons-cart"></span> |
415 | 415 | </a> |
416 | 416 | </li>'; |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | $dl_invoice_lnk = ' |
422 | 422 | <li> |
423 | 423 | <a title="' . esc_attr__('View Transaction Invoice', |
424 | - 'event_espresso') . '" target="_blank" href="' . $dl_invoice_lnk_url . '" class="tiny-text"> |
|
424 | + 'event_espresso').'" target="_blank" href="'.$dl_invoice_lnk_url.'" class="tiny-text"> |
|
425 | 425 | <span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span> |
426 | 426 | </a> |
427 | 427 | </li>'; |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | $dl_receipt_lnk = ' |
434 | 434 | <li> |
435 | 435 | <a title="' . esc_attr__('View Transaction Receipt', |
436 | - 'event_espresso') . '" target="_blank" href="' . $dl_receipt_lnk_url . '" class="tiny-text"> |
|
436 | + 'event_espresso').'" target="_blank" href="'.$dl_receipt_lnk_url.'" class="tiny-text"> |
|
437 | 437 | <span class="dashicons dashicons-media-default ee-icon-size-18"></span> |
438 | 438 | </a> |
439 | 439 | </li>'; |
@@ -448,8 +448,8 @@ discard block |
||
448 | 448 | ) |
449 | 449 | ? ' |
450 | 450 | <li> |
451 | - <a href="' . $send_pay_lnk_url . '" title="' . esc_attr__('Send Payment Reminder', |
|
452 | - 'event_espresso') . '" class="tiny-text"> |
|
451 | + <a href="' . $send_pay_lnk_url.'" title="'.esc_attr__('Send Payment Reminder', |
|
452 | + 'event_espresso').'" class="tiny-text"> |
|
453 | 453 | <span class="dashicons dashicons-email-alt"></span> |
454 | 454 | </a> |
455 | 455 | </li>' |
@@ -469,8 +469,8 @@ discard block |
||
469 | 469 | ) |
470 | 470 | ? ' |
471 | 471 | <li> |
472 | - <a href="' . $view_reg_lnk_url . '" title="' . esc_attr__('View Registration Details', |
|
473 | - 'event_espresso') . '" class="tiny-text"> |
|
472 | + <a href="' . $view_reg_lnk_url.'" title="'.esc_attr__('View Registration Details', |
|
473 | + 'event_espresso').'" class="tiny-text"> |
|
474 | 474 | <span class="dashicons dashicons-clipboard"></span> |
475 | 475 | </a> |
476 | 476 | </li>' |
@@ -478,10 +478,10 @@ discard block |
||
478 | 478 | |
479 | 479 | $view_related_messages_lnk = ''; |
480 | 480 | if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
481 | - $view_related_messages_lnk = '<li>' . $related_messages_link . '</li>'; |
|
481 | + $view_related_messages_lnk = '<li>'.$related_messages_link.'</li>'; |
|
482 | 482 | } |
483 | 483 | |
484 | - return $this->_action_string($view_lnk . $dl_invoice_lnk . $dl_receipt_lnk . $view_reg_lnk . $send_pay_lnk . $view_related_messages_lnk, |
|
484 | + return $this->_action_string($view_lnk.$dl_invoice_lnk.$dl_receipt_lnk.$view_reg_lnk.$send_pay_lnk.$view_related_messages_lnk, |
|
485 | 485 | $item, 'ul', 'txn-overview-actions-ul'); |
486 | 486 | } |
487 | 487 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('ABSPATH')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /* |
5 | 5 | Plugin Name: Event Espresso |
@@ -40,243 +40,243 @@ discard block |
||
40 | 40 | * @since 4.0 |
41 | 41 | */ |
42 | 42 | if (function_exists('espresso_version')) { |
43 | - /** |
|
44 | - * espresso_duplicate_plugin_error |
|
45 | - * displays if more than one version of EE is activated at the same time |
|
46 | - */ |
|
47 | - function espresso_duplicate_plugin_error() |
|
48 | - { |
|
49 | - ?> |
|
43 | + /** |
|
44 | + * espresso_duplicate_plugin_error |
|
45 | + * displays if more than one version of EE is activated at the same time |
|
46 | + */ |
|
47 | + function espresso_duplicate_plugin_error() |
|
48 | + { |
|
49 | + ?> |
|
50 | 50 | <div class="error"> |
51 | 51 | <p> |
52 | 52 | <?php echo esc_html__( |
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | 61 | |
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | - if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - /** |
|
97 | - * espresso_version |
|
98 | - * Returns the plugin version |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - function espresso_version() |
|
103 | - { |
|
104 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.43.rc.005'); |
|
105 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + /** |
|
97 | + * espresso_version |
|
98 | + * Returns the plugin version |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + function espresso_version() |
|
103 | + { |
|
104 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.43.rc.005'); |
|
105 | + } |
|
106 | 106 | |
107 | - // define versions |
|
108 | - define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | - define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | - define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | - define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | - //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | - if ( ! defined('DS')) { |
|
115 | - define('DS', '/'); |
|
116 | - } |
|
117 | - if ( ! defined('PS')) { |
|
118 | - define('PS', PATH_SEPARATOR); |
|
119 | - } |
|
120 | - if ( ! defined('SP')) { |
|
121 | - define('SP', ' '); |
|
122 | - } |
|
123 | - if ( ! defined('EENL')) { |
|
124 | - define('EENL', "\n"); |
|
125 | - } |
|
126 | - define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | - // define the plugin directory and URL |
|
128 | - define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | - define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | - define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | - // main root folder paths |
|
132 | - define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | - define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | - define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | - define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | - define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | - define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | - define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | - define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | - // core system paths |
|
141 | - define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | - define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | - define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | - define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | - define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | - define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | - define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | - define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | - define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | - define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | - define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | - define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | - // gateways |
|
154 | - define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | - define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | - // asset URL paths |
|
157 | - define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | - define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | - define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | - define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | - define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | - define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | - // define upload paths |
|
164 | - $uploads = wp_upload_dir(); |
|
165 | - // define the uploads directory and URL |
|
166 | - define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | - define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | - // define the templates directory and URL |
|
169 | - define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | - define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | - // define the gateway directory and URL |
|
172 | - define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | - define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | - // languages folder/path |
|
175 | - define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | - define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | - //check for dompdf fonts in uploads |
|
178 | - if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | - } |
|
181 | - //ajax constants |
|
182 | - define( |
|
183 | - 'EE_FRONT_AJAX', |
|
184 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | - ); |
|
186 | - define( |
|
187 | - 'EE_ADMIN_AJAX', |
|
188 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | - ); |
|
190 | - //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | - //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | - //want to change its default value! or find when -1 means infinity |
|
193 | - define('EE_INF_IN_DB', -1); |
|
194 | - define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | - define('EE_DEBUG', false); |
|
196 | - // for older WP versions |
|
197 | - if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | - define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | - } |
|
200 | - /** |
|
201 | - * espresso_plugin_activation |
|
202 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | - */ |
|
204 | - function espresso_plugin_activation() |
|
205 | - { |
|
206 | - update_option('ee_espresso_activation', true); |
|
207 | - } |
|
107 | + // define versions |
|
108 | + define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | + define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | + define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | + define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | + //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | + if ( ! defined('DS')) { |
|
115 | + define('DS', '/'); |
|
116 | + } |
|
117 | + if ( ! defined('PS')) { |
|
118 | + define('PS', PATH_SEPARATOR); |
|
119 | + } |
|
120 | + if ( ! defined('SP')) { |
|
121 | + define('SP', ' '); |
|
122 | + } |
|
123 | + if ( ! defined('EENL')) { |
|
124 | + define('EENL', "\n"); |
|
125 | + } |
|
126 | + define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | + // define the plugin directory and URL |
|
128 | + define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | + define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | + define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | + // main root folder paths |
|
132 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | + define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | + // core system paths |
|
141 | + define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | + define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | + define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | + define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | + define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | + define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | + define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | + define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | + define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | + define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | + define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | + // gateways |
|
154 | + define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | + // asset URL paths |
|
157 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | + // define upload paths |
|
164 | + $uploads = wp_upload_dir(); |
|
165 | + // define the uploads directory and URL |
|
166 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | + // define the templates directory and URL |
|
169 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | + // define the gateway directory and URL |
|
172 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | + // languages folder/path |
|
175 | + define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | + //check for dompdf fonts in uploads |
|
178 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | + } |
|
181 | + //ajax constants |
|
182 | + define( |
|
183 | + 'EE_FRONT_AJAX', |
|
184 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | + ); |
|
186 | + define( |
|
187 | + 'EE_ADMIN_AJAX', |
|
188 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | + ); |
|
190 | + //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | + //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | + //want to change its default value! or find when -1 means infinity |
|
193 | + define('EE_INF_IN_DB', -1); |
|
194 | + define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | + define('EE_DEBUG', false); |
|
196 | + // for older WP versions |
|
197 | + if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | + define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | + } |
|
200 | + /** |
|
201 | + * espresso_plugin_activation |
|
202 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | + */ |
|
204 | + function espresso_plugin_activation() |
|
205 | + { |
|
206 | + update_option('ee_espresso_activation', true); |
|
207 | + } |
|
208 | 208 | |
209 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | - /** |
|
211 | - * espresso_load_error_handling |
|
212 | - * this function loads EE's class for handling exceptions and errors |
|
213 | - */ |
|
214 | - function espresso_load_error_handling() |
|
215 | - { |
|
216 | - // load debugging tools |
|
217 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | - require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | - EEH_Debug_Tools::instance(); |
|
220 | - } |
|
221 | - // load error handling |
|
222 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | - require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | - } else { |
|
225 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | - } |
|
227 | - } |
|
209 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | + /** |
|
211 | + * espresso_load_error_handling |
|
212 | + * this function loads EE's class for handling exceptions and errors |
|
213 | + */ |
|
214 | + function espresso_load_error_handling() |
|
215 | + { |
|
216 | + // load debugging tools |
|
217 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | + require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | + EEH_Debug_Tools::instance(); |
|
220 | + } |
|
221 | + // load error handling |
|
222 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | + require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | + } else { |
|
225 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | + } |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * espresso_load_required |
|
231 | - * given a class name and path, this function will load that file or throw an exception |
|
232 | - * |
|
233 | - * @param string $classname |
|
234 | - * @param string $full_path_to_file |
|
235 | - * @throws EE_Error |
|
236 | - */ |
|
237 | - function espresso_load_required($classname, $full_path_to_file) |
|
238 | - { |
|
239 | - static $error_handling_loaded = false; |
|
240 | - if ( ! $error_handling_loaded) { |
|
241 | - espresso_load_error_handling(); |
|
242 | - $error_handling_loaded = true; |
|
243 | - } |
|
244 | - if (is_readable($full_path_to_file)) { |
|
245 | - require_once($full_path_to_file); |
|
246 | - } else { |
|
247 | - throw new EE_Error ( |
|
248 | - sprintf( |
|
249 | - esc_html__( |
|
250 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | - 'event_espresso' |
|
252 | - ), |
|
253 | - $classname |
|
254 | - ) |
|
255 | - ); |
|
256 | - } |
|
257 | - } |
|
229 | + /** |
|
230 | + * espresso_load_required |
|
231 | + * given a class name and path, this function will load that file or throw an exception |
|
232 | + * |
|
233 | + * @param string $classname |
|
234 | + * @param string $full_path_to_file |
|
235 | + * @throws EE_Error |
|
236 | + */ |
|
237 | + function espresso_load_required($classname, $full_path_to_file) |
|
238 | + { |
|
239 | + static $error_handling_loaded = false; |
|
240 | + if ( ! $error_handling_loaded) { |
|
241 | + espresso_load_error_handling(); |
|
242 | + $error_handling_loaded = true; |
|
243 | + } |
|
244 | + if (is_readable($full_path_to_file)) { |
|
245 | + require_once($full_path_to_file); |
|
246 | + } else { |
|
247 | + throw new EE_Error ( |
|
248 | + sprintf( |
|
249 | + esc_html__( |
|
250 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | + 'event_espresso' |
|
252 | + ), |
|
253 | + $classname |
|
254 | + ) |
|
255 | + ); |
|
256 | + } |
|
257 | + } |
|
258 | 258 | |
259 | - espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | - espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | - espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | - new EE_Bootstrap(); |
|
263 | - } |
|
259 | + espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | + espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | + espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | + new EE_Bootstrap(); |
|
263 | + } |
|
264 | 264 | } |
265 | 265 | if ( ! function_exists('espresso_deactivate_plugin')) { |
266 | - /** |
|
267 | - * deactivate_plugin |
|
268 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | - * |
|
270 | - * @access public |
|
271 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | - * @return void |
|
273 | - */ |
|
274 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | - { |
|
276 | - if ( ! function_exists('deactivate_plugins')) { |
|
277 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | - } |
|
279 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | - deactivate_plugins($plugin_basename); |
|
281 | - } |
|
266 | + /** |
|
267 | + * deactivate_plugin |
|
268 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | + * |
|
270 | + * @access public |
|
271 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | + * @return void |
|
273 | + */ |
|
274 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | + { |
|
276 | + if ( ! function_exists('deactivate_plugins')) { |
|
277 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | + } |
|
279 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | + deactivate_plugins($plugin_basename); |
|
281 | + } |
|
282 | 282 | } |
283 | 283 | \ No newline at end of file |
@@ -293,13 +293,13 @@ discard block |
||
293 | 293 | */ |
294 | 294 | public static function localize_i18n_js_strings() |
295 | 295 | { |
296 | - $i18n_js_strings = (array)EE_Registry::$i18n_js_strings; |
|
296 | + $i18n_js_strings = (array) EE_Registry::$i18n_js_strings; |
|
297 | 297 | foreach ($i18n_js_strings as $key => $value) { |
298 | 298 | if (is_scalar($value)) { |
299 | - $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
299 | + $i18n_js_strings[$key] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8'); |
|
300 | 300 | } |
301 | 301 | } |
302 | - return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
302 | + return "/* <![CDATA[ */ var eei18n = ".wp_json_encode($i18n_js_strings).'; /* ]]> */'; |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | |
@@ -350,9 +350,9 @@ discard block |
||
350 | 350 | EE_CORE, |
351 | 351 | EE_ADMIN, |
352 | 352 | EE_CPTS, |
353 | - EE_CORE . 'data_migration_scripts' . DS, |
|
354 | - EE_CORE . 'request_stack' . DS, |
|
355 | - EE_CORE . 'middleware' . DS, |
|
353 | + EE_CORE.'data_migration_scripts'.DS, |
|
354 | + EE_CORE.'request_stack'.DS, |
|
355 | + EE_CORE.'middleware'.DS, |
|
356 | 356 | ) |
357 | 357 | ); |
358 | 358 | // retrieve instantiated class |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | $service_paths = apply_filters( |
376 | 376 | 'FHEE__EE_Registry__load_service__service_paths', |
377 | 377 | array( |
378 | - EE_CORE . 'services' . DS, |
|
378 | + EE_CORE.'services'.DS, |
|
379 | 379 | ) |
380 | 380 | ); |
381 | 381 | // retrieve instantiated class |
@@ -455,10 +455,10 @@ discard block |
||
455 | 455 | { |
456 | 456 | $paths = array( |
457 | 457 | EE_LIBRARIES, |
458 | - EE_LIBRARIES . 'messages' . DS, |
|
459 | - EE_LIBRARIES . 'shortcodes' . DS, |
|
460 | - EE_LIBRARIES . 'qtips' . DS, |
|
461 | - EE_LIBRARIES . 'payment_methods' . DS, |
|
458 | + EE_LIBRARIES.'messages'.DS, |
|
459 | + EE_LIBRARIES.'shortcodes'.DS, |
|
460 | + EE_LIBRARIES.'qtips'.DS, |
|
461 | + EE_LIBRARIES.'payment_methods'.DS, |
|
462 | 462 | ); |
463 | 463 | // retrieve instantiated class |
464 | 464 | return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only); |
@@ -497,10 +497,10 @@ discard block |
||
497 | 497 | public function load_model_class($class_name, $arguments = array(), $load_only = true) |
498 | 498 | { |
499 | 499 | $paths = array( |
500 | - EE_MODELS . 'fields' . DS, |
|
501 | - EE_MODELS . 'helpers' . DS, |
|
502 | - EE_MODELS . 'relations' . DS, |
|
503 | - EE_MODELS . 'strategies' . DS, |
|
500 | + EE_MODELS.'fields'.DS, |
|
501 | + EE_MODELS.'helpers'.DS, |
|
502 | + EE_MODELS.'relations'.DS, |
|
503 | + EE_MODELS.'strategies'.DS, |
|
504 | 504 | ); |
505 | 505 | // retrieve instantiated class |
506 | 506 | return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only); |
@@ -589,7 +589,7 @@ discard block |
||
589 | 589 | $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments); |
590 | 590 | // if a non-FQCN was passed, then verifyClassExists() might return an object |
591 | 591 | // or it could return null if the class just could not be found anywhere |
592 | - if ($class_exists instanceof $class_name || $class_exists === null){ |
|
592 | + if ($class_exists instanceof $class_name || $class_exists === null) { |
|
593 | 593 | // either way, return the results |
594 | 594 | return $class_exists; |
595 | 595 | } |
@@ -612,7 +612,7 @@ discard block |
||
612 | 612 | // instantiate the requested object |
613 | 613 | $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
614 | 614 | // if caching is turned on OR this class is cached in a class property |
615 | - if (($this->_cache_on && $cache) || isset($this->_class_abbreviations[ $class_name ])) { |
|
615 | + if (($this->_cache_on && $cache) || isset($this->_class_abbreviations[$class_name])) { |
|
616 | 616 | // save it for later... kinda like gum { : $ |
617 | 617 | $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
618 | 618 | } |
@@ -638,7 +638,7 @@ discard block |
||
638 | 638 | case 1: |
639 | 639 | // if it's a FQCN then maybe the class is registered with a preceding \ |
640 | 640 | $class_name = strpos($class_name, '\\') !== false |
641 | - ? '\\' . ltrim($class_name, '\\') |
|
641 | + ? '\\'.ltrim($class_name, '\\') |
|
642 | 642 | : $class_name; |
643 | 643 | break; |
644 | 644 | case 2: |
@@ -693,7 +693,7 @@ discard block |
||
693 | 693 | // make sure $class_prefix is uppercase |
694 | 694 | $class_prefix = strtoupper(trim($class_prefix)); |
695 | 695 | // add class prefix ONCE!!! |
696 | - $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
696 | + $class_name = $class_prefix.str_replace($class_prefix, '', $class_name); |
|
697 | 697 | } |
698 | 698 | $class_name = $this->_dependency_map->get_alias($class_name); |
699 | 699 | $class_exists = class_exists($class_name); |
@@ -753,8 +753,8 @@ discard block |
||
753 | 753 | protected function _get_cached_class($class_name, $class_prefix = '') |
754 | 754 | { |
755 | 755 | // have to specify something, but not anything that will conflict |
756 | - $class_abbreviation = isset($this->_class_abbreviations[ $class_name ]) |
|
757 | - ? $this->_class_abbreviations[ $class_name ] |
|
756 | + $class_abbreviation = isset($this->_class_abbreviations[$class_name]) |
|
757 | + ? $this->_class_abbreviations[$class_name] |
|
758 | 758 | : 'FANCY_BATMAN_PANTS'; |
759 | 759 | $class_name = str_replace('\\', '_', $class_name); |
760 | 760 | // check if class has already been loaded, and return it if it has been |
@@ -785,8 +785,8 @@ discard block |
||
785 | 785 | public function clear_cached_class($class_name, $addon = false) |
786 | 786 | { |
787 | 787 | // have to specify something, but not anything that will conflict |
788 | - $class_abbreviation = isset($this->_class_abbreviations[ $class_name ]) |
|
789 | - ? $this->_class_abbreviations[ $class_name ] |
|
788 | + $class_abbreviation = isset($this->_class_abbreviations[$class_name]) |
|
789 | + ? $this->_class_abbreviations[$class_name] |
|
790 | 790 | : 'FANCY_BATMAN_PANTS'; |
791 | 791 | $class_name = str_replace('\\', '_', $class_name); |
792 | 792 | // check if class has already been loaded, and return it if it has been |
@@ -831,9 +831,9 @@ discard block |
||
831 | 831 | // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
832 | 832 | $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES; |
833 | 833 | // prep file type |
834 | - $type = ! empty($type) ? trim($type, '.') . '.' : ''; |
|
834 | + $type = ! empty($type) ? trim($type, '.').'.' : ''; |
|
835 | 835 | // build full file path |
836 | - $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
836 | + $file_paths[$key] = rtrim($file_path, DS).DS.$class_name.'.'.$type.'php'; |
|
837 | 837 | //does the file exist and can be read ? |
838 | 838 | if (is_readable($file_paths[$key])) { |
839 | 839 | return $file_paths[$key]; |
@@ -864,12 +864,12 @@ discard block |
||
864 | 864 | //does the file exist and can it be read ? |
865 | 865 | if ( ! $path) { |
866 | 866 | // so sorry, can't find the file |
867 | - throw new EE_Error ( |
|
867 | + throw new EE_Error( |
|
868 | 868 | sprintf( |
869 | 869 | __('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso'), |
870 | 870 | trim($type, '.'), |
871 | 871 | $class_name, |
872 | - '<br />' . implode(',<br />', $file_paths) |
|
872 | + '<br />'.implode(',<br />', $file_paths) |
|
873 | 873 | ) |
874 | 874 | ); |
875 | 875 | } |
@@ -16,1465 +16,1465 @@ |
||
16 | 16 | class EE_Registry |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * EE_Registry Object |
|
21 | - * |
|
22 | - * @var EE_Registry $_instance |
|
23 | - * @access private |
|
24 | - */ |
|
25 | - private static $_instance = null; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var EE_Dependency_Map $_dependency_map |
|
29 | - * @access protected |
|
30 | - */ |
|
31 | - protected $_dependency_map = null; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var array $_class_abbreviations |
|
35 | - * @access protected |
|
36 | - */ |
|
37 | - protected $_class_abbreviations = array(); |
|
38 | - |
|
39 | - /** |
|
40 | - * @access public |
|
41 | - * @var \EventEspresso\core\services\commands\CommandBusInterface $BUS |
|
42 | - */ |
|
43 | - public $BUS; |
|
44 | - |
|
45 | - /** |
|
46 | - * EE_Cart Object |
|
47 | - * |
|
48 | - * @access public |
|
49 | - * @var EE_Cart $CART |
|
50 | - */ |
|
51 | - public $CART = null; |
|
52 | - |
|
53 | - /** |
|
54 | - * EE_Config Object |
|
55 | - * |
|
56 | - * @access public |
|
57 | - * @var EE_Config $CFG |
|
58 | - */ |
|
59 | - public $CFG = null; |
|
60 | - |
|
61 | - /** |
|
62 | - * EE_Network_Config Object |
|
63 | - * |
|
64 | - * @access public |
|
65 | - * @var EE_Network_Config $NET_CFG |
|
66 | - */ |
|
67 | - public $NET_CFG = null; |
|
68 | - |
|
69 | - /** |
|
70 | - * StdClass object for storing library classes in |
|
71 | - * |
|
72 | - * @public LIB |
|
73 | - * @var StdClass $LIB |
|
74 | - */ |
|
75 | - public $LIB = null; |
|
76 | - |
|
77 | - /** |
|
78 | - * EE_Request_Handler Object |
|
79 | - * |
|
80 | - * @access public |
|
81 | - * @var EE_Request_Handler $REQ |
|
82 | - */ |
|
83 | - public $REQ = null; |
|
84 | - |
|
85 | - /** |
|
86 | - * EE_Session Object |
|
87 | - * |
|
88 | - * @access public |
|
89 | - * @var EE_Session $SSN |
|
90 | - */ |
|
91 | - public $SSN = null; |
|
92 | - |
|
93 | - /** |
|
94 | - * holds the ee capabilities object. |
|
95 | - * |
|
96 | - * @since 4.5.0 |
|
97 | - * @var EE_Capabilities |
|
98 | - */ |
|
99 | - public $CAP = null; |
|
100 | - |
|
101 | - /** |
|
102 | - * holds the EE_Message_Resource_Manager object. |
|
103 | - * |
|
104 | - * @since 4.9.0 |
|
105 | - * @var EE_Message_Resource_Manager |
|
106 | - */ |
|
107 | - public $MRM = null; |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * Holds the Assets Registry instance |
|
112 | - * @var Registry |
|
113 | - */ |
|
114 | - public $AssetsRegistry = null; |
|
115 | - |
|
116 | - /** |
|
117 | - * $addons - StdClass object for holding addons which have registered themselves to work with EE core |
|
118 | - * |
|
119 | - * @access public |
|
120 | - * @var EE_Addon[] |
|
121 | - */ |
|
122 | - public $addons = null; |
|
123 | - |
|
124 | - /** |
|
125 | - * $models |
|
126 | - * @access public |
|
127 | - * @var EEM_Base[] $models keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
128 | - */ |
|
129 | - public $models = array(); |
|
130 | - |
|
131 | - /** |
|
132 | - * $modules |
|
133 | - * @access public |
|
134 | - * @var EED_Module[] $modules |
|
135 | - */ |
|
136 | - public $modules = null; |
|
137 | - |
|
138 | - /** |
|
139 | - * $shortcodes |
|
140 | - * @access public |
|
141 | - * @var EES_Shortcode[] $shortcodes |
|
142 | - */ |
|
143 | - public $shortcodes = null; |
|
144 | - |
|
145 | - /** |
|
146 | - * $widgets |
|
147 | - * @access public |
|
148 | - * @var WP_Widget[] $widgets |
|
149 | - */ |
|
150 | - public $widgets = null; |
|
151 | - |
|
152 | - /** |
|
153 | - * $non_abstract_db_models |
|
154 | - * @access public |
|
155 | - * @var array this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
156 | - * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
157 | - * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
158 | - * classnames (eg "EEM_Event") |
|
159 | - */ |
|
160 | - public $non_abstract_db_models = array(); |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * $i18n_js_strings - internationalization for JS strings |
|
165 | - * usage: EE_Registry::i18n_js_strings['string_key'] = __( 'string to translate.', 'event_espresso' ); |
|
166 | - * in js file: var translatedString = eei18n.string_key; |
|
167 | - * |
|
168 | - * @access public |
|
169 | - * @var array |
|
170 | - */ |
|
171 | - public static $i18n_js_strings = array(); |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * $main_file - path to espresso.php |
|
176 | - * |
|
177 | - * @access public |
|
178 | - * @var array |
|
179 | - */ |
|
180 | - public $main_file; |
|
181 | - |
|
182 | - /** |
|
183 | - * array of ReflectionClass objects where the key is the class name |
|
184 | - * |
|
185 | - * @access public |
|
186 | - * @var ReflectionClass[] |
|
187 | - */ |
|
188 | - public $_reflectors; |
|
189 | - |
|
190 | - /** |
|
191 | - * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
192 | - * |
|
193 | - * @access protected |
|
194 | - * @var boolean $_cache_on |
|
195 | - */ |
|
196 | - protected $_cache_on = true; |
|
197 | - |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * @singleton method used to instantiate class object |
|
202 | - * @access public |
|
203 | - * @param \EE_Dependency_Map $dependency_map |
|
204 | - * @return \EE_Registry instance |
|
205 | - */ |
|
206 | - public static function instance(\EE_Dependency_Map $dependency_map = null) |
|
207 | - { |
|
208 | - // check if class object is instantiated |
|
209 | - if ( ! self::$_instance instanceof EE_Registry) { |
|
210 | - self::$_instance = new EE_Registry($dependency_map); |
|
211 | - } |
|
212 | - return self::$_instance; |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - *protected constructor to prevent direct creation |
|
219 | - * |
|
220 | - * @Constructor |
|
221 | - * @access protected |
|
222 | - * @param \EE_Dependency_Map $dependency_map |
|
223 | - */ |
|
224 | - protected function __construct(\EE_Dependency_Map $dependency_map) |
|
225 | - { |
|
226 | - $this->_dependency_map = $dependency_map; |
|
227 | - $this->LIB = new stdClass(); |
|
228 | - $this->addons = new stdClass(); |
|
229 | - $this->modules = new stdClass(); |
|
230 | - $this->shortcodes = new stdClass(); |
|
231 | - $this->widgets = new stdClass(); |
|
232 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - |
|
237 | - /** |
|
238 | - * initialize |
|
239 | - */ |
|
240 | - public function initialize() |
|
241 | - { |
|
242 | - $this->_class_abbreviations = apply_filters( |
|
243 | - 'FHEE__EE_Registry____construct___class_abbreviations', |
|
244 | - array( |
|
245 | - 'EE_Config' => 'CFG', |
|
246 | - 'EE_Session' => 'SSN', |
|
247 | - 'EE_Capabilities' => 'CAP', |
|
248 | - 'EE_Cart' => 'CART', |
|
249 | - 'EE_Network_Config' => 'NET_CFG', |
|
250 | - 'EE_Request_Handler' => 'REQ', |
|
251 | - 'EE_Message_Resource_Manager' => 'MRM', |
|
252 | - 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
253 | - 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
|
254 | - ) |
|
255 | - ); |
|
256 | - $this->load_core('Base', array(), true); |
|
257 | - // add our request and response objects to the cache |
|
258 | - $request_loader = $this->_dependency_map->class_loader('EE_Request'); |
|
259 | - $this->_set_cached_class( |
|
260 | - $request_loader(), |
|
261 | - 'EE_Request' |
|
262 | - ); |
|
263 | - $response_loader = $this->_dependency_map->class_loader('EE_Response'); |
|
264 | - $this->_set_cached_class( |
|
265 | - $response_loader(), |
|
266 | - 'EE_Response' |
|
267 | - ); |
|
268 | - add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
269 | - } |
|
270 | - |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * init |
|
275 | - * |
|
276 | - * @access public |
|
277 | - * @return void |
|
278 | - */ |
|
279 | - public function init() |
|
280 | - { |
|
281 | - // Get current page protocol |
|
282 | - $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
283 | - // Output admin-ajax.php URL with same protocol as current page |
|
284 | - self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
285 | - self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
286 | - } |
|
287 | - |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * localize_i18n_js_strings |
|
292 | - * |
|
293 | - * @return string |
|
294 | - */ |
|
295 | - public static function localize_i18n_js_strings() |
|
296 | - { |
|
297 | - $i18n_js_strings = (array)EE_Registry::$i18n_js_strings; |
|
298 | - foreach ($i18n_js_strings as $key => $value) { |
|
299 | - if (is_scalar($value)) { |
|
300 | - $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
301 | - } |
|
302 | - } |
|
303 | - return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
304 | - } |
|
305 | - |
|
306 | - |
|
307 | - |
|
308 | - /** |
|
309 | - * @param mixed string | EED_Module $module |
|
310 | - */ |
|
311 | - public function add_module($module) |
|
312 | - { |
|
313 | - if ($module instanceof EED_Module) { |
|
314 | - $module_class = get_class($module); |
|
315 | - $this->modules->{$module_class} = $module; |
|
316 | - } else { |
|
317 | - if ( ! class_exists('EE_Module_Request_Router')) { |
|
318 | - $this->load_core('Module_Request_Router'); |
|
319 | - } |
|
320 | - $this->modules->{$module} = EE_Module_Request_Router::module_factory($module); |
|
321 | - } |
|
322 | - } |
|
323 | - |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * @param string $module_name |
|
328 | - * @return mixed EED_Module | NULL |
|
329 | - */ |
|
330 | - public function get_module($module_name = '') |
|
331 | - { |
|
332 | - return isset($this->modules->{$module_name}) ? $this->modules->{$module_name} : null; |
|
333 | - } |
|
334 | - |
|
335 | - |
|
336 | - |
|
337 | - /** |
|
338 | - * loads core classes - must be singletons |
|
339 | - * |
|
340 | - * @access public |
|
341 | - * @param string $class_name - simple class name ie: session |
|
342 | - * @param mixed $arguments |
|
343 | - * @param bool $load_only |
|
344 | - * @return mixed |
|
345 | - */ |
|
346 | - public function load_core($class_name, $arguments = array(), $load_only = false) |
|
347 | - { |
|
348 | - $core_paths = apply_filters( |
|
349 | - 'FHEE__EE_Registry__load_core__core_paths', |
|
350 | - array( |
|
351 | - EE_CORE, |
|
352 | - EE_ADMIN, |
|
353 | - EE_CPTS, |
|
354 | - EE_CORE . 'data_migration_scripts' . DS, |
|
355 | - EE_CORE . 'request_stack' . DS, |
|
356 | - EE_CORE . 'middleware' . DS, |
|
357 | - ) |
|
358 | - ); |
|
359 | - // retrieve instantiated class |
|
360 | - return $this->_load($core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only); |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - |
|
365 | - /** |
|
366 | - * loads service classes |
|
367 | - * |
|
368 | - * @access public |
|
369 | - * @param string $class_name - simple class name ie: session |
|
370 | - * @param mixed $arguments |
|
371 | - * @param bool $load_only |
|
372 | - * @return mixed |
|
373 | - */ |
|
374 | - public function load_service($class_name, $arguments = array(), $load_only = false) |
|
375 | - { |
|
376 | - $service_paths = apply_filters( |
|
377 | - 'FHEE__EE_Registry__load_service__service_paths', |
|
378 | - array( |
|
379 | - EE_CORE . 'services' . DS, |
|
380 | - ) |
|
381 | - ); |
|
382 | - // retrieve instantiated class |
|
383 | - return $this->_load($service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only); |
|
384 | - } |
|
385 | - |
|
386 | - |
|
387 | - |
|
388 | - /** |
|
389 | - * loads data_migration_scripts |
|
390 | - * |
|
391 | - * @access public |
|
392 | - * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
393 | - * @param mixed $arguments |
|
394 | - * @return EE_Data_Migration_Script_Base|mixed |
|
395 | - */ |
|
396 | - public function load_dms($class_name, $arguments = array()) |
|
397 | - { |
|
398 | - // retrieve instantiated class |
|
399 | - return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false); |
|
400 | - } |
|
401 | - |
|
402 | - |
|
403 | - |
|
404 | - /** |
|
405 | - * loads object creating classes - must be singletons |
|
406 | - * |
|
407 | - * @param string $class_name - simple class name ie: attendee |
|
408 | - * @param mixed $arguments - an array of arguments to pass to the class |
|
409 | - * @param bool $from_db - some classes are instantiated from the db and thus call a different method to instantiate |
|
410 | - * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
411 | - * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate (default) |
|
412 | - * @return EE_Base_Class | bool |
|
413 | - */ |
|
414 | - public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
415 | - { |
|
416 | - $paths = apply_filters('FHEE__EE_Registry__load_class__paths', array( |
|
417 | - EE_CORE, |
|
418 | - EE_CLASSES, |
|
419 | - EE_BUSINESS, |
|
420 | - )); |
|
421 | - // retrieve instantiated class |
|
422 | - return $this->_load($paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only); |
|
423 | - } |
|
424 | - |
|
425 | - |
|
426 | - |
|
427 | - /** |
|
428 | - * loads helper classes - must be singletons |
|
429 | - * |
|
430 | - * @param string $class_name - simple class name ie: price |
|
431 | - * @param mixed $arguments |
|
432 | - * @param bool $load_only |
|
433 | - * @return EEH_Base | bool |
|
434 | - */ |
|
435 | - public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
436 | - { |
|
437 | - // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
438 | - $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
439 | - // retrieve instantiated class |
|
440 | - return $this->_load($helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only); |
|
441 | - } |
|
442 | - |
|
443 | - |
|
444 | - |
|
445 | - /** |
|
446 | - * loads core classes - must be singletons |
|
447 | - * |
|
448 | - * @access public |
|
449 | - * @param string $class_name - simple class name ie: session |
|
450 | - * @param mixed $arguments |
|
451 | - * @param bool $load_only |
|
452 | - * @param bool $cache whether to cache the object or not. |
|
453 | - * @return mixed |
|
454 | - */ |
|
455 | - public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
456 | - { |
|
457 | - $paths = array( |
|
458 | - EE_LIBRARIES, |
|
459 | - EE_LIBRARIES . 'messages' . DS, |
|
460 | - EE_LIBRARIES . 'shortcodes' . DS, |
|
461 | - EE_LIBRARIES . 'qtips' . DS, |
|
462 | - EE_LIBRARIES . 'payment_methods' . DS, |
|
463 | - ); |
|
464 | - // retrieve instantiated class |
|
465 | - return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only); |
|
466 | - } |
|
467 | - |
|
468 | - |
|
469 | - |
|
470 | - /** |
|
471 | - * loads model classes - must be singletons |
|
472 | - * |
|
473 | - * @param string $class_name - simple class name ie: price |
|
474 | - * @param mixed $arguments |
|
475 | - * @param bool $load_only |
|
476 | - * @return EEM_Base | bool |
|
477 | - */ |
|
478 | - public function load_model($class_name, $arguments = array(), $load_only = false) |
|
479 | - { |
|
480 | - $paths = apply_filters('FHEE__EE_Registry__load_model__paths', array( |
|
481 | - EE_MODELS, |
|
482 | - EE_CORE, |
|
483 | - )); |
|
484 | - // retrieve instantiated class |
|
485 | - return $this->_load($paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only); |
|
486 | - } |
|
487 | - |
|
488 | - |
|
489 | - |
|
490 | - /** |
|
491 | - * loads model classes - must be singletons |
|
492 | - * |
|
493 | - * @param string $class_name - simple class name ie: price |
|
494 | - * @param mixed $arguments |
|
495 | - * @param bool $load_only |
|
496 | - * @return mixed | bool |
|
497 | - */ |
|
498 | - public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
499 | - { |
|
500 | - $paths = array( |
|
501 | - EE_MODELS . 'fields' . DS, |
|
502 | - EE_MODELS . 'helpers' . DS, |
|
503 | - EE_MODELS . 'relations' . DS, |
|
504 | - EE_MODELS . 'strategies' . DS, |
|
505 | - ); |
|
506 | - // retrieve instantiated class |
|
507 | - return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only); |
|
508 | - } |
|
509 | - |
|
510 | - |
|
511 | - |
|
512 | - /** |
|
513 | - * Determines if $model_name is the name of an actual EE model. |
|
514 | - * |
|
515 | - * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
516 | - * @return boolean |
|
517 | - */ |
|
518 | - public function is_model_name($model_name) |
|
519 | - { |
|
520 | - return isset($this->models[$model_name]) ? true : false; |
|
521 | - } |
|
522 | - |
|
523 | - |
|
524 | - |
|
525 | - /** |
|
526 | - * generic class loader |
|
527 | - * |
|
528 | - * @param string $path_to_file - directory path to file location, not including filename |
|
529 | - * @param string $file_name - file name ie: my_file.php, including extension |
|
530 | - * @param string $type - file type - core? class? helper? model? |
|
531 | - * @param mixed $arguments |
|
532 | - * @param bool $load_only |
|
533 | - * @return mixed |
|
534 | - */ |
|
535 | - public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
536 | - { |
|
537 | - // retrieve instantiated class |
|
538 | - return $this->_load($path_to_file, '', $file_name, $type, $arguments, false, true, $load_only); |
|
539 | - } |
|
540 | - |
|
541 | - |
|
542 | - |
|
543 | - /** |
|
544 | - * load_addon |
|
545 | - * |
|
546 | - * @param string $path_to_file - directory path to file location, not including filename |
|
547 | - * @param string $class_name - full class name ie: My_Class |
|
548 | - * @param string $type - file type - core? class? helper? model? |
|
549 | - * @param mixed $arguments |
|
550 | - * @param bool $load_only |
|
551 | - * @return EE_Addon |
|
552 | - */ |
|
553 | - public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
554 | - { |
|
555 | - // retrieve instantiated class |
|
556 | - return $this->_load($path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only); |
|
557 | - } |
|
558 | - |
|
559 | - |
|
560 | - |
|
561 | - /** |
|
562 | - * instantiates, caches, and automatically resolves dependencies |
|
563 | - * for classes that use a Fully Qualified Class Name. |
|
564 | - * if the class is not capable of being loaded using PSR-4 autoloading, |
|
565 | - * then you need to use one of the existing load_*() methods |
|
566 | - * which can resolve the classname and filepath from the passed arguments |
|
567 | - * |
|
568 | - * @param bool|string $class_name Fully Qualified Class Name |
|
569 | - * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
570 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
571 | - * @param bool $from_db some classes are instantiated from the db |
|
572 | - * and thus call a different method to instantiate |
|
573 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
574 | - * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
575 | - * @return mixed null = failure to load or instantiate class object. |
|
576 | - * object = class loaded and instantiated successfully. |
|
577 | - * bool = fail or success when $load_only is true |
|
578 | - * @throws EE_Error |
|
579 | - */ |
|
580 | - public function create( |
|
581 | - $class_name = false, |
|
582 | - $arguments = array(), |
|
583 | - $cache = false, |
|
584 | - $from_db = false, |
|
585 | - $load_only = false, |
|
586 | - $addon = false |
|
587 | - ) { |
|
588 | - $class_name = ltrim($class_name, '\\'); |
|
589 | - $class_name = $this->_dependency_map->get_alias($class_name); |
|
590 | - $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments); |
|
591 | - // if a non-FQCN was passed, then verifyClassExists() might return an object |
|
592 | - // or it could return null if the class just could not be found anywhere |
|
593 | - if ($class_exists instanceof $class_name || $class_exists === null){ |
|
594 | - // either way, return the results |
|
595 | - return $class_exists; |
|
596 | - } |
|
597 | - $class_name = $class_exists; |
|
598 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
599 | - if ($load_only) { |
|
600 | - return true; |
|
601 | - } |
|
602 | - $addon = $addon ? 'addon' : ''; |
|
603 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
604 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
605 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
606 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
607 | - // return object if it's already cached |
|
608 | - $cached_class = $this->_get_cached_class($class_name, $addon); |
|
609 | - if ($cached_class !== null) { |
|
610 | - return $cached_class; |
|
611 | - } |
|
612 | - } |
|
613 | - // instantiate the requested object |
|
614 | - $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
615 | - // if caching is turned on OR this class is cached in a class property |
|
616 | - if (($this->_cache_on && $cache) || isset($this->_class_abbreviations[ $class_name ])) { |
|
617 | - // save it for later... kinda like gum { : $ |
|
618 | - $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
619 | - } |
|
620 | - $this->_cache_on = true; |
|
621 | - return $class_obj; |
|
622 | - } |
|
623 | - |
|
624 | - |
|
625 | - |
|
626 | - /** |
|
627 | - * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs |
|
628 | - * |
|
629 | - * @param string $class_name |
|
630 | - * @param array $arguments |
|
631 | - * @param int $attempt |
|
632 | - * @return mixed |
|
633 | - */ |
|
634 | - private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) { |
|
635 | - if (is_object($class_name) || class_exists($class_name)) { |
|
636 | - return $class_name; |
|
637 | - } |
|
638 | - switch ($attempt) { |
|
639 | - case 1: |
|
640 | - // if it's a FQCN then maybe the class is registered with a preceding \ |
|
641 | - $class_name = strpos($class_name, '\\') !== false |
|
642 | - ? '\\' . ltrim($class_name, '\\') |
|
643 | - : $class_name; |
|
644 | - break; |
|
645 | - case 2: |
|
646 | - // |
|
647 | - $loader = $this->_dependency_map->class_loader($class_name); |
|
648 | - if ($loader && method_exists($this, $loader)) { |
|
649 | - return $this->{$loader}($class_name, $arguments); |
|
650 | - } |
|
651 | - break; |
|
652 | - case 3: |
|
653 | - default; |
|
654 | - return null; |
|
655 | - } |
|
656 | - $attempt++; |
|
657 | - return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt); |
|
658 | - } |
|
659 | - |
|
660 | - |
|
661 | - |
|
662 | - /** |
|
663 | - * instantiates, caches, and injects dependencies for classes |
|
664 | - * |
|
665 | - * @param array $file_paths an array of paths to folders to look in |
|
666 | - * @param string $class_prefix EE or EEM or... ??? |
|
667 | - * @param bool|string $class_name $class name |
|
668 | - * @param string $type file type - core? class? helper? model? |
|
669 | - * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
670 | - * @param bool $from_db some classes are instantiated from the db |
|
671 | - * and thus call a different method to instantiate |
|
672 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
673 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
674 | - * @return bool|null|object null = failure to load or instantiate class object. |
|
675 | - * object = class loaded and instantiated successfully. |
|
676 | - * bool = fail or success when $load_only is true |
|
677 | - * @throws EE_Error |
|
678 | - */ |
|
679 | - protected function _load( |
|
680 | - $file_paths = array(), |
|
681 | - $class_prefix = 'EE_', |
|
682 | - $class_name = false, |
|
683 | - $type = 'class', |
|
684 | - $arguments = array(), |
|
685 | - $from_db = false, |
|
686 | - $cache = true, |
|
687 | - $load_only = false |
|
688 | - ) { |
|
689 | - $class_name = ltrim($class_name, '\\'); |
|
690 | - // strip php file extension |
|
691 | - $class_name = str_replace('.php', '', trim($class_name)); |
|
692 | - // does the class have a prefix ? |
|
693 | - if ( ! empty($class_prefix) && $class_prefix != 'addon') { |
|
694 | - // make sure $class_prefix is uppercase |
|
695 | - $class_prefix = strtoupper(trim($class_prefix)); |
|
696 | - // add class prefix ONCE!!! |
|
697 | - $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
698 | - } |
|
699 | - $class_name = $this->_dependency_map->get_alias($class_name); |
|
700 | - $class_exists = class_exists($class_name); |
|
701 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
702 | - if ($load_only && $class_exists) { |
|
703 | - return true; |
|
704 | - } |
|
705 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
706 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
707 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
708 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
709 | - // return object if it's already cached |
|
710 | - $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
711 | - if ($cached_class !== null) { |
|
712 | - return $cached_class; |
|
713 | - } |
|
714 | - } |
|
715 | - // if the class doesn't already exist.. then we need to try and find the file and load it |
|
716 | - if ( ! $class_exists) { |
|
717 | - // get full path to file |
|
718 | - $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
719 | - // load the file |
|
720 | - $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
721 | - // if loading failed, or we are only loading a file but NOT instantiating an object |
|
722 | - if ( ! $loaded || $load_only) { |
|
723 | - // return boolean if only loading, or null if an object was expected |
|
724 | - return $load_only ? $loaded : null; |
|
725 | - } |
|
726 | - } |
|
727 | - // instantiate the requested object |
|
728 | - $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
729 | - if ($this->_cache_on && $cache) { |
|
730 | - // save it for later... kinda like gum { : $ |
|
731 | - $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
732 | - } |
|
733 | - $this->_cache_on = true; |
|
734 | - return $class_obj; |
|
735 | - } |
|
736 | - |
|
737 | - |
|
738 | - |
|
739 | - |
|
740 | - /** |
|
741 | - * _get_cached_class |
|
742 | - * attempts to find a cached version of the requested class |
|
743 | - * by looking in the following places: |
|
744 | - * $this->{$class_abbreviation} ie: $this->CART |
|
745 | - * $this->{$class_name} ie: $this->Some_Class |
|
746 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
747 | - * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
748 | - * |
|
749 | - * @access protected |
|
750 | - * @param string $class_name |
|
751 | - * @param string $class_prefix |
|
752 | - * @return mixed |
|
753 | - */ |
|
754 | - protected function _get_cached_class($class_name, $class_prefix = '') |
|
755 | - { |
|
756 | - // have to specify something, but not anything that will conflict |
|
757 | - $class_abbreviation = isset($this->_class_abbreviations[ $class_name ]) |
|
758 | - ? $this->_class_abbreviations[ $class_name ] |
|
759 | - : 'FANCY_BATMAN_PANTS'; |
|
760 | - $class_name = str_replace('\\', '_', $class_name); |
|
761 | - // check if class has already been loaded, and return it if it has been |
|
762 | - if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) { |
|
763 | - return $this->{$class_abbreviation}; |
|
764 | - } |
|
765 | - if (isset ($this->{$class_name})) { |
|
766 | - return $this->{$class_name}; |
|
767 | - } |
|
768 | - if (isset ($this->LIB->{$class_name})) { |
|
769 | - return $this->LIB->{$class_name}; |
|
770 | - } |
|
771 | - if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) { |
|
772 | - return $this->addons->{$class_name}; |
|
773 | - } |
|
774 | - return null; |
|
775 | - } |
|
776 | - |
|
777 | - |
|
778 | - |
|
779 | - /** |
|
780 | - * removes a cached version of the requested class |
|
781 | - * |
|
782 | - * @param string $class_name |
|
783 | - * @param boolean $addon |
|
784 | - * @return boolean |
|
785 | - */ |
|
786 | - public function clear_cached_class($class_name, $addon = false) |
|
787 | - { |
|
788 | - // have to specify something, but not anything that will conflict |
|
789 | - $class_abbreviation = isset($this->_class_abbreviations[ $class_name ]) |
|
790 | - ? $this->_class_abbreviations[ $class_name ] |
|
791 | - : 'FANCY_BATMAN_PANTS'; |
|
792 | - $class_name = str_replace('\\', '_', $class_name); |
|
793 | - // check if class has already been loaded, and return it if it has been |
|
794 | - if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) { |
|
795 | - $this->{$class_abbreviation} = null; |
|
796 | - return true; |
|
797 | - } |
|
798 | - if (isset($this->{$class_name})) { |
|
799 | - $this->{$class_name} = null; |
|
800 | - return true; |
|
801 | - } |
|
802 | - if (isset($this->LIB->{$class_name})) { |
|
803 | - unset($this->LIB->{$class_name}); |
|
804 | - return true; |
|
805 | - } |
|
806 | - if ($addon && isset($this->addons->{$class_name})) { |
|
807 | - unset($this->addons->{$class_name}); |
|
808 | - return true; |
|
809 | - } |
|
810 | - return false; |
|
811 | - } |
|
812 | - |
|
813 | - |
|
814 | - /** |
|
815 | - * _resolve_path |
|
816 | - * attempts to find a full valid filepath for the requested class. |
|
817 | - * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
818 | - * then returns that path if the target file has been found and is readable |
|
819 | - * |
|
820 | - * @access protected |
|
821 | - * @param string $class_name |
|
822 | - * @param string $type |
|
823 | - * @param array $file_paths |
|
824 | - * @return string | bool |
|
825 | - */ |
|
826 | - protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
827 | - { |
|
828 | - // make sure $file_paths is an array |
|
829 | - $file_paths = is_array($file_paths) ? $file_paths : array($file_paths); |
|
830 | - // cycle thru paths |
|
831 | - foreach ($file_paths as $key => $file_path) { |
|
832 | - // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
833 | - $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES; |
|
834 | - // prep file type |
|
835 | - $type = ! empty($type) ? trim($type, '.') . '.' : ''; |
|
836 | - // build full file path |
|
837 | - $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
838 | - //does the file exist and can be read ? |
|
839 | - if (is_readable($file_paths[$key])) { |
|
840 | - return $file_paths[$key]; |
|
841 | - } |
|
842 | - } |
|
843 | - return false; |
|
844 | - } |
|
845 | - |
|
846 | - |
|
847 | - |
|
848 | - /** |
|
849 | - * _require_file |
|
850 | - * basically just performs a require_once() |
|
851 | - * but with some error handling |
|
852 | - * |
|
853 | - * @access protected |
|
854 | - * @param string $path |
|
855 | - * @param string $class_name |
|
856 | - * @param string $type |
|
857 | - * @param array $file_paths |
|
858 | - * @return boolean |
|
859 | - * @throws \EE_Error |
|
860 | - */ |
|
861 | - protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
862 | - { |
|
863 | - // don't give up! you gotta... |
|
864 | - try { |
|
865 | - //does the file exist and can it be read ? |
|
866 | - if ( ! $path) { |
|
867 | - // so sorry, can't find the file |
|
868 | - throw new EE_Error ( |
|
869 | - sprintf( |
|
870 | - __('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso'), |
|
871 | - trim($type, '.'), |
|
872 | - $class_name, |
|
873 | - '<br />' . implode(',<br />', $file_paths) |
|
874 | - ) |
|
875 | - ); |
|
876 | - } |
|
877 | - // get the file |
|
878 | - require_once($path); |
|
879 | - // if the class isn't already declared somewhere |
|
880 | - if (class_exists($class_name, false) === false) { |
|
881 | - // so sorry, not a class |
|
882 | - throw new EE_Error( |
|
883 | - sprintf( |
|
884 | - __('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
885 | - $type, |
|
886 | - $path, |
|
887 | - $class_name |
|
888 | - ) |
|
889 | - ); |
|
890 | - } |
|
891 | - } catch (EE_Error $e) { |
|
892 | - $e->get_error(); |
|
893 | - return false; |
|
894 | - } |
|
895 | - return true; |
|
896 | - } |
|
897 | - |
|
898 | - |
|
899 | - |
|
900 | - /** |
|
901 | - * _create_object |
|
902 | - * Attempts to instantiate the requested class via any of the |
|
903 | - * commonly used instantiation methods employed throughout EE. |
|
904 | - * The priority for instantiation is as follows: |
|
905 | - * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
906 | - * - model objects via their 'new_instance_from_db' method |
|
907 | - * - model objects via their 'new_instance' method |
|
908 | - * - "singleton" classes" via their 'instance' method |
|
909 | - * - standard instantiable classes via their __constructor |
|
910 | - * Prior to instantiation, if the classname exists in the dependency_map, |
|
911 | - * then the constructor for the requested class will be examined to determine |
|
912 | - * if any dependencies exist, and if they can be injected. |
|
913 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
914 | - * |
|
915 | - * @access protected |
|
916 | - * @param string $class_name |
|
917 | - * @param array $arguments |
|
918 | - * @param string $type |
|
919 | - * @param bool $from_db |
|
920 | - * @return null | object |
|
921 | - * @throws \EE_Error |
|
922 | - */ |
|
923 | - protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
924 | - { |
|
925 | - $class_obj = null; |
|
926 | - $instantiation_mode = '0) none'; |
|
927 | - // don't give up! you gotta... |
|
928 | - try { |
|
929 | - // create reflection |
|
930 | - $reflector = $this->get_ReflectionClass($class_name); |
|
931 | - // make sure arguments are an array |
|
932 | - $arguments = is_array($arguments) ? $arguments : array($arguments); |
|
933 | - // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
934 | - // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
935 | - $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
936 | - ? $arguments |
|
937 | - : array($arguments); |
|
938 | - // attempt to inject dependencies ? |
|
939 | - if ($this->_dependency_map->has($class_name)) { |
|
940 | - $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
941 | - } |
|
942 | - // instantiate the class if possible |
|
943 | - if ($reflector->isAbstract()) { |
|
944 | - // nothing to instantiate, loading file was enough |
|
945 | - // does not throw an exception so $instantiation_mode is unused |
|
946 | - // $instantiation_mode = "1) no constructor abstract class"; |
|
947 | - $class_obj = true; |
|
948 | - } else if ($reflector->getConstructor() === null && $reflector->isInstantiable() && empty($arguments)) { |
|
949 | - // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
950 | - $instantiation_mode = "2) no constructor but instantiable"; |
|
951 | - $class_obj = $reflector->newInstance(); |
|
952 | - } else if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
953 | - $instantiation_mode = "3) new_instance_from_db()"; |
|
954 | - $class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
955 | - } else if (method_exists($class_name, 'new_instance')) { |
|
956 | - $instantiation_mode = "4) new_instance()"; |
|
957 | - $class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
958 | - } else if (method_exists($class_name, 'instance')) { |
|
959 | - $instantiation_mode = "5) instance()"; |
|
960 | - $class_obj = call_user_func_array(array($class_name, 'instance'), $arguments); |
|
961 | - } else if ($reflector->isInstantiable()) { |
|
962 | - $instantiation_mode = "6) constructor"; |
|
963 | - $class_obj = $reflector->newInstanceArgs($arguments); |
|
964 | - } else { |
|
965 | - // heh ? something's not right ! |
|
966 | - throw new EE_Error( |
|
967 | - sprintf( |
|
968 | - __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
969 | - $type, |
|
970 | - $class_name |
|
971 | - ) |
|
972 | - ); |
|
973 | - } |
|
974 | - } catch (Exception $e) { |
|
975 | - if ( ! $e instanceof EE_Error) { |
|
976 | - $e = new EE_Error( |
|
977 | - sprintf( |
|
978 | - __('The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso'), |
|
979 | - $class_name, |
|
980 | - '<br />', |
|
981 | - $e->getMessage(), |
|
982 | - $instantiation_mode |
|
983 | - ) |
|
984 | - ); |
|
985 | - } |
|
986 | - $e->get_error(); |
|
987 | - } |
|
988 | - return $class_obj; |
|
989 | - } |
|
990 | - |
|
991 | - |
|
992 | - |
|
993 | - /** |
|
994 | - * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
995 | - * @param array $array |
|
996 | - * @return bool |
|
997 | - */ |
|
998 | - protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
999 | - { |
|
1000 | - return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true; |
|
1001 | - } |
|
1002 | - |
|
1003 | - |
|
1004 | - |
|
1005 | - /** |
|
1006 | - * getReflectionClass |
|
1007 | - * checks if a ReflectionClass object has already been generated for a class |
|
1008 | - * and returns that instead of creating a new one |
|
1009 | - * |
|
1010 | - * @access public |
|
1011 | - * @param string $class_name |
|
1012 | - * @return ReflectionClass |
|
1013 | - */ |
|
1014 | - public function get_ReflectionClass($class_name) |
|
1015 | - { |
|
1016 | - if ( |
|
1017 | - ! isset($this->_reflectors[$class_name]) |
|
1018 | - || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
1019 | - ) { |
|
1020 | - $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
1021 | - } |
|
1022 | - return $this->_reflectors[$class_name]; |
|
1023 | - } |
|
1024 | - |
|
1025 | - |
|
1026 | - |
|
1027 | - /** |
|
1028 | - * _resolve_dependencies |
|
1029 | - * examines the constructor for the requested class to determine |
|
1030 | - * if any dependencies exist, and if they can be injected. |
|
1031 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
1032 | - * PLZ NOTE: this is achieved by type hinting the constructor params |
|
1033 | - * For example: |
|
1034 | - * if attempting to load a class "Foo" with the following constructor: |
|
1035 | - * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
1036 | - * then $bar_class and $grohl_class will be added to the $arguments array, |
|
1037 | - * but only IF they are NOT already present in the incoming arguments array, |
|
1038 | - * and the correct classes can be loaded |
|
1039 | - * |
|
1040 | - * @access protected |
|
1041 | - * @param ReflectionClass $reflector |
|
1042 | - * @param string $class_name |
|
1043 | - * @param array $arguments |
|
1044 | - * @return array |
|
1045 | - * @throws \ReflectionException |
|
1046 | - */ |
|
1047 | - protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
|
1048 | - { |
|
1049 | - // let's examine the constructor |
|
1050 | - $constructor = $reflector->getConstructor(); |
|
1051 | - // whu? huh? nothing? |
|
1052 | - if ( ! $constructor) { |
|
1053 | - return $arguments; |
|
1054 | - } |
|
1055 | - // get constructor parameters |
|
1056 | - $params = $constructor->getParameters(); |
|
1057 | - // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
1058 | - $argument_keys = array_keys($arguments); |
|
1059 | - // now loop thru all of the constructors expected parameters |
|
1060 | - foreach ($params as $index => $param) { |
|
1061 | - // is this a dependency for a specific class ? |
|
1062 | - $param_class = $param->getClass() ? $param->getClass()->name : null; |
|
1063 | - // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime) |
|
1064 | - $param_class = $this->_dependency_map->has_alias($param_class, $class_name) |
|
1065 | - ? $this->_dependency_map->get_alias($param_class, $class_name) |
|
1066 | - : $param_class; |
|
1067 | - if ( |
|
1068 | - // param is not even a class |
|
1069 | - empty($param_class) |
|
1070 | - // and something already exists in the incoming arguments for this param |
|
1071 | - && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
1072 | - ) { |
|
1073 | - // so let's skip this argument and move on to the next |
|
1074 | - continue; |
|
1075 | - } |
|
1076 | - if ( |
|
1077 | - // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
1078 | - ! empty($param_class) |
|
1079 | - && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
1080 | - && $arguments[$argument_keys[$index]] instanceof $param_class |
|
1081 | - ) { |
|
1082 | - // skip this argument and move on to the next |
|
1083 | - continue; |
|
1084 | - } |
|
1085 | - if ( |
|
1086 | - // parameter is type hinted as a class, and should be injected |
|
1087 | - ! empty($param_class) |
|
1088 | - && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
1089 | - ) { |
|
1090 | - $arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index); |
|
1091 | - } else { |
|
1092 | - try { |
|
1093 | - $arguments[$index] = $param->getDefaultValue(); |
|
1094 | - } catch (ReflectionException $e) { |
|
1095 | - throw new ReflectionException( |
|
1096 | - sprintf( |
|
1097 | - __('%1$s for parameter "$%2$s"', 'event_espresso'), |
|
1098 | - $e->getMessage(), |
|
1099 | - $param->getName() |
|
1100 | - ) |
|
1101 | - ); |
|
1102 | - } |
|
1103 | - } |
|
1104 | - } |
|
1105 | - return $arguments; |
|
1106 | - } |
|
1107 | - |
|
1108 | - |
|
1109 | - |
|
1110 | - /** |
|
1111 | - * @access protected |
|
1112 | - * @param string $class_name |
|
1113 | - * @param string $param_class |
|
1114 | - * @param array $arguments |
|
1115 | - * @param mixed $index |
|
1116 | - * @return array |
|
1117 | - */ |
|
1118 | - protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
|
1119 | - { |
|
1120 | - $dependency = null; |
|
1121 | - // should dependency be loaded from cache ? |
|
1122 | - $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class) |
|
1123 | - !== EE_Dependency_Map::load_new_object |
|
1124 | - ? true |
|
1125 | - : false; |
|
1126 | - // we might have a dependency... |
|
1127 | - // let's MAYBE try and find it in our cache if that's what's been requested |
|
1128 | - $cached_class = $cache_on ? $this->_get_cached_class($param_class) : null; |
|
1129 | - // and grab it if it exists |
|
1130 | - if ($cached_class instanceof $param_class) { |
|
1131 | - $dependency = $cached_class; |
|
1132 | - } else if ($param_class !== $class_name) { |
|
1133 | - // obtain the loader method from the dependency map |
|
1134 | - $loader = $this->_dependency_map->class_loader($param_class); |
|
1135 | - // is loader a custom closure ? |
|
1136 | - if ($loader instanceof Closure) { |
|
1137 | - $dependency = $loader(); |
|
1138 | - } else { |
|
1139 | - // set the cache on property for the recursive loading call |
|
1140 | - $this->_cache_on = $cache_on; |
|
1141 | - // if not, then let's try and load it via the registry |
|
1142 | - if ($loader && method_exists($this, $loader)) { |
|
1143 | - $dependency = $this->{$loader}($param_class); |
|
1144 | - } else { |
|
1145 | - $dependency = $this->create($param_class, array(), $cache_on); |
|
1146 | - } |
|
1147 | - } |
|
1148 | - } |
|
1149 | - // did we successfully find the correct dependency ? |
|
1150 | - if ($dependency instanceof $param_class) { |
|
1151 | - // then let's inject it into the incoming array of arguments at the correct location |
|
1152 | - if (isset($argument_keys[$index])) { |
|
1153 | - $arguments[$argument_keys[$index]] = $dependency; |
|
1154 | - } else { |
|
1155 | - $arguments[$index] = $dependency; |
|
1156 | - } |
|
1157 | - } |
|
1158 | - return $arguments; |
|
1159 | - } |
|
1160 | - |
|
1161 | - |
|
1162 | - |
|
1163 | - /** |
|
1164 | - * _set_cached_class |
|
1165 | - * attempts to cache the instantiated class locally |
|
1166 | - * in one of the following places, in the following order: |
|
1167 | - * $this->{class_abbreviation} ie: $this->CART |
|
1168 | - * $this->{$class_name} ie: $this->Some_Class |
|
1169 | - * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
1170 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
1171 | - * |
|
1172 | - * @access protected |
|
1173 | - * @param object $class_obj |
|
1174 | - * @param string $class_name |
|
1175 | - * @param string $class_prefix |
|
1176 | - * @param bool $from_db |
|
1177 | - * @return void |
|
1178 | - */ |
|
1179 | - protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
|
1180 | - { |
|
1181 | - if (empty($class_obj)) { |
|
1182 | - return; |
|
1183 | - } |
|
1184 | - // return newly instantiated class |
|
1185 | - if (isset($this->_class_abbreviations[$class_name])) { |
|
1186 | - $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
1187 | - $this->{$class_abbreviation} = $class_obj; |
|
1188 | - return; |
|
1189 | - } |
|
1190 | - $class_name = str_replace('\\', '_', $class_name); |
|
1191 | - if (property_exists($this, $class_name)) { |
|
1192 | - $this->{$class_name} = $class_obj; |
|
1193 | - return; |
|
1194 | - } |
|
1195 | - if ($class_prefix === 'addon') { |
|
1196 | - $this->addons->{$class_name} = $class_obj; |
|
1197 | - return; |
|
1198 | - } |
|
1199 | - if ( ! $from_db) { |
|
1200 | - $this->LIB->{$class_name} = $class_obj; |
|
1201 | - } |
|
1202 | - } |
|
1203 | - |
|
1204 | - |
|
1205 | - |
|
1206 | - /** |
|
1207 | - * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
1208 | - * |
|
1209 | - * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
1210 | - * in the EE_Dependency_Map::$_class_loaders array, |
|
1211 | - * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
1212 | - * @param array $arguments |
|
1213 | - * @return object |
|
1214 | - */ |
|
1215 | - public static function factory($classname, $arguments = array()) |
|
1216 | - { |
|
1217 | - $loader = self::instance()->_dependency_map->class_loader($classname); |
|
1218 | - if ($loader instanceof Closure) { |
|
1219 | - return $loader($arguments); |
|
1220 | - } |
|
1221 | - if (method_exists(EE_Registry::instance(), $loader)) { |
|
1222 | - return EE_Registry::instance()->{$loader}($classname, $arguments); |
|
1223 | - } |
|
1224 | - return null; |
|
1225 | - } |
|
1226 | - |
|
1227 | - |
|
1228 | - |
|
1229 | - /** |
|
1230 | - * Gets the addon by its name/slug (not classname. For that, just |
|
1231 | - * use the classname as the property name on EE_Config::instance()->addons) |
|
1232 | - * |
|
1233 | - * @param string $name |
|
1234 | - * @return EE_Addon |
|
1235 | - */ |
|
1236 | - public function get_addon_by_name($name) |
|
1237 | - { |
|
1238 | - foreach ($this->addons as $addon) { |
|
1239 | - if ($addon->name() == $name) { |
|
1240 | - return $addon; |
|
1241 | - } |
|
1242 | - } |
|
1243 | - return null; |
|
1244 | - } |
|
1245 | - |
|
1246 | - |
|
1247 | - |
|
1248 | - /** |
|
1249 | - * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their name() function) They're already available on EE_Config::instance()->addons as properties, where each property's name is |
|
1250 | - * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname} |
|
1251 | - * |
|
1252 | - * @return EE_Addon[] where the KEYS are the addon's name() |
|
1253 | - */ |
|
1254 | - public function get_addons_by_name() |
|
1255 | - { |
|
1256 | - $addons = array(); |
|
1257 | - foreach ($this->addons as $addon) { |
|
1258 | - $addons[$addon->name()] = $addon; |
|
1259 | - } |
|
1260 | - return $addons; |
|
1261 | - } |
|
1262 | - |
|
1263 | - |
|
1264 | - |
|
1265 | - /** |
|
1266 | - * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
1267 | - * a stale copy of it around |
|
1268 | - * |
|
1269 | - * @param string $model_name |
|
1270 | - * @return \EEM_Base |
|
1271 | - * @throws \EE_Error |
|
1272 | - */ |
|
1273 | - public function reset_model($model_name) |
|
1274 | - { |
|
1275 | - $model_class_name = strpos($model_name, 'EEM_') !== 0 ? "EEM_{$model_name}" : $model_name; |
|
1276 | - if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
1277 | - return null; |
|
1278 | - } |
|
1279 | - //get that model reset it and make sure we nuke the old reference to it |
|
1280 | - if ($this->LIB->{$model_class_name} instanceof $model_class_name && is_callable(array($model_class_name, 'reset'))) { |
|
1281 | - $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
1282 | - } else { |
|
1283 | - throw new EE_Error(sprintf(__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
1284 | - } |
|
1285 | - return $this->LIB->{$model_class_name}; |
|
1286 | - } |
|
1287 | - |
|
1288 | - |
|
1289 | - |
|
1290 | - /** |
|
1291 | - * Resets the registry. |
|
1292 | - * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog |
|
1293 | - * is used in a multisite install. Here is a list of things that are NOT reset. |
|
1294 | - * - $_dependency_map |
|
1295 | - * - $_class_abbreviations |
|
1296 | - * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
1297 | - * - $REQ: Still on the same request so no need to change. |
|
1298 | - * - $CAP: There is no site specific state in the EE_Capability class. |
|
1299 | - * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session |
|
1300 | - * can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
1301 | - * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
1302 | - * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
1303 | - * switch or on the restore. |
|
1304 | - * - $modules |
|
1305 | - * - $shortcodes |
|
1306 | - * - $widgets |
|
1307 | - * |
|
1308 | - * @param boolean $hard whether to reset data in the database too, or just refresh |
|
1309 | - * the Registry to its state at the beginning of the request |
|
1310 | - * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
1311 | - * or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN |
|
1312 | - * currently reinstantiate the singletons at the moment) |
|
1313 | - * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so client |
|
1314 | - * code instead can just change the model context to a different blog id if necessary |
|
1315 | - * @return EE_Registry |
|
1316 | - */ |
|
1317 | - public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
1318 | - { |
|
1319 | - $instance = self::instance(); |
|
1320 | - EEH_Activation::reset(); |
|
1321 | - //properties that get reset |
|
1322 | - $instance->_cache_on = true; |
|
1323 | - $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
1324 | - $instance->CART = null; |
|
1325 | - $instance->MRM = null; |
|
1326 | - $instance->AssetsRegistry = null; |
|
1327 | - $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry'); |
|
1328 | - //messages reset |
|
1329 | - EED_Messages::reset(); |
|
1330 | - if ($reset_models) { |
|
1331 | - foreach (array_keys($instance->non_abstract_db_models) as $model_name) { |
|
1332 | - $instance->reset_model($model_name); |
|
1333 | - } |
|
1334 | - } |
|
1335 | - $instance->LIB = new stdClass(); |
|
1336 | - return $instance; |
|
1337 | - } |
|
1338 | - |
|
1339 | - |
|
1340 | - |
|
1341 | - /** |
|
1342 | - * @override magic methods |
|
1343 | - * @return void |
|
1344 | - */ |
|
1345 | - public final function __destruct() |
|
1346 | - { |
|
1347 | - } |
|
1348 | - |
|
1349 | - |
|
1350 | - |
|
1351 | - /** |
|
1352 | - * @param $a |
|
1353 | - * @param $b |
|
1354 | - */ |
|
1355 | - public final function __call($a, $b) |
|
1356 | - { |
|
1357 | - } |
|
1358 | - |
|
1359 | - |
|
1360 | - |
|
1361 | - /** |
|
1362 | - * @param $a |
|
1363 | - */ |
|
1364 | - public final function __get($a) |
|
1365 | - { |
|
1366 | - } |
|
1367 | - |
|
1368 | - |
|
1369 | - |
|
1370 | - /** |
|
1371 | - * @param $a |
|
1372 | - * @param $b |
|
1373 | - */ |
|
1374 | - public final function __set($a, $b) |
|
1375 | - { |
|
1376 | - } |
|
1377 | - |
|
1378 | - |
|
1379 | - |
|
1380 | - /** |
|
1381 | - * @param $a |
|
1382 | - */ |
|
1383 | - public final function __isset($a) |
|
1384 | - { |
|
1385 | - } |
|
19 | + /** |
|
20 | + * EE_Registry Object |
|
21 | + * |
|
22 | + * @var EE_Registry $_instance |
|
23 | + * @access private |
|
24 | + */ |
|
25 | + private static $_instance = null; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var EE_Dependency_Map $_dependency_map |
|
29 | + * @access protected |
|
30 | + */ |
|
31 | + protected $_dependency_map = null; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var array $_class_abbreviations |
|
35 | + * @access protected |
|
36 | + */ |
|
37 | + protected $_class_abbreviations = array(); |
|
38 | + |
|
39 | + /** |
|
40 | + * @access public |
|
41 | + * @var \EventEspresso\core\services\commands\CommandBusInterface $BUS |
|
42 | + */ |
|
43 | + public $BUS; |
|
44 | + |
|
45 | + /** |
|
46 | + * EE_Cart Object |
|
47 | + * |
|
48 | + * @access public |
|
49 | + * @var EE_Cart $CART |
|
50 | + */ |
|
51 | + public $CART = null; |
|
52 | + |
|
53 | + /** |
|
54 | + * EE_Config Object |
|
55 | + * |
|
56 | + * @access public |
|
57 | + * @var EE_Config $CFG |
|
58 | + */ |
|
59 | + public $CFG = null; |
|
60 | + |
|
61 | + /** |
|
62 | + * EE_Network_Config Object |
|
63 | + * |
|
64 | + * @access public |
|
65 | + * @var EE_Network_Config $NET_CFG |
|
66 | + */ |
|
67 | + public $NET_CFG = null; |
|
68 | + |
|
69 | + /** |
|
70 | + * StdClass object for storing library classes in |
|
71 | + * |
|
72 | + * @public LIB |
|
73 | + * @var StdClass $LIB |
|
74 | + */ |
|
75 | + public $LIB = null; |
|
76 | + |
|
77 | + /** |
|
78 | + * EE_Request_Handler Object |
|
79 | + * |
|
80 | + * @access public |
|
81 | + * @var EE_Request_Handler $REQ |
|
82 | + */ |
|
83 | + public $REQ = null; |
|
84 | + |
|
85 | + /** |
|
86 | + * EE_Session Object |
|
87 | + * |
|
88 | + * @access public |
|
89 | + * @var EE_Session $SSN |
|
90 | + */ |
|
91 | + public $SSN = null; |
|
92 | + |
|
93 | + /** |
|
94 | + * holds the ee capabilities object. |
|
95 | + * |
|
96 | + * @since 4.5.0 |
|
97 | + * @var EE_Capabilities |
|
98 | + */ |
|
99 | + public $CAP = null; |
|
100 | + |
|
101 | + /** |
|
102 | + * holds the EE_Message_Resource_Manager object. |
|
103 | + * |
|
104 | + * @since 4.9.0 |
|
105 | + * @var EE_Message_Resource_Manager |
|
106 | + */ |
|
107 | + public $MRM = null; |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * Holds the Assets Registry instance |
|
112 | + * @var Registry |
|
113 | + */ |
|
114 | + public $AssetsRegistry = null; |
|
115 | + |
|
116 | + /** |
|
117 | + * $addons - StdClass object for holding addons which have registered themselves to work with EE core |
|
118 | + * |
|
119 | + * @access public |
|
120 | + * @var EE_Addon[] |
|
121 | + */ |
|
122 | + public $addons = null; |
|
123 | + |
|
124 | + /** |
|
125 | + * $models |
|
126 | + * @access public |
|
127 | + * @var EEM_Base[] $models keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
128 | + */ |
|
129 | + public $models = array(); |
|
130 | + |
|
131 | + /** |
|
132 | + * $modules |
|
133 | + * @access public |
|
134 | + * @var EED_Module[] $modules |
|
135 | + */ |
|
136 | + public $modules = null; |
|
137 | + |
|
138 | + /** |
|
139 | + * $shortcodes |
|
140 | + * @access public |
|
141 | + * @var EES_Shortcode[] $shortcodes |
|
142 | + */ |
|
143 | + public $shortcodes = null; |
|
144 | + |
|
145 | + /** |
|
146 | + * $widgets |
|
147 | + * @access public |
|
148 | + * @var WP_Widget[] $widgets |
|
149 | + */ |
|
150 | + public $widgets = null; |
|
151 | + |
|
152 | + /** |
|
153 | + * $non_abstract_db_models |
|
154 | + * @access public |
|
155 | + * @var array this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
156 | + * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
157 | + * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
158 | + * classnames (eg "EEM_Event") |
|
159 | + */ |
|
160 | + public $non_abstract_db_models = array(); |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * $i18n_js_strings - internationalization for JS strings |
|
165 | + * usage: EE_Registry::i18n_js_strings['string_key'] = __( 'string to translate.', 'event_espresso' ); |
|
166 | + * in js file: var translatedString = eei18n.string_key; |
|
167 | + * |
|
168 | + * @access public |
|
169 | + * @var array |
|
170 | + */ |
|
171 | + public static $i18n_js_strings = array(); |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * $main_file - path to espresso.php |
|
176 | + * |
|
177 | + * @access public |
|
178 | + * @var array |
|
179 | + */ |
|
180 | + public $main_file; |
|
181 | + |
|
182 | + /** |
|
183 | + * array of ReflectionClass objects where the key is the class name |
|
184 | + * |
|
185 | + * @access public |
|
186 | + * @var ReflectionClass[] |
|
187 | + */ |
|
188 | + public $_reflectors; |
|
189 | + |
|
190 | + /** |
|
191 | + * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
192 | + * |
|
193 | + * @access protected |
|
194 | + * @var boolean $_cache_on |
|
195 | + */ |
|
196 | + protected $_cache_on = true; |
|
197 | + |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * @singleton method used to instantiate class object |
|
202 | + * @access public |
|
203 | + * @param \EE_Dependency_Map $dependency_map |
|
204 | + * @return \EE_Registry instance |
|
205 | + */ |
|
206 | + public static function instance(\EE_Dependency_Map $dependency_map = null) |
|
207 | + { |
|
208 | + // check if class object is instantiated |
|
209 | + if ( ! self::$_instance instanceof EE_Registry) { |
|
210 | + self::$_instance = new EE_Registry($dependency_map); |
|
211 | + } |
|
212 | + return self::$_instance; |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + *protected constructor to prevent direct creation |
|
219 | + * |
|
220 | + * @Constructor |
|
221 | + * @access protected |
|
222 | + * @param \EE_Dependency_Map $dependency_map |
|
223 | + */ |
|
224 | + protected function __construct(\EE_Dependency_Map $dependency_map) |
|
225 | + { |
|
226 | + $this->_dependency_map = $dependency_map; |
|
227 | + $this->LIB = new stdClass(); |
|
228 | + $this->addons = new stdClass(); |
|
229 | + $this->modules = new stdClass(); |
|
230 | + $this->shortcodes = new stdClass(); |
|
231 | + $this->widgets = new stdClass(); |
|
232 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + |
|
237 | + /** |
|
238 | + * initialize |
|
239 | + */ |
|
240 | + public function initialize() |
|
241 | + { |
|
242 | + $this->_class_abbreviations = apply_filters( |
|
243 | + 'FHEE__EE_Registry____construct___class_abbreviations', |
|
244 | + array( |
|
245 | + 'EE_Config' => 'CFG', |
|
246 | + 'EE_Session' => 'SSN', |
|
247 | + 'EE_Capabilities' => 'CAP', |
|
248 | + 'EE_Cart' => 'CART', |
|
249 | + 'EE_Network_Config' => 'NET_CFG', |
|
250 | + 'EE_Request_Handler' => 'REQ', |
|
251 | + 'EE_Message_Resource_Manager' => 'MRM', |
|
252 | + 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
253 | + 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
|
254 | + ) |
|
255 | + ); |
|
256 | + $this->load_core('Base', array(), true); |
|
257 | + // add our request and response objects to the cache |
|
258 | + $request_loader = $this->_dependency_map->class_loader('EE_Request'); |
|
259 | + $this->_set_cached_class( |
|
260 | + $request_loader(), |
|
261 | + 'EE_Request' |
|
262 | + ); |
|
263 | + $response_loader = $this->_dependency_map->class_loader('EE_Response'); |
|
264 | + $this->_set_cached_class( |
|
265 | + $response_loader(), |
|
266 | + 'EE_Response' |
|
267 | + ); |
|
268 | + add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
269 | + } |
|
270 | + |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * init |
|
275 | + * |
|
276 | + * @access public |
|
277 | + * @return void |
|
278 | + */ |
|
279 | + public function init() |
|
280 | + { |
|
281 | + // Get current page protocol |
|
282 | + $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
283 | + // Output admin-ajax.php URL with same protocol as current page |
|
284 | + self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
285 | + self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
286 | + } |
|
287 | + |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * localize_i18n_js_strings |
|
292 | + * |
|
293 | + * @return string |
|
294 | + */ |
|
295 | + public static function localize_i18n_js_strings() |
|
296 | + { |
|
297 | + $i18n_js_strings = (array)EE_Registry::$i18n_js_strings; |
|
298 | + foreach ($i18n_js_strings as $key => $value) { |
|
299 | + if (is_scalar($value)) { |
|
300 | + $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
301 | + } |
|
302 | + } |
|
303 | + return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
304 | + } |
|
305 | + |
|
306 | + |
|
307 | + |
|
308 | + /** |
|
309 | + * @param mixed string | EED_Module $module |
|
310 | + */ |
|
311 | + public function add_module($module) |
|
312 | + { |
|
313 | + if ($module instanceof EED_Module) { |
|
314 | + $module_class = get_class($module); |
|
315 | + $this->modules->{$module_class} = $module; |
|
316 | + } else { |
|
317 | + if ( ! class_exists('EE_Module_Request_Router')) { |
|
318 | + $this->load_core('Module_Request_Router'); |
|
319 | + } |
|
320 | + $this->modules->{$module} = EE_Module_Request_Router::module_factory($module); |
|
321 | + } |
|
322 | + } |
|
323 | + |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * @param string $module_name |
|
328 | + * @return mixed EED_Module | NULL |
|
329 | + */ |
|
330 | + public function get_module($module_name = '') |
|
331 | + { |
|
332 | + return isset($this->modules->{$module_name}) ? $this->modules->{$module_name} : null; |
|
333 | + } |
|
334 | + |
|
335 | + |
|
336 | + |
|
337 | + /** |
|
338 | + * loads core classes - must be singletons |
|
339 | + * |
|
340 | + * @access public |
|
341 | + * @param string $class_name - simple class name ie: session |
|
342 | + * @param mixed $arguments |
|
343 | + * @param bool $load_only |
|
344 | + * @return mixed |
|
345 | + */ |
|
346 | + public function load_core($class_name, $arguments = array(), $load_only = false) |
|
347 | + { |
|
348 | + $core_paths = apply_filters( |
|
349 | + 'FHEE__EE_Registry__load_core__core_paths', |
|
350 | + array( |
|
351 | + EE_CORE, |
|
352 | + EE_ADMIN, |
|
353 | + EE_CPTS, |
|
354 | + EE_CORE . 'data_migration_scripts' . DS, |
|
355 | + EE_CORE . 'request_stack' . DS, |
|
356 | + EE_CORE . 'middleware' . DS, |
|
357 | + ) |
|
358 | + ); |
|
359 | + // retrieve instantiated class |
|
360 | + return $this->_load($core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only); |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + |
|
365 | + /** |
|
366 | + * loads service classes |
|
367 | + * |
|
368 | + * @access public |
|
369 | + * @param string $class_name - simple class name ie: session |
|
370 | + * @param mixed $arguments |
|
371 | + * @param bool $load_only |
|
372 | + * @return mixed |
|
373 | + */ |
|
374 | + public function load_service($class_name, $arguments = array(), $load_only = false) |
|
375 | + { |
|
376 | + $service_paths = apply_filters( |
|
377 | + 'FHEE__EE_Registry__load_service__service_paths', |
|
378 | + array( |
|
379 | + EE_CORE . 'services' . DS, |
|
380 | + ) |
|
381 | + ); |
|
382 | + // retrieve instantiated class |
|
383 | + return $this->_load($service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only); |
|
384 | + } |
|
385 | + |
|
386 | + |
|
387 | + |
|
388 | + /** |
|
389 | + * loads data_migration_scripts |
|
390 | + * |
|
391 | + * @access public |
|
392 | + * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
393 | + * @param mixed $arguments |
|
394 | + * @return EE_Data_Migration_Script_Base|mixed |
|
395 | + */ |
|
396 | + public function load_dms($class_name, $arguments = array()) |
|
397 | + { |
|
398 | + // retrieve instantiated class |
|
399 | + return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false); |
|
400 | + } |
|
401 | + |
|
402 | + |
|
403 | + |
|
404 | + /** |
|
405 | + * loads object creating classes - must be singletons |
|
406 | + * |
|
407 | + * @param string $class_name - simple class name ie: attendee |
|
408 | + * @param mixed $arguments - an array of arguments to pass to the class |
|
409 | + * @param bool $from_db - some classes are instantiated from the db and thus call a different method to instantiate |
|
410 | + * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
411 | + * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate (default) |
|
412 | + * @return EE_Base_Class | bool |
|
413 | + */ |
|
414 | + public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
415 | + { |
|
416 | + $paths = apply_filters('FHEE__EE_Registry__load_class__paths', array( |
|
417 | + EE_CORE, |
|
418 | + EE_CLASSES, |
|
419 | + EE_BUSINESS, |
|
420 | + )); |
|
421 | + // retrieve instantiated class |
|
422 | + return $this->_load($paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only); |
|
423 | + } |
|
424 | + |
|
425 | + |
|
426 | + |
|
427 | + /** |
|
428 | + * loads helper classes - must be singletons |
|
429 | + * |
|
430 | + * @param string $class_name - simple class name ie: price |
|
431 | + * @param mixed $arguments |
|
432 | + * @param bool $load_only |
|
433 | + * @return EEH_Base | bool |
|
434 | + */ |
|
435 | + public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
436 | + { |
|
437 | + // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
438 | + $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
439 | + // retrieve instantiated class |
|
440 | + return $this->_load($helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only); |
|
441 | + } |
|
442 | + |
|
443 | + |
|
444 | + |
|
445 | + /** |
|
446 | + * loads core classes - must be singletons |
|
447 | + * |
|
448 | + * @access public |
|
449 | + * @param string $class_name - simple class name ie: session |
|
450 | + * @param mixed $arguments |
|
451 | + * @param bool $load_only |
|
452 | + * @param bool $cache whether to cache the object or not. |
|
453 | + * @return mixed |
|
454 | + */ |
|
455 | + public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
456 | + { |
|
457 | + $paths = array( |
|
458 | + EE_LIBRARIES, |
|
459 | + EE_LIBRARIES . 'messages' . DS, |
|
460 | + EE_LIBRARIES . 'shortcodes' . DS, |
|
461 | + EE_LIBRARIES . 'qtips' . DS, |
|
462 | + EE_LIBRARIES . 'payment_methods' . DS, |
|
463 | + ); |
|
464 | + // retrieve instantiated class |
|
465 | + return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only); |
|
466 | + } |
|
467 | + |
|
468 | + |
|
469 | + |
|
470 | + /** |
|
471 | + * loads model classes - must be singletons |
|
472 | + * |
|
473 | + * @param string $class_name - simple class name ie: price |
|
474 | + * @param mixed $arguments |
|
475 | + * @param bool $load_only |
|
476 | + * @return EEM_Base | bool |
|
477 | + */ |
|
478 | + public function load_model($class_name, $arguments = array(), $load_only = false) |
|
479 | + { |
|
480 | + $paths = apply_filters('FHEE__EE_Registry__load_model__paths', array( |
|
481 | + EE_MODELS, |
|
482 | + EE_CORE, |
|
483 | + )); |
|
484 | + // retrieve instantiated class |
|
485 | + return $this->_load($paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only); |
|
486 | + } |
|
487 | + |
|
488 | + |
|
489 | + |
|
490 | + /** |
|
491 | + * loads model classes - must be singletons |
|
492 | + * |
|
493 | + * @param string $class_name - simple class name ie: price |
|
494 | + * @param mixed $arguments |
|
495 | + * @param bool $load_only |
|
496 | + * @return mixed | bool |
|
497 | + */ |
|
498 | + public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
499 | + { |
|
500 | + $paths = array( |
|
501 | + EE_MODELS . 'fields' . DS, |
|
502 | + EE_MODELS . 'helpers' . DS, |
|
503 | + EE_MODELS . 'relations' . DS, |
|
504 | + EE_MODELS . 'strategies' . DS, |
|
505 | + ); |
|
506 | + // retrieve instantiated class |
|
507 | + return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only); |
|
508 | + } |
|
509 | + |
|
510 | + |
|
511 | + |
|
512 | + /** |
|
513 | + * Determines if $model_name is the name of an actual EE model. |
|
514 | + * |
|
515 | + * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
516 | + * @return boolean |
|
517 | + */ |
|
518 | + public function is_model_name($model_name) |
|
519 | + { |
|
520 | + return isset($this->models[$model_name]) ? true : false; |
|
521 | + } |
|
522 | + |
|
523 | + |
|
524 | + |
|
525 | + /** |
|
526 | + * generic class loader |
|
527 | + * |
|
528 | + * @param string $path_to_file - directory path to file location, not including filename |
|
529 | + * @param string $file_name - file name ie: my_file.php, including extension |
|
530 | + * @param string $type - file type - core? class? helper? model? |
|
531 | + * @param mixed $arguments |
|
532 | + * @param bool $load_only |
|
533 | + * @return mixed |
|
534 | + */ |
|
535 | + public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
536 | + { |
|
537 | + // retrieve instantiated class |
|
538 | + return $this->_load($path_to_file, '', $file_name, $type, $arguments, false, true, $load_only); |
|
539 | + } |
|
540 | + |
|
541 | + |
|
542 | + |
|
543 | + /** |
|
544 | + * load_addon |
|
545 | + * |
|
546 | + * @param string $path_to_file - directory path to file location, not including filename |
|
547 | + * @param string $class_name - full class name ie: My_Class |
|
548 | + * @param string $type - file type - core? class? helper? model? |
|
549 | + * @param mixed $arguments |
|
550 | + * @param bool $load_only |
|
551 | + * @return EE_Addon |
|
552 | + */ |
|
553 | + public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
554 | + { |
|
555 | + // retrieve instantiated class |
|
556 | + return $this->_load($path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only); |
|
557 | + } |
|
558 | + |
|
559 | + |
|
560 | + |
|
561 | + /** |
|
562 | + * instantiates, caches, and automatically resolves dependencies |
|
563 | + * for classes that use a Fully Qualified Class Name. |
|
564 | + * if the class is not capable of being loaded using PSR-4 autoloading, |
|
565 | + * then you need to use one of the existing load_*() methods |
|
566 | + * which can resolve the classname and filepath from the passed arguments |
|
567 | + * |
|
568 | + * @param bool|string $class_name Fully Qualified Class Name |
|
569 | + * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
570 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
571 | + * @param bool $from_db some classes are instantiated from the db |
|
572 | + * and thus call a different method to instantiate |
|
573 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
574 | + * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
575 | + * @return mixed null = failure to load or instantiate class object. |
|
576 | + * object = class loaded and instantiated successfully. |
|
577 | + * bool = fail or success when $load_only is true |
|
578 | + * @throws EE_Error |
|
579 | + */ |
|
580 | + public function create( |
|
581 | + $class_name = false, |
|
582 | + $arguments = array(), |
|
583 | + $cache = false, |
|
584 | + $from_db = false, |
|
585 | + $load_only = false, |
|
586 | + $addon = false |
|
587 | + ) { |
|
588 | + $class_name = ltrim($class_name, '\\'); |
|
589 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
590 | + $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments); |
|
591 | + // if a non-FQCN was passed, then verifyClassExists() might return an object |
|
592 | + // or it could return null if the class just could not be found anywhere |
|
593 | + if ($class_exists instanceof $class_name || $class_exists === null){ |
|
594 | + // either way, return the results |
|
595 | + return $class_exists; |
|
596 | + } |
|
597 | + $class_name = $class_exists; |
|
598 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
599 | + if ($load_only) { |
|
600 | + return true; |
|
601 | + } |
|
602 | + $addon = $addon ? 'addon' : ''; |
|
603 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
604 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
605 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
606 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
607 | + // return object if it's already cached |
|
608 | + $cached_class = $this->_get_cached_class($class_name, $addon); |
|
609 | + if ($cached_class !== null) { |
|
610 | + return $cached_class; |
|
611 | + } |
|
612 | + } |
|
613 | + // instantiate the requested object |
|
614 | + $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
615 | + // if caching is turned on OR this class is cached in a class property |
|
616 | + if (($this->_cache_on && $cache) || isset($this->_class_abbreviations[ $class_name ])) { |
|
617 | + // save it for later... kinda like gum { : $ |
|
618 | + $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
619 | + } |
|
620 | + $this->_cache_on = true; |
|
621 | + return $class_obj; |
|
622 | + } |
|
623 | + |
|
624 | + |
|
625 | + |
|
626 | + /** |
|
627 | + * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs |
|
628 | + * |
|
629 | + * @param string $class_name |
|
630 | + * @param array $arguments |
|
631 | + * @param int $attempt |
|
632 | + * @return mixed |
|
633 | + */ |
|
634 | + private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) { |
|
635 | + if (is_object($class_name) || class_exists($class_name)) { |
|
636 | + return $class_name; |
|
637 | + } |
|
638 | + switch ($attempt) { |
|
639 | + case 1: |
|
640 | + // if it's a FQCN then maybe the class is registered with a preceding \ |
|
641 | + $class_name = strpos($class_name, '\\') !== false |
|
642 | + ? '\\' . ltrim($class_name, '\\') |
|
643 | + : $class_name; |
|
644 | + break; |
|
645 | + case 2: |
|
646 | + // |
|
647 | + $loader = $this->_dependency_map->class_loader($class_name); |
|
648 | + if ($loader && method_exists($this, $loader)) { |
|
649 | + return $this->{$loader}($class_name, $arguments); |
|
650 | + } |
|
651 | + break; |
|
652 | + case 3: |
|
653 | + default; |
|
654 | + return null; |
|
655 | + } |
|
656 | + $attempt++; |
|
657 | + return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt); |
|
658 | + } |
|
659 | + |
|
660 | + |
|
661 | + |
|
662 | + /** |
|
663 | + * instantiates, caches, and injects dependencies for classes |
|
664 | + * |
|
665 | + * @param array $file_paths an array of paths to folders to look in |
|
666 | + * @param string $class_prefix EE or EEM or... ??? |
|
667 | + * @param bool|string $class_name $class name |
|
668 | + * @param string $type file type - core? class? helper? model? |
|
669 | + * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
670 | + * @param bool $from_db some classes are instantiated from the db |
|
671 | + * and thus call a different method to instantiate |
|
672 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
673 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
674 | + * @return bool|null|object null = failure to load or instantiate class object. |
|
675 | + * object = class loaded and instantiated successfully. |
|
676 | + * bool = fail or success when $load_only is true |
|
677 | + * @throws EE_Error |
|
678 | + */ |
|
679 | + protected function _load( |
|
680 | + $file_paths = array(), |
|
681 | + $class_prefix = 'EE_', |
|
682 | + $class_name = false, |
|
683 | + $type = 'class', |
|
684 | + $arguments = array(), |
|
685 | + $from_db = false, |
|
686 | + $cache = true, |
|
687 | + $load_only = false |
|
688 | + ) { |
|
689 | + $class_name = ltrim($class_name, '\\'); |
|
690 | + // strip php file extension |
|
691 | + $class_name = str_replace('.php', '', trim($class_name)); |
|
692 | + // does the class have a prefix ? |
|
693 | + if ( ! empty($class_prefix) && $class_prefix != 'addon') { |
|
694 | + // make sure $class_prefix is uppercase |
|
695 | + $class_prefix = strtoupper(trim($class_prefix)); |
|
696 | + // add class prefix ONCE!!! |
|
697 | + $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
698 | + } |
|
699 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
700 | + $class_exists = class_exists($class_name); |
|
701 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
702 | + if ($load_only && $class_exists) { |
|
703 | + return true; |
|
704 | + } |
|
705 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
706 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
707 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
708 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
709 | + // return object if it's already cached |
|
710 | + $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
711 | + if ($cached_class !== null) { |
|
712 | + return $cached_class; |
|
713 | + } |
|
714 | + } |
|
715 | + // if the class doesn't already exist.. then we need to try and find the file and load it |
|
716 | + if ( ! $class_exists) { |
|
717 | + // get full path to file |
|
718 | + $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
719 | + // load the file |
|
720 | + $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
721 | + // if loading failed, or we are only loading a file but NOT instantiating an object |
|
722 | + if ( ! $loaded || $load_only) { |
|
723 | + // return boolean if only loading, or null if an object was expected |
|
724 | + return $load_only ? $loaded : null; |
|
725 | + } |
|
726 | + } |
|
727 | + // instantiate the requested object |
|
728 | + $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
729 | + if ($this->_cache_on && $cache) { |
|
730 | + // save it for later... kinda like gum { : $ |
|
731 | + $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
732 | + } |
|
733 | + $this->_cache_on = true; |
|
734 | + return $class_obj; |
|
735 | + } |
|
736 | + |
|
737 | + |
|
738 | + |
|
739 | + |
|
740 | + /** |
|
741 | + * _get_cached_class |
|
742 | + * attempts to find a cached version of the requested class |
|
743 | + * by looking in the following places: |
|
744 | + * $this->{$class_abbreviation} ie: $this->CART |
|
745 | + * $this->{$class_name} ie: $this->Some_Class |
|
746 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
747 | + * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
748 | + * |
|
749 | + * @access protected |
|
750 | + * @param string $class_name |
|
751 | + * @param string $class_prefix |
|
752 | + * @return mixed |
|
753 | + */ |
|
754 | + protected function _get_cached_class($class_name, $class_prefix = '') |
|
755 | + { |
|
756 | + // have to specify something, but not anything that will conflict |
|
757 | + $class_abbreviation = isset($this->_class_abbreviations[ $class_name ]) |
|
758 | + ? $this->_class_abbreviations[ $class_name ] |
|
759 | + : 'FANCY_BATMAN_PANTS'; |
|
760 | + $class_name = str_replace('\\', '_', $class_name); |
|
761 | + // check if class has already been loaded, and return it if it has been |
|
762 | + if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) { |
|
763 | + return $this->{$class_abbreviation}; |
|
764 | + } |
|
765 | + if (isset ($this->{$class_name})) { |
|
766 | + return $this->{$class_name}; |
|
767 | + } |
|
768 | + if (isset ($this->LIB->{$class_name})) { |
|
769 | + return $this->LIB->{$class_name}; |
|
770 | + } |
|
771 | + if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) { |
|
772 | + return $this->addons->{$class_name}; |
|
773 | + } |
|
774 | + return null; |
|
775 | + } |
|
776 | + |
|
777 | + |
|
778 | + |
|
779 | + /** |
|
780 | + * removes a cached version of the requested class |
|
781 | + * |
|
782 | + * @param string $class_name |
|
783 | + * @param boolean $addon |
|
784 | + * @return boolean |
|
785 | + */ |
|
786 | + public function clear_cached_class($class_name, $addon = false) |
|
787 | + { |
|
788 | + // have to specify something, but not anything that will conflict |
|
789 | + $class_abbreviation = isset($this->_class_abbreviations[ $class_name ]) |
|
790 | + ? $this->_class_abbreviations[ $class_name ] |
|
791 | + : 'FANCY_BATMAN_PANTS'; |
|
792 | + $class_name = str_replace('\\', '_', $class_name); |
|
793 | + // check if class has already been loaded, and return it if it has been |
|
794 | + if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) { |
|
795 | + $this->{$class_abbreviation} = null; |
|
796 | + return true; |
|
797 | + } |
|
798 | + if (isset($this->{$class_name})) { |
|
799 | + $this->{$class_name} = null; |
|
800 | + return true; |
|
801 | + } |
|
802 | + if (isset($this->LIB->{$class_name})) { |
|
803 | + unset($this->LIB->{$class_name}); |
|
804 | + return true; |
|
805 | + } |
|
806 | + if ($addon && isset($this->addons->{$class_name})) { |
|
807 | + unset($this->addons->{$class_name}); |
|
808 | + return true; |
|
809 | + } |
|
810 | + return false; |
|
811 | + } |
|
812 | + |
|
813 | + |
|
814 | + /** |
|
815 | + * _resolve_path |
|
816 | + * attempts to find a full valid filepath for the requested class. |
|
817 | + * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
818 | + * then returns that path if the target file has been found and is readable |
|
819 | + * |
|
820 | + * @access protected |
|
821 | + * @param string $class_name |
|
822 | + * @param string $type |
|
823 | + * @param array $file_paths |
|
824 | + * @return string | bool |
|
825 | + */ |
|
826 | + protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
827 | + { |
|
828 | + // make sure $file_paths is an array |
|
829 | + $file_paths = is_array($file_paths) ? $file_paths : array($file_paths); |
|
830 | + // cycle thru paths |
|
831 | + foreach ($file_paths as $key => $file_path) { |
|
832 | + // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
833 | + $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES; |
|
834 | + // prep file type |
|
835 | + $type = ! empty($type) ? trim($type, '.') . '.' : ''; |
|
836 | + // build full file path |
|
837 | + $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
838 | + //does the file exist and can be read ? |
|
839 | + if (is_readable($file_paths[$key])) { |
|
840 | + return $file_paths[$key]; |
|
841 | + } |
|
842 | + } |
|
843 | + return false; |
|
844 | + } |
|
845 | + |
|
846 | + |
|
847 | + |
|
848 | + /** |
|
849 | + * _require_file |
|
850 | + * basically just performs a require_once() |
|
851 | + * but with some error handling |
|
852 | + * |
|
853 | + * @access protected |
|
854 | + * @param string $path |
|
855 | + * @param string $class_name |
|
856 | + * @param string $type |
|
857 | + * @param array $file_paths |
|
858 | + * @return boolean |
|
859 | + * @throws \EE_Error |
|
860 | + */ |
|
861 | + protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
862 | + { |
|
863 | + // don't give up! you gotta... |
|
864 | + try { |
|
865 | + //does the file exist and can it be read ? |
|
866 | + if ( ! $path) { |
|
867 | + // so sorry, can't find the file |
|
868 | + throw new EE_Error ( |
|
869 | + sprintf( |
|
870 | + __('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso'), |
|
871 | + trim($type, '.'), |
|
872 | + $class_name, |
|
873 | + '<br />' . implode(',<br />', $file_paths) |
|
874 | + ) |
|
875 | + ); |
|
876 | + } |
|
877 | + // get the file |
|
878 | + require_once($path); |
|
879 | + // if the class isn't already declared somewhere |
|
880 | + if (class_exists($class_name, false) === false) { |
|
881 | + // so sorry, not a class |
|
882 | + throw new EE_Error( |
|
883 | + sprintf( |
|
884 | + __('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
885 | + $type, |
|
886 | + $path, |
|
887 | + $class_name |
|
888 | + ) |
|
889 | + ); |
|
890 | + } |
|
891 | + } catch (EE_Error $e) { |
|
892 | + $e->get_error(); |
|
893 | + return false; |
|
894 | + } |
|
895 | + return true; |
|
896 | + } |
|
897 | + |
|
898 | + |
|
899 | + |
|
900 | + /** |
|
901 | + * _create_object |
|
902 | + * Attempts to instantiate the requested class via any of the |
|
903 | + * commonly used instantiation methods employed throughout EE. |
|
904 | + * The priority for instantiation is as follows: |
|
905 | + * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
906 | + * - model objects via their 'new_instance_from_db' method |
|
907 | + * - model objects via their 'new_instance' method |
|
908 | + * - "singleton" classes" via their 'instance' method |
|
909 | + * - standard instantiable classes via their __constructor |
|
910 | + * Prior to instantiation, if the classname exists in the dependency_map, |
|
911 | + * then the constructor for the requested class will be examined to determine |
|
912 | + * if any dependencies exist, and if they can be injected. |
|
913 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
914 | + * |
|
915 | + * @access protected |
|
916 | + * @param string $class_name |
|
917 | + * @param array $arguments |
|
918 | + * @param string $type |
|
919 | + * @param bool $from_db |
|
920 | + * @return null | object |
|
921 | + * @throws \EE_Error |
|
922 | + */ |
|
923 | + protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
924 | + { |
|
925 | + $class_obj = null; |
|
926 | + $instantiation_mode = '0) none'; |
|
927 | + // don't give up! you gotta... |
|
928 | + try { |
|
929 | + // create reflection |
|
930 | + $reflector = $this->get_ReflectionClass($class_name); |
|
931 | + // make sure arguments are an array |
|
932 | + $arguments = is_array($arguments) ? $arguments : array($arguments); |
|
933 | + // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
934 | + // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
935 | + $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
936 | + ? $arguments |
|
937 | + : array($arguments); |
|
938 | + // attempt to inject dependencies ? |
|
939 | + if ($this->_dependency_map->has($class_name)) { |
|
940 | + $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
941 | + } |
|
942 | + // instantiate the class if possible |
|
943 | + if ($reflector->isAbstract()) { |
|
944 | + // nothing to instantiate, loading file was enough |
|
945 | + // does not throw an exception so $instantiation_mode is unused |
|
946 | + // $instantiation_mode = "1) no constructor abstract class"; |
|
947 | + $class_obj = true; |
|
948 | + } else if ($reflector->getConstructor() === null && $reflector->isInstantiable() && empty($arguments)) { |
|
949 | + // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
950 | + $instantiation_mode = "2) no constructor but instantiable"; |
|
951 | + $class_obj = $reflector->newInstance(); |
|
952 | + } else if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
953 | + $instantiation_mode = "3) new_instance_from_db()"; |
|
954 | + $class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
955 | + } else if (method_exists($class_name, 'new_instance')) { |
|
956 | + $instantiation_mode = "4) new_instance()"; |
|
957 | + $class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
958 | + } else if (method_exists($class_name, 'instance')) { |
|
959 | + $instantiation_mode = "5) instance()"; |
|
960 | + $class_obj = call_user_func_array(array($class_name, 'instance'), $arguments); |
|
961 | + } else if ($reflector->isInstantiable()) { |
|
962 | + $instantiation_mode = "6) constructor"; |
|
963 | + $class_obj = $reflector->newInstanceArgs($arguments); |
|
964 | + } else { |
|
965 | + // heh ? something's not right ! |
|
966 | + throw new EE_Error( |
|
967 | + sprintf( |
|
968 | + __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
969 | + $type, |
|
970 | + $class_name |
|
971 | + ) |
|
972 | + ); |
|
973 | + } |
|
974 | + } catch (Exception $e) { |
|
975 | + if ( ! $e instanceof EE_Error) { |
|
976 | + $e = new EE_Error( |
|
977 | + sprintf( |
|
978 | + __('The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso'), |
|
979 | + $class_name, |
|
980 | + '<br />', |
|
981 | + $e->getMessage(), |
|
982 | + $instantiation_mode |
|
983 | + ) |
|
984 | + ); |
|
985 | + } |
|
986 | + $e->get_error(); |
|
987 | + } |
|
988 | + return $class_obj; |
|
989 | + } |
|
990 | + |
|
991 | + |
|
992 | + |
|
993 | + /** |
|
994 | + * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
995 | + * @param array $array |
|
996 | + * @return bool |
|
997 | + */ |
|
998 | + protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
999 | + { |
|
1000 | + return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true; |
|
1001 | + } |
|
1002 | + |
|
1003 | + |
|
1004 | + |
|
1005 | + /** |
|
1006 | + * getReflectionClass |
|
1007 | + * checks if a ReflectionClass object has already been generated for a class |
|
1008 | + * and returns that instead of creating a new one |
|
1009 | + * |
|
1010 | + * @access public |
|
1011 | + * @param string $class_name |
|
1012 | + * @return ReflectionClass |
|
1013 | + */ |
|
1014 | + public function get_ReflectionClass($class_name) |
|
1015 | + { |
|
1016 | + if ( |
|
1017 | + ! isset($this->_reflectors[$class_name]) |
|
1018 | + || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
1019 | + ) { |
|
1020 | + $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
1021 | + } |
|
1022 | + return $this->_reflectors[$class_name]; |
|
1023 | + } |
|
1024 | + |
|
1025 | + |
|
1026 | + |
|
1027 | + /** |
|
1028 | + * _resolve_dependencies |
|
1029 | + * examines the constructor for the requested class to determine |
|
1030 | + * if any dependencies exist, and if they can be injected. |
|
1031 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
1032 | + * PLZ NOTE: this is achieved by type hinting the constructor params |
|
1033 | + * For example: |
|
1034 | + * if attempting to load a class "Foo" with the following constructor: |
|
1035 | + * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
1036 | + * then $bar_class and $grohl_class will be added to the $arguments array, |
|
1037 | + * but only IF they are NOT already present in the incoming arguments array, |
|
1038 | + * and the correct classes can be loaded |
|
1039 | + * |
|
1040 | + * @access protected |
|
1041 | + * @param ReflectionClass $reflector |
|
1042 | + * @param string $class_name |
|
1043 | + * @param array $arguments |
|
1044 | + * @return array |
|
1045 | + * @throws \ReflectionException |
|
1046 | + */ |
|
1047 | + protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
|
1048 | + { |
|
1049 | + // let's examine the constructor |
|
1050 | + $constructor = $reflector->getConstructor(); |
|
1051 | + // whu? huh? nothing? |
|
1052 | + if ( ! $constructor) { |
|
1053 | + return $arguments; |
|
1054 | + } |
|
1055 | + // get constructor parameters |
|
1056 | + $params = $constructor->getParameters(); |
|
1057 | + // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
1058 | + $argument_keys = array_keys($arguments); |
|
1059 | + // now loop thru all of the constructors expected parameters |
|
1060 | + foreach ($params as $index => $param) { |
|
1061 | + // is this a dependency for a specific class ? |
|
1062 | + $param_class = $param->getClass() ? $param->getClass()->name : null; |
|
1063 | + // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime) |
|
1064 | + $param_class = $this->_dependency_map->has_alias($param_class, $class_name) |
|
1065 | + ? $this->_dependency_map->get_alias($param_class, $class_name) |
|
1066 | + : $param_class; |
|
1067 | + if ( |
|
1068 | + // param is not even a class |
|
1069 | + empty($param_class) |
|
1070 | + // and something already exists in the incoming arguments for this param |
|
1071 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
1072 | + ) { |
|
1073 | + // so let's skip this argument and move on to the next |
|
1074 | + continue; |
|
1075 | + } |
|
1076 | + if ( |
|
1077 | + // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
1078 | + ! empty($param_class) |
|
1079 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
1080 | + && $arguments[$argument_keys[$index]] instanceof $param_class |
|
1081 | + ) { |
|
1082 | + // skip this argument and move on to the next |
|
1083 | + continue; |
|
1084 | + } |
|
1085 | + if ( |
|
1086 | + // parameter is type hinted as a class, and should be injected |
|
1087 | + ! empty($param_class) |
|
1088 | + && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
1089 | + ) { |
|
1090 | + $arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index); |
|
1091 | + } else { |
|
1092 | + try { |
|
1093 | + $arguments[$index] = $param->getDefaultValue(); |
|
1094 | + } catch (ReflectionException $e) { |
|
1095 | + throw new ReflectionException( |
|
1096 | + sprintf( |
|
1097 | + __('%1$s for parameter "$%2$s"', 'event_espresso'), |
|
1098 | + $e->getMessage(), |
|
1099 | + $param->getName() |
|
1100 | + ) |
|
1101 | + ); |
|
1102 | + } |
|
1103 | + } |
|
1104 | + } |
|
1105 | + return $arguments; |
|
1106 | + } |
|
1107 | + |
|
1108 | + |
|
1109 | + |
|
1110 | + /** |
|
1111 | + * @access protected |
|
1112 | + * @param string $class_name |
|
1113 | + * @param string $param_class |
|
1114 | + * @param array $arguments |
|
1115 | + * @param mixed $index |
|
1116 | + * @return array |
|
1117 | + */ |
|
1118 | + protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
|
1119 | + { |
|
1120 | + $dependency = null; |
|
1121 | + // should dependency be loaded from cache ? |
|
1122 | + $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class) |
|
1123 | + !== EE_Dependency_Map::load_new_object |
|
1124 | + ? true |
|
1125 | + : false; |
|
1126 | + // we might have a dependency... |
|
1127 | + // let's MAYBE try and find it in our cache if that's what's been requested |
|
1128 | + $cached_class = $cache_on ? $this->_get_cached_class($param_class) : null; |
|
1129 | + // and grab it if it exists |
|
1130 | + if ($cached_class instanceof $param_class) { |
|
1131 | + $dependency = $cached_class; |
|
1132 | + } else if ($param_class !== $class_name) { |
|
1133 | + // obtain the loader method from the dependency map |
|
1134 | + $loader = $this->_dependency_map->class_loader($param_class); |
|
1135 | + // is loader a custom closure ? |
|
1136 | + if ($loader instanceof Closure) { |
|
1137 | + $dependency = $loader(); |
|
1138 | + } else { |
|
1139 | + // set the cache on property for the recursive loading call |
|
1140 | + $this->_cache_on = $cache_on; |
|
1141 | + // if not, then let's try and load it via the registry |
|
1142 | + if ($loader && method_exists($this, $loader)) { |
|
1143 | + $dependency = $this->{$loader}($param_class); |
|
1144 | + } else { |
|
1145 | + $dependency = $this->create($param_class, array(), $cache_on); |
|
1146 | + } |
|
1147 | + } |
|
1148 | + } |
|
1149 | + // did we successfully find the correct dependency ? |
|
1150 | + if ($dependency instanceof $param_class) { |
|
1151 | + // then let's inject it into the incoming array of arguments at the correct location |
|
1152 | + if (isset($argument_keys[$index])) { |
|
1153 | + $arguments[$argument_keys[$index]] = $dependency; |
|
1154 | + } else { |
|
1155 | + $arguments[$index] = $dependency; |
|
1156 | + } |
|
1157 | + } |
|
1158 | + return $arguments; |
|
1159 | + } |
|
1160 | + |
|
1161 | + |
|
1162 | + |
|
1163 | + /** |
|
1164 | + * _set_cached_class |
|
1165 | + * attempts to cache the instantiated class locally |
|
1166 | + * in one of the following places, in the following order: |
|
1167 | + * $this->{class_abbreviation} ie: $this->CART |
|
1168 | + * $this->{$class_name} ie: $this->Some_Class |
|
1169 | + * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
1170 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
1171 | + * |
|
1172 | + * @access protected |
|
1173 | + * @param object $class_obj |
|
1174 | + * @param string $class_name |
|
1175 | + * @param string $class_prefix |
|
1176 | + * @param bool $from_db |
|
1177 | + * @return void |
|
1178 | + */ |
|
1179 | + protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
|
1180 | + { |
|
1181 | + if (empty($class_obj)) { |
|
1182 | + return; |
|
1183 | + } |
|
1184 | + // return newly instantiated class |
|
1185 | + if (isset($this->_class_abbreviations[$class_name])) { |
|
1186 | + $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
1187 | + $this->{$class_abbreviation} = $class_obj; |
|
1188 | + return; |
|
1189 | + } |
|
1190 | + $class_name = str_replace('\\', '_', $class_name); |
|
1191 | + if (property_exists($this, $class_name)) { |
|
1192 | + $this->{$class_name} = $class_obj; |
|
1193 | + return; |
|
1194 | + } |
|
1195 | + if ($class_prefix === 'addon') { |
|
1196 | + $this->addons->{$class_name} = $class_obj; |
|
1197 | + return; |
|
1198 | + } |
|
1199 | + if ( ! $from_db) { |
|
1200 | + $this->LIB->{$class_name} = $class_obj; |
|
1201 | + } |
|
1202 | + } |
|
1203 | + |
|
1204 | + |
|
1205 | + |
|
1206 | + /** |
|
1207 | + * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
1208 | + * |
|
1209 | + * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
1210 | + * in the EE_Dependency_Map::$_class_loaders array, |
|
1211 | + * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
1212 | + * @param array $arguments |
|
1213 | + * @return object |
|
1214 | + */ |
|
1215 | + public static function factory($classname, $arguments = array()) |
|
1216 | + { |
|
1217 | + $loader = self::instance()->_dependency_map->class_loader($classname); |
|
1218 | + if ($loader instanceof Closure) { |
|
1219 | + return $loader($arguments); |
|
1220 | + } |
|
1221 | + if (method_exists(EE_Registry::instance(), $loader)) { |
|
1222 | + return EE_Registry::instance()->{$loader}($classname, $arguments); |
|
1223 | + } |
|
1224 | + return null; |
|
1225 | + } |
|
1226 | + |
|
1227 | + |
|
1228 | + |
|
1229 | + /** |
|
1230 | + * Gets the addon by its name/slug (not classname. For that, just |
|
1231 | + * use the classname as the property name on EE_Config::instance()->addons) |
|
1232 | + * |
|
1233 | + * @param string $name |
|
1234 | + * @return EE_Addon |
|
1235 | + */ |
|
1236 | + public function get_addon_by_name($name) |
|
1237 | + { |
|
1238 | + foreach ($this->addons as $addon) { |
|
1239 | + if ($addon->name() == $name) { |
|
1240 | + return $addon; |
|
1241 | + } |
|
1242 | + } |
|
1243 | + return null; |
|
1244 | + } |
|
1245 | + |
|
1246 | + |
|
1247 | + |
|
1248 | + /** |
|
1249 | + * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their name() function) They're already available on EE_Config::instance()->addons as properties, where each property's name is |
|
1250 | + * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname} |
|
1251 | + * |
|
1252 | + * @return EE_Addon[] where the KEYS are the addon's name() |
|
1253 | + */ |
|
1254 | + public function get_addons_by_name() |
|
1255 | + { |
|
1256 | + $addons = array(); |
|
1257 | + foreach ($this->addons as $addon) { |
|
1258 | + $addons[$addon->name()] = $addon; |
|
1259 | + } |
|
1260 | + return $addons; |
|
1261 | + } |
|
1262 | + |
|
1263 | + |
|
1264 | + |
|
1265 | + /** |
|
1266 | + * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
1267 | + * a stale copy of it around |
|
1268 | + * |
|
1269 | + * @param string $model_name |
|
1270 | + * @return \EEM_Base |
|
1271 | + * @throws \EE_Error |
|
1272 | + */ |
|
1273 | + public function reset_model($model_name) |
|
1274 | + { |
|
1275 | + $model_class_name = strpos($model_name, 'EEM_') !== 0 ? "EEM_{$model_name}" : $model_name; |
|
1276 | + if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
1277 | + return null; |
|
1278 | + } |
|
1279 | + //get that model reset it and make sure we nuke the old reference to it |
|
1280 | + if ($this->LIB->{$model_class_name} instanceof $model_class_name && is_callable(array($model_class_name, 'reset'))) { |
|
1281 | + $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
1282 | + } else { |
|
1283 | + throw new EE_Error(sprintf(__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
1284 | + } |
|
1285 | + return $this->LIB->{$model_class_name}; |
|
1286 | + } |
|
1287 | + |
|
1288 | + |
|
1289 | + |
|
1290 | + /** |
|
1291 | + * Resets the registry. |
|
1292 | + * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog |
|
1293 | + * is used in a multisite install. Here is a list of things that are NOT reset. |
|
1294 | + * - $_dependency_map |
|
1295 | + * - $_class_abbreviations |
|
1296 | + * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
1297 | + * - $REQ: Still on the same request so no need to change. |
|
1298 | + * - $CAP: There is no site specific state in the EE_Capability class. |
|
1299 | + * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session |
|
1300 | + * can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
1301 | + * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
1302 | + * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
1303 | + * switch or on the restore. |
|
1304 | + * - $modules |
|
1305 | + * - $shortcodes |
|
1306 | + * - $widgets |
|
1307 | + * |
|
1308 | + * @param boolean $hard whether to reset data in the database too, or just refresh |
|
1309 | + * the Registry to its state at the beginning of the request |
|
1310 | + * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
1311 | + * or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN |
|
1312 | + * currently reinstantiate the singletons at the moment) |
|
1313 | + * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so client |
|
1314 | + * code instead can just change the model context to a different blog id if necessary |
|
1315 | + * @return EE_Registry |
|
1316 | + */ |
|
1317 | + public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
1318 | + { |
|
1319 | + $instance = self::instance(); |
|
1320 | + EEH_Activation::reset(); |
|
1321 | + //properties that get reset |
|
1322 | + $instance->_cache_on = true; |
|
1323 | + $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
1324 | + $instance->CART = null; |
|
1325 | + $instance->MRM = null; |
|
1326 | + $instance->AssetsRegistry = null; |
|
1327 | + $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry'); |
|
1328 | + //messages reset |
|
1329 | + EED_Messages::reset(); |
|
1330 | + if ($reset_models) { |
|
1331 | + foreach (array_keys($instance->non_abstract_db_models) as $model_name) { |
|
1332 | + $instance->reset_model($model_name); |
|
1333 | + } |
|
1334 | + } |
|
1335 | + $instance->LIB = new stdClass(); |
|
1336 | + return $instance; |
|
1337 | + } |
|
1338 | + |
|
1339 | + |
|
1340 | + |
|
1341 | + /** |
|
1342 | + * @override magic methods |
|
1343 | + * @return void |
|
1344 | + */ |
|
1345 | + public final function __destruct() |
|
1346 | + { |
|
1347 | + } |
|
1348 | + |
|
1349 | + |
|
1350 | + |
|
1351 | + /** |
|
1352 | + * @param $a |
|
1353 | + * @param $b |
|
1354 | + */ |
|
1355 | + public final function __call($a, $b) |
|
1356 | + { |
|
1357 | + } |
|
1358 | + |
|
1359 | + |
|
1360 | + |
|
1361 | + /** |
|
1362 | + * @param $a |
|
1363 | + */ |
|
1364 | + public final function __get($a) |
|
1365 | + { |
|
1366 | + } |
|
1367 | + |
|
1368 | + |
|
1369 | + |
|
1370 | + /** |
|
1371 | + * @param $a |
|
1372 | + * @param $b |
|
1373 | + */ |
|
1374 | + public final function __set($a, $b) |
|
1375 | + { |
|
1376 | + } |
|
1377 | + |
|
1378 | + |
|
1379 | + |
|
1380 | + /** |
|
1381 | + * @param $a |
|
1382 | + */ |
|
1383 | + public final function __isset($a) |
|
1384 | + { |
|
1385 | + } |
|
1386 | 1386 | |
1387 | 1387 | |
1388 | 1388 | |
1389 | - /** |
|
1390 | - * @param $a |
|
1391 | - */ |
|
1392 | - public final function __unset($a) |
|
1393 | - { |
|
1394 | - } |
|
1389 | + /** |
|
1390 | + * @param $a |
|
1391 | + */ |
|
1392 | + public final function __unset($a) |
|
1393 | + { |
|
1394 | + } |
|
1395 | 1395 | |
1396 | 1396 | |
1397 | 1397 | |
1398 | - /** |
|
1399 | - * @return array |
|
1400 | - */ |
|
1401 | - public final function __sleep() |
|
1402 | - { |
|
1403 | - return array(); |
|
1404 | - } |
|
1398 | + /** |
|
1399 | + * @return array |
|
1400 | + */ |
|
1401 | + public final function __sleep() |
|
1402 | + { |
|
1403 | + return array(); |
|
1404 | + } |
|
1405 | 1405 | |
1406 | 1406 | |
1407 | 1407 | |
1408 | - public final function __wakeup() |
|
1409 | - { |
|
1410 | - } |
|
1408 | + public final function __wakeup() |
|
1409 | + { |
|
1410 | + } |
|
1411 | 1411 | |
1412 | 1412 | |
1413 | 1413 | |
1414 | - /** |
|
1415 | - * @return string |
|
1416 | - */ |
|
1417 | - public final function __toString() |
|
1418 | - { |
|
1419 | - return ''; |
|
1420 | - } |
|
1414 | + /** |
|
1415 | + * @return string |
|
1416 | + */ |
|
1417 | + public final function __toString() |
|
1418 | + { |
|
1419 | + return ''; |
|
1420 | + } |
|
1421 | 1421 | |
1422 | 1422 | |
1423 | 1423 | |
1424 | - public final function __invoke() |
|
1425 | - { |
|
1426 | - } |
|
1424 | + public final function __invoke() |
|
1425 | + { |
|
1426 | + } |
|
1427 | 1427 | |
1428 | 1428 | |
1429 | 1429 | |
1430 | - public final static function __set_state($array = array()) |
|
1431 | - { |
|
1432 | - return EE_Registry::instance(); |
|
1433 | - } |
|
1430 | + public final static function __set_state($array = array()) |
|
1431 | + { |
|
1432 | + return EE_Registry::instance(); |
|
1433 | + } |
|
1434 | 1434 | |
1435 | 1435 | |
1436 | 1436 | |
1437 | - public final function __clone() |
|
1438 | - { |
|
1439 | - } |
|
1437 | + public final function __clone() |
|
1438 | + { |
|
1439 | + } |
|
1440 | 1440 | |
1441 | 1441 | |
1442 | 1442 | |
1443 | - /** |
|
1444 | - * @param $a |
|
1445 | - * @param $b |
|
1446 | - */ |
|
1447 | - public final static function __callStatic($a, $b) |
|
1448 | - { |
|
1449 | - } |
|
1443 | + /** |
|
1444 | + * @param $a |
|
1445 | + * @param $b |
|
1446 | + */ |
|
1447 | + public final static function __callStatic($a, $b) |
|
1448 | + { |
|
1449 | + } |
|
1450 | 1450 | |
1451 | 1451 | |
1452 | 1452 | |
1453 | - /** |
|
1454 | - * Gets all the custom post type models defined |
|
1455 | - * |
|
1456 | - * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
1457 | - */ |
|
1458 | - public function cpt_models() |
|
1459 | - { |
|
1460 | - $cpt_models = array(); |
|
1461 | - foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
1462 | - if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
1463 | - $cpt_models[$short_name] = $classname; |
|
1464 | - } |
|
1465 | - } |
|
1466 | - return $cpt_models; |
|
1467 | - } |
|
1453 | + /** |
|
1454 | + * Gets all the custom post type models defined |
|
1455 | + * |
|
1456 | + * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
1457 | + */ |
|
1458 | + public function cpt_models() |
|
1459 | + { |
|
1460 | + $cpt_models = array(); |
|
1461 | + foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
1462 | + if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
1463 | + $cpt_models[$short_name] = $classname; |
|
1464 | + } |
|
1465 | + } |
|
1466 | + return $cpt_models; |
|
1467 | + } |
|
1468 | 1468 | |
1469 | 1469 | |
1470 | 1470 | |
1471 | - /** |
|
1472 | - * @return \EE_Config |
|
1473 | - */ |
|
1474 | - public static function CFG() |
|
1475 | - { |
|
1476 | - return self::instance()->CFG; |
|
1477 | - } |
|
1471 | + /** |
|
1472 | + * @return \EE_Config |
|
1473 | + */ |
|
1474 | + public static function CFG() |
|
1475 | + { |
|
1476 | + return self::instance()->CFG; |
|
1477 | + } |
|
1478 | 1478 | |
1479 | 1479 | |
1480 | 1480 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use EventEspresso\core\services\shortcodes\ShortcodesManager; |
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 | |
@@ -20,1098 +20,1098 @@ discard block |
||
20 | 20 | { |
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
25 | - * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
26 | - */ |
|
27 | - const req_type_normal = 0; |
|
28 | - |
|
29 | - /** |
|
30 | - * Indicates this is a brand new installation of EE so we should install |
|
31 | - * tables and default data etc |
|
32 | - */ |
|
33 | - const req_type_new_activation = 1; |
|
34 | - |
|
35 | - /** |
|
36 | - * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
37 | - * and we just exited maintenance mode). We MUST check the database is setup properly |
|
38 | - * and that default data is setup too |
|
39 | - */ |
|
40 | - const req_type_reactivation = 2; |
|
41 | - |
|
42 | - /** |
|
43 | - * indicates that EE has been upgraded since its previous request. |
|
44 | - * We may have data migration scripts to call and will want to trigger maintenance mode |
|
45 | - */ |
|
46 | - const req_type_upgrade = 3; |
|
47 | - |
|
48 | - /** |
|
49 | - * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
50 | - */ |
|
51 | - const req_type_downgrade = 4; |
|
52 | - |
|
53 | - /** |
|
54 | - * @deprecated since version 4.6.0.dev.006 |
|
55 | - * Now whenever a new_activation is detected the request type is still just |
|
56 | - * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
57 | - * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
58 | - * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
59 | - * (Specifically, when the migration manager indicates migrations are finished |
|
60 | - * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
61 | - */ |
|
62 | - const req_type_activation_but_not_installed = 5; |
|
63 | - |
|
64 | - /** |
|
65 | - * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
66 | - */ |
|
67 | - const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * @var EE_System $_instance |
|
72 | - */ |
|
73 | - private static $_instance; |
|
74 | - |
|
75 | - /** |
|
76 | - * @var EE_Registry $registry |
|
77 | - */ |
|
78 | - private $registry; |
|
79 | - |
|
80 | - /** |
|
81 | - * @var LoaderInterface $loader |
|
82 | - */ |
|
83 | - private $loader; |
|
84 | - |
|
85 | - /** |
|
86 | - * @var EE_Capabilities $capabilities |
|
87 | - */ |
|
88 | - private $capabilities; |
|
89 | - |
|
90 | - /** |
|
91 | - * @var EE_Request $request |
|
92 | - */ |
|
93 | - private $request; |
|
94 | - |
|
95 | - /** |
|
96 | - * @var EE_Maintenance_Mode $maintenance_mode |
|
97 | - */ |
|
98 | - private $maintenance_mode; |
|
99 | - |
|
100 | - /** |
|
101 | - * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
102 | - * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
103 | - * |
|
104 | - * @var int |
|
105 | - */ |
|
106 | - private $_req_type; |
|
107 | - |
|
108 | - /** |
|
109 | - * Whether or not there was a non-micro version change in EE core version during this request |
|
110 | - * |
|
111 | - * @var boolean |
|
112 | - */ |
|
113 | - private $_major_version_change = false; |
|
114 | - |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * @singleton method used to instantiate class object |
|
119 | - * @param EE_Registry|null $registry |
|
120 | - * @param LoaderInterface|null $loader |
|
121 | - * @param EE_Capabilities|null $capabilities |
|
122 | - * @param EE_Request|null $request |
|
123 | - * @param EE_Maintenance_Mode|null $maintenance_mode |
|
124 | - * @return EE_System |
|
125 | - */ |
|
126 | - public static function instance( |
|
127 | - EE_Registry $registry = null, |
|
128 | - LoaderInterface $loader = null, |
|
129 | - EE_Capabilities $capabilities = null, |
|
130 | - EE_Request $request = null, |
|
131 | - EE_Maintenance_Mode $maintenance_mode = null |
|
132 | - ) { |
|
133 | - // check if class object is instantiated |
|
134 | - if (! self::$_instance instanceof EE_System) { |
|
135 | - self::$_instance = new self($registry, $loader, $capabilities, $request, $maintenance_mode); |
|
136 | - } |
|
137 | - return self::$_instance; |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * resets the instance and returns it |
|
144 | - * |
|
145 | - * @return EE_System |
|
146 | - */ |
|
147 | - public static function reset() |
|
148 | - { |
|
149 | - self::$_instance->_req_type = null; |
|
150 | - //make sure none of the old hooks are left hanging around |
|
151 | - remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
152 | - //we need to reset the migration manager in order for it to detect DMSs properly |
|
153 | - EE_Data_Migration_Manager::reset(); |
|
154 | - self::instance()->detect_activations_or_upgrades(); |
|
155 | - self::instance()->perform_activations_upgrades_and_migrations(); |
|
156 | - return self::instance(); |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * sets hooks for running rest of system |
|
163 | - * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
164 | - * starting EE Addons from any other point may lead to problems |
|
165 | - * |
|
166 | - * @param EE_Registry $registry |
|
167 | - * @param LoaderInterface $loader |
|
168 | - * @param EE_Capabilities $capabilities |
|
169 | - * @param EE_Request $request |
|
170 | - * @param EE_Maintenance_Mode $maintenance_mode |
|
171 | - */ |
|
172 | - private function __construct( |
|
173 | - EE_Registry $registry, |
|
174 | - LoaderInterface $loader, |
|
175 | - EE_Capabilities $capabilities, |
|
176 | - EE_Request $request, |
|
177 | - EE_Maintenance_Mode $maintenance_mode |
|
178 | - ) { |
|
179 | - $this->registry = $registry; |
|
180 | - $this->loader = $loader; |
|
181 | - $this->capabilities = $capabilities; |
|
182 | - $this->request = $request; |
|
183 | - $this->maintenance_mode = $maintenance_mode; |
|
184 | - do_action('AHEE__EE_System__construct__begin', $this); |
|
185 | - // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
186 | - add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons')); |
|
187 | - // when an ee addon is activated, we want to call the core hook(s) again |
|
188 | - // because the newly-activated addon didn't get a chance to run at all |
|
189 | - add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
190 | - // detect whether install or upgrade |
|
191 | - add_action( |
|
192 | - 'AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'), |
|
193 | - 3 |
|
194 | - ); |
|
195 | - // load EE_Config, EE_Textdomain, etc |
|
196 | - add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5); |
|
197 | - // load EE_Config, EE_Textdomain, etc |
|
198 | - add_action( |
|
199 | - 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
200 | - array($this, 'register_shortcodes_modules_and_widgets'), 7 |
|
201 | - ); |
|
202 | - // you wanna get going? I wanna get going... let's get going! |
|
203 | - add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9); |
|
204 | - //other housekeeping |
|
205 | - //exclude EE critical pages from wp_list_pages |
|
206 | - add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10); |
|
207 | - // ALL EE Addons should use the following hook point to attach their initial setup too |
|
208 | - // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
209 | - do_action('AHEE__EE_System__construct__complete', $this); |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * load_espresso_addons |
|
216 | - * allow addons to load first so that they can set hooks for running DMS's, etc |
|
217 | - * this is hooked into both: |
|
218 | - * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
219 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
220 | - * and the WP 'activate_plugin' hook point |
|
221 | - * |
|
222 | - * @access public |
|
223 | - * @return void |
|
224 | - * @throws EE_Error |
|
225 | - */ |
|
226 | - public function load_espresso_addons() |
|
227 | - { |
|
228 | - // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
229 | - // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
230 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
231 | - //caps need to be initialized on every request so that capability maps are set. |
|
232 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
233 | - $this->capabilities->init_caps(); |
|
234 | - do_action('AHEE__EE_System__load_espresso_addons'); |
|
235 | - //if the WP API basic auth plugin isn't already loaded, load it now. |
|
236 | - //We want it for mobile apps. Just include the entire plugin |
|
237 | - //also, don't load the basic auth when a plugin is getting activated, because |
|
238 | - //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
239 | - //and causes a fatal error |
|
240 | - if ( |
|
241 | - ! ( |
|
242 | - isset($_GET['activate']) |
|
243 | - && $_GET['activate'] === 'true' |
|
244 | - ) |
|
245 | - && ! function_exists('json_basic_auth_handler') |
|
246 | - && ! function_exists('json_basic_auth_error') |
|
247 | - && ! ( |
|
248 | - isset($_GET['action']) |
|
249 | - && in_array($_GET['action'], array('activate', 'activate-selected'), true) |
|
250 | - ) |
|
251 | - ) { |
|
252 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
253 | - } |
|
254 | - do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - |
|
259 | - /** |
|
260 | - * detect_activations_or_upgrades |
|
261 | - * Checks for activation or upgrade of core first; |
|
262 | - * then also checks if any registered addons have been activated or upgraded |
|
263 | - * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
264 | - * which runs during the WP 'plugins_loaded' action at priority 3 |
|
265 | - * |
|
266 | - * @access public |
|
267 | - * @return void |
|
268 | - */ |
|
269 | - public function detect_activations_or_upgrades() |
|
270 | - { |
|
271 | - //first off: let's make sure to handle core |
|
272 | - $this->detect_if_activation_or_upgrade(); |
|
273 | - foreach (get_object_vars($this->registry->addons) as $addon) { |
|
274 | - if ($addon instanceof EE_Addon) { |
|
275 | - //detect teh request type for that addon |
|
276 | - $addon->detect_activation_or_upgrade(); |
|
277 | - } |
|
278 | - } |
|
279 | - } |
|
280 | - |
|
281 | - |
|
282 | - |
|
283 | - /** |
|
284 | - * detect_if_activation_or_upgrade |
|
285 | - * Takes care of detecting whether this is a brand new install or code upgrade, |
|
286 | - * and either setting up the DB or setting up maintenance mode etc. |
|
287 | - * |
|
288 | - * @access public |
|
289 | - * @return void |
|
290 | - */ |
|
291 | - public function detect_if_activation_or_upgrade() |
|
292 | - { |
|
293 | - do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
294 | - // check if db has been updated, or if its a brand-new installation |
|
295 | - $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
296 | - $request_type = $this->detect_req_type($espresso_db_update); |
|
297 | - //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
298 | - switch ($request_type) { |
|
299 | - case EE_System::req_type_new_activation: |
|
300 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
301 | - $this->_handle_core_version_change($espresso_db_update); |
|
302 | - break; |
|
303 | - case EE_System::req_type_reactivation: |
|
304 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
305 | - $this->_handle_core_version_change($espresso_db_update); |
|
306 | - break; |
|
307 | - case EE_System::req_type_upgrade: |
|
308 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
309 | - //migrations may be required now that we've upgraded |
|
310 | - $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
311 | - $this->_handle_core_version_change($espresso_db_update); |
|
312 | - // echo "done upgrade";die; |
|
313 | - break; |
|
314 | - case EE_System::req_type_downgrade: |
|
315 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
316 | - //its possible migrations are no longer required |
|
317 | - $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
318 | - $this->_handle_core_version_change($espresso_db_update); |
|
319 | - break; |
|
320 | - case EE_System::req_type_normal: |
|
321 | - default: |
|
322 | - // $this->_maybe_redirect_to_ee_about(); |
|
323 | - break; |
|
324 | - } |
|
325 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - |
|
330 | - /** |
|
331 | - * Updates the list of installed versions and sets hooks for |
|
332 | - * initializing the database later during the request |
|
333 | - * |
|
334 | - * @param array $espresso_db_update |
|
335 | - */ |
|
336 | - private function _handle_core_version_change($espresso_db_update) |
|
337 | - { |
|
338 | - $this->update_list_of_installed_versions($espresso_db_update); |
|
339 | - //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
340 | - add_action( |
|
341 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
342 | - array($this, 'initialize_db_if_no_migrations_required') |
|
343 | - ); |
|
344 | - } |
|
345 | - |
|
346 | - |
|
347 | - |
|
348 | - /** |
|
349 | - * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
350 | - * information about what versions of EE have been installed and activated, |
|
351 | - * NOT necessarily the state of the database |
|
352 | - * |
|
353 | - * @param null $espresso_db_update |
|
354 | - * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it |
|
355 | - * from the options table |
|
356 | - * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
357 | - */ |
|
358 | - private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
359 | - { |
|
360 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
361 | - if (! $espresso_db_update) { |
|
362 | - $espresso_db_update = get_option('espresso_db_update'); |
|
363 | - } |
|
364 | - // check that option is an array |
|
365 | - if (! is_array($espresso_db_update)) { |
|
366 | - // if option is FALSE, then it never existed |
|
367 | - if ($espresso_db_update === false) { |
|
368 | - // make $espresso_db_update an array and save option with autoload OFF |
|
369 | - $espresso_db_update = array(); |
|
370 | - add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
371 | - } else { |
|
372 | - // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
373 | - $espresso_db_update = array($espresso_db_update => array()); |
|
374 | - update_option('espresso_db_update', $espresso_db_update); |
|
375 | - } |
|
376 | - } else { |
|
377 | - $corrected_db_update = array(); |
|
378 | - //if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
379 | - foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
380 | - if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
381 | - //the key is an int, and the value IS NOT an array |
|
382 | - //so it must be numerically-indexed, where values are versions installed... |
|
383 | - //fix it! |
|
384 | - $version_string = $should_be_array; |
|
385 | - $corrected_db_update[ $version_string ] = array('unknown-date'); |
|
386 | - } else { |
|
387 | - //ok it checks out |
|
388 | - $corrected_db_update[ $should_be_version_string ] = $should_be_array; |
|
389 | - } |
|
390 | - } |
|
391 | - $espresso_db_update = $corrected_db_update; |
|
392 | - update_option('espresso_db_update', $espresso_db_update); |
|
393 | - } |
|
394 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
395 | - return $espresso_db_update; |
|
396 | - } |
|
397 | - |
|
398 | - |
|
399 | - |
|
400 | - /** |
|
401 | - * Does the traditional work of setting up the plugin's database and adding default data. |
|
402 | - * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
403 | - * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
404 | - * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
405 | - * so that it will be done when migrations are finished |
|
406 | - * |
|
407 | - * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
408 | - * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
409 | - * This is a resource-intensive job |
|
410 | - * so we prefer to only do it when necessary |
|
411 | - * @return void |
|
412 | - * @throws EE_Error |
|
413 | - */ |
|
414 | - public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
415 | - { |
|
416 | - $request_type = $this->detect_req_type(); |
|
417 | - //only initialize system if we're not in maintenance mode. |
|
418 | - if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
419 | - update_option('ee_flush_rewrite_rules', true); |
|
420 | - if ($verify_schema) { |
|
421 | - EEH_Activation::initialize_db_and_folders(); |
|
422 | - } |
|
423 | - EEH_Activation::initialize_db_content(); |
|
424 | - EEH_Activation::system_initialization(); |
|
425 | - if ($initialize_addons_too) { |
|
426 | - $this->initialize_addons(); |
|
427 | - } |
|
428 | - } else { |
|
429 | - EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
430 | - } |
|
431 | - if ($request_type === EE_System::req_type_new_activation |
|
432 | - || $request_type === EE_System::req_type_reactivation |
|
433 | - || ( |
|
434 | - $request_type === EE_System::req_type_upgrade |
|
435 | - && $this->is_major_version_change() |
|
436 | - ) |
|
437 | - ) { |
|
438 | - add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
439 | - } |
|
440 | - } |
|
441 | - |
|
442 | - |
|
443 | - |
|
444 | - /** |
|
445 | - * Initializes the db for all registered addons |
|
446 | - * |
|
447 | - * @throws EE_Error |
|
448 | - */ |
|
449 | - public function initialize_addons() |
|
450 | - { |
|
451 | - //foreach registered addon, make sure its db is up-to-date too |
|
452 | - foreach (get_object_vars($this->registry->addons) as $addon) { |
|
453 | - if($addon instanceof EE_Addon) { |
|
454 | - $addon->initialize_db_if_no_migrations_required(); |
|
455 | - } |
|
456 | - } |
|
457 | - } |
|
458 | - |
|
459 | - |
|
460 | - |
|
461 | - /** |
|
462 | - * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
463 | - * |
|
464 | - * @param array $version_history |
|
465 | - * @param string $current_version_to_add version to be added to the version history |
|
466 | - * @return boolean success as to whether or not this option was changed |
|
467 | - */ |
|
468 | - public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
469 | - { |
|
470 | - if (! $version_history) { |
|
471 | - $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
472 | - } |
|
473 | - if ($current_version_to_add === null) { |
|
474 | - $current_version_to_add = espresso_version(); |
|
475 | - } |
|
476 | - $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time()); |
|
477 | - // re-save |
|
478 | - return update_option('espresso_db_update', $version_history); |
|
479 | - } |
|
480 | - |
|
481 | - |
|
482 | - |
|
483 | - /** |
|
484 | - * Detects if the current version indicated in the has existed in the list of |
|
485 | - * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
486 | - * |
|
487 | - * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
488 | - * If not supplied, fetches it from the options table. |
|
489 | - * Also, caches its result so later parts of the code can also know whether |
|
490 | - * there's been an update or not. This way we can add the current version to |
|
491 | - * espresso_db_update, but still know if this is a new install or not |
|
492 | - * @return int one of the constants on EE_System::req_type_ |
|
493 | - */ |
|
494 | - public function detect_req_type($espresso_db_update = null) |
|
495 | - { |
|
496 | - if ($this->_req_type === null) { |
|
497 | - $espresso_db_update = ! empty($espresso_db_update) |
|
498 | - ? $espresso_db_update |
|
499 | - : $this->fix_espresso_db_upgrade_option(); |
|
500 | - $this->_req_type = self::detect_req_type_given_activation_history( |
|
501 | - $espresso_db_update, |
|
502 | - 'ee_espresso_activation', espresso_version() |
|
503 | - ); |
|
504 | - $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
505 | - } |
|
506 | - return $this->_req_type; |
|
507 | - } |
|
508 | - |
|
509 | - |
|
510 | - |
|
511 | - /** |
|
512 | - * Returns whether or not there was a non-micro version change (ie, change in either |
|
513 | - * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
514 | - * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
515 | - * |
|
516 | - * @param $activation_history |
|
517 | - * @return bool |
|
518 | - */ |
|
519 | - private function _detect_major_version_change($activation_history) |
|
520 | - { |
|
521 | - $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
522 | - $previous_version_parts = explode('.', $previous_version); |
|
523 | - $current_version_parts = explode('.', espresso_version()); |
|
524 | - return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
525 | - && ($previous_version_parts[0] !== $current_version_parts[0] |
|
526 | - || $previous_version_parts[1] !== $current_version_parts[1] |
|
527 | - ); |
|
528 | - } |
|
529 | - |
|
530 | - |
|
531 | - |
|
532 | - /** |
|
533 | - * Returns true if either the major or minor version of EE changed during this request. |
|
534 | - * 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 |
|
535 | - * |
|
536 | - * @return bool |
|
537 | - */ |
|
538 | - public function is_major_version_change() |
|
539 | - { |
|
540 | - return $this->_major_version_change; |
|
541 | - } |
|
542 | - |
|
543 | - |
|
544 | - |
|
545 | - /** |
|
546 | - * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
547 | - * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily |
|
548 | - * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
549 | - * just activated to (for core that will always be espresso_version()) |
|
550 | - * |
|
551 | - * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
552 | - * ee plugin. for core that's 'espresso_db_update' |
|
553 | - * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to |
|
554 | - * indicate that this plugin was just activated |
|
555 | - * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
556 | - * espresso_version()) |
|
557 | - * @return int one of the constants on EE_System::req_type_* |
|
558 | - */ |
|
559 | - public static function detect_req_type_given_activation_history( |
|
560 | - $activation_history_for_addon, |
|
561 | - $activation_indicator_option_name, |
|
562 | - $version_to_upgrade_to |
|
563 | - ) { |
|
564 | - $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
565 | - if ($activation_history_for_addon) { |
|
566 | - //it exists, so this isn't a completely new install |
|
567 | - //check if this version already in that list of previously installed versions |
|
568 | - if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) { |
|
569 | - //it a version we haven't seen before |
|
570 | - if ($version_is_higher === 1) { |
|
571 | - $req_type = EE_System::req_type_upgrade; |
|
572 | - } else { |
|
573 | - $req_type = EE_System::req_type_downgrade; |
|
574 | - } |
|
575 | - delete_option($activation_indicator_option_name); |
|
576 | - } else { |
|
577 | - // its not an update. maybe a reactivation? |
|
578 | - if (get_option($activation_indicator_option_name, false)) { |
|
579 | - if ($version_is_higher === -1) { |
|
580 | - $req_type = EE_System::req_type_downgrade; |
|
581 | - } else if ($version_is_higher === 0) { |
|
582 | - //we've seen this version before, but it's an activation. must be a reactivation |
|
583 | - $req_type = EE_System::req_type_reactivation; |
|
584 | - } else {//$version_is_higher === 1 |
|
585 | - $req_type = EE_System::req_type_upgrade; |
|
586 | - } |
|
587 | - delete_option($activation_indicator_option_name); |
|
588 | - } else { |
|
589 | - //we've seen this version before and the activation indicate doesn't show it was just activated |
|
590 | - if ($version_is_higher === -1) { |
|
591 | - $req_type = EE_System::req_type_downgrade; |
|
592 | - } else if ($version_is_higher === 0) { |
|
593 | - //we've seen this version before and it's not an activation. its normal request |
|
594 | - $req_type = EE_System::req_type_normal; |
|
595 | - } else {//$version_is_higher === 1 |
|
596 | - $req_type = EE_System::req_type_upgrade; |
|
597 | - } |
|
598 | - } |
|
599 | - } |
|
600 | - } else { |
|
601 | - //brand new install |
|
602 | - $req_type = EE_System::req_type_new_activation; |
|
603 | - delete_option($activation_indicator_option_name); |
|
604 | - } |
|
605 | - return $req_type; |
|
606 | - } |
|
607 | - |
|
608 | - |
|
609 | - |
|
610 | - /** |
|
611 | - * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
612 | - * the $activation_history_for_addon |
|
613 | - * |
|
614 | - * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
615 | - * sometimes containing 'unknown-date' |
|
616 | - * @param string $version_to_upgrade_to (current version) |
|
617 | - * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
618 | - * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
619 | - * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
620 | - * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
621 | - */ |
|
622 | - private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
623 | - { |
|
624 | - //find the most recently-activated version |
|
625 | - $most_recently_active_version = |
|
626 | - EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
627 | - return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
628 | - } |
|
629 | - |
|
630 | - |
|
631 | - |
|
632 | - /** |
|
633 | - * Gets the most recently active version listed in the activation history, |
|
634 | - * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
635 | - * |
|
636 | - * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
637 | - * sometimes containing 'unknown-date' |
|
638 | - * @return string |
|
639 | - */ |
|
640 | - private static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
641 | - { |
|
642 | - $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
643 | - $most_recently_active_version = '0.0.0.dev.000'; |
|
644 | - if (is_array($activation_history)) { |
|
645 | - foreach ($activation_history as $version => $times_activated) { |
|
646 | - //check there is a record of when this version was activated. Otherwise, |
|
647 | - //mark it as unknown |
|
648 | - if (! $times_activated) { |
|
649 | - $times_activated = array('unknown-date'); |
|
650 | - } |
|
651 | - if (is_string($times_activated)) { |
|
652 | - $times_activated = array($times_activated); |
|
653 | - } |
|
654 | - foreach ($times_activated as $an_activation) { |
|
655 | - if ($an_activation !== 'unknown-date' && $an_activation > $most_recently_active_version_activation) { |
|
656 | - $most_recently_active_version = $version; |
|
657 | - $most_recently_active_version_activation = $an_activation === 'unknown-date' |
|
658 | - ? '1970-01-01 00:00:00' |
|
659 | - : $an_activation; |
|
660 | - } |
|
661 | - } |
|
662 | - } |
|
663 | - } |
|
664 | - return $most_recently_active_version; |
|
665 | - } |
|
666 | - |
|
667 | - |
|
668 | - |
|
669 | - /** |
|
670 | - * This redirects to the about EE page after activation |
|
671 | - * |
|
672 | - * @return void |
|
673 | - */ |
|
674 | - public function redirect_to_about_ee() |
|
675 | - { |
|
676 | - $notices = EE_Error::get_notices(false); |
|
677 | - //if current user is an admin and it's not an ajax or rest request |
|
678 | - if ( |
|
679 | - ! (defined('DOING_AJAX') && DOING_AJAX) |
|
680 | - && ! (defined('REST_REQUEST') && REST_REQUEST) |
|
681 | - && ! isset($notices['errors']) |
|
682 | - && apply_filters( |
|
683 | - 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
684 | - $this->capabilities->current_user_can('manage_options', 'espresso_about_default') |
|
685 | - ) |
|
686 | - ) { |
|
687 | - $query_params = array('page' => 'espresso_about'); |
|
688 | - if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) { |
|
689 | - $query_params['new_activation'] = true; |
|
690 | - } |
|
691 | - if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) { |
|
692 | - $query_params['reactivation'] = true; |
|
693 | - } |
|
694 | - $url = add_query_arg($query_params, admin_url('admin.php')); |
|
695 | - wp_safe_redirect($url); |
|
696 | - exit(); |
|
697 | - } |
|
698 | - } |
|
699 | - |
|
700 | - |
|
701 | - |
|
702 | - /** |
|
703 | - * load_core_configuration |
|
704 | - * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
705 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
706 | - * |
|
707 | - * @return void |
|
708 | - * @throws ReflectionException |
|
709 | - */ |
|
710 | - public function load_core_configuration() |
|
711 | - { |
|
712 | - do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
713 | - $this->loader->getShared('EE_Load_Textdomain'); |
|
714 | - //load textdomain |
|
715 | - EE_Load_Textdomain::load_textdomain(); |
|
716 | - // load and setup EE_Config and EE_Network_Config |
|
717 | - $config = $this->loader->getShared('EE_Config'); |
|
718 | - $this->loader->getShared('EE_Network_Config'); |
|
719 | - // setup autoloaders |
|
720 | - // enable logging? |
|
721 | - if ($config->admin->use_full_logging) { |
|
722 | - $this->loader->getShared('EE_Log'); |
|
723 | - } |
|
724 | - // check for activation errors |
|
725 | - $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
726 | - if ($activation_errors) { |
|
727 | - EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
728 | - update_option('ee_plugin_activation_errors', false); |
|
729 | - } |
|
730 | - // get model names |
|
731 | - $this->_parse_model_names(); |
|
732 | - //load caf stuff a chance to play during the activation process too. |
|
733 | - $this->_maybe_brew_regular(); |
|
734 | - do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
735 | - } |
|
736 | - |
|
737 | - |
|
738 | - |
|
739 | - /** |
|
740 | - * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
741 | - * |
|
742 | - * @return void |
|
743 | - * @throws ReflectionException |
|
744 | - */ |
|
745 | - private function _parse_model_names() |
|
746 | - { |
|
747 | - //get all the files in the EE_MODELS folder that end in .model.php |
|
748 | - $models = glob(EE_MODELS . '*.model.php'); |
|
749 | - $model_names = array(); |
|
750 | - $non_abstract_db_models = array(); |
|
751 | - foreach ($models as $model) { |
|
752 | - // get model classname |
|
753 | - $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
754 | - $short_name = str_replace('EEM_', '', $classname); |
|
755 | - $reflectionClass = new ReflectionClass($classname); |
|
756 | - if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
757 | - $non_abstract_db_models[ $short_name ] = $classname; |
|
758 | - } |
|
759 | - $model_names[ $short_name ] = $classname; |
|
760 | - } |
|
761 | - $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
762 | - $this->registry->non_abstract_db_models = apply_filters( |
|
763 | - 'FHEE__EE_System__parse_implemented_model_names', |
|
764 | - $non_abstract_db_models |
|
765 | - ); |
|
766 | - } |
|
767 | - |
|
768 | - |
|
769 | - |
|
770 | - /** |
|
771 | - * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
772 | - * that need to be setup before our EE_System launches. |
|
773 | - * |
|
774 | - * @return void |
|
775 | - */ |
|
776 | - private function _maybe_brew_regular() |
|
777 | - { |
|
778 | - if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
779 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
780 | - } |
|
781 | - } |
|
782 | - |
|
783 | - |
|
784 | - |
|
785 | - /** |
|
786 | - * register_shortcodes_modules_and_widgets |
|
787 | - * generate lists of shortcodes and modules, then verify paths and classes |
|
788 | - * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
789 | - * which runs during the WP 'plugins_loaded' action at priority 7 |
|
790 | - * |
|
791 | - * @access public |
|
792 | - * @return void |
|
793 | - */ |
|
794 | - public function register_shortcodes_modules_and_widgets() |
|
795 | - { |
|
796 | - try { |
|
797 | - // load, register, and add shortcodes the new way |
|
798 | - new ShortcodesManager( |
|
799 | - // and the old way, but we'll put it under control of the new system |
|
800 | - EE_Config::getLegacyShortcodesManager() |
|
801 | - ); |
|
802 | - } catch (Exception $exception) { |
|
803 | - new ExceptionStackTraceDisplay($exception); |
|
804 | - } |
|
805 | - do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
806 | - // check for addons using old hookpoint |
|
807 | - if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
808 | - $this->_incompatible_addon_error(); |
|
809 | - } |
|
810 | - } |
|
811 | - |
|
812 | - |
|
813 | - |
|
814 | - /** |
|
815 | - * _incompatible_addon_error |
|
816 | - * |
|
817 | - * @access public |
|
818 | - * @return void |
|
819 | - */ |
|
820 | - private function _incompatible_addon_error() |
|
821 | - { |
|
822 | - // get array of classes hooking into here |
|
823 | - $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook( |
|
824 | - 'AHEE__EE_System__register_shortcodes_modules_and_addons' |
|
825 | - ); |
|
826 | - if (! empty($class_names)) { |
|
827 | - $msg = __( |
|
828 | - 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
829 | - 'event_espresso' |
|
830 | - ); |
|
831 | - $msg .= '<ul>'; |
|
832 | - foreach ($class_names as $class_name) { |
|
833 | - $msg .= '<li><b>Event Espresso - ' . str_replace( |
|
834 | - array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
835 | - $class_name |
|
836 | - ) . '</b></li>'; |
|
837 | - } |
|
838 | - $msg .= '</ul>'; |
|
839 | - $msg .= __( |
|
840 | - 'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
841 | - 'event_espresso' |
|
842 | - ); |
|
843 | - // save list of incompatible addons to wp-options for later use |
|
844 | - add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
845 | - if (is_admin()) { |
|
846 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
847 | - } |
|
848 | - } |
|
849 | - } |
|
850 | - |
|
851 | - |
|
852 | - |
|
853 | - /** |
|
854 | - * brew_espresso |
|
855 | - * begins the process of setting hooks for initializing EE in the correct order |
|
856 | - * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point |
|
857 | - * which runs during the WP 'plugins_loaded' action at priority 9 |
|
858 | - * |
|
859 | - * @return void |
|
860 | - */ |
|
861 | - public function brew_espresso() |
|
862 | - { |
|
863 | - do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
864 | - // load some final core systems |
|
865 | - add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
866 | - add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
867 | - add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
868 | - add_action('init', array($this, 'load_controllers'), 7); |
|
869 | - add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
870 | - add_action('init', array($this, 'initialize'), 10); |
|
871 | - add_action('init', array($this, 'initialize_last'), 100); |
|
872 | - if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
873 | - // pew pew pew |
|
874 | - $this->loader->getShared('EE_PUE'); |
|
875 | - do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
876 | - } |
|
877 | - do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
878 | - } |
|
879 | - |
|
880 | - |
|
881 | - |
|
882 | - /** |
|
883 | - * set_hooks_for_core |
|
884 | - * |
|
885 | - * @access public |
|
886 | - * @return void |
|
887 | - */ |
|
888 | - public function set_hooks_for_core() |
|
889 | - { |
|
890 | - $this->_deactivate_incompatible_addons(); |
|
891 | - do_action('AHEE__EE_System__set_hooks_for_core'); |
|
892 | - } |
|
893 | - |
|
894 | - |
|
895 | - |
|
896 | - /** |
|
897 | - * Using the information gathered in EE_System::_incompatible_addon_error, |
|
898 | - * deactivates any addons considered incompatible with the current version of EE |
|
899 | - */ |
|
900 | - private function _deactivate_incompatible_addons() |
|
901 | - { |
|
902 | - $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
903 | - if (! empty($incompatible_addons)) { |
|
904 | - $active_plugins = get_option('active_plugins', array()); |
|
905 | - foreach ($active_plugins as $active_plugin) { |
|
906 | - foreach ($incompatible_addons as $incompatible_addon) { |
|
907 | - if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
908 | - unset($_GET['activate']); |
|
909 | - espresso_deactivate_plugin($active_plugin); |
|
910 | - } |
|
911 | - } |
|
912 | - } |
|
913 | - } |
|
914 | - } |
|
915 | - |
|
916 | - |
|
917 | - |
|
918 | - /** |
|
919 | - * perform_activations_upgrades_and_migrations |
|
920 | - * |
|
921 | - * @access public |
|
922 | - * @return void |
|
923 | - */ |
|
924 | - public function perform_activations_upgrades_and_migrations() |
|
925 | - { |
|
926 | - //first check if we had previously attempted to setup EE's directories but failed |
|
927 | - if (EEH_Activation::upload_directories_incomplete()) { |
|
928 | - EEH_Activation::create_upload_directories(); |
|
929 | - } |
|
930 | - do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
931 | - } |
|
932 | - |
|
933 | - |
|
934 | - |
|
935 | - /** |
|
936 | - * load_CPTs_and_session |
|
937 | - * |
|
938 | - * @access public |
|
939 | - * @return void |
|
940 | - */ |
|
941 | - public function load_CPTs_and_session() |
|
942 | - { |
|
943 | - do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
944 | - // register Custom Post Types |
|
945 | - $this->loader->getShared('EE_Register_CPTs'); |
|
946 | - do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
947 | - } |
|
948 | - |
|
949 | - |
|
950 | - |
|
951 | - /** |
|
952 | - * load_controllers |
|
953 | - * this is the best place to load any additional controllers that needs access to EE core. |
|
954 | - * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
955 | - * time |
|
956 | - * |
|
957 | - * @access public |
|
958 | - * @return void |
|
959 | - */ |
|
960 | - public function load_controllers() |
|
961 | - { |
|
962 | - do_action('AHEE__EE_System__load_controllers__start'); |
|
963 | - // let's get it started |
|
964 | - if (! is_admin() && ! $this->maintenance_mode->level()) { |
|
965 | - do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
966 | - $this->loader->getShared('EE_Front_Controller'); |
|
967 | - } else if (! EE_FRONT_AJAX) { |
|
968 | - do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
969 | - $this->loader->getShared('EE_Admin'); |
|
970 | - } |
|
971 | - do_action('AHEE__EE_System__load_controllers__complete'); |
|
972 | - } |
|
973 | - |
|
974 | - |
|
975 | - |
|
976 | - /** |
|
977 | - * core_loaded_and_ready |
|
978 | - * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
979 | - * |
|
980 | - * @access public |
|
981 | - * @return void |
|
982 | - */ |
|
983 | - public function core_loaded_and_ready() |
|
984 | - { |
|
985 | - $this->registry->load_core('Session'); |
|
986 | - do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
987 | - // load_espresso_template_tags |
|
988 | - if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
989 | - require_once(EE_PUBLIC . 'template_tags.php'); |
|
990 | - } |
|
991 | - do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
992 | - $this->loader->getShared('EE_Session'); |
|
993 | - $this->loader->getShared('EventEspresso\core\services\assets\Registry'); |
|
994 | - wp_enqueue_script('espresso_core'); |
|
995 | - } |
|
996 | - |
|
997 | - |
|
998 | - |
|
999 | - /** |
|
1000 | - * initialize |
|
1001 | - * this is the best place to begin initializing client code |
|
1002 | - * |
|
1003 | - * @access public |
|
1004 | - * @return void |
|
1005 | - */ |
|
1006 | - public function initialize() |
|
1007 | - { |
|
1008 | - do_action('AHEE__EE_System__initialize'); |
|
1009 | - } |
|
1010 | - |
|
1011 | - |
|
1012 | - |
|
1013 | - /** |
|
1014 | - * initialize_last |
|
1015 | - * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to |
|
1016 | - * initialize has done so |
|
1017 | - * |
|
1018 | - * @access public |
|
1019 | - * @return void |
|
1020 | - */ |
|
1021 | - public function initialize_last() |
|
1022 | - { |
|
1023 | - do_action('AHEE__EE_System__initialize_last'); |
|
1024 | - add_action('admin_bar_init', array($this, 'addEspressoToolbar')); |
|
1025 | - } |
|
1026 | - |
|
1027 | - |
|
1028 | - |
|
1029 | - /** |
|
1030 | - * @return void |
|
1031 | - * @throws EE_Error |
|
1032 | - */ |
|
1033 | - public function addEspressoToolbar() |
|
1034 | - { |
|
1035 | - $this->registry->create( |
|
1036 | - 'EventEspresso\core\domain\services\admin\AdminToolBar', |
|
1037 | - array($this->registry->CAP) |
|
1038 | - ); |
|
1039 | - } |
|
1040 | - |
|
1041 | - |
|
1042 | - |
|
1043 | - /** |
|
1044 | - * do_not_cache |
|
1045 | - * sets no cache headers and defines no cache constants for WP plugins |
|
1046 | - * |
|
1047 | - * @access public |
|
1048 | - * @return void |
|
1049 | - */ |
|
1050 | - public static function do_not_cache() |
|
1051 | - { |
|
1052 | - // set no cache constants |
|
1053 | - if (! defined('DONOTCACHEPAGE')) { |
|
1054 | - define('DONOTCACHEPAGE', true); |
|
1055 | - } |
|
1056 | - if (! defined('DONOTCACHCEOBJECT')) { |
|
1057 | - define('DONOTCACHCEOBJECT', true); |
|
1058 | - } |
|
1059 | - if (! defined('DONOTCACHEDB')) { |
|
1060 | - define('DONOTCACHEDB', true); |
|
1061 | - } |
|
1062 | - // add no cache headers |
|
1063 | - add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
1064 | - // plus a little extra for nginx and Google Chrome |
|
1065 | - add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
1066 | - // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
1067 | - remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
1068 | - } |
|
1069 | - |
|
1070 | - |
|
1071 | - |
|
1072 | - /** |
|
1073 | - * extra_nocache_headers |
|
1074 | - * |
|
1075 | - * @access public |
|
1076 | - * @param $headers |
|
1077 | - * @return array |
|
1078 | - */ |
|
1079 | - public static function extra_nocache_headers($headers) |
|
1080 | - { |
|
1081 | - // for NGINX |
|
1082 | - $headers['X-Accel-Expires'] = 0; |
|
1083 | - // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
1084 | - $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
1085 | - return $headers; |
|
1086 | - } |
|
1087 | - |
|
1088 | - |
|
1089 | - |
|
1090 | - /** |
|
1091 | - * nocache_headers |
|
1092 | - * |
|
1093 | - * @access public |
|
1094 | - * @return void |
|
1095 | - */ |
|
1096 | - public static function nocache_headers() |
|
1097 | - { |
|
1098 | - nocache_headers(); |
|
1099 | - } |
|
1100 | - |
|
1101 | - |
|
1102 | - |
|
1103 | - |
|
1104 | - /** |
|
1105 | - * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
1106 | - * never returned with the function. |
|
1107 | - * |
|
1108 | - * @param array $exclude_array any existing pages being excluded are in this array. |
|
1109 | - * @return array |
|
1110 | - */ |
|
1111 | - public function remove_pages_from_wp_list_pages($exclude_array) |
|
1112 | - { |
|
1113 | - return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
1114 | - } |
|
23 | + /** |
|
24 | + * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
25 | + * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
26 | + */ |
|
27 | + const req_type_normal = 0; |
|
28 | + |
|
29 | + /** |
|
30 | + * Indicates this is a brand new installation of EE so we should install |
|
31 | + * tables and default data etc |
|
32 | + */ |
|
33 | + const req_type_new_activation = 1; |
|
34 | + |
|
35 | + /** |
|
36 | + * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
37 | + * and we just exited maintenance mode). We MUST check the database is setup properly |
|
38 | + * and that default data is setup too |
|
39 | + */ |
|
40 | + const req_type_reactivation = 2; |
|
41 | + |
|
42 | + /** |
|
43 | + * indicates that EE has been upgraded since its previous request. |
|
44 | + * We may have data migration scripts to call and will want to trigger maintenance mode |
|
45 | + */ |
|
46 | + const req_type_upgrade = 3; |
|
47 | + |
|
48 | + /** |
|
49 | + * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
50 | + */ |
|
51 | + const req_type_downgrade = 4; |
|
52 | + |
|
53 | + /** |
|
54 | + * @deprecated since version 4.6.0.dev.006 |
|
55 | + * Now whenever a new_activation is detected the request type is still just |
|
56 | + * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
57 | + * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
58 | + * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
59 | + * (Specifically, when the migration manager indicates migrations are finished |
|
60 | + * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
61 | + */ |
|
62 | + const req_type_activation_but_not_installed = 5; |
|
63 | + |
|
64 | + /** |
|
65 | + * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
66 | + */ |
|
67 | + const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * @var EE_System $_instance |
|
72 | + */ |
|
73 | + private static $_instance; |
|
74 | + |
|
75 | + /** |
|
76 | + * @var EE_Registry $registry |
|
77 | + */ |
|
78 | + private $registry; |
|
79 | + |
|
80 | + /** |
|
81 | + * @var LoaderInterface $loader |
|
82 | + */ |
|
83 | + private $loader; |
|
84 | + |
|
85 | + /** |
|
86 | + * @var EE_Capabilities $capabilities |
|
87 | + */ |
|
88 | + private $capabilities; |
|
89 | + |
|
90 | + /** |
|
91 | + * @var EE_Request $request |
|
92 | + */ |
|
93 | + private $request; |
|
94 | + |
|
95 | + /** |
|
96 | + * @var EE_Maintenance_Mode $maintenance_mode |
|
97 | + */ |
|
98 | + private $maintenance_mode; |
|
99 | + |
|
100 | + /** |
|
101 | + * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
102 | + * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
103 | + * |
|
104 | + * @var int |
|
105 | + */ |
|
106 | + private $_req_type; |
|
107 | + |
|
108 | + /** |
|
109 | + * Whether or not there was a non-micro version change in EE core version during this request |
|
110 | + * |
|
111 | + * @var boolean |
|
112 | + */ |
|
113 | + private $_major_version_change = false; |
|
114 | + |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * @singleton method used to instantiate class object |
|
119 | + * @param EE_Registry|null $registry |
|
120 | + * @param LoaderInterface|null $loader |
|
121 | + * @param EE_Capabilities|null $capabilities |
|
122 | + * @param EE_Request|null $request |
|
123 | + * @param EE_Maintenance_Mode|null $maintenance_mode |
|
124 | + * @return EE_System |
|
125 | + */ |
|
126 | + public static function instance( |
|
127 | + EE_Registry $registry = null, |
|
128 | + LoaderInterface $loader = null, |
|
129 | + EE_Capabilities $capabilities = null, |
|
130 | + EE_Request $request = null, |
|
131 | + EE_Maintenance_Mode $maintenance_mode = null |
|
132 | + ) { |
|
133 | + // check if class object is instantiated |
|
134 | + if (! self::$_instance instanceof EE_System) { |
|
135 | + self::$_instance = new self($registry, $loader, $capabilities, $request, $maintenance_mode); |
|
136 | + } |
|
137 | + return self::$_instance; |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * resets the instance and returns it |
|
144 | + * |
|
145 | + * @return EE_System |
|
146 | + */ |
|
147 | + public static function reset() |
|
148 | + { |
|
149 | + self::$_instance->_req_type = null; |
|
150 | + //make sure none of the old hooks are left hanging around |
|
151 | + remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
152 | + //we need to reset the migration manager in order for it to detect DMSs properly |
|
153 | + EE_Data_Migration_Manager::reset(); |
|
154 | + self::instance()->detect_activations_or_upgrades(); |
|
155 | + self::instance()->perform_activations_upgrades_and_migrations(); |
|
156 | + return self::instance(); |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * sets hooks for running rest of system |
|
163 | + * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
164 | + * starting EE Addons from any other point may lead to problems |
|
165 | + * |
|
166 | + * @param EE_Registry $registry |
|
167 | + * @param LoaderInterface $loader |
|
168 | + * @param EE_Capabilities $capabilities |
|
169 | + * @param EE_Request $request |
|
170 | + * @param EE_Maintenance_Mode $maintenance_mode |
|
171 | + */ |
|
172 | + private function __construct( |
|
173 | + EE_Registry $registry, |
|
174 | + LoaderInterface $loader, |
|
175 | + EE_Capabilities $capabilities, |
|
176 | + EE_Request $request, |
|
177 | + EE_Maintenance_Mode $maintenance_mode |
|
178 | + ) { |
|
179 | + $this->registry = $registry; |
|
180 | + $this->loader = $loader; |
|
181 | + $this->capabilities = $capabilities; |
|
182 | + $this->request = $request; |
|
183 | + $this->maintenance_mode = $maintenance_mode; |
|
184 | + do_action('AHEE__EE_System__construct__begin', $this); |
|
185 | + // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
186 | + add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons')); |
|
187 | + // when an ee addon is activated, we want to call the core hook(s) again |
|
188 | + // because the newly-activated addon didn't get a chance to run at all |
|
189 | + add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
190 | + // detect whether install or upgrade |
|
191 | + add_action( |
|
192 | + 'AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'), |
|
193 | + 3 |
|
194 | + ); |
|
195 | + // load EE_Config, EE_Textdomain, etc |
|
196 | + add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5); |
|
197 | + // load EE_Config, EE_Textdomain, etc |
|
198 | + add_action( |
|
199 | + 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
200 | + array($this, 'register_shortcodes_modules_and_widgets'), 7 |
|
201 | + ); |
|
202 | + // you wanna get going? I wanna get going... let's get going! |
|
203 | + add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9); |
|
204 | + //other housekeeping |
|
205 | + //exclude EE critical pages from wp_list_pages |
|
206 | + add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10); |
|
207 | + // ALL EE Addons should use the following hook point to attach their initial setup too |
|
208 | + // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
209 | + do_action('AHEE__EE_System__construct__complete', $this); |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * load_espresso_addons |
|
216 | + * allow addons to load first so that they can set hooks for running DMS's, etc |
|
217 | + * this is hooked into both: |
|
218 | + * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
219 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
220 | + * and the WP 'activate_plugin' hook point |
|
221 | + * |
|
222 | + * @access public |
|
223 | + * @return void |
|
224 | + * @throws EE_Error |
|
225 | + */ |
|
226 | + public function load_espresso_addons() |
|
227 | + { |
|
228 | + // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
229 | + // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
230 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
231 | + //caps need to be initialized on every request so that capability maps are set. |
|
232 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
233 | + $this->capabilities->init_caps(); |
|
234 | + do_action('AHEE__EE_System__load_espresso_addons'); |
|
235 | + //if the WP API basic auth plugin isn't already loaded, load it now. |
|
236 | + //We want it for mobile apps. Just include the entire plugin |
|
237 | + //also, don't load the basic auth when a plugin is getting activated, because |
|
238 | + //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
239 | + //and causes a fatal error |
|
240 | + if ( |
|
241 | + ! ( |
|
242 | + isset($_GET['activate']) |
|
243 | + && $_GET['activate'] === 'true' |
|
244 | + ) |
|
245 | + && ! function_exists('json_basic_auth_handler') |
|
246 | + && ! function_exists('json_basic_auth_error') |
|
247 | + && ! ( |
|
248 | + isset($_GET['action']) |
|
249 | + && in_array($_GET['action'], array('activate', 'activate-selected'), true) |
|
250 | + ) |
|
251 | + ) { |
|
252 | + include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
253 | + } |
|
254 | + do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + |
|
259 | + /** |
|
260 | + * detect_activations_or_upgrades |
|
261 | + * Checks for activation or upgrade of core first; |
|
262 | + * then also checks if any registered addons have been activated or upgraded |
|
263 | + * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
264 | + * which runs during the WP 'plugins_loaded' action at priority 3 |
|
265 | + * |
|
266 | + * @access public |
|
267 | + * @return void |
|
268 | + */ |
|
269 | + public function detect_activations_or_upgrades() |
|
270 | + { |
|
271 | + //first off: let's make sure to handle core |
|
272 | + $this->detect_if_activation_or_upgrade(); |
|
273 | + foreach (get_object_vars($this->registry->addons) as $addon) { |
|
274 | + if ($addon instanceof EE_Addon) { |
|
275 | + //detect teh request type for that addon |
|
276 | + $addon->detect_activation_or_upgrade(); |
|
277 | + } |
|
278 | + } |
|
279 | + } |
|
280 | + |
|
281 | + |
|
282 | + |
|
283 | + /** |
|
284 | + * detect_if_activation_or_upgrade |
|
285 | + * Takes care of detecting whether this is a brand new install or code upgrade, |
|
286 | + * and either setting up the DB or setting up maintenance mode etc. |
|
287 | + * |
|
288 | + * @access public |
|
289 | + * @return void |
|
290 | + */ |
|
291 | + public function detect_if_activation_or_upgrade() |
|
292 | + { |
|
293 | + do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
294 | + // check if db has been updated, or if its a brand-new installation |
|
295 | + $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
296 | + $request_type = $this->detect_req_type($espresso_db_update); |
|
297 | + //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
298 | + switch ($request_type) { |
|
299 | + case EE_System::req_type_new_activation: |
|
300 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
301 | + $this->_handle_core_version_change($espresso_db_update); |
|
302 | + break; |
|
303 | + case EE_System::req_type_reactivation: |
|
304 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
305 | + $this->_handle_core_version_change($espresso_db_update); |
|
306 | + break; |
|
307 | + case EE_System::req_type_upgrade: |
|
308 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
309 | + //migrations may be required now that we've upgraded |
|
310 | + $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
311 | + $this->_handle_core_version_change($espresso_db_update); |
|
312 | + // echo "done upgrade";die; |
|
313 | + break; |
|
314 | + case EE_System::req_type_downgrade: |
|
315 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
316 | + //its possible migrations are no longer required |
|
317 | + $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
318 | + $this->_handle_core_version_change($espresso_db_update); |
|
319 | + break; |
|
320 | + case EE_System::req_type_normal: |
|
321 | + default: |
|
322 | + // $this->_maybe_redirect_to_ee_about(); |
|
323 | + break; |
|
324 | + } |
|
325 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + |
|
330 | + /** |
|
331 | + * Updates the list of installed versions and sets hooks for |
|
332 | + * initializing the database later during the request |
|
333 | + * |
|
334 | + * @param array $espresso_db_update |
|
335 | + */ |
|
336 | + private function _handle_core_version_change($espresso_db_update) |
|
337 | + { |
|
338 | + $this->update_list_of_installed_versions($espresso_db_update); |
|
339 | + //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
340 | + add_action( |
|
341 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
342 | + array($this, 'initialize_db_if_no_migrations_required') |
|
343 | + ); |
|
344 | + } |
|
345 | + |
|
346 | + |
|
347 | + |
|
348 | + /** |
|
349 | + * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
350 | + * information about what versions of EE have been installed and activated, |
|
351 | + * NOT necessarily the state of the database |
|
352 | + * |
|
353 | + * @param null $espresso_db_update |
|
354 | + * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it |
|
355 | + * from the options table |
|
356 | + * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
357 | + */ |
|
358 | + private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
359 | + { |
|
360 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
361 | + if (! $espresso_db_update) { |
|
362 | + $espresso_db_update = get_option('espresso_db_update'); |
|
363 | + } |
|
364 | + // check that option is an array |
|
365 | + if (! is_array($espresso_db_update)) { |
|
366 | + // if option is FALSE, then it never existed |
|
367 | + if ($espresso_db_update === false) { |
|
368 | + // make $espresso_db_update an array and save option with autoload OFF |
|
369 | + $espresso_db_update = array(); |
|
370 | + add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
371 | + } else { |
|
372 | + // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
373 | + $espresso_db_update = array($espresso_db_update => array()); |
|
374 | + update_option('espresso_db_update', $espresso_db_update); |
|
375 | + } |
|
376 | + } else { |
|
377 | + $corrected_db_update = array(); |
|
378 | + //if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
379 | + foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
380 | + if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
381 | + //the key is an int, and the value IS NOT an array |
|
382 | + //so it must be numerically-indexed, where values are versions installed... |
|
383 | + //fix it! |
|
384 | + $version_string = $should_be_array; |
|
385 | + $corrected_db_update[ $version_string ] = array('unknown-date'); |
|
386 | + } else { |
|
387 | + //ok it checks out |
|
388 | + $corrected_db_update[ $should_be_version_string ] = $should_be_array; |
|
389 | + } |
|
390 | + } |
|
391 | + $espresso_db_update = $corrected_db_update; |
|
392 | + update_option('espresso_db_update', $espresso_db_update); |
|
393 | + } |
|
394 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
395 | + return $espresso_db_update; |
|
396 | + } |
|
397 | + |
|
398 | + |
|
399 | + |
|
400 | + /** |
|
401 | + * Does the traditional work of setting up the plugin's database and adding default data. |
|
402 | + * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
403 | + * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
404 | + * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
405 | + * so that it will be done when migrations are finished |
|
406 | + * |
|
407 | + * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
408 | + * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
409 | + * This is a resource-intensive job |
|
410 | + * so we prefer to only do it when necessary |
|
411 | + * @return void |
|
412 | + * @throws EE_Error |
|
413 | + */ |
|
414 | + public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
415 | + { |
|
416 | + $request_type = $this->detect_req_type(); |
|
417 | + //only initialize system if we're not in maintenance mode. |
|
418 | + if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
419 | + update_option('ee_flush_rewrite_rules', true); |
|
420 | + if ($verify_schema) { |
|
421 | + EEH_Activation::initialize_db_and_folders(); |
|
422 | + } |
|
423 | + EEH_Activation::initialize_db_content(); |
|
424 | + EEH_Activation::system_initialization(); |
|
425 | + if ($initialize_addons_too) { |
|
426 | + $this->initialize_addons(); |
|
427 | + } |
|
428 | + } else { |
|
429 | + EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
430 | + } |
|
431 | + if ($request_type === EE_System::req_type_new_activation |
|
432 | + || $request_type === EE_System::req_type_reactivation |
|
433 | + || ( |
|
434 | + $request_type === EE_System::req_type_upgrade |
|
435 | + && $this->is_major_version_change() |
|
436 | + ) |
|
437 | + ) { |
|
438 | + add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
439 | + } |
|
440 | + } |
|
441 | + |
|
442 | + |
|
443 | + |
|
444 | + /** |
|
445 | + * Initializes the db for all registered addons |
|
446 | + * |
|
447 | + * @throws EE_Error |
|
448 | + */ |
|
449 | + public function initialize_addons() |
|
450 | + { |
|
451 | + //foreach registered addon, make sure its db is up-to-date too |
|
452 | + foreach (get_object_vars($this->registry->addons) as $addon) { |
|
453 | + if($addon instanceof EE_Addon) { |
|
454 | + $addon->initialize_db_if_no_migrations_required(); |
|
455 | + } |
|
456 | + } |
|
457 | + } |
|
458 | + |
|
459 | + |
|
460 | + |
|
461 | + /** |
|
462 | + * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
463 | + * |
|
464 | + * @param array $version_history |
|
465 | + * @param string $current_version_to_add version to be added to the version history |
|
466 | + * @return boolean success as to whether or not this option was changed |
|
467 | + */ |
|
468 | + public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
469 | + { |
|
470 | + if (! $version_history) { |
|
471 | + $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
472 | + } |
|
473 | + if ($current_version_to_add === null) { |
|
474 | + $current_version_to_add = espresso_version(); |
|
475 | + } |
|
476 | + $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time()); |
|
477 | + // re-save |
|
478 | + return update_option('espresso_db_update', $version_history); |
|
479 | + } |
|
480 | + |
|
481 | + |
|
482 | + |
|
483 | + /** |
|
484 | + * Detects if the current version indicated in the has existed in the list of |
|
485 | + * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
486 | + * |
|
487 | + * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
488 | + * If not supplied, fetches it from the options table. |
|
489 | + * Also, caches its result so later parts of the code can also know whether |
|
490 | + * there's been an update or not. This way we can add the current version to |
|
491 | + * espresso_db_update, but still know if this is a new install or not |
|
492 | + * @return int one of the constants on EE_System::req_type_ |
|
493 | + */ |
|
494 | + public function detect_req_type($espresso_db_update = null) |
|
495 | + { |
|
496 | + if ($this->_req_type === null) { |
|
497 | + $espresso_db_update = ! empty($espresso_db_update) |
|
498 | + ? $espresso_db_update |
|
499 | + : $this->fix_espresso_db_upgrade_option(); |
|
500 | + $this->_req_type = self::detect_req_type_given_activation_history( |
|
501 | + $espresso_db_update, |
|
502 | + 'ee_espresso_activation', espresso_version() |
|
503 | + ); |
|
504 | + $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
505 | + } |
|
506 | + return $this->_req_type; |
|
507 | + } |
|
508 | + |
|
509 | + |
|
510 | + |
|
511 | + /** |
|
512 | + * Returns whether or not there was a non-micro version change (ie, change in either |
|
513 | + * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
514 | + * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
515 | + * |
|
516 | + * @param $activation_history |
|
517 | + * @return bool |
|
518 | + */ |
|
519 | + private function _detect_major_version_change($activation_history) |
|
520 | + { |
|
521 | + $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
522 | + $previous_version_parts = explode('.', $previous_version); |
|
523 | + $current_version_parts = explode('.', espresso_version()); |
|
524 | + return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
525 | + && ($previous_version_parts[0] !== $current_version_parts[0] |
|
526 | + || $previous_version_parts[1] !== $current_version_parts[1] |
|
527 | + ); |
|
528 | + } |
|
529 | + |
|
530 | + |
|
531 | + |
|
532 | + /** |
|
533 | + * Returns true if either the major or minor version of EE changed during this request. |
|
534 | + * 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 |
|
535 | + * |
|
536 | + * @return bool |
|
537 | + */ |
|
538 | + public function is_major_version_change() |
|
539 | + { |
|
540 | + return $this->_major_version_change; |
|
541 | + } |
|
542 | + |
|
543 | + |
|
544 | + |
|
545 | + /** |
|
546 | + * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
547 | + * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily |
|
548 | + * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
549 | + * just activated to (for core that will always be espresso_version()) |
|
550 | + * |
|
551 | + * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
552 | + * ee plugin. for core that's 'espresso_db_update' |
|
553 | + * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to |
|
554 | + * indicate that this plugin was just activated |
|
555 | + * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
556 | + * espresso_version()) |
|
557 | + * @return int one of the constants on EE_System::req_type_* |
|
558 | + */ |
|
559 | + public static function detect_req_type_given_activation_history( |
|
560 | + $activation_history_for_addon, |
|
561 | + $activation_indicator_option_name, |
|
562 | + $version_to_upgrade_to |
|
563 | + ) { |
|
564 | + $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
565 | + if ($activation_history_for_addon) { |
|
566 | + //it exists, so this isn't a completely new install |
|
567 | + //check if this version already in that list of previously installed versions |
|
568 | + if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) { |
|
569 | + //it a version we haven't seen before |
|
570 | + if ($version_is_higher === 1) { |
|
571 | + $req_type = EE_System::req_type_upgrade; |
|
572 | + } else { |
|
573 | + $req_type = EE_System::req_type_downgrade; |
|
574 | + } |
|
575 | + delete_option($activation_indicator_option_name); |
|
576 | + } else { |
|
577 | + // its not an update. maybe a reactivation? |
|
578 | + if (get_option($activation_indicator_option_name, false)) { |
|
579 | + if ($version_is_higher === -1) { |
|
580 | + $req_type = EE_System::req_type_downgrade; |
|
581 | + } else if ($version_is_higher === 0) { |
|
582 | + //we've seen this version before, but it's an activation. must be a reactivation |
|
583 | + $req_type = EE_System::req_type_reactivation; |
|
584 | + } else {//$version_is_higher === 1 |
|
585 | + $req_type = EE_System::req_type_upgrade; |
|
586 | + } |
|
587 | + delete_option($activation_indicator_option_name); |
|
588 | + } else { |
|
589 | + //we've seen this version before and the activation indicate doesn't show it was just activated |
|
590 | + if ($version_is_higher === -1) { |
|
591 | + $req_type = EE_System::req_type_downgrade; |
|
592 | + } else if ($version_is_higher === 0) { |
|
593 | + //we've seen this version before and it's not an activation. its normal request |
|
594 | + $req_type = EE_System::req_type_normal; |
|
595 | + } else {//$version_is_higher === 1 |
|
596 | + $req_type = EE_System::req_type_upgrade; |
|
597 | + } |
|
598 | + } |
|
599 | + } |
|
600 | + } else { |
|
601 | + //brand new install |
|
602 | + $req_type = EE_System::req_type_new_activation; |
|
603 | + delete_option($activation_indicator_option_name); |
|
604 | + } |
|
605 | + return $req_type; |
|
606 | + } |
|
607 | + |
|
608 | + |
|
609 | + |
|
610 | + /** |
|
611 | + * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
612 | + * the $activation_history_for_addon |
|
613 | + * |
|
614 | + * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
615 | + * sometimes containing 'unknown-date' |
|
616 | + * @param string $version_to_upgrade_to (current version) |
|
617 | + * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
618 | + * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
619 | + * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
620 | + * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
621 | + */ |
|
622 | + private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
623 | + { |
|
624 | + //find the most recently-activated version |
|
625 | + $most_recently_active_version = |
|
626 | + EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
627 | + return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
628 | + } |
|
629 | + |
|
630 | + |
|
631 | + |
|
632 | + /** |
|
633 | + * Gets the most recently active version listed in the activation history, |
|
634 | + * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
635 | + * |
|
636 | + * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
637 | + * sometimes containing 'unknown-date' |
|
638 | + * @return string |
|
639 | + */ |
|
640 | + private static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
641 | + { |
|
642 | + $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
643 | + $most_recently_active_version = '0.0.0.dev.000'; |
|
644 | + if (is_array($activation_history)) { |
|
645 | + foreach ($activation_history as $version => $times_activated) { |
|
646 | + //check there is a record of when this version was activated. Otherwise, |
|
647 | + //mark it as unknown |
|
648 | + if (! $times_activated) { |
|
649 | + $times_activated = array('unknown-date'); |
|
650 | + } |
|
651 | + if (is_string($times_activated)) { |
|
652 | + $times_activated = array($times_activated); |
|
653 | + } |
|
654 | + foreach ($times_activated as $an_activation) { |
|
655 | + if ($an_activation !== 'unknown-date' && $an_activation > $most_recently_active_version_activation) { |
|
656 | + $most_recently_active_version = $version; |
|
657 | + $most_recently_active_version_activation = $an_activation === 'unknown-date' |
|
658 | + ? '1970-01-01 00:00:00' |
|
659 | + : $an_activation; |
|
660 | + } |
|
661 | + } |
|
662 | + } |
|
663 | + } |
|
664 | + return $most_recently_active_version; |
|
665 | + } |
|
666 | + |
|
667 | + |
|
668 | + |
|
669 | + /** |
|
670 | + * This redirects to the about EE page after activation |
|
671 | + * |
|
672 | + * @return void |
|
673 | + */ |
|
674 | + public function redirect_to_about_ee() |
|
675 | + { |
|
676 | + $notices = EE_Error::get_notices(false); |
|
677 | + //if current user is an admin and it's not an ajax or rest request |
|
678 | + if ( |
|
679 | + ! (defined('DOING_AJAX') && DOING_AJAX) |
|
680 | + && ! (defined('REST_REQUEST') && REST_REQUEST) |
|
681 | + && ! isset($notices['errors']) |
|
682 | + && apply_filters( |
|
683 | + 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
684 | + $this->capabilities->current_user_can('manage_options', 'espresso_about_default') |
|
685 | + ) |
|
686 | + ) { |
|
687 | + $query_params = array('page' => 'espresso_about'); |
|
688 | + if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) { |
|
689 | + $query_params['new_activation'] = true; |
|
690 | + } |
|
691 | + if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) { |
|
692 | + $query_params['reactivation'] = true; |
|
693 | + } |
|
694 | + $url = add_query_arg($query_params, admin_url('admin.php')); |
|
695 | + wp_safe_redirect($url); |
|
696 | + exit(); |
|
697 | + } |
|
698 | + } |
|
699 | + |
|
700 | + |
|
701 | + |
|
702 | + /** |
|
703 | + * load_core_configuration |
|
704 | + * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
705 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
706 | + * |
|
707 | + * @return void |
|
708 | + * @throws ReflectionException |
|
709 | + */ |
|
710 | + public function load_core_configuration() |
|
711 | + { |
|
712 | + do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
713 | + $this->loader->getShared('EE_Load_Textdomain'); |
|
714 | + //load textdomain |
|
715 | + EE_Load_Textdomain::load_textdomain(); |
|
716 | + // load and setup EE_Config and EE_Network_Config |
|
717 | + $config = $this->loader->getShared('EE_Config'); |
|
718 | + $this->loader->getShared('EE_Network_Config'); |
|
719 | + // setup autoloaders |
|
720 | + // enable logging? |
|
721 | + if ($config->admin->use_full_logging) { |
|
722 | + $this->loader->getShared('EE_Log'); |
|
723 | + } |
|
724 | + // check for activation errors |
|
725 | + $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
726 | + if ($activation_errors) { |
|
727 | + EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
728 | + update_option('ee_plugin_activation_errors', false); |
|
729 | + } |
|
730 | + // get model names |
|
731 | + $this->_parse_model_names(); |
|
732 | + //load caf stuff a chance to play during the activation process too. |
|
733 | + $this->_maybe_brew_regular(); |
|
734 | + do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
735 | + } |
|
736 | + |
|
737 | + |
|
738 | + |
|
739 | + /** |
|
740 | + * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
741 | + * |
|
742 | + * @return void |
|
743 | + * @throws ReflectionException |
|
744 | + */ |
|
745 | + private function _parse_model_names() |
|
746 | + { |
|
747 | + //get all the files in the EE_MODELS folder that end in .model.php |
|
748 | + $models = glob(EE_MODELS . '*.model.php'); |
|
749 | + $model_names = array(); |
|
750 | + $non_abstract_db_models = array(); |
|
751 | + foreach ($models as $model) { |
|
752 | + // get model classname |
|
753 | + $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
754 | + $short_name = str_replace('EEM_', '', $classname); |
|
755 | + $reflectionClass = new ReflectionClass($classname); |
|
756 | + if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
757 | + $non_abstract_db_models[ $short_name ] = $classname; |
|
758 | + } |
|
759 | + $model_names[ $short_name ] = $classname; |
|
760 | + } |
|
761 | + $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
762 | + $this->registry->non_abstract_db_models = apply_filters( |
|
763 | + 'FHEE__EE_System__parse_implemented_model_names', |
|
764 | + $non_abstract_db_models |
|
765 | + ); |
|
766 | + } |
|
767 | + |
|
768 | + |
|
769 | + |
|
770 | + /** |
|
771 | + * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
772 | + * that need to be setup before our EE_System launches. |
|
773 | + * |
|
774 | + * @return void |
|
775 | + */ |
|
776 | + private function _maybe_brew_regular() |
|
777 | + { |
|
778 | + if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
779 | + require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
780 | + } |
|
781 | + } |
|
782 | + |
|
783 | + |
|
784 | + |
|
785 | + /** |
|
786 | + * register_shortcodes_modules_and_widgets |
|
787 | + * generate lists of shortcodes and modules, then verify paths and classes |
|
788 | + * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
789 | + * which runs during the WP 'plugins_loaded' action at priority 7 |
|
790 | + * |
|
791 | + * @access public |
|
792 | + * @return void |
|
793 | + */ |
|
794 | + public function register_shortcodes_modules_and_widgets() |
|
795 | + { |
|
796 | + try { |
|
797 | + // load, register, and add shortcodes the new way |
|
798 | + new ShortcodesManager( |
|
799 | + // and the old way, but we'll put it under control of the new system |
|
800 | + EE_Config::getLegacyShortcodesManager() |
|
801 | + ); |
|
802 | + } catch (Exception $exception) { |
|
803 | + new ExceptionStackTraceDisplay($exception); |
|
804 | + } |
|
805 | + do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
806 | + // check for addons using old hookpoint |
|
807 | + if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
808 | + $this->_incompatible_addon_error(); |
|
809 | + } |
|
810 | + } |
|
811 | + |
|
812 | + |
|
813 | + |
|
814 | + /** |
|
815 | + * _incompatible_addon_error |
|
816 | + * |
|
817 | + * @access public |
|
818 | + * @return void |
|
819 | + */ |
|
820 | + private function _incompatible_addon_error() |
|
821 | + { |
|
822 | + // get array of classes hooking into here |
|
823 | + $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook( |
|
824 | + 'AHEE__EE_System__register_shortcodes_modules_and_addons' |
|
825 | + ); |
|
826 | + if (! empty($class_names)) { |
|
827 | + $msg = __( |
|
828 | + 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
829 | + 'event_espresso' |
|
830 | + ); |
|
831 | + $msg .= '<ul>'; |
|
832 | + foreach ($class_names as $class_name) { |
|
833 | + $msg .= '<li><b>Event Espresso - ' . str_replace( |
|
834 | + array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
835 | + $class_name |
|
836 | + ) . '</b></li>'; |
|
837 | + } |
|
838 | + $msg .= '</ul>'; |
|
839 | + $msg .= __( |
|
840 | + 'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
841 | + 'event_espresso' |
|
842 | + ); |
|
843 | + // save list of incompatible addons to wp-options for later use |
|
844 | + add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
845 | + if (is_admin()) { |
|
846 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
847 | + } |
|
848 | + } |
|
849 | + } |
|
850 | + |
|
851 | + |
|
852 | + |
|
853 | + /** |
|
854 | + * brew_espresso |
|
855 | + * begins the process of setting hooks for initializing EE in the correct order |
|
856 | + * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point |
|
857 | + * which runs during the WP 'plugins_loaded' action at priority 9 |
|
858 | + * |
|
859 | + * @return void |
|
860 | + */ |
|
861 | + public function brew_espresso() |
|
862 | + { |
|
863 | + do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
864 | + // load some final core systems |
|
865 | + add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
866 | + add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
867 | + add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
868 | + add_action('init', array($this, 'load_controllers'), 7); |
|
869 | + add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
870 | + add_action('init', array($this, 'initialize'), 10); |
|
871 | + add_action('init', array($this, 'initialize_last'), 100); |
|
872 | + if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
873 | + // pew pew pew |
|
874 | + $this->loader->getShared('EE_PUE'); |
|
875 | + do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
876 | + } |
|
877 | + do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
878 | + } |
|
879 | + |
|
880 | + |
|
881 | + |
|
882 | + /** |
|
883 | + * set_hooks_for_core |
|
884 | + * |
|
885 | + * @access public |
|
886 | + * @return void |
|
887 | + */ |
|
888 | + public function set_hooks_for_core() |
|
889 | + { |
|
890 | + $this->_deactivate_incompatible_addons(); |
|
891 | + do_action('AHEE__EE_System__set_hooks_for_core'); |
|
892 | + } |
|
893 | + |
|
894 | + |
|
895 | + |
|
896 | + /** |
|
897 | + * Using the information gathered in EE_System::_incompatible_addon_error, |
|
898 | + * deactivates any addons considered incompatible with the current version of EE |
|
899 | + */ |
|
900 | + private function _deactivate_incompatible_addons() |
|
901 | + { |
|
902 | + $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
903 | + if (! empty($incompatible_addons)) { |
|
904 | + $active_plugins = get_option('active_plugins', array()); |
|
905 | + foreach ($active_plugins as $active_plugin) { |
|
906 | + foreach ($incompatible_addons as $incompatible_addon) { |
|
907 | + if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
908 | + unset($_GET['activate']); |
|
909 | + espresso_deactivate_plugin($active_plugin); |
|
910 | + } |
|
911 | + } |
|
912 | + } |
|
913 | + } |
|
914 | + } |
|
915 | + |
|
916 | + |
|
917 | + |
|
918 | + /** |
|
919 | + * perform_activations_upgrades_and_migrations |
|
920 | + * |
|
921 | + * @access public |
|
922 | + * @return void |
|
923 | + */ |
|
924 | + public function perform_activations_upgrades_and_migrations() |
|
925 | + { |
|
926 | + //first check if we had previously attempted to setup EE's directories but failed |
|
927 | + if (EEH_Activation::upload_directories_incomplete()) { |
|
928 | + EEH_Activation::create_upload_directories(); |
|
929 | + } |
|
930 | + do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
931 | + } |
|
932 | + |
|
933 | + |
|
934 | + |
|
935 | + /** |
|
936 | + * load_CPTs_and_session |
|
937 | + * |
|
938 | + * @access public |
|
939 | + * @return void |
|
940 | + */ |
|
941 | + public function load_CPTs_and_session() |
|
942 | + { |
|
943 | + do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
944 | + // register Custom Post Types |
|
945 | + $this->loader->getShared('EE_Register_CPTs'); |
|
946 | + do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
947 | + } |
|
948 | + |
|
949 | + |
|
950 | + |
|
951 | + /** |
|
952 | + * load_controllers |
|
953 | + * this is the best place to load any additional controllers that needs access to EE core. |
|
954 | + * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
955 | + * time |
|
956 | + * |
|
957 | + * @access public |
|
958 | + * @return void |
|
959 | + */ |
|
960 | + public function load_controllers() |
|
961 | + { |
|
962 | + do_action('AHEE__EE_System__load_controllers__start'); |
|
963 | + // let's get it started |
|
964 | + if (! is_admin() && ! $this->maintenance_mode->level()) { |
|
965 | + do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
966 | + $this->loader->getShared('EE_Front_Controller'); |
|
967 | + } else if (! EE_FRONT_AJAX) { |
|
968 | + do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
969 | + $this->loader->getShared('EE_Admin'); |
|
970 | + } |
|
971 | + do_action('AHEE__EE_System__load_controllers__complete'); |
|
972 | + } |
|
973 | + |
|
974 | + |
|
975 | + |
|
976 | + /** |
|
977 | + * core_loaded_and_ready |
|
978 | + * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
979 | + * |
|
980 | + * @access public |
|
981 | + * @return void |
|
982 | + */ |
|
983 | + public function core_loaded_and_ready() |
|
984 | + { |
|
985 | + $this->registry->load_core('Session'); |
|
986 | + do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
987 | + // load_espresso_template_tags |
|
988 | + if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
989 | + require_once(EE_PUBLIC . 'template_tags.php'); |
|
990 | + } |
|
991 | + do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
992 | + $this->loader->getShared('EE_Session'); |
|
993 | + $this->loader->getShared('EventEspresso\core\services\assets\Registry'); |
|
994 | + wp_enqueue_script('espresso_core'); |
|
995 | + } |
|
996 | + |
|
997 | + |
|
998 | + |
|
999 | + /** |
|
1000 | + * initialize |
|
1001 | + * this is the best place to begin initializing client code |
|
1002 | + * |
|
1003 | + * @access public |
|
1004 | + * @return void |
|
1005 | + */ |
|
1006 | + public function initialize() |
|
1007 | + { |
|
1008 | + do_action('AHEE__EE_System__initialize'); |
|
1009 | + } |
|
1010 | + |
|
1011 | + |
|
1012 | + |
|
1013 | + /** |
|
1014 | + * initialize_last |
|
1015 | + * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to |
|
1016 | + * initialize has done so |
|
1017 | + * |
|
1018 | + * @access public |
|
1019 | + * @return void |
|
1020 | + */ |
|
1021 | + public function initialize_last() |
|
1022 | + { |
|
1023 | + do_action('AHEE__EE_System__initialize_last'); |
|
1024 | + add_action('admin_bar_init', array($this, 'addEspressoToolbar')); |
|
1025 | + } |
|
1026 | + |
|
1027 | + |
|
1028 | + |
|
1029 | + /** |
|
1030 | + * @return void |
|
1031 | + * @throws EE_Error |
|
1032 | + */ |
|
1033 | + public function addEspressoToolbar() |
|
1034 | + { |
|
1035 | + $this->registry->create( |
|
1036 | + 'EventEspresso\core\domain\services\admin\AdminToolBar', |
|
1037 | + array($this->registry->CAP) |
|
1038 | + ); |
|
1039 | + } |
|
1040 | + |
|
1041 | + |
|
1042 | + |
|
1043 | + /** |
|
1044 | + * do_not_cache |
|
1045 | + * sets no cache headers and defines no cache constants for WP plugins |
|
1046 | + * |
|
1047 | + * @access public |
|
1048 | + * @return void |
|
1049 | + */ |
|
1050 | + public static function do_not_cache() |
|
1051 | + { |
|
1052 | + // set no cache constants |
|
1053 | + if (! defined('DONOTCACHEPAGE')) { |
|
1054 | + define('DONOTCACHEPAGE', true); |
|
1055 | + } |
|
1056 | + if (! defined('DONOTCACHCEOBJECT')) { |
|
1057 | + define('DONOTCACHCEOBJECT', true); |
|
1058 | + } |
|
1059 | + if (! defined('DONOTCACHEDB')) { |
|
1060 | + define('DONOTCACHEDB', true); |
|
1061 | + } |
|
1062 | + // add no cache headers |
|
1063 | + add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
1064 | + // plus a little extra for nginx and Google Chrome |
|
1065 | + add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
1066 | + // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
1067 | + remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
1068 | + } |
|
1069 | + |
|
1070 | + |
|
1071 | + |
|
1072 | + /** |
|
1073 | + * extra_nocache_headers |
|
1074 | + * |
|
1075 | + * @access public |
|
1076 | + * @param $headers |
|
1077 | + * @return array |
|
1078 | + */ |
|
1079 | + public static function extra_nocache_headers($headers) |
|
1080 | + { |
|
1081 | + // for NGINX |
|
1082 | + $headers['X-Accel-Expires'] = 0; |
|
1083 | + // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
1084 | + $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
1085 | + return $headers; |
|
1086 | + } |
|
1087 | + |
|
1088 | + |
|
1089 | + |
|
1090 | + /** |
|
1091 | + * nocache_headers |
|
1092 | + * |
|
1093 | + * @access public |
|
1094 | + * @return void |
|
1095 | + */ |
|
1096 | + public static function nocache_headers() |
|
1097 | + { |
|
1098 | + nocache_headers(); |
|
1099 | + } |
|
1100 | + |
|
1101 | + |
|
1102 | + |
|
1103 | + |
|
1104 | + /** |
|
1105 | + * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
1106 | + * never returned with the function. |
|
1107 | + * |
|
1108 | + * @param array $exclude_array any existing pages being excluded are in this array. |
|
1109 | + * @return array |
|
1110 | + */ |
|
1111 | + public function remove_pages_from_wp_list_pages($exclude_array) |
|
1112 | + { |
|
1113 | + return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
1114 | + } |
|
1115 | 1115 | |
1116 | 1116 | |
1117 | 1117 |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | use EventEspresso\core\services\loaders\LoaderInterface; |
4 | 4 | use EventEspresso\core\services\shortcodes\ShortcodesManager; |
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 | |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | EE_Maintenance_Mode $maintenance_mode = null |
132 | 132 | ) { |
133 | 133 | // check if class object is instantiated |
134 | - if (! self::$_instance instanceof EE_System) { |
|
134 | + if ( ! self::$_instance instanceof EE_System) { |
|
135 | 135 | self::$_instance = new self($registry, $loader, $capabilities, $request, $maintenance_mode); |
136 | 136 | } |
137 | 137 | return self::$_instance; |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | { |
228 | 228 | // set autoloaders for all of the classes implementing EEI_Plugin_API |
229 | 229 | // which provide helpers for EE plugin authors to more easily register certain components with EE. |
230 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
230 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api'); |
|
231 | 231 | //caps need to be initialized on every request so that capability maps are set. |
232 | 232 | //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
233 | 233 | $this->capabilities->init_caps(); |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | && in_array($_GET['action'], array('activate', 'activate-selected'), true) |
250 | 250 | ) |
251 | 251 | ) { |
252 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
252 | + include_once EE_THIRD_PARTY.'wp-api-basic-auth'.DS.'basic-auth.php'; |
|
253 | 253 | } |
254 | 254 | do_action('AHEE__EE_System__load_espresso_addons__complete'); |
255 | 255 | } |
@@ -358,11 +358,11 @@ discard block |
||
358 | 358 | private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
359 | 359 | { |
360 | 360 | do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
361 | - if (! $espresso_db_update) { |
|
361 | + if ( ! $espresso_db_update) { |
|
362 | 362 | $espresso_db_update = get_option('espresso_db_update'); |
363 | 363 | } |
364 | 364 | // check that option is an array |
365 | - if (! is_array($espresso_db_update)) { |
|
365 | + if ( ! is_array($espresso_db_update)) { |
|
366 | 366 | // if option is FALSE, then it never existed |
367 | 367 | if ($espresso_db_update === false) { |
368 | 368 | // make $espresso_db_update an array and save option with autoload OFF |
@@ -382,10 +382,10 @@ discard block |
||
382 | 382 | //so it must be numerically-indexed, where values are versions installed... |
383 | 383 | //fix it! |
384 | 384 | $version_string = $should_be_array; |
385 | - $corrected_db_update[ $version_string ] = array('unknown-date'); |
|
385 | + $corrected_db_update[$version_string] = array('unknown-date'); |
|
386 | 386 | } else { |
387 | 387 | //ok it checks out |
388 | - $corrected_db_update[ $should_be_version_string ] = $should_be_array; |
|
388 | + $corrected_db_update[$should_be_version_string] = $should_be_array; |
|
389 | 389 | } |
390 | 390 | } |
391 | 391 | $espresso_db_update = $corrected_db_update; |
@@ -450,7 +450,7 @@ discard block |
||
450 | 450 | { |
451 | 451 | //foreach registered addon, make sure its db is up-to-date too |
452 | 452 | foreach (get_object_vars($this->registry->addons) as $addon) { |
453 | - if($addon instanceof EE_Addon) { |
|
453 | + if ($addon instanceof EE_Addon) { |
|
454 | 454 | $addon->initialize_db_if_no_migrations_required(); |
455 | 455 | } |
456 | 456 | } |
@@ -467,13 +467,13 @@ discard block |
||
467 | 467 | */ |
468 | 468 | public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
469 | 469 | { |
470 | - if (! $version_history) { |
|
470 | + if ( ! $version_history) { |
|
471 | 471 | $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
472 | 472 | } |
473 | 473 | if ($current_version_to_add === null) { |
474 | 474 | $current_version_to_add = espresso_version(); |
475 | 475 | } |
476 | - $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time()); |
|
476 | + $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
477 | 477 | // re-save |
478 | 478 | return update_option('espresso_db_update', $version_history); |
479 | 479 | } |
@@ -565,7 +565,7 @@ discard block |
||
565 | 565 | if ($activation_history_for_addon) { |
566 | 566 | //it exists, so this isn't a completely new install |
567 | 567 | //check if this version already in that list of previously installed versions |
568 | - if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) { |
|
568 | + if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
569 | 569 | //it a version we haven't seen before |
570 | 570 | if ($version_is_higher === 1) { |
571 | 571 | $req_type = EE_System::req_type_upgrade; |
@@ -645,7 +645,7 @@ discard block |
||
645 | 645 | foreach ($activation_history as $version => $times_activated) { |
646 | 646 | //check there is a record of when this version was activated. Otherwise, |
647 | 647 | //mark it as unknown |
648 | - if (! $times_activated) { |
|
648 | + if ( ! $times_activated) { |
|
649 | 649 | $times_activated = array('unknown-date'); |
650 | 650 | } |
651 | 651 | if (is_string($times_activated)) { |
@@ -745,7 +745,7 @@ discard block |
||
745 | 745 | private function _parse_model_names() |
746 | 746 | { |
747 | 747 | //get all the files in the EE_MODELS folder that end in .model.php |
748 | - $models = glob(EE_MODELS . '*.model.php'); |
|
748 | + $models = glob(EE_MODELS.'*.model.php'); |
|
749 | 749 | $model_names = array(); |
750 | 750 | $non_abstract_db_models = array(); |
751 | 751 | foreach ($models as $model) { |
@@ -754,9 +754,9 @@ discard block |
||
754 | 754 | $short_name = str_replace('EEM_', '', $classname); |
755 | 755 | $reflectionClass = new ReflectionClass($classname); |
756 | 756 | if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
757 | - $non_abstract_db_models[ $short_name ] = $classname; |
|
757 | + $non_abstract_db_models[$short_name] = $classname; |
|
758 | 758 | } |
759 | - $model_names[ $short_name ] = $classname; |
|
759 | + $model_names[$short_name] = $classname; |
|
760 | 760 | } |
761 | 761 | $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
762 | 762 | $this->registry->non_abstract_db_models = apply_filters( |
@@ -775,8 +775,8 @@ discard block |
||
775 | 775 | */ |
776 | 776 | private function _maybe_brew_regular() |
777 | 777 | { |
778 | - if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
779 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
778 | + if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH.'brewing_regular.php')) { |
|
779 | + require_once EE_CAFF_PATH.'brewing_regular.php'; |
|
780 | 780 | } |
781 | 781 | } |
782 | 782 | |
@@ -823,17 +823,17 @@ discard block |
||
823 | 823 | $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook( |
824 | 824 | 'AHEE__EE_System__register_shortcodes_modules_and_addons' |
825 | 825 | ); |
826 | - if (! empty($class_names)) { |
|
826 | + if ( ! empty($class_names)) { |
|
827 | 827 | $msg = __( |
828 | 828 | 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
829 | 829 | 'event_espresso' |
830 | 830 | ); |
831 | 831 | $msg .= '<ul>'; |
832 | 832 | foreach ($class_names as $class_name) { |
833 | - $msg .= '<li><b>Event Espresso - ' . str_replace( |
|
833 | + $msg .= '<li><b>Event Espresso - '.str_replace( |
|
834 | 834 | array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
835 | 835 | $class_name |
836 | - ) . '</b></li>'; |
|
836 | + ).'</b></li>'; |
|
837 | 837 | } |
838 | 838 | $msg .= '</ul>'; |
839 | 839 | $msg .= __( |
@@ -900,7 +900,7 @@ discard block |
||
900 | 900 | private function _deactivate_incompatible_addons() |
901 | 901 | { |
902 | 902 | $incompatible_addons = get_option('ee_incompatible_addons', array()); |
903 | - if (! empty($incompatible_addons)) { |
|
903 | + if ( ! empty($incompatible_addons)) { |
|
904 | 904 | $active_plugins = get_option('active_plugins', array()); |
905 | 905 | foreach ($active_plugins as $active_plugin) { |
906 | 906 | foreach ($incompatible_addons as $incompatible_addon) { |
@@ -961,10 +961,10 @@ discard block |
||
961 | 961 | { |
962 | 962 | do_action('AHEE__EE_System__load_controllers__start'); |
963 | 963 | // let's get it started |
964 | - if (! is_admin() && ! $this->maintenance_mode->level()) { |
|
964 | + if ( ! is_admin() && ! $this->maintenance_mode->level()) { |
|
965 | 965 | do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
966 | 966 | $this->loader->getShared('EE_Front_Controller'); |
967 | - } else if (! EE_FRONT_AJAX) { |
|
967 | + } else if ( ! EE_FRONT_AJAX) { |
|
968 | 968 | do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
969 | 969 | $this->loader->getShared('EE_Admin'); |
970 | 970 | } |
@@ -985,8 +985,8 @@ discard block |
||
985 | 985 | $this->registry->load_core('Session'); |
986 | 986 | do_action('AHEE__EE_System__core_loaded_and_ready'); |
987 | 987 | // load_espresso_template_tags |
988 | - if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
989 | - require_once(EE_PUBLIC . 'template_tags.php'); |
|
988 | + if (is_readable(EE_PUBLIC.'template_tags.php')) { |
|
989 | + require_once(EE_PUBLIC.'template_tags.php'); |
|
990 | 990 | } |
991 | 991 | do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
992 | 992 | $this->loader->getShared('EE_Session'); |
@@ -1050,13 +1050,13 @@ discard block |
||
1050 | 1050 | public static function do_not_cache() |
1051 | 1051 | { |
1052 | 1052 | // set no cache constants |
1053 | - if (! defined('DONOTCACHEPAGE')) { |
|
1053 | + if ( ! defined('DONOTCACHEPAGE')) { |
|
1054 | 1054 | define('DONOTCACHEPAGE', true); |
1055 | 1055 | } |
1056 | - if (! defined('DONOTCACHCEOBJECT')) { |
|
1056 | + if ( ! defined('DONOTCACHCEOBJECT')) { |
|
1057 | 1057 | define('DONOTCACHCEOBJECT', true); |
1058 | 1058 | } |
1059 | - if (! defined('DONOTCACHEDB')) { |
|
1059 | + if ( ! defined('DONOTCACHEDB')) { |
|
1060 | 1060 | define('DONOTCACHEDB', true); |
1061 | 1061 | } |
1062 | 1062 | // add no cache headers |