@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | * Sets quantity |
| 173 | 173 | * @param int $quantity |
| 174 | 174 | */ |
| 175 | - public function set_quantity( $quantity ) { |
|
| 175 | + public function set_quantity( $quantity ) { |
|
| 176 | 176 | $this->set( 'LIN_quantity', max( $quantity, 0 ) ); |
| 177 | 177 | } |
| 178 | 178 | |
@@ -212,25 +212,25 @@ discard block |
||
| 212 | 212 | * Gets item_type |
| 213 | 213 | * @return string |
| 214 | 214 | */ |
| 215 | - public function OBJ_type_i18n() { |
|
| 216 | - $obj_type = $this->OBJ_type(); |
|
| 217 | - switch ($obj_type) { |
|
| 218 | - case 'Event': |
|
| 219 | - $obj_type = __('Event', 'event_espresso'); |
|
| 220 | - break; |
|
| 221 | - case 'Price': |
|
| 222 | - $obj_type = __('Price', 'event_espresso'); |
|
| 223 | - break; |
|
| 224 | - case 'Promotion': |
|
| 225 | - $obj_type = __('Promotion', 'event_espresso'); |
|
| 226 | - break; |
|
| 227 | - case 'Ticket': |
|
| 228 | - $obj_type = __('Ticket', 'event_espresso'); |
|
| 229 | - break; |
|
| 230 | - case 'Transaction': |
|
| 231 | - $obj_type = __('Transaction', 'event_espresso'); |
|
| 232 | - break; |
|
| 233 | - } |
|
| 215 | + public function OBJ_type_i18n() { |
|
| 216 | + $obj_type = $this->OBJ_type(); |
|
| 217 | + switch ($obj_type) { |
|
| 218 | + case 'Event': |
|
| 219 | + $obj_type = __('Event', 'event_espresso'); |
|
| 220 | + break; |
|
| 221 | + case 'Price': |
|
| 222 | + $obj_type = __('Price', 'event_espresso'); |
|
| 223 | + break; |
|
| 224 | + case 'Promotion': |
|
| 225 | + $obj_type = __('Promotion', 'event_espresso'); |
|
| 226 | + break; |
|
| 227 | + case 'Ticket': |
|
| 228 | + $obj_type = __('Ticket', 'event_espresso'); |
|
| 229 | + break; |
|
| 230 | + case 'Transaction': |
|
| 231 | + $obj_type = __('Transaction', 'event_espresso'); |
|
| 232 | + break; |
|
| 233 | + } |
|
| 234 | 234 | return apply_filters('FHEE__EE_Line_Item__OBJ_type_i18n', $obj_type, $this); |
| 235 | 235 | } |
| 236 | 236 | |
@@ -879,7 +879,7 @@ discard block |
||
| 879 | 879 | $this->set_quantity( 1 ); |
| 880 | 880 | } |
| 881 | 881 | if( ! $this->is_percent() ) { |
| 882 | - $this->set_unit_price( $total ); |
|
| 882 | + $this->set_unit_price( $total ); |
|
| 883 | 883 | } |
| 884 | 884 | } |
| 885 | 885 | |
@@ -1244,48 +1244,48 @@ discard block |
||
| 1244 | 1244 | |
| 1245 | 1245 | |
| 1246 | 1246 | |
| 1247 | - /** |
|
| 1248 | - * @param bool $raw |
|
| 1249 | - * @return int |
|
| 1250 | - * @throws \EE_Error |
|
| 1251 | - */ |
|
| 1252 | - public function timestamp($raw = false) |
|
| 1253 | - { |
|
| 1254 | - return $raw ? $this->get_raw('LIN_timestamp') : $this->get('LIN_timestamp'); |
|
| 1255 | - } |
|
| 1247 | + /** |
|
| 1248 | + * @param bool $raw |
|
| 1249 | + * @return int |
|
| 1250 | + * @throws \EE_Error |
|
| 1251 | + */ |
|
| 1252 | + public function timestamp($raw = false) |
|
| 1253 | + { |
|
| 1254 | + return $raw ? $this->get_raw('LIN_timestamp') : $this->get('LIN_timestamp'); |
|
| 1255 | + } |
|
| 1256 | 1256 | |
| 1257 | 1257 | |
| 1258 | 1258 | |
| 1259 | 1259 | |
| 1260 | - /************************* DEPRECATED *************************/ |
|
| 1260 | + /************************* DEPRECATED *************************/ |
|
| 1261 | 1261 | |
| 1262 | 1262 | |
| 1263 | 1263 | |
| 1264 | - /** |
|
| 1265 | - * @deprecated 4.6.0 |
|
| 1266 | - * @param string $type one of the constants on EEM_Line_Item |
|
| 1267 | - * @return EE_Line_Item[] |
|
| 1268 | - */ |
|
| 1269 | - protected function _get_descendants_of_type($type) |
|
| 1270 | - { |
|
| 1271 | - EE_Error::doing_it_wrong('EE_Line_Item::_get_descendants_of_type()', |
|
| 1272 | - __('Method replaced with EEH_Line_Item::get_descendants_of_type()', 'event_espresso'), '4.6.0'); |
|
| 1273 | - return EEH_Line_Item::get_descendants_of_type($this, $type); |
|
| 1274 | - } |
|
| 1264 | + /** |
|
| 1265 | + * @deprecated 4.6.0 |
|
| 1266 | + * @param string $type one of the constants on EEM_Line_Item |
|
| 1267 | + * @return EE_Line_Item[] |
|
| 1268 | + */ |
|
| 1269 | + protected function _get_descendants_of_type($type) |
|
| 1270 | + { |
|
| 1271 | + EE_Error::doing_it_wrong('EE_Line_Item::_get_descendants_of_type()', |
|
| 1272 | + __('Method replaced with EEH_Line_Item::get_descendants_of_type()', 'event_espresso'), '4.6.0'); |
|
| 1273 | + return EEH_Line_Item::get_descendants_of_type($this, $type); |
|
| 1274 | + } |
|
| 1275 | 1275 | |
| 1276 | 1276 | |
| 1277 | 1277 | |
| 1278 | - /** |
|
| 1279 | - * @deprecated 4.6.0 |
|
| 1280 | - * @param string $type like one of the EEM_Line_Item::type_* |
|
| 1281 | - * @return EE_Line_Item |
|
| 1282 | - */ |
|
| 1283 | - public function get_nearest_descendant_of_type($type) |
|
| 1284 | - { |
|
| 1285 | - EE_Error::doing_it_wrong('EE_Line_Item::get_nearest_descendant_of_type()', |
|
| 1286 | - __('Method replaced with EEH_Line_Item::get_nearest_descendant_of_type()', 'event_espresso'), '4.6.0'); |
|
| 1287 | - return EEH_Line_Item::get_nearest_descendant_of_type($this, $type); |
|
| 1288 | - } |
|
| 1278 | + /** |
|
| 1279 | + * @deprecated 4.6.0 |
|
| 1280 | + * @param string $type like one of the EEM_Line_Item::type_* |
|
| 1281 | + * @return EE_Line_Item |
|
| 1282 | + */ |
|
| 1283 | + public function get_nearest_descendant_of_type($type) |
|
| 1284 | + { |
|
| 1285 | + EE_Error::doing_it_wrong('EE_Line_Item::get_nearest_descendant_of_type()', |
|
| 1286 | + __('Method replaced with EEH_Line_Item::get_nearest_descendant_of_type()', 'event_espresso'), '4.6.0'); |
|
| 1287 | + return EEH_Line_Item::get_nearest_descendant_of_type($this, $type); |
|
| 1288 | + } |
|
| 1289 | 1289 | |
| 1290 | 1290 | |
| 1291 | 1291 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | -<?php if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 2 | - exit( 'No direct script access allowed' ); |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | /** |
| 5 | 5 | * Event Espresso |
@@ -50,9 +50,9 @@ discard block |
||
| 50 | 50 | * date_format and the second value is the time format |
| 51 | 51 | * @return EE_Line_Item |
| 52 | 52 | */ |
| 53 | - public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) { |
|
| 54 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats ); |
|
| 55 | - return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats ); |
|
| 53 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) { |
|
| 54 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 55 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | |
@@ -63,8 +63,8 @@ discard block |
||
| 63 | 63 | * the website will be used. |
| 64 | 64 | * @return EE_Line_Item |
| 65 | 65 | */ |
| 66 | - public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) { |
|
| 67 | - return new self( $props_n_values, TRUE, $timezone ); |
|
| 66 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) { |
|
| 67 | + return new self($props_n_values, TRUE, $timezone); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | |
@@ -75,10 +75,10 @@ discard block |
||
| 75 | 75 | * @param bool $bydb |
| 76 | 76 | * @param string $timezone |
| 77 | 77 | */ |
| 78 | - protected function __construct( $fieldValues = array(), $bydb = FALSE, $timezone = '' ) { |
|
| 79 | - parent::__construct( $fieldValues, $bydb, $timezone ); |
|
| 80 | - if ( ! $this->get( 'LIN_code' ) ) { |
|
| 81 | - $this->set_code( $this->generate_code() ); |
|
| 78 | + protected function __construct($fieldValues = array(), $bydb = FALSE, $timezone = '') { |
|
| 79 | + parent::__construct($fieldValues, $bydb, $timezone); |
|
| 80 | + if ( ! $this->get('LIN_code')) { |
|
| 81 | + $this->set_code($this->generate_code()); |
|
| 82 | 82 | } |
| 83 | 83 | } |
| 84 | 84 | |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | * @return int |
| 90 | 90 | */ |
| 91 | 91 | public function ID() { |
| 92 | - return $this->get( 'LIN_ID' ); |
|
| 92 | + return $this->get('LIN_ID'); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | * @return int |
| 100 | 100 | */ |
| 101 | 101 | public function TXN_ID() { |
| 102 | - return $this->get( 'TXN_ID' ); |
|
| 102 | + return $this->get('TXN_ID'); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | |
@@ -108,8 +108,8 @@ discard block |
||
| 108 | 108 | * Sets TXN_ID |
| 109 | 109 | * @param int $TXN_ID |
| 110 | 110 | */ |
| 111 | - public function set_TXN_ID( $TXN_ID ) { |
|
| 112 | - $this->set( 'TXN_ID', $TXN_ID ); |
|
| 111 | + public function set_TXN_ID($TXN_ID) { |
|
| 112 | + $this->set('TXN_ID', $TXN_ID); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | |
@@ -119,9 +119,9 @@ discard block |
||
| 119 | 119 | * @return string |
| 120 | 120 | */ |
| 121 | 121 | public function name() { |
| 122 | - $name = $this->get( 'LIN_name' ); |
|
| 123 | - if( ! $name ){ |
|
| 124 | - $name = ucwords( str_replace( '-', ' ', $this->type() ) ); |
|
| 122 | + $name = $this->get('LIN_name'); |
|
| 123 | + if ( ! $name) { |
|
| 124 | + $name = ucwords(str_replace('-', ' ', $this->type())); |
|
| 125 | 125 | } |
| 126 | 126 | return $name; |
| 127 | 127 | } |
@@ -132,8 +132,8 @@ discard block |
||
| 132 | 132 | * Sets name |
| 133 | 133 | * @param string $name |
| 134 | 134 | */ |
| 135 | - public function set_name( $name ) { |
|
| 136 | - $this->set( 'LIN_name', $name ); |
|
| 135 | + public function set_name($name) { |
|
| 136 | + $this->set('LIN_name', $name); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | * @return string |
| 144 | 144 | */ |
| 145 | 145 | public function desc() { |
| 146 | - return $this->get( 'LIN_desc' ); |
|
| 146 | + return $this->get('LIN_desc'); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | |
@@ -152,8 +152,8 @@ discard block |
||
| 152 | 152 | * Sets desc |
| 153 | 153 | * @param string $desc |
| 154 | 154 | */ |
| 155 | - public function set_desc( $desc ) { |
|
| 156 | - $this->set( 'LIN_desc', $desc ); |
|
| 155 | + public function set_desc($desc) { |
|
| 156 | + $this->set('LIN_desc', $desc); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | * @return int |
| 164 | 164 | */ |
| 165 | 165 | public function quantity() { |
| 166 | - return $this->get( 'LIN_quantity' ); |
|
| 166 | + return $this->get('LIN_quantity'); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | |
@@ -172,8 +172,8 @@ discard block |
||
| 172 | 172 | * Sets quantity |
| 173 | 173 | * @param int $quantity |
| 174 | 174 | */ |
| 175 | - public function set_quantity( $quantity ) { |
|
| 176 | - $this->set( 'LIN_quantity', max( $quantity, 0 ) ); |
|
| 175 | + public function set_quantity($quantity) { |
|
| 176 | + $this->set('LIN_quantity', max($quantity, 0)); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | * @return string |
| 184 | 184 | */ |
| 185 | 185 | public function OBJ_ID() { |
| 186 | - return $this->get( 'OBJ_ID' ); |
|
| 186 | + return $this->get('OBJ_ID'); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | |
@@ -192,8 +192,8 @@ discard block |
||
| 192 | 192 | * Sets item_id |
| 193 | 193 | * @param string $item_id |
| 194 | 194 | */ |
| 195 | - public function set_OBJ_ID( $item_id ) { |
|
| 196 | - $this->set( 'OBJ_ID', $item_id ); |
|
| 195 | + public function set_OBJ_ID($item_id) { |
|
| 196 | + $this->set('OBJ_ID', $item_id); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | * @return string |
| 204 | 204 | */ |
| 205 | 205 | public function OBJ_type() { |
| 206 | - return $this->get( 'OBJ_type' ); |
|
| 206 | + return $this->get('OBJ_type'); |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | |
@@ -240,8 +240,8 @@ discard block |
||
| 240 | 240 | * Sets item_type |
| 241 | 241 | * @param string $OBJ_type |
| 242 | 242 | */ |
| 243 | - public function set_OBJ_type( $OBJ_type ) { |
|
| 244 | - $this->set( 'OBJ_type', $OBJ_type ); |
|
| 243 | + public function set_OBJ_type($OBJ_type) { |
|
| 244 | + $this->set('OBJ_type', $OBJ_type); |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | * @return float |
| 252 | 252 | */ |
| 253 | 253 | public function unit_price() { |
| 254 | - return $this->get( 'LIN_unit_price' ); |
|
| 254 | + return $this->get('LIN_unit_price'); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | |
@@ -261,8 +261,8 @@ discard block |
||
| 261 | 261 | * |
| 262 | 262 | * @param float $unit_price |
| 263 | 263 | */ |
| 264 | - public function set_unit_price( $unit_price ) { |
|
| 265 | - $this->set( 'LIN_unit_price', $unit_price ); |
|
| 264 | + public function set_unit_price($unit_price) { |
|
| 265 | + $this->set('LIN_unit_price', $unit_price); |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | |
@@ -273,19 +273,19 @@ discard block |
||
| 273 | 273 | * @return boolean |
| 274 | 274 | */ |
| 275 | 275 | public function is_percent() { |
| 276 | - if( $this->is_tax_sub_total() ) { |
|
| 276 | + if ($this->is_tax_sub_total()) { |
|
| 277 | 277 | //tax subtotals HAVE a percent on them, that percentage only applies |
| 278 | 278 | //to taxable items, so its' an exception. Treat it like a flat line item |
| 279 | 279 | return false; |
| 280 | 280 | } |
| 281 | - $unit_price = abs( $this->get( 'LIN_unit_price' ) ); |
|
| 282 | - $percent = abs( $this->get( 'LIN_percent' ) ); |
|
| 283 | - if ( $unit_price < .001 && $percent ) { |
|
| 281 | + $unit_price = abs($this->get('LIN_unit_price')); |
|
| 282 | + $percent = abs($this->get('LIN_percent')); |
|
| 283 | + if ($unit_price < .001 && $percent) { |
|
| 284 | 284 | return TRUE; |
| 285 | - } elseif ( $unit_price >= .001 && !$percent ) { |
|
| 285 | + } elseif ($unit_price >= .001 && ! $percent) { |
|
| 286 | 286 | return FALSE; |
| 287 | - } elseif ( $unit_price >= .001 && $percent ) { |
|
| 288 | - throw new EE_Error( sprintf( __( "A Line Item can not have a unit price of (%s) AND a percent (%s)!", "event_espresso" ), $unit_price, $percent ) ); |
|
| 287 | + } elseif ($unit_price >= .001 && $percent) { |
|
| 288 | + throw new EE_Error(sprintf(__("A Line Item can not have a unit price of (%s) AND a percent (%s)!", "event_espresso"), $unit_price, $percent)); |
|
| 289 | 289 | } else { |
| 290 | 290 | // if they're both 0, assume its not a percent item |
| 291 | 291 | return FALSE; |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | * @return float |
| 300 | 300 | */ |
| 301 | 301 | public function percent() { |
| 302 | - return $this->get( 'LIN_percent' ); |
|
| 302 | + return $this->get('LIN_percent'); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | |
@@ -308,8 +308,8 @@ discard block |
||
| 308 | 308 | * Sets percent (between 100-0.01) |
| 309 | 309 | * @param float $percent |
| 310 | 310 | */ |
| 311 | - public function set_percent( $percent ) { |
|
| 312 | - $this->set( 'LIN_percent', $percent ); |
|
| 311 | + public function set_percent($percent) { |
|
| 312 | + $this->set('LIN_percent', $percent); |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | * @return float |
| 320 | 320 | */ |
| 321 | 321 | public function total() { |
| 322 | - return $this->get( 'LIN_total' ); |
|
| 322 | + return $this->get('LIN_total'); |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | |
@@ -328,8 +328,8 @@ discard block |
||
| 328 | 328 | * Sets total |
| 329 | 329 | * @param float $total |
| 330 | 330 | */ |
| 331 | - public function set_total( $total ) { |
|
| 332 | - $this->set( 'LIN_total', $total ); |
|
| 331 | + public function set_total($total) { |
|
| 332 | + $this->set('LIN_total', $total); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | |
@@ -339,7 +339,7 @@ discard block |
||
| 339 | 339 | * @return int |
| 340 | 340 | */ |
| 341 | 341 | public function order() { |
| 342 | - return $this->get( 'LIN_order' ); |
|
| 342 | + return $this->get('LIN_order'); |
|
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | |
@@ -348,8 +348,8 @@ discard block |
||
| 348 | 348 | * Sets order |
| 349 | 349 | * @param int $order |
| 350 | 350 | */ |
| 351 | - public function set_order( $order ) { |
|
| 352 | - $this->set( 'LIN_order', $order ); |
|
| 351 | + public function set_order($order) { |
|
| 352 | + $this->set('LIN_order', $order); |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | * @return int |
| 360 | 360 | */ |
| 361 | 361 | public function parent_ID() { |
| 362 | - return $this->get( 'LIN_parent' ); |
|
| 362 | + return $this->get('LIN_parent'); |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | |
@@ -368,8 +368,8 @@ discard block |
||
| 368 | 368 | * Sets parent |
| 369 | 369 | * @param int $parent |
| 370 | 370 | */ |
| 371 | - public function set_parent_ID( $parent ) { |
|
| 372 | - $this->set( 'LIN_parent', $parent ); |
|
| 371 | + public function set_parent_ID($parent) { |
|
| 372 | + $this->set('LIN_parent', $parent); |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | * @return string |
| 380 | 380 | */ |
| 381 | 381 | public function type() { |
| 382 | - return $this->get( 'LIN_type' ); |
|
| 382 | + return $this->get('LIN_type'); |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | |
@@ -388,8 +388,8 @@ discard block |
||
| 388 | 388 | * Sets type |
| 389 | 389 | * @param string $type |
| 390 | 390 | */ |
| 391 | - public function set_type( $type ) { |
|
| 392 | - $this->set( 'LIN_type', $type ); |
|
| 391 | + public function set_type($type) { |
|
| 392 | + $this->set('LIN_type', $type); |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | |
@@ -402,8 +402,8 @@ discard block |
||
| 402 | 402 | * @return EE_Line_Item |
| 403 | 403 | */ |
| 404 | 404 | public function parent() { |
| 405 | - if( $this->ID() ) { |
|
| 406 | - return $this->get_model()->get_one_by_ID( $this->parent_ID() ); |
|
| 405 | + if ($this->ID()) { |
|
| 406 | + return $this->get_model()->get_one_by_ID($this->parent_ID()); |
|
| 407 | 407 | } else { |
| 408 | 408 | return $this->_parent; |
| 409 | 409 | } |
@@ -416,13 +416,13 @@ discard block |
||
| 416 | 416 | * @return EE_Line_Item[] |
| 417 | 417 | */ |
| 418 | 418 | public function children() { |
| 419 | - if ( $this->ID() ) { |
|
| 419 | + if ($this->ID()) { |
|
| 420 | 420 | return $this->get_model()->get_all( |
| 421 | 421 | array( |
| 422 | - array( 'LIN_parent' => $this->ID() ), |
|
| 423 | - 'order_by' => array( 'LIN_order' => 'ASC' ) ) ); |
|
| 422 | + array('LIN_parent' => $this->ID()), |
|
| 423 | + 'order_by' => array('LIN_order' => 'ASC') ) ); |
|
| 424 | 424 | } else { |
| 425 | - if ( ! is_array( $this->_children ) ) { |
|
| 425 | + if ( ! is_array($this->_children)) { |
|
| 426 | 426 | $this->_children = array(); |
| 427 | 427 | } |
| 428 | 428 | return $this->_children; |
@@ -436,7 +436,7 @@ discard block |
||
| 436 | 436 | * @return string |
| 437 | 437 | */ |
| 438 | 438 | public function code() { |
| 439 | - return $this->get( 'LIN_code' ); |
|
| 439 | + return $this->get('LIN_code'); |
|
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | |
@@ -445,8 +445,8 @@ discard block |
||
| 445 | 445 | * Sets code |
| 446 | 446 | * @param string $code |
| 447 | 447 | */ |
| 448 | - public function set_code( $code ) { |
|
| 449 | - $this->set( 'LIN_code', $code ); |
|
| 448 | + public function set_code($code) { |
|
| 449 | + $this->set('LIN_code', $code); |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | |
@@ -456,7 +456,7 @@ discard block |
||
| 456 | 456 | * @return boolean |
| 457 | 457 | */ |
| 458 | 458 | public function is_taxable() { |
| 459 | - return $this->get( 'LIN_is_taxable' ); |
|
| 459 | + return $this->get('LIN_is_taxable'); |
|
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | |
@@ -465,8 +465,8 @@ discard block |
||
| 465 | 465 | * Sets is_taxable |
| 466 | 466 | * @param boolean $is_taxable |
| 467 | 467 | */ |
| 468 | - public function set_is_taxable( $is_taxable ) { |
|
| 469 | - $this->set( 'LIN_is_taxable', $is_taxable ); |
|
| 468 | + public function set_is_taxable($is_taxable) { |
|
| 469 | + $this->set('LIN_is_taxable', $is_taxable); |
|
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | */ |
| 482 | 482 | public function get_object() { |
| 483 | 483 | $model_name_of_related_obj = $this->OBJ_type(); |
| 484 | - return $this->get_model()->has_relation( $model_name_of_related_obj ) ? $this->get_first_related( $model_name_of_related_obj ) : NULL; |
|
| 484 | + return $this->get_model()->has_relation($model_name_of_related_obj) ? $this->get_first_related($model_name_of_related_obj) : NULL; |
|
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | |
@@ -492,11 +492,11 @@ discard block |
||
| 492 | 492 | * @param array $query_params |
| 493 | 493 | * @return EE_Ticket |
| 494 | 494 | */ |
| 495 | - public function ticket( $query_params = array() ) { |
|
| 495 | + public function ticket($query_params = array()) { |
|
| 496 | 496 | //we're going to assume that when this method is called we always want to receive the attached ticket EVEN if that ticket is archived. This can be overridden via the incoming $query_params argument |
| 497 | - $remove_defaults = array( 'default_where_conditions' => 'none' ); |
|
| 498 | - $query_params = array_merge( $remove_defaults, $query_params ); |
|
| 499 | - return $this->get_first_related( 'Ticket', $query_params ); |
|
| 497 | + $remove_defaults = array('default_where_conditions' => 'none'); |
|
| 498 | + $query_params = array_merge($remove_defaults, $query_params); |
|
| 499 | + return $this->get_first_related('Ticket', $query_params); |
|
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | |
@@ -506,11 +506,11 @@ discard block |
||
| 506 | 506 | * @return EE_Datetime | NULL |
| 507 | 507 | */ |
| 508 | 508 | public function get_ticket_datetime() { |
| 509 | - if ( $this->OBJ_type() === 'Ticket' ) { |
|
| 509 | + if ($this->OBJ_type() === 'Ticket') { |
|
| 510 | 510 | $ticket = $this->ticket(); |
| 511 | - if ( $ticket instanceof EE_Ticket ) { |
|
| 511 | + if ($ticket instanceof EE_Ticket) { |
|
| 512 | 512 | $datetime = $ticket->first_datetime(); |
| 513 | - if ( $datetime instanceof EE_Datetime ) { |
|
| 513 | + if ($datetime instanceof EE_Datetime) { |
|
| 514 | 514 | return $datetime; |
| 515 | 515 | } |
| 516 | 516 | } |
@@ -526,9 +526,9 @@ discard block |
||
| 526 | 526 | * @return string |
| 527 | 527 | */ |
| 528 | 528 | public function ticket_event_name() { |
| 529 | - $event_name = __( "Unknown", "event_espresso" ); |
|
| 529 | + $event_name = __("Unknown", "event_espresso"); |
|
| 530 | 530 | $event = $this->ticket_event(); |
| 531 | - if ( $event instanceof EE_Event ) { |
|
| 531 | + if ($event instanceof EE_Event) { |
|
| 532 | 532 | $event_name = $event->name(); |
| 533 | 533 | } |
| 534 | 534 | return $event_name; |
@@ -542,9 +542,9 @@ discard block |
||
| 542 | 542 | public function ticket_event() { |
| 543 | 543 | $event = null; |
| 544 | 544 | $ticket = $this->ticket(); |
| 545 | - if ( $ticket instanceof EE_Ticket ) { |
|
| 545 | + if ($ticket instanceof EE_Ticket) { |
|
| 546 | 546 | $datetime = $ticket->first_datetime(); |
| 547 | - if ( $datetime instanceof EE_Datetime ) { |
|
| 547 | + if ($datetime instanceof EE_Datetime) { |
|
| 548 | 548 | $event = $datetime->event(); |
| 549 | 549 | } |
| 550 | 550 | } |
@@ -559,11 +559,11 @@ discard block |
||
| 559 | 559 | * @param string $time_format |
| 560 | 560 | * @return string |
| 561 | 561 | */ |
| 562 | - public function ticket_datetime_start( $date_format = '', $time_format = '' ) { |
|
| 563 | - $first_datetime_string = __( "Unknown", "event_espresso" ); |
|
| 562 | + public function ticket_datetime_start($date_format = '', $time_format = '') { |
|
| 563 | + $first_datetime_string = __("Unknown", "event_espresso"); |
|
| 564 | 564 | $datetime = $this->get_ticket_datetime(); |
| 565 | - if ( $datetime ) { |
|
| 566 | - $first_datetime_string = $datetime->start_date_and_time( $date_format, $time_format ); |
|
| 565 | + if ($datetime) { |
|
| 566 | + $first_datetime_string = $datetime->start_date_and_time($date_format, $time_format); |
|
| 567 | 567 | } |
| 568 | 568 | return $first_datetime_string; |
| 569 | 569 | } |
@@ -578,26 +578,26 @@ discard block |
||
| 578 | 578 | * @return bool success |
| 579 | 579 | * @throws \EE_Error |
| 580 | 580 | */ |
| 581 | - public function add_child_line_item( EEI_Line_Item $line_item, $set_order = true ) { |
|
| 581 | + public function add_child_line_item(EEI_Line_Item $line_item, $set_order = true) { |
|
| 582 | 582 | // should we calculate the LIN_order for this line item ? |
| 583 | - if ( $set_order || $line_item->order() === null ) { |
|
| 584 | - $line_item->set_order( count( $this->children() ) ); |
|
| 583 | + if ($set_order || $line_item->order() === null) { |
|
| 584 | + $line_item->set_order(count($this->children())); |
|
| 585 | 585 | } |
| 586 | - if ( $this->ID() ) { |
|
| 586 | + if ($this->ID()) { |
|
| 587 | 587 | //check for any duplicate line items (with the same code), if so, this replaces it |
| 588 | - $line_item_with_same_code = $this->get_child_line_item( $line_item->code() ); |
|
| 589 | - if( $line_item_with_same_code instanceof EE_Line_Item && $line_item_with_same_code !== $line_item ) { |
|
| 590 | - $this->delete_child_line_item( $line_item_with_same_code->code() ); |
|
| 588 | + $line_item_with_same_code = $this->get_child_line_item($line_item->code()); |
|
| 589 | + if ($line_item_with_same_code instanceof EE_Line_Item && $line_item_with_same_code !== $line_item) { |
|
| 590 | + $this->delete_child_line_item($line_item_with_same_code->code()); |
|
| 591 | 591 | } |
| 592 | - $line_item->set_parent_ID( $this->ID() ); |
|
| 593 | - if( $this->TXN_ID() ){ |
|
| 594 | - $line_item->set_TXN_ID( $this->TXN_ID() ); |
|
| 592 | + $line_item->set_parent_ID($this->ID()); |
|
| 593 | + if ($this->TXN_ID()) { |
|
| 594 | + $line_item->set_TXN_ID($this->TXN_ID()); |
|
| 595 | 595 | } |
| 596 | 596 | return $line_item->save(); |
| 597 | 597 | } else { |
| 598 | - $this->_children[ $line_item->code() ] = $line_item; |
|
| 599 | - if( $line_item->parent() != $this ) { |
|
| 600 | - $line_item->set_parent( $this ); |
|
| 598 | + $this->_children[$line_item->code()] = $line_item; |
|
| 599 | + if ($line_item->parent() != $this) { |
|
| 600 | + $line_item->set_parent($this); |
|
| 601 | 601 | } |
| 602 | 602 | return TRUE; |
| 603 | 603 | } |
@@ -611,16 +611,16 @@ discard block |
||
| 611 | 611 | * @param EE_Line_Item $line_item |
| 612 | 612 | * |
| 613 | 613 | */ |
| 614 | - public function set_parent( $line_item ) { |
|
| 615 | - if ( $this->ID() ) { |
|
| 616 | - if( ! $line_item->ID() ) { |
|
| 614 | + public function set_parent($line_item) { |
|
| 615 | + if ($this->ID()) { |
|
| 616 | + if ( ! $line_item->ID()) { |
|
| 617 | 617 | $line_item->save(); |
| 618 | 618 | } |
| 619 | - $this->set_parent_ID( $line_item->ID() ); |
|
| 619 | + $this->set_parent_ID($line_item->ID()); |
|
| 620 | 620 | $this->save(); |
| 621 | 621 | } else { |
| 622 | 622 | $this->_parent = $line_item; |
| 623 | - $this->set_parent_ID( $line_item->ID() ); |
|
| 623 | + $this->set_parent_ID($line_item->ID()); |
|
| 624 | 624 | } |
| 625 | 625 | } |
| 626 | 626 | |
@@ -633,11 +633,11 @@ discard block |
||
| 633 | 633 | * @param string $code |
| 634 | 634 | * @return EE_Line_Item |
| 635 | 635 | */ |
| 636 | - public function get_child_line_item( $code ) { |
|
| 637 | - if ( $this->ID() ) { |
|
| 638 | - return $this->get_model()->get_one( array( array( 'LIN_parent' => $this->ID(), 'LIN_code' => $code ) ) ); |
|
| 636 | + public function get_child_line_item($code) { |
|
| 637 | + if ($this->ID()) { |
|
| 638 | + return $this->get_model()->get_one(array(array('LIN_parent' => $this->ID(), 'LIN_code' => $code))); |
|
| 639 | 639 | } else { |
| 640 | - return isset( $this->_children[ $code ] ) ? $this->_children[ $code ] : null; |
|
| 640 | + return isset($this->_children[$code]) ? $this->_children[$code] : null; |
|
| 641 | 641 | } |
| 642 | 642 | } |
| 643 | 643 | |
@@ -648,10 +648,10 @@ discard block |
||
| 648 | 648 | * @return int |
| 649 | 649 | */ |
| 650 | 650 | public function delete_children_line_items() { |
| 651 | - if ( $this->ID() ) { |
|
| 652 | - return $this->get_model()->delete( array( array( 'LIN_parent' => $this->ID() ) ) ); |
|
| 651 | + if ($this->ID()) { |
|
| 652 | + return $this->get_model()->delete(array(array('LIN_parent' => $this->ID()))); |
|
| 653 | 653 | } else { |
| 654 | - $count = count( $this->_children ); |
|
| 654 | + $count = count($this->_children); |
|
| 655 | 655 | $this->_children = array(); |
| 656 | 656 | return $count; |
| 657 | 657 | } |
@@ -668,25 +668,25 @@ discard block |
||
| 668 | 668 | * @param bool $stop_search_once_found |
| 669 | 669 | * @return int count of items deleted (or simply removed from the line item's cache, if not has not been saved to the DB yet) |
| 670 | 670 | */ |
| 671 | - public function delete_child_line_item( $code, $stop_search_once_found = true ) { |
|
| 672 | - if ( $this->ID() ) { |
|
| 671 | + public function delete_child_line_item($code, $stop_search_once_found = true) { |
|
| 672 | + if ($this->ID()) { |
|
| 673 | 673 | $items_deleted = 0; |
| 674 | - if( $this->code() == $code ) { |
|
| 675 | - $items_deleted += EEH_Line_Item::delete_all_child_items( $this ); |
|
| 674 | + if ($this->code() == $code) { |
|
| 675 | + $items_deleted += EEH_Line_Item::delete_all_child_items($this); |
|
| 676 | 676 | $items_deleted += (int) $this->delete(); |
| 677 | - if( $stop_search_once_found ){ |
|
| 677 | + if ($stop_search_once_found) { |
|
| 678 | 678 | return $items_deleted; |
| 679 | 679 | } |
| 680 | 680 | } |
| 681 | - foreach( $this->children() as $child_line_item ) { |
|
| 682 | - $items_deleted += $child_line_item->delete_child_line_item( $code, $stop_search_once_found ); |
|
| 681 | + foreach ($this->children() as $child_line_item) { |
|
| 682 | + $items_deleted += $child_line_item->delete_child_line_item($code, $stop_search_once_found); |
|
| 683 | 683 | } |
| 684 | 684 | return $items_deleted; |
| 685 | 685 | } else { |
| 686 | - if( isset( $this->_children[ $code ] ) ) { |
|
| 687 | - unset( $this->_children[ $code ] ); |
|
| 686 | + if (isset($this->_children[$code])) { |
|
| 687 | + unset($this->_children[$code]); |
|
| 688 | 688 | return 1; |
| 689 | - }else{ |
|
| 689 | + } else { |
|
| 690 | 690 | return 0; |
| 691 | 691 | } |
| 692 | 692 | } |
@@ -699,9 +699,9 @@ discard block |
||
| 699 | 699 | * @return boolean |
| 700 | 700 | */ |
| 701 | 701 | public function delete_if_childless_subtotal() { |
| 702 | - if( $this->ID() && |
|
| 702 | + if ($this->ID() && |
|
| 703 | 703 | $this->type() == EEM_Line_Item::type_sub_total && |
| 704 | - ! $this->children() ) { |
|
| 704 | + ! $this->children()) { |
|
| 705 | 705 | return $this->delete(); |
| 706 | 706 | } else { |
| 707 | 707 | return false; |
@@ -716,7 +716,7 @@ discard block |
||
| 716 | 716 | */ |
| 717 | 717 | public function generate_code() { |
| 718 | 718 | // each line item in the cart requires a unique identifier |
| 719 | - return md5( $this->get( 'OBJ_type' ) . $this->get( 'OBJ_ID' ) . microtime() ); |
|
| 719 | + return md5($this->get('OBJ_type').$this->get('OBJ_ID').microtime()); |
|
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | |
@@ -799,7 +799,7 @@ discard block |
||
| 799 | 799 | * @return string like '2, 004.00', formatted according to the localized currency |
| 800 | 800 | */ |
| 801 | 801 | public function unit_price_no_code() { |
| 802 | - return $this->get_pretty( 'LIN_unit_price', 'no_currency_code' ); |
|
| 802 | + return $this->get_pretty('LIN_unit_price', 'no_currency_code'); |
|
| 803 | 803 | } |
| 804 | 804 | |
| 805 | 805 | |
@@ -809,7 +809,7 @@ discard block |
||
| 809 | 809 | * @return string like '2, 004.00', formatted according to the localized currency |
| 810 | 810 | */ |
| 811 | 811 | public function total_no_code() { |
| 812 | - return $this->get_pretty( 'LIN_total', 'no_currency_code' ); |
|
| 812 | + return $this->get_pretty('LIN_total', 'no_currency_code'); |
|
| 813 | 813 | } |
| 814 | 814 | |
| 815 | 815 | |
@@ -829,17 +829,17 @@ discard block |
||
| 829 | 829 | $tax_total = $this->recalculate_taxes_and_tax_total(); |
| 830 | 830 | $total = $pre_tax_total + $tax_total; |
| 831 | 831 | // no negative totals plz |
| 832 | - $total = max( $total, 0 ); |
|
| 833 | - $this->set_total( $total ); |
|
| 832 | + $total = max($total, 0); |
|
| 833 | + $this->set_total($total); |
|
| 834 | 834 | //only update the related transaction's total |
| 835 | 835 | //if we intend to save this line item and its a grand total |
| 836 | - if( |
|
| 836 | + if ( |
|
| 837 | 837 | $this->allow_persist() && |
| 838 | 838 | $this->type() === EEM_Line_Item::type_total && |
| 839 | 839 | $this->transaction() instanceof EE_Transaction |
| 840 | - ){ |
|
| 841 | - $this->transaction()->set_total( $total ); |
|
| 842 | - if ( $this->transaction()->ID() ) { |
|
| 840 | + ) { |
|
| 841 | + $this->transaction()->set_total($total); |
|
| 842 | + if ($this->transaction()->ID()) { |
|
| 843 | 843 | $this->transaction()->save(); |
| 844 | 844 | } |
| 845 | 845 | } |
@@ -858,47 +858,47 @@ discard block |
||
| 858 | 858 | public function recalculate_pre_tax_total() { |
| 859 | 859 | $total = 0; |
| 860 | 860 | $my_children = $this->children(); |
| 861 | - $has_children = ! empty( $my_children ); |
|
| 862 | - if ( $has_children && $this->is_line_item() ) { |
|
| 863 | - $total = $this->_recalculate_pretax_total_for_line_item( $total, $my_children ); |
|
| 864 | - } elseif ( ! $has_children && ( $this->is_sub_line_item() || $this->is_line_item() ) ) { |
|
| 861 | + $has_children = ! empty($my_children); |
|
| 862 | + if ($has_children && $this->is_line_item()) { |
|
| 863 | + $total = $this->_recalculate_pretax_total_for_line_item($total, $my_children); |
|
| 864 | + } elseif ( ! $has_children && ($this->is_sub_line_item() || $this->is_line_item())) { |
|
| 865 | 865 | $total = $this->unit_price() * $this->quantity(); |
| 866 | - } elseif( $this->is_sub_total() || $this->is_total() ) { |
|
| 867 | - $total = $this->_recalculate_pretax_total_for_subtotal( $total, $my_children ); |
|
| 868 | - } elseif ( $this->is_tax_sub_total() || $this->is_tax() || $this->is_cancelled() ) { |
|
| 866 | + } elseif ($this->is_sub_total() || $this->is_total()) { |
|
| 867 | + $total = $this->_recalculate_pretax_total_for_subtotal($total, $my_children); |
|
| 868 | + } elseif ($this->is_tax_sub_total() || $this->is_tax() || $this->is_cancelled()) { |
|
| 869 | 869 | // completely ignore tax totals, tax sub-totals, and cancelled line items, when calculating the pre-tax-total |
| 870 | 870 | return 0; |
| 871 | 871 | } |
| 872 | 872 | // ensure all non-line items and non-sub-line-items have a quantity of 1 (except for Events) |
| 873 | - if( |
|
| 873 | + if ( |
|
| 874 | 874 | ! $this->is_line_item() && |
| 875 | 875 | ! $this->is_sub_line_item() && |
| 876 | 876 | ! $this->is_cancellation() |
| 877 | 877 | ) { |
| 878 | - if ( $this->OBJ_type() !== 'Event' ) { |
|
| 879 | - $this->set_quantity( 1 ); |
|
| 878 | + if ($this->OBJ_type() !== 'Event') { |
|
| 879 | + $this->set_quantity(1); |
|
| 880 | 880 | } |
| 881 | - if( ! $this->is_percent() ) { |
|
| 882 | - $this->set_unit_price( $total ); |
|
| 881 | + if ( ! $this->is_percent()) { |
|
| 882 | + $this->set_unit_price($total); |
|
| 883 | 883 | } |
| 884 | 884 | } |
| 885 | 885 | |
| 886 | 886 | //we don't want to bother saving grand totals, because that needs to factor in taxes anyways |
| 887 | 887 | //so it ought to be |
| 888 | - if( ! $this->is_total() ) { |
|
| 889 | - $this->set_total( $total ); |
|
| 888 | + if ( ! $this->is_total()) { |
|
| 889 | + $this->set_total($total); |
|
| 890 | 890 | //if not a percent line item, make sure we keep the unit price in sync |
| 891 | - if( |
|
| 891 | + if ( |
|
| 892 | 892 | $has_children |
| 893 | 893 | && $this->is_line_item() |
| 894 | 894 | && ! $this->is_percent() |
| 895 | 895 | ) { |
| 896 | - if( $this->quantity() === 0 ){ |
|
| 896 | + if ($this->quantity() === 0) { |
|
| 897 | 897 | $new_unit_price = 0; |
| 898 | 898 | } else { |
| 899 | 899 | $new_unit_price = $this->total() / $this->quantity(); |
| 900 | 900 | } |
| 901 | - $this->set_unit_price( $new_unit_price ); |
|
| 901 | + $this->set_unit_price($new_unit_price); |
|
| 902 | 902 | } |
| 903 | 903 | $this->maybe_save(); |
| 904 | 904 | } |
@@ -918,39 +918,39 @@ discard block |
||
| 918 | 918 | * @return float |
| 919 | 919 | * @throws \EE_Error |
| 920 | 920 | */ |
| 921 | - protected function _recalculate_pretax_total_for_subtotal( $calculated_total_so_far, $my_children = null ) { |
|
| 922 | - if( $my_children === null ) { |
|
| 921 | + protected function _recalculate_pretax_total_for_subtotal($calculated_total_so_far, $my_children = null) { |
|
| 922 | + if ($my_children === null) { |
|
| 923 | 923 | $my_children = $this->children(); |
| 924 | 924 | } |
| 925 | 925 | //get the total of all its children |
| 926 | - foreach ( $my_children as $child_line_item ) { |
|
| 927 | - if ( $child_line_item instanceof EE_Line_Item && ! $child_line_item->is_cancellation() ) { |
|
| 926 | + foreach ($my_children as $child_line_item) { |
|
| 927 | + if ($child_line_item instanceof EE_Line_Item && ! $child_line_item->is_cancellation()) { |
|
| 928 | 928 | // percentage line items are based on total so far |
| 929 | - if ( $child_line_item->is_percent() ) { |
|
| 929 | + if ($child_line_item->is_percent()) { |
|
| 930 | 930 | //round as we go so that the line items add up ok |
| 931 | 931 | $percent_total = round( |
| 932 | 932 | $calculated_total_so_far * $child_line_item->percent() / 100, |
| 933 | 933 | EE_Registry::instance()->CFG->currency->dec_plc |
| 934 | 934 | ); |
| 935 | - $child_line_item->set_total( $percent_total ); |
|
| 935 | + $child_line_item->set_total($percent_total); |
|
| 936 | 936 | //so far all percent line items should have a quantity of 1 |
| 937 | 937 | //(ie, no double percent discounts. Although that might be requested someday) |
| 938 | - $child_line_item->set_quantity( 1 ); |
|
| 938 | + $child_line_item->set_quantity(1); |
|
| 939 | 939 | $child_line_item->maybe_save(); |
| 940 | 940 | $calculated_total_so_far += $percent_total; |
| 941 | 941 | } else { |
| 942 | 942 | //verify flat sub-line-item quantities match their parent |
| 943 | - if( $child_line_item->is_sub_line_item() ) { |
|
| 944 | - $child_line_item->set_quantity( $this->quantity() ); |
|
| 943 | + if ($child_line_item->is_sub_line_item()) { |
|
| 944 | + $child_line_item->set_quantity($this->quantity()); |
|
| 945 | 945 | } |
| 946 | 946 | $calculated_total_so_far += $child_line_item->recalculate_pre_tax_total(); |
| 947 | 947 | } |
| 948 | 948 | } |
| 949 | 949 | } |
| 950 | 950 | |
| 951 | - if( $this->is_sub_total() ){ |
|
| 951 | + if ($this->is_sub_total()) { |
|
| 952 | 952 | // no negative totals plz |
| 953 | - $calculated_total_so_far = max( $calculated_total_so_far, 0 ); |
|
| 953 | + $calculated_total_so_far = max($calculated_total_so_far, 0); |
|
| 954 | 954 | } |
| 955 | 955 | return $calculated_total_so_far; |
| 956 | 956 | } |
@@ -968,8 +968,8 @@ discard block |
||
| 968 | 968 | * @return float |
| 969 | 969 | * @throws \EE_Error |
| 970 | 970 | */ |
| 971 | - protected function _recalculate_pretax_total_for_line_item( $calculated_total_so_far, $my_children = null ) { |
|
| 972 | - if( $my_children === null ) { |
|
| 971 | + protected function _recalculate_pretax_total_for_line_item($calculated_total_so_far, $my_children = null) { |
|
| 972 | + if ($my_children === null) { |
|
| 973 | 973 | $my_children = $this->children(); |
| 974 | 974 | } |
| 975 | 975 | //we need to keep track of the running total for a single item, |
@@ -977,10 +977,10 @@ discard block |
||
| 977 | 977 | $unit_price_for_total = 0; |
| 978 | 978 | $quantity_for_total = 1; |
| 979 | 979 | //get the total of all its children |
| 980 | - foreach ( $my_children as $child_line_item ) { |
|
| 981 | - if ( $child_line_item instanceof EE_Line_Item && |
|
| 980 | + foreach ($my_children as $child_line_item) { |
|
| 981 | + if ($child_line_item instanceof EE_Line_Item && |
|
| 982 | 982 | ! $child_line_item->is_cancellation()) { |
| 983 | - if ( $child_line_item->is_percent() ) { |
|
| 983 | + if ($child_line_item->is_percent()) { |
|
| 984 | 984 | //it should be the unit-price-so-far multiplied by teh percent multiplied by the quantity |
| 985 | 985 | //not total multiplied by percent, because that ignores rounding along-the-way |
| 986 | 986 | $percent_unit_price = round( |
@@ -988,17 +988,17 @@ discard block |
||
| 988 | 988 | EE_Registry::instance()->CFG->currency->dec_plc |
| 989 | 989 | ); |
| 990 | 990 | $percent_total = $percent_unit_price * $quantity_for_total; |
| 991 | - $child_line_item->set_total( $percent_total ); |
|
| 991 | + $child_line_item->set_total($percent_total); |
|
| 992 | 992 | //so far all percent line items should have a quantity of 1 |
| 993 | 993 | //(ie, no double percent discounts. Although that might be requested someday) |
| 994 | - $child_line_item->set_quantity( 1 ); |
|
| 994 | + $child_line_item->set_quantity(1); |
|
| 995 | 995 | $child_line_item->maybe_save(); |
| 996 | 996 | $calculated_total_so_far += $percent_total; |
| 997 | 997 | $unit_price_for_total += $percent_unit_price; |
| 998 | 998 | } else { |
| 999 | 999 | //verify flat sub-line-item quantities match their parent |
| 1000 | - if( $child_line_item->is_sub_line_item() ) { |
|
| 1001 | - $child_line_item->set_quantity( $this->quantity() ); |
|
| 1000 | + if ($child_line_item->is_sub_line_item()) { |
|
| 1001 | + $child_line_item->set_quantity($this->quantity()); |
|
| 1002 | 1002 | } |
| 1003 | 1003 | $quantity_for_total = $child_line_item->quantity(); |
| 1004 | 1004 | $calculated_total_so_far += $child_line_item->recalculate_pre_tax_total(); |
@@ -1022,10 +1022,10 @@ discard block |
||
| 1022 | 1022 | //calculate the pretax total |
| 1023 | 1023 | $taxable_total = $this->taxable_total(); |
| 1024 | 1024 | $tax_total = 0; |
| 1025 | - foreach ( $taxes as $tax ) { |
|
| 1025 | + foreach ($taxes as $tax) { |
|
| 1026 | 1026 | $total_on_this_tax = $taxable_total * $tax->percent() / 100; |
| 1027 | 1027 | //remember the total on this line item |
| 1028 | - $tax->set_total( $total_on_this_tax ); |
|
| 1028 | + $tax->set_total($total_on_this_tax); |
|
| 1029 | 1029 | $tax_total += $tax->total(); |
| 1030 | 1030 | } |
| 1031 | 1031 | $this->_recalculate_tax_sub_total(); |
@@ -1039,21 +1039,21 @@ discard block |
||
| 1039 | 1039 | * @return void |
| 1040 | 1040 | */ |
| 1041 | 1041 | private function _recalculate_tax_sub_total() { |
| 1042 | - if ( $this->is_tax_sub_total() ) { |
|
| 1042 | + if ($this->is_tax_sub_total()) { |
|
| 1043 | 1043 | $total = 0; |
| 1044 | 1044 | $total_percent = 0; |
| 1045 | 1045 | //simply loop through all its children (which should be taxes) and sum their total |
| 1046 | - foreach ( $this->children() as $child_tax ) { |
|
| 1047 | - if ( $child_tax instanceof EE_Line_Item ) { |
|
| 1046 | + foreach ($this->children() as $child_tax) { |
|
| 1047 | + if ($child_tax instanceof EE_Line_Item) { |
|
| 1048 | 1048 | $total += $child_tax->total(); |
| 1049 | 1049 | $total_percent += $child_tax->percent(); |
| 1050 | 1050 | } |
| 1051 | 1051 | } |
| 1052 | - $this->set_total( $total ); |
|
| 1053 | - $this->set_percent( $total_percent ); |
|
| 1054 | - } elseif ( $this->is_total() ) { |
|
| 1055 | - foreach ( $this->children() as $maybe_tax_subtotal ) { |
|
| 1056 | - if ( $maybe_tax_subtotal instanceof EE_Line_Item ) { |
|
| 1052 | + $this->set_total($total); |
|
| 1053 | + $this->set_percent($total_percent); |
|
| 1054 | + } elseif ($this->is_total()) { |
|
| 1055 | + foreach ($this->children() as $maybe_tax_subtotal) { |
|
| 1056 | + if ($maybe_tax_subtotal instanceof EE_Line_Item) { |
|
| 1057 | 1057 | $maybe_tax_subtotal->_recalculate_tax_sub_total(); |
| 1058 | 1058 | } |
| 1059 | 1059 | } |
@@ -1069,8 +1069,8 @@ discard block |
||
| 1069 | 1069 | public function get_total_tax() { |
| 1070 | 1070 | $this->_recalculate_tax_sub_total(); |
| 1071 | 1071 | $total = 0; |
| 1072 | - foreach ( $this->tax_descendants() as $tax_line_item ) { |
|
| 1073 | - if ( $tax_line_item instanceof EE_Line_Item ) { |
|
| 1072 | + foreach ($this->tax_descendants() as $tax_line_item) { |
|
| 1073 | + if ($tax_line_item instanceof EE_Line_Item) { |
|
| 1074 | 1074 | $total += $tax_line_item->total(); |
| 1075 | 1075 | } |
| 1076 | 1076 | } |
@@ -1084,15 +1084,15 @@ discard block |
||
| 1084 | 1084 | */ |
| 1085 | 1085 | public function get_items_total() { |
| 1086 | 1086 | //by default, let's make sure we're consistent with the existing line item |
| 1087 | - if( $this->is_total() ) { |
|
| 1088 | - $pretax_subtotal_li = EEH_Line_Item::get_pre_tax_subtotal( $this ); |
|
| 1089 | - if( $pretax_subtotal_li instanceof EE_Line_Item ) { |
|
| 1087 | + if ($this->is_total()) { |
|
| 1088 | + $pretax_subtotal_li = EEH_Line_Item::get_pre_tax_subtotal($this); |
|
| 1089 | + if ($pretax_subtotal_li instanceof EE_Line_Item) { |
|
| 1090 | 1090 | return $pretax_subtotal_li->total(); |
| 1091 | 1091 | } |
| 1092 | 1092 | } |
| 1093 | 1093 | $total = 0; |
| 1094 | - foreach ( $this->get_items() as $item ) { |
|
| 1095 | - if ( $item instanceof EE_Line_Item ) { |
|
| 1094 | + foreach ($this->get_items() as $item) { |
|
| 1095 | + if ($item instanceof EE_Line_Item) { |
|
| 1096 | 1096 | $total += $item->total(); |
| 1097 | 1097 | } |
| 1098 | 1098 | } |
@@ -1107,7 +1107,7 @@ discard block |
||
| 1107 | 1107 | * @return EE_Line_Item[] |
| 1108 | 1108 | */ |
| 1109 | 1109 | public function tax_descendants() { |
| 1110 | - return EEH_Line_Item::get_tax_descendants( $this ); |
|
| 1110 | + return EEH_Line_Item::get_tax_descendants($this); |
|
| 1111 | 1111 | } |
| 1112 | 1112 | |
| 1113 | 1113 | |
@@ -1117,7 +1117,7 @@ discard block |
||
| 1117 | 1117 | * @return EE_Line_Item[] |
| 1118 | 1118 | */ |
| 1119 | 1119 | public function get_items() { |
| 1120 | - return EEH_Line_Item::get_line_item_descendants( $this ); |
|
| 1120 | + return EEH_Line_Item::get_line_item_descendants($this); |
|
| 1121 | 1121 | } |
| 1122 | 1122 | |
| 1123 | 1123 | |
@@ -1133,22 +1133,22 @@ discard block |
||
| 1133 | 1133 | */ |
| 1134 | 1134 | public function taxable_total() { |
| 1135 | 1135 | $total = 0; |
| 1136 | - if ( $this->children() ) { |
|
| 1137 | - foreach ( $this->children() as $child_line_item ) { |
|
| 1138 | - if ( $child_line_item->type() === EEM_Line_Item::type_line_item && $child_line_item->is_taxable()) { |
|
| 1136 | + if ($this->children()) { |
|
| 1137 | + foreach ($this->children() as $child_line_item) { |
|
| 1138 | + if ($child_line_item->type() === EEM_Line_Item::type_line_item && $child_line_item->is_taxable()) { |
|
| 1139 | 1139 | //if it's a percent item, only take into account the percent |
| 1140 | 1140 | //that's taxable too (the taxable total so far) |
| 1141 | - if( $child_line_item->is_percent() ) { |
|
| 1142 | - $total = $total + ( $total * $child_line_item->percent() / 100 ); |
|
| 1143 | - }else{ |
|
| 1141 | + if ($child_line_item->is_percent()) { |
|
| 1142 | + $total = $total + ($total * $child_line_item->percent() / 100); |
|
| 1143 | + } else { |
|
| 1144 | 1144 | $total += $child_line_item->total(); |
| 1145 | 1145 | } |
| 1146 | - }elseif( $child_line_item->type() === EEM_Line_Item::type_sub_total ){ |
|
| 1146 | + }elseif ($child_line_item->type() === EEM_Line_Item::type_sub_total) { |
|
| 1147 | 1147 | $total += $child_line_item->taxable_total(); |
| 1148 | 1148 | } |
| 1149 | 1149 | } |
| 1150 | 1150 | } |
| 1151 | - return max( $total, 0 ); |
|
| 1151 | + return max($total, 0); |
|
| 1152 | 1152 | } |
| 1153 | 1153 | |
| 1154 | 1154 | |
@@ -1158,7 +1158,7 @@ discard block |
||
| 1158 | 1158 | * @return EE_Transaction |
| 1159 | 1159 | */ |
| 1160 | 1160 | public function transaction() { |
| 1161 | - return $this->get_first_related( 'Transaction' ); |
|
| 1161 | + return $this->get_first_related('Transaction'); |
|
| 1162 | 1162 | } |
| 1163 | 1163 | |
| 1164 | 1164 | |
@@ -1171,18 +1171,18 @@ discard block |
||
| 1171 | 1171 | * @param int $txn_id if none is provided, assumes $this->TXN_ID() |
| 1172 | 1172 | * @return int count of items saved |
| 1173 | 1173 | */ |
| 1174 | - public function save_this_and_descendants_to_txn( $txn_id = NULL ) { |
|
| 1174 | + public function save_this_and_descendants_to_txn($txn_id = NULL) { |
|
| 1175 | 1175 | $count = 0; |
| 1176 | - if ( ! $txn_id ) { |
|
| 1176 | + if ( ! $txn_id) { |
|
| 1177 | 1177 | $txn_id = $this->TXN_ID(); |
| 1178 | 1178 | } |
| 1179 | - $this->set_TXN_ID( $txn_id ); |
|
| 1179 | + $this->set_TXN_ID($txn_id); |
|
| 1180 | 1180 | $children = $this->children(); |
| 1181 | 1181 | $count += $this->save() ? 1 : 0; |
| 1182 | - foreach ( $children as $child_line_item ) { |
|
| 1183 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
| 1184 | - $child_line_item->set_parent_ID( $this->ID() ); |
|
| 1185 | - $count += $child_line_item->save_this_and_descendants_to_txn( $txn_id ); |
|
| 1182 | + foreach ($children as $child_line_item) { |
|
| 1183 | + if ($child_line_item instanceof EE_Line_Item) { |
|
| 1184 | + $child_line_item->set_parent_ID($this->ID()); |
|
| 1185 | + $count += $child_line_item->save_this_and_descendants_to_txn($txn_id); |
|
| 1186 | 1186 | } |
| 1187 | 1187 | } |
| 1188 | 1188 | return $count; |
@@ -1199,9 +1199,9 @@ discard block |
||
| 1199 | 1199 | $count = 0; |
| 1200 | 1200 | $children = $this->children(); |
| 1201 | 1201 | $count += $this->save() ? 1 : 0; |
| 1202 | - foreach ( $children as $child_line_item ) { |
|
| 1203 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
| 1204 | - $child_line_item->set_parent_ID( $this->ID() ); |
|
| 1202 | + foreach ($children as $child_line_item) { |
|
| 1203 | + if ($child_line_item instanceof EE_Line_Item) { |
|
| 1204 | + $child_line_item->set_parent_ID($this->ID()); |
|
| 1205 | 1205 | $count += $child_line_item->save_this_and_descendants(); |
| 1206 | 1206 | } |
| 1207 | 1207 | } |
@@ -1215,8 +1215,8 @@ discard block |
||
| 1215 | 1215 | * @return EE_Line_Item[] |
| 1216 | 1216 | */ |
| 1217 | 1217 | public function get_cancellations() { |
| 1218 | - EE_Registry::instance()->load_helper( 'Line_Item' ); |
|
| 1219 | - return EEH_Line_Item::get_descendants_of_type( $this, EEM_Line_Item::type_cancellation ); |
|
| 1218 | + EE_Registry::instance()->load_helper('Line_Item'); |
|
| 1219 | + return EEH_Line_Item::get_descendants_of_type($this, EEM_Line_Item::type_cancellation); |
|
| 1220 | 1220 | } |
| 1221 | 1221 | |
| 1222 | 1222 | |
@@ -1227,7 +1227,7 @@ discard block |
||
| 1227 | 1227 | * @return int count of items saved |
| 1228 | 1228 | */ |
| 1229 | 1229 | public function maybe_save() { |
| 1230 | - if ( $this->ID() ) { |
|
| 1230 | + if ($this->ID()) { |
|
| 1231 | 1231 | return $this->save(); |
| 1232 | 1232 | } |
| 1233 | 1233 | return false; |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | { |
| 121 | 121 | wp_register_style( |
| 122 | 122 | 'espresso-admin-toolbar', |
| 123 | - EE_GLOBAL_ASSETS_URL . 'css/espresso-admin-toolbar.css', |
|
| 123 | + EE_GLOBAL_ASSETS_URL.'css/espresso-admin-toolbar.css', |
|
| 124 | 124 | array('dashicons'), |
| 125 | 125 | EVENT_ESPRESSO_VERSION |
| 126 | 126 | ); |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | 'href' => $this->events_admin_url, |
| 144 | 144 | 'meta' => array( |
| 145 | 145 | 'title' => esc_html__('Event Espresso', 'event_espresso'), |
| 146 | - 'class' => $this->menu_class . 'first', |
|
| 146 | + 'class' => $this->menu_class.'first', |
|
| 147 | 147 | ), |
| 148 | 148 | ) |
| 149 | 149 | ); |
@@ -491,7 +491,7 @@ discard block |
||
| 491 | 491 | 'meta' => array( |
| 492 | 492 | 'title' => esc_html__('Approved', 'event_espresso'), |
| 493 | 493 | 'target' => '', |
| 494 | - 'class' => $this->menu_class . ' ee-toolbar-icon-approved', |
|
| 494 | + 'class' => $this->menu_class.' ee-toolbar-icon-approved', |
|
| 495 | 495 | ), |
| 496 | 496 | ) |
| 497 | 497 | ); |
@@ -528,7 +528,7 @@ discard block |
||
| 528 | 528 | 'meta' => array( |
| 529 | 529 | 'title' => esc_html__('Pending Payment', 'event_espresso'), |
| 530 | 530 | 'target' => '', |
| 531 | - 'class' => $this->menu_class . ' ee-toolbar-icon-pending', |
|
| 531 | + 'class' => $this->menu_class.' ee-toolbar-icon-pending', |
|
| 532 | 532 | ), |
| 533 | 533 | ) |
| 534 | 534 | ); |
@@ -565,7 +565,7 @@ discard block |
||
| 565 | 565 | 'meta' => array( |
| 566 | 566 | 'title' => esc_html__('Not Approved', 'event_espresso'), |
| 567 | 567 | 'target' => '', |
| 568 | - 'class' => $this->menu_class . ' ee-toolbar-icon-not-approved', |
|
| 568 | + 'class' => $this->menu_class.' ee-toolbar-icon-not-approved', |
|
| 569 | 569 | ), |
| 570 | 570 | ) |
| 571 | 571 | ); |
@@ -602,7 +602,7 @@ discard block |
||
| 602 | 602 | 'meta' => array( |
| 603 | 603 | 'title' => esc_html__('Cancelled', 'event_espresso'), |
| 604 | 604 | 'target' => '', |
| 605 | - 'class' => $this->menu_class . ' ee-toolbar-icon-cancelled', |
|
| 605 | + 'class' => $this->menu_class.' ee-toolbar-icon-cancelled', |
|
| 606 | 606 | ), |
| 607 | 607 | ) |
| 608 | 608 | ); |
@@ -674,7 +674,7 @@ discard block |
||
| 674 | 674 | 'meta' => array( |
| 675 | 675 | 'title' => esc_html__('Approved', 'event_espresso'), |
| 676 | 676 | 'target' => '', |
| 677 | - 'class' => $this->menu_class . ' ee-toolbar-icon-approved', |
|
| 677 | + 'class' => $this->menu_class.' ee-toolbar-icon-approved', |
|
| 678 | 678 | ), |
| 679 | 679 | ) |
| 680 | 680 | ); |
@@ -711,7 +711,7 @@ discard block |
||
| 711 | 711 | 'meta' => array( |
| 712 | 712 | 'title' => esc_html__('Pending', 'event_espresso'), |
| 713 | 713 | 'target' => '', |
| 714 | - 'class' => $this->menu_class . ' ee-toolbar-icon-pending', |
|
| 714 | + 'class' => $this->menu_class.' ee-toolbar-icon-pending', |
|
| 715 | 715 | ), |
| 716 | 716 | ) |
| 717 | 717 | ); |
@@ -748,7 +748,7 @@ discard block |
||
| 748 | 748 | 'meta' => array( |
| 749 | 749 | 'title' => esc_html__('Not Approved', 'event_espresso'), |
| 750 | 750 | 'target' => '', |
| 751 | - 'class' => $this->menu_class . ' ee-toolbar-icon-not-approved', |
|
| 751 | + 'class' => $this->menu_class.' ee-toolbar-icon-not-approved', |
|
| 752 | 752 | ), |
| 753 | 753 | ) |
| 754 | 754 | ); |
@@ -785,7 +785,7 @@ discard block |
||
| 785 | 785 | 'meta' => array( |
| 786 | 786 | 'title' => esc_html__('Cancelled', 'event_espresso'), |
| 787 | 787 | 'target' => '', |
| 788 | - 'class' => $this->menu_class . ' ee-toolbar-icon-cancelled', |
|
| 788 | + 'class' => $this->menu_class.' ee-toolbar-icon-cancelled', |
|
| 789 | 789 | ), |
| 790 | 790 | ) |
| 791 | 791 | ); |
@@ -22,804 +22,804 @@ |
||
| 22 | 22 | class AdminToolBar |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var WP_Admin_Bar $admin_bar |
|
| 27 | - */ |
|
| 28 | - private $admin_bar; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var EE_Capabilities $capabilities |
|
| 32 | - */ |
|
| 33 | - private $capabilities; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var string $events_admin_url |
|
| 37 | - */ |
|
| 38 | - private $events_admin_url; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var string $menu_class |
|
| 42 | - */ |
|
| 43 | - private $menu_class = 'espresso_menu_item_class'; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var string $reg_admin_url |
|
| 47 | - */ |
|
| 48 | - private $reg_admin_url; |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * AdminToolBar constructor. |
|
| 54 | - * |
|
| 55 | - * @param EE_Capabilities $capabilities |
|
| 56 | - */ |
|
| 57 | - public function __construct(EE_Capabilities $capabilities) |
|
| 58 | - { |
|
| 59 | - $this->capabilities = $capabilities; |
|
| 60 | - add_action('admin_bar_menu', array($this, 'espressoToolbarItems'), 100); |
|
| 61 | - $this->enqueueAssets(); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * espresso_toolbar_items |
|
| 68 | - * |
|
| 69 | - * @access public |
|
| 70 | - * @param WP_Admin_Bar $admin_bar |
|
| 71 | - * @return void |
|
| 72 | - */ |
|
| 73 | - public function espressoToolbarItems(WP_Admin_Bar $admin_bar) |
|
| 74 | - { |
|
| 75 | - // if its an AJAX request, or user is NOT an admin, or in full M-Mode |
|
| 76 | - if ( |
|
| 77 | - defined('DOING_AJAX') |
|
| 78 | - || ! $this->capabilities->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level') |
|
| 79 | - || EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 80 | - ) { |
|
| 81 | - return; |
|
| 82 | - } |
|
| 83 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 84 | - $this->admin_bar = $admin_bar; |
|
| 85 | - //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
|
| 86 | - //because they're only defined in each of their respective constructors |
|
| 87 | - //and this might be a frontend request, in which case they aren't available |
|
| 88 | - $this->events_admin_url = admin_url('admin.php?page=espresso_events'); |
|
| 89 | - $this->reg_admin_url = admin_url('admin.php?page=espresso_registrations'); |
|
| 90 | - // now let's add all of the menu items |
|
| 91 | - $this->addTopLevelMenu(); |
|
| 92 | - $this->addEventsSubMenu(); |
|
| 93 | - $this->addEventsAddEditHeader(); |
|
| 94 | - $this->addEventsAddNew(); |
|
| 95 | - $this->addEventsEditCurrentEvent(); |
|
| 96 | - $this->addEventsViewHeader(); |
|
| 97 | - $this->addEventsViewAll(); |
|
| 98 | - $this->addEventsViewToday(); |
|
| 99 | - $this->addEventsViewThisMonth(); |
|
| 100 | - $this->addRegistrationSubMenu(); |
|
| 101 | - $this->addRegistrationOverviewToday(); |
|
| 102 | - $this->addRegistrationOverviewTodayApproved(); |
|
| 103 | - $this->addRegistrationOverviewTodayPendingPayment(); |
|
| 104 | - $this->addRegistrationOverviewTodayNotApproved(); |
|
| 105 | - $this->addRegistrationOverviewTodayCancelled(); |
|
| 106 | - $this->addRegistrationOverviewThisMonth(); |
|
| 107 | - $this->addRegistrationOverviewThisMonthApproved(); |
|
| 108 | - $this->addRegistrationOverviewThisMonthPending(); |
|
| 109 | - $this->addRegistrationOverviewThisMonthNotApproved(); |
|
| 110 | - $this->addRegistrationOverviewThisMonthCancelled(); |
|
| 111 | - $this->addExtensionsAndServices(); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * @return void |
|
| 118 | - */ |
|
| 119 | - private function enqueueAssets() |
|
| 120 | - { |
|
| 121 | - wp_register_style( |
|
| 122 | - 'espresso-admin-toolbar', |
|
| 123 | - EE_GLOBAL_ASSETS_URL . 'css/espresso-admin-toolbar.css', |
|
| 124 | - array('dashicons'), |
|
| 125 | - EVENT_ESPRESSO_VERSION |
|
| 126 | - ); |
|
| 127 | - wp_enqueue_style('espresso-admin-toolbar'); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * @return void |
|
| 134 | - */ |
|
| 135 | - private function addTopLevelMenu() |
|
| 136 | - { |
|
| 137 | - $this->admin_bar->add_menu( |
|
| 138 | - array( |
|
| 139 | - 'id' => 'espresso-toolbar', |
|
| 140 | - 'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' |
|
| 141 | - . esc_html_x('Event Espresso', 'admin bar menu group label', 'event_espresso') |
|
| 142 | - . '</span>', |
|
| 143 | - 'href' => $this->events_admin_url, |
|
| 144 | - 'meta' => array( |
|
| 145 | - 'title' => esc_html__('Event Espresso', 'event_espresso'), |
|
| 146 | - 'class' => $this->menu_class . 'first', |
|
| 147 | - ), |
|
| 148 | - ) |
|
| 149 | - ); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * @return void |
|
| 156 | - */ |
|
| 157 | - private function addEventsSubMenu() |
|
| 158 | - { |
|
| 159 | - if ( |
|
| 160 | - $this->capabilities->current_user_can( |
|
| 161 | - 'ee_read_events', |
|
| 162 | - 'ee_admin_bar_menu_espresso-toolbar-events' |
|
| 163 | - ) |
|
| 164 | - ) { |
|
| 165 | - $this->admin_bar->add_menu( |
|
| 166 | - array( |
|
| 167 | - 'id' => 'espresso-toolbar-events', |
|
| 168 | - 'parent' => 'espresso-toolbar', |
|
| 169 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 170 | - . esc_html__('Events', 'event_espresso'), |
|
| 171 | - 'href' => $this->events_admin_url, |
|
| 172 | - 'meta' => array( |
|
| 173 | - 'title' => esc_html__('Events', 'event_espresso'), |
|
| 174 | - 'target' => '', |
|
| 175 | - 'class' => $this->menu_class, |
|
| 176 | - ), |
|
| 177 | - ) |
|
| 178 | - ); |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * @return void |
|
| 186 | - */ |
|
| 187 | - private function addEventsAddEditHeader() |
|
| 188 | - { |
|
| 189 | - if ( |
|
| 190 | - $this->capabilities->current_user_can( |
|
| 191 | - 'ee_read_events', |
|
| 192 | - 'ee_admin_bar_menu_espresso-toolbar-events-view' |
|
| 193 | - ) |
|
| 194 | - ) { |
|
| 195 | - $this->admin_bar->add_menu( |
|
| 196 | - array( |
|
| 197 | - 'id' => 'espresso-toolbar-events-add-edit', |
|
| 198 | - 'parent' => 'espresso-toolbar-events', |
|
| 199 | - 'title' => esc_html__('Add / Edit', 'event_espresso'), |
|
| 200 | - 'href' => '', |
|
| 201 | - ) |
|
| 202 | - ); |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * @return void |
|
| 210 | - */ |
|
| 211 | - private function addEventsAddNew() |
|
| 212 | - { |
|
| 213 | - if ( |
|
| 214 | - $this->capabilities->current_user_can( |
|
| 215 | - 'ee_edit_events', |
|
| 216 | - 'ee_admin_bar_menu_espresso-toolbar-events-new' |
|
| 217 | - ) |
|
| 218 | - ) { |
|
| 219 | - $this->admin_bar->add_menu( |
|
| 220 | - array( |
|
| 221 | - 'id' => 'espresso-toolbar-events-new', |
|
| 222 | - 'parent' => 'espresso-toolbar-events', |
|
| 223 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 224 | - . esc_html__('Add New', 'event_espresso'), |
|
| 225 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 226 | - array('action' => 'create_new'), |
|
| 227 | - $this->events_admin_url |
|
| 228 | - ), |
|
| 229 | - 'meta' => array( |
|
| 230 | - 'title' => esc_html__('Add New', 'event_espresso'), |
|
| 231 | - 'target' => '', |
|
| 232 | - 'class' => $this->menu_class, |
|
| 233 | - ), |
|
| 234 | - ) |
|
| 235 | - ); |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * @return void |
|
| 243 | - */ |
|
| 244 | - private function addEventsEditCurrentEvent() |
|
| 245 | - { |
|
| 246 | - if (is_single() && (get_post_type() === 'espresso_events')) { |
|
| 247 | - //Current post |
|
| 248 | - global $post; |
|
| 249 | - if ( |
|
| 250 | - $this->capabilities->current_user_can( |
|
| 251 | - 'ee_edit_event', |
|
| 252 | - 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID |
|
| 253 | - ) |
|
| 254 | - ) { |
|
| 255 | - $this->admin_bar->add_menu( |
|
| 256 | - array( |
|
| 257 | - 'id' => 'espresso-toolbar-events-edit', |
|
| 258 | - 'parent' => 'espresso-toolbar-events', |
|
| 259 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 260 | - . esc_html__('Edit Event', 'event_espresso'), |
|
| 261 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 262 | - array( |
|
| 263 | - 'action' => 'edit', |
|
| 264 | - 'post' => $post->ID |
|
| 265 | - ), |
|
| 266 | - $this->events_admin_url |
|
| 267 | - ), |
|
| 268 | - 'meta' => array( |
|
| 269 | - 'title' => esc_html__('Edit Event', 'event_espresso'), |
|
| 270 | - 'target' => '', |
|
| 271 | - 'class' => $this->menu_class, |
|
| 272 | - ), |
|
| 273 | - ) |
|
| 274 | - ); |
|
| 275 | - } |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * @return void |
|
| 283 | - */ |
|
| 284 | - private function addEventsViewHeader() |
|
| 285 | - { |
|
| 286 | - if ( |
|
| 287 | - $this->capabilities->current_user_can( |
|
| 288 | - 'ee_read_events', |
|
| 289 | - 'ee_admin_bar_menu_espresso-toolbar-events-view' |
|
| 290 | - ) |
|
| 291 | - ) { |
|
| 292 | - $this->admin_bar->add_menu( |
|
| 293 | - array( |
|
| 294 | - 'id' => 'espresso-toolbar-events-view', |
|
| 295 | - 'parent' => 'espresso-toolbar-events', |
|
| 296 | - 'title' => esc_html__('View', 'event_espresso'), |
|
| 297 | - 'href' => '', |
|
| 298 | - ) |
|
| 299 | - ); |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * @return void |
|
| 307 | - */ |
|
| 308 | - private function addEventsViewAll() |
|
| 309 | - { |
|
| 310 | - if ( |
|
| 311 | - $this->capabilities->current_user_can( |
|
| 312 | - 'ee_read_events', |
|
| 313 | - 'ee_admin_bar_menu_espresso-toolbar-events-all' |
|
| 314 | - ) |
|
| 315 | - ) { |
|
| 316 | - $this->admin_bar->add_menu( |
|
| 317 | - array( |
|
| 318 | - 'id' => 'espresso-toolbar-events-all', |
|
| 319 | - 'parent' => 'espresso-toolbar-events', |
|
| 320 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 321 | - . esc_html__('All', 'event_espresso'), |
|
| 322 | - 'href' => $this->events_admin_url, |
|
| 323 | - 'meta' => array( |
|
| 324 | - 'title' => esc_html__('All', 'event_espresso'), |
|
| 325 | - 'target' => '', |
|
| 326 | - 'class' => $this->menu_class, |
|
| 327 | - ), |
|
| 328 | - ) |
|
| 329 | - ); |
|
| 330 | - } |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * @return void |
|
| 337 | - */ |
|
| 338 | - private function addEventsViewToday() |
|
| 339 | - { |
|
| 340 | - if ( |
|
| 341 | - $this->capabilities->current_user_can( |
|
| 342 | - 'ee_read_events', |
|
| 343 | - 'ee_admin_bar_menu_espresso-toolbar-events-today' |
|
| 344 | - ) |
|
| 345 | - ) { |
|
| 346 | - $this->admin_bar->add_menu( |
|
| 347 | - array( |
|
| 348 | - 'id' => 'espresso-toolbar-events-today', |
|
| 349 | - 'parent' => 'espresso-toolbar-events', |
|
| 350 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 351 | - . esc_html__('Today', 'event_espresso'), |
|
| 352 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 353 | - array( |
|
| 354 | - 'action' => 'default', |
|
| 355 | - 'status' => 'today' |
|
| 356 | - ), |
|
| 357 | - $this->events_admin_url |
|
| 358 | - ), |
|
| 359 | - 'meta' => array( |
|
| 360 | - 'title' => esc_html__('Today', 'event_espresso'), |
|
| 361 | - 'target' => '', |
|
| 362 | - 'class' => $this->menu_class, |
|
| 363 | - ), |
|
| 364 | - ) |
|
| 365 | - ); |
|
| 366 | - } |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * @return void |
|
| 373 | - */ |
|
| 374 | - private function addEventsViewThisMonth() |
|
| 375 | - { |
|
| 376 | - if ( |
|
| 377 | - $this->capabilities->current_user_can( |
|
| 378 | - 'ee_read_events', |
|
| 379 | - 'ee_admin_bar_menu_espresso-toolbar-events-month' |
|
| 380 | - ) |
|
| 381 | - ) { |
|
| 382 | - $this->admin_bar->add_menu( |
|
| 383 | - array( |
|
| 384 | - 'id' => 'espresso-toolbar-events-month', |
|
| 385 | - 'parent' => 'espresso-toolbar-events', |
|
| 386 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 387 | - . esc_html__('This Month', 'event_espresso'), |
|
| 388 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 389 | - array( |
|
| 390 | - 'action' => 'default', |
|
| 391 | - 'status' => 'month' |
|
| 392 | - ), |
|
| 393 | - $this->events_admin_url |
|
| 394 | - ), |
|
| 395 | - 'meta' => array( |
|
| 396 | - 'title' => esc_html__('This Month', 'event_espresso'), |
|
| 397 | - 'target' => '', |
|
| 398 | - 'class' => $this->menu_class, |
|
| 399 | - ), |
|
| 400 | - ) |
|
| 401 | - ); |
|
| 402 | - } |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - |
|
| 406 | - |
|
| 407 | - /** |
|
| 408 | - * @return void |
|
| 409 | - */ |
|
| 410 | - private function addRegistrationSubMenu() |
|
| 411 | - { |
|
| 412 | - if ( |
|
| 413 | - $this->capabilities->current_user_can( |
|
| 414 | - 'ee_read_registrations', |
|
| 415 | - 'ee_admin_bar_menu_espresso-toolbar-registrations' |
|
| 416 | - ) |
|
| 417 | - ) { |
|
| 418 | - $this->admin_bar->add_menu( |
|
| 419 | - array( |
|
| 420 | - 'id' => 'espresso-toolbar-registrations', |
|
| 421 | - 'parent' => 'espresso-toolbar', |
|
| 422 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 423 | - . esc_html__('Registrations', 'event_espresso'), |
|
| 424 | - 'href' => $this->reg_admin_url, |
|
| 425 | - 'meta' => array( |
|
| 426 | - 'title' => esc_html__('Registrations', 'event_espresso'), |
|
| 427 | - 'target' => '', |
|
| 428 | - 'class' => $this->menu_class, |
|
| 429 | - ), |
|
| 430 | - ) |
|
| 431 | - ); |
|
| 432 | - } |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * @return void |
|
| 439 | - */ |
|
| 440 | - private function addRegistrationOverviewToday() |
|
| 441 | - { |
|
| 442 | - if ( |
|
| 443 | - $this->capabilities->current_user_can( |
|
| 444 | - 'ee_read_registrations', |
|
| 445 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today' |
|
| 446 | - ) |
|
| 447 | - ) { |
|
| 448 | - $this->admin_bar->add_menu( |
|
| 449 | - array( |
|
| 450 | - 'id' => 'espresso-toolbar-registrations-today', |
|
| 451 | - 'parent' => 'espresso-toolbar-registrations', |
|
| 452 | - 'title' => esc_html__('Today', 'event_espresso'), |
|
| 453 | - 'href' => '', |
|
| 454 | - 'meta' => array( |
|
| 455 | - 'title' => esc_html__('Today', 'event_espresso'), |
|
| 456 | - 'target' => '', |
|
| 457 | - 'class' => $this->menu_class, |
|
| 458 | - ), |
|
| 459 | - ) |
|
| 460 | - ); |
|
| 461 | - } |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - |
|
| 465 | - |
|
| 466 | - /** |
|
| 467 | - * @return void |
|
| 468 | - */ |
|
| 469 | - private function addRegistrationOverviewTodayApproved() |
|
| 470 | - { |
|
| 471 | - if ( |
|
| 472 | - $this->capabilities->current_user_can( |
|
| 473 | - 'ee_read_registrations', |
|
| 474 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved' |
|
| 475 | - ) |
|
| 476 | - ) { |
|
| 477 | - $this->admin_bar->add_menu( |
|
| 478 | - array( |
|
| 479 | - 'id' => 'espresso-toolbar-registrations-today-approved', |
|
| 480 | - 'parent' => 'espresso-toolbar-registrations', |
|
| 481 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 482 | - . esc_html__('Approved', 'event_espresso'), |
|
| 483 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 484 | - array( |
|
| 485 | - 'action' => 'default', |
|
| 486 | - 'status' => 'today', |
|
| 487 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
| 488 | - ), |
|
| 489 | - $this->reg_admin_url |
|
| 490 | - ), |
|
| 491 | - 'meta' => array( |
|
| 492 | - 'title' => esc_html__('Approved', 'event_espresso'), |
|
| 493 | - 'target' => '', |
|
| 494 | - 'class' => $this->menu_class . ' ee-toolbar-icon-approved', |
|
| 495 | - ), |
|
| 496 | - ) |
|
| 497 | - ); |
|
| 498 | - } |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - |
|
| 502 | - |
|
| 503 | - /** |
|
| 504 | - * @return void |
|
| 505 | - */ |
|
| 506 | - private function addRegistrationOverviewTodayPendingPayment() |
|
| 507 | - { |
|
| 508 | - if ( |
|
| 509 | - $this->capabilities->current_user_can( |
|
| 510 | - 'ee_read_registrations', |
|
| 511 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending' |
|
| 512 | - ) |
|
| 513 | - ) { |
|
| 514 | - $this->admin_bar->add_menu( |
|
| 515 | - array( |
|
| 516 | - 'id' => 'espresso-toolbar-registrations-today-pending', |
|
| 517 | - 'parent' => 'espresso-toolbar-registrations', |
|
| 518 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 519 | - . esc_html__('Pending', 'event_espresso'), |
|
| 520 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 521 | - array( |
|
| 522 | - 'action' => 'default', |
|
| 523 | - 'status' => 'today', |
|
| 524 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 525 | - ), |
|
| 526 | - $this->reg_admin_url |
|
| 527 | - ), |
|
| 528 | - 'meta' => array( |
|
| 529 | - 'title' => esc_html__('Pending Payment', 'event_espresso'), |
|
| 530 | - 'target' => '', |
|
| 531 | - 'class' => $this->menu_class . ' ee-toolbar-icon-pending', |
|
| 532 | - ), |
|
| 533 | - ) |
|
| 534 | - ); |
|
| 535 | - } |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - |
|
| 539 | - |
|
| 540 | - /** |
|
| 541 | - * @return void |
|
| 542 | - */ |
|
| 543 | - private function addRegistrationOverviewTodayNotApproved() |
|
| 544 | - { |
|
| 545 | - if ( |
|
| 546 | - $this->capabilities->current_user_can( |
|
| 547 | - 'ee_read_registrations', |
|
| 548 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved' |
|
| 549 | - ) |
|
| 550 | - ) { |
|
| 551 | - $this->admin_bar->add_menu( |
|
| 552 | - array( |
|
| 553 | - 'id' => 'espresso-toolbar-registrations-today-not-approved', |
|
| 554 | - 'parent' => 'espresso-toolbar-registrations', |
|
| 555 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 556 | - . esc_html__('Not Approved', 'event_espresso'), |
|
| 557 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 558 | - array( |
|
| 559 | - 'action' => 'default', |
|
| 560 | - 'status' => 'today', |
|
| 561 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 562 | - ), |
|
| 563 | - $this->reg_admin_url |
|
| 564 | - ), |
|
| 565 | - 'meta' => array( |
|
| 566 | - 'title' => esc_html__('Not Approved', 'event_espresso'), |
|
| 567 | - 'target' => '', |
|
| 568 | - 'class' => $this->menu_class . ' ee-toolbar-icon-not-approved', |
|
| 569 | - ), |
|
| 570 | - ) |
|
| 571 | - ); |
|
| 572 | - } |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * @return void |
|
| 579 | - */ |
|
| 580 | - private function addRegistrationOverviewTodayCancelled() |
|
| 581 | - { |
|
| 582 | - if ( |
|
| 583 | - $this->capabilities->current_user_can( |
|
| 584 | - 'ee_read_registrations', |
|
| 585 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled' |
|
| 586 | - ) |
|
| 587 | - ) { |
|
| 588 | - $this->admin_bar->add_menu( |
|
| 589 | - array( |
|
| 590 | - 'id' => 'espresso-toolbar-registrations-today-cancelled', |
|
| 591 | - 'parent' => 'espresso-toolbar-registrations', |
|
| 592 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 593 | - . esc_html__('Cancelled', 'event_espresso'), |
|
| 594 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 595 | - array( |
|
| 596 | - 'action' => 'default', |
|
| 597 | - 'status' => 'today', |
|
| 598 | - '_reg_status' => EEM_Registration::status_id_cancelled, |
|
| 599 | - ), |
|
| 600 | - $this->reg_admin_url |
|
| 601 | - ), |
|
| 602 | - 'meta' => array( |
|
| 603 | - 'title' => esc_html__('Cancelled', 'event_espresso'), |
|
| 604 | - 'target' => '', |
|
| 605 | - 'class' => $this->menu_class . ' ee-toolbar-icon-cancelled', |
|
| 606 | - ), |
|
| 607 | - ) |
|
| 608 | - ); |
|
| 609 | - } |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - |
|
| 613 | - |
|
| 614 | - /** |
|
| 615 | - * @return void |
|
| 616 | - */ |
|
| 617 | - private function addRegistrationOverviewThisMonth() |
|
| 618 | - { |
|
| 619 | - if ( |
|
| 620 | - $this->capabilities->current_user_can( |
|
| 621 | - 'ee_read_registrations', |
|
| 622 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month' |
|
| 623 | - ) |
|
| 624 | - ) { |
|
| 625 | - $this->admin_bar->add_menu( |
|
| 626 | - array( |
|
| 627 | - 'id' => 'espresso-toolbar-registrations-month', |
|
| 628 | - 'parent' => 'espresso-toolbar-registrations', |
|
| 629 | - 'title' => esc_html__('This Month', 'event_espresso'), |
|
| 630 | - 'href' => '', //EEH_URL::add_query_args_and_nonce( |
|
| 631 | - // array( |
|
| 632 | - // 'action' => 'default', |
|
| 633 | - // 'status' => 'month' |
|
| 634 | - // ), |
|
| 635 | - // $this->reg_admin_url |
|
| 636 | - // ), |
|
| 637 | - 'meta' => array( |
|
| 638 | - 'title' => esc_html__('This Month', 'event_espresso'), |
|
| 639 | - 'target' => '', |
|
| 640 | - 'class' => $this->menu_class, |
|
| 641 | - ), |
|
| 642 | - ) |
|
| 643 | - ); |
|
| 644 | - } |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - |
|
| 648 | - |
|
| 649 | - /** |
|
| 650 | - * @return void |
|
| 651 | - */ |
|
| 652 | - private function addRegistrationOverviewThisMonthApproved() |
|
| 653 | - { |
|
| 654 | - if ( |
|
| 655 | - $this->capabilities->current_user_can( |
|
| 656 | - 'ee_read_registrations', |
|
| 657 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved' |
|
| 658 | - ) |
|
| 659 | - ) { |
|
| 660 | - $this->admin_bar->add_menu( |
|
| 661 | - array( |
|
| 662 | - 'id' => 'espresso-toolbar-registrations-month-approved', |
|
| 663 | - 'parent' => 'espresso-toolbar-registrations', |
|
| 664 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 665 | - . esc_html__('Approved', 'event_espresso'), |
|
| 666 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 667 | - array( |
|
| 668 | - 'action' => 'default', |
|
| 669 | - 'status' => 'month', |
|
| 670 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
| 671 | - ), |
|
| 672 | - $this->reg_admin_url |
|
| 673 | - ), |
|
| 674 | - 'meta' => array( |
|
| 675 | - 'title' => esc_html__('Approved', 'event_espresso'), |
|
| 676 | - 'target' => '', |
|
| 677 | - 'class' => $this->menu_class . ' ee-toolbar-icon-approved', |
|
| 678 | - ), |
|
| 679 | - ) |
|
| 680 | - ); |
|
| 681 | - } |
|
| 682 | - } |
|
| 683 | - |
|
| 684 | - |
|
| 685 | - |
|
| 686 | - /** |
|
| 687 | - * @return void |
|
| 688 | - */ |
|
| 689 | - private function addRegistrationOverviewThisMonthPending() |
|
| 690 | - { |
|
| 691 | - if ( |
|
| 692 | - $this->capabilities->current_user_can( |
|
| 693 | - 'ee_read_registrations', |
|
| 694 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending' |
|
| 695 | - ) |
|
| 696 | - ) { |
|
| 697 | - $this->admin_bar->add_menu( |
|
| 698 | - array( |
|
| 699 | - 'id' => 'espresso-toolbar-registrations-month-pending', |
|
| 700 | - 'parent' => 'espresso-toolbar-registrations', |
|
| 701 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 702 | - . esc_html__('Pending', 'event_espresso'), |
|
| 703 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 704 | - array( |
|
| 705 | - 'action' => 'default', |
|
| 706 | - 'status' => 'month', |
|
| 707 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 708 | - ), |
|
| 709 | - $this->reg_admin_url |
|
| 710 | - ), |
|
| 711 | - 'meta' => array( |
|
| 712 | - 'title' => esc_html__('Pending', 'event_espresso'), |
|
| 713 | - 'target' => '', |
|
| 714 | - 'class' => $this->menu_class . ' ee-toolbar-icon-pending', |
|
| 715 | - ), |
|
| 716 | - ) |
|
| 717 | - ); |
|
| 718 | - } |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - |
|
| 722 | - |
|
| 723 | - /** |
|
| 724 | - * @return void |
|
| 725 | - */ |
|
| 726 | - private function addRegistrationOverviewThisMonthNotApproved() |
|
| 727 | - { |
|
| 728 | - if ( |
|
| 729 | - $this->capabilities->current_user_can( |
|
| 730 | - 'ee_read_registrations', |
|
| 731 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved' |
|
| 732 | - ) |
|
| 733 | - ) { |
|
| 734 | - $this->admin_bar->add_menu( |
|
| 735 | - array( |
|
| 736 | - 'id' => 'espresso-toolbar-registrations-month-not-approved', |
|
| 737 | - 'parent' => 'espresso-toolbar-registrations', |
|
| 738 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 739 | - . esc_html__('Not Approved', 'event_espresso'), |
|
| 740 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 741 | - array( |
|
| 742 | - 'action' => 'default', |
|
| 743 | - 'status' => 'month', |
|
| 744 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 745 | - ), |
|
| 746 | - $this->reg_admin_url |
|
| 747 | - ), |
|
| 748 | - 'meta' => array( |
|
| 749 | - 'title' => esc_html__('Not Approved', 'event_espresso'), |
|
| 750 | - 'target' => '', |
|
| 751 | - 'class' => $this->menu_class . ' ee-toolbar-icon-not-approved', |
|
| 752 | - ), |
|
| 753 | - ) |
|
| 754 | - ); |
|
| 755 | - } |
|
| 756 | - } |
|
| 757 | - |
|
| 758 | - |
|
| 759 | - |
|
| 760 | - /** |
|
| 761 | - * @return void |
|
| 762 | - */ |
|
| 763 | - private function addRegistrationOverviewThisMonthCancelled() |
|
| 764 | - { |
|
| 765 | - if ( |
|
| 766 | - $this->capabilities->current_user_can( |
|
| 767 | - 'ee_read_registrations', |
|
| 768 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled' |
|
| 769 | - ) |
|
| 770 | - ) { |
|
| 771 | - $this->admin_bar->add_menu( |
|
| 772 | - array( |
|
| 773 | - 'id' => 'espresso-toolbar-registrations-month-cancelled', |
|
| 774 | - 'parent' => 'espresso-toolbar-registrations', |
|
| 775 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 776 | - . esc_html__('Cancelled', 'event_espresso'), |
|
| 777 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 778 | - array( |
|
| 779 | - 'action' => 'default', |
|
| 780 | - 'status' => 'month', |
|
| 781 | - '_reg_status' => EEM_Registration::status_id_cancelled, |
|
| 782 | - ), |
|
| 783 | - $this->reg_admin_url |
|
| 784 | - ), |
|
| 785 | - 'meta' => array( |
|
| 786 | - 'title' => esc_html__('Cancelled', 'event_espresso'), |
|
| 787 | - 'target' => '', |
|
| 788 | - 'class' => $this->menu_class . ' ee-toolbar-icon-cancelled', |
|
| 789 | - ), |
|
| 790 | - ) |
|
| 791 | - ); |
|
| 792 | - } |
|
| 793 | - } |
|
| 794 | - |
|
| 795 | - |
|
| 796 | - |
|
| 797 | - /** |
|
| 798 | - * @return void |
|
| 799 | - */ |
|
| 800 | - private function addExtensionsAndServices() |
|
| 801 | - { |
|
| 802 | - if ( |
|
| 803 | - $this->capabilities->current_user_can( |
|
| 804 | - 'ee_read_ee', |
|
| 805 | - 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services' |
|
| 806 | - ) |
|
| 807 | - ) { |
|
| 808 | - $this->admin_bar->add_menu( |
|
| 809 | - array( |
|
| 810 | - 'id' => 'espresso-toolbar-extensions-and-services', |
|
| 811 | - 'parent' => 'espresso-toolbar', |
|
| 812 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 813 | - . esc_html__('Extensions & Services', 'event_espresso'), |
|
| 814 | - 'href' => admin_url('admin.php?page=espresso_packages'), |
|
| 815 | - 'meta' => array( |
|
| 816 | - 'title' => esc_html__('Extensions & Services', 'event_espresso'), |
|
| 817 | - 'target' => '', |
|
| 818 | - 'class' => $this->menu_class, |
|
| 819 | - ), |
|
| 820 | - ) |
|
| 821 | - ); |
|
| 822 | - } |
|
| 823 | - } |
|
| 25 | + /** |
|
| 26 | + * @var WP_Admin_Bar $admin_bar |
|
| 27 | + */ |
|
| 28 | + private $admin_bar; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var EE_Capabilities $capabilities |
|
| 32 | + */ |
|
| 33 | + private $capabilities; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var string $events_admin_url |
|
| 37 | + */ |
|
| 38 | + private $events_admin_url; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var string $menu_class |
|
| 42 | + */ |
|
| 43 | + private $menu_class = 'espresso_menu_item_class'; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var string $reg_admin_url |
|
| 47 | + */ |
|
| 48 | + private $reg_admin_url; |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * AdminToolBar constructor. |
|
| 54 | + * |
|
| 55 | + * @param EE_Capabilities $capabilities |
|
| 56 | + */ |
|
| 57 | + public function __construct(EE_Capabilities $capabilities) |
|
| 58 | + { |
|
| 59 | + $this->capabilities = $capabilities; |
|
| 60 | + add_action('admin_bar_menu', array($this, 'espressoToolbarItems'), 100); |
|
| 61 | + $this->enqueueAssets(); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * espresso_toolbar_items |
|
| 68 | + * |
|
| 69 | + * @access public |
|
| 70 | + * @param WP_Admin_Bar $admin_bar |
|
| 71 | + * @return void |
|
| 72 | + */ |
|
| 73 | + public function espressoToolbarItems(WP_Admin_Bar $admin_bar) |
|
| 74 | + { |
|
| 75 | + // if its an AJAX request, or user is NOT an admin, or in full M-Mode |
|
| 76 | + if ( |
|
| 77 | + defined('DOING_AJAX') |
|
| 78 | + || ! $this->capabilities->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level') |
|
| 79 | + || EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 80 | + ) { |
|
| 81 | + return; |
|
| 82 | + } |
|
| 83 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 84 | + $this->admin_bar = $admin_bar; |
|
| 85 | + //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
|
| 86 | + //because they're only defined in each of their respective constructors |
|
| 87 | + //and this might be a frontend request, in which case they aren't available |
|
| 88 | + $this->events_admin_url = admin_url('admin.php?page=espresso_events'); |
|
| 89 | + $this->reg_admin_url = admin_url('admin.php?page=espresso_registrations'); |
|
| 90 | + // now let's add all of the menu items |
|
| 91 | + $this->addTopLevelMenu(); |
|
| 92 | + $this->addEventsSubMenu(); |
|
| 93 | + $this->addEventsAddEditHeader(); |
|
| 94 | + $this->addEventsAddNew(); |
|
| 95 | + $this->addEventsEditCurrentEvent(); |
|
| 96 | + $this->addEventsViewHeader(); |
|
| 97 | + $this->addEventsViewAll(); |
|
| 98 | + $this->addEventsViewToday(); |
|
| 99 | + $this->addEventsViewThisMonth(); |
|
| 100 | + $this->addRegistrationSubMenu(); |
|
| 101 | + $this->addRegistrationOverviewToday(); |
|
| 102 | + $this->addRegistrationOverviewTodayApproved(); |
|
| 103 | + $this->addRegistrationOverviewTodayPendingPayment(); |
|
| 104 | + $this->addRegistrationOverviewTodayNotApproved(); |
|
| 105 | + $this->addRegistrationOverviewTodayCancelled(); |
|
| 106 | + $this->addRegistrationOverviewThisMonth(); |
|
| 107 | + $this->addRegistrationOverviewThisMonthApproved(); |
|
| 108 | + $this->addRegistrationOverviewThisMonthPending(); |
|
| 109 | + $this->addRegistrationOverviewThisMonthNotApproved(); |
|
| 110 | + $this->addRegistrationOverviewThisMonthCancelled(); |
|
| 111 | + $this->addExtensionsAndServices(); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * @return void |
|
| 118 | + */ |
|
| 119 | + private function enqueueAssets() |
|
| 120 | + { |
|
| 121 | + wp_register_style( |
|
| 122 | + 'espresso-admin-toolbar', |
|
| 123 | + EE_GLOBAL_ASSETS_URL . 'css/espresso-admin-toolbar.css', |
|
| 124 | + array('dashicons'), |
|
| 125 | + EVENT_ESPRESSO_VERSION |
|
| 126 | + ); |
|
| 127 | + wp_enqueue_style('espresso-admin-toolbar'); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * @return void |
|
| 134 | + */ |
|
| 135 | + private function addTopLevelMenu() |
|
| 136 | + { |
|
| 137 | + $this->admin_bar->add_menu( |
|
| 138 | + array( |
|
| 139 | + 'id' => 'espresso-toolbar', |
|
| 140 | + 'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' |
|
| 141 | + . esc_html_x('Event Espresso', 'admin bar menu group label', 'event_espresso') |
|
| 142 | + . '</span>', |
|
| 143 | + 'href' => $this->events_admin_url, |
|
| 144 | + 'meta' => array( |
|
| 145 | + 'title' => esc_html__('Event Espresso', 'event_espresso'), |
|
| 146 | + 'class' => $this->menu_class . 'first', |
|
| 147 | + ), |
|
| 148 | + ) |
|
| 149 | + ); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * @return void |
|
| 156 | + */ |
|
| 157 | + private function addEventsSubMenu() |
|
| 158 | + { |
|
| 159 | + if ( |
|
| 160 | + $this->capabilities->current_user_can( |
|
| 161 | + 'ee_read_events', |
|
| 162 | + 'ee_admin_bar_menu_espresso-toolbar-events' |
|
| 163 | + ) |
|
| 164 | + ) { |
|
| 165 | + $this->admin_bar->add_menu( |
|
| 166 | + array( |
|
| 167 | + 'id' => 'espresso-toolbar-events', |
|
| 168 | + 'parent' => 'espresso-toolbar', |
|
| 169 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 170 | + . esc_html__('Events', 'event_espresso'), |
|
| 171 | + 'href' => $this->events_admin_url, |
|
| 172 | + 'meta' => array( |
|
| 173 | + 'title' => esc_html__('Events', 'event_espresso'), |
|
| 174 | + 'target' => '', |
|
| 175 | + 'class' => $this->menu_class, |
|
| 176 | + ), |
|
| 177 | + ) |
|
| 178 | + ); |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * @return void |
|
| 186 | + */ |
|
| 187 | + private function addEventsAddEditHeader() |
|
| 188 | + { |
|
| 189 | + if ( |
|
| 190 | + $this->capabilities->current_user_can( |
|
| 191 | + 'ee_read_events', |
|
| 192 | + 'ee_admin_bar_menu_espresso-toolbar-events-view' |
|
| 193 | + ) |
|
| 194 | + ) { |
|
| 195 | + $this->admin_bar->add_menu( |
|
| 196 | + array( |
|
| 197 | + 'id' => 'espresso-toolbar-events-add-edit', |
|
| 198 | + 'parent' => 'espresso-toolbar-events', |
|
| 199 | + 'title' => esc_html__('Add / Edit', 'event_espresso'), |
|
| 200 | + 'href' => '', |
|
| 201 | + ) |
|
| 202 | + ); |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * @return void |
|
| 210 | + */ |
|
| 211 | + private function addEventsAddNew() |
|
| 212 | + { |
|
| 213 | + if ( |
|
| 214 | + $this->capabilities->current_user_can( |
|
| 215 | + 'ee_edit_events', |
|
| 216 | + 'ee_admin_bar_menu_espresso-toolbar-events-new' |
|
| 217 | + ) |
|
| 218 | + ) { |
|
| 219 | + $this->admin_bar->add_menu( |
|
| 220 | + array( |
|
| 221 | + 'id' => 'espresso-toolbar-events-new', |
|
| 222 | + 'parent' => 'espresso-toolbar-events', |
|
| 223 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 224 | + . esc_html__('Add New', 'event_espresso'), |
|
| 225 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 226 | + array('action' => 'create_new'), |
|
| 227 | + $this->events_admin_url |
|
| 228 | + ), |
|
| 229 | + 'meta' => array( |
|
| 230 | + 'title' => esc_html__('Add New', 'event_espresso'), |
|
| 231 | + 'target' => '', |
|
| 232 | + 'class' => $this->menu_class, |
|
| 233 | + ), |
|
| 234 | + ) |
|
| 235 | + ); |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * @return void |
|
| 243 | + */ |
|
| 244 | + private function addEventsEditCurrentEvent() |
|
| 245 | + { |
|
| 246 | + if (is_single() && (get_post_type() === 'espresso_events')) { |
|
| 247 | + //Current post |
|
| 248 | + global $post; |
|
| 249 | + if ( |
|
| 250 | + $this->capabilities->current_user_can( |
|
| 251 | + 'ee_edit_event', |
|
| 252 | + 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID |
|
| 253 | + ) |
|
| 254 | + ) { |
|
| 255 | + $this->admin_bar->add_menu( |
|
| 256 | + array( |
|
| 257 | + 'id' => 'espresso-toolbar-events-edit', |
|
| 258 | + 'parent' => 'espresso-toolbar-events', |
|
| 259 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 260 | + . esc_html__('Edit Event', 'event_espresso'), |
|
| 261 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 262 | + array( |
|
| 263 | + 'action' => 'edit', |
|
| 264 | + 'post' => $post->ID |
|
| 265 | + ), |
|
| 266 | + $this->events_admin_url |
|
| 267 | + ), |
|
| 268 | + 'meta' => array( |
|
| 269 | + 'title' => esc_html__('Edit Event', 'event_espresso'), |
|
| 270 | + 'target' => '', |
|
| 271 | + 'class' => $this->menu_class, |
|
| 272 | + ), |
|
| 273 | + ) |
|
| 274 | + ); |
|
| 275 | + } |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * @return void |
|
| 283 | + */ |
|
| 284 | + private function addEventsViewHeader() |
|
| 285 | + { |
|
| 286 | + if ( |
|
| 287 | + $this->capabilities->current_user_can( |
|
| 288 | + 'ee_read_events', |
|
| 289 | + 'ee_admin_bar_menu_espresso-toolbar-events-view' |
|
| 290 | + ) |
|
| 291 | + ) { |
|
| 292 | + $this->admin_bar->add_menu( |
|
| 293 | + array( |
|
| 294 | + 'id' => 'espresso-toolbar-events-view', |
|
| 295 | + 'parent' => 'espresso-toolbar-events', |
|
| 296 | + 'title' => esc_html__('View', 'event_espresso'), |
|
| 297 | + 'href' => '', |
|
| 298 | + ) |
|
| 299 | + ); |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * @return void |
|
| 307 | + */ |
|
| 308 | + private function addEventsViewAll() |
|
| 309 | + { |
|
| 310 | + if ( |
|
| 311 | + $this->capabilities->current_user_can( |
|
| 312 | + 'ee_read_events', |
|
| 313 | + 'ee_admin_bar_menu_espresso-toolbar-events-all' |
|
| 314 | + ) |
|
| 315 | + ) { |
|
| 316 | + $this->admin_bar->add_menu( |
|
| 317 | + array( |
|
| 318 | + 'id' => 'espresso-toolbar-events-all', |
|
| 319 | + 'parent' => 'espresso-toolbar-events', |
|
| 320 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 321 | + . esc_html__('All', 'event_espresso'), |
|
| 322 | + 'href' => $this->events_admin_url, |
|
| 323 | + 'meta' => array( |
|
| 324 | + 'title' => esc_html__('All', 'event_espresso'), |
|
| 325 | + 'target' => '', |
|
| 326 | + 'class' => $this->menu_class, |
|
| 327 | + ), |
|
| 328 | + ) |
|
| 329 | + ); |
|
| 330 | + } |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * @return void |
|
| 337 | + */ |
|
| 338 | + private function addEventsViewToday() |
|
| 339 | + { |
|
| 340 | + if ( |
|
| 341 | + $this->capabilities->current_user_can( |
|
| 342 | + 'ee_read_events', |
|
| 343 | + 'ee_admin_bar_menu_espresso-toolbar-events-today' |
|
| 344 | + ) |
|
| 345 | + ) { |
|
| 346 | + $this->admin_bar->add_menu( |
|
| 347 | + array( |
|
| 348 | + 'id' => 'espresso-toolbar-events-today', |
|
| 349 | + 'parent' => 'espresso-toolbar-events', |
|
| 350 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 351 | + . esc_html__('Today', 'event_espresso'), |
|
| 352 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 353 | + array( |
|
| 354 | + 'action' => 'default', |
|
| 355 | + 'status' => 'today' |
|
| 356 | + ), |
|
| 357 | + $this->events_admin_url |
|
| 358 | + ), |
|
| 359 | + 'meta' => array( |
|
| 360 | + 'title' => esc_html__('Today', 'event_espresso'), |
|
| 361 | + 'target' => '', |
|
| 362 | + 'class' => $this->menu_class, |
|
| 363 | + ), |
|
| 364 | + ) |
|
| 365 | + ); |
|
| 366 | + } |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * @return void |
|
| 373 | + */ |
|
| 374 | + private function addEventsViewThisMonth() |
|
| 375 | + { |
|
| 376 | + if ( |
|
| 377 | + $this->capabilities->current_user_can( |
|
| 378 | + 'ee_read_events', |
|
| 379 | + 'ee_admin_bar_menu_espresso-toolbar-events-month' |
|
| 380 | + ) |
|
| 381 | + ) { |
|
| 382 | + $this->admin_bar->add_menu( |
|
| 383 | + array( |
|
| 384 | + 'id' => 'espresso-toolbar-events-month', |
|
| 385 | + 'parent' => 'espresso-toolbar-events', |
|
| 386 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 387 | + . esc_html__('This Month', 'event_espresso'), |
|
| 388 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 389 | + array( |
|
| 390 | + 'action' => 'default', |
|
| 391 | + 'status' => 'month' |
|
| 392 | + ), |
|
| 393 | + $this->events_admin_url |
|
| 394 | + ), |
|
| 395 | + 'meta' => array( |
|
| 396 | + 'title' => esc_html__('This Month', 'event_espresso'), |
|
| 397 | + 'target' => '', |
|
| 398 | + 'class' => $this->menu_class, |
|
| 399 | + ), |
|
| 400 | + ) |
|
| 401 | + ); |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + |
|
| 406 | + |
|
| 407 | + /** |
|
| 408 | + * @return void |
|
| 409 | + */ |
|
| 410 | + private function addRegistrationSubMenu() |
|
| 411 | + { |
|
| 412 | + if ( |
|
| 413 | + $this->capabilities->current_user_can( |
|
| 414 | + 'ee_read_registrations', |
|
| 415 | + 'ee_admin_bar_menu_espresso-toolbar-registrations' |
|
| 416 | + ) |
|
| 417 | + ) { |
|
| 418 | + $this->admin_bar->add_menu( |
|
| 419 | + array( |
|
| 420 | + 'id' => 'espresso-toolbar-registrations', |
|
| 421 | + 'parent' => 'espresso-toolbar', |
|
| 422 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 423 | + . esc_html__('Registrations', 'event_espresso'), |
|
| 424 | + 'href' => $this->reg_admin_url, |
|
| 425 | + 'meta' => array( |
|
| 426 | + 'title' => esc_html__('Registrations', 'event_espresso'), |
|
| 427 | + 'target' => '', |
|
| 428 | + 'class' => $this->menu_class, |
|
| 429 | + ), |
|
| 430 | + ) |
|
| 431 | + ); |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * @return void |
|
| 439 | + */ |
|
| 440 | + private function addRegistrationOverviewToday() |
|
| 441 | + { |
|
| 442 | + if ( |
|
| 443 | + $this->capabilities->current_user_can( |
|
| 444 | + 'ee_read_registrations', |
|
| 445 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today' |
|
| 446 | + ) |
|
| 447 | + ) { |
|
| 448 | + $this->admin_bar->add_menu( |
|
| 449 | + array( |
|
| 450 | + 'id' => 'espresso-toolbar-registrations-today', |
|
| 451 | + 'parent' => 'espresso-toolbar-registrations', |
|
| 452 | + 'title' => esc_html__('Today', 'event_espresso'), |
|
| 453 | + 'href' => '', |
|
| 454 | + 'meta' => array( |
|
| 455 | + 'title' => esc_html__('Today', 'event_espresso'), |
|
| 456 | + 'target' => '', |
|
| 457 | + 'class' => $this->menu_class, |
|
| 458 | + ), |
|
| 459 | + ) |
|
| 460 | + ); |
|
| 461 | + } |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + |
|
| 465 | + |
|
| 466 | + /** |
|
| 467 | + * @return void |
|
| 468 | + */ |
|
| 469 | + private function addRegistrationOverviewTodayApproved() |
|
| 470 | + { |
|
| 471 | + if ( |
|
| 472 | + $this->capabilities->current_user_can( |
|
| 473 | + 'ee_read_registrations', |
|
| 474 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved' |
|
| 475 | + ) |
|
| 476 | + ) { |
|
| 477 | + $this->admin_bar->add_menu( |
|
| 478 | + array( |
|
| 479 | + 'id' => 'espresso-toolbar-registrations-today-approved', |
|
| 480 | + 'parent' => 'espresso-toolbar-registrations', |
|
| 481 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 482 | + . esc_html__('Approved', 'event_espresso'), |
|
| 483 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 484 | + array( |
|
| 485 | + 'action' => 'default', |
|
| 486 | + 'status' => 'today', |
|
| 487 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
| 488 | + ), |
|
| 489 | + $this->reg_admin_url |
|
| 490 | + ), |
|
| 491 | + 'meta' => array( |
|
| 492 | + 'title' => esc_html__('Approved', 'event_espresso'), |
|
| 493 | + 'target' => '', |
|
| 494 | + 'class' => $this->menu_class . ' ee-toolbar-icon-approved', |
|
| 495 | + ), |
|
| 496 | + ) |
|
| 497 | + ); |
|
| 498 | + } |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + |
|
| 502 | + |
|
| 503 | + /** |
|
| 504 | + * @return void |
|
| 505 | + */ |
|
| 506 | + private function addRegistrationOverviewTodayPendingPayment() |
|
| 507 | + { |
|
| 508 | + if ( |
|
| 509 | + $this->capabilities->current_user_can( |
|
| 510 | + 'ee_read_registrations', |
|
| 511 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending' |
|
| 512 | + ) |
|
| 513 | + ) { |
|
| 514 | + $this->admin_bar->add_menu( |
|
| 515 | + array( |
|
| 516 | + 'id' => 'espresso-toolbar-registrations-today-pending', |
|
| 517 | + 'parent' => 'espresso-toolbar-registrations', |
|
| 518 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 519 | + . esc_html__('Pending', 'event_espresso'), |
|
| 520 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 521 | + array( |
|
| 522 | + 'action' => 'default', |
|
| 523 | + 'status' => 'today', |
|
| 524 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 525 | + ), |
|
| 526 | + $this->reg_admin_url |
|
| 527 | + ), |
|
| 528 | + 'meta' => array( |
|
| 529 | + 'title' => esc_html__('Pending Payment', 'event_espresso'), |
|
| 530 | + 'target' => '', |
|
| 531 | + 'class' => $this->menu_class . ' ee-toolbar-icon-pending', |
|
| 532 | + ), |
|
| 533 | + ) |
|
| 534 | + ); |
|
| 535 | + } |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + |
|
| 539 | + |
|
| 540 | + /** |
|
| 541 | + * @return void |
|
| 542 | + */ |
|
| 543 | + private function addRegistrationOverviewTodayNotApproved() |
|
| 544 | + { |
|
| 545 | + if ( |
|
| 546 | + $this->capabilities->current_user_can( |
|
| 547 | + 'ee_read_registrations', |
|
| 548 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved' |
|
| 549 | + ) |
|
| 550 | + ) { |
|
| 551 | + $this->admin_bar->add_menu( |
|
| 552 | + array( |
|
| 553 | + 'id' => 'espresso-toolbar-registrations-today-not-approved', |
|
| 554 | + 'parent' => 'espresso-toolbar-registrations', |
|
| 555 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 556 | + . esc_html__('Not Approved', 'event_espresso'), |
|
| 557 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 558 | + array( |
|
| 559 | + 'action' => 'default', |
|
| 560 | + 'status' => 'today', |
|
| 561 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 562 | + ), |
|
| 563 | + $this->reg_admin_url |
|
| 564 | + ), |
|
| 565 | + 'meta' => array( |
|
| 566 | + 'title' => esc_html__('Not Approved', 'event_espresso'), |
|
| 567 | + 'target' => '', |
|
| 568 | + 'class' => $this->menu_class . ' ee-toolbar-icon-not-approved', |
|
| 569 | + ), |
|
| 570 | + ) |
|
| 571 | + ); |
|
| 572 | + } |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * @return void |
|
| 579 | + */ |
|
| 580 | + private function addRegistrationOverviewTodayCancelled() |
|
| 581 | + { |
|
| 582 | + if ( |
|
| 583 | + $this->capabilities->current_user_can( |
|
| 584 | + 'ee_read_registrations', |
|
| 585 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled' |
|
| 586 | + ) |
|
| 587 | + ) { |
|
| 588 | + $this->admin_bar->add_menu( |
|
| 589 | + array( |
|
| 590 | + 'id' => 'espresso-toolbar-registrations-today-cancelled', |
|
| 591 | + 'parent' => 'espresso-toolbar-registrations', |
|
| 592 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 593 | + . esc_html__('Cancelled', 'event_espresso'), |
|
| 594 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 595 | + array( |
|
| 596 | + 'action' => 'default', |
|
| 597 | + 'status' => 'today', |
|
| 598 | + '_reg_status' => EEM_Registration::status_id_cancelled, |
|
| 599 | + ), |
|
| 600 | + $this->reg_admin_url |
|
| 601 | + ), |
|
| 602 | + 'meta' => array( |
|
| 603 | + 'title' => esc_html__('Cancelled', 'event_espresso'), |
|
| 604 | + 'target' => '', |
|
| 605 | + 'class' => $this->menu_class . ' ee-toolbar-icon-cancelled', |
|
| 606 | + ), |
|
| 607 | + ) |
|
| 608 | + ); |
|
| 609 | + } |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + |
|
| 613 | + |
|
| 614 | + /** |
|
| 615 | + * @return void |
|
| 616 | + */ |
|
| 617 | + private function addRegistrationOverviewThisMonth() |
|
| 618 | + { |
|
| 619 | + if ( |
|
| 620 | + $this->capabilities->current_user_can( |
|
| 621 | + 'ee_read_registrations', |
|
| 622 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month' |
|
| 623 | + ) |
|
| 624 | + ) { |
|
| 625 | + $this->admin_bar->add_menu( |
|
| 626 | + array( |
|
| 627 | + 'id' => 'espresso-toolbar-registrations-month', |
|
| 628 | + 'parent' => 'espresso-toolbar-registrations', |
|
| 629 | + 'title' => esc_html__('This Month', 'event_espresso'), |
|
| 630 | + 'href' => '', //EEH_URL::add_query_args_and_nonce( |
|
| 631 | + // array( |
|
| 632 | + // 'action' => 'default', |
|
| 633 | + // 'status' => 'month' |
|
| 634 | + // ), |
|
| 635 | + // $this->reg_admin_url |
|
| 636 | + // ), |
|
| 637 | + 'meta' => array( |
|
| 638 | + 'title' => esc_html__('This Month', 'event_espresso'), |
|
| 639 | + 'target' => '', |
|
| 640 | + 'class' => $this->menu_class, |
|
| 641 | + ), |
|
| 642 | + ) |
|
| 643 | + ); |
|
| 644 | + } |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + |
|
| 648 | + |
|
| 649 | + /** |
|
| 650 | + * @return void |
|
| 651 | + */ |
|
| 652 | + private function addRegistrationOverviewThisMonthApproved() |
|
| 653 | + { |
|
| 654 | + if ( |
|
| 655 | + $this->capabilities->current_user_can( |
|
| 656 | + 'ee_read_registrations', |
|
| 657 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved' |
|
| 658 | + ) |
|
| 659 | + ) { |
|
| 660 | + $this->admin_bar->add_menu( |
|
| 661 | + array( |
|
| 662 | + 'id' => 'espresso-toolbar-registrations-month-approved', |
|
| 663 | + 'parent' => 'espresso-toolbar-registrations', |
|
| 664 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 665 | + . esc_html__('Approved', 'event_espresso'), |
|
| 666 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 667 | + array( |
|
| 668 | + 'action' => 'default', |
|
| 669 | + 'status' => 'month', |
|
| 670 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
| 671 | + ), |
|
| 672 | + $this->reg_admin_url |
|
| 673 | + ), |
|
| 674 | + 'meta' => array( |
|
| 675 | + 'title' => esc_html__('Approved', 'event_espresso'), |
|
| 676 | + 'target' => '', |
|
| 677 | + 'class' => $this->menu_class . ' ee-toolbar-icon-approved', |
|
| 678 | + ), |
|
| 679 | + ) |
|
| 680 | + ); |
|
| 681 | + } |
|
| 682 | + } |
|
| 683 | + |
|
| 684 | + |
|
| 685 | + |
|
| 686 | + /** |
|
| 687 | + * @return void |
|
| 688 | + */ |
|
| 689 | + private function addRegistrationOverviewThisMonthPending() |
|
| 690 | + { |
|
| 691 | + if ( |
|
| 692 | + $this->capabilities->current_user_can( |
|
| 693 | + 'ee_read_registrations', |
|
| 694 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending' |
|
| 695 | + ) |
|
| 696 | + ) { |
|
| 697 | + $this->admin_bar->add_menu( |
|
| 698 | + array( |
|
| 699 | + 'id' => 'espresso-toolbar-registrations-month-pending', |
|
| 700 | + 'parent' => 'espresso-toolbar-registrations', |
|
| 701 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 702 | + . esc_html__('Pending', 'event_espresso'), |
|
| 703 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 704 | + array( |
|
| 705 | + 'action' => 'default', |
|
| 706 | + 'status' => 'month', |
|
| 707 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 708 | + ), |
|
| 709 | + $this->reg_admin_url |
|
| 710 | + ), |
|
| 711 | + 'meta' => array( |
|
| 712 | + 'title' => esc_html__('Pending', 'event_espresso'), |
|
| 713 | + 'target' => '', |
|
| 714 | + 'class' => $this->menu_class . ' ee-toolbar-icon-pending', |
|
| 715 | + ), |
|
| 716 | + ) |
|
| 717 | + ); |
|
| 718 | + } |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + |
|
| 722 | + |
|
| 723 | + /** |
|
| 724 | + * @return void |
|
| 725 | + */ |
|
| 726 | + private function addRegistrationOverviewThisMonthNotApproved() |
|
| 727 | + { |
|
| 728 | + if ( |
|
| 729 | + $this->capabilities->current_user_can( |
|
| 730 | + 'ee_read_registrations', |
|
| 731 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved' |
|
| 732 | + ) |
|
| 733 | + ) { |
|
| 734 | + $this->admin_bar->add_menu( |
|
| 735 | + array( |
|
| 736 | + 'id' => 'espresso-toolbar-registrations-month-not-approved', |
|
| 737 | + 'parent' => 'espresso-toolbar-registrations', |
|
| 738 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 739 | + . esc_html__('Not Approved', 'event_espresso'), |
|
| 740 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 741 | + array( |
|
| 742 | + 'action' => 'default', |
|
| 743 | + 'status' => 'month', |
|
| 744 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 745 | + ), |
|
| 746 | + $this->reg_admin_url |
|
| 747 | + ), |
|
| 748 | + 'meta' => array( |
|
| 749 | + 'title' => esc_html__('Not Approved', 'event_espresso'), |
|
| 750 | + 'target' => '', |
|
| 751 | + 'class' => $this->menu_class . ' ee-toolbar-icon-not-approved', |
|
| 752 | + ), |
|
| 753 | + ) |
|
| 754 | + ); |
|
| 755 | + } |
|
| 756 | + } |
|
| 757 | + |
|
| 758 | + |
|
| 759 | + |
|
| 760 | + /** |
|
| 761 | + * @return void |
|
| 762 | + */ |
|
| 763 | + private function addRegistrationOverviewThisMonthCancelled() |
|
| 764 | + { |
|
| 765 | + if ( |
|
| 766 | + $this->capabilities->current_user_can( |
|
| 767 | + 'ee_read_registrations', |
|
| 768 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled' |
|
| 769 | + ) |
|
| 770 | + ) { |
|
| 771 | + $this->admin_bar->add_menu( |
|
| 772 | + array( |
|
| 773 | + 'id' => 'espresso-toolbar-registrations-month-cancelled', |
|
| 774 | + 'parent' => 'espresso-toolbar-registrations', |
|
| 775 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 776 | + . esc_html__('Cancelled', 'event_espresso'), |
|
| 777 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 778 | + array( |
|
| 779 | + 'action' => 'default', |
|
| 780 | + 'status' => 'month', |
|
| 781 | + '_reg_status' => EEM_Registration::status_id_cancelled, |
|
| 782 | + ), |
|
| 783 | + $this->reg_admin_url |
|
| 784 | + ), |
|
| 785 | + 'meta' => array( |
|
| 786 | + 'title' => esc_html__('Cancelled', 'event_espresso'), |
|
| 787 | + 'target' => '', |
|
| 788 | + 'class' => $this->menu_class . ' ee-toolbar-icon-cancelled', |
|
| 789 | + ), |
|
| 790 | + ) |
|
| 791 | + ); |
|
| 792 | + } |
|
| 793 | + } |
|
| 794 | + |
|
| 795 | + |
|
| 796 | + |
|
| 797 | + /** |
|
| 798 | + * @return void |
|
| 799 | + */ |
|
| 800 | + private function addExtensionsAndServices() |
|
| 801 | + { |
|
| 802 | + if ( |
|
| 803 | + $this->capabilities->current_user_can( |
|
| 804 | + 'ee_read_ee', |
|
| 805 | + 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services' |
|
| 806 | + ) |
|
| 807 | + ) { |
|
| 808 | + $this->admin_bar->add_menu( |
|
| 809 | + array( |
|
| 810 | + 'id' => 'espresso-toolbar-extensions-and-services', |
|
| 811 | + 'parent' => 'espresso-toolbar', |
|
| 812 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 813 | + . esc_html__('Extensions & Services', 'event_espresso'), |
|
| 814 | + 'href' => admin_url('admin.php?page=espresso_packages'), |
|
| 815 | + 'meta' => array( |
|
| 816 | + 'title' => esc_html__('Extensions & Services', 'event_espresso'), |
|
| 817 | + 'target' => '', |
|
| 818 | + 'class' => $this->menu_class, |
|
| 819 | + ), |
|
| 820 | + ) |
|
| 821 | + ); |
|
| 822 | + } |
|
| 823 | + } |
|
| 824 | 824 | |
| 825 | 825 | } |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | namespace EventEspresso\core\exceptions; |
| 4 | 4 | |
| 5 | 5 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 6 | - exit('No direct script access allowed'); |
|
| 6 | + exit('No direct script access allowed'); |
|
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | |
@@ -18,32 +18,32 @@ discard block |
||
| 18 | 18 | class InvalidEntityException extends \InvalidArgumentException |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * InvalidInterfaceException constructor. |
|
| 23 | - * |
|
| 24 | - * @param string $actual classname of what we got |
|
| 25 | - * @param string $expected classname of the entity we wanted |
|
| 26 | - * @param string $message |
|
| 27 | - * @param int $code |
|
| 28 | - * @param \Exception $previous |
|
| 29 | - */ |
|
| 30 | - public function __construct($actual, $expected, $message = '', $code = 0, \Exception $previous = null) |
|
| 31 | - { |
|
| 32 | - if (empty($message)) { |
|
| 33 | - $message = sprintf( |
|
| 34 | - __( |
|
| 35 | - 'The supplied entity is an instance of "%1$s", but an instance of "%2$s" was expected. Object: %3$s', |
|
| 36 | - 'event_espresso' |
|
| 37 | - ), |
|
| 38 | - is_object($actual) |
|
| 39 | - ? get_class($actual) |
|
| 40 | - : gettype($actual), |
|
| 41 | - $expected, |
|
| 42 | - var_export($actual, true) |
|
| 43 | - ); |
|
| 44 | - } |
|
| 45 | - parent::__construct($message, $code, $previous); |
|
| 46 | - } |
|
| 21 | + /** |
|
| 22 | + * InvalidInterfaceException constructor. |
|
| 23 | + * |
|
| 24 | + * @param string $actual classname of what we got |
|
| 25 | + * @param string $expected classname of the entity we wanted |
|
| 26 | + * @param string $message |
|
| 27 | + * @param int $code |
|
| 28 | + * @param \Exception $previous |
|
| 29 | + */ |
|
| 30 | + public function __construct($actual, $expected, $message = '', $code = 0, \Exception $previous = null) |
|
| 31 | + { |
|
| 32 | + if (empty($message)) { |
|
| 33 | + $message = sprintf( |
|
| 34 | + __( |
|
| 35 | + 'The supplied entity is an instance of "%1$s", but an instance of "%2$s" was expected. Object: %3$s', |
|
| 36 | + 'event_espresso' |
|
| 37 | + ), |
|
| 38 | + is_object($actual) |
|
| 39 | + ? get_class($actual) |
|
| 40 | + : gettype($actual), |
|
| 41 | + $expected, |
|
| 42 | + var_export($actual, true) |
|
| 43 | + ); |
|
| 44 | + } |
|
| 45 | + parent::__construct($message, $code, $previous); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | 48 | } |
| 49 | 49 | // End of file InvalidEntityException.php |
@@ -2,7 +2,7 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace EventEspresso\core\exceptions; |
| 4 | 4 | |
| 5 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 5 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 6 | 6 | exit('No direct script access allowed'); |
| 7 | 7 | } |
| 8 | 8 | |
@@ -157,7 +157,7 @@ |
||
| 157 | 157 | /** |
| 158 | 158 | * This retrieves the EE_Venue from the available data object. |
| 159 | 159 | * |
| 160 | - * @return EE_Venue|null |
|
| 160 | + * @return EE_Base_Class|null |
|
| 161 | 161 | */ |
| 162 | 162 | private function _get_venue() { |
| 163 | 163 | |
@@ -16,288 +16,288 @@ |
||
| 16 | 16 | { |
| 17 | 17 | |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Will hold the EE_Event if available |
|
| 21 | - * |
|
| 22 | - * @var EE_Event |
|
| 23 | - */ |
|
| 24 | - protected $_event; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Will hold the EE_Venue if available |
|
| 28 | - * |
|
| 29 | - * @var EE_Venue |
|
| 30 | - */ |
|
| 31 | - protected $_venue; |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Initialize properties |
|
| 36 | - */ |
|
| 37 | - protected function _init_props() |
|
| 38 | - { |
|
| 39 | - $this->label = esc_html__('Venue Shortcodes', 'event_espresso'); |
|
| 40 | - $this->description = esc_html__('All shortcodes specific to venue related data', 'event_espresso'); |
|
| 41 | - $this->_shortcodes = array( |
|
| 42 | - '[VENUE_TITLE]' => esc_html__('The title for the event venue', 'event_espresso'), |
|
| 43 | - '[VENUE_DESCRIPTION]' => esc_html__('The description for the event venue', 'event_espresso'), |
|
| 44 | - '[VENUE_URL]' => esc_html__('A url to a webpage for the venue', 'event_espresso'), |
|
| 45 | - '[VENUE_IMAGE]' => esc_html__('An image representing the event venue', 'event_espresso'), |
|
| 46 | - '[VENUE_PHONE]' => esc_html__('The phone number for the venue', 'event_espresso'), |
|
| 47 | - '[VENUE_ADDRESS]' => esc_html__('The address for the venue', 'event_espresso'), |
|
| 48 | - '[VENUE_ADDRESS2]' => esc_html__('Address 2 for the venue', 'event_espresso'), |
|
| 49 | - '[VENUE_CITY]' => esc_html__('The city the venue is in', 'event_espresso'), |
|
| 50 | - '[VENUE_STATE]' => esc_html__('The state the venue is located in', 'event_espresso'), |
|
| 51 | - '[VENUE_COUNTRY]' => esc_html__('The country the venue is located in', 'event_espresso'), |
|
| 52 | - '[VENUE_FORMATTED_ADDRESS]' => esc_html__( |
|
| 53 | - 'This just outputs the venue address in a semantic address format.', |
|
| 54 | - 'event_espresso' |
|
| 55 | - ), |
|
| 56 | - '[VENUE_ZIP]' => esc_html__('The zip code for the venue address', 'event_espresso'), |
|
| 57 | - '[VENUE_META_*]' => esc_html__( |
|
| 58 | - 'This is a special dynamic shortcode. After the "*", add the exact name for your custom field, if there is a value set for that custom field within the venue then it will be output in place of this shortcode.', |
|
| 59 | - 'event_espresso' |
|
| 60 | - ), |
|
| 61 | - '[GOOGLE_MAP_URL]' => esc_html__( |
|
| 62 | - 'URL for the google map associated with the venue.', |
|
| 63 | - 'event_espresso' |
|
| 64 | - ), |
|
| 65 | - '[GOOGLE_MAP_LINK]' => esc_html__('Link to a google map for the venue', 'event_espresso'), |
|
| 66 | - '[GOOGLE_MAP_IMAGE]' => esc_html__('Google map for venue wrapped in image tags', 'event_espresso'), |
|
| 67 | - ); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Parse incoming shortcode |
|
| 73 | - * @param string $shortcode |
|
| 74 | - * @return string |
|
| 75 | - */ |
|
| 76 | - protected function _parser($shortcode) |
|
| 77 | - { |
|
| 78 | - $this->_venue = $this->_get_venue(); |
|
| 79 | - //If there is no venue object by now then get out. |
|
| 80 | - if ( ! $this->_venue instanceof EE_Venue ) |
|
| 81 | - return ''; |
|
| 82 | - |
|
| 83 | - switch ($shortcode) { |
|
| 84 | - case '[VENUE_TITLE]': |
|
| 85 | - return $this->_venue('title'); |
|
| 86 | - break; |
|
| 87 | - |
|
| 88 | - case '[VENUE_DESCRIPTION]': |
|
| 89 | - return $this->_venue('description'); |
|
| 90 | - break; |
|
| 91 | - |
|
| 92 | - case '[VENUE_URL]': |
|
| 93 | - return $this->_venue('url'); |
|
| 94 | - break; |
|
| 95 | - |
|
| 96 | - case '[VENUE_IMAGE]': |
|
| 97 | - return $this->_venue('image'); |
|
| 98 | - break; |
|
| 99 | - |
|
| 100 | - case '[VENUE_PHONE]': |
|
| 101 | - return $this->_venue('phone'); |
|
| 102 | - break; |
|
| 103 | - |
|
| 104 | - case '[VENUE_ADDRESS]': |
|
| 105 | - return $this->_venue('address'); |
|
| 106 | - break; |
|
| 107 | - |
|
| 108 | - case '[VENUE_ADDRESS2]': |
|
| 109 | - return $this->_venue('address2'); |
|
| 110 | - break; |
|
| 111 | - |
|
| 112 | - case '[VENUE_CITY]': |
|
| 113 | - return $this->_venue('city'); |
|
| 114 | - break; |
|
| 115 | - |
|
| 116 | - case '[VENUE_COUNTRY]': |
|
| 117 | - return $this->_venue('country'); |
|
| 118 | - break; |
|
| 119 | - |
|
| 120 | - case '[VENUE_STATE]': |
|
| 121 | - return $this->_venue('state'); |
|
| 122 | - break; |
|
| 123 | - |
|
| 124 | - case '[VENUE_ZIP]': |
|
| 125 | - return $this->_venue('zip'); |
|
| 126 | - break; |
|
| 127 | - |
|
| 128 | - case '[VENUE_FORMATTED_ADDRESS]': |
|
| 129 | - return $this->_venue('formatted_address'); |
|
| 130 | - break; |
|
| 131 | - |
|
| 132 | - case '[GOOGLE_MAP_URL]': |
|
| 133 | - return $this->_venue('gmap_url'); |
|
| 134 | - break; |
|
| 135 | - |
|
| 136 | - case '[GOOGLE_MAP_LINK]': |
|
| 137 | - return $this->_venue('gmap_link'); |
|
| 138 | - break; |
|
| 139 | - |
|
| 140 | - case '[GOOGLE_MAP_IMAGE]': |
|
| 141 | - return $this->_venue('gmap_link_img'); |
|
| 142 | - break; |
|
| 143 | - |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - if ( strpos( $shortcode, '[VENUE_META_*' ) !== false ) { |
|
| 147 | - $shortcode = str_replace( '[VENUE_META_*', '', $shortcode ); |
|
| 148 | - $shortcode = trim( str_replace( ']', '', $shortcode ) ); |
|
| 149 | - |
|
| 150 | - //pull the meta value from the venue post |
|
| 151 | - $venue_meta = $this->_venue->get_post_meta( $shortcode, true ); |
|
| 152 | - |
|
| 153 | - return ! empty( $venue_meta ) ? $venue_meta : ''; |
|
| 154 | - |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - /** |
|
| 158 | - * This retrieves the EE_Venue from the available data object. |
|
| 159 | - * |
|
| 160 | - * @return EE_Venue|null |
|
| 161 | - */ |
|
| 162 | - private function _get_venue() { |
|
| 163 | - |
|
| 164 | - //we need the EE_Event object to get the venue. |
|
| 165 | - $this->_event = $this->_data instanceof EE_Event ? $this->_data : null; |
|
| 166 | - |
|
| 167 | - //if no event, then let's see if there is a reg_obj. If there IS, then we'll try and grab the event from the reg_obj instead. |
|
| 168 | - if (empty($this->_event)) { |
|
| 169 | - $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
| 170 | - $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee; |
|
| 171 | - |
|
| 172 | - $this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration ? $aee->reg_obj->event() : null; |
|
| 173 | - |
|
| 174 | - //if still empty do we have a ticket data item? |
|
| 175 | - $this->_event = empty($this->_event) |
|
| 176 | - && $this->_data instanceof EE_Ticket |
|
| 177 | - && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
| 178 | - ? $this->_extra_data['data']->tickets[$this->_data->ID()]['EE_Event'] |
|
| 179 | - : $this->_event; |
|
| 180 | - |
|
| 181 | - //if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee and use that. |
|
| 182 | - $event = $aee instanceof EE_Messages_Addressee ? reset($aee->events) : array(); |
|
| 183 | - $this->_event = empty($this->_event) && ! empty($events) ? $event : $this->_event; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - //If we have an event object use it to pull the venue. |
|
| 187 | - if ($this->_event instanceof EE_Event) { |
|
| 188 | - return $this->_event->get_first_related('Venue'); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - return null; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * This retrieves the specified venue information |
|
| 196 | - * |
|
| 197 | - * @param string $field What Venue field to retrieve |
|
| 198 | - * @return string What was retrieved! |
|
| 199 | - * @throws EE_Error |
|
| 200 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 201 | - */ |
|
| 202 | - private function _venue($field) |
|
| 203 | - { |
|
| 204 | - |
|
| 205 | - if (empty($this->_venue)) { |
|
| 206 | - return ''; |
|
| 207 | - } //no venue so get out. |
|
| 208 | - |
|
| 209 | - switch ($field) { |
|
| 210 | - case 'title': |
|
| 211 | - return $this->_venue->get('VNU_name'); |
|
| 212 | - break; |
|
| 213 | - |
|
| 214 | - case 'description': |
|
| 215 | - return $this->_venue->get('VNU_desc'); |
|
| 216 | - break; |
|
| 217 | - |
|
| 218 | - case 'url': |
|
| 219 | - $url = $this->_venue->get('VNU_url'); |
|
| 220 | - return empty($url) ? $this->_venue->get_permalink() : $url; |
|
| 221 | - break; |
|
| 222 | - |
|
| 223 | - case 'image': |
|
| 224 | - return '<img src="' . $this->_venue->feature_image_url(array(200, 200,)) |
|
| 225 | - . '" alt="' . sprintf( |
|
| 226 | - esc_attr__('%s Feature Image', 'event_espresso'), |
|
| 227 | - $this->_venue->get('VNU_name') |
|
| 228 | - ) . '" />'; |
|
| 229 | - break; |
|
| 230 | - |
|
| 231 | - case 'phone': |
|
| 232 | - return $this->_venue->get('VNU_phone'); |
|
| 233 | - break; |
|
| 234 | - |
|
| 235 | - case 'address': |
|
| 236 | - return $this->_venue->get('VNU_address'); |
|
| 237 | - break; |
|
| 238 | - |
|
| 239 | - case 'address2': |
|
| 240 | - return $this->_venue->get('VNU_address2'); |
|
| 241 | - break; |
|
| 242 | - |
|
| 243 | - case 'city': |
|
| 244 | - return $this->_venue->get('VNU_city'); |
|
| 245 | - break; |
|
| 246 | - |
|
| 247 | - case 'state': |
|
| 248 | - $state = $this->_venue->state_obj(); |
|
| 249 | - return is_object($state) ? $state->get('STA_name') : ''; |
|
| 250 | - break; |
|
| 251 | - |
|
| 252 | - case 'country': |
|
| 253 | - $country = $this->_venue->country_obj(); |
|
| 254 | - return is_object($country) ? $country->get('CNT_name') : ''; |
|
| 255 | - break; |
|
| 256 | - |
|
| 257 | - case 'zip': |
|
| 258 | - return $this->_venue->get('VNU_zip'); |
|
| 259 | - break; |
|
| 260 | - |
|
| 261 | - case 'formatted_address': |
|
| 262 | - return EEH_Address::format($this->_venue); |
|
| 263 | - break; |
|
| 264 | - |
|
| 265 | - case 'gmap_link': |
|
| 266 | - case 'gmap_url': |
|
| 267 | - case 'gmap_link_img': |
|
| 268 | - $atts = $this->get_map_attributes($this->_venue, $field); |
|
| 269 | - return EEH_Maps::google_map_link($atts); |
|
| 270 | - break; |
|
| 271 | - } |
|
| 272 | - return ''; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * Generates the attributes for retrieving a google_map artifact. |
|
| 278 | - * @param EE_Venue $venue |
|
| 279 | - * @param string $field |
|
| 280 | - * @return array |
|
| 281 | - * @throws EE_Error |
|
| 282 | - */ |
|
| 283 | - protected function get_map_attributes(EE_Venue $venue, $field = 'gmap_link') |
|
| 284 | - { |
|
| 285 | - $state = $venue->state_obj(); |
|
| 286 | - $country = $venue->country_obj(); |
|
| 287 | - $atts = array( |
|
| 288 | - 'id' => $venue->ID(), |
|
| 289 | - 'address' => $venue->get('VNU_address'), |
|
| 290 | - 'city' => $venue->get('VNU_city'), |
|
| 291 | - 'state' => is_object($state) ? $state->get('STA_name') : '', |
|
| 292 | - 'zip' => $venue->get('VNU_zip'), |
|
| 293 | - 'country' => is_object($country) ? $country->get('CNT_name') : '', |
|
| 294 | - 'type' => $field === 'gmap_link' ? 'url' : 'map', |
|
| 295 | - 'map_w' => 200, |
|
| 296 | - 'map_h' => 200, |
|
| 297 | - ); |
|
| 298 | - if ($field === 'gmap_url') { |
|
| 299 | - $atts['type'] = 'url_only'; |
|
| 300 | - } |
|
| 301 | - return $atts; |
|
| 302 | - } |
|
| 19 | + /** |
|
| 20 | + * Will hold the EE_Event if available |
|
| 21 | + * |
|
| 22 | + * @var EE_Event |
|
| 23 | + */ |
|
| 24 | + protected $_event; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Will hold the EE_Venue if available |
|
| 28 | + * |
|
| 29 | + * @var EE_Venue |
|
| 30 | + */ |
|
| 31 | + protected $_venue; |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Initialize properties |
|
| 36 | + */ |
|
| 37 | + protected function _init_props() |
|
| 38 | + { |
|
| 39 | + $this->label = esc_html__('Venue Shortcodes', 'event_espresso'); |
|
| 40 | + $this->description = esc_html__('All shortcodes specific to venue related data', 'event_espresso'); |
|
| 41 | + $this->_shortcodes = array( |
|
| 42 | + '[VENUE_TITLE]' => esc_html__('The title for the event venue', 'event_espresso'), |
|
| 43 | + '[VENUE_DESCRIPTION]' => esc_html__('The description for the event venue', 'event_espresso'), |
|
| 44 | + '[VENUE_URL]' => esc_html__('A url to a webpage for the venue', 'event_espresso'), |
|
| 45 | + '[VENUE_IMAGE]' => esc_html__('An image representing the event venue', 'event_espresso'), |
|
| 46 | + '[VENUE_PHONE]' => esc_html__('The phone number for the venue', 'event_espresso'), |
|
| 47 | + '[VENUE_ADDRESS]' => esc_html__('The address for the venue', 'event_espresso'), |
|
| 48 | + '[VENUE_ADDRESS2]' => esc_html__('Address 2 for the venue', 'event_espresso'), |
|
| 49 | + '[VENUE_CITY]' => esc_html__('The city the venue is in', 'event_espresso'), |
|
| 50 | + '[VENUE_STATE]' => esc_html__('The state the venue is located in', 'event_espresso'), |
|
| 51 | + '[VENUE_COUNTRY]' => esc_html__('The country the venue is located in', 'event_espresso'), |
|
| 52 | + '[VENUE_FORMATTED_ADDRESS]' => esc_html__( |
|
| 53 | + 'This just outputs the venue address in a semantic address format.', |
|
| 54 | + 'event_espresso' |
|
| 55 | + ), |
|
| 56 | + '[VENUE_ZIP]' => esc_html__('The zip code for the venue address', 'event_espresso'), |
|
| 57 | + '[VENUE_META_*]' => esc_html__( |
|
| 58 | + 'This is a special dynamic shortcode. After the "*", add the exact name for your custom field, if there is a value set for that custom field within the venue then it will be output in place of this shortcode.', |
|
| 59 | + 'event_espresso' |
|
| 60 | + ), |
|
| 61 | + '[GOOGLE_MAP_URL]' => esc_html__( |
|
| 62 | + 'URL for the google map associated with the venue.', |
|
| 63 | + 'event_espresso' |
|
| 64 | + ), |
|
| 65 | + '[GOOGLE_MAP_LINK]' => esc_html__('Link to a google map for the venue', 'event_espresso'), |
|
| 66 | + '[GOOGLE_MAP_IMAGE]' => esc_html__('Google map for venue wrapped in image tags', 'event_espresso'), |
|
| 67 | + ); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Parse incoming shortcode |
|
| 73 | + * @param string $shortcode |
|
| 74 | + * @return string |
|
| 75 | + */ |
|
| 76 | + protected function _parser($shortcode) |
|
| 77 | + { |
|
| 78 | + $this->_venue = $this->_get_venue(); |
|
| 79 | + //If there is no venue object by now then get out. |
|
| 80 | + if ( ! $this->_venue instanceof EE_Venue ) |
|
| 81 | + return ''; |
|
| 82 | + |
|
| 83 | + switch ($shortcode) { |
|
| 84 | + case '[VENUE_TITLE]': |
|
| 85 | + return $this->_venue('title'); |
|
| 86 | + break; |
|
| 87 | + |
|
| 88 | + case '[VENUE_DESCRIPTION]': |
|
| 89 | + return $this->_venue('description'); |
|
| 90 | + break; |
|
| 91 | + |
|
| 92 | + case '[VENUE_URL]': |
|
| 93 | + return $this->_venue('url'); |
|
| 94 | + break; |
|
| 95 | + |
|
| 96 | + case '[VENUE_IMAGE]': |
|
| 97 | + return $this->_venue('image'); |
|
| 98 | + break; |
|
| 99 | + |
|
| 100 | + case '[VENUE_PHONE]': |
|
| 101 | + return $this->_venue('phone'); |
|
| 102 | + break; |
|
| 103 | + |
|
| 104 | + case '[VENUE_ADDRESS]': |
|
| 105 | + return $this->_venue('address'); |
|
| 106 | + break; |
|
| 107 | + |
|
| 108 | + case '[VENUE_ADDRESS2]': |
|
| 109 | + return $this->_venue('address2'); |
|
| 110 | + break; |
|
| 111 | + |
|
| 112 | + case '[VENUE_CITY]': |
|
| 113 | + return $this->_venue('city'); |
|
| 114 | + break; |
|
| 115 | + |
|
| 116 | + case '[VENUE_COUNTRY]': |
|
| 117 | + return $this->_venue('country'); |
|
| 118 | + break; |
|
| 119 | + |
|
| 120 | + case '[VENUE_STATE]': |
|
| 121 | + return $this->_venue('state'); |
|
| 122 | + break; |
|
| 123 | + |
|
| 124 | + case '[VENUE_ZIP]': |
|
| 125 | + return $this->_venue('zip'); |
|
| 126 | + break; |
|
| 127 | + |
|
| 128 | + case '[VENUE_FORMATTED_ADDRESS]': |
|
| 129 | + return $this->_venue('formatted_address'); |
|
| 130 | + break; |
|
| 131 | + |
|
| 132 | + case '[GOOGLE_MAP_URL]': |
|
| 133 | + return $this->_venue('gmap_url'); |
|
| 134 | + break; |
|
| 135 | + |
|
| 136 | + case '[GOOGLE_MAP_LINK]': |
|
| 137 | + return $this->_venue('gmap_link'); |
|
| 138 | + break; |
|
| 139 | + |
|
| 140 | + case '[GOOGLE_MAP_IMAGE]': |
|
| 141 | + return $this->_venue('gmap_link_img'); |
|
| 142 | + break; |
|
| 143 | + |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + if ( strpos( $shortcode, '[VENUE_META_*' ) !== false ) { |
|
| 147 | + $shortcode = str_replace( '[VENUE_META_*', '', $shortcode ); |
|
| 148 | + $shortcode = trim( str_replace( ']', '', $shortcode ) ); |
|
| 149 | + |
|
| 150 | + //pull the meta value from the venue post |
|
| 151 | + $venue_meta = $this->_venue->get_post_meta( $shortcode, true ); |
|
| 152 | + |
|
| 153 | + return ! empty( $venue_meta ) ? $venue_meta : ''; |
|
| 154 | + |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + /** |
|
| 158 | + * This retrieves the EE_Venue from the available data object. |
|
| 159 | + * |
|
| 160 | + * @return EE_Venue|null |
|
| 161 | + */ |
|
| 162 | + private function _get_venue() { |
|
| 163 | + |
|
| 164 | + //we need the EE_Event object to get the venue. |
|
| 165 | + $this->_event = $this->_data instanceof EE_Event ? $this->_data : null; |
|
| 166 | + |
|
| 167 | + //if no event, then let's see if there is a reg_obj. If there IS, then we'll try and grab the event from the reg_obj instead. |
|
| 168 | + if (empty($this->_event)) { |
|
| 169 | + $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
| 170 | + $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee; |
|
| 171 | + |
|
| 172 | + $this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration ? $aee->reg_obj->event() : null; |
|
| 173 | + |
|
| 174 | + //if still empty do we have a ticket data item? |
|
| 175 | + $this->_event = empty($this->_event) |
|
| 176 | + && $this->_data instanceof EE_Ticket |
|
| 177 | + && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
| 178 | + ? $this->_extra_data['data']->tickets[$this->_data->ID()]['EE_Event'] |
|
| 179 | + : $this->_event; |
|
| 180 | + |
|
| 181 | + //if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee and use that. |
|
| 182 | + $event = $aee instanceof EE_Messages_Addressee ? reset($aee->events) : array(); |
|
| 183 | + $this->_event = empty($this->_event) && ! empty($events) ? $event : $this->_event; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + //If we have an event object use it to pull the venue. |
|
| 187 | + if ($this->_event instanceof EE_Event) { |
|
| 188 | + return $this->_event->get_first_related('Venue'); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + return null; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * This retrieves the specified venue information |
|
| 196 | + * |
|
| 197 | + * @param string $field What Venue field to retrieve |
|
| 198 | + * @return string What was retrieved! |
|
| 199 | + * @throws EE_Error |
|
| 200 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 201 | + */ |
|
| 202 | + private function _venue($field) |
|
| 203 | + { |
|
| 204 | + |
|
| 205 | + if (empty($this->_venue)) { |
|
| 206 | + return ''; |
|
| 207 | + } //no venue so get out. |
|
| 208 | + |
|
| 209 | + switch ($field) { |
|
| 210 | + case 'title': |
|
| 211 | + return $this->_venue->get('VNU_name'); |
|
| 212 | + break; |
|
| 213 | + |
|
| 214 | + case 'description': |
|
| 215 | + return $this->_venue->get('VNU_desc'); |
|
| 216 | + break; |
|
| 217 | + |
|
| 218 | + case 'url': |
|
| 219 | + $url = $this->_venue->get('VNU_url'); |
|
| 220 | + return empty($url) ? $this->_venue->get_permalink() : $url; |
|
| 221 | + break; |
|
| 222 | + |
|
| 223 | + case 'image': |
|
| 224 | + return '<img src="' . $this->_venue->feature_image_url(array(200, 200,)) |
|
| 225 | + . '" alt="' . sprintf( |
|
| 226 | + esc_attr__('%s Feature Image', 'event_espresso'), |
|
| 227 | + $this->_venue->get('VNU_name') |
|
| 228 | + ) . '" />'; |
|
| 229 | + break; |
|
| 230 | + |
|
| 231 | + case 'phone': |
|
| 232 | + return $this->_venue->get('VNU_phone'); |
|
| 233 | + break; |
|
| 234 | + |
|
| 235 | + case 'address': |
|
| 236 | + return $this->_venue->get('VNU_address'); |
|
| 237 | + break; |
|
| 238 | + |
|
| 239 | + case 'address2': |
|
| 240 | + return $this->_venue->get('VNU_address2'); |
|
| 241 | + break; |
|
| 242 | + |
|
| 243 | + case 'city': |
|
| 244 | + return $this->_venue->get('VNU_city'); |
|
| 245 | + break; |
|
| 246 | + |
|
| 247 | + case 'state': |
|
| 248 | + $state = $this->_venue->state_obj(); |
|
| 249 | + return is_object($state) ? $state->get('STA_name') : ''; |
|
| 250 | + break; |
|
| 251 | + |
|
| 252 | + case 'country': |
|
| 253 | + $country = $this->_venue->country_obj(); |
|
| 254 | + return is_object($country) ? $country->get('CNT_name') : ''; |
|
| 255 | + break; |
|
| 256 | + |
|
| 257 | + case 'zip': |
|
| 258 | + return $this->_venue->get('VNU_zip'); |
|
| 259 | + break; |
|
| 260 | + |
|
| 261 | + case 'formatted_address': |
|
| 262 | + return EEH_Address::format($this->_venue); |
|
| 263 | + break; |
|
| 264 | + |
|
| 265 | + case 'gmap_link': |
|
| 266 | + case 'gmap_url': |
|
| 267 | + case 'gmap_link_img': |
|
| 268 | + $atts = $this->get_map_attributes($this->_venue, $field); |
|
| 269 | + return EEH_Maps::google_map_link($atts); |
|
| 270 | + break; |
|
| 271 | + } |
|
| 272 | + return ''; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * Generates the attributes for retrieving a google_map artifact. |
|
| 278 | + * @param EE_Venue $venue |
|
| 279 | + * @param string $field |
|
| 280 | + * @return array |
|
| 281 | + * @throws EE_Error |
|
| 282 | + */ |
|
| 283 | + protected function get_map_attributes(EE_Venue $venue, $field = 'gmap_link') |
|
| 284 | + { |
|
| 285 | + $state = $venue->state_obj(); |
|
| 286 | + $country = $venue->country_obj(); |
|
| 287 | + $atts = array( |
|
| 288 | + 'id' => $venue->ID(), |
|
| 289 | + 'address' => $venue->get('VNU_address'), |
|
| 290 | + 'city' => $venue->get('VNU_city'), |
|
| 291 | + 'state' => is_object($state) ? $state->get('STA_name') : '', |
|
| 292 | + 'zip' => $venue->get('VNU_zip'), |
|
| 293 | + 'country' => is_object($country) ? $country->get('CNT_name') : '', |
|
| 294 | + 'type' => $field === 'gmap_link' ? 'url' : 'map', |
|
| 295 | + 'map_w' => 200, |
|
| 296 | + 'map_h' => 200, |
|
| 297 | + ); |
|
| 298 | + if ($field === 'gmap_url') { |
|
| 299 | + $atts['type'] = 'url_only'; |
|
| 300 | + } |
|
| 301 | + return $atts; |
|
| 302 | + } |
|
| 303 | 303 | } |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | { |
| 78 | 78 | $this->_venue = $this->_get_venue(); |
| 79 | 79 | //If there is no venue object by now then get out. |
| 80 | - if ( ! $this->_venue instanceof EE_Venue ) |
|
| 80 | + if ( ! $this->_venue instanceof EE_Venue) |
|
| 81 | 81 | return ''; |
| 82 | 82 | |
| 83 | 83 | switch ($shortcode) { |
@@ -143,14 +143,14 @@ discard block |
||
| 143 | 143 | |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - if ( strpos( $shortcode, '[VENUE_META_*' ) !== false ) { |
|
| 147 | - $shortcode = str_replace( '[VENUE_META_*', '', $shortcode ); |
|
| 148 | - $shortcode = trim( str_replace( ']', '', $shortcode ) ); |
|
| 146 | + if (strpos($shortcode, '[VENUE_META_*') !== false) { |
|
| 147 | + $shortcode = str_replace('[VENUE_META_*', '', $shortcode); |
|
| 148 | + $shortcode = trim(str_replace(']', '', $shortcode)); |
|
| 149 | 149 | |
| 150 | 150 | //pull the meta value from the venue post |
| 151 | - $venue_meta = $this->_venue->get_post_meta( $shortcode, true ); |
|
| 151 | + $venue_meta = $this->_venue->get_post_meta($shortcode, true); |
|
| 152 | 152 | |
| 153 | - return ! empty( $venue_meta ) ? $venue_meta : ''; |
|
| 153 | + return ! empty($venue_meta) ? $venue_meta : ''; |
|
| 154 | 154 | |
| 155 | 155 | } |
| 156 | 156 | } |
@@ -221,11 +221,11 @@ discard block |
||
| 221 | 221 | break; |
| 222 | 222 | |
| 223 | 223 | case 'image': |
| 224 | - return '<img src="' . $this->_venue->feature_image_url(array(200, 200,)) |
|
| 225 | - . '" alt="' . sprintf( |
|
| 224 | + return '<img src="'.$this->_venue->feature_image_url(array(200, 200,)) |
|
| 225 | + . '" alt="'.sprintf( |
|
| 226 | 226 | esc_attr__('%s Feature Image', 'event_espresso'), |
| 227 | 227 | $this->_venue->get('VNU_name') |
| 228 | - ) . '" />'; |
|
| 228 | + ).'" />'; |
|
| 229 | 229 | break; |
| 230 | 230 | |
| 231 | 231 | case 'phone': |
@@ -77,8 +77,9 @@ |
||
| 77 | 77 | { |
| 78 | 78 | $this->_venue = $this->_get_venue(); |
| 79 | 79 | //If there is no venue object by now then get out. |
| 80 | - if ( ! $this->_venue instanceof EE_Venue ) |
|
| 81 | - return ''; |
|
| 80 | + if ( ! $this->_venue instanceof EE_Venue ) { |
|
| 81 | + return ''; |
|
| 82 | + } |
|
| 82 | 83 | |
| 83 | 84 | switch ($shortcode) { |
| 84 | 85 | case '[VENUE_TITLE]': |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | EE_Maintenance_Mode $maintenance_mode = null |
| 133 | 133 | ) { |
| 134 | 134 | // check if class object is instantiated |
| 135 | - if (! self::$_instance instanceof EE_System) { |
|
| 135 | + if ( ! self::$_instance instanceof EE_System) { |
|
| 136 | 136 | self::$_instance = new self($registry, $loader, $capabilities, $request, $maintenance_mode); |
| 137 | 137 | } |
| 138 | 138 | return self::$_instance; |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | { |
| 300 | 300 | // set autoloaders for all of the classes implementing EEI_Plugin_API |
| 301 | 301 | // which provide helpers for EE plugin authors to more easily register certain components with EE. |
| 302 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
| 302 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api'); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | && in_array($_GET['action'], array('activate', 'activate-selected'), true) |
| 337 | 337 | ) |
| 338 | 338 | ) { |
| 339 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
| 339 | + include_once EE_THIRD_PARTY.'wp-api-basic-auth'.DS.'basic-auth.php'; |
|
| 340 | 340 | } |
| 341 | 341 | do_action('AHEE__EE_System__load_espresso_addons__complete'); |
| 342 | 342 | } |
@@ -444,11 +444,11 @@ discard block |
||
| 444 | 444 | private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
| 445 | 445 | { |
| 446 | 446 | do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
| 447 | - if (! $espresso_db_update) { |
|
| 447 | + if ( ! $espresso_db_update) { |
|
| 448 | 448 | $espresso_db_update = get_option('espresso_db_update'); |
| 449 | 449 | } |
| 450 | 450 | // check that option is an array |
| 451 | - if (! is_array($espresso_db_update)) { |
|
| 451 | + if ( ! is_array($espresso_db_update)) { |
|
| 452 | 452 | // if option is FALSE, then it never existed |
| 453 | 453 | if ($espresso_db_update === false) { |
| 454 | 454 | // make $espresso_db_update an array and save option with autoload OFF |
@@ -553,7 +553,7 @@ discard block |
||
| 553 | 553 | */ |
| 554 | 554 | public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
| 555 | 555 | { |
| 556 | - if (! $version_history) { |
|
| 556 | + if ( ! $version_history) { |
|
| 557 | 557 | $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
| 558 | 558 | } |
| 559 | 559 | if ($current_version_to_add === null) { |
@@ -651,7 +651,7 @@ discard block |
||
| 651 | 651 | if ($activation_history_for_addon) { |
| 652 | 652 | //it exists, so this isn't a completely new install |
| 653 | 653 | //check if this version already in that list of previously installed versions |
| 654 | - if (! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
| 654 | + if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
| 655 | 655 | //it a version we haven't seen before |
| 656 | 656 | if ($version_is_higher === 1) { |
| 657 | 657 | $req_type = EE_System::req_type_upgrade; |
@@ -731,7 +731,7 @@ discard block |
||
| 731 | 731 | foreach ($activation_history as $version => $times_activated) { |
| 732 | 732 | //check there is a record of when this version was activated. Otherwise, |
| 733 | 733 | //mark it as unknown |
| 734 | - if (! $times_activated) { |
|
| 734 | + if ( ! $times_activated) { |
|
| 735 | 735 | $times_activated = array('unknown-date'); |
| 736 | 736 | } |
| 737 | 737 | if (is_string($times_activated)) { |
@@ -831,7 +831,7 @@ discard block |
||
| 831 | 831 | private function _parse_model_names() |
| 832 | 832 | { |
| 833 | 833 | //get all the files in the EE_MODELS folder that end in .model.php |
| 834 | - $models = glob(EE_MODELS . '*.model.php'); |
|
| 834 | + $models = glob(EE_MODELS.'*.model.php'); |
|
| 835 | 835 | $model_names = array(); |
| 836 | 836 | $non_abstract_db_models = array(); |
| 837 | 837 | foreach ($models as $model) { |
@@ -861,8 +861,8 @@ discard block |
||
| 861 | 861 | */ |
| 862 | 862 | private function _maybe_brew_regular() |
| 863 | 863 | { |
| 864 | - if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
| 865 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
| 864 | + if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH.'brewing_regular.php')) { |
|
| 865 | + require_once EE_CAFF_PATH.'brewing_regular.php'; |
|
| 866 | 866 | } |
| 867 | 867 | } |
| 868 | 868 | |
@@ -910,17 +910,17 @@ discard block |
||
| 910 | 910 | $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook( |
| 911 | 911 | 'AHEE__EE_System__register_shortcodes_modules_and_addons' |
| 912 | 912 | ); |
| 913 | - if (! empty($class_names)) { |
|
| 913 | + if ( ! empty($class_names)) { |
|
| 914 | 914 | $msg = __( |
| 915 | 915 | 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
| 916 | 916 | 'event_espresso' |
| 917 | 917 | ); |
| 918 | 918 | $msg .= '<ul>'; |
| 919 | 919 | foreach ($class_names as $class_name) { |
| 920 | - $msg .= '<li><b>Event Espresso - ' . str_replace( |
|
| 920 | + $msg .= '<li><b>Event Espresso - '.str_replace( |
|
| 921 | 921 | array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
| 922 | 922 | $class_name |
| 923 | - ) . '</b></li>'; |
|
| 923 | + ).'</b></li>'; |
|
| 924 | 924 | } |
| 925 | 925 | $msg .= '</ul>'; |
| 926 | 926 | $msg .= __( |
@@ -991,7 +991,7 @@ discard block |
||
| 991 | 991 | private function _deactivate_incompatible_addons() |
| 992 | 992 | { |
| 993 | 993 | $incompatible_addons = get_option('ee_incompatible_addons', array()); |
| 994 | - if (! empty($incompatible_addons)) { |
|
| 994 | + if ( ! empty($incompatible_addons)) { |
|
| 995 | 995 | $active_plugins = get_option('active_plugins', array()); |
| 996 | 996 | foreach ($active_plugins as $active_plugin) { |
| 997 | 997 | foreach ($incompatible_addons as $incompatible_addon) { |
@@ -1052,10 +1052,10 @@ discard block |
||
| 1052 | 1052 | { |
| 1053 | 1053 | do_action('AHEE__EE_System__load_controllers__start'); |
| 1054 | 1054 | // let's get it started |
| 1055 | - if (! is_admin() && ! $this->maintenance_mode->level()) { |
|
| 1055 | + if ( ! is_admin() && ! $this->maintenance_mode->level()) { |
|
| 1056 | 1056 | do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
| 1057 | 1057 | $this->loader->getShared('EE_Front_Controller'); |
| 1058 | - } else if (! EE_FRONT_AJAX) { |
|
| 1058 | + } else if ( ! EE_FRONT_AJAX) { |
|
| 1059 | 1059 | do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
| 1060 | 1060 | $this->loader->getShared('EE_Admin'); |
| 1061 | 1061 | } |
@@ -1076,8 +1076,8 @@ discard block |
||
| 1076 | 1076 | $this->loader->getShared('EE_Session'); |
| 1077 | 1077 | do_action('AHEE__EE_System__core_loaded_and_ready'); |
| 1078 | 1078 | // load_espresso_template_tags |
| 1079 | - if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
| 1080 | - require_once(EE_PUBLIC . 'template_tags.php'); |
|
| 1079 | + if (is_readable(EE_PUBLIC.'template_tags.php')) { |
|
| 1080 | + require_once(EE_PUBLIC.'template_tags.php'); |
|
| 1081 | 1081 | } |
| 1082 | 1082 | do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
| 1083 | 1083 | $this->loader->getShared('EventEspresso\core\services\assets\Registry'); |
@@ -1139,13 +1139,13 @@ discard block |
||
| 1139 | 1139 | public static function do_not_cache() |
| 1140 | 1140 | { |
| 1141 | 1141 | // set no cache constants |
| 1142 | - if (! defined('DONOTCACHEPAGE')) { |
|
| 1142 | + if ( ! defined('DONOTCACHEPAGE')) { |
|
| 1143 | 1143 | define('DONOTCACHEPAGE', true); |
| 1144 | 1144 | } |
| 1145 | - if (! defined('DONOTCACHCEOBJECT')) { |
|
| 1145 | + if ( ! defined('DONOTCACHCEOBJECT')) { |
|
| 1146 | 1146 | define('DONOTCACHCEOBJECT', true); |
| 1147 | 1147 | } |
| 1148 | - if (! defined('DONOTCACHEDB')) { |
|
| 1148 | + if ( ! defined('DONOTCACHEDB')) { |
|
| 1149 | 1149 | define('DONOTCACHEDB', true); |
| 1150 | 1150 | } |
| 1151 | 1151 | // add no cache headers |
@@ -21,1188 +21,1188 @@ |
||
| 21 | 21 | { |
| 22 | 22 | |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
| 26 | - * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
| 27 | - */ |
|
| 28 | - const req_type_normal = 0; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Indicates this is a brand new installation of EE so we should install |
|
| 32 | - * tables and default data etc |
|
| 33 | - */ |
|
| 34 | - const req_type_new_activation = 1; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
| 38 | - * and we just exited maintenance mode). We MUST check the database is setup properly |
|
| 39 | - * and that default data is setup too |
|
| 40 | - */ |
|
| 41 | - const req_type_reactivation = 2; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * indicates that EE has been upgraded since its previous request. |
|
| 45 | - * We may have data migration scripts to call and will want to trigger maintenance mode |
|
| 46 | - */ |
|
| 47 | - const req_type_upgrade = 3; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
| 51 | - */ |
|
| 52 | - const req_type_downgrade = 4; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @deprecated since version 4.6.0.dev.006 |
|
| 56 | - * Now whenever a new_activation is detected the request type is still just |
|
| 57 | - * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
| 58 | - * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
| 59 | - * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
| 60 | - * (Specifically, when the migration manager indicates migrations are finished |
|
| 61 | - * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
| 62 | - */ |
|
| 63 | - const req_type_activation_but_not_installed = 5; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
| 67 | - */ |
|
| 68 | - const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @var EE_System $_instance |
|
| 73 | - */ |
|
| 74 | - private static $_instance; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @var EE_Registry $registry |
|
| 78 | - */ |
|
| 79 | - private $registry; |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @var LoaderInterface $loader |
|
| 83 | - */ |
|
| 84 | - private $loader; |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * @var EE_Capabilities $capabilities |
|
| 88 | - */ |
|
| 89 | - private $capabilities; |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @var EE_Request $request |
|
| 93 | - */ |
|
| 94 | - private $request; |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @var EE_Maintenance_Mode $maintenance_mode |
|
| 98 | - */ |
|
| 99 | - private $maintenance_mode; |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
| 103 | - * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
| 104 | - * |
|
| 105 | - * @var int $_req_type |
|
| 106 | - */ |
|
| 107 | - private $_req_type; |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Whether or not there was a non-micro version change in EE core version during this request |
|
| 111 | - * |
|
| 112 | - * @var boolean $_major_version_change |
|
| 113 | - */ |
|
| 114 | - private $_major_version_change = false; |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * @singleton method used to instantiate class object |
|
| 120 | - * @param EE_Registry|null $registry |
|
| 121 | - * @param LoaderInterface|null $loader |
|
| 122 | - * @param EE_Capabilities|null $capabilities |
|
| 123 | - * @param EE_Request|null $request |
|
| 124 | - * @param EE_Maintenance_Mode|null $maintenance_mode |
|
| 125 | - * @return EE_System |
|
| 126 | - */ |
|
| 127 | - public static function instance( |
|
| 128 | - EE_Registry $registry = null, |
|
| 129 | - LoaderInterface $loader = null, |
|
| 130 | - EE_Capabilities $capabilities = null, |
|
| 131 | - EE_Request $request = null, |
|
| 132 | - EE_Maintenance_Mode $maintenance_mode = null |
|
| 133 | - ) { |
|
| 134 | - // check if class object is instantiated |
|
| 135 | - if (! self::$_instance instanceof EE_System) { |
|
| 136 | - self::$_instance = new self($registry, $loader, $capabilities, $request, $maintenance_mode); |
|
| 137 | - } |
|
| 138 | - return self::$_instance; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * resets the instance and returns it |
|
| 145 | - * |
|
| 146 | - * @return EE_System |
|
| 147 | - */ |
|
| 148 | - public static function reset() |
|
| 149 | - { |
|
| 150 | - self::$_instance->_req_type = null; |
|
| 151 | - //make sure none of the old hooks are left hanging around |
|
| 152 | - remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
| 153 | - //we need to reset the migration manager in order for it to detect DMSs properly |
|
| 154 | - EE_Data_Migration_Manager::reset(); |
|
| 155 | - self::instance()->detect_activations_or_upgrades(); |
|
| 156 | - self::instance()->perform_activations_upgrades_and_migrations(); |
|
| 157 | - return self::instance(); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * sets hooks for running rest of system |
|
| 164 | - * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
| 165 | - * starting EE Addons from any other point may lead to problems |
|
| 166 | - * |
|
| 167 | - * @param EE_Registry $registry |
|
| 168 | - * @param LoaderInterface $loader |
|
| 169 | - * @param EE_Capabilities $capabilities |
|
| 170 | - * @param EE_Request $request |
|
| 171 | - * @param EE_Maintenance_Mode $maintenance_mode |
|
| 172 | - */ |
|
| 173 | - private function __construct( |
|
| 174 | - EE_Registry $registry, |
|
| 175 | - LoaderInterface $loader, |
|
| 176 | - EE_Capabilities $capabilities, |
|
| 177 | - EE_Request $request, |
|
| 178 | - EE_Maintenance_Mode $maintenance_mode |
|
| 179 | - ) { |
|
| 180 | - $this->registry = $registry; |
|
| 181 | - $this->loader = $loader; |
|
| 182 | - $this->capabilities = $capabilities; |
|
| 183 | - $this->request = $request; |
|
| 184 | - $this->maintenance_mode = $maintenance_mode; |
|
| 185 | - do_action('AHEE__EE_System__construct__begin', $this); |
|
| 186 | - add_action( |
|
| 187 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 188 | - array($this, 'loadCapabilities'), |
|
| 189 | - 5 |
|
| 190 | - ); |
|
| 191 | - add_action( |
|
| 192 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 193 | - array($this, 'loadCommandBus'), |
|
| 194 | - 7 |
|
| 195 | - ); |
|
| 196 | - add_action( |
|
| 197 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 198 | - array($this, 'loadPluginApi'), |
|
| 199 | - 9 |
|
| 200 | - ); |
|
| 201 | - // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
| 202 | - add_action( |
|
| 203 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 204 | - array($this, 'load_espresso_addons') |
|
| 205 | - ); |
|
| 206 | - // when an ee addon is activated, we want to call the core hook(s) again |
|
| 207 | - // because the newly-activated addon didn't get a chance to run at all |
|
| 208 | - add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
| 209 | - // detect whether install or upgrade |
|
| 210 | - add_action( |
|
| 211 | - 'AHEE__EE_Bootstrap__detect_activations_or_upgrades', |
|
| 212 | - array($this, 'detect_activations_or_upgrades'), |
|
| 213 | - 3 |
|
| 214 | - ); |
|
| 215 | - // load EE_Config, EE_Textdomain, etc |
|
| 216 | - add_action( |
|
| 217 | - 'AHEE__EE_Bootstrap__load_core_configuration', |
|
| 218 | - array($this, 'load_core_configuration'), |
|
| 219 | - 5 |
|
| 220 | - ); |
|
| 221 | - // load EE_Config, EE_Textdomain, etc |
|
| 222 | - add_action( |
|
| 223 | - 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
| 224 | - array($this, 'register_shortcodes_modules_and_widgets'), |
|
| 225 | - 7 |
|
| 226 | - ); |
|
| 227 | - // you wanna get going? I wanna get going... let's get going! |
|
| 228 | - add_action( |
|
| 229 | - 'AHEE__EE_Bootstrap__brew_espresso', |
|
| 230 | - array($this, 'brew_espresso'), |
|
| 231 | - 9 |
|
| 232 | - ); |
|
| 233 | - //other housekeeping |
|
| 234 | - //exclude EE critical pages from wp_list_pages |
|
| 235 | - add_filter( |
|
| 236 | - 'wp_list_pages_excludes', |
|
| 237 | - array($this, 'remove_pages_from_wp_list_pages'), |
|
| 238 | - 10 |
|
| 239 | - ); |
|
| 240 | - // ALL EE Addons should use the following hook point to attach their initial setup too |
|
| 241 | - // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
| 242 | - do_action('AHEE__EE_System__construct__complete', $this); |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * load and setup EE_Capabilities |
|
| 249 | - * |
|
| 250 | - * @return void |
|
| 251 | - * @throws EE_Error |
|
| 252 | - */ |
|
| 253 | - public function loadCapabilities() |
|
| 254 | - { |
|
| 255 | - $this->loader->getShared('EE_Capabilities'); |
|
| 256 | - add_action( |
|
| 257 | - 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
| 258 | - function() { |
|
| 259 | - LoaderFactory::getLoader()->getShared('Payment_Method_Manager'); |
|
| 260 | - } |
|
| 261 | - ); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * create and cache the CommandBus, and also add middleware |
|
| 268 | - * The CapChecker middleware requires the use of EE_Capabilities |
|
| 269 | - * which is why we need to load the CommandBus after Caps are set up |
|
| 270 | - * |
|
| 271 | - * @return void |
|
| 272 | - * @throws EE_Error |
|
| 273 | - */ |
|
| 274 | - public function loadCommandBus() |
|
| 275 | - { |
|
| 276 | - $this->loader->getShared( |
|
| 277 | - 'CommandBusInterface', |
|
| 278 | - array( |
|
| 279 | - null, |
|
| 280 | - apply_filters( |
|
| 281 | - 'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware', |
|
| 282 | - array( |
|
| 283 | - $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'), |
|
| 284 | - $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'), |
|
| 285 | - ) |
|
| 286 | - ), |
|
| 287 | - ) |
|
| 288 | - ); |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * @return void |
|
| 295 | - * @throws EE_Error |
|
| 296 | - */ |
|
| 297 | - public function loadPluginApi() |
|
| 298 | - { |
|
| 299 | - // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
| 300 | - // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
| 301 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * load_espresso_addons |
|
| 308 | - * allow addons to load first so that they can set hooks for running DMS's, etc |
|
| 309 | - * this is hooked into both: |
|
| 310 | - * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
| 311 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
| 312 | - * and the WP 'activate_plugin' hook point |
|
| 313 | - * |
|
| 314 | - * @access public |
|
| 315 | - * @return void |
|
| 316 | - * @throws EE_Error |
|
| 317 | - */ |
|
| 318 | - public function load_espresso_addons() |
|
| 319 | - { |
|
| 320 | - do_action('AHEE__EE_System__load_espresso_addons'); |
|
| 321 | - //if the WP API basic auth plugin isn't already loaded, load it now. |
|
| 322 | - //We want it for mobile apps. Just include the entire plugin |
|
| 323 | - //also, don't load the basic auth when a plugin is getting activated, because |
|
| 324 | - //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
| 325 | - //and causes a fatal error |
|
| 326 | - if ( |
|
| 327 | - ! ( |
|
| 328 | - isset($_GET['activate']) |
|
| 329 | - && $_GET['activate'] === 'true' |
|
| 330 | - ) |
|
| 331 | - && ! function_exists('json_basic_auth_handler') |
|
| 332 | - && ! function_exists('json_basic_auth_error') |
|
| 333 | - && ! ( |
|
| 334 | - isset($_GET['action']) |
|
| 335 | - && in_array($_GET['action'], array('activate', 'activate-selected'), true) |
|
| 336 | - ) |
|
| 337 | - ) { |
|
| 338 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
| 339 | - } |
|
| 340 | - do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - |
|
| 344 | - |
|
| 345 | - /** |
|
| 346 | - * detect_activations_or_upgrades |
|
| 347 | - * Checks for activation or upgrade of core first; |
|
| 348 | - * then also checks if any registered addons have been activated or upgraded |
|
| 349 | - * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
| 350 | - * which runs during the WP 'plugins_loaded' action at priority 3 |
|
| 351 | - * |
|
| 352 | - * @access public |
|
| 353 | - * @return void |
|
| 354 | - */ |
|
| 355 | - public function detect_activations_or_upgrades() |
|
| 356 | - { |
|
| 357 | - //first off: let's make sure to handle core |
|
| 358 | - $this->detect_if_activation_or_upgrade(); |
|
| 359 | - foreach ($this->registry->addons as $addon) { |
|
| 360 | - if ($addon instanceof EE_Addon) { |
|
| 361 | - //detect teh request type for that addon |
|
| 362 | - $addon->detect_activation_or_upgrade(); |
|
| 363 | - } |
|
| 364 | - } |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * detect_if_activation_or_upgrade |
|
| 371 | - * Takes care of detecting whether this is a brand new install or code upgrade, |
|
| 372 | - * and either setting up the DB or setting up maintenance mode etc. |
|
| 373 | - * |
|
| 374 | - * @access public |
|
| 375 | - * @return void |
|
| 376 | - */ |
|
| 377 | - public function detect_if_activation_or_upgrade() |
|
| 378 | - { |
|
| 379 | - do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
| 380 | - // check if db has been updated, or if its a brand-new installation |
|
| 381 | - $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
| 382 | - $request_type = $this->detect_req_type($espresso_db_update); |
|
| 383 | - //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
| 384 | - switch ($request_type) { |
|
| 385 | - case EE_System::req_type_new_activation: |
|
| 386 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
| 387 | - $this->_handle_core_version_change($espresso_db_update); |
|
| 388 | - break; |
|
| 389 | - case EE_System::req_type_reactivation: |
|
| 390 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
| 391 | - $this->_handle_core_version_change($espresso_db_update); |
|
| 392 | - break; |
|
| 393 | - case EE_System::req_type_upgrade: |
|
| 394 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
| 395 | - //migrations may be required now that we've upgraded |
|
| 396 | - $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
| 397 | - $this->_handle_core_version_change($espresso_db_update); |
|
| 398 | - // echo "done upgrade";die; |
|
| 399 | - break; |
|
| 400 | - case EE_System::req_type_downgrade: |
|
| 401 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
| 402 | - //its possible migrations are no longer required |
|
| 403 | - $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
| 404 | - $this->_handle_core_version_change($espresso_db_update); |
|
| 405 | - break; |
|
| 406 | - case EE_System::req_type_normal: |
|
| 407 | - default: |
|
| 408 | - // $this->_maybe_redirect_to_ee_about(); |
|
| 409 | - break; |
|
| 410 | - } |
|
| 411 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - |
|
| 415 | - |
|
| 416 | - /** |
|
| 417 | - * Updates the list of installed versions and sets hooks for |
|
| 418 | - * initializing the database later during the request |
|
| 419 | - * |
|
| 420 | - * @param array $espresso_db_update |
|
| 421 | - */ |
|
| 422 | - private function _handle_core_version_change($espresso_db_update) |
|
| 423 | - { |
|
| 424 | - $this->update_list_of_installed_versions($espresso_db_update); |
|
| 425 | - //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
| 426 | - add_action( |
|
| 427 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 428 | - array($this, 'initialize_db_if_no_migrations_required') |
|
| 429 | - ); |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
| 436 | - * information about what versions of EE have been installed and activated, |
|
| 437 | - * NOT necessarily the state of the database |
|
| 438 | - * |
|
| 439 | - * @param mixed $espresso_db_update the value of the WordPress option. |
|
| 440 | - * If not supplied, fetches it from the options table |
|
| 441 | - * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
| 442 | - */ |
|
| 443 | - private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
| 444 | - { |
|
| 445 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
| 446 | - if (! $espresso_db_update) { |
|
| 447 | - $espresso_db_update = get_option('espresso_db_update'); |
|
| 448 | - } |
|
| 449 | - // check that option is an array |
|
| 450 | - if (! is_array($espresso_db_update)) { |
|
| 451 | - // if option is FALSE, then it never existed |
|
| 452 | - if ($espresso_db_update === false) { |
|
| 453 | - // make $espresso_db_update an array and save option with autoload OFF |
|
| 454 | - $espresso_db_update = array(); |
|
| 455 | - add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
| 456 | - } else { |
|
| 457 | - // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
| 458 | - $espresso_db_update = array($espresso_db_update => array()); |
|
| 459 | - update_option('espresso_db_update', $espresso_db_update); |
|
| 460 | - } |
|
| 461 | - } else { |
|
| 462 | - $corrected_db_update = array(); |
|
| 463 | - //if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
| 464 | - foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
| 465 | - if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
| 466 | - //the key is an int, and the value IS NOT an array |
|
| 467 | - //so it must be numerically-indexed, where values are versions installed... |
|
| 468 | - //fix it! |
|
| 469 | - $version_string = $should_be_array; |
|
| 470 | - $corrected_db_update[$version_string] = array('unknown-date'); |
|
| 471 | - } else { |
|
| 472 | - //ok it checks out |
|
| 473 | - $corrected_db_update[$should_be_version_string] = $should_be_array; |
|
| 474 | - } |
|
| 475 | - } |
|
| 476 | - $espresso_db_update = $corrected_db_update; |
|
| 477 | - update_option('espresso_db_update', $espresso_db_update); |
|
| 478 | - } |
|
| 479 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
| 480 | - return $espresso_db_update; |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - |
|
| 484 | - |
|
| 485 | - /** |
|
| 486 | - * Does the traditional work of setting up the plugin's database and adding default data. |
|
| 487 | - * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
| 488 | - * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
| 489 | - * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
| 490 | - * so that it will be done when migrations are finished |
|
| 491 | - * |
|
| 492 | - * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
| 493 | - * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
| 494 | - * This is a resource-intensive job |
|
| 495 | - * so we prefer to only do it when necessary |
|
| 496 | - * @return void |
|
| 497 | - * @throws EE_Error |
|
| 498 | - */ |
|
| 499 | - public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
| 500 | - { |
|
| 501 | - $request_type = $this->detect_req_type(); |
|
| 502 | - //only initialize system if we're not in maintenance mode. |
|
| 503 | - if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 504 | - update_option('ee_flush_rewrite_rules', true); |
|
| 505 | - if ($verify_schema) { |
|
| 506 | - EEH_Activation::initialize_db_and_folders(); |
|
| 507 | - } |
|
| 508 | - EEH_Activation::initialize_db_content(); |
|
| 509 | - EEH_Activation::system_initialization(); |
|
| 510 | - if ($initialize_addons_too) { |
|
| 511 | - $this->initialize_addons(); |
|
| 512 | - } |
|
| 513 | - } else { |
|
| 514 | - EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
| 515 | - } |
|
| 516 | - if ($request_type === EE_System::req_type_new_activation |
|
| 517 | - || $request_type === EE_System::req_type_reactivation |
|
| 518 | - || ( |
|
| 519 | - $request_type === EE_System::req_type_upgrade |
|
| 520 | - && $this->is_major_version_change() |
|
| 521 | - ) |
|
| 522 | - ) { |
|
| 523 | - add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
| 524 | - } |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - |
|
| 528 | - |
|
| 529 | - /** |
|
| 530 | - * Initializes the db for all registered addons |
|
| 531 | - * |
|
| 532 | - * @throws EE_Error |
|
| 533 | - */ |
|
| 534 | - public function initialize_addons() |
|
| 535 | - { |
|
| 536 | - //foreach registered addon, make sure its db is up-to-date too |
|
| 537 | - foreach ($this->registry->addons as $addon) { |
|
| 538 | - if ($addon instanceof EE_Addon) { |
|
| 539 | - $addon->initialize_db_if_no_migrations_required(); |
|
| 540 | - } |
|
| 541 | - } |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
| 548 | - * |
|
| 549 | - * @param array $version_history |
|
| 550 | - * @param string $current_version_to_add version to be added to the version history |
|
| 551 | - * @return boolean success as to whether or not this option was changed |
|
| 552 | - */ |
|
| 553 | - public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
| 554 | - { |
|
| 555 | - if (! $version_history) { |
|
| 556 | - $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
| 557 | - } |
|
| 558 | - if ($current_version_to_add === null) { |
|
| 559 | - $current_version_to_add = espresso_version(); |
|
| 560 | - } |
|
| 561 | - $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
| 562 | - // re-save |
|
| 563 | - return update_option('espresso_db_update', $version_history); |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - |
|
| 567 | - |
|
| 568 | - /** |
|
| 569 | - * Detects if the current version indicated in the has existed in the list of |
|
| 570 | - * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
| 571 | - * |
|
| 572 | - * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
| 573 | - * If not supplied, fetches it from the options table. |
|
| 574 | - * Also, caches its result so later parts of the code can also know whether |
|
| 575 | - * there's been an update or not. This way we can add the current version to |
|
| 576 | - * espresso_db_update, but still know if this is a new install or not |
|
| 577 | - * @return int one of the constants on EE_System::req_type_ |
|
| 578 | - */ |
|
| 579 | - public function detect_req_type($espresso_db_update = null) |
|
| 580 | - { |
|
| 581 | - if ($this->_req_type === null) { |
|
| 582 | - $espresso_db_update = ! empty($espresso_db_update) |
|
| 583 | - ? $espresso_db_update |
|
| 584 | - : $this->fix_espresso_db_upgrade_option(); |
|
| 585 | - $this->_req_type = EE_System::detect_req_type_given_activation_history( |
|
| 586 | - $espresso_db_update, |
|
| 587 | - 'ee_espresso_activation', espresso_version() |
|
| 588 | - ); |
|
| 589 | - $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
| 590 | - } |
|
| 591 | - return $this->_req_type; |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - |
|
| 595 | - |
|
| 596 | - /** |
|
| 597 | - * Returns whether or not there was a non-micro version change (ie, change in either |
|
| 598 | - * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
| 599 | - * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
| 600 | - * |
|
| 601 | - * @param $activation_history |
|
| 602 | - * @return bool |
|
| 603 | - */ |
|
| 604 | - private function _detect_major_version_change($activation_history) |
|
| 605 | - { |
|
| 606 | - $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
| 607 | - $previous_version_parts = explode('.', $previous_version); |
|
| 608 | - $current_version_parts = explode('.', espresso_version()); |
|
| 609 | - return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
| 610 | - && ($previous_version_parts[0] !== $current_version_parts[0] |
|
| 611 | - || $previous_version_parts[1] !== $current_version_parts[1] |
|
| 612 | - ); |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - |
|
| 616 | - |
|
| 617 | - /** |
|
| 618 | - * Returns true if either the major or minor version of EE changed during this request. |
|
| 619 | - * 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 |
|
| 620 | - * |
|
| 621 | - * @return bool |
|
| 622 | - */ |
|
| 623 | - public function is_major_version_change() |
|
| 624 | - { |
|
| 625 | - return $this->_major_version_change; |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - |
|
| 629 | - |
|
| 630 | - /** |
|
| 631 | - * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
| 632 | - * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily |
|
| 633 | - * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
| 634 | - * just activated to (for core that will always be espresso_version()) |
|
| 635 | - * |
|
| 636 | - * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
| 637 | - * ee plugin. for core that's 'espresso_db_update' |
|
| 638 | - * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to |
|
| 639 | - * indicate that this plugin was just activated |
|
| 640 | - * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
| 641 | - * espresso_version()) |
|
| 642 | - * @return int one of the constants on EE_System::req_type_* |
|
| 643 | - */ |
|
| 644 | - public static function detect_req_type_given_activation_history( |
|
| 645 | - $activation_history_for_addon, |
|
| 646 | - $activation_indicator_option_name, |
|
| 647 | - $version_to_upgrade_to |
|
| 648 | - ) { |
|
| 649 | - $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
| 650 | - if ($activation_history_for_addon) { |
|
| 651 | - //it exists, so this isn't a completely new install |
|
| 652 | - //check if this version already in that list of previously installed versions |
|
| 653 | - if (! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
| 654 | - //it a version we haven't seen before |
|
| 655 | - if ($version_is_higher === 1) { |
|
| 656 | - $req_type = EE_System::req_type_upgrade; |
|
| 657 | - } else { |
|
| 658 | - $req_type = EE_System::req_type_downgrade; |
|
| 659 | - } |
|
| 660 | - delete_option($activation_indicator_option_name); |
|
| 661 | - } else { |
|
| 662 | - // its not an update. maybe a reactivation? |
|
| 663 | - if (get_option($activation_indicator_option_name, false)) { |
|
| 664 | - if ($version_is_higher === -1) { |
|
| 665 | - $req_type = EE_System::req_type_downgrade; |
|
| 666 | - } else if ($version_is_higher === 0) { |
|
| 667 | - //we've seen this version before, but it's an activation. must be a reactivation |
|
| 668 | - $req_type = EE_System::req_type_reactivation; |
|
| 669 | - } else {//$version_is_higher === 1 |
|
| 670 | - $req_type = EE_System::req_type_upgrade; |
|
| 671 | - } |
|
| 672 | - delete_option($activation_indicator_option_name); |
|
| 673 | - } else { |
|
| 674 | - //we've seen this version before and the activation indicate doesn't show it was just activated |
|
| 675 | - if ($version_is_higher === -1) { |
|
| 676 | - $req_type = EE_System::req_type_downgrade; |
|
| 677 | - } else if ($version_is_higher === 0) { |
|
| 678 | - //we've seen this version before and it's not an activation. its normal request |
|
| 679 | - $req_type = EE_System::req_type_normal; |
|
| 680 | - } else {//$version_is_higher === 1 |
|
| 681 | - $req_type = EE_System::req_type_upgrade; |
|
| 682 | - } |
|
| 683 | - } |
|
| 684 | - } |
|
| 685 | - } else { |
|
| 686 | - //brand new install |
|
| 687 | - $req_type = EE_System::req_type_new_activation; |
|
| 688 | - delete_option($activation_indicator_option_name); |
|
| 689 | - } |
|
| 690 | - return $req_type; |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - |
|
| 694 | - |
|
| 695 | - /** |
|
| 696 | - * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
| 697 | - * the $activation_history_for_addon |
|
| 698 | - * |
|
| 699 | - * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
| 700 | - * sometimes containing 'unknown-date' |
|
| 701 | - * @param string $version_to_upgrade_to (current version) |
|
| 702 | - * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
| 703 | - * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
| 704 | - * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
| 705 | - * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
| 706 | - */ |
|
| 707 | - private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
| 708 | - { |
|
| 709 | - //find the most recently-activated version |
|
| 710 | - $most_recently_active_version = |
|
| 711 | - EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
| 712 | - return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
| 713 | - } |
|
| 714 | - |
|
| 715 | - |
|
| 716 | - |
|
| 717 | - /** |
|
| 718 | - * Gets the most recently active version listed in the activation history, |
|
| 719 | - * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
| 720 | - * |
|
| 721 | - * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
| 722 | - * sometimes containing 'unknown-date' |
|
| 723 | - * @return string |
|
| 724 | - */ |
|
| 725 | - private static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
| 726 | - { |
|
| 727 | - $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
| 728 | - $most_recently_active_version = '0.0.0.dev.000'; |
|
| 729 | - if (is_array($activation_history)) { |
|
| 730 | - foreach ($activation_history as $version => $times_activated) { |
|
| 731 | - //check there is a record of when this version was activated. Otherwise, |
|
| 732 | - //mark it as unknown |
|
| 733 | - if (! $times_activated) { |
|
| 734 | - $times_activated = array('unknown-date'); |
|
| 735 | - } |
|
| 736 | - if (is_string($times_activated)) { |
|
| 737 | - $times_activated = array($times_activated); |
|
| 738 | - } |
|
| 739 | - foreach ($times_activated as $an_activation) { |
|
| 740 | - if ($an_activation !== 'unknown-date' && $an_activation > $most_recently_active_version_activation) { |
|
| 741 | - $most_recently_active_version = $version; |
|
| 742 | - $most_recently_active_version_activation = $an_activation === 'unknown-date' |
|
| 743 | - ? '1970-01-01 00:00:00' |
|
| 744 | - : $an_activation; |
|
| 745 | - } |
|
| 746 | - } |
|
| 747 | - } |
|
| 748 | - } |
|
| 749 | - return $most_recently_active_version; |
|
| 750 | - } |
|
| 751 | - |
|
| 752 | - |
|
| 753 | - |
|
| 754 | - /** |
|
| 755 | - * This redirects to the about EE page after activation |
|
| 756 | - * |
|
| 757 | - * @return void |
|
| 758 | - */ |
|
| 759 | - public function redirect_to_about_ee() |
|
| 760 | - { |
|
| 761 | - $notices = EE_Error::get_notices(false); |
|
| 762 | - //if current user is an admin and it's not an ajax or rest request |
|
| 763 | - if ( |
|
| 764 | - ! (defined('DOING_AJAX') && DOING_AJAX) |
|
| 765 | - && ! (defined('REST_REQUEST') && REST_REQUEST) |
|
| 766 | - && ! isset($notices['errors']) |
|
| 767 | - && apply_filters( |
|
| 768 | - 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
| 769 | - $this->capabilities->current_user_can('manage_options', 'espresso_about_default') |
|
| 770 | - ) |
|
| 771 | - ) { |
|
| 772 | - $query_params = array('page' => 'espresso_about'); |
|
| 773 | - if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) { |
|
| 774 | - $query_params['new_activation'] = true; |
|
| 775 | - } |
|
| 776 | - if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) { |
|
| 777 | - $query_params['reactivation'] = true; |
|
| 778 | - } |
|
| 779 | - $url = add_query_arg($query_params, admin_url('admin.php')); |
|
| 780 | - wp_safe_redirect($url); |
|
| 781 | - exit(); |
|
| 782 | - } |
|
| 783 | - } |
|
| 784 | - |
|
| 785 | - |
|
| 786 | - |
|
| 787 | - /** |
|
| 788 | - * load_core_configuration |
|
| 789 | - * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
| 790 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
| 791 | - * |
|
| 792 | - * @return void |
|
| 793 | - * @throws ReflectionException |
|
| 794 | - */ |
|
| 795 | - public function load_core_configuration() |
|
| 796 | - { |
|
| 797 | - do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
| 798 | - $this->loader->getShared('EE_Load_Textdomain'); |
|
| 799 | - //load textdomain |
|
| 800 | - EE_Load_Textdomain::load_textdomain(); |
|
| 801 | - // load and setup EE_Config and EE_Network_Config |
|
| 802 | - $config = $this->loader->getShared('EE_Config'); |
|
| 803 | - $this->loader->getShared('EE_Network_Config'); |
|
| 804 | - // setup autoloaders |
|
| 805 | - // enable logging? |
|
| 806 | - if ($config->admin->use_full_logging) { |
|
| 807 | - $this->loader->getShared('EE_Log'); |
|
| 808 | - } |
|
| 809 | - // check for activation errors |
|
| 810 | - $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
| 811 | - if ($activation_errors) { |
|
| 812 | - EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
| 813 | - update_option('ee_plugin_activation_errors', false); |
|
| 814 | - } |
|
| 815 | - // get model names |
|
| 816 | - $this->_parse_model_names(); |
|
| 817 | - //load caf stuff a chance to play during the activation process too. |
|
| 818 | - $this->_maybe_brew_regular(); |
|
| 819 | - do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
| 820 | - } |
|
| 821 | - |
|
| 822 | - |
|
| 823 | - |
|
| 824 | - /** |
|
| 825 | - * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
| 826 | - * |
|
| 827 | - * @return void |
|
| 828 | - * @throws ReflectionException |
|
| 829 | - */ |
|
| 830 | - private function _parse_model_names() |
|
| 831 | - { |
|
| 832 | - //get all the files in the EE_MODELS folder that end in .model.php |
|
| 833 | - $models = glob(EE_MODELS . '*.model.php'); |
|
| 834 | - $model_names = array(); |
|
| 835 | - $non_abstract_db_models = array(); |
|
| 836 | - foreach ($models as $model) { |
|
| 837 | - // get model classname |
|
| 838 | - $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
| 839 | - $short_name = str_replace('EEM_', '', $classname); |
|
| 840 | - $reflectionClass = new ReflectionClass($classname); |
|
| 841 | - if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
| 842 | - $non_abstract_db_models[$short_name] = $classname; |
|
| 843 | - } |
|
| 844 | - $model_names[$short_name] = $classname; |
|
| 845 | - } |
|
| 846 | - $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
| 847 | - $this->registry->non_abstract_db_models = apply_filters( |
|
| 848 | - 'FHEE__EE_System__parse_implemented_model_names', |
|
| 849 | - $non_abstract_db_models |
|
| 850 | - ); |
|
| 851 | - } |
|
| 852 | - |
|
| 853 | - |
|
| 854 | - |
|
| 855 | - /** |
|
| 856 | - * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
| 857 | - * that need to be setup before our EE_System launches. |
|
| 858 | - * |
|
| 859 | - * @return void |
|
| 860 | - */ |
|
| 861 | - private function _maybe_brew_regular() |
|
| 862 | - { |
|
| 863 | - if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
| 864 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
| 865 | - } |
|
| 866 | - } |
|
| 867 | - |
|
| 868 | - |
|
| 869 | - |
|
| 870 | - /** |
|
| 871 | - * register_shortcodes_modules_and_widgets |
|
| 872 | - * generate lists of shortcodes and modules, then verify paths and classes |
|
| 873 | - * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
| 874 | - * which runs during the WP 'plugins_loaded' action at priority 7 |
|
| 875 | - * |
|
| 876 | - * @access public |
|
| 877 | - * @return void |
|
| 878 | - * @throws Exception |
|
| 879 | - */ |
|
| 880 | - public function register_shortcodes_modules_and_widgets() |
|
| 881 | - { |
|
| 882 | - try { |
|
| 883 | - // load, register, and add shortcodes the new way |
|
| 884 | - $this->loader->getShared( |
|
| 885 | - 'EventEspresso\core\services\shortcodes\ShortcodesManager', |
|
| 886 | - array( |
|
| 887 | - // and the old way, but we'll put it under control of the new system |
|
| 888 | - EE_Config::getLegacyShortcodesManager() |
|
| 889 | - ) |
|
| 890 | - ); |
|
| 891 | - } catch (Exception $exception) { |
|
| 892 | - new ExceptionStackTraceDisplay($exception); |
|
| 893 | - } |
|
| 894 | - do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
| 895 | - // check for addons using old hook point |
|
| 896 | - if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
| 897 | - $this->_incompatible_addon_error(); |
|
| 898 | - } |
|
| 899 | - } |
|
| 900 | - |
|
| 901 | - |
|
| 902 | - |
|
| 903 | - /** |
|
| 904 | - * _incompatible_addon_error |
|
| 905 | - * |
|
| 906 | - * @access public |
|
| 907 | - * @return void |
|
| 908 | - */ |
|
| 909 | - private function _incompatible_addon_error() |
|
| 910 | - { |
|
| 911 | - // get array of classes hooking into here |
|
| 912 | - $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook( |
|
| 913 | - 'AHEE__EE_System__register_shortcodes_modules_and_addons' |
|
| 914 | - ); |
|
| 915 | - if (! empty($class_names)) { |
|
| 916 | - $msg = __( |
|
| 917 | - 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
| 918 | - 'event_espresso' |
|
| 919 | - ); |
|
| 920 | - $msg .= '<ul>'; |
|
| 921 | - foreach ($class_names as $class_name) { |
|
| 922 | - $msg .= '<li><b>Event Espresso - ' . str_replace( |
|
| 923 | - array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
| 924 | - $class_name |
|
| 925 | - ) . '</b></li>'; |
|
| 926 | - } |
|
| 927 | - $msg .= '</ul>'; |
|
| 928 | - $msg .= __( |
|
| 929 | - 'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
| 930 | - 'event_espresso' |
|
| 931 | - ); |
|
| 932 | - // save list of incompatible addons to wp-options for later use |
|
| 933 | - add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
| 934 | - if (is_admin()) { |
|
| 935 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 936 | - } |
|
| 937 | - } |
|
| 938 | - } |
|
| 939 | - |
|
| 940 | - |
|
| 941 | - |
|
| 942 | - /** |
|
| 943 | - * brew_espresso |
|
| 944 | - * begins the process of setting hooks for initializing EE in the correct order |
|
| 945 | - * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point |
|
| 946 | - * which runs during the WP 'plugins_loaded' action at priority 9 |
|
| 947 | - * |
|
| 948 | - * @return void |
|
| 949 | - */ |
|
| 950 | - public function brew_espresso() |
|
| 951 | - { |
|
| 952 | - do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
| 953 | - // load some final core systems |
|
| 954 | - add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
| 955 | - add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
| 956 | - add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
| 957 | - add_action('init', array($this, 'load_controllers'), 7); |
|
| 958 | - add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
| 959 | - add_action('init', array($this, 'initialize'), 10); |
|
| 960 | - add_action('init', array($this, 'initialize_last'), 100); |
|
| 961 | - if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
| 962 | - // pew pew pew |
|
| 963 | - $this->loader->getShared('EE_PUE'); |
|
| 964 | - do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
| 965 | - } |
|
| 966 | - do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
| 967 | - } |
|
| 968 | - |
|
| 969 | - |
|
| 970 | - |
|
| 971 | - /** |
|
| 972 | - * set_hooks_for_core |
|
| 973 | - * |
|
| 974 | - * @access public |
|
| 975 | - * @return void |
|
| 976 | - * @throws EE_Error |
|
| 977 | - */ |
|
| 978 | - public function set_hooks_for_core() |
|
| 979 | - { |
|
| 980 | - $this->_deactivate_incompatible_addons(); |
|
| 981 | - do_action('AHEE__EE_System__set_hooks_for_core'); |
|
| 982 | - //caps need to be initialized on every request so that capability maps are set. |
|
| 983 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
| 984 | - $this->registry->CAP->init_caps(); |
|
| 985 | - } |
|
| 986 | - |
|
| 987 | - |
|
| 988 | - |
|
| 989 | - /** |
|
| 990 | - * Using the information gathered in EE_System::_incompatible_addon_error, |
|
| 991 | - * deactivates any addons considered incompatible with the current version of EE |
|
| 992 | - */ |
|
| 993 | - private function _deactivate_incompatible_addons() |
|
| 994 | - { |
|
| 995 | - $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
| 996 | - if (! empty($incompatible_addons)) { |
|
| 997 | - $active_plugins = get_option('active_plugins', array()); |
|
| 998 | - foreach ($active_plugins as $active_plugin) { |
|
| 999 | - foreach ($incompatible_addons as $incompatible_addon) { |
|
| 1000 | - if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
| 1001 | - unset($_GET['activate']); |
|
| 1002 | - espresso_deactivate_plugin($active_plugin); |
|
| 1003 | - } |
|
| 1004 | - } |
|
| 1005 | - } |
|
| 1006 | - } |
|
| 1007 | - } |
|
| 1008 | - |
|
| 1009 | - |
|
| 1010 | - |
|
| 1011 | - /** |
|
| 1012 | - * perform_activations_upgrades_and_migrations |
|
| 1013 | - * |
|
| 1014 | - * @access public |
|
| 1015 | - * @return void |
|
| 1016 | - */ |
|
| 1017 | - public function perform_activations_upgrades_and_migrations() |
|
| 1018 | - { |
|
| 1019 | - //first check if we had previously attempted to setup EE's directories but failed |
|
| 1020 | - if (EEH_Activation::upload_directories_incomplete()) { |
|
| 1021 | - EEH_Activation::create_upload_directories(); |
|
| 1022 | - } |
|
| 1023 | - do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
| 1024 | - } |
|
| 1025 | - |
|
| 1026 | - |
|
| 1027 | - |
|
| 1028 | - /** |
|
| 1029 | - * load_CPTs_and_session |
|
| 1030 | - * |
|
| 1031 | - * @access public |
|
| 1032 | - * @return void |
|
| 1033 | - */ |
|
| 1034 | - public function load_CPTs_and_session() |
|
| 1035 | - { |
|
| 1036 | - do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
| 1037 | - // register Custom Post Types |
|
| 1038 | - $this->loader->getShared('EE_Register_CPTs'); |
|
| 1039 | - do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
| 1040 | - } |
|
| 1041 | - |
|
| 1042 | - |
|
| 1043 | - |
|
| 1044 | - /** |
|
| 1045 | - * load_controllers |
|
| 1046 | - * this is the best place to load any additional controllers that needs access to EE core. |
|
| 1047 | - * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
| 1048 | - * time |
|
| 1049 | - * |
|
| 1050 | - * @access public |
|
| 1051 | - * @return void |
|
| 1052 | - */ |
|
| 1053 | - public function load_controllers() |
|
| 1054 | - { |
|
| 1055 | - do_action('AHEE__EE_System__load_controllers__start'); |
|
| 1056 | - // let's get it started |
|
| 1057 | - if (! is_admin() && ! $this->maintenance_mode->level()) { |
|
| 1058 | - do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
| 1059 | - $this->loader->getShared('EE_Front_Controller'); |
|
| 1060 | - } else if (! EE_FRONT_AJAX) { |
|
| 1061 | - do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
| 1062 | - $this->loader->getShared('EE_Admin'); |
|
| 1063 | - } |
|
| 1064 | - do_action('AHEE__EE_System__load_controllers__complete'); |
|
| 1065 | - } |
|
| 1066 | - |
|
| 1067 | - |
|
| 1068 | - |
|
| 1069 | - /** |
|
| 1070 | - * core_loaded_and_ready |
|
| 1071 | - * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
| 1072 | - * |
|
| 1073 | - * @access public |
|
| 1074 | - * @return void |
|
| 1075 | - */ |
|
| 1076 | - public function core_loaded_and_ready() |
|
| 1077 | - { |
|
| 1078 | - $this->loader->getShared('EE_Session'); |
|
| 1079 | - do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
| 1080 | - // load_espresso_template_tags |
|
| 1081 | - if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
| 1082 | - require_once(EE_PUBLIC . 'template_tags.php'); |
|
| 1083 | - } |
|
| 1084 | - do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
| 1085 | - $this->loader->getShared('EventEspresso\core\services\assets\Registry'); |
|
| 1086 | - } |
|
| 1087 | - |
|
| 1088 | - |
|
| 1089 | - |
|
| 1090 | - /** |
|
| 1091 | - * initialize |
|
| 1092 | - * this is the best place to begin initializing client code |
|
| 1093 | - * |
|
| 1094 | - * @access public |
|
| 1095 | - * @return void |
|
| 1096 | - */ |
|
| 1097 | - public function initialize() |
|
| 1098 | - { |
|
| 1099 | - do_action('AHEE__EE_System__initialize'); |
|
| 1100 | - } |
|
| 1101 | - |
|
| 1102 | - |
|
| 1103 | - |
|
| 1104 | - /** |
|
| 1105 | - * initialize_last |
|
| 1106 | - * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to |
|
| 1107 | - * initialize has done so |
|
| 1108 | - * |
|
| 1109 | - * @access public |
|
| 1110 | - * @return void |
|
| 1111 | - */ |
|
| 1112 | - public function initialize_last() |
|
| 1113 | - { |
|
| 1114 | - do_action('AHEE__EE_System__initialize_last'); |
|
| 1115 | - add_action('admin_bar_init', array($this, 'addEspressoToolbar')); |
|
| 1116 | - } |
|
| 1117 | - |
|
| 1118 | - |
|
| 1119 | - |
|
| 1120 | - /** |
|
| 1121 | - * @return void |
|
| 1122 | - * @throws EE_Error |
|
| 1123 | - */ |
|
| 1124 | - public function addEspressoToolbar() |
|
| 1125 | - { |
|
| 1126 | - $this->loader->getShared( |
|
| 1127 | - 'EventEspresso\core\domain\services\admin\AdminToolBar', |
|
| 1128 | - array($this->registry->CAP) |
|
| 1129 | - ); |
|
| 1130 | - } |
|
| 1131 | - |
|
| 1132 | - |
|
| 1133 | - |
|
| 1134 | - /** |
|
| 1135 | - * do_not_cache |
|
| 1136 | - * sets no cache headers and defines no cache constants for WP plugins |
|
| 1137 | - * |
|
| 1138 | - * @access public |
|
| 1139 | - * @return void |
|
| 1140 | - */ |
|
| 1141 | - public static function do_not_cache() |
|
| 1142 | - { |
|
| 1143 | - // set no cache constants |
|
| 1144 | - if (! defined('DONOTCACHEPAGE')) { |
|
| 1145 | - define('DONOTCACHEPAGE', true); |
|
| 1146 | - } |
|
| 1147 | - if (! defined('DONOTCACHCEOBJECT')) { |
|
| 1148 | - define('DONOTCACHCEOBJECT', true); |
|
| 1149 | - } |
|
| 1150 | - if (! defined('DONOTCACHEDB')) { |
|
| 1151 | - define('DONOTCACHEDB', true); |
|
| 1152 | - } |
|
| 1153 | - // add no cache headers |
|
| 1154 | - add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
| 1155 | - // plus a little extra for nginx and Google Chrome |
|
| 1156 | - add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
| 1157 | - // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
| 1158 | - remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
| 1159 | - } |
|
| 1160 | - |
|
| 1161 | - |
|
| 1162 | - |
|
| 1163 | - /** |
|
| 1164 | - * extra_nocache_headers |
|
| 1165 | - * |
|
| 1166 | - * @access public |
|
| 1167 | - * @param $headers |
|
| 1168 | - * @return array |
|
| 1169 | - */ |
|
| 1170 | - public static function extra_nocache_headers($headers) |
|
| 1171 | - { |
|
| 1172 | - // for NGINX |
|
| 1173 | - $headers['X-Accel-Expires'] = 0; |
|
| 1174 | - // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
| 1175 | - $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
| 1176 | - return $headers; |
|
| 1177 | - } |
|
| 1178 | - |
|
| 1179 | - |
|
| 1180 | - |
|
| 1181 | - /** |
|
| 1182 | - * nocache_headers |
|
| 1183 | - * |
|
| 1184 | - * @access public |
|
| 1185 | - * @return void |
|
| 1186 | - */ |
|
| 1187 | - public static function nocache_headers() |
|
| 1188 | - { |
|
| 1189 | - nocache_headers(); |
|
| 1190 | - } |
|
| 1191 | - |
|
| 1192 | - |
|
| 1193 | - |
|
| 1194 | - |
|
| 1195 | - /** |
|
| 1196 | - * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
| 1197 | - * never returned with the function. |
|
| 1198 | - * |
|
| 1199 | - * @param array $exclude_array any existing pages being excluded are in this array. |
|
| 1200 | - * @return array |
|
| 1201 | - */ |
|
| 1202 | - public function remove_pages_from_wp_list_pages($exclude_array) |
|
| 1203 | - { |
|
| 1204 | - return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
| 1205 | - } |
|
| 24 | + /** |
|
| 25 | + * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
| 26 | + * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
| 27 | + */ |
|
| 28 | + const req_type_normal = 0; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Indicates this is a brand new installation of EE so we should install |
|
| 32 | + * tables and default data etc |
|
| 33 | + */ |
|
| 34 | + const req_type_new_activation = 1; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
| 38 | + * and we just exited maintenance mode). We MUST check the database is setup properly |
|
| 39 | + * and that default data is setup too |
|
| 40 | + */ |
|
| 41 | + const req_type_reactivation = 2; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * indicates that EE has been upgraded since its previous request. |
|
| 45 | + * We may have data migration scripts to call and will want to trigger maintenance mode |
|
| 46 | + */ |
|
| 47 | + const req_type_upgrade = 3; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
| 51 | + */ |
|
| 52 | + const req_type_downgrade = 4; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @deprecated since version 4.6.0.dev.006 |
|
| 56 | + * Now whenever a new_activation is detected the request type is still just |
|
| 57 | + * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
| 58 | + * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
| 59 | + * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
| 60 | + * (Specifically, when the migration manager indicates migrations are finished |
|
| 61 | + * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
| 62 | + */ |
|
| 63 | + const req_type_activation_but_not_installed = 5; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
| 67 | + */ |
|
| 68 | + const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @var EE_System $_instance |
|
| 73 | + */ |
|
| 74 | + private static $_instance; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @var EE_Registry $registry |
|
| 78 | + */ |
|
| 79 | + private $registry; |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @var LoaderInterface $loader |
|
| 83 | + */ |
|
| 84 | + private $loader; |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @var EE_Capabilities $capabilities |
|
| 88 | + */ |
|
| 89 | + private $capabilities; |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @var EE_Request $request |
|
| 93 | + */ |
|
| 94 | + private $request; |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @var EE_Maintenance_Mode $maintenance_mode |
|
| 98 | + */ |
|
| 99 | + private $maintenance_mode; |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
| 103 | + * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
| 104 | + * |
|
| 105 | + * @var int $_req_type |
|
| 106 | + */ |
|
| 107 | + private $_req_type; |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Whether or not there was a non-micro version change in EE core version during this request |
|
| 111 | + * |
|
| 112 | + * @var boolean $_major_version_change |
|
| 113 | + */ |
|
| 114 | + private $_major_version_change = false; |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * @singleton method used to instantiate class object |
|
| 120 | + * @param EE_Registry|null $registry |
|
| 121 | + * @param LoaderInterface|null $loader |
|
| 122 | + * @param EE_Capabilities|null $capabilities |
|
| 123 | + * @param EE_Request|null $request |
|
| 124 | + * @param EE_Maintenance_Mode|null $maintenance_mode |
|
| 125 | + * @return EE_System |
|
| 126 | + */ |
|
| 127 | + public static function instance( |
|
| 128 | + EE_Registry $registry = null, |
|
| 129 | + LoaderInterface $loader = null, |
|
| 130 | + EE_Capabilities $capabilities = null, |
|
| 131 | + EE_Request $request = null, |
|
| 132 | + EE_Maintenance_Mode $maintenance_mode = null |
|
| 133 | + ) { |
|
| 134 | + // check if class object is instantiated |
|
| 135 | + if (! self::$_instance instanceof EE_System) { |
|
| 136 | + self::$_instance = new self($registry, $loader, $capabilities, $request, $maintenance_mode); |
|
| 137 | + } |
|
| 138 | + return self::$_instance; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * resets the instance and returns it |
|
| 145 | + * |
|
| 146 | + * @return EE_System |
|
| 147 | + */ |
|
| 148 | + public static function reset() |
|
| 149 | + { |
|
| 150 | + self::$_instance->_req_type = null; |
|
| 151 | + //make sure none of the old hooks are left hanging around |
|
| 152 | + remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
| 153 | + //we need to reset the migration manager in order for it to detect DMSs properly |
|
| 154 | + EE_Data_Migration_Manager::reset(); |
|
| 155 | + self::instance()->detect_activations_or_upgrades(); |
|
| 156 | + self::instance()->perform_activations_upgrades_and_migrations(); |
|
| 157 | + return self::instance(); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * sets hooks for running rest of system |
|
| 164 | + * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
| 165 | + * starting EE Addons from any other point may lead to problems |
|
| 166 | + * |
|
| 167 | + * @param EE_Registry $registry |
|
| 168 | + * @param LoaderInterface $loader |
|
| 169 | + * @param EE_Capabilities $capabilities |
|
| 170 | + * @param EE_Request $request |
|
| 171 | + * @param EE_Maintenance_Mode $maintenance_mode |
|
| 172 | + */ |
|
| 173 | + private function __construct( |
|
| 174 | + EE_Registry $registry, |
|
| 175 | + LoaderInterface $loader, |
|
| 176 | + EE_Capabilities $capabilities, |
|
| 177 | + EE_Request $request, |
|
| 178 | + EE_Maintenance_Mode $maintenance_mode |
|
| 179 | + ) { |
|
| 180 | + $this->registry = $registry; |
|
| 181 | + $this->loader = $loader; |
|
| 182 | + $this->capabilities = $capabilities; |
|
| 183 | + $this->request = $request; |
|
| 184 | + $this->maintenance_mode = $maintenance_mode; |
|
| 185 | + do_action('AHEE__EE_System__construct__begin', $this); |
|
| 186 | + add_action( |
|
| 187 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 188 | + array($this, 'loadCapabilities'), |
|
| 189 | + 5 |
|
| 190 | + ); |
|
| 191 | + add_action( |
|
| 192 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 193 | + array($this, 'loadCommandBus'), |
|
| 194 | + 7 |
|
| 195 | + ); |
|
| 196 | + add_action( |
|
| 197 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 198 | + array($this, 'loadPluginApi'), |
|
| 199 | + 9 |
|
| 200 | + ); |
|
| 201 | + // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
| 202 | + add_action( |
|
| 203 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 204 | + array($this, 'load_espresso_addons') |
|
| 205 | + ); |
|
| 206 | + // when an ee addon is activated, we want to call the core hook(s) again |
|
| 207 | + // because the newly-activated addon didn't get a chance to run at all |
|
| 208 | + add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
| 209 | + // detect whether install or upgrade |
|
| 210 | + add_action( |
|
| 211 | + 'AHEE__EE_Bootstrap__detect_activations_or_upgrades', |
|
| 212 | + array($this, 'detect_activations_or_upgrades'), |
|
| 213 | + 3 |
|
| 214 | + ); |
|
| 215 | + // load EE_Config, EE_Textdomain, etc |
|
| 216 | + add_action( |
|
| 217 | + 'AHEE__EE_Bootstrap__load_core_configuration', |
|
| 218 | + array($this, 'load_core_configuration'), |
|
| 219 | + 5 |
|
| 220 | + ); |
|
| 221 | + // load EE_Config, EE_Textdomain, etc |
|
| 222 | + add_action( |
|
| 223 | + 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
| 224 | + array($this, 'register_shortcodes_modules_and_widgets'), |
|
| 225 | + 7 |
|
| 226 | + ); |
|
| 227 | + // you wanna get going? I wanna get going... let's get going! |
|
| 228 | + add_action( |
|
| 229 | + 'AHEE__EE_Bootstrap__brew_espresso', |
|
| 230 | + array($this, 'brew_espresso'), |
|
| 231 | + 9 |
|
| 232 | + ); |
|
| 233 | + //other housekeeping |
|
| 234 | + //exclude EE critical pages from wp_list_pages |
|
| 235 | + add_filter( |
|
| 236 | + 'wp_list_pages_excludes', |
|
| 237 | + array($this, 'remove_pages_from_wp_list_pages'), |
|
| 238 | + 10 |
|
| 239 | + ); |
|
| 240 | + // ALL EE Addons should use the following hook point to attach their initial setup too |
|
| 241 | + // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
| 242 | + do_action('AHEE__EE_System__construct__complete', $this); |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * load and setup EE_Capabilities |
|
| 249 | + * |
|
| 250 | + * @return void |
|
| 251 | + * @throws EE_Error |
|
| 252 | + */ |
|
| 253 | + public function loadCapabilities() |
|
| 254 | + { |
|
| 255 | + $this->loader->getShared('EE_Capabilities'); |
|
| 256 | + add_action( |
|
| 257 | + 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
| 258 | + function() { |
|
| 259 | + LoaderFactory::getLoader()->getShared('Payment_Method_Manager'); |
|
| 260 | + } |
|
| 261 | + ); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * create and cache the CommandBus, and also add middleware |
|
| 268 | + * The CapChecker middleware requires the use of EE_Capabilities |
|
| 269 | + * which is why we need to load the CommandBus after Caps are set up |
|
| 270 | + * |
|
| 271 | + * @return void |
|
| 272 | + * @throws EE_Error |
|
| 273 | + */ |
|
| 274 | + public function loadCommandBus() |
|
| 275 | + { |
|
| 276 | + $this->loader->getShared( |
|
| 277 | + 'CommandBusInterface', |
|
| 278 | + array( |
|
| 279 | + null, |
|
| 280 | + apply_filters( |
|
| 281 | + 'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware', |
|
| 282 | + array( |
|
| 283 | + $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'), |
|
| 284 | + $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'), |
|
| 285 | + ) |
|
| 286 | + ), |
|
| 287 | + ) |
|
| 288 | + ); |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * @return void |
|
| 295 | + * @throws EE_Error |
|
| 296 | + */ |
|
| 297 | + public function loadPluginApi() |
|
| 298 | + { |
|
| 299 | + // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
| 300 | + // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
| 301 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * load_espresso_addons |
|
| 308 | + * allow addons to load first so that they can set hooks for running DMS's, etc |
|
| 309 | + * this is hooked into both: |
|
| 310 | + * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
| 311 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
| 312 | + * and the WP 'activate_plugin' hook point |
|
| 313 | + * |
|
| 314 | + * @access public |
|
| 315 | + * @return void |
|
| 316 | + * @throws EE_Error |
|
| 317 | + */ |
|
| 318 | + public function load_espresso_addons() |
|
| 319 | + { |
|
| 320 | + do_action('AHEE__EE_System__load_espresso_addons'); |
|
| 321 | + //if the WP API basic auth plugin isn't already loaded, load it now. |
|
| 322 | + //We want it for mobile apps. Just include the entire plugin |
|
| 323 | + //also, don't load the basic auth when a plugin is getting activated, because |
|
| 324 | + //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
| 325 | + //and causes a fatal error |
|
| 326 | + if ( |
|
| 327 | + ! ( |
|
| 328 | + isset($_GET['activate']) |
|
| 329 | + && $_GET['activate'] === 'true' |
|
| 330 | + ) |
|
| 331 | + && ! function_exists('json_basic_auth_handler') |
|
| 332 | + && ! function_exists('json_basic_auth_error') |
|
| 333 | + && ! ( |
|
| 334 | + isset($_GET['action']) |
|
| 335 | + && in_array($_GET['action'], array('activate', 'activate-selected'), true) |
|
| 336 | + ) |
|
| 337 | + ) { |
|
| 338 | + include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
| 339 | + } |
|
| 340 | + do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + |
|
| 344 | + |
|
| 345 | + /** |
|
| 346 | + * detect_activations_or_upgrades |
|
| 347 | + * Checks for activation or upgrade of core first; |
|
| 348 | + * then also checks if any registered addons have been activated or upgraded |
|
| 349 | + * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
| 350 | + * which runs during the WP 'plugins_loaded' action at priority 3 |
|
| 351 | + * |
|
| 352 | + * @access public |
|
| 353 | + * @return void |
|
| 354 | + */ |
|
| 355 | + public function detect_activations_or_upgrades() |
|
| 356 | + { |
|
| 357 | + //first off: let's make sure to handle core |
|
| 358 | + $this->detect_if_activation_or_upgrade(); |
|
| 359 | + foreach ($this->registry->addons as $addon) { |
|
| 360 | + if ($addon instanceof EE_Addon) { |
|
| 361 | + //detect teh request type for that addon |
|
| 362 | + $addon->detect_activation_or_upgrade(); |
|
| 363 | + } |
|
| 364 | + } |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * detect_if_activation_or_upgrade |
|
| 371 | + * Takes care of detecting whether this is a brand new install or code upgrade, |
|
| 372 | + * and either setting up the DB or setting up maintenance mode etc. |
|
| 373 | + * |
|
| 374 | + * @access public |
|
| 375 | + * @return void |
|
| 376 | + */ |
|
| 377 | + public function detect_if_activation_or_upgrade() |
|
| 378 | + { |
|
| 379 | + do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
| 380 | + // check if db has been updated, or if its a brand-new installation |
|
| 381 | + $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
| 382 | + $request_type = $this->detect_req_type($espresso_db_update); |
|
| 383 | + //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
| 384 | + switch ($request_type) { |
|
| 385 | + case EE_System::req_type_new_activation: |
|
| 386 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
| 387 | + $this->_handle_core_version_change($espresso_db_update); |
|
| 388 | + break; |
|
| 389 | + case EE_System::req_type_reactivation: |
|
| 390 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
| 391 | + $this->_handle_core_version_change($espresso_db_update); |
|
| 392 | + break; |
|
| 393 | + case EE_System::req_type_upgrade: |
|
| 394 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
| 395 | + //migrations may be required now that we've upgraded |
|
| 396 | + $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
| 397 | + $this->_handle_core_version_change($espresso_db_update); |
|
| 398 | + // echo "done upgrade";die; |
|
| 399 | + break; |
|
| 400 | + case EE_System::req_type_downgrade: |
|
| 401 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
| 402 | + //its possible migrations are no longer required |
|
| 403 | + $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
| 404 | + $this->_handle_core_version_change($espresso_db_update); |
|
| 405 | + break; |
|
| 406 | + case EE_System::req_type_normal: |
|
| 407 | + default: |
|
| 408 | + // $this->_maybe_redirect_to_ee_about(); |
|
| 409 | + break; |
|
| 410 | + } |
|
| 411 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + |
|
| 415 | + |
|
| 416 | + /** |
|
| 417 | + * Updates the list of installed versions and sets hooks for |
|
| 418 | + * initializing the database later during the request |
|
| 419 | + * |
|
| 420 | + * @param array $espresso_db_update |
|
| 421 | + */ |
|
| 422 | + private function _handle_core_version_change($espresso_db_update) |
|
| 423 | + { |
|
| 424 | + $this->update_list_of_installed_versions($espresso_db_update); |
|
| 425 | + //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
| 426 | + add_action( |
|
| 427 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 428 | + array($this, 'initialize_db_if_no_migrations_required') |
|
| 429 | + ); |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
| 436 | + * information about what versions of EE have been installed and activated, |
|
| 437 | + * NOT necessarily the state of the database |
|
| 438 | + * |
|
| 439 | + * @param mixed $espresso_db_update the value of the WordPress option. |
|
| 440 | + * If not supplied, fetches it from the options table |
|
| 441 | + * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
| 442 | + */ |
|
| 443 | + private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
| 444 | + { |
|
| 445 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
| 446 | + if (! $espresso_db_update) { |
|
| 447 | + $espresso_db_update = get_option('espresso_db_update'); |
|
| 448 | + } |
|
| 449 | + // check that option is an array |
|
| 450 | + if (! is_array($espresso_db_update)) { |
|
| 451 | + // if option is FALSE, then it never existed |
|
| 452 | + if ($espresso_db_update === false) { |
|
| 453 | + // make $espresso_db_update an array and save option with autoload OFF |
|
| 454 | + $espresso_db_update = array(); |
|
| 455 | + add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
| 456 | + } else { |
|
| 457 | + // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
| 458 | + $espresso_db_update = array($espresso_db_update => array()); |
|
| 459 | + update_option('espresso_db_update', $espresso_db_update); |
|
| 460 | + } |
|
| 461 | + } else { |
|
| 462 | + $corrected_db_update = array(); |
|
| 463 | + //if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
| 464 | + foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
| 465 | + if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
| 466 | + //the key is an int, and the value IS NOT an array |
|
| 467 | + //so it must be numerically-indexed, where values are versions installed... |
|
| 468 | + //fix it! |
|
| 469 | + $version_string = $should_be_array; |
|
| 470 | + $corrected_db_update[$version_string] = array('unknown-date'); |
|
| 471 | + } else { |
|
| 472 | + //ok it checks out |
|
| 473 | + $corrected_db_update[$should_be_version_string] = $should_be_array; |
|
| 474 | + } |
|
| 475 | + } |
|
| 476 | + $espresso_db_update = $corrected_db_update; |
|
| 477 | + update_option('espresso_db_update', $espresso_db_update); |
|
| 478 | + } |
|
| 479 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
| 480 | + return $espresso_db_update; |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + |
|
| 484 | + |
|
| 485 | + /** |
|
| 486 | + * Does the traditional work of setting up the plugin's database and adding default data. |
|
| 487 | + * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
| 488 | + * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
| 489 | + * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
| 490 | + * so that it will be done when migrations are finished |
|
| 491 | + * |
|
| 492 | + * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
| 493 | + * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
| 494 | + * This is a resource-intensive job |
|
| 495 | + * so we prefer to only do it when necessary |
|
| 496 | + * @return void |
|
| 497 | + * @throws EE_Error |
|
| 498 | + */ |
|
| 499 | + public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
| 500 | + { |
|
| 501 | + $request_type = $this->detect_req_type(); |
|
| 502 | + //only initialize system if we're not in maintenance mode. |
|
| 503 | + if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 504 | + update_option('ee_flush_rewrite_rules', true); |
|
| 505 | + if ($verify_schema) { |
|
| 506 | + EEH_Activation::initialize_db_and_folders(); |
|
| 507 | + } |
|
| 508 | + EEH_Activation::initialize_db_content(); |
|
| 509 | + EEH_Activation::system_initialization(); |
|
| 510 | + if ($initialize_addons_too) { |
|
| 511 | + $this->initialize_addons(); |
|
| 512 | + } |
|
| 513 | + } else { |
|
| 514 | + EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
| 515 | + } |
|
| 516 | + if ($request_type === EE_System::req_type_new_activation |
|
| 517 | + || $request_type === EE_System::req_type_reactivation |
|
| 518 | + || ( |
|
| 519 | + $request_type === EE_System::req_type_upgrade |
|
| 520 | + && $this->is_major_version_change() |
|
| 521 | + ) |
|
| 522 | + ) { |
|
| 523 | + add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
| 524 | + } |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + |
|
| 528 | + |
|
| 529 | + /** |
|
| 530 | + * Initializes the db for all registered addons |
|
| 531 | + * |
|
| 532 | + * @throws EE_Error |
|
| 533 | + */ |
|
| 534 | + public function initialize_addons() |
|
| 535 | + { |
|
| 536 | + //foreach registered addon, make sure its db is up-to-date too |
|
| 537 | + foreach ($this->registry->addons as $addon) { |
|
| 538 | + if ($addon instanceof EE_Addon) { |
|
| 539 | + $addon->initialize_db_if_no_migrations_required(); |
|
| 540 | + } |
|
| 541 | + } |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
| 548 | + * |
|
| 549 | + * @param array $version_history |
|
| 550 | + * @param string $current_version_to_add version to be added to the version history |
|
| 551 | + * @return boolean success as to whether or not this option was changed |
|
| 552 | + */ |
|
| 553 | + public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
| 554 | + { |
|
| 555 | + if (! $version_history) { |
|
| 556 | + $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
| 557 | + } |
|
| 558 | + if ($current_version_to_add === null) { |
|
| 559 | + $current_version_to_add = espresso_version(); |
|
| 560 | + } |
|
| 561 | + $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
| 562 | + // re-save |
|
| 563 | + return update_option('espresso_db_update', $version_history); |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + |
|
| 567 | + |
|
| 568 | + /** |
|
| 569 | + * Detects if the current version indicated in the has existed in the list of |
|
| 570 | + * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
| 571 | + * |
|
| 572 | + * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
| 573 | + * If not supplied, fetches it from the options table. |
|
| 574 | + * Also, caches its result so later parts of the code can also know whether |
|
| 575 | + * there's been an update or not. This way we can add the current version to |
|
| 576 | + * espresso_db_update, but still know if this is a new install or not |
|
| 577 | + * @return int one of the constants on EE_System::req_type_ |
|
| 578 | + */ |
|
| 579 | + public function detect_req_type($espresso_db_update = null) |
|
| 580 | + { |
|
| 581 | + if ($this->_req_type === null) { |
|
| 582 | + $espresso_db_update = ! empty($espresso_db_update) |
|
| 583 | + ? $espresso_db_update |
|
| 584 | + : $this->fix_espresso_db_upgrade_option(); |
|
| 585 | + $this->_req_type = EE_System::detect_req_type_given_activation_history( |
|
| 586 | + $espresso_db_update, |
|
| 587 | + 'ee_espresso_activation', espresso_version() |
|
| 588 | + ); |
|
| 589 | + $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
| 590 | + } |
|
| 591 | + return $this->_req_type; |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + |
|
| 595 | + |
|
| 596 | + /** |
|
| 597 | + * Returns whether or not there was a non-micro version change (ie, change in either |
|
| 598 | + * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
| 599 | + * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
| 600 | + * |
|
| 601 | + * @param $activation_history |
|
| 602 | + * @return bool |
|
| 603 | + */ |
|
| 604 | + private function _detect_major_version_change($activation_history) |
|
| 605 | + { |
|
| 606 | + $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
| 607 | + $previous_version_parts = explode('.', $previous_version); |
|
| 608 | + $current_version_parts = explode('.', espresso_version()); |
|
| 609 | + return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
| 610 | + && ($previous_version_parts[0] !== $current_version_parts[0] |
|
| 611 | + || $previous_version_parts[1] !== $current_version_parts[1] |
|
| 612 | + ); |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + |
|
| 616 | + |
|
| 617 | + /** |
|
| 618 | + * Returns true if either the major or minor version of EE changed during this request. |
|
| 619 | + * 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 |
|
| 620 | + * |
|
| 621 | + * @return bool |
|
| 622 | + */ |
|
| 623 | + public function is_major_version_change() |
|
| 624 | + { |
|
| 625 | + return $this->_major_version_change; |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + |
|
| 629 | + |
|
| 630 | + /** |
|
| 631 | + * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
| 632 | + * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily |
|
| 633 | + * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
| 634 | + * just activated to (for core that will always be espresso_version()) |
|
| 635 | + * |
|
| 636 | + * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
| 637 | + * ee plugin. for core that's 'espresso_db_update' |
|
| 638 | + * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to |
|
| 639 | + * indicate that this plugin was just activated |
|
| 640 | + * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
| 641 | + * espresso_version()) |
|
| 642 | + * @return int one of the constants on EE_System::req_type_* |
|
| 643 | + */ |
|
| 644 | + public static function detect_req_type_given_activation_history( |
|
| 645 | + $activation_history_for_addon, |
|
| 646 | + $activation_indicator_option_name, |
|
| 647 | + $version_to_upgrade_to |
|
| 648 | + ) { |
|
| 649 | + $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
| 650 | + if ($activation_history_for_addon) { |
|
| 651 | + //it exists, so this isn't a completely new install |
|
| 652 | + //check if this version already in that list of previously installed versions |
|
| 653 | + if (! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
| 654 | + //it a version we haven't seen before |
|
| 655 | + if ($version_is_higher === 1) { |
|
| 656 | + $req_type = EE_System::req_type_upgrade; |
|
| 657 | + } else { |
|
| 658 | + $req_type = EE_System::req_type_downgrade; |
|
| 659 | + } |
|
| 660 | + delete_option($activation_indicator_option_name); |
|
| 661 | + } else { |
|
| 662 | + // its not an update. maybe a reactivation? |
|
| 663 | + if (get_option($activation_indicator_option_name, false)) { |
|
| 664 | + if ($version_is_higher === -1) { |
|
| 665 | + $req_type = EE_System::req_type_downgrade; |
|
| 666 | + } else if ($version_is_higher === 0) { |
|
| 667 | + //we've seen this version before, but it's an activation. must be a reactivation |
|
| 668 | + $req_type = EE_System::req_type_reactivation; |
|
| 669 | + } else {//$version_is_higher === 1 |
|
| 670 | + $req_type = EE_System::req_type_upgrade; |
|
| 671 | + } |
|
| 672 | + delete_option($activation_indicator_option_name); |
|
| 673 | + } else { |
|
| 674 | + //we've seen this version before and the activation indicate doesn't show it was just activated |
|
| 675 | + if ($version_is_higher === -1) { |
|
| 676 | + $req_type = EE_System::req_type_downgrade; |
|
| 677 | + } else if ($version_is_higher === 0) { |
|
| 678 | + //we've seen this version before and it's not an activation. its normal request |
|
| 679 | + $req_type = EE_System::req_type_normal; |
|
| 680 | + } else {//$version_is_higher === 1 |
|
| 681 | + $req_type = EE_System::req_type_upgrade; |
|
| 682 | + } |
|
| 683 | + } |
|
| 684 | + } |
|
| 685 | + } else { |
|
| 686 | + //brand new install |
|
| 687 | + $req_type = EE_System::req_type_new_activation; |
|
| 688 | + delete_option($activation_indicator_option_name); |
|
| 689 | + } |
|
| 690 | + return $req_type; |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + |
|
| 694 | + |
|
| 695 | + /** |
|
| 696 | + * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
| 697 | + * the $activation_history_for_addon |
|
| 698 | + * |
|
| 699 | + * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
| 700 | + * sometimes containing 'unknown-date' |
|
| 701 | + * @param string $version_to_upgrade_to (current version) |
|
| 702 | + * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
| 703 | + * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
| 704 | + * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
| 705 | + * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
| 706 | + */ |
|
| 707 | + private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
| 708 | + { |
|
| 709 | + //find the most recently-activated version |
|
| 710 | + $most_recently_active_version = |
|
| 711 | + EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
| 712 | + return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
| 713 | + } |
|
| 714 | + |
|
| 715 | + |
|
| 716 | + |
|
| 717 | + /** |
|
| 718 | + * Gets the most recently active version listed in the activation history, |
|
| 719 | + * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
| 720 | + * |
|
| 721 | + * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
| 722 | + * sometimes containing 'unknown-date' |
|
| 723 | + * @return string |
|
| 724 | + */ |
|
| 725 | + private static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
| 726 | + { |
|
| 727 | + $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
| 728 | + $most_recently_active_version = '0.0.0.dev.000'; |
|
| 729 | + if (is_array($activation_history)) { |
|
| 730 | + foreach ($activation_history as $version => $times_activated) { |
|
| 731 | + //check there is a record of when this version was activated. Otherwise, |
|
| 732 | + //mark it as unknown |
|
| 733 | + if (! $times_activated) { |
|
| 734 | + $times_activated = array('unknown-date'); |
|
| 735 | + } |
|
| 736 | + if (is_string($times_activated)) { |
|
| 737 | + $times_activated = array($times_activated); |
|
| 738 | + } |
|
| 739 | + foreach ($times_activated as $an_activation) { |
|
| 740 | + if ($an_activation !== 'unknown-date' && $an_activation > $most_recently_active_version_activation) { |
|
| 741 | + $most_recently_active_version = $version; |
|
| 742 | + $most_recently_active_version_activation = $an_activation === 'unknown-date' |
|
| 743 | + ? '1970-01-01 00:00:00' |
|
| 744 | + : $an_activation; |
|
| 745 | + } |
|
| 746 | + } |
|
| 747 | + } |
|
| 748 | + } |
|
| 749 | + return $most_recently_active_version; |
|
| 750 | + } |
|
| 751 | + |
|
| 752 | + |
|
| 753 | + |
|
| 754 | + /** |
|
| 755 | + * This redirects to the about EE page after activation |
|
| 756 | + * |
|
| 757 | + * @return void |
|
| 758 | + */ |
|
| 759 | + public function redirect_to_about_ee() |
|
| 760 | + { |
|
| 761 | + $notices = EE_Error::get_notices(false); |
|
| 762 | + //if current user is an admin and it's not an ajax or rest request |
|
| 763 | + if ( |
|
| 764 | + ! (defined('DOING_AJAX') && DOING_AJAX) |
|
| 765 | + && ! (defined('REST_REQUEST') && REST_REQUEST) |
|
| 766 | + && ! isset($notices['errors']) |
|
| 767 | + && apply_filters( |
|
| 768 | + 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
| 769 | + $this->capabilities->current_user_can('manage_options', 'espresso_about_default') |
|
| 770 | + ) |
|
| 771 | + ) { |
|
| 772 | + $query_params = array('page' => 'espresso_about'); |
|
| 773 | + if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) { |
|
| 774 | + $query_params['new_activation'] = true; |
|
| 775 | + } |
|
| 776 | + if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) { |
|
| 777 | + $query_params['reactivation'] = true; |
|
| 778 | + } |
|
| 779 | + $url = add_query_arg($query_params, admin_url('admin.php')); |
|
| 780 | + wp_safe_redirect($url); |
|
| 781 | + exit(); |
|
| 782 | + } |
|
| 783 | + } |
|
| 784 | + |
|
| 785 | + |
|
| 786 | + |
|
| 787 | + /** |
|
| 788 | + * load_core_configuration |
|
| 789 | + * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
| 790 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
| 791 | + * |
|
| 792 | + * @return void |
|
| 793 | + * @throws ReflectionException |
|
| 794 | + */ |
|
| 795 | + public function load_core_configuration() |
|
| 796 | + { |
|
| 797 | + do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
| 798 | + $this->loader->getShared('EE_Load_Textdomain'); |
|
| 799 | + //load textdomain |
|
| 800 | + EE_Load_Textdomain::load_textdomain(); |
|
| 801 | + // load and setup EE_Config and EE_Network_Config |
|
| 802 | + $config = $this->loader->getShared('EE_Config'); |
|
| 803 | + $this->loader->getShared('EE_Network_Config'); |
|
| 804 | + // setup autoloaders |
|
| 805 | + // enable logging? |
|
| 806 | + if ($config->admin->use_full_logging) { |
|
| 807 | + $this->loader->getShared('EE_Log'); |
|
| 808 | + } |
|
| 809 | + // check for activation errors |
|
| 810 | + $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
| 811 | + if ($activation_errors) { |
|
| 812 | + EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
| 813 | + update_option('ee_plugin_activation_errors', false); |
|
| 814 | + } |
|
| 815 | + // get model names |
|
| 816 | + $this->_parse_model_names(); |
|
| 817 | + //load caf stuff a chance to play during the activation process too. |
|
| 818 | + $this->_maybe_brew_regular(); |
|
| 819 | + do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
| 820 | + } |
|
| 821 | + |
|
| 822 | + |
|
| 823 | + |
|
| 824 | + /** |
|
| 825 | + * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
| 826 | + * |
|
| 827 | + * @return void |
|
| 828 | + * @throws ReflectionException |
|
| 829 | + */ |
|
| 830 | + private function _parse_model_names() |
|
| 831 | + { |
|
| 832 | + //get all the files in the EE_MODELS folder that end in .model.php |
|
| 833 | + $models = glob(EE_MODELS . '*.model.php'); |
|
| 834 | + $model_names = array(); |
|
| 835 | + $non_abstract_db_models = array(); |
|
| 836 | + foreach ($models as $model) { |
|
| 837 | + // get model classname |
|
| 838 | + $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
| 839 | + $short_name = str_replace('EEM_', '', $classname); |
|
| 840 | + $reflectionClass = new ReflectionClass($classname); |
|
| 841 | + if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
| 842 | + $non_abstract_db_models[$short_name] = $classname; |
|
| 843 | + } |
|
| 844 | + $model_names[$short_name] = $classname; |
|
| 845 | + } |
|
| 846 | + $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
| 847 | + $this->registry->non_abstract_db_models = apply_filters( |
|
| 848 | + 'FHEE__EE_System__parse_implemented_model_names', |
|
| 849 | + $non_abstract_db_models |
|
| 850 | + ); |
|
| 851 | + } |
|
| 852 | + |
|
| 853 | + |
|
| 854 | + |
|
| 855 | + /** |
|
| 856 | + * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
| 857 | + * that need to be setup before our EE_System launches. |
|
| 858 | + * |
|
| 859 | + * @return void |
|
| 860 | + */ |
|
| 861 | + private function _maybe_brew_regular() |
|
| 862 | + { |
|
| 863 | + if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
| 864 | + require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
| 865 | + } |
|
| 866 | + } |
|
| 867 | + |
|
| 868 | + |
|
| 869 | + |
|
| 870 | + /** |
|
| 871 | + * register_shortcodes_modules_and_widgets |
|
| 872 | + * generate lists of shortcodes and modules, then verify paths and classes |
|
| 873 | + * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
| 874 | + * which runs during the WP 'plugins_loaded' action at priority 7 |
|
| 875 | + * |
|
| 876 | + * @access public |
|
| 877 | + * @return void |
|
| 878 | + * @throws Exception |
|
| 879 | + */ |
|
| 880 | + public function register_shortcodes_modules_and_widgets() |
|
| 881 | + { |
|
| 882 | + try { |
|
| 883 | + // load, register, and add shortcodes the new way |
|
| 884 | + $this->loader->getShared( |
|
| 885 | + 'EventEspresso\core\services\shortcodes\ShortcodesManager', |
|
| 886 | + array( |
|
| 887 | + // and the old way, but we'll put it under control of the new system |
|
| 888 | + EE_Config::getLegacyShortcodesManager() |
|
| 889 | + ) |
|
| 890 | + ); |
|
| 891 | + } catch (Exception $exception) { |
|
| 892 | + new ExceptionStackTraceDisplay($exception); |
|
| 893 | + } |
|
| 894 | + do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
| 895 | + // check for addons using old hook point |
|
| 896 | + if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
| 897 | + $this->_incompatible_addon_error(); |
|
| 898 | + } |
|
| 899 | + } |
|
| 900 | + |
|
| 901 | + |
|
| 902 | + |
|
| 903 | + /** |
|
| 904 | + * _incompatible_addon_error |
|
| 905 | + * |
|
| 906 | + * @access public |
|
| 907 | + * @return void |
|
| 908 | + */ |
|
| 909 | + private function _incompatible_addon_error() |
|
| 910 | + { |
|
| 911 | + // get array of classes hooking into here |
|
| 912 | + $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook( |
|
| 913 | + 'AHEE__EE_System__register_shortcodes_modules_and_addons' |
|
| 914 | + ); |
|
| 915 | + if (! empty($class_names)) { |
|
| 916 | + $msg = __( |
|
| 917 | + 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
| 918 | + 'event_espresso' |
|
| 919 | + ); |
|
| 920 | + $msg .= '<ul>'; |
|
| 921 | + foreach ($class_names as $class_name) { |
|
| 922 | + $msg .= '<li><b>Event Espresso - ' . str_replace( |
|
| 923 | + array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
| 924 | + $class_name |
|
| 925 | + ) . '</b></li>'; |
|
| 926 | + } |
|
| 927 | + $msg .= '</ul>'; |
|
| 928 | + $msg .= __( |
|
| 929 | + 'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
| 930 | + 'event_espresso' |
|
| 931 | + ); |
|
| 932 | + // save list of incompatible addons to wp-options for later use |
|
| 933 | + add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
| 934 | + if (is_admin()) { |
|
| 935 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 936 | + } |
|
| 937 | + } |
|
| 938 | + } |
|
| 939 | + |
|
| 940 | + |
|
| 941 | + |
|
| 942 | + /** |
|
| 943 | + * brew_espresso |
|
| 944 | + * begins the process of setting hooks for initializing EE in the correct order |
|
| 945 | + * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point |
|
| 946 | + * which runs during the WP 'plugins_loaded' action at priority 9 |
|
| 947 | + * |
|
| 948 | + * @return void |
|
| 949 | + */ |
|
| 950 | + public function brew_espresso() |
|
| 951 | + { |
|
| 952 | + do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
| 953 | + // load some final core systems |
|
| 954 | + add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
| 955 | + add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
| 956 | + add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
| 957 | + add_action('init', array($this, 'load_controllers'), 7); |
|
| 958 | + add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
| 959 | + add_action('init', array($this, 'initialize'), 10); |
|
| 960 | + add_action('init', array($this, 'initialize_last'), 100); |
|
| 961 | + if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
| 962 | + // pew pew pew |
|
| 963 | + $this->loader->getShared('EE_PUE'); |
|
| 964 | + do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
| 965 | + } |
|
| 966 | + do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
| 967 | + } |
|
| 968 | + |
|
| 969 | + |
|
| 970 | + |
|
| 971 | + /** |
|
| 972 | + * set_hooks_for_core |
|
| 973 | + * |
|
| 974 | + * @access public |
|
| 975 | + * @return void |
|
| 976 | + * @throws EE_Error |
|
| 977 | + */ |
|
| 978 | + public function set_hooks_for_core() |
|
| 979 | + { |
|
| 980 | + $this->_deactivate_incompatible_addons(); |
|
| 981 | + do_action('AHEE__EE_System__set_hooks_for_core'); |
|
| 982 | + //caps need to be initialized on every request so that capability maps are set. |
|
| 983 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
| 984 | + $this->registry->CAP->init_caps(); |
|
| 985 | + } |
|
| 986 | + |
|
| 987 | + |
|
| 988 | + |
|
| 989 | + /** |
|
| 990 | + * Using the information gathered in EE_System::_incompatible_addon_error, |
|
| 991 | + * deactivates any addons considered incompatible with the current version of EE |
|
| 992 | + */ |
|
| 993 | + private function _deactivate_incompatible_addons() |
|
| 994 | + { |
|
| 995 | + $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
| 996 | + if (! empty($incompatible_addons)) { |
|
| 997 | + $active_plugins = get_option('active_plugins', array()); |
|
| 998 | + foreach ($active_plugins as $active_plugin) { |
|
| 999 | + foreach ($incompatible_addons as $incompatible_addon) { |
|
| 1000 | + if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
| 1001 | + unset($_GET['activate']); |
|
| 1002 | + espresso_deactivate_plugin($active_plugin); |
|
| 1003 | + } |
|
| 1004 | + } |
|
| 1005 | + } |
|
| 1006 | + } |
|
| 1007 | + } |
|
| 1008 | + |
|
| 1009 | + |
|
| 1010 | + |
|
| 1011 | + /** |
|
| 1012 | + * perform_activations_upgrades_and_migrations |
|
| 1013 | + * |
|
| 1014 | + * @access public |
|
| 1015 | + * @return void |
|
| 1016 | + */ |
|
| 1017 | + public function perform_activations_upgrades_and_migrations() |
|
| 1018 | + { |
|
| 1019 | + //first check if we had previously attempted to setup EE's directories but failed |
|
| 1020 | + if (EEH_Activation::upload_directories_incomplete()) { |
|
| 1021 | + EEH_Activation::create_upload_directories(); |
|
| 1022 | + } |
|
| 1023 | + do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
| 1024 | + } |
|
| 1025 | + |
|
| 1026 | + |
|
| 1027 | + |
|
| 1028 | + /** |
|
| 1029 | + * load_CPTs_and_session |
|
| 1030 | + * |
|
| 1031 | + * @access public |
|
| 1032 | + * @return void |
|
| 1033 | + */ |
|
| 1034 | + public function load_CPTs_and_session() |
|
| 1035 | + { |
|
| 1036 | + do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
| 1037 | + // register Custom Post Types |
|
| 1038 | + $this->loader->getShared('EE_Register_CPTs'); |
|
| 1039 | + do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
| 1040 | + } |
|
| 1041 | + |
|
| 1042 | + |
|
| 1043 | + |
|
| 1044 | + /** |
|
| 1045 | + * load_controllers |
|
| 1046 | + * this is the best place to load any additional controllers that needs access to EE core. |
|
| 1047 | + * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
| 1048 | + * time |
|
| 1049 | + * |
|
| 1050 | + * @access public |
|
| 1051 | + * @return void |
|
| 1052 | + */ |
|
| 1053 | + public function load_controllers() |
|
| 1054 | + { |
|
| 1055 | + do_action('AHEE__EE_System__load_controllers__start'); |
|
| 1056 | + // let's get it started |
|
| 1057 | + if (! is_admin() && ! $this->maintenance_mode->level()) { |
|
| 1058 | + do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
| 1059 | + $this->loader->getShared('EE_Front_Controller'); |
|
| 1060 | + } else if (! EE_FRONT_AJAX) { |
|
| 1061 | + do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
| 1062 | + $this->loader->getShared('EE_Admin'); |
|
| 1063 | + } |
|
| 1064 | + do_action('AHEE__EE_System__load_controllers__complete'); |
|
| 1065 | + } |
|
| 1066 | + |
|
| 1067 | + |
|
| 1068 | + |
|
| 1069 | + /** |
|
| 1070 | + * core_loaded_and_ready |
|
| 1071 | + * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
| 1072 | + * |
|
| 1073 | + * @access public |
|
| 1074 | + * @return void |
|
| 1075 | + */ |
|
| 1076 | + public function core_loaded_and_ready() |
|
| 1077 | + { |
|
| 1078 | + $this->loader->getShared('EE_Session'); |
|
| 1079 | + do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
| 1080 | + // load_espresso_template_tags |
|
| 1081 | + if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
| 1082 | + require_once(EE_PUBLIC . 'template_tags.php'); |
|
| 1083 | + } |
|
| 1084 | + do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
| 1085 | + $this->loader->getShared('EventEspresso\core\services\assets\Registry'); |
|
| 1086 | + } |
|
| 1087 | + |
|
| 1088 | + |
|
| 1089 | + |
|
| 1090 | + /** |
|
| 1091 | + * initialize |
|
| 1092 | + * this is the best place to begin initializing client code |
|
| 1093 | + * |
|
| 1094 | + * @access public |
|
| 1095 | + * @return void |
|
| 1096 | + */ |
|
| 1097 | + public function initialize() |
|
| 1098 | + { |
|
| 1099 | + do_action('AHEE__EE_System__initialize'); |
|
| 1100 | + } |
|
| 1101 | + |
|
| 1102 | + |
|
| 1103 | + |
|
| 1104 | + /** |
|
| 1105 | + * initialize_last |
|
| 1106 | + * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to |
|
| 1107 | + * initialize has done so |
|
| 1108 | + * |
|
| 1109 | + * @access public |
|
| 1110 | + * @return void |
|
| 1111 | + */ |
|
| 1112 | + public function initialize_last() |
|
| 1113 | + { |
|
| 1114 | + do_action('AHEE__EE_System__initialize_last'); |
|
| 1115 | + add_action('admin_bar_init', array($this, 'addEspressoToolbar')); |
|
| 1116 | + } |
|
| 1117 | + |
|
| 1118 | + |
|
| 1119 | + |
|
| 1120 | + /** |
|
| 1121 | + * @return void |
|
| 1122 | + * @throws EE_Error |
|
| 1123 | + */ |
|
| 1124 | + public function addEspressoToolbar() |
|
| 1125 | + { |
|
| 1126 | + $this->loader->getShared( |
|
| 1127 | + 'EventEspresso\core\domain\services\admin\AdminToolBar', |
|
| 1128 | + array($this->registry->CAP) |
|
| 1129 | + ); |
|
| 1130 | + } |
|
| 1131 | + |
|
| 1132 | + |
|
| 1133 | + |
|
| 1134 | + /** |
|
| 1135 | + * do_not_cache |
|
| 1136 | + * sets no cache headers and defines no cache constants for WP plugins |
|
| 1137 | + * |
|
| 1138 | + * @access public |
|
| 1139 | + * @return void |
|
| 1140 | + */ |
|
| 1141 | + public static function do_not_cache() |
|
| 1142 | + { |
|
| 1143 | + // set no cache constants |
|
| 1144 | + if (! defined('DONOTCACHEPAGE')) { |
|
| 1145 | + define('DONOTCACHEPAGE', true); |
|
| 1146 | + } |
|
| 1147 | + if (! defined('DONOTCACHCEOBJECT')) { |
|
| 1148 | + define('DONOTCACHCEOBJECT', true); |
|
| 1149 | + } |
|
| 1150 | + if (! defined('DONOTCACHEDB')) { |
|
| 1151 | + define('DONOTCACHEDB', true); |
|
| 1152 | + } |
|
| 1153 | + // add no cache headers |
|
| 1154 | + add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
| 1155 | + // plus a little extra for nginx and Google Chrome |
|
| 1156 | + add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
| 1157 | + // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
| 1158 | + remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
| 1159 | + } |
|
| 1160 | + |
|
| 1161 | + |
|
| 1162 | + |
|
| 1163 | + /** |
|
| 1164 | + * extra_nocache_headers |
|
| 1165 | + * |
|
| 1166 | + * @access public |
|
| 1167 | + * @param $headers |
|
| 1168 | + * @return array |
|
| 1169 | + */ |
|
| 1170 | + public static function extra_nocache_headers($headers) |
|
| 1171 | + { |
|
| 1172 | + // for NGINX |
|
| 1173 | + $headers['X-Accel-Expires'] = 0; |
|
| 1174 | + // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
| 1175 | + $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
| 1176 | + return $headers; |
|
| 1177 | + } |
|
| 1178 | + |
|
| 1179 | + |
|
| 1180 | + |
|
| 1181 | + /** |
|
| 1182 | + * nocache_headers |
|
| 1183 | + * |
|
| 1184 | + * @access public |
|
| 1185 | + * @return void |
|
| 1186 | + */ |
|
| 1187 | + public static function nocache_headers() |
|
| 1188 | + { |
|
| 1189 | + nocache_headers(); |
|
| 1190 | + } |
|
| 1191 | + |
|
| 1192 | + |
|
| 1193 | + |
|
| 1194 | + |
|
| 1195 | + /** |
|
| 1196 | + * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
| 1197 | + * never returned with the function. |
|
| 1198 | + * |
|
| 1199 | + * @param array $exclude_array any existing pages being excluded are in this array. |
|
| 1200 | + * @return array |
|
| 1201 | + */ |
|
| 1202 | + public function remove_pages_from_wp_list_pages($exclude_array) |
|
| 1203 | + { |
|
| 1204 | + return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
| 1205 | + } |
|
| 1206 | 1206 | |
| 1207 | 1207 | |
| 1208 | 1208 | |
@@ -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.46.rc.043'); |
|
| 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.46.rc.043'); |
|
| 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 |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | use EventEspresso\core\services\loaders\LoaderInterface; |
| 6 | 6 | |
| 7 | 7 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 8 | - exit('No direct script access allowed'); |
|
| 8 | + exit('No direct script access allowed'); |
|
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | |
@@ -22,793 +22,793 @@ discard block |
||
| 22 | 22 | class EE_Dependency_Map |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * This means that the requested class dependency is not present in the dependency map |
|
| 27 | - */ |
|
| 28 | - const not_registered = 0; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
| 32 | - */ |
|
| 33 | - const load_new_object = 1; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
| 37 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
| 38 | - */ |
|
| 39 | - const load_from_cache = 2; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * When registering a dependency, |
|
| 43 | - * this indicates to keep any existing dependencies that already exist, |
|
| 44 | - * and simply discard any new dependencies declared in the incoming data |
|
| 45 | - */ |
|
| 46 | - const KEEP_EXISTING_DEPENDENCIES = 0; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * When registering a dependency, |
|
| 50 | - * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
| 51 | - */ |
|
| 52 | - const OVERWRITE_DEPENDENCIES = 1; |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @type EE_Dependency_Map $_instance |
|
| 58 | - */ |
|
| 59 | - protected static $_instance; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @type EE_Request $request |
|
| 63 | - */ |
|
| 64 | - protected $_request; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @type EE_Response $response |
|
| 68 | - */ |
|
| 69 | - protected $_response; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @type LoaderInterface $loader |
|
| 73 | - */ |
|
| 74 | - protected $loader; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @type array $_dependency_map |
|
| 78 | - */ |
|
| 79 | - protected $_dependency_map = array(); |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @type array $_class_loaders |
|
| 83 | - */ |
|
| 84 | - protected $_class_loaders = array(); |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * @type array $_aliases |
|
| 88 | - */ |
|
| 89 | - protected $_aliases = array(); |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * EE_Dependency_Map constructor. |
|
| 95 | - * |
|
| 96 | - * @param EE_Request $request |
|
| 97 | - * @param EE_Response $response |
|
| 98 | - */ |
|
| 99 | - protected function __construct(EE_Request $request, EE_Response $response) |
|
| 100 | - { |
|
| 101 | - $this->_request = $request; |
|
| 102 | - $this->_response = $response; |
|
| 103 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 104 | - do_action('EE_Dependency_Map____construct'); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @throws InvalidDataTypeException |
|
| 111 | - * @throws InvalidInterfaceException |
|
| 112 | - * @throws InvalidArgumentException |
|
| 113 | - */ |
|
| 114 | - public function initialize() |
|
| 115 | - { |
|
| 116 | - $this->_register_core_dependencies(); |
|
| 117 | - $this->_register_core_class_loaders(); |
|
| 118 | - $this->_register_core_aliases(); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * @singleton method used to instantiate class object |
|
| 125 | - * @access public |
|
| 126 | - * @param EE_Request $request |
|
| 127 | - * @param EE_Response $response |
|
| 128 | - * @return EE_Dependency_Map |
|
| 129 | - */ |
|
| 130 | - public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
| 131 | - { |
|
| 132 | - // check if class object is instantiated, and instantiated properly |
|
| 133 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 134 | - self::$_instance = new EE_Dependency_Map($request, $response); |
|
| 135 | - } |
|
| 136 | - return self::$_instance; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @param LoaderInterface $loader |
|
| 143 | - */ |
|
| 144 | - public function setLoader(LoaderInterface $loader) |
|
| 145 | - { |
|
| 146 | - $this->loader = $loader; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * @param string $class |
|
| 153 | - * @param array $dependencies |
|
| 154 | - * @param int $overwrite |
|
| 155 | - * @return bool |
|
| 156 | - */ |
|
| 157 | - public static function register_dependencies( |
|
| 158 | - $class, |
|
| 159 | - array $dependencies, |
|
| 160 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 161 | - ) { |
|
| 162 | - return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
| 169 | - * to the class specified by the first parameter. |
|
| 170 | - * IMPORTANT !!! |
|
| 171 | - * The order of elements in the incoming $dependencies array MUST match |
|
| 172 | - * the order of the constructor parameters for the class in question. |
|
| 173 | - * This is especially important when overriding any existing dependencies that are registered. |
|
| 174 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
| 175 | - * |
|
| 176 | - * @param string $class |
|
| 177 | - * @param array $dependencies |
|
| 178 | - * @param int $overwrite |
|
| 179 | - * @return bool |
|
| 180 | - */ |
|
| 181 | - public function registerDependencies( |
|
| 182 | - $class, |
|
| 183 | - array $dependencies, |
|
| 184 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 185 | - ) { |
|
| 186 | - $class = trim($class, '\\'); |
|
| 187 | - $registered = false; |
|
| 188 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
| 189 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
| 190 | - } |
|
| 191 | - // we need to make sure that any aliases used when registering a dependency |
|
| 192 | - // get resolved to the correct class name |
|
| 193 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
| 194 | - $alias = self::$_instance->get_alias($dependency); |
|
| 195 | - if ( |
|
| 196 | - $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
| 197 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
| 198 | - ) { |
|
| 199 | - unset($dependencies[$dependency]); |
|
| 200 | - $dependencies[$alias] = $load_source; |
|
| 201 | - $registered = true; |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - // now add our two lists of dependencies together. |
|
| 205 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
| 206 | - // so $dependencies is NOT overwritten because it is listed first |
|
| 207 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
| 208 | - // Union is way faster than array_merge() but should be used with caution... |
|
| 209 | - // especially with numerically indexed arrays |
|
| 210 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
| 211 | - // now we need to ensure that the resulting dependencies |
|
| 212 | - // array only has the entries that are required for the class |
|
| 213 | - // so first count how many dependencies were originally registered for the class |
|
| 214 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
| 215 | - // if that count is non-zero (meaning dependencies were already registered) |
|
| 216 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
| 217 | - // then truncate the final array to match that count |
|
| 218 | - ? array_slice($dependencies, 0, $dependency_count) |
|
| 219 | - // otherwise just take the incoming array because nothing previously existed |
|
| 220 | - : $dependencies; |
|
| 221 | - return $registered; |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * @param string $class_name |
|
| 228 | - * @param string $loader |
|
| 229 | - * @return bool |
|
| 230 | - * @throws DomainException |
|
| 231 | - */ |
|
| 232 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
| 233 | - { |
|
| 234 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
| 235 | - throw new DomainException( |
|
| 236 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
| 237 | - ); |
|
| 238 | - } |
|
| 239 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
| 240 | - if ( |
|
| 241 | - ! is_callable($loader) |
|
| 242 | - && ( |
|
| 243 | - strpos($loader, 'load_') !== 0 |
|
| 244 | - || ! method_exists('EE_Registry', $loader) |
|
| 245 | - ) |
|
| 246 | - ) { |
|
| 247 | - throw new DomainException( |
|
| 248 | - sprintf( |
|
| 249 | - esc_html__( |
|
| 250 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
| 251 | - 'event_espresso' |
|
| 252 | - ), |
|
| 253 | - $loader |
|
| 254 | - ) |
|
| 255 | - ); |
|
| 256 | - } |
|
| 257 | - $class_name = self::$_instance->get_alias($class_name); |
|
| 258 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 259 | - self::$_instance->_class_loaders[$class_name] = $loader; |
|
| 260 | - return true; |
|
| 261 | - } |
|
| 262 | - return false; |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * @return array |
|
| 269 | - */ |
|
| 270 | - public function dependency_map() |
|
| 271 | - { |
|
| 272 | - return $this->_dependency_map; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
| 279 | - * |
|
| 280 | - * @param string $class_name |
|
| 281 | - * @return boolean |
|
| 282 | - */ |
|
| 283 | - public function has($class_name = '') |
|
| 284 | - { |
|
| 285 | - // all legacy models have the same dependencies |
|
| 286 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 287 | - $class_name = 'LEGACY_MODELS'; |
|
| 288 | - } |
|
| 289 | - return isset($this->_dependency_map[$class_name]) ? true : false; |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 296 | - * |
|
| 297 | - * @param string $class_name |
|
| 298 | - * @param string $dependency |
|
| 299 | - * @return bool |
|
| 300 | - */ |
|
| 301 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
| 302 | - { |
|
| 303 | - // all legacy models have the same dependencies |
|
| 304 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 305 | - $class_name = 'LEGACY_MODELS'; |
|
| 306 | - } |
|
| 307 | - $dependency = $this->get_alias($dependency); |
|
| 308 | - return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
| 309 | - ? true |
|
| 310 | - : false; |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 317 | - * |
|
| 318 | - * @param string $class_name |
|
| 319 | - * @param string $dependency |
|
| 320 | - * @return int |
|
| 321 | - */ |
|
| 322 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
| 323 | - { |
|
| 324 | - // all legacy models have the same dependencies |
|
| 325 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 326 | - $class_name = 'LEGACY_MODELS'; |
|
| 327 | - } |
|
| 328 | - $dependency = $this->get_alias($dependency); |
|
| 329 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
| 330 | - ? $this->_dependency_map[$class_name][$dependency] |
|
| 331 | - : EE_Dependency_Map::not_registered; |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * @param string $class_name |
|
| 338 | - * @return string | Closure |
|
| 339 | - */ |
|
| 340 | - public function class_loader($class_name) |
|
| 341 | - { |
|
| 342 | - // all legacy models use load_model() |
|
| 343 | - if(strpos($class_name, 'EEM_') === 0){ |
|
| 344 | - return 'load_model'; |
|
| 345 | - } |
|
| 346 | - $class_name = $this->get_alias($class_name); |
|
| 347 | - return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * @return array |
|
| 354 | - */ |
|
| 355 | - public function class_loaders() |
|
| 356 | - { |
|
| 357 | - return $this->_class_loaders; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * adds an alias for a classname |
|
| 364 | - * |
|
| 365 | - * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
| 366 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 367 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 368 | - */ |
|
| 369 | - public function add_alias($class_name, $alias, $for_class = '') |
|
| 370 | - { |
|
| 371 | - if ($for_class !== '') { |
|
| 372 | - if (! isset($this->_aliases[$for_class])) { |
|
| 373 | - $this->_aliases[$for_class] = array(); |
|
| 374 | - } |
|
| 375 | - $this->_aliases[$for_class][$class_name] = $alias; |
|
| 376 | - } |
|
| 377 | - $this->_aliases[$class_name] = $alias; |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * returns TRUE if the provided class name has an alias |
|
| 384 | - * |
|
| 385 | - * @param string $class_name |
|
| 386 | - * @param string $for_class |
|
| 387 | - * @return bool |
|
| 388 | - */ |
|
| 389 | - public function has_alias($class_name = '', $for_class = '') |
|
| 390 | - { |
|
| 391 | - return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
| 392 | - || ( |
|
| 393 | - isset($this->_aliases[$class_name]) |
|
| 394 | - && ! is_array($this->_aliases[$class_name]) |
|
| 395 | - ); |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - |
|
| 399 | - |
|
| 400 | - /** |
|
| 401 | - * returns alias for class name if one exists, otherwise returns the original classname |
|
| 402 | - * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
| 403 | - * for example: |
|
| 404 | - * if the following two entries were added to the _aliases array: |
|
| 405 | - * array( |
|
| 406 | - * 'interface_alias' => 'some\namespace\interface' |
|
| 407 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 408 | - * ) |
|
| 409 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 410 | - * to load an instance of 'some\namespace\classname' |
|
| 411 | - * |
|
| 412 | - * @param string $class_name |
|
| 413 | - * @param string $for_class |
|
| 414 | - * @return string |
|
| 415 | - */ |
|
| 416 | - public function get_alias($class_name = '', $for_class = '') |
|
| 417 | - { |
|
| 418 | - if (! $this->has_alias($class_name, $for_class)) { |
|
| 419 | - return $class_name; |
|
| 420 | - } |
|
| 421 | - if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
| 422 | - return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
| 423 | - } |
|
| 424 | - return $this->get_alias($this->_aliases[$class_name]); |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - |
|
| 428 | - |
|
| 429 | - /** |
|
| 430 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 431 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 432 | - * This is done by using the following class constants: |
|
| 433 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 434 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 435 | - */ |
|
| 436 | - protected function _register_core_dependencies() |
|
| 437 | - { |
|
| 438 | - $this->_dependency_map = array( |
|
| 439 | - 'EE_Request_Handler' => array( |
|
| 440 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 441 | - ), |
|
| 442 | - 'EE_System' => array( |
|
| 443 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 444 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 445 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 446 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 447 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
| 448 | - ), |
|
| 449 | - 'EE_Session' => array( |
|
| 450 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 451 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
| 452 | - ), |
|
| 453 | - 'EE_Cart' => array( |
|
| 454 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 455 | - ), |
|
| 456 | - 'EE_Front_Controller' => array( |
|
| 457 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 458 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 459 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
| 460 | - ), |
|
| 461 | - 'EE_Messenger_Collection_Loader' => array( |
|
| 462 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 463 | - ), |
|
| 464 | - 'EE_Message_Type_Collection_Loader' => array( |
|
| 465 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 466 | - ), |
|
| 467 | - 'EE_Message_Resource_Manager' => array( |
|
| 468 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 469 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 470 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 471 | - ), |
|
| 472 | - 'EE_Message_Factory' => array( |
|
| 473 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 474 | - ), |
|
| 475 | - 'EE_messages' => array( |
|
| 476 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 477 | - ), |
|
| 478 | - 'EE_Messages_Generator' => array( |
|
| 479 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 480 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 481 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 482 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 483 | - ), |
|
| 484 | - 'EE_Messages_Processor' => array( |
|
| 485 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 486 | - ), |
|
| 487 | - 'EE_Messages_Queue' => array( |
|
| 488 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 489 | - ), |
|
| 490 | - 'EE_Messages_Template_Defaults' => array( |
|
| 491 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 492 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 493 | - ), |
|
| 494 | - 'EE_Message_To_Generate_From_Request' => array( |
|
| 495 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 496 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 497 | - ), |
|
| 498 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
| 499 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 500 | - ), |
|
| 501 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
| 502 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 503 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 504 | - ), |
|
| 505 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
| 506 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 507 | - ), |
|
| 508 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
| 509 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
| 510 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
| 511 | - ), |
|
| 512 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
| 513 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 514 | - ), |
|
| 515 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
| 516 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 517 | - ), |
|
| 518 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
| 519 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 520 | - ), |
|
| 521 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
| 522 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 523 | - ), |
|
| 524 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
| 525 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 526 | - ), |
|
| 527 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
| 528 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 529 | - ), |
|
| 530 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
| 531 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 532 | - ), |
|
| 533 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
| 534 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 535 | - ), |
|
| 536 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
| 537 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 538 | - ), |
|
| 539 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
| 540 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 541 | - ), |
|
| 542 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
| 543 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 544 | - ), |
|
| 545 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
| 546 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 547 | - ), |
|
| 548 | - 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
| 549 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 550 | - ), |
|
| 551 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
| 552 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 553 | - ), |
|
| 554 | - 'EE_Data_Migration_Class_Base' => array( |
|
| 555 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 556 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 557 | - ), |
|
| 558 | - 'EE_DMS_Core_4_1_0' => array( |
|
| 559 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 560 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 561 | - ), |
|
| 562 | - 'EE_DMS_Core_4_2_0' => array( |
|
| 563 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 564 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 565 | - ), |
|
| 566 | - 'EE_DMS_Core_4_3_0' => array( |
|
| 567 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 568 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 569 | - ), |
|
| 570 | - 'EE_DMS_Core_4_4_0' => array( |
|
| 571 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 572 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 573 | - ), |
|
| 574 | - 'EE_DMS_Core_4_5_0' => array( |
|
| 575 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 576 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 577 | - ), |
|
| 578 | - 'EE_DMS_Core_4_6_0' => array( |
|
| 579 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 580 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 581 | - ), |
|
| 582 | - 'EE_DMS_Core_4_7_0' => array( |
|
| 583 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 584 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 585 | - ), |
|
| 586 | - 'EE_DMS_Core_4_8_0' => array( |
|
| 587 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 588 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 589 | - ), |
|
| 590 | - 'EE_DMS_Core_4_9_0' => array( |
|
| 591 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 592 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 593 | - ), |
|
| 594 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
| 595 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
| 596 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
| 597 | - ), |
|
| 598 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
| 599 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 600 | - ), |
|
| 601 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
| 602 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 603 | - ), |
|
| 604 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
| 605 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 606 | - ), |
|
| 607 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
| 608 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 609 | - ), |
|
| 610 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
| 611 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 612 | - ), |
|
| 613 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
| 614 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 615 | - ), |
|
| 616 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
| 617 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 618 | - ), |
|
| 619 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
| 620 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 621 | - ), |
|
| 622 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
| 623 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 624 | - ), |
|
| 625 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
| 626 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 627 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 628 | - ), |
|
| 629 | - 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
| 630 | - null, |
|
| 631 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
| 632 | - ), |
|
| 633 | - 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
| 634 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 635 | - ), |
|
| 636 | - 'LEGACY_MODELS' => array( |
|
| 637 | - null, |
|
| 638 | - 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
| 639 | - ), |
|
| 640 | - 'EE_Module_Request_Router' => array( |
|
| 641 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 642 | - ), |
|
| 643 | - ); |
|
| 644 | - } |
|
| 645 | - |
|
| 646 | - |
|
| 647 | - |
|
| 648 | - /** |
|
| 649 | - * Registers how core classes are loaded. |
|
| 650 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 651 | - * 'EE_Request_Handler' => 'load_core' |
|
| 652 | - * 'EE_Messages_Queue' => 'load_lib' |
|
| 653 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
| 654 | - * or, if greater control is required, by providing a custom closure. For example: |
|
| 655 | - * 'Some_Class' => function () { |
|
| 656 | - * return new Some_Class(); |
|
| 657 | - * }, |
|
| 658 | - * This is required for instantiating dependencies |
|
| 659 | - * where an interface has been type hinted in a class constructor. For example: |
|
| 660 | - * 'Required_Interface' => function () { |
|
| 661 | - * return new A_Class_That_Implements_Required_Interface(); |
|
| 662 | - * }, |
|
| 663 | - * |
|
| 664 | - * @throws InvalidInterfaceException |
|
| 665 | - * @throws InvalidDataTypeException |
|
| 666 | - * @throws InvalidArgumentException |
|
| 667 | - */ |
|
| 668 | - protected function _register_core_class_loaders() |
|
| 669 | - { |
|
| 670 | - //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
| 671 | - //be used in a closure. |
|
| 672 | - $request = &$this->_request; |
|
| 673 | - $response = &$this->_response; |
|
| 674 | - // $loader = &$this->loader; |
|
| 675 | - $this->_class_loaders = array( |
|
| 676 | - //load_core |
|
| 677 | - 'EE_Capabilities' => 'load_core', |
|
| 678 | - 'EE_Encryption' => 'load_core', |
|
| 679 | - 'EE_Front_Controller' => 'load_core', |
|
| 680 | - 'EE_Module_Request_Router' => 'load_core', |
|
| 681 | - 'EE_Registry' => 'load_core', |
|
| 682 | - 'EE_Request' => function () use (&$request) { |
|
| 683 | - return $request; |
|
| 684 | - }, |
|
| 685 | - 'EE_Response' => function () use (&$response) { |
|
| 686 | - return $response; |
|
| 687 | - }, |
|
| 688 | - 'EE_Request_Handler' => 'load_core', |
|
| 689 | - 'EE_Session' => 'load_core', |
|
| 690 | - 'EE_Cron_Tasks' => 'load_core', |
|
| 691 | - 'EE_System' => 'load_core', |
|
| 692 | - 'EE_Maintenance_Mode' => 'load_core', |
|
| 693 | - 'EE_Register_CPTs' => 'load_core', |
|
| 694 | - 'EE_Admin' => 'load_core', |
|
| 695 | - //load_lib |
|
| 696 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 697 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
| 698 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 699 | - 'EE_Messenger_Collection' => 'load_lib', |
|
| 700 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 701 | - 'EE_Messages_Processor' => 'load_lib', |
|
| 702 | - 'EE_Message_Repository' => 'load_lib', |
|
| 703 | - 'EE_Messages_Queue' => 'load_lib', |
|
| 704 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 705 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 706 | - 'EE_Messages_Generator' => function () { |
|
| 707 | - return EE_Registry::instance()->load_lib( |
|
| 708 | - 'Messages_Generator', |
|
| 709 | - array(), |
|
| 710 | - false, |
|
| 711 | - false |
|
| 712 | - ); |
|
| 713 | - }, |
|
| 714 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 715 | - return EE_Registry::instance()->load_lib( |
|
| 716 | - 'Messages_Template_Defaults', |
|
| 717 | - $arguments, |
|
| 718 | - false, |
|
| 719 | - false |
|
| 720 | - ); |
|
| 721 | - }, |
|
| 722 | - //load_model |
|
| 723 | - // 'EEM_Attendee' => 'load_model', |
|
| 724 | - // 'EEM_Message_Template_Group' => 'load_model', |
|
| 725 | - // 'EEM_Message_Template' => 'load_model', |
|
| 726 | - //load_helper |
|
| 727 | - 'EEH_Parse_Shortcodes' => function () { |
|
| 728 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 729 | - return new EEH_Parse_Shortcodes(); |
|
| 730 | - } |
|
| 731 | - return null; |
|
| 732 | - }, |
|
| 733 | - 'EE_Template_Config' => function () { |
|
| 734 | - return EE_Config::instance()->template_settings; |
|
| 735 | - }, |
|
| 736 | - 'EE_Currency_Config' => function () { |
|
| 737 | - return EE_Config::instance()->currency; |
|
| 738 | - }, |
|
| 739 | - 'EE_Registration_Config' => function () { |
|
| 740 | - return EE_Config::instance()->registration; |
|
| 741 | - }, |
|
| 742 | - 'EventEspresso\core\services\loaders\Loader' => function () { |
|
| 743 | - return LoaderFactory::getLoader(); |
|
| 744 | - }, |
|
| 745 | - ); |
|
| 746 | - } |
|
| 747 | - |
|
| 748 | - |
|
| 749 | - |
|
| 750 | - /** |
|
| 751 | - * can be used for supplying alternate names for classes, |
|
| 752 | - * or for connecting interface names to instantiable classes |
|
| 753 | - */ |
|
| 754 | - protected function _register_core_aliases() |
|
| 755 | - { |
|
| 756 | - $this->_aliases = array( |
|
| 757 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 758 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 759 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 760 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 761 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 762 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
| 763 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 764 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
| 765 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 766 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 767 | - 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
| 768 | - 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
| 769 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 770 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 771 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 772 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 773 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 774 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 775 | - 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
| 776 | - 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
| 777 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 778 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 779 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 780 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
| 781 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 782 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
| 783 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
| 784 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
| 785 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
| 786 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
| 787 | - 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
| 788 | - 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
| 789 | - 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
| 790 | - 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
| 791 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
| 792 | - 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
| 793 | - 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
| 794 | - ); |
|
| 795 | - } |
|
| 796 | - |
|
| 797 | - |
|
| 798 | - |
|
| 799 | - /** |
|
| 800 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 801 | - * request Primarily used by unit tests. |
|
| 802 | - * |
|
| 803 | - * @throws InvalidDataTypeException |
|
| 804 | - * @throws InvalidInterfaceException |
|
| 805 | - * @throws InvalidArgumentException |
|
| 806 | - */ |
|
| 807 | - public function reset() |
|
| 808 | - { |
|
| 809 | - $this->_register_core_class_loaders(); |
|
| 810 | - $this->_register_core_dependencies(); |
|
| 811 | - } |
|
| 25 | + /** |
|
| 26 | + * This means that the requested class dependency is not present in the dependency map |
|
| 27 | + */ |
|
| 28 | + const not_registered = 0; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
| 32 | + */ |
|
| 33 | + const load_new_object = 1; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
| 37 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
| 38 | + */ |
|
| 39 | + const load_from_cache = 2; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * When registering a dependency, |
|
| 43 | + * this indicates to keep any existing dependencies that already exist, |
|
| 44 | + * and simply discard any new dependencies declared in the incoming data |
|
| 45 | + */ |
|
| 46 | + const KEEP_EXISTING_DEPENDENCIES = 0; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * When registering a dependency, |
|
| 50 | + * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
| 51 | + */ |
|
| 52 | + const OVERWRITE_DEPENDENCIES = 1; |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @type EE_Dependency_Map $_instance |
|
| 58 | + */ |
|
| 59 | + protected static $_instance; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @type EE_Request $request |
|
| 63 | + */ |
|
| 64 | + protected $_request; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @type EE_Response $response |
|
| 68 | + */ |
|
| 69 | + protected $_response; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @type LoaderInterface $loader |
|
| 73 | + */ |
|
| 74 | + protected $loader; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @type array $_dependency_map |
|
| 78 | + */ |
|
| 79 | + protected $_dependency_map = array(); |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @type array $_class_loaders |
|
| 83 | + */ |
|
| 84 | + protected $_class_loaders = array(); |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @type array $_aliases |
|
| 88 | + */ |
|
| 89 | + protected $_aliases = array(); |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * EE_Dependency_Map constructor. |
|
| 95 | + * |
|
| 96 | + * @param EE_Request $request |
|
| 97 | + * @param EE_Response $response |
|
| 98 | + */ |
|
| 99 | + protected function __construct(EE_Request $request, EE_Response $response) |
|
| 100 | + { |
|
| 101 | + $this->_request = $request; |
|
| 102 | + $this->_response = $response; |
|
| 103 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 104 | + do_action('EE_Dependency_Map____construct'); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @throws InvalidDataTypeException |
|
| 111 | + * @throws InvalidInterfaceException |
|
| 112 | + * @throws InvalidArgumentException |
|
| 113 | + */ |
|
| 114 | + public function initialize() |
|
| 115 | + { |
|
| 116 | + $this->_register_core_dependencies(); |
|
| 117 | + $this->_register_core_class_loaders(); |
|
| 118 | + $this->_register_core_aliases(); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * @singleton method used to instantiate class object |
|
| 125 | + * @access public |
|
| 126 | + * @param EE_Request $request |
|
| 127 | + * @param EE_Response $response |
|
| 128 | + * @return EE_Dependency_Map |
|
| 129 | + */ |
|
| 130 | + public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
| 131 | + { |
|
| 132 | + // check if class object is instantiated, and instantiated properly |
|
| 133 | + if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 134 | + self::$_instance = new EE_Dependency_Map($request, $response); |
|
| 135 | + } |
|
| 136 | + return self::$_instance; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * @param LoaderInterface $loader |
|
| 143 | + */ |
|
| 144 | + public function setLoader(LoaderInterface $loader) |
|
| 145 | + { |
|
| 146 | + $this->loader = $loader; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * @param string $class |
|
| 153 | + * @param array $dependencies |
|
| 154 | + * @param int $overwrite |
|
| 155 | + * @return bool |
|
| 156 | + */ |
|
| 157 | + public static function register_dependencies( |
|
| 158 | + $class, |
|
| 159 | + array $dependencies, |
|
| 160 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 161 | + ) { |
|
| 162 | + return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
| 169 | + * to the class specified by the first parameter. |
|
| 170 | + * IMPORTANT !!! |
|
| 171 | + * The order of elements in the incoming $dependencies array MUST match |
|
| 172 | + * the order of the constructor parameters for the class in question. |
|
| 173 | + * This is especially important when overriding any existing dependencies that are registered. |
|
| 174 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
| 175 | + * |
|
| 176 | + * @param string $class |
|
| 177 | + * @param array $dependencies |
|
| 178 | + * @param int $overwrite |
|
| 179 | + * @return bool |
|
| 180 | + */ |
|
| 181 | + public function registerDependencies( |
|
| 182 | + $class, |
|
| 183 | + array $dependencies, |
|
| 184 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 185 | + ) { |
|
| 186 | + $class = trim($class, '\\'); |
|
| 187 | + $registered = false; |
|
| 188 | + if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
| 189 | + self::$_instance->_dependency_map[ $class ] = array(); |
|
| 190 | + } |
|
| 191 | + // we need to make sure that any aliases used when registering a dependency |
|
| 192 | + // get resolved to the correct class name |
|
| 193 | + foreach ((array)$dependencies as $dependency => $load_source) { |
|
| 194 | + $alias = self::$_instance->get_alias($dependency); |
|
| 195 | + if ( |
|
| 196 | + $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
| 197 | + || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
| 198 | + ) { |
|
| 199 | + unset($dependencies[$dependency]); |
|
| 200 | + $dependencies[$alias] = $load_source; |
|
| 201 | + $registered = true; |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + // now add our two lists of dependencies together. |
|
| 205 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
| 206 | + // so $dependencies is NOT overwritten because it is listed first |
|
| 207 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
| 208 | + // Union is way faster than array_merge() but should be used with caution... |
|
| 209 | + // especially with numerically indexed arrays |
|
| 210 | + $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
| 211 | + // now we need to ensure that the resulting dependencies |
|
| 212 | + // array only has the entries that are required for the class |
|
| 213 | + // so first count how many dependencies were originally registered for the class |
|
| 214 | + $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
| 215 | + // if that count is non-zero (meaning dependencies were already registered) |
|
| 216 | + self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
| 217 | + // then truncate the final array to match that count |
|
| 218 | + ? array_slice($dependencies, 0, $dependency_count) |
|
| 219 | + // otherwise just take the incoming array because nothing previously existed |
|
| 220 | + : $dependencies; |
|
| 221 | + return $registered; |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * @param string $class_name |
|
| 228 | + * @param string $loader |
|
| 229 | + * @return bool |
|
| 230 | + * @throws DomainException |
|
| 231 | + */ |
|
| 232 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
| 233 | + { |
|
| 234 | + if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
| 235 | + throw new DomainException( |
|
| 236 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
| 237 | + ); |
|
| 238 | + } |
|
| 239 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
| 240 | + if ( |
|
| 241 | + ! is_callable($loader) |
|
| 242 | + && ( |
|
| 243 | + strpos($loader, 'load_') !== 0 |
|
| 244 | + || ! method_exists('EE_Registry', $loader) |
|
| 245 | + ) |
|
| 246 | + ) { |
|
| 247 | + throw new DomainException( |
|
| 248 | + sprintf( |
|
| 249 | + esc_html__( |
|
| 250 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
| 251 | + 'event_espresso' |
|
| 252 | + ), |
|
| 253 | + $loader |
|
| 254 | + ) |
|
| 255 | + ); |
|
| 256 | + } |
|
| 257 | + $class_name = self::$_instance->get_alias($class_name); |
|
| 258 | + if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 259 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
| 260 | + return true; |
|
| 261 | + } |
|
| 262 | + return false; |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * @return array |
|
| 269 | + */ |
|
| 270 | + public function dependency_map() |
|
| 271 | + { |
|
| 272 | + return $this->_dependency_map; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
| 279 | + * |
|
| 280 | + * @param string $class_name |
|
| 281 | + * @return boolean |
|
| 282 | + */ |
|
| 283 | + public function has($class_name = '') |
|
| 284 | + { |
|
| 285 | + // all legacy models have the same dependencies |
|
| 286 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 287 | + $class_name = 'LEGACY_MODELS'; |
|
| 288 | + } |
|
| 289 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 296 | + * |
|
| 297 | + * @param string $class_name |
|
| 298 | + * @param string $dependency |
|
| 299 | + * @return bool |
|
| 300 | + */ |
|
| 301 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
| 302 | + { |
|
| 303 | + // all legacy models have the same dependencies |
|
| 304 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 305 | + $class_name = 'LEGACY_MODELS'; |
|
| 306 | + } |
|
| 307 | + $dependency = $this->get_alias($dependency); |
|
| 308 | + return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
| 309 | + ? true |
|
| 310 | + : false; |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 317 | + * |
|
| 318 | + * @param string $class_name |
|
| 319 | + * @param string $dependency |
|
| 320 | + * @return int |
|
| 321 | + */ |
|
| 322 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
| 323 | + { |
|
| 324 | + // all legacy models have the same dependencies |
|
| 325 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 326 | + $class_name = 'LEGACY_MODELS'; |
|
| 327 | + } |
|
| 328 | + $dependency = $this->get_alias($dependency); |
|
| 329 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
| 330 | + ? $this->_dependency_map[$class_name][$dependency] |
|
| 331 | + : EE_Dependency_Map::not_registered; |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * @param string $class_name |
|
| 338 | + * @return string | Closure |
|
| 339 | + */ |
|
| 340 | + public function class_loader($class_name) |
|
| 341 | + { |
|
| 342 | + // all legacy models use load_model() |
|
| 343 | + if(strpos($class_name, 'EEM_') === 0){ |
|
| 344 | + return 'load_model'; |
|
| 345 | + } |
|
| 346 | + $class_name = $this->get_alias($class_name); |
|
| 347 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * @return array |
|
| 354 | + */ |
|
| 355 | + public function class_loaders() |
|
| 356 | + { |
|
| 357 | + return $this->_class_loaders; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * adds an alias for a classname |
|
| 364 | + * |
|
| 365 | + * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
| 366 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 367 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 368 | + */ |
|
| 369 | + public function add_alias($class_name, $alias, $for_class = '') |
|
| 370 | + { |
|
| 371 | + if ($for_class !== '') { |
|
| 372 | + if (! isset($this->_aliases[$for_class])) { |
|
| 373 | + $this->_aliases[$for_class] = array(); |
|
| 374 | + } |
|
| 375 | + $this->_aliases[$for_class][$class_name] = $alias; |
|
| 376 | + } |
|
| 377 | + $this->_aliases[$class_name] = $alias; |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * returns TRUE if the provided class name has an alias |
|
| 384 | + * |
|
| 385 | + * @param string $class_name |
|
| 386 | + * @param string $for_class |
|
| 387 | + * @return bool |
|
| 388 | + */ |
|
| 389 | + public function has_alias($class_name = '', $for_class = '') |
|
| 390 | + { |
|
| 391 | + return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
| 392 | + || ( |
|
| 393 | + isset($this->_aliases[$class_name]) |
|
| 394 | + && ! is_array($this->_aliases[$class_name]) |
|
| 395 | + ); |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * returns alias for class name if one exists, otherwise returns the original classname |
|
| 402 | + * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
| 403 | + * for example: |
|
| 404 | + * if the following two entries were added to the _aliases array: |
|
| 405 | + * array( |
|
| 406 | + * 'interface_alias' => 'some\namespace\interface' |
|
| 407 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 408 | + * ) |
|
| 409 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 410 | + * to load an instance of 'some\namespace\classname' |
|
| 411 | + * |
|
| 412 | + * @param string $class_name |
|
| 413 | + * @param string $for_class |
|
| 414 | + * @return string |
|
| 415 | + */ |
|
| 416 | + public function get_alias($class_name = '', $for_class = '') |
|
| 417 | + { |
|
| 418 | + if (! $this->has_alias($class_name, $for_class)) { |
|
| 419 | + return $class_name; |
|
| 420 | + } |
|
| 421 | + if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
| 422 | + return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
| 423 | + } |
|
| 424 | + return $this->get_alias($this->_aliases[$class_name]); |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + |
|
| 428 | + |
|
| 429 | + /** |
|
| 430 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 431 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 432 | + * This is done by using the following class constants: |
|
| 433 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 434 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 435 | + */ |
|
| 436 | + protected function _register_core_dependencies() |
|
| 437 | + { |
|
| 438 | + $this->_dependency_map = array( |
|
| 439 | + 'EE_Request_Handler' => array( |
|
| 440 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 441 | + ), |
|
| 442 | + 'EE_System' => array( |
|
| 443 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 444 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 445 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 446 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 447 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
| 448 | + ), |
|
| 449 | + 'EE_Session' => array( |
|
| 450 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 451 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
| 452 | + ), |
|
| 453 | + 'EE_Cart' => array( |
|
| 454 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 455 | + ), |
|
| 456 | + 'EE_Front_Controller' => array( |
|
| 457 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 458 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 459 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
| 460 | + ), |
|
| 461 | + 'EE_Messenger_Collection_Loader' => array( |
|
| 462 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 463 | + ), |
|
| 464 | + 'EE_Message_Type_Collection_Loader' => array( |
|
| 465 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 466 | + ), |
|
| 467 | + 'EE_Message_Resource_Manager' => array( |
|
| 468 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 469 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 470 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 471 | + ), |
|
| 472 | + 'EE_Message_Factory' => array( |
|
| 473 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 474 | + ), |
|
| 475 | + 'EE_messages' => array( |
|
| 476 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 477 | + ), |
|
| 478 | + 'EE_Messages_Generator' => array( |
|
| 479 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 480 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 481 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 482 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 483 | + ), |
|
| 484 | + 'EE_Messages_Processor' => array( |
|
| 485 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 486 | + ), |
|
| 487 | + 'EE_Messages_Queue' => array( |
|
| 488 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 489 | + ), |
|
| 490 | + 'EE_Messages_Template_Defaults' => array( |
|
| 491 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 492 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 493 | + ), |
|
| 494 | + 'EE_Message_To_Generate_From_Request' => array( |
|
| 495 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 496 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 497 | + ), |
|
| 498 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
| 499 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 500 | + ), |
|
| 501 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
| 502 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 503 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 504 | + ), |
|
| 505 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
| 506 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 507 | + ), |
|
| 508 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
| 509 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
| 510 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
| 511 | + ), |
|
| 512 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
| 513 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 514 | + ), |
|
| 515 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
| 516 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 517 | + ), |
|
| 518 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
| 519 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 520 | + ), |
|
| 521 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
| 522 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 523 | + ), |
|
| 524 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
| 525 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 526 | + ), |
|
| 527 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
| 528 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 529 | + ), |
|
| 530 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
| 531 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 532 | + ), |
|
| 533 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
| 534 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 535 | + ), |
|
| 536 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
| 537 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 538 | + ), |
|
| 539 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
| 540 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 541 | + ), |
|
| 542 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
| 543 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 544 | + ), |
|
| 545 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
| 546 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 547 | + ), |
|
| 548 | + 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
| 549 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 550 | + ), |
|
| 551 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
| 552 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 553 | + ), |
|
| 554 | + 'EE_Data_Migration_Class_Base' => array( |
|
| 555 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 556 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 557 | + ), |
|
| 558 | + 'EE_DMS_Core_4_1_0' => array( |
|
| 559 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 560 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 561 | + ), |
|
| 562 | + 'EE_DMS_Core_4_2_0' => array( |
|
| 563 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 564 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 565 | + ), |
|
| 566 | + 'EE_DMS_Core_4_3_0' => array( |
|
| 567 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 568 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 569 | + ), |
|
| 570 | + 'EE_DMS_Core_4_4_0' => array( |
|
| 571 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 572 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 573 | + ), |
|
| 574 | + 'EE_DMS_Core_4_5_0' => array( |
|
| 575 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 576 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 577 | + ), |
|
| 578 | + 'EE_DMS_Core_4_6_0' => array( |
|
| 579 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 580 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 581 | + ), |
|
| 582 | + 'EE_DMS_Core_4_7_0' => array( |
|
| 583 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 584 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 585 | + ), |
|
| 586 | + 'EE_DMS_Core_4_8_0' => array( |
|
| 587 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 588 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 589 | + ), |
|
| 590 | + 'EE_DMS_Core_4_9_0' => array( |
|
| 591 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 592 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 593 | + ), |
|
| 594 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
| 595 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
| 596 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
| 597 | + ), |
|
| 598 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
| 599 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 600 | + ), |
|
| 601 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
| 602 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 603 | + ), |
|
| 604 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
| 605 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 606 | + ), |
|
| 607 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
| 608 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 609 | + ), |
|
| 610 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
| 611 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 612 | + ), |
|
| 613 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
| 614 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 615 | + ), |
|
| 616 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
| 617 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 618 | + ), |
|
| 619 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
| 620 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 621 | + ), |
|
| 622 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
| 623 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 624 | + ), |
|
| 625 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
| 626 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 627 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 628 | + ), |
|
| 629 | + 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
| 630 | + null, |
|
| 631 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
| 632 | + ), |
|
| 633 | + 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
| 634 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 635 | + ), |
|
| 636 | + 'LEGACY_MODELS' => array( |
|
| 637 | + null, |
|
| 638 | + 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
| 639 | + ), |
|
| 640 | + 'EE_Module_Request_Router' => array( |
|
| 641 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 642 | + ), |
|
| 643 | + ); |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + |
|
| 647 | + |
|
| 648 | + /** |
|
| 649 | + * Registers how core classes are loaded. |
|
| 650 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 651 | + * 'EE_Request_Handler' => 'load_core' |
|
| 652 | + * 'EE_Messages_Queue' => 'load_lib' |
|
| 653 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
| 654 | + * or, if greater control is required, by providing a custom closure. For example: |
|
| 655 | + * 'Some_Class' => function () { |
|
| 656 | + * return new Some_Class(); |
|
| 657 | + * }, |
|
| 658 | + * This is required for instantiating dependencies |
|
| 659 | + * where an interface has been type hinted in a class constructor. For example: |
|
| 660 | + * 'Required_Interface' => function () { |
|
| 661 | + * return new A_Class_That_Implements_Required_Interface(); |
|
| 662 | + * }, |
|
| 663 | + * |
|
| 664 | + * @throws InvalidInterfaceException |
|
| 665 | + * @throws InvalidDataTypeException |
|
| 666 | + * @throws InvalidArgumentException |
|
| 667 | + */ |
|
| 668 | + protected function _register_core_class_loaders() |
|
| 669 | + { |
|
| 670 | + //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
| 671 | + //be used in a closure. |
|
| 672 | + $request = &$this->_request; |
|
| 673 | + $response = &$this->_response; |
|
| 674 | + // $loader = &$this->loader; |
|
| 675 | + $this->_class_loaders = array( |
|
| 676 | + //load_core |
|
| 677 | + 'EE_Capabilities' => 'load_core', |
|
| 678 | + 'EE_Encryption' => 'load_core', |
|
| 679 | + 'EE_Front_Controller' => 'load_core', |
|
| 680 | + 'EE_Module_Request_Router' => 'load_core', |
|
| 681 | + 'EE_Registry' => 'load_core', |
|
| 682 | + 'EE_Request' => function () use (&$request) { |
|
| 683 | + return $request; |
|
| 684 | + }, |
|
| 685 | + 'EE_Response' => function () use (&$response) { |
|
| 686 | + return $response; |
|
| 687 | + }, |
|
| 688 | + 'EE_Request_Handler' => 'load_core', |
|
| 689 | + 'EE_Session' => 'load_core', |
|
| 690 | + 'EE_Cron_Tasks' => 'load_core', |
|
| 691 | + 'EE_System' => 'load_core', |
|
| 692 | + 'EE_Maintenance_Mode' => 'load_core', |
|
| 693 | + 'EE_Register_CPTs' => 'load_core', |
|
| 694 | + 'EE_Admin' => 'load_core', |
|
| 695 | + //load_lib |
|
| 696 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 697 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
| 698 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 699 | + 'EE_Messenger_Collection' => 'load_lib', |
|
| 700 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 701 | + 'EE_Messages_Processor' => 'load_lib', |
|
| 702 | + 'EE_Message_Repository' => 'load_lib', |
|
| 703 | + 'EE_Messages_Queue' => 'load_lib', |
|
| 704 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 705 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 706 | + 'EE_Messages_Generator' => function () { |
|
| 707 | + return EE_Registry::instance()->load_lib( |
|
| 708 | + 'Messages_Generator', |
|
| 709 | + array(), |
|
| 710 | + false, |
|
| 711 | + false |
|
| 712 | + ); |
|
| 713 | + }, |
|
| 714 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 715 | + return EE_Registry::instance()->load_lib( |
|
| 716 | + 'Messages_Template_Defaults', |
|
| 717 | + $arguments, |
|
| 718 | + false, |
|
| 719 | + false |
|
| 720 | + ); |
|
| 721 | + }, |
|
| 722 | + //load_model |
|
| 723 | + // 'EEM_Attendee' => 'load_model', |
|
| 724 | + // 'EEM_Message_Template_Group' => 'load_model', |
|
| 725 | + // 'EEM_Message_Template' => 'load_model', |
|
| 726 | + //load_helper |
|
| 727 | + 'EEH_Parse_Shortcodes' => function () { |
|
| 728 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 729 | + return new EEH_Parse_Shortcodes(); |
|
| 730 | + } |
|
| 731 | + return null; |
|
| 732 | + }, |
|
| 733 | + 'EE_Template_Config' => function () { |
|
| 734 | + return EE_Config::instance()->template_settings; |
|
| 735 | + }, |
|
| 736 | + 'EE_Currency_Config' => function () { |
|
| 737 | + return EE_Config::instance()->currency; |
|
| 738 | + }, |
|
| 739 | + 'EE_Registration_Config' => function () { |
|
| 740 | + return EE_Config::instance()->registration; |
|
| 741 | + }, |
|
| 742 | + 'EventEspresso\core\services\loaders\Loader' => function () { |
|
| 743 | + return LoaderFactory::getLoader(); |
|
| 744 | + }, |
|
| 745 | + ); |
|
| 746 | + } |
|
| 747 | + |
|
| 748 | + |
|
| 749 | + |
|
| 750 | + /** |
|
| 751 | + * can be used for supplying alternate names for classes, |
|
| 752 | + * or for connecting interface names to instantiable classes |
|
| 753 | + */ |
|
| 754 | + protected function _register_core_aliases() |
|
| 755 | + { |
|
| 756 | + $this->_aliases = array( |
|
| 757 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 758 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 759 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 760 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 761 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 762 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
| 763 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 764 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
| 765 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 766 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 767 | + 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
| 768 | + 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
| 769 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 770 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 771 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 772 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 773 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 774 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 775 | + 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
| 776 | + 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
| 777 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 778 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 779 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 780 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
| 781 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 782 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
| 783 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
| 784 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
| 785 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
| 786 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
| 787 | + 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
| 788 | + 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
| 789 | + 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
| 790 | + 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
| 791 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
| 792 | + 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
| 793 | + 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
| 794 | + ); |
|
| 795 | + } |
|
| 796 | + |
|
| 797 | + |
|
| 798 | + |
|
| 799 | + /** |
|
| 800 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 801 | + * request Primarily used by unit tests. |
|
| 802 | + * |
|
| 803 | + * @throws InvalidDataTypeException |
|
| 804 | + * @throws InvalidInterfaceException |
|
| 805 | + * @throws InvalidArgumentException |
|
| 806 | + */ |
|
| 807 | + public function reset() |
|
| 808 | + { |
|
| 809 | + $this->_register_core_class_loaders(); |
|
| 810 | + $this->_register_core_dependencies(); |
|
| 811 | + } |
|
| 812 | 812 | |
| 813 | 813 | |
| 814 | 814 | } |
@@ -22,1519 +22,1519 @@ |
||
| 22 | 22 | class EE_Registry implements ResettableInterface |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var EE_Registry $_instance |
|
| 27 | - */ |
|
| 28 | - private static $_instance; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var EE_Dependency_Map $_dependency_map |
|
| 32 | - */ |
|
| 33 | - protected $_dependency_map; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var array $_class_abbreviations |
|
| 37 | - */ |
|
| 38 | - protected $_class_abbreviations = array(); |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var CommandBusInterface $BUS |
|
| 42 | - */ |
|
| 43 | - public $BUS; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var EE_Cart $CART |
|
| 47 | - */ |
|
| 48 | - public $CART; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var EE_Config $CFG |
|
| 52 | - */ |
|
| 53 | - public $CFG; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @var EE_Network_Config $NET_CFG |
|
| 57 | - */ |
|
| 58 | - public $NET_CFG; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * StdClass object for storing library classes in |
|
| 62 | - * |
|
| 63 | - * @var StdClass $LIB |
|
| 64 | - */ |
|
| 65 | - public $LIB; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @var EE_Request_Handler $REQ |
|
| 69 | - */ |
|
| 70 | - public $REQ; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @var EE_Session $SSN |
|
| 74 | - */ |
|
| 75 | - public $SSN; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @since 4.5.0 |
|
| 79 | - * @var EE_Capabilities $CAP |
|
| 80 | - */ |
|
| 81 | - public $CAP; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @since 4.9.0 |
|
| 85 | - * @var EE_Message_Resource_Manager $MRM |
|
| 86 | - */ |
|
| 87 | - public $MRM; |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @var Registry $AssetsRegistry |
|
| 92 | - */ |
|
| 93 | - public $AssetsRegistry; |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * StdClass object for holding addons which have registered themselves to work with EE core |
|
| 97 | - * |
|
| 98 | - * @var EE_Addon[] $addons |
|
| 99 | - */ |
|
| 100 | - public $addons; |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
| 104 | - * |
|
| 105 | - * @var EEM_Base[] $models |
|
| 106 | - */ |
|
| 107 | - public $models = array(); |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @var EED_Module[] $modules |
|
| 111 | - */ |
|
| 112 | - public $modules; |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * @var EES_Shortcode[] $shortcodes |
|
| 116 | - */ |
|
| 117 | - public $shortcodes; |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * @var WP_Widget[] $widgets |
|
| 121 | - */ |
|
| 122 | - public $widgets; |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
| 126 | - * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
| 127 | - * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
| 128 | - * classnames (eg "EEM_Event") |
|
| 129 | - * |
|
| 130 | - * @var array $non_abstract_db_models |
|
| 131 | - */ |
|
| 132 | - public $non_abstract_db_models = array(); |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * internationalization for JS strings |
|
| 137 | - * usage: EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' ); |
|
| 138 | - * in js file: var translatedString = eei18n.string_key; |
|
| 139 | - * |
|
| 140 | - * @var array $i18n_js_strings |
|
| 141 | - */ |
|
| 142 | - public static $i18n_js_strings = array(); |
|
| 143 | - |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * $main_file - path to espresso.php |
|
| 147 | - * |
|
| 148 | - * @var array $main_file |
|
| 149 | - */ |
|
| 150 | - public $main_file; |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * array of ReflectionClass objects where the key is the class name |
|
| 154 | - * |
|
| 155 | - * @var ReflectionClass[] $_reflectors |
|
| 156 | - */ |
|
| 157 | - public $_reflectors; |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
| 161 | - * |
|
| 162 | - * @var boolean $_cache_on |
|
| 163 | - */ |
|
| 164 | - protected $_cache_on = true; |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * @singleton method used to instantiate class object |
|
| 170 | - * @param EE_Dependency_Map $dependency_map |
|
| 171 | - * @return EE_Registry instance |
|
| 172 | - * @throws InvalidArgumentException |
|
| 173 | - * @throws InvalidInterfaceException |
|
| 174 | - * @throws InvalidDataTypeException |
|
| 175 | - */ |
|
| 176 | - public static function instance(EE_Dependency_Map $dependency_map = null) |
|
| 177 | - { |
|
| 178 | - // check if class object is instantiated |
|
| 179 | - if (! self::$_instance instanceof EE_Registry) { |
|
| 180 | - self::$_instance = new self($dependency_map); |
|
| 181 | - } |
|
| 182 | - return self::$_instance; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * protected constructor to prevent direct creation |
|
| 189 | - * |
|
| 190 | - * @Constructor |
|
| 191 | - * @param EE_Dependency_Map $dependency_map |
|
| 192 | - * @throws InvalidDataTypeException |
|
| 193 | - * @throws InvalidInterfaceException |
|
| 194 | - * @throws InvalidArgumentException |
|
| 195 | - */ |
|
| 196 | - protected function __construct(EE_Dependency_Map $dependency_map) |
|
| 197 | - { |
|
| 198 | - $this->_dependency_map = $dependency_map; |
|
| 199 | - $this->LIB = new stdClass(); |
|
| 200 | - $this->addons = new stdClass(); |
|
| 201 | - $this->modules = new stdClass(); |
|
| 202 | - $this->shortcodes = new stdClass(); |
|
| 203 | - $this->widgets = new stdClass(); |
|
| 204 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * initialize |
|
| 211 | - * |
|
| 212 | - * @throws EE_Error |
|
| 213 | - * @throws ReflectionException |
|
| 214 | - */ |
|
| 215 | - public function initialize() |
|
| 216 | - { |
|
| 217 | - $this->_class_abbreviations = apply_filters( |
|
| 218 | - 'FHEE__EE_Registry____construct___class_abbreviations', |
|
| 219 | - array( |
|
| 220 | - 'EE_Config' => 'CFG', |
|
| 221 | - 'EE_Session' => 'SSN', |
|
| 222 | - 'EE_Capabilities' => 'CAP', |
|
| 223 | - 'EE_Cart' => 'CART', |
|
| 224 | - 'EE_Network_Config' => 'NET_CFG', |
|
| 225 | - 'EE_Request_Handler' => 'REQ', |
|
| 226 | - 'EE_Message_Resource_Manager' => 'MRM', |
|
| 227 | - 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
| 228 | - 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
|
| 229 | - ) |
|
| 230 | - ); |
|
| 231 | - $this->load_core('Base', array(), true); |
|
| 232 | - // add our request and response objects to the cache |
|
| 233 | - $request_loader = $this->_dependency_map->class_loader('EE_Request'); |
|
| 234 | - $this->_set_cached_class( |
|
| 235 | - $request_loader(), |
|
| 236 | - 'EE_Request' |
|
| 237 | - ); |
|
| 238 | - $response_loader = $this->_dependency_map->class_loader('EE_Response'); |
|
| 239 | - $this->_set_cached_class( |
|
| 240 | - $response_loader(), |
|
| 241 | - 'EE_Response' |
|
| 242 | - ); |
|
| 243 | - add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * @return void |
|
| 250 | - */ |
|
| 251 | - public function init() |
|
| 252 | - { |
|
| 253 | - // Get current page protocol |
|
| 254 | - $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
| 255 | - // Output admin-ajax.php URL with same protocol as current page |
|
| 256 | - self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
| 257 | - self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * localize_i18n_js_strings |
|
| 264 | - * |
|
| 265 | - * @return string |
|
| 266 | - */ |
|
| 267 | - public static function localize_i18n_js_strings() |
|
| 268 | - { |
|
| 269 | - $i18n_js_strings = (array)self::$i18n_js_strings; |
|
| 270 | - foreach ($i18n_js_strings as $key => $value) { |
|
| 271 | - if (is_scalar($value)) { |
|
| 272 | - $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 273 | - } |
|
| 274 | - } |
|
| 275 | - return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * @param mixed string | EED_Module $module |
|
| 282 | - * @throws EE_Error |
|
| 283 | - * @throws ReflectionException |
|
| 284 | - */ |
|
| 285 | - public function add_module($module) |
|
| 286 | - { |
|
| 287 | - if ($module instanceof EED_Module) { |
|
| 288 | - $module_class = get_class($module); |
|
| 289 | - $this->modules->{$module_class} = $module; |
|
| 290 | - } else { |
|
| 291 | - if (! class_exists('EE_Module_Request_Router')) { |
|
| 292 | - $this->load_core('Module_Request_Router'); |
|
| 293 | - } |
|
| 294 | - EE_Module_Request_Router::module_factory($module); |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * @param string $module_name |
|
| 302 | - * @return mixed EED_Module | NULL |
|
| 303 | - */ |
|
| 304 | - public function get_module($module_name = '') |
|
| 305 | - { |
|
| 306 | - return isset($this->modules->{$module_name}) |
|
| 307 | - ? $this->modules->{$module_name} |
|
| 308 | - : null; |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * loads core classes - must be singletons |
|
| 315 | - * |
|
| 316 | - * @param string $class_name - simple class name ie: session |
|
| 317 | - * @param mixed $arguments |
|
| 318 | - * @param bool $load_only |
|
| 319 | - * @return mixed |
|
| 320 | - * @throws EE_Error |
|
| 321 | - * @throws ReflectionException |
|
| 322 | - */ |
|
| 323 | - public function load_core($class_name, $arguments = array(), $load_only = false) |
|
| 324 | - { |
|
| 325 | - $core_paths = apply_filters( |
|
| 326 | - 'FHEE__EE_Registry__load_core__core_paths', |
|
| 327 | - array( |
|
| 328 | - EE_CORE, |
|
| 329 | - EE_ADMIN, |
|
| 330 | - EE_CPTS, |
|
| 331 | - EE_CORE . 'data_migration_scripts' . DS, |
|
| 332 | - EE_CORE . 'capabilities' . DS, |
|
| 333 | - EE_CORE . 'request_stack' . DS, |
|
| 334 | - EE_CORE . 'middleware' . DS, |
|
| 335 | - ) |
|
| 336 | - ); |
|
| 337 | - // retrieve instantiated class |
|
| 338 | - return $this->_load( |
|
| 339 | - $core_paths, |
|
| 340 | - 'EE_', |
|
| 341 | - $class_name, |
|
| 342 | - 'core', |
|
| 343 | - $arguments, |
|
| 344 | - false, |
|
| 345 | - true, |
|
| 346 | - $load_only |
|
| 347 | - ); |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * loads service classes |
|
| 354 | - * |
|
| 355 | - * @param string $class_name - simple class name ie: session |
|
| 356 | - * @param mixed $arguments |
|
| 357 | - * @param bool $load_only |
|
| 358 | - * @return mixed |
|
| 359 | - * @throws EE_Error |
|
| 360 | - * @throws ReflectionException |
|
| 361 | - */ |
|
| 362 | - public function load_service($class_name, $arguments = array(), $load_only = false) |
|
| 363 | - { |
|
| 364 | - $service_paths = apply_filters( |
|
| 365 | - 'FHEE__EE_Registry__load_service__service_paths', |
|
| 366 | - array( |
|
| 367 | - EE_CORE . 'services' . DS, |
|
| 368 | - ) |
|
| 369 | - ); |
|
| 370 | - // retrieve instantiated class |
|
| 371 | - return $this->_load( |
|
| 372 | - $service_paths, |
|
| 373 | - 'EE_', |
|
| 374 | - $class_name, |
|
| 375 | - 'class', |
|
| 376 | - $arguments, |
|
| 377 | - false, |
|
| 378 | - true, |
|
| 379 | - $load_only |
|
| 380 | - ); |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * loads data_migration_scripts |
|
| 387 | - * |
|
| 388 | - * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
| 389 | - * @param mixed $arguments |
|
| 390 | - * @return EE_Data_Migration_Script_Base|mixed |
|
| 391 | - * @throws EE_Error |
|
| 392 | - * @throws ReflectionException |
|
| 393 | - */ |
|
| 394 | - public function load_dms($class_name, $arguments = array()) |
|
| 395 | - { |
|
| 396 | - // retrieve instantiated class |
|
| 397 | - return $this->_load( |
|
| 398 | - EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), |
|
| 399 | - 'EE_DMS_', |
|
| 400 | - $class_name, |
|
| 401 | - 'dms', |
|
| 402 | - $arguments, |
|
| 403 | - false, |
|
| 404 | - false |
|
| 405 | - ); |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * loads object creating classes - must be singletons |
|
| 412 | - * |
|
| 413 | - * @param string $class_name - simple class name ie: attendee |
|
| 414 | - * @param mixed $arguments - an array of arguments to pass to the class |
|
| 415 | - * @param bool $from_db - some classes are instantiated from the db and thus call a different method to |
|
| 416 | - * instantiate |
|
| 417 | - * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then |
|
| 418 | - * set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
| 419 | - * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate |
|
| 420 | - * (default) |
|
| 421 | - * @return EE_Base_Class | bool |
|
| 422 | - * @throws EE_Error |
|
| 423 | - * @throws ReflectionException |
|
| 424 | - */ |
|
| 425 | - public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
| 426 | - { |
|
| 427 | - $paths = apply_filters( |
|
| 428 | - 'FHEE__EE_Registry__load_class__paths', array( |
|
| 429 | - EE_CORE, |
|
| 430 | - EE_CLASSES, |
|
| 431 | - EE_BUSINESS, |
|
| 432 | - ) |
|
| 433 | - ); |
|
| 434 | - // retrieve instantiated class |
|
| 435 | - return $this->_load( |
|
| 436 | - $paths, |
|
| 437 | - 'EE_', |
|
| 438 | - $class_name, |
|
| 439 | - 'class', |
|
| 440 | - $arguments, |
|
| 441 | - $from_db, |
|
| 442 | - $cache, |
|
| 443 | - $load_only |
|
| 444 | - ); |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - |
|
| 448 | - |
|
| 449 | - /** |
|
| 450 | - * loads helper classes - must be singletons |
|
| 451 | - * |
|
| 452 | - * @param string $class_name - simple class name ie: price |
|
| 453 | - * @param mixed $arguments |
|
| 454 | - * @param bool $load_only |
|
| 455 | - * @return EEH_Base | bool |
|
| 456 | - * @throws EE_Error |
|
| 457 | - * @throws ReflectionException |
|
| 458 | - */ |
|
| 459 | - public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
| 460 | - { |
|
| 461 | - // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
| 462 | - $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
| 463 | - // retrieve instantiated class |
|
| 464 | - return $this->_load( |
|
| 465 | - $helper_paths, |
|
| 466 | - 'EEH_', |
|
| 467 | - $class_name, |
|
| 468 | - 'helper', |
|
| 469 | - $arguments, |
|
| 470 | - false, |
|
| 471 | - true, |
|
| 472 | - $load_only |
|
| 473 | - ); |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - |
|
| 477 | - |
|
| 478 | - /** |
|
| 479 | - * loads core classes - must be singletons |
|
| 480 | - * |
|
| 481 | - * @param string $class_name - simple class name ie: session |
|
| 482 | - * @param mixed $arguments |
|
| 483 | - * @param bool $load_only |
|
| 484 | - * @param bool $cache whether to cache the object or not. |
|
| 485 | - * @return mixed |
|
| 486 | - * @throws EE_Error |
|
| 487 | - * @throws ReflectionException |
|
| 488 | - */ |
|
| 489 | - public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
| 490 | - { |
|
| 491 | - $paths = array( |
|
| 492 | - EE_LIBRARIES, |
|
| 493 | - EE_LIBRARIES . 'messages' . DS, |
|
| 494 | - EE_LIBRARIES . 'shortcodes' . DS, |
|
| 495 | - EE_LIBRARIES . 'qtips' . DS, |
|
| 496 | - EE_LIBRARIES . 'payment_methods' . DS, |
|
| 497 | - ); |
|
| 498 | - // retrieve instantiated class |
|
| 499 | - return $this->_load( |
|
| 500 | - $paths, |
|
| 501 | - 'EE_', |
|
| 502 | - $class_name, |
|
| 503 | - 'lib', |
|
| 504 | - $arguments, |
|
| 505 | - false, |
|
| 506 | - $cache, |
|
| 507 | - $load_only |
|
| 508 | - ); |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - |
|
| 512 | - |
|
| 513 | - /** |
|
| 514 | - * loads model classes - must be singletons |
|
| 515 | - * |
|
| 516 | - * @param string $class_name - simple class name ie: price |
|
| 517 | - * @param mixed $arguments |
|
| 518 | - * @param bool $load_only |
|
| 519 | - * @return EEM_Base | bool |
|
| 520 | - * @throws EE_Error |
|
| 521 | - * @throws ReflectionException |
|
| 522 | - */ |
|
| 523 | - public function load_model($class_name, $arguments = array(), $load_only = false) |
|
| 524 | - { |
|
| 525 | - $paths = apply_filters( |
|
| 526 | - 'FHEE__EE_Registry__load_model__paths', array( |
|
| 527 | - EE_MODELS, |
|
| 528 | - EE_CORE, |
|
| 529 | - ) |
|
| 530 | - ); |
|
| 531 | - // retrieve instantiated class |
|
| 532 | - return $this->_load( |
|
| 533 | - $paths, |
|
| 534 | - 'EEM_', |
|
| 535 | - $class_name, |
|
| 536 | - 'model', |
|
| 537 | - $arguments, |
|
| 538 | - false, |
|
| 539 | - true, |
|
| 540 | - $load_only |
|
| 541 | - ); |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * loads model classes - must be singletons |
|
| 548 | - * |
|
| 549 | - * @param string $class_name - simple class name ie: price |
|
| 550 | - * @param mixed $arguments |
|
| 551 | - * @param bool $load_only |
|
| 552 | - * @return mixed | bool |
|
| 553 | - * @throws EE_Error |
|
| 554 | - * @throws ReflectionException |
|
| 555 | - */ |
|
| 556 | - public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
| 557 | - { |
|
| 558 | - $paths = array( |
|
| 559 | - EE_MODELS . 'fields' . DS, |
|
| 560 | - EE_MODELS . 'helpers' . DS, |
|
| 561 | - EE_MODELS . 'relations' . DS, |
|
| 562 | - EE_MODELS . 'strategies' . DS, |
|
| 563 | - ); |
|
| 564 | - // retrieve instantiated class |
|
| 565 | - return $this->_load( |
|
| 566 | - $paths, |
|
| 567 | - 'EE_', |
|
| 568 | - $class_name, |
|
| 569 | - '', |
|
| 570 | - $arguments, |
|
| 571 | - false, |
|
| 572 | - true, |
|
| 573 | - $load_only |
|
| 574 | - ); |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - |
|
| 578 | - |
|
| 579 | - /** |
|
| 580 | - * Determines if $model_name is the name of an actual EE model. |
|
| 581 | - * |
|
| 582 | - * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
| 583 | - * @return boolean |
|
| 584 | - */ |
|
| 585 | - public function is_model_name($model_name) |
|
| 586 | - { |
|
| 587 | - return isset($this->models[$model_name]); |
|
| 588 | - } |
|
| 589 | - |
|
| 590 | - |
|
| 591 | - |
|
| 592 | - /** |
|
| 593 | - * generic class loader |
|
| 594 | - * |
|
| 595 | - * @param string $path_to_file - directory path to file location, not including filename |
|
| 596 | - * @param string $file_name - file name ie: my_file.php, including extension |
|
| 597 | - * @param string $type - file type - core? class? helper? model? |
|
| 598 | - * @param mixed $arguments |
|
| 599 | - * @param bool $load_only |
|
| 600 | - * @return mixed |
|
| 601 | - * @throws EE_Error |
|
| 602 | - * @throws ReflectionException |
|
| 603 | - */ |
|
| 604 | - public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
| 605 | - { |
|
| 606 | - // retrieve instantiated class |
|
| 607 | - return $this->_load( |
|
| 608 | - $path_to_file, |
|
| 609 | - '', |
|
| 610 | - $file_name, |
|
| 611 | - $type, |
|
| 612 | - $arguments, |
|
| 613 | - false, |
|
| 614 | - true, |
|
| 615 | - $load_only |
|
| 616 | - ); |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - |
|
| 620 | - |
|
| 621 | - /** |
|
| 622 | - * @param string $path_to_file - directory path to file location, not including filename |
|
| 623 | - * @param string $class_name - full class name ie: My_Class |
|
| 624 | - * @param string $type - file type - core? class? helper? model? |
|
| 625 | - * @param mixed $arguments |
|
| 626 | - * @param bool $load_only |
|
| 627 | - * @return bool|EE_Addon|object |
|
| 628 | - * @throws EE_Error |
|
| 629 | - * @throws ReflectionException |
|
| 630 | - */ |
|
| 631 | - public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
| 632 | - { |
|
| 633 | - // retrieve instantiated class |
|
| 634 | - return $this->_load( |
|
| 635 | - $path_to_file, |
|
| 636 | - 'addon', |
|
| 637 | - $class_name, |
|
| 638 | - $type, |
|
| 639 | - $arguments, |
|
| 640 | - false, |
|
| 641 | - true, |
|
| 642 | - $load_only |
|
| 643 | - ); |
|
| 644 | - } |
|
| 645 | - |
|
| 646 | - |
|
| 647 | - |
|
| 648 | - /** |
|
| 649 | - * instantiates, caches, and automatically resolves dependencies |
|
| 650 | - * for classes that use a Fully Qualified Class Name. |
|
| 651 | - * if the class is not capable of being loaded using PSR-4 autoloading, |
|
| 652 | - * then you need to use one of the existing load_*() methods |
|
| 653 | - * which can resolve the classname and filepath from the passed arguments |
|
| 654 | - * |
|
| 655 | - * @param bool|string $class_name Fully Qualified Class Name |
|
| 656 | - * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
| 657 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
| 658 | - * @param bool $from_db some classes are instantiated from the db |
|
| 659 | - * and thus call a different method to instantiate |
|
| 660 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
| 661 | - * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
| 662 | - * @return bool|null|mixed null = failure to load or instantiate class object. |
|
| 663 | - * object = class loaded and instantiated successfully. |
|
| 664 | - * bool = fail or success when $load_only is true |
|
| 665 | - * @throws EE_Error |
|
| 666 | - * @throws ReflectionException |
|
| 667 | - */ |
|
| 668 | - public function create( |
|
| 669 | - $class_name = false, |
|
| 670 | - $arguments = array(), |
|
| 671 | - $cache = false, |
|
| 672 | - $from_db = false, |
|
| 673 | - $load_only = false, |
|
| 674 | - $addon = false |
|
| 675 | - ) { |
|
| 676 | - $class_name = ltrim($class_name, '\\'); |
|
| 677 | - $class_name = $this->_dependency_map->get_alias($class_name); |
|
| 678 | - $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments); |
|
| 679 | - // if a non-FQCN was passed, then verifyClassExists() might return an object |
|
| 680 | - // or it could return null if the class just could not be found anywhere |
|
| 681 | - if ($class_exists instanceof $class_name || $class_exists === null){ |
|
| 682 | - // either way, return the results |
|
| 683 | - return $class_exists; |
|
| 684 | - } |
|
| 685 | - $class_name = $class_exists; |
|
| 686 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
| 687 | - if ($load_only) { |
|
| 688 | - return true; |
|
| 689 | - } |
|
| 690 | - $addon = $addon |
|
| 691 | - ? 'addon' |
|
| 692 | - : ''; |
|
| 693 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
| 694 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
| 695 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
| 696 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
| 697 | - // return object if it's already cached |
|
| 698 | - $cached_class = $this->_get_cached_class($class_name, $addon); |
|
| 699 | - if ($cached_class !== null) { |
|
| 700 | - return $cached_class; |
|
| 701 | - } |
|
| 702 | - } |
|
| 703 | - // obtain the loader method from the dependency map |
|
| 704 | - $loader = $this->_dependency_map->class_loader($class_name); |
|
| 705 | - // instantiate the requested object |
|
| 706 | - if ($loader instanceof Closure) { |
|
| 707 | - $class_obj = $loader($arguments); |
|
| 708 | - } else if ($loader && method_exists($this, $loader)) { |
|
| 709 | - $class_obj = $this->{$loader}($class_name, $arguments); |
|
| 710 | - } else { |
|
| 711 | - $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
| 712 | - } |
|
| 713 | - if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) { |
|
| 714 | - // save it for later... kinda like gum { : $ |
|
| 715 | - $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
| 716 | - } |
|
| 717 | - $this->_cache_on = true; |
|
| 718 | - return $class_obj; |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - |
|
| 722 | - |
|
| 723 | - /** |
|
| 724 | - * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs |
|
| 725 | - * |
|
| 726 | - * @param string $class_name |
|
| 727 | - * @param array $arguments |
|
| 728 | - * @param int $attempt |
|
| 729 | - * @return mixed |
|
| 730 | - */ |
|
| 731 | - private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) { |
|
| 732 | - if (is_object($class_name) || class_exists($class_name)) { |
|
| 733 | - return $class_name; |
|
| 734 | - } |
|
| 735 | - switch ($attempt) { |
|
| 736 | - case 1: |
|
| 737 | - // if it's a FQCN then maybe the class is registered with a preceding \ |
|
| 738 | - $class_name = strpos($class_name, '\\') !== false |
|
| 739 | - ? '\\' . ltrim($class_name, '\\') |
|
| 740 | - : $class_name; |
|
| 741 | - break; |
|
| 742 | - case 2: |
|
| 743 | - // |
|
| 744 | - $loader = $this->_dependency_map->class_loader($class_name); |
|
| 745 | - if ($loader && method_exists($this, $loader)) { |
|
| 746 | - return $this->{$loader}($class_name, $arguments); |
|
| 747 | - } |
|
| 748 | - break; |
|
| 749 | - case 3: |
|
| 750 | - default; |
|
| 751 | - return null; |
|
| 752 | - } |
|
| 753 | - $attempt++; |
|
| 754 | - return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt); |
|
| 755 | - } |
|
| 756 | - |
|
| 757 | - |
|
| 758 | - |
|
| 759 | - /** |
|
| 760 | - * instantiates, caches, and injects dependencies for classes |
|
| 761 | - * |
|
| 762 | - * @param array $file_paths an array of paths to folders to look in |
|
| 763 | - * @param string $class_prefix EE or EEM or... ??? |
|
| 764 | - * @param bool|string $class_name $class name |
|
| 765 | - * @param string $type file type - core? class? helper? model? |
|
| 766 | - * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
| 767 | - * @param bool $from_db some classes are instantiated from the db |
|
| 768 | - * and thus call a different method to instantiate |
|
| 769 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
| 770 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
| 771 | - * @return bool|null|object null = failure to load or instantiate class object. |
|
| 772 | - * object = class loaded and instantiated successfully. |
|
| 773 | - * bool = fail or success when $load_only is true |
|
| 774 | - * @throws EE_Error |
|
| 775 | - * @throws ReflectionException |
|
| 776 | - */ |
|
| 777 | - protected function _load( |
|
| 778 | - $file_paths = array(), |
|
| 779 | - $class_prefix = 'EE_', |
|
| 780 | - $class_name = false, |
|
| 781 | - $type = 'class', |
|
| 782 | - $arguments = array(), |
|
| 783 | - $from_db = false, |
|
| 784 | - $cache = true, |
|
| 785 | - $load_only = false |
|
| 786 | - ) { |
|
| 787 | - $class_name = ltrim($class_name, '\\'); |
|
| 788 | - // strip php file extension |
|
| 789 | - $class_name = str_replace('.php', '', trim($class_name)); |
|
| 790 | - // does the class have a prefix ? |
|
| 791 | - if (! empty($class_prefix) && $class_prefix !== 'addon') { |
|
| 792 | - // make sure $class_prefix is uppercase |
|
| 793 | - $class_prefix = strtoupper(trim($class_prefix)); |
|
| 794 | - // add class prefix ONCE!!! |
|
| 795 | - $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
| 796 | - } |
|
| 797 | - $class_name = $this->_dependency_map->get_alias($class_name); |
|
| 798 | - $class_exists = class_exists($class_name); |
|
| 799 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
| 800 | - if ($load_only && $class_exists) { |
|
| 801 | - return true; |
|
| 802 | - } |
|
| 803 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
| 804 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
| 805 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
| 806 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
| 807 | - // return object if it's already cached |
|
| 808 | - $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
| 809 | - if ($cached_class !== null) { |
|
| 810 | - return $cached_class; |
|
| 811 | - } |
|
| 812 | - } |
|
| 813 | - // if the class doesn't already exist.. then we need to try and find the file and load it |
|
| 814 | - if (! $class_exists) { |
|
| 815 | - // get full path to file |
|
| 816 | - $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
| 817 | - // load the file |
|
| 818 | - $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
| 819 | - // if loading failed, or we are only loading a file but NOT instantiating an object |
|
| 820 | - if (! $loaded || $load_only) { |
|
| 821 | - // return boolean if only loading, or null if an object was expected |
|
| 822 | - return $load_only |
|
| 823 | - ? $loaded |
|
| 824 | - : null; |
|
| 825 | - } |
|
| 826 | - } |
|
| 827 | - // instantiate the requested object |
|
| 828 | - $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
| 829 | - if ($this->_cache_on && $cache) { |
|
| 830 | - // save it for later... kinda like gum { : $ |
|
| 831 | - $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
| 832 | - } |
|
| 833 | - $this->_cache_on = true; |
|
| 834 | - return $class_obj; |
|
| 835 | - } |
|
| 836 | - |
|
| 837 | - |
|
| 838 | - |
|
| 839 | - /** |
|
| 840 | - * @param string $class_name |
|
| 841 | - * @param string $default have to specify something, but not anything that will conflict |
|
| 842 | - * @return mixed|string |
|
| 843 | - */ |
|
| 844 | - protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS') |
|
| 845 | - { |
|
| 846 | - return isset($this->_class_abbreviations[$class_name]) |
|
| 847 | - ? $this->_class_abbreviations[$class_name] |
|
| 848 | - : $default; |
|
| 849 | - } |
|
| 850 | - |
|
| 851 | - /** |
|
| 852 | - * attempts to find a cached version of the requested class |
|
| 853 | - * by looking in the following places: |
|
| 854 | - * $this->{$class_abbreviation} ie: $this->CART |
|
| 855 | - * $this->{$class_name} ie: $this->Some_Class |
|
| 856 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
| 857 | - * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
| 858 | - * |
|
| 859 | - * @param string $class_name |
|
| 860 | - * @param string $class_prefix |
|
| 861 | - * @return mixed |
|
| 862 | - */ |
|
| 863 | - protected function _get_cached_class($class_name, $class_prefix = '') |
|
| 864 | - { |
|
| 865 | - if ($class_name === 'EE_Registry') { |
|
| 866 | - return $this; |
|
| 867 | - } |
|
| 868 | - $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
| 869 | - $class_name = str_replace('\\', '_', $class_name); |
|
| 870 | - // check if class has already been loaded, and return it if it has been |
|
| 871 | - if (isset($this->{$class_abbreviation})) { |
|
| 872 | - return $this->{$class_abbreviation}; |
|
| 873 | - } |
|
| 874 | - if (isset ($this->{$class_name})) { |
|
| 875 | - return $this->{$class_name}; |
|
| 876 | - } |
|
| 877 | - if (isset ($this->LIB->{$class_name})) { |
|
| 878 | - return $this->LIB->{$class_name}; |
|
| 879 | - } |
|
| 880 | - if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) { |
|
| 881 | - return $this->addons->{$class_name}; |
|
| 882 | - } |
|
| 883 | - return null; |
|
| 884 | - } |
|
| 885 | - |
|
| 886 | - |
|
| 887 | - |
|
| 888 | - /** |
|
| 889 | - * removes a cached version of the requested class |
|
| 890 | - * |
|
| 891 | - * @param string $class_name |
|
| 892 | - * @param boolean $addon |
|
| 893 | - * @return boolean |
|
| 894 | - */ |
|
| 895 | - public function clear_cached_class($class_name, $addon = false) |
|
| 896 | - { |
|
| 897 | - $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
| 898 | - $class_name = str_replace('\\', '_', $class_name); |
|
| 899 | - // check if class has already been loaded, and return it if it has been |
|
| 900 | - if (isset($this->{$class_abbreviation})) { |
|
| 901 | - $this->{$class_abbreviation} = null; |
|
| 902 | - return true; |
|
| 903 | - } |
|
| 904 | - if (isset($this->{$class_name})) { |
|
| 905 | - $this->{$class_name} = null; |
|
| 906 | - return true; |
|
| 907 | - } |
|
| 908 | - if (isset($this->LIB->{$class_name})) { |
|
| 909 | - unset($this->LIB->{$class_name}); |
|
| 910 | - return true; |
|
| 911 | - } |
|
| 912 | - if ($addon && isset($this->addons->{$class_name})) { |
|
| 913 | - unset($this->addons->{$class_name}); |
|
| 914 | - return true; |
|
| 915 | - } |
|
| 916 | - return false; |
|
| 917 | - } |
|
| 918 | - |
|
| 919 | - |
|
| 920 | - |
|
| 921 | - /** |
|
| 922 | - * attempts to find a full valid filepath for the requested class. |
|
| 923 | - * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
| 924 | - * then returns that path if the target file has been found and is readable |
|
| 925 | - * |
|
| 926 | - * @param string $class_name |
|
| 927 | - * @param string $type |
|
| 928 | - * @param array $file_paths |
|
| 929 | - * @return string | bool |
|
| 930 | - */ |
|
| 931 | - protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
| 932 | - { |
|
| 933 | - // make sure $file_paths is an array |
|
| 934 | - $file_paths = is_array($file_paths) |
|
| 935 | - ? $file_paths |
|
| 936 | - : array($file_paths); |
|
| 937 | - // cycle thru paths |
|
| 938 | - foreach ($file_paths as $key => $file_path) { |
|
| 939 | - // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
| 940 | - $file_path = $file_path |
|
| 941 | - ? str_replace(array('/', '\\'), DS, $file_path) |
|
| 942 | - : EE_CLASSES; |
|
| 943 | - // prep file type |
|
| 944 | - $type = ! empty($type) |
|
| 945 | - ? trim($type, '.') . '.' |
|
| 946 | - : ''; |
|
| 947 | - // build full file path |
|
| 948 | - $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
| 949 | - //does the file exist and can be read ? |
|
| 950 | - if (is_readable($file_paths[$key])) { |
|
| 951 | - return $file_paths[$key]; |
|
| 952 | - } |
|
| 953 | - } |
|
| 954 | - return false; |
|
| 955 | - } |
|
| 956 | - |
|
| 957 | - |
|
| 958 | - |
|
| 959 | - /** |
|
| 960 | - * basically just performs a require_once() |
|
| 961 | - * but with some error handling |
|
| 962 | - * |
|
| 963 | - * @param string $path |
|
| 964 | - * @param string $class_name |
|
| 965 | - * @param string $type |
|
| 966 | - * @param array $file_paths |
|
| 967 | - * @return bool |
|
| 968 | - * @throws EE_Error |
|
| 969 | - * @throws ReflectionException |
|
| 970 | - */ |
|
| 971 | - protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
| 972 | - { |
|
| 973 | - // don't give up! you gotta... |
|
| 974 | - try { |
|
| 975 | - //does the file exist and can it be read ? |
|
| 976 | - if (! $path) { |
|
| 977 | - // so sorry, can't find the file |
|
| 978 | - throw new EE_Error ( |
|
| 979 | - sprintf( |
|
| 980 | - esc_html__( |
|
| 981 | - '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', |
|
| 982 | - 'event_espresso' |
|
| 983 | - ), |
|
| 984 | - trim($type, '.'), |
|
| 985 | - $class_name, |
|
| 986 | - '<br />' . implode(',<br />', $file_paths) |
|
| 987 | - ) |
|
| 988 | - ); |
|
| 989 | - } |
|
| 990 | - // get the file |
|
| 991 | - require_once($path); |
|
| 992 | - // if the class isn't already declared somewhere |
|
| 993 | - if (class_exists($class_name, false) === false) { |
|
| 994 | - // so sorry, not a class |
|
| 995 | - throw new EE_Error( |
|
| 996 | - sprintf( |
|
| 997 | - esc_html__('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
| 998 | - $type, |
|
| 999 | - $path, |
|
| 1000 | - $class_name |
|
| 1001 | - ) |
|
| 1002 | - ); |
|
| 1003 | - } |
|
| 1004 | - } catch (EE_Error $e) { |
|
| 1005 | - $e->get_error(); |
|
| 1006 | - return false; |
|
| 1007 | - } |
|
| 1008 | - return true; |
|
| 1009 | - } |
|
| 1010 | - |
|
| 1011 | - |
|
| 1012 | - |
|
| 1013 | - /** |
|
| 1014 | - * _create_object |
|
| 1015 | - * Attempts to instantiate the requested class via any of the |
|
| 1016 | - * commonly used instantiation methods employed throughout EE. |
|
| 1017 | - * The priority for instantiation is as follows: |
|
| 1018 | - * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
| 1019 | - * - model objects via their 'new_instance_from_db' method |
|
| 1020 | - * - model objects via their 'new_instance' method |
|
| 1021 | - * - "singleton" classes" via their 'instance' method |
|
| 1022 | - * - standard instantiable classes via their __constructor |
|
| 1023 | - * Prior to instantiation, if the classname exists in the dependency_map, |
|
| 1024 | - * then the constructor for the requested class will be examined to determine |
|
| 1025 | - * if any dependencies exist, and if they can be injected. |
|
| 1026 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
| 1027 | - * |
|
| 1028 | - * @param string $class_name |
|
| 1029 | - * @param array $arguments |
|
| 1030 | - * @param string $type |
|
| 1031 | - * @param bool $from_db |
|
| 1032 | - * @return null|object |
|
| 1033 | - * @throws EE_Error |
|
| 1034 | - * @throws ReflectionException |
|
| 1035 | - */ |
|
| 1036 | - protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
| 1037 | - { |
|
| 1038 | - // create reflection |
|
| 1039 | - $reflector = $this->get_ReflectionClass($class_name); |
|
| 1040 | - // make sure arguments are an array |
|
| 1041 | - $arguments = is_array($arguments) |
|
| 1042 | - ? $arguments |
|
| 1043 | - : array($arguments); |
|
| 1044 | - // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
| 1045 | - // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
| 1046 | - $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
| 1047 | - ? $arguments |
|
| 1048 | - : array($arguments); |
|
| 1049 | - // attempt to inject dependencies ? |
|
| 1050 | - if ($this->_dependency_map->has($class_name)) { |
|
| 1051 | - $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
| 1052 | - } |
|
| 1053 | - // instantiate the class if possible |
|
| 1054 | - if ($reflector->isAbstract()) { |
|
| 1055 | - // nothing to instantiate, loading file was enough |
|
| 1056 | - // does not throw an exception so $instantiation_mode is unused |
|
| 1057 | - // $instantiation_mode = "1) no constructor abstract class"; |
|
| 1058 | - return true; |
|
| 1059 | - } |
|
| 1060 | - if (empty($arguments) && $reflector->getConstructor() === null && $reflector->isInstantiable()) { |
|
| 1061 | - // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
| 1062 | - // $instantiation_mode = "2) no constructor but instantiable"; |
|
| 1063 | - return $reflector->newInstance(); |
|
| 1064 | - } |
|
| 1065 | - if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
| 1066 | - // $instantiation_mode = "3) new_instance_from_db()"; |
|
| 1067 | - return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
| 1068 | - } |
|
| 1069 | - if (method_exists($class_name, 'new_instance')) { |
|
| 1070 | - // $instantiation_mode = "4) new_instance()"; |
|
| 1071 | - return call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
| 1072 | - } |
|
| 1073 | - if (method_exists($class_name, 'instance')) { |
|
| 1074 | - // $instantiation_mode = "5) instance()"; |
|
| 1075 | - return call_user_func_array(array($class_name, 'instance'), $arguments); |
|
| 1076 | - } |
|
| 1077 | - if ($reflector->isInstantiable()) { |
|
| 1078 | - // $instantiation_mode = "6) constructor"; |
|
| 1079 | - return $reflector->newInstanceArgs($arguments); |
|
| 1080 | - } |
|
| 1081 | - // heh ? something's not right ! |
|
| 1082 | - throw new EE_Error( |
|
| 1083 | - sprintf( |
|
| 1084 | - __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
| 1085 | - $type, |
|
| 1086 | - $class_name |
|
| 1087 | - ) |
|
| 1088 | - ); |
|
| 1089 | - } |
|
| 1090 | - |
|
| 1091 | - |
|
| 1092 | - |
|
| 1093 | - /** |
|
| 1094 | - * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
| 1095 | - * @param array $array |
|
| 1096 | - * @return bool |
|
| 1097 | - */ |
|
| 1098 | - protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
| 1099 | - { |
|
| 1100 | - return ! empty($array) |
|
| 1101 | - ? array_keys($array) === range(0, count($array) - 1) |
|
| 1102 | - : true; |
|
| 1103 | - } |
|
| 1104 | - |
|
| 1105 | - |
|
| 1106 | - |
|
| 1107 | - /** |
|
| 1108 | - * getReflectionClass |
|
| 1109 | - * checks if a ReflectionClass object has already been generated for a class |
|
| 1110 | - * and returns that instead of creating a new one |
|
| 1111 | - * |
|
| 1112 | - * @param string $class_name |
|
| 1113 | - * @return ReflectionClass |
|
| 1114 | - * @throws ReflectionException |
|
| 1115 | - */ |
|
| 1116 | - public function get_ReflectionClass($class_name) |
|
| 1117 | - { |
|
| 1118 | - if ( |
|
| 1119 | - ! isset($this->_reflectors[$class_name]) |
|
| 1120 | - || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
| 1121 | - ) { |
|
| 1122 | - $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
| 1123 | - } |
|
| 1124 | - return $this->_reflectors[$class_name]; |
|
| 1125 | - } |
|
| 1126 | - |
|
| 1127 | - |
|
| 1128 | - |
|
| 1129 | - /** |
|
| 1130 | - * _resolve_dependencies |
|
| 1131 | - * examines the constructor for the requested class to determine |
|
| 1132 | - * if any dependencies exist, and if they can be injected. |
|
| 1133 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
| 1134 | - * PLZ NOTE: this is achieved by type hinting the constructor params |
|
| 1135 | - * For example: |
|
| 1136 | - * if attempting to load a class "Foo" with the following constructor: |
|
| 1137 | - * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
| 1138 | - * then $bar_class and $grohl_class will be added to the $arguments array, |
|
| 1139 | - * but only IF they are NOT already present in the incoming arguments array, |
|
| 1140 | - * and the correct classes can be loaded |
|
| 1141 | - * |
|
| 1142 | - * @param ReflectionClass $reflector |
|
| 1143 | - * @param string $class_name |
|
| 1144 | - * @param array $arguments |
|
| 1145 | - * @return array |
|
| 1146 | - * @throws EE_Error |
|
| 1147 | - * @throws ReflectionException |
|
| 1148 | - */ |
|
| 1149 | - protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
|
| 1150 | - { |
|
| 1151 | - // let's examine the constructor |
|
| 1152 | - $constructor = $reflector->getConstructor(); |
|
| 1153 | - // whu? huh? nothing? |
|
| 1154 | - if (! $constructor) { |
|
| 1155 | - return $arguments; |
|
| 1156 | - } |
|
| 1157 | - // get constructor parameters |
|
| 1158 | - $params = $constructor->getParameters(); |
|
| 1159 | - // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
| 1160 | - $argument_keys = array_keys($arguments); |
|
| 1161 | - // now loop thru all of the constructors expected parameters |
|
| 1162 | - foreach ($params as $index => $param) { |
|
| 1163 | - // is this a dependency for a specific class ? |
|
| 1164 | - $param_class = $param->getClass() |
|
| 1165 | - ? $param->getClass()->name |
|
| 1166 | - : null; |
|
| 1167 | - // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime) |
|
| 1168 | - $param_class = $this->_dependency_map->has_alias($param_class, $class_name) |
|
| 1169 | - ? $this->_dependency_map->get_alias($param_class, $class_name) |
|
| 1170 | - : $param_class; |
|
| 1171 | - if ( |
|
| 1172 | - // param is not even a class |
|
| 1173 | - $param_class === null |
|
| 1174 | - // and something already exists in the incoming arguments for this param |
|
| 1175 | - && array_key_exists($index, $argument_keys) |
|
| 1176 | - && array_key_exists($argument_keys[$index], $arguments) |
|
| 1177 | - ) { |
|
| 1178 | - // so let's skip this argument and move on to the next |
|
| 1179 | - continue; |
|
| 1180 | - } |
|
| 1181 | - if ( |
|
| 1182 | - // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
| 1183 | - $param_class !== null |
|
| 1184 | - && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
| 1185 | - && $arguments[$argument_keys[$index]] instanceof $param_class |
|
| 1186 | - ) { |
|
| 1187 | - // skip this argument and move on to the next |
|
| 1188 | - continue; |
|
| 1189 | - } |
|
| 1190 | - if ( |
|
| 1191 | - // parameter is type hinted as a class, and should be injected |
|
| 1192 | - $param_class !== null |
|
| 1193 | - && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
| 1194 | - ) { |
|
| 1195 | - $arguments = $this->_resolve_dependency( |
|
| 1196 | - $class_name, |
|
| 1197 | - $param_class, |
|
| 1198 | - $arguments, |
|
| 1199 | - $index, |
|
| 1200 | - $argument_keys |
|
| 1201 | - ); |
|
| 1202 | - } else { |
|
| 1203 | - try { |
|
| 1204 | - $arguments[$index] = $param->isDefaultValueAvailable() |
|
| 1205 | - ? $param->getDefaultValue() |
|
| 1206 | - : null; |
|
| 1207 | - } catch (ReflectionException $e) { |
|
| 1208 | - throw new ReflectionException( |
|
| 1209 | - sprintf( |
|
| 1210 | - esc_html__('%1$s for parameter "$%2$s on classname "%3$s"', 'event_espresso'), |
|
| 1211 | - $e->getMessage(), |
|
| 1212 | - $param->getName(), |
|
| 1213 | - $class_name |
|
| 1214 | - ) |
|
| 1215 | - ); |
|
| 1216 | - } |
|
| 1217 | - } |
|
| 1218 | - } |
|
| 1219 | - return $arguments; |
|
| 1220 | - } |
|
| 1221 | - |
|
| 1222 | - |
|
| 1223 | - |
|
| 1224 | - /** |
|
| 1225 | - * @param string $class_name |
|
| 1226 | - * @param string $param_class |
|
| 1227 | - * @param array $arguments |
|
| 1228 | - * @param mixed $index |
|
| 1229 | - * @param array $argument_keys |
|
| 1230 | - * @return array |
|
| 1231 | - * @throws EE_Error |
|
| 1232 | - * @throws ReflectionException |
|
| 1233 | - * @throws InvalidArgumentException |
|
| 1234 | - * @throws InvalidInterfaceException |
|
| 1235 | - * @throws InvalidDataTypeException |
|
| 1236 | - */ |
|
| 1237 | - protected function _resolve_dependency($class_name, $param_class, $arguments, $index, array $argument_keys) |
|
| 1238 | - { |
|
| 1239 | - $dependency = null; |
|
| 1240 | - // should dependency be loaded from cache ? |
|
| 1241 | - $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency( |
|
| 1242 | - $class_name, |
|
| 1243 | - $param_class |
|
| 1244 | - ); |
|
| 1245 | - $cache_on = $cache_on !== EE_Dependency_Map::load_new_object; |
|
| 1246 | - // we might have a dependency... |
|
| 1247 | - // let's MAYBE try and find it in our cache if that's what's been requested |
|
| 1248 | - $cached_class = $cache_on |
|
| 1249 | - ? $this->_get_cached_class($param_class) |
|
| 1250 | - : null; |
|
| 1251 | - // and grab it if it exists |
|
| 1252 | - if ($cached_class instanceof $param_class) { |
|
| 1253 | - $dependency = $cached_class; |
|
| 1254 | - } else if ($param_class !== $class_name) { |
|
| 1255 | - // obtain the loader method from the dependency map |
|
| 1256 | - $loader = $this->_dependency_map->class_loader($param_class); |
|
| 1257 | - // is loader a custom closure ? |
|
| 1258 | - if ($loader instanceof Closure) { |
|
| 1259 | - $dependency = $loader($arguments); |
|
| 1260 | - } else { |
|
| 1261 | - // set the cache on property for the recursive loading call |
|
| 1262 | - $this->_cache_on = $cache_on; |
|
| 1263 | - // if not, then let's try and load it via the registry |
|
| 1264 | - if ($loader && method_exists($this, $loader)) { |
|
| 1265 | - $dependency = $this->{$loader}($param_class); |
|
| 1266 | - } else { |
|
| 1267 | - $dependency = LoaderFactory::getLoader()->load( |
|
| 1268 | - $param_class, |
|
| 1269 | - array(), |
|
| 1270 | - $cache_on |
|
| 1271 | - ); |
|
| 1272 | - } |
|
| 1273 | - } |
|
| 1274 | - } |
|
| 1275 | - // did we successfully find the correct dependency ? |
|
| 1276 | - if ($dependency instanceof $param_class) { |
|
| 1277 | - // then let's inject it into the incoming array of arguments at the correct location |
|
| 1278 | - $arguments[$index] = $dependency; |
|
| 1279 | - } |
|
| 1280 | - return $arguments; |
|
| 1281 | - } |
|
| 1282 | - |
|
| 1283 | - |
|
| 1284 | - |
|
| 1285 | - /** |
|
| 1286 | - * _set_cached_class |
|
| 1287 | - * attempts to cache the instantiated class locally |
|
| 1288 | - * in one of the following places, in the following order: |
|
| 1289 | - * $this->{class_abbreviation} ie: $this->CART |
|
| 1290 | - * $this->{$class_name} ie: $this->Some_Class |
|
| 1291 | - * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
| 1292 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
| 1293 | - * |
|
| 1294 | - * @param object $class_obj |
|
| 1295 | - * @param string $class_name |
|
| 1296 | - * @param string $class_prefix |
|
| 1297 | - * @param bool $from_db |
|
| 1298 | - * @return void |
|
| 1299 | - */ |
|
| 1300 | - protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
|
| 1301 | - { |
|
| 1302 | - if ($class_name === 'EE_Registry' || empty($class_obj)) { |
|
| 1303 | - return; |
|
| 1304 | - } |
|
| 1305 | - // return newly instantiated class |
|
| 1306 | - $class_abbreviation = $this->get_class_abbreviation($class_name, ''); |
|
| 1307 | - if ($class_abbreviation) { |
|
| 1308 | - $this->{$class_abbreviation} = $class_obj; |
|
| 1309 | - return; |
|
| 1310 | - } |
|
| 1311 | - $class_name = str_replace('\\', '_', $class_name); |
|
| 1312 | - if (property_exists($this, $class_name)) { |
|
| 1313 | - $this->{$class_name} = $class_obj; |
|
| 1314 | - return; |
|
| 1315 | - } |
|
| 1316 | - if ($class_prefix === 'addon') { |
|
| 1317 | - $this->addons->{$class_name} = $class_obj; |
|
| 1318 | - return; |
|
| 1319 | - } |
|
| 1320 | - if (! $from_db) { |
|
| 1321 | - $this->LIB->{$class_name} = $class_obj; |
|
| 1322 | - } |
|
| 1323 | - } |
|
| 1324 | - |
|
| 1325 | - |
|
| 1326 | - |
|
| 1327 | - /** |
|
| 1328 | - * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
| 1329 | - * |
|
| 1330 | - * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
| 1331 | - * in the EE_Dependency_Map::$_class_loaders array, |
|
| 1332 | - * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
| 1333 | - * @param array $arguments |
|
| 1334 | - * @return object |
|
| 1335 | - */ |
|
| 1336 | - public static function factory($classname, $arguments = array()) |
|
| 1337 | - { |
|
| 1338 | - $loader = self::instance()->_dependency_map->class_loader($classname); |
|
| 1339 | - if ($loader instanceof Closure) { |
|
| 1340 | - return $loader($arguments); |
|
| 1341 | - } |
|
| 1342 | - if (method_exists(self::instance(), $loader)) { |
|
| 1343 | - return self::instance()->{$loader}($classname, $arguments); |
|
| 1344 | - } |
|
| 1345 | - return null; |
|
| 1346 | - } |
|
| 1347 | - |
|
| 1348 | - |
|
| 1349 | - |
|
| 1350 | - /** |
|
| 1351 | - * Gets the addon by its name/slug (not classname. For that, just |
|
| 1352 | - * use the classname as the property name on EE_Config::instance()->addons) |
|
| 1353 | - * |
|
| 1354 | - * @param string $name |
|
| 1355 | - * @return EE_Addon |
|
| 1356 | - */ |
|
| 1357 | - public function get_addon_by_name($name) |
|
| 1358 | - { |
|
| 1359 | - foreach ($this->addons as $addon) { |
|
| 1360 | - if ($addon->name() === $name) { |
|
| 1361 | - return $addon; |
|
| 1362 | - } |
|
| 1363 | - } |
|
| 1364 | - return null; |
|
| 1365 | - } |
|
| 1366 | - |
|
| 1367 | - |
|
| 1368 | - |
|
| 1369 | - /** |
|
| 1370 | - * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their |
|
| 1371 | - * name() function) They're already available on EE_Config::instance()->addons as properties, where each property's |
|
| 1372 | - * name is the addon's classname. So if you just want to get the addon by classname, use |
|
| 1373 | - * EE_Config::instance()->addons->{classname} |
|
| 1374 | - * |
|
| 1375 | - * @return EE_Addon[] where the KEYS are the addon's name() |
|
| 1376 | - */ |
|
| 1377 | - public function get_addons_by_name() |
|
| 1378 | - { |
|
| 1379 | - $addons = array(); |
|
| 1380 | - foreach ($this->addons as $addon) { |
|
| 1381 | - $addons[$addon->name()] = $addon; |
|
| 1382 | - } |
|
| 1383 | - return $addons; |
|
| 1384 | - } |
|
| 1385 | - |
|
| 1386 | - |
|
| 1387 | - |
|
| 1388 | - /** |
|
| 1389 | - * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
| 1390 | - * a stale copy of it around |
|
| 1391 | - * |
|
| 1392 | - * @param string $model_name |
|
| 1393 | - * @return \EEM_Base |
|
| 1394 | - * @throws \EE_Error |
|
| 1395 | - */ |
|
| 1396 | - public function reset_model($model_name) |
|
| 1397 | - { |
|
| 1398 | - $model_class_name = strpos($model_name, 'EEM_') !== 0 |
|
| 1399 | - ? "EEM_{$model_name}" |
|
| 1400 | - : $model_name; |
|
| 1401 | - if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
| 1402 | - return null; |
|
| 1403 | - } |
|
| 1404 | - //get that model reset it and make sure we nuke the old reference to it |
|
| 1405 | - if ($this->LIB->{$model_class_name} instanceof $model_class_name |
|
| 1406 | - && is_callable( |
|
| 1407 | - array($model_class_name, 'reset') |
|
| 1408 | - )) { |
|
| 1409 | - $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
| 1410 | - } else { |
|
| 1411 | - throw new EE_Error(sprintf(esc_html__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
| 1412 | - } |
|
| 1413 | - return $this->LIB->{$model_class_name}; |
|
| 1414 | - } |
|
| 1415 | - |
|
| 1416 | - |
|
| 1417 | - |
|
| 1418 | - /** |
|
| 1419 | - * Resets the registry. |
|
| 1420 | - * The criteria for what gets reset is based on what can be shared between sites on the same request when |
|
| 1421 | - * switch_to_blog is used in a multisite install. Here is a list of things that are NOT reset. |
|
| 1422 | - * - $_dependency_map |
|
| 1423 | - * - $_class_abbreviations |
|
| 1424 | - * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
| 1425 | - * - $REQ: Still on the same request so no need to change. |
|
| 1426 | - * - $CAP: There is no site specific state in the EE_Capability class. |
|
| 1427 | - * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only |
|
| 1428 | - * one Session can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
| 1429 | - * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
| 1430 | - * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
| 1431 | - * switch or on the restore. |
|
| 1432 | - * - $modules |
|
| 1433 | - * - $shortcodes |
|
| 1434 | - * - $widgets |
|
| 1435 | - * |
|
| 1436 | - * @param boolean $hard [deprecated] |
|
| 1437 | - * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
| 1438 | - * or just reset without re-instantiating (handy to set to FALSE if you're not |
|
| 1439 | - * sure if you CAN currently reinstantiate the singletons at the moment) |
|
| 1440 | - * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so |
|
| 1441 | - * client |
|
| 1442 | - * code instead can just change the model context to a different blog id if |
|
| 1443 | - * necessary |
|
| 1444 | - * @return EE_Registry |
|
| 1445 | - * @throws EE_Error |
|
| 1446 | - * @throws ReflectionException |
|
| 1447 | - */ |
|
| 1448 | - public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
| 1449 | - { |
|
| 1450 | - $instance = self::instance(); |
|
| 1451 | - $instance->_cache_on = true; |
|
| 1452 | - // reset some "special" classes |
|
| 1453 | - EEH_Activation::reset(); |
|
| 1454 | - $hard = apply_filters( 'FHEE__EE_Registry__reset__hard', $hard); |
|
| 1455 | - $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
| 1456 | - $instance->CART = null; |
|
| 1457 | - $instance->MRM = null; |
|
| 1458 | - $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry'); |
|
| 1459 | - //messages reset |
|
| 1460 | - EED_Messages::reset(); |
|
| 1461 | - //handle of objects cached on LIB |
|
| 1462 | - foreach (array('LIB', 'modules') as $cache) { |
|
| 1463 | - foreach ($instance->{$cache} as $class_name => $class) { |
|
| 1464 | - if (self::_reset_and_unset_object($class, $reset_models)) { |
|
| 1465 | - unset($instance->{$cache}->{$class_name}); |
|
| 1466 | - } |
|
| 1467 | - } |
|
| 1468 | - } |
|
| 1469 | - return $instance; |
|
| 1470 | - } |
|
| 1471 | - |
|
| 1472 | - |
|
| 1473 | - |
|
| 1474 | - /** |
|
| 1475 | - * if passed object implements ResettableInterface, then call it's reset() method |
|
| 1476 | - * if passed object implements InterminableInterface, then return false, |
|
| 1477 | - * to indicate that it should NOT be cleared from the Registry cache |
|
| 1478 | - * |
|
| 1479 | - * @param $object |
|
| 1480 | - * @param bool $reset_models |
|
| 1481 | - * @return bool returns true if cached object should be unset |
|
| 1482 | - */ |
|
| 1483 | - private static function _reset_and_unset_object($object, $reset_models) |
|
| 1484 | - { |
|
| 1485 | - if (! is_object($object)) { |
|
| 1486 | - // don't unset anything that's not an object |
|
| 1487 | - return false; |
|
| 1488 | - } |
|
| 1489 | - if ($object instanceof EED_Module) { |
|
| 1490 | - $object::reset(); |
|
| 1491 | - // don't unset modules |
|
| 1492 | - return false; |
|
| 1493 | - } |
|
| 1494 | - if ($object instanceof ResettableInterface) { |
|
| 1495 | - if ($object instanceof EEM_Base) { |
|
| 1496 | - if ($reset_models) { |
|
| 1497 | - $object->reset(); |
|
| 1498 | - return true; |
|
| 1499 | - } |
|
| 1500 | - return false; |
|
| 1501 | - } |
|
| 1502 | - $object->reset(); |
|
| 1503 | - return true; |
|
| 1504 | - } |
|
| 1505 | - if (! $object instanceof InterminableInterface) { |
|
| 1506 | - return true; |
|
| 1507 | - } |
|
| 1508 | - return false; |
|
| 1509 | - } |
|
| 1510 | - |
|
| 1511 | - |
|
| 1512 | - |
|
| 1513 | - /** |
|
| 1514 | - * Gets all the custom post type models defined |
|
| 1515 | - * |
|
| 1516 | - * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
| 1517 | - */ |
|
| 1518 | - public function cpt_models() |
|
| 1519 | - { |
|
| 1520 | - $cpt_models = array(); |
|
| 1521 | - foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
| 1522 | - if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
| 1523 | - $cpt_models[$short_name] = $classname; |
|
| 1524 | - } |
|
| 1525 | - } |
|
| 1526 | - return $cpt_models; |
|
| 1527 | - } |
|
| 1528 | - |
|
| 1529 | - |
|
| 1530 | - |
|
| 1531 | - /** |
|
| 1532 | - * @return \EE_Config |
|
| 1533 | - */ |
|
| 1534 | - public static function CFG() |
|
| 1535 | - { |
|
| 1536 | - return self::instance()->CFG; |
|
| 1537 | - } |
|
| 25 | + /** |
|
| 26 | + * @var EE_Registry $_instance |
|
| 27 | + */ |
|
| 28 | + private static $_instance; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var EE_Dependency_Map $_dependency_map |
|
| 32 | + */ |
|
| 33 | + protected $_dependency_map; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var array $_class_abbreviations |
|
| 37 | + */ |
|
| 38 | + protected $_class_abbreviations = array(); |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var CommandBusInterface $BUS |
|
| 42 | + */ |
|
| 43 | + public $BUS; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var EE_Cart $CART |
|
| 47 | + */ |
|
| 48 | + public $CART; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var EE_Config $CFG |
|
| 52 | + */ |
|
| 53 | + public $CFG; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @var EE_Network_Config $NET_CFG |
|
| 57 | + */ |
|
| 58 | + public $NET_CFG; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * StdClass object for storing library classes in |
|
| 62 | + * |
|
| 63 | + * @var StdClass $LIB |
|
| 64 | + */ |
|
| 65 | + public $LIB; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @var EE_Request_Handler $REQ |
|
| 69 | + */ |
|
| 70 | + public $REQ; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @var EE_Session $SSN |
|
| 74 | + */ |
|
| 75 | + public $SSN; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @since 4.5.0 |
|
| 79 | + * @var EE_Capabilities $CAP |
|
| 80 | + */ |
|
| 81 | + public $CAP; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @since 4.9.0 |
|
| 85 | + * @var EE_Message_Resource_Manager $MRM |
|
| 86 | + */ |
|
| 87 | + public $MRM; |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @var Registry $AssetsRegistry |
|
| 92 | + */ |
|
| 93 | + public $AssetsRegistry; |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * StdClass object for holding addons which have registered themselves to work with EE core |
|
| 97 | + * |
|
| 98 | + * @var EE_Addon[] $addons |
|
| 99 | + */ |
|
| 100 | + public $addons; |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
| 104 | + * |
|
| 105 | + * @var EEM_Base[] $models |
|
| 106 | + */ |
|
| 107 | + public $models = array(); |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @var EED_Module[] $modules |
|
| 111 | + */ |
|
| 112 | + public $modules; |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * @var EES_Shortcode[] $shortcodes |
|
| 116 | + */ |
|
| 117 | + public $shortcodes; |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * @var WP_Widget[] $widgets |
|
| 121 | + */ |
|
| 122 | + public $widgets; |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
| 126 | + * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
| 127 | + * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
| 128 | + * classnames (eg "EEM_Event") |
|
| 129 | + * |
|
| 130 | + * @var array $non_abstract_db_models |
|
| 131 | + */ |
|
| 132 | + public $non_abstract_db_models = array(); |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * internationalization for JS strings |
|
| 137 | + * usage: EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' ); |
|
| 138 | + * in js file: var translatedString = eei18n.string_key; |
|
| 139 | + * |
|
| 140 | + * @var array $i18n_js_strings |
|
| 141 | + */ |
|
| 142 | + public static $i18n_js_strings = array(); |
|
| 143 | + |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * $main_file - path to espresso.php |
|
| 147 | + * |
|
| 148 | + * @var array $main_file |
|
| 149 | + */ |
|
| 150 | + public $main_file; |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * array of ReflectionClass objects where the key is the class name |
|
| 154 | + * |
|
| 155 | + * @var ReflectionClass[] $_reflectors |
|
| 156 | + */ |
|
| 157 | + public $_reflectors; |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
| 161 | + * |
|
| 162 | + * @var boolean $_cache_on |
|
| 163 | + */ |
|
| 164 | + protected $_cache_on = true; |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * @singleton method used to instantiate class object |
|
| 170 | + * @param EE_Dependency_Map $dependency_map |
|
| 171 | + * @return EE_Registry instance |
|
| 172 | + * @throws InvalidArgumentException |
|
| 173 | + * @throws InvalidInterfaceException |
|
| 174 | + * @throws InvalidDataTypeException |
|
| 175 | + */ |
|
| 176 | + public static function instance(EE_Dependency_Map $dependency_map = null) |
|
| 177 | + { |
|
| 178 | + // check if class object is instantiated |
|
| 179 | + if (! self::$_instance instanceof EE_Registry) { |
|
| 180 | + self::$_instance = new self($dependency_map); |
|
| 181 | + } |
|
| 182 | + return self::$_instance; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * protected constructor to prevent direct creation |
|
| 189 | + * |
|
| 190 | + * @Constructor |
|
| 191 | + * @param EE_Dependency_Map $dependency_map |
|
| 192 | + * @throws InvalidDataTypeException |
|
| 193 | + * @throws InvalidInterfaceException |
|
| 194 | + * @throws InvalidArgumentException |
|
| 195 | + */ |
|
| 196 | + protected function __construct(EE_Dependency_Map $dependency_map) |
|
| 197 | + { |
|
| 198 | + $this->_dependency_map = $dependency_map; |
|
| 199 | + $this->LIB = new stdClass(); |
|
| 200 | + $this->addons = new stdClass(); |
|
| 201 | + $this->modules = new stdClass(); |
|
| 202 | + $this->shortcodes = new stdClass(); |
|
| 203 | + $this->widgets = new stdClass(); |
|
| 204 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * initialize |
|
| 211 | + * |
|
| 212 | + * @throws EE_Error |
|
| 213 | + * @throws ReflectionException |
|
| 214 | + */ |
|
| 215 | + public function initialize() |
|
| 216 | + { |
|
| 217 | + $this->_class_abbreviations = apply_filters( |
|
| 218 | + 'FHEE__EE_Registry____construct___class_abbreviations', |
|
| 219 | + array( |
|
| 220 | + 'EE_Config' => 'CFG', |
|
| 221 | + 'EE_Session' => 'SSN', |
|
| 222 | + 'EE_Capabilities' => 'CAP', |
|
| 223 | + 'EE_Cart' => 'CART', |
|
| 224 | + 'EE_Network_Config' => 'NET_CFG', |
|
| 225 | + 'EE_Request_Handler' => 'REQ', |
|
| 226 | + 'EE_Message_Resource_Manager' => 'MRM', |
|
| 227 | + 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
| 228 | + 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
|
| 229 | + ) |
|
| 230 | + ); |
|
| 231 | + $this->load_core('Base', array(), true); |
|
| 232 | + // add our request and response objects to the cache |
|
| 233 | + $request_loader = $this->_dependency_map->class_loader('EE_Request'); |
|
| 234 | + $this->_set_cached_class( |
|
| 235 | + $request_loader(), |
|
| 236 | + 'EE_Request' |
|
| 237 | + ); |
|
| 238 | + $response_loader = $this->_dependency_map->class_loader('EE_Response'); |
|
| 239 | + $this->_set_cached_class( |
|
| 240 | + $response_loader(), |
|
| 241 | + 'EE_Response' |
|
| 242 | + ); |
|
| 243 | + add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * @return void |
|
| 250 | + */ |
|
| 251 | + public function init() |
|
| 252 | + { |
|
| 253 | + // Get current page protocol |
|
| 254 | + $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
| 255 | + // Output admin-ajax.php URL with same protocol as current page |
|
| 256 | + self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
| 257 | + self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * localize_i18n_js_strings |
|
| 264 | + * |
|
| 265 | + * @return string |
|
| 266 | + */ |
|
| 267 | + public static function localize_i18n_js_strings() |
|
| 268 | + { |
|
| 269 | + $i18n_js_strings = (array)self::$i18n_js_strings; |
|
| 270 | + foreach ($i18n_js_strings as $key => $value) { |
|
| 271 | + if (is_scalar($value)) { |
|
| 272 | + $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 273 | + } |
|
| 274 | + } |
|
| 275 | + return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * @param mixed string | EED_Module $module |
|
| 282 | + * @throws EE_Error |
|
| 283 | + * @throws ReflectionException |
|
| 284 | + */ |
|
| 285 | + public function add_module($module) |
|
| 286 | + { |
|
| 287 | + if ($module instanceof EED_Module) { |
|
| 288 | + $module_class = get_class($module); |
|
| 289 | + $this->modules->{$module_class} = $module; |
|
| 290 | + } else { |
|
| 291 | + if (! class_exists('EE_Module_Request_Router')) { |
|
| 292 | + $this->load_core('Module_Request_Router'); |
|
| 293 | + } |
|
| 294 | + EE_Module_Request_Router::module_factory($module); |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * @param string $module_name |
|
| 302 | + * @return mixed EED_Module | NULL |
|
| 303 | + */ |
|
| 304 | + public function get_module($module_name = '') |
|
| 305 | + { |
|
| 306 | + return isset($this->modules->{$module_name}) |
|
| 307 | + ? $this->modules->{$module_name} |
|
| 308 | + : null; |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * loads core classes - must be singletons |
|
| 315 | + * |
|
| 316 | + * @param string $class_name - simple class name ie: session |
|
| 317 | + * @param mixed $arguments |
|
| 318 | + * @param bool $load_only |
|
| 319 | + * @return mixed |
|
| 320 | + * @throws EE_Error |
|
| 321 | + * @throws ReflectionException |
|
| 322 | + */ |
|
| 323 | + public function load_core($class_name, $arguments = array(), $load_only = false) |
|
| 324 | + { |
|
| 325 | + $core_paths = apply_filters( |
|
| 326 | + 'FHEE__EE_Registry__load_core__core_paths', |
|
| 327 | + array( |
|
| 328 | + EE_CORE, |
|
| 329 | + EE_ADMIN, |
|
| 330 | + EE_CPTS, |
|
| 331 | + EE_CORE . 'data_migration_scripts' . DS, |
|
| 332 | + EE_CORE . 'capabilities' . DS, |
|
| 333 | + EE_CORE . 'request_stack' . DS, |
|
| 334 | + EE_CORE . 'middleware' . DS, |
|
| 335 | + ) |
|
| 336 | + ); |
|
| 337 | + // retrieve instantiated class |
|
| 338 | + return $this->_load( |
|
| 339 | + $core_paths, |
|
| 340 | + 'EE_', |
|
| 341 | + $class_name, |
|
| 342 | + 'core', |
|
| 343 | + $arguments, |
|
| 344 | + false, |
|
| 345 | + true, |
|
| 346 | + $load_only |
|
| 347 | + ); |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * loads service classes |
|
| 354 | + * |
|
| 355 | + * @param string $class_name - simple class name ie: session |
|
| 356 | + * @param mixed $arguments |
|
| 357 | + * @param bool $load_only |
|
| 358 | + * @return mixed |
|
| 359 | + * @throws EE_Error |
|
| 360 | + * @throws ReflectionException |
|
| 361 | + */ |
|
| 362 | + public function load_service($class_name, $arguments = array(), $load_only = false) |
|
| 363 | + { |
|
| 364 | + $service_paths = apply_filters( |
|
| 365 | + 'FHEE__EE_Registry__load_service__service_paths', |
|
| 366 | + array( |
|
| 367 | + EE_CORE . 'services' . DS, |
|
| 368 | + ) |
|
| 369 | + ); |
|
| 370 | + // retrieve instantiated class |
|
| 371 | + return $this->_load( |
|
| 372 | + $service_paths, |
|
| 373 | + 'EE_', |
|
| 374 | + $class_name, |
|
| 375 | + 'class', |
|
| 376 | + $arguments, |
|
| 377 | + false, |
|
| 378 | + true, |
|
| 379 | + $load_only |
|
| 380 | + ); |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * loads data_migration_scripts |
|
| 387 | + * |
|
| 388 | + * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
| 389 | + * @param mixed $arguments |
|
| 390 | + * @return EE_Data_Migration_Script_Base|mixed |
|
| 391 | + * @throws EE_Error |
|
| 392 | + * @throws ReflectionException |
|
| 393 | + */ |
|
| 394 | + public function load_dms($class_name, $arguments = array()) |
|
| 395 | + { |
|
| 396 | + // retrieve instantiated class |
|
| 397 | + return $this->_load( |
|
| 398 | + EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), |
|
| 399 | + 'EE_DMS_', |
|
| 400 | + $class_name, |
|
| 401 | + 'dms', |
|
| 402 | + $arguments, |
|
| 403 | + false, |
|
| 404 | + false |
|
| 405 | + ); |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * loads object creating classes - must be singletons |
|
| 412 | + * |
|
| 413 | + * @param string $class_name - simple class name ie: attendee |
|
| 414 | + * @param mixed $arguments - an array of arguments to pass to the class |
|
| 415 | + * @param bool $from_db - some classes are instantiated from the db and thus call a different method to |
|
| 416 | + * instantiate |
|
| 417 | + * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then |
|
| 418 | + * set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
| 419 | + * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate |
|
| 420 | + * (default) |
|
| 421 | + * @return EE_Base_Class | bool |
|
| 422 | + * @throws EE_Error |
|
| 423 | + * @throws ReflectionException |
|
| 424 | + */ |
|
| 425 | + public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
| 426 | + { |
|
| 427 | + $paths = apply_filters( |
|
| 428 | + 'FHEE__EE_Registry__load_class__paths', array( |
|
| 429 | + EE_CORE, |
|
| 430 | + EE_CLASSES, |
|
| 431 | + EE_BUSINESS, |
|
| 432 | + ) |
|
| 433 | + ); |
|
| 434 | + // retrieve instantiated class |
|
| 435 | + return $this->_load( |
|
| 436 | + $paths, |
|
| 437 | + 'EE_', |
|
| 438 | + $class_name, |
|
| 439 | + 'class', |
|
| 440 | + $arguments, |
|
| 441 | + $from_db, |
|
| 442 | + $cache, |
|
| 443 | + $load_only |
|
| 444 | + ); |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + |
|
| 448 | + |
|
| 449 | + /** |
|
| 450 | + * loads helper classes - must be singletons |
|
| 451 | + * |
|
| 452 | + * @param string $class_name - simple class name ie: price |
|
| 453 | + * @param mixed $arguments |
|
| 454 | + * @param bool $load_only |
|
| 455 | + * @return EEH_Base | bool |
|
| 456 | + * @throws EE_Error |
|
| 457 | + * @throws ReflectionException |
|
| 458 | + */ |
|
| 459 | + public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
| 460 | + { |
|
| 461 | + // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
| 462 | + $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
| 463 | + // retrieve instantiated class |
|
| 464 | + return $this->_load( |
|
| 465 | + $helper_paths, |
|
| 466 | + 'EEH_', |
|
| 467 | + $class_name, |
|
| 468 | + 'helper', |
|
| 469 | + $arguments, |
|
| 470 | + false, |
|
| 471 | + true, |
|
| 472 | + $load_only |
|
| 473 | + ); |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + |
|
| 477 | + |
|
| 478 | + /** |
|
| 479 | + * loads core classes - must be singletons |
|
| 480 | + * |
|
| 481 | + * @param string $class_name - simple class name ie: session |
|
| 482 | + * @param mixed $arguments |
|
| 483 | + * @param bool $load_only |
|
| 484 | + * @param bool $cache whether to cache the object or not. |
|
| 485 | + * @return mixed |
|
| 486 | + * @throws EE_Error |
|
| 487 | + * @throws ReflectionException |
|
| 488 | + */ |
|
| 489 | + public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
| 490 | + { |
|
| 491 | + $paths = array( |
|
| 492 | + EE_LIBRARIES, |
|
| 493 | + EE_LIBRARIES . 'messages' . DS, |
|
| 494 | + EE_LIBRARIES . 'shortcodes' . DS, |
|
| 495 | + EE_LIBRARIES . 'qtips' . DS, |
|
| 496 | + EE_LIBRARIES . 'payment_methods' . DS, |
|
| 497 | + ); |
|
| 498 | + // retrieve instantiated class |
|
| 499 | + return $this->_load( |
|
| 500 | + $paths, |
|
| 501 | + 'EE_', |
|
| 502 | + $class_name, |
|
| 503 | + 'lib', |
|
| 504 | + $arguments, |
|
| 505 | + false, |
|
| 506 | + $cache, |
|
| 507 | + $load_only |
|
| 508 | + ); |
|
| 509 | + } |
|
| 510 | + |
|
| 511 | + |
|
| 512 | + |
|
| 513 | + /** |
|
| 514 | + * loads model classes - must be singletons |
|
| 515 | + * |
|
| 516 | + * @param string $class_name - simple class name ie: price |
|
| 517 | + * @param mixed $arguments |
|
| 518 | + * @param bool $load_only |
|
| 519 | + * @return EEM_Base | bool |
|
| 520 | + * @throws EE_Error |
|
| 521 | + * @throws ReflectionException |
|
| 522 | + */ |
|
| 523 | + public function load_model($class_name, $arguments = array(), $load_only = false) |
|
| 524 | + { |
|
| 525 | + $paths = apply_filters( |
|
| 526 | + 'FHEE__EE_Registry__load_model__paths', array( |
|
| 527 | + EE_MODELS, |
|
| 528 | + EE_CORE, |
|
| 529 | + ) |
|
| 530 | + ); |
|
| 531 | + // retrieve instantiated class |
|
| 532 | + return $this->_load( |
|
| 533 | + $paths, |
|
| 534 | + 'EEM_', |
|
| 535 | + $class_name, |
|
| 536 | + 'model', |
|
| 537 | + $arguments, |
|
| 538 | + false, |
|
| 539 | + true, |
|
| 540 | + $load_only |
|
| 541 | + ); |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * loads model classes - must be singletons |
|
| 548 | + * |
|
| 549 | + * @param string $class_name - simple class name ie: price |
|
| 550 | + * @param mixed $arguments |
|
| 551 | + * @param bool $load_only |
|
| 552 | + * @return mixed | bool |
|
| 553 | + * @throws EE_Error |
|
| 554 | + * @throws ReflectionException |
|
| 555 | + */ |
|
| 556 | + public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
| 557 | + { |
|
| 558 | + $paths = array( |
|
| 559 | + EE_MODELS . 'fields' . DS, |
|
| 560 | + EE_MODELS . 'helpers' . DS, |
|
| 561 | + EE_MODELS . 'relations' . DS, |
|
| 562 | + EE_MODELS . 'strategies' . DS, |
|
| 563 | + ); |
|
| 564 | + // retrieve instantiated class |
|
| 565 | + return $this->_load( |
|
| 566 | + $paths, |
|
| 567 | + 'EE_', |
|
| 568 | + $class_name, |
|
| 569 | + '', |
|
| 570 | + $arguments, |
|
| 571 | + false, |
|
| 572 | + true, |
|
| 573 | + $load_only |
|
| 574 | + ); |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + |
|
| 578 | + |
|
| 579 | + /** |
|
| 580 | + * Determines if $model_name is the name of an actual EE model. |
|
| 581 | + * |
|
| 582 | + * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
| 583 | + * @return boolean |
|
| 584 | + */ |
|
| 585 | + public function is_model_name($model_name) |
|
| 586 | + { |
|
| 587 | + return isset($this->models[$model_name]); |
|
| 588 | + } |
|
| 589 | + |
|
| 590 | + |
|
| 591 | + |
|
| 592 | + /** |
|
| 593 | + * generic class loader |
|
| 594 | + * |
|
| 595 | + * @param string $path_to_file - directory path to file location, not including filename |
|
| 596 | + * @param string $file_name - file name ie: my_file.php, including extension |
|
| 597 | + * @param string $type - file type - core? class? helper? model? |
|
| 598 | + * @param mixed $arguments |
|
| 599 | + * @param bool $load_only |
|
| 600 | + * @return mixed |
|
| 601 | + * @throws EE_Error |
|
| 602 | + * @throws ReflectionException |
|
| 603 | + */ |
|
| 604 | + public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
| 605 | + { |
|
| 606 | + // retrieve instantiated class |
|
| 607 | + return $this->_load( |
|
| 608 | + $path_to_file, |
|
| 609 | + '', |
|
| 610 | + $file_name, |
|
| 611 | + $type, |
|
| 612 | + $arguments, |
|
| 613 | + false, |
|
| 614 | + true, |
|
| 615 | + $load_only |
|
| 616 | + ); |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + |
|
| 620 | + |
|
| 621 | + /** |
|
| 622 | + * @param string $path_to_file - directory path to file location, not including filename |
|
| 623 | + * @param string $class_name - full class name ie: My_Class |
|
| 624 | + * @param string $type - file type - core? class? helper? model? |
|
| 625 | + * @param mixed $arguments |
|
| 626 | + * @param bool $load_only |
|
| 627 | + * @return bool|EE_Addon|object |
|
| 628 | + * @throws EE_Error |
|
| 629 | + * @throws ReflectionException |
|
| 630 | + */ |
|
| 631 | + public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
| 632 | + { |
|
| 633 | + // retrieve instantiated class |
|
| 634 | + return $this->_load( |
|
| 635 | + $path_to_file, |
|
| 636 | + 'addon', |
|
| 637 | + $class_name, |
|
| 638 | + $type, |
|
| 639 | + $arguments, |
|
| 640 | + false, |
|
| 641 | + true, |
|
| 642 | + $load_only |
|
| 643 | + ); |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + |
|
| 647 | + |
|
| 648 | + /** |
|
| 649 | + * instantiates, caches, and automatically resolves dependencies |
|
| 650 | + * for classes that use a Fully Qualified Class Name. |
|
| 651 | + * if the class is not capable of being loaded using PSR-4 autoloading, |
|
| 652 | + * then you need to use one of the existing load_*() methods |
|
| 653 | + * which can resolve the classname and filepath from the passed arguments |
|
| 654 | + * |
|
| 655 | + * @param bool|string $class_name Fully Qualified Class Name |
|
| 656 | + * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
| 657 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
| 658 | + * @param bool $from_db some classes are instantiated from the db |
|
| 659 | + * and thus call a different method to instantiate |
|
| 660 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
| 661 | + * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
| 662 | + * @return bool|null|mixed null = failure to load or instantiate class object. |
|
| 663 | + * object = class loaded and instantiated successfully. |
|
| 664 | + * bool = fail or success when $load_only is true |
|
| 665 | + * @throws EE_Error |
|
| 666 | + * @throws ReflectionException |
|
| 667 | + */ |
|
| 668 | + public function create( |
|
| 669 | + $class_name = false, |
|
| 670 | + $arguments = array(), |
|
| 671 | + $cache = false, |
|
| 672 | + $from_db = false, |
|
| 673 | + $load_only = false, |
|
| 674 | + $addon = false |
|
| 675 | + ) { |
|
| 676 | + $class_name = ltrim($class_name, '\\'); |
|
| 677 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
| 678 | + $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments); |
|
| 679 | + // if a non-FQCN was passed, then verifyClassExists() might return an object |
|
| 680 | + // or it could return null if the class just could not be found anywhere |
|
| 681 | + if ($class_exists instanceof $class_name || $class_exists === null){ |
|
| 682 | + // either way, return the results |
|
| 683 | + return $class_exists; |
|
| 684 | + } |
|
| 685 | + $class_name = $class_exists; |
|
| 686 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
| 687 | + if ($load_only) { |
|
| 688 | + return true; |
|
| 689 | + } |
|
| 690 | + $addon = $addon |
|
| 691 | + ? 'addon' |
|
| 692 | + : ''; |
|
| 693 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
| 694 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
| 695 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
| 696 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
| 697 | + // return object if it's already cached |
|
| 698 | + $cached_class = $this->_get_cached_class($class_name, $addon); |
|
| 699 | + if ($cached_class !== null) { |
|
| 700 | + return $cached_class; |
|
| 701 | + } |
|
| 702 | + } |
|
| 703 | + // obtain the loader method from the dependency map |
|
| 704 | + $loader = $this->_dependency_map->class_loader($class_name); |
|
| 705 | + // instantiate the requested object |
|
| 706 | + if ($loader instanceof Closure) { |
|
| 707 | + $class_obj = $loader($arguments); |
|
| 708 | + } else if ($loader && method_exists($this, $loader)) { |
|
| 709 | + $class_obj = $this->{$loader}($class_name, $arguments); |
|
| 710 | + } else { |
|
| 711 | + $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
| 712 | + } |
|
| 713 | + if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) { |
|
| 714 | + // save it for later... kinda like gum { : $ |
|
| 715 | + $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
| 716 | + } |
|
| 717 | + $this->_cache_on = true; |
|
| 718 | + return $class_obj; |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + |
|
| 722 | + |
|
| 723 | + /** |
|
| 724 | + * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs |
|
| 725 | + * |
|
| 726 | + * @param string $class_name |
|
| 727 | + * @param array $arguments |
|
| 728 | + * @param int $attempt |
|
| 729 | + * @return mixed |
|
| 730 | + */ |
|
| 731 | + private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) { |
|
| 732 | + if (is_object($class_name) || class_exists($class_name)) { |
|
| 733 | + return $class_name; |
|
| 734 | + } |
|
| 735 | + switch ($attempt) { |
|
| 736 | + case 1: |
|
| 737 | + // if it's a FQCN then maybe the class is registered with a preceding \ |
|
| 738 | + $class_name = strpos($class_name, '\\') !== false |
|
| 739 | + ? '\\' . ltrim($class_name, '\\') |
|
| 740 | + : $class_name; |
|
| 741 | + break; |
|
| 742 | + case 2: |
|
| 743 | + // |
|
| 744 | + $loader = $this->_dependency_map->class_loader($class_name); |
|
| 745 | + if ($loader && method_exists($this, $loader)) { |
|
| 746 | + return $this->{$loader}($class_name, $arguments); |
|
| 747 | + } |
|
| 748 | + break; |
|
| 749 | + case 3: |
|
| 750 | + default; |
|
| 751 | + return null; |
|
| 752 | + } |
|
| 753 | + $attempt++; |
|
| 754 | + return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt); |
|
| 755 | + } |
|
| 756 | + |
|
| 757 | + |
|
| 758 | + |
|
| 759 | + /** |
|
| 760 | + * instantiates, caches, and injects dependencies for classes |
|
| 761 | + * |
|
| 762 | + * @param array $file_paths an array of paths to folders to look in |
|
| 763 | + * @param string $class_prefix EE or EEM or... ??? |
|
| 764 | + * @param bool|string $class_name $class name |
|
| 765 | + * @param string $type file type - core? class? helper? model? |
|
| 766 | + * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
| 767 | + * @param bool $from_db some classes are instantiated from the db |
|
| 768 | + * and thus call a different method to instantiate |
|
| 769 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
| 770 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
| 771 | + * @return bool|null|object null = failure to load or instantiate class object. |
|
| 772 | + * object = class loaded and instantiated successfully. |
|
| 773 | + * bool = fail or success when $load_only is true |
|
| 774 | + * @throws EE_Error |
|
| 775 | + * @throws ReflectionException |
|
| 776 | + */ |
|
| 777 | + protected function _load( |
|
| 778 | + $file_paths = array(), |
|
| 779 | + $class_prefix = 'EE_', |
|
| 780 | + $class_name = false, |
|
| 781 | + $type = 'class', |
|
| 782 | + $arguments = array(), |
|
| 783 | + $from_db = false, |
|
| 784 | + $cache = true, |
|
| 785 | + $load_only = false |
|
| 786 | + ) { |
|
| 787 | + $class_name = ltrim($class_name, '\\'); |
|
| 788 | + // strip php file extension |
|
| 789 | + $class_name = str_replace('.php', '', trim($class_name)); |
|
| 790 | + // does the class have a prefix ? |
|
| 791 | + if (! empty($class_prefix) && $class_prefix !== 'addon') { |
|
| 792 | + // make sure $class_prefix is uppercase |
|
| 793 | + $class_prefix = strtoupper(trim($class_prefix)); |
|
| 794 | + // add class prefix ONCE!!! |
|
| 795 | + $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
| 796 | + } |
|
| 797 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
| 798 | + $class_exists = class_exists($class_name); |
|
| 799 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
| 800 | + if ($load_only && $class_exists) { |
|
| 801 | + return true; |
|
| 802 | + } |
|
| 803 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
| 804 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
| 805 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
| 806 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
| 807 | + // return object if it's already cached |
|
| 808 | + $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
| 809 | + if ($cached_class !== null) { |
|
| 810 | + return $cached_class; |
|
| 811 | + } |
|
| 812 | + } |
|
| 813 | + // if the class doesn't already exist.. then we need to try and find the file and load it |
|
| 814 | + if (! $class_exists) { |
|
| 815 | + // get full path to file |
|
| 816 | + $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
| 817 | + // load the file |
|
| 818 | + $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
| 819 | + // if loading failed, or we are only loading a file but NOT instantiating an object |
|
| 820 | + if (! $loaded || $load_only) { |
|
| 821 | + // return boolean if only loading, or null if an object was expected |
|
| 822 | + return $load_only |
|
| 823 | + ? $loaded |
|
| 824 | + : null; |
|
| 825 | + } |
|
| 826 | + } |
|
| 827 | + // instantiate the requested object |
|
| 828 | + $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
| 829 | + if ($this->_cache_on && $cache) { |
|
| 830 | + // save it for later... kinda like gum { : $ |
|
| 831 | + $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
| 832 | + } |
|
| 833 | + $this->_cache_on = true; |
|
| 834 | + return $class_obj; |
|
| 835 | + } |
|
| 836 | + |
|
| 837 | + |
|
| 838 | + |
|
| 839 | + /** |
|
| 840 | + * @param string $class_name |
|
| 841 | + * @param string $default have to specify something, but not anything that will conflict |
|
| 842 | + * @return mixed|string |
|
| 843 | + */ |
|
| 844 | + protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS') |
|
| 845 | + { |
|
| 846 | + return isset($this->_class_abbreviations[$class_name]) |
|
| 847 | + ? $this->_class_abbreviations[$class_name] |
|
| 848 | + : $default; |
|
| 849 | + } |
|
| 850 | + |
|
| 851 | + /** |
|
| 852 | + * attempts to find a cached version of the requested class |
|
| 853 | + * by looking in the following places: |
|
| 854 | + * $this->{$class_abbreviation} ie: $this->CART |
|
| 855 | + * $this->{$class_name} ie: $this->Some_Class |
|
| 856 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
| 857 | + * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
| 858 | + * |
|
| 859 | + * @param string $class_name |
|
| 860 | + * @param string $class_prefix |
|
| 861 | + * @return mixed |
|
| 862 | + */ |
|
| 863 | + protected function _get_cached_class($class_name, $class_prefix = '') |
|
| 864 | + { |
|
| 865 | + if ($class_name === 'EE_Registry') { |
|
| 866 | + return $this; |
|
| 867 | + } |
|
| 868 | + $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
| 869 | + $class_name = str_replace('\\', '_', $class_name); |
|
| 870 | + // check if class has already been loaded, and return it if it has been |
|
| 871 | + if (isset($this->{$class_abbreviation})) { |
|
| 872 | + return $this->{$class_abbreviation}; |
|
| 873 | + } |
|
| 874 | + if (isset ($this->{$class_name})) { |
|
| 875 | + return $this->{$class_name}; |
|
| 876 | + } |
|
| 877 | + if (isset ($this->LIB->{$class_name})) { |
|
| 878 | + return $this->LIB->{$class_name}; |
|
| 879 | + } |
|
| 880 | + if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) { |
|
| 881 | + return $this->addons->{$class_name}; |
|
| 882 | + } |
|
| 883 | + return null; |
|
| 884 | + } |
|
| 885 | + |
|
| 886 | + |
|
| 887 | + |
|
| 888 | + /** |
|
| 889 | + * removes a cached version of the requested class |
|
| 890 | + * |
|
| 891 | + * @param string $class_name |
|
| 892 | + * @param boolean $addon |
|
| 893 | + * @return boolean |
|
| 894 | + */ |
|
| 895 | + public function clear_cached_class($class_name, $addon = false) |
|
| 896 | + { |
|
| 897 | + $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
| 898 | + $class_name = str_replace('\\', '_', $class_name); |
|
| 899 | + // check if class has already been loaded, and return it if it has been |
|
| 900 | + if (isset($this->{$class_abbreviation})) { |
|
| 901 | + $this->{$class_abbreviation} = null; |
|
| 902 | + return true; |
|
| 903 | + } |
|
| 904 | + if (isset($this->{$class_name})) { |
|
| 905 | + $this->{$class_name} = null; |
|
| 906 | + return true; |
|
| 907 | + } |
|
| 908 | + if (isset($this->LIB->{$class_name})) { |
|
| 909 | + unset($this->LIB->{$class_name}); |
|
| 910 | + return true; |
|
| 911 | + } |
|
| 912 | + if ($addon && isset($this->addons->{$class_name})) { |
|
| 913 | + unset($this->addons->{$class_name}); |
|
| 914 | + return true; |
|
| 915 | + } |
|
| 916 | + return false; |
|
| 917 | + } |
|
| 918 | + |
|
| 919 | + |
|
| 920 | + |
|
| 921 | + /** |
|
| 922 | + * attempts to find a full valid filepath for the requested class. |
|
| 923 | + * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
| 924 | + * then returns that path if the target file has been found and is readable |
|
| 925 | + * |
|
| 926 | + * @param string $class_name |
|
| 927 | + * @param string $type |
|
| 928 | + * @param array $file_paths |
|
| 929 | + * @return string | bool |
|
| 930 | + */ |
|
| 931 | + protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
| 932 | + { |
|
| 933 | + // make sure $file_paths is an array |
|
| 934 | + $file_paths = is_array($file_paths) |
|
| 935 | + ? $file_paths |
|
| 936 | + : array($file_paths); |
|
| 937 | + // cycle thru paths |
|
| 938 | + foreach ($file_paths as $key => $file_path) { |
|
| 939 | + // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
| 940 | + $file_path = $file_path |
|
| 941 | + ? str_replace(array('/', '\\'), DS, $file_path) |
|
| 942 | + : EE_CLASSES; |
|
| 943 | + // prep file type |
|
| 944 | + $type = ! empty($type) |
|
| 945 | + ? trim($type, '.') . '.' |
|
| 946 | + : ''; |
|
| 947 | + // build full file path |
|
| 948 | + $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
| 949 | + //does the file exist and can be read ? |
|
| 950 | + if (is_readable($file_paths[$key])) { |
|
| 951 | + return $file_paths[$key]; |
|
| 952 | + } |
|
| 953 | + } |
|
| 954 | + return false; |
|
| 955 | + } |
|
| 956 | + |
|
| 957 | + |
|
| 958 | + |
|
| 959 | + /** |
|
| 960 | + * basically just performs a require_once() |
|
| 961 | + * but with some error handling |
|
| 962 | + * |
|
| 963 | + * @param string $path |
|
| 964 | + * @param string $class_name |
|
| 965 | + * @param string $type |
|
| 966 | + * @param array $file_paths |
|
| 967 | + * @return bool |
|
| 968 | + * @throws EE_Error |
|
| 969 | + * @throws ReflectionException |
|
| 970 | + */ |
|
| 971 | + protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
| 972 | + { |
|
| 973 | + // don't give up! you gotta... |
|
| 974 | + try { |
|
| 975 | + //does the file exist and can it be read ? |
|
| 976 | + if (! $path) { |
|
| 977 | + // so sorry, can't find the file |
|
| 978 | + throw new EE_Error ( |
|
| 979 | + sprintf( |
|
| 980 | + esc_html__( |
|
| 981 | + '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', |
|
| 982 | + 'event_espresso' |
|
| 983 | + ), |
|
| 984 | + trim($type, '.'), |
|
| 985 | + $class_name, |
|
| 986 | + '<br />' . implode(',<br />', $file_paths) |
|
| 987 | + ) |
|
| 988 | + ); |
|
| 989 | + } |
|
| 990 | + // get the file |
|
| 991 | + require_once($path); |
|
| 992 | + // if the class isn't already declared somewhere |
|
| 993 | + if (class_exists($class_name, false) === false) { |
|
| 994 | + // so sorry, not a class |
|
| 995 | + throw new EE_Error( |
|
| 996 | + sprintf( |
|
| 997 | + esc_html__('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
| 998 | + $type, |
|
| 999 | + $path, |
|
| 1000 | + $class_name |
|
| 1001 | + ) |
|
| 1002 | + ); |
|
| 1003 | + } |
|
| 1004 | + } catch (EE_Error $e) { |
|
| 1005 | + $e->get_error(); |
|
| 1006 | + return false; |
|
| 1007 | + } |
|
| 1008 | + return true; |
|
| 1009 | + } |
|
| 1010 | + |
|
| 1011 | + |
|
| 1012 | + |
|
| 1013 | + /** |
|
| 1014 | + * _create_object |
|
| 1015 | + * Attempts to instantiate the requested class via any of the |
|
| 1016 | + * commonly used instantiation methods employed throughout EE. |
|
| 1017 | + * The priority for instantiation is as follows: |
|
| 1018 | + * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
| 1019 | + * - model objects via their 'new_instance_from_db' method |
|
| 1020 | + * - model objects via their 'new_instance' method |
|
| 1021 | + * - "singleton" classes" via their 'instance' method |
|
| 1022 | + * - standard instantiable classes via their __constructor |
|
| 1023 | + * Prior to instantiation, if the classname exists in the dependency_map, |
|
| 1024 | + * then the constructor for the requested class will be examined to determine |
|
| 1025 | + * if any dependencies exist, and if they can be injected. |
|
| 1026 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
| 1027 | + * |
|
| 1028 | + * @param string $class_name |
|
| 1029 | + * @param array $arguments |
|
| 1030 | + * @param string $type |
|
| 1031 | + * @param bool $from_db |
|
| 1032 | + * @return null|object |
|
| 1033 | + * @throws EE_Error |
|
| 1034 | + * @throws ReflectionException |
|
| 1035 | + */ |
|
| 1036 | + protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
| 1037 | + { |
|
| 1038 | + // create reflection |
|
| 1039 | + $reflector = $this->get_ReflectionClass($class_name); |
|
| 1040 | + // make sure arguments are an array |
|
| 1041 | + $arguments = is_array($arguments) |
|
| 1042 | + ? $arguments |
|
| 1043 | + : array($arguments); |
|
| 1044 | + // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
| 1045 | + // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
| 1046 | + $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
| 1047 | + ? $arguments |
|
| 1048 | + : array($arguments); |
|
| 1049 | + // attempt to inject dependencies ? |
|
| 1050 | + if ($this->_dependency_map->has($class_name)) { |
|
| 1051 | + $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
| 1052 | + } |
|
| 1053 | + // instantiate the class if possible |
|
| 1054 | + if ($reflector->isAbstract()) { |
|
| 1055 | + // nothing to instantiate, loading file was enough |
|
| 1056 | + // does not throw an exception so $instantiation_mode is unused |
|
| 1057 | + // $instantiation_mode = "1) no constructor abstract class"; |
|
| 1058 | + return true; |
|
| 1059 | + } |
|
| 1060 | + if (empty($arguments) && $reflector->getConstructor() === null && $reflector->isInstantiable()) { |
|
| 1061 | + // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
| 1062 | + // $instantiation_mode = "2) no constructor but instantiable"; |
|
| 1063 | + return $reflector->newInstance(); |
|
| 1064 | + } |
|
| 1065 | + if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
| 1066 | + // $instantiation_mode = "3) new_instance_from_db()"; |
|
| 1067 | + return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
| 1068 | + } |
|
| 1069 | + if (method_exists($class_name, 'new_instance')) { |
|
| 1070 | + // $instantiation_mode = "4) new_instance()"; |
|
| 1071 | + return call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
| 1072 | + } |
|
| 1073 | + if (method_exists($class_name, 'instance')) { |
|
| 1074 | + // $instantiation_mode = "5) instance()"; |
|
| 1075 | + return call_user_func_array(array($class_name, 'instance'), $arguments); |
|
| 1076 | + } |
|
| 1077 | + if ($reflector->isInstantiable()) { |
|
| 1078 | + // $instantiation_mode = "6) constructor"; |
|
| 1079 | + return $reflector->newInstanceArgs($arguments); |
|
| 1080 | + } |
|
| 1081 | + // heh ? something's not right ! |
|
| 1082 | + throw new EE_Error( |
|
| 1083 | + sprintf( |
|
| 1084 | + __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
| 1085 | + $type, |
|
| 1086 | + $class_name |
|
| 1087 | + ) |
|
| 1088 | + ); |
|
| 1089 | + } |
|
| 1090 | + |
|
| 1091 | + |
|
| 1092 | + |
|
| 1093 | + /** |
|
| 1094 | + * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
| 1095 | + * @param array $array |
|
| 1096 | + * @return bool |
|
| 1097 | + */ |
|
| 1098 | + protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
| 1099 | + { |
|
| 1100 | + return ! empty($array) |
|
| 1101 | + ? array_keys($array) === range(0, count($array) - 1) |
|
| 1102 | + : true; |
|
| 1103 | + } |
|
| 1104 | + |
|
| 1105 | + |
|
| 1106 | + |
|
| 1107 | + /** |
|
| 1108 | + * getReflectionClass |
|
| 1109 | + * checks if a ReflectionClass object has already been generated for a class |
|
| 1110 | + * and returns that instead of creating a new one |
|
| 1111 | + * |
|
| 1112 | + * @param string $class_name |
|
| 1113 | + * @return ReflectionClass |
|
| 1114 | + * @throws ReflectionException |
|
| 1115 | + */ |
|
| 1116 | + public function get_ReflectionClass($class_name) |
|
| 1117 | + { |
|
| 1118 | + if ( |
|
| 1119 | + ! isset($this->_reflectors[$class_name]) |
|
| 1120 | + || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
| 1121 | + ) { |
|
| 1122 | + $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
| 1123 | + } |
|
| 1124 | + return $this->_reflectors[$class_name]; |
|
| 1125 | + } |
|
| 1126 | + |
|
| 1127 | + |
|
| 1128 | + |
|
| 1129 | + /** |
|
| 1130 | + * _resolve_dependencies |
|
| 1131 | + * examines the constructor for the requested class to determine |
|
| 1132 | + * if any dependencies exist, and if they can be injected. |
|
| 1133 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
| 1134 | + * PLZ NOTE: this is achieved by type hinting the constructor params |
|
| 1135 | + * For example: |
|
| 1136 | + * if attempting to load a class "Foo" with the following constructor: |
|
| 1137 | + * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
| 1138 | + * then $bar_class and $grohl_class will be added to the $arguments array, |
|
| 1139 | + * but only IF they are NOT already present in the incoming arguments array, |
|
| 1140 | + * and the correct classes can be loaded |
|
| 1141 | + * |
|
| 1142 | + * @param ReflectionClass $reflector |
|
| 1143 | + * @param string $class_name |
|
| 1144 | + * @param array $arguments |
|
| 1145 | + * @return array |
|
| 1146 | + * @throws EE_Error |
|
| 1147 | + * @throws ReflectionException |
|
| 1148 | + */ |
|
| 1149 | + protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
|
| 1150 | + { |
|
| 1151 | + // let's examine the constructor |
|
| 1152 | + $constructor = $reflector->getConstructor(); |
|
| 1153 | + // whu? huh? nothing? |
|
| 1154 | + if (! $constructor) { |
|
| 1155 | + return $arguments; |
|
| 1156 | + } |
|
| 1157 | + // get constructor parameters |
|
| 1158 | + $params = $constructor->getParameters(); |
|
| 1159 | + // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
| 1160 | + $argument_keys = array_keys($arguments); |
|
| 1161 | + // now loop thru all of the constructors expected parameters |
|
| 1162 | + foreach ($params as $index => $param) { |
|
| 1163 | + // is this a dependency for a specific class ? |
|
| 1164 | + $param_class = $param->getClass() |
|
| 1165 | + ? $param->getClass()->name |
|
| 1166 | + : null; |
|
| 1167 | + // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime) |
|
| 1168 | + $param_class = $this->_dependency_map->has_alias($param_class, $class_name) |
|
| 1169 | + ? $this->_dependency_map->get_alias($param_class, $class_name) |
|
| 1170 | + : $param_class; |
|
| 1171 | + if ( |
|
| 1172 | + // param is not even a class |
|
| 1173 | + $param_class === null |
|
| 1174 | + // and something already exists in the incoming arguments for this param |
|
| 1175 | + && array_key_exists($index, $argument_keys) |
|
| 1176 | + && array_key_exists($argument_keys[$index], $arguments) |
|
| 1177 | + ) { |
|
| 1178 | + // so let's skip this argument and move on to the next |
|
| 1179 | + continue; |
|
| 1180 | + } |
|
| 1181 | + if ( |
|
| 1182 | + // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
| 1183 | + $param_class !== null |
|
| 1184 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
| 1185 | + && $arguments[$argument_keys[$index]] instanceof $param_class |
|
| 1186 | + ) { |
|
| 1187 | + // skip this argument and move on to the next |
|
| 1188 | + continue; |
|
| 1189 | + } |
|
| 1190 | + if ( |
|
| 1191 | + // parameter is type hinted as a class, and should be injected |
|
| 1192 | + $param_class !== null |
|
| 1193 | + && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
| 1194 | + ) { |
|
| 1195 | + $arguments = $this->_resolve_dependency( |
|
| 1196 | + $class_name, |
|
| 1197 | + $param_class, |
|
| 1198 | + $arguments, |
|
| 1199 | + $index, |
|
| 1200 | + $argument_keys |
|
| 1201 | + ); |
|
| 1202 | + } else { |
|
| 1203 | + try { |
|
| 1204 | + $arguments[$index] = $param->isDefaultValueAvailable() |
|
| 1205 | + ? $param->getDefaultValue() |
|
| 1206 | + : null; |
|
| 1207 | + } catch (ReflectionException $e) { |
|
| 1208 | + throw new ReflectionException( |
|
| 1209 | + sprintf( |
|
| 1210 | + esc_html__('%1$s for parameter "$%2$s on classname "%3$s"', 'event_espresso'), |
|
| 1211 | + $e->getMessage(), |
|
| 1212 | + $param->getName(), |
|
| 1213 | + $class_name |
|
| 1214 | + ) |
|
| 1215 | + ); |
|
| 1216 | + } |
|
| 1217 | + } |
|
| 1218 | + } |
|
| 1219 | + return $arguments; |
|
| 1220 | + } |
|
| 1221 | + |
|
| 1222 | + |
|
| 1223 | + |
|
| 1224 | + /** |
|
| 1225 | + * @param string $class_name |
|
| 1226 | + * @param string $param_class |
|
| 1227 | + * @param array $arguments |
|
| 1228 | + * @param mixed $index |
|
| 1229 | + * @param array $argument_keys |
|
| 1230 | + * @return array |
|
| 1231 | + * @throws EE_Error |
|
| 1232 | + * @throws ReflectionException |
|
| 1233 | + * @throws InvalidArgumentException |
|
| 1234 | + * @throws InvalidInterfaceException |
|
| 1235 | + * @throws InvalidDataTypeException |
|
| 1236 | + */ |
|
| 1237 | + protected function _resolve_dependency($class_name, $param_class, $arguments, $index, array $argument_keys) |
|
| 1238 | + { |
|
| 1239 | + $dependency = null; |
|
| 1240 | + // should dependency be loaded from cache ? |
|
| 1241 | + $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency( |
|
| 1242 | + $class_name, |
|
| 1243 | + $param_class |
|
| 1244 | + ); |
|
| 1245 | + $cache_on = $cache_on !== EE_Dependency_Map::load_new_object; |
|
| 1246 | + // we might have a dependency... |
|
| 1247 | + // let's MAYBE try and find it in our cache if that's what's been requested |
|
| 1248 | + $cached_class = $cache_on |
|
| 1249 | + ? $this->_get_cached_class($param_class) |
|
| 1250 | + : null; |
|
| 1251 | + // and grab it if it exists |
|
| 1252 | + if ($cached_class instanceof $param_class) { |
|
| 1253 | + $dependency = $cached_class; |
|
| 1254 | + } else if ($param_class !== $class_name) { |
|
| 1255 | + // obtain the loader method from the dependency map |
|
| 1256 | + $loader = $this->_dependency_map->class_loader($param_class); |
|
| 1257 | + // is loader a custom closure ? |
|
| 1258 | + if ($loader instanceof Closure) { |
|
| 1259 | + $dependency = $loader($arguments); |
|
| 1260 | + } else { |
|
| 1261 | + // set the cache on property for the recursive loading call |
|
| 1262 | + $this->_cache_on = $cache_on; |
|
| 1263 | + // if not, then let's try and load it via the registry |
|
| 1264 | + if ($loader && method_exists($this, $loader)) { |
|
| 1265 | + $dependency = $this->{$loader}($param_class); |
|
| 1266 | + } else { |
|
| 1267 | + $dependency = LoaderFactory::getLoader()->load( |
|
| 1268 | + $param_class, |
|
| 1269 | + array(), |
|
| 1270 | + $cache_on |
|
| 1271 | + ); |
|
| 1272 | + } |
|
| 1273 | + } |
|
| 1274 | + } |
|
| 1275 | + // did we successfully find the correct dependency ? |
|
| 1276 | + if ($dependency instanceof $param_class) { |
|
| 1277 | + // then let's inject it into the incoming array of arguments at the correct location |
|
| 1278 | + $arguments[$index] = $dependency; |
|
| 1279 | + } |
|
| 1280 | + return $arguments; |
|
| 1281 | + } |
|
| 1282 | + |
|
| 1283 | + |
|
| 1284 | + |
|
| 1285 | + /** |
|
| 1286 | + * _set_cached_class |
|
| 1287 | + * attempts to cache the instantiated class locally |
|
| 1288 | + * in one of the following places, in the following order: |
|
| 1289 | + * $this->{class_abbreviation} ie: $this->CART |
|
| 1290 | + * $this->{$class_name} ie: $this->Some_Class |
|
| 1291 | + * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
| 1292 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
| 1293 | + * |
|
| 1294 | + * @param object $class_obj |
|
| 1295 | + * @param string $class_name |
|
| 1296 | + * @param string $class_prefix |
|
| 1297 | + * @param bool $from_db |
|
| 1298 | + * @return void |
|
| 1299 | + */ |
|
| 1300 | + protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
|
| 1301 | + { |
|
| 1302 | + if ($class_name === 'EE_Registry' || empty($class_obj)) { |
|
| 1303 | + return; |
|
| 1304 | + } |
|
| 1305 | + // return newly instantiated class |
|
| 1306 | + $class_abbreviation = $this->get_class_abbreviation($class_name, ''); |
|
| 1307 | + if ($class_abbreviation) { |
|
| 1308 | + $this->{$class_abbreviation} = $class_obj; |
|
| 1309 | + return; |
|
| 1310 | + } |
|
| 1311 | + $class_name = str_replace('\\', '_', $class_name); |
|
| 1312 | + if (property_exists($this, $class_name)) { |
|
| 1313 | + $this->{$class_name} = $class_obj; |
|
| 1314 | + return; |
|
| 1315 | + } |
|
| 1316 | + if ($class_prefix === 'addon') { |
|
| 1317 | + $this->addons->{$class_name} = $class_obj; |
|
| 1318 | + return; |
|
| 1319 | + } |
|
| 1320 | + if (! $from_db) { |
|
| 1321 | + $this->LIB->{$class_name} = $class_obj; |
|
| 1322 | + } |
|
| 1323 | + } |
|
| 1324 | + |
|
| 1325 | + |
|
| 1326 | + |
|
| 1327 | + /** |
|
| 1328 | + * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
| 1329 | + * |
|
| 1330 | + * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
| 1331 | + * in the EE_Dependency_Map::$_class_loaders array, |
|
| 1332 | + * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
| 1333 | + * @param array $arguments |
|
| 1334 | + * @return object |
|
| 1335 | + */ |
|
| 1336 | + public static function factory($classname, $arguments = array()) |
|
| 1337 | + { |
|
| 1338 | + $loader = self::instance()->_dependency_map->class_loader($classname); |
|
| 1339 | + if ($loader instanceof Closure) { |
|
| 1340 | + return $loader($arguments); |
|
| 1341 | + } |
|
| 1342 | + if (method_exists(self::instance(), $loader)) { |
|
| 1343 | + return self::instance()->{$loader}($classname, $arguments); |
|
| 1344 | + } |
|
| 1345 | + return null; |
|
| 1346 | + } |
|
| 1347 | + |
|
| 1348 | + |
|
| 1349 | + |
|
| 1350 | + /** |
|
| 1351 | + * Gets the addon by its name/slug (not classname. For that, just |
|
| 1352 | + * use the classname as the property name on EE_Config::instance()->addons) |
|
| 1353 | + * |
|
| 1354 | + * @param string $name |
|
| 1355 | + * @return EE_Addon |
|
| 1356 | + */ |
|
| 1357 | + public function get_addon_by_name($name) |
|
| 1358 | + { |
|
| 1359 | + foreach ($this->addons as $addon) { |
|
| 1360 | + if ($addon->name() === $name) { |
|
| 1361 | + return $addon; |
|
| 1362 | + } |
|
| 1363 | + } |
|
| 1364 | + return null; |
|
| 1365 | + } |
|
| 1366 | + |
|
| 1367 | + |
|
| 1368 | + |
|
| 1369 | + /** |
|
| 1370 | + * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their |
|
| 1371 | + * name() function) They're already available on EE_Config::instance()->addons as properties, where each property's |
|
| 1372 | + * name is the addon's classname. So if you just want to get the addon by classname, use |
|
| 1373 | + * EE_Config::instance()->addons->{classname} |
|
| 1374 | + * |
|
| 1375 | + * @return EE_Addon[] where the KEYS are the addon's name() |
|
| 1376 | + */ |
|
| 1377 | + public function get_addons_by_name() |
|
| 1378 | + { |
|
| 1379 | + $addons = array(); |
|
| 1380 | + foreach ($this->addons as $addon) { |
|
| 1381 | + $addons[$addon->name()] = $addon; |
|
| 1382 | + } |
|
| 1383 | + return $addons; |
|
| 1384 | + } |
|
| 1385 | + |
|
| 1386 | + |
|
| 1387 | + |
|
| 1388 | + /** |
|
| 1389 | + * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
| 1390 | + * a stale copy of it around |
|
| 1391 | + * |
|
| 1392 | + * @param string $model_name |
|
| 1393 | + * @return \EEM_Base |
|
| 1394 | + * @throws \EE_Error |
|
| 1395 | + */ |
|
| 1396 | + public function reset_model($model_name) |
|
| 1397 | + { |
|
| 1398 | + $model_class_name = strpos($model_name, 'EEM_') !== 0 |
|
| 1399 | + ? "EEM_{$model_name}" |
|
| 1400 | + : $model_name; |
|
| 1401 | + if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
| 1402 | + return null; |
|
| 1403 | + } |
|
| 1404 | + //get that model reset it and make sure we nuke the old reference to it |
|
| 1405 | + if ($this->LIB->{$model_class_name} instanceof $model_class_name |
|
| 1406 | + && is_callable( |
|
| 1407 | + array($model_class_name, 'reset') |
|
| 1408 | + )) { |
|
| 1409 | + $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
| 1410 | + } else { |
|
| 1411 | + throw new EE_Error(sprintf(esc_html__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
| 1412 | + } |
|
| 1413 | + return $this->LIB->{$model_class_name}; |
|
| 1414 | + } |
|
| 1415 | + |
|
| 1416 | + |
|
| 1417 | + |
|
| 1418 | + /** |
|
| 1419 | + * Resets the registry. |
|
| 1420 | + * The criteria for what gets reset is based on what can be shared between sites on the same request when |
|
| 1421 | + * switch_to_blog is used in a multisite install. Here is a list of things that are NOT reset. |
|
| 1422 | + * - $_dependency_map |
|
| 1423 | + * - $_class_abbreviations |
|
| 1424 | + * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
| 1425 | + * - $REQ: Still on the same request so no need to change. |
|
| 1426 | + * - $CAP: There is no site specific state in the EE_Capability class. |
|
| 1427 | + * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only |
|
| 1428 | + * one Session can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
| 1429 | + * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
| 1430 | + * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
| 1431 | + * switch or on the restore. |
|
| 1432 | + * - $modules |
|
| 1433 | + * - $shortcodes |
|
| 1434 | + * - $widgets |
|
| 1435 | + * |
|
| 1436 | + * @param boolean $hard [deprecated] |
|
| 1437 | + * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
| 1438 | + * or just reset without re-instantiating (handy to set to FALSE if you're not |
|
| 1439 | + * sure if you CAN currently reinstantiate the singletons at the moment) |
|
| 1440 | + * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so |
|
| 1441 | + * client |
|
| 1442 | + * code instead can just change the model context to a different blog id if |
|
| 1443 | + * necessary |
|
| 1444 | + * @return EE_Registry |
|
| 1445 | + * @throws EE_Error |
|
| 1446 | + * @throws ReflectionException |
|
| 1447 | + */ |
|
| 1448 | + public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
| 1449 | + { |
|
| 1450 | + $instance = self::instance(); |
|
| 1451 | + $instance->_cache_on = true; |
|
| 1452 | + // reset some "special" classes |
|
| 1453 | + EEH_Activation::reset(); |
|
| 1454 | + $hard = apply_filters( 'FHEE__EE_Registry__reset__hard', $hard); |
|
| 1455 | + $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
| 1456 | + $instance->CART = null; |
|
| 1457 | + $instance->MRM = null; |
|
| 1458 | + $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry'); |
|
| 1459 | + //messages reset |
|
| 1460 | + EED_Messages::reset(); |
|
| 1461 | + //handle of objects cached on LIB |
|
| 1462 | + foreach (array('LIB', 'modules') as $cache) { |
|
| 1463 | + foreach ($instance->{$cache} as $class_name => $class) { |
|
| 1464 | + if (self::_reset_and_unset_object($class, $reset_models)) { |
|
| 1465 | + unset($instance->{$cache}->{$class_name}); |
|
| 1466 | + } |
|
| 1467 | + } |
|
| 1468 | + } |
|
| 1469 | + return $instance; |
|
| 1470 | + } |
|
| 1471 | + |
|
| 1472 | + |
|
| 1473 | + |
|
| 1474 | + /** |
|
| 1475 | + * if passed object implements ResettableInterface, then call it's reset() method |
|
| 1476 | + * if passed object implements InterminableInterface, then return false, |
|
| 1477 | + * to indicate that it should NOT be cleared from the Registry cache |
|
| 1478 | + * |
|
| 1479 | + * @param $object |
|
| 1480 | + * @param bool $reset_models |
|
| 1481 | + * @return bool returns true if cached object should be unset |
|
| 1482 | + */ |
|
| 1483 | + private static function _reset_and_unset_object($object, $reset_models) |
|
| 1484 | + { |
|
| 1485 | + if (! is_object($object)) { |
|
| 1486 | + // don't unset anything that's not an object |
|
| 1487 | + return false; |
|
| 1488 | + } |
|
| 1489 | + if ($object instanceof EED_Module) { |
|
| 1490 | + $object::reset(); |
|
| 1491 | + // don't unset modules |
|
| 1492 | + return false; |
|
| 1493 | + } |
|
| 1494 | + if ($object instanceof ResettableInterface) { |
|
| 1495 | + if ($object instanceof EEM_Base) { |
|
| 1496 | + if ($reset_models) { |
|
| 1497 | + $object->reset(); |
|
| 1498 | + return true; |
|
| 1499 | + } |
|
| 1500 | + return false; |
|
| 1501 | + } |
|
| 1502 | + $object->reset(); |
|
| 1503 | + return true; |
|
| 1504 | + } |
|
| 1505 | + if (! $object instanceof InterminableInterface) { |
|
| 1506 | + return true; |
|
| 1507 | + } |
|
| 1508 | + return false; |
|
| 1509 | + } |
|
| 1510 | + |
|
| 1511 | + |
|
| 1512 | + |
|
| 1513 | + /** |
|
| 1514 | + * Gets all the custom post type models defined |
|
| 1515 | + * |
|
| 1516 | + * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
| 1517 | + */ |
|
| 1518 | + public function cpt_models() |
|
| 1519 | + { |
|
| 1520 | + $cpt_models = array(); |
|
| 1521 | + foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
| 1522 | + if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
| 1523 | + $cpt_models[$short_name] = $classname; |
|
| 1524 | + } |
|
| 1525 | + } |
|
| 1526 | + return $cpt_models; |
|
| 1527 | + } |
|
| 1528 | + |
|
| 1529 | + |
|
| 1530 | + |
|
| 1531 | + /** |
|
| 1532 | + * @return \EE_Config |
|
| 1533 | + */ |
|
| 1534 | + public static function CFG() |
|
| 1535 | + { |
|
| 1536 | + return self::instance()->CFG; |
|
| 1537 | + } |
|
| 1538 | 1538 | |
| 1539 | 1539 | |
| 1540 | 1540 | } |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | public static function instance(EE_Dependency_Map $dependency_map = null) |
| 177 | 177 | { |
| 178 | 178 | // check if class object is instantiated |
| 179 | - if (! self::$_instance instanceof EE_Registry) { |
|
| 179 | + if ( ! self::$_instance instanceof EE_Registry) { |
|
| 180 | 180 | self::$_instance = new self($dependency_map); |
| 181 | 181 | } |
| 182 | 182 | return self::$_instance; |
@@ -266,13 +266,13 @@ discard block |
||
| 266 | 266 | */ |
| 267 | 267 | public static function localize_i18n_js_strings() |
| 268 | 268 | { |
| 269 | - $i18n_js_strings = (array)self::$i18n_js_strings; |
|
| 269 | + $i18n_js_strings = (array) self::$i18n_js_strings; |
|
| 270 | 270 | foreach ($i18n_js_strings as $key => $value) { |
| 271 | 271 | if (is_scalar($value)) { |
| 272 | - $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 272 | + $i18n_js_strings[$key] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8'); |
|
| 273 | 273 | } |
| 274 | 274 | } |
| 275 | - return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
| 275 | + return '/* <![CDATA[ */ var eei18n = '.wp_json_encode($i18n_js_strings).'; /* ]]> */'; |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | $module_class = get_class($module); |
| 289 | 289 | $this->modules->{$module_class} = $module; |
| 290 | 290 | } else { |
| 291 | - if (! class_exists('EE_Module_Request_Router')) { |
|
| 291 | + if ( ! class_exists('EE_Module_Request_Router')) { |
|
| 292 | 292 | $this->load_core('Module_Request_Router'); |
| 293 | 293 | } |
| 294 | 294 | EE_Module_Request_Router::module_factory($module); |
@@ -328,10 +328,10 @@ discard block |
||
| 328 | 328 | EE_CORE, |
| 329 | 329 | EE_ADMIN, |
| 330 | 330 | EE_CPTS, |
| 331 | - EE_CORE . 'data_migration_scripts' . DS, |
|
| 332 | - EE_CORE . 'capabilities' . DS, |
|
| 333 | - EE_CORE . 'request_stack' . DS, |
|
| 334 | - EE_CORE . 'middleware' . DS, |
|
| 331 | + EE_CORE.'data_migration_scripts'.DS, |
|
| 332 | + EE_CORE.'capabilities'.DS, |
|
| 333 | + EE_CORE.'request_stack'.DS, |
|
| 334 | + EE_CORE.'middleware'.DS, |
|
| 335 | 335 | ) |
| 336 | 336 | ); |
| 337 | 337 | // retrieve instantiated class |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | $service_paths = apply_filters( |
| 365 | 365 | 'FHEE__EE_Registry__load_service__service_paths', |
| 366 | 366 | array( |
| 367 | - EE_CORE . 'services' . DS, |
|
| 367 | + EE_CORE.'services'.DS, |
|
| 368 | 368 | ) |
| 369 | 369 | ); |
| 370 | 370 | // retrieve instantiated class |
@@ -490,10 +490,10 @@ discard block |
||
| 490 | 490 | { |
| 491 | 491 | $paths = array( |
| 492 | 492 | EE_LIBRARIES, |
| 493 | - EE_LIBRARIES . 'messages' . DS, |
|
| 494 | - EE_LIBRARIES . 'shortcodes' . DS, |
|
| 495 | - EE_LIBRARIES . 'qtips' . DS, |
|
| 496 | - EE_LIBRARIES . 'payment_methods' . DS, |
|
| 493 | + EE_LIBRARIES.'messages'.DS, |
|
| 494 | + EE_LIBRARIES.'shortcodes'.DS, |
|
| 495 | + EE_LIBRARIES.'qtips'.DS, |
|
| 496 | + EE_LIBRARIES.'payment_methods'.DS, |
|
| 497 | 497 | ); |
| 498 | 498 | // retrieve instantiated class |
| 499 | 499 | return $this->_load( |
@@ -556,10 +556,10 @@ discard block |
||
| 556 | 556 | public function load_model_class($class_name, $arguments = array(), $load_only = true) |
| 557 | 557 | { |
| 558 | 558 | $paths = array( |
| 559 | - EE_MODELS . 'fields' . DS, |
|
| 560 | - EE_MODELS . 'helpers' . DS, |
|
| 561 | - EE_MODELS . 'relations' . DS, |
|
| 562 | - EE_MODELS . 'strategies' . DS, |
|
| 559 | + EE_MODELS.'fields'.DS, |
|
| 560 | + EE_MODELS.'helpers'.DS, |
|
| 561 | + EE_MODELS.'relations'.DS, |
|
| 562 | + EE_MODELS.'strategies'.DS, |
|
| 563 | 563 | ); |
| 564 | 564 | // retrieve instantiated class |
| 565 | 565 | return $this->_load( |
@@ -678,7 +678,7 @@ discard block |
||
| 678 | 678 | $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments); |
| 679 | 679 | // if a non-FQCN was passed, then verifyClassExists() might return an object |
| 680 | 680 | // or it could return null if the class just could not be found anywhere |
| 681 | - if ($class_exists instanceof $class_name || $class_exists === null){ |
|
| 681 | + if ($class_exists instanceof $class_name || $class_exists === null) { |
|
| 682 | 682 | // either way, return the results |
| 683 | 683 | return $class_exists; |
| 684 | 684 | } |
@@ -736,7 +736,7 @@ discard block |
||
| 736 | 736 | case 1: |
| 737 | 737 | // if it's a FQCN then maybe the class is registered with a preceding \ |
| 738 | 738 | $class_name = strpos($class_name, '\\') !== false |
| 739 | - ? '\\' . ltrim($class_name, '\\') |
|
| 739 | + ? '\\'.ltrim($class_name, '\\') |
|
| 740 | 740 | : $class_name; |
| 741 | 741 | break; |
| 742 | 742 | case 2: |
@@ -788,11 +788,11 @@ discard block |
||
| 788 | 788 | // strip php file extension |
| 789 | 789 | $class_name = str_replace('.php', '', trim($class_name)); |
| 790 | 790 | // does the class have a prefix ? |
| 791 | - if (! empty($class_prefix) && $class_prefix !== 'addon') { |
|
| 791 | + if ( ! empty($class_prefix) && $class_prefix !== 'addon') { |
|
| 792 | 792 | // make sure $class_prefix is uppercase |
| 793 | 793 | $class_prefix = strtoupper(trim($class_prefix)); |
| 794 | 794 | // add class prefix ONCE!!! |
| 795 | - $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
| 795 | + $class_name = $class_prefix.str_replace($class_prefix, '', $class_name); |
|
| 796 | 796 | } |
| 797 | 797 | $class_name = $this->_dependency_map->get_alias($class_name); |
| 798 | 798 | $class_exists = class_exists($class_name); |
@@ -811,13 +811,13 @@ discard block |
||
| 811 | 811 | } |
| 812 | 812 | } |
| 813 | 813 | // if the class doesn't already exist.. then we need to try and find the file and load it |
| 814 | - if (! $class_exists) { |
|
| 814 | + if ( ! $class_exists) { |
|
| 815 | 815 | // get full path to file |
| 816 | 816 | $path = $this->_resolve_path($class_name, $type, $file_paths); |
| 817 | 817 | // load the file |
| 818 | 818 | $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
| 819 | 819 | // if loading failed, or we are only loading a file but NOT instantiating an object |
| 820 | - if (! $loaded || $load_only) { |
|
| 820 | + if ( ! $loaded || $load_only) { |
|
| 821 | 821 | // return boolean if only loading, or null if an object was expected |
| 822 | 822 | return $load_only |
| 823 | 823 | ? $loaded |
@@ -942,10 +942,10 @@ discard block |
||
| 942 | 942 | : EE_CLASSES; |
| 943 | 943 | // prep file type |
| 944 | 944 | $type = ! empty($type) |
| 945 | - ? trim($type, '.') . '.' |
|
| 945 | + ? trim($type, '.').'.' |
|
| 946 | 946 | : ''; |
| 947 | 947 | // build full file path |
| 948 | - $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
| 948 | + $file_paths[$key] = rtrim($file_path, DS).DS.$class_name.'.'.$type.'php'; |
|
| 949 | 949 | //does the file exist and can be read ? |
| 950 | 950 | if (is_readable($file_paths[$key])) { |
| 951 | 951 | return $file_paths[$key]; |
@@ -973,9 +973,9 @@ discard block |
||
| 973 | 973 | // don't give up! you gotta... |
| 974 | 974 | try { |
| 975 | 975 | //does the file exist and can it be read ? |
| 976 | - if (! $path) { |
|
| 976 | + if ( ! $path) { |
|
| 977 | 977 | // so sorry, can't find the file |
| 978 | - throw new EE_Error ( |
|
| 978 | + throw new EE_Error( |
|
| 979 | 979 | sprintf( |
| 980 | 980 | esc_html__( |
| 981 | 981 | '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', |
@@ -983,7 +983,7 @@ discard block |
||
| 983 | 983 | ), |
| 984 | 984 | trim($type, '.'), |
| 985 | 985 | $class_name, |
| 986 | - '<br />' . implode(',<br />', $file_paths) |
|
| 986 | + '<br />'.implode(',<br />', $file_paths) |
|
| 987 | 987 | ) |
| 988 | 988 | ); |
| 989 | 989 | } |
@@ -1151,7 +1151,7 @@ discard block |
||
| 1151 | 1151 | // let's examine the constructor |
| 1152 | 1152 | $constructor = $reflector->getConstructor(); |
| 1153 | 1153 | // whu? huh? nothing? |
| 1154 | - if (! $constructor) { |
|
| 1154 | + if ( ! $constructor) { |
|
| 1155 | 1155 | return $arguments; |
| 1156 | 1156 | } |
| 1157 | 1157 | // get constructor parameters |
@@ -1317,7 +1317,7 @@ discard block |
||
| 1317 | 1317 | $this->addons->{$class_name} = $class_obj; |
| 1318 | 1318 | return; |
| 1319 | 1319 | } |
| 1320 | - if (! $from_db) { |
|
| 1320 | + if ( ! $from_db) { |
|
| 1321 | 1321 | $this->LIB->{$class_name} = $class_obj; |
| 1322 | 1322 | } |
| 1323 | 1323 | } |
@@ -1398,7 +1398,7 @@ discard block |
||
| 1398 | 1398 | $model_class_name = strpos($model_name, 'EEM_') !== 0 |
| 1399 | 1399 | ? "EEM_{$model_name}" |
| 1400 | 1400 | : $model_name; |
| 1401 | - if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
| 1401 | + if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
| 1402 | 1402 | return null; |
| 1403 | 1403 | } |
| 1404 | 1404 | //get that model reset it and make sure we nuke the old reference to it |
@@ -1451,7 +1451,7 @@ discard block |
||
| 1451 | 1451 | $instance->_cache_on = true; |
| 1452 | 1452 | // reset some "special" classes |
| 1453 | 1453 | EEH_Activation::reset(); |
| 1454 | - $hard = apply_filters( 'FHEE__EE_Registry__reset__hard', $hard); |
|
| 1454 | + $hard = apply_filters('FHEE__EE_Registry__reset__hard', $hard); |
|
| 1455 | 1455 | $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
| 1456 | 1456 | $instance->CART = null; |
| 1457 | 1457 | $instance->MRM = null; |
@@ -1482,7 +1482,7 @@ discard block |
||
| 1482 | 1482 | */ |
| 1483 | 1483 | private static function _reset_and_unset_object($object, $reset_models) |
| 1484 | 1484 | { |
| 1485 | - if (! is_object($object)) { |
|
| 1485 | + if ( ! is_object($object)) { |
|
| 1486 | 1486 | // don't unset anything that's not an object |
| 1487 | 1487 | return false; |
| 1488 | 1488 | } |
@@ -1502,7 +1502,7 @@ discard block |
||
| 1502 | 1502 | $object->reset(); |
| 1503 | 1503 | return true; |
| 1504 | 1504 | } |
| 1505 | - if (! $object instanceof InterminableInterface) { |
|
| 1505 | + if ( ! $object instanceof InterminableInterface) { |
|
| 1506 | 1506 | return true; |
| 1507 | 1507 | } |
| 1508 | 1508 | return false; |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
|
| 2 | 2 | /** |
| 3 | 3 | * |
| 4 | 4 | * EEH_Line_Item |
@@ -45,8 +45,8 @@ discard block |
||
| 45 | 45 | * @return boolean success |
| 46 | 46 | * @throws \EE_Error |
| 47 | 47 | */ |
| 48 | - public static function add_unrelated_item( EE_Line_Item $parent_line_item, $name, $unit_price, $description = '', $quantity = 1, $taxable = FALSE, $code = NULL ){ |
|
| 49 | - $items_subtotal = self::get_pre_tax_subtotal( $parent_line_item ); |
|
| 48 | + public static function add_unrelated_item(EE_Line_Item $parent_line_item, $name, $unit_price, $description = '', $quantity = 1, $taxable = FALSE, $code = NULL) { |
|
| 49 | + $items_subtotal = self::get_pre_tax_subtotal($parent_line_item); |
|
| 50 | 50 | $line_item = EE_Line_Item::new_instance(array( |
| 51 | 51 | 'LIN_name' => $name, |
| 52 | 52 | 'LIN_desc' => $description, |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | 'LIN_quantity' => $quantity, |
| 55 | 55 | 'LIN_percent' => null, |
| 56 | 56 | 'LIN_is_taxable' => $taxable, |
| 57 | - 'LIN_order' => $items_subtotal instanceof EE_Line_Item ? count( $items_subtotal->children() ) : 0, |
|
| 57 | + 'LIN_order' => $items_subtotal instanceof EE_Line_Item ? count($items_subtotal->children()) : 0, |
|
| 58 | 58 | 'LIN_total' => (float) $unit_price * (int) $quantity, |
| 59 | 59 | 'LIN_type'=> EEM_Line_Item::type_line_item, |
| 60 | 60 | 'LIN_code' => $code, |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | $line_item, |
| 65 | 65 | $parent_line_item |
| 66 | 66 | ); |
| 67 | - return self::add_item( $parent_line_item, $line_item ); |
|
| 67 | + return self::add_item($parent_line_item, $line_item); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | * @return boolean success |
| 87 | 87 | * @throws \EE_Error |
| 88 | 88 | */ |
| 89 | - public static function add_percentage_based_item( EE_Line_Item $parent_line_item, $name, $percentage_amount, $description = '', $taxable = FALSE ){ |
|
| 89 | + public static function add_percentage_based_item(EE_Line_Item $parent_line_item, $name, $percentage_amount, $description = '', $taxable = FALSE) { |
|
| 90 | 90 | $line_item = EE_Line_Item::new_instance(array( |
| 91 | 91 | 'LIN_name' => $name, |
| 92 | 92 | 'LIN_desc' => $description, |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | 'LIN_percent' => $percentage_amount, |
| 95 | 95 | 'LIN_quantity' => NULL, |
| 96 | 96 | 'LIN_is_taxable' => $taxable, |
| 97 | - 'LIN_total' => (float) ( $percentage_amount * ( $parent_line_item->total() / 100 ) ), |
|
| 97 | + 'LIN_total' => (float) ($percentage_amount * ($parent_line_item->total() / 100)), |
|
| 98 | 98 | 'LIN_type'=> EEM_Line_Item::type_line_item, |
| 99 | 99 | 'LIN_parent' => $parent_line_item->ID() |
| 100 | 100 | )); |
@@ -123,15 +123,15 @@ discard block |
||
| 123 | 123 | * @return \EE_Line_Item |
| 124 | 124 | * @throws \EE_Error |
| 125 | 125 | */ |
| 126 | - public static function add_ticket_purchase( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ){ |
|
| 127 | - if ( ! $total_line_item instanceof EE_Line_Item || ! $total_line_item->is_total() ) { |
|
| 128 | - throw new EE_Error( sprintf( __( 'A valid line item total is required in order to add tickets. A line item of type "%s" was passed.', 'event_espresso' ), $ticket->ID(), $total_line_item->ID() ) ); |
|
| 126 | + public static function add_ticket_purchase(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) { |
|
| 127 | + if ( ! $total_line_item instanceof EE_Line_Item || ! $total_line_item->is_total()) { |
|
| 128 | + throw new EE_Error(sprintf(__('A valid line item total is required in order to add tickets. A line item of type "%s" was passed.', 'event_espresso'), $ticket->ID(), $total_line_item->ID())); |
|
| 129 | 129 | } |
| 130 | 130 | // either increment the qty for an existing ticket |
| 131 | - $line_item = self::increment_ticket_qty_if_already_in_cart( $total_line_item, $ticket, $qty ); |
|
| 131 | + $line_item = self::increment_ticket_qty_if_already_in_cart($total_line_item, $ticket, $qty); |
|
| 132 | 132 | // or add a new one |
| 133 | - if ( ! $line_item instanceof EE_Line_Item ) { |
|
| 134 | - $line_item = self::create_ticket_line_item( $total_line_item, $ticket, $qty ); |
|
| 133 | + if ( ! $line_item instanceof EE_Line_Item) { |
|
| 134 | + $line_item = self::create_ticket_line_item($total_line_item, $ticket, $qty); |
|
| 135 | 135 | } |
| 136 | 136 | $total_line_item->recalculate_total_including_taxes(); |
| 137 | 137 | return $line_item; |
@@ -147,11 +147,11 @@ discard block |
||
| 147 | 147 | * @return \EE_Line_Item |
| 148 | 148 | * @throws \EE_Error |
| 149 | 149 | */ |
| 150 | - public static function increment_ticket_qty_if_already_in_cart( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ) { |
|
| 150 | + public static function increment_ticket_qty_if_already_in_cart(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) { |
|
| 151 | 151 | $line_item = null; |
| 152 | - if ( $total_line_item instanceof EE_Line_Item && $total_line_item->is_total() ) { |
|
| 153 | - $ticket_line_items = EEH_Line_Item::get_ticket_line_items( $total_line_item ); |
|
| 154 | - foreach ( (array)$ticket_line_items as $ticket_line_item ) { |
|
| 152 | + if ($total_line_item instanceof EE_Line_Item && $total_line_item->is_total()) { |
|
| 153 | + $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
| 154 | + foreach ((array) $ticket_line_items as $ticket_line_item) { |
|
| 155 | 155 | if ( |
| 156 | 156 | $ticket_line_item instanceof EE_Line_Item |
| 157 | 157 | && (int) $ticket_line_item->OBJ_ID() === (int) $ticket->ID() |
@@ -161,8 +161,8 @@ discard block |
||
| 161 | 161 | } |
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | - if ( $line_item instanceof EE_Line_Item ) { |
|
| 165 | - EEH_Line_Item::increment_quantity( $line_item, $qty ); |
|
| 164 | + if ($line_item instanceof EE_Line_Item) { |
|
| 165 | + EEH_Line_Item::increment_quantity($line_item, $qty); |
|
| 166 | 166 | return $line_item; |
| 167 | 167 | } |
| 168 | 168 | return null; |
@@ -179,16 +179,16 @@ discard block |
||
| 179 | 179 | * @return void |
| 180 | 180 | * @throws \EE_Error |
| 181 | 181 | */ |
| 182 | - public static function increment_quantity( EE_Line_Item $line_item, $qty = 1 ) { |
|
| 183 | - if( ! $line_item->is_percent() ) { |
|
| 182 | + public static function increment_quantity(EE_Line_Item $line_item, $qty = 1) { |
|
| 183 | + if ( ! $line_item->is_percent()) { |
|
| 184 | 184 | $qty += $line_item->quantity(); |
| 185 | - $line_item->set_quantity( $qty ); |
|
| 186 | - $line_item->set_total( $line_item->unit_price() * $qty ); |
|
| 185 | + $line_item->set_quantity($qty); |
|
| 186 | + $line_item->set_total($line_item->unit_price() * $qty); |
|
| 187 | 187 | $line_item->save(); |
| 188 | 188 | } |
| 189 | - foreach( $line_item->children() as $child ) { |
|
| 190 | - if( $child->is_sub_line_item() ) { |
|
| 191 | - EEH_Line_Item::update_quantity( $child, $qty ); |
|
| 189 | + foreach ($line_item->children() as $child) { |
|
| 190 | + if ($child->is_sub_line_item()) { |
|
| 191 | + EEH_Line_Item::update_quantity($child, $qty); |
|
| 192 | 192 | } |
| 193 | 193 | } |
| 194 | 194 | } |
@@ -204,17 +204,17 @@ discard block |
||
| 204 | 204 | * @return void |
| 205 | 205 | * @throws \EE_Error |
| 206 | 206 | */ |
| 207 | - public static function decrement_quantity( EE_Line_Item $line_item, $qty = 1 ) { |
|
| 208 | - if( ! $line_item->is_percent() ) { |
|
| 207 | + public static function decrement_quantity(EE_Line_Item $line_item, $qty = 1) { |
|
| 208 | + if ( ! $line_item->is_percent()) { |
|
| 209 | 209 | $qty = $line_item->quantity() - $qty; |
| 210 | - $qty = max( $qty, 0 ); |
|
| 211 | - $line_item->set_quantity( $qty ); |
|
| 212 | - $line_item->set_total( $line_item->unit_price() * $qty ); |
|
| 210 | + $qty = max($qty, 0); |
|
| 211 | + $line_item->set_quantity($qty); |
|
| 212 | + $line_item->set_total($line_item->unit_price() * $qty); |
|
| 213 | 213 | $line_item->save(); |
| 214 | 214 | } |
| 215 | - foreach( $line_item->children() as $child ) { |
|
| 216 | - if( $child->is_sub_line_item() ) { |
|
| 217 | - EEH_Line_Item::update_quantity( $child, $qty ); |
|
| 215 | + foreach ($line_item->children() as $child) { |
|
| 216 | + if ($child->is_sub_line_item()) { |
|
| 217 | + EEH_Line_Item::update_quantity($child, $qty); |
|
| 218 | 218 | } |
| 219 | 219 | } |
| 220 | 220 | } |
@@ -229,15 +229,15 @@ discard block |
||
| 229 | 229 | * @param int $new_quantity |
| 230 | 230 | * @throws \EE_Error |
| 231 | 231 | */ |
| 232 | - public static function update_quantity( EE_Line_Item $line_item, $new_quantity ) { |
|
| 233 | - if( ! $line_item->is_percent() ) { |
|
| 234 | - $line_item->set_quantity( $new_quantity ); |
|
| 235 | - $line_item->set_total( $line_item->unit_price() * $new_quantity ); |
|
| 232 | + public static function update_quantity(EE_Line_Item $line_item, $new_quantity) { |
|
| 233 | + if ( ! $line_item->is_percent()) { |
|
| 234 | + $line_item->set_quantity($new_quantity); |
|
| 235 | + $line_item->set_total($line_item->unit_price() * $new_quantity); |
|
| 236 | 236 | $line_item->save(); |
| 237 | 237 | } |
| 238 | - foreach( $line_item->children() as $child ) { |
|
| 239 | - if( $child->is_sub_line_item() ) { |
|
| 240 | - EEH_Line_Item::update_quantity( $child, $new_quantity ); |
|
| 238 | + foreach ($line_item->children() as $child) { |
|
| 239 | + if ($child->is_sub_line_item()) { |
|
| 240 | + EEH_Line_Item::update_quantity($child, $new_quantity); |
|
| 241 | 241 | } |
| 242 | 242 | } |
| 243 | 243 | } |
@@ -252,43 +252,43 @@ discard block |
||
| 252 | 252 | * @return \EE_Line_Item |
| 253 | 253 | * @throws \EE_Error |
| 254 | 254 | */ |
| 255 | - public static function create_ticket_line_item( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ) { |
|
| 255 | + public static function create_ticket_line_item(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) { |
|
| 256 | 256 | $datetimes = $ticket->datetimes(); |
| 257 | - $first_datetime = reset( $datetimes ); |
|
| 258 | - if( $first_datetime instanceof EE_Datetime && $first_datetime->event() instanceof EE_Event ) { |
|
| 257 | + $first_datetime = reset($datetimes); |
|
| 258 | + if ($first_datetime instanceof EE_Datetime && $first_datetime->event() instanceof EE_Event) { |
|
| 259 | 259 | $first_datetime_name = $first_datetime->event()->name(); |
| 260 | 260 | } else { |
| 261 | - $first_datetime_name = __( 'Event', 'event_espresso' ); |
|
| 261 | + $first_datetime_name = __('Event', 'event_espresso'); |
|
| 262 | 262 | } |
| 263 | - $event = sprintf( _x( '(For %1$s)', '(For Event Name)', 'event_espresso' ), $first_datetime_name ); |
|
| 263 | + $event = sprintf(_x('(For %1$s)', '(For Event Name)', 'event_espresso'), $first_datetime_name); |
|
| 264 | 264 | // get event subtotal line |
| 265 | - $events_sub_total = self::get_event_line_item_for_ticket( $total_line_item, $ticket ); |
|
| 265 | + $events_sub_total = self::get_event_line_item_for_ticket($total_line_item, $ticket); |
|
| 266 | 266 | // add $ticket to cart |
| 267 | - $line_item = EE_Line_Item::new_instance( array( |
|
| 267 | + $line_item = EE_Line_Item::new_instance(array( |
|
| 268 | 268 | 'LIN_name' => $ticket->name(), |
| 269 | - 'LIN_desc' => $ticket->description() !== '' ? $ticket->description() . ' ' . $event : $event, |
|
| 269 | + 'LIN_desc' => $ticket->description() !== '' ? $ticket->description().' '.$event : $event, |
|
| 270 | 270 | 'LIN_unit_price' => $ticket->price(), |
| 271 | 271 | 'LIN_quantity' => $qty, |
| 272 | 272 | 'LIN_is_taxable' => $ticket->taxable(), |
| 273 | - 'LIN_order' => count( $events_sub_total->children() ), |
|
| 273 | + 'LIN_order' => count($events_sub_total->children()), |
|
| 274 | 274 | 'LIN_total' => $ticket->price() * $qty, |
| 275 | 275 | 'LIN_type' => EEM_Line_Item::type_line_item, |
| 276 | 276 | 'OBJ_ID' => $ticket->ID(), |
| 277 | 277 | 'OBJ_type' => 'Ticket' |
| 278 | - ) ); |
|
| 278 | + )); |
|
| 279 | 279 | $line_item = apply_filters( |
| 280 | 280 | 'FHEE__EEH_Line_Item__create_ticket_line_item__line_item', |
| 281 | 281 | $line_item |
| 282 | 282 | ); |
| 283 | - $events_sub_total->add_child_line_item( $line_item ); |
|
| 283 | + $events_sub_total->add_child_line_item($line_item); |
|
| 284 | 284 | //now add the sub-line items |
| 285 | 285 | $running_total_for_ticket = 0; |
| 286 | - foreach ( $ticket->prices( array( 'order_by' => array( 'PRC_order' => 'ASC' ) ) ) as $price ) { |
|
| 286 | + foreach ($ticket->prices(array('order_by' => array('PRC_order' => 'ASC'))) as $price) { |
|
| 287 | 287 | $sign = $price->is_discount() ? -1 : 1; |
| 288 | 288 | $price_total = $price->is_percent() |
| 289 | 289 | ? $running_total_for_ticket * $price->amount() / 100 |
| 290 | 290 | : $price->amount() * $qty; |
| 291 | - $sub_line_item = EE_Line_Item::new_instance( array( |
|
| 291 | + $sub_line_item = EE_Line_Item::new_instance(array( |
|
| 292 | 292 | 'LIN_name' => $price->name(), |
| 293 | 293 | 'LIN_desc' => $price->desc(), |
| 294 | 294 | 'LIN_quantity' => $price->is_percent() ? null : $qty, |
@@ -298,18 +298,18 @@ discard block |
||
| 298 | 298 | 'LIN_type' => EEM_Line_Item::type_sub_line_item, |
| 299 | 299 | 'OBJ_ID' => $price->ID(), |
| 300 | 300 | 'OBJ_type' => 'Price' |
| 301 | - ) ); |
|
| 301 | + )); |
|
| 302 | 302 | $sub_line_item = apply_filters( |
| 303 | 303 | 'FHEE__EEH_Line_Item__create_ticket_line_item__sub_line_item', |
| 304 | 304 | $sub_line_item |
| 305 | 305 | ); |
| 306 | - if ( $price->is_percent() ) { |
|
| 307 | - $sub_line_item->set_percent( $sign * $price->amount() ); |
|
| 306 | + if ($price->is_percent()) { |
|
| 307 | + $sub_line_item->set_percent($sign * $price->amount()); |
|
| 308 | 308 | } else { |
| 309 | - $sub_line_item->set_unit_price( $sign * $price->amount() ); |
|
| 309 | + $sub_line_item->set_unit_price($sign * $price->amount()); |
|
| 310 | 310 | } |
| 311 | 311 | $running_total_for_ticket += $price_total; |
| 312 | - $line_item->add_child_line_item( $sub_line_item ); |
|
| 312 | + $line_item->add_child_line_item($sub_line_item); |
|
| 313 | 313 | } |
| 314 | 314 | return $line_item; |
| 315 | 315 | } |
@@ -329,11 +329,11 @@ discard block |
||
| 329 | 329 | * @return boolean |
| 330 | 330 | * @throws \EE_Error |
| 331 | 331 | */ |
| 332 | - public static function add_item( EE_Line_Item $total_line_item, EE_Line_Item $item ){ |
|
| 333 | - $pre_tax_subtotal = self::get_pre_tax_subtotal( $total_line_item ); |
|
| 334 | - if ( $pre_tax_subtotal instanceof EE_Line_Item ){ |
|
| 332 | + public static function add_item(EE_Line_Item $total_line_item, EE_Line_Item $item) { |
|
| 333 | + $pre_tax_subtotal = self::get_pre_tax_subtotal($total_line_item); |
|
| 334 | + if ($pre_tax_subtotal instanceof EE_Line_Item) { |
|
| 335 | 335 | $success = $pre_tax_subtotal->add_child_line_item($item); |
| 336 | - }else{ |
|
| 336 | + } else { |
|
| 337 | 337 | return FALSE; |
| 338 | 338 | } |
| 339 | 339 | $total_line_item->recalculate_total_including_taxes(); |
@@ -352,34 +352,34 @@ discard block |
||
| 352 | 352 | * @return bool success |
| 353 | 353 | * @throws \EE_Error |
| 354 | 354 | */ |
| 355 | - public static function cancel_ticket_line_item( EE_Line_Item $ticket_line_item, $qty = 1 ) { |
|
| 355 | + public static function cancel_ticket_line_item(EE_Line_Item $ticket_line_item, $qty = 1) { |
|
| 356 | 356 | // validate incoming line_item |
| 357 | - if ( $ticket_line_item->OBJ_type() !== 'Ticket' ) { |
|
| 357 | + if ($ticket_line_item->OBJ_type() !== 'Ticket') { |
|
| 358 | 358 | throw new EE_Error( |
| 359 | 359 | sprintf( |
| 360 | - __( 'The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso' ), |
|
| 360 | + __('The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso'), |
|
| 361 | 361 | $ticket_line_item->type() |
| 362 | 362 | ) |
| 363 | 363 | ); |
| 364 | 364 | } |
| 365 | - if ( $ticket_line_item->quantity() < $qty ) { |
|
| 365 | + if ($ticket_line_item->quantity() < $qty) { |
|
| 366 | 366 | throw new EE_Error( |
| 367 | 367 | sprintf( |
| 368 | - __( 'Can not cancel %1$d ticket(s) because the supplied line item has a quantity of %2$d.', 'event_espresso' ), |
|
| 368 | + __('Can not cancel %1$d ticket(s) because the supplied line item has a quantity of %2$d.', 'event_espresso'), |
|
| 369 | 369 | $qty, |
| 370 | 370 | $ticket_line_item->quantity() |
| 371 | 371 | ) |
| 372 | 372 | ); |
| 373 | 373 | } |
| 374 | 374 | // decrement ticket quantity; don't rely on auto-fixing when recalculating totals to do this |
| 375 | - $ticket_line_item->set_quantity( $ticket_line_item->quantity() - $qty ); |
|
| 376 | - foreach( $ticket_line_item->children() as $child_line_item ) { |
|
| 377 | - if( |
|
| 375 | + $ticket_line_item->set_quantity($ticket_line_item->quantity() - $qty); |
|
| 376 | + foreach ($ticket_line_item->children() as $child_line_item) { |
|
| 377 | + if ( |
|
| 378 | 378 | $child_line_item->is_sub_line_item() |
| 379 | 379 | && ! $child_line_item->is_percent() |
| 380 | 380 | && ! $child_line_item->is_cancellation() |
| 381 | 381 | ) { |
| 382 | - $child_line_item->set_quantity( $child_line_item->quantity() - $qty ); |
|
| 382 | + $child_line_item->set_quantity($child_line_item->quantity() - $qty); |
|
| 383 | 383 | } |
| 384 | 384 | } |
| 385 | 385 | // get cancellation sub line item |
@@ -387,37 +387,37 @@ discard block |
||
| 387 | 387 | $ticket_line_item, |
| 388 | 388 | EEM_Line_Item::type_cancellation |
| 389 | 389 | ); |
| 390 | - $cancellation_line_item = reset( $cancellation_line_item ); |
|
| 390 | + $cancellation_line_item = reset($cancellation_line_item); |
|
| 391 | 391 | // verify that this ticket was indeed previously cancelled |
| 392 | - if ( $cancellation_line_item instanceof EE_Line_Item ) { |
|
| 392 | + if ($cancellation_line_item instanceof EE_Line_Item) { |
|
| 393 | 393 | // increment cancelled quantity |
| 394 | - $cancellation_line_item->set_quantity( $cancellation_line_item->quantity() + $qty ); |
|
| 394 | + $cancellation_line_item->set_quantity($cancellation_line_item->quantity() + $qty); |
|
| 395 | 395 | } else { |
| 396 | 396 | // create cancellation sub line item |
| 397 | - $cancellation_line_item = EE_Line_Item::new_instance( array( |
|
| 398 | - 'LIN_name' => __( 'Cancellation', 'event_espresso' ), |
|
| 397 | + $cancellation_line_item = EE_Line_Item::new_instance(array( |
|
| 398 | + 'LIN_name' => __('Cancellation', 'event_espresso'), |
|
| 399 | 399 | 'LIN_desc' => sprintf( |
| 400 | - _x( 'Cancelled %1$s : %2$s', 'Cancelled Ticket Name : 2015-01-01 11:11', 'event_espresso' ), |
|
| 400 | + _x('Cancelled %1$s : %2$s', 'Cancelled Ticket Name : 2015-01-01 11:11', 'event_espresso'), |
|
| 401 | 401 | $ticket_line_item->name(), |
| 402 | - current_time( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) ) |
|
| 402 | + current_time(get_option('date_format').' '.get_option('time_format')) |
|
| 403 | 403 | ), |
| 404 | 404 | 'LIN_unit_price' => 0, // $ticket_line_item->unit_price() |
| 405 | 405 | 'LIN_quantity' => $qty, |
| 406 | 406 | 'LIN_is_taxable' => $ticket_line_item->is_taxable(), |
| 407 | - 'LIN_order' => count( $ticket_line_item->children() ), |
|
| 407 | + 'LIN_order' => count($ticket_line_item->children()), |
|
| 408 | 408 | 'LIN_total' => 0, // $ticket_line_item->unit_price() |
| 409 | 409 | 'LIN_type' => EEM_Line_Item::type_cancellation, |
| 410 | - ) ); |
|
| 411 | - $ticket_line_item->add_child_line_item( $cancellation_line_item ); |
|
| 410 | + )); |
|
| 411 | + $ticket_line_item->add_child_line_item($cancellation_line_item); |
|
| 412 | 412 | } |
| 413 | - if ( $ticket_line_item->save_this_and_descendants() > 0 ) { |
|
| 413 | + if ($ticket_line_item->save_this_and_descendants() > 0) { |
|
| 414 | 414 | // decrement parent line item quantity |
| 415 | 415 | $event_line_item = $ticket_line_item->parent(); |
| 416 | - if ( $event_line_item instanceof EE_Line_Item && $event_line_item->OBJ_type() === 'Event' ) { |
|
| 417 | - $event_line_item->set_quantity( $event_line_item->quantity() - $qty ); |
|
| 416 | + if ($event_line_item instanceof EE_Line_Item && $event_line_item->OBJ_type() === 'Event') { |
|
| 417 | + $event_line_item->set_quantity($event_line_item->quantity() - $qty); |
|
| 418 | 418 | $event_line_item->save(); |
| 419 | 419 | } |
| 420 | - EEH_Line_Item::get_grand_total_and_recalculate_everything( $ticket_line_item ); |
|
| 420 | + EEH_Line_Item::get_grand_total_and_recalculate_everything($ticket_line_item); |
|
| 421 | 421 | return true; |
| 422 | 422 | } |
| 423 | 423 | return false; |
@@ -435,12 +435,12 @@ discard block |
||
| 435 | 435 | * @return bool success |
| 436 | 436 | * @throws \EE_Error |
| 437 | 437 | */ |
| 438 | - public static function reinstate_canceled_ticket_line_item( EE_Line_Item $ticket_line_item, $qty = 1 ) { |
|
| 438 | + public static function reinstate_canceled_ticket_line_item(EE_Line_Item $ticket_line_item, $qty = 1) { |
|
| 439 | 439 | // validate incoming line_item |
| 440 | - if ( $ticket_line_item->OBJ_type() !== 'Ticket' ) { |
|
| 440 | + if ($ticket_line_item->OBJ_type() !== 'Ticket') { |
|
| 441 | 441 | throw new EE_Error( |
| 442 | 442 | sprintf( |
| 443 | - __( 'The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso' ), |
|
| 443 | + __('The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso'), |
|
| 444 | 444 | $ticket_line_item->type() |
| 445 | 445 | ) |
| 446 | 446 | ); |
@@ -450,42 +450,42 @@ discard block |
||
| 450 | 450 | $ticket_line_item, |
| 451 | 451 | EEM_Line_Item::type_cancellation |
| 452 | 452 | ); |
| 453 | - $cancellation_line_item = reset( $cancellation_line_item ); |
|
| 453 | + $cancellation_line_item = reset($cancellation_line_item); |
|
| 454 | 454 | // verify that this ticket was indeed previously cancelled |
| 455 | - if ( ! $cancellation_line_item instanceof EE_Line_Item ) { |
|
| 455 | + if ( ! $cancellation_line_item instanceof EE_Line_Item) { |
|
| 456 | 456 | return false; |
| 457 | 457 | } |
| 458 | - if ( $cancellation_line_item->quantity() > $qty ) { |
|
| 458 | + if ($cancellation_line_item->quantity() > $qty) { |
|
| 459 | 459 | // decrement cancelled quantity |
| 460 | - $cancellation_line_item->set_quantity( $cancellation_line_item->quantity() - $qty ); |
|
| 461 | - } else if ( $cancellation_line_item->quantity() == $qty ) { |
|
| 460 | + $cancellation_line_item->set_quantity($cancellation_line_item->quantity() - $qty); |
|
| 461 | + } else if ($cancellation_line_item->quantity() == $qty) { |
|
| 462 | 462 | // decrement cancelled quantity in case anyone still has the object kicking around |
| 463 | - $cancellation_line_item->set_quantity( $cancellation_line_item->quantity() - $qty ); |
|
| 463 | + $cancellation_line_item->set_quantity($cancellation_line_item->quantity() - $qty); |
|
| 464 | 464 | // delete because quantity will end up as 0 |
| 465 | 465 | $cancellation_line_item->delete(); |
| 466 | 466 | // and attempt to destroy the object, |
| 467 | 467 | // even though PHP won't actually destroy it until it needs the memory |
| 468 | - unset( $cancellation_line_item ); |
|
| 468 | + unset($cancellation_line_item); |
|
| 469 | 469 | } else { |
| 470 | 470 | // what ?!?! negative quantity ?!?! |
| 471 | 471 | throw new EE_Error( |
| 472 | 472 | sprintf( |
| 473 | - __( 'Can not reinstate %1$d cancelled ticket(s) because the cancelled ticket quantity is only %2$d.', |
|
| 474 | - 'event_espresso' ), |
|
| 473 | + __('Can not reinstate %1$d cancelled ticket(s) because the cancelled ticket quantity is only %2$d.', |
|
| 474 | + 'event_espresso'), |
|
| 475 | 475 | $qty, |
| 476 | 476 | $cancellation_line_item->quantity() |
| 477 | 477 | ) |
| 478 | 478 | ); |
| 479 | 479 | } |
| 480 | 480 | // increment ticket quantity |
| 481 | - $ticket_line_item->set_quantity( $ticket_line_item->quantity() + $qty ); |
|
| 482 | - if ( $ticket_line_item->save_this_and_descendants() > 0 ) { |
|
| 481 | + $ticket_line_item->set_quantity($ticket_line_item->quantity() + $qty); |
|
| 482 | + if ($ticket_line_item->save_this_and_descendants() > 0) { |
|
| 483 | 483 | // increment parent line item quantity |
| 484 | 484 | $event_line_item = $ticket_line_item->parent(); |
| 485 | - if ( $event_line_item instanceof EE_Line_Item && $event_line_item->OBJ_type() === 'Event' ) { |
|
| 486 | - $event_line_item->set_quantity( $event_line_item->quantity() + $qty ); |
|
| 485 | + if ($event_line_item instanceof EE_Line_Item && $event_line_item->OBJ_type() === 'Event') { |
|
| 486 | + $event_line_item->set_quantity($event_line_item->quantity() + $qty); |
|
| 487 | 487 | } |
| 488 | - EEH_Line_Item::get_grand_total_and_recalculate_everything( $ticket_line_item ); |
|
| 488 | + EEH_Line_Item::get_grand_total_and_recalculate_everything($ticket_line_item); |
|
| 489 | 489 | return true; |
| 490 | 490 | } |
| 491 | 491 | return false; |
@@ -500,8 +500,8 @@ discard block |
||
| 500 | 500 | * @param EE_Line_Item $line_item |
| 501 | 501 | * @return \EE_Line_Item |
| 502 | 502 | */ |
| 503 | - public static function get_grand_total_and_recalculate_everything( EE_Line_Item $line_item ){ |
|
| 504 | - $grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item( $line_item ); |
|
| 503 | + public static function get_grand_total_and_recalculate_everything(EE_Line_Item $line_item) { |
|
| 504 | + $grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item($line_item); |
|
| 505 | 505 | return $grand_total_line_item->recalculate_total_including_taxes(); |
| 506 | 506 | } |
| 507 | 507 | |
@@ -514,11 +514,11 @@ discard block |
||
| 514 | 514 | * @return \EE_Line_Item |
| 515 | 515 | * @throws \EE_Error |
| 516 | 516 | */ |
| 517 | - public static function get_pre_tax_subtotal( EE_Line_Item $total_line_item ){ |
|
| 518 | - $pre_tax_subtotal = $total_line_item->get_child_line_item( 'pre-tax-subtotal' ); |
|
| 517 | + public static function get_pre_tax_subtotal(EE_Line_Item $total_line_item) { |
|
| 518 | + $pre_tax_subtotal = $total_line_item->get_child_line_item('pre-tax-subtotal'); |
|
| 519 | 519 | return $pre_tax_subtotal instanceof EE_Line_Item |
| 520 | 520 | ? $pre_tax_subtotal |
| 521 | - : self::create_pre_tax_subtotal( $total_line_item ); |
|
| 521 | + : self::create_pre_tax_subtotal($total_line_item); |
|
| 522 | 522 | } |
| 523 | 523 | |
| 524 | 524 | |
@@ -530,9 +530,9 @@ discard block |
||
| 530 | 530 | * @return \EE_Line_Item |
| 531 | 531 | * @throws \EE_Error |
| 532 | 532 | */ |
| 533 | - public static function get_taxes_subtotal( EE_Line_Item $total_line_item ){ |
|
| 534 | - $taxes = $total_line_item->get_child_line_item( 'taxes' ); |
|
| 535 | - return $taxes ? $taxes : self::create_taxes_subtotal( $total_line_item ); |
|
| 533 | + public static function get_taxes_subtotal(EE_Line_Item $total_line_item) { |
|
| 534 | + $taxes = $total_line_item->get_child_line_item('taxes'); |
|
| 535 | + return $taxes ? $taxes : self::create_taxes_subtotal($total_line_item); |
|
| 536 | 536 | } |
| 537 | 537 | |
| 538 | 538 | |
@@ -545,12 +545,12 @@ discard block |
||
| 545 | 545 | * @return void |
| 546 | 546 | * @throws \EE_Error |
| 547 | 547 | */ |
| 548 | - public static function set_TXN_ID( EE_Line_Item $line_item, $transaction = NULL ){ |
|
| 549 | - if( $transaction ){ |
|
| 548 | + public static function set_TXN_ID(EE_Line_Item $line_item, $transaction = NULL) { |
|
| 549 | + if ($transaction) { |
|
| 550 | 550 | /** @type EEM_Transaction $EEM_Transaction */ |
| 551 | - $EEM_Transaction = EE_Registry::instance()->load_model( 'Transaction' ); |
|
| 552 | - $TXN_ID = $EEM_Transaction->ensure_is_ID( $transaction ); |
|
| 553 | - $line_item->set_TXN_ID( $TXN_ID ); |
|
| 551 | + $EEM_Transaction = EE_Registry::instance()->load_model('Transaction'); |
|
| 552 | + $TXN_ID = $EEM_Transaction->ensure_is_ID($transaction); |
|
| 553 | + $line_item->set_TXN_ID($TXN_ID); |
|
| 554 | 554 | } |
| 555 | 555 | } |
| 556 | 556 | |
@@ -565,8 +565,8 @@ discard block |
||
| 565 | 565 | * @return \EE_Line_Item of type total |
| 566 | 566 | * @throws \EE_Error |
| 567 | 567 | */ |
| 568 | - public static function create_total_line_item( $transaction = NULL ){ |
|
| 569 | - $total_line_item = EE_Line_Item::new_instance( array( |
|
| 568 | + public static function create_total_line_item($transaction = NULL) { |
|
| 569 | + $total_line_item = EE_Line_Item::new_instance(array( |
|
| 570 | 570 | 'LIN_code' => 'total', |
| 571 | 571 | 'LIN_name' => __('Grand Total', 'event_espresso'), |
| 572 | 572 | 'LIN_type' => EEM_Line_Item::type_total, |
@@ -576,9 +576,9 @@ discard block |
||
| 576 | 576 | 'FHEE__EEH_Line_Item__create_total_line_item__total_line_item', |
| 577 | 577 | $total_line_item |
| 578 | 578 | ); |
| 579 | - self::set_TXN_ID( $total_line_item, $transaction ); |
|
| 580 | - self::create_pre_tax_subtotal( $total_line_item, $transaction ); |
|
| 581 | - self::create_taxes_subtotal( $total_line_item, $transaction ); |
|
| 579 | + self::set_TXN_ID($total_line_item, $transaction); |
|
| 580 | + self::create_pre_tax_subtotal($total_line_item, $transaction); |
|
| 581 | + self::create_taxes_subtotal($total_line_item, $transaction); |
|
| 582 | 582 | return $total_line_item; |
| 583 | 583 | } |
| 584 | 584 | |
@@ -592,19 +592,19 @@ discard block |
||
| 592 | 592 | * @return EE_Line_Item |
| 593 | 593 | * @throws \EE_Error |
| 594 | 594 | */ |
| 595 | - protected static function create_pre_tax_subtotal( EE_Line_Item $total_line_item, $transaction = NULL ){ |
|
| 596 | - $pre_tax_line_item = EE_Line_Item::new_instance( array( |
|
| 595 | + protected static function create_pre_tax_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
| 596 | + $pre_tax_line_item = EE_Line_Item::new_instance(array( |
|
| 597 | 597 | 'LIN_code' => 'pre-tax-subtotal', |
| 598 | - 'LIN_name' => __( 'Pre-Tax Subtotal', 'event_espresso' ), |
|
| 598 | + 'LIN_name' => __('Pre-Tax Subtotal', 'event_espresso'), |
|
| 599 | 599 | 'LIN_type' => EEM_Line_Item::type_sub_total |
| 600 | - ) ); |
|
| 600 | + )); |
|
| 601 | 601 | $pre_tax_line_item = apply_filters( |
| 602 | 602 | 'FHEE__EEH_Line_Item__create_pre_tax_subtotal__pre_tax_line_item', |
| 603 | 603 | $pre_tax_line_item |
| 604 | 604 | ); |
| 605 | - self::set_TXN_ID( $pre_tax_line_item, $transaction ); |
|
| 606 | - $total_line_item->add_child_line_item( $pre_tax_line_item ); |
|
| 607 | - self::create_event_subtotal( $pre_tax_line_item, $transaction ); |
|
| 605 | + self::set_TXN_ID($pre_tax_line_item, $transaction); |
|
| 606 | + $total_line_item->add_child_line_item($pre_tax_line_item); |
|
| 607 | + self::create_event_subtotal($pre_tax_line_item, $transaction); |
|
| 608 | 608 | return $pre_tax_line_item; |
| 609 | 609 | } |
| 610 | 610 | |
@@ -619,21 +619,21 @@ discard block |
||
| 619 | 619 | * @return EE_Line_Item |
| 620 | 620 | * @throws \EE_Error |
| 621 | 621 | */ |
| 622 | - protected static function create_taxes_subtotal( EE_Line_Item $total_line_item, $transaction = NULL ){ |
|
| 622 | + protected static function create_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
| 623 | 623 | $tax_line_item = EE_Line_Item::new_instance(array( |
| 624 | 624 | 'LIN_code' => 'taxes', |
| 625 | 625 | 'LIN_name' => __('Taxes', 'event_espresso'), |
| 626 | 626 | 'LIN_type' => EEM_Line_Item::type_tax_sub_total, |
| 627 | - 'LIN_order' => 1000,//this should always come last |
|
| 627 | + 'LIN_order' => 1000, //this should always come last |
|
| 628 | 628 | )); |
| 629 | 629 | $tax_line_item = apply_filters( |
| 630 | 630 | 'FHEE__EEH_Line_Item__create_taxes_subtotal__tax_line_item', |
| 631 | 631 | $tax_line_item |
| 632 | 632 | ); |
| 633 | - self::set_TXN_ID( $tax_line_item, $transaction ); |
|
| 634 | - $total_line_item->add_child_line_item( $tax_line_item ); |
|
| 633 | + self::set_TXN_ID($tax_line_item, $transaction); |
|
| 634 | + $total_line_item->add_child_line_item($tax_line_item); |
|
| 635 | 635 | //and lastly, add the actual taxes |
| 636 | - self::apply_taxes( $total_line_item ); |
|
| 636 | + self::apply_taxes($total_line_item); |
|
| 637 | 637 | return $tax_line_item; |
| 638 | 638 | } |
| 639 | 639 | |
@@ -648,11 +648,11 @@ discard block |
||
| 648 | 648 | * @return EE_Line_Item |
| 649 | 649 | * @throws \EE_Error |
| 650 | 650 | */ |
| 651 | - public static function create_event_subtotal( EE_Line_Item $pre_tax_line_item, $transaction = NULL, $event = NULL ){ |
|
| 651 | + public static function create_event_subtotal(EE_Line_Item $pre_tax_line_item, $transaction = NULL, $event = NULL) { |
|
| 652 | 652 | $event_line_item = EE_Line_Item::new_instance(array( |
| 653 | - 'LIN_code' => self::get_event_code( $event ), |
|
| 654 | - 'LIN_name' => self::get_event_name( $event ), |
|
| 655 | - 'LIN_desc' => self::get_event_desc( $event ), |
|
| 653 | + 'LIN_code' => self::get_event_code($event), |
|
| 654 | + 'LIN_name' => self::get_event_name($event), |
|
| 655 | + 'LIN_desc' => self::get_event_desc($event), |
|
| 656 | 656 | 'LIN_type' => EEM_Line_Item::type_sub_total, |
| 657 | 657 | 'OBJ_type' => 'Event', |
| 658 | 658 | 'OBJ_ID' => $event instanceof EE_Event ? $event->ID() : 0 |
@@ -661,8 +661,8 @@ discard block |
||
| 661 | 661 | 'FHEE__EEH_Line_Item__create_event_subtotal__event_line_item', |
| 662 | 662 | $event_line_item |
| 663 | 663 | ); |
| 664 | - self::set_TXN_ID( $event_line_item, $transaction ); |
|
| 665 | - $pre_tax_line_item->add_child_line_item( $event_line_item ); |
|
| 664 | + self::set_TXN_ID($event_line_item, $transaction); |
|
| 665 | + $pre_tax_line_item->add_child_line_item($event_line_item); |
|
| 666 | 666 | return $event_line_item; |
| 667 | 667 | } |
| 668 | 668 | |
@@ -675,8 +675,8 @@ discard block |
||
| 675 | 675 | * @return string |
| 676 | 676 | * @throws \EE_Error |
| 677 | 677 | */ |
| 678 | - public static function get_event_code( $event ) { |
|
| 679 | - return 'event-' . ( $event instanceof EE_Event ? $event->ID() : '0' ); |
|
| 678 | + public static function get_event_code($event) { |
|
| 679 | + return 'event-'.($event instanceof EE_Event ? $event->ID() : '0'); |
|
| 680 | 680 | } |
| 681 | 681 | |
| 682 | 682 | /** |
@@ -684,8 +684,8 @@ discard block |
||
| 684 | 684 | * @param EE_Event $event |
| 685 | 685 | * @return string |
| 686 | 686 | */ |
| 687 | - public static function get_event_name( $event ) { |
|
| 688 | - return $event instanceof EE_Event ? $event->name() : __( 'Event', 'event_espresso' ); |
|
| 687 | + public static function get_event_name($event) { |
|
| 688 | + return $event instanceof EE_Event ? $event->name() : __('Event', 'event_espresso'); |
|
| 689 | 689 | } |
| 690 | 690 | |
| 691 | 691 | /** |
@@ -693,7 +693,7 @@ discard block |
||
| 693 | 693 | * @param EE_Event $event |
| 694 | 694 | * @return string |
| 695 | 695 | */ |
| 696 | - public static function get_event_desc( $event ) { |
|
| 696 | + public static function get_event_desc($event) { |
|
| 697 | 697 | return $event instanceof EE_Event ? $event->short_description() : ''; |
| 698 | 698 | } |
| 699 | 699 | |
@@ -707,27 +707,27 @@ discard block |
||
| 707 | 707 | * @throws \EE_Error |
| 708 | 708 | * @return EE_Line_Item |
| 709 | 709 | */ |
| 710 | - public static function get_event_line_item_for_ticket( EE_Line_Item $grand_total, EE_Ticket $ticket ) { |
|
| 710 | + public static function get_event_line_item_for_ticket(EE_Line_Item $grand_total, EE_Ticket $ticket) { |
|
| 711 | 711 | $first_datetime = $ticket->first_datetime(); |
| 712 | - if ( ! $first_datetime instanceof EE_Datetime ) { |
|
| 712 | + if ( ! $first_datetime instanceof EE_Datetime) { |
|
| 713 | 713 | throw new EE_Error( |
| 714 | - sprintf( __( 'The supplied ticket (ID %d) has no datetimes', 'event_espresso' ), $ticket->ID() ) |
|
| 714 | + sprintf(__('The supplied ticket (ID %d) has no datetimes', 'event_espresso'), $ticket->ID()) |
|
| 715 | 715 | ); |
| 716 | 716 | } |
| 717 | 717 | $event = $first_datetime->event(); |
| 718 | - if ( ! $event instanceof EE_Event ) { |
|
| 718 | + if ( ! $event instanceof EE_Event) { |
|
| 719 | 719 | throw new EE_Error( |
| 720 | 720 | sprintf( |
| 721 | - __( 'The supplied ticket (ID %d) has no event data associated with it.', 'event_espresso' ), |
|
| 721 | + __('The supplied ticket (ID %d) has no event data associated with it.', 'event_espresso'), |
|
| 722 | 722 | $ticket->ID() |
| 723 | 723 | ) |
| 724 | 724 | ); |
| 725 | 725 | } |
| 726 | - $events_sub_total = EEH_Line_Item::get_event_line_item( $grand_total, $event ); |
|
| 727 | - if ( ! $events_sub_total instanceof EE_Line_Item ) { |
|
| 726 | + $events_sub_total = EEH_Line_Item::get_event_line_item($grand_total, $event); |
|
| 727 | + if ( ! $events_sub_total instanceof EE_Line_Item) { |
|
| 728 | 728 | throw new EE_Error( |
| 729 | 729 | sprintf( |
| 730 | - __( 'There is no events sub-total for ticket %s on total line item %d', 'event_espresso' ), |
|
| 730 | + __('There is no events sub-total for ticket %s on total line item %d', 'event_espresso'), |
|
| 731 | 731 | $ticket->ID(), |
| 732 | 732 | $grand_total->ID() |
| 733 | 733 | ) |
@@ -746,31 +746,31 @@ discard block |
||
| 746 | 746 | * @return EE_Line_Item for the event subtotal which is a child of $grand_total |
| 747 | 747 | * @throws \EE_Error |
| 748 | 748 | */ |
| 749 | - public static function get_event_line_item( EE_Line_Item $grand_total, $event ) { |
|
| 749 | + public static function get_event_line_item(EE_Line_Item $grand_total, $event) { |
|
| 750 | 750 | /** @type EE_Event $event */ |
| 751 | - $event = EEM_Event::instance()->ensure_is_obj( $event, true ); |
|
| 751 | + $event = EEM_Event::instance()->ensure_is_obj($event, true); |
|
| 752 | 752 | $event_line_item = NULL; |
| 753 | 753 | $found = false; |
| 754 | - foreach ( EEH_Line_Item::get_event_subtotals( $grand_total ) as $event_line_item ) { |
|
| 754 | + foreach (EEH_Line_Item::get_event_subtotals($grand_total) as $event_line_item) { |
|
| 755 | 755 | // default event subtotal, we should only ever find this the first time this method is called |
| 756 | - if ( ! $event_line_item->OBJ_ID() ) { |
|
| 756 | + if ( ! $event_line_item->OBJ_ID()) { |
|
| 757 | 757 | // let's use this! but first... set the event details |
| 758 | - EEH_Line_Item::set_event_subtotal_details( $event_line_item, $event ); |
|
| 758 | + EEH_Line_Item::set_event_subtotal_details($event_line_item, $event); |
|
| 759 | 759 | $found = true; |
| 760 | 760 | break; |
| 761 | - } else if ( $event_line_item->OBJ_ID() === $event->ID() ) { |
|
| 761 | + } else if ($event_line_item->OBJ_ID() === $event->ID()) { |
|
| 762 | 762 | // found existing line item for this event in the cart, so break out of loop and use this one |
| 763 | 763 | $found = true; |
| 764 | 764 | break; |
| 765 | 765 | } |
| 766 | 766 | } |
| 767 | - if ( ! $found ) { |
|
| 767 | + if ( ! $found) { |
|
| 768 | 768 | //there is no event sub-total yet, so add it |
| 769 | - $pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal( $grand_total ); |
|
| 769 | + $pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal($grand_total); |
|
| 770 | 770 | // create a new "event" subtotal below that |
| 771 | - $event_line_item = EEH_Line_Item::create_event_subtotal( $pre_tax_subtotal, null, $event ); |
|
| 771 | + $event_line_item = EEH_Line_Item::create_event_subtotal($pre_tax_subtotal, null, $event); |
|
| 772 | 772 | // and set the event details |
| 773 | - EEH_Line_Item::set_event_subtotal_details( $event_line_item, $event ); |
|
| 773 | + EEH_Line_Item::set_event_subtotal_details($event_line_item, $event); |
|
| 774 | 774 | } |
| 775 | 775 | return $event_line_item; |
| 776 | 776 | } |
@@ -791,13 +791,13 @@ discard block |
||
| 791 | 791 | EE_Event $event, |
| 792 | 792 | $transaction = null |
| 793 | 793 | ) { |
| 794 | - if ( $event instanceof EE_Event ) { |
|
| 795 | - $event_line_item->set_code( self::get_event_code( $event ) ); |
|
| 796 | - $event_line_item->set_name( self::get_event_name( $event ) ); |
|
| 797 | - $event_line_item->set_desc( self::get_event_desc( $event ) ); |
|
| 798 | - $event_line_item->set_OBJ_ID( $event->ID() ); |
|
| 794 | + if ($event instanceof EE_Event) { |
|
| 795 | + $event_line_item->set_code(self::get_event_code($event)); |
|
| 796 | + $event_line_item->set_name(self::get_event_name($event)); |
|
| 797 | + $event_line_item->set_desc(self::get_event_desc($event)); |
|
| 798 | + $event_line_item->set_OBJ_ID($event->ID()); |
|
| 799 | 799 | } |
| 800 | - self::set_TXN_ID( $event_line_item, $transaction ); |
|
| 800 | + self::set_TXN_ID($event_line_item, $transaction); |
|
| 801 | 801 | } |
| 802 | 802 | |
| 803 | 803 | |
@@ -810,19 +810,19 @@ discard block |
||
| 810 | 810 | * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
| 811 | 811 | * @throws \EE_Error |
| 812 | 812 | */ |
| 813 | - public static function apply_taxes( EE_Line_Item $total_line_item ){ |
|
| 813 | + public static function apply_taxes(EE_Line_Item $total_line_item) { |
|
| 814 | 814 | /** @type EEM_Price $EEM_Price */ |
| 815 | - $EEM_Price = EE_Registry::instance()->load_model( 'Price' ); |
|
| 815 | + $EEM_Price = EE_Registry::instance()->load_model('Price'); |
|
| 816 | 816 | // get array of taxes via Price Model |
| 817 | 817 | $ordered_taxes = $EEM_Price->get_all_prices_that_are_taxes(); |
| 818 | - ksort( $ordered_taxes ); |
|
| 819 | - $taxes_line_item = self::get_taxes_subtotal( $total_line_item ); |
|
| 818 | + ksort($ordered_taxes); |
|
| 819 | + $taxes_line_item = self::get_taxes_subtotal($total_line_item); |
|
| 820 | 820 | //just to be safe, remove its old tax line items |
| 821 | 821 | $taxes_line_item->delete_children_line_items(); |
| 822 | 822 | //loop thru taxes |
| 823 | - foreach ( $ordered_taxes as $order => $taxes ) { |
|
| 824 | - foreach ( $taxes as $tax ) { |
|
| 825 | - if ( $tax instanceof EE_Price ) { |
|
| 823 | + foreach ($ordered_taxes as $order => $taxes) { |
|
| 824 | + foreach ($taxes as $tax) { |
|
| 825 | + if ($tax instanceof EE_Price) { |
|
| 826 | 826 | $tax_line_item = EE_Line_Item::new_instance( |
| 827 | 827 | array( |
| 828 | 828 | 'LIN_name' => $tax->name(), |
@@ -840,7 +840,7 @@ discard block |
||
| 840 | 840 | 'FHEE__EEH_Line_Item__apply_taxes__tax_line_item', |
| 841 | 841 | $tax_line_item |
| 842 | 842 | ); |
| 843 | - $taxes_line_item->add_child_line_item( $tax_line_item ); |
|
| 843 | + $taxes_line_item->add_child_line_item($tax_line_item); |
|
| 844 | 844 | } |
| 845 | 845 | } |
| 846 | 846 | } |
@@ -857,10 +857,10 @@ discard block |
||
| 857 | 857 | * @return float |
| 858 | 858 | * @throws \EE_Error |
| 859 | 859 | */ |
| 860 | - public static function ensure_taxes_applied( $total_line_item ){ |
|
| 861 | - $taxes_subtotal = self::get_taxes_subtotal( $total_line_item ); |
|
| 862 | - if( ! $taxes_subtotal->children()){ |
|
| 863 | - self::apply_taxes( $total_line_item ); |
|
| 860 | + public static function ensure_taxes_applied($total_line_item) { |
|
| 861 | + $taxes_subtotal = self::get_taxes_subtotal($total_line_item); |
|
| 862 | + if ( ! $taxes_subtotal->children()) { |
|
| 863 | + self::apply_taxes($total_line_item); |
|
| 864 | 864 | } |
| 865 | 865 | return $taxes_subtotal->total(); |
| 866 | 866 | } |
@@ -874,16 +874,16 @@ discard block |
||
| 874 | 874 | * @return bool |
| 875 | 875 | * @throws \EE_Error |
| 876 | 876 | */ |
| 877 | - public static function delete_all_child_items( EE_Line_Item $parent_line_item ) { |
|
| 877 | + public static function delete_all_child_items(EE_Line_Item $parent_line_item) { |
|
| 878 | 878 | $deleted = 0; |
| 879 | - foreach ( $parent_line_item->children() as $child_line_item ) { |
|
| 880 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
| 881 | - $deleted += EEH_Line_Item::delete_all_child_items( $child_line_item ); |
|
| 882 | - if ( $child_line_item->ID() ) { |
|
| 879 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
| 880 | + if ($child_line_item instanceof EE_Line_Item) { |
|
| 881 | + $deleted += EEH_Line_Item::delete_all_child_items($child_line_item); |
|
| 882 | + if ($child_line_item->ID()) { |
|
| 883 | 883 | $child_line_item->delete(); |
| 884 | - unset( $child_line_item ); |
|
| 884 | + unset($child_line_item); |
|
| 885 | 885 | } else { |
| 886 | - $parent_line_item->delete_child_line_item( $child_line_item->code() ); |
|
| 886 | + $parent_line_item->delete_child_line_item($child_line_item->code()); |
|
| 887 | 887 | } |
| 888 | 888 | $deleted++; |
| 889 | 889 | } |
@@ -905,9 +905,9 @@ discard block |
||
| 905 | 905 | * @param array|bool|string $line_item_codes |
| 906 | 906 | * @return int number of items successfully removed |
| 907 | 907 | */ |
| 908 | - public static function delete_items( EE_Line_Item $total_line_item, $line_item_codes = FALSE ) { |
|
| 908 | + public static function delete_items(EE_Line_Item $total_line_item, $line_item_codes = FALSE) { |
|
| 909 | 909 | |
| 910 | - if( $total_line_item->type() !== EEM_Line_Item::type_total ){ |
|
| 910 | + if ($total_line_item->type() !== EEM_Line_Item::type_total) { |
|
| 911 | 911 | EE_Error::doing_it_wrong( |
| 912 | 912 | 'EEH_Line_Item::delete_items', |
| 913 | 913 | __( |
@@ -917,20 +917,20 @@ discard block |
||
| 917 | 917 | '4.6.18' |
| 918 | 918 | ); |
| 919 | 919 | } |
| 920 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
| 920 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 921 | 921 | |
| 922 | 922 | // check if only a single line_item_id was passed |
| 923 | - if ( ! empty( $line_item_codes ) && ! is_array( $line_item_codes )) { |
|
| 923 | + if ( ! empty($line_item_codes) && ! is_array($line_item_codes)) { |
|
| 924 | 924 | // place single line_item_id in an array to appear as multiple line_item_ids |
| 925 | - $line_item_codes = array ( $line_item_codes ); |
|
| 925 | + $line_item_codes = array($line_item_codes); |
|
| 926 | 926 | } |
| 927 | 927 | $removals = 0; |
| 928 | 928 | // cycle thru line_item_ids |
| 929 | - foreach ( $line_item_codes as $line_item_id ) { |
|
| 929 | + foreach ($line_item_codes as $line_item_id) { |
|
| 930 | 930 | $removals += $total_line_item->delete_child_line_item($line_item_id); |
| 931 | 931 | } |
| 932 | 932 | |
| 933 | - if ( $removals > 0 ) { |
|
| 933 | + if ($removals > 0) { |
|
| 934 | 934 | $total_line_item->recalculate_taxes_and_tax_total(); |
| 935 | 935 | return $removals; |
| 936 | 936 | } else { |
@@ -963,33 +963,33 @@ discard block |
||
| 963 | 963 | $code = null, |
| 964 | 964 | $add_to_existing_line_item = false |
| 965 | 965 | ) { |
| 966 | - $tax_subtotal = self::get_taxes_subtotal( $total_line_item ); |
|
| 966 | + $tax_subtotal = self::get_taxes_subtotal($total_line_item); |
|
| 967 | 967 | $taxable_total = $total_line_item->taxable_total(); |
| 968 | 968 | |
| 969 | - if( $add_to_existing_line_item ) { |
|
| 970 | - $new_tax = $tax_subtotal->get_child_line_item( $code ); |
|
| 969 | + if ($add_to_existing_line_item) { |
|
| 970 | + $new_tax = $tax_subtotal->get_child_line_item($code); |
|
| 971 | 971 | EEM_Line_Item::instance()->delete( |
| 972 | - array( array( 'LIN_code' => array( '!=', $code ), 'LIN_parent' => $tax_subtotal->ID() ) ) |
|
| 972 | + array(array('LIN_code' => array('!=', $code), 'LIN_parent' => $tax_subtotal->ID())) |
|
| 973 | 973 | ); |
| 974 | 974 | } else { |
| 975 | 975 | $new_tax = null; |
| 976 | 976 | $tax_subtotal->delete_children_line_items(); |
| 977 | 977 | } |
| 978 | - if( $new_tax ) { |
|
| 979 | - $new_tax->set_total( $new_tax->total() + $amount ); |
|
| 980 | - $new_tax->set_percent( $taxable_total ? $new_tax->total() / $taxable_total * 100 : 0 ); |
|
| 978 | + if ($new_tax) { |
|
| 979 | + $new_tax->set_total($new_tax->total() + $amount); |
|
| 980 | + $new_tax->set_percent($taxable_total ? $new_tax->total() / $taxable_total * 100 : 0); |
|
| 981 | 981 | } else { |
| 982 | 982 | //no existing tax item. Create it |
| 983 | - $new_tax = EE_Line_Item::new_instance( array( |
|
| 983 | + $new_tax = EE_Line_Item::new_instance(array( |
|
| 984 | 984 | 'TXN_ID' => $total_line_item->TXN_ID(), |
| 985 | - 'LIN_name' => $name ? $name : __( 'Tax', 'event_espresso' ), |
|
| 985 | + 'LIN_name' => $name ? $name : __('Tax', 'event_espresso'), |
|
| 986 | 986 | 'LIN_desc' => $description ? $description : '', |
| 987 | - 'LIN_percent' => $taxable_total ? ( $amount / $taxable_total * 100 ) : 0, |
|
| 987 | + 'LIN_percent' => $taxable_total ? ($amount / $taxable_total * 100) : 0, |
|
| 988 | 988 | 'LIN_total' => $amount, |
| 989 | 989 | 'LIN_parent' => $tax_subtotal->ID(), |
| 990 | 990 | 'LIN_type' => EEM_Line_Item::type_tax, |
| 991 | 991 | 'LIN_code' => $code |
| 992 | - ) ); |
|
| 992 | + )); |
|
| 993 | 993 | } |
| 994 | 994 | |
| 995 | 995 | $new_tax = apply_filters( |
@@ -998,7 +998,7 @@ discard block |
||
| 998 | 998 | $total_line_item |
| 999 | 999 | ); |
| 1000 | 1000 | $new_tax->save(); |
| 1001 | - $tax_subtotal->set_total( $new_tax->total() ); |
|
| 1001 | + $tax_subtotal->set_total($new_tax->total()); |
|
| 1002 | 1002 | $tax_subtotal->save(); |
| 1003 | 1003 | $total_line_item->recalculate_total_including_taxes(); |
| 1004 | 1004 | return $new_tax; |
@@ -1020,14 +1020,14 @@ discard block |
||
| 1020 | 1020 | $code_substring_for_whitelist = null |
| 1021 | 1021 | ) { |
| 1022 | 1022 | $whitelisted = false; |
| 1023 | - if( $code_substring_for_whitelist !== null ) { |
|
| 1024 | - $whitelisted = strpos( $line_item->code(), $code_substring_for_whitelist ) !== false ? true : false; |
|
| 1023 | + if ($code_substring_for_whitelist !== null) { |
|
| 1024 | + $whitelisted = strpos($line_item->code(), $code_substring_for_whitelist) !== false ? true : false; |
|
| 1025 | 1025 | } |
| 1026 | - if( ! $whitelisted && $line_item->is_line_item() ) { |
|
| 1027 | - $line_item->set_is_taxable( $taxable ); |
|
| 1026 | + if ( ! $whitelisted && $line_item->is_line_item()) { |
|
| 1027 | + $line_item->set_is_taxable($taxable); |
|
| 1028 | 1028 | } |
| 1029 | - foreach( $line_item->children() as $child_line_item ) { |
|
| 1030 | - EEH_Line_Item::set_line_items_taxable( $child_line_item, $taxable, $code_substring_for_whitelist ); |
|
| 1029 | + foreach ($line_item->children() as $child_line_item) { |
|
| 1030 | + EEH_Line_Item::set_line_items_taxable($child_line_item, $taxable, $code_substring_for_whitelist); |
|
| 1031 | 1031 | } |
| 1032 | 1032 | } |
| 1033 | 1033 | |
@@ -1040,8 +1040,8 @@ discard block |
||
| 1040 | 1040 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
| 1041 | 1041 | * @return EE_Line_Item[] |
| 1042 | 1042 | */ |
| 1043 | - public static function get_event_subtotals( EE_Line_Item $parent_line_item ) { |
|
| 1044 | - return self::get_subtotals_of_object_type( $parent_line_item, 'Event' ); |
|
| 1043 | + public static function get_event_subtotals(EE_Line_Item $parent_line_item) { |
|
| 1044 | + return self::get_subtotals_of_object_type($parent_line_item, 'Event'); |
|
| 1045 | 1045 | } |
| 1046 | 1046 | |
| 1047 | 1047 | |
@@ -1054,7 +1054,7 @@ discard block |
||
| 1054 | 1054 | * @param string $obj_type |
| 1055 | 1055 | * @return EE_Line_Item[] |
| 1056 | 1056 | */ |
| 1057 | - public static function get_subtotals_of_object_type( EE_Line_Item $parent_line_item, $obj_type = '' ) { |
|
| 1057 | + public static function get_subtotals_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') { |
|
| 1058 | 1058 | return self::_get_descendants_by_type_and_object_type( |
| 1059 | 1059 | $parent_line_item, |
| 1060 | 1060 | EEM_Line_Item::type_sub_total, |
@@ -1071,8 +1071,8 @@ discard block |
||
| 1071 | 1071 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
| 1072 | 1072 | * @return EE_Line_Item[] |
| 1073 | 1073 | */ |
| 1074 | - public static function get_ticket_line_items( EE_Line_Item $parent_line_item ) { |
|
| 1075 | - return self::get_line_items_of_object_type( $parent_line_item, 'Ticket' ); |
|
| 1074 | + public static function get_ticket_line_items(EE_Line_Item $parent_line_item) { |
|
| 1075 | + return self::get_line_items_of_object_type($parent_line_item, 'Ticket'); |
|
| 1076 | 1076 | } |
| 1077 | 1077 | |
| 1078 | 1078 | |
@@ -1085,8 +1085,8 @@ discard block |
||
| 1085 | 1085 | * @param string $obj_type |
| 1086 | 1086 | * @return EE_Line_Item[] |
| 1087 | 1087 | */ |
| 1088 | - public static function get_line_items_of_object_type( EE_Line_Item $parent_line_item, $obj_type = '' ) { |
|
| 1089 | - return self::_get_descendants_by_type_and_object_type( $parent_line_item, EEM_Line_Item::type_line_item, $obj_type ); |
|
| 1088 | + public static function get_line_items_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') { |
|
| 1089 | + return self::_get_descendants_by_type_and_object_type($parent_line_item, EEM_Line_Item::type_line_item, $obj_type); |
|
| 1090 | 1090 | } |
| 1091 | 1091 | |
| 1092 | 1092 | |
@@ -1097,8 +1097,8 @@ discard block |
||
| 1097 | 1097 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
| 1098 | 1098 | * @return EE_Line_Item[] |
| 1099 | 1099 | */ |
| 1100 | - public static function get_tax_descendants( EE_Line_Item $parent_line_item ) { |
|
| 1101 | - return EEH_Line_Item::get_descendants_of_type( $parent_line_item, EEM_Line_Item::type_tax ); |
|
| 1100 | + public static function get_tax_descendants(EE_Line_Item $parent_line_item) { |
|
| 1101 | + return EEH_Line_Item::get_descendants_of_type($parent_line_item, EEM_Line_Item::type_tax); |
|
| 1102 | 1102 | } |
| 1103 | 1103 | |
| 1104 | 1104 | |
@@ -1109,8 +1109,8 @@ discard block |
||
| 1109 | 1109 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
| 1110 | 1110 | * @return EE_Line_Item[] |
| 1111 | 1111 | */ |
| 1112 | - public static function get_line_item_descendants( EE_Line_Item $parent_line_item ) { |
|
| 1113 | - return EEH_Line_Item::get_descendants_of_type( $parent_line_item, EEM_Line_Item::type_line_item ); |
|
| 1112 | + public static function get_line_item_descendants(EE_Line_Item $parent_line_item) { |
|
| 1113 | + return EEH_Line_Item::get_descendants_of_type($parent_line_item, EEM_Line_Item::type_line_item); |
|
| 1114 | 1114 | } |
| 1115 | 1115 | |
| 1116 | 1116 | |
@@ -1123,8 +1123,8 @@ discard block |
||
| 1123 | 1123 | * @param string $line_item_type one of the EEM_Line_Item constants |
| 1124 | 1124 | * @return EE_Line_Item[] |
| 1125 | 1125 | */ |
| 1126 | - public static function get_descendants_of_type( EE_Line_Item $parent_line_item, $line_item_type ) { |
|
| 1127 | - return self::_get_descendants_by_type_and_object_type( $parent_line_item, $line_item_type, NULL ); |
|
| 1126 | + public static function get_descendants_of_type(EE_Line_Item $parent_line_item, $line_item_type) { |
|
| 1127 | + return self::_get_descendants_by_type_and_object_type($parent_line_item, $line_item_type, NULL); |
|
| 1128 | 1128 | } |
| 1129 | 1129 | |
| 1130 | 1130 | |
@@ -1143,8 +1143,8 @@ discard block |
||
| 1143 | 1143 | $obj_type = null |
| 1144 | 1144 | ) { |
| 1145 | 1145 | $objects = array(); |
| 1146 | - foreach ( $parent_line_item->children() as $child_line_item ) { |
|
| 1147 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
| 1146 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
| 1147 | + if ($child_line_item instanceof EE_Line_Item) { |
|
| 1148 | 1148 | if ( |
| 1149 | 1149 | $child_line_item->type() === $line_item_type |
| 1150 | 1150 | && ( |
@@ -1184,7 +1184,7 @@ discard block |
||
| 1184 | 1184 | $OBJ_type = '', |
| 1185 | 1185 | $OBJ_IDs = array() |
| 1186 | 1186 | ) { |
| 1187 | - return self::_get_descendants_by_object_type_and_object_ID( $parent_line_item, $OBJ_type, $OBJ_IDs ); |
|
| 1187 | + return self::_get_descendants_by_object_type_and_object_ID($parent_line_item, $OBJ_type, $OBJ_IDs); |
|
| 1188 | 1188 | } |
| 1189 | 1189 | |
| 1190 | 1190 | |
@@ -1203,12 +1203,12 @@ discard block |
||
| 1203 | 1203 | $OBJ_IDs |
| 1204 | 1204 | ) { |
| 1205 | 1205 | $objects = array(); |
| 1206 | - foreach ( $parent_line_item->children() as $child_line_item ) { |
|
| 1207 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
| 1206 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
| 1207 | + if ($child_line_item instanceof EE_Line_Item) { |
|
| 1208 | 1208 | if ( |
| 1209 | 1209 | $child_line_item->OBJ_type() === $OBJ_type |
| 1210 | - && is_array( $OBJ_IDs ) |
|
| 1211 | - && in_array( $child_line_item->OBJ_ID(), $OBJ_IDs ) |
|
| 1210 | + && is_array($OBJ_IDs) |
|
| 1211 | + && in_array($child_line_item->OBJ_ID(), $OBJ_IDs) |
|
| 1212 | 1212 | ) { |
| 1213 | 1213 | $objects[] = $child_line_item; |
| 1214 | 1214 | } else { |
@@ -1238,8 +1238,8 @@ discard block |
||
| 1238 | 1238 | * @param string $type like one of the EEM_Line_Item::type_* |
| 1239 | 1239 | * @return EE_Line_Item |
| 1240 | 1240 | */ |
| 1241 | - public static function get_nearest_descendant_of_type( EE_Line_Item $parent_line_item, $type ) { |
|
| 1242 | - return self::_get_nearest_descendant( $parent_line_item, 'LIN_type' , $type ); |
|
| 1241 | + public static function get_nearest_descendant_of_type(EE_Line_Item $parent_line_item, $type) { |
|
| 1242 | + return self::_get_nearest_descendant($parent_line_item, 'LIN_type', $type); |
|
| 1243 | 1243 | } |
| 1244 | 1244 | |
| 1245 | 1245 | |
@@ -1253,8 +1253,8 @@ discard block |
||
| 1253 | 1253 | * @param string $code any value used for LIN_code |
| 1254 | 1254 | * @return EE_Line_Item |
| 1255 | 1255 | */ |
| 1256 | - public static function get_nearest_descendant_having_code( EE_Line_Item $parent_line_item, $code ) { |
|
| 1257 | - return self::_get_nearest_descendant( $parent_line_item, 'LIN_code' , $code ); |
|
| 1256 | + public static function get_nearest_descendant_having_code(EE_Line_Item $parent_line_item, $code) { |
|
| 1257 | + return self::_get_nearest_descendant($parent_line_item, 'LIN_code', $code); |
|
| 1258 | 1258 | } |
| 1259 | 1259 | |
| 1260 | 1260 | |
@@ -1268,15 +1268,15 @@ discard block |
||
| 1268 | 1268 | * @param string $value any value stored in $search_field |
| 1269 | 1269 | * @return EE_Line_Item |
| 1270 | 1270 | */ |
| 1271 | - protected static function _get_nearest_descendant( EE_Line_Item $parent_line_item, $search_field, $value ) { |
|
| 1272 | - foreach( $parent_line_item->children() as $child ){ |
|
| 1273 | - if ( $child->get( $search_field ) == $value ){ |
|
| 1271 | + protected static function _get_nearest_descendant(EE_Line_Item $parent_line_item, $search_field, $value) { |
|
| 1272 | + foreach ($parent_line_item->children() as $child) { |
|
| 1273 | + if ($child->get($search_field) == $value) { |
|
| 1274 | 1274 | return $child; |
| 1275 | 1275 | } |
| 1276 | 1276 | } |
| 1277 | - foreach( $parent_line_item->children() as $child ){ |
|
| 1278 | - $descendant_found = self::_get_nearest_descendant( $child, $search_field, $value ); |
|
| 1279 | - if ( $descendant_found ){ |
|
| 1277 | + foreach ($parent_line_item->children() as $child) { |
|
| 1278 | + $descendant_found = self::_get_nearest_descendant($child, $search_field, $value); |
|
| 1279 | + if ($descendant_found) { |
|
| 1280 | 1280 | return $descendant_found; |
| 1281 | 1281 | } |
| 1282 | 1282 | } |
@@ -1293,24 +1293,24 @@ discard block |
||
| 1293 | 1293 | * @return \EE_Line_Item |
| 1294 | 1294 | * @throws \EE_Error |
| 1295 | 1295 | */ |
| 1296 | - public static function find_transaction_grand_total_for_line_item( EE_Line_Item $line_item ){ |
|
| 1297 | - if ( $line_item->TXN_ID() ) { |
|
| 1298 | - $total_line_item = $line_item->transaction()->total_line_item( false ); |
|
| 1299 | - if ( $total_line_item instanceof EE_Line_Item ) { |
|
| 1296 | + public static function find_transaction_grand_total_for_line_item(EE_Line_Item $line_item) { |
|
| 1297 | + if ($line_item->TXN_ID()) { |
|
| 1298 | + $total_line_item = $line_item->transaction()->total_line_item(false); |
|
| 1299 | + if ($total_line_item instanceof EE_Line_Item) { |
|
| 1300 | 1300 | return $total_line_item; |
| 1301 | 1301 | } |
| 1302 | 1302 | } else { |
| 1303 | 1303 | $line_item_parent = $line_item->parent(); |
| 1304 | - if ( $line_item_parent instanceof EE_Line_Item ) { |
|
| 1305 | - if ( $line_item_parent->is_total() ) { |
|
| 1304 | + if ($line_item_parent instanceof EE_Line_Item) { |
|
| 1305 | + if ($line_item_parent->is_total()) { |
|
| 1306 | 1306 | return $line_item_parent; |
| 1307 | 1307 | } |
| 1308 | - return EEH_Line_Item::find_transaction_grand_total_for_line_item( $line_item_parent ); |
|
| 1308 | + return EEH_Line_Item::find_transaction_grand_total_for_line_item($line_item_parent); |
|
| 1309 | 1309 | } |
| 1310 | 1310 | } |
| 1311 | 1311 | throw new EE_Error( |
| 1312 | 1312 | sprintf( |
| 1313 | - __( 'A valid grand total for line item %1$d was not found.', 'event_espresso' ), |
|
| 1313 | + __('A valid grand total for line item %1$d was not found.', 'event_espresso'), |
|
| 1314 | 1314 | $line_item->ID() |
| 1315 | 1315 | ) |
| 1316 | 1316 | ); |
@@ -1327,31 +1327,31 @@ discard block |
||
| 1327 | 1327 | * @return void |
| 1328 | 1328 | * @throws \EE_Error |
| 1329 | 1329 | */ |
| 1330 | - public static function visualize( EE_Line_Item $line_item, $indentation = 0 ){ |
|
| 1330 | + public static function visualize(EE_Line_Item $line_item, $indentation = 0) { |
|
| 1331 | 1331 | echo defined('EE_TESTS_DIR') ? "\n" : '<br />'; |
| 1332 | - if ( ! $indentation ) { |
|
| 1333 | - echo defined( 'EE_TESTS_DIR' ) ? "\n" : '<br />'; |
|
| 1332 | + if ( ! $indentation) { |
|
| 1333 | + echo defined('EE_TESTS_DIR') ? "\n" : '<br />'; |
|
| 1334 | 1334 | } |
| 1335 | - for( $i = 0; $i < $indentation; $i++ ){ |
|
| 1335 | + for ($i = 0; $i < $indentation; $i++) { |
|
| 1336 | 1336 | echo ". "; |
| 1337 | 1337 | } |
| 1338 | 1338 | $breakdown = ''; |
| 1339 | - if ( $line_item->is_line_item()){ |
|
| 1340 | - if ( $line_item->is_percent() ) { |
|
| 1339 | + if ($line_item->is_line_item()) { |
|
| 1340 | + if ($line_item->is_percent()) { |
|
| 1341 | 1341 | $breakdown = "{$line_item->percent()}%"; |
| 1342 | 1342 | } else { |
| 1343 | - $breakdown = '$' . "{$line_item->unit_price()} x {$line_item->quantity()}"; |
|
| 1343 | + $breakdown = '$'."{$line_item->unit_price()} x {$line_item->quantity()}"; |
|
| 1344 | 1344 | } |
| 1345 | 1345 | } |
| 1346 | - echo $line_item->name() . " [ ID:{$line_item->ID()} | qty:{$line_item->quantity()} ] {$line_item->type()} : " . '$' . "{$line_item->total()}"; |
|
| 1347 | - if ( $breakdown ) { |
|
| 1346 | + echo $line_item->name()." [ ID:{$line_item->ID()} | qty:{$line_item->quantity()} ] {$line_item->type()} : ".'$'."{$line_item->total()}"; |
|
| 1347 | + if ($breakdown) { |
|
| 1348 | 1348 | echo " ( {$breakdown} )"; |
| 1349 | 1349 | } |
| 1350 | - if( $line_item->is_taxable() ){ |
|
| 1350 | + if ($line_item->is_taxable()) { |
|
| 1351 | 1351 | echo " * taxable"; |
| 1352 | 1352 | } |
| 1353 | - if( $line_item->children() ){ |
|
| 1354 | - foreach($line_item->children() as $child){ |
|
| 1353 | + if ($line_item->children()) { |
|
| 1354 | + foreach ($line_item->children() as $child) { |
|
| 1355 | 1355 | self::visualize($child, $indentation + 1); |
| 1356 | 1356 | } |
| 1357 | 1357 | } |
@@ -1392,97 +1392,97 @@ discard block |
||
| 1392 | 1392 | * is theirs, which can be done with |
| 1393 | 1393 | * `EEM_Line_Item::instance()->get_line_item_for_registration( $registration );` |
| 1394 | 1394 | */ |
| 1395 | - public static function calculate_reg_final_prices_per_line_item( EE_Line_Item $line_item, $billable_ticket_quantities = array() ) { |
|
| 1395 | + public static function calculate_reg_final_prices_per_line_item(EE_Line_Item $line_item, $billable_ticket_quantities = array()) { |
|
| 1396 | 1396 | //init running grand total if not already |
| 1397 | - if ( ! isset( $running_totals[ 'total' ] ) ) { |
|
| 1398 | - $running_totals[ 'total' ] = 0; |
|
| 1397 | + if ( ! isset($running_totals['total'])) { |
|
| 1398 | + $running_totals['total'] = 0; |
|
| 1399 | 1399 | } |
| 1400 | - if( ! isset( $running_totals[ 'taxable' ] ) ) { |
|
| 1401 | - $running_totals[ 'taxable' ] = array( 'total' => 0 ); |
|
| 1400 | + if ( ! isset($running_totals['taxable'])) { |
|
| 1401 | + $running_totals['taxable'] = array('total' => 0); |
|
| 1402 | 1402 | } |
| 1403 | - foreach ( $line_item->children() as $child_line_item ) { |
|
| 1404 | - switch ( $child_line_item->type() ) { |
|
| 1403 | + foreach ($line_item->children() as $child_line_item) { |
|
| 1404 | + switch ($child_line_item->type()) { |
|
| 1405 | 1405 | |
| 1406 | 1406 | case EEM_Line_Item::type_sub_total : |
| 1407 | - $running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item( $child_line_item, $billable_ticket_quantities ); |
|
| 1407 | + $running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item($child_line_item, $billable_ticket_quantities); |
|
| 1408 | 1408 | //combine arrays but preserve numeric keys |
| 1409 | - $running_totals = array_replace_recursive( $running_totals_from_subtotal, $running_totals ); |
|
| 1410 | - $running_totals[ 'total' ] += $running_totals_from_subtotal[ 'total' ]; |
|
| 1411 | - $running_totals[ 'taxable'][ 'total' ] += $running_totals_from_subtotal[ 'taxable' ][ 'total' ]; |
|
| 1409 | + $running_totals = array_replace_recursive($running_totals_from_subtotal, $running_totals); |
|
| 1410 | + $running_totals['total'] += $running_totals_from_subtotal['total']; |
|
| 1411 | + $running_totals['taxable']['total'] += $running_totals_from_subtotal['taxable']['total']; |
|
| 1412 | 1412 | break; |
| 1413 | 1413 | |
| 1414 | 1414 | case EEM_Line_Item::type_tax_sub_total : |
| 1415 | 1415 | |
| 1416 | 1416 | //find how much the taxes percentage is |
| 1417 | - if ( $child_line_item->percent() !== 0 ) { |
|
| 1417 | + if ($child_line_item->percent() !== 0) { |
|
| 1418 | 1418 | $tax_percent_decimal = $child_line_item->percent() / 100; |
| 1419 | 1419 | } else { |
| 1420 | 1420 | $tax_percent_decimal = EE_Taxes::get_total_taxes_percentage() / 100; |
| 1421 | 1421 | } |
| 1422 | 1422 | //and apply to all the taxable totals, and add to the pretax totals |
| 1423 | - foreach ( $running_totals as $line_item_id => $this_running_total ) { |
|
| 1423 | + foreach ($running_totals as $line_item_id => $this_running_total) { |
|
| 1424 | 1424 | //"total" and "taxable" array key is an exception |
| 1425 | - if ( $line_item_id === 'taxable' ) { |
|
| 1425 | + if ($line_item_id === 'taxable') { |
|
| 1426 | 1426 | continue; |
| 1427 | 1427 | } |
| 1428 | - $taxable_total = $running_totals[ 'taxable' ][ $line_item_id ]; |
|
| 1429 | - $running_totals[ $line_item_id ] += ( $taxable_total * $tax_percent_decimal ); |
|
| 1428 | + $taxable_total = $running_totals['taxable'][$line_item_id]; |
|
| 1429 | + $running_totals[$line_item_id] += ($taxable_total * $tax_percent_decimal); |
|
| 1430 | 1430 | } |
| 1431 | 1431 | break; |
| 1432 | 1432 | |
| 1433 | 1433 | case EEM_Line_Item::type_line_item : |
| 1434 | 1434 | |
| 1435 | 1435 | // ticket line items or ???? |
| 1436 | - if ( $child_line_item->OBJ_type() === 'Ticket' ) { |
|
| 1436 | + if ($child_line_item->OBJ_type() === 'Ticket') { |
|
| 1437 | 1437 | // kk it's a ticket |
| 1438 | - if ( isset( $running_totals[ $child_line_item->ID() ] ) ) { |
|
| 1438 | + if (isset($running_totals[$child_line_item->ID()])) { |
|
| 1439 | 1439 | //huh? that shouldn't happen. |
| 1440 | - $running_totals[ 'total' ] += $child_line_item->total(); |
|
| 1440 | + $running_totals['total'] += $child_line_item->total(); |
|
| 1441 | 1441 | } else { |
| 1442 | 1442 | //its not in our running totals yet. great. |
| 1443 | - if ( $child_line_item->is_taxable() ) { |
|
| 1443 | + if ($child_line_item->is_taxable()) { |
|
| 1444 | 1444 | $taxable_amount = $child_line_item->unit_price(); |
| 1445 | 1445 | } else { |
| 1446 | 1446 | $taxable_amount = 0; |
| 1447 | 1447 | } |
| 1448 | 1448 | // are we only calculating totals for some tickets? |
| 1449 | - if ( isset( $billable_ticket_quantities[ $child_line_item->OBJ_ID() ] ) ) { |
|
| 1450 | - $quantity = $billable_ticket_quantities[ $child_line_item->OBJ_ID() ]; |
|
| 1451 | - $running_totals[ $child_line_item->ID() ] = $quantity |
|
| 1449 | + if (isset($billable_ticket_quantities[$child_line_item->OBJ_ID()])) { |
|
| 1450 | + $quantity = $billable_ticket_quantities[$child_line_item->OBJ_ID()]; |
|
| 1451 | + $running_totals[$child_line_item->ID()] = $quantity |
|
| 1452 | 1452 | ? $child_line_item->unit_price() |
| 1453 | 1453 | : 0; |
| 1454 | - $running_totals[ 'taxable' ][ $child_line_item->ID() ] = $quantity |
|
| 1454 | + $running_totals['taxable'][$child_line_item->ID()] = $quantity |
|
| 1455 | 1455 | ? $taxable_amount |
| 1456 | 1456 | : 0; |
| 1457 | 1457 | } else { |
| 1458 | 1458 | $quantity = $child_line_item->quantity(); |
| 1459 | - $running_totals[ $child_line_item->ID() ] = $child_line_item->unit_price(); |
|
| 1460 | - $running_totals[ 'taxable' ][ $child_line_item->ID() ] = $taxable_amount; |
|
| 1459 | + $running_totals[$child_line_item->ID()] = $child_line_item->unit_price(); |
|
| 1460 | + $running_totals['taxable'][$child_line_item->ID()] = $taxable_amount; |
|
| 1461 | 1461 | } |
| 1462 | - $running_totals[ 'taxable' ][ 'total' ] += $taxable_amount * $quantity; |
|
| 1463 | - $running_totals[ 'total' ] += $child_line_item->unit_price() * $quantity; |
|
| 1462 | + $running_totals['taxable']['total'] += $taxable_amount * $quantity; |
|
| 1463 | + $running_totals['total'] += $child_line_item->unit_price() * $quantity; |
|
| 1464 | 1464 | } |
| 1465 | 1465 | } else { |
| 1466 | 1466 | // it's some other type of item added to the cart |
| 1467 | 1467 | // it should affect the running totals |
| 1468 | 1468 | // basically we want to convert it into a PERCENT modifier. Because |
| 1469 | 1469 | // more clearly affect all registration's final price equally |
| 1470 | - $line_items_percent_of_running_total = $running_totals[ 'total' ] > 0 |
|
| 1471 | - ? ( $child_line_item->total() / $running_totals[ 'total' ] ) + 1 |
|
| 1470 | + $line_items_percent_of_running_total = $running_totals['total'] > 0 |
|
| 1471 | + ? ($child_line_item->total() / $running_totals['total']) + 1 |
|
| 1472 | 1472 | : 1; |
| 1473 | - foreach ( $running_totals as $line_item_id => $this_running_total ) { |
|
| 1473 | + foreach ($running_totals as $line_item_id => $this_running_total) { |
|
| 1474 | 1474 | //the "taxable" array key is an exception |
| 1475 | - if ( $line_item_id === 'taxable' ) { |
|
| 1475 | + if ($line_item_id === 'taxable') { |
|
| 1476 | 1476 | continue; |
| 1477 | 1477 | } |
| 1478 | 1478 | // update the running totals |
| 1479 | 1479 | // yes this actually even works for the running grand total! |
| 1480 | - $running_totals[ $line_item_id ] = |
|
| 1480 | + $running_totals[$line_item_id] = |
|
| 1481 | 1481 | $line_items_percent_of_running_total * $this_running_total; |
| 1482 | 1482 | |
| 1483 | - if ( $child_line_item->is_taxable() ) { |
|
| 1484 | - $running_totals[ 'taxable' ][ $line_item_id ] = |
|
| 1485 | - $line_items_percent_of_running_total * $running_totals[ 'taxable' ][ $line_item_id ]; |
|
| 1483 | + if ($child_line_item->is_taxable()) { |
|
| 1484 | + $running_totals['taxable'][$line_item_id] = |
|
| 1485 | + $line_items_percent_of_running_total * $running_totals['taxable'][$line_item_id]; |
|
| 1486 | 1486 | } |
| 1487 | 1487 | } |
| 1488 | 1488 | } |
@@ -1500,16 +1500,16 @@ discard block |
||
| 1500 | 1500 | * @return float | null |
| 1501 | 1501 | * @throws \OutOfRangeException |
| 1502 | 1502 | */ |
| 1503 | - public static function calculate_final_price_for_ticket_line_item( \EE_Line_Item $total_line_item, \EE_Line_Item $ticket_line_item ) { |
|
| 1503 | + public static function calculate_final_price_for_ticket_line_item(\EE_Line_Item $total_line_item, \EE_Line_Item $ticket_line_item) { |
|
| 1504 | 1504 | static $final_prices_per_ticket_line_item = array(); |
| 1505 | - if ( empty( $final_prices_per_ticket_line_item ) ) { |
|
| 1505 | + if (empty($final_prices_per_ticket_line_item)) { |
|
| 1506 | 1506 | $final_prices_per_ticket_line_item = \EEH_Line_Item::calculate_reg_final_prices_per_line_item( |
| 1507 | 1507 | $total_line_item |
| 1508 | 1508 | ); |
| 1509 | 1509 | } |
| 1510 | 1510 | //ok now find this new registration's final price |
| 1511 | - if ( isset( $final_prices_per_ticket_line_item[ $ticket_line_item->ID() ] ) ) { |
|
| 1512 | - return $final_prices_per_ticket_line_item[ $ticket_line_item->ID() ]; |
|
| 1511 | + if (isset($final_prices_per_ticket_line_item[$ticket_line_item->ID()])) { |
|
| 1512 | + return $final_prices_per_ticket_line_item[$ticket_line_item->ID()]; |
|
| 1513 | 1513 | } |
| 1514 | 1514 | $message = sprintf( |
| 1515 | 1515 | __( |
@@ -1518,11 +1518,11 @@ discard block |
||
| 1518 | 1518 | ), |
| 1519 | 1519 | $ticket_line_item->ID() |
| 1520 | 1520 | ); |
| 1521 | - if ( WP_DEBUG ) { |
|
| 1522 | - $message .= '<br>' . print_r( $final_prices_per_ticket_line_item, true ); |
|
| 1523 | - throw new \OutOfRangeException( $message ); |
|
| 1521 | + if (WP_DEBUG) { |
|
| 1522 | + $message .= '<br>'.print_r($final_prices_per_ticket_line_item, true); |
|
| 1523 | + throw new \OutOfRangeException($message); |
|
| 1524 | 1524 | } else { |
| 1525 | - EE_Log::instance()->log( __CLASS__, __FUNCTION__, $message ); |
|
| 1525 | + EE_Log::instance()->log(__CLASS__, __FUNCTION__, $message); |
|
| 1526 | 1526 | } |
| 1527 | 1527 | return null; |
| 1528 | 1528 | } |
@@ -1538,15 +1538,15 @@ discard block |
||
| 1538 | 1538 | * @return \EE_Line_Item |
| 1539 | 1539 | * @throws \EE_Error |
| 1540 | 1540 | */ |
| 1541 | - public static function billable_line_item_tree( EE_Line_Item $line_item, $registrations ) { |
|
| 1542 | - $copy_li = EEH_Line_Item::billable_line_item( $line_item, $registrations ); |
|
| 1543 | - foreach ( $line_item->children() as $child_li ) { |
|
| 1544 | - $copy_li->add_child_line_item( EEH_Line_Item::billable_line_item_tree( $child_li, $registrations ) ); |
|
| 1541 | + public static function billable_line_item_tree(EE_Line_Item $line_item, $registrations) { |
|
| 1542 | + $copy_li = EEH_Line_Item::billable_line_item($line_item, $registrations); |
|
| 1543 | + foreach ($line_item->children() as $child_li) { |
|
| 1544 | + $copy_li->add_child_line_item(EEH_Line_Item::billable_line_item_tree($child_li, $registrations)); |
|
| 1545 | 1545 | } |
| 1546 | 1546 | //if this is the grand total line item, make sure the totals all add up |
| 1547 | 1547 | //(we could have duplicated this logic AS we copied the line items, but |
| 1548 | 1548 | //it seems DRYer this way) |
| 1549 | - if ( $copy_li->type() === EEM_Line_Item::type_total ) { |
|
| 1549 | + if ($copy_li->type() === EEM_Line_Item::type_total) { |
|
| 1550 | 1550 | $copy_li->recalculate_total_including_taxes(); |
| 1551 | 1551 | } |
| 1552 | 1552 | return $copy_li; |
@@ -1563,24 +1563,24 @@ discard block |
||
| 1563 | 1563 | * @throws \EE_Error |
| 1564 | 1564 | * @param EE_Registration[] $registrations |
| 1565 | 1565 | */ |
| 1566 | - public static function billable_line_item( EE_Line_Item $line_item, $registrations ) { |
|
| 1566 | + public static function billable_line_item(EE_Line_Item $line_item, $registrations) { |
|
| 1567 | 1567 | $new_li_fields = $line_item->model_field_array(); |
| 1568 | - if ( $line_item->type() === EEM_Line_Item::type_line_item && |
|
| 1568 | + if ($line_item->type() === EEM_Line_Item::type_line_item && |
|
| 1569 | 1569 | $line_item->OBJ_type() === 'Ticket' |
| 1570 | 1570 | ) { |
| 1571 | 1571 | $count = 0; |
| 1572 | - foreach ( $registrations as $registration ) { |
|
| 1573 | - if ( $line_item->OBJ_ID() === $registration->ticket_ID() && |
|
| 1574 | - in_array( $registration->status_ID(), EEM_Registration::reg_statuses_that_allow_payment() ) |
|
| 1572 | + foreach ($registrations as $registration) { |
|
| 1573 | + if ($line_item->OBJ_ID() === $registration->ticket_ID() && |
|
| 1574 | + in_array($registration->status_ID(), EEM_Registration::reg_statuses_that_allow_payment()) |
|
| 1575 | 1575 | ) { |
| 1576 | 1576 | $count++; |
| 1577 | 1577 | } |
| 1578 | 1578 | } |
| 1579 | - $new_li_fields[ 'LIN_quantity' ] = $count; |
|
| 1579 | + $new_li_fields['LIN_quantity'] = $count; |
|
| 1580 | 1580 | } |
| 1581 | 1581 | //don't set the total. We'll leave that up to the code that calculates it |
| 1582 | - unset( $new_li_fields[ 'LIN_ID' ], $new_li_fields[ 'LIN_parent' ], $new_li_fields[ 'LIN_total' ] ); |
|
| 1583 | - return EE_Line_Item::new_instance( $new_li_fields ); |
|
| 1582 | + unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent'], $new_li_fields['LIN_total']); |
|
| 1583 | + return EE_Line_Item::new_instance($new_li_fields); |
|
| 1584 | 1584 | } |
| 1585 | 1585 | |
| 1586 | 1586 | |
@@ -1593,19 +1593,19 @@ discard block |
||
| 1593 | 1593 | * @return \EE_Line_Item|null |
| 1594 | 1594 | * @throws \EE_Error |
| 1595 | 1595 | */ |
| 1596 | - public static function non_empty_line_items( EE_Line_Item $line_item ) { |
|
| 1597 | - $copied_li = EEH_Line_Item::non_empty_line_item( $line_item ); |
|
| 1598 | - if ( $copied_li === null ) { |
|
| 1596 | + public static function non_empty_line_items(EE_Line_Item $line_item) { |
|
| 1597 | + $copied_li = EEH_Line_Item::non_empty_line_item($line_item); |
|
| 1598 | + if ($copied_li === null) { |
|
| 1599 | 1599 | return null; |
| 1600 | 1600 | } |
| 1601 | 1601 | //if this is an event subtotal, we want to only include it if it |
| 1602 | 1602 | //has a non-zero total and at least one ticket line item child |
| 1603 | 1603 | $ticket_children = 0; |
| 1604 | - foreach ( $line_item->children() as $child_li ) { |
|
| 1605 | - $child_li_copy = EEH_Line_Item::non_empty_line_items( $child_li ); |
|
| 1606 | - if ( $child_li_copy !== null ) { |
|
| 1607 | - $copied_li->add_child_line_item( $child_li_copy ); |
|
| 1608 | - if ( $child_li_copy->type() === EEM_Line_Item::type_line_item && |
|
| 1604 | + foreach ($line_item->children() as $child_li) { |
|
| 1605 | + $child_li_copy = EEH_Line_Item::non_empty_line_items($child_li); |
|
| 1606 | + if ($child_li_copy !== null) { |
|
| 1607 | + $copied_li->add_child_line_item($child_li_copy); |
|
| 1608 | + if ($child_li_copy->type() === EEM_Line_Item::type_line_item && |
|
| 1609 | 1609 | $child_li_copy->OBJ_type() === 'Ticket' |
| 1610 | 1610 | ) { |
| 1611 | 1611 | $ticket_children++; |
@@ -1635,8 +1635,8 @@ discard block |
||
| 1635 | 1635 | * @return EE_Line_Item |
| 1636 | 1636 | * @throws \EE_Error |
| 1637 | 1637 | */ |
| 1638 | - public static function non_empty_line_item( EE_Line_Item $line_item ) { |
|
| 1639 | - if ( $line_item->type() === EEM_Line_Item::type_line_item && |
|
| 1638 | + public static function non_empty_line_item(EE_Line_Item $line_item) { |
|
| 1639 | + if ($line_item->type() === EEM_Line_Item::type_line_item && |
|
| 1640 | 1640 | $line_item->OBJ_type() === 'Ticket' && |
| 1641 | 1641 | $line_item->quantity() === 0 |
| 1642 | 1642 | ) { |
@@ -1644,8 +1644,8 @@ discard block |
||
| 1644 | 1644 | } |
| 1645 | 1645 | $new_li_fields = $line_item->model_field_array(); |
| 1646 | 1646 | //don't set the total. We'll leave that up to the code that calculates it |
| 1647 | - unset( $new_li_fields[ 'LIN_ID' ], $new_li_fields[ 'LIN_parent' ] ); |
|
| 1648 | - return EE_Line_Item::new_instance( $new_li_fields ); |
|
| 1647 | + unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent']); |
|
| 1648 | + return EE_Line_Item::new_instance($new_li_fields); |
|
| 1649 | 1649 | } |
| 1650 | 1650 | |
| 1651 | 1651 | |
@@ -1657,9 +1657,9 @@ discard block |
||
| 1657 | 1657 | * @return \EE_Line_Item |
| 1658 | 1658 | * @throws \EE_Error |
| 1659 | 1659 | */ |
| 1660 | - public static function get_items_subtotal( EE_Line_Item $total_line_item ){ |
|
| 1661 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::get_items_subtotal()', __('Method replaced with EEH_Line_Item::get_pre_tax_subtotal()', 'event_espresso'), '4.6.0' ); |
|
| 1662 | - return self::get_pre_tax_subtotal( $total_line_item ); |
|
| 1660 | + public static function get_items_subtotal(EE_Line_Item $total_line_item) { |
|
| 1661 | + EE_Error::doing_it_wrong('EEH_Line_Item::get_items_subtotal()', __('Method replaced with EEH_Line_Item::get_pre_tax_subtotal()', 'event_espresso'), '4.6.0'); |
|
| 1662 | + return self::get_pre_tax_subtotal($total_line_item); |
|
| 1663 | 1663 | } |
| 1664 | 1664 | |
| 1665 | 1665 | |
@@ -1670,9 +1670,9 @@ discard block |
||
| 1670 | 1670 | * @return \EE_Line_Item |
| 1671 | 1671 | * @throws \EE_Error |
| 1672 | 1672 | */ |
| 1673 | - public static function create_default_total_line_item( $transaction = NULL) { |
|
| 1674 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_total_line_item()', __('Method replaced with EEH_Line_Item::create_total_line_item()', 'event_espresso'), '4.6.0' ); |
|
| 1675 | - return self::create_total_line_item( $transaction ); |
|
| 1673 | + public static function create_default_total_line_item($transaction = NULL) { |
|
| 1674 | + EE_Error::doing_it_wrong('EEH_Line_Item::create_default_total_line_item()', __('Method replaced with EEH_Line_Item::create_total_line_item()', 'event_espresso'), '4.6.0'); |
|
| 1675 | + return self::create_total_line_item($transaction); |
|
| 1676 | 1676 | } |
| 1677 | 1677 | |
| 1678 | 1678 | |
@@ -1684,9 +1684,9 @@ discard block |
||
| 1684 | 1684 | * @return \EE_Line_Item |
| 1685 | 1685 | * @throws \EE_Error |
| 1686 | 1686 | */ |
| 1687 | - public static function create_default_tickets_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) { |
|
| 1688 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_tickets_subtotal()', __('Method replaced with EEH_Line_Item::create_pre_tax_subtotal()', 'event_espresso'), '4.6.0' ); |
|
| 1689 | - return self::create_pre_tax_subtotal( $total_line_item, $transaction ); |
|
| 1687 | + public static function create_default_tickets_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
| 1688 | + EE_Error::doing_it_wrong('EEH_Line_Item::create_default_tickets_subtotal()', __('Method replaced with EEH_Line_Item::create_pre_tax_subtotal()', 'event_espresso'), '4.6.0'); |
|
| 1689 | + return self::create_pre_tax_subtotal($total_line_item, $transaction); |
|
| 1690 | 1690 | } |
| 1691 | 1691 | |
| 1692 | 1692 | |
@@ -1698,9 +1698,9 @@ discard block |
||
| 1698 | 1698 | * @return \EE_Line_Item |
| 1699 | 1699 | * @throws \EE_Error |
| 1700 | 1700 | */ |
| 1701 | - public static function create_default_taxes_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) { |
|
| 1702 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_taxes_subtotal()', __('Method replaced with EEH_Line_Item::create_taxes_subtotal()', 'event_espresso'), '4.6.0' ); |
|
| 1703 | - return self::create_taxes_subtotal( $total_line_item, $transaction ); |
|
| 1701 | + public static function create_default_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
| 1702 | + EE_Error::doing_it_wrong('EEH_Line_Item::create_default_taxes_subtotal()', __('Method replaced with EEH_Line_Item::create_taxes_subtotal()', 'event_espresso'), '4.6.0'); |
|
| 1703 | + return self::create_taxes_subtotal($total_line_item, $transaction); |
|
| 1704 | 1704 | } |
| 1705 | 1705 | |
| 1706 | 1706 | |
@@ -1712,9 +1712,9 @@ discard block |
||
| 1712 | 1712 | * @return \EE_Line_Item |
| 1713 | 1713 | * @throws \EE_Error |
| 1714 | 1714 | */ |
| 1715 | - public static function create_default_event_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) { |
|
| 1716 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_event_subtotal()', __('Method replaced with EEH_Line_Item::create_event_subtotal()', 'event_espresso'), '4.6.0' ); |
|
| 1717 | - return self::create_event_subtotal( $total_line_item, $transaction ); |
|
| 1715 | + public static function create_default_event_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
| 1716 | + EE_Error::doing_it_wrong('EEH_Line_Item::create_default_event_subtotal()', __('Method replaced with EEH_Line_Item::create_event_subtotal()', 'event_espresso'), '4.6.0'); |
|
| 1717 | + return self::create_event_subtotal($total_line_item, $transaction); |
|
| 1718 | 1718 | } |
| 1719 | 1719 | |
| 1720 | 1720 | |