@@ -105,41 +105,41 @@ discard block |
||
| 105 | 105 | * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
| 106 | 106 | * @return \EEM_Line_Item |
| 107 | 107 | */ |
| 108 | - protected function __construct( $timezone ) { |
|
| 109 | - $this->singular_item = __('Line Item','event_espresso'); |
|
| 110 | - $this->plural_item = __('Line Items','event_espresso'); |
|
| 108 | + protected function __construct($timezone) { |
|
| 109 | + $this->singular_item = __('Line Item', 'event_espresso'); |
|
| 110 | + $this->plural_item = __('Line Items', 'event_espresso'); |
|
| 111 | 111 | |
| 112 | 112 | $this->_tables = array( |
| 113 | - 'Line_Item'=>new EE_Primary_Table('esp_line_item','LIN_ID') |
|
| 113 | + 'Line_Item'=>new EE_Primary_Table('esp_line_item', 'LIN_ID') |
|
| 114 | 114 | ); |
| 115 | - $line_items_can_be_for = apply_filters( 'FHEE__EEM_Line_Item__line_items_can_be_for', array('Ticket','Price', 'Event' ) ); |
|
| 115 | + $line_items_can_be_for = apply_filters('FHEE__EEM_Line_Item__line_items_can_be_for', array('Ticket', 'Price', 'Event')); |
|
| 116 | 116 | $this->_fields = array( |
| 117 | 117 | 'Line_Item' => array( |
| 118 | - 'LIN_ID' => new EE_Primary_Key_Int_Field( 'LIN_ID', __( "ID", "event_espresso" ) ), |
|
| 119 | - 'LIN_code' => new EE_Slug_Field( 'LIN_code', __( "Code for index into Cart", "event_espresso" ), TRUE ), |
|
| 120 | - 'TXN_ID' => new EE_Foreign_Key_Int_Field( 'TXN_ID', __( "Transaction ID", "event_espresso" ), TRUE, NULL, 'Transaction' ), |
|
| 121 | - 'LIN_name' => new EE_Full_HTML_Field( 'LIN_name', __( "Line Item Name", "event_espresso" ), FALSE, '' ), |
|
| 122 | - 'LIN_desc' => new EE_Full_HTML_Field( 'LIN_desc', __( "Line Item Description", "event_espresso" ), TRUE ), |
|
| 123 | - 'LIN_unit_price' => new EE_Money_Field( 'LIN_unit_price', __( "Unit Price", "event_espresso" ), FALSE, 0 ), |
|
| 124 | - 'LIN_percent' => new EE_Float_Field( 'LIN_percent', __( "Percent", "event_espresso" ), FALSE, 0 ), |
|
| 125 | - 'LIN_is_taxable' => new EE_Boolean_Field( 'LIN_is_taxable', __( "Taxable", "event_espresso" ), FALSE, FALSE ), |
|
| 126 | - 'LIN_order' => new EE_Integer_Field( 'LIN_order', __( "Order of Application towards total of parent", "event_espresso" ), FALSE, 1 ), |
|
| 127 | - 'LIN_total' => new EE_Money_Field( 'LIN_total', __( "Total (unit price x quantity)", "event_espresso" ), FALSE, 0 ), |
|
| 128 | - 'LIN_quantity' => new EE_Integer_Field( 'LIN_quantity', __( "Quantity", "event_espresso" ), TRUE, 1 ), |
|
| 129 | - 'LIN_parent' => new EE_Integer_Field( 'LIN_parent', __( "Parent ID (this item goes towards that Line Item's total)", "event_espresso" ), TRUE, NULL ), |
|
| 130 | - 'LIN_type' => new EE_Enum_Text_Field( 'LIN_type', __( "Type", "event_espresso" ), FALSE, 'line-item', array( |
|
| 118 | + 'LIN_ID' => new EE_Primary_Key_Int_Field('LIN_ID', __("ID", "event_espresso")), |
|
| 119 | + 'LIN_code' => new EE_Slug_Field('LIN_code', __("Code for index into Cart", "event_espresso"), TRUE), |
|
| 120 | + 'TXN_ID' => new EE_Foreign_Key_Int_Field('TXN_ID', __("Transaction ID", "event_espresso"), TRUE, NULL, 'Transaction'), |
|
| 121 | + 'LIN_name' => new EE_Full_HTML_Field('LIN_name', __("Line Item Name", "event_espresso"), FALSE, ''), |
|
| 122 | + 'LIN_desc' => new EE_Full_HTML_Field('LIN_desc', __("Line Item Description", "event_espresso"), TRUE), |
|
| 123 | + 'LIN_unit_price' => new EE_Money_Field('LIN_unit_price', __("Unit Price", "event_espresso"), FALSE, 0), |
|
| 124 | + 'LIN_percent' => new EE_Float_Field('LIN_percent', __("Percent", "event_espresso"), FALSE, 0), |
|
| 125 | + 'LIN_is_taxable' => new EE_Boolean_Field('LIN_is_taxable', __("Taxable", "event_espresso"), FALSE, FALSE), |
|
| 126 | + 'LIN_order' => new EE_Integer_Field('LIN_order', __("Order of Application towards total of parent", "event_espresso"), FALSE, 1), |
|
| 127 | + 'LIN_total' => new EE_Money_Field('LIN_total', __("Total (unit price x quantity)", "event_espresso"), FALSE, 0), |
|
| 128 | + 'LIN_quantity' => new EE_Integer_Field('LIN_quantity', __("Quantity", "event_espresso"), TRUE, 1), |
|
| 129 | + 'LIN_parent' => new EE_Integer_Field('LIN_parent', __("Parent ID (this item goes towards that Line Item's total)", "event_espresso"), TRUE, NULL), |
|
| 130 | + 'LIN_type' => new EE_Enum_Text_Field('LIN_type', __("Type", "event_espresso"), FALSE, 'line-item', array( |
|
| 131 | 131 | self::type_line_item => __("Line Item", "event_espresso"), |
| 132 | 132 | self::type_sub_line_item => __("Sub-Item", "event_espresso"), |
| 133 | 133 | self::type_sub_total => __("Subtotal", "event_espresso"), |
| 134 | 134 | self::type_tax_sub_total => __("Tax Subtotal", "event_espresso"), |
| 135 | 135 | self::type_tax => __("Tax", "event_espresso"), |
| 136 | 136 | self::type_total => __("Total", "event_espresso"), |
| 137 | - self::type_cancellation => __( 'Cancellation', 'event_espresso' ) |
|
| 137 | + self::type_cancellation => __('Cancellation', 'event_espresso') |
|
| 138 | 138 | ) |
| 139 | 139 | ), |
| 140 | - 'OBJ_ID' => new EE_Foreign_Key_Int_Field( 'OBJ_ID', __( 'ID of Item purchased.', 'event_espresso' ), TRUE, NULL, $line_items_can_be_for ), |
|
| 141 | - 'OBJ_type' =>new EE_Any_Foreign_Model_Name_Field( 'OBJ_type', __( "Model Name this Line Item is for", "event_espresso" ), TRUE, NULL, $line_items_can_be_for ), |
|
| 142 | - 'LIN_timestamp' => new EE_Datetime_Field('LIN_timestamp', __('When the line item was created','event_espresso'), false, EE_Datetime_Field::now, $timezone ), |
|
| 140 | + 'OBJ_ID' => new EE_Foreign_Key_Int_Field('OBJ_ID', __('ID of Item purchased.', 'event_espresso'), TRUE, NULL, $line_items_can_be_for), |
|
| 141 | + 'OBJ_type' =>new EE_Any_Foreign_Model_Name_Field('OBJ_type', __("Model Name this Line Item is for", "event_espresso"), TRUE, NULL, $line_items_can_be_for), |
|
| 142 | + 'LIN_timestamp' => new EE_Datetime_Field('LIN_timestamp', __('When the line item was created', 'event_espresso'), false, EE_Datetime_Field::now, $timezone), |
|
| 143 | 143 | ) |
| 144 | 144 | ); |
| 145 | 145 | $this->_model_relations = array( |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | ); |
| 151 | 151 | $this->_model_chain_to_wp_user = 'Transaction.Registration.Event'; |
| 152 | 152 | $this->_caps_slug = 'transactions'; |
| 153 | - parent::__construct( $timezone ); |
|
| 153 | + parent::__construct($timezone); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | |
@@ -161,9 +161,9 @@ discard block |
||
| 161 | 161 | * @param EE_Transaction|int $transaction |
| 162 | 162 | * @return EE_Line_Item[] |
| 163 | 163 | */ |
| 164 | - public function get_all_of_type_for_transaction( $line_item_type, $transaction ){ |
|
| 165 | - $transaction = EEM_Transaction::instance()->ensure_is_ID( $transaction ); |
|
| 166 | - return $this->get_all( array( array( |
|
| 164 | + public function get_all_of_type_for_transaction($line_item_type, $transaction) { |
|
| 165 | + $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
| 166 | + return $this->get_all(array(array( |
|
| 167 | 167 | 'LIN_type' => $line_item_type, |
| 168 | 168 | 'TXN_ID' => $transaction |
| 169 | 169 | ))); |
@@ -177,14 +177,14 @@ discard block |
||
| 177 | 177 | * @param EE_Transaction|int $transaction |
| 178 | 178 | * @return EE_Line_Item[] |
| 179 | 179 | */ |
| 180 | - public function get_all_non_ticket_line_items_for_transaction( $transaction ) { |
|
| 181 | - $transaction = EEM_Transaction::instance()->ensure_is_ID( $transaction ); |
|
| 182 | - return $this->get_all( array( array( |
|
| 180 | + public function get_all_non_ticket_line_items_for_transaction($transaction) { |
|
| 181 | + $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
| 182 | + return $this->get_all(array(array( |
|
| 183 | 183 | 'LIN_type' => self::type_line_item, |
| 184 | 184 | 'TXN_ID' => $transaction, |
| 185 | 185 | 'OR' => array( |
| 186 | - 'OBJ_type*notticket' => array( '!=', 'Ticket'), |
|
| 187 | - 'OBJ_type*null' => array( 'IS_NULL' )) |
|
| 186 | + 'OBJ_type*notticket' => array('!=', 'Ticket'), |
|
| 187 | + 'OBJ_type*null' => array('IS_NULL')) |
|
| 188 | 188 | ))); |
| 189 | 189 | } |
| 190 | 190 | |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | * because if there are spam bots afoot there will be LOTS of line items |
| 195 | 195 | * @return int count of how many deleted |
| 196 | 196 | */ |
| 197 | - public function delete_line_items_with_no_transaction(){ |
|
| 197 | + public function delete_line_items_with_no_transaction() { |
|
| 198 | 198 | /** @type WPDB $wpdb */ |
| 199 | 199 | global $wpdb; |
| 200 | 200 | $time_to_leave_alone = apply_filters( |
@@ -202,13 +202,13 @@ discard block |
||
| 202 | 202 | ); |
| 203 | 203 | $query = $wpdb->prepare( |
| 204 | 204 | 'DELETE li |
| 205 | - FROM ' . $this->table() . ' li |
|
| 206 | - LEFT JOIN ' . EEM_Transaction::instance()->table(). ' t ON li.TXN_ID = t.TXN_ID |
|
| 205 | + FROM ' . $this->table().' li |
|
| 206 | + LEFT JOIN ' . EEM_Transaction::instance()->table().' t ON li.TXN_ID = t.TXN_ID |
|
| 207 | 207 | WHERE t.TXN_ID IS NULL AND li.LIN_timestamp < %s', |
| 208 | 208 | // use GMT time because that's what TXN_timestamps are in |
| 209 | - date( 'Y-m-d H:i:s', time() - $time_to_leave_alone ) |
|
| 209 | + date('Y-m-d H:i:s', time() - $time_to_leave_alone) |
|
| 210 | 210 | ); |
| 211 | - return $wpdb->query( $query ); |
|
| 211 | + return $wpdb->query($query); |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | |
@@ -221,10 +221,10 @@ discard block |
||
| 221 | 221 | * @param \EE_Base_Class $object |
| 222 | 222 | * @return EE_Line_Item[] |
| 223 | 223 | */ |
| 224 | - public function get_line_item_for_transaction_object( $TXN_ID, EE_Base_Class $object ){ |
|
| 225 | - return $this->get_all( array( array( |
|
| 224 | + public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object) { |
|
| 225 | + return $this->get_all(array(array( |
|
| 226 | 226 | 'TXN_ID' => $TXN_ID, |
| 227 | - 'OBJ_type' => str_replace( 'EE_', '', get_class( $object )), |
|
| 227 | + 'OBJ_type' => str_replace('EE_', '', get_class($object)), |
|
| 228 | 228 | 'OBJ_ID' => $object->ID() |
| 229 | 229 | ))); |
| 230 | 230 | } |
@@ -240,16 +240,16 @@ discard block |
||
| 240 | 240 | * @param array $OBJ_IDs |
| 241 | 241 | * @return EE_Line_Item[] |
| 242 | 242 | */ |
| 243 | - public function get_object_line_items_for_transaction( $TXN_ID, $OBJ_type = 'Event', $OBJ_IDs = array() ){ |
|
| 243 | + public function get_object_line_items_for_transaction($TXN_ID, $OBJ_type = 'Event', $OBJ_IDs = array()) { |
|
| 244 | 244 | $query_params = array( |
| 245 | 245 | 'OBJ_type' => $OBJ_type, |
| 246 | 246 | // if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query |
| 247 | - 'OBJ_ID' => is_array( $OBJ_IDs ) && ! isset( $OBJ_IDs['IN'] ) ? array( 'IN', $OBJ_IDs ) : $OBJ_IDs |
|
| 247 | + 'OBJ_ID' => is_array($OBJ_IDs) && ! isset($OBJ_IDs['IN']) ? array('IN', $OBJ_IDs) : $OBJ_IDs |
|
| 248 | 248 | ); |
| 249 | - if ( $TXN_ID ) { |
|
| 249 | + if ($TXN_ID) { |
|
| 250 | 250 | $query_params['TXN_ID'] = $TXN_ID; |
| 251 | 251 | } |
| 252 | - return $this->get_all( array( $query_params )); |
|
| 252 | + return $this->get_all(array($query_params)); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | |
@@ -260,13 +260,13 @@ discard block |
||
| 260 | 260 | * @param EE_Transaction $transaction |
| 261 | 261 | * @return EE_Line_Item[] |
| 262 | 262 | */ |
| 263 | - public function get_all_ticket_line_items_for_transaction( EE_Transaction $transaction ) { |
|
| 264 | - return $this->get_all( array( |
|
| 263 | + public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction) { |
|
| 264 | + return $this->get_all(array( |
|
| 265 | 265 | array( |
| 266 | 266 | 'TXN_ID' => $transaction->ID(), |
| 267 | 267 | 'OBJ_type' => 'Ticket', |
| 268 | 268 | ) |
| 269 | - ) ); |
|
| 269 | + )); |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | |
@@ -278,14 +278,14 @@ discard block |
||
| 278 | 278 | * @param int $TKT_ID |
| 279 | 279 | * @return \EE_Line_Item |
| 280 | 280 | */ |
| 281 | - public function get_ticket_line_item_for_transaction( $TXN_ID, $TKT_ID ) { |
|
| 282 | - return $this->get_one( array( |
|
| 281 | + public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID) { |
|
| 282 | + return $this->get_one(array( |
|
| 283 | 283 | array( |
| 284 | - 'TXN_ID' => EEM_Transaction::instance()->ensure_is_ID( $TXN_ID ), |
|
| 284 | + 'TXN_ID' => EEM_Transaction::instance()->ensure_is_ID($TXN_ID), |
|
| 285 | 285 | 'OBJ_ID' => $TKT_ID, |
| 286 | 286 | 'OBJ_type' => 'Ticket', |
| 287 | 287 | ) |
| 288 | - ) ); |
|
| 288 | + )); |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | |
@@ -300,8 +300,8 @@ discard block |
||
| 300 | 300 | * @param EE_Promotion $promotion |
| 301 | 301 | * @return EE_Line_Item |
| 302 | 302 | */ |
| 303 | - public function get_existing_promotion_line_item( EE_Line_Item $parent_line_item, EE_Promotion $promotion ) { |
|
| 304 | - return $this->get_one( array( |
|
| 303 | + public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion) { |
|
| 304 | + return $this->get_one(array( |
|
| 305 | 305 | array( |
| 306 | 306 | 'TXN_ID' => $parent_line_item->TXN_ID(), |
| 307 | 307 | 'LIN_parent' => $parent_line_item->ID(), |
@@ -322,8 +322,8 @@ discard block |
||
| 322 | 322 | * @param EE_Line_Item $parent_line_item |
| 323 | 323 | * @return EE_Line_Item[] |
| 324 | 324 | */ |
| 325 | - public function get_all_promotion_line_items( EE_Line_Item $parent_line_item ) { |
|
| 326 | - return $this->get_all( array( |
|
| 325 | + public function get_all_promotion_line_items(EE_Line_Item $parent_line_item) { |
|
| 326 | + return $this->get_all(array( |
|
| 327 | 327 | array( |
| 328 | 328 | 'TXN_ID' => $parent_line_item->TXN_ID(), |
| 329 | 329 | 'LIN_parent' => $parent_line_item->ID(), |
@@ -340,8 +340,8 @@ discard block |
||
| 340 | 340 | * @param EE_Registration $registration |
| 341 | 341 | * @return EE_Line_ITem |
| 342 | 342 | */ |
| 343 | - public function get_line_item_for_registration( EE_Registration $registration ) { |
|
| 344 | - return $this->get_one( $this->line_item_for_registration_query_params( $registration )); |
|
| 343 | + public function get_line_item_for_registration(EE_Registration $registration) { |
|
| 344 | + return $this->get_one($this->line_item_for_registration_query_params($registration)); |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | /** |
@@ -350,14 +350,14 @@ discard block |
||
| 350 | 350 | * @param array $original_query_params any extra query params you'd like to be merged with |
| 351 | 351 | * @return array like EEM_Base::get_all()'s $query_params |
| 352 | 352 | */ |
| 353 | - public function line_item_for_registration_query_params( EE_Registration $registration, $original_query_params = array() ) { |
|
| 354 | - return array_replace_recursive( $original_query_params, array( |
|
| 353 | + public function line_item_for_registration_query_params(EE_Registration $registration, $original_query_params = array()) { |
|
| 354 | + return array_replace_recursive($original_query_params, array( |
|
| 355 | 355 | array( |
| 356 | 356 | 'OBJ_ID' => $registration->ticket_ID(), |
| 357 | 357 | 'OBJ_type' => 'Ticket', |
| 358 | 358 | 'TXN_ID' => $registration->transaction_ID() |
| 359 | 359 | ) |
| 360 | - ) ); |
|
| 360 | + )); |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | |
@@ -1,4 +1,6 @@ |
||
| 1 | -<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | +} |
|
| 2 | 4 | /** |
| 3 | 5 | * Event Espresso |
| 4 | 6 | * |
@@ -362,62 +362,62 @@ |
||
| 362 | 362 | |
| 363 | 363 | |
| 364 | 364 | |
| 365 | - /** |
|
| 366 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 367 | - * @throws \EE_Error |
|
| 368 | - */ |
|
| 369 | - public function get_total_line_items_with_no_transaction() |
|
| 370 | - { |
|
| 371 | - return $this->get_total_line_items_for_carts(); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 378 | - * @throws \EE_Error |
|
| 379 | - */ |
|
| 380 | - public function get_total_line_items_for_active_carts() |
|
| 381 | - { |
|
| 382 | - return $this->get_total_line_items_for_carts(false); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - |
|
| 386 | - |
|
| 387 | - /** |
|
| 388 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 389 | - * @throws \EE_Error |
|
| 390 | - */ |
|
| 391 | - public function get_total_line_items_for_expired_carts() |
|
| 392 | - { |
|
| 393 | - return $this->get_total_line_items_for_carts(true); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * Returns an array of grand total line items where the TXN_ID is 0. |
|
| 400 | - * If $expired is set to true, then only line items for expired sessions will be returned. |
|
| 401 | - * If $expired is set to false, then only line items for active sessions will be returned. |
|
| 402 | - * |
|
| 403 | - * @param bool|null $expired |
|
| 404 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 405 | - * @throws \EE_Error |
|
| 406 | - */ |
|
| 407 | - private function get_total_line_items_for_carts($expired = null) |
|
| 408 | - { |
|
| 409 | - $where_params = array( |
|
| 410 | - 'TXN_ID' => 0, |
|
| 411 | - 'LIN_type' => 'total', |
|
| 412 | - ); |
|
| 413 | - if ($expired !== null) { |
|
| 414 | - $where_params['LIN_timestamp'] = array( |
|
| 415 | - $expired ? '<=' : '>', |
|
| 416 | - time() - EE_Registry::instance()->SSN->lifespan(), |
|
| 417 | - ); |
|
| 418 | - } |
|
| 419 | - return $this->get_all(array($where_params)); |
|
| 420 | - } |
|
| 365 | + /** |
|
| 366 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 367 | + * @throws \EE_Error |
|
| 368 | + */ |
|
| 369 | + public function get_total_line_items_with_no_transaction() |
|
| 370 | + { |
|
| 371 | + return $this->get_total_line_items_for_carts(); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 378 | + * @throws \EE_Error |
|
| 379 | + */ |
|
| 380 | + public function get_total_line_items_for_active_carts() |
|
| 381 | + { |
|
| 382 | + return $this->get_total_line_items_for_carts(false); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + |
|
| 386 | + |
|
| 387 | + /** |
|
| 388 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 389 | + * @throws \EE_Error |
|
| 390 | + */ |
|
| 391 | + public function get_total_line_items_for_expired_carts() |
|
| 392 | + { |
|
| 393 | + return $this->get_total_line_items_for_carts(true); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * Returns an array of grand total line items where the TXN_ID is 0. |
|
| 400 | + * If $expired is set to true, then only line items for expired sessions will be returned. |
|
| 401 | + * If $expired is set to false, then only line items for active sessions will be returned. |
|
| 402 | + * |
|
| 403 | + * @param bool|null $expired |
|
| 404 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 405 | + * @throws \EE_Error |
|
| 406 | + */ |
|
| 407 | + private function get_total_line_items_for_carts($expired = null) |
|
| 408 | + { |
|
| 409 | + $where_params = array( |
|
| 410 | + 'TXN_ID' => 0, |
|
| 411 | + 'LIN_type' => 'total', |
|
| 412 | + ); |
|
| 413 | + if ($expired !== null) { |
|
| 414 | + $where_params['LIN_timestamp'] = array( |
|
| 415 | + $expired ? '<=' : '>', |
|
| 416 | + time() - EE_Registry::instance()->SSN->lifespan(), |
|
| 417 | + ); |
|
| 418 | + } |
|
| 419 | + return $this->get_all(array($where_params)); |
|
| 420 | + } |
|
| 421 | 421 | |
| 422 | 422 | |
| 423 | 423 | |
@@ -418,7 +418,7 @@ |
||
| 418 | 418 | * In this case, we delete the temporary file |
| 419 | 419 | * |
| 420 | 420 | * @param JobParameters $job_parameters |
| 421 | - * @return boolean |
|
| 421 | + * @return JobStepResponse |
|
| 422 | 422 | */ |
| 423 | 423 | public function cleanup_job(JobParameters $job_parameters) |
| 424 | 424 | { |
@@ -174,7 +174,7 @@ |
||
| 174 | 174 | $job_parameters->extra_datum('query_params')); |
| 175 | 175 | \EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false); |
| 176 | 176 | $units_processed = count($csv_data); |
| 177 | - }else{ |
|
| 177 | + } else{ |
|
| 178 | 178 | $units_processed = 0; |
| 179 | 179 | } |
| 180 | 180 | $job_parameters->mark_processed($units_processed); |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | array_diff_key( |
| 84 | 84 | $query_params, |
| 85 | 85 | array_flip( |
| 86 | - array( 'limit' ) |
|
| 86 | + array('limit') |
|
| 87 | 87 | ) |
| 88 | 88 | ) |
| 89 | 89 | ) |
@@ -130,11 +130,11 @@ discard block |
||
| 130 | 130 | ); |
| 131 | 131 | } |
| 132 | 132 | $question_query_params[0]['QST_system'] = array('NOT_IN', array_keys(\EEM_Attendee::instance()->system_question_to_attendee_field_mapping())); |
| 133 | - if(apply_filters('FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions', false, $registration_query_params)) { |
|
| 133 | + if (apply_filters('FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions', false, $registration_query_params)) { |
|
| 134 | 134 | $question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL'); |
| 135 | 135 | } |
| 136 | - $question_query_params['group_by'] = array( 'QST_ID' ); |
|
| 137 | - return array_unique( \EEM_Question::instance()->get_col( $question_query_params, 'QST_admin_label' ) ); |
|
| 136 | + $question_query_params['group_by'] = array('QST_ID'); |
|
| 137 | + return array_unique(\EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label')); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | $question_where_params[$key] = $this->_change_registration_where_params_to_question_where_params($val); |
| 154 | 154 | } else { |
| 155 | 155 | //it's a normal where condition |
| 156 | - $question_where_params['Question_Group.Event.Registration.' . $key] = $val; |
|
| 156 | + $question_where_params['Question_Group.Event.Registration.'.$key] = $val; |
|
| 157 | 157 | } |
| 158 | 158 | } |
| 159 | 159 | return $question_where_params; |
@@ -171,13 +171,13 @@ discard block |
||
| 171 | 171 | */ |
| 172 | 172 | public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
| 173 | 173 | { |
| 174 | - if( $job_parameters->units_processed() < $job_parameters->job_size() ) { |
|
| 174 | + if ($job_parameters->units_processed() < $job_parameters->job_size()) { |
|
| 175 | 175 | $csv_data = $this->get_csv_data_for($job_parameters->request_datum('EVT_ID', '0'), |
| 176 | 176 | $job_parameters->units_processed(), $batch_size, $job_parameters->extra_datum('question_labels'), |
| 177 | 177 | $job_parameters->extra_datum('query_params')); |
| 178 | 178 | \EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false); |
| 179 | 179 | $units_processed = count($csv_data); |
| 180 | - }else{ |
|
| 180 | + } else { |
|
| 181 | 181 | $units_processed = 0; |
| 182 | 182 | } |
| 183 | 183 | $job_parameters->mark_processed($units_processed); |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | use EventEspressoBatchRequest\Helpers\JobStepResponse; |
| 18 | 18 | |
| 19 | 19 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 20 | - exit('No direct script access allowed'); |
|
| 20 | + exit('No direct script access allowed'); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -25,443 +25,442 @@ discard block |
||
| 25 | 25 | class RegistrationsReport extends JobHandlerFile |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Performs any necessary setup for starting the job. This is also a good |
|
| 30 | - * place to setup the $job_arguments which will be used for subsequent HTTP requests |
|
| 31 | - * when continue_job will be called |
|
| 32 | - * |
|
| 33 | - * @param JobParameters $job_parameters |
|
| 34 | - * @throws BatchRequestException |
|
| 35 | - * @return JobStepResponse |
|
| 36 | - */ |
|
| 37 | - public function create_job(JobParameters $job_parameters) |
|
| 38 | - { |
|
| 39 | - $event_id = intval($job_parameters->request_datum('EVT_ID', '0')); |
|
| 40 | - if ( ! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) { |
|
| 41 | - throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso')); |
|
| 42 | - } |
|
| 43 | - $filepath = $this->create_file_from_job_with_name($job_parameters->job_id(), |
|
| 44 | - $this->get_filename($event_id)); |
|
| 45 | - $job_parameters->add_extra_data('filepath', $filepath); |
|
| 46 | - if ($job_parameters->request_datum('use_filters', false)) { |
|
| 47 | - $query_params = maybe_unserialize(stripslashes($job_parameters->request_datum('filters', array()))); |
|
| 48 | - } else { |
|
| 49 | - $query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array( |
|
| 50 | - array( |
|
| 51 | - 'OR' => array( |
|
| 52 | - //don't include registrations from failed or abandoned transactions... |
|
| 53 | - 'Transaction.STS_ID' => array( |
|
| 54 | - 'NOT IN', |
|
| 55 | - array( |
|
| 56 | - \EEM_Transaction::failed_status_code, |
|
| 57 | - \EEM_Transaction::abandoned_status_code, |
|
| 58 | - ), |
|
| 59 | - ), |
|
| 60 | - //unless the registration is approved, in which case include it regardless of transaction status |
|
| 61 | - 'STS_ID' => \EEM_Registration::status_id_approved, |
|
| 62 | - ), |
|
| 63 | - 'Ticket.TKT_deleted' => array('IN', array(true, false)), |
|
| 64 | - ), |
|
| 65 | - 'order_by' => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'), |
|
| 66 | - 'force_join' => array('Transaction', 'Ticket', 'Attendee'), |
|
| 67 | - 'caps' => \EEM_Base::caps_read_admin, |
|
| 68 | - ), $event_id); |
|
| 69 | - if ($event_id) { |
|
| 70 | - $query_params[0]['EVT_ID'] = $event_id; |
|
| 71 | - } else { |
|
| 72 | - $query_params['force_join'][] = 'Event'; |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - if ( ! isset($query_params['force_join'])) { |
|
| 76 | - $query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee'); |
|
| 77 | - } |
|
| 78 | - $job_parameters->add_extra_data('query_params', $query_params); |
|
| 79 | - $question_labels = $this->_get_question_labels($query_params); |
|
| 80 | - $job_parameters->add_extra_data('question_labels', $question_labels); |
|
| 81 | - $job_parameters->set_job_size( |
|
| 82 | - \EEM_Registration::instance()->count( |
|
| 83 | - array_diff_key( |
|
| 84 | - $query_params, |
|
| 85 | - array_flip( |
|
| 86 | - array( 'limit' ) |
|
| 87 | - ) |
|
| 88 | - ) |
|
| 89 | - ) |
|
| 90 | - ); |
|
| 91 | - //we should also set the header columns |
|
| 92 | - $csv_data_for_row = $this->get_csv_data_for($event_id, 0, 1, $job_parameters->extra_datum('question_labels'), |
|
| 93 | - $job_parameters->extra_datum('query_params')); |
|
| 94 | - \EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true); |
|
| 95 | - //if we actually processed a row there, record it |
|
| 96 | - if ($job_parameters->job_size()) { |
|
| 97 | - $job_parameters->mark_processed(1); |
|
| 98 | - } |
|
| 99 | - return new JobStepResponse($job_parameters, |
|
| 100 | - __('Registrations report started successfully...', 'event_espresso')); |
|
| 101 | - } |
|
| 28 | + /** |
|
| 29 | + * Performs any necessary setup for starting the job. This is also a good |
|
| 30 | + * place to setup the $job_arguments which will be used for subsequent HTTP requests |
|
| 31 | + * when continue_job will be called |
|
| 32 | + * |
|
| 33 | + * @param JobParameters $job_parameters |
|
| 34 | + * @throws BatchRequestException |
|
| 35 | + * @return JobStepResponse |
|
| 36 | + */ |
|
| 37 | + public function create_job(JobParameters $job_parameters) |
|
| 38 | + { |
|
| 39 | + $event_id = intval($job_parameters->request_datum('EVT_ID', '0')); |
|
| 40 | + if ( ! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) { |
|
| 41 | + throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso')); |
|
| 42 | + } |
|
| 43 | + $filepath = $this->create_file_from_job_with_name($job_parameters->job_id(), |
|
| 44 | + $this->get_filename($event_id)); |
|
| 45 | + $job_parameters->add_extra_data('filepath', $filepath); |
|
| 46 | + if ($job_parameters->request_datum('use_filters', false)) { |
|
| 47 | + $query_params = maybe_unserialize(stripslashes($job_parameters->request_datum('filters', array()))); |
|
| 48 | + } else { |
|
| 49 | + $query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array( |
|
| 50 | + array( |
|
| 51 | + 'OR' => array( |
|
| 52 | + //don't include registrations from failed or abandoned transactions... |
|
| 53 | + 'Transaction.STS_ID' => array( |
|
| 54 | + 'NOT IN', |
|
| 55 | + array( |
|
| 56 | + \EEM_Transaction::failed_status_code, |
|
| 57 | + \EEM_Transaction::abandoned_status_code, |
|
| 58 | + ), |
|
| 59 | + ), |
|
| 60 | + //unless the registration is approved, in which case include it regardless of transaction status |
|
| 61 | + 'STS_ID' => \EEM_Registration::status_id_approved, |
|
| 62 | + ), |
|
| 63 | + 'Ticket.TKT_deleted' => array('IN', array(true, false)), |
|
| 64 | + ), |
|
| 65 | + 'order_by' => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'), |
|
| 66 | + 'force_join' => array('Transaction', 'Ticket', 'Attendee'), |
|
| 67 | + 'caps' => \EEM_Base::caps_read_admin, |
|
| 68 | + ), $event_id); |
|
| 69 | + if ($event_id) { |
|
| 70 | + $query_params[0]['EVT_ID'] = $event_id; |
|
| 71 | + } else { |
|
| 72 | + $query_params['force_join'][] = 'Event'; |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + if ( ! isset($query_params['force_join'])) { |
|
| 76 | + $query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee'); |
|
| 77 | + } |
|
| 78 | + $job_parameters->add_extra_data('query_params', $query_params); |
|
| 79 | + $question_labels = $this->_get_question_labels($query_params); |
|
| 80 | + $job_parameters->add_extra_data('question_labels', $question_labels); |
|
| 81 | + $job_parameters->set_job_size( |
|
| 82 | + \EEM_Registration::instance()->count( |
|
| 83 | + array_diff_key( |
|
| 84 | + $query_params, |
|
| 85 | + array_flip( |
|
| 86 | + array( 'limit' ) |
|
| 87 | + ) |
|
| 88 | + ) |
|
| 89 | + ) |
|
| 90 | + ); |
|
| 91 | + //we should also set the header columns |
|
| 92 | + $csv_data_for_row = $this->get_csv_data_for($event_id, 0, 1, $job_parameters->extra_datum('question_labels'), |
|
| 93 | + $job_parameters->extra_datum('query_params')); |
|
| 94 | + \EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true); |
|
| 95 | + //if we actually processed a row there, record it |
|
| 96 | + if ($job_parameters->job_size()) { |
|
| 97 | + $job_parameters->mark_processed(1); |
|
| 98 | + } |
|
| 99 | + return new JobStepResponse($job_parameters, |
|
| 100 | + __('Registrations report started successfully...', 'event_espresso')); |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | 103 | |
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * Gets the filename |
|
| 107 | - * @return string |
|
| 108 | - */ |
|
| 109 | - protected function get_filename() |
|
| 110 | - { |
|
| 111 | - return sprintf("event-espresso-registrations-%s.csv", str_replace(':', '-', current_time('mysql'))); |
|
| 112 | - } |
|
| 105 | + /** |
|
| 106 | + * Gets the filename |
|
| 107 | + * @return string |
|
| 108 | + */ |
|
| 109 | + protected function get_filename() |
|
| 110 | + { |
|
| 111 | + return sprintf("event-espresso-registrations-%s.csv", str_replace(':', '-', current_time('mysql'))); |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | 114 | |
| 115 | 115 | |
| 116 | - /** |
|
| 117 | - * Gets the questions which are to be used for this report, so they |
|
| 118 | - * can be remembered for later |
|
| 119 | - * |
|
| 120 | - * @param array $registration_query_params |
|
| 121 | - * @return array question admin labels to be used for this report |
|
| 122 | - */ |
|
| 123 | - protected function _get_question_labels($registration_query_params) |
|
| 124 | - { |
|
| 125 | - $where = isset($registration_query_params[0]) ? $registration_query_params[0] : null; |
|
| 126 | - $question_query_params = array(); |
|
| 127 | - if ($where !== null) { |
|
| 128 | - $question_query_params = array( |
|
| 129 | - $this->_change_registration_where_params_to_question_where_params($registration_query_params[0]), |
|
| 130 | - ); |
|
| 131 | - } |
|
| 132 | - $question_query_params[0]['QST_system'] = array('NOT_IN', array_keys(\EEM_Attendee::instance()->system_question_to_attendee_field_mapping())); |
|
| 133 | - if(apply_filters('FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions', false, $registration_query_params)) { |
|
| 134 | - $question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL'); |
|
| 135 | - } |
|
| 136 | - $question_query_params['group_by'] = array( 'QST_ID' ); |
|
| 137 | - return array_unique( \EEM_Question::instance()->get_col( $question_query_params, 'QST_admin_label' ) ); |
|
| 138 | - } |
|
| 116 | + /** |
|
| 117 | + * Gets the questions which are to be used for this report, so they |
|
| 118 | + * can be remembered for later |
|
| 119 | + * |
|
| 120 | + * @param array $registration_query_params |
|
| 121 | + * @return array question admin labels to be used for this report |
|
| 122 | + */ |
|
| 123 | + protected function _get_question_labels($registration_query_params) |
|
| 124 | + { |
|
| 125 | + $where = isset($registration_query_params[0]) ? $registration_query_params[0] : null; |
|
| 126 | + $question_query_params = array(); |
|
| 127 | + if ($where !== null) { |
|
| 128 | + $question_query_params = array( |
|
| 129 | + $this->_change_registration_where_params_to_question_where_params($registration_query_params[0]), |
|
| 130 | + ); |
|
| 131 | + } |
|
| 132 | + $question_query_params[0]['QST_system'] = array('NOT_IN', array_keys(\EEM_Attendee::instance()->system_question_to_attendee_field_mapping())); |
|
| 133 | + if(apply_filters('FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions', false, $registration_query_params)) { |
|
| 134 | + $question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL'); |
|
| 135 | + } |
|
| 136 | + $question_query_params['group_by'] = array( 'QST_ID' ); |
|
| 137 | + return array_unique( \EEM_Question::instance()->get_col( $question_query_params, 'QST_admin_label' ) ); |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | 140 | |
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * Takes where params meant for registrations and changes them to work for questions |
|
| 144 | - * |
|
| 145 | - * @param array $reg_where_params |
|
| 146 | - * @return array |
|
| 147 | - */ |
|
| 148 | - protected function _change_registration_where_params_to_question_where_params($reg_where_params) |
|
| 149 | - { |
|
| 150 | - $question_where_params = array(); |
|
| 151 | - foreach ($reg_where_params as $key => $val) { |
|
| 152 | - if (\EEM_Registration::instance()->is_logic_query_param_key($key)) { |
|
| 153 | - $question_where_params[$key] = $this->_change_registration_where_params_to_question_where_params($val); |
|
| 154 | - } else { |
|
| 155 | - //it's a normal where condition |
|
| 156 | - $question_where_params['Question_Group.Event.Registration.' . $key] = $val; |
|
| 157 | - } |
|
| 158 | - } |
|
| 159 | - return $question_where_params; |
|
| 160 | - } |
|
| 142 | + /** |
|
| 143 | + * Takes where params meant for registrations and changes them to work for questions |
|
| 144 | + * |
|
| 145 | + * @param array $reg_where_params |
|
| 146 | + * @return array |
|
| 147 | + */ |
|
| 148 | + protected function _change_registration_where_params_to_question_where_params($reg_where_params) |
|
| 149 | + { |
|
| 150 | + $question_where_params = array(); |
|
| 151 | + foreach ($reg_where_params as $key => $val) { |
|
| 152 | + if (\EEM_Registration::instance()->is_logic_query_param_key($key)) { |
|
| 153 | + $question_where_params[$key] = $this->_change_registration_where_params_to_question_where_params($val); |
|
| 154 | + } else { |
|
| 155 | + //it's a normal where condition |
|
| 156 | + $question_where_params['Question_Group.Event.Registration.' . $key] = $val; |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | + return $question_where_params; |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | 162 | |
| 163 | 163 | |
| 164 | - /** |
|
| 165 | - * Performs another step of the job |
|
| 166 | - * |
|
| 167 | - * @param JobParameters $job_parameters |
|
| 168 | - * @param int $batch_size |
|
| 169 | - * @return JobStepResponse |
|
| 170 | - * @throws \EE_Error |
|
| 171 | - */ |
|
| 172 | - public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
| 173 | - { |
|
| 174 | - if( $job_parameters->units_processed() < $job_parameters->job_size() ) { |
|
| 175 | - $csv_data = $this->get_csv_data_for($job_parameters->request_datum('EVT_ID', '0'), |
|
| 176 | - $job_parameters->units_processed(), $batch_size, $job_parameters->extra_datum('question_labels'), |
|
| 177 | - $job_parameters->extra_datum('query_params')); |
|
| 178 | - \EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false); |
|
| 179 | - $units_processed = count($csv_data); |
|
| 180 | - }else{ |
|
| 181 | - $units_processed = 0; |
|
| 182 | - } |
|
| 183 | - $job_parameters->mark_processed($units_processed); |
|
| 184 | - $extra_response_data = array( |
|
| 185 | - 'file_url' => '', |
|
| 186 | - ); |
|
| 187 | - if ($units_processed < $batch_size) { |
|
| 188 | - $job_parameters->set_status(JobParameters::status_complete); |
|
| 189 | - $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath')); |
|
| 190 | - } |
|
| 164 | + /** |
|
| 165 | + * Performs another step of the job |
|
| 166 | + * |
|
| 167 | + * @param JobParameters $job_parameters |
|
| 168 | + * @param int $batch_size |
|
| 169 | + * @return JobStepResponse |
|
| 170 | + * @throws \EE_Error |
|
| 171 | + */ |
|
| 172 | + public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
| 173 | + { |
|
| 174 | + if( $job_parameters->units_processed() < $job_parameters->job_size() ) { |
|
| 175 | + $csv_data = $this->get_csv_data_for($job_parameters->request_datum('EVT_ID', '0'), |
|
| 176 | + $job_parameters->units_processed(), $batch_size, $job_parameters->extra_datum('question_labels'), |
|
| 177 | + $job_parameters->extra_datum('query_params')); |
|
| 178 | + \EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false); |
|
| 179 | + $units_processed = count($csv_data); |
|
| 180 | + }else{ |
|
| 181 | + $units_processed = 0; |
|
| 182 | + } |
|
| 183 | + $job_parameters->mark_processed($units_processed); |
|
| 184 | + $extra_response_data = array( |
|
| 185 | + 'file_url' => '', |
|
| 186 | + ); |
|
| 187 | + if ($units_processed < $batch_size) { |
|
| 188 | + $job_parameters->set_status(JobParameters::status_complete); |
|
| 189 | + $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath')); |
|
| 190 | + } |
|
| 191 | 191 | |
| 192 | - return new JobStepResponse($job_parameters, |
|
| 193 | - sprintf(__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count($csv_data)), |
|
| 194 | - $extra_response_data); |
|
| 195 | - } |
|
| 192 | + return new JobStepResponse($job_parameters, |
|
| 193 | + sprintf(__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count($csv_data)), |
|
| 194 | + $extra_response_data); |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | 197 | |
| 198 | 198 | |
| 199 | - /** |
|
| 200 | - * Gets the csv data for a batch of registrations |
|
| 201 | - |
|
| 202 | - * |
|
| 199 | + /** |
|
| 200 | + * Gets the csv data for a batch of registrations |
|
| 201 | + * |
|
| 203 | 202 | *@param int|null $event_id |
| 204 | - * @param int $offset |
|
| 205 | - * @param int $limit |
|
| 206 | - * @param array $question_labels the IDs for all the questions which were answered by someone in this selection |
|
| 207 | - * @param array $query_params for using where querying the model |
|
| 208 | - * @return array top-level keys are numeric, next-level keys are column headers |
|
| 209 | - */ |
|
| 210 | - function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params) |
|
| 211 | - { |
|
| 212 | - $reg_fields_to_include = array( |
|
| 213 | - 'TXN_ID', |
|
| 214 | - 'ATT_ID', |
|
| 215 | - 'REG_ID', |
|
| 216 | - 'REG_date', |
|
| 217 | - 'REG_code', |
|
| 218 | - 'REG_count', |
|
| 219 | - 'REG_final_price', |
|
| 220 | - ); |
|
| 221 | - $att_fields_to_include = array( |
|
| 222 | - 'ATT_fname', |
|
| 223 | - 'ATT_lname', |
|
| 224 | - 'ATT_email', |
|
| 225 | - 'ATT_address', |
|
| 226 | - 'ATT_address2', |
|
| 227 | - 'ATT_city', |
|
| 228 | - 'STA_ID', |
|
| 229 | - 'CNT_ISO', |
|
| 230 | - 'ATT_zip', |
|
| 231 | - 'ATT_phone', |
|
| 232 | - ); |
|
| 233 | - $registrations_csv_ready_array = array(); |
|
| 234 | - $reg_model = \EE_Registry::instance()->load_model('Registration'); |
|
| 235 | - $query_params['limit'] = array($offset, $limit); |
|
| 236 | - $registration_rows = $reg_model->get_all_wpdb_results($query_params); |
|
| 237 | - $registration_ids = array(); |
|
| 238 | - foreach ($registration_rows as $reg_row) { |
|
| 239 | - $registration_ids[] = intval($reg_row['Registration.REG_ID']); |
|
| 240 | - } |
|
| 241 | - foreach ($registration_rows as $reg_row) { |
|
| 242 | - if (is_array($reg_row)) { |
|
| 243 | - $reg_csv_array = array(); |
|
| 244 | - if ( ! $event_id) { |
|
| 245 | - //get the event's name and Id |
|
| 246 | - $reg_csv_array[__('Event', 'event_espresso')] = sprintf(__('%1$s (%2$s)', 'event_espresso'), |
|
| 247 | - \EEH_Export::prepare_value_from_db_for_display(\EEM_Event::instance(), 'EVT_name', |
|
| 248 | - $reg_row['Event_CPT.post_title']), $reg_row['Event_CPT.ID']); |
|
| 249 | - } |
|
| 250 | - $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false; |
|
| 251 | - /*@var $reg_row EE_Registration */ |
|
| 252 | - foreach ($reg_fields_to_include as $field_name) { |
|
| 253 | - $field = $reg_model->field_settings_for($field_name); |
|
| 254 | - if ($field_name == 'REG_final_price') { |
|
| 255 | - $value = \EEH_Export::prepare_value_from_db_for_display($reg_model, $field_name, |
|
| 256 | - $reg_row['Registration.REG_final_price'], 'localized_float'); |
|
| 257 | - } elseif ($field_name == 'REG_count') { |
|
| 258 | - $value = sprintf(__('%s of %s', 'event_espresso'), |
|
| 259 | - \EEH_Export::prepare_value_from_db_for_display($reg_model, 'REG_count', |
|
| 260 | - $reg_row['Registration.REG_count']), |
|
| 261 | - \EEH_Export::prepare_value_from_db_for_display($reg_model, 'REG_group_size', |
|
| 262 | - $reg_row['Registration.REG_group_size'])); |
|
| 263 | - } elseif ($field_name == 'REG_date') { |
|
| 264 | - $value = \EEH_Export::prepare_value_from_db_for_display($reg_model, $field_name, |
|
| 265 | - $reg_row['Registration.REG_date'], 'no_html'); |
|
| 266 | - } else { |
|
| 267 | - $value = \EEH_Export::prepare_value_from_db_for_display($reg_model, $field_name, |
|
| 268 | - $reg_row[$field->get_qualified_column()]); |
|
| 269 | - } |
|
| 270 | - $reg_csv_array[\EEH_Export::get_column_name_for_field($field)] = $value; |
|
| 271 | - if ($field_name == 'REG_final_price') { |
|
| 272 | - //add a column named Currency after the final price |
|
| 273 | - $reg_csv_array[__("Currency", "event_espresso")] = \EE_Config::instance()->currency->code; |
|
| 274 | - } |
|
| 275 | - } |
|
| 276 | - //get pretty status |
|
| 277 | - $stati = \EEM_Status::instance()->localized_status(array( |
|
| 278 | - $reg_row['Registration.STS_ID'] => __('unknown', 'event_espresso'), |
|
| 279 | - $reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'), |
|
| 280 | - ), false, 'sentence'); |
|
| 281 | - $reg_csv_array[__("Registration Status", 'event_espresso')] = $stati[$reg_row['Registration.STS_ID']]; |
|
| 282 | - //get pretty transaction status |
|
| 283 | - $reg_csv_array[__("Transaction Status", |
|
| 284 | - 'event_espresso')] = $stati[$reg_row['TransactionTable.STS_ID']]; |
|
| 285 | - $reg_csv_array[__('Transaction Amount Due', 'event_espresso')] = $is_primary_reg |
|
| 286 | - ? \EEH_Export::prepare_value_from_db_for_display(\EEM_Transaction::instance(), 'TXN_total', |
|
| 287 | - $reg_row['TransactionTable.TXN_total'], 'localized_float') : '0.00'; |
|
| 288 | - $reg_csv_array[__('Amount Paid', 'event_espresso')] = $is_primary_reg |
|
| 289 | - ? \EEH_Export::prepare_value_from_db_for_display(\EEM_Transaction::instance(), 'TXN_paid', |
|
| 290 | - $reg_row['TransactionTable.TXN_paid'], 'localized_float') : '0.00'; |
|
| 291 | - $payment_methods = array(); |
|
| 292 | - $gateway_txn_ids_etc = array(); |
|
| 293 | - $payment_times = array(); |
|
| 294 | - if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) { |
|
| 295 | - $payments_info = \EEM_Payment::instance()->get_all_wpdb_results(array( |
|
| 296 | - array( |
|
| 297 | - 'TXN_ID' => $reg_row['TransactionTable.TXN_ID'], |
|
| 298 | - 'STS_ID' => \EEM_Payment::status_id_approved, |
|
| 299 | - ), |
|
| 300 | - 'force_join' => array('Payment_Method'), |
|
| 301 | - ), ARRAY_A, |
|
| 302 | - 'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time'); |
|
| 303 | - foreach ($payments_info as $payment_method_and_gateway_txn_id) { |
|
| 304 | - $payment_methods[] = isset($payment_method_and_gateway_txn_id['name']) |
|
| 305 | - ? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso'); |
|
| 306 | - $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id']) |
|
| 307 | - ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : ''; |
|
| 308 | - $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time']) |
|
| 309 | - ? $payment_method_and_gateway_txn_id['payment_time'] : ''; |
|
| 310 | - } |
|
| 311 | - } |
|
| 312 | - $reg_csv_array[__('Payment Date(s)', 'event_espresso')] = implode(',', $payment_times); |
|
| 313 | - $reg_csv_array[__('Payment Method(s)', 'event_espresso')] = implode(",", $payment_methods); |
|
| 314 | - $reg_csv_array[__('Gateway Transaction ID(s)', 'event_espresso')] = implode(',', $gateway_txn_ids_etc); |
|
| 315 | - //get whether or not the user has checked in |
|
| 316 | - $reg_csv_array[__("Check-Ins", |
|
| 317 | - "event_espresso")] = $reg_model->count_related($reg_row['Registration.REG_ID'], 'Checkin'); |
|
| 318 | - //get ticket of registration and its price |
|
| 319 | - $ticket_model = \EE_Registry::instance()->load_model('Ticket'); |
|
| 320 | - if ($reg_row['Ticket.TKT_ID']) { |
|
| 321 | - $ticket_name = \EEH_Export::prepare_value_from_db_for_display($ticket_model, 'TKT_name', |
|
| 322 | - $reg_row['Ticket.TKT_name']); |
|
| 323 | - $datetimes_strings = array(); |
|
| 324 | - foreach ( |
|
| 325 | - \EEM_Datetime::instance()->get_all_wpdb_results(array( |
|
| 326 | - array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']), |
|
| 327 | - 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
| 328 | - 'default_where_conditions' => 'none', |
|
| 329 | - )) as $datetime |
|
| 330 | - ) { |
|
| 331 | - $datetimes_strings[] = \EEH_Export::prepare_value_from_db_for_display(\EEM_Datetime::instance(), |
|
| 332 | - 'DTT_EVT_start', $datetime['Datetime.DTT_EVT_start']); |
|
| 333 | - } |
|
| 334 | - } else { |
|
| 335 | - $ticket_name = __('Unknown', 'event_espresso'); |
|
| 336 | - $datetimes_strings = array(__('Unknown', 'event_espresso')); |
|
| 337 | - } |
|
| 338 | - $reg_csv_array[$ticket_model->field_settings_for('TKT_name')->get_nicename()] = $ticket_name; |
|
| 339 | - $reg_csv_array[__("Datetimes of Ticket", "event_espresso")] = implode(", ", $datetimes_strings); |
|
| 340 | - //get datetime(s) of registration |
|
| 341 | - //add attendee columns |
|
| 342 | - foreach ($att_fields_to_include as $att_field_name) { |
|
| 343 | - $field_obj = \EEM_Attendee::instance()->field_settings_for($att_field_name); |
|
| 344 | - if ($reg_row['Attendee_CPT.ID']) { |
|
| 345 | - if ($att_field_name == 'STA_ID') { |
|
| 346 | - $value = \EEM_State::instance() |
|
| 347 | - ->get_var(array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])), |
|
| 348 | - 'STA_name'); |
|
| 349 | - } elseif ($att_field_name == 'CNT_ISO') { |
|
| 350 | - $value = \EEM_Country::instance() |
|
| 351 | - ->get_var(array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])), |
|
| 352 | - 'CNT_name'); |
|
| 353 | - } else { |
|
| 354 | - $value = \EEH_Export::prepare_value_from_db_for_display(\EEM_Attendee::instance(), |
|
| 355 | - $att_field_name, $reg_row[$field_obj->get_qualified_column()]); |
|
| 356 | - } |
|
| 357 | - } else { |
|
| 358 | - $value = ''; |
|
| 359 | - } |
|
| 360 | - $reg_csv_array[\EEH_Export::get_column_name_for_field($field_obj)] = $value; |
|
| 361 | - } |
|
| 362 | - //make sure each registration has the same questions in the same order |
|
| 363 | - foreach ($question_labels as $question_label) { |
|
| 364 | - if ( ! isset($reg_csv_array[$question_label])) { |
|
| 365 | - $reg_csv_array[$question_label] = null; |
|
| 366 | - } |
|
| 367 | - } |
|
| 368 | - $answers = \EEM_Answer::instance()->get_all_wpdb_results(array( |
|
| 369 | - array('REG_ID' => $reg_row['Registration.REG_ID']), |
|
| 370 | - 'force_join' => array('Question'), |
|
| 371 | - )); |
|
| 372 | - //now fill out the questions THEY answered |
|
| 373 | - foreach ($answers as $answer_row) { |
|
| 374 | - if ($answer_row['Question.QST_ID']) { |
|
| 375 | - $question_label = \EEH_Export::prepare_value_from_db_for_display(\EEM_Question::instance(), |
|
| 376 | - 'QST_admin_label', $answer_row['Question.QST_admin_label']); |
|
| 377 | - } else { |
|
| 378 | - $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']); |
|
| 379 | - } |
|
| 380 | - if (isset($answer_row['Question.QST_type']) |
|
| 381 | - && $answer_row['Question.QST_type'] == \EEM_Question::QST_type_state |
|
| 382 | - ) { |
|
| 383 | - $reg_csv_array[$question_label] = \EEM_State::instance() |
|
| 384 | - ->get_state_name_by_ID($answer_row['Answer.ANS_value']); |
|
| 385 | - } else { |
|
| 386 | - //this isn't for html, so don't show html entities |
|
| 387 | - $reg_csv_array[$question_label] = html_entity_decode(\EEH_Export::prepare_value_from_db_for_display(\EEM_Answer::instance(), |
|
| 388 | - 'ANS_value', $answer_row['Answer.ANS_value'])); |
|
| 389 | - } |
|
| 390 | - } |
|
| 391 | - /** |
|
| 392 | - * Filter to change the contents of each row of the registrations report CSV file. |
|
| 393 | - * |
|
| 394 | - * This can be used to add or remote columns from the CSV file, or change their values. * |
|
| 395 | - * Note: it has this name because originally that's where this filter resided, |
|
| 396 | - * and we've left its name as-is for backward compatibility. |
|
| 397 | - * Note when using: all rows in the CSV should have the same columns. |
|
| 398 | - * |
|
| 399 | - * @param array $reg_csv_array keys are column-header names, and values are that columns' value |
|
| 400 | - * in this row |
|
| 401 | - * @param array $reg_row is the row from the database's wp_esp_registration table |
|
| 402 | - * |
|
| 403 | - */ |
|
| 404 | - $registrations_csv_ready_array[] = apply_filters( |
|
| 405 | - 'FHEE__EE_Export__report_registrations__reg_csv_array', |
|
| 406 | - $reg_csv_array, |
|
| 407 | - $reg_row |
|
| 408 | - ); |
|
| 409 | - } |
|
| 410 | - } |
|
| 411 | - //if we couldn't export anything, we want to at least show the column headers |
|
| 412 | - if (empty($registrations_csv_ready_array)) { |
|
| 413 | - $reg_csv_array = array(); |
|
| 414 | - $model_and_fields_to_include = array( |
|
| 415 | - 'Registration' => $reg_fields_to_include, |
|
| 416 | - 'Attendee' => $att_fields_to_include, |
|
| 417 | - ); |
|
| 418 | - foreach ($model_and_fields_to_include as $model_name => $field_list) { |
|
| 419 | - $model = \EE_Registry::instance()->load_model($model_name); |
|
| 420 | - foreach ($field_list as $field_name) { |
|
| 421 | - $field = $model->field_settings_for($field_name); |
|
| 422 | - $reg_csv_array[\EEH_Export::get_column_name_for_field($field)] = null; |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - $registrations_csv_ready_array[] = $reg_csv_array; |
|
| 426 | - } |
|
| 427 | - return $registrations_csv_ready_array; |
|
| 428 | - } |
|
| 203 | + * @param int $offset |
|
| 204 | + * @param int $limit |
|
| 205 | + * @param array $question_labels the IDs for all the questions which were answered by someone in this selection |
|
| 206 | + * @param array $query_params for using where querying the model |
|
| 207 | + * @return array top-level keys are numeric, next-level keys are column headers |
|
| 208 | + */ |
|
| 209 | + function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params) |
|
| 210 | + { |
|
| 211 | + $reg_fields_to_include = array( |
|
| 212 | + 'TXN_ID', |
|
| 213 | + 'ATT_ID', |
|
| 214 | + 'REG_ID', |
|
| 215 | + 'REG_date', |
|
| 216 | + 'REG_code', |
|
| 217 | + 'REG_count', |
|
| 218 | + 'REG_final_price', |
|
| 219 | + ); |
|
| 220 | + $att_fields_to_include = array( |
|
| 221 | + 'ATT_fname', |
|
| 222 | + 'ATT_lname', |
|
| 223 | + 'ATT_email', |
|
| 224 | + 'ATT_address', |
|
| 225 | + 'ATT_address2', |
|
| 226 | + 'ATT_city', |
|
| 227 | + 'STA_ID', |
|
| 228 | + 'CNT_ISO', |
|
| 229 | + 'ATT_zip', |
|
| 230 | + 'ATT_phone', |
|
| 231 | + ); |
|
| 232 | + $registrations_csv_ready_array = array(); |
|
| 233 | + $reg_model = \EE_Registry::instance()->load_model('Registration'); |
|
| 234 | + $query_params['limit'] = array($offset, $limit); |
|
| 235 | + $registration_rows = $reg_model->get_all_wpdb_results($query_params); |
|
| 236 | + $registration_ids = array(); |
|
| 237 | + foreach ($registration_rows as $reg_row) { |
|
| 238 | + $registration_ids[] = intval($reg_row['Registration.REG_ID']); |
|
| 239 | + } |
|
| 240 | + foreach ($registration_rows as $reg_row) { |
|
| 241 | + if (is_array($reg_row)) { |
|
| 242 | + $reg_csv_array = array(); |
|
| 243 | + if ( ! $event_id) { |
|
| 244 | + //get the event's name and Id |
|
| 245 | + $reg_csv_array[__('Event', 'event_espresso')] = sprintf(__('%1$s (%2$s)', 'event_espresso'), |
|
| 246 | + \EEH_Export::prepare_value_from_db_for_display(\EEM_Event::instance(), 'EVT_name', |
|
| 247 | + $reg_row['Event_CPT.post_title']), $reg_row['Event_CPT.ID']); |
|
| 248 | + } |
|
| 249 | + $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false; |
|
| 250 | + /*@var $reg_row EE_Registration */ |
|
| 251 | + foreach ($reg_fields_to_include as $field_name) { |
|
| 252 | + $field = $reg_model->field_settings_for($field_name); |
|
| 253 | + if ($field_name == 'REG_final_price') { |
|
| 254 | + $value = \EEH_Export::prepare_value_from_db_for_display($reg_model, $field_name, |
|
| 255 | + $reg_row['Registration.REG_final_price'], 'localized_float'); |
|
| 256 | + } elseif ($field_name == 'REG_count') { |
|
| 257 | + $value = sprintf(__('%s of %s', 'event_espresso'), |
|
| 258 | + \EEH_Export::prepare_value_from_db_for_display($reg_model, 'REG_count', |
|
| 259 | + $reg_row['Registration.REG_count']), |
|
| 260 | + \EEH_Export::prepare_value_from_db_for_display($reg_model, 'REG_group_size', |
|
| 261 | + $reg_row['Registration.REG_group_size'])); |
|
| 262 | + } elseif ($field_name == 'REG_date') { |
|
| 263 | + $value = \EEH_Export::prepare_value_from_db_for_display($reg_model, $field_name, |
|
| 264 | + $reg_row['Registration.REG_date'], 'no_html'); |
|
| 265 | + } else { |
|
| 266 | + $value = \EEH_Export::prepare_value_from_db_for_display($reg_model, $field_name, |
|
| 267 | + $reg_row[$field->get_qualified_column()]); |
|
| 268 | + } |
|
| 269 | + $reg_csv_array[\EEH_Export::get_column_name_for_field($field)] = $value; |
|
| 270 | + if ($field_name == 'REG_final_price') { |
|
| 271 | + //add a column named Currency after the final price |
|
| 272 | + $reg_csv_array[__("Currency", "event_espresso")] = \EE_Config::instance()->currency->code; |
|
| 273 | + } |
|
| 274 | + } |
|
| 275 | + //get pretty status |
|
| 276 | + $stati = \EEM_Status::instance()->localized_status(array( |
|
| 277 | + $reg_row['Registration.STS_ID'] => __('unknown', 'event_espresso'), |
|
| 278 | + $reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'), |
|
| 279 | + ), false, 'sentence'); |
|
| 280 | + $reg_csv_array[__("Registration Status", 'event_espresso')] = $stati[$reg_row['Registration.STS_ID']]; |
|
| 281 | + //get pretty transaction status |
|
| 282 | + $reg_csv_array[__("Transaction Status", |
|
| 283 | + 'event_espresso')] = $stati[$reg_row['TransactionTable.STS_ID']]; |
|
| 284 | + $reg_csv_array[__('Transaction Amount Due', 'event_espresso')] = $is_primary_reg |
|
| 285 | + ? \EEH_Export::prepare_value_from_db_for_display(\EEM_Transaction::instance(), 'TXN_total', |
|
| 286 | + $reg_row['TransactionTable.TXN_total'], 'localized_float') : '0.00'; |
|
| 287 | + $reg_csv_array[__('Amount Paid', 'event_espresso')] = $is_primary_reg |
|
| 288 | + ? \EEH_Export::prepare_value_from_db_for_display(\EEM_Transaction::instance(), 'TXN_paid', |
|
| 289 | + $reg_row['TransactionTable.TXN_paid'], 'localized_float') : '0.00'; |
|
| 290 | + $payment_methods = array(); |
|
| 291 | + $gateway_txn_ids_etc = array(); |
|
| 292 | + $payment_times = array(); |
|
| 293 | + if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) { |
|
| 294 | + $payments_info = \EEM_Payment::instance()->get_all_wpdb_results(array( |
|
| 295 | + array( |
|
| 296 | + 'TXN_ID' => $reg_row['TransactionTable.TXN_ID'], |
|
| 297 | + 'STS_ID' => \EEM_Payment::status_id_approved, |
|
| 298 | + ), |
|
| 299 | + 'force_join' => array('Payment_Method'), |
|
| 300 | + ), ARRAY_A, |
|
| 301 | + 'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time'); |
|
| 302 | + foreach ($payments_info as $payment_method_and_gateway_txn_id) { |
|
| 303 | + $payment_methods[] = isset($payment_method_and_gateway_txn_id['name']) |
|
| 304 | + ? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso'); |
|
| 305 | + $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id']) |
|
| 306 | + ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : ''; |
|
| 307 | + $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time']) |
|
| 308 | + ? $payment_method_and_gateway_txn_id['payment_time'] : ''; |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | + $reg_csv_array[__('Payment Date(s)', 'event_espresso')] = implode(',', $payment_times); |
|
| 312 | + $reg_csv_array[__('Payment Method(s)', 'event_espresso')] = implode(",", $payment_methods); |
|
| 313 | + $reg_csv_array[__('Gateway Transaction ID(s)', 'event_espresso')] = implode(',', $gateway_txn_ids_etc); |
|
| 314 | + //get whether or not the user has checked in |
|
| 315 | + $reg_csv_array[__("Check-Ins", |
|
| 316 | + "event_espresso")] = $reg_model->count_related($reg_row['Registration.REG_ID'], 'Checkin'); |
|
| 317 | + //get ticket of registration and its price |
|
| 318 | + $ticket_model = \EE_Registry::instance()->load_model('Ticket'); |
|
| 319 | + if ($reg_row['Ticket.TKT_ID']) { |
|
| 320 | + $ticket_name = \EEH_Export::prepare_value_from_db_for_display($ticket_model, 'TKT_name', |
|
| 321 | + $reg_row['Ticket.TKT_name']); |
|
| 322 | + $datetimes_strings = array(); |
|
| 323 | + foreach ( |
|
| 324 | + \EEM_Datetime::instance()->get_all_wpdb_results(array( |
|
| 325 | + array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']), |
|
| 326 | + 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
| 327 | + 'default_where_conditions' => 'none', |
|
| 328 | + )) as $datetime |
|
| 329 | + ) { |
|
| 330 | + $datetimes_strings[] = \EEH_Export::prepare_value_from_db_for_display(\EEM_Datetime::instance(), |
|
| 331 | + 'DTT_EVT_start', $datetime['Datetime.DTT_EVT_start']); |
|
| 332 | + } |
|
| 333 | + } else { |
|
| 334 | + $ticket_name = __('Unknown', 'event_espresso'); |
|
| 335 | + $datetimes_strings = array(__('Unknown', 'event_espresso')); |
|
| 336 | + } |
|
| 337 | + $reg_csv_array[$ticket_model->field_settings_for('TKT_name')->get_nicename()] = $ticket_name; |
|
| 338 | + $reg_csv_array[__("Datetimes of Ticket", "event_espresso")] = implode(", ", $datetimes_strings); |
|
| 339 | + //get datetime(s) of registration |
|
| 340 | + //add attendee columns |
|
| 341 | + foreach ($att_fields_to_include as $att_field_name) { |
|
| 342 | + $field_obj = \EEM_Attendee::instance()->field_settings_for($att_field_name); |
|
| 343 | + if ($reg_row['Attendee_CPT.ID']) { |
|
| 344 | + if ($att_field_name == 'STA_ID') { |
|
| 345 | + $value = \EEM_State::instance() |
|
| 346 | + ->get_var(array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])), |
|
| 347 | + 'STA_name'); |
|
| 348 | + } elseif ($att_field_name == 'CNT_ISO') { |
|
| 349 | + $value = \EEM_Country::instance() |
|
| 350 | + ->get_var(array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])), |
|
| 351 | + 'CNT_name'); |
|
| 352 | + } else { |
|
| 353 | + $value = \EEH_Export::prepare_value_from_db_for_display(\EEM_Attendee::instance(), |
|
| 354 | + $att_field_name, $reg_row[$field_obj->get_qualified_column()]); |
|
| 355 | + } |
|
| 356 | + } else { |
|
| 357 | + $value = ''; |
|
| 358 | + } |
|
| 359 | + $reg_csv_array[\EEH_Export::get_column_name_for_field($field_obj)] = $value; |
|
| 360 | + } |
|
| 361 | + //make sure each registration has the same questions in the same order |
|
| 362 | + foreach ($question_labels as $question_label) { |
|
| 363 | + if ( ! isset($reg_csv_array[$question_label])) { |
|
| 364 | + $reg_csv_array[$question_label] = null; |
|
| 365 | + } |
|
| 366 | + } |
|
| 367 | + $answers = \EEM_Answer::instance()->get_all_wpdb_results(array( |
|
| 368 | + array('REG_ID' => $reg_row['Registration.REG_ID']), |
|
| 369 | + 'force_join' => array('Question'), |
|
| 370 | + )); |
|
| 371 | + //now fill out the questions THEY answered |
|
| 372 | + foreach ($answers as $answer_row) { |
|
| 373 | + if ($answer_row['Question.QST_ID']) { |
|
| 374 | + $question_label = \EEH_Export::prepare_value_from_db_for_display(\EEM_Question::instance(), |
|
| 375 | + 'QST_admin_label', $answer_row['Question.QST_admin_label']); |
|
| 376 | + } else { |
|
| 377 | + $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']); |
|
| 378 | + } |
|
| 379 | + if (isset($answer_row['Question.QST_type']) |
|
| 380 | + && $answer_row['Question.QST_type'] == \EEM_Question::QST_type_state |
|
| 381 | + ) { |
|
| 382 | + $reg_csv_array[$question_label] = \EEM_State::instance() |
|
| 383 | + ->get_state_name_by_ID($answer_row['Answer.ANS_value']); |
|
| 384 | + } else { |
|
| 385 | + //this isn't for html, so don't show html entities |
|
| 386 | + $reg_csv_array[$question_label] = html_entity_decode(\EEH_Export::prepare_value_from_db_for_display(\EEM_Answer::instance(), |
|
| 387 | + 'ANS_value', $answer_row['Answer.ANS_value'])); |
|
| 388 | + } |
|
| 389 | + } |
|
| 390 | + /** |
|
| 391 | + * Filter to change the contents of each row of the registrations report CSV file. |
|
| 392 | + * |
|
| 393 | + * This can be used to add or remote columns from the CSV file, or change their values. * |
|
| 394 | + * Note: it has this name because originally that's where this filter resided, |
|
| 395 | + * and we've left its name as-is for backward compatibility. |
|
| 396 | + * Note when using: all rows in the CSV should have the same columns. |
|
| 397 | + * |
|
| 398 | + * @param array $reg_csv_array keys are column-header names, and values are that columns' value |
|
| 399 | + * in this row |
|
| 400 | + * @param array $reg_row is the row from the database's wp_esp_registration table |
|
| 401 | + * |
|
| 402 | + */ |
|
| 403 | + $registrations_csv_ready_array[] = apply_filters( |
|
| 404 | + 'FHEE__EE_Export__report_registrations__reg_csv_array', |
|
| 405 | + $reg_csv_array, |
|
| 406 | + $reg_row |
|
| 407 | + ); |
|
| 408 | + } |
|
| 409 | + } |
|
| 410 | + //if we couldn't export anything, we want to at least show the column headers |
|
| 411 | + if (empty($registrations_csv_ready_array)) { |
|
| 412 | + $reg_csv_array = array(); |
|
| 413 | + $model_and_fields_to_include = array( |
|
| 414 | + 'Registration' => $reg_fields_to_include, |
|
| 415 | + 'Attendee' => $att_fields_to_include, |
|
| 416 | + ); |
|
| 417 | + foreach ($model_and_fields_to_include as $model_name => $field_list) { |
|
| 418 | + $model = \EE_Registry::instance()->load_model($model_name); |
|
| 419 | + foreach ($field_list as $field_name) { |
|
| 420 | + $field = $model->field_settings_for($field_name); |
|
| 421 | + $reg_csv_array[\EEH_Export::get_column_name_for_field($field)] = null; |
|
| 422 | + } |
|
| 423 | + } |
|
| 424 | + $registrations_csv_ready_array[] = $reg_csv_array; |
|
| 425 | + } |
|
| 426 | + return $registrations_csv_ready_array; |
|
| 427 | + } |
|
| 429 | 428 | |
| 430 | 429 | |
| 431 | 430 | |
| 432 | - /** |
|
| 433 | - * Counts total unit to process |
|
| 434 | - * |
|
| 435 | - * @deprecated since 4.9.19 |
|
| 436 | - * @param int|array $event_id |
|
| 437 | - * @return int |
|
| 438 | - */ |
|
| 439 | - public function count_units_to_process($event_id) |
|
| 440 | - { |
|
| 441 | - //use the legacy filter |
|
| 442 | - if ($event_id) { |
|
| 443 | - $query_params[0]['EVT_ID'] = $event_id; |
|
| 444 | - } else { |
|
| 445 | - $query_params['force_join'][] = 'Event'; |
|
| 446 | - } |
|
| 447 | - return \EEM_Registration::instance()->count($query_params); |
|
| 448 | - } |
|
| 431 | + /** |
|
| 432 | + * Counts total unit to process |
|
| 433 | + * |
|
| 434 | + * @deprecated since 4.9.19 |
|
| 435 | + * @param int|array $event_id |
|
| 436 | + * @return int |
|
| 437 | + */ |
|
| 438 | + public function count_units_to_process($event_id) |
|
| 439 | + { |
|
| 440 | + //use the legacy filter |
|
| 441 | + if ($event_id) { |
|
| 442 | + $query_params[0]['EVT_ID'] = $event_id; |
|
| 443 | + } else { |
|
| 444 | + $query_params['force_join'][] = 'Event'; |
|
| 445 | + } |
|
| 446 | + return \EEM_Registration::instance()->count($query_params); |
|
| 447 | + } |
|
| 449 | 448 | |
| 450 | 449 | |
| 451 | 450 | |
| 452 | - /** |
|
| 453 | - * Performs any clean-up logic when we know the job is completed. |
|
| 454 | - * In this case, we delete the temporary file |
|
| 455 | - * |
|
| 456 | - * @param JobParameters $job_parameters |
|
| 457 | - * @return boolean |
|
| 458 | - */ |
|
| 459 | - public function cleanup_job(JobParameters $job_parameters) |
|
| 460 | - { |
|
| 461 | - $this->_file_helper->delete(\EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')), |
|
| 462 | - true, 'd'); |
|
| 463 | - return new JobStepResponse($job_parameters, __('Cleaned up temporary file', 'event_espresso')); |
|
| 464 | - } |
|
| 451 | + /** |
|
| 452 | + * Performs any clean-up logic when we know the job is completed. |
|
| 453 | + * In this case, we delete the temporary file |
|
| 454 | + * |
|
| 455 | + * @param JobParameters $job_parameters |
|
| 456 | + * @return boolean |
|
| 457 | + */ |
|
| 458 | + public function cleanup_job(JobParameters $job_parameters) |
|
| 459 | + { |
|
| 460 | + $this->_file_helper->delete(\EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')), |
|
| 461 | + true, 'd'); |
|
| 462 | + return new JobStepResponse($job_parameters, __('Cleaned up temporary file', 'event_espresso')); |
|
| 463 | + } |
|
| 465 | 464 | } |
| 466 | 465 | |
| 467 | 466 | |
@@ -227,7 +227,7 @@ |
||
| 227 | 227 | * _get_table_filters |
| 228 | 228 | * |
| 229 | 229 | * @access protected |
| 230 | - * @return array |
|
| 230 | + * @return string[] |
|
| 231 | 231 | */ |
| 232 | 232 | protected function _get_table_filters() |
| 233 | 233 | { |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | ); |
| 158 | 158 | $this->_primary_column = '_REG_ID'; |
| 159 | 159 | $this->_sortable_columns = array( |
| 160 | - '_REG_date' => array('_REG_date' => true), //true means its already sorted |
|
| 160 | + '_REG_date' => array('_REG_date' => true), //true means its already sorted |
|
| 161 | 161 | /** |
| 162 | 162 | * Allows users to change the default sort if they wish. |
| 163 | 163 | * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name. |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | { |
| 190 | 190 | $class = parent::_get_row_class($item); |
| 191 | 191 | //add status class |
| 192 | - $class .= ' ee-status-strip reg-status-' . $item->status_ID(); |
|
| 192 | + $class .= ' ee-status-strip reg-status-'.$item->status_ID(); |
|
| 193 | 193 | if ($this->_has_checkbox_column) { |
| 194 | 194 | $class .= ' has-checkbox-column'; |
| 195 | 195 | } |
@@ -337,11 +337,11 @@ discard block |
||
| 337 | 337 | //setup date query. |
| 338 | 338 | $beginning_string = EEM_Registration::instance() |
| 339 | 339 | ->convert_datetime_for_query('REG_date', |
| 340 | - $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start, |
|
| 340 | + $this_year_r.'-'.$this_month_r.'-01'.' '.$time_start, |
|
| 341 | 341 | 'Y-m-d H:i:s'); |
| 342 | 342 | $end_string = EEM_Registration::instance() |
| 343 | 343 | ->convert_datetime_for_query('REG_date', |
| 344 | - $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end, |
|
| 344 | + $this_year_r.'-'.$this_month_r.'-'.$days_this_month.' '.$time_end, |
|
| 345 | 345 | 'Y-m-d H:i:s'); |
| 346 | 346 | $_where['REG_date'] = array( |
| 347 | 347 | 'BETWEEN', |
@@ -374,9 +374,9 @@ discard block |
||
| 374 | 374 | 'BETWEEN', |
| 375 | 375 | array( |
| 376 | 376 | EEM_Registration::instance() |
| 377 | - ->convert_datetime_for_query('REG_date', $current_date . $time_start, 'Y-m-d H:i:s'), |
|
| 377 | + ->convert_datetime_for_query('REG_date', $current_date.$time_start, 'Y-m-d H:i:s'), |
|
| 378 | 378 | EEM_Registration::instance() |
| 379 | - ->convert_datetime_for_query('REG_date', $current_date . $time_end, 'Y-m-d H:i:s'), |
|
| 379 | + ->convert_datetime_for_query('REG_date', $current_date.$time_end, 'Y-m-d H:i:s'), |
|
| 380 | 380 | ), |
| 381 | 381 | ); |
| 382 | 382 | $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
@@ -420,8 +420,8 @@ discard block |
||
| 420 | 420 | $content .= '<div class="show-on-mobile-view-only">'; |
| 421 | 421 | $content .= '<br>'; |
| 422 | 422 | $content .= $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
| 423 | - $content .= ' ' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
| 424 | - $content .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
| 423 | + $content .= ' '.sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
| 424 | + $content .= '<br>'.sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
| 425 | 425 | $content .= '</div>'; |
| 426 | 426 | return $content; |
| 427 | 427 | } |
@@ -492,10 +492,10 @@ discard block |
||
| 492 | 492 | . $event_name |
| 493 | 493 | . '</a>' : $event_name; |
| 494 | 494 | $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('event_id' => $EVT_ID), REG_ADMIN_URL); |
| 495 | - $actions['event_filter'] = '<a href="' . $edit_event_url . '" title="'; |
|
| 495 | + $actions['event_filter'] = '<a href="'.$edit_event_url.'" title="'; |
|
| 496 | 496 | $actions['event_filter'] .= sprintf(esc_attr__('Filter this list to only show registrations for %s', |
| 497 | 497 | 'event_espresso'), $event_name); |
| 498 | - $actions['event_filter'] .= '">' . __('View Registrations', 'event_espresso') . '</a>'; |
|
| 498 | + $actions['event_filter'] .= '">'.__('View Registrations', 'event_espresso').'</a>'; |
|
| 499 | 499 | } else { |
| 500 | 500 | $edit_event = $event_name; |
| 501 | 501 | $actions['event_filter'] = ''; |
@@ -561,12 +561,12 @@ discard block |
||
| 561 | 561 | $t = $item->get_first_related('Transaction'); |
| 562 | 562 | $payment_count = $t instanceof EE_Transaction ? $t->count_related('Payment') : 0; |
| 563 | 563 | //append group count to name |
| 564 | - $link .= ' ' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
| 564 | + $link .= ' '.sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
| 565 | 565 | //append reg_code |
| 566 | - $link .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
| 566 | + $link .= '<br>'.sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
| 567 | 567 | //reg status text for accessibility |
| 568 | - $link .= '<br><span class="ee-status-text-small">' . EEH_Template::pretty_status($item->status_ID(), false, |
|
| 569 | - 'sentence') . '</span>'; |
|
| 568 | + $link .= '<br><span class="ee-status-text-small">'.EEH_Template::pretty_status($item->status_ID(), false, |
|
| 569 | + 'sentence').'</span>'; |
|
| 570 | 570 | //trash/restore/delete actions |
| 571 | 571 | $actions = array(); |
| 572 | 572 | if ($this->_view !== 'trash' |
@@ -578,8 +578,8 @@ discard block |
||
| 578 | 578 | 'action' => 'trash_registrations', |
| 579 | 579 | '_REG_ID' => $item->ID(), |
| 580 | 580 | ), REG_ADMIN_URL); |
| 581 | - $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="' . esc_attr__('Trash Registration', |
|
| 582 | - 'event_espresso') . '">' . __('Trash', 'event_espresso') . '</a>'; |
|
| 581 | + $actions['trash'] = '<a href="'.$trash_lnk_url.'" title="'.esc_attr__('Trash Registration', |
|
| 582 | + 'event_espresso').'">'.__('Trash', 'event_espresso').'</a>'; |
|
| 583 | 583 | } elseif ($this->_view === 'trash') { |
| 584 | 584 | // restore registration link |
| 585 | 585 | if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registration', |
@@ -589,8 +589,8 @@ discard block |
||
| 589 | 589 | 'action' => 'restore_registrations', |
| 590 | 590 | '_REG_ID' => $item->ID(), |
| 591 | 591 | ), REG_ADMIN_URL); |
| 592 | - $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="' . esc_attr__('Restore Registration', |
|
| 593 | - 'event_espresso') . '">' . __('Restore', 'event_espresso') . '</a>'; |
|
| 592 | + $actions['restore'] = '<a href="'.$restore_lnk_url.'" title="'.esc_attr__('Restore Registration', |
|
| 593 | + 'event_espresso').'">'.__('Restore', 'event_espresso').'</a>'; |
|
| 594 | 594 | } |
| 595 | 595 | if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registration', |
| 596 | 596 | 'espresso_registrations_ee_delete_registrations', $item->ID()) |
@@ -658,7 +658,7 @@ discard block |
||
| 658 | 658 | . $ticket->name() |
| 659 | 659 | . '</span><br />' : ''; |
| 660 | 660 | if ($item->final_price() > 0) { |
| 661 | - $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>'; |
|
| 661 | + $content .= '<span class="reg-pad-rght">'.$item->pretty_final_price().'</span>'; |
|
| 662 | 662 | } else { |
| 663 | 663 | // free event |
| 664 | 664 | $content .= '<span class="reg-overview-free-event-spn reg-pad-rght">' |
@@ -685,7 +685,7 @@ discard block |
||
| 685 | 685 | : '<span class="TKT_name">' |
| 686 | 686 | . $ticket->name() |
| 687 | 687 | . '</span><br />'; |
| 688 | - $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>'; |
|
| 688 | + $content .= '<span class="reg-pad-rght">'.$item->pretty_final_price().'</span>'; |
|
| 689 | 689 | return $content; |
| 690 | 690 | } |
| 691 | 691 | |
@@ -703,10 +703,10 @@ discard block |
||
| 703 | 703 | $payment_method = $item->payment_method(); |
| 704 | 704 | $payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name() |
| 705 | 705 | : __('Unknown', 'event_espresso'); |
| 706 | - $content = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>'; |
|
| 706 | + $content = '<span class="reg-pad-rght">'.$item->pretty_paid().'</span>'; |
|
| 707 | 707 | if ($item->paid() > 0) { |
| 708 | - $content .= '<br><span class="ee-status-text-small">' . sprintf(__('...via %s', 'event_espresso'), |
|
| 709 | - $payment_method_name) . '</span>'; |
|
| 708 | + $content .= '<br><span class="ee-status-text-small">'.sprintf(__('...via %s', 'event_espresso'), |
|
| 709 | + $payment_method_name).'</span>'; |
|
| 710 | 710 | } |
| 711 | 711 | return $content; |
| 712 | 712 | } |
@@ -738,7 +738,7 @@ discard block |
||
| 738 | 738 | . esc_attr__('View Transaction', 'event_espresso') |
| 739 | 739 | . '">' |
| 740 | 740 | . $item->transaction()->pretty_total() |
| 741 | - . '</a></span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>'; |
|
| 741 | + . '</a></span>' : '<span class="reg-pad-rght">'.$item->transaction()->pretty_total().'</span>'; |
|
| 742 | 742 | } else { |
| 743 | 743 | return __("None", "event_espresso"); |
| 744 | 744 | } |
@@ -775,7 +775,7 @@ discard block |
||
| 775 | 775 | . esc_attr__('View Transaction', 'event_espresso') |
| 776 | 776 | . '">' |
| 777 | 777 | . $item->transaction()->pretty_paid() |
| 778 | - . '</a><span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>'; |
|
| 778 | + . '</a><span>' : '<span class="reg-pad-rght">'.$item->transaction()->pretty_paid().'</span>'; |
|
| 779 | 779 | } |
| 780 | 780 | } |
| 781 | 781 | return ' '; |
@@ -815,7 +815,7 @@ discard block |
||
| 815 | 815 | $actions['view_lnk'] = EE_Registry::instance()->CAP->current_user_can('ee_read_registration', |
| 816 | 816 | 'espresso_registrations_view_registration', $item->ID()) ? ' |
| 817 | 817 | <li> |
| 818 | - <a href="' . $view_lnk_url . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '" class="tiny-text"> |
|
| 818 | + <a href="' . $view_lnk_url.'" title="'.esc_attr__('View Registration Details', 'event_espresso').'" class="tiny-text"> |
|
| 819 | 819 | <div class="dashicons dashicons-clipboard"></div> |
| 820 | 820 | </a> |
| 821 | 821 | </li>' : ''; |
@@ -823,7 +823,7 @@ discard block |
||
| 823 | 823 | 'espresso_registrations_edit_attendee') |
| 824 | 824 | && $attendee instanceof EE_Attendee ? ' |
| 825 | 825 | <li> |
| 826 | - <a href="' . $edit_lnk_url . '" title="' . esc_attr__('Edit Contact Details', 'event_espresso') . '" class="tiny-text"> |
|
| 826 | + <a href="' . $edit_lnk_url.'" title="'.esc_attr__('Edit Contact Details', 'event_espresso').'" class="tiny-text"> |
|
| 827 | 827 | <div class="ee-icon ee-icon-user-edit ee-icon-size-16"></div> |
| 828 | 828 | </a> |
| 829 | 829 | </li>' : ''; |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | |
@@ -26,875 +26,875 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | |
| 28 | 28 | |
| 29 | - private $_status; |
|
| 30 | - |
|
| 31 | - |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * An array of transaction details for the related transaction to the registration being processed. |
|
| 35 | - * This is set via the _set_related_details method. |
|
| 36 | - * |
|
| 37 | - * @var array |
|
| 38 | - */ |
|
| 39 | - protected $_transaction_details = array(); |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * An array of event details for the related event to the registration being processed. |
|
| 45 | - * This is set via the _set_related_details method. |
|
| 46 | - * |
|
| 47 | - * @var array |
|
| 48 | - */ |
|
| 49 | - protected $_event_details = array(); |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @param \Registrations_Admin_Page $admin_page |
|
| 55 | - */ |
|
| 56 | - public function __construct(Registrations_Admin_Page $admin_page) |
|
| 57 | - { |
|
| 58 | - if ( ! empty($_GET['event_id'])) { |
|
| 59 | - $extra_query_args = array(); |
|
| 60 | - foreach ($admin_page->get_views() as $key => $view_details) { |
|
| 61 | - $extra_query_args[$view_details['slug']] = array('event_id' => $_GET['event_id']); |
|
| 62 | - } |
|
| 63 | - $this->_views = $admin_page->get_list_table_view_RLs($extra_query_args); |
|
| 64 | - } |
|
| 65 | - parent::__construct($admin_page); |
|
| 66 | - $this->_status = $this->_admin_page->get_registration_status_array(); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * _setup_data |
|
| 73 | - * |
|
| 74 | - * @access protected |
|
| 75 | - * @return void |
|
| 76 | - */ |
|
| 77 | - protected function _setup_data() |
|
| 78 | - { |
|
| 79 | - $this->_data = $this->_admin_page->get_registrations($this->_per_page); |
|
| 80 | - $this->_all_data_count = $this->_admin_page->get_registrations($this->_per_page, true, false, false); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * _set_properties |
|
| 87 | - * |
|
| 88 | - * @access protected |
|
| 89 | - * @return void |
|
| 90 | - */ |
|
| 91 | - protected function _set_properties() |
|
| 92 | - { |
|
| 93 | - $this->_wp_list_args = array( |
|
| 94 | - 'singular' => __('registration', 'event_espresso'), |
|
| 95 | - 'plural' => __('registrations', 'event_espresso'), |
|
| 96 | - 'ajax' => true, |
|
| 97 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 98 | - ); |
|
| 99 | - $ID_column_name = __('ID', 'event_espresso'); |
|
| 100 | - $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">'; |
|
| 101 | - $ID_column_name .= __('Registrant Name', 'event_espresso'); |
|
| 102 | - $ID_column_name .= '</span> '; |
|
| 103 | - if (isset($_GET['event_id'])) { |
|
| 104 | - $this->_columns = array( |
|
| 105 | - 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text |
|
| 106 | - '_REG_ID' => $ID_column_name, |
|
| 107 | - 'ATT_fname' => __('Name', 'event_espresso'), |
|
| 108 | - 'ATT_email' => __('Email', 'event_espresso'), |
|
| 109 | - '_REG_date' => __('Reg Date', 'event_espresso'), |
|
| 110 | - 'PRC_amount' => __('TKT Price', 'event_espresso'), |
|
| 111 | - '_REG_final_price' => __('Final Price', 'event_espresso'), |
|
| 112 | - 'TXN_total' => __('Total Txn', 'event_espresso'), |
|
| 113 | - 'TXN_paid' => __('Paid', 'event_espresso'), |
|
| 114 | - 'actions' => __('Actions', 'event_espresso'), |
|
| 115 | - ); |
|
| 116 | - $this->_bottom_buttons = array( |
|
| 117 | - 'report' => array( |
|
| 118 | - 'route' => 'registrations_report', |
|
| 119 | - 'extra_request' => array( |
|
| 120 | - 'EVT_ID' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null, |
|
| 121 | - 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
| 122 | - ), |
|
| 123 | - ), |
|
| 124 | - ); |
|
| 125 | - } else { |
|
| 126 | - $this->_columns = array( |
|
| 127 | - 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text |
|
| 128 | - '_REG_ID' => $ID_column_name, |
|
| 129 | - 'ATT_fname' => __('Name', 'event_espresso'), |
|
| 130 | - '_REG_date' => __('TXN Date', 'event_espresso'), |
|
| 131 | - 'event_name' => __('Event', 'event_espresso'), |
|
| 132 | - 'DTT_EVT_start' => __('Event Date', 'event_espresso'), |
|
| 133 | - '_REG_final_price' => __('Price', 'event_espresso'), |
|
| 134 | - '_REG_paid' => __('Paid', 'event_espresso'), |
|
| 135 | - 'actions' => __('Actions', 'event_espresso'), |
|
| 136 | - ); |
|
| 137 | - $this->_bottom_buttons = array( |
|
| 138 | - 'report_all' => array( |
|
| 139 | - 'route' => 'registrations_report', |
|
| 140 | - 'extra_request' => array( |
|
| 141 | - 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
| 142 | - ), |
|
| 143 | - ), |
|
| 144 | - ); |
|
| 145 | - } |
|
| 146 | - $this->_bottom_buttons['report_filtered'] = array( |
|
| 147 | - 'route' => 'registrations_report', |
|
| 148 | - 'extra_request' => array( |
|
| 149 | - 'use_filters' => true, |
|
| 150 | - 'filters' => array_diff_key($this->_req_data, array_flip(array( |
|
| 151 | - 'page', |
|
| 152 | - 'action', |
|
| 153 | - 'default_nonce', |
|
| 154 | - ))), |
|
| 155 | - 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
| 156 | - ), |
|
| 157 | - ); |
|
| 158 | - $this->_primary_column = '_REG_ID'; |
|
| 159 | - $this->_sortable_columns = array( |
|
| 160 | - '_REG_date' => array('_REG_date' => true), //true means its already sorted |
|
| 161 | - /** |
|
| 162 | - * Allows users to change the default sort if they wish. |
|
| 163 | - * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name. |
|
| 164 | - */ |
|
| 165 | - 'ATT_fname' => array( |
|
| 166 | - 'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name', |
|
| 167 | - true, |
|
| 168 | - $this |
|
| 169 | - ) |
|
| 170 | - ? array('ATT_lname' => false) |
|
| 171 | - : array('ATT_fname' => false), |
|
| 172 | - 'event_name' => array('event_name' => false), |
|
| 173 | - 'DTT_EVT_start' => array('DTT_EVT_start' => false), |
|
| 174 | - '_REG_ID' => array('_REG_ID' => false), |
|
| 175 | - ); |
|
| 176 | - $this->_hidden_columns = array(); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * This simply sets up the row class for the table rows. |
|
| 183 | - * Allows for easier overriding of child methods for setting up sorting. |
|
| 184 | - * |
|
| 185 | - * @param EE_Registration $item the current item |
|
| 186 | - * @return string |
|
| 187 | - */ |
|
| 188 | - protected function _get_row_class($item) |
|
| 189 | - { |
|
| 190 | - $class = parent::_get_row_class($item); |
|
| 191 | - //add status class |
|
| 192 | - $class .= ' ee-status-strip reg-status-' . $item->status_ID(); |
|
| 193 | - if ($this->_has_checkbox_column) { |
|
| 194 | - $class .= ' has-checkbox-column'; |
|
| 195 | - } |
|
| 196 | - return $class; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * Set the $_transaction_details property if not set yet. |
|
| 203 | - * |
|
| 204 | - * @param EE_Registration $registration |
|
| 205 | - * @throws \EE_Error |
|
| 206 | - */ |
|
| 207 | - protected function _set_related_details(EE_Registration $registration) |
|
| 208 | - { |
|
| 209 | - $transaction = $registration->get_first_related('Transaction'); |
|
| 210 | - $status = $transaction instanceof EE_Transaction ? $transaction->status_ID() |
|
| 211 | - : EEM_Transaction::failed_status_code; |
|
| 212 | - $this->_transaction_details = array( |
|
| 213 | - 'transaction' => $transaction, |
|
| 214 | - 'status' => $status, |
|
| 215 | - 'id' => $transaction instanceof EE_Transaction ? $transaction->ID() : 0, |
|
| 216 | - 'title_attr' => sprintf(__('View Transaction Details (%s)', 'event_espresso'), |
|
| 217 | - EEH_Template::pretty_status($status, false, 'sentence')), |
|
| 218 | - ); |
|
| 219 | - try { |
|
| 220 | - $event = $registration->event(); |
|
| 221 | - } catch (\EventEspresso\core\exceptions\EntityNotFoundException $e) { |
|
| 222 | - $event = null; |
|
| 223 | - } |
|
| 224 | - $status = $event instanceof EE_Event ? $event->get_active_status() : EE_Datetime::inactive; |
|
| 225 | - $this->_event_details = array( |
|
| 226 | - 'event' => $event, |
|
| 227 | - 'status' => $status, |
|
| 228 | - 'id' => $event instanceof EE_Event ? $event->ID() : 0, |
|
| 229 | - 'title_attr' => sprintf(__('Edit Event (%s)', 'event_espresso'), |
|
| 230 | - EEH_Template::pretty_status($status, false, 'sentence')), |
|
| 231 | - ); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * _get_table_filters |
|
| 238 | - * |
|
| 239 | - * @access protected |
|
| 240 | - * @return array |
|
| 241 | - */ |
|
| 242 | - protected function _get_table_filters() |
|
| 243 | - { |
|
| 244 | - $filters = array(); |
|
| 245 | - //todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as methods. |
|
| 246 | - $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : ''; |
|
| 247 | - $cur_category = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1; |
|
| 248 | - $reg_status = isset($this->_req_data['_reg_status']) ? $this->_req_data['_reg_status'] : ''; |
|
| 249 | - $filters[] = EEH_Form_Fields::generate_registration_months_dropdown($cur_date, $reg_status, $cur_category); |
|
| 250 | - $filters[] = EEH_Form_Fields::generate_event_category_dropdown($cur_category); |
|
| 251 | - $status = array(); |
|
| 252 | - $status[] = array('id' => 0, 'text' => __('Select Status', 'event_espresso')); |
|
| 253 | - foreach ($this->_status as $key => $value) { |
|
| 254 | - $status[] = array('id' => $key, 'text' => $value); |
|
| 255 | - } |
|
| 256 | - if ($this->_view !== 'incomplete') { |
|
| 257 | - $filters[] = EEH_Form_Fields::select_input('_reg_status', $status, |
|
| 258 | - isset($this->_req_data['_reg_status']) ? strtoupper(sanitize_key($this->_req_data['_reg_status'])) |
|
| 259 | - : ''); |
|
| 260 | - } |
|
| 261 | - if (isset($this->_req_data['event_id'])) { |
|
| 262 | - $filters[] = EEH_Form_Fields::hidden_input('event_id', $this->_req_data['event_id'], 'reg_event_id'); |
|
| 263 | - } |
|
| 264 | - return $filters; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * _add_view_counts |
|
| 271 | - * |
|
| 272 | - * @access protected |
|
| 273 | - * @return void |
|
| 274 | - * @throws \EE_Error |
|
| 275 | - */ |
|
| 276 | - protected function _add_view_counts() |
|
| 277 | - { |
|
| 278 | - $this->_views['all']['count'] = $this->_total_registrations(); |
|
| 279 | - $this->_views['month']['count'] = $this->_total_registrations_this_month(); |
|
| 280 | - $this->_views['today']['count'] = $this->_total_registrations_today(); |
|
| 281 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registrations', |
|
| 282 | - 'espresso_registrations_trash_registrations') |
|
| 283 | - ) { |
|
| 284 | - $this->_views['incomplete']['count'] = $this->_total_registrations('incomplete'); |
|
| 285 | - $this->_views['trash']['count'] = $this->_total_registrations('trash'); |
|
| 286 | - } |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - |
|
| 290 | - |
|
| 291 | - /** |
|
| 292 | - * _total_registrations |
|
| 293 | - * |
|
| 294 | - * @access protected |
|
| 295 | - * @param string $view |
|
| 296 | - * @return int |
|
| 297 | - * @throws \EE_Error |
|
| 298 | - */ |
|
| 299 | - protected function _total_registrations($view = '') |
|
| 300 | - { |
|
| 301 | - $_where = array(); |
|
| 302 | - $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
| 303 | - if ($EVT_ID) { |
|
| 304 | - $_where['EVT_ID'] = $EVT_ID; |
|
| 305 | - } |
|
| 306 | - switch ($view) { |
|
| 307 | - case 'trash' : |
|
| 308 | - return EEM_Registration::instance()->count_deleted(array($_where)); |
|
| 309 | - break; |
|
| 310 | - case 'incomplete' : |
|
| 311 | - $_where['STS_ID'] = EEM_Registration::status_id_incomplete; |
|
| 312 | - break; |
|
| 313 | - default : |
|
| 314 | - $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
| 315 | - } |
|
| 316 | - return EEM_Registration::instance()->count(array($_where)); |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * _total_registrations_this_month |
|
| 323 | - * |
|
| 324 | - * @access protected |
|
| 325 | - * @return int |
|
| 326 | - * @throws \EE_Error |
|
| 327 | - */ |
|
| 328 | - protected function _total_registrations_this_month() |
|
| 329 | - { |
|
| 330 | - $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
| 331 | - $_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array(); |
|
| 332 | - $this_year_r = date('Y', current_time('timestamp')); |
|
| 333 | - $time_start = ' 00:00:00'; |
|
| 334 | - $time_end = ' 23:59:59'; |
|
| 335 | - $this_month_r = date('m', current_time('timestamp')); |
|
| 336 | - $days_this_month = date('t', current_time('timestamp')); |
|
| 337 | - //setup date query. |
|
| 338 | - $beginning_string = EEM_Registration::instance() |
|
| 339 | - ->convert_datetime_for_query('REG_date', |
|
| 340 | - $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start, |
|
| 341 | - 'Y-m-d H:i:s'); |
|
| 342 | - $end_string = EEM_Registration::instance() |
|
| 343 | - ->convert_datetime_for_query('REG_date', |
|
| 344 | - $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end, |
|
| 345 | - 'Y-m-d H:i:s'); |
|
| 346 | - $_where['REG_date'] = array( |
|
| 347 | - 'BETWEEN', |
|
| 348 | - array( |
|
| 349 | - $beginning_string, |
|
| 350 | - $end_string, |
|
| 351 | - ), |
|
| 352 | - ); |
|
| 353 | - $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
| 354 | - return EEM_Registration::instance()->count(array($_where)); |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * _total_registrations_today |
|
| 361 | - * |
|
| 362 | - * @access protected |
|
| 363 | - * @return int |
|
| 364 | - * @throws \EE_Error |
|
| 365 | - */ |
|
| 366 | - protected function _total_registrations_today() |
|
| 367 | - { |
|
| 368 | - $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
| 369 | - $_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array(); |
|
| 370 | - $current_date = date('Y-m-d', current_time('timestamp')); |
|
| 371 | - $time_start = ' 00:00:00'; |
|
| 372 | - $time_end = ' 23:59:59'; |
|
| 373 | - $_where['REG_date'] = array( |
|
| 374 | - 'BETWEEN', |
|
| 375 | - array( |
|
| 376 | - EEM_Registration::instance() |
|
| 377 | - ->convert_datetime_for_query('REG_date', $current_date . $time_start, 'Y-m-d H:i:s'), |
|
| 378 | - EEM_Registration::instance() |
|
| 379 | - ->convert_datetime_for_query('REG_date', $current_date . $time_end, 'Y-m-d H:i:s'), |
|
| 380 | - ), |
|
| 381 | - ); |
|
| 382 | - $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
| 383 | - return EEM_Registration::instance()->count(array($_where)); |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * column_cb |
|
| 390 | - * |
|
| 391 | - * @access public |
|
| 392 | - * @param \EE_Registration $item |
|
| 393 | - * @return string |
|
| 394 | - * @throws \EE_Error |
|
| 395 | - */ |
|
| 396 | - public function column_cb($item) |
|
| 397 | - { |
|
| 398 | - /** checkbox/lock **/ |
|
| 399 | - $transaction = $item->get_first_related('Transaction'); |
|
| 400 | - $payment_count = $transaction instanceof EE_Transaction ? $transaction->count_related('Payment') : 0; |
|
| 401 | - return $payment_count > 0 |
|
| 402 | - || ! EE_Registry::instance()->CAP->current_user_can( |
|
| 403 | - 'ee_edit_registration', |
|
| 404 | - 'registration_list_table_checkbox_input', |
|
| 405 | - $item->ID() |
|
| 406 | - ) |
|
| 407 | - ? sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID()) |
|
| 408 | - . '<span class="ee-lock-icon"></span>' |
|
| 409 | - : sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID()); |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - |
|
| 413 | - |
|
| 414 | - /** |
|
| 415 | - * column__REG_ID |
|
| 416 | - * |
|
| 417 | - * @access public |
|
| 418 | - * @param \EE_Registration $item |
|
| 419 | - * @return string |
|
| 420 | - * @throws \EE_Error |
|
| 421 | - */ |
|
| 422 | - public function column__REG_ID(EE_Registration $item) |
|
| 423 | - { |
|
| 424 | - $attendee = $item->attendee(); |
|
| 425 | - $content = $item->ID(); |
|
| 426 | - $content .= '<div class="show-on-mobile-view-only">'; |
|
| 427 | - $content .= '<br>'; |
|
| 428 | - $content .= $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
|
| 429 | - $content .= ' ' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
| 430 | - $content .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
| 431 | - $content .= '</div>'; |
|
| 432 | - return $content; |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * column__REG_date |
|
| 439 | - * |
|
| 440 | - * @access public |
|
| 441 | - * @param \EE_Registration $item |
|
| 442 | - * @return string |
|
| 443 | - * @throws \EE_Error |
|
| 444 | - */ |
|
| 445 | - public function column__REG_date(EE_Registration $item) |
|
| 446 | - { |
|
| 447 | - $this->_set_related_details($item); |
|
| 448 | - //Build row actions |
|
| 449 | - $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 450 | - 'action' => 'view_transaction', |
|
| 451 | - 'TXN_ID' => $this->_transaction_details['id'], |
|
| 452 | - ), TXN_ADMIN_URL); |
|
| 453 | - $view_link = EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', |
|
| 454 | - 'espresso_transactions_view_transaction') ? '<a class="ee-status-color-' |
|
| 455 | - . $this->_transaction_details['status'] |
|
| 456 | - . '" href="' |
|
| 457 | - . $view_lnk_url |
|
| 458 | - . '" title="' |
|
| 459 | - . esc_attr($this->_transaction_details['title_attr']) |
|
| 460 | - . '">' |
|
| 461 | - . $item->get_i18n_datetime('REG_date') |
|
| 462 | - . '</a>' : $item->get_i18n_datetime('REG_date'); |
|
| 463 | - $view_link .= '<br><span class="ee-status-text-small">' |
|
| 464 | - . EEH_Template::pretty_status($this->_transaction_details['status'], false, 'sentence') |
|
| 465 | - . '</span>'; |
|
| 466 | - return $view_link; |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - |
|
| 470 | - |
|
| 471 | - /** |
|
| 472 | - * column_event_name |
|
| 473 | - * |
|
| 474 | - * @access public |
|
| 475 | - * @param \EE_Registration $item |
|
| 476 | - * @return string |
|
| 477 | - * @throws \EE_Error |
|
| 478 | - */ |
|
| 479 | - public function column_event_name(EE_Registration $item) |
|
| 480 | - { |
|
| 481 | - $this->_set_related_details($item); |
|
| 482 | - // page=espresso_events&action=edit_event&EVT_ID=2&edit_event_nonce=cf3a7e5b62 |
|
| 483 | - $EVT_ID = $item->event_ID(); |
|
| 484 | - $event_name = $item->event_name(); |
|
| 485 | - $event_name = $event_name ? $event_name : __("No Associated Event", 'event_espresso'); |
|
| 486 | - $event_name = wp_trim_words($event_name, 30, '...'); |
|
| 487 | - if ($EVT_ID) { |
|
| 488 | - $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $EVT_ID), |
|
| 489 | - EVENTS_ADMIN_URL); |
|
| 490 | - $edit_event = EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'edit_event', $EVT_ID) |
|
| 491 | - ? '<a class="ee-status-color-' |
|
| 492 | - . $this->_event_details['status'] |
|
| 493 | - . '" href="' |
|
| 494 | - . $edit_event_url |
|
| 495 | - . '" title="' |
|
| 496 | - . esc_attr($this->_event_details['title_attr']) |
|
| 497 | - . '">' |
|
| 498 | - . $event_name |
|
| 499 | - . '</a>' : $event_name; |
|
| 500 | - $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('event_id' => $EVT_ID), REG_ADMIN_URL); |
|
| 501 | - $actions['event_filter'] = '<a href="' . $edit_event_url . '" title="'; |
|
| 502 | - $actions['event_filter'] .= sprintf(esc_attr__('Filter this list to only show registrations for %s', |
|
| 503 | - 'event_espresso'), $event_name); |
|
| 504 | - $actions['event_filter'] .= '">' . __('View Registrations', 'event_espresso') . '</a>'; |
|
| 505 | - } else { |
|
| 506 | - $edit_event = $event_name; |
|
| 507 | - $actions['event_filter'] = ''; |
|
| 508 | - } |
|
| 509 | - return sprintf('%1$s %2$s', $edit_event, $this->row_actions($actions)); |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - |
|
| 513 | - |
|
| 514 | - /** |
|
| 515 | - * column_DTT_EVT_start |
|
| 516 | - * |
|
| 517 | - * @access public |
|
| 518 | - * @param \EE_Registration $item |
|
| 519 | - * @return string |
|
| 520 | - * @throws \EE_Error |
|
| 521 | - */ |
|
| 522 | - public function column_DTT_EVT_start(EE_Registration $item) |
|
| 523 | - { |
|
| 524 | - $datetime_strings = array(); |
|
| 525 | - $ticket = $item->ticket(true); |
|
| 526 | - if ($ticket instanceof EE_Ticket) { |
|
| 527 | - $remove_defaults = array('default_where_conditions' => 'none'); |
|
| 528 | - $datetimes = $ticket->datetimes($remove_defaults); |
|
| 529 | - foreach ($datetimes as $datetime) { |
|
| 530 | - $datetime_strings[] = $datetime->get_i18n_datetime('DTT_EVT_start'); |
|
| 531 | - } |
|
| 532 | - return implode("<br />", $datetime_strings); |
|
| 533 | - } else { |
|
| 534 | - return __('There is no ticket on this registration', 'event_espresso'); |
|
| 535 | - } |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - |
|
| 539 | - |
|
| 540 | - /** |
|
| 541 | - * column_ATT_fname |
|
| 542 | - * |
|
| 543 | - * @access public |
|
| 544 | - * @param \EE_Registration $item |
|
| 545 | - * @return string |
|
| 546 | - * @throws \EE_Error |
|
| 547 | - */ |
|
| 548 | - public function column_ATT_fname(EE_Registration $item) |
|
| 549 | - { |
|
| 550 | - $attendee = $item->attendee(); |
|
| 551 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 552 | - 'action' => 'view_registration', |
|
| 553 | - '_REG_ID' => $item->ID(), |
|
| 554 | - ), REG_ADMIN_URL); |
|
| 555 | - $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
|
| 556 | - $link = EE_Registry::instance()->CAP->current_user_can('ee_read_registration', |
|
| 557 | - 'espresso_registrations_view_registration', $item->ID()) ? '<a href="' |
|
| 558 | - . $edit_lnk_url |
|
| 559 | - . '" title="' |
|
| 560 | - . esc_attr__('View Registration Details', |
|
| 561 | - 'event_espresso') |
|
| 562 | - . '">' |
|
| 563 | - . $attendee_name |
|
| 564 | - . '</a>' : $attendee_name; |
|
| 565 | - $link .= $item->count() === 1 |
|
| 566 | - ? ' <sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>' : ''; |
|
| 567 | - $t = $item->get_first_related('Transaction'); |
|
| 568 | - $payment_count = $t instanceof EE_Transaction ? $t->count_related('Payment') : 0; |
|
| 569 | - //append group count to name |
|
| 570 | - $link .= ' ' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
| 571 | - //append reg_code |
|
| 572 | - $link .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
| 573 | - //reg status text for accessibility |
|
| 574 | - $link .= '<br><span class="ee-status-text-small">' . EEH_Template::pretty_status($item->status_ID(), false, |
|
| 575 | - 'sentence') . '</span>'; |
|
| 576 | - //trash/restore/delete actions |
|
| 577 | - $actions = array(); |
|
| 578 | - if ($this->_view !== 'trash' |
|
| 579 | - && $payment_count === 0 |
|
| 580 | - && EE_Registry::instance()->CAP->current_user_can('ee_delete_registration', |
|
| 581 | - 'espresso_registrations_trash_registrations', $item->ID()) |
|
| 582 | - ) { |
|
| 583 | - $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 584 | - 'action' => 'trash_registrations', |
|
| 585 | - '_REG_ID' => $item->ID(), |
|
| 586 | - ), REG_ADMIN_URL); |
|
| 587 | - $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="' . esc_attr__('Trash Registration', |
|
| 588 | - 'event_espresso') . '">' . __('Trash', 'event_espresso') . '</a>'; |
|
| 589 | - } elseif ($this->_view === 'trash') { |
|
| 590 | - // restore registration link |
|
| 591 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registration', |
|
| 592 | - 'espresso_registrations_restore_registrations', $item->ID()) |
|
| 593 | - ) { |
|
| 594 | - $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 595 | - 'action' => 'restore_registrations', |
|
| 596 | - '_REG_ID' => $item->ID(), |
|
| 597 | - ), REG_ADMIN_URL); |
|
| 598 | - $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="' . esc_attr__('Restore Registration', |
|
| 599 | - 'event_espresso') . '">' . __('Restore', 'event_espresso') . '</a>'; |
|
| 600 | - } |
|
| 601 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registration', |
|
| 602 | - 'espresso_registrations_ee_delete_registrations', $item->ID()) |
|
| 603 | - ) { |
|
| 604 | - $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 605 | - 'action' => 'delete_registrations', |
|
| 606 | - '_REG_ID' => $item->ID(), |
|
| 607 | - ), REG_ADMIN_URL); |
|
| 608 | - $actions['delete'] = '<a href="' |
|
| 609 | - . $delete_lnk_url |
|
| 610 | - . '" title="' |
|
| 611 | - . esc_attr__('Delete Registration Permanently', 'event_espresso') |
|
| 612 | - . '">' |
|
| 613 | - . __('Delete', 'event_espresso') |
|
| 614 | - . '</a>'; |
|
| 615 | - } |
|
| 616 | - } |
|
| 617 | - return sprintf('%1$s %2$s', $link, $this->row_actions($actions)); |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - |
|
| 621 | - |
|
| 622 | - /** |
|
| 623 | - * column_ATT_email |
|
| 624 | - * |
|
| 625 | - * @access public |
|
| 626 | - * @param \EE_Registration $item |
|
| 627 | - * @return string |
|
| 628 | - * @throws \EE_Error |
|
| 629 | - */ |
|
| 630 | - public function column_ATT_email(EE_Registration $item) |
|
| 631 | - { |
|
| 632 | - $attendee = $item->get_first_related('Attendee'); |
|
| 633 | - return ! $attendee instanceof EE_Attendee ? __('No attached contact record.', 'event_espresso') |
|
| 634 | - : $attendee->email(); |
|
| 635 | - } |
|
| 636 | - |
|
| 637 | - |
|
| 638 | - |
|
| 639 | - /** |
|
| 640 | - * column__REG_count |
|
| 641 | - * |
|
| 642 | - * @access public |
|
| 643 | - * @param \EE_Registration $item |
|
| 644 | - * @return string |
|
| 645 | - */ |
|
| 646 | - public function column__REG_count(EE_Registration $item) |
|
| 647 | - { |
|
| 648 | - return sprintf(__('%1$s / %2$s', 'event_espresso'), $item->count(), $item->group_size()); |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - |
|
| 652 | - |
|
| 653 | - /** |
|
| 654 | - * column_PRC_amount |
|
| 655 | - * |
|
| 656 | - * @access public |
|
| 657 | - * @param \EE_Registration $item |
|
| 658 | - * @return string |
|
| 659 | - */ |
|
| 660 | - public function column_PRC_amount(EE_Registration $item) |
|
| 661 | - { |
|
| 662 | - $ticket = $item->ticket(); |
|
| 663 | - $content = isset($_GET['event_id']) && $ticket instanceof EE_Ticket ? '<span class="TKT_name">' |
|
| 664 | - . $ticket->name() |
|
| 665 | - . '</span><br />' : ''; |
|
| 666 | - if ($item->final_price() > 0) { |
|
| 667 | - $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>'; |
|
| 668 | - } else { |
|
| 669 | - // free event |
|
| 670 | - $content .= '<span class="reg-overview-free-event-spn reg-pad-rght">' |
|
| 671 | - . __('free', 'event_espresso') |
|
| 672 | - . '</span>'; |
|
| 673 | - } |
|
| 674 | - return $content; |
|
| 675 | - } |
|
| 676 | - |
|
| 677 | - |
|
| 678 | - |
|
| 679 | - /** |
|
| 680 | - * column__REG_final_price |
|
| 681 | - * |
|
| 682 | - * @access public |
|
| 683 | - * @param \EE_Registration $item |
|
| 684 | - * @return string |
|
| 685 | - */ |
|
| 686 | - public function column__REG_final_price(EE_Registration $item) |
|
| 687 | - { |
|
| 688 | - $ticket = $item->ticket(); |
|
| 689 | - $content = isset($_GET['event_id']) || ! $ticket instanceof EE_Ticket |
|
| 690 | - ? '' |
|
| 691 | - : '<span class="TKT_name">' |
|
| 692 | - . $ticket->name() |
|
| 693 | - . '</span><br />'; |
|
| 694 | - $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>'; |
|
| 695 | - return $content; |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - |
|
| 699 | - |
|
| 700 | - /** |
|
| 701 | - * column__REG_paid |
|
| 702 | - * |
|
| 703 | - * @access public |
|
| 704 | - * @param \EE_Registration $item |
|
| 705 | - * @return string |
|
| 706 | - */ |
|
| 707 | - public function column__REG_paid(EE_Registration $item) |
|
| 708 | - { |
|
| 709 | - $payment_method = $item->payment_method(); |
|
| 710 | - $payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name() |
|
| 711 | - : __('Unknown', 'event_espresso'); |
|
| 712 | - $content = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>'; |
|
| 713 | - if ($item->paid() > 0) { |
|
| 714 | - $content .= '<br><span class="ee-status-text-small">' . sprintf(__('...via %s', 'event_espresso'), |
|
| 715 | - $payment_method_name) . '</span>'; |
|
| 716 | - } |
|
| 717 | - return $content; |
|
| 718 | - } |
|
| 719 | - |
|
| 720 | - |
|
| 721 | - |
|
| 722 | - /** |
|
| 723 | - * column_TXN_total |
|
| 724 | - * |
|
| 725 | - * @access public |
|
| 726 | - * @param \EE_Registration $item |
|
| 727 | - * @return string |
|
| 728 | - * @throws \EE_Error |
|
| 729 | - */ |
|
| 730 | - public function column_TXN_total(EE_Registration $item) |
|
| 731 | - { |
|
| 732 | - if ($item->transaction()) { |
|
| 733 | - $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 734 | - 'action' => 'view_transaction', |
|
| 735 | - 'TXN_ID' => $item->transaction_ID(), |
|
| 736 | - ), TXN_ADMIN_URL); |
|
| 737 | - return EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', |
|
| 738 | - 'espresso_transactions_view_transaction', $item->transaction_ID()) |
|
| 739 | - ? '<span class="reg-pad-rght"><a class="status-' |
|
| 740 | - . $item->transaction()->status_ID() |
|
| 741 | - . '" href="' |
|
| 742 | - . $view_txn_lnk_url |
|
| 743 | - . '" title="' |
|
| 744 | - . esc_attr__('View Transaction', 'event_espresso') |
|
| 745 | - . '">' |
|
| 746 | - . $item->transaction()->pretty_total() |
|
| 747 | - . '</a></span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>'; |
|
| 748 | - } else { |
|
| 749 | - return __("None", "event_espresso"); |
|
| 750 | - } |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - |
|
| 754 | - |
|
| 755 | - /** |
|
| 756 | - * column_TXN_paid |
|
| 757 | - * |
|
| 758 | - * @access public |
|
| 759 | - * @param \EE_Registration $item |
|
| 760 | - * @return string |
|
| 761 | - * @throws \EE_Error |
|
| 762 | - */ |
|
| 763 | - public function column_TXN_paid(EE_Registration $item) |
|
| 764 | - { |
|
| 765 | - if ($item->count() === 1) { |
|
| 766 | - $transaction = $item->transaction() ? $item->transaction() : EE_Transaction::new_instance(); |
|
| 767 | - if ($transaction->paid() >= $transaction->total()) { |
|
| 768 | - return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>'; |
|
| 769 | - } else { |
|
| 770 | - $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 771 | - 'action' => 'view_transaction', |
|
| 772 | - 'TXN_ID' => $item->transaction_ID(), |
|
| 773 | - ), TXN_ADMIN_URL); |
|
| 774 | - return EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', |
|
| 775 | - 'espresso_transactions_view_transaction', $item->transaction_ID()) |
|
| 776 | - ? '<span class="reg-pad-rght"><a class="status-' |
|
| 777 | - . $transaction->status_ID() |
|
| 778 | - . '" href="' |
|
| 779 | - . $view_txn_lnk_url |
|
| 780 | - . '" title="' |
|
| 781 | - . esc_attr__('View Transaction', 'event_espresso') |
|
| 782 | - . '">' |
|
| 783 | - . $item->transaction()->pretty_paid() |
|
| 784 | - . '</a><span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>'; |
|
| 785 | - } |
|
| 786 | - } |
|
| 787 | - return ' '; |
|
| 788 | - } |
|
| 789 | - |
|
| 790 | - |
|
| 791 | - |
|
| 792 | - /** |
|
| 793 | - * column_actions |
|
| 794 | - * |
|
| 795 | - * @access public |
|
| 796 | - * @param \EE_Registration $item |
|
| 797 | - * @return string |
|
| 798 | - * @throws \EE_Error |
|
| 799 | - */ |
|
| 800 | - public function column_actions(EE_Registration $item) |
|
| 801 | - { |
|
| 802 | - $actions = array(); |
|
| 803 | - $attendee = $item->attendee(); |
|
| 804 | - $this->_set_related_details($item); |
|
| 805 | - //Build row actions |
|
| 806 | - $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 807 | - 'action' => 'view_registration', |
|
| 808 | - '_REG_ID' => $item->ID(), |
|
| 809 | - ), REG_ADMIN_URL); |
|
| 810 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 811 | - 'action' => 'edit_attendee', |
|
| 812 | - 'post' => $item->attendee_ID(), |
|
| 813 | - ), REG_ADMIN_URL); |
|
| 814 | - // page=attendees&event_admin_reports=resend_email®istration_id=43653465634&event_id=2&form_action=resend_email |
|
| 815 | - //$resend_reg_lnk_url_params = array( 'action'=>'resend_registration', '_REG_ID'=>$item->REG_ID ); |
|
| 816 | - $resend_reg_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 817 | - 'action' => 'resend_registration', |
|
| 818 | - '_REG_ID' => $item->ID(), |
|
| 819 | - ), REG_ADMIN_URL, true); |
|
| 820 | - //Build row actions |
|
| 821 | - $actions['view_lnk'] = EE_Registry::instance()->CAP->current_user_can('ee_read_registration', |
|
| 822 | - 'espresso_registrations_view_registration', $item->ID()) ? ' |
|
| 29 | + private $_status; |
|
| 30 | + |
|
| 31 | + |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * An array of transaction details for the related transaction to the registration being processed. |
|
| 35 | + * This is set via the _set_related_details method. |
|
| 36 | + * |
|
| 37 | + * @var array |
|
| 38 | + */ |
|
| 39 | + protected $_transaction_details = array(); |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * An array of event details for the related event to the registration being processed. |
|
| 45 | + * This is set via the _set_related_details method. |
|
| 46 | + * |
|
| 47 | + * @var array |
|
| 48 | + */ |
|
| 49 | + protected $_event_details = array(); |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @param \Registrations_Admin_Page $admin_page |
|
| 55 | + */ |
|
| 56 | + public function __construct(Registrations_Admin_Page $admin_page) |
|
| 57 | + { |
|
| 58 | + if ( ! empty($_GET['event_id'])) { |
|
| 59 | + $extra_query_args = array(); |
|
| 60 | + foreach ($admin_page->get_views() as $key => $view_details) { |
|
| 61 | + $extra_query_args[$view_details['slug']] = array('event_id' => $_GET['event_id']); |
|
| 62 | + } |
|
| 63 | + $this->_views = $admin_page->get_list_table_view_RLs($extra_query_args); |
|
| 64 | + } |
|
| 65 | + parent::__construct($admin_page); |
|
| 66 | + $this->_status = $this->_admin_page->get_registration_status_array(); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * _setup_data |
|
| 73 | + * |
|
| 74 | + * @access protected |
|
| 75 | + * @return void |
|
| 76 | + */ |
|
| 77 | + protected function _setup_data() |
|
| 78 | + { |
|
| 79 | + $this->_data = $this->_admin_page->get_registrations($this->_per_page); |
|
| 80 | + $this->_all_data_count = $this->_admin_page->get_registrations($this->_per_page, true, false, false); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * _set_properties |
|
| 87 | + * |
|
| 88 | + * @access protected |
|
| 89 | + * @return void |
|
| 90 | + */ |
|
| 91 | + protected function _set_properties() |
|
| 92 | + { |
|
| 93 | + $this->_wp_list_args = array( |
|
| 94 | + 'singular' => __('registration', 'event_espresso'), |
|
| 95 | + 'plural' => __('registrations', 'event_espresso'), |
|
| 96 | + 'ajax' => true, |
|
| 97 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 98 | + ); |
|
| 99 | + $ID_column_name = __('ID', 'event_espresso'); |
|
| 100 | + $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">'; |
|
| 101 | + $ID_column_name .= __('Registrant Name', 'event_espresso'); |
|
| 102 | + $ID_column_name .= '</span> '; |
|
| 103 | + if (isset($_GET['event_id'])) { |
|
| 104 | + $this->_columns = array( |
|
| 105 | + 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text |
|
| 106 | + '_REG_ID' => $ID_column_name, |
|
| 107 | + 'ATT_fname' => __('Name', 'event_espresso'), |
|
| 108 | + 'ATT_email' => __('Email', 'event_espresso'), |
|
| 109 | + '_REG_date' => __('Reg Date', 'event_espresso'), |
|
| 110 | + 'PRC_amount' => __('TKT Price', 'event_espresso'), |
|
| 111 | + '_REG_final_price' => __('Final Price', 'event_espresso'), |
|
| 112 | + 'TXN_total' => __('Total Txn', 'event_espresso'), |
|
| 113 | + 'TXN_paid' => __('Paid', 'event_espresso'), |
|
| 114 | + 'actions' => __('Actions', 'event_espresso'), |
|
| 115 | + ); |
|
| 116 | + $this->_bottom_buttons = array( |
|
| 117 | + 'report' => array( |
|
| 118 | + 'route' => 'registrations_report', |
|
| 119 | + 'extra_request' => array( |
|
| 120 | + 'EVT_ID' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null, |
|
| 121 | + 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
| 122 | + ), |
|
| 123 | + ), |
|
| 124 | + ); |
|
| 125 | + } else { |
|
| 126 | + $this->_columns = array( |
|
| 127 | + 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text |
|
| 128 | + '_REG_ID' => $ID_column_name, |
|
| 129 | + 'ATT_fname' => __('Name', 'event_espresso'), |
|
| 130 | + '_REG_date' => __('TXN Date', 'event_espresso'), |
|
| 131 | + 'event_name' => __('Event', 'event_espresso'), |
|
| 132 | + 'DTT_EVT_start' => __('Event Date', 'event_espresso'), |
|
| 133 | + '_REG_final_price' => __('Price', 'event_espresso'), |
|
| 134 | + '_REG_paid' => __('Paid', 'event_espresso'), |
|
| 135 | + 'actions' => __('Actions', 'event_espresso'), |
|
| 136 | + ); |
|
| 137 | + $this->_bottom_buttons = array( |
|
| 138 | + 'report_all' => array( |
|
| 139 | + 'route' => 'registrations_report', |
|
| 140 | + 'extra_request' => array( |
|
| 141 | + 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
| 142 | + ), |
|
| 143 | + ), |
|
| 144 | + ); |
|
| 145 | + } |
|
| 146 | + $this->_bottom_buttons['report_filtered'] = array( |
|
| 147 | + 'route' => 'registrations_report', |
|
| 148 | + 'extra_request' => array( |
|
| 149 | + 'use_filters' => true, |
|
| 150 | + 'filters' => array_diff_key($this->_req_data, array_flip(array( |
|
| 151 | + 'page', |
|
| 152 | + 'action', |
|
| 153 | + 'default_nonce', |
|
| 154 | + ))), |
|
| 155 | + 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
| 156 | + ), |
|
| 157 | + ); |
|
| 158 | + $this->_primary_column = '_REG_ID'; |
|
| 159 | + $this->_sortable_columns = array( |
|
| 160 | + '_REG_date' => array('_REG_date' => true), //true means its already sorted |
|
| 161 | + /** |
|
| 162 | + * Allows users to change the default sort if they wish. |
|
| 163 | + * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name. |
|
| 164 | + */ |
|
| 165 | + 'ATT_fname' => array( |
|
| 166 | + 'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name', |
|
| 167 | + true, |
|
| 168 | + $this |
|
| 169 | + ) |
|
| 170 | + ? array('ATT_lname' => false) |
|
| 171 | + : array('ATT_fname' => false), |
|
| 172 | + 'event_name' => array('event_name' => false), |
|
| 173 | + 'DTT_EVT_start' => array('DTT_EVT_start' => false), |
|
| 174 | + '_REG_ID' => array('_REG_ID' => false), |
|
| 175 | + ); |
|
| 176 | + $this->_hidden_columns = array(); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * This simply sets up the row class for the table rows. |
|
| 183 | + * Allows for easier overriding of child methods for setting up sorting. |
|
| 184 | + * |
|
| 185 | + * @param EE_Registration $item the current item |
|
| 186 | + * @return string |
|
| 187 | + */ |
|
| 188 | + protected function _get_row_class($item) |
|
| 189 | + { |
|
| 190 | + $class = parent::_get_row_class($item); |
|
| 191 | + //add status class |
|
| 192 | + $class .= ' ee-status-strip reg-status-' . $item->status_ID(); |
|
| 193 | + if ($this->_has_checkbox_column) { |
|
| 194 | + $class .= ' has-checkbox-column'; |
|
| 195 | + } |
|
| 196 | + return $class; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * Set the $_transaction_details property if not set yet. |
|
| 203 | + * |
|
| 204 | + * @param EE_Registration $registration |
|
| 205 | + * @throws \EE_Error |
|
| 206 | + */ |
|
| 207 | + protected function _set_related_details(EE_Registration $registration) |
|
| 208 | + { |
|
| 209 | + $transaction = $registration->get_first_related('Transaction'); |
|
| 210 | + $status = $transaction instanceof EE_Transaction ? $transaction->status_ID() |
|
| 211 | + : EEM_Transaction::failed_status_code; |
|
| 212 | + $this->_transaction_details = array( |
|
| 213 | + 'transaction' => $transaction, |
|
| 214 | + 'status' => $status, |
|
| 215 | + 'id' => $transaction instanceof EE_Transaction ? $transaction->ID() : 0, |
|
| 216 | + 'title_attr' => sprintf(__('View Transaction Details (%s)', 'event_espresso'), |
|
| 217 | + EEH_Template::pretty_status($status, false, 'sentence')), |
|
| 218 | + ); |
|
| 219 | + try { |
|
| 220 | + $event = $registration->event(); |
|
| 221 | + } catch (\EventEspresso\core\exceptions\EntityNotFoundException $e) { |
|
| 222 | + $event = null; |
|
| 223 | + } |
|
| 224 | + $status = $event instanceof EE_Event ? $event->get_active_status() : EE_Datetime::inactive; |
|
| 225 | + $this->_event_details = array( |
|
| 226 | + 'event' => $event, |
|
| 227 | + 'status' => $status, |
|
| 228 | + 'id' => $event instanceof EE_Event ? $event->ID() : 0, |
|
| 229 | + 'title_attr' => sprintf(__('Edit Event (%s)', 'event_espresso'), |
|
| 230 | + EEH_Template::pretty_status($status, false, 'sentence')), |
|
| 231 | + ); |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * _get_table_filters |
|
| 238 | + * |
|
| 239 | + * @access protected |
|
| 240 | + * @return array |
|
| 241 | + */ |
|
| 242 | + protected function _get_table_filters() |
|
| 243 | + { |
|
| 244 | + $filters = array(); |
|
| 245 | + //todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as methods. |
|
| 246 | + $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : ''; |
|
| 247 | + $cur_category = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1; |
|
| 248 | + $reg_status = isset($this->_req_data['_reg_status']) ? $this->_req_data['_reg_status'] : ''; |
|
| 249 | + $filters[] = EEH_Form_Fields::generate_registration_months_dropdown($cur_date, $reg_status, $cur_category); |
|
| 250 | + $filters[] = EEH_Form_Fields::generate_event_category_dropdown($cur_category); |
|
| 251 | + $status = array(); |
|
| 252 | + $status[] = array('id' => 0, 'text' => __('Select Status', 'event_espresso')); |
|
| 253 | + foreach ($this->_status as $key => $value) { |
|
| 254 | + $status[] = array('id' => $key, 'text' => $value); |
|
| 255 | + } |
|
| 256 | + if ($this->_view !== 'incomplete') { |
|
| 257 | + $filters[] = EEH_Form_Fields::select_input('_reg_status', $status, |
|
| 258 | + isset($this->_req_data['_reg_status']) ? strtoupper(sanitize_key($this->_req_data['_reg_status'])) |
|
| 259 | + : ''); |
|
| 260 | + } |
|
| 261 | + if (isset($this->_req_data['event_id'])) { |
|
| 262 | + $filters[] = EEH_Form_Fields::hidden_input('event_id', $this->_req_data['event_id'], 'reg_event_id'); |
|
| 263 | + } |
|
| 264 | + return $filters; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * _add_view_counts |
|
| 271 | + * |
|
| 272 | + * @access protected |
|
| 273 | + * @return void |
|
| 274 | + * @throws \EE_Error |
|
| 275 | + */ |
|
| 276 | + protected function _add_view_counts() |
|
| 277 | + { |
|
| 278 | + $this->_views['all']['count'] = $this->_total_registrations(); |
|
| 279 | + $this->_views['month']['count'] = $this->_total_registrations_this_month(); |
|
| 280 | + $this->_views['today']['count'] = $this->_total_registrations_today(); |
|
| 281 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registrations', |
|
| 282 | + 'espresso_registrations_trash_registrations') |
|
| 283 | + ) { |
|
| 284 | + $this->_views['incomplete']['count'] = $this->_total_registrations('incomplete'); |
|
| 285 | + $this->_views['trash']['count'] = $this->_total_registrations('trash'); |
|
| 286 | + } |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + |
|
| 290 | + |
|
| 291 | + /** |
|
| 292 | + * _total_registrations |
|
| 293 | + * |
|
| 294 | + * @access protected |
|
| 295 | + * @param string $view |
|
| 296 | + * @return int |
|
| 297 | + * @throws \EE_Error |
|
| 298 | + */ |
|
| 299 | + protected function _total_registrations($view = '') |
|
| 300 | + { |
|
| 301 | + $_where = array(); |
|
| 302 | + $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
| 303 | + if ($EVT_ID) { |
|
| 304 | + $_where['EVT_ID'] = $EVT_ID; |
|
| 305 | + } |
|
| 306 | + switch ($view) { |
|
| 307 | + case 'trash' : |
|
| 308 | + return EEM_Registration::instance()->count_deleted(array($_where)); |
|
| 309 | + break; |
|
| 310 | + case 'incomplete' : |
|
| 311 | + $_where['STS_ID'] = EEM_Registration::status_id_incomplete; |
|
| 312 | + break; |
|
| 313 | + default : |
|
| 314 | + $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
| 315 | + } |
|
| 316 | + return EEM_Registration::instance()->count(array($_where)); |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * _total_registrations_this_month |
|
| 323 | + * |
|
| 324 | + * @access protected |
|
| 325 | + * @return int |
|
| 326 | + * @throws \EE_Error |
|
| 327 | + */ |
|
| 328 | + protected function _total_registrations_this_month() |
|
| 329 | + { |
|
| 330 | + $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
| 331 | + $_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array(); |
|
| 332 | + $this_year_r = date('Y', current_time('timestamp')); |
|
| 333 | + $time_start = ' 00:00:00'; |
|
| 334 | + $time_end = ' 23:59:59'; |
|
| 335 | + $this_month_r = date('m', current_time('timestamp')); |
|
| 336 | + $days_this_month = date('t', current_time('timestamp')); |
|
| 337 | + //setup date query. |
|
| 338 | + $beginning_string = EEM_Registration::instance() |
|
| 339 | + ->convert_datetime_for_query('REG_date', |
|
| 340 | + $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start, |
|
| 341 | + 'Y-m-d H:i:s'); |
|
| 342 | + $end_string = EEM_Registration::instance() |
|
| 343 | + ->convert_datetime_for_query('REG_date', |
|
| 344 | + $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end, |
|
| 345 | + 'Y-m-d H:i:s'); |
|
| 346 | + $_where['REG_date'] = array( |
|
| 347 | + 'BETWEEN', |
|
| 348 | + array( |
|
| 349 | + $beginning_string, |
|
| 350 | + $end_string, |
|
| 351 | + ), |
|
| 352 | + ); |
|
| 353 | + $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
| 354 | + return EEM_Registration::instance()->count(array($_where)); |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * _total_registrations_today |
|
| 361 | + * |
|
| 362 | + * @access protected |
|
| 363 | + * @return int |
|
| 364 | + * @throws \EE_Error |
|
| 365 | + */ |
|
| 366 | + protected function _total_registrations_today() |
|
| 367 | + { |
|
| 368 | + $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
| 369 | + $_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array(); |
|
| 370 | + $current_date = date('Y-m-d', current_time('timestamp')); |
|
| 371 | + $time_start = ' 00:00:00'; |
|
| 372 | + $time_end = ' 23:59:59'; |
|
| 373 | + $_where['REG_date'] = array( |
|
| 374 | + 'BETWEEN', |
|
| 375 | + array( |
|
| 376 | + EEM_Registration::instance() |
|
| 377 | + ->convert_datetime_for_query('REG_date', $current_date . $time_start, 'Y-m-d H:i:s'), |
|
| 378 | + EEM_Registration::instance() |
|
| 379 | + ->convert_datetime_for_query('REG_date', $current_date . $time_end, 'Y-m-d H:i:s'), |
|
| 380 | + ), |
|
| 381 | + ); |
|
| 382 | + $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
| 383 | + return EEM_Registration::instance()->count(array($_where)); |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * column_cb |
|
| 390 | + * |
|
| 391 | + * @access public |
|
| 392 | + * @param \EE_Registration $item |
|
| 393 | + * @return string |
|
| 394 | + * @throws \EE_Error |
|
| 395 | + */ |
|
| 396 | + public function column_cb($item) |
|
| 397 | + { |
|
| 398 | + /** checkbox/lock **/ |
|
| 399 | + $transaction = $item->get_first_related('Transaction'); |
|
| 400 | + $payment_count = $transaction instanceof EE_Transaction ? $transaction->count_related('Payment') : 0; |
|
| 401 | + return $payment_count > 0 |
|
| 402 | + || ! EE_Registry::instance()->CAP->current_user_can( |
|
| 403 | + 'ee_edit_registration', |
|
| 404 | + 'registration_list_table_checkbox_input', |
|
| 405 | + $item->ID() |
|
| 406 | + ) |
|
| 407 | + ? sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID()) |
|
| 408 | + . '<span class="ee-lock-icon"></span>' |
|
| 409 | + : sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID()); |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + |
|
| 413 | + |
|
| 414 | + /** |
|
| 415 | + * column__REG_ID |
|
| 416 | + * |
|
| 417 | + * @access public |
|
| 418 | + * @param \EE_Registration $item |
|
| 419 | + * @return string |
|
| 420 | + * @throws \EE_Error |
|
| 421 | + */ |
|
| 422 | + public function column__REG_ID(EE_Registration $item) |
|
| 423 | + { |
|
| 424 | + $attendee = $item->attendee(); |
|
| 425 | + $content = $item->ID(); |
|
| 426 | + $content .= '<div class="show-on-mobile-view-only">'; |
|
| 427 | + $content .= '<br>'; |
|
| 428 | + $content .= $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
|
| 429 | + $content .= ' ' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
| 430 | + $content .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
| 431 | + $content .= '</div>'; |
|
| 432 | + return $content; |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * column__REG_date |
|
| 439 | + * |
|
| 440 | + * @access public |
|
| 441 | + * @param \EE_Registration $item |
|
| 442 | + * @return string |
|
| 443 | + * @throws \EE_Error |
|
| 444 | + */ |
|
| 445 | + public function column__REG_date(EE_Registration $item) |
|
| 446 | + { |
|
| 447 | + $this->_set_related_details($item); |
|
| 448 | + //Build row actions |
|
| 449 | + $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 450 | + 'action' => 'view_transaction', |
|
| 451 | + 'TXN_ID' => $this->_transaction_details['id'], |
|
| 452 | + ), TXN_ADMIN_URL); |
|
| 453 | + $view_link = EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', |
|
| 454 | + 'espresso_transactions_view_transaction') ? '<a class="ee-status-color-' |
|
| 455 | + . $this->_transaction_details['status'] |
|
| 456 | + . '" href="' |
|
| 457 | + . $view_lnk_url |
|
| 458 | + . '" title="' |
|
| 459 | + . esc_attr($this->_transaction_details['title_attr']) |
|
| 460 | + . '">' |
|
| 461 | + . $item->get_i18n_datetime('REG_date') |
|
| 462 | + . '</a>' : $item->get_i18n_datetime('REG_date'); |
|
| 463 | + $view_link .= '<br><span class="ee-status-text-small">' |
|
| 464 | + . EEH_Template::pretty_status($this->_transaction_details['status'], false, 'sentence') |
|
| 465 | + . '</span>'; |
|
| 466 | + return $view_link; |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + |
|
| 470 | + |
|
| 471 | + /** |
|
| 472 | + * column_event_name |
|
| 473 | + * |
|
| 474 | + * @access public |
|
| 475 | + * @param \EE_Registration $item |
|
| 476 | + * @return string |
|
| 477 | + * @throws \EE_Error |
|
| 478 | + */ |
|
| 479 | + public function column_event_name(EE_Registration $item) |
|
| 480 | + { |
|
| 481 | + $this->_set_related_details($item); |
|
| 482 | + // page=espresso_events&action=edit_event&EVT_ID=2&edit_event_nonce=cf3a7e5b62 |
|
| 483 | + $EVT_ID = $item->event_ID(); |
|
| 484 | + $event_name = $item->event_name(); |
|
| 485 | + $event_name = $event_name ? $event_name : __("No Associated Event", 'event_espresso'); |
|
| 486 | + $event_name = wp_trim_words($event_name, 30, '...'); |
|
| 487 | + if ($EVT_ID) { |
|
| 488 | + $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $EVT_ID), |
|
| 489 | + EVENTS_ADMIN_URL); |
|
| 490 | + $edit_event = EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'edit_event', $EVT_ID) |
|
| 491 | + ? '<a class="ee-status-color-' |
|
| 492 | + . $this->_event_details['status'] |
|
| 493 | + . '" href="' |
|
| 494 | + . $edit_event_url |
|
| 495 | + . '" title="' |
|
| 496 | + . esc_attr($this->_event_details['title_attr']) |
|
| 497 | + . '">' |
|
| 498 | + . $event_name |
|
| 499 | + . '</a>' : $event_name; |
|
| 500 | + $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('event_id' => $EVT_ID), REG_ADMIN_URL); |
|
| 501 | + $actions['event_filter'] = '<a href="' . $edit_event_url . '" title="'; |
|
| 502 | + $actions['event_filter'] .= sprintf(esc_attr__('Filter this list to only show registrations for %s', |
|
| 503 | + 'event_espresso'), $event_name); |
|
| 504 | + $actions['event_filter'] .= '">' . __('View Registrations', 'event_espresso') . '</a>'; |
|
| 505 | + } else { |
|
| 506 | + $edit_event = $event_name; |
|
| 507 | + $actions['event_filter'] = ''; |
|
| 508 | + } |
|
| 509 | + return sprintf('%1$s %2$s', $edit_event, $this->row_actions($actions)); |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + |
|
| 513 | + |
|
| 514 | + /** |
|
| 515 | + * column_DTT_EVT_start |
|
| 516 | + * |
|
| 517 | + * @access public |
|
| 518 | + * @param \EE_Registration $item |
|
| 519 | + * @return string |
|
| 520 | + * @throws \EE_Error |
|
| 521 | + */ |
|
| 522 | + public function column_DTT_EVT_start(EE_Registration $item) |
|
| 523 | + { |
|
| 524 | + $datetime_strings = array(); |
|
| 525 | + $ticket = $item->ticket(true); |
|
| 526 | + if ($ticket instanceof EE_Ticket) { |
|
| 527 | + $remove_defaults = array('default_where_conditions' => 'none'); |
|
| 528 | + $datetimes = $ticket->datetimes($remove_defaults); |
|
| 529 | + foreach ($datetimes as $datetime) { |
|
| 530 | + $datetime_strings[] = $datetime->get_i18n_datetime('DTT_EVT_start'); |
|
| 531 | + } |
|
| 532 | + return implode("<br />", $datetime_strings); |
|
| 533 | + } else { |
|
| 534 | + return __('There is no ticket on this registration', 'event_espresso'); |
|
| 535 | + } |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + |
|
| 539 | + |
|
| 540 | + /** |
|
| 541 | + * column_ATT_fname |
|
| 542 | + * |
|
| 543 | + * @access public |
|
| 544 | + * @param \EE_Registration $item |
|
| 545 | + * @return string |
|
| 546 | + * @throws \EE_Error |
|
| 547 | + */ |
|
| 548 | + public function column_ATT_fname(EE_Registration $item) |
|
| 549 | + { |
|
| 550 | + $attendee = $item->attendee(); |
|
| 551 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 552 | + 'action' => 'view_registration', |
|
| 553 | + '_REG_ID' => $item->ID(), |
|
| 554 | + ), REG_ADMIN_URL); |
|
| 555 | + $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
|
| 556 | + $link = EE_Registry::instance()->CAP->current_user_can('ee_read_registration', |
|
| 557 | + 'espresso_registrations_view_registration', $item->ID()) ? '<a href="' |
|
| 558 | + . $edit_lnk_url |
|
| 559 | + . '" title="' |
|
| 560 | + . esc_attr__('View Registration Details', |
|
| 561 | + 'event_espresso') |
|
| 562 | + . '">' |
|
| 563 | + . $attendee_name |
|
| 564 | + . '</a>' : $attendee_name; |
|
| 565 | + $link .= $item->count() === 1 |
|
| 566 | + ? ' <sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>' : ''; |
|
| 567 | + $t = $item->get_first_related('Transaction'); |
|
| 568 | + $payment_count = $t instanceof EE_Transaction ? $t->count_related('Payment') : 0; |
|
| 569 | + //append group count to name |
|
| 570 | + $link .= ' ' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
| 571 | + //append reg_code |
|
| 572 | + $link .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
| 573 | + //reg status text for accessibility |
|
| 574 | + $link .= '<br><span class="ee-status-text-small">' . EEH_Template::pretty_status($item->status_ID(), false, |
|
| 575 | + 'sentence') . '</span>'; |
|
| 576 | + //trash/restore/delete actions |
|
| 577 | + $actions = array(); |
|
| 578 | + if ($this->_view !== 'trash' |
|
| 579 | + && $payment_count === 0 |
|
| 580 | + && EE_Registry::instance()->CAP->current_user_can('ee_delete_registration', |
|
| 581 | + 'espresso_registrations_trash_registrations', $item->ID()) |
|
| 582 | + ) { |
|
| 583 | + $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 584 | + 'action' => 'trash_registrations', |
|
| 585 | + '_REG_ID' => $item->ID(), |
|
| 586 | + ), REG_ADMIN_URL); |
|
| 587 | + $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="' . esc_attr__('Trash Registration', |
|
| 588 | + 'event_espresso') . '">' . __('Trash', 'event_espresso') . '</a>'; |
|
| 589 | + } elseif ($this->_view === 'trash') { |
|
| 590 | + // restore registration link |
|
| 591 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registration', |
|
| 592 | + 'espresso_registrations_restore_registrations', $item->ID()) |
|
| 593 | + ) { |
|
| 594 | + $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 595 | + 'action' => 'restore_registrations', |
|
| 596 | + '_REG_ID' => $item->ID(), |
|
| 597 | + ), REG_ADMIN_URL); |
|
| 598 | + $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="' . esc_attr__('Restore Registration', |
|
| 599 | + 'event_espresso') . '">' . __('Restore', 'event_espresso') . '</a>'; |
|
| 600 | + } |
|
| 601 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registration', |
|
| 602 | + 'espresso_registrations_ee_delete_registrations', $item->ID()) |
|
| 603 | + ) { |
|
| 604 | + $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 605 | + 'action' => 'delete_registrations', |
|
| 606 | + '_REG_ID' => $item->ID(), |
|
| 607 | + ), REG_ADMIN_URL); |
|
| 608 | + $actions['delete'] = '<a href="' |
|
| 609 | + . $delete_lnk_url |
|
| 610 | + . '" title="' |
|
| 611 | + . esc_attr__('Delete Registration Permanently', 'event_espresso') |
|
| 612 | + . '">' |
|
| 613 | + . __('Delete', 'event_espresso') |
|
| 614 | + . '</a>'; |
|
| 615 | + } |
|
| 616 | + } |
|
| 617 | + return sprintf('%1$s %2$s', $link, $this->row_actions($actions)); |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + |
|
| 621 | + |
|
| 622 | + /** |
|
| 623 | + * column_ATT_email |
|
| 624 | + * |
|
| 625 | + * @access public |
|
| 626 | + * @param \EE_Registration $item |
|
| 627 | + * @return string |
|
| 628 | + * @throws \EE_Error |
|
| 629 | + */ |
|
| 630 | + public function column_ATT_email(EE_Registration $item) |
|
| 631 | + { |
|
| 632 | + $attendee = $item->get_first_related('Attendee'); |
|
| 633 | + return ! $attendee instanceof EE_Attendee ? __('No attached contact record.', 'event_espresso') |
|
| 634 | + : $attendee->email(); |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + |
|
| 638 | + |
|
| 639 | + /** |
|
| 640 | + * column__REG_count |
|
| 641 | + * |
|
| 642 | + * @access public |
|
| 643 | + * @param \EE_Registration $item |
|
| 644 | + * @return string |
|
| 645 | + */ |
|
| 646 | + public function column__REG_count(EE_Registration $item) |
|
| 647 | + { |
|
| 648 | + return sprintf(__('%1$s / %2$s', 'event_espresso'), $item->count(), $item->group_size()); |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + |
|
| 652 | + |
|
| 653 | + /** |
|
| 654 | + * column_PRC_amount |
|
| 655 | + * |
|
| 656 | + * @access public |
|
| 657 | + * @param \EE_Registration $item |
|
| 658 | + * @return string |
|
| 659 | + */ |
|
| 660 | + public function column_PRC_amount(EE_Registration $item) |
|
| 661 | + { |
|
| 662 | + $ticket = $item->ticket(); |
|
| 663 | + $content = isset($_GET['event_id']) && $ticket instanceof EE_Ticket ? '<span class="TKT_name">' |
|
| 664 | + . $ticket->name() |
|
| 665 | + . '</span><br />' : ''; |
|
| 666 | + if ($item->final_price() > 0) { |
|
| 667 | + $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>'; |
|
| 668 | + } else { |
|
| 669 | + // free event |
|
| 670 | + $content .= '<span class="reg-overview-free-event-spn reg-pad-rght">' |
|
| 671 | + . __('free', 'event_espresso') |
|
| 672 | + . '</span>'; |
|
| 673 | + } |
|
| 674 | + return $content; |
|
| 675 | + } |
|
| 676 | + |
|
| 677 | + |
|
| 678 | + |
|
| 679 | + /** |
|
| 680 | + * column__REG_final_price |
|
| 681 | + * |
|
| 682 | + * @access public |
|
| 683 | + * @param \EE_Registration $item |
|
| 684 | + * @return string |
|
| 685 | + */ |
|
| 686 | + public function column__REG_final_price(EE_Registration $item) |
|
| 687 | + { |
|
| 688 | + $ticket = $item->ticket(); |
|
| 689 | + $content = isset($_GET['event_id']) || ! $ticket instanceof EE_Ticket |
|
| 690 | + ? '' |
|
| 691 | + : '<span class="TKT_name">' |
|
| 692 | + . $ticket->name() |
|
| 693 | + . '</span><br />'; |
|
| 694 | + $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>'; |
|
| 695 | + return $content; |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + |
|
| 699 | + |
|
| 700 | + /** |
|
| 701 | + * column__REG_paid |
|
| 702 | + * |
|
| 703 | + * @access public |
|
| 704 | + * @param \EE_Registration $item |
|
| 705 | + * @return string |
|
| 706 | + */ |
|
| 707 | + public function column__REG_paid(EE_Registration $item) |
|
| 708 | + { |
|
| 709 | + $payment_method = $item->payment_method(); |
|
| 710 | + $payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name() |
|
| 711 | + : __('Unknown', 'event_espresso'); |
|
| 712 | + $content = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>'; |
|
| 713 | + if ($item->paid() > 0) { |
|
| 714 | + $content .= '<br><span class="ee-status-text-small">' . sprintf(__('...via %s', 'event_espresso'), |
|
| 715 | + $payment_method_name) . '</span>'; |
|
| 716 | + } |
|
| 717 | + return $content; |
|
| 718 | + } |
|
| 719 | + |
|
| 720 | + |
|
| 721 | + |
|
| 722 | + /** |
|
| 723 | + * column_TXN_total |
|
| 724 | + * |
|
| 725 | + * @access public |
|
| 726 | + * @param \EE_Registration $item |
|
| 727 | + * @return string |
|
| 728 | + * @throws \EE_Error |
|
| 729 | + */ |
|
| 730 | + public function column_TXN_total(EE_Registration $item) |
|
| 731 | + { |
|
| 732 | + if ($item->transaction()) { |
|
| 733 | + $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 734 | + 'action' => 'view_transaction', |
|
| 735 | + 'TXN_ID' => $item->transaction_ID(), |
|
| 736 | + ), TXN_ADMIN_URL); |
|
| 737 | + return EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', |
|
| 738 | + 'espresso_transactions_view_transaction', $item->transaction_ID()) |
|
| 739 | + ? '<span class="reg-pad-rght"><a class="status-' |
|
| 740 | + . $item->transaction()->status_ID() |
|
| 741 | + . '" href="' |
|
| 742 | + . $view_txn_lnk_url |
|
| 743 | + . '" title="' |
|
| 744 | + . esc_attr__('View Transaction', 'event_espresso') |
|
| 745 | + . '">' |
|
| 746 | + . $item->transaction()->pretty_total() |
|
| 747 | + . '</a></span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>'; |
|
| 748 | + } else { |
|
| 749 | + return __("None", "event_espresso"); |
|
| 750 | + } |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + |
|
| 754 | + |
|
| 755 | + /** |
|
| 756 | + * column_TXN_paid |
|
| 757 | + * |
|
| 758 | + * @access public |
|
| 759 | + * @param \EE_Registration $item |
|
| 760 | + * @return string |
|
| 761 | + * @throws \EE_Error |
|
| 762 | + */ |
|
| 763 | + public function column_TXN_paid(EE_Registration $item) |
|
| 764 | + { |
|
| 765 | + if ($item->count() === 1) { |
|
| 766 | + $transaction = $item->transaction() ? $item->transaction() : EE_Transaction::new_instance(); |
|
| 767 | + if ($transaction->paid() >= $transaction->total()) { |
|
| 768 | + return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>'; |
|
| 769 | + } else { |
|
| 770 | + $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 771 | + 'action' => 'view_transaction', |
|
| 772 | + 'TXN_ID' => $item->transaction_ID(), |
|
| 773 | + ), TXN_ADMIN_URL); |
|
| 774 | + return EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', |
|
| 775 | + 'espresso_transactions_view_transaction', $item->transaction_ID()) |
|
| 776 | + ? '<span class="reg-pad-rght"><a class="status-' |
|
| 777 | + . $transaction->status_ID() |
|
| 778 | + . '" href="' |
|
| 779 | + . $view_txn_lnk_url |
|
| 780 | + . '" title="' |
|
| 781 | + . esc_attr__('View Transaction', 'event_espresso') |
|
| 782 | + . '">' |
|
| 783 | + . $item->transaction()->pretty_paid() |
|
| 784 | + . '</a><span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>'; |
|
| 785 | + } |
|
| 786 | + } |
|
| 787 | + return ' '; |
|
| 788 | + } |
|
| 789 | + |
|
| 790 | + |
|
| 791 | + |
|
| 792 | + /** |
|
| 793 | + * column_actions |
|
| 794 | + * |
|
| 795 | + * @access public |
|
| 796 | + * @param \EE_Registration $item |
|
| 797 | + * @return string |
|
| 798 | + * @throws \EE_Error |
|
| 799 | + */ |
|
| 800 | + public function column_actions(EE_Registration $item) |
|
| 801 | + { |
|
| 802 | + $actions = array(); |
|
| 803 | + $attendee = $item->attendee(); |
|
| 804 | + $this->_set_related_details($item); |
|
| 805 | + //Build row actions |
|
| 806 | + $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 807 | + 'action' => 'view_registration', |
|
| 808 | + '_REG_ID' => $item->ID(), |
|
| 809 | + ), REG_ADMIN_URL); |
|
| 810 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 811 | + 'action' => 'edit_attendee', |
|
| 812 | + 'post' => $item->attendee_ID(), |
|
| 813 | + ), REG_ADMIN_URL); |
|
| 814 | + // page=attendees&event_admin_reports=resend_email®istration_id=43653465634&event_id=2&form_action=resend_email |
|
| 815 | + //$resend_reg_lnk_url_params = array( 'action'=>'resend_registration', '_REG_ID'=>$item->REG_ID ); |
|
| 816 | + $resend_reg_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 817 | + 'action' => 'resend_registration', |
|
| 818 | + '_REG_ID' => $item->ID(), |
|
| 819 | + ), REG_ADMIN_URL, true); |
|
| 820 | + //Build row actions |
|
| 821 | + $actions['view_lnk'] = EE_Registry::instance()->CAP->current_user_can('ee_read_registration', |
|
| 822 | + 'espresso_registrations_view_registration', $item->ID()) ? ' |
|
| 823 | 823 | <li> |
| 824 | 824 | <a href="' . $view_lnk_url . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '" class="tiny-text"> |
| 825 | 825 | <div class="dashicons dashicons-clipboard"></div> |
| 826 | 826 | </a> |
| 827 | 827 | </li>' : ''; |
| 828 | - $actions['edit_lnk'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_contacts', |
|
| 829 | - 'espresso_registrations_edit_attendee') |
|
| 830 | - && $attendee instanceof EE_Attendee ? ' |
|
| 828 | + $actions['edit_lnk'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_contacts', |
|
| 829 | + 'espresso_registrations_edit_attendee') |
|
| 830 | + && $attendee instanceof EE_Attendee ? ' |
|
| 831 | 831 | <li> |
| 832 | 832 | <a href="' . $edit_lnk_url . '" title="' . esc_attr__('Edit Contact Details', 'event_espresso') . '" class="tiny-text"> |
| 833 | 833 | <div class="ee-icon ee-icon-user-edit ee-icon-size-16"></div> |
| 834 | 834 | </a> |
| 835 | 835 | </li>' : ''; |
| 836 | - $actions['resend_reg_lnk'] = $attendee instanceof EE_Attendee |
|
| 837 | - && EE_Registry::instance()->CAP->current_user_can('ee_send_message', |
|
| 838 | - 'espresso_registrations_resend_registration', $item->ID()) ? ' |
|
| 836 | + $actions['resend_reg_lnk'] = $attendee instanceof EE_Attendee |
|
| 837 | + && EE_Registry::instance()->CAP->current_user_can('ee_send_message', |
|
| 838 | + 'espresso_registrations_resend_registration', $item->ID()) ? ' |
|
| 839 | 839 | <li> |
| 840 | 840 | <a href="' |
| 841 | - . $resend_reg_lnk_url |
|
| 842 | - . '" title="' |
|
| 843 | - . esc_attr__('Resend Registration Details', |
|
| 844 | - 'event_espresso') |
|
| 845 | - . '" class="tiny-text"> |
|
| 841 | + . $resend_reg_lnk_url |
|
| 842 | + . '" title="' |
|
| 843 | + . esc_attr__('Resend Registration Details', |
|
| 844 | + 'event_espresso') |
|
| 845 | + . '" class="tiny-text"> |
|
| 846 | 846 | <div class="dashicons dashicons-email-alt"></div> |
| 847 | 847 | </a> |
| 848 | 848 | </li>' : ''; |
| 849 | - // page=transactions&action=view_transaction&txn=256&_wpnonce=6414da4dbb |
|
| 850 | - $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 851 | - 'action' => 'view_transaction', |
|
| 852 | - 'TXN_ID' => $this->_transaction_details['id'], |
|
| 853 | - ), TXN_ADMIN_URL); |
|
| 854 | - $actions['view_txn_lnk'] = EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', |
|
| 855 | - 'espresso_transactions_view_transaction', $this->_transaction_details['id']) ? ' |
|
| 849 | + // page=transactions&action=view_transaction&txn=256&_wpnonce=6414da4dbb |
|
| 850 | + $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 851 | + 'action' => 'view_transaction', |
|
| 852 | + 'TXN_ID' => $this->_transaction_details['id'], |
|
| 853 | + ), TXN_ADMIN_URL); |
|
| 854 | + $actions['view_txn_lnk'] = EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', |
|
| 855 | + 'espresso_transactions_view_transaction', $this->_transaction_details['id']) ? ' |
|
| 856 | 856 | <li> |
| 857 | 857 | <a class="ee-status-color-' |
| 858 | - . $this->_transaction_details['status'] |
|
| 859 | - . ' tiny-text" href="' |
|
| 860 | - . $view_txn_lnk_url |
|
| 861 | - . '" title="' |
|
| 862 | - . $this->_transaction_details['title_attr'] |
|
| 863 | - . '"> |
|
| 858 | + . $this->_transaction_details['status'] |
|
| 859 | + . ' tiny-text" href="' |
|
| 860 | + . $view_txn_lnk_url |
|
| 861 | + . '" title="' |
|
| 862 | + . $this->_transaction_details['title_attr'] |
|
| 863 | + . '"> |
|
| 864 | 864 | <div class="dashicons dashicons-cart"></div> |
| 865 | 865 | </a> |
| 866 | 866 | </li>' : ''; |
| 867 | - //invoice link |
|
| 868 | - $actions['dl_invoice_lnk'] = ''; |
|
| 869 | - $dl_invoice_lnk_url = $item->invoice_url(); |
|
| 870 | - //only show invoice link if message type is active. |
|
| 871 | - if ($attendee instanceof EE_Attendee |
|
| 872 | - && $item->is_primary_registrant() |
|
| 873 | - && EEH_MSG_Template::is_mt_active('invoice') |
|
| 874 | - ) { |
|
| 875 | - $actions['dl_invoice_lnk'] = ' |
|
| 867 | + //invoice link |
|
| 868 | + $actions['dl_invoice_lnk'] = ''; |
|
| 869 | + $dl_invoice_lnk_url = $item->invoice_url(); |
|
| 870 | + //only show invoice link if message type is active. |
|
| 871 | + if ($attendee instanceof EE_Attendee |
|
| 872 | + && $item->is_primary_registrant() |
|
| 873 | + && EEH_MSG_Template::is_mt_active('invoice') |
|
| 874 | + ) { |
|
| 875 | + $actions['dl_invoice_lnk'] = ' |
|
| 876 | 876 | <li> |
| 877 | 877 | <a title="' |
| 878 | - . esc_attr__('View Transaction Invoice', 'event_espresso') |
|
| 879 | - . '" target="_blank" href="' |
|
| 880 | - . $dl_invoice_lnk_url |
|
| 881 | - . '" class="tiny-text"> |
|
| 878 | + . esc_attr__('View Transaction Invoice', 'event_espresso') |
|
| 879 | + . '" target="_blank" href="' |
|
| 880 | + . $dl_invoice_lnk_url |
|
| 881 | + . '" class="tiny-text"> |
|
| 882 | 882 | <span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span> |
| 883 | 883 | </a> |
| 884 | 884 | </li>'; |
| 885 | - } |
|
| 886 | - $actions['filtered_messages_link'] = ''; |
|
| 887 | - //message list table link (filtered by REG_ID |
|
| 888 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
| 889 | - $actions['filtered_messages_link'] = '<li>' |
|
| 890 | - . EEH_MSG_Template::get_message_action_link('see_notifications_for', |
|
| 891 | - null, array( |
|
| 892 | - '_REG_ID' => $item->ID(), |
|
| 893 | - )) |
|
| 894 | - . '</li>'; |
|
| 895 | - } |
|
| 896 | - $actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $item, $this); |
|
| 897 | - return $this->_action_string(implode('', $actions), $item, 'ul', 'reg-overview-actions-ul'); |
|
| 898 | - } |
|
| 885 | + } |
|
| 886 | + $actions['filtered_messages_link'] = ''; |
|
| 887 | + //message list table link (filtered by REG_ID |
|
| 888 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
| 889 | + $actions['filtered_messages_link'] = '<li>' |
|
| 890 | + . EEH_MSG_Template::get_message_action_link('see_notifications_for', |
|
| 891 | + null, array( |
|
| 892 | + '_REG_ID' => $item->ID(), |
|
| 893 | + )) |
|
| 894 | + . '</li>'; |
|
| 895 | + } |
|
| 896 | + $actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $item, $this); |
|
| 897 | + return $this->_action_string(implode('', $actions), $item, 'ul', 'reg-overview-actions-ul'); |
|
| 898 | + } |
|
| 899 | 899 | |
| 900 | 900 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 3 | - exit('NO direct script access allowed'); |
|
| 3 | + exit('NO direct script access allowed'); |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | |
@@ -29,91 +29,91 @@ discard block |
||
| 29 | 29 | { |
| 30 | 30 | |
| 31 | 31 | |
| 32 | - public function __construct() |
|
| 33 | - { |
|
| 34 | - //define some page related constants |
|
| 35 | - define('EE_MAINTENANCE_LABEL', __('Maintenance', 'event_espresso')); |
|
| 36 | - define('EE_MAINTENANCE_PG_SLUG', 'espresso_maintenance_settings'); |
|
| 37 | - define('EE_MAINTENANCE_ADMIN_URL', admin_url('admin.php?page=' . EE_MAINTENANCE_PG_SLUG)); |
|
| 38 | - define('EE_MAINTENANCE_ADMIN', EE_ADMIN_PAGES . 'maintenance' . DS); |
|
| 39 | - define('EE_MAINTENANCE_TEMPLATE_PATH', EE_MAINTENANCE_ADMIN . 'templates' . DS); |
|
| 40 | - define('EE_MAINTENANCE_ASSETS_URL', EE_ADMIN_PAGES_URL . 'maintenance/assets/'); |
|
| 41 | - //check that if we're in maintenance mode that we tell the admin that |
|
| 42 | - add_action('admin_notices', array($this, 'check_maintenance_mode')); |
|
| 43 | - parent::__construct(); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - protected function _set_init_properties() |
|
| 49 | - { |
|
| 50 | - $this->label = EE_MAINTENANCE_LABEL; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - protected function _set_menu_map() |
|
| 56 | - { |
|
| 57 | - $menu_map = $this->_menu_map(); |
|
| 58 | - $this->_menu_map = EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 59 | - ? new EE_Admin_Page_Main_Menu($menu_map) : new EE_Admin_Page_Sub_Menu($menu_map); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - protected function _menu_map() |
|
| 65 | - { |
|
| 66 | - $map = array( |
|
| 67 | - 'menu_group' => 'extras', |
|
| 68 | - 'menu_order' => 30, |
|
| 69 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
| 70 | - 'parent_slug' => 'espresso_events', |
|
| 71 | - 'menu_slug' => EE_MAINTENANCE_PG_SLUG, |
|
| 72 | - 'menu_label' => EE_MAINTENANCE_LABEL, |
|
| 73 | - 'capability' => 'manage_options', |
|
| 74 | - 'maintenance_mode_parent' => EE_MAINTENANCE_PG_SLUG, |
|
| 75 | - 'admin_init_page' => $this, |
|
| 76 | - ); |
|
| 77 | - if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 78 | - $map['menu_group'] = 'main'; |
|
| 79 | - $map['subtitle'] = EE_MAINTENANCE_LABEL; |
|
| 80 | - $map['menu_label'] = __('Event Espresso', 'event_espresso'); |
|
| 81 | - } |
|
| 82 | - return $map; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Checks if we're in maintenance mode, and if so we notify the admin adn tell them how to take the site OUT of |
|
| 89 | - * maintenance mode |
|
| 90 | - */ |
|
| 91 | - public function check_maintenance_mode() |
|
| 92 | - { |
|
| 93 | - $notice = ''; |
|
| 94 | - $maintenance_page_url = ''; |
|
| 95 | - if (EE_Maintenance_Mode::instance()->level()) { |
|
| 96 | - $maintenance_page_url = EE_Admin_Page::add_query_args_and_nonce(array(), EE_MAINTENANCE_ADMIN_URL); |
|
| 97 | - switch (EE_Maintenance_Mode::instance()->level()) { |
|
| 98 | - case EE_Maintenance_Mode::level_1_frontend_only_maintenance: |
|
| 99 | - $notice = '<div class="update-nag"> |
|
| 32 | + public function __construct() |
|
| 33 | + { |
|
| 34 | + //define some page related constants |
|
| 35 | + define('EE_MAINTENANCE_LABEL', __('Maintenance', 'event_espresso')); |
|
| 36 | + define('EE_MAINTENANCE_PG_SLUG', 'espresso_maintenance_settings'); |
|
| 37 | + define('EE_MAINTENANCE_ADMIN_URL', admin_url('admin.php?page=' . EE_MAINTENANCE_PG_SLUG)); |
|
| 38 | + define('EE_MAINTENANCE_ADMIN', EE_ADMIN_PAGES . 'maintenance' . DS); |
|
| 39 | + define('EE_MAINTENANCE_TEMPLATE_PATH', EE_MAINTENANCE_ADMIN . 'templates' . DS); |
|
| 40 | + define('EE_MAINTENANCE_ASSETS_URL', EE_ADMIN_PAGES_URL . 'maintenance/assets/'); |
|
| 41 | + //check that if we're in maintenance mode that we tell the admin that |
|
| 42 | + add_action('admin_notices', array($this, 'check_maintenance_mode')); |
|
| 43 | + parent::__construct(); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + protected function _set_init_properties() |
|
| 49 | + { |
|
| 50 | + $this->label = EE_MAINTENANCE_LABEL; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + protected function _set_menu_map() |
|
| 56 | + { |
|
| 57 | + $menu_map = $this->_menu_map(); |
|
| 58 | + $this->_menu_map = EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 59 | + ? new EE_Admin_Page_Main_Menu($menu_map) : new EE_Admin_Page_Sub_Menu($menu_map); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + protected function _menu_map() |
|
| 65 | + { |
|
| 66 | + $map = array( |
|
| 67 | + 'menu_group' => 'extras', |
|
| 68 | + 'menu_order' => 30, |
|
| 69 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
| 70 | + 'parent_slug' => 'espresso_events', |
|
| 71 | + 'menu_slug' => EE_MAINTENANCE_PG_SLUG, |
|
| 72 | + 'menu_label' => EE_MAINTENANCE_LABEL, |
|
| 73 | + 'capability' => 'manage_options', |
|
| 74 | + 'maintenance_mode_parent' => EE_MAINTENANCE_PG_SLUG, |
|
| 75 | + 'admin_init_page' => $this, |
|
| 76 | + ); |
|
| 77 | + if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 78 | + $map['menu_group'] = 'main'; |
|
| 79 | + $map['subtitle'] = EE_MAINTENANCE_LABEL; |
|
| 80 | + $map['menu_label'] = __('Event Espresso', 'event_espresso'); |
|
| 81 | + } |
|
| 82 | + return $map; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Checks if we're in maintenance mode, and if so we notify the admin adn tell them how to take the site OUT of |
|
| 89 | + * maintenance mode |
|
| 90 | + */ |
|
| 91 | + public function check_maintenance_mode() |
|
| 92 | + { |
|
| 93 | + $notice = ''; |
|
| 94 | + $maintenance_page_url = ''; |
|
| 95 | + if (EE_Maintenance_Mode::instance()->level()) { |
|
| 96 | + $maintenance_page_url = EE_Admin_Page::add_query_args_and_nonce(array(), EE_MAINTENANCE_ADMIN_URL); |
|
| 97 | + switch (EE_Maintenance_Mode::instance()->level()) { |
|
| 98 | + case EE_Maintenance_Mode::level_1_frontend_only_maintenance: |
|
| 99 | + $notice = '<div class="update-nag"> |
|
| 100 | 100 | ' |
| 101 | - . sprintf(__("Event Espresso is in Frontend-Only MAINTENANCE MODE. This means the front-end (ie, non-wp-admin pages) is disabled for ALL users except site admins. Visit the %s Maintenance Page %s to disable maintenance mode.", |
|
| 102 | - "event_espresso"), "<a href='$maintenance_page_url'>", "</a>") |
|
| 103 | - . |
|
| 104 | - '</div>'; |
|
| 105 | - break; |
|
| 106 | - case EE_Maintenance_Mode::level_2_complete_maintenance: |
|
| 107 | - $notice = '<div class="error"> |
|
| 101 | + . sprintf(__("Event Espresso is in Frontend-Only MAINTENANCE MODE. This means the front-end (ie, non-wp-admin pages) is disabled for ALL users except site admins. Visit the %s Maintenance Page %s to disable maintenance mode.", |
|
| 102 | + "event_espresso"), "<a href='$maintenance_page_url'>", "</a>") |
|
| 103 | + . |
|
| 104 | + '</div>'; |
|
| 105 | + break; |
|
| 106 | + case EE_Maintenance_Mode::level_2_complete_maintenance: |
|
| 107 | + $notice = '<div class="error"> |
|
| 108 | 108 | <p>' . sprintf(__("As part of the process for updating Event Espresso, your database also |
| 109 | 109 | needs to be updated. Event Espresso is in COMPLETE MAINTENANCE MODE (both WordPress admin pages and front-end event registration pages are disabled) until you run the database update script. %s Visit the Maintenance Page to get started,%s it only takes a moment.", |
| 110 | - "event_espresso"), "<a href='$maintenance_page_url'>", "</a>") . |
|
| 111 | - '</div>'; |
|
| 112 | - break; |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - echo apply_filters('FHEE__Maintenance_Admin_Page_Init__check_maintenance_mode__notice', $notice, |
|
| 116 | - $maintenance_page_url); |
|
| 117 | - } |
|
| 110 | + "event_espresso"), "<a href='$maintenance_page_url'>", "</a>") . |
|
| 111 | + '</div>'; |
|
| 112 | + break; |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + echo apply_filters('FHEE__Maintenance_Admin_Page_Init__check_maintenance_mode__notice', $notice, |
|
| 116 | + $maintenance_page_url); |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | 119 | } //end class Payments_Admin_Page_Init |
@@ -34,10 +34,10 @@ discard block |
||
| 34 | 34 | //define some page related constants |
| 35 | 35 | define('EE_MAINTENANCE_LABEL', __('Maintenance', 'event_espresso')); |
| 36 | 36 | define('EE_MAINTENANCE_PG_SLUG', 'espresso_maintenance_settings'); |
| 37 | - define('EE_MAINTENANCE_ADMIN_URL', admin_url('admin.php?page=' . EE_MAINTENANCE_PG_SLUG)); |
|
| 38 | - define('EE_MAINTENANCE_ADMIN', EE_ADMIN_PAGES . 'maintenance' . DS); |
|
| 39 | - define('EE_MAINTENANCE_TEMPLATE_PATH', EE_MAINTENANCE_ADMIN . 'templates' . DS); |
|
| 40 | - define('EE_MAINTENANCE_ASSETS_URL', EE_ADMIN_PAGES_URL . 'maintenance/assets/'); |
|
| 37 | + define('EE_MAINTENANCE_ADMIN_URL', admin_url('admin.php?page='.EE_MAINTENANCE_PG_SLUG)); |
|
| 38 | + define('EE_MAINTENANCE_ADMIN', EE_ADMIN_PAGES.'maintenance'.DS); |
|
| 39 | + define('EE_MAINTENANCE_TEMPLATE_PATH', EE_MAINTENANCE_ADMIN.'templates'.DS); |
|
| 40 | + define('EE_MAINTENANCE_ASSETS_URL', EE_ADMIN_PAGES_URL.'maintenance/assets/'); |
|
| 41 | 41 | //check that if we're in maintenance mode that we tell the admin that |
| 42 | 42 | add_action('admin_notices', array($this, 'check_maintenance_mode')); |
| 43 | 43 | parent::__construct(); |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | $notice = '<div class="error"> |
| 108 | 108 | <p>' . sprintf(__("As part of the process for updating Event Espresso, your database also |
| 109 | 109 | needs to be updated. Event Espresso is in COMPLETE MAINTENANCE MODE (both WordPress admin pages and front-end event registration pages are disabled) until you run the database update script. %s Visit the Maintenance Page to get started,%s it only takes a moment.", |
| 110 | - "event_espresso"), "<a href='$maintenance_page_url'>", "</a>") . |
|
| 110 | + "event_espresso"), "<a href='$maintenance_page_url'>", "</a>"). |
|
| 111 | 111 | '</div>'; |
| 112 | 112 | break; |
| 113 | 113 | } |
@@ -39,8 +39,8 @@ discard block |
||
| 39 | 39 | if ( |
| 40 | 40 | ! ( $checkout->uts || $checkout->reg_url_link ) |
| 41 | 41 | && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) |
| 42 | - && \EE_Config::instance()->registration->track_invalid_checkout_access() |
|
| 43 | - ) { |
|
| 42 | + && \EE_Config::instance()->registration->track_invalid_checkout_access() |
|
| 43 | + ) { |
|
| 44 | 44 | /** @var \EE_Request $request */ |
| 45 | 45 | $request = \EE_Registry::instance()->load_core( 'EE_Request' ); |
| 46 | 46 | $ip_address = $request->ip_address(); |
@@ -60,14 +60,14 @@ discard block |
||
| 60 | 60 | } |
| 61 | 61 | $ee_bot_checkout[ $ip_address ][ $http_referer ]++; |
| 62 | 62 | update_option( InvalidCheckoutAccess::OPTION_KEY, $ee_bot_checkout ); |
| 63 | - if (WP_DEBUG) { |
|
| 64 | - \EE_Error::add_error( |
|
| 65 | - esc_html__('Direct access to the registration checkout page is not allowed.', 'event_espresso'), |
|
| 66 | - __FILE__, |
|
| 67 | - __FUNCTION__, |
|
| 68 | - __LINE__ |
|
| 69 | - ); |
|
| 70 | - } |
|
| 63 | + if (WP_DEBUG) { |
|
| 64 | + \EE_Error::add_error( |
|
| 65 | + esc_html__('Direct access to the registration checkout page is not allowed.', 'event_espresso'), |
|
| 66 | + __FILE__, |
|
| 67 | + __FUNCTION__, |
|
| 68 | + __LINE__ |
|
| 69 | + ); |
|
| 70 | + } |
|
| 71 | 71 | return true; |
| 72 | 72 | } |
| 73 | 73 | return false; |
@@ -1,8 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace EventEspresso\modules\invalid_checkout_access; |
| 3 | 3 | |
| 4 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 5 | - exit( 'No direct script access allowed' ); |
|
| 4 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 5 | + exit('No direct script access allowed'); |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | |
@@ -35,31 +35,31 @@ discard block |
||
| 35 | 35 | * @param \EE_Checkout $checkout |
| 36 | 36 | * @return bool true if access to registration checkout appears to be invalid |
| 37 | 37 | */ |
| 38 | - public function checkoutAccessIsInvalid( \EE_Checkout $checkout ) { |
|
| 38 | + public function checkoutAccessIsInvalid(\EE_Checkout $checkout) { |
|
| 39 | 39 | if ( |
| 40 | - ! ( $checkout->uts || $checkout->reg_url_link ) |
|
| 41 | - && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) |
|
| 40 | + ! ($checkout->uts || $checkout->reg_url_link) |
|
| 41 | + && ! (defined('DOING_AJAX') && DOING_AJAX) |
|
| 42 | 42 | && \EE_Config::instance()->registration->track_invalid_checkout_access() |
| 43 | 43 | ) { |
| 44 | 44 | /** @var \EE_Request $request */ |
| 45 | - $request = \EE_Registry::instance()->load_core( 'EE_Request' ); |
|
| 45 | + $request = \EE_Registry::instance()->load_core('EE_Request'); |
|
| 46 | 46 | $ip_address = $request->ip_address(); |
| 47 | - $ee_bot_checkout = get_option( InvalidCheckoutAccess::OPTION_KEY ); |
|
| 48 | - if ( $ee_bot_checkout === false ) { |
|
| 47 | + $ee_bot_checkout = get_option(InvalidCheckoutAccess::OPTION_KEY); |
|
| 48 | + if ($ee_bot_checkout === false) { |
|
| 49 | 49 | $ee_bot_checkout = array(); |
| 50 | - add_option( InvalidCheckoutAccess::OPTION_KEY, $ee_bot_checkout, '', false ); |
|
| 50 | + add_option(InvalidCheckoutAccess::OPTION_KEY, $ee_bot_checkout, '', false); |
|
| 51 | 51 | } |
| 52 | - if ( ! isset( $ee_bot_checkout[ $ip_address ] ) ) { |
|
| 53 | - $ee_bot_checkout[ $ip_address ] = array(); |
|
| 52 | + if ( ! isset($ee_bot_checkout[$ip_address])) { |
|
| 53 | + $ee_bot_checkout[$ip_address] = array(); |
|
| 54 | 54 | } |
| 55 | - $http_referer = isset( $_SERVER['HTTP_REFERER'] ) |
|
| 56 | - ? esc_attr( $_SERVER['HTTP_REFERER'] ) |
|
| 55 | + $http_referer = isset($_SERVER['HTTP_REFERER']) |
|
| 56 | + ? esc_attr($_SERVER['HTTP_REFERER']) |
|
| 57 | 57 | : 0; |
| 58 | - if ( ! isset( $ee_bot_checkout[ $ip_address ][ $http_referer ] ) ) { |
|
| 59 | - $ee_bot_checkout[ $ip_address ][ $http_referer ] = 0; |
|
| 58 | + if ( ! isset($ee_bot_checkout[$ip_address][$http_referer])) { |
|
| 59 | + $ee_bot_checkout[$ip_address][$http_referer] = 0; |
|
| 60 | 60 | } |
| 61 | - $ee_bot_checkout[ $ip_address ][ $http_referer ]++; |
|
| 62 | - update_option( InvalidCheckoutAccess::OPTION_KEY, $ee_bot_checkout ); |
|
| 61 | + $ee_bot_checkout[$ip_address][$http_referer]++; |
|
| 62 | + update_option(InvalidCheckoutAccess::OPTION_KEY, $ee_bot_checkout); |
|
| 63 | 63 | if (WP_DEBUG) { |
| 64 | 64 | \EE_Error::add_error( |
| 65 | 65 | esc_html__('Direct access to the registration checkout page is not allowed.', 'event_espresso'), |
@@ -88,13 +88,13 @@ discard block |
||
| 88 | 88 | 'layout_strategy' => new \EE_Admin_Two_Column_Layout(), |
| 89 | 89 | 'subsections' => array( |
| 90 | 90 | 'invalid_checkout_access_hdr' => new \EE_Form_Section_HTML( |
| 91 | - \EEH_HTML::h2( esc_html__( 'Invalid Checkout Access', 'event_espresso' ) ) |
|
| 91 | + \EEH_HTML::h2(esc_html__('Invalid Checkout Access', 'event_espresso')) |
|
| 92 | 92 | ), |
| 93 | 93 | 'ee_bot_checkout_data' => new \EE_Text_Area_Input( |
| 94 | 94 | array( |
| 95 | - 'html_label_text' => esc_html__( 'Invalid Checkout Data', 'event_espresso' ), |
|
| 95 | + 'html_label_text' => esc_html__('Invalid Checkout Data', 'event_espresso'), |
|
| 96 | 96 | 'default' => var_export( |
| 97 | - get_option( InvalidCheckoutAccess::OPTION_KEY, array() ), |
|
| 97 | + get_option(InvalidCheckoutAccess::OPTION_KEY, array()), |
|
| 98 | 98 | true |
| 99 | 99 | ), |
| 100 | 100 | 'required' => false, |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | ), |
| 107 | 107 | 'track_invalid_checkout_access' => new \EE_Yes_No_Input( |
| 108 | 108 | array( |
| 109 | - 'html_label_text' => __( 'Track Invalid Checkout Access?', 'event_espresso' ), |
|
| 109 | + 'html_label_text' => __('Track Invalid Checkout Access?', 'event_espresso'), |
|
| 110 | 110 | 'html_help_text' => esc_html__( |
| 111 | 111 | 'Controls whether or not invalid attempts to directly access the registration checkout page should be tracked. Setting this to "No" means that the above data will no longer be collected.', |
| 112 | 112 | 'event_espresso' |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | ), |
| 120 | 120 | 'delete_invalid_checkout_data' => new \EE_Yes_No_Input( |
| 121 | 121 | array( |
| 122 | - 'html_label_text' => __( 'Reset Invalid Checkout Data', 'event_espresso' ), |
|
| 122 | + 'html_label_text' => __('Reset Invalid Checkout Data', 'event_espresso'), |
|
| 123 | 123 | 'html_help_text' => esc_html__( |
| 124 | 124 | 'Setting this to "Yes" will delete all existing invalid checkout access data.', |
| 125 | 125 | 'event_espresso' |
@@ -141,15 +141,15 @@ discard block |
||
| 141 | 141 | * @param \EE_Registration_Config $EE_Registration_Config |
| 142 | 142 | * @return \EE_Registration_Config |
| 143 | 143 | */ |
| 144 | - public function processForm( \EE_Registration_Config $EE_Registration_Config ) { |
|
| 144 | + public function processForm(\EE_Registration_Config $EE_Registration_Config) { |
|
| 145 | 145 | try { |
| 146 | 146 | $invalid_checkout_access_form = $this->getForm(); |
| 147 | 147 | // if not displaying a form, then check for form submission |
| 148 | - if ( $invalid_checkout_access_form->was_submitted() ) { |
|
| 148 | + if ($invalid_checkout_access_form->was_submitted()) { |
|
| 149 | 149 | // capture form data |
| 150 | 150 | $invalid_checkout_access_form->receive_form_submission(); |
| 151 | 151 | // validate form data |
| 152 | - if ( $invalid_checkout_access_form->is_valid() ) { |
|
| 152 | + if ($invalid_checkout_access_form->is_valid()) { |
|
| 153 | 153 | // grab validated data from form |
| 154 | 154 | $valid_data = $invalid_checkout_access_form->valid_data(); |
| 155 | 155 | // ensure form inputs we want are set |
@@ -163,8 +163,8 @@ discard block |
||
| 163 | 163 | $valid_data['track_invalid_checkout_access'] |
| 164 | 164 | ); |
| 165 | 165 | // if deleting, then update option with empty array |
| 166 | - if ( filter_var( $valid_data['delete_invalid_checkout_data'], FILTER_VALIDATE_BOOLEAN ) ) { |
|
| 167 | - update_option( InvalidCheckoutAccess::OPTION_KEY, array() ); |
|
| 166 | + if (filter_var($valid_data['delete_invalid_checkout_data'], FILTER_VALIDATE_BOOLEAN)) { |
|
| 167 | + update_option(InvalidCheckoutAccess::OPTION_KEY, array()); |
|
| 168 | 168 | } |
| 169 | 169 | } else { |
| 170 | 170 | \EE_Error::add_error( |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | ); |
| 179 | 179 | } |
| 180 | 180 | } else { |
| 181 | - if ( $invalid_checkout_access_form->submission_error_message() !== '' ) { |
|
| 181 | + if ($invalid_checkout_access_form->submission_error_message() !== '') { |
|
| 182 | 182 | \EE_Error::add_error( |
| 183 | 183 | $invalid_checkout_access_form->submission_error_message(), |
| 184 | 184 | __FILE__, |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | } |
| 189 | 189 | } |
| 190 | 190 | } |
| 191 | - } catch ( \EE_Error $e ) { |
|
| 191 | + } catch (\EE_Error $e) { |
|
| 192 | 192 | $e->get_error(); |
| 193 | 193 | } |
| 194 | 194 | return $EE_Registration_Config; |
@@ -370,7 +370,7 @@ |
||
| 370 | 370 | * with construction finalize being called later |
| 371 | 371 | * (realizing that the subsections' html names |
| 372 | 372 | * might not be set yet, etc.) |
| 373 | - * @return EE_Form_Section_Base |
|
| 373 | + * @return EE_Form_Section_Validatable|null |
|
| 374 | 374 | * @throws \EE_Error |
| 375 | 375 | */ |
| 376 | 376 | public function get_subsection($name, $require_construction_to_be_finalized = true) |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | */ |
| 85 | 85 | public function __construct($options_array = array()) |
| 86 | 86 | { |
| 87 | - $options_array = (array)apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array, |
|
| 87 | + $options_array = (array) apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array, |
|
| 88 | 88 | $this); |
| 89 | 89 | //call parent first, as it may be setting the name |
| 90 | 90 | parent::__construct($options_array); |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | if (isset($options_array['layout_strategy'])) { |
| 108 | 108 | $this->_layout_strategy = $options_array['layout_strategy']; |
| 109 | 109 | } |
| 110 | - if (! $this->_layout_strategy) { |
|
| 110 | + if ( ! $this->_layout_strategy) { |
|
| 111 | 111 | $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
| 112 | 112 | } |
| 113 | 113 | $this->_layout_strategy->_construct_finalize($this); |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | if ($validate) { |
| 259 | 259 | $this->_validate(); |
| 260 | 260 | //if it's invalid, we're going to want to re-display so remember what they submitted |
| 261 | - if (! $this->is_valid()) { |
|
| 261 | + if ( ! $this->is_valid()) { |
|
| 262 | 262 | $this->store_submitted_form_data_in_session(); |
| 263 | 263 | } |
| 264 | 264 | } |
@@ -438,7 +438,7 @@ discard block |
||
| 438 | 438 | public function get_input($name, $require_construction_to_be_finalized = true) |
| 439 | 439 | { |
| 440 | 440 | $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
| 441 | - if (! $subsection instanceof EE_Form_Input_Base) { |
|
| 441 | + if ( ! $subsection instanceof EE_Form_Input_Base) { |
|
| 442 | 442 | throw new EE_Error( |
| 443 | 443 | sprintf( |
| 444 | 444 | __( |
@@ -473,7 +473,7 @@ discard block |
||
| 473 | 473 | public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
| 474 | 474 | { |
| 475 | 475 | $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
| 476 | - if (! $subsection instanceof EE_Form_Section_Proper) { |
|
| 476 | + if ( ! $subsection instanceof EE_Form_Section_Proper) { |
|
| 477 | 477 | throw new EE_Error( |
| 478 | 478 | sprintf( |
| 479 | 479 | __("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'), |
@@ -511,7 +511,7 @@ discard block |
||
| 511 | 511 | */ |
| 512 | 512 | public function is_valid() |
| 513 | 513 | { |
| 514 | - if (! $this->has_received_submission()) { |
|
| 514 | + if ( ! $this->has_received_submission()) { |
|
| 515 | 515 | throw new EE_Error( |
| 516 | 516 | sprintf( |
| 517 | 517 | __( |
@@ -521,14 +521,14 @@ discard block |
||
| 521 | 521 | ) |
| 522 | 522 | ); |
| 523 | 523 | } |
| 524 | - if (! parent::is_valid()) { |
|
| 524 | + if ( ! parent::is_valid()) { |
|
| 525 | 525 | return false; |
| 526 | 526 | } |
| 527 | 527 | // ok so no general errors to this entire form section. |
| 528 | 528 | // so let's check the subsections, but only set errors if that hasn't been done yet |
| 529 | 529 | $set_submission_errors = $this->submission_error_message() === '' ? true : false; |
| 530 | 530 | foreach ($this->get_validatable_subsections() as $subsection) { |
| 531 | - if (! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') { |
|
| 531 | + if ( ! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') { |
|
| 532 | 532 | if ($set_submission_errors) { |
| 533 | 533 | $this->set_submission_error_message($subsection->get_validation_error_string()); |
| 534 | 534 | } |
@@ -547,7 +547,7 @@ discard block |
||
| 547 | 547 | */ |
| 548 | 548 | protected function _set_default_name_if_empty() |
| 549 | 549 | { |
| 550 | - if (! $this->_name) { |
|
| 550 | + if ( ! $this->_name) { |
|
| 551 | 551 | $classname = get_class($this); |
| 552 | 552 | $default_name = str_replace("EE_", "", $classname); |
| 553 | 553 | $this->_name = $default_name; |
@@ -632,7 +632,7 @@ discard block |
||
| 632 | 632 | { |
| 633 | 633 | wp_register_script( |
| 634 | 634 | 'ee_form_section_validation', |
| 635 | - EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
| 635 | + EE_GLOBAL_ASSETS_URL.'scripts'.DS.'form_section_validation.js', |
|
| 636 | 636 | array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
| 637 | 637 | EVENT_ESPRESSO_VERSION, |
| 638 | 638 | true |
@@ -778,7 +778,7 @@ discard block |
||
| 778 | 778 | */ |
| 779 | 779 | public function ensure_scripts_localized() |
| 780 | 780 | { |
| 781 | - if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
| 781 | + if ( ! EE_Form_Section_Proper::$_scripts_localized) { |
|
| 782 | 782 | $this->_enqueue_and_localize_form_js(); |
| 783 | 783 | } |
| 784 | 784 | } |
@@ -874,8 +874,8 @@ discard block |
||
| 874 | 874 | protected function _validate() |
| 875 | 875 | { |
| 876 | 876 | foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
| 877 | - if (method_exists($this, '_validate_' . $subsection_name)) { |
|
| 878 | - call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
| 877 | + if (method_exists($this, '_validate_'.$subsection_name)) { |
|
| 878 | + call_user_func_array(array($this, '_validate_'.$subsection_name), array($subsection)); |
|
| 879 | 879 | } |
| 880 | 880 | $subsection->_validate(); |
| 881 | 881 | } |
@@ -1151,7 +1151,7 @@ discard block |
||
| 1151 | 1151 | public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
| 1152 | 1152 | { |
| 1153 | 1153 | foreach ($new_subsections as $subsection_name => $subsection) { |
| 1154 | - if (! $subsection instanceof EE_Form_Section_Base) { |
|
| 1154 | + if ( ! $subsection instanceof EE_Form_Section_Base) { |
|
| 1155 | 1155 | EE_Error::add_error( |
| 1156 | 1156 | sprintf( |
| 1157 | 1157 | __( |
@@ -1249,7 +1249,7 @@ discard block |
||
| 1249 | 1249 | public function html_name_prefix() |
| 1250 | 1250 | { |
| 1251 | 1251 | if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
| 1252 | - return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
| 1252 | + return $this->parent_section()->html_name_prefix().'['.$this->name().']'; |
|
| 1253 | 1253 | } else { |
| 1254 | 1254 | return $this->name(); |
| 1255 | 1255 | } |
@@ -1293,7 +1293,7 @@ discard block |
||
| 1293 | 1293 | */ |
| 1294 | 1294 | public function ensure_construct_finalized_called() |
| 1295 | 1295 | { |
| 1296 | - if (! $this->_construction_finalized) { |
|
| 1296 | + if ( ! $this->_construction_finalized) { |
|
| 1297 | 1297 | $this->_construct_finalize($this->_parent_section, $this->_name); |
| 1298 | 1298 | } |
| 1299 | 1299 | } |
@@ -11,1385 +11,1385 @@ |
||
| 11 | 11 | class EE_Form_Section_Proper extends EE_Form_Section_Validatable |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
|
| 15 | - |
|
| 16 | - /** |
|
| 17 | - * Subsections |
|
| 18 | - * |
|
| 19 | - * @var EE_Form_Section_Validatable[] |
|
| 20 | - */ |
|
| 21 | - protected $_subsections = array(); |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * Strategy for laying out the form |
|
| 25 | - * |
|
| 26 | - * @var EE_Form_Section_Layout_Base |
|
| 27 | - */ |
|
| 28 | - protected $_layout_strategy; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Whether or not this form has received and validated a form submission yet |
|
| 32 | - * |
|
| 33 | - * @var boolean |
|
| 34 | - */ |
|
| 35 | - protected $_received_submission = false; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * message displayed to users upon successful form submission |
|
| 39 | - * |
|
| 40 | - * @var string |
|
| 41 | - */ |
|
| 42 | - protected $_form_submission_success_message = ''; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * message displayed to users upon unsuccessful form submission |
|
| 46 | - * |
|
| 47 | - * @var string |
|
| 48 | - */ |
|
| 49 | - protected $_form_submission_error_message = ''; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Stores all the data that will localized for form validation |
|
| 53 | - * |
|
| 54 | - * @var array |
|
| 55 | - */ |
|
| 56 | - static protected $_js_localization = array(); |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * whether or not the form's localized validation JS vars have been set |
|
| 60 | - * |
|
| 61 | - * @type boolean |
|
| 62 | - */ |
|
| 63 | - static protected $_scripts_localized = false; |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * when constructing a proper form section, calls _construct_finalize on children |
|
| 69 | - * so that they know who their parent is, and what name they've been given. |
|
| 70 | - * |
|
| 71 | - * @param array $options_array { |
|
| 72 | - * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name |
|
| 73 | - * @type $include string[] numerically-indexed where values are section names to be included, |
|
| 74 | - * and in that order. This is handy if you want |
|
| 75 | - * the subsections to be ordered differently than the default, and if you override |
|
| 76 | - * which fields are shown |
|
| 77 | - * @type $exclude string[] values are subsections to be excluded. This is handy if you want |
|
| 78 | - * to remove certain default subsections (note: if you specify BOTH 'include' AND |
|
| 79 | - * 'exclude', the inclusions will be applied first, and the exclusions will exclude |
|
| 80 | - * items from that list of inclusions) |
|
| 81 | - * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form |
|
| 82 | - * } @see EE_Form_Section_Validatable::__construct() |
|
| 83 | - * @throws \EE_Error |
|
| 84 | - */ |
|
| 85 | - public function __construct($options_array = array()) |
|
| 86 | - { |
|
| 87 | - $options_array = (array)apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array, |
|
| 88 | - $this); |
|
| 89 | - //call parent first, as it may be setting the name |
|
| 90 | - parent::__construct($options_array); |
|
| 91 | - //if they've included subsections in the constructor, add them now |
|
| 92 | - if (isset($options_array['include'])) { |
|
| 93 | - //we are going to make sure we ONLY have those subsections to include |
|
| 94 | - //AND we are going to make sure they're in that specified order |
|
| 95 | - $reordered_subsections = array(); |
|
| 96 | - foreach ($options_array['include'] as $input_name) { |
|
| 97 | - if (isset($this->_subsections[$input_name])) { |
|
| 98 | - $reordered_subsections[$input_name] = $this->_subsections[$input_name]; |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - $this->_subsections = $reordered_subsections; |
|
| 102 | - } |
|
| 103 | - if (isset($options_array['exclude'])) { |
|
| 104 | - $exclude = $options_array['exclude']; |
|
| 105 | - $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
|
| 106 | - } |
|
| 107 | - if (isset($options_array['layout_strategy'])) { |
|
| 108 | - $this->_layout_strategy = $options_array['layout_strategy']; |
|
| 109 | - } |
|
| 110 | - if (! $this->_layout_strategy) { |
|
| 111 | - $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
|
| 112 | - } |
|
| 113 | - $this->_layout_strategy->_construct_finalize($this); |
|
| 114 | - //ok so we are definitely going to want the forms JS, |
|
| 115 | - //so enqueue it or remember to enqueue it during wp_enqueue_scripts |
|
| 116 | - if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) { |
|
| 117 | - //ok so they've constructed this object after when they should have. |
|
| 118 | - //just enqueue the generic form scripts and initialize the form immediately in the JS |
|
| 119 | - \EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
| 120 | - } else { |
|
| 121 | - add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 122 | - add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 123 | - } |
|
| 124 | - add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Gives other plugins a chance to hook in before construct finalize is called. The form probably doesn't |
|
| 128 | - * yet have a parent form section. Since 4.9.32, when this action was introduced, this is the best place to |
|
| 129 | - * add a subsection onto a form, assuming you don't care what the form section's name, HTML ID, or HTML name etc are. |
|
| 130 | - * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end |
|
| 131 | - * @since 4.9.32 |
|
| 132 | - * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, except maybe calling |
|
| 133 | - * _construct_finalize has been done |
|
| 134 | - * @param array $options_array options passed into the constructor |
|
| 135 | - */ |
|
| 136 | - do_action('AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', $this, $options_array); |
|
| 137 | - |
|
| 138 | - if (isset($options_array['name'])) { |
|
| 139 | - $this->_construct_finalize(null, $options_array['name']); |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Finishes construction given the parent form section and this form section's name |
|
| 147 | - * |
|
| 148 | - * @param EE_Form_Section_Proper $parent_form_section |
|
| 149 | - * @param string $name |
|
| 150 | - * @throws \EE_Error |
|
| 151 | - */ |
|
| 152 | - public function _construct_finalize($parent_form_section, $name) |
|
| 153 | - { |
|
| 154 | - parent::_construct_finalize($parent_form_section, $name); |
|
| 155 | - $this->_set_default_name_if_empty(); |
|
| 156 | - $this->_set_default_html_id_if_empty(); |
|
| 157 | - foreach ($this->_subsections as $subsection_name => $subsection) { |
|
| 158 | - if ($subsection instanceof EE_Form_Section_Base) { |
|
| 159 | - $subsection->_construct_finalize($this, $subsection_name); |
|
| 160 | - } else { |
|
| 161 | - throw new EE_Error( |
|
| 162 | - sprintf( |
|
| 163 | - __('Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', |
|
| 164 | - 'event_espresso'), |
|
| 165 | - $subsection_name, |
|
| 166 | - get_class($this), |
|
| 167 | - $subsection ? get_class($subsection) : __('NULL', 'event_espresso') |
|
| 168 | - ) |
|
| 169 | - ); |
|
| 170 | - } |
|
| 171 | - } |
|
| 172 | - /** |
|
| 173 | - * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed. |
|
| 174 | - * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID (or other attributes derived |
|
| 175 | - * from the name like the HTML label id, etc), this is where it should be done. |
|
| 176 | - * This might only happen just before displaying the form, or just before it receives form submission data. |
|
| 177 | - * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've |
|
| 178 | - * ensured it has a name, HTML IDs, etc |
|
| 179 | - * @param EE_Form_Section_Proper $this |
|
| 180 | - * @param EE_Form_Section_Proper|null $parent_form_section |
|
| 181 | - * @param string $name |
|
| 182 | - */ |
|
| 183 | - do_action('AHEE__EE_Form_Section_Proper___construct_finalize__end', $this, $parent_form_section, $name); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * Gets the layout strategy for this form section |
|
| 190 | - * |
|
| 191 | - * @return EE_Form_Section_Layout_Base |
|
| 192 | - */ |
|
| 193 | - public function get_layout_strategy() |
|
| 194 | - { |
|
| 195 | - return $this->_layout_strategy; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * Gets the HTML for a single input for this form section according |
|
| 202 | - * to the layout strategy |
|
| 203 | - * |
|
| 204 | - * @param EE_Form_Input_Base $input |
|
| 205 | - * @return string |
|
| 206 | - */ |
|
| 207 | - public function get_html_for_input($input) |
|
| 208 | - { |
|
| 209 | - return $this->_layout_strategy->layout_input($input); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * was_submitted - checks if form inputs are present in request data |
|
| 216 | - * Basically an alias for form_data_present_in() (which is used by both |
|
| 217 | - * proper form sections and form inputs) |
|
| 218 | - * |
|
| 219 | - * @param null $form_data |
|
| 220 | - * @return boolean |
|
| 221 | - */ |
|
| 222 | - public function was_submitted($form_data = null) |
|
| 223 | - { |
|
| 224 | - return $this->form_data_present_in($form_data); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * After the form section is initially created, call this to sanitize the data in the submission |
|
| 231 | - * which relates to this form section, validate it, and set it as properties on the form. |
|
| 232 | - * |
|
| 233 | - * @param array|null $req_data should usually be $_POST (the default). |
|
| 234 | - * However, you CAN supply a different array. |
|
| 235 | - * Consider using set_defaults() instead however. |
|
| 236 | - * (If you rendered the form in the page using echo $form_x->get_html() |
|
| 237 | - * the inputs will have the correct name in the request data for this function |
|
| 238 | - * to find them and populate the form with them. |
|
| 239 | - * If you have a flat form (with only input subsections), |
|
| 240 | - * you can supply a flat array where keys |
|
| 241 | - * are the form input names and values are their values) |
|
| 242 | - * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
| 243 | - * of course, to validate that data, and set errors on the invalid values. |
|
| 244 | - * But if the data has already been validated |
|
| 245 | - * (eg you validated the data then stored it in the DB) |
|
| 246 | - * you may want to skip this step. |
|
| 247 | - */ |
|
| 248 | - public function receive_form_submission($req_data = null, $validate = true) |
|
| 249 | - { |
|
| 250 | - $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', $req_data, $this, |
|
| 251 | - $validate); |
|
| 252 | - if ($req_data === null) { |
|
| 253 | - $req_data = array_merge($_GET, $_POST); |
|
| 254 | - } |
|
| 255 | - $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', $req_data, |
|
| 256 | - $this); |
|
| 257 | - $this->_normalize($req_data); |
|
| 258 | - if ($validate) { |
|
| 259 | - $this->_validate(); |
|
| 260 | - //if it's invalid, we're going to want to re-display so remember what they submitted |
|
| 261 | - if (! $this->is_valid()) { |
|
| 262 | - $this->store_submitted_form_data_in_session(); |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - do_action('AHEE__EE_Form_Section_Proper__receive_form_submission__end', $req_data, $this, $validate); |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * caches the originally submitted input values in the session |
|
| 272 | - * so that they can be used to repopulate the form if it failed validation |
|
| 273 | - * |
|
| 274 | - * @return boolean whether or not the data was successfully stored in the session |
|
| 275 | - */ |
|
| 276 | - protected function store_submitted_form_data_in_session() |
|
| 277 | - { |
|
| 278 | - return EE_Registry::instance()->SSN->set_session_data( |
|
| 279 | - array( |
|
| 280 | - \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
| 281 | - ) |
|
| 282 | - ); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * retrieves the originally submitted input values in the session |
|
| 289 | - * so that they can be used to repopulate the form if it failed validation |
|
| 290 | - * |
|
| 291 | - * @return array |
|
| 292 | - */ |
|
| 293 | - protected function get_submitted_form_data_from_session() |
|
| 294 | - { |
|
| 295 | - $session = EE_Registry::instance()->SSN; |
|
| 296 | - if ($session instanceof EE_Session) { |
|
| 297 | - return $session->get_session_data( |
|
| 298 | - \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
| 299 | - ); |
|
| 300 | - } else { |
|
| 301 | - return array(); |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * flushed the originally submitted input values from the session |
|
| 309 | - * |
|
| 310 | - * @return boolean whether or not the data was successfully removed from the session |
|
| 311 | - */ |
|
| 312 | - protected function flush_submitted_form_data_from_session() |
|
| 313 | - { |
|
| 314 | - return EE_Registry::instance()->SSN->reset_data( |
|
| 315 | - array(\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
| 316 | - ); |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * Populates this form and its subsections with data from the session. |
|
| 323 | - * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
| 324 | - * validation errors when displaying too) |
|
| 325 | - * Returns true if the form was populated from the session, false otherwise |
|
| 326 | - * |
|
| 327 | - * @return boolean |
|
| 328 | - */ |
|
| 329 | - public function populate_from_session() |
|
| 330 | - { |
|
| 331 | - $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
| 332 | - if (empty($form_data_in_session)) { |
|
| 333 | - return false; |
|
| 334 | - } |
|
| 335 | - $this->receive_form_submission($form_data_in_session); |
|
| 336 | - $this->flush_submitted_form_data_from_session(); |
|
| 337 | - if ($this->form_data_present_in($form_data_in_session)) { |
|
| 338 | - return true; |
|
| 339 | - } else { |
|
| 340 | - return false; |
|
| 341 | - } |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * Populates the default data for the form, given an array where keys are |
|
| 348 | - * the input names, and values are their values (preferably normalized to be their |
|
| 349 | - * proper PHP types, not all strings... although that should be ok too). |
|
| 350 | - * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
| 351 | - * the value being an array formatted in teh same way |
|
| 352 | - * |
|
| 353 | - * @param array $default_data |
|
| 354 | - */ |
|
| 355 | - public function populate_defaults($default_data) |
|
| 356 | - { |
|
| 357 | - foreach ($this->subsections(false) as $subsection_name => $subsection) { |
|
| 358 | - if (isset($default_data[$subsection_name])) { |
|
| 359 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 360 | - $subsection->set_default($default_data[$subsection_name]); |
|
| 361 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 362 | - $subsection->populate_defaults($default_data[$subsection_name]); |
|
| 363 | - } |
|
| 364 | - } |
|
| 365 | - } |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - |
|
| 369 | - |
|
| 370 | - /** |
|
| 371 | - * returns true if subsection exists |
|
| 372 | - * |
|
| 373 | - * @param string $name |
|
| 374 | - * @return boolean |
|
| 375 | - */ |
|
| 376 | - public function subsection_exists($name) |
|
| 377 | - { |
|
| 378 | - return isset($this->_subsections[$name]) ? true : false; |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * Gets the subsection specified by its name |
|
| 385 | - * |
|
| 386 | - * @param string $name |
|
| 387 | - * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
| 388 | - * so that the inputs will be properly configured. |
|
| 389 | - * However, some client code may be ok |
|
| 390 | - * with construction finalize being called later |
|
| 391 | - * (realizing that the subsections' html names |
|
| 392 | - * might not be set yet, etc.) |
|
| 393 | - * @return EE_Form_Section_Base |
|
| 394 | - * @throws \EE_Error |
|
| 395 | - */ |
|
| 396 | - public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
| 397 | - { |
|
| 398 | - if ($require_construction_to_be_finalized) { |
|
| 399 | - $this->ensure_construct_finalized_called(); |
|
| 400 | - } |
|
| 401 | - return $this->subsection_exists($name) ? $this->_subsections[$name] : null; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * Gets all the validatable subsections of this form section |
|
| 408 | - * |
|
| 409 | - * @return EE_Form_Section_Validatable[] |
|
| 410 | - */ |
|
| 411 | - public function get_validatable_subsections() |
|
| 412 | - { |
|
| 413 | - $validatable_subsections = array(); |
|
| 414 | - foreach ($this->subsections() as $name => $obj) { |
|
| 415 | - if ($obj instanceof EE_Form_Section_Validatable) { |
|
| 416 | - $validatable_subsections[$name] = $obj; |
|
| 417 | - } |
|
| 418 | - } |
|
| 419 | - return $validatable_subsections; |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
| 426 | - * throw an EE_Error. |
|
| 427 | - * |
|
| 428 | - * @param string $name |
|
| 429 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
| 430 | - * leave this as TRUE so that the inputs will be properly |
|
| 431 | - * configured. However, some client code may be ok with |
|
| 432 | - * construction finalize being called later |
|
| 433 | - * (realizing that the subsections' html names might not be |
|
| 434 | - * set yet, etc.) |
|
| 435 | - * @return EE_Form_Input_Base |
|
| 436 | - * @throws EE_Error |
|
| 437 | - */ |
|
| 438 | - public function get_input($name, $require_construction_to_be_finalized = true) |
|
| 439 | - { |
|
| 440 | - $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
|
| 441 | - if (! $subsection instanceof EE_Form_Input_Base) { |
|
| 442 | - throw new EE_Error( |
|
| 443 | - sprintf( |
|
| 444 | - __( |
|
| 445 | - "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
| 446 | - 'event_espresso' |
|
| 447 | - ), |
|
| 448 | - $name, |
|
| 449 | - get_class($this), |
|
| 450 | - $subsection ? get_class($subsection) : __("NULL", 'event_espresso') |
|
| 451 | - ) |
|
| 452 | - ); |
|
| 453 | - } |
|
| 454 | - return $subsection; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - |
|
| 458 | - |
|
| 459 | - /** |
|
| 460 | - * Like get_input(), gets the proper subsection of the form given the name, |
|
| 461 | - * otherwise throws an EE_Error |
|
| 462 | - * |
|
| 463 | - * @param string $name |
|
| 464 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
| 465 | - * leave this as TRUE so that the inputs will be properly |
|
| 466 | - * configured. However, some client code may be ok with |
|
| 467 | - * construction finalize being called later |
|
| 468 | - * (realizing that the subsections' html names might not be |
|
| 469 | - * set yet, etc.) |
|
| 470 | - * @return EE_Form_Section_Proper |
|
| 471 | - * @throws EE_Error |
|
| 472 | - */ |
|
| 473 | - public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
| 474 | - { |
|
| 475 | - $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
|
| 476 | - if (! $subsection instanceof EE_Form_Section_Proper) { |
|
| 477 | - throw new EE_Error( |
|
| 478 | - sprintf( |
|
| 479 | - __("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'), |
|
| 480 | - $name, |
|
| 481 | - get_class($this) |
|
| 482 | - ) |
|
| 483 | - ); |
|
| 484 | - } |
|
| 485 | - return $subsection; |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - |
|
| 489 | - |
|
| 490 | - /** |
|
| 491 | - * Gets the value of the specified input. Should be called after receive_form_submission() |
|
| 492 | - * or populate_defaults() on the form, where the normalized value on the input is set. |
|
| 493 | - * |
|
| 494 | - * @param string $name |
|
| 495 | - * @return mixed depending on the input's type and its normalization strategy |
|
| 496 | - * @throws \EE_Error |
|
| 497 | - */ |
|
| 498 | - public function get_input_value($name) |
|
| 499 | - { |
|
| 500 | - $input = $this->get_input($name); |
|
| 501 | - return $input->normalized_value(); |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - |
|
| 505 | - |
|
| 506 | - /** |
|
| 507 | - * Checks if this form section itself is valid, and then checks its subsections |
|
| 508 | - * |
|
| 509 | - * @throws EE_Error |
|
| 510 | - * @return boolean |
|
| 511 | - */ |
|
| 512 | - public function is_valid() |
|
| 513 | - { |
|
| 514 | - if (! $this->has_received_submission()) { |
|
| 515 | - throw new EE_Error( |
|
| 516 | - sprintf( |
|
| 517 | - __( |
|
| 518 | - "You cannot check if a form is valid before receiving the form submission using receive_form_submission", |
|
| 519 | - "event_espresso" |
|
| 520 | - ) |
|
| 521 | - ) |
|
| 522 | - ); |
|
| 523 | - } |
|
| 524 | - if (! parent::is_valid()) { |
|
| 525 | - return false; |
|
| 526 | - } |
|
| 527 | - // ok so no general errors to this entire form section. |
|
| 528 | - // so let's check the subsections, but only set errors if that hasn't been done yet |
|
| 529 | - $set_submission_errors = $this->submission_error_message() === '' ? true : false; |
|
| 530 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 531 | - if (! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') { |
|
| 532 | - if ($set_submission_errors) { |
|
| 533 | - $this->set_submission_error_message($subsection->get_validation_error_string()); |
|
| 534 | - } |
|
| 535 | - return false; |
|
| 536 | - } |
|
| 537 | - } |
|
| 538 | - return true; |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - |
|
| 542 | - |
|
| 543 | - /** |
|
| 544 | - * gets teh default name of this form section if none is specified |
|
| 545 | - * |
|
| 546 | - * @return string |
|
| 547 | - */ |
|
| 548 | - protected function _set_default_name_if_empty() |
|
| 549 | - { |
|
| 550 | - if (! $this->_name) { |
|
| 551 | - $classname = get_class($this); |
|
| 552 | - $default_name = str_replace("EE_", "", $classname); |
|
| 553 | - $this->_name = $default_name; |
|
| 554 | - } |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - |
|
| 558 | - |
|
| 559 | - /** |
|
| 560 | - * Returns the HTML for the form, except for the form opening and closing tags |
|
| 561 | - * (as the form section doesn't know where you necessarily want to send the information to), |
|
| 562 | - * and except for a submit button. Enqueus JS and CSS; if called early enough we will |
|
| 563 | - * try to enqueue them in the header, otherwise they'll be enqueued in the footer. |
|
| 564 | - * Not doing_it_wrong because theoretically this CAN be used properly, |
|
| 565 | - * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue |
|
| 566 | - * any CSS. |
|
| 567 | - * |
|
| 568 | - * @throws \EE_Error |
|
| 569 | - */ |
|
| 570 | - public function get_html_and_js() |
|
| 571 | - { |
|
| 572 | - $this->enqueue_js(); |
|
| 573 | - return $this->get_html(); |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - |
|
| 577 | - |
|
| 578 | - /** |
|
| 579 | - * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
| 580 | - * |
|
| 581 | - * @param bool $display_previously_submitted_data |
|
| 582 | - * @return string |
|
| 583 | - */ |
|
| 584 | - public function get_html($display_previously_submitted_data = true) |
|
| 585 | - { |
|
| 586 | - $this->ensure_construct_finalized_called(); |
|
| 587 | - if ($display_previously_submitted_data) { |
|
| 588 | - $this->populate_from_session(); |
|
| 589 | - } |
|
| 590 | - return $this->_form_html_filter |
|
| 591 | - ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this) |
|
| 592 | - : $this->_layout_strategy->layout_form(); |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - |
|
| 596 | - |
|
| 597 | - /** |
|
| 598 | - * enqueues JS and CSS for the form. |
|
| 599 | - * It is preferred to call this before wp_enqueue_scripts so the |
|
| 600 | - * scripts and styles can be put in the header, but if called later |
|
| 601 | - * they will be put in the footer (which is OK for JS, but in HTML4 CSS should |
|
| 602 | - * only be in the header; but in HTML5 its ok in the body. |
|
| 603 | - * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag. |
|
| 604 | - * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.) |
|
| 605 | - * |
|
| 606 | - * @return string |
|
| 607 | - * @throws \EE_Error |
|
| 608 | - */ |
|
| 609 | - public function enqueue_js() |
|
| 610 | - { |
|
| 611 | - $this->_enqueue_and_localize_form_js(); |
|
| 612 | - foreach ($this->subsections() as $subsection) { |
|
| 613 | - $subsection->enqueue_js(); |
|
| 614 | - } |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - |
|
| 618 | - |
|
| 619 | - /** |
|
| 620 | - * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
| 621 | - * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
| 622 | - * the wp_enqueue_scripts hook. |
|
| 623 | - * However, registering the form js and localizing it can happen when we |
|
| 624 | - * actually output the form (which is preferred, seeing how teh form's fields |
|
| 625 | - * could change until it's actually outputted) |
|
| 626 | - * |
|
| 627 | - * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
| 628 | - * to be triggered automatically or not |
|
| 629 | - * @return void |
|
| 630 | - */ |
|
| 631 | - public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
| 632 | - { |
|
| 633 | - wp_register_script( |
|
| 634 | - 'ee_form_section_validation', |
|
| 635 | - EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
| 636 | - array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
| 637 | - EVENT_ESPRESSO_VERSION, |
|
| 638 | - true |
|
| 639 | - ); |
|
| 640 | - wp_localize_script( |
|
| 641 | - 'ee_form_section_validation', |
|
| 642 | - 'ee_form_section_validation_init', |
|
| 643 | - array('init' => $init_form_validation_automatically ? '1' : '0') |
|
| 644 | - ); |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - |
|
| 648 | - |
|
| 649 | - /** |
|
| 650 | - * gets the variables used by form_section_validation.js. |
|
| 651 | - * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
| 652 | - * but before the wordpress hook wp_loaded |
|
| 653 | - * |
|
| 654 | - * @throws \EE_Error |
|
| 655 | - */ |
|
| 656 | - public function _enqueue_and_localize_form_js() |
|
| 657 | - { |
|
| 658 | - $this->ensure_construct_finalized_called(); |
|
| 659 | - //actually, we don't want to localize just yet. There may be other forms on the page. |
|
| 660 | - //so we need to add our form section data to a static variable accessible by all form sections |
|
| 661 | - //and localize it just before the footer |
|
| 662 | - $this->localize_validation_rules(); |
|
| 663 | - add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
| 664 | - add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
| 665 | - } |
|
| 666 | - |
|
| 667 | - |
|
| 668 | - |
|
| 669 | - /** |
|
| 670 | - * add our form section data to a static variable accessible by all form sections |
|
| 671 | - * |
|
| 672 | - * @param bool $return_for_subsection |
|
| 673 | - * @return void |
|
| 674 | - * @throws \EE_Error |
|
| 675 | - */ |
|
| 676 | - public function localize_validation_rules($return_for_subsection = false) |
|
| 677 | - { |
|
| 678 | - // we only want to localize vars ONCE for the entire form, |
|
| 679 | - // so if the form section doesn't have a parent, then it must be the top dog |
|
| 680 | - if ($return_for_subsection || ! $this->parent_section()) { |
|
| 681 | - EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array( |
|
| 682 | - 'form_section_id' => $this->html_id(true), |
|
| 683 | - 'validation_rules' => $this->get_jquery_validation_rules(), |
|
| 684 | - 'other_data' => $this->get_other_js_data(), |
|
| 685 | - 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
| 686 | - ); |
|
| 687 | - EE_Form_Section_Proper::$_scripts_localized = true; |
|
| 688 | - } |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - |
|
| 692 | - |
|
| 693 | - /** |
|
| 694 | - * Gets an array of extra data that will be useful for client-side javascript. |
|
| 695 | - * This is primarily data added by inputs and forms in addition to any |
|
| 696 | - * scripts they might enqueue |
|
| 697 | - * |
|
| 698 | - * @param array $form_other_js_data |
|
| 699 | - * @return array |
|
| 700 | - */ |
|
| 701 | - public function get_other_js_data($form_other_js_data = array()) |
|
| 702 | - { |
|
| 703 | - foreach ($this->subsections() as $subsection) { |
|
| 704 | - $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
| 705 | - } |
|
| 706 | - return $form_other_js_data; |
|
| 707 | - } |
|
| 708 | - |
|
| 709 | - |
|
| 710 | - |
|
| 711 | - /** |
|
| 712 | - * Gets a flat array of inputs for this form section and its subsections. |
|
| 713 | - * Keys are their form names, and values are the inputs themselves |
|
| 714 | - * |
|
| 715 | - * @return EE_Form_Input_Base |
|
| 716 | - */ |
|
| 717 | - public function inputs_in_subsections() |
|
| 718 | - { |
|
| 719 | - $inputs = array(); |
|
| 720 | - foreach ($this->subsections() as $subsection) { |
|
| 721 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 722 | - $inputs[$subsection->html_name()] = $subsection; |
|
| 723 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 724 | - $inputs += $subsection->inputs_in_subsections(); |
|
| 725 | - } |
|
| 726 | - } |
|
| 727 | - return $inputs; |
|
| 728 | - } |
|
| 729 | - |
|
| 730 | - |
|
| 731 | - |
|
| 732 | - /** |
|
| 733 | - * Gets a flat array of all the validation errors. |
|
| 734 | - * Keys are html names (because those should be unique) |
|
| 735 | - * and values are a string of all their validation errors |
|
| 736 | - * |
|
| 737 | - * @return string[] |
|
| 738 | - */ |
|
| 739 | - public function subsection_validation_errors_by_html_name() |
|
| 740 | - { |
|
| 741 | - $inputs = $this->inputs(); |
|
| 742 | - $errors = array(); |
|
| 743 | - foreach ($inputs as $form_input) { |
|
| 744 | - if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
| 745 | - $errors[$form_input->html_name()] = $form_input->get_validation_error_string(); |
|
| 746 | - } |
|
| 747 | - } |
|
| 748 | - return $errors; |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - |
|
| 752 | - |
|
| 753 | - /** |
|
| 754 | - * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
| 755 | - * Should be setup by each form during the _enqueues_and_localize_form_js |
|
| 756 | - */ |
|
| 757 | - public static function localize_script_for_all_forms() |
|
| 758 | - { |
|
| 759 | - //allow inputs and stuff to hook in their JS and stuff here |
|
| 760 | - do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
| 761 | - EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
| 762 | - $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
| 763 | - ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
| 764 | - : 'wp_default'; |
|
| 765 | - EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
| 766 | - wp_enqueue_script('ee_form_section_validation'); |
|
| 767 | - wp_localize_script( |
|
| 768 | - 'ee_form_section_validation', |
|
| 769 | - 'ee_form_section_vars', |
|
| 770 | - EE_Form_Section_Proper::$_js_localization |
|
| 771 | - ); |
|
| 772 | - } |
|
| 773 | - |
|
| 774 | - |
|
| 775 | - |
|
| 776 | - /** |
|
| 777 | - * ensure_scripts_localized |
|
| 778 | - */ |
|
| 779 | - public function ensure_scripts_localized() |
|
| 780 | - { |
|
| 781 | - if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
| 782 | - $this->_enqueue_and_localize_form_js(); |
|
| 783 | - } |
|
| 784 | - } |
|
| 785 | - |
|
| 786 | - |
|
| 787 | - |
|
| 788 | - /** |
|
| 789 | - * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
| 790 | - * is that the key here should be the same as the custom validation rule put in the JS file |
|
| 791 | - * |
|
| 792 | - * @return array keys are custom validation rules, and values are internationalized strings |
|
| 793 | - */ |
|
| 794 | - private static function _get_localized_error_messages() |
|
| 795 | - { |
|
| 796 | - return array( |
|
| 797 | - 'validUrl' => __("This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg", "event_espresso"), |
|
| 798 | - 'regex' => __('Please check your input', 'event_espresso'), |
|
| 799 | - ); |
|
| 800 | - } |
|
| 801 | - |
|
| 802 | - |
|
| 803 | - |
|
| 804 | - /** |
|
| 805 | - * @return array |
|
| 806 | - */ |
|
| 807 | - public static function js_localization() |
|
| 808 | - { |
|
| 809 | - return self::$_js_localization; |
|
| 810 | - } |
|
| 811 | - |
|
| 812 | - |
|
| 813 | - |
|
| 814 | - /** |
|
| 815 | - * @return array |
|
| 816 | - */ |
|
| 817 | - public static function reset_js_localization() |
|
| 818 | - { |
|
| 819 | - self::$_js_localization = array(); |
|
| 820 | - } |
|
| 821 | - |
|
| 822 | - |
|
| 823 | - |
|
| 824 | - /** |
|
| 825 | - * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
| 826 | - * See parent function for more... |
|
| 827 | - * |
|
| 828 | - * @return array |
|
| 829 | - */ |
|
| 830 | - public function get_jquery_validation_rules() |
|
| 831 | - { |
|
| 832 | - $jquery_validation_rules = array(); |
|
| 833 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 834 | - $jquery_validation_rules = array_merge( |
|
| 835 | - $jquery_validation_rules, |
|
| 836 | - $subsection->get_jquery_validation_rules() |
|
| 837 | - ); |
|
| 838 | - } |
|
| 839 | - return $jquery_validation_rules; |
|
| 840 | - } |
|
| 841 | - |
|
| 842 | - |
|
| 843 | - |
|
| 844 | - /** |
|
| 845 | - * Sanitizes all the data and sets the sanitized value of each field |
|
| 846 | - * |
|
| 847 | - * @param array $req_data like $_POST |
|
| 848 | - * @return void |
|
| 849 | - */ |
|
| 850 | - protected function _normalize($req_data) |
|
| 851 | - { |
|
| 852 | - $this->_received_submission = true; |
|
| 853 | - $this->_validation_errors = array(); |
|
| 854 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 855 | - try { |
|
| 856 | - $subsection->_normalize($req_data); |
|
| 857 | - } catch (EE_Validation_Error $e) { |
|
| 858 | - $subsection->add_validation_error($e); |
|
| 859 | - } |
|
| 860 | - } |
|
| 861 | - } |
|
| 862 | - |
|
| 863 | - |
|
| 864 | - |
|
| 865 | - /** |
|
| 866 | - * Performs validation on this form section and its subsections. |
|
| 867 | - * For each subsection, |
|
| 868 | - * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
| 869 | - * and passes it the subsection, then calls _validate on that subsection. |
|
| 870 | - * If you need to perform validation on the form as a whole (considering multiple) |
|
| 871 | - * you would be best to override this _validate method, |
|
| 872 | - * calling parent::_validate() first. |
|
| 873 | - */ |
|
| 874 | - protected function _validate() |
|
| 875 | - { |
|
| 876 | - foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
| 877 | - if (method_exists($this, '_validate_' . $subsection_name)) { |
|
| 878 | - call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
| 879 | - } |
|
| 880 | - $subsection->_validate(); |
|
| 881 | - } |
|
| 882 | - } |
|
| 883 | - |
|
| 884 | - |
|
| 885 | - |
|
| 886 | - /** |
|
| 887 | - * Gets all the validated inputs for the form section |
|
| 888 | - * |
|
| 889 | - * @return array |
|
| 890 | - */ |
|
| 891 | - public function valid_data() |
|
| 892 | - { |
|
| 893 | - $inputs = array(); |
|
| 894 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 895 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 896 | - $inputs[$subsection_name] = $subsection->valid_data(); |
|
| 897 | - } else if ($subsection instanceof EE_Form_Input_Base) { |
|
| 898 | - $inputs[$subsection_name] = $subsection->normalized_value(); |
|
| 899 | - } |
|
| 900 | - } |
|
| 901 | - return $inputs; |
|
| 902 | - } |
|
| 903 | - |
|
| 904 | - |
|
| 905 | - |
|
| 906 | - /** |
|
| 907 | - * Gets all the inputs on this form section |
|
| 908 | - * |
|
| 909 | - * @return EE_Form_Input_Base[] |
|
| 910 | - */ |
|
| 911 | - public function inputs() |
|
| 912 | - { |
|
| 913 | - $inputs = array(); |
|
| 914 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 915 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 916 | - $inputs[$subsection_name] = $subsection; |
|
| 917 | - } |
|
| 918 | - } |
|
| 919 | - return $inputs; |
|
| 920 | - } |
|
| 921 | - |
|
| 922 | - |
|
| 923 | - |
|
| 924 | - /** |
|
| 925 | - * Gets all the subsections which are a proper form |
|
| 926 | - * |
|
| 927 | - * @return EE_Form_Section_Proper[] |
|
| 928 | - */ |
|
| 929 | - public function subforms() |
|
| 930 | - { |
|
| 931 | - $form_sections = array(); |
|
| 932 | - foreach ($this->subsections() as $name => $obj) { |
|
| 933 | - if ($obj instanceof EE_Form_Section_Proper) { |
|
| 934 | - $form_sections[$name] = $obj; |
|
| 935 | - } |
|
| 936 | - } |
|
| 937 | - return $form_sections; |
|
| 938 | - } |
|
| 939 | - |
|
| 940 | - |
|
| 941 | - |
|
| 942 | - /** |
|
| 943 | - * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
| 944 | - * Consider using inputs() or subforms() |
|
| 945 | - * if you only want form inputs or proper form sections. |
|
| 946 | - * |
|
| 947 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
| 948 | - * leave this as TRUE so that the inputs will be properly |
|
| 949 | - * configured. However, some client code may be ok with |
|
| 950 | - * construction finalize being called later |
|
| 951 | - * (realizing that the subsections' html names might not be |
|
| 952 | - * set yet, etc.) |
|
| 953 | - * @return EE_Form_Section_Proper[] |
|
| 954 | - */ |
|
| 955 | - public function subsections($require_construction_to_be_finalized = true) |
|
| 956 | - { |
|
| 957 | - if ($require_construction_to_be_finalized) { |
|
| 958 | - $this->ensure_construct_finalized_called(); |
|
| 959 | - } |
|
| 960 | - return $this->_subsections; |
|
| 961 | - } |
|
| 962 | - |
|
| 963 | - |
|
| 964 | - |
|
| 965 | - /** |
|
| 966 | - * Returns a simple array where keys are input names, and values are their normalized |
|
| 967 | - * values. (Similar to calling get_input_value on inputs) |
|
| 968 | - * |
|
| 969 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 970 | - * or just this forms' direct children inputs |
|
| 971 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 972 | - * or allow multidimensional array |
|
| 973 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 974 | - * with array keys being input names |
|
| 975 | - * (regardless of whether they are from a subsection or not), |
|
| 976 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 977 | - * where keys are always subsection names and values are either |
|
| 978 | - * the input's normalized value, or an array like the top-level array |
|
| 979 | - */ |
|
| 980 | - public function input_values($include_subform_inputs = false, $flatten = false) |
|
| 981 | - { |
|
| 982 | - return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
| 983 | - } |
|
| 984 | - |
|
| 985 | - |
|
| 986 | - |
|
| 987 | - /** |
|
| 988 | - * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
| 989 | - * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
| 990 | - * is not necessarily the value we want to display to users. This creates an array |
|
| 991 | - * where keys are the input names, and values are their display values |
|
| 992 | - * |
|
| 993 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 994 | - * or just this forms' direct children inputs |
|
| 995 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 996 | - * or allow multidimensional array |
|
| 997 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 998 | - * with array keys being input names |
|
| 999 | - * (regardless of whether they are from a subsection or not), |
|
| 1000 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 1001 | - * where keys are always subsection names and values are either |
|
| 1002 | - * the input's normalized value, or an array like the top-level array |
|
| 1003 | - */ |
|
| 1004 | - public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
| 1005 | - { |
|
| 1006 | - return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
| 1007 | - } |
|
| 1008 | - |
|
| 1009 | - |
|
| 1010 | - |
|
| 1011 | - /** |
|
| 1012 | - * Gets the input values from the form |
|
| 1013 | - * |
|
| 1014 | - * @param boolean $pretty Whether to retrieve the pretty value, |
|
| 1015 | - * or just the normalized value |
|
| 1016 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 1017 | - * or just this forms' direct children inputs |
|
| 1018 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 1019 | - * or allow multidimensional array |
|
| 1020 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
| 1021 | - * input names (regardless of whether they are from a subsection or not), |
|
| 1022 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 1023 | - * where keys are always subsection names and values are either |
|
| 1024 | - * the input's normalized value, or an array like the top-level array |
|
| 1025 | - */ |
|
| 1026 | - public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
| 1027 | - { |
|
| 1028 | - $input_values = array(); |
|
| 1029 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 1030 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1031 | - $input_values[$subsection_name] = $pretty |
|
| 1032 | - ? $subsection->pretty_value() |
|
| 1033 | - : $subsection->normalized_value(); |
|
| 1034 | - } else if ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
| 1035 | - $subform_input_values = $subsection->_input_values($pretty, $include_subform_inputs, $flatten); |
|
| 1036 | - if ($flatten) { |
|
| 1037 | - $input_values = array_merge($input_values, $subform_input_values); |
|
| 1038 | - } else { |
|
| 1039 | - $input_values[$subsection_name] = $subform_input_values; |
|
| 1040 | - } |
|
| 1041 | - } |
|
| 1042 | - } |
|
| 1043 | - return $input_values; |
|
| 1044 | - } |
|
| 1045 | - |
|
| 1046 | - |
|
| 1047 | - |
|
| 1048 | - /** |
|
| 1049 | - * Gets the originally submitted input values from the form |
|
| 1050 | - * |
|
| 1051 | - * @param boolean $include_subforms Whether to include inputs from subforms, |
|
| 1052 | - * or just this forms' direct children inputs |
|
| 1053 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1054 | - * with array keys being input names |
|
| 1055 | - * (regardless of whether they are from a subsection or not), |
|
| 1056 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 1057 | - * where keys are always subsection names and values are either |
|
| 1058 | - * the input's normalized value, or an array like the top-level array |
|
| 1059 | - */ |
|
| 1060 | - public function submitted_values($include_subforms = false) |
|
| 1061 | - { |
|
| 1062 | - $submitted_values = array(); |
|
| 1063 | - foreach ($this->subsections() as $subsection) { |
|
| 1064 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1065 | - // is this input part of an array of inputs? |
|
| 1066 | - if (strpos($subsection->html_name(), '[') !== false) { |
|
| 1067 | - $full_input_name = \EEH_Array::convert_array_values_to_keys( |
|
| 1068 | - explode('[', str_replace(']', '', $subsection->html_name())), |
|
| 1069 | - $subsection->raw_value() |
|
| 1070 | - ); |
|
| 1071 | - $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
| 1072 | - } else { |
|
| 1073 | - $submitted_values[$subsection->html_name()] = $subsection->raw_value(); |
|
| 1074 | - } |
|
| 1075 | - } else if ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
| 1076 | - $subform_input_values = $subsection->submitted_values($include_subforms); |
|
| 1077 | - $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
| 1078 | - } |
|
| 1079 | - } |
|
| 1080 | - return $submitted_values; |
|
| 1081 | - } |
|
| 1082 | - |
|
| 1083 | - |
|
| 1084 | - |
|
| 1085 | - /** |
|
| 1086 | - * Indicates whether or not this form has received a submission yet |
|
| 1087 | - * (ie, had receive_form_submission called on it yet) |
|
| 1088 | - * |
|
| 1089 | - * @return boolean |
|
| 1090 | - * @throws \EE_Error |
|
| 1091 | - */ |
|
| 1092 | - public function has_received_submission() |
|
| 1093 | - { |
|
| 1094 | - $this->ensure_construct_finalized_called(); |
|
| 1095 | - return $this->_received_submission; |
|
| 1096 | - } |
|
| 1097 | - |
|
| 1098 | - |
|
| 1099 | - |
|
| 1100 | - /** |
|
| 1101 | - * Equivalent to passing 'exclude' in the constructor's options array. |
|
| 1102 | - * Removes the listed inputs from the form |
|
| 1103 | - * |
|
| 1104 | - * @param array $inputs_to_exclude values are the input names |
|
| 1105 | - * @return void |
|
| 1106 | - */ |
|
| 1107 | - public function exclude(array $inputs_to_exclude = array()) |
|
| 1108 | - { |
|
| 1109 | - foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
| 1110 | - unset($this->_subsections[$input_to_exclude_name]); |
|
| 1111 | - } |
|
| 1112 | - } |
|
| 1113 | - |
|
| 1114 | - |
|
| 1115 | - |
|
| 1116 | - /** |
|
| 1117 | - * @param array $inputs_to_hide |
|
| 1118 | - * @throws \EE_Error |
|
| 1119 | - */ |
|
| 1120 | - public function hide(array $inputs_to_hide = array()) |
|
| 1121 | - { |
|
| 1122 | - foreach ($inputs_to_hide as $input_to_hide) { |
|
| 1123 | - $input = $this->get_input($input_to_hide); |
|
| 1124 | - $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
| 1125 | - } |
|
| 1126 | - } |
|
| 1127 | - |
|
| 1128 | - |
|
| 1129 | - |
|
| 1130 | - /** |
|
| 1131 | - * add_subsections |
|
| 1132 | - * Adds the listed subsections to the form section. |
|
| 1133 | - * If $subsection_name_to_target is provided, |
|
| 1134 | - * then new subsections are added before or after that subsection, |
|
| 1135 | - * otherwise to the start or end of the entire subsections array. |
|
| 1136 | - * |
|
| 1137 | - * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
| 1138 | - * where keys are their names |
|
| 1139 | - * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
| 1140 | - * should be added before or after |
|
| 1141 | - * IF $subsection_name_to_target is null, |
|
| 1142 | - * then $new_subsections will be added to |
|
| 1143 | - * the beginning or end of the entire subsections array |
|
| 1144 | - * @param boolean $add_before whether to add $new_subsections, before or after |
|
| 1145 | - * $subsection_name_to_target, |
|
| 1146 | - * or if $subsection_name_to_target is null, |
|
| 1147 | - * before or after entire subsections array |
|
| 1148 | - * @return void |
|
| 1149 | - * @throws \EE_Error |
|
| 1150 | - */ |
|
| 1151 | - public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
| 1152 | - { |
|
| 1153 | - foreach ($new_subsections as $subsection_name => $subsection) { |
|
| 1154 | - if (! $subsection instanceof EE_Form_Section_Base) { |
|
| 1155 | - EE_Error::add_error( |
|
| 1156 | - sprintf( |
|
| 1157 | - __( |
|
| 1158 | - "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
| 1159 | - "event_espresso" |
|
| 1160 | - ), |
|
| 1161 | - get_class($subsection), |
|
| 1162 | - $subsection_name, |
|
| 1163 | - $this->name() |
|
| 1164 | - ) |
|
| 1165 | - ); |
|
| 1166 | - unset($new_subsections[$subsection_name]); |
|
| 1167 | - } |
|
| 1168 | - } |
|
| 1169 | - $this->_subsections = EEH_Array::insert_into_array( |
|
| 1170 | - $this->_subsections, |
|
| 1171 | - $new_subsections, |
|
| 1172 | - $subsection_name_to_target, |
|
| 1173 | - $add_before |
|
| 1174 | - ); |
|
| 1175 | - if ($this->_construction_finalized) { |
|
| 1176 | - foreach ($this->_subsections as $name => $subsection) { |
|
| 1177 | - $subsection->_construct_finalize($this, $name); |
|
| 1178 | - } |
|
| 1179 | - } |
|
| 1180 | - } |
|
| 1181 | - |
|
| 1182 | - |
|
| 1183 | - |
|
| 1184 | - /** |
|
| 1185 | - * Just gets all validatable subsections to clean their sensitive data |
|
| 1186 | - */ |
|
| 1187 | - public function clean_sensitive_data() |
|
| 1188 | - { |
|
| 1189 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1190 | - $subsection->clean_sensitive_data(); |
|
| 1191 | - } |
|
| 1192 | - } |
|
| 1193 | - |
|
| 1194 | - |
|
| 1195 | - |
|
| 1196 | - /** |
|
| 1197 | - * @param string $form_submission_error_message |
|
| 1198 | - */ |
|
| 1199 | - public function set_submission_error_message($form_submission_error_message = '') |
|
| 1200 | - { |
|
| 1201 | - $this->_form_submission_error_message .= ! empty($form_submission_error_message) |
|
| 1202 | - ? $form_submission_error_message |
|
| 1203 | - : __('Form submission failed due to errors', 'event_espresso'); |
|
| 1204 | - } |
|
| 1205 | - |
|
| 1206 | - |
|
| 1207 | - |
|
| 1208 | - /** |
|
| 1209 | - * @return string |
|
| 1210 | - */ |
|
| 1211 | - public function submission_error_message() |
|
| 1212 | - { |
|
| 1213 | - return $this->_form_submission_error_message; |
|
| 1214 | - } |
|
| 1215 | - |
|
| 1216 | - |
|
| 1217 | - |
|
| 1218 | - /** |
|
| 1219 | - * @param string $form_submission_success_message |
|
| 1220 | - */ |
|
| 1221 | - public function set_submission_success_message($form_submission_success_message) |
|
| 1222 | - { |
|
| 1223 | - $this->_form_submission_success_message .= ! empty($form_submission_success_message) |
|
| 1224 | - ? $form_submission_success_message |
|
| 1225 | - : __('Form submitted successfully', 'event_espresso'); |
|
| 1226 | - } |
|
| 1227 | - |
|
| 1228 | - |
|
| 1229 | - |
|
| 1230 | - /** |
|
| 1231 | - * @return string |
|
| 1232 | - */ |
|
| 1233 | - public function submission_success_message() |
|
| 1234 | - { |
|
| 1235 | - return $this->_form_submission_success_message; |
|
| 1236 | - } |
|
| 1237 | - |
|
| 1238 | - |
|
| 1239 | - |
|
| 1240 | - /** |
|
| 1241 | - * Returns the prefix that should be used on child of this form section for |
|
| 1242 | - * their html names. If this form section itself has a parent, prepends ITS |
|
| 1243 | - * prefix onto this form section's prefix. Used primarily by |
|
| 1244 | - * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
| 1245 | - * |
|
| 1246 | - * @return string |
|
| 1247 | - * @throws \EE_Error |
|
| 1248 | - */ |
|
| 1249 | - public function html_name_prefix() |
|
| 1250 | - { |
|
| 1251 | - if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
| 1252 | - return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
| 1253 | - } else { |
|
| 1254 | - return $this->name(); |
|
| 1255 | - } |
|
| 1256 | - } |
|
| 1257 | - |
|
| 1258 | - |
|
| 1259 | - |
|
| 1260 | - /** |
|
| 1261 | - * Gets the name, but first checks _construct_finalize has been called. If not, |
|
| 1262 | - * calls it (assumes there is no parent and that we want the name to be whatever |
|
| 1263 | - * was set, which is probably nothing, or the classname) |
|
| 1264 | - * |
|
| 1265 | - * @return string |
|
| 1266 | - * @throws \EE_Error |
|
| 1267 | - */ |
|
| 1268 | - public function name() |
|
| 1269 | - { |
|
| 1270 | - $this->ensure_construct_finalized_called(); |
|
| 1271 | - return parent::name(); |
|
| 1272 | - } |
|
| 1273 | - |
|
| 1274 | - |
|
| 1275 | - |
|
| 1276 | - /** |
|
| 1277 | - * @return EE_Form_Section_Proper |
|
| 1278 | - * @throws \EE_Error |
|
| 1279 | - */ |
|
| 1280 | - public function parent_section() |
|
| 1281 | - { |
|
| 1282 | - $this->ensure_construct_finalized_called(); |
|
| 1283 | - return parent::parent_section(); |
|
| 1284 | - } |
|
| 1285 | - |
|
| 1286 | - |
|
| 1287 | - |
|
| 1288 | - /** |
|
| 1289 | - * make sure construction finalized was called, otherwise children might not be ready |
|
| 1290 | - * |
|
| 1291 | - * @return void |
|
| 1292 | - * @throws \EE_Error |
|
| 1293 | - */ |
|
| 1294 | - public function ensure_construct_finalized_called() |
|
| 1295 | - { |
|
| 1296 | - if (! $this->_construction_finalized) { |
|
| 1297 | - $this->_construct_finalize($this->_parent_section, $this->_name); |
|
| 1298 | - } |
|
| 1299 | - } |
|
| 1300 | - |
|
| 1301 | - |
|
| 1302 | - |
|
| 1303 | - /** |
|
| 1304 | - * Checks if any of this form section's inputs, or any of its children's inputs, |
|
| 1305 | - * are in teh form data. If any are found, returns true. Else false |
|
| 1306 | - * |
|
| 1307 | - * @param array $req_data |
|
| 1308 | - * @return boolean |
|
| 1309 | - */ |
|
| 1310 | - public function form_data_present_in($req_data = null) |
|
| 1311 | - { |
|
| 1312 | - if ($req_data === null) { |
|
| 1313 | - $req_data = $_POST; |
|
| 1314 | - } |
|
| 1315 | - foreach ($this->subsections() as $subsection) { |
|
| 1316 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1317 | - if ($subsection->form_data_present_in($req_data)) { |
|
| 1318 | - return true; |
|
| 1319 | - } |
|
| 1320 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1321 | - if ($subsection->form_data_present_in($req_data)) { |
|
| 1322 | - return true; |
|
| 1323 | - } |
|
| 1324 | - } |
|
| 1325 | - } |
|
| 1326 | - return false; |
|
| 1327 | - } |
|
| 1328 | - |
|
| 1329 | - |
|
| 1330 | - |
|
| 1331 | - /** |
|
| 1332 | - * Gets validation errors for this form section and subsections |
|
| 1333 | - * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
| 1334 | - * gets the validation errors for ALL subsection |
|
| 1335 | - * |
|
| 1336 | - * @return EE_Validation_Error[] |
|
| 1337 | - */ |
|
| 1338 | - public function get_validation_errors_accumulated() |
|
| 1339 | - { |
|
| 1340 | - $validation_errors = $this->get_validation_errors(); |
|
| 1341 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1342 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1343 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
| 1344 | - } else { |
|
| 1345 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
| 1346 | - } |
|
| 1347 | - if ($validation_errors_on_this_subsection) { |
|
| 1348 | - $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
| 1349 | - } |
|
| 1350 | - } |
|
| 1351 | - return $validation_errors; |
|
| 1352 | - } |
|
| 1353 | - |
|
| 1354 | - |
|
| 1355 | - |
|
| 1356 | - /** |
|
| 1357 | - * This isn't just the name of an input, it's a path pointing to an input. The |
|
| 1358 | - * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
| 1359 | - * dot-dot-slash (../) means to ascend into the parent section. |
|
| 1360 | - * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
| 1361 | - * which will be returned. |
|
| 1362 | - * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
| 1363 | - * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
| 1364 | - * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
| 1365 | - * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
| 1366 | - * Etc |
|
| 1367 | - * |
|
| 1368 | - * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
| 1369 | - * @return EE_Form_Section_Base |
|
| 1370 | - */ |
|
| 1371 | - public function find_section_from_path($form_section_path) |
|
| 1372 | - { |
|
| 1373 | - //check if we can find the input from purely going straight up the tree |
|
| 1374 | - $input = parent::find_section_from_path($form_section_path); |
|
| 1375 | - if ($input instanceof EE_Form_Section_Base) { |
|
| 1376 | - return $input; |
|
| 1377 | - } |
|
| 1378 | - $next_slash_pos = strpos($form_section_path, '/'); |
|
| 1379 | - if ($next_slash_pos !== false) { |
|
| 1380 | - $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
| 1381 | - $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
| 1382 | - } else { |
|
| 1383 | - $child_section_name = $form_section_path; |
|
| 1384 | - $subpath = ''; |
|
| 1385 | - } |
|
| 1386 | - $child_section = $this->get_subsection($child_section_name); |
|
| 1387 | - if ($child_section instanceof EE_Form_Section_Base) { |
|
| 1388 | - return $child_section->find_section_from_path($subpath); |
|
| 1389 | - } else { |
|
| 1390 | - return null; |
|
| 1391 | - } |
|
| 1392 | - } |
|
| 14 | + const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
|
| 15 | + |
|
| 16 | + /** |
|
| 17 | + * Subsections |
|
| 18 | + * |
|
| 19 | + * @var EE_Form_Section_Validatable[] |
|
| 20 | + */ |
|
| 21 | + protected $_subsections = array(); |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * Strategy for laying out the form |
|
| 25 | + * |
|
| 26 | + * @var EE_Form_Section_Layout_Base |
|
| 27 | + */ |
|
| 28 | + protected $_layout_strategy; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Whether or not this form has received and validated a form submission yet |
|
| 32 | + * |
|
| 33 | + * @var boolean |
|
| 34 | + */ |
|
| 35 | + protected $_received_submission = false; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * message displayed to users upon successful form submission |
|
| 39 | + * |
|
| 40 | + * @var string |
|
| 41 | + */ |
|
| 42 | + protected $_form_submission_success_message = ''; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * message displayed to users upon unsuccessful form submission |
|
| 46 | + * |
|
| 47 | + * @var string |
|
| 48 | + */ |
|
| 49 | + protected $_form_submission_error_message = ''; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Stores all the data that will localized for form validation |
|
| 53 | + * |
|
| 54 | + * @var array |
|
| 55 | + */ |
|
| 56 | + static protected $_js_localization = array(); |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * whether or not the form's localized validation JS vars have been set |
|
| 60 | + * |
|
| 61 | + * @type boolean |
|
| 62 | + */ |
|
| 63 | + static protected $_scripts_localized = false; |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * when constructing a proper form section, calls _construct_finalize on children |
|
| 69 | + * so that they know who their parent is, and what name they've been given. |
|
| 70 | + * |
|
| 71 | + * @param array $options_array { |
|
| 72 | + * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name |
|
| 73 | + * @type $include string[] numerically-indexed where values are section names to be included, |
|
| 74 | + * and in that order. This is handy if you want |
|
| 75 | + * the subsections to be ordered differently than the default, and if you override |
|
| 76 | + * which fields are shown |
|
| 77 | + * @type $exclude string[] values are subsections to be excluded. This is handy if you want |
|
| 78 | + * to remove certain default subsections (note: if you specify BOTH 'include' AND |
|
| 79 | + * 'exclude', the inclusions will be applied first, and the exclusions will exclude |
|
| 80 | + * items from that list of inclusions) |
|
| 81 | + * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form |
|
| 82 | + * } @see EE_Form_Section_Validatable::__construct() |
|
| 83 | + * @throws \EE_Error |
|
| 84 | + */ |
|
| 85 | + public function __construct($options_array = array()) |
|
| 86 | + { |
|
| 87 | + $options_array = (array)apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array, |
|
| 88 | + $this); |
|
| 89 | + //call parent first, as it may be setting the name |
|
| 90 | + parent::__construct($options_array); |
|
| 91 | + //if they've included subsections in the constructor, add them now |
|
| 92 | + if (isset($options_array['include'])) { |
|
| 93 | + //we are going to make sure we ONLY have those subsections to include |
|
| 94 | + //AND we are going to make sure they're in that specified order |
|
| 95 | + $reordered_subsections = array(); |
|
| 96 | + foreach ($options_array['include'] as $input_name) { |
|
| 97 | + if (isset($this->_subsections[$input_name])) { |
|
| 98 | + $reordered_subsections[$input_name] = $this->_subsections[$input_name]; |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + $this->_subsections = $reordered_subsections; |
|
| 102 | + } |
|
| 103 | + if (isset($options_array['exclude'])) { |
|
| 104 | + $exclude = $options_array['exclude']; |
|
| 105 | + $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
|
| 106 | + } |
|
| 107 | + if (isset($options_array['layout_strategy'])) { |
|
| 108 | + $this->_layout_strategy = $options_array['layout_strategy']; |
|
| 109 | + } |
|
| 110 | + if (! $this->_layout_strategy) { |
|
| 111 | + $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
|
| 112 | + } |
|
| 113 | + $this->_layout_strategy->_construct_finalize($this); |
|
| 114 | + //ok so we are definitely going to want the forms JS, |
|
| 115 | + //so enqueue it or remember to enqueue it during wp_enqueue_scripts |
|
| 116 | + if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) { |
|
| 117 | + //ok so they've constructed this object after when they should have. |
|
| 118 | + //just enqueue the generic form scripts and initialize the form immediately in the JS |
|
| 119 | + \EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
| 120 | + } else { |
|
| 121 | + add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 122 | + add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 123 | + } |
|
| 124 | + add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Gives other plugins a chance to hook in before construct finalize is called. The form probably doesn't |
|
| 128 | + * yet have a parent form section. Since 4.9.32, when this action was introduced, this is the best place to |
|
| 129 | + * add a subsection onto a form, assuming you don't care what the form section's name, HTML ID, or HTML name etc are. |
|
| 130 | + * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end |
|
| 131 | + * @since 4.9.32 |
|
| 132 | + * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, except maybe calling |
|
| 133 | + * _construct_finalize has been done |
|
| 134 | + * @param array $options_array options passed into the constructor |
|
| 135 | + */ |
|
| 136 | + do_action('AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', $this, $options_array); |
|
| 137 | + |
|
| 138 | + if (isset($options_array['name'])) { |
|
| 139 | + $this->_construct_finalize(null, $options_array['name']); |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Finishes construction given the parent form section and this form section's name |
|
| 147 | + * |
|
| 148 | + * @param EE_Form_Section_Proper $parent_form_section |
|
| 149 | + * @param string $name |
|
| 150 | + * @throws \EE_Error |
|
| 151 | + */ |
|
| 152 | + public function _construct_finalize($parent_form_section, $name) |
|
| 153 | + { |
|
| 154 | + parent::_construct_finalize($parent_form_section, $name); |
|
| 155 | + $this->_set_default_name_if_empty(); |
|
| 156 | + $this->_set_default_html_id_if_empty(); |
|
| 157 | + foreach ($this->_subsections as $subsection_name => $subsection) { |
|
| 158 | + if ($subsection instanceof EE_Form_Section_Base) { |
|
| 159 | + $subsection->_construct_finalize($this, $subsection_name); |
|
| 160 | + } else { |
|
| 161 | + throw new EE_Error( |
|
| 162 | + sprintf( |
|
| 163 | + __('Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', |
|
| 164 | + 'event_espresso'), |
|
| 165 | + $subsection_name, |
|
| 166 | + get_class($this), |
|
| 167 | + $subsection ? get_class($subsection) : __('NULL', 'event_espresso') |
|
| 168 | + ) |
|
| 169 | + ); |
|
| 170 | + } |
|
| 171 | + } |
|
| 172 | + /** |
|
| 173 | + * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed. |
|
| 174 | + * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID (or other attributes derived |
|
| 175 | + * from the name like the HTML label id, etc), this is where it should be done. |
|
| 176 | + * This might only happen just before displaying the form, or just before it receives form submission data. |
|
| 177 | + * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've |
|
| 178 | + * ensured it has a name, HTML IDs, etc |
|
| 179 | + * @param EE_Form_Section_Proper $this |
|
| 180 | + * @param EE_Form_Section_Proper|null $parent_form_section |
|
| 181 | + * @param string $name |
|
| 182 | + */ |
|
| 183 | + do_action('AHEE__EE_Form_Section_Proper___construct_finalize__end', $this, $parent_form_section, $name); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * Gets the layout strategy for this form section |
|
| 190 | + * |
|
| 191 | + * @return EE_Form_Section_Layout_Base |
|
| 192 | + */ |
|
| 193 | + public function get_layout_strategy() |
|
| 194 | + { |
|
| 195 | + return $this->_layout_strategy; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * Gets the HTML for a single input for this form section according |
|
| 202 | + * to the layout strategy |
|
| 203 | + * |
|
| 204 | + * @param EE_Form_Input_Base $input |
|
| 205 | + * @return string |
|
| 206 | + */ |
|
| 207 | + public function get_html_for_input($input) |
|
| 208 | + { |
|
| 209 | + return $this->_layout_strategy->layout_input($input); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * was_submitted - checks if form inputs are present in request data |
|
| 216 | + * Basically an alias for form_data_present_in() (which is used by both |
|
| 217 | + * proper form sections and form inputs) |
|
| 218 | + * |
|
| 219 | + * @param null $form_data |
|
| 220 | + * @return boolean |
|
| 221 | + */ |
|
| 222 | + public function was_submitted($form_data = null) |
|
| 223 | + { |
|
| 224 | + return $this->form_data_present_in($form_data); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * After the form section is initially created, call this to sanitize the data in the submission |
|
| 231 | + * which relates to this form section, validate it, and set it as properties on the form. |
|
| 232 | + * |
|
| 233 | + * @param array|null $req_data should usually be $_POST (the default). |
|
| 234 | + * However, you CAN supply a different array. |
|
| 235 | + * Consider using set_defaults() instead however. |
|
| 236 | + * (If you rendered the form in the page using echo $form_x->get_html() |
|
| 237 | + * the inputs will have the correct name in the request data for this function |
|
| 238 | + * to find them and populate the form with them. |
|
| 239 | + * If you have a flat form (with only input subsections), |
|
| 240 | + * you can supply a flat array where keys |
|
| 241 | + * are the form input names and values are their values) |
|
| 242 | + * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
| 243 | + * of course, to validate that data, and set errors on the invalid values. |
|
| 244 | + * But if the data has already been validated |
|
| 245 | + * (eg you validated the data then stored it in the DB) |
|
| 246 | + * you may want to skip this step. |
|
| 247 | + */ |
|
| 248 | + public function receive_form_submission($req_data = null, $validate = true) |
|
| 249 | + { |
|
| 250 | + $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', $req_data, $this, |
|
| 251 | + $validate); |
|
| 252 | + if ($req_data === null) { |
|
| 253 | + $req_data = array_merge($_GET, $_POST); |
|
| 254 | + } |
|
| 255 | + $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', $req_data, |
|
| 256 | + $this); |
|
| 257 | + $this->_normalize($req_data); |
|
| 258 | + if ($validate) { |
|
| 259 | + $this->_validate(); |
|
| 260 | + //if it's invalid, we're going to want to re-display so remember what they submitted |
|
| 261 | + if (! $this->is_valid()) { |
|
| 262 | + $this->store_submitted_form_data_in_session(); |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + do_action('AHEE__EE_Form_Section_Proper__receive_form_submission__end', $req_data, $this, $validate); |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * caches the originally submitted input values in the session |
|
| 272 | + * so that they can be used to repopulate the form if it failed validation |
|
| 273 | + * |
|
| 274 | + * @return boolean whether or not the data was successfully stored in the session |
|
| 275 | + */ |
|
| 276 | + protected function store_submitted_form_data_in_session() |
|
| 277 | + { |
|
| 278 | + return EE_Registry::instance()->SSN->set_session_data( |
|
| 279 | + array( |
|
| 280 | + \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
| 281 | + ) |
|
| 282 | + ); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * retrieves the originally submitted input values in the session |
|
| 289 | + * so that they can be used to repopulate the form if it failed validation |
|
| 290 | + * |
|
| 291 | + * @return array |
|
| 292 | + */ |
|
| 293 | + protected function get_submitted_form_data_from_session() |
|
| 294 | + { |
|
| 295 | + $session = EE_Registry::instance()->SSN; |
|
| 296 | + if ($session instanceof EE_Session) { |
|
| 297 | + return $session->get_session_data( |
|
| 298 | + \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
| 299 | + ); |
|
| 300 | + } else { |
|
| 301 | + return array(); |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * flushed the originally submitted input values from the session |
|
| 309 | + * |
|
| 310 | + * @return boolean whether or not the data was successfully removed from the session |
|
| 311 | + */ |
|
| 312 | + protected function flush_submitted_form_data_from_session() |
|
| 313 | + { |
|
| 314 | + return EE_Registry::instance()->SSN->reset_data( |
|
| 315 | + array(\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
| 316 | + ); |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * Populates this form and its subsections with data from the session. |
|
| 323 | + * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
| 324 | + * validation errors when displaying too) |
|
| 325 | + * Returns true if the form was populated from the session, false otherwise |
|
| 326 | + * |
|
| 327 | + * @return boolean |
|
| 328 | + */ |
|
| 329 | + public function populate_from_session() |
|
| 330 | + { |
|
| 331 | + $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
| 332 | + if (empty($form_data_in_session)) { |
|
| 333 | + return false; |
|
| 334 | + } |
|
| 335 | + $this->receive_form_submission($form_data_in_session); |
|
| 336 | + $this->flush_submitted_form_data_from_session(); |
|
| 337 | + if ($this->form_data_present_in($form_data_in_session)) { |
|
| 338 | + return true; |
|
| 339 | + } else { |
|
| 340 | + return false; |
|
| 341 | + } |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * Populates the default data for the form, given an array where keys are |
|
| 348 | + * the input names, and values are their values (preferably normalized to be their |
|
| 349 | + * proper PHP types, not all strings... although that should be ok too). |
|
| 350 | + * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
| 351 | + * the value being an array formatted in teh same way |
|
| 352 | + * |
|
| 353 | + * @param array $default_data |
|
| 354 | + */ |
|
| 355 | + public function populate_defaults($default_data) |
|
| 356 | + { |
|
| 357 | + foreach ($this->subsections(false) as $subsection_name => $subsection) { |
|
| 358 | + if (isset($default_data[$subsection_name])) { |
|
| 359 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 360 | + $subsection->set_default($default_data[$subsection_name]); |
|
| 361 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 362 | + $subsection->populate_defaults($default_data[$subsection_name]); |
|
| 363 | + } |
|
| 364 | + } |
|
| 365 | + } |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + |
|
| 369 | + |
|
| 370 | + /** |
|
| 371 | + * returns true if subsection exists |
|
| 372 | + * |
|
| 373 | + * @param string $name |
|
| 374 | + * @return boolean |
|
| 375 | + */ |
|
| 376 | + public function subsection_exists($name) |
|
| 377 | + { |
|
| 378 | + return isset($this->_subsections[$name]) ? true : false; |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * Gets the subsection specified by its name |
|
| 385 | + * |
|
| 386 | + * @param string $name |
|
| 387 | + * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
| 388 | + * so that the inputs will be properly configured. |
|
| 389 | + * However, some client code may be ok |
|
| 390 | + * with construction finalize being called later |
|
| 391 | + * (realizing that the subsections' html names |
|
| 392 | + * might not be set yet, etc.) |
|
| 393 | + * @return EE_Form_Section_Base |
|
| 394 | + * @throws \EE_Error |
|
| 395 | + */ |
|
| 396 | + public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
| 397 | + { |
|
| 398 | + if ($require_construction_to_be_finalized) { |
|
| 399 | + $this->ensure_construct_finalized_called(); |
|
| 400 | + } |
|
| 401 | + return $this->subsection_exists($name) ? $this->_subsections[$name] : null; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + |
|
| 405 | + |
|
| 406 | + /** |
|
| 407 | + * Gets all the validatable subsections of this form section |
|
| 408 | + * |
|
| 409 | + * @return EE_Form_Section_Validatable[] |
|
| 410 | + */ |
|
| 411 | + public function get_validatable_subsections() |
|
| 412 | + { |
|
| 413 | + $validatable_subsections = array(); |
|
| 414 | + foreach ($this->subsections() as $name => $obj) { |
|
| 415 | + if ($obj instanceof EE_Form_Section_Validatable) { |
|
| 416 | + $validatable_subsections[$name] = $obj; |
|
| 417 | + } |
|
| 418 | + } |
|
| 419 | + return $validatable_subsections; |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
| 426 | + * throw an EE_Error. |
|
| 427 | + * |
|
| 428 | + * @param string $name |
|
| 429 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
| 430 | + * leave this as TRUE so that the inputs will be properly |
|
| 431 | + * configured. However, some client code may be ok with |
|
| 432 | + * construction finalize being called later |
|
| 433 | + * (realizing that the subsections' html names might not be |
|
| 434 | + * set yet, etc.) |
|
| 435 | + * @return EE_Form_Input_Base |
|
| 436 | + * @throws EE_Error |
|
| 437 | + */ |
|
| 438 | + public function get_input($name, $require_construction_to_be_finalized = true) |
|
| 439 | + { |
|
| 440 | + $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
|
| 441 | + if (! $subsection instanceof EE_Form_Input_Base) { |
|
| 442 | + throw new EE_Error( |
|
| 443 | + sprintf( |
|
| 444 | + __( |
|
| 445 | + "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
| 446 | + 'event_espresso' |
|
| 447 | + ), |
|
| 448 | + $name, |
|
| 449 | + get_class($this), |
|
| 450 | + $subsection ? get_class($subsection) : __("NULL", 'event_espresso') |
|
| 451 | + ) |
|
| 452 | + ); |
|
| 453 | + } |
|
| 454 | + return $subsection; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + |
|
| 458 | + |
|
| 459 | + /** |
|
| 460 | + * Like get_input(), gets the proper subsection of the form given the name, |
|
| 461 | + * otherwise throws an EE_Error |
|
| 462 | + * |
|
| 463 | + * @param string $name |
|
| 464 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
| 465 | + * leave this as TRUE so that the inputs will be properly |
|
| 466 | + * configured. However, some client code may be ok with |
|
| 467 | + * construction finalize being called later |
|
| 468 | + * (realizing that the subsections' html names might not be |
|
| 469 | + * set yet, etc.) |
|
| 470 | + * @return EE_Form_Section_Proper |
|
| 471 | + * @throws EE_Error |
|
| 472 | + */ |
|
| 473 | + public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
| 474 | + { |
|
| 475 | + $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
|
| 476 | + if (! $subsection instanceof EE_Form_Section_Proper) { |
|
| 477 | + throw new EE_Error( |
|
| 478 | + sprintf( |
|
| 479 | + __("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'), |
|
| 480 | + $name, |
|
| 481 | + get_class($this) |
|
| 482 | + ) |
|
| 483 | + ); |
|
| 484 | + } |
|
| 485 | + return $subsection; |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + |
|
| 489 | + |
|
| 490 | + /** |
|
| 491 | + * Gets the value of the specified input. Should be called after receive_form_submission() |
|
| 492 | + * or populate_defaults() on the form, where the normalized value on the input is set. |
|
| 493 | + * |
|
| 494 | + * @param string $name |
|
| 495 | + * @return mixed depending on the input's type and its normalization strategy |
|
| 496 | + * @throws \EE_Error |
|
| 497 | + */ |
|
| 498 | + public function get_input_value($name) |
|
| 499 | + { |
|
| 500 | + $input = $this->get_input($name); |
|
| 501 | + return $input->normalized_value(); |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * Checks if this form section itself is valid, and then checks its subsections |
|
| 508 | + * |
|
| 509 | + * @throws EE_Error |
|
| 510 | + * @return boolean |
|
| 511 | + */ |
|
| 512 | + public function is_valid() |
|
| 513 | + { |
|
| 514 | + if (! $this->has_received_submission()) { |
|
| 515 | + throw new EE_Error( |
|
| 516 | + sprintf( |
|
| 517 | + __( |
|
| 518 | + "You cannot check if a form is valid before receiving the form submission using receive_form_submission", |
|
| 519 | + "event_espresso" |
|
| 520 | + ) |
|
| 521 | + ) |
|
| 522 | + ); |
|
| 523 | + } |
|
| 524 | + if (! parent::is_valid()) { |
|
| 525 | + return false; |
|
| 526 | + } |
|
| 527 | + // ok so no general errors to this entire form section. |
|
| 528 | + // so let's check the subsections, but only set errors if that hasn't been done yet |
|
| 529 | + $set_submission_errors = $this->submission_error_message() === '' ? true : false; |
|
| 530 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 531 | + if (! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') { |
|
| 532 | + if ($set_submission_errors) { |
|
| 533 | + $this->set_submission_error_message($subsection->get_validation_error_string()); |
|
| 534 | + } |
|
| 535 | + return false; |
|
| 536 | + } |
|
| 537 | + } |
|
| 538 | + return true; |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + |
|
| 542 | + |
|
| 543 | + /** |
|
| 544 | + * gets teh default name of this form section if none is specified |
|
| 545 | + * |
|
| 546 | + * @return string |
|
| 547 | + */ |
|
| 548 | + protected function _set_default_name_if_empty() |
|
| 549 | + { |
|
| 550 | + if (! $this->_name) { |
|
| 551 | + $classname = get_class($this); |
|
| 552 | + $default_name = str_replace("EE_", "", $classname); |
|
| 553 | + $this->_name = $default_name; |
|
| 554 | + } |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + |
|
| 558 | + |
|
| 559 | + /** |
|
| 560 | + * Returns the HTML for the form, except for the form opening and closing tags |
|
| 561 | + * (as the form section doesn't know where you necessarily want to send the information to), |
|
| 562 | + * and except for a submit button. Enqueus JS and CSS; if called early enough we will |
|
| 563 | + * try to enqueue them in the header, otherwise they'll be enqueued in the footer. |
|
| 564 | + * Not doing_it_wrong because theoretically this CAN be used properly, |
|
| 565 | + * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue |
|
| 566 | + * any CSS. |
|
| 567 | + * |
|
| 568 | + * @throws \EE_Error |
|
| 569 | + */ |
|
| 570 | + public function get_html_and_js() |
|
| 571 | + { |
|
| 572 | + $this->enqueue_js(); |
|
| 573 | + return $this->get_html(); |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + |
|
| 577 | + |
|
| 578 | + /** |
|
| 579 | + * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
| 580 | + * |
|
| 581 | + * @param bool $display_previously_submitted_data |
|
| 582 | + * @return string |
|
| 583 | + */ |
|
| 584 | + public function get_html($display_previously_submitted_data = true) |
|
| 585 | + { |
|
| 586 | + $this->ensure_construct_finalized_called(); |
|
| 587 | + if ($display_previously_submitted_data) { |
|
| 588 | + $this->populate_from_session(); |
|
| 589 | + } |
|
| 590 | + return $this->_form_html_filter |
|
| 591 | + ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this) |
|
| 592 | + : $this->_layout_strategy->layout_form(); |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + |
|
| 596 | + |
|
| 597 | + /** |
|
| 598 | + * enqueues JS and CSS for the form. |
|
| 599 | + * It is preferred to call this before wp_enqueue_scripts so the |
|
| 600 | + * scripts and styles can be put in the header, but if called later |
|
| 601 | + * they will be put in the footer (which is OK for JS, but in HTML4 CSS should |
|
| 602 | + * only be in the header; but in HTML5 its ok in the body. |
|
| 603 | + * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag. |
|
| 604 | + * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.) |
|
| 605 | + * |
|
| 606 | + * @return string |
|
| 607 | + * @throws \EE_Error |
|
| 608 | + */ |
|
| 609 | + public function enqueue_js() |
|
| 610 | + { |
|
| 611 | + $this->_enqueue_and_localize_form_js(); |
|
| 612 | + foreach ($this->subsections() as $subsection) { |
|
| 613 | + $subsection->enqueue_js(); |
|
| 614 | + } |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + |
|
| 618 | + |
|
| 619 | + /** |
|
| 620 | + * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
| 621 | + * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
| 622 | + * the wp_enqueue_scripts hook. |
|
| 623 | + * However, registering the form js and localizing it can happen when we |
|
| 624 | + * actually output the form (which is preferred, seeing how teh form's fields |
|
| 625 | + * could change until it's actually outputted) |
|
| 626 | + * |
|
| 627 | + * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
| 628 | + * to be triggered automatically or not |
|
| 629 | + * @return void |
|
| 630 | + */ |
|
| 631 | + public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
| 632 | + { |
|
| 633 | + wp_register_script( |
|
| 634 | + 'ee_form_section_validation', |
|
| 635 | + EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
| 636 | + array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
| 637 | + EVENT_ESPRESSO_VERSION, |
|
| 638 | + true |
|
| 639 | + ); |
|
| 640 | + wp_localize_script( |
|
| 641 | + 'ee_form_section_validation', |
|
| 642 | + 'ee_form_section_validation_init', |
|
| 643 | + array('init' => $init_form_validation_automatically ? '1' : '0') |
|
| 644 | + ); |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + |
|
| 648 | + |
|
| 649 | + /** |
|
| 650 | + * gets the variables used by form_section_validation.js. |
|
| 651 | + * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
| 652 | + * but before the wordpress hook wp_loaded |
|
| 653 | + * |
|
| 654 | + * @throws \EE_Error |
|
| 655 | + */ |
|
| 656 | + public function _enqueue_and_localize_form_js() |
|
| 657 | + { |
|
| 658 | + $this->ensure_construct_finalized_called(); |
|
| 659 | + //actually, we don't want to localize just yet. There may be other forms on the page. |
|
| 660 | + //so we need to add our form section data to a static variable accessible by all form sections |
|
| 661 | + //and localize it just before the footer |
|
| 662 | + $this->localize_validation_rules(); |
|
| 663 | + add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
| 664 | + add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
| 665 | + } |
|
| 666 | + |
|
| 667 | + |
|
| 668 | + |
|
| 669 | + /** |
|
| 670 | + * add our form section data to a static variable accessible by all form sections |
|
| 671 | + * |
|
| 672 | + * @param bool $return_for_subsection |
|
| 673 | + * @return void |
|
| 674 | + * @throws \EE_Error |
|
| 675 | + */ |
|
| 676 | + public function localize_validation_rules($return_for_subsection = false) |
|
| 677 | + { |
|
| 678 | + // we only want to localize vars ONCE for the entire form, |
|
| 679 | + // so if the form section doesn't have a parent, then it must be the top dog |
|
| 680 | + if ($return_for_subsection || ! $this->parent_section()) { |
|
| 681 | + EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array( |
|
| 682 | + 'form_section_id' => $this->html_id(true), |
|
| 683 | + 'validation_rules' => $this->get_jquery_validation_rules(), |
|
| 684 | + 'other_data' => $this->get_other_js_data(), |
|
| 685 | + 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
| 686 | + ); |
|
| 687 | + EE_Form_Section_Proper::$_scripts_localized = true; |
|
| 688 | + } |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + |
|
| 692 | + |
|
| 693 | + /** |
|
| 694 | + * Gets an array of extra data that will be useful for client-side javascript. |
|
| 695 | + * This is primarily data added by inputs and forms in addition to any |
|
| 696 | + * scripts they might enqueue |
|
| 697 | + * |
|
| 698 | + * @param array $form_other_js_data |
|
| 699 | + * @return array |
|
| 700 | + */ |
|
| 701 | + public function get_other_js_data($form_other_js_data = array()) |
|
| 702 | + { |
|
| 703 | + foreach ($this->subsections() as $subsection) { |
|
| 704 | + $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
| 705 | + } |
|
| 706 | + return $form_other_js_data; |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + |
|
| 710 | + |
|
| 711 | + /** |
|
| 712 | + * Gets a flat array of inputs for this form section and its subsections. |
|
| 713 | + * Keys are their form names, and values are the inputs themselves |
|
| 714 | + * |
|
| 715 | + * @return EE_Form_Input_Base |
|
| 716 | + */ |
|
| 717 | + public function inputs_in_subsections() |
|
| 718 | + { |
|
| 719 | + $inputs = array(); |
|
| 720 | + foreach ($this->subsections() as $subsection) { |
|
| 721 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 722 | + $inputs[$subsection->html_name()] = $subsection; |
|
| 723 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 724 | + $inputs += $subsection->inputs_in_subsections(); |
|
| 725 | + } |
|
| 726 | + } |
|
| 727 | + return $inputs; |
|
| 728 | + } |
|
| 729 | + |
|
| 730 | + |
|
| 731 | + |
|
| 732 | + /** |
|
| 733 | + * Gets a flat array of all the validation errors. |
|
| 734 | + * Keys are html names (because those should be unique) |
|
| 735 | + * and values are a string of all their validation errors |
|
| 736 | + * |
|
| 737 | + * @return string[] |
|
| 738 | + */ |
|
| 739 | + public function subsection_validation_errors_by_html_name() |
|
| 740 | + { |
|
| 741 | + $inputs = $this->inputs(); |
|
| 742 | + $errors = array(); |
|
| 743 | + foreach ($inputs as $form_input) { |
|
| 744 | + if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
| 745 | + $errors[$form_input->html_name()] = $form_input->get_validation_error_string(); |
|
| 746 | + } |
|
| 747 | + } |
|
| 748 | + return $errors; |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + |
|
| 752 | + |
|
| 753 | + /** |
|
| 754 | + * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
| 755 | + * Should be setup by each form during the _enqueues_and_localize_form_js |
|
| 756 | + */ |
|
| 757 | + public static function localize_script_for_all_forms() |
|
| 758 | + { |
|
| 759 | + //allow inputs and stuff to hook in their JS and stuff here |
|
| 760 | + do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
| 761 | + EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
| 762 | + $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
| 763 | + ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
| 764 | + : 'wp_default'; |
|
| 765 | + EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
| 766 | + wp_enqueue_script('ee_form_section_validation'); |
|
| 767 | + wp_localize_script( |
|
| 768 | + 'ee_form_section_validation', |
|
| 769 | + 'ee_form_section_vars', |
|
| 770 | + EE_Form_Section_Proper::$_js_localization |
|
| 771 | + ); |
|
| 772 | + } |
|
| 773 | + |
|
| 774 | + |
|
| 775 | + |
|
| 776 | + /** |
|
| 777 | + * ensure_scripts_localized |
|
| 778 | + */ |
|
| 779 | + public function ensure_scripts_localized() |
|
| 780 | + { |
|
| 781 | + if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
| 782 | + $this->_enqueue_and_localize_form_js(); |
|
| 783 | + } |
|
| 784 | + } |
|
| 785 | + |
|
| 786 | + |
|
| 787 | + |
|
| 788 | + /** |
|
| 789 | + * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
| 790 | + * is that the key here should be the same as the custom validation rule put in the JS file |
|
| 791 | + * |
|
| 792 | + * @return array keys are custom validation rules, and values are internationalized strings |
|
| 793 | + */ |
|
| 794 | + private static function _get_localized_error_messages() |
|
| 795 | + { |
|
| 796 | + return array( |
|
| 797 | + 'validUrl' => __("This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg", "event_espresso"), |
|
| 798 | + 'regex' => __('Please check your input', 'event_espresso'), |
|
| 799 | + ); |
|
| 800 | + } |
|
| 801 | + |
|
| 802 | + |
|
| 803 | + |
|
| 804 | + /** |
|
| 805 | + * @return array |
|
| 806 | + */ |
|
| 807 | + public static function js_localization() |
|
| 808 | + { |
|
| 809 | + return self::$_js_localization; |
|
| 810 | + } |
|
| 811 | + |
|
| 812 | + |
|
| 813 | + |
|
| 814 | + /** |
|
| 815 | + * @return array |
|
| 816 | + */ |
|
| 817 | + public static function reset_js_localization() |
|
| 818 | + { |
|
| 819 | + self::$_js_localization = array(); |
|
| 820 | + } |
|
| 821 | + |
|
| 822 | + |
|
| 823 | + |
|
| 824 | + /** |
|
| 825 | + * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
| 826 | + * See parent function for more... |
|
| 827 | + * |
|
| 828 | + * @return array |
|
| 829 | + */ |
|
| 830 | + public function get_jquery_validation_rules() |
|
| 831 | + { |
|
| 832 | + $jquery_validation_rules = array(); |
|
| 833 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 834 | + $jquery_validation_rules = array_merge( |
|
| 835 | + $jquery_validation_rules, |
|
| 836 | + $subsection->get_jquery_validation_rules() |
|
| 837 | + ); |
|
| 838 | + } |
|
| 839 | + return $jquery_validation_rules; |
|
| 840 | + } |
|
| 841 | + |
|
| 842 | + |
|
| 843 | + |
|
| 844 | + /** |
|
| 845 | + * Sanitizes all the data and sets the sanitized value of each field |
|
| 846 | + * |
|
| 847 | + * @param array $req_data like $_POST |
|
| 848 | + * @return void |
|
| 849 | + */ |
|
| 850 | + protected function _normalize($req_data) |
|
| 851 | + { |
|
| 852 | + $this->_received_submission = true; |
|
| 853 | + $this->_validation_errors = array(); |
|
| 854 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 855 | + try { |
|
| 856 | + $subsection->_normalize($req_data); |
|
| 857 | + } catch (EE_Validation_Error $e) { |
|
| 858 | + $subsection->add_validation_error($e); |
|
| 859 | + } |
|
| 860 | + } |
|
| 861 | + } |
|
| 862 | + |
|
| 863 | + |
|
| 864 | + |
|
| 865 | + /** |
|
| 866 | + * Performs validation on this form section and its subsections. |
|
| 867 | + * For each subsection, |
|
| 868 | + * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
| 869 | + * and passes it the subsection, then calls _validate on that subsection. |
|
| 870 | + * If you need to perform validation on the form as a whole (considering multiple) |
|
| 871 | + * you would be best to override this _validate method, |
|
| 872 | + * calling parent::_validate() first. |
|
| 873 | + */ |
|
| 874 | + protected function _validate() |
|
| 875 | + { |
|
| 876 | + foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
| 877 | + if (method_exists($this, '_validate_' . $subsection_name)) { |
|
| 878 | + call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
| 879 | + } |
|
| 880 | + $subsection->_validate(); |
|
| 881 | + } |
|
| 882 | + } |
|
| 883 | + |
|
| 884 | + |
|
| 885 | + |
|
| 886 | + /** |
|
| 887 | + * Gets all the validated inputs for the form section |
|
| 888 | + * |
|
| 889 | + * @return array |
|
| 890 | + */ |
|
| 891 | + public function valid_data() |
|
| 892 | + { |
|
| 893 | + $inputs = array(); |
|
| 894 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 895 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 896 | + $inputs[$subsection_name] = $subsection->valid_data(); |
|
| 897 | + } else if ($subsection instanceof EE_Form_Input_Base) { |
|
| 898 | + $inputs[$subsection_name] = $subsection->normalized_value(); |
|
| 899 | + } |
|
| 900 | + } |
|
| 901 | + return $inputs; |
|
| 902 | + } |
|
| 903 | + |
|
| 904 | + |
|
| 905 | + |
|
| 906 | + /** |
|
| 907 | + * Gets all the inputs on this form section |
|
| 908 | + * |
|
| 909 | + * @return EE_Form_Input_Base[] |
|
| 910 | + */ |
|
| 911 | + public function inputs() |
|
| 912 | + { |
|
| 913 | + $inputs = array(); |
|
| 914 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 915 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 916 | + $inputs[$subsection_name] = $subsection; |
|
| 917 | + } |
|
| 918 | + } |
|
| 919 | + return $inputs; |
|
| 920 | + } |
|
| 921 | + |
|
| 922 | + |
|
| 923 | + |
|
| 924 | + /** |
|
| 925 | + * Gets all the subsections which are a proper form |
|
| 926 | + * |
|
| 927 | + * @return EE_Form_Section_Proper[] |
|
| 928 | + */ |
|
| 929 | + public function subforms() |
|
| 930 | + { |
|
| 931 | + $form_sections = array(); |
|
| 932 | + foreach ($this->subsections() as $name => $obj) { |
|
| 933 | + if ($obj instanceof EE_Form_Section_Proper) { |
|
| 934 | + $form_sections[$name] = $obj; |
|
| 935 | + } |
|
| 936 | + } |
|
| 937 | + return $form_sections; |
|
| 938 | + } |
|
| 939 | + |
|
| 940 | + |
|
| 941 | + |
|
| 942 | + /** |
|
| 943 | + * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
| 944 | + * Consider using inputs() or subforms() |
|
| 945 | + * if you only want form inputs or proper form sections. |
|
| 946 | + * |
|
| 947 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
| 948 | + * leave this as TRUE so that the inputs will be properly |
|
| 949 | + * configured. However, some client code may be ok with |
|
| 950 | + * construction finalize being called later |
|
| 951 | + * (realizing that the subsections' html names might not be |
|
| 952 | + * set yet, etc.) |
|
| 953 | + * @return EE_Form_Section_Proper[] |
|
| 954 | + */ |
|
| 955 | + public function subsections($require_construction_to_be_finalized = true) |
|
| 956 | + { |
|
| 957 | + if ($require_construction_to_be_finalized) { |
|
| 958 | + $this->ensure_construct_finalized_called(); |
|
| 959 | + } |
|
| 960 | + return $this->_subsections; |
|
| 961 | + } |
|
| 962 | + |
|
| 963 | + |
|
| 964 | + |
|
| 965 | + /** |
|
| 966 | + * Returns a simple array where keys are input names, and values are their normalized |
|
| 967 | + * values. (Similar to calling get_input_value on inputs) |
|
| 968 | + * |
|
| 969 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 970 | + * or just this forms' direct children inputs |
|
| 971 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 972 | + * or allow multidimensional array |
|
| 973 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 974 | + * with array keys being input names |
|
| 975 | + * (regardless of whether they are from a subsection or not), |
|
| 976 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 977 | + * where keys are always subsection names and values are either |
|
| 978 | + * the input's normalized value, or an array like the top-level array |
|
| 979 | + */ |
|
| 980 | + public function input_values($include_subform_inputs = false, $flatten = false) |
|
| 981 | + { |
|
| 982 | + return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
| 983 | + } |
|
| 984 | + |
|
| 985 | + |
|
| 986 | + |
|
| 987 | + /** |
|
| 988 | + * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
| 989 | + * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
| 990 | + * is not necessarily the value we want to display to users. This creates an array |
|
| 991 | + * where keys are the input names, and values are their display values |
|
| 992 | + * |
|
| 993 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 994 | + * or just this forms' direct children inputs |
|
| 995 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 996 | + * or allow multidimensional array |
|
| 997 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 998 | + * with array keys being input names |
|
| 999 | + * (regardless of whether they are from a subsection or not), |
|
| 1000 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 1001 | + * where keys are always subsection names and values are either |
|
| 1002 | + * the input's normalized value, or an array like the top-level array |
|
| 1003 | + */ |
|
| 1004 | + public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
| 1005 | + { |
|
| 1006 | + return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
| 1007 | + } |
|
| 1008 | + |
|
| 1009 | + |
|
| 1010 | + |
|
| 1011 | + /** |
|
| 1012 | + * Gets the input values from the form |
|
| 1013 | + * |
|
| 1014 | + * @param boolean $pretty Whether to retrieve the pretty value, |
|
| 1015 | + * or just the normalized value |
|
| 1016 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 1017 | + * or just this forms' direct children inputs |
|
| 1018 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 1019 | + * or allow multidimensional array |
|
| 1020 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
| 1021 | + * input names (regardless of whether they are from a subsection or not), |
|
| 1022 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 1023 | + * where keys are always subsection names and values are either |
|
| 1024 | + * the input's normalized value, or an array like the top-level array |
|
| 1025 | + */ |
|
| 1026 | + public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
| 1027 | + { |
|
| 1028 | + $input_values = array(); |
|
| 1029 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 1030 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1031 | + $input_values[$subsection_name] = $pretty |
|
| 1032 | + ? $subsection->pretty_value() |
|
| 1033 | + : $subsection->normalized_value(); |
|
| 1034 | + } else if ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
| 1035 | + $subform_input_values = $subsection->_input_values($pretty, $include_subform_inputs, $flatten); |
|
| 1036 | + if ($flatten) { |
|
| 1037 | + $input_values = array_merge($input_values, $subform_input_values); |
|
| 1038 | + } else { |
|
| 1039 | + $input_values[$subsection_name] = $subform_input_values; |
|
| 1040 | + } |
|
| 1041 | + } |
|
| 1042 | + } |
|
| 1043 | + return $input_values; |
|
| 1044 | + } |
|
| 1045 | + |
|
| 1046 | + |
|
| 1047 | + |
|
| 1048 | + /** |
|
| 1049 | + * Gets the originally submitted input values from the form |
|
| 1050 | + * |
|
| 1051 | + * @param boolean $include_subforms Whether to include inputs from subforms, |
|
| 1052 | + * or just this forms' direct children inputs |
|
| 1053 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1054 | + * with array keys being input names |
|
| 1055 | + * (regardless of whether they are from a subsection or not), |
|
| 1056 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 1057 | + * where keys are always subsection names and values are either |
|
| 1058 | + * the input's normalized value, or an array like the top-level array |
|
| 1059 | + */ |
|
| 1060 | + public function submitted_values($include_subforms = false) |
|
| 1061 | + { |
|
| 1062 | + $submitted_values = array(); |
|
| 1063 | + foreach ($this->subsections() as $subsection) { |
|
| 1064 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1065 | + // is this input part of an array of inputs? |
|
| 1066 | + if (strpos($subsection->html_name(), '[') !== false) { |
|
| 1067 | + $full_input_name = \EEH_Array::convert_array_values_to_keys( |
|
| 1068 | + explode('[', str_replace(']', '', $subsection->html_name())), |
|
| 1069 | + $subsection->raw_value() |
|
| 1070 | + ); |
|
| 1071 | + $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
| 1072 | + } else { |
|
| 1073 | + $submitted_values[$subsection->html_name()] = $subsection->raw_value(); |
|
| 1074 | + } |
|
| 1075 | + } else if ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
| 1076 | + $subform_input_values = $subsection->submitted_values($include_subforms); |
|
| 1077 | + $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
| 1078 | + } |
|
| 1079 | + } |
|
| 1080 | + return $submitted_values; |
|
| 1081 | + } |
|
| 1082 | + |
|
| 1083 | + |
|
| 1084 | + |
|
| 1085 | + /** |
|
| 1086 | + * Indicates whether or not this form has received a submission yet |
|
| 1087 | + * (ie, had receive_form_submission called on it yet) |
|
| 1088 | + * |
|
| 1089 | + * @return boolean |
|
| 1090 | + * @throws \EE_Error |
|
| 1091 | + */ |
|
| 1092 | + public function has_received_submission() |
|
| 1093 | + { |
|
| 1094 | + $this->ensure_construct_finalized_called(); |
|
| 1095 | + return $this->_received_submission; |
|
| 1096 | + } |
|
| 1097 | + |
|
| 1098 | + |
|
| 1099 | + |
|
| 1100 | + /** |
|
| 1101 | + * Equivalent to passing 'exclude' in the constructor's options array. |
|
| 1102 | + * Removes the listed inputs from the form |
|
| 1103 | + * |
|
| 1104 | + * @param array $inputs_to_exclude values are the input names |
|
| 1105 | + * @return void |
|
| 1106 | + */ |
|
| 1107 | + public function exclude(array $inputs_to_exclude = array()) |
|
| 1108 | + { |
|
| 1109 | + foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
| 1110 | + unset($this->_subsections[$input_to_exclude_name]); |
|
| 1111 | + } |
|
| 1112 | + } |
|
| 1113 | + |
|
| 1114 | + |
|
| 1115 | + |
|
| 1116 | + /** |
|
| 1117 | + * @param array $inputs_to_hide |
|
| 1118 | + * @throws \EE_Error |
|
| 1119 | + */ |
|
| 1120 | + public function hide(array $inputs_to_hide = array()) |
|
| 1121 | + { |
|
| 1122 | + foreach ($inputs_to_hide as $input_to_hide) { |
|
| 1123 | + $input = $this->get_input($input_to_hide); |
|
| 1124 | + $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
| 1125 | + } |
|
| 1126 | + } |
|
| 1127 | + |
|
| 1128 | + |
|
| 1129 | + |
|
| 1130 | + /** |
|
| 1131 | + * add_subsections |
|
| 1132 | + * Adds the listed subsections to the form section. |
|
| 1133 | + * If $subsection_name_to_target is provided, |
|
| 1134 | + * then new subsections are added before or after that subsection, |
|
| 1135 | + * otherwise to the start or end of the entire subsections array. |
|
| 1136 | + * |
|
| 1137 | + * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
| 1138 | + * where keys are their names |
|
| 1139 | + * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
| 1140 | + * should be added before or after |
|
| 1141 | + * IF $subsection_name_to_target is null, |
|
| 1142 | + * then $new_subsections will be added to |
|
| 1143 | + * the beginning or end of the entire subsections array |
|
| 1144 | + * @param boolean $add_before whether to add $new_subsections, before or after |
|
| 1145 | + * $subsection_name_to_target, |
|
| 1146 | + * or if $subsection_name_to_target is null, |
|
| 1147 | + * before or after entire subsections array |
|
| 1148 | + * @return void |
|
| 1149 | + * @throws \EE_Error |
|
| 1150 | + */ |
|
| 1151 | + public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
| 1152 | + { |
|
| 1153 | + foreach ($new_subsections as $subsection_name => $subsection) { |
|
| 1154 | + if (! $subsection instanceof EE_Form_Section_Base) { |
|
| 1155 | + EE_Error::add_error( |
|
| 1156 | + sprintf( |
|
| 1157 | + __( |
|
| 1158 | + "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
| 1159 | + "event_espresso" |
|
| 1160 | + ), |
|
| 1161 | + get_class($subsection), |
|
| 1162 | + $subsection_name, |
|
| 1163 | + $this->name() |
|
| 1164 | + ) |
|
| 1165 | + ); |
|
| 1166 | + unset($new_subsections[$subsection_name]); |
|
| 1167 | + } |
|
| 1168 | + } |
|
| 1169 | + $this->_subsections = EEH_Array::insert_into_array( |
|
| 1170 | + $this->_subsections, |
|
| 1171 | + $new_subsections, |
|
| 1172 | + $subsection_name_to_target, |
|
| 1173 | + $add_before |
|
| 1174 | + ); |
|
| 1175 | + if ($this->_construction_finalized) { |
|
| 1176 | + foreach ($this->_subsections as $name => $subsection) { |
|
| 1177 | + $subsection->_construct_finalize($this, $name); |
|
| 1178 | + } |
|
| 1179 | + } |
|
| 1180 | + } |
|
| 1181 | + |
|
| 1182 | + |
|
| 1183 | + |
|
| 1184 | + /** |
|
| 1185 | + * Just gets all validatable subsections to clean their sensitive data |
|
| 1186 | + */ |
|
| 1187 | + public function clean_sensitive_data() |
|
| 1188 | + { |
|
| 1189 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1190 | + $subsection->clean_sensitive_data(); |
|
| 1191 | + } |
|
| 1192 | + } |
|
| 1193 | + |
|
| 1194 | + |
|
| 1195 | + |
|
| 1196 | + /** |
|
| 1197 | + * @param string $form_submission_error_message |
|
| 1198 | + */ |
|
| 1199 | + public function set_submission_error_message($form_submission_error_message = '') |
|
| 1200 | + { |
|
| 1201 | + $this->_form_submission_error_message .= ! empty($form_submission_error_message) |
|
| 1202 | + ? $form_submission_error_message |
|
| 1203 | + : __('Form submission failed due to errors', 'event_espresso'); |
|
| 1204 | + } |
|
| 1205 | + |
|
| 1206 | + |
|
| 1207 | + |
|
| 1208 | + /** |
|
| 1209 | + * @return string |
|
| 1210 | + */ |
|
| 1211 | + public function submission_error_message() |
|
| 1212 | + { |
|
| 1213 | + return $this->_form_submission_error_message; |
|
| 1214 | + } |
|
| 1215 | + |
|
| 1216 | + |
|
| 1217 | + |
|
| 1218 | + /** |
|
| 1219 | + * @param string $form_submission_success_message |
|
| 1220 | + */ |
|
| 1221 | + public function set_submission_success_message($form_submission_success_message) |
|
| 1222 | + { |
|
| 1223 | + $this->_form_submission_success_message .= ! empty($form_submission_success_message) |
|
| 1224 | + ? $form_submission_success_message |
|
| 1225 | + : __('Form submitted successfully', 'event_espresso'); |
|
| 1226 | + } |
|
| 1227 | + |
|
| 1228 | + |
|
| 1229 | + |
|
| 1230 | + /** |
|
| 1231 | + * @return string |
|
| 1232 | + */ |
|
| 1233 | + public function submission_success_message() |
|
| 1234 | + { |
|
| 1235 | + return $this->_form_submission_success_message; |
|
| 1236 | + } |
|
| 1237 | + |
|
| 1238 | + |
|
| 1239 | + |
|
| 1240 | + /** |
|
| 1241 | + * Returns the prefix that should be used on child of this form section for |
|
| 1242 | + * their html names. If this form section itself has a parent, prepends ITS |
|
| 1243 | + * prefix onto this form section's prefix. Used primarily by |
|
| 1244 | + * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
| 1245 | + * |
|
| 1246 | + * @return string |
|
| 1247 | + * @throws \EE_Error |
|
| 1248 | + */ |
|
| 1249 | + public function html_name_prefix() |
|
| 1250 | + { |
|
| 1251 | + if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
| 1252 | + return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
| 1253 | + } else { |
|
| 1254 | + return $this->name(); |
|
| 1255 | + } |
|
| 1256 | + } |
|
| 1257 | + |
|
| 1258 | + |
|
| 1259 | + |
|
| 1260 | + /** |
|
| 1261 | + * Gets the name, but first checks _construct_finalize has been called. If not, |
|
| 1262 | + * calls it (assumes there is no parent and that we want the name to be whatever |
|
| 1263 | + * was set, which is probably nothing, or the classname) |
|
| 1264 | + * |
|
| 1265 | + * @return string |
|
| 1266 | + * @throws \EE_Error |
|
| 1267 | + */ |
|
| 1268 | + public function name() |
|
| 1269 | + { |
|
| 1270 | + $this->ensure_construct_finalized_called(); |
|
| 1271 | + return parent::name(); |
|
| 1272 | + } |
|
| 1273 | + |
|
| 1274 | + |
|
| 1275 | + |
|
| 1276 | + /** |
|
| 1277 | + * @return EE_Form_Section_Proper |
|
| 1278 | + * @throws \EE_Error |
|
| 1279 | + */ |
|
| 1280 | + public function parent_section() |
|
| 1281 | + { |
|
| 1282 | + $this->ensure_construct_finalized_called(); |
|
| 1283 | + return parent::parent_section(); |
|
| 1284 | + } |
|
| 1285 | + |
|
| 1286 | + |
|
| 1287 | + |
|
| 1288 | + /** |
|
| 1289 | + * make sure construction finalized was called, otherwise children might not be ready |
|
| 1290 | + * |
|
| 1291 | + * @return void |
|
| 1292 | + * @throws \EE_Error |
|
| 1293 | + */ |
|
| 1294 | + public function ensure_construct_finalized_called() |
|
| 1295 | + { |
|
| 1296 | + if (! $this->_construction_finalized) { |
|
| 1297 | + $this->_construct_finalize($this->_parent_section, $this->_name); |
|
| 1298 | + } |
|
| 1299 | + } |
|
| 1300 | + |
|
| 1301 | + |
|
| 1302 | + |
|
| 1303 | + /** |
|
| 1304 | + * Checks if any of this form section's inputs, or any of its children's inputs, |
|
| 1305 | + * are in teh form data. If any are found, returns true. Else false |
|
| 1306 | + * |
|
| 1307 | + * @param array $req_data |
|
| 1308 | + * @return boolean |
|
| 1309 | + */ |
|
| 1310 | + public function form_data_present_in($req_data = null) |
|
| 1311 | + { |
|
| 1312 | + if ($req_data === null) { |
|
| 1313 | + $req_data = $_POST; |
|
| 1314 | + } |
|
| 1315 | + foreach ($this->subsections() as $subsection) { |
|
| 1316 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1317 | + if ($subsection->form_data_present_in($req_data)) { |
|
| 1318 | + return true; |
|
| 1319 | + } |
|
| 1320 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1321 | + if ($subsection->form_data_present_in($req_data)) { |
|
| 1322 | + return true; |
|
| 1323 | + } |
|
| 1324 | + } |
|
| 1325 | + } |
|
| 1326 | + return false; |
|
| 1327 | + } |
|
| 1328 | + |
|
| 1329 | + |
|
| 1330 | + |
|
| 1331 | + /** |
|
| 1332 | + * Gets validation errors for this form section and subsections |
|
| 1333 | + * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
| 1334 | + * gets the validation errors for ALL subsection |
|
| 1335 | + * |
|
| 1336 | + * @return EE_Validation_Error[] |
|
| 1337 | + */ |
|
| 1338 | + public function get_validation_errors_accumulated() |
|
| 1339 | + { |
|
| 1340 | + $validation_errors = $this->get_validation_errors(); |
|
| 1341 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1342 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1343 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
| 1344 | + } else { |
|
| 1345 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
| 1346 | + } |
|
| 1347 | + if ($validation_errors_on_this_subsection) { |
|
| 1348 | + $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
| 1349 | + } |
|
| 1350 | + } |
|
| 1351 | + return $validation_errors; |
|
| 1352 | + } |
|
| 1353 | + |
|
| 1354 | + |
|
| 1355 | + |
|
| 1356 | + /** |
|
| 1357 | + * This isn't just the name of an input, it's a path pointing to an input. The |
|
| 1358 | + * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
| 1359 | + * dot-dot-slash (../) means to ascend into the parent section. |
|
| 1360 | + * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
| 1361 | + * which will be returned. |
|
| 1362 | + * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
| 1363 | + * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
| 1364 | + * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
| 1365 | + * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
| 1366 | + * Etc |
|
| 1367 | + * |
|
| 1368 | + * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
| 1369 | + * @return EE_Form_Section_Base |
|
| 1370 | + */ |
|
| 1371 | + public function find_section_from_path($form_section_path) |
|
| 1372 | + { |
|
| 1373 | + //check if we can find the input from purely going straight up the tree |
|
| 1374 | + $input = parent::find_section_from_path($form_section_path); |
|
| 1375 | + if ($input instanceof EE_Form_Section_Base) { |
|
| 1376 | + return $input; |
|
| 1377 | + } |
|
| 1378 | + $next_slash_pos = strpos($form_section_path, '/'); |
|
| 1379 | + if ($next_slash_pos !== false) { |
|
| 1380 | + $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
| 1381 | + $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
| 1382 | + } else { |
|
| 1383 | + $child_section_name = $form_section_path; |
|
| 1384 | + $subpath = ''; |
|
| 1385 | + } |
|
| 1386 | + $child_section = $this->get_subsection($child_section_name); |
|
| 1387 | + if ($child_section instanceof EE_Form_Section_Base) { |
|
| 1388 | + return $child_section->find_section_from_path($subpath); |
|
| 1389 | + } else { |
|
| 1390 | + return null; |
|
| 1391 | + } |
|
| 1392 | + } |
|
| 1393 | 1393 | |
| 1394 | 1394 | } |
| 1395 | 1395 | |
@@ -2640,7 +2640,7 @@ discard block |
||
| 2640 | 2640 | * @param int $GRP_ID The group being deleted |
| 2641 | 2641 | * @param bool $include_group whether to delete the Message Template Group as well. |
| 2642 | 2642 | * |
| 2643 | - * @return bool boolean to indicate the success of the deletes or not. |
|
| 2643 | + * @return integer boolean to indicate the success of the deletes or not. |
|
| 2644 | 2644 | */ |
| 2645 | 2645 | private function _delete_mtp_permanently($GRP_ID, $include_group = true) |
| 2646 | 2646 | { |
@@ -2772,7 +2772,7 @@ discard block |
||
| 2772 | 2772 | * This just prepares the content for the message type settings |
| 2773 | 2773 | * |
| 2774 | 2774 | * @param object $message_type The message type object |
| 2775 | - * @param object $messenger The messenger object |
|
| 2775 | + * @param EE_messenger|null $messenger The messenger object |
|
| 2776 | 2776 | * @param boolean $active Whether the message type is active or not |
| 2777 | 2777 | * |
| 2778 | 2778 | * @return string html output for the content |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('NO direct script access allowed'); |
|
| 2 | + exit('NO direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | /** |
@@ -17,2222 +17,2222 @@ discard block |
||
| 17 | 17 | class Messages_Admin_Page extends EE_Admin_Page |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 22 | - */ |
|
| 23 | - protected $_message_resource_manager; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @type string $_active_message_type_name |
|
| 27 | - */ |
|
| 28 | - protected $_active_message_type_name = ''; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @type EE_messenger $_active_messenger |
|
| 32 | - */ |
|
| 33 | - protected $_active_messenger; |
|
| 34 | - protected $_activate_state; |
|
| 35 | - protected $_activate_meta_box_type; |
|
| 36 | - protected $_current_message_meta_box; |
|
| 37 | - protected $_current_message_meta_box_object; |
|
| 38 | - protected $_context_switcher; |
|
| 39 | - protected $_shortcodes = array(); |
|
| 40 | - protected $_active_messengers = array(); |
|
| 41 | - protected $_active_message_types = array(); |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @var EE_Message_Template_Group $_message_template_group |
|
| 45 | - */ |
|
| 46 | - protected $_message_template_group; |
|
| 47 | - protected $_m_mt_settings = array(); |
|
| 48 | - |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * This is set via the _set_message_template_group method and holds whatever the template pack for the group is. |
|
| 52 | - * IF there is no group then it gets automatically set to the Default template pack. |
|
| 53 | - * |
|
| 54 | - * @since 4.5.0 |
|
| 55 | - * |
|
| 56 | - * @var EE_Messages_Template_Pack |
|
| 57 | - */ |
|
| 58 | - protected $_template_pack; |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * This is set via the _set_message_template_group method and holds whatever the template pack variation for the |
|
| 63 | - * group is. If there is no group then it automatically gets set to default. |
|
| 64 | - * |
|
| 65 | - * @since 4.5.0 |
|
| 66 | - * |
|
| 67 | - * @var string |
|
| 68 | - */ |
|
| 69 | - protected $_variation; |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @param bool $routing |
|
| 74 | - */ |
|
| 75 | - public function __construct($routing = true) |
|
| 76 | - { |
|
| 77 | - //make sure messages autoloader is running |
|
| 78 | - EED_Messages::set_autoloaders(); |
|
| 79 | - parent::__construct($routing); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - |
|
| 83 | - protected function _init_page_props() |
|
| 84 | - { |
|
| 85 | - $this->page_slug = EE_MSG_PG_SLUG; |
|
| 86 | - $this->page_label = __('Messages Settings', 'event_espresso'); |
|
| 87 | - $this->_admin_base_url = EE_MSG_ADMIN_URL; |
|
| 88 | - $this->_admin_base_path = EE_MSG_ADMIN; |
|
| 89 | - |
|
| 90 | - $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array(); |
|
| 91 | - |
|
| 92 | - $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null; |
|
| 93 | - $this->_load_message_resource_manager(); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * loads messenger objects into the $_active_messengers property (so we can access the needed methods) |
|
| 99 | - * |
|
| 100 | - * |
|
| 101 | - * @throws EE_Error |
|
| 102 | - */ |
|
| 103 | - protected function _load_message_resource_manager() |
|
| 104 | - { |
|
| 105 | - $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @deprecated 4.9.9.rc.014 |
|
| 111 | - * @return array |
|
| 112 | - */ |
|
| 113 | - public function get_messengers_for_list_table() |
|
| 114 | - { |
|
| 115 | - EE_Error::doing_it_wrong( |
|
| 116 | - __METHOD__, |
|
| 117 | - __('This method is no longer in use. There is no replacement for it. The method was used to generate a set of |
|
| 20 | + /** |
|
| 21 | + * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 22 | + */ |
|
| 23 | + protected $_message_resource_manager; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @type string $_active_message_type_name |
|
| 27 | + */ |
|
| 28 | + protected $_active_message_type_name = ''; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @type EE_messenger $_active_messenger |
|
| 32 | + */ |
|
| 33 | + protected $_active_messenger; |
|
| 34 | + protected $_activate_state; |
|
| 35 | + protected $_activate_meta_box_type; |
|
| 36 | + protected $_current_message_meta_box; |
|
| 37 | + protected $_current_message_meta_box_object; |
|
| 38 | + protected $_context_switcher; |
|
| 39 | + protected $_shortcodes = array(); |
|
| 40 | + protected $_active_messengers = array(); |
|
| 41 | + protected $_active_message_types = array(); |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @var EE_Message_Template_Group $_message_template_group |
|
| 45 | + */ |
|
| 46 | + protected $_message_template_group; |
|
| 47 | + protected $_m_mt_settings = array(); |
|
| 48 | + |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * This is set via the _set_message_template_group method and holds whatever the template pack for the group is. |
|
| 52 | + * IF there is no group then it gets automatically set to the Default template pack. |
|
| 53 | + * |
|
| 54 | + * @since 4.5.0 |
|
| 55 | + * |
|
| 56 | + * @var EE_Messages_Template_Pack |
|
| 57 | + */ |
|
| 58 | + protected $_template_pack; |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * This is set via the _set_message_template_group method and holds whatever the template pack variation for the |
|
| 63 | + * group is. If there is no group then it automatically gets set to default. |
|
| 64 | + * |
|
| 65 | + * @since 4.5.0 |
|
| 66 | + * |
|
| 67 | + * @var string |
|
| 68 | + */ |
|
| 69 | + protected $_variation; |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @param bool $routing |
|
| 74 | + */ |
|
| 75 | + public function __construct($routing = true) |
|
| 76 | + { |
|
| 77 | + //make sure messages autoloader is running |
|
| 78 | + EED_Messages::set_autoloaders(); |
|
| 79 | + parent::__construct($routing); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + |
|
| 83 | + protected function _init_page_props() |
|
| 84 | + { |
|
| 85 | + $this->page_slug = EE_MSG_PG_SLUG; |
|
| 86 | + $this->page_label = __('Messages Settings', 'event_espresso'); |
|
| 87 | + $this->_admin_base_url = EE_MSG_ADMIN_URL; |
|
| 88 | + $this->_admin_base_path = EE_MSG_ADMIN; |
|
| 89 | + |
|
| 90 | + $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array(); |
|
| 91 | + |
|
| 92 | + $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null; |
|
| 93 | + $this->_load_message_resource_manager(); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * loads messenger objects into the $_active_messengers property (so we can access the needed methods) |
|
| 99 | + * |
|
| 100 | + * |
|
| 101 | + * @throws EE_Error |
|
| 102 | + */ |
|
| 103 | + protected function _load_message_resource_manager() |
|
| 104 | + { |
|
| 105 | + $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @deprecated 4.9.9.rc.014 |
|
| 111 | + * @return array |
|
| 112 | + */ |
|
| 113 | + public function get_messengers_for_list_table() |
|
| 114 | + { |
|
| 115 | + EE_Error::doing_it_wrong( |
|
| 116 | + __METHOD__, |
|
| 117 | + __('This method is no longer in use. There is no replacement for it. The method was used to generate a set of |
|
| 118 | 118 | values for use in creating a messenger filter dropdown which is now generated differently via |
| 119 | 119 | Messages_Admin_Page::get_messengers_select_input', 'event_espresso'), |
| 120 | - '4.9.9.rc.014' |
|
| 121 | - ); |
|
| 122 | - |
|
| 123 | - $m_values = array(); |
|
| 124 | - $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger')); |
|
| 125 | - //setup messengers for selects |
|
| 126 | - $i = 1; |
|
| 127 | - foreach ($active_messengers as $active_messenger) { |
|
| 128 | - if ($active_messenger instanceof EE_Message) { |
|
| 129 | - $m_values[$i]['id'] = $active_messenger->messenger(); |
|
| 130 | - $m_values[$i]['text'] = ucwords($active_messenger->messenger_label()); |
|
| 131 | - $i++; |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - return $m_values; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @deprecated 4.9.9.rc.014 |
|
| 141 | - * @return array |
|
| 142 | - */ |
|
| 143 | - public function get_message_types_for_list_table() |
|
| 144 | - { |
|
| 145 | - EE_Error::doing_it_wrong( |
|
| 146 | - __METHOD__, |
|
| 147 | - __('This method is no longer in use. There is no replacement for it. The method was used to generate a set of |
|
| 120 | + '4.9.9.rc.014' |
|
| 121 | + ); |
|
| 122 | + |
|
| 123 | + $m_values = array(); |
|
| 124 | + $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger')); |
|
| 125 | + //setup messengers for selects |
|
| 126 | + $i = 1; |
|
| 127 | + foreach ($active_messengers as $active_messenger) { |
|
| 128 | + if ($active_messenger instanceof EE_Message) { |
|
| 129 | + $m_values[$i]['id'] = $active_messenger->messenger(); |
|
| 130 | + $m_values[$i]['text'] = ucwords($active_messenger->messenger_label()); |
|
| 131 | + $i++; |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + return $m_values; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @deprecated 4.9.9.rc.014 |
|
| 141 | + * @return array |
|
| 142 | + */ |
|
| 143 | + public function get_message_types_for_list_table() |
|
| 144 | + { |
|
| 145 | + EE_Error::doing_it_wrong( |
|
| 146 | + __METHOD__, |
|
| 147 | + __('This method is no longer in use. There is no replacement for it. The method was used to generate a set of |
|
| 148 | 148 | values for use in creating a message type filter dropdown which is now generated differently via |
| 149 | 149 | Messages_Admin_Page::get_message_types_select_input', 'event_espresso'), |
| 150 | - '4.9.9.rc.014' |
|
| 151 | - ); |
|
| 152 | - |
|
| 153 | - $mt_values = array(); |
|
| 154 | - $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type')); |
|
| 155 | - $i = 1; |
|
| 156 | - foreach ($active_messages as $active_message) { |
|
| 157 | - if ($active_message instanceof EE_Message) { |
|
| 158 | - $mt_values[$i]['id'] = $active_message->message_type(); |
|
| 159 | - $mt_values[$i]['text'] = ucwords($active_message->message_type_label()); |
|
| 160 | - $i++; |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - return $mt_values; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * @deprecated 4.9.9.rc.014 |
|
| 170 | - * @return array |
|
| 171 | - */ |
|
| 172 | - public function get_contexts_for_message_types_for_list_table() |
|
| 173 | - { |
|
| 174 | - EE_Error::doing_it_wrong( |
|
| 175 | - __METHOD__, |
|
| 176 | - __('This method is no longer in use. There is no replacement for it. The method was used to generate a set of |
|
| 150 | + '4.9.9.rc.014' |
|
| 151 | + ); |
|
| 152 | + |
|
| 153 | + $mt_values = array(); |
|
| 154 | + $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type')); |
|
| 155 | + $i = 1; |
|
| 156 | + foreach ($active_messages as $active_message) { |
|
| 157 | + if ($active_message instanceof EE_Message) { |
|
| 158 | + $mt_values[$i]['id'] = $active_message->message_type(); |
|
| 159 | + $mt_values[$i]['text'] = ucwords($active_message->message_type_label()); |
|
| 160 | + $i++; |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + return $mt_values; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * @deprecated 4.9.9.rc.014 |
|
| 170 | + * @return array |
|
| 171 | + */ |
|
| 172 | + public function get_contexts_for_message_types_for_list_table() |
|
| 173 | + { |
|
| 174 | + EE_Error::doing_it_wrong( |
|
| 175 | + __METHOD__, |
|
| 176 | + __('This method is no longer in use. There is no replacement for it. The method was used to generate a set of |
|
| 177 | 177 | values for use in creating a message type context filter dropdown which is now generated differently via |
| 178 | 178 | Messages_Admin_Page::get_contexts_for_message_types_select_input', 'event_espresso'), |
| 179 | - '4.9.9.rc.014' |
|
| 180 | - ); |
|
| 181 | - |
|
| 182 | - $contexts = array(); |
|
| 183 | - $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context')); |
|
| 184 | - foreach ($active_message_contexts as $active_message) { |
|
| 185 | - if ($active_message instanceof EE_Message) { |
|
| 186 | - $message_type = $active_message->message_type_object(); |
|
| 187 | - if ($message_type instanceof EE_message_type) { |
|
| 188 | - $message_type_contexts = $message_type->get_contexts(); |
|
| 189 | - foreach ($message_type_contexts as $context => $context_details) { |
|
| 190 | - $contexts[$context] = $context_details['label']; |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - return $contexts; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * Generate select input with provided messenger options array. |
|
| 202 | - * |
|
| 203 | - * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger |
|
| 204 | - * labels. |
|
| 205 | - * |
|
| 206 | - * @return string |
|
| 207 | - */ |
|
| 208 | - public function get_messengers_select_input($messenger_options) |
|
| 209 | - { |
|
| 210 | - //if empty or just one value then just return an empty string |
|
| 211 | - if (empty($messenger_options) |
|
| 212 | - || ! is_array($messenger_options) |
|
| 213 | - || count($messenger_options) === 1 |
|
| 214 | - ) { |
|
| 215 | - return ''; |
|
| 216 | - } |
|
| 217 | - //merge in default |
|
| 218 | - $messenger_options = array_merge( |
|
| 219 | - array('none_selected' => __('Show All Messengers', 'event_espresso')), |
|
| 220 | - $messenger_options |
|
| 221 | - ); |
|
| 222 | - $input = new EE_Select_Input( |
|
| 223 | - $messenger_options, |
|
| 224 | - array( |
|
| 225 | - 'html_name' => 'ee_messenger_filter_by', |
|
| 226 | - 'html_id' => 'ee_messenger_filter_by', |
|
| 227 | - 'html_class' => 'wide', |
|
| 228 | - 'default' => isset($this->_req_data['ee_messenger_filter_by']) |
|
| 229 | - ? sanitize_title($this->_req_data['ee_messenger_filter_by']) |
|
| 230 | - : 'none_selected' |
|
| 231 | - ) |
|
| 232 | - ); |
|
| 233 | - |
|
| 234 | - return $input->get_html_for_input(); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * Generate select input with provided message type options array. |
|
| 240 | - * |
|
| 241 | - * @param array $message_type_options Array of message types indexed by message type slug, and values are the |
|
| 242 | - * message type labels |
|
| 243 | - * |
|
| 244 | - * @return string |
|
| 245 | - */ |
|
| 246 | - public function get_message_types_select_input($message_type_options) |
|
| 247 | - { |
|
| 248 | - //if empty or count of options is 1 then just return an empty string |
|
| 249 | - if (empty($message_type_options) |
|
| 250 | - || ! is_array($message_type_options) |
|
| 251 | - || count($message_type_options) === 1 |
|
| 252 | - ) { |
|
| 253 | - return ''; |
|
| 254 | - } |
|
| 255 | - //merge in default |
|
| 256 | - $message_type_options = array_merge( |
|
| 257 | - array('none_selected' => __('Show All Message Types', 'event_espresso')), |
|
| 258 | - $message_type_options |
|
| 259 | - ); |
|
| 260 | - $input = new EE_Select_Input( |
|
| 261 | - $message_type_options, |
|
| 262 | - array( |
|
| 263 | - 'html_name' => 'ee_message_type_filter_by', |
|
| 264 | - 'html_id' => 'ee_message_type_filter_by', |
|
| 265 | - 'html_class' => 'wide', |
|
| 266 | - 'default' => isset($this->_req_data['ee_message_type_filter_by']) |
|
| 267 | - ? sanitize_title($this->_req_data['ee_message_type_filter_by']) |
|
| 268 | - : 'none_selected', |
|
| 269 | - ) |
|
| 270 | - ); |
|
| 271 | - |
|
| 272 | - return $input->get_html_for_input(); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * Generate select input with provide message type contexts array. |
|
| 278 | - * |
|
| 279 | - * @param array $context_options Array of message type contexts indexed by context slug, and values are the |
|
| 280 | - * context label. |
|
| 281 | - * |
|
| 282 | - * @return string |
|
| 283 | - */ |
|
| 284 | - public function get_contexts_for_message_types_select_input($context_options) |
|
| 285 | - { |
|
| 286 | - //if empty or count of options is one then just return empty string |
|
| 287 | - if (empty($context_options) |
|
| 288 | - || ! is_array($context_options) |
|
| 289 | - || count($context_options) === 1 |
|
| 290 | - ) { |
|
| 291 | - return ''; |
|
| 292 | - } |
|
| 293 | - //merge in default |
|
| 294 | - $context_options = array_merge( |
|
| 295 | - array('none_selected' => __('Show all Contexts', 'event_espresso')), |
|
| 296 | - $context_options |
|
| 297 | - ); |
|
| 298 | - $input = new EE_Select_Input( |
|
| 299 | - $context_options, |
|
| 300 | - array( |
|
| 301 | - 'html_name' => 'ee_context_filter_by', |
|
| 302 | - 'html_id' => 'ee_context_filter_by', |
|
| 303 | - 'html_class' => 'wide', |
|
| 304 | - 'default' => isset($this->_req_data['ee_context_filter_by']) |
|
| 305 | - ? sanitize_title($this->_req_data['ee_context_filter_by']) |
|
| 306 | - : 'none_selected', |
|
| 307 | - ) |
|
| 308 | - ); |
|
| 309 | - |
|
| 310 | - return $input->get_html_for_input(); |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - |
|
| 314 | - protected function _ajax_hooks() |
|
| 315 | - { |
|
| 316 | - add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle')); |
|
| 317 | - add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle')); |
|
| 318 | - add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings')); |
|
| 319 | - add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form')); |
|
| 320 | - add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack')); |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - |
|
| 324 | - protected function _define_page_props() |
|
| 325 | - { |
|
| 326 | - $this->_admin_page_title = $this->page_label; |
|
| 327 | - $this->_labels = array( |
|
| 328 | - 'buttons' => array( |
|
| 329 | - 'add' => __('Add New Message Template', 'event_espresso'), |
|
| 330 | - 'edit' => __('Edit Message Template', 'event_espresso'), |
|
| 331 | - 'delete' => __('Delete Message Template', 'event_espresso') |
|
| 332 | - ), |
|
| 333 | - 'publishbox' => __('Update Actions', 'event_espresso') |
|
| 334 | - ); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - |
|
| 338 | - /** |
|
| 339 | - * an array for storing key => value pairs of request actions and their corresponding methods |
|
| 340 | - * @access protected |
|
| 341 | - * @return void |
|
| 342 | - */ |
|
| 343 | - protected function _set_page_routes() |
|
| 344 | - { |
|
| 345 | - $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID']) |
|
| 346 | - ? $this->_req_data['GRP_ID'] |
|
| 347 | - : 0; |
|
| 348 | - $grp_id = empty($grp_id) && ! empty($this->_req_data['id']) |
|
| 349 | - ? $this->_req_data['id'] |
|
| 350 | - : $grp_id; |
|
| 351 | - $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID']) |
|
| 352 | - ? $this->_req_data['MSG_ID'] |
|
| 353 | - : 0; |
|
| 354 | - |
|
| 355 | - $this->_page_routes = array( |
|
| 356 | - 'default' => array( |
|
| 357 | - 'func' => '_message_queue_list_table', |
|
| 358 | - 'capability' => 'ee_read_global_messages' |
|
| 359 | - ), |
|
| 360 | - 'global_mtps' => array( |
|
| 361 | - 'func' => '_ee_default_messages_overview_list_table', |
|
| 362 | - 'capability' => 'ee_read_global_messages' |
|
| 363 | - ), |
|
| 364 | - 'custom_mtps' => array( |
|
| 365 | - 'func' => '_custom_mtps_preview', |
|
| 366 | - 'capability' => 'ee_read_messages' |
|
| 367 | - ), |
|
| 368 | - 'add_new_message_template' => array( |
|
| 369 | - 'func' => '_add_message_template', |
|
| 370 | - 'capability' => 'ee_edit_messages', |
|
| 371 | - 'noheader' => true |
|
| 372 | - ), |
|
| 373 | - 'edit_message_template' => array( |
|
| 374 | - 'func' => '_edit_message_template', |
|
| 375 | - 'capability' => 'ee_edit_message', |
|
| 376 | - 'obj_id' => $grp_id |
|
| 377 | - ), |
|
| 378 | - 'preview_message' => array( |
|
| 379 | - 'func' => '_preview_message', |
|
| 380 | - 'capability' => 'ee_read_message', |
|
| 381 | - 'obj_id' => $grp_id, |
|
| 382 | - 'noheader' => true, |
|
| 383 | - 'headers_sent_route' => 'display_preview_message' |
|
| 384 | - ), |
|
| 385 | - 'display_preview_message' => array( |
|
| 386 | - 'func' => '_display_preview_message', |
|
| 387 | - 'capability' => 'ee_read_message', |
|
| 388 | - 'obj_id' => $grp_id |
|
| 389 | - ), |
|
| 390 | - 'insert_message_template' => array( |
|
| 391 | - 'func' => '_insert_or_update_message_template', |
|
| 392 | - 'capability' => 'ee_edit_messages', |
|
| 393 | - 'args' => array('new_template' => true), |
|
| 394 | - 'noheader' => true |
|
| 395 | - ), |
|
| 396 | - 'update_message_template' => array( |
|
| 397 | - 'func' => '_insert_or_update_message_template', |
|
| 398 | - 'capability' => 'ee_edit_message', |
|
| 399 | - 'obj_id' => $grp_id, |
|
| 400 | - 'args' => array('new_template' => false), |
|
| 401 | - 'noheader' => true |
|
| 402 | - ), |
|
| 403 | - 'trash_message_template' => array( |
|
| 404 | - 'func' => '_trash_or_restore_message_template', |
|
| 405 | - 'capability' => 'ee_delete_message', |
|
| 406 | - 'obj_id' => $grp_id, |
|
| 407 | - 'args' => array('trash' => true, 'all' => true), |
|
| 408 | - 'noheader' => true |
|
| 409 | - ), |
|
| 410 | - 'trash_message_template_context' => array( |
|
| 411 | - 'func' => '_trash_or_restore_message_template', |
|
| 412 | - 'capability' => 'ee_delete_message', |
|
| 413 | - 'obj_id' => $grp_id, |
|
| 414 | - 'args' => array('trash' => true), |
|
| 415 | - 'noheader' => true |
|
| 416 | - ), |
|
| 417 | - 'restore_message_template' => array( |
|
| 418 | - 'func' => '_trash_or_restore_message_template', |
|
| 419 | - 'capability' => 'ee_delete_message', |
|
| 420 | - 'obj_id' => $grp_id, |
|
| 421 | - 'args' => array('trash' => false, 'all' => true), |
|
| 422 | - 'noheader' => true |
|
| 423 | - ), |
|
| 424 | - 'restore_message_template_context' => array( |
|
| 425 | - 'func' => '_trash_or_restore_message_template', |
|
| 426 | - 'capability' => 'ee_delete_message', |
|
| 427 | - 'obj_id' => $grp_id, |
|
| 428 | - 'args' => array('trash' => false), |
|
| 429 | - 'noheader' => true |
|
| 430 | - ), |
|
| 431 | - 'delete_message_template' => array( |
|
| 432 | - 'func' => '_delete_message_template', |
|
| 433 | - 'capability' => 'ee_delete_message', |
|
| 434 | - 'obj_id' => $grp_id, |
|
| 435 | - 'noheader' => true |
|
| 436 | - ), |
|
| 437 | - 'reset_to_default' => array( |
|
| 438 | - 'func' => '_reset_to_default_template', |
|
| 439 | - 'capability' => 'ee_edit_message', |
|
| 440 | - 'obj_id' => $grp_id, |
|
| 441 | - 'noheader' => true |
|
| 442 | - ), |
|
| 443 | - 'settings' => array( |
|
| 444 | - 'func' => '_settings', |
|
| 445 | - 'capability' => 'manage_options' |
|
| 446 | - ), |
|
| 447 | - 'update_global_settings' => array( |
|
| 448 | - 'func' => '_update_global_settings', |
|
| 449 | - 'capability' => 'manage_options', |
|
| 450 | - 'noheader' => true |
|
| 451 | - ), |
|
| 452 | - 'generate_now' => array( |
|
| 453 | - 'func' => '_generate_now', |
|
| 454 | - 'capability' => 'ee_send_message', |
|
| 455 | - 'noheader' => true |
|
| 456 | - ), |
|
| 457 | - 'generate_and_send_now' => array( |
|
| 458 | - 'func' => '_generate_and_send_now', |
|
| 459 | - 'capability' => 'ee_send_message', |
|
| 460 | - 'noheader' => true |
|
| 461 | - ), |
|
| 462 | - 'queue_for_resending' => array( |
|
| 463 | - 'func' => '_queue_for_resending', |
|
| 464 | - 'capability' => 'ee_send_message', |
|
| 465 | - 'noheader' => true |
|
| 466 | - ), |
|
| 467 | - 'send_now' => array( |
|
| 468 | - 'func' => '_send_now', |
|
| 469 | - 'capability' => 'ee_send_message', |
|
| 470 | - 'noheader' => true |
|
| 471 | - ), |
|
| 472 | - 'delete_ee_message' => array( |
|
| 473 | - 'func' => '_delete_ee_messages', |
|
| 474 | - 'capability' => 'ee_delete_messages', |
|
| 475 | - 'noheader' => true |
|
| 476 | - ), |
|
| 477 | - 'delete_ee_messages' => array( |
|
| 478 | - 'func' => '_delete_ee_messages', |
|
| 479 | - 'capability' => 'ee_delete_messages', |
|
| 480 | - 'noheader' => true, |
|
| 481 | - 'obj_id' => $msg_id |
|
| 482 | - ) |
|
| 483 | - ); |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - |
|
| 487 | - protected function _set_page_config() |
|
| 488 | - { |
|
| 489 | - $this->_page_config = array( |
|
| 490 | - 'default' => array( |
|
| 491 | - 'nav' => array( |
|
| 492 | - 'label' => __('Message Activity', 'event_espresso'), |
|
| 493 | - 'order' => 10 |
|
| 494 | - ), |
|
| 495 | - 'list_table' => 'EE_Message_List_Table', |
|
| 496 | - // 'qtips' => array( 'EE_Message_List_Table_Tips' ), |
|
| 497 | - 'require_nonce' => false |
|
| 498 | - ), |
|
| 499 | - 'global_mtps' => array( |
|
| 500 | - 'nav' => array( |
|
| 501 | - 'label' => __('Default Message Templates', 'event_espresso'), |
|
| 502 | - 'order' => 20 |
|
| 503 | - ), |
|
| 504 | - 'list_table' => 'Messages_Template_List_Table', |
|
| 505 | - 'help_tabs' => array( |
|
| 506 | - 'messages_overview_help_tab' => array( |
|
| 507 | - 'title' => __('Messages Overview', 'event_espresso'), |
|
| 508 | - 'filename' => 'messages_overview' |
|
| 509 | - ), |
|
| 510 | - 'messages_overview_messages_table_column_headings_help_tab' => array( |
|
| 511 | - 'title' => __('Messages Table Column Headings', 'event_espresso'), |
|
| 512 | - 'filename' => 'messages_overview_table_column_headings' |
|
| 513 | - ), |
|
| 514 | - 'messages_overview_messages_filters_help_tab' => array( |
|
| 515 | - 'title' => __('Message Filters', 'event_espresso'), |
|
| 516 | - 'filename' => 'messages_overview_filters' |
|
| 517 | - ), |
|
| 518 | - 'messages_overview_messages_views_help_tab' => array( |
|
| 519 | - 'title' => __('Message Views', 'event_espresso'), |
|
| 520 | - 'filename' => 'messages_overview_views' |
|
| 521 | - ), |
|
| 522 | - 'message_overview_message_types_help_tab' => array( |
|
| 523 | - 'title' => __('Message Types', 'event_espresso'), |
|
| 524 | - 'filename' => 'messages_overview_types' |
|
| 525 | - ), |
|
| 526 | - 'messages_overview_messengers_help_tab' => array( |
|
| 527 | - 'title' => __('Messengers', 'event_espresso'), |
|
| 528 | - 'filename' => 'messages_overview_messengers', |
|
| 529 | - ), |
|
| 530 | - ), |
|
| 531 | - 'help_tour' => array('Messages_Overview_Help_Tour'), |
|
| 532 | - 'require_nonce' => false |
|
| 533 | - ), |
|
| 534 | - 'custom_mtps' => array( |
|
| 535 | - 'nav' => array( |
|
| 536 | - 'label' => __('Custom Message Templates', 'event_espresso'), |
|
| 537 | - 'order' => 30 |
|
| 538 | - ), |
|
| 539 | - 'help_tabs' => array(), |
|
| 540 | - 'help_tour' => array(), |
|
| 541 | - 'require_nonce' => false |
|
| 542 | - ), |
|
| 543 | - 'add_new_message_template' => array( |
|
| 544 | - 'nav' => array( |
|
| 545 | - 'label' => __('Add New Message Templates', 'event_espresso'), |
|
| 546 | - 'order' => 5, |
|
| 547 | - 'persistent' => false |
|
| 548 | - ), |
|
| 549 | - 'require_nonce' => false |
|
| 550 | - ), |
|
| 551 | - 'edit_message_template' => array( |
|
| 552 | - 'labels' => array( |
|
| 553 | - 'buttons' => array( |
|
| 554 | - 'reset' => __('Reset Templates'), |
|
| 555 | - ), |
|
| 556 | - 'publishbox' => __('Update Actions', 'event_espresso') |
|
| 557 | - ), |
|
| 558 | - 'nav' => array( |
|
| 559 | - 'label' => __('Edit Message Templates', 'event_espresso'), |
|
| 560 | - 'order' => 5, |
|
| 561 | - 'persistent' => false, |
|
| 562 | - 'url' => '' |
|
| 563 | - ), |
|
| 564 | - 'metaboxes' => array('_publish_post_box', '_register_edit_meta_boxes'), |
|
| 565 | - 'has_metaboxes' => true, |
|
| 566 | - 'help_tour' => array('Message_Templates_Edit_Help_Tour'), |
|
| 567 | - 'help_tabs' => array( |
|
| 568 | - 'edit_message_template' => array( |
|
| 569 | - 'title' => __('Message Template Editor', 'event_espresso'), |
|
| 570 | - 'callback' => 'edit_message_template_help_tab' |
|
| 571 | - ), |
|
| 572 | - 'message_templates_help_tab' => array( |
|
| 573 | - 'title' => __('Message Templates', 'event_espresso'), |
|
| 574 | - 'filename' => 'messages_templates' |
|
| 575 | - ), |
|
| 576 | - 'message_template_shortcodes' => array( |
|
| 577 | - 'title' => __('Message Shortcodes', 'event_espresso'), |
|
| 578 | - 'callback' => 'message_template_shortcodes_help_tab' |
|
| 579 | - ), |
|
| 580 | - 'message_preview_help_tab' => array( |
|
| 581 | - 'title' => __('Message Preview', 'event_espresso'), |
|
| 582 | - 'filename' => 'messages_preview' |
|
| 583 | - ), |
|
| 584 | - 'messages_overview_other_help_tab' => array( |
|
| 585 | - 'title' => __('Messages Other', 'event_espresso'), |
|
| 586 | - 'filename' => 'messages_overview_other', |
|
| 587 | - ), |
|
| 588 | - ), |
|
| 589 | - 'require_nonce' => false |
|
| 590 | - ), |
|
| 591 | - 'display_preview_message' => array( |
|
| 592 | - 'nav' => array( |
|
| 593 | - 'label' => __('Message Preview', 'event_espresso'), |
|
| 594 | - 'order' => 5, |
|
| 595 | - 'url' => '', |
|
| 596 | - 'persistent' => false |
|
| 597 | - ), |
|
| 598 | - 'help_tabs' => array( |
|
| 599 | - 'preview_message' => array( |
|
| 600 | - 'title' => __('About Previews', 'event_espresso'), |
|
| 601 | - 'callback' => 'preview_message_help_tab' |
|
| 602 | - ) |
|
| 603 | - ), |
|
| 604 | - 'require_nonce' => false |
|
| 605 | - ), |
|
| 606 | - 'settings' => array( |
|
| 607 | - 'nav' => array( |
|
| 608 | - 'label' => __('Settings', 'event_espresso'), |
|
| 609 | - 'order' => 40 |
|
| 610 | - ), |
|
| 611 | - 'metaboxes' => array('_messages_settings_metaboxes'), |
|
| 612 | - 'help_tabs' => array( |
|
| 613 | - 'messages_settings_help_tab' => array( |
|
| 614 | - 'title' => __('Messages Settings', 'event_espresso'), |
|
| 615 | - 'filename' => 'messages_settings' |
|
| 616 | - ), |
|
| 617 | - 'messages_settings_message_types_help_tab' => array( |
|
| 618 | - 'title' => __('Activating / Deactivating Message Types', 'event_espresso'), |
|
| 619 | - 'filename' => 'messages_settings_message_types' |
|
| 620 | - ), |
|
| 621 | - 'messages_settings_messengers_help_tab' => array( |
|
| 622 | - 'title' => __('Activating / Deactivating Messengers', 'event_espresso'), |
|
| 623 | - 'filename' => 'messages_settings_messengers' |
|
| 624 | - ), |
|
| 625 | - ), |
|
| 626 | - 'help_tour' => array('Messages_Settings_Help_Tour'), |
|
| 627 | - 'require_nonce' => false |
|
| 628 | - ) |
|
| 629 | - ); |
|
| 630 | - } |
|
| 631 | - |
|
| 632 | - |
|
| 633 | - protected function _add_screen_options() |
|
| 634 | - { |
|
| 635 | - //todo |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - |
|
| 639 | - protected function _add_screen_options_global_mtps() |
|
| 640 | - { |
|
| 641 | - /** |
|
| 642 | - * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options |
|
| 643 | - * uses the $_admin_page_title property and we want different outputs in the different spots. |
|
| 644 | - */ |
|
| 645 | - $page_title = $this->_admin_page_title; |
|
| 646 | - $this->_admin_page_title = __('Global Message Templates', 'event_espresso'); |
|
| 647 | - $this->_per_page_screen_option(); |
|
| 648 | - $this->_admin_page_title = $page_title; |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - |
|
| 652 | - protected function _add_screen_options_default() |
|
| 653 | - { |
|
| 654 | - $this->_admin_page_title = __('Message Activity', 'event_espresso'); |
|
| 655 | - $this->_per_page_screen_option(); |
|
| 656 | - } |
|
| 657 | - |
|
| 658 | - |
|
| 659 | - //none of the below group are currently used for Messages |
|
| 660 | - protected function _add_feature_pointers() |
|
| 661 | - { |
|
| 662 | - } |
|
| 663 | - |
|
| 664 | - public function admin_init() |
|
| 665 | - { |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - public function admin_notices() |
|
| 669 | - { |
|
| 670 | - } |
|
| 671 | - |
|
| 672 | - public function admin_footer_scripts() |
|
| 673 | - { |
|
| 674 | - } |
|
| 675 | - |
|
| 676 | - |
|
| 677 | - public function messages_help_tab() |
|
| 678 | - { |
|
| 679 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php'); |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - |
|
| 683 | - public function messengers_help_tab() |
|
| 684 | - { |
|
| 685 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php'); |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - |
|
| 689 | - public function message_types_help_tab() |
|
| 690 | - { |
|
| 691 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php'); |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - |
|
| 695 | - public function messages_overview_help_tab() |
|
| 696 | - { |
|
| 697 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php'); |
|
| 698 | - } |
|
| 699 | - |
|
| 700 | - |
|
| 701 | - public function message_templates_help_tab() |
|
| 702 | - { |
|
| 703 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php'); |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - |
|
| 707 | - public function edit_message_template_help_tab() |
|
| 708 | - { |
|
| 709 | - $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' . esc_attr__('Editor Title', |
|
| 710 | - 'event_espresso') . '" />'; |
|
| 711 | - $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' . esc_attr__('Context Switcher and Preview', |
|
| 712 | - 'event_espresso') . '" />'; |
|
| 713 | - $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' . esc_attr__('Message Template Form Fields', |
|
| 714 | - 'event_espresso') . '" />'; |
|
| 715 | - $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' . esc_attr__('Shortcodes Metabox', |
|
| 716 | - 'event_espresso') . '" />'; |
|
| 717 | - $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' . esc_attr__('Publish Metabox', |
|
| 718 | - 'event_espresso') . '" />'; |
|
| 719 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 720 | - $args); |
|
| 721 | - } |
|
| 722 | - |
|
| 723 | - |
|
| 724 | - public function message_template_shortcodes_help_tab() |
|
| 725 | - { |
|
| 726 | - $this->_set_shortcodes(); |
|
| 727 | - $args['shortcodes'] = $this->_shortcodes; |
|
| 728 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 729 | - $args); |
|
| 730 | - } |
|
| 179 | + '4.9.9.rc.014' |
|
| 180 | + ); |
|
| 181 | + |
|
| 182 | + $contexts = array(); |
|
| 183 | + $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context')); |
|
| 184 | + foreach ($active_message_contexts as $active_message) { |
|
| 185 | + if ($active_message instanceof EE_Message) { |
|
| 186 | + $message_type = $active_message->message_type_object(); |
|
| 187 | + if ($message_type instanceof EE_message_type) { |
|
| 188 | + $message_type_contexts = $message_type->get_contexts(); |
|
| 189 | + foreach ($message_type_contexts as $context => $context_details) { |
|
| 190 | + $contexts[$context] = $context_details['label']; |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + return $contexts; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * Generate select input with provided messenger options array. |
|
| 202 | + * |
|
| 203 | + * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger |
|
| 204 | + * labels. |
|
| 205 | + * |
|
| 206 | + * @return string |
|
| 207 | + */ |
|
| 208 | + public function get_messengers_select_input($messenger_options) |
|
| 209 | + { |
|
| 210 | + //if empty or just one value then just return an empty string |
|
| 211 | + if (empty($messenger_options) |
|
| 212 | + || ! is_array($messenger_options) |
|
| 213 | + || count($messenger_options) === 1 |
|
| 214 | + ) { |
|
| 215 | + return ''; |
|
| 216 | + } |
|
| 217 | + //merge in default |
|
| 218 | + $messenger_options = array_merge( |
|
| 219 | + array('none_selected' => __('Show All Messengers', 'event_espresso')), |
|
| 220 | + $messenger_options |
|
| 221 | + ); |
|
| 222 | + $input = new EE_Select_Input( |
|
| 223 | + $messenger_options, |
|
| 224 | + array( |
|
| 225 | + 'html_name' => 'ee_messenger_filter_by', |
|
| 226 | + 'html_id' => 'ee_messenger_filter_by', |
|
| 227 | + 'html_class' => 'wide', |
|
| 228 | + 'default' => isset($this->_req_data['ee_messenger_filter_by']) |
|
| 229 | + ? sanitize_title($this->_req_data['ee_messenger_filter_by']) |
|
| 230 | + : 'none_selected' |
|
| 231 | + ) |
|
| 232 | + ); |
|
| 233 | + |
|
| 234 | + return $input->get_html_for_input(); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * Generate select input with provided message type options array. |
|
| 240 | + * |
|
| 241 | + * @param array $message_type_options Array of message types indexed by message type slug, and values are the |
|
| 242 | + * message type labels |
|
| 243 | + * |
|
| 244 | + * @return string |
|
| 245 | + */ |
|
| 246 | + public function get_message_types_select_input($message_type_options) |
|
| 247 | + { |
|
| 248 | + //if empty or count of options is 1 then just return an empty string |
|
| 249 | + if (empty($message_type_options) |
|
| 250 | + || ! is_array($message_type_options) |
|
| 251 | + || count($message_type_options) === 1 |
|
| 252 | + ) { |
|
| 253 | + return ''; |
|
| 254 | + } |
|
| 255 | + //merge in default |
|
| 256 | + $message_type_options = array_merge( |
|
| 257 | + array('none_selected' => __('Show All Message Types', 'event_espresso')), |
|
| 258 | + $message_type_options |
|
| 259 | + ); |
|
| 260 | + $input = new EE_Select_Input( |
|
| 261 | + $message_type_options, |
|
| 262 | + array( |
|
| 263 | + 'html_name' => 'ee_message_type_filter_by', |
|
| 264 | + 'html_id' => 'ee_message_type_filter_by', |
|
| 265 | + 'html_class' => 'wide', |
|
| 266 | + 'default' => isset($this->_req_data['ee_message_type_filter_by']) |
|
| 267 | + ? sanitize_title($this->_req_data['ee_message_type_filter_by']) |
|
| 268 | + : 'none_selected', |
|
| 269 | + ) |
|
| 270 | + ); |
|
| 271 | + |
|
| 272 | + return $input->get_html_for_input(); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * Generate select input with provide message type contexts array. |
|
| 278 | + * |
|
| 279 | + * @param array $context_options Array of message type contexts indexed by context slug, and values are the |
|
| 280 | + * context label. |
|
| 281 | + * |
|
| 282 | + * @return string |
|
| 283 | + */ |
|
| 284 | + public function get_contexts_for_message_types_select_input($context_options) |
|
| 285 | + { |
|
| 286 | + //if empty or count of options is one then just return empty string |
|
| 287 | + if (empty($context_options) |
|
| 288 | + || ! is_array($context_options) |
|
| 289 | + || count($context_options) === 1 |
|
| 290 | + ) { |
|
| 291 | + return ''; |
|
| 292 | + } |
|
| 293 | + //merge in default |
|
| 294 | + $context_options = array_merge( |
|
| 295 | + array('none_selected' => __('Show all Contexts', 'event_espresso')), |
|
| 296 | + $context_options |
|
| 297 | + ); |
|
| 298 | + $input = new EE_Select_Input( |
|
| 299 | + $context_options, |
|
| 300 | + array( |
|
| 301 | + 'html_name' => 'ee_context_filter_by', |
|
| 302 | + 'html_id' => 'ee_context_filter_by', |
|
| 303 | + 'html_class' => 'wide', |
|
| 304 | + 'default' => isset($this->_req_data['ee_context_filter_by']) |
|
| 305 | + ? sanitize_title($this->_req_data['ee_context_filter_by']) |
|
| 306 | + : 'none_selected', |
|
| 307 | + ) |
|
| 308 | + ); |
|
| 309 | + |
|
| 310 | + return $input->get_html_for_input(); |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + |
|
| 314 | + protected function _ajax_hooks() |
|
| 315 | + { |
|
| 316 | + add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle')); |
|
| 317 | + add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle')); |
|
| 318 | + add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings')); |
|
| 319 | + add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form')); |
|
| 320 | + add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack')); |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + |
|
| 324 | + protected function _define_page_props() |
|
| 325 | + { |
|
| 326 | + $this->_admin_page_title = $this->page_label; |
|
| 327 | + $this->_labels = array( |
|
| 328 | + 'buttons' => array( |
|
| 329 | + 'add' => __('Add New Message Template', 'event_espresso'), |
|
| 330 | + 'edit' => __('Edit Message Template', 'event_espresso'), |
|
| 331 | + 'delete' => __('Delete Message Template', 'event_espresso') |
|
| 332 | + ), |
|
| 333 | + 'publishbox' => __('Update Actions', 'event_espresso') |
|
| 334 | + ); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + |
|
| 338 | + /** |
|
| 339 | + * an array for storing key => value pairs of request actions and their corresponding methods |
|
| 340 | + * @access protected |
|
| 341 | + * @return void |
|
| 342 | + */ |
|
| 343 | + protected function _set_page_routes() |
|
| 344 | + { |
|
| 345 | + $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID']) |
|
| 346 | + ? $this->_req_data['GRP_ID'] |
|
| 347 | + : 0; |
|
| 348 | + $grp_id = empty($grp_id) && ! empty($this->_req_data['id']) |
|
| 349 | + ? $this->_req_data['id'] |
|
| 350 | + : $grp_id; |
|
| 351 | + $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID']) |
|
| 352 | + ? $this->_req_data['MSG_ID'] |
|
| 353 | + : 0; |
|
| 354 | + |
|
| 355 | + $this->_page_routes = array( |
|
| 356 | + 'default' => array( |
|
| 357 | + 'func' => '_message_queue_list_table', |
|
| 358 | + 'capability' => 'ee_read_global_messages' |
|
| 359 | + ), |
|
| 360 | + 'global_mtps' => array( |
|
| 361 | + 'func' => '_ee_default_messages_overview_list_table', |
|
| 362 | + 'capability' => 'ee_read_global_messages' |
|
| 363 | + ), |
|
| 364 | + 'custom_mtps' => array( |
|
| 365 | + 'func' => '_custom_mtps_preview', |
|
| 366 | + 'capability' => 'ee_read_messages' |
|
| 367 | + ), |
|
| 368 | + 'add_new_message_template' => array( |
|
| 369 | + 'func' => '_add_message_template', |
|
| 370 | + 'capability' => 'ee_edit_messages', |
|
| 371 | + 'noheader' => true |
|
| 372 | + ), |
|
| 373 | + 'edit_message_template' => array( |
|
| 374 | + 'func' => '_edit_message_template', |
|
| 375 | + 'capability' => 'ee_edit_message', |
|
| 376 | + 'obj_id' => $grp_id |
|
| 377 | + ), |
|
| 378 | + 'preview_message' => array( |
|
| 379 | + 'func' => '_preview_message', |
|
| 380 | + 'capability' => 'ee_read_message', |
|
| 381 | + 'obj_id' => $grp_id, |
|
| 382 | + 'noheader' => true, |
|
| 383 | + 'headers_sent_route' => 'display_preview_message' |
|
| 384 | + ), |
|
| 385 | + 'display_preview_message' => array( |
|
| 386 | + 'func' => '_display_preview_message', |
|
| 387 | + 'capability' => 'ee_read_message', |
|
| 388 | + 'obj_id' => $grp_id |
|
| 389 | + ), |
|
| 390 | + 'insert_message_template' => array( |
|
| 391 | + 'func' => '_insert_or_update_message_template', |
|
| 392 | + 'capability' => 'ee_edit_messages', |
|
| 393 | + 'args' => array('new_template' => true), |
|
| 394 | + 'noheader' => true |
|
| 395 | + ), |
|
| 396 | + 'update_message_template' => array( |
|
| 397 | + 'func' => '_insert_or_update_message_template', |
|
| 398 | + 'capability' => 'ee_edit_message', |
|
| 399 | + 'obj_id' => $grp_id, |
|
| 400 | + 'args' => array('new_template' => false), |
|
| 401 | + 'noheader' => true |
|
| 402 | + ), |
|
| 403 | + 'trash_message_template' => array( |
|
| 404 | + 'func' => '_trash_or_restore_message_template', |
|
| 405 | + 'capability' => 'ee_delete_message', |
|
| 406 | + 'obj_id' => $grp_id, |
|
| 407 | + 'args' => array('trash' => true, 'all' => true), |
|
| 408 | + 'noheader' => true |
|
| 409 | + ), |
|
| 410 | + 'trash_message_template_context' => array( |
|
| 411 | + 'func' => '_trash_or_restore_message_template', |
|
| 412 | + 'capability' => 'ee_delete_message', |
|
| 413 | + 'obj_id' => $grp_id, |
|
| 414 | + 'args' => array('trash' => true), |
|
| 415 | + 'noheader' => true |
|
| 416 | + ), |
|
| 417 | + 'restore_message_template' => array( |
|
| 418 | + 'func' => '_trash_or_restore_message_template', |
|
| 419 | + 'capability' => 'ee_delete_message', |
|
| 420 | + 'obj_id' => $grp_id, |
|
| 421 | + 'args' => array('trash' => false, 'all' => true), |
|
| 422 | + 'noheader' => true |
|
| 423 | + ), |
|
| 424 | + 'restore_message_template_context' => array( |
|
| 425 | + 'func' => '_trash_or_restore_message_template', |
|
| 426 | + 'capability' => 'ee_delete_message', |
|
| 427 | + 'obj_id' => $grp_id, |
|
| 428 | + 'args' => array('trash' => false), |
|
| 429 | + 'noheader' => true |
|
| 430 | + ), |
|
| 431 | + 'delete_message_template' => array( |
|
| 432 | + 'func' => '_delete_message_template', |
|
| 433 | + 'capability' => 'ee_delete_message', |
|
| 434 | + 'obj_id' => $grp_id, |
|
| 435 | + 'noheader' => true |
|
| 436 | + ), |
|
| 437 | + 'reset_to_default' => array( |
|
| 438 | + 'func' => '_reset_to_default_template', |
|
| 439 | + 'capability' => 'ee_edit_message', |
|
| 440 | + 'obj_id' => $grp_id, |
|
| 441 | + 'noheader' => true |
|
| 442 | + ), |
|
| 443 | + 'settings' => array( |
|
| 444 | + 'func' => '_settings', |
|
| 445 | + 'capability' => 'manage_options' |
|
| 446 | + ), |
|
| 447 | + 'update_global_settings' => array( |
|
| 448 | + 'func' => '_update_global_settings', |
|
| 449 | + 'capability' => 'manage_options', |
|
| 450 | + 'noheader' => true |
|
| 451 | + ), |
|
| 452 | + 'generate_now' => array( |
|
| 453 | + 'func' => '_generate_now', |
|
| 454 | + 'capability' => 'ee_send_message', |
|
| 455 | + 'noheader' => true |
|
| 456 | + ), |
|
| 457 | + 'generate_and_send_now' => array( |
|
| 458 | + 'func' => '_generate_and_send_now', |
|
| 459 | + 'capability' => 'ee_send_message', |
|
| 460 | + 'noheader' => true |
|
| 461 | + ), |
|
| 462 | + 'queue_for_resending' => array( |
|
| 463 | + 'func' => '_queue_for_resending', |
|
| 464 | + 'capability' => 'ee_send_message', |
|
| 465 | + 'noheader' => true |
|
| 466 | + ), |
|
| 467 | + 'send_now' => array( |
|
| 468 | + 'func' => '_send_now', |
|
| 469 | + 'capability' => 'ee_send_message', |
|
| 470 | + 'noheader' => true |
|
| 471 | + ), |
|
| 472 | + 'delete_ee_message' => array( |
|
| 473 | + 'func' => '_delete_ee_messages', |
|
| 474 | + 'capability' => 'ee_delete_messages', |
|
| 475 | + 'noheader' => true |
|
| 476 | + ), |
|
| 477 | + 'delete_ee_messages' => array( |
|
| 478 | + 'func' => '_delete_ee_messages', |
|
| 479 | + 'capability' => 'ee_delete_messages', |
|
| 480 | + 'noheader' => true, |
|
| 481 | + 'obj_id' => $msg_id |
|
| 482 | + ) |
|
| 483 | + ); |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + |
|
| 487 | + protected function _set_page_config() |
|
| 488 | + { |
|
| 489 | + $this->_page_config = array( |
|
| 490 | + 'default' => array( |
|
| 491 | + 'nav' => array( |
|
| 492 | + 'label' => __('Message Activity', 'event_espresso'), |
|
| 493 | + 'order' => 10 |
|
| 494 | + ), |
|
| 495 | + 'list_table' => 'EE_Message_List_Table', |
|
| 496 | + // 'qtips' => array( 'EE_Message_List_Table_Tips' ), |
|
| 497 | + 'require_nonce' => false |
|
| 498 | + ), |
|
| 499 | + 'global_mtps' => array( |
|
| 500 | + 'nav' => array( |
|
| 501 | + 'label' => __('Default Message Templates', 'event_espresso'), |
|
| 502 | + 'order' => 20 |
|
| 503 | + ), |
|
| 504 | + 'list_table' => 'Messages_Template_List_Table', |
|
| 505 | + 'help_tabs' => array( |
|
| 506 | + 'messages_overview_help_tab' => array( |
|
| 507 | + 'title' => __('Messages Overview', 'event_espresso'), |
|
| 508 | + 'filename' => 'messages_overview' |
|
| 509 | + ), |
|
| 510 | + 'messages_overview_messages_table_column_headings_help_tab' => array( |
|
| 511 | + 'title' => __('Messages Table Column Headings', 'event_espresso'), |
|
| 512 | + 'filename' => 'messages_overview_table_column_headings' |
|
| 513 | + ), |
|
| 514 | + 'messages_overview_messages_filters_help_tab' => array( |
|
| 515 | + 'title' => __('Message Filters', 'event_espresso'), |
|
| 516 | + 'filename' => 'messages_overview_filters' |
|
| 517 | + ), |
|
| 518 | + 'messages_overview_messages_views_help_tab' => array( |
|
| 519 | + 'title' => __('Message Views', 'event_espresso'), |
|
| 520 | + 'filename' => 'messages_overview_views' |
|
| 521 | + ), |
|
| 522 | + 'message_overview_message_types_help_tab' => array( |
|
| 523 | + 'title' => __('Message Types', 'event_espresso'), |
|
| 524 | + 'filename' => 'messages_overview_types' |
|
| 525 | + ), |
|
| 526 | + 'messages_overview_messengers_help_tab' => array( |
|
| 527 | + 'title' => __('Messengers', 'event_espresso'), |
|
| 528 | + 'filename' => 'messages_overview_messengers', |
|
| 529 | + ), |
|
| 530 | + ), |
|
| 531 | + 'help_tour' => array('Messages_Overview_Help_Tour'), |
|
| 532 | + 'require_nonce' => false |
|
| 533 | + ), |
|
| 534 | + 'custom_mtps' => array( |
|
| 535 | + 'nav' => array( |
|
| 536 | + 'label' => __('Custom Message Templates', 'event_espresso'), |
|
| 537 | + 'order' => 30 |
|
| 538 | + ), |
|
| 539 | + 'help_tabs' => array(), |
|
| 540 | + 'help_tour' => array(), |
|
| 541 | + 'require_nonce' => false |
|
| 542 | + ), |
|
| 543 | + 'add_new_message_template' => array( |
|
| 544 | + 'nav' => array( |
|
| 545 | + 'label' => __('Add New Message Templates', 'event_espresso'), |
|
| 546 | + 'order' => 5, |
|
| 547 | + 'persistent' => false |
|
| 548 | + ), |
|
| 549 | + 'require_nonce' => false |
|
| 550 | + ), |
|
| 551 | + 'edit_message_template' => array( |
|
| 552 | + 'labels' => array( |
|
| 553 | + 'buttons' => array( |
|
| 554 | + 'reset' => __('Reset Templates'), |
|
| 555 | + ), |
|
| 556 | + 'publishbox' => __('Update Actions', 'event_espresso') |
|
| 557 | + ), |
|
| 558 | + 'nav' => array( |
|
| 559 | + 'label' => __('Edit Message Templates', 'event_espresso'), |
|
| 560 | + 'order' => 5, |
|
| 561 | + 'persistent' => false, |
|
| 562 | + 'url' => '' |
|
| 563 | + ), |
|
| 564 | + 'metaboxes' => array('_publish_post_box', '_register_edit_meta_boxes'), |
|
| 565 | + 'has_metaboxes' => true, |
|
| 566 | + 'help_tour' => array('Message_Templates_Edit_Help_Tour'), |
|
| 567 | + 'help_tabs' => array( |
|
| 568 | + 'edit_message_template' => array( |
|
| 569 | + 'title' => __('Message Template Editor', 'event_espresso'), |
|
| 570 | + 'callback' => 'edit_message_template_help_tab' |
|
| 571 | + ), |
|
| 572 | + 'message_templates_help_tab' => array( |
|
| 573 | + 'title' => __('Message Templates', 'event_espresso'), |
|
| 574 | + 'filename' => 'messages_templates' |
|
| 575 | + ), |
|
| 576 | + 'message_template_shortcodes' => array( |
|
| 577 | + 'title' => __('Message Shortcodes', 'event_espresso'), |
|
| 578 | + 'callback' => 'message_template_shortcodes_help_tab' |
|
| 579 | + ), |
|
| 580 | + 'message_preview_help_tab' => array( |
|
| 581 | + 'title' => __('Message Preview', 'event_espresso'), |
|
| 582 | + 'filename' => 'messages_preview' |
|
| 583 | + ), |
|
| 584 | + 'messages_overview_other_help_tab' => array( |
|
| 585 | + 'title' => __('Messages Other', 'event_espresso'), |
|
| 586 | + 'filename' => 'messages_overview_other', |
|
| 587 | + ), |
|
| 588 | + ), |
|
| 589 | + 'require_nonce' => false |
|
| 590 | + ), |
|
| 591 | + 'display_preview_message' => array( |
|
| 592 | + 'nav' => array( |
|
| 593 | + 'label' => __('Message Preview', 'event_espresso'), |
|
| 594 | + 'order' => 5, |
|
| 595 | + 'url' => '', |
|
| 596 | + 'persistent' => false |
|
| 597 | + ), |
|
| 598 | + 'help_tabs' => array( |
|
| 599 | + 'preview_message' => array( |
|
| 600 | + 'title' => __('About Previews', 'event_espresso'), |
|
| 601 | + 'callback' => 'preview_message_help_tab' |
|
| 602 | + ) |
|
| 603 | + ), |
|
| 604 | + 'require_nonce' => false |
|
| 605 | + ), |
|
| 606 | + 'settings' => array( |
|
| 607 | + 'nav' => array( |
|
| 608 | + 'label' => __('Settings', 'event_espresso'), |
|
| 609 | + 'order' => 40 |
|
| 610 | + ), |
|
| 611 | + 'metaboxes' => array('_messages_settings_metaboxes'), |
|
| 612 | + 'help_tabs' => array( |
|
| 613 | + 'messages_settings_help_tab' => array( |
|
| 614 | + 'title' => __('Messages Settings', 'event_espresso'), |
|
| 615 | + 'filename' => 'messages_settings' |
|
| 616 | + ), |
|
| 617 | + 'messages_settings_message_types_help_tab' => array( |
|
| 618 | + 'title' => __('Activating / Deactivating Message Types', 'event_espresso'), |
|
| 619 | + 'filename' => 'messages_settings_message_types' |
|
| 620 | + ), |
|
| 621 | + 'messages_settings_messengers_help_tab' => array( |
|
| 622 | + 'title' => __('Activating / Deactivating Messengers', 'event_espresso'), |
|
| 623 | + 'filename' => 'messages_settings_messengers' |
|
| 624 | + ), |
|
| 625 | + ), |
|
| 626 | + 'help_tour' => array('Messages_Settings_Help_Tour'), |
|
| 627 | + 'require_nonce' => false |
|
| 628 | + ) |
|
| 629 | + ); |
|
| 630 | + } |
|
| 631 | + |
|
| 632 | + |
|
| 633 | + protected function _add_screen_options() |
|
| 634 | + { |
|
| 635 | + //todo |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + |
|
| 639 | + protected function _add_screen_options_global_mtps() |
|
| 640 | + { |
|
| 641 | + /** |
|
| 642 | + * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options |
|
| 643 | + * uses the $_admin_page_title property and we want different outputs in the different spots. |
|
| 644 | + */ |
|
| 645 | + $page_title = $this->_admin_page_title; |
|
| 646 | + $this->_admin_page_title = __('Global Message Templates', 'event_espresso'); |
|
| 647 | + $this->_per_page_screen_option(); |
|
| 648 | + $this->_admin_page_title = $page_title; |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + |
|
| 652 | + protected function _add_screen_options_default() |
|
| 653 | + { |
|
| 654 | + $this->_admin_page_title = __('Message Activity', 'event_espresso'); |
|
| 655 | + $this->_per_page_screen_option(); |
|
| 656 | + } |
|
| 657 | + |
|
| 658 | + |
|
| 659 | + //none of the below group are currently used for Messages |
|
| 660 | + protected function _add_feature_pointers() |
|
| 661 | + { |
|
| 662 | + } |
|
| 663 | + |
|
| 664 | + public function admin_init() |
|
| 665 | + { |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + public function admin_notices() |
|
| 669 | + { |
|
| 670 | + } |
|
| 671 | + |
|
| 672 | + public function admin_footer_scripts() |
|
| 673 | + { |
|
| 674 | + } |
|
| 675 | + |
|
| 676 | + |
|
| 677 | + public function messages_help_tab() |
|
| 678 | + { |
|
| 679 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php'); |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + |
|
| 683 | + public function messengers_help_tab() |
|
| 684 | + { |
|
| 685 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php'); |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + |
|
| 689 | + public function message_types_help_tab() |
|
| 690 | + { |
|
| 691 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php'); |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + |
|
| 695 | + public function messages_overview_help_tab() |
|
| 696 | + { |
|
| 697 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php'); |
|
| 698 | + } |
|
| 699 | + |
|
| 700 | + |
|
| 701 | + public function message_templates_help_tab() |
|
| 702 | + { |
|
| 703 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php'); |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + |
|
| 707 | + public function edit_message_template_help_tab() |
|
| 708 | + { |
|
| 709 | + $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' . esc_attr__('Editor Title', |
|
| 710 | + 'event_espresso') . '" />'; |
|
| 711 | + $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' . esc_attr__('Context Switcher and Preview', |
|
| 712 | + 'event_espresso') . '" />'; |
|
| 713 | + $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' . esc_attr__('Message Template Form Fields', |
|
| 714 | + 'event_espresso') . '" />'; |
|
| 715 | + $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' . esc_attr__('Shortcodes Metabox', |
|
| 716 | + 'event_espresso') . '" />'; |
|
| 717 | + $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' . esc_attr__('Publish Metabox', |
|
| 718 | + 'event_espresso') . '" />'; |
|
| 719 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 720 | + $args); |
|
| 721 | + } |
|
| 722 | + |
|
| 723 | + |
|
| 724 | + public function message_template_shortcodes_help_tab() |
|
| 725 | + { |
|
| 726 | + $this->_set_shortcodes(); |
|
| 727 | + $args['shortcodes'] = $this->_shortcodes; |
|
| 728 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 729 | + $args); |
|
| 730 | + } |
|
| 731 | 731 | |
| 732 | 732 | |
| 733 | - public function preview_message_help_tab() |
|
| 734 | - { |
|
| 735 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php'); |
|
| 736 | - } |
|
| 733 | + public function preview_message_help_tab() |
|
| 734 | + { |
|
| 735 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php'); |
|
| 736 | + } |
|
| 737 | 737 | |
| 738 | - |
|
| 739 | - public function settings_help_tab() |
|
| 740 | - { |
|
| 741 | - $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '" alt="' . esc_attr__('Active Email Tab', |
|
| 742 | - 'event_espresso') . '" />'; |
|
| 743 | - $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' . '" alt="' . esc_attr__('Inactive Email Tab', |
|
| 744 | - 'event_espresso') . '" />'; |
|
| 745 | - $args['img3'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked"><label for="ee-on-off-toggle-on"></label>'; |
|
| 746 | - $args['img4'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox"><label for="ee-on-off-toggle-on"></label>'; |
|
| 747 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 748 | - } |
|
| 738 | + |
|
| 739 | + public function settings_help_tab() |
|
| 740 | + { |
|
| 741 | + $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '" alt="' . esc_attr__('Active Email Tab', |
|
| 742 | + 'event_espresso') . '" />'; |
|
| 743 | + $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' . '" alt="' . esc_attr__('Inactive Email Tab', |
|
| 744 | + 'event_espresso') . '" />'; |
|
| 745 | + $args['img3'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked"><label for="ee-on-off-toggle-on"></label>'; |
|
| 746 | + $args['img4'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox"><label for="ee-on-off-toggle-on"></label>'; |
|
| 747 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 748 | + } |
|
| 749 | 749 | |
| 750 | 750 | |
| 751 | - public function load_scripts_styles() |
|
| 752 | - { |
|
| 753 | - wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 754 | - wp_enqueue_style('espresso_ee_msg'); |
|
| 751 | + public function load_scripts_styles() |
|
| 752 | + { |
|
| 753 | + wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 754 | + wp_enqueue_style('espresso_ee_msg'); |
|
| 755 | 755 | |
| 756 | - wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js', |
|
| 757 | - array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true); |
|
| 758 | - wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', |
|
| 759 | - array('ee-dialog'), EVENT_ESPRESSO_VERSION); |
|
| 760 | - } |
|
| 756 | + wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js', |
|
| 757 | + array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true); |
|
| 758 | + wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', |
|
| 759 | + array('ee-dialog'), EVENT_ESPRESSO_VERSION); |
|
| 760 | + } |
|
| 761 | 761 | |
| 762 | 762 | |
| 763 | - public function load_scripts_styles_default() |
|
| 764 | - { |
|
| 765 | - wp_enqueue_script('ee-msg-list-table-js'); |
|
| 766 | - } |
|
| 763 | + public function load_scripts_styles_default() |
|
| 764 | + { |
|
| 765 | + wp_enqueue_script('ee-msg-list-table-js'); |
|
| 766 | + } |
|
| 767 | 767 | |
| 768 | 768 | |
| 769 | - public function wp_editor_css($mce_css) |
|
| 770 | - { |
|
| 771 | - //if we're on the edit_message_template route |
|
| 772 | - if ($this->_req_action == 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) { |
|
| 773 | - $message_type_name = $this->_active_message_type_name; |
|
| 769 | + public function wp_editor_css($mce_css) |
|
| 770 | + { |
|
| 771 | + //if we're on the edit_message_template route |
|
| 772 | + if ($this->_req_action == 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) { |
|
| 773 | + $message_type_name = $this->_active_message_type_name; |
|
| 774 | 774 | |
| 775 | - //we're going to REPLACE the existing mce css |
|
| 776 | - //we need to get the css file location from the active messenger |
|
| 777 | - $mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, |
|
| 778 | - 'wpeditor', $this->_variation); |
|
| 779 | - } |
|
| 775 | + //we're going to REPLACE the existing mce css |
|
| 776 | + //we need to get the css file location from the active messenger |
|
| 777 | + $mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, |
|
| 778 | + 'wpeditor', $this->_variation); |
|
| 779 | + } |
|
| 780 | 780 | |
| 781 | - return $mce_css; |
|
| 782 | - } |
|
| 781 | + return $mce_css; |
|
| 782 | + } |
|
| 783 | 783 | |
| 784 | 784 | |
| 785 | - public function load_scripts_styles_edit_message_template() |
|
| 786 | - { |
|
| 785 | + public function load_scripts_styles_edit_message_template() |
|
| 786 | + { |
|
| 787 | 787 | |
| 788 | - $this->_set_shortcodes(); |
|
| 788 | + $this->_set_shortcodes(); |
|
| 789 | 789 | |
| 790 | - EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 791 | - __('Are you sure you want to reset the %s %s message templates? Remember continuing will reset the templates for all contexts in this messenger and message type group.', |
|
| 792 | - 'event_espresso'), |
|
| 793 | - $this->_message_template_group->messenger_obj()->label['singular'], |
|
| 794 | - $this->_message_template_group->message_type_obj()->label['singular'] |
|
| 795 | - ); |
|
| 796 | - EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = __('Switching the template pack for a messages template will reset the content for the template so the new layout is loaded. Any custom content in the existing template will be lost. Are you sure you wish to do this?', |
|
| 797 | - 'event_espresso'); |
|
| 790 | + EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 791 | + __('Are you sure you want to reset the %s %s message templates? Remember continuing will reset the templates for all contexts in this messenger and message type group.', |
|
| 792 | + 'event_espresso'), |
|
| 793 | + $this->_message_template_group->messenger_obj()->label['singular'], |
|
| 794 | + $this->_message_template_group->message_type_obj()->label['singular'] |
|
| 795 | + ); |
|
| 796 | + EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = __('Switching the template pack for a messages template will reset the content for the template so the new layout is loaded. Any custom content in the existing template will be lost. Are you sure you wish to do this?', |
|
| 797 | + 'event_espresso'); |
|
| 798 | 798 | |
| 799 | - wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL . 'ee_message_editor.js', array('jquery'), |
|
| 800 | - EVENT_ESPRESSO_VERSION); |
|
| 799 | + wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL . 'ee_message_editor.js', array('jquery'), |
|
| 800 | + EVENT_ESPRESSO_VERSION); |
|
| 801 | 801 | |
| 802 | - wp_enqueue_script('ee_admin_js'); |
|
| 803 | - wp_enqueue_script('ee_msgs_edit_js'); |
|
| 802 | + wp_enqueue_script('ee_admin_js'); |
|
| 803 | + wp_enqueue_script('ee_msgs_edit_js'); |
|
| 804 | 804 | |
| 805 | - //add in special css for tiny_mce |
|
| 806 | - add_filter('mce_css', array($this, 'wp_editor_css')); |
|
| 807 | - } |
|
| 805 | + //add in special css for tiny_mce |
|
| 806 | + add_filter('mce_css', array($this, 'wp_editor_css')); |
|
| 807 | + } |
|
| 808 | 808 | |
| 809 | 809 | |
| 810 | - public function load_scripts_styles_display_preview_message() |
|
| 811 | - { |
|
| 810 | + public function load_scripts_styles_display_preview_message() |
|
| 811 | + { |
|
| 812 | 812 | |
| 813 | - $this->_set_message_template_group(); |
|
| 813 | + $this->_set_message_template_group(); |
|
| 814 | 814 | |
| 815 | - if (isset($this->_req_data['messenger'])) { |
|
| 816 | - $this->_active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 817 | - } |
|
| 815 | + if (isset($this->_req_data['messenger'])) { |
|
| 816 | + $this->_active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 817 | + } |
|
| 818 | 818 | |
| 819 | - $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : ''; |
|
| 819 | + $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : ''; |
|
| 820 | 820 | |
| 821 | 821 | |
| 822 | - wp_enqueue_style('espresso_preview_css', |
|
| 823 | - $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, 'preview', |
|
| 824 | - $this->_variation)); |
|
| 825 | - } |
|
| 822 | + wp_enqueue_style('espresso_preview_css', |
|
| 823 | + $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, 'preview', |
|
| 824 | + $this->_variation)); |
|
| 825 | + } |
|
| 826 | 826 | |
| 827 | 827 | |
| 828 | - public function load_scripts_styles_settings() |
|
| 829 | - { |
|
| 830 | - wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL . 'ee_message_settings.css', array(), |
|
| 831 | - EVENT_ESPRESSO_VERSION); |
|
| 832 | - wp_enqueue_style('ee-text-links'); |
|
| 833 | - wp_enqueue_style('ee-message-settings'); |
|
| 828 | + public function load_scripts_styles_settings() |
|
| 829 | + { |
|
| 830 | + wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL . 'ee_message_settings.css', array(), |
|
| 831 | + EVENT_ESPRESSO_VERSION); |
|
| 832 | + wp_enqueue_style('ee-text-links'); |
|
| 833 | + wp_enqueue_style('ee-message-settings'); |
|
| 834 | 834 | |
| 835 | - wp_enqueue_script('ee-messages-settings'); |
|
| 836 | - } |
|
| 835 | + wp_enqueue_script('ee-messages-settings'); |
|
| 836 | + } |
|
| 837 | 837 | |
| 838 | 838 | |
| 839 | - /** |
|
| 840 | - * set views array for List Table |
|
| 841 | - */ |
|
| 842 | - public function _set_list_table_views_global_mtps() |
|
| 843 | - { |
|
| 844 | - $this->_views = array( |
|
| 845 | - 'in_use' => array( |
|
| 846 | - 'slug' => 'in_use', |
|
| 847 | - 'label' => __('In Use', 'event_espresso'), |
|
| 848 | - 'count' => 0, |
|
| 849 | - ) |
|
| 850 | - ); |
|
| 851 | - } |
|
| 839 | + /** |
|
| 840 | + * set views array for List Table |
|
| 841 | + */ |
|
| 842 | + public function _set_list_table_views_global_mtps() |
|
| 843 | + { |
|
| 844 | + $this->_views = array( |
|
| 845 | + 'in_use' => array( |
|
| 846 | + 'slug' => 'in_use', |
|
| 847 | + 'label' => __('In Use', 'event_espresso'), |
|
| 848 | + 'count' => 0, |
|
| 849 | + ) |
|
| 850 | + ); |
|
| 851 | + } |
|
| 852 | 852 | |
| 853 | 853 | |
| 854 | - /** |
|
| 855 | - * Set views array for the Custom Template List Table |
|
| 856 | - */ |
|
| 857 | - public function _set_list_table_views_custom_mtps() |
|
| 858 | - { |
|
| 859 | - $this->_set_list_table_views_global_mtps(); |
|
| 860 | - $this->_views['in_use']['bulk_action'] = array( |
|
| 861 | - 'trash_message_template' => esc_html__('Move to Trash', 'event_espresso') |
|
| 862 | - ); |
|
| 863 | - } |
|
| 864 | - |
|
| 865 | - |
|
| 866 | - /** |
|
| 867 | - * set views array for message queue list table |
|
| 868 | - */ |
|
| 869 | - public function _set_list_table_views_default() |
|
| 870 | - { |
|
| 871 | - EE_Registry::instance()->load_helper('Template'); |
|
| 872 | - |
|
| 873 | - $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can('ee_send_message', |
|
| 874 | - 'message_list_table_bulk_actions') |
|
| 875 | - ? array( |
|
| 876 | - 'generate_now' => __('Generate Now', 'event_espresso'), |
|
| 877 | - 'generate_and_send_now' => __('Generate and Send Now', 'event_espresso'), |
|
| 878 | - 'queue_for_resending' => __('Queue for Resending', 'event_espresso'), |
|
| 879 | - 'send_now' => __('Send Now', 'event_espresso') |
|
| 880 | - ) |
|
| 881 | - : array(); |
|
| 882 | - |
|
| 883 | - $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can('ee_delete_messages', |
|
| 884 | - 'message_list_table_bulk_actions') |
|
| 885 | - ? array('delete_ee_messages' => __('Delete Messages', 'event_espresso')) |
|
| 886 | - : array(); |
|
| 887 | - |
|
| 888 | - |
|
| 889 | - $this->_views = array( |
|
| 890 | - 'all' => array( |
|
| 891 | - 'slug' => 'all', |
|
| 892 | - 'label' => __('All', 'event_espresso'), |
|
| 893 | - 'count' => 0, |
|
| 894 | - 'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action) |
|
| 895 | - ) |
|
| 896 | - ); |
|
| 897 | - |
|
| 898 | - |
|
| 899 | - foreach (EEM_Message::instance()->all_statuses() as $status) { |
|
| 900 | - if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) { |
|
| 901 | - continue; |
|
| 902 | - } |
|
| 903 | - $status_bulk_actions = $common_bulk_actions; |
|
| 904 | - //unset bulk actions not applying to status |
|
| 905 | - if (! empty($status_bulk_actions)) { |
|
| 906 | - switch ($status) { |
|
| 907 | - case EEM_Message::status_idle: |
|
| 908 | - case EEM_Message::status_resend: |
|
| 909 | - $status_bulk_actions['send_now'] = $common_bulk_actions['send_now']; |
|
| 910 | - break; |
|
| 854 | + /** |
|
| 855 | + * Set views array for the Custom Template List Table |
|
| 856 | + */ |
|
| 857 | + public function _set_list_table_views_custom_mtps() |
|
| 858 | + { |
|
| 859 | + $this->_set_list_table_views_global_mtps(); |
|
| 860 | + $this->_views['in_use']['bulk_action'] = array( |
|
| 861 | + 'trash_message_template' => esc_html__('Move to Trash', 'event_espresso') |
|
| 862 | + ); |
|
| 863 | + } |
|
| 864 | + |
|
| 865 | + |
|
| 866 | + /** |
|
| 867 | + * set views array for message queue list table |
|
| 868 | + */ |
|
| 869 | + public function _set_list_table_views_default() |
|
| 870 | + { |
|
| 871 | + EE_Registry::instance()->load_helper('Template'); |
|
| 872 | + |
|
| 873 | + $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can('ee_send_message', |
|
| 874 | + 'message_list_table_bulk_actions') |
|
| 875 | + ? array( |
|
| 876 | + 'generate_now' => __('Generate Now', 'event_espresso'), |
|
| 877 | + 'generate_and_send_now' => __('Generate and Send Now', 'event_espresso'), |
|
| 878 | + 'queue_for_resending' => __('Queue for Resending', 'event_espresso'), |
|
| 879 | + 'send_now' => __('Send Now', 'event_espresso') |
|
| 880 | + ) |
|
| 881 | + : array(); |
|
| 882 | + |
|
| 883 | + $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can('ee_delete_messages', |
|
| 884 | + 'message_list_table_bulk_actions') |
|
| 885 | + ? array('delete_ee_messages' => __('Delete Messages', 'event_espresso')) |
|
| 886 | + : array(); |
|
| 887 | + |
|
| 888 | + |
|
| 889 | + $this->_views = array( |
|
| 890 | + 'all' => array( |
|
| 891 | + 'slug' => 'all', |
|
| 892 | + 'label' => __('All', 'event_espresso'), |
|
| 893 | + 'count' => 0, |
|
| 894 | + 'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action) |
|
| 895 | + ) |
|
| 896 | + ); |
|
| 897 | + |
|
| 898 | + |
|
| 899 | + foreach (EEM_Message::instance()->all_statuses() as $status) { |
|
| 900 | + if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) { |
|
| 901 | + continue; |
|
| 902 | + } |
|
| 903 | + $status_bulk_actions = $common_bulk_actions; |
|
| 904 | + //unset bulk actions not applying to status |
|
| 905 | + if (! empty($status_bulk_actions)) { |
|
| 906 | + switch ($status) { |
|
| 907 | + case EEM_Message::status_idle: |
|
| 908 | + case EEM_Message::status_resend: |
|
| 909 | + $status_bulk_actions['send_now'] = $common_bulk_actions['send_now']; |
|
| 910 | + break; |
|
| 911 | 911 | |
| 912 | - case EEM_Message::status_failed: |
|
| 913 | - case EEM_Message::status_debug_only: |
|
| 914 | - case EEM_Message::status_messenger_executing: |
|
| 915 | - $status_bulk_actions = array(); |
|
| 916 | - break; |
|
| 912 | + case EEM_Message::status_failed: |
|
| 913 | + case EEM_Message::status_debug_only: |
|
| 914 | + case EEM_Message::status_messenger_executing: |
|
| 915 | + $status_bulk_actions = array(); |
|
| 916 | + break; |
|
| 917 | 917 | |
| 918 | - case EEM_Message::status_incomplete: |
|
| 919 | - unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']); |
|
| 920 | - break; |
|
| 918 | + case EEM_Message::status_incomplete: |
|
| 919 | + unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']); |
|
| 920 | + break; |
|
| 921 | 921 | |
| 922 | - case EEM_Message::status_retry: |
|
| 923 | - case EEM_Message::status_sent: |
|
| 924 | - unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']); |
|
| 925 | - break; |
|
| 926 | - } |
|
| 927 | - } |
|
| 922 | + case EEM_Message::status_retry: |
|
| 923 | + case EEM_Message::status_sent: |
|
| 924 | + unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']); |
|
| 925 | + break; |
|
| 926 | + } |
|
| 927 | + } |
|
| 928 | 928 | |
| 929 | - //skip adding messenger executing status to views because it will be included with the Failed view. |
|
| 930 | - if ( $status === EEM_Message::status_messenger_executing ) { |
|
| 931 | - continue; |
|
| 932 | - } |
|
| 929 | + //skip adding messenger executing status to views because it will be included with the Failed view. |
|
| 930 | + if ( $status === EEM_Message::status_messenger_executing ) { |
|
| 931 | + continue; |
|
| 932 | + } |
|
| 933 | 933 | |
| 934 | - $this->_views[strtolower($status)] = array( |
|
| 935 | - 'slug' => strtolower($status), |
|
| 936 | - 'label' => EEH_Template::pretty_status($status, false, 'sentence'), |
|
| 937 | - 'count' => 0, |
|
| 938 | - 'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action) |
|
| 939 | - ); |
|
| 940 | - } |
|
| 941 | - } |
|
| 942 | - |
|
| 943 | - |
|
| 944 | - protected function _ee_default_messages_overview_list_table() |
|
| 945 | - { |
|
| 946 | - $this->_admin_page_title = __('Default Message Templates', 'event_espresso'); |
|
| 947 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 948 | - } |
|
| 949 | - |
|
| 950 | - |
|
| 951 | - protected function _message_queue_list_table() |
|
| 952 | - { |
|
| 953 | - $this->_search_btn_label = __('Message Activity', 'event_espresso'); |
|
| 954 | - $this->_template_args['per_column'] = 6; |
|
| 955 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items()); |
|
| 956 | - $this->_template_args['before_list_table'] = '<h3>' . EEM_Message::instance()->get_pretty_label_for_results() . '</h3>'; |
|
| 957 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 958 | - } |
|
| 959 | - |
|
| 960 | - |
|
| 961 | - protected function _message_legend_items() |
|
| 962 | - { |
|
| 963 | - |
|
| 964 | - $action_css_classes = EEH_MSG_Template::get_message_action_icons(); |
|
| 965 | - $action_items = array(); |
|
| 966 | - |
|
| 967 | - foreach ($action_css_classes as $action_item => $action_details) { |
|
| 968 | - if ($action_item === 'see_notifications_for') { |
|
| 969 | - continue; |
|
| 970 | - } |
|
| 971 | - $action_items[$action_item] = array( |
|
| 972 | - 'class' => $action_details['css_class'], |
|
| 973 | - 'desc' => $action_details['label'] |
|
| 974 | - ); |
|
| 975 | - } |
|
| 976 | - |
|
| 977 | - /** @type array $status_items status legend setup */ |
|
| 978 | - $status_items = array( |
|
| 979 | - 'sent_status' => array( |
|
| 980 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent, |
|
| 981 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence') |
|
| 982 | - ), |
|
| 983 | - 'idle_status' => array( |
|
| 984 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle, |
|
| 985 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence') |
|
| 986 | - ), |
|
| 987 | - 'failed_status' => array( |
|
| 988 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed, |
|
| 989 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence') |
|
| 990 | - ), |
|
| 991 | - 'messenger_executing_status' => array( |
|
| 992 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing, |
|
| 993 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence') |
|
| 994 | - ), |
|
| 995 | - 'resend_status' => array( |
|
| 996 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend, |
|
| 997 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence') |
|
| 998 | - ), |
|
| 999 | - 'incomplete_status' => array( |
|
| 1000 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete, |
|
| 1001 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence') |
|
| 1002 | - ), |
|
| 1003 | - 'retry_status' => array( |
|
| 1004 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry, |
|
| 1005 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence') |
|
| 1006 | - ) |
|
| 1007 | - ); |
|
| 1008 | - if (EEM_Message::debug()) { |
|
| 1009 | - $status_items['debug_only_status'] = array( |
|
| 1010 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only, |
|
| 1011 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence') |
|
| 1012 | - ); |
|
| 1013 | - } |
|
| 1014 | - |
|
| 1015 | - return array_merge($action_items, $status_items); |
|
| 1016 | - } |
|
| 1017 | - |
|
| 1018 | - |
|
| 1019 | - protected function _custom_mtps_preview() |
|
| 1020 | - { |
|
| 1021 | - $this->_admin_page_title = __('Custom Message Templates (Preview)', 'event_espresso'); |
|
| 1022 | - $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png" alt="' . esc_attr__('Preview Custom Message Templates screenshot', |
|
| 1023 | - 'event_espresso') . '" />'; |
|
| 1024 | - $this->_template_args['preview_text'] = '<strong>' . __('Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.', |
|
| 1025 | - 'event_espresso') . '</strong>'; |
|
| 1026 | - $this->display_admin_caf_preview_page('custom_message_types', false); |
|
| 1027 | - } |
|
| 1028 | - |
|
| 1029 | - |
|
| 1030 | - /** |
|
| 1031 | - * get_message_templates |
|
| 1032 | - * This gets all the message templates for listing on the overview list. |
|
| 1033 | - * |
|
| 1034 | - * @access public |
|
| 1035 | - * |
|
| 1036 | - * @param int $perpage the amount of templates groups to show per page |
|
| 1037 | - * @param string $type the current _view we're getting templates for |
|
| 1038 | - * @param bool $count return count? |
|
| 1039 | - * @param bool $all disregard any paging info (get all data); |
|
| 1040 | - * @param bool $global whether to return just global (true) or custom templates (false) |
|
| 1041 | - * |
|
| 1042 | - * @return array |
|
| 1043 | - */ |
|
| 1044 | - public function get_message_templates($perpage = 10, $type = 'in_use', $count = false, $all = false, $global = true) |
|
| 1045 | - { |
|
| 1046 | - |
|
| 1047 | - $MTP = EEM_Message_Template_Group::instance(); |
|
| 1048 | - |
|
| 1049 | - $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby']; |
|
| 1050 | - $orderby = $this->_req_data['orderby']; |
|
| 1051 | - |
|
| 1052 | - $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC'; |
|
| 1053 | - |
|
| 1054 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
| 1055 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $perpage; |
|
| 1056 | - |
|
| 1057 | - $offset = ($current_page - 1) * $per_page; |
|
| 1058 | - $limit = $all ? null : array($offset, $per_page); |
|
| 1059 | - |
|
| 1060 | - |
|
| 1061 | - //options will match what is in the _views array property |
|
| 1062 | - switch ($type) { |
|
| 934 | + $this->_views[strtolower($status)] = array( |
|
| 935 | + 'slug' => strtolower($status), |
|
| 936 | + 'label' => EEH_Template::pretty_status($status, false, 'sentence'), |
|
| 937 | + 'count' => 0, |
|
| 938 | + 'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action) |
|
| 939 | + ); |
|
| 940 | + } |
|
| 941 | + } |
|
| 942 | + |
|
| 943 | + |
|
| 944 | + protected function _ee_default_messages_overview_list_table() |
|
| 945 | + { |
|
| 946 | + $this->_admin_page_title = __('Default Message Templates', 'event_espresso'); |
|
| 947 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 948 | + } |
|
| 949 | + |
|
| 950 | + |
|
| 951 | + protected function _message_queue_list_table() |
|
| 952 | + { |
|
| 953 | + $this->_search_btn_label = __('Message Activity', 'event_espresso'); |
|
| 954 | + $this->_template_args['per_column'] = 6; |
|
| 955 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items()); |
|
| 956 | + $this->_template_args['before_list_table'] = '<h3>' . EEM_Message::instance()->get_pretty_label_for_results() . '</h3>'; |
|
| 957 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 958 | + } |
|
| 959 | + |
|
| 960 | + |
|
| 961 | + protected function _message_legend_items() |
|
| 962 | + { |
|
| 963 | + |
|
| 964 | + $action_css_classes = EEH_MSG_Template::get_message_action_icons(); |
|
| 965 | + $action_items = array(); |
|
| 966 | + |
|
| 967 | + foreach ($action_css_classes as $action_item => $action_details) { |
|
| 968 | + if ($action_item === 'see_notifications_for') { |
|
| 969 | + continue; |
|
| 970 | + } |
|
| 971 | + $action_items[$action_item] = array( |
|
| 972 | + 'class' => $action_details['css_class'], |
|
| 973 | + 'desc' => $action_details['label'] |
|
| 974 | + ); |
|
| 975 | + } |
|
| 976 | + |
|
| 977 | + /** @type array $status_items status legend setup */ |
|
| 978 | + $status_items = array( |
|
| 979 | + 'sent_status' => array( |
|
| 980 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent, |
|
| 981 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence') |
|
| 982 | + ), |
|
| 983 | + 'idle_status' => array( |
|
| 984 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle, |
|
| 985 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence') |
|
| 986 | + ), |
|
| 987 | + 'failed_status' => array( |
|
| 988 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed, |
|
| 989 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence') |
|
| 990 | + ), |
|
| 991 | + 'messenger_executing_status' => array( |
|
| 992 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing, |
|
| 993 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence') |
|
| 994 | + ), |
|
| 995 | + 'resend_status' => array( |
|
| 996 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend, |
|
| 997 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence') |
|
| 998 | + ), |
|
| 999 | + 'incomplete_status' => array( |
|
| 1000 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete, |
|
| 1001 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence') |
|
| 1002 | + ), |
|
| 1003 | + 'retry_status' => array( |
|
| 1004 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry, |
|
| 1005 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence') |
|
| 1006 | + ) |
|
| 1007 | + ); |
|
| 1008 | + if (EEM_Message::debug()) { |
|
| 1009 | + $status_items['debug_only_status'] = array( |
|
| 1010 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only, |
|
| 1011 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence') |
|
| 1012 | + ); |
|
| 1013 | + } |
|
| 1014 | + |
|
| 1015 | + return array_merge($action_items, $status_items); |
|
| 1016 | + } |
|
| 1017 | + |
|
| 1018 | + |
|
| 1019 | + protected function _custom_mtps_preview() |
|
| 1020 | + { |
|
| 1021 | + $this->_admin_page_title = __('Custom Message Templates (Preview)', 'event_espresso'); |
|
| 1022 | + $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png" alt="' . esc_attr__('Preview Custom Message Templates screenshot', |
|
| 1023 | + 'event_espresso') . '" />'; |
|
| 1024 | + $this->_template_args['preview_text'] = '<strong>' . __('Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.', |
|
| 1025 | + 'event_espresso') . '</strong>'; |
|
| 1026 | + $this->display_admin_caf_preview_page('custom_message_types', false); |
|
| 1027 | + } |
|
| 1028 | + |
|
| 1029 | + |
|
| 1030 | + /** |
|
| 1031 | + * get_message_templates |
|
| 1032 | + * This gets all the message templates for listing on the overview list. |
|
| 1033 | + * |
|
| 1034 | + * @access public |
|
| 1035 | + * |
|
| 1036 | + * @param int $perpage the amount of templates groups to show per page |
|
| 1037 | + * @param string $type the current _view we're getting templates for |
|
| 1038 | + * @param bool $count return count? |
|
| 1039 | + * @param bool $all disregard any paging info (get all data); |
|
| 1040 | + * @param bool $global whether to return just global (true) or custom templates (false) |
|
| 1041 | + * |
|
| 1042 | + * @return array |
|
| 1043 | + */ |
|
| 1044 | + public function get_message_templates($perpage = 10, $type = 'in_use', $count = false, $all = false, $global = true) |
|
| 1045 | + { |
|
| 1046 | + |
|
| 1047 | + $MTP = EEM_Message_Template_Group::instance(); |
|
| 1048 | + |
|
| 1049 | + $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby']; |
|
| 1050 | + $orderby = $this->_req_data['orderby']; |
|
| 1051 | + |
|
| 1052 | + $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC'; |
|
| 1053 | + |
|
| 1054 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
| 1055 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $perpage; |
|
| 1056 | + |
|
| 1057 | + $offset = ($current_page - 1) * $per_page; |
|
| 1058 | + $limit = $all ? null : array($offset, $per_page); |
|
| 1059 | + |
|
| 1060 | + |
|
| 1061 | + //options will match what is in the _views array property |
|
| 1062 | + switch ($type) { |
|
| 1063 | 1063 | |
| 1064 | - case 'in_use': |
|
| 1065 | - $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true); |
|
| 1066 | - break; |
|
| 1064 | + case 'in_use': |
|
| 1065 | + $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true); |
|
| 1066 | + break; |
|
| 1067 | 1067 | |
| 1068 | - default: |
|
| 1069 | - $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global); |
|
| 1068 | + default: |
|
| 1069 | + $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global); |
|
| 1070 | 1070 | |
| 1071 | - } |
|
| 1072 | - |
|
| 1073 | - return $templates; |
|
| 1074 | - } |
|
| 1075 | - |
|
| 1076 | - |
|
| 1077 | - /** |
|
| 1078 | - * filters etc might need a list of installed message_types |
|
| 1079 | - * @return array an array of message type objects |
|
| 1080 | - */ |
|
| 1081 | - public function get_installed_message_types() |
|
| 1082 | - { |
|
| 1083 | - $installed_message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 1084 | - $installed = array(); |
|
| 1085 | - |
|
| 1086 | - foreach ($installed_message_types as $message_type) { |
|
| 1087 | - $installed[$message_type->name] = $message_type; |
|
| 1088 | - } |
|
| 1089 | - |
|
| 1090 | - return $installed; |
|
| 1091 | - } |
|
| 1092 | - |
|
| 1093 | - |
|
| 1094 | - /** |
|
| 1095 | - * _add_message_template |
|
| 1096 | - * |
|
| 1097 | - * This is used when creating a custom template. All Custom Templates start based off another template. |
|
| 1098 | - * |
|
| 1099 | - * @param string $message_type |
|
| 1100 | - * @param string $messenger |
|
| 1101 | - * @param string $GRP_ID |
|
| 1102 | - * |
|
| 1103 | - * @throws EE_error |
|
| 1104 | - */ |
|
| 1105 | - protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '') |
|
| 1106 | - { |
|
| 1107 | - //set values override any request data |
|
| 1108 | - $message_type = ! empty($message_type) ? $message_type : ''; |
|
| 1109 | - $message_type = empty($message_type) && ! empty($this->_req_data['message_type']) ? $this->_req_data['message_type'] : $message_type; |
|
| 1110 | - |
|
| 1111 | - $messenger = ! empty($messenger) ? $messenger : ''; |
|
| 1112 | - $messenger = empty($messenger) && ! empty($this->_req_data['messenger']) ? $this->_req_data['messenger'] : $messenger; |
|
| 1113 | - |
|
| 1114 | - $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : ''; |
|
| 1115 | - $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID; |
|
| 1116 | - |
|
| 1117 | - //we need messenger and message type. They should be coming from the event editor. If not here then return error |
|
| 1118 | - if (empty($message_type) || empty($messenger)) { |
|
| 1119 | - throw new EE_error(__('Sorry, but we can\'t create new templates because we\'re missing the messenger or message type', |
|
| 1120 | - 'event_espresso')); |
|
| 1121 | - } |
|
| 1122 | - |
|
| 1123 | - //we need the GRP_ID for the template being used as the base for the new template |
|
| 1124 | - if (empty($GRP_ID)) { |
|
| 1125 | - throw new EE_Error(__('In order to create a custom message template the GRP_ID of the template being used as a base is needed', |
|
| 1126 | - 'event_espresso')); |
|
| 1127 | - } |
|
| 1128 | - |
|
| 1129 | - //let's just make sure the template gets generated! |
|
| 1130 | - |
|
| 1131 | - //we need to reassign some variables for what the insert is expecting |
|
| 1132 | - $this->_req_data['MTP_messenger'] = $messenger; |
|
| 1133 | - $this->_req_data['MTP_message_type'] = $message_type; |
|
| 1134 | - $this->_req_data['GRP_ID'] = $GRP_ID; |
|
| 1135 | - $this->_insert_or_update_message_template(true); |
|
| 1136 | - } |
|
| 1137 | - |
|
| 1138 | - |
|
| 1139 | - /** |
|
| 1140 | - * public wrapper for the _add_message_template method |
|
| 1141 | - * |
|
| 1142 | - * @param string $message_type message type slug |
|
| 1143 | - * @param string $messenger messenger slug |
|
| 1144 | - * @param int $GRP_ID GRP_ID for the related message template group this new template will be based |
|
| 1145 | - * off of. |
|
| 1146 | - */ |
|
| 1147 | - public function add_message_template($message_type, $messenger, $GRP_ID) |
|
| 1148 | - { |
|
| 1149 | - $this->_add_message_template($message_type, $messenger, $GRP_ID); |
|
| 1150 | - } |
|
| 1151 | - |
|
| 1152 | - |
|
| 1153 | - /** |
|
| 1154 | - * _edit_message_template |
|
| 1155 | - * |
|
| 1156 | - * @access protected |
|
| 1157 | - * @return void |
|
| 1158 | - */ |
|
| 1159 | - protected function _edit_message_template() |
|
| 1160 | - { |
|
| 1161 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1162 | - $template_fields = ''; |
|
| 1163 | - $sidebar_fields = ''; |
|
| 1164 | - //we filter the tinyMCE settings to remove the validation since message templates by their nature will not have valid html in the templates. |
|
| 1165 | - add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2); |
|
| 1166 | - |
|
| 1167 | - $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) |
|
| 1168 | - ? absint($this->_req_data['id']) |
|
| 1169 | - : false; |
|
| 1170 | - |
|
| 1171 | - $this->_set_shortcodes(); //this also sets the _message_template property. |
|
| 1172 | - $message_template_group = $this->_message_template_group; |
|
| 1173 | - $c_label = $message_template_group->context_label(); |
|
| 1174 | - $c_config = $message_template_group->contexts_config(); |
|
| 1175 | - |
|
| 1176 | - reset($c_config); |
|
| 1177 | - $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context']) |
|
| 1178 | - ? strtolower($this->_req_data['context']) |
|
| 1179 | - : key($c_config); |
|
| 1180 | - |
|
| 1181 | - |
|
| 1182 | - if (empty($GRP_ID)) { |
|
| 1183 | - $action = 'insert_message_template'; |
|
| 1184 | - //$button_both = false; |
|
| 1185 | - //$button_text = array( __( 'Save','event_espresso') ); |
|
| 1186 | - //$button_actions = array('something_different'); |
|
| 1187 | - //$referrer = false; |
|
| 1188 | - $edit_message_template_form_url = add_query_arg( |
|
| 1189 | - array('action' => $action, 'noheader' => true), |
|
| 1190 | - EE_MSG_ADMIN_URL |
|
| 1191 | - ); |
|
| 1192 | - } else { |
|
| 1193 | - $action = 'update_message_template'; |
|
| 1194 | - //$button_both = true; |
|
| 1195 | - //$button_text = array(); |
|
| 1196 | - //$button_actions = array(); |
|
| 1197 | - //$referrer = $this->_admin_base_url; |
|
| 1198 | - $edit_message_template_form_url = add_query_arg( |
|
| 1199 | - array('action' => $action, 'noheader' => true), |
|
| 1200 | - EE_MSG_ADMIN_URL |
|
| 1201 | - ); |
|
| 1202 | - } |
|
| 1203 | - |
|
| 1204 | - //set active messenger for this view |
|
| 1205 | - $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 1206 | - $message_template_group->messenger() |
|
| 1207 | - ); |
|
| 1208 | - $this->_active_message_type_name = $message_template_group->message_type(); |
|
| 1209 | - |
|
| 1210 | - |
|
| 1211 | - //Do we have any validation errors? |
|
| 1212 | - $validators = $this->_get_transient(); |
|
| 1213 | - $v_fields = ! empty($validators) ? array_keys($validators) : array(); |
|
| 1214 | - |
|
| 1215 | - |
|
| 1216 | - //we need to assemble the title from Various details |
|
| 1217 | - $context_label = sprintf( |
|
| 1218 | - __('(%s %s)', 'event_espresso'), |
|
| 1219 | - $c_config[$context]['label'], |
|
| 1220 | - ucwords($c_label['label']) |
|
| 1221 | - ); |
|
| 1222 | - |
|
| 1223 | - $title = sprintf( |
|
| 1224 | - __(' %s %s Template %s', 'event_espresso'), |
|
| 1225 | - ucwords($message_template_group->messenger_obj()->label['singular']), |
|
| 1226 | - ucwords($message_template_group->message_type_obj()->label['singular']), |
|
| 1227 | - $context_label |
|
| 1228 | - ); |
|
| 1229 | - |
|
| 1230 | - $this->_template_args['GRP_ID'] = $GRP_ID; |
|
| 1231 | - $this->_template_args['message_template'] = $message_template_group; |
|
| 1232 | - $this->_template_args['is_extra_fields'] = false; |
|
| 1233 | - |
|
| 1234 | - |
|
| 1235 | - //let's get EEH_MSG_Template so we can get template form fields |
|
| 1236 | - $template_field_structure = EEH_MSG_Template::get_fields( |
|
| 1237 | - $message_template_group->messenger(), |
|
| 1238 | - $message_template_group->message_type() |
|
| 1239 | - ); |
|
| 1240 | - |
|
| 1241 | - if ( ! $template_field_structure) { |
|
| 1242 | - $template_field_structure = false; |
|
| 1243 | - $template_fields = __('There was an error in assembling the fields for this display (you should see an error message)', |
|
| 1244 | - 'event_espresso'); |
|
| 1245 | - } |
|
| 1246 | - |
|
| 1247 | - |
|
| 1248 | - $message_templates = $message_template_group->context_templates(); |
|
| 1249 | - |
|
| 1250 | - |
|
| 1251 | - //if we have the extra key.. then we need to remove the content index from the template_field_structure as it will get handled in the "extra" array. |
|
| 1252 | - if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) { |
|
| 1253 | - foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) { |
|
| 1254 | - unset($template_field_structure[$context][$reference_field]); |
|
| 1255 | - } |
|
| 1256 | - } |
|
| 1257 | - |
|
| 1258 | - //let's loop through the template_field_structure and actually assemble the input fields! |
|
| 1259 | - if ( ! empty($template_field_structure)) { |
|
| 1260 | - foreach ($template_field_structure[$context] as $template_field => $field_setup_array) { |
|
| 1261 | - //if this is an 'extra' template field then we need to remove any existing fields that are keyed up in the extra array and reset them. |
|
| 1262 | - if ($template_field == 'extra') { |
|
| 1263 | - $this->_template_args['is_extra_fields'] = true; |
|
| 1264 | - foreach ($field_setup_array as $reference_field => $new_fields_array) { |
|
| 1265 | - $message_template = $message_templates[$context][$reference_field]; |
|
| 1266 | - $content = $message_template instanceof EE_Message_Template |
|
| 1267 | - ? $message_template->get('MTP_content') |
|
| 1268 | - : ''; |
|
| 1269 | - foreach ($new_fields_array as $extra_field => $extra_array) { |
|
| 1270 | - //let's verify if we need this extra field via the shortcodes parameter. |
|
| 1271 | - $continue = false; |
|
| 1272 | - if (isset($extra_array['shortcodes_required'])) { |
|
| 1273 | - foreach ((array)$extra_array['shortcodes_required'] as $shortcode) { |
|
| 1274 | - if ( ! array_key_exists($shortcode, $this->_shortcodes)) { |
|
| 1275 | - $continue = true; |
|
| 1276 | - } |
|
| 1277 | - } |
|
| 1278 | - if ($continue) { |
|
| 1279 | - continue; |
|
| 1280 | - } |
|
| 1281 | - } |
|
| 1071 | + } |
|
| 1072 | + |
|
| 1073 | + return $templates; |
|
| 1074 | + } |
|
| 1075 | + |
|
| 1076 | + |
|
| 1077 | + /** |
|
| 1078 | + * filters etc might need a list of installed message_types |
|
| 1079 | + * @return array an array of message type objects |
|
| 1080 | + */ |
|
| 1081 | + public function get_installed_message_types() |
|
| 1082 | + { |
|
| 1083 | + $installed_message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 1084 | + $installed = array(); |
|
| 1085 | + |
|
| 1086 | + foreach ($installed_message_types as $message_type) { |
|
| 1087 | + $installed[$message_type->name] = $message_type; |
|
| 1088 | + } |
|
| 1089 | + |
|
| 1090 | + return $installed; |
|
| 1091 | + } |
|
| 1092 | + |
|
| 1093 | + |
|
| 1094 | + /** |
|
| 1095 | + * _add_message_template |
|
| 1096 | + * |
|
| 1097 | + * This is used when creating a custom template. All Custom Templates start based off another template. |
|
| 1098 | + * |
|
| 1099 | + * @param string $message_type |
|
| 1100 | + * @param string $messenger |
|
| 1101 | + * @param string $GRP_ID |
|
| 1102 | + * |
|
| 1103 | + * @throws EE_error |
|
| 1104 | + */ |
|
| 1105 | + protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '') |
|
| 1106 | + { |
|
| 1107 | + //set values override any request data |
|
| 1108 | + $message_type = ! empty($message_type) ? $message_type : ''; |
|
| 1109 | + $message_type = empty($message_type) && ! empty($this->_req_data['message_type']) ? $this->_req_data['message_type'] : $message_type; |
|
| 1110 | + |
|
| 1111 | + $messenger = ! empty($messenger) ? $messenger : ''; |
|
| 1112 | + $messenger = empty($messenger) && ! empty($this->_req_data['messenger']) ? $this->_req_data['messenger'] : $messenger; |
|
| 1113 | + |
|
| 1114 | + $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : ''; |
|
| 1115 | + $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID; |
|
| 1116 | + |
|
| 1117 | + //we need messenger and message type. They should be coming from the event editor. If not here then return error |
|
| 1118 | + if (empty($message_type) || empty($messenger)) { |
|
| 1119 | + throw new EE_error(__('Sorry, but we can\'t create new templates because we\'re missing the messenger or message type', |
|
| 1120 | + 'event_espresso')); |
|
| 1121 | + } |
|
| 1122 | + |
|
| 1123 | + //we need the GRP_ID for the template being used as the base for the new template |
|
| 1124 | + if (empty($GRP_ID)) { |
|
| 1125 | + throw new EE_Error(__('In order to create a custom message template the GRP_ID of the template being used as a base is needed', |
|
| 1126 | + 'event_espresso')); |
|
| 1127 | + } |
|
| 1128 | + |
|
| 1129 | + //let's just make sure the template gets generated! |
|
| 1130 | + |
|
| 1131 | + //we need to reassign some variables for what the insert is expecting |
|
| 1132 | + $this->_req_data['MTP_messenger'] = $messenger; |
|
| 1133 | + $this->_req_data['MTP_message_type'] = $message_type; |
|
| 1134 | + $this->_req_data['GRP_ID'] = $GRP_ID; |
|
| 1135 | + $this->_insert_or_update_message_template(true); |
|
| 1136 | + } |
|
| 1137 | + |
|
| 1138 | + |
|
| 1139 | + /** |
|
| 1140 | + * public wrapper for the _add_message_template method |
|
| 1141 | + * |
|
| 1142 | + * @param string $message_type message type slug |
|
| 1143 | + * @param string $messenger messenger slug |
|
| 1144 | + * @param int $GRP_ID GRP_ID for the related message template group this new template will be based |
|
| 1145 | + * off of. |
|
| 1146 | + */ |
|
| 1147 | + public function add_message_template($message_type, $messenger, $GRP_ID) |
|
| 1148 | + { |
|
| 1149 | + $this->_add_message_template($message_type, $messenger, $GRP_ID); |
|
| 1150 | + } |
|
| 1151 | + |
|
| 1152 | + |
|
| 1153 | + /** |
|
| 1154 | + * _edit_message_template |
|
| 1155 | + * |
|
| 1156 | + * @access protected |
|
| 1157 | + * @return void |
|
| 1158 | + */ |
|
| 1159 | + protected function _edit_message_template() |
|
| 1160 | + { |
|
| 1161 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1162 | + $template_fields = ''; |
|
| 1163 | + $sidebar_fields = ''; |
|
| 1164 | + //we filter the tinyMCE settings to remove the validation since message templates by their nature will not have valid html in the templates. |
|
| 1165 | + add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2); |
|
| 1166 | + |
|
| 1167 | + $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) |
|
| 1168 | + ? absint($this->_req_data['id']) |
|
| 1169 | + : false; |
|
| 1170 | + |
|
| 1171 | + $this->_set_shortcodes(); //this also sets the _message_template property. |
|
| 1172 | + $message_template_group = $this->_message_template_group; |
|
| 1173 | + $c_label = $message_template_group->context_label(); |
|
| 1174 | + $c_config = $message_template_group->contexts_config(); |
|
| 1175 | + |
|
| 1176 | + reset($c_config); |
|
| 1177 | + $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context']) |
|
| 1178 | + ? strtolower($this->_req_data['context']) |
|
| 1179 | + : key($c_config); |
|
| 1180 | + |
|
| 1181 | + |
|
| 1182 | + if (empty($GRP_ID)) { |
|
| 1183 | + $action = 'insert_message_template'; |
|
| 1184 | + //$button_both = false; |
|
| 1185 | + //$button_text = array( __( 'Save','event_espresso') ); |
|
| 1186 | + //$button_actions = array('something_different'); |
|
| 1187 | + //$referrer = false; |
|
| 1188 | + $edit_message_template_form_url = add_query_arg( |
|
| 1189 | + array('action' => $action, 'noheader' => true), |
|
| 1190 | + EE_MSG_ADMIN_URL |
|
| 1191 | + ); |
|
| 1192 | + } else { |
|
| 1193 | + $action = 'update_message_template'; |
|
| 1194 | + //$button_both = true; |
|
| 1195 | + //$button_text = array(); |
|
| 1196 | + //$button_actions = array(); |
|
| 1197 | + //$referrer = $this->_admin_base_url; |
|
| 1198 | + $edit_message_template_form_url = add_query_arg( |
|
| 1199 | + array('action' => $action, 'noheader' => true), |
|
| 1200 | + EE_MSG_ADMIN_URL |
|
| 1201 | + ); |
|
| 1202 | + } |
|
| 1203 | + |
|
| 1204 | + //set active messenger for this view |
|
| 1205 | + $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 1206 | + $message_template_group->messenger() |
|
| 1207 | + ); |
|
| 1208 | + $this->_active_message_type_name = $message_template_group->message_type(); |
|
| 1209 | + |
|
| 1210 | + |
|
| 1211 | + //Do we have any validation errors? |
|
| 1212 | + $validators = $this->_get_transient(); |
|
| 1213 | + $v_fields = ! empty($validators) ? array_keys($validators) : array(); |
|
| 1214 | + |
|
| 1215 | + |
|
| 1216 | + //we need to assemble the title from Various details |
|
| 1217 | + $context_label = sprintf( |
|
| 1218 | + __('(%s %s)', 'event_espresso'), |
|
| 1219 | + $c_config[$context]['label'], |
|
| 1220 | + ucwords($c_label['label']) |
|
| 1221 | + ); |
|
| 1222 | + |
|
| 1223 | + $title = sprintf( |
|
| 1224 | + __(' %s %s Template %s', 'event_espresso'), |
|
| 1225 | + ucwords($message_template_group->messenger_obj()->label['singular']), |
|
| 1226 | + ucwords($message_template_group->message_type_obj()->label['singular']), |
|
| 1227 | + $context_label |
|
| 1228 | + ); |
|
| 1229 | + |
|
| 1230 | + $this->_template_args['GRP_ID'] = $GRP_ID; |
|
| 1231 | + $this->_template_args['message_template'] = $message_template_group; |
|
| 1232 | + $this->_template_args['is_extra_fields'] = false; |
|
| 1233 | + |
|
| 1234 | + |
|
| 1235 | + //let's get EEH_MSG_Template so we can get template form fields |
|
| 1236 | + $template_field_structure = EEH_MSG_Template::get_fields( |
|
| 1237 | + $message_template_group->messenger(), |
|
| 1238 | + $message_template_group->message_type() |
|
| 1239 | + ); |
|
| 1240 | + |
|
| 1241 | + if ( ! $template_field_structure) { |
|
| 1242 | + $template_field_structure = false; |
|
| 1243 | + $template_fields = __('There was an error in assembling the fields for this display (you should see an error message)', |
|
| 1244 | + 'event_espresso'); |
|
| 1245 | + } |
|
| 1246 | + |
|
| 1247 | + |
|
| 1248 | + $message_templates = $message_template_group->context_templates(); |
|
| 1249 | + |
|
| 1250 | + |
|
| 1251 | + //if we have the extra key.. then we need to remove the content index from the template_field_structure as it will get handled in the "extra" array. |
|
| 1252 | + if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) { |
|
| 1253 | + foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) { |
|
| 1254 | + unset($template_field_structure[$context][$reference_field]); |
|
| 1255 | + } |
|
| 1256 | + } |
|
| 1257 | + |
|
| 1258 | + //let's loop through the template_field_structure and actually assemble the input fields! |
|
| 1259 | + if ( ! empty($template_field_structure)) { |
|
| 1260 | + foreach ($template_field_structure[$context] as $template_field => $field_setup_array) { |
|
| 1261 | + //if this is an 'extra' template field then we need to remove any existing fields that are keyed up in the extra array and reset them. |
|
| 1262 | + if ($template_field == 'extra') { |
|
| 1263 | + $this->_template_args['is_extra_fields'] = true; |
|
| 1264 | + foreach ($field_setup_array as $reference_field => $new_fields_array) { |
|
| 1265 | + $message_template = $message_templates[$context][$reference_field]; |
|
| 1266 | + $content = $message_template instanceof EE_Message_Template |
|
| 1267 | + ? $message_template->get('MTP_content') |
|
| 1268 | + : ''; |
|
| 1269 | + foreach ($new_fields_array as $extra_field => $extra_array) { |
|
| 1270 | + //let's verify if we need this extra field via the shortcodes parameter. |
|
| 1271 | + $continue = false; |
|
| 1272 | + if (isset($extra_array['shortcodes_required'])) { |
|
| 1273 | + foreach ((array)$extra_array['shortcodes_required'] as $shortcode) { |
|
| 1274 | + if ( ! array_key_exists($shortcode, $this->_shortcodes)) { |
|
| 1275 | + $continue = true; |
|
| 1276 | + } |
|
| 1277 | + } |
|
| 1278 | + if ($continue) { |
|
| 1279 | + continue; |
|
| 1280 | + } |
|
| 1281 | + } |
|
| 1282 | 1282 | |
| 1283 | - $field_id = $reference_field . '-' . $extra_field . '-content'; |
|
| 1284 | - $template_form_fields[$field_id] = $extra_array; |
|
| 1285 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $reference_field . '][content][' . $extra_field . ']'; |
|
| 1286 | - $css_class = isset($extra_array['css_class']) ? $extra_array['css_class'] : ''; |
|
| 1283 | + $field_id = $reference_field . '-' . $extra_field . '-content'; |
|
| 1284 | + $template_form_fields[$field_id] = $extra_array; |
|
| 1285 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $reference_field . '][content][' . $extra_field . ']'; |
|
| 1286 | + $css_class = isset($extra_array['css_class']) ? $extra_array['css_class'] : ''; |
|
| 1287 | 1287 | |
| 1288 | - $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1289 | - && in_array($extra_field, $v_fields) |
|
| 1290 | - && |
|
| 1291 | - ( |
|
| 1292 | - is_array($validators[$extra_field]) |
|
| 1293 | - && isset($validators[$extra_field]['msg']) |
|
| 1294 | - ) |
|
| 1295 | - ? 'validate-error ' . $css_class |
|
| 1296 | - : $css_class; |
|
| 1288 | + $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1289 | + && in_array($extra_field, $v_fields) |
|
| 1290 | + && |
|
| 1291 | + ( |
|
| 1292 | + is_array($validators[$extra_field]) |
|
| 1293 | + && isset($validators[$extra_field]['msg']) |
|
| 1294 | + ) |
|
| 1295 | + ? 'validate-error ' . $css_class |
|
| 1296 | + : $css_class; |
|
| 1297 | 1297 | |
| 1298 | - $template_form_fields[$field_id]['value'] = ! empty($message_templates) && isset($content[$extra_field]) |
|
| 1299 | - ? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8")) |
|
| 1300 | - : ''; |
|
| 1298 | + $template_form_fields[$field_id]['value'] = ! empty($message_templates) && isset($content[$extra_field]) |
|
| 1299 | + ? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8")) |
|
| 1300 | + : ''; |
|
| 1301 | 1301 | |
| 1302 | - //do we have a validation error? if we do then let's use that value instead |
|
| 1303 | - $template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) ? $validators[$extra_field]['value'] : $template_form_fields[$field_id]['value']; |
|
| 1302 | + //do we have a validation error? if we do then let's use that value instead |
|
| 1303 | + $template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) ? $validators[$extra_field]['value'] : $template_form_fields[$field_id]['value']; |
|
| 1304 | 1304 | |
| 1305 | 1305 | |
| 1306 | - $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1306 | + $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1307 | 1307 | |
| 1308 | - //shortcode selector |
|
| 1309 | - $field_name_to_use = $extra_field == 'main' ? 'content' : $extra_field; |
|
| 1310 | - $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1311 | - $field_name_to_use, |
|
| 1312 | - $field_id |
|
| 1313 | - ); |
|
| 1308 | + //shortcode selector |
|
| 1309 | + $field_name_to_use = $extra_field == 'main' ? 'content' : $extra_field; |
|
| 1310 | + $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1311 | + $field_name_to_use, |
|
| 1312 | + $field_id |
|
| 1313 | + ); |
|
| 1314 | 1314 | |
| 1315 | - if (isset($extra_array['input']) && $extra_array['input'] == 'wp_editor') { |
|
| 1316 | - //we want to decode the entities |
|
| 1317 | - $template_form_fields[$field_id]['value'] = stripslashes( |
|
| 1318 | - html_entity_decode($template_form_fields[$field_id]['value'], ENT_QUOTES, "UTF-8") |
|
| 1319 | - ); |
|
| 1315 | + if (isset($extra_array['input']) && $extra_array['input'] == 'wp_editor') { |
|
| 1316 | + //we want to decode the entities |
|
| 1317 | + $template_form_fields[$field_id]['value'] = stripslashes( |
|
| 1318 | + html_entity_decode($template_form_fields[$field_id]['value'], ENT_QUOTES, "UTF-8") |
|
| 1319 | + ); |
|
| 1320 | 1320 | |
| 1321 | - }/**/ |
|
| 1322 | - } |
|
| 1323 | - $templatefield_MTP_id = $reference_field . '-MTP_ID'; |
|
| 1324 | - $templatefield_templatename_id = $reference_field . '-name'; |
|
| 1321 | + }/**/ |
|
| 1322 | + } |
|
| 1323 | + $templatefield_MTP_id = $reference_field . '-MTP_ID'; |
|
| 1324 | + $templatefield_templatename_id = $reference_field . '-name'; |
|
| 1325 | 1325 | |
| 1326 | - $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1327 | - 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]', |
|
| 1328 | - 'label' => null, |
|
| 1329 | - 'input' => 'hidden', |
|
| 1330 | - 'type' => 'int', |
|
| 1331 | - 'required' => false, |
|
| 1332 | - 'validation' => false, |
|
| 1333 | - 'value' => ! empty($message_templates) ? $message_template->ID() : '', |
|
| 1334 | - 'css_class' => '', |
|
| 1335 | - 'format' => '%d', |
|
| 1336 | - 'db-col' => 'MTP_ID' |
|
| 1337 | - ); |
|
| 1326 | + $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1327 | + 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]', |
|
| 1328 | + 'label' => null, |
|
| 1329 | + 'input' => 'hidden', |
|
| 1330 | + 'type' => 'int', |
|
| 1331 | + 'required' => false, |
|
| 1332 | + 'validation' => false, |
|
| 1333 | + 'value' => ! empty($message_templates) ? $message_template->ID() : '', |
|
| 1334 | + 'css_class' => '', |
|
| 1335 | + 'format' => '%d', |
|
| 1336 | + 'db-col' => 'MTP_ID' |
|
| 1337 | + ); |
|
| 1338 | 1338 | |
| 1339 | - $template_form_fields[$templatefield_templatename_id] = array( |
|
| 1340 | - 'name' => 'MTP_template_fields[' . $reference_field . '][name]', |
|
| 1341 | - 'label' => null, |
|
| 1342 | - 'input' => 'hidden', |
|
| 1343 | - 'type' => 'string', |
|
| 1344 | - 'required' => false, |
|
| 1345 | - 'validation' => true, |
|
| 1346 | - 'value' => $reference_field, |
|
| 1347 | - 'css_class' => '', |
|
| 1348 | - 'format' => '%s', |
|
| 1349 | - 'db-col' => 'MTP_template_field' |
|
| 1350 | - ); |
|
| 1351 | - } |
|
| 1352 | - continue; //skip the next stuff, we got the necessary fields here for this dataset. |
|
| 1353 | - } else { |
|
| 1354 | - $field_id = $template_field . '-content'; |
|
| 1355 | - $template_form_fields[$field_id] = $field_setup_array; |
|
| 1356 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $template_field . '][content]'; |
|
| 1357 | - $message_template = isset($message_templates[$context][$template_field]) |
|
| 1358 | - ? $message_templates[$context][$template_field] |
|
| 1359 | - : null; |
|
| 1360 | - $template_form_fields[$field_id]['value'] = ! empty($message_templates) |
|
| 1361 | - && is_array($message_templates[$context]) |
|
| 1362 | - && $message_template instanceof EE_Message_Template |
|
| 1363 | - ? $message_template->get('MTP_content') |
|
| 1364 | - : ''; |
|
| 1339 | + $template_form_fields[$templatefield_templatename_id] = array( |
|
| 1340 | + 'name' => 'MTP_template_fields[' . $reference_field . '][name]', |
|
| 1341 | + 'label' => null, |
|
| 1342 | + 'input' => 'hidden', |
|
| 1343 | + 'type' => 'string', |
|
| 1344 | + 'required' => false, |
|
| 1345 | + 'validation' => true, |
|
| 1346 | + 'value' => $reference_field, |
|
| 1347 | + 'css_class' => '', |
|
| 1348 | + 'format' => '%s', |
|
| 1349 | + 'db-col' => 'MTP_template_field' |
|
| 1350 | + ); |
|
| 1351 | + } |
|
| 1352 | + continue; //skip the next stuff, we got the necessary fields here for this dataset. |
|
| 1353 | + } else { |
|
| 1354 | + $field_id = $template_field . '-content'; |
|
| 1355 | + $template_form_fields[$field_id] = $field_setup_array; |
|
| 1356 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $template_field . '][content]'; |
|
| 1357 | + $message_template = isset($message_templates[$context][$template_field]) |
|
| 1358 | + ? $message_templates[$context][$template_field] |
|
| 1359 | + : null; |
|
| 1360 | + $template_form_fields[$field_id]['value'] = ! empty($message_templates) |
|
| 1361 | + && is_array($message_templates[$context]) |
|
| 1362 | + && $message_template instanceof EE_Message_Template |
|
| 1363 | + ? $message_template->get('MTP_content') |
|
| 1364 | + : ''; |
|
| 1365 | 1365 | |
| 1366 | - //do we have a validator error for this field? if we do then we'll use that value instead |
|
| 1367 | - $template_form_fields[$field_id]['value'] = isset($validators[$template_field]) |
|
| 1368 | - ? $validators[$template_field]['value'] |
|
| 1369 | - : $template_form_fields[$field_id]['value']; |
|
| 1366 | + //do we have a validator error for this field? if we do then we'll use that value instead |
|
| 1367 | + $template_form_fields[$field_id]['value'] = isset($validators[$template_field]) |
|
| 1368 | + ? $validators[$template_field]['value'] |
|
| 1369 | + : $template_form_fields[$field_id]['value']; |
|
| 1370 | 1370 | |
| 1371 | 1371 | |
| 1372 | - $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1373 | - $css_class = isset($field_setup_array['css_class']) ? $field_setup_array['css_class'] : ''; |
|
| 1374 | - $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1375 | - && in_array($template_field, $v_fields) |
|
| 1376 | - && isset($validators[$template_field]['msg']) |
|
| 1377 | - ? 'validate-error ' . $css_class |
|
| 1378 | - : $css_class; |
|
| 1372 | + $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1373 | + $css_class = isset($field_setup_array['css_class']) ? $field_setup_array['css_class'] : ''; |
|
| 1374 | + $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1375 | + && in_array($template_field, $v_fields) |
|
| 1376 | + && isset($validators[$template_field]['msg']) |
|
| 1377 | + ? 'validate-error ' . $css_class |
|
| 1378 | + : $css_class; |
|
| 1379 | 1379 | |
| 1380 | - //shortcode selector |
|
| 1381 | - $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1382 | - $template_field, $field_id |
|
| 1383 | - ); |
|
| 1384 | - } |
|
| 1380 | + //shortcode selector |
|
| 1381 | + $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1382 | + $template_field, $field_id |
|
| 1383 | + ); |
|
| 1384 | + } |
|
| 1385 | 1385 | |
| 1386 | - //k took care of content field(s) now let's take care of others. |
|
| 1386 | + //k took care of content field(s) now let's take care of others. |
|
| 1387 | 1387 | |
| 1388 | - $templatefield_MTP_id = $template_field . '-MTP_ID'; |
|
| 1389 | - $templatefield_field_templatename_id = $template_field . '-name'; |
|
| 1388 | + $templatefield_MTP_id = $template_field . '-MTP_ID'; |
|
| 1389 | + $templatefield_field_templatename_id = $template_field . '-name'; |
|
| 1390 | 1390 | |
| 1391 | - //foreach template field there are actually two form fields created |
|
| 1392 | - $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1393 | - 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]', |
|
| 1394 | - 'label' => null, |
|
| 1395 | - 'input' => 'hidden', |
|
| 1396 | - 'type' => 'int', |
|
| 1397 | - 'required' => false, |
|
| 1398 | - 'validation' => true, |
|
| 1399 | - 'value' => $message_template instanceof EE_Message_Template ? $message_template->ID() : '', |
|
| 1400 | - 'css_class' => '', |
|
| 1401 | - 'format' => '%d', |
|
| 1402 | - 'db-col' => 'MTP_ID' |
|
| 1403 | - ); |
|
| 1391 | + //foreach template field there are actually two form fields created |
|
| 1392 | + $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1393 | + 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]', |
|
| 1394 | + 'label' => null, |
|
| 1395 | + 'input' => 'hidden', |
|
| 1396 | + 'type' => 'int', |
|
| 1397 | + 'required' => false, |
|
| 1398 | + 'validation' => true, |
|
| 1399 | + 'value' => $message_template instanceof EE_Message_Template ? $message_template->ID() : '', |
|
| 1400 | + 'css_class' => '', |
|
| 1401 | + 'format' => '%d', |
|
| 1402 | + 'db-col' => 'MTP_ID' |
|
| 1403 | + ); |
|
| 1404 | 1404 | |
| 1405 | - $template_form_fields[$templatefield_field_templatename_id] = array( |
|
| 1406 | - 'name' => 'MTP_template_fields[' . $template_field . '][name]', |
|
| 1407 | - 'label' => null, |
|
| 1408 | - 'input' => 'hidden', |
|
| 1409 | - 'type' => 'string', |
|
| 1410 | - 'required' => false, |
|
| 1411 | - 'validation' => true, |
|
| 1412 | - 'value' => $template_field, |
|
| 1413 | - 'css_class' => '', |
|
| 1414 | - 'format' => '%s', |
|
| 1415 | - 'db-col' => 'MTP_template_field' |
|
| 1416 | - ); |
|
| 1405 | + $template_form_fields[$templatefield_field_templatename_id] = array( |
|
| 1406 | + 'name' => 'MTP_template_fields[' . $template_field . '][name]', |
|
| 1407 | + 'label' => null, |
|
| 1408 | + 'input' => 'hidden', |
|
| 1409 | + 'type' => 'string', |
|
| 1410 | + 'required' => false, |
|
| 1411 | + 'validation' => true, |
|
| 1412 | + 'value' => $template_field, |
|
| 1413 | + 'css_class' => '', |
|
| 1414 | + 'format' => '%s', |
|
| 1415 | + 'db-col' => 'MTP_template_field' |
|
| 1416 | + ); |
|
| 1417 | 1417 | |
| 1418 | - } |
|
| 1418 | + } |
|
| 1419 | 1419 | |
| 1420 | - //add other fields |
|
| 1421 | - $template_form_fields['ee-msg-current-context'] = array( |
|
| 1422 | - 'name' => 'MTP_context', |
|
| 1423 | - 'label' => null, |
|
| 1424 | - 'input' => 'hidden', |
|
| 1425 | - 'type' => 'string', |
|
| 1426 | - 'required' => false, |
|
| 1427 | - 'validation' => true, |
|
| 1428 | - 'value' => $context, |
|
| 1429 | - 'css_class' => '', |
|
| 1430 | - 'format' => '%s', |
|
| 1431 | - 'db-col' => 'MTP_context' |
|
| 1432 | - ); |
|
| 1420 | + //add other fields |
|
| 1421 | + $template_form_fields['ee-msg-current-context'] = array( |
|
| 1422 | + 'name' => 'MTP_context', |
|
| 1423 | + 'label' => null, |
|
| 1424 | + 'input' => 'hidden', |
|
| 1425 | + 'type' => 'string', |
|
| 1426 | + 'required' => false, |
|
| 1427 | + 'validation' => true, |
|
| 1428 | + 'value' => $context, |
|
| 1429 | + 'css_class' => '', |
|
| 1430 | + 'format' => '%s', |
|
| 1431 | + 'db-col' => 'MTP_context' |
|
| 1432 | + ); |
|
| 1433 | 1433 | |
| 1434 | - $template_form_fields['ee-msg-grp-id'] = array( |
|
| 1435 | - 'name' => 'GRP_ID', |
|
| 1436 | - 'label' => null, |
|
| 1437 | - 'input' => 'hidden', |
|
| 1438 | - 'type' => 'int', |
|
| 1439 | - 'required' => false, |
|
| 1440 | - 'validation' => true, |
|
| 1441 | - 'value' => $GRP_ID, |
|
| 1442 | - 'css_class' => '', |
|
| 1443 | - 'format' => '%d', |
|
| 1444 | - 'db-col' => 'GRP_ID' |
|
| 1445 | - ); |
|
| 1434 | + $template_form_fields['ee-msg-grp-id'] = array( |
|
| 1435 | + 'name' => 'GRP_ID', |
|
| 1436 | + 'label' => null, |
|
| 1437 | + 'input' => 'hidden', |
|
| 1438 | + 'type' => 'int', |
|
| 1439 | + 'required' => false, |
|
| 1440 | + 'validation' => true, |
|
| 1441 | + 'value' => $GRP_ID, |
|
| 1442 | + 'css_class' => '', |
|
| 1443 | + 'format' => '%d', |
|
| 1444 | + 'db-col' => 'GRP_ID' |
|
| 1445 | + ); |
|
| 1446 | 1446 | |
| 1447 | - $template_form_fields['ee-msg-messenger'] = array( |
|
| 1448 | - 'name' => 'MTP_messenger', |
|
| 1449 | - 'label' => null, |
|
| 1450 | - 'input' => 'hidden', |
|
| 1451 | - 'type' => 'string', |
|
| 1452 | - 'required' => false, |
|
| 1453 | - 'validation' => true, |
|
| 1454 | - 'value' => $message_template_group->messenger(), |
|
| 1455 | - 'css_class' => '', |
|
| 1456 | - 'format' => '%s', |
|
| 1457 | - 'db-col' => 'MTP_messenger' |
|
| 1458 | - ); |
|
| 1447 | + $template_form_fields['ee-msg-messenger'] = array( |
|
| 1448 | + 'name' => 'MTP_messenger', |
|
| 1449 | + 'label' => null, |
|
| 1450 | + 'input' => 'hidden', |
|
| 1451 | + 'type' => 'string', |
|
| 1452 | + 'required' => false, |
|
| 1453 | + 'validation' => true, |
|
| 1454 | + 'value' => $message_template_group->messenger(), |
|
| 1455 | + 'css_class' => '', |
|
| 1456 | + 'format' => '%s', |
|
| 1457 | + 'db-col' => 'MTP_messenger' |
|
| 1458 | + ); |
|
| 1459 | 1459 | |
| 1460 | - $template_form_fields['ee-msg-message-type'] = array( |
|
| 1461 | - 'name' => 'MTP_message_type', |
|
| 1462 | - 'label' => null, |
|
| 1463 | - 'input' => 'hidden', |
|
| 1464 | - 'type' => 'string', |
|
| 1465 | - 'required' => false, |
|
| 1466 | - 'validation' => true, |
|
| 1467 | - 'value' => $message_template_group->message_type(), |
|
| 1468 | - 'css_class' => '', |
|
| 1469 | - 'format' => '%s', |
|
| 1470 | - 'db-col' => 'MTP_message_type' |
|
| 1471 | - ); |
|
| 1460 | + $template_form_fields['ee-msg-message-type'] = array( |
|
| 1461 | + 'name' => 'MTP_message_type', |
|
| 1462 | + 'label' => null, |
|
| 1463 | + 'input' => 'hidden', |
|
| 1464 | + 'type' => 'string', |
|
| 1465 | + 'required' => false, |
|
| 1466 | + 'validation' => true, |
|
| 1467 | + 'value' => $message_template_group->message_type(), |
|
| 1468 | + 'css_class' => '', |
|
| 1469 | + 'format' => '%s', |
|
| 1470 | + 'db-col' => 'MTP_message_type' |
|
| 1471 | + ); |
|
| 1472 | 1472 | |
| 1473 | - $sidebar_form_fields['ee-msg-is-global'] = array( |
|
| 1474 | - 'name' => 'MTP_is_global', |
|
| 1475 | - 'label' => __('Global Template', 'event_espresso'), |
|
| 1476 | - 'input' => 'hidden', |
|
| 1477 | - 'type' => 'int', |
|
| 1478 | - 'required' => false, |
|
| 1479 | - 'validation' => true, |
|
| 1480 | - 'value' => $message_template_group->get('MTP_is_global'), |
|
| 1481 | - 'css_class' => '', |
|
| 1482 | - 'format' => '%d', |
|
| 1483 | - 'db-col' => 'MTP_is_global' |
|
| 1484 | - ); |
|
| 1473 | + $sidebar_form_fields['ee-msg-is-global'] = array( |
|
| 1474 | + 'name' => 'MTP_is_global', |
|
| 1475 | + 'label' => __('Global Template', 'event_espresso'), |
|
| 1476 | + 'input' => 'hidden', |
|
| 1477 | + 'type' => 'int', |
|
| 1478 | + 'required' => false, |
|
| 1479 | + 'validation' => true, |
|
| 1480 | + 'value' => $message_template_group->get('MTP_is_global'), |
|
| 1481 | + 'css_class' => '', |
|
| 1482 | + 'format' => '%d', |
|
| 1483 | + 'db-col' => 'MTP_is_global' |
|
| 1484 | + ); |
|
| 1485 | 1485 | |
| 1486 | - $sidebar_form_fields['ee-msg-is-override'] = array( |
|
| 1487 | - 'name' => 'MTP_is_override', |
|
| 1488 | - 'label' => __('Override all custom', 'event_espresso'), |
|
| 1489 | - 'input' => $message_template_group->is_global() ? 'checkbox' : 'hidden', |
|
| 1490 | - 'type' => 'int', |
|
| 1491 | - 'required' => false, |
|
| 1492 | - 'validation' => true, |
|
| 1493 | - 'value' => $message_template_group->get('MTP_is_override'), |
|
| 1494 | - 'css_class' => '', |
|
| 1495 | - 'format' => '%d', |
|
| 1496 | - 'db-col' => 'MTP_is_override' |
|
| 1497 | - ); |
|
| 1486 | + $sidebar_form_fields['ee-msg-is-override'] = array( |
|
| 1487 | + 'name' => 'MTP_is_override', |
|
| 1488 | + 'label' => __('Override all custom', 'event_espresso'), |
|
| 1489 | + 'input' => $message_template_group->is_global() ? 'checkbox' : 'hidden', |
|
| 1490 | + 'type' => 'int', |
|
| 1491 | + 'required' => false, |
|
| 1492 | + 'validation' => true, |
|
| 1493 | + 'value' => $message_template_group->get('MTP_is_override'), |
|
| 1494 | + 'css_class' => '', |
|
| 1495 | + 'format' => '%d', |
|
| 1496 | + 'db-col' => 'MTP_is_override' |
|
| 1497 | + ); |
|
| 1498 | 1498 | |
| 1499 | - $sidebar_form_fields['ee-msg-is-active'] = array( |
|
| 1500 | - 'name' => 'MTP_is_active', |
|
| 1501 | - 'label' => __('Active Template', 'event_espresso'), |
|
| 1502 | - 'input' => 'hidden', |
|
| 1503 | - 'type' => 'int', |
|
| 1504 | - 'required' => false, |
|
| 1505 | - 'validation' => true, |
|
| 1506 | - 'value' => $message_template_group->is_active(), |
|
| 1507 | - 'css_class' => '', |
|
| 1508 | - 'format' => '%d', |
|
| 1509 | - 'db-col' => 'MTP_is_active' |
|
| 1510 | - ); |
|
| 1499 | + $sidebar_form_fields['ee-msg-is-active'] = array( |
|
| 1500 | + 'name' => 'MTP_is_active', |
|
| 1501 | + 'label' => __('Active Template', 'event_espresso'), |
|
| 1502 | + 'input' => 'hidden', |
|
| 1503 | + 'type' => 'int', |
|
| 1504 | + 'required' => false, |
|
| 1505 | + 'validation' => true, |
|
| 1506 | + 'value' => $message_template_group->is_active(), |
|
| 1507 | + 'css_class' => '', |
|
| 1508 | + 'format' => '%d', |
|
| 1509 | + 'db-col' => 'MTP_is_active' |
|
| 1510 | + ); |
|
| 1511 | 1511 | |
| 1512 | - $sidebar_form_fields['ee-msg-deleted'] = array( |
|
| 1513 | - 'name' => 'MTP_deleted', |
|
| 1514 | - 'label' => null, |
|
| 1515 | - 'input' => 'hidden', |
|
| 1516 | - 'type' => 'int', |
|
| 1517 | - 'required' => false, |
|
| 1518 | - 'validation' => true, |
|
| 1519 | - 'value' => $message_template_group->get('MTP_deleted'), |
|
| 1520 | - 'css_class' => '', |
|
| 1521 | - 'format' => '%d', |
|
| 1522 | - 'db-col' => 'MTP_deleted' |
|
| 1523 | - ); |
|
| 1524 | - $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1525 | - 'name' => 'MTP_user_id', |
|
| 1526 | - 'label' => __('Author', 'event_espresso'), |
|
| 1527 | - 'input' => 'hidden', |
|
| 1528 | - 'type' => 'int', |
|
| 1529 | - 'required' => false, |
|
| 1530 | - 'validation' => false, |
|
| 1531 | - 'value' => $message_template_group->user(), |
|
| 1532 | - 'format' => '%d', |
|
| 1533 | - 'db-col' => 'MTP_user_id' |
|
| 1534 | - ); |
|
| 1512 | + $sidebar_form_fields['ee-msg-deleted'] = array( |
|
| 1513 | + 'name' => 'MTP_deleted', |
|
| 1514 | + 'label' => null, |
|
| 1515 | + 'input' => 'hidden', |
|
| 1516 | + 'type' => 'int', |
|
| 1517 | + 'required' => false, |
|
| 1518 | + 'validation' => true, |
|
| 1519 | + 'value' => $message_template_group->get('MTP_deleted'), |
|
| 1520 | + 'css_class' => '', |
|
| 1521 | + 'format' => '%d', |
|
| 1522 | + 'db-col' => 'MTP_deleted' |
|
| 1523 | + ); |
|
| 1524 | + $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1525 | + 'name' => 'MTP_user_id', |
|
| 1526 | + 'label' => __('Author', 'event_espresso'), |
|
| 1527 | + 'input' => 'hidden', |
|
| 1528 | + 'type' => 'int', |
|
| 1529 | + 'required' => false, |
|
| 1530 | + 'validation' => false, |
|
| 1531 | + 'value' => $message_template_group->user(), |
|
| 1532 | + 'format' => '%d', |
|
| 1533 | + 'db-col' => 'MTP_user_id' |
|
| 1534 | + ); |
|
| 1535 | 1535 | |
| 1536 | - $sidebar_form_fields['ee-msg-route'] = array( |
|
| 1537 | - 'name' => 'action', |
|
| 1538 | - 'input' => 'hidden', |
|
| 1539 | - 'type' => 'string', |
|
| 1540 | - 'value' => $action |
|
| 1541 | - ); |
|
| 1536 | + $sidebar_form_fields['ee-msg-route'] = array( |
|
| 1537 | + 'name' => 'action', |
|
| 1538 | + 'input' => 'hidden', |
|
| 1539 | + 'type' => 'string', |
|
| 1540 | + 'value' => $action |
|
| 1541 | + ); |
|
| 1542 | 1542 | |
| 1543 | - $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1544 | - 'name' => 'id', |
|
| 1545 | - 'input' => 'hidden', |
|
| 1546 | - 'type' => 'int', |
|
| 1547 | - 'value' => $GRP_ID |
|
| 1548 | - ); |
|
| 1549 | - $sidebar_form_fields['ee-msg-evt-nonce'] = array( |
|
| 1550 | - 'name' => $action . '_nonce', |
|
| 1551 | - 'input' => 'hidden', |
|
| 1552 | - 'type' => 'string', |
|
| 1553 | - 'value' => wp_create_nonce($action . '_nonce') |
|
| 1554 | - ); |
|
| 1543 | + $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1544 | + 'name' => 'id', |
|
| 1545 | + 'input' => 'hidden', |
|
| 1546 | + 'type' => 'int', |
|
| 1547 | + 'value' => $GRP_ID |
|
| 1548 | + ); |
|
| 1549 | + $sidebar_form_fields['ee-msg-evt-nonce'] = array( |
|
| 1550 | + 'name' => $action . '_nonce', |
|
| 1551 | + 'input' => 'hidden', |
|
| 1552 | + 'type' => 'string', |
|
| 1553 | + 'value' => wp_create_nonce($action . '_nonce') |
|
| 1554 | + ); |
|
| 1555 | 1555 | |
| 1556 | - if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { |
|
| 1557 | - $sidebar_form_fields['ee-msg-template-switch'] = array( |
|
| 1558 | - 'name' => 'template_switch', |
|
| 1559 | - 'input' => 'hidden', |
|
| 1560 | - 'type' => 'int', |
|
| 1561 | - 'value' => 1 |
|
| 1562 | - ); |
|
| 1563 | - } |
|
| 1556 | + if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { |
|
| 1557 | + $sidebar_form_fields['ee-msg-template-switch'] = array( |
|
| 1558 | + 'name' => 'template_switch', |
|
| 1559 | + 'input' => 'hidden', |
|
| 1560 | + 'type' => 'int', |
|
| 1561 | + 'value' => 1 |
|
| 1562 | + ); |
|
| 1563 | + } |
|
| 1564 | 1564 | |
| 1565 | 1565 | |
| 1566 | - $template_fields = $this->_generate_admin_form_fields($template_form_fields); |
|
| 1567 | - $sidebar_fields = $this->_generate_admin_form_fields($sidebar_form_fields); |
|
| 1566 | + $template_fields = $this->_generate_admin_form_fields($template_form_fields); |
|
| 1567 | + $sidebar_fields = $this->_generate_admin_form_fields($sidebar_form_fields); |
|
| 1568 | 1568 | |
| 1569 | 1569 | |
| 1570 | - } //end if ( !empty($template_field_structure) ) |
|
| 1570 | + } //end if ( !empty($template_field_structure) ) |
|
| 1571 | 1571 | |
| 1572 | - //set extra content for publish box |
|
| 1573 | - $this->_template_args['publish_box_extra_content'] = $sidebar_fields; |
|
| 1574 | - $this->_set_publish_post_box_vars( |
|
| 1575 | - 'id', |
|
| 1576 | - $GRP_ID, |
|
| 1577 | - false, |
|
| 1578 | - add_query_arg( |
|
| 1579 | - array('action' => 'global_mtps'), |
|
| 1580 | - $this->_admin_base_url |
|
| 1581 | - ) |
|
| 1582 | - ); |
|
| 1583 | - |
|
| 1584 | - //add preview button |
|
| 1585 | - $preview_url = parent::add_query_args_and_nonce( |
|
| 1586 | - array( |
|
| 1587 | - 'message_type' => $message_template_group->message_type(), |
|
| 1588 | - 'messenger' => $message_template_group->messenger(), |
|
| 1589 | - 'context' => $context, |
|
| 1590 | - 'GRP_ID' => $GRP_ID, |
|
| 1591 | - 'action' => 'preview_message' |
|
| 1592 | - ), |
|
| 1593 | - $this->_admin_base_url |
|
| 1594 | - ); |
|
| 1595 | - $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' . __('Preview', |
|
| 1596 | - 'event_espresso') . '</a>'; |
|
| 1597 | - |
|
| 1598 | - |
|
| 1599 | - //setup context switcher |
|
| 1600 | - $context_switcher_args = array( |
|
| 1601 | - 'page' => 'espresso_messages', |
|
| 1602 | - 'action' => 'edit_message_template', |
|
| 1603 | - 'id' => $GRP_ID, |
|
| 1604 | - 'context' => $context, |
|
| 1605 | - 'extra' => $preview_button |
|
| 1606 | - ); |
|
| 1607 | - $this->_set_context_switcher($message_template_group, $context_switcher_args); |
|
| 1608 | - |
|
| 1609 | - |
|
| 1610 | - //main box |
|
| 1611 | - $this->_template_args['template_fields'] = $template_fields; |
|
| 1612 | - $this->_template_args['sidebar_box_id'] = 'details'; |
|
| 1613 | - $this->_template_args['action'] = $action; |
|
| 1614 | - $this->_template_args['context'] = $context; |
|
| 1615 | - $this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url; |
|
| 1616 | - $this->_template_args['learn_more_about_message_templates_link'] = $this->_learn_more_about_message_templates_link(); |
|
| 1617 | - |
|
| 1618 | - |
|
| 1619 | - $this->_template_args['before_admin_page_content'] = $this->add_context_switcher(); |
|
| 1620 | - $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before(); |
|
| 1621 | - $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after(); |
|
| 1622 | - |
|
| 1623 | - $this->_template_path = $this->_template_args['GRP_ID'] |
|
| 1624 | - ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php' |
|
| 1625 | - : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1626 | - |
|
| 1627 | - //send along EE_Message_Template_Group object for further template use. |
|
| 1628 | - $this->_template_args['MTP'] = $message_template_group; |
|
| 1629 | - |
|
| 1630 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
|
| 1631 | - $this->_template_args, true); |
|
| 1632 | - |
|
| 1633 | - |
|
| 1634 | - //finally, let's set the admin_page title |
|
| 1635 | - $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title); |
|
| 1636 | - |
|
| 1637 | - |
|
| 1638 | - //we need to take care of setting the shortcodes property for use elsewhere. |
|
| 1639 | - $this->_set_shortcodes(); |
|
| 1640 | - |
|
| 1641 | - |
|
| 1642 | - //final template wrapper |
|
| 1643 | - $this->display_admin_page_with_sidebar(); |
|
| 1644 | - } |
|
| 1645 | - |
|
| 1646 | - |
|
| 1647 | - public function filter_tinymce_init($mceInit, $editor_id) |
|
| 1648 | - { |
|
| 1649 | - return $mceInit; |
|
| 1650 | - } |
|
| 1651 | - |
|
| 1652 | - |
|
| 1653 | - public function add_context_switcher() |
|
| 1654 | - { |
|
| 1655 | - return $this->_context_switcher; |
|
| 1656 | - } |
|
| 1657 | - |
|
| 1658 | - public function _add_form_element_before() |
|
| 1659 | - { |
|
| 1660 | - return '<form method="post" action="' . $this->_template_args["edit_message_template_form_url"] . '" id="ee-msg-edit-frm">'; |
|
| 1661 | - } |
|
| 1662 | - |
|
| 1663 | - public function _add_form_element_after() |
|
| 1664 | - { |
|
| 1665 | - return '</form>'; |
|
| 1666 | - } |
|
| 1667 | - |
|
| 1668 | - |
|
| 1669 | - /** |
|
| 1670 | - * This executes switching the template pack for a message template. |
|
| 1671 | - * |
|
| 1672 | - * @since 4.5.0 |
|
| 1673 | - * |
|
| 1674 | - */ |
|
| 1675 | - public function switch_template_pack() |
|
| 1676 | - { |
|
| 1677 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 1678 | - $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : ''; |
|
| 1679 | - |
|
| 1680 | - //verify we have needed values. |
|
| 1681 | - if (empty($GRP_ID) || empty($template_pack)) { |
|
| 1682 | - $this->_template_args['error'] = true; |
|
| 1683 | - EE_Error::add_error(__('The required date for switching templates is not available.', 'event_espresso'), |
|
| 1684 | - __FILE__, __FUNCTION__, __LINE__); |
|
| 1685 | - } else { |
|
| 1686 | - //get template, set the new template_pack and then reset to default |
|
| 1687 | - /** @type EE_Message_Template_Group $message_template_group */ |
|
| 1688 | - $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
| 1572 | + //set extra content for publish box |
|
| 1573 | + $this->_template_args['publish_box_extra_content'] = $sidebar_fields; |
|
| 1574 | + $this->_set_publish_post_box_vars( |
|
| 1575 | + 'id', |
|
| 1576 | + $GRP_ID, |
|
| 1577 | + false, |
|
| 1578 | + add_query_arg( |
|
| 1579 | + array('action' => 'global_mtps'), |
|
| 1580 | + $this->_admin_base_url |
|
| 1581 | + ) |
|
| 1582 | + ); |
|
| 1583 | + |
|
| 1584 | + //add preview button |
|
| 1585 | + $preview_url = parent::add_query_args_and_nonce( |
|
| 1586 | + array( |
|
| 1587 | + 'message_type' => $message_template_group->message_type(), |
|
| 1588 | + 'messenger' => $message_template_group->messenger(), |
|
| 1589 | + 'context' => $context, |
|
| 1590 | + 'GRP_ID' => $GRP_ID, |
|
| 1591 | + 'action' => 'preview_message' |
|
| 1592 | + ), |
|
| 1593 | + $this->_admin_base_url |
|
| 1594 | + ); |
|
| 1595 | + $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' . __('Preview', |
|
| 1596 | + 'event_espresso') . '</a>'; |
|
| 1597 | + |
|
| 1598 | + |
|
| 1599 | + //setup context switcher |
|
| 1600 | + $context_switcher_args = array( |
|
| 1601 | + 'page' => 'espresso_messages', |
|
| 1602 | + 'action' => 'edit_message_template', |
|
| 1603 | + 'id' => $GRP_ID, |
|
| 1604 | + 'context' => $context, |
|
| 1605 | + 'extra' => $preview_button |
|
| 1606 | + ); |
|
| 1607 | + $this->_set_context_switcher($message_template_group, $context_switcher_args); |
|
| 1608 | + |
|
| 1609 | + |
|
| 1610 | + //main box |
|
| 1611 | + $this->_template_args['template_fields'] = $template_fields; |
|
| 1612 | + $this->_template_args['sidebar_box_id'] = 'details'; |
|
| 1613 | + $this->_template_args['action'] = $action; |
|
| 1614 | + $this->_template_args['context'] = $context; |
|
| 1615 | + $this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url; |
|
| 1616 | + $this->_template_args['learn_more_about_message_templates_link'] = $this->_learn_more_about_message_templates_link(); |
|
| 1617 | + |
|
| 1618 | + |
|
| 1619 | + $this->_template_args['before_admin_page_content'] = $this->add_context_switcher(); |
|
| 1620 | + $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before(); |
|
| 1621 | + $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after(); |
|
| 1622 | + |
|
| 1623 | + $this->_template_path = $this->_template_args['GRP_ID'] |
|
| 1624 | + ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php' |
|
| 1625 | + : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1626 | + |
|
| 1627 | + //send along EE_Message_Template_Group object for further template use. |
|
| 1628 | + $this->_template_args['MTP'] = $message_template_group; |
|
| 1629 | + |
|
| 1630 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
|
| 1631 | + $this->_template_args, true); |
|
| 1632 | + |
|
| 1633 | + |
|
| 1634 | + //finally, let's set the admin_page title |
|
| 1635 | + $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title); |
|
| 1636 | + |
|
| 1637 | + |
|
| 1638 | + //we need to take care of setting the shortcodes property for use elsewhere. |
|
| 1639 | + $this->_set_shortcodes(); |
|
| 1640 | + |
|
| 1641 | + |
|
| 1642 | + //final template wrapper |
|
| 1643 | + $this->display_admin_page_with_sidebar(); |
|
| 1644 | + } |
|
| 1645 | + |
|
| 1646 | + |
|
| 1647 | + public function filter_tinymce_init($mceInit, $editor_id) |
|
| 1648 | + { |
|
| 1649 | + return $mceInit; |
|
| 1650 | + } |
|
| 1651 | + |
|
| 1652 | + |
|
| 1653 | + public function add_context_switcher() |
|
| 1654 | + { |
|
| 1655 | + return $this->_context_switcher; |
|
| 1656 | + } |
|
| 1657 | + |
|
| 1658 | + public function _add_form_element_before() |
|
| 1659 | + { |
|
| 1660 | + return '<form method="post" action="' . $this->_template_args["edit_message_template_form_url"] . '" id="ee-msg-edit-frm">'; |
|
| 1661 | + } |
|
| 1662 | + |
|
| 1663 | + public function _add_form_element_after() |
|
| 1664 | + { |
|
| 1665 | + return '</form>'; |
|
| 1666 | + } |
|
| 1667 | + |
|
| 1668 | + |
|
| 1669 | + /** |
|
| 1670 | + * This executes switching the template pack for a message template. |
|
| 1671 | + * |
|
| 1672 | + * @since 4.5.0 |
|
| 1673 | + * |
|
| 1674 | + */ |
|
| 1675 | + public function switch_template_pack() |
|
| 1676 | + { |
|
| 1677 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 1678 | + $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : ''; |
|
| 1679 | + |
|
| 1680 | + //verify we have needed values. |
|
| 1681 | + if (empty($GRP_ID) || empty($template_pack)) { |
|
| 1682 | + $this->_template_args['error'] = true; |
|
| 1683 | + EE_Error::add_error(__('The required date for switching templates is not available.', 'event_espresso'), |
|
| 1684 | + __FILE__, __FUNCTION__, __LINE__); |
|
| 1685 | + } else { |
|
| 1686 | + //get template, set the new template_pack and then reset to default |
|
| 1687 | + /** @type EE_Message_Template_Group $message_template_group */ |
|
| 1688 | + $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
| 1689 | 1689 | |
| 1690 | - $message_template_group->set_template_pack_name($template_pack); |
|
| 1691 | - $this->_req_data['msgr'] = $message_template_group->messenger(); |
|
| 1692 | - $this->_req_data['mt'] = $message_template_group->message_type(); |
|
| 1690 | + $message_template_group->set_template_pack_name($template_pack); |
|
| 1691 | + $this->_req_data['msgr'] = $message_template_group->messenger(); |
|
| 1692 | + $this->_req_data['mt'] = $message_template_group->message_type(); |
|
| 1693 | 1693 | |
| 1694 | - $query_args = $this->_reset_to_default_template(); |
|
| 1694 | + $query_args = $this->_reset_to_default_template(); |
|
| 1695 | 1695 | |
| 1696 | - if (empty($query_args['id'])) { |
|
| 1697 | - EE_Error::add_error( |
|
| 1698 | - __( |
|
| 1699 | - 'Something went wrong with switching the template pack. Please try again or contact EE support', |
|
| 1700 | - 'event_espresso' |
|
| 1701 | - ), |
|
| 1702 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1703 | - ); |
|
| 1704 | - $this->_template_args['error'] = true; |
|
| 1705 | - } else { |
|
| 1706 | - $template_label = $message_template_group->get_template_pack()->label; |
|
| 1707 | - $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels(); |
|
| 1708 | - EE_Error::add_success( |
|
| 1709 | - sprintf( |
|
| 1710 | - __( |
|
| 1711 | - 'This message template has been successfully switched to use the %1$s %2$s. Please wait while the page reloads with your new template.', |
|
| 1712 | - 'event_espresso' |
|
| 1713 | - ), |
|
| 1714 | - $template_label, |
|
| 1715 | - $template_pack_labels->template_pack |
|
| 1716 | - ) |
|
| 1717 | - ); |
|
| 1718 | - //generate the redirect url for js. |
|
| 1719 | - $url = self::add_query_args_and_nonce($query_args, |
|
| 1720 | - $this->_admin_base_url); |
|
| 1721 | - $this->_template_args['data']['redirect_url'] = $url; |
|
| 1722 | - $this->_template_args['success'] = true; |
|
| 1723 | - } |
|
| 1696 | + if (empty($query_args['id'])) { |
|
| 1697 | + EE_Error::add_error( |
|
| 1698 | + __( |
|
| 1699 | + 'Something went wrong with switching the template pack. Please try again or contact EE support', |
|
| 1700 | + 'event_espresso' |
|
| 1701 | + ), |
|
| 1702 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1703 | + ); |
|
| 1704 | + $this->_template_args['error'] = true; |
|
| 1705 | + } else { |
|
| 1706 | + $template_label = $message_template_group->get_template_pack()->label; |
|
| 1707 | + $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels(); |
|
| 1708 | + EE_Error::add_success( |
|
| 1709 | + sprintf( |
|
| 1710 | + __( |
|
| 1711 | + 'This message template has been successfully switched to use the %1$s %2$s. Please wait while the page reloads with your new template.', |
|
| 1712 | + 'event_espresso' |
|
| 1713 | + ), |
|
| 1714 | + $template_label, |
|
| 1715 | + $template_pack_labels->template_pack |
|
| 1716 | + ) |
|
| 1717 | + ); |
|
| 1718 | + //generate the redirect url for js. |
|
| 1719 | + $url = self::add_query_args_and_nonce($query_args, |
|
| 1720 | + $this->_admin_base_url); |
|
| 1721 | + $this->_template_args['data']['redirect_url'] = $url; |
|
| 1722 | + $this->_template_args['success'] = true; |
|
| 1723 | + } |
|
| 1724 | 1724 | |
| 1725 | - $this->_return_json(); |
|
| 1725 | + $this->_return_json(); |
|
| 1726 | 1726 | |
| 1727 | - } |
|
| 1728 | - } |
|
| 1729 | - |
|
| 1730 | - |
|
| 1731 | - /** |
|
| 1732 | - * This handles resetting the template for the given messenger/message_type so that users can start from scratch if |
|
| 1733 | - * they want. |
|
| 1734 | - * |
|
| 1735 | - * @access protected |
|
| 1736 | - * @return array|null |
|
| 1737 | - */ |
|
| 1738 | - protected function _reset_to_default_template() |
|
| 1739 | - { |
|
| 1740 | - |
|
| 1741 | - $templates = array(); |
|
| 1742 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 1743 | - //we need to make sure we've got the info we need. |
|
| 1744 | - if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) { |
|
| 1745 | - EE_Error::add_error( |
|
| 1746 | - __( |
|
| 1747 | - 'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset. At least one of these is missing.', |
|
| 1748 | - 'event_espresso' |
|
| 1749 | - ), |
|
| 1750 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1751 | - ); |
|
| 1752 | - } |
|
| 1753 | - |
|
| 1754 | - // all templates will be reset to whatever the defaults are |
|
| 1755 | - // for the global template matching the messenger and message type. |
|
| 1756 | - $success = ! empty($GRP_ID) ? true : false; |
|
| 1757 | - |
|
| 1758 | - if ($success) { |
|
| 1727 | + } |
|
| 1728 | + } |
|
| 1729 | + |
|
| 1730 | + |
|
| 1731 | + /** |
|
| 1732 | + * This handles resetting the template for the given messenger/message_type so that users can start from scratch if |
|
| 1733 | + * they want. |
|
| 1734 | + * |
|
| 1735 | + * @access protected |
|
| 1736 | + * @return array|null |
|
| 1737 | + */ |
|
| 1738 | + protected function _reset_to_default_template() |
|
| 1739 | + { |
|
| 1740 | + |
|
| 1741 | + $templates = array(); |
|
| 1742 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 1743 | + //we need to make sure we've got the info we need. |
|
| 1744 | + if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) { |
|
| 1745 | + EE_Error::add_error( |
|
| 1746 | + __( |
|
| 1747 | + 'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset. At least one of these is missing.', |
|
| 1748 | + 'event_espresso' |
|
| 1749 | + ), |
|
| 1750 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1751 | + ); |
|
| 1752 | + } |
|
| 1753 | + |
|
| 1754 | + // all templates will be reset to whatever the defaults are |
|
| 1755 | + // for the global template matching the messenger and message type. |
|
| 1756 | + $success = ! empty($GRP_ID) ? true : false; |
|
| 1757 | + |
|
| 1758 | + if ($success) { |
|
| 1759 | 1759 | |
| 1760 | - //let's first determine if the incoming template is a global template, |
|
| 1761 | - // if it isn't then we need to get the global template matching messenger and message type. |
|
| 1762 | - //$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID ); |
|
| 1760 | + //let's first determine if the incoming template is a global template, |
|
| 1761 | + // if it isn't then we need to get the global template matching messenger and message type. |
|
| 1762 | + //$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID ); |
|
| 1763 | 1763 | |
| 1764 | 1764 | |
| 1765 | - //note this is ONLY deleting the template fields (Message Template rows) NOT the message template group. |
|
| 1766 | - $success = $this->_delete_mtp_permanently($GRP_ID, false); |
|
| 1765 | + //note this is ONLY deleting the template fields (Message Template rows) NOT the message template group. |
|
| 1766 | + $success = $this->_delete_mtp_permanently($GRP_ID, false); |
|
| 1767 | 1767 | |
| 1768 | - if ($success) { |
|
| 1769 | - // if successfully deleted, lets generate the new ones. |
|
| 1770 | - // Note. We set GLOBAL to true, because resets on ANY template |
|
| 1771 | - // will use the related global template defaults for regeneration. |
|
| 1772 | - // This means that if a custom template is reset it resets to whatever the related global template is. |
|
| 1773 | - // HOWEVER, we DO keep the template pack and template variation set |
|
| 1774 | - // for the current custom template when resetting. |
|
| 1775 | - $templates = $this->_generate_new_templates( |
|
| 1776 | - $this->_req_data['msgr'], |
|
| 1777 | - $this->_req_data['mt'], |
|
| 1778 | - $GRP_ID, |
|
| 1779 | - true |
|
| 1780 | - ); |
|
| 1781 | - } |
|
| 1768 | + if ($success) { |
|
| 1769 | + // if successfully deleted, lets generate the new ones. |
|
| 1770 | + // Note. We set GLOBAL to true, because resets on ANY template |
|
| 1771 | + // will use the related global template defaults for regeneration. |
|
| 1772 | + // This means that if a custom template is reset it resets to whatever the related global template is. |
|
| 1773 | + // HOWEVER, we DO keep the template pack and template variation set |
|
| 1774 | + // for the current custom template when resetting. |
|
| 1775 | + $templates = $this->_generate_new_templates( |
|
| 1776 | + $this->_req_data['msgr'], |
|
| 1777 | + $this->_req_data['mt'], |
|
| 1778 | + $GRP_ID, |
|
| 1779 | + true |
|
| 1780 | + ); |
|
| 1781 | + } |
|
| 1782 | 1782 | |
| 1783 | - } |
|
| 1784 | - |
|
| 1785 | - //any error messages? |
|
| 1786 | - if ( ! $success) { |
|
| 1787 | - EE_Error::add_error( |
|
| 1788 | - __('Something went wrong with deleting existing templates. Unable to reset to default', |
|
| 1789 | - 'event_espresso'), |
|
| 1790 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1791 | - ); |
|
| 1792 | - } |
|
| 1793 | - |
|
| 1794 | - //all good, let's add a success message! |
|
| 1795 | - if ($success && ! empty($templates)) { |
|
| 1796 | - $templates = $templates[0]; //the info for the template we generated is the first element in the returned array. |
|
| 1797 | - EE_Error::overwrite_success(); |
|
| 1798 | - EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso')); |
|
| 1799 | - } |
|
| 1800 | - |
|
| 1801 | - |
|
| 1802 | - $query_args = array( |
|
| 1803 | - 'id' => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null, |
|
| 1804 | - 'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null, |
|
| 1805 | - 'action' => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps' |
|
| 1806 | - ); |
|
| 1807 | - |
|
| 1808 | - //if called via ajax then we return query args otherwise redirect |
|
| 1809 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 1810 | - return $query_args; |
|
| 1811 | - } else { |
|
| 1812 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1783 | + } |
|
| 1784 | + |
|
| 1785 | + //any error messages? |
|
| 1786 | + if ( ! $success) { |
|
| 1787 | + EE_Error::add_error( |
|
| 1788 | + __('Something went wrong with deleting existing templates. Unable to reset to default', |
|
| 1789 | + 'event_espresso'), |
|
| 1790 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1791 | + ); |
|
| 1792 | + } |
|
| 1793 | + |
|
| 1794 | + //all good, let's add a success message! |
|
| 1795 | + if ($success && ! empty($templates)) { |
|
| 1796 | + $templates = $templates[0]; //the info for the template we generated is the first element in the returned array. |
|
| 1797 | + EE_Error::overwrite_success(); |
|
| 1798 | + EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso')); |
|
| 1799 | + } |
|
| 1800 | + |
|
| 1801 | + |
|
| 1802 | + $query_args = array( |
|
| 1803 | + 'id' => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null, |
|
| 1804 | + 'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null, |
|
| 1805 | + 'action' => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps' |
|
| 1806 | + ); |
|
| 1807 | + |
|
| 1808 | + //if called via ajax then we return query args otherwise redirect |
|
| 1809 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 1810 | + return $query_args; |
|
| 1811 | + } else { |
|
| 1812 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1813 | 1813 | |
| 1814 | - return null; |
|
| 1815 | - } |
|
| 1816 | - } |
|
| 1817 | - |
|
| 1818 | - |
|
| 1819 | - /** |
|
| 1820 | - * Retrieve and set the message preview for display. |
|
| 1821 | - * |
|
| 1822 | - * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview. |
|
| 1823 | - * |
|
| 1824 | - * @return string |
|
| 1825 | - */ |
|
| 1826 | - public function _preview_message($send = false) |
|
| 1827 | - { |
|
| 1828 | - //first make sure we've got the necessary parameters |
|
| 1829 | - if ( |
|
| 1830 | - ! isset( |
|
| 1831 | - $this->_req_data['message_type'], |
|
| 1832 | - $this->_req_data['messenger'], |
|
| 1833 | - $this->_req_data['messenger'], |
|
| 1834 | - $this->_req_data['GRP_ID'] |
|
| 1835 | - ) |
|
| 1836 | - ) { |
|
| 1837 | - EE_Error::add_error( |
|
| 1838 | - __('Missing necessary parameters for displaying preview', 'event_espresso'), |
|
| 1839 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1840 | - ); |
|
| 1841 | - } |
|
| 1842 | - |
|
| 1843 | - EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']); |
|
| 1844 | - |
|
| 1845 | - |
|
| 1846 | - //get the preview! |
|
| 1847 | - $preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'], |
|
| 1848 | - $this->_req_data['messenger'], $send); |
|
| 1849 | - |
|
| 1850 | - if ($send) { |
|
| 1851 | - return $preview; |
|
| 1852 | - } |
|
| 1853 | - |
|
| 1854 | - //let's add a button to go back to the edit view |
|
| 1855 | - $query_args = array( |
|
| 1856 | - 'id' => $this->_req_data['GRP_ID'], |
|
| 1857 | - 'context' => $this->_req_data['context'], |
|
| 1858 | - 'action' => 'edit_message_template' |
|
| 1859 | - ); |
|
| 1860 | - $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 1861 | - $preview_button = '<a href="' . $go_back_url . '" class="button-secondary messages-preview-go-back-button">' . __('Go Back to Edit', |
|
| 1862 | - 'event_espresso') . '</a>'; |
|
| 1863 | - $message_types = $this->get_installed_message_types(); |
|
| 1864 | - $active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 1865 | - $active_messenger_label = $active_messenger instanceof EE_messenger |
|
| 1866 | - ? ucwords($active_messenger->label['singular']) |
|
| 1867 | - : esc_html__('Unknown Messenger', 'event_espresso'); |
|
| 1868 | - //let's provide a helpful title for context |
|
| 1869 | - $preview_title = sprintf( |
|
| 1870 | - __('Viewing Preview for %s %s Message Template', 'event_espresso'), |
|
| 1871 | - $active_messenger_label, |
|
| 1872 | - ucwords($message_types[$this->_req_data['message_type']]->label['singular']) |
|
| 1873 | - ); |
|
| 1874 | - //setup display of preview. |
|
| 1875 | - $this->_admin_page_title = $preview_title; |
|
| 1876 | - $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview); |
|
| 1877 | - $this->_template_args['data']['force_json'] = true; |
|
| 1878 | - |
|
| 1879 | - return ''; |
|
| 1880 | - } |
|
| 1881 | - |
|
| 1882 | - |
|
| 1883 | - /** |
|
| 1884 | - * The initial _preview_message is on a no headers route. It will optionally call this if necessary otherwise it |
|
| 1885 | - * gets called automatically. |
|
| 1886 | - * |
|
| 1887 | - * @since 4.5.0 |
|
| 1888 | - * |
|
| 1889 | - * @return string |
|
| 1890 | - */ |
|
| 1891 | - protected function _display_preview_message() |
|
| 1892 | - { |
|
| 1893 | - $this->display_admin_page_with_no_sidebar(); |
|
| 1894 | - } |
|
| 1895 | - |
|
| 1896 | - |
|
| 1897 | - /** |
|
| 1898 | - * registers metaboxes that should show up on the "edit_message_template" page |
|
| 1899 | - * |
|
| 1900 | - * @access protected |
|
| 1901 | - * @return void |
|
| 1902 | - */ |
|
| 1903 | - protected function _register_edit_meta_boxes() |
|
| 1904 | - { |
|
| 1905 | - add_meta_box('mtp_valid_shortcodes', __('Valid Shortcodes', 'event_espresso'), |
|
| 1906 | - array($this, 'shortcode_meta_box'), $this->_current_screen->id, 'side', 'default'); |
|
| 1907 | - add_meta_box('mtp_extra_actions', __('Extra Actions', 'event_espresso'), array($this, 'extra_actions_meta_box'), |
|
| 1908 | - $this->_current_screen->id, 'side', 'high'); |
|
| 1909 | - add_meta_box('mtp_templates', __('Template Styles', 'event_espresso'), array($this, 'template_pack_meta_box'), |
|
| 1910 | - $this->_current_screen->id, 'side', 'high'); |
|
| 1911 | - } |
|
| 1912 | - |
|
| 1913 | - |
|
| 1914 | - /** |
|
| 1915 | - * metabox content for all template pack and variation selection. |
|
| 1916 | - * |
|
| 1917 | - * @since 4.5.0 |
|
| 1918 | - * |
|
| 1919 | - * @return string |
|
| 1920 | - */ |
|
| 1921 | - public function template_pack_meta_box() |
|
| 1922 | - { |
|
| 1923 | - $this->_set_message_template_group(); |
|
| 1924 | - |
|
| 1925 | - $tp_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 1926 | - |
|
| 1927 | - $tp_select_values = array(); |
|
| 1928 | - |
|
| 1929 | - foreach ($tp_collection as $tp) { |
|
| 1930 | - //only include template packs that support this messenger and message type! |
|
| 1931 | - $supports = $tp->get_supports(); |
|
| 1932 | - if ( |
|
| 1933 | - ! isset($supports[$this->_message_template_group->messenger()]) |
|
| 1934 | - || ! in_array( |
|
| 1935 | - $this->_message_template_group->message_type(), |
|
| 1936 | - $supports[$this->_message_template_group->messenger()] |
|
| 1937 | - ) |
|
| 1938 | - ) { |
|
| 1939 | - //not supported |
|
| 1940 | - continue; |
|
| 1941 | - } |
|
| 1814 | + return null; |
|
| 1815 | + } |
|
| 1816 | + } |
|
| 1817 | + |
|
| 1818 | + |
|
| 1819 | + /** |
|
| 1820 | + * Retrieve and set the message preview for display. |
|
| 1821 | + * |
|
| 1822 | + * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview. |
|
| 1823 | + * |
|
| 1824 | + * @return string |
|
| 1825 | + */ |
|
| 1826 | + public function _preview_message($send = false) |
|
| 1827 | + { |
|
| 1828 | + //first make sure we've got the necessary parameters |
|
| 1829 | + if ( |
|
| 1830 | + ! isset( |
|
| 1831 | + $this->_req_data['message_type'], |
|
| 1832 | + $this->_req_data['messenger'], |
|
| 1833 | + $this->_req_data['messenger'], |
|
| 1834 | + $this->_req_data['GRP_ID'] |
|
| 1835 | + ) |
|
| 1836 | + ) { |
|
| 1837 | + EE_Error::add_error( |
|
| 1838 | + __('Missing necessary parameters for displaying preview', 'event_espresso'), |
|
| 1839 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1840 | + ); |
|
| 1841 | + } |
|
| 1842 | + |
|
| 1843 | + EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']); |
|
| 1844 | + |
|
| 1845 | + |
|
| 1846 | + //get the preview! |
|
| 1847 | + $preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'], |
|
| 1848 | + $this->_req_data['messenger'], $send); |
|
| 1849 | + |
|
| 1850 | + if ($send) { |
|
| 1851 | + return $preview; |
|
| 1852 | + } |
|
| 1853 | + |
|
| 1854 | + //let's add a button to go back to the edit view |
|
| 1855 | + $query_args = array( |
|
| 1856 | + 'id' => $this->_req_data['GRP_ID'], |
|
| 1857 | + 'context' => $this->_req_data['context'], |
|
| 1858 | + 'action' => 'edit_message_template' |
|
| 1859 | + ); |
|
| 1860 | + $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 1861 | + $preview_button = '<a href="' . $go_back_url . '" class="button-secondary messages-preview-go-back-button">' . __('Go Back to Edit', |
|
| 1862 | + 'event_espresso') . '</a>'; |
|
| 1863 | + $message_types = $this->get_installed_message_types(); |
|
| 1864 | + $active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 1865 | + $active_messenger_label = $active_messenger instanceof EE_messenger |
|
| 1866 | + ? ucwords($active_messenger->label['singular']) |
|
| 1867 | + : esc_html__('Unknown Messenger', 'event_espresso'); |
|
| 1868 | + //let's provide a helpful title for context |
|
| 1869 | + $preview_title = sprintf( |
|
| 1870 | + __('Viewing Preview for %s %s Message Template', 'event_espresso'), |
|
| 1871 | + $active_messenger_label, |
|
| 1872 | + ucwords($message_types[$this->_req_data['message_type']]->label['singular']) |
|
| 1873 | + ); |
|
| 1874 | + //setup display of preview. |
|
| 1875 | + $this->_admin_page_title = $preview_title; |
|
| 1876 | + $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview); |
|
| 1877 | + $this->_template_args['data']['force_json'] = true; |
|
| 1878 | + |
|
| 1879 | + return ''; |
|
| 1880 | + } |
|
| 1881 | + |
|
| 1882 | + |
|
| 1883 | + /** |
|
| 1884 | + * The initial _preview_message is on a no headers route. It will optionally call this if necessary otherwise it |
|
| 1885 | + * gets called automatically. |
|
| 1886 | + * |
|
| 1887 | + * @since 4.5.0 |
|
| 1888 | + * |
|
| 1889 | + * @return string |
|
| 1890 | + */ |
|
| 1891 | + protected function _display_preview_message() |
|
| 1892 | + { |
|
| 1893 | + $this->display_admin_page_with_no_sidebar(); |
|
| 1894 | + } |
|
| 1895 | + |
|
| 1896 | + |
|
| 1897 | + /** |
|
| 1898 | + * registers metaboxes that should show up on the "edit_message_template" page |
|
| 1899 | + * |
|
| 1900 | + * @access protected |
|
| 1901 | + * @return void |
|
| 1902 | + */ |
|
| 1903 | + protected function _register_edit_meta_boxes() |
|
| 1904 | + { |
|
| 1905 | + add_meta_box('mtp_valid_shortcodes', __('Valid Shortcodes', 'event_espresso'), |
|
| 1906 | + array($this, 'shortcode_meta_box'), $this->_current_screen->id, 'side', 'default'); |
|
| 1907 | + add_meta_box('mtp_extra_actions', __('Extra Actions', 'event_espresso'), array($this, 'extra_actions_meta_box'), |
|
| 1908 | + $this->_current_screen->id, 'side', 'high'); |
|
| 1909 | + add_meta_box('mtp_templates', __('Template Styles', 'event_espresso'), array($this, 'template_pack_meta_box'), |
|
| 1910 | + $this->_current_screen->id, 'side', 'high'); |
|
| 1911 | + } |
|
| 1912 | + |
|
| 1913 | + |
|
| 1914 | + /** |
|
| 1915 | + * metabox content for all template pack and variation selection. |
|
| 1916 | + * |
|
| 1917 | + * @since 4.5.0 |
|
| 1918 | + * |
|
| 1919 | + * @return string |
|
| 1920 | + */ |
|
| 1921 | + public function template_pack_meta_box() |
|
| 1922 | + { |
|
| 1923 | + $this->_set_message_template_group(); |
|
| 1924 | + |
|
| 1925 | + $tp_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 1926 | + |
|
| 1927 | + $tp_select_values = array(); |
|
| 1928 | + |
|
| 1929 | + foreach ($tp_collection as $tp) { |
|
| 1930 | + //only include template packs that support this messenger and message type! |
|
| 1931 | + $supports = $tp->get_supports(); |
|
| 1932 | + if ( |
|
| 1933 | + ! isset($supports[$this->_message_template_group->messenger()]) |
|
| 1934 | + || ! in_array( |
|
| 1935 | + $this->_message_template_group->message_type(), |
|
| 1936 | + $supports[$this->_message_template_group->messenger()] |
|
| 1937 | + ) |
|
| 1938 | + ) { |
|
| 1939 | + //not supported |
|
| 1940 | + continue; |
|
| 1941 | + } |
|
| 1942 | 1942 | |
| 1943 | - $tp_select_values[] = array( |
|
| 1944 | - 'text' => $tp->label, |
|
| 1945 | - 'id' => $tp->dbref |
|
| 1946 | - ); |
|
| 1947 | - } |
|
| 1948 | - |
|
| 1949 | - //if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by the default template pack. This still allows for the odd template pack to override. |
|
| 1950 | - if (empty($tp_select_values)) { |
|
| 1951 | - $tp_select_values[] = array( |
|
| 1952 | - 'text' => __('Default', 'event_espresso'), |
|
| 1953 | - 'id' => 'default' |
|
| 1954 | - ); |
|
| 1955 | - } |
|
| 1956 | - |
|
| 1957 | - //setup variation select values for the currently selected template. |
|
| 1958 | - $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 1959 | - $this->_message_template_group->messenger(), |
|
| 1960 | - $this->_message_template_group->message_type() |
|
| 1961 | - ); |
|
| 1962 | - $variations_select_values = array(); |
|
| 1963 | - foreach ($variations as $variation => $label) { |
|
| 1964 | - $variations_select_values[] = array( |
|
| 1965 | - 'text' => $label, |
|
| 1966 | - 'id' => $variation |
|
| 1967 | - ); |
|
| 1968 | - } |
|
| 1969 | - |
|
| 1970 | - $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels(); |
|
| 1971 | - |
|
| 1972 | - $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 1973 | - 'MTP_template_pack', |
|
| 1974 | - $tp_select_values, |
|
| 1975 | - $this->_message_template_group->get_template_pack_name() |
|
| 1976 | - ); |
|
| 1977 | - $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 1978 | - 'MTP_template_variation', |
|
| 1979 | - $variations_select_values, |
|
| 1980 | - $this->_message_template_group->get_template_pack_variation() |
|
| 1981 | - ); |
|
| 1982 | - $template_args['template_pack_label'] = $template_pack_labels->template_pack; |
|
| 1983 | - $template_args['template_variation_label'] = $template_pack_labels->template_variation; |
|
| 1984 | - $template_args['template_pack_description'] = $template_pack_labels->template_pack_description; |
|
| 1985 | - $template_args['template_variation_description'] = $template_pack_labels->template_variation_description; |
|
| 1986 | - |
|
| 1987 | - $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php'; |
|
| 1988 | - |
|
| 1989 | - EEH_Template::display_template($template, $template_args); |
|
| 1990 | - } |
|
| 1991 | - |
|
| 1992 | - |
|
| 1993 | - /** |
|
| 1994 | - * This meta box holds any extra actions related to Message Templates |
|
| 1995 | - * For now, this includes Resetting templates to defaults and sending a test email. |
|
| 1996 | - * |
|
| 1997 | - * @access public |
|
| 1998 | - * @return void |
|
| 1999 | - * @throws \EE_Error |
|
| 2000 | - */ |
|
| 2001 | - public function extra_actions_meta_box() |
|
| 2002 | - { |
|
| 2003 | - $template_form_fields = array(); |
|
| 2004 | - |
|
| 2005 | - $extra_args = array( |
|
| 2006 | - 'msgr' => $this->_message_template_group->messenger(), |
|
| 2007 | - 'mt' => $this->_message_template_group->message_type(), |
|
| 2008 | - 'GRP_ID' => $this->_message_template_group->GRP_ID() |
|
| 2009 | - ); |
|
| 2010 | - //first we need to see if there are any fields |
|
| 2011 | - $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields(); |
|
| 2012 | - |
|
| 2013 | - if ( ! empty($fields)) { |
|
| 2014 | - //yup there be fields |
|
| 2015 | - foreach ($fields as $field => $config) { |
|
| 2016 | - $field_id = $this->_message_template_group->messenger() . '_' . $field; |
|
| 2017 | - $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings(); |
|
| 2018 | - $default = isset($config['default']) ? $config['default'] : ''; |
|
| 2019 | - $default = isset($config['value']) ? $config['value'] : $default; |
|
| 1943 | + $tp_select_values[] = array( |
|
| 1944 | + 'text' => $tp->label, |
|
| 1945 | + 'id' => $tp->dbref |
|
| 1946 | + ); |
|
| 1947 | + } |
|
| 1948 | + |
|
| 1949 | + //if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by the default template pack. This still allows for the odd template pack to override. |
|
| 1950 | + if (empty($tp_select_values)) { |
|
| 1951 | + $tp_select_values[] = array( |
|
| 1952 | + 'text' => __('Default', 'event_espresso'), |
|
| 1953 | + 'id' => 'default' |
|
| 1954 | + ); |
|
| 1955 | + } |
|
| 1956 | + |
|
| 1957 | + //setup variation select values for the currently selected template. |
|
| 1958 | + $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 1959 | + $this->_message_template_group->messenger(), |
|
| 1960 | + $this->_message_template_group->message_type() |
|
| 1961 | + ); |
|
| 1962 | + $variations_select_values = array(); |
|
| 1963 | + foreach ($variations as $variation => $label) { |
|
| 1964 | + $variations_select_values[] = array( |
|
| 1965 | + 'text' => $label, |
|
| 1966 | + 'id' => $variation |
|
| 1967 | + ); |
|
| 1968 | + } |
|
| 1969 | + |
|
| 1970 | + $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels(); |
|
| 1971 | + |
|
| 1972 | + $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 1973 | + 'MTP_template_pack', |
|
| 1974 | + $tp_select_values, |
|
| 1975 | + $this->_message_template_group->get_template_pack_name() |
|
| 1976 | + ); |
|
| 1977 | + $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 1978 | + 'MTP_template_variation', |
|
| 1979 | + $variations_select_values, |
|
| 1980 | + $this->_message_template_group->get_template_pack_variation() |
|
| 1981 | + ); |
|
| 1982 | + $template_args['template_pack_label'] = $template_pack_labels->template_pack; |
|
| 1983 | + $template_args['template_variation_label'] = $template_pack_labels->template_variation; |
|
| 1984 | + $template_args['template_pack_description'] = $template_pack_labels->template_pack_description; |
|
| 1985 | + $template_args['template_variation_description'] = $template_pack_labels->template_variation_description; |
|
| 1986 | + |
|
| 1987 | + $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php'; |
|
| 1988 | + |
|
| 1989 | + EEH_Template::display_template($template, $template_args); |
|
| 1990 | + } |
|
| 1991 | + |
|
| 1992 | + |
|
| 1993 | + /** |
|
| 1994 | + * This meta box holds any extra actions related to Message Templates |
|
| 1995 | + * For now, this includes Resetting templates to defaults and sending a test email. |
|
| 1996 | + * |
|
| 1997 | + * @access public |
|
| 1998 | + * @return void |
|
| 1999 | + * @throws \EE_Error |
|
| 2000 | + */ |
|
| 2001 | + public function extra_actions_meta_box() |
|
| 2002 | + { |
|
| 2003 | + $template_form_fields = array(); |
|
| 2004 | + |
|
| 2005 | + $extra_args = array( |
|
| 2006 | + 'msgr' => $this->_message_template_group->messenger(), |
|
| 2007 | + 'mt' => $this->_message_template_group->message_type(), |
|
| 2008 | + 'GRP_ID' => $this->_message_template_group->GRP_ID() |
|
| 2009 | + ); |
|
| 2010 | + //first we need to see if there are any fields |
|
| 2011 | + $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields(); |
|
| 2012 | + |
|
| 2013 | + if ( ! empty($fields)) { |
|
| 2014 | + //yup there be fields |
|
| 2015 | + foreach ($fields as $field => $config) { |
|
| 2016 | + $field_id = $this->_message_template_group->messenger() . '_' . $field; |
|
| 2017 | + $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings(); |
|
| 2018 | + $default = isset($config['default']) ? $config['default'] : ''; |
|
| 2019 | + $default = isset($config['value']) ? $config['value'] : $default; |
|
| 2020 | 2020 | |
| 2021 | - // if type is hidden and the value is empty |
|
| 2022 | - // something may have gone wrong so let's correct with the defaults |
|
| 2023 | - $fix = $config['input'] === 'hidden' && isset($existing[$field]) && empty($existing[$field]) |
|
| 2024 | - ? $default |
|
| 2025 | - : ''; |
|
| 2026 | - $existing[$field] = isset($existing[$field]) && empty($fix) |
|
| 2027 | - ? $existing[$field] |
|
| 2028 | - : $fix; |
|
| 2021 | + // if type is hidden and the value is empty |
|
| 2022 | + // something may have gone wrong so let's correct with the defaults |
|
| 2023 | + $fix = $config['input'] === 'hidden' && isset($existing[$field]) && empty($existing[$field]) |
|
| 2024 | + ? $default |
|
| 2025 | + : ''; |
|
| 2026 | + $existing[$field] = isset($existing[$field]) && empty($fix) |
|
| 2027 | + ? $existing[$field] |
|
| 2028 | + : $fix; |
|
| 2029 | 2029 | |
| 2030 | - $template_form_fields[$field_id] = array( |
|
| 2031 | - 'name' => 'test_settings_fld[' . $field . ']', |
|
| 2032 | - 'label' => $config['label'], |
|
| 2033 | - 'input' => $config['input'], |
|
| 2034 | - 'type' => $config['type'], |
|
| 2035 | - 'required' => $config['required'], |
|
| 2036 | - 'validation' => $config['validation'], |
|
| 2037 | - 'value' => isset($existing[$field]) ? $existing[$field] : $default, |
|
| 2038 | - 'css_class' => $config['css_class'], |
|
| 2039 | - 'options' => isset($config['options']) ? $config['options'] : array(), |
|
| 2040 | - 'default' => $default, |
|
| 2041 | - 'format' => $config['format'] |
|
| 2042 | - ); |
|
| 2043 | - } |
|
| 2044 | - } |
|
| 2045 | - |
|
| 2046 | - $test_settings_fields = ! empty($template_form_fields) |
|
| 2047 | - ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds') |
|
| 2048 | - : ''; |
|
| 2049 | - |
|
| 2050 | - $test_settings_html = ''; |
|
| 2051 | - //print out $test_settings_fields |
|
| 2052 | - if ( ! empty($test_settings_fields)) { |
|
| 2053 | - echo $test_settings_fields; |
|
| 2054 | - $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" '; |
|
| 2055 | - $test_settings_html .= 'name="test_button" value="'; |
|
| 2056 | - $test_settings_html .= __('Test Send', 'event_espresso'); |
|
| 2057 | - $test_settings_html .= '" /><div style="clear:both"></div>'; |
|
| 2058 | - } |
|
| 2059 | - |
|
| 2060 | - //and button |
|
| 2061 | - $test_settings_html .= '<p>' . __('Need to reset this message type and start over?', 'event_espresso') . '</p>'; |
|
| 2062 | - $test_settings_html .= '<div class="publishing-action alignright resetbutton">'; |
|
| 2063 | - $test_settings_html .= $this->get_action_link_or_button( |
|
| 2064 | - 'reset_to_default', |
|
| 2065 | - 'reset', |
|
| 2066 | - $extra_args, |
|
| 2067 | - 'button-primary reset-default-button' |
|
| 2068 | - ); |
|
| 2069 | - $test_settings_html .= '</div><div style="clear:both"></div>'; |
|
| 2070 | - echo $test_settings_html; |
|
| 2071 | - } |
|
| 2072 | - |
|
| 2073 | - |
|
| 2074 | - /** |
|
| 2075 | - * This returns the shortcode selector skeleton for a given context and field. |
|
| 2076 | - * |
|
| 2077 | - * @since 4.9.rc.000 |
|
| 2078 | - * |
|
| 2079 | - * @param string $field The name of the field retrieving shortcodes for. |
|
| 2080 | - * @param string $linked_input_id The css id of the input that the shortcodes get added to. |
|
| 2081 | - * |
|
| 2082 | - * @return string |
|
| 2083 | - */ |
|
| 2084 | - protected function _get_shortcode_selector($field, $linked_input_id) |
|
| 2085 | - { |
|
| 2086 | - $template_args = array( |
|
| 2087 | - 'shortcodes' => $this->_get_shortcodes(array($field), true), |
|
| 2088 | - 'fieldname' => $field, |
|
| 2089 | - 'linked_input_id' => $linked_input_id |
|
| 2090 | - ); |
|
| 2091 | - |
|
| 2092 | - return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php', |
|
| 2093 | - $template_args, true); |
|
| 2094 | - } |
|
| 2095 | - |
|
| 2096 | - |
|
| 2097 | - /** |
|
| 2098 | - * This just takes care of returning the meta box content for shortcodes (only used on the edit message template |
|
| 2099 | - * page) |
|
| 2100 | - * |
|
| 2101 | - * @access public |
|
| 2102 | - * @return void |
|
| 2103 | - */ |
|
| 2104 | - public function shortcode_meta_box() |
|
| 2105 | - { |
|
| 2106 | - $shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set |
|
| 2107 | - //$messenger = $this->_message_template_group->messenger_obj(); |
|
| 2108 | - //now let's set the content depending on the status of the shortcodes array |
|
| 2109 | - if (empty($shortcodes)) { |
|
| 2110 | - $content = '<p>' . __('There are no valid shortcodes available', 'event_espresso') . '</p>'; |
|
| 2111 | - echo $content; |
|
| 2112 | - } else { |
|
| 2113 | - //$alt = 0; |
|
| 2114 | - ?> |
|
| 2030 | + $template_form_fields[$field_id] = array( |
|
| 2031 | + 'name' => 'test_settings_fld[' . $field . ']', |
|
| 2032 | + 'label' => $config['label'], |
|
| 2033 | + 'input' => $config['input'], |
|
| 2034 | + 'type' => $config['type'], |
|
| 2035 | + 'required' => $config['required'], |
|
| 2036 | + 'validation' => $config['validation'], |
|
| 2037 | + 'value' => isset($existing[$field]) ? $existing[$field] : $default, |
|
| 2038 | + 'css_class' => $config['css_class'], |
|
| 2039 | + 'options' => isset($config['options']) ? $config['options'] : array(), |
|
| 2040 | + 'default' => $default, |
|
| 2041 | + 'format' => $config['format'] |
|
| 2042 | + ); |
|
| 2043 | + } |
|
| 2044 | + } |
|
| 2045 | + |
|
| 2046 | + $test_settings_fields = ! empty($template_form_fields) |
|
| 2047 | + ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds') |
|
| 2048 | + : ''; |
|
| 2049 | + |
|
| 2050 | + $test_settings_html = ''; |
|
| 2051 | + //print out $test_settings_fields |
|
| 2052 | + if ( ! empty($test_settings_fields)) { |
|
| 2053 | + echo $test_settings_fields; |
|
| 2054 | + $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" '; |
|
| 2055 | + $test_settings_html .= 'name="test_button" value="'; |
|
| 2056 | + $test_settings_html .= __('Test Send', 'event_espresso'); |
|
| 2057 | + $test_settings_html .= '" /><div style="clear:both"></div>'; |
|
| 2058 | + } |
|
| 2059 | + |
|
| 2060 | + //and button |
|
| 2061 | + $test_settings_html .= '<p>' . __('Need to reset this message type and start over?', 'event_espresso') . '</p>'; |
|
| 2062 | + $test_settings_html .= '<div class="publishing-action alignright resetbutton">'; |
|
| 2063 | + $test_settings_html .= $this->get_action_link_or_button( |
|
| 2064 | + 'reset_to_default', |
|
| 2065 | + 'reset', |
|
| 2066 | + $extra_args, |
|
| 2067 | + 'button-primary reset-default-button' |
|
| 2068 | + ); |
|
| 2069 | + $test_settings_html .= '</div><div style="clear:both"></div>'; |
|
| 2070 | + echo $test_settings_html; |
|
| 2071 | + } |
|
| 2072 | + |
|
| 2073 | + |
|
| 2074 | + /** |
|
| 2075 | + * This returns the shortcode selector skeleton for a given context and field. |
|
| 2076 | + * |
|
| 2077 | + * @since 4.9.rc.000 |
|
| 2078 | + * |
|
| 2079 | + * @param string $field The name of the field retrieving shortcodes for. |
|
| 2080 | + * @param string $linked_input_id The css id of the input that the shortcodes get added to. |
|
| 2081 | + * |
|
| 2082 | + * @return string |
|
| 2083 | + */ |
|
| 2084 | + protected function _get_shortcode_selector($field, $linked_input_id) |
|
| 2085 | + { |
|
| 2086 | + $template_args = array( |
|
| 2087 | + 'shortcodes' => $this->_get_shortcodes(array($field), true), |
|
| 2088 | + 'fieldname' => $field, |
|
| 2089 | + 'linked_input_id' => $linked_input_id |
|
| 2090 | + ); |
|
| 2091 | + |
|
| 2092 | + return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php', |
|
| 2093 | + $template_args, true); |
|
| 2094 | + } |
|
| 2095 | + |
|
| 2096 | + |
|
| 2097 | + /** |
|
| 2098 | + * This just takes care of returning the meta box content for shortcodes (only used on the edit message template |
|
| 2099 | + * page) |
|
| 2100 | + * |
|
| 2101 | + * @access public |
|
| 2102 | + * @return void |
|
| 2103 | + */ |
|
| 2104 | + public function shortcode_meta_box() |
|
| 2105 | + { |
|
| 2106 | + $shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set |
|
| 2107 | + //$messenger = $this->_message_template_group->messenger_obj(); |
|
| 2108 | + //now let's set the content depending on the status of the shortcodes array |
|
| 2109 | + if (empty($shortcodes)) { |
|
| 2110 | + $content = '<p>' . __('There are no valid shortcodes available', 'event_espresso') . '</p>'; |
|
| 2111 | + echo $content; |
|
| 2112 | + } else { |
|
| 2113 | + //$alt = 0; |
|
| 2114 | + ?> |
|
| 2115 | 2115 | <div |
| 2116 | 2116 | style="float:right; margin-top:10px"><?php echo $this->_get_help_tab_link('message_template_shortcodes'); ?></div> |
| 2117 | 2117 | <p class="small-text"><?php printf(__('You can view the shortcodes usable in your template by clicking the %s icon next to each field.', |
| 2118 | - 'event_espresso'), '<span class="dashicons dashicons-menu"></span>'); ?></p> |
|
| 2118 | + 'event_espresso'), '<span class="dashicons dashicons-menu"></span>'); ?></p> |
|
| 2119 | 2119 | <?php |
| 2120 | - } |
|
| 2121 | - |
|
| 2122 | - |
|
| 2123 | - } |
|
| 2124 | - |
|
| 2125 | - |
|
| 2126 | - /** |
|
| 2127 | - * used to set the $_shortcodes property for when its needed elsewhere. |
|
| 2128 | - * |
|
| 2129 | - * @access protected |
|
| 2130 | - * @return void |
|
| 2131 | - */ |
|
| 2132 | - protected function _set_shortcodes() |
|
| 2133 | - { |
|
| 2134 | - |
|
| 2135 | - //no need to run this if the property is already set |
|
| 2136 | - if ( ! empty($this->_shortcodes)) { |
|
| 2137 | - return; |
|
| 2138 | - } |
|
| 2139 | - |
|
| 2140 | - $this->_shortcodes = $this->_get_shortcodes(); |
|
| 2141 | - } |
|
| 2142 | - |
|
| 2143 | - |
|
| 2144 | - /** |
|
| 2145 | - * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes |
|
| 2146 | - * property) |
|
| 2147 | - * |
|
| 2148 | - * @access protected |
|
| 2149 | - * |
|
| 2150 | - * @param array $fields include an array of specific field names that you want to be used to get the shortcodes |
|
| 2151 | - * for. Defaults to all (for the given context) |
|
| 2152 | - * @param boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes |
|
| 2153 | - * |
|
| 2154 | - * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is |
|
| 2155 | - * true just an array of shortcode/label pairs. |
|
| 2156 | - */ |
|
| 2157 | - protected function _get_shortcodes($fields = array(), $merged = true) |
|
| 2158 | - { |
|
| 2159 | - $this->_set_message_template_group(); |
|
| 2160 | - |
|
| 2161 | - //we need the messenger and message template to retrieve the valid shortcodes array. |
|
| 2162 | - $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) : false; |
|
| 2163 | - $context = isset($this->_req_data['context']) ? $this->_req_data['context'] : key($this->_message_template_group->contexts_config()); |
|
| 2164 | - |
|
| 2165 | - return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array(); |
|
| 2166 | - } |
|
| 2167 | - |
|
| 2168 | - |
|
| 2169 | - /** |
|
| 2170 | - * This sets the _message_template property (containing the called message_template object) |
|
| 2171 | - * |
|
| 2172 | - * @access protected |
|
| 2173 | - * @return void |
|
| 2174 | - */ |
|
| 2175 | - protected function _set_message_template_group() |
|
| 2176 | - { |
|
| 2177 | - |
|
| 2178 | - if ( ! empty($this->_message_template_group)) { |
|
| 2179 | - return; |
|
| 2180 | - } //get out if this is already set. |
|
| 2181 | - |
|
| 2182 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false; |
|
| 2183 | - $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID; |
|
| 2184 | - |
|
| 2185 | - //let's get the message templates |
|
| 2186 | - $MTP = EEM_Message_Template_Group::instance(); |
|
| 2187 | - |
|
| 2188 | - if (empty($GRP_ID)) { |
|
| 2189 | - $this->_message_template_group = $MTP->create_default_object(); |
|
| 2190 | - } else { |
|
| 2191 | - $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID); |
|
| 2192 | - } |
|
| 2193 | - |
|
| 2194 | - $this->_template_pack = $this->_message_template_group->get_template_pack(); |
|
| 2195 | - $this->_variation = $this->_message_template_group->get_template_pack_variation(); |
|
| 2196 | - |
|
| 2197 | - } |
|
| 2198 | - |
|
| 2199 | - |
|
| 2200 | - /** |
|
| 2201 | - * sets up a context switcher for edit forms |
|
| 2202 | - * |
|
| 2203 | - * @access protected |
|
| 2204 | - * |
|
| 2205 | - * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form |
|
| 2206 | - * @param array $args various things the context switcher needs. |
|
| 2207 | - * |
|
| 2208 | - */ |
|
| 2209 | - protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args) |
|
| 2210 | - { |
|
| 2211 | - $context_details = $template_group_object->contexts_config(); |
|
| 2212 | - $context_label = $template_group_object->context_label(); |
|
| 2213 | - ob_start(); |
|
| 2214 | - ?> |
|
| 2120 | + } |
|
| 2121 | + |
|
| 2122 | + |
|
| 2123 | + } |
|
| 2124 | + |
|
| 2125 | + |
|
| 2126 | + /** |
|
| 2127 | + * used to set the $_shortcodes property for when its needed elsewhere. |
|
| 2128 | + * |
|
| 2129 | + * @access protected |
|
| 2130 | + * @return void |
|
| 2131 | + */ |
|
| 2132 | + protected function _set_shortcodes() |
|
| 2133 | + { |
|
| 2134 | + |
|
| 2135 | + //no need to run this if the property is already set |
|
| 2136 | + if ( ! empty($this->_shortcodes)) { |
|
| 2137 | + return; |
|
| 2138 | + } |
|
| 2139 | + |
|
| 2140 | + $this->_shortcodes = $this->_get_shortcodes(); |
|
| 2141 | + } |
|
| 2142 | + |
|
| 2143 | + |
|
| 2144 | + /** |
|
| 2145 | + * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes |
|
| 2146 | + * property) |
|
| 2147 | + * |
|
| 2148 | + * @access protected |
|
| 2149 | + * |
|
| 2150 | + * @param array $fields include an array of specific field names that you want to be used to get the shortcodes |
|
| 2151 | + * for. Defaults to all (for the given context) |
|
| 2152 | + * @param boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes |
|
| 2153 | + * |
|
| 2154 | + * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is |
|
| 2155 | + * true just an array of shortcode/label pairs. |
|
| 2156 | + */ |
|
| 2157 | + protected function _get_shortcodes($fields = array(), $merged = true) |
|
| 2158 | + { |
|
| 2159 | + $this->_set_message_template_group(); |
|
| 2160 | + |
|
| 2161 | + //we need the messenger and message template to retrieve the valid shortcodes array. |
|
| 2162 | + $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) : false; |
|
| 2163 | + $context = isset($this->_req_data['context']) ? $this->_req_data['context'] : key($this->_message_template_group->contexts_config()); |
|
| 2164 | + |
|
| 2165 | + return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array(); |
|
| 2166 | + } |
|
| 2167 | + |
|
| 2168 | + |
|
| 2169 | + /** |
|
| 2170 | + * This sets the _message_template property (containing the called message_template object) |
|
| 2171 | + * |
|
| 2172 | + * @access protected |
|
| 2173 | + * @return void |
|
| 2174 | + */ |
|
| 2175 | + protected function _set_message_template_group() |
|
| 2176 | + { |
|
| 2177 | + |
|
| 2178 | + if ( ! empty($this->_message_template_group)) { |
|
| 2179 | + return; |
|
| 2180 | + } //get out if this is already set. |
|
| 2181 | + |
|
| 2182 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false; |
|
| 2183 | + $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID; |
|
| 2184 | + |
|
| 2185 | + //let's get the message templates |
|
| 2186 | + $MTP = EEM_Message_Template_Group::instance(); |
|
| 2187 | + |
|
| 2188 | + if (empty($GRP_ID)) { |
|
| 2189 | + $this->_message_template_group = $MTP->create_default_object(); |
|
| 2190 | + } else { |
|
| 2191 | + $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID); |
|
| 2192 | + } |
|
| 2193 | + |
|
| 2194 | + $this->_template_pack = $this->_message_template_group->get_template_pack(); |
|
| 2195 | + $this->_variation = $this->_message_template_group->get_template_pack_variation(); |
|
| 2196 | + |
|
| 2197 | + } |
|
| 2198 | + |
|
| 2199 | + |
|
| 2200 | + /** |
|
| 2201 | + * sets up a context switcher for edit forms |
|
| 2202 | + * |
|
| 2203 | + * @access protected |
|
| 2204 | + * |
|
| 2205 | + * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form |
|
| 2206 | + * @param array $args various things the context switcher needs. |
|
| 2207 | + * |
|
| 2208 | + */ |
|
| 2209 | + protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args) |
|
| 2210 | + { |
|
| 2211 | + $context_details = $template_group_object->contexts_config(); |
|
| 2212 | + $context_label = $template_group_object->context_label(); |
|
| 2213 | + ob_start(); |
|
| 2214 | + ?> |
|
| 2215 | 2215 | <div class="ee-msg-switcher-container"> |
| 2216 | 2216 | <form method="get" action="<?php echo EE_MSG_ADMIN_URL; ?>" id="ee-msg-context-switcher-frm"> |
| 2217 | 2217 | <?php |
| 2218 | - foreach ($args as $name => $value) { |
|
| 2219 | - if ($name == 'context' || empty($value) || $name == 'extra') { |
|
| 2220 | - continue; |
|
| 2221 | - } |
|
| 2222 | - ?> |
|
| 2218 | + foreach ($args as $name => $value) { |
|
| 2219 | + if ($name == 'context' || empty($value) || $name == 'extra') { |
|
| 2220 | + continue; |
|
| 2221 | + } |
|
| 2222 | + ?> |
|
| 2223 | 2223 | <input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>"/> |
| 2224 | 2224 | <?php |
| 2225 | - } |
|
| 2226 | - //setup nonce_url |
|
| 2227 | - wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false); |
|
| 2228 | - ?> |
|
| 2225 | + } |
|
| 2226 | + //setup nonce_url |
|
| 2227 | + wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false); |
|
| 2228 | + ?> |
|
| 2229 | 2229 | <select name="context"> |
| 2230 | 2230 | <?php |
| 2231 | - $context_templates = $template_group_object->context_templates(); |
|
| 2232 | - if (is_array($context_templates)) : |
|
| 2233 | - foreach ($context_templates as $context => $template_fields) : |
|
| 2234 | - $checked = ($context == $args['context']) ? 'selected="selected"' : ''; |
|
| 2235 | - ?> |
|
| 2231 | + $context_templates = $template_group_object->context_templates(); |
|
| 2232 | + if (is_array($context_templates)) : |
|
| 2233 | + foreach ($context_templates as $context => $template_fields) : |
|
| 2234 | + $checked = ($context == $args['context']) ? 'selected="selected"' : ''; |
|
| 2235 | + ?> |
|
| 2236 | 2236 | <option value="<?php echo $context; ?>" <?php echo $checked; ?>> |
| 2237 | 2237 | <?php echo $context_details[$context]['label']; ?> |
| 2238 | 2238 | </option> |
@@ -2245,1584 +2245,1584 @@ discard block |
||
| 2245 | 2245 | <?php echo $args['extra']; ?> |
| 2246 | 2246 | </div> <!-- end .ee-msg-switcher-container --> |
| 2247 | 2247 | <?php |
| 2248 | - $output = ob_get_contents(); |
|
| 2249 | - ob_clean(); |
|
| 2250 | - $this->_context_switcher = $output; |
|
| 2251 | - } |
|
| 2252 | - |
|
| 2253 | - |
|
| 2254 | - /** |
|
| 2255 | - * utility for sanitizing new values coming in. |
|
| 2256 | - * Note: this is only used when updating a context. |
|
| 2257 | - * |
|
| 2258 | - * @access protected |
|
| 2259 | - * |
|
| 2260 | - * @param int $index This helps us know which template field to select from the request array. |
|
| 2261 | - * |
|
| 2262 | - * @return array |
|
| 2263 | - */ |
|
| 2264 | - protected function _set_message_template_column_values($index) |
|
| 2265 | - { |
|
| 2266 | - if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) { |
|
| 2267 | - foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) { |
|
| 2268 | - $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value; |
|
| 2269 | - } |
|
| 2270 | - } /*else { |
|
| 2248 | + $output = ob_get_contents(); |
|
| 2249 | + ob_clean(); |
|
| 2250 | + $this->_context_switcher = $output; |
|
| 2251 | + } |
|
| 2252 | + |
|
| 2253 | + |
|
| 2254 | + /** |
|
| 2255 | + * utility for sanitizing new values coming in. |
|
| 2256 | + * Note: this is only used when updating a context. |
|
| 2257 | + * |
|
| 2258 | + * @access protected |
|
| 2259 | + * |
|
| 2260 | + * @param int $index This helps us know which template field to select from the request array. |
|
| 2261 | + * |
|
| 2262 | + * @return array |
|
| 2263 | + */ |
|
| 2264 | + protected function _set_message_template_column_values($index) |
|
| 2265 | + { |
|
| 2266 | + if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) { |
|
| 2267 | + foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) { |
|
| 2268 | + $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value; |
|
| 2269 | + } |
|
| 2270 | + } /*else { |
|
| 2271 | 2271 | $this->_req_data['MTP_template_fields'][$index]['content'] = $this->_req_data['MTP_template_fields'][$index]['content']; |
| 2272 | 2272 | }*/ |
| 2273 | 2273 | |
| 2274 | 2274 | |
| 2275 | - $set_column_values = array( |
|
| 2276 | - 'MTP_ID' => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']), |
|
| 2277 | - 'GRP_ID' => absint($this->_req_data['GRP_ID']), |
|
| 2278 | - 'MTP_user_id' => absint($this->_req_data['MTP_user_id']), |
|
| 2279 | - 'MTP_messenger' => strtolower($this->_req_data['MTP_messenger']), |
|
| 2280 | - 'MTP_message_type' => strtolower($this->_req_data['MTP_message_type']), |
|
| 2281 | - 'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']), |
|
| 2282 | - 'MTP_context' => strtolower($this->_req_data['MTP_context']), |
|
| 2283 | - 'MTP_content' => $this->_req_data['MTP_template_fields'][$index]['content'], |
|
| 2284 | - 'MTP_is_global' => isset($this->_req_data['MTP_is_global']) |
|
| 2285 | - ? absint($this->_req_data['MTP_is_global']) |
|
| 2286 | - : 0, |
|
| 2287 | - 'MTP_is_override' => isset($this->_req_data['MTP_is_override']) |
|
| 2288 | - ? absint($this->_req_data['MTP_is_override']) |
|
| 2289 | - : 0, |
|
| 2290 | - 'MTP_deleted' => absint($this->_req_data['MTP_deleted']), |
|
| 2291 | - 'MTP_is_active' => absint($this->_req_data['MTP_is_active']) |
|
| 2292 | - ); |
|
| 2293 | - |
|
| 2294 | - |
|
| 2295 | - return $set_column_values; |
|
| 2296 | - } |
|
| 2297 | - |
|
| 2298 | - |
|
| 2299 | - protected function _insert_or_update_message_template($new = false) |
|
| 2300 | - { |
|
| 2301 | - |
|
| 2302 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2303 | - $success = 0; |
|
| 2304 | - $override = false; |
|
| 2305 | - |
|
| 2306 | - //setup notices description |
|
| 2307 | - $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : ''; |
|
| 2308 | - |
|
| 2309 | - //need the message type and messenger objects to be able to use the labels for the notices |
|
| 2310 | - $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug); |
|
| 2311 | - $messenger_label = $messenger_object instanceof EE_messenger ? ucwords($messenger_object->label['singular']) : ''; |
|
| 2312 | - |
|
| 2313 | - $message_type_slug = ! empty($this->_req_data['MTP_message_type']) ? $this->_req_data['MTP_message_type'] : ''; |
|
| 2314 | - $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug); |
|
| 2315 | - |
|
| 2316 | - $message_type_label = $message_type_object instanceof EE_message_type |
|
| 2317 | - ? ucwords($message_type_object->label['singular']) |
|
| 2318 | - : ''; |
|
| 2319 | - |
|
| 2320 | - $context_slug = ! empty($this->_req_data['MTP_context']) |
|
| 2321 | - ? $this->_req_data['MTP_context'] |
|
| 2322 | - : ''; |
|
| 2323 | - $context = ucwords(str_replace('_', ' ', $context_slug)); |
|
| 2324 | - |
|
| 2325 | - $item_desc = $messenger_label && $message_type_label ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' : ''; |
|
| 2326 | - $item_desc .= 'Message Template'; |
|
| 2327 | - $query_args = array(); |
|
| 2328 | - $edit_array = array(); |
|
| 2329 | - $action_desc = ''; |
|
| 2330 | - |
|
| 2331 | - //if this is "new" then we need to generate the default contexts for the selected messenger/message_type for user to edit. |
|
| 2332 | - if ($new) { |
|
| 2333 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 2334 | - if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) { |
|
| 2335 | - if (empty($edit_array)) { |
|
| 2336 | - $success = 0; |
|
| 2337 | - } else { |
|
| 2338 | - $success = 1; |
|
| 2339 | - $edit_array = $edit_array[0]; |
|
| 2340 | - $query_args = array( |
|
| 2341 | - 'id' => $edit_array['GRP_ID'], |
|
| 2342 | - 'context' => $edit_array['MTP_context'], |
|
| 2343 | - 'action' => 'edit_message_template' |
|
| 2344 | - ); |
|
| 2345 | - } |
|
| 2346 | - } |
|
| 2347 | - $action_desc = 'created'; |
|
| 2348 | - } else { |
|
| 2349 | - $MTPG = EEM_Message_Template_Group::instance(); |
|
| 2350 | - $MTP = EEM_Message_Template::instance(); |
|
| 2275 | + $set_column_values = array( |
|
| 2276 | + 'MTP_ID' => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']), |
|
| 2277 | + 'GRP_ID' => absint($this->_req_data['GRP_ID']), |
|
| 2278 | + 'MTP_user_id' => absint($this->_req_data['MTP_user_id']), |
|
| 2279 | + 'MTP_messenger' => strtolower($this->_req_data['MTP_messenger']), |
|
| 2280 | + 'MTP_message_type' => strtolower($this->_req_data['MTP_message_type']), |
|
| 2281 | + 'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']), |
|
| 2282 | + 'MTP_context' => strtolower($this->_req_data['MTP_context']), |
|
| 2283 | + 'MTP_content' => $this->_req_data['MTP_template_fields'][$index]['content'], |
|
| 2284 | + 'MTP_is_global' => isset($this->_req_data['MTP_is_global']) |
|
| 2285 | + ? absint($this->_req_data['MTP_is_global']) |
|
| 2286 | + : 0, |
|
| 2287 | + 'MTP_is_override' => isset($this->_req_data['MTP_is_override']) |
|
| 2288 | + ? absint($this->_req_data['MTP_is_override']) |
|
| 2289 | + : 0, |
|
| 2290 | + 'MTP_deleted' => absint($this->_req_data['MTP_deleted']), |
|
| 2291 | + 'MTP_is_active' => absint($this->_req_data['MTP_is_active']) |
|
| 2292 | + ); |
|
| 2293 | + |
|
| 2294 | + |
|
| 2295 | + return $set_column_values; |
|
| 2296 | + } |
|
| 2297 | + |
|
| 2298 | + |
|
| 2299 | + protected function _insert_or_update_message_template($new = false) |
|
| 2300 | + { |
|
| 2301 | + |
|
| 2302 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2303 | + $success = 0; |
|
| 2304 | + $override = false; |
|
| 2305 | + |
|
| 2306 | + //setup notices description |
|
| 2307 | + $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : ''; |
|
| 2308 | + |
|
| 2309 | + //need the message type and messenger objects to be able to use the labels for the notices |
|
| 2310 | + $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug); |
|
| 2311 | + $messenger_label = $messenger_object instanceof EE_messenger ? ucwords($messenger_object->label['singular']) : ''; |
|
| 2312 | + |
|
| 2313 | + $message_type_slug = ! empty($this->_req_data['MTP_message_type']) ? $this->_req_data['MTP_message_type'] : ''; |
|
| 2314 | + $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug); |
|
| 2315 | + |
|
| 2316 | + $message_type_label = $message_type_object instanceof EE_message_type |
|
| 2317 | + ? ucwords($message_type_object->label['singular']) |
|
| 2318 | + : ''; |
|
| 2319 | + |
|
| 2320 | + $context_slug = ! empty($this->_req_data['MTP_context']) |
|
| 2321 | + ? $this->_req_data['MTP_context'] |
|
| 2322 | + : ''; |
|
| 2323 | + $context = ucwords(str_replace('_', ' ', $context_slug)); |
|
| 2324 | + |
|
| 2325 | + $item_desc = $messenger_label && $message_type_label ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' : ''; |
|
| 2326 | + $item_desc .= 'Message Template'; |
|
| 2327 | + $query_args = array(); |
|
| 2328 | + $edit_array = array(); |
|
| 2329 | + $action_desc = ''; |
|
| 2330 | + |
|
| 2331 | + //if this is "new" then we need to generate the default contexts for the selected messenger/message_type for user to edit. |
|
| 2332 | + if ($new) { |
|
| 2333 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 2334 | + if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) { |
|
| 2335 | + if (empty($edit_array)) { |
|
| 2336 | + $success = 0; |
|
| 2337 | + } else { |
|
| 2338 | + $success = 1; |
|
| 2339 | + $edit_array = $edit_array[0]; |
|
| 2340 | + $query_args = array( |
|
| 2341 | + 'id' => $edit_array['GRP_ID'], |
|
| 2342 | + 'context' => $edit_array['MTP_context'], |
|
| 2343 | + 'action' => 'edit_message_template' |
|
| 2344 | + ); |
|
| 2345 | + } |
|
| 2346 | + } |
|
| 2347 | + $action_desc = 'created'; |
|
| 2348 | + } else { |
|
| 2349 | + $MTPG = EEM_Message_Template_Group::instance(); |
|
| 2350 | + $MTP = EEM_Message_Template::instance(); |
|
| 2351 | 2351 | |
| 2352 | 2352 | |
| 2353 | - //run update for each template field in displayed context |
|
| 2354 | - if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) { |
|
| 2355 | - EE_Error::add_error( |
|
| 2356 | - __('There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.', |
|
| 2357 | - 'event_espresso'), |
|
| 2358 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2359 | - ); |
|
| 2360 | - $success = 0; |
|
| 2353 | + //run update for each template field in displayed context |
|
| 2354 | + if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) { |
|
| 2355 | + EE_Error::add_error( |
|
| 2356 | + __('There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.', |
|
| 2357 | + 'event_espresso'), |
|
| 2358 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2359 | + ); |
|
| 2360 | + $success = 0; |
|
| 2361 | 2361 | |
| 2362 | - } else { |
|
| 2363 | - //first validate all fields! |
|
| 2364 | - $validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug, |
|
| 2365 | - $message_type_slug); |
|
| 2362 | + } else { |
|
| 2363 | + //first validate all fields! |
|
| 2364 | + $validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug, |
|
| 2365 | + $message_type_slug); |
|
| 2366 | 2366 | |
| 2367 | - //if $validate returned error messages (i.e. is_array()) then we need to process them and setup an appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array. WE need to make sure there is no actual error messages in validates. |
|
| 2368 | - if (is_array($validates) && ! empty($validates)) { |
|
| 2369 | - //add the transient so when the form loads we know which fields to highlight |
|
| 2370 | - $this->_add_transient('edit_message_template', $validates); |
|
| 2367 | + //if $validate returned error messages (i.e. is_array()) then we need to process them and setup an appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array. WE need to make sure there is no actual error messages in validates. |
|
| 2368 | + if (is_array($validates) && ! empty($validates)) { |
|
| 2369 | + //add the transient so when the form loads we know which fields to highlight |
|
| 2370 | + $this->_add_transient('edit_message_template', $validates); |
|
| 2371 | 2371 | |
| 2372 | - $success = 0; |
|
| 2372 | + $success = 0; |
|
| 2373 | 2373 | |
| 2374 | - //setup notices |
|
| 2375 | - foreach ($validates as $field => $error) { |
|
| 2376 | - if (isset($error['msg'])) { |
|
| 2377 | - EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__); |
|
| 2378 | - } |
|
| 2379 | - } |
|
| 2374 | + //setup notices |
|
| 2375 | + foreach ($validates as $field => $error) { |
|
| 2376 | + if (isset($error['msg'])) { |
|
| 2377 | + EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__); |
|
| 2378 | + } |
|
| 2379 | + } |
|
| 2380 | 2380 | |
| 2381 | - } else { |
|
| 2382 | - $set_column_values = array(); |
|
| 2383 | - foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) { |
|
| 2384 | - $set_column_values = $this->_set_message_template_column_values($template_field); |
|
| 2381 | + } else { |
|
| 2382 | + $set_column_values = array(); |
|
| 2383 | + foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) { |
|
| 2384 | + $set_column_values = $this->_set_message_template_column_values($template_field); |
|
| 2385 | 2385 | |
| 2386 | - $where_cols_n_values = array( |
|
| 2387 | - 'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'] |
|
| 2388 | - ); |
|
| 2386 | + $where_cols_n_values = array( |
|
| 2387 | + 'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'] |
|
| 2388 | + ); |
|
| 2389 | 2389 | |
| 2390 | - $message_template_fields = array( |
|
| 2391 | - 'GRP_ID' => $set_column_values['GRP_ID'], |
|
| 2392 | - 'MTP_template_field' => $set_column_values['MTP_template_field'], |
|
| 2393 | - 'MTP_context' => $set_column_values['MTP_context'], |
|
| 2394 | - 'MTP_content' => $set_column_values['MTP_content'] |
|
| 2395 | - ); |
|
| 2396 | - if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) { |
|
| 2397 | - if ($updated === false) { |
|
| 2398 | - EE_Error::add_error( |
|
| 2399 | - sprintf( |
|
| 2400 | - __('%s field was NOT updated for some reason', 'event_espresso'), |
|
| 2401 | - $template_field |
|
| 2402 | - ), |
|
| 2403 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2404 | - ); |
|
| 2405 | - } else { |
|
| 2406 | - $success = 1; |
|
| 2407 | - } |
|
| 2408 | - } |
|
| 2409 | - $action_desc = 'updated'; |
|
| 2410 | - } |
|
| 2390 | + $message_template_fields = array( |
|
| 2391 | + 'GRP_ID' => $set_column_values['GRP_ID'], |
|
| 2392 | + 'MTP_template_field' => $set_column_values['MTP_template_field'], |
|
| 2393 | + 'MTP_context' => $set_column_values['MTP_context'], |
|
| 2394 | + 'MTP_content' => $set_column_values['MTP_content'] |
|
| 2395 | + ); |
|
| 2396 | + if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) { |
|
| 2397 | + if ($updated === false) { |
|
| 2398 | + EE_Error::add_error( |
|
| 2399 | + sprintf( |
|
| 2400 | + __('%s field was NOT updated for some reason', 'event_espresso'), |
|
| 2401 | + $template_field |
|
| 2402 | + ), |
|
| 2403 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2404 | + ); |
|
| 2405 | + } else { |
|
| 2406 | + $success = 1; |
|
| 2407 | + } |
|
| 2408 | + } |
|
| 2409 | + $action_desc = 'updated'; |
|
| 2410 | + } |
|
| 2411 | 2411 | |
| 2412 | - //we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs) |
|
| 2413 | - $mtpg_fields = array( |
|
| 2414 | - 'MTP_user_id' => $set_column_values['MTP_user_id'], |
|
| 2415 | - 'MTP_messenger' => $set_column_values['MTP_messenger'], |
|
| 2416 | - 'MTP_message_type' => $set_column_values['MTP_message_type'], |
|
| 2417 | - 'MTP_is_global' => $set_column_values['MTP_is_global'], |
|
| 2418 | - 'MTP_is_override' => $set_column_values['MTP_is_override'], |
|
| 2419 | - 'MTP_deleted' => $set_column_values['MTP_deleted'], |
|
| 2420 | - 'MTP_is_active' => $set_column_values['MTP_is_active'], |
|
| 2421 | - 'MTP_name' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name']) |
|
| 2422 | - ? $this->_req_data['ee_msg_non_global_fields']['MTP_name'] |
|
| 2423 | - : '', |
|
| 2424 | - 'MTP_description' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description']) |
|
| 2425 | - ? $this->_req_data['ee_msg_non_global_fields']['MTP_description'] |
|
| 2426 | - : '' |
|
| 2427 | - ); |
|
| 2412 | + //we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs) |
|
| 2413 | + $mtpg_fields = array( |
|
| 2414 | + 'MTP_user_id' => $set_column_values['MTP_user_id'], |
|
| 2415 | + 'MTP_messenger' => $set_column_values['MTP_messenger'], |
|
| 2416 | + 'MTP_message_type' => $set_column_values['MTP_message_type'], |
|
| 2417 | + 'MTP_is_global' => $set_column_values['MTP_is_global'], |
|
| 2418 | + 'MTP_is_override' => $set_column_values['MTP_is_override'], |
|
| 2419 | + 'MTP_deleted' => $set_column_values['MTP_deleted'], |
|
| 2420 | + 'MTP_is_active' => $set_column_values['MTP_is_active'], |
|
| 2421 | + 'MTP_name' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name']) |
|
| 2422 | + ? $this->_req_data['ee_msg_non_global_fields']['MTP_name'] |
|
| 2423 | + : '', |
|
| 2424 | + 'MTP_description' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description']) |
|
| 2425 | + ? $this->_req_data['ee_msg_non_global_fields']['MTP_description'] |
|
| 2426 | + : '' |
|
| 2427 | + ); |
|
| 2428 | 2428 | |
| 2429 | - $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']); |
|
| 2430 | - $updated = $MTPG->update($mtpg_fields, array($mtpg_where)); |
|
| 2429 | + $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']); |
|
| 2430 | + $updated = $MTPG->update($mtpg_fields, array($mtpg_where)); |
|
| 2431 | 2431 | |
| 2432 | - if ($updated === false) { |
|
| 2433 | - EE_Error::add_error( |
|
| 2434 | - sprintf( |
|
| 2435 | - __('The Message Template Group (%d) was NOT updated for some reason', 'event_espresso'), |
|
| 2436 | - $set_column_values['GRP_ID'] |
|
| 2437 | - ), |
|
| 2438 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2439 | - ); |
|
| 2440 | - } else { |
|
| 2441 | - //k now we need to ensure the template_pack and template_variation fields are set. |
|
| 2442 | - $template_pack = ! empty($this->_req_data['MTP_template_pack']) |
|
| 2443 | - ? $this->_req_data['MTP_template_pack'] |
|
| 2444 | - : 'default'; |
|
| 2432 | + if ($updated === false) { |
|
| 2433 | + EE_Error::add_error( |
|
| 2434 | + sprintf( |
|
| 2435 | + __('The Message Template Group (%d) was NOT updated for some reason', 'event_espresso'), |
|
| 2436 | + $set_column_values['GRP_ID'] |
|
| 2437 | + ), |
|
| 2438 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2439 | + ); |
|
| 2440 | + } else { |
|
| 2441 | + //k now we need to ensure the template_pack and template_variation fields are set. |
|
| 2442 | + $template_pack = ! empty($this->_req_data['MTP_template_pack']) |
|
| 2443 | + ? $this->_req_data['MTP_template_pack'] |
|
| 2444 | + : 'default'; |
|
| 2445 | 2445 | |
| 2446 | - $template_variation = ! empty($this->_req_data['MTP_template_variation']) |
|
| 2447 | - ? $this->_req_data['MTP_template_variation'] |
|
| 2448 | - : 'default'; |
|
| 2446 | + $template_variation = ! empty($this->_req_data['MTP_template_variation']) |
|
| 2447 | + ? $this->_req_data['MTP_template_variation'] |
|
| 2448 | + : 'default'; |
|
| 2449 | 2449 | |
| 2450 | - $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']); |
|
| 2451 | - if ($mtpg_obj instanceof EE_Message_Template_Group) { |
|
| 2452 | - $mtpg_obj->set_template_pack_name($template_pack); |
|
| 2453 | - $mtpg_obj->set_template_pack_variation($template_variation); |
|
| 2454 | - } |
|
| 2455 | - $success = 1; |
|
| 2456 | - } |
|
| 2457 | - } |
|
| 2458 | - } |
|
| 2450 | + $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']); |
|
| 2451 | + if ($mtpg_obj instanceof EE_Message_Template_Group) { |
|
| 2452 | + $mtpg_obj->set_template_pack_name($template_pack); |
|
| 2453 | + $mtpg_obj->set_template_pack_variation($template_variation); |
|
| 2454 | + } |
|
| 2455 | + $success = 1; |
|
| 2456 | + } |
|
| 2457 | + } |
|
| 2458 | + } |
|
| 2459 | 2459 | |
| 2460 | - } |
|
| 2461 | - |
|
| 2462 | - //we return things differently if doing ajax |
|
| 2463 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2464 | - $this->_template_args['success'] = $success; |
|
| 2465 | - $this->_template_args['error'] = ! $success ? true : false; |
|
| 2466 | - $this->_template_args['content'] = ''; |
|
| 2467 | - $this->_template_args['data'] = array( |
|
| 2468 | - 'grpID' => $edit_array['GRP_ID'], |
|
| 2469 | - 'templateName' => $edit_array['template_name'] |
|
| 2470 | - ); |
|
| 2471 | - if ($success) { |
|
| 2472 | - EE_Error::overwrite_success(); |
|
| 2473 | - EE_Error::add_success(__('The new template has been created and automatically selected for this event. You can edit the new template by clicking the edit button. Note before this template is assigned to this event, the event must be saved.', |
|
| 2474 | - 'event_espresso')); |
|
| 2475 | - } |
|
| 2460 | + } |
|
| 2461 | + |
|
| 2462 | + //we return things differently if doing ajax |
|
| 2463 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2464 | + $this->_template_args['success'] = $success; |
|
| 2465 | + $this->_template_args['error'] = ! $success ? true : false; |
|
| 2466 | + $this->_template_args['content'] = ''; |
|
| 2467 | + $this->_template_args['data'] = array( |
|
| 2468 | + 'grpID' => $edit_array['GRP_ID'], |
|
| 2469 | + 'templateName' => $edit_array['template_name'] |
|
| 2470 | + ); |
|
| 2471 | + if ($success) { |
|
| 2472 | + EE_Error::overwrite_success(); |
|
| 2473 | + EE_Error::add_success(__('The new template has been created and automatically selected for this event. You can edit the new template by clicking the edit button. Note before this template is assigned to this event, the event must be saved.', |
|
| 2474 | + 'event_espresso')); |
|
| 2475 | + } |
|
| 2476 | 2476 | |
| 2477 | - $this->_return_json(); |
|
| 2478 | - } |
|
| 2479 | - |
|
| 2480 | - |
|
| 2481 | - //was a test send triggered? |
|
| 2482 | - if (isset($this->_req_data['test_button'])) { |
|
| 2483 | - EE_Error::overwrite_success(); |
|
| 2484 | - $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug); |
|
| 2485 | - $override = true; |
|
| 2486 | - } |
|
| 2487 | - |
|
| 2488 | - if (empty($query_args)) { |
|
| 2489 | - $query_args = array( |
|
| 2490 | - 'id' => $this->_req_data['GRP_ID'], |
|
| 2491 | - 'context' => $context_slug, |
|
| 2492 | - 'action' => 'edit_message_template' |
|
| 2493 | - ); |
|
| 2494 | - } |
|
| 2495 | - |
|
| 2496 | - $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override); |
|
| 2497 | - } |
|
| 2498 | - |
|
| 2499 | - |
|
| 2500 | - /** |
|
| 2501 | - * processes a test send request to do an actual messenger delivery test for the given message template being tested |
|
| 2502 | - * |
|
| 2503 | - * @param string $context what context being tested |
|
| 2504 | - * @param string $messenger messenger being tested |
|
| 2505 | - * @param string $message_type message type being tested |
|
| 2506 | - * |
|
| 2507 | - */ |
|
| 2508 | - protected function _do_test_send($context, $messenger, $message_type) |
|
| 2509 | - { |
|
| 2510 | - //set things up for preview |
|
| 2511 | - $this->_req_data['messenger'] = $messenger; |
|
| 2512 | - $this->_req_data['message_type'] = $message_type; |
|
| 2513 | - $this->_req_data['context'] = $context; |
|
| 2514 | - $this->_req_data['GRP_ID'] = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : ''; |
|
| 2515 | - $active_messenger = $this->_message_resource_manager->get_active_messenger($messenger); |
|
| 2516 | - |
|
| 2517 | - //let's save any existing fields that might be required by the messenger |
|
| 2518 | - if ( |
|
| 2519 | - isset($this->_req_data['test_settings_fld']) |
|
| 2520 | - && $active_messenger instanceof EE_messenger |
|
| 2521 | - && apply_filters( |
|
| 2522 | - 'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings', |
|
| 2523 | - true, |
|
| 2524 | - $this->_req_data['test_settings_fld'], |
|
| 2525 | - $active_messenger |
|
| 2526 | - ) |
|
| 2527 | - ) { |
|
| 2528 | - $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']); |
|
| 2529 | - } |
|
| 2530 | - |
|
| 2531 | - $success = $this->_preview_message(true); |
|
| 2532 | - |
|
| 2533 | - if ($success) { |
|
| 2534 | - EE_Error::add_success(__('Test message sent', 'event_espresso')); |
|
| 2535 | - } else { |
|
| 2536 | - EE_Error::add_error(__('The test message was not sent', 'event_espresso'), __FILE__, __FUNCTION__, |
|
| 2537 | - __LINE__); |
|
| 2538 | - } |
|
| 2539 | - } |
|
| 2540 | - |
|
| 2541 | - |
|
| 2542 | - /** |
|
| 2543 | - * _generate_new_templates |
|
| 2544 | - * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will |
|
| 2545 | - * automatically create the defaults for the event. The user would then be redirected to edit the default context |
|
| 2546 | - * for the event. |
|
| 2547 | - * |
|
| 2548 | - * |
|
| 2549 | - * @param string $messenger the messenger we are generating templates for |
|
| 2550 | - * @param array $message_types array of message types that the templates are generated for. |
|
| 2551 | - * @param int $GRP_ID If this is a custom template being generated then a GRP_ID needs to be included to |
|
| 2552 | - * indicate the message_template_group being used as the base. |
|
| 2553 | - * |
|
| 2554 | - * @param bool $global |
|
| 2555 | - * |
|
| 2556 | - * @return array|bool array of data required for the redirect to the correct edit page or bool if |
|
| 2557 | - * encountering problems. |
|
| 2558 | - * @throws \EE_Error |
|
| 2559 | - */ |
|
| 2560 | - protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false) |
|
| 2561 | - { |
|
| 2562 | - |
|
| 2563 | - //if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we just don't generate any templates. |
|
| 2564 | - if (empty($message_types)) { |
|
| 2565 | - return true; |
|
| 2566 | - } |
|
| 2567 | - |
|
| 2568 | - return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global); |
|
| 2569 | - } |
|
| 2570 | - |
|
| 2571 | - |
|
| 2572 | - /** |
|
| 2573 | - * [_trash_or_restore_message_template] |
|
| 2574 | - * |
|
| 2575 | - * @param boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE) |
|
| 2576 | - * @param boolean $all whether this is going to trash/restore all contexts within a template group (TRUE) OR just |
|
| 2577 | - * an individual context (FALSE). |
|
| 2578 | - * |
|
| 2579 | - * @return void |
|
| 2580 | - */ |
|
| 2581 | - protected function _trash_or_restore_message_template($trash = true, $all = false) |
|
| 2582 | - { |
|
| 2583 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2584 | - $MTP = EEM_Message_Template_Group::instance(); |
|
| 2585 | - |
|
| 2586 | - $success = 1; |
|
| 2587 | - |
|
| 2588 | - //incoming GRP_IDs |
|
| 2589 | - if ($all) { |
|
| 2590 | - //Checkboxes |
|
| 2591 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 2592 | - //if array has more than one element then success message should be plural. |
|
| 2593 | - //todo: what about nonce? |
|
| 2594 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 2477 | + $this->_return_json(); |
|
| 2478 | + } |
|
| 2479 | + |
|
| 2480 | + |
|
| 2481 | + //was a test send triggered? |
|
| 2482 | + if (isset($this->_req_data['test_button'])) { |
|
| 2483 | + EE_Error::overwrite_success(); |
|
| 2484 | + $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug); |
|
| 2485 | + $override = true; |
|
| 2486 | + } |
|
| 2487 | + |
|
| 2488 | + if (empty($query_args)) { |
|
| 2489 | + $query_args = array( |
|
| 2490 | + 'id' => $this->_req_data['GRP_ID'], |
|
| 2491 | + 'context' => $context_slug, |
|
| 2492 | + 'action' => 'edit_message_template' |
|
| 2493 | + ); |
|
| 2494 | + } |
|
| 2495 | + |
|
| 2496 | + $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override); |
|
| 2497 | + } |
|
| 2498 | + |
|
| 2499 | + |
|
| 2500 | + /** |
|
| 2501 | + * processes a test send request to do an actual messenger delivery test for the given message template being tested |
|
| 2502 | + * |
|
| 2503 | + * @param string $context what context being tested |
|
| 2504 | + * @param string $messenger messenger being tested |
|
| 2505 | + * @param string $message_type message type being tested |
|
| 2506 | + * |
|
| 2507 | + */ |
|
| 2508 | + protected function _do_test_send($context, $messenger, $message_type) |
|
| 2509 | + { |
|
| 2510 | + //set things up for preview |
|
| 2511 | + $this->_req_data['messenger'] = $messenger; |
|
| 2512 | + $this->_req_data['message_type'] = $message_type; |
|
| 2513 | + $this->_req_data['context'] = $context; |
|
| 2514 | + $this->_req_data['GRP_ID'] = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : ''; |
|
| 2515 | + $active_messenger = $this->_message_resource_manager->get_active_messenger($messenger); |
|
| 2516 | + |
|
| 2517 | + //let's save any existing fields that might be required by the messenger |
|
| 2518 | + if ( |
|
| 2519 | + isset($this->_req_data['test_settings_fld']) |
|
| 2520 | + && $active_messenger instanceof EE_messenger |
|
| 2521 | + && apply_filters( |
|
| 2522 | + 'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings', |
|
| 2523 | + true, |
|
| 2524 | + $this->_req_data['test_settings_fld'], |
|
| 2525 | + $active_messenger |
|
| 2526 | + ) |
|
| 2527 | + ) { |
|
| 2528 | + $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']); |
|
| 2529 | + } |
|
| 2530 | + |
|
| 2531 | + $success = $this->_preview_message(true); |
|
| 2532 | + |
|
| 2533 | + if ($success) { |
|
| 2534 | + EE_Error::add_success(__('Test message sent', 'event_espresso')); |
|
| 2535 | + } else { |
|
| 2536 | + EE_Error::add_error(__('The test message was not sent', 'event_espresso'), __FILE__, __FUNCTION__, |
|
| 2537 | + __LINE__); |
|
| 2538 | + } |
|
| 2539 | + } |
|
| 2540 | + |
|
| 2541 | + |
|
| 2542 | + /** |
|
| 2543 | + * _generate_new_templates |
|
| 2544 | + * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will |
|
| 2545 | + * automatically create the defaults for the event. The user would then be redirected to edit the default context |
|
| 2546 | + * for the event. |
|
| 2547 | + * |
|
| 2548 | + * |
|
| 2549 | + * @param string $messenger the messenger we are generating templates for |
|
| 2550 | + * @param array $message_types array of message types that the templates are generated for. |
|
| 2551 | + * @param int $GRP_ID If this is a custom template being generated then a GRP_ID needs to be included to |
|
| 2552 | + * indicate the message_template_group being used as the base. |
|
| 2553 | + * |
|
| 2554 | + * @param bool $global |
|
| 2555 | + * |
|
| 2556 | + * @return array|bool array of data required for the redirect to the correct edit page or bool if |
|
| 2557 | + * encountering problems. |
|
| 2558 | + * @throws \EE_Error |
|
| 2559 | + */ |
|
| 2560 | + protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false) |
|
| 2561 | + { |
|
| 2562 | + |
|
| 2563 | + //if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we just don't generate any templates. |
|
| 2564 | + if (empty($message_types)) { |
|
| 2565 | + return true; |
|
| 2566 | + } |
|
| 2567 | + |
|
| 2568 | + return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global); |
|
| 2569 | + } |
|
| 2570 | + |
|
| 2571 | + |
|
| 2572 | + /** |
|
| 2573 | + * [_trash_or_restore_message_template] |
|
| 2574 | + * |
|
| 2575 | + * @param boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE) |
|
| 2576 | + * @param boolean $all whether this is going to trash/restore all contexts within a template group (TRUE) OR just |
|
| 2577 | + * an individual context (FALSE). |
|
| 2578 | + * |
|
| 2579 | + * @return void |
|
| 2580 | + */ |
|
| 2581 | + protected function _trash_or_restore_message_template($trash = true, $all = false) |
|
| 2582 | + { |
|
| 2583 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2584 | + $MTP = EEM_Message_Template_Group::instance(); |
|
| 2585 | + |
|
| 2586 | + $success = 1; |
|
| 2587 | + |
|
| 2588 | + //incoming GRP_IDs |
|
| 2589 | + if ($all) { |
|
| 2590 | + //Checkboxes |
|
| 2591 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 2592 | + //if array has more than one element then success message should be plural. |
|
| 2593 | + //todo: what about nonce? |
|
| 2594 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 2595 | 2595 | |
| 2596 | - //cycle through checkboxes |
|
| 2597 | - while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 2598 | - $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 2599 | - if ( ! $trashed_or_restored) { |
|
| 2600 | - $success = 0; |
|
| 2601 | - } |
|
| 2602 | - } |
|
| 2603 | - } else { |
|
| 2604 | - //grab single GRP_ID and handle |
|
| 2605 | - $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
| 2606 | - if ( ! empty($GRP_ID)) { |
|
| 2607 | - $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 2608 | - if ( ! $trashed_or_restored) { |
|
| 2609 | - $success = 0; |
|
| 2610 | - } |
|
| 2611 | - } else { |
|
| 2612 | - $success = 0; |
|
| 2613 | - } |
|
| 2614 | - } |
|
| 2596 | + //cycle through checkboxes |
|
| 2597 | + while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 2598 | + $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 2599 | + if ( ! $trashed_or_restored) { |
|
| 2600 | + $success = 0; |
|
| 2601 | + } |
|
| 2602 | + } |
|
| 2603 | + } else { |
|
| 2604 | + //grab single GRP_ID and handle |
|
| 2605 | + $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
| 2606 | + if ( ! empty($GRP_ID)) { |
|
| 2607 | + $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 2608 | + if ( ! $trashed_or_restored) { |
|
| 2609 | + $success = 0; |
|
| 2610 | + } |
|
| 2611 | + } else { |
|
| 2612 | + $success = 0; |
|
| 2613 | + } |
|
| 2614 | + } |
|
| 2615 | 2615 | |
| 2616 | - } |
|
| 2616 | + } |
|
| 2617 | 2617 | |
| 2618 | - $action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso'); |
|
| 2618 | + $action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso'); |
|
| 2619 | 2619 | |
| 2620 | - $action_desc = ! empty($this->_req_data['template_switch']) ? __('switched') : $action_desc; |
|
| 2620 | + $action_desc = ! empty($this->_req_data['template_switch']) ? __('switched') : $action_desc; |
|
| 2621 | 2621 | |
| 2622 | - $item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success, |
|
| 2623 | - 'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso'); |
|
| 2622 | + $item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success, |
|
| 2623 | + 'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso'); |
|
| 2624 | 2624 | |
| 2625 | - $item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success, |
|
| 2626 | - 'event_espresso') : $item_desc; |
|
| 2625 | + $item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success, |
|
| 2626 | + 'event_espresso') : $item_desc; |
|
| 2627 | 2627 | |
| 2628 | - $this->_redirect_after_action($success, $item_desc, $action_desc, array()); |
|
| 2628 | + $this->_redirect_after_action($success, $item_desc, $action_desc, array()); |
|
| 2629 | 2629 | |
| 2630 | - } |
|
| 2630 | + } |
|
| 2631 | 2631 | |
| 2632 | 2632 | |
| 2633 | - /** |
|
| 2634 | - * [_delete_message_template] |
|
| 2635 | - * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group. |
|
| 2636 | - * @return void |
|
| 2637 | - */ |
|
| 2638 | - protected function _delete_message_template() |
|
| 2639 | - { |
|
| 2640 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2633 | + /** |
|
| 2634 | + * [_delete_message_template] |
|
| 2635 | + * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group. |
|
| 2636 | + * @return void |
|
| 2637 | + */ |
|
| 2638 | + protected function _delete_message_template() |
|
| 2639 | + { |
|
| 2640 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2641 | 2641 | |
| 2642 | - //checkboxes |
|
| 2643 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 2644 | - //if array has more than one element then success message should be plural |
|
| 2645 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 2642 | + //checkboxes |
|
| 2643 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 2644 | + //if array has more than one element then success message should be plural |
|
| 2645 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 2646 | 2646 | |
| 2647 | - //cycle through bulk action checkboxes |
|
| 2648 | - while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 2649 | - $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 2650 | - } |
|
| 2651 | - } else { |
|
| 2652 | - //grab single grp_id and delete |
|
| 2653 | - $GRP_ID = absint($this->_req_data['id']); |
|
| 2654 | - $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 2655 | - } |
|
| 2656 | - |
|
| 2657 | - $this->_redirect_after_action($success, 'Message Templates', 'deleted', array()); |
|
| 2658 | - |
|
| 2659 | - } |
|
| 2660 | - |
|
| 2661 | - |
|
| 2662 | - /** |
|
| 2663 | - * helper for permanently deleting a mtP group and all related message_templates |
|
| 2664 | - * |
|
| 2665 | - * @param int $GRP_ID The group being deleted |
|
| 2666 | - * @param bool $include_group whether to delete the Message Template Group as well. |
|
| 2667 | - * |
|
| 2668 | - * @return bool boolean to indicate the success of the deletes or not. |
|
| 2669 | - */ |
|
| 2670 | - private function _delete_mtp_permanently($GRP_ID, $include_group = true) |
|
| 2671 | - { |
|
| 2672 | - $success = 1; |
|
| 2673 | - $MTPG = EEM_Message_Template_Group::instance(); |
|
| 2674 | - //first let's GET this group |
|
| 2675 | - $MTG = $MTPG->get_one_by_ID($GRP_ID); |
|
| 2676 | - //then delete permanently all the related Message Templates |
|
| 2677 | - $deleted = $MTG->delete_related_permanently('Message_Template'); |
|
| 2678 | - |
|
| 2679 | - if ($deleted === 0) { |
|
| 2680 | - $success = 0; |
|
| 2681 | - } |
|
| 2682 | - |
|
| 2683 | - //now delete permanently this particular group |
|
| 2684 | - |
|
| 2685 | - if ($include_group && ! $MTG->delete_permanently()) { |
|
| 2686 | - $success = 0; |
|
| 2687 | - } |
|
| 2688 | - |
|
| 2689 | - return $success; |
|
| 2690 | - } |
|
| 2691 | - |
|
| 2692 | - |
|
| 2693 | - /** |
|
| 2694 | - * _learn_more_about_message_templates_link |
|
| 2695 | - * @access protected |
|
| 2696 | - * @return string |
|
| 2697 | - */ |
|
| 2698 | - protected function _learn_more_about_message_templates_link() |
|
| 2699 | - { |
|
| 2700 | - return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __('learn more about how message templates works', |
|
| 2701 | - 'event_espresso') . '</a>'; |
|
| 2702 | - } |
|
| 2703 | - |
|
| 2704 | - |
|
| 2705 | - /** |
|
| 2706 | - * Used for setting up messenger/message type activation. This loads up the initial view. The rest is handled by |
|
| 2707 | - * ajax and other routes. |
|
| 2708 | - * @return void |
|
| 2709 | - */ |
|
| 2710 | - protected function _settings() |
|
| 2711 | - { |
|
| 2712 | - |
|
| 2713 | - |
|
| 2714 | - $this->_set_m_mt_settings(); |
|
| 2715 | - |
|
| 2716 | - $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email'; |
|
| 2717 | - |
|
| 2718 | - //let's setup the messenger tabs |
|
| 2719 | - $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links($this->_m_mt_settings['messenger_tabs'], |
|
| 2720 | - 'messenger_links', '|', $selected_messenger); |
|
| 2721 | - $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">'; |
|
| 2722 | - $this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->'; |
|
| 2723 | - |
|
| 2724 | - $this->display_admin_page_with_sidebar(); |
|
| 2725 | - |
|
| 2726 | - } |
|
| 2727 | - |
|
| 2728 | - |
|
| 2729 | - /** |
|
| 2730 | - * This sets the $_m_mt_settings property for when needed (used on the Messages settings page) |
|
| 2731 | - * |
|
| 2732 | - * @access protected |
|
| 2733 | - * @return void |
|
| 2734 | - */ |
|
| 2735 | - protected function _set_m_mt_settings() |
|
| 2736 | - { |
|
| 2737 | - //first if this is already set then lets get out no need to regenerate data. |
|
| 2738 | - if ( ! empty($this->_m_mt_settings)) { |
|
| 2739 | - return; |
|
| 2740 | - } |
|
| 2741 | - |
|
| 2742 | - //$selected_messenger = isset( $this->_req_data['selected_messenger'] ) ? $this->_req_data['selected_messenger'] : 'email'; |
|
| 2743 | - |
|
| 2744 | - //get all installed messengers and message_types |
|
| 2745 | - /** @type EE_messenger[] $messengers */ |
|
| 2746 | - $messengers = $this->_message_resource_manager->installed_messengers(); |
|
| 2747 | - /** @type EE_message_type[] $message_types */ |
|
| 2748 | - $message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 2749 | - |
|
| 2750 | - |
|
| 2751 | - //assemble the array for the _tab_text_links helper |
|
| 2752 | - |
|
| 2753 | - foreach ($messengers as $messenger) { |
|
| 2754 | - $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array( |
|
| 2755 | - 'label' => ucwords($messenger->label['singular']), |
|
| 2756 | - 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) ? 'messenger-active' : '', |
|
| 2757 | - 'href' => $messenger->name, |
|
| 2758 | - 'title' => __('Modify this Messenger', 'event_espresso'), |
|
| 2759 | - 'slug' => $messenger->name, |
|
| 2760 | - 'obj' => $messenger |
|
| 2761 | - ); |
|
| 2647 | + //cycle through bulk action checkboxes |
|
| 2648 | + while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 2649 | + $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 2650 | + } |
|
| 2651 | + } else { |
|
| 2652 | + //grab single grp_id and delete |
|
| 2653 | + $GRP_ID = absint($this->_req_data['id']); |
|
| 2654 | + $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 2655 | + } |
|
| 2656 | + |
|
| 2657 | + $this->_redirect_after_action($success, 'Message Templates', 'deleted', array()); |
|
| 2658 | + |
|
| 2659 | + } |
|
| 2660 | + |
|
| 2661 | + |
|
| 2662 | + /** |
|
| 2663 | + * helper for permanently deleting a mtP group and all related message_templates |
|
| 2664 | + * |
|
| 2665 | + * @param int $GRP_ID The group being deleted |
|
| 2666 | + * @param bool $include_group whether to delete the Message Template Group as well. |
|
| 2667 | + * |
|
| 2668 | + * @return bool boolean to indicate the success of the deletes or not. |
|
| 2669 | + */ |
|
| 2670 | + private function _delete_mtp_permanently($GRP_ID, $include_group = true) |
|
| 2671 | + { |
|
| 2672 | + $success = 1; |
|
| 2673 | + $MTPG = EEM_Message_Template_Group::instance(); |
|
| 2674 | + //first let's GET this group |
|
| 2675 | + $MTG = $MTPG->get_one_by_ID($GRP_ID); |
|
| 2676 | + //then delete permanently all the related Message Templates |
|
| 2677 | + $deleted = $MTG->delete_related_permanently('Message_Template'); |
|
| 2678 | + |
|
| 2679 | + if ($deleted === 0) { |
|
| 2680 | + $success = 0; |
|
| 2681 | + } |
|
| 2682 | + |
|
| 2683 | + //now delete permanently this particular group |
|
| 2684 | + |
|
| 2685 | + if ($include_group && ! $MTG->delete_permanently()) { |
|
| 2686 | + $success = 0; |
|
| 2687 | + } |
|
| 2688 | + |
|
| 2689 | + return $success; |
|
| 2690 | + } |
|
| 2691 | + |
|
| 2692 | + |
|
| 2693 | + /** |
|
| 2694 | + * _learn_more_about_message_templates_link |
|
| 2695 | + * @access protected |
|
| 2696 | + * @return string |
|
| 2697 | + */ |
|
| 2698 | + protected function _learn_more_about_message_templates_link() |
|
| 2699 | + { |
|
| 2700 | + return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __('learn more about how message templates works', |
|
| 2701 | + 'event_espresso') . '</a>'; |
|
| 2702 | + } |
|
| 2703 | + |
|
| 2704 | + |
|
| 2705 | + /** |
|
| 2706 | + * Used for setting up messenger/message type activation. This loads up the initial view. The rest is handled by |
|
| 2707 | + * ajax and other routes. |
|
| 2708 | + * @return void |
|
| 2709 | + */ |
|
| 2710 | + protected function _settings() |
|
| 2711 | + { |
|
| 2712 | + |
|
| 2713 | + |
|
| 2714 | + $this->_set_m_mt_settings(); |
|
| 2715 | + |
|
| 2716 | + $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email'; |
|
| 2717 | + |
|
| 2718 | + //let's setup the messenger tabs |
|
| 2719 | + $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links($this->_m_mt_settings['messenger_tabs'], |
|
| 2720 | + 'messenger_links', '|', $selected_messenger); |
|
| 2721 | + $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">'; |
|
| 2722 | + $this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->'; |
|
| 2723 | + |
|
| 2724 | + $this->display_admin_page_with_sidebar(); |
|
| 2725 | + |
|
| 2726 | + } |
|
| 2727 | + |
|
| 2728 | + |
|
| 2729 | + /** |
|
| 2730 | + * This sets the $_m_mt_settings property for when needed (used on the Messages settings page) |
|
| 2731 | + * |
|
| 2732 | + * @access protected |
|
| 2733 | + * @return void |
|
| 2734 | + */ |
|
| 2735 | + protected function _set_m_mt_settings() |
|
| 2736 | + { |
|
| 2737 | + //first if this is already set then lets get out no need to regenerate data. |
|
| 2738 | + if ( ! empty($this->_m_mt_settings)) { |
|
| 2739 | + return; |
|
| 2740 | + } |
|
| 2741 | + |
|
| 2742 | + //$selected_messenger = isset( $this->_req_data['selected_messenger'] ) ? $this->_req_data['selected_messenger'] : 'email'; |
|
| 2743 | + |
|
| 2744 | + //get all installed messengers and message_types |
|
| 2745 | + /** @type EE_messenger[] $messengers */ |
|
| 2746 | + $messengers = $this->_message_resource_manager->installed_messengers(); |
|
| 2747 | + /** @type EE_message_type[] $message_types */ |
|
| 2748 | + $message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 2749 | + |
|
| 2750 | + |
|
| 2751 | + //assemble the array for the _tab_text_links helper |
|
| 2752 | + |
|
| 2753 | + foreach ($messengers as $messenger) { |
|
| 2754 | + $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array( |
|
| 2755 | + 'label' => ucwords($messenger->label['singular']), |
|
| 2756 | + 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) ? 'messenger-active' : '', |
|
| 2757 | + 'href' => $messenger->name, |
|
| 2758 | + 'title' => __('Modify this Messenger', 'event_espresso'), |
|
| 2759 | + 'slug' => $messenger->name, |
|
| 2760 | + 'obj' => $messenger |
|
| 2761 | + ); |
|
| 2762 | 2762 | |
| 2763 | 2763 | |
| 2764 | - $message_types_for_messenger = $messenger->get_valid_message_types(); |
|
| 2764 | + $message_types_for_messenger = $messenger->get_valid_message_types(); |
|
| 2765 | 2765 | |
| 2766 | - foreach ($message_types as $message_type) { |
|
| 2767 | - //first we need to verify that this message type is valid with this messenger. Cause if it isn't then it shouldn't show in either the inactive OR active metabox. |
|
| 2768 | - if ( ! in_array($message_type->name, $message_types_for_messenger)) { |
|
| 2769 | - continue; |
|
| 2770 | - } |
|
| 2766 | + foreach ($message_types as $message_type) { |
|
| 2767 | + //first we need to verify that this message type is valid with this messenger. Cause if it isn't then it shouldn't show in either the inactive OR active metabox. |
|
| 2768 | + if ( ! in_array($message_type->name, $message_types_for_messenger)) { |
|
| 2769 | + continue; |
|
| 2770 | + } |
|
| 2771 | 2771 | |
| 2772 | - $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger($messenger->name, |
|
| 2773 | - $message_type->name) ? 'active' : 'inactive'; |
|
| 2772 | + $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger($messenger->name, |
|
| 2773 | + $message_type->name) ? 'active' : 'inactive'; |
|
| 2774 | 2774 | |
| 2775 | - $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array( |
|
| 2776 | - 'label' => ucwords($message_type->label['singular']), |
|
| 2777 | - 'class' => 'message-type-' . $a_or_i, |
|
| 2778 | - 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name, |
|
| 2779 | - 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'), |
|
| 2780 | - 'href' => 'espresso_' . $message_type->name . '_message_type_settings', |
|
| 2781 | - 'title' => $a_or_i == 'active' |
|
| 2782 | - ? __('Drag this message type to the Inactive window to deactivate', 'event_espresso') |
|
| 2783 | - : __('Drag this message type to the messenger to activate', 'event_espresso'), |
|
| 2784 | - 'content' => $a_or_i == 'active' |
|
| 2785 | - ? $this->_message_type_settings_content($message_type, $messenger, true) |
|
| 2786 | - : $this->_message_type_settings_content($message_type, $messenger), |
|
| 2787 | - 'slug' => $message_type->name, |
|
| 2788 | - 'active' => $a_or_i == 'active' ? true : false, |
|
| 2789 | - 'obj' => $message_type |
|
| 2790 | - ); |
|
| 2791 | - } |
|
| 2792 | - } |
|
| 2793 | - } |
|
| 2794 | - |
|
| 2795 | - |
|
| 2796 | - /** |
|
| 2797 | - * This just prepares the content for the message type settings |
|
| 2798 | - * |
|
| 2799 | - * @param object $message_type The message type object |
|
| 2800 | - * @param object $messenger The messenger object |
|
| 2801 | - * @param boolean $active Whether the message type is active or not |
|
| 2802 | - * |
|
| 2803 | - * @return string html output for the content |
|
| 2804 | - */ |
|
| 2805 | - protected function _message_type_settings_content($message_type, $messenger, $active = false) |
|
| 2806 | - { |
|
| 2807 | - //get message type fields |
|
| 2808 | - $fields = $message_type->get_admin_settings_fields(); |
|
| 2809 | - $settings_template_args['template_form_fields'] = ''; |
|
| 2810 | - |
|
| 2811 | - if ( ! empty($fields) && $active) { |
|
| 2775 | + $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array( |
|
| 2776 | + 'label' => ucwords($message_type->label['singular']), |
|
| 2777 | + 'class' => 'message-type-' . $a_or_i, |
|
| 2778 | + 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name, |
|
| 2779 | + 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'), |
|
| 2780 | + 'href' => 'espresso_' . $message_type->name . '_message_type_settings', |
|
| 2781 | + 'title' => $a_or_i == 'active' |
|
| 2782 | + ? __('Drag this message type to the Inactive window to deactivate', 'event_espresso') |
|
| 2783 | + : __('Drag this message type to the messenger to activate', 'event_espresso'), |
|
| 2784 | + 'content' => $a_or_i == 'active' |
|
| 2785 | + ? $this->_message_type_settings_content($message_type, $messenger, true) |
|
| 2786 | + : $this->_message_type_settings_content($message_type, $messenger), |
|
| 2787 | + 'slug' => $message_type->name, |
|
| 2788 | + 'active' => $a_or_i == 'active' ? true : false, |
|
| 2789 | + 'obj' => $message_type |
|
| 2790 | + ); |
|
| 2791 | + } |
|
| 2792 | + } |
|
| 2793 | + } |
|
| 2794 | + |
|
| 2795 | + |
|
| 2796 | + /** |
|
| 2797 | + * This just prepares the content for the message type settings |
|
| 2798 | + * |
|
| 2799 | + * @param object $message_type The message type object |
|
| 2800 | + * @param object $messenger The messenger object |
|
| 2801 | + * @param boolean $active Whether the message type is active or not |
|
| 2802 | + * |
|
| 2803 | + * @return string html output for the content |
|
| 2804 | + */ |
|
| 2805 | + protected function _message_type_settings_content($message_type, $messenger, $active = false) |
|
| 2806 | + { |
|
| 2807 | + //get message type fields |
|
| 2808 | + $fields = $message_type->get_admin_settings_fields(); |
|
| 2809 | + $settings_template_args['template_form_fields'] = ''; |
|
| 2810 | + |
|
| 2811 | + if ( ! empty($fields) && $active) { |
|
| 2812 | 2812 | |
| 2813 | - $existing_settings = $message_type->get_existing_admin_settings($messenger->name); |
|
| 2813 | + $existing_settings = $message_type->get_existing_admin_settings($messenger->name); |
|
| 2814 | 2814 | |
| 2815 | - foreach ($fields as $fldname => $fldprops) { |
|
| 2816 | - $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname; |
|
| 2817 | - $template_form_field[$field_id] = array( |
|
| 2818 | - 'name' => 'message_type_settings[' . $fldname . ']', |
|
| 2819 | - 'label' => $fldprops['label'], |
|
| 2820 | - 'input' => $fldprops['field_type'], |
|
| 2821 | - 'type' => $fldprops['value_type'], |
|
| 2822 | - 'required' => $fldprops['required'], |
|
| 2823 | - 'validation' => $fldprops['validation'], |
|
| 2824 | - 'value' => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'], |
|
| 2825 | - 'options' => isset($fldprops['options']) ? $fldprops['options'] : array(), |
|
| 2826 | - 'default' => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'], |
|
| 2827 | - 'css_class' => 'no-drag', |
|
| 2828 | - 'format' => $fldprops['format'] |
|
| 2829 | - ); |
|
| 2830 | - } |
|
| 2815 | + foreach ($fields as $fldname => $fldprops) { |
|
| 2816 | + $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname; |
|
| 2817 | + $template_form_field[$field_id] = array( |
|
| 2818 | + 'name' => 'message_type_settings[' . $fldname . ']', |
|
| 2819 | + 'label' => $fldprops['label'], |
|
| 2820 | + 'input' => $fldprops['field_type'], |
|
| 2821 | + 'type' => $fldprops['value_type'], |
|
| 2822 | + 'required' => $fldprops['required'], |
|
| 2823 | + 'validation' => $fldprops['validation'], |
|
| 2824 | + 'value' => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'], |
|
| 2825 | + 'options' => isset($fldprops['options']) ? $fldprops['options'] : array(), |
|
| 2826 | + 'default' => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'], |
|
| 2827 | + 'css_class' => 'no-drag', |
|
| 2828 | + 'format' => $fldprops['format'] |
|
| 2829 | + ); |
|
| 2830 | + } |
|
| 2831 | 2831 | |
| 2832 | 2832 | |
| 2833 | - $settings_template_args['template_form_fields'] = ! empty($template_form_field) ? $this->_generate_admin_form_fields($template_form_field, |
|
| 2834 | - 'string', 'ee_mt_activate_form') : ''; |
|
| 2835 | - } |
|
| 2836 | - |
|
| 2837 | - $settings_template_args['description'] = $message_type->description; |
|
| 2838 | - //we also need some hidden fields |
|
| 2839 | - $settings_template_args['hidden_fields'] = array( |
|
| 2840 | - 'message_type_settings[messenger]' => array( |
|
| 2841 | - 'type' => 'hidden', |
|
| 2842 | - 'value' => $messenger->name |
|
| 2843 | - ), |
|
| 2844 | - 'message_type_settings[message_type]' => array( |
|
| 2845 | - 'type' => 'hidden', |
|
| 2846 | - 'value' => $message_type->name |
|
| 2847 | - ), |
|
| 2848 | - 'type' => array( |
|
| 2849 | - 'type' => 'hidden', |
|
| 2850 | - 'value' => 'message_type' |
|
| 2851 | - ) |
|
| 2852 | - ); |
|
| 2853 | - |
|
| 2854 | - $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields($settings_template_args['hidden_fields'], |
|
| 2855 | - 'array'); |
|
| 2856 | - $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) ? ' hidden' : ''; |
|
| 2857 | - |
|
| 2858 | - |
|
| 2859 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php'; |
|
| 2860 | - $content = EEH_Template::display_template($template, $settings_template_args, true); |
|
| 2861 | - |
|
| 2862 | - return $content; |
|
| 2863 | - } |
|
| 2864 | - |
|
| 2865 | - |
|
| 2866 | - /** |
|
| 2867 | - * Generate all the metaboxes for the message types and register them for the messages settings page. |
|
| 2868 | - * |
|
| 2869 | - * @access protected |
|
| 2870 | - * @return void |
|
| 2871 | - */ |
|
| 2872 | - protected function _messages_settings_metaboxes() |
|
| 2873 | - { |
|
| 2874 | - $this->_set_m_mt_settings(); |
|
| 2875 | - $m_boxes = $mt_boxes = array(); |
|
| 2876 | - $m_template_args = $mt_template_args = array(); |
|
| 2877 | - |
|
| 2878 | - $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email'; |
|
| 2879 | - |
|
| 2880 | - if (isset($this->_m_mt_settings['messenger_tabs'])) { |
|
| 2881 | - foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) { |
|
| 2882 | - $hide_on_message = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden'; |
|
| 2883 | - $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : ''; |
|
| 2884 | - //messenger meta boxes |
|
| 2885 | - $active = $selected_messenger == $messenger ? true : false; |
|
| 2886 | - $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active']) |
|
| 2887 | - ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
|
| 2888 | - : ''; |
|
| 2889 | - $m_boxes[$messenger . '_a_box'] = sprintf( |
|
| 2890 | - __('%s Settings', 'event_espresso'), |
|
| 2891 | - $tab_array['label'] |
|
| 2892 | - ); |
|
| 2893 | - $m_template_args[$messenger . '_a_box'] = array( |
|
| 2894 | - 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 2895 | - 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2896 | - ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2897 | - : '', |
|
| 2898 | - 'content' => $this->_get_messenger_box_content($tab_array['obj']), |
|
| 2899 | - 'hidden' => $active ? '' : ' hidden', |
|
| 2900 | - 'hide_on_message' => $hide_on_message, |
|
| 2901 | - 'messenger' => $messenger, |
|
| 2902 | - 'active' => $active |
|
| 2903 | - ); |
|
| 2904 | - // message type meta boxes |
|
| 2905 | - // (which is really just the inactive container for each messenger |
|
| 2906 | - // showing inactive message types for that messenger) |
|
| 2907 | - $mt_boxes[$messenger . '_i_box'] = __('Inactive Message Types', 'event_espresso'); |
|
| 2908 | - $mt_template_args[$messenger . '_i_box'] = array( |
|
| 2909 | - 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 2910 | - 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2911 | - ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2912 | - : '', |
|
| 2913 | - 'hidden' => $active ? '' : ' hidden', |
|
| 2914 | - 'hide_on_message' => $hide_on_message, |
|
| 2915 | - 'hide_off_message' => $hide_off_message, |
|
| 2916 | - 'messenger' => $messenger, |
|
| 2917 | - 'active' => $active |
|
| 2918 | - ); |
|
| 2919 | - } |
|
| 2920 | - } |
|
| 2921 | - |
|
| 2922 | - |
|
| 2923 | - //register messenger metaboxes |
|
| 2924 | - $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 2925 | - foreach ($m_boxes as $box => $label) { |
|
| 2926 | - $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]); |
|
| 2927 | - $msgr = str_replace('_a_box', '', $box); |
|
| 2928 | - add_meta_box( |
|
| 2929 | - 'espresso_' . $msgr . '_settings', |
|
| 2930 | - $label, |
|
| 2931 | - function ($post, $metabox) { |
|
| 2932 | - echo EEH_Template::display_template($metabox["args"]["template_path"], |
|
| 2933 | - $metabox["args"]["template_args"], true); |
|
| 2934 | - }, |
|
| 2935 | - $this->_current_screen->id, |
|
| 2936 | - 'normal', |
|
| 2937 | - 'high', |
|
| 2938 | - $callback_args |
|
| 2939 | - ); |
|
| 2940 | - } |
|
| 2941 | - |
|
| 2942 | - //register message type metaboxes |
|
| 2943 | - $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php'; |
|
| 2944 | - foreach ($mt_boxes as $box => $label) { |
|
| 2945 | - $callback_args = array( |
|
| 2946 | - 'template_path' => $mt_template_path, |
|
| 2947 | - 'template_args' => $mt_template_args[$box] |
|
| 2948 | - ); |
|
| 2949 | - $mt = str_replace('_i_box', '', $box); |
|
| 2950 | - add_meta_box( |
|
| 2951 | - 'espresso_' . $mt . '_inactive_mts', |
|
| 2952 | - $label, |
|
| 2953 | - function ($post, $metabox) { |
|
| 2954 | - echo EEH_Template::display_template($metabox["args"]["template_path"], |
|
| 2955 | - $metabox["args"]["template_args"], true); |
|
| 2956 | - }, |
|
| 2957 | - $this->_current_screen->id, |
|
| 2958 | - 'side', |
|
| 2959 | - 'high', |
|
| 2960 | - $callback_args |
|
| 2961 | - ); |
|
| 2962 | - } |
|
| 2963 | - |
|
| 2964 | - //register metabox for global messages settings but only when on the main site. On single site installs this will |
|
| 2965 | - //always result in the metabox showing, on multisite installs the metabox will only show on the main site. |
|
| 2966 | - if (is_main_site()) { |
|
| 2967 | - add_meta_box( |
|
| 2968 | - 'espresso_global_message_settings', |
|
| 2969 | - __('Global Message Settings', 'event_espresso'), |
|
| 2970 | - array($this, 'global_messages_settings_metabox_content'), |
|
| 2971 | - $this->_current_screen->id, |
|
| 2972 | - 'normal', |
|
| 2973 | - 'low', |
|
| 2974 | - array() |
|
| 2975 | - ); |
|
| 2976 | - } |
|
| 2977 | - |
|
| 2978 | - } |
|
| 2979 | - |
|
| 2980 | - |
|
| 2981 | - /** |
|
| 2982 | - * This generates the content for the global messages settings metabox. |
|
| 2983 | - * @return string |
|
| 2984 | - */ |
|
| 2985 | - public function global_messages_settings_metabox_content() |
|
| 2986 | - { |
|
| 2987 | - $form = $this->_generate_global_settings_form(); |
|
| 2988 | - echo $form->form_open( |
|
| 2989 | - $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL), |
|
| 2990 | - 'POST' |
|
| 2991 | - ) |
|
| 2992 | - . $form->get_html() |
|
| 2993 | - . $form->form_close(); |
|
| 2994 | - } |
|
| 2995 | - |
|
| 2996 | - |
|
| 2997 | - /** |
|
| 2998 | - * This generates and returns the form object for the global messages settings. |
|
| 2999 | - * @return EE_Form_Section_Proper |
|
| 3000 | - */ |
|
| 3001 | - protected function _generate_global_settings_form() |
|
| 3002 | - { |
|
| 3003 | - EE_Registry::instance()->load_helper('HTML'); |
|
| 3004 | - /** @var EE_Network_Core_Config $network_config */ |
|
| 3005 | - $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3006 | - |
|
| 3007 | - return new EE_Form_Section_Proper( |
|
| 3008 | - array( |
|
| 3009 | - 'name' => 'global_messages_settings', |
|
| 3010 | - 'html_id' => 'global_messages_settings', |
|
| 3011 | - 'html_class' => 'form-table', |
|
| 3012 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 3013 | - 'subsections' => apply_filters( |
|
| 3014 | - 'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections', |
|
| 3015 | - array( |
|
| 3016 | - 'do_messages_on_same_request' => new EE_Select_Input( |
|
| 3017 | - array( |
|
| 3018 | - true => esc_html__("On the same request", "event_espresso"), |
|
| 3019 | - false => esc_html__("On a separate request", "event_espresso") |
|
| 3020 | - ), |
|
| 3021 | - array( |
|
| 3022 | - 'default' => $network_config->do_messages_on_same_request, |
|
| 3023 | - 'html_label_text' => esc_html__('Generate and send all messages:', 'event_espresso'), |
|
| 3024 | - 'html_help_text' => esc_html__('By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system. This makes things execute faster for people registering for your events. However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.', |
|
| 3025 | - 'event_espresso'), |
|
| 3026 | - ) |
|
| 3027 | - ), |
|
| 3028 | - 'delete_threshold' => new EE_Select_Input( |
|
| 3029 | - array( |
|
| 3030 | - 0 => esc_html__('Forever', 'event_espresso'), |
|
| 3031 | - 3 => esc_html__('3 Months', 'event_espresso'), |
|
| 3032 | - 6 => esc_html__('6 Months', 'event_espresso'), |
|
| 3033 | - 9 => esc_html__('9 Months', 'event_espresso'), |
|
| 3034 | - 12 => esc_html__('12 Months', 'event_espresso'), |
|
| 3035 | - 24 => esc_html__('24 Months', 'event_espresso'), |
|
| 3036 | - 36 => esc_html__('36 Months', 'event_espresso') |
|
| 3037 | - ), |
|
| 3038 | - array( |
|
| 3039 | - 'default' => EE_Registry::instance()->CFG->messages->delete_threshold, |
|
| 3040 | - 'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'), |
|
| 3041 | - 'html_help_text' => esc_html__('You can control how long a record of processed messages is kept |
|
| 2833 | + $settings_template_args['template_form_fields'] = ! empty($template_form_field) ? $this->_generate_admin_form_fields($template_form_field, |
|
| 2834 | + 'string', 'ee_mt_activate_form') : ''; |
|
| 2835 | + } |
|
| 2836 | + |
|
| 2837 | + $settings_template_args['description'] = $message_type->description; |
|
| 2838 | + //we also need some hidden fields |
|
| 2839 | + $settings_template_args['hidden_fields'] = array( |
|
| 2840 | + 'message_type_settings[messenger]' => array( |
|
| 2841 | + 'type' => 'hidden', |
|
| 2842 | + 'value' => $messenger->name |
|
| 2843 | + ), |
|
| 2844 | + 'message_type_settings[message_type]' => array( |
|
| 2845 | + 'type' => 'hidden', |
|
| 2846 | + 'value' => $message_type->name |
|
| 2847 | + ), |
|
| 2848 | + 'type' => array( |
|
| 2849 | + 'type' => 'hidden', |
|
| 2850 | + 'value' => 'message_type' |
|
| 2851 | + ) |
|
| 2852 | + ); |
|
| 2853 | + |
|
| 2854 | + $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields($settings_template_args['hidden_fields'], |
|
| 2855 | + 'array'); |
|
| 2856 | + $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) ? ' hidden' : ''; |
|
| 2857 | + |
|
| 2858 | + |
|
| 2859 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php'; |
|
| 2860 | + $content = EEH_Template::display_template($template, $settings_template_args, true); |
|
| 2861 | + |
|
| 2862 | + return $content; |
|
| 2863 | + } |
|
| 2864 | + |
|
| 2865 | + |
|
| 2866 | + /** |
|
| 2867 | + * Generate all the metaboxes for the message types and register them for the messages settings page. |
|
| 2868 | + * |
|
| 2869 | + * @access protected |
|
| 2870 | + * @return void |
|
| 2871 | + */ |
|
| 2872 | + protected function _messages_settings_metaboxes() |
|
| 2873 | + { |
|
| 2874 | + $this->_set_m_mt_settings(); |
|
| 2875 | + $m_boxes = $mt_boxes = array(); |
|
| 2876 | + $m_template_args = $mt_template_args = array(); |
|
| 2877 | + |
|
| 2878 | + $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email'; |
|
| 2879 | + |
|
| 2880 | + if (isset($this->_m_mt_settings['messenger_tabs'])) { |
|
| 2881 | + foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) { |
|
| 2882 | + $hide_on_message = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden'; |
|
| 2883 | + $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : ''; |
|
| 2884 | + //messenger meta boxes |
|
| 2885 | + $active = $selected_messenger == $messenger ? true : false; |
|
| 2886 | + $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active']) |
|
| 2887 | + ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
|
| 2888 | + : ''; |
|
| 2889 | + $m_boxes[$messenger . '_a_box'] = sprintf( |
|
| 2890 | + __('%s Settings', 'event_espresso'), |
|
| 2891 | + $tab_array['label'] |
|
| 2892 | + ); |
|
| 2893 | + $m_template_args[$messenger . '_a_box'] = array( |
|
| 2894 | + 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 2895 | + 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2896 | + ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2897 | + : '', |
|
| 2898 | + 'content' => $this->_get_messenger_box_content($tab_array['obj']), |
|
| 2899 | + 'hidden' => $active ? '' : ' hidden', |
|
| 2900 | + 'hide_on_message' => $hide_on_message, |
|
| 2901 | + 'messenger' => $messenger, |
|
| 2902 | + 'active' => $active |
|
| 2903 | + ); |
|
| 2904 | + // message type meta boxes |
|
| 2905 | + // (which is really just the inactive container for each messenger |
|
| 2906 | + // showing inactive message types for that messenger) |
|
| 2907 | + $mt_boxes[$messenger . '_i_box'] = __('Inactive Message Types', 'event_espresso'); |
|
| 2908 | + $mt_template_args[$messenger . '_i_box'] = array( |
|
| 2909 | + 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 2910 | + 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2911 | + ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2912 | + : '', |
|
| 2913 | + 'hidden' => $active ? '' : ' hidden', |
|
| 2914 | + 'hide_on_message' => $hide_on_message, |
|
| 2915 | + 'hide_off_message' => $hide_off_message, |
|
| 2916 | + 'messenger' => $messenger, |
|
| 2917 | + 'active' => $active |
|
| 2918 | + ); |
|
| 2919 | + } |
|
| 2920 | + } |
|
| 2921 | + |
|
| 2922 | + |
|
| 2923 | + //register messenger metaboxes |
|
| 2924 | + $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 2925 | + foreach ($m_boxes as $box => $label) { |
|
| 2926 | + $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]); |
|
| 2927 | + $msgr = str_replace('_a_box', '', $box); |
|
| 2928 | + add_meta_box( |
|
| 2929 | + 'espresso_' . $msgr . '_settings', |
|
| 2930 | + $label, |
|
| 2931 | + function ($post, $metabox) { |
|
| 2932 | + echo EEH_Template::display_template($metabox["args"]["template_path"], |
|
| 2933 | + $metabox["args"]["template_args"], true); |
|
| 2934 | + }, |
|
| 2935 | + $this->_current_screen->id, |
|
| 2936 | + 'normal', |
|
| 2937 | + 'high', |
|
| 2938 | + $callback_args |
|
| 2939 | + ); |
|
| 2940 | + } |
|
| 2941 | + |
|
| 2942 | + //register message type metaboxes |
|
| 2943 | + $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php'; |
|
| 2944 | + foreach ($mt_boxes as $box => $label) { |
|
| 2945 | + $callback_args = array( |
|
| 2946 | + 'template_path' => $mt_template_path, |
|
| 2947 | + 'template_args' => $mt_template_args[$box] |
|
| 2948 | + ); |
|
| 2949 | + $mt = str_replace('_i_box', '', $box); |
|
| 2950 | + add_meta_box( |
|
| 2951 | + 'espresso_' . $mt . '_inactive_mts', |
|
| 2952 | + $label, |
|
| 2953 | + function ($post, $metabox) { |
|
| 2954 | + echo EEH_Template::display_template($metabox["args"]["template_path"], |
|
| 2955 | + $metabox["args"]["template_args"], true); |
|
| 2956 | + }, |
|
| 2957 | + $this->_current_screen->id, |
|
| 2958 | + 'side', |
|
| 2959 | + 'high', |
|
| 2960 | + $callback_args |
|
| 2961 | + ); |
|
| 2962 | + } |
|
| 2963 | + |
|
| 2964 | + //register metabox for global messages settings but only when on the main site. On single site installs this will |
|
| 2965 | + //always result in the metabox showing, on multisite installs the metabox will only show on the main site. |
|
| 2966 | + if (is_main_site()) { |
|
| 2967 | + add_meta_box( |
|
| 2968 | + 'espresso_global_message_settings', |
|
| 2969 | + __('Global Message Settings', 'event_espresso'), |
|
| 2970 | + array($this, 'global_messages_settings_metabox_content'), |
|
| 2971 | + $this->_current_screen->id, |
|
| 2972 | + 'normal', |
|
| 2973 | + 'low', |
|
| 2974 | + array() |
|
| 2975 | + ); |
|
| 2976 | + } |
|
| 2977 | + |
|
| 2978 | + } |
|
| 2979 | + |
|
| 2980 | + |
|
| 2981 | + /** |
|
| 2982 | + * This generates the content for the global messages settings metabox. |
|
| 2983 | + * @return string |
|
| 2984 | + */ |
|
| 2985 | + public function global_messages_settings_metabox_content() |
|
| 2986 | + { |
|
| 2987 | + $form = $this->_generate_global_settings_form(); |
|
| 2988 | + echo $form->form_open( |
|
| 2989 | + $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL), |
|
| 2990 | + 'POST' |
|
| 2991 | + ) |
|
| 2992 | + . $form->get_html() |
|
| 2993 | + . $form->form_close(); |
|
| 2994 | + } |
|
| 2995 | + |
|
| 2996 | + |
|
| 2997 | + /** |
|
| 2998 | + * This generates and returns the form object for the global messages settings. |
|
| 2999 | + * @return EE_Form_Section_Proper |
|
| 3000 | + */ |
|
| 3001 | + protected function _generate_global_settings_form() |
|
| 3002 | + { |
|
| 3003 | + EE_Registry::instance()->load_helper('HTML'); |
|
| 3004 | + /** @var EE_Network_Core_Config $network_config */ |
|
| 3005 | + $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3006 | + |
|
| 3007 | + return new EE_Form_Section_Proper( |
|
| 3008 | + array( |
|
| 3009 | + 'name' => 'global_messages_settings', |
|
| 3010 | + 'html_id' => 'global_messages_settings', |
|
| 3011 | + 'html_class' => 'form-table', |
|
| 3012 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 3013 | + 'subsections' => apply_filters( |
|
| 3014 | + 'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections', |
|
| 3015 | + array( |
|
| 3016 | + 'do_messages_on_same_request' => new EE_Select_Input( |
|
| 3017 | + array( |
|
| 3018 | + true => esc_html__("On the same request", "event_espresso"), |
|
| 3019 | + false => esc_html__("On a separate request", "event_espresso") |
|
| 3020 | + ), |
|
| 3021 | + array( |
|
| 3022 | + 'default' => $network_config->do_messages_on_same_request, |
|
| 3023 | + 'html_label_text' => esc_html__('Generate and send all messages:', 'event_espresso'), |
|
| 3024 | + 'html_help_text' => esc_html__('By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system. This makes things execute faster for people registering for your events. However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.', |
|
| 3025 | + 'event_espresso'), |
|
| 3026 | + ) |
|
| 3027 | + ), |
|
| 3028 | + 'delete_threshold' => new EE_Select_Input( |
|
| 3029 | + array( |
|
| 3030 | + 0 => esc_html__('Forever', 'event_espresso'), |
|
| 3031 | + 3 => esc_html__('3 Months', 'event_espresso'), |
|
| 3032 | + 6 => esc_html__('6 Months', 'event_espresso'), |
|
| 3033 | + 9 => esc_html__('9 Months', 'event_espresso'), |
|
| 3034 | + 12 => esc_html__('12 Months', 'event_espresso'), |
|
| 3035 | + 24 => esc_html__('24 Months', 'event_espresso'), |
|
| 3036 | + 36 => esc_html__('36 Months', 'event_espresso') |
|
| 3037 | + ), |
|
| 3038 | + array( |
|
| 3039 | + 'default' => EE_Registry::instance()->CFG->messages->delete_threshold, |
|
| 3040 | + 'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'), |
|
| 3041 | + 'html_help_text' => esc_html__('You can control how long a record of processed messages is kept |
|
| 3042 | 3042 | via this option.', 'event_espresso'), |
| 3043 | - ) |
|
| 3044 | - ), |
|
| 3045 | - 'update_settings' => new EE_Submit_Input( |
|
| 3046 | - array( |
|
| 3047 | - 'default' => esc_html__('Update', 'event_espresso'), |
|
| 3048 | - 'html_label_text' => ' ' |
|
| 3049 | - ) |
|
| 3050 | - ) |
|
| 3051 | - ) |
|
| 3052 | - ) |
|
| 3053 | - ) |
|
| 3054 | - ); |
|
| 3055 | - } |
|
| 3056 | - |
|
| 3057 | - |
|
| 3058 | - /** |
|
| 3059 | - * This handles updating the global settings set on the admin page. |
|
| 3060 | - * @throws \EE_Error |
|
| 3061 | - */ |
|
| 3062 | - protected function _update_global_settings() |
|
| 3063 | - { |
|
| 3064 | - /** @var EE_Network_Core_Config $network_config */ |
|
| 3065 | - $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3066 | - $messages_config = EE_Registry::instance()->CFG->messages; |
|
| 3067 | - $form = $this->_generate_global_settings_form(); |
|
| 3068 | - if ($form->was_submitted()) { |
|
| 3069 | - $form->receive_form_submission(); |
|
| 3070 | - if ($form->is_valid()) { |
|
| 3071 | - $valid_data = $form->valid_data(); |
|
| 3072 | - foreach ($valid_data as $property => $value) { |
|
| 3073 | - $setter = 'set_' . $property; |
|
| 3074 | - if (method_exists($network_config, $setter)) { |
|
| 3075 | - $network_config->{$setter}($value); |
|
| 3076 | - } else if ( |
|
| 3077 | - property_exists($network_config, $property) |
|
| 3078 | - && $network_config->{$property} !== $value |
|
| 3079 | - ) { |
|
| 3080 | - $network_config->{$property} = $value; |
|
| 3081 | - } else if ( |
|
| 3082 | - property_exists($messages_config, $property) |
|
| 3083 | - && $messages_config->{$property} !== $value |
|
| 3084 | - ) { |
|
| 3085 | - $messages_config->{$property} = $value; |
|
| 3086 | - } |
|
| 3087 | - } |
|
| 3088 | - //only update if the form submission was valid! |
|
| 3089 | - EE_Registry::instance()->NET_CFG->update_config(true, false); |
|
| 3090 | - EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 3091 | - EE_Error::overwrite_success(); |
|
| 3092 | - EE_Error::add_success(__('Global message settings were updated', 'event_espresso')); |
|
| 3093 | - } |
|
| 3094 | - } |
|
| 3095 | - $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true); |
|
| 3096 | - } |
|
| 3097 | - |
|
| 3098 | - |
|
| 3099 | - /** |
|
| 3100 | - * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate |
|
| 3101 | - * |
|
| 3102 | - * @param array $tab_array This is an array of message type tab details used to generate the tabs |
|
| 3103 | - * |
|
| 3104 | - * @return string html formatted tabs |
|
| 3105 | - */ |
|
| 3106 | - protected function _get_mt_tabs($tab_array) |
|
| 3107 | - { |
|
| 3108 | - $tab_array = (array)$tab_array; |
|
| 3109 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3110 | - $tabs = ''; |
|
| 3111 | - |
|
| 3112 | - foreach ($tab_array as $tab) { |
|
| 3113 | - $tabs .= EEH_Template::display_template($template, $tab, true); |
|
| 3114 | - } |
|
| 3115 | - |
|
| 3116 | - return $tabs; |
|
| 3117 | - } |
|
| 3118 | - |
|
| 3119 | - |
|
| 3120 | - /** |
|
| 3121 | - * This prepares the content of the messenger meta box admin settings |
|
| 3122 | - * |
|
| 3123 | - * @param EE_messenger $messenger The messenger we're setting up content for |
|
| 3124 | - * |
|
| 3125 | - * @return string html formatted content |
|
| 3126 | - */ |
|
| 3127 | - protected function _get_messenger_box_content(EE_messenger $messenger) |
|
| 3128 | - { |
|
| 3129 | - |
|
| 3130 | - $fields = $messenger->get_admin_settings_fields(); |
|
| 3131 | - $settings_template_args['template_form_fields'] = ''; |
|
| 3132 | - |
|
| 3133 | - //is $messenger active? |
|
| 3134 | - $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3135 | - |
|
| 3136 | - |
|
| 3137 | - if ( ! empty($fields)) { |
|
| 3043 | + ) |
|
| 3044 | + ), |
|
| 3045 | + 'update_settings' => new EE_Submit_Input( |
|
| 3046 | + array( |
|
| 3047 | + 'default' => esc_html__('Update', 'event_espresso'), |
|
| 3048 | + 'html_label_text' => ' ' |
|
| 3049 | + ) |
|
| 3050 | + ) |
|
| 3051 | + ) |
|
| 3052 | + ) |
|
| 3053 | + ) |
|
| 3054 | + ); |
|
| 3055 | + } |
|
| 3056 | + |
|
| 3057 | + |
|
| 3058 | + /** |
|
| 3059 | + * This handles updating the global settings set on the admin page. |
|
| 3060 | + * @throws \EE_Error |
|
| 3061 | + */ |
|
| 3062 | + protected function _update_global_settings() |
|
| 3063 | + { |
|
| 3064 | + /** @var EE_Network_Core_Config $network_config */ |
|
| 3065 | + $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3066 | + $messages_config = EE_Registry::instance()->CFG->messages; |
|
| 3067 | + $form = $this->_generate_global_settings_form(); |
|
| 3068 | + if ($form->was_submitted()) { |
|
| 3069 | + $form->receive_form_submission(); |
|
| 3070 | + if ($form->is_valid()) { |
|
| 3071 | + $valid_data = $form->valid_data(); |
|
| 3072 | + foreach ($valid_data as $property => $value) { |
|
| 3073 | + $setter = 'set_' . $property; |
|
| 3074 | + if (method_exists($network_config, $setter)) { |
|
| 3075 | + $network_config->{$setter}($value); |
|
| 3076 | + } else if ( |
|
| 3077 | + property_exists($network_config, $property) |
|
| 3078 | + && $network_config->{$property} !== $value |
|
| 3079 | + ) { |
|
| 3080 | + $network_config->{$property} = $value; |
|
| 3081 | + } else if ( |
|
| 3082 | + property_exists($messages_config, $property) |
|
| 3083 | + && $messages_config->{$property} !== $value |
|
| 3084 | + ) { |
|
| 3085 | + $messages_config->{$property} = $value; |
|
| 3086 | + } |
|
| 3087 | + } |
|
| 3088 | + //only update if the form submission was valid! |
|
| 3089 | + EE_Registry::instance()->NET_CFG->update_config(true, false); |
|
| 3090 | + EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 3091 | + EE_Error::overwrite_success(); |
|
| 3092 | + EE_Error::add_success(__('Global message settings were updated', 'event_espresso')); |
|
| 3093 | + } |
|
| 3094 | + } |
|
| 3095 | + $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true); |
|
| 3096 | + } |
|
| 3097 | + |
|
| 3098 | + |
|
| 3099 | + /** |
|
| 3100 | + * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate |
|
| 3101 | + * |
|
| 3102 | + * @param array $tab_array This is an array of message type tab details used to generate the tabs |
|
| 3103 | + * |
|
| 3104 | + * @return string html formatted tabs |
|
| 3105 | + */ |
|
| 3106 | + protected function _get_mt_tabs($tab_array) |
|
| 3107 | + { |
|
| 3108 | + $tab_array = (array)$tab_array; |
|
| 3109 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3110 | + $tabs = ''; |
|
| 3111 | + |
|
| 3112 | + foreach ($tab_array as $tab) { |
|
| 3113 | + $tabs .= EEH_Template::display_template($template, $tab, true); |
|
| 3114 | + } |
|
| 3115 | + |
|
| 3116 | + return $tabs; |
|
| 3117 | + } |
|
| 3118 | + |
|
| 3119 | + |
|
| 3120 | + /** |
|
| 3121 | + * This prepares the content of the messenger meta box admin settings |
|
| 3122 | + * |
|
| 3123 | + * @param EE_messenger $messenger The messenger we're setting up content for |
|
| 3124 | + * |
|
| 3125 | + * @return string html formatted content |
|
| 3126 | + */ |
|
| 3127 | + protected function _get_messenger_box_content(EE_messenger $messenger) |
|
| 3128 | + { |
|
| 3129 | + |
|
| 3130 | + $fields = $messenger->get_admin_settings_fields(); |
|
| 3131 | + $settings_template_args['template_form_fields'] = ''; |
|
| 3132 | + |
|
| 3133 | + //is $messenger active? |
|
| 3134 | + $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3135 | + |
|
| 3136 | + |
|
| 3137 | + if ( ! empty($fields)) { |
|
| 3138 | 3138 | |
| 3139 | - $existing_settings = $messenger->get_existing_admin_settings(); |
|
| 3139 | + $existing_settings = $messenger->get_existing_admin_settings(); |
|
| 3140 | 3140 | |
| 3141 | - foreach ($fields as $fldname => $fldprops) { |
|
| 3142 | - $field_id = $messenger->name . '-' . $fldname; |
|
| 3143 | - $template_form_field[$field_id] = array( |
|
| 3144 | - 'name' => 'messenger_settings[' . $field_id . ']', |
|
| 3145 | - 'label' => $fldprops['label'], |
|
| 3146 | - 'input' => $fldprops['field_type'], |
|
| 3147 | - 'type' => $fldprops['value_type'], |
|
| 3148 | - 'required' => $fldprops['required'], |
|
| 3149 | - 'validation' => $fldprops['validation'], |
|
| 3150 | - 'value' => isset($existing_settings[$field_id]) |
|
| 3151 | - ? $existing_settings[$field_id] |
|
| 3152 | - : $fldprops['default'], |
|
| 3153 | - 'css_class' => '', |
|
| 3154 | - 'format' => $fldprops['format'] |
|
| 3155 | - ); |
|
| 3156 | - } |
|
| 3141 | + foreach ($fields as $fldname => $fldprops) { |
|
| 3142 | + $field_id = $messenger->name . '-' . $fldname; |
|
| 3143 | + $template_form_field[$field_id] = array( |
|
| 3144 | + 'name' => 'messenger_settings[' . $field_id . ']', |
|
| 3145 | + 'label' => $fldprops['label'], |
|
| 3146 | + 'input' => $fldprops['field_type'], |
|
| 3147 | + 'type' => $fldprops['value_type'], |
|
| 3148 | + 'required' => $fldprops['required'], |
|
| 3149 | + 'validation' => $fldprops['validation'], |
|
| 3150 | + 'value' => isset($existing_settings[$field_id]) |
|
| 3151 | + ? $existing_settings[$field_id] |
|
| 3152 | + : $fldprops['default'], |
|
| 3153 | + 'css_class' => '', |
|
| 3154 | + 'format' => $fldprops['format'] |
|
| 3155 | + ); |
|
| 3156 | + } |
|
| 3157 | 3157 | |
| 3158 | 3158 | |
| 3159 | - $settings_template_args['template_form_fields'] = ! empty($template_form_field) |
|
| 3160 | - ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form') |
|
| 3161 | - : ''; |
|
| 3162 | - } |
|
| 3163 | - |
|
| 3164 | - //we also need some hidden fields |
|
| 3165 | - $settings_template_args['hidden_fields'] = array( |
|
| 3166 | - 'messenger_settings[messenger]' => array( |
|
| 3167 | - 'type' => 'hidden', |
|
| 3168 | - 'value' => $messenger->name |
|
| 3169 | - ), |
|
| 3170 | - 'type' => array( |
|
| 3171 | - 'type' => 'hidden', |
|
| 3172 | - 'value' => 'messenger' |
|
| 3173 | - ) |
|
| 3174 | - ); |
|
| 3175 | - |
|
| 3176 | - //make sure any active message types that are existing are included in the hidden fields |
|
| 3177 | - if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) { |
|
| 3178 | - foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) { |
|
| 3179 | - $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array( |
|
| 3180 | - 'type' => 'hidden', |
|
| 3181 | - 'value' => $mt |
|
| 3182 | - ); |
|
| 3183 | - } |
|
| 3184 | - } |
|
| 3185 | - $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( |
|
| 3186 | - $settings_template_args['hidden_fields'], |
|
| 3187 | - 'array' |
|
| 3188 | - ); |
|
| 3189 | - $active = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3190 | - |
|
| 3191 | - $settings_template_args['messenger'] = $messenger->name; |
|
| 3192 | - $settings_template_args['description'] = $messenger->description; |
|
| 3193 | - $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden'; |
|
| 3194 | - |
|
| 3195 | - |
|
| 3196 | - $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active($messenger->name) |
|
| 3197 | - ? $settings_template_args['show_hide_edit_form'] |
|
| 3198 | - : ' hidden'; |
|
| 3199 | - |
|
| 3200 | - $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3201 | - ? ' hidden' |
|
| 3202 | - : $settings_template_args['show_hide_edit_form']; |
|
| 3203 | - |
|
| 3204 | - |
|
| 3205 | - $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on'; |
|
| 3206 | - $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); |
|
| 3207 | - $settings_template_args['on_off_status'] = $active ? true : false; |
|
| 3208 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php'; |
|
| 3209 | - $content = EEH_Template::display_template($template, $settings_template_args, |
|
| 3210 | - true); |
|
| 3211 | - |
|
| 3212 | - return $content; |
|
| 3213 | - } |
|
| 3214 | - |
|
| 3215 | - |
|
| 3216 | - /** |
|
| 3217 | - * used by ajax on the messages settings page to activate|deactivate the messenger |
|
| 3218 | - */ |
|
| 3219 | - public function activate_messenger_toggle() |
|
| 3220 | - { |
|
| 3221 | - $success = true; |
|
| 3222 | - $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3223 | - //let's check that we have required data |
|
| 3224 | - if ( ! isset($this->_req_data['messenger'])) { |
|
| 3225 | - EE_Error::add_error( |
|
| 3226 | - __('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3227 | - __FILE__, |
|
| 3228 | - __FUNCTION__, |
|
| 3229 | - __LINE__ |
|
| 3230 | - ); |
|
| 3231 | - $success = false; |
|
| 3232 | - } |
|
| 3233 | - |
|
| 3234 | - //do a nonce check here since we're not arriving via a normal route |
|
| 3235 | - $nonce = isset($this->_req_data['activate_nonce']) ? sanitize_text_field($this->_req_data['activate_nonce']) : ''; |
|
| 3236 | - $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce'; |
|
| 3237 | - |
|
| 3238 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3239 | - |
|
| 3240 | - |
|
| 3241 | - if ( ! isset($this->_req_data['status'])) { |
|
| 3242 | - EE_Error::add_error( |
|
| 3243 | - __( |
|
| 3244 | - 'Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3245 | - 'event_espresso' |
|
| 3246 | - ), |
|
| 3247 | - __FILE__, |
|
| 3248 | - __FUNCTION__, |
|
| 3249 | - __LINE__ |
|
| 3250 | - ); |
|
| 3251 | - $success = false; |
|
| 3252 | - } |
|
| 3253 | - |
|
| 3254 | - //do check to verify we have a valid status. |
|
| 3255 | - $status = $this->_req_data['status']; |
|
| 3256 | - |
|
| 3257 | - if ($status != 'off' && $status != 'on') { |
|
| 3258 | - EE_Error::add_error( |
|
| 3259 | - sprintf( |
|
| 3260 | - __('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
|
| 3261 | - $this->_req_data['status'] |
|
| 3262 | - ), |
|
| 3263 | - __FILE__, |
|
| 3264 | - __FUNCTION__, |
|
| 3265 | - __LINE__ |
|
| 3266 | - ); |
|
| 3267 | - $success = false; |
|
| 3268 | - } |
|
| 3269 | - |
|
| 3270 | - if ($success) { |
|
| 3271 | - //made it here? Stop dawdling then!! |
|
| 3272 | - $success = $status == 'off' |
|
| 3273 | - ? $this->_deactivate_messenger($this->_req_data['messenger']) |
|
| 3274 | - : $this->_activate_messenger($this->_req_data['messenger']); |
|
| 3275 | - } |
|
| 3276 | - |
|
| 3277 | - $this->_template_args['success'] = $success; |
|
| 3278 | - |
|
| 3279 | - //no special instructions so let's just do the json return (which should automatically do all the special stuff). |
|
| 3280 | - $this->_return_json(); |
|
| 3281 | - |
|
| 3282 | - } |
|
| 3283 | - |
|
| 3284 | - |
|
| 3285 | - /** |
|
| 3286 | - * used by ajax from the messages settings page to activate|deactivate a message type |
|
| 3287 | - * |
|
| 3288 | - */ |
|
| 3289 | - public function activate_mt_toggle() |
|
| 3290 | - { |
|
| 3291 | - $success = true; |
|
| 3292 | - $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3293 | - |
|
| 3294 | - //let's make sure we have the necessary data |
|
| 3295 | - if ( ! isset($this->_req_data['message_type'])) { |
|
| 3296 | - EE_Error::add_error( |
|
| 3297 | - __('Message Type name needed to toggle activation. None given', 'event_espresso'), |
|
| 3298 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 3299 | - ); |
|
| 3300 | - $success = false; |
|
| 3301 | - } |
|
| 3302 | - |
|
| 3303 | - if ( ! isset($this->_req_data['messenger'])) { |
|
| 3304 | - EE_Error::add_error( |
|
| 3305 | - __('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3306 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 3307 | - ); |
|
| 3308 | - $success = false; |
|
| 3309 | - } |
|
| 3310 | - |
|
| 3311 | - if ( ! isset($this->_req_data['status'])) { |
|
| 3312 | - EE_Error::add_error( |
|
| 3313 | - __('Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3314 | - 'event_espresso'), |
|
| 3315 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 3316 | - ); |
|
| 3317 | - $success = false; |
|
| 3318 | - } |
|
| 3319 | - |
|
| 3320 | - |
|
| 3321 | - //do check to verify we have a valid status. |
|
| 3322 | - $status = $this->_req_data['status']; |
|
| 3323 | - |
|
| 3324 | - if ($status != 'activate' && $status != 'deactivate') { |
|
| 3325 | - EE_Error::add_error( |
|
| 3326 | - sprintf( |
|
| 3327 | - __('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'), |
|
| 3328 | - $this->_req_data['status'] |
|
| 3329 | - ), |
|
| 3330 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 3331 | - ); |
|
| 3332 | - $success = false; |
|
| 3333 | - } |
|
| 3334 | - |
|
| 3335 | - |
|
| 3336 | - //do a nonce check here since we're not arriving via a normal route |
|
| 3337 | - $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : ''; |
|
| 3338 | - $nonce_ref = $this->_req_data['message_type'] . '_nonce'; |
|
| 3339 | - |
|
| 3340 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3341 | - |
|
| 3342 | - if ($success) { |
|
| 3343 | - //made it here? um, what are you waiting for then? |
|
| 3344 | - $success = $status == 'deactivate' |
|
| 3345 | - ? $this->_deactivate_message_type_for_messenger($this->_req_data['messenger'], |
|
| 3346 | - $this->_req_data['message_type']) |
|
| 3347 | - : $this->_activate_message_type_for_messenger($this->_req_data['messenger'], |
|
| 3348 | - $this->_req_data['message_type']); |
|
| 3349 | - } |
|
| 3350 | - |
|
| 3351 | - $this->_template_args['success'] = $success; |
|
| 3352 | - $this->_return_json(); |
|
| 3353 | - } |
|
| 3354 | - |
|
| 3355 | - |
|
| 3356 | - /** |
|
| 3357 | - * Takes care of processing activating a messenger and preparing the appropriate response. |
|
| 3358 | - * |
|
| 3359 | - * @param string $messenger_name The name of the messenger being activated |
|
| 3360 | - * |
|
| 3361 | - * @return bool |
|
| 3362 | - */ |
|
| 3363 | - protected function _activate_messenger($messenger_name) |
|
| 3364 | - { |
|
| 3365 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3366 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3367 | - $message_types_to_activate = $active_messenger instanceof EE_Messenger ? $active_messenger->get_default_message_types() : array(); |
|
| 3368 | - |
|
| 3369 | - //ensure is active |
|
| 3370 | - $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate); |
|
| 3371 | - |
|
| 3372 | - //set response_data for reload |
|
| 3373 | - foreach ($message_types_to_activate as $message_type_name) { |
|
| 3374 | - /** @var EE_message_type $message_type */ |
|
| 3375 | - $message_type = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3376 | - if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name, |
|
| 3377 | - $message_type_name) |
|
| 3378 | - && $message_type instanceof EE_message_type |
|
| 3379 | - ) { |
|
| 3380 | - $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3381 | - if ($message_type->get_admin_settings_fields()) { |
|
| 3382 | - $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3383 | - } |
|
| 3384 | - } |
|
| 3385 | - } |
|
| 3386 | - |
|
| 3387 | - //add success message for activating messenger |
|
| 3388 | - return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger); |
|
| 3389 | - |
|
| 3390 | - } |
|
| 3391 | - |
|
| 3392 | - |
|
| 3393 | - /** |
|
| 3394 | - * Takes care of processing deactivating a messenger and preparing the appropriate response. |
|
| 3395 | - * |
|
| 3396 | - * @param string $messenger_name The name of the messenger being activated |
|
| 3397 | - * |
|
| 3398 | - * @return bool |
|
| 3399 | - */ |
|
| 3400 | - protected function _deactivate_messenger($messenger_name) |
|
| 3401 | - { |
|
| 3402 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3403 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3404 | - $this->_message_resource_manager->deactivate_messenger($messenger_name); |
|
| 3405 | - |
|
| 3406 | - return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger); |
|
| 3407 | - } |
|
| 3408 | - |
|
| 3409 | - |
|
| 3410 | - /** |
|
| 3411 | - * Takes care of processing activating a message type for a messenger and preparing the appropriate response. |
|
| 3412 | - * |
|
| 3413 | - * @param string $messenger_name The name of the messenger the message type is being activated for. |
|
| 3414 | - * @param string $message_type_name The name of the message type being activated for the messenger |
|
| 3415 | - * |
|
| 3416 | - * @return bool |
|
| 3417 | - */ |
|
| 3418 | - protected function _activate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 3419 | - { |
|
| 3420 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3421 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3422 | - /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 3423 | - $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3424 | - |
|
| 3425 | - //ensure is active |
|
| 3426 | - $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name); |
|
| 3427 | - |
|
| 3428 | - //set response for load |
|
| 3429 | - if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name, |
|
| 3430 | - $message_type_name) |
|
| 3431 | - ) { |
|
| 3432 | - $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3433 | - if ($message_type_to_activate->get_admin_settings_fields()) { |
|
| 3434 | - $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3435 | - } |
|
| 3436 | - } |
|
| 3437 | - |
|
| 3438 | - return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger, |
|
| 3439 | - $message_type_to_activate); |
|
| 3440 | - } |
|
| 3441 | - |
|
| 3442 | - |
|
| 3443 | - /** |
|
| 3444 | - * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response. |
|
| 3445 | - * |
|
| 3446 | - * @param string $messenger_name The name of the messenger the message type is being deactivated for. |
|
| 3447 | - * @param string $message_type_name The name of the message type being deactivated for the messenger |
|
| 3448 | - * |
|
| 3449 | - * @return bool |
|
| 3450 | - */ |
|
| 3451 | - protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 3452 | - { |
|
| 3453 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3454 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3455 | - /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 3456 | - $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3457 | - $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name); |
|
| 3458 | - |
|
| 3459 | - return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger, |
|
| 3460 | - $message_type_to_deactivate); |
|
| 3461 | - } |
|
| 3462 | - |
|
| 3463 | - |
|
| 3464 | - /** |
|
| 3465 | - * This just initializes the defaults for activating messenger and message type responses. |
|
| 3466 | - */ |
|
| 3467 | - protected function _prep_default_response_for_messenger_or_message_type_toggle() |
|
| 3468 | - { |
|
| 3469 | - $this->_template_args['data']['active_mts'] = array(); |
|
| 3470 | - $this->_template_args['data']['mt_reload'] = array(); |
|
| 3471 | - } |
|
| 3472 | - |
|
| 3473 | - |
|
| 3474 | - /** |
|
| 3475 | - * Setup appropriate response for activating a messenger and/or message types |
|
| 3476 | - * |
|
| 3477 | - * @param EE_messenger $messenger |
|
| 3478 | - * @param EE_message_type|null $message_type |
|
| 3479 | - * |
|
| 3480 | - * @return bool |
|
| 3481 | - * @throws EE_Error |
|
| 3482 | - */ |
|
| 3483 | - protected function _setup_response_message_for_activating_messenger_with_message_types( |
|
| 3484 | - $messenger, |
|
| 3485 | - EE_Message_Type $message_type = null |
|
| 3486 | - ) { |
|
| 3487 | - //if $messenger isn't a valid messenger object then get out. |
|
| 3488 | - if ( ! $messenger instanceof EE_Messenger) { |
|
| 3489 | - EE_Error::add_error( |
|
| 3490 | - __('The messenger being activated is not a valid messenger', 'event_espresso'), |
|
| 3491 | - __FILE__, |
|
| 3492 | - __FUNCTION__, |
|
| 3493 | - __LINE__ |
|
| 3494 | - ); |
|
| 3159 | + $settings_template_args['template_form_fields'] = ! empty($template_form_field) |
|
| 3160 | + ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form') |
|
| 3161 | + : ''; |
|
| 3162 | + } |
|
| 3163 | + |
|
| 3164 | + //we also need some hidden fields |
|
| 3165 | + $settings_template_args['hidden_fields'] = array( |
|
| 3166 | + 'messenger_settings[messenger]' => array( |
|
| 3167 | + 'type' => 'hidden', |
|
| 3168 | + 'value' => $messenger->name |
|
| 3169 | + ), |
|
| 3170 | + 'type' => array( |
|
| 3171 | + 'type' => 'hidden', |
|
| 3172 | + 'value' => 'messenger' |
|
| 3173 | + ) |
|
| 3174 | + ); |
|
| 3175 | + |
|
| 3176 | + //make sure any active message types that are existing are included in the hidden fields |
|
| 3177 | + if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) { |
|
| 3178 | + foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) { |
|
| 3179 | + $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array( |
|
| 3180 | + 'type' => 'hidden', |
|
| 3181 | + 'value' => $mt |
|
| 3182 | + ); |
|
| 3183 | + } |
|
| 3184 | + } |
|
| 3185 | + $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( |
|
| 3186 | + $settings_template_args['hidden_fields'], |
|
| 3187 | + 'array' |
|
| 3188 | + ); |
|
| 3189 | + $active = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3190 | + |
|
| 3191 | + $settings_template_args['messenger'] = $messenger->name; |
|
| 3192 | + $settings_template_args['description'] = $messenger->description; |
|
| 3193 | + $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden'; |
|
| 3194 | + |
|
| 3195 | + |
|
| 3196 | + $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active($messenger->name) |
|
| 3197 | + ? $settings_template_args['show_hide_edit_form'] |
|
| 3198 | + : ' hidden'; |
|
| 3199 | + |
|
| 3200 | + $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3201 | + ? ' hidden' |
|
| 3202 | + : $settings_template_args['show_hide_edit_form']; |
|
| 3203 | + |
|
| 3204 | + |
|
| 3205 | + $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on'; |
|
| 3206 | + $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); |
|
| 3207 | + $settings_template_args['on_off_status'] = $active ? true : false; |
|
| 3208 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php'; |
|
| 3209 | + $content = EEH_Template::display_template($template, $settings_template_args, |
|
| 3210 | + true); |
|
| 3211 | + |
|
| 3212 | + return $content; |
|
| 3213 | + } |
|
| 3214 | + |
|
| 3215 | + |
|
| 3216 | + /** |
|
| 3217 | + * used by ajax on the messages settings page to activate|deactivate the messenger |
|
| 3218 | + */ |
|
| 3219 | + public function activate_messenger_toggle() |
|
| 3220 | + { |
|
| 3221 | + $success = true; |
|
| 3222 | + $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3223 | + //let's check that we have required data |
|
| 3224 | + if ( ! isset($this->_req_data['messenger'])) { |
|
| 3225 | + EE_Error::add_error( |
|
| 3226 | + __('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3227 | + __FILE__, |
|
| 3228 | + __FUNCTION__, |
|
| 3229 | + __LINE__ |
|
| 3230 | + ); |
|
| 3231 | + $success = false; |
|
| 3232 | + } |
|
| 3233 | + |
|
| 3234 | + //do a nonce check here since we're not arriving via a normal route |
|
| 3235 | + $nonce = isset($this->_req_data['activate_nonce']) ? sanitize_text_field($this->_req_data['activate_nonce']) : ''; |
|
| 3236 | + $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce'; |
|
| 3237 | + |
|
| 3238 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3239 | + |
|
| 3240 | + |
|
| 3241 | + if ( ! isset($this->_req_data['status'])) { |
|
| 3242 | + EE_Error::add_error( |
|
| 3243 | + __( |
|
| 3244 | + 'Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3245 | + 'event_espresso' |
|
| 3246 | + ), |
|
| 3247 | + __FILE__, |
|
| 3248 | + __FUNCTION__, |
|
| 3249 | + __LINE__ |
|
| 3250 | + ); |
|
| 3251 | + $success = false; |
|
| 3252 | + } |
|
| 3253 | + |
|
| 3254 | + //do check to verify we have a valid status. |
|
| 3255 | + $status = $this->_req_data['status']; |
|
| 3256 | + |
|
| 3257 | + if ($status != 'off' && $status != 'on') { |
|
| 3258 | + EE_Error::add_error( |
|
| 3259 | + sprintf( |
|
| 3260 | + __('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
|
| 3261 | + $this->_req_data['status'] |
|
| 3262 | + ), |
|
| 3263 | + __FILE__, |
|
| 3264 | + __FUNCTION__, |
|
| 3265 | + __LINE__ |
|
| 3266 | + ); |
|
| 3267 | + $success = false; |
|
| 3268 | + } |
|
| 3269 | + |
|
| 3270 | + if ($success) { |
|
| 3271 | + //made it here? Stop dawdling then!! |
|
| 3272 | + $success = $status == 'off' |
|
| 3273 | + ? $this->_deactivate_messenger($this->_req_data['messenger']) |
|
| 3274 | + : $this->_activate_messenger($this->_req_data['messenger']); |
|
| 3275 | + } |
|
| 3276 | + |
|
| 3277 | + $this->_template_args['success'] = $success; |
|
| 3278 | + |
|
| 3279 | + //no special instructions so let's just do the json return (which should automatically do all the special stuff). |
|
| 3280 | + $this->_return_json(); |
|
| 3281 | + |
|
| 3282 | + } |
|
| 3283 | + |
|
| 3284 | + |
|
| 3285 | + /** |
|
| 3286 | + * used by ajax from the messages settings page to activate|deactivate a message type |
|
| 3287 | + * |
|
| 3288 | + */ |
|
| 3289 | + public function activate_mt_toggle() |
|
| 3290 | + { |
|
| 3291 | + $success = true; |
|
| 3292 | + $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3293 | + |
|
| 3294 | + //let's make sure we have the necessary data |
|
| 3295 | + if ( ! isset($this->_req_data['message_type'])) { |
|
| 3296 | + EE_Error::add_error( |
|
| 3297 | + __('Message Type name needed to toggle activation. None given', 'event_espresso'), |
|
| 3298 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 3299 | + ); |
|
| 3300 | + $success = false; |
|
| 3301 | + } |
|
| 3302 | + |
|
| 3303 | + if ( ! isset($this->_req_data['messenger'])) { |
|
| 3304 | + EE_Error::add_error( |
|
| 3305 | + __('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3306 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 3307 | + ); |
|
| 3308 | + $success = false; |
|
| 3309 | + } |
|
| 3310 | + |
|
| 3311 | + if ( ! isset($this->_req_data['status'])) { |
|
| 3312 | + EE_Error::add_error( |
|
| 3313 | + __('Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3314 | + 'event_espresso'), |
|
| 3315 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 3316 | + ); |
|
| 3317 | + $success = false; |
|
| 3318 | + } |
|
| 3319 | + |
|
| 3320 | + |
|
| 3321 | + //do check to verify we have a valid status. |
|
| 3322 | + $status = $this->_req_data['status']; |
|
| 3323 | + |
|
| 3324 | + if ($status != 'activate' && $status != 'deactivate') { |
|
| 3325 | + EE_Error::add_error( |
|
| 3326 | + sprintf( |
|
| 3327 | + __('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'), |
|
| 3328 | + $this->_req_data['status'] |
|
| 3329 | + ), |
|
| 3330 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 3331 | + ); |
|
| 3332 | + $success = false; |
|
| 3333 | + } |
|
| 3334 | + |
|
| 3335 | + |
|
| 3336 | + //do a nonce check here since we're not arriving via a normal route |
|
| 3337 | + $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : ''; |
|
| 3338 | + $nonce_ref = $this->_req_data['message_type'] . '_nonce'; |
|
| 3339 | + |
|
| 3340 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3341 | + |
|
| 3342 | + if ($success) { |
|
| 3343 | + //made it here? um, what are you waiting for then? |
|
| 3344 | + $success = $status == 'deactivate' |
|
| 3345 | + ? $this->_deactivate_message_type_for_messenger($this->_req_data['messenger'], |
|
| 3346 | + $this->_req_data['message_type']) |
|
| 3347 | + : $this->_activate_message_type_for_messenger($this->_req_data['messenger'], |
|
| 3348 | + $this->_req_data['message_type']); |
|
| 3349 | + } |
|
| 3350 | + |
|
| 3351 | + $this->_template_args['success'] = $success; |
|
| 3352 | + $this->_return_json(); |
|
| 3353 | + } |
|
| 3354 | + |
|
| 3355 | + |
|
| 3356 | + /** |
|
| 3357 | + * Takes care of processing activating a messenger and preparing the appropriate response. |
|
| 3358 | + * |
|
| 3359 | + * @param string $messenger_name The name of the messenger being activated |
|
| 3360 | + * |
|
| 3361 | + * @return bool |
|
| 3362 | + */ |
|
| 3363 | + protected function _activate_messenger($messenger_name) |
|
| 3364 | + { |
|
| 3365 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3366 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3367 | + $message_types_to_activate = $active_messenger instanceof EE_Messenger ? $active_messenger->get_default_message_types() : array(); |
|
| 3368 | + |
|
| 3369 | + //ensure is active |
|
| 3370 | + $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate); |
|
| 3371 | + |
|
| 3372 | + //set response_data for reload |
|
| 3373 | + foreach ($message_types_to_activate as $message_type_name) { |
|
| 3374 | + /** @var EE_message_type $message_type */ |
|
| 3375 | + $message_type = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3376 | + if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name, |
|
| 3377 | + $message_type_name) |
|
| 3378 | + && $message_type instanceof EE_message_type |
|
| 3379 | + ) { |
|
| 3380 | + $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3381 | + if ($message_type->get_admin_settings_fields()) { |
|
| 3382 | + $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3383 | + } |
|
| 3384 | + } |
|
| 3385 | + } |
|
| 3386 | + |
|
| 3387 | + //add success message for activating messenger |
|
| 3388 | + return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger); |
|
| 3389 | + |
|
| 3390 | + } |
|
| 3391 | + |
|
| 3392 | + |
|
| 3393 | + /** |
|
| 3394 | + * Takes care of processing deactivating a messenger and preparing the appropriate response. |
|
| 3395 | + * |
|
| 3396 | + * @param string $messenger_name The name of the messenger being activated |
|
| 3397 | + * |
|
| 3398 | + * @return bool |
|
| 3399 | + */ |
|
| 3400 | + protected function _deactivate_messenger($messenger_name) |
|
| 3401 | + { |
|
| 3402 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3403 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3404 | + $this->_message_resource_manager->deactivate_messenger($messenger_name); |
|
| 3405 | + |
|
| 3406 | + return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger); |
|
| 3407 | + } |
|
| 3408 | + |
|
| 3409 | + |
|
| 3410 | + /** |
|
| 3411 | + * Takes care of processing activating a message type for a messenger and preparing the appropriate response. |
|
| 3412 | + * |
|
| 3413 | + * @param string $messenger_name The name of the messenger the message type is being activated for. |
|
| 3414 | + * @param string $message_type_name The name of the message type being activated for the messenger |
|
| 3415 | + * |
|
| 3416 | + * @return bool |
|
| 3417 | + */ |
|
| 3418 | + protected function _activate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 3419 | + { |
|
| 3420 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3421 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3422 | + /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 3423 | + $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3424 | + |
|
| 3425 | + //ensure is active |
|
| 3426 | + $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name); |
|
| 3427 | + |
|
| 3428 | + //set response for load |
|
| 3429 | + if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name, |
|
| 3430 | + $message_type_name) |
|
| 3431 | + ) { |
|
| 3432 | + $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3433 | + if ($message_type_to_activate->get_admin_settings_fields()) { |
|
| 3434 | + $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3435 | + } |
|
| 3436 | + } |
|
| 3437 | + |
|
| 3438 | + return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger, |
|
| 3439 | + $message_type_to_activate); |
|
| 3440 | + } |
|
| 3441 | + |
|
| 3442 | + |
|
| 3443 | + /** |
|
| 3444 | + * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response. |
|
| 3445 | + * |
|
| 3446 | + * @param string $messenger_name The name of the messenger the message type is being deactivated for. |
|
| 3447 | + * @param string $message_type_name The name of the message type being deactivated for the messenger |
|
| 3448 | + * |
|
| 3449 | + * @return bool |
|
| 3450 | + */ |
|
| 3451 | + protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 3452 | + { |
|
| 3453 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3454 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3455 | + /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 3456 | + $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3457 | + $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name); |
|
| 3458 | + |
|
| 3459 | + return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger, |
|
| 3460 | + $message_type_to_deactivate); |
|
| 3461 | + } |
|
| 3462 | + |
|
| 3463 | + |
|
| 3464 | + /** |
|
| 3465 | + * This just initializes the defaults for activating messenger and message type responses. |
|
| 3466 | + */ |
|
| 3467 | + protected function _prep_default_response_for_messenger_or_message_type_toggle() |
|
| 3468 | + { |
|
| 3469 | + $this->_template_args['data']['active_mts'] = array(); |
|
| 3470 | + $this->_template_args['data']['mt_reload'] = array(); |
|
| 3471 | + } |
|
| 3472 | + |
|
| 3473 | + |
|
| 3474 | + /** |
|
| 3475 | + * Setup appropriate response for activating a messenger and/or message types |
|
| 3476 | + * |
|
| 3477 | + * @param EE_messenger $messenger |
|
| 3478 | + * @param EE_message_type|null $message_type |
|
| 3479 | + * |
|
| 3480 | + * @return bool |
|
| 3481 | + * @throws EE_Error |
|
| 3482 | + */ |
|
| 3483 | + protected function _setup_response_message_for_activating_messenger_with_message_types( |
|
| 3484 | + $messenger, |
|
| 3485 | + EE_Message_Type $message_type = null |
|
| 3486 | + ) { |
|
| 3487 | + //if $messenger isn't a valid messenger object then get out. |
|
| 3488 | + if ( ! $messenger instanceof EE_Messenger) { |
|
| 3489 | + EE_Error::add_error( |
|
| 3490 | + __('The messenger being activated is not a valid messenger', 'event_espresso'), |
|
| 3491 | + __FILE__, |
|
| 3492 | + __FUNCTION__, |
|
| 3493 | + __LINE__ |
|
| 3494 | + ); |
|
| 3495 | 3495 | |
| 3496 | - return false; |
|
| 3497 | - } |
|
| 3498 | - //activated |
|
| 3499 | - if ($this->_template_args['data']['active_mts']) { |
|
| 3500 | - EE_Error::overwrite_success(); |
|
| 3501 | - //activated a message type with the messenger |
|
| 3502 | - if ($message_type instanceof EE_message_type) { |
|
| 3503 | - EE_Error::add_success( |
|
| 3504 | - sprintf( |
|
| 3505 | - __('%s message type has been successfully activated with the %s messenger', 'event_espresso'), |
|
| 3506 | - ucwords($message_type->label['singular']), |
|
| 3507 | - ucwords($messenger->label['singular']) |
|
| 3508 | - ) |
|
| 3509 | - ); |
|
| 3496 | + return false; |
|
| 3497 | + } |
|
| 3498 | + //activated |
|
| 3499 | + if ($this->_template_args['data']['active_mts']) { |
|
| 3500 | + EE_Error::overwrite_success(); |
|
| 3501 | + //activated a message type with the messenger |
|
| 3502 | + if ($message_type instanceof EE_message_type) { |
|
| 3503 | + EE_Error::add_success( |
|
| 3504 | + sprintf( |
|
| 3505 | + __('%s message type has been successfully activated with the %s messenger', 'event_espresso'), |
|
| 3506 | + ucwords($message_type->label['singular']), |
|
| 3507 | + ucwords($messenger->label['singular']) |
|
| 3508 | + ) |
|
| 3509 | + ); |
|
| 3510 | 3510 | |
| 3511 | - //if message type was invoice then let's make sure we activate the invoice payment method. |
|
| 3512 | - if ($message_type->name == 'invoice') { |
|
| 3513 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 3514 | - $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 3515 | - if ($pm instanceof EE_Payment_Method) { |
|
| 3516 | - EE_Error::add_attention(__('Activating the invoice message type also automatically activates the invoice payment method. If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.', |
|
| 3517 | - 'event_espresso')); |
|
| 3518 | - } |
|
| 3519 | - } |
|
| 3520 | - //just toggles the entire messenger |
|
| 3521 | - } else { |
|
| 3522 | - EE_Error::add_success( |
|
| 3523 | - sprintf( |
|
| 3524 | - __('%s messenger has been successfully activated', 'event_espresso'), |
|
| 3525 | - ucwords($messenger->label['singular']) |
|
| 3526 | - ) |
|
| 3527 | - ); |
|
| 3528 | - } |
|
| 3511 | + //if message type was invoice then let's make sure we activate the invoice payment method. |
|
| 3512 | + if ($message_type->name == 'invoice') { |
|
| 3513 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 3514 | + $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 3515 | + if ($pm instanceof EE_Payment_Method) { |
|
| 3516 | + EE_Error::add_attention(__('Activating the invoice message type also automatically activates the invoice payment method. If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.', |
|
| 3517 | + 'event_espresso')); |
|
| 3518 | + } |
|
| 3519 | + } |
|
| 3520 | + //just toggles the entire messenger |
|
| 3521 | + } else { |
|
| 3522 | + EE_Error::add_success( |
|
| 3523 | + sprintf( |
|
| 3524 | + __('%s messenger has been successfully activated', 'event_espresso'), |
|
| 3525 | + ucwords($messenger->label['singular']) |
|
| 3526 | + ) |
|
| 3527 | + ); |
|
| 3528 | + } |
|
| 3529 | 3529 | |
| 3530 | - return true; |
|
| 3530 | + return true; |
|
| 3531 | 3531 | |
| 3532 | - //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active |
|
| 3533 | - //message types after the activation process. However its possible some messengers don't HAVE any default_message_types |
|
| 3534 | - //in which case we just give a success message for the messenger being successfully activated. |
|
| 3535 | - } else { |
|
| 3536 | - if ( ! $messenger->get_default_message_types()) { |
|
| 3537 | - //messenger doesn't have any default message types so still a success. |
|
| 3538 | - EE_Error::add_success( |
|
| 3539 | - sprintf( |
|
| 3540 | - __('%s messenger was successfully activated.', 'event_espresso'), |
|
| 3541 | - ucwords($messenger->label['singular']) |
|
| 3542 | - ) |
|
| 3543 | - ); |
|
| 3532 | + //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active |
|
| 3533 | + //message types after the activation process. However its possible some messengers don't HAVE any default_message_types |
|
| 3534 | + //in which case we just give a success message for the messenger being successfully activated. |
|
| 3535 | + } else { |
|
| 3536 | + if ( ! $messenger->get_default_message_types()) { |
|
| 3537 | + //messenger doesn't have any default message types so still a success. |
|
| 3538 | + EE_Error::add_success( |
|
| 3539 | + sprintf( |
|
| 3540 | + __('%s messenger was successfully activated.', 'event_espresso'), |
|
| 3541 | + ucwords($messenger->label['singular']) |
|
| 3542 | + ) |
|
| 3543 | + ); |
|
| 3544 | 3544 | |
| 3545 | - return true; |
|
| 3546 | - } else { |
|
| 3547 | - EE_Error::add_error( |
|
| 3548 | - $message_type instanceof EE_message_type |
|
| 3549 | - ? sprintf( |
|
| 3550 | - __('%s message type was not successfully activated with the %s messenger', 'event_espresso'), |
|
| 3551 | - ucwords($message_type->label['singular']), |
|
| 3552 | - ucwords($messenger->label['singular']) |
|
| 3553 | - ) |
|
| 3554 | - : sprintf( |
|
| 3555 | - __('%s messenger was not successfully activated', 'event_espresso'), |
|
| 3556 | - ucwords($messenger->label['singular']) |
|
| 3557 | - ), |
|
| 3558 | - __FILE__, |
|
| 3559 | - __FUNCTION__, |
|
| 3560 | - __LINE__ |
|
| 3561 | - ); |
|
| 3545 | + return true; |
|
| 3546 | + } else { |
|
| 3547 | + EE_Error::add_error( |
|
| 3548 | + $message_type instanceof EE_message_type |
|
| 3549 | + ? sprintf( |
|
| 3550 | + __('%s message type was not successfully activated with the %s messenger', 'event_espresso'), |
|
| 3551 | + ucwords($message_type->label['singular']), |
|
| 3552 | + ucwords($messenger->label['singular']) |
|
| 3553 | + ) |
|
| 3554 | + : sprintf( |
|
| 3555 | + __('%s messenger was not successfully activated', 'event_espresso'), |
|
| 3556 | + ucwords($messenger->label['singular']) |
|
| 3557 | + ), |
|
| 3558 | + __FILE__, |
|
| 3559 | + __FUNCTION__, |
|
| 3560 | + __LINE__ |
|
| 3561 | + ); |
|
| 3562 | 3562 | |
| 3563 | - return false; |
|
| 3564 | - } |
|
| 3565 | - } |
|
| 3566 | - } |
|
| 3567 | - |
|
| 3568 | - |
|
| 3569 | - /** |
|
| 3570 | - * This sets up the appropriate response for deactivating a messenger and/or message type. |
|
| 3571 | - * |
|
| 3572 | - * @param EE_messenger $messenger |
|
| 3573 | - * @param EE_message_type|null $message_type |
|
| 3574 | - * |
|
| 3575 | - * @return bool |
|
| 3576 | - */ |
|
| 3577 | - protected function _setup_response_message_for_deactivating_messenger_with_message_types( |
|
| 3578 | - $messenger, |
|
| 3579 | - EE_message_type $message_type = null |
|
| 3580 | - ) { |
|
| 3581 | - EE_Error::overwrite_success(); |
|
| 3582 | - |
|
| 3583 | - //if $messenger isn't a valid messenger object then get out. |
|
| 3584 | - if ( ! $messenger instanceof EE_Messenger) { |
|
| 3585 | - EE_Error::add_error( |
|
| 3586 | - __('The messenger being deactivated is not a valid messenger', 'event_espresso'), |
|
| 3587 | - __FILE__, |
|
| 3588 | - __FUNCTION__, |
|
| 3589 | - __LINE__ |
|
| 3590 | - ); |
|
| 3563 | + return false; |
|
| 3564 | + } |
|
| 3565 | + } |
|
| 3566 | + } |
|
| 3567 | + |
|
| 3568 | + |
|
| 3569 | + /** |
|
| 3570 | + * This sets up the appropriate response for deactivating a messenger and/or message type. |
|
| 3571 | + * |
|
| 3572 | + * @param EE_messenger $messenger |
|
| 3573 | + * @param EE_message_type|null $message_type |
|
| 3574 | + * |
|
| 3575 | + * @return bool |
|
| 3576 | + */ |
|
| 3577 | + protected function _setup_response_message_for_deactivating_messenger_with_message_types( |
|
| 3578 | + $messenger, |
|
| 3579 | + EE_message_type $message_type = null |
|
| 3580 | + ) { |
|
| 3581 | + EE_Error::overwrite_success(); |
|
| 3582 | + |
|
| 3583 | + //if $messenger isn't a valid messenger object then get out. |
|
| 3584 | + if ( ! $messenger instanceof EE_Messenger) { |
|
| 3585 | + EE_Error::add_error( |
|
| 3586 | + __('The messenger being deactivated is not a valid messenger', 'event_espresso'), |
|
| 3587 | + __FILE__, |
|
| 3588 | + __FUNCTION__, |
|
| 3589 | + __LINE__ |
|
| 3590 | + ); |
|
| 3591 | 3591 | |
| 3592 | - return false; |
|
| 3593 | - } |
|
| 3594 | - |
|
| 3595 | - if ($message_type instanceof EE_message_type) { |
|
| 3596 | - $message_type_name = $message_type->name; |
|
| 3597 | - EE_Error::add_success( |
|
| 3598 | - sprintf( |
|
| 3599 | - __('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'), |
|
| 3600 | - ucwords($message_type->label['singular']), |
|
| 3601 | - ucwords($messenger->label['singular']) |
|
| 3602 | - ) |
|
| 3603 | - ); |
|
| 3604 | - } else { |
|
| 3605 | - $message_type_name = ''; |
|
| 3606 | - EE_Error::add_success( |
|
| 3607 | - sprintf( |
|
| 3608 | - __('%s messenger has been successfully deactivated.', 'event_espresso'), |
|
| 3609 | - ucwords($messenger->label['singular']) |
|
| 3610 | - ) |
|
| 3611 | - ); |
|
| 3612 | - } |
|
| 3613 | - |
|
| 3614 | - //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method. |
|
| 3615 | - if ($messenger->name == 'html' || $message_type_name == 'invoice') { |
|
| 3616 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 3617 | - $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice'); |
|
| 3618 | - if ($count_updated > 0) { |
|
| 3619 | - $msg = $message_type_name == 'invoice' |
|
| 3620 | - ? __('Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.', |
|
| 3621 | - 'event_espresso') |
|
| 3622 | - : __('Deactivating the html messenger also automatically deactivates the invoice payment method. In order for invoices to be generated the html messenger must be be active. If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.', |
|
| 3623 | - 'event_espresso'); |
|
| 3624 | - EE_Error::add_attention($msg); |
|
| 3625 | - } |
|
| 3626 | - } |
|
| 3627 | - |
|
| 3628 | - return true; |
|
| 3629 | - } |
|
| 3630 | - |
|
| 3631 | - |
|
| 3632 | - /** |
|
| 3633 | - * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax) |
|
| 3634 | - */ |
|
| 3635 | - public function update_mt_form() |
|
| 3636 | - { |
|
| 3637 | - if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) { |
|
| 3638 | - EE_Error::add_error(__('Require message type or messenger to send an updated form'), __FILE__, __FUNCTION__, |
|
| 3639 | - __LINE__); |
|
| 3640 | - $this->_return_json(); |
|
| 3641 | - } |
|
| 3642 | - |
|
| 3643 | - $message_types = $this->get_installed_message_types(); |
|
| 3644 | - |
|
| 3645 | - $message_type = $message_types[$this->_req_data['message_type']]; |
|
| 3646 | - $messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 3647 | - |
|
| 3648 | - $content = $this->_message_type_settings_content($message_type, $messenger, true); |
|
| 3649 | - $this->_template_args['success'] = true; |
|
| 3650 | - $this->_template_args['content'] = $content; |
|
| 3651 | - $this->_return_json(); |
|
| 3652 | - } |
|
| 3653 | - |
|
| 3654 | - |
|
| 3655 | - /** |
|
| 3656 | - * this handles saving the settings for a messenger or message type |
|
| 3657 | - * |
|
| 3658 | - */ |
|
| 3659 | - public function save_settings() |
|
| 3660 | - { |
|
| 3661 | - if ( ! isset($this->_req_data['type'])) { |
|
| 3662 | - EE_Error::add_error(__('Cannot save settings because type is unknown (messenger settings or messsage type settings?)', |
|
| 3663 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 3664 | - $this->_template_args['error'] = true; |
|
| 3665 | - $this->_return_json(); |
|
| 3666 | - } |
|
| 3667 | - |
|
| 3668 | - |
|
| 3669 | - if ($this->_req_data['type'] == 'messenger') { |
|
| 3670 | - $settings = $this->_req_data['messenger_settings']; //this should be an array. |
|
| 3671 | - $messenger = $settings['messenger']; |
|
| 3672 | - //let's setup the settings data |
|
| 3673 | - foreach ($settings as $key => $value) { |
|
| 3674 | - switch ($key) { |
|
| 3675 | - case 'messenger' : |
|
| 3676 | - unset($settings['messenger']); |
|
| 3677 | - break; |
|
| 3678 | - case 'message_types' : |
|
| 3679 | - unset($settings['message_types']); |
|
| 3680 | - break; |
|
| 3681 | - default : |
|
| 3682 | - $settings[$key] = $value; |
|
| 3683 | - break; |
|
| 3684 | - } |
|
| 3685 | - } |
|
| 3686 | - $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings); |
|
| 3687 | - } else if ($this->_req_data['type'] == 'message_type') { |
|
| 3688 | - $settings = $this->_req_data['message_type_settings']; |
|
| 3689 | - $messenger = $settings['messenger']; |
|
| 3690 | - $message_type = $settings['message_type']; |
|
| 3592 | + return false; |
|
| 3593 | + } |
|
| 3594 | + |
|
| 3595 | + if ($message_type instanceof EE_message_type) { |
|
| 3596 | + $message_type_name = $message_type->name; |
|
| 3597 | + EE_Error::add_success( |
|
| 3598 | + sprintf( |
|
| 3599 | + __('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'), |
|
| 3600 | + ucwords($message_type->label['singular']), |
|
| 3601 | + ucwords($messenger->label['singular']) |
|
| 3602 | + ) |
|
| 3603 | + ); |
|
| 3604 | + } else { |
|
| 3605 | + $message_type_name = ''; |
|
| 3606 | + EE_Error::add_success( |
|
| 3607 | + sprintf( |
|
| 3608 | + __('%s messenger has been successfully deactivated.', 'event_espresso'), |
|
| 3609 | + ucwords($messenger->label['singular']) |
|
| 3610 | + ) |
|
| 3611 | + ); |
|
| 3612 | + } |
|
| 3613 | + |
|
| 3614 | + //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method. |
|
| 3615 | + if ($messenger->name == 'html' || $message_type_name == 'invoice') { |
|
| 3616 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 3617 | + $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice'); |
|
| 3618 | + if ($count_updated > 0) { |
|
| 3619 | + $msg = $message_type_name == 'invoice' |
|
| 3620 | + ? __('Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.', |
|
| 3621 | + 'event_espresso') |
|
| 3622 | + : __('Deactivating the html messenger also automatically deactivates the invoice payment method. In order for invoices to be generated the html messenger must be be active. If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.', |
|
| 3623 | + 'event_espresso'); |
|
| 3624 | + EE_Error::add_attention($msg); |
|
| 3625 | + } |
|
| 3626 | + } |
|
| 3627 | + |
|
| 3628 | + return true; |
|
| 3629 | + } |
|
| 3630 | + |
|
| 3631 | + |
|
| 3632 | + /** |
|
| 3633 | + * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax) |
|
| 3634 | + */ |
|
| 3635 | + public function update_mt_form() |
|
| 3636 | + { |
|
| 3637 | + if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) { |
|
| 3638 | + EE_Error::add_error(__('Require message type or messenger to send an updated form'), __FILE__, __FUNCTION__, |
|
| 3639 | + __LINE__); |
|
| 3640 | + $this->_return_json(); |
|
| 3641 | + } |
|
| 3642 | + |
|
| 3643 | + $message_types = $this->get_installed_message_types(); |
|
| 3644 | + |
|
| 3645 | + $message_type = $message_types[$this->_req_data['message_type']]; |
|
| 3646 | + $messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 3647 | + |
|
| 3648 | + $content = $this->_message_type_settings_content($message_type, $messenger, true); |
|
| 3649 | + $this->_template_args['success'] = true; |
|
| 3650 | + $this->_template_args['content'] = $content; |
|
| 3651 | + $this->_return_json(); |
|
| 3652 | + } |
|
| 3653 | + |
|
| 3654 | + |
|
| 3655 | + /** |
|
| 3656 | + * this handles saving the settings for a messenger or message type |
|
| 3657 | + * |
|
| 3658 | + */ |
|
| 3659 | + public function save_settings() |
|
| 3660 | + { |
|
| 3661 | + if ( ! isset($this->_req_data['type'])) { |
|
| 3662 | + EE_Error::add_error(__('Cannot save settings because type is unknown (messenger settings or messsage type settings?)', |
|
| 3663 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 3664 | + $this->_template_args['error'] = true; |
|
| 3665 | + $this->_return_json(); |
|
| 3666 | + } |
|
| 3667 | + |
|
| 3668 | + |
|
| 3669 | + if ($this->_req_data['type'] == 'messenger') { |
|
| 3670 | + $settings = $this->_req_data['messenger_settings']; //this should be an array. |
|
| 3671 | + $messenger = $settings['messenger']; |
|
| 3672 | + //let's setup the settings data |
|
| 3673 | + foreach ($settings as $key => $value) { |
|
| 3674 | + switch ($key) { |
|
| 3675 | + case 'messenger' : |
|
| 3676 | + unset($settings['messenger']); |
|
| 3677 | + break; |
|
| 3678 | + case 'message_types' : |
|
| 3679 | + unset($settings['message_types']); |
|
| 3680 | + break; |
|
| 3681 | + default : |
|
| 3682 | + $settings[$key] = $value; |
|
| 3683 | + break; |
|
| 3684 | + } |
|
| 3685 | + } |
|
| 3686 | + $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings); |
|
| 3687 | + } else if ($this->_req_data['type'] == 'message_type') { |
|
| 3688 | + $settings = $this->_req_data['message_type_settings']; |
|
| 3689 | + $messenger = $settings['messenger']; |
|
| 3690 | + $message_type = $settings['message_type']; |
|
| 3691 | 3691 | |
| 3692 | - foreach ($settings as $key => $value) { |
|
| 3693 | - switch ($key) { |
|
| 3694 | - case 'messenger' : |
|
| 3695 | - unset($settings['messenger']); |
|
| 3696 | - break; |
|
| 3697 | - case 'message_type' : |
|
| 3698 | - unset($settings['message_type']); |
|
| 3699 | - break; |
|
| 3700 | - default : |
|
| 3701 | - $settings[$key] = $value; |
|
| 3702 | - break; |
|
| 3703 | - } |
|
| 3704 | - } |
|
| 3692 | + foreach ($settings as $key => $value) { |
|
| 3693 | + switch ($key) { |
|
| 3694 | + case 'messenger' : |
|
| 3695 | + unset($settings['messenger']); |
|
| 3696 | + break; |
|
| 3697 | + case 'message_type' : |
|
| 3698 | + unset($settings['message_type']); |
|
| 3699 | + break; |
|
| 3700 | + default : |
|
| 3701 | + $settings[$key] = $value; |
|
| 3702 | + break; |
|
| 3703 | + } |
|
| 3704 | + } |
|
| 3705 | 3705 | |
| 3706 | - $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings); |
|
| 3707 | - } |
|
| 3708 | - |
|
| 3709 | - //okay we should have the data all setup. Now we just update! |
|
| 3710 | - $success = $this->_message_resource_manager->update_active_messengers_option(); |
|
| 3711 | - |
|
| 3712 | - if ($success) { |
|
| 3713 | - EE_Error::add_success(__('Settings updated', 'event_espresso')); |
|
| 3714 | - } else { |
|
| 3715 | - EE_Error::add_error(__('Settings did not get updated', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 3716 | - } |
|
| 3717 | - |
|
| 3718 | - $this->_template_args['success'] = $success; |
|
| 3719 | - $this->_return_json(); |
|
| 3720 | - } |
|
| 3721 | - |
|
| 3722 | - |
|
| 3723 | - |
|
| 3724 | - |
|
| 3725 | - /** EE MESSAGE PROCESSING ACTIONS **/ |
|
| 3726 | - |
|
| 3727 | - |
|
| 3728 | - /** |
|
| 3729 | - * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete |
|
| 3730 | - * However, this does not send immediately, it just queues for sending. |
|
| 3731 | - * |
|
| 3732 | - * @since 4.9.0 |
|
| 3733 | - */ |
|
| 3734 | - protected function _generate_now() |
|
| 3735 | - { |
|
| 3736 | - $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3737 | - EED_Messages::generate_now($msg_ids); |
|
| 3738 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3739 | - } |
|
| 3740 | - |
|
| 3741 | - |
|
| 3742 | - /** |
|
| 3743 | - * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that |
|
| 3744 | - * are EEM_Message::status_resend or EEM_Message::status_idle |
|
| 3745 | - * |
|
| 3746 | - * @since 4.9.0 |
|
| 3747 | - * |
|
| 3748 | - */ |
|
| 3749 | - protected function _generate_and_send_now() |
|
| 3750 | - { |
|
| 3751 | - $this->_generate_now(); |
|
| 3752 | - $this->_send_now(); |
|
| 3753 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3754 | - } |
|
| 3755 | - |
|
| 3756 | - |
|
| 3757 | - /** |
|
| 3758 | - * This queues any EEM_Message::status_sent EE_Message ids in the request for resending. |
|
| 3759 | - * |
|
| 3760 | - * @since 4.9.0 |
|
| 3761 | - */ |
|
| 3762 | - protected function _queue_for_resending() |
|
| 3763 | - { |
|
| 3764 | - $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3765 | - EED_Messages::queue_for_resending($msg_ids); |
|
| 3766 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3767 | - } |
|
| 3768 | - |
|
| 3769 | - |
|
| 3770 | - /** |
|
| 3771 | - * This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue |
|
| 3772 | - * |
|
| 3773 | - * @since 4.9.0 |
|
| 3774 | - */ |
|
| 3775 | - protected function _send_now() |
|
| 3776 | - { |
|
| 3777 | - $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3778 | - EED_Messages::send_now($msg_ids); |
|
| 3779 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3780 | - } |
|
| 3781 | - |
|
| 3782 | - |
|
| 3783 | - /** |
|
| 3784 | - * Deletes EE_messages for IDs in the request. |
|
| 3785 | - * |
|
| 3786 | - * @since 4.9.0 |
|
| 3787 | - */ |
|
| 3788 | - protected function _delete_ee_messages() |
|
| 3789 | - { |
|
| 3790 | - $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3791 | - $deleted_count = 0; |
|
| 3792 | - foreach ($msg_ids as $msg_id) { |
|
| 3793 | - if (EEM_Message::instance()->delete_by_ID($msg_id)) { |
|
| 3794 | - $deleted_count++; |
|
| 3795 | - } |
|
| 3796 | - } |
|
| 3797 | - if ($deleted_count) { |
|
| 3798 | - $this->_redirect_after_action( |
|
| 3799 | - true, |
|
| 3800 | - _n('message', 'messages', $deleted_count, 'event_espresso'), |
|
| 3801 | - __('deleted', 'event_espresso') |
|
| 3802 | - ); |
|
| 3803 | - } else { |
|
| 3804 | - EE_Error::add_error( |
|
| 3805 | - _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'), |
|
| 3806 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 3807 | - ); |
|
| 3808 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3809 | - } |
|
| 3810 | - } |
|
| 3811 | - |
|
| 3812 | - |
|
| 3813 | - /** |
|
| 3814 | - * This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present. |
|
| 3815 | - * @since 4.9.0 |
|
| 3816 | - * @return array |
|
| 3817 | - */ |
|
| 3818 | - protected function _get_msg_ids_from_request() |
|
| 3819 | - { |
|
| 3820 | - if ( ! isset($this->_req_data['MSG_ID'])) { |
|
| 3821 | - return array(); |
|
| 3822 | - } |
|
| 3823 | - |
|
| 3824 | - return is_array($this->_req_data['MSG_ID']) ? array_keys($this->_req_data['MSG_ID']) : array($this->_req_data['MSG_ID']); |
|
| 3825 | - } |
|
| 3706 | + $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings); |
|
| 3707 | + } |
|
| 3708 | + |
|
| 3709 | + //okay we should have the data all setup. Now we just update! |
|
| 3710 | + $success = $this->_message_resource_manager->update_active_messengers_option(); |
|
| 3711 | + |
|
| 3712 | + if ($success) { |
|
| 3713 | + EE_Error::add_success(__('Settings updated', 'event_espresso')); |
|
| 3714 | + } else { |
|
| 3715 | + EE_Error::add_error(__('Settings did not get updated', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 3716 | + } |
|
| 3717 | + |
|
| 3718 | + $this->_template_args['success'] = $success; |
|
| 3719 | + $this->_return_json(); |
|
| 3720 | + } |
|
| 3721 | + |
|
| 3722 | + |
|
| 3723 | + |
|
| 3724 | + |
|
| 3725 | + /** EE MESSAGE PROCESSING ACTIONS **/ |
|
| 3726 | + |
|
| 3727 | + |
|
| 3728 | + /** |
|
| 3729 | + * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete |
|
| 3730 | + * However, this does not send immediately, it just queues for sending. |
|
| 3731 | + * |
|
| 3732 | + * @since 4.9.0 |
|
| 3733 | + */ |
|
| 3734 | + protected function _generate_now() |
|
| 3735 | + { |
|
| 3736 | + $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3737 | + EED_Messages::generate_now($msg_ids); |
|
| 3738 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3739 | + } |
|
| 3740 | + |
|
| 3741 | + |
|
| 3742 | + /** |
|
| 3743 | + * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that |
|
| 3744 | + * are EEM_Message::status_resend or EEM_Message::status_idle |
|
| 3745 | + * |
|
| 3746 | + * @since 4.9.0 |
|
| 3747 | + * |
|
| 3748 | + */ |
|
| 3749 | + protected function _generate_and_send_now() |
|
| 3750 | + { |
|
| 3751 | + $this->_generate_now(); |
|
| 3752 | + $this->_send_now(); |
|
| 3753 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3754 | + } |
|
| 3755 | + |
|
| 3756 | + |
|
| 3757 | + /** |
|
| 3758 | + * This queues any EEM_Message::status_sent EE_Message ids in the request for resending. |
|
| 3759 | + * |
|
| 3760 | + * @since 4.9.0 |
|
| 3761 | + */ |
|
| 3762 | + protected function _queue_for_resending() |
|
| 3763 | + { |
|
| 3764 | + $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3765 | + EED_Messages::queue_for_resending($msg_ids); |
|
| 3766 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3767 | + } |
|
| 3768 | + |
|
| 3769 | + |
|
| 3770 | + /** |
|
| 3771 | + * This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue |
|
| 3772 | + * |
|
| 3773 | + * @since 4.9.0 |
|
| 3774 | + */ |
|
| 3775 | + protected function _send_now() |
|
| 3776 | + { |
|
| 3777 | + $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3778 | + EED_Messages::send_now($msg_ids); |
|
| 3779 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3780 | + } |
|
| 3781 | + |
|
| 3782 | + |
|
| 3783 | + /** |
|
| 3784 | + * Deletes EE_messages for IDs in the request. |
|
| 3785 | + * |
|
| 3786 | + * @since 4.9.0 |
|
| 3787 | + */ |
|
| 3788 | + protected function _delete_ee_messages() |
|
| 3789 | + { |
|
| 3790 | + $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3791 | + $deleted_count = 0; |
|
| 3792 | + foreach ($msg_ids as $msg_id) { |
|
| 3793 | + if (EEM_Message::instance()->delete_by_ID($msg_id)) { |
|
| 3794 | + $deleted_count++; |
|
| 3795 | + } |
|
| 3796 | + } |
|
| 3797 | + if ($deleted_count) { |
|
| 3798 | + $this->_redirect_after_action( |
|
| 3799 | + true, |
|
| 3800 | + _n('message', 'messages', $deleted_count, 'event_espresso'), |
|
| 3801 | + __('deleted', 'event_espresso') |
|
| 3802 | + ); |
|
| 3803 | + } else { |
|
| 3804 | + EE_Error::add_error( |
|
| 3805 | + _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'), |
|
| 3806 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 3807 | + ); |
|
| 3808 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3809 | + } |
|
| 3810 | + } |
|
| 3811 | + |
|
| 3812 | + |
|
| 3813 | + /** |
|
| 3814 | + * This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present. |
|
| 3815 | + * @since 4.9.0 |
|
| 3816 | + * @return array |
|
| 3817 | + */ |
|
| 3818 | + protected function _get_msg_ids_from_request() |
|
| 3819 | + { |
|
| 3820 | + if ( ! isset($this->_req_data['MSG_ID'])) { |
|
| 3821 | + return array(); |
|
| 3822 | + } |
|
| 3823 | + |
|
| 3824 | + return is_array($this->_req_data['MSG_ID']) ? array_keys($this->_req_data['MSG_ID']) : array($this->_req_data['MSG_ID']); |
|
| 3825 | + } |
|
| 3826 | 3826 | |
| 3827 | 3827 | |
| 3828 | 3828 | } |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | $this->_admin_base_url = EE_MSG_ADMIN_URL; |
| 88 | 88 | $this->_admin_base_path = EE_MSG_ADMIN; |
| 89 | 89 | |
| 90 | - $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array(); |
|
| 90 | + $this->_activate_state = isset($this->_req_data['activate_state']) ? (array) $this->_req_data['activate_state'] : array(); |
|
| 91 | 91 | |
| 92 | 92 | $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null; |
| 93 | 93 | $this->_load_message_resource_manager(); |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | array('none_selected' => __('Show All Messengers', 'event_espresso')), |
| 220 | 220 | $messenger_options |
| 221 | 221 | ); |
| 222 | - $input = new EE_Select_Input( |
|
| 222 | + $input = new EE_Select_Input( |
|
| 223 | 223 | $messenger_options, |
| 224 | 224 | array( |
| 225 | 225 | 'html_name' => 'ee_messenger_filter_by', |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | array('none_selected' => __('Show All Message Types', 'event_espresso')), |
| 258 | 258 | $message_type_options |
| 259 | 259 | ); |
| 260 | - $input = new EE_Select_Input( |
|
| 260 | + $input = new EE_Select_Input( |
|
| 261 | 261 | $message_type_options, |
| 262 | 262 | array( |
| 263 | 263 | 'html_name' => 'ee_message_type_filter_by', |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | array('none_selected' => __('Show all Contexts', 'event_espresso')), |
| 296 | 296 | $context_options |
| 297 | 297 | ); |
| 298 | - $input = new EE_Select_Input( |
|
| 298 | + $input = new EE_Select_Input( |
|
| 299 | 299 | $context_options, |
| 300 | 300 | array( |
| 301 | 301 | 'html_name' => 'ee_context_filter_by', |
@@ -676,47 +676,47 @@ discard block |
||
| 676 | 676 | |
| 677 | 677 | public function messages_help_tab() |
| 678 | 678 | { |
| 679 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php'); |
|
| 679 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_help_tab.template.php'); |
|
| 680 | 680 | } |
| 681 | 681 | |
| 682 | 682 | |
| 683 | 683 | public function messengers_help_tab() |
| 684 | 684 | { |
| 685 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php'); |
|
| 685 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messenger_help_tab.template.php'); |
|
| 686 | 686 | } |
| 687 | 687 | |
| 688 | 688 | |
| 689 | 689 | public function message_types_help_tab() |
| 690 | 690 | { |
| 691 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php'); |
|
| 691 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_type_help_tab.template.php'); |
|
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | |
| 695 | 695 | public function messages_overview_help_tab() |
| 696 | 696 | { |
| 697 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php'); |
|
| 697 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_overview_help_tab.template.php'); |
|
| 698 | 698 | } |
| 699 | 699 | |
| 700 | 700 | |
| 701 | 701 | public function message_templates_help_tab() |
| 702 | 702 | { |
| 703 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php'); |
|
| 703 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_templates_help_tab.template.php'); |
|
| 704 | 704 | } |
| 705 | 705 | |
| 706 | 706 | |
| 707 | 707 | public function edit_message_template_help_tab() |
| 708 | 708 | { |
| 709 | - $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' . esc_attr__('Editor Title', |
|
| 710 | - 'event_espresso') . '" />'; |
|
| 711 | - $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' . esc_attr__('Context Switcher and Preview', |
|
| 712 | - 'event_espresso') . '" />'; |
|
| 713 | - $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' . esc_attr__('Message Template Form Fields', |
|
| 714 | - 'event_espresso') . '" />'; |
|
| 715 | - $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' . esc_attr__('Shortcodes Metabox', |
|
| 716 | - 'event_espresso') . '" />'; |
|
| 717 | - $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' . esc_attr__('Publish Metabox', |
|
| 718 | - 'event_espresso') . '" />'; |
|
| 719 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 709 | + $args['img1'] = '<img src="'.EE_MSG_ASSETS_URL.'images/editor.png'.'" alt="'.esc_attr__('Editor Title', |
|
| 710 | + 'event_espresso').'" />'; |
|
| 711 | + $args['img2'] = '<img src="'.EE_MSG_ASSETS_URL.'images/switch-context.png'.'" alt="'.esc_attr__('Context Switcher and Preview', |
|
| 712 | + 'event_espresso').'" />'; |
|
| 713 | + $args['img3'] = '<img class="left" src="'.EE_MSG_ASSETS_URL.'images/form-fields.png'.'" alt="'.esc_attr__('Message Template Form Fields', |
|
| 714 | + 'event_espresso').'" />'; |
|
| 715 | + $args['img4'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/shortcodes-metabox.png'.'" alt="'.esc_attr__('Shortcodes Metabox', |
|
| 716 | + 'event_espresso').'" />'; |
|
| 717 | + $args['img5'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/publish-meta-box.png'.'" alt="'.esc_attr__('Publish Metabox', |
|
| 718 | + 'event_espresso').'" />'; |
|
| 719 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 720 | 720 | $args); |
| 721 | 721 | } |
| 722 | 722 | |
@@ -725,37 +725,37 @@ discard block |
||
| 725 | 725 | { |
| 726 | 726 | $this->_set_shortcodes(); |
| 727 | 727 | $args['shortcodes'] = $this->_shortcodes; |
| 728 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 728 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 729 | 729 | $args); |
| 730 | 730 | } |
| 731 | 731 | |
| 732 | 732 | |
| 733 | 733 | public function preview_message_help_tab() |
| 734 | 734 | { |
| 735 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php'); |
|
| 735 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_preview_help_tab.template.php'); |
|
| 736 | 736 | } |
| 737 | 737 | |
| 738 | 738 | |
| 739 | 739 | public function settings_help_tab() |
| 740 | 740 | { |
| 741 | - $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '" alt="' . esc_attr__('Active Email Tab', |
|
| 742 | - 'event_espresso') . '" />'; |
|
| 743 | - $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' . '" alt="' . esc_attr__('Inactive Email Tab', |
|
| 744 | - 'event_espresso') . '" />'; |
|
| 741 | + $args['img1'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png'.'" alt="'.esc_attr__('Active Email Tab', |
|
| 742 | + 'event_espresso').'" />'; |
|
| 743 | + $args['img2'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png'.'" alt="'.esc_attr__('Inactive Email Tab', |
|
| 744 | + 'event_espresso').'" />'; |
|
| 745 | 745 | $args['img3'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked"><label for="ee-on-off-toggle-on"></label>'; |
| 746 | 746 | $args['img4'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox"><label for="ee-on-off-toggle-on"></label>'; |
| 747 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 747 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 748 | 748 | } |
| 749 | 749 | |
| 750 | 750 | |
| 751 | 751 | public function load_scripts_styles() |
| 752 | 752 | { |
| 753 | - wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 753 | + wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL.'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 754 | 754 | wp_enqueue_style('espresso_ee_msg'); |
| 755 | 755 | |
| 756 | - wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js', |
|
| 756 | + wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL.'ee-messages-settings.js', |
|
| 757 | 757 | array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true); |
| 758 | - wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', |
|
| 758 | + wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL.'ee_message_admin_list_table.js', |
|
| 759 | 759 | array('ee-dialog'), EVENT_ESPRESSO_VERSION); |
| 760 | 760 | } |
| 761 | 761 | |
@@ -787,7 +787,7 @@ discard block |
||
| 787 | 787 | |
| 788 | 788 | $this->_set_shortcodes(); |
| 789 | 789 | |
| 790 | - EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 790 | + EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 791 | 791 | __('Are you sure you want to reset the %s %s message templates? Remember continuing will reset the templates for all contexts in this messenger and message type group.', |
| 792 | 792 | 'event_espresso'), |
| 793 | 793 | $this->_message_template_group->messenger_obj()->label['singular'], |
@@ -796,7 +796,7 @@ discard block |
||
| 796 | 796 | EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = __('Switching the template pack for a messages template will reset the content for the template so the new layout is loaded. Any custom content in the existing template will be lost. Are you sure you wish to do this?', |
| 797 | 797 | 'event_espresso'); |
| 798 | 798 | |
| 799 | - wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL . 'ee_message_editor.js', array('jquery'), |
|
| 799 | + wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL.'ee_message_editor.js', array('jquery'), |
|
| 800 | 800 | EVENT_ESPRESSO_VERSION); |
| 801 | 801 | |
| 802 | 802 | wp_enqueue_script('ee_admin_js'); |
@@ -827,7 +827,7 @@ discard block |
||
| 827 | 827 | |
| 828 | 828 | public function load_scripts_styles_settings() |
| 829 | 829 | { |
| 830 | - wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL . 'ee_message_settings.css', array(), |
|
| 830 | + wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL.'ee_message_settings.css', array(), |
|
| 831 | 831 | EVENT_ESPRESSO_VERSION); |
| 832 | 832 | wp_enqueue_style('ee-text-links'); |
| 833 | 833 | wp_enqueue_style('ee-message-settings'); |
@@ -893,7 +893,7 @@ discard block |
||
| 893 | 893 | } |
| 894 | 894 | $status_bulk_actions = $common_bulk_actions; |
| 895 | 895 | //unset bulk actions not applying to status |
| 896 | - if (! empty($status_bulk_actions)) { |
|
| 896 | + if ( ! empty($status_bulk_actions)) { |
|
| 897 | 897 | switch ($status) { |
| 898 | 898 | case EEM_Message::status_idle: |
| 899 | 899 | case EEM_Message::status_resend: |
@@ -918,7 +918,7 @@ discard block |
||
| 918 | 918 | } |
| 919 | 919 | |
| 920 | 920 | //skip adding messenger executing status to views because it will be included with the Failed view. |
| 921 | - if ( $status === EEM_Message::status_messenger_executing ) { |
|
| 921 | + if ($status === EEM_Message::status_messenger_executing) { |
|
| 922 | 922 | continue; |
| 923 | 923 | } |
| 924 | 924 | |
@@ -944,7 +944,7 @@ discard block |
||
| 944 | 944 | $this->_search_btn_label = __('Message Activity', 'event_espresso'); |
| 945 | 945 | $this->_template_args['per_column'] = 6; |
| 946 | 946 | $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items()); |
| 947 | - $this->_template_args['before_list_table'] = '<h3>' . EEM_Message::instance()->get_pretty_label_for_results() . '</h3>'; |
|
| 947 | + $this->_template_args['before_list_table'] = '<h3>'.EEM_Message::instance()->get_pretty_label_for_results().'</h3>'; |
|
| 948 | 948 | $this->display_admin_list_table_page_with_no_sidebar(); |
| 949 | 949 | } |
| 950 | 950 | |
@@ -968,37 +968,37 @@ discard block |
||
| 968 | 968 | /** @type array $status_items status legend setup */ |
| 969 | 969 | $status_items = array( |
| 970 | 970 | 'sent_status' => array( |
| 971 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent, |
|
| 971 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_sent, |
|
| 972 | 972 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence') |
| 973 | 973 | ), |
| 974 | 974 | 'idle_status' => array( |
| 975 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle, |
|
| 975 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_idle, |
|
| 976 | 976 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence') |
| 977 | 977 | ), |
| 978 | 978 | 'failed_status' => array( |
| 979 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed, |
|
| 979 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_failed, |
|
| 980 | 980 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence') |
| 981 | 981 | ), |
| 982 | 982 | 'messenger_executing_status' => array( |
| 983 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing, |
|
| 983 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_messenger_executing, |
|
| 984 | 984 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence') |
| 985 | 985 | ), |
| 986 | 986 | 'resend_status' => array( |
| 987 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend, |
|
| 987 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_resend, |
|
| 988 | 988 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence') |
| 989 | 989 | ), |
| 990 | 990 | 'incomplete_status' => array( |
| 991 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete, |
|
| 991 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_incomplete, |
|
| 992 | 992 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence') |
| 993 | 993 | ), |
| 994 | 994 | 'retry_status' => array( |
| 995 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry, |
|
| 995 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_retry, |
|
| 996 | 996 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence') |
| 997 | 997 | ) |
| 998 | 998 | ); |
| 999 | 999 | if (EEM_Message::debug()) { |
| 1000 | 1000 | $status_items['debug_only_status'] = array( |
| 1001 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only, |
|
| 1001 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_debug_only, |
|
| 1002 | 1002 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence') |
| 1003 | 1003 | ); |
| 1004 | 1004 | } |
@@ -1010,10 +1010,10 @@ discard block |
||
| 1010 | 1010 | protected function _custom_mtps_preview() |
| 1011 | 1011 | { |
| 1012 | 1012 | $this->_admin_page_title = __('Custom Message Templates (Preview)', 'event_espresso'); |
| 1013 | - $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png" alt="' . esc_attr__('Preview Custom Message Templates screenshot', |
|
| 1014 | - 'event_espresso') . '" />'; |
|
| 1015 | - $this->_template_args['preview_text'] = '<strong>' . __('Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.', |
|
| 1016 | - 'event_espresso') . '</strong>'; |
|
| 1013 | + $this->_template_args['preview_img'] = '<img src="'.EE_MSG_ASSETS_URL.'images/custom_mtps_preview.png" alt="'.esc_attr__('Preview Custom Message Templates screenshot', |
|
| 1014 | + 'event_espresso').'" />'; |
|
| 1015 | + $this->_template_args['preview_text'] = '<strong>'.__('Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.', |
|
| 1016 | + 'event_espresso').'</strong>'; |
|
| 1017 | 1017 | $this->display_admin_caf_preview_page('custom_message_types', false); |
| 1018 | 1018 | } |
| 1019 | 1019 | |
@@ -1261,7 +1261,7 @@ discard block |
||
| 1261 | 1261 | //let's verify if we need this extra field via the shortcodes parameter. |
| 1262 | 1262 | $continue = false; |
| 1263 | 1263 | if (isset($extra_array['shortcodes_required'])) { |
| 1264 | - foreach ((array)$extra_array['shortcodes_required'] as $shortcode) { |
|
| 1264 | + foreach ((array) $extra_array['shortcodes_required'] as $shortcode) { |
|
| 1265 | 1265 | if ( ! array_key_exists($shortcode, $this->_shortcodes)) { |
| 1266 | 1266 | $continue = true; |
| 1267 | 1267 | } |
@@ -1271,9 +1271,9 @@ discard block |
||
| 1271 | 1271 | } |
| 1272 | 1272 | } |
| 1273 | 1273 | |
| 1274 | - $field_id = $reference_field . '-' . $extra_field . '-content'; |
|
| 1274 | + $field_id = $reference_field.'-'.$extra_field.'-content'; |
|
| 1275 | 1275 | $template_form_fields[$field_id] = $extra_array; |
| 1276 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $reference_field . '][content][' . $extra_field . ']'; |
|
| 1276 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields['.$reference_field.'][content]['.$extra_field.']'; |
|
| 1277 | 1277 | $css_class = isset($extra_array['css_class']) ? $extra_array['css_class'] : ''; |
| 1278 | 1278 | |
| 1279 | 1279 | $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
@@ -1283,7 +1283,7 @@ discard block |
||
| 1283 | 1283 | is_array($validators[$extra_field]) |
| 1284 | 1284 | && isset($validators[$extra_field]['msg']) |
| 1285 | 1285 | ) |
| 1286 | - ? 'validate-error ' . $css_class |
|
| 1286 | + ? 'validate-error '.$css_class |
|
| 1287 | 1287 | : $css_class; |
| 1288 | 1288 | |
| 1289 | 1289 | $template_form_fields[$field_id]['value'] = ! empty($message_templates) && isset($content[$extra_field]) |
@@ -1311,11 +1311,11 @@ discard block |
||
| 1311 | 1311 | |
| 1312 | 1312 | }/**/ |
| 1313 | 1313 | } |
| 1314 | - $templatefield_MTP_id = $reference_field . '-MTP_ID'; |
|
| 1315 | - $templatefield_templatename_id = $reference_field . '-name'; |
|
| 1314 | + $templatefield_MTP_id = $reference_field.'-MTP_ID'; |
|
| 1315 | + $templatefield_templatename_id = $reference_field.'-name'; |
|
| 1316 | 1316 | |
| 1317 | 1317 | $template_form_fields[$templatefield_MTP_id] = array( |
| 1318 | - 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]', |
|
| 1318 | + 'name' => 'MTP_template_fields['.$reference_field.'][MTP_ID]', |
|
| 1319 | 1319 | 'label' => null, |
| 1320 | 1320 | 'input' => 'hidden', |
| 1321 | 1321 | 'type' => 'int', |
@@ -1328,7 +1328,7 @@ discard block |
||
| 1328 | 1328 | ); |
| 1329 | 1329 | |
| 1330 | 1330 | $template_form_fields[$templatefield_templatename_id] = array( |
| 1331 | - 'name' => 'MTP_template_fields[' . $reference_field . '][name]', |
|
| 1331 | + 'name' => 'MTP_template_fields['.$reference_field.'][name]', |
|
| 1332 | 1332 | 'label' => null, |
| 1333 | 1333 | 'input' => 'hidden', |
| 1334 | 1334 | 'type' => 'string', |
@@ -1342,9 +1342,9 @@ discard block |
||
| 1342 | 1342 | } |
| 1343 | 1343 | continue; //skip the next stuff, we got the necessary fields here for this dataset. |
| 1344 | 1344 | } else { |
| 1345 | - $field_id = $template_field . '-content'; |
|
| 1345 | + $field_id = $template_field.'-content'; |
|
| 1346 | 1346 | $template_form_fields[$field_id] = $field_setup_array; |
| 1347 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $template_field . '][content]'; |
|
| 1347 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields['.$template_field.'][content]'; |
|
| 1348 | 1348 | $message_template = isset($message_templates[$context][$template_field]) |
| 1349 | 1349 | ? $message_templates[$context][$template_field] |
| 1350 | 1350 | : null; |
@@ -1365,7 +1365,7 @@ discard block |
||
| 1365 | 1365 | $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
| 1366 | 1366 | && in_array($template_field, $v_fields) |
| 1367 | 1367 | && isset($validators[$template_field]['msg']) |
| 1368 | - ? 'validate-error ' . $css_class |
|
| 1368 | + ? 'validate-error '.$css_class |
|
| 1369 | 1369 | : $css_class; |
| 1370 | 1370 | |
| 1371 | 1371 | //shortcode selector |
@@ -1376,12 +1376,12 @@ discard block |
||
| 1376 | 1376 | |
| 1377 | 1377 | //k took care of content field(s) now let's take care of others. |
| 1378 | 1378 | |
| 1379 | - $templatefield_MTP_id = $template_field . '-MTP_ID'; |
|
| 1380 | - $templatefield_field_templatename_id = $template_field . '-name'; |
|
| 1379 | + $templatefield_MTP_id = $template_field.'-MTP_ID'; |
|
| 1380 | + $templatefield_field_templatename_id = $template_field.'-name'; |
|
| 1381 | 1381 | |
| 1382 | 1382 | //foreach template field there are actually two form fields created |
| 1383 | 1383 | $template_form_fields[$templatefield_MTP_id] = array( |
| 1384 | - 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]', |
|
| 1384 | + 'name' => 'MTP_template_fields['.$template_field.'][MTP_ID]', |
|
| 1385 | 1385 | 'label' => null, |
| 1386 | 1386 | 'input' => 'hidden', |
| 1387 | 1387 | 'type' => 'int', |
@@ -1394,7 +1394,7 @@ discard block |
||
| 1394 | 1394 | ); |
| 1395 | 1395 | |
| 1396 | 1396 | $template_form_fields[$templatefield_field_templatename_id] = array( |
| 1397 | - 'name' => 'MTP_template_fields[' . $template_field . '][name]', |
|
| 1397 | + 'name' => 'MTP_template_fields['.$template_field.'][name]', |
|
| 1398 | 1398 | 'label' => null, |
| 1399 | 1399 | 'input' => 'hidden', |
| 1400 | 1400 | 'type' => 'string', |
@@ -1512,7 +1512,7 @@ discard block |
||
| 1512 | 1512 | 'format' => '%d', |
| 1513 | 1513 | 'db-col' => 'MTP_deleted' |
| 1514 | 1514 | ); |
| 1515 | - $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1515 | + $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1516 | 1516 | 'name' => 'MTP_user_id', |
| 1517 | 1517 | 'label' => __('Author', 'event_espresso'), |
| 1518 | 1518 | 'input' => 'hidden', |
@@ -1531,17 +1531,17 @@ discard block |
||
| 1531 | 1531 | 'value' => $action |
| 1532 | 1532 | ); |
| 1533 | 1533 | |
| 1534 | - $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1534 | + $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1535 | 1535 | 'name' => 'id', |
| 1536 | 1536 | 'input' => 'hidden', |
| 1537 | 1537 | 'type' => 'int', |
| 1538 | 1538 | 'value' => $GRP_ID |
| 1539 | 1539 | ); |
| 1540 | 1540 | $sidebar_form_fields['ee-msg-evt-nonce'] = array( |
| 1541 | - 'name' => $action . '_nonce', |
|
| 1541 | + 'name' => $action.'_nonce', |
|
| 1542 | 1542 | 'input' => 'hidden', |
| 1543 | 1543 | 'type' => 'string', |
| 1544 | - 'value' => wp_create_nonce($action . '_nonce') |
|
| 1544 | + 'value' => wp_create_nonce($action.'_nonce') |
|
| 1545 | 1545 | ); |
| 1546 | 1546 | |
| 1547 | 1547 | if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { |
@@ -1573,7 +1573,7 @@ discard block |
||
| 1573 | 1573 | ); |
| 1574 | 1574 | |
| 1575 | 1575 | //add preview button |
| 1576 | - $preview_url = parent::add_query_args_and_nonce( |
|
| 1576 | + $preview_url = parent::add_query_args_and_nonce( |
|
| 1577 | 1577 | array( |
| 1578 | 1578 | 'message_type' => $message_template_group->message_type(), |
| 1579 | 1579 | 'messenger' => $message_template_group->messenger(), |
@@ -1583,8 +1583,8 @@ discard block |
||
| 1583 | 1583 | ), |
| 1584 | 1584 | $this->_admin_base_url |
| 1585 | 1585 | ); |
| 1586 | - $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' . __('Preview', |
|
| 1587 | - 'event_espresso') . '</a>'; |
|
| 1586 | + $preview_button = '<a href="'.$preview_url.'" class="button-secondary messages-preview-button">'.__('Preview', |
|
| 1587 | + 'event_espresso').'</a>'; |
|
| 1588 | 1588 | |
| 1589 | 1589 | |
| 1590 | 1590 | //setup context switcher |
@@ -1613,7 +1613,7 @@ discard block |
||
| 1613 | 1613 | |
| 1614 | 1614 | $this->_template_path = $this->_template_args['GRP_ID'] |
| 1615 | 1615 | ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php' |
| 1616 | - : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1616 | + : EE_MSG_TEMPLATE_PATH.'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1617 | 1617 | |
| 1618 | 1618 | //send along EE_Message_Template_Group object for further template use. |
| 1619 | 1619 | $this->_template_args['MTP'] = $message_template_group; |
@@ -1648,7 +1648,7 @@ discard block |
||
| 1648 | 1648 | |
| 1649 | 1649 | public function _add_form_element_before() |
| 1650 | 1650 | { |
| 1651 | - return '<form method="post" action="' . $this->_template_args["edit_message_template_form_url"] . '" id="ee-msg-edit-frm">'; |
|
| 1651 | + return '<form method="post" action="'.$this->_template_args["edit_message_template_form_url"].'" id="ee-msg-edit-frm">'; |
|
| 1652 | 1652 | } |
| 1653 | 1653 | |
| 1654 | 1654 | public function _add_form_element_after() |
@@ -1843,14 +1843,14 @@ discard block |
||
| 1843 | 1843 | } |
| 1844 | 1844 | |
| 1845 | 1845 | //let's add a button to go back to the edit view |
| 1846 | - $query_args = array( |
|
| 1846 | + $query_args = array( |
|
| 1847 | 1847 | 'id' => $this->_req_data['GRP_ID'], |
| 1848 | 1848 | 'context' => $this->_req_data['context'], |
| 1849 | 1849 | 'action' => 'edit_message_template' |
| 1850 | 1850 | ); |
| 1851 | 1851 | $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
| 1852 | - $preview_button = '<a href="' . $go_back_url . '" class="button-secondary messages-preview-go-back-button">' . __('Go Back to Edit', |
|
| 1853 | - 'event_espresso') . '</a>'; |
|
| 1852 | + $preview_button = '<a href="'.$go_back_url.'" class="button-secondary messages-preview-go-back-button">'.__('Go Back to Edit', |
|
| 1853 | + 'event_espresso').'</a>'; |
|
| 1854 | 1854 | $message_types = $this->get_installed_message_types(); |
| 1855 | 1855 | $active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
| 1856 | 1856 | $active_messenger_label = $active_messenger instanceof EE_messenger |
@@ -1864,7 +1864,7 @@ discard block |
||
| 1864 | 1864 | ); |
| 1865 | 1865 | //setup display of preview. |
| 1866 | 1866 | $this->_admin_page_title = $preview_title; |
| 1867 | - $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview); |
|
| 1867 | + $this->_template_args['admin_page_content'] = $preview_button.'<br />'.stripslashes($preview); |
|
| 1868 | 1868 | $this->_template_args['data']['force_json'] = true; |
| 1869 | 1869 | |
| 1870 | 1870 | return ''; |
@@ -1946,7 +1946,7 @@ discard block |
||
| 1946 | 1946 | } |
| 1947 | 1947 | |
| 1948 | 1948 | //setup variation select values for the currently selected template. |
| 1949 | - $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 1949 | + $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 1950 | 1950 | $this->_message_template_group->messenger(), |
| 1951 | 1951 | $this->_message_template_group->message_type() |
| 1952 | 1952 | ); |
@@ -1960,12 +1960,12 @@ discard block |
||
| 1960 | 1960 | |
| 1961 | 1961 | $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels(); |
| 1962 | 1962 | |
| 1963 | - $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 1963 | + $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 1964 | 1964 | 'MTP_template_pack', |
| 1965 | 1965 | $tp_select_values, |
| 1966 | 1966 | $this->_message_template_group->get_template_pack_name() |
| 1967 | 1967 | ); |
| 1968 | - $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 1968 | + $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 1969 | 1969 | 'MTP_template_variation', |
| 1970 | 1970 | $variations_select_values, |
| 1971 | 1971 | $this->_message_template_group->get_template_pack_variation() |
@@ -1975,7 +1975,7 @@ discard block |
||
| 1975 | 1975 | $template_args['template_pack_description'] = $template_pack_labels->template_pack_description; |
| 1976 | 1976 | $template_args['template_variation_description'] = $template_pack_labels->template_variation_description; |
| 1977 | 1977 | |
| 1978 | - $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php'; |
|
| 1978 | + $template = EE_MSG_TEMPLATE_PATH.'template_pack_and_variations_metabox.template.php'; |
|
| 1979 | 1979 | |
| 1980 | 1980 | EEH_Template::display_template($template, $template_args); |
| 1981 | 1981 | } |
@@ -2004,7 +2004,7 @@ discard block |
||
| 2004 | 2004 | if ( ! empty($fields)) { |
| 2005 | 2005 | //yup there be fields |
| 2006 | 2006 | foreach ($fields as $field => $config) { |
| 2007 | - $field_id = $this->_message_template_group->messenger() . '_' . $field; |
|
| 2007 | + $field_id = $this->_message_template_group->messenger().'_'.$field; |
|
| 2008 | 2008 | $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings(); |
| 2009 | 2009 | $default = isset($config['default']) ? $config['default'] : ''; |
| 2010 | 2010 | $default = isset($config['value']) ? $config['value'] : $default; |
@@ -2019,7 +2019,7 @@ discard block |
||
| 2019 | 2019 | : $fix; |
| 2020 | 2020 | |
| 2021 | 2021 | $template_form_fields[$field_id] = array( |
| 2022 | - 'name' => 'test_settings_fld[' . $field . ']', |
|
| 2022 | + 'name' => 'test_settings_fld['.$field.']', |
|
| 2023 | 2023 | 'label' => $config['label'], |
| 2024 | 2024 | 'input' => $config['input'], |
| 2025 | 2025 | 'type' => $config['type'], |
@@ -2049,7 +2049,7 @@ discard block |
||
| 2049 | 2049 | } |
| 2050 | 2050 | |
| 2051 | 2051 | //and button |
| 2052 | - $test_settings_html .= '<p>' . __('Need to reset this message type and start over?', 'event_espresso') . '</p>'; |
|
| 2052 | + $test_settings_html .= '<p>'.__('Need to reset this message type and start over?', 'event_espresso').'</p>'; |
|
| 2053 | 2053 | $test_settings_html .= '<div class="publishing-action alignright resetbutton">'; |
| 2054 | 2054 | $test_settings_html .= $this->get_action_link_or_button( |
| 2055 | 2055 | 'reset_to_default', |
@@ -2080,7 +2080,7 @@ discard block |
||
| 2080 | 2080 | 'linked_input_id' => $linked_input_id |
| 2081 | 2081 | ); |
| 2082 | 2082 | |
| 2083 | - return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php', |
|
| 2083 | + return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'shortcode_selector_skeleton.template.php', |
|
| 2084 | 2084 | $template_args, true); |
| 2085 | 2085 | } |
| 2086 | 2086 | |
@@ -2098,7 +2098,7 @@ discard block |
||
| 2098 | 2098 | //$messenger = $this->_message_template_group->messenger_obj(); |
| 2099 | 2099 | //now let's set the content depending on the status of the shortcodes array |
| 2100 | 2100 | if (empty($shortcodes)) { |
| 2101 | - $content = '<p>' . __('There are no valid shortcodes available', 'event_espresso') . '</p>'; |
|
| 2101 | + $content = '<p>'.__('There are no valid shortcodes available', 'event_espresso').'</p>'; |
|
| 2102 | 2102 | echo $content; |
| 2103 | 2103 | } else { |
| 2104 | 2104 | //$alt = 0; |
@@ -2215,7 +2215,7 @@ discard block |
||
| 2215 | 2215 | <?php |
| 2216 | 2216 | } |
| 2217 | 2217 | //setup nonce_url |
| 2218 | - wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false); |
|
| 2218 | + wp_nonce_field($args['action'].'_nonce', $args['action'].'_nonce', false); |
|
| 2219 | 2219 | ?> |
| 2220 | 2220 | <select name="context"> |
| 2221 | 2221 | <?php |
@@ -2313,7 +2313,7 @@ discard block |
||
| 2313 | 2313 | : ''; |
| 2314 | 2314 | $context = ucwords(str_replace('_', ' ', $context_slug)); |
| 2315 | 2315 | |
| 2316 | - $item_desc = $messenger_label && $message_type_label ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' : ''; |
|
| 2316 | + $item_desc = $messenger_label && $message_type_label ? $messenger_label.' '.$message_type_label.' '.$context.' ' : ''; |
|
| 2317 | 2317 | $item_desc .= 'Message Template'; |
| 2318 | 2318 | $query_args = array(); |
| 2319 | 2319 | $edit_array = array(); |
@@ -2688,8 +2688,8 @@ discard block |
||
| 2688 | 2688 | */ |
| 2689 | 2689 | protected function _learn_more_about_message_templates_link() |
| 2690 | 2690 | { |
| 2691 | - return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __('learn more about how message templates works', |
|
| 2692 | - 'event_espresso') . '</a>'; |
|
| 2691 | + return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'.__('learn more about how message templates works', |
|
| 2692 | + 'event_espresso').'</a>'; |
|
| 2693 | 2693 | } |
| 2694 | 2694 | |
| 2695 | 2695 | |
@@ -2765,10 +2765,10 @@ discard block |
||
| 2765 | 2765 | |
| 2766 | 2766 | $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array( |
| 2767 | 2767 | 'label' => ucwords($message_type->label['singular']), |
| 2768 | - 'class' => 'message-type-' . $a_or_i, |
|
| 2769 | - 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name, |
|
| 2770 | - 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'), |
|
| 2771 | - 'href' => 'espresso_' . $message_type->name . '_message_type_settings', |
|
| 2768 | + 'class' => 'message-type-'.$a_or_i, |
|
| 2769 | + 'slug_id' => $message_type->name.'-messagetype-'.$messenger->name, |
|
| 2770 | + 'mt_nonce' => wp_create_nonce($message_type->name.'_nonce'), |
|
| 2771 | + 'href' => 'espresso_'.$message_type->name.'_message_type_settings', |
|
| 2772 | 2772 | 'title' => $a_or_i == 'active' |
| 2773 | 2773 | ? __('Drag this message type to the Inactive window to deactivate', 'event_espresso') |
| 2774 | 2774 | : __('Drag this message type to the messenger to activate', 'event_espresso'), |
@@ -2804,9 +2804,9 @@ discard block |
||
| 2804 | 2804 | $existing_settings = $message_type->get_existing_admin_settings($messenger->name); |
| 2805 | 2805 | |
| 2806 | 2806 | foreach ($fields as $fldname => $fldprops) { |
| 2807 | - $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname; |
|
| 2807 | + $field_id = $messenger->name.'-'.$message_type->name.'-'.$fldname; |
|
| 2808 | 2808 | $template_form_field[$field_id] = array( |
| 2809 | - 'name' => 'message_type_settings[' . $fldname . ']', |
|
| 2809 | + 'name' => 'message_type_settings['.$fldname.']', |
|
| 2810 | 2810 | 'label' => $fldprops['label'], |
| 2811 | 2811 | 'input' => $fldprops['field_type'], |
| 2812 | 2812 | 'type' => $fldprops['value_type'], |
@@ -2847,7 +2847,7 @@ discard block |
||
| 2847 | 2847 | $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) ? ' hidden' : ''; |
| 2848 | 2848 | |
| 2849 | 2849 | |
| 2850 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php'; |
|
| 2850 | + $template = EE_MSG_TEMPLATE_PATH.'ee_msg_mt_settings_content.template.php'; |
|
| 2851 | 2851 | $content = EEH_Template::display_template($template, $settings_template_args, true); |
| 2852 | 2852 | |
| 2853 | 2853 | return $content; |
@@ -2877,11 +2877,11 @@ discard block |
||
| 2877 | 2877 | $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active']) |
| 2878 | 2878 | ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
| 2879 | 2879 | : ''; |
| 2880 | - $m_boxes[$messenger . '_a_box'] = sprintf( |
|
| 2880 | + $m_boxes[$messenger.'_a_box'] = sprintf( |
|
| 2881 | 2881 | __('%s Settings', 'event_espresso'), |
| 2882 | 2882 | $tab_array['label'] |
| 2883 | 2883 | ); |
| 2884 | - $m_template_args[$messenger . '_a_box'] = array( |
|
| 2884 | + $m_template_args[$messenger.'_a_box'] = array( |
|
| 2885 | 2885 | 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
| 2886 | 2886 | 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
| 2887 | 2887 | ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
@@ -2895,8 +2895,8 @@ discard block |
||
| 2895 | 2895 | // message type meta boxes |
| 2896 | 2896 | // (which is really just the inactive container for each messenger |
| 2897 | 2897 | // showing inactive message types for that messenger) |
| 2898 | - $mt_boxes[$messenger . '_i_box'] = __('Inactive Message Types', 'event_espresso'); |
|
| 2899 | - $mt_template_args[$messenger . '_i_box'] = array( |
|
| 2898 | + $mt_boxes[$messenger.'_i_box'] = __('Inactive Message Types', 'event_espresso'); |
|
| 2899 | + $mt_template_args[$messenger.'_i_box'] = array( |
|
| 2900 | 2900 | 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
| 2901 | 2901 | 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
| 2902 | 2902 | ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
@@ -2912,14 +2912,14 @@ discard block |
||
| 2912 | 2912 | |
| 2913 | 2913 | |
| 2914 | 2914 | //register messenger metaboxes |
| 2915 | - $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 2915 | + $m_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 2916 | 2916 | foreach ($m_boxes as $box => $label) { |
| 2917 | 2917 | $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]); |
| 2918 | 2918 | $msgr = str_replace('_a_box', '', $box); |
| 2919 | 2919 | add_meta_box( |
| 2920 | - 'espresso_' . $msgr . '_settings', |
|
| 2920 | + 'espresso_'.$msgr.'_settings', |
|
| 2921 | 2921 | $label, |
| 2922 | - function ($post, $metabox) { |
|
| 2922 | + function($post, $metabox) { |
|
| 2923 | 2923 | echo EEH_Template::display_template($metabox["args"]["template_path"], |
| 2924 | 2924 | $metabox["args"]["template_args"], true); |
| 2925 | 2925 | }, |
@@ -2931,17 +2931,17 @@ discard block |
||
| 2931 | 2931 | } |
| 2932 | 2932 | |
| 2933 | 2933 | //register message type metaboxes |
| 2934 | - $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php'; |
|
| 2934 | + $mt_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_meta_box.template.php'; |
|
| 2935 | 2935 | foreach ($mt_boxes as $box => $label) { |
| 2936 | 2936 | $callback_args = array( |
| 2937 | 2937 | 'template_path' => $mt_template_path, |
| 2938 | 2938 | 'template_args' => $mt_template_args[$box] |
| 2939 | 2939 | ); |
| 2940 | - $mt = str_replace('_i_box', '', $box); |
|
| 2940 | + $mt = str_replace('_i_box', '', $box); |
|
| 2941 | 2941 | add_meta_box( |
| 2942 | - 'espresso_' . $mt . '_inactive_mts', |
|
| 2942 | + 'espresso_'.$mt.'_inactive_mts', |
|
| 2943 | 2943 | $label, |
| 2944 | - function ($post, $metabox) { |
|
| 2944 | + function($post, $metabox) { |
|
| 2945 | 2945 | echo EEH_Template::display_template($metabox["args"]["template_path"], |
| 2946 | 2946 | $metabox["args"]["template_args"], true); |
| 2947 | 2947 | }, |
@@ -3043,7 +3043,7 @@ discard block |
||
| 3043 | 3043 | if ($form->is_valid()) { |
| 3044 | 3044 | $valid_data = $form->valid_data(); |
| 3045 | 3045 | foreach ($valid_data as $property => $value) { |
| 3046 | - $setter = 'set_' . $property; |
|
| 3046 | + $setter = 'set_'.$property; |
|
| 3047 | 3047 | if (method_exists($network_config, $setter)) { |
| 3048 | 3048 | $network_config->{$setter}($value); |
| 3049 | 3049 | } else if ( |
@@ -3072,8 +3072,8 @@ discard block |
||
| 3072 | 3072 | */ |
| 3073 | 3073 | protected function _get_mt_tabs($tab_array) |
| 3074 | 3074 | { |
| 3075 | - $tab_array = (array)$tab_array; |
|
| 3076 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3075 | + $tab_array = (array) $tab_array; |
|
| 3076 | + $template = EE_MSG_TEMPLATE_PATH.'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3077 | 3077 | $tabs = ''; |
| 3078 | 3078 | |
| 3079 | 3079 | foreach ($tab_array as $tab) { |
@@ -3106,9 +3106,9 @@ discard block |
||
| 3106 | 3106 | $existing_settings = $messenger->get_existing_admin_settings(); |
| 3107 | 3107 | |
| 3108 | 3108 | foreach ($fields as $fldname => $fldprops) { |
| 3109 | - $field_id = $messenger->name . '-' . $fldname; |
|
| 3109 | + $field_id = $messenger->name.'-'.$fldname; |
|
| 3110 | 3110 | $template_form_field[$field_id] = array( |
| 3111 | - 'name' => 'messenger_settings[' . $field_id . ']', |
|
| 3111 | + 'name' => 'messenger_settings['.$field_id.']', |
|
| 3112 | 3112 | 'label' => $fldprops['label'], |
| 3113 | 3113 | 'input' => $fldprops['field_type'], |
| 3114 | 3114 | 'type' => $fldprops['value_type'], |
@@ -3143,7 +3143,7 @@ discard block |
||
| 3143 | 3143 | //make sure any active message types that are existing are included in the hidden fields |
| 3144 | 3144 | if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) { |
| 3145 | 3145 | foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) { |
| 3146 | - $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array( |
|
| 3146 | + $settings_template_args['hidden_fields']['messenger_settings[message_types]['.$mt.']'] = array( |
|
| 3147 | 3147 | 'type' => 'hidden', |
| 3148 | 3148 | 'value' => $mt |
| 3149 | 3149 | ); |
@@ -3153,7 +3153,7 @@ discard block |
||
| 3153 | 3153 | $settings_template_args['hidden_fields'], |
| 3154 | 3154 | 'array' |
| 3155 | 3155 | ); |
| 3156 | - $active = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3156 | + $active = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3157 | 3157 | |
| 3158 | 3158 | $settings_template_args['messenger'] = $messenger->name; |
| 3159 | 3159 | $settings_template_args['description'] = $messenger->description; |
@@ -3170,9 +3170,9 @@ discard block |
||
| 3170 | 3170 | |
| 3171 | 3171 | |
| 3172 | 3172 | $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on'; |
| 3173 | - $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); |
|
| 3173 | + $settings_template_args['nonce'] = wp_create_nonce('activate_'.$messenger->name.'_toggle_nonce'); |
|
| 3174 | 3174 | $settings_template_args['on_off_status'] = $active ? true : false; |
| 3175 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php'; |
|
| 3175 | + $template = EE_MSG_TEMPLATE_PATH.'ee_msg_m_settings_content.template.php'; |
|
| 3176 | 3176 | $content = EEH_Template::display_template($template, $settings_template_args, |
| 3177 | 3177 | true); |
| 3178 | 3178 | |
@@ -3200,7 +3200,7 @@ discard block |
||
| 3200 | 3200 | |
| 3201 | 3201 | //do a nonce check here since we're not arriving via a normal route |
| 3202 | 3202 | $nonce = isset($this->_req_data['activate_nonce']) ? sanitize_text_field($this->_req_data['activate_nonce']) : ''; |
| 3203 | - $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce'; |
|
| 3203 | + $nonce_ref = 'activate_'.$this->_req_data['messenger'].'_toggle_nonce'; |
|
| 3204 | 3204 | |
| 3205 | 3205 | $this->_verify_nonce($nonce, $nonce_ref); |
| 3206 | 3206 | |
@@ -3302,7 +3302,7 @@ discard block |
||
| 3302 | 3302 | |
| 3303 | 3303 | //do a nonce check here since we're not arriving via a normal route |
| 3304 | 3304 | $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : ''; |
| 3305 | - $nonce_ref = $this->_req_data['message_type'] . '_nonce'; |
|
| 3305 | + $nonce_ref = $this->_req_data['message_type'].'_nonce'; |
|
| 3306 | 3306 | |
| 3307 | 3307 | $this->_verify_nonce($nonce, $nonce_ref); |
| 3308 | 3308 | |
@@ -1421,7 +1421,6 @@ discard block |
||
| 1421 | 1421 | * Makes sure the 3.1's image url is converted to an image attachment post to the 4.1 CPT event |
| 1422 | 1422 | * and sets it as the featured image on the CPT event |
| 1423 | 1423 | * |
| 1424 | - * @param type $old_event |
|
| 1425 | 1424 | * @param type $new_cpt_id |
| 1426 | 1425 | * @param EE_Data_Migration_Script_Stage $migration_stage the stage which called this, where errors should be added |
| 1427 | 1426 | * @return boolean whether or not we had to do the big job of creating an image attachment |
@@ -1483,7 +1482,7 @@ discard block |
||
| 1483 | 1482 | * we download it to our uploads directory so that it can be properly processed (eg, creates different sizes of |
| 1484 | 1483 | * thumbnails) |
| 1485 | 1484 | * |
| 1486 | - * @param type $guid |
|
| 1485 | + * @param string $guid |
|
| 1487 | 1486 | * @param EE_Data_Migration_Script_Stage $migration_stage |
| 1488 | 1487 | * @return int |
| 1489 | 1488 | */ |
@@ -1571,7 +1570,7 @@ discard block |
||
| 1571 | 1570 | * Returns a mysql-formatted DATETIME in UTC time, given a $DATETIME_string |
| 1572 | 1571 | * (and optionally a timezone; if none is given, the wp DEFAULT is used) |
| 1573 | 1572 | * |
| 1574 | - * @param EE_Data_Migration_Script_base $stage |
|
| 1573 | + * @param EE_Data_Migration_Script_Stage $stage |
|
| 1575 | 1574 | * @param array $row_of_data , the row from the DB (as an array) we're trying to find the |
| 1576 | 1575 | * UTC time for |
| 1577 | 1576 | * @param string $DATETIME_string |
@@ -12,11 +12,11 @@ discard block |
||
| 12 | 12 | $stages = glob(EE_CORE . 'data_migration_scripts/4_1_0_stages/*'); |
| 13 | 13 | $class_to_filepath = array(); |
| 14 | 14 | if ( ! empty($stages)) { |
| 15 | - foreach ($stages as $filepath) { |
|
| 16 | - $matches = array(); |
|
| 17 | - preg_match('~4_1_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
| 18 | - $class_to_filepath[$matches[1]] = $filepath; |
|
| 19 | - } |
|
| 15 | + foreach ($stages as $filepath) { |
|
| 16 | + $matches = array(); |
|
| 17 | + preg_match('~4_1_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
| 18 | + $class_to_filepath[$matches[1]] = $filepath; |
|
| 19 | + } |
|
| 20 | 20 | } |
| 21 | 21 | //give addons a chance to autoload their stages too |
| 22 | 22 | $class_to_filepath = apply_filters('FHEE__EE_DMS_4_1_0__autoloaded_stages', $class_to_filepath); |
@@ -44,91 +44,91 @@ discard block |
||
| 44 | 44 | |
| 45 | 45 | |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * EE_DMS_Core_4_1_0 constructor. |
|
| 49 | - * |
|
| 50 | - * @param TableManager $table_manager |
|
| 51 | - * @param TableAnalysis $table_analysis |
|
| 52 | - */ |
|
| 53 | - public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
| 54 | - { |
|
| 55 | - $this->_pretty_name = esc_html__("Data Migration from Event Espresso 3 to Event Espresso 4.1.0", "event_espresso"); |
|
| 56 | - $this->_priority = 10; |
|
| 57 | - $this->_migration_stages = array( |
|
| 58 | - new EE_DMS_4_1_0_org_options(), |
|
| 59 | - new EE_DMS_4_1_0_shortcodes(), |
|
| 60 | - new EE_DMS_4_1_0_gateways(), |
|
| 61 | - new EE_DMS_4_1_0_events(), |
|
| 62 | - new EE_DMS_4_1_0_prices(), |
|
| 63 | - new EE_DMS_4_1_0_category_details(), |
|
| 64 | - new EE_DMS_4_1_0_event_category(), |
|
| 65 | - new EE_DMS_4_1_0_venues(), |
|
| 66 | - new EE_DMS_4_1_0_event_venue(), |
|
| 67 | - new EE_DMS_4_1_0_question_groups(), |
|
| 68 | - new EE_DMS_4_1_0_questions(), |
|
| 69 | - new EE_DMS_4_1_0_question_group_question(), |
|
| 70 | - new EE_DMS_4_1_0_event_question_group(), |
|
| 71 | - new EE_DMS_4_1_0_attendees(), |
|
| 72 | - new EE_DMS_4_1_0_line_items(), |
|
| 73 | - new EE_DMS_4_1_0_answers(), |
|
| 74 | - new EE_DMS_4_1_0_checkins(), |
|
| 75 | - ); |
|
| 76 | - parent::__construct($table_manager, $table_analysis); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Checks if this 3.1 Check-in table exists. If it doesn't we can't migrate Check-ins |
|
| 83 | - * |
|
| 84 | - * @global wpdb $wpdb |
|
| 85 | - * @return boolean |
|
| 86 | - */ |
|
| 87 | - private function _checkin_table_exists() |
|
| 88 | - { |
|
| 89 | - global $wpdb; |
|
| 90 | - $results = $wpdb->get_results("SHOW TABLES LIKE '" . $wpdb->prefix . "events_attendee_checkin" . "'"); |
|
| 91 | - if ($results) { |
|
| 92 | - return true; |
|
| 93 | - } else { |
|
| 94 | - return false; |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - public function can_migrate_from_version($version_array) |
|
| 101 | - { |
|
| 102 | - $version_string = $version_array['Core']; |
|
| 103 | - if (version_compare($version_string, '4.0.0', '<=') && version_compare($version_string, '3.1.26', '>=')) { |
|
| 47 | + /** |
|
| 48 | + * EE_DMS_Core_4_1_0 constructor. |
|
| 49 | + * |
|
| 50 | + * @param TableManager $table_manager |
|
| 51 | + * @param TableAnalysis $table_analysis |
|
| 52 | + */ |
|
| 53 | + public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
| 54 | + { |
|
| 55 | + $this->_pretty_name = esc_html__("Data Migration from Event Espresso 3 to Event Espresso 4.1.0", "event_espresso"); |
|
| 56 | + $this->_priority = 10; |
|
| 57 | + $this->_migration_stages = array( |
|
| 58 | + new EE_DMS_4_1_0_org_options(), |
|
| 59 | + new EE_DMS_4_1_0_shortcodes(), |
|
| 60 | + new EE_DMS_4_1_0_gateways(), |
|
| 61 | + new EE_DMS_4_1_0_events(), |
|
| 62 | + new EE_DMS_4_1_0_prices(), |
|
| 63 | + new EE_DMS_4_1_0_category_details(), |
|
| 64 | + new EE_DMS_4_1_0_event_category(), |
|
| 65 | + new EE_DMS_4_1_0_venues(), |
|
| 66 | + new EE_DMS_4_1_0_event_venue(), |
|
| 67 | + new EE_DMS_4_1_0_question_groups(), |
|
| 68 | + new EE_DMS_4_1_0_questions(), |
|
| 69 | + new EE_DMS_4_1_0_question_group_question(), |
|
| 70 | + new EE_DMS_4_1_0_event_question_group(), |
|
| 71 | + new EE_DMS_4_1_0_attendees(), |
|
| 72 | + new EE_DMS_4_1_0_line_items(), |
|
| 73 | + new EE_DMS_4_1_0_answers(), |
|
| 74 | + new EE_DMS_4_1_0_checkins(), |
|
| 75 | + ); |
|
| 76 | + parent::__construct($table_manager, $table_analysis); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Checks if this 3.1 Check-in table exists. If it doesn't we can't migrate Check-ins |
|
| 83 | + * |
|
| 84 | + * @global wpdb $wpdb |
|
| 85 | + * @return boolean |
|
| 86 | + */ |
|
| 87 | + private function _checkin_table_exists() |
|
| 88 | + { |
|
| 89 | + global $wpdb; |
|
| 90 | + $results = $wpdb->get_results("SHOW TABLES LIKE '" . $wpdb->prefix . "events_attendee_checkin" . "'"); |
|
| 91 | + if ($results) { |
|
| 92 | + return true; |
|
| 93 | + } else { |
|
| 94 | + return false; |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + public function can_migrate_from_version($version_array) |
|
| 101 | + { |
|
| 102 | + $version_string = $version_array['Core']; |
|
| 103 | + if (version_compare($version_string, '4.0.0', '<=') && version_compare($version_string, '3.1.26', '>=')) { |
|
| 104 | 104 | // echo "$version_string can be migrated fro"; |
| 105 | - return true; |
|
| 106 | - } elseif ( ! $version_string) { |
|
| 105 | + return true; |
|
| 106 | + } elseif ( ! $version_string) { |
|
| 107 | 107 | // echo "no version string provided: $version_string"; |
| 108 | - //no version string provided... this must be pre 4.1 |
|
| 109 | - //because since 4.1 we're |
|
| 110 | - return false;//changed mind. dont want people thinking they should migrate yet because they cant |
|
| 111 | - } else { |
|
| 108 | + //no version string provided... this must be pre 4.1 |
|
| 109 | + //because since 4.1 we're |
|
| 110 | + return false;//changed mind. dont want people thinking they should migrate yet because they cant |
|
| 111 | + } else { |
|
| 112 | 112 | // echo "$version_string doesnt apply"; |
| 113 | - return false; |
|
| 114 | - } |
|
| 115 | - } |
|
| 113 | + return false; |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | 117 | |
| 118 | 118 | |
| 119 | - public function schema_changes_before_migration() |
|
| 120 | - { |
|
| 121 | - //relies on 4.1's EEH_Activation::create_table |
|
| 122 | - require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
| 123 | - $table_name = 'esp_answer'; |
|
| 124 | - $sql = " ANS_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 119 | + public function schema_changes_before_migration() |
|
| 120 | + { |
|
| 121 | + //relies on 4.1's EEH_Activation::create_table |
|
| 122 | + require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
| 123 | + $table_name = 'esp_answer'; |
|
| 124 | + $sql = " ANS_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 125 | 125 | REG_ID INT UNSIGNED NOT NULL, |
| 126 | 126 | QST_ID INT UNSIGNED NOT NULL, |
| 127 | 127 | ANS_value TEXT NOT NULL, |
| 128 | 128 | PRIMARY KEY (ANS_ID)"; |
| 129 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 130 | - $table_name = 'esp_attendee_meta'; |
|
| 131 | - $sql = "ATTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 129 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 130 | + $table_name = 'esp_attendee_meta'; |
|
| 131 | + $sql = "ATTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 132 | 132 | ATT_ID BIGINT(20) UNSIGNED NOT NULL, |
| 133 | 133 | ATT_fname VARCHAR(45) NOT NULL, |
| 134 | 134 | ATT_lname VARCHAR(45) NOT NULL, |
@@ -144,9 +144,9 @@ discard block |
||
| 144 | 144 | KEY ATT_fname (ATT_fname), |
| 145 | 145 | KEY ATT_lname (ATT_lname), |
| 146 | 146 | KEY ATT_email (ATT_email)"; |
| 147 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 148 | - $table_name = 'esp_country'; |
|
| 149 | - $sql = "CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL, |
|
| 147 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 148 | + $table_name = 'esp_country'; |
|
| 149 | + $sql = "CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL, |
|
| 150 | 150 | CNT_ISO3 VARCHAR(3) COLLATE utf8_bin NOT NULL, |
| 151 | 151 | RGN_ID TINYINT(3) UNSIGNED DEFAULT NULL, |
| 152 | 152 | CNT_name VARCHAR(45) COLLATE utf8_bin NOT NULL, |
@@ -162,9 +162,9 @@ discard block |
||
| 162 | 162 | CNT_is_EU TINYINT(1) DEFAULT '0', |
| 163 | 163 | CNT_active TINYINT(1) DEFAULT '0', |
| 164 | 164 | PRIMARY KEY (CNT_ISO)"; |
| 165 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 166 | - $table_name = 'esp_datetime'; |
|
| 167 | - $sql = "DTT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 165 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 166 | + $table_name = 'esp_datetime'; |
|
| 167 | + $sql = "DTT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 168 | 168 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
| 169 | 169 | DTT_EVT_start DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', |
| 170 | 170 | DTT_EVT_end DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', |
@@ -177,9 +177,9 @@ discard block |
||
| 177 | 177 | PRIMARY KEY (DTT_ID), |
| 178 | 178 | KEY EVT_ID (EVT_ID), |
| 179 | 179 | KEY DTT_is_primary (DTT_is_primary)"; |
| 180 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 181 | - $table_name = 'esp_event_meta'; |
|
| 182 | - $sql = " |
|
| 180 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 181 | + $table_name = 'esp_event_meta'; |
|
| 182 | + $sql = " |
|
| 183 | 183 | EVTM_ID INT NOT NULL AUTO_INCREMENT, |
| 184 | 184 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
| 185 | 185 | EVT_display_desc TINYINT(1) UNSIGNED NOT NULL DEFAULT 1, |
@@ -194,31 +194,31 @@ discard block |
||
| 194 | 194 | EVT_external_URL VARCHAR(200) NULL, |
| 195 | 195 | EVT_donations TINYINT(1) NULL, |
| 196 | 196 | PRIMARY KEY (EVTM_ID)"; |
| 197 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 198 | - $table_name = 'esp_event_question_group'; |
|
| 199 | - $sql = "EQG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 197 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 198 | + $table_name = 'esp_event_question_group'; |
|
| 199 | + $sql = "EQG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 200 | 200 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
| 201 | 201 | QSG_ID INT UNSIGNED NOT NULL, |
| 202 | 202 | EQG_primary TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, |
| 203 | 203 | PRIMARY KEY (EQG_ID)"; |
| 204 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 205 | - $table_name = 'esp_event_venue'; |
|
| 206 | - $sql = "EVV_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
| 204 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 205 | + $table_name = 'esp_event_venue'; |
|
| 206 | + $sql = "EVV_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
| 207 | 207 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
| 208 | 208 | VNU_ID BIGINT(20) UNSIGNED NOT NULL, |
| 209 | 209 | EVV_primary TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, |
| 210 | 210 | PRIMARY KEY (EVV_ID)"; |
| 211 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 212 | - $table_name = 'esp_extra_meta'; |
|
| 213 | - $sql = "EXM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
| 211 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 212 | + $table_name = 'esp_extra_meta'; |
|
| 213 | + $sql = "EXM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
| 214 | 214 | OBJ_ID INT(11) DEFAULT NULL, |
| 215 | 215 | EXM_type VARCHAR(45) DEFAULT NULL, |
| 216 | 216 | EXM_key VARCHAR(45) DEFAULT NULL, |
| 217 | 217 | EXM_value TEXT, |
| 218 | 218 | PRIMARY KEY (EXM_ID)"; |
| 219 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 220 | - $table_name = 'esp_line_item'; |
|
| 221 | - $sql = "LIN_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
| 219 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 220 | + $table_name = 'esp_line_item'; |
|
| 221 | + $sql = "LIN_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
| 222 | 222 | LIN_code VARCHAR(245) NOT NULL DEFAULT '', |
| 223 | 223 | TXN_ID INT(11) DEFAULT NULL, |
| 224 | 224 | LIN_name VARCHAR(245) NOT NULL DEFAULT '', |
@@ -234,18 +234,18 @@ discard block |
||
| 234 | 234 | OBJ_ID INT(11) DEFAULT NULL, |
| 235 | 235 | OBJ_type VARCHAR(45)DEFAULT NULL, |
| 236 | 236 | PRIMARY KEY (LIN_ID)"; |
| 237 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 238 | - $table_name = 'esp_message_template'; |
|
| 239 | - $sql = "MTP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 237 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 238 | + $table_name = 'esp_message_template'; |
|
| 239 | + $sql = "MTP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 240 | 240 | GRP_ID INT(10) UNSIGNED NOT NULL, |
| 241 | 241 | MTP_context VARCHAR(50) NOT NULL, |
| 242 | 242 | MTP_template_field VARCHAR(30) NOT NULL, |
| 243 | 243 | MTP_content TEXT NOT NULL, |
| 244 | 244 | PRIMARY KEY (MTP_ID), |
| 245 | 245 | KEY GRP_ID (GRP_ID)"; |
| 246 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 247 | - $table_name = 'esp_message_template_group'; |
|
| 248 | - $sql = "GRP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 246 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 247 | + $table_name = 'esp_message_template_group'; |
|
| 248 | + $sql = "GRP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 249 | 249 | EVT_ID BIGINT(20) UNSIGNED DEFAULT NULL, |
| 250 | 250 | MTP_user_id INT(10) NOT NULL DEFAULT '1', |
| 251 | 251 | MTP_messenger VARCHAR(30) NOT NULL, |
@@ -257,9 +257,9 @@ discard block |
||
| 257 | 257 | PRIMARY KEY (GRP_ID), |
| 258 | 258 | KEY EVT_ID (EVT_ID), |
| 259 | 259 | KEY MTP_user_id (MTP_user_id)"; |
| 260 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 261 | - $table_name = 'esp_payment'; |
|
| 262 | - $sql = "PAY_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 260 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 261 | + $table_name = 'esp_payment'; |
|
| 262 | + $sql = "PAY_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 263 | 263 | TXN_ID INT(10) UNSIGNED DEFAULT NULL, |
| 264 | 264 | STS_ID VARCHAR(3) COLLATE utf8_bin DEFAULT NULL, |
| 265 | 265 | PAY_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', |
@@ -275,9 +275,9 @@ discard block |
||
| 275 | 275 | PRIMARY KEY (PAY_ID), |
| 276 | 276 | KEY TXN_ID (TXN_ID), |
| 277 | 277 | KEY PAY_timestamp (PAY_timestamp)"; |
| 278 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 279 | - $table_name = "esp_ticket"; |
|
| 280 | - $sql = "TKT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 278 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 279 | + $table_name = "esp_ticket"; |
|
| 280 | + $sql = "TKT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 281 | 281 | TTM_ID INT(10) UNSIGNED NOT NULL, |
| 282 | 282 | TKT_name VARCHAR(245) NOT NULL DEFAULT '', |
| 283 | 283 | TKT_description TEXT NOT NULL, |
@@ -296,28 +296,28 @@ discard block |
||
| 296 | 296 | TKT_parent INT(10) UNSIGNED DEFAULT '0', |
| 297 | 297 | TKT_deleted TINYINT(1) NOT NULL DEFAULT '0', |
| 298 | 298 | PRIMARY KEY (TKT_ID)"; |
| 299 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 300 | - $table_name = "esp_ticket_price"; |
|
| 301 | - $sql = "TKP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 299 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 300 | + $table_name = "esp_ticket_price"; |
|
| 301 | + $sql = "TKP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 302 | 302 | TKT_ID INT(10) UNSIGNED NOT NULL, |
| 303 | 303 | PRC_ID INT(10) UNSIGNED NOT NULL, |
| 304 | 304 | PRIMARY KEY (TKP_ID)"; |
| 305 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 306 | - $table_name = "esp_datetime_ticket"; |
|
| 307 | - $sql = "DTK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 305 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 306 | + $table_name = "esp_datetime_ticket"; |
|
| 307 | + $sql = "DTK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 308 | 308 | DTT_ID INT(10) UNSIGNED NOT NULL, |
| 309 | 309 | TKT_ID INT(10) UNSIGNED NOT NULL, |
| 310 | 310 | PRIMARY KEY (DTK_ID)"; |
| 311 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 312 | - $table_name = "esp_ticket_template"; |
|
| 313 | - $sql = "TTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 311 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 312 | + $table_name = "esp_ticket_template"; |
|
| 313 | + $sql = "TTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 314 | 314 | TTM_name VARCHAR(45) NOT NULL, |
| 315 | 315 | TTM_description TEXT, |
| 316 | 316 | TTM_file VARCHAR(45), |
| 317 | 317 | PRIMARY KEY (TTM_ID)"; |
| 318 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 319 | - $table_name = "esp_price"; |
|
| 320 | - $sql = "PRC_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 318 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 319 | + $table_name = "esp_price"; |
|
| 320 | + $sql = "PRC_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 321 | 321 | PRT_ID TINYINT(3) UNSIGNED NOT NULL, |
| 322 | 322 | PRC_amount DECIMAL(10,3) NOT NULL DEFAULT '0.00', |
| 323 | 323 | PRC_name VARCHAR(245) NOT NULL, |
@@ -328,9 +328,9 @@ discard block |
||
| 328 | 328 | PRC_order TINYINT(3) UNSIGNED NOT NULL DEFAULT '0', |
| 329 | 329 | PRC_parent INT(10) UNSIGNED DEFAULT 0, |
| 330 | 330 | PRIMARY KEY (PRC_ID)"; |
| 331 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 332 | - $table_name = "esp_price_type"; |
|
| 333 | - $sql = "PRT_ID TINYINT(3) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 331 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 332 | + $table_name = "esp_price_type"; |
|
| 333 | + $sql = "PRT_ID TINYINT(3) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 334 | 334 | PRT_name VARCHAR(45) NOT NULL, |
| 335 | 335 | PBT_ID TINYINT(3) UNSIGNED NOT NULL DEFAULT '1', |
| 336 | 336 | PRT_is_percent TINYINT(1) NOT NULL DEFAULT '0', |
@@ -338,9 +338,9 @@ discard block |
||
| 338 | 338 | PRT_deleted TINYINT(1) NOT NULL DEFAULT '0', |
| 339 | 339 | UNIQUE KEY PRT_name_UNIQUE (PRT_name), |
| 340 | 340 | PRIMARY KEY (PRT_ID)"; |
| 341 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 342 | - $table_name = 'esp_question'; |
|
| 343 | - $sql = 'QST_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 341 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 342 | + $table_name = 'esp_question'; |
|
| 343 | + $sql = 'QST_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 344 | 344 | QST_display_text TEXT NOT NULL, |
| 345 | 345 | QST_admin_label VARCHAR(255) NOT NULL, |
| 346 | 346 | QST_system VARCHAR(25) DEFAULT NULL, |
@@ -352,10 +352,10 @@ discard block |
||
| 352 | 352 | QST_wp_user BIGINT UNSIGNED NULL, |
| 353 | 353 | QST_deleted TINYINT UNSIGNED NOT NULL DEFAULT 0, |
| 354 | 354 | PRIMARY KEY (QST_ID)'; |
| 355 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 356 | - $this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_identifier_UNIQUE'); |
|
| 357 | - $table_name = 'esp_question_group'; |
|
| 358 | - $sql = 'QSG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 355 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 356 | + $this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_identifier_UNIQUE'); |
|
| 357 | + $table_name = 'esp_question_group'; |
|
| 358 | + $sql = 'QSG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 359 | 359 | QSG_name VARCHAR(255) NOT NULL, |
| 360 | 360 | QSG_identifier VARCHAR(100) NOT NULL, |
| 361 | 361 | QSG_desc TEXT NULL, |
@@ -366,23 +366,23 @@ discard block |
||
| 366 | 366 | QSG_deleted TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, |
| 367 | 367 | PRIMARY KEY (QSG_ID), |
| 368 | 368 | UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier ASC)'; |
| 369 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 370 | - $table_name = 'esp_question_group_question'; |
|
| 371 | - $sql = "QGQ_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 369 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 370 | + $table_name = 'esp_question_group_question'; |
|
| 371 | + $sql = "QGQ_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 372 | 372 | QSG_ID INT UNSIGNED NOT NULL, |
| 373 | 373 | QST_ID INT UNSIGNED NOT NULL, |
| 374 | 374 | PRIMARY KEY (QGQ_ID) "; |
| 375 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 376 | - $table_name = 'esp_question_option'; |
|
| 377 | - $sql = "QSO_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 375 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 376 | + $table_name = 'esp_question_option'; |
|
| 377 | + $sql = "QSO_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 378 | 378 | QSO_value VARCHAR(255) NOT NULL, |
| 379 | 379 | QSO_desc TEXT NOT NULL, |
| 380 | 380 | QST_ID INT UNSIGNED NOT NULL, |
| 381 | 381 | QSO_deleted TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, |
| 382 | 382 | PRIMARY KEY (QSO_ID)"; |
| 383 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 384 | - $table_name = 'esp_registration'; |
|
| 385 | - $sql = "REG_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 383 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 384 | + $table_name = 'esp_registration'; |
|
| 385 | + $sql = "REG_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 386 | 386 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
| 387 | 387 | ATT_ID BIGINT(20) UNSIGNED NOT NULL, |
| 388 | 388 | TXN_ID INT(10) UNSIGNED NOT NULL, |
@@ -405,25 +405,25 @@ discard block |
||
| 405 | 405 | KEY STS_ID (STS_ID), |
| 406 | 406 | KEY REG_url_link (REG_url_link), |
| 407 | 407 | KEY REG_code (REG_code)"; |
| 408 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 409 | - $table_name = 'esp_checkin'; |
|
| 410 | - $sql = "CHK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 408 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 409 | + $table_name = 'esp_checkin'; |
|
| 410 | + $sql = "CHK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 411 | 411 | REG_ID INT(10) UNSIGNED NOT NULL, |
| 412 | 412 | DTT_ID INT(10) UNSIGNED NOT NULL, |
| 413 | 413 | CHK_in TINYINT(1) UNSIGNED NOT NULL DEFAULT 1, |
| 414 | 414 | CHK_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', |
| 415 | 415 | PRIMARY KEY (CHK_ID)"; |
| 416 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 417 | - $table_name = 'esp_state'; |
|
| 418 | - $sql = "STA_ID smallint(5) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 416 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 417 | + $table_name = 'esp_state'; |
|
| 418 | + $sql = "STA_ID smallint(5) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 419 | 419 | CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL, |
| 420 | 420 | STA_abbrev VARCHAR(6) COLLATE utf8_bin NOT NULL, |
| 421 | 421 | STA_name VARCHAR(100) COLLATE utf8_bin NOT NULL, |
| 422 | 422 | STA_active TINYINT(1) DEFAULT '1', |
| 423 | 423 | PRIMARY KEY (STA_ID)"; |
| 424 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 425 | - $table_name = 'esp_status'; |
|
| 426 | - $sql = "STS_ID VARCHAR(3) COLLATE utf8_bin NOT NULL, |
|
| 424 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 425 | + $table_name = 'esp_status'; |
|
| 426 | + $sql = "STS_ID VARCHAR(3) COLLATE utf8_bin NOT NULL, |
|
| 427 | 427 | STS_code VARCHAR(45) COLLATE utf8_bin NOT NULL, |
| 428 | 428 | STS_type set('event','registration','transaction','payment','email') COLLATE utf8_bin NOT NULL, |
| 429 | 429 | STS_can_edit TINYINT(1) NOT NULL DEFAULT 0, |
@@ -431,9 +431,9 @@ discard block |
||
| 431 | 431 | STS_open TINYINT(1) NOT NULL DEFAULT 1, |
| 432 | 432 | UNIQUE KEY STS_ID_UNIQUE (STS_ID), |
| 433 | 433 | KEY STS_type (STS_type)"; |
| 434 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 435 | - $table_name = 'esp_transaction'; |
|
| 436 | - $sql = "TXN_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 434 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 435 | + $table_name = 'esp_transaction'; |
|
| 436 | + $sql = "TXN_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 437 | 437 | TXN_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', |
| 438 | 438 | TXN_total DECIMAL(10,3) DEFAULT '0.00', |
| 439 | 439 | TXN_paid DECIMAL(10,3) NOT NULL DEFAULT '0.00', |
@@ -443,9 +443,9 @@ discard block |
||
| 443 | 443 | PRIMARY KEY (TXN_ID), |
| 444 | 444 | KEY TXN_timestamp (TXN_timestamp), |
| 445 | 445 | KEY STS_ID (STS_ID)"; |
| 446 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 447 | - $table_name = 'esp_venue_meta'; |
|
| 448 | - $sql = "VNUM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
| 446 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 447 | + $table_name = 'esp_venue_meta'; |
|
| 448 | + $sql = "VNUM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
| 449 | 449 | VNU_ID BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, |
| 450 | 450 | VNU_address VARCHAR(255) DEFAULT NULL, |
| 451 | 451 | VNU_address2 VARCHAR(255) DEFAULT NULL, |
@@ -463,52 +463,52 @@ discard block |
||
| 463 | 463 | PRIMARY KEY (VNUM_ID), |
| 464 | 464 | KEY STA_ID (STA_ID), |
| 465 | 465 | KEY CNT_ISO (CNT_ISO)"; |
| 466 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 467 | - //setting up the DEFAULT stats and countries is also essential for the data migrations to run |
|
| 468 | - //(because many need to convert old string states to foreign keys into the states table) |
|
| 469 | - $this->insert_default_states(); |
|
| 470 | - $this->insert_default_countries(); |
|
| 471 | - //setting up DEFAULT prices, price types, and tickets is also essential for the price migrations |
|
| 472 | - $this->insert_default_price_types(); |
|
| 473 | - $this->insert_default_prices(); |
|
| 474 | - $this->insert_default_tickets(); |
|
| 475 | - //setting up the config wp option pretty well counts as a 'schema change', or at least should happen ehre |
|
| 476 | - EE_Config::instance()->update_espresso_config(false, true); |
|
| 477 | - return true; |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * Yes we could have cleaned up the ee3 tables here. But just in case someone |
|
| 484 | - * didn't backup their DB, and decides they want ot keep using EE3, we'll |
|
| 485 | - * leave them for now. Mayeb remove them in 4.5 or something. |
|
| 486 | - * |
|
| 487 | - * @return boolean |
|
| 488 | - */ |
|
| 489 | - public function schema_changes_after_migration() |
|
| 490 | - { |
|
| 491 | - return true; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - |
|
| 495 | - |
|
| 496 | - /** |
|
| 497 | - * insert_default_states |
|
| 498 | - * |
|
| 499 | - * @access public |
|
| 500 | - * @static |
|
| 501 | - * @return void |
|
| 502 | - */ |
|
| 503 | - public function insert_default_states() |
|
| 504 | - { |
|
| 505 | - global $wpdb; |
|
| 506 | - $state_table = $wpdb->prefix . "esp_state"; |
|
| 507 | - if ($this->_get_table_analysis()->tableExists($state_table)) { |
|
| 508 | - $SQL = "SELECT COUNT('STA_ID') FROM " . $state_table; |
|
| 509 | - $states = $wpdb->get_var($SQL); |
|
| 510 | - if ( ! $states) { |
|
| 511 | - $SQL = "INSERT INTO " . $state_table . " |
|
| 466 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 467 | + //setting up the DEFAULT stats and countries is also essential for the data migrations to run |
|
| 468 | + //(because many need to convert old string states to foreign keys into the states table) |
|
| 469 | + $this->insert_default_states(); |
|
| 470 | + $this->insert_default_countries(); |
|
| 471 | + //setting up DEFAULT prices, price types, and tickets is also essential for the price migrations |
|
| 472 | + $this->insert_default_price_types(); |
|
| 473 | + $this->insert_default_prices(); |
|
| 474 | + $this->insert_default_tickets(); |
|
| 475 | + //setting up the config wp option pretty well counts as a 'schema change', or at least should happen ehre |
|
| 476 | + EE_Config::instance()->update_espresso_config(false, true); |
|
| 477 | + return true; |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * Yes we could have cleaned up the ee3 tables here. But just in case someone |
|
| 484 | + * didn't backup their DB, and decides they want ot keep using EE3, we'll |
|
| 485 | + * leave them for now. Mayeb remove them in 4.5 or something. |
|
| 486 | + * |
|
| 487 | + * @return boolean |
|
| 488 | + */ |
|
| 489 | + public function schema_changes_after_migration() |
|
| 490 | + { |
|
| 491 | + return true; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + |
|
| 495 | + |
|
| 496 | + /** |
|
| 497 | + * insert_default_states |
|
| 498 | + * |
|
| 499 | + * @access public |
|
| 500 | + * @static |
|
| 501 | + * @return void |
|
| 502 | + */ |
|
| 503 | + public function insert_default_states() |
|
| 504 | + { |
|
| 505 | + global $wpdb; |
|
| 506 | + $state_table = $wpdb->prefix . "esp_state"; |
|
| 507 | + if ($this->_get_table_analysis()->tableExists($state_table)) { |
|
| 508 | + $SQL = "SELECT COUNT('STA_ID') FROM " . $state_table; |
|
| 509 | + $states = $wpdb->get_var($SQL); |
|
| 510 | + if ( ! $states) { |
|
| 511 | + $SQL = "INSERT INTO " . $state_table . " |
|
| 512 | 512 | (STA_ID, CNT_ISO, STA_abbrev, STA_name, STA_active) VALUES |
| 513 | 513 | (1, 'US', 'AK', 'Alaska', 1), |
| 514 | 514 | (2, 'US', 'AL', 'Alabama', 1), |
@@ -579,29 +579,29 @@ discard block |
||
| 579 | 579 | (67, 'CA', 'PE', 'Prince Edward Island', 1), |
| 580 | 580 | (68, 'CA', 'QC', 'Quebec', 1), |
| 581 | 581 | (69, 'CA', 'SK', 'Saskatchewan', 1);"; |
| 582 | - $wpdb->query($SQL); |
|
| 583 | - } |
|
| 584 | - } |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - |
|
| 588 | - |
|
| 589 | - /** |
|
| 590 | - * insert_default_countries |
|
| 591 | - * |
|
| 592 | - * @access public |
|
| 593 | - * @static |
|
| 594 | - * @return void |
|
| 595 | - */ |
|
| 596 | - public function insert_default_countries() |
|
| 597 | - { |
|
| 598 | - global $wpdb; |
|
| 599 | - $country_table = $wpdb->prefix . "esp_country"; |
|
| 600 | - if ($this->_get_table_analysis()->tableExists($country_table)) { |
|
| 601 | - $SQL = "SELECT COUNT('CNT_ISO') FROM " . $country_table; |
|
| 602 | - $countries = $wpdb->get_var($SQL); |
|
| 603 | - if ( ! $countries) { |
|
| 604 | - $SQL = "INSERT INTO " . $country_table . " |
|
| 582 | + $wpdb->query($SQL); |
|
| 583 | + } |
|
| 584 | + } |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + |
|
| 588 | + |
|
| 589 | + /** |
|
| 590 | + * insert_default_countries |
|
| 591 | + * |
|
| 592 | + * @access public |
|
| 593 | + * @static |
|
| 594 | + * @return void |
|
| 595 | + */ |
|
| 596 | + public function insert_default_countries() |
|
| 597 | + { |
|
| 598 | + global $wpdb; |
|
| 599 | + $country_table = $wpdb->prefix . "esp_country"; |
|
| 600 | + if ($this->_get_table_analysis()->tableExists($country_table)) { |
|
| 601 | + $SQL = "SELECT COUNT('CNT_ISO') FROM " . $country_table; |
|
| 602 | + $countries = $wpdb->get_var($SQL); |
|
| 603 | + if ( ! $countries) { |
|
| 604 | + $SQL = "INSERT INTO " . $country_table . " |
|
| 605 | 605 | (CNT_ISO, CNT_ISO3, RGN_ID, CNT_name, CNT_cur_code, CNT_cur_single, CNT_cur_plural, CNT_cur_sign, CNT_cur_sign_b4, CNT_cur_dec_plc, CNT_tel_code, CNT_is_EU, CNT_active) VALUES |
| 606 | 606 | ('AD', 'AND', 0, 'Andorra', 'EUR', 'Euro', 'Euros', '€', 1, 2, '+376', 0, 0), |
| 607 | 607 | ('AE', 'ARE', 0, 'United Arab Emirates', 'AED', 'Dirham', 'Dirhams', 'د.إ', 1, 2, '+971', 0, 0), |
@@ -829,941 +829,941 @@ discard block |
||
| 829 | 829 | ('ZA', 'ZAF', 0, 'South Africa', 'ZAR', 'Rand', 'Rands', 'R', 1, 2, '+27', 0, 0), |
| 830 | 830 | ('ZM', 'ZMB', 0, 'Zambia', 'ZMK', 'Kwacha', 'Kwachas', '', 1, 2, '+260', 0, 0), |
| 831 | 831 | ('ZW', 'ZWE', 0, 'Zimbabwe', 'ZWD', 'Dollar', 'Dollars', 'Z$', 1, 2, '+263', 0, 0);"; |
| 832 | - $wpdb->query($SQL); |
|
| 833 | - } |
|
| 834 | - } |
|
| 835 | - } |
|
| 836 | - |
|
| 837 | - |
|
| 838 | - |
|
| 839 | - /** |
|
| 840 | - * insert_default_price_types |
|
| 841 | - * |
|
| 842 | - * @access public |
|
| 843 | - * @static |
|
| 844 | - * @return void |
|
| 845 | - */ |
|
| 846 | - public function insert_default_price_types() |
|
| 847 | - { |
|
| 848 | - global $wpdb; |
|
| 849 | - $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
| 850 | - if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
|
| 851 | - $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table; |
|
| 852 | - $price_types_exist = $wpdb->get_var($SQL); |
|
| 853 | - if ( ! $price_types_exist) { |
|
| 854 | - $SQL = "INSERT INTO $price_type_table ( PRT_ID, PRT_name, PBT_ID, PRT_is_percent, PRT_order, PRT_deleted ) VALUES |
|
| 832 | + $wpdb->query($SQL); |
|
| 833 | + } |
|
| 834 | + } |
|
| 835 | + } |
|
| 836 | + |
|
| 837 | + |
|
| 838 | + |
|
| 839 | + /** |
|
| 840 | + * insert_default_price_types |
|
| 841 | + * |
|
| 842 | + * @access public |
|
| 843 | + * @static |
|
| 844 | + * @return void |
|
| 845 | + */ |
|
| 846 | + public function insert_default_price_types() |
|
| 847 | + { |
|
| 848 | + global $wpdb; |
|
| 849 | + $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
| 850 | + if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
|
| 851 | + $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table; |
|
| 852 | + $price_types_exist = $wpdb->get_var($SQL); |
|
| 853 | + if ( ! $price_types_exist) { |
|
| 854 | + $SQL = "INSERT INTO $price_type_table ( PRT_ID, PRT_name, PBT_ID, PRT_is_percent, PRT_order, PRT_deleted ) VALUES |
|
| 855 | 855 | (1, '" . esc_html__('Base Price', 'event_espresso') . "', 1, 0, 0, 0), |
| 856 | 856 | (2, '" . esc_html__('Percent Discount', 'event_espresso') . "', 2, 1, 20, 0), |
| 857 | 857 | (3, '" . esc_html__('Fixed Discount', 'event_espresso') . "', 2, 0, 30, 0), |
| 858 | 858 | (4, '" . esc_html__('Percent Surcharge', 'event_espresso') . "', 3, 1, 40, 0), |
| 859 | 859 | (5, '" . esc_html__('Fixed Surcharge', 'event_espresso') . "', 3, 0, 50, 0);"; |
| 860 | - $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_price_types__SQL', $SQL); |
|
| 861 | - $wpdb->query($SQL); |
|
| 862 | - } |
|
| 863 | - } |
|
| 864 | - } |
|
| 865 | - |
|
| 866 | - |
|
| 867 | - |
|
| 868 | - /** |
|
| 869 | - * insert_default_prices. We assume we're upgrading to regular here. |
|
| 870 | - * If we're INSTALLING 4.1 CAF, then we add a few extra DEFAULT prices |
|
| 871 | - * when EEH_Activaion's initialize_db_content is called via ahook in |
|
| 872 | - * EE_BRewing_regular |
|
| 873 | - * |
|
| 874 | - * @access public |
|
| 875 | - * @static |
|
| 876 | - * @return void |
|
| 877 | - */ |
|
| 878 | - public function insert_default_prices() |
|
| 879 | - { |
|
| 880 | - global $wpdb; |
|
| 881 | - $price_table = $wpdb->prefix . "esp_price"; |
|
| 882 | - if ($this->_get_table_analysis()->tableExists($price_table)) { |
|
| 883 | - $SQL = 'SELECT COUNT(PRC_ID) FROM ' . $price_table; |
|
| 884 | - $prices_exist = $wpdb->get_var($SQL); |
|
| 885 | - if ( ! $prices_exist) { |
|
| 886 | - $SQL = "INSERT INTO $price_table |
|
| 860 | + $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_price_types__SQL', $SQL); |
|
| 861 | + $wpdb->query($SQL); |
|
| 862 | + } |
|
| 863 | + } |
|
| 864 | + } |
|
| 865 | + |
|
| 866 | + |
|
| 867 | + |
|
| 868 | + /** |
|
| 869 | + * insert_default_prices. We assume we're upgrading to regular here. |
|
| 870 | + * If we're INSTALLING 4.1 CAF, then we add a few extra DEFAULT prices |
|
| 871 | + * when EEH_Activaion's initialize_db_content is called via ahook in |
|
| 872 | + * EE_BRewing_regular |
|
| 873 | + * |
|
| 874 | + * @access public |
|
| 875 | + * @static |
|
| 876 | + * @return void |
|
| 877 | + */ |
|
| 878 | + public function insert_default_prices() |
|
| 879 | + { |
|
| 880 | + global $wpdb; |
|
| 881 | + $price_table = $wpdb->prefix . "esp_price"; |
|
| 882 | + if ($this->_get_table_analysis()->tableExists($price_table)) { |
|
| 883 | + $SQL = 'SELECT COUNT(PRC_ID) FROM ' . $price_table; |
|
| 884 | + $prices_exist = $wpdb->get_var($SQL); |
|
| 885 | + if ( ! $prices_exist) { |
|
| 886 | + $SQL = "INSERT INTO $price_table |
|
| 887 | 887 | (PRC_ID, PRT_ID, PRC_amount, PRC_name, PRC_desc, PRC_is_default, PRC_overrides, PRC_order, PRC_deleted, PRC_parent ) VALUES |
| 888 | 888 | (1, 1, '0.00', 'Free Admission', '', 1, NULL, 0, 0, 0);"; |
| 889 | - $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_prices__SQL', $SQL); |
|
| 890 | - $wpdb->query($SQL); |
|
| 891 | - } |
|
| 892 | - } |
|
| 893 | - } |
|
| 894 | - |
|
| 895 | - |
|
| 896 | - |
|
| 897 | - /** |
|
| 898 | - * insert DEFAULT ticket |
|
| 899 | - * |
|
| 900 | - * @access public |
|
| 901 | - * @static |
|
| 902 | - * @return void |
|
| 903 | - */ |
|
| 904 | - public function insert_default_tickets() |
|
| 905 | - { |
|
| 906 | - global $wpdb; |
|
| 907 | - $ticket_table = $wpdb->prefix . "esp_ticket"; |
|
| 908 | - if ($this->_get_table_analysis()->tableExists($ticket_table)) { |
|
| 909 | - $SQL = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table; |
|
| 910 | - $tickets_exist = $wpdb->get_var($SQL); |
|
| 911 | - if ( ! $tickets_exist) { |
|
| 912 | - $SQL = "INSERT INTO $ticket_table |
|
| 889 | + $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_prices__SQL', $SQL); |
|
| 890 | + $wpdb->query($SQL); |
|
| 891 | + } |
|
| 892 | + } |
|
| 893 | + } |
|
| 894 | + |
|
| 895 | + |
|
| 896 | + |
|
| 897 | + /** |
|
| 898 | + * insert DEFAULT ticket |
|
| 899 | + * |
|
| 900 | + * @access public |
|
| 901 | + * @static |
|
| 902 | + * @return void |
|
| 903 | + */ |
|
| 904 | + public function insert_default_tickets() |
|
| 905 | + { |
|
| 906 | + global $wpdb; |
|
| 907 | + $ticket_table = $wpdb->prefix . "esp_ticket"; |
|
| 908 | + if ($this->_get_table_analysis()->tableExists($ticket_table)) { |
|
| 909 | + $SQL = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table; |
|
| 910 | + $tickets_exist = $wpdb->get_var($SQL); |
|
| 911 | + if ( ! $tickets_exist) { |
|
| 912 | + $SQL = "INSERT INTO $ticket_table |
|
| 913 | 913 | ( TKT_ID, TTM_ID, TKT_name, TKT_description, TKT_qty, TKT_sold, TKT_uses, TKT_min, TKT_max, TKT_price, TKT_start_date, TKT_end_date, TKT_taxable, TKT_order, TKT_row, TKT_is_default, TKT_parent, TKT_deleted ) VALUES |
| 914 | 914 | ( 1, 0, '" |
| 915 | - . esc_html__("Free Ticket", "event_espresso") |
|
| 916 | - . "', '', 100, 0, -1, 0, -1, 0.00, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0, 0, 1, 1, 0, 0);"; |
|
| 917 | - $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_tickets__SQL', $SQL); |
|
| 918 | - $wpdb->query($SQL); |
|
| 919 | - } |
|
| 920 | - } |
|
| 921 | - $ticket_price_table = $wpdb->prefix . "esp_ticket_price"; |
|
| 922 | - if ($this->_get_table_analysis()->tableExists($ticket_price_table)) { |
|
| 923 | - $SQL = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table; |
|
| 924 | - $ticket_prc_exist = $wpdb->get_var($SQL); |
|
| 925 | - if ( ! $ticket_prc_exist) { |
|
| 926 | - $SQL = "INSERT INTO $ticket_price_table |
|
| 915 | + . esc_html__("Free Ticket", "event_espresso") |
|
| 916 | + . "', '', 100, 0, -1, 0, -1, 0.00, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0, 0, 1, 1, 0, 0);"; |
|
| 917 | + $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_tickets__SQL', $SQL); |
|
| 918 | + $wpdb->query($SQL); |
|
| 919 | + } |
|
| 920 | + } |
|
| 921 | + $ticket_price_table = $wpdb->prefix . "esp_ticket_price"; |
|
| 922 | + if ($this->_get_table_analysis()->tableExists($ticket_price_table)) { |
|
| 923 | + $SQL = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table; |
|
| 924 | + $ticket_prc_exist = $wpdb->get_var($SQL); |
|
| 925 | + if ( ! $ticket_prc_exist) { |
|
| 926 | + $SQL = "INSERT INTO $ticket_price_table |
|
| 927 | 927 | ( TKP_ID, TKT_ID, PRC_ID ) VALUES |
| 928 | 928 | ( 1, 1, 1 ) |
| 929 | 929 | "; |
| 930 | - $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_tickets__SQL__ticket_price', $SQL); |
|
| 931 | - $wpdb->query($SQL); |
|
| 932 | - } |
|
| 933 | - } |
|
| 934 | - } |
|
| 935 | - |
|
| 936 | - |
|
| 937 | - |
|
| 938 | - /** |
|
| 939 | - * Gets a country entry as an array, or creates one if none is found. Much like EEM_Country::instance()->get_one(), |
|
| 940 | - * but is independent of outside code which can change in future versions of EE. Also, $country_name CAN be a 3.1 |
|
| 941 | - * country ID (int), a 2-letter ISO, 3-letter ISO, or name |
|
| 942 | - * |
|
| 943 | - * @global type $wpdb |
|
| 944 | - * @param string $country_name |
|
| 945 | - * @return array where keys are columns, values are column values |
|
| 946 | - */ |
|
| 947 | - public function get_or_create_country($country_name) |
|
| 948 | - { |
|
| 949 | - if ( ! $country_name) { |
|
| 950 | - throw new EE_Error(esc_html__("Could not get a country because country name is blank", "event_espresso")); |
|
| 951 | - } |
|
| 952 | - global $wpdb; |
|
| 953 | - $country_table = $wpdb->prefix . "esp_country"; |
|
| 954 | - if (is_int($country_name)) { |
|
| 955 | - $country_name = $this->get_iso_from_3_1_country_id($country_name); |
|
| 956 | - } |
|
| 957 | - $country = $wpdb->get_row($wpdb->prepare("SELECT * FROM $country_table WHERE |
|
| 930 | + $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_tickets__SQL__ticket_price', $SQL); |
|
| 931 | + $wpdb->query($SQL); |
|
| 932 | + } |
|
| 933 | + } |
|
| 934 | + } |
|
| 935 | + |
|
| 936 | + |
|
| 937 | + |
|
| 938 | + /** |
|
| 939 | + * Gets a country entry as an array, or creates one if none is found. Much like EEM_Country::instance()->get_one(), |
|
| 940 | + * but is independent of outside code which can change in future versions of EE. Also, $country_name CAN be a 3.1 |
|
| 941 | + * country ID (int), a 2-letter ISO, 3-letter ISO, or name |
|
| 942 | + * |
|
| 943 | + * @global type $wpdb |
|
| 944 | + * @param string $country_name |
|
| 945 | + * @return array where keys are columns, values are column values |
|
| 946 | + */ |
|
| 947 | + public function get_or_create_country($country_name) |
|
| 948 | + { |
|
| 949 | + if ( ! $country_name) { |
|
| 950 | + throw new EE_Error(esc_html__("Could not get a country because country name is blank", "event_espresso")); |
|
| 951 | + } |
|
| 952 | + global $wpdb; |
|
| 953 | + $country_table = $wpdb->prefix . "esp_country"; |
|
| 954 | + if (is_int($country_name)) { |
|
| 955 | + $country_name = $this->get_iso_from_3_1_country_id($country_name); |
|
| 956 | + } |
|
| 957 | + $country = $wpdb->get_row($wpdb->prepare("SELECT * FROM $country_table WHERE |
|
| 958 | 958 | CNT_ISO LIKE %s OR |
| 959 | 959 | CNT_ISO3 LIKE %s OR |
| 960 | 960 | CNT_name LIKE %s LIMIT 1", $country_name, $country_name, $country_name), ARRAY_A); |
| 961 | - if ( ! $country) { |
|
| 962 | - //insert a new one then |
|
| 963 | - $cols_n_values = array( |
|
| 964 | - 'CNT_ISO' => $this->_find_available_country_iso(2), |
|
| 965 | - 'CNT_ISO3' => $this->_find_available_country_iso(3), |
|
| 966 | - 'RGN_ID' => 0, |
|
| 967 | - 'CNT_name' => $country_name, |
|
| 968 | - 'CNT_cur_code' => 'USD', |
|
| 969 | - 'CNT_cur_single' => 'Dollar', |
|
| 970 | - 'CNT_cur_plural' => 'Dollars', |
|
| 971 | - 'CNT_cur_sign' => '$', |
|
| 972 | - 'CNT_cur_sign_b4' => true, |
|
| 973 | - 'CNT_cur_dec_plc' => 2, |
|
| 974 | - 'CNT_cur_dec_mrk' => '.', |
|
| 975 | - 'CNT_cur_thsnds' => ',', |
|
| 976 | - 'CNT_tel_code' => '+1', |
|
| 977 | - 'CNT_is_EU' => false, |
|
| 978 | - 'CNT_active' => true, |
|
| 979 | - ); |
|
| 980 | - $data_types = array( |
|
| 981 | - '%s',//CNT_ISO |
|
| 982 | - '%s',//CNT_ISO3 |
|
| 983 | - '%d',//RGN_ID |
|
| 984 | - '%s',//CNT_name |
|
| 985 | - '%s',//CNT_cur_code |
|
| 986 | - '%s',//CNT_cur_single |
|
| 987 | - '%s',//CNT_cur_plural |
|
| 988 | - '%s',//CNT_cur_sign |
|
| 989 | - '%d',//CNT_cur_sign_b4 |
|
| 990 | - '%d',//CNT_cur_dec_plc |
|
| 991 | - '%s',//CNT_cur_dec_mrk |
|
| 992 | - '%s',//CNT_cur_thsnds |
|
| 993 | - '%s',//CNT_tel_code |
|
| 994 | - '%d',//CNT_is_EU |
|
| 995 | - '%d',//CNT_active |
|
| 996 | - ); |
|
| 997 | - $success = $wpdb->insert($country_table, |
|
| 998 | - $cols_n_values, |
|
| 999 | - $data_types); |
|
| 1000 | - if ( ! $success) { |
|
| 1001 | - throw new EE_Error($this->_create_error_message_for_db_insertion('N/A', |
|
| 1002 | - array('country_id' => $country_name), $country_table, $cols_n_values, $data_types)); |
|
| 1003 | - } |
|
| 1004 | - $country = $cols_n_values; |
|
| 1005 | - } |
|
| 1006 | - return $country; |
|
| 1007 | - } |
|
| 1008 | - |
|
| 1009 | - |
|
| 1010 | - |
|
| 1011 | - /** |
|
| 1012 | - * finds a country iso which hasnt been used yet |
|
| 1013 | - * |
|
| 1014 | - * @global type $wpdb |
|
| 1015 | - * @return string |
|
| 1016 | - */ |
|
| 1017 | - private function _find_available_country_iso($num_letters = 2) |
|
| 1018 | - { |
|
| 1019 | - global $wpdb; |
|
| 1020 | - $country_table = $wpdb->prefix . "esp_country"; |
|
| 1021 | - $attempts = 0; |
|
| 1022 | - do { |
|
| 1023 | - $current_iso = strtoupper(wp_generate_password($num_letters, false)); |
|
| 1024 | - $country_with_that_iso = $wpdb->get_var($wpdb->prepare("SELECT count(CNT_ISO) FROM " |
|
| 1025 | - . $country_table |
|
| 1026 | - . " WHERE CNT_ISO=%s", $current_iso)); |
|
| 1027 | - $attempts++; |
|
| 1028 | - //keep going until we find an available country code, or we arbitrarily |
|
| 1029 | - //decide we've tried this enough. Somehow they have way too many countries |
|
| 1030 | - //(probably because they're mis-using the EE3 country_id like a custom question) |
|
| 1031 | - } while (intval($country_with_that_iso) && $attempts < 200); |
|
| 1032 | - return $current_iso; |
|
| 1033 | - } |
|
| 1034 | - |
|
| 1035 | - |
|
| 1036 | - |
|
| 1037 | - /** |
|
| 1038 | - * Gets a state entry as an array, or creates one if none is found. Much like EEM_State::instance()->get_one(), but |
|
| 1039 | - * is independent of outside code which can change in future versions of EE |
|
| 1040 | - * |
|
| 1041 | - * @global type $wpdb |
|
| 1042 | - * @param string $state_name |
|
| 1043 | - * @return array where keys are columns, values are column values |
|
| 1044 | - */ |
|
| 1045 | - public function get_or_create_state($state_name, $country_name = '') |
|
| 1046 | - { |
|
| 1047 | - if ( ! $state_name) { |
|
| 1048 | - throw new EE_Error(esc_html__("Could not get-or-create state because no state name was provided", |
|
| 1049 | - "event_espresso")); |
|
| 1050 | - } |
|
| 1051 | - try { |
|
| 1052 | - $country = $this->get_or_create_country($country_name); |
|
| 1053 | - $country_iso = $country['CNT_ISO']; |
|
| 1054 | - } catch (EE_Error $e) { |
|
| 1055 | - $country_iso = $this->get_default_country_iso(); |
|
| 1056 | - } |
|
| 1057 | - global $wpdb; |
|
| 1058 | - $state_table = $wpdb->prefix . "esp_state"; |
|
| 1059 | - $state = $wpdb->get_row($wpdb->prepare("SELECT * FROM $state_table WHERE |
|
| 961 | + if ( ! $country) { |
|
| 962 | + //insert a new one then |
|
| 963 | + $cols_n_values = array( |
|
| 964 | + 'CNT_ISO' => $this->_find_available_country_iso(2), |
|
| 965 | + 'CNT_ISO3' => $this->_find_available_country_iso(3), |
|
| 966 | + 'RGN_ID' => 0, |
|
| 967 | + 'CNT_name' => $country_name, |
|
| 968 | + 'CNT_cur_code' => 'USD', |
|
| 969 | + 'CNT_cur_single' => 'Dollar', |
|
| 970 | + 'CNT_cur_plural' => 'Dollars', |
|
| 971 | + 'CNT_cur_sign' => '$', |
|
| 972 | + 'CNT_cur_sign_b4' => true, |
|
| 973 | + 'CNT_cur_dec_plc' => 2, |
|
| 974 | + 'CNT_cur_dec_mrk' => '.', |
|
| 975 | + 'CNT_cur_thsnds' => ',', |
|
| 976 | + 'CNT_tel_code' => '+1', |
|
| 977 | + 'CNT_is_EU' => false, |
|
| 978 | + 'CNT_active' => true, |
|
| 979 | + ); |
|
| 980 | + $data_types = array( |
|
| 981 | + '%s',//CNT_ISO |
|
| 982 | + '%s',//CNT_ISO3 |
|
| 983 | + '%d',//RGN_ID |
|
| 984 | + '%s',//CNT_name |
|
| 985 | + '%s',//CNT_cur_code |
|
| 986 | + '%s',//CNT_cur_single |
|
| 987 | + '%s',//CNT_cur_plural |
|
| 988 | + '%s',//CNT_cur_sign |
|
| 989 | + '%d',//CNT_cur_sign_b4 |
|
| 990 | + '%d',//CNT_cur_dec_plc |
|
| 991 | + '%s',//CNT_cur_dec_mrk |
|
| 992 | + '%s',//CNT_cur_thsnds |
|
| 993 | + '%s',//CNT_tel_code |
|
| 994 | + '%d',//CNT_is_EU |
|
| 995 | + '%d',//CNT_active |
|
| 996 | + ); |
|
| 997 | + $success = $wpdb->insert($country_table, |
|
| 998 | + $cols_n_values, |
|
| 999 | + $data_types); |
|
| 1000 | + if ( ! $success) { |
|
| 1001 | + throw new EE_Error($this->_create_error_message_for_db_insertion('N/A', |
|
| 1002 | + array('country_id' => $country_name), $country_table, $cols_n_values, $data_types)); |
|
| 1003 | + } |
|
| 1004 | + $country = $cols_n_values; |
|
| 1005 | + } |
|
| 1006 | + return $country; |
|
| 1007 | + } |
|
| 1008 | + |
|
| 1009 | + |
|
| 1010 | + |
|
| 1011 | + /** |
|
| 1012 | + * finds a country iso which hasnt been used yet |
|
| 1013 | + * |
|
| 1014 | + * @global type $wpdb |
|
| 1015 | + * @return string |
|
| 1016 | + */ |
|
| 1017 | + private function _find_available_country_iso($num_letters = 2) |
|
| 1018 | + { |
|
| 1019 | + global $wpdb; |
|
| 1020 | + $country_table = $wpdb->prefix . "esp_country"; |
|
| 1021 | + $attempts = 0; |
|
| 1022 | + do { |
|
| 1023 | + $current_iso = strtoupper(wp_generate_password($num_letters, false)); |
|
| 1024 | + $country_with_that_iso = $wpdb->get_var($wpdb->prepare("SELECT count(CNT_ISO) FROM " |
|
| 1025 | + . $country_table |
|
| 1026 | + . " WHERE CNT_ISO=%s", $current_iso)); |
|
| 1027 | + $attempts++; |
|
| 1028 | + //keep going until we find an available country code, or we arbitrarily |
|
| 1029 | + //decide we've tried this enough. Somehow they have way too many countries |
|
| 1030 | + //(probably because they're mis-using the EE3 country_id like a custom question) |
|
| 1031 | + } while (intval($country_with_that_iso) && $attempts < 200); |
|
| 1032 | + return $current_iso; |
|
| 1033 | + } |
|
| 1034 | + |
|
| 1035 | + |
|
| 1036 | + |
|
| 1037 | + /** |
|
| 1038 | + * Gets a state entry as an array, or creates one if none is found. Much like EEM_State::instance()->get_one(), but |
|
| 1039 | + * is independent of outside code which can change in future versions of EE |
|
| 1040 | + * |
|
| 1041 | + * @global type $wpdb |
|
| 1042 | + * @param string $state_name |
|
| 1043 | + * @return array where keys are columns, values are column values |
|
| 1044 | + */ |
|
| 1045 | + public function get_or_create_state($state_name, $country_name = '') |
|
| 1046 | + { |
|
| 1047 | + if ( ! $state_name) { |
|
| 1048 | + throw new EE_Error(esc_html__("Could not get-or-create state because no state name was provided", |
|
| 1049 | + "event_espresso")); |
|
| 1050 | + } |
|
| 1051 | + try { |
|
| 1052 | + $country = $this->get_or_create_country($country_name); |
|
| 1053 | + $country_iso = $country['CNT_ISO']; |
|
| 1054 | + } catch (EE_Error $e) { |
|
| 1055 | + $country_iso = $this->get_default_country_iso(); |
|
| 1056 | + } |
|
| 1057 | + global $wpdb; |
|
| 1058 | + $state_table = $wpdb->prefix . "esp_state"; |
|
| 1059 | + $state = $wpdb->get_row($wpdb->prepare("SELECT * FROM $state_table WHERE |
|
| 1060 | 1060 | (STA_abbrev LIKE %s OR |
| 1061 | 1061 | STA_name LIKE %s) AND |
| 1062 | 1062 | CNT_ISO LIKE %s LIMIT 1", $state_name, $state_name, $country_iso), ARRAY_A); |
| 1063 | - if ( ! $state) { |
|
| 1064 | - //insert a new one then |
|
| 1065 | - $cols_n_values = array( |
|
| 1066 | - 'CNT_ISO' => $country_iso, |
|
| 1067 | - 'STA_abbrev' => substr($state_name, 0, 6), |
|
| 1068 | - 'STA_name' => $state_name, |
|
| 1069 | - 'STA_active' => true, |
|
| 1070 | - ); |
|
| 1071 | - $data_types = array( |
|
| 1072 | - '%s',//CNT_ISO |
|
| 1073 | - '%s',//STA_abbrev |
|
| 1074 | - '%s',//STA_name |
|
| 1075 | - '%d',//STA_active |
|
| 1076 | - ); |
|
| 1077 | - $success = $wpdb->insert($state_table, $cols_n_values, $data_types); |
|
| 1078 | - if ( ! $success) { |
|
| 1079 | - throw new EE_Error($this->_create_error_message_for_db_insertion('N/A', |
|
| 1080 | - array('state' => $state_name, 'country_id' => $country_name), $state_table, $cols_n_values, |
|
| 1081 | - $data_types)); |
|
| 1082 | - } |
|
| 1083 | - $state = $cols_n_values; |
|
| 1084 | - $state['STA_ID'] = $wpdb->insert_id; |
|
| 1085 | - } |
|
| 1086 | - return $state; |
|
| 1087 | - } |
|
| 1088 | - |
|
| 1089 | - |
|
| 1090 | - |
|
| 1091 | - /** |
|
| 1092 | - * Fixes times like "5:00 PM" into the expected 24-hour format "17:00". |
|
| 1093 | - * THis is actually just copied from the 3.1 JSON API because it needed to do the exact same thing |
|
| 1094 | - * |
|
| 1095 | - * @param type $timeString |
|
| 1096 | - * @return string in the php DATETIME format: "G:i" (24-hour format hour with leading zeros, a colon, and minutes |
|
| 1097 | - * with leading zeros) |
|
| 1098 | - */ |
|
| 1099 | - public function convertTimeFromAMPM($timeString) |
|
| 1100 | - { |
|
| 1101 | - $matches = array(); |
|
| 1102 | - preg_match("~(\\d*):(\\d*)~", $timeString, $matches); |
|
| 1103 | - if ( ! $matches || count($matches) < 3) { |
|
| 1104 | - $hour = '00'; |
|
| 1105 | - $minutes = '00'; |
|
| 1106 | - } else { |
|
| 1107 | - $hour = intval($matches[1]); |
|
| 1108 | - $minutes = $matches[2]; |
|
| 1109 | - } |
|
| 1110 | - if (strpos($timeString, 'PM') || strpos($timeString, 'pm')) { |
|
| 1111 | - $hour = intval($hour) + 12; |
|
| 1112 | - } |
|
| 1113 | - $hour = str_pad("$hour", 2, '0', STR_PAD_LEFT); |
|
| 1114 | - $minutes = str_pad("$minutes", 2, '0', STR_PAD_LEFT); |
|
| 1115 | - return "$hour:$minutes"; |
|
| 1116 | - } |
|
| 1117 | - |
|
| 1118 | - |
|
| 1119 | - |
|
| 1120 | - /** |
|
| 1121 | - * Gets the ISO3 fora country given its 3.1 country ID. |
|
| 1122 | - * |
|
| 1123 | - * @param int $country_id |
|
| 1124 | - * @return string the country's ISO3 code |
|
| 1125 | - */ |
|
| 1126 | - public function get_iso_from_3_1_country_id($country_id) |
|
| 1127 | - { |
|
| 1128 | - $old_countries = array( |
|
| 1129 | - array(64, 'United States', 'US', 'USA', 1), |
|
| 1130 | - array(15, 'Australia', 'AU', 'AUS', 1), |
|
| 1131 | - array(39, 'Canada', 'CA', 'CAN', 1), |
|
| 1132 | - array(171, 'United Kingdom', 'GB', 'GBR', 1), |
|
| 1133 | - array(70, 'France', 'FR', 'FRA', 2), |
|
| 1134 | - array(111, 'Italy', 'IT', 'ITA', 2), |
|
| 1135 | - array(63, 'Spain', 'ES', 'ESP', 2), |
|
| 1136 | - array(1, 'Afghanistan', 'AF', 'AFG', 1), |
|
| 1137 | - array(2, 'Albania', 'AL', 'ALB', 1), |
|
| 1138 | - array(3, 'Germany', 'DE', 'DEU', 2), |
|
| 1139 | - array(198, 'Switzerland', 'CH', 'CHE', 1), |
|
| 1140 | - array(87, 'Netherlands', 'NL', 'NLD', 2), |
|
| 1141 | - array(197, 'Sweden', 'SE', 'SWE', 1), |
|
| 1142 | - array(230, 'Akrotiri and Dhekelia', 'CY', 'CYP', 2), |
|
| 1143 | - array(4, 'Andorra', 'AD', 'AND', 2), |
|
| 1144 | - array(5, 'Angola', 'AO', 'AGO', 1), |
|
| 1145 | - array(6, 'Anguilla', 'AI', 'AIA', 1), |
|
| 1146 | - array(7, 'Antarctica', 'AQ', 'ATA', 1), |
|
| 1147 | - array(8, 'Antigua and Barbuda', 'AG', 'ATG', 1), |
|
| 1148 | - array(10, 'Saudi Arabia', 'SA', 'SAU', 1), |
|
| 1149 | - array(11, 'Algeria', 'DZ', 'DZA', 1), |
|
| 1150 | - array(12, 'Argentina', 'AR', 'ARG', 1), |
|
| 1151 | - array(13, 'Armenia', 'AM', 'ARM', 1), |
|
| 1152 | - array(14, 'Aruba', 'AW', 'ABW', 1), |
|
| 1153 | - array(16, 'Austria', 'AT', 'AUT', 2), |
|
| 1154 | - array(17, 'Azerbaijan', 'AZ', 'AZE', 1), |
|
| 1155 | - array(18, 'Bahamas', 'BS', 'BHS', 1), |
|
| 1156 | - array(19, 'Bahrain', 'BH', 'BHR', 1), |
|
| 1157 | - array(20, 'Bangladesh', 'BD', 'BGD', 1), |
|
| 1158 | - array(21, 'Barbados', 'BB', 'BRB', 1), |
|
| 1159 | - array(22, 'Belgium ', 'BE', 'BEL', 2), |
|
| 1160 | - array(23, 'Belize', 'BZ', 'BLZ', 1), |
|
| 1161 | - array(24, 'Benin', 'BJ', 'BEN', 1), |
|
| 1162 | - array(25, 'Bermudas', 'BM', 'BMU', 1), |
|
| 1163 | - array(26, 'Belarus', 'BY', 'BLR', 1), |
|
| 1164 | - array(27, 'Bolivia', 'BO', 'BOL', 1), |
|
| 1165 | - array(28, 'Bosnia and Herzegovina', 'BA', 'BIH', 1), |
|
| 1166 | - array(29, 'Botswana', 'BW', 'BWA', 1), |
|
| 1167 | - array(96, 'Bouvet Island', 'BV', 'BVT', 1), |
|
| 1168 | - array(30, 'Brazil', 'BR', 'BRA', 1), |
|
| 1169 | - array(31, 'Brunei', 'BN', 'BRN', 1), |
|
| 1170 | - array(32, 'Bulgaria', 'BG', 'BGR', 1), |
|
| 1171 | - array(33, 'Burkina Faso', 'BF', 'BFA', 1), |
|
| 1172 | - array(34, 'Burundi', 'BI', 'BDI', 1), |
|
| 1173 | - array(35, 'Bhutan', 'BT', 'BTN', 1), |
|
| 1174 | - array(36, 'Cape Verde', 'CV', 'CPV', 1), |
|
| 1175 | - array(37, 'Cambodia', 'KH', 'KHM', 1), |
|
| 1176 | - array(38, 'Cameroon', 'CM', 'CMR', 1), |
|
| 1177 | - array(98, 'Cayman Islands', 'KY', 'CYM', 1), |
|
| 1178 | - array(172, 'Central African Republic', 'CF', 'CAF', 1), |
|
| 1179 | - array(40, 'Chad', 'TD', 'TCD', 1), |
|
| 1180 | - array(41, 'Chile', 'CL', 'CHL', 1), |
|
| 1181 | - array(42, 'China', 'CN', 'CHN', 1), |
|
| 1182 | - array(105, 'Christmas Island', 'CX', 'CXR', 1), |
|
| 1183 | - array(43, 'Cyprus', 'CY', 'CYP', 2), |
|
| 1184 | - array(99, 'Cocos Island', 'CC', 'CCK', 1), |
|
| 1185 | - array(100, 'Cook Islands', 'CK', 'COK', 1), |
|
| 1186 | - array(44, 'Colombia', 'CO', 'COL', 1), |
|
| 1187 | - array(45, 'Comoros', 'KM', 'COM', 1), |
|
| 1188 | - array(46, 'Congo', 'CG', 'COG', 1), |
|
| 1189 | - array(47, 'North Korea', 'KP', 'PRK', 1), |
|
| 1190 | - array(50, 'Costa Rica', 'CR', 'CRI', 1), |
|
| 1191 | - array(51, 'Croatia', 'HR', 'HRV', 1), |
|
| 1192 | - array(52, 'Cuba', 'CU', 'CUB', 1), |
|
| 1193 | - array(173, 'Czech Republic', 'CZ', 'CZE', 1), |
|
| 1194 | - array(53, 'Denmark', 'DK', 'DNK', 1), |
|
| 1195 | - array(54, 'Djibouti', 'DJ', 'DJI', 1), |
|
| 1196 | - array(55, 'Dominica', 'DM', 'DMA', 1), |
|
| 1197 | - array(174, 'Dominican Republic', 'DO', 'DOM', 1), |
|
| 1198 | - array(56, 'Ecuador', 'EC', 'ECU', 1), |
|
| 1199 | - array(57, 'Egypt', 'EG', 'EGY', 1), |
|
| 1200 | - array(58, 'El Salvador', 'SV', 'SLV', 1), |
|
| 1201 | - array(60, 'Eritrea', 'ER', 'ERI', 1), |
|
| 1202 | - array(61, 'Slovakia', 'SK', 'SVK', 2), |
|
| 1203 | - array(62, 'Slovenia', 'SI', 'SVN', 2), |
|
| 1204 | - array(65, 'Estonia', 'EE', 'EST', 2), |
|
| 1205 | - array(66, 'Ethiopia', 'ET', 'ETH', 1), |
|
| 1206 | - array(102, 'Faroe islands', 'FO', 'FRO', 1), |
|
| 1207 | - array(103, 'Falkland Islands', 'FK', 'FLK', 1), |
|
| 1208 | - array(67, 'Fiji', 'FJ', 'FJI', 1), |
|
| 1209 | - array(69, 'Finland', 'FI', 'FIN', 2), |
|
| 1210 | - array(71, 'Gabon', 'GA', 'GAB', 1), |
|
| 1211 | - array(72, 'Gambia', 'GM', 'GMB', 1), |
|
| 1212 | - array(73, 'Georgia', 'GE', 'GEO', 1), |
|
| 1213 | - array(74, 'Ghana', 'GH', 'GHA', 1), |
|
| 1214 | - array(75, 'Gibraltar', 'GI', 'GIB', 1), |
|
| 1215 | - array(76, 'Greece', 'GR', 'GRC', 2), |
|
| 1216 | - array(77, 'Grenada', 'GD', 'GRD', 1), |
|
| 1217 | - array(78, 'Greenland', 'GL', 'GRL', 1), |
|
| 1218 | - array(79, 'Guadeloupe', 'GP', 'GLP', 1), |
|
| 1219 | - array(80, 'Guam', 'GU', 'GUM', 1), |
|
| 1220 | - array(81, 'Guatemala', 'GT', 'GTM', 1), |
|
| 1221 | - array(82, 'Guinea', 'GN', 'GIN', 1), |
|
| 1222 | - array(83, 'Equatorial Guinea', 'GQ', 'GNQ', 1), |
|
| 1223 | - array(84, 'Guinea-Bissau', 'GW', 'GNB', 1), |
|
| 1224 | - array(85, 'Guyana', 'GY', 'GUY', 1), |
|
| 1225 | - array(86, 'Haiti', 'HT', 'HTI', 1), |
|
| 1226 | - array(88, 'Honduras', 'HN', 'HND', 1), |
|
| 1227 | - array(89, 'Hong Kong', 'HK', 'HKG', 1), |
|
| 1228 | - array(90, 'Hungary', 'HU', 'HUN', 1), |
|
| 1229 | - array(91, 'India', 'IN', 'IND', 1), |
|
| 1230 | - array(205, 'British Indian Ocean Territory', 'IO', 'IOT', 1), |
|
| 1231 | - array(92, 'Indonesia', 'ID', 'IDN', 1), |
|
| 1232 | - array(93, 'Iraq', 'IQ', 'IRQ', 1), |
|
| 1233 | - array(94, 'Iran', 'IR', 'IRN', 1), |
|
| 1234 | - array(95, 'Ireland', 'IE', 'IRL', 2), |
|
| 1235 | - array(97, 'Iceland', 'IS', 'ISL', 1), |
|
| 1236 | - array(110, 'Israel', 'IL', 'ISR', 1), |
|
| 1237 | - array(49, 'Ivory Coast ', 'CI', 'CIV', 1), |
|
| 1238 | - array(112, 'Jamaica', 'JM', 'JAM', 1), |
|
| 1239 | - array(113, 'Japan', 'JP', 'JPN', 1), |
|
| 1240 | - array(114, 'Jordan', 'JO', 'JOR', 1), |
|
| 1241 | - array(115, 'Kazakhstan', 'KZ', 'KAZ', 1), |
|
| 1242 | - array(116, 'Kenya', 'KE', 'KEN', 1), |
|
| 1243 | - array(117, 'Kyrgyzstan', 'KG', 'KGZ', 1), |
|
| 1244 | - array(118, 'Kiribati', 'KI', 'KIR', 1), |
|
| 1245 | - array(48, 'South Korea', 'KR', 'KOR', 1), |
|
| 1246 | - array(228, 'Kosovo', 'XK', 'XKV', 2), |
|
| 1247 | - // there is no official ISO code for Kosovo yet (http://geonames.wordpress.com/2010/03/08/xk-country-code-for-kosovo/) so using a temporary country code and a modified 3 character code for ISO code -- this should be updated if/when Kosovo gets its own ISO code |
|
| 1248 | - array(119, 'Kuwait', 'KW', 'KWT', 1), |
|
| 1249 | - array(120, 'Laos', 'LA', 'LAO', 1), |
|
| 1250 | - array(121, 'Latvia', 'LV', 'LVA', 2), |
|
| 1251 | - array(122, 'Lesotho', 'LS', 'LSO', 1), |
|
| 1252 | - array(123, 'Lebanon', 'LB', 'LBN', 1), |
|
| 1253 | - array(124, 'Liberia', 'LR', 'LBR', 1), |
|
| 1254 | - array(125, 'Libya', 'LY', 'LBY', 1), |
|
| 1255 | - array(126, 'Liechtenstein', 'LI', 'LIE', 1), |
|
| 1256 | - array(127, 'Lithuania', 'LT', 'LTU', 2), |
|
| 1257 | - array(128, 'Luxemburg', 'LU', 'LUX', 2), |
|
| 1258 | - array(129, 'Macao', 'MO', 'MAC', 1), |
|
| 1259 | - array(130, 'Macedonia', 'MK', 'MKD', 1), |
|
| 1260 | - array(131, 'Madagascar', 'MG', 'MDG', 1), |
|
| 1261 | - array(132, 'Malaysia', 'MY', 'MYS', 1), |
|
| 1262 | - array(133, 'Malawi', 'MW', 'MWI', 1), |
|
| 1263 | - array(134, 'Maldivas', 'MV', 'MDV', 1), |
|
| 1264 | - array(135, 'Mali', 'ML', 'MLI', 1), |
|
| 1265 | - array(136, 'Malta', 'MT', 'MLT', 2), |
|
| 1266 | - array(101, 'Northern Marianas', 'MP', 'MNP', 1), |
|
| 1267 | - array(137, 'Morocco', 'MA', 'MAR', 1), |
|
| 1268 | - array(104, 'Marshall islands', 'MH', 'MHL', 1), |
|
| 1269 | - array(138, 'Martinique', 'MQ', 'MTQ', 1), |
|
| 1270 | - array(139, 'Mauritius', 'MU', 'MUS', 1), |
|
| 1271 | - array(140, 'Mauritania', 'MR', 'MRT', 1), |
|
| 1272 | - array(141, 'Mayote', 'YT', 'MYT', 2), |
|
| 1273 | - array(142, 'Mexico', 'MX', 'MEX', 1), |
|
| 1274 | - array(143, 'Micronesia', 'FM', 'FSM', 1), |
|
| 1275 | - array(144, 'Moldova', 'MD', 'MDA', 1), |
|
| 1276 | - array(145, 'Monaco', 'MC', 'MCO', 2), |
|
| 1277 | - array(146, 'Mongolia', 'MN', 'MNG', 1), |
|
| 1278 | - array(147, 'Montserrat', 'MS', 'MSR', 1), |
|
| 1279 | - array(227, 'Montenegro', 'ME', 'MNE', 2), |
|
| 1280 | - array(148, 'Mozambique', 'MZ', 'MOZ', 1), |
|
| 1281 | - array(149, 'Myanmar', 'MM', 'MMR', 1), |
|
| 1282 | - array(150, 'Namibia', 'NA', 'NAM', 1), |
|
| 1283 | - array(151, 'Nauru', 'NR', 'NRU', 1), |
|
| 1284 | - array(152, 'Nepal', 'NP', 'NPL', 1), |
|
| 1285 | - array(9, 'Netherlands Antilles', 'AN', 'ANT', 1), |
|
| 1286 | - array(153, 'Nicaragua', 'NI', 'NIC', 1), |
|
| 1287 | - array(154, 'Niger', 'NE', 'NER', 1), |
|
| 1288 | - array(155, 'Nigeria', 'NG', 'NGA', 1), |
|
| 1289 | - array(156, 'Niue', 'NU', 'NIU', 1), |
|
| 1290 | - array(157, 'Norway', 'NO', 'NOR', 1), |
|
| 1291 | - array(158, 'New Caledonia', 'NC', 'NCL', 1), |
|
| 1292 | - array(159, 'New Zealand', 'NZ', 'NZL', 1), |
|
| 1293 | - array(160, 'Oman', 'OM', 'OMN', 1), |
|
| 1294 | - array(161, 'Pakistan', 'PK', 'PAK', 1), |
|
| 1295 | - array(162, 'Palau', 'PW', 'PLW', 1), |
|
| 1296 | - array(163, 'Panama', 'PA', 'PAN', 1), |
|
| 1297 | - array(164, 'Papua New Guinea', 'PG', 'PNG', 1), |
|
| 1298 | - array(165, 'Paraguay', 'PY', 'PRY', 1), |
|
| 1299 | - array(166, 'Peru', 'PE', 'PER', 1), |
|
| 1300 | - array(68, 'Philippines', 'PH', 'PHL', 1), |
|
| 1301 | - array(167, 'Poland', 'PL', 'POL', 1), |
|
| 1302 | - array(168, 'Portugal', 'PT', 'PRT', 2), |
|
| 1303 | - array(169, 'Puerto Rico', 'PR', 'PRI', 1), |
|
| 1304 | - array(170, 'Qatar', 'QA', 'QAT', 1), |
|
| 1305 | - array(176, 'Rwanda', 'RW', 'RWA', 1), |
|
| 1306 | - array(177, 'Romania', 'RO', 'ROM', 2), |
|
| 1307 | - array(178, 'Russia', 'RU', 'RUS', 1), |
|
| 1308 | - array(229, 'Saint Pierre and Miquelon', 'PM', 'SPM', 2), |
|
| 1309 | - array(180, 'Samoa', 'WS', 'WSM', 1), |
|
| 1310 | - array(181, 'American Samoa', 'AS', 'ASM', 1), |
|
| 1311 | - array(183, 'San Marino', 'SM', 'SMR', 2), |
|
| 1312 | - array(184, 'Saint Vincent and the Grenadines', 'VC', 'VCT', 1), |
|
| 1313 | - array(185, 'Saint Helena', 'SH', 'SHN', 1), |
|
| 1314 | - array(186, 'Saint Lucia', 'LC', 'LCA', 1), |
|
| 1315 | - array(188, 'Senegal', 'SN', 'SEN', 1), |
|
| 1316 | - array(189, 'Seychelles', 'SC', 'SYC', 1), |
|
| 1317 | - array(190, 'Sierra Leona', 'SL', 'SLE', 1), |
|
| 1318 | - array(191, 'Singapore', 'SG', 'SGP', 1), |
|
| 1319 | - array(192, 'Syria', 'SY', 'SYR', 1), |
|
| 1320 | - array(193, 'Somalia', 'SO', 'SOM', 1), |
|
| 1321 | - array(194, 'Sri Lanka', 'LK', 'LKA', 1), |
|
| 1322 | - array(195, 'South Africa', 'ZA', 'ZAF', 1), |
|
| 1323 | - array(196, 'Sudan', 'SD', 'SDN', 1), |
|
| 1324 | - array(199, 'Suriname', 'SR', 'SUR', 1), |
|
| 1325 | - array(200, 'Swaziland', 'SZ', 'SWZ', 1), |
|
| 1326 | - array(201, 'Thailand', 'TH', 'THA', 1), |
|
| 1327 | - array(202, 'Taiwan', 'TW', 'TWN', 1), |
|
| 1328 | - array(203, 'Tanzania', 'TZ', 'TZA', 1), |
|
| 1329 | - array(204, 'Tajikistan', 'TJ', 'TJK', 1), |
|
| 1330 | - array(206, 'Timor-Leste', 'TL', 'TLS', 1), |
|
| 1331 | - array(207, 'Togo', 'TG', 'TGO', 1), |
|
| 1332 | - array(208, 'Tokelau', 'TK', 'TKL', 1), |
|
| 1333 | - array(209, 'Tonga', 'TO', 'TON', 1), |
|
| 1334 | - array(210, 'Trinidad and Tobago', 'TT', 'TTO', 1), |
|
| 1335 | - array(211, 'Tunisia', 'TN', 'TUN', 1), |
|
| 1336 | - array(212, 'Turkmenistan', 'TM', 'TKM', 1), |
|
| 1337 | - array(213, 'Turkey', 'TR', 'TUR', 1), |
|
| 1338 | - array(214, 'Tuvalu', 'TV', 'TUV', 1), |
|
| 1339 | - array(215, 'Ukraine', 'UA', 'UKR', 1), |
|
| 1340 | - array(216, 'Uganda', 'UG', 'UGA', 1), |
|
| 1341 | - array(59, 'United Arab Emirates', 'AE', 'ARE', 1), |
|
| 1342 | - array(217, 'Uruguay', 'UY', 'URY', 1), |
|
| 1343 | - array(218, 'Uzbekistan', 'UZ', 'UZB', 1), |
|
| 1344 | - array(219, 'Vanuatu', 'VU', 'VUT', 1), |
|
| 1345 | - array(220, 'Vatican City', 'VA', 'VAT', 2), |
|
| 1346 | - array(221, 'Venezuela', 'VE', 'VEN', 1), |
|
| 1347 | - array(222, 'Vietnam', 'VN', 'VNM', 1), |
|
| 1348 | - array(108, 'Virgin Islands', 'VI', 'VIR', 1), |
|
| 1349 | - array(223, 'Yemen', 'YE', 'YEM', 1), |
|
| 1350 | - array(225, 'Zambia', 'ZM', 'ZMB', 1), |
|
| 1351 | - array(226, 'Zimbabwe', 'ZW', 'ZWE', 1), |
|
| 1352 | - ); |
|
| 1353 | - $country_iso = 'US'; |
|
| 1354 | - foreach ($old_countries as $country_array) { |
|
| 1355 | - //note: index 0 is the 3.1 country ID |
|
| 1356 | - if ($country_array[0] == $country_id) { |
|
| 1357 | - //note: index 2 is the ISO |
|
| 1358 | - $country_iso = $country_array[2]; |
|
| 1359 | - break; |
|
| 1360 | - } |
|
| 1361 | - } |
|
| 1362 | - return $country_iso; |
|
| 1363 | - } |
|
| 1364 | - |
|
| 1365 | - |
|
| 1366 | - |
|
| 1367 | - /** |
|
| 1368 | - * Gets the ISO3 for the |
|
| 1369 | - * |
|
| 1370 | - * @return string |
|
| 1371 | - */ |
|
| 1372 | - public function get_default_country_iso() |
|
| 1373 | - { |
|
| 1374 | - $old_org_options = get_option('events_organization_settings'); |
|
| 1375 | - $iso = $this->get_iso_from_3_1_country_id($old_org_options['organization_country']); |
|
| 1376 | - return $iso; |
|
| 1377 | - } |
|
| 1378 | - |
|
| 1379 | - |
|
| 1380 | - |
|
| 1381 | - /** |
|
| 1382 | - * Converst a 3.1 payment status to its equivalent 4.1 regisration status |
|
| 1383 | - * |
|
| 1384 | - * @param string $payment_status possible value for 3.1's evens_attendee.payment_status |
|
| 1385 | - * @param boolean $this_thing_required_pre_approval whether the thing we're considering (the general setting's |
|
| 1386 | - * DEFAULT payment status, the event's DEFAULT payment status, or |
|
| 1387 | - * the attendee's payment status) required pre-approval. |
|
| 1388 | - * @return string STS_ID for use in 4.1 |
|
| 1389 | - */ |
|
| 1390 | - public function convert_3_1_payment_status_to_4_1_STS_ID($payment_status, $this_thing_required_pre_approval = false) |
|
| 1391 | - { |
|
| 1392 | - //EE team can read the related discussion: https://app.asana.com/0/2400967562914/9418495544455 |
|
| 1393 | - if ($this_thing_required_pre_approval) { |
|
| 1394 | - return 'RNA'; |
|
| 1395 | - } else { |
|
| 1396 | - $mapping = $default_reg_stati_conversions = array( |
|
| 1397 | - 'Completed' => 'RAP', |
|
| 1398 | - '' => 'RPP', |
|
| 1399 | - 'Incomplete' => 'RPP', |
|
| 1400 | - 'Pending' => 'RAP', |
|
| 1401 | - //stati that only occurred on 3.1 attendees: |
|
| 1402 | - 'Payment Declined' => 'RPP', |
|
| 1403 | - 'Not Completed' => 'RPP', |
|
| 1404 | - 'Cancelled' => 'RPP', |
|
| 1405 | - 'Declined' => 'RPP', |
|
| 1406 | - ); |
|
| 1407 | - } |
|
| 1408 | - return isset($mapping[$payment_status]) ? $mapping[$payment_status] : 'RNA'; |
|
| 1409 | - } |
|
| 1410 | - |
|
| 1411 | - |
|
| 1412 | - |
|
| 1413 | - /** |
|
| 1414 | - * Makes sure the 3.1's image url is converted to an image attachment post to the 4.1 CPT event |
|
| 1415 | - * and sets it as the featured image on the CPT event |
|
| 1416 | - * |
|
| 1417 | - * @param type $old_event |
|
| 1418 | - * @param type $new_cpt_id |
|
| 1419 | - * @param EE_Data_Migration_Script_Stage $migration_stage the stage which called this, where errors should be added |
|
| 1420 | - * @return boolean whether or not we had to do the big job of creating an image attachment |
|
| 1421 | - */ |
|
| 1422 | - public function convert_image_url_to_attachment_and_attach_to_post( |
|
| 1423 | - $guid, |
|
| 1424 | - $new_cpt_id, |
|
| 1425 | - EE_Data_Migration_Script_Stage $migration_stage |
|
| 1426 | - ) { |
|
| 1427 | - $created_attachment_post = false; |
|
| 1428 | - $guid = $this->_get_original_guid($guid); |
|
| 1429 | - if ($guid) { |
|
| 1430 | - //check for an existing attachment post with this guid |
|
| 1431 | - $attachment_post_id = $this->_get_image_attachment_id_by_GUID($guid); |
|
| 1432 | - if ( ! $attachment_post_id) { |
|
| 1433 | - //post thumbnail with that GUID doesn't exist, we should create one |
|
| 1434 | - $attachment_post_id = $this->_create_image_attachment_from_GUID($guid, $migration_stage); |
|
| 1435 | - $created_attachment_post = true; |
|
| 1436 | - } |
|
| 1437 | - //double-check we actually have an attachment post |
|
| 1438 | - if ($attachment_post_id) { |
|
| 1439 | - update_post_meta($new_cpt_id, '_thumbnail_id', $attachment_post_id); |
|
| 1440 | - } else { |
|
| 1441 | - $migration_stage->add_error(sprintf(esc_html__("Could not update event image %s for CPT with ID %d, but attachments post ID is %d", |
|
| 1442 | - "event_espresso"), $guid, $new_cpt_id, $attachment_post_id)); |
|
| 1443 | - } |
|
| 1444 | - } |
|
| 1445 | - return $created_attachment_post; |
|
| 1446 | - } |
|
| 1447 | - |
|
| 1448 | - |
|
| 1449 | - |
|
| 1450 | - /** |
|
| 1451 | - * In 3.1, the event thumbnail image DOESN'T point to the orignal image, but instead |
|
| 1452 | - * to a large thumbnail (which has nearly the same GUID, except it adds "-{width}x{height}" before the filetype, |
|
| 1453 | - * or whatever dimensions it is. Eg 'http://mysite.com/image1-300x400.jpg' instead of |
|
| 1454 | - * 'http://mysite.com/image1.jpg' ). This function attempts to strip that off and get the original file, if it |
|
| 1455 | - * exists |
|
| 1456 | - * |
|
| 1457 | - * @param string $guid_in_old_event |
|
| 1458 | - * @return string either the original guid, or $guid_in_old_event if we couldn't figure out what the original was |
|
| 1459 | - */ |
|
| 1460 | - private function _get_original_guid($guid_in_old_event) |
|
| 1461 | - { |
|
| 1462 | - $original_guid = preg_replace('~-\d*x\d*\.~', '.', $guid_in_old_event, 1); |
|
| 1463 | - //do a head request to verify the file exists |
|
| 1464 | - $head_response = wp_remote_head($original_guid); |
|
| 1465 | - if ( ! $head_response instanceof WP_Error && $head_response['response']['message'] == 'OK') { |
|
| 1466 | - return $original_guid; |
|
| 1467 | - } else { |
|
| 1468 | - return $guid_in_old_event; |
|
| 1469 | - } |
|
| 1470 | - } |
|
| 1471 | - |
|
| 1472 | - |
|
| 1473 | - |
|
| 1474 | - /** |
|
| 1475 | - * Creates an image attachment post for the GUID. If the GUID points to a remote image, |
|
| 1476 | - * we download it to our uploads directory so that it can be properly processed (eg, creates different sizes of |
|
| 1477 | - * thumbnails) |
|
| 1478 | - * |
|
| 1479 | - * @param type $guid |
|
| 1480 | - * @param EE_Data_Migration_Script_Stage $migration_stage |
|
| 1481 | - * @return int |
|
| 1482 | - */ |
|
| 1483 | - private function _create_image_attachment_from_GUID($guid, EE_Data_Migration_Script_Stage $migration_stage) |
|
| 1484 | - { |
|
| 1485 | - if ( ! $guid) { |
|
| 1486 | - $migration_stage->add_error(sprintf(esc_html__("Cannot create image attachment for a blank GUID!", |
|
| 1487 | - "event_espresso"))); |
|
| 1488 | - return 0; |
|
| 1489 | - } |
|
| 1490 | - $wp_filetype = wp_check_filetype(basename($guid), null); |
|
| 1491 | - $wp_upload_dir = wp_upload_dir(); |
|
| 1492 | - //if the file is located remotely, download it to our uploads DIR, because wp_genereate_attachmnet_metadata needs the file to be local |
|
| 1493 | - if (strpos($guid, $wp_upload_dir['url']) === false) { |
|
| 1494 | - //image is located remotely. download it and place it in the uploads directory |
|
| 1495 | - if ( ! is_readable($guid)) { |
|
| 1496 | - $migration_stage->add_error(sprintf(esc_html__("Could not create image attachment from non-existent file: %s", |
|
| 1497 | - "event_espresso"), $guid)); |
|
| 1498 | - return 0; |
|
| 1499 | - } |
|
| 1500 | - $contents = file_get_contents($guid); |
|
| 1501 | - if ($contents === false) { |
|
| 1502 | - $migration_stage->add_error(sprintf(esc_html__("Could not read image at %s, and therefore couldnt create an attachment post for it.", |
|
| 1503 | - "event_espresso"), $guid)); |
|
| 1504 | - return false; |
|
| 1505 | - } |
|
| 1506 | - $local_filepath = $wp_upload_dir['path'] . DS . basename($guid); |
|
| 1507 | - $savefile = fopen($local_filepath, 'w'); |
|
| 1508 | - fwrite($savefile, $contents); |
|
| 1509 | - fclose($savefile); |
|
| 1510 | - $guid = str_replace($wp_upload_dir['path'], $wp_upload_dir['url'], $local_filepath); |
|
| 1511 | - } else { |
|
| 1512 | - $local_filepath = str_replace($wp_upload_dir['url'], $wp_upload_dir['path'], $guid); |
|
| 1513 | - } |
|
| 1514 | - $attachment = array( |
|
| 1515 | - 'guid' => $guid, |
|
| 1516 | - 'post_mime_type' => $wp_filetype['type'], |
|
| 1517 | - 'post_title' => preg_replace('/\.[^.]+$/', '', basename($guid)), |
|
| 1518 | - 'post_content' => '', |
|
| 1519 | - 'post_status' => 'inherit', |
|
| 1520 | - ); |
|
| 1521 | - $attach_id = wp_insert_attachment($attachment, $guid); |
|
| 1522 | - if ( ! $attach_id) { |
|
| 1523 | - $migration_stage->add_error(sprintf(esc_html__("Could not create image attachment post from image '%s'. Attachment data was %s.", |
|
| 1524 | - "event_espresso"), $guid, $this->_json_encode($attachment))); |
|
| 1525 | - return $attach_id; |
|
| 1526 | - } |
|
| 1527 | - // you must first include the image.php file |
|
| 1528 | - // for the function wp_generate_attachment_metadata() to work |
|
| 1529 | - require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
| 1530 | - $attach_data = wp_generate_attachment_metadata($attach_id, $local_filepath); |
|
| 1531 | - if ( ! $attach_data) { |
|
| 1532 | - $migration_stage->add_error(sprintf(esc_html__("Coudl not genereate attachment metadata for attachment post %d with filepath %s and GUID %s. Please check the file was downloaded properly.", |
|
| 1533 | - "event_espresso"), $attach_id, $local_filepath, $guid)); |
|
| 1534 | - return $attach_id; |
|
| 1535 | - } |
|
| 1536 | - $metadata_save_result = wp_update_attachment_metadata($attach_id, $attach_data); |
|
| 1537 | - if ( ! $metadata_save_result) { |
|
| 1538 | - $migration_stage->add_error(sprintf(esc_html__("Could not update attachment metadata for attachment %d with data %s", |
|
| 1539 | - "event_espresso"), $attach_id, $this->_json_encode($attach_data))); |
|
| 1540 | - } |
|
| 1541 | - return $attach_id; |
|
| 1542 | - } |
|
| 1543 | - |
|
| 1544 | - |
|
| 1545 | - |
|
| 1546 | - /** |
|
| 1547 | - * Finds the attachment post containing info about an image attachment given the GUID (link to the image itself), |
|
| 1548 | - * and returns its ID. |
|
| 1549 | - * |
|
| 1550 | - * @global type $wpdb |
|
| 1551 | - * @param string $guid |
|
| 1552 | - * @return int |
|
| 1553 | - */ |
|
| 1554 | - private function _get_image_attachment_id_by_GUID($guid) |
|
| 1555 | - { |
|
| 1556 | - global $wpdb; |
|
| 1557 | - $attachment_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid=%s LIMIT 1", $guid)); |
|
| 1558 | - return $attachment_id; |
|
| 1559 | - } |
|
| 1560 | - |
|
| 1561 | - |
|
| 1562 | - |
|
| 1563 | - /** |
|
| 1564 | - * Returns a mysql-formatted DATETIME in UTC time, given a $DATETIME_string |
|
| 1565 | - * (and optionally a timezone; if none is given, the wp DEFAULT is used) |
|
| 1566 | - * |
|
| 1567 | - * @param EE_Data_Migration_Script_base $stage |
|
| 1568 | - * @param array $row_of_data , the row from the DB (as an array) we're trying to find the |
|
| 1569 | - * UTC time for |
|
| 1570 | - * @param string $DATETIME_string |
|
| 1571 | - * @param string $timezone |
|
| 1572 | - * @return string |
|
| 1573 | - */ |
|
| 1574 | - public function convert_date_string_to_utc( |
|
| 1575 | - EE_Data_Migration_Script_Stage $stage, |
|
| 1576 | - $row_of_data, |
|
| 1577 | - $DATETIME_string, |
|
| 1578 | - $timezone = null |
|
| 1579 | - ) { |
|
| 1580 | - $original_tz = $timezone; |
|
| 1581 | - if ( ! $timezone) { |
|
| 1582 | - $timezone = $this->_get_wp_timezone(); |
|
| 1583 | - } |
|
| 1584 | - if ( ! $timezone) { |
|
| 1585 | - $stage->add_error(sprintf(esc_html__("Could not find timezone given %s for %s", "event_espresso"), $original_tz, |
|
| 1586 | - $row_of_data)); |
|
| 1587 | - $timezone = 'UTC'; |
|
| 1588 | - } |
|
| 1589 | - try { |
|
| 1590 | - $date_obj = new DateTime($DATETIME_string, new DateTimeZone($timezone)); |
|
| 1591 | - $date_obj->setTimezone(new DateTimeZone('UTC')); |
|
| 1592 | - } catch (Exception $e) { |
|
| 1593 | - $stage->add_error(sprintf(esc_html__("Could not convert time string '%s' using timezone '%s' into a proper DATETIME. Using current time instead.", |
|
| 1594 | - "event_espresso"), $DATETIME_string, $timezone)); |
|
| 1595 | - $date_obj = new DateTime(); |
|
| 1596 | - } |
|
| 1597 | - return $date_obj->format('Y-m-d H:i:s'); |
|
| 1598 | - } |
|
| 1599 | - |
|
| 1600 | - |
|
| 1601 | - |
|
| 1602 | - /** |
|
| 1603 | - * Gets the DEFAULT timezone string from wordpress (even if they set a gmt offset) |
|
| 1604 | - * |
|
| 1605 | - * @return string |
|
| 1606 | - */ |
|
| 1607 | - private function _get_wp_timezone() |
|
| 1608 | - { |
|
| 1609 | - $timezone = empty($timezone) ? get_option('timezone_string') : $timezone; |
|
| 1610 | - //if timezone is STILL empty then let's get the GMT offset and then set the timezone_string using our converter |
|
| 1611 | - if (empty($timezone)) { |
|
| 1612 | - //let's get a the WordPress UTC offset |
|
| 1613 | - $offset = get_option('gmt_offset'); |
|
| 1614 | - $timezone = $this->timezone_convert_to_string_from_offset($offset); |
|
| 1615 | - } |
|
| 1616 | - return $timezone; |
|
| 1617 | - } |
|
| 1618 | - |
|
| 1619 | - |
|
| 1620 | - |
|
| 1621 | - /** |
|
| 1622 | - * Gets the wordpress timezone string from a UTC offset |
|
| 1623 | - * |
|
| 1624 | - * @param int $offset |
|
| 1625 | - * @return boolean |
|
| 1626 | - */ |
|
| 1627 | - private function timezone_convert_to_string_from_offset($offset) |
|
| 1628 | - { |
|
| 1629 | - //shamelessly taken from bottom comment at http://ca1.php.net/manual/en/function.timezone-name-from-abbr.php because timezone_name_from_abbr() did NOT work as expected - its not reliable |
|
| 1630 | - $offset *= 3600; // convert hour offset to seconds |
|
| 1631 | - $abbrarray = timezone_abbreviations_list(); |
|
| 1632 | - foreach ($abbrarray as $abbr) { |
|
| 1633 | - foreach ($abbr as $city) { |
|
| 1634 | - if ($city['offset'] == $offset) { |
|
| 1635 | - return $city['timezone_id']; |
|
| 1636 | - } |
|
| 1637 | - } |
|
| 1638 | - } |
|
| 1639 | - return false; |
|
| 1640 | - } |
|
| 1641 | - |
|
| 1642 | - |
|
| 1643 | - |
|
| 1644 | - public function migration_page_hooks() |
|
| 1645 | - { |
|
| 1646 | - add_filter( |
|
| 1647 | - 'FHEE__ee_migration_page__header', |
|
| 1648 | - array($this, '_migrate_page_hook_simplify_version_strings'), |
|
| 1649 | - 10, |
|
| 1650 | - 3 |
|
| 1651 | - ); |
|
| 1652 | - add_filter( |
|
| 1653 | - 'FHEE__ee_migration_page__p_after_header', |
|
| 1654 | - array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1655 | - 10, |
|
| 1656 | - 2 |
|
| 1657 | - ); |
|
| 1658 | - add_filter( |
|
| 1659 | - 'FHEE__ee_migration_page__option_1_main', |
|
| 1660 | - array($this, '_migrate_page_hook_simplify_version_strings'), |
|
| 1661 | - 10, |
|
| 1662 | - 3 |
|
| 1663 | - ); |
|
| 1664 | - add_filter( |
|
| 1665 | - 'FHEE__ee_migration_page__option_1_button_text', |
|
| 1666 | - array($this, '_migrate_page_hook_simplify_version_strings'), |
|
| 1667 | - 10, |
|
| 1668 | - 3 |
|
| 1669 | - ); |
|
| 1670 | - add_action( |
|
| 1671 | - 'AHEE__ee_migration_page__option_1_extra_details', |
|
| 1672 | - array($this, '_migration_page_hook_option_1_extra_details'), |
|
| 1673 | - 10, |
|
| 1674 | - 3 |
|
| 1675 | - ); |
|
| 1676 | - add_filter( |
|
| 1677 | - 'FHEE__ee_migration_page__option_2_main', |
|
| 1678 | - array($this, '_migrate_page_hook_simplify_version_strings'), |
|
| 1679 | - 10, |
|
| 1680 | - 4 |
|
| 1681 | - ); |
|
| 1682 | - add_filter( |
|
| 1683 | - 'FHEE__ee_migration_page__option_2_button_text', |
|
| 1684 | - array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1685 | - 10, |
|
| 1686 | - 2 |
|
| 1687 | - ); |
|
| 1688 | - add_filter( |
|
| 1689 | - 'FHEE__ee_migration_page__option_2_details', |
|
| 1690 | - array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1691 | - 10, |
|
| 1692 | - 2 |
|
| 1693 | - ); |
|
| 1694 | - add_action( |
|
| 1695 | - 'AHEE__ee_migration_page__after_migration_options_table', |
|
| 1696 | - array($this, '_migration_page_hook_after_migration_options_table') |
|
| 1697 | - ); |
|
| 1698 | - add_filter( |
|
| 1699 | - 'FHEE__ee_migration_page__done_migration_header', |
|
| 1700 | - array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1701 | - 10, |
|
| 1702 | - 2 |
|
| 1703 | - ); |
|
| 1704 | - add_filter( |
|
| 1705 | - 'FHEE__ee_migration_page__p_after_done_migration_header', |
|
| 1706 | - array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1707 | - 10, |
|
| 1708 | - 2 |
|
| 1709 | - ); |
|
| 1710 | - add_filter( |
|
| 1711 | - 'FHEE__ee_migration_page__migration_options_template', |
|
| 1712 | - array($this,'use_migration_options_from_ee3_template') |
|
| 1713 | - ); |
|
| 1714 | - } |
|
| 1715 | - |
|
| 1716 | - |
|
| 1717 | - |
|
| 1718 | - public function _migrate_page_hook_simplify_version_strings( |
|
| 1719 | - $old_content, |
|
| 1720 | - $current_db_state, |
|
| 1721 | - $next_db_state, |
|
| 1722 | - $ultimate_db_state = null |
|
| 1723 | - ) { |
|
| 1724 | - return str_replace(array($current_db_state, $next_db_state, $ultimate_db_state), |
|
| 1725 | - array(esc_html__('EE3', 'event_espresso'), esc_html__('EE4', 'event_espresso'), esc_html__("EE4", 'event_espresso')), |
|
| 1726 | - $old_content); |
|
| 1727 | - } |
|
| 1728 | - |
|
| 1729 | - |
|
| 1730 | - |
|
| 1731 | - public function _migration_page_hook_simplify_next_db_state($old_content, $next_db_state) |
|
| 1732 | - { |
|
| 1733 | - return str_replace($next_db_state, esc_html__("EE4", 'event_espresso'), $old_content); |
|
| 1734 | - } |
|
| 1735 | - |
|
| 1736 | - |
|
| 1737 | - |
|
| 1738 | - public function _migration_page_hook_option_1_extra_details() |
|
| 1739 | - { |
|
| 1740 | - ?> |
|
| 1063 | + if ( ! $state) { |
|
| 1064 | + //insert a new one then |
|
| 1065 | + $cols_n_values = array( |
|
| 1066 | + 'CNT_ISO' => $country_iso, |
|
| 1067 | + 'STA_abbrev' => substr($state_name, 0, 6), |
|
| 1068 | + 'STA_name' => $state_name, |
|
| 1069 | + 'STA_active' => true, |
|
| 1070 | + ); |
|
| 1071 | + $data_types = array( |
|
| 1072 | + '%s',//CNT_ISO |
|
| 1073 | + '%s',//STA_abbrev |
|
| 1074 | + '%s',//STA_name |
|
| 1075 | + '%d',//STA_active |
|
| 1076 | + ); |
|
| 1077 | + $success = $wpdb->insert($state_table, $cols_n_values, $data_types); |
|
| 1078 | + if ( ! $success) { |
|
| 1079 | + throw new EE_Error($this->_create_error_message_for_db_insertion('N/A', |
|
| 1080 | + array('state' => $state_name, 'country_id' => $country_name), $state_table, $cols_n_values, |
|
| 1081 | + $data_types)); |
|
| 1082 | + } |
|
| 1083 | + $state = $cols_n_values; |
|
| 1084 | + $state['STA_ID'] = $wpdb->insert_id; |
|
| 1085 | + } |
|
| 1086 | + return $state; |
|
| 1087 | + } |
|
| 1088 | + |
|
| 1089 | + |
|
| 1090 | + |
|
| 1091 | + /** |
|
| 1092 | + * Fixes times like "5:00 PM" into the expected 24-hour format "17:00". |
|
| 1093 | + * THis is actually just copied from the 3.1 JSON API because it needed to do the exact same thing |
|
| 1094 | + * |
|
| 1095 | + * @param type $timeString |
|
| 1096 | + * @return string in the php DATETIME format: "G:i" (24-hour format hour with leading zeros, a colon, and minutes |
|
| 1097 | + * with leading zeros) |
|
| 1098 | + */ |
|
| 1099 | + public function convertTimeFromAMPM($timeString) |
|
| 1100 | + { |
|
| 1101 | + $matches = array(); |
|
| 1102 | + preg_match("~(\\d*):(\\d*)~", $timeString, $matches); |
|
| 1103 | + if ( ! $matches || count($matches) < 3) { |
|
| 1104 | + $hour = '00'; |
|
| 1105 | + $minutes = '00'; |
|
| 1106 | + } else { |
|
| 1107 | + $hour = intval($matches[1]); |
|
| 1108 | + $minutes = $matches[2]; |
|
| 1109 | + } |
|
| 1110 | + if (strpos($timeString, 'PM') || strpos($timeString, 'pm')) { |
|
| 1111 | + $hour = intval($hour) + 12; |
|
| 1112 | + } |
|
| 1113 | + $hour = str_pad("$hour", 2, '0', STR_PAD_LEFT); |
|
| 1114 | + $minutes = str_pad("$minutes", 2, '0', STR_PAD_LEFT); |
|
| 1115 | + return "$hour:$minutes"; |
|
| 1116 | + } |
|
| 1117 | + |
|
| 1118 | + |
|
| 1119 | + |
|
| 1120 | + /** |
|
| 1121 | + * Gets the ISO3 fora country given its 3.1 country ID. |
|
| 1122 | + * |
|
| 1123 | + * @param int $country_id |
|
| 1124 | + * @return string the country's ISO3 code |
|
| 1125 | + */ |
|
| 1126 | + public function get_iso_from_3_1_country_id($country_id) |
|
| 1127 | + { |
|
| 1128 | + $old_countries = array( |
|
| 1129 | + array(64, 'United States', 'US', 'USA', 1), |
|
| 1130 | + array(15, 'Australia', 'AU', 'AUS', 1), |
|
| 1131 | + array(39, 'Canada', 'CA', 'CAN', 1), |
|
| 1132 | + array(171, 'United Kingdom', 'GB', 'GBR', 1), |
|
| 1133 | + array(70, 'France', 'FR', 'FRA', 2), |
|
| 1134 | + array(111, 'Italy', 'IT', 'ITA', 2), |
|
| 1135 | + array(63, 'Spain', 'ES', 'ESP', 2), |
|
| 1136 | + array(1, 'Afghanistan', 'AF', 'AFG', 1), |
|
| 1137 | + array(2, 'Albania', 'AL', 'ALB', 1), |
|
| 1138 | + array(3, 'Germany', 'DE', 'DEU', 2), |
|
| 1139 | + array(198, 'Switzerland', 'CH', 'CHE', 1), |
|
| 1140 | + array(87, 'Netherlands', 'NL', 'NLD', 2), |
|
| 1141 | + array(197, 'Sweden', 'SE', 'SWE', 1), |
|
| 1142 | + array(230, 'Akrotiri and Dhekelia', 'CY', 'CYP', 2), |
|
| 1143 | + array(4, 'Andorra', 'AD', 'AND', 2), |
|
| 1144 | + array(5, 'Angola', 'AO', 'AGO', 1), |
|
| 1145 | + array(6, 'Anguilla', 'AI', 'AIA', 1), |
|
| 1146 | + array(7, 'Antarctica', 'AQ', 'ATA', 1), |
|
| 1147 | + array(8, 'Antigua and Barbuda', 'AG', 'ATG', 1), |
|
| 1148 | + array(10, 'Saudi Arabia', 'SA', 'SAU', 1), |
|
| 1149 | + array(11, 'Algeria', 'DZ', 'DZA', 1), |
|
| 1150 | + array(12, 'Argentina', 'AR', 'ARG', 1), |
|
| 1151 | + array(13, 'Armenia', 'AM', 'ARM', 1), |
|
| 1152 | + array(14, 'Aruba', 'AW', 'ABW', 1), |
|
| 1153 | + array(16, 'Austria', 'AT', 'AUT', 2), |
|
| 1154 | + array(17, 'Azerbaijan', 'AZ', 'AZE', 1), |
|
| 1155 | + array(18, 'Bahamas', 'BS', 'BHS', 1), |
|
| 1156 | + array(19, 'Bahrain', 'BH', 'BHR', 1), |
|
| 1157 | + array(20, 'Bangladesh', 'BD', 'BGD', 1), |
|
| 1158 | + array(21, 'Barbados', 'BB', 'BRB', 1), |
|
| 1159 | + array(22, 'Belgium ', 'BE', 'BEL', 2), |
|
| 1160 | + array(23, 'Belize', 'BZ', 'BLZ', 1), |
|
| 1161 | + array(24, 'Benin', 'BJ', 'BEN', 1), |
|
| 1162 | + array(25, 'Bermudas', 'BM', 'BMU', 1), |
|
| 1163 | + array(26, 'Belarus', 'BY', 'BLR', 1), |
|
| 1164 | + array(27, 'Bolivia', 'BO', 'BOL', 1), |
|
| 1165 | + array(28, 'Bosnia and Herzegovina', 'BA', 'BIH', 1), |
|
| 1166 | + array(29, 'Botswana', 'BW', 'BWA', 1), |
|
| 1167 | + array(96, 'Bouvet Island', 'BV', 'BVT', 1), |
|
| 1168 | + array(30, 'Brazil', 'BR', 'BRA', 1), |
|
| 1169 | + array(31, 'Brunei', 'BN', 'BRN', 1), |
|
| 1170 | + array(32, 'Bulgaria', 'BG', 'BGR', 1), |
|
| 1171 | + array(33, 'Burkina Faso', 'BF', 'BFA', 1), |
|
| 1172 | + array(34, 'Burundi', 'BI', 'BDI', 1), |
|
| 1173 | + array(35, 'Bhutan', 'BT', 'BTN', 1), |
|
| 1174 | + array(36, 'Cape Verde', 'CV', 'CPV', 1), |
|
| 1175 | + array(37, 'Cambodia', 'KH', 'KHM', 1), |
|
| 1176 | + array(38, 'Cameroon', 'CM', 'CMR', 1), |
|
| 1177 | + array(98, 'Cayman Islands', 'KY', 'CYM', 1), |
|
| 1178 | + array(172, 'Central African Republic', 'CF', 'CAF', 1), |
|
| 1179 | + array(40, 'Chad', 'TD', 'TCD', 1), |
|
| 1180 | + array(41, 'Chile', 'CL', 'CHL', 1), |
|
| 1181 | + array(42, 'China', 'CN', 'CHN', 1), |
|
| 1182 | + array(105, 'Christmas Island', 'CX', 'CXR', 1), |
|
| 1183 | + array(43, 'Cyprus', 'CY', 'CYP', 2), |
|
| 1184 | + array(99, 'Cocos Island', 'CC', 'CCK', 1), |
|
| 1185 | + array(100, 'Cook Islands', 'CK', 'COK', 1), |
|
| 1186 | + array(44, 'Colombia', 'CO', 'COL', 1), |
|
| 1187 | + array(45, 'Comoros', 'KM', 'COM', 1), |
|
| 1188 | + array(46, 'Congo', 'CG', 'COG', 1), |
|
| 1189 | + array(47, 'North Korea', 'KP', 'PRK', 1), |
|
| 1190 | + array(50, 'Costa Rica', 'CR', 'CRI', 1), |
|
| 1191 | + array(51, 'Croatia', 'HR', 'HRV', 1), |
|
| 1192 | + array(52, 'Cuba', 'CU', 'CUB', 1), |
|
| 1193 | + array(173, 'Czech Republic', 'CZ', 'CZE', 1), |
|
| 1194 | + array(53, 'Denmark', 'DK', 'DNK', 1), |
|
| 1195 | + array(54, 'Djibouti', 'DJ', 'DJI', 1), |
|
| 1196 | + array(55, 'Dominica', 'DM', 'DMA', 1), |
|
| 1197 | + array(174, 'Dominican Republic', 'DO', 'DOM', 1), |
|
| 1198 | + array(56, 'Ecuador', 'EC', 'ECU', 1), |
|
| 1199 | + array(57, 'Egypt', 'EG', 'EGY', 1), |
|
| 1200 | + array(58, 'El Salvador', 'SV', 'SLV', 1), |
|
| 1201 | + array(60, 'Eritrea', 'ER', 'ERI', 1), |
|
| 1202 | + array(61, 'Slovakia', 'SK', 'SVK', 2), |
|
| 1203 | + array(62, 'Slovenia', 'SI', 'SVN', 2), |
|
| 1204 | + array(65, 'Estonia', 'EE', 'EST', 2), |
|
| 1205 | + array(66, 'Ethiopia', 'ET', 'ETH', 1), |
|
| 1206 | + array(102, 'Faroe islands', 'FO', 'FRO', 1), |
|
| 1207 | + array(103, 'Falkland Islands', 'FK', 'FLK', 1), |
|
| 1208 | + array(67, 'Fiji', 'FJ', 'FJI', 1), |
|
| 1209 | + array(69, 'Finland', 'FI', 'FIN', 2), |
|
| 1210 | + array(71, 'Gabon', 'GA', 'GAB', 1), |
|
| 1211 | + array(72, 'Gambia', 'GM', 'GMB', 1), |
|
| 1212 | + array(73, 'Georgia', 'GE', 'GEO', 1), |
|
| 1213 | + array(74, 'Ghana', 'GH', 'GHA', 1), |
|
| 1214 | + array(75, 'Gibraltar', 'GI', 'GIB', 1), |
|
| 1215 | + array(76, 'Greece', 'GR', 'GRC', 2), |
|
| 1216 | + array(77, 'Grenada', 'GD', 'GRD', 1), |
|
| 1217 | + array(78, 'Greenland', 'GL', 'GRL', 1), |
|
| 1218 | + array(79, 'Guadeloupe', 'GP', 'GLP', 1), |
|
| 1219 | + array(80, 'Guam', 'GU', 'GUM', 1), |
|
| 1220 | + array(81, 'Guatemala', 'GT', 'GTM', 1), |
|
| 1221 | + array(82, 'Guinea', 'GN', 'GIN', 1), |
|
| 1222 | + array(83, 'Equatorial Guinea', 'GQ', 'GNQ', 1), |
|
| 1223 | + array(84, 'Guinea-Bissau', 'GW', 'GNB', 1), |
|
| 1224 | + array(85, 'Guyana', 'GY', 'GUY', 1), |
|
| 1225 | + array(86, 'Haiti', 'HT', 'HTI', 1), |
|
| 1226 | + array(88, 'Honduras', 'HN', 'HND', 1), |
|
| 1227 | + array(89, 'Hong Kong', 'HK', 'HKG', 1), |
|
| 1228 | + array(90, 'Hungary', 'HU', 'HUN', 1), |
|
| 1229 | + array(91, 'India', 'IN', 'IND', 1), |
|
| 1230 | + array(205, 'British Indian Ocean Territory', 'IO', 'IOT', 1), |
|
| 1231 | + array(92, 'Indonesia', 'ID', 'IDN', 1), |
|
| 1232 | + array(93, 'Iraq', 'IQ', 'IRQ', 1), |
|
| 1233 | + array(94, 'Iran', 'IR', 'IRN', 1), |
|
| 1234 | + array(95, 'Ireland', 'IE', 'IRL', 2), |
|
| 1235 | + array(97, 'Iceland', 'IS', 'ISL', 1), |
|
| 1236 | + array(110, 'Israel', 'IL', 'ISR', 1), |
|
| 1237 | + array(49, 'Ivory Coast ', 'CI', 'CIV', 1), |
|
| 1238 | + array(112, 'Jamaica', 'JM', 'JAM', 1), |
|
| 1239 | + array(113, 'Japan', 'JP', 'JPN', 1), |
|
| 1240 | + array(114, 'Jordan', 'JO', 'JOR', 1), |
|
| 1241 | + array(115, 'Kazakhstan', 'KZ', 'KAZ', 1), |
|
| 1242 | + array(116, 'Kenya', 'KE', 'KEN', 1), |
|
| 1243 | + array(117, 'Kyrgyzstan', 'KG', 'KGZ', 1), |
|
| 1244 | + array(118, 'Kiribati', 'KI', 'KIR', 1), |
|
| 1245 | + array(48, 'South Korea', 'KR', 'KOR', 1), |
|
| 1246 | + array(228, 'Kosovo', 'XK', 'XKV', 2), |
|
| 1247 | + // there is no official ISO code for Kosovo yet (http://geonames.wordpress.com/2010/03/08/xk-country-code-for-kosovo/) so using a temporary country code and a modified 3 character code for ISO code -- this should be updated if/when Kosovo gets its own ISO code |
|
| 1248 | + array(119, 'Kuwait', 'KW', 'KWT', 1), |
|
| 1249 | + array(120, 'Laos', 'LA', 'LAO', 1), |
|
| 1250 | + array(121, 'Latvia', 'LV', 'LVA', 2), |
|
| 1251 | + array(122, 'Lesotho', 'LS', 'LSO', 1), |
|
| 1252 | + array(123, 'Lebanon', 'LB', 'LBN', 1), |
|
| 1253 | + array(124, 'Liberia', 'LR', 'LBR', 1), |
|
| 1254 | + array(125, 'Libya', 'LY', 'LBY', 1), |
|
| 1255 | + array(126, 'Liechtenstein', 'LI', 'LIE', 1), |
|
| 1256 | + array(127, 'Lithuania', 'LT', 'LTU', 2), |
|
| 1257 | + array(128, 'Luxemburg', 'LU', 'LUX', 2), |
|
| 1258 | + array(129, 'Macao', 'MO', 'MAC', 1), |
|
| 1259 | + array(130, 'Macedonia', 'MK', 'MKD', 1), |
|
| 1260 | + array(131, 'Madagascar', 'MG', 'MDG', 1), |
|
| 1261 | + array(132, 'Malaysia', 'MY', 'MYS', 1), |
|
| 1262 | + array(133, 'Malawi', 'MW', 'MWI', 1), |
|
| 1263 | + array(134, 'Maldivas', 'MV', 'MDV', 1), |
|
| 1264 | + array(135, 'Mali', 'ML', 'MLI', 1), |
|
| 1265 | + array(136, 'Malta', 'MT', 'MLT', 2), |
|
| 1266 | + array(101, 'Northern Marianas', 'MP', 'MNP', 1), |
|
| 1267 | + array(137, 'Morocco', 'MA', 'MAR', 1), |
|
| 1268 | + array(104, 'Marshall islands', 'MH', 'MHL', 1), |
|
| 1269 | + array(138, 'Martinique', 'MQ', 'MTQ', 1), |
|
| 1270 | + array(139, 'Mauritius', 'MU', 'MUS', 1), |
|
| 1271 | + array(140, 'Mauritania', 'MR', 'MRT', 1), |
|
| 1272 | + array(141, 'Mayote', 'YT', 'MYT', 2), |
|
| 1273 | + array(142, 'Mexico', 'MX', 'MEX', 1), |
|
| 1274 | + array(143, 'Micronesia', 'FM', 'FSM', 1), |
|
| 1275 | + array(144, 'Moldova', 'MD', 'MDA', 1), |
|
| 1276 | + array(145, 'Monaco', 'MC', 'MCO', 2), |
|
| 1277 | + array(146, 'Mongolia', 'MN', 'MNG', 1), |
|
| 1278 | + array(147, 'Montserrat', 'MS', 'MSR', 1), |
|
| 1279 | + array(227, 'Montenegro', 'ME', 'MNE', 2), |
|
| 1280 | + array(148, 'Mozambique', 'MZ', 'MOZ', 1), |
|
| 1281 | + array(149, 'Myanmar', 'MM', 'MMR', 1), |
|
| 1282 | + array(150, 'Namibia', 'NA', 'NAM', 1), |
|
| 1283 | + array(151, 'Nauru', 'NR', 'NRU', 1), |
|
| 1284 | + array(152, 'Nepal', 'NP', 'NPL', 1), |
|
| 1285 | + array(9, 'Netherlands Antilles', 'AN', 'ANT', 1), |
|
| 1286 | + array(153, 'Nicaragua', 'NI', 'NIC', 1), |
|
| 1287 | + array(154, 'Niger', 'NE', 'NER', 1), |
|
| 1288 | + array(155, 'Nigeria', 'NG', 'NGA', 1), |
|
| 1289 | + array(156, 'Niue', 'NU', 'NIU', 1), |
|
| 1290 | + array(157, 'Norway', 'NO', 'NOR', 1), |
|
| 1291 | + array(158, 'New Caledonia', 'NC', 'NCL', 1), |
|
| 1292 | + array(159, 'New Zealand', 'NZ', 'NZL', 1), |
|
| 1293 | + array(160, 'Oman', 'OM', 'OMN', 1), |
|
| 1294 | + array(161, 'Pakistan', 'PK', 'PAK', 1), |
|
| 1295 | + array(162, 'Palau', 'PW', 'PLW', 1), |
|
| 1296 | + array(163, 'Panama', 'PA', 'PAN', 1), |
|
| 1297 | + array(164, 'Papua New Guinea', 'PG', 'PNG', 1), |
|
| 1298 | + array(165, 'Paraguay', 'PY', 'PRY', 1), |
|
| 1299 | + array(166, 'Peru', 'PE', 'PER', 1), |
|
| 1300 | + array(68, 'Philippines', 'PH', 'PHL', 1), |
|
| 1301 | + array(167, 'Poland', 'PL', 'POL', 1), |
|
| 1302 | + array(168, 'Portugal', 'PT', 'PRT', 2), |
|
| 1303 | + array(169, 'Puerto Rico', 'PR', 'PRI', 1), |
|
| 1304 | + array(170, 'Qatar', 'QA', 'QAT', 1), |
|
| 1305 | + array(176, 'Rwanda', 'RW', 'RWA', 1), |
|
| 1306 | + array(177, 'Romania', 'RO', 'ROM', 2), |
|
| 1307 | + array(178, 'Russia', 'RU', 'RUS', 1), |
|
| 1308 | + array(229, 'Saint Pierre and Miquelon', 'PM', 'SPM', 2), |
|
| 1309 | + array(180, 'Samoa', 'WS', 'WSM', 1), |
|
| 1310 | + array(181, 'American Samoa', 'AS', 'ASM', 1), |
|
| 1311 | + array(183, 'San Marino', 'SM', 'SMR', 2), |
|
| 1312 | + array(184, 'Saint Vincent and the Grenadines', 'VC', 'VCT', 1), |
|
| 1313 | + array(185, 'Saint Helena', 'SH', 'SHN', 1), |
|
| 1314 | + array(186, 'Saint Lucia', 'LC', 'LCA', 1), |
|
| 1315 | + array(188, 'Senegal', 'SN', 'SEN', 1), |
|
| 1316 | + array(189, 'Seychelles', 'SC', 'SYC', 1), |
|
| 1317 | + array(190, 'Sierra Leona', 'SL', 'SLE', 1), |
|
| 1318 | + array(191, 'Singapore', 'SG', 'SGP', 1), |
|
| 1319 | + array(192, 'Syria', 'SY', 'SYR', 1), |
|
| 1320 | + array(193, 'Somalia', 'SO', 'SOM', 1), |
|
| 1321 | + array(194, 'Sri Lanka', 'LK', 'LKA', 1), |
|
| 1322 | + array(195, 'South Africa', 'ZA', 'ZAF', 1), |
|
| 1323 | + array(196, 'Sudan', 'SD', 'SDN', 1), |
|
| 1324 | + array(199, 'Suriname', 'SR', 'SUR', 1), |
|
| 1325 | + array(200, 'Swaziland', 'SZ', 'SWZ', 1), |
|
| 1326 | + array(201, 'Thailand', 'TH', 'THA', 1), |
|
| 1327 | + array(202, 'Taiwan', 'TW', 'TWN', 1), |
|
| 1328 | + array(203, 'Tanzania', 'TZ', 'TZA', 1), |
|
| 1329 | + array(204, 'Tajikistan', 'TJ', 'TJK', 1), |
|
| 1330 | + array(206, 'Timor-Leste', 'TL', 'TLS', 1), |
|
| 1331 | + array(207, 'Togo', 'TG', 'TGO', 1), |
|
| 1332 | + array(208, 'Tokelau', 'TK', 'TKL', 1), |
|
| 1333 | + array(209, 'Tonga', 'TO', 'TON', 1), |
|
| 1334 | + array(210, 'Trinidad and Tobago', 'TT', 'TTO', 1), |
|
| 1335 | + array(211, 'Tunisia', 'TN', 'TUN', 1), |
|
| 1336 | + array(212, 'Turkmenistan', 'TM', 'TKM', 1), |
|
| 1337 | + array(213, 'Turkey', 'TR', 'TUR', 1), |
|
| 1338 | + array(214, 'Tuvalu', 'TV', 'TUV', 1), |
|
| 1339 | + array(215, 'Ukraine', 'UA', 'UKR', 1), |
|
| 1340 | + array(216, 'Uganda', 'UG', 'UGA', 1), |
|
| 1341 | + array(59, 'United Arab Emirates', 'AE', 'ARE', 1), |
|
| 1342 | + array(217, 'Uruguay', 'UY', 'URY', 1), |
|
| 1343 | + array(218, 'Uzbekistan', 'UZ', 'UZB', 1), |
|
| 1344 | + array(219, 'Vanuatu', 'VU', 'VUT', 1), |
|
| 1345 | + array(220, 'Vatican City', 'VA', 'VAT', 2), |
|
| 1346 | + array(221, 'Venezuela', 'VE', 'VEN', 1), |
|
| 1347 | + array(222, 'Vietnam', 'VN', 'VNM', 1), |
|
| 1348 | + array(108, 'Virgin Islands', 'VI', 'VIR', 1), |
|
| 1349 | + array(223, 'Yemen', 'YE', 'YEM', 1), |
|
| 1350 | + array(225, 'Zambia', 'ZM', 'ZMB', 1), |
|
| 1351 | + array(226, 'Zimbabwe', 'ZW', 'ZWE', 1), |
|
| 1352 | + ); |
|
| 1353 | + $country_iso = 'US'; |
|
| 1354 | + foreach ($old_countries as $country_array) { |
|
| 1355 | + //note: index 0 is the 3.1 country ID |
|
| 1356 | + if ($country_array[0] == $country_id) { |
|
| 1357 | + //note: index 2 is the ISO |
|
| 1358 | + $country_iso = $country_array[2]; |
|
| 1359 | + break; |
|
| 1360 | + } |
|
| 1361 | + } |
|
| 1362 | + return $country_iso; |
|
| 1363 | + } |
|
| 1364 | + |
|
| 1365 | + |
|
| 1366 | + |
|
| 1367 | + /** |
|
| 1368 | + * Gets the ISO3 for the |
|
| 1369 | + * |
|
| 1370 | + * @return string |
|
| 1371 | + */ |
|
| 1372 | + public function get_default_country_iso() |
|
| 1373 | + { |
|
| 1374 | + $old_org_options = get_option('events_organization_settings'); |
|
| 1375 | + $iso = $this->get_iso_from_3_1_country_id($old_org_options['organization_country']); |
|
| 1376 | + return $iso; |
|
| 1377 | + } |
|
| 1378 | + |
|
| 1379 | + |
|
| 1380 | + |
|
| 1381 | + /** |
|
| 1382 | + * Converst a 3.1 payment status to its equivalent 4.1 regisration status |
|
| 1383 | + * |
|
| 1384 | + * @param string $payment_status possible value for 3.1's evens_attendee.payment_status |
|
| 1385 | + * @param boolean $this_thing_required_pre_approval whether the thing we're considering (the general setting's |
|
| 1386 | + * DEFAULT payment status, the event's DEFAULT payment status, or |
|
| 1387 | + * the attendee's payment status) required pre-approval. |
|
| 1388 | + * @return string STS_ID for use in 4.1 |
|
| 1389 | + */ |
|
| 1390 | + public function convert_3_1_payment_status_to_4_1_STS_ID($payment_status, $this_thing_required_pre_approval = false) |
|
| 1391 | + { |
|
| 1392 | + //EE team can read the related discussion: https://app.asana.com/0/2400967562914/9418495544455 |
|
| 1393 | + if ($this_thing_required_pre_approval) { |
|
| 1394 | + return 'RNA'; |
|
| 1395 | + } else { |
|
| 1396 | + $mapping = $default_reg_stati_conversions = array( |
|
| 1397 | + 'Completed' => 'RAP', |
|
| 1398 | + '' => 'RPP', |
|
| 1399 | + 'Incomplete' => 'RPP', |
|
| 1400 | + 'Pending' => 'RAP', |
|
| 1401 | + //stati that only occurred on 3.1 attendees: |
|
| 1402 | + 'Payment Declined' => 'RPP', |
|
| 1403 | + 'Not Completed' => 'RPP', |
|
| 1404 | + 'Cancelled' => 'RPP', |
|
| 1405 | + 'Declined' => 'RPP', |
|
| 1406 | + ); |
|
| 1407 | + } |
|
| 1408 | + return isset($mapping[$payment_status]) ? $mapping[$payment_status] : 'RNA'; |
|
| 1409 | + } |
|
| 1410 | + |
|
| 1411 | + |
|
| 1412 | + |
|
| 1413 | + /** |
|
| 1414 | + * Makes sure the 3.1's image url is converted to an image attachment post to the 4.1 CPT event |
|
| 1415 | + * and sets it as the featured image on the CPT event |
|
| 1416 | + * |
|
| 1417 | + * @param type $old_event |
|
| 1418 | + * @param type $new_cpt_id |
|
| 1419 | + * @param EE_Data_Migration_Script_Stage $migration_stage the stage which called this, where errors should be added |
|
| 1420 | + * @return boolean whether or not we had to do the big job of creating an image attachment |
|
| 1421 | + */ |
|
| 1422 | + public function convert_image_url_to_attachment_and_attach_to_post( |
|
| 1423 | + $guid, |
|
| 1424 | + $new_cpt_id, |
|
| 1425 | + EE_Data_Migration_Script_Stage $migration_stage |
|
| 1426 | + ) { |
|
| 1427 | + $created_attachment_post = false; |
|
| 1428 | + $guid = $this->_get_original_guid($guid); |
|
| 1429 | + if ($guid) { |
|
| 1430 | + //check for an existing attachment post with this guid |
|
| 1431 | + $attachment_post_id = $this->_get_image_attachment_id_by_GUID($guid); |
|
| 1432 | + if ( ! $attachment_post_id) { |
|
| 1433 | + //post thumbnail with that GUID doesn't exist, we should create one |
|
| 1434 | + $attachment_post_id = $this->_create_image_attachment_from_GUID($guid, $migration_stage); |
|
| 1435 | + $created_attachment_post = true; |
|
| 1436 | + } |
|
| 1437 | + //double-check we actually have an attachment post |
|
| 1438 | + if ($attachment_post_id) { |
|
| 1439 | + update_post_meta($new_cpt_id, '_thumbnail_id', $attachment_post_id); |
|
| 1440 | + } else { |
|
| 1441 | + $migration_stage->add_error(sprintf(esc_html__("Could not update event image %s for CPT with ID %d, but attachments post ID is %d", |
|
| 1442 | + "event_espresso"), $guid, $new_cpt_id, $attachment_post_id)); |
|
| 1443 | + } |
|
| 1444 | + } |
|
| 1445 | + return $created_attachment_post; |
|
| 1446 | + } |
|
| 1447 | + |
|
| 1448 | + |
|
| 1449 | + |
|
| 1450 | + /** |
|
| 1451 | + * In 3.1, the event thumbnail image DOESN'T point to the orignal image, but instead |
|
| 1452 | + * to a large thumbnail (which has nearly the same GUID, except it adds "-{width}x{height}" before the filetype, |
|
| 1453 | + * or whatever dimensions it is. Eg 'http://mysite.com/image1-300x400.jpg' instead of |
|
| 1454 | + * 'http://mysite.com/image1.jpg' ). This function attempts to strip that off and get the original file, if it |
|
| 1455 | + * exists |
|
| 1456 | + * |
|
| 1457 | + * @param string $guid_in_old_event |
|
| 1458 | + * @return string either the original guid, or $guid_in_old_event if we couldn't figure out what the original was |
|
| 1459 | + */ |
|
| 1460 | + private function _get_original_guid($guid_in_old_event) |
|
| 1461 | + { |
|
| 1462 | + $original_guid = preg_replace('~-\d*x\d*\.~', '.', $guid_in_old_event, 1); |
|
| 1463 | + //do a head request to verify the file exists |
|
| 1464 | + $head_response = wp_remote_head($original_guid); |
|
| 1465 | + if ( ! $head_response instanceof WP_Error && $head_response['response']['message'] == 'OK') { |
|
| 1466 | + return $original_guid; |
|
| 1467 | + } else { |
|
| 1468 | + return $guid_in_old_event; |
|
| 1469 | + } |
|
| 1470 | + } |
|
| 1471 | + |
|
| 1472 | + |
|
| 1473 | + |
|
| 1474 | + /** |
|
| 1475 | + * Creates an image attachment post for the GUID. If the GUID points to a remote image, |
|
| 1476 | + * we download it to our uploads directory so that it can be properly processed (eg, creates different sizes of |
|
| 1477 | + * thumbnails) |
|
| 1478 | + * |
|
| 1479 | + * @param type $guid |
|
| 1480 | + * @param EE_Data_Migration_Script_Stage $migration_stage |
|
| 1481 | + * @return int |
|
| 1482 | + */ |
|
| 1483 | + private function _create_image_attachment_from_GUID($guid, EE_Data_Migration_Script_Stage $migration_stage) |
|
| 1484 | + { |
|
| 1485 | + if ( ! $guid) { |
|
| 1486 | + $migration_stage->add_error(sprintf(esc_html__("Cannot create image attachment for a blank GUID!", |
|
| 1487 | + "event_espresso"))); |
|
| 1488 | + return 0; |
|
| 1489 | + } |
|
| 1490 | + $wp_filetype = wp_check_filetype(basename($guid), null); |
|
| 1491 | + $wp_upload_dir = wp_upload_dir(); |
|
| 1492 | + //if the file is located remotely, download it to our uploads DIR, because wp_genereate_attachmnet_metadata needs the file to be local |
|
| 1493 | + if (strpos($guid, $wp_upload_dir['url']) === false) { |
|
| 1494 | + //image is located remotely. download it and place it in the uploads directory |
|
| 1495 | + if ( ! is_readable($guid)) { |
|
| 1496 | + $migration_stage->add_error(sprintf(esc_html__("Could not create image attachment from non-existent file: %s", |
|
| 1497 | + "event_espresso"), $guid)); |
|
| 1498 | + return 0; |
|
| 1499 | + } |
|
| 1500 | + $contents = file_get_contents($guid); |
|
| 1501 | + if ($contents === false) { |
|
| 1502 | + $migration_stage->add_error(sprintf(esc_html__("Could not read image at %s, and therefore couldnt create an attachment post for it.", |
|
| 1503 | + "event_espresso"), $guid)); |
|
| 1504 | + return false; |
|
| 1505 | + } |
|
| 1506 | + $local_filepath = $wp_upload_dir['path'] . DS . basename($guid); |
|
| 1507 | + $savefile = fopen($local_filepath, 'w'); |
|
| 1508 | + fwrite($savefile, $contents); |
|
| 1509 | + fclose($savefile); |
|
| 1510 | + $guid = str_replace($wp_upload_dir['path'], $wp_upload_dir['url'], $local_filepath); |
|
| 1511 | + } else { |
|
| 1512 | + $local_filepath = str_replace($wp_upload_dir['url'], $wp_upload_dir['path'], $guid); |
|
| 1513 | + } |
|
| 1514 | + $attachment = array( |
|
| 1515 | + 'guid' => $guid, |
|
| 1516 | + 'post_mime_type' => $wp_filetype['type'], |
|
| 1517 | + 'post_title' => preg_replace('/\.[^.]+$/', '', basename($guid)), |
|
| 1518 | + 'post_content' => '', |
|
| 1519 | + 'post_status' => 'inherit', |
|
| 1520 | + ); |
|
| 1521 | + $attach_id = wp_insert_attachment($attachment, $guid); |
|
| 1522 | + if ( ! $attach_id) { |
|
| 1523 | + $migration_stage->add_error(sprintf(esc_html__("Could not create image attachment post from image '%s'. Attachment data was %s.", |
|
| 1524 | + "event_espresso"), $guid, $this->_json_encode($attachment))); |
|
| 1525 | + return $attach_id; |
|
| 1526 | + } |
|
| 1527 | + // you must first include the image.php file |
|
| 1528 | + // for the function wp_generate_attachment_metadata() to work |
|
| 1529 | + require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
| 1530 | + $attach_data = wp_generate_attachment_metadata($attach_id, $local_filepath); |
|
| 1531 | + if ( ! $attach_data) { |
|
| 1532 | + $migration_stage->add_error(sprintf(esc_html__("Coudl not genereate attachment metadata for attachment post %d with filepath %s and GUID %s. Please check the file was downloaded properly.", |
|
| 1533 | + "event_espresso"), $attach_id, $local_filepath, $guid)); |
|
| 1534 | + return $attach_id; |
|
| 1535 | + } |
|
| 1536 | + $metadata_save_result = wp_update_attachment_metadata($attach_id, $attach_data); |
|
| 1537 | + if ( ! $metadata_save_result) { |
|
| 1538 | + $migration_stage->add_error(sprintf(esc_html__("Could not update attachment metadata for attachment %d with data %s", |
|
| 1539 | + "event_espresso"), $attach_id, $this->_json_encode($attach_data))); |
|
| 1540 | + } |
|
| 1541 | + return $attach_id; |
|
| 1542 | + } |
|
| 1543 | + |
|
| 1544 | + |
|
| 1545 | + |
|
| 1546 | + /** |
|
| 1547 | + * Finds the attachment post containing info about an image attachment given the GUID (link to the image itself), |
|
| 1548 | + * and returns its ID. |
|
| 1549 | + * |
|
| 1550 | + * @global type $wpdb |
|
| 1551 | + * @param string $guid |
|
| 1552 | + * @return int |
|
| 1553 | + */ |
|
| 1554 | + private function _get_image_attachment_id_by_GUID($guid) |
|
| 1555 | + { |
|
| 1556 | + global $wpdb; |
|
| 1557 | + $attachment_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid=%s LIMIT 1", $guid)); |
|
| 1558 | + return $attachment_id; |
|
| 1559 | + } |
|
| 1560 | + |
|
| 1561 | + |
|
| 1562 | + |
|
| 1563 | + /** |
|
| 1564 | + * Returns a mysql-formatted DATETIME in UTC time, given a $DATETIME_string |
|
| 1565 | + * (and optionally a timezone; if none is given, the wp DEFAULT is used) |
|
| 1566 | + * |
|
| 1567 | + * @param EE_Data_Migration_Script_base $stage |
|
| 1568 | + * @param array $row_of_data , the row from the DB (as an array) we're trying to find the |
|
| 1569 | + * UTC time for |
|
| 1570 | + * @param string $DATETIME_string |
|
| 1571 | + * @param string $timezone |
|
| 1572 | + * @return string |
|
| 1573 | + */ |
|
| 1574 | + public function convert_date_string_to_utc( |
|
| 1575 | + EE_Data_Migration_Script_Stage $stage, |
|
| 1576 | + $row_of_data, |
|
| 1577 | + $DATETIME_string, |
|
| 1578 | + $timezone = null |
|
| 1579 | + ) { |
|
| 1580 | + $original_tz = $timezone; |
|
| 1581 | + if ( ! $timezone) { |
|
| 1582 | + $timezone = $this->_get_wp_timezone(); |
|
| 1583 | + } |
|
| 1584 | + if ( ! $timezone) { |
|
| 1585 | + $stage->add_error(sprintf(esc_html__("Could not find timezone given %s for %s", "event_espresso"), $original_tz, |
|
| 1586 | + $row_of_data)); |
|
| 1587 | + $timezone = 'UTC'; |
|
| 1588 | + } |
|
| 1589 | + try { |
|
| 1590 | + $date_obj = new DateTime($DATETIME_string, new DateTimeZone($timezone)); |
|
| 1591 | + $date_obj->setTimezone(new DateTimeZone('UTC')); |
|
| 1592 | + } catch (Exception $e) { |
|
| 1593 | + $stage->add_error(sprintf(esc_html__("Could not convert time string '%s' using timezone '%s' into a proper DATETIME. Using current time instead.", |
|
| 1594 | + "event_espresso"), $DATETIME_string, $timezone)); |
|
| 1595 | + $date_obj = new DateTime(); |
|
| 1596 | + } |
|
| 1597 | + return $date_obj->format('Y-m-d H:i:s'); |
|
| 1598 | + } |
|
| 1599 | + |
|
| 1600 | + |
|
| 1601 | + |
|
| 1602 | + /** |
|
| 1603 | + * Gets the DEFAULT timezone string from wordpress (even if they set a gmt offset) |
|
| 1604 | + * |
|
| 1605 | + * @return string |
|
| 1606 | + */ |
|
| 1607 | + private function _get_wp_timezone() |
|
| 1608 | + { |
|
| 1609 | + $timezone = empty($timezone) ? get_option('timezone_string') : $timezone; |
|
| 1610 | + //if timezone is STILL empty then let's get the GMT offset and then set the timezone_string using our converter |
|
| 1611 | + if (empty($timezone)) { |
|
| 1612 | + //let's get a the WordPress UTC offset |
|
| 1613 | + $offset = get_option('gmt_offset'); |
|
| 1614 | + $timezone = $this->timezone_convert_to_string_from_offset($offset); |
|
| 1615 | + } |
|
| 1616 | + return $timezone; |
|
| 1617 | + } |
|
| 1618 | + |
|
| 1619 | + |
|
| 1620 | + |
|
| 1621 | + /** |
|
| 1622 | + * Gets the wordpress timezone string from a UTC offset |
|
| 1623 | + * |
|
| 1624 | + * @param int $offset |
|
| 1625 | + * @return boolean |
|
| 1626 | + */ |
|
| 1627 | + private function timezone_convert_to_string_from_offset($offset) |
|
| 1628 | + { |
|
| 1629 | + //shamelessly taken from bottom comment at http://ca1.php.net/manual/en/function.timezone-name-from-abbr.php because timezone_name_from_abbr() did NOT work as expected - its not reliable |
|
| 1630 | + $offset *= 3600; // convert hour offset to seconds |
|
| 1631 | + $abbrarray = timezone_abbreviations_list(); |
|
| 1632 | + foreach ($abbrarray as $abbr) { |
|
| 1633 | + foreach ($abbr as $city) { |
|
| 1634 | + if ($city['offset'] == $offset) { |
|
| 1635 | + return $city['timezone_id']; |
|
| 1636 | + } |
|
| 1637 | + } |
|
| 1638 | + } |
|
| 1639 | + return false; |
|
| 1640 | + } |
|
| 1641 | + |
|
| 1642 | + |
|
| 1643 | + |
|
| 1644 | + public function migration_page_hooks() |
|
| 1645 | + { |
|
| 1646 | + add_filter( |
|
| 1647 | + 'FHEE__ee_migration_page__header', |
|
| 1648 | + array($this, '_migrate_page_hook_simplify_version_strings'), |
|
| 1649 | + 10, |
|
| 1650 | + 3 |
|
| 1651 | + ); |
|
| 1652 | + add_filter( |
|
| 1653 | + 'FHEE__ee_migration_page__p_after_header', |
|
| 1654 | + array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1655 | + 10, |
|
| 1656 | + 2 |
|
| 1657 | + ); |
|
| 1658 | + add_filter( |
|
| 1659 | + 'FHEE__ee_migration_page__option_1_main', |
|
| 1660 | + array($this, '_migrate_page_hook_simplify_version_strings'), |
|
| 1661 | + 10, |
|
| 1662 | + 3 |
|
| 1663 | + ); |
|
| 1664 | + add_filter( |
|
| 1665 | + 'FHEE__ee_migration_page__option_1_button_text', |
|
| 1666 | + array($this, '_migrate_page_hook_simplify_version_strings'), |
|
| 1667 | + 10, |
|
| 1668 | + 3 |
|
| 1669 | + ); |
|
| 1670 | + add_action( |
|
| 1671 | + 'AHEE__ee_migration_page__option_1_extra_details', |
|
| 1672 | + array($this, '_migration_page_hook_option_1_extra_details'), |
|
| 1673 | + 10, |
|
| 1674 | + 3 |
|
| 1675 | + ); |
|
| 1676 | + add_filter( |
|
| 1677 | + 'FHEE__ee_migration_page__option_2_main', |
|
| 1678 | + array($this, '_migrate_page_hook_simplify_version_strings'), |
|
| 1679 | + 10, |
|
| 1680 | + 4 |
|
| 1681 | + ); |
|
| 1682 | + add_filter( |
|
| 1683 | + 'FHEE__ee_migration_page__option_2_button_text', |
|
| 1684 | + array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1685 | + 10, |
|
| 1686 | + 2 |
|
| 1687 | + ); |
|
| 1688 | + add_filter( |
|
| 1689 | + 'FHEE__ee_migration_page__option_2_details', |
|
| 1690 | + array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1691 | + 10, |
|
| 1692 | + 2 |
|
| 1693 | + ); |
|
| 1694 | + add_action( |
|
| 1695 | + 'AHEE__ee_migration_page__after_migration_options_table', |
|
| 1696 | + array($this, '_migration_page_hook_after_migration_options_table') |
|
| 1697 | + ); |
|
| 1698 | + add_filter( |
|
| 1699 | + 'FHEE__ee_migration_page__done_migration_header', |
|
| 1700 | + array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1701 | + 10, |
|
| 1702 | + 2 |
|
| 1703 | + ); |
|
| 1704 | + add_filter( |
|
| 1705 | + 'FHEE__ee_migration_page__p_after_done_migration_header', |
|
| 1706 | + array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1707 | + 10, |
|
| 1708 | + 2 |
|
| 1709 | + ); |
|
| 1710 | + add_filter( |
|
| 1711 | + 'FHEE__ee_migration_page__migration_options_template', |
|
| 1712 | + array($this,'use_migration_options_from_ee3_template') |
|
| 1713 | + ); |
|
| 1714 | + } |
|
| 1715 | + |
|
| 1716 | + |
|
| 1717 | + |
|
| 1718 | + public function _migrate_page_hook_simplify_version_strings( |
|
| 1719 | + $old_content, |
|
| 1720 | + $current_db_state, |
|
| 1721 | + $next_db_state, |
|
| 1722 | + $ultimate_db_state = null |
|
| 1723 | + ) { |
|
| 1724 | + return str_replace(array($current_db_state, $next_db_state, $ultimate_db_state), |
|
| 1725 | + array(esc_html__('EE3', 'event_espresso'), esc_html__('EE4', 'event_espresso'), esc_html__("EE4", 'event_espresso')), |
|
| 1726 | + $old_content); |
|
| 1727 | + } |
|
| 1728 | + |
|
| 1729 | + |
|
| 1730 | + |
|
| 1731 | + public function _migration_page_hook_simplify_next_db_state($old_content, $next_db_state) |
|
| 1732 | + { |
|
| 1733 | + return str_replace($next_db_state, esc_html__("EE4", 'event_espresso'), $old_content); |
|
| 1734 | + } |
|
| 1735 | + |
|
| 1736 | + |
|
| 1737 | + |
|
| 1738 | + public function _migration_page_hook_option_1_extra_details() |
|
| 1739 | + { |
|
| 1740 | + ?> |
|
| 1741 | 1741 | <p><?php printf(esc_html__("Note: many of your EE3 shortcodes will be changed to EE4 shortcodes during this migration (among many other things). Should you revert to EE3, then you should restore to your backup or manually change the EE4 shortcodes back to their EE3 equivalents", |
| 1742 | - "event_espresso")); ?></p><?php |
|
| 1743 | - } |
|
| 1742 | + "event_espresso")); ?></p><?php |
|
| 1743 | + } |
|
| 1744 | 1744 | |
| 1745 | 1745 | |
| 1746 | 1746 | |
| 1747 | - public function _migration_page_hook_after_migration_options_table() |
|
| 1748 | - { |
|
| 1749 | - ?><p class="ee-attention"> |
|
| 1747 | + public function _migration_page_hook_after_migration_options_table() |
|
| 1748 | + { |
|
| 1749 | + ?><p class="ee-attention"> |
|
| 1750 | 1750 | <strong><span class="reminder-spn"><?php _e("Important note to those using Event Espresso 3 addons: ", |
| 1751 | - "event_espresso"); ?></span></strong> |
|
| 1751 | + "event_espresso"); ?></span></strong> |
|
| 1752 | 1752 | <br/><?php _e("Unless an addon's description on our website explicitly states that it is compatible with EE4, you should consider it incompatible and know that it WILL NOT WORK correctly with this new version of Event Espresso 4 (EE4). As well, any data for incompatible addons will NOT BE MIGRATED until an updated EE4 compatible version of the addon is available. If you want, or need to keep using your EE3 addons, you should simply continue using EE3 until EE4 compatible versions of your addons become available. To continue using EE3 for now, just deactivate EE4 and reactivate EE3.", |
| 1753 | - "event_espresso"); ?> |
|
| 1753 | + "event_espresso"); ?> |
|
| 1754 | 1754 | </p><?php |
| 1755 | - } |
|
| 1755 | + } |
|
| 1756 | 1756 | |
| 1757 | 1757 | |
| 1758 | 1758 | |
| 1759 | - /** |
|
| 1760 | - * When showing the migration options, show more options and info than normal (ie, give folks the option |
|
| 1761 | - * to start using EE4 without migrating. From EE3 that's fine, because it doesn't actually remove any data, because |
|
| 1762 | - * EE4 doesn't have any yet. But when migrating from EE4 it would remove old data, so its not a great idea). |
|
| 1763 | - * @param $template_filepath |
|
| 1764 | - * @return string |
|
| 1765 | - */ |
|
| 1766 | - public function use_migration_options_from_ee3_template( $template_filepath ) { |
|
| 1767 | - return EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee3.template.php'; |
|
| 1768 | - } |
|
| 1759 | + /** |
|
| 1760 | + * When showing the migration options, show more options and info than normal (ie, give folks the option |
|
| 1761 | + * to start using EE4 without migrating. From EE3 that's fine, because it doesn't actually remove any data, because |
|
| 1762 | + * EE4 doesn't have any yet. But when migrating from EE4 it would remove old data, so its not a great idea). |
|
| 1763 | + * @param $template_filepath |
|
| 1764 | + * @return string |
|
| 1765 | + */ |
|
| 1766 | + public function use_migration_options_from_ee3_template( $template_filepath ) { |
|
| 1767 | + return EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee3.template.php'; |
|
| 1768 | + } |
|
| 1769 | 1769 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | //unfortunately, this needs to be done upon INCLUSION of this file, |
| 10 | 10 | //instead of construction, because it only gets constructed on first page load |
| 11 | 11 | //(all other times it gets resurrected from a wordpress option) |
| 12 | -$stages = glob(EE_CORE . 'data_migration_scripts/4_1_0_stages/*'); |
|
| 12 | +$stages = glob(EE_CORE.'data_migration_scripts/4_1_0_stages/*'); |
|
| 13 | 13 | $class_to_filepath = array(); |
| 14 | 14 | if ( ! empty($stages)) { |
| 15 | 15 | foreach ($stages as $filepath) { |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | private function _checkin_table_exists() |
| 88 | 88 | { |
| 89 | 89 | global $wpdb; |
| 90 | - $results = $wpdb->get_results("SHOW TABLES LIKE '" . $wpdb->prefix . "events_attendee_checkin" . "'"); |
|
| 90 | + $results = $wpdb->get_results("SHOW TABLES LIKE '".$wpdb->prefix."events_attendee_checkin"."'"); |
|
| 91 | 91 | if ($results) { |
| 92 | 92 | return true; |
| 93 | 93 | } else { |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | // echo "no version string provided: $version_string"; |
| 108 | 108 | //no version string provided... this must be pre 4.1 |
| 109 | 109 | //because since 4.1 we're |
| 110 | - return false;//changed mind. dont want people thinking they should migrate yet because they cant |
|
| 110 | + return false; //changed mind. dont want people thinking they should migrate yet because they cant |
|
| 111 | 111 | } else { |
| 112 | 112 | // echo "$version_string doesnt apply"; |
| 113 | 113 | return false; |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | public function schema_changes_before_migration() |
| 120 | 120 | { |
| 121 | 121 | //relies on 4.1's EEH_Activation::create_table |
| 122 | - require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
| 122 | + require_once(EE_HELPERS.'EEH_Activation.helper.php'); |
|
| 123 | 123 | $table_name = 'esp_answer'; |
| 124 | 124 | $sql = " ANS_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
| 125 | 125 | REG_ID INT UNSIGNED NOT NULL, |
@@ -503,12 +503,12 @@ discard block |
||
| 503 | 503 | public function insert_default_states() |
| 504 | 504 | { |
| 505 | 505 | global $wpdb; |
| 506 | - $state_table = $wpdb->prefix . "esp_state"; |
|
| 506 | + $state_table = $wpdb->prefix."esp_state"; |
|
| 507 | 507 | if ($this->_get_table_analysis()->tableExists($state_table)) { |
| 508 | - $SQL = "SELECT COUNT('STA_ID') FROM " . $state_table; |
|
| 508 | + $SQL = "SELECT COUNT('STA_ID') FROM ".$state_table; |
|
| 509 | 509 | $states = $wpdb->get_var($SQL); |
| 510 | 510 | if ( ! $states) { |
| 511 | - $SQL = "INSERT INTO " . $state_table . " |
|
| 511 | + $SQL = "INSERT INTO ".$state_table." |
|
| 512 | 512 | (STA_ID, CNT_ISO, STA_abbrev, STA_name, STA_active) VALUES |
| 513 | 513 | (1, 'US', 'AK', 'Alaska', 1), |
| 514 | 514 | (2, 'US', 'AL', 'Alabama', 1), |
@@ -596,12 +596,12 @@ discard block |
||
| 596 | 596 | public function insert_default_countries() |
| 597 | 597 | { |
| 598 | 598 | global $wpdb; |
| 599 | - $country_table = $wpdb->prefix . "esp_country"; |
|
| 599 | + $country_table = $wpdb->prefix."esp_country"; |
|
| 600 | 600 | if ($this->_get_table_analysis()->tableExists($country_table)) { |
| 601 | - $SQL = "SELECT COUNT('CNT_ISO') FROM " . $country_table; |
|
| 601 | + $SQL = "SELECT COUNT('CNT_ISO') FROM ".$country_table; |
|
| 602 | 602 | $countries = $wpdb->get_var($SQL); |
| 603 | 603 | if ( ! $countries) { |
| 604 | - $SQL = "INSERT INTO " . $country_table . " |
|
| 604 | + $SQL = "INSERT INTO ".$country_table." |
|
| 605 | 605 | (CNT_ISO, CNT_ISO3, RGN_ID, CNT_name, CNT_cur_code, CNT_cur_single, CNT_cur_plural, CNT_cur_sign, CNT_cur_sign_b4, CNT_cur_dec_plc, CNT_tel_code, CNT_is_EU, CNT_active) VALUES |
| 606 | 606 | ('AD', 'AND', 0, 'Andorra', 'EUR', 'Euro', 'Euros', '€', 1, 2, '+376', 0, 0), |
| 607 | 607 | ('AE', 'ARE', 0, 'United Arab Emirates', 'AED', 'Dirham', 'Dirhams', 'د.إ', 1, 2, '+971', 0, 0), |
@@ -846,17 +846,17 @@ discard block |
||
| 846 | 846 | public function insert_default_price_types() |
| 847 | 847 | { |
| 848 | 848 | global $wpdb; |
| 849 | - $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
| 849 | + $price_type_table = $wpdb->prefix."esp_price_type"; |
|
| 850 | 850 | if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
| 851 | - $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table; |
|
| 851 | + $SQL = 'SELECT COUNT(PRT_ID) FROM '.$price_type_table; |
|
| 852 | 852 | $price_types_exist = $wpdb->get_var($SQL); |
| 853 | 853 | if ( ! $price_types_exist) { |
| 854 | 854 | $SQL = "INSERT INTO $price_type_table ( PRT_ID, PRT_name, PBT_ID, PRT_is_percent, PRT_order, PRT_deleted ) VALUES |
| 855 | - (1, '" . esc_html__('Base Price', 'event_espresso') . "', 1, 0, 0, 0), |
|
| 856 | - (2, '" . esc_html__('Percent Discount', 'event_espresso') . "', 2, 1, 20, 0), |
|
| 857 | - (3, '" . esc_html__('Fixed Discount', 'event_espresso') . "', 2, 0, 30, 0), |
|
| 858 | - (4, '" . esc_html__('Percent Surcharge', 'event_espresso') . "', 3, 1, 40, 0), |
|
| 859 | - (5, '" . esc_html__('Fixed Surcharge', 'event_espresso') . "', 3, 0, 50, 0);"; |
|
| 855 | + (1, '".esc_html__('Base Price', 'event_espresso')."', 1, 0, 0, 0), |
|
| 856 | + (2, '" . esc_html__('Percent Discount', 'event_espresso')."', 2, 1, 20, 0), |
|
| 857 | + (3, '" . esc_html__('Fixed Discount', 'event_espresso')."', 2, 0, 30, 0), |
|
| 858 | + (4, '" . esc_html__('Percent Surcharge', 'event_espresso')."', 3, 1, 40, 0), |
|
| 859 | + (5, '" . esc_html__('Fixed Surcharge', 'event_espresso')."', 3, 0, 50, 0);"; |
|
| 860 | 860 | $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_price_types__SQL', $SQL); |
| 861 | 861 | $wpdb->query($SQL); |
| 862 | 862 | } |
@@ -878,9 +878,9 @@ discard block |
||
| 878 | 878 | public function insert_default_prices() |
| 879 | 879 | { |
| 880 | 880 | global $wpdb; |
| 881 | - $price_table = $wpdb->prefix . "esp_price"; |
|
| 881 | + $price_table = $wpdb->prefix."esp_price"; |
|
| 882 | 882 | if ($this->_get_table_analysis()->tableExists($price_table)) { |
| 883 | - $SQL = 'SELECT COUNT(PRC_ID) FROM ' . $price_table; |
|
| 883 | + $SQL = 'SELECT COUNT(PRC_ID) FROM '.$price_table; |
|
| 884 | 884 | $prices_exist = $wpdb->get_var($SQL); |
| 885 | 885 | if ( ! $prices_exist) { |
| 886 | 886 | $SQL = "INSERT INTO $price_table |
@@ -904,9 +904,9 @@ discard block |
||
| 904 | 904 | public function insert_default_tickets() |
| 905 | 905 | { |
| 906 | 906 | global $wpdb; |
| 907 | - $ticket_table = $wpdb->prefix . "esp_ticket"; |
|
| 907 | + $ticket_table = $wpdb->prefix."esp_ticket"; |
|
| 908 | 908 | if ($this->_get_table_analysis()->tableExists($ticket_table)) { |
| 909 | - $SQL = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table; |
|
| 909 | + $SQL = 'SELECT COUNT(TKT_ID) FROM '.$ticket_table; |
|
| 910 | 910 | $tickets_exist = $wpdb->get_var($SQL); |
| 911 | 911 | if ( ! $tickets_exist) { |
| 912 | 912 | $SQL = "INSERT INTO $ticket_table |
@@ -918,9 +918,9 @@ discard block |
||
| 918 | 918 | $wpdb->query($SQL); |
| 919 | 919 | } |
| 920 | 920 | } |
| 921 | - $ticket_price_table = $wpdb->prefix . "esp_ticket_price"; |
|
| 921 | + $ticket_price_table = $wpdb->prefix."esp_ticket_price"; |
|
| 922 | 922 | if ($this->_get_table_analysis()->tableExists($ticket_price_table)) { |
| 923 | - $SQL = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table; |
|
| 923 | + $SQL = 'SELECT COUNT(TKP_ID) FROM '.$ticket_price_table; |
|
| 924 | 924 | $ticket_prc_exist = $wpdb->get_var($SQL); |
| 925 | 925 | if ( ! $ticket_prc_exist) { |
| 926 | 926 | $SQL = "INSERT INTO $ticket_price_table |
@@ -950,7 +950,7 @@ discard block |
||
| 950 | 950 | throw new EE_Error(esc_html__("Could not get a country because country name is blank", "event_espresso")); |
| 951 | 951 | } |
| 952 | 952 | global $wpdb; |
| 953 | - $country_table = $wpdb->prefix . "esp_country"; |
|
| 953 | + $country_table = $wpdb->prefix."esp_country"; |
|
| 954 | 954 | if (is_int($country_name)) { |
| 955 | 955 | $country_name = $this->get_iso_from_3_1_country_id($country_name); |
| 956 | 956 | } |
@@ -978,21 +978,21 @@ discard block |
||
| 978 | 978 | 'CNT_active' => true, |
| 979 | 979 | ); |
| 980 | 980 | $data_types = array( |
| 981 | - '%s',//CNT_ISO |
|
| 982 | - '%s',//CNT_ISO3 |
|
| 983 | - '%d',//RGN_ID |
|
| 984 | - '%s',//CNT_name |
|
| 985 | - '%s',//CNT_cur_code |
|
| 986 | - '%s',//CNT_cur_single |
|
| 987 | - '%s',//CNT_cur_plural |
|
| 988 | - '%s',//CNT_cur_sign |
|
| 989 | - '%d',//CNT_cur_sign_b4 |
|
| 990 | - '%d',//CNT_cur_dec_plc |
|
| 991 | - '%s',//CNT_cur_dec_mrk |
|
| 992 | - '%s',//CNT_cur_thsnds |
|
| 993 | - '%s',//CNT_tel_code |
|
| 994 | - '%d',//CNT_is_EU |
|
| 995 | - '%d',//CNT_active |
|
| 981 | + '%s', //CNT_ISO |
|
| 982 | + '%s', //CNT_ISO3 |
|
| 983 | + '%d', //RGN_ID |
|
| 984 | + '%s', //CNT_name |
|
| 985 | + '%s', //CNT_cur_code |
|
| 986 | + '%s', //CNT_cur_single |
|
| 987 | + '%s', //CNT_cur_plural |
|
| 988 | + '%s', //CNT_cur_sign |
|
| 989 | + '%d', //CNT_cur_sign_b4 |
|
| 990 | + '%d', //CNT_cur_dec_plc |
|
| 991 | + '%s', //CNT_cur_dec_mrk |
|
| 992 | + '%s', //CNT_cur_thsnds |
|
| 993 | + '%s', //CNT_tel_code |
|
| 994 | + '%d', //CNT_is_EU |
|
| 995 | + '%d', //CNT_active |
|
| 996 | 996 | ); |
| 997 | 997 | $success = $wpdb->insert($country_table, |
| 998 | 998 | $cols_n_values, |
@@ -1017,7 +1017,7 @@ discard block |
||
| 1017 | 1017 | private function _find_available_country_iso($num_letters = 2) |
| 1018 | 1018 | { |
| 1019 | 1019 | global $wpdb; |
| 1020 | - $country_table = $wpdb->prefix . "esp_country"; |
|
| 1020 | + $country_table = $wpdb->prefix."esp_country"; |
|
| 1021 | 1021 | $attempts = 0; |
| 1022 | 1022 | do { |
| 1023 | 1023 | $current_iso = strtoupper(wp_generate_password($num_letters, false)); |
@@ -1028,7 +1028,7 @@ discard block |
||
| 1028 | 1028 | //keep going until we find an available country code, or we arbitrarily |
| 1029 | 1029 | //decide we've tried this enough. Somehow they have way too many countries |
| 1030 | 1030 | //(probably because they're mis-using the EE3 country_id like a custom question) |
| 1031 | - } while (intval($country_with_that_iso) && $attempts < 200); |
|
| 1031 | + }while (intval($country_with_that_iso) && $attempts < 200); |
|
| 1032 | 1032 | return $current_iso; |
| 1033 | 1033 | } |
| 1034 | 1034 | |
@@ -1055,7 +1055,7 @@ discard block |
||
| 1055 | 1055 | $country_iso = $this->get_default_country_iso(); |
| 1056 | 1056 | } |
| 1057 | 1057 | global $wpdb; |
| 1058 | - $state_table = $wpdb->prefix . "esp_state"; |
|
| 1058 | + $state_table = $wpdb->prefix."esp_state"; |
|
| 1059 | 1059 | $state = $wpdb->get_row($wpdb->prepare("SELECT * FROM $state_table WHERE |
| 1060 | 1060 | (STA_abbrev LIKE %s OR |
| 1061 | 1061 | STA_name LIKE %s) AND |
@@ -1069,10 +1069,10 @@ discard block |
||
| 1069 | 1069 | 'STA_active' => true, |
| 1070 | 1070 | ); |
| 1071 | 1071 | $data_types = array( |
| 1072 | - '%s',//CNT_ISO |
|
| 1073 | - '%s',//STA_abbrev |
|
| 1074 | - '%s',//STA_name |
|
| 1075 | - '%d',//STA_active |
|
| 1072 | + '%s', //CNT_ISO |
|
| 1073 | + '%s', //STA_abbrev |
|
| 1074 | + '%s', //STA_name |
|
| 1075 | + '%d', //STA_active |
|
| 1076 | 1076 | ); |
| 1077 | 1077 | $success = $wpdb->insert($state_table, $cols_n_values, $data_types); |
| 1078 | 1078 | if ( ! $success) { |
@@ -1503,7 +1503,7 @@ discard block |
||
| 1503 | 1503 | "event_espresso"), $guid)); |
| 1504 | 1504 | return false; |
| 1505 | 1505 | } |
| 1506 | - $local_filepath = $wp_upload_dir['path'] . DS . basename($guid); |
|
| 1506 | + $local_filepath = $wp_upload_dir['path'].DS.basename($guid); |
|
| 1507 | 1507 | $savefile = fopen($local_filepath, 'w'); |
| 1508 | 1508 | fwrite($savefile, $contents); |
| 1509 | 1509 | fclose($savefile); |
@@ -1526,7 +1526,7 @@ discard block |
||
| 1526 | 1526 | } |
| 1527 | 1527 | // you must first include the image.php file |
| 1528 | 1528 | // for the function wp_generate_attachment_metadata() to work |
| 1529 | - require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
| 1529 | + require_once(ABSPATH.'wp-admin/includes/image.php'); |
|
| 1530 | 1530 | $attach_data = wp_generate_attachment_metadata($attach_id, $local_filepath); |
| 1531 | 1531 | if ( ! $attach_data) { |
| 1532 | 1532 | $migration_stage->add_error(sprintf(esc_html__("Coudl not genereate attachment metadata for attachment post %d with filepath %s and GUID %s. Please check the file was downloaded properly.", |
@@ -1709,7 +1709,7 @@ discard block |
||
| 1709 | 1709 | ); |
| 1710 | 1710 | add_filter( |
| 1711 | 1711 | 'FHEE__ee_migration_page__migration_options_template', |
| 1712 | - array($this,'use_migration_options_from_ee3_template') |
|
| 1712 | + array($this, 'use_migration_options_from_ee3_template') |
|
| 1713 | 1713 | ); |
| 1714 | 1714 | } |
| 1715 | 1715 | |
@@ -1763,7 +1763,7 @@ discard block |
||
| 1763 | 1763 | * @param $template_filepath |
| 1764 | 1764 | * @return string |
| 1765 | 1765 | */ |
| 1766 | - public function use_migration_options_from_ee3_template( $template_filepath ) { |
|
| 1767 | - return EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee3.template.php'; |
|
| 1766 | + public function use_migration_options_from_ee3_template($template_filepath) { |
|
| 1767 | + return EE_MAINTENANCE_TEMPLATE_PATH.'migration_options_from_ee3.template.php'; |
|
| 1768 | 1768 | } |
| 1769 | 1769 | } |
@@ -805,7 +805,7 @@ discard block |
||
| 805 | 805 | * @since 4.5.0 |
| 806 | 806 | * |
| 807 | 807 | * @param string $meta_cap What meta capability is this mapping. |
| 808 | - * @param array $map_values array { |
|
| 808 | + * @param string[] $map_values array { |
|
| 809 | 809 | * //array of values that MUST match a count of 4. It's okay to send an empty string for |
| 810 | 810 | * capabilities that don't get mapped to. |
| 811 | 811 | * |
@@ -880,8 +880,8 @@ discard block |
||
| 880 | 880 | * @since 4.6.x |
| 881 | 881 | * |
| 882 | 882 | * @param $caps |
| 883 | - * @param $cap |
|
| 884 | - * @param $user_id |
|
| 883 | + * @param string $cap |
|
| 884 | + * @param integer $user_id |
|
| 885 | 885 | * @param $args |
| 886 | 886 | * |
| 887 | 887 | * @return array |
@@ -18,980 +18,980 @@ discard block |
||
| 18 | 18 | final class EE_Capabilities extends EE_Base |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * the name of the wp option used to store caps previously initialized |
|
| 23 | - */ |
|
| 24 | - const option_name = 'ee_caps_initialized'; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * instance of EE_Capabilities object |
|
| 28 | - * |
|
| 29 | - * @var EE_Capabilities |
|
| 30 | - */ |
|
| 31 | - private static $_instance; |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * This is a map of caps that correspond to a default WP_Role. |
|
| 36 | - * Array is indexed by Role and values are ee capabilities. |
|
| 37 | - * |
|
| 38 | - * @since 4.5.0 |
|
| 39 | - * |
|
| 40 | - * @var array |
|
| 41 | - */ |
|
| 42 | - private $capabilities_map = array(); |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * This used to hold an array of EE_Meta_Capability_Map objects |
|
| 46 | - * that define the granular capabilities mapped to for a user depending on context. |
|
| 47 | - * |
|
| 48 | - * @var EE_Meta_Capability_Map[] |
|
| 49 | - */ |
|
| 50 | - private $_meta_caps = array(); |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * The internal $capabilities_map needs to be initialized before it can be used. |
|
| 54 | - * This flag tracks whether that has happened or not. |
|
| 55 | - * But for this to work, we need three states to indicate: |
|
| 56 | - * initialization has not occurred at all |
|
| 57 | - * initialization has started but is not complete |
|
| 58 | - * initialization is complete |
|
| 59 | - * The reason this is needed is because the addCaps() method |
|
| 60 | - * normally requires the $capabilities_map to be initialized, |
|
| 61 | - * but is also used during the initialization process. |
|
| 62 | - * So: |
|
| 63 | - * If initialized === null, init_caps() will be called before any other methods will run. |
|
| 64 | - * If initialized === false, then init_caps() is in the process of running it's logic. |
|
| 65 | - * If initialized === true, then init_caps() has completed the initialization process. |
|
| 66 | - * |
|
| 67 | - * @var boolean|null $initialized |
|
| 68 | - */ |
|
| 69 | - private $initialized; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @var boolean $reset |
|
| 73 | - */ |
|
| 74 | - private $reset = false; |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * singleton method used to instantiate class object |
|
| 80 | - * |
|
| 81 | - * @since 4.5.0 |
|
| 82 | - * |
|
| 83 | - * @return EE_Capabilities |
|
| 84 | - */ |
|
| 85 | - public static function instance() |
|
| 86 | - { |
|
| 87 | - //check if instantiated, and if not do so. |
|
| 88 | - if (! self::$_instance instanceof EE_Capabilities) { |
|
| 89 | - self::$_instance = new self(); |
|
| 90 | - } |
|
| 91 | - return self::$_instance; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * private constructor |
|
| 98 | - * |
|
| 99 | - * @since 4.5.0 |
|
| 100 | - */ |
|
| 101 | - private function __construct() |
|
| 102 | - { |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * This delays the initialization of the capabilities class until EE_System core is loaded and ready. |
|
| 109 | - * |
|
| 110 | - * @param bool $reset allows for resetting the default capabilities saved on roles. Note that this doesn't |
|
| 111 | - * actually REMOVE any capabilities from existing roles, it just resaves defaults roles and |
|
| 112 | - * ensures that they are up to date. |
|
| 113 | - * |
|
| 114 | - * @since 4.5.0 |
|
| 115 | - * @return bool |
|
| 116 | - * @throws EE_Error |
|
| 117 | - */ |
|
| 118 | - public function init_caps($reset = false) |
|
| 119 | - { |
|
| 120 | - if(! EE_Maintenance_Mode::instance()->models_can_query()){ |
|
| 121 | - return false; |
|
| 122 | - } |
|
| 123 | - $this->reset = filter_var($reset, FILTER_VALIDATE_BOOLEAN); |
|
| 124 | - // if reset, then completely delete the cache option and clear the $capabilities_map property. |
|
| 125 | - if ($this->reset) { |
|
| 126 | - $this->initialized = null; |
|
| 127 | - $this->capabilities_map = array(); |
|
| 128 | - delete_option(self::option_name); |
|
| 129 | - } |
|
| 130 | - if ($this->initialized === null) { |
|
| 131 | - $this->initialized = false; |
|
| 132 | - do_action( |
|
| 133 | - 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
| 134 | - $this->reset |
|
| 135 | - ); |
|
| 136 | - $this->addCaps($this->_init_caps_map()); |
|
| 137 | - $this->_set_meta_caps(); |
|
| 138 | - do_action( |
|
| 139 | - 'AHEE__EE_Capabilities__init_caps__after_initialization', |
|
| 140 | - $this->capabilities_map |
|
| 141 | - ); |
|
| 142 | - $this->initialized = true; |
|
| 143 | - } |
|
| 144 | - // reset $this->reset so that it's not stuck on true if init_caps() gets called again |
|
| 145 | - $this->reset = false; |
|
| 146 | - return true; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * This sets the meta caps property. |
|
| 153 | - * |
|
| 154 | - * @since 4.5.0 |
|
| 155 | - * @return void |
|
| 156 | - * @throws EE_Error |
|
| 157 | - */ |
|
| 158 | - private function _set_meta_caps() |
|
| 159 | - { |
|
| 160 | - // get default meta caps and filter the returned array |
|
| 161 | - $this->_meta_caps = apply_filters( |
|
| 162 | - 'FHEE__EE_Capabilities___set_meta_caps__meta_caps', |
|
| 163 | - $this->_get_default_meta_caps_array() |
|
| 164 | - ); |
|
| 165 | - //add filter for map_meta_caps but only if models can query. |
|
| 166 | - if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) { |
|
| 167 | - add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4); |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * This builds and returns the default meta_caps array only once. |
|
| 175 | - * |
|
| 176 | - * @since 4.8.28.rc.012 |
|
| 177 | - * @return array |
|
| 178 | - * @throws EE_Error |
|
| 179 | - */ |
|
| 180 | - private function _get_default_meta_caps_array() |
|
| 181 | - { |
|
| 182 | - static $default_meta_caps = array(); |
|
| 183 | - // make sure we're only ever initializing the default _meta_caps array once if it's empty. |
|
| 184 | - if (empty($default_meta_caps)) { |
|
| 185 | - $default_meta_caps = array( |
|
| 186 | - //edits |
|
| 187 | - new EE_Meta_Capability_Map_Edit( |
|
| 188 | - 'ee_edit_event', |
|
| 189 | - array('Event', 'ee_edit_published_events', 'ee_edit_others_events', 'ee_edit_private_events') |
|
| 190 | - ), |
|
| 191 | - new EE_Meta_Capability_Map_Edit( |
|
| 192 | - 'ee_edit_venue', |
|
| 193 | - array('Venue', 'ee_edit_published_venues', 'ee_edit_others_venues', 'ee_edit_private_venues') |
|
| 194 | - ), |
|
| 195 | - new EE_Meta_Capability_Map_Edit( |
|
| 196 | - 'ee_edit_registration', |
|
| 197 | - array('Registration', '', 'ee_edit_others_registrations', '') |
|
| 198 | - ), |
|
| 199 | - new EE_Meta_Capability_Map_Edit( |
|
| 200 | - 'ee_edit_checkin', |
|
| 201 | - array('Registration', '', 'ee_edit_others_checkins', '') |
|
| 202 | - ), |
|
| 203 | - new EE_Meta_Capability_Map_Messages_Cap( |
|
| 204 | - 'ee_edit_message', |
|
| 205 | - array('Message_Template_Group', '', 'ee_edit_others_messages', 'ee_edit_global_messages') |
|
| 206 | - ), |
|
| 207 | - new EE_Meta_Capability_Map_Edit( |
|
| 208 | - 'ee_edit_default_ticket', |
|
| 209 | - array('Ticket', '', 'ee_edit_others_default_tickets', '') |
|
| 210 | - ), |
|
| 211 | - new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 212 | - 'ee_edit_question', |
|
| 213 | - array('Question', '', '', 'ee_edit_system_questions') |
|
| 214 | - ), |
|
| 215 | - new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 216 | - 'ee_edit_question_group', |
|
| 217 | - array('Question_Group', '', '', 'ee_edit_system_question_groups') |
|
| 218 | - ), |
|
| 219 | - new EE_Meta_Capability_Map_Edit( |
|
| 220 | - 'ee_edit_payment_method', |
|
| 221 | - array('Payment_Method', '', 'ee_edit_others_payment_methods', '') |
|
| 222 | - ), |
|
| 223 | - //reads |
|
| 224 | - new EE_Meta_Capability_Map_Read( |
|
| 225 | - 'ee_read_event', |
|
| 226 | - array('Event', '', 'ee_read_others_events', 'ee_read_private_events') |
|
| 227 | - ), |
|
| 228 | - new EE_Meta_Capability_Map_Read( |
|
| 229 | - 'ee_read_venue', |
|
| 230 | - array('Venue', '', 'ee_read_others_venues', 'ee_read_private_venues') |
|
| 231 | - ), |
|
| 232 | - new EE_Meta_Capability_Map_Read( |
|
| 233 | - 'ee_read_registration', |
|
| 234 | - array('Registration', '', 'ee_read_others_registrations', '') |
|
| 235 | - ), |
|
| 236 | - new EE_Meta_Capability_Map_Read( |
|
| 237 | - 'ee_read_checkin', |
|
| 238 | - array('Registration', '', 'ee_read_others_checkins', '') |
|
| 239 | - ), |
|
| 240 | - new EE_Meta_Capability_Map_Messages_Cap( |
|
| 241 | - 'ee_read_message', |
|
| 242 | - array('Message_Template_Group', '', 'ee_read_others_messages', 'ee_read_global_messages') |
|
| 243 | - ), |
|
| 244 | - new EE_Meta_Capability_Map_Read( |
|
| 245 | - 'ee_read_default_ticket', |
|
| 246 | - array('Ticket', '', 'ee_read_others_default_tickets', '') |
|
| 247 | - ), |
|
| 248 | - new EE_Meta_Capability_Map_Read( |
|
| 249 | - 'ee_read_payment_method', |
|
| 250 | - array('Payment_Method', '', 'ee_read_others_payment_methods', '') |
|
| 251 | - ), |
|
| 252 | - //deletes |
|
| 253 | - new EE_Meta_Capability_Map_Delete( |
|
| 254 | - 'ee_delete_event', |
|
| 255 | - array( |
|
| 256 | - 'Event', |
|
| 257 | - 'ee_delete_published_events', |
|
| 258 | - 'ee_delete_others_events', |
|
| 259 | - 'ee_delete_private_events', |
|
| 260 | - ) |
|
| 261 | - ), |
|
| 262 | - new EE_Meta_Capability_Map_Delete( |
|
| 263 | - 'ee_delete_venue', |
|
| 264 | - array( |
|
| 265 | - 'Venue', |
|
| 266 | - 'ee_delete_published_venues', |
|
| 267 | - 'ee_delete_others_venues', |
|
| 268 | - 'ee_delete_private_venues', |
|
| 269 | - ) |
|
| 270 | - ), |
|
| 271 | - new EE_Meta_Capability_Map_Delete( |
|
| 272 | - 'ee_delete_registration', |
|
| 273 | - array('Registration', '', 'ee_delete_others_registrations', '') |
|
| 274 | - ), |
|
| 275 | - new EE_Meta_Capability_Map_Delete( |
|
| 276 | - 'ee_delete_checkin', |
|
| 277 | - array('Registration', '', 'ee_delete_others_checkins', '') |
|
| 278 | - ), |
|
| 279 | - new EE_Meta_Capability_Map_Messages_Cap( |
|
| 280 | - 'ee_delete_message', |
|
| 281 | - array('Message_Template_Group', '', 'ee_delete_others_messages', 'ee_delete_global_messages') |
|
| 282 | - ), |
|
| 283 | - new EE_Meta_Capability_Map_Delete( |
|
| 284 | - 'ee_delete_default_ticket', |
|
| 285 | - array('Ticket', '', 'ee_delete_others_default_tickets', '') |
|
| 286 | - ), |
|
| 287 | - new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 288 | - 'ee_delete_question', |
|
| 289 | - array('Question', '', '', 'delete_system_questions') |
|
| 290 | - ), |
|
| 291 | - new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 292 | - 'ee_delete_question_group', |
|
| 293 | - array('Question_Group', '', '', 'delete_system_question_groups') |
|
| 294 | - ), |
|
| 295 | - new EE_Meta_Capability_Map_Delete( |
|
| 296 | - 'ee_delete_payment_method', |
|
| 297 | - array('Payment_Method', '', 'ee_delete_others_payment_methods', '') |
|
| 298 | - ), |
|
| 299 | - ); |
|
| 300 | - } |
|
| 301 | - return $default_meta_caps; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 308 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 309 | - * |
|
| 310 | - * The actual logic is carried out by implementer classes in their definition of _map_meta_caps. |
|
| 311 | - * |
|
| 312 | - * @since 4.5.0 |
|
| 313 | - * @see wp-includes/capabilities.php |
|
| 314 | - * |
|
| 315 | - * @param array $caps actual users capabilities |
|
| 316 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 317 | - * @param int $user_id The user id |
|
| 318 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 319 | - * @return array actual users capabilities |
|
| 320 | - * @throws EE_Error |
|
| 321 | - */ |
|
| 322 | - public function map_meta_caps($caps, $cap, $user_id, $args) |
|
| 323 | - { |
|
| 324 | - if (did_action('AHEE__EE_System__load_espresso_addons__complete')) { |
|
| 325 | - //loop through our _meta_caps array |
|
| 326 | - foreach ($this->_meta_caps as $meta_map) { |
|
| 327 | - if (! $meta_map instanceof EE_Meta_Capability_Map) { |
|
| 328 | - continue; |
|
| 329 | - } |
|
| 330 | - // don't load models if there is no object ID in the args |
|
| 331 | - if (! empty($args[0])) { |
|
| 332 | - $meta_map->ensure_is_model(); |
|
| 333 | - } |
|
| 334 | - $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args); |
|
| 335 | - } |
|
| 336 | - } |
|
| 337 | - return $caps; |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * This sets up and returns the initial capabilities map for Event Espresso |
|
| 344 | - * Note this array is filtered. |
|
| 345 | - * It is assumed that all available EE capabilities are assigned to the administrator role. |
|
| 346 | - * |
|
| 347 | - * @since 4.5.0 |
|
| 348 | - * |
|
| 349 | - * @return array |
|
| 350 | - */ |
|
| 351 | - private function _init_caps_map() |
|
| 352 | - { |
|
| 353 | - return apply_filters( |
|
| 354 | - 'FHEE__EE_Capabilities__init_caps_map__caps', |
|
| 355 | - array( |
|
| 356 | - 'administrator' => array( |
|
| 357 | - //basic access |
|
| 358 | - 'ee_read_ee', |
|
| 359 | - //gateways |
|
| 360 | - /** |
|
| 361 | - * note that with payment method capabilities, although we've implemented |
|
| 362 | - * capability mapping which will be used for accessing payment methods owned by |
|
| 363 | - * other users. This is not fully implemented yet in the payment method ui. |
|
| 364 | - * Currently only the "plural" caps are in active use. |
|
| 365 | - * (Specific payment method caps are in use as well). |
|
| 366 | - **/ |
|
| 367 | - 'ee_manage_gateways', |
|
| 368 | - 'ee_read_payment_methods', |
|
| 369 | - 'ee_read_others_payment_methods', |
|
| 370 | - 'ee_edit_payment_methods', |
|
| 371 | - 'ee_edit_others_payment_methods', |
|
| 372 | - 'ee_delete_payment_methods', |
|
| 373 | - //events |
|
| 374 | - 'ee_publish_events', |
|
| 375 | - 'ee_read_private_events', |
|
| 376 | - 'ee_read_others_events', |
|
| 377 | - 'ee_read_events', |
|
| 378 | - 'ee_edit_events', |
|
| 379 | - 'ee_edit_published_events', |
|
| 380 | - 'ee_edit_others_events', |
|
| 381 | - 'ee_edit_private_events', |
|
| 382 | - 'ee_delete_published_events', |
|
| 383 | - 'ee_delete_private_events', |
|
| 384 | - 'ee_delete_events', |
|
| 385 | - 'ee_delete_others_events', |
|
| 386 | - //event categories |
|
| 387 | - 'ee_manage_event_categories', |
|
| 388 | - 'ee_edit_event_category', |
|
| 389 | - 'ee_delete_event_category', |
|
| 390 | - 'ee_assign_event_category', |
|
| 391 | - //venues |
|
| 392 | - 'ee_publish_venues', |
|
| 393 | - 'ee_read_venues', |
|
| 394 | - 'ee_read_others_venues', |
|
| 395 | - 'ee_read_private_venues', |
|
| 396 | - 'ee_edit_venues', |
|
| 397 | - 'ee_edit_others_venues', |
|
| 398 | - 'ee_edit_published_venues', |
|
| 399 | - 'ee_edit_private_venues', |
|
| 400 | - 'ee_delete_venues', |
|
| 401 | - 'ee_delete_others_venues', |
|
| 402 | - 'ee_delete_private_venues', |
|
| 403 | - 'ee_delete_published_venues', |
|
| 404 | - //venue categories |
|
| 405 | - 'ee_manage_venue_categories', |
|
| 406 | - 'ee_edit_venue_category', |
|
| 407 | - 'ee_delete_venue_category', |
|
| 408 | - 'ee_assign_venue_category', |
|
| 409 | - //contacts |
|
| 410 | - 'ee_read_contacts', |
|
| 411 | - 'ee_edit_contacts', |
|
| 412 | - 'ee_delete_contacts', |
|
| 413 | - //registrations |
|
| 414 | - 'ee_read_registrations', |
|
| 415 | - 'ee_read_others_registrations', |
|
| 416 | - 'ee_edit_registrations', |
|
| 417 | - 'ee_edit_others_registrations', |
|
| 418 | - 'ee_delete_registrations', |
|
| 419 | - //checkins |
|
| 420 | - 'ee_read_others_checkins', |
|
| 421 | - 'ee_read_checkins', |
|
| 422 | - 'ee_edit_checkins', |
|
| 423 | - 'ee_edit_others_checkins', |
|
| 424 | - 'ee_delete_checkins', |
|
| 425 | - 'ee_delete_others_checkins', |
|
| 426 | - //transactions && payments |
|
| 427 | - 'ee_read_transaction', |
|
| 428 | - 'ee_read_transactions', |
|
| 429 | - 'ee_edit_payments', |
|
| 430 | - 'ee_delete_payments', |
|
| 431 | - //messages |
|
| 432 | - 'ee_read_messages', |
|
| 433 | - 'ee_read_others_messages', |
|
| 434 | - 'ee_read_global_messages', |
|
| 435 | - 'ee_edit_global_messages', |
|
| 436 | - 'ee_edit_messages', |
|
| 437 | - 'ee_edit_others_messages', |
|
| 438 | - 'ee_delete_messages', |
|
| 439 | - 'ee_delete_others_messages', |
|
| 440 | - 'ee_delete_global_messages', |
|
| 441 | - 'ee_send_message', |
|
| 442 | - //tickets |
|
| 443 | - 'ee_read_default_tickets', |
|
| 444 | - 'ee_read_others_default_tickets', |
|
| 445 | - 'ee_edit_default_tickets', |
|
| 446 | - 'ee_edit_others_default_tickets', |
|
| 447 | - 'ee_delete_default_tickets', |
|
| 448 | - 'ee_delete_others_default_tickets', |
|
| 449 | - //prices |
|
| 450 | - 'ee_edit_default_price', |
|
| 451 | - 'ee_edit_default_prices', |
|
| 452 | - 'ee_delete_default_price', |
|
| 453 | - 'ee_delete_default_prices', |
|
| 454 | - 'ee_edit_default_price_type', |
|
| 455 | - 'ee_edit_default_price_types', |
|
| 456 | - 'ee_delete_default_price_type', |
|
| 457 | - 'ee_delete_default_price_types', |
|
| 458 | - 'ee_read_default_prices', |
|
| 459 | - 'ee_read_default_price_types', |
|
| 460 | - //registration form |
|
| 461 | - 'ee_edit_questions', |
|
| 462 | - 'ee_edit_system_questions', |
|
| 463 | - 'ee_read_questions', |
|
| 464 | - 'ee_delete_questions', |
|
| 465 | - 'ee_edit_question_groups', |
|
| 466 | - 'ee_read_question_groups', |
|
| 467 | - 'ee_edit_system_question_groups', |
|
| 468 | - 'ee_delete_question_groups', |
|
| 469 | - //event_type taxonomy |
|
| 470 | - 'ee_assign_event_type', |
|
| 471 | - 'ee_manage_event_types', |
|
| 472 | - 'ee_edit_event_type', |
|
| 473 | - 'ee_delete_event_type', |
|
| 474 | - ), |
|
| 475 | - 'ee_events_administrator' => array( |
|
| 476 | - //core wp caps |
|
| 477 | - 'read', |
|
| 478 | - 'read_private_pages', |
|
| 479 | - 'read_private_posts', |
|
| 480 | - 'edit_users', |
|
| 481 | - 'edit_posts', |
|
| 482 | - 'edit_pages', |
|
| 483 | - 'edit_published_posts', |
|
| 484 | - 'edit_published_pages', |
|
| 485 | - 'edit_private_pages', |
|
| 486 | - 'edit_private_posts', |
|
| 487 | - 'edit_others_posts', |
|
| 488 | - 'edit_others_pages', |
|
| 489 | - 'publish_posts', |
|
| 490 | - 'publish_pages', |
|
| 491 | - 'delete_posts', |
|
| 492 | - 'delete_pages', |
|
| 493 | - 'delete_private_pages', |
|
| 494 | - 'delete_private_posts', |
|
| 495 | - 'delete_published_pages', |
|
| 496 | - 'delete_published_posts', |
|
| 497 | - 'delete_others_posts', |
|
| 498 | - 'delete_others_pages', |
|
| 499 | - 'manage_categories', |
|
| 500 | - 'manage_links', |
|
| 501 | - 'moderate_comments', |
|
| 502 | - 'unfiltered_html', |
|
| 503 | - 'upload_files', |
|
| 504 | - 'export', |
|
| 505 | - 'import', |
|
| 506 | - 'list_users', |
|
| 507 | - 'level_1', //required if user with this role shows up in author dropdowns |
|
| 508 | - //basic ee access |
|
| 509 | - 'ee_read_ee', |
|
| 510 | - //events |
|
| 511 | - 'ee_publish_events', |
|
| 512 | - 'ee_read_private_events', |
|
| 513 | - 'ee_read_others_events', |
|
| 514 | - 'ee_read_event', |
|
| 515 | - 'ee_read_events', |
|
| 516 | - 'ee_edit_event', |
|
| 517 | - 'ee_edit_events', |
|
| 518 | - 'ee_edit_published_events', |
|
| 519 | - 'ee_edit_others_events', |
|
| 520 | - 'ee_edit_private_events', |
|
| 521 | - 'ee_delete_published_events', |
|
| 522 | - 'ee_delete_private_events', |
|
| 523 | - 'ee_delete_event', |
|
| 524 | - 'ee_delete_events', |
|
| 525 | - 'ee_delete_others_events', |
|
| 526 | - //event categories |
|
| 527 | - 'ee_manage_event_categories', |
|
| 528 | - 'ee_edit_event_category', |
|
| 529 | - 'ee_delete_event_category', |
|
| 530 | - 'ee_assign_event_category', |
|
| 531 | - //venues |
|
| 532 | - 'ee_publish_venues', |
|
| 533 | - 'ee_read_venue', |
|
| 534 | - 'ee_read_venues', |
|
| 535 | - 'ee_read_others_venues', |
|
| 536 | - 'ee_read_private_venues', |
|
| 537 | - 'ee_edit_venue', |
|
| 538 | - 'ee_edit_venues', |
|
| 539 | - 'ee_edit_others_venues', |
|
| 540 | - 'ee_edit_published_venues', |
|
| 541 | - 'ee_edit_private_venues', |
|
| 542 | - 'ee_delete_venue', |
|
| 543 | - 'ee_delete_venues', |
|
| 544 | - 'ee_delete_others_venues', |
|
| 545 | - 'ee_delete_private_venues', |
|
| 546 | - 'ee_delete_published_venues', |
|
| 547 | - //venue categories |
|
| 548 | - 'ee_manage_venue_categories', |
|
| 549 | - 'ee_edit_venue_category', |
|
| 550 | - 'ee_delete_venue_category', |
|
| 551 | - 'ee_assign_venue_category', |
|
| 552 | - //contacts |
|
| 553 | - 'ee_read_contacts', |
|
| 554 | - 'ee_edit_contacts', |
|
| 555 | - 'ee_delete_contacts', |
|
| 556 | - //registrations |
|
| 557 | - 'ee_read_registrations', |
|
| 558 | - 'ee_read_others_registrations', |
|
| 559 | - 'ee_edit_registration', |
|
| 560 | - 'ee_edit_registrations', |
|
| 561 | - 'ee_edit_others_registrations', |
|
| 562 | - 'ee_delete_registration', |
|
| 563 | - 'ee_delete_registrations', |
|
| 564 | - //checkins |
|
| 565 | - 'ee_read_others_checkins', |
|
| 566 | - 'ee_read_checkins', |
|
| 567 | - 'ee_edit_checkins', |
|
| 568 | - 'ee_edit_others_checkins', |
|
| 569 | - 'ee_delete_checkins', |
|
| 570 | - 'ee_delete_others_checkins', |
|
| 571 | - //transactions && payments |
|
| 572 | - 'ee_read_transaction', |
|
| 573 | - 'ee_read_transactions', |
|
| 574 | - 'ee_edit_payments', |
|
| 575 | - 'ee_delete_payments', |
|
| 576 | - //messages |
|
| 577 | - 'ee_read_messages', |
|
| 578 | - 'ee_read_others_messages', |
|
| 579 | - 'ee_read_global_messages', |
|
| 580 | - 'ee_edit_global_messages', |
|
| 581 | - 'ee_edit_messages', |
|
| 582 | - 'ee_edit_others_messages', |
|
| 583 | - 'ee_delete_messages', |
|
| 584 | - 'ee_delete_others_messages', |
|
| 585 | - 'ee_delete_global_messages', |
|
| 586 | - 'ee_send_message', |
|
| 587 | - //tickets |
|
| 588 | - 'ee_read_default_tickets', |
|
| 589 | - 'ee_read_others_default_tickets', |
|
| 590 | - 'ee_edit_default_tickets', |
|
| 591 | - 'ee_edit_others_default_tickets', |
|
| 592 | - 'ee_delete_default_tickets', |
|
| 593 | - 'ee_delete_others_default_tickets', |
|
| 594 | - //prices |
|
| 595 | - 'ee_edit_default_price', |
|
| 596 | - 'ee_edit_default_prices', |
|
| 597 | - 'ee_delete_default_price', |
|
| 598 | - 'ee_delete_default_prices', |
|
| 599 | - 'ee_edit_default_price_type', |
|
| 600 | - 'ee_edit_default_price_types', |
|
| 601 | - 'ee_delete_default_price_type', |
|
| 602 | - 'ee_delete_default_price_types', |
|
| 603 | - 'ee_read_default_prices', |
|
| 604 | - 'ee_read_default_price_types', |
|
| 605 | - //registration form |
|
| 606 | - 'ee_edit_questions', |
|
| 607 | - 'ee_edit_system_questions', |
|
| 608 | - 'ee_read_questions', |
|
| 609 | - 'ee_delete_questions', |
|
| 610 | - 'ee_edit_question_groups', |
|
| 611 | - 'ee_read_question_groups', |
|
| 612 | - 'ee_edit_system_question_groups', |
|
| 613 | - 'ee_delete_question_groups', |
|
| 614 | - //event_type taxonomy |
|
| 615 | - 'ee_assign_event_type', |
|
| 616 | - 'ee_manage_event_types', |
|
| 617 | - 'ee_edit_event_type', |
|
| 618 | - 'ee_delete_event_type', |
|
| 619 | - ) |
|
| 620 | - ) |
|
| 621 | - ); |
|
| 622 | - } |
|
| 623 | - |
|
| 624 | - |
|
| 625 | - |
|
| 626 | - /** |
|
| 627 | - * @return bool |
|
| 628 | - * @throws EE_Error |
|
| 629 | - */ |
|
| 630 | - private function setupCapabilitiesMap() |
|
| 631 | - { |
|
| 632 | - // if the initialization process hasn't even started, then we need to call init_caps() |
|
| 633 | - if($this->initialized === null) { |
|
| 634 | - return $this->init_caps(); |
|
| 635 | - } |
|
| 636 | - // unless resetting, get caps from db if we haven't already |
|
| 637 | - $this->capabilities_map = $this->reset || ! empty($this->capabilities_map) |
|
| 638 | - ? $this->capabilities_map |
|
| 639 | - : get_option(self::option_name, array()); |
|
| 640 | - return true; |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - |
|
| 644 | - |
|
| 645 | - /** |
|
| 646 | - * @param bool $update |
|
| 647 | - * @return bool |
|
| 648 | - */ |
|
| 649 | - private function updateCapabilitiesMap($update = true) |
|
| 650 | - { |
|
| 651 | - return $update ? update_option(self::option_name, $this->capabilities_map) : false; |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - |
|
| 655 | - |
|
| 656 | - /** |
|
| 657 | - * Adds capabilities to roles. |
|
| 658 | - * |
|
| 659 | - * @since 4.9.42 |
|
| 660 | - * @param array $capabilities_to_add array of capabilities to add, indexed by roles. |
|
| 661 | - * Note that this should ONLY be called on activation hook |
|
| 662 | - * otherwise the caps will be added on every request. |
|
| 663 | - * @return bool |
|
| 664 | - * @throws \EE_Error |
|
| 665 | - */ |
|
| 666 | - public function addCaps(array $capabilities_to_add) |
|
| 667 | - { |
|
| 668 | - // don't do anything if the capabilities map can not be initialized |
|
| 669 | - if (! $this->setupCapabilitiesMap()) { |
|
| 670 | - return false; |
|
| 671 | - } |
|
| 672 | - // and filter the array so others can get in on the fun during resets |
|
| 673 | - $capabilities_to_add = apply_filters( |
|
| 674 | - 'FHEE__EE_Capabilities__addCaps__capabilities_to_add', |
|
| 675 | - $capabilities_to_add, |
|
| 676 | - $this->reset, |
|
| 677 | - $this->capabilities_map |
|
| 678 | - ); |
|
| 679 | - $update_capabilities_map = false; |
|
| 680 | - // if not reset, see what caps are new for each role. if they're new, add them. |
|
| 681 | - foreach ($capabilities_to_add as $role => $caps_for_role) { |
|
| 682 | - if (is_array($caps_for_role)) { |
|
| 683 | - foreach ($caps_for_role as $cap) { |
|
| 684 | - if ( |
|
| 685 | - ! $this->capHasBeenAddedToRole($role, $cap) |
|
| 686 | - && $this->add_cap_to_role($role, $cap, true, false) |
|
| 687 | - ) { |
|
| 688 | - $update_capabilities_map = true; |
|
| 689 | - } |
|
| 690 | - } |
|
| 691 | - } |
|
| 692 | - } |
|
| 693 | - // now let's just save the cap that has been set but only if there's been a change. |
|
| 694 | - $updated = $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 695 | - do_action('AHEE__EE_Capabilities__addCaps__complete', $this->capabilities_map, $updated); |
|
| 696 | - return $updated; |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - |
|
| 700 | - |
|
| 701 | - /** |
|
| 702 | - * Loops through the capabilities map and removes the role caps specified by the incoming array |
|
| 703 | - * |
|
| 704 | - * @param array $caps_map map of capabilities to be removed (indexed by roles) |
|
| 705 | - * @return bool |
|
| 706 | - * @throws \EE_Error |
|
| 707 | - */ |
|
| 708 | - public function removeCaps($caps_map) |
|
| 709 | - { |
|
| 710 | - // don't do anything if the capabilities map can not be initialized |
|
| 711 | - if (! $this->setupCapabilitiesMap()) { |
|
| 712 | - return false; |
|
| 713 | - } |
|
| 714 | - $update_capabilities_map = false; |
|
| 715 | - foreach ($caps_map as $role => $caps_for_role) { |
|
| 716 | - if (is_array($caps_for_role)) { |
|
| 717 | - foreach ($caps_for_role as $cap) { |
|
| 718 | - if ( |
|
| 719 | - $this->capHasBeenAddedToRole($role, $cap) |
|
| 720 | - && $this->remove_cap_from_role($role, $cap, false) |
|
| 721 | - ) { |
|
| 722 | - $update_capabilities_map = true; |
|
| 723 | - } |
|
| 724 | - } |
|
| 725 | - } |
|
| 726 | - } |
|
| 727 | - // maybe resave the caps |
|
| 728 | - return $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 729 | - } |
|
| 730 | - |
|
| 731 | - |
|
| 732 | - |
|
| 733 | - /** |
|
| 734 | - * This method sets a capability on a role. Note this should only be done on activation, or if you have something |
|
| 735 | - * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note. |
|
| 736 | - * this is a wrapper for $wp_role->add_cap() |
|
| 737 | - * |
|
| 738 | - * @see wp-includes/capabilities.php |
|
| 739 | - * @since 4.5.0 |
|
| 740 | - * @param string|WP_Role $role A WordPress role the capability is being added to |
|
| 741 | - * @param string $cap The capability being added to the role |
|
| 742 | - * @param bool $grant Whether to grant access to this cap on this role. |
|
| 743 | - * @param bool $update_capabilities_map |
|
| 744 | - * @return bool |
|
| 745 | - * @throws \EE_Error |
|
| 746 | - */ |
|
| 747 | - public function add_cap_to_role($role, $cap, $grant = true, $update_capabilities_map = true) |
|
| 748 | - { |
|
| 749 | - // capture incoming value for $role because we may need it to create a new WP_Role |
|
| 750 | - $orig_role = $role; |
|
| 751 | - $role = $role instanceof WP_Role ? $role : get_role($role); |
|
| 752 | - //if the role isn't available then we create it. |
|
| 753 | - if (! $role instanceof WP_Role) { |
|
| 754 | - // if a plugin wants to create a specific role name then they should create the role before |
|
| 755 | - // EE_Capabilities does. Otherwise this function will create the role name from the slug: |
|
| 756 | - // - removes any `ee_` namespacing from the start of the slug. |
|
| 757 | - // - replaces `_` with ` ` (empty space). |
|
| 758 | - // - sentence case on the resulting string. |
|
| 759 | - $role_label = ucwords(str_replace(array('ee_', '_'), array('', ' '), $orig_role)); |
|
| 760 | - $role = add_role($orig_role, $role_label); |
|
| 761 | - } |
|
| 762 | - if ($role instanceof WP_Role) { |
|
| 763 | - // don't do anything if the capabilities map can not be initialized |
|
| 764 | - if (! $this->setupCapabilitiesMap()) { |
|
| 765 | - return false; |
|
| 766 | - } |
|
| 767 | - if (! $this->capHasBeenAddedToRole($role->name, $cap)) { |
|
| 768 | - $role->add_cap($cap, $grant); |
|
| 769 | - $this->capabilities_map[ $role->name ][] = $cap; |
|
| 770 | - $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 771 | - return true; |
|
| 772 | - } |
|
| 773 | - } |
|
| 774 | - return false; |
|
| 775 | - } |
|
| 776 | - |
|
| 777 | - |
|
| 778 | - |
|
| 779 | - /** |
|
| 780 | - * Functions similarly to add_cap_to_role except removes cap from given role. |
|
| 781 | - * Wrapper for $wp_role->remove_cap() |
|
| 782 | - * |
|
| 783 | - * @see wp-includes/capabilities.php |
|
| 784 | - * @since 4.5.0 |
|
| 785 | - * @param string|WP_Role $role A WordPress role the capability is being removed from. |
|
| 786 | - * @param string $cap The capability being removed |
|
| 787 | - * @param bool $update_capabilities_map |
|
| 788 | - * @return bool |
|
| 789 | - * @throws \EE_Error |
|
| 790 | - */ |
|
| 791 | - public function remove_cap_from_role($role, $cap, $update_capabilities_map = true) |
|
| 792 | - { |
|
| 793 | - // don't do anything if the capabilities map can not be initialized |
|
| 794 | - if (! $this->setupCapabilitiesMap()) { |
|
| 795 | - return false; |
|
| 796 | - } |
|
| 797 | - $role = $role instanceof WP_Role ? $role :get_role($role); |
|
| 798 | - if ($index = $this->capHasBeenAddedToRole($role->name, $cap, true)) { |
|
| 799 | - $role->remove_cap($cap); |
|
| 800 | - unset($this->capabilities_map[ $role->name ][ $index ]); |
|
| 801 | - $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 802 | - return true; |
|
| 803 | - } |
|
| 804 | - return false; |
|
| 805 | - } |
|
| 806 | - |
|
| 807 | - |
|
| 808 | - |
|
| 809 | - /** |
|
| 810 | - * @param string $role_name |
|
| 811 | - * @param string $cap |
|
| 812 | - * @param bool $get_index |
|
| 813 | - * @return bool|mixed |
|
| 814 | - */ |
|
| 815 | - private function capHasBeenAddedToRole($role_name='', $cap='', $get_index = false) |
|
| 816 | - { |
|
| 817 | - if ( |
|
| 818 | - isset($this->capabilities_map[$role_name]) |
|
| 819 | - && ($index = array_search($cap, $this->capabilities_map[$role_name], true)) !== false |
|
| 820 | - ) { |
|
| 821 | - return $get_index ? $index : true; |
|
| 822 | - } |
|
| 823 | - return false; |
|
| 824 | - } |
|
| 825 | - |
|
| 826 | - |
|
| 827 | - |
|
| 828 | - /** |
|
| 829 | - * Wrapper for the native WP current_user_can() method. |
|
| 830 | - * This is provided as a handy method for a couple things: |
|
| 831 | - * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
| 832 | - * write those filters wherever current_user_can is called). |
|
| 833 | - * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
| 834 | - * |
|
| 835 | - * @since 4.5.0 |
|
| 836 | - * |
|
| 837 | - * @param string $cap The cap being checked. |
|
| 838 | - * @param string $context The context where the current_user_can is being called from. |
|
| 839 | - * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
| 840 | - * filters. |
|
| 841 | - * |
|
| 842 | - * @return bool Whether user can or not. |
|
| 843 | - */ |
|
| 844 | - public function current_user_can($cap, $context, $id = 0) |
|
| 845 | - { |
|
| 846 | - //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 847 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id); |
|
| 848 | - $filtered_cap = apply_filters( |
|
| 849 | - 'FHEE__EE_Capabilities__current_user_can__cap', |
|
| 850 | - $filtered_cap, |
|
| 851 | - $context, |
|
| 852 | - $cap, |
|
| 853 | - $id |
|
| 854 | - ); |
|
| 855 | - return ! empty($id) |
|
| 856 | - ? current_user_can($filtered_cap, $id) |
|
| 857 | - : current_user_can($filtered_cap); |
|
| 858 | - } |
|
| 859 | - |
|
| 860 | - |
|
| 861 | - |
|
| 862 | - /** |
|
| 863 | - * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class. |
|
| 864 | - * |
|
| 865 | - * @param int|WP_User $user Either the user_id or a WP_User object |
|
| 866 | - * @param string $cap The capability string being checked |
|
| 867 | - * @param string $context The context where the user_can is being called from (used in filters). |
|
| 868 | - * @param int $id Optional. Id for item where user_can is being called from ( used in map_meta_cap() |
|
| 869 | - * filters) |
|
| 870 | - * |
|
| 871 | - * @return bool Whether user can or not. |
|
| 872 | - */ |
|
| 873 | - public function user_can($user, $cap, $context, $id = 0) |
|
| 874 | - { |
|
| 875 | - //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 876 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id); |
|
| 877 | - $filtered_cap = apply_filters( |
|
| 878 | - 'FHEE__EE_Capabilities__user_can__cap', |
|
| 879 | - $filtered_cap, |
|
| 880 | - $context, |
|
| 881 | - $cap, |
|
| 882 | - $user, |
|
| 883 | - $id |
|
| 884 | - ); |
|
| 885 | - return ! empty($id) |
|
| 886 | - ? user_can($user, $filtered_cap, $id) |
|
| 887 | - : user_can($user, $filtered_cap); |
|
| 888 | - } |
|
| 889 | - |
|
| 890 | - |
|
| 891 | - |
|
| 892 | - /** |
|
| 893 | - * Wrapper for the native WP current_user_can_for_blog() method. |
|
| 894 | - * This is provided as a handy method for a couple things: |
|
| 895 | - * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
| 896 | - * write those filters wherever current_user_can is called). |
|
| 897 | - * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
| 898 | - * |
|
| 899 | - * @since 4.5.0 |
|
| 900 | - * |
|
| 901 | - * @param int $blog_id The blog id that is being checked for. |
|
| 902 | - * @param string $cap The cap being checked. |
|
| 903 | - * @param string $context The context where the current_user_can is being called from. |
|
| 904 | - * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
| 905 | - * filters. |
|
| 906 | - * |
|
| 907 | - * @return bool Whether user can or not. |
|
| 908 | - */ |
|
| 909 | - public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0) |
|
| 910 | - { |
|
| 911 | - $user_can = ! empty($id) |
|
| 912 | - ? current_user_can_for_blog($blog_id, $cap, $id) |
|
| 913 | - : current_user_can($blog_id, $cap); |
|
| 914 | - //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 915 | - $user_can = apply_filters( |
|
| 916 | - 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context, |
|
| 917 | - $user_can, |
|
| 918 | - $blog_id, |
|
| 919 | - $cap, |
|
| 920 | - $id |
|
| 921 | - ); |
|
| 922 | - $user_can = apply_filters( |
|
| 923 | - 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can', |
|
| 924 | - $user_can, |
|
| 925 | - $context, |
|
| 926 | - $blog_id, |
|
| 927 | - $cap, |
|
| 928 | - $id |
|
| 929 | - ); |
|
| 930 | - return $user_can; |
|
| 931 | - } |
|
| 932 | - |
|
| 933 | - |
|
| 934 | - |
|
| 935 | - /** |
|
| 936 | - * This helper method just returns an array of registered EE capabilities. |
|
| 937 | - * |
|
| 938 | - * @since 4.5.0 |
|
| 939 | - * @param string $role If empty then the entire role/capability map is returned. |
|
| 940 | - * Otherwise just the capabilities for the given role are returned. |
|
| 941 | - * @return array |
|
| 942 | - * @throws EE_Error |
|
| 943 | - */ |
|
| 944 | - public function get_ee_capabilities($role = 'administrator') |
|
| 945 | - { |
|
| 946 | - if (! $this->initialized) { |
|
| 947 | - $this->init_caps(); |
|
| 948 | - } |
|
| 949 | - if (empty($role)) { |
|
| 950 | - return $this->capabilities_map; |
|
| 951 | - } |
|
| 952 | - return isset($this->capabilities_map[ $role ]) |
|
| 953 | - ? $this->capabilities_map[ $role ] |
|
| 954 | - : array(); |
|
| 955 | - } |
|
| 956 | - |
|
| 957 | - |
|
| 958 | - |
|
| 959 | - /** |
|
| 960 | - * @deprecated 4.9.42 |
|
| 961 | - * @param bool $reset If you need to reset Event Espresso's capabilities, |
|
| 962 | - * then please use the init_caps() method with the "$reset" parameter set to "true" |
|
| 963 | - * @param array $caps_map Optional. |
|
| 964 | - * Can be used to send a custom map of roles and capabilities for setting them up. |
|
| 965 | - * Note that this should ONLY be called on activation hook or some other one-time |
|
| 966 | - * task otherwise the caps will be added on every request. |
|
| 967 | - * @return void |
|
| 968 | - * @throws EE_Error |
|
| 969 | - */ |
|
| 970 | - public function init_role_caps($reset = false, $caps_map = array()) |
|
| 971 | - { |
|
| 972 | - // If this method is called directly and reset is set as 'true', |
|
| 973 | - // then display a doing it wrong notice, because we want resets to go through init_caps() |
|
| 974 | - // to guarantee that everything is set up correctly. |
|
| 975 | - // This prevents the capabilities map getting reset incorrectly by direct calls to this method. |
|
| 976 | - if ($reset) { |
|
| 977 | - EE_Error::doing_it_wrong( |
|
| 978 | - __METHOD__, |
|
| 979 | - sprintf( |
|
| 980 | - esc_html__( |
|
| 981 | - 'The "%1$s" parameter for the "%2$s" method is deprecated. If you need to reset Event Espresso\'s capabilities, then please use the "%3$s" method with the "%1$s" parameter set to "%4$s".', |
|
| 982 | - 'event_espresso' |
|
| 983 | - ), |
|
| 984 | - '$reset', |
|
| 985 | - __METHOD__ . '()', |
|
| 986 | - 'EE_Capabilities::init_caps()', |
|
| 987 | - 'true' |
|
| 988 | - ), |
|
| 989 | - '4.9.42', |
|
| 990 | - '5.0.0' |
|
| 991 | - ); |
|
| 992 | - } |
|
| 993 | - $this->addCaps($caps_map); |
|
| 994 | - } |
|
| 21 | + /** |
|
| 22 | + * the name of the wp option used to store caps previously initialized |
|
| 23 | + */ |
|
| 24 | + const option_name = 'ee_caps_initialized'; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * instance of EE_Capabilities object |
|
| 28 | + * |
|
| 29 | + * @var EE_Capabilities |
|
| 30 | + */ |
|
| 31 | + private static $_instance; |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * This is a map of caps that correspond to a default WP_Role. |
|
| 36 | + * Array is indexed by Role and values are ee capabilities. |
|
| 37 | + * |
|
| 38 | + * @since 4.5.0 |
|
| 39 | + * |
|
| 40 | + * @var array |
|
| 41 | + */ |
|
| 42 | + private $capabilities_map = array(); |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * This used to hold an array of EE_Meta_Capability_Map objects |
|
| 46 | + * that define the granular capabilities mapped to for a user depending on context. |
|
| 47 | + * |
|
| 48 | + * @var EE_Meta_Capability_Map[] |
|
| 49 | + */ |
|
| 50 | + private $_meta_caps = array(); |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * The internal $capabilities_map needs to be initialized before it can be used. |
|
| 54 | + * This flag tracks whether that has happened or not. |
|
| 55 | + * But for this to work, we need three states to indicate: |
|
| 56 | + * initialization has not occurred at all |
|
| 57 | + * initialization has started but is not complete |
|
| 58 | + * initialization is complete |
|
| 59 | + * The reason this is needed is because the addCaps() method |
|
| 60 | + * normally requires the $capabilities_map to be initialized, |
|
| 61 | + * but is also used during the initialization process. |
|
| 62 | + * So: |
|
| 63 | + * If initialized === null, init_caps() will be called before any other methods will run. |
|
| 64 | + * If initialized === false, then init_caps() is in the process of running it's logic. |
|
| 65 | + * If initialized === true, then init_caps() has completed the initialization process. |
|
| 66 | + * |
|
| 67 | + * @var boolean|null $initialized |
|
| 68 | + */ |
|
| 69 | + private $initialized; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @var boolean $reset |
|
| 73 | + */ |
|
| 74 | + private $reset = false; |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * singleton method used to instantiate class object |
|
| 80 | + * |
|
| 81 | + * @since 4.5.0 |
|
| 82 | + * |
|
| 83 | + * @return EE_Capabilities |
|
| 84 | + */ |
|
| 85 | + public static function instance() |
|
| 86 | + { |
|
| 87 | + //check if instantiated, and if not do so. |
|
| 88 | + if (! self::$_instance instanceof EE_Capabilities) { |
|
| 89 | + self::$_instance = new self(); |
|
| 90 | + } |
|
| 91 | + return self::$_instance; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * private constructor |
|
| 98 | + * |
|
| 99 | + * @since 4.5.0 |
|
| 100 | + */ |
|
| 101 | + private function __construct() |
|
| 102 | + { |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * This delays the initialization of the capabilities class until EE_System core is loaded and ready. |
|
| 109 | + * |
|
| 110 | + * @param bool $reset allows for resetting the default capabilities saved on roles. Note that this doesn't |
|
| 111 | + * actually REMOVE any capabilities from existing roles, it just resaves defaults roles and |
|
| 112 | + * ensures that they are up to date. |
|
| 113 | + * |
|
| 114 | + * @since 4.5.0 |
|
| 115 | + * @return bool |
|
| 116 | + * @throws EE_Error |
|
| 117 | + */ |
|
| 118 | + public function init_caps($reset = false) |
|
| 119 | + { |
|
| 120 | + if(! EE_Maintenance_Mode::instance()->models_can_query()){ |
|
| 121 | + return false; |
|
| 122 | + } |
|
| 123 | + $this->reset = filter_var($reset, FILTER_VALIDATE_BOOLEAN); |
|
| 124 | + // if reset, then completely delete the cache option and clear the $capabilities_map property. |
|
| 125 | + if ($this->reset) { |
|
| 126 | + $this->initialized = null; |
|
| 127 | + $this->capabilities_map = array(); |
|
| 128 | + delete_option(self::option_name); |
|
| 129 | + } |
|
| 130 | + if ($this->initialized === null) { |
|
| 131 | + $this->initialized = false; |
|
| 132 | + do_action( |
|
| 133 | + 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
| 134 | + $this->reset |
|
| 135 | + ); |
|
| 136 | + $this->addCaps($this->_init_caps_map()); |
|
| 137 | + $this->_set_meta_caps(); |
|
| 138 | + do_action( |
|
| 139 | + 'AHEE__EE_Capabilities__init_caps__after_initialization', |
|
| 140 | + $this->capabilities_map |
|
| 141 | + ); |
|
| 142 | + $this->initialized = true; |
|
| 143 | + } |
|
| 144 | + // reset $this->reset so that it's not stuck on true if init_caps() gets called again |
|
| 145 | + $this->reset = false; |
|
| 146 | + return true; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * This sets the meta caps property. |
|
| 153 | + * |
|
| 154 | + * @since 4.5.0 |
|
| 155 | + * @return void |
|
| 156 | + * @throws EE_Error |
|
| 157 | + */ |
|
| 158 | + private function _set_meta_caps() |
|
| 159 | + { |
|
| 160 | + // get default meta caps and filter the returned array |
|
| 161 | + $this->_meta_caps = apply_filters( |
|
| 162 | + 'FHEE__EE_Capabilities___set_meta_caps__meta_caps', |
|
| 163 | + $this->_get_default_meta_caps_array() |
|
| 164 | + ); |
|
| 165 | + //add filter for map_meta_caps but only if models can query. |
|
| 166 | + if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) { |
|
| 167 | + add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4); |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * This builds and returns the default meta_caps array only once. |
|
| 175 | + * |
|
| 176 | + * @since 4.8.28.rc.012 |
|
| 177 | + * @return array |
|
| 178 | + * @throws EE_Error |
|
| 179 | + */ |
|
| 180 | + private function _get_default_meta_caps_array() |
|
| 181 | + { |
|
| 182 | + static $default_meta_caps = array(); |
|
| 183 | + // make sure we're only ever initializing the default _meta_caps array once if it's empty. |
|
| 184 | + if (empty($default_meta_caps)) { |
|
| 185 | + $default_meta_caps = array( |
|
| 186 | + //edits |
|
| 187 | + new EE_Meta_Capability_Map_Edit( |
|
| 188 | + 'ee_edit_event', |
|
| 189 | + array('Event', 'ee_edit_published_events', 'ee_edit_others_events', 'ee_edit_private_events') |
|
| 190 | + ), |
|
| 191 | + new EE_Meta_Capability_Map_Edit( |
|
| 192 | + 'ee_edit_venue', |
|
| 193 | + array('Venue', 'ee_edit_published_venues', 'ee_edit_others_venues', 'ee_edit_private_venues') |
|
| 194 | + ), |
|
| 195 | + new EE_Meta_Capability_Map_Edit( |
|
| 196 | + 'ee_edit_registration', |
|
| 197 | + array('Registration', '', 'ee_edit_others_registrations', '') |
|
| 198 | + ), |
|
| 199 | + new EE_Meta_Capability_Map_Edit( |
|
| 200 | + 'ee_edit_checkin', |
|
| 201 | + array('Registration', '', 'ee_edit_others_checkins', '') |
|
| 202 | + ), |
|
| 203 | + new EE_Meta_Capability_Map_Messages_Cap( |
|
| 204 | + 'ee_edit_message', |
|
| 205 | + array('Message_Template_Group', '', 'ee_edit_others_messages', 'ee_edit_global_messages') |
|
| 206 | + ), |
|
| 207 | + new EE_Meta_Capability_Map_Edit( |
|
| 208 | + 'ee_edit_default_ticket', |
|
| 209 | + array('Ticket', '', 'ee_edit_others_default_tickets', '') |
|
| 210 | + ), |
|
| 211 | + new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 212 | + 'ee_edit_question', |
|
| 213 | + array('Question', '', '', 'ee_edit_system_questions') |
|
| 214 | + ), |
|
| 215 | + new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 216 | + 'ee_edit_question_group', |
|
| 217 | + array('Question_Group', '', '', 'ee_edit_system_question_groups') |
|
| 218 | + ), |
|
| 219 | + new EE_Meta_Capability_Map_Edit( |
|
| 220 | + 'ee_edit_payment_method', |
|
| 221 | + array('Payment_Method', '', 'ee_edit_others_payment_methods', '') |
|
| 222 | + ), |
|
| 223 | + //reads |
|
| 224 | + new EE_Meta_Capability_Map_Read( |
|
| 225 | + 'ee_read_event', |
|
| 226 | + array('Event', '', 'ee_read_others_events', 'ee_read_private_events') |
|
| 227 | + ), |
|
| 228 | + new EE_Meta_Capability_Map_Read( |
|
| 229 | + 'ee_read_venue', |
|
| 230 | + array('Venue', '', 'ee_read_others_venues', 'ee_read_private_venues') |
|
| 231 | + ), |
|
| 232 | + new EE_Meta_Capability_Map_Read( |
|
| 233 | + 'ee_read_registration', |
|
| 234 | + array('Registration', '', 'ee_read_others_registrations', '') |
|
| 235 | + ), |
|
| 236 | + new EE_Meta_Capability_Map_Read( |
|
| 237 | + 'ee_read_checkin', |
|
| 238 | + array('Registration', '', 'ee_read_others_checkins', '') |
|
| 239 | + ), |
|
| 240 | + new EE_Meta_Capability_Map_Messages_Cap( |
|
| 241 | + 'ee_read_message', |
|
| 242 | + array('Message_Template_Group', '', 'ee_read_others_messages', 'ee_read_global_messages') |
|
| 243 | + ), |
|
| 244 | + new EE_Meta_Capability_Map_Read( |
|
| 245 | + 'ee_read_default_ticket', |
|
| 246 | + array('Ticket', '', 'ee_read_others_default_tickets', '') |
|
| 247 | + ), |
|
| 248 | + new EE_Meta_Capability_Map_Read( |
|
| 249 | + 'ee_read_payment_method', |
|
| 250 | + array('Payment_Method', '', 'ee_read_others_payment_methods', '') |
|
| 251 | + ), |
|
| 252 | + //deletes |
|
| 253 | + new EE_Meta_Capability_Map_Delete( |
|
| 254 | + 'ee_delete_event', |
|
| 255 | + array( |
|
| 256 | + 'Event', |
|
| 257 | + 'ee_delete_published_events', |
|
| 258 | + 'ee_delete_others_events', |
|
| 259 | + 'ee_delete_private_events', |
|
| 260 | + ) |
|
| 261 | + ), |
|
| 262 | + new EE_Meta_Capability_Map_Delete( |
|
| 263 | + 'ee_delete_venue', |
|
| 264 | + array( |
|
| 265 | + 'Venue', |
|
| 266 | + 'ee_delete_published_venues', |
|
| 267 | + 'ee_delete_others_venues', |
|
| 268 | + 'ee_delete_private_venues', |
|
| 269 | + ) |
|
| 270 | + ), |
|
| 271 | + new EE_Meta_Capability_Map_Delete( |
|
| 272 | + 'ee_delete_registration', |
|
| 273 | + array('Registration', '', 'ee_delete_others_registrations', '') |
|
| 274 | + ), |
|
| 275 | + new EE_Meta_Capability_Map_Delete( |
|
| 276 | + 'ee_delete_checkin', |
|
| 277 | + array('Registration', '', 'ee_delete_others_checkins', '') |
|
| 278 | + ), |
|
| 279 | + new EE_Meta_Capability_Map_Messages_Cap( |
|
| 280 | + 'ee_delete_message', |
|
| 281 | + array('Message_Template_Group', '', 'ee_delete_others_messages', 'ee_delete_global_messages') |
|
| 282 | + ), |
|
| 283 | + new EE_Meta_Capability_Map_Delete( |
|
| 284 | + 'ee_delete_default_ticket', |
|
| 285 | + array('Ticket', '', 'ee_delete_others_default_tickets', '') |
|
| 286 | + ), |
|
| 287 | + new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 288 | + 'ee_delete_question', |
|
| 289 | + array('Question', '', '', 'delete_system_questions') |
|
| 290 | + ), |
|
| 291 | + new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 292 | + 'ee_delete_question_group', |
|
| 293 | + array('Question_Group', '', '', 'delete_system_question_groups') |
|
| 294 | + ), |
|
| 295 | + new EE_Meta_Capability_Map_Delete( |
|
| 296 | + 'ee_delete_payment_method', |
|
| 297 | + array('Payment_Method', '', 'ee_delete_others_payment_methods', '') |
|
| 298 | + ), |
|
| 299 | + ); |
|
| 300 | + } |
|
| 301 | + return $default_meta_caps; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 308 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 309 | + * |
|
| 310 | + * The actual logic is carried out by implementer classes in their definition of _map_meta_caps. |
|
| 311 | + * |
|
| 312 | + * @since 4.5.0 |
|
| 313 | + * @see wp-includes/capabilities.php |
|
| 314 | + * |
|
| 315 | + * @param array $caps actual users capabilities |
|
| 316 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 317 | + * @param int $user_id The user id |
|
| 318 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 319 | + * @return array actual users capabilities |
|
| 320 | + * @throws EE_Error |
|
| 321 | + */ |
|
| 322 | + public function map_meta_caps($caps, $cap, $user_id, $args) |
|
| 323 | + { |
|
| 324 | + if (did_action('AHEE__EE_System__load_espresso_addons__complete')) { |
|
| 325 | + //loop through our _meta_caps array |
|
| 326 | + foreach ($this->_meta_caps as $meta_map) { |
|
| 327 | + if (! $meta_map instanceof EE_Meta_Capability_Map) { |
|
| 328 | + continue; |
|
| 329 | + } |
|
| 330 | + // don't load models if there is no object ID in the args |
|
| 331 | + if (! empty($args[0])) { |
|
| 332 | + $meta_map->ensure_is_model(); |
|
| 333 | + } |
|
| 334 | + $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args); |
|
| 335 | + } |
|
| 336 | + } |
|
| 337 | + return $caps; |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * This sets up and returns the initial capabilities map for Event Espresso |
|
| 344 | + * Note this array is filtered. |
|
| 345 | + * It is assumed that all available EE capabilities are assigned to the administrator role. |
|
| 346 | + * |
|
| 347 | + * @since 4.5.0 |
|
| 348 | + * |
|
| 349 | + * @return array |
|
| 350 | + */ |
|
| 351 | + private function _init_caps_map() |
|
| 352 | + { |
|
| 353 | + return apply_filters( |
|
| 354 | + 'FHEE__EE_Capabilities__init_caps_map__caps', |
|
| 355 | + array( |
|
| 356 | + 'administrator' => array( |
|
| 357 | + //basic access |
|
| 358 | + 'ee_read_ee', |
|
| 359 | + //gateways |
|
| 360 | + /** |
|
| 361 | + * note that with payment method capabilities, although we've implemented |
|
| 362 | + * capability mapping which will be used for accessing payment methods owned by |
|
| 363 | + * other users. This is not fully implemented yet in the payment method ui. |
|
| 364 | + * Currently only the "plural" caps are in active use. |
|
| 365 | + * (Specific payment method caps are in use as well). |
|
| 366 | + **/ |
|
| 367 | + 'ee_manage_gateways', |
|
| 368 | + 'ee_read_payment_methods', |
|
| 369 | + 'ee_read_others_payment_methods', |
|
| 370 | + 'ee_edit_payment_methods', |
|
| 371 | + 'ee_edit_others_payment_methods', |
|
| 372 | + 'ee_delete_payment_methods', |
|
| 373 | + //events |
|
| 374 | + 'ee_publish_events', |
|
| 375 | + 'ee_read_private_events', |
|
| 376 | + 'ee_read_others_events', |
|
| 377 | + 'ee_read_events', |
|
| 378 | + 'ee_edit_events', |
|
| 379 | + 'ee_edit_published_events', |
|
| 380 | + 'ee_edit_others_events', |
|
| 381 | + 'ee_edit_private_events', |
|
| 382 | + 'ee_delete_published_events', |
|
| 383 | + 'ee_delete_private_events', |
|
| 384 | + 'ee_delete_events', |
|
| 385 | + 'ee_delete_others_events', |
|
| 386 | + //event categories |
|
| 387 | + 'ee_manage_event_categories', |
|
| 388 | + 'ee_edit_event_category', |
|
| 389 | + 'ee_delete_event_category', |
|
| 390 | + 'ee_assign_event_category', |
|
| 391 | + //venues |
|
| 392 | + 'ee_publish_venues', |
|
| 393 | + 'ee_read_venues', |
|
| 394 | + 'ee_read_others_venues', |
|
| 395 | + 'ee_read_private_venues', |
|
| 396 | + 'ee_edit_venues', |
|
| 397 | + 'ee_edit_others_venues', |
|
| 398 | + 'ee_edit_published_venues', |
|
| 399 | + 'ee_edit_private_venues', |
|
| 400 | + 'ee_delete_venues', |
|
| 401 | + 'ee_delete_others_venues', |
|
| 402 | + 'ee_delete_private_venues', |
|
| 403 | + 'ee_delete_published_venues', |
|
| 404 | + //venue categories |
|
| 405 | + 'ee_manage_venue_categories', |
|
| 406 | + 'ee_edit_venue_category', |
|
| 407 | + 'ee_delete_venue_category', |
|
| 408 | + 'ee_assign_venue_category', |
|
| 409 | + //contacts |
|
| 410 | + 'ee_read_contacts', |
|
| 411 | + 'ee_edit_contacts', |
|
| 412 | + 'ee_delete_contacts', |
|
| 413 | + //registrations |
|
| 414 | + 'ee_read_registrations', |
|
| 415 | + 'ee_read_others_registrations', |
|
| 416 | + 'ee_edit_registrations', |
|
| 417 | + 'ee_edit_others_registrations', |
|
| 418 | + 'ee_delete_registrations', |
|
| 419 | + //checkins |
|
| 420 | + 'ee_read_others_checkins', |
|
| 421 | + 'ee_read_checkins', |
|
| 422 | + 'ee_edit_checkins', |
|
| 423 | + 'ee_edit_others_checkins', |
|
| 424 | + 'ee_delete_checkins', |
|
| 425 | + 'ee_delete_others_checkins', |
|
| 426 | + //transactions && payments |
|
| 427 | + 'ee_read_transaction', |
|
| 428 | + 'ee_read_transactions', |
|
| 429 | + 'ee_edit_payments', |
|
| 430 | + 'ee_delete_payments', |
|
| 431 | + //messages |
|
| 432 | + 'ee_read_messages', |
|
| 433 | + 'ee_read_others_messages', |
|
| 434 | + 'ee_read_global_messages', |
|
| 435 | + 'ee_edit_global_messages', |
|
| 436 | + 'ee_edit_messages', |
|
| 437 | + 'ee_edit_others_messages', |
|
| 438 | + 'ee_delete_messages', |
|
| 439 | + 'ee_delete_others_messages', |
|
| 440 | + 'ee_delete_global_messages', |
|
| 441 | + 'ee_send_message', |
|
| 442 | + //tickets |
|
| 443 | + 'ee_read_default_tickets', |
|
| 444 | + 'ee_read_others_default_tickets', |
|
| 445 | + 'ee_edit_default_tickets', |
|
| 446 | + 'ee_edit_others_default_tickets', |
|
| 447 | + 'ee_delete_default_tickets', |
|
| 448 | + 'ee_delete_others_default_tickets', |
|
| 449 | + //prices |
|
| 450 | + 'ee_edit_default_price', |
|
| 451 | + 'ee_edit_default_prices', |
|
| 452 | + 'ee_delete_default_price', |
|
| 453 | + 'ee_delete_default_prices', |
|
| 454 | + 'ee_edit_default_price_type', |
|
| 455 | + 'ee_edit_default_price_types', |
|
| 456 | + 'ee_delete_default_price_type', |
|
| 457 | + 'ee_delete_default_price_types', |
|
| 458 | + 'ee_read_default_prices', |
|
| 459 | + 'ee_read_default_price_types', |
|
| 460 | + //registration form |
|
| 461 | + 'ee_edit_questions', |
|
| 462 | + 'ee_edit_system_questions', |
|
| 463 | + 'ee_read_questions', |
|
| 464 | + 'ee_delete_questions', |
|
| 465 | + 'ee_edit_question_groups', |
|
| 466 | + 'ee_read_question_groups', |
|
| 467 | + 'ee_edit_system_question_groups', |
|
| 468 | + 'ee_delete_question_groups', |
|
| 469 | + //event_type taxonomy |
|
| 470 | + 'ee_assign_event_type', |
|
| 471 | + 'ee_manage_event_types', |
|
| 472 | + 'ee_edit_event_type', |
|
| 473 | + 'ee_delete_event_type', |
|
| 474 | + ), |
|
| 475 | + 'ee_events_administrator' => array( |
|
| 476 | + //core wp caps |
|
| 477 | + 'read', |
|
| 478 | + 'read_private_pages', |
|
| 479 | + 'read_private_posts', |
|
| 480 | + 'edit_users', |
|
| 481 | + 'edit_posts', |
|
| 482 | + 'edit_pages', |
|
| 483 | + 'edit_published_posts', |
|
| 484 | + 'edit_published_pages', |
|
| 485 | + 'edit_private_pages', |
|
| 486 | + 'edit_private_posts', |
|
| 487 | + 'edit_others_posts', |
|
| 488 | + 'edit_others_pages', |
|
| 489 | + 'publish_posts', |
|
| 490 | + 'publish_pages', |
|
| 491 | + 'delete_posts', |
|
| 492 | + 'delete_pages', |
|
| 493 | + 'delete_private_pages', |
|
| 494 | + 'delete_private_posts', |
|
| 495 | + 'delete_published_pages', |
|
| 496 | + 'delete_published_posts', |
|
| 497 | + 'delete_others_posts', |
|
| 498 | + 'delete_others_pages', |
|
| 499 | + 'manage_categories', |
|
| 500 | + 'manage_links', |
|
| 501 | + 'moderate_comments', |
|
| 502 | + 'unfiltered_html', |
|
| 503 | + 'upload_files', |
|
| 504 | + 'export', |
|
| 505 | + 'import', |
|
| 506 | + 'list_users', |
|
| 507 | + 'level_1', //required if user with this role shows up in author dropdowns |
|
| 508 | + //basic ee access |
|
| 509 | + 'ee_read_ee', |
|
| 510 | + //events |
|
| 511 | + 'ee_publish_events', |
|
| 512 | + 'ee_read_private_events', |
|
| 513 | + 'ee_read_others_events', |
|
| 514 | + 'ee_read_event', |
|
| 515 | + 'ee_read_events', |
|
| 516 | + 'ee_edit_event', |
|
| 517 | + 'ee_edit_events', |
|
| 518 | + 'ee_edit_published_events', |
|
| 519 | + 'ee_edit_others_events', |
|
| 520 | + 'ee_edit_private_events', |
|
| 521 | + 'ee_delete_published_events', |
|
| 522 | + 'ee_delete_private_events', |
|
| 523 | + 'ee_delete_event', |
|
| 524 | + 'ee_delete_events', |
|
| 525 | + 'ee_delete_others_events', |
|
| 526 | + //event categories |
|
| 527 | + 'ee_manage_event_categories', |
|
| 528 | + 'ee_edit_event_category', |
|
| 529 | + 'ee_delete_event_category', |
|
| 530 | + 'ee_assign_event_category', |
|
| 531 | + //venues |
|
| 532 | + 'ee_publish_venues', |
|
| 533 | + 'ee_read_venue', |
|
| 534 | + 'ee_read_venues', |
|
| 535 | + 'ee_read_others_venues', |
|
| 536 | + 'ee_read_private_venues', |
|
| 537 | + 'ee_edit_venue', |
|
| 538 | + 'ee_edit_venues', |
|
| 539 | + 'ee_edit_others_venues', |
|
| 540 | + 'ee_edit_published_venues', |
|
| 541 | + 'ee_edit_private_venues', |
|
| 542 | + 'ee_delete_venue', |
|
| 543 | + 'ee_delete_venues', |
|
| 544 | + 'ee_delete_others_venues', |
|
| 545 | + 'ee_delete_private_venues', |
|
| 546 | + 'ee_delete_published_venues', |
|
| 547 | + //venue categories |
|
| 548 | + 'ee_manage_venue_categories', |
|
| 549 | + 'ee_edit_venue_category', |
|
| 550 | + 'ee_delete_venue_category', |
|
| 551 | + 'ee_assign_venue_category', |
|
| 552 | + //contacts |
|
| 553 | + 'ee_read_contacts', |
|
| 554 | + 'ee_edit_contacts', |
|
| 555 | + 'ee_delete_contacts', |
|
| 556 | + //registrations |
|
| 557 | + 'ee_read_registrations', |
|
| 558 | + 'ee_read_others_registrations', |
|
| 559 | + 'ee_edit_registration', |
|
| 560 | + 'ee_edit_registrations', |
|
| 561 | + 'ee_edit_others_registrations', |
|
| 562 | + 'ee_delete_registration', |
|
| 563 | + 'ee_delete_registrations', |
|
| 564 | + //checkins |
|
| 565 | + 'ee_read_others_checkins', |
|
| 566 | + 'ee_read_checkins', |
|
| 567 | + 'ee_edit_checkins', |
|
| 568 | + 'ee_edit_others_checkins', |
|
| 569 | + 'ee_delete_checkins', |
|
| 570 | + 'ee_delete_others_checkins', |
|
| 571 | + //transactions && payments |
|
| 572 | + 'ee_read_transaction', |
|
| 573 | + 'ee_read_transactions', |
|
| 574 | + 'ee_edit_payments', |
|
| 575 | + 'ee_delete_payments', |
|
| 576 | + //messages |
|
| 577 | + 'ee_read_messages', |
|
| 578 | + 'ee_read_others_messages', |
|
| 579 | + 'ee_read_global_messages', |
|
| 580 | + 'ee_edit_global_messages', |
|
| 581 | + 'ee_edit_messages', |
|
| 582 | + 'ee_edit_others_messages', |
|
| 583 | + 'ee_delete_messages', |
|
| 584 | + 'ee_delete_others_messages', |
|
| 585 | + 'ee_delete_global_messages', |
|
| 586 | + 'ee_send_message', |
|
| 587 | + //tickets |
|
| 588 | + 'ee_read_default_tickets', |
|
| 589 | + 'ee_read_others_default_tickets', |
|
| 590 | + 'ee_edit_default_tickets', |
|
| 591 | + 'ee_edit_others_default_tickets', |
|
| 592 | + 'ee_delete_default_tickets', |
|
| 593 | + 'ee_delete_others_default_tickets', |
|
| 594 | + //prices |
|
| 595 | + 'ee_edit_default_price', |
|
| 596 | + 'ee_edit_default_prices', |
|
| 597 | + 'ee_delete_default_price', |
|
| 598 | + 'ee_delete_default_prices', |
|
| 599 | + 'ee_edit_default_price_type', |
|
| 600 | + 'ee_edit_default_price_types', |
|
| 601 | + 'ee_delete_default_price_type', |
|
| 602 | + 'ee_delete_default_price_types', |
|
| 603 | + 'ee_read_default_prices', |
|
| 604 | + 'ee_read_default_price_types', |
|
| 605 | + //registration form |
|
| 606 | + 'ee_edit_questions', |
|
| 607 | + 'ee_edit_system_questions', |
|
| 608 | + 'ee_read_questions', |
|
| 609 | + 'ee_delete_questions', |
|
| 610 | + 'ee_edit_question_groups', |
|
| 611 | + 'ee_read_question_groups', |
|
| 612 | + 'ee_edit_system_question_groups', |
|
| 613 | + 'ee_delete_question_groups', |
|
| 614 | + //event_type taxonomy |
|
| 615 | + 'ee_assign_event_type', |
|
| 616 | + 'ee_manage_event_types', |
|
| 617 | + 'ee_edit_event_type', |
|
| 618 | + 'ee_delete_event_type', |
|
| 619 | + ) |
|
| 620 | + ) |
|
| 621 | + ); |
|
| 622 | + } |
|
| 623 | + |
|
| 624 | + |
|
| 625 | + |
|
| 626 | + /** |
|
| 627 | + * @return bool |
|
| 628 | + * @throws EE_Error |
|
| 629 | + */ |
|
| 630 | + private function setupCapabilitiesMap() |
|
| 631 | + { |
|
| 632 | + // if the initialization process hasn't even started, then we need to call init_caps() |
|
| 633 | + if($this->initialized === null) { |
|
| 634 | + return $this->init_caps(); |
|
| 635 | + } |
|
| 636 | + // unless resetting, get caps from db if we haven't already |
|
| 637 | + $this->capabilities_map = $this->reset || ! empty($this->capabilities_map) |
|
| 638 | + ? $this->capabilities_map |
|
| 639 | + : get_option(self::option_name, array()); |
|
| 640 | + return true; |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + |
|
| 644 | + |
|
| 645 | + /** |
|
| 646 | + * @param bool $update |
|
| 647 | + * @return bool |
|
| 648 | + */ |
|
| 649 | + private function updateCapabilitiesMap($update = true) |
|
| 650 | + { |
|
| 651 | + return $update ? update_option(self::option_name, $this->capabilities_map) : false; |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + |
|
| 655 | + |
|
| 656 | + /** |
|
| 657 | + * Adds capabilities to roles. |
|
| 658 | + * |
|
| 659 | + * @since 4.9.42 |
|
| 660 | + * @param array $capabilities_to_add array of capabilities to add, indexed by roles. |
|
| 661 | + * Note that this should ONLY be called on activation hook |
|
| 662 | + * otherwise the caps will be added on every request. |
|
| 663 | + * @return bool |
|
| 664 | + * @throws \EE_Error |
|
| 665 | + */ |
|
| 666 | + public function addCaps(array $capabilities_to_add) |
|
| 667 | + { |
|
| 668 | + // don't do anything if the capabilities map can not be initialized |
|
| 669 | + if (! $this->setupCapabilitiesMap()) { |
|
| 670 | + return false; |
|
| 671 | + } |
|
| 672 | + // and filter the array so others can get in on the fun during resets |
|
| 673 | + $capabilities_to_add = apply_filters( |
|
| 674 | + 'FHEE__EE_Capabilities__addCaps__capabilities_to_add', |
|
| 675 | + $capabilities_to_add, |
|
| 676 | + $this->reset, |
|
| 677 | + $this->capabilities_map |
|
| 678 | + ); |
|
| 679 | + $update_capabilities_map = false; |
|
| 680 | + // if not reset, see what caps are new for each role. if they're new, add them. |
|
| 681 | + foreach ($capabilities_to_add as $role => $caps_for_role) { |
|
| 682 | + if (is_array($caps_for_role)) { |
|
| 683 | + foreach ($caps_for_role as $cap) { |
|
| 684 | + if ( |
|
| 685 | + ! $this->capHasBeenAddedToRole($role, $cap) |
|
| 686 | + && $this->add_cap_to_role($role, $cap, true, false) |
|
| 687 | + ) { |
|
| 688 | + $update_capabilities_map = true; |
|
| 689 | + } |
|
| 690 | + } |
|
| 691 | + } |
|
| 692 | + } |
|
| 693 | + // now let's just save the cap that has been set but only if there's been a change. |
|
| 694 | + $updated = $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 695 | + do_action('AHEE__EE_Capabilities__addCaps__complete', $this->capabilities_map, $updated); |
|
| 696 | + return $updated; |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + |
|
| 700 | + |
|
| 701 | + /** |
|
| 702 | + * Loops through the capabilities map and removes the role caps specified by the incoming array |
|
| 703 | + * |
|
| 704 | + * @param array $caps_map map of capabilities to be removed (indexed by roles) |
|
| 705 | + * @return bool |
|
| 706 | + * @throws \EE_Error |
|
| 707 | + */ |
|
| 708 | + public function removeCaps($caps_map) |
|
| 709 | + { |
|
| 710 | + // don't do anything if the capabilities map can not be initialized |
|
| 711 | + if (! $this->setupCapabilitiesMap()) { |
|
| 712 | + return false; |
|
| 713 | + } |
|
| 714 | + $update_capabilities_map = false; |
|
| 715 | + foreach ($caps_map as $role => $caps_for_role) { |
|
| 716 | + if (is_array($caps_for_role)) { |
|
| 717 | + foreach ($caps_for_role as $cap) { |
|
| 718 | + if ( |
|
| 719 | + $this->capHasBeenAddedToRole($role, $cap) |
|
| 720 | + && $this->remove_cap_from_role($role, $cap, false) |
|
| 721 | + ) { |
|
| 722 | + $update_capabilities_map = true; |
|
| 723 | + } |
|
| 724 | + } |
|
| 725 | + } |
|
| 726 | + } |
|
| 727 | + // maybe resave the caps |
|
| 728 | + return $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 729 | + } |
|
| 730 | + |
|
| 731 | + |
|
| 732 | + |
|
| 733 | + /** |
|
| 734 | + * This method sets a capability on a role. Note this should only be done on activation, or if you have something |
|
| 735 | + * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note. |
|
| 736 | + * this is a wrapper for $wp_role->add_cap() |
|
| 737 | + * |
|
| 738 | + * @see wp-includes/capabilities.php |
|
| 739 | + * @since 4.5.0 |
|
| 740 | + * @param string|WP_Role $role A WordPress role the capability is being added to |
|
| 741 | + * @param string $cap The capability being added to the role |
|
| 742 | + * @param bool $grant Whether to grant access to this cap on this role. |
|
| 743 | + * @param bool $update_capabilities_map |
|
| 744 | + * @return bool |
|
| 745 | + * @throws \EE_Error |
|
| 746 | + */ |
|
| 747 | + public function add_cap_to_role($role, $cap, $grant = true, $update_capabilities_map = true) |
|
| 748 | + { |
|
| 749 | + // capture incoming value for $role because we may need it to create a new WP_Role |
|
| 750 | + $orig_role = $role; |
|
| 751 | + $role = $role instanceof WP_Role ? $role : get_role($role); |
|
| 752 | + //if the role isn't available then we create it. |
|
| 753 | + if (! $role instanceof WP_Role) { |
|
| 754 | + // if a plugin wants to create a specific role name then they should create the role before |
|
| 755 | + // EE_Capabilities does. Otherwise this function will create the role name from the slug: |
|
| 756 | + // - removes any `ee_` namespacing from the start of the slug. |
|
| 757 | + // - replaces `_` with ` ` (empty space). |
|
| 758 | + // - sentence case on the resulting string. |
|
| 759 | + $role_label = ucwords(str_replace(array('ee_', '_'), array('', ' '), $orig_role)); |
|
| 760 | + $role = add_role($orig_role, $role_label); |
|
| 761 | + } |
|
| 762 | + if ($role instanceof WP_Role) { |
|
| 763 | + // don't do anything if the capabilities map can not be initialized |
|
| 764 | + if (! $this->setupCapabilitiesMap()) { |
|
| 765 | + return false; |
|
| 766 | + } |
|
| 767 | + if (! $this->capHasBeenAddedToRole($role->name, $cap)) { |
|
| 768 | + $role->add_cap($cap, $grant); |
|
| 769 | + $this->capabilities_map[ $role->name ][] = $cap; |
|
| 770 | + $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 771 | + return true; |
|
| 772 | + } |
|
| 773 | + } |
|
| 774 | + return false; |
|
| 775 | + } |
|
| 776 | + |
|
| 777 | + |
|
| 778 | + |
|
| 779 | + /** |
|
| 780 | + * Functions similarly to add_cap_to_role except removes cap from given role. |
|
| 781 | + * Wrapper for $wp_role->remove_cap() |
|
| 782 | + * |
|
| 783 | + * @see wp-includes/capabilities.php |
|
| 784 | + * @since 4.5.0 |
|
| 785 | + * @param string|WP_Role $role A WordPress role the capability is being removed from. |
|
| 786 | + * @param string $cap The capability being removed |
|
| 787 | + * @param bool $update_capabilities_map |
|
| 788 | + * @return bool |
|
| 789 | + * @throws \EE_Error |
|
| 790 | + */ |
|
| 791 | + public function remove_cap_from_role($role, $cap, $update_capabilities_map = true) |
|
| 792 | + { |
|
| 793 | + // don't do anything if the capabilities map can not be initialized |
|
| 794 | + if (! $this->setupCapabilitiesMap()) { |
|
| 795 | + return false; |
|
| 796 | + } |
|
| 797 | + $role = $role instanceof WP_Role ? $role :get_role($role); |
|
| 798 | + if ($index = $this->capHasBeenAddedToRole($role->name, $cap, true)) { |
|
| 799 | + $role->remove_cap($cap); |
|
| 800 | + unset($this->capabilities_map[ $role->name ][ $index ]); |
|
| 801 | + $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 802 | + return true; |
|
| 803 | + } |
|
| 804 | + return false; |
|
| 805 | + } |
|
| 806 | + |
|
| 807 | + |
|
| 808 | + |
|
| 809 | + /** |
|
| 810 | + * @param string $role_name |
|
| 811 | + * @param string $cap |
|
| 812 | + * @param bool $get_index |
|
| 813 | + * @return bool|mixed |
|
| 814 | + */ |
|
| 815 | + private function capHasBeenAddedToRole($role_name='', $cap='', $get_index = false) |
|
| 816 | + { |
|
| 817 | + if ( |
|
| 818 | + isset($this->capabilities_map[$role_name]) |
|
| 819 | + && ($index = array_search($cap, $this->capabilities_map[$role_name], true)) !== false |
|
| 820 | + ) { |
|
| 821 | + return $get_index ? $index : true; |
|
| 822 | + } |
|
| 823 | + return false; |
|
| 824 | + } |
|
| 825 | + |
|
| 826 | + |
|
| 827 | + |
|
| 828 | + /** |
|
| 829 | + * Wrapper for the native WP current_user_can() method. |
|
| 830 | + * This is provided as a handy method for a couple things: |
|
| 831 | + * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
| 832 | + * write those filters wherever current_user_can is called). |
|
| 833 | + * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
| 834 | + * |
|
| 835 | + * @since 4.5.0 |
|
| 836 | + * |
|
| 837 | + * @param string $cap The cap being checked. |
|
| 838 | + * @param string $context The context where the current_user_can is being called from. |
|
| 839 | + * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
| 840 | + * filters. |
|
| 841 | + * |
|
| 842 | + * @return bool Whether user can or not. |
|
| 843 | + */ |
|
| 844 | + public function current_user_can($cap, $context, $id = 0) |
|
| 845 | + { |
|
| 846 | + //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 847 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id); |
|
| 848 | + $filtered_cap = apply_filters( |
|
| 849 | + 'FHEE__EE_Capabilities__current_user_can__cap', |
|
| 850 | + $filtered_cap, |
|
| 851 | + $context, |
|
| 852 | + $cap, |
|
| 853 | + $id |
|
| 854 | + ); |
|
| 855 | + return ! empty($id) |
|
| 856 | + ? current_user_can($filtered_cap, $id) |
|
| 857 | + : current_user_can($filtered_cap); |
|
| 858 | + } |
|
| 859 | + |
|
| 860 | + |
|
| 861 | + |
|
| 862 | + /** |
|
| 863 | + * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class. |
|
| 864 | + * |
|
| 865 | + * @param int|WP_User $user Either the user_id or a WP_User object |
|
| 866 | + * @param string $cap The capability string being checked |
|
| 867 | + * @param string $context The context where the user_can is being called from (used in filters). |
|
| 868 | + * @param int $id Optional. Id for item where user_can is being called from ( used in map_meta_cap() |
|
| 869 | + * filters) |
|
| 870 | + * |
|
| 871 | + * @return bool Whether user can or not. |
|
| 872 | + */ |
|
| 873 | + public function user_can($user, $cap, $context, $id = 0) |
|
| 874 | + { |
|
| 875 | + //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 876 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id); |
|
| 877 | + $filtered_cap = apply_filters( |
|
| 878 | + 'FHEE__EE_Capabilities__user_can__cap', |
|
| 879 | + $filtered_cap, |
|
| 880 | + $context, |
|
| 881 | + $cap, |
|
| 882 | + $user, |
|
| 883 | + $id |
|
| 884 | + ); |
|
| 885 | + return ! empty($id) |
|
| 886 | + ? user_can($user, $filtered_cap, $id) |
|
| 887 | + : user_can($user, $filtered_cap); |
|
| 888 | + } |
|
| 889 | + |
|
| 890 | + |
|
| 891 | + |
|
| 892 | + /** |
|
| 893 | + * Wrapper for the native WP current_user_can_for_blog() method. |
|
| 894 | + * This is provided as a handy method for a couple things: |
|
| 895 | + * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
| 896 | + * write those filters wherever current_user_can is called). |
|
| 897 | + * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
| 898 | + * |
|
| 899 | + * @since 4.5.0 |
|
| 900 | + * |
|
| 901 | + * @param int $blog_id The blog id that is being checked for. |
|
| 902 | + * @param string $cap The cap being checked. |
|
| 903 | + * @param string $context The context where the current_user_can is being called from. |
|
| 904 | + * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
| 905 | + * filters. |
|
| 906 | + * |
|
| 907 | + * @return bool Whether user can or not. |
|
| 908 | + */ |
|
| 909 | + public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0) |
|
| 910 | + { |
|
| 911 | + $user_can = ! empty($id) |
|
| 912 | + ? current_user_can_for_blog($blog_id, $cap, $id) |
|
| 913 | + : current_user_can($blog_id, $cap); |
|
| 914 | + //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 915 | + $user_can = apply_filters( |
|
| 916 | + 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context, |
|
| 917 | + $user_can, |
|
| 918 | + $blog_id, |
|
| 919 | + $cap, |
|
| 920 | + $id |
|
| 921 | + ); |
|
| 922 | + $user_can = apply_filters( |
|
| 923 | + 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can', |
|
| 924 | + $user_can, |
|
| 925 | + $context, |
|
| 926 | + $blog_id, |
|
| 927 | + $cap, |
|
| 928 | + $id |
|
| 929 | + ); |
|
| 930 | + return $user_can; |
|
| 931 | + } |
|
| 932 | + |
|
| 933 | + |
|
| 934 | + |
|
| 935 | + /** |
|
| 936 | + * This helper method just returns an array of registered EE capabilities. |
|
| 937 | + * |
|
| 938 | + * @since 4.5.0 |
|
| 939 | + * @param string $role If empty then the entire role/capability map is returned. |
|
| 940 | + * Otherwise just the capabilities for the given role are returned. |
|
| 941 | + * @return array |
|
| 942 | + * @throws EE_Error |
|
| 943 | + */ |
|
| 944 | + public function get_ee_capabilities($role = 'administrator') |
|
| 945 | + { |
|
| 946 | + if (! $this->initialized) { |
|
| 947 | + $this->init_caps(); |
|
| 948 | + } |
|
| 949 | + if (empty($role)) { |
|
| 950 | + return $this->capabilities_map; |
|
| 951 | + } |
|
| 952 | + return isset($this->capabilities_map[ $role ]) |
|
| 953 | + ? $this->capabilities_map[ $role ] |
|
| 954 | + : array(); |
|
| 955 | + } |
|
| 956 | + |
|
| 957 | + |
|
| 958 | + |
|
| 959 | + /** |
|
| 960 | + * @deprecated 4.9.42 |
|
| 961 | + * @param bool $reset If you need to reset Event Espresso's capabilities, |
|
| 962 | + * then please use the init_caps() method with the "$reset" parameter set to "true" |
|
| 963 | + * @param array $caps_map Optional. |
|
| 964 | + * Can be used to send a custom map of roles and capabilities for setting them up. |
|
| 965 | + * Note that this should ONLY be called on activation hook or some other one-time |
|
| 966 | + * task otherwise the caps will be added on every request. |
|
| 967 | + * @return void |
|
| 968 | + * @throws EE_Error |
|
| 969 | + */ |
|
| 970 | + public function init_role_caps($reset = false, $caps_map = array()) |
|
| 971 | + { |
|
| 972 | + // If this method is called directly and reset is set as 'true', |
|
| 973 | + // then display a doing it wrong notice, because we want resets to go through init_caps() |
|
| 974 | + // to guarantee that everything is set up correctly. |
|
| 975 | + // This prevents the capabilities map getting reset incorrectly by direct calls to this method. |
|
| 976 | + if ($reset) { |
|
| 977 | + EE_Error::doing_it_wrong( |
|
| 978 | + __METHOD__, |
|
| 979 | + sprintf( |
|
| 980 | + esc_html__( |
|
| 981 | + 'The "%1$s" parameter for the "%2$s" method is deprecated. If you need to reset Event Espresso\'s capabilities, then please use the "%3$s" method with the "%1$s" parameter set to "%4$s".', |
|
| 982 | + 'event_espresso' |
|
| 983 | + ), |
|
| 984 | + '$reset', |
|
| 985 | + __METHOD__ . '()', |
|
| 986 | + 'EE_Capabilities::init_caps()', |
|
| 987 | + 'true' |
|
| 988 | + ), |
|
| 989 | + '4.9.42', |
|
| 990 | + '5.0.0' |
|
| 991 | + ); |
|
| 992 | + } |
|
| 993 | + $this->addCaps($caps_map); |
|
| 994 | + } |
|
| 995 | 995 | |
| 996 | 996 | |
| 997 | 997 | |
@@ -1012,142 +1012,142 @@ discard block |
||
| 1012 | 1012 | abstract class EE_Meta_Capability_Map |
| 1013 | 1013 | { |
| 1014 | 1014 | |
| 1015 | - public $meta_cap; |
|
| 1016 | - |
|
| 1017 | - /** |
|
| 1018 | - * @var EEM_Base |
|
| 1019 | - */ |
|
| 1020 | - protected $_model; |
|
| 1021 | - |
|
| 1022 | - protected $_model_name; |
|
| 1023 | - |
|
| 1024 | - public $published_cap = ''; |
|
| 1025 | - |
|
| 1026 | - public $others_cap = ''; |
|
| 1027 | - |
|
| 1028 | - public $private_cap = ''; |
|
| 1029 | - |
|
| 1030 | - |
|
| 1031 | - /** |
|
| 1032 | - * constructor. |
|
| 1033 | - * Receives the setup arguments for the map. |
|
| 1034 | - * |
|
| 1035 | - * @since 4.5.0 |
|
| 1036 | - * |
|
| 1037 | - * @param string $meta_cap What meta capability is this mapping. |
|
| 1038 | - * @param array $map_values array { |
|
| 1039 | - * //array of values that MUST match a count of 4. It's okay to send an empty string for |
|
| 1040 | - * capabilities that don't get mapped to. |
|
| 1041 | - * |
|
| 1042 | - * @type $map_values [0] string A string representing the model name. Required. String's |
|
| 1043 | - * should always be used when Menu Maps are registered via the |
|
| 1044 | - * plugin API as models are not allowed to be instantiated when |
|
| 1045 | - * in maintenance mode 2 (migrations). |
|
| 1046 | - * @type $map_values [1] string represents the capability used for published. Optional. |
|
| 1047 | - * @type $map_values [2] string represents the capability used for "others". Optional. |
|
| 1048 | - * @type $map_values [3] string represents the capability used for private. Optional. |
|
| 1049 | - * } |
|
| 1050 | - * @throws EE_Error |
|
| 1051 | - */ |
|
| 1052 | - public function __construct($meta_cap, $map_values) |
|
| 1053 | - { |
|
| 1054 | - $this->meta_cap = $meta_cap; |
|
| 1055 | - //verify there are four args in the $map_values array; |
|
| 1056 | - if (count($map_values) !== 4) { |
|
| 1057 | - throw new EE_Error( |
|
| 1058 | - sprintf( |
|
| 1059 | - __( |
|
| 1060 | - 'Incoming $map_values array should have a count of four values in it. This is what was given: %s', |
|
| 1061 | - 'event_espresso' |
|
| 1062 | - ), |
|
| 1063 | - '<br>' . print_r($map_values, true) |
|
| 1064 | - ) |
|
| 1065 | - ); |
|
| 1066 | - } |
|
| 1067 | - //set properties |
|
| 1068 | - $this->_model = null; |
|
| 1069 | - $this->_model_name = $map_values[0]; |
|
| 1070 | - $this->published_cap = (string)$map_values[1]; |
|
| 1071 | - $this->others_cap = (string)$map_values[2]; |
|
| 1072 | - $this->private_cap = (string)$map_values[3]; |
|
| 1073 | - } |
|
| 1074 | - |
|
| 1075 | - /** |
|
| 1076 | - * Makes it so this object stops filtering caps |
|
| 1077 | - */ |
|
| 1078 | - public function remove_filters() |
|
| 1079 | - { |
|
| 1080 | - remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10); |
|
| 1081 | - } |
|
| 1082 | - |
|
| 1083 | - |
|
| 1084 | - /** |
|
| 1085 | - * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class |
|
| 1086 | - * |
|
| 1087 | - * @since 4.5.0 |
|
| 1088 | - * @throws EE_Error |
|
| 1089 | - * |
|
| 1090 | - * @return void |
|
| 1091 | - */ |
|
| 1092 | - public function ensure_is_model() |
|
| 1093 | - { |
|
| 1094 | - //is it already instantiated? |
|
| 1095 | - if ($this->_model instanceof EEM_Base) { |
|
| 1096 | - return; |
|
| 1097 | - } |
|
| 1098 | - //ensure model name is string |
|
| 1099 | - $this->_model_name = (string)$this->_model_name; |
|
| 1100 | - //error proof if the name has EEM in it |
|
| 1101 | - $this->_model_name = str_replace('EEM', '', $this->_model_name); |
|
| 1102 | - $this->_model = EE_Registry::instance()->load_model($this->_model_name); |
|
| 1103 | - if (! $this->_model instanceof EEM_Base) { |
|
| 1104 | - throw new EE_Error( |
|
| 1105 | - sprintf( |
|
| 1106 | - __( |
|
| 1107 | - 'This string passed in to %s to represent a EEM_Base model class was not able to be used to instantiate the class. Please ensure that the string is a match for the EEM_Base model name (not including the EEM_ part). This was given: %s', |
|
| 1108 | - 'event_espresso' |
|
| 1109 | - ), |
|
| 1110 | - get_class($this), |
|
| 1111 | - $this->_model |
|
| 1112 | - ) |
|
| 1113 | - ); |
|
| 1114 | - } |
|
| 1115 | - } |
|
| 1116 | - |
|
| 1117 | - |
|
| 1118 | - /** |
|
| 1119 | - * |
|
| 1120 | - * @see EE_Meta_Capability_Map::_map_meta_caps() for docs on params. |
|
| 1121 | - * @since 4.6.x |
|
| 1122 | - * |
|
| 1123 | - * @param $caps |
|
| 1124 | - * @param $cap |
|
| 1125 | - * @param $user_id |
|
| 1126 | - * @param $args |
|
| 1127 | - * |
|
| 1128 | - * @return array |
|
| 1129 | - */ |
|
| 1130 | - public function map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1131 | - { |
|
| 1132 | - return $this->_map_meta_caps($caps, $cap, $user_id, $args); |
|
| 1133 | - } |
|
| 1134 | - |
|
| 1135 | - |
|
| 1136 | - /** |
|
| 1137 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1138 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1139 | - * |
|
| 1140 | - * @since 4.5.0 |
|
| 1141 | - * @see wp-includes/capabilities.php |
|
| 1142 | - * |
|
| 1143 | - * @param array $caps actual users capabilities |
|
| 1144 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1145 | - * @param int $user_id The user id |
|
| 1146 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1147 | - * |
|
| 1148 | - * @return array actual users capabilities |
|
| 1149 | - */ |
|
| 1150 | - abstract protected function _map_meta_caps($caps, $cap, $user_id, $args); |
|
| 1015 | + public $meta_cap; |
|
| 1016 | + |
|
| 1017 | + /** |
|
| 1018 | + * @var EEM_Base |
|
| 1019 | + */ |
|
| 1020 | + protected $_model; |
|
| 1021 | + |
|
| 1022 | + protected $_model_name; |
|
| 1023 | + |
|
| 1024 | + public $published_cap = ''; |
|
| 1025 | + |
|
| 1026 | + public $others_cap = ''; |
|
| 1027 | + |
|
| 1028 | + public $private_cap = ''; |
|
| 1029 | + |
|
| 1030 | + |
|
| 1031 | + /** |
|
| 1032 | + * constructor. |
|
| 1033 | + * Receives the setup arguments for the map. |
|
| 1034 | + * |
|
| 1035 | + * @since 4.5.0 |
|
| 1036 | + * |
|
| 1037 | + * @param string $meta_cap What meta capability is this mapping. |
|
| 1038 | + * @param array $map_values array { |
|
| 1039 | + * //array of values that MUST match a count of 4. It's okay to send an empty string for |
|
| 1040 | + * capabilities that don't get mapped to. |
|
| 1041 | + * |
|
| 1042 | + * @type $map_values [0] string A string representing the model name. Required. String's |
|
| 1043 | + * should always be used when Menu Maps are registered via the |
|
| 1044 | + * plugin API as models are not allowed to be instantiated when |
|
| 1045 | + * in maintenance mode 2 (migrations). |
|
| 1046 | + * @type $map_values [1] string represents the capability used for published. Optional. |
|
| 1047 | + * @type $map_values [2] string represents the capability used for "others". Optional. |
|
| 1048 | + * @type $map_values [3] string represents the capability used for private. Optional. |
|
| 1049 | + * } |
|
| 1050 | + * @throws EE_Error |
|
| 1051 | + */ |
|
| 1052 | + public function __construct($meta_cap, $map_values) |
|
| 1053 | + { |
|
| 1054 | + $this->meta_cap = $meta_cap; |
|
| 1055 | + //verify there are four args in the $map_values array; |
|
| 1056 | + if (count($map_values) !== 4) { |
|
| 1057 | + throw new EE_Error( |
|
| 1058 | + sprintf( |
|
| 1059 | + __( |
|
| 1060 | + 'Incoming $map_values array should have a count of four values in it. This is what was given: %s', |
|
| 1061 | + 'event_espresso' |
|
| 1062 | + ), |
|
| 1063 | + '<br>' . print_r($map_values, true) |
|
| 1064 | + ) |
|
| 1065 | + ); |
|
| 1066 | + } |
|
| 1067 | + //set properties |
|
| 1068 | + $this->_model = null; |
|
| 1069 | + $this->_model_name = $map_values[0]; |
|
| 1070 | + $this->published_cap = (string)$map_values[1]; |
|
| 1071 | + $this->others_cap = (string)$map_values[2]; |
|
| 1072 | + $this->private_cap = (string)$map_values[3]; |
|
| 1073 | + } |
|
| 1074 | + |
|
| 1075 | + /** |
|
| 1076 | + * Makes it so this object stops filtering caps |
|
| 1077 | + */ |
|
| 1078 | + public function remove_filters() |
|
| 1079 | + { |
|
| 1080 | + remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10); |
|
| 1081 | + } |
|
| 1082 | + |
|
| 1083 | + |
|
| 1084 | + /** |
|
| 1085 | + * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class |
|
| 1086 | + * |
|
| 1087 | + * @since 4.5.0 |
|
| 1088 | + * @throws EE_Error |
|
| 1089 | + * |
|
| 1090 | + * @return void |
|
| 1091 | + */ |
|
| 1092 | + public function ensure_is_model() |
|
| 1093 | + { |
|
| 1094 | + //is it already instantiated? |
|
| 1095 | + if ($this->_model instanceof EEM_Base) { |
|
| 1096 | + return; |
|
| 1097 | + } |
|
| 1098 | + //ensure model name is string |
|
| 1099 | + $this->_model_name = (string)$this->_model_name; |
|
| 1100 | + //error proof if the name has EEM in it |
|
| 1101 | + $this->_model_name = str_replace('EEM', '', $this->_model_name); |
|
| 1102 | + $this->_model = EE_Registry::instance()->load_model($this->_model_name); |
|
| 1103 | + if (! $this->_model instanceof EEM_Base) { |
|
| 1104 | + throw new EE_Error( |
|
| 1105 | + sprintf( |
|
| 1106 | + __( |
|
| 1107 | + 'This string passed in to %s to represent a EEM_Base model class was not able to be used to instantiate the class. Please ensure that the string is a match for the EEM_Base model name (not including the EEM_ part). This was given: %s', |
|
| 1108 | + 'event_espresso' |
|
| 1109 | + ), |
|
| 1110 | + get_class($this), |
|
| 1111 | + $this->_model |
|
| 1112 | + ) |
|
| 1113 | + ); |
|
| 1114 | + } |
|
| 1115 | + } |
|
| 1116 | + |
|
| 1117 | + |
|
| 1118 | + /** |
|
| 1119 | + * |
|
| 1120 | + * @see EE_Meta_Capability_Map::_map_meta_caps() for docs on params. |
|
| 1121 | + * @since 4.6.x |
|
| 1122 | + * |
|
| 1123 | + * @param $caps |
|
| 1124 | + * @param $cap |
|
| 1125 | + * @param $user_id |
|
| 1126 | + * @param $args |
|
| 1127 | + * |
|
| 1128 | + * @return array |
|
| 1129 | + */ |
|
| 1130 | + public function map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1131 | + { |
|
| 1132 | + return $this->_map_meta_caps($caps, $cap, $user_id, $args); |
|
| 1133 | + } |
|
| 1134 | + |
|
| 1135 | + |
|
| 1136 | + /** |
|
| 1137 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1138 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1139 | + * |
|
| 1140 | + * @since 4.5.0 |
|
| 1141 | + * @see wp-includes/capabilities.php |
|
| 1142 | + * |
|
| 1143 | + * @param array $caps actual users capabilities |
|
| 1144 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1145 | + * @param int $user_id The user id |
|
| 1146 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1147 | + * |
|
| 1148 | + * @return array actual users capabilities |
|
| 1149 | + */ |
|
| 1150 | + abstract protected function _map_meta_caps($caps, $cap, $user_id, $args); |
|
| 1151 | 1151 | } |
| 1152 | 1152 | |
| 1153 | 1153 | |
@@ -1163,81 +1163,81 @@ discard block |
||
| 1163 | 1163 | class EE_Meta_Capability_Map_Edit extends EE_Meta_Capability_Map |
| 1164 | 1164 | { |
| 1165 | 1165 | |
| 1166 | - /** |
|
| 1167 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1168 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1169 | - * |
|
| 1170 | - * @since 4.5.0 |
|
| 1171 | - * @see wp-includes/capabilities.php |
|
| 1172 | - * |
|
| 1173 | - * @param array $caps actual users capabilities |
|
| 1174 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1175 | - * @param int $user_id The user id |
|
| 1176 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1177 | - * |
|
| 1178 | - * @return array actual users capabilities |
|
| 1179 | - */ |
|
| 1180 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1181 | - { |
|
| 1182 | - //only process if we're checking our mapped_cap |
|
| 1183 | - if ($cap !== $this->meta_cap) { |
|
| 1184 | - return $caps; |
|
| 1185 | - } |
|
| 1186 | - |
|
| 1187 | - //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1188 | - if (($key = array_search($cap, $caps)) !== false) { |
|
| 1189 | - unset($caps[$key]); |
|
| 1190 | - } |
|
| 1191 | - |
|
| 1192 | - //cast $user_id to int for later explicit comparisons |
|
| 1193 | - $user_id = (int) $user_id; |
|
| 1194 | - |
|
| 1195 | - /** @var EE_Base_Class $obj */ |
|
| 1196 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1197 | - //if no obj then let's just do cap |
|
| 1198 | - if (! $obj instanceof EE_Base_Class) { |
|
| 1199 | - $caps[] = 'do_not_allow'; |
|
| 1200 | - return $caps; |
|
| 1201 | - } |
|
| 1202 | - $caps[] = $cap . 's'; |
|
| 1203 | - if ($obj instanceof EE_CPT_Base) { |
|
| 1204 | - //if the item author is set and the user is the author... |
|
| 1205 | - if ($obj->wp_user() && $user_id === $obj->wp_user()) { |
|
| 1206 | - //if obj is published... |
|
| 1207 | - if ($obj->status() === 'publish') { |
|
| 1208 | - $caps[] = $this->published_cap; |
|
| 1209 | - } |
|
| 1210 | - } else { |
|
| 1211 | - //the user is trying to edit someone else's obj |
|
| 1212 | - if (! empty($this->others_cap)) { |
|
| 1213 | - $caps[] = $this->others_cap; |
|
| 1214 | - } |
|
| 1215 | - if (! empty($this->published_cap) && $obj->status() === 'publish') { |
|
| 1216 | - $caps[] = $this->published_cap; |
|
| 1217 | - } elseif (! empty($this->private_cap) && $obj->status() === 'private') { |
|
| 1218 | - $caps[] = $this->private_cap; |
|
| 1219 | - } |
|
| 1220 | - } |
|
| 1221 | - } else { |
|
| 1222 | - //not a cpt object so handled differently |
|
| 1223 | - $has_cap = false; |
|
| 1224 | - try { |
|
| 1225 | - $has_cap = method_exists($obj, 'wp_user') |
|
| 1226 | - && $obj->wp_user() |
|
| 1227 | - && $obj->wp_user() === $user_id; |
|
| 1228 | - } catch (Exception $e) { |
|
| 1229 | - if (WP_DEBUG) { |
|
| 1230 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1231 | - } |
|
| 1232 | - } |
|
| 1233 | - if (! $has_cap) { |
|
| 1234 | - if (! empty($this->others_cap)) { |
|
| 1235 | - $caps[] = $this->others_cap; |
|
| 1236 | - } |
|
| 1237 | - } |
|
| 1238 | - } |
|
| 1239 | - return $caps; |
|
| 1240 | - } |
|
| 1166 | + /** |
|
| 1167 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1168 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1169 | + * |
|
| 1170 | + * @since 4.5.0 |
|
| 1171 | + * @see wp-includes/capabilities.php |
|
| 1172 | + * |
|
| 1173 | + * @param array $caps actual users capabilities |
|
| 1174 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1175 | + * @param int $user_id The user id |
|
| 1176 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1177 | + * |
|
| 1178 | + * @return array actual users capabilities |
|
| 1179 | + */ |
|
| 1180 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1181 | + { |
|
| 1182 | + //only process if we're checking our mapped_cap |
|
| 1183 | + if ($cap !== $this->meta_cap) { |
|
| 1184 | + return $caps; |
|
| 1185 | + } |
|
| 1186 | + |
|
| 1187 | + //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1188 | + if (($key = array_search($cap, $caps)) !== false) { |
|
| 1189 | + unset($caps[$key]); |
|
| 1190 | + } |
|
| 1191 | + |
|
| 1192 | + //cast $user_id to int for later explicit comparisons |
|
| 1193 | + $user_id = (int) $user_id; |
|
| 1194 | + |
|
| 1195 | + /** @var EE_Base_Class $obj */ |
|
| 1196 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1197 | + //if no obj then let's just do cap |
|
| 1198 | + if (! $obj instanceof EE_Base_Class) { |
|
| 1199 | + $caps[] = 'do_not_allow'; |
|
| 1200 | + return $caps; |
|
| 1201 | + } |
|
| 1202 | + $caps[] = $cap . 's'; |
|
| 1203 | + if ($obj instanceof EE_CPT_Base) { |
|
| 1204 | + //if the item author is set and the user is the author... |
|
| 1205 | + if ($obj->wp_user() && $user_id === $obj->wp_user()) { |
|
| 1206 | + //if obj is published... |
|
| 1207 | + if ($obj->status() === 'publish') { |
|
| 1208 | + $caps[] = $this->published_cap; |
|
| 1209 | + } |
|
| 1210 | + } else { |
|
| 1211 | + //the user is trying to edit someone else's obj |
|
| 1212 | + if (! empty($this->others_cap)) { |
|
| 1213 | + $caps[] = $this->others_cap; |
|
| 1214 | + } |
|
| 1215 | + if (! empty($this->published_cap) && $obj->status() === 'publish') { |
|
| 1216 | + $caps[] = $this->published_cap; |
|
| 1217 | + } elseif (! empty($this->private_cap) && $obj->status() === 'private') { |
|
| 1218 | + $caps[] = $this->private_cap; |
|
| 1219 | + } |
|
| 1220 | + } |
|
| 1221 | + } else { |
|
| 1222 | + //not a cpt object so handled differently |
|
| 1223 | + $has_cap = false; |
|
| 1224 | + try { |
|
| 1225 | + $has_cap = method_exists($obj, 'wp_user') |
|
| 1226 | + && $obj->wp_user() |
|
| 1227 | + && $obj->wp_user() === $user_id; |
|
| 1228 | + } catch (Exception $e) { |
|
| 1229 | + if (WP_DEBUG) { |
|
| 1230 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1231 | + } |
|
| 1232 | + } |
|
| 1233 | + if (! $has_cap) { |
|
| 1234 | + if (! empty($this->others_cap)) { |
|
| 1235 | + $caps[] = $this->others_cap; |
|
| 1236 | + } |
|
| 1237 | + } |
|
| 1238 | + } |
|
| 1239 | + return $caps; |
|
| 1240 | + } |
|
| 1241 | 1241 | } |
| 1242 | 1242 | |
| 1243 | 1243 | |
@@ -1254,24 +1254,24 @@ discard block |
||
| 1254 | 1254 | class EE_Meta_Capability_Map_Delete extends EE_Meta_Capability_Map_Edit |
| 1255 | 1255 | { |
| 1256 | 1256 | |
| 1257 | - /** |
|
| 1258 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1259 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1260 | - * |
|
| 1261 | - * @since 4.5.0 |
|
| 1262 | - * @see wp-includes/capabilities.php |
|
| 1263 | - * |
|
| 1264 | - * @param array $caps actual users capabilities |
|
| 1265 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1266 | - * @param int $user_id The user id |
|
| 1267 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1268 | - * |
|
| 1269 | - * @return array actual users capabilities |
|
| 1270 | - */ |
|
| 1271 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1272 | - { |
|
| 1273 | - return parent::_map_meta_caps($caps, $cap, $user_id, $args); |
|
| 1274 | - } |
|
| 1257 | + /** |
|
| 1258 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1259 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1260 | + * |
|
| 1261 | + * @since 4.5.0 |
|
| 1262 | + * @see wp-includes/capabilities.php |
|
| 1263 | + * |
|
| 1264 | + * @param array $caps actual users capabilities |
|
| 1265 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1266 | + * @param int $user_id The user id |
|
| 1267 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1268 | + * |
|
| 1269 | + * @return array actual users capabilities |
|
| 1270 | + */ |
|
| 1271 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1272 | + { |
|
| 1273 | + return parent::_map_meta_caps($caps, $cap, $user_id, $args); |
|
| 1274 | + } |
|
| 1275 | 1275 | } |
| 1276 | 1276 | |
| 1277 | 1277 | |
@@ -1287,85 +1287,85 @@ discard block |
||
| 1287 | 1287 | class EE_Meta_Capability_Map_Read extends EE_Meta_Capability_Map |
| 1288 | 1288 | { |
| 1289 | 1289 | |
| 1290 | - /** |
|
| 1291 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1292 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1293 | - * |
|
| 1294 | - * @since 4.5.0 |
|
| 1295 | - * @see wp-includes/capabilities.php |
|
| 1296 | - * |
|
| 1297 | - * @param array $caps actual users capabilities |
|
| 1298 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1299 | - * @param int $user_id The user id |
|
| 1300 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1301 | - * |
|
| 1302 | - * @return array actual users capabilities |
|
| 1303 | - */ |
|
| 1304 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1305 | - { |
|
| 1306 | - //only process if we're checking our mapped cap; |
|
| 1307 | - if ($cap !== $this->meta_cap) { |
|
| 1308 | - return $caps; |
|
| 1309 | - } |
|
| 1310 | - |
|
| 1311 | - //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1312 | - if (($key = array_search($cap, $caps)) !== false) { |
|
| 1313 | - unset($caps[$key]); |
|
| 1314 | - } |
|
| 1315 | - |
|
| 1316 | - //cast $user_id to int for later explicit comparisons |
|
| 1317 | - $user_id = (int) $user_id; |
|
| 1318 | - |
|
| 1319 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1320 | - //if no obj then let's just do cap |
|
| 1321 | - if (! $obj instanceof EE_Base_Class) { |
|
| 1322 | - $caps[] = 'do_not_allow'; |
|
| 1323 | - return $caps; |
|
| 1324 | - } |
|
| 1325 | - |
|
| 1326 | - $caps[] = $cap . 's'; |
|
| 1327 | - if ($obj instanceof EE_CPT_Base) { |
|
| 1328 | - $status_obj = get_post_status_object($obj->status()); |
|
| 1329 | - if ($status_obj->public) { |
|
| 1330 | - return $caps; |
|
| 1331 | - } |
|
| 1332 | - //if the item author is set and the user is not the author... |
|
| 1333 | - if ($obj->wp_user() && $obj->wp_user() !== $user_id) { |
|
| 1334 | - if (! empty($this->others_cap)) { |
|
| 1335 | - $caps[] = $this->others_cap; |
|
| 1336 | - } |
|
| 1337 | - } |
|
| 1338 | - //yes this means that if users created the private post, they are able to see it regardless of private cap. |
|
| 1339 | - if ($status_obj->private |
|
| 1340 | - && ! empty($this->private_cap) |
|
| 1341 | - && $obj->wp_user() !== $user_id |
|
| 1342 | - ) { |
|
| 1343 | - //the user is trying to view a private object for an object they don't own. |
|
| 1344 | - $caps[] = $this->private_cap; |
|
| 1345 | - } |
|
| 1346 | - } else { |
|
| 1347 | - //not a cpt object so handled differently |
|
| 1348 | - $has_cap = false; |
|
| 1349 | - try { |
|
| 1350 | - $has_cap = method_exists($obj, 'wp_user') |
|
| 1351 | - && $obj->wp_user() |
|
| 1352 | - && $obj->wp_user() === $user_id; |
|
| 1353 | - } catch (Exception $e) { |
|
| 1354 | - if (WP_DEBUG) { |
|
| 1355 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1356 | - } |
|
| 1357 | - } |
|
| 1358 | - if (! $has_cap) { |
|
| 1359 | - if (! empty($this->private_cap)) { |
|
| 1360 | - $caps[] = $this->private_cap; |
|
| 1361 | - } |
|
| 1362 | - if (! empty($this->others_cap)) { |
|
| 1363 | - $caps[] = $this->others_cap; |
|
| 1364 | - } |
|
| 1365 | - } |
|
| 1366 | - } |
|
| 1367 | - return $caps; |
|
| 1368 | - } |
|
| 1290 | + /** |
|
| 1291 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1292 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1293 | + * |
|
| 1294 | + * @since 4.5.0 |
|
| 1295 | + * @see wp-includes/capabilities.php |
|
| 1296 | + * |
|
| 1297 | + * @param array $caps actual users capabilities |
|
| 1298 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1299 | + * @param int $user_id The user id |
|
| 1300 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1301 | + * |
|
| 1302 | + * @return array actual users capabilities |
|
| 1303 | + */ |
|
| 1304 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1305 | + { |
|
| 1306 | + //only process if we're checking our mapped cap; |
|
| 1307 | + if ($cap !== $this->meta_cap) { |
|
| 1308 | + return $caps; |
|
| 1309 | + } |
|
| 1310 | + |
|
| 1311 | + //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1312 | + if (($key = array_search($cap, $caps)) !== false) { |
|
| 1313 | + unset($caps[$key]); |
|
| 1314 | + } |
|
| 1315 | + |
|
| 1316 | + //cast $user_id to int for later explicit comparisons |
|
| 1317 | + $user_id = (int) $user_id; |
|
| 1318 | + |
|
| 1319 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1320 | + //if no obj then let's just do cap |
|
| 1321 | + if (! $obj instanceof EE_Base_Class) { |
|
| 1322 | + $caps[] = 'do_not_allow'; |
|
| 1323 | + return $caps; |
|
| 1324 | + } |
|
| 1325 | + |
|
| 1326 | + $caps[] = $cap . 's'; |
|
| 1327 | + if ($obj instanceof EE_CPT_Base) { |
|
| 1328 | + $status_obj = get_post_status_object($obj->status()); |
|
| 1329 | + if ($status_obj->public) { |
|
| 1330 | + return $caps; |
|
| 1331 | + } |
|
| 1332 | + //if the item author is set and the user is not the author... |
|
| 1333 | + if ($obj->wp_user() && $obj->wp_user() !== $user_id) { |
|
| 1334 | + if (! empty($this->others_cap)) { |
|
| 1335 | + $caps[] = $this->others_cap; |
|
| 1336 | + } |
|
| 1337 | + } |
|
| 1338 | + //yes this means that if users created the private post, they are able to see it regardless of private cap. |
|
| 1339 | + if ($status_obj->private |
|
| 1340 | + && ! empty($this->private_cap) |
|
| 1341 | + && $obj->wp_user() !== $user_id |
|
| 1342 | + ) { |
|
| 1343 | + //the user is trying to view a private object for an object they don't own. |
|
| 1344 | + $caps[] = $this->private_cap; |
|
| 1345 | + } |
|
| 1346 | + } else { |
|
| 1347 | + //not a cpt object so handled differently |
|
| 1348 | + $has_cap = false; |
|
| 1349 | + try { |
|
| 1350 | + $has_cap = method_exists($obj, 'wp_user') |
|
| 1351 | + && $obj->wp_user() |
|
| 1352 | + && $obj->wp_user() === $user_id; |
|
| 1353 | + } catch (Exception $e) { |
|
| 1354 | + if (WP_DEBUG) { |
|
| 1355 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1356 | + } |
|
| 1357 | + } |
|
| 1358 | + if (! $has_cap) { |
|
| 1359 | + if (! empty($this->private_cap)) { |
|
| 1360 | + $caps[] = $this->private_cap; |
|
| 1361 | + } |
|
| 1362 | + if (! empty($this->others_cap)) { |
|
| 1363 | + $caps[] = $this->others_cap; |
|
| 1364 | + } |
|
| 1365 | + } |
|
| 1366 | + } |
|
| 1367 | + return $caps; |
|
| 1368 | + } |
|
| 1369 | 1369 | } |
| 1370 | 1370 | |
| 1371 | 1371 | |
@@ -1382,56 +1382,56 @@ discard block |
||
| 1382 | 1382 | class EE_Meta_Capability_Map_Messages_Cap extends EE_Meta_Capability_Map |
| 1383 | 1383 | { |
| 1384 | 1384 | |
| 1385 | - /** |
|
| 1386 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1387 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1388 | - * |
|
| 1389 | - * @since 4.5.0 |
|
| 1390 | - * @see wp-includes/capabilities.php |
|
| 1391 | - * |
|
| 1392 | - * @param array $caps actual users capabilities |
|
| 1393 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1394 | - * @param int $user_id The user id |
|
| 1395 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1396 | - * |
|
| 1397 | - * @return array actual users capabilities |
|
| 1398 | - */ |
|
| 1399 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1400 | - { |
|
| 1401 | - //only process if we're checking our mapped_cap |
|
| 1402 | - if ($cap !== $this->meta_cap) { |
|
| 1403 | - return $caps; |
|
| 1404 | - } |
|
| 1405 | - |
|
| 1406 | - //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1407 | - if (($key = array_search($cap, $caps)) !== false) { |
|
| 1408 | - unset($caps[$key]); |
|
| 1409 | - } |
|
| 1410 | - |
|
| 1411 | - //cast $user_id to int for later explicit comparisons |
|
| 1412 | - $user_id = (int) $user_id; |
|
| 1413 | - |
|
| 1414 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1415 | - //if no obj then let's just do cap |
|
| 1416 | - if (! $obj instanceof EE_Message_Template_Group) { |
|
| 1417 | - $caps[] = 'do_not_allow'; |
|
| 1418 | - return $caps; |
|
| 1419 | - } |
|
| 1420 | - $caps[] = $cap . 's'; |
|
| 1421 | - $is_global = $obj->is_global(); |
|
| 1422 | - if ($obj->wp_user() && $obj->wp_user() === $user_id) { |
|
| 1423 | - if ($is_global) { |
|
| 1424 | - $caps[] = $this->private_cap; |
|
| 1425 | - } |
|
| 1426 | - } else { |
|
| 1427 | - if ($is_global) { |
|
| 1428 | - $caps[] = $this->private_cap; |
|
| 1429 | - } else { |
|
| 1430 | - $caps[] = $this->others_cap; |
|
| 1431 | - } |
|
| 1432 | - } |
|
| 1433 | - return $caps; |
|
| 1434 | - } |
|
| 1385 | + /** |
|
| 1386 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1387 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1388 | + * |
|
| 1389 | + * @since 4.5.0 |
|
| 1390 | + * @see wp-includes/capabilities.php |
|
| 1391 | + * |
|
| 1392 | + * @param array $caps actual users capabilities |
|
| 1393 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1394 | + * @param int $user_id The user id |
|
| 1395 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1396 | + * |
|
| 1397 | + * @return array actual users capabilities |
|
| 1398 | + */ |
|
| 1399 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1400 | + { |
|
| 1401 | + //only process if we're checking our mapped_cap |
|
| 1402 | + if ($cap !== $this->meta_cap) { |
|
| 1403 | + return $caps; |
|
| 1404 | + } |
|
| 1405 | + |
|
| 1406 | + //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1407 | + if (($key = array_search($cap, $caps)) !== false) { |
|
| 1408 | + unset($caps[$key]); |
|
| 1409 | + } |
|
| 1410 | + |
|
| 1411 | + //cast $user_id to int for later explicit comparisons |
|
| 1412 | + $user_id = (int) $user_id; |
|
| 1413 | + |
|
| 1414 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1415 | + //if no obj then let's just do cap |
|
| 1416 | + if (! $obj instanceof EE_Message_Template_Group) { |
|
| 1417 | + $caps[] = 'do_not_allow'; |
|
| 1418 | + return $caps; |
|
| 1419 | + } |
|
| 1420 | + $caps[] = $cap . 's'; |
|
| 1421 | + $is_global = $obj->is_global(); |
|
| 1422 | + if ($obj->wp_user() && $obj->wp_user() === $user_id) { |
|
| 1423 | + if ($is_global) { |
|
| 1424 | + $caps[] = $this->private_cap; |
|
| 1425 | + } |
|
| 1426 | + } else { |
|
| 1427 | + if ($is_global) { |
|
| 1428 | + $caps[] = $this->private_cap; |
|
| 1429 | + } else { |
|
| 1430 | + $caps[] = $this->others_cap; |
|
| 1431 | + } |
|
| 1432 | + } |
|
| 1433 | + return $caps; |
|
| 1434 | + } |
|
| 1435 | 1435 | } |
| 1436 | 1436 | |
| 1437 | 1437 | |
@@ -1448,40 +1448,40 @@ discard block |
||
| 1448 | 1448 | class EE_Meta_Capability_Map_Registration_Form_Cap extends EE_Meta_Capability_Map |
| 1449 | 1449 | { |
| 1450 | 1450 | |
| 1451 | - /** |
|
| 1452 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1453 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1454 | - * |
|
| 1455 | - * @since 4.5.0 |
|
| 1456 | - * @see wp-includes/capabilities.php |
|
| 1457 | - * @param array $caps actual users capabilities |
|
| 1458 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1459 | - * @param int $user_id The user id |
|
| 1460 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1461 | - * @return array actual users capabilities |
|
| 1462 | - */ |
|
| 1463 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1464 | - { |
|
| 1465 | - //only process if we're checking our mapped_cap |
|
| 1466 | - if ($cap !== $this->meta_cap) { |
|
| 1467 | - return $caps; |
|
| 1468 | - } |
|
| 1469 | - //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1470 | - if (($key = array_search($cap, $caps)) !== false) { |
|
| 1471 | - unset($caps[$key]); |
|
| 1472 | - } |
|
| 1473 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1474 | - //if no obj then let's just do cap |
|
| 1475 | - if (! $obj instanceof EE_Base_Class) { |
|
| 1476 | - $caps[] = 'do_not_allow'; |
|
| 1477 | - return $caps; |
|
| 1478 | - } |
|
| 1479 | - $caps[] = $cap . 's'; |
|
| 1480 | - $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false; |
|
| 1481 | - $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system; |
|
| 1482 | - if ($is_system) { |
|
| 1483 | - $caps[] = $this->private_cap; |
|
| 1484 | - } |
|
| 1485 | - return $caps; |
|
| 1486 | - } |
|
| 1451 | + /** |
|
| 1452 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1453 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1454 | + * |
|
| 1455 | + * @since 4.5.0 |
|
| 1456 | + * @see wp-includes/capabilities.php |
|
| 1457 | + * @param array $caps actual users capabilities |
|
| 1458 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1459 | + * @param int $user_id The user id |
|
| 1460 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1461 | + * @return array actual users capabilities |
|
| 1462 | + */ |
|
| 1463 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1464 | + { |
|
| 1465 | + //only process if we're checking our mapped_cap |
|
| 1466 | + if ($cap !== $this->meta_cap) { |
|
| 1467 | + return $caps; |
|
| 1468 | + } |
|
| 1469 | + //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1470 | + if (($key = array_search($cap, $caps)) !== false) { |
|
| 1471 | + unset($caps[$key]); |
|
| 1472 | + } |
|
| 1473 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1474 | + //if no obj then let's just do cap |
|
| 1475 | + if (! $obj instanceof EE_Base_Class) { |
|
| 1476 | + $caps[] = 'do_not_allow'; |
|
| 1477 | + return $caps; |
|
| 1478 | + } |
|
| 1479 | + $caps[] = $cap . 's'; |
|
| 1480 | + $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false; |
|
| 1481 | + $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system; |
|
| 1482 | + if ($is_system) { |
|
| 1483 | + $caps[] = $this->private_cap; |
|
| 1484 | + } |
|
| 1485 | + return $caps; |
|
| 1486 | + } |
|
| 1487 | 1487 | } |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | public static function instance() |
| 86 | 86 | { |
| 87 | 87 | //check if instantiated, and if not do so. |
| 88 | - if (! self::$_instance instanceof EE_Capabilities) { |
|
| 88 | + if ( ! self::$_instance instanceof EE_Capabilities) { |
|
| 89 | 89 | self::$_instance = new self(); |
| 90 | 90 | } |
| 91 | 91 | return self::$_instance; |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | */ |
| 118 | 118 | public function init_caps($reset = false) |
| 119 | 119 | { |
| 120 | - if(! EE_Maintenance_Mode::instance()->models_can_query()){ |
|
| 120 | + if ( ! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 121 | 121 | return false; |
| 122 | 122 | } |
| 123 | 123 | $this->reset = filter_var($reset, FILTER_VALIDATE_BOOLEAN); |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | $this->_get_default_meta_caps_array() |
| 164 | 164 | ); |
| 165 | 165 | //add filter for map_meta_caps but only if models can query. |
| 166 | - if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) { |
|
| 166 | + if ( ! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) { |
|
| 167 | 167 | add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4); |
| 168 | 168 | } |
| 169 | 169 | } |
@@ -324,11 +324,11 @@ discard block |
||
| 324 | 324 | if (did_action('AHEE__EE_System__load_espresso_addons__complete')) { |
| 325 | 325 | //loop through our _meta_caps array |
| 326 | 326 | foreach ($this->_meta_caps as $meta_map) { |
| 327 | - if (! $meta_map instanceof EE_Meta_Capability_Map) { |
|
| 327 | + if ( ! $meta_map instanceof EE_Meta_Capability_Map) { |
|
| 328 | 328 | continue; |
| 329 | 329 | } |
| 330 | 330 | // don't load models if there is no object ID in the args |
| 331 | - if (! empty($args[0])) { |
|
| 331 | + if ( ! empty($args[0])) { |
|
| 332 | 332 | $meta_map->ensure_is_model(); |
| 333 | 333 | } |
| 334 | 334 | $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args); |
@@ -630,7 +630,7 @@ discard block |
||
| 630 | 630 | private function setupCapabilitiesMap() |
| 631 | 631 | { |
| 632 | 632 | // if the initialization process hasn't even started, then we need to call init_caps() |
| 633 | - if($this->initialized === null) { |
|
| 633 | + if ($this->initialized === null) { |
|
| 634 | 634 | return $this->init_caps(); |
| 635 | 635 | } |
| 636 | 636 | // unless resetting, get caps from db if we haven't already |
@@ -666,7 +666,7 @@ discard block |
||
| 666 | 666 | public function addCaps(array $capabilities_to_add) |
| 667 | 667 | { |
| 668 | 668 | // don't do anything if the capabilities map can not be initialized |
| 669 | - if (! $this->setupCapabilitiesMap()) { |
|
| 669 | + if ( ! $this->setupCapabilitiesMap()) { |
|
| 670 | 670 | return false; |
| 671 | 671 | } |
| 672 | 672 | // and filter the array so others can get in on the fun during resets |
@@ -708,7 +708,7 @@ discard block |
||
| 708 | 708 | public function removeCaps($caps_map) |
| 709 | 709 | { |
| 710 | 710 | // don't do anything if the capabilities map can not be initialized |
| 711 | - if (! $this->setupCapabilitiesMap()) { |
|
| 711 | + if ( ! $this->setupCapabilitiesMap()) { |
|
| 712 | 712 | return false; |
| 713 | 713 | } |
| 714 | 714 | $update_capabilities_map = false; |
@@ -750,7 +750,7 @@ discard block |
||
| 750 | 750 | $orig_role = $role; |
| 751 | 751 | $role = $role instanceof WP_Role ? $role : get_role($role); |
| 752 | 752 | //if the role isn't available then we create it. |
| 753 | - if (! $role instanceof WP_Role) { |
|
| 753 | + if ( ! $role instanceof WP_Role) { |
|
| 754 | 754 | // if a plugin wants to create a specific role name then they should create the role before |
| 755 | 755 | // EE_Capabilities does. Otherwise this function will create the role name from the slug: |
| 756 | 756 | // - removes any `ee_` namespacing from the start of the slug. |
@@ -761,12 +761,12 @@ discard block |
||
| 761 | 761 | } |
| 762 | 762 | if ($role instanceof WP_Role) { |
| 763 | 763 | // don't do anything if the capabilities map can not be initialized |
| 764 | - if (! $this->setupCapabilitiesMap()) { |
|
| 764 | + if ( ! $this->setupCapabilitiesMap()) { |
|
| 765 | 765 | return false; |
| 766 | 766 | } |
| 767 | - if (! $this->capHasBeenAddedToRole($role->name, $cap)) { |
|
| 767 | + if ( ! $this->capHasBeenAddedToRole($role->name, $cap)) { |
|
| 768 | 768 | $role->add_cap($cap, $grant); |
| 769 | - $this->capabilities_map[ $role->name ][] = $cap; |
|
| 769 | + $this->capabilities_map[$role->name][] = $cap; |
|
| 770 | 770 | $this->updateCapabilitiesMap($update_capabilities_map); |
| 771 | 771 | return true; |
| 772 | 772 | } |
@@ -791,13 +791,13 @@ discard block |
||
| 791 | 791 | public function remove_cap_from_role($role, $cap, $update_capabilities_map = true) |
| 792 | 792 | { |
| 793 | 793 | // don't do anything if the capabilities map can not be initialized |
| 794 | - if (! $this->setupCapabilitiesMap()) { |
|
| 794 | + if ( ! $this->setupCapabilitiesMap()) { |
|
| 795 | 795 | return false; |
| 796 | 796 | } |
| 797 | - $role = $role instanceof WP_Role ? $role :get_role($role); |
|
| 797 | + $role = $role instanceof WP_Role ? $role : get_role($role); |
|
| 798 | 798 | if ($index = $this->capHasBeenAddedToRole($role->name, $cap, true)) { |
| 799 | 799 | $role->remove_cap($cap); |
| 800 | - unset($this->capabilities_map[ $role->name ][ $index ]); |
|
| 800 | + unset($this->capabilities_map[$role->name][$index]); |
|
| 801 | 801 | $this->updateCapabilitiesMap($update_capabilities_map); |
| 802 | 802 | return true; |
| 803 | 803 | } |
@@ -812,7 +812,7 @@ discard block |
||
| 812 | 812 | * @param bool $get_index |
| 813 | 813 | * @return bool|mixed |
| 814 | 814 | */ |
| 815 | - private function capHasBeenAddedToRole($role_name='', $cap='', $get_index = false) |
|
| 815 | + private function capHasBeenAddedToRole($role_name = '', $cap = '', $get_index = false) |
|
| 816 | 816 | { |
| 817 | 817 | if ( |
| 818 | 818 | isset($this->capabilities_map[$role_name]) |
@@ -844,7 +844,7 @@ discard block |
||
| 844 | 844 | public function current_user_can($cap, $context, $id = 0) |
| 845 | 845 | { |
| 846 | 846 | //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
| 847 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id); |
|
| 847 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__'.$context, $cap, $id); |
|
| 848 | 848 | $filtered_cap = apply_filters( |
| 849 | 849 | 'FHEE__EE_Capabilities__current_user_can__cap', |
| 850 | 850 | $filtered_cap, |
@@ -873,7 +873,7 @@ discard block |
||
| 873 | 873 | public function user_can($user, $cap, $context, $id = 0) |
| 874 | 874 | { |
| 875 | 875 | //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
| 876 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id); |
|
| 876 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__'.$context, $cap, $user, $id); |
|
| 877 | 877 | $filtered_cap = apply_filters( |
| 878 | 878 | 'FHEE__EE_Capabilities__user_can__cap', |
| 879 | 879 | $filtered_cap, |
@@ -913,7 +913,7 @@ discard block |
||
| 913 | 913 | : current_user_can($blog_id, $cap); |
| 914 | 914 | //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
| 915 | 915 | $user_can = apply_filters( |
| 916 | - 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context, |
|
| 916 | + 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__'.$context, |
|
| 917 | 917 | $user_can, |
| 918 | 918 | $blog_id, |
| 919 | 919 | $cap, |
@@ -943,14 +943,14 @@ discard block |
||
| 943 | 943 | */ |
| 944 | 944 | public function get_ee_capabilities($role = 'administrator') |
| 945 | 945 | { |
| 946 | - if (! $this->initialized) { |
|
| 946 | + if ( ! $this->initialized) { |
|
| 947 | 947 | $this->init_caps(); |
| 948 | 948 | } |
| 949 | 949 | if (empty($role)) { |
| 950 | 950 | return $this->capabilities_map; |
| 951 | 951 | } |
| 952 | - return isset($this->capabilities_map[ $role ]) |
|
| 953 | - ? $this->capabilities_map[ $role ] |
|
| 952 | + return isset($this->capabilities_map[$role]) |
|
| 953 | + ? $this->capabilities_map[$role] |
|
| 954 | 954 | : array(); |
| 955 | 955 | } |
| 956 | 956 | |
@@ -982,7 +982,7 @@ discard block |
||
| 982 | 982 | 'event_espresso' |
| 983 | 983 | ), |
| 984 | 984 | '$reset', |
| 985 | - __METHOD__ . '()', |
|
| 985 | + __METHOD__.'()', |
|
| 986 | 986 | 'EE_Capabilities::init_caps()', |
| 987 | 987 | 'true' |
| 988 | 988 | ), |
@@ -1060,16 +1060,16 @@ discard block |
||
| 1060 | 1060 | 'Incoming $map_values array should have a count of four values in it. This is what was given: %s', |
| 1061 | 1061 | 'event_espresso' |
| 1062 | 1062 | ), |
| 1063 | - '<br>' . print_r($map_values, true) |
|
| 1063 | + '<br>'.print_r($map_values, true) |
|
| 1064 | 1064 | ) |
| 1065 | 1065 | ); |
| 1066 | 1066 | } |
| 1067 | 1067 | //set properties |
| 1068 | 1068 | $this->_model = null; |
| 1069 | 1069 | $this->_model_name = $map_values[0]; |
| 1070 | - $this->published_cap = (string)$map_values[1]; |
|
| 1071 | - $this->others_cap = (string)$map_values[2]; |
|
| 1072 | - $this->private_cap = (string)$map_values[3]; |
|
| 1070 | + $this->published_cap = (string) $map_values[1]; |
|
| 1071 | + $this->others_cap = (string) $map_values[2]; |
|
| 1072 | + $this->private_cap = (string) $map_values[3]; |
|
| 1073 | 1073 | } |
| 1074 | 1074 | |
| 1075 | 1075 | /** |
@@ -1096,11 +1096,11 @@ discard block |
||
| 1096 | 1096 | return; |
| 1097 | 1097 | } |
| 1098 | 1098 | //ensure model name is string |
| 1099 | - $this->_model_name = (string)$this->_model_name; |
|
| 1099 | + $this->_model_name = (string) $this->_model_name; |
|
| 1100 | 1100 | //error proof if the name has EEM in it |
| 1101 | 1101 | $this->_model_name = str_replace('EEM', '', $this->_model_name); |
| 1102 | 1102 | $this->_model = EE_Registry::instance()->load_model($this->_model_name); |
| 1103 | - if (! $this->_model instanceof EEM_Base) { |
|
| 1103 | + if ( ! $this->_model instanceof EEM_Base) { |
|
| 1104 | 1104 | throw new EE_Error( |
| 1105 | 1105 | sprintf( |
| 1106 | 1106 | __( |
@@ -1195,11 +1195,11 @@ discard block |
||
| 1195 | 1195 | /** @var EE_Base_Class $obj */ |
| 1196 | 1196 | $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
| 1197 | 1197 | //if no obj then let's just do cap |
| 1198 | - if (! $obj instanceof EE_Base_Class) { |
|
| 1198 | + if ( ! $obj instanceof EE_Base_Class) { |
|
| 1199 | 1199 | $caps[] = 'do_not_allow'; |
| 1200 | 1200 | return $caps; |
| 1201 | 1201 | } |
| 1202 | - $caps[] = $cap . 's'; |
|
| 1202 | + $caps[] = $cap.'s'; |
|
| 1203 | 1203 | if ($obj instanceof EE_CPT_Base) { |
| 1204 | 1204 | //if the item author is set and the user is the author... |
| 1205 | 1205 | if ($obj->wp_user() && $user_id === $obj->wp_user()) { |
@@ -1209,12 +1209,12 @@ discard block |
||
| 1209 | 1209 | } |
| 1210 | 1210 | } else { |
| 1211 | 1211 | //the user is trying to edit someone else's obj |
| 1212 | - if (! empty($this->others_cap)) { |
|
| 1212 | + if ( ! empty($this->others_cap)) { |
|
| 1213 | 1213 | $caps[] = $this->others_cap; |
| 1214 | 1214 | } |
| 1215 | - if (! empty($this->published_cap) && $obj->status() === 'publish') { |
|
| 1215 | + if ( ! empty($this->published_cap) && $obj->status() === 'publish') { |
|
| 1216 | 1216 | $caps[] = $this->published_cap; |
| 1217 | - } elseif (! empty($this->private_cap) && $obj->status() === 'private') { |
|
| 1217 | + } elseif ( ! empty($this->private_cap) && $obj->status() === 'private') { |
|
| 1218 | 1218 | $caps[] = $this->private_cap; |
| 1219 | 1219 | } |
| 1220 | 1220 | } |
@@ -1230,8 +1230,8 @@ discard block |
||
| 1230 | 1230 | EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
| 1231 | 1231 | } |
| 1232 | 1232 | } |
| 1233 | - if (! $has_cap) { |
|
| 1234 | - if (! empty($this->others_cap)) { |
|
| 1233 | + if ( ! $has_cap) { |
|
| 1234 | + if ( ! empty($this->others_cap)) { |
|
| 1235 | 1235 | $caps[] = $this->others_cap; |
| 1236 | 1236 | } |
| 1237 | 1237 | } |
@@ -1318,12 +1318,12 @@ discard block |
||
| 1318 | 1318 | |
| 1319 | 1319 | $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
| 1320 | 1320 | //if no obj then let's just do cap |
| 1321 | - if (! $obj instanceof EE_Base_Class) { |
|
| 1321 | + if ( ! $obj instanceof EE_Base_Class) { |
|
| 1322 | 1322 | $caps[] = 'do_not_allow'; |
| 1323 | 1323 | return $caps; |
| 1324 | 1324 | } |
| 1325 | 1325 | |
| 1326 | - $caps[] = $cap . 's'; |
|
| 1326 | + $caps[] = $cap.'s'; |
|
| 1327 | 1327 | if ($obj instanceof EE_CPT_Base) { |
| 1328 | 1328 | $status_obj = get_post_status_object($obj->status()); |
| 1329 | 1329 | if ($status_obj->public) { |
@@ -1331,7 +1331,7 @@ discard block |
||
| 1331 | 1331 | } |
| 1332 | 1332 | //if the item author is set and the user is not the author... |
| 1333 | 1333 | if ($obj->wp_user() && $obj->wp_user() !== $user_id) { |
| 1334 | - if (! empty($this->others_cap)) { |
|
| 1334 | + if ( ! empty($this->others_cap)) { |
|
| 1335 | 1335 | $caps[] = $this->others_cap; |
| 1336 | 1336 | } |
| 1337 | 1337 | } |
@@ -1355,11 +1355,11 @@ discard block |
||
| 1355 | 1355 | EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
| 1356 | 1356 | } |
| 1357 | 1357 | } |
| 1358 | - if (! $has_cap) { |
|
| 1359 | - if (! empty($this->private_cap)) { |
|
| 1358 | + if ( ! $has_cap) { |
|
| 1359 | + if ( ! empty($this->private_cap)) { |
|
| 1360 | 1360 | $caps[] = $this->private_cap; |
| 1361 | 1361 | } |
| 1362 | - if (! empty($this->others_cap)) { |
|
| 1362 | + if ( ! empty($this->others_cap)) { |
|
| 1363 | 1363 | $caps[] = $this->others_cap; |
| 1364 | 1364 | } |
| 1365 | 1365 | } |
@@ -1413,11 +1413,11 @@ discard block |
||
| 1413 | 1413 | |
| 1414 | 1414 | $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
| 1415 | 1415 | //if no obj then let's just do cap |
| 1416 | - if (! $obj instanceof EE_Message_Template_Group) { |
|
| 1416 | + if ( ! $obj instanceof EE_Message_Template_Group) { |
|
| 1417 | 1417 | $caps[] = 'do_not_allow'; |
| 1418 | 1418 | return $caps; |
| 1419 | 1419 | } |
| 1420 | - $caps[] = $cap . 's'; |
|
| 1420 | + $caps[] = $cap.'s'; |
|
| 1421 | 1421 | $is_global = $obj->is_global(); |
| 1422 | 1422 | if ($obj->wp_user() && $obj->wp_user() === $user_id) { |
| 1423 | 1423 | if ($is_global) { |
@@ -1472,11 +1472,11 @@ discard block |
||
| 1472 | 1472 | } |
| 1473 | 1473 | $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
| 1474 | 1474 | //if no obj then let's just do cap |
| 1475 | - if (! $obj instanceof EE_Base_Class) { |
|
| 1475 | + if ( ! $obj instanceof EE_Base_Class) { |
|
| 1476 | 1476 | $caps[] = 'do_not_allow'; |
| 1477 | 1477 | return $caps; |
| 1478 | 1478 | } |
| 1479 | - $caps[] = $cap . 's'; |
|
| 1479 | + $caps[] = $cap.'s'; |
|
| 1480 | 1480 | $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false; |
| 1481 | 1481 | $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system; |
| 1482 | 1482 | if ($is_system) { |